astyle --formatted --mode=c --indent=spaces=2 --indent-switches --indent-preprocessor --keep-one-line-blocks --max-instatement-indent=60 --brackets=linux --pad-oper --unpad-paren --pad-header
This commit is contained in:
parent
562205cc14
commit
01303fab0d
59 changed files with 3178 additions and 3178 deletions
|
|
@ -11,45 +11,45 @@
|
|||
* inconsistent state after use.
|
||||
*/
|
||||
void
|
||||
test_access_storm (void)
|
||||
test_access_storm(void)
|
||||
{
|
||||
int n = NTESTS;
|
||||
nfc_connstring connstrings[MAX_DEVICE_COUNT];
|
||||
int res = 0;
|
||||
|
||||
nfc_init (NULL);
|
||||
nfc_init(NULL);
|
||||
|
||||
size_t ref_device_count = nfc_list_devices (NULL, connstrings, MAX_DEVICE_COUNT);
|
||||
size_t ref_device_count = nfc_list_devices(NULL, connstrings, MAX_DEVICE_COUNT);
|
||||
if (!ref_device_count)
|
||||
cut_omit ("No NFC device found");
|
||||
cut_omit("No NFC device found");
|
||||
|
||||
while (n) {
|
||||
size_t i;
|
||||
|
||||
size_t device_count = nfc_list_devices (NULL, connstrings, MAX_DEVICE_COUNT);
|
||||
cut_assert_equal_int (ref_device_count, device_count, cut_message ("device count"));
|
||||
size_t device_count = nfc_list_devices(NULL, connstrings, MAX_DEVICE_COUNT);
|
||||
cut_assert_equal_int(ref_device_count, device_count, cut_message("device count"));
|
||||
|
||||
for (i = 0; i < device_count; i++) {
|
||||
nfc_device *device;
|
||||
nfc_target ant[MAX_TARGET_COUNT];
|
||||
|
||||
device = nfc_open (NULL, connstrings[i]);
|
||||
cut_assert_not_null (device, cut_message ("nfc_open"));
|
||||
device = nfc_open(NULL, connstrings[i]);
|
||||
cut_assert_not_null(device, cut_message("nfc_open"));
|
||||
|
||||
res = nfc_initiator_init(device);
|
||||
cut_assert_equal_int (0, res, cut_message ("nfc_initiator_init"));
|
||||
cut_assert_equal_int(0, res, cut_message("nfc_initiator_init"));
|
||||
|
||||
const nfc_modulation nm = {
|
||||
.nmt = NMT_ISO14443A,
|
||||
.nbr = NBR_106,
|
||||
};
|
||||
res = nfc_initiator_list_passive_targets(device, nm, ant, MAX_TARGET_COUNT);
|
||||
cut_assert_operator_int (res, >= , 0, cut_message ("nfc_initiator_list_passive_targets"));
|
||||
cut_assert_operator_int(res, >= , 0, cut_message("nfc_initiator_list_passive_targets"));
|
||||
|
||||
nfc_close (device);
|
||||
nfc_close(device);
|
||||
}
|
||||
|
||||
n--;
|
||||
}
|
||||
nfc_exit (NULL);
|
||||
nfc_exit(NULL);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,35 +15,35 @@ nfc_device *devices[2];
|
|||
intptr_t result[2];
|
||||
|
||||
void
|
||||
abort_test_by_keypress (int sig)
|
||||
abort_test_by_keypress(int sig)
|
||||
{
|
||||
(void) sig;
|
||||
printf ("\033[0;1;31mSIGINT\033[0m");
|
||||
printf("\033[0;1;31mSIGINT\033[0m");
|
||||
|
||||
nfc_abort_command (devices[INITIATOR]);
|
||||
nfc_abort_command (devices[TARGET]);
|
||||
nfc_abort_command(devices[INITIATOR]);
|
||||
nfc_abort_command(devices[TARGET]);
|
||||
}
|
||||
|
||||
void
|
||||
cut_setup (void)
|
||||
cut_setup(void)
|
||||
{
|
||||
size_t n = nfc_list_devices (NULL, connstrings, 2);
|
||||
size_t n = nfc_list_devices(NULL, connstrings, 2);
|
||||
if (n < 2) {
|
||||
cut_omit ("At least two NFC devices must be plugged-in to run this test");
|
||||
cut_omit("At least two NFC devices must be plugged-in to run this test");
|
||||
}
|
||||
nfc_init (NULL);
|
||||
devices[TARGET] = nfc_open (NULL, connstrings[TARGET]);
|
||||
devices[INITIATOR] = nfc_open (NULL, connstrings[INITIATOR]);
|
||||
nfc_init(NULL);
|
||||
devices[TARGET] = nfc_open(NULL, connstrings[TARGET]);
|
||||
devices[INITIATOR] = nfc_open(NULL, connstrings[INITIATOR]);
|
||||
|
||||
signal (SIGINT, abort_test_by_keypress);
|
||||
signal(SIGINT, abort_test_by_keypress);
|
||||
}
|
||||
|
||||
void
|
||||
cut_teardown (void)
|
||||
cut_teardown(void)
|
||||
{
|
||||
nfc_close (devices[TARGET]);
|
||||
nfc_close (devices[INITIATOR]);
|
||||
nfc_exit (NULL);
|
||||
nfc_close(devices[TARGET]);
|
||||
nfc_close(devices[INITIATOR]);
|
||||
nfc_exit(NULL);
|
||||
}
|
||||
|
||||
struct thread_data {
|
||||
|
|
@ -53,13 +53,13 @@ struct thread_data {
|
|||
};
|
||||
|
||||
void *
|
||||
target_thread (void *arg)
|
||||
target_thread(void *arg)
|
||||
{
|
||||
intptr_t thread_res = 0;
|
||||
nfc_device *device = ((struct thread_data *) arg)->device;
|
||||
cut_set_current_test_context (((struct thread_data *) arg)->cut_test_context);
|
||||
cut_set_current_test_context(((struct thread_data *) arg)->cut_test_context);
|
||||
|
||||
printf ("=========== TARGET %s =========\n", nfc_device_get_name (device));
|
||||
printf("=========== TARGET %s =========\n", nfc_device_get_name(device));
|
||||
nfc_target nt = {
|
||||
.nm = {
|
||||
.nmt = NMT_DEP,
|
||||
|
|
@ -82,79 +82,79 @@ target_thread (void *arg)
|
|||
};
|
||||
|
||||
uint8_t abtRx[1024];
|
||||
size_t szRx = sizeof (abtRx);
|
||||
int res = nfc_target_init (device, &nt, abtRx, sizeof (abtRx), 0);
|
||||
cut_assert_operator_int (res, > , 0, cut_message ("Can't initialize NFC device as target: %s", nfc_strerror (device)));
|
||||
size_t szRx = sizeof(abtRx);
|
||||
int res = nfc_target_init(device, &nt, abtRx, sizeof(abtRx), 0);
|
||||
cut_assert_operator_int(res, > , 0, cut_message("Can't initialize NFC device as target: %s", nfc_strerror(device)));
|
||||
if (res < 0) { thread_res = -1; return (void*) thread_res; }
|
||||
|
||||
res = nfc_target_receive_bytes (device, abtRx, sizeof (abtRx), 500);
|
||||
cut_assert_operator_int (res, > , 0, cut_message ("Can't receive bytes from initiator: %s", nfc_strerror (device)));
|
||||
res = nfc_target_receive_bytes(device, abtRx, sizeof(abtRx), 500);
|
||||
cut_assert_operator_int(res, > , 0, cut_message("Can't receive bytes from initiator: %s", nfc_strerror(device)));
|
||||
szRx = (size_t) res;
|
||||
const uint8_t abtAttRx[] = "Hello DEP target!";
|
||||
cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data"));
|
||||
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, szRx, cut_message("Invalid received data"));
|
||||
if (res <= 0) { thread_res = -1; return (void*) thread_res; }
|
||||
|
||||
const uint8_t abtTx[] = "Hello DEP initiator!";
|
||||
res = nfc_target_send_bytes (device, abtTx, sizeof(abtTx), 500);
|
||||
cut_assert_operator_int (res, > , 0, cut_message ("Can't send bytes to initiator: %s", nfc_strerror (device)));
|
||||
res = nfc_target_send_bytes(device, abtTx, sizeof(abtTx), 500);
|
||||
cut_assert_operator_int(res, > , 0, cut_message("Can't send bytes to initiator: %s", nfc_strerror(device)));
|
||||
if (res <= 0) { thread_res = -1; return (void*) thread_res; }
|
||||
|
||||
return (void *) thread_res;
|
||||
}
|
||||
|
||||
void *
|
||||
initiator_thread (void *arg)
|
||||
initiator_thread(void *arg)
|
||||
{
|
||||
intptr_t thread_res = 0;
|
||||
nfc_device *device = ((struct thread_data *) arg)->device;
|
||||
cut_set_current_test_context (((struct thread_data *) arg)->cut_test_context);
|
||||
cut_set_current_test_context(((struct thread_data *) arg)->cut_test_context);
|
||||
nfc_baud_rate nbr = (((struct thread_data *) arg)->nbr);
|
||||
|
||||
/*
|
||||
* Wait some time for the other thread to initialise NFC device as target
|
||||
*/
|
||||
sleep (1);
|
||||
printf ("=========== INITIATOR %s =========\n", nfc_device_get_name (device));
|
||||
int res = nfc_initiator_init (device);
|
||||
cut_assert_equal_int (0, res, cut_message ("Can't initialize NFC device as initiator: %s", nfc_strerror (device)));
|
||||
sleep(1);
|
||||
printf("=========== INITIATOR %s =========\n", nfc_device_get_name(device));
|
||||
int res = nfc_initiator_init(device);
|
||||
cut_assert_equal_int(0, res, cut_message("Can't initialize NFC device as initiator: %s", nfc_strerror(device)));
|
||||
if (res < 0) { thread_res = -1; return (void*) thread_res; }
|
||||
|
||||
nfc_target nt;
|
||||
|
||||
// Active mode
|
||||
printf ("=========== INITIATOR %s (Active mode / %s Kbps) =========\n", nfc_device_get_name (device), str_nfc_baud_rate(nbr));
|
||||
res = nfc_initiator_select_dep_target (device, NDM_ACTIVE, nbr, NULL, &nt, 1000);
|
||||
cut_assert_operator_int (res, > , 0, 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, 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_ACTIVE, 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 (Active mode / %s Kbps) =========\n", nfc_device_get_name(device), str_nfc_baud_rate(nbr));
|
||||
res = nfc_initiator_select_dep_target(device, NDM_ACTIVE, nbr, NULL, &nt, 1000);
|
||||
cut_assert_operator_int(res, > , 0, 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, 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_ACTIVE, 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 <= 0) { thread_res = -1; return (void*) thread_res; }
|
||||
|
||||
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, 5000);
|
||||
cut_assert_operator_int (res, >= , 0, cut_message ("Can't transceive bytes to target: %s", nfc_strerror (device)));
|
||||
size_t szRx = sizeof(abtRx);
|
||||
res = nfc_initiator_transceive_bytes(device, abtTx, sizeof(abtTx), abtRx, &szRx, 5000);
|
||||
cut_assert_operator_int(res, >= , 0, cut_message("Can't transceive bytes to target: %s", nfc_strerror(device)));
|
||||
|
||||
const uint8_t abtAttRx[] = "Hello DEP initiator!";
|
||||
cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data"));
|
||||
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, szRx, cut_message("Invalid received data"));
|
||||
if (res < 0) { thread_res = -1; return (void*) thread_res; }
|
||||
res = nfc_initiator_deselect_target (device);
|
||||
cut_assert_operator_int (res, >= , 0, cut_message ("Can't deselect target: %s", nfc_strerror (device)));
|
||||
res = nfc_initiator_deselect_target(device);
|
||||
cut_assert_operator_int(res, >= , 0, cut_message("Can't deselect target: %s", nfc_strerror(device)));
|
||||
if (res < 0) { thread_res = -1; return (void*) thread_res; }
|
||||
|
||||
return (void *) thread_res;
|
||||
}
|
||||
|
||||
void
|
||||
test_dep (void)
|
||||
test_dep(void)
|
||||
{
|
||||
int res;
|
||||
nfc_baud_rate nbrs[3] = { NBR_106, NBR_212, NBR_424};
|
||||
|
||||
CutTestContext *test_context = cut_get_current_test_context ();
|
||||
CutTestContext *test_context = cut_get_current_test_context();
|
||||
struct thread_data target_data = {
|
||||
.device = devices[TARGET],
|
||||
.cut_test_context = test_context,
|
||||
|
|
@ -168,18 +168,18 @@ test_dep (void)
|
|||
for (int i = 0; i < 3; i++) {
|
||||
initiator_data.nbr = nbrs[i];
|
||||
|
||||
if ((res = pthread_create (&(threads[TARGET]), NULL, target_thread, &target_data)))
|
||||
cut_fail ("pthread_create() returned %d", res);
|
||||
if ((res = pthread_create (&(threads[INITIATOR]), NULL, initiator_thread, &initiator_data)))
|
||||
cut_fail ("pthread_create() returned %d", res);
|
||||
if ((res = pthread_create(&(threads[TARGET]), NULL, target_thread, &target_data)))
|
||||
cut_fail("pthread_create() returned %d", res);
|
||||
if ((res = pthread_create(&(threads[INITIATOR]), NULL, initiator_thread, &initiator_data)))
|
||||
cut_fail("pthread_create() returned %d", res);
|
||||
|
||||
if ((res = pthread_join (threads[INITIATOR], (void *) &result[INITIATOR])))
|
||||
cut_fail ("pthread_join() returned %d", res);
|
||||
if ((res = pthread_join (threads[TARGET], (void *) &result[TARGET])))
|
||||
cut_fail ("pthread_join() returned %d", res);
|
||||
if ((res = pthread_join(threads[INITIATOR], (void *) &result[INITIATOR])))
|
||||
cut_fail("pthread_join() returned %d", res);
|
||||
if ((res = pthread_join(threads[TARGET], (void *) &result[TARGET])))
|
||||
cut_fail("pthread_join() returned %d", res);
|
||||
|
||||
cut_assert_equal_int (0, result[INITIATOR], cut_message ("Unexpected initiator return code"));
|
||||
cut_assert_equal_int (0, result[TARGET], cut_message ("Unexpected target return code"));
|
||||
cut_assert_equal_int(0, result[INITIATOR], cut_message("Unexpected initiator return code"));
|
||||
cut_assert_equal_int(0, result[TARGET], cut_message("Unexpected target return code"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,36 +14,36 @@ nfc_device *devices[2];
|
|||
intptr_t result[2];
|
||||
|
||||
void
|
||||
abort_test_by_keypress (int sig)
|
||||
abort_test_by_keypress(int sig)
|
||||
{
|
||||
(void) sig;
|
||||
printf ("\033[0;1;31mSIGINT\033[0m");
|
||||
printf("\033[0;1;31mSIGINT\033[0m");
|
||||
|
||||
nfc_abort_command (devices[INITIATOR]);
|
||||
nfc_abort_command (devices[TARGET]);
|
||||
nfc_abort_command(devices[INITIATOR]);
|
||||
nfc_abort_command(devices[TARGET]);
|
||||
}
|
||||
|
||||
void
|
||||
cut_setup (void)
|
||||
cut_setup(void)
|
||||
{
|
||||
size_t n = nfc_list_devices (NULL, connstrings, 2);
|
||||
size_t n = nfc_list_devices(NULL, connstrings, 2);
|
||||
if (n < 2) {
|
||||
cut_omit ("At least two NFC devices must be plugged-in to run this test");
|
||||
cut_omit("At least two NFC devices must be plugged-in to run this test");
|
||||
}
|
||||
|
||||
nfc_init (NULL);
|
||||
devices[TARGET] = nfc_open (NULL, connstrings[TARGET]);
|
||||
devices[INITIATOR] = nfc_open (NULL, connstrings[INITIATOR]);
|
||||
nfc_init(NULL);
|
||||
devices[TARGET] = nfc_open(NULL, connstrings[TARGET]);
|
||||
devices[INITIATOR] = nfc_open(NULL, connstrings[INITIATOR]);
|
||||
|
||||
signal (SIGINT, abort_test_by_keypress);
|
||||
signal(SIGINT, abort_test_by_keypress);
|
||||
}
|
||||
|
||||
void
|
||||
cut_teardown (void)
|
||||
cut_teardown(void)
|
||||
{
|
||||
nfc_close (devices[TARGET]);
|
||||
nfc_close (devices[INITIATOR]);
|
||||
nfc_exit (NULL);
|
||||
nfc_close(devices[TARGET]);
|
||||
nfc_close(devices[INITIATOR]);
|
||||
nfc_exit(NULL);
|
||||
}
|
||||
|
||||
struct thread_data {
|
||||
|
|
@ -52,13 +52,13 @@ struct thread_data {
|
|||
};
|
||||
|
||||
void *
|
||||
target_thread (void *arg)
|
||||
target_thread(void *arg)
|
||||
{
|
||||
intptr_t thread_res = 0;
|
||||
nfc_device *device = ((struct thread_data *) arg)->device;
|
||||
cut_set_current_test_context (((struct thread_data *) arg)->cut_test_context);
|
||||
cut_set_current_test_context(((struct thread_data *) arg)->cut_test_context);
|
||||
|
||||
printf ("=========== TARGET %s =========\n", nfc_device_get_name (device));
|
||||
printf("=========== TARGET %s =========\n", nfc_device_get_name(device));
|
||||
nfc_target nt = {
|
||||
.nm = {
|
||||
.nmt = NMT_DEP,
|
||||
|
|
@ -81,202 +81,202 @@ target_thread (void *arg)
|
|||
};
|
||||
|
||||
uint8_t abtRx[1024];
|
||||
size_t szRx = sizeof (abtRx);
|
||||
int res = nfc_target_init (device, &nt, abtRx, szRx, 0);
|
||||
cut_assert_operator_int (res, > , 0, cut_message ("Can't initialize NFC device as target: %s", nfc_strerror (device)));
|
||||
size_t szRx = sizeof(abtRx);
|
||||
int res = nfc_target_init(device, &nt, abtRx, szRx, 0);
|
||||
cut_assert_operator_int(res, > , 0, cut_message("Can't initialize NFC device as target: %s", nfc_strerror(device)));
|
||||
if (res < 0) { thread_res = -1; return (void*) thread_res; }
|
||||
|
||||
// First pass
|
||||
res = nfc_target_receive_bytes (device, abtRx, sizeof (abtRx), 500);
|
||||
cut_assert_operator_int (res, > , 0, cut_message ("Can't receive bytes from initiator: %s", nfc_strerror (device)));
|
||||
res = nfc_target_receive_bytes(device, abtRx, sizeof(abtRx), 500);
|
||||
cut_assert_operator_int(res, > , 0, cut_message("Can't receive bytes from initiator: %s", nfc_strerror(device)));
|
||||
szRx = (size_t) res;
|
||||
|
||||
const uint8_t abtAttRx[] = "Hello DEP target!";
|
||||
cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data"));
|
||||
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, szRx, cut_message("Invalid received data"));
|
||||
if (res <= 0) { thread_res = -1; return (void*) thread_res; }
|
||||
|
||||
const uint8_t abtTx[] = "Hello DEP initiator!";
|
||||
res = nfc_target_send_bytes (device, abtTx, sizeof(abtTx), 500);
|
||||
cut_assert_operator_int (res, > , 0, cut_message ("Can't send bytes to initiator: %s", nfc_strerror (device)));
|
||||
res = nfc_target_send_bytes(device, abtTx, sizeof(abtTx), 500);
|
||||
cut_assert_operator_int(res, > , 0, cut_message("Can't send bytes to initiator: %s", nfc_strerror(device)));
|
||||
if (res <= 0) { thread_res = -1; return (void*) thread_res; }
|
||||
|
||||
// Second pass
|
||||
res = nfc_target_receive_bytes (device, abtRx, sizeof (abtRx), 500);
|
||||
cut_assert_operator_int (res, > , 0, cut_message ("Can't receive bytes from initiator: %s", nfc_strerror (device)));
|
||||
res = nfc_target_receive_bytes(device, abtRx, sizeof(abtRx), 500);
|
||||
cut_assert_operator_int(res, > , 0, cut_message("Can't receive bytes from initiator: %s", nfc_strerror(device)));
|
||||
szRx = (size_t) res;
|
||||
|
||||
cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data"));
|
||||
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, szRx, cut_message("Invalid received data"));
|
||||
if (res <= 0) { thread_res = -1; return (void*) thread_res; }
|
||||
|
||||
res = nfc_target_send_bytes (device, abtTx, sizeof(abtTx), 500);
|
||||
cut_assert_operator_int (res, > , 0, cut_message ("Can't send bytes to initiator: %s", nfc_strerror (device)));
|
||||
res = nfc_target_send_bytes(device, abtTx, sizeof(abtTx), 500);
|
||||
cut_assert_operator_int(res, > , 0, cut_message("Can't send bytes to initiator: %s", nfc_strerror(device)));
|
||||
if (res <= 0) { thread_res = -1; return (void*) thread_res; }
|
||||
|
||||
// Third pass
|
||||
res = nfc_target_receive_bytes (device, abtRx, sizeof (abtRx), 500);
|
||||
cut_assert_operator_int (res, > , 0, cut_message ("Can't receive bytes from initiator: %s", nfc_strerror (device)));
|
||||
res = nfc_target_receive_bytes(device, abtRx, sizeof(abtRx), 500);
|
||||
cut_assert_operator_int(res, > , 0, cut_message("Can't receive bytes from initiator: %s", nfc_strerror(device)));
|
||||
szRx = (size_t) res;
|
||||
|
||||
cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data"));
|
||||
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, szRx, cut_message("Invalid received data"));
|
||||
if (res <= 0) { thread_res = -1; return (void*) thread_res; }
|
||||
|
||||
res = nfc_target_send_bytes (device, abtTx, sizeof(abtTx), 500);
|
||||
cut_assert_operator_int (res, > , 0, cut_message ("Can't send bytes to initiator: %s", nfc_strerror (device)));
|
||||
res = nfc_target_send_bytes(device, abtTx, sizeof(abtTx), 500);
|
||||
cut_assert_operator_int(res, > , 0, cut_message("Can't send bytes to initiator: %s", nfc_strerror(device)));
|
||||
if (res <= 0) { thread_res = -1; return (void*) thread_res; }
|
||||
|
||||
// Fourth pass
|
||||
res = nfc_target_receive_bytes (device, abtRx, sizeof (abtRx), 500);
|
||||
cut_assert_operator_int (res, > , 0, cut_message ("Can't receive bytes from initiator: %s", nfc_strerror (device)));
|
||||
res = nfc_target_receive_bytes(device, abtRx, sizeof(abtRx), 500);
|
||||
cut_assert_operator_int(res, > , 0, cut_message("Can't receive bytes from initiator: %s", nfc_strerror(device)));
|
||||
szRx = (size_t) res;
|
||||
|
||||
cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data"));
|
||||
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, szRx, cut_message("Invalid received data"));
|
||||
if (res <= 0) { thread_res = -1; return (void*) thread_res; }
|
||||
|
||||
res = nfc_target_send_bytes (device, abtTx, sizeof(abtTx), 500);
|
||||
cut_assert_operator_int (res, > , 0, cut_message ("Can't send bytes to initiator: %s", nfc_strerror (device)));
|
||||
res = nfc_target_send_bytes(device, abtTx, sizeof(abtTx), 500);
|
||||
cut_assert_operator_int(res, > , 0, cut_message("Can't send bytes to initiator: %s", nfc_strerror(device)));
|
||||
if (res <= 0) { thread_res = -1; return (void*) thread_res; }
|
||||
|
||||
return (void *) thread_res;
|
||||
}
|
||||
|
||||
void *
|
||||
initiator_thread (void *arg)
|
||||
initiator_thread(void *arg)
|
||||
{
|
||||
intptr_t thread_res = 0;
|
||||
nfc_device *device = ((struct thread_data *) arg)->device;
|
||||
cut_set_current_test_context (((struct thread_data *) arg)->cut_test_context);
|
||||
cut_set_current_test_context(((struct thread_data *) arg)->cut_test_context);
|
||||
|
||||
/*
|
||||
* Wait some time for the other thread to initialise NFC device as target
|
||||
*/
|
||||
sleep (1);
|
||||
printf ("=========== INITIATOR %s =========\n", nfc_device_get_name (device));
|
||||
sleep(1);
|
||||
printf("=========== INITIATOR %s =========\n", nfc_device_get_name(device));
|
||||
|
||||
int res = nfc_initiator_init (device);
|
||||
cut_assert_equal_int (0, res, cut_message ("Can't initialize NFC device as initiator: %s", nfc_strerror (device)));
|
||||
int res = nfc_initiator_init(device);
|
||||
cut_assert_equal_int(0, res, cut_message("Can't initialize NFC device as initiator: %s", nfc_strerror(device)));
|
||||
if (res < 0) { thread_res = -1; return (void*) thread_res; }
|
||||
|
||||
nfc_target nt;
|
||||
|
||||
// Passive mode / 106Kbps
|
||||
printf ("=========== INITIATOR %s (Passive mode / 106Kbps) =========\n", nfc_device_get_name (device));
|
||||
res = nfc_initiator_select_dep_target (device, NDM_PASSIVE, NBR_106, NULL, &nt, 5000);
|
||||
cut_assert_operator_int (res, > , 0, 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_106, 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 / 106Kbps) =========\n", nfc_device_get_name(device));
|
||||
res = nfc_initiator_select_dep_target(device, NDM_PASSIVE, NBR_106, NULL, &nt, 5000);
|
||||
cut_assert_operator_int(res, > , 0, 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_106, 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 <= 0) { thread_res = -1; return (void*) thread_res; }
|
||||
|
||||
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, 500);
|
||||
cut_assert_operator_int (res, >= , 0, cut_message ("Can't transceive bytes to target: %s", nfc_strerror (device)));
|
||||
size_t szRx = sizeof(abtRx);
|
||||
res = nfc_initiator_transceive_bytes(device, abtTx, sizeof(abtTx), abtRx, &szRx, 500);
|
||||
cut_assert_operator_int(res, >= , 0, cut_message("Can't transceive bytes to target: %s", nfc_strerror(device)));
|
||||
|
||||
const uint8_t abtAttRx[] = "Hello DEP initiator!";
|
||||
cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data"));
|
||||
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, szRx, cut_message("Invalid received data"));
|
||||
if (res < 0) { thread_res = -1; return (void*) thread_res; }
|
||||
|
||||
res = nfc_initiator_deselect_target (device);
|
||||
cut_assert_operator_int (res, >= , 0, cut_message ("Can't deselect target: %s", nfc_strerror (device)));
|
||||
res = nfc_initiator_deselect_target(device);
|
||||
cut_assert_operator_int(res, >= , 0, cut_message("Can't deselect target: %s", nfc_strerror(device)));
|
||||
if (res < 0) { thread_res = -1; return (void*) thread_res; }
|
||||
|
||||
// Passive mode / 212Kbps (second pass)
|
||||
printf ("=========== INITIATOR %s (Passive mode / 212Kbps) =========\n", nfc_device_get_name (device));
|
||||
res = nfc_initiator_select_dep_target (device, NDM_PASSIVE, NBR_212, NULL, &nt, 1000);
|
||||
cut_assert_operator_int (res, > , 0, 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"));
|
||||
printf("=========== INITIATOR %s (Passive mode / 212Kbps) =========\n", nfc_device_get_name(device));
|
||||
res = nfc_initiator_select_dep_target(device, NDM_PASSIVE, NBR_212, NULL, &nt, 1000);
|
||||
cut_assert_operator_int(res, > , 0, 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 <= 0) { thread_res = -1; return (void*) thread_res; }
|
||||
|
||||
szRx = sizeof (abtRx);
|
||||
res = nfc_initiator_transceive_bytes (device, abtTx, sizeof (abtTx), abtRx, &szRx, 1000);
|
||||
cut_assert_operator_int (res, >= , 0, cut_message ("Can't transceive bytes to target: %s", nfc_strerror (device)));
|
||||
szRx = sizeof(abtRx);
|
||||
res = nfc_initiator_transceive_bytes(device, abtTx, sizeof(abtTx), abtRx, &szRx, 1000);
|
||||
cut_assert_operator_int(res, >= , 0, 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"));
|
||||
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, szRx, cut_message("Invalid received data"));
|
||||
if (res < 0) { thread_res = -1; return (void*) thread_res; }
|
||||
|
||||
res = nfc_initiator_deselect_target (device);
|
||||
cut_assert_operator_int (res, >= , 0, cut_message ("Can't deselect target: %s", nfc_strerror (device)));
|
||||
res = nfc_initiator_deselect_target(device);
|
||||
cut_assert_operator_int(res, >= , 0, cut_message("Can't deselect target: %s", nfc_strerror(device)));
|
||||
if (res < 0) { thread_res = -1; return (void*) thread_res; }
|
||||
|
||||
// Passive mode / 212Kbps
|
||||
printf ("=========== INITIATOR %s (Passive mode / 212Kbps, second pass) =========\n", nfc_device_get_name (device));
|
||||
res = nfc_initiator_select_dep_target (device, NDM_PASSIVE, NBR_212, NULL, &nt, 1000);
|
||||
cut_assert_operator_int (res, > , 0, 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"));
|
||||
printf("=========== INITIATOR %s (Passive mode / 212Kbps, second pass) =========\n", nfc_device_get_name(device));
|
||||
res = nfc_initiator_select_dep_target(device, NDM_PASSIVE, NBR_212, NULL, &nt, 1000);
|
||||
cut_assert_operator_int(res, > , 0, 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 <= 0) { thread_res = -1; return (void*) thread_res; }
|
||||
|
||||
szRx = sizeof (abtRx);
|
||||
res = nfc_initiator_transceive_bytes (device, abtTx, sizeof (abtTx), abtRx, &szRx, 5000);
|
||||
cut_assert_operator_int (res, >= , 0, cut_message ("Can't transceive bytes to target: %s", nfc_strerror (device)));
|
||||
szRx = sizeof(abtRx);
|
||||
res = nfc_initiator_transceive_bytes(device, abtTx, sizeof(abtTx), abtRx, &szRx, 5000);
|
||||
cut_assert_operator_int(res, >= , 0, 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"));
|
||||
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, szRx, cut_message("Invalid received data"));
|
||||
if (res < 0) { thread_res = -1; return (void*) thread_res; }
|
||||
|
||||
res = nfc_initiator_deselect_target (device);
|
||||
cut_assert_operator_int (res, >= , 0, cut_message ("Can't deselect target: %s", nfc_strerror (device)));
|
||||
res = nfc_initiator_deselect_target(device);
|
||||
cut_assert_operator_int(res, >= , 0, cut_message("Can't deselect target: %s", nfc_strerror(device)));
|
||||
if (res < 0) { thread_res = -1; return (void*) thread_res; }
|
||||
|
||||
// Passive mode / 424Kbps
|
||||
printf ("=========== INITIATOR %s (Passive mode / 424Kbps) =========\n", nfc_device_get_name (device));
|
||||
res = nfc_initiator_select_dep_target (device, NDM_PASSIVE, NBR_424, NULL, &nt, 1000);
|
||||
cut_assert_operator_int (res, > , 0, 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"));
|
||||
printf("=========== INITIATOR %s (Passive mode / 424Kbps) =========\n", nfc_device_get_name(device));
|
||||
res = nfc_initiator_select_dep_target(device, NDM_PASSIVE, NBR_424, NULL, &nt, 1000);
|
||||
cut_assert_operator_int(res, > , 0, 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 <= 0) { thread_res = -1; return (void*) thread_res; }
|
||||
|
||||
szRx = sizeof (abtRx);
|
||||
res = nfc_initiator_transceive_bytes (device, abtTx, sizeof (abtTx), abtRx, &szRx, 5000);
|
||||
cut_assert_operator_int (res, >= , 0, cut_message ("Can't transceive bytes to target: %s", nfc_strerror (device)));
|
||||
szRx = sizeof(abtRx);
|
||||
res = nfc_initiator_transceive_bytes(device, abtTx, sizeof(abtTx), abtRx, &szRx, 5000);
|
||||
cut_assert_operator_int(res, >= , 0, 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"));
|
||||
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, szRx, cut_message("Invalid received data"));
|
||||
if (res < 0) { thread_res = -1; return (void*) thread_res; }
|
||||
|
||||
res = nfc_initiator_deselect_target (device);
|
||||
cut_assert_operator_int (res, >= , 0, cut_message ("Can't deselect target: %s", nfc_strerror (device)));
|
||||
res = nfc_initiator_deselect_target(device);
|
||||
cut_assert_operator_int(res, >= , 0, cut_message("Can't deselect target: %s", nfc_strerror(device)));
|
||||
if (res < 0) { thread_res = -1; return (void*) thread_res; }
|
||||
|
||||
return (void *) thread_res;
|
||||
}
|
||||
|
||||
void
|
||||
test_dep (void)
|
||||
test_dep(void)
|
||||
{
|
||||
int res;
|
||||
|
||||
CutTestContext *test_context = cut_get_current_test_context ();
|
||||
CutTestContext *test_context = cut_get_current_test_context();
|
||||
struct thread_data target_data = {
|
||||
.device = devices[TARGET],
|
||||
.cut_test_context = test_context,
|
||||
};
|
||||
if ((res = pthread_create (&(threads[TARGET]), NULL, target_thread, &target_data)))
|
||||
cut_fail ("pthread_create() returned %d", res);
|
||||
if ((res = pthread_create(&(threads[TARGET]), NULL, target_thread, &target_data)))
|
||||
cut_fail("pthread_create() returned %d", res);
|
||||
|
||||
struct thread_data initiator_data = {
|
||||
.device = devices[INITIATOR],
|
||||
.cut_test_context = test_context,
|
||||
};
|
||||
if ((res = pthread_create (&(threads[INITIATOR]), NULL, initiator_thread, &initiator_data)))
|
||||
cut_fail ("pthread_create() returned %d", res);
|
||||
if ((res = pthread_create(&(threads[INITIATOR]), NULL, initiator_thread, &initiator_data)))
|
||||
cut_fail("pthread_create() returned %d", res);
|
||||
|
||||
if ((res = pthread_join (threads[INITIATOR], (void *) &result[INITIATOR])))
|
||||
cut_fail ("pthread_join() returned %d", res);
|
||||
if ((res = pthread_join (threads[TARGET], (void *) &result[TARGET])))
|
||||
cut_fail ("pthread_join() returned %d", res);
|
||||
if ((res = pthread_join(threads[INITIATOR], (void *) &result[INITIATOR])))
|
||||
cut_fail("pthread_join() returned %d", res);
|
||||
if ((res = pthread_join(threads[TARGET], (void *) &result[TARGET])))
|
||||
cut_fail("pthread_join() returned %d", res);
|
||||
|
||||
cut_assert_equal_int (0, result[INITIATOR], cut_message ("Unexpected initiator return code"));
|
||||
cut_assert_equal_int (0, result[TARGET], cut_message ("Unexpected target return code"));
|
||||
cut_assert_equal_int(0, result[INITIATOR], cut_message("Unexpected initiator return code"));
|
||||
cut_assert_equal_int(0, result[TARGET], cut_message("Unexpected target return code"));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,36 +12,36 @@ nfc_device *first_device, *second_device;
|
|||
intptr_t result[2];
|
||||
|
||||
void
|
||||
abort_test_by_keypress (int sig)
|
||||
abort_test_by_keypress(int sig)
|
||||
{
|
||||
(void) sig;
|
||||
printf ("\033[0;1;31mSIGINT\033[0m");
|
||||
printf("\033[0;1;31mSIGINT\033[0m");
|
||||
|
||||
nfc_abort_command (first_device);
|
||||
nfc_abort_command (second_device);
|
||||
nfc_abort_command(first_device);
|
||||
nfc_abort_command(second_device);
|
||||
}
|
||||
|
||||
void
|
||||
cut_setup (void)
|
||||
cut_setup(void)
|
||||
{
|
||||
size_t n = nfc_list_devices (NULL, connstrings, 2);
|
||||
size_t n = nfc_list_devices(NULL, connstrings, 2);
|
||||
if (n < 2) {
|
||||
cut_omit ("At least two NFC devices must be plugged-in to run this test");
|
||||
cut_omit("At least two NFC devices must be plugged-in to run this test");
|
||||
}
|
||||
|
||||
nfc_init (NULL);
|
||||
second_device = nfc_open (NULL, connstrings[0]);
|
||||
first_device = nfc_open (NULL, connstrings[1]);
|
||||
nfc_init(NULL);
|
||||
second_device = nfc_open(NULL, connstrings[0]);
|
||||
first_device = nfc_open(NULL, connstrings[1]);
|
||||
|
||||
signal (SIGINT, abort_test_by_keypress);
|
||||
signal(SIGINT, abort_test_by_keypress);
|
||||
}
|
||||
|
||||
void
|
||||
cut_teardown (void)
|
||||
cut_teardown(void)
|
||||
{
|
||||
nfc_close (second_device);
|
||||
nfc_close (first_device);
|
||||
nfc_exit (NULL);
|
||||
nfc_close(second_device);
|
||||
nfc_close(first_device);
|
||||
nfc_exit(NULL);
|
||||
}
|
||||
|
||||
struct thread_data {
|
||||
|
|
@ -50,21 +50,21 @@ struct thread_data {
|
|||
};
|
||||
|
||||
void *
|
||||
target_thread (void *arg)
|
||||
target_thread(void *arg)
|
||||
{
|
||||
intptr_t thread_res = 0;
|
||||
nfc_device *device = ((struct thread_data *) arg)->device;
|
||||
cut_set_current_test_context (((struct thread_data *) arg)->cut_test_context);
|
||||
cut_set_current_test_context(((struct thread_data *) arg)->cut_test_context);
|
||||
|
||||
printf ("=========== TARGET %s =========\n", nfc_device_get_name (device));
|
||||
printf("=========== TARGET %s =========\n", nfc_device_get_name(device));
|
||||
nfc_target nt;
|
||||
|
||||
uint8_t abtRx[1024];
|
||||
size_t szRx = sizeof (abtRx);
|
||||
size_t szRx = sizeof(abtRx);
|
||||
|
||||
// 1) nfc_target_init should take target in idle mode
|
||||
int res = nfc_target_init (device, &nt, abtRx, szRx, 500);
|
||||
cut_assert_operator_int (res, >= , 0, cut_message ("Can't initialize NFC device as target: %s", nfc_strerror (device)));
|
||||
int res = nfc_target_init(device, &nt, abtRx, szRx, 500);
|
||||
cut_assert_operator_int(res, >= , 0, cut_message("Can't initialize NFC device as target: %s", nfc_strerror(device)));
|
||||
if (res < 0) { thread_res = -1; return (void*) thread_res; }
|
||||
|
||||
// 2) act as target
|
||||
|
|
@ -89,51 +89,51 @@ target_thread (void *arg)
|
|||
},
|
||||
};
|
||||
sleep(6);
|
||||
res = nfc_target_init (device, &nt1, abtRx, szRx, 0);
|
||||
cut_assert_operator_int (res, > , 0, cut_message ("Can't initialize NFC device as target: %s", nfc_strerror (device)));
|
||||
res = nfc_target_init(device, &nt1, abtRx, szRx, 0);
|
||||
cut_assert_operator_int(res, > , 0, cut_message("Can't initialize NFC device as target: %s", nfc_strerror(device)));
|
||||
if (res < 0) { thread_res = -1; return (void*) thread_res; }
|
||||
|
||||
res = nfc_target_receive_bytes (device, abtRx, sizeof (abtRx), 500);
|
||||
cut_assert_operator_int (res, > , 0, cut_message ("Can't receive bytes from initiator: %s", nfc_strerror (device)));
|
||||
res = nfc_target_receive_bytes(device, abtRx, sizeof(abtRx), 500);
|
||||
cut_assert_operator_int(res, > , 0, cut_message("Can't receive bytes from initiator: %s", nfc_strerror(device)));
|
||||
szRx = (size_t) res;
|
||||
|
||||
const uint8_t abtAttRx[] = "Hello DEP target!";
|
||||
cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data"));
|
||||
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, szRx, cut_message("Invalid received data"));
|
||||
if (res <= 0) { thread_res = -1; return (void*) thread_res; }
|
||||
|
||||
const uint8_t abtTx[] = "Hello DEP initiator!";
|
||||
res = nfc_target_send_bytes (device, abtTx, sizeof(abtTx), 500);
|
||||
cut_assert_operator_int (res, > , 0, cut_message ("Can't send bytes to initiator: %s", nfc_strerror (device)));
|
||||
res = nfc_target_send_bytes(device, abtTx, sizeof(abtTx), 500);
|
||||
cut_assert_operator_int(res, > , 0, cut_message("Can't send bytes to initiator: %s", nfc_strerror(device)));
|
||||
if (res <= 0) { thread_res = -1; return (void*) thread_res; }
|
||||
|
||||
// 3) idle mode
|
||||
sleep (1);
|
||||
nfc_idle (device);
|
||||
sleep(1);
|
||||
nfc_idle(device);
|
||||
|
||||
return (void *) thread_res;
|
||||
}
|
||||
|
||||
void *
|
||||
initiator_thread (void *arg)
|
||||
initiator_thread(void *arg)
|
||||
{
|
||||
intptr_t thread_res = 0;
|
||||
nfc_device *device = ((struct thread_data *) arg)->device;
|
||||
cut_set_current_test_context (((struct thread_data *) arg)->cut_test_context);
|
||||
cut_set_current_test_context(((struct thread_data *) arg)->cut_test_context);
|
||||
|
||||
/*
|
||||
* Wait some time for the other thread to initialise NFC device as target
|
||||
*/
|
||||
sleep (5);
|
||||
printf ("=========== INITIATOR %s =========\n", nfc_device_get_name (device));
|
||||
sleep(5);
|
||||
printf("=========== INITIATOR %s =========\n", nfc_device_get_name(device));
|
||||
|
||||
int res = nfc_initiator_init (device);
|
||||
cut_assert_equal_int (0, res, cut_message ("Can't initialize NFC device as initiator: %s", nfc_strerror (device)));
|
||||
int res = nfc_initiator_init(device);
|
||||
cut_assert_equal_int(0, res, cut_message("Can't initialize NFC device as initiator: %s", nfc_strerror(device)));
|
||||
if (res < 0) { thread_res = -1; return (void*) thread_res; }
|
||||
|
||||
// 1) As other device should be in idle mode, nfc_initiator_poll_dep_target should return 0
|
||||
nfc_target nt;
|
||||
res = nfc_initiator_poll_dep_target (device, NDM_PASSIVE, NBR_106, NULL, &nt, 1000);
|
||||
cut_assert_equal_int (0, res, cut_message ("Problem with nfc_idle"));
|
||||
res = nfc_initiator_poll_dep_target(device, NDM_PASSIVE, NBR_106, NULL, &nt, 1000);
|
||||
cut_assert_equal_int(0, res, cut_message("Problem with nfc_idle"));
|
||||
if (res != 0) { thread_res = -1; return (void*) thread_res; }
|
||||
|
||||
|
||||
|
|
@ -141,45 +141,45 @@ initiator_thread (void *arg)
|
|||
nfc_target nt1;
|
||||
|
||||
// Passive mode / 106Kbps
|
||||
printf ("=========== INITIATOR %s (Passive mode / 106Kbps) =========\n", nfc_device_get_name (device));
|
||||
res = nfc_initiator_poll_dep_target (device, NDM_PASSIVE, NBR_106, NULL, &nt1, 5000);
|
||||
cut_assert_operator_int (res, > , 0, cut_message ("Can't select any DEP target: %s", nfc_strerror (device)));
|
||||
cut_assert_equal_int (NMT_DEP, nt1.nm.nmt, cut_message ("Invalid target modulation"));
|
||||
cut_assert_equal_int (NBR_106, nt1.nm.nbr, cut_message ("Invalid target baud rate"));
|
||||
cut_assert_equal_memory ("\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA", 10, nt1.nti.ndi.abtNFCID3, 10, cut_message ("Invalid target NFCID3"));
|
||||
cut_assert_equal_int (NDM_PASSIVE, nt1.nti.ndi.ndm, cut_message ("Invalid target DEP mode"));
|
||||
cut_assert_equal_memory ("\x12\x34\x56\x78", 4, nt1.nti.ndi.abtGB, nt1.nti.ndi.szGB, cut_message ("Invalid target general bytes"));
|
||||
printf("=========== INITIATOR %s (Passive mode / 106Kbps) =========\n", nfc_device_get_name(device));
|
||||
res = nfc_initiator_poll_dep_target(device, NDM_PASSIVE, NBR_106, NULL, &nt1, 5000);
|
||||
cut_assert_operator_int(res, > , 0, cut_message("Can't select any DEP target: %s", nfc_strerror(device)));
|
||||
cut_assert_equal_int(NMT_DEP, nt1.nm.nmt, cut_message("Invalid target modulation"));
|
||||
cut_assert_equal_int(NBR_106, nt1.nm.nbr, cut_message("Invalid target baud rate"));
|
||||
cut_assert_equal_memory("\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA", 10, nt1.nti.ndi.abtNFCID3, 10, cut_message("Invalid target NFCID3"));
|
||||
cut_assert_equal_int(NDM_PASSIVE, nt1.nti.ndi.ndm, cut_message("Invalid target DEP mode"));
|
||||
cut_assert_equal_memory("\x12\x34\x56\x78", 4, nt1.nti.ndi.abtGB, nt1.nti.ndi.szGB, cut_message("Invalid target general bytes"));
|
||||
if (res <= 0) { thread_res = -1; return (void*) thread_res; }
|
||||
|
||||
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, 500);
|
||||
cut_assert_operator_int (res, >= , 0, cut_message ("Can't transceive bytes to target: %s", nfc_strerror (device)));
|
||||
size_t szRx = sizeof(abtRx);
|
||||
res = nfc_initiator_transceive_bytes(device, abtTx, sizeof(abtTx), abtRx, &szRx, 500);
|
||||
cut_assert_operator_int(res, >= , 0, cut_message("Can't transceive bytes to target: %s", nfc_strerror(device)));
|
||||
|
||||
const uint8_t abtAttRx[] = "Hello DEP initiator!";
|
||||
cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data"));
|
||||
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, szRx, cut_message("Invalid received data"));
|
||||
if (res < 0) { thread_res = -1; return (void*) thread_res; }
|
||||
|
||||
res = nfc_initiator_deselect_target (device);
|
||||
cut_assert_operator_int (res, >= , 0, cut_message ("Can't deselect target: %s", nfc_strerror (device)));
|
||||
res = nfc_initiator_deselect_target(device);
|
||||
cut_assert_operator_int(res, >= , 0, cut_message("Can't deselect target: %s", nfc_strerror(device)));
|
||||
if (res < 0) { thread_res = -1; return (void*) thread_res; }
|
||||
|
||||
// 3) As other device should be in idle mode, nfc_initiator_poll_dep_target should return 0
|
||||
nfc_target nt2;
|
||||
res = nfc_initiator_poll_dep_target (device, NDM_PASSIVE, NBR_106, NULL, &nt2, 1000);
|
||||
cut_assert_equal_int (0, res, cut_message ("Problem with nfc_idle"));
|
||||
res = nfc_initiator_poll_dep_target(device, NDM_PASSIVE, NBR_106, NULL, &nt2, 1000);
|
||||
cut_assert_equal_int(0, res, cut_message("Problem with nfc_idle"));
|
||||
if (res != 0) { thread_res = -1; return (void*) thread_res; }
|
||||
|
||||
return (void *) thread_res;
|
||||
}
|
||||
|
||||
void
|
||||
test_dep_states (void)
|
||||
test_dep_states(void)
|
||||
{
|
||||
int res;
|
||||
|
||||
CutTestContext *test_context = cut_get_current_test_context ();
|
||||
CutTestContext *test_context = cut_get_current_test_context();
|
||||
struct thread_data target_data = {
|
||||
.device = first_device,
|
||||
.cut_test_context = test_context,
|
||||
|
|
@ -191,19 +191,19 @@ test_dep_states (void)
|
|||
};
|
||||
|
||||
for (int i = 0; i < 2; i++) {
|
||||
if ((res = pthread_create (&(threads[1]), NULL, target_thread, &target_data)))
|
||||
cut_fail ("pthread_create() returned %d", res);
|
||||
if ((res = pthread_create(&(threads[1]), NULL, target_thread, &target_data)))
|
||||
cut_fail("pthread_create() returned %d", res);
|
||||
|
||||
if ((res = pthread_create (&(threads[0]), NULL, initiator_thread, &initiator_data)))
|
||||
cut_fail ("pthread_create() returned %d", res);
|
||||
if ((res = pthread_create(&(threads[0]), NULL, initiator_thread, &initiator_data)))
|
||||
cut_fail("pthread_create() returned %d", res);
|
||||
|
||||
if ((res = pthread_join (threads[0], (void *) &result[0])))
|
||||
cut_fail ("pthread_join() returned %d", res);
|
||||
if ((res = pthread_join (threads[1], (void *) &result[1])))
|
||||
cut_fail ("pthread_join() returned %d", res);
|
||||
if ((res = pthread_join(threads[0], (void *) &result[0])))
|
||||
cut_fail("pthread_join() returned %d", res);
|
||||
if ((res = pthread_join(threads[1], (void *) &result[1])))
|
||||
cut_fail("pthread_join() returned %d", res);
|
||||
|
||||
cut_assert_equal_int (0, result[0], cut_message ("Unexpected initiator return code"));
|
||||
cut_assert_equal_int (0, result[1], cut_message ("Unexpected target return code"));
|
||||
cut_assert_equal_int(0, result[0], cut_message("Unexpected initiator return code"));
|
||||
cut_assert_equal_int(0, result[1], cut_message("Unexpected target return code"));
|
||||
|
||||
// initiator --> target, target --> initiator
|
||||
target_data.device = second_device;
|
||||
|
|
|
|||
|
|
@ -7,42 +7,42 @@
|
|||
#define MAX_TARGET_COUNT 1
|
||||
|
||||
void
|
||||
test_register_endianness (void)
|
||||
test_register_endianness(void)
|
||||
{
|
||||
nfc_connstring connstrings[MAX_DEVICE_COUNT];
|
||||
int res = 0;
|
||||
|
||||
nfc_init (NULL);
|
||||
nfc_init(NULL);
|
||||
|
||||
size_t device_count = nfc_list_devices (NULL, connstrings, MAX_DEVICE_COUNT);
|
||||
size_t device_count = nfc_list_devices(NULL, connstrings, MAX_DEVICE_COUNT);
|
||||
if (!device_count)
|
||||
cut_omit ("No NFC device found");
|
||||
cut_omit("No NFC device found");
|
||||
|
||||
nfc_device *device;
|
||||
|
||||
device = nfc_open (NULL, connstrings[0]);
|
||||
cut_assert_not_null (device, cut_message ("nfc_open"));
|
||||
device = nfc_open(NULL, connstrings[0]);
|
||||
cut_assert_not_null(device, cut_message("nfc_open"));
|
||||
|
||||
uint8_t value;
|
||||
|
||||
/* Set a 0xAA test value in writable register memory to test register access */
|
||||
res = pn53x_write_register (device, PN53X_REG_CIU_TxMode, 0xFF, 0xAA);
|
||||
cut_assert_equal_int (0, res, cut_message ("write register value to 0xAA"));
|
||||
res = pn53x_write_register(device, PN53X_REG_CIU_TxMode, 0xFF, 0xAA);
|
||||
cut_assert_equal_int(0, res, cut_message("write register value to 0xAA"));
|
||||
|
||||
/* Get test value from register memory */
|
||||
res = pn53x_read_register (device, PN53X_REG_CIU_TxMode, &value);
|
||||
cut_assert_equal_int (0, res, cut_message ("read register value"));
|
||||
cut_assert_equal_uint (0xAA, value, cut_message ("check register value"));
|
||||
res = pn53x_read_register(device, PN53X_REG_CIU_TxMode, &value);
|
||||
cut_assert_equal_int(0, res, cut_message("read register value"));
|
||||
cut_assert_equal_uint(0xAA, value, cut_message("check register value"));
|
||||
|
||||
/* Set a 0x55 test value in writable register memory to test register access */
|
||||
res = pn53x_write_register (device, PN53X_REG_CIU_TxMode, 0xFF, 0x55);
|
||||
cut_assert_equal_int (0, res, cut_message ("write register value to 0x55"));
|
||||
res = pn53x_write_register(device, PN53X_REG_CIU_TxMode, 0xFF, 0x55);
|
||||
cut_assert_equal_int(0, res, cut_message("write register value to 0x55"));
|
||||
|
||||
/* Get test value from register memory */
|
||||
res = pn53x_read_register (device, PN53X_REG_CIU_TxMode, &value);
|
||||
cut_assert_equal_int (0, res, cut_message ("read register value"));
|
||||
cut_assert_equal_uint (0x55, value, cut_message ("check register value"));
|
||||
res = pn53x_read_register(device, PN53X_REG_CIU_TxMode, &value);
|
||||
cut_assert_equal_int(0, res, cut_message("read register value"));
|
||||
cut_assert_equal_uint(0x55, value, cut_message("check register value"));
|
||||
|
||||
nfc_close (device);
|
||||
nfc_exit (NULL);
|
||||
nfc_close(device);
|
||||
nfc_exit(NULL);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,32 +8,32 @@
|
|||
#include "chips/pn53x.h"
|
||||
|
||||
void
|
||||
test_register_endianness (void)
|
||||
test_register_endianness(void)
|
||||
{
|
||||
nfc_connstring connstrings[MAX_DEVICE_COUNT];
|
||||
int res = 0;
|
||||
|
||||
nfc_init (NULL);
|
||||
nfc_init(NULL);
|
||||
|
||||
size_t device_count = nfc_list_devices (NULL, connstrings, MAX_DEVICE_COUNT);
|
||||
size_t device_count = nfc_list_devices(NULL, connstrings, MAX_DEVICE_COUNT);
|
||||
if (!device_count)
|
||||
cut_omit ("No NFC device found");
|
||||
cut_omit("No NFC device found");
|
||||
|
||||
nfc_device *device;
|
||||
|
||||
device = nfc_open (NULL, connstrings[0]);
|
||||
cut_assert_not_null (device, cut_message ("nfc_open"));
|
||||
device = nfc_open(NULL, connstrings[0]);
|
||||
cut_assert_not_null(device, cut_message("nfc_open"));
|
||||
|
||||
uint8_t value;
|
||||
|
||||
/* Read valid XRAM memory */
|
||||
res = pn53x_read_register (device, 0xF0FF, &value);
|
||||
cut_assert_equal_int (0, res, cut_message ("read register 0xF0FF"));
|
||||
res = pn53x_read_register(device, 0xF0FF, &value);
|
||||
cut_assert_equal_int(0, res, cut_message("read register 0xF0FF"));
|
||||
|
||||
/* Read invalid SFR register */
|
||||
res = pn53x_read_register (device, 0xFFF0, &value);
|
||||
cut_assert_equal_int (0, res, cut_message ("read register 0xFFF0"));
|
||||
res = pn53x_read_register(device, 0xFFF0, &value);
|
||||
cut_assert_equal_int(0, res, cut_message("read register 0xFFF0"));
|
||||
|
||||
nfc_close (device);
|
||||
nfc_exit (NULL);
|
||||
nfc_close(device);
|
||||
nfc_exit(NULL);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue