2021-06-15 17:54:09 +03:00
|
|
|
#pragma once
|
|
|
|
|
2022-04-19 18:23:58 +03:00
|
|
|
#include <furi_hal_nfc.h>
|
2021-06-15 17:54:09 +03:00
|
|
|
|
2021-10-05 08:14:19 +03:00
|
|
|
#define MF_UL_MAX_DUMP_SIZE 1024
|
2021-07-22 09:05:07 +03:00
|
|
|
|
|
|
|
#define MF_UL_TEARING_FLAG_DEFAULT (0xBD)
|
|
|
|
|
2021-12-21 15:33:17 +03:00
|
|
|
#define MF_UL_HALT_START (0x50)
|
2021-06-15 17:54:09 +03:00
|
|
|
#define MF_UL_GET_VERSION_CMD (0x60)
|
|
|
|
#define MF_UL_READ_CMD (0x30)
|
|
|
|
#define MF_UL_FAST_READ_CMD (0x3A)
|
2021-07-22 09:05:07 +03:00
|
|
|
#define MF_UL_WRITE (0xA2)
|
|
|
|
#define MF_UL_COMP_WRITE (0xA0)
|
|
|
|
#define MF_UL_READ_CNT (0x39)
|
|
|
|
#define MF_UL_INC_CNT (0xA5)
|
|
|
|
#define MF_UL_AUTH (0x1B)
|
|
|
|
#define MF_UL_READ_SIG (0x3C)
|
|
|
|
#define MF_UL_CHECK_TEARING (0x3E)
|
|
|
|
#define MF_UL_READ_VCSL (0x4B)
|
|
|
|
|
2021-06-15 17:54:09 +03:00
|
|
|
typedef enum {
|
|
|
|
MfUltralightTypeUnknown,
|
|
|
|
MfUltralightTypeUL11,
|
|
|
|
MfUltralightTypeUL21,
|
|
|
|
MfUltralightTypeNTAG213,
|
|
|
|
MfUltralightTypeNTAG215,
|
|
|
|
MfUltralightTypeNTAG216,
|
2021-12-21 15:33:17 +03:00
|
|
|
|
|
|
|
// Keep last for number of types calculation
|
|
|
|
MfUltralightTypeNum,
|
2021-06-15 17:54:09 +03:00
|
|
|
} MfUltralightType;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
uint8_t header;
|
|
|
|
uint8_t vendor_id;
|
|
|
|
uint8_t prod_type;
|
|
|
|
uint8_t prod_subtype;
|
|
|
|
uint8_t prod_ver_major;
|
|
|
|
uint8_t prod_ver_minor;
|
|
|
|
uint8_t storage_size;
|
|
|
|
uint8_t protocol_type;
|
|
|
|
} MfUltralightVersion;
|
|
|
|
|
|
|
|
typedef struct {
|
2022-01-05 19:10:18 +03:00
|
|
|
uint8_t sn0[3];
|
|
|
|
uint8_t btBCC0;
|
|
|
|
uint8_t sn1[4];
|
|
|
|
uint8_t btBCC1;
|
|
|
|
uint8_t internal;
|
|
|
|
uint8_t lock[2];
|
|
|
|
uint8_t otp[4];
|
2021-06-15 17:54:09 +03:00
|
|
|
} MfUltralightManufacturerBlock;
|
|
|
|
|
2021-07-22 09:05:07 +03:00
|
|
|
typedef struct {
|
2021-12-21 15:33:17 +03:00
|
|
|
MfUltralightType type;
|
2021-07-22 09:05:07 +03:00
|
|
|
MfUltralightVersion version;
|
|
|
|
uint8_t signature[32];
|
|
|
|
uint32_t counter[3];
|
|
|
|
uint8_t tearing[3];
|
|
|
|
uint16_t data_size;
|
|
|
|
uint8_t data[MF_UL_MAX_DUMP_SIZE];
|
2022-04-19 18:23:58 +03:00
|
|
|
} MfUltralightData;
|
2021-07-22 09:05:07 +03:00
|
|
|
|
2021-12-15 21:27:25 +03:00
|
|
|
typedef struct {
|
|
|
|
uint8_t pwd[4];
|
|
|
|
union {
|
|
|
|
uint8_t raw[2];
|
|
|
|
uint16_t value;
|
|
|
|
} pack;
|
2022-04-19 18:23:58 +03:00
|
|
|
} MfUltralightAuth;
|
2021-12-15 21:27:25 +03:00
|
|
|
|
2021-06-15 17:54:09 +03:00
|
|
|
typedef struct {
|
|
|
|
uint8_t pages_to_read;
|
2022-04-14 15:03:47 +03:00
|
|
|
uint8_t pages_read;
|
2021-06-15 17:54:09 +03:00
|
|
|
bool support_fast_read;
|
2022-04-28 19:09:52 +03:00
|
|
|
bool support_tearing_flags;
|
|
|
|
bool support_counters;
|
2022-04-19 18:23:58 +03:00
|
|
|
} MfUltralightReader;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
MfUltralightData data;
|
|
|
|
bool support_fast_read;
|
2021-08-17 00:45:04 +03:00
|
|
|
bool data_changed;
|
2021-12-21 15:33:17 +03:00
|
|
|
bool comp_write_cmd_started;
|
|
|
|
uint8_t comp_write_page_addr;
|
2022-04-19 18:23:58 +03:00
|
|
|
MfUltralightAuth* auth_data;
|
|
|
|
} MfUltralightEmulator;
|
2021-06-15 17:54:09 +03:00
|
|
|
|
|
|
|
bool mf_ul_check_card_type(uint8_t ATQA0, uint8_t ATQA1, uint8_t SAK);
|
|
|
|
|
2022-04-19 18:23:58 +03:00
|
|
|
bool mf_ultralight_read_version(
|
|
|
|
FuriHalNfcTxRxContext* tx_rx,
|
|
|
|
MfUltralightReader* reader,
|
|
|
|
MfUltralightData* data);
|
2021-07-22 09:05:07 +03:00
|
|
|
|
2022-04-19 18:23:58 +03:00
|
|
|
bool mf_ultralight_read_pages(
|
|
|
|
FuriHalNfcTxRxContext* tx_rx,
|
|
|
|
MfUltralightReader* reader,
|
|
|
|
MfUltralightData* data);
|
2021-07-22 09:05:07 +03:00
|
|
|
|
2022-04-19 18:23:58 +03:00
|
|
|
bool mf_ultralight_fast_read_pages(
|
|
|
|
FuriHalNfcTxRxContext* tx_rx,
|
|
|
|
MfUltralightReader* reader,
|
|
|
|
MfUltralightData* data);
|
2021-07-22 09:05:07 +03:00
|
|
|
|
2022-04-19 18:23:58 +03:00
|
|
|
bool mf_ultralight_read_signature(FuriHalNfcTxRxContext* tx_rx, MfUltralightData* data);
|
2021-07-22 09:05:07 +03:00
|
|
|
|
2022-04-19 18:23:58 +03:00
|
|
|
bool mf_ultralight_read_counters(FuriHalNfcTxRxContext* tx_rx, MfUltralightData* data);
|
2021-06-15 17:54:09 +03:00
|
|
|
|
2022-04-19 18:23:58 +03:00
|
|
|
bool mf_ultralight_read_tearing_flags(FuriHalNfcTxRxContext* tx_rx, MfUltralightData* data);
|
2021-07-22 09:05:07 +03:00
|
|
|
|
2022-04-19 18:23:58 +03:00
|
|
|
bool mf_ul_read_card(
|
|
|
|
FuriHalNfcTxRxContext* tx_rx,
|
|
|
|
MfUltralightReader* reader,
|
|
|
|
MfUltralightData* data);
|
2021-07-22 09:05:07 +03:00
|
|
|
|
2022-04-19 18:23:58 +03:00
|
|
|
void mf_ul_prepare_emulation(MfUltralightEmulator* emulator, MfUltralightData* data);
|
2021-07-22 09:05:07 +03:00
|
|
|
|
2022-02-02 22:59:28 +03:00
|
|
|
bool mf_ul_prepare_emulation_response(
|
2022-01-05 19:10:18 +03:00
|
|
|
uint8_t* buff_rx,
|
2022-02-02 22:59:28 +03:00
|
|
|
uint16_t buff_rx_len,
|
2022-01-05 19:10:18 +03:00
|
|
|
uint8_t* buff_tx,
|
2022-02-02 22:59:28 +03:00
|
|
|
uint16_t* buff_tx_len,
|
|
|
|
uint32_t* data_type,
|
2022-05-06 16:37:10 +03:00
|
|
|
void* context);
|