diff --git a/contrib/win32/stdlib.c b/contrib/win32/stdlib.c index fc27042..5a1bd56 100644 --- a/contrib/win32/stdlib.c +++ b/contrib/win32/stdlib.c @@ -37,12 +37,12 @@ //There is no setenv()and unsetenv() in windows,but we can use putenv() instead. int setenv(const char *name, const char *value, int overwrite) { - char* env = getenv(name); + char *env = getenv(name); if ((env && overwrite) || (!env)) { - char* str[32]; - strcpy(str,name); - strcat(str,"="); - strcat(str,value); + char *str[32]; + strcpy(str, name); + strcat(str, "="); + strcat(str, value); return putenv(str); } return -1; @@ -50,8 +50,8 @@ int setenv(const char *name, const char *value, int overwrite) void unsetenv(const char *name) { - char* str[32]; - strcpy(str,name); - strcat(str,"="); + char *str[32]; + strcpy(str, name); + strcat(str, "="); putenv(str); } diff --git a/libnfc/buses/spi.c b/libnfc/buses/spi.c index 3d29fd3..0e68f9b 100644 --- a/libnfc/buses/spi.c +++ b/libnfc/buses/spi.c @@ -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 = { .tx_buf = (unsigned long) pbtTx, .rx_buf = 0, - .len = szTx , + .len = szTx, .delay_usecs = 0, .speed_hz = 0, .bits_per_word = 0, diff --git a/libnfc/buses/uart.c b/libnfc/buses/uart.c index 61ad87d..ffe64aa 100644 --- a/libnfc/buses/uart.c +++ b/libnfc/buses/uart.c @@ -78,7 +78,7 @@ const char *serial_ports_device_radix[] = { "tty.SLAB_USBtoUART", "tty.usbserial # elif defined (__FreeBSD__) || defined (__OpenBSD__) || defined(__FreeBSD_kernel__) const char *serial_ports_device_radix[] = { "cuaU", "cuau", NULL }; # 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__) const char *serial_ports_device_radix[] = { "ttyUSB", "ttyS", "ttyACM", "ttyAMA", "ttyO", NULL }; # else diff --git a/libnfc/chips/pn53x.c b/libnfc/chips/pn53x.c index 4abfefc..f48fd48 100644 --- a/libnfc/chips/pn53x.c +++ b/libnfc/chips/pn53x.c @@ -611,7 +611,7 @@ pn53x_decode_target_data(const uint8_t *pbtRawData, size_t szRawData, pn53x_type pbtRawData += 2; memcpy(pnti->nji.btId, pbtRawData, 4); break; - // Should not happend... + // Should not happend... case NMT_DEP: return NFC_ECHIP; } @@ -829,7 +829,7 @@ pn53x_set_property_int(struct nfc_device *pnd, const nfc_property property, cons case NP_TIMEOUT_COM: CHIP_DATA(pnd)->timeout_communication = value; return pn53x_RFConfiguration__Various_timings(pnd, pn53x_int_to_timeout(CHIP_DATA(pnd)->timeout_atr), pn53x_int_to_timeout(CHIP_DATA(pnd)->timeout_communication)); - // Following properties are invalid (not integer) + // Following properties are invalid (not integer) case NP_HANDLE_CRC: case NP_HANDLE_PARITY: case NP_ACTIVATE_FIELD: @@ -952,7 +952,7 @@ pn53x_set_property_bool(struct nfc_device *pnd, const nfc_property property, con return res; } return pn53x_write_register(pnd, PN53X_REG_CIU_RxMode, SYMBOL_RX_SPEED, 0x00); - // Following properties are invalid (not boolean) + // Following properties are invalid (not boolean) case NP_TIMEOUT_COMMAND: case NP_TIMEOUT_ATR: case NP_TIMEOUT_COM: @@ -2391,7 +2391,7 @@ pn53x_target_receive_bytes(struct nfc_device *pnd, uint8_t *pbtRx, const size_t return pnd->last_error; } } - // NO BREAK + // NO BREAK case NMT_JEWEL: case NMT_ISO14443B: case NMT_ISO14443BI: @@ -2496,7 +2496,7 @@ pn53x_target_send_bytes(struct nfc_device *pnd, const uint8_t *pbtTx, const size return pnd->last_error; } } - // NO BREAK + // NO BREAK case NMT_JEWEL: case NMT_ISO14443B: case NMT_ISO14443BI: @@ -3215,7 +3215,7 @@ pn53x_nm_to_ptt(const nfc_modulation nm) switch (nm.nmt) { case NMT_ISO14443A: return PTT_MIFARE; - // return PTT_ISO14443_4A_106; + // return PTT_ISO14443_4A_106; case NMT_ISO14443B: switch (nm.nbr) { diff --git a/libnfc/conf.c b/libnfc/conf.c index 590ca6e..149173a 100644 --- a/libnfc/conf.c +++ b/libnfc/conf.c @@ -60,7 +60,7 @@ static int escaped_value(const char line[BUFSIZ], int i, char **value) { if (line[i] != '"') - goto FAIL; + goto FAIL; i++; if (line[i] == 0 || line[i] == '\n') goto FAIL; diff --git a/libnfc/drivers/pn532_i2c.c b/libnfc/drivers/pn532_i2c.c index d242df9..67762a1 100644 --- a/libnfc/drivers/pn532_i2c.c +++ b/libnfc/drivers/pn532_i2c.c @@ -120,19 +120,19 @@ static struct timespec __transaction_stop; * @return length (in bytes) of read data, or driver error code (negative value) */ static ssize_t pn532_i2c_read(const i2c_device id, - uint8_t *buf, const size_t len) + uint8_t *buf, const size_t len) { - struct timespec transaction_start, bus_free_time = { 0 }; - ssize_t ret; + struct timespec transaction_start, bus_free_time = { 0 }; + ssize_t ret; - clock_gettime(CLOCK_MONOTONIC, &transaction_start); - bus_free_time.tv_nsec = (PN532_BUS_FREE_TIME * 1000 * 1000) - - (transaction_start.tv_nsec - __transaction_stop.tv_nsec); - nanosleep(&bus_free_time, NULL); + clock_gettime(CLOCK_MONOTONIC, &transaction_start); + bus_free_time.tv_nsec = (PN532_BUS_FREE_TIME * 1000 * 1000) - + (transaction_start.tv_nsec - __transaction_stop.tv_nsec); + nanosleep(&bus_free_time, NULL); - ret = i2c_read(id, buf, len); - clock_gettime(CLOCK_MONOTONIC, &__transaction_stop); - return ret; + ret = i2c_read(id, buf, len); + clock_gettime(CLOCK_MONOTONIC, &__transaction_stop); + return ret; } /** @@ -148,19 +148,19 @@ static ssize_t pn532_i2c_read(const i2c_device id, * @return NFC_SUCCESS on success, otherwise driver error code */ static ssize_t pn532_i2c_write(const i2c_device id, - const uint8_t *buf, const size_t len) + const uint8_t *buf, const size_t len) { - struct timespec transaction_start, bus_free_time = { 0 }; - ssize_t ret; + struct timespec transaction_start, bus_free_time = { 0 }; + ssize_t ret; - clock_gettime(CLOCK_MONOTONIC, &transaction_start); - bus_free_time.tv_nsec = (PN532_BUS_FREE_TIME * 1000 * 1000) - - (transaction_start.tv_nsec - __transaction_stop.tv_nsec); - nanosleep(&bus_free_time, NULL); + clock_gettime(CLOCK_MONOTONIC, &transaction_start); + bus_free_time.tv_nsec = (PN532_BUS_FREE_TIME * 1000 * 1000) - + (transaction_start.tv_nsec - __transaction_stop.tv_nsec); + nanosleep(&bus_free_time, NULL); - ret = i2c_write(id, buf, len); - clock_gettime(CLOCK_MONOTONIC, &__transaction_stop); - return ret; + ret = i2c_write(id, buf, len); + clock_gettime(CLOCK_MONOTONIC, &__transaction_stop); + return ret; } /** diff --git a/libnfc/drivers/pn532_spi.c b/libnfc/drivers/pn532_spi.c index f9ed9db..39a8b51 100644 --- a/libnfc/drivers/pn532_spi.c +++ b/libnfc/drivers/pn532_spi.c @@ -433,7 +433,7 @@ pn532_spi_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, int 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) { goto error; diff --git a/libnfc/drivers/pn53x_usb.c b/libnfc/drivers/pn53x_usb.c index d0c9adf..c9659de 100644 --- a/libnfc/drivers/pn53x_usb.c +++ b/libnfc/drivers/pn53x_usb.c @@ -351,7 +351,7 @@ pn53x_usb_open(const nfc_context *context, const nfc_connstring connstring) } switch (DRIVER_DATA(pnd)->model) { - // empirical tuning + // empirical tuning case ASK_LOGO: CHIP_DATA(pnd)->timer_correction = 50; break; @@ -697,12 +697,12 @@ pn53x_usb_set_property_bool(nfc_device *pnd, const nfc_property property, const } break; case SCM_SCL3712: - if (NP_ACTIVATE_FIELD == property) { - // Switch on/off LED according to ACTIVATE_FIELD option - if ((res = pn53x_write_register(pnd, PN53X_SFR_P3, _BV(P32), bEnable ? 0 : _BV(P32))) < 0) - return res; - } - break; + if (NP_ACTIVATE_FIELD == property) { + // Switch on/off LED according to ACTIVATE_FIELD option + if ((res = pn53x_write_register(pnd, PN53X_SFR_P3, _BV(P32), bEnable ? 0 : _BV(P32))) < 0) + return res; + } + break; case NXP_PN531: case NXP_PN533: case SONY_PN531: diff --git a/libnfc/nfc.c b/libnfc/nfc.c index 42d4ab7..008d2e4 100644 --- a/libnfc/nfc.c +++ b/libnfc/nfc.c @@ -388,7 +388,7 @@ nfc_list_devices(nfc_context *context, nfc_connstring connstrings[], const size_ pndl = pndl->next; } } 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; diff --git a/test/test_access_storm.c b/test/test_access_storm.c index c86d855..deff802 100644 --- a/test/test_access_storm.c +++ b/test/test_access_storm.c @@ -45,7 +45,7 @@ test_access_storm(void) .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); } diff --git a/test/test_dep_active.c b/test/test_dep_active.c index ff87f6e..68a873c 100644 --- a/test/test_dep_active.c +++ b/test/test_dep_active.c @@ -86,18 +86,18 @@ target_thread(void *arg) uint8_t abtRx[1024]; 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; } 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!"; cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, res, 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))); + 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; @@ -125,7 +125,7 @@ initiator_thread(void *arg) // 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_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")); @@ -136,13 +136,13 @@ initiator_thread(void *arg) const uint8_t abtTx[] = "Hello DEP target!"; uint8_t abtRx[1024]; 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!"; 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; } 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; } return (void *) thread_res; diff --git a/test/test_dep_passive.c b/test/test_dep_passive.c index 71d7e3a..1f7a927 100644 --- a/test/test_dep_passive.c +++ b/test/test_dep_passive.c @@ -86,12 +86,12 @@ 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))); + 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))); + 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!"; 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!"; 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; } // 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))); + 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")); 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))); + 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))); + 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")); 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))); + 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))); + 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")); 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))); + 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; @@ -160,7 +160,7 @@ initiator_thread(void *arg) // 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_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")); @@ -171,20 +171,20 @@ initiator_thread(void *arg) const uint8_t abtTx[] = "Hello DEP target!"; uint8_t abtRx[1024]; 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!"; cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, res, 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))); + 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_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")); @@ -193,19 +193,19 @@ initiator_thread(void *arg) if (res <= 0) { thread_res = -1; return (void *) thread_res; } 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")); 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))); + 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_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")); @@ -214,19 +214,19 @@ initiator_thread(void *arg) if (res <= 0) { thread_res = -1; return (void *) thread_res; } 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")); 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))); + 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_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")); @@ -235,13 +235,13 @@ initiator_thread(void *arg) if (res <= 0) { thread_res = -1; return (void *) thread_res; } 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")); 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))); + 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; diff --git a/test/test_device_modes_as_dep.c b/test/test_device_modes_as_dep.c index 48ee9b9..7bfd5ef 100644 --- a/test/test_device_modes_as_dep.c +++ b/test/test_device_modes_as_dep.c @@ -66,7 +66,7 @@ target_thread(void *arg) // 1) nfc_target_init should take target in idle mode 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; } // 2) act as target @@ -92,11 +92,11 @@ target_thread(void *arg) }; sleep(6); 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; } 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!"; 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!"; 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; } // 3) idle mode @@ -144,7 +144,7 @@ initiator_thread(void *arg) // 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_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")); @@ -155,14 +155,14 @@ initiator_thread(void *arg) const uint8_t abtTx[] = "Hello DEP target!"; uint8_t abtRx[1024]; 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!"; cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, res, 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))); + 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 diff --git a/utils/mifare.c b/utils/mifare.c index 5e368fc..1cbf6b1 100644 --- a/utils/mifare.c +++ b/utils/mifare.c @@ -68,31 +68,31 @@ nfc_initiator_mifare_cmd(nfc_device *pnd, const mifare_cmd mc, const uint8_t ui8 abtCmd[1] = ui8Block; // The block address (1K=0x00..0x39, 4K=0x00..0xff) switch (mc) { - // Read and store command have no parameter + // Read and store command have no parameter case MC_READ: case MC_STORE: szParamLen = 0; break; - // Authenticate command + // Authenticate command case MC_AUTH_A: case MC_AUTH_B: szParamLen = sizeof(struct mifare_param_auth); break; - // Data command + // Data command case MC_WRITE: szParamLen = sizeof(struct mifare_param_data); break; - // Value command + // Value command case MC_DECREMENT: case MC_INCREMENT: case MC_TRANSFER: szParamLen = sizeof(struct mifare_param_value); break; - // Please fix your code, you never should reach this statement + // Please fix your code, you never should reach this statement default: return false; } diff --git a/utils/nfc-mfclassic.c b/utils/nfc-mfclassic.c index 19ef1eb..2e03e3f 100644 --- a/utils/nfc-mfclassic.c +++ b/utils/nfc-mfclassic.c @@ -310,7 +310,7 @@ read_card(int read_unlocked) uint32_t uiReadBlocks = 0; if (read_unlocked) { - //If the user is attempting an unlocked read, but has a direct-write type magic card, they don't + //If the user is attempting an unlocked read, but has a direct-write type magic card, they don't //need to use the R mode. We'll trigger a warning and let them proceed. if (magic2) { printf("Note: This card does not require an unlocked write (R) \n"); @@ -318,11 +318,11 @@ read_card(int read_unlocked) } else { //If User has requested an unlocked read, but we're unable to unlock the card, we'll error out. if (!unlock_card()) { - return false; + return false; } } } - + printf("Reading out %d blocks |", uiBlocks + 1); // Read the card from end to begin for (iBlock = uiBlocks; iBlock >= 0; iBlock--) { @@ -390,7 +390,7 @@ write_card(int write_block_zero) uint32_t uiWriteBlocks = 0; if (write_block_zero) { - //If the user is attempting an unlocked write, but has a direct-write type magic card, they don't + //If the user is attempting an unlocked write, but has a direct-write type magic card, they don't //need to use the W mode. We'll trigger a warning and let them proceed. if (magic2) { printf("Note: This card does not require an unlocked write (W) \n"); @@ -398,11 +398,11 @@ write_card(int write_block_zero) } else { //If User has requested an unlocked write, but we're unable to unlock the card, we'll error out. if (!unlock_card()) { - return false; + return false; } } } - + printf("Writing %d blocks |", uiBlocks + 1); // Write the card from begin to end; for (uiBlock = 0; uiBlock <= uiBlocks; uiBlock++) { diff --git a/utils/nfc-mfultralight.c b/utils/nfc-mfultralight.c index 63ea215..b89bc43 100644 --- a/utils/nfc-mfultralight.c +++ b/utils/nfc-mfultralight.c @@ -182,11 +182,12 @@ unlock_card(void) return true; } -static bool check_magic() { - bool bFailure = false; - int uid_data; +static bool check_magic() +{ + bool bFailure = false; + int uid_data; - for (uint32_t page = 0; page <= 1; page++) { + for (uint32_t page = 0; page <= 1; page++) { // Show if the readout went well if (bFailure) { // When a failure occured we need to redo the anti-collision @@ -206,27 +207,27 @@ static bool check_magic() { nfc_initiator_mifare_cmd(pnd, MC_WRITE, page, &mp); } - //Check that the ID is now set to 0x000000000000 - if (nfc_initiator_mifare_cmd(pnd, MC_READ, 0, &mp)) { - //printf("%u", mp.mpd.abtData); - bool result = true; - for(int i = 0; i <= 7; i++) { - if (mp.mpd.abtData[i] != 0x00) result = false; - } - - if (result) { - return true; - } - + //Check that the ID is now set to 0x000000000000 + if (nfc_initiator_mifare_cmd(pnd, MC_READ, 0, &mp)) { + //printf("%u", mp.mpd.abtData); + bool result = true; + for (int i = 0; i <= 7; i++) { + if (mp.mpd.abtData[i] != 0x00) result = false; } - //Initially check if we can unlock via the MF method - if (unlock_card()) { + if (result) { return true; - } else { - return false; } + } + + //Initially check if we can unlock via the MF method + if (unlock_card()) { + return true; + } else { + return false; + } + } static bool @@ -351,7 +352,7 @@ static size_t str_to_uid(const char *str, uint8_t *uid) memset(uid, 0x0, MAX_UID_LEN); 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 */ nibble[0] = *str++; @@ -391,8 +392,8 @@ main(int argc, const char *argv[]) FILE *pfDump; if (argc < 2) { - print_usage(argv); - exit(EXIT_FAILURE); + print_usage(argv); + exit(EXIT_FAILURE); } DBG("\nChecking arguments and settings\n"); @@ -541,12 +542,12 @@ main(int argc, const char *argv[]) write_card(bOTP, bLock, bUID); } else if (iAction == 3) { if (!check_magic()) { - printf("Card is not magic\n"); - nfc_close(pnd); - nfc_exit(context); - exit(EXIT_FAILURE); + printf("Card is not magic\n"); + nfc_close(pnd); + nfc_exit(context); + exit(EXIT_FAILURE); } else { - printf("Card is magic\n"); + printf("Card is magic\n"); } }