Commit 5a5bdf1d authored by Audrey Diacre's avatar Audrey Diacre

add nfc_device_get_supported_modulation() and nfc_device_get_supported_baud_rate() functions.

parent 75e776ff
......@@ -276,7 +276,7 @@ typedef enum {
* @brief NFC modulation type enumeration
*/
typedef enum {
NMT_ISO14443A,
NMT_ISO14443A = 1,
NMT_JEWEL,
NMT_ISO14443B,
NMT_ISO14443BI, // pre-ISO14443B aka ISO/IEC 14443 B' or Type B'
......@@ -286,6 +286,15 @@ typedef enum {
NMT_DEP,
} nfc_modulation_type;
/**
* @enum nfc_mode
* @brief NFC mode type enumeration
*/
typedef enum {
N_TARGET,
N_INITIATOR,
} nfc_mode;
/**
* @struct nfc_modulation
* @brief NFC modulation structure
......
......@@ -113,6 +113,8 @@ extern "C" {
NFC_EXPORT void iso14443a_crc_append (uint8_t *pbtData, size_t szLen);
NFC_EXPORT uint8_t *iso14443a_locate_historical_bytes (uint8_t *pbtAts, size_t szAts, size_t *pszTk);
NFC_EXPORT const char *nfc_version (void);
NFC_EXPORT int nfc_device_get_supported_modulation (nfc_device *pnd, const nfc_mode mode, nfc_modulation_type **supported_mt);
NFC_EXPORT int nfc_device_get_supported_baud_rate (nfc_device *pnd, const nfc_modulation_type nmt, nfc_baud_rate **supported_br);
/* Error codes */
/** @ingroup error
......
......@@ -49,6 +49,13 @@
const uint8_t pn53x_ack_frame[] = { 0x00, 0x00, 0xff, 0x00, 0xff, 0x00 };
const uint8_t pn53x_nack_frame[] = { 0x00, 0x00, 0xff, 0xff, 0x00, 0x00 };
static const uint8_t pn53x_error_frame[] = { 0x00, 0x00, 0xff, 0x01, 0xff, 0x7f, 0x81, 0x00 };
const nfc_baud_rate pn53x_iso14443a_supported_baud_rates[] = { NBR_106, 0 };
const nfc_baud_rate pn53x_felica_supported_baud_rates[] = { NBR_424, NBR_212, 0 };
const nfc_baud_rate pn53x_dep_supported_baud_rates[] = { NBR_424, NBR_212, NBR_106, 0 };
const nfc_baud_rate pn53x_jewel_supported_baud_rates[] = { NBR_106, 0 };
const nfc_baud_rate pn532_iso14443b_supported_baud_rates[] = { NBR_106, 0 };
const nfc_baud_rate pn533_iso14443b_supported_baud_rates[] = { NBR_847, NBR_424, NBR_212, NBR_106, 0 };
const nfc_modulation_type pn53x_supported_modulation_as_target[] = {NMT_ISO14443A, NMT_FELICA, NMT_DEP, 0};
/* prototypes */
int pn53x_reset_settings (struct nfc_device *pnd);
......@@ -68,6 +75,32 @@ pn53x_init(struct nfc_device *pnd)
return res;
}
if (!CHIP_DATA(pnd)->supported_modulation_as_initiator) {
CHIP_DATA(pnd)->supported_modulation_as_initiator = malloc(sizeof(nfc_modulation) * 9);
int nbSupportedModulation = 0;
if ((pnd->btSupportByte & SUPPORT_ISO14443A)) {
CHIP_DATA(pnd)->supported_modulation_as_initiator[nbSupportedModulation] = NMT_ISO14443A;
nbSupportedModulation++;
CHIP_DATA(pnd)->supported_modulation_as_initiator[nbSupportedModulation] = NMT_FELICA;
nbSupportedModulation++;
}
if (pnd->btSupportByte & SUPPORT_ISO14443B) {
CHIP_DATA(pnd)->supported_modulation_as_initiator[nbSupportedModulation] = NMT_ISO14443B;
nbSupportedModulation++;
}
if(CHIP_DATA(pnd)->type != PN531) {
CHIP_DATA(pnd)->supported_modulation_as_initiator[nbSupportedModulation] = NMT_JEWEL;
nbSupportedModulation++;
}
CHIP_DATA(pnd)->supported_modulation_as_initiator[nbSupportedModulation] = NMT_DEP;
nbSupportedModulation++;
CHIP_DATA(pnd)->supported_modulation_as_initiator[nbSupportedModulation] = 0;
}
if (!CHIP_DATA(pnd)->supported_modulation_as_target) {
CHIP_DATA(pnd)->supported_modulation_as_target = pn53x_supported_modulation_as_target;
}
// CRC handling should be enabled by default as declared in nfc_device_new
// which is the case by default for pn53x, so nothing to do here
// Parity handling should be enabled by default as declared in nfc_device_new
......@@ -2758,6 +2791,51 @@ pn53x_nm_to_ptt(const nfc_modulation nm)
return PTT_UNDEFINED;
}
int
pn53x_get_supported_modulation(nfc_device *pnd, const nfc_mode mode, nfc_modulation_type **supported_mt)
{
switch (mode) {
case N_TARGET:
*supported_mt = CHIP_DATA(pnd)->supported_modulation_as_target;
break;
case N_INITIATOR:
*supported_mt = CHIP_DATA(pnd)->supported_modulation_as_initiator;
break;
default:
return NFC_EINVARG;
}
return NFC_SUCCESS;
}
int
pn53x_get_supported_baud_rate (nfc_device *pnd, const nfc_modulation_type nmt, nfc_baud_rate **supported_br)
{
switch (nmt) {
case NMT_FELICA:
*supported_br = (nfc_baud_rate*)pn53x_felica_supported_baud_rates;
break;
case NMT_ISO14443A:
*supported_br = (nfc_baud_rate*)pn53x_iso14443a_supported_baud_rates;
break;
case NMT_ISO14443B: {
if ((CHIP_DATA(pnd)->type != PN533)) {
*supported_br = (nfc_baud_rate*)pn532_iso14443b_supported_baud_rates;
} else {
*supported_br = (nfc_baud_rate*)pn533_iso14443b_supported_baud_rates;
}
}
break;
case NMT_JEWEL:
*supported_br = (nfc_baud_rate*)pn53x_jewel_supported_baud_rates;
break;
case NMT_DEP:
*supported_br = (nfc_baud_rate*)pn53x_dep_supported_baud_rates;
break;
return NFC_EINVARG;
}
return NFC_SUCCESS;
}
void
pn53x_data_new (struct nfc_device *pnd, const struct pn53x_io *io)
{
......@@ -2794,6 +2872,10 @@ pn53x_data_new (struct nfc_device *pnd, const struct pn53x_io *io)
// Set default communication timeout (52 ms)
CHIP_DATA (pnd)->timeout_communication = 52;
CHIP_DATA (pnd)->supported_modulation_as_initiator = NULL;
CHIP_DATA (pnd)->supported_modulation_as_target = NULL;
}
void
......@@ -2802,5 +2884,8 @@ pn53x_data_free (struct nfc_device *pnd)
if (CHIP_DATA (pnd)->current_target) {
free (CHIP_DATA (pnd)->current_target);
}
if (CHIP_DATA(pnd)->supported_modulation_as_initiator) {
free (CHIP_DATA(pnd)->supported_modulation_as_initiator);
}
free (pnd->chip_data);
}
......@@ -187,6 +187,9 @@ struct pn53x_data {
int timeout_atr;
/** Communication timeout */
int timeout_communication;
/** Supported modulation type */
nfc_modulation_type *supported_modulation_as_initiator;
nfc_modulation_type *supported_modulation_as_target;
};
#define CHIP_DATA(pnd) ((struct pn53x_data*)(pnd->chip_data))
......@@ -377,6 +380,8 @@ int pn53x_RFConfiguration__MaxRetries (struct nfc_device *pnd, const uint8_t
int pn53x_check_ack_frame (struct nfc_device *pnd, const uint8_t *pbtRxFrame, const size_t szRxFrameLen);
int pn53x_check_error_frame (struct nfc_device *pnd, const uint8_t *pbtRxFrame, const size_t szRxFrameLen);
int pn53x_build_frame (uint8_t *pbtFrame, size_t *pszFrame, const uint8_t *pbtData, const size_t szData);
int pn53x_get_supported_modulation(nfc_device *pnd, const nfc_mode mode, nfc_modulation_type **supported_mt);
int pn53x_get_supported_baud_rate(nfc_device *pnd, const nfc_modulation_type nmt, nfc_baud_rate **supported_br);
void pn53x_data_new (struct nfc_device *pnd, const struct pn53x_io *io);
void pn53x_data_free (struct nfc_device *pnd);
......
......@@ -488,6 +488,8 @@ const struct nfc_driver acr122_driver = {
.device_set_property_bool = pn53x_set_property_bool,
.device_set_property_int = pn53x_set_property_int,
.get_supported_modulation = pn53x_get_supported_modulation,
.get_supported_baud_rate = pn53x_get_supported_baud_rate,
.abort_command = NULL, // FIXME: abort is not supported in this driver
.idle = NULL, // FIXME: idle is not supported in this driver
......
......@@ -743,6 +743,8 @@ const struct nfc_driver acr122s_driver = {
.device_set_property_bool = pn53x_set_property_bool,
.device_set_property_int = pn53x_set_property_int,
.get_supported_modulation = pn53x_get_supported_modulation,
.get_supported_baud_rate = pn53x_get_supported_baud_rate,
.abort_command = acr122s_abort_command,
.idle = NULL,
......
......@@ -585,6 +585,8 @@ const struct nfc_driver arygon_driver = {
.device_set_property_bool = pn53x_set_property_bool,
.device_set_property_int = pn53x_set_property_int,
.get_supported_modulation = pn53x_get_supported_modulation,
.get_supported_baud_rate = pn53x_get_supported_baud_rate,
.abort_command = arygon_abort_command,
.idle = NULL, // FIXME arygon driver does not support idle()
......
......@@ -527,6 +527,8 @@ const struct nfc_driver pn532_uart_driver = {
.device_set_property_bool = pn53x_set_property_bool,
.device_set_property_int = pn53x_set_property_int,
.get_supported_modulation = pn53x_get_supported_modulation,
.get_supported_baud_rate = pn53x_get_supported_baud_rate,
.abort_command = pn532_uart_abort_command,
.idle = pn53x_idle,
......
......@@ -773,6 +773,8 @@ const struct nfc_driver pn53x_usb_driver = {
.device_set_property_bool = pn53x_usb_set_property_bool,
.device_set_property_int = pn53x_set_property_int,
.get_supported_modulation = pn53x_get_supported_modulation,
.get_supported_baud_rate = pn53x_get_supported_baud_rate,
.abort_command = pn53x_usb_abort_command,
.idle = pn53x_idle,
......
......@@ -151,6 +151,8 @@ struct nfc_driver {
int (*device_set_property_bool) (struct nfc_device *pnd, const nfc_property property, const bool bEnable);
int (*device_set_property_int) (struct nfc_device *pnd, const nfc_property property, const int value);
int (*get_supported_modulation) (struct nfc_device *pnd, const nfc_mode mode, nfc_modulation_type **supported_mt);
int (*get_supported_baud_rate) (struct nfc_device *pnd, const nfc_modulation_type nmt, nfc_baud_rate **supported_br);
int (*abort_command) (struct nfc_device *pnd);
int (*idle) (struct nfc_device *pnd);
......
......@@ -1001,3 +1001,15 @@ nfc_version (void)
return PACKAGE_VERSION;
#endif // SVN_REVISION
}
int
nfc_device_get_supported_modulation (nfc_device *pnd, const nfc_mode mode, nfc_modulation_type **supported_mt)
{
HAL (get_supported_modulation, pnd, mode, supported_mt);
}
int
nfc_device_get_supported_baud_rate (nfc_device *pnd, const nfc_modulation_type nmt, nfc_baud_rate **supported_br)
{
HAL (get_supported_baud_rate, pnd, nmt, supported_br);
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment