nfc.h

Go to the documentation of this file.
00001 /*-
00002  * Public platform independent Near Field Communication (NFC) library
00003  * 
00004  * Copyright (C) 2009, Roel Verdult
00005  * 
00006  * This program is free software: you can redistribute it and/or modify it
00007  * under the terms of the GNU Lesser General Public License as published by the
00008  * Free Software Foundation, either version 3 of the License, or (at your
00009  * option) any later version.
00010  * 
00011  * This program is distributed in the hope that it will be useful, but WITHOUT
00012  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00013  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
00014  * more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public License
00017  * along with this program.  If not, see <http://www.gnu.org/licenses/>
00018  */
00019 
00027 #ifndef _LIBNFC_H_
00028 #  define _LIBNFC_H_
00029 
00030 #  include <stdint.h>
00031 #  include <stdbool.h>
00032 
00033 #  ifdef _WIN32
00034   /* Windows platform */
00035 #    ifndef _WINDLL
00036     /* CMake compilation */
00037 #      ifdef nfc_EXPORTS
00038 #        define  NFC_EXPORT __declspec(dllexport)
00039 #      else
00040       /* nfc_EXPORTS */
00041 #        define  NFC_EXPORT __declspec(dllimport)
00042 #      endif
00043        /* nfc_EXPORTS */
00044 #    else
00045       /* _WINDLL */
00046     /* Manual makefile */
00047 #      define NFC_EXPORT
00048 #    endif
00049        /* _WINDLL */
00050 #  else
00051       /* _WIN32 */
00052 #    define NFC_EXPORT
00053 #  endif
00054        /* _WIN32 */
00055 
00056 #  include <nfc/nfc-types.h>
00057 
00058 #  ifdef __cplusplus
00059 extern  "C" {
00060 #  endif                        // __cplusplus
00061 
00062 /* NFC Device/Hardware manipulation */
00063   NFC_EXPORT void nfc_list_devices (nfc_device_desc_t pnddDevices[], size_t szDevices, size_t * pszDeviceFound);
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 bool nfc_configure (nfc_device_t * pnd, const nfc_device_option_t ndo, const bool bEnable);
00067 
00068 /* NFC initiator: act as "reader" */
00069   NFC_EXPORT bool nfc_initiator_init (nfc_device_t * pnd);
00070   NFC_EXPORT bool nfc_initiator_select_passive_target (nfc_device_t * pnd, const nfc_modulation_t nmInitModulation,
00071                                                        const byte_t * pbtInitData, const size_t szInitDataLen,
00072                                                        nfc_target_info_t * pti);
00073   NFC_EXPORT bool nfc_initiator_list_passive_targets (nfc_device_t * pnd, const nfc_modulation_t nmInitModulation,
00074                                                       nfc_target_info_t anti[], const size_t szTargets,
00075                                                       size_t * pszTargetFound);
00076   NFC_EXPORT bool nfc_initiator_poll_targets (nfc_device_t * pnd, const nfc_target_type_t * pnttTargetTypes,
00077                                               const size_t szTargetTypes, const byte_t btPollNr, const byte_t btPeriod,
00078                                               nfc_target_t * pntTargets, size_t * pszTargetFound);
00079   NFC_EXPORT bool nfc_initiator_select_dep_target (nfc_device_t * pnd, const nfc_modulation_t nmInitModulation,
00080                                                    const byte_t * pbtPidData, const size_t szPidDataLen,
00081                                                    const byte_t * pbtNFCID3i, const size_t szNFCID3iDataLen,
00082                                                    const byte_t * pbtGbData, const size_t szGbDataLen,
00083                                                    nfc_target_info_t * pti);
00084   NFC_EXPORT bool nfc_initiator_deselect_target (nfc_device_t * pnd);
00085   NFC_EXPORT bool nfc_initiator_transceive_bits (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxBits,
00086                                                  const byte_t * pbtTxPar, byte_t * pbtRx, size_t * pszRxBits,
00087                                                  byte_t * pbtRxPar);
00088   NFC_EXPORT bool nfc_initiator_transceive_bytes (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxLen,
00089                                                   byte_t * pbtRx, size_t * pszRxLen);
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, byte_t * pbtRx, size_t * pszRxBits);
00093   NFC_EXPORT bool nfc_target_receive_bits (nfc_device_t * pnd, byte_t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar);
00094   NFC_EXPORT bool nfc_target_receive_bytes (nfc_device_t * pnd, byte_t * pbtRx, size_t * pszRxLen);
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_send_bytes (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxLen);
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 append_iso14443a_crc (byte_t * pbtData, size_t szLen);
00110   NFC_EXPORT const char *nfc_version (void);
00111 
00112 /* Common device-level errors */
00113 #  define DEIO            0x1000/* Input/output error */
00114 #  define DEINVAL         0x2000/* Invalid argument */
00115 #  define DETIMEOUT       0x3000/* Operation timeout */
00116 
00117 #  ifdef __cplusplus
00118 }
00119 #  endif                        // __cplusplus
00120 #endif                          // _LIBNFC_H_