make style

This commit is contained in:
Philippe Teuwen 2020-05-21 15:06:17 +02:00
parent f52d04e0a7
commit 4525cd1c32
9 changed files with 455 additions and 470 deletions

View file

@ -580,8 +580,8 @@ pn53x_decode_target_data(const uint8_t *pbtRawData, size_t szRawData, pn53x_type
case NMT_ISO14443BICLASS:
// Store the UID
for(uint8_t i= 0 ; i < 8 ; ++i)
pnti->nhi.abtUID[7 - i]= pbtRawData[i];
for (uint8_t i = 0 ; i < 8 ; ++i)
pnti->nhi.abtUID[7 - i] = pbtRawData[i];
break;
case NMT_ISO14443B2CT:
@ -1216,8 +1216,8 @@ pn53x_initiator_select_passive_target_ext(struct nfc_device *pnd,
// return res;
}
// do select - returned anticol contains 'handle' for tag if present
abtReqt[0]= 0x0c; // iClass SELECT
abtAnticol[0]= 0x81; // iClass ANTICOL
abtReqt[0] = 0x0c; // iClass SELECT
abtAnticol[0] = 0x81; // iClass ANTICOL
if ((res = pn53x_initiator_transceive_bytes(pnd, abtReqt, sizeof(abtReqt), &abtAnticol[1], sizeof(abtAnticol) - 1, timeout)) < 0) {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "timeout on iClass anticol");
return res;
@ -2249,7 +2249,7 @@ static int pn53x_ISO14443B_SR_is_present(struct nfc_device *pnd)
static int pn53x_ISO14443B_ICLASS_is_present(struct nfc_device *pnd)
{
int timeout= 300;
int timeout = 300;
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "target_is_present(): Ping B iClass");
pn53x_initiator_init_iclass_modulation(pnd);
//
@ -2261,8 +2261,8 @@ static int pn53x_ISO14443B_ICLASS_is_present(struct nfc_device *pnd)
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "got expected timeout on iClass activate all");
}
// do select - returned anticol contains 'handle' for tag if present
abtReqt[0]= 0x0c; // iClass SELECT
abtAnticol[0]= 0x81; // iClass ANTICOL
abtReqt[0] = 0x0c; // iClass SELECT
abtAnticol[0] = 0x81; // iClass ANTICOL
if (pn53x_initiator_transceive_bytes(pnd, abtReqt, sizeof(abtReqt), &abtAnticol[1], sizeof(abtAnticol) - 1, timeout) < 0) {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "timeout on iClass anticol");
return NFC_ETGRELEASED;;

View file

@ -331,7 +331,7 @@ acr122_usb_scan(const nfc_context *context, nfc_connstring connstrings[], const
// acr122_usb_get_usb_device_name (dev, udev, pnddDevices[device_found].acDevice, sizeof (pnddDevices[device_found].acDevice));
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);
usb_close(udev);
if(snprintf(connstrings[device_found], sizeof(nfc_connstring), "%s:%s:%s", ACR122_USB_DRIVER_NAME, bus->dirname, dev->filename) >= (int)sizeof(nfc_connstring)) {
if (snprintf(connstrings[device_found], sizeof(nfc_connstring), "%s:%s:%s", ACR122_USB_DRIVER_NAME, bus->dirname, dev->filename) >= (int)sizeof(nfc_connstring)) {
// truncation occurred, skipping that one
continue;
}

View file

@ -138,8 +138,7 @@ int pcsc_transmit(struct nfc_device *pnd, const uint8_t *tx, const size_t tx_len
DWORD dw_rx_len = *rx_len;
//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
//so if found the reader is Feitian reader, we set to 2
if (dw_rx_len == 1 && is_pcsc_reader_vendor_feitian(pnd))
{
if (dw_rx_len == 1 && is_pcsc_reader_vendor_feitian(pnd)) {
dw_rx_len = 2;
}
@ -201,15 +200,14 @@ uint8_t pcsc_get_icc_type(const struct nfc_device *pnd)
return it;
}
bool is_pcsc_reader_vendor(const struct nfc_device *pnd, const char * target_vendor_name)
bool is_pcsc_reader_vendor(const struct nfc_device *pnd, const char *target_vendor_name)
{
bool isTarget = false;
if (pnd == NULL || strlen(pnd->name) == 0)
{
if (pnd == NULL || strlen(pnd->name) == 0) {
return isTarget;
}
return isTarget = (strstr(pnd->name, target_vendor_name)) ? true:false;
return isTarget = (strstr(pnd->name, target_vendor_name)) ? true : false;
}
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
memcpy(pnt->nti.nai.abtUid, puid, szuid);
pnt->nti.nai.szUidLen = szuid;
}
if (is_pcsc_reader_vendor_feitian(pnd))
{
if (is_pcsc_reader_vendor_feitian(pnd)) {
uint8_t atqa[2];
pcsc_get_atqa(pnd,atqa,sizeof(atqa));
pcsc_get_atqa(pnd, atqa, sizeof(atqa));
//memcpy(pnt->nti.nai.abtAtqa,atqa,2);
pnt->nti.nai.abtAtqa[0] = atqa[1];
pnt->nti.nai.abtAtqa[1] = atqa[0];
uint8_t sak[1];
pcsc_get_sak(pnd,sak,sizeof(sak));
pcsc_get_sak(pnd, sak, sizeof(sak));
pnt->nti.nai.btSak = sak[0];
uint8_t ats[256];
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
// FIXME: timeout is not handled
(void) timeout;
if (is_pcsc_reader_vendor_feitian(pnd)){
if (is_pcsc_reader_vendor_feitian(pnd)) {
LOG_HEX(NFC_LOG_GROUP_COM, "not feitian reader pcsc apdu send", pbtTx, szTx);
uint8_t apdu_data[256];
@ -797,7 +794,7 @@ int pcsc_initiator_transceive_bytes(struct nfc_device *pnd, const uint8_t *pbtTx
apdu_data[4] = szTx - 2;
memcpy(apdu_data + 5, pbtTx + 2, szTx - 2);
send_size = 5 + szTx - 2;
} else if (pbtTx[0] == 0x60 || pbtTx[0] == 0x61 || pbtTx[0] == 0x1A){//Auth command
} else if (pbtTx[0] == 0x60 || pbtTx[0] == 0x61 || pbtTx[0] == 0x1A) { //Auth command
apdu_data[0] = 0xFF;
apdu_data[1] = 0x86;
apdu_data[2] = 0x00;
@ -809,7 +806,7 @@ int pcsc_initiator_transceive_bytes(struct nfc_device *pnd, const uint8_t *pbtTx
apdu_data[8] = pbtTx[0];//type a or type b
apdu_data[9] = 0x01;
send_size = 10;
} else if (pbtTx[0] == 0xC0){//DECREMENT cmd
} else if (pbtTx[0] == 0xC0) { //DECREMENT cmd
apdu_data[0] = 0xFF;
apdu_data[1] = 0xD7;
apdu_data[2] = 0x00;
@ -817,7 +814,7 @@ int pcsc_initiator_transceive_bytes(struct nfc_device *pnd, const uint8_t *pbtTx
apdu_data[4] = 0x05;
memcpy(apdu_data + 5, pbtTx + 2, szTx - 2);
send_size = 5 + szTx - 2;
} else if (pbtTx[0] == 0xC1){//INCREMENT cmd
} else if (pbtTx[0] == 0xC1) { //INCREMENT cmd
apdu_data[0] = 0xFF;
apdu_data[1] = 0xD7;
apdu_data[2] = 0x00;
@ -825,7 +822,7 @@ int pcsc_initiator_transceive_bytes(struct nfc_device *pnd, const uint8_t *pbtTx
apdu_data[4] = 0x05;
memcpy(apdu_data + 5, pbtTx + 2, szTx - 2);
send_size = 5 + szTx - 2;
} else if (pbtTx[0] == 0xC2){//STORE cmd
} else if (pbtTx[0] == 0xC2) { //STORE cmd
apdu_data[0] = 0xFF;
apdu_data[1] = 0xD8;
apdu_data[2] = 0x00;
@ -974,27 +971,22 @@ pcsc_get_information_about(nfc_device *pnd, char **pbuf)
error:
#ifdef __APPLE__
if (pscc != NULL)
{
if (pscc != NULL) {
SCardReleaseContext(*pscc);
}
if (name != NULL)
{
if (name != NULL) {
free(name);
name = NULL;
}
if (type != NULL)
{
if (type != NULL) {
free(type);
type = NULL;
}
if (version != NULL)
{
if (version != NULL) {
free(version);
version = NULL;
}
if (serial != NULL)
{
if (serial != NULL) {
free(serial);
serial = NULL;
}

View file

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

View file

@ -159,91 +159,84 @@ static bool IsTechnology(nfc_tag_info_t *TagInfo, nfc_modulation_type nmt)
return false;
}
static void BufferPrintBytes(char* buffer, unsigned int buflen, const uint8_t *data, unsigned int datalen)
static void BufferPrintBytes(char *buffer, unsigned int buflen, const uint8_t *data, unsigned int datalen)
{
int cx = 0;
for(unsigned int i = 0x00; i < datalen; i++) {
for (unsigned int i = 0x00; i < datalen; i++) {
cx += snprintf(buffer + cx, buflen - cx, "%02X ", data[i]);
}
}
static void PrintTagInfo (nfc_tag_info_t *TagInfo)
static void PrintTagInfo(nfc_tag_info_t *TagInfo)
{
switch (TagInfo->technology)
{
case TARGET_TYPE_UNKNOWN:
{
switch (TagInfo->technology) {
case TARGET_TYPE_UNKNOWN: {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type Unknown'");
} break;
case TARGET_TYPE_ISO14443_3A:
{
}
break;
case TARGET_TYPE_ISO14443_3A: {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type 3A'");
} break;
case TARGET_TYPE_ISO14443_3B:
{
}
break;
case TARGET_TYPE_ISO14443_3B: {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type 3B'");
} break;
case TARGET_TYPE_ISO14443_4:
{
}
break;
case TARGET_TYPE_ISO14443_4: {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type 4A'");
} break;
case TARGET_TYPE_FELICA:
{
}
break;
case TARGET_TYPE_FELICA: {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type F'");
} break;
case TARGET_TYPE_ISO15693:
{
}
break;
case TARGET_TYPE_ISO15693: {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type V'");
} break;
case TARGET_TYPE_NDEF:
{
}
break;
case TARGET_TYPE_NDEF: {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type NDEF'");
} break;
case TARGET_TYPE_NDEF_FORMATABLE:
{
}
break;
case TARGET_TYPE_NDEF_FORMATABLE: {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type Formatable'");
} break;
case TARGET_TYPE_MIFARE_CLASSIC:
{
}
break;
case TARGET_TYPE_MIFARE_CLASSIC: {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type A - Mifare Classic'");
} break;
case TARGET_TYPE_MIFARE_UL:
{
}
break;
case TARGET_TYPE_MIFARE_UL: {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type A - Mifare Ul'");
} break;
case TARGET_TYPE_KOVIO_BARCODE:
{
}
break;
case TARGET_TYPE_KOVIO_BARCODE: {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type A - Kovio Barcode'");
} break;
case TARGET_TYPE_ISO14443_3A_3B:
{
}
break;
case TARGET_TYPE_ISO14443_3A_3B: {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type A/B'");
} break;
default:
{
}
break;
default: {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type %d (Unknown or not supported)'\n", TagInfo->technology);
} break;
}
break;
}
/*32 is max UID len (Kovio tags)*/
if((0x00 != TagInfo->uid_length) && (32 >= TagInfo->uid_length))
{
if ((0x00 != TagInfo->uid_length) && (32 >= TagInfo->uid_length)) {
char buffer [100];
int cx = 0;
if(4 == TagInfo->uid_length || 7 == TagInfo->uid_length || 10 == TagInfo->uid_length)
{
if (4 == TagInfo->uid_length || 7 == TagInfo->uid_length || 10 == TagInfo->uid_length) {
cx += snprintf(buffer + cx, sizeof(buffer) - cx, "NFCID1 : \t'");
}
else if(8 == TagInfo->uid_length)
{
} else if (8 == TagInfo->uid_length) {
cx += snprintf(buffer + cx, sizeof(buffer) - cx, "NFCID2 : \t'");
}
else
{
} else {
cx += snprintf(buffer + cx, sizeof(buffer) - cx, "UID : \t'");
}
BufferPrintBytes(buffer + cx, sizeof(buffer) - cx, (unsigned char*) TagInfo->uid, TagInfo->uid_length);
BufferPrintBytes(buffer + cx, sizeof(buffer) - cx, (unsigned char *) TagInfo->uid, TagInfo->uid_length);
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s'", buffer);
}
}
@ -292,7 +285,7 @@ pn71xx_initiator_select_passive_target(struct nfc_device *pnd,
memset(&nttmp, 0x00, sizeof(nfc_target));
nttmp.nm = nm;
void* uidPtr = NULL;
void *uidPtr = NULL;
unsigned int maxLen = 0;
switch (nm.nmt) {
@ -307,7 +300,7 @@ pn71xx_initiator_select_passive_target(struct nfc_device *pnd,
// make hardcoded desfire for freefare lib check
nttmp.nti.nai.btSak = 0x20;
nttmp.nti.nai.szAtsLen = 5;
memcpy (nttmp.nti.nai.abtAts, "\x75\x77\x81\x02", 4);
memcpy(nttmp.nti.nai.abtAts, "\x75\x77\x81\x02", 4);
}
}
break;
@ -387,7 +380,7 @@ pn71xx_initiator_deselect_target(struct nfc_device *pnd)
static int
pn71xx_initiator_transceive_bytes(struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, uint8_t *pbtRx,
const size_t szRx, int timeout)
const size_t szRx, int timeout)
{
if (pnd == NULL) return NFC_EIO;
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "transceive_bytes timeout=%d", timeout);
@ -515,7 +508,7 @@ pn71xx_set_property_int(struct nfc_device *pnd, const nfc_property property, con
static int
pn71xx_get_information_about(nfc_device *pnd, char **pbuf)
{
static const char* info = "PN71XX nfc driver using libnfc-nci userspace library";
static const char *info = "PN71XX nfc driver using libnfc-nci userspace library";
size_t buflen = strlen(info) + 1;
if (pnd == NULL) return NFC_EIO;

View file

@ -140,7 +140,7 @@ struct nfc_driver_list {
const struct nfc_driver_list *nfc_drivers = NULL;
// descritions for debugging
const char * nfc_property_name[] = {
const char *nfc_property_name[] = {
"NP_TIMEOUT_COMMAND",
"NP_TIMEOUT_ATR",
"NP_TIMEOUT_COM",
@ -206,8 +206,7 @@ nfc_device_validate_modulation(nfc_device *pnd, const nfc_mode mode, const nfc_m
int
nfc_register_driver(const struct nfc_driver *ndr)
{
if (!ndr)
{
if (!ndr) {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "nfc_register_driver returning NFC_EINVARG");
return NFC_EINVARG;
}

View file

@ -620,7 +620,8 @@ print_usage(const char *pcProgramName)
}
bool is_directwrite(){
bool is_directwrite()
{
printf("Checking if Badge is DirectWrite...\n");
// Set default keys
@ -629,23 +630,23 @@ bool is_directwrite(){
memcpy(mtDump.amb[0].mbt.abtKeyB, default_key, sizeof(default_key));
// Temporarly override bUseKeyFile
bool orig_bUseKeyFile=bUseKeyFile;
bUseKeyFile=false;
bool orig_bUseKeyFile = bUseKeyFile;
bUseKeyFile = false;
// Try to authenticate for the current sector
if (!authenticate(0)) {
printf("!\nError: authentication failed for block 0x%02x\n", 0);
bUseKeyFile=orig_bUseKeyFile;
bUseKeyFile = orig_bUseKeyFile;
return false;
}
// restore bUseKeyFile
bUseKeyFile=orig_bUseKeyFile;
bUseKeyFile = orig_bUseKeyFile;
// Try to read block 0
uint8_t original_b0[16];
if (nfc_initiator_mifare_cmd(pnd, MC_READ, 0, &mp)) {
memcpy(original_b0, mp.mpd.abtData, sizeof(mp.mpd.abtData));
printf(" Original Block 0: ");
for(int i=0;i<16;i++){
for (int i = 0; i < 16; i++) {
printf("%02x", original_b0[i]);
}
printf("\n");
@ -845,14 +846,14 @@ main(int argc, const char *argv[])
}
} else
printf("RATS support: no\n");
printf("Guessing size: seems to be a %lu-byte card\n", (unsigned long) ((uiBlocks + 1) * sizeof(mifare_classic_block)));
printf("Guessing size: seems to be a %lu-byte card\n", (unsigned long)((uiBlocks + 1) * sizeof(mifare_classic_block)));
//If size is 4k check for direct-write card
if (uiBlocks == 0xff) {
if (is_directwrite()){
if (is_directwrite()) {
printf("Card is DirectWrite\n");
magic3=true;
unlock=0;
magic3 = true;
unlock = 0;
} else {
printf("Card is not DirectWrite\n");
}

View file

@ -300,7 +300,7 @@ static bool check_magic(void)
if (nfc_initiator_mifare_cmd(pnd, MC_READ, 0, &mp)) {
memcpy(original_b0, mp.mpd.abtData, 12);
printf(" Original Block 0 (Pages 0-2): ");
for(int i=0;i<12;i++){
for (int i = 0; i < 12; i++) {
printf("%02x", original_b0[i]);
}
printf("\n");
@ -313,8 +313,8 @@ static bool check_magic(void)
printf(" Attempt to write Block 0 (pages 0-2) ...\n");
for (uint32_t page = 0; page <= 2; page++) {
printf(" Writing Page %i:", page);
memcpy(mp.mpd.abtData, original_b0 + page*4, 4);
for(int i=0;i<4;i++){
memcpy(mp.mpd.abtData, original_b0 + page * 4, 4);
for (int i = 0; i < 4; i++) {
printf(" %02x", mp.mpd.abtData[i]);
}
printf("\n");
@ -324,7 +324,7 @@ static bool check_magic(void)
break;
}
}
if(directWrite){
if (directWrite) {
printf(" Block 0 written successfully\n");
printf("Card is DirectWrite\n");
return true;