nfc-emulation.h   nfc-emulation.h 
/*- /*-
* Public platform independent Near Field Communication (NFC) library * Free/Libre Near Field Communication (NFC) library
* *
* Copyright (C) 2011, Romuald Conty, Romain Tartière * Libnfc historical contributors:
* Copyright (C) 2009 Roel Verdult
* Copyright (C) 2009-2013 Romuald Conty
* Copyright (C) 2010-2012 Romain Tartière
* Copyright (C) 2010-2013 Philippe Teuwen
* Copyright (C) 2012-2013 Ludovic Rousseau
* See AUTHORS file for a more comprehensive list of contributors.
* Additional contributors of this file:
* *
* This program is free software: you can redistribute it and/or modify it * 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 * 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 * Free Software Foundation, either version 3 of the License, or (at your
* option) any later version. * option) any later version.
* *
* This program is distributed in the hope that it will be useful, but WITH OUT * This program is distributed in the hope that it will be useful, but WITH OUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License fo r * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License fo r
* more details. * more details.
* *
* You should have received a copy of the GNU Lesser General Public License * 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/> * along with this program. If not, see <http://www.gnu.org/licenses/>
*/ */
/**
* @file nfc-emulation.h
* @brief Provide a small API to ease emulation in libnfc
*/
#ifndef __NFC_EMULATION_H__ #ifndef __NFC_EMULATION_H__
#define __NFC_EMULATION_H__ #define __NFC_EMULATION_H__
#include <sys/types.h> #include <sys/types.h>
#include <nfc/nfc.h> #include <nfc/nfc.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
struct nfc_emulator; struct nfc_emulator;
struct nfc_emulation_state_machine; struct nfc_emulation_state_machine;
/**
* @struct nfc_emulator
* @brief NFC emulator structure
*/
struct nfc_emulator { struct nfc_emulator {
nfc_target_t *target; nfc_target *target;
struct nfc_emulation_state_machine *state_machine; struct nfc_emulation_state_machine *state_machine;
void *user_data; void *user_data;
}; };
/**
* @struct nfc_emulation_state_machine
* @brief NFC emulation state machine structure
*/
struct nfc_emulation_state_machine { struct nfc_emulation_state_machine {
int (*io)(struct nfc_emulator *emulator, const byte_t *data_in, const siz e_t data_in_len, byte_t *data_out, const size_t data_out_len); int (*io)(struct nfc_emulator *emulator, const uint8_t *data_in, const si ze_t data_in_len, uint8_t *data_out, const size_t data_out_len);
void *data; void *data;
}; };
NFC_EXPORT int nfc_emulate_target (nfc_device_t* pnd, struct nfc_emulato r *emulator); NFC_EXPORT int nfc_emulate_target(nfc_device *pnd, struct nfc_emulator * emulator, const int timeout);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */
#endif /* __NFC_EMULATION_H__ */ #endif /* __NFC_EMULATION_H__ */
 End of changes. 8 change blocks. 
5 lines changed or deleted 25 lines changed or added


 nfc-types.h   nfc-types.h 
