mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2024-12-24 05:48:08 +03:00
6a5d63803a
* New scenes for ultralight poller write mode * Added new button and transition logic for write operation For now write is only possible for NTAG21x cards with default password and no AUTHLIM set * Poller states extended * Enums and datatypes extended for new poller mode * Added mode field to poller instance datatype * New states for poller added in order to implement write mode * Added new event type for locked cards in order to simplify state flow * New logic for poller write commands * Scenes adjustments * Scenes renamed * New field added to poller instance * Now we write in 'page per call' mode * Now function takes callback return value into account * Callback will be called only in write mode * Event type added * Log adjusted and start page to write set * Logs added and check in now false at start, then it moves to true * Now mf_ultralight_poller_handler_request_write_data halts card in case of check failure and stops poller * All fail events now returns NfcCommandStop callback * In case of fail we move back properly * Remove garbage Co-authored-by: gornekich <n.gorbadey@gmail.com> Co-authored-by: あく <alleteam@gmail.com>
204 lines
7.5 KiB
C
204 lines
7.5 KiB
C
#pragma once
|
|
|
|
#include "mf_ultralight.h"
|
|
#include <lib/nfc/protocols/iso14443_3a/iso14443_3a_poller.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/**
|
|
* @brief MfUltralightPoller opaque type definition.
|
|
*/
|
|
typedef struct MfUltralightPoller MfUltralightPoller;
|
|
|
|
/**
|
|
* @brief Enumeration of possible MfUltralight poller event types.
|
|
*/
|
|
typedef enum {
|
|
MfUltralightPollerEventTypeRequestMode, /**< Poller requests for operating mode. */
|
|
MfUltralightPollerEventTypeAuthRequest, /**< Poller requests to fill authentication context. */
|
|
MfUltralightPollerEventTypeAuthSuccess, /**< Authentication succeeded. */
|
|
MfUltralightPollerEventTypeAuthFailed, /**< Authentication failed. */
|
|
MfUltralightPollerEventTypeReadSuccess, /**< Poller read card successfully. */
|
|
MfUltralightPollerEventTypeReadFailed, /**< Poller failed to read card. */
|
|
MfUltralightPollerEventTypeRequestWriteData, /**< Poller request card data for write operation. */
|
|
MfUltralightPollerEventTypeCardMismatch, /**< Type of card for writing differs from presented one. */
|
|
MfUltralightPollerEventTypeCardLocked, /**< Presented card is locked by password, AUTH0 or lock bytes. */
|
|
MfUltralightPollerEventTypeWriteSuccess, /**< Poller wrote card successfully. */
|
|
MfUltralightPollerEventTypeWriteFail, /**< Poller failed to write card. */
|
|
} MfUltralightPollerEventType;
|
|
|
|
/**
|
|
* @brief Enumeration of possible MfUltralight poller operating modes.
|
|
*/
|
|
typedef enum {
|
|
MfUltralightPollerModeRead, /**< Poller will only read card. It's a default mode. */
|
|
MfUltralightPollerModeWrite, /**< Poller will write already saved card to another presented card. */
|
|
} MfUltralightPollerMode;
|
|
|
|
/**
|
|
* @brief MfUltralight poller authentication context.
|
|
*/
|
|
typedef struct {
|
|
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;
|
|
|
|
/**
|
|
* @brief MfUltralight poller event data.
|
|
*/
|
|
typedef union {
|
|
MfUltralightPollerAuthContext auth_context; /**< Authentication context. */
|
|
MfUltralightError error; /**< Error code indicating reading fail reason. */
|
|
const MfUltralightData* write_data;
|
|
MfUltralightPollerMode poller_mode;
|
|
} 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; /**< 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
|