libnfc interface More...
#include <stdint.h>
#include <stdbool.h>
#include <nfc/nfc-types.h>
Go to the source code of this file.
Functions | |
NFC_EXPORT nfc_device_t * | nfc_connect (nfc_device_desc_t *pndd) |
Connect to a NFC device. | |
NFC_EXPORT void | nfc_disconnect (nfc_device_t *pnd) |
Disconnect from a NFC device. | |
NFC_EXPORT void | nfc_list_devices (nfc_device_desc_t pnddDevices[], size_t szDevices, size_t *pszDeviceFound) |
Probe for discoverable supported devices (ie. only available for some drivers). | |
NFC_EXPORT bool | nfc_configure (nfc_device_t *pnd, const nfc_device_option_t ndo, const bool bEnable) |
Configure advanced NFC device settings. | |
NFC_EXPORT bool | nfc_initiator_init (nfc_device_t *pnd) |
Initialize NFC device as initiator (reader). | |
NFC_EXPORT bool | nfc_initiator_select_passive_target (nfc_device_t *pnd, const nfc_modulation_t nm, const byte_t *pbtInitData, const size_t szInitData, nfc_target_t *pnt) |
Select a passive or emulated tag. | |
NFC_EXPORT bool | nfc_initiator_list_passive_targets (nfc_device_t *pnd, const nfc_modulation_t nm, nfc_target_t ant[], const size_t szTargets, size_t *pszTargetFound) |
List passive or emulated tags. | |
NFC_EXPORT bool | nfc_initiator_poll_targets (nfc_device_t *pnd, const nfc_modulation_t *pnmTargetTypes, const size_t szTargetTypes, const byte_t btPollNr, const byte_t btPeriod, nfc_target_t *pntTargets, size_t *pszTargetFound) |
Polling for NFC targets. | |
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 *pndiInitiator, nfc_target_t *pnt) |
Select a target and request active or passive mode for D.E.P. (Data Exchange Protocol). | |
NFC_EXPORT bool | nfc_initiator_transceive_bytes (nfc_device_t *pnd, const byte_t *pbtTx, const size_t szTx, byte_t *pbtRx, size_t *pszRx) |
Send data to target then retrieve data from target. | |
NFC_EXPORT bool | nfc_initiator_transceive_bits (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) |
Transceive raw bit-frames to a target. | |
NFC_EXPORT bool | nfc_target_init (nfc_device_t *pnd, nfc_target_t *pnt, byte_t *pbtRx, size_t *pszRx) |
Initialize NFC device as an emulated tag. | |
NFC_EXPORT bool | nfc_target_send_bytes (nfc_device_t *pnd, const byte_t *pbtTx, const size_t szTx) |
Send bytes and APDU frames. | |
NFC_EXPORT bool | nfc_target_receive_bytes (nfc_device_t *pnd, byte_t *pbtRx, size_t *pszRx) |
Receive bytes and APDU frames. | |
NFC_EXPORT bool | nfc_target_send_bits (nfc_device_t *pnd, const byte_t *pbtTx, const size_t szTxBits, const byte_t *pbtTxPar) |
Send raw bit-frames. | |
NFC_EXPORT bool | nfc_target_receive_bits (nfc_device_t *pnd, byte_t *pbtRx, size_t *pszRxBits, byte_t *pbtRxPar) |
Receive bit-frames. | |
NFC_EXPORT const char * | nfc_strerror (const nfc_device_t *pnd) |
Return the PCD error string. | |
NFC_EXPORT int | nfc_strerror_r (const nfc_device_t *pnd, char *pcStrErrBuf, size_t szBufLen) |
Renders the PCD error in pcStrErrBuf for a maximum size of szBufLen chars. | |
NFC_EXPORT void | nfc_perror (const nfc_device_t *pnd, const char *pcString) |
Display the PCD error a-la perror. | |
NFC_EXPORT const char * | nfc_device_name (nfc_device_t *pnd) |
Returns the device name. | |
NFC_EXPORT const char * | nfc_version (void) |
Returns the library version. |
libnfc interface
Provide all usefull functions (API) to handle NFC devices.
Definition in file nfc.h.
NFC_EXPORT bool nfc_configure | ( | nfc_device_t * | pnd, | |
const nfc_device_option_t | ndo, | |||
const bool | bEnable | |||
) |
Configure advanced NFC device settings.
true
if action was successfully performed; otherwise returns false
. pnd | nfc_device_t struct pointer that represent currently used device | |
ndo | nfc_device_option_t struct that contains option to set to device | |
bEnable | boolean to activate/disactivate the option |
Configures parameters and registers that control for example timing, modulation, frame and error handling. There are different categories for configuring the PN53X chip features (handle, activate, infinite and accept).
NFC_EXPORT nfc_device_t* nfc_connect | ( | nfc_device_desc_t * | pndd | ) |
Connect to a NFC device.
pndd | device description if specific device is wanted, NULL otherwise |
NULL
value.If pndd is NULL
, the first available NFC device is claimed. It will automatically search the system using all available drivers to determine a device is NFC-enabled.
If pndd is passed then this function will try to claim the right device using information provided by the nfc_device_desc_t struct.
When it has successfully claimed a NFC device, memory is allocated to save the device information. It will return a pointer to a nfc_device_t struct. This pointer should be supplied by every next functions of libnfc that should perform an action with this device.
NFC_EXPORT const char* nfc_device_name | ( | nfc_device_t * | pnd | ) |
NFC_EXPORT void nfc_disconnect | ( | nfc_device_t * | pnd | ) |
Disconnect from a NFC device.
pnd | nfc_device_t struct pointer that represent currently used device |
Initiator's selected tag is disconnected and the device, including allocated nfc_device_t struct, is released.
NFC_EXPORT bool nfc_initiator_init | ( | nfc_device_t * | pnd | ) |
Initialize NFC device as initiator (reader).
true
if action was successfully performed; otherwise returns false
. pnd | nfc_device_t struct pointer that represent currently used device |
The NFC device is configured to function as RFID reader. After initialization it can be used to communicate to passive RFID tags and active NFC devices. The reader will act as initiator to communicate peer 2 peer (NFCIP) to other active NFC devices.
NFC_EXPORT bool nfc_initiator_list_passive_targets | ( | nfc_device_t * | pnd, | |
const nfc_modulation_t | nm, | |||
nfc_target_t | ant[], | |||
const size_t | szTargets, | |||
size_t * | pszTargetFound | |||
) |
List passive or emulated tags.
true
if action was successfully performed; otherwise returns false
.pnd | nfc_device_t struct pointer that represent currently used device | |
nm | desired modulation | |
[out] | ant | array of nfc_target_t that will be filled with targets info |
szTargets | size of ant (will be the max targets listed) | |
[out] | pszTargetFound | pointer where target found counter will be stored |
The NFC device will try to find the available passive tags. Some NFC devices are capable to emulate passive tags. The standards (ISO18092 and ECMA-340) describe the modulation that can be used for reader to passive communications. The chip needs to know with what kind of tag it is dealing with, therefore the initial modulation and speed (106, 212 or 424 kbps) should be supplied.
NFC_EXPORT bool nfc_initiator_poll_targets | ( | nfc_device_t * | pnd, | |
const nfc_modulation_t * | pnmModulations, | |||
const size_t | szModulations, | |||
const byte_t | btPollNr, | |||
const byte_t | btPeriod, | |||
nfc_target_t * | pntTargets, | |||
size_t * | pszTargetFound | |||
) |
Polling for NFC targets.
true
if action was successfully performed; otherwise returns false
.pnd | nfc_device_t struct pointer that represent currently used device | |
ppttTargetTypes | array of desired target types | |
szTargetTypes | ppttTargetTypes count | |
btPollNr | specifies the number of polling |
btPeriod | indicates the polling period in units of 150 ms | |
[out] | pntTargets | pointer on array of 2 nfc_target_t (over)writables struct |
[out] | pszTargetFound | found targets count |
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 * | pndiInitiator, | |||
nfc_target_t * | pnt | |||
) |
Select a target and request active or passive mode for D.E.P. (Data Exchange Protocol).
true
if action was successfully performed; otherwise returns false
.pnd | nfc_device_t struct pointer that represent currently used device | |
ndm | desired D.E.P. mode (NDM_ACTIVE or NDM_PASSIVE for active, respectively passive mode) | |
ndiInitiator | pointer nfc_dep_info_t struct that contains NFCID3 and General Bytes to set to the initiator device (optionnal, can be NULL) | |
[out] | pnt | is a nfc_target_t struct pointer where target information will be put. |
The NFC device will try to find an available D.E.P. target. The standards (ISO18092 and ECMA-340) describe the modulation that can be used for reader to passive communications.
NFC_EXPORT bool nfc_initiator_select_passive_target | ( | nfc_device_t * | pnd, | |
const nfc_modulation_t | nm, | |||
const byte_t * | pbtInitData, | |||
const size_t | szInitData, | |||
nfc_target_t * | pnt | |||
) |
Select a passive or emulated tag.
true
if action was successfully performed; otherwise returns false
.pnd | nfc_device_t struct pointer that represent currently used device | |
nm | desired modulation | |
pbtInitData | optional initiator data used for Felica, ISO14443B, Topaz polling or to select a specific UID in ISO14443A. | |
szInitData | length of initiator data pbtInitData. |
[out] | pnt | nfc_target_t struct pointer which will filled if available |
The NFC device will try to find one available passive tag or emulated tag.
The chip needs to know with what kind of tag it is dealing with, therefore the initial modulation and speed (106, 212 or 424 kbps) should be supplied.
NFC_EXPORT bool nfc_initiator_transceive_bits | ( | 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 | |||
) |
Transceive raw bit-frames to a target.
true
if action was successfully performed; otherwise returns false
.pbtTx | contains a byte array of the frame that needs to be transmitted. | |
szTxBits | contains the length in bits. |
pbtTxPar | parameter contains a byte array of the corresponding parity bits needed to send per byte. |
[out] | pbtRx | response from the tag |
[out] | pszRxBits | pbtRx length in bits |
[out] | pbtRxPar | parameter contains a byte array of the corresponding parity bits |
The NFC device (configured as initiator) will transmit low-level messages where only the modulation is handled by the PN53x chip. Construction of the frame (data, CRC and parity) is completely done by libnfc. This can be very useful for testing purposes. Some protocols (e.g. MIFARE Classic) require to violate the ISO14443-A standard by sending incorrect parity and CRC bytes. Using this feature you are able to simulate these frames.
NFC_EXPORT bool nfc_initiator_transceive_bytes | ( | nfc_device_t * | pnd, | |
const byte_t * | pbtTx, | |||
const size_t | szTx, | |||
byte_t * | pbtRx, | |||
size_t * | pszRx | |||
) |
Send data to target then retrieve data from target.
true
if action was successfully performed; otherwise returns false
.The NFC device (configured as initiator) will transmit the supplied bytes (pbtTx) to the target. It waits for the response and stores the received bytes in the pbtRx byte array.
If NDO_EASY_FRAMING option is disabled the frames will sent and received in raw mode: PN53x will not handle input neither output data.
The parity bits are handled by the PN53x chip. The CRC can be generated automatically or handled manually. Using this function, frames can be communicated very fast via the NFC initiator to the tag.
Tests show that on average this way of communicating is much faster than using the regular driver/middle-ware (often supplied by manufacturers).
true
(the default value). NFC_EXPORT void nfc_list_devices | ( | nfc_device_desc_t | pnddDevices[], | |
size_t | szDevices, | |||
size_t * | pszDeviceFound | |||
) |
Probe for discoverable supported devices (ie. only available for some drivers).
[out] | pnddDevices | array of nfc_device_desc_t previously allocated by the caller. |
szDevices | size of the pnddDevices array. | |
[out] | pszDeviceFound | number of devices found. |
NFC_EXPORT const char* nfc_strerror | ( | const nfc_device_t * | pnd | ) |
NFC_EXPORT int nfc_strerror_r | ( | const nfc_device_t * | pnd, | |
char * | pcStrErrBuf, | |||
size_t | szBufLen | |||
) |
NFC_EXPORT bool nfc_target_init | ( | nfc_device_t * | pnd, | |
nfc_target_t * | pnt, | |||
byte_t * | pbtRx, | |||
size_t * | pszRx | |||
) |
Initialize NFC device as an emulated tag.
true
if action was successfully performed; otherwise returns false
.pnd | nfc_device_t struct pointer that represent currently used device | |
ntm | target mode restriction that you want to emulate (eg. NTM_PASSIVE_ONLY) | |
pnt | pointer to nfc_target_t struct that represents the wanted emulated target |
[out] | pbtRx | Rx buffer pointer |
[out] | pszRx | received bytes count |
This function initialize NFC device in target mode in order to emulate a tag using the specified nfc_target_mode_t.
NFC_EXPORT bool nfc_target_receive_bits | ( | nfc_device_t * | pnd, | |
byte_t * | pbtRx, | |||
size_t * | pszRxBits, | |||
byte_t * | pbtRxPar | |||
) |
Receive bit-frames.
true
if action was successfully performed; otherwise returns false
.This function makes it possible to receive (raw) bit-frames. It returns all the messages that are stored in the FIFO buffer of the PN53x chip. It does not require to send any frame and thereby could be used to snoop frames that are transmitted by a nearby initiator.
NFC_EXPORT bool nfc_target_receive_bytes | ( | nfc_device_t * | pnd, | |
byte_t * | pbtRx, | |||
size_t * | pszRx | |||
) |
Receive bytes and APDU frames.
true
if action was successfully performed; otherwise returns false
. pnd | nfc_device_t struct pointer that represent currently used device | |
[out] | pbtRx | pointer to Rx buffer |
[out] | pszRx | received byte count |
This function retrieves bytes frames (e.g. ADPU) sent by the initiator to the NFC device (configured as target).
NFC_EXPORT bool nfc_target_send_bits | ( | nfc_device_t * | pnd, | |
const byte_t * | pbtTx, | |||
const size_t | szTxBits, | |||
const byte_t * | pbtTxPar | |||
) |
NFC_EXPORT bool nfc_target_send_bytes | ( | nfc_device_t * | pnd, | |
const byte_t * | pbtTx, | |||
const size_t | szTx | |||
) |
Send bytes and APDU frames.
true
if action was successfully performed; otherwise returns false
.pnd | nfc_device_t struct pointer that represent currently used device | |
pbtTx | pointer to Tx buffer | |
szTx | size of Tx buffer |
This function make the NFC device (configured as target) send byte frames (e.g. APDU responses) to the initiator.