Detect errors in examples.
This commit is contained in:
parent
076fa3686c
commit
eb90b92c12
9 changed files with 157 additions and 44 deletions
|
@ -66,7 +66,10 @@ bool nfc_initiator_mifare_cmd(nfc_device_t* pnd, const mifare_cmd mc, const uint
|
||||||
if (szParamLen) memcpy(abtCmd+2,(byte_t*)pmp,szParamLen);
|
if (szParamLen) memcpy(abtCmd+2,(byte_t*)pmp,szParamLen);
|
||||||
|
|
||||||
// Fire the mifare command
|
// Fire the mifare command
|
||||||
if (!nfc_initiator_transceive_dep_bytes(pnd,abtCmd,2+szParamLen,abtRx,&szRxLen)) return false;
|
if (!nfc_initiator_transceive_dep_bytes(pnd,abtCmd,2+szParamLen,abtRx,&szRxLen)) {
|
||||||
|
nfc_perror (pnd, "nfc_initiator_transceive_dep_bytes");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// When we have executed a read command, copy the received bytes into the param
|
// When we have executed a read command, copy the received bytes into the param
|
||||||
if (mc == MC_READ) {
|
if (mc == MC_READ) {
|
||||||
|
|
|
@ -143,14 +143,28 @@ int main(int argc,char* argv[])
|
||||||
nfc_initiator_init(pnd);
|
nfc_initiator_init(pnd);
|
||||||
|
|
||||||
// Drop the field for a while
|
// Drop the field for a while
|
||||||
nfc_configure(pnd,NDO_ACTIVATE_FIELD,false);
|
if (!nfc_configure(pnd,NDO_ACTIVATE_FIELD,false)) {
|
||||||
|
nfc_perror (pnd, "nfc_configure");
|
||||||
|
exit (EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
// Configure the CRC and Parity settings
|
// Configure the CRC
|
||||||
nfc_configure(pnd,NDO_HANDLE_CRC,false);
|
if (!nfc_configure(pnd,NDO_HANDLE_CRC,false)) {
|
||||||
nfc_configure(pnd,NDO_HANDLE_PARITY,true);
|
nfc_perror (pnd, "nfc_configure");
|
||||||
|
exit (EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Configure parity settings
|
||||||
|
if (!nfc_configure(pnd,NDO_HANDLE_PARITY,true)) {
|
||||||
|
nfc_perror (pnd, "nfc_configure");
|
||||||
|
exit (EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
// Enable field so more power consuming cards can power themselves up
|
// Enable field so more power consuming cards can power themselves up
|
||||||
nfc_configure(pnd,NDO_ACTIVATE_FIELD,true);
|
if (!nfc_configure(pnd,NDO_ACTIVATE_FIELD,true)) {
|
||||||
|
nfc_perror (pnd, "nfc_configure");
|
||||||
|
exit (EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
printf("\nConnected to NFC reader: %s\n\n",pnd->acName);
|
printf("\nConnected to NFC reader: %s\n\n",pnd->acName);
|
||||||
|
|
||||||
|
|
|
@ -113,8 +113,10 @@ int main(int argc, char *argv[])
|
||||||
printf("[+] Received initiator command: ");
|
printf("[+] Received initiator command: ");
|
||||||
print_hex_bits(abtRecv,szRecvBits);
|
print_hex_bits(abtRecv,szRecvBits);
|
||||||
printf("[+] Configuring communication\n");
|
printf("[+] Configuring communication\n");
|
||||||
nfc_configure(pnd,NDO_HANDLE_CRC,false);
|
if (!nfc_configure(pnd,NDO_HANDLE_CRC,false) || !nfc_configure(pnd,NDO_HANDLE_PARITY,true)) {
|
||||||
nfc_configure(pnd,NDO_HANDLE_PARITY,true);
|
nfc_perror(pnd, "nfc_configure");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
printf("[+] Done, the emulated tag is initialized with UID: %02X%02X%02X%02X\n\n",abtUidBcc[0],abtUidBcc[1],abtUidBcc[2],abtUidBcc[3]);
|
printf("[+] Done, the emulated tag is initialized with UID: %02X%02X%02X%02X\n\n",abtUidBcc[0],abtUidBcc[1],abtUidBcc[2],abtUidBcc[3]);
|
||||||
|
|
||||||
while(true)
|
while(true)
|
||||||
|
@ -157,7 +159,10 @@ int main(int argc, char *argv[])
|
||||||
if(szTxBits)
|
if(szTxBits)
|
||||||
{
|
{
|
||||||
// Send and print the command to the screen
|
// Send and print the command to the screen
|
||||||
nfc_target_send_bits(pnd,pbtTx,szTxBits,NULL);
|
if (!nfc_target_send_bits(pnd,pbtTx,szTxBits,NULL)) {
|
||||||
|
nfc_perror(pnd, "nfc_target_send_bits");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
if(!quiet_output)
|
if(!quiet_output)
|
||||||
{
|
{
|
||||||
printf("T: ");
|
printf("T: ");
|
||||||
|
@ -168,5 +173,6 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
nfc_disconnect(pnd);
|
nfc_disconnect(pnd);
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -117,17 +117,32 @@ int main(int argc, const char* argv[])
|
||||||
nfc_initiator_init(pnd);
|
nfc_initiator_init(pnd);
|
||||||
|
|
||||||
// Drop the field for a while
|
// Drop the field for a while
|
||||||
nfc_configure(pnd,NDO_ACTIVATE_FIELD,false);
|
if (!nfc_configure(pnd,NDO_ACTIVATE_FIELD,false)) {
|
||||||
|
nfc_perror(pnd, "nfc_configure");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
// Let the reader only try once to find a tag
|
// Let the reader only try once to find a tag
|
||||||
nfc_configure(pnd,NDO_INFINITE_SELECT,false);
|
if (!nfc_configure(pnd,NDO_INFINITE_SELECT,false)) {
|
||||||
|
nfc_perror(pnd, "nfc_configure");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
// Configure the CRC and Parity settings
|
// Configure the CRC and Parity settings
|
||||||
nfc_configure(pnd,NDO_HANDLE_CRC,true);
|
if (!nfc_configure(pnd,NDO_HANDLE_CRC,true)) {
|
||||||
nfc_configure(pnd,NDO_HANDLE_PARITY,true);
|
nfc_perror(pnd, "nfc_configure");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
if (!nfc_configure(pnd,NDO_HANDLE_PARITY,true)) {
|
||||||
|
nfc_perror(pnd, "nfc_configure");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
// Enable field so more power consuming cards can power themselves up
|
// Enable field so more power consuming cards can power themselves up
|
||||||
nfc_configure(pnd,NDO_ACTIVATE_FIELD,true);
|
if (!nfc_configure(pnd,NDO_ACTIVATE_FIELD,true)) {
|
||||||
|
nfc_perror(pnd, "nfc_configure");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
printf("Connected to NFC reader: %s\n",pnd->acName);
|
printf("Connected to NFC reader: %s\n",pnd->acName);
|
||||||
|
|
||||||
|
|
|
@ -414,15 +414,30 @@ main (int argc, const char *argv[])
|
||||||
nfc_initiator_init (pnd);
|
nfc_initiator_init (pnd);
|
||||||
|
|
||||||
// Drop the field for a while
|
// Drop the field for a while
|
||||||
nfc_configure (pnd, NDO_ACTIVATE_FIELD, false);
|
if (!nfc_configure (pnd, NDO_ACTIVATE_FIELD, false)) {
|
||||||
|
nfc_perror(pnd, "nfc_configure");
|
||||||
|
exit (EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
// Let the reader only try once to find a tag
|
// Let the reader only try once to find a tag
|
||||||
nfc_configure (pnd, NDO_INFINITE_SELECT, false);
|
if (!nfc_configure (pnd, NDO_INFINITE_SELECT, false)) {
|
||||||
nfc_configure (pnd, NDO_HANDLE_CRC, true);
|
nfc_perror(pnd, "nfc_configure");
|
||||||
nfc_configure (pnd, NDO_HANDLE_PARITY, true);
|
exit (EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
if (!nfc_configure (pnd, NDO_HANDLE_CRC, true)) {
|
||||||
|
nfc_perror(pnd, "nfc_configure");
|
||||||
|
exit (EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
if (!nfc_configure (pnd, NDO_HANDLE_PARITY, true)) {
|
||||||
|
nfc_perror(pnd, "nfc_configure");
|
||||||
|
exit (EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
// Enable field so more power consuming cards can power themselves up
|
// Enable field so more power consuming cards can power themselves up
|
||||||
nfc_configure (pnd, NDO_ACTIVATE_FIELD, true);
|
if (!nfc_configure (pnd, NDO_ACTIVATE_FIELD, true)) {
|
||||||
|
nfc_perror(pnd, "nfc_configure");
|
||||||
|
exit (EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
printf ("Connected to NFC reader: %s\n", pnd->acName);
|
printf ("Connected to NFC reader: %s\n", pnd->acName);
|
||||||
|
|
||||||
|
|
|
@ -190,15 +190,30 @@ main (int argc, const char *argv[])
|
||||||
nfc_initiator_init (pnd);
|
nfc_initiator_init (pnd);
|
||||||
|
|
||||||
// Drop the field for a while
|
// Drop the field for a while
|
||||||
nfc_configure (pnd, NDO_ACTIVATE_FIELD, false);
|
if (!nfc_configure (pnd, NDO_ACTIVATE_FIELD, false)) {
|
||||||
|
nfc_perror(pnd, "nfc_configure");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
// Let the reader only try once to find a tag
|
// Let the reader only try once to find a tag
|
||||||
nfc_configure (pnd, NDO_INFINITE_SELECT, false);
|
if (!nfc_configure (pnd, NDO_INFINITE_SELECT, false)) {
|
||||||
nfc_configure (pnd, NDO_HANDLE_CRC, true);
|
nfc_perror(pnd, "nfc_configure");
|
||||||
nfc_configure (pnd, NDO_HANDLE_PARITY, true);
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
if (!nfc_configure (pnd, NDO_HANDLE_CRC, true)) {
|
||||||
|
nfc_perror(pnd, "nfc_configure");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
if (!nfc_configure (pnd, NDO_HANDLE_PARITY, true)) {
|
||||||
|
nfc_perror(pnd, "nfc_configure");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
// Enable field so more power consuming cards can power themselves up
|
// Enable field so more power consuming cards can power themselves up
|
||||||
nfc_configure (pnd, NDO_ACTIVATE_FIELD, true);
|
if (!nfc_configure (pnd, NDO_ACTIVATE_FIELD, true)) {
|
||||||
|
nfc_perror(pnd, "nfc_configure");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
printf ("Connected to NFC reader: %s\n", pnd->acName);
|
printf ("Connected to NFC reader: %s\n", pnd->acName);
|
||||||
|
|
||||||
|
|
|
@ -88,17 +88,32 @@ main (int argc, const char *argv[])
|
||||||
nfc_initiator_init (pnd);
|
nfc_initiator_init (pnd);
|
||||||
|
|
||||||
// Drop the field for a while
|
// Drop the field for a while
|
||||||
nfc_configure (pnd, NDO_ACTIVATE_FIELD, false);
|
if (!nfc_configure (pnd, NDO_ACTIVATE_FIELD, false)) {
|
||||||
|
nfc_perror(pnd, "nfc_configure");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
// Let the reader only try once to find a tag
|
// Let the reader only try once to find a tag
|
||||||
nfc_configure (pnd, NDO_INFINITE_SELECT, false);
|
if (!nfc_configure (pnd, NDO_INFINITE_SELECT, false)) {
|
||||||
|
nfc_perror(pnd, "nfc_configure");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
// Configure the CRC and Parity settings
|
// Configure the CRC and Parity settings
|
||||||
nfc_configure (pnd, NDO_HANDLE_CRC, true);
|
if (!nfc_configure (pnd, NDO_HANDLE_CRC, true)) {
|
||||||
nfc_configure (pnd, NDO_HANDLE_PARITY, true);
|
nfc_perror(pnd, "nfc_configure");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
if (!nfc_configure (pnd, NDO_HANDLE_PARITY, true)) {
|
||||||
|
nfc_perror(pnd, "nfc_configure");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
// Enable field so more power consuming cards can power themselves up
|
// Enable field so more power consuming cards can power themselves up
|
||||||
nfc_configure (pnd, NDO_ACTIVATE_FIELD, true);
|
if (!nfc_configure (pnd, NDO_ACTIVATE_FIELD, true)) {
|
||||||
|
nfc_perror(pnd, "nfc_configure");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
printf ("Connected to NFC reader: %s\n", pnd->acName);
|
printf ("Connected to NFC reader: %s\n", pnd->acName);
|
||||||
|
|
||||||
|
|
|
@ -132,9 +132,12 @@ int main(int argc,char* argv[])
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
printf("%s", "Configuring emulator settings...");
|
printf("%s", "Configuring emulator settings...");
|
||||||
nfc_configure(pndTag,NDO_HANDLE_CRC,false);
|
if (!nfc_configure(pndTag,NDO_HANDLE_CRC,false) ||
|
||||||
nfc_configure(pndTag,NDO_HANDLE_PARITY,false);
|
!nfc_configure(pndTag,NDO_HANDLE_PARITY,false) ||
|
||||||
nfc_configure(pndTag,NDO_ACCEPT_INVALID_FRAMES,true);
|
!nfc_configure(pndTag,NDO_ACCEPT_INVALID_FRAMES,true)) {
|
||||||
|
nfc_perror(pndTag, "nfc_configure");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
printf("%s", "Done, emulated tag is initialized");
|
printf("%s", "Done, emulated tag is initialized");
|
||||||
|
|
||||||
// Try to open the NFC reader
|
// Try to open the NFC reader
|
||||||
|
@ -143,9 +146,12 @@ int main(int argc,char* argv[])
|
||||||
printf("Connected to the NFC reader device: %s", pndReader->acName);
|
printf("Connected to the NFC reader device: %s", pndReader->acName);
|
||||||
printf("%s", "Configuring NFC reader settings...");
|
printf("%s", "Configuring NFC reader settings...");
|
||||||
nfc_initiator_init(pndReader);
|
nfc_initiator_init(pndReader);
|
||||||
nfc_configure(pndReader,NDO_HANDLE_CRC,false);
|
if (!nfc_configure(pndReader,NDO_HANDLE_CRC,false) ||
|
||||||
nfc_configure(pndReader,NDO_HANDLE_PARITY,false);
|
!nfc_configure(pndReader,NDO_HANDLE_PARITY,false) ||
|
||||||
nfc_configure(pndReader,NDO_ACCEPT_INVALID_FRAMES,true);
|
!nfc_configure(pndReader,NDO_ACCEPT_INVALID_FRAMES,true)) {
|
||||||
|
nfc_perror(pndReader, "nfc_configure");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
printf("%s", "Done, relaying frames now!");
|
printf("%s", "Done, relaying frames now!");
|
||||||
|
|
||||||
while(!quitting)
|
while(!quitting)
|
||||||
|
@ -157,10 +163,16 @@ int main(int argc,char* argv[])
|
||||||
if (szReaderRxBits == 7 && abtReaderRx[0] == 0x26)
|
if (szReaderRxBits == 7 && abtReaderRx[0] == 0x26)
|
||||||
{
|
{
|
||||||
// Drop down field for a very short time (original tag will reboot)
|
// Drop down field for a very short time (original tag will reboot)
|
||||||
nfc_configure(pndReader,NDO_ACTIVATE_FIELD,false);
|
if (!nfc_configure(pndReader,NDO_ACTIVATE_FIELD,false)) {
|
||||||
|
nfc_perror(pndReader, "nfc_configure");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
if(!quiet_output)
|
if(!quiet_output)
|
||||||
printf("\n");
|
printf("\n");
|
||||||
nfc_configure(pndReader,NDO_ACTIVATE_FIELD,true);
|
if (!nfc_configure(pndReader,NDO_ACTIVATE_FIELD,true)) {
|
||||||
|
nfc_perror(pndReader, "nfc_configure");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Print the reader frame to the screen
|
// Print the reader frame to the screen
|
||||||
|
@ -173,7 +185,10 @@ int main(int argc,char* argv[])
|
||||||
if (nfc_initiator_transceive_bits(pndReader,abtReaderRx,szReaderRxBits,abtReaderRxPar,abtTagRx,&szTagRxBits,abtTagRxPar))
|
if (nfc_initiator_transceive_bits(pndReader,abtReaderRx,szReaderRxBits,abtReaderRxPar,abtTagRx,&szTagRxBits,abtTagRxPar))
|
||||||
{
|
{
|
||||||
// Redirect the answer back to the reader
|
// Redirect the answer back to the reader
|
||||||
nfc_target_send_bits(pndTag,abtTagRx,szTagRxBits,abtTagRxPar);
|
if (!nfc_target_send_bits(pndTag,abtTagRx,szTagRxBits,abtTagRxPar)) {
|
||||||
|
nfc_perror(pndTag, "nfc_target_send_bits");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
// Print the tag frame to the screen
|
// Print the tag frame to the screen
|
||||||
if(!quiet_output)
|
if(!quiet_output)
|
||||||
|
|
|
@ -167,17 +167,32 @@ int main(int argc, const char* argv[])
|
||||||
nfc_initiator_init(pnd);
|
nfc_initiator_init(pnd);
|
||||||
|
|
||||||
// Drop the field for a while
|
// Drop the field for a while
|
||||||
nfc_configure(pnd,NDO_ACTIVATE_FIELD,false);
|
if (!nfc_configure(pnd,NDO_ACTIVATE_FIELD,false)) {
|
||||||
|
nfc_perror(pnd, "nfc_configure");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
// Let the reader only try once to find a tag
|
// Let the reader only try once to find a tag
|
||||||
nfc_configure(pnd,NDO_INFINITE_SELECT,false);
|
if (!nfc_configure(pnd,NDO_INFINITE_SELECT,false)) {
|
||||||
|
nfc_perror(pnd, "nfc_configure");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
// Configure the CRC and Parity settings
|
// Configure the CRC and Parity settings
|
||||||
nfc_configure(pnd,NDO_HANDLE_CRC,true);
|
if (!nfc_configure(pnd,NDO_HANDLE_CRC,true)) {
|
||||||
nfc_configure(pnd,NDO_HANDLE_PARITY,true);
|
nfc_perror(pnd, "nfc_configure");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
if (!nfc_configure(pnd,NDO_HANDLE_PARITY,true)) {
|
||||||
|
nfc_perror(pnd, "nfc_configure");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
// Enable field so more power consuming cards can power themselves up
|
// Enable field so more power consuming cards can power themselves up
|
||||||
nfc_configure(pnd,NDO_ACTIVATE_FIELD,true);
|
if (!nfc_configure(pnd,NDO_ACTIVATE_FIELD,true)) {
|
||||||
|
nfc_perror(pnd, "nfc_configure");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
// Read the SAM's info
|
// Read the SAM's info
|
||||||
if (!nfc_initiator_select_passive_target(pnd,NM_ISO14443A_106,NULL,0,&nti)) {
|
if (!nfc_initiator_select_passive_target(pnd,NM_ISO14443A_106,NULL,0,&nti)) {
|
||||||
|
|
Loading…
Reference in a new issue