diff --git a/Firmware/Chameleon-Mini/Application/Application.h b/Firmware/Chameleon-Mini/Application/Application.h index 37e4537..fa53ce0 100644 --- a/Firmware/Chameleon-Mini/Application/Application.h +++ b/Firmware/Chameleon-Mini/Application/Application.h @@ -21,7 +21,7 @@ #include "TITagitstandard.h" #include "Sniff14443A.h" #include "EM4233.h" -#include "NTAG215.h" +#include "NTAG21x.h" #include "Sniff15693.h" #include "IClass.h" diff --git a/Firmware/Chameleon-Mini/Application/NTAG215.h b/Firmware/Chameleon-Mini/Application/NTAG215.h deleted file mode 100644 index 77c1cc5..0000000 --- a/Firmware/Chameleon-Mini/Application/NTAG215.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * NTAG215.h - * - * Created on: 20.02.2019 - * Author: gcammisa - */ - -#ifndef NTAG215_H_ -#define NTAG215_H_ - -#include "Application.h" -#include "ISO14443-3A.h" - -#define NTAG215_UID_SIZE ISO14443A_UID_SIZE_DOUBLE // 7 bytes UID -#define NTAG215_PAGE_SIZE 4 // bytes per page -#define NTAG215_PAGES 135 // 135 pages total, from 0 to 134 -#define NTAG215_MEM_SIZE ( NTAG215_PAGE_SIZE * NTAG215_PAGES ) - -void NTAG215AppInit(void); -void NTAG215AppReset(void); -void NTAG215AppTask(void); - -uint16_t NTAG215AppProcess(uint8_t* Buffer, uint16_t BitCount); - -void NTAG215GetUid(ConfigurationUidType Uid); -void NTAG215SetUid(ConfigurationUidType Uid); -#endif diff --git a/Firmware/Chameleon-Mini/Application/NTAG215.c b/Firmware/Chameleon-Mini/Application/NTAG21x.c similarity index 85% rename from Firmware/Chameleon-Mini/Application/NTAG215.c rename to Firmware/Chameleon-Mini/Application/NTAG21x.c index c7bb0e1..4c334f8 100644 --- a/Firmware/Chameleon-Mini/Application/NTAG215.c +++ b/Firmware/Chameleon-Mini/Application/NTAG21x.c @@ -1,5 +1,5 @@ /* - * NTAG215.c + * NTAG21x.c * * Created on: 20.02.2019 * Author: Giovanni Cammisa (gcammisa) @@ -12,7 +12,7 @@ #include "ISO14443-3A.h" #include "../Codec/ISO14443-2A.h" #include "../Memory.h" -#include "NTAG215.h" +#include "NTAG21x.h" // DEFINE ATQA and SAK #define ATQA_VALUE 0x0044 @@ -55,7 +55,9 @@ #define STATIC_LOCKBYTE_0_ADDRESS 0x0A #define STATIC_LOCKBYTE_1_ADDRESS 0x0B // CONFIG stuff -#define CONFIG_AREA_START_ADDRESS NTAG215_PAGE_SIZE * 0x83 +#define NTAG213_CONFIG_AREA_START_ADDRESS NTAG21x_PAGE_SIZE * 0x29 +#define NTAG215_CONFIG_AREA_START_ADDRESS NTAG21x_PAGE_SIZE * 0x83 +#define NTAG216_CONFIG_AREA_START_ADDRESS NTAG21x_PAGE_SIZE * 0xE3 #define CONFIG_AREA_SIZE 8 // CONFIG offsets, relative to config start address #define CONF_AUTH0_OFFSET 0x03 @@ -72,12 +74,18 @@ #define VERSION_INFO_LENGTH 8 //8 bytes info lenght + crc -#define BYTES_PER_READ NTAG215_PAGE_SIZE * 4 +#define BYTES_PER_READ NTAG21x_PAGE_SIZE * 4 // SIGNATURE Lenght #define SIGNATURE_LENGTH 32 +static enum { + TYPE_NTAG213, + TYPE_NTAG215, + TYPE_NTAG216 +} Ntag_Type; + static enum { STATE_HALT, STATE_IDLE, @@ -86,6 +94,7 @@ static enum { STATE_ACTIVE } State; +static uint32_t ConfigStartAddr = NTAG213_CONFIG_AREA_START_ADDRESS; static bool FromHalt = false; static uint8_t PageCount; static bool ArmedForCompatWrite; @@ -96,27 +105,69 @@ static bool ReadAccessProtected; static uint8_t Access; -void NTAG215AppInit(void) +void NTAG21xAppInit(void) { - State = STATE_IDLE; FromHalt = false; ArmedForCompatWrite = false; Authenticated = false; - PageCount = NTAG215_PAGES; + //PageCount = NTAG215_PAGES; + + switch (Ntag_Type) + { + case TYPE_NTAG213: + PageCount = NTAG213_PAGES; + break; + case TYPE_NTAG215: + PageCount = NTAG215_PAGES; + break; + case TYPE_NTAG216: + PageCount = NTAG216_PAGES; + break; + } /* Fetch some of the configuration into RAM */ - MemoryReadBlock(&FirstAuthenticatedPage, CONFIG_AREA_START_ADDRESS + CONF_AUTH0_OFFSET, 1); - MemoryReadBlock(&Access, CONFIG_AREA_START_ADDRESS + CONF_ACCESS_OFFSET, 1); + MemoryReadBlock(&FirstAuthenticatedPage, ConfigStartAddr + CONF_AUTH0_OFFSET, 1); + MemoryReadBlock(&Access, ConfigStartAddr + CONF_ACCESS_OFFSET, 1); ReadAccessProtected = !!(Access & CONF_ACCESS_PROT); } -void NTAG215AppReset(void) +#if defined(CONFIG_NTAG213_SUPPORT) +void NTAG213AppInit(void) +{ + Ntag_Type = TYPE_NTAG213; + PageCount = NTAG213_PAGES; + ConfigStartAddr = NTAG213_CONFIG_AREA_START_ADDRESS; + NTAG21xAppInit(); +} +#endif // CONIFG_NTAG213_SUPPORT + +#ifdef CONFIG_NTAG215_SUPPORT +void NTAG215AppInit(void) +{ + Ntag_Type = TYPE_NTAG215; + PageCount = NTAG215_PAGES; + ConfigStartAddr = NTAG215_CONFIG_AREA_START_ADDRESS; + NTAG21xAppInit(); +} +#endif // CONFIG_NTAG215_SUPPORT + +#ifdef CONFIG_NTAG216_SUPPORT +void NTAG216AppInit(void) +{ + Ntag_Type = TYPE_NTAG216; + PageCount = NTAG216_PAGES; + ConfigStartAddr = NTAG216_CONFIG_AREA_START_ADDRESS; + NTAG21xAppInit(); +} +#endif // CONFIG_NTAG216_SUPPORT + +void NTAG21xAppReset(void) { State = STATE_IDLE; } -void NTAG215AppTask(void) +void NTAG21xAppTask(void) { } @@ -136,7 +187,7 @@ static bool VerifyAuthentication(uint8_t PageAddress) static uint8_t AppWritePage(uint8_t PageAddress, uint8_t* const Buffer) { if (!ActiveConfiguration.ReadOnly) { - MemoryWriteBlock(Buffer, PageAddress * NTAG215_PAGE_SIZE, NTAG215_PAGE_SIZE); + MemoryWriteBlock(Buffer, PageAddress * NTAG21x_PAGE_SIZE, NTAG21x_PAGE_SIZE); } else { /* If the chameleon is in read only mode, it silently * ignores any attempt to write data. */ @@ -167,7 +218,17 @@ static uint16_t AppProcess(uint8_t* const Buffer, uint16_t ByteCount) Buffer[3] = 0x02; Buffer[4] = 0x01; Buffer[5] = 0x00; - Buffer[6] = 0x11; + switch (Ntag_Type) { + case TYPE_NTAG213: + Buffer[6] = 0x0F; + break; + case TYPE_NTAG215: + Buffer[6] = 0x11; + break; + case TYPE_NTAG216: + Buffer[6] = 0x13; + break; + } Buffer[7] = 0x03; ISO14443AAppendCRCA(Buffer, VERSION_INFO_LENGTH); return (VERSION_INFO_LENGTH + ISO14443A_CRCA_SIZE) * 8; @@ -195,7 +256,7 @@ static uint16_t AppProcess(uint8_t* const Buffer, uint16_t ByteCount) } /* Read out, emulating the wraparound */ for (Offset = 0; Offset < BYTES_PER_READ; Offset += 4) { - MemoryReadBlock(&Buffer[Offset], PageAddress * NTAG215_PAGE_SIZE, NTAG215_PAGE_SIZE); + MemoryReadBlock(&Buffer[Offset], PageAddress * NTAG21x_PAGE_SIZE, NTAG21x_PAGE_SIZE); PageAddress++; if (PageAddress == PageLimit) { // if arrived ad the last page, start reading from page 0 PageAddress = 0; @@ -222,8 +283,8 @@ static uint16_t AppProcess(uint8_t* const Buffer, uint16_t ByteCount) } } - ByteCount = (EndPageAddress - StartPageAddress + 1) * NTAG215_PAGE_SIZE; - MemoryReadBlock(Buffer, StartPageAddress * NTAG215_PAGE_SIZE, ByteCount); + ByteCount = (EndPageAddress - StartPageAddress + 1) * NTAG21x_PAGE_SIZE; + MemoryReadBlock(Buffer, StartPageAddress * NTAG21x_PAGE_SIZE, ByteCount); ISO14443AAppendCRCA(Buffer, ByteCount); return (ByteCount + ISO14443A_CRCA_SIZE) * 8; } @@ -235,7 +296,7 @@ static uint16_t AppProcess(uint8_t* const Buffer, uint16_t ByteCount) /* TODO: IMPLEMENT COUNTER AUTHLIM */ /* Read and compare the password */ - MemoryReadBlock(Password, CONFIG_AREA_START_ADDRESS + CONF_PASSWORD_OFFSET, 4); + MemoryReadBlock(Password, ConfigStartAddr + CONF_PASSWORD_OFFSET, 4); if (Password[0] != Buffer[1] || Password[1] != Buffer[2] || Password[2] != Buffer[3] || Password[3] != Buffer[4]) { Buffer[0] = NAK_NOT_AUTHED; return NAK_FRAME_SIZE; @@ -244,7 +305,7 @@ static uint16_t AppProcess(uint8_t* const Buffer, uint16_t ByteCount) //RESET AUTHLIM COUNTER, CURRENTLY NOT IMPLEMENTED Authenticated = 1; /* Send the PACK value back */ - MemoryReadBlock(Buffer, CONFIG_AREA_START_ADDRESS + CONF_PACK_OFFSET, 2); + MemoryReadBlock(Buffer, ConfigStartAddr + CONF_PACK_OFFSET, 2); ISO14443AAppendCRCA(Buffer, 2); return (2 + ISO14443A_CRCA_SIZE) * 8; } @@ -324,7 +385,7 @@ static uint16_t AppProcess(uint8_t* const Buffer, uint16_t ByteCount) // FINITE STATE MACHINE STUFF, SHOULD BE THE VERY SIMILAR TO Mifare Ultralight -uint16_t NTAG215AppProcess(uint8_t* Buffer, uint16_t BitCount) +uint16_t NTAG21xAppProcess(uint8_t* Buffer, uint16_t BitCount) { uint8_t Cmd = Buffer[0]; uint16_t ByteCount; @@ -418,14 +479,14 @@ uint16_t NTAG215AppProcess(uint8_t* Buffer, uint16_t BitCount) } // HELPER FUNCTIONS -void NTAG215GetUid(ConfigurationUidType Uid) +void NTAG21xGetUid(ConfigurationUidType Uid) { /* Read UID from memory */ MemoryReadBlock(&Uid[0], UID_CL1_ADDRESS, UID_CL1_SIZE); MemoryReadBlock(&Uid[UID_CL1_SIZE], UID_CL2_ADDRESS, UID_CL2_SIZE); } -void NTAG215SetUid(ConfigurationUidType Uid) +void NTAG21xSetUid(ConfigurationUidType Uid) { /* Calculate check bytes and write everything into memory */ uint8_t BCC1 = ISO14443A_UID0_CT ^ Uid[0] ^ Uid[1] ^ Uid[2]; diff --git a/Firmware/Chameleon-Mini/Application/NTAG21x.h b/Firmware/Chameleon-Mini/Application/NTAG21x.h new file mode 100644 index 0000000..eaf3949 --- /dev/null +++ b/Firmware/Chameleon-Mini/Application/NTAG21x.h @@ -0,0 +1,34 @@ +/* + * NTAG21x.h + * + * Created on: 20.02.2019 + * Author: gcammisa + */ + +#ifndef NTAG21x_H_ +#define NTAG21x_H_ + +#include "Application.h" +#include "ISO14443-3A.h" + +#define NTAG21x_UID_SIZE ISO14443A_UID_SIZE_DOUBLE // 7 bytes UID +#define NTAG21x_PAGE_SIZE 4 // bytes per page +#define NTAG213_PAGES 45 //45 pages total for ntag213, from 0 to 44 +#define NTAG215_PAGES 135 //135 pages total for ntag215, from 0 to 134 +#define NTAG216_PAGES 231 //231 pages total for ntag216, from 0 to 230 + +#define NTAG213_MEM_SIZE ( NTAG21x_PAGE_SIZE * NTAG213_PAGES ) +#define NTAG215_MEM_SIZE ( NTAG21x_PAGE_SIZE * NTAG215_PAGES ) +#define NTAG216_MEM_SIZE ( NTAG21x_PAGE_SIZE * NTAG216_PAGES ) + +void NTAG213AppInit(void); +void NTAG215AppInit(void); +void NTAG216AppInit(void); +void NTAG21xAppReset(void); +void NTAG21xAppTask(void); + +uint16_t NTAG21xAppProcess(uint8_t* Buffer, uint16_t BitCount); + +void NTAG21xGetUid(ConfigurationUidType Uid); +void NTAG21xSetUid(ConfigurationUidType Uid); +#endif diff --git a/Firmware/Chameleon-Mini/Configuration.c b/Firmware/Chameleon-Mini/Configuration.c index ccd18e1..77264cc 100644 --- a/Firmware/Chameleon-Mini/Configuration.c +++ b/Firmware/Chameleon-Mini/Configuration.c @@ -51,9 +51,15 @@ static const MapEntryType PROGMEM ConfigurationMap[] = { #ifdef CONFIG_ISO14443A_READER_SUPPORT { .Id = CONFIG_ISO14443A_READER, .Text = "ISO14443A_READER" }, #endif +#ifdef CONFIG_NTAG213_SUPPORT + { .Id = CONFIG_NTAG213, .Text = "NTAG213" }, +#endif #ifdef CONFIG_NTAG215_SUPPORT { .Id = CONFIG_NTAG215, .Text = "NTAG215" }, #endif +#ifdef CONFIG_NTAG216_SUPPORT + { .Id = CONFIG_NTAG216, .Text = "NTAG216" }, +#endif #ifdef CONFIG_VICINITY_SUPPORT { .Id = CONFIG_VICINITY, .Text = "VICINITY" }, #endif @@ -485,24 +491,60 @@ static const PROGMEM ConfigurationType ConfigurationTable[] = { .TagFamily = TAG_FAMILY_ISO15693 }, #endif +#ifdef CONFIG_NTAG213_SUPPORT + [CONFIG_NTAG213] = { + .CodecInitFunc = ISO14443ACodecInit, + .CodecDeInitFunc = ISO14443ACodecDeInit, + .CodecTaskFunc = ISO14443ACodecTask, + .ApplicationInitFunc = NTAG213AppInit, + .ApplicationResetFunc = NTAG21xAppReset, + .ApplicationTaskFunc = NTAG21xAppTask, + .ApplicationTickFunc = ApplicationTickDummy, + .ApplicationProcessFunc = NTAG21xAppProcess, + .ApplicationGetUidFunc = NTAG21xGetUid, + .ApplicationSetUidFunc = NTAG21xSetUid, + .UidSize = NTAG21x_UID_SIZE, + .MemorySize = NTAG213_MEM_SIZE, + .ReadOnly = false, + .TagFamily = TAG_FAMILY_ISO14443A + }, +#endif #ifdef CONFIG_NTAG215_SUPPORT [CONFIG_NTAG215] = { .CodecInitFunc = ISO14443ACodecInit, .CodecDeInitFunc = ISO14443ACodecDeInit, .CodecTaskFunc = ISO14443ACodecTask, .ApplicationInitFunc = NTAG215AppInit, - .ApplicationResetFunc = NTAG215AppReset, - .ApplicationTaskFunc = NTAG215AppTask, + .ApplicationResetFunc = NTAG21xAppReset, + .ApplicationTaskFunc = NTAG21xAppTask, .ApplicationTickFunc = ApplicationTickDummy, - .ApplicationProcessFunc = NTAG215AppProcess, - .ApplicationGetUidFunc = NTAG215GetUid, - .ApplicationSetUidFunc = NTAG215SetUid, - .UidSize = NTAG215_UID_SIZE, + .ApplicationProcessFunc = NTAG21xAppProcess, + .ApplicationGetUidFunc = NTAG21xGetUid, + .ApplicationSetUidFunc = NTAG21xSetUid, + .UidSize = NTAG21x_UID_SIZE, .MemorySize = NTAG215_MEM_SIZE, .ReadOnly = false, .TagFamily = TAG_FAMILY_ISO14443A }, #endif +#ifdef CONFIG_NTAG216_SUPPORT + [CONFIG_NTAG216] = { + .CodecInitFunc = ISO14443ACodecInit, + .CodecDeInitFunc = ISO14443ACodecDeInit, + .CodecTaskFunc = ISO14443ACodecTask, + .ApplicationInitFunc = NTAG216AppInit, + .ApplicationResetFunc = NTAG21xAppReset, + .ApplicationTaskFunc = NTAG21xAppTask, + .ApplicationTickFunc = ApplicationTickDummy, + .ApplicationProcessFunc = NTAG21xAppProcess, + .ApplicationGetUidFunc = NTAG21xGetUid, + .ApplicationSetUidFunc = NTAG21xSetUid, + .UidSize = NTAG21x_UID_SIZE, + .MemorySize = NTAG216_MEM_SIZE, + .ReadOnly = false, + .TagFamily = TAG_FAMILY_ISO14443A + }, +#endif #ifdef CONFIG_ICLASS_SUPPORT [CONFIG_ICLASS] = { .CodecInitFunc = ISO15693CodecInit, diff --git a/Firmware/Chameleon-Mini/Configuration.h b/Firmware/Chameleon-Mini/Configuration.h index ee2c52b..ba83e6f 100644 --- a/Firmware/Chameleon-Mini/Configuration.h +++ b/Firmware/Chameleon-Mini/Configuration.h @@ -57,9 +57,15 @@ typedef enum { #ifdef CONFIG_ISO14443A_READER_SUPPORT CONFIG_ISO14443A_READER, #endif +#ifdef CONFIG_NTAG213_SUPPORT + CONFIG_NTAG213, +#endif #ifdef CONFIG_NTAG215_SUPPORT CONFIG_NTAG215, #endif +#ifdef CONFIG_NTAG216_SUPPORT + CONFIG_NTAG216, +#endif #ifdef CONFIG_VICINITY_SUPPORT CONFIG_VICINITY, #endif diff --git a/Firmware/Chameleon-Mini/Makefile b/Firmware/Chameleon-Mini/Makefile index e7fb7ba..2590382 100644 --- a/Firmware/Chameleon-Mini/Makefile +++ b/Firmware/Chameleon-Mini/Makefile @@ -17,7 +17,9 @@ SETTINGS += -DCONFIG_MF_CLASSIC_4K_7B_SUPPORT SETTINGS += -DCONFIG_MF_ULTRALIGHT_SUPPORT SETTINGS += -DCONFIG_ISO14443A_SNIFF_SUPPORT SETTINGS += -DCONFIG_ISO14443A_READER_SUPPORT +SETTINGS += -DCONFIG_NTAG213_SUPPORT SETTINGS += -DCONFIG_NTAG215_SUPPORT +SETTINGS += -DCONFIG_NTAG216_SUPPORT # SETTINGS += -DCONFIG_VICINITY_SUPPORT # SETTINGS += -DCONFIG_SL2S2002_SUPPORT # SETTINGS += -DCONFIG_TITAGITSTANDARD_SUPPORT @@ -113,7 +115,7 @@ OPTIMIZATION = s SRC += Chameleon-Mini.c LUFADescriptors.c System.c ISRSharing.S Configuration.c Random.c Common.c Memory.c MemoryAsm.S Button.c Log.c Settings.c LED.c Map.c AntennaLevel.c Uart.c uartcmd.c SRC += Terminal/Terminal.c Terminal/Commands.c Terminal/XModem.c Terminal/CommandLine.c SRC += Codec/Codec.c Codec/ISO14443-2A.c Codec/Reader14443-2A.c Codec/SniffISO14443-2A.c Codec/Reader14443-ISR.S -SRC += Application/MifareUltralight.c Application/MifareClassic.c Application/ISO14443-3A.c Application/Crypto1.c Application/Reader14443A.c Application/Sniff14443A.c Application/CryptoTDEA.S Application/NTAG215.c +SRC += Application/MifareUltralight.c Application/MifareClassic.c Application/ISO14443-3A.c Application/Crypto1.c Application/Reader14443A.c Application/Sniff14443A.c Application/CryptoTDEA.S Application/NTAG21x.c SRC += Codec/ISO15693.c Codec/SniffISO15693.c SRC += Application/Vicinity.c Application/Sl2s2002.c Application/TITagitstandard.c Application/ISO15693-A.c Application/EM4233.c Application/Sniff15693.c Application/IClass.c SRC += $(LUFA_SRC_USB) $(LUFA_SRC_USBCLASS)