/** /*-
* Public platform independent Near Field Communication (NFC) library * Free/Libre Near Field Communication (NFC) library
* *
* Copyright (C) 2009, Roel Verdult * Libnfc historical contributors:
* Copyright (C) 2010, Romain Tartière, Romuald Conty * Copyright (C) 2009 Roel Verdult
* Copyright (C) 2011, Romain Tartière, Romuald Conty * Copyright (C) 2009-2013 Romuald Conty
* Copyright (C) 2010-2012 Romain Tartière
* Copyright (C) 2010-2013 Philippe Teuwen
* Copyright (C) 2012-2013 Ludovic Rousseau
* See AUTHORS file for a more comprehensive list of contributors.
* Additional contributors of this file:
* *
* This program is free software: you can redistribute it and/or modify it * 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 * 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 * Free Software Foundation, either version 3 of the License, or (at your
* option) any later version. * option) any later version.
* *
* This program is distributed in the hope that it will be useful, but WITH OUT * This program is distributed in the hope that it will be useful, but WITH OUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License fo r * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License fo r
* more details. * more details.
skipping to change at line 28 skipping to change at line 33
* You should have received a copy of the GNU Lesser General Public License * 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/> * along with this program. If not, see <http://www.gnu.org/licenses/>
*/ */
/** /**
* @file nfc-types.h * @file nfc-types.h
* @brief Define NFC types * @brief Define NFC types
*/ */
#ifndef __NFC_TYPES_H__ #ifndef __NFC_TYPES_H__
# define __NFC_TYPES_H__ #define __NFC_TYPES_H__
# include <stddef.h>
# include <stdint.h>
# include <stdbool.h>
# include <stdio.h>
typedef uint8_t byte_t; #include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
# define DEVICE_NAME_LENGTH 256 #ifndef NFC_BUFSIZE_CONNSTRING
# define DEVICE_PORT_LENGTH 64 #define NFC_BUFSIZE_CONNSTRING 1024
#endif
/** /**
* @struct nfc_device_t * NFC context
* @brief NFC device information
*/ */
typedef struct { typedef struct nfc_context nfc_context;
/** Driver's functions for handling device specific wrapping */
const struct nfc_driver_t *driver; /**
void* driver_data; * NFC device
void* chip_data;
/** Device name string, including device wrapper firmware */
char acName[DEVICE_NAME_LENGTH];
/** Is the crc automaticly added, checked and removed from the frames */
bool bCrc;
/** Does the chip handle parity bits, all parities are handled as data */
bool bPar;
/** Should the chip handle frames encapsulation and chaining */
bool bEasyFraming;
/** Should the chip switch automatically activate ISO14443-4 when
selecting tags supporting it? */
bool bAutoIso14443_4;
/** Supported modulation encoded in a byte */
byte_t btSupportByte;
/** Last error reported by the PCD / encountered by the PCD driver
* MSB LSB
* | 00 | 00 |
* || ||
* || ++----- Chip-level error (as reported by the PCD)
* |+---------- Driver-level specific error
* +----------- Driver-level general error (common to all drivers)
*/ */
int iLastError; typedef struct nfc_device nfc_device;
} nfc_device_t;
/** /**
* @struct nfc_device_desc_t * NFC device driver
* @brief NFC device description
*
* This struct is used to try to connect to a specified nfc device when nfc
_connect(...)
*/ */
typedef struct { typedef struct nfc_driver nfc_driver;
/** Device name (e.g. "ACS ACR 38U-CCID 00 00") */
char acDevice[DEVICE_NAME_LENGTH];
/** Driver name (e.g. "PN532_UART")*/
char *pcDriver;
/** Port (e.g. "/dev/ttyUSB0") */
char acPort[DEVICE_PORT_LENGTH];
/** Port speed (e.g. "115200") */
uint32_t uiSpeed;
/** Device index for backward compatibility (used to choose one specific
device in USB or PSCS devices list) */
uint32_t uiBusIndex;
} nfc_device_desc_t;
// Compiler directive, set struct alignment to 1 byte_t for compatibility /**
# pragma pack(1) * Connection string
*/
typedef char nfc_connstring[NFC_BUFSIZE_CONNSTRING];
/** /**
* @enum nfc_device_option_t * Properties
* @brief NFC device option
*/ */
typedef enum { typedef enum {
/** Let the PN53X chip handle the CRC bytes. This means that the chip appen /**
ds * Default command processing timeout
* the CRC bytes to the frames that are transmitted. It will parse the last * Property value's (duration) unit is ms and 0 means no timeout (infinit
* bytes from received frames as incoming CRC bytes. They will be verified e).
* against the used modulation and protocol. If an frame is expected with * Default value is set by driver layer
* incorrect CRC bytes this option should be disabled. Example frames where */
* this is useful are the ATQA and UID+BCC that are transmitted without CRC NP_TIMEOUT_COMMAND,
* bytes during the anti-collision phase of the ISO14443-A protocol. */ /**
NDO_HANDLE_CRC = 0x00, * Timeout between ATR_REQ and ATR_RES
/** Parity bits in the network layer of ISO14443-A are by default generated * When the device is in initiator mode, a target is considered as mute i
and f no
* validated in the PN53X chip. This is a very convenient feature. On certa * valid ATR_RES is received within this timeout value.
in * Default value for this property is 103 ms on PN53x based devices.
* times though it is useful to get full control of the transmitted data. T */
he NP_TIMEOUT_ATR,
* proprietary MIFARE Classic protocol uses for example custom (encrypted) /**
* parity bits. For interoperability it is required to be completely * Timeout value to give up reception from the target in case of no answe
* compatible, including the arbitrary parity bits. When this option is r.
* disabled, the functions to communicating bits should be used. */ * Default value for this property is 52 ms).
NDO_HANDLE_PARITY = 0x01, */
/** This option can be used to enable or disable the electronic field of th NP_TIMEOUT_COM,
e /** Let the PN53X chip handle the CRC bytes. This means that the chip app
* NFC device. */ ends
NDO_ACTIVATE_FIELD = 0x10, * the CRC bytes to the frames that are transmitted. It will parse the las
/** The internal CRYPTO1 co-processor can be used to transmit messages t
* encrypted. This option is automatically activated after a successful MIF * bytes from received frames as incoming CRC bytes. They will be verified
ARE * against the used modulation and protocol. If an frame is expected with
* Classic authentication. */ * incorrect CRC bytes this option should be disabled. Example frames wher
NDO_ACTIVATE_CRYPTO1 = 0x11, e
/** The default configuration defines that the PN53X chip will try indefini * this is useful are the ATQA and UID+BCC that are transmitted without CR
tely C
* to invite a tag in the field to respond. This could be desired when it i * bytes during the anti-collision phase of the ISO14443-A protocol. */
s NP_HANDLE_CRC,
* certain a tag will enter the field. On the other hand, when this is /** Parity bits in the network layer of ISO14443-A are by default generat
* uncertain, it will block the application. This option could best be comp ed and
ared * validated in the PN53X chip. This is a very convenient feature. On cer
* to the (NON)BLOCKING option used by (socket)network programming. */ tain
NDO_INFINITE_SELECT = 0x20, * times though it is useful to get full control of the transmitted data.
/** If this option is enabled, frames that carry less than 4 bits are allow The
ed. * proprietary MIFARE Classic protocol uses for example custom (encrypted
* According to the standards these frames should normally be handles as )
* invalid frames. */ * parity bits. For interoperability it is required to be completely
NDO_ACCEPT_INVALID_FRAMES = 0x30, * compatible, including the arbitrary parity bits. When this option is
/** If the NFC device should only listen to frames, it could be useful to l * disabled, the functions to communicating bits should be used. */
et NP_HANDLE_PARITY,
* it gather multiple frames in a sequence. They will be stored in the inte /** This option can be used to enable or disable the electronic field of
rnal the
* FIFO of the PN53X chip. This could be retrieved by using the receive dat * NFC device. */
a NP_ACTIVATE_FIELD,
* functions. Note that if the chip runs out of bytes (FIFO = 64 bytes long /** The internal CRYPTO1 co-processor can be used to transmit messages
), * encrypted. This option is automatically activated after a successful M
* it will overwrite the first received frames, so quick retrieving of the IFARE
* received data is desirable. */ * Classic authentication. */
NDO_ACCEPT_MULTIPLE_FRAMES = 0x31, NP_ACTIVATE_CRYPTO1,
/** This option can be used to enable or disable the auto-switching mode to /** The default configuration defines that the PN53X chip will try indefi
* ISO14443-4 is device is compliant. nitely
* In initiator mode, it means that NFC chip will send RATS automatically w * to invite a tag in the field to respond. This could be desired when it
hen is
* select and it will automatically poll for ISO14443-4 card when ISO14443A * certain a tag will enter the field. On the other hand, when this is
is * uncertain, it will block the application. This option could best be co
* requested. mpared
* In target mode, with a NFC chip compiliant (ie. PN532), the chip will * to the (NON)BLOCKING option used by (socket)network programming. */
* emulate a 14443-4 PICC using hardware capability */ NP_INFINITE_SELECT,
NDO_AUTO_ISO14443_4 = 0x40, /** If this option is enabled, frames that carry less than 4 bits are all
/** Use automatic frames encapsulation and chaining. */ owed.
NDO_EASY_FRAMING = 0x41, * According to the standards these frames should normally be handles as
/** Force the chip to switch in ISO14443-A */ * invalid frames. */
NDO_FORCE_ISO14443_A = 0x42, NP_ACCEPT_INVALID_FRAMES,
/** Force the chip to switch in ISO14443-B */ /** If the NFC device should only listen to frames, it could be useful to
NDO_FORCE_ISO14443_B = 0x43, let
/** Force the chip to run at 106 kbps */ * it gather multiple frames in a sequence. They will be stored in the in
NDO_FORCE_SPEED_106 = 0x50, ternal
} nfc_device_option_t; * FIFO of the PN53X chip. This could be retrieved by using the receive d
ata
* functions. Note that if the chip runs out of bytes (FIFO = 64 bytes lo
ng),
* it will overwrite the first received frames, so quick retrieving of th
e
* received data is desirable. */
NP_ACCEPT_MULTIPLE_FRAMES,
/** This option can be used to enable or disable the auto-switching mode
to
* ISO14443-4 is device is compliant.
* In initiator mode, it means that NFC chip will send RATS automatically
when
* select and it will automatically poll for ISO14443-4 card when ISO1444
3A is
* requested.
* In target mode, with a NFC chip compliant (ie. PN532), the chip will
* emulate a 14443-4 PICC using hardware capability */
NP_AUTO_ISO14443_4,
/** Use automatic frames encapsulation and chaining. */
NP_EASY_FRAMING,
/** Force the chip to switch in ISO14443-A */
NP_FORCE_ISO14443_A,
/** Force the chip to switch in ISO14443-B */
NP_FORCE_ISO14443_B,
/** Force the chip to run at 106 kbps */
NP_FORCE_SPEED_106,
} nfc_property;
// Compiler directive, set struct alignment to 1 uint8_t for compatibility
# pragma pack(1)
/** /**
* @enum nfc_dep_mode_t * @enum nfc_dep_mode
* @brief NFC D.E.P. (Data Exchange Protocol) active/passive mode * @brief NFC D.E.P. (Data Exchange Protocol) active/passive mode
*/ */
typedef enum { typedef enum {
NDM_UNDEFINED = 0, NDM_UNDEFINED = 0,
NDM_PASSIVE, NDM_PASSIVE,
NDM_ACTIVE, NDM_ACTIVE,
} nfc_dep_mode_t; } nfc_dep_mode;
/** /**
* @struct nfc_dep_info_t * @struct nfc_dep_info
* @brief NFC target information in D.E.P. (Data Exchange Protocol) see ISO /IEC 18092 (NFCIP-1) * @brief NFC target information in D.E.P. (Data Exchange Protocol) see ISO /IEC 18092 (NFCIP-1)
*/ */
typedef struct { typedef struct {
/** NFCID3 */ /** NFCID3 */
byte_t abtNFCID3[10]; uint8_t abtNFCID3[10];
/** DID */ /** DID */
byte_t btDID; uint8_t btDID;
/** Supported send-bit rate */ /** Supported send-bit rate */
byte_t btBS; uint8_t btBS;
/** Supported receive-bit rate */ /** Supported receive-bit rate */
byte_t btBR; uint8_t btBR;
/** Timeout value */ /** Timeout value */
byte_t btTO; uint8_t btTO;
/** PP Parameters */ /** PP Parameters */
byte_t btPP; uint8_t btPP;
/** General Bytes */ /** General Bytes */
byte_t abtGB[48]; uint8_t abtGB[48];
size_t szGB; size_t szGB;
/** DEP mode */ /** DEP mode */
nfc_dep_mode_t ndm; nfc_dep_mode ndm;
} nfc_dep_info_t; } nfc_dep_info;
/** /**
* @struct nfc_iso14443a_info_t * @struct nfc_iso14443a_info
* @brief NFC ISO14443A tag (MIFARE) information * @brief NFC ISO14443A tag (MIFARE) information
*/ */
typedef struct { typedef struct {
byte_t abtAtqa[2]; uint8_t abtAtqa[2];
byte_t btSak; uint8_t btSak;
size_t szUidLen; size_t szUidLen;
byte_t abtUid[10]; uint8_t abtUid[10];
size_t szAtsLen; size_t szAtsLen;
byte_t abtAts[254]; // Maximal theoretical ATS is FSD-2, FSD=256 for FSD uint8_t abtAts[254]; // Maximal theoretical ATS is FSD-2, FSD=256 for FS
I=8 in RATS DI=8 in RATS
} nfc_iso14443a_info_t; } nfc_iso14443a_info;
/** /**
* @struct nfc_felica_info_t * @struct nfc_felica_info
* @brief NFC FeLiCa tag information * @brief NFC FeLiCa tag information
*/ */
typedef struct { typedef struct {
size_t szLen; size_t szLen;
byte_t btResCode; uint8_t btResCode;
byte_t abtId[8]; uint8_t abtId[8];
byte_t abtPad[8]; uint8_t abtPad[8];
byte_t abtSysCode[2]; uint8_t abtSysCode[2];
} nfc_felica_info_t; } nfc_felica_info;
/** /**
* @struct nfc_iso14443b_info_t * @struct nfc_iso14443b_info
* @brief NFC ISO14443B tag information * @brief NFC ISO14443B tag information
*/ */
typedef struct { typedef struct {
/** abtPupi store PUPI contained in ATQB (Answer To reQuest of type B) (see /** abtPupi store PUPI contained in ATQB (Answer To reQuest of type B) (s
ISO14443-3) */ ee ISO14443-3) */
byte_t abtPupi[4]; uint8_t abtPupi[4];
/** abtApplicationData store Application Data contained in ATQB (see ISO144 /** abtApplicationData store Application Data contained in ATQB (see ISO1
43-3) */ 4443-3) */
byte_t abtApplicationData[4]; uint8_t abtApplicationData[4];
/** abtProtocolInfo store Protocol Info contained in ATQB (see ISO14443-3) /** abtProtocolInfo store Protocol Info contained in ATQB (see ISO14443-3
*/ ) */
byte_t abtProtocolInfo[3]; uint8_t abtProtocolInfo[3];
/** ui8CardIdentifier store CID (Card Identifier) attributted by PCD to the /** ui8CardIdentifier store CID (Card Identifier) attributted by PCD to t
PICC */ he PICC */
uint8_t ui8CardIdentifier; uint8_t ui8CardIdentifier;
} nfc_iso14443b_info_t; } nfc_iso14443b_info;
/** /**
* @struct nfc_iso14443bi_info_t * @struct nfc_iso14443bi_info
* @brief NFC ISO14443B' tag information * @brief NFC ISO14443B' tag information
*/ */
typedef struct { typedef struct {
/** DIV: 4 LSBytes of tag serial number */ /** DIV: 4 LSBytes of tag serial number */
byte_t abtDIV[4]; uint8_t abtDIV[4];
/** Software version & type of REPGEN */ /** Software version & type of REPGEN */
byte_t btVerLog; uint8_t btVerLog;
/** Config Byte, present if long REPGEN */ /** Config Byte, present if long REPGEN */
byte_t btConfig; uint8_t btConfig;
/** ATR, if any */ /** ATR, if any */
size_t szAtrLen; size_t szAtrLen;
byte_t abtAtr[33]; uint8_t abtAtr[33];
} nfc_iso14443bi_info_t; } nfc_iso14443bi_info;
/** /**
* @struct nfc_iso14443b2sr_info_t * @struct nfc_iso14443b2sr_info
* @brief NFC ISO14443-2B ST SRx tag information * @brief NFC ISO14443-2B ST SRx tag information
*/ */
typedef struct { typedef struct {
byte_t abtUID[8]; uint8_t abtUID[8];
} nfc_iso14443b2sr_info_t; } nfc_iso14443b2sr_info;
/** /**
* @struct nfc_iso14443b2ct_info_t * @struct nfc_iso14443b2ct_info
* @brief NFC ISO14443-2B ASK CTx tag information * @brief NFC ISO14443-2B ASK CTx tag information
*/ */
typedef struct { typedef struct {
byte_t abtUID[4]; uint8_t abtUID[4];
byte_t btProdCode; uint8_t btProdCode;
byte_t btFabCode; uint8_t btFabCode;
} nfc_iso14443b2ct_info_t; } nfc_iso14443b2ct_info;
/** /**
* @struct nfc_jewel_info_t * @struct nfc_jewel_info
* @brief NFC Jewel tag information * @brief NFC Jewel tag information
*/ */
typedef struct { typedef struct {
byte_t btSensRes[2]; uint8_t btSensRes[2];
byte_t btId[4]; uint8_t btId[4];
} nfc_jewel_info_t; } nfc_jewel_info;
/** /**
* @union nfc_target_info_t * @union nfc_target_info
* @brief Union between all kind of tags information structures. * @brief Union between all kind of tags information structures.
*/ */
typedef union { typedef union {
nfc_iso14443a_info_t nai; nfc_iso14443a_info nai;
nfc_felica_info_t nfi; nfc_felica_info nfi;
nfc_iso14443b_info_t nbi; nfc_iso14443b_info nbi;
nfc_iso14443bi_info_t nii; nfc_iso14443bi_info nii;
nfc_iso14443b2sr_info_t nsi; nfc_iso14443b2sr_info nsi;
nfc_iso14443b2ct_info_t nci; nfc_iso14443b2ct_info nci;
nfc_jewel_info_t nji; nfc_jewel_info nji;
nfc_dep_info_t ndi; nfc_dep_info ndi;
} nfc_target_info_t; } nfc_target_info;
/** /**
* @enum nfc_baud_rate_t * @enum nfc_baud_rate
* @brief NFC baud rate enumeration * @brief NFC baud rate enumeration
*/ */
typedef enum { typedef enum {
NBR_UNDEFINED = 0, NBR_UNDEFINED = 0,
NBR_106, NBR_106,
NBR_212, NBR_212,
NBR_424, NBR_424,
NBR_847, NBR_847,
} nfc_baud_rate_t; } nfc_baud_rate;
/** /**
* @enum nfc_modulation_type_t * @enum nfc_modulation_type
* @brief NFC modulation type enumeration * @brief NFC modulation type enumeration
*/ */
typedef enum { typedef enum {
NMT_ISO14443A, NMT_ISO14443A = 1,
NMT_JEWEL, NMT_JEWEL,
NMT_ISO14443B, NMT_ISO14443B,
NMT_ISO14443BI, // pre-ISO14443B aka ISO/IEC 14443 B' or Type B' NMT_ISO14443BI, // pre-ISO14443B aka ISO/IEC 14443 B' or Type B'
NMT_ISO14443B2SR, // ISO14443-2B ST SRx NMT_ISO14443B2SR, // ISO14443-2B ST SRx
NMT_ISO14443B2CT, // ISO14443-2B ASK CTx NMT_ISO14443B2CT, // ISO14443-2B ASK CTx
NMT_FELICA, NMT_FELICA,
NMT_DEP, NMT_DEP,
} nfc_modulation_type_t; } nfc_modulation_type;
/**
* @enum nfc_mode
* @brief NFC mode type enumeration
*/
typedef enum {
N_TARGET,
N_INITIATOR,
} nfc_mode;
/** /**
* @struct nfc_modulation_t * @struct nfc_modulation
* @brief NFC modulation structure * @brief NFC modulation structure
*/ */
typedef struct { typedef struct {
nfc_modulation_type_t nmt; nfc_modulation_type nmt;
nfc_baud_rate_t nbr; nfc_baud_rate nbr;
} nfc_modulation_t; } nfc_modulation;
/** /**
* @struct nfc_target_t * @struct nfc_target
* @brief NFC target structure * @brief NFC target structure
*/ */
typedef struct { typedef struct {
nfc_target_info_t nti; nfc_target_info nti;
nfc_modulation_t nm; nfc_modulation nm;
} nfc_target_t; } nfc_target;
// Reset struct alignment to default // Reset struct alignment to default
# pragma pack() # pragma pack()
#endif // _LIBNFC_TYPES_H_ #endif // _LIBNFC_TYPES_H_
 End of changes. 47 change blocks. 
