drivers/pn53x_usb: Make valgrind more happy :)
This commit is contained in:
parent
eec2794d2d
commit
fd19773c21
3 changed files with 25 additions and 46 deletions
|
@ -118,6 +118,7 @@ typedef struct {
|
|||
} pn53x_command;
|
||||
|
||||
typedef enum {
|
||||
PN53X = 0x00, // Unknown PN53x chip type
|
||||
PN531 = 0x01,
|
||||
PN532 = 0x02,
|
||||
PN533 = 0x04,
|
||||
|
|
|
@ -169,14 +169,17 @@ pn53x_transceive (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx, b
|
|||
}
|
||||
pnd->iLastError = pbtRx[0] & 0x3f;
|
||||
break;
|
||||
default:
|
||||
case ReadRegister:
|
||||
case WriteRegister:
|
||||
if (CHIP_DATA(pnd)->type == PN533) {
|
||||
// PN533 prepends its answer by the status byte
|
||||
pnd->iLastError = pbtRx[0] & 0x3f;
|
||||
} else {
|
||||
pnd->iLastError = 0;
|
||||
}
|
||||
if (CHIP_DATA(pnd)->type == PN533) {
|
||||
if ((pbtTx[0] == ReadRegister) || (pbtTx[0] == WriteRegister)) {
|
||||
// PN533 prepends its answer by a status byte
|
||||
pnd->iLastError = pbtRx[0] & 0x3f;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
pnd->iLastError = 0;
|
||||
}
|
||||
return (0 == pnd->iLastError);
|
||||
}
|
||||
|
@ -626,6 +629,9 @@ pn53x_get_firmware_version (nfc_device_t * pnd, char abtFirmwareText[22])
|
|||
snprintf (abtFirmwareText, 22, "PN533 v%d.%d (0x%02x)", abtFw[1], abtFw[2], abtFw[3]);
|
||||
pnd->btSupportByte = abtFw[3];
|
||||
break;
|
||||
case PN53X:
|
||||
// Could not happend
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -861,6 +867,7 @@ pn53x_initiator_select_passive_target (nfc_device_t * pnd,
|
|||
if (nm.nmt == NMT_ISO14443BI || nm.nmt == NMT_ISO14443B2SR || nm.nmt == NMT_ISO14443B2CT) {
|
||||
if (CHIP_DATA(pnd)->type == RCS360) {
|
||||
// TODO add support for RC-S360, at the moment it refuses to send raw frames without a first select
|
||||
pnd->iLastError = ENOTIMPL;
|
||||
return false;
|
||||
}
|
||||
// No native support in InListPassiveTarget so we do discovery by hand
|
||||
|
@ -1921,7 +1928,6 @@ pn53x_InListPassiveTarget (nfc_device_t * pnd,
|
|||
|
||||
abtCmd[1] = szMaxTargets; // MaxTg
|
||||
|
||||
// XXX Is there a better way to do handle supported modulations ?
|
||||
switch(pmInitModulation) {
|
||||
case PM_ISO14443A_106:
|
||||
case PM_FELICA_212:
|
||||
|
@ -2492,6 +2498,9 @@ pn53x_data_new (nfc_device_t * pnd, const struct pn53x_io* io)
|
|||
// Keep I/O functions
|
||||
CHIP_DATA (pnd)->io = io;
|
||||
|
||||
// Set type to generic (means unknown)
|
||||
CHIP_DATA (pnd)->type = PN53X;
|
||||
|
||||
// Set power mode to normal, if your device starts in LowVBat (ie. PN532
|
||||
// UART) the driver layer have to correctly set it.
|
||||
CHIP_DATA (pnd)->power_mode = NORMAL;
|
||||
|
|
47
libnfc/nfc.c
47
libnfc/nfc.c
|
@ -43,8 +43,6 @@
|
|||
|
||||
#include <sys/param.h>
|
||||
|
||||
nfc_device_desc_t *nfc_pick_device (void);
|
||||
|
||||
const struct nfc_driver_t *nfc_drivers[] = {
|
||||
# if defined (DRIVER_PN53X_USB_ENABLED)
|
||||
&pn53x_usb_driver,
|
||||
|
@ -82,8 +80,14 @@ nfc_connect (nfc_device_desc_t * pndd)
|
|||
{
|
||||
nfc_device_t *pnd = NULL;
|
||||
|
||||
if (pndd == NULL)
|
||||
pndd = nfc_pick_device ();
|
||||
if (pndd == NULL) {
|
||||
size_t szDeviceFound;
|
||||
nfc_device_desc_t ndd[1];
|
||||
nfc_list_devices (ndd, 1, &szDeviceFound);
|
||||
if (szDeviceFound) {
|
||||
pndd = &ndd[0];
|
||||
}
|
||||
}
|
||||
|
||||
if (pndd == NULL)
|
||||
return NULL;
|
||||
|
@ -130,41 +134,6 @@ nfc_disconnect (nfc_device_t * pnd)
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Probe for the first discoverable supported devices (ie. only available for some drivers)
|
||||
* @return \a nfc_device_desc_t struct pointer
|
||||
*/
|
||||
nfc_device_desc_t *
|
||||
nfc_pick_device (void)
|
||||
{
|
||||
const struct nfc_driver_t *ndr;
|
||||
const struct nfc_driver_t **pndr = nfc_drivers;
|
||||
while ((ndr = *pndr)) {
|
||||
nfc_device_desc_t *pndd;
|
||||
|
||||
if ((pndd = malloc (sizeof (*pndd)))) {
|
||||
size_t szN;
|
||||
|
||||
if (!ndr->probe (pndd, 1, &szN)) {
|
||||
DBG ("%s probe failed", ndr->name);
|
||||
szN = 0;
|
||||
}
|
||||
|
||||
if (szN == 0) {
|
||||
DBG ("No %s device found", ndr->name);
|
||||
free (pndd);
|
||||
} else {
|
||||
DBG ("One %s device found", ndr->name);
|
||||
return pndd;
|
||||
}
|
||||
}
|
||||
pndr++;
|
||||
}
|
||||
|
||||
DBG ("%s", "No device found with any driver :-(");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Probe for discoverable supported devices (ie. only available for some drivers)
|
||||
* @param[out] pnddDevices array of \a nfc_device_desc_t previously allocated by the caller.
|
||||
|
|
Loading…
Reference in a new issue