2010-01-10 19:14:26 +01:00
|
|
|
|
/*-
|
2009-10-12 16:52:26 +02:00
|
|
|
|
* Public platform independent Near Field Communication (NFC) library
|
2012-05-29 02:33:22 +02:00
|
|
|
|
*
|
2010-10-14 13:12:23 +02:00
|
|
|
|
* Copyright (C) 2009, Roel Verdult, Romuald Conty
|
|
|
|
|
* Copyright (C) 2010, Roel Verdult, Romuald Conty, Romain Tartière
|
2011-03-02 16:00:44 +01:00
|
|
|
|
* Copyright (C) 2011, Romuald Conty, Romain Tartière
|
2012-05-29 02:33:22 +02:00
|
|
|
|
*
|
2009-10-12 16:52:26 +02:00
|
|
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
|
|
|
* under the terms of the GNU Lesser General Public License as published by the
|
|
|
|
|
* Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
|
* option) any later version.
|
2012-05-29 02:33:22 +02:00
|
|
|
|
*
|
2009-10-12 16:52:26 +02:00
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
|
* more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2010-01-10 19:14:26 +01:00
|
|
|
|
*/
|
2010-09-07 19:51:03 +02:00
|
|
|
|
|
2012-05-29 02:33:22 +02:00
|
|
|
|
/**
|
2009-11-04 11:14:17 +01:00
|
|
|
|
* @file nfc.c
|
2009-11-18 12:52:18 +01:00
|
|
|
|
* @brief NFC library implementation
|
2009-10-12 16:52:26 +02:00
|
|
|
|
*/
|
2012-01-30 12:00:02 +01:00
|
|
|
|
/**
|
|
|
|
|
* @defgroup lib Library initialization/deinitialization
|
|
|
|
|
* This page details how to initialize and deinitialize libnfc. Initialization
|
|
|
|
|
* must be performed before using any libnfc functionality, and similarly you
|
|
|
|
|
* must not call any libnfc functions after deinitialization.
|
|
|
|
|
*/
|
|
|
|
|
/**
|
2012-05-29 02:33:22 +02:00
|
|
|
|
* @defgroup dev NFC Device/Hardware manipulation
|
2012-01-31 10:49:43 +01:00
|
|
|
|
* The functionality documented below is designed to help with the following
|
|
|
|
|
* operations:
|
|
|
|
|
* - Enumerating the NFC devices currently attached to the system
|
|
|
|
|
* - Opening and closing the chosen device
|
2012-05-29 02:33:22 +02:00
|
|
|
|
*/
|
2012-01-30 12:00:02 +01:00
|
|
|
|
/**
|
|
|
|
|
* @defgroup initiator NFC initiator
|
2012-01-31 15:28:45 +01:00
|
|
|
|
* This page details how to act as "reader".
|
2012-05-29 02:33:22 +02:00
|
|
|
|
*/
|
2012-01-30 12:00:02 +01:00
|
|
|
|
/**
|
|
|
|
|
* @defgroup target NFC target
|
2012-01-31 15:28:45 +01:00
|
|
|
|
* This page details how to act as tag (i.e. MIFARE Classic) or NFC target device.
|
2012-05-29 02:33:22 +02:00
|
|
|
|
*/
|
2012-01-30 12:00:02 +01:00
|
|
|
|
/**
|
|
|
|
|
* @defgroup error Error reporting
|
2012-01-31 15:28:45 +01:00
|
|
|
|
* Most libnfc functions return 0 on success or one of error codes defined on failure.
|
2012-05-29 02:33:22 +02:00
|
|
|
|
*/
|
2012-01-30 12:00:02 +01:00
|
|
|
|
/**
|
|
|
|
|
* @defgroup data Special data accessors
|
2012-01-31 15:28:45 +01:00
|
|
|
|
* The functionnality documented below allow to access to special data as device name or device connstring.
|
2012-05-29 02:33:22 +02:00
|
|
|
|
*/
|
2012-01-30 12:00:02 +01:00
|
|
|
|
/**
|
|
|
|
|
* @defgroup properties Properties accessors
|
2012-01-31 15:28:45 +01:00
|
|
|
|
* The functionnality documented below allow to configure parameters and registers.
|
2012-05-29 02:33:22 +02:00
|
|
|
|
*/
|
2012-01-30 12:00:02 +01:00
|
|
|
|
/**
|
|
|
|
|
* @defgroup misc Miscellaneous
|
2012-05-29 02:33:22 +02:00
|
|
|
|
*
|
|
|
|
|
*/
|
2009-04-29 14:47:41 +02:00
|
|
|
|
|
2011-03-02 16:00:44 +01:00
|
|
|
|
/* vim:set ts=2 sw=2 et: */
|
|
|
|
|
|
2010-01-15 11:18:11 +01:00
|
|
|
|
#ifdef HAVE_CONFIG_H
|
2010-09-07 19:51:03 +02:00
|
|
|
|
# include "config.h"
|
2010-01-15 11:18:11 +01:00
|
|
|
|
#endif // HAVE_CONFIG_H
|
|
|
|
|
|
2011-03-04 20:59:49 +01:00
|
|
|
|
#include <fcntl.h>
|
2009-04-29 14:47:41 +02:00
|
|
|
|
#include <stdio.h>
|
2010-01-13 17:23:06 +01:00
|
|
|
|
#include <stdlib.h>
|
2009-05-27 14:18:21 +02:00
|
|
|
|
#include <stddef.h>
|
2009-04-29 14:47:41 +02:00
|
|
|
|
#include <string.h>
|
|
|
|
|
|
2009-12-01 15:23:00 +01:00
|
|
|
|
#include <nfc/nfc.h>
|
2009-11-24 14:03:48 +01:00
|
|
|
|
|
2011-03-02 16:00:44 +01:00
|
|
|
|
#include "nfc-internal.h"
|
2011-09-12 16:50:01 +02:00
|
|
|
|
#include "drivers.h"
|
2009-07-15 19:45:38 +02:00
|
|
|
|
|
2011-09-12 16:50:01 +02:00
|
|
|
|
#define LOG_CATEGORY "libnfc.general"
|
|
|
|
|
|
2012-01-17 15:17:01 +01:00
|
|
|
|
const struct nfc_driver *nfc_drivers[] = {
|
2011-03-05 20:54:52 +01:00
|
|
|
|
# if defined (DRIVER_PN53X_USB_ENABLED)
|
|
|
|
|
&pn53x_usb_driver,
|
|
|
|
|
# endif /* DRIVER_PN53X_USB_ENABLED */
|
2012-05-02 01:09:57 +02:00
|
|
|
|
# if defined (DRIVER_ACR122_PCSC_ENABLED)
|
|
|
|
|
&acr122_pcsc_driver,
|
|
|
|
|
# endif /* DRIVER_ACR122_PCSC_ENABLED */
|
|
|
|
|
# if defined (DRIVER_ACR122_USB_ENABLED)
|
2012-01-26 16:23:11 +01:00
|
|
|
|
&acr122_usb_driver,
|
2012-05-02 01:09:57 +02:00
|
|
|
|
# endif /* DRIVER_ACR122_USB_ENABLED */
|
2011-11-23 04:05:12 +01:00
|
|
|
|
# if defined (DRIVER_ACR122S_ENABLED)
|
|
|
|
|
&acr122s_driver,
|
|
|
|
|
# endif /* DRIVER_ACR122S_ENABLED */
|
2011-03-02 16:00:44 +01:00
|
|
|
|
# if defined (DRIVER_PN532_UART_ENABLED)
|
|
|
|
|
&pn532_uart_driver,
|
|
|
|
|
# endif /* DRIVER_PN532_UART_ENABLED */
|
2011-03-04 10:28:25 +01:00
|
|
|
|
# if defined (DRIVER_ARYGON_ENABLED)
|
|
|
|
|
&arygon_driver,
|
|
|
|
|
# endif /* DRIVER_ARYGON_ENABLED */
|
2011-03-02 16:00:44 +01:00
|
|
|
|
NULL
|
|
|
|
|
};
|
|
|
|
|
|
2012-01-31 10:49:43 +01:00
|
|
|
|
/** @ingroup lib
|
2012-01-18 10:53:45 +01:00
|
|
|
|
* @brief Initialize libnfc.
|
2012-01-18 12:09:01 +01:00
|
|
|
|
* This function must be called before calling any other libnfc function
|
2012-01-18 17:22:06 +01:00
|
|
|
|
* @param context Optional output location for context pointer
|
2012-01-18 10:53:45 +01:00
|
|
|
|
*/
|
2012-03-01 14:33:13 +01:00
|
|
|
|
void
|
2012-01-18 17:22:06 +01:00
|
|
|
|
nfc_init(nfc_context *context)
|
2012-01-18 10:53:45 +01:00
|
|
|
|
{
|
2012-03-01 14:33:13 +01:00
|
|
|
|
(void) context;
|
2012-05-29 17:54:36 +02:00
|
|
|
|
log_init();
|
2012-01-18 10:53:45 +01:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-31 10:49:43 +01:00
|
|
|
|
/** @ingroup lib
|
2012-01-18 10:53:45 +01:00
|
|
|
|
* @brief Deinitialize libnfc.
|
2012-01-18 17:22:06 +01:00
|
|
|
|
* Should be called after closing all open devices and before your application terminates.
|
2012-03-01 14:33:13 +01:00
|
|
|
|
*@param context The context to deinitialize
|
2012-01-18 10:53:45 +01:00
|
|
|
|
*/
|
2012-03-01 14:33:13 +01:00
|
|
|
|
void
|
2012-01-18 17:22:06 +01:00
|
|
|
|
nfc_exit(nfc_context *context)
|
2012-01-18 10:53:45 +01:00
|
|
|
|
{
|
2012-03-01 14:33:13 +01:00
|
|
|
|
(void) context;
|
2012-05-29 17:54:36 +02:00
|
|
|
|
log_fini();
|
2012-01-18 10:53:45 +01:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-31 10:49:43 +01:00
|
|
|
|
/** @ingroup dev
|
2011-10-17 15:03:56 +02:00
|
|
|
|
* @brief Get the defaut NFC device
|
2012-05-29 02:33:22 +02:00
|
|
|
|
* @param connstring \a nfc_connstring pointer where the default connection string will be stored
|
2011-10-17 15:03:56 +02:00
|
|
|
|
* @return \e true on success
|
2010-01-10 19:14:26 +01:00
|
|
|
|
*
|
2011-10-17 15:03:56 +02:00
|
|
|
|
* This function fill \e connstring with the LIBNFC_DEFAULT_DEVICE environment variable content
|
|
|
|
|
* if is set otherwise it will search for the first available device, and fill
|
|
|
|
|
* \e connstring with the corresponding \a nfc_connstring value.
|
2010-01-10 19:14:26 +01:00
|
|
|
|
*
|
2011-10-17 15:03:56 +02:00
|
|
|
|
* This function returns true when LIBNFC_DEFAULT_DEVICE is set or an available device is found.
|
2012-05-29 02:33:22 +02:00
|
|
|
|
*
|
2011-10-17 15:03:56 +02:00
|
|
|
|
* @note The \e connstring content can be invalid if LIBNFC_DEFAULT_DEVICE is
|
|
|
|
|
* set with incorrect value.
|
|
|
|
|
*/
|
2012-05-29 02:33:22 +02:00
|
|
|
|
bool
|
2012-05-29 17:54:36 +02:00
|
|
|
|
nfc_get_default_device(nfc_connstring *connstring)
|
2011-10-17 15:03:56 +02:00
|
|
|
|
{
|
2012-05-29 17:54:36 +02:00
|
|
|
|
char *env_default_connstring = getenv("LIBNFC_DEFAULT_DEVICE");
|
2011-10-17 15:03:56 +02:00
|
|
|
|
if (NULL == env_default_connstring) {
|
|
|
|
|
// LIBNFC_DEFAULT_DEVICE is not set, we fallback on probing for the first available device
|
|
|
|
|
nfc_connstring listed_cs[1];
|
2012-05-29 17:54:36 +02:00
|
|
|
|
size_t szDeviceFound = nfc_list_devices(NULL, listed_cs, 1);
|
2011-10-17 15:03:56 +02:00
|
|
|
|
if (szDeviceFound) {
|
2012-05-29 17:54:36 +02:00
|
|
|
|
strncpy(*connstring, listed_cs[0], sizeof(nfc_connstring));
|
2011-10-17 15:03:56 +02:00
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2012-05-29 17:54:36 +02:00
|
|
|
|
strncpy(*connstring, env_default_connstring, sizeof(nfc_connstring));
|
2011-10-17 15:03:56 +02:00
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-31 10:49:43 +01:00
|
|
|
|
/** @ingroup dev
|
2012-01-17 16:21:56 +01:00
|
|
|
|
* @brief Open a NFC device
|
2012-01-30 10:43:58 +01:00
|
|
|
|
* @param context The context to operate on, or NULL for the default context.
|
2011-10-17 15:03:56 +02:00
|
|
|
|
* @param connstring The device connection string if specific device is wanted, \c NULL otherwise
|
2011-11-23 16:55:40 +01:00
|
|
|
|
* @return Returns pointer to a \a nfc_device struct if successfull; otherwise returns \c NULL value.
|
2010-01-10 19:14:26 +01:00
|
|
|
|
*
|
2011-10-17 15:03:56 +02:00
|
|
|
|
* If \e connstring is \c NULL, the \a nfc_get_default_device() function is used.
|
2012-05-29 02:33:22 +02:00
|
|
|
|
*
|
2011-10-17 15:03:56 +02:00
|
|
|
|
* If \e connstring is set, this function will try to claim the right device using information provided by \e connstring.
|
2010-01-10 19:14:26 +01:00
|
|
|
|
*
|
2011-10-17 15:03:56 +02:00
|
|
|
|
* When it has successfully claimed a NFC device, memory is allocated to save the device information.
|
2011-11-23 16:55:40 +01:00
|
|
|
|
* It will return a pointer to a \a nfc_device struct.
|
2010-09-29 16:26:06 +02:00
|
|
|
|
* This pointer should be supplied by every next functions of libnfc that should perform an action with this device.
|
2010-10-18 12:11:30 +02:00
|
|
|
|
*
|
2012-05-29 02:33:22 +02:00
|
|
|
|
* @note Depending on the desired operation mode, the device needs to be configured by using nfc_initiator_init() or nfc_target_init(),
|
2011-10-17 15:03:56 +02:00
|
|
|
|
* optionally followed by manual tuning of the parameters if the default parameters are not suiting your goals.
|
2010-01-10 19:14:26 +01:00
|
|
|
|
*/
|
2011-11-23 16:55:40 +01:00
|
|
|
|
nfc_device *
|
2012-05-29 17:54:36 +02:00
|
|
|
|
nfc_open(nfc_context *context, const nfc_connstring connstring)
|
2009-04-29 14:47:41 +02:00
|
|
|
|
{
|
2012-03-01 14:33:13 +01:00
|
|
|
|
(void) context;
|
2011-11-23 16:55:40 +01:00
|
|
|
|
nfc_device *pnd = NULL;
|
2011-03-02 16:00:44 +01:00
|
|
|
|
|
2011-10-17 15:03:56 +02:00
|
|
|
|
nfc_connstring ncs;
|
|
|
|
|
if (connstring == NULL) {
|
2012-05-29 17:54:36 +02:00
|
|
|
|
if (!nfc_get_default_device(&ncs)) {
|
|
|
|
|
log_fini();
|
2011-10-17 15:03:56 +02:00
|
|
|
|
return NULL;
|
2011-06-28 16:05:40 +02:00
|
|
|
|
}
|
2011-10-17 15:03:56 +02:00
|
|
|
|
} else {
|
2012-05-29 17:54:36 +02:00
|
|
|
|
strncpy(ncs, connstring, sizeof(nfc_connstring));
|
2011-06-28 16:05:40 +02:00
|
|
|
|
}
|
2012-05-29 02:33:22 +02:00
|
|
|
|
|
2009-04-29 14:47:41 +02:00
|
|
|
|
// Search through the device list for an available device
|
2012-01-17 15:17:01 +01:00
|
|
|
|
const struct nfc_driver *ndr;
|
|
|
|
|
const struct nfc_driver **pndr = nfc_drivers;
|
2011-03-02 16:00:44 +01:00
|
|
|
|
while ((ndr = *pndr)) {
|
2012-05-29 02:33:22 +02:00
|
|
|
|
// Specific device is requested: using device description
|
2012-05-29 17:54:36 +02:00
|
|
|
|
if (0 != strncmp(ndr->name, ncs, strlen(ndr->name))) {
|
2011-03-04 12:18:47 +01:00
|
|
|
|
pndr++;
|
2011-03-02 16:00:44 +01:00
|
|
|
|
continue;
|
2009-09-04 15:24:34 +02:00
|
|
|
|
}
|
2009-08-28 18:54:04 +02:00
|
|
|
|
|
2012-05-29 17:54:36 +02:00
|
|
|
|
pnd = ndr->open(ncs);
|
2012-01-17 16:21:56 +01:00
|
|
|
|
// Test if the opening was successful
|
2011-10-17 15:03:56 +02:00
|
|
|
|
if (pnd == NULL) {
|
2012-05-29 17:54:36 +02:00
|
|
|
|
log_put(LOG_CATEGORY, NFC_PRIORITY_TRACE, "Unable to open \"%s\".", ncs);
|
|
|
|
|
log_fini();
|
2009-11-09 12:23:33 +01:00
|
|
|
|
return pnd;
|
2009-09-07 12:15:34 +02:00
|
|
|
|
}
|
2012-05-29 02:33:22 +02:00
|
|
|
|
|
2012-05-29 17:54:36 +02:00
|
|
|
|
log_put(LOG_CATEGORY, NFC_PRIORITY_TRACE, "\"%s\" (%s) has been claimed.", pnd->name, pnd->connstring);
|
|
|
|
|
log_fini();
|
2011-10-17 15:03:56 +02:00
|
|
|
|
return pnd;
|
2009-04-29 14:47:41 +02:00
|
|
|
|
}
|
2011-10-17 15:03:56 +02:00
|
|
|
|
|
|
|
|
|
// Too bad, no driver can decode connstring
|
2012-05-29 17:54:36 +02:00
|
|
|
|
log_put(LOG_CATEGORY, NFC_PRIORITY_TRACE, "No driver available to handle \"%s\".", ncs);
|
|
|
|
|
log_fini();
|
2009-11-18 12:11:06 +01:00
|
|
|
|
return NULL;
|
2009-04-29 14:47:41 +02:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-31 10:49:43 +01:00
|
|
|
|
/** @ingroup dev
|
2012-01-17 15:52:39 +01:00
|
|
|
|
* @brief Close from a NFC device
|
2011-11-23 16:55:40 +01:00
|
|
|
|
* @param pnd \a nfc_device struct pointer that represent currently used device
|
2010-01-10 19:14:26 +01:00
|
|
|
|
*
|
2012-01-17 15:52:39 +01:00
|
|
|
|
* Initiator's selected tag is closed and the device, including allocated \a nfc_device struct, is released.
|
2010-01-10 19:14:26 +01:00
|
|
|
|
*/
|
2010-09-07 19:51:03 +02:00
|
|
|
|
void
|
2012-05-29 17:54:36 +02:00
|
|
|
|
nfc_close(nfc_device *pnd)
|
2009-04-29 14:47:41 +02:00
|
|
|
|
{
|
2010-09-07 19:51:03 +02:00
|
|
|
|
if (pnd) {
|
2011-05-09 12:09:40 +02:00
|
|
|
|
// Go in idle mode
|
2012-05-29 17:54:36 +02:00
|
|
|
|
nfc_idle(pnd);
|
2012-05-29 02:33:22 +02:00
|
|
|
|
// Close, clean up and release the device
|
2012-05-29 17:54:36 +02:00
|
|
|
|
pnd->driver->close(pnd);
|
2012-01-18 12:36:18 +01:00
|
|
|
|
|
2010-08-11 18:38:22 +02:00
|
|
|
|
}
|
2009-04-29 14:47:41 +02:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-31 10:49:43 +01:00
|
|
|
|
/** @ingroup dev
|
2010-09-10 15:35:25 +02:00
|
|
|
|
* @brief Probe for discoverable supported devices (ie. only available for some drivers)
|
2012-01-10 11:35:36 +01:00
|
|
|
|
* @return Returns the number of devices found.
|
2012-01-30 10:43:58 +01:00
|
|
|
|
* @param context The context to operate on, or NULL for the default context.
|
2012-01-31 10:49:43 +01:00
|
|
|
|
* @param connstrings array of \a nfc_connstring.
|
2012-01-30 10:43:58 +01:00
|
|
|
|
* @param szDevices size of the \a connstrings array.
|
2012-05-29 02:33:22 +02:00
|
|
|
|
*
|
2010-09-10 15:35:25 +02:00
|
|
|
|
*/
|
2012-01-10 11:35:36 +01:00
|
|
|
|
size_t
|
2012-05-29 17:54:36 +02:00
|
|
|
|
nfc_list_devices(nfc_context *context, nfc_connstring connstrings[] , size_t szDevices)
|
2010-09-10 15:35:25 +02:00
|
|
|
|
{
|
2012-01-10 11:35:36 +01:00
|
|
|
|
size_t szN;
|
|
|
|
|
size_t szDeviceFound = 0;
|
2012-01-17 15:17:01 +01:00
|
|
|
|
const struct nfc_driver *ndr;
|
|
|
|
|
const struct nfc_driver **pndr = nfc_drivers;
|
2011-09-12 16:50:01 +02:00
|
|
|
|
|
2012-03-01 14:33:13 +01:00
|
|
|
|
(void) context;
|
|
|
|
|
|
2011-03-02 16:00:44 +01:00
|
|
|
|
while ((ndr = *pndr)) {
|
|
|
|
|
szN = 0;
|
2012-05-29 17:54:36 +02:00
|
|
|
|
if (ndr->probe(connstrings + (szDeviceFound), szDevices - (szDeviceFound), &szN)) {
|
2012-01-10 11:35:36 +01:00
|
|
|
|
szDeviceFound += szN;
|
2012-05-29 17:54:36 +02:00
|
|
|
|
log_put(LOG_CATEGORY, NFC_PRIORITY_TRACE, "%ld device(s) found using %s driver", (unsigned long) szN, ndr->name);
|
2012-01-10 11:35:36 +01:00
|
|
|
|
if (szDeviceFound == szDevices)
|
2012-05-29 17:52:51 +02:00
|
|
|
|
break;
|
2010-09-10 15:35:25 +02:00
|
|
|
|
}
|
2011-03-02 16:00:44 +01:00
|
|
|
|
pndr++;
|
2010-09-10 15:35:25 +02:00
|
|
|
|
}
|
2012-05-29 17:54:36 +02:00
|
|
|
|
log_fini();
|
2012-01-10 11:35:36 +01:00
|
|
|
|
return szDeviceFound;
|
2010-09-10 15:35:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-31 10:49:43 +01:00
|
|
|
|
/** @ingroup properties
|
2011-12-14 14:27:11 +01:00
|
|
|
|
* @brief Set a device's integer-property value
|
|
|
|
|
* @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 property \a nfc_property which will be set
|
|
|
|
|
* @param value integer value
|
|
|
|
|
*
|
|
|
|
|
* Sets integer property.
|
|
|
|
|
*
|
|
|
|
|
* @see nfc_property enum values
|
|
|
|
|
*/
|
2012-05-29 02:33:22 +02:00
|
|
|
|
int
|
2012-05-29 17:54:36 +02:00
|
|
|
|
nfc_device_set_property_int(nfc_device *pnd, const nfc_property property, const int value)
|
2011-12-14 14:27:11 +01:00
|
|
|
|
{
|
2012-05-29 17:54:36 +02:00
|
|
|
|
HAL(device_set_property_int, pnd, property, value);
|
2011-12-14 14:27:11 +01:00
|
|
|
|
}
|
|
|
|
|
|
2011-12-14 17:01:00 +01:00
|
|
|
|
|
2012-01-31 10:49:43 +01:00
|
|
|
|
/** @ingroup properties
|
2011-12-14 17:01:00 +01:00
|
|
|
|
* @brief Set a device's boolean-property value
|
|
|
|
|
* @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 property \a nfc_property which will be set
|
|
|
|
|
* @param bEnable boolean to activate/disactivate the property
|
2010-01-10 19:14:26 +01:00
|
|
|
|
*
|
2010-10-14 13:12:23 +02:00
|
|
|
|
* Configures parameters and registers that control for example timing,
|
|
|
|
|
* modulation, frame and error handling. There are different categories for
|
|
|
|
|
* configuring the \e PN53X chip features (handle, activate, infinite and
|
|
|
|
|
* accept).
|
2010-01-10 19:14:26 +01:00
|
|
|
|
*/
|
2011-12-14 17:01:00 +01:00
|
|
|
|
int
|
2012-05-29 17:54:36 +02:00
|
|
|
|
nfc_device_set_property_bool(nfc_device *pnd, const nfc_property property, const bool bEnable)
|
2009-04-29 14:47:41 +02:00
|
|
|
|
{
|
2012-05-29 17:54:36 +02:00
|
|
|
|
HAL(device_set_property_bool, pnd, property, bEnable);
|
2009-04-29 14:47:41 +02:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-31 10:49:43 +01:00
|
|
|
|
/** @ingroup initiator
|
2010-01-10 19:14:26 +01:00
|
|
|
|
* @brief Initialize NFC device as initiator (reader)
|
2011-12-15 12:46:14 +01:00
|
|
|
|
* @return Returns 0 on success, otherwise returns libnfc's error code (negative value)
|
2011-11-23 16:55:40 +01:00
|
|
|
|
* @param pnd \a nfc_device struct pointer that represent currently used device
|
2010-01-10 19:14:26 +01:00
|
|
|
|
*
|
2010-04-09 18:20:47 +02:00
|
|
|
|
* The NFC device is configured to function as RFID reader.
|
|
|
|
|
* After initialization it can be used to communicate to passive RFID tags and active NFC devices.
|
|
|
|
|
* The reader will act as initiator to communicate peer 2 peer (NFCIP) to other active NFC devices.
|
2011-12-14 17:01:00 +01:00
|
|
|
|
* - Crc is handled by the device (NP_HANDLE_CRC = true)
|
|
|
|
|
* - Parity is handled the device (NP_HANDLE_PARITY = true)
|
|
|
|
|
* - Cryto1 cipher is disabled (NP_ACTIVATE_CRYPTO1 = false)
|
|
|
|
|
* - Easy framing is enabled (NP_EASY_FRAMING = true)
|
|
|
|
|
* - Auto-switching in ISO14443-4 mode is enabled (NP_AUTO_ISO14443_4 = true)
|
|
|
|
|
* - Invalid frames are not accepted (NP_ACCEPT_INVALID_FRAMES = false)
|
|
|
|
|
* - Multiple frames are not accepted (NP_ACCEPT_MULTIPLE_FRAMES = false)
|
|
|
|
|
* - 14443-A mode is activated (NP_FORCE_ISO14443_A = true)
|
|
|
|
|
* - speed is set to 106 kbps (NP_FORCE_SPEED_106 = true)
|
|
|
|
|
* - Let the device try forever to find a target (NP_INFINITE_SELECT = true)
|
2011-05-11 01:44:27 +02:00
|
|
|
|
* - RF field is shortly dropped (if it was enabled) then activated again
|
2010-01-10 19:14:26 +01:00
|
|
|
|
*/
|
2011-12-15 12:46:14 +01:00
|
|
|
|
int
|
2012-05-29 17:54:36 +02:00
|
|
|
|
nfc_initiator_init(nfc_device *pnd)
|
2009-04-29 14:47:41 +02:00
|
|
|
|
{
|
2011-12-15 12:46:14 +01:00
|
|
|
|
int res = 0;
|
2011-05-05 12:12:26 +02:00
|
|
|
|
// Drop the field for a while
|
2012-05-29 17:54:36 +02:00
|
|
|
|
if ((res = nfc_device_set_property_bool(pnd, NP_ACTIVATE_FIELD, false)) < 0)
|
2011-12-15 12:46:14 +01:00
|
|
|
|
return res;
|
2011-05-11 01:44:27 +02:00
|
|
|
|
// Enable field so more power consuming cards can power themselves up
|
2012-05-29 17:54:36 +02:00
|
|
|
|
if ((res = nfc_device_set_property_bool(pnd, NP_ACTIVATE_FIELD, true)) < 0)
|
2011-12-15 12:46:14 +01:00
|
|
|
|
return res;
|
2011-05-11 01:44:27 +02:00
|
|
|
|
// Let the device try forever to find a target/tag
|
2012-05-29 17:54:36 +02:00
|
|
|
|
if ((res = nfc_device_set_property_bool(pnd, NP_INFINITE_SELECT, true)) < 0)
|
2011-12-15 12:46:14 +01:00
|
|
|
|
return res;
|
2011-05-11 01:44:27 +02:00
|
|
|
|
// Activate auto ISO14443-4 switching by default
|
2012-05-29 17:54:36 +02:00
|
|
|
|
if ((res = nfc_device_set_property_bool(pnd, NP_AUTO_ISO14443_4, true)) < 0)
|
2011-12-15 12:46:14 +01:00
|
|
|
|
return res;
|
2011-05-05 12:12:26 +02:00
|
|
|
|
// Force 14443-A mode
|
2012-05-29 17:54:36 +02:00
|
|
|
|
if ((res = nfc_device_set_property_bool(pnd, NP_FORCE_ISO14443_A, true)) < 0)
|
2011-12-15 12:46:14 +01:00
|
|
|
|
return res;
|
2011-05-06 16:14:06 +02:00
|
|
|
|
// Force speed at 106kbps
|
2012-05-29 17:54:36 +02:00
|
|
|
|
if ((res = nfc_device_set_property_bool(pnd, NP_FORCE_SPEED_106, true)) < 0)
|
2011-12-15 12:46:14 +01:00
|
|
|
|
return res;
|
2011-05-05 12:12:26 +02:00
|
|
|
|
// Disallow invalid frame
|
2012-05-29 17:54:36 +02:00
|
|
|
|
if ((res = nfc_device_set_property_bool(pnd, NP_ACCEPT_INVALID_FRAMES, false)) < 0)
|
2011-12-15 12:46:14 +01:00
|
|
|
|
return res;
|
2011-05-05 12:12:26 +02:00
|
|
|
|
// Disallow multiple frames
|
2012-05-29 17:54:36 +02:00
|
|
|
|
if ((res = nfc_device_set_property_bool(pnd, NP_ACCEPT_MULTIPLE_FRAMES, false)) < 0)
|
2011-12-15 12:46:14 +01:00
|
|
|
|
return res;
|
2011-05-05 12:12:26 +02:00
|
|
|
|
// Make sure we reset the CRC and parity to chip handling.
|
2012-05-29 17:54:36 +02:00
|
|
|
|
if ((res = nfc_device_set_property_bool(pnd, NP_HANDLE_CRC, true)) < 0)
|
2011-12-15 12:46:14 +01:00
|
|
|
|
return res;
|
2012-05-29 17:54:36 +02:00
|
|
|
|
if ((res = nfc_device_set_property_bool(pnd, NP_HANDLE_PARITY, true)) < 0)
|
2011-12-15 12:46:14 +01:00
|
|
|
|
return res;
|
2011-05-05 12:12:26 +02:00
|
|
|
|
// Activate "easy framing" feature by default
|
2012-05-29 17:54:36 +02:00
|
|
|
|
if ((res = nfc_device_set_property_bool(pnd, NP_EASY_FRAMING, true)) < 0)
|
2011-12-15 12:46:14 +01:00
|
|
|
|
return res;
|
2011-05-05 12:12:26 +02:00
|
|
|
|
// Deactivate the CRYPTO1 cipher, it may could cause problems when still active
|
2012-05-29 17:54:36 +02:00
|
|
|
|
if ((res = nfc_device_set_property_bool(pnd, NP_ACTIVATE_CRYPTO1, false)) < 0)
|
2011-12-15 12:46:14 +01:00
|
|
|
|
return res;
|
2011-05-05 12:12:26 +02:00
|
|
|
|
|
2012-05-29 17:54:36 +02:00
|
|
|
|
HAL(initiator_init, pnd);
|
2009-04-29 14:47:41 +02:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-31 10:49:43 +01:00
|
|
|
|
/** @ingroup initiator
|
2010-01-10 19:14:26 +01:00
|
|
|
|
* @brief Select a passive or emulated tag
|
2011-12-21 12:33:21 +01:00
|
|
|
|
* @return Returns selected passive target count on success, otherwise returns libnfc's error code (negative value)
|
2010-07-22 18:16:37 +02:00
|
|
|
|
*
|
2011-11-23 16:55:40 +01:00
|
|
|
|
* @param pnd \a nfc_device struct pointer that represent currently used device
|
2010-10-14 13:12:23 +02:00
|
|
|
|
* @param nm desired modulation
|
|
|
|
|
* @param pbtInitData optional initiator data used for Felica, ISO14443B, Topaz polling or to select a specific UID in ISO14443A.
|
|
|
|
|
* @param szInitData length of initiator data \a pbtInitData.
|
2010-10-18 18:17:01 +02:00
|
|
|
|
* @note pbtInitData is used with different kind of data depending on modulation type:
|
2010-10-18 11:53:14 +02:00
|
|
|
|
* - for an ISO/IEC 14443 type A modulation, pbbInitData contains the UID you want to select;
|
|
|
|
|
* - for an ISO/IEC 14443 type B modulation, pbbInitData contains Application Family Identifier (AFI) (see ISO/IEC 14443-3);
|
|
|
|
|
* - for a FeliCa modulation, pbbInitData contains polling payload (see ISO/IEC 18092 11.2.2.5).
|
|
|
|
|
*
|
2011-11-23 16:55:40 +01:00
|
|
|
|
* @param[out] pnt \a nfc_target struct pointer which will filled if available
|
2010-09-29 16:26:06 +02:00
|
|
|
|
*
|
2012-05-29 02:33:22 +02:00
|
|
|
|
* The NFC device will try to find one available passive tag or emulated tag.
|
2010-09-29 16:26:06 +02:00
|
|
|
|
*
|
2010-10-14 13:12:23 +02:00
|
|
|
|
* The chip needs to know with what kind of tag it is dealing with, therefore
|
|
|
|
|
* the initial modulation and speed (106, 212 or 424 kbps) should be supplied.
|
2010-01-10 19:14:26 +01:00
|
|
|
|
*/
|
2011-12-19 17:27:50 +01:00
|
|
|
|
int
|
2012-05-29 17:54:36 +02:00
|
|
|
|
nfc_initiator_select_passive_target(nfc_device *pnd,
|
|
|
|
|
const nfc_modulation nm,
|
|
|
|
|
const uint8_t *pbtInitData, const size_t szInitData,
|
|
|
|
|
nfc_target *pnt)
|
2009-04-29 14:47:41 +02:00
|
|
|
|
{
|
2011-11-24 11:54:42 +01:00
|
|
|
|
uint8_t abtInit[MAX(12, szInitData)];
|
2010-10-13 19:43:23 +02:00
|
|
|
|
size_t szInit;
|
2010-08-10 21:50:29 +02:00
|
|
|
|
|
2010-10-13 19:43:23 +02:00
|
|
|
|
switch (nm.nmt) {
|
2012-05-29 17:52:51 +02:00
|
|
|
|
case NMT_ISO14443A:
|
2012-05-29 17:54:36 +02:00
|
|
|
|
iso14443_cascade_uid(pbtInitData, szInitData, abtInit, &szInit);
|
2012-05-29 17:52:51 +02:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case NMT_JEWEL:
|
|
|
|
|
case NMT_ISO14443B:
|
|
|
|
|
case NMT_ISO14443BI:
|
|
|
|
|
case NMT_ISO14443B2SR:
|
|
|
|
|
case NMT_ISO14443B2CT:
|
|
|
|
|
case NMT_FELICA:
|
|
|
|
|
case NMT_DEP:
|
2012-05-29 17:54:36 +02:00
|
|
|
|
memcpy(abtInit, pbtInitData, szInitData);
|
2012-05-29 17:52:51 +02:00
|
|
|
|
szInit = szInitData;
|
|
|
|
|
break;
|
2009-10-19 15:08:29 +02:00
|
|
|
|
}
|
2010-09-07 19:51:03 +02:00
|
|
|
|
|
2012-05-29 17:54:36 +02:00
|
|
|
|
HAL(initiator_select_passive_target, pnd, nm, abtInit, szInit, pnt);
|
2009-04-29 14:47:41 +02:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-31 10:49:43 +01:00
|
|
|
|
/** @ingroup initiator
|
2010-09-09 00:20:09 +02:00
|
|
|
|
* @brief List passive or emulated tags
|
2011-12-15 12:46:14 +01:00
|
|
|
|
* @return Returns the number of targets found on success, otherwise returns libnfc's error code (negative value)
|
2010-09-09 00:20:09 +02:00
|
|
|
|
*
|
2011-11-23 16:55:40 +01:00
|
|
|
|
* @param pnd \a nfc_device struct pointer that represent currently used device
|
2010-10-14 13:12:23 +02:00
|
|
|
|
* @param nm desired modulation
|
2011-11-23 16:55:40 +01:00
|
|
|
|
* @param[out] ant array of \a nfc_target that will be filled with targets info
|
2010-10-14 13:44:43 +02:00
|
|
|
|
* @param szTargets size of \a ant (will be the max targets listed)
|
2010-10-14 13:12:23 +02:00
|
|
|
|
*
|
|
|
|
|
* The NFC device will try to find the available passive tags. Some NFC devices
|
|
|
|
|
* are capable to emulate passive tags. The standards (ISO18092 and ECMA-340)
|
|
|
|
|
* describe the modulation that can be used for reader to passive
|
|
|
|
|
* communications. The chip needs to know with what kind of tag it is dealing
|
|
|
|
|
* with, therefore the initial modulation and speed (106, 212 or 424 kbps)
|
|
|
|
|
* should be supplied.
|
2010-09-09 00:20:09 +02:00
|
|
|
|
*/
|
2011-12-15 12:46:14 +01:00
|
|
|
|
int
|
2012-05-29 17:54:36 +02:00
|
|
|
|
nfc_initiator_list_passive_targets(nfc_device *pnd,
|
|
|
|
|
const nfc_modulation nm,
|
|
|
|
|
nfc_target ant[], const size_t szTargets)
|
2010-07-30 15:27:03 +02:00
|
|
|
|
{
|
2011-11-23 16:55:40 +01:00
|
|
|
|
nfc_target nt;
|
2010-09-07 19:51:03 +02:00
|
|
|
|
size_t szTargetFound = 0;
|
2011-11-24 11:54:42 +01:00
|
|
|
|
uint8_t *pbtInitData = NULL;
|
2010-09-07 19:51:03 +02:00
|
|
|
|
size_t szInitDataLen = 0;
|
2011-12-15 12:46:14 +01:00
|
|
|
|
int res = 0;
|
2010-07-30 15:27:03 +02:00
|
|
|
|
|
2011-12-15 17:02:38 +01:00
|
|
|
|
pnd->last_error = 0;
|
2010-08-15 16:08:29 +02:00
|
|
|
|
|
2010-10-18 12:11:30 +02:00
|
|
|
|
// Let the reader only try once to find a tag
|
2012-05-29 17:54:36 +02:00
|
|
|
|
if ((res = nfc_device_set_property_bool(pnd, NP_INFINITE_SELECT, false)) < 0) {
|
2011-12-15 12:46:14 +01:00
|
|
|
|
return res;
|
2010-10-18 12:11:30 +02:00
|
|
|
|
}
|
2010-09-07 19:51:03 +02:00
|
|
|
|
|
2012-05-29 17:54:36 +02:00
|
|
|
|
prepare_initiator_data(nm, &pbtInitData, &szInitDataLen);
|
2010-09-21 18:15:27 +02:00
|
|
|
|
|
2012-05-29 17:54:36 +02:00
|
|
|
|
while (nfc_initiator_select_passive_target(pnd, nm, pbtInitData, szInitDataLen, &nt) > 0) {
|
|
|
|
|
nfc_initiator_deselect_target(pnd);
|
2011-06-07 22:36:20 +02:00
|
|
|
|
if (szTargets == szTargetFound) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
2011-06-13 23:46:01 +02:00
|
|
|
|
size_t i;
|
2011-06-07 22:36:20 +02:00
|
|
|
|
bool seen = false;
|
|
|
|
|
// Check if we've already seen this tag
|
|
|
|
|
for (i = 0; i < szTargetFound; i++) {
|
2012-05-29 17:54:36 +02:00
|
|
|
|
if (memcmp(&(ant[i]), &nt, sizeof(nfc_target)) == 0) {
|
2011-06-07 22:36:20 +02:00
|
|
|
|
seen = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (seen) {
|
2010-09-21 18:05:24 +02:00
|
|
|
|
break;
|
2010-07-30 15:27:03 +02:00
|
|
|
|
}
|
2012-05-29 17:54:36 +02:00
|
|
|
|
memcpy(&(ant[szTargetFound]), &nt, sizeof(nfc_target));
|
2010-07-30 15:27:03 +02:00
|
|
|
|
szTargetFound++;
|
2010-09-28 17:31:31 +02:00
|
|
|
|
// deselect has no effect on FeliCa and Jewel cards so we'll stop after one...
|
2011-05-06 16:14:06 +02:00
|
|
|
|
// ISO/IEC 14443 B' cards are polled at 100% probability so it's not possible to detect correctly two cards at the same time
|
2011-05-12 01:00:54 +02:00
|
|
|
|
if ((nm.nmt == NMT_FELICA) || (nm.nmt == NMT_JEWEL) || (nm.nmt == NMT_ISO14443BI) || (nm.nmt == NMT_ISO14443B2SR) || (nm.nmt == NMT_ISO14443B2CT)) {
|
2011-05-03 21:22:28 +02:00
|
|
|
|
break;
|
2010-09-21 18:15:27 +02:00
|
|
|
|
}
|
2010-07-30 15:27:03 +02:00
|
|
|
|
}
|
2011-12-15 12:46:14 +01:00
|
|
|
|
return szTargetFound;
|
2010-07-30 15:27:03 +02:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-31 10:49:43 +01:00
|
|
|
|
/** @ingroup initiator
|
2010-04-09 18:20:47 +02:00
|
|
|
|
* @brief Polling for NFC targets
|
2011-12-22 12:16:27 +01:00
|
|
|
|
* @return Returns polled targets count, otherwise returns libnfc's error code (negative value).
|
2010-09-29 16:26:06 +02:00
|
|
|
|
*
|
2011-11-23 16:55:40 +01:00
|
|
|
|
* @param pnd \a nfc_device struct pointer that represent currently used device
|
2012-01-31 10:49:43 +01:00
|
|
|
|
* @param pnmModulations desired modulations
|
2012-01-30 10:43:58 +01:00
|
|
|
|
* @param szModulations size of \a pnmModulations
|
2011-10-03 13:19:08 +02:00
|
|
|
|
* @param uiPollNr specifies the number of polling (0x01 – 0xFE: 1 up to 254 polling, 0xFF: Endless polling)
|
2010-04-09 18:20:47 +02:00
|
|
|
|
* @note one polling is a polling for each desired target type
|
2011-10-03 13:19:08 +02:00
|
|
|
|
* @param uiPeriod indicates the polling period in units of 150 ms (0x01 – 0x0F: 150ms – 2.25s)
|
|
|
|
|
* @note e.g. if uiPeriod=10, it will poll each desired target type during 1.5s
|
2011-11-23 16:55:40 +01:00
|
|
|
|
* @param[out] pnt pointer on \a nfc_target (over)writable struct
|
2010-04-09 18:20:47 +02:00
|
|
|
|
*/
|
2011-12-20 16:46:35 +01:00
|
|
|
|
int
|
2012-05-29 17:54:36 +02:00
|
|
|
|
nfc_initiator_poll_target(nfc_device *pnd,
|
|
|
|
|
const nfc_modulation *pnmModulations, const size_t szModulations,
|
|
|
|
|
const uint8_t uiPollNr, const uint8_t uiPeriod,
|
|
|
|
|
nfc_target *pnt)
|
2010-04-09 18:20:47 +02:00
|
|
|
|
{
|
2012-05-29 17:54:36 +02:00
|
|
|
|
HAL(initiator_poll_target, pnd, pnmModulations, szModulations, uiPollNr, uiPeriod, pnt);
|
2010-04-09 18:20:47 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-10-13 19:43:23 +02:00
|
|
|
|
|
2012-01-31 10:49:43 +01:00
|
|
|
|
/** @ingroup initiator
|
2010-10-14 13:12:23 +02:00
|
|
|
|
* @brief Select a target and request active or passive mode for D.E.P. (Data Exchange Protocol)
|
2012-01-05 02:39:10 +01:00
|
|
|
|
* @return Returns selected D.E.P targets count on success, otherwise returns libnfc's error code (negative value).
|
2010-09-29 16:26:06 +02:00
|
|
|
|
*
|
2011-11-23 16:55:40 +01:00
|
|
|
|
* @param pnd \a nfc_device struct pointer that represent currently used device
|
2010-10-14 13:12:23 +02:00
|
|
|
|
* @param ndm desired D.E.P. mode (\a NDM_ACTIVE or \a NDM_PASSIVE for active, respectively passive mode)
|
2012-01-31 16:35:13 +01:00
|
|
|
|
* @param nbr desired baud rate
|
2011-11-23 16:55:40 +01:00
|
|
|
|
* @param ndiInitiator pointer \a nfc_dep_info struct that contains \e NFCID3 and \e General \e Bytes to set to the initiator device (optionnal, can be \e NULL)
|
|
|
|
|
* @param[out] pnt is a \a nfc_target struct pointer where target information will be put.
|
2012-01-30 10:43:58 +01:00
|
|
|
|
* @param timeout in milliseconds
|
2010-01-10 19:14:26 +01:00
|
|
|
|
*
|
2010-10-11 16:49:08 +02:00
|
|
|
|
* The NFC device will try to find an available D.E.P. target. The standards
|
|
|
|
|
* (ISO18092 and ECMA-340) describe the modulation that can be used for reader
|
|
|
|
|
* to passive communications.
|
2012-05-29 02:33:22 +02:00
|
|
|
|
*
|
2011-11-23 16:55:40 +01:00
|
|
|
|
* @note \a nfc_dep_info will be returned when the target was acquired successfully.
|
2010-01-10 19:14:26 +01:00
|
|
|
|
*/
|
2011-12-21 10:15:44 +01:00
|
|
|
|
int
|
2012-05-29 17:54:36 +02:00
|
|
|
|
nfc_initiator_select_dep_target(nfc_device *pnd,
|
|
|
|
|
const nfc_dep_mode ndm, const nfc_baud_rate nbr,
|
|
|
|
|
const nfc_dep_info *pndiInitiator, nfc_target *pnt, const int timeout)
|
2009-04-29 14:47:41 +02:00
|
|
|
|
{
|
2012-05-29 17:54:36 +02:00
|
|
|
|
HAL(initiator_select_dep_target, pnd, ndm, nbr, pndiInitiator, pnt, timeout);
|
2010-09-10 15:35:25 +02:00
|
|
|
|
}
|
2010-08-24 12:30:18 +02:00
|
|
|
|
|
2012-01-31 10:49:43 +01:00
|
|
|
|
/** @ingroup initiator
|
2012-01-10 15:17:18 +01:00
|
|
|
|
* @brief Poll a target and request active or passive mode for D.E.P. (Data Exchange Protocol)
|
|
|
|
|
* @return Returns selected D.E.P targets count on success, otherwise returns libnfc's error code (negative value).
|
|
|
|
|
*
|
|
|
|
|
* @param pnd \a nfc_device struct pointer that represent currently used device
|
|
|
|
|
* @param ndm desired D.E.P. mode (\a NDM_ACTIVE or \a NDM_PASSIVE for active, respectively passive mode)
|
2012-01-30 10:43:58 +01:00
|
|
|
|
* @param nbr desired baud rate
|
2012-01-10 15:17:18 +01:00
|
|
|
|
* @param ndiInitiator pointer \a nfc_dep_info struct that contains \e NFCID3 and \e General \e Bytes to set to the initiator device (optionnal, can be \e NULL)
|
|
|
|
|
* @param[out] pnt is a \a nfc_target struct pointer where target information will be put.
|
2012-01-30 10:43:58 +01:00
|
|
|
|
* @param timeout in milliseconds
|
2012-01-10 15:17:18 +01:00
|
|
|
|
*
|
|
|
|
|
* The NFC device will try to find an available D.E.P. target. The standards
|
|
|
|
|
* (ISO18092 and ECMA-340) describe the modulation that can be used for reader
|
|
|
|
|
* to passive communications.
|
2012-05-29 02:33:22 +02:00
|
|
|
|
*
|
2012-01-10 15:17:18 +01:00
|
|
|
|
* @note \a nfc_dep_info will be returned when the target was acquired successfully.
|
|
|
|
|
*/
|
|
|
|
|
int
|
2012-05-29 17:54:36 +02:00
|
|
|
|
nfc_initiator_poll_dep_target(struct nfc_device *pnd,
|
|
|
|
|
const nfc_dep_mode ndm, const nfc_baud_rate nbr,
|
|
|
|
|
const nfc_dep_info *pndiInitiator,
|
|
|
|
|
nfc_target *pnt,
|
|
|
|
|
const int timeout)
|
2012-01-10 15:17:18 +01:00
|
|
|
|
{
|
|
|
|
|
const int period = 300;
|
|
|
|
|
int remaining_time = timeout;
|
|
|
|
|
int res;
|
2012-05-29 17:54:36 +02:00
|
|
|
|
if ((res = nfc_device_set_property_bool(pnd, NP_INFINITE_SELECT, true)) < 0)
|
2012-01-10 15:17:18 +01:00
|
|
|
|
return res;
|
|
|
|
|
while (remaining_time > 0) {
|
2012-05-29 17:54:36 +02:00
|
|
|
|
if ((res = nfc_initiator_select_dep_target(pnd, ndm, nbr, pndiInitiator, pnt, period)) < 0) {
|
2012-01-10 15:17:18 +01:00
|
|
|
|
if (res != NFC_ETIMEOUT)
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
if (res == 1)
|
|
|
|
|
return res;
|
|
|
|
|
remaining_time -= period;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
2010-09-10 15:35:25 +02:00
|
|
|
|
}
|
2010-08-24 12:30:18 +02:00
|
|
|
|
|
2012-01-31 10:49:43 +01:00
|
|
|
|
/** @ingroup initiator
|
2010-09-10 15:35:25 +02:00
|
|
|
|
* @brief Deselect a selected passive or emulated tag
|
2011-12-21 10:53:16 +01:00
|
|
|
|
* @return Returns 0 on success, otherwise returns libnfc's error code (negative value).
|
2011-11-23 16:55:40 +01:00
|
|
|
|
* @param pnd \a nfc_device struct pointer that represents currently used device
|
2010-09-10 15:35:25 +02:00
|
|
|
|
*
|
2010-10-11 16:49:08 +02:00
|
|
|
|
* After selecting and communicating with a passive tag, this function could be
|
2010-10-14 13:12:23 +02:00
|
|
|
|
* used to deactivate and release the tag. This is very useful when there are
|
2010-10-11 16:49:08 +02:00
|
|
|
|
* multiple tags available in the field. It is possible to use the \fn
|
|
|
|
|
* nfc_initiator_select_passive_target() function to select the first available
|
|
|
|
|
* tag, test it for the available features and support, deselect it and skip to
|
|
|
|
|
* the next tag until the correct tag is found.
|
2010-09-10 15:35:25 +02:00
|
|
|
|
*/
|
2011-12-21 10:53:16 +01:00
|
|
|
|
int
|
2012-05-29 17:54:36 +02:00
|
|
|
|
nfc_initiator_deselect_target(nfc_device *pnd)
|
2010-09-10 15:35:25 +02:00
|
|
|
|
{
|
2012-05-29 17:54:36 +02:00
|
|
|
|
HAL(initiator_deselect_target, pnd);
|
2009-04-29 14:47:41 +02:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-31 10:49:43 +01:00
|
|
|
|
/** @ingroup initiator
|
2010-09-10 15:35:25 +02:00
|
|
|
|
* @brief Send data to target then retrieve data from target
|
2011-12-19 15:37:22 +01:00
|
|
|
|
* @return Returns received bytes count on success, otherwise returns libnfc's error code
|
2010-01-10 19:14:26 +01:00
|
|
|
|
*
|
2012-01-30 10:43:58 +01:00
|
|
|
|
* @param pnd \a nfc_device struct pointer that represents currently used device
|
2011-09-29 11:49:08 +02:00
|
|
|
|
* @param pbtTx contains a byte array of the frame that needs to be transmitted.
|
|
|
|
|
* @param szTx contains the length in bytes.
|
2012-01-30 10:43:58 +01:00
|
|
|
|
* @param[out] pbtRx response from the tags
|
2012-05-27 23:06:22 +02:00
|
|
|
|
* @param szRx size of \a pbtRx (Will return NFC_EOVFLOW if RX exceeds this size)
|
2011-11-25 12:37:30 +01:00
|
|
|
|
* @param timeout in milliseconds
|
2012-05-29 02:33:22 +02:00
|
|
|
|
*
|
2010-09-29 16:26:06 +02:00
|
|
|
|
* The NFC device (configured as initiator) will transmit the supplied bytes (\a pbtTx) to the target.
|
2010-09-10 15:35:25 +02:00
|
|
|
|
* It waits for the response and stores the received bytes in the \a pbtRx byte array.
|
|
|
|
|
*
|
2011-09-29 11:49:08 +02:00
|
|
|
|
* If timeout is not a null pointer, it specifies the maximum interval to wait for the function to be executed.
|
|
|
|
|
* If timeout is a null pointer, the function blocks indefinitely (until an error is raised or function is completed).
|
|
|
|
|
*
|
2011-12-14 17:01:00 +01:00
|
|
|
|
* If \a NP_EASY_FRAMING option is disabled the frames will sent and received in raw mode: \e PN53x will not handle input neither output data.
|
2010-09-10 15:35:25 +02:00
|
|
|
|
*
|
2010-09-29 16:26:06 +02:00
|
|
|
|
* The parity bits are handled by the \e PN53x chip. The CRC can be generated automatically or handled manually.
|
|
|
|
|
* Using this function, frames can be communicated very fast via the NFC initiator to the tag.
|
2010-07-30 13:30:19 +02:00
|
|
|
|
*
|
|
|
|
|
* Tests show that on average this way of communicating is much faster than using the regular driver/middle-ware (often supplied by manufacturers).
|
|
|
|
|
*
|
2011-12-14 17:01:00 +01:00
|
|
|
|
* @warning The configuration option \a NP_HANDLE_PARITY must be set to \c true (the default value).
|
2010-01-10 19:14:26 +01:00
|
|
|
|
*/
|
2011-12-19 15:37:22 +01:00
|
|
|
|
int
|
2012-05-29 17:54:36 +02:00
|
|
|
|
nfc_initiator_transceive_bytes(nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, uint8_t *pbtRx,
|
|
|
|
|
const size_t szRx, int timeout)
|
2009-04-29 14:47:41 +02:00
|
|
|
|
{
|
2012-05-29 17:54:36 +02:00
|
|
|
|
HAL(initiator_transceive_bytes, pnd, pbtTx, szTx, pbtRx, szRx, timeout)
|
2009-04-29 14:47:41 +02:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-31 10:49:43 +01:00
|
|
|
|
/** @ingroup initiator
|
2010-09-29 16:26:06 +02:00
|
|
|
|
* @brief Transceive raw bit-frames to a target
|
2012-01-04 12:46:07 +01:00
|
|
|
|
* @return Returns received bits count on success, otherwise returns libnfc's error code
|
2010-09-29 16:26:06 +02:00
|
|
|
|
*
|
2012-01-30 10:43:58 +01:00
|
|
|
|
* @param pnd \a nfc_device struct pointer that represents currently used device
|
2010-09-10 15:35:25 +02:00
|
|
|
|
* @param pbtTx contains a byte array of the frame that needs to be transmitted.
|
|
|
|
|
* @param szTxBits contains the length in bits.
|
2010-10-14 13:12:23 +02:00
|
|
|
|
*
|
|
|
|
|
* @note For example the REQA (0x26) command (first anti-collision command of
|
|
|
|
|
* ISO14443-A) must be precise 7 bits long. This is not possible by using
|
|
|
|
|
* nfc_initiator_transceive_bytes(). With that function you can only
|
|
|
|
|
* communicate frames that consist of full bytes. When you send a full byte (8
|
|
|
|
|
* bits + 1 parity) with the value of REQA (0x26), a tag will simply not
|
2010-10-14 13:53:27 +02:00
|
|
|
|
* respond. More information about this can be found in the anti-collision
|
2010-10-14 13:12:23 +02:00
|
|
|
|
* example (\e nfc-anticol).
|
|
|
|
|
*
|
2010-09-10 15:35:25 +02:00
|
|
|
|
* @param pbtTxPar parameter contains a byte array of the corresponding parity bits needed to send per byte.
|
|
|
|
|
*
|
2010-10-14 13:12:23 +02:00
|
|
|
|
* @note For example if you send the SELECT_ALL (0x93, 0x20) = [ 10010011,
|
|
|
|
|
* 00100000 ] command, you have to supply the following parity bytes (0x01,
|
|
|
|
|
* 0x00) to define the correct odd parity bits. This is only an example to
|
|
|
|
|
* explain how it works, if you just are sending two bytes with ISO14443-A
|
|
|
|
|
* compliant parity bits you better can use the
|
|
|
|
|
* nfc_initiator_transceive_bytes() function.
|
2012-05-29 02:33:22 +02:00
|
|
|
|
*
|
2010-10-14 13:12:23 +02:00
|
|
|
|
* @param[out] pbtRx response from the tag
|
|
|
|
|
* @param[out] pbtRxPar parameter contains a byte array of the corresponding parity bits
|
|
|
|
|
*
|
|
|
|
|
* The NFC device (configured as \e initiator) will transmit low-level messages
|
|
|
|
|
* where only the modulation is handled by the \e PN53x chip. Construction of
|
|
|
|
|
* the frame (data, CRC and parity) is completely done by libnfc. This can be
|
|
|
|
|
* very useful for testing purposes. Some protocols (e.g. MIFARE Classic)
|
|
|
|
|
* require to violate the ISO14443-A standard by sending incorrect parity and
|
|
|
|
|
* CRC bytes. Using this feature you are able to simulate these frames.
|
2010-09-10 15:35:25 +02:00
|
|
|
|
*/
|
2012-01-04 12:46:07 +01:00
|
|
|
|
int
|
2012-05-29 17:54:36 +02:00
|
|
|
|
nfc_initiator_transceive_bits(nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar,
|
|
|
|
|
uint8_t *pbtRx, uint8_t *pbtRxPar)
|
2010-09-10 15:35:25 +02:00
|
|
|
|
{
|
2012-05-29 17:54:36 +02:00
|
|
|
|
HAL(initiator_transceive_bits, pnd, pbtTx, szTxBits, pbtTxPar, pbtRx, pbtRxPar);
|
2010-09-10 15:35:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-31 10:49:43 +01:00
|
|
|
|
/** @ingroup initiator
|
2011-04-04 16:16:36 +02:00
|
|
|
|
* @brief Send data to target then retrieve data from target
|
2012-01-04 12:54:55 +01:00
|
|
|
|
* @return Returns received bytes count on success, otherwise returns libnfc's error code.
|
2011-04-04 16:16:36 +02:00
|
|
|
|
*
|
|
|
|
|
* This function is similar to nfc_initiator_transceive_bytes() with the following differences:
|
|
|
|
|
* - A precise cycles counter will indicate the number of cycles between emission & reception of frames.
|
2011-12-14 17:01:00 +01:00
|
|
|
|
* - It only supports mode with \a NP_EASY_FRAMING option disabled.
|
2011-04-04 16:16:36 +02:00
|
|
|
|
* - Overall communication with the host is heavier and slower.
|
|
|
|
|
*
|
2011-05-12 22:33:00 +02:00
|
|
|
|
* Timer control:
|
2011-05-12 22:51:44 +02:00
|
|
|
|
* By default timer configuration tries to maximize the precision, which also limits the maximum
|
|
|
|
|
* cycles count before saturation/timeout.
|
|
|
|
|
* E.g. with PN53x it can count up to 65535 cycles, so about 4.8ms, with a precision of about 73ns.
|
2011-05-12 22:33:00 +02:00
|
|
|
|
* - If you're ok with the defaults, set *cycles = 0 before calling this function.
|
|
|
|
|
* - If you need to count more cycles, set *cycles to the maximum you expect but don't forget
|
|
|
|
|
* you'll loose in precision and it'll take more time before timeout, so don't abuse!
|
|
|
|
|
*
|
2011-12-14 17:01:00 +01:00
|
|
|
|
* @warning The configuration option \a NP_EASY_FRAMING must be set to \c false.
|
|
|
|
|
* @warning The configuration option \a NP_HANDLE_PARITY must be set to \c true (the default value).
|
2011-04-04 16:16:36 +02:00
|
|
|
|
*/
|
2012-01-04 12:54:55 +01:00
|
|
|
|
int
|
2012-05-29 17:54:36 +02:00
|
|
|
|
nfc_initiator_transceive_bytes_timed(nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, uint8_t *pbtRx, uint32_t *cycles)
|
2011-04-04 16:16:36 +02:00
|
|
|
|
{
|
2012-05-29 17:54:36 +02:00
|
|
|
|
HAL(initiator_transceive_bytes_timed, pnd, pbtTx, szTx, pbtRx, cycles);
|
2012-05-28 00:34:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** @ingroup initiator
|
|
|
|
|
* @brief Check target presence
|
|
|
|
|
* @return Returns 0 on success, otherwise returns libnfc's error code.
|
|
|
|
|
*
|
|
|
|
|
* This function tests if \a nfc_target is currently present on NFC device.
|
|
|
|
|
* @warning The target have to be selected before check its presence
|
|
|
|
|
* @warning To run the test, one or more commands will be sent to target
|
|
|
|
|
*/
|
|
|
|
|
int
|
2012-05-29 17:54:36 +02:00
|
|
|
|
nfc_initiator_target_is_present(nfc_device *pnd, const nfc_target nt)
|
2012-05-28 00:34:21 +02:00
|
|
|
|
{
|
2012-05-29 17:54:36 +02:00
|
|
|
|
HAL(initiator_target_is_present, pnd, nt);
|
2011-04-04 16:16:36 +02:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-31 10:49:43 +01:00
|
|
|
|
/** @ingroup initiator
|
2011-04-04 16:16:36 +02:00
|
|
|
|
* @brief Transceive raw bit-frames to a target
|
2012-01-04 14:18:11 +01:00
|
|
|
|
* @return Returns received bits count on success, otherwise returns libnfc's error code
|
2011-04-04 16:16:36 +02:00
|
|
|
|
*
|
|
|
|
|
* This function is similar to nfc_initiator_transceive_bits() with the following differences:
|
|
|
|
|
* - A precise cycles counter will indicate the number of cycles between emission & reception of frames.
|
2011-12-14 17:01:00 +01:00
|
|
|
|
* - It only supports mode with \a NP_EASY_FRAMING option disabled and CRC must be handled manually.
|
2011-04-04 16:16:36 +02:00
|
|
|
|
* - Overall communication with the host is heavier and slower.
|
|
|
|
|
*
|
2011-05-12 22:33:00 +02:00
|
|
|
|
* Timer control:
|
2011-05-12 22:51:44 +02:00
|
|
|
|
* By default timer configuration tries to maximize the precision, which also limits the maximum
|
|
|
|
|
* cycles count before saturation/timeout.
|
|
|
|
|
* E.g. with PN53x it can count up to 65535 cycles, so about 4.8ms, with a precision of about 73ns.
|
2011-05-12 22:33:00 +02:00
|
|
|
|
* - If you're ok with the defaults, set *cycles = 0 before calling this function.
|
|
|
|
|
* - If you need to count more cycles, set *cycles to the maximum you expect but don't forget
|
|
|
|
|
* you'll loose in precision and it'll take more time before timeout, so don't abuse!
|
|
|
|
|
*
|
2011-12-14 17:01:00 +01:00
|
|
|
|
* @warning The configuration option \a NP_EASY_FRAMING must be set to \c false.
|
|
|
|
|
* @warning The configuration option \a NP_HANDLE_CRC must be set to \c false.
|
|
|
|
|
* @warning The configuration option \a NP_HANDLE_PARITY must be set to \c true (the default value).
|
2011-04-04 16:16:36 +02:00
|
|
|
|
*/
|
2012-01-04 14:18:11 +01:00
|
|
|
|
int
|
2012-05-29 17:54:36 +02:00
|
|
|
|
nfc_initiator_transceive_bits_timed(nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar,
|
|
|
|
|
uint8_t *pbtRx, uint8_t *pbtRxPar, uint32_t *cycles)
|
2011-04-04 16:16:36 +02:00
|
|
|
|
{
|
2012-05-29 17:54:36 +02:00
|
|
|
|
HAL(initiator_transceive_bits_timed, pnd, pbtTx, szTxBits, pbtTxPar, pbtRx, pbtRxPar, cycles);
|
2011-04-04 16:16:36 +02:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-31 10:49:43 +01:00
|
|
|
|
/** @ingroup target
|
2010-01-10 19:14:26 +01:00
|
|
|
|
* @brief Initialize NFC device as an emulated tag
|
2012-01-05 16:10:11 +01:00
|
|
|
|
* @return Returns received bytes count on success, otherwise returns libnfc's error code
|
2010-09-29 16:26:06 +02:00
|
|
|
|
*
|
2011-11-23 16:55:40 +01:00
|
|
|
|
* @param pnd \a nfc_device struct pointer that represent currently used device
|
|
|
|
|
* @param pnt pointer to \a nfc_target struct that represents the wanted emulated target
|
2010-10-14 18:27:50 +02:00
|
|
|
|
*
|
|
|
|
|
* @note \a pnt can be updated by this function: if you set NBR_UNDEFINED
|
|
|
|
|
* and/or NDM_UNDEFINED (ie. for DEP mode), these fields will be updated.
|
|
|
|
|
*
|
2010-10-12 17:34:37 +02:00
|
|
|
|
* @param[out] pbtRx Rx buffer pointer
|
2012-01-09 12:26:57 +01:00
|
|
|
|
* @param[out] szRx received bytes count
|
2012-01-05 16:10:11 +01:00
|
|
|
|
* @param timeout in milliseconds
|
2010-01-10 19:14:26 +01:00
|
|
|
|
*
|
2011-05-11 01:44:27 +02:00
|
|
|
|
* This function initializes NFC device in \e target mode in order to emulate a
|
2010-10-14 13:12:23 +02:00
|
|
|
|
* tag using the specified \a nfc_target_mode_t.
|
2011-12-14 17:01:00 +01:00
|
|
|
|
* - Crc is handled by the device (NP_HANDLE_CRC = true)
|
|
|
|
|
* - Parity is handled the device (NP_HANDLE_PARITY = true)
|
|
|
|
|
* - Cryto1 cipher is disabled (NP_ACTIVATE_CRYPTO1 = false)
|
|
|
|
|
* - Auto-switching in ISO14443-4 mode is enabled (NP_AUTO_ISO14443_4 = true)
|
|
|
|
|
* - Easy framing is disabled (NP_EASY_FRAMING = false)
|
|
|
|
|
* - Invalid frames are not accepted (NP_ACCEPT_INVALID_FRAMES = false)
|
|
|
|
|
* - Multiple frames are not accepted (NP_ACCEPT_MULTIPLE_FRAMES = false)
|
2011-05-11 01:44:27 +02:00
|
|
|
|
* - RF field is dropped
|
2010-01-10 19:14:26 +01:00
|
|
|
|
*
|
2010-10-14 13:12:23 +02:00
|
|
|
|
* @warning Be aware that this function will wait (hang) until a command is
|
|
|
|
|
* received that is not part of the anti-collision. The RATS command for
|
|
|
|
|
* example would wake up the emulator. After this is received, the send and
|
|
|
|
|
* receive functions can be used.
|
2010-01-10 19:14:26 +01:00
|
|
|
|
*/
|
2011-12-19 16:35:37 +01:00
|
|
|
|
int
|
2012-05-29 17:54:36 +02:00
|
|
|
|
nfc_target_init(nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, const size_t szRx, int timeout)
|
2009-04-29 14:47:41 +02:00
|
|
|
|
{
|
2011-12-19 16:35:37 +01:00
|
|
|
|
int res = 0;
|
2011-05-05 12:12:26 +02:00
|
|
|
|
// Disallow invalid frame
|
2012-05-29 17:54:36 +02:00
|
|
|
|
if ((res = nfc_device_set_property_bool(pnd, NP_ACCEPT_INVALID_FRAMES, false)) < 0)
|
2012-01-04 16:59:34 +01:00
|
|
|
|
return res;
|
2011-05-05 12:12:26 +02:00
|
|
|
|
// Disallow multiple frames
|
2012-05-29 17:54:36 +02:00
|
|
|
|
if ((res = nfc_device_set_property_bool(pnd, NP_ACCEPT_MULTIPLE_FRAMES, false)) < 0)
|
2012-01-04 16:59:34 +01:00
|
|
|
|
return res;
|
2011-05-05 12:12:26 +02:00
|
|
|
|
// Make sure we reset the CRC and parity to chip handling.
|
2012-05-29 17:54:36 +02:00
|
|
|
|
if ((res = nfc_device_set_property_bool(pnd, NP_HANDLE_CRC, true)) < 0)
|
2012-01-04 16:59:34 +01:00
|
|
|
|
return res;
|
2012-05-29 17:54:36 +02:00
|
|
|
|
if ((res = nfc_device_set_property_bool(pnd, NP_HANDLE_PARITY, true)) < 0)
|
2012-01-04 16:59:34 +01:00
|
|
|
|
return res;
|
2011-05-24 19:10:13 +02:00
|
|
|
|
// Activate auto ISO14443-4 switching by default
|
2012-05-29 17:54:36 +02:00
|
|
|
|
if ((res = nfc_device_set_property_bool(pnd, NP_AUTO_ISO14443_4, true)) < 0)
|
2012-01-04 16:59:34 +01:00
|
|
|
|
return res;
|
2011-05-05 12:12:26 +02:00
|
|
|
|
// Activate "easy framing" feature by default
|
2012-05-29 17:54:36 +02:00
|
|
|
|
if ((res = nfc_device_set_property_bool(pnd, NP_EASY_FRAMING, true)) < 0)
|
2012-01-04 16:59:34 +01:00
|
|
|
|
return res;
|
2011-05-05 12:12:26 +02:00
|
|
|
|
// Deactivate the CRYPTO1 cipher, it may could cause problems when still active
|
2012-05-29 17:54:36 +02:00
|
|
|
|
if ((res = nfc_device_set_property_bool(pnd, NP_ACTIVATE_CRYPTO1, false)) < 0)
|
2012-01-04 16:59:34 +01:00
|
|
|
|
return res;
|
2011-05-05 16:58:26 +02:00
|
|
|
|
// Drop explicitely the field
|
2012-05-29 17:54:36 +02:00
|
|
|
|
if ((res = nfc_device_set_property_bool(pnd, NP_ACTIVATE_FIELD, false)) < 0)
|
2012-01-04 16:59:34 +01:00
|
|
|
|
return res;
|
2011-05-05 12:12:26 +02:00
|
|
|
|
|
2012-05-29 17:54:36 +02:00
|
|
|
|
HAL(target_init, pnd, pnt, pbtRx, szRx, timeout);
|
2009-04-29 14:47:41 +02:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-31 10:49:43 +01:00
|
|
|
|
/** @ingroup dev
|
2011-05-09 12:09:40 +02:00
|
|
|
|
* @brief Turn NFC device in idle mode
|
2012-01-05 09:57:16 +01:00
|
|
|
|
* @return Returns 0 on success, otherwise returns libnfc's error code.
|
2011-05-09 12:09:40 +02:00
|
|
|
|
*
|
2011-11-23 16:55:40 +01:00
|
|
|
|
* @param pnd \a nfc_device struct pointer that represent currently used device
|
2011-05-09 12:09:40 +02:00
|
|
|
|
*
|
|
|
|
|
* This function switch the device in idle mode.
|
|
|
|
|
* In initiator mode, the RF field is turned off and the device is set to low power mode (if avaible);
|
|
|
|
|
* In target mode, the emulation is stoped (no target available from external initiator) and the device is set to low power mode (if avaible).
|
|
|
|
|
*/
|
2012-01-05 09:57:16 +01:00
|
|
|
|
int
|
2012-05-29 17:54:36 +02:00
|
|
|
|
nfc_idle(nfc_device *pnd)
|
2011-05-09 12:09:40 +02:00
|
|
|
|
{
|
2012-05-29 17:54:36 +02:00
|
|
|
|
HAL(idle, pnd);
|
2011-05-09 12:09:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-31 10:49:43 +01:00
|
|
|
|
/** @ingroup dev
|
2011-05-07 01:25:41 +02:00
|
|
|
|
* @brief Abort current running command
|
2012-01-05 15:49:02 +01:00
|
|
|
|
* @return Returns 0 on success, otherwise returns libnfc's error code.
|
2011-05-07 01:25:41 +02:00
|
|
|
|
*
|
2011-11-23 16:55:40 +01:00
|
|
|
|
* @param pnd \a nfc_device struct pointer that represent currently used device
|
2011-05-07 01:25:41 +02:00
|
|
|
|
*
|
|
|
|
|
* Some commands (ie. nfc_target_init()) are blocking functions and will return only in particular conditions (ie. external initiator request).
|
|
|
|
|
* This function attempt to abort the current running command.
|
|
|
|
|
*
|
|
|
|
|
* @note The blocking function (ie. nfc_target_init()) will failed with DEABORT error.
|
|
|
|
|
*/
|
2012-01-05 15:49:02 +01:00
|
|
|
|
int
|
2012-05-29 17:54:36 +02:00
|
|
|
|
nfc_abort_command(nfc_device *pnd)
|
2011-03-04 20:59:49 +01:00
|
|
|
|
{
|
2012-05-29 17:54:36 +02:00
|
|
|
|
HAL(abort_command, pnd);
|
2011-03-04 20:59:49 +01:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-31 10:49:43 +01:00
|
|
|
|
/** @ingroup target
|
2010-09-10 15:35:25 +02:00
|
|
|
|
* @brief Send bytes and APDU frames
|
2011-12-22 16:59:08 +01:00
|
|
|
|
* @return Returns sent bytes count on success, otherwise returns libnfc's error code
|
2010-01-10 19:14:26 +01:00
|
|
|
|
*
|
2011-11-23 16:55:40 +01:00
|
|
|
|
* @param pnd \a nfc_device struct pointer that represent currently used device
|
2010-09-29 16:26:06 +02:00
|
|
|
|
* @param pbtTx pointer to Tx buffer
|
2010-10-12 16:56:42 +02:00
|
|
|
|
* @param szTx size of Tx buffer
|
2011-11-25 12:37:30 +01:00
|
|
|
|
* @param timeout in milliseconds
|
2010-09-29 16:26:06 +02:00
|
|
|
|
*
|
2010-10-14 13:12:23 +02:00
|
|
|
|
* This function make the NFC device (configured as \e target) send byte frames
|
|
|
|
|
* (e.g. APDU responses) to the \e initiator.
|
2011-09-29 11:49:08 +02:00
|
|
|
|
*
|
|
|
|
|
* If timeout is not a null pointer, it specifies the maximum interval to wait for the function to be executed.
|
|
|
|
|
* If timeout is a null pointer, the function blocks indefinitely (until an error is raised or function is completed).
|
2010-01-10 19:14:26 +01:00
|
|
|
|
*/
|
2011-12-22 16:59:08 +01:00
|
|
|
|
int
|
2012-05-29 17:54:36 +02:00
|
|
|
|
nfc_target_send_bytes(nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, int timeout)
|
2009-04-29 14:47:41 +02:00
|
|
|
|
{
|
2012-05-29 17:54:36 +02:00
|
|
|
|
HAL(target_send_bytes, pnd, pbtTx, szTx, timeout);
|
2009-04-29 14:47:41 +02:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-31 10:49:43 +01:00
|
|
|
|
/** @ingroup target
|
2010-01-10 19:14:26 +01:00
|
|
|
|
* @brief Receive bytes and APDU frames
|
2011-12-22 16:39:51 +01:00
|
|
|
|
* @return Returns received bytes count on success, otherwise returns libnfc's error code
|
2012-05-29 02:33:22 +02:00
|
|
|
|
*
|
2011-11-23 16:55:40 +01:00
|
|
|
|
* @param pnd \a nfc_device struct pointer that represent currently used device
|
2012-01-05 22:35:02 +01:00
|
|
|
|
* @param pbtRx pointer to Rx buffer
|
|
|
|
|
* @param szRx size of Rx buffer
|
2011-11-25 12:37:30 +01:00
|
|
|
|
* @param timeout in milliseconds
|
2010-01-10 19:14:26 +01:00
|
|
|
|
*
|
2010-09-29 16:26:06 +02:00
|
|
|
|
* This function retrieves bytes frames (e.g. ADPU) sent by the \e initiator to the NFC device (configured as \e target).
|
2011-09-29 11:49:08 +02:00
|
|
|
|
*
|
2012-01-05 22:35:02 +01:00
|
|
|
|
* If timeout equals to 0, the function blocks indefinitely (until an error is raised or function is completed)
|
|
|
|
|
* If timeout equals to -1, the default timeout will be used
|
2010-01-10 19:14:26 +01:00
|
|
|
|
*/
|
2011-12-22 16:39:51 +01:00
|
|
|
|
int
|
2012-05-29 17:54:36 +02:00
|
|
|
|
nfc_target_receive_bytes(nfc_device *pnd, uint8_t *pbtRx, const size_t szRx, int timeout)
|
2009-04-29 14:47:41 +02:00
|
|
|
|
{
|
2012-05-29 17:54:36 +02:00
|
|
|
|
HAL(target_receive_bytes, pnd, pbtRx, szRx, timeout);
|
2009-04-29 14:47:41 +02:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-31 10:49:43 +01:00
|
|
|
|
/** @ingroup target
|
2010-01-10 19:14:26 +01:00
|
|
|
|
* @brief Send raw bit-frames
|
2012-01-04 14:27:15 +01:00
|
|
|
|
* @return Returns sent bits count on success, otherwise returns libnfc's error code.
|
2010-01-10 19:14:26 +01:00
|
|
|
|
*
|
2012-01-30 10:43:58 +01:00
|
|
|
|
* @param pnd \a nfc_device struct pointer that represent currently used device
|
|
|
|
|
* @param pbtTx pointer to Tx buffer
|
|
|
|
|
* @param szTxBits size of Tx buffer
|
|
|
|
|
* @param pbtTxPar parameter contains a byte array of the corresponding parity bits needed to send per byte.
|
2010-10-14 13:12:23 +02:00
|
|
|
|
* This function can be used to transmit (raw) bit-frames to the \e initiator
|
|
|
|
|
* using the specified NFC device (configured as \e target).
|
2010-01-10 19:14:26 +01:00
|
|
|
|
*/
|
2012-01-04 14:27:15 +01:00
|
|
|
|
int
|
2012-05-29 17:54:36 +02:00
|
|
|
|
nfc_target_send_bits(nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar)
|
2009-04-29 14:47:41 +02:00
|
|
|
|
{
|
2012-05-29 17:54:36 +02:00
|
|
|
|
HAL(target_send_bits, pnd, pbtTx, szTxBits, pbtTxPar);
|
2009-04-29 14:47:41 +02:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-31 10:49:43 +01:00
|
|
|
|
/** @ingroup target
|
2010-09-10 15:35:25 +02:00
|
|
|
|
* @brief Receive bit-frames
|
2012-01-04 14:33:53 +01:00
|
|
|
|
* @return Returns received bits count on success, otherwise returns libnfc's error code
|
2010-01-10 19:14:26 +01:00
|
|
|
|
*
|
2012-01-30 10:43:58 +01:00
|
|
|
|
* @param pnd \a nfc_device struct pointer that represent currently used device
|
|
|
|
|
* @param pbtRx pointer to Rx buffer
|
|
|
|
|
* @param szRx size of Rx buffer
|
|
|
|
|
* @param[out] pbtRxPar parameter contains a byte array of the corresponding parity bits
|
2010-01-10 19:14:26 +01:00
|
|
|
|
*
|
2010-10-14 13:12:23 +02:00
|
|
|
|
* This function makes it possible to receive (raw) bit-frames. It returns all
|
|
|
|
|
* the messages that are stored in the FIFO buffer of the \e PN53x chip. It
|
|
|
|
|
* does not require to send any frame and thereby could be used to snoop frames
|
|
|
|
|
* that are transmitted by a nearby \e initiator. @note Check out the
|
2011-12-14 17:01:00 +01:00
|
|
|
|
* NP_ACCEPT_MULTIPLE_FRAMES configuration option to avoid losing transmitted
|
2010-10-14 13:12:23 +02:00
|
|
|
|
* frames.
|
2010-01-10 19:14:26 +01:00
|
|
|
|
*/
|
2012-01-04 14:33:53 +01:00
|
|
|
|
int
|
2012-05-29 17:54:36 +02:00
|
|
|
|
nfc_target_receive_bits(nfc_device *pnd, uint8_t *pbtRx, const size_t szRx, uint8_t *pbtRxPar)
|
2009-04-29 14:47:41 +02:00
|
|
|
|
{
|
2012-05-29 17:54:36 +02:00
|
|
|
|
HAL(target_receive_bits, pnd, pbtRx, szRx, pbtRxPar);
|
2009-04-29 14:47:41 +02:00
|
|
|
|
}
|
2009-09-03 15:47:26 +02:00
|
|
|
|
|
2012-01-11 09:47:14 +01:00
|
|
|
|
static struct sErrorMessage {
|
|
|
|
|
int iErrorCode;
|
|
|
|
|
const char *pcErrorMsg;
|
|
|
|
|
} sErrorMessages[] = {
|
|
|
|
|
/* Chip-level errors (internal errors, RF errors, etc.) */
|
|
|
|
|
{ NFC_SUCCESS, "Success" },
|
|
|
|
|
{ NFC_EIO, "Input / Output Error" },
|
|
|
|
|
{ NFC_EINVARG, "Invalid argument(s)" },
|
|
|
|
|
{ NFC_EDEVNOTSUPP, "Not Supported by Device" },
|
|
|
|
|
{ NFC_ENOTSUCHDEV, "No Such Device" },
|
|
|
|
|
{ NFC_EOVFLOW, "Buffer Overflow" },
|
|
|
|
|
{ NFC_ETIMEOUT, "Timeout" },
|
|
|
|
|
{ NFC_EOPABORTED, "Operation Aborted" },
|
|
|
|
|
{ NFC_ENOTIMPL, "Not (yet) Implemented" },
|
|
|
|
|
{ NFC_ETGRELEASED, "Target Released" },
|
|
|
|
|
{ NFC_ERFTRANS, "RF Transmission Error" },
|
|
|
|
|
{ NFC_ECHIP, "Device's Internal Chip Error" },
|
|
|
|
|
};
|
|
|
|
|
|
2012-01-31 10:49:43 +01:00
|
|
|
|
/** @ingroup error
|
2012-01-11 09:47:14 +01:00
|
|
|
|
* @brief Return the last error string
|
2010-07-29 16:16:11 +02:00
|
|
|
|
* @return Returns a string
|
2012-05-29 02:33:22 +02:00
|
|
|
|
*
|
2012-01-30 10:43:58 +01:00
|
|
|
|
* @param pnd \a nfc_device struct pointer that represent currently used device
|
2010-07-29 16:16:11 +02:00
|
|
|
|
*/
|
2010-09-07 19:51:03 +02:00
|
|
|
|
const char *
|
2012-05-29 17:54:36 +02:00
|
|
|
|
nfc_strerror(const nfc_device *pnd)
|
2012-05-29 02:33:22 +02:00
|
|
|
|
{
|
2012-01-11 09:47:14 +01:00
|
|
|
|
const char *pcRes = "Unknown error";
|
|
|
|
|
size_t i;
|
2012-05-29 17:54:36 +02:00
|
|
|
|
for (i = 0; i < (sizeof(sErrorMessages) / sizeof(struct sErrorMessage)); i++) {
|
2012-01-11 09:47:14 +01:00
|
|
|
|
if (sErrorMessages[i].iErrorCode == pnd->last_error) {
|
|
|
|
|
pcRes = sErrorMessages[i].pcErrorMsg;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return pcRes;
|
2010-07-29 16:16:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-31 10:49:43 +01:00
|
|
|
|
/** @ingroup error
|
2012-01-11 09:47:14 +01:00
|
|
|
|
* @brief Renders the last error in pcStrErrBuf for a maximum size of szBufLen chars
|
2010-07-29 16:16:11 +02:00
|
|
|
|
* @return Returns 0 upon success
|
2012-05-29 02:33:22 +02:00
|
|
|
|
*
|
2012-01-30 10:43:58 +01:00
|
|
|
|
* @param pnd \a nfc_device struct pointer that represent currently used device
|
2012-01-31 16:35:13 +01:00
|
|
|
|
* @param pcStrErrBuf a string that contains the last error.
|
|
|
|
|
* @param szBufLen size of buffer
|
2010-07-29 16:16:11 +02:00
|
|
|
|
*/
|
2010-09-07 19:51:03 +02:00
|
|
|
|
int
|
2012-05-29 17:54:36 +02:00
|
|
|
|
nfc_strerror_r(const nfc_device *pnd, char *pcStrErrBuf, size_t szBufLen)
|
2010-07-29 16:16:11 +02:00
|
|
|
|
{
|
2012-05-29 17:54:36 +02:00
|
|
|
|
return (snprintf(pcStrErrBuf, szBufLen, "%s", nfc_strerror(pnd)) < 0) ? -1 : 0;
|
2010-07-29 16:16:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-31 10:49:43 +01:00
|
|
|
|
/** @ingroup error
|
2012-01-11 09:47:14 +01:00
|
|
|
|
* @brief Display the last error occured on a nfc_device
|
2012-05-29 02:33:22 +02:00
|
|
|
|
*
|
2012-01-30 10:43:58 +01:00
|
|
|
|
* @param pnd \a nfc_device struct pointer that represent currently used device
|
2012-05-29 02:33:22 +02:00
|
|
|
|
* @param pcString a string
|
2010-07-29 16:16:11 +02:00
|
|
|
|
*/
|
2010-09-07 19:51:03 +02:00
|
|
|
|
void
|
2012-05-29 17:54:36 +02:00
|
|
|
|
nfc_perror(const nfc_device *pnd, const char *pcString)
|
2010-07-29 16:16:11 +02:00
|
|
|
|
{
|
2012-05-29 17:54:36 +02:00
|
|
|
|
fprintf(stderr, "%s: %s\n", pcString, nfc_strerror(pnd));
|
2010-07-29 16:16:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-31 10:49:43 +01:00
|
|
|
|
/** @ingroup error
|
2012-01-05 02:39:10 +01:00
|
|
|
|
* @brief Returns last error occured on a nfc_device
|
2012-01-30 10:43:58 +01:00
|
|
|
|
* @return Returns an integer that represents to libnfc's error code.
|
2012-05-29 02:33:22 +02:00
|
|
|
|
*
|
2012-01-30 10:43:58 +01:00
|
|
|
|
* @param pnd \a nfc_device struct pointer that represent currently used device
|
2012-01-05 02:39:10 +01:00
|
|
|
|
*/
|
|
|
|
|
int
|
2012-05-29 17:54:36 +02:00
|
|
|
|
nfc_device_get_last_error(const nfc_device *pnd)
|
2012-01-05 02:39:10 +01:00
|
|
|
|
{
|
|
|
|
|
return pnd->last_error;
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-10 19:14:26 +01:00
|
|
|
|
/* Special data accessors */
|
|
|
|
|
|
2012-01-31 10:49:43 +01:00
|
|
|
|
/** @ingroup data
|
2010-01-10 19:14:26 +01:00
|
|
|
|
* @brief Returns the device name
|
2010-08-13 21:10:31 +02:00
|
|
|
|
* @return Returns a string with the device name
|
2012-05-29 02:33:22 +02:00
|
|
|
|
*
|
2012-01-30 10:43:58 +01:00
|
|
|
|
* @param pnd \a nfc_device struct pointer that represent currently used device
|
2010-01-10 19:14:26 +01:00
|
|
|
|
*/
|
2010-09-07 19:51:03 +02:00
|
|
|
|
const char *
|
2012-05-29 17:54:36 +02:00
|
|
|
|
nfc_device_get_name(nfc_device *pnd)
|
2009-11-02 15:05:03 +01:00
|
|
|
|
{
|
2012-01-18 14:17:01 +01:00
|
|
|
|
return pnd->name;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-31 10:49:43 +01:00
|
|
|
|
/** @ingroup data
|
2012-01-18 14:17:01 +01:00
|
|
|
|
* @brief Returns the device connection string
|
|
|
|
|
* @return Returns a string with the device connstring
|
2012-05-29 02:33:22 +02:00
|
|
|
|
*
|
2012-01-30 10:43:58 +01:00
|
|
|
|
* @param pnd \a nfc_device struct pointer that represent currently used device
|
2012-01-18 14:17:01 +01:00
|
|
|
|
*/
|
|
|
|
|
const char *
|
2012-05-29 17:54:36 +02:00
|
|
|
|
nfc_device_get_connstring(nfc_device *pnd)
|
2009-11-02 15:05:03 +01:00
|
|
|
|
{
|
2012-01-18 14:17:01 +01:00
|
|
|
|
return pnd->connstring;
|
2009-11-02 15:05:03 +01:00
|
|
|
|
}
|
|
|
|
|
|
2012-03-01 14:52:51 +01:00
|
|
|
|
/** @ingroup data
|
|
|
|
|
* @brief Get supported modulations.
|
|
|
|
|
* @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 supported_mt pointer of \a nfc_modulation_type array.
|
2012-05-29 02:33:22 +02:00
|
|
|
|
*
|
2012-03-01 14:52:51 +01:00
|
|
|
|
*/
|
2012-05-29 02:33:22 +02:00
|
|
|
|
int
|
2012-05-29 17:54:36 +02:00
|
|
|
|
nfc_device_get_supported_modulation(nfc_device *pnd, const nfc_mode mode, const nfc_modulation_type **const supported_mt)
|
2012-03-01 14:52:51 +01:00
|
|
|
|
{
|
2012-05-29 17:54:36 +02:00
|
|
|
|
HAL(get_supported_modulation, pnd, mode, supported_mt);
|
2012-03-01 14:52:51 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** @ingroup data
|
|
|
|
|
* @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 nmt \a nfc_modulation_type.
|
|
|
|
|
* @param supported_br pointer of \a nfc_baud_rate array.
|
2012-05-29 02:33:22 +02:00
|
|
|
|
*
|
2012-03-01 14:52:51 +01:00
|
|
|
|
*/
|
2012-05-29 02:33:22 +02:00
|
|
|
|
int
|
2012-05-29 17:54:36 +02:00
|
|
|
|
nfc_device_get_supported_baud_rate(nfc_device *pnd, const nfc_modulation_type nmt, const nfc_baud_rate **const supported_br)
|
2012-03-01 14:52:51 +01:00
|
|
|
|
{
|
2012-05-29 17:54:36 +02:00
|
|
|
|
HAL(get_supported_baud_rate, pnd, nmt, supported_br);
|
2012-03-01 14:52:51 +01:00
|
|
|
|
}
|
|
|
|
|
|
2010-01-10 19:14:26 +01:00
|
|
|
|
/* Misc. functions */
|
2009-11-02 15:05:03 +01:00
|
|
|
|
|
2012-01-31 10:49:43 +01:00
|
|
|
|
/** @ingroup misc
|
2010-01-10 19:14:26 +01:00
|
|
|
|
* @brief Returns the library version
|
|
|
|
|
* @return Returns a string with the library version
|
2012-05-29 02:33:22 +02:00
|
|
|
|
*
|
2012-01-30 10:43:58 +01:00
|
|
|
|
* @param pnd \a nfc_device struct pointer that represent currently used device
|
2010-01-10 19:14:26 +01:00
|
|
|
|
*/
|
2010-09-07 19:51:03 +02:00
|
|
|
|
const char *
|
2012-05-29 17:54:36 +02:00
|
|
|
|
nfc_version(void)
|
2009-12-14 20:18:29 +01:00
|
|
|
|
{
|
2010-09-07 19:51:03 +02:00
|
|
|
|
#ifdef SVN_REVISION
|
|
|
|
|
return PACKAGE_VERSION " (r" SVN_REVISION ")";
|
|
|
|
|
#else
|
2010-07-22 15:41:20 +02:00
|
|
|
|
return PACKAGE_VERSION;
|
2010-09-07 19:51:03 +02:00
|
|
|
|
#endif // SVN_REVISION
|
2012-03-01 14:33:13 +01:00
|
|
|
|
}
|
2012-05-17 02:48:47 +02:00
|
|
|
|
|
|
|
|
|
/** @ingroup misc
|
|
|
|
|
* @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
|
|
|
|
|
*/
|
2012-05-29 02:33:22 +02:00
|
|
|
|
int
|
2012-05-29 17:54:36 +02:00
|
|
|
|
nfc_device_get_information_about(nfc_device *pnd, char *buf, size_t buflen)
|
2012-05-17 02:48:47 +02:00
|
|
|
|
{
|
2012-05-29 17:54:36 +02:00
|
|
|
|
HAL(device_get_information_about, pnd, buf, buflen);
|
2012-05-17 02:48:47 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** @ingroup string-converter
|
|
|
|
|
* @brief Convert \a nfc_baud_rate value to string
|
|
|
|
|
* @return Returns nfc baud rate
|
|
|
|
|
* @param \a nfc_baud_rate to convert
|
|
|
|
|
*/
|
|
|
|
|
const char *
|
2012-05-29 17:54:36 +02:00
|
|
|
|
str_nfc_baud_rate(const nfc_baud_rate nbr)
|
2012-05-17 02:48:47 +02:00
|
|
|
|
{
|
2012-05-29 17:54:36 +02:00
|
|
|
|
switch (nbr) {
|
2012-05-17 02:48:47 +02:00
|
|
|
|
case NBR_UNDEFINED:
|
|
|
|
|
return "undefined baud rate";
|
2012-05-29 17:52:51 +02:00
|
|
|
|
break;
|
2012-05-17 02:48:47 +02:00
|
|
|
|
case NBR_106:
|
|
|
|
|
return "106 kbps";
|
2012-05-29 17:52:51 +02:00
|
|
|
|
break;
|
2012-05-17 02:48:47 +02:00
|
|
|
|
case NBR_212:
|
|
|
|
|
return "212 kbps";
|
2012-05-29 17:52:51 +02:00
|
|
|
|
break;
|
2012-05-17 02:48:47 +02:00
|
|
|
|
case NBR_424:
|
|
|
|
|
return "424 kbps";
|
2012-05-29 17:52:51 +02:00
|
|
|
|
break;
|
2012-05-17 02:48:47 +02:00
|
|
|
|
case NBR_847:
|
|
|
|
|
return "847 kbps";
|
2012-05-29 17:52:51 +02:00
|
|
|
|
break;
|
2012-05-17 02:48:47 +02:00
|
|
|
|
}
|
|
|
|
|
// Should never go there..
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** @ingroup string-converter
|
|
|
|
|
* @brief Convert \a nfc_modulation_type value to string
|
|
|
|
|
* @return Returns nfc modulation type
|
|
|
|
|
* @param \a nfc_modulation_type to convert
|
|
|
|
|
*/
|
|
|
|
|
const char *
|
2012-05-29 17:54:36 +02:00
|
|
|
|
str_nfc_modulation_type(const nfc_modulation_type nmt)
|
2012-05-17 02:48:47 +02:00
|
|
|
|
{
|
2012-05-29 17:54:36 +02:00
|
|
|
|
switch (nmt) {
|
2012-05-17 02:48:47 +02:00
|
|
|
|
case NMT_ISO14443A:
|
|
|
|
|
return "ISO/IEC 14443A";
|
2012-05-29 17:52:51 +02:00
|
|
|
|
break;
|
2012-05-17 02:48:47 +02:00
|
|
|
|
case NMT_ISO14443B:
|
|
|
|
|
return "ISO/IEC 14443-4B";
|
2012-05-29 17:52:51 +02:00
|
|
|
|
break;
|
2012-05-17 02:48:47 +02:00
|
|
|
|
case NMT_ISO14443BI:
|
|
|
|
|
return "ISO/IEC 14443-4B'";
|
2012-05-29 17:52:51 +02:00
|
|
|
|
break;
|
2012-05-17 02:48:47 +02:00
|
|
|
|
case NMT_ISO14443B2CT:
|
|
|
|
|
return "ISO/IEC 14443-2B ASK CTx";
|
2012-05-29 17:52:51 +02:00
|
|
|
|
break;
|
2012-05-17 02:48:47 +02:00
|
|
|
|
case NMT_ISO14443B2SR:
|
|
|
|
|
return "ISO/IEC 14443-2B ST SRx";
|
2012-05-29 17:52:51 +02:00
|
|
|
|
break;
|
2012-05-17 02:48:47 +02:00
|
|
|
|
case NMT_FELICA:
|
|
|
|
|
return "FeliCa";
|
2012-05-29 17:52:51 +02:00
|
|
|
|
break;
|
2012-05-17 02:48:47 +02:00
|
|
|
|
case NMT_JEWEL:
|
|
|
|
|
return "Innovision Jewel";
|
2012-05-29 17:52:51 +02:00
|
|
|
|
break;
|
2012-05-17 02:48:47 +02:00
|
|
|
|
case NMT_DEP:
|
|
|
|
|
return "D.E.P.";
|
2012-05-29 17:52:51 +02:00
|
|
|
|
break;
|
2012-05-17 02:48:47 +02:00
|
|
|
|
}
|
|
|
|
|
// Should never go there..
|
|
|
|
|
return "";
|
|
|
|
|
}
|