[FL-662] Read Mifare Ultralight (#518)
* nfc: add read mifare ultralight to menu * emv_decoder: add pragma once * nfc: add mifare ultralight reader * nfc: add mifare ultralight read draw * nfc: add mifare ultralight type checker * nfc: rework menu callback * mifare ultralight: change type names Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
59
lib/nfc_protocols/mifare_ultralight.c
Normal file
59
lib/nfc_protocols/mifare_ultralight.c
Normal file
@@ -0,0 +1,59 @@
|
||||
#include "mifare_ultralight.h"
|
||||
|
||||
bool mf_ul_check_card_type(uint8_t ATQA0, uint8_t ATQA1, uint8_t SAK) {
|
||||
if((ATQA0 == 0x44) && (ATQA1 == 0x00) && (SAK == 0x00)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
uint16_t mf_ul_prepare_get_version(uint8_t* dest) {
|
||||
dest[0] = MF_UL_GET_VERSION_CMD;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void mf_ul_parse_get_version_response(uint8_t* buff, MfUltralightRead* mf_ul_read) {
|
||||
MfUltralightVersion* version = (MfUltralightVersion*) buff;
|
||||
if(version->storage_size == 0x0B || version->storage_size == 0x00) {
|
||||
mf_ul_read->type = MfUltralightTypeUL11;
|
||||
mf_ul_read->pages_to_read = 20;
|
||||
mf_ul_read->support_fast_read = true;
|
||||
} else if(version->storage_size == 0x0E) {
|
||||
mf_ul_read->type = MfUltralightTypeUL21;
|
||||
mf_ul_read->pages_to_read = 41;
|
||||
mf_ul_read->support_fast_read = true;
|
||||
} else if(version->storage_size == 0x0F) {
|
||||
mf_ul_read->type = MfUltralightTypeNTAG213;
|
||||
mf_ul_read->pages_to_read = 45;
|
||||
mf_ul_read->support_fast_read = false;
|
||||
} else if(version->storage_size == 0x11) {
|
||||
mf_ul_read->type = MfUltralightTypeNTAG215;
|
||||
mf_ul_read->pages_to_read = 135;
|
||||
mf_ul_read->support_fast_read = false;
|
||||
} else if(version->storage_size == 0x13) {
|
||||
mf_ul_read->type = MfUltralightTypeNTAG216;
|
||||
mf_ul_read->pages_to_read = 231;
|
||||
mf_ul_read->support_fast_read = false;
|
||||
} else {
|
||||
mf_ul_set_default_version(mf_ul_read);
|
||||
}
|
||||
}
|
||||
|
||||
void mf_ul_set_default_version(MfUltralightRead* mf_ul_read) {
|
||||
mf_ul_read->type = MfUltralightTypeUnknown;
|
||||
mf_ul_read->pages_to_read = 20;
|
||||
mf_ul_read->support_fast_read = false;
|
||||
}
|
||||
|
||||
uint16_t mf_ul_prepare_read(uint8_t* dest, uint8_t start_page) {
|
||||
dest[0] = MF_UL_READ_CMD;
|
||||
dest[1] = start_page;
|
||||
return 2;
|
||||
}
|
||||
|
||||
uint16_t mf_ul_prepare_fast_read(uint8_t* dest, uint8_t start_page, uint8_t end_page) {
|
||||
dest[0] = MF_UL_FAST_READ_CMD;
|
||||
dest[1] = start_page;
|
||||
dest[2] = end_page;
|
||||
return 3;
|
||||
}
|
56
lib/nfc_protocols/mifare_ultralight.h
Normal file
56
lib/nfc_protocols/mifare_ultralight.h
Normal file
@@ -0,0 +1,56 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
#define MF_UL_GET_VERSION_CMD (0x60)
|
||||
#define MF_UL_READ_CMD (0x30)
|
||||
#define MF_UL_FAST_READ_CMD (0x3A)
|
||||
|
||||
typedef enum {
|
||||
MfUltralightTypeUnknown,
|
||||
MfUltralightTypeUL11,
|
||||
MfUltralightTypeUL21,
|
||||
MfUltralightTypeNTAG213,
|
||||
MfUltralightTypeNTAG215,
|
||||
MfUltralightTypeNTAG216,
|
||||
} 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 {
|
||||
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];
|
||||
} MfUltralightManufacturerBlock;
|
||||
|
||||
typedef struct {
|
||||
MfUltralightType type;
|
||||
uint8_t pages_to_read;
|
||||
uint8_t pages_readed;
|
||||
bool support_fast_read;
|
||||
uint8_t dump[255];
|
||||
} MfUltralightRead;
|
||||
|
||||
bool mf_ul_check_card_type(uint8_t ATQA0, uint8_t ATQA1, uint8_t SAK);
|
||||
|
||||
uint16_t mf_ul_prepare_get_version(uint8_t* dest);
|
||||
void mf_ul_parse_get_version_response(uint8_t* buff, MfUltralightRead* mf_ul_read);
|
||||
void mf_ul_set_default_version(MfUltralightRead* mf_ul_read);
|
||||
|
||||
uint16_t mf_ul_prepare_read(uint8_t* dest, uint8_t start_page);
|
||||
uint16_t mf_ul_prepare_fast_read(uint8_t* dest, uint8_t start_page, uint8_t end_page);
|
Reference in New Issue
Block a user