DEP enhancements:

- Add timeout on InJumpForDEP (pn53x) and initiator_select_dep (libnfc API)
- test_dep now works again (except 424Kbps)
- Fix ndi.ndm feeling when select a DEP target
Important: test_dep does not work on PN53x_USB devices after running previous tests
This commit is contained in:
Romuald Conty 2011-12-06 10:05:35 +00:00
parent 3b657ee547
commit c286eec920
8 changed files with 123 additions and 47 deletions

View file

@ -55,10 +55,10 @@ void *
target_thread (void *arg)
{
intptr_t thread_res = 0;
// nfc_device *device = ((struct thread_data *) arg)->device;
nfc_device *device = ((struct thread_data *) arg)->device;
cut_set_current_test_context (((struct thread_data *) arg)->cut_test_context);
#if 0
printf ("=========== TARGET %s =========\n", nfc_device_name (device));
nfc_target nt = {
.nm = {
.nmt = NMT_DEP,
@ -69,7 +69,7 @@ target_thread (void *arg)
.abtNFCID3 = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA },
.szGB = 4,
.abtGB = { 0x12, 0x34, 0x56, 0x78 },
.ndm = NDM_UNDEFINED,
.ndm = NDM_PASSIVE,
/* These bytes are not used by nfc_target_init: the chip will provide them automatically to the initiator */
.btDID = 0x00,
.btBS = 0x00,
@ -83,21 +83,46 @@ target_thread (void *arg)
uint8_t abtRx[1024];
size_t szRx = sizeof (abtRx);
bool res = nfc_target_init (device, &nt, abtRx, &szRx);
// cut_assert_true (res, cut_message ("Can't initialize NFC device as target"));
cut_assert_true (res, cut_message ("Can't initialize NFC device as target: %s", nfc_strerror (device)));
uint8_t abtAtrRes[] = "\x11\xd4\x00\x01\xfe\x12\x34\x56\x78\x90\x12\x00\x00\x00\x00\x00\x00";
// cut_assert_equal_memory (abtAtrRes, sizeof (abtAtrRes) - 1, abtRx, szRx, cut_message ("Invalid received ATR_RES"));
const uint8_t abtAtrRes[] = "\x11\xd4\x00\x01\xfe\x12\x34\x56\x78\x90\x12\x00\x00\x00\x00\x00\x00";
cut_assert_equal_memory (abtAtrRes, sizeof (abtAtrRes) - 1, abtRx, szRx, cut_message ("Invalid received ATR_RES"));
if (!res) { thread_res = -1; return (void*) thread_res; }
res = nfc_target_receive_bytes (device, abtRx, &szRx);
// cut_assert_true (res, cut_message ("Can't receive bytes from initiator"));
// First pass
res = nfc_target_receive_bytes (device, abtRx, &szRx, 500);
cut_assert_true (res, cut_message ("Can't receive bytes from initiator: %s", nfc_strerror (device)));
uint8_t abtAttRx[] = "Hello DEP target!";
// cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data"));
const uint8_t abtAttRx[] = "Hello DEP target!";
cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data"));
if (!res) { thread_res = -1; return (void*) thread_res; }
uint8_t abtTx[] = "Hello DEP initiator!";
res = nfc_target_send_bytes (device, abtTx, sizeof(abtTx));
// cut_assert_true (res, cut_message ("Can't send bytes to initiator"));
#endif
const uint8_t abtTx[] = "Hello DEP initiator!";
res = nfc_target_send_bytes (device, abtTx, sizeof(abtTx), 500);
cut_assert_true (res, cut_message ("Can't send bytes to initiator: %s", nfc_strerror (device)));
if (!res) { thread_res = -1; return (void*) thread_res; }
// Second pass
res = nfc_target_receive_bytes (device, abtRx, &szRx, 500);
cut_assert_true (res, cut_message ("Can't receive bytes from initiator: %s", nfc_strerror (device)));
cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data"));
if (!res) { thread_res = -1; return (void*) thread_res; }
res = nfc_target_send_bytes (device, abtTx, sizeof(abtTx), 500);
cut_assert_true (res, cut_message ("Can't send bytes to initiator: %s", nfc_strerror (device)));
if (!res) { thread_res = -1; return (void*) thread_res; }
// Third pass
res = nfc_target_receive_bytes (device, abtRx, &szRx, 500);
cut_assert_true (res, cut_message ("Can't receive bytes from initiator: %s", nfc_strerror (device)));
cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data"));
if (!res) { thread_res = -1; return (void*) thread_res; }
res = nfc_target_send_bytes (device, abtTx, sizeof(abtTx), 500);
cut_assert_true (res, cut_message ("Can't send bytes to initiator: %s", nfc_strerror (device)));
if (!res) { thread_res = -1; return (void*) thread_res; }
return (void *) thread_res;
}
@ -106,45 +131,90 @@ void *
initiator_thread (void *arg)
{
intptr_t thread_res = 0;
// nfc_device *device = ((struct thread_data *) arg)->device;
nfc_device *device = ((struct thread_data *) arg)->device;
cut_set_current_test_context (((struct thread_data *) arg)->cut_test_context);
cut_fail("plop");
#if 0
/*
* Wait some time for the other thread to initialise NFC device as target
*/
sleep (1);
printf ("====================================\n");
printf ("Activating initiator...\n");
printf ("=========== INITIATOR %s =========\n", nfc_device_name (device));
bool res = nfc_initiator_init (device);
// cut_assert_true (res, cut_message ("Can't initialize NFC device as initiator"));
cut_assert_true (res, cut_message ("Can't initialize NFC device as initiator: %s", nfc_strerror (device)));
if (!res) { thread_res = -1; return (void*) thread_res; }
nfc_target nt;
// Passive mode / 212Kbps
res = nfc_initiator_select_dep_target (device, NDM_PASSIVE, NBR_212, NULL, &nt);
// cut_assert_true (res, cut_message ("Can't select any DEP target"));
// cut_assert_equal_int (NMT_DEP, nt.nm.nmt, cut_message ("Invalid target modulation"));
// cut_assert_equal_int (NBR_212, nt.nm.nbr, cut_message ("Invalid target baud rate"));
// cut_assert_equal_memory ("\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA", 10, nt.nti.ndi.abtNFCID3, 10, cut_message ("Invalid target NFCID3"));
// cut_assert_equal_int (NDM_PASSIVE, nt.nti.ndi.ndm, cut_message ("Invalid target DEP mode"));
// cut_assert_equal_memory ("\x12\x34\x56\x78", 4, nt.nti.ndi.abtGB, nt.nti.ndi.szGB, cut_message ("Invalid target general bytes"));
printf ("=========== INITIATOR %s (Passive mode / 212Kbps) =========\n", nfc_device_name (device));
res = nfc_initiator_select_dep_target (device, NDM_PASSIVE, NBR_212, NULL, &nt, 5000);
cut_assert_true (res, cut_message ("Can't select any DEP target: %s", nfc_strerror (device)));
cut_assert_equal_int (NMT_DEP, nt.nm.nmt, cut_message ("Invalid target modulation"));
cut_assert_equal_int (NBR_212, nt.nm.nbr, cut_message ("Invalid target baud rate"));
cut_assert_equal_memory ("\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA", 10, nt.nti.ndi.abtNFCID3, 10, cut_message ("Invalid target NFCID3"));
cut_assert_equal_int (NDM_PASSIVE, nt.nti.ndi.ndm, cut_message ("Invalid target DEP mode"));
cut_assert_equal_memory ("\x12\x34\x56\x78", 4, nt.nti.ndi.abtGB, nt.nti.ndi.szGB, cut_message ("Invalid target general bytes"));
if (!res) { thread_res = -1; return (void*) thread_res; }
uint8_t abtTx[] = "Hello DEP target!";
const uint8_t abtTx[] = "Hello DEP target!";
uint8_t abtRx[1024];
size_t szRx = sizeof (abtRx);
res = nfc_initiator_transceive_bytes (device, abtTx, sizeof (abtTx), abtRx, &szRx);
// cut_assert_true (res, cut_message ("Can't transceive bytes to target"));
res = nfc_initiator_transceive_bytes (device, abtTx, sizeof (abtTx), abtRx, &szRx, 500);
cut_assert_true (res, cut_message ("Can't transceive bytes to target: %s", nfc_strerror (device)));
uint8_t abtAttRx[] = "Hello DEP initiator!";
// cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data"));
const uint8_t abtAttRx[] = "Hello DEP initiator!";
cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data"));
if (!res) { thread_res = -1; return (void*) thread_res; }
res = nfc_initiator_deselect_target (device);
// cut_assert_true (res, cut_message ("Can't deselect target"));
#endif
cut_assert_true (res, cut_message ("Can't deselect target: %s", nfc_strerror (device)));
if (!res) { thread_res = -1; return (void*) thread_res; }
// Passive mode / 212Kbps (second pass)
printf ("=========== INITIATOR %s (Passive mode / 212Kbps, second pass) =========\n", nfc_device_name (device));
res = nfc_initiator_select_dep_target (device, NDM_PASSIVE, NBR_212, NULL, &nt, 1000);
cut_assert_true (res, cut_message ("Can't select any DEP target: %s", nfc_strerror (device)));
cut_assert_equal_int (NMT_DEP, nt.nm.nmt, cut_message ("Invalid target modulation"));
cut_assert_equal_int (NBR_212, nt.nm.nbr, cut_message ("Invalid target baud rate"));
cut_assert_equal_memory ("\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA", 10, nt.nti.ndi.abtNFCID3, 10, cut_message ("Invalid target NFCID3"));
cut_assert_equal_int (NDM_PASSIVE, nt.nti.ndi.ndm, cut_message ("Invalid target DEP mode"));
cut_assert_equal_memory ("\x12\x34\x56\x78", 4, nt.nti.ndi.abtGB, nt.nti.ndi.szGB, cut_message ("Invalid target general bytes"));
if (!res) { thread_res = -1; return (void*) thread_res; }
szRx = sizeof (abtRx);
res = nfc_initiator_transceive_bytes (device, abtTx, sizeof (abtTx), abtRx, &szRx, 1000);
cut_assert_true (res, cut_message ("Can't transceive bytes to target: %s", nfc_strerror (device)));
cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data"));
if (!res) { thread_res = -1; return (void*) thread_res; }
res = nfc_initiator_deselect_target (device);
cut_assert_true (res, cut_message ("Can't deselect target: %s", nfc_strerror (device)));
if (!res) { thread_res = -1; return (void*) thread_res; }
// Passive mode / 424Kbps
printf ("=========== INITIATOR %s (Passive mode / 424Kbps) =========\n", nfc_device_name (device));
res = nfc_initiator_select_dep_target (device, NDM_PASSIVE, NBR_424, NULL, &nt, 1000);
cut_assert_true (res, cut_message ("Can't select any DEP target: %s", nfc_strerror (device)));
cut_assert_equal_int (NMT_DEP, nt.nm.nmt, cut_message ("Invalid target modulation"));
cut_assert_equal_int (NBR_424, nt.nm.nbr, cut_message ("Invalid target baud rate"));
cut_assert_equal_memory ("\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA", 10, nt.nti.ndi.abtNFCID3, 10, cut_message ("Invalid target NFCID3"));
cut_assert_equal_int (NDM_PASSIVE, nt.nti.ndi.ndm, cut_message ("Invalid target DEP mode"));
cut_assert_equal_memory ("\x12\x34\x56\x78", 4, nt.nti.ndi.abtGB, nt.nti.ndi.szGB, cut_message ("Invalid target general bytes"));
if (!res) { thread_res = -1; return (void*) thread_res; }
szRx = sizeof (abtRx);
res = nfc_initiator_transceive_bytes (device, abtTx, sizeof (abtTx), abtRx, &szRx, 5000);
cut_assert_true (res, cut_message ("Can't transceive bytes to target: %s", nfc_strerror (device)));
cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data"));
if (!res) { thread_res = -1; return (void*) thread_res; }
res = nfc_initiator_deselect_target (device);
cut_assert_true (res, cut_message ("Can't deselect target: %s", nfc_strerror (device)));
if (!res) { thread_res = -1; return (void*) thread_res; }
return (void *) thread_res;
}