nfc-types.h | nfc-types.h | |||
---|---|---|---|---|
/** | /** | |||
* Public platform independent Near Field Communication (NFC) library | * Public platform independent Near Field Communication (NFC) library | |||
* | * | |||
* Copyright (C) 2009, Roel Verdult | * Copyright (C) 2009, Roel Verdult | |||
* Copyright (C) 2010, Romain Tartière, Romuald Conty | * Copyright (C) 2010, Romain Tartière, Romuald Conty | |||
* Copyright (C) 2011, Romain Tartière, Romuald Conty | ||||
* | * | |||
* 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-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__ | |||
/** | ||||
* @file types.h | ||||
* @brief libnfc-defined types | ||||
* | ||||
* Define libnfc specific types: typedef, enum, struct, etc. | ||||
*/ | ||||
# include <stddef.h> | # include <stddef.h> | |||
# include <stdint.h> | # include <stdint.h> | |||
# include <stdbool.h> | # include <stdbool.h> | |||
# include <stdio.h> | # include <stdio.h> | |||
typedef uint8_t byte_t; | typedef uint8_t byte_t; | |||
typedef enum { | ||||
NC_PN531 = 0x10, | ||||
NC_PN532 = 0x20, | ||||
NC_PN533 = 0x30, | ||||
} nfc_chip_t; | ||||
struct driver_callbacks; // Prototype the callback struct | ||||
typedef void *nfc_device_spec_t; // Device connection specification | ||||
# define DEVICE_NAME_LENGTH 256 | # define DEVICE_NAME_LENGTH 256 | |||
/** | /** | |||
* @struct nfc_device_t | * @struct nfc_device_t | |||
* @brief NFC device information | * @brief NFC device information | |||
*/ | */ | |||
typedef struct { | typedef struct { | |||
/** Callback functions for handling device specific wrapping */ | /** Driver's functions for handling device specific wrapping */ | |||
const struct driver_callbacks *pdc; | const struct nfc_driver_t *driver; | |||
void* driver_data; | ||||
void* chip_data; | ||||
/** Device name string, including device wrapper firmware */ | /** Device name string, including device wrapper firmware */ | |||
char acName[DEVICE_NAME_LENGTH]; | char acName[DEVICE_NAME_LENGTH]; | |||
/** PN53X chip type, this is useful for some "bug" work-arounds */ | ||||
nfc_chip_t nc; | ||||
/** Pointer to the device connection specification */ | ||||
nfc_device_spec_t nds; | ||||
/** This represents if the PN53X device was initialized succesful */ | ||||
bool bActive; | ||||
/** Is the crc automaticly added, checked and removed from the frames */ | /** Is the crc automaticly added, checked and removed from the frames */ | |||
bool bCrc; | bool bCrc; | |||
/** Does the PN53x chip handles parity bits, all parities are handled as da ta */ | /** Does the PN53x chip handles parity bits, all parities are handled as da ta */ | |||
bool bPar; | bool bPar; | |||
/** Should the PN53x chip handle frames encapsulation and chaining */ | /** Should the PN53x chip handle frames encapsulation and chaining */ | |||
bool bEasyFraming; | bool bEasyFraming; | |||
/** Should the PN53x chip switch automatically in ISO14443-4 when ISO14443 */ | /** Should the PN53x chip switch automatically in ISO14443-4 when ISO14443 */ | |||
bool bAutoIso14443_4; | bool bAutoIso14443_4; | |||
/** Register cache for REG_CIU_BIT_FRAMING, SYMBOL_TX_LAST_BITS: The last T | ||||
X bits setting, we need to reset this if it does not apply anymore */ | ||||
uint8_t ui8TxBits; | ||||
/** Register cache for SetParameters function. */ | ||||
uint8_t ui8Parameters; | ||||
/** Supported modulation encoded in a byte */ | /** Supported modulation encoded in a byte */ | |||
byte_t btSupportByte; | byte_t btSupportByte; | |||
/** Last error reported by the PCD / encountered by the PCD driver | /** Last error reported by the PCD / encountered by the PCD driver | |||
* MSB LSB | * MSB LSB | |||
* | 00 | 00 | | * | 00 | 00 | | |||
* || || | * || || | |||
* || ++----- Chip-level error (as reported by the PCD) | * || ++----- Chip-level error (as reported by the PCD) | |||
* |+---------- Driver-level specific error | * |+---------- Driver-level specific error | |||
* +----------- Driver-level general error (common to all drivers) | * +----------- Driver-level general error (common to all drivers) | |||
*/ | */ | |||
int iLastError; | int iLastError; | |||
int iAbortFds[2]; | ||||
} nfc_device_t; | } nfc_device_t; | |||
/** | /** | |||
* @struct nfc_device_desc_t | * @struct nfc_device_desc_t | |||
* @brief NFC device description | * @brief NFC device description | |||
* | * | |||
* This struct is used to try to connect to a specified nfc device when nfc _connect(...) | * This struct is used to try to connect to a specified nfc device when nfc _connect(...) | |||
*/ | */ | |||
typedef struct { | typedef struct { | |||
/** Device name (e.g. "ACS ACR 38U-CCID 00 00") */ | /** Device name (e.g. "ACS ACR 38U-CCID 00 00") */ | |||
skipping to change at line 120 | skipping to change at line 100 | |||
/** | /** | |||
* @struct chip_callbacks | * @struct chip_callbacks | |||
* @brief Functions for chip specific functions. | * @brief Functions for chip specific functions. | |||
*/ | */ | |||
struct chip_callbacks { | struct chip_callbacks { | |||
/** Error lookup */ | /** Error lookup */ | |||
const char *(*strerror) (const nfc_device_t * pnd); | const char *(*strerror) (const nfc_device_t * pnd); | |||
}; | }; | |||
/** | ||||
* @struct driver_callbacks | ||||
* @brief Generic structure to handle NFC device functions. | ||||
*/ | ||||
struct driver_callbacks { | ||||
/** Driver name */ | ||||
const char *acDriver; | ||||
/** Chip specific callback functions */ | ||||
const struct chip_callbacks *pcc; | ||||
/** Pick devices callback */ | ||||
nfc_device_desc_t *(*pick_device) (void); | ||||
/** List devices callback */ | ||||
bool (*list_devices) (nfc_device_desc_t pnddDevices[], size_t szDevices, | ||||
size_t * pszDeviceFound); | ||||
/** Connect callback */ | ||||
nfc_device_t *(*connect) (const nfc_device_desc_t * pndd); | ||||
/** Init callback */ | ||||
void (*init) (nfc_device_t * pnd); | ||||
/** Transceive callback */ | ||||
bool (*transceive) (nfc_device_t * pnd, const byte_t * pbtTx, const size_ | ||||
t szTx, byte_t * pbtRx, size_t * pszRx); | ||||
/** Disconnect callback */ | ||||
void (*disconnect) (nfc_device_t * pnd); | ||||
}; | ||||
// Compiler directive, set struct alignment to 1 byte_t for compatibility | // Compiler directive, set struct alignment to 1 byte_t for compatibility | |||
# pragma pack(1) | # pragma pack(1) | |||
/** | /** | |||
* @enum nfc_device_option_t | * @enum nfc_device_option_t | |||
* @brief NFC device option | * @brief NFC device option | |||
*/ | */ | |||
typedef enum { | typedef enum { | |||
/** Let the PN53X chip handle the CRC bytes. This means that the chip appen ds | /** Let the PN53X chip handle the CRC bytes. This means that the chip appen ds | |||
* the CRC bytes to the frames that are transmitted. It will parse the last | * the CRC bytes to the frames that are transmitted. It will parse the last | |||
End of changes. 9 change blocks. | ||||
56 lines changed or deleted | 10 lines changed or added | |||
nfc.h | nfc.h | |||
---|---|---|---|---|
skipping to change at line 66 | skipping to change at line 66 | |||
# include <nfc/nfc-types.h> | # include <nfc/nfc-types.h> | |||
# ifdef __cplusplus | # ifdef __cplusplus | |||
extern "C" { | extern "C" { | |||
# endif // __cplusplus | # endif // __cplusplus | |||
/* NFC Device/Hardware manipulation */ | /* NFC Device/Hardware manipulation */ | |||
NFC_EXPORT nfc_device_t *nfc_connect (nfc_device_desc_t * pndd); | NFC_EXPORT nfc_device_t *nfc_connect (nfc_device_desc_t * pndd); | |||
NFC_EXPORT void nfc_disconnect (nfc_device_t * pnd); | NFC_EXPORT void nfc_disconnect (nfc_device_t * pnd); | |||
NFC_EXPORT void nfc_abort_command (nfc_device_t * pnd); | ||||
NFC_EXPORT void nfc_list_devices (nfc_device_desc_t pnddDevices[], size_t szDevices, size_t * pszDeviceFound); | NFC_EXPORT void nfc_list_devices (nfc_device_desc_t pnddDevices[], size_t szDevices, size_t * pszDeviceFound); | |||
NFC_EXPORT bool nfc_configure (nfc_device_t * pnd, const nfc_device_optio n_t ndo, const bool bEnable); | NFC_EXPORT bool nfc_configure (nfc_device_t * pnd, const nfc_device_optio n_t ndo, const bool bEnable); | |||
/* NFC initiator: act as "reader" */ | /* NFC initiator: act as "reader" */ | |||
NFC_EXPORT bool nfc_initiator_init (nfc_device_t * pnd); | NFC_EXPORT bool nfc_initiator_init (nfc_device_t * pnd); | |||
NFC_EXPORT bool nfc_initiator_select_passive_target (nfc_device_t * pnd, | NFC_EXPORT bool nfc_initiator_select_passive_target (nfc_device_t * pnd, | |||
const nfc_modulation_t nm, | const nfc_modulation_t nm, const byte_t * pbtInitData, const size_t szInitD | |||
const byte_t * pbtIn | ata, nfc_target_t * pnt); | |||
itData, const size_t szInitData, | NFC_EXPORT bool nfc_initiator_list_passive_targets (nfc_device_t * pnd, c | |||
nfc_target_t * pnt); | onst nfc_modulation_t nm, nfc_target_t ant[], const size_t szTargets, size_ | |||
NFC_EXPORT bool nfc_initiator_list_passive_targets (nfc_device_t * pnd, c | t * pszTargetFound); | |||
onst nfc_modulation_t nm, | NFC_EXPORT bool nfc_initiator_poll_targets (nfc_device_t * pnd, const nfc | |||
nfc_target_t ant[], c | _modulation_t * pnmTargetTypes, const size_t szTargetTypes, const byte_t bt | |||
onst size_t szTargets, | PollNr, const byte_t btPeriod, nfc_target_t * pntTargets, size_t * pszTarge | |||
size_t * pszTargetFou | tFound); | |||
nd); | NFC_EXPORT bool nfc_initiator_select_dep_target (nfc_device_t * pnd, cons | |||
NFC_EXPORT bool nfc_initiator_poll_targets (nfc_device_t * pnd, const nfc | t nfc_dep_mode_t ndm, const nfc_baud_rate_t nbr, const nfc_dep_info_t * pnd | |||
_modulation_t * pnmTargetTypes, | iInitiator, nfc_target_t * pnt); | |||
const size_t szTargetTypes, c | ||||
onst byte_t btPollNr, const byte_t btPeriod, | ||||
nfc_target_t * pntTargets, si | ||||
ze_t * pszTargetFound); | ||||
NFC_EXPORT bool nfc_initiator_select_dep_target (nfc_device_t * pnd, | ||||
const nfc_dep_mode_t ndm | ||||
, const nfc_baud_rate_t nbr, | ||||
const nfc_dep_info_t * p | ||||
ndiInitiator, | ||||
nfc_target_t * pnt); | ||||
NFC_EXPORT bool nfc_initiator_deselect_target (nfc_device_t * pnd); | NFC_EXPORT bool nfc_initiator_deselect_target (nfc_device_t * pnd); | |||
NFC_EXPORT bool nfc_initiator_transceive_bytes (nfc_device_t * pnd, const | NFC_EXPORT bool nfc_initiator_transceive_bytes (nfc_device_t * pnd, const | |||
byte_t * pbtTx, const size_t szTx, | byte_t * pbtTx, const size_t szTx, byte_t * pbtRx, size_t * pszRx); | |||
byte_t * pbtRx, size_t * | NFC_EXPORT bool nfc_initiator_transceive_bits (nfc_device_t * pnd, const | |||
pszRx); | byte_t * pbtTx, const size_t szTxBits, const byte_t * pbtTxPar, byte_t * pb | |||
NFC_EXPORT bool nfc_initiator_transceive_bits (nfc_device_t * pnd, const | tRx, size_t * pszRxBits, byte_t * pbtRxPar); | |||
byte_t * pbtTx, const size_t szTxBits, | NFC_EXPORT bool nfc_initiator_transceive_bytes_timed (nfc_device_t * pnd, | |||
const byte_t * pbtTxPar, b | const byte_t * pbtTx, const size_t szTx, byte_t * pbtRx, size_t * pszRx, u | |||
yte_t * pbtRx, size_t * pszRxBits, | int16_t * cycles); | |||
byte_t * pbtRxPar); | NFC_EXPORT bool nfc_initiator_transceive_bits_timed (nfc_device_t * pnd, | |||
const byte_t * pbtTx, const size_t szTxBits, const byte_t * pbtTxPar, byte_ | ||||
t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar, uint16_t * cycles); | ||||
/* 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, byte_t * pbtRx, size_t * pszRx); | NFC_EXPORT bool nfc_target_init (nfc_device_t * pnd, nfc_target_t * pnt, byte_t * pbtRx, size_t * pszRx); | |||
NFC_EXPORT bool nfc_target_send_bytes (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx); | NFC_EXPORT bool nfc_target_send_bytes (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx); | |||
NFC_EXPORT bool nfc_target_receive_bytes (nfc_device_t * pnd, byte_t * pb tRx, size_t * pszRx); | NFC_EXPORT bool nfc_target_receive_bytes (nfc_device_t * pnd, byte_t * pb tRx, size_t * pszRx); | |||
NFC_EXPORT bool nfc_target_send_bits (nfc_device_t * pnd, const byte_t * | NFC_EXPORT bool nfc_target_send_bits (nfc_device_t * pnd, const byte_t * | |||
pbtTx, const size_t szTxBits, | pbtTx, const size_t szTxBits, const byte_t * pbtTxPar); | |||
const byte_t * pbtTxPar); | ||||
NFC_EXPORT bool nfc_target_receive_bits (nfc_device_t * pnd, byte_t * pbt Rx, size_t * pszRxBits, byte_t * pbtRxPar); | NFC_EXPORT bool nfc_target_receive_bits (nfc_device_t * pnd, byte_t * pbt Rx, size_t * pszRxBits, byte_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_t * pnd); | |||
NFC_EXPORT int nfc_strerror_r (const nfc_device_t * pnd, char *pcStrErrBu f, size_t szBufLen); | NFC_EXPORT int nfc_strerror_r (const nfc_device_t * pnd, char *pcStrErrBu f, size_t szBufLen); | |||
NFC_EXPORT void nfc_perror (const nfc_device_t * pnd, const char *pcStrin g); | NFC_EXPORT void nfc_perror (const nfc_device_t * pnd, const char *pcStrin g); | |||
/* Special data accessors */ | /* Special data accessors */ | |||
NFC_EXPORT const char *nfc_device_name (nfc_device_t * pnd); | NFC_EXPORT const char *nfc_device_name (nfc_device_t * pnd); | |||
skipping to change at line 150 | skipping to change at line 140 | |||
#define EOVCURRENT 0x2d | #define EOVCURRENT 0x2d | |||
#define ENAD 0x2e | #define ENAD 0x2e | |||
/* Software level errors */ | /* Software level errors */ | |||
#define ETGUIDNOTSUP 0x0100 /* Target UID not supported */ | #define ETGUIDNOTSUP 0x0100 /* Target UID not supported */ | |||
/* Common device-level errors */ | /* Common device-level errors */ | |||
#define DEIO 0x1000 /* Input/output error */ | #define DEIO 0x1000 /* Input/output error */ | |||
#define DEINVAL 0x2000 /* Invalid argument */ | #define DEINVAL 0x2000 /* Invalid argument */ | |||
#define DETIMEOUT 0x3000 /* Operation timeout */ | #define DETIMEOUT 0x3000 /* Operation timeout */ | |||
#define DEABORT 0x4000 /* Operation aborted */ | ||||
# ifdef __cplusplus | # ifdef __cplusplus | |||
} | } | |||
# endif // __cplusplus | # endif // __cplusplus | |||
#endif // _LIBNFC_H_ | #endif // _LIBNFC_H_ | |||
End of changes. 5 change blocks. | ||||
35 lines changed or deleted | 28 lines changed or added | |||