diff --git a/examples/mifare.c b/examples/mifare.c index d436812..75a0b76 100644 --- a/examples/mifare.c +++ b/examples/mifare.c @@ -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); // 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 if (mc == MC_READ) { diff --git a/examples/nfc-anticol.c b/examples/nfc-anticol.c index b1cd476..477eb08 100644 --- a/examples/nfc-anticol.c +++ b/examples/nfc-anticol.c @@ -143,14 +143,28 @@ int main(int argc,char* argv[]) nfc_initiator_init(pnd); // 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 - nfc_configure(pnd,NDO_HANDLE_CRC,false); - nfc_configure(pnd,NDO_HANDLE_PARITY,true); + // Configure the CRC + if (!nfc_configure(pnd,NDO_HANDLE_CRC,false)) { + 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 - 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); diff --git a/examples/nfc-emulate.c b/examples/nfc-emulate.c index 3e3036e..1652f8f 100644 --- a/examples/nfc-emulate.c +++ b/examples/nfc-emulate.c @@ -113,8 +113,10 @@ int main(int argc, char *argv[]) printf("[+] Received initiator command: "); print_hex_bits(abtRecv,szRecvBits); printf("[+] Configuring communication\n"); - nfc_configure(pnd,NDO_HANDLE_CRC,false); - nfc_configure(pnd,NDO_HANDLE_PARITY,true); + if (!nfc_configure(pnd,NDO_HANDLE_CRC,false) || !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]); while(true) @@ -157,7 +159,10 @@ int main(int argc, char *argv[]) if(szTxBits) { // 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) { printf("T: "); @@ -168,5 +173,6 @@ int main(int argc, char *argv[]) } nfc_disconnect(pnd); + exit(EXIT_SUCCESS); } diff --git a/examples/nfc-list.c b/examples/nfc-list.c index b6249d0..24a2e18 100644 --- a/examples/nfc-list.c +++ b/examples/nfc-list.c @@ -117,17 +117,32 @@ int main(int argc, const char* argv[]) nfc_initiator_init(pnd); // 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 - 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 - nfc_configure(pnd,NDO_HANDLE_CRC,true); - nfc_configure(pnd,NDO_HANDLE_PARITY,true); + 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 - 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); diff --git a/examples/nfc-mfclassic.c b/examples/nfc-mfclassic.c index 7b1e628..c53a394 100644 --- a/examples/nfc-mfclassic.c +++ b/examples/nfc-mfclassic.c @@ -414,15 +414,30 @@ main (int argc, const char *argv[]) nfc_initiator_init (pnd); // 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 - nfc_configure (pnd, NDO_INFINITE_SELECT, false); - nfc_configure (pnd, NDO_HANDLE_CRC, true); - nfc_configure (pnd, NDO_HANDLE_PARITY, true); + if (!nfc_configure (pnd, NDO_INFINITE_SELECT, false)) { + nfc_perror(pnd, "nfc_configure"); + 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 - 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); diff --git a/examples/nfc-mfultralight.c b/examples/nfc-mfultralight.c index 5e59446..a2fe548 100644 --- a/examples/nfc-mfultralight.c +++ b/examples/nfc-mfultralight.c @@ -190,15 +190,30 @@ main (int argc, const char *argv[]) nfc_initiator_init (pnd); // 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 - nfc_configure (pnd, NDO_INFINITE_SELECT, false); - nfc_configure (pnd, NDO_HANDLE_CRC, true); - nfc_configure (pnd, NDO_HANDLE_PARITY, true); + if (!nfc_configure (pnd, NDO_INFINITE_SELECT, false)) { + nfc_perror(pnd, "nfc_configure"); + 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 - 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); diff --git a/examples/nfc-poll.c b/examples/nfc-poll.c index 304816a..b2426d3 100644 --- a/examples/nfc-poll.c +++ b/examples/nfc-poll.c @@ -88,17 +88,32 @@ main (int argc, const char *argv[]) nfc_initiator_init (pnd); // 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 - 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 - nfc_configure (pnd, NDO_HANDLE_CRC, true); - nfc_configure (pnd, NDO_HANDLE_PARITY, true); + 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 - 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); diff --git a/examples/nfc-relay.c b/examples/nfc-relay.c index 99dfa71..d0b06ae 100644 --- a/examples/nfc-relay.c +++ b/examples/nfc-relay.c @@ -132,9 +132,12 @@ int main(int argc,char* argv[]) return EXIT_FAILURE; } printf("%s", "Configuring emulator settings..."); - nfc_configure(pndTag,NDO_HANDLE_CRC,false); - nfc_configure(pndTag,NDO_HANDLE_PARITY,false); - nfc_configure(pndTag,NDO_ACCEPT_INVALID_FRAMES,true); + if (!nfc_configure(pndTag,NDO_HANDLE_CRC,false) || + !nfc_configure(pndTag,NDO_HANDLE_PARITY,false) || + !nfc_configure(pndTag,NDO_ACCEPT_INVALID_FRAMES,true)) { + nfc_perror(pndTag, "nfc_configure"); + exit(EXIT_FAILURE); + } printf("%s", "Done, emulated tag is initialized"); // 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("%s", "Configuring NFC reader settings..."); nfc_initiator_init(pndReader); - nfc_configure(pndReader,NDO_HANDLE_CRC,false); - nfc_configure(pndReader,NDO_HANDLE_PARITY,false); - nfc_configure(pndReader,NDO_ACCEPT_INVALID_FRAMES,true); + if (!nfc_configure(pndReader,NDO_HANDLE_CRC,false) || + !nfc_configure(pndReader,NDO_HANDLE_PARITY,false) || + !nfc_configure(pndReader,NDO_ACCEPT_INVALID_FRAMES,true)) { + nfc_perror(pndReader, "nfc_configure"); + exit(EXIT_FAILURE); + } printf("%s", "Done, relaying frames now!"); while(!quitting) @@ -157,10 +163,16 @@ int main(int argc,char* argv[]) if (szReaderRxBits == 7 && abtReaderRx[0] == 0x26) { // 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) 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 @@ -173,7 +185,10 @@ int main(int argc,char* argv[]) if (nfc_initiator_transceive_bits(pndReader,abtReaderRx,szReaderRxBits,abtReaderRxPar,abtTagRx,&szTagRxBits,abtTagRxPar)) { // 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 if(!quiet_output) diff --git a/examples/nfc-sam.c b/examples/nfc-sam.c index 547d6da..6a744e0 100644 --- a/examples/nfc-sam.c +++ b/examples/nfc-sam.c @@ -167,18 +167,33 @@ int main(int argc, const char* argv[]) nfc_initiator_init(pnd); // 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 - 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 - nfc_configure(pnd,NDO_HANDLE_CRC,true); - nfc_configure(pnd,NDO_HANDLE_PARITY,true); + 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 - 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 if (!nfc_initiator_select_passive_target(pnd,NM_ISO14443A_106,NULL,0,&nti)) { ERR("%s", "Reading of SAM info failed.");