Flipper Zero Firmware
Loading...
Searching...
No Matches
nfc.h
Go to the documentation of this file.
1
18#pragma once
19
20#include <toolbox/bit_buffer.h>
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
29typedef struct Nfc Nfc;
30
48
52typedef struct {
55
65
77
87typedef NfcCommand (*NfcEventCallback)(NfcEvent event, void* context);
88
100
112
123
131Nfc* nfc_alloc(void);
132
140void nfc_free(Nfc* instance);
141
151void nfc_config(Nfc* instance, NfcMode mode, NfcTech tech);
152
159void nfc_set_fdt_poll_fc(Nfc* instance, uint32_t fdt_poll_fc);
160
167void nfc_set_fdt_listen_fc(Nfc* instance, uint32_t fdt_listen_fc);
168
175void nfc_set_mask_receive_time_fc(Nfc* instance, uint32_t mask_rx_time_fc);
176
185void nfc_set_fdt_poll_poll_us(Nfc* instance, uint32_t fdt_poll_poll_us);
186
193void nfc_set_guard_time_us(Nfc* instance, uint32_t guard_time_us);
194
208void nfc_start(Nfc* instance, NfcEventCallback callback, void* context);
209
217void nfc_stop(Nfc* instance);
218
238 nfc_poller_trx(Nfc* instance, const BitBuffer* tx_buffer, BitBuffer* rx_buffer, uint32_t fwt);
239
255NfcError nfc_listener_tx(Nfc* instance, const BitBuffer* tx_buffer);
256
257/*
258 * Technology-specific functions.
259 *
260 * In a perfect world, this would not be necessary.
261 * However, the current implementation employs NFC hardware that partially implements
262 * certain protocols (e.g. ISO14443-3A), thus requiring methods to access such features.
263 */
264
265/******************* ISO14443-3A specific API *******************/
266
270typedef enum {
271 NfcIso14443aShortFrameSensReq,
272 NfcIso14443aShortFrameAllReqa,
274
285 Nfc* instance,
287 BitBuffer* rx_buffer,
288 uint32_t fwt);
289
300 Nfc* instance,
301 const BitBuffer* tx_buffer,
302 BitBuffer* rx_buffer,
303 uint32_t fwt);
304
318 Nfc* instance,
319 const BitBuffer* tx_buffer,
320 BitBuffer* rx_buffer,
321 uint32_t fwt);
322
334
348 Nfc* instance,
349 uint8_t* uid,
350 uint8_t uid_len,
351 uint8_t* atqa,
352 uint8_t sak);
353
368 Nfc* instance,
369 const uint8_t* idm,
370 const uint8_t idm_len,
371 const uint8_t* pmm,
372 const uint8_t pmm_len,
373 const uint16_t sys_code);
374
382
383#ifdef __cplusplus
384}
385#endif
void nfc_stop(Nfc *instance)
Stop Nfc instance.
Definition nfc.c:326
void nfc_config(Nfc *instance, NfcMode mode, NfcTech tech)
Configure the Nfc instance to work in a particular mode.
Definition nfc.c:265
void nfc_set_fdt_poll_fc(Nfc *instance, uint32_t fdt_poll_fc)
Set poller frame delay time.
Definition nfc.c:284
void nfc_set_mask_receive_time_fc(Nfc *instance, uint32_t mask_rx_time_fc)
Set mask receive time.
Definition nfc.c:304
void nfc_free(Nfc *instance)
Delete an Nfc instance.
Definition nfc.c:255
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.
Definition nfc.c:407
void nfc_set_fdt_poll_poll_us(Nfc *instance, uint32_t fdt_poll_poll_us)
Set frame delay time.
Definition nfc.c:294
NfcEventType
Enumeration of possible Nfc event types.
Definition nfc.h:36
@ NfcEventTypeListenerActivated
The listener has been activated by the reader.
Definition nfc.h:45
@ NfcEventTypeFieldOn
Reader's field was detected by the NFC hardware.
Definition nfc.h:38
@ NfcEventTypeRxStart
Data reception has started.
Definition nfc.h:42
@ NfcEventTypeRxEnd
Data reception has ended.
Definition nfc.h:43
@ NfcEventTypeTxEnd
Data transmission has ended.
Definition nfc.h:41
@ NfcEventTypeUserAbort
User code explicitly aborted the current operation.
Definition nfc.h:37
@ NfcEventTypeFieldOff
Reader's field was lost.
Definition nfc.h:39
@ NfcEventTypeTxStart
Data transmission has started.
Definition nfc.h:40
@ NfcEventTypePollerReady
The card has been activated by the poller.
Definition nfc.h:46
void nfc_start(Nfc *instance, NfcEventCallback callback, void *context)
Start the Nfc instance.
Definition nfc.c:309
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.
Definition nfc.c:572
void nfc_set_fdt_listen_fc(Nfc *instance, uint32_t fdt_listen_fc)
Set listener frame delay time.
Definition nfc.c:289
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.
Definition nfc.c:522
Nfc * nfc_alloc(void)
Allocate an Nfc instance.
Definition nfc.c:238
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.
Definition nfc.c:464
NfcIso14443aShortFrame
Enumeration of possible ISO14443-3A short frame types.
Definition nfc.h:270
void nfc_set_guard_time_us(Nfc *instance, uint32_t guard_time_us)
Set guard time.
Definition nfc.c:299
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.
Definition nfc.c:620
NfcError nfc_listener_tx(Nfc *instance, const BitBuffer *tx_buffer)
Transmit a data frame in listener mode.
Definition nfc.c:338
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.
Definition nfc.c:649
NfcError nfc_iso15693_listener_tx_sof(Nfc *instance)
Send ISO15693 Start of Frame pattern in listener mode.
Definition nfc.c:637
NfcTech
Enumeration of available technologies.
Definition nfc.h:104
@ NfcTechIso14443b
Configure the Nfc instance to use the ISO14443-3B technology.
Definition nfc.h:106
@ NfcTechIso15693
Configure the Nfc instance to use the ISO15693 technology.
Definition nfc.h:107
@ NfcTechFelica
Configure the Nfc instance to use the FeliCa technology.
Definition nfc.h:108
@ NfcTechIso14443a
Configure the Nfc instance to use the ISO14443-3A technology.
Definition nfc.h:105
@ NfcTechNum
Technologies count.
Definition nfc.h:110
NfcCommand(* NfcEventCallback)(NfcEvent event, void *context)
Nfc event callback type.
Definition nfc.h:87
NfcMode
Enumeration of possible operating modes.
Definition nfc.h:94
@ NfcModeNum
Operating mode count.
Definition nfc.h:98
@ NfcModeListener
Configure the Nfc instance as a listener.
Definition nfc.h:96
@ NfcModePoller
Configure the Nfc instance as a poller.
Definition nfc.h:95
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.
Definition nfc.c:508
NfcError
Enumeration of possible Nfc error codes.
Definition nfc.h:116
@ NfcErrorTimeout
Operation is taking too long (e.g.
Definition nfc.h:119
@ NfcErrorNone
No error has occurred.
Definition nfc.h:117
@ NfcErrorDataFormat
Data has not been parsed due to wrong/unknown format.
Definition nfc.h:121
@ NfcErrorIncompleteFrame
An incomplete data frame has been received.
Definition nfc.h:120
@ NfcErrorInternal
An unknown error has occured on the lower level.
Definition nfc.h:118
NfcCommand
Enumeration of possible Nfc commands.
Definition nfc.h:71
@ NfcCommandContinue
Continue operation normally.
Definition nfc.h:72
@ NfcCommandSleep
Switch Nfc hardware to low-power mode.
Definition nfc.h:75
@ NfcCommandStop
Stop the current operation.
Definition nfc.h:74
@ NfcCommandReset
Reset the current state.
Definition nfc.h:73
Definition bit_buffer.c:7
Nfc event data structure.
Definition nfc.h:52
BitBuffer * buffer
Pointer to the received data buffer.
Definition nfc.h:53
Nfc event structure.
Definition nfc.h:61
NfcEventData data
Event-specific data.
Definition nfc.h:63
NfcEventType type
Type of the emitted event.
Definition nfc.h:62
Definition nfc.c:41