make style
This commit is contained in:
parent
f52d04e0a7
commit
4525cd1c32
9 changed files with 455 additions and 470 deletions
|
@ -580,8 +580,8 @@ pn53x_decode_target_data(const uint8_t *pbtRawData, size_t szRawData, pn53x_type
|
||||||
|
|
||||||
case NMT_ISO14443BICLASS:
|
case NMT_ISO14443BICLASS:
|
||||||
// Store the UID
|
// Store the UID
|
||||||
for(uint8_t i= 0 ; i < 8 ; ++i)
|
for (uint8_t i = 0 ; i < 8 ; ++i)
|
||||||
pnti->nhi.abtUID[7 - i]= pbtRawData[i];
|
pnti->nhi.abtUID[7 - i] = pbtRawData[i];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NMT_ISO14443B2CT:
|
case NMT_ISO14443B2CT:
|
||||||
|
@ -1060,51 +1060,51 @@ pn53x_initiator_init(struct nfc_device *pnd)
|
||||||
// iclass requires special modulation settings
|
// iclass requires special modulation settings
|
||||||
void pn53x_initiator_init_iclass_modulation(struct nfc_device *pnd)
|
void pn53x_initiator_init_iclass_modulation(struct nfc_device *pnd)
|
||||||
{
|
{
|
||||||
// send a bunch of low level commands reverse engineered from a working iClass reader
|
// send a bunch of low level commands reverse engineered from a working iClass reader
|
||||||
// original device was using a PN512
|
// original device was using a PN512
|
||||||
//
|
//
|
||||||
// // TxModeReg - Defines the data rate and framing during transmission.
|
// // TxModeReg - Defines the data rate and framing during transmission.
|
||||||
//// 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
|
//// 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
|
||||||
//pn512_write_register(0x12, "\x03", 1, false);
|
//pn512_write_register(0x12, "\x03", 1, false);
|
||||||
pn53x_WriteRegister(pnd, PN53X_REG_CIU_TxMode, 0x03);
|
pn53x_WriteRegister(pnd, PN53X_REG_CIU_TxMode, 0x03);
|
||||||
//
|
//
|
||||||
// // RxModeReg - Defines the data rate and framing during reception.
|
// // RxModeReg - Defines the data rate and framing during reception.
|
||||||
//pn512_write_register(0x13, "\x03", 1, false);
|
//pn512_write_register(0x13, "\x03", 1, false);
|
||||||
// addy changed to set bit 3 - RxNoErr (put data in fifo before flagging read end)
|
// addy changed to set bit 3 - RxNoErr (put data in fifo before flagging read end)
|
||||||
//pn512_write_register(0x13, "\x0B", 1, false);
|
//pn512_write_register(0x13, "\x0B", 1, false);
|
||||||
pn53x_WriteRegister(pnd, PN53X_REG_CIU_RxMode, 0x0B);
|
pn53x_WriteRegister(pnd, PN53X_REG_CIU_RxMode, 0x0B);
|
||||||
|
|
||||||
// ManualRCVReg - Allows manual fine tuning of the internal receiver.
|
// ManualRCVReg - Allows manual fine tuning of the internal receiver.
|
||||||
//pn512_write_register(0x1d, "\x10", 1, false);
|
//pn512_write_register(0x1d, "\x10", 1, false);
|
||||||
pn53x_WriteRegister(pnd, PN53X_REG_CIU_ManualRCV, 0x10);
|
pn53x_WriteRegister(pnd, PN53X_REG_CIU_ManualRCV, 0x10);
|
||||||
|
|
||||||
// RFCfgReg - Configures the receiver gain and RF level detector sensitivity.
|
// RFCfgReg - Configures the receiver gain and RF level detector sensitivity.
|
||||||
//pn512_write_register(0x26, "\x70", 1, false);
|
//pn512_write_register(0x26, "\x70", 1, false);
|
||||||
pn53x_WriteRegister(pnd, PN53X_REG_CIU_RFCfg, 0x70);
|
pn53x_WriteRegister(pnd, PN53X_REG_CIU_RFCfg, 0x70);
|
||||||
|
|
||||||
// GsNOffReg - Selects the conductance for the N-driver of the antenna driver pins TX1 and TX2 when the driver is switched off.
|
// GsNOffReg - Selects the conductance for the N-driver of the antenna driver pins TX1 and TX2 when the driver is switched off.
|
||||||
//pn512_write_register(0x23, "\x88", 1, false);
|
//pn512_write_register(0x23, "\x88", 1, false);
|
||||||
pn53x_WriteRegister(pnd, PN53X_REG_CIU_GsNOFF, 0x88);
|
pn53x_WriteRegister(pnd, PN53X_REG_CIU_GsNOFF, 0x88);
|
||||||
|
|
||||||
// GsNOnReg - Selects the conductance for the N-driver of the antenna driver pins TX1 and TX2 when the driver is switched on.
|
// GsNOnReg - Selects the conductance for the N-driver of the antenna driver pins TX1 and TX2 when the driver is switched on.
|
||||||
//pn512_write_register(0x27, "\xf8", 1, false);
|
//pn512_write_register(0x27, "\xf8", 1, false);
|
||||||
pn53x_WriteRegister(pnd, PN53X_REG_CIU_GsNOn, 0xf8);
|
pn53x_WriteRegister(pnd, PN53X_REG_CIU_GsNOn, 0xf8);
|
||||||
|
|
||||||
// CWGsPReg - Defines the conductance of the P-driver during times of no modulation.
|
// CWGsPReg - Defines the conductance of the P-driver during times of no modulation.
|
||||||
//pn512_write_register(0x28, "\x3f", 1, false);
|
//pn512_write_register(0x28, "\x3f", 1, false);
|
||||||
pn53x_WriteRegister(pnd, PN53X_REG_CIU_CWGsP, 0x3f);
|
pn53x_WriteRegister(pnd, PN53X_REG_CIU_CWGsP, 0x3f);
|
||||||
|
|
||||||
// ModGsPReg - Defines the driver P-output conductance during modulation.
|
// ModGsPReg - Defines the driver P-output conductance during modulation.
|
||||||
//pn512_write_register(0x29, "\x10", 1, false);
|
//pn512_write_register(0x29, "\x10", 1, false);
|
||||||
pn53x_WriteRegister(pnd, PN53X_REG_CIU_ModGsP, 0x10);
|
pn53x_WriteRegister(pnd, PN53X_REG_CIU_ModGsP, 0x10);
|
||||||
|
|
||||||
// TReloadReg (MSB) - Describes the MSB of the 16-bit long timer reload value.
|
// TReloadReg (MSB) - Describes the MSB of the 16-bit long timer reload value.
|
||||||
//pn512_write_register(0x2c, "\x69", 1, false);
|
//pn512_write_register(0x2c, "\x69", 1, false);
|
||||||
pn53x_WriteRegister(pnd, PN53X_REG_CIU_TReloadVal_hi, 0x69);
|
pn53x_WriteRegister(pnd, PN53X_REG_CIU_TReloadVal_hi, 0x69);
|
||||||
|
|
||||||
// TReloadReg (LSB) - Describes the LSB of the 16-bit long timer reload value.
|
// TReloadReg (LSB) - Describes the LSB of the 16-bit long timer reload value.
|
||||||
//pn512_write_register(0x2d, "\xf0", 1, false);
|
//pn512_write_register(0x2d, "\xf0", 1, false);
|
||||||
pn53x_WriteRegister(pnd, PN53X_REG_CIU_TReloadVal_lo, 0xf0);
|
pn53x_WriteRegister(pnd, PN53X_REG_CIU_TReloadVal_lo, 0xf0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -1202,10 +1202,10 @@ pn53x_initiator_select_passive_target_ext(struct nfc_device *pnd,
|
||||||
}
|
}
|
||||||
szTargetsData = 6; // u16 UID_LSB, u8 prod code, u8 fab code, u16 UID_MSB
|
szTargetsData = 6; // u16 UID_LSB, u8 prod code, u8 fab code, u16 UID_MSB
|
||||||
} else if (nm.nmt == NMT_ISO14443BICLASS) {
|
} else if (nm.nmt == NMT_ISO14443BICLASS) {
|
||||||
pn53x_initiator_init_iclass_modulation(pnd);
|
pn53x_initiator_init_iclass_modulation(pnd);
|
||||||
//
|
//
|
||||||
// Some work to do before getting the UID...
|
// Some work to do before getting the UID...
|
||||||
// send ICLASS_ACTIVATE_ALL command - will get timeout as we don't expect response
|
// send ICLASS_ACTIVATE_ALL command - will get timeout as we don't expect response
|
||||||
uint8_t abtReqt[] = { 0x0a }; // iClass ACTIVATE_ALL
|
uint8_t abtReqt[] = { 0x0a }; // iClass ACTIVATE_ALL
|
||||||
uint8_t abtAnticol[11];
|
uint8_t abtAnticol[11];
|
||||||
if ((res = pn53x_initiator_transceive_bytes(pnd, abtReqt, sizeof(abtReqt), NULL, 0, timeout)) < 0) {
|
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,
|
||||||
// continue;
|
// continue;
|
||||||
//} else
|
//} else
|
||||||
// return res;
|
// return res;
|
||||||
}
|
}
|
||||||
// do select - returned anticol contains 'handle' for tag if present
|
// do select - returned anticol contains 'handle' for tag if present
|
||||||
abtReqt[0]= 0x0c; // iClass SELECT
|
abtReqt[0] = 0x0c; // iClass SELECT
|
||||||
abtAnticol[0]= 0x81; // iClass ANTICOL
|
abtAnticol[0] = 0x81; // iClass ANTICOL
|
||||||
if ((res = pn53x_initiator_transceive_bytes(pnd, abtReqt, sizeof(abtReqt), &abtAnticol[1], sizeof(abtAnticol) - 1, timeout)) < 0) {
|
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");
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "timeout on iClass anticol");
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
// write back anticol handle to get UID
|
// write back anticol handle to get UID
|
||||||
if ((res = pn53x_initiator_transceive_bytes(pnd, abtAnticol, 9, abtTargetsData, 10, timeout)) < 0) {
|
if ((res = pn53x_initiator_transceive_bytes(pnd, abtAnticol, 9, abtTargetsData, 10, timeout)) < 0) {
|
||||||
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "timeout on iClass get UID");
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "timeout on iClass get UID");
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
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]);
|
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]);
|
||||||
szTargetsData = 8;
|
szTargetsData = 8;
|
||||||
nttmp.nm = nm;
|
nttmp.nm = nm;
|
||||||
if ((res = pn53x_decode_target_data(abtTargetsData, szTargetsData, CHIP_DATA(pnd)->type, nm.nmt, &(nttmp.nti))) < 0) {
|
if ((res = pn53x_decode_target_data(abtTargetsData, szTargetsData, CHIP_DATA(pnd)->type, nm.nmt, &(nttmp.nti))) < 0) {
|
||||||
return res;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
|
|
||||||
if ((res = pn53x_initiator_transceive_bytes(pnd, pbtInitData, szInitData, abtTargetsData, sizeof(abtTargetsData), timeout)) < 0) {
|
|
||||||
if ((res == NFC_ERFTRANS) && (CHIP_DATA(pnd)->last_status_byte == 0x01)) { // Chip timeout
|
|
||||||
continue;
|
|
||||||
} else
|
|
||||||
return res;
|
return res;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if ((res = pn53x_initiator_transceive_bytes(pnd, pbtInitData, szInitData, abtTargetsData, sizeof(abtTargetsData), timeout)) < 0) {
|
||||||
|
if ((res == NFC_ERFTRANS) && (CHIP_DATA(pnd)->last_status_byte == 0x01)) { // Chip timeout
|
||||||
|
continue;
|
||||||
|
} else
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
szTargetsData = (size_t)res;
|
||||||
}
|
}
|
||||||
szTargetsData = (size_t)res;
|
|
||||||
}
|
|
||||||
|
|
||||||
nttmp.nm = nm;
|
nttmp.nm = nm;
|
||||||
if ((res = pn53x_decode_target_data(abtTargetsData, szTargetsData, CHIP_DATA(pnd)->type, nm.nmt, &(nttmp.nti))) < 0) {
|
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)
|
||||||
|
|
||||||
static int pn53x_ISO14443B_ICLASS_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");
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "target_is_present(): Ping B iClass");
|
||||||
pn53x_initiator_init_iclass_modulation(pnd);
|
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");
|
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
|
// do select - returned anticol contains 'handle' for tag if present
|
||||||
abtReqt[0]= 0x0c; // iClass SELECT
|
abtReqt[0] = 0x0c; // iClass SELECT
|
||||||
abtAnticol[0]= 0x81; // iClass ANTICOL
|
abtAnticol[0] = 0x81; // iClass ANTICOL
|
||||||
if (pn53x_initiator_transceive_bytes(pnd, abtReqt, sizeof(abtReqt), &abtAnticol[1], sizeof(abtAnticol) - 1, timeout) < 0) {
|
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");
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "timeout on iClass anticol");
|
||||||
return NFC_ETGRELEASED;;
|
return NFC_ETGRELEASED;;
|
||||||
|
|
|
@ -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));
|
// 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);
|
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);
|
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
|
// truncation occurred, skipping that one
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -430,7 +430,7 @@ acr122_usb_open(const nfc_context *context, const nfc_connstring connstring)
|
||||||
goto free_mem;
|
goto free_mem;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if there are more than 0 alternative interfaces and claim the first one
|
// Check if there are more than 0 alternative interfaces and claim the first one
|
||||||
if (dev->config->interface->altsetting->bAlternateSetting > 0) {
|
if (dev->config->interface->altsetting->bAlternateSetting > 0) {
|
||||||
res = usb_set_altinterface(data.pudh, 0);
|
res = usb_set_altinterface(data.pudh, 0);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
|
|
|
@ -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;
|
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
|
//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
|
//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;
|
dw_rx_len = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,15 +200,14 @@ uint8_t pcsc_get_icc_type(const struct nfc_device *pnd)
|
||||||
return it;
|
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;
|
bool isTarget = false;
|
||||||
if (pnd == NULL || strlen(pnd->name) == 0)
|
if (pnd == NULL || strlen(pnd->name) == 0) {
|
||||||
{
|
|
||||||
return isTarget;
|
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)
|
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);
|
memcpy(pnt->nti.nai.abtUid, puid, szuid);
|
||||||
pnt->nti.nai.szUidLen = szuid;
|
pnt->nti.nai.szUidLen = szuid;
|
||||||
}
|
}
|
||||||
if (is_pcsc_reader_vendor_feitian(pnd))
|
if (is_pcsc_reader_vendor_feitian(pnd)) {
|
||||||
{
|
|
||||||
uint8_t atqa[2];
|
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);
|
//memcpy(pnt->nti.nai.abtAtqa,atqa,2);
|
||||||
pnt->nti.nai.abtAtqa[0] = atqa[1];
|
pnt->nti.nai.abtAtqa[0] = atqa[1];
|
||||||
pnt->nti.nai.abtAtqa[1] = atqa[0];
|
pnt->nti.nai.abtAtqa[1] = atqa[0];
|
||||||
uint8_t sak[1];
|
uint8_t sak[1];
|
||||||
pcsc_get_sak(pnd,sak,sizeof(sak));
|
pcsc_get_sak(pnd, sak, sizeof(sak));
|
||||||
pnt->nti.nai.btSak = sak[0];
|
pnt->nti.nai.btSak = sak[0];
|
||||||
uint8_t ats[256];
|
uint8_t ats[256];
|
||||||
int ats_len = pcsc_get_ats(pnd, ats, sizeof(ats));
|
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
|
// FIXME: timeout is not handled
|
||||||
(void) timeout;
|
(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);
|
LOG_HEX(NFC_LOG_GROUP_COM, "not feitian reader pcsc apdu send", pbtTx, szTx);
|
||||||
|
|
||||||
uint8_t apdu_data[256];
|
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;
|
apdu_data[4] = szTx - 2;
|
||||||
memcpy(apdu_data + 5, pbtTx + 2, szTx - 2);
|
memcpy(apdu_data + 5, pbtTx + 2, szTx - 2);
|
||||||
send_size = 5 + 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[0] = 0xFF;
|
||||||
apdu_data[1] = 0x86;
|
apdu_data[1] = 0x86;
|
||||||
apdu_data[2] = 0x00;
|
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[8] = pbtTx[0];//type a or type b
|
||||||
apdu_data[9] = 0x01;
|
apdu_data[9] = 0x01;
|
||||||
send_size = 10;
|
send_size = 10;
|
||||||
} else if (pbtTx[0] == 0xC0){//DECREMENT cmd
|
} else if (pbtTx[0] == 0xC0) { //DECREMENT cmd
|
||||||
apdu_data[0] = 0xFF;
|
apdu_data[0] = 0xFF;
|
||||||
apdu_data[1] = 0xD7;
|
apdu_data[1] = 0xD7;
|
||||||
apdu_data[2] = 0x00;
|
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;
|
apdu_data[4] = 0x05;
|
||||||
memcpy(apdu_data + 5, pbtTx + 2, szTx - 2);
|
memcpy(apdu_data + 5, pbtTx + 2, szTx - 2);
|
||||||
send_size = 5 + 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[0] = 0xFF;
|
||||||
apdu_data[1] = 0xD7;
|
apdu_data[1] = 0xD7;
|
||||||
apdu_data[2] = 0x00;
|
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;
|
apdu_data[4] = 0x05;
|
||||||
memcpy(apdu_data + 5, pbtTx + 2, szTx - 2);
|
memcpy(apdu_data + 5, pbtTx + 2, szTx - 2);
|
||||||
send_size = 5 + 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[0] = 0xFF;
|
||||||
apdu_data[1] = 0xD8;
|
apdu_data[1] = 0xD8;
|
||||||
apdu_data[2] = 0x00;
|
apdu_data[2] = 0x00;
|
||||||
|
@ -840,7 +837,7 @@ int pcsc_initiator_transceive_bytes(struct nfc_device *pnd, const uint8_t *pbtTx
|
||||||
LOG_HEX(NFC_LOG_GROUP_COM, "feitian reader pcsc apdu send:", apdu_data, send_size);
|
LOG_HEX(NFC_LOG_GROUP_COM, "feitian reader pcsc apdu send:", apdu_data, send_size);
|
||||||
pnd->last_error = pcsc_transmit(pnd, apdu_data, send_size, resp, &resp_len);
|
pnd->last_error = pcsc_transmit(pnd, apdu_data, send_size, resp, &resp_len);
|
||||||
LOG_HEX(NFC_LOG_GROUP_COM, "feitian reader pcsc apdu received:", resp, resp_len);
|
LOG_HEX(NFC_LOG_GROUP_COM, "feitian reader pcsc apdu received:", resp, resp_len);
|
||||||
|
|
||||||
memcpy(pbtRx, resp, resp_len);
|
memcpy(pbtRx, resp, resp_len);
|
||||||
} else {
|
} else {
|
||||||
pnd->last_error = pcsc_transmit(pnd, pbtTx, szTx, pbtRx, &resp_len);
|
pnd->last_error = pcsc_transmit(pnd, pbtTx, szTx, pbtRx, &resp_len);
|
||||||
|
@ -938,7 +935,7 @@ pcsc_get_information_about(nfc_device *pnd, char **pbuf)
|
||||||
struct pcsc_data *data = pnd->driver_data;
|
struct pcsc_data *data = pnd->driver_data;
|
||||||
LPBYTE name = NULL, version = NULL, type = NULL, serial = NULL;
|
LPBYTE name = NULL, version = NULL, type = NULL, serial = NULL;
|
||||||
DWORD name_len = SCARD_AUTOALLOCATE, version_len = SCARD_AUTOALLOCATE,
|
DWORD name_len = SCARD_AUTOALLOCATE, version_len = SCARD_AUTOALLOCATE,
|
||||||
type_len = SCARD_AUTOALLOCATE, serial_len = SCARD_AUTOALLOCATE;
|
type_len = SCARD_AUTOALLOCATE, serial_len = SCARD_AUTOALLOCATE;
|
||||||
int res = NFC_SUCCESS;
|
int res = NFC_SUCCESS;
|
||||||
SCARDCONTEXT *pscc;
|
SCARDCONTEXT *pscc;
|
||||||
|
|
||||||
|
@ -974,27 +971,22 @@ pcsc_get_information_about(nfc_device *pnd, char **pbuf)
|
||||||
|
|
||||||
error:
|
error:
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
if (pscc != NULL)
|
if (pscc != NULL) {
|
||||||
{
|
|
||||||
SCardReleaseContext(*pscc);
|
SCardReleaseContext(*pscc);
|
||||||
}
|
}
|
||||||
if (name != NULL)
|
if (name != NULL) {
|
||||||
{
|
|
||||||
free(name);
|
free(name);
|
||||||
name = NULL;
|
name = NULL;
|
||||||
}
|
}
|
||||||
if (type != NULL)
|
if (type != NULL) {
|
||||||
{
|
|
||||||
free(type);
|
free(type);
|
||||||
type = NULL;
|
type = NULL;
|
||||||
}
|
}
|
||||||
if (version != NULL)
|
if (version != NULL) {
|
||||||
{
|
|
||||||
free(version);
|
free(version);
|
||||||
version = NULL;
|
version = NULL;
|
||||||
}
|
}
|
||||||
if (serial != NULL)
|
if (serial != NULL) {
|
||||||
{
|
|
||||||
free(serial);
|
free(serial);
|
||||||
serial = NULL;
|
serial = NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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));
|
// 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);
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "device found: Bus %s Device %s", bus->dirname, dev->filename);
|
||||||
usb_close(udev);
|
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
|
// truncation occurred, skipping that one
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,16 +58,16 @@ static void onTagDeparture(void);
|
||||||
static size_t
|
static size_t
|
||||||
pn71xx_scan(const nfc_context *context, nfc_connstring connstrings[], const size_t connstrings_len)
|
pn71xx_scan(const nfc_context *context, nfc_connstring connstrings[], const size_t connstrings_len)
|
||||||
{
|
{
|
||||||
size_t device_found = 0;
|
size_t device_found = 0;
|
||||||
|
|
||||||
if ((context == NULL) || (connstrings_len == 0)) return 0;
|
if ((context == NULL) || (connstrings_len == 0)) return 0;
|
||||||
|
|
||||||
if (nfcManager_doInitialize() == 0) {
|
if (nfcManager_doInitialize() == 0) {
|
||||||
nfc_connstring connstring = "pn71xx";
|
nfc_connstring connstring = "pn71xx";
|
||||||
memcpy(connstrings[device_found++], connstring, sizeof(nfc_connstring));
|
memcpy(connstrings[device_found++], connstring, sizeof(nfc_connstring));
|
||||||
}
|
}
|
||||||
|
|
||||||
return device_found;
|
return device_found;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -77,12 +77,12 @@ pn71xx_scan(const nfc_context *context, nfc_connstring connstrings[], const size
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
pn71xx_close(nfc_device *pnd)
|
pn71xx_close(nfc_device *pnd)
|
||||||
{
|
{
|
||||||
nfcManager_disableDiscovery();
|
nfcManager_disableDiscovery();
|
||||||
nfcManager_deregisterTagCallback();
|
nfcManager_deregisterTagCallback();
|
||||||
nfcManager_doDeinitialize();
|
nfcManager_doDeinitialize();
|
||||||
nfc_device_free(pnd);
|
nfc_device_free(pnd);
|
||||||
pnd = NULL;
|
pnd = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -95,157 +95,150 @@ pn71xx_close(nfc_device *pnd)
|
||||||
static nfc_device *
|
static nfc_device *
|
||||||
pn71xx_open(const nfc_context *context, const nfc_connstring connstring)
|
pn71xx_open(const nfc_context *context, const nfc_connstring connstring)
|
||||||
{
|
{
|
||||||
nfc_device *pnd;
|
nfc_device *pnd;
|
||||||
|
|
||||||
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "open: %s", connstring);
|
|
||||||
|
|
||||||
pnd = nfc_device_new(context, connstring);
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "open: %s", connstring);
|
||||||
if (!pnd) {
|
|
||||||
perror("malloc");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
pnd->driver = &pn71xx_driver;
|
pnd = nfc_device_new(context, connstring);
|
||||||
strcpy(pnd->name, "pn71xx-device");
|
if (!pnd) {
|
||||||
strcpy(pnd->connstring, connstring);
|
perror("malloc");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
TagCB.onTagArrival = onTagArrival;
|
pnd->driver = &pn71xx_driver;
|
||||||
TagCB.onTagDeparture = onTagDeparture;
|
strcpy(pnd->name, "pn71xx-device");
|
||||||
nfcManager_registerTagCallback(&TagCB);
|
strcpy(pnd->connstring, connstring);
|
||||||
|
|
||||||
nfcManager_enableDiscovery(DEFAULT_NFA_TECH_MASK, 1, 0, 0);
|
TagCB.onTagArrival = onTagArrival;
|
||||||
|
TagCB.onTagDeparture = onTagDeparture;
|
||||||
|
nfcManager_registerTagCallback(&TagCB);
|
||||||
|
|
||||||
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "wait 1 seconds for polling");
|
nfcManager_enableDiscovery(DEFAULT_NFA_TECH_MASK, 1, 0, 0);
|
||||||
sleep(1);
|
|
||||||
|
|
||||||
return pnd;
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "wait 1 seconds for polling");
|
||||||
|
sleep(1);
|
||||||
|
|
||||||
|
return pnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** ------------------------------------------------------------------------ */
|
/** ------------------------------------------------------------------------ */
|
||||||
/** ------------------------------------------------------------------------ */
|
/** ------------------------------------------------------------------------ */
|
||||||
static bool IsTechnology(nfc_tag_info_t *TagInfo, nfc_modulation_type nmt)
|
static bool IsTechnology(nfc_tag_info_t *TagInfo, nfc_modulation_type nmt)
|
||||||
{
|
{
|
||||||
switch (nmt) {
|
switch (nmt) {
|
||||||
case NMT_ISO14443A:
|
case NMT_ISO14443A:
|
||||||
if (TagInfo->technology == TARGET_TYPE_ISO14443_4
|
if (TagInfo->technology == TARGET_TYPE_ISO14443_4
|
||||||
|| TagInfo->technology == TARGET_TYPE_ISO14443_3A
|
|| TagInfo->technology == TARGET_TYPE_ISO14443_3A
|
||||||
|| TagInfo->technology == TARGET_TYPE_MIFARE_CLASSIC
|
|| TagInfo->technology == TARGET_TYPE_MIFARE_CLASSIC
|
||||||
|| TagInfo->technology == TARGET_TYPE_MIFARE_UL)
|
|| TagInfo->technology == TARGET_TYPE_MIFARE_UL)
|
||||||
return true;
|
return true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NMT_ISO14443B:
|
case NMT_ISO14443B:
|
||||||
case NMT_ISO14443BI:
|
case NMT_ISO14443BI:
|
||||||
case NMT_ISO14443B2SR:
|
case NMT_ISO14443B2SR:
|
||||||
case NMT_ISO14443B2CT:
|
case NMT_ISO14443B2CT:
|
||||||
if (TagInfo->technology == TARGET_TYPE_ISO14443_3B)
|
if (TagInfo->technology == TARGET_TYPE_ISO14443_3B)
|
||||||
return true;
|
return true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NMT_FELICA:
|
case NMT_FELICA:
|
||||||
if (TagInfo->technology == TARGET_TYPE_FELICA)
|
if (TagInfo->technology == TARGET_TYPE_FELICA)
|
||||||
return true;
|
return true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NMT_JEWEL:
|
case NMT_JEWEL:
|
||||||
if (TagInfo->technology == TARGET_TYPE_ISO14443_3A
|
if (TagInfo->technology == TARGET_TYPE_ISO14443_3A
|
||||||
&& TagInfo->protocol == NFA_PROTOCOL_T1T)
|
&& TagInfo->protocol == NFA_PROTOCOL_T1T)
|
||||||
return true;
|
return true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return false;
|
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;
|
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]);
|
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)
|
switch (TagInfo->technology) {
|
||||||
{
|
case TARGET_TYPE_UNKNOWN: {
|
||||||
case TARGET_TYPE_UNKNOWN:
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type Unknown'");
|
||||||
{
|
}
|
||||||
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type Unknown'");
|
break;
|
||||||
} break;
|
case TARGET_TYPE_ISO14443_3A: {
|
||||||
case TARGET_TYPE_ISO14443_3A:
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type 3A'");
|
||||||
{
|
}
|
||||||
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type 3A'");
|
break;
|
||||||
} break;
|
case TARGET_TYPE_ISO14443_3B: {
|
||||||
case TARGET_TYPE_ISO14443_3B:
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type 3B'");
|
||||||
{
|
}
|
||||||
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type 3B'");
|
break;
|
||||||
} break;
|
case TARGET_TYPE_ISO14443_4: {
|
||||||
case TARGET_TYPE_ISO14443_4:
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type 4A'");
|
||||||
{
|
}
|
||||||
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type 4A'");
|
break;
|
||||||
} break;
|
case TARGET_TYPE_FELICA: {
|
||||||
case TARGET_TYPE_FELICA:
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type F'");
|
||||||
{
|
}
|
||||||
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type F'");
|
break;
|
||||||
} break;
|
case TARGET_TYPE_ISO15693: {
|
||||||
case TARGET_TYPE_ISO15693:
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type V'");
|
||||||
{
|
}
|
||||||
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type V'");
|
break;
|
||||||
} break;
|
case TARGET_TYPE_NDEF: {
|
||||||
case TARGET_TYPE_NDEF:
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type NDEF'");
|
||||||
{
|
}
|
||||||
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type NDEF'");
|
break;
|
||||||
} break;
|
case TARGET_TYPE_NDEF_FORMATABLE: {
|
||||||
case TARGET_TYPE_NDEF_FORMATABLE:
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type Formatable'");
|
||||||
{
|
}
|
||||||
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type Formatable'");
|
break;
|
||||||
} break;
|
case TARGET_TYPE_MIFARE_CLASSIC: {
|
||||||
case TARGET_TYPE_MIFARE_CLASSIC:
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type A - Mifare Classic'");
|
||||||
{
|
}
|
||||||
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type A - Mifare Classic'");
|
break;
|
||||||
} break;
|
case TARGET_TYPE_MIFARE_UL: {
|
||||||
case TARGET_TYPE_MIFARE_UL:
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type A - Mifare Ul'");
|
||||||
{
|
}
|
||||||
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type A - Mifare Ul'");
|
break;
|
||||||
} break;
|
case TARGET_TYPE_KOVIO_BARCODE: {
|
||||||
case TARGET_TYPE_KOVIO_BARCODE:
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type A - Kovio Barcode'");
|
||||||
{
|
}
|
||||||
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type A - Kovio Barcode'");
|
break;
|
||||||
} break;
|
case TARGET_TYPE_ISO14443_3A_3B: {
|
||||||
case TARGET_TYPE_ISO14443_3A_3B:
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type A/B'");
|
||||||
{
|
}
|
||||||
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type A/B'");
|
break;
|
||||||
} break;
|
default: {
|
||||||
default:
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type %d (Unknown or not supported)'\n", TagInfo->technology);
|
||||||
{
|
}
|
||||||
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)*/
|
||||||
/*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;
|
||||||
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'");
|
||||||
cx += snprintf(buffer + cx, sizeof(buffer) - cx, "NFCID1 : \t'");
|
} else if (8 == TagInfo->uid_length) {
|
||||||
}
|
cx += snprintf(buffer + cx, sizeof(buffer) - cx, "NFCID2 : \t'");
|
||||||
else if(8 == TagInfo->uid_length)
|
} else {
|
||||||
{
|
cx += snprintf(buffer + cx, sizeof(buffer) - cx, "UID : \t'");
|
||||||
cx += snprintf(buffer + cx, sizeof(buffer) - cx, "NFCID2 : \t'");
|
}
|
||||||
}
|
|
||||||
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);
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s'", buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** ------------------------------------------------------------------------ */
|
/** ------------------------------------------------------------------------ */
|
||||||
|
@ -253,194 +246,194 @@ static void PrintTagInfo (nfc_tag_info_t *TagInfo)
|
||||||
|
|
||||||
static void onTagArrival(nfc_tag_info_t *pTagInfo)
|
static void onTagArrival(nfc_tag_info_t *pTagInfo)
|
||||||
{
|
{
|
||||||
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "tag found");
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "tag found");
|
||||||
|
|
||||||
TagInfo = malloc(sizeof(nfc_tag_info_t));
|
TagInfo = malloc(sizeof(nfc_tag_info_t));
|
||||||
memcpy(TagInfo, pTagInfo, sizeof(nfc_tag_info_t));
|
memcpy(TagInfo, pTagInfo, sizeof(nfc_tag_info_t));
|
||||||
|
|
||||||
PrintTagInfo(TagInfo);
|
PrintTagInfo(TagInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void onTagDeparture(void)
|
static void onTagDeparture(void)
|
||||||
{
|
{
|
||||||
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "tag lost");
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "tag lost");
|
||||||
|
|
||||||
free(TagInfo);
|
free(TagInfo);
|
||||||
TagInfo = NULL;
|
TagInfo = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
pn71xx_initiator_init(struct nfc_device *pnd)
|
pn71xx_initiator_init(struct nfc_device *pnd)
|
||||||
{
|
{
|
||||||
if (pnd == NULL) return NFC_EIO;
|
if (pnd == NULL) return NFC_EIO;
|
||||||
return NFC_SUCCESS;
|
return NFC_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
pn71xx_initiator_select_passive_target(struct nfc_device *pnd,
|
pn71xx_initiator_select_passive_target(struct nfc_device *pnd,
|
||||||
const nfc_modulation nm,
|
const nfc_modulation nm,
|
||||||
const uint8_t *pbtInitData, const size_t szInitData,
|
const uint8_t *pbtInitData, const size_t szInitData,
|
||||||
nfc_target *pnt)
|
nfc_target *pnt)
|
||||||
{
|
{
|
||||||
if (pnd == NULL) return NFC_EIO;
|
if (pnd == NULL) return NFC_EIO;
|
||||||
|
|
||||||
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "select_passive_target");
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "select_passive_target");
|
||||||
|
|
||||||
if (TagInfo) {
|
if (TagInfo) {
|
||||||
|
|
||||||
nfc_target nttmp;
|
nfc_target nttmp;
|
||||||
memset(&nttmp, 0x00, sizeof(nfc_target));
|
memset(&nttmp, 0x00, sizeof(nfc_target));
|
||||||
nttmp.nm = nm;
|
nttmp.nm = nm;
|
||||||
|
|
||||||
void* uidPtr = NULL;
|
void *uidPtr = NULL;
|
||||||
unsigned int maxLen = 0;
|
unsigned int maxLen = 0;
|
||||||
|
|
||||||
switch (nm.nmt) {
|
switch (nm.nmt) {
|
||||||
case NMT_ISO14443A:
|
case NMT_ISO14443A:
|
||||||
if (IsTechnology(TagInfo, nm.nmt)) {
|
if (IsTechnology(TagInfo, nm.nmt)) {
|
||||||
maxLen = 10;
|
maxLen = 10;
|
||||||
uidPtr = nttmp.nti.nai.abtUid;
|
uidPtr = nttmp.nti.nai.abtUid;
|
||||||
|
|
||||||
if (TagInfo->technology == TARGET_TYPE_MIFARE_CLASSIC) {
|
if (TagInfo->technology == TARGET_TYPE_MIFARE_CLASSIC) {
|
||||||
nttmp.nti.nai.btSak = 0x08;
|
nttmp.nti.nai.btSak = 0x08;
|
||||||
} else {
|
} else {
|
||||||
// make hardcoded desfire for freefare lib check
|
// make hardcoded desfire for freefare lib check
|
||||||
nttmp.nti.nai.btSak = 0x20;
|
nttmp.nti.nai.btSak = 0x20;
|
||||||
nttmp.nti.nai.szAtsLen = 5;
|
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;
|
break;
|
||||||
|
|
||||||
case NMT_ISO14443B:
|
case NMT_ISO14443B:
|
||||||
if (IsTechnology(TagInfo, nm.nmt)) {
|
if (IsTechnology(TagInfo, nm.nmt)) {
|
||||||
maxLen = 4;
|
maxLen = 4;
|
||||||
uidPtr = nttmp.nti.nbi.abtPupi;
|
uidPtr = nttmp.nti.nbi.abtPupi;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NMT_ISO14443BI:
|
case NMT_ISO14443BI:
|
||||||
if (IsTechnology(TagInfo, nm.nmt)) {
|
if (IsTechnology(TagInfo, nm.nmt)) {
|
||||||
maxLen = 4;
|
maxLen = 4;
|
||||||
uidPtr = nttmp.nti.nii.abtDIV;
|
uidPtr = nttmp.nti.nii.abtDIV;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NMT_ISO14443B2SR:
|
case NMT_ISO14443B2SR:
|
||||||
if (IsTechnology(TagInfo, nm.nmt)) {
|
if (IsTechnology(TagInfo, nm.nmt)) {
|
||||||
maxLen = 8;
|
maxLen = 8;
|
||||||
uidPtr = nttmp.nti.nsi.abtUID;
|
uidPtr = nttmp.nti.nsi.abtUID;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NMT_ISO14443B2CT:
|
case NMT_ISO14443B2CT:
|
||||||
if (IsTechnology(TagInfo, nm.nmt)) {
|
if (IsTechnology(TagInfo, nm.nmt)) {
|
||||||
maxLen = 4;
|
maxLen = 4;
|
||||||
uidPtr = nttmp.nti.nci.abtUID;
|
uidPtr = nttmp.nti.nci.abtUID;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NMT_FELICA:
|
case NMT_FELICA:
|
||||||
if (IsTechnology(TagInfo, nm.nmt)) {
|
if (IsTechnology(TagInfo, nm.nmt)) {
|
||||||
maxLen = 8;
|
maxLen = 8;
|
||||||
uidPtr = nttmp.nti.nfi.abtId;
|
uidPtr = nttmp.nti.nfi.abtId;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NMT_JEWEL:
|
case NMT_JEWEL:
|
||||||
if (IsTechnology(TagInfo, nm.nmt)) {
|
if (IsTechnology(TagInfo, nm.nmt)) {
|
||||||
maxLen = 4;
|
maxLen = 4;
|
||||||
uidPtr = nttmp.nti.nji.btId;
|
uidPtr = nttmp.nti.nji.btId;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uidPtr && TagInfo->uid_length) {
|
if (uidPtr && TagInfo->uid_length) {
|
||||||
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "target found");
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "target found");
|
||||||
int len = TagInfo->uid_length > maxLen ? maxLen : TagInfo->uid_length;
|
int len = TagInfo->uid_length > maxLen ? maxLen : TagInfo->uid_length;
|
||||||
memcpy(uidPtr, TagInfo->uid, len);
|
memcpy(uidPtr, TagInfo->uid, len);
|
||||||
if (nm.nmt == NMT_ISO14443A)
|
if (nm.nmt == NMT_ISO14443A)
|
||||||
nttmp.nti.nai.szUidLen = len;
|
nttmp.nti.nai.szUidLen = len;
|
||||||
|
|
||||||
// Is a tag info struct available
|
// Is a tag info struct available
|
||||||
if (pnt) {
|
if (pnt) {
|
||||||
memcpy(pnt, &nttmp, sizeof(nfc_target));
|
memcpy(pnt, &nttmp, sizeof(nfc_target));
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
pn71xx_initiator_deselect_target(struct nfc_device *pnd)
|
pn71xx_initiator_deselect_target(struct nfc_device *pnd)
|
||||||
{
|
{
|
||||||
if (pnd == NULL) return NFC_EIO;
|
if (pnd == NULL) return NFC_EIO;
|
||||||
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "deselect_passive_target");
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "deselect_passive_target");
|
||||||
return NFC_SUCCESS;
|
return NFC_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
pn71xx_initiator_transceive_bytes(struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, uint8_t *pbtRx,
|
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;
|
if (pnd == NULL) return NFC_EIO;
|
||||||
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "transceive_bytes timeout=%d", timeout);
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "transceive_bytes timeout=%d", timeout);
|
||||||
|
|
||||||
if (!TagInfo) return NFC_EINVARG;
|
if (!TagInfo) return NFC_EINVARG;
|
||||||
|
|
||||||
char buffer[500];
|
char buffer[500];
|
||||||
BufferPrintBytes(buffer, sizeof(buffer), pbtTx, szTx);
|
BufferPrintBytes(buffer, sizeof(buffer), pbtTx, szTx);
|
||||||
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "===> %s", buffer);
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "===> %s", buffer);
|
||||||
|
|
||||||
int received = nfcTag_transceive(TagInfo->handle, (uint8_t *) pbtTx, szTx, pbtRx, szRx, 500);
|
int received = nfcTag_transceive(TagInfo->handle, (uint8_t *) pbtTx, szTx, pbtRx, szRx, 500);
|
||||||
if (received <= 0)
|
if (received <= 0)
|
||||||
return NFC_EIO;
|
return NFC_EIO;
|
||||||
|
|
||||||
BufferPrintBytes(buffer, sizeof(buffer), pbtRx, received);
|
BufferPrintBytes(buffer, sizeof(buffer), pbtRx, received);
|
||||||
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "<=== %s", buffer);
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "<=== %s", buffer);
|
||||||
|
|
||||||
return received;
|
return received;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
pn71xx_initiator_poll_target(struct nfc_device *pnd,
|
pn71xx_initiator_poll_target(struct nfc_device *pnd,
|
||||||
const nfc_modulation *pnmModulations, const size_t szModulations,
|
const nfc_modulation *pnmModulations, const size_t szModulations,
|
||||||
const uint8_t uiPollNr, const uint8_t uiPeriod,
|
const uint8_t uiPollNr, const uint8_t uiPeriod,
|
||||||
nfc_target *pnt)
|
nfc_target *pnt)
|
||||||
{
|
{
|
||||||
static int periodFactor = 150000;
|
static int periodFactor = 150000;
|
||||||
int period = uiPeriod * periodFactor;
|
int period = uiPeriod * periodFactor;
|
||||||
|
|
||||||
if (pnd == NULL) return 0;
|
if (pnd == NULL) return 0;
|
||||||
|
|
||||||
for (int j = 0; j < uiPollNr; j++) {
|
for (int j = 0; j < uiPollNr; j++) {
|
||||||
for (unsigned int i = 0; i < szModulations; i++) {
|
for (unsigned int i = 0; i < szModulations; i++) {
|
||||||
const nfc_modulation nm = pnmModulations[i];
|
const nfc_modulation nm = pnmModulations[i];
|
||||||
|
|
||||||
nfc_target nt;
|
|
||||||
int res = pn71xx_initiator_select_passive_target(pnd, nm, 0, 0, &nt);
|
|
||||||
if (res > 0 && pnt) {
|
|
||||||
memcpy(pnt, &nt, sizeof(nfc_target));
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
usleep(period);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
nfc_target nt;
|
||||||
|
int res = pn71xx_initiator_select_passive_target(pnd, nm, 0, 0, &nt);
|
||||||
|
if (res > 0 && pnt) {
|
||||||
|
memcpy(pnt, &nt, sizeof(nfc_target));
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
usleep(period);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
pn71xx_initiator_target_is_present(struct nfc_device *pnd, const nfc_target *pnt)
|
pn71xx_initiator_target_is_present(struct nfc_device *pnd, const nfc_target *pnt)
|
||||||
{
|
{
|
||||||
if ((pnd == NULL) || (pnt == NULL)) return 1;
|
if ((pnd == NULL) || (pnt == NULL)) return 1;
|
||||||
return !TagInfo;
|
return !TagInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -449,17 +442,17 @@ pn71xx_initiator_target_is_present(struct nfc_device *pnd, const nfc_target *pnt
|
||||||
static int
|
static int
|
||||||
pn71xx_get_supported_modulation(nfc_device *pnd, const nfc_mode mode, const nfc_modulation_type **const supported_mt)
|
pn71xx_get_supported_modulation(nfc_device *pnd, const nfc_mode mode, const nfc_modulation_type **const supported_mt)
|
||||||
{
|
{
|
||||||
if (pnd == NULL) return NFC_EIO;
|
if (pnd == NULL) return NFC_EIO;
|
||||||
|
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case N_TARGET:
|
case N_TARGET:
|
||||||
*supported_mt = (nfc_modulation_type *)pn71xx_supported_modulation_as_target;
|
*supported_mt = (nfc_modulation_type *)pn71xx_supported_modulation_as_target;
|
||||||
break;
|
break;
|
||||||
case N_INITIATOR:
|
case N_INITIATOR:
|
||||||
*supported_mt = (nfc_modulation_type *)pn71xx_supported_modulation_as_initiator;
|
*supported_mt = (nfc_modulation_type *)pn71xx_supported_modulation_as_initiator;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return NFC_EINVARG;
|
return NFC_EINVARG;
|
||||||
}
|
}
|
||||||
return NFC_SUCCESS;
|
return NFC_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -467,32 +460,32 @@ pn71xx_get_supported_modulation(nfc_device *pnd, const nfc_mode mode, const nfc_
|
||||||
static int
|
static int
|
||||||
pn71xx_get_supported_baud_rate(nfc_device *pnd, const nfc_mode mode, const nfc_modulation_type nmt, const nfc_baud_rate **const supported_br)
|
pn71xx_get_supported_baud_rate(nfc_device *pnd, const nfc_mode mode, const nfc_modulation_type nmt, const nfc_baud_rate **const supported_br)
|
||||||
{
|
{
|
||||||
if (pnd == NULL) return NFC_EIO;
|
if (pnd == NULL) return NFC_EIO;
|
||||||
if (mode) {}
|
if (mode) {}
|
||||||
|
|
||||||
switch (nmt) {
|
switch (nmt) {
|
||||||
case NMT_FELICA:
|
case NMT_FELICA:
|
||||||
*supported_br = (nfc_baud_rate *)pn71xx_felica_supported_baud_rates;
|
*supported_br = (nfc_baud_rate *)pn71xx_felica_supported_baud_rates;
|
||||||
break;
|
break;
|
||||||
case NMT_ISO14443A:
|
case NMT_ISO14443A:
|
||||||
*supported_br = (nfc_baud_rate *)pn71xx_iso14443a_supported_baud_rates;
|
*supported_br = (nfc_baud_rate *)pn71xx_iso14443a_supported_baud_rates;
|
||||||
break;
|
break;
|
||||||
case NMT_ISO14443B:
|
case NMT_ISO14443B:
|
||||||
case NMT_ISO14443BI:
|
case NMT_ISO14443BI:
|
||||||
case NMT_ISO14443B2SR:
|
case NMT_ISO14443B2SR:
|
||||||
case NMT_ISO14443B2CT:
|
case NMT_ISO14443B2CT:
|
||||||
*supported_br = (nfc_baud_rate *)pn71xx_iso14443b_supported_baud_rates;
|
*supported_br = (nfc_baud_rate *)pn71xx_iso14443b_supported_baud_rates;
|
||||||
break;
|
break;
|
||||||
case NMT_JEWEL:
|
case NMT_JEWEL:
|
||||||
*supported_br = (nfc_baud_rate *)pn71xx_jewel_supported_baud_rates;
|
*supported_br = (nfc_baud_rate *)pn71xx_jewel_supported_baud_rates;
|
||||||
break;
|
break;
|
||||||
case NMT_DEP:
|
case NMT_DEP:
|
||||||
*supported_br = (nfc_baud_rate *)pn71xx_dep_supported_baud_rates;
|
*supported_br = (nfc_baud_rate *)pn71xx_dep_supported_baud_rates;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return NFC_EINVARG;
|
return NFC_EINVARG;
|
||||||
}
|
}
|
||||||
return NFC_SUCCESS;
|
return NFC_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** ------------------------------------------------------------------------ */
|
/** ------------------------------------------------------------------------ */
|
||||||
|
@ -501,29 +494,29 @@ pn71xx_get_supported_baud_rate(nfc_device *pnd, const nfc_mode mode, const nfc_m
|
||||||
static int
|
static int
|
||||||
pn71xx_set_property_bool(struct nfc_device *pnd, const nfc_property property, const bool bEnable)
|
pn71xx_set_property_bool(struct nfc_device *pnd, const nfc_property property, const bool bEnable)
|
||||||
{
|
{
|
||||||
if (pnd == NULL) return NFC_EIO;
|
if (pnd == NULL) return NFC_EIO;
|
||||||
return NFC_SUCCESS;
|
return NFC_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
pn71xx_set_property_int(struct nfc_device *pnd, const nfc_property property, const int value)
|
pn71xx_set_property_int(struct nfc_device *pnd, const nfc_property property, const int value)
|
||||||
{
|
{
|
||||||
if (pnd == NULL) return NFC_EIO;
|
if (pnd == NULL) return NFC_EIO;
|
||||||
return NFC_SUCCESS;
|
return NFC_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
pn71xx_get_information_about(nfc_device *pnd, char **pbuf)
|
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;
|
size_t buflen = strlen(info) + 1;
|
||||||
|
|
||||||
if (pnd == NULL) return NFC_EIO;
|
if (pnd == NULL) return NFC_EIO;
|
||||||
|
|
||||||
*pbuf = malloc(buflen);
|
|
||||||
memcpy(*pbuf, info, buflen);
|
|
||||||
|
|
||||||
return buflen;
|
*pbuf = malloc(buflen);
|
||||||
|
memcpy(*pbuf, info, buflen);
|
||||||
|
|
||||||
|
return buflen;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @brief Abort any pending operation
|
* @brief Abort any pending operation
|
||||||
|
@ -534,25 +527,25 @@ pn71xx_get_information_about(nfc_device *pnd, char **pbuf)
|
||||||
static int
|
static int
|
||||||
pn71xx_abort_command(nfc_device *pnd)
|
pn71xx_abort_command(nfc_device *pnd)
|
||||||
{
|
{
|
||||||
if (pnd == NULL) return NFC_EIO;
|
if (pnd == NULL) return NFC_EIO;
|
||||||
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "abort_command");
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "abort_command");
|
||||||
return NFC_SUCCESS;
|
return NFC_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
pn71xx_idle(struct nfc_device *pnd)
|
pn71xx_idle(struct nfc_device *pnd)
|
||||||
{
|
{
|
||||||
if (pnd == NULL) return NFC_EIO;
|
if (pnd == NULL) return NFC_EIO;
|
||||||
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "idle");
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "idle");
|
||||||
return NFC_SUCCESS;
|
return NFC_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
pn71xx_PowerDown(struct nfc_device *pnd)
|
pn71xx_PowerDown(struct nfc_device *pnd)
|
||||||
{
|
{
|
||||||
if (pnd == NULL) return NFC_EIO;
|
if (pnd == NULL) return NFC_EIO;
|
||||||
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "PowerDown");
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "PowerDown");
|
||||||
return NFC_SUCCESS;
|
return NFC_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** ------------------------------------------------------------------------ */
|
/** ------------------------------------------------------------------------ */
|
||||||
|
|
|
@ -174,17 +174,17 @@ prepare_initiator_data(const nfc_modulation nm, uint8_t **ppbtInitiatorData, siz
|
||||||
// Application Family Identifier (AFI) must equals 0x00 in order to wakeup all ISO14443-B PICCs (see ISO/IEC 14443-3)
|
// Application Family Identifier (AFI) must equals 0x00 in order to wakeup all ISO14443-B PICCs (see ISO/IEC 14443-3)
|
||||||
*ppbtInitiatorData = (uint8_t *) "\x00";
|
*ppbtInitiatorData = (uint8_t *) "\x00";
|
||||||
*pszInitiatorData = 1;
|
*pszInitiatorData = 1;
|
||||||
break;
|
break;
|
||||||
case NMT_ISO14443BI:
|
case NMT_ISO14443BI:
|
||||||
// APGEN
|
// APGEN
|
||||||
*ppbtInitiatorData = (uint8_t *) "\x01\x0b\x3f\x80";
|
*ppbtInitiatorData = (uint8_t *) "\x01\x0b\x3f\x80";
|
||||||
*pszInitiatorData = 4;
|
*pszInitiatorData = 4;
|
||||||
break;
|
break;
|
||||||
case NMT_FELICA:
|
case NMT_FELICA:
|
||||||
// polling payload must be present (see ISO/IEC 18092 11.2.2.5)
|
// polling payload must be present (see ISO/IEC 18092 11.2.2.5)
|
||||||
*ppbtInitiatorData = (uint8_t *) "\x00\xff\xff\x01\x00";
|
*ppbtInitiatorData = (uint8_t *) "\x00\xff\xff\x01\x00";
|
||||||
*pszInitiatorData = 5;
|
*pszInitiatorData = 5;
|
||||||
break;
|
break;
|
||||||
case NMT_ISO14443A:
|
case NMT_ISO14443A:
|
||||||
case NMT_ISO14443B2CT:
|
case NMT_ISO14443B2CT:
|
||||||
case NMT_ISO14443B2SR:
|
case NMT_ISO14443B2SR:
|
||||||
|
|
|
@ -140,7 +140,7 @@ struct nfc_driver_list {
|
||||||
const struct nfc_driver_list *nfc_drivers = NULL;
|
const struct nfc_driver_list *nfc_drivers = NULL;
|
||||||
|
|
||||||
// descritions for debugging
|
// descritions for debugging
|
||||||
const char * nfc_property_name[] = {
|
const char *nfc_property_name[] = {
|
||||||
"NP_TIMEOUT_COMMAND",
|
"NP_TIMEOUT_COMMAND",
|
||||||
"NP_TIMEOUT_ATR",
|
"NP_TIMEOUT_ATR",
|
||||||
"NP_TIMEOUT_COM",
|
"NP_TIMEOUT_COM",
|
||||||
|
@ -206,8 +206,7 @@ nfc_device_validate_modulation(nfc_device *pnd, const nfc_mode mode, const nfc_m
|
||||||
int
|
int
|
||||||
nfc_register_driver(const struct nfc_driver *ndr)
|
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");
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "nfc_register_driver returning NFC_EINVARG");
|
||||||
return NFC_EINVARG;
|
return NFC_EINVARG;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
* See AUTHORS file for a more comprehensive list of contributors.
|
* See AUTHORS file for a more comprehensive list of contributors.
|
||||||
* Additional contributors of this file:
|
* Additional contributors of this file:
|
||||||
* Copyright (C) 2011-2013 Adam Laurie
|
* Copyright (C) 2011-2013 Adam Laurie
|
||||||
* Copyright (C) 2018-2019 Danielle Bruneo
|
* Copyright (C) 2018-2019 Danielle Bruneo
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
@ -218,9 +218,9 @@ authenticate(uint32_t uiBlock)
|
||||||
|
|
||||||
// Try to authenticate for the current sector
|
// Try to authenticate for the current sector
|
||||||
if (nfc_initiator_mifare_cmd(pnd, mc, uiBlock, &mp)) {
|
if (nfc_initiator_mifare_cmd(pnd, mc, uiBlock, &mp)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// If formatting or not using key file, try to guess the right key
|
// If formatting or not using key file, try to guess the right key
|
||||||
} else if (bFormatCard || !bUseKeyFile) {
|
} else if (bFormatCard || !bUseKeyFile) {
|
||||||
for (size_t key_index = 0; key_index < num_keys; key_index++) {
|
for (size_t key_index = 0; key_index < num_keys; key_index++) {
|
||||||
memcpy(mp.mpa.abtKey, keys + (key_index * 6), 6);
|
memcpy(mp.mpa.abtKey, keys + (key_index * 6), 6);
|
||||||
|
@ -494,7 +494,7 @@ write_card(int write_block_zero)
|
||||||
bFailure = true;
|
bFailure = true;
|
||||||
printf("Failure to write to data block %i\n", uiBlock);
|
printf("Failure to write to data block %i\n", uiBlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
printf("Failure during write process.\n");
|
printf("Failure during write process.\n");
|
||||||
}
|
}
|
||||||
|
@ -510,19 +510,19 @@ write_card(int write_block_zero)
|
||||||
if (write_block_zero || magic2 || magic3) {
|
if (write_block_zero || magic2 || magic3) {
|
||||||
for (uiBlock = 0; uiBlock < 4; uiBlock++) {
|
for (uiBlock = 0; uiBlock < 4; uiBlock++) {
|
||||||
|
|
||||||
// The first block 0x00 is read only, skip this
|
// The first block 0x00 is read only, skip this
|
||||||
if (uiBlock == 0) {
|
if (uiBlock == 0) {
|
||||||
//If the card is not magic, we're gonna skip over
|
//If the card is not magic, we're gonna skip over
|
||||||
if (write_block_zero || magic2 || magic3) {
|
if (write_block_zero || magic2 || magic3) {
|
||||||
//NOP
|
//NOP
|
||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_first_block(uiBlock)) {
|
if (is_first_block(uiBlock)) {
|
||||||
if (bFailure) {
|
if (bFailure) {
|
||||||
// When a failure occured we need to redo the anti-collision
|
// When a failure occured we need to redo the anti-collision
|
||||||
if (nfc_initiator_select_passive_target(pnd, nmMifare, NULL, 0, &nt) <= 0) {
|
if (nfc_initiator_select_passive_target(pnd, nmMifare, NULL, 0, &nt) <= 0) {
|
||||||
printf("!\nError: tag was removed\n");
|
printf("!\nError: tag was removed\n");
|
||||||
return false;
|
return false;
|
||||||
|
@ -530,27 +530,27 @@ write_card(int write_block_zero)
|
||||||
bFailure = false;
|
bFailure = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
// Try to authenticate for the current sector
|
// Try to authenticate for the current sector
|
||||||
// If we are are writing to a chinese magic card, we've already unlocked
|
// If we are are writing to a chinese magic card, we've already unlocked
|
||||||
// If we're writing to a One Time Write, we need to authenticate
|
// If we're writing to a One Time Write, we need to authenticate
|
||||||
// If we're writing something else, we'll need to authenticate
|
// If we're writing something else, we'll need to authenticate
|
||||||
if ((write_block_zero && magic3) || !write_block_zero) {
|
if ((write_block_zero && magic3) || !write_block_zero) {
|
||||||
if (!authenticate(uiBlock) && !bTolerateFailures) {
|
if (!authenticate(uiBlock) && !bTolerateFailures) {
|
||||||
printf("!\nError: authentication failed for block %02x\n", uiBlock);
|
printf("!\nError: authentication failed for block %02x\n", uiBlock);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure a earlier write did not fail
|
// Make sure a earlier write did not fail
|
||||||
if (!bFailure) {
|
if (!bFailure) {
|
||||||
// Try to write the data block
|
// Try to write the data block
|
||||||
if (bFormatCard && uiBlock)
|
if (bFormatCard && uiBlock)
|
||||||
memset(mp.mpd.abtData, 0x00, sizeof(mp.mpd.abtData));
|
memset(mp.mpd.abtData, 0x00, sizeof(mp.mpd.abtData));
|
||||||
else
|
else
|
||||||
memcpy(mp.mpd.abtData, mtDump.amb[uiBlock].mbd.abtData, sizeof(mp.mpd.abtData));
|
memcpy(mp.mpd.abtData, mtDump.amb[uiBlock].mbd.abtData, sizeof(mp.mpd.abtData));
|
||||||
// do not write a block 0 with incorrect BCC - card will be made invalid!
|
// do not write a block 0 with incorrect BCC - card will be made invalid!
|
||||||
if (uiBlock == 0) {
|
if (uiBlock == 0) {
|
||||||
if ((mp.mpd.abtData[0] ^ mp.mpd.abtData[1] ^ mp.mpd.abtData[2] ^ mp.mpd.abtData[3] ^ mp.mpd.abtData[4]) != 0x00 && !magic2) {
|
if ((mp.mpd.abtData[0] ^ mp.mpd.abtData[1] ^ mp.mpd.abtData[2] ^ mp.mpd.abtData[3] ^ mp.mpd.abtData[4]) != 0x00 && !magic2) {
|
||||||
printf("!\nError: incorrect BCC in MFD file!\n");
|
printf("!\nError: incorrect BCC in MFD file!\n");
|
||||||
|
@ -562,15 +562,15 @@ write_card(int write_block_zero)
|
||||||
bFailure = true;
|
bFailure = true;
|
||||||
printf("Failure to write to data block %i\n", uiBlock);
|
printf("Failure to write to data block %i\n", uiBlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
printf("Failure during write process.\n");
|
printf("Failure during write process.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show if the write went well for each block
|
// Show if the write went well for each block
|
||||||
print_success_or_failure(bFailure, &uiWriteBlocks);
|
print_success_or_failure(bFailure, &uiWriteBlocks);
|
||||||
if ((! bTolerateFailures) && bFailure)
|
if ((! bTolerateFailures) && bFailure)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -620,7 +620,8 @@ print_usage(const char *pcProgramName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool is_directwrite(){
|
bool is_directwrite()
|
||||||
|
{
|
||||||
printf("Checking if Badge is DirectWrite...\n");
|
printf("Checking if Badge is DirectWrite...\n");
|
||||||
|
|
||||||
// Set default keys
|
// Set default keys
|
||||||
|
@ -629,28 +630,28 @@ bool is_directwrite(){
|
||||||
memcpy(mtDump.amb[0].mbt.abtKeyB, default_key, sizeof(default_key));
|
memcpy(mtDump.amb[0].mbt.abtKeyB, default_key, sizeof(default_key));
|
||||||
|
|
||||||
// Temporarly override bUseKeyFile
|
// Temporarly override bUseKeyFile
|
||||||
bool orig_bUseKeyFile=bUseKeyFile;
|
bool orig_bUseKeyFile = bUseKeyFile;
|
||||||
bUseKeyFile=false;
|
bUseKeyFile = false;
|
||||||
// Try to authenticate for the current sector
|
// Try to authenticate for the current sector
|
||||||
if (!authenticate(0)) {
|
if (!authenticate(0)) {
|
||||||
printf("!\nError: authentication failed for block 0x%02x\n", 0);
|
printf("!\nError: authentication failed for block 0x%02x\n", 0);
|
||||||
bUseKeyFile=orig_bUseKeyFile;
|
bUseKeyFile = orig_bUseKeyFile;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// restore bUseKeyFile
|
// restore bUseKeyFile
|
||||||
bUseKeyFile=orig_bUseKeyFile;
|
bUseKeyFile = orig_bUseKeyFile;
|
||||||
|
|
||||||
// Try to read block 0
|
// Try to read block 0
|
||||||
uint8_t original_b0[16];
|
uint8_t original_b0[16];
|
||||||
if (nfc_initiator_mifare_cmd(pnd, MC_READ, 0, &mp)) {
|
if (nfc_initiator_mifare_cmd(pnd, MC_READ, 0, &mp)) {
|
||||||
memcpy(original_b0, mp.mpd.abtData, sizeof(mp.mpd.abtData));
|
memcpy(original_b0, mp.mpd.abtData, sizeof(mp.mpd.abtData));
|
||||||
printf(" Original Block 0: ");
|
printf(" Original Block 0: ");
|
||||||
for(int i=0;i<16;i++){
|
for (int i = 0; i < 16; i++) {
|
||||||
printf("%02x", original_b0[i]);
|
printf("%02x", original_b0[i]);
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf(" Original UID: %02x%02x%02x%02x\n",
|
printf(" Original UID: %02x%02x%02x%02x\n",
|
||||||
original_b0[0], original_b0[1], original_b0[2], original_b0[3]);
|
original_b0[0], original_b0[1], original_b0[2], original_b0[3]);
|
||||||
} else {
|
} else {
|
||||||
printf("!\nError: unable to read block 0x%02x\n", 0);
|
printf("!\nError: unable to read block 0x%02x\n", 0);
|
||||||
return false;
|
return false;
|
||||||
|
@ -845,22 +846,22 @@ main(int argc, const char *argv[])
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
printf("RATS support: no\n");
|
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 size is 4k check for direct-write card
|
||||||
if (uiBlocks == 0xff) {
|
if (uiBlocks == 0xff) {
|
||||||
if (is_directwrite()){
|
if (is_directwrite()) {
|
||||||
printf("Card is DirectWrite\n");
|
printf("Card is DirectWrite\n");
|
||||||
magic3=true;
|
magic3 = true;
|
||||||
unlock=0;
|
unlock = 0;
|
||||||
} else {
|
} else {
|
||||||
printf("Card is not DirectWrite\n");
|
printf("Card is not DirectWrite\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Check to see if we have a One Time Write badge (magic3)
|
//Check to see if we have a One Time Write badge (magic3)
|
||||||
if (pbtUID[0] == 0xaa && pbtUID[1] == 0x55 &&
|
if (pbtUID[0] == 0xaa && pbtUID[1] == 0x55 &&
|
||||||
pbtUID[2] == 0xc3 && pbtUID[3] == 0x96) {
|
pbtUID[2] == 0xc3 && pbtUID[3] == 0x96) {
|
||||||
printf("Card appears to be a One Time Write Card..\n");
|
printf("Card appears to be a One Time Write Card..\n");
|
||||||
magic3 = true;
|
magic3 = true;
|
||||||
unlock = 0;
|
unlock = 0;
|
||||||
|
|
|
@ -300,12 +300,12 @@ static bool check_magic(void)
|
||||||
if (nfc_initiator_mifare_cmd(pnd, MC_READ, 0, &mp)) {
|
if (nfc_initiator_mifare_cmd(pnd, MC_READ, 0, &mp)) {
|
||||||
memcpy(original_b0, mp.mpd.abtData, 12);
|
memcpy(original_b0, mp.mpd.abtData, 12);
|
||||||
printf(" Original Block 0 (Pages 0-2): ");
|
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("%02x", original_b0[i]);
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf(" Original UID: %02x%02x%02x%02x%02x%02x%02x\n",
|
printf(" Original UID: %02x%02x%02x%02x%02x%02x%02x\n",
|
||||||
original_b0[0], original_b0[1], original_b0[2], original_b0[4], original_b0[5], original_b0[6], original_b0[7]);
|
original_b0[0], original_b0[1], original_b0[2], original_b0[4], original_b0[5], original_b0[6], original_b0[7]);
|
||||||
} else {
|
} else {
|
||||||
printf("!\nError: unable to read block 0x%02x\n", 0);
|
printf("!\nError: unable to read block 0x%02x\n", 0);
|
||||||
directWrite = false;
|
directWrite = false;
|
||||||
|
@ -313,8 +313,8 @@ static bool check_magic(void)
|
||||||
printf(" Attempt to write Block 0 (pages 0-2) ...\n");
|
printf(" Attempt to write Block 0 (pages 0-2) ...\n");
|
||||||
for (uint32_t page = 0; page <= 2; page++) {
|
for (uint32_t page = 0; page <= 2; page++) {
|
||||||
printf(" Writing Page %i:", page);
|
printf(" Writing Page %i:", page);
|
||||||
memcpy(mp.mpd.abtData, original_b0 + page*4, 4);
|
memcpy(mp.mpd.abtData, original_b0 + page * 4, 4);
|
||||||
for(int i=0;i<4;i++){
|
for (int i = 0; i < 4; i++) {
|
||||||
printf(" %02x", mp.mpd.abtData[i]);
|
printf(" %02x", mp.mpd.abtData[i]);
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
@ -324,7 +324,7 @@ static bool check_magic(void)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(directWrite){
|
if (directWrite) {
|
||||||
printf(" Block 0 written successfully\n");
|
printf(" Block 0 written successfully\n");
|
||||||
printf("Card is DirectWrite\n");
|
printf("Card is DirectWrite\n");
|
||||||
return true;
|
return true;
|
||||||
|
@ -407,9 +407,9 @@ write_card(bool write_otp, bool write_lock, bool write_dyn_lock, bool write_uid)
|
||||||
}
|
}
|
||||||
// NTAG and MF0UL21 have Dynamic Lock Bytes
|
// NTAG and MF0UL21 have Dynamic Lock Bytes
|
||||||
if (((iEV1Type == EV1_UL21 && page == 0x24) || \
|
if (((iEV1Type == EV1_UL21 && page == 0x24) || \
|
||||||
(iNTAGType == NTAG_213 && page == 0x28) || \
|
(iNTAGType == NTAG_213 && page == 0x28) || \
|
||||||
(iNTAGType == NTAG_215 && page == 0x82) || \
|
(iNTAGType == NTAG_215 && page == 0x82) || \
|
||||||
(iNTAGType == NTAG_216 && page == 0xe2)) && (!write_dyn_lock)) {
|
(iNTAGType == NTAG_216 && page == 0xe2)) && (!write_dyn_lock)) {
|
||||||
printf("s");
|
printf("s");
|
||||||
uiSkippedPages++;
|
uiSkippedPages++;
|
||||||
continue;
|
continue;
|
||||||
|
@ -655,7 +655,7 @@ main(int argc, const char *argv[])
|
||||||
iEV1Type = EV1_UL11;
|
iEV1Type = EV1_UL11;
|
||||||
} else if (abtRx[6] == 0x0e) {
|
} else if (abtRx[6] == 0x0e) {
|
||||||
printf("EV1 type: MF0UL21 (128 user bytes)\n");
|
printf("EV1 type: MF0UL21 (128 user bytes)\n");
|
||||||
uiBlocks = 41;
|
uiBlocks = 41;
|
||||||
iDumpSize = uiBlocks * 4;
|
iDumpSize = uiBlocks * 4;
|
||||||
iEV1Type = EV1_UL21;
|
iEV1Type = EV1_UL21;
|
||||||
} else if (abtRx[6] == 0x0f) {
|
} else if (abtRx[6] == 0x0f) {
|
||||||
|
|
Loading…
Reference in a new issue