2010-01-12 11:50:09 +00:00
|
|
|
/*-
|
2009-10-12 14:52:26 +00:00
|
|
|
* Public platform independent Near Field Communication (NFC) library
|
2012-05-29 00:33:22 +00:00
|
|
|
*
|
2009-10-12 14:52:26 +00:00
|
|
|
* Copyright (C) 2009, Roel Verdult
|
2010-09-10 13:35:25 +00:00
|
|
|
* Copyright (C) 2010, Romuald Conty
|
2012-05-29 00:33:22 +00:00
|
|
|
*
|
2009-10-12 14:52:26 +00: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 00:33:22 +00:00
|
|
|
*
|
2009-10-12 14:52:26 +00: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-12 11:50:09 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2010-01-10 18:14:26 +00:00
|
|
|
* @file nfc.h
|
2010-01-12 11:50:09 +00:00
|
|
|
* @brief libnfc interface
|
2009-08-27 10:49:45 +00:00
|
|
|
*
|
2009-10-12 14:52:26 +00:00
|
|
|
* Provide all usefull functions (API) to handle NFC devices.
|
2009-08-27 10:49:45 +00:00
|
|
|
*/
|
|
|
|
|
2009-10-13 12:43:52 +00:00
|
|
|
#ifndef _LIBNFC_H_
|
2010-09-07 17:51:03 +00:00
|
|
|
# define _LIBNFC_H_
|
2009-10-12 14:52:26 +00:00
|
|
|
|
2011-09-22 13:03:47 +00:00
|
|
|
# include <sys/time.h>
|
|
|
|
|
2010-09-07 17:51:03 +00:00
|
|
|
# include <stdint.h>
|
|
|
|
# include <stdbool.h>
|
2009-05-27 10:13:19 +00:00
|
|
|
|
2010-09-07 17:51:03 +00:00
|
|
|
# ifdef _WIN32
|
2012-05-29 15:52:51 +00:00
|
|
|
/* Windows platform */
|
2010-09-07 17:51:03 +00:00
|
|
|
# ifndef _WINDLL
|
2012-05-29 15:52:51 +00:00
|
|
|
/* CMake compilation */
|
2010-09-07 17:51:03 +00:00
|
|
|
# ifdef nfc_EXPORTS
|
|
|
|
# define NFC_EXPORT __declspec(dllexport)
|
|
|
|
# else
|
2012-05-29 15:52:51 +00:00
|
|
|
/* nfc_EXPORTS */
|
2010-09-07 17:51:03 +00:00
|
|
|
# define NFC_EXPORT __declspec(dllimport)
|
|
|
|
# endif
|
2012-05-29 15:52:51 +00:00
|
|
|
/* nfc_EXPORTS */
|
2010-09-07 17:51:03 +00:00
|
|
|
# else
|
2012-05-29 15:52:51 +00:00
|
|
|
/* _WINDLL */
|
|
|
|
/* Manual makefile */
|
2010-09-07 17:51:03 +00:00
|
|
|
# define NFC_EXPORT
|
|
|
|
# endif
|
2012-05-29 15:52:51 +00:00
|
|
|
/* _WINDLL */
|
2010-09-07 17:51:03 +00:00
|
|
|
# else
|
2012-05-29 15:52:51 +00:00
|
|
|
/* _WIN32 */
|
2010-09-07 17:51:03 +00:00
|
|
|
# define NFC_EXPORT
|
|
|
|
# endif
|
2012-05-29 15:52:51 +00:00
|
|
|
/* _WIN32 */
|
2009-11-10 09:47:59 +00:00
|
|
|
|
2010-09-07 17:51:03 +00:00
|
|
|
# include <nfc/nfc-types.h>
|
2009-04-29 12:47:41 +00:00
|
|
|
|
2010-09-07 17:51:03 +00:00
|
|
|
# ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
# endif // __cplusplus
|
2009-11-02 07:46:29 +00:00
|
|
|
|
2012-05-29 15:52:51 +00:00
|
|
|
/* Library initialization/deinitialization */
|
2012-01-18 16:22:06 +00:00
|
|
|
NFC_EXPORT void nfc_init(nfc_context *context);
|
|
|
|
NFC_EXPORT void nfc_exit(nfc_context *context);
|
2012-01-18 09:53:45 +00:00
|
|
|
|
2012-05-29 15:52:51 +00:00
|
|
|
/* NFC Device/Hardware manipulation */
|
2011-10-17 13:03:56 +00:00
|
|
|
NFC_EXPORT bool nfc_get_default_device (nfc_connstring *connstring);
|
2012-01-18 16:22:06 +00:00
|
|
|
NFC_EXPORT nfc_device *nfc_open (nfc_context *context, const nfc_connstring connstring);
|
2012-01-17 14:52:39 +00:00
|
|
|
NFC_EXPORT void nfc_close (nfc_device *pnd);
|
2012-01-05 14:49:02 +00:00
|
|
|
NFC_EXPORT int nfc_abort_command (nfc_device *pnd);
|
2012-01-18 16:22:06 +00:00
|
|
|
NFC_EXPORT size_t nfc_list_devices (nfc_context *context, nfc_connstring connstrings[], size_t connstrings_len);
|
2012-01-05 08:57:16 +00:00
|
|
|
NFC_EXPORT int nfc_idle (nfc_device *pnd);
|
2009-08-27 10:49:45 +00:00
|
|
|
|
2012-05-29 15:52:51 +00:00
|
|
|
/* NFC initiator: act as "reader" */
|
2011-12-15 11:46:14 +00:00
|
|
|
NFC_EXPORT int nfc_initiator_init (nfc_device *pnd);
|
2011-12-19 16:27:50 +00:00
|
|
|
NFC_EXPORT int nfc_initiator_select_passive_target (nfc_device *pnd, const nfc_modulation nm, const uint8_t *pbtInitData, const size_t szInitData, nfc_target *pnt);
|
2011-12-15 11:46:14 +00:00
|
|
|
NFC_EXPORT int nfc_initiator_list_passive_targets (nfc_device *pnd, const nfc_modulation nm, nfc_target ant[], const size_t szTargets);
|
2011-12-20 15:46:35 +00:00
|
|
|
NFC_EXPORT int nfc_initiator_poll_target (nfc_device *pnd, const nfc_modulation *pnmTargetTypes, const size_t szTargetTypes, const uint8_t uiPollNr, const uint8_t uiPeriod, nfc_target *pnt);
|
2011-12-21 09:15:44 +00:00
|
|
|
NFC_EXPORT int 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);
|
2012-01-10 14:17:18 +00:00
|
|
|
NFC_EXPORT int nfc_initiator_poll_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);
|
2011-12-21 09:53:16 +00:00
|
|
|
NFC_EXPORT int nfc_initiator_deselect_target (nfc_device *pnd);
|
2012-05-27 21:06:22 +00:00
|
|
|
NFC_EXPORT int nfc_initiator_transceive_bytes (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, uint8_t *pbtRx, const size_t szRx, int timeout);
|
2012-01-04 15:30:42 +00:00
|
|
|
NFC_EXPORT int 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);
|
2012-01-04 15:53:41 +00:00
|
|
|
NFC_EXPORT int nfc_initiator_transceive_bytes_timed (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, uint8_t *pbtRx, uint32_t *cycles);
|
2012-01-04 15:43:08 +00:00
|
|
|
NFC_EXPORT int 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);
|
2012-05-27 22:34:21 +00:00
|
|
|
NFC_EXPORT int nfc_initiator_target_is_present (nfc_device *pnd, const nfc_target nt);
|
2010-09-20 14:41:41 +00:00
|
|
|
|
2012-05-29 15:52:51 +00:00
|
|
|
/* NFC target: act as tag (i.e. MIFARE Classic) or NFC target device. */
|
2012-01-09 11:26:57 +00:00
|
|
|
NFC_EXPORT int nfc_target_init (nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, const size_t szRx, int timeout);
|
2011-12-22 15:59:08 +00:00
|
|
|
NFC_EXPORT int nfc_target_send_bytes (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, int timeout);
|
2012-01-05 21:35:02 +00:00
|
|
|
NFC_EXPORT int nfc_target_receive_bytes (nfc_device *pnd, uint8_t *pbtRx, const size_t szRx, int timeout);
|
2012-01-04 13:27:15 +00:00
|
|
|
NFC_EXPORT int nfc_target_send_bits (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar);
|
2012-01-05 21:35:02 +00:00
|
|
|
NFC_EXPORT int nfc_target_receive_bits (nfc_device *pnd, uint8_t *pbtRx, const size_t szRx, uint8_t *pbtRxPar);
|
2010-09-20 14:41:41 +00:00
|
|
|
|
2012-05-29 15:52:51 +00:00
|
|
|
/* Error reporting */
|
2011-11-24 16:45:27 +00:00
|
|
|
NFC_EXPORT const char *nfc_strerror (const nfc_device *pnd);
|
2011-12-15 16:02:38 +00:00
|
|
|
NFC_EXPORT int nfc_strerror_r (const nfc_device *pnd, char *buf, size_t buflen);
|
|
|
|
NFC_EXPORT void nfc_perror (const nfc_device *pnd, const char *s);
|
2012-01-05 01:39:10 +00:00
|
|
|
NFC_EXPORT int nfc_device_get_last_error (const nfc_device *pnd);
|
2010-07-29 14:16:11 +00:00
|
|
|
|
2012-05-29 15:52:51 +00:00
|
|
|
/* Special data accessors */
|
2011-12-15 16:02:38 +00:00
|
|
|
NFC_EXPORT const char *nfc_device_get_name (nfc_device *pnd);
|
2012-01-18 13:17:01 +00:00
|
|
|
NFC_EXPORT const char *nfc_device_get_connstring (nfc_device *pnd);
|
2012-03-01 13:52:51 +00:00
|
|
|
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);
|
2009-12-14 19:18:29 +00:00
|
|
|
|
2012-05-29 15:52:51 +00:00
|
|
|
/* Properties accessors */
|
2011-12-14 13:27:11 +00:00
|
|
|
NFC_EXPORT int nfc_device_set_property_int (nfc_device *pnd, const nfc_property property, const int value);
|
2011-12-14 16:01:00 +00:00
|
|
|
NFC_EXPORT int nfc_device_set_property_bool (nfc_device *pnd, const nfc_property property, const bool bEnable);
|
2011-12-14 13:27:11 +00:00
|
|
|
|
2012-05-29 15:52:51 +00:00
|
|
|
/* Misc. functions */
|
2011-11-24 16:45:27 +00:00
|
|
|
NFC_EXPORT void iso14443a_crc (uint8_t *pbtData, size_t szLen, uint8_t *pbtCrc);
|
|
|
|
NFC_EXPORT void iso14443a_crc_append (uint8_t *pbtData, size_t szLen);
|
|
|
|
NFC_EXPORT uint8_t *iso14443a_locate_historical_bytes (uint8_t *pbtAts, size_t szAts, size_t *pszTk);
|
2012-05-17 00:48:47 +00:00
|
|
|
|
2010-09-07 17:51:03 +00:00
|
|
|
NFC_EXPORT const char *nfc_version (void);
|
2012-05-17 00:48:47 +00:00
|
|
|
NFC_EXPORT int nfc_device_get_information_about (nfc_device *pnd, char *buf, size_t buflen);
|
|
|
|
|
2012-05-29 15:52:51 +00:00
|
|
|
/* String converter functions */
|
2012-05-17 00:48:47 +00:00
|
|
|
NFC_EXPORT const char * str_nfc_modulation_type (const nfc_modulation_type nmt);
|
|
|
|
NFC_EXPORT const char * str_nfc_baud_rate (const nfc_baud_rate nbr);
|
|
|
|
|
2010-01-10 18:14:26 +00:00
|
|
|
|
2012-05-29 15:52:51 +00:00
|
|
|
/* Error codes */
|
|
|
|
/** @ingroup error
|
|
|
|
* @hideinitializer
|
|
|
|
* Success (no error)
|
|
|
|
*/
|
2012-01-31 09:49:43 +00:00
|
|
|
#define NFC_SUCCESS 0
|
2012-05-29 15:52:51 +00:00
|
|
|
/** @ingroup error
|
|
|
|
* @hideinitializer
|
|
|
|
* Input / output error, device may not be usable anymore without re-open it
|
|
|
|
*/
|
2012-01-31 09:49:43 +00:00
|
|
|
#define NFC_EIO -1
|
2012-05-29 15:52:51 +00:00
|
|
|
/** @ingroup error
|
|
|
|
* @hideinitializer
|
|
|
|
* Invalid argument(s)
|
|
|
|
*/
|
2012-01-31 09:49:43 +00:00
|
|
|
#define NFC_EINVARG -2
|
2012-05-29 15:52:51 +00:00
|
|
|
/** @ingroup error
|
|
|
|
* @hideinitializer
|
|
|
|
* Operation not supported by device
|
|
|
|
*/
|
2012-01-31 09:49:43 +00:00
|
|
|
#define NFC_EDEVNOTSUPP -3
|
2012-05-29 15:52:51 +00:00
|
|
|
/** @ingroup error
|
|
|
|
* @hideinitializer
|
|
|
|
* No such device
|
|
|
|
*/
|
2012-01-31 09:49:43 +00:00
|
|
|
#define NFC_ENOTSUCHDEV -4
|
2012-05-29 15:52:51 +00:00
|
|
|
/** @ingroup error
|
|
|
|
* @hideinitializer
|
|
|
|
* Buffer overflow
|
|
|
|
*/
|
2012-01-31 09:49:43 +00:00
|
|
|
#define NFC_EOVFLOW -5
|
2012-05-29 15:52:51 +00:00
|
|
|
/** @ingroup error
|
|
|
|
* @hideinitializer
|
|
|
|
* Operation timed out
|
|
|
|
*/
|
2012-01-31 09:49:43 +00:00
|
|
|
#define NFC_ETIMEOUT -6
|
2012-05-29 15:52:51 +00:00
|
|
|
/** @ingroup error
|
|
|
|
* @hideinitializer
|
|
|
|
* Operation aborted (by user)
|
|
|
|
*/
|
2012-01-31 09:49:43 +00:00
|
|
|
#define NFC_EOPABORTED -7
|
2012-05-29 15:52:51 +00:00
|
|
|
/** @ingroup error
|
|
|
|
* @hideinitializer
|
|
|
|
* Not (yet) implemented
|
|
|
|
*/
|
2012-01-31 09:49:43 +00:00
|
|
|
#define NFC_ENOTIMPL -8
|
2012-05-29 15:52:51 +00:00
|
|
|
/** @ingroup error
|
|
|
|
* @hideinitializer
|
|
|
|
* Target released
|
|
|
|
*/
|
2012-05-29 00:33:22 +00:00
|
|
|
#define NFC_ETGRELEASED -10
|
2012-05-29 15:52:51 +00:00
|
|
|
/** @ingroup error
|
|
|
|
* @hideinitializer
|
|
|
|
* Error while RF transmission
|
|
|
|
*/
|
2012-01-31 09:49:43 +00:00
|
|
|
#define NFC_ERFTRANS -20
|
2012-05-29 15:52:51 +00:00
|
|
|
/** @ingroup error
|
|
|
|
* @hideinitializer
|
|
|
|
* Software error (allocation, file/pipe creation, etc.)
|
|
|
|
*/
|
2012-05-16 18:24:16 +00:00
|
|
|
#define NFC_ESOFT -80
|
2012-05-29 15:52:51 +00:00
|
|
|
/** @ingroup error
|
|
|
|
* @hideinitializer
|
|
|
|
* Device's internal chip error
|
|
|
|
*/
|
2012-01-31 09:49:43 +00:00
|
|
|
#define NFC_ECHIP -90
|
|
|
|
|
2010-08-15 14:08:29 +00:00
|
|
|
|
2010-09-07 17:51:03 +00:00
|
|
|
# ifdef __cplusplus
|
2009-11-02 07:46:29 +00:00
|
|
|
}
|
2010-09-07 17:51:03 +00:00
|
|
|
# endif // __cplusplus
|
|
|
|
#endif // _LIBNFC_H_
|