[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:
gornekich
2023-11-15 17:32:45 +09:00
committed by GitHub
co-authored by あく
parent d0b9a3a4ae
commit c00776ca22
62 changed files with 1708 additions and 719 deletions
@@ -70,7 +70,7 @@ static NfcCommand iso15693_3_poller_run(NfcGenericEvent event, void* context) {
if(nfc_event->type == NfcEventTypePollerReady) {
if(instance->state != Iso15693_3PollerStateActivated) {
Iso15693_3Error error = iso15693_3_poller_async_activate(instance, instance->data);
Iso15693_3Error error = iso15693_3_poller_activate(instance, instance->data);
if(error == Iso15693_3ErrorNone) {
instance->iso15693_3_event.type = Iso15693_3PollerEventTypeReady;
instance->iso15693_3_event_data.error = error;
@@ -105,7 +105,7 @@ static bool iso15693_3_poller_detect(NfcGenericEvent event, void* context) {
if(nfc_event->type == NfcEventTypePollerReady) {
uint8_t uid[ISO15693_3_UID_SIZE];
Iso15693_3Error error = iso15693_3_poller_async_inventory(instance, uid);
Iso15693_3Error error = iso15693_3_poller_inventory(instance, uid);
protocol_detected = (error == Iso15693_3ErrorNone);
}
@@ -8,22 +8,142 @@
extern "C" {
#endif
/**
* @brief Iso15693_3Poller opaque type definition.
*/
typedef struct Iso15693_3Poller Iso15693_3Poller;
/**
* @brief Enumeration of possible Iso15693_3 poller event types.
*/
typedef enum {
Iso15693_3PollerEventTypeError,
Iso15693_3PollerEventTypeReady,
Iso15693_3PollerEventTypeError, /**< The card was activated by the poller. */
Iso15693_3PollerEventTypeReady, /**< An error occured during activation procedure. */
} Iso15693_3PollerEventType;
typedef struct {
Iso15693_3Error error;
/**
* @brief Iso15693_3 poller event data.
*/
typedef union {
Iso15693_3Error error; /**< Error code indicating card activation fail reason. */
} Iso15693_3PollerEventData;
/**
* @brief Iso15693_3 poller event structure.
*
* Upon emission of an event, an instance of this struct will be passed to the callback.
*/
typedef struct {
Iso15693_3PollerEventType type;
Iso15693_3PollerEventData* data;
Iso15693_3PollerEventType type; /**< Type of emmitted event. */
Iso15693_3PollerEventData* data; /**< Pointer to event specific data. */
} Iso15693_3PollerEvent;
/**
* @brief Transmit and receive Iso15693_3 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 Iso15693_3ErrorNone on success, an error code on failure.
*/
Iso15693_3Error iso15693_3_poller_send_frame(
Iso15693_3Poller* instance,
const BitBuffer* tx_buffer,
BitBuffer* rx_buffer,
uint32_t fwt);
/**
* @brief Perform activation procedure.
*
* Must ONLY be used inside the callback function.
*
* Perfoms the activation procedure as defined in Iso15693_3. The data
* field will be filled with Iso15693_3Data data on success.
*
* @param[in, out] instance pointer to the instance to be used in the transaction.
* @param[out] data pointer to the Iso15693_3 data structure to be filled.
* @return Iso15693_3ErrorNone on success, an error code on failure.
*/
Iso15693_3Error iso15693_3_poller_activate(Iso15693_3Poller* instance, Iso15693_3Data* data);
/**
* @brief Send invertory command and parse response.
*
* Must ONLY be used inside the callback function.
*
* @param[in, out] instance pointer to the instance to be used in the transaction.
* @param[out] uid pointer to the buffer to be filled with the UID.
* @return Iso15693_3ErrorNone on success, an error code on failure.
*/
Iso15693_3Error iso15693_3_poller_inventory(Iso15693_3Poller* instance, uint8_t* uid);
/**
* @brief Send get system info command and parse response.
*
* Must ONLY be used inside the callback function.
*
* @param[in, out] instance pointer to the instance to be used in the transaction.
* @param[out] data pointer to the Iso15693_3SystemInfo structure to be filled.
* @return Iso15693_3ErrorNone on success, an error code on failure.
*/
Iso15693_3Error
iso15693_3_poller_get_system_info(Iso15693_3Poller* instance, Iso15693_3SystemInfo* data);
/**
* @brief Read Iso15693_3 block.
*
* Must ONLY be used inside the callback function.
*
* @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 the block data.
* @param[in] block_number block number to be read.
* @param[in] block_size size of the block to be read.
* @return Iso15693_3ErrorNone on success, an error code on failure.
*/
Iso15693_3Error iso15693_3_poller_read_block(
Iso15693_3Poller* instance,
uint8_t* data,
uint8_t block_number,
uint8_t block_size);
/**
* @brief Read multiple Iso15693_3 blocks.
*
* Must ONLY be used inside the callback function.
*
* @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 the block data.
* @param[in] block_count number of blocks to be read.
* @param[in] block_size size of the blocks to be read.
* @return Iso15693_3ErrorNone on success, an error code on failure.
*/
Iso15693_3Error iso15693_3_poller_read_blocks(
Iso15693_3Poller* instance,
uint8_t* data,
uint16_t block_count,
uint8_t block_size);
/**
* @brief Get Iso15693_3 block security status.
*
* Must ONLY be used inside the callback function.
*
* @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 the block security status.
* @param[in] block_count block security number to be read.
* @return Iso15693_3ErrorNone on success, an error code on failure.
*/
Iso15693_3Error iso15693_3_poller_get_blocks_security(
Iso15693_3Poller* instance,
uint8_t* data,
uint16_t block_count);
#ifdef __cplusplus
}
#endif
@@ -36,7 +36,7 @@ static Iso15693_3Error iso15693_3_poller_prepare_trx(Iso15693_3Poller* instance)
furi_assert(instance);
if(instance->state == Iso15693_3PollerStateIdle) {
return iso15693_3_poller_async_activate(instance, NULL);
return iso15693_3_poller_activate(instance, NULL);
}
return Iso15693_3ErrorNone;
@@ -80,8 +80,7 @@ static Iso15693_3Error iso15693_3_poller_frame_exchange(
return ret;
}
Iso15693_3Error
iso15693_3_poller_async_activate(Iso15693_3Poller* instance, Iso15693_3Data* data) {
Iso15693_3Error iso15693_3_poller_activate(Iso15693_3Poller* instance, Iso15693_3Data* data) {
furi_assert(instance);
furi_assert(instance->nfc);
@@ -93,7 +92,7 @@ Iso15693_3Error
instance->state = Iso15693_3PollerStateColResInProgress;
// Inventory: Mandatory command
ret = iso15693_3_poller_async_inventory(instance, data->uid);
ret = iso15693_3_poller_inventory(instance, data->uid);
if(ret != Iso15693_3ErrorNone) {
instance->state = Iso15693_3PollerStateColResFailed;
break;
@@ -103,7 +102,7 @@ Iso15693_3Error
// Get system info: Optional command
Iso15693_3SystemInfo* system_info = &data->system_info;
ret = iso15693_3_poller_async_get_system_info(instance, system_info);
ret = iso15693_3_poller_get_system_info(instance, system_info);
if(ret != Iso15693_3ErrorNone) {
ret = iso15693_3_poller_filter_error(ret);
break;
@@ -111,7 +110,7 @@ Iso15693_3Error
// Read blocks: Optional command
simple_array_init(data->block_data, system_info->block_count * system_info->block_size);
ret = iso15693_3_poller_async_read_blocks(
ret = iso15693_3_poller_read_blocks(
instance,
simple_array_get_data(data->block_data),
system_info->block_count,
@@ -124,7 +123,7 @@ Iso15693_3Error
// Get block security status: Optional command
simple_array_init(data->block_security, system_info->block_count);
ret = iso15693_3_poller_async_get_blocks_security(
ret = iso15693_3_poller_get_blocks_security(
instance, simple_array_get_data(data->block_security), system_info->block_count);
if(ret != Iso15693_3ErrorNone) {
ret = iso15693_3_poller_filter_error(ret);
@@ -136,7 +135,7 @@ Iso15693_3Error
return ret;
}
Iso15693_3Error iso15693_3_poller_async_inventory(Iso15693_3Poller* instance, uint8_t* uid) {
Iso15693_3Error iso15693_3_poller_inventory(Iso15693_3Poller* instance, uint8_t* uid) {
furi_assert(instance);
furi_assert(instance->nfc);
furi_assert(uid);
@@ -165,9 +164,8 @@ Iso15693_3Error iso15693_3_poller_async_inventory(Iso15693_3Poller* instance, ui
return ret;
}
Iso15693_3Error iso15693_3_poller_async_get_system_info(
Iso15693_3Poller* instance,
Iso15693_3SystemInfo* data) {
Iso15693_3Error
iso15693_3_poller_get_system_info(Iso15693_3Poller* instance, Iso15693_3SystemInfo* data) {
furi_assert(instance);
furi_assert(data);
@@ -193,7 +191,7 @@ Iso15693_3Error iso15693_3_poller_async_get_system_info(
return ret;
}
Iso15693_3Error iso15693_3_poller_async_read_block(
Iso15693_3Error iso15693_3_poller_read_block(
Iso15693_3Poller* instance,
uint8_t* data,
uint8_t block_number,
@@ -222,7 +220,7 @@ Iso15693_3Error iso15693_3_poller_async_read_block(
return ret;
}
Iso15693_3Error iso15693_3_poller_async_read_blocks(
Iso15693_3Error iso15693_3_poller_read_blocks(
Iso15693_3Poller* instance,
uint8_t* data,
uint16_t block_count,
@@ -235,14 +233,14 @@ Iso15693_3Error iso15693_3_poller_async_read_blocks(
Iso15693_3Error ret = Iso15693_3ErrorNone;
for(uint32_t i = 0; i < block_count; ++i) {
ret = iso15693_3_poller_async_read_block(instance, &data[block_size * i], i, block_size);
ret = iso15693_3_poller_read_block(instance, &data[block_size * i], i, block_size);
if(ret != Iso15693_3ErrorNone) break;
}
return ret;
}
Iso15693_3Error iso15693_3_poller_async_get_blocks_security(
Iso15693_3Error iso15693_3_poller_get_blocks_security(
Iso15693_3Poller* instance,
uint8_t* data,
uint16_t block_count) {
@@ -35,36 +35,6 @@ struct Iso15693_3Poller {
const Iso15693_3Data* iso15693_3_poller_get_data(Iso15693_3Poller* instance);
Iso15693_3Error iso15693_3_poller_async_activate(Iso15693_3Poller* instance, Iso15693_3Data* data);
Iso15693_3Error iso15693_3_poller_async_inventory(Iso15693_3Poller* instance, uint8_t* uid);
Iso15693_3Error
iso15693_3_poller_async_get_system_info(Iso15693_3Poller* instance, Iso15693_3SystemInfo* data);
Iso15693_3Error iso15693_3_poller_async_read_block(
Iso15693_3Poller* instance,
uint8_t* data,
uint8_t block_number,
uint8_t block_size);
Iso15693_3Error iso15693_3_poller_async_read_blocks(
Iso15693_3Poller* instance,
uint8_t* data,
uint16_t block_count,
uint8_t block_size);
Iso15693_3Error iso15693_3_poller_async_get_blocks_security(
Iso15693_3Poller* instance,
uint8_t* data,
uint16_t block_count);
Iso15693_3Error iso15693_3_poller_send_frame(
Iso15693_3Poller* instance,
const BitBuffer* tx_buffer,
BitBuffer* rx_buffer,
uint32_t fwt);
#ifdef __cplusplus
}
#endif