From 04a51df7967a4711b5779493aec39569e9d01195 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Mon, 8 Jun 2015 11:34:16 +0200 Subject: [PATCH] nfc_get_supported_baud_rate() proposal to reverse API cf issue #298 nfc_get_supported_baud_rate() would be the one for "initiator mode" and we add nfc_get_supported_baud_rate_target_mode() --- include/nfc/nfc.h | 3 ++- libnfc/chips/pn53x.c | 4 ++-- libnfc/nfc.c | 31 +++++++++++++++++++++++++------ 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/include/nfc/nfc.h b/include/nfc/nfc.h index 9e9e78c..2f377e5 100644 --- a/include/nfc/nfc.h +++ b/include/nfc/nfc.h @@ -126,7 +126,8 @@ 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_mode mode, 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_modulation_type nmt, const nfc_baud_rate **const supported_br); +NFC_EXPORT int nfc_device_get_supported_baud_rate_target_mode(nfc_device *pnd, 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 e91b3bd..4abfefc 100644 --- a/libnfc/chips/pn53x.c +++ b/libnfc/chips/pn53x.c @@ -3366,7 +3366,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, N_INITIATOR, nmt[i], &nbr)) < 0) { + if ((res = nfc_device_get_supported_baud_rate(pnd, nmt[i], &nbr)) < 0) { free(*pbuf); return res; } @@ -3431,7 +3431,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, N_TARGET, nmt[i], &nbr)) < 0) { + if ((res = nfc_device_get_supported_baud_rate_target_mode(pnd, nmt[i], &nbr)) < 0) { free(*pbuf); return res; } diff --git a/libnfc/nfc.c b/libnfc/nfc.c index c774504..114d5e8 100644 --- a/libnfc/nfc.c +++ b/libnfc/nfc.c @@ -1198,18 +1198,31 @@ nfc_device_get_supported_modulation(nfc_device *pnd, const nfc_mode mode, const } /** @ingroup data - * @brief Get supported baud rates. + * @brief Get supported baud rates (initiator mode). * @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_mode mode, const nfc_modulation_type nmt, const nfc_baud_rate **const supported_br) +nfc_device_get_supported_baud_rate(nfc_device *pnd, const nfc_modulation_type nmt, const nfc_baud_rate **const supported_br) { - HAL(get_supported_baud_rate, pnd, mode, nmt, supported_br); + HAL(get_supported_baud_rate, pnd, N_INITIATOR, nmt, supported_br); +} + +/** @ingroup data + * @brief Get supported baud rates for target mode. + * @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 nmt \a nfc_modulation_type. + * @param supported_br pointer of \a nfc_baud_rate array. + * + */ +int +nfc_device_get_supported_baud_rate_target_mode(nfc_device *pnd, const nfc_modulation_type nmt, const nfc_baud_rate **const supported_br) +{ + HAL(get_supported_baud_rate, pnd, N_TARGET, nmt, supported_br); } /** @ingroup data @@ -1231,8 +1244,14 @@ nfc_device_validate_modulation(nfc_device *pnd, const nfc_mode mode, const nfc_m for (int i = 0; nmt[i]; i++) { if (nmt[i] == nm->nmt) { const nfc_baud_rate *nbr; - if ((res = nfc_device_get_supported_baud_rate(pnd, mode, nmt[i], &nbr)) < 0) { - return res; + if (mode == N_INITIATOR) { + if ((res = nfc_device_get_supported_baud_rate(pnd, nmt[i], &nbr)) < 0) { + return res; + } + } else { + if ((res = nfc_device_get_supported_baud_rate_target_mode(pnd, nmt[i], &nbr)) < 0) { + return res; + } } for (int j = 0; nbr[j]; j++) { if (nbr[j] == nm->nbr)