Flipper Zero Firmware
Loading...
Searching...
No Matches
nfc_poller_base.h File Reference

Abstract interface definitions for the NFC poller system. More...

#include "nfc_generic_event.h"
#include "nfc_device_base.h"

Go to the source code of this file.

Data Structures

struct  NfcPollerBase
 Generic NFC poller interface. More...
 

Typedefs

typedef NfcGenericInstance *(* NfcPollerAlloc) (NfcGenericInstance *base_poller)
 Allocate a protocol-specific poller instance.
 
typedef void(* NfcPollerFree) (NfcGenericInstance *instance)
 Delete a protocol-specific poller instance.
 
typedef void(* NfcPollerSetCallback) (NfcGenericInstance *poller, NfcGenericCallback callback, void *context)
 Set the callback function to handle events emitted by the poller instance.
 
typedef NfcCommand(* NfcPollerRun) (NfcGenericEvent event, void *context)
 Activate and read a supported NFC card.
 
typedef bool(* NfcPollerDetect) (NfcGenericEvent event, void *context)
 Determine whether there is a supported card in the vicinity.
 
typedef const NfcDeviceData *(* NfcPollerGetData) (const NfcGenericInstance *instance)
 Get the data that was that was gathered during the reading process.
 

Detailed Description

Abstract interface definitions for the NFC poller system.

This file is an implementation detail. It must not be included in any public API-related headers.

See also
nfc_poller.h

Typedef Documentation

◆ NfcPollerAlloc

typedef NfcGenericInstance *(* NfcPollerAlloc) (NfcGenericInstance *base_poller)

Allocate a protocol-specific poller instance.

For base pollers pass a pointer to an instance of type Nfc as the base_poller parameter, otherwise it must be a pointer to another poller instance (compare iso14443_3a/iso14443_3a_poller.c and iso14443_4a/iso14443_4a_poller.c).

See also
nfc_protocol.c
Parameters
[in]base_pollerpointer to the parent poller instance.
Returns
pointer to the allocated poller instance.

◆ NfcPollerDetect

typedef bool(* NfcPollerDetect) (NfcGenericEvent event, void *context)

Determine whether there is a supported card in the vicinity.

The behaviour is mostly the same as of NfcPollerRun, with the difference in the procedure and return value. The procedure implemented in this function must do whatever it needs to unambigiously determine whether a supported and valid NFC card is in the vicinity.

Like the previously described NfcPollerRun, it is called automatically by the NfcPoller implementation, so there is no need to call it explicitly.

Parameters
[in]eventprotocol-specific event passed by the parent poller instance.
[in,out]contextpointer to the protocol-specific poller instance.
Returns
true if a supported card was detected, false otherwise.

◆ NfcPollerFree

typedef void(* NfcPollerFree) (NfcGenericInstance *instance)

Delete a protocol-specific poller instance.

Parameters
[in,out]instancepointer to the instance to be deleted.

◆ NfcPollerGetData

typedef const NfcDeviceData *(* NfcPollerGetData) (const NfcGenericInstance *instance)

Get the data that was that was gathered during the reading process.

Parameters
[in]instancepointer to the protocol-specific poller instance.
Returns
pointer to the NFC device data.

◆ NfcPollerRun

typedef NfcCommand(* NfcPollerRun) (NfcGenericEvent event, void *context)

Activate and read a supported NFC card.

Ths function is passed to the parent poller's ${POLLER_NAME}_set_callback function as the callback parameter. This is done automatically by the NfcPoller implementation based on the protocol hierarchy defined in nfc_protocol.c, so there is no need to call it explicitly.

Thus, it will be called each time the parent poller emits an event. Usually it happens only after the parent poller has successfully completed its job.

Example for an application reading a card with a compound (non-base) protocol (simplified):

start() <-- set_callback() <-- set_callback() <-- nfc_poller_start()
| | |
Nfc | Base Poller | Child Poller | Application
| | |
worker() --> run() --> run() ---> handle_event()
Definition nfc.c:41

The base poller receives events directly from an Nfc instance, from which they are propagated as needed to however many other pollers there are in the current hierarchy.

This function can be thought of as the poller's "main loop" function. Depending on the particular poller implementation, it may perform actions such as reading and writing to an NFC card, state changes and control of the parent poller.

See also
nfc_generic_event.h
Parameters
[in]eventprotocol-specific event passed by the parent poller instance.
[in,out]contextpointer to the protocol-specific poller instance.
Returns
command to be executed by the parent poller instance.

◆ NfcPollerSetCallback

typedef void( * NfcPollerSetCallback) (NfcGenericInstance *poller, NfcGenericCallback callback, void *context)

Set the callback function to handle events emitted by the poller instance.

See also
nfc_generic_event.h
Parameters
[in,out]pollerpointer to the protocol-specific poller instance.
[in]callbackpointer to the user-defined callback function which will receive events.
[in]contextpointer to the user-specific context (will be passed to the callback).