Clean the way to retrieve firmware
This commit is contained in:
parent
c6c43afc87
commit
bfb49b594f
3 changed files with 18 additions and 14 deletions
|
@ -106,6 +106,16 @@ pn53x_init(nfc_device_t * pnd)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char abtFirmwareText[18];
|
||||||
|
if (!pn53x_get_firmware_version (pnd, abtFirmwareText)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add the firmware revision to the device name
|
||||||
|
char *pcName;
|
||||||
|
pcName = strdup (pnd->acName);
|
||||||
|
snprintf (pnd->acName, DEVICE_NAME_LENGTH - 1, "%s - %s", pcName, abtFirmwareText);
|
||||||
|
free (pcName);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -723,7 +733,7 @@ static struct sErrorMessage {
|
||||||
DENACK, "Received NACK"}, {
|
DENACK, "Received NACK"}, {
|
||||||
DEACKMISMATCH, "Expected ACK/NACK"}, {
|
DEACKMISMATCH, "Expected ACK/NACK"}, {
|
||||||
DEISERRFRAME, "Received an error frame"},
|
DEISERRFRAME, "Received an error frame"},
|
||||||
/* TODO: Move me in more generic code for libnfc 1.6 */
|
// TODO: Move me in more generic code for libnfc 1.6
|
||||||
{
|
{
|
||||||
DEINVAL, "Invalid argument"}, {
|
DEINVAL, "Invalid argument"}, {
|
||||||
DEIO, "Input/output error"}, {
|
DEIO, "Input/output error"}, {
|
||||||
|
@ -748,31 +758,29 @@ pn53x_strerror (const nfc_device_t * pnd)
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
pn53x_get_firmware_version (nfc_device_t * pnd)
|
pn53x_get_firmware_version (nfc_device_t * pnd, char abtFirmwareText[18])
|
||||||
{
|
{
|
||||||
byte_t abtFw[4];
|
byte_t abtFw[4];
|
||||||
size_t szFwLen = sizeof (abtFw);
|
size_t szFwLen = sizeof (abtFw);
|
||||||
char *pcName;
|
|
||||||
// TODO Read more info here: there are modulation capabilities info to know if ISO14443B is supported
|
// TODO Read more info here: there are modulation capabilities info to know if ISO14443B is supported
|
||||||
if (!pn53x_transceive (pnd, pncmd_get_firmware_version, 2, abtFw, &szFwLen)) {
|
if (!pn53x_transceive (pnd, pncmd_get_firmware_version, 2, abtFw, &szFwLen)) {
|
||||||
// Failed to get firmware revision??, whatever...let's disconnect and clean up and return err
|
// Failed to get firmware revision??, whatever...let's disconnect and clean up and return err
|
||||||
pnd->pdc->disconnect (pnd);
|
pnd->pdc->disconnect (pnd);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Add the firmware revision to the device name, PN531 gives 2 bytes info, but PN532 and PN533 gives 4
|
// Convert firmware info in text, PN531 gives 2 bytes info, but PN532 and PN533 gives 4
|
||||||
pcName = strdup (pnd->acName);
|
|
||||||
switch (pnd->nc) {
|
switch (pnd->nc) {
|
||||||
case NC_PN531:
|
case NC_PN531:
|
||||||
snprintf (pnd->acName, DEVICE_NAME_LENGTH - 1, "%s - PN531 v%d.%d", pcName, abtFw[0], abtFw[1]);
|
snprintf (abtFirmwareText, 18, "PN531 v%d.%d", abtFw[0], abtFw[1]);
|
||||||
break;
|
break;
|
||||||
case NC_PN532:
|
case NC_PN532:
|
||||||
snprintf (pnd->acName, DEVICE_NAME_LENGTH - 1, "%s - PN532 v%d.%d (0x%02x)", pcName, abtFw[1], abtFw[2], abtFw[3]);
|
snprintf (abtFirmwareText, 18, "PN532 v%d.%d (0x%02x)", abtFw[1], abtFw[2], abtFw[3]);
|
||||||
break;
|
break;
|
||||||
case NC_PN533:
|
case NC_PN533:
|
||||||
snprintf (pnd->acName, DEVICE_NAME_LENGTH - 1, "%s - PN533 v%d.%d (0x%02x)", pcName, abtFw[1], abtFw[2], abtFw[3]);
|
snprintf (abtFirmwareText, 18, "PN533 v%d.%d (0x%02x)", abtFw[1], abtFw[2], abtFw[3]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
free (pcName);
|
abtFirmwareText[17] = '\0';
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -186,7 +186,7 @@ bool pn53x_unwrap_frame (const byte_t * pbtFrame, const size_t szFrameBits, b
|
||||||
bool pn53x_decode_target_data (const byte_t * pbtRawData, size_t szRawData,
|
bool pn53x_decode_target_data (const byte_t * pbtRawData, size_t szRawData,
|
||||||
nfc_chip_t nc, nfc_modulation_type_t nmt,
|
nfc_chip_t nc, nfc_modulation_type_t nmt,
|
||||||
nfc_target_info_t * pnti);
|
nfc_target_info_t * pnti);
|
||||||
bool pn53x_get_firmware_version (nfc_device_t * pnd);
|
bool pn53x_get_firmware_version (nfc_device_t * pnd, char abtFirmwareText[18]);
|
||||||
bool pn53x_configure (nfc_device_t * pnd, const nfc_device_option_t ndo, const bool bEnable);
|
bool pn53x_configure (nfc_device_t * pnd, const nfc_device_option_t ndo, const bool bEnable);
|
||||||
|
|
||||||
// NFC device as Initiator functions
|
// NFC device as Initiator functions
|
||||||
|
|
|
@ -109,10 +109,6 @@ nfc_connect (nfc_device_desc_t * pndd)
|
||||||
// Great we have claimed a device
|
// Great we have claimed a device
|
||||||
pnd->pdc = &(drivers_callbacks_list[uiDriver]);
|
pnd->pdc = &(drivers_callbacks_list[uiDriver]);
|
||||||
|
|
||||||
// FIXME Why do we do this ?
|
|
||||||
if (!pn53x_get_firmware_version (pnd))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
if (!pn53x_init (pnd))
|
if (!pn53x_init (pnd))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue