libnfc
1.4.2
|
00001 /*- 00002 * Public platform independent Near Field Communication (NFC) library 00003 * 00004 * Copyright (C) 2009, Roel Verdult 00005 * Copyright (C) 2010, Romuald Conty 00006 * 00007 * This program is free software: you can redistribute it and/or modify it 00008 * under the terms of the GNU Lesser General Public License as published by the 00009 * Free Software Foundation, either version 3 of the License, or (at your 00010 * option) any later version. 00011 * 00012 * This program is distributed in the hope that it will be useful, but WITHOUT 00013 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00014 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 00015 * more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public License 00018 * along with this program. If not, see <http://www.gnu.org/licenses/> 00019 */ 00020 00028 #ifndef _LIBNFC_H_ 00029 # define _LIBNFC_H_ 00030 00031 # include <stdint.h> 00032 # include <stdbool.h> 00033 00034 # ifdef _WIN32 00035 /* Windows platform */ 00036 # ifndef _WINDLL 00037 /* CMake compilation */ 00038 # ifdef nfc_EXPORTS 00039 # define NFC_EXPORT __declspec(dllexport) 00040 # else 00041 /* nfc_EXPORTS */ 00042 # define NFC_EXPORT __declspec(dllimport) 00043 # endif 00044 /* nfc_EXPORTS */ 00045 # else 00046 /* _WINDLL */ 00047 /* Manual makefile */ 00048 # define NFC_EXPORT 00049 # endif 00050 /* _WINDLL */ 00051 # else 00052 /* _WIN32 */ 00053 # define NFC_EXPORT 00054 # endif 00055 /* _WIN32 */ 00056 00057 # include <nfc/nfc-types.h> 00058 00059 # ifdef __cplusplus 00060 extern "C" { 00061 # endif // __cplusplus 00062 00063 /* NFC Device/Hardware manipulation */ 00064 NFC_EXPORT nfc_device_t *nfc_connect (nfc_device_desc_t * pndd); 00065 NFC_EXPORT void nfc_disconnect (nfc_device_t * pnd); 00066 NFC_EXPORT void nfc_list_devices (nfc_device_desc_t pnddDevices[], size_t szDevices, size_t * pszDeviceFound); 00067 NFC_EXPORT bool nfc_configure (nfc_device_t * pnd, const nfc_device_option_t ndo, const bool bEnable); 00068 00069 /* NFC initiator: act as "reader" */ 00070 NFC_EXPORT bool nfc_initiator_init (nfc_device_t * pnd); 00071 NFC_EXPORT bool nfc_initiator_select_passive_target (nfc_device_t * pnd, const nfc_modulation_t nm, 00072 const byte_t * pbtInitData, const size_t szInitData, 00073 nfc_target_t * pnt); 00074 NFC_EXPORT bool nfc_initiator_list_passive_targets (nfc_device_t * pnd, const nfc_modulation_t nm, 00075 nfc_target_t ant[], const size_t szTargets, 00076 size_t * pszTargetFound); 00077 NFC_EXPORT bool nfc_initiator_poll_targets (nfc_device_t * pnd, const nfc_modulation_t * pnmTargetTypes, 00078 const size_t szTargetTypes, const byte_t btPollNr, const byte_t btPeriod, 00079 nfc_target_t * pntTargets, size_t * pszTargetFound); 00080 NFC_EXPORT bool nfc_initiator_select_dep_target (nfc_device_t * pnd, 00081 const nfc_dep_mode_t ndm, const nfc_baud_rate_t nbr, 00082 const nfc_dep_info_t * pndiInitiator, 00083 nfc_target_t * pnt); 00084 NFC_EXPORT bool nfc_initiator_deselect_target (nfc_device_t * pnd); 00085 NFC_EXPORT bool nfc_initiator_transceive_bytes (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx, 00086 byte_t * pbtRx, size_t * pszRx); 00087 NFC_EXPORT bool nfc_initiator_transceive_bits (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxBits, 00088 const byte_t * pbtTxPar, byte_t * pbtRx, size_t * pszRxBits, 00089 byte_t * pbtRxPar); 00090 00091 /* NFC target: act as tag (i.e. MIFARE Classic) or NFC target device. */ 00092 NFC_EXPORT bool nfc_target_init (nfc_device_t * pnd, nfc_target_t * pnt, byte_t * pbtRx, size_t * pszRx); 00093 NFC_EXPORT bool nfc_target_send_bytes (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx); 00094 NFC_EXPORT bool nfc_target_receive_bytes (nfc_device_t * pnd, byte_t * pbtRx, size_t * pszRx); 00095 NFC_EXPORT bool nfc_target_send_bits (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxBits, 00096 const byte_t * pbtTxPar); 00097 NFC_EXPORT bool nfc_target_receive_bits (nfc_device_t * pnd, byte_t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar); 00098 00099 /* Error reporting */ 00100 NFC_EXPORT const char *nfc_strerror (const nfc_device_t * pnd); 00101 NFC_EXPORT int nfc_strerror_r (const nfc_device_t * pnd, char *pcStrErrBuf, size_t szBufLen); 00102 NFC_EXPORT void nfc_perror (const nfc_device_t * pnd, const char *pcString); 00103 00104 /* Special data accessors */ 00105 NFC_EXPORT const char *nfc_device_name (nfc_device_t * pnd); 00106 00107 /* Misc. functions */ 00108 NFC_EXPORT void iso14443a_crc (byte_t * pbtData, size_t szLen, byte_t * pbtCrc); 00109 NFC_EXPORT void iso14443a_crc_append (byte_t * pbtData, size_t szLen); 00110 NFC_EXPORT byte_t * iso14443a_locate_historical_bytes (byte_t * pbtAts, size_t szAts, size_t * pszTk); 00111 NFC_EXPORT const char *nfc_version (void); 00112 00113 /* PN53x specific errors */ 00114 // TODO: Be not PN53x-specific here 00115 #define ETIMEOUT 0x01 00116 #define ECRC 0x02 00117 #define EPARITY 0x03 00118 #define EBITCOUNT 0x04 00119 #define EFRAMING 0x05 00120 #define EBITCOLL 0x06 00121 #define ESMALLBUF 0x07 00122 #define EBUFOVF 0x09 00123 #define ERFTIMEOUT 0x0a 00124 #define ERFPROTO 0x0b 00125 #define EOVHEAT 0x0d 00126 #define EINBUFOVF 0x0e 00127 #define EINVPARAM 0x10 00128 #define EDEPUNKCMD 0x12 00129 #define EINVRXFRAM 0x13 00130 #define EMFAUTH 0x14 00131 #define ENSECNOTSUPP 0x18 // PN533 only 00132 #define EBCC 0x23 00133 #define EDEPINVSTATE 0x25 00134 #define EOPNOTALL 0x26 00135 #define ECMD 0x27 00136 #define ETGREL 0x29 00137 #define ECID 0x2a 00138 #define ECDISCARDED 0x2b 00139 #define ENFCID3 0x2c 00140 #define EOVCURRENT 0x2d 00141 #define ENAD 0x2e 00142 00143 /* Software level errors */ 00144 #define ETGUIDNOTSUP 0x0100 /* Target UID not supported */ 00145 00146 /* Common device-level errors */ 00147 #define DEIO 0x1000 /* Input/output error */ 00148 #define DEINVAL 0x2000 /* Invalid argument */ 00149 #define DETIMEOUT 0x3000 /* Operation timeout */ 00150 00151 # ifdef __cplusplus 00152 } 00153 # endif // __cplusplus 00154 #endif // _LIBNFC_H_