Skip to content

Commit

Permalink
Fix handle_Iso_14443_4_Tag and read methods (#55)
Browse files Browse the repository at this point in the history
* Fix malformed SELECT FILE command in `handle_Iso_14443_4_Tag()` (close #54)
* Add readClass option to `read()` method to allow specifying the class (instead of the hard-coded 0xFF class)
* Fix reading blocks beyond 255
  • Loading branch information
martijnthe authored and pokusew committed Dec 27, 2018
1 parent 0a90087 commit cca3781
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/Reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ class Reader extends EventEmitter {

}

async read(blockNumber, length, blockSize = 4, packetSize = 16) {
async read(blockNumber, length, blockSize = 4, packetSize = 16, readClass = 0xff) {

if (!this.card) {
throw new ReadError(CARD_NOT_CONNECTED);
Expand All @@ -505,7 +505,7 @@ class Reader extends EventEmitter {

// console.log(i, block, size);

commands.push(this.read(block, size, blockSize, packetSize));
commands.push(this.read(block, size, blockSize, packetSize, readClass));

}

Expand All @@ -519,10 +519,10 @@ class Reader extends EventEmitter {

// APDU CMD: Read Binary Blocks
const packet = new Buffer([
0xff, // Class
readClass, // Class
0xb0, // Ins
0x00, // P1
blockNumber, // P2: Block Number
(blockNumber >> 8) & 0xFF, // P1
blockNumber & 0xFF, // P2: Block Number
length // Le: Number of Bytes to Read (Maximum 16 bytes)
]);

Expand Down Expand Up @@ -734,17 +734,19 @@ class Reader extends EventEmitter {
}

// APDU CMD: Select Apdu
const aid = Buffer.from(this._parsedAid);
const packetHeader = Buffer.from([
0x00, // Class
0xa4, // INS
0x04, // P1
0x00, // P2
0x05 // Le
aid.length, // Lc
]);
const packetFooter = Buffer.from([
0x00, // Le
]);

const aid = Buffer.from(this._parsedAid);

const packet = Buffer.concat([packetHeader, aid]);
const packet = Buffer.concat([packetHeader, aid, packetFooter]);

try {

Expand Down

0 comments on commit cca3781

Please sign in to comment.