mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2024-12-20 03:41:42 +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>
116 lines
3.4 KiB
C
116 lines
3.4 KiB
C
#pragma once
|
|
|
|
#include "mf_ultralight_poller.h"
|
|
#include <lib/nfc/protocols/iso14443_3a/iso14443_3a_poller_i.h>
|
|
#include <lib/nfc/helpers/nfc_util.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#define MF_ULTRALIGHT_POLLER_STANDARD_FWT_FC (60000)
|
|
#define MF_ULTRALIGHT_MAX_BUFF_SIZE (64)
|
|
|
|
#define MF_ULTRALIGHT_DEFAULT_PASSWORD (0xffffffffUL)
|
|
|
|
#define MF_ULTRALIGHT_IS_NTAG_I2C(type) \
|
|
(((type) == MfUltralightTypeNTAGI2C1K) || ((type) == MfUltralightTypeNTAGI2C2K) || \
|
|
((type) == MfUltralightTypeNTAGI2CPlus1K) || ((type) == MfUltralightTypeNTAGI2CPlus2K))
|
|
|
|
typedef struct {
|
|
MfUltralightPage page;
|
|
uint8_t page_to_write;
|
|
} MfUltralightPollerWritePageCommand;
|
|
|
|
typedef struct {
|
|
MfUltralightPageReadCommandData data;
|
|
uint8_t start_page;
|
|
} MfUltralightPollerReadPageCommand;
|
|
|
|
typedef struct {
|
|
MfUltralightCounter data;
|
|
uint8_t counter_num;
|
|
} MfUltralightPollerReadCounterCommand;
|
|
|
|
typedef struct {
|
|
MfUltralightTearingFlag data;
|
|
uint8_t tearing_flag_num;
|
|
} MfUltralightPollerReadTearingFlagCommand;
|
|
|
|
typedef union {
|
|
MfUltralightPollerWritePageCommand write_cmd;
|
|
MfUltralightPollerReadPageCommand read_cmd;
|
|
MfUltralightVersion version;
|
|
MfUltralightSignature signature;
|
|
MfUltralightPollerReadCounterCommand counter_cmd;
|
|
MfUltralightPollerReadTearingFlagCommand tearing_flag_cmd;
|
|
MfUltralightData* data;
|
|
} MfUltralightPollerContextData;
|
|
|
|
typedef enum {
|
|
MfUltralightPollerStateIdle,
|
|
MfUltralightPollerStateRequestMode,
|
|
MfUltralightPollerStateReadVersion,
|
|
MfUltralightPollerStateDetectMfulC,
|
|
MfUltralightPollerStateDetectNtag203,
|
|
MfUltralightPollerStateGetFeatureSet,
|
|
MfUltralightPollerStateReadSignature,
|
|
MfUltralightPollerStateReadCounters,
|
|
MfUltralightPollerStateReadTearingFlags,
|
|
MfUltralightPollerStateAuth,
|
|
MfUltralightPollerStateReadPages,
|
|
MfUltralightPollerStateTryDefaultPass,
|
|
MfUltralightPollerStateReadFailed,
|
|
MfUltralightPollerStateReadSuccess,
|
|
MfUltralightPollerStateRequestWriteData,
|
|
MfUltralightPollerStateWritePages,
|
|
MfUltralightPollerStateWriteFail,
|
|
MfUltralightPollerStateWriteSuccess,
|
|
|
|
MfUltralightPollerStateNum,
|
|
} MfUltralightPollerState;
|
|
|
|
struct MfUltralightPoller {
|
|
Iso14443_3aPoller* iso14443_3a_poller;
|
|
MfUltralightPollerState state;
|
|
MfUltralightPollerMode mode;
|
|
BitBuffer* tx_buffer;
|
|
BitBuffer* rx_buffer;
|
|
MfUltralightData* data;
|
|
MfUltralightPollerAuthContext auth_context;
|
|
uint32_t feature_set;
|
|
uint16_t pages_read;
|
|
uint16_t pages_total;
|
|
uint8_t counters_read;
|
|
uint8_t counters_total;
|
|
uint8_t tearing_flag_read;
|
|
uint8_t tearing_flag_total;
|
|
uint16_t current_page;
|
|
MfUltralightError error;
|
|
|
|
NfcGenericEvent general_event;
|
|
MfUltralightPollerEvent mfu_event;
|
|
MfUltralightPollerEventData mfu_event_data;
|
|
NfcGenericCallback callback;
|
|
void* context;
|
|
};
|
|
|
|
MfUltralightError mf_ultralight_process_error(Iso14443_3aError error);
|
|
|
|
MfUltralightPoller* mf_ultralight_poller_alloc(Iso14443_3aPoller* iso14443_3a_poller);
|
|
|
|
void mf_ultralight_poller_free(MfUltralightPoller* instance);
|
|
|
|
const MfUltralightData* mf_ultralight_poller_get_data(MfUltralightPoller* instance);
|
|
|
|
bool mf_ultralight_poller_ntag_i2c_addr_lin_to_tag(
|
|
MfUltralightPoller* instance,
|
|
uint16_t lin_addr,
|
|
uint8_t* sector,
|
|
uint8_t* tag,
|
|
uint8_t* pages_left);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|