Detect errors in examples.

This commit is contained in:
Romain Tartiere 2010-08-18 17:22:13 +00:00
parent 076fa3686c
commit eb90b92c12
9 changed files with 157 additions and 44 deletions

View file

@ -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) {

View file

@ -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);

View file

@ -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);
}

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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)

View file

@ -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.");