Skip to content

Commit

Permalink
Cleanup codes again
Browse files Browse the repository at this point in the history
  • Loading branch information
ikspress committed Jun 30, 2024
1 parent cef4552 commit 805a939
Show file tree
Hide file tree
Showing 17 changed files with 160 additions and 164 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ ENDIF(LIBNFC_ENVVARS)

SET(LIBNFC_DEBUG_MODE OFF CACHE BOOL "Debug mode")
IF(LIBNFC_DEBUG_MODE)
ADD_DEFINITIONS(-DDEBUG)
SET(WIN32_MODE "debug")
ELSE(LIBNFC_DEBUG_MODE)
SET(WIN32_MODE "release")
Expand Down
2 changes: 1 addition & 1 deletion contrib/win32/libnfc/buses/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ uart_set_speed(serial_port sp, const uint32_t uiPortSpeed)
// Set baud rate
spw->dcb.BaudRate = uiPortSpeed;
if (!SetCommState(spw->hPort, &spw->dcb)) {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Unable to apply new speed settings.");
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to apply new speed settings.");
return;
}
PurgeComm(spw->hPort, PURGE_RXABORT | PURGE_RXCLEAR);
Expand Down
2 changes: 1 addition & 1 deletion libnfc/buses/i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
#include <limits.h>
#include <stdio.h>
#include <termios.h>
Expand Down
1 change: 0 additions & 1 deletion libnfc/buses/spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
#include <sys/types.h>
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <stdio.h>
Expand Down
6 changes: 3 additions & 3 deletions libnfc/buses/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ uart_set_speed(serial_port sp, const uint32_t uiPortSpeed)
cfsetispeed(&(UART_DATA(sp)->termios_new), stPortSpeed);
cfsetospeed(&(UART_DATA(sp)->termios_new), stPortSpeed);
if (tcsetattr(UART_DATA(sp)->fd, TCSADRAIN, &(UART_DATA(sp)->termios_new)) == -1) {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Unable to apply new speed settings.");
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to apply new speed settings.");
}
}

Expand Down Expand Up @@ -322,13 +322,13 @@ uart_receive(serial_port sp, uint8_t *pbtRx, const size_t szRx, void *abort_p, i
}
// Read time-out
if (res == 0) {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "Timeout!");
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Timeout!");
return NFC_ETIMEOUT;
}

if (FD_ISSET(iAbortFd, &rfds)) {
// Abort requested
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "Abort!");
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Abort!");
close(iAbortFd);
return NFC_EOPABORTED;
}
Expand Down
38 changes: 19 additions & 19 deletions libnfc/chips/pn53x.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ pn53x_transceive(struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx
if (timeout > 0) {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Timeout value: %d", timeout);
} else if (timeout == 0) {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "No timeout");
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "No timeout");
} else if (timeout == -1) {
timeout = CHIP_DATA(pnd)->timeout_command;
} else {
Expand Down Expand Up @@ -1996,7 +1996,7 @@ static int pn53x_Diagnose06(struct nfc_device *pnd)
static int pn53x_ISO14443A_4_is_present(struct nfc_device *pnd)
{
int ret;
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "target_is_present(): Ping -4A");
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "target_is_present(): Ping -4A");
if (CHIP_DATA(pnd)->type == PN533) {
ret = pn53x_Diagnose06(pnd);
if ((ret == NFC_ETIMEOUT) || (ret == NFC_ETGRELEASED)) {
Expand Down Expand Up @@ -2037,7 +2037,7 @@ static int pn53x_ISO14443A_4_is_present(struct nfc_device *pnd)
static int pn53x_ISO14443A_Jewel_is_present(struct nfc_device *pnd)
{
int ret;
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "target_is_present(): Ping Jewel");
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "target_is_present(): Ping Jewel");
uint8_t abtCmd[1] = {0x78};
int failures = 0;
while (failures < 2) {
Expand All @@ -2057,7 +2057,7 @@ static int pn53x_ISO14443A_Jewel_is_present(struct nfc_device *pnd)
static int pn53x_ISO14443A_Barcode_is_present(struct nfc_device *pnd)
{
int ret;
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "target_is_present(): Ping Barcode");
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "target_is_present(): Ping Barcode");

// We turn RF field off first for a better detection rate but this doesn't work well with ASK LoGO
if ((! CHIP_DATA(pnd)->progressive_field) && (ret = nfc_device_set_property_bool(pnd, NP_ACTIVATE_FIELD, false)) < 0) {
Expand Down Expand Up @@ -2091,7 +2091,7 @@ static int pn53x_ISO14443A_Barcode_is_present(struct nfc_device *pnd)
static int pn53x_ISO14443A_MFUL_is_present(struct nfc_device *pnd)
{
int ret;
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "target_is_present(): Ping MFUL");
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "target_is_present(): Ping MFUL");
// Limitation: test on MFULC non-authenticated with read of first sector forbidden will fail
if (CHIP_DATA(pnd)->type == PN533) {
ret = pn53x_Diagnose06(pnd);
Expand All @@ -2116,7 +2116,7 @@ static int pn53x_ISO14443A_MFUL_is_present(struct nfc_device *pnd)
static int pn53x_ISO14443A_MFC_is_present(struct nfc_device *pnd)
{
int ret;
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "target_is_present(): Ping MFC");
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "target_is_present(): Ping MFC");
if ((CHIP_DATA(pnd)->type == PN533) && (CHIP_DATA(pnd)->current_target->nti.nai.btSak != 0x09)) {
// MFC Mini (atqa0004/sak09) fails on PN533, so we exclude it
ret = pn53x_Diagnose06(pnd);
Expand Down Expand Up @@ -2145,7 +2145,7 @@ static int pn53x_ISO14443A_MFC_is_present(struct nfc_device *pnd)
static int pn53x_DEP_is_present(struct nfc_device *pnd)
{
int ret;
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "target_is_present(): Ping DEP");
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "target_is_present(): Ping DEP");
if ((CHIP_DATA(pnd)->type == PN531) || (CHIP_DATA(pnd)->type == PN532) || (CHIP_DATA(pnd)->type == PN533))
ret = pn53x_Diagnose06(pnd);
else
Expand All @@ -2155,7 +2155,7 @@ static int pn53x_DEP_is_present(struct nfc_device *pnd)

static int pn53x_Felica_is_present(struct nfc_device *pnd)
{
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "target_is_present(): Ping Felica");
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "target_is_present(): Ping Felica");
// if (CHIP_DATA(pnd)->type == PN533) { ret = pn53x_Diagnose06(pnd); } else...
// Because ping fails now & then, better not to use Diagnose at all
// Limitation: does not work on Felica Lite cards (neither Diagnose nor our method)
Expand All @@ -2176,7 +2176,7 @@ static int pn53x_Felica_is_present(struct nfc_device *pnd)
static int pn53x_ISO14443B_4_is_present(struct nfc_device *pnd)
{
int ret;
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "target_is_present(): Ping -4B");
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "target_is_present(): Ping -4B");
if (CHIP_DATA(pnd)->type == PN533) { // Not supported on PN532 even if the doc is same as for PN533
ret = pn53x_Diagnose06(pnd);
} else {
Expand Down Expand Up @@ -2209,7 +2209,7 @@ static int pn53x_ISO14443B_4_is_present(struct nfc_device *pnd)
static int pn53x_ISO14443B_I_is_present(struct nfc_device *pnd)
{
int ret;
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "target_is_present(): Ping B'");
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "target_is_present(): Ping B'");
// Sending ATTRIB in raw:
if ((ret = pn53x_set_property_bool(pnd, NP_EASY_FRAMING, false)) < 0)
return ret;
Expand Down Expand Up @@ -2238,7 +2238,7 @@ static int pn53x_ISO14443B_I_is_present(struct nfc_device *pnd)
static int pn53x_ISO14443B_SR_is_present(struct nfc_device *pnd)
{
int ret;
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "target_is_present(): Ping B2 ST SRx");
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "target_is_present(): Ping B2 ST SRx");
// Sending Get_UID in raw: (EASY_FRAMING is already supposed to be false)
uint8_t abtCmd[1] = {0x0b};
int failures = 0;
Expand All @@ -2261,7 +2261,7 @@ static int pn53x_ISO14443B_SR_is_present(struct nfc_device *pnd)
static int pn53x_ISO14443B_ICLASS_is_present(struct nfc_device *pnd)
{
int timeout = 300;
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "target_is_present(): Ping B iClass");
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "target_is_present(): Ping B iClass");
pn53x_initiator_init_iclass_modulation(pnd);
//
// Some work to do before getting the UID...
Expand All @@ -2284,7 +2284,7 @@ static int pn53x_ISO14443B_ICLASS_is_present(struct nfc_device *pnd)
static int pn53x_ISO14443B_CT_is_present(struct nfc_device *pnd)
{
int ret;
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "target_is_present(): Ping B2 ASK CTx");
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "target_is_present(): Ping B2 ASK CTx");
// Sending SELECT in raw: (EASY_FRAMING is already supposed to be false)
uint8_t abtCmd[3] = {0x9f};
memcpy(abtCmd + 1, CHIP_DATA(pnd)->current_target->nti.nci.abtUID, 2);
Expand All @@ -2310,13 +2310,13 @@ pn53x_initiator_target_is_present(struct nfc_device *pnd, const nfc_target *pnt)
{
// Check if there is a saved target
if (CHIP_DATA(pnd)->current_target == NULL) {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "target_is_present(): no saved target");
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "target_is_present(): no saved target");
return pnd->last_error = NFC_EINVARG;
}

// Check if the argument target nt is equals to current saved target
if ((pnt != NULL) && (!pn53x_current_target_is(pnd, pnt))) {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "target_is_present(): another target");
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "target_is_present(): another target");
return pnd->last_error = NFC_ETGRELEASED;
}

Expand All @@ -2333,7 +2333,7 @@ pn53x_initiator_target_is_present(struct nfc_device *pnd, const nfc_target *pnt)
} else if (CHIP_DATA(pnd)->current_target->nti.nai.btSak & 0x08) {
ret = pn53x_ISO14443A_MFC_is_present(pnd);
} else {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "target_is_present(): card type A not supported");
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "target_is_present(): card type A not supported");
ret = NFC_EDEVNOTSUPP;
}
break;
Expand Down Expand Up @@ -3311,12 +3311,12 @@ pn53x_check_ack_frame(struct nfc_device *pnd, const uint8_t *pbtRxFrame, const s
{
if (szRxFrameLen >= sizeof(pn53x_ack_frame)) {
if (0 == memcmp(pbtRxFrame, pn53x_ack_frame, sizeof(pn53x_ack_frame))) {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "PN53x ACKed");
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "PN53x ACKed");
return NFC_SUCCESS;
}
}
pnd->last_error = NFC_EIO;
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Unexpected PN53x reply!");
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unexpected PN53x reply!");
return pnd->last_error;
}

Expand All @@ -3325,7 +3325,7 @@ pn53x_check_error_frame(struct nfc_device *pnd, const uint8_t *pbtRxFrame, const
{
if (szRxFrameLen >= sizeof(pn53x_error_frame)) {
if (0 == memcmp(pbtRxFrame, pn53x_error_frame, sizeof(pn53x_error_frame))) {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "PN53x sent an error frame");
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "PN53x sent an error frame");
pnd->last_error = NFC_EIO;
return pnd->last_error;
}
Expand Down
6 changes: 3 additions & 3 deletions libnfc/conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ conf_keyvalue_context(void *data, const char *key, const char *value)
} else if (strcmp(key, "device.name") == 0) {
if ((context->user_defined_device_count == 0) || strcmp(context->user_defined_devices[context->user_defined_device_count - 1].name, "") != 0) {
if (context->user_defined_device_count >= MAX_USER_DEFINED_DEVICES) {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Configuration exceeded maximum user-defined devices.");
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Configuration exceeded maximum user-defined devices.");
return;
}
context->user_defined_device_count++;
Expand All @@ -230,7 +230,7 @@ conf_keyvalue_context(void *data, const char *key, const char *value)
} else if (strcmp(key, "device.connstring") == 0) {
if ((context->user_defined_device_count == 0) || strcmp(context->user_defined_devices[context->user_defined_device_count - 1].connstring, "") != 0) {
if (context->user_defined_device_count >= MAX_USER_DEFINED_DEVICES) {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Configuration exceeded maximum user-defined devices.");
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Configuration exceeded maximum user-defined devices.");
return;
}
context->user_defined_device_count++;
Expand All @@ -240,7 +240,7 @@ conf_keyvalue_context(void *data, const char *key, const char *value)
} else if (strcmp(key, "device.optional") == 0) {
if ((context->user_defined_device_count == 0) || context->user_defined_devices[context->user_defined_device_count - 1].optional) {
if (context->user_defined_device_count >= MAX_USER_DEFINED_DEVICES) {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Configuration exceeded maximum user-defined devices.");
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Configuration exceeded maximum user-defined devices.");
return;
}
context->user_defined_device_count++;
Expand Down
6 changes: 3 additions & 3 deletions libnfc/drivers/acr122_pcsc.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,11 @@ acr122_pcsc_open(const nfc_context *context, const nfc_connstring connstring)
if (!(pscc = acr122_pcsc_get_scardcontext()))
goto error;
// Test if we were able to connect to the "emulator" card
if (SCardConnect(*pscc, ndd.pcsc_device_name, SCARD_SHARE_EXCLUSIVE, SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1, &(DRIVER_DATA(pnd)->hCard), (void *) & (DRIVER_DATA(pnd)->ioCard.dwProtocol)) != SCARD_S_SUCCESS) {
if (SCardConnect(*pscc, ndd.pcsc_device_name, SCARD_SHARE_EXCLUSIVE, SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1, &(DRIVER_DATA(pnd)->hCard), &(DRIVER_DATA(pnd)->ioCard.dwProtocol)) != SCARD_S_SUCCESS) {
// Connect to ACR122 firmware version >2.0
if (SCardConnect(*pscc, ndd.pcsc_device_name, SCARD_SHARE_DIRECT, 0, &(DRIVER_DATA(pnd)->hCard), (void *) & (DRIVER_DATA(pnd)->ioCard.dwProtocol)) != SCARD_S_SUCCESS) {
if (SCardConnect(*pscc, ndd.pcsc_device_name, SCARD_SHARE_DIRECT, 0, &(DRIVER_DATA(pnd)->hCard), &(DRIVER_DATA(pnd)->ioCard.dwProtocol)) != SCARD_S_SUCCESS) {
// We can not connect to this device.
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "PCSC connect failed");
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "PCSC connect failed");
goto error;
}
}
Expand Down
Loading

0 comments on commit 805a939

Please sign in to comment.