Attempt to provide clean types for API

This commit is contained in:
Romuald Conty 2010-10-13 17:43:23 +00:00
parent 9020014160
commit d289eabc36
19 changed files with 437 additions and 311 deletions

View file

@ -62,7 +62,7 @@ main (int argc, const char *argv[])
return EXIT_FAILURE;
}
if(!nfc_initiator_select_dep_target (pnd, PM_PASSIVE_DEP, NULL, &nti)) {
if(!nfc_initiator_select_dep_target (pnd, false, NULL, &nti)) {
nfc_perror(pnd, "nfc_initiator_select_dep_target");
return EXIT_FAILURE;
}

View file

@ -66,7 +66,7 @@ main (int argc, const char *argv[])
}
const nfc_target_t nt = {
.ptt = PTT_DEP_PASSIVE_106,
.nmt = NMT_DEP,
.nti.ndi.abtNFCID3 = { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xff, 0x00, 0x00 },
.nti.ndi.szGB = 4,
.nti.ndi.abtGB = { 0x12, 0x34, 0x56, 0x78 },

View file

@ -112,7 +112,7 @@ main (int argc, char *argv[])
printf ("Emulating NDEF tag now, please touch it with a second NFC device\n");
nfc_target_t nt = {
.ptt = PTT_MIFARE,
.nmt = NMT_ISO14443A,
.nti.nai.abtAtqa = { 0x00, 0x04 },
.nti.nai.abtUid = { 0x08, 0x00, 0xb0, 0x0b },
.nti.nai.btSak = 0x20,

View file

@ -173,7 +173,7 @@ main (int argc, char *argv[])
// Example of a Mifare Classic Mini
// Note that crypto1 is not implemented in this example
nfc_target_t nt = {
.ptt = PTT_MIFARE,
.nmt = NMT_ISO14443A,
.nti.nai.abtAtqa = { 0x00, 0x04 },
.nti.nai.abtUid = { 0x08, 0xab, 0xcd, 0xef },
.nti.nai.btSak = 0x09,
@ -183,7 +183,7 @@ main (int argc, char *argv[])
/*
// Example of a FeliCa
nfc_target_t nt = {
.ptt = PTT_FELICA_212,
.nmt = NMT_FELICA,
.nti.nfi.abtId = { 0x01, 0xFE, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF },
.nti.nfi.abtPad = { 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF },
.nti.nfi.abtSysCode = { 0xFF, 0xFF },
@ -192,7 +192,7 @@ main (int argc, char *argv[])
/*
// Example of a ISO14443-4 (DESfire)
nfc_target_t nt = {
.ptt = PTT_MIFARE,
.nmt = NMT_ISO14443A,
.nti.nai.abtAtqa = { 0x03, 0x44 },
.nti.nai.abtUid = { 0x08, 0xab, 0xcd, 0xef },
.nti.nai.btSak = 0x20,

View file

@ -132,7 +132,7 @@ main (int argc, char *argv[])
// Note: We have to build a "fake" nfc_target_t in order to do exactly the same that was done before the new nfc_target_init() was introduced.
nfc_target_t nt = {
.ptt = PTT_MIFARE,
.nmt = NMT_ISO14443A,
.nti.nai.abtAtqa = { 0x04, 0x00 },
.nti.nai.abtUid = { 0xde, 0xad, 0xbe, 0xaf },
.nti.nai.btSak = 0x20,

View file

@ -142,7 +142,11 @@ main (int argc, const char *argv[])
printf ("Connected to NFC device: %s\n", pnd->acName);
// List ISO14443A targets
if (nfc_initiator_list_passive_targets (pnd, PM_ISO14443A_106, anti, MAX_TARGET_COUNT, &szTargetFound)) {
nfc_modulation_t nm = {
.nmt = NMT_ISO14443A,
.nbr = NBR_106,
};
if (nfc_initiator_list_passive_targets (pnd, nm, anti, MAX_TARGET_COUNT, &szTargetFound)) {
size_t n;
printf ("%d ISO14443A passive target(s) was found%s\n", (int) szTargetFound, (szTargetFound == 0) ? ".\n" : ":");
for (n = 0; n < szTargetFound; n++) {
@ -150,8 +154,11 @@ main (int argc, const char *argv[])
printf ("\n");
}
}
nm.nmt = NMT_FELICA;
nm.nbr = NBR_212;
// List Felica tags
if (nfc_initiator_list_passive_targets (pnd, PM_FELICA_212, anti, MAX_TARGET_COUNT, &szTargetFound)) {
if (nfc_initiator_list_passive_targets (pnd, nm, anti, MAX_TARGET_COUNT, &szTargetFound)) {
size_t n;
printf ("%d Felica (212 kbps) passive target(s) was found%s\n", (int) szTargetFound,
(szTargetFound == 0) ? ".\n" : ":");
@ -160,7 +167,9 @@ main (int argc, const char *argv[])
printf ("\n");
}
}
if (nfc_initiator_list_passive_targets (pnd, PM_FELICA_424, anti, MAX_TARGET_COUNT, &szTargetFound)) {
nm.nbr = NBR_424;
if (nfc_initiator_list_passive_targets (pnd, nm, anti, MAX_TARGET_COUNT, &szTargetFound)) {
size_t n;
printf ("%d Felica (424 kbps) passive target(s) was found%s\n", (int) szTargetFound,
(szTargetFound == 0) ? ".\n" : ":");
@ -169,8 +178,11 @@ main (int argc, const char *argv[])
printf ("\n");
}
}
nm.nmt = NMT_ISO14443B;
nm.nbr = NBR_106;
// List ISO14443B targets
if (nfc_initiator_list_passive_targets (pnd, PM_ISO14443B_106, anti, MAX_TARGET_COUNT, &szTargetFound)) {
if (nfc_initiator_list_passive_targets (pnd, nm, anti, MAX_TARGET_COUNT, &szTargetFound)) {
size_t n;
printf ("%d ISO14443B passive target(s) was found%s\n", (int) szTargetFound, (szTargetFound == 0) ? ".\n" : ":");
for (n = 0; n < szTargetFound; n++) {
@ -179,8 +191,10 @@ main (int argc, const char *argv[])
}
}
nm.nmt = NMT_JEWEL;
nm.nbr = NBR_106;
// List Jewel targets
if (nfc_initiator_list_passive_targets(pnd, PM_JEWEL_106, anti, MAX_TARGET_COUNT, &szTargetFound )) {
if (nfc_initiator_list_passive_targets(pnd, nm, anti, MAX_TARGET_COUNT, &szTargetFound )) {
size_t n;
printf("%d Jewel passive target(s) was found%s\n", (int)szTargetFound, (szTargetFound==0)?".\n":":");
for(n=0; n<szTargetFound; n++) {

View file

@ -60,6 +60,11 @@ static byte_t keys[] = {
0xab, 0xcd, 0xef, 0x12, 0x34, 0x56
};
static const nfc_modulation_t nmMifare = {
.nmt = NMT_ISO14443A,
.nbr = NBR_106,
};
static size_t num_keys = sizeof (keys) / 6;
static void
@ -150,7 +155,7 @@ authenticate (uint32_t uiBlock)
return true;
}
nfc_initiator_select_passive_target (pnd, PM_ISO14443A_106, mp.mpa.abtUid, 4, NULL);
nfc_initiator_select_passive_target (pnd, nmMifare, mp.mpa.abtUid, 4, NULL);
}
}
@ -177,7 +182,7 @@ read_card (void)
// Show if the readout went well
if (bFailure) {
// When a failure occured we need to redo the anti-collision
if (!nfc_initiator_select_passive_target (pnd, PM_ISO14443A_106, NULL, 0, &nti)) {
if (!nfc_initiator_select_passive_target (pnd, nmMifare, NULL, 0, &nti)) {
printf ("!\nError: tag was removed\n");
return false;
}
@ -242,7 +247,7 @@ write_card (void)
// Show if the readout went well
if (bFailure) {
// When a failure occured we need to redo the anti-collision
if (!nfc_initiator_select_passive_target (pnd, PM_ISO14443A_106, NULL, 0, &nti)) {
if (!nfc_initiator_select_passive_target (pnd, nmMifare, NULL, 0, &nti)) {
printf ("!\nError: tag was removed\n");
return false;
}
@ -442,7 +447,7 @@ main (int argc, const char *argv[])
printf ("Connected to NFC reader: %s\n", pnd->acName);
// Try to find a MIFARE Classic tag
if (!nfc_initiator_select_passive_target (pnd, PM_ISO14443A_106, NULL, 0, &nti)) {
if (!nfc_initiator_select_passive_target (pnd, nmMifare, NULL, 0, &nti)) {
printf ("Error: no tag was found\n");
nfc_disconnect (pnd);
exit (EXIT_FAILURE);

View file

@ -47,6 +47,11 @@ static mifare_param mp;
static mifareul_tag mtDump;
static uint32_t uiBlocks = 0xF;
static const nfc_modulation_t nmMifare = {
.nmt = NMT_ISO14443A,
.nbr = NBR_106,
};
static void
print_success_or_failure (bool bFailure, uint32_t * uiCounter)
{
@ -116,7 +121,7 @@ write_card (void)
// Show if the readout went well
if (bFailure) {
// When a failure occured we need to redo the anti-collision
if (!nfc_initiator_select_passive_target (pnd, PM_ISO14443A_106, NULL, 0, &nti)) {
if (!nfc_initiator_select_passive_target (pnd, nmMifare, NULL, 0, &nti)) {
ERR ("tag was removed");
return false;
}
@ -216,7 +221,7 @@ main (int argc, const char *argv[])
printf ("Connected to NFC device: %s\n", pnd->acName);
// Try to find a MIFARE Ultralight tag
if (!nfc_initiator_select_passive_target (pnd, PM_ISO14443A_106, NULL, 0, &nti)) {
if (!nfc_initiator_select_passive_target (pnd, nmMifare, NULL, 0, &nti)) {
ERR ("no tag was found\n");
nfc_disconnect (pnd);
return 1;

View file

@ -72,8 +72,14 @@ main (int argc, const char *argv[])
const byte_t btPollNr = 20;
const byte_t btPeriod = 2;
const pn53x_target_type_t pttArray[5] = {PTT_GENERIC_PASSIVE_106, PTT_GENERIC_PASSIVE_212, PTT_GENERIC_PASSIVE_424, PTT_ISO14443_4B_106, PTT_JEWEL_106};
const size_t szTargetTypes = 5;
const nfc_modulation_t nmModulations[5] = {
{ .nmt = NMT_ISO14443A, .nbr = NBR_106 },
{ .nmt = NMT_ISO14443B, .nbr = NBR_106 },
{ .nmt = NMT_FELICA, .nbr = NBR_212 },
{ .nmt = NMT_FELICA, .nbr = NBR_424 },
{ .nmt = NMT_JEWEL, .nbr = NBR_106 },
};
const size_t szModulations = 5;
nfc_target_t antTargets[2];
size_t szTargetFound;
@ -105,57 +111,15 @@ main (int argc, const char *argv[])
printf ("Connected to NFC reader: %s\n", pnd->acName);
printf ("PN532 will poll during %ld ms\n", (unsigned long) btPollNr * szTargetTypes * btPeriod * 150);
res = nfc_initiator_poll_targets (pnd, pttArray, szTargetTypes, btPollNr, btPeriod, antTargets, &szTargetFound);
printf ("PN532 will poll during %ld ms\n", (unsigned long) btPollNr * szModulations * btPeriod * 150);
res = nfc_initiator_poll_targets (pnd, nmModulations, szModulations, btPollNr, btPeriod, antTargets, &szTargetFound);
if (res) {
uint8_t n;
printf ("%ld target(s) have been found.\n", (unsigned long) szTargetFound);
for (n = 0; n < szTargetFound; n++) {
printf ("T%d: targetType=%02x ", n + 1, antTargets[n].ptt);
switch(antTargets[n].ptt) {
case PTT_JEWEL_106:
printf ("(Innovision Jewel tag), targetData:\n");
print_nfc_jewel_info (antTargets[n].nti.nji);
break;
case PTT_MIFARE:
printf ("(Mifare card), targetData:\n");
print_nfc_iso14443a_info (antTargets[n].nti.nai);
break;
case PTT_FELICA_212:
printf ("(FeliCa 212 kbps card), targetData:\n");
print_nfc_felica_info (antTargets[n].nti.nfi);
break;
case PTT_FELICA_424:
printf ("(FeliCa 212 kbps card), targetData:\n");
print_nfc_felica_info (antTargets[n].nti.nfi);
break;
case PTT_ISO14443_4A_106:
printf ("(Passive 106 kbps ISO/IEC 14443-4A card), targetData:\n");
print_nfc_iso14443a_info (antTargets[n].nti.nai);
break;
case PTT_ISO14443_4B_TCL_106:
printf ("(Passive 106 kbps ISO/IEC 14443-4B card), targetData:\n");
print_nfc_iso14443b_info (antTargets[n].nti.nbi);
break;
case PTT_DEP_PASSIVE_106:
printf ("(DEP passive 106 kbps)\n");
break;
case PTT_DEP_PASSIVE_212:
printf ("(DEP passive 212 kbps)\n");
break;
case PTT_DEP_PASSIVE_424:
printf ("(DEP passive 424 kbps)\n");
break;
case PTT_DEP_ACTIVE_106:
printf ("(DEP active 106 kbps)\n");
break;
case PTT_DEP_ACTIVE_212:
printf ("(DEP active 212 kbps)\n");
break;
case PTT_DEP_ACTIVE_424:
printf ("(DEP active 424 kbps)\n");
break;
};
printf ("T%d: targetType=%02x ", n + 1, antTargets[n].nmt);
print_nfc_target ( antTargets[n] );
}
} else {
nfc_perror (pnd, "nfc_initiator_poll_targets");

View file

@ -127,7 +127,7 @@ main (int argc, char *argv[])
printf ("[+] For example, send a RATS command or use the \"nfc-anticol\" tool\n");
nfc_target_t nt = {
.ptt = PTT_MIFARE,
.nmt = NMT_ISO14443A,
.nti.nai.abtAtqa = { 0x04, 0x00 },
.nti.nai.abtUid = { 0xde, 0xad, 0xbe, 0xef },
.nti.nai.btSak = 0x20,

View file

@ -212,60 +212,6 @@ print_nfc_dep_info (const nfc_dep_info_t ndi)
}
}
void print_nfc_target_type( const pn53x_target_type_t ptt )
{
switch (ptt) {
case PTT_GENERIC_PASSIVE_106:
printf ("Generic passive 106 kbps (ISO/IEC14443-4A, mifare, DEP)\n");
break;
case PTT_GENERIC_PASSIVE_212:
printf ("Generic passive 212 kbps (FeliCa, DEP)\n");
break;
case PTT_GENERIC_PASSIVE_424:
printf ("Generic passive 424 kbps (FeliCa, DEP)\n");
break;
case PTT_ISO14443_4B_106:
printf ("Passive 106 kbps ISO/IEC14443-4B\n");
break;
case PTT_JEWEL_106:
printf ("Innovision Jewel tag\n");
break;
case PTT_MIFARE:
printf ("mifare card\n");
break;
case PTT_FELICA_212:
printf ("FeliCa 212 kbps card\n");
break;
case PTT_FELICA_424:
printf ("FeliCa 424 kbps card\n");
break;
case PTT_ISO14443_4A_106:
printf ("Passive 106 kbps ISO/IEC14443-4A\n");
break;
case PTT_ISO14443_4B_TCL_106:
printf ("Passive 106 kbps ISO/IEC14443-4B with TCL flag\n");
break;
case PTT_DEP_PASSIVE_106:
printf ("DEP passive 106 kbps\n");
break;
case PTT_DEP_PASSIVE_212:
printf ("DEP passive 212 kbps\n");
break;
case PTT_DEP_PASSIVE_424:
printf ("DEP passive 424 kbps\n");
break;
case PTT_DEP_ACTIVE_106:
printf ("DEP active 106 kbps\n");
break;
case PTT_DEP_ACTIVE_212:
printf ("DEP active 212 kbps\n");
break;
case PTT_DEP_ACTIVE_424:
printf ("DEP active 424 kbps\n");
break;
}
}
/**
* @brief Tries to parse arguments to find device descriptions.
* @return Returns the list of found device descriptions.
@ -308,3 +254,30 @@ parse_device_desc (int argc, const char *argv[], size_t * szFound)
return pndd;
}
void
print_nfc_target (const nfc_target_t nt)
{
switch(nt.nmt) {
case NMT_ISO14443A:
printf ("ISO/IEC 14443A target:\n");
print_nfc_iso14443a_info (nt.nti.nai);
break;
case NMT_JEWEL:
printf ("Innovision Jewel target:\n");
print_nfc_jewel_info (nt.nti.nji);
break;
case NMT_FELICA:
printf ("FeliCa target:\n");
print_nfc_felica_info (nt.nti.nfi);
break;
case NMT_ISO14443B:
printf ("ISO/IEC 14443-4B target:\n");
print_nfc_iso14443b_info (nt.nti.nbi);
break;
case NMT_DEP:
printf ("D.E.P. target:\n");
print_nfc_dep_info (nt.nti.ndi);
break;
}
};

View file

@ -40,8 +40,6 @@ void print_nfc_felica_info (const nfc_felica_info_t nfi);
void print_nfc_jewel_info (const nfc_jewel_info_t nji);
void print_nfc_dep_info (const nfc_dep_info_t ndi);
void print_nfc_target_type( const pn53x_target_type_t ptt );
nfc_device_desc_t *parse_device_desc (int argc, const char *argv[], size_t * szFound);
#endif

View file

@ -181,7 +181,11 @@ main (int argc, const char *argv[])
exit (EXIT_FAILURE);
}
// Read the SAM's info
if (!nfc_initiator_select_passive_target (pnd, PM_ISO14443A_106, NULL, 0, &nti)) {
const nfc_modulation_t nmSAM = {
.nmt = NMT_ISO14443A,
.nbr = NBR_106,
};
if (!nfc_initiator_select_passive_target (pnd, nmSAM, NULL, 0, &nti)) {
nfc_perror (pnd, "nfc_initiator_select_passive_target");
ERR ("%s", "Reading of SAM info failed.");
return EXIT_FAILURE;
@ -198,7 +202,7 @@ main (int argc, const char *argv[])
size_t szRx;
nfc_target_t nt = {
.ptt = PTT_MIFARE,
.nmt = NMT_ISO14443A,
.nti.nai.abtAtqa = { 0x04, 0x00 },
.nti.nai.abtUid = { 0x08, 0xad, 0xbe, 0xaf },
.nti.nai.btSak = 0x20,