Transport layer Nfc library. More...
#include <toolbox/bit_buffer.h>
Go to the source code of this file.
Data Structures | |
struct | NfcEventData |
Nfc event data structure. More... | |
struct | NfcEvent |
Nfc event structure. More... | |
Typedefs | |
typedef struct Nfc | Nfc |
Nfc opaque type definition. | |
typedef NfcCommand(* | NfcEventCallback) (NfcEvent event, void *context) |
Nfc event callback type. | |
Functions | |
Nfc * | nfc_alloc (void) |
Allocate an Nfc instance. | |
void | nfc_free (Nfc *instance) |
Delete an Nfc instance. | |
void | nfc_config (Nfc *instance, NfcMode mode, NfcTech tech) |
Configure the Nfc instance to work in a particular mode. | |
void | nfc_set_fdt_poll_fc (Nfc *instance, uint32_t fdt_poll_fc) |
Set poller frame delay time. | |
void | nfc_set_fdt_listen_fc (Nfc *instance, uint32_t fdt_listen_fc) |
Set listener frame delay time. | |
void | nfc_set_mask_receive_time_fc (Nfc *instance, uint32_t mask_rx_time_fc) |
Set mask receive time. | |
void | nfc_set_fdt_poll_poll_us (Nfc *instance, uint32_t fdt_poll_poll_us) |
Set frame delay time. | |
void | nfc_set_guard_time_us (Nfc *instance, uint32_t guard_time_us) |
Set guard time. | |
void | nfc_start (Nfc *instance, NfcEventCallback callback, void *context) |
Start the Nfc instance. | |
void | nfc_stop (Nfc *instance) |
Stop Nfc instance. | |
NfcError | nfc_poller_trx (Nfc *instance, const BitBuffer *tx_buffer, BitBuffer *rx_buffer, uint32_t fwt) |
Transmit and receive a data frame in poller mode. | |
NfcError | nfc_listener_tx (Nfc *instance, const BitBuffer *tx_buffer) |
Transmit a data frame in listener mode. | |
NfcError | nfc_iso14443a_poller_trx_short_frame (Nfc *instance, NfcIso14443aShortFrame frame, BitBuffer *rx_buffer, uint32_t fwt) |
Transmit an ISO14443-3A short frame and receive the response in poller mode. | |
NfcError | nfc_iso14443a_poller_trx_sdd_frame (Nfc *instance, const BitBuffer *tx_buffer, BitBuffer *rx_buffer, uint32_t fwt) |
Transmit an ISO14443-3A SDD frame and receive the response in poller mode. | |
NfcError | nfc_iso14443a_poller_trx_custom_parity (Nfc *instance, const BitBuffer *tx_buffer, BitBuffer *rx_buffer, uint32_t fwt) |
Transmit an ISO14443-3A data frame with custom parity bits and receive the response in poller mode. | |
NfcError | nfc_iso14443a_listener_tx_custom_parity (Nfc *instance, const BitBuffer *tx_buffer) |
Transmit an ISO14443-3A frame with custom parity bits in listener mode. | |
NfcError | nfc_iso14443a_listener_set_col_res_data (Nfc *instance, uint8_t *uid, uint8_t uid_len, uint8_t *atqa, uint8_t sak) |
Set ISO14443-3A collision resolution parameters in listener mode. | |
NfcError | nfc_felica_listener_set_sensf_res_data (Nfc *instance, const uint8_t *idm, const uint8_t idm_len, const uint8_t *pmm, const uint8_t pmm_len, const uint16_t sys_code) |
Set FeliCa collision resolution parameters in listener mode. | |
NfcError | nfc_iso15693_listener_tx_sof (Nfc *instance) |
Send ISO15693 Start of Frame pattern in listener mode. | |
Transport layer Nfc library.
The Nfc layer is responsible for setting the operating mode (poller or listener) and technology (ISO14443-3A/B, ISO15693, ...), data exchange between higher protocol-specific levels and underlying NFC hardware, as well as timings handling.
In applications using the NFC protocol system there is no need to neiter explicitly create an Nfc instance nor call any of its functions, as it is all handled automatically under the hood.
If the NFC protocol system is not suitable for the application's intended purpose or there is need of having direct access to the NFC transport layer, then an Nfc instance must be allocated and the below functions shall be used to implement the required logic.
typedef NfcCommand(* NfcEventCallback) (NfcEvent event, void *context) |
Nfc event callback type.
A function of this type must be passed as the callback parameter upon start of a an Nfc instance.
[in] | event | Nfc event, passed by value, complete with protocol type and data. |
[in,out] | context | pointer to the user-specific context (set when starting an Nfc instance). |
enum NfcCommand |
Enumeration of possible Nfc commands.
The event callback must return one of these to determine the next action.
Enumerator | |
---|---|
NfcCommandContinue | Continue operation normally. |
NfcCommandReset | Reset the current state. |
NfcCommandStop | Stop the current operation. |
NfcCommandSleep | Switch Nfc hardware to low-power mode. |
enum NfcError |
Enumeration of possible Nfc error codes.
enum NfcEventType |
Enumeration of possible Nfc event types.
Not all technologies implement all events (this is due to hardware limitations).
enum NfcMode |
enum NfcTech |
Enumeration of available technologies.
Nfc * nfc_alloc | ( | void | ) |
Allocate an Nfc instance.
Will exclusively take over the NFC HAL until deleted.
Configure the Nfc instance to work in a particular mode.
Not all technologies implement the listener operating mode.
[in,out] | instance | pointer to the instance to be configured. |
[in] | mode | required operating mode. |
[in] | tech | required technology configuration. |
NfcError nfc_felica_listener_set_sensf_res_data | ( | Nfc * | instance, |
const uint8_t * | idm, | ||
const uint8_t | idm_len, | ||
const uint8_t * | pmm, | ||
const uint8_t | pmm_len, | ||
const uint16_t | sys_code ) |
Set FeliCa collision resolution parameters in listener mode.
Configures the NFC hardware for automatic collision resolution.
[in,out] | instance | pointer to the instance to be configured. |
[in] | idm | pointer to a byte array containing the IDm. |
[in] | idm_len | IDm length in bytes. |
[in] | pmm | pointer to a byte array containing the PMm. |
[in] | pmm_len | PMm length in bytes. |
[in] | sys_code | System code from SYS_C block |
void nfc_free | ( | Nfc * | instance | ) |
Delete an Nfc instance.
Will release the NFC HAL lock, making it available for use by others.
[in,out] | instance | pointer to the instance to be deleted. |
NfcError nfc_iso14443a_listener_set_col_res_data | ( | Nfc * | instance, |
uint8_t * | uid, | ||
uint8_t | uid_len, | ||
uint8_t * | atqa, | ||
uint8_t | sak ) |
Set ISO14443-3A collision resolution parameters in listener mode.
Configures the NFC hardware for automatic collision resolution.
[in,out] | instance | pointer to the instance to be configured. |
[in] | uid | pointer to a byte array containing the UID. |
[in] | uid_len | UID length in bytes (must be supported by the protocol). |
[in] | atqa | ATQA byte value. |
[in] | sak | SAK byte value. |
Transmit an ISO14443-3A frame with custom parity bits in listener mode.
Same as nfc_listener_tx(), but uses the parity bits provided by the user code instead of calculating them automatically.
[in,out] | instance | pointer to the instance to be used in the transaction. |
[in] | tx_buffer | pointer to the buffer containing the data to be transmitted. |
NfcError nfc_iso14443a_poller_trx_custom_parity | ( | Nfc * | instance, |
const BitBuffer * | tx_buffer, | ||
BitBuffer * | rx_buffer, | ||
uint32_t | fwt ) |
Transmit an ISO14443-3A data frame with custom parity bits and receive the response in poller mode.
Same as nfc_poller_trx(), but uses the parity bits provided by the user code instead of calculating them automatically.
[in,out] | instance | pointer to the instance to be used in the transaction. |
[in] | tx_buffer | pointer to the buffer containing the data to be transmitted. |
[out] | rx_buffer | pointer to the buffer to be filled with received data. |
[in] | fwt | frame wait time (response timeout), in carrier cycles. |
NfcError nfc_iso14443a_poller_trx_sdd_frame | ( | Nfc * | instance, |
const BitBuffer * | tx_buffer, | ||
BitBuffer * | rx_buffer, | ||
uint32_t | fwt ) |
Transmit an ISO14443-3A SDD frame and receive the response in poller mode.
[in,out] | instance | pointer to the instance to be used in the transaction. |
[in] | tx_buffer | pointer to the buffer containing the data to be transmitted. |
[out] | rx_buffer | pointer to the buffer to be filled with received data. |
[in] | fwt | frame wait time (response timeout), in carrier cycles. |
NfcError nfc_iso14443a_poller_trx_short_frame | ( | Nfc * | instance, |
NfcIso14443aShortFrame | frame, | ||
BitBuffer * | rx_buffer, | ||
uint32_t | fwt ) |
Transmit an ISO14443-3A short frame and receive the response in poller mode.
[in,out] | instance | pointer to the instance to be used in the transaction. |
[in] | frame | type of short frame to be sent. |
[out] | rx_buffer | pointer to the buffer to be filled with received data. |
[in] | fwt | frame wait time (response timeout), in carrier cycles. |
Send ISO15693 Start of Frame pattern in listener mode.
[in,out] | instance | pointer to the instance to be configured. |
Transmit a data frame in listener mode.
Used to transmit a response to the reader request in listener mode.
The data being transmitted may be either bit- or byte-oriented. It shall not contain any technology-specific sequences as start or stop bits and/or other special symbols, as this is handled on the underlying HAL level.
Must ONLY be used inside the callback function.
[in,out] | instance | pointer to the instance to be used in the transaction. |
[in] | tx_buffer | pointer to the buffer containing the data to be transmitted. |
NfcError nfc_poller_trx | ( | Nfc * | instance, |
const BitBuffer * | tx_buffer, | ||
BitBuffer * | rx_buffer, | ||
uint32_t | fwt ) |
Transmit and receive a data frame in poller mode.
The rx_buffer will be filled with any data received as a response to data sent from tx_buffer, with a timeout defined by the fwt parameter.
The data being transmitted and received may be either bit- or byte-oriented. It shall not contain any technology-specific sequences as start or stop bits and/or other special symbols, as this is handled on the underlying HAL level.
Must ONLY be used inside the callback function.
[in,out] | instance | pointer to the instance to be used in the transaction. |
[in] | tx_buffer | pointer to the buffer containing the data to be transmitted. |
[out] | rx_buffer | pointer to the buffer to be filled with received data. |
[in] | fwt | frame wait time (response timeout), in carrier cycles. |
void nfc_set_fdt_listen_fc | ( | Nfc * | instance, |
uint32_t | fdt_listen_fc ) |
Set listener frame delay time.
[in,out] | instance | pointer to the instance to be modified. |
[in] | fdt_listen_fc | frame delay time, in carrier cycles. |
void nfc_set_fdt_poll_fc | ( | Nfc * | instance, |
uint32_t | fdt_poll_fc ) |
Set poller frame delay time.
[in,out] | instance | pointer to the instance to be modified. |
[in] | fdt_poll_fc | frame delay time, in carrier cycles. |
void nfc_set_fdt_poll_poll_us | ( | Nfc * | instance, |
uint32_t | fdt_poll_poll_us ) |
Set frame delay time.
Frame delay time is the minimum time between two consecutive poll frames.
[in,out] | instance | pointer to the instance to be modified. |
[in] | fdt_poll_poll_us | frame delay time, in microseconds. |
void nfc_set_guard_time_us | ( | Nfc * | instance, |
uint32_t | guard_time_us ) |
Set guard time.
[in,out] | instance | pointer to the instance to be modified. |
[in] | guard_time_us | guard time, in microseconds. |
void nfc_set_mask_receive_time_fc | ( | Nfc * | instance, |
uint32_t | mask_rx_time_fc ) |
Set mask receive time.
[in,out] | instance | pointer to the instance to be modified. |
[in] | mask_rx_time_fc | mask receive time, in carrier cycles. |
void nfc_start | ( | Nfc * | instance, |
NfcEventCallback | callback, | ||
void * | context ) |
Start the Nfc instance.
The instance must be configured to work with a specific technology in a specific operating mode with a nfc_config() call before starting.
Once started, the user code will be receiving events through the provided callback which must handle them according to the logic required.
[in,out] | instance | pointer to the instance to be started. |
[in] | callback | pointer to a user-defined callback function which will receive events. |
[in] | context | pointer to a user-specific context (will be passed to the callback). |
void nfc_stop | ( | Nfc * | instance | ) |
Stop Nfc instance.
The instance can only be stopped if it is running.
[in,out] | instance | pointer to the instance to be stopped. |