libnfc  1.4.2
nfc.h
Go to the documentation of this file.
1 /*-
2  * Public platform independent Near Field Communication (NFC) library
3  *
4  * Copyright (C) 2009, Roel Verdult
5  * Copyright (C) 2010, Romuald Conty
6  *
7  * This program is free software: you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation, either version 3 of the License, or (at your
10  * option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15  * more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>
19  */
20 
28 #ifndef _LIBNFC_H_
29 # define _LIBNFC_H_
30 
31 # include <stdint.h>
32 # include <stdbool.h>
33 
34 # ifdef _WIN32
35  /* Windows platform */
36 # ifndef _WINDLL
37  /* CMake compilation */
38 # ifdef nfc_EXPORTS
39 # define NFC_EXPORT __declspec(dllexport)
40 # else
41  /* nfc_EXPORTS */
42 # define NFC_EXPORT __declspec(dllimport)
43 # endif
44  /* nfc_EXPORTS */
45 # else
46  /* _WINDLL */
47  /* Manual makefile */
48 # define NFC_EXPORT
49 # endif
50  /* _WINDLL */
51 # else
52  /* _WIN32 */
53 # define NFC_EXPORT
54 # endif
55  /* _WIN32 */
56 
57 # include <nfc/nfc-types.h>
58 
59 # ifdef __cplusplus
60 extern "C" {
61 # endif // __cplusplus
62 
63 /* NFC Device/Hardware manipulation */
64  NFC_EXPORT nfc_device_t *nfc_connect (nfc_device_desc_t * pndd);
65  NFC_EXPORT void nfc_disconnect (nfc_device_t * pnd);
66  NFC_EXPORT void nfc_list_devices (nfc_device_desc_t pnddDevices[], size_t szDevices, size_t * pszDeviceFound);
67  NFC_EXPORT bool nfc_configure (nfc_device_t * pnd, const nfc_device_option_t ndo, const bool bEnable);
68 
69 /* NFC initiator: act as "reader" */
70  NFC_EXPORT bool nfc_initiator_init (nfc_device_t * pnd);
71  NFC_EXPORT bool nfc_initiator_select_passive_target (nfc_device_t * pnd, const nfc_modulation_t nm,
72  const byte_t * pbtInitData, const size_t szInitData,
73  nfc_target_t * pnt);
74  NFC_EXPORT bool nfc_initiator_list_passive_targets (nfc_device_t * pnd, const nfc_modulation_t nm,
75  nfc_target_t ant[], const size_t szTargets,
76  size_t * pszTargetFound);
77  NFC_EXPORT bool nfc_initiator_poll_targets (nfc_device_t * pnd, const nfc_modulation_t * pnmTargetTypes,
78  const size_t szTargetTypes, const byte_t btPollNr, const byte_t btPeriod,
79  nfc_target_t * pntTargets, size_t * pszTargetFound);
80  NFC_EXPORT bool nfc_initiator_select_dep_target (nfc_device_t * pnd,
81  const nfc_dep_mode_t ndm, const nfc_baud_rate_t nbr,
82  const nfc_dep_info_t * pndiInitiator,
83  nfc_target_t * pnt);
84  NFC_EXPORT bool nfc_initiator_deselect_target (nfc_device_t * pnd);
85  NFC_EXPORT bool nfc_initiator_transceive_bytes (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx,
86  byte_t * pbtRx, size_t * pszRx);
87  NFC_EXPORT bool nfc_initiator_transceive_bits (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxBits,
88  const byte_t * pbtTxPar, byte_t * pbtRx, size_t * pszRxBits,
89  byte_t * pbtRxPar);
90 
91 /* NFC target: act as tag (i.e. MIFARE Classic) or NFC target device. */
92  NFC_EXPORT bool nfc_target_init (nfc_device_t * pnd, nfc_target_t * pnt, byte_t * pbtRx, size_t * pszRx);
93  NFC_EXPORT bool nfc_target_send_bytes (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx);
94  NFC_EXPORT bool nfc_target_receive_bytes (nfc_device_t * pnd, byte_t * pbtRx, size_t * pszRx);
95  NFC_EXPORT bool nfc_target_send_bits (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxBits,
96  const byte_t * pbtTxPar);
97  NFC_EXPORT bool nfc_target_receive_bits (nfc_device_t * pnd, byte_t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar);
98 
99 /* Error reporting */
100  NFC_EXPORT const char *nfc_strerror (const nfc_device_t * pnd);
101  NFC_EXPORT int nfc_strerror_r (const nfc_device_t * pnd, char *pcStrErrBuf, size_t szBufLen);
102  NFC_EXPORT void nfc_perror (const nfc_device_t * pnd, const char *pcString);
103 
104 /* Special data accessors */
105  NFC_EXPORT const char *nfc_device_name (nfc_device_t * pnd);
106 
107 /* Misc. functions */
108  NFC_EXPORT void iso14443a_crc (byte_t * pbtData, size_t szLen, byte_t * pbtCrc);
109  NFC_EXPORT void iso14443a_crc_append (byte_t * pbtData, size_t szLen);
110  NFC_EXPORT byte_t * iso14443a_locate_historical_bytes (byte_t * pbtAts, size_t szAts, size_t * pszTk);
111  NFC_EXPORT const char *nfc_version (void);
112 
113 /* PN53x specific errors */
114 // TODO: Be not PN53x-specific here
115 #define ETIMEOUT 0x01
116 #define ECRC 0x02
117 #define EPARITY 0x03
118 #define EBITCOUNT 0x04
119 #define EFRAMING 0x05
120 #define EBITCOLL 0x06
121 #define ESMALLBUF 0x07
122 #define EBUFOVF 0x09
123 #define ERFTIMEOUT 0x0a
124 #define ERFPROTO 0x0b
125 #define EOVHEAT 0x0d
126 #define EINBUFOVF 0x0e
127 #define EINVPARAM 0x10
128 #define EDEPUNKCMD 0x12
129 #define EINVRXFRAM 0x13
130 #define EMFAUTH 0x14
131 #define ENSECNOTSUPP 0x18 // PN533 only
132 #define EBCC 0x23
133 #define EDEPINVSTATE 0x25
134 #define EOPNOTALL 0x26
135 #define ECMD 0x27
136 #define ETGREL 0x29
137 #define ECID 0x2a
138 #define ECDISCARDED 0x2b
139 #define ENFCID3 0x2c
140 #define EOVCURRENT 0x2d
141 #define ENAD 0x2e
142 
143 /* Software level errors */
144 #define ETGUIDNOTSUP 0x0100 /* Target UID not supported */
145 
146 /* Common device-level errors */
147 #define DEIO 0x1000 /* Input/output error */
148 #define DEINVAL 0x2000 /* Invalid argument */
149 #define DETIMEOUT 0x3000 /* Operation timeout */
150 
151 # ifdef __cplusplus
152 }
153 # endif // __cplusplus
154 #endif // _LIBNFC_H_