Skip to content

Commit

Permalink
nfc: NTAG203 support (#1383)
Browse files Browse the repository at this point in the history
* nfc: Fix original MFUL feature flags
* nfc: Add NTAG203 read support
* nfc: Update emulation lock byte handling for NTAG203
* nfc: Add NTAG203 counter emulation support
* nfc: Add NTAG203 tag generator
* nfc: Fix NTAG203 emulating GET_VERSION
* nfc: Fix MFUL version reading
* nfc: Complete NTAG203 counter emulation behavior
* nfc: Complete NTAG203 emulation
* nfc: Remove unnecessary init in MFUL emulation
* nfc: Add notes about MFUL type enum

Co-authored-by: gornekich <[email protected]>
Co-authored-by: あく <[email protected]>
  • Loading branch information
3 people authored Jul 25, 2022
1 parent 30820b8 commit f8e0ec4
Show file tree
Hide file tree
Showing 4 changed files with 236 additions and 56 deletions.
20 changes: 20 additions & 0 deletions applications/nfc/helpers/nfc_generators.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
static const uint8_t version_bytes_mf0ulx1[] = {0x00, 0x04, 0x03, 0x00, 0x01, 0x00, 0x00, 0x03};
static const uint8_t version_bytes_ntag21x[] = {0x00, 0x04, 0x04, 0x02, 0x01, 0x00, 0x00, 0x03};
static const uint8_t version_bytes_ntag_i2c[] = {0x00, 0x04, 0x04, 0x05, 0x02, 0x00, 0x00, 0x03};
static const uint8_t default_data_ntag203[] =
{0xE1, 0x10, 0x12, 0x00, 0x01, 0x03, 0xA0, 0x10, 0x44, 0x03, 0x00, 0xFE};
static const uint8_t default_data_ntag213[] = {0x01, 0x03, 0xA0, 0x0C, 0x34, 0x03, 0x00, 0xFE};
static const uint8_t default_data_ntag215_216[] = {0x03, 0x00, 0xFE};
static const uint8_t default_data_ntag_i2c[] = {0xE1, 0x10, 0x00, 0x00, 0x03, 0x00, 0xFE};
Expand Down Expand Up @@ -58,6 +60,18 @@ static void nfc_generate_mf_ul_orig(NfcDeviceData* data) {
memset(&mful->data[4 * 4], 0xFF, 4);
}

static void nfc_generate_mf_ul_ntag203(NfcDeviceData* data) {
nfc_generate_common_start(data);
nfc_generate_mf_ul_common(data);

MfUltralightData* mful = &data->mf_ul_data;
mful->type = MfUltralightTypeNTAG203;
mful->data_size = 42 * 4;
nfc_generate_mf_ul_copy_uid_with_bcc(data);
mful->data[9] = 0x48; // Internal byte
memcpy(&mful->data[3 * 4], default_data_ntag203, sizeof(default_data_ntag203));
}

static void nfc_generate_mf_ul_with_config_common(NfcDeviceData* data, uint8_t num_pages) {
nfc_generate_common_start(data);
nfc_generate_mf_ul_common(data);
Expand Down Expand Up @@ -275,6 +289,11 @@ static const NfcGenerator mf_ul_h21_generator = {
.generator_func = nfc_generate_mf_ul_h21,
.next_scene = NfcSceneMifareUlMenu};

static const NfcGenerator ntag203_generator = {
.name = "NTAG203",
.generator_func = nfc_generate_mf_ul_ntag203,
.next_scene = NfcSceneMifareUlMenu};

static const NfcGenerator ntag213_generator = {
.name = "NTAG213",
.generator_func = nfc_generate_ntag213,
Expand Down Expand Up @@ -316,6 +335,7 @@ const NfcGenerator* const nfc_generators[] = {
&mf_ul_h11_generator,
&mf_ul_21_generator,
&mf_ul_h21_generator,
&ntag203_generator,
&ntag213_generator,
&ntag215_generator,
&ntag216_generator,
Expand Down
2 changes: 2 additions & 0 deletions applications/nfc/nfc_types.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ const char* nfc_mf_ul_type(MfUltralightType type, bool full_name) {
return "NTAG I2C Plus 1K";
} else if(type == MfUltralightTypeNTAGI2CPlus2K) {
return "NTAG I2C Plus 2K";
} else if(type == MfUltralightTypeNTAG203) {
return "NTAG203";
} else if(type == MfUltralightTypeUL11 && full_name) {
return "Mifare Ultralight 11";
} else if(type == MfUltralightTypeUL21 && full_name) {
Expand Down
Loading

0 comments on commit f8e0ec4

Please sign in to comment.