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

NFC card emulation library. More...

Go to the source code of this file.

Typedefs

typedef struct NfcListener NfcListener
 NfcListener opaque type definition.
 

Functions

NfcListenernfc_listener_alloc (Nfc *nfc, NfcProtocol protocol, const NfcDeviceData *data)
 Allocate an NfcListener instance.
 
void nfc_listener_free (NfcListener *instance)
 Delete an NfcListener instance.
 
void nfc_listener_start (NfcListener *instance, NfcGenericCallback callback, void *context)
 Start an NfcListener instance.
 
void nfc_listener_stop (NfcListener *instance)
 Stop an NfcListener instance.
 
NfcProtocol nfc_listener_get_protocol (const NfcListener *instance)
 Get the protocol identifier an NfcListener instance was created with.
 
const NfcDeviceDatanfc_listener_get_data (const NfcListener *instance, NfcProtocol protocol)
 Get the data that was that was provided for emulation.
 

Detailed Description

NFC card emulation library.

Once started, it will respond to supported commands from an NFC reader, thus imitating (or emulating) an NFC card. The responses will depend on the data that was supplied to the listener, so various card types and different cards of the same type can be emulated.

It will also make any changes necessary to the emulated data in response to the reader commands if the protocol supports it.

When running, NfcListener will generate events that the calling code must handle by providing a callback function. The events passed to the callback are protocol-specific and may include errors, state changes, data reception, special function requests and more.

Function Documentation

◆ nfc_listener_alloc()

NfcListener * nfc_listener_alloc ( Nfc * nfc,
NfcProtocol protocol,
const NfcDeviceData * data )

Allocate an NfcListener instance.

Parameters
[in]nfcpointer to an Nfc instance.
[in]protocolidentifier of the protocol to be used.
[in]datapointer to the data to use during emulation.
Returns
pointer to an allocated instance.
See also
nfc.h

◆ nfc_listener_free()

void nfc_listener_free ( NfcListener * instance)

Delete an NfcListener instance.

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

◆ nfc_listener_get_data()

const NfcDeviceData * nfc_listener_get_data ( const NfcListener * instance,
NfcProtocol protocol )

Get the data that was that was provided for emulation.

The protocol identifier passed as the protocol parameter MUST match the one stored in the instance, otherwise a crash will occur. This is to improve type safety.

Parameters
[in]instancepointer to the instance to be queried.
[in]protocolassumed protocol identifier of the data to be retrieved.
Returns
pointer to the NFC device data.

◆ nfc_listener_get_protocol()

NfcProtocol nfc_listener_get_protocol ( const NfcListener * instance)

Get the protocol identifier an NfcListener instance was created with.

Parameters
[in]instancepointer to the instance to be queried.
Returns
identifier of the protocol used by the instance.

◆ nfc_listener_start()

void nfc_listener_start ( NfcListener * instance,
NfcGenericCallback callback,
void * context )

Start an NfcListener instance.

The callback logic is protocol-specific, so it cannot be described here in detail. However, the callback return value ALWAYS determines what the listener should do next: to continue whatever it was doing prior to the callback run or to stop.

Parameters
[in,out]instancepointer to the instance to be started.
[in]callbackpointer to a user-defined callback function which will receive events.
[in]contextpointer to a user-specific context (will be passed to the callback).

◆ nfc_listener_stop()

void nfc_listener_stop ( NfcListener * instance)

Stop an NfcListener instance.

The emulation process can be stopped explicitly (the other way is via the callback return value).

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