Commit 562205cc authored by Philippe Teuwen's avatar Philippe Teuwen

astyle --formatted --mode=c --indent=spaces=2 --indent-switches...

astyle --formatted --mode=c --indent=spaces=2 --indent-switches --indent-preprocessor --keep-one-line-blocks --max-instatement-indent=60 --brackets=linux --pad-oper
parent 67522bae
......@@ -111,7 +111,7 @@ target_io( nfc_target *pnt, const uint8_t *pbtInput, const size_t szInput, uint8
*pszOutput = pnt->nti.nai.szAtsLen + 1;
pbtOutput[0] = pnt->nti.nai.szAtsLen + 1; // ISO14443-4 says that ATS contains ATS_Length as first byte
if(pnt->nti.nai.szAtsLen) {
memcpy(pbtOutput+1, pnt->nti.nai.abtAts, pnt->nti.nai.szAtsLen);
memcpy(pbtOutput + 1, pnt->nti.nai.abtAts, pnt->nti.nai.szAtsLen);
}
break;
case 0xc2: // S-block DESELECT
......
......@@ -148,9 +148,9 @@ int
main (int argc, char *argv[])
{
int arg, i;
bool format= false;
bool format = false;
unsigned int c;
char tmp[3]= { 0x00, 0x00, 0x00 };
char tmp[3] = { 0x00, 0x00, 0x00 };
// Get commandline options
......@@ -159,16 +159,16 @@ main (int argc, char *argv[])
print_usage (argv);
exit(EXIT_SUCCESS);
} else if (0 == strcmp (argv[arg], "-f")) {
format= true;
format = true;
} else if (0 == strcmp (argv[arg], "-q")) {
quiet_output = true;
} else if (strlen(argv[arg]) == 8) {
for(i= 0 ; i < 4 ; ++i) {
memcpy(tmp, argv[arg]+i*2, 2);
for(i = 0 ; i < 4 ; ++i) {
memcpy(tmp, argv[arg] + i * 2, 2);
sscanf(tmp, "%02x", &c);
abtData[i]= (char) c;
abtData[i] = (char) c;
}
abtData[4]= abtData[0] ^ abtData[1] ^ abtData[2] ^ abtData[3];
abtData[4] = abtData[0] ^ abtData[1] ^ abtData[2] ^ abtData[3];
iso14443a_crc_append (abtData, 16);
} else {
ERR ("%s is not supported option.", argv[arg]);
......@@ -334,21 +334,21 @@ main (int argc, char *argv[])
// now reset UID
iso14443a_crc_append(abtHalt, 2);
transmit_bytes (abtHalt, 4);
transmit_bits (abtUnlock1,7);
transmit_bits (abtUnlock1, 7);
if(format) {
transmit_bytes (abtWipe,1);
transmit_bytes (abtWipe, 1);
transmit_bytes (abtHalt, 4);
transmit_bits (abtUnlock1,7);
transmit_bits (abtUnlock1, 7);
}
transmit_bytes (abtUnlock2,1);
transmit_bytes (abtWrite,4);
transmit_bytes (abtData,18);
transmit_bytes (abtUnlock2, 1);
transmit_bytes (abtWrite, 4);
transmit_bytes (abtData, 18);
if(format) {
for(i = 3 ; i < 64 ; i += 4) {
abtWrite[1]= (char) i;
abtWrite[1] = (char) i;
iso14443a_crc_append (abtWrite, 2);
transmit_bytes (abtWrite,4);
transmit_bytes (abtBlank,18);
transmit_bytes (abtWrite, 4);
transmit_bytes (abtBlank, 18);
}
}
......
......@@ -77,7 +77,7 @@ int main(int argc, const char* argv[])
FILE* input = NULL;
if (argc >= 2) {
if((input = fopen(argv[1], "r"))==NULL) {
if((input = fopen(argv[1], "r")) == NULL) {
ERR ("%s", "Cannot open file.");
return EXIT_FAILURE;
}
......@@ -147,7 +147,7 @@ int main(int argc, const char* argv[])
}
sscanf(cmd + offset, "%d", &s);
printf("Pause for %i msecs\n", s);
if (s>0) {
if (s > 0) {
sleep(s * SUSP_TIME);
}
free(cmd);
......@@ -160,13 +160,13 @@ int main(int argc, const char* argv[])
while (isspace(cmd[offset])) {
offset++;
}
size = sscanf(cmd+offset, "%2x", &byte);
size = sscanf(cmd + offset, "%2x", &byte);
if (size < 1 ) {
break;
}
abtTx[i] = byte;
szTx++;
if (cmd[offset+1] == 0) { // if last hex was only 1 symbol
if (cmd[offset + 1] == 0) { // if last hex was only 1 symbol
break;
}
offset += 2;
......@@ -177,7 +177,7 @@ int main(int argc, const char* argv[])
continue;
}
printf("Tx: ");
print_hex(abtTx,szTx);
print_hex(abtTx, szTx);
szRx = sizeof(abtRx);
int res = 0;
......
......@@ -349,18 +349,18 @@ uart_list_ports (void)
const char **p = serial_ports_device_radix;
while (*p) {
if (!strncmp(pdDirEnt->d_name, *p, strlen (*p))) {
char **res2 = realloc (res, (szRes+1) * sizeof (char *));
char **res2 = realloc (res, (szRes + 1) * sizeof (char *));
if (!res2)
goto oom;
res = res2;
if (!(res[szRes-1] = malloc (6 + strlen (pdDirEnt->d_name))))
if (!(res[szRes - 1] = malloc (6 + strlen (pdDirEnt->d_name))))
goto oom;
sprintf (res[szRes-1], "/dev/%s", pdDirEnt->d_name);
sprintf (res[szRes - 1], "/dev/%s", pdDirEnt->d_name);
szRes++;
res[szRes-1] = NULL;
res[szRes - 1] = NULL;
}
p++;
}
......
......@@ -144,49 +144,49 @@ typedef enum {
static const pn53x_command pn53x_commands[] = {
// Miscellaneous
PNCMD( Diagnose, PN531|PN532|PN533|RCS360 ),
PNCMD( GetFirmwareVersion, PN531|PN532|PN533|RCS360 ),
PNCMD( GetGeneralStatus, PN531|PN532|PN533|RCS360 ),
PNCMD( ReadRegister, PN531|PN532|PN533|RCS360 ),
PNCMD( WriteRegister, PN531|PN532|PN533|RCS360 ),
PNCMD( ReadGPIO, PN531|PN532|PN533 ),
PNCMD( WriteGPIO, PN531|PN532|PN533 ),
PNCMD( SetSerialBaudRate, PN531|PN532|PN533 ),
PNCMD( SetParameters, PN531|PN532|PN533|RCS360 ),
PNCMD( SAMConfiguration, PN531|PN532 ),
PNCMD( PowerDown, PN531|PN532 ),
PNCMD( AlparCommandForTDA, PN533|RCS360 ), // Has another usage on RC-S360...
PNCMD( Diagnose, PN531 | PN532 | PN533 | RCS360 ),
PNCMD( GetFirmwareVersion, PN531 | PN532 | PN533 | RCS360 ),
PNCMD( GetGeneralStatus, PN531 | PN532 | PN533 | RCS360 ),
PNCMD( ReadRegister, PN531 | PN532 | PN533 | RCS360 ),
PNCMD( WriteRegister, PN531 | PN532 | PN533 | RCS360 ),
PNCMD( ReadGPIO, PN531 | PN532 | PN533 ),
PNCMD( WriteGPIO, PN531 | PN532 | PN533 ),
PNCMD( SetSerialBaudRate, PN531 | PN532 | PN533 ),
PNCMD( SetParameters, PN531 | PN532 | PN533 | RCS360 ),
PNCMD( SAMConfiguration, PN531 | PN532 ),
PNCMD( PowerDown, PN531 | PN532 ),
PNCMD( AlparCommandForTDA, PN533 | RCS360 ), // Has another usage on RC-S360...
// RF communication
PNCMD( RFConfiguration, PN531|PN532|PN533|RCS360 ),
PNCMD( RFRegulationTest, PN531|PN532|PN533 ),
PNCMD( RFConfiguration, PN531 | PN532 | PN533 | RCS360 ),
PNCMD( RFRegulationTest, PN531 | PN532 | PN533 ),
// Initiator
PNCMD( InJumpForDEP, PN531|PN532|PN533|RCS360 ),
PNCMD( InJumpForPSL, PN531|PN532|PN533 ),
PNCMD( InListPassiveTarget, PN531|PN532|PN533|RCS360 ),
PNCMD( InATR, PN531|PN532|PN533 ),
PNCMD( InPSL, PN531|PN532|PN533 ),
PNCMD( InDataExchange, PN531|PN532|PN533 ),
PNCMD( InCommunicateThru, PN531|PN532|PN533|RCS360 ),
PNCMD( InJumpForDEP, PN531 | PN532 | PN533 | RCS360 ),
PNCMD( InJumpForPSL, PN531 | PN532 | PN533 ),
PNCMD( InListPassiveTarget, PN531 | PN532 | PN533 | RCS360 ),
PNCMD( InATR, PN531 | PN532 | PN533 ),
PNCMD( InPSL, PN531 | PN532 | PN533 ),
PNCMD( InDataExchange, PN531 | PN532 | PN533 ),
PNCMD( InCommunicateThru, PN531 | PN532 | PN533 | RCS360 ),
PNCMD( InQuartetByteExchange, PN533 ),
PNCMD( InDeselect, PN531|PN532|PN533|RCS360 ),
PNCMD( InRelease, PN531|PN532|PN533|RCS360 ),
PNCMD( InSelect, PN531|PN532|PN533 ),
PNCMD( InDeselect, PN531 | PN532 | PN533 | RCS360 ),
PNCMD( InRelease, PN531 | PN532 | PN533 | RCS360 ),
PNCMD( InSelect, PN531 | PN532 | PN533 ),
PNCMD( InAutoPoll, PN532 ),
PNCMD( InActivateDeactivatePaypass, PN533 ),
// Target
PNCMD( TgInitAsTarget, PN531|PN532|PN533 ),
PNCMD( TgSetGeneralBytes, PN531|PN532|PN533 ),
PNCMD( TgGetData, PN531|PN532|PN533 ),
PNCMD( TgSetData, PN531|PN532|PN533 ),
PNCMD( TgInitAsTarget, PN531 | PN532 | PN533 ),
PNCMD( TgSetGeneralBytes, PN531 | PN532 | PN533 ),
PNCMD( TgGetData, PN531 | PN532 | PN533 ),
PNCMD( TgSetData, PN531 | PN532 | PN533 ),
PNCMD( TgSetDataSecure, PN533 ),
PNCMD( TgSetMetaData, PN531|PN532|PN533 ),
PNCMD( TgSetMetaData, PN531 | PN532 | PN533 ),
PNCMD( TgSetMetaDataSecure, PN533 ),
PNCMD( TgGetInitiatorCommand, PN531|PN532|PN533 ),
PNCMD( TgResponseToInitiator, PN531|PN532|PN533 ),
PNCMD( TgGetTargetStatus, PN531|PN532|PN533 ),
PNCMD( TgGetInitiatorCommand, PN531 | PN532 | PN533 ),
PNCMD( TgResponseToInitiator, PN531 | PN532 | PN533 ),
PNCMD( TgGetTargetStatus, PN531 | PN532 | PN533 ),
};
// SFR part
......
This diff is collapsed.
......@@ -222,8 +222,8 @@ acr122_pcsc_connstring_decode (const nfc_connstring connstring, struct acr122_pc
free (cs);
return 1;
}
strncpy (desc->pcsc_device_name, device_name, sizeof(desc->pcsc_device_name)-1);
desc->pcsc_device_name[sizeof(desc->pcsc_device_name)-1] = '\0';
strncpy (desc->pcsc_device_name, device_name, sizeof(desc->pcsc_device_name) - 1);
desc->pcsc_device_name[sizeof(desc->pcsc_device_name) - 1] = '\0';
free (cs);
return 2;
......@@ -288,9 +288,9 @@ acr122_pcsc_open (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), (void *) & (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), (void *) & (DRIVER_DATA (pnd)->ioCard.dwProtocol)) != SCARD_S_SUCCESS) {
// We can not connect to this device.
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "%s", "PCSC connect failed");
goto error;
......@@ -453,7 +453,7 @@ acr122_pcsc_firmware (nfc_device *pnd)
DWORD dwFwLen = sizeof (abtFw);
memset (abtFw, 0x00, sizeof (abtFw));
if (DRIVER_DATA (pnd)->ioCard.dwProtocol == SCARD_PROTOCOL_UNDEFINED) {
uiResult = SCardControl (DRIVER_DATA (pnd)->hCard, IOCTL_CCID_ESCAPE_SCARD_CTL_CODE, abtGetFw, sizeof (abtGetFw), (uint8_t *) abtFw, dwFwLen-1, &dwFwLen);
uiResult = SCardControl (DRIVER_DATA (pnd)->hCard, IOCTL_CCID_ESCAPE_SCARD_CTL_CODE, abtGetFw, sizeof (abtGetFw), (uint8_t *) abtFw, dwFwLen - 1, &dwFwLen);
} else {
uiResult = SCardTransmit (DRIVER_DATA (pnd)->hCard, &(DRIVER_DATA (pnd)->ioCard), abtGetFw, sizeof (abtGetFw), NULL, (uint8_t *) abtFw, &dwFwLen);
}
......
......@@ -512,7 +512,7 @@ acr122_build_frame_from_apdu (uint8_t **frame, const uint8_t *apdu, const size_t
0x00, // len
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // padding
};
if ((apdu_len+10) > ACR122_USB_BUFFER_LEN)
if ((apdu_len + 10) > ACR122_USB_BUFFER_LEN)
return NFC_EINVARG;
abtFrame[1] = apdu_len;
......@@ -533,7 +533,7 @@ acr122_build_frame_from_tama (uint8_t **frame, const uint8_t *tama, const size_t
0x00, // PN532 command length
0xd4, // PN532 direction
};
if ((tama_len+16) > ACR122_USB_BUFFER_LEN)
if ((tama_len + 16) > ACR122_USB_BUFFER_LEN)
return NFC_EINVARG;
abtFrame[1] = tama_len + 6;
......
......@@ -445,8 +445,8 @@ acr122s_connstring_decode (const nfc_connstring connstring, struct acr122s_descr
free (cs);
return 1;
}
strncpy (desc->port, port, sizeof(desc->port)-1);
desc->port[sizeof(desc->port)-1] = '\0';
strncpy (desc->port, port, sizeof(desc->port) - 1);
desc->port[sizeof(desc->port) - 1] = '\0';
const char *speed_s = strtok (NULL, ":");
if (!speed_s) {
......
......@@ -196,8 +196,8 @@ arygon_connstring_decode (const nfc_connstring connstring, struct arygon_descrip
free (cs);
return 1;
}
strncpy (desc->port, port, sizeof(desc->port)-1);
desc->port[sizeof(desc->port)-1] = '\0';
strncpy (desc->port, port, sizeof(desc->port) - 1);
desc->port[sizeof(desc->port) - 1] = '\0';
const char *speed_s = strtok (NULL, ":");
if (!speed_s) {
......@@ -378,7 +378,7 @@ arygon_tama_receive (nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen,
#ifndef WIN32
abort_p = &(DRIVER_DATA (pnd)->iAbortFds[1]);
#else
abort_p = (void*)&(DRIVER_DATA (pnd)->abort_flag);
abort_p = (void*) & (DRIVER_DATA (pnd)->abort_flag);
#endif
pnd->last_error = uart_receive (DRIVER_DATA (pnd)->port, abtRxBuf, 5, abort_p, timeout);
......
......@@ -174,8 +174,8 @@ pn532_connstring_decode (const nfc_connstring connstring, struct pn532_uart_desc
free (cs);
return 1;
}
strncpy (desc->port, port, sizeof(desc->port)-1);
desc->port[sizeof(desc->port)-1] = '\0';
strncpy (desc->port, port, sizeof(desc->port) - 1);
desc->port[sizeof(desc->port) - 1] = '\0';
const char *speed_s = strtok (NULL, ":");
if (!speed_s) {
......@@ -358,7 +358,7 @@ pn532_uart_receive (nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, i
#ifndef WIN32
abort_p = &(DRIVER_DATA (pnd)->iAbortFds[1]);
#else
abort_p = (void*)&(DRIVER_DATA (pnd)->abort_flag);
abort_p = (void*) & (DRIVER_DATA (pnd)->abort_flag);
#endif
pnd->last_error = uart_receive (DRIVER_DATA (pnd)->port, abtRxBuf, 5, abort_p, timeout);
......
......@@ -83,8 +83,8 @@ iso14443a_locate_historical_bytes (uint8_t *pbtAts, size_t szAts, size_t *pszTk)
offset++;
}
if (szAts > offset) {
*pszTk = (szAts-offset);
return (pbtAts+offset);
*pszTk = (szAts - offset);
return (pbtAts + offset);
}
}
*pszTk = 0;
......
......@@ -44,7 +44,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);
}
......
......@@ -84,11 +84,11 @@ 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)));
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)));
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"));
......@@ -96,7 +96,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; }
return (void *) thread_res;
......@@ -124,7 +124,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)
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)));
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"));
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;
......
This diff is collapsed.
......@@ -64,7 +64,7 @@ target_thread (void *arg)
// 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)));
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
......@@ -90,11 +90,11 @@ 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)));
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)));
szRx = (size_t) res;
const uint8_t abtAttRx[] = "Hello DEP target!";
......@@ -103,7 +103,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
......@@ -143,7 +143,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)
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)));
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"));
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
......
......@@ -274,11 +274,11 @@ static size_t
ndef_message_save (char *filename, struct nfcforum_tag4_ndef_data *tag_data)
{
FILE *F;
if (!(F= fopen (filename, "w")))
if (!(F = fopen (filename, "w")))
err (EXIT_FAILURE, "fopen (%s, w)", filename);
if (1 != fwrite (tag_data->ndef_file + 2, tag_data->ndef_file_len - 2, 1, F)) {
err (EXIT_FAILURE, "fwrite (%d)", (int) tag_data->ndef_file_len -2);
err (EXIT_FAILURE, "fwrite (%d)", (int) tag_data->ndef_file_len - 2);
}
fclose (F);
......
......@@ -241,7 +241,7 @@ main (int argc, const char *argv[])
if ((res = nfc_initiator_list_passive_targets(pnd, nm, ant, MAX_TARGET_COUNT)) >= 0) {
int n;
if (verbose || (res > 0)) {
printf("%d Jewel passive target(s) found%s\n", res, (res == 0)?".\n":":");
printf("%d Jewel passive target(s) found%s\n", res, (res == 0) ? ".\n" : ":");
}
for(n = 0; n < res; n++) {
print_nfc_jewel_info (ant[n].nti.nji, verbose);
......
......@@ -437,7 +437,7 @@ main (int argc, const char *argv[])
uint8_t *pbtUID;
FILE *pfKeys = NULL;
FILE *pfDump = NULL;
int unlock= 0;
int unlock = 0;
if (argc < 2) {
print_usage (argv[0]);
......@@ -452,8 +452,8 @@ main (int argc, const char *argv[])
}
atAction = ACTION_READ;
if (strcmp (command, "R") == 0)
unlock= 1;
bUseKeyA = tolower ((int) ((unsigned char) *(argv[2]))) == 'a';
unlock = 1;
bUseKeyA = tolower ((int) ((unsigned char) * (argv[2]))) == 'a';
bUseKeyFile = (argc > 4);
} else if (strcmp (command, "w") == 0 || strcmp (command, "W") == 0) {
if (argc < 4) {
......@@ -462,8 +462,8 @@ main (int argc, const char *argv[])
}
atAction = ACTION_WRITE;
if (strcmp (command, "W") == 0)
unlock= 1;
bUseKeyA = tolower ((int) ((unsigned char) *(argv[2]))) == 'a';
unlock = 1;
bUseKeyA = tolower ((int) ((unsigned char) * (argv[2]))) == 'a';
bUseKeyFile = (argc > 4);
}
......
......@@ -129,12 +129,12 @@ write_card (void)
uiSkippedPages = 2;
for (int page = 0x2; page <= 0xF; page++) {
if ((page==0x2) && (!write_lock)) {
if ((page == 0x2) && (!write_lock)) {
printf ("s");
uiSkippedPages++;
continue;
}
if ((page==0x3) && (!write_otp)) {
if ((page == 0x3) && (!write_otp)) {
printf ("s");
uiSkippedPages++;
continue;
......@@ -183,7 +183,7 @@ main (int argc, const char *argv[])
DBG ("\nChecking arguments and settings\n");
bReadAction = tolower ((int) ((unsigned char) *(argv[1])) == 'r');
bReadAction = tolower ((int) ((unsigned char) * (argv[1])) == 'r');
if (bReadAction) {
memset (&mtDump, 0x00, sizeof (mtDump));
......
......@@ -143,7 +143,7 @@ nfc_forum_tag_type3_check (nfc_device *dev, const nfc_target nt, const uint16_t
}
// const uint8_t res_block_count = res[12];
*data_len = res - res_overhead + 1; // +1 => block count is stored on 1 byte
memcpy (data, &rx[res_overhead+1], *data_len);
memcpy (data, &rx[res_overhead + 1], *data_len);
return *data_len;
}
......@@ -294,9 +294,9 @@ main(int argc, char *argv[])
const uint16_t block_count_to_check = (ndef_data_len / 16) + 1;
data_len = 0;
for (uint16_t b = 0; b < (block_count_to_check/block_max_per_check); b += block_max_per_check) {
for (uint16_t b = 0; b < (block_count_to_check / block_max_per_check); b += block_max_per_check) {
size_t size = sizeof(data) - data_len;
if(!nfc_forum_tag_type3_check (pnd, nt, 1+b, MIN(block_max_per_check, (block_count_to_check-(b*block_max_per_check))), data + data_len, &size)) {
if(!nfc_forum_tag_type3_check (pnd, nt, 1 + b, MIN(block_max_per_check, (block_count_to_check - (b * block_max_per_check))), data + data_len, &size)) {
nfc_perror (pnd, "nfc_forum_tag_type3_check");
error = EXIT_FAILURE;
goto error;
......
......@@ -123,7 +123,7 @@ static bool scan_hex_fd3 (uint8_t *pbtData, size_t *pszBytes, const char *pchPre
char pchScan[256];
int c;
// Look for our next sync marker
while ( (c=fgetc(fd3)) != '#') {
while ( (c = fgetc(fd3)) != '#') {
if (c == EOF) {
return EXIT_FAILURE;
}
......@@ -133,7 +133,7 @@ static bool scan_hex_fd3 (uint8_t *pbtData, size_t *pszBytes, const char *pchPre
if (fscanf (fd3, pchScan, &uiBytes) < 1) {
return EXIT_FAILURE;
}
*pszBytes=uiBytes;
*pszBytes = uiBytes;
if (*pszBytes > MAX_FRAME_LEN) {
return EXIT_FAILURE;
}
......@@ -141,7 +141,7 @@ static bool scan_hex_fd3 (uint8_t *pbtData, size_t *pszBytes, const char *pchPre
if (fscanf (fd3, "%02x", &uiData) < 1) {
return EXIT_FAILURE;
}
pbtData[szPos]=uiData;
pbtData[szPos] = uiData;
}
return EXIT_SUCCESS;
}
......@@ -322,7 +322,7 @@ main (int argc, char *argv[])
}
// We can only emulate a short UID, so fix length & ATQA bit:
ntEmulatedTarget.nti.nai.szUidLen = 4;
ntEmulatedTarget.nti.nai.abtAtqa[1] &= (0xFF-0x40);
ntEmulatedTarget.nti.nai.abtAtqa[1] &= (0xFF - 0x40);
// First byte of UID is always automatically replaced by 0x08 in this mode anyway
ntEmulatedTarget.nti.nai.abtUid[0] = 0x08;
// ATS is always automatically replaced by PN532, we've no control on it:
......
......@@ -93,7 +93,7 @@ struct card_atqa const_ca[] = {
},
{
0x0044, 0xffff, "P3SR008",
{-1}
{ -1}
}, // TODO we need SAK info
{
0x0004, 0xf0ff, "SmartMX with MIFARE 1K emulation",
......@@ -213,7 +213,7 @@ print_nfc_iso14443a_info (const nfc_iso14443a_info nai, bool verbose)
print_hex (nai.abtAtqa, 2);
if (verbose) {
printf("* UID size: ");
switch ((nai.abtAtqa[1] & 0xc0)>>6) {
switch ((nai.abtAtqa[1] & 0xc0) >> 6) {
case 0:
printf("single\n");
break;
......@@ -282,39 +282,39 @@ print_nfc_iso14443a_info (const nfc_iso14443a_info nai, bool verbose)
if (TA == 0) {
printf (" * PICC supports only 106 kbits/s in both directions\n");
}
if (TA & 1<<7) {
if (TA & 1 << 7) {
printf (" * Same bitrate in both directions mandatory\n");
}
if (TA & 1<<4) {
if (TA & 1 << 4) {
printf (" * PICC to PCD, DS=2, bitrate 212 kbits/s supported\n");
}
if (TA & 1<<5) {
if (TA & 1 << 5) {
printf (" * PICC to PCD, DS=4, bitrate 424 kbits/s supported\n");
}
if (TA & 1<<6) {
if (TA & 1 << 6) {
printf (" * PICC to PCD, DS=8, bitrate 847 kbits/s supported\n");
}
if (TA & 1<<0) {
if (TA & 1 << 0) {
printf (" * PCD to PICC, DR=2, bitrate 212 kbits/s supported\n");
}
if (TA & 1<<1) {
if (TA & 1 << 1) {
printf (" * PCD to PICC, DR=4, bitrate 424 kbits/s supported\n");
}
if (TA & 1<<2) {
if (TA & 1 << 2) {
printf (" * PCD to PICC, DR=8, bitrate 847 kbits/s supported\n");
}
if (TA & 1<<3) {
if (TA & 1 << 3) {
printf (" * ERROR unknown value\n");
}
}
if (nai.abtAts[0] & 0x20) { // TB(1) present
uint8_t TB= nai.abtAts[offset];
uint8_t TB = nai.abtAts[offset];
offset++;
printf ("* Frame Waiting Time: %.4g ms\n",256.0*16.0*(1<<((TB & 0xf0) >> 4))/13560.0);
printf ("* Frame Waiting Time: %.4g ms\n", 256.0 * 16.0 * (1 << ((TB & 0xf0) >> 4)) / 13560.0);
if ((TB & 0x0f) == 0) {
printf ("* No Start-up Frame Guard Time required\n");
} else {
printf ("* Start-up Frame Guard Time: %.4g ms\n",256.0*16.0*(1<<(TB & 0x0f))/13560.0);
printf ("* Start-up Frame Guard Time: %.4g ms\n", 256.0 * 16.0 * (1 << (TB & 0x0f)) / 13560.0);
}
}
if (nai.abtAts[0] & 0x40) { // TC(1) present
......@@ -473,11 +473,11 @@ print_nfc_iso14443a_info (const nfc_iso14443a_info nai, bool verbose)
uint8_t i, j;
bool found_possible_match = false;
atqa = (((uint16_t)nai.abtAtqa[0] & 0xff)<<8);
atqa = (((uint16_t)nai.abtAtqa[0] & 0xff) << 8);
atqa += (((uint16_t)nai.abtAtqa[1] & 0xff));
sak = ((uint8_t)nai.btSak & 0xff);
for (i = 0; i < sizeof(const_ca)/sizeof(const_ca[0]); i++) {
for (i = 0; i < sizeof(const_ca) / sizeof(const_ca[0]); i++) {
if ((atqa & const_ca[i].mask) == const_ca[i].atqa) {
for (j = 0; (j < sizeof(const_ca[i].saklist)) && (const_ca[i].saklist[j] >= 0); j++) {
int sakindex = const_ca[i].saklist[j];
......@@ -493,8 +493,8 @@ print_nfc_iso14443a_info (const nfc_iso14443a_info nai, bool verbose)
// but seen in the field:
printf("Other possible matches based on ATQA & SAK values:\n");