[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:
@@ -230,7 +230,7 @@ static NfcCommand mf_ultralight_poller_handler_idle(MfUltralightPoller* instance
|
||||
}
|
||||
|
||||
static NfcCommand mf_ultralight_poller_handler_read_version(MfUltralightPoller* instance) {
|
||||
instance->error = mf_ultralight_poller_async_read_version(instance, &instance->data->version);
|
||||
instance->error = mf_ultralight_poller_read_version(instance, &instance->data->version);
|
||||
if(instance->error == MfUltralightErrorNone) {
|
||||
FURI_LOG_D(TAG, "Read version success");
|
||||
instance->data->type = mf_ultralight_get_type_by_version(&instance->data->version);
|
||||
@@ -245,7 +245,7 @@ static NfcCommand mf_ultralight_poller_handler_read_version(MfUltralightPoller*
|
||||
}
|
||||
|
||||
static NfcCommand mf_ultralight_poller_handler_check_ultralight_c(MfUltralightPoller* instance) {
|
||||
instance->error = mf_ultralight_poller_async_authenticate(instance);
|
||||
instance->error = mf_ultralight_poller_authenticate(instance);
|
||||
if(instance->error == MfUltralightErrorNone) {
|
||||
FURI_LOG_D(TAG, "Ultralight C detected");
|
||||
instance->data->type = MfUltralightTypeMfulC;
|
||||
@@ -260,7 +260,7 @@ static NfcCommand mf_ultralight_poller_handler_check_ultralight_c(MfUltralightPo
|
||||
|
||||
static NfcCommand mf_ultralight_poller_handler_check_ntag_203(MfUltralightPoller* instance) {
|
||||
MfUltralightPageReadCommandData data = {};
|
||||
instance->error = mf_ultralight_poller_async_read_page(instance, 41, &data);
|
||||
instance->error = mf_ultralight_poller_read_page(instance, 41, &data);
|
||||
if(instance->error == MfUltralightErrorNone) {
|
||||
FURI_LOG_D(TAG, "NTAG203 detected");
|
||||
instance->data->type = MfUltralightTypeNTAG203;
|
||||
@@ -294,7 +294,7 @@ static NfcCommand mf_ultralight_poller_handler_read_signature(MfUltralightPoller
|
||||
instance->feature_set, MfUltralightFeatureSupportReadSignature)) {
|
||||
FURI_LOG_D(TAG, "Reading signature");
|
||||
instance->error =
|
||||
mf_ultralight_poller_async_read_signature(instance, &instance->data->signature);
|
||||
mf_ultralight_poller_read_signature(instance, &instance->data->signature);
|
||||
if(instance->error != MfUltralightErrorNone) {
|
||||
FURI_LOG_D(TAG, "Read signature failed");
|
||||
next_state = MfUltralightPollerStateReadFailed;
|
||||
@@ -337,7 +337,7 @@ static NfcCommand mf_ultralight_poller_handler_read_counters(MfUltralightPoller*
|
||||
}
|
||||
|
||||
FURI_LOG_D(TAG, "Reading counter %d", instance->counters_read);
|
||||
instance->error = mf_ultralight_poller_async_read_counter(
|
||||
instance->error = mf_ultralight_poller_read_counter(
|
||||
instance, instance->counters_read, &instance->data->counter[instance->counters_read]);
|
||||
if(instance->error != MfUltralightErrorNone) {
|
||||
FURI_LOG_D(TAG, "Failed to read %d counter", instance->counters_read);
|
||||
@@ -363,7 +363,7 @@ static NfcCommand mf_ultralight_poller_handler_read_tearing_flags(MfUltralightPo
|
||||
if(single_counter) instance->tearing_flag_read = 2;
|
||||
|
||||
FURI_LOG_D(TAG, "Reading tearing flag %d", instance->tearing_flag_read);
|
||||
instance->error = mf_ultralight_poller_async_read_tearing_flag(
|
||||
instance->error = mf_ultralight_poller_read_tearing_flag(
|
||||
instance,
|
||||
instance->tearing_flag_read,
|
||||
&instance->data->tearing_flag[instance->tearing_flag_read]);
|
||||
@@ -396,8 +396,7 @@ static NfcCommand mf_ultralight_poller_handler_auth(MfUltralightPoller* instance
|
||||
uint32_t pass = nfc_util_bytes2num(
|
||||
instance->auth_context.password.data, sizeof(MfUltralightAuthPassword));
|
||||
FURI_LOG_D(TAG, "Trying to authenticate with password %08lX", pass);
|
||||
instance->error =
|
||||
mf_ultralight_poller_async_auth_pwd(instance, &instance->auth_context);
|
||||
instance->error = mf_ultralight_poller_auth_pwd(instance, &instance->auth_context);
|
||||
if(instance->error == MfUltralightErrorNone) {
|
||||
FURI_LOG_D(TAG, "Auth success");
|
||||
instance->auth_context.auth_success = true;
|
||||
@@ -428,13 +427,13 @@ static NfcCommand mf_ultralight_poller_handler_read_pages(MfUltralightPoller* in
|
||||
if(mf_ultralight_poller_ntag_i2c_addr_lin_to_tag(
|
||||
instance, start_page, §or, &tag, &pages_left)) {
|
||||
instance->error =
|
||||
mf_ultralight_poller_async_read_page_from_sector(instance, sector, tag, &data);
|
||||
mf_ultralight_poller_read_page_from_sector(instance, sector, tag, &data);
|
||||
} else {
|
||||
FURI_LOG_D(TAG, "Failed to calculate sector and tag from %d page", start_page);
|
||||
instance->error = MfUltralightErrorProtocol;
|
||||
}
|
||||
} else {
|
||||
instance->error = mf_ultralight_poller_async_read_page(instance, start_page, &data);
|
||||
instance->error = mf_ultralight_poller_read_page(instance, start_page, &data);
|
||||
}
|
||||
|
||||
if(instance->error == MfUltralightErrorNone) {
|
||||
@@ -478,8 +477,7 @@ static NfcCommand mf_ultralight_poller_handler_try_default_pass(MfUltralightPoll
|
||||
MF_ULTRALIGHT_DEFAULT_PASSWORD,
|
||||
sizeof(MfUltralightAuthPassword),
|
||||
instance->auth_context.password.data);
|
||||
instance->error =
|
||||
mf_ultralight_poller_async_auth_pwd(instance, &instance->auth_context);
|
||||
instance->error = mf_ultralight_poller_auth_pwd(instance, &instance->auth_context);
|
||||
if(instance->error == MfUltralightErrorNone) {
|
||||
FURI_LOG_D(TAG, "Default password detected");
|
||||
nfc_util_num2bytes(
|
||||
@@ -576,8 +574,7 @@ static bool mf_ultralight_poller_detect(NfcGenericEvent event, void* context) {
|
||||
|
||||
if(iso14443_3a_event->type == Iso14443_3aPollerEventTypeReady) {
|
||||
MfUltralightPageReadCommandData read_page_cmd_data = {};
|
||||
MfUltralightError error =
|
||||
mf_ultralight_poller_async_read_page(instance, 0, &read_page_cmd_data);
|
||||
MfUltralightError error = mf_ultralight_poller_read_page(instance, 0, &read_page_cmd_data);
|
||||
protocol_detected = (error == MfUltralightErrorNone);
|
||||
iso14443_3a_poller_halt(instance->iso14443_3a_poller);
|
||||
}
|
||||
|
||||
@@ -7,35 +7,181 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief MfUltralightPoller opaque type definition.
|
||||
*/
|
||||
typedef struct MfUltralightPoller MfUltralightPoller;
|
||||
|
||||
/**
|
||||
* @brief Enumeration of possible MfUltralight poller event types.
|
||||
*/
|
||||
typedef enum {
|
||||
MfUltralightPollerEventTypeAuthRequest,
|
||||
MfUltralightPollerEventTypeAuthSuccess,
|
||||
MfUltralightPollerEventTypeAuthFailed,
|
||||
MfUltralightPollerEventTypeReadSuccess,
|
||||
MfUltralightPollerEventTypeReadFailed,
|
||||
MfUltralightPollerEventTypeAuthRequest, /**< Poller requests to fill authentication context. */
|
||||
MfUltralightPollerEventTypeAuthSuccess, /**< Authentication succeeded. */
|
||||
MfUltralightPollerEventTypeAuthFailed, /**< Authentication failed. */
|
||||
MfUltralightPollerEventTypeReadSuccess, /**< Poller read card successfully. */
|
||||
MfUltralightPollerEventTypeReadFailed, /**< Poller failed to read card. */
|
||||
} MfUltralightPollerEventType;
|
||||
|
||||
/**
|
||||
* @brief MfUltralight poller authentication context.
|
||||
*/
|
||||
typedef struct {
|
||||
MfUltralightAuthPassword password;
|
||||
MfUltralightAuthPack pack;
|
||||
bool auth_success;
|
||||
bool skip_auth;
|
||||
MfUltralightAuthPassword password; /**< Password to be used for authentication. */
|
||||
MfUltralightAuthPack pack; /**< Pack received on successfull authentication. */
|
||||
bool auth_success; /**< Set to true if authentication succeeded, false otherwise. */
|
||||
bool skip_auth; /**< Set to true if authentication should be skipped, false otherwise. */
|
||||
} MfUltralightPollerAuthContext;
|
||||
|
||||
typedef struct {
|
||||
union {
|
||||
MfUltralightPollerAuthContext auth_context;
|
||||
MfUltralightError error;
|
||||
};
|
||||
/**
|
||||
* @brief MfUltralight poller event data.
|
||||
*/
|
||||
typedef union {
|
||||
MfUltralightPollerAuthContext auth_context; /**< Authentication context. */
|
||||
MfUltralightError error; /**< Error code indicating reading fail reason. */
|
||||
} MfUltralightPollerEventData;
|
||||
|
||||
/**
|
||||
* @brief MfUltralight poller event structure.
|
||||
*
|
||||
* Upon emission of an event, an instance of this struct will be passed to the callback.
|
||||
*/
|
||||
typedef struct {
|
||||
MfUltralightPollerEventType type;
|
||||
MfUltralightPollerEventData* data;
|
||||
MfUltralightPollerEventType type; /**< Type of emmitted event. */
|
||||
MfUltralightPollerEventData* data; /**< Pointer to event specific data. */
|
||||
} MfUltralightPollerEvent;
|
||||
|
||||
/**
|
||||
* @brief Perform authentication with password.
|
||||
*
|
||||
* Must ONLY be used inside the callback function.
|
||||
*
|
||||
* @param[in, out] instance pointer to the instance to be used in the transaction.
|
||||
* @param[in, out] data pointer to the authentication context.
|
||||
* @return MfUltralightErrorNone on success, an error code on failure.
|
||||
*/
|
||||
MfUltralightError mf_ultralight_poller_auth_pwd(
|
||||
MfUltralightPoller* instance,
|
||||
MfUltralightPollerAuthContext* data);
|
||||
|
||||
/**
|
||||
* @brief Start authentication procedure.
|
||||
*
|
||||
* Must ONLY be used inside the callback function.
|
||||
*
|
||||
* This function now is used only to identify Mf Ultralight C cards.
|
||||
*
|
||||
* @param[in, out] instance pointer to the instance to be used in the transaction.
|
||||
* @return MfUltralightErrorNone if card supports authentication command, an error code on otherwise.
|
||||
*/
|
||||
MfUltralightError mf_ultralight_poller_authenticate(MfUltralightPoller* instance);
|
||||
|
||||
/**
|
||||
* @brief Read page from card.
|
||||
*
|
||||
* Must ONLY be used inside the callback function.
|
||||
*
|
||||
* Send read command and parse response. The response on this command is data of 4 pages starting
|
||||
* from the page specified in the command.
|
||||
*
|
||||
* @param[in, out] instance pointer to the instance to be used in the transaction.
|
||||
* @param[in] start_page page number to be read.
|
||||
* @param[out] data pointer to the MfUltralightPageReadCommandData structure to be filled with page data.
|
||||
* @return MfUltralightErrorNone on success, an error code on failure.
|
||||
*/
|
||||
MfUltralightError mf_ultralight_poller_read_page(
|
||||
MfUltralightPoller* instance,
|
||||
uint8_t start_page,
|
||||
MfUltralightPageReadCommandData* data);
|
||||
|
||||
/**
|
||||
* @brief Read page from sector.
|
||||
*
|
||||
* Must ONLY be used inside the callback function.
|
||||
*
|
||||
* This command should be used for NTAGI2C tags.
|
||||
*
|
||||
* @param[in, out] instance pointer to the instance to be used in the transaction.
|
||||
* @param[in] sector sector number to be read.
|
||||
* @param[in] tag tag number to be read.
|
||||
* @param[out] data pointer to the MfUltralightPageReadCommandData structure to be filled with page data.
|
||||
* @return MfUltralightErrorNone on success, an error code on failure.
|
||||
*/
|
||||
MfUltralightError mf_ultralight_poller_read_page_from_sector(
|
||||
MfUltralightPoller* instance,
|
||||
uint8_t sector,
|
||||
uint8_t tag,
|
||||
MfUltralightPageReadCommandData* data);
|
||||
|
||||
/**
|
||||
* @brief Write page to card.
|
||||
*
|
||||
* Must ONLY be used inside the callback function.
|
||||
*
|
||||
* @param[in, out] instance pointer to the instance to be used in the transaction.
|
||||
* @param[in] page page number to be written.
|
||||
* @param[in] data pointer to the MfUltralightPage structure to be written.
|
||||
* @return MfUltralightErrorNone on success, an error code on failure.
|
||||
*/
|
||||
MfUltralightError mf_ultralight_poller_write_page(
|
||||
MfUltralightPoller* instance,
|
||||
uint8_t page,
|
||||
const MfUltralightPage* data);
|
||||
|
||||
/**
|
||||
* @brief Read version from card.
|
||||
*
|
||||
* 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 MfUltralightVersion structure to be filled.
|
||||
* @return MfUltralightErrorNone on success, an error code on failure.
|
||||
*/
|
||||
MfUltralightError
|
||||
mf_ultralight_poller_read_version(MfUltralightPoller* instance, MfUltralightVersion* data);
|
||||
|
||||
/**
|
||||
* @brief Read signature from card.
|
||||
*
|
||||
* 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 MfUltralightSignature structure to be filled.
|
||||
* @return MfUltralightErrorNone on success, an error code on failure.
|
||||
*/
|
||||
MfUltralightError
|
||||
mf_ultralight_poller_read_signature(MfUltralightPoller* instance, MfUltralightSignature* data);
|
||||
|
||||
/**
|
||||
* @brief Read counter from card.
|
||||
*
|
||||
* Must ONLY be used inside the callback function.
|
||||
*
|
||||
* @param[in, out] instance pointer to the instance to be used in the transaction.
|
||||
* @param[in] counter_num counter number to be read.
|
||||
* @param[out] data pointer to the MfUltralightCounter structure to be filled.
|
||||
* @return MfUltralightErrorNone on success, an error code on failure.
|
||||
*/
|
||||
MfUltralightError mf_ultralight_poller_read_counter(
|
||||
MfUltralightPoller* instance,
|
||||
uint8_t counter_num,
|
||||
MfUltralightCounter* data);
|
||||
|
||||
/**
|
||||
* @brief Read tearing flag from card.
|
||||
*
|
||||
* Must ONLY be used inside the callback function.
|
||||
*
|
||||
* @param[in, out] instance pointer to the instance to be used in the transaction.
|
||||
* @param[in] tearing_falg_num tearing flag number to be read.
|
||||
* @param[out] data pointer to the MfUltralightTearingFlag structure to be filled.
|
||||
* @return MfUltralightErrorNone on success, an error code on failure.
|
||||
*/
|
||||
MfUltralightError mf_ultralight_poller_read_tearing_flag(
|
||||
MfUltralightPoller* instance,
|
||||
uint8_t tearing_falg_num,
|
||||
MfUltralightTearingFlag* data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -30,7 +30,7 @@ MfUltralightError mf_ultralight_process_error(Iso14443_3aError error) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
MfUltralightError mf_ultralight_poller_async_auth_pwd(
|
||||
MfUltralightError mf_ultralight_poller_auth_pwd(
|
||||
MfUltralightPoller* instance,
|
||||
MfUltralightPollerAuthContext* data) {
|
||||
uint8_t auth_cmd[5] = {MF_ULTRALIGHT_CMD_PWD_AUTH}; //-V1009
|
||||
@@ -59,7 +59,7 @@ MfUltralightError mf_ultralight_poller_async_auth_pwd(
|
||||
return ret;
|
||||
}
|
||||
|
||||
MfUltralightError mf_ultralight_poller_async_authenticate(MfUltralightPoller* instance) {
|
||||
MfUltralightError mf_ultralight_poller_authenticate(MfUltralightPoller* instance) {
|
||||
uint8_t auth_cmd[2] = {MF_ULTRALIGHT_CMD_AUTH, 0x00};
|
||||
bit_buffer_copy_bytes(instance->tx_buffer, auth_cmd, sizeof(auth_cmd));
|
||||
|
||||
@@ -86,7 +86,7 @@ MfUltralightError mf_ultralight_poller_async_authenticate(MfUltralightPoller* in
|
||||
return ret;
|
||||
}
|
||||
|
||||
MfUltralightError mf_ultralight_poller_async_read_page_from_sector(
|
||||
MfUltralightError mf_ultralight_poller_read_page_from_sector(
|
||||
MfUltralightPoller* instance,
|
||||
uint8_t sector,
|
||||
uint8_t tag,
|
||||
@@ -122,13 +122,13 @@ MfUltralightError mf_ultralight_poller_async_read_page_from_sector(
|
||||
break;
|
||||
}
|
||||
|
||||
ret = mf_ultralight_poller_async_read_page(instance, tag, data);
|
||||
ret = mf_ultralight_poller_read_page(instance, tag, data);
|
||||
} while(false);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
MfUltralightError mf_ultralight_poller_async_read_page(
|
||||
MfUltralightError mf_ultralight_poller_read_page(
|
||||
MfUltralightPoller* instance,
|
||||
uint8_t start_page,
|
||||
MfUltralightPageReadCommandData* data) {
|
||||
@@ -158,10 +158,10 @@ MfUltralightError mf_ultralight_poller_async_read_page(
|
||||
return ret;
|
||||
}
|
||||
|
||||
MfUltralightError mf_ultralight_poller_async_write_page(
|
||||
MfUltralightError mf_ultralight_poller_write_page(
|
||||
MfUltralightPoller* instance,
|
||||
uint8_t page,
|
||||
MfUltralightPage* data) {
|
||||
const MfUltralightPage* data) {
|
||||
MfUltralightError ret = MfUltralightErrorNone;
|
||||
Iso14443_3aError error = Iso14443_3aErrorNone;
|
||||
|
||||
@@ -191,9 +191,8 @@ MfUltralightError mf_ultralight_poller_async_write_page(
|
||||
return ret;
|
||||
}
|
||||
|
||||
MfUltralightError mf_ultralight_poller_async_read_version(
|
||||
MfUltralightPoller* instance,
|
||||
MfUltralightVersion* data) {
|
||||
MfUltralightError
|
||||
mf_ultralight_poller_read_version(MfUltralightPoller* instance, MfUltralightVersion* data) {
|
||||
MfUltralightError ret = MfUltralightErrorNone;
|
||||
Iso14443_3aError error = Iso14443_3aErrorNone;
|
||||
|
||||
@@ -221,9 +220,8 @@ MfUltralightError mf_ultralight_poller_async_read_version(
|
||||
return ret;
|
||||
}
|
||||
|
||||
MfUltralightError mf_ultralight_poller_async_read_signature(
|
||||
MfUltralightPoller* instance,
|
||||
MfUltralightSignature* data) {
|
||||
MfUltralightError
|
||||
mf_ultralight_poller_read_signature(MfUltralightPoller* instance, MfUltralightSignature* data) {
|
||||
MfUltralightError ret = MfUltralightErrorNone;
|
||||
Iso14443_3aError error = Iso14443_3aErrorNone;
|
||||
|
||||
@@ -249,7 +247,7 @@ MfUltralightError mf_ultralight_poller_async_read_signature(
|
||||
return ret;
|
||||
}
|
||||
|
||||
MfUltralightError mf_ultralight_poller_async_read_counter(
|
||||
MfUltralightError mf_ultralight_poller_read_counter(
|
||||
MfUltralightPoller* instance,
|
||||
uint8_t counter_num,
|
||||
MfUltralightCounter* data) {
|
||||
@@ -278,7 +276,7 @@ MfUltralightError mf_ultralight_poller_async_read_counter(
|
||||
return ret;
|
||||
}
|
||||
|
||||
MfUltralightError mf_ultralight_poller_async_read_tearing_flag(
|
||||
MfUltralightError mf_ultralight_poller_read_tearing_flag(
|
||||
MfUltralightPoller* instance,
|
||||
uint8_t tearing_falg_num,
|
||||
MfUltralightTearingFlag* data) {
|
||||
|
||||
@@ -103,46 +103,6 @@ bool mf_ultralight_poller_ntag_i2c_addr_lin_to_tag(
|
||||
uint8_t* tag,
|
||||
uint8_t* pages_left);
|
||||
|
||||
MfUltralightError mf_ultralight_poller_async_auth_pwd(
|
||||
MfUltralightPoller* instance,
|
||||
MfUltralightPollerAuthContext* data);
|
||||
|
||||
MfUltralightError mf_ultralight_poller_async_authenticate(MfUltralightPoller* instance);
|
||||
|
||||
MfUltralightError mf_ultralight_poller_async_read_page(
|
||||
MfUltralightPoller* instance,
|
||||
uint8_t start_page,
|
||||
MfUltralightPageReadCommandData* data);
|
||||
|
||||
MfUltralightError mf_ultralight_poller_async_read_page_from_sector(
|
||||
MfUltralightPoller* instance,
|
||||
uint8_t sector,
|
||||
uint8_t tag,
|
||||
MfUltralightPageReadCommandData* data);
|
||||
|
||||
MfUltralightError mf_ultralight_poller_async_write_page(
|
||||
MfUltralightPoller* instance,
|
||||
uint8_t page,
|
||||
MfUltralightPage* data);
|
||||
|
||||
MfUltralightError mf_ultralight_poller_async_read_version(
|
||||
MfUltralightPoller* instance,
|
||||
MfUltralightVersion* data);
|
||||
|
||||
MfUltralightError mf_ultralight_poller_async_read_signature(
|
||||
MfUltralightPoller* instance,
|
||||
MfUltralightSignature* data);
|
||||
|
||||
MfUltralightError mf_ultralight_poller_async_read_counter(
|
||||
MfUltralightPoller* instance,
|
||||
uint8_t counter_num,
|
||||
MfUltralightCounter* data);
|
||||
|
||||
MfUltralightError mf_ultralight_poller_async_read_tearing_flag(
|
||||
MfUltralightPoller* instance,
|
||||
uint8_t tearing_falg_num,
|
||||
MfUltralightTearingFlag* data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
+25
-26
@@ -1,3 +1,4 @@
|
||||
#include "mf_ultralight_poller_sync.h"
|
||||
#include "mf_ultralight_poller_i.h"
|
||||
|
||||
#include <nfc/nfc_poller.h>
|
||||
@@ -31,40 +32,39 @@ typedef MfUltralightError (*MfUltralightPollerCmdHandler)(
|
||||
MfUltralightError mf_ultralight_poller_read_page_handler(
|
||||
MfUltralightPoller* poller,
|
||||
MfUltralightPollerContextData* data) {
|
||||
return mf_ultralight_poller_async_read_page(
|
||||
poller, data->read_cmd.start_page, &data->read_cmd.data);
|
||||
return mf_ultralight_poller_read_page(poller, data->read_cmd.start_page, &data->read_cmd.data);
|
||||
}
|
||||
|
||||
MfUltralightError mf_ultralight_poller_write_page_handler(
|
||||
MfUltralightPoller* poller,
|
||||
MfUltralightPollerContextData* data) {
|
||||
return mf_ultralight_poller_async_write_page(
|
||||
return mf_ultralight_poller_write_page(
|
||||
poller, data->write_cmd.page_to_write, &data->write_cmd.page);
|
||||
}
|
||||
|
||||
MfUltralightError mf_ultralight_poller_read_version_handler(
|
||||
MfUltralightPoller* poller,
|
||||
MfUltralightPollerContextData* data) {
|
||||
return mf_ultralight_poller_async_read_version(poller, &data->version);
|
||||
return mf_ultralight_poller_read_version(poller, &data->version);
|
||||
}
|
||||
|
||||
MfUltralightError mf_ultralight_poller_read_signature_handler(
|
||||
MfUltralightPoller* poller,
|
||||
MfUltralightPollerContextData* data) {
|
||||
return mf_ultralight_poller_async_read_signature(poller, &data->signature);
|
||||
return mf_ultralight_poller_read_signature(poller, &data->signature);
|
||||
}
|
||||
|
||||
MfUltralightError mf_ultralight_poller_read_counter_handler(
|
||||
MfUltralightPoller* poller,
|
||||
MfUltralightPollerContextData* data) {
|
||||
return mf_ultralight_poller_async_read_counter(
|
||||
return mf_ultralight_poller_read_counter(
|
||||
poller, data->counter_cmd.counter_num, &data->counter_cmd.data);
|
||||
}
|
||||
|
||||
MfUltralightError mf_ultralight_poller_read_tearing_flag_handler(
|
||||
MfUltralightPoller* poller,
|
||||
MfUltralightPollerContextData* data) {
|
||||
return mf_ultralight_poller_async_read_tearing_flag(
|
||||
return mf_ultralight_poller_read_tearing_flag(
|
||||
poller, data->tearing_flag_cmd.tearing_flag_num, &data->tearing_flag_cmd.data);
|
||||
}
|
||||
|
||||
@@ -79,16 +79,14 @@ static const MfUltralightPollerCmdHandler
|
||||
mf_ultralight_poller_read_tearing_flag_handler,
|
||||
};
|
||||
|
||||
static NfcCommand mf_ultralight_poller_cmd_callback(NfcGenericEvent event, void* context) {
|
||||
furi_assert(event.instance);
|
||||
furi_assert(event.protocol == NfcProtocolIso14443_3a);
|
||||
furi_assert(event.event_data);
|
||||
static NfcCommand mf_ultralight_poller_cmd_callback(NfcGenericEventEx event, void* context) {
|
||||
furi_assert(event.poller);
|
||||
furi_assert(event.parent_event_data);
|
||||
furi_assert(context);
|
||||
|
||||
MfUltralightPollerContext* poller_context = context;
|
||||
Iso14443_3aPollerEvent* iso14443_3a_event = event.event_data;
|
||||
Iso14443_3aPoller* iso14443_3a_poller = event.instance;
|
||||
MfUltralightPoller* mfu_poller = mf_ultralight_poller_alloc(iso14443_3a_poller);
|
||||
Iso14443_3aPollerEvent* iso14443_3a_event = event.parent_event_data;
|
||||
MfUltralightPoller* mfu_poller = event.poller;
|
||||
|
||||
if(iso14443_3a_event->type == Iso14443_3aPollerEventTypeReady) {
|
||||
poller_context->error = mf_ultralight_poller_cmd_handlers[poller_context->cmd_type](
|
||||
@@ -99,8 +97,6 @@ static NfcCommand mf_ultralight_poller_cmd_callback(NfcGenericEvent event, void*
|
||||
|
||||
furi_thread_flags_set(poller_context->thread_id, MF_ULTRALIGHT_POLLER_COMPLETE_EVENT);
|
||||
|
||||
mf_ultralight_poller_free(mfu_poller);
|
||||
|
||||
return NfcCommandStop;
|
||||
}
|
||||
|
||||
@@ -110,8 +106,8 @@ static MfUltralightError
|
||||
|
||||
poller_ctx->thread_id = furi_thread_get_current_id();
|
||||
|
||||
NfcPoller* poller = nfc_poller_alloc(nfc, NfcProtocolIso14443_3a);
|
||||
nfc_poller_start(poller, mf_ultralight_poller_cmd_callback, poller_ctx);
|
||||
NfcPoller* poller = nfc_poller_alloc(nfc, NfcProtocolMfUltralight);
|
||||
nfc_poller_start_ex(poller, mf_ultralight_poller_cmd_callback, poller_ctx);
|
||||
furi_thread_flags_wait(MF_ULTRALIGHT_POLLER_COMPLETE_EVENT, FuriFlagWaitAny, FuriWaitForever);
|
||||
furi_thread_flags_clear(MF_ULTRALIGHT_POLLER_COMPLETE_EVENT);
|
||||
|
||||
@@ -121,7 +117,8 @@ static MfUltralightError
|
||||
return poller_ctx->error;
|
||||
}
|
||||
|
||||
MfUltralightError mf_ultralight_poller_read_page(Nfc* nfc, uint16_t page, MfUltralightPage* data) {
|
||||
MfUltralightError
|
||||
mf_ultralight_poller_sync_read_page(Nfc* nfc, uint16_t page, MfUltralightPage* data) {
|
||||
furi_assert(nfc);
|
||||
furi_assert(data);
|
||||
|
||||
@@ -140,7 +137,7 @@ MfUltralightError mf_ultralight_poller_read_page(Nfc* nfc, uint16_t page, MfUltr
|
||||
}
|
||||
|
||||
MfUltralightError
|
||||
mf_ultralight_poller_write_page(Nfc* nfc, uint16_t page, MfUltralightPage* data) {
|
||||
mf_ultralight_poller_sync_write_page(Nfc* nfc, uint16_t page, MfUltralightPage* data) {
|
||||
furi_assert(nfc);
|
||||
furi_assert(data);
|
||||
|
||||
@@ -158,7 +155,7 @@ MfUltralightError
|
||||
return error;
|
||||
}
|
||||
|
||||
MfUltralightError mf_ultralight_poller_read_version(Nfc* nfc, MfUltralightVersion* data) {
|
||||
MfUltralightError mf_ultralight_poller_sync_read_version(Nfc* nfc, MfUltralightVersion* data) {
|
||||
furi_assert(nfc);
|
||||
furi_assert(data);
|
||||
|
||||
@@ -175,7 +172,7 @@ MfUltralightError mf_ultralight_poller_read_version(Nfc* nfc, MfUltralightVersio
|
||||
return error;
|
||||
}
|
||||
|
||||
MfUltralightError mf_ultralight_poller_read_signature(Nfc* nfc, MfUltralightSignature* data) {
|
||||
MfUltralightError mf_ultralight_poller_sync_read_signature(Nfc* nfc, MfUltralightSignature* data) {
|
||||
furi_assert(nfc);
|
||||
furi_assert(data);
|
||||
|
||||
@@ -192,8 +189,10 @@ MfUltralightError mf_ultralight_poller_read_signature(Nfc* nfc, MfUltralightSign
|
||||
return error;
|
||||
}
|
||||
|
||||
MfUltralightError
|
||||
mf_ultralight_poller_read_counter(Nfc* nfc, uint8_t counter_num, MfUltralightCounter* data) {
|
||||
MfUltralightError mf_ultralight_poller_sync_read_counter(
|
||||
Nfc* nfc,
|
||||
uint8_t counter_num,
|
||||
MfUltralightCounter* data) {
|
||||
furi_assert(nfc);
|
||||
furi_assert(data);
|
||||
|
||||
@@ -211,7 +210,7 @@ MfUltralightError
|
||||
return error;
|
||||
}
|
||||
|
||||
MfUltralightError mf_ultralight_poller_read_tearing_flag(
|
||||
MfUltralightError mf_ultralight_poller_sync_read_tearing_flag(
|
||||
Nfc* nfc,
|
||||
uint8_t flag_num,
|
||||
MfUltralightTearingFlag* data) {
|
||||
@@ -261,7 +260,7 @@ static NfcCommand mf_ultralight_poller_read_callback(NfcGenericEvent event, void
|
||||
return command;
|
||||
}
|
||||
|
||||
MfUltralightError mf_ultralight_poller_read_card(Nfc* nfc, MfUltralightData* data) {
|
||||
MfUltralightError mf_ultralight_poller_sync_read_card(Nfc* nfc, MfUltralightData* data) {
|
||||
furi_assert(nfc);
|
||||
furi_assert(data);
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#include "mf_ultralight.h"
|
||||
#include <nfc/nfc.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
MfUltralightError
|
||||
mf_ultralight_poller_sync_read_page(Nfc* nfc, uint16_t page, MfUltralightPage* data);
|
||||
|
||||
MfUltralightError
|
||||
mf_ultralight_poller_sync_write_page(Nfc* nfc, uint16_t page, MfUltralightPage* data);
|
||||
|
||||
MfUltralightError mf_ultralight_poller_sync_read_version(Nfc* nfc, MfUltralightVersion* data);
|
||||
|
||||
MfUltralightError mf_ultralight_poller_sync_read_signature(Nfc* nfc, MfUltralightSignature* data);
|
||||
|
||||
MfUltralightError mf_ultralight_poller_sync_read_counter(
|
||||
Nfc* nfc,
|
||||
uint8_t counter_num,
|
||||
MfUltralightCounter* data);
|
||||
|
||||
MfUltralightError mf_ultralight_poller_sync_read_tearing_flag(
|
||||
Nfc* nfc,
|
||||
uint8_t flag_num,
|
||||
MfUltralightTearingFlag* data);
|
||||
|
||||
MfUltralightError mf_ultralight_poller_sync_read_card(Nfc* nfc, MfUltralightData* data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -1,30 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "mf_ultralight.h"
|
||||
#include <nfc/nfc.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
MfUltralightError mf_ultralight_poller_read_page(Nfc* nfc, uint16_t page, MfUltralightPage* data);
|
||||
|
||||
MfUltralightError mf_ultralight_poller_write_page(Nfc* nfc, uint16_t page, MfUltralightPage* data);
|
||||
|
||||
MfUltralightError mf_ultralight_poller_read_version(Nfc* nfc, MfUltralightVersion* data);
|
||||
|
||||
MfUltralightError mf_ultralight_poller_read_signature(Nfc* nfc, MfUltralightSignature* data);
|
||||
|
||||
MfUltralightError
|
||||
mf_ultralight_poller_read_counter(Nfc* nfc, uint8_t counter_num, MfUltralightCounter* data);
|
||||
|
||||
MfUltralightError mf_ultralight_poller_read_tearing_flag(
|
||||
Nfc* nfc,
|
||||
uint8_t flag_num,
|
||||
MfUltralightTearingFlag* data);
|
||||
|
||||
MfUltralightError mf_ultralight_poller_read_card(Nfc* nfc, MfUltralightData* data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user