Cosmetics changes
This commit is contained in:
parent
7eae55e929
commit
4a10d0f21b
2 changed files with 275 additions and 286 deletions
|
@ -1,134 +0,0 @@
|
||||||
|
|
||||||
#ifndef __NFC_DRIVER_LIBNFC_NCI_H__
|
|
||||||
#define __NFC_DRIVER_LIBNFC_NCI_H__
|
|
||||||
|
|
||||||
#include "linux_nfc_api.h"
|
|
||||||
|
|
||||||
#define LOG_CATEGORY "libnfc.driver.pn71xx"
|
|
||||||
#define LOG_GROUP NFC_LOG_GROUP_DRIVER
|
|
||||||
|
|
||||||
static bool IsTechnology(nfc_tag_info_t *TagInfo, nfc_modulation_type nmt)
|
|
||||||
{
|
|
||||||
switch (nmt) {
|
|
||||||
case NMT_ISO14443A:
|
|
||||||
if (TagInfo->technology == TARGET_TYPE_ISO14443_4
|
|
||||||
|| TagInfo->technology == TARGET_TYPE_ISO14443_3A
|
|
||||||
|| TagInfo->technology == TARGET_TYPE_MIFARE_CLASSIC
|
|
||||||
|| TagInfo->technology == TARGET_TYPE_MIFARE_UL)
|
|
||||||
return true;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case NMT_ISO14443B:
|
|
||||||
case NMT_ISO14443BI:
|
|
||||||
case NMT_ISO14443B2SR:
|
|
||||||
case NMT_ISO14443B2CT:
|
|
||||||
if (TagInfo->technology == TARGET_TYPE_ISO14443_3B)
|
|
||||||
return true;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case NMT_FELICA:
|
|
||||||
if (TagInfo->technology == TARGET_TYPE_FELICA)
|
|
||||||
return true;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case NMT_JEWEL:
|
|
||||||
if (TagInfo->technology == TARGET_TYPE_ISO14443_3A)
|
|
||||||
return true;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void BufferPrintBytes(char* buffer, unsigned int buflen, unsigned char* data, unsigned int datalen)
|
|
||||||
{
|
|
||||||
int cx = 0;
|
|
||||||
for(int i = 0x00; i < datalen; i++) {
|
|
||||||
cx += snprintf(buffer + cx, buflen - cx, "%02X ", data[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void PrintTagInfo (nfc_tag_info_t *TagInfo)
|
|
||||||
{
|
|
||||||
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:
|
|
||||||
{
|
|
||||||
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type A'");
|
|
||||||
} break;
|
|
||||||
case TARGET_TYPE_ISO14443_3B:
|
|
||||||
{
|
|
||||||
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type 4B'");
|
|
||||||
} break;
|
|
||||||
case TARGET_TYPE_ISO14443_4:
|
|
||||||
{
|
|
||||||
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type 4A'");
|
|
||||||
} break;
|
|
||||||
case TARGET_TYPE_FELICA:
|
|
||||||
{
|
|
||||||
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type F'");
|
|
||||||
} break;
|
|
||||||
case TARGET_TYPE_ISO15693:
|
|
||||||
{
|
|
||||||
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type V'");
|
|
||||||
} break;
|
|
||||||
case TARGET_TYPE_NDEF:
|
|
||||||
{
|
|
||||||
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type NDEF'");
|
|
||||||
} break;
|
|
||||||
case TARGET_TYPE_NDEF_FORMATABLE:
|
|
||||||
{
|
|
||||||
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type Formatable'");
|
|
||||||
} 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:
|
|
||||||
{
|
|
||||||
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type A - Mifare Ul'");
|
|
||||||
} 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:
|
|
||||||
{
|
|
||||||
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type A/B'");
|
|
||||||
} break;
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type %d (Unknown or not supported)'\n", TagInfo->technology);
|
|
||||||
} break;
|
|
||||||
}
|
|
||||||
/*32 is max UID len (Kovio tags)*/
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
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
|
|
||||||
{
|
|
||||||
cx += snprintf(buffer + cx, sizeof(buffer) - cx, "UID : \t'");
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -22,7 +22,6 @@
|
||||||
#include "drivers.h"
|
#include "drivers.h"
|
||||||
#include "nfc-internal.h"
|
#include "nfc-internal.h"
|
||||||
|
|
||||||
#include "libnfc_nci_support.h"
|
|
||||||
#include "linux_nfc_api.h"
|
#include "linux_nfc_api.h"
|
||||||
|
|
||||||
#define PN71XX_DRIVER_NAME "pn71xx"
|
#define PN71XX_DRIVER_NAME "pn71xx"
|
||||||
|
@ -42,47 +41,27 @@ const nfc_baud_rate pn71xx_iso14443b_supported_baud_rates[] = { NBR_847, NBR_424
|
||||||
static nfcTagCallback_t TagCB;
|
static nfcTagCallback_t TagCB;
|
||||||
static nfc_tag_info_t *TagInfo = NULL;
|
static nfc_tag_info_t *TagInfo = NULL;
|
||||||
|
|
||||||
|
static void onTagArrival(nfc_tag_info_t *pTagInfo);
|
||||||
|
static void onTagDeparture(void);
|
||||||
|
|
||||||
/** ------------------------------------------------------------------------ */
|
/** ------------------------------------------------------------------------ */
|
||||||
/** ------------------------------------------------------------------------ */
|
/** ------------------------------------------------------------------------ */
|
||||||
|
|
||||||
static void onTagArrival(nfc_tag_info_t *pTagInfo)
|
|
||||||
{
|
|
||||||
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "tag found");
|
|
||||||
|
|
||||||
TagInfo = malloc(sizeof(nfc_tag_info_t));
|
|
||||||
memcpy(TagInfo, pTagInfo, sizeof(nfc_tag_info_t));
|
|
||||||
|
|
||||||
PrintTagInfo(TagInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void onTagDeparture(void)
|
|
||||||
{
|
|
||||||
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "tag lost");
|
|
||||||
|
|
||||||
free(TagInfo);
|
|
||||||
TagInfo = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** ------------------------------------------------------------------------ */
|
|
||||||
/** ------------------------------------------------------------------------ */
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Scan all available I2C buses to find PN532 devices.
|
* @brief Initialize libnfc_nci library to verify presence of PN71xx device.
|
||||||
*
|
*
|
||||||
* @param context NFC context.
|
* @param context NFC context.
|
||||||
* @param connstrings array of 'nfc_connstring' buffer (allocated by caller). It is used to store the
|
* @param connstrings array of 'nfc_connstring' buffer (allocated by caller). It is used to store the
|
||||||
* connection info strings of all I2C PN532 devices found.
|
* connection info strings of devices found.
|
||||||
* @param connstrings_len length of the connstrings array.
|
* @param connstrings_len length of the connstrings array.
|
||||||
* @return number of PN532 devices found on all I2C buses.
|
* @return number of devices found.
|
||||||
*/
|
*/
|
||||||
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 (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));
|
||||||
|
@ -92,7 +71,7 @@ pn71xx_scan(const nfc_context *context, nfc_connstring connstrings[], const size
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Close I2C connection to the PN532 device.
|
* @brief Close connection to PN71xx by stopping the discovery loop and deinitializing the libnfc_nci library.
|
||||||
*
|
*
|
||||||
* @param pnd pointer on the device to close.
|
* @param pnd pointer on the device to close.
|
||||||
*/
|
*/
|
||||||
|
@ -102,12 +81,12 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Open an I2C connection to the PN532 device.
|
* @brief Open a connection to PN71xx, starting the discovery loop for tag detection.
|
||||||
*
|
*
|
||||||
* @param context NFC context.
|
* @param context NFC context.
|
||||||
* @param connstring connection info to the device
|
* @param connstring connection info to the device
|
||||||
|
@ -130,29 +109,170 @@ pn71xx_open(const nfc_context *context, const nfc_connstring connstring)
|
||||||
strcpy(pnd->name, "pn71xx-device");
|
strcpy(pnd->name, "pn71xx-device");
|
||||||
strcpy(pnd->connstring, connstring);
|
strcpy(pnd->connstring, connstring);
|
||||||
|
|
||||||
|
|
||||||
TagCB.onTagArrival = onTagArrival;
|
TagCB.onTagArrival = onTagArrival;
|
||||||
TagCB.onTagDeparture = onTagDeparture;
|
TagCB.onTagDeparture = onTagDeparture;
|
||||||
nfcManager_registerTagCallback(&TagCB);
|
nfcManager_registerTagCallback(&TagCB);
|
||||||
|
|
||||||
nfcManager_enableDiscovery(DEFAULT_NFA_TECH_MASK, 1, 0, 0);
|
nfcManager_enableDiscovery(DEFAULT_NFA_TECH_MASK, 1, 0, 0);
|
||||||
|
|
||||||
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "wait 1 seconds for polling");
|
||||||
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "wait 2 seconds for polling");
|
sleep(1);
|
||||||
sleep(2);
|
|
||||||
|
|
||||||
return pnd;
|
return pnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** ------------------------------------------------------------------------ */
|
||||||
|
/** ------------------------------------------------------------------------ */
|
||||||
|
static bool IsTechnology(nfc_tag_info_t *TagInfo, nfc_modulation_type nmt)
|
||||||
|
{
|
||||||
|
switch (nmt) {
|
||||||
|
case NMT_ISO14443A:
|
||||||
|
if (TagInfo->technology == TARGET_TYPE_ISO14443_4
|
||||||
|
|| TagInfo->technology == TARGET_TYPE_ISO14443_3A
|
||||||
|
|| TagInfo->technology == TARGET_TYPE_MIFARE_CLASSIC
|
||||||
|
|| TagInfo->technology == TARGET_TYPE_MIFARE_UL)
|
||||||
|
return true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case NMT_ISO14443B:
|
||||||
|
case NMT_ISO14443BI:
|
||||||
|
case NMT_ISO14443B2SR:
|
||||||
|
case NMT_ISO14443B2CT:
|
||||||
|
if (TagInfo->technology == TARGET_TYPE_ISO14443_3B)
|
||||||
|
return true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case NMT_FELICA:
|
||||||
|
if (TagInfo->technology == TARGET_TYPE_FELICA)
|
||||||
|
return true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case NMT_JEWEL:
|
||||||
|
if (TagInfo->technology == TARGET_TYPE_ISO14443_3A
|
||||||
|
&& TagInfo->protocol == NFA_PROTOCOL_T1T)
|
||||||
|
return true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
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++) {
|
||||||
|
cx += snprintf(buffer + cx, buflen - cx, "%02X ", data[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void PrintTagInfo (nfc_tag_info_t *TagInfo)
|
||||||
|
{
|
||||||
|
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:
|
||||||
|
{
|
||||||
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type 3A'");
|
||||||
|
} break;
|
||||||
|
case TARGET_TYPE_ISO14443_3B:
|
||||||
|
{
|
||||||
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type 3B'");
|
||||||
|
} break;
|
||||||
|
case TARGET_TYPE_ISO14443_4:
|
||||||
|
{
|
||||||
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type 4A'");
|
||||||
|
} break;
|
||||||
|
case TARGET_TYPE_FELICA:
|
||||||
|
{
|
||||||
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type F'");
|
||||||
|
} break;
|
||||||
|
case TARGET_TYPE_ISO15693:
|
||||||
|
{
|
||||||
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type V'");
|
||||||
|
} break;
|
||||||
|
case TARGET_TYPE_NDEF:
|
||||||
|
{
|
||||||
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type NDEF'");
|
||||||
|
} break;
|
||||||
|
case TARGET_TYPE_NDEF_FORMATABLE:
|
||||||
|
{
|
||||||
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type Formatable'");
|
||||||
|
} 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:
|
||||||
|
{
|
||||||
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type A - Mifare Ul'");
|
||||||
|
} 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:
|
||||||
|
{
|
||||||
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type A/B'");
|
||||||
|
} break;
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type %d (Unknown or not supported)'\n", TagInfo->technology);
|
||||||
|
} break;
|
||||||
|
}
|
||||||
|
/*32 is max UID len (Kovio tags)*/
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
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
|
||||||
|
{
|
||||||
|
cx += snprintf(buffer + cx, sizeof(buffer) - cx, "UID : \t'");
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** ------------------------------------------------------------------------ */
|
/** ------------------------------------------------------------------------ */
|
||||||
/** ------------------------------------------------------------------------ */
|
/** ------------------------------------------------------------------------ */
|
||||||
|
|
||||||
|
static void onTagArrival(nfc_tag_info_t *pTagInfo)
|
||||||
|
{
|
||||||
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "tag found");
|
||||||
|
|
||||||
|
TagInfo = malloc(sizeof(nfc_tag_info_t));
|
||||||
|
memcpy(TagInfo, pTagInfo, sizeof(nfc_tag_info_t));
|
||||||
|
|
||||||
|
PrintTagInfo(TagInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void onTagDeparture(void)
|
||||||
|
{
|
||||||
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "tag lost");
|
||||||
|
|
||||||
|
free(TagInfo);
|
||||||
|
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;
|
||||||
return NFC_SUCCESS;
|
return NFC_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,6 +282,8 @@ pn71xx_initiator_select_passive_target(struct nfc_device *pnd,
|
||||||
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;
|
||||||
|
|
||||||
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) {
|
||||||
|
@ -171,7 +293,7 @@ pn71xx_initiator_select_passive_target(struct nfc_device *pnd,
|
||||||
nttmp.nm = nm;
|
nttmp.nm = nm;
|
||||||
|
|
||||||
void* uidPtr = NULL;
|
void* uidPtr = NULL;
|
||||||
int maxLen = 0;
|
unsigned int maxLen = 0;
|
||||||
|
|
||||||
switch (nm.nmt) {
|
switch (nm.nmt) {
|
||||||
case NMT_ISO14443A:
|
case NMT_ISO14443A:
|
||||||
|
@ -257,6 +379,7 @@ pn71xx_initiator_select_passive_target(struct nfc_device *pnd,
|
||||||
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;
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
@ -266,16 +389,16 @@ 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;
|
||||||
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)
|
if (!TagInfo) return NFC_EINVARG;
|
||||||
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, 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;
|
||||||
|
|
||||||
|
@ -294,11 +417,11 @@ pn71xx_initiator_poll_target(struct nfc_device *pnd,
|
||||||
static int periodFactor = 150000;
|
static int periodFactor = 150000;
|
||||||
int period = uiPeriod * periodFactor;
|
int period = uiPeriod * periodFactor;
|
||||||
|
|
||||||
for (int j = 0; j < uiPollNr; j++) {
|
if (pnd == NULL) return 0;
|
||||||
for (int i = 0; i < szModulations; i++) {
|
|
||||||
const nfc_modulation nm = pnmModulations[i];
|
|
||||||
|
|
||||||
//log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "check %s", str_nfc_modulation_type(nm.nmt));
|
for (int j = 0; j < uiPollNr; j++) {
|
||||||
|
for (unsigned int i = 0; i < szModulations; i++) {
|
||||||
|
const nfc_modulation nm = pnmModulations[i];
|
||||||
|
|
||||||
nfc_target nt;
|
nfc_target nt;
|
||||||
int res = pn71xx_initiator_select_passive_target(pnd, nm, 0, 0, &nt);
|
int res = pn71xx_initiator_select_passive_target(pnd, nm, 0, 0, &nt);
|
||||||
|
@ -316,23 +439,18 @@ pn71xx_initiator_poll_target(struct nfc_device *pnd,
|
||||||
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 (pnt) {
|
if ((pnd == NULL) || (pnt == NULL)) return 1;
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// 0 = true
|
|
||||||
return !TagInfo;
|
return !TagInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** ------------------------------------------------------------------------ */
|
/** ------------------------------------------------------------------------ */
|
||||||
/** ------------------------------------------------------------------------ */
|
/** ------------------------------------------------------------------------ */
|
||||||
|
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
//log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "get_supported_modulation mode=%d", mode);
|
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;
|
||||||
|
@ -349,6 +467,9 @@ 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 (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;
|
||||||
|
@ -380,14 +501,14 @@ 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)
|
||||||
{
|
{
|
||||||
//log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "set_property_bool");
|
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)
|
||||||
{
|
{
|
||||||
//log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "set_property_int");
|
if (pnd == NULL) return NFC_EIO;
|
||||||
return NFC_SUCCESS;
|
return NFC_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -397,6 +518,8 @@ 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;
|
||||||
|
|
||||||
*pbuf = malloc(buflen);
|
*pbuf = malloc(buflen);
|
||||||
memcpy(*pbuf, info, buflen);
|
memcpy(*pbuf, info, buflen);
|
||||||
|
|
||||||
|
@ -411,6 +534,7 @@ 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;
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
@ -418,6 +542,7 @@ pn71xx_abort_command(nfc_device *pnd)
|
||||||
static int
|
static int
|
||||||
pn71xx_idle(struct nfc_device *pnd)
|
pn71xx_idle(struct nfc_device *pnd)
|
||||||
{
|
{
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
@ -425,18 +550,16 @@ pn71xx_idle(struct nfc_device *pnd)
|
||||||
static int
|
static int
|
||||||
pn71xx_PowerDown(struct nfc_device *pnd)
|
pn71xx_PowerDown(struct nfc_device *pnd)
|
||||||
{
|
{
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** ------------------------------------------------------------------------ */
|
/** ------------------------------------------------------------------------ */
|
||||||
/** ------------------------------------------------------------------------ */
|
/** ------------------------------------------------------------------------ */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const struct nfc_driver pn71xx_driver = {
|
const struct nfc_driver pn71xx_driver = {
|
||||||
.name = PN71XX_DRIVER_NAME,
|
.name = PN71XX_DRIVER_NAME,
|
||||||
.scan_type = INTRUSIVE,
|
.scan_type = NOT_INTRUSIVE,
|
||||||
.scan = pn71xx_scan,
|
.scan = pn71xx_scan,
|
||||||
.open = pn71xx_open,
|
.open = pn71xx_open,
|
||||||
.close = pn71xx_close,
|
.close = pn71xx_close,
|
||||||
|
|
Loading…
Add table
Reference in a new issue