diff --git a/NEWS b/NEWS index 83b7d91..e3f5411 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,9 @@ +New in 1.7.x: + +API Changes: + + * nfc_device_get_supported_baud_rate() now takes also "mode" as argument + New in 1.7.1: API Changes: diff --git a/include/nfc/nfc.h b/include/nfc/nfc.h index 44f92d9..9e9e78c 100644 --- a/include/nfc/nfc.h +++ b/include/nfc/nfc.h @@ -126,7 +126,7 @@ NFC_EXPORT int nfc_device_get_last_error(const nfc_device *pnd); NFC_EXPORT const char *nfc_device_get_name(nfc_device *pnd); NFC_EXPORT const char *nfc_device_get_connstring(nfc_device *pnd); NFC_EXPORT int nfc_device_get_supported_modulation(nfc_device *pnd, const nfc_mode mode, const nfc_modulation_type **const supported_mt); -NFC_EXPORT int nfc_device_get_supported_baud_rate(nfc_device *pnd, const nfc_modulation_type nmt, const nfc_baud_rate **const supported_br); +NFC_EXPORT int nfc_device_get_supported_baud_rate(nfc_device *pnd, const nfc_mode mode, const nfc_modulation_type nmt, const nfc_baud_rate **const supported_br); /* Properties accessors */ NFC_EXPORT int nfc_device_set_property_int(nfc_device *pnd, const nfc_property property, const int value); diff --git a/libnfc/chips/pn53x.c b/libnfc/chips/pn53x.c index 3841782..4114231 100644 --- a/libnfc/chips/pn53x.c +++ b/libnfc/chips/pn53x.c @@ -52,7 +52,8 @@ 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 pn532_iso14443a_supported_baud_rates[] = { NBR_424, NBR_212, NBR_106, 0 }; +const nfc_baud_rate pn533_iso14443a_supported_baud_rates[] = { NBR_847, NBR_424, NBR_212, 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 }; @@ -96,6 +97,12 @@ pn53x_init(struct nfc_device *pnd) if (pnd->btSupportByte & SUPPORT_ISO14443B) { CHIP_DATA(pnd)->supported_modulation_as_initiator[nbSupportedModulation] = NMT_ISO14443B; nbSupportedModulation++; + CHIP_DATA(pnd)->supported_modulation_as_initiator[nbSupportedModulation] = NMT_ISO14443BI; + nbSupportedModulation++; + CHIP_DATA(pnd)->supported_modulation_as_initiator[nbSupportedModulation] = NMT_ISO14443B2SR; + nbSupportedModulation++; + CHIP_DATA(pnd)->supported_modulation_as_initiator[nbSupportedModulation] = NMT_ISO14443B2CT; + nbSupportedModulation++; } if (CHIP_DATA(pnd)->type != PN531) { CHIP_DATA(pnd)->supported_modulation_as_initiator[nbSupportedModulation] = NMT_JEWEL; @@ -1158,7 +1165,7 @@ pn53x_initiator_select_passive_target_ext(struct nfc_device *pnd, if ((res = pn53x_decode_target_data(abtTargetsData + 1, szTargetsData - 1, CHIP_DATA(pnd)->type, nm.nmt, &(nttmp.nti))) < 0) { return res; } - if (nm.nbr != NBR_106) { + if ((nm.nmt == NMT_ISO14443A) && (nm.nbr != NBR_106)) { uint8_t pncmd_inpsl[4] = { InPSL, 0x01 }; pncmd_inpsl[2] = nm.nbr - 1; pncmd_inpsl[3] = nm.nbr - 1; @@ -3265,19 +3272,21 @@ pn53x_get_supported_modulation(nfc_device *pnd, const nfc_mode mode, const nfc_m } int -pn53x_get_supported_baud_rate(nfc_device *pnd, const nfc_modulation_type nmt, const nfc_baud_rate **const supported_br) +pn53x_get_supported_baud_rate(nfc_device *pnd, const nfc_mode mode, const nfc_modulation_type nmt, const nfc_baud_rate **const 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: - case NMT_ISO14443BI: - case NMT_ISO14443B2SR: - case NMT_ISO14443B2CT: { + case NMT_ISO14443A: { + if ((CHIP_DATA(pnd)->type != PN533) || (mode == N_TARGET)) { + *supported_br = (nfc_baud_rate *)pn532_iso14443a_supported_baud_rates; + } else { + *supported_br = (nfc_baud_rate *)pn533_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 { @@ -3285,6 +3294,11 @@ pn53x_get_supported_baud_rate(nfc_device *pnd, const nfc_modulation_type nmt, co } } break; + case NMT_ISO14443BI: + case NMT_ISO14443B2SR: + case NMT_ISO14443B2CT: + *supported_br = (nfc_baud_rate *)pn532_iso14443b_supported_baud_rates; + break; case NMT_JEWEL: *supported_br = (nfc_baud_rate *)pn53x_jewel_supported_baud_rates; break; @@ -3347,7 +3361,7 @@ pn53x_get_information_about(nfc_device *pnd, char **pbuf) } buflen -= res; const nfc_baud_rate *nbr; - if ((res = nfc_device_get_supported_baud_rate(pnd, nmt[i], &nbr)) < 0) { + if ((res = nfc_device_get_supported_baud_rate(pnd, N_INITIATOR, nmt[i], &nbr)) < 0) { free(*pbuf); return res; } @@ -3400,7 +3414,6 @@ pn53x_get_information_about(nfc_device *pnd, char **pbuf) free(*pbuf); return res; } - for (int i = 0; nmt[i]; i++) { if ((res = snprintf(buf, buflen, "%s%s (", (i == 0) ? "" : ", ", str_nfc_modulation_type(nmt[i]))) < 0) { free(*pbuf); @@ -3413,7 +3426,7 @@ pn53x_get_information_about(nfc_device *pnd, char **pbuf) } buflen -= res; const nfc_baud_rate *nbr; - if ((res = nfc_device_get_supported_baud_rate(pnd, nmt[i], &nbr)) < 0) { + if ((res = nfc_device_get_supported_baud_rate(pnd, N_TARGET, nmt[i], &nbr)) < 0) { free(*pbuf); return res; } diff --git a/libnfc/chips/pn53x.h b/libnfc/chips/pn53x.h index b45f1c5..bb5d6e3 100644 --- a/libnfc/chips/pn53x.h +++ b/libnfc/chips/pn53x.h @@ -392,7 +392,7 @@ int pn53x_check_ack_frame(struct nfc_device *pnd, const uint8_t *pbtRxFrame, 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, const nfc_modulation_type **const supported_mt); -int pn53x_get_supported_baud_rate(nfc_device *pnd, const nfc_modulation_type nmt, const nfc_baud_rate **const supported_br); +int pn53x_get_supported_baud_rate(nfc_device *pnd, const nfc_mode mode, const nfc_modulation_type nmt, const nfc_baud_rate **const supported_br); int pn53x_get_information_about(nfc_device *pnd, char **pbuf); void *pn53x_data_new(struct nfc_device *pnd, const struct pn53x_io *io); diff --git a/libnfc/drivers/pn53x_usb.c b/libnfc/drivers/pn53x_usb.c index e75a086..b4dbe89 100644 --- a/libnfc/drivers/pn53x_usb.c +++ b/libnfc/drivers/pn53x_usb.c @@ -60,6 +60,8 @@ Thanks to d18c7db and Okko for example code #define DRIVER_DATA(pnd) ((struct pn53x_usb_data*)(pnd->driver_data)) +const nfc_modulation_type no_target_support[] = {0}; + typedef enum { UNKNOWN, NXP_PN531, @@ -709,6 +711,16 @@ pn53x_usb_abort_command(nfc_device *pnd) return NFC_SUCCESS; } +static int +pn53x_usb_get_supported_modulation(nfc_device *pnd, const nfc_mode mode, const nfc_modulation_type **const supported_mt) +{ + if ((DRIVER_DATA(pnd)->model != ASK_LOGO) || (mode != N_TARGET)) + return pn53x_get_supported_modulation(pnd, mode, supported_mt); + else // ASK_LOGO has no N_TARGET support + *supported_mt = no_target_support; + return NFC_SUCCESS; +} + const struct pn53x_io pn53x_usb_io = { .send = pn53x_usb_send, .receive = pn53x_usb_receive, @@ -742,7 +754,7 @@ 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_modulation = pn53x_usb_get_supported_modulation, .get_supported_baud_rate = pn53x_get_supported_baud_rate, .device_get_information_about = pn53x_get_information_about, diff --git a/libnfc/nfc-internal.h b/libnfc/nfc-internal.h index 0e63c93..4fa2fc2 100644 --- a/libnfc/nfc-internal.h +++ b/libnfc/nfc-internal.h @@ -148,7 +148,7 @@ 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, const nfc_modulation_type **const supported_mt); - int (*get_supported_baud_rate)(struct nfc_device *pnd, const nfc_modulation_type nmt, const nfc_baud_rate **const supported_br); + int (*get_supported_baud_rate)(struct nfc_device *pnd, const nfc_mode mode, const nfc_modulation_type nmt, const nfc_baud_rate **const supported_br); int (*device_get_information_about)(struct nfc_device *pnd, char **buf); int (*abort_command)(struct nfc_device *pnd); diff --git a/libnfc/nfc.c b/libnfc/nfc.c index 7ca4c24..2094765 100644 --- a/libnfc/nfc.c +++ b/libnfc/nfc.c @@ -1196,14 +1196,15 @@ nfc_device_get_supported_modulation(nfc_device *pnd, const nfc_mode mode, const * @brief Get supported baud rates. * @return Returns 0 on success, otherwise returns libnfc's error code (negative value) * @param pnd \a nfc_device struct pointer that represent currently used device + * @param mode \a nfc_mode. * @param nmt \a nfc_modulation_type. * @param supported_br pointer of \a nfc_baud_rate array. * */ int -nfc_device_get_supported_baud_rate(nfc_device *pnd, const nfc_modulation_type nmt, const nfc_baud_rate **const supported_br) +nfc_device_get_supported_baud_rate(nfc_device *pnd, const nfc_mode mode, const nfc_modulation_type nmt, const nfc_baud_rate **const supported_br) { - HAL(get_supported_baud_rate, pnd, nmt, supported_br); + HAL(get_supported_baud_rate, pnd, mode, nmt, supported_br); } /* Misc. functions */