230 lines changed or deleted 234 lines changed or added


 nfc.h   nfc.h 
/*- /*-
* Public platform independent Near Field Communication (NFC) library * Free/Libre Near Field Communication (NFC) library
* *
* Copyright (C) 2009, Roel Verdult * Libnfc historical contributors:
* Copyright (C) 2010, Romuald Conty * Copyright (C) 2009 Roel Verdult
* Copyright (C) 2009-2013 Romuald Conty
* Copyright (C) 2010-2012 Romain Tartière
* Copyright (C) 2010-2013 Philippe Teuwen
* Copyright (C) 2012-2013 Ludovic Rousseau
* See AUTHORS file for a more comprehensive list of contributors.
* Additional contributors of this file:
* *
* This program is free software: you can redistribute it and/or modify it * 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 * 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 * Free Software Foundation, either version 3 of the License, or (at your
* option) any later version. * option) any later version.
* *
* This program is distributed in the hope that it will be useful, but WITH OUT * This program is distributed in the hope that it will be useful, but WITH OUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License fo r * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License fo r
* more details. * more details.
skipping to change at line 37 skipping to change at line 43
#ifndef _LIBNFC_H_ #ifndef _LIBNFC_H_
# define _LIBNFC_H_ # define _LIBNFC_H_
# include <sys/time.h> # include <sys/time.h>
# include <stdint.h> # include <stdint.h>
# include <stdbool.h> # include <stdbool.h>
# ifdef _WIN32 # ifdef _WIN32
/* Windows platform */ /* Windows platform */
# ifndef _WINDLL # ifndef _WINDLL
/* CMake compilation */ /* CMake compilation */
# ifdef nfc_EXPORTS # ifdef nfc_EXPORTS
# define NFC_EXPORT __declspec(dllexport) # define NFC_EXPORT __declspec(dllexport)
# else # else
/* nfc_EXPORTS */ /* nfc_EXPORTS */
# define NFC_EXPORT __declspec(dllimport) # define NFC_EXPORT __declspec(dllimport)
# endif # endif
/* nfc_EXPORTS */ /* nfc_EXPORTS */
# else # else
/* _WINDLL */ /* _WINDLL */
/* Manual makefile */ /* Manual makefile */
# define NFC_EXPORT # define NFC_EXPORT
# endif # endif
/* _WINDLL */ /* _WINDLL */
# else # else
/* _WIN32 */ /* _WIN32 */
# define NFC_EXPORT # define NFC_EXPORT
# endif # endif
/* _WIN32 */ /* _WIN32 */
# include <nfc/nfc-types.h> # include <nfc/nfc-types.h>
# ifndef __has_attribute
# define __has_attribute(x) 0
# endif
# if __has_attribute(nonnull) || defined(__GNUC__)
# define __has_attribute_nonnull 1
# endif
# if __has_attribute_nonnull
# define ATTRIBUTE_NONNULL( param ) __attribute__((nonnull (param)))
# else
# define ATTRIBUTE_NONNULL( param )
# endif
# ifdef __cplusplus # ifdef __cplusplus
extern "C" { extern "C" {
# endif // __cplusplus # endif // __cplusplus
/* Library initialization/deinitialization */
NFC_EXPORT void nfc_init(nfc_context **context) ATTRIBUTE_NONNULL(1);
NFC_EXPORT void nfc_exit(nfc_context *context) ATTRIBUTE_NONNULL(1);
NFC_EXPORT int nfc_register_driver(const nfc_driver *driver);
/* NFC Device/Hardware manipulation */ /* NFC Device/Hardware manipulation */
NFC_EXPORT nfc_device_t *nfc_connect (nfc_device_desc_t * pndd); NFC_EXPORT nfc_device *nfc_open(nfc_context *context, const nfc_connstring
NFC_EXPORT void nfc_disconnect (nfc_device_t * pnd); connstring) ATTRIBUTE_NONNULL(1);
NFC_EXPORT bool nfc_abort_command (nfc_device_t * pnd); NFC_EXPORT void nfc_close(nfc_device *pnd);
NFC_EXPORT void nfc_list_devices (nfc_device_desc_t pnddDevices[], size_t NFC_EXPORT int nfc_abort_command(nfc_device *pnd);
szDevices, size_t * pszDeviceFound); NFC_EXPORT size_t nfc_list_devices(nfc_context *context, nfc_connstring con
NFC_EXPORT bool nfc_configure (nfc_device_t * pnd, const nfc_device_optio nstrings[], size_t connstrings_len) ATTRIBUTE_NONNULL(1);
n_t ndo, const bool bEnable); NFC_EXPORT int nfc_idle(nfc_device *pnd);
NFC_EXPORT bool nfc_idle (nfc_device_t * pnd);
/* NFC initiator: act as "reader" */ /* NFC initiator: act as "reader" */
NFC_EXPORT bool nfc_initiator_init (nfc_device_t * pnd); NFC_EXPORT int nfc_initiator_init(nfc_device *pnd);
NFC_EXPORT bool nfc_initiator_select_passive_target (nfc_device_t * pnd, NFC_EXPORT int nfc_initiator_init_secure_element(nfc_device *pnd);
const nfc_modulation_t nm, const byte_t * pbtInitData, const size_t szInitD NFC_EXPORT int nfc_initiator_select_passive_target(nfc_device *pnd, const n
ata, nfc_target_t * pnt); fc_modulation nm, const uint8_t *pbtInitData, const size_t szInitData, nfc_
NFC_EXPORT bool nfc_initiator_list_passive_targets (nfc_device_t * pnd, c target *pnt);
onst nfc_modulation_t nm, nfc_target_t ant[], const size_t szTargets, size_ NFC_EXPORT int nfc_initiator_list_passive_targets(nfc_device *pnd, const nf
t * pszTargetFound); c_modulation nm, nfc_target ant[], const size_t szTargets);
NFC_EXPORT bool nfc_initiator_poll_target (nfc_device_t * pnd, const nfc_ NFC_EXPORT int nfc_initiator_poll_target(nfc_device *pnd, const nfc_modulat
modulation_t * pnmTargetTypes, const size_t szTargetTypes, const uint8_t ui ion *pnmTargetTypes, const size_t szTargetTypes, const uint8_t uiPollNr, co
PollNr, const uint8_t uiPeriod, nfc_target_t * pnt); nst uint8_t uiPeriod, nfc_target *pnt);
NFC_EXPORT bool nfc_initiator_select_dep_target (nfc_device_t * pnd, cons NFC_EXPORT int nfc_initiator_select_dep_target(nfc_device *pnd, const nfc_d
t nfc_dep_mode_t ndm, const nfc_baud_rate_t nbr, const nfc_dep_info_t * pnd ep_mode ndm, const nfc_baud_rate nbr, const nfc_dep_info *pndiInitiator, nf
iInitiator, nfc_target_t * pnt); c_target *pnt, const int timeout);
NFC_EXPORT bool nfc_initiator_deselect_target (nfc_device_t * pnd); NFC_EXPORT int nfc_initiator_poll_dep_target(nfc_device *pnd, const nfc_dep
NFC_EXPORT bool nfc_initiator_transceive_bytes (nfc_device_t * pnd, const _mode ndm, const nfc_baud_rate nbr, const nfc_dep_info *pndiInitiator, nfc_
byte_t * pbtTx, const size_t szTx, byte_t * pbtRx, size_t * pszRx, struct target *pnt, const int timeout);
timeval *timeout); NFC_EXPORT int nfc_initiator_deselect_target(nfc_device *pnd);
NFC_EXPORT bool nfc_initiator_transceive_bits (nfc_device_t * pnd, const NFC_EXPORT int nfc_initiator_transceive_bytes(nfc_device *pnd, const uint8_
byte_t * pbtTx, const size_t szTxBits, const byte_t * pbtTxPar, byte_t * pb t *pbtTx, const size_t szTx, uint8_t *pbtRx, const size_t szRx, int timeout
tRx, size_t * pszRxBits, byte_t * pbtRxPar); );
NFC_EXPORT bool nfc_initiator_transceive_bytes_timed (nfc_device_t * pnd, NFC_EXPORT int nfc_initiator_transceive_bits(nfc_device *pnd, const uint8_t
const byte_t * pbtTx, const size_t szTx, byte_t * pbtRx, size_t * pszRx, u *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar, uint8_t *pbtRx, co
int32_t * cycles); nst size_t szRx, uint8_t *pbtRxPar);
NFC_EXPORT bool nfc_initiator_transceive_bits_timed (nfc_device_t * pnd, NFC_EXPORT int nfc_initiator_transceive_bytes_timed(nfc_device *pnd, const
const byte_t * pbtTx, const size_t szTxBits, const byte_t * pbtTxPar, byte_ uint8_t *pbtTx, const size_t szTx, uint8_t *pbtRx, const size_t szRx, uint3
t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar, uint32_t * cycles); 2_t *cycles);
NFC_EXPORT int nfc_initiator_transceive_bits_timed(nfc_device *pnd, const u
int8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar, uint8_t *pbt
Rx, const size_t szRx, uint8_t *pbtRxPar, uint32_t *cycles);
NFC_EXPORT int nfc_initiator_target_is_present(nfc_device *pnd, const nfc_t
arget *pnt);
/* NFC target: act as tag (i.e. MIFARE Classic) or NFC target device. */ /* NFC target: act as tag (i.e. MIFARE Classic) or NFC target device. */
NFC_EXPORT bool nfc_target_init (nfc_device_t * pnd, nfc_target_t * pnt, NFC_EXPORT int nfc_target_init(nfc_device *pnd, nfc_target *pnt, uint8_t *p
byte_t * pbtRx, size_t * pszRx); btRx, const size_t szRx, int timeout);
NFC_EXPORT bool nfc_target_send_bytes (nfc_device_t * pnd, const byte_t * NFC_EXPORT int nfc_target_send_bytes(nfc_device *pnd, const uint8_t *pbtTx,
pbtTx, const size_t szTx, struct timeval *timout); const size_t szTx, int timeout);
NFC_EXPORT bool nfc_target_receive_bytes (nfc_device_t * pnd, byte_t * pb NFC_EXPORT int nfc_target_receive_bytes(nfc_device *pnd, uint8_t *pbtRx, co
tRx, size_t * pszRx, struct timeval *timout); nst size_t szRx, int timeout);
NFC_EXPORT bool nfc_target_send_bits (nfc_device_t * pnd, const byte_t * NFC_EXPORT int nfc_target_send_bits(nfc_device *pnd, const uint8_t *pbtTx,
pbtTx, const size_t szTxBits, const byte_t * pbtTxPar); const size_t szTxBits, const uint8_t *pbtTxPar);
NFC_EXPORT bool nfc_target_receive_bits (nfc_device_t * pnd, byte_t * pbt NFC_EXPORT int nfc_target_receive_bits(nfc_device *pnd, uint8_t *pbtRx, con
Rx, size_t * pszRxBits, byte_t * pbtRxPar); st size_t szRx, uint8_t *pbtRxPar);
/* Error reporting */ /* Error reporting */
NFC_EXPORT const char *nfc_strerror (const nfc_device_t * pnd); NFC_EXPORT const char *nfc_strerror(const nfc_device *pnd);
NFC_EXPORT int nfc_strerror_r (const nfc_device_t * pnd, char *pcStrErrBu NFC_EXPORT int nfc_strerror_r(const nfc_device *pnd, char *buf, size_t bufl
f, size_t szBufLen); en);
NFC_EXPORT void nfc_perror (const nfc_device_t * pnd, const char *pcStrin NFC_EXPORT void nfc_perror(const nfc_device *pnd, const char *s);
g); NFC_EXPORT int nfc_device_get_last_error(const nfc_device *pnd);
/* Special data accessors */ /* Special data accessors */
NFC_EXPORT const char *nfc_device_name (nfc_device_t * pnd); NFC_EXPORT const char *nfc_device_get_name(nfc_device *pnd);
NFC_EXPORT const char *nfc_device_get_connstring(nfc_device *pnd);
NFC_EXPORT int nfc_device_get_supported_modulation(nfc_device *pnd, const n
fc_mode mode, const nfc_modulation_type **const supported_mt);
NFC_EXPORT int nfc_device_get_supported_baud_rate(nfc_device *pnd, const nf
c_modulation_type nmt, const nfc_baud_rate **const supported_br);
/* Properties accessors */
NFC_EXPORT int nfc_device_set_property_int(nfc_device *pnd, const nfc_prope
rty property, const int value);
NFC_EXPORT int nfc_device_set_property_bool(nfc_device *pnd, const nfc_prop
erty property, const bool bEnable);
/* Misc. functions */ /* Misc. functions */
NFC_EXPORT void iso14443a_crc (byte_t * pbtData, size_t szLen, byte_t * p NFC_EXPORT void iso14443a_crc(uint8_t *pbtData, size_t szLen, uint8_t *pbtC
btCrc); rc);
NFC_EXPORT void iso14443a_crc_append (byte_t * pbtData, size_t szLen); NFC_EXPORT void iso14443a_crc_append(uint8_t *pbtData, size_t szLen);
NFC_EXPORT byte_t * iso14443a_locate_historical_bytes (byte_t * pbtAts, s NFC_EXPORT void iso14443b_crc(uint8_t *pbtData, size_t szLen, uint8_t *pbtC
ize_t szAts, size_t * pszTk); rc);
NFC_EXPORT const char *nfc_version (void); NFC_EXPORT void iso14443b_crc_append(uint8_t *pbtData, size_t szLen);
NFC_EXPORT uint8_t *iso14443a_locate_historical_bytes(uint8_t *pbtAts, size
/* PN53x specific errors */ _t szAts, size_t *pszTk);
// TODO: Be not PN53x-specific here
#define ETIMEOUT 0x01 NFC_EXPORT void nfc_free(void *p);
#define ECRC 0x02 NFC_EXPORT const char *nfc_version(void);
#define EPARITY 0x03 NFC_EXPORT int nfc_device_get_information_about(nfc_device *pnd, char **buf
#define EBITCOUNT 0x04 );
#define EFRAMING 0x05
#define EBITCOLL 0x06 /* String converter functions */
#define ESMALLBUF 0x07 NFC_EXPORT const char *str_nfc_modulation_type(const nfc_modulation_type nm
#define EBUFOVF 0x09 t);
#define ERFTIMEOUT 0x0a NFC_EXPORT const char *str_nfc_baud_rate(const nfc_baud_rate nbr);
#define ERFPROTO 0x0b NFC_EXPORT int str_nfc_target(char **buf, const nfc_target *pnt, bool verbo
#define EOVHEAT 0x0d se);
#define EINBUFOVF 0x0e
#define EINVPARAM 0x10 /* Error codes */
#define EDEPUNKCMD 0x12 /** @ingroup error
#define EINVRXFRAM 0x13 * @hideinitializer
#define EMFAUTH 0x14 * Success (no error)
#define ENSECNOTSUPP 0x18 // PN533 only */
#define EBCC 0x23 #define NFC_SUCCESS 0
#define EDEPINVSTATE 0x25 /** @ingroup error
#define EOPNOTALL 0x26 * @hideinitializer
#define ECMD 0x27 * Input / output error, device may not be usable anymore without re-open i
#define ETGREL 0x29 t
#define ECID 0x2a */
#define ECDISCARDED 0x2b #define NFC_EIO -1
#define ENFCID3 0x2c /** @ingroup error
#define EOVCURRENT 0x2d * @hideinitializer
#define ENAD 0x2e * Invalid argument(s)
*/
/* PN53x framing-level errors */ #define NFC_EINVARG -2
#define EFRAACKMISMATCH 0x0100 /* Unexpected data */ /** @ingroup error
#define EFRAISERRFRAME 0x0101 /* Error frame */ * @hideinitializer
* Operation not supported by device
/* Communication-level errors */ */
#define ECOMIO 0x1000 /* Input/output error */ #define NFC_EDEVNOTSUPP -3
#define ECOMTIMEOUT 0x1001 /* Operation timeout */ /** @ingroup error
* @hideinitializer
/* Software level errors */ * No such device
#define ETGUIDNOTSUP 0xFF00 /* Target UID not supported */ */
#define EOPABORT 0xFF01 /* Operation aborted */ #define NFC_ENOTSUCHDEV -4
#define EINVALARG 0xFF02 /* Invalid argument */ /** @ingroup error
#define EDEVNOTSUP 0xFF03 /* Not supported by device */ * @hideinitializer
#define ENOTIMPL 0xFF04 /* Not (yet) implemented in libnfc */ * Buffer overflow
*/
#define NFC_EOVFLOW -5
/** @ingroup error
* @hideinitializer
* Operation timed out
*/
#define NFC_ETIMEOUT -6
/** @ingroup error
* @hideinitializer
* Operation aborted (by user)
*/
#define NFC_EOPABORTED -7
/** @ingroup error
* @hideinitializer
* Not (yet) implemented
*/
#define NFC_ENOTIMPL -8
/** @ingroup error
* @hideinitializer
* Target released
*/
#define NFC_ETGRELEASED -10
/** @ingroup error
* @hideinitializer
* Error while RF transmission
*/
#define NFC_ERFTRANS -20
/** @ingroup error
* @hideinitializer
* MIFARE Classic: authentication failed
*/
#define NFC_EMFCAUTHFAIL -30
/** @ingroup error
* @hideinitializer
* Software error (allocation, file/pipe creation, etc.)
*/
#define NFC_ESOFT -80
/** @ingroup error
* @hideinitializer
* Device's internal chip error
*/
#define NFC_ECHIP -90
# ifdef __cplusplus # ifdef __cplusplus
} }
# endif // __cplusplus # endif // __cplusplus
#endif // _LIBNFC_H_ #endif // _LIBNFC_H_
 End of changes. 18 change blocks. 
113 lines changed or deleted 195 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/