Skip to content

Commit

Permalink
Added preliminary support for NTAG215
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankWu100 committed Jun 11, 2020
1 parent 7c8f7dd commit 83a8350
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 9 deletions.
55 changes: 46 additions & 9 deletions Firmware/Chameleon-Mini/Application/MifareUltralight.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,13 @@
#define VERSION_INFO_LENGTH 8
#define SIGNATURE_LENGTH 32

#define CONFIG_AREA_START_ADDRESS MIFARE_ULTRALIGHT_PAGE_SIZE * 0x83

static enum {
UL_EV0,
UL_C,
UL_EV1,
UL_NTAG_215
} Flavor;

static enum {
Expand Down Expand Up @@ -202,6 +205,19 @@ static void AppInitEV1Common(void) {
AppInitCommon();
}

static void AppInitNTAG215Common(void) {
uint8_t ConfigAreaAddress = PageCount * MIFARE_ULTRALIGHT_PAGE_SIZE - CONFIG_AREA_SIZE;
uint8_t Access;

/* Set up the emulation flavor */
Flavor = UL_NTAG_215;
/* Fetch some of the configuration into RAM */
MemoryReadBlock(&FirstAuthenticatedPage, ConfigAreaAddress + CONF_AUTH0_OFFSET, 1);
MemoryReadBlock(&Access, ConfigAreaAddress + CONF_ACCESS_OFFSET, 1);
ReadAccessProtected = !!(Access & CONF_ACCESS_PROT);
AppInitCommon();
}

void MifareUltralightEV11AppInit(void) {
PageCount = MIFARE_ULTRALIGHT_EV11_PAGES;
AppInitEV1Common();
Expand All @@ -212,6 +228,11 @@ void MifareUltralightEV12AppInit(void) {
AppInitEV1Common();
}

void MifareUltralightNTAG215AppInit(void) {
PageCount = MIFARE_ULTRALIGHT_NTAG_215_PAGES;
AppInitNTAG215Common();
}

void MifareUltralightAppReset(void) {
State = STATE_IDLE;
}
Expand Down Expand Up @@ -414,14 +435,26 @@ static uint16_t AppProcess(uint8_t *const Buffer, uint16_t ByteCount) {

case CMD_GET_VERSION: {
/* Provide hardcoded version response */
Buffer[0] = 0x00;
Buffer[1] = 0x04;
Buffer[2] = 0x03;
Buffer[3] = 0x01; /**/
Buffer[4] = 0x01;
Buffer[5] = 0x00;
Buffer[6] = PageCount == MIFARE_ULTRALIGHT_EV11_PAGES ? 0x0B : 0x0E;
Buffer[7] = 0x03;
if (Flavor == UL_EV1) { //VERSION RESPONSE FOR EV1
Buffer[0] = 0x00;
Buffer[1] = 0x04;
Buffer[2] = 0x03;
Buffer[3] = 0x01; /**/
Buffer[4] = 0x01;
Buffer[5] = 0x00;
Buffer[6] = PageCount == MIFARE_ULTRALIGHT_EV11_PAGES ? 0x0B : 0x0E;
Buffer[7] = 0x03;
} else { //VERSION RESPONSE FOR NTAG 215
/* Provide hardcoded version response */
Buffer[0] = 0x00;
Buffer[1] = 0x04;
Buffer[2] = 0x04;
Buffer[3] = 0x02;
Buffer[4] = 0x01;
Buffer[5] = 0x00;
Buffer[6] = 0x11;
Buffer[7] = 0x03;
}
ISO14443AAppendCRCA(Buffer, VERSION_INFO_LENGTH);
return (VERSION_INFO_LENGTH + ISO14443A_CRCA_SIZE) * 8;
}
Expand Down Expand Up @@ -459,7 +492,11 @@ static uint16_t AppProcess(uint8_t *const Buffer, uint16_t ByteCount) {
return NAK_FRAME_SIZE;
}
/* Read and compare the password */
MemoryReadBlock(Password, ConfigAreaAddress + CONF_PASSWORD_OFFSET, 4);
if (Flavor == UL_EV1) { //VERSION RESPONSE FOR EV1
MemoryReadBlock(Password, ConfigAreaAddress + CONF_PASSWORD_OFFSET, 4);
} else { //VERSION RESPONSE FOR NTAG 215
MemoryReadBlock(Password, CONFIG_AREA_START_ADDRESS + CONF_PASSWORD_OFFSET, 4);
}
if (Password[0] != Buffer[1] || Password[1] != Buffer[2] || Password[2] != Buffer[3] || Password[3] != Buffer[4]) {
Buffer[0] = NAK_AUTH_FAILED;
return NAK_FRAME_SIZE;
Expand Down
3 changes: 3 additions & 0 deletions Firmware/Chameleon-Mini/Application/MifareUltralight.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@
#define MIFARE_ULTRALIGHT_PAGES 16
#define MIFARE_ULTRALIGHT_EV11_PAGES 20
#define MIFARE_ULTRALIGHT_EV12_PAGES 41
#define MIFARE_ULTRALIGHT_NTAG_215_PAGES 135 //135 pages total, from 0 to 134
#define MIFARE_ULTRALIGHT_MEM_SIZE (MIFARE_ULTRALIGHT_PAGES * MIFARE_ULTRALIGHT_PAGE_SIZE)
#define MIFARE_ULTRALIGHT_EV11_MEM_SIZE (MIFARE_ULTRALIGHT_EV11_PAGES * MIFARE_ULTRALIGHT_PAGE_SIZE)
#define MIFARE_ULTRALIGHT_EV12_MEM_SIZE (MIFARE_ULTRALIGHT_EV12_PAGES * MIFARE_ULTRALIGHT_PAGE_SIZE)
#define MIFARE_ULTRALIGHT_NTAG_215_MEM_SIZE ( MIFARE_ULTRALIGHT_NTAG_215_PAGES * MIFARE_ULTRALIGHTC_PAGE_SIZE )

void MifareUltralightAppInit(void);
void MifareUltralightEV11AppInit(void);
void MifareUltralightEV12AppInit(void);
void MifareUltralightNTAG215AppInit(void);
void MifareUltralightAppReset(void);
void MifareUltralightAppTask(void);

Expand Down
17 changes: 17 additions & 0 deletions Firmware/Chameleon-Mini/Configuration.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ static const MapEntryType PROGMEM ConfigurationMap[] = {
{ .Id = CONFIG_MF_ULTRALIGHT_EV1_80B, .Text = "MF_ULTRALIGHT_EV1_80B" },
{ .Id = CONFIG_MF_ULTRALIGHT_EV1_164B, .Text = "MF_ULTRALIGHT_EV1_164B" },
{.Id = CONFIG_MF_ULTRALIGHT_C, .Text = "MF_ULTRALIGHT_C"},
{ .Id = CONFIG_MF_ULTRALIGHT_NTAG_215, .Text = "MF_ULTRALIGHT_NTAG_215" },
#endif
#ifdef CONFIG_MF_CLASSIC_MINI_4B_SUPPORT
{ .Id = CONFIG_MF_CLASSIC_MINI_4B, .Text = "MF_CLASSIC_MINI_4B" },
Expand Down Expand Up @@ -166,6 +167,22 @@ static const PROGMEM ConfigurationType ConfigurationTable[] = {
.ReadOnly = false,
.TagFamily = TAG_FAMILY_ISO14443A
},
[CONFIG_MF_ULTRALIGHT_NTAG_215] = {
.CodecInitFunc = ISO14443ACodecInit,
.CodecDeInitFunc = ISO14443ACodecDeInit,
.CodecTaskFunc = ISO14443ACodecTask,
.ApplicationInitFunc = MifareUltralightNTAG215AppInit,
.ApplicationResetFunc = MifareUltralightAppReset,
.ApplicationTaskFunc = MifareUltralightAppTask,
.ApplicationTickFunc = ApplicationTickDummy,
.ApplicationProcessFunc = MifareUltralightAppProcess,
.ApplicationGetUidFunc = MifareUltralightGetUid,
.ApplicationSetUidFunc = MifareUltralightSetUid,
.UidSize = MIFARE_ULTRALIGHT_UID_SIZE,
.MemorySize = MIFARE_ULTRALIGHT_NTAG_215_MEM_SIZE,
.ReadOnly = false,
.TagFamily = TAG_FAMILY_ISO14443A
},
#endif
#ifdef CONFIG_MF_CLASSIC_MINI_4B_SUPPORT
[CONFIG_MF_CLASSIC_MINI_4B] = {
Expand Down
1 change: 1 addition & 0 deletions Firmware/Chameleon-Mini/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ typedef enum {
CONFIG_MF_ULTRALIGHT_C,
CONFIG_MF_ULTRALIGHT_EV1_80B,
CONFIG_MF_ULTRALIGHT_EV1_164B,
CONFIG_MF_ULTRALIGHT_NTAG_215,
#endif
#ifdef CONFIG_MF_CLASSIC_MINI_4B_SUPPORT
CONFIG_MF_CLASSIC_MINI_4B,
Expand Down

0 comments on commit 83a8350

Please sign in to comment.