[FL-3666] NFC API improvements (#3214)
* drivers: expose st25r3916 driver API * nfc poller: add start with custom callback * mf classic: rework sync API with poller custom start * mf ultralight: rework sync API with poller custom start * iso14443_3a poller: remove unused col res state * nfc: rework nfc poller custom start * mf ultralight: rename sync API * mf classic: rename sync API * iso14443-3a: rename sync API * nfc: remove async prefix in internal functions * nfc: expose internal API * nfc: fix sync api include and docs * targets: fix f18 build * nfc: rework NfcGenericEventEx type * nfc poller: add documentation * iso14443-3a poller: add documentation * felica poller: add documentation * iso14443_3b poller: add documentation * so14443_4a poller: add documentation * iso14443_4b poller: add documentation * iso15693 poller: add documentation * slix poller: add documentation * mf desfire poller: add documentation * mf ultralight poller: fix API and add documentation * mf classic poller: add documentation Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
@@ -70,7 +70,7 @@ static NfcCommand iso14443_3b_poller_run(NfcGenericEvent event, void* context) {
|
||||
|
||||
if(nfc_event->type == NfcEventTypePollerReady) {
|
||||
if(instance->state != Iso14443_3bPollerStateActivated) {
|
||||
Iso14443_3bError error = iso14443_3b_poller_async_activate(instance, instance->data);
|
||||
Iso14443_3bError error = iso14443_3b_poller_activate(instance, instance->data);
|
||||
if(error == Iso14443_3bErrorNone) {
|
||||
instance->iso14443_3b_event.type = Iso14443_3bPollerEventTypeReady;
|
||||
instance->iso14443_3b_event_data.error = error;
|
||||
@@ -104,7 +104,7 @@ static bool iso14443_3b_poller_detect(NfcGenericEvent event, void* context) {
|
||||
furi_assert(instance->state == Iso14443_3bPollerStateIdle);
|
||||
|
||||
if(nfc_event->type == NfcEventTypePollerReady) {
|
||||
Iso14443_3bError error = iso14443_3b_poller_async_activate(instance, instance->data);
|
||||
Iso14443_3bError error = iso14443_3b_poller_activate(instance, instance->data);
|
||||
protocol_detected = (error == Iso14443_3bErrorNone);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,22 +9,81 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Iso14443_3bPoller opaque type definition.
|
||||
*/
|
||||
typedef struct Iso14443_3bPoller Iso14443_3bPoller;
|
||||
|
||||
/**
|
||||
* @brief Enumeration of possible Iso14443_3b poller event types.
|
||||
*/
|
||||
typedef enum {
|
||||
Iso14443_3bPollerEventTypeError,
|
||||
Iso14443_3bPollerEventTypeReady,
|
||||
Iso14443_3bPollerEventTypeError, /**< The card was activated by the poller. */
|
||||
Iso14443_3bPollerEventTypeReady, /**< An error occured during activation procedure. */
|
||||
} Iso14443_3bPollerEventType;
|
||||
|
||||
typedef struct {
|
||||
Iso14443_3bError error;
|
||||
/**
|
||||
* @brief Iso14443_3b poller event data.
|
||||
*/
|
||||
typedef union {
|
||||
Iso14443_3bError error; /**< Error code indicating card activation fail reason. */
|
||||
} Iso14443_3bPollerEventData;
|
||||
|
||||
/**
|
||||
* @brief Iso14443_3b poller event structure.
|
||||
*
|
||||
* Upon emission of an event, an instance of this struct will be passed to the callback.
|
||||
*/
|
||||
typedef struct {
|
||||
Iso14443_3bPollerEventType type;
|
||||
Iso14443_3bPollerEventData* data;
|
||||
Iso14443_3bPollerEventType type; /**< Type of emmitted event. */
|
||||
Iso14443_3bPollerEventData* data; /**< Pointer to event specific data. */
|
||||
} Iso14443_3bPollerEvent;
|
||||
|
||||
/**
|
||||
* @brief Transmit and receive Iso14443_3b frames in poller mode.
|
||||
*
|
||||
* Must ONLY be used inside the callback function.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @param[in, out] instance pointer to the instance to be used in the transaction.
|
||||
* @param[in] tx_buffer pointer to the buffer containing the data to be transmitted.
|
||||
* @param[out] rx_buffer pointer to the buffer to be filled with received data.
|
||||
* @param[in] fwt frame wait time (response timeout), in carrier cycles.
|
||||
* @return Iso14443_3bErrorNone on success, an error code on failure.
|
||||
*/
|
||||
Iso14443_3bError iso14443_3b_poller_send_frame(
|
||||
Iso14443_3bPoller* instance,
|
||||
const BitBuffer* tx_buffer,
|
||||
BitBuffer* rx_buffer);
|
||||
|
||||
/**
|
||||
* @brief Perform collision resolution procedure.
|
||||
*
|
||||
* Must ONLY be used inside the callback function.
|
||||
*
|
||||
* Perfoms the collision resolution procedure as defined in Iso14443-3b. The data
|
||||
* field will be filled with Iso14443-3b data on success.
|
||||
*
|
||||
* @param[in, out] instance pointer to the instance to be used in the transaction.
|
||||
* @param[out] data pointer to the Iso14443_3b data structure to be filled.
|
||||
* @return Iso14443_3bErrorNone on success, an error code on failure.
|
||||
*/
|
||||
Iso14443_3bError iso14443_3b_poller_activate(Iso14443_3bPoller* instance, Iso14443_3bData* data);
|
||||
|
||||
/**
|
||||
* @brief Send HALT command to the card.
|
||||
*
|
||||
* Must ONLY be used inside the callback function.
|
||||
*
|
||||
* Halts card and changes internal Iso14443_3bPoller state to Idle.
|
||||
*
|
||||
* @param[in, out] instance pointer to the instance to be used in the transaction.
|
||||
* @return Iso14443_3bErrorNone on success, an error code on failure.
|
||||
*/
|
||||
Iso14443_3bError iso14443_3b_poller_halt(Iso14443_3bPoller* instance);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -21,7 +21,7 @@ static Iso14443_3bError iso14443_3b_poller_prepare_trx(Iso14443_3bPoller* instan
|
||||
furi_assert(instance);
|
||||
|
||||
if(instance->state == Iso14443_3bPollerStateIdle) {
|
||||
return iso14443_3b_poller_async_activate(instance, NULL);
|
||||
return iso14443_3b_poller_activate(instance, NULL);
|
||||
}
|
||||
|
||||
return Iso14443_3bErrorNone;
|
||||
@@ -63,8 +63,7 @@ static Iso14443_3bError iso14443_3b_poller_frame_exchange(
|
||||
return ret;
|
||||
}
|
||||
|
||||
Iso14443_3bError
|
||||
iso14443_3b_poller_async_activate(Iso14443_3bPoller* instance, Iso14443_3bData* data) {
|
||||
Iso14443_3bError iso14443_3b_poller_activate(Iso14443_3bPoller* instance, Iso14443_3bData* data) {
|
||||
furi_assert(instance);
|
||||
furi_assert(instance->nfc);
|
||||
|
||||
|
||||
@@ -34,16 +34,6 @@ struct Iso14443_3bPoller {
|
||||
|
||||
const Iso14443_3bData* iso14443_3b_poller_get_data(Iso14443_3bPoller* instance);
|
||||
|
||||
Iso14443_3bError
|
||||
iso14443_3b_poller_async_activate(Iso14443_3bPoller* instance, Iso14443_3bData* data);
|
||||
|
||||
Iso14443_3bError iso14443_3b_poller_halt(Iso14443_3bPoller* instance);
|
||||
|
||||
Iso14443_3bError iso14443_3b_poller_send_frame(
|
||||
Iso14443_3bPoller* instance,
|
||||
const BitBuffer* tx_buffer,
|
||||
BitBuffer* rx_buffer);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user