astyle
This commit is contained in:
parent
f184407cc5
commit
e4df2f3334
16 changed files with 121 additions and 120 deletions
|
@ -37,12 +37,12 @@
|
||||||
//There is no setenv()and unsetenv() in windows,but we can use putenv() instead.
|
//There is no setenv()and unsetenv() in windows,but we can use putenv() instead.
|
||||||
int setenv(const char *name, const char *value, int overwrite)
|
int setenv(const char *name, const char *value, int overwrite)
|
||||||
{
|
{
|
||||||
char* env = getenv(name);
|
char *env = getenv(name);
|
||||||
if ((env && overwrite) || (!env)) {
|
if ((env && overwrite) || (!env)) {
|
||||||
char* str[32];
|
char *str[32];
|
||||||
strcpy(str,name);
|
strcpy(str, name);
|
||||||
strcat(str,"=");
|
strcat(str, "=");
|
||||||
strcat(str,value);
|
strcat(str, value);
|
||||||
return putenv(str);
|
return putenv(str);
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -50,8 +50,8 @@ int setenv(const char *name, const char *value, int overwrite)
|
||||||
|
|
||||||
void unsetenv(const char *name)
|
void unsetenv(const char *name)
|
||||||
{
|
{
|
||||||
char* str[32];
|
char *str[32];
|
||||||
strcpy(str,name);
|
strcpy(str, name);
|
||||||
strcat(str,"=");
|
strcat(str, "=");
|
||||||
putenv(str);
|
putenv(str);
|
||||||
}
|
}
|
||||||
|
|
|
@ -196,7 +196,7 @@ spi_send_receive(spi_port sp, const uint8_t *pbtTx, const size_t szTx, uint8_t *
|
||||||
struct spi_ioc_transfer tr_send = {
|
struct spi_ioc_transfer tr_send = {
|
||||||
.tx_buf = (unsigned long) pbtTx,
|
.tx_buf = (unsigned long) pbtTx,
|
||||||
.rx_buf = 0,
|
.rx_buf = 0,
|
||||||
.len = szTx ,
|
.len = szTx,
|
||||||
.delay_usecs = 0,
|
.delay_usecs = 0,
|
||||||
.speed_hz = 0,
|
.speed_hz = 0,
|
||||||
.bits_per_word = 0,
|
.bits_per_word = 0,
|
||||||
|
|
|
@ -78,7 +78,7 @@ const char *serial_ports_device_radix[] = { "tty.SLAB_USBtoUART", "tty.usbserial
|
||||||
# elif defined (__FreeBSD__) || defined (__OpenBSD__) || defined(__FreeBSD_kernel__)
|
# elif defined (__FreeBSD__) || defined (__OpenBSD__) || defined(__FreeBSD_kernel__)
|
||||||
const char *serial_ports_device_radix[] = { "cuaU", "cuau", NULL };
|
const char *serial_ports_device_radix[] = { "cuaU", "cuau", NULL };
|
||||||
# elif defined (__NetBSD__)
|
# elif defined (__NetBSD__)
|
||||||
const char *serial_ports_device_radix[] = { "tty0", "ttyC", "ttyS", "ttyU", "ttyY" , NULL };
|
const char *serial_ports_device_radix[] = { "tty0", "ttyC", "ttyS", "ttyU", "ttyY", NULL };
|
||||||
# elif defined (__linux__) || defined (__CYGWIN__)
|
# elif defined (__linux__) || defined (__CYGWIN__)
|
||||||
const char *serial_ports_device_radix[] = { "ttyUSB", "ttyS", "ttyACM", "ttyAMA", "ttyO", NULL };
|
const char *serial_ports_device_radix[] = { "ttyUSB", "ttyS", "ttyACM", "ttyAMA", "ttyO", NULL };
|
||||||
# else
|
# else
|
||||||
|
|
|
@ -433,7 +433,7 @@ pn532_spi_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, int
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
pnd->last_error = spi_send_receive(DRIVER_DATA(pnd)->port, &pn532_spi_cmd_dataread, 1, abtRxBuf , 4, true);
|
pnd->last_error = spi_send_receive(DRIVER_DATA(pnd)->port, &pn532_spi_cmd_dataread, 1, abtRxBuf, 4, true);
|
||||||
|
|
||||||
if (pnd->last_error < 0) {
|
if (pnd->last_error < 0) {
|
||||||
goto error;
|
goto error;
|
||||||
|
|
|
@ -388,7 +388,7 @@ nfc_list_devices(nfc_context *context, nfc_connstring connstrings[], const size_
|
||||||
pndl = pndl->next;
|
pndl = pndl->next;
|
||||||
}
|
}
|
||||||
} else if (context->user_defined_device_count == 0) {
|
} else if (context->user_defined_device_count == 0) {
|
||||||
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_INFO, "Warning: %s" , "user must specify device(s) manually when autoscan is disabled");
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_INFO, "Warning: %s", "user must specify device(s) manually when autoscan is disabled");
|
||||||
}
|
}
|
||||||
|
|
||||||
return device_found;
|
return device_found;
|
||||||
|
|
|
@ -45,7 +45,7 @@ test_access_storm(void)
|
||||||
.nbr = NBR_106,
|
.nbr = NBR_106,
|
||||||
};
|
};
|
||||||
res = nfc_initiator_list_passive_targets(device, nm, ant, MAX_TARGET_COUNT);
|
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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,18 +86,18 @@ target_thread(void *arg)
|
||||||
|
|
||||||
uint8_t abtRx[1024];
|
uint8_t abtRx[1024];
|
||||||
int res = nfc_target_init(device, &nt, abtRx, sizeof(abtRx), 0);
|
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)));
|
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; }
|
if (res < 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
res = nfc_target_receive_bytes(device, abtRx, sizeof(abtRx), 500);
|
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)));
|
cut_assert_operator_int(res, >, 0, cut_message("Can't receive bytes from initiator: %s", nfc_strerror(device)));
|
||||||
const uint8_t abtAttRx[] = "Hello DEP target!";
|
const uint8_t abtAttRx[] = "Hello DEP target!";
|
||||||
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, res, cut_message("Invalid received data"));
|
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, res, cut_message("Invalid received data"));
|
||||||
if (res <= 0) { thread_res = -1; return (void *) thread_res; }
|
if (res <= 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
const uint8_t abtTx[] = "Hello DEP initiator!";
|
const uint8_t abtTx[] = "Hello DEP initiator!";
|
||||||
res = nfc_target_send_bytes(device, abtTx, sizeof(abtTx), 500);
|
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)));
|
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; }
|
if (res <= 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
return (void *) thread_res;
|
return (void *) thread_res;
|
||||||
|
@ -125,7 +125,7 @@ initiator_thread(void *arg)
|
||||||
// Active mode
|
// Active mode
|
||||||
printf("=========== INITIATOR %s (Active mode / %s Kbps) =========\n", nfc_device_get_name(device), str_nfc_baud_rate(nbr));
|
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);
|
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_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(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_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_memory("\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA", 10, nt.nti.ndi.abtNFCID3, 10, cut_message("Invalid target NFCID3"));
|
||||||
|
@ -136,13 +136,13 @@ initiator_thread(void *arg)
|
||||||
const uint8_t abtTx[] = "Hello DEP target!";
|
const uint8_t abtTx[] = "Hello DEP target!";
|
||||||
uint8_t abtRx[1024];
|
uint8_t abtRx[1024];
|
||||||
res = nfc_initiator_transceive_bytes(device, abtTx, sizeof(abtTx), abtRx, sizeof(abtRx), 5000);
|
res = nfc_initiator_transceive_bytes(device, abtTx, sizeof(abtTx), abtRx, sizeof(abtRx), 5000);
|
||||||
cut_assert_operator_int(res, >= , 0, cut_message("Can't transceive bytes to target: %s", nfc_strerror(device)));
|
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!";
|
const uint8_t abtAttRx[] = "Hello DEP initiator!";
|
||||||
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, res, cut_message("Invalid received data (as initiator)"));
|
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, res, cut_message("Invalid received data (as initiator)"));
|
||||||
if (res < 0) { thread_res = -1; return (void *) thread_res; }
|
if (res < 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
res = nfc_initiator_deselect_target(device);
|
res = nfc_initiator_deselect_target(device);
|
||||||
cut_assert_operator_int(res, >= , 0, cut_message("Can't deselect target: %s", nfc_strerror(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; }
|
if (res < 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
return (void *) thread_res;
|
return (void *) thread_res;
|
||||||
|
|
|
@ -86,12 +86,12 @@ target_thread(void *arg)
|
||||||
uint8_t abtRx[1024];
|
uint8_t abtRx[1024];
|
||||||
size_t szRx = sizeof(abtRx);
|
size_t szRx = sizeof(abtRx);
|
||||||
int res = nfc_target_init(device, &nt, abtRx, szRx, 0);
|
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)));
|
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; }
|
if (res < 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
// First pass
|
// First pass
|
||||||
res = nfc_target_receive_bytes(device, abtRx, sizeof(abtRx), 500);
|
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)));
|
cut_assert_operator_int(res, >, 0, cut_message("Can't receive bytes from initiator: %s", nfc_strerror(device)));
|
||||||
|
|
||||||
const uint8_t abtAttRx[] = "Hello DEP target!";
|
const uint8_t abtAttRx[] = "Hello DEP target!";
|
||||||
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, res, cut_message("Invalid received data"));
|
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, res, cut_message("Invalid received data"));
|
||||||
|
@ -99,40 +99,40 @@ target_thread(void *arg)
|
||||||
|
|
||||||
const uint8_t abtTx[] = "Hello DEP initiator!";
|
const uint8_t abtTx[] = "Hello DEP initiator!";
|
||||||
res = nfc_target_send_bytes(device, abtTx, sizeof(abtTx), 500);
|
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)));
|
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; }
|
if (res <= 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
// Second pass
|
// Second pass
|
||||||
res = nfc_target_receive_bytes(device, abtRx, sizeof(abtRx), 500);
|
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)));
|
cut_assert_operator_int(res, >, 0, cut_message("Can't receive bytes from initiator: %s", nfc_strerror(device)));
|
||||||
|
|
||||||
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, res, cut_message("Invalid received data"));
|
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, res, cut_message("Invalid received data"));
|
||||||
if (res <= 0) { thread_res = -1; return (void *) thread_res; }
|
if (res <= 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
res = nfc_target_send_bytes(device, abtTx, sizeof(abtTx), 500);
|
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)));
|
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; }
|
if (res <= 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
// Third pass
|
// Third pass
|
||||||
res = nfc_target_receive_bytes(device, abtRx, sizeof(abtRx), 500);
|
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)));
|
cut_assert_operator_int(res, >, 0, cut_message("Can't receive bytes from initiator: %s", nfc_strerror(device)));
|
||||||
|
|
||||||
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, res, cut_message("Invalid received data"));
|
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, res, cut_message("Invalid received data"));
|
||||||
if (res <= 0) { thread_res = -1; return (void *) thread_res; }
|
if (res <= 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
res = nfc_target_send_bytes(device, abtTx, sizeof(abtTx), 500);
|
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)));
|
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; }
|
if (res <= 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
// Fourth pass
|
// Fourth pass
|
||||||
res = nfc_target_receive_bytes(device, abtRx, sizeof(abtRx), 500);
|
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)));
|
cut_assert_operator_int(res, >, 0, cut_message("Can't receive bytes from initiator: %s", nfc_strerror(device)));
|
||||||
|
|
||||||
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, res, cut_message("Invalid received data"));
|
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, res, cut_message("Invalid received data"));
|
||||||
if (res <= 0) { thread_res = -1; return (void *) thread_res; }
|
if (res <= 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
res = nfc_target_send_bytes(device, abtTx, sizeof(abtTx), 500);
|
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)));
|
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; }
|
if (res <= 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
return (void *) thread_res;
|
return (void *) thread_res;
|
||||||
|
@ -160,7 +160,7 @@ initiator_thread(void *arg)
|
||||||
// Passive mode / 106Kbps
|
// Passive mode / 106Kbps
|
||||||
printf("=========== INITIATOR %s (Passive mode / 106Kbps) =========\n", nfc_device_get_name(device));
|
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);
|
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_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(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_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_memory("\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA", 10, nt.nti.ndi.abtNFCID3, 10, cut_message("Invalid target NFCID3"));
|
||||||
|
@ -171,20 +171,20 @@ initiator_thread(void *arg)
|
||||||
const uint8_t abtTx[] = "Hello DEP target!";
|
const uint8_t abtTx[] = "Hello DEP target!";
|
||||||
uint8_t abtRx[1024];
|
uint8_t abtRx[1024];
|
||||||
res = nfc_initiator_transceive_bytes(device, abtTx, sizeof(abtTx), abtRx, sizeof(abtRx), 500);
|
res = nfc_initiator_transceive_bytes(device, abtTx, sizeof(abtTx), abtRx, sizeof(abtRx), 500);
|
||||||
cut_assert_operator_int(res, >= , 0, cut_message("Can't transceive bytes to target: %s", nfc_strerror(device)));
|
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!";
|
const uint8_t abtAttRx[] = "Hello DEP initiator!";
|
||||||
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, res, cut_message("Invalid received data"));
|
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, res, cut_message("Invalid received data"));
|
||||||
if (res < 0) { thread_res = -1; return (void *) thread_res; }
|
if (res < 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
res = nfc_initiator_deselect_target(device);
|
res = nfc_initiator_deselect_target(device);
|
||||||
cut_assert_operator_int(res, >= , 0, cut_message("Can't deselect target: %s", nfc_strerror(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; }
|
if (res < 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
// Passive mode / 212Kbps (second pass)
|
// Passive mode / 212Kbps (second pass)
|
||||||
printf("=========== INITIATOR %s (Passive mode / 212Kbps) =========\n", nfc_device_get_name(device));
|
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);
|
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_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(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_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_memory("\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA", 10, nt.nti.ndi.abtNFCID3, 10, cut_message("Invalid target NFCID3"));
|
||||||
|
@ -193,19 +193,19 @@ initiator_thread(void *arg)
|
||||||
if (res <= 0) { thread_res = -1; return (void *) thread_res; }
|
if (res <= 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
res = nfc_initiator_transceive_bytes(device, abtTx, sizeof(abtTx), abtRx, sizeof(abtRx), 1000);
|
res = nfc_initiator_transceive_bytes(device, abtTx, sizeof(abtTx), abtRx, sizeof(abtRx), 1000);
|
||||||
cut_assert_operator_int(res, >= , 0, cut_message("Can't transceive bytes to target: %s", nfc_strerror(device)));
|
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, res, cut_message("Invalid received data"));
|
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, res, cut_message("Invalid received data"));
|
||||||
if (res < 0) { thread_res = -1; return (void *) thread_res; }
|
if (res < 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
res = nfc_initiator_deselect_target(device);
|
res = nfc_initiator_deselect_target(device);
|
||||||
cut_assert_operator_int(res, >= , 0, cut_message("Can't deselect target: %s", nfc_strerror(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; }
|
if (res < 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
// Passive mode / 212Kbps
|
// Passive mode / 212Kbps
|
||||||
printf("=========== INITIATOR %s (Passive mode / 212Kbps, second pass) =========\n", nfc_device_get_name(device));
|
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);
|
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_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(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_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_memory("\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA", 10, nt.nti.ndi.abtNFCID3, 10, cut_message("Invalid target NFCID3"));
|
||||||
|
@ -214,19 +214,19 @@ initiator_thread(void *arg)
|
||||||
if (res <= 0) { thread_res = -1; return (void *) thread_res; }
|
if (res <= 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
res = nfc_initiator_transceive_bytes(device, abtTx, sizeof(abtTx), abtRx, sizeof(abtRx), 5000);
|
res = nfc_initiator_transceive_bytes(device, abtTx, sizeof(abtTx), abtRx, sizeof(abtRx), 5000);
|
||||||
cut_assert_operator_int(res, >= , 0, cut_message("Can't transceive bytes to target: %s", nfc_strerror(device)));
|
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, res, cut_message("Invalid received data"));
|
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, res, cut_message("Invalid received data"));
|
||||||
if (res < 0) { thread_res = -1; return (void *) thread_res; }
|
if (res < 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
res = nfc_initiator_deselect_target(device);
|
res = nfc_initiator_deselect_target(device);
|
||||||
cut_assert_operator_int(res, >= , 0, cut_message("Can't deselect target: %s", nfc_strerror(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; }
|
if (res < 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
// Passive mode / 424Kbps
|
// Passive mode / 424Kbps
|
||||||
printf("=========== INITIATOR %s (Passive mode / 424Kbps) =========\n", nfc_device_get_name(device));
|
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);
|
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_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(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_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_memory("\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA", 10, nt.nti.ndi.abtNFCID3, 10, cut_message("Invalid target NFCID3"));
|
||||||
|
@ -235,13 +235,13 @@ initiator_thread(void *arg)
|
||||||
if (res <= 0) { thread_res = -1; return (void *) thread_res; }
|
if (res <= 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
res = nfc_initiator_transceive_bytes(device, abtTx, sizeof(abtTx), abtRx, sizeof(abtRx), 5000);
|
res = nfc_initiator_transceive_bytes(device, abtTx, sizeof(abtTx), abtRx, sizeof(abtRx), 5000);
|
||||||
cut_assert_operator_int(res, >= , 0, cut_message("Can't transceive bytes to target: %s", nfc_strerror(device)));
|
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, res, cut_message("Invalid received data"));
|
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, res, cut_message("Invalid received data"));
|
||||||
if (res < 0) { thread_res = -1; return (void *) thread_res; }
|
if (res < 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
res = nfc_initiator_deselect_target(device);
|
res = nfc_initiator_deselect_target(device);
|
||||||
cut_assert_operator_int(res, >= , 0, cut_message("Can't deselect target: %s", nfc_strerror(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; }
|
if (res < 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
return (void *) thread_res;
|
return (void *) thread_res;
|
||||||
|
|
|
@ -66,7 +66,7 @@ target_thread(void *arg)
|
||||||
|
|
||||||
// 1) nfc_target_init should take target in idle mode
|
// 1) nfc_target_init should take target in idle mode
|
||||||
int res = nfc_target_init(device, &nt, abtRx, sizeof(abtRx), 500);
|
int res = nfc_target_init(device, &nt, abtRx, sizeof(abtRx), 500);
|
||||||
cut_assert_operator_int(res, >= , 0, cut_message("Can't initialize NFC device as target: %s", nfc_strerror(device)));
|
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; }
|
if (res < 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
// 2) act as target
|
// 2) act as target
|
||||||
|
@ -92,11 +92,11 @@ target_thread(void *arg)
|
||||||
};
|
};
|
||||||
sleep(6);
|
sleep(6);
|
||||||
res = nfc_target_init(device, &nt1, abtRx, sizeof(abtRx), 0);
|
res = nfc_target_init(device, &nt1, abtRx, sizeof(abtRx), 0);
|
||||||
cut_assert_operator_int(res, > , 0, cut_message("Can't initialize NFC device as target: %s", nfc_strerror(device)));
|
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; }
|
if (res < 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
res = nfc_target_receive_bytes(device, abtRx, sizeof(abtRx), 500);
|
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)));
|
cut_assert_operator_int(res, >, 0, cut_message("Can't receive bytes from initiator: %s", nfc_strerror(device)));
|
||||||
|
|
||||||
const uint8_t abtAttRx[] = "Hello DEP target!";
|
const uint8_t abtAttRx[] = "Hello DEP target!";
|
||||||
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, res, cut_message("Invalid received data"));
|
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, res, cut_message("Invalid received data"));
|
||||||
|
@ -104,7 +104,7 @@ target_thread(void *arg)
|
||||||
|
|
||||||
const uint8_t abtTx[] = "Hello DEP initiator!";
|
const uint8_t abtTx[] = "Hello DEP initiator!";
|
||||||
res = nfc_target_send_bytes(device, abtTx, sizeof(abtTx), 500);
|
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)));
|
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; }
|
if (res <= 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
// 3) idle mode
|
// 3) idle mode
|
||||||
|
@ -144,7 +144,7 @@ initiator_thread(void *arg)
|
||||||
// Passive mode / 106Kbps
|
// Passive mode / 106Kbps
|
||||||
printf("=========== INITIATOR %s (Passive mode / 106Kbps) =========\n", nfc_device_get_name(device));
|
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);
|
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_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(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_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_memory("\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA", 10, nt1.nti.ndi.abtNFCID3, 10, cut_message("Invalid target NFCID3"));
|
||||||
|
@ -155,14 +155,14 @@ initiator_thread(void *arg)
|
||||||
const uint8_t abtTx[] = "Hello DEP target!";
|
const uint8_t abtTx[] = "Hello DEP target!";
|
||||||
uint8_t abtRx[1024];
|
uint8_t abtRx[1024];
|
||||||
res = nfc_initiator_transceive_bytes(device, abtTx, sizeof(abtTx), abtRx, sizeof(abtRx), 500);
|
res = nfc_initiator_transceive_bytes(device, abtTx, sizeof(abtTx), abtRx, sizeof(abtRx), 500);
|
||||||
cut_assert_operator_int(res, >= , 0, cut_message("Can't transceive bytes to target: %s", nfc_strerror(device)));
|
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!";
|
const uint8_t abtAttRx[] = "Hello DEP initiator!";
|
||||||
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, res, cut_message("Invalid received data"));
|
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, res, cut_message("Invalid received data"));
|
||||||
if (res < 0) { thread_res = -1; return (void *) thread_res; }
|
if (res < 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
res = nfc_initiator_deselect_target(device);
|
res = nfc_initiator_deselect_target(device);
|
||||||
cut_assert_operator_int(res, >= , 0, cut_message("Can't deselect target: %s", nfc_strerror(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; }
|
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
|
// 3) As other device should be in idle mode, nfc_initiator_poll_dep_target should return 0
|
||||||
|
|
|
@ -182,7 +182,8 @@ unlock_card(void)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool check_magic() {
|
static bool check_magic()
|
||||||
|
{
|
||||||
bool bFailure = false;
|
bool bFailure = false;
|
||||||
int uid_data;
|
int uid_data;
|
||||||
|
|
||||||
|
@ -210,7 +211,7 @@ static bool check_magic() {
|
||||||
if (nfc_initiator_mifare_cmd(pnd, MC_READ, 0, &mp)) {
|
if (nfc_initiator_mifare_cmd(pnd, MC_READ, 0, &mp)) {
|
||||||
//printf("%u", mp.mpd.abtData);
|
//printf("%u", mp.mpd.abtData);
|
||||||
bool result = true;
|
bool result = true;
|
||||||
for(int i = 0; i <= 7; i++) {
|
for (int i = 0; i <= 7; i++) {
|
||||||
if (mp.mpd.abtData[i] != 0x00) result = false;
|
if (mp.mpd.abtData[i] != 0x00) result = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -351,7 +352,7 @@ static size_t str_to_uid(const char *str, uint8_t *uid)
|
||||||
|
|
||||||
memset(uid, 0x0, MAX_UID_LEN);
|
memset(uid, 0x0, MAX_UID_LEN);
|
||||||
i = 0;
|
i = 0;
|
||||||
while ((*str != '\0') && ((i >> 1) < MAX_UID_LEN) ) {
|
while ((*str != '\0') && ((i >> 1) < MAX_UID_LEN)) {
|
||||||
char nibble[2] = { 0x00, '\n' }; /* for strtol */
|
char nibble[2] = { 0x00, '\n' }; /* for strtol */
|
||||||
|
|
||||||
nibble[0] = *str++;
|
nibble[0] = *str++;
|
||||||
|
|
Loading…
Add table
Reference in a new issue