nfc_device_get_information_about() now allocates returned string.
Note: must be freed by free().
This commit is contained in:
parent
2aba0f962a
commit
de827ab583
6 changed files with 17 additions and 11 deletions
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
11
libnfc/nfc.c
11
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
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue