[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:
@@ -2,6 +2,8 @@
|
||||
|
||||
#include <nfc/protocols/iso14443_3a/iso14443_3a.h>
|
||||
|
||||
#include <lib/toolbox/simple_array.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@@ -28,7 +30,19 @@ typedef enum {
|
||||
Iso14443_4aFrameOptionCid,
|
||||
} Iso14443_4aFrameOption;
|
||||
|
||||
typedef struct Iso14443_4aData Iso14443_4aData;
|
||||
typedef struct {
|
||||
uint8_t tl;
|
||||
uint8_t t0;
|
||||
uint8_t ta_1;
|
||||
uint8_t tb_1;
|
||||
uint8_t tc_1;
|
||||
SimpleArray* t1_tk;
|
||||
} Iso14443_4aAtsData;
|
||||
|
||||
typedef struct {
|
||||
Iso14443_3aData* iso14443_3a_data;
|
||||
Iso14443_4aAtsData ats_data;
|
||||
} Iso14443_4aData;
|
||||
|
||||
// Virtual methods
|
||||
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
|
||||
#include "iso14443_4a.h"
|
||||
|
||||
#include <lib/toolbox/simple_array.h>
|
||||
|
||||
#define ISO14443_4A_CMD_READ_ATS (0xE0)
|
||||
|
||||
// ATS bit definitions
|
||||
@@ -23,20 +21,6 @@
|
||||
#define ISO14443_4A_ATS_TC1_NAD (1U << 0)
|
||||
#define ISO14443_4A_ATS_TC1_CID (1U << 1)
|
||||
|
||||
typedef struct {
|
||||
uint8_t tl;
|
||||
uint8_t t0;
|
||||
uint8_t ta_1;
|
||||
uint8_t tb_1;
|
||||
uint8_t tc_1;
|
||||
SimpleArray* t1_tk;
|
||||
} Iso14443_4aAtsData;
|
||||
|
||||
struct Iso14443_4aData {
|
||||
Iso14443_3aData* iso14443_3a_data;
|
||||
Iso14443_4aAtsData ats_data;
|
||||
};
|
||||
|
||||
bool iso14443_4a_ats_parse(Iso14443_4aAtsData* data, const BitBuffer* buf);
|
||||
|
||||
Iso14443_4aError iso14443_4a_process_error(Iso14443_3aError error);
|
||||
|
||||
@@ -55,8 +55,7 @@ static NfcCommand iso14443_4a_poller_handler_idle(Iso14443_4aPoller* instance) {
|
||||
}
|
||||
|
||||
static NfcCommand iso14443_4a_poller_handler_read_ats(Iso14443_4aPoller* instance) {
|
||||
Iso14443_4aError error =
|
||||
iso14443_4a_poller_async_read_ats(instance, &instance->data->ats_data);
|
||||
Iso14443_4aError error = iso14443_4a_poller_read_ats(instance, &instance->data->ats_data);
|
||||
if(error == Iso14443_4aErrorNone) {
|
||||
FURI_LOG_D(TAG, "Read ATS success");
|
||||
instance->poller_state = Iso14443_4aPollerStateReady;
|
||||
|
||||
@@ -8,22 +8,80 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Iso14443_4aPoller opaque type definition.
|
||||
*/
|
||||
typedef struct Iso14443_4aPoller Iso14443_4aPoller;
|
||||
|
||||
/**
|
||||
* @brief Enumeration of possible Iso14443_4a poller event types.
|
||||
*/
|
||||
typedef enum {
|
||||
Iso14443_4aPollerEventTypeError,
|
||||
Iso14443_4aPollerEventTypeReady,
|
||||
Iso14443_4aPollerEventTypeError, /**< The card was activated by the poller. */
|
||||
Iso14443_4aPollerEventTypeReady, /**< An error occured during activation procedure. */
|
||||
} Iso14443_4aPollerEventType;
|
||||
|
||||
typedef struct {
|
||||
Iso14443_4aError error;
|
||||
/**
|
||||
* @brief Iso14443_4a poller event data.
|
||||
*/
|
||||
typedef union {
|
||||
Iso14443_4aError error; /**< Error code indicating card activation fail reason. */
|
||||
} Iso14443_4aPollerEventData;
|
||||
|
||||
/**
|
||||
* @brief Iso14443_4a poller event structure.
|
||||
*
|
||||
* Upon emission of an event, an instance of this struct will be passed to the callback.
|
||||
*/
|
||||
typedef struct {
|
||||
Iso14443_4aPollerEventType type;
|
||||
Iso14443_4aPollerEventData* data;
|
||||
Iso14443_4aPollerEventType type; /**< Type of emmitted event. */
|
||||
Iso14443_4aPollerEventData* data; /**< Pointer to event specific data. */
|
||||
} Iso14443_4aPollerEvent;
|
||||
|
||||
/**
|
||||
* @brief Transmit and receive Iso14443_4a blocks 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. The fwt parameter is calculated during activation procedure.
|
||||
*
|
||||
* @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.
|
||||
* @return Iso14443_4aErrorNone on success, an error code on failure.
|
||||
*/
|
||||
Iso14443_4aError iso14443_4a_poller_send_block(
|
||||
Iso14443_4aPoller* instance,
|
||||
const BitBuffer* tx_buffer,
|
||||
BitBuffer* rx_buffer);
|
||||
|
||||
/**
|
||||
* @brief Send HALT command to the card.
|
||||
*
|
||||
* Must ONLY be used inside the callback function.
|
||||
*
|
||||
* Halts card and changes internal Iso14443_4aPoller state to Idle.
|
||||
*
|
||||
* @param[in, out] instance pointer to the instance to be used in the transaction.
|
||||
* @return Iso14443_4aErrorNone on success, an error code on failure.
|
||||
*/
|
||||
Iso14443_4aError iso14443_4a_poller_halt(Iso14443_4aPoller* instance);
|
||||
|
||||
/**
|
||||
* @brief Read Answer To Select (ATS) from the card.
|
||||
*
|
||||
* Must ONLY be used inside the callback function.
|
||||
*
|
||||
* Send Request Answer To Select (RATS) command to the card and parse the response.
|
||||
*
|
||||
* @param[in, out] instance pointer to the instance to be used in the transaction.
|
||||
* @param[out] data pointer to the buffer to be filled with ATS data.
|
||||
* @return Iso14443_4aErrorNone on success, an error code on failure.
|
||||
*/
|
||||
Iso14443_4aError
|
||||
iso14443_4a_poller_read_ats(Iso14443_4aPoller* instance, Iso14443_4aAtsData* data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -18,7 +18,7 @@ Iso14443_4aError iso14443_4a_poller_halt(Iso14443_4aPoller* instance) {
|
||||
}
|
||||
|
||||
Iso14443_4aError
|
||||
iso14443_4a_poller_async_read_ats(Iso14443_4aPoller* instance, Iso14443_4aAtsData* data) {
|
||||
iso14443_4a_poller_read_ats(Iso14443_4aPoller* instance, Iso14443_4aAtsData* data) {
|
||||
furi_assert(instance);
|
||||
|
||||
bit_buffer_reset(instance->tx_buffer);
|
||||
|
||||
@@ -45,16 +45,6 @@ struct Iso14443_4aPoller {
|
||||
|
||||
const Iso14443_4aData* iso14443_4a_poller_get_data(Iso14443_4aPoller* instance);
|
||||
|
||||
Iso14443_4aError iso14443_4a_poller_halt(Iso14443_4aPoller* instance);
|
||||
|
||||
Iso14443_4aError
|
||||
iso14443_4a_poller_async_read_ats(Iso14443_4aPoller* instance, Iso14443_4aAtsData* data);
|
||||
|
||||
Iso14443_4aError iso14443_4a_poller_send_block(
|
||||
Iso14443_4aPoller* instance,
|
||||
const BitBuffer* tx_buffer,
|
||||
BitBuffer* rx_buffer);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user