Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a listApps feature and test before read data #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 34 additions & 3 deletions examples/desfire.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,39 @@ nfc.on('reader', async reader => {

};

const listApps = async () => {
const res = await reader.transmit(Buffer.from([0x90, 0x6a, 0x00, 0x00, 0x00]), 32);

if (res.slice(-1)[0] !== 0x00) {
throw new Error('error in step 3 - list apps');
}

// empty card
if (res.length < 3) {
pretty.info(`no apps found`);
return [];
}

const resApps = res.slice(0, res.length - res.length % 3);
let i = 0;
let apps = [];

for (i = 0; i < resApps.length; i++) {
apps.push(resApps.slice(i ,i + 3));
i += 2
}
pretty.info(`apps found`, apps);
return apps;
}

const readData = async () => {

// 3: [0xBD] ReadData(FileNo,Offset,Length) [8bytes] - Reads data from Standard Data Files or Backup Data Files
const res = await send(wrap(0xbd, [desfire.read.fileId, ...desfire.read.offset, ...desfire.read.length]), 'step 3 - read', 255);

// something went wrong
if (res.slice(-1)[0] !== 0x00) {
throw new Error('error in step 3 - read');
throw new Error('error in step 4 - read');
}

console.log('data', res);
Expand All @@ -172,7 +197,13 @@ nfc.on('reader', async reader => {
await authenticate(key);

// step 3
await readData();
const apps = await listApps();

if (apps.length > 0) {
// step 4
await readData();
}



} catch (err) {
Expand Down