Skip to content

Commit 4525cd1

Browse files
committed
make style
1 parent f52d04e commit 4525cd1

File tree

9 files changed

+490
-505
lines changed

9 files changed

+490
-505
lines changed

libnfc/chips/pn53x.c

+73-73
Original file line numberDiff line numberDiff line change
@@ -580,8 +580,8 @@ pn53x_decode_target_data(const uint8_t *pbtRawData, size_t szRawData, pn53x_type
580580

581581
case NMT_ISO14443BICLASS:
582582
// Store the UID
583-
for(uint8_t i= 0 ; i < 8 ; ++i)
584-
pnti->nhi.abtUID[7 - i]= pbtRawData[i];
583+
for (uint8_t i = 0 ; i < 8 ; ++i)
584+
pnti->nhi.abtUID[7 - i] = pbtRawData[i];
585585
break;
586586

587587
case NMT_ISO14443B2CT:
@@ -1060,51 +1060,51 @@ pn53x_initiator_init(struct nfc_device *pnd)
10601060
// iclass requires special modulation settings
10611061
void pn53x_initiator_init_iclass_modulation(struct nfc_device *pnd)
10621062
{
1063-
// send a bunch of low level commands reverse engineered from a working iClass reader
1064-
// original device was using a PN512
1065-
//
1066-
// // TxModeReg - Defines the data rate and framing during transmission.
1067-
//// set bit 4 for target mode? - RxWaitRF Set to logic 1, the counter for RxWait starts only if an external RF field is detected in Target mode for NFCIP-1 or in Card Communication mode
1068-
//pn512_write_register(0x12, "\x03", 1, false);
1069-
pn53x_WriteRegister(pnd, PN53X_REG_CIU_TxMode, 0x03);
1070-
//
1071-
// // RxModeReg - Defines the data rate and framing during reception.
1072-
//pn512_write_register(0x13, "\x03", 1, false);
1073-
// addy changed to set bit 3 - RxNoErr (put data in fifo before flagging read end)
1074-
//pn512_write_register(0x13, "\x0B", 1, false);
1075-
pn53x_WriteRegister(pnd, PN53X_REG_CIU_RxMode, 0x0B);
1076-
1077-
// ManualRCVReg - Allows manual fine tuning of the internal receiver.
1078-
//pn512_write_register(0x1d, "\x10", 1, false);
1079-
pn53x_WriteRegister(pnd, PN53X_REG_CIU_ManualRCV, 0x10);
1080-
1081-
// RFCfgReg - Configures the receiver gain and RF level detector sensitivity.
1082-
//pn512_write_register(0x26, "\x70", 1, false);
1083-
pn53x_WriteRegister(pnd, PN53X_REG_CIU_RFCfg, 0x70);
1084-
1085-
// GsNOffReg - Selects the conductance for the N-driver of the antenna driver pins TX1 and TX2 when the driver is switched off.
1086-
//pn512_write_register(0x23, "\x88", 1, false);
1087-
pn53x_WriteRegister(pnd, PN53X_REG_CIU_GsNOFF, 0x88);
1088-
1089-
// GsNOnReg - Selects the conductance for the N-driver of the antenna driver pins TX1 and TX2 when the driver is switched on.
1090-
//pn512_write_register(0x27, "\xf8", 1, false);
1091-
pn53x_WriteRegister(pnd, PN53X_REG_CIU_GsNOn, 0xf8);
1092-
1093-
// CWGsPReg - Defines the conductance of the P-driver during times of no modulation.
1094-
//pn512_write_register(0x28, "\x3f", 1, false);
1095-
pn53x_WriteRegister(pnd, PN53X_REG_CIU_CWGsP, 0x3f);
1096-
1097-
// ModGsPReg - Defines the driver P-output conductance during modulation.
1098-
//pn512_write_register(0x29, "\x10", 1, false);
1099-
pn53x_WriteRegister(pnd, PN53X_REG_CIU_ModGsP, 0x10);
1100-
1101-
// TReloadReg (MSB) - Describes the MSB of the 16-bit long timer reload value.
1102-
//pn512_write_register(0x2c, "\x69", 1, false);
1103-
pn53x_WriteRegister(pnd, PN53X_REG_CIU_TReloadVal_hi, 0x69);
1104-
1105-
// TReloadReg (LSB) - Describes the LSB of the 16-bit long timer reload value.
1106-
//pn512_write_register(0x2d, "\xf0", 1, false);
1107-
pn53x_WriteRegister(pnd, PN53X_REG_CIU_TReloadVal_lo, 0xf0);
1063+
// send a bunch of low level commands reverse engineered from a working iClass reader
1064+
// original device was using a PN512
1065+
//
1066+
// // TxModeReg - Defines the data rate and framing during transmission.
1067+
//// set bit 4 for target mode? - RxWaitRF Set to logic 1, the counter for RxWait starts only if an external RF field is detected in Target mode for NFCIP-1 or in Card Communication mode
1068+
//pn512_write_register(0x12, "\x03", 1, false);
1069+
pn53x_WriteRegister(pnd, PN53X_REG_CIU_TxMode, 0x03);
1070+
//
1071+
// // RxModeReg - Defines the data rate and framing during reception.
1072+
//pn512_write_register(0x13, "\x03", 1, false);
1073+
// addy changed to set bit 3 - RxNoErr (put data in fifo before flagging read end)
1074+
//pn512_write_register(0x13, "\x0B", 1, false);
1075+
pn53x_WriteRegister(pnd, PN53X_REG_CIU_RxMode, 0x0B);
1076+
1077+
// ManualRCVReg - Allows manual fine tuning of the internal receiver.
1078+
//pn512_write_register(0x1d, "\x10", 1, false);
1079+
pn53x_WriteRegister(pnd, PN53X_REG_CIU_ManualRCV, 0x10);
1080+
1081+
// RFCfgReg - Configures the receiver gain and RF level detector sensitivity.
1082+
//pn512_write_register(0x26, "\x70", 1, false);
1083+
pn53x_WriteRegister(pnd, PN53X_REG_CIU_RFCfg, 0x70);
1084+
1085+
// GsNOffReg - Selects the conductance for the N-driver of the antenna driver pins TX1 and TX2 when the driver is switched off.
1086+
//pn512_write_register(0x23, "\x88", 1, false);
1087+
pn53x_WriteRegister(pnd, PN53X_REG_CIU_GsNOFF, 0x88);
1088+
1089+
// GsNOnReg - Selects the conductance for the N-driver of the antenna driver pins TX1 and TX2 when the driver is switched on.
1090+
//pn512_write_register(0x27, "\xf8", 1, false);
1091+
pn53x_WriteRegister(pnd, PN53X_REG_CIU_GsNOn, 0xf8);
1092+
1093+
// CWGsPReg - Defines the conductance of the P-driver during times of no modulation.
1094+
//pn512_write_register(0x28, "\x3f", 1, false);
1095+
pn53x_WriteRegister(pnd, PN53X_REG_CIU_CWGsP, 0x3f);
1096+
1097+
// ModGsPReg - Defines the driver P-output conductance during modulation.
1098+
//pn512_write_register(0x29, "\x10", 1, false);
1099+
pn53x_WriteRegister(pnd, PN53X_REG_CIU_ModGsP, 0x10);
1100+
1101+
// TReloadReg (MSB) - Describes the MSB of the 16-bit long timer reload value.
1102+
//pn512_write_register(0x2c, "\x69", 1, false);
1103+
pn53x_WriteRegister(pnd, PN53X_REG_CIU_TReloadVal_hi, 0x69);
1104+
1105+
// TReloadReg (LSB) - Describes the LSB of the 16-bit long timer reload value.
1106+
//pn512_write_register(0x2d, "\xf0", 1, false);
1107+
pn53x_WriteRegister(pnd, PN53X_REG_CIU_TReloadVal_lo, 0xf0);
11081108
}
11091109

11101110
int
@@ -1202,10 +1202,10 @@ pn53x_initiator_select_passive_target_ext(struct nfc_device *pnd,
12021202
}
12031203
szTargetsData = 6; // u16 UID_LSB, u8 prod code, u8 fab code, u16 UID_MSB
12041204
} else if (nm.nmt == NMT_ISO14443BICLASS) {
1205-
pn53x_initiator_init_iclass_modulation(pnd);
1206-
//
1205+
pn53x_initiator_init_iclass_modulation(pnd);
1206+
//
12071207
// Some work to do before getting the UID...
1208-
// send ICLASS_ACTIVATE_ALL command - will get timeout as we don't expect response
1208+
// send ICLASS_ACTIVATE_ALL command - will get timeout as we don't expect response
12091209
uint8_t abtReqt[] = { 0x0a }; // iClass ACTIVATE_ALL
12101210
uint8_t abtAnticol[11];
12111211
if ((res = pn53x_initiator_transceive_bytes(pnd, abtReqt, sizeof(abtReqt), NULL, 0, timeout)) < 0) {
@@ -1214,35 +1214,35 @@ pn53x_initiator_select_passive_target_ext(struct nfc_device *pnd,
12141214
// continue;
12151215
//} else
12161216
// return res;
1217-
}
1218-
// do select - returned anticol contains 'handle' for tag if present
1219-
abtReqt[0]= 0x0c; // iClass SELECT
1220-
abtAnticol[0]= 0x81; // iClass ANTICOL
1217+
}
1218+
// do select - returned anticol contains 'handle' for tag if present
1219+
abtReqt[0] = 0x0c; // iClass SELECT
1220+
abtAnticol[0] = 0x81; // iClass ANTICOL
12211221
if ((res = pn53x_initiator_transceive_bytes(pnd, abtReqt, sizeof(abtReqt), &abtAnticol[1], sizeof(abtAnticol) - 1, timeout)) < 0) {
12221222
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "timeout on iClass anticol");
12231223
return res;
1224-
}
1225-
// write back anticol handle to get UID
1224+
}
1225+
// write back anticol handle to get UID
12261226
if ((res = pn53x_initiator_transceive_bytes(pnd, abtAnticol, 9, abtTargetsData, 10, timeout)) < 0) {
12271227
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "timeout on iClass get UID");
12281228
return res;
1229-
}
1229+
}
12301230
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "iClass raw UID: %02x %02x %02x %02x %02x %02x %02x %02x", abtTargetsData[0], abtTargetsData[1], abtTargetsData[2], abtTargetsData[3], abtTargetsData[4], abtTargetsData[5], abtTargetsData[6], abtTargetsData[7]);
1231-
szTargetsData = 8;
1232-
nttmp.nm = nm;
1233-
if ((res = pn53x_decode_target_data(abtTargetsData, szTargetsData, CHIP_DATA(pnd)->type, nm.nmt, &(nttmp.nti))) < 0) {
1234-
return res;
1235-
}
1236-
} else {
1237-
1238-
if ((res = pn53x_initiator_transceive_bytes(pnd, pbtInitData, szInitData, abtTargetsData, sizeof(abtTargetsData), timeout)) < 0) {
1239-
if ((res == NFC_ERFTRANS) && (CHIP_DATA(pnd)->last_status_byte == 0x01)) { // Chip timeout
1240-
continue;
1241-
} else
1231+
szTargetsData = 8;
1232+
nttmp.nm = nm;
1233+
if ((res = pn53x_decode_target_data(abtTargetsData, szTargetsData, CHIP_DATA(pnd)->type, nm.nmt, &(nttmp.nti))) < 0) {
12421234
return res;
1235+
}
1236+
} else {
1237+
1238+
if ((res = pn53x_initiator_transceive_bytes(pnd, pbtInitData, szInitData, abtTargetsData, sizeof(abtTargetsData), timeout)) < 0) {
1239+
if ((res == NFC_ERFTRANS) && (CHIP_DATA(pnd)->last_status_byte == 0x01)) { // Chip timeout
1240+
continue;
1241+
} else
1242+
return res;
1243+
}
1244+
szTargetsData = (size_t)res;
12431245
}
1244-
szTargetsData = (size_t)res;
1245-
}
12461246

12471247
nttmp.nm = nm;
12481248
if ((res = pn53x_decode_target_data(abtTargetsData, szTargetsData, CHIP_DATA(pnd)->type, nm.nmt, &(nttmp.nti))) < 0) {
@@ -2249,7 +2249,7 @@ static int pn53x_ISO14443B_SR_is_present(struct nfc_device *pnd)
22492249

22502250
static int pn53x_ISO14443B_ICLASS_is_present(struct nfc_device *pnd)
22512251
{
2252-
int timeout= 300;
2252+
int timeout = 300;
22532253
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "target_is_present(): Ping B iClass");
22542254
pn53x_initiator_init_iclass_modulation(pnd);
22552255
//
@@ -2261,8 +2261,8 @@ static int pn53x_ISO14443B_ICLASS_is_present(struct nfc_device *pnd)
22612261
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "got expected timeout on iClass activate all");
22622262
}
22632263
// do select - returned anticol contains 'handle' for tag if present
2264-
abtReqt[0]= 0x0c; // iClass SELECT
2265-
abtAnticol[0]= 0x81; // iClass ANTICOL
2264+
abtReqt[0] = 0x0c; // iClass SELECT
2265+
abtAnticol[0] = 0x81; // iClass ANTICOL
22662266
if (pn53x_initiator_transceive_bytes(pnd, abtReqt, sizeof(abtReqt), &abtAnticol[1], sizeof(abtAnticol) - 1, timeout) < 0) {
22672267
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "timeout on iClass anticol");
22682268
return NFC_ETGRELEASED;;

libnfc/drivers/acr122_usb.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ acr122_usb_scan(const nfc_context *context, nfc_connstring connstrings[], const
331331
// acr122_usb_get_usb_device_name (dev, udev, pnddDevices[device_found].acDevice, sizeof (pnddDevices[device_found].acDevice));
332332
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "device found: Bus %s Device %s Name %s", bus->dirname, dev->filename, acr122_usb_supported_devices[n].name);
333333
usb_close(udev);
334-
if(snprintf(connstrings[device_found], sizeof(nfc_connstring), "%s:%s:%s", ACR122_USB_DRIVER_NAME, bus->dirname, dev->filename) >= (int)sizeof(nfc_connstring)) {
334+
if (snprintf(connstrings[device_found], sizeof(nfc_connstring), "%s:%s:%s", ACR122_USB_DRIVER_NAME, bus->dirname, dev->filename) >= (int)sizeof(nfc_connstring)) {
335335
// truncation occurred, skipping that one
336336
continue;
337337
}
@@ -430,7 +430,7 @@ acr122_usb_open(const nfc_context *context, const nfc_connstring connstring)
430430
goto free_mem;
431431
}
432432

433-
// Check if there are more than 0 alternative interfaces and claim the first one
433+
// Check if there are more than 0 alternative interfaces and claim the first one
434434
if (dev->config->interface->altsetting->bAlternateSetting > 0) {
435435
res = usb_set_altinterface(data.pudh, 0);
436436
if (res < 0) {

libnfc/drivers/pcsc.c

+19-27
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,7 @@ int pcsc_transmit(struct nfc_device *pnd, const uint8_t *tx, const size_t tx_len
138138
DWORD dw_rx_len = *rx_len;
139139
//in libfreefare, tx_len = 1, and it leads to 0x80100008 error, with PC/SC reader, the input tx_len at least two bytes for the SW value
140140
//so if found the reader is Feitian reader, we set to 2
141-
if (dw_rx_len == 1 && is_pcsc_reader_vendor_feitian(pnd))
142-
{
141+
if (dw_rx_len == 1 && is_pcsc_reader_vendor_feitian(pnd)) {
143142
dw_rx_len = 2;
144143
}
145144

@@ -201,15 +200,14 @@ uint8_t pcsc_get_icc_type(const struct nfc_device *pnd)
201200
return it;
202201
}
203202

204-
bool is_pcsc_reader_vendor(const struct nfc_device *pnd, const char * target_vendor_name)
203+
bool is_pcsc_reader_vendor(const struct nfc_device *pnd, const char *target_vendor_name)
205204
{
206205
bool isTarget = false;
207-
if (pnd == NULL || strlen(pnd->name) == 0)
208-
{
206+
if (pnd == NULL || strlen(pnd->name) == 0) {
209207
return isTarget;
210208
}
211209

212-
return isTarget = (strstr(pnd->name, target_vendor_name)) ? true:false;
210+
return isTarget = (strstr(pnd->name, target_vendor_name)) ? true : false;
213211
}
214212

215213
bool is_pcsc_reader_vendor_feitian(const struct nfc_device *pnd)
@@ -340,15 +338,14 @@ int pcsc_props_to_target(struct nfc_device *pnd, uint8_t it, const uint8_t *patr
340338
memcpy(pnt->nti.nai.abtUid, puid, szuid);
341339
pnt->nti.nai.szUidLen = szuid;
342340
}
343-
if (is_pcsc_reader_vendor_feitian(pnd))
344-
{
341+
if (is_pcsc_reader_vendor_feitian(pnd)) {
345342
uint8_t atqa[2];
346-
pcsc_get_atqa(pnd,atqa,sizeof(atqa));
343+
pcsc_get_atqa(pnd, atqa, sizeof(atqa));
347344
//memcpy(pnt->nti.nai.abtAtqa,atqa,2);
348345
pnt->nti.nai.abtAtqa[0] = atqa[1];
349346
pnt->nti.nai.abtAtqa[1] = atqa[0];
350347
uint8_t sak[1];
351-
pcsc_get_sak(pnd,sak,sizeof(sak));
348+
pcsc_get_sak(pnd, sak, sizeof(sak));
352349
pnt->nti.nai.btSak = sak[0];
353350
uint8_t ats[256];
354351
int ats_len = pcsc_get_ats(pnd, ats, sizeof(ats));
@@ -776,7 +773,7 @@ int pcsc_initiator_transceive_bytes(struct nfc_device *pnd, const uint8_t *pbtTx
776773
// FIXME: timeout is not handled
777774
(void) timeout;
778775

779-
if (is_pcsc_reader_vendor_feitian(pnd)){
776+
if (is_pcsc_reader_vendor_feitian(pnd)) {
780777
LOG_HEX(NFC_LOG_GROUP_COM, "not feitian reader pcsc apdu send", pbtTx, szTx);
781778

782779
uint8_t apdu_data[256];
@@ -797,7 +794,7 @@ int pcsc_initiator_transceive_bytes(struct nfc_device *pnd, const uint8_t *pbtTx
797794
apdu_data[4] = szTx - 2;
798795
memcpy(apdu_data + 5, pbtTx + 2, szTx - 2);
799796
send_size = 5 + szTx - 2;
800-
} else if (pbtTx[0] == 0x60 || pbtTx[0] == 0x61 || pbtTx[0] == 0x1A){//Auth command
797+
} else if (pbtTx[0] == 0x60 || pbtTx[0] == 0x61 || pbtTx[0] == 0x1A) { //Auth command
801798
apdu_data[0] = 0xFF;
802799
apdu_data[1] = 0x86;
803800
apdu_data[2] = 0x00;
@@ -809,23 +806,23 @@ int pcsc_initiator_transceive_bytes(struct nfc_device *pnd, const uint8_t *pbtTx
809806
apdu_data[8] = pbtTx[0];//type a or type b
810807
apdu_data[9] = 0x01;
811808
send_size = 10;
812-
} else if (pbtTx[0] == 0xC0){//DECREMENT cmd
809+
} else if (pbtTx[0] == 0xC0) { //DECREMENT cmd
813810
apdu_data[0] = 0xFF;
814811
apdu_data[1] = 0xD7;
815812
apdu_data[2] = 0x00;
816813
apdu_data[3] = pbtTx[1];//block index
817814
apdu_data[4] = 0x05;
818815
memcpy(apdu_data + 5, pbtTx + 2, szTx - 2);
819816
send_size = 5 + szTx - 2;
820-
} else if (pbtTx[0] == 0xC1){//INCREMENT cmd
817+
} else if (pbtTx[0] == 0xC1) { //INCREMENT cmd
821818
apdu_data[0] = 0xFF;
822819
apdu_data[1] = 0xD7;
823820
apdu_data[2] = 0x00;
824821
apdu_data[3] = pbtTx[1];//block index
825822
apdu_data[4] = 0x05;
826823
memcpy(apdu_data + 5, pbtTx + 2, szTx - 2);
827824
send_size = 5 + szTx - 2;
828-
} else if (pbtTx[0] == 0xC2){//STORE cmd
825+
} else if (pbtTx[0] == 0xC2) { //STORE cmd
829826
apdu_data[0] = 0xFF;
830827
apdu_data[1] = 0xD8;
831828
apdu_data[2] = 0x00;
@@ -840,7 +837,7 @@ int pcsc_initiator_transceive_bytes(struct nfc_device *pnd, const uint8_t *pbtTx
840837
LOG_HEX(NFC_LOG_GROUP_COM, "feitian reader pcsc apdu send:", apdu_data, send_size);
841838
pnd->last_error = pcsc_transmit(pnd, apdu_data, send_size, resp, &resp_len);
842839
LOG_HEX(NFC_LOG_GROUP_COM, "feitian reader pcsc apdu received:", resp, resp_len);
843-
840+
844841
memcpy(pbtRx, resp, resp_len);
845842
} else {
846843
pnd->last_error = pcsc_transmit(pnd, pbtTx, szTx, pbtRx, &resp_len);
@@ -938,7 +935,7 @@ pcsc_get_information_about(nfc_device *pnd, char **pbuf)
938935
struct pcsc_data *data = pnd->driver_data;
939936
LPBYTE name = NULL, version = NULL, type = NULL, serial = NULL;
940937
DWORD name_len = SCARD_AUTOALLOCATE, version_len = SCARD_AUTOALLOCATE,
941-
type_len = SCARD_AUTOALLOCATE, serial_len = SCARD_AUTOALLOCATE;
938+
type_len = SCARD_AUTOALLOCATE, serial_len = SCARD_AUTOALLOCATE;
942939
int res = NFC_SUCCESS;
943940
SCARDCONTEXT *pscc;
944941

@@ -974,27 +971,22 @@ pcsc_get_information_about(nfc_device *pnd, char **pbuf)
974971

975972
error:
976973
#ifdef __APPLE__
977-
if (pscc != NULL)
978-
{
974+
if (pscc != NULL) {
979975
SCardReleaseContext(*pscc);
980976
}
981-
if (name != NULL)
982-
{
977+
if (name != NULL) {
983978
free(name);
984979
name = NULL;
985980
}
986-
if (type != NULL)
987-
{
981+
if (type != NULL) {
988982
free(type);
989983
type = NULL;
990984
}
991-
if (version != NULL)
992-
{
985+
if (version != NULL) {
993986
free(version);
994987
version = NULL;
995988
}
996-
if (serial != NULL)
997-
{
989+
if (serial != NULL) {
998990
free(serial);
999991
serial = NULL;
1000992
}

libnfc/drivers/pn53x_usb.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ pn53x_usb_scan(const nfc_context *context, nfc_connstring connstrings[], const s
337337
// pn53x_usb_get_usb_device_name (dev, udev, pnddDevices[device_found].acDevice, sizeof (pnddDevices[device_found].acDevice));
338338
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "device found: Bus %s Device %s", bus->dirname, dev->filename);
339339
usb_close(udev);
340-
if(snprintf(connstrings[device_found], sizeof(nfc_connstring), "%s:%s:%s", PN53X_USB_DRIVER_NAME, bus->dirname, dev->filename) >= (int)sizeof(nfc_connstring)) {
340+
if (snprintf(connstrings[device_found], sizeof(nfc_connstring), "%s:%s:%s", PN53X_USB_DRIVER_NAME, bus->dirname, dev->filename) >= (int)sizeof(nfc_connstring)) {
341341
// truncation occurred, skipping that one
342342
continue;
343343
}

0 commit comments

Comments
 (0)