diff --git a/include/nfc/nfc.h b/include/nfc/nfc.h index 75aad63..90ff0b2 100644 --- a/include/nfc/nfc.h +++ b/include/nfc/nfc.h @@ -118,7 +118,7 @@ extern "C" { 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_information_about(nfc_device *pnd, char *buf, size_t buflen); + NFC_EXPORT int nfc_device_get_information_about(nfc_device *pnd, char **buf); /* String converter functions */ NFC_EXPORT const char *str_nfc_modulation_type(const nfc_modulation_type nmt); diff --git a/libnfc/chips/pn53x.c b/libnfc/chips/pn53x.c index 66b3064..51befdd 100644 --- a/libnfc/chips/pn53x.c +++ b/libnfc/chips/pn53x.c @@ -2925,8 +2925,12 @@ pn53x_get_supported_baud_rate(nfc_device *pnd, const nfc_modulation_type nmt, co } int -pn53x_get_information_about(nfc_device *pnd, char *buf, size_t buflen) +pn53x_get_information_about(nfc_device *pnd, char **pbuf) { + size_t buflen = 2048; + *pbuf = malloc(buflen); + char *buf = *pbuf; + int res; if ((res = snprintf(buf, buflen, "chip: %s\n", CHIP_DATA(pnd)->firmware_text)) < 0) { return NFC_ESOFT; diff --git a/libnfc/chips/pn53x.h b/libnfc/chips/pn53x.h index fcee233..999b83d 100644 --- a/libnfc/chips/pn53x.h +++ b/libnfc/chips/pn53x.h @@ -388,7 +388,7 @@ int pn53x_check_error_frame(struct nfc_device *pnd, const uint8_t *pbtRxFrame 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_information_about(nfc_device *pnd, char *buf, size_t buflen); +int pn53x_get_information_about(nfc_device *pnd, char **pbuf); void pn53x_data_new(struct nfc_device *pnd, const struct pn53x_io *io); void pn53x_data_free(struct nfc_device *pnd); diff --git a/libnfc/nfc-internal.h b/libnfc/nfc-internal.h index 298ec56..e8a788a 100644 --- a/libnfc/nfc-internal.h +++ b/libnfc/nfc-internal.h @@ -162,7 +162,7 @@ struct nfc_driver { 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 (*device_get_information_about)(struct nfc_device *pnd, char *buf, size_t buflen); + int (*device_get_information_about)(struct nfc_device *pnd, char **buf); int (*abort_command)(struct nfc_device *pnd); int (*idle)(struct nfc_device *pnd); diff --git a/libnfc/nfc.c b/libnfc/nfc.c index a8e388b..17b9a46 100644 --- a/libnfc/nfc.c +++ b/libnfc/nfc.c @@ -201,7 +201,7 @@ nfc_open(nfc_context *context, const nfc_connstring connstring) // Specific device is requested: using device description if (0 != strncmp(ndr->name, ncs, strlen(ndr->name))) { // Check if connstring driver is usb -> accept any driver *_usb - if ((0 != strncmp("usb", ncs, strlen("usb"))) || 0 != strncmp ("_usb", ndr->name + (strlen(ndr->name) - 4), 4)) { + if ((0 != strncmp("usb", ncs, strlen("usb"))) || 0 != strncmp("_usb", ndr->name + (strlen(ndr->name) - 4), 4)) { pndr++; continue; } @@ -1076,13 +1076,14 @@ nfc_version(void) * @brief Print information about NFC device * @return Upon successful return, this function returns the number of characters printed (excluding the null byte used to end output to strings), otherwise returns libnfc's error code (negative value) * @param pnd \a nfc_device struct pointer that represent currently used device - * @param buf string to print information - * @param buflen buf length + * @param buf pointer where string will be allocated, then information printed + * + * @warning *buf must be freed. */ int -nfc_device_get_information_about(nfc_device *pnd, char *buf, size_t buflen) +nfc_device_get_information_about(nfc_device *pnd, char **buf) { - HAL(device_get_information_about, pnd, buf, buflen); + HAL(device_get_information_about, pnd, buf); } /** @ingroup string-converter diff --git a/utils/nfc-probe.c b/utils/nfc-probe.c index 0c9a6fe..a5ef1c8 100644 --- a/utils/nfc-probe.c +++ b/utils/nfc-probe.c @@ -104,14 +104,15 @@ main(int argc, const char *argv[]) } printf("%d NFC device(s) found:\n", (int)szDeviceFound); - char strinfo[1024]; + char *strinfo = NULL; for (i = 0; i < szDeviceFound; i++) { pnd = nfc_open(NULL, connstrings[i]); if (pnd != NULL) { printf("- %s:\n %s\n", nfc_device_get_name(pnd), nfc_device_get_connstring(pnd)); if (verbose) { - if (nfc_device_get_information_about(pnd, strinfo, sizeof(strinfo)) >= 0) { + if (nfc_device_get_information_about(pnd, &strinfo) >= 0) { printf("%s", strinfo); + free(strinfo); } } nfc_close(pnd);