Merge r520-546 from trunk.
This commit is contained in:
commit
769eef20f7
16 changed files with 291 additions and 278 deletions
|
|
@ -69,7 +69,13 @@ bool nfc_initiator_mifare_cmd(nfc_device_t* pnd, const mifare_cmd mc, const uint
|
|||
if (!nfc_initiator_transceive_dep_bytes(pnd,abtCmd,2+szParamLen,abtRx,&szRxLen)) return false;
|
||||
|
||||
// When we have executed a read command, copy the received bytes into the param
|
||||
if (mc == MC_READ && szRxLen == 17) memcpy(pmp->mpd.abtData,abtRx+1,16);
|
||||
if (mc == MC_READ) {
|
||||
if(szRxLen == 16) {
|
||||
memcpy(pmp->mpd.abtData,abtRx,16);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Command succesfully executed
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -47,7 +47,6 @@
|
|||
#define MAX_TARGET_COUNT 16
|
||||
|
||||
static nfc_device_t* pnd;
|
||||
static byte_t abtFelica[5] = { 0x00, 0xff, 0xff, 0x00, 0x00 };
|
||||
|
||||
int main(int argc, const char* argv[])
|
||||
{
|
||||
|
|
@ -55,7 +54,6 @@ int main(int argc, const char* argv[])
|
|||
size_t szDeviceFound;
|
||||
size_t szTargetFound;
|
||||
size_t i;
|
||||
nfc_target_info_t nti;
|
||||
nfc_device_desc_t *pnddDevices;
|
||||
|
||||
// Display libnfc version
|
||||
|
|
@ -133,45 +131,54 @@ int main(int argc, const char* argv[])
|
|||
|
||||
printf("Connected to NFC reader: %s\n",pnd->acName);
|
||||
|
||||
// List ISO14443A targets
|
||||
if (nfc_initiator_list_passive_targets(pnd, NM_ISO14443A_106, anti, MAX_TARGET_COUNT, &szTargetFound )) {
|
||||
size_t n;
|
||||
printf("%zu ISO14443A passive targets was found:\n", szTargetFound);
|
||||
printf("%zu ISO14443A passive target(s) was found%s\n", szTargetFound, (szTargetFound==0)?".\n":":");
|
||||
for(n=0; n<szTargetFound; n++) {
|
||||
print_nfc_iso14443a_info (anti[n].nai);
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
printf("-------------------\n");
|
||||
|
||||
// Poll for a Felica tag
|
||||
if (nfc_initiator_select_passive_target(pnd,NM_FELICA_212,abtFelica,5,&nti) || nfc_initiator_select_passive_target(pnd,NM_FELICA_424,abtFelica,5,&nti))
|
||||
{
|
||||
printf("The following (NFC) Felica tag was found:\n\n");
|
||||
printf("%18s","ID (NFCID2): "); print_hex(nti.nfi.abtId,8);
|
||||
printf("%18s","Parameter (PAD): "); print_hex(nti.nfi.abtPad,8);
|
||||
}
|
||||
|
||||
// Poll for a ISO14443B tag
|
||||
if (nfc_initiator_select_passive_target(pnd,NM_ISO14443B_106,(byte_t*)"\x00",1,&nti))
|
||||
{
|
||||
printf("The following (NFC) ISO14443-B tag was found:\n\n");
|
||||
printf(" ATQB: "); print_hex(nti.nbi.abtAtqb,12);
|
||||
printf(" ID: "); print_hex(nti.nbi.abtId,4);
|
||||
printf(" CID: %02x\n",nti.nbi.btCid);
|
||||
if (nti.nbi.szInfLen>0)
|
||||
{
|
||||
printf(" INF: "); print_hex(nti.nbi.abtInf,nti.nbi.szInfLen);
|
||||
// List Felica tags
|
||||
if (nfc_initiator_list_passive_targets(pnd, NM_FELICA_212, anti, MAX_TARGET_COUNT, &szTargetFound )) {
|
||||
size_t n;
|
||||
printf("%zu Felica (212 kbps) passive target(s) was found%s\n", szTargetFound, (szTargetFound==0)?".\n":":");
|
||||
for(n=0; n<szTargetFound; n++) {
|
||||
print_nfc_felica_info (anti[n].nfi);
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
if (nfc_initiator_list_passive_targets(pnd, NM_FELICA_424, anti, MAX_TARGET_COUNT, &szTargetFound )) {
|
||||
size_t n;
|
||||
printf("%zu Felica (424 kbps) passive target(s) was found%s\n", szTargetFound, (szTargetFound==0)?".\n":":");
|
||||
for(n=0; n<szTargetFound; n++) {
|
||||
print_nfc_felica_info (anti[n].nfi);
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
// List ISO14443B targets
|
||||
if (nfc_initiator_list_passive_targets(pnd, NM_ISO14443B_106, anti, MAX_TARGET_COUNT, &szTargetFound )) {
|
||||
size_t n;
|
||||
printf("%zu ISO14443B passive target(s) was found%s\n", szTargetFound, (szTargetFound==0)?".\n":":");
|
||||
for(n=0; n<szTargetFound; n++) {
|
||||
print_nfc_iso14443b_info (anti[n].nbi);
|
||||
printf("\n");
|
||||
}
|
||||
printf("PARAMS: %02x %02x %02x %02x\n",nti.nbi.btParam1,nti.nbi.btParam2,nti.nbi.btParam3,nti.nbi.btParam4);
|
||||
}
|
||||
|
||||
// Poll for a Jewel tag
|
||||
if (nfc_initiator_select_passive_target(pnd,NM_JEWEL_106,NULL,0,&nti))
|
||||
{
|
||||
// No test results yet
|
||||
printf("jewel\n");
|
||||
/*
|
||||
// List Jewel targets
|
||||
if (nfc_initiator_list_passive_targets(pnd, NM_JEWEL_106, anti, MAX_TARGET_COUNT, &szTargetFound )) {
|
||||
size_t n;
|
||||
printf("%zu Jewel passive target(s) was found%s\n", szTargetFound, (szTargetFound==0)?".\n":":"); for(n=0; n<szTargetFound; n++) {
|
||||
printf("Jewel support is missing in libnfc, feel free to contribute.\n");
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
nfc_disconnect(pnd);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -141,9 +141,6 @@ authenticate (uint32_t uiBlock)
|
|||
for (key_index = 0; key_index < num_keys; key_index++) {
|
||||
memcpy (mp.mpa.abtKey, keys + (key_index * 6), 6);
|
||||
if (nfc_initiator_mifare_cmd (pnd, mc, uiBlock, &mp)) {
|
||||
/**
|
||||
* @note: what about the other key?
|
||||
*/
|
||||
if (bUseKeyA)
|
||||
memcpy (mtKeys.amb[uiBlock].mbt.abtKeyA, &mp.mpa.abtKey, 6);
|
||||
else
|
||||
|
|
@ -190,7 +187,7 @@ read_card (void)
|
|||
|
||||
// Try to authenticate for the current sector
|
||||
if (!authenticate (iBlock)) {
|
||||
printf ("!\nError: authentication failed for block %02x\n", iBlock);
|
||||
printf ("!\nError: authentication failed for block 0x%02x\n", iBlock);
|
||||
return false;
|
||||
}
|
||||
// Try to read out the trailer
|
||||
|
|
@ -199,6 +196,8 @@ read_card (void)
|
|||
memcpy (mtDump.amb[iBlock].mbt.abtKeyA, mtKeys.amb[iBlock].mbt.abtKeyA, 6);
|
||||
memcpy (mtDump.amb[iBlock].mbt.abtAccessBits, mp.mpd.abtData + 6, 4);
|
||||
memcpy (mtDump.amb[iBlock].mbt.abtKeyB, mtKeys.amb[iBlock].mbt.abtKeyB, 6);
|
||||
} else {
|
||||
printf("!\nError: unable to read trailer block 0x%02x\n", iBlock);
|
||||
}
|
||||
} else {
|
||||
// Make sure a earlier readout did not fail
|
||||
|
|
@ -208,6 +207,8 @@ read_card (void)
|
|||
memcpy (mtDump.amb[iBlock].mbd.abtData, mp.mpd.abtData, 16);
|
||||
} else {
|
||||
bFailure = true;
|
||||
printf("!\nError: unable to read block 0x%02x\n", iBlock);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -102,15 +102,9 @@ main (int argc, const char *argv[])
|
|||
|
||||
printf ("Connected to NFC reader: %s\n", pnd->acName);
|
||||
|
||||
// NOTE we can't use pn53x_transceive() because rx[0] is not status byte (0x00 != status OK)
|
||||
// XXX: as of r491, this is no longer the case. Unfortunately I can't be sure that these comments can be removed.
|
||||
// bool pn53x_transceive(const nfc_device_t* pnd, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen);
|
||||
// bool res = pn53x_transceive(pnd, abtTx, szTxLen, abtRx, &szRxLen);
|
||||
|
||||
// bool (*transceive)(const nfc_device_spec_t nds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen);
|
||||
|
||||
if (pnd->nc == NC_PN531) {
|
||||
// PN531 doesn't support hardware polling (InAutoPoll)
|
||||
// TODO find a way to handle this in higher level (i.e. libnfc)
|
||||
WARN ("%s", "PN531 doesn't support hardware polling.");
|
||||
continue;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,6 +84,9 @@ void print_hex_par(const byte_t* pbtData, const size_t szBits, const byte_t* pbt
|
|||
printf("\n");
|
||||
}
|
||||
|
||||
#define SAK_ISO14443_4_COMPLIANT 0x20
|
||||
#define SAK_ISO18092_COMPLIANT 0x40
|
||||
|
||||
void print_nfc_iso14443a_info(const nfc_iso14443a_info_t nai)
|
||||
{
|
||||
printf(" ATQA (SENS_RES): "); print_hex(nai.abtAtqa,2);
|
||||
|
|
@ -93,6 +96,28 @@ void print_nfc_iso14443a_info(const nfc_iso14443a_info_t nai)
|
|||
printf(" ATS (ATR): ");
|
||||
print_hex(nai.abtAts, nai.szAtsLen);
|
||||
}
|
||||
if ( (nai.btSak & SAK_ISO14443_4_COMPLIANT) || (nai.btSak & SAK_ISO18092_COMPLIANT) ) {
|
||||
printf(" Compliant with: ");
|
||||
if (nai.btSak & SAK_ISO14443_4_COMPLIANT) printf("ISO/IEC 14443-4 ");
|
||||
if (nai.btSak & SAK_ISO18092_COMPLIANT) printf("ISO/IEC 18092");
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
void print_nfc_felica_info(const nfc_felica_info_t nfi)
|
||||
{
|
||||
printf(" ID (NFCID2): "); print_hex(nfi.abtId,8);
|
||||
printf(" Parameter (PAD): "); print_hex(nfi.abtPad,8);
|
||||
}
|
||||
|
||||
void print_nfc_iso14443b_info(const nfc_iso14443b_info_t nbi)
|
||||
{
|
||||
printf(" ATQB: "); print_hex(nbi.abtAtqb,12);
|
||||
printf(" ID: "); print_hex(nbi.abtId,4);
|
||||
printf(" CID: %02x\n",nbi.btCid);
|
||||
if (nbi.szInfLen>0) {
|
||||
printf(" INF: "); print_hex(nbi.abtInf,nbi.szInfLen);
|
||||
}
|
||||
printf(" PARAMS: %02x %02x %02x %02x\n",nbi.btParam1,nbi.btParam2,nbi.btParam3,nbi.btParam4);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -31,7 +31,11 @@
|
|||
void print_hex(const byte_t* pbtData, const size_t szLen);
|
||||
void print_hex_bits(const byte_t* pbtData, const size_t szBits);
|
||||
void print_hex_par(const byte_t* pbtData, const size_t szBits, const byte_t* pbtDataPar);
|
||||
|
||||
void print_nfc_iso14443a_info(const nfc_iso14443a_info_t nai);
|
||||
void print_nfc_iso14443b_info(const nfc_iso14443b_info_t nbi);
|
||||
void print_nfc_felica_info(const nfc_felica_info_t nfi);
|
||||
|
||||
nfc_device_desc_t* parse_device_desc(int argc, const char *argv[], size_t* szFound);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue