astyle --formatted --mode=c --indent=spaces=2 --indent-switches --indent-preprocessor --keep-one-line-blocks --max-instatement-indent=60 --brackets=linux --pad-oper

This commit is contained in:
Philippe Teuwen 2012-05-29 15:54:00 +00:00
parent 67522bae65
commit 562205cc14
23 changed files with 196 additions and 196 deletions

View file

@ -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

View file

@ -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);
}
}

View file

@ -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;

View file

@ -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++;
}

View file

@ -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

View file

@ -520,7 +520,7 @@ pn53x_decode_target_data (const uint8_t *pbtRawData, size_t szRawData, pn53x_typ
pnti->nci.btProdCode = *(pbtRawData++);
pnti->nci.btFabCode = *(pbtRawData++);
// Store UID MSB
memcpy (pnti->nci.abtUID+2, pbtRawData, 2);
memcpy (pnti->nci.abtUID + 2, pbtRawData, 2);
pbtRawData += 2;
break;
@ -748,7 +748,7 @@ pn53x_int_to_timeout (const int ms)
uint8_t res = 0;
if (ms) {
res = 0x10;
for (int i=3280; i>1; i/=2) {
for (int i = 3280; i > 1; i /= 2) {
if (ms > i)
break;
res--;
@ -1030,7 +1030,7 @@ pn53x_initiator_select_passive_target_ext (struct nfc_device *pnd,
pnd->bEasyFraming = false;
if (nm.nmt == NMT_ISO14443B2SR) {
// Some work to do before getting the UID...
uint8_t abtInitiate[]="\x06\x00";
uint8_t abtInitiate[] = "\x06\x00";
size_t szInitiateLen = 2;
uint8_t abtSelect[] = { 0x0e, 0x00 };
uint8_t abtRx[1];
@ -1045,9 +1045,9 @@ pn53x_initiator_select_passive_target_ext (struct nfc_device *pnd,
szTargetsData = (size_t)res;
} else if (nm.nmt == NMT_ISO14443B2CT) {
// Some work to do before getting the UID...
const uint8_t abtReqt[]= { 0x10 };
const uint8_t abtReqt[] = { 0x10 };
// Getting product code / fab code & store it in output buffer after the serial nr we'll obtain later
if ((res = pn53x_initiator_transceive_bytes (pnd, abtReqt, sizeof(abtReqt), abtTargetsData+2, sizeof(abtTargetsData)-2, timeout)) < 0) {
if ((res = pn53x_initiator_transceive_bytes (pnd, abtReqt, sizeof(abtReqt), abtTargetsData + 2, sizeof(abtTargetsData) - 2, timeout)) < 0) {
return res;
}
szTargetsData = (size_t)res;
@ -1058,8 +1058,8 @@ pn53x_initiator_select_passive_target_ext (struct nfc_device *pnd,
if (nm.nmt == NMT_ISO14443B2CT) {
if (szTargetsData != 2)
return NFC_ECHIP; // FIXME: It should not return a NFC_ECHIP here!
uint8_t abtRead[]= { 0xC4 }; // Reading UID_MSB (Read address 4)
if ((res = pn53x_initiator_transceive_bytes (pnd, abtRead, sizeof(abtRead), abtTargetsData+4, sizeof(abtTargetsData)-4, timeout) < 0)) {
uint8_t abtRead[] = { 0xC4 }; // Reading UID_MSB (Read address 4)
if ((res = pn53x_initiator_transceive_bytes (pnd, abtRead, sizeof(abtRead), abtTargetsData + 4, sizeof(abtTargetsData) - 4, timeout) < 0)) {
return res;
}
szTargetsData = 6; // u16 UID_LSB, u8 prod code, u8 fab code, u16 UID_MSB
@ -1174,7 +1174,7 @@ pn53x_initiator_poll_target (struct nfc_device *pnd,
}
}
}
} while (uiPollNr==0xff); // uiPollNr==0xff means infinite polling
} while (uiPollNr == 0xff); // uiPollNr==0xff means infinite polling
// We reach this point when each listing give no result, we simply have to return 0
return 0;
}
@ -1344,7 +1344,7 @@ static void __pn53x_init_timer(struct nfc_device *pnd, const uint32_t max_cycles
// prescaler = 2 => precision: ~369ns timer saturates at ~25ms
// prescaler = 10 => precision: ~1.5us timer saturates at ~100ms
if (max_cycles > 0xFFFF) {
CHIP_DATA (pnd)->timer_prescaler = ((max_cycles/0xFFFF)-1)/2;
CHIP_DATA (pnd)->timer_prescaler = ((max_cycles / 0xFFFF) - 1) / 2;
} else {
CHIP_DATA (pnd)->timer_prescaler = 0;
}
@ -1381,7 +1381,7 @@ static uint32_t __pn53x_get_timer(struct nfc_device *pnd, const uint8_t last_cmd
return false;
}
counter_hi = abtRes[off];
counter_lo = abtRes[off+1];
counter_lo = abtRes[off + 1];
counter = counter_hi;
counter = (counter << 8) + counter_lo;
if (counter == 0) {
@ -1404,7 +1404,7 @@ static uint32_t __pn53x_get_timer(struct nfc_device *pnd, const uint8_t last_cmd
((last_cmd_byte >> 5) & 1) ^ ((last_cmd_byte >> 4) & 1) ^
((last_cmd_byte >> 3) & 1) ^ ((last_cmd_byte >> 2) & 1) ^
((last_cmd_byte >> 1) & 1) ^ (last_cmd_byte & 1);
parity = parity ? 0:1;
parity = parity ? 0 : 1;
// When sent ...YY (cmd ends with logical 1, so when last parity bit is 1):
if (parity) {
// it finishes 64us sooner than a ...ZY signal
@ -1478,7 +1478,7 @@ pn53x_initiator_transceive_bits_timed (struct nfc_device *pnd, const uint8_t *pb
// our PN53x timer saturates after 4.8ms so this function shouldn't be used for
// responses coming very late anyway.
// Ideally we should implement a real timer here too but looping a few times is good enough.
for (i = 0; i < (3 *(CHIP_DATA (pnd)->timer_prescaler * 2 + 1)); i++) {
for (i = 0; i < (3 * (CHIP_DATA (pnd)->timer_prescaler * 2 + 1)); i++) {
pn53x_read_register (pnd, PN53X_REG_CIU_FIFOLevel, &sz);
if (sz > 0)
break;
@ -1504,10 +1504,10 @@ pn53x_initiator_transceive_bits_timed (struct nfc_device *pnd, const uint8_t *pb
return res;
}
for (i = 0; i < sz; i++) {
pbtRx[i+szRxBits] = abtRes[i+off];
pbtRx[i + szRxBits] = abtRes[i + off];
}
szRxBits += (size_t) (sz & SYMBOL_FIFO_LEVEL);
sz = abtRes[sz+off];
sz = abtRes[sz + off];
if (sz == 0)
break;
}
@ -1573,7 +1573,7 @@ pn53x_initiator_transceive_bytes_timed (struct nfc_device *pnd, const uint8_t *p
// our PN53x timer saturates after 4.8ms so this function shouldn't be used for
// responses coming very late anyway.
// Ideally we should implement a real timer here too but looping a few times is good enough.
for (i = 0; i < (3 *(CHIP_DATA (pnd)->timer_prescaler * 2 + 1)); i++) {
for (i = 0; i < (3 * (CHIP_DATA (pnd)->timer_prescaler * 2 + 1)); i++) {
pn53x_read_register (pnd, PN53X_REG_CIU_FIFOLevel, &sz);
if (sz > 0)
break;
@ -1599,10 +1599,10 @@ pn53x_initiator_transceive_bytes_timed (struct nfc_device *pnd, const uint8_t *p
return res;
}
for (i = 0; i < sz; i++) {
pbtRx[i+szRx] = abtRes[i+off];
pbtRx[i + szRx] = abtRes[i + off];
}
szRx += (size_t) (sz & SYMBOL_FIFO_LEVEL);
sz = abtRes[sz+off];
sz = abtRes[sz + off];
if (sz == 0)
break;
}
@ -1611,13 +1611,13 @@ pn53x_initiator_transceive_bytes_timed (struct nfc_device *pnd, const uint8_t *p
if (pnd->bCrc) {
// We've to compute CRC ourselves to know last byte actually sent
uint8_t *pbtTxRaw;
pbtTxRaw = (uint8_t *) malloc(szTx+2);
pbtTxRaw = (uint8_t *) malloc(szTx + 2);
memcpy (pbtTxRaw, pbtTx, szTx);
iso14443a_crc_append (pbtTxRaw, szTx);
*cycles = __pn53x_get_timer (pnd, pbtTxRaw[szTx +1]);
*cycles = __pn53x_get_timer (pnd, pbtTxRaw[szTx + 1]);
free(pbtTxRaw);
} else {
*cycles = __pn53x_get_timer (pnd, pbtTx[szTx -1]);
*cycles = __pn53x_get_timer (pnd, pbtTx[szTx - 1]);
}
return szRx;
}
@ -1638,7 +1638,7 @@ pn53x_initiator_target_is_present (struct nfc_device *pnd, const nfc_target nt)
if ((res = pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), abtRx, sizeof (abtRx), -1)) < 0)
return res;
if (res==1) {
if (res == 1) {
return NFC_SUCCESS;
}
return NFC_ETGRELEASED;
@ -1734,9 +1734,9 @@ pn53x_target_init (struct nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, cons
// Set NFCID2t
memcpy(abtFeliCaParams, pnt->nti.nfi.abtId, 8);
// Set PAD
memcpy(abtFeliCaParams+8, pnt->nti.nfi.abtPad, 8);
memcpy(abtFeliCaParams + 8, pnt->nti.nfi.abtPad, 8);
// Set SystemCode
memcpy(abtFeliCaParams+16, pnt->nti.nfi.abtSysCode, 2);
memcpy(abtFeliCaParams + 16, pnt->nti.nfi.abtSysCode, 2);
pbtFeliCaParams = abtFeliCaParams;
break;
@ -2356,7 +2356,7 @@ pn53x_InAutoPoll (struct nfc_device *pnd,
// InAutoPoll frame looks like this { 0xd4, 0x60, 0x0f, 0x01, 0x00 } => { direction, command, pollnr, period, types... }
size_t szTxInAutoPoll = 3 + szTargetTypes;
uint8_t abtCmd[3+15] = { InAutoPoll, btPollNr, btPeriod };
uint8_t abtCmd[3 + 15] = { InAutoPoll, btPollNr, btPeriod };
for (size_t n = 0; n < szTargetTypes; n++) {
abtCmd[3 + n] = ppttTargetTypes[n];
}
@ -2523,34 +2523,34 @@ pn53x_TgInitAsTarget (struct nfc_device *pnd, pn53x_target_mode ptm,
// MIFARE part
if (pbtMifareParams) {
memcpy (abtCmd+2, pbtMifareParams, 6);
memcpy (abtCmd + 2, pbtMifareParams, 6);
}
// FeliCa part
if (pbtFeliCaParams) {
memcpy (abtCmd+8, pbtFeliCaParams, 18);
memcpy (abtCmd + 8, pbtFeliCaParams, 18);
}
// DEP part
if (pbtNFCID3t) {
memcpy(abtCmd+26, pbtNFCID3t, 10);
memcpy(abtCmd + 26, pbtNFCID3t, 10);
}
// General Bytes (ISO/IEC 18092)
if ((CHIP_DATA(pnd)->type == PN531) || (CHIP_DATA(pnd)->type == RCS360)) {
if (szGBt) {
memcpy (abtCmd+36, pbtGBt, szGBt);
memcpy (abtCmd + 36, pbtGBt, szGBt);
szOptionalBytes = szGBt;
}
} else {
abtCmd[36] = (uint8_t)(szGBt);
if (szGBt) {
memcpy (abtCmd+37, pbtGBt, szGBt);
memcpy (abtCmd + 37, pbtGBt, szGBt);
}
szOptionalBytes = szGBt + 1;
}
// Historical bytes (ISO/IEC 14443-4)
if ((CHIP_DATA(pnd)->type != PN531) && (CHIP_DATA(pnd)->type != RCS360)) { // PN531 does not handle Historical Bytes
abtCmd[36+szOptionalBytes] = (uint8_t)(szTkt);
abtCmd[36 + szOptionalBytes] = (uint8_t)(szTkt);
if (szTkt) {
memcpy (abtCmd+37+szOptionalBytes, pbtTkt, szTkt);
memcpy (abtCmd + 37 + szOptionalBytes, pbtTkt, szTkt);
}
szOptionalBytes += szTkt + 1;
}
@ -2903,8 +2903,8 @@ pn53x_get_information_about (nfc_device *pnd, char *buf, size_t buflen)
return res;
}
for (int i=0; nmt[i]; i++) {
if ((res = snprintf (buf, buflen, "%s%s (", (i==0)?"":", ", str_nfc_modulation_type (nmt[i]))) < 0) {
for (int i = 0; nmt[i]; i++) {
if ((res = snprintf (buf, buflen, "%s%s (", (i == 0) ? "" : ", ", str_nfc_modulation_type (nmt[i]))) < 0) {
return NFC_ESOFT;
}
buf += res;
@ -2917,8 +2917,8 @@ pn53x_get_information_about (nfc_device *pnd, char *buf, size_t buflen)
return res;
}
for (int j=0; nbr[j]; j++) {
if ((res = snprintf (buf, buflen, "%s%s", (j==0)?"":", ", str_nfc_baud_rate (nbr[j]))) < 0) {
for (int j = 0; nbr[j]; j++) {
if ((res = snprintf (buf, buflen, "%s%s", (j == 0) ? "" : ", ", str_nfc_baud_rate (nbr[j]))) < 0) {
return NFC_ESOFT;
}
buf += res;
@ -2957,8 +2957,8 @@ pn53x_get_information_about (nfc_device *pnd, char *buf, size_t buflen)
return res;
}
for (int i=0; nmt[i]; i++) {
if ((res = snprintf (buf, buflen, "%s%s (", (i==0)?"":", ", str_nfc_modulation_type (nmt[i]))) < 0) {
for (int i = 0; nmt[i]; i++) {
if ((res = snprintf (buf, buflen, "%s%s (", (i == 0) ? "" : ", ", str_nfc_modulation_type (nmt[i]))) < 0) {
return NFC_ESOFT;
}
buf += res;
@ -2971,8 +2971,8 @@ pn53x_get_information_about (nfc_device *pnd, char *buf, size_t buflen)
return res;
}
for (int j=0; nbr[j]; j++) {
if ((res = snprintf (buf, buflen, "%s%s", (j==0)?"":", ", str_nfc_baud_rate (nbr[j]))) < 0) {
for (int j = 0; nbr[j]; j++) {
if ((res = snprintf (buf, buflen, "%s%s", (j == 0) ? "" : ", ", str_nfc_baud_rate (nbr[j]))) < 0) {
return NFC_ESOFT;
}
buf += res;

View file

@ -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);
}

View file

@ -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;

View file

@ -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) {

View file

@ -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);

View file

@ -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);

View file

@ -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;

View file

@ -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);
}

View file

@ -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;

View file

@ -83,12 +83,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)));
szRx = (size_t) res;
const uint8_t abtAttRx[] = "Hello DEP target!";
@ -97,43 +97,43 @@ 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)));
szRx = (size_t) res;
cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data"));
if (res <= 0) { thread_res = -1; return (void*) thread_res; }
res = nfc_target_send_bytes (device, abtTx, sizeof(abtTx), 500);
cut_assert_operator_int (res, >, 0, cut_message ("Can't send bytes to initiator: %s", nfc_strerror (device)));
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)));
szRx = (size_t) res;
cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data"));
if (res <= 0) { thread_res = -1; return (void*) thread_res; }
res = nfc_target_send_bytes (device, abtTx, sizeof(abtTx), 500);
cut_assert_operator_int (res, >, 0, cut_message ("Can't send bytes to initiator: %s", nfc_strerror (device)));
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)));
szRx = (size_t) res;
cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data"));
if (res <= 0) { thread_res = -1; return (void*) thread_res; }
res = nfc_target_send_bytes (device, abtTx, sizeof(abtTx), 500);
cut_assert_operator_int (res, >, 0, cut_message ("Can't send bytes to initiator: %s", nfc_strerror (device)));
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;
@ -161,7 +161,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"));
@ -173,20 +173,20 @@ 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; }
// 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"));
@ -196,19 +196,19 @@ initiator_thread (void *arg)
szRx = sizeof (abtRx);
res = nfc_initiator_transceive_bytes (device, abtTx, sizeof (abtTx), abtRx, &szRx, 1000);
cut_assert_operator_int (res, >=, 0, cut_message ("Can't transceive bytes to target: %s", nfc_strerror (device)));
cut_assert_operator_int (res, >= , 0, cut_message ("Can't transceive bytes to target: %s", nfc_strerror (device)));
cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data"));
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"));
@ -218,19 +218,19 @@ initiator_thread (void *arg)
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)));
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; }
// 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"));
@ -240,13 +240,13 @@ initiator_thread (void *arg)
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)));
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;

View file

@ -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

View file

@ -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);

View file

@ -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);

View file

@ -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);
}

View file

@ -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));

View file

@ -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;

View file

@ -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:

View file

@ -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");
uint32_t atqasak = 0;
atqasak += (((uint32_t)nai.abtAtqa[0] & 0xff)<<16);
atqasak += (((uint32_t)nai.abtAtqa[1] & 0xff)<<8);
atqasak += (((uint32_t)nai.abtAtqa[0] & 0xff) << 16);
atqasak += (((uint32_t)nai.abtAtqa[1] & 0xff) << 8);
atqasak += ((uint32_t)nai.btSak & 0xff);
switch (atqasak) {
case 0x000488:
@ -581,28 +581,28 @@ print_nfc_iso14443b_info (const nfc_iso14443b_info nbi, bool verbose)
if (nbi.abtProtocolInfo[0] == 0) {
printf (" * PICC supports only 106 kbits/s in both directions\n");
}
if (nbi.abtProtocolInfo[0] & 1<<7) {
if (nbi.abtProtocolInfo[0] & 1 << 7) {
printf (" * Same bitrate in both directions mandatory\n");
}
if (nbi.abtProtocolInfo[0] & 1<<4) {
if (nbi.abtProtocolInfo[0] & 1 << 4) {
printf (" * PICC to PCD, 1etu=64/fc, bitrate 212 kbits/s supported\n");
}
if (nbi.abtProtocolInfo[0] & 1<<5) {
if (nbi.abtProtocolInfo[0] & 1 << 5) {
printf (" * PICC to PCD, 1etu=32/fc, bitrate 424 kbits/s supported\n");
}
if (nbi.abtProtocolInfo[0] & 1<<6) {
if (nbi.abtProtocolInfo[0] & 1 << 6) {
printf (" * PICC to PCD, 1etu=16/fc, bitrate 847 kbits/s supported\n");
}
if (nbi.abtProtocolInfo[0] & 1<<0) {
if (nbi.abtProtocolInfo[0] & 1 << 0) {
printf (" * PCD to PICC, 1etu=64/fc, bitrate 212 kbits/s supported\n");
}
if (nbi.abtProtocolInfo[0] & 1<<1) {
if (nbi.abtProtocolInfo[0] & 1 << 1) {
printf (" * PCD to PICC, 1etu=32/fc, bitrate 424 kbits/s supported\n");
}
if (nbi.abtProtocolInfo[0] & 1<<2) {
if (nbi.abtProtocolInfo[0] & 1 << 2) {
printf (" * PCD to PICC, 1etu=16/fc, bitrate 847 kbits/s supported\n");
}
if (nbi.abtProtocolInfo[0] & 1<<3) {
if (nbi.abtProtocolInfo[0] & 1 << 3) {
printf (" * ERROR unknown value\n");
}
if( (nbi.abtProtocolInfo[1] & 0xf0) <= 0x80 ) {
@ -611,8 +611,8 @@ print_nfc_iso14443b_info (const nfc_iso14443b_info nbi, bool verbose)
if((nbi.abtProtocolInfo[1] & 0x0f) == PI_ISO14443_4_SUPPORTED) {
printf ("* Protocol types supported: ISO/IEC 14443-4\n");
}
printf ("* Frame Waiting Time: %.4g ms\n",256.0*16.0*(1<<((nbi.abtProtocolInfo[2] & 0xf0) >> 4))/13560.0);
if((nbi.abtProtocolInfo[2] & (PI_NAD_SUPPORTED|PI_CID_SUPPORTED)) != 0) {
printf ("* Frame Waiting Time: %.4g ms\n", 256.0 * 16.0 * (1 << ((nbi.abtProtocolInfo[2] & 0xf0) >> 4)) / 13560.0);
if((nbi.abtProtocolInfo[2] & (PI_NAD_SUPPORTED | PI_CID_SUPPORTED)) != 0) {
printf ("* Frame options supported: ");
if ((nbi.abtProtocolInfo[2] & PI_NAD_SUPPORTED) != 0) printf ("NAD ");
if ((nbi.abtProtocolInfo[2] & PI_CID_SUPPORTED) != 0) printf ("CID ");
@ -627,7 +627,7 @@ print_nfc_iso14443bi_info (const nfc_iso14443bi_info nii, bool verbose)
printf (" DIV: ");
print_hex (nii.abtDIV, 4);
if (verbose) {
int version = (nii.btVerLog & 0x1e)>>1;
int version = (nii.btVerLog & 0x1e) >> 1;
printf (" Software Version: ");
if (version == 15) {
printf ("Undefined\n");
@ -685,7 +685,7 @@ print_nfc_dep_info (const nfc_dep_info ndi, bool verbose)
void
print_nfc_target (const nfc_target nt, bool verbose)
{
printf ("%s (%s%s) target:\n", str_nfc_modulation_type(nt.nm.nmt), str_nfc_baud_rate(nt.nm.nbr), (nt.nm.nmt!=NMT_DEP)?"":(nt.nti.ndi.ndm == NDM_ACTIVE)? "active mode" : "passive mode");
printf ("%s (%s%s) target:\n", str_nfc_modulation_type(nt.nm.nmt), str_nfc_baud_rate(nt.nm.nbr), (nt.nm.nmt != NMT_DEP) ? "" : (nt.nti.ndi.ndm == NDM_ACTIVE) ? "active mode" : "passive mode");
switch(nt.nm.nmt) {
case NMT_ISO14443A:
print_nfc_iso14443a_info (nt.nti.nai, verbose);