|
|
|
@@ -19,9 +19,6 @@ CurrentFrame FrameInfo;
|
|
|
|
|
uint64_t EM4233_FactoryLockBits_Mask = 0; /* Holds lock state of blocks */
|
|
|
|
|
uint64_t EM4233_UserLockBits_Mask = 0; /* Holds lock state of blocks */
|
|
|
|
|
|
|
|
|
|
//uint8_t EM4233_Lock_Status[64] = { 1 };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void EM4233AppInit(void)
|
|
|
|
|
{
|
|
|
|
|
State = STATE_READY;
|
|
|
|
@@ -31,9 +28,7 @@ void EM4233AppInit(void)
|
|
|
|
|
FrameInfo.Parameters = NULL;
|
|
|
|
|
FrameInfo.ParamLen = 0;
|
|
|
|
|
FrameInfo.Addressed = false;
|
|
|
|
|
|
|
|
|
|
//MemoryReadBlock(EM4233_Lock_Status, EM4233_MEM_LSM_ADDRESS, 64);
|
|
|
|
|
//MemoryReadBlock(&EM4233_FactoryLockBits_Mask, EM4233_MEM_FLM_ADDRESS, 8);
|
|
|
|
|
FrameInfo.Selected = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EM4233AppReset(void)
|
|
|
|
@@ -45,12 +40,9 @@ void EM4233AppReset(void)
|
|
|
|
|
FrameInfo.Parameters = NULL;
|
|
|
|
|
FrameInfo.ParamLen = 0;
|
|
|
|
|
FrameInfo.Addressed = false;
|
|
|
|
|
|
|
|
|
|
//MemoryReadBlock(&EM4233_UserLockBits_Mask, EM4233_MEM_ULM_ADDRESS, 8);
|
|
|
|
|
//MemoryReadBlock(&EM4233_FactoryLockBits_Mask, EM4233_MEM_FLM_ADDRESS, 8);
|
|
|
|
|
FrameInfo.Selected = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void EM4233AppTask(void)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
@@ -70,20 +62,20 @@ uint16_t EM4233_Lock_Block(uint8_t* FrameBuf, uint16_t FrameBytes)
|
|
|
|
|
return ISO15693_APP_NO_RESPONSE; /* malformed: not enough or too much data */
|
|
|
|
|
|
|
|
|
|
if (PageAddress > EM4233_NUMBER_OF_BLCKS) {
|
|
|
|
|
FrameBuf[ISO15693_ADDR_FLAGS] = ISO15693_RES_FLAG_ERROR;
|
|
|
|
|
FrameBuf[ISO15693_RES_ADDR_PARAM] = ISO15693_RES_ERR_OPT_NOT_SUPP;
|
|
|
|
|
ResponseByteCount = 2;
|
|
|
|
|
// FrameBuf[ISO15693_ADDR_FLAGS] = ISO15693_RES_FLAG_ERROR;
|
|
|
|
|
// FrameBuf[ISO15693_RES_ADDR_PARAM] = ISO15693_RES_ERR_OPT_NOT_SUPP;
|
|
|
|
|
ResponseByteCount = ISO15693_APP_NO_RESPONSE; /* real tag does not respond anyway */
|
|
|
|
|
return ResponseByteCount; /* malformed: trying to lock a non-existing block */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((EM4233_FactoryLockBits_Mask & (uint64_t)(1 << PageAddress)) || (EM4233_UserLockBits_Mask & (uint64_t)(1 << PageAddress))) { /* if already locked */
|
|
|
|
|
FrameBuf[ISO15693_ADDR_FLAGS] = ISO15693_RES_FLAG_ERROR;
|
|
|
|
|
FrameBuf[ISO15693_RES_ADDR_PARAM] = ISO15693_RES_ERR_BLK_ALRD_LKD;
|
|
|
|
|
ResponseByteCount = 2;
|
|
|
|
|
// FrameBuf[ISO15693_ADDR_FLAGS] = ISO15693_RES_FLAG_ERROR;
|
|
|
|
|
// FrameBuf[ISO15693_RES_ADDR_PARAM] = ISO15693_RES_ERR_BLK_ALRD_LKD;
|
|
|
|
|
ResponseByteCount = ISO15693_APP_NO_RESPONSE; /* real tag does not respond anyway */
|
|
|
|
|
} else {
|
|
|
|
|
EM4233_UserLockBits_Mask |= (uint64_t)(1 << PageAddress); /* write the lock status in mask */
|
|
|
|
|
FrameBuf[ISO15693_ADDR_FLAGS] = ISO15693_RES_FLAG_NO_ERROR;
|
|
|
|
|
ResponseByteCount = 1;
|
|
|
|
|
ResponseByteCount = ISO15693_APP_NO_RESPONSE; /* real tag does not respond anyway */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ResponseByteCount;
|
|
|
|
@@ -94,31 +86,33 @@ uint16_t EM4233_Write_Single(uint8_t* FrameBuf, uint16_t FrameBytes)
|
|
|
|
|
uint16_t ResponseByteCount = ISO15693_APP_NO_RESPONSE;
|
|
|
|
|
uint8_t* Dataptr;
|
|
|
|
|
uint8_t PageAddress = *FrameInfo.Parameters;
|
|
|
|
|
uint8_t LockStatus = 0;
|
|
|
|
|
|
|
|
|
|
if (FrameInfo.ParamLen != 5)
|
|
|
|
|
return ISO15693_APP_NO_RESPONSE; /* malformed: not enough or too much data */
|
|
|
|
|
|
|
|
|
|
if (PageAddress > EM4233_NUMBER_OF_BLCKS) {
|
|
|
|
|
FrameBuf[ISO15693_ADDR_FLAGS] = ISO15693_RES_FLAG_ERROR;
|
|
|
|
|
FrameBuf[ISO15693_RES_ADDR_PARAM] = ISO15693_RES_ERR_OPT_NOT_SUPP;
|
|
|
|
|
ResponseByteCount = 2; /* malformed: trying to write in a non-existing block */
|
|
|
|
|
return ResponseByteCount;
|
|
|
|
|
// FrameBuf[ISO15693_ADDR_FLAGS] = ISO15693_RES_FLAG_ERROR;
|
|
|
|
|
// FrameBuf[ISO15693_RES_ADDR_PARAM] = ISO15693_RES_ERR_OPT_NOT_SUPP;
|
|
|
|
|
ResponseByteCount = ISO15693_APP_NO_RESPONSE; /* real tag does not respond anyway */
|
|
|
|
|
return ResponseByteCount; /* malformed: trying to write in a non-existing block */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MemoryReadBlock(&LockStatus, (EM4233_MEM_LSM_ADDRESS + PageAddress), 1);
|
|
|
|
|
Dataptr = PageAddress + 0x01;
|
|
|
|
|
|
|
|
|
|
if (EM4233_FactoryLockBits_Mask & (uint64_t)(1 << PageAddress)) {
|
|
|
|
|
FrameBuf[ISO15693_ADDR_FLAGS] = ISO15693_RES_FLAG_ERROR;
|
|
|
|
|
FrameBuf[ISO15693_RES_ADDR_PARAM] = ISO15693_RES_ERR_OPT_NOT_SUPP;
|
|
|
|
|
ResponseByteCount = 2;
|
|
|
|
|
} else if (EM4233_UserLockBits_Mask & (uint64_t)(1 << PageAddress)) {
|
|
|
|
|
FrameBuf[ISO15693_ADDR_FLAGS] = ISO15693_RES_FLAG_ERROR;
|
|
|
|
|
FrameBuf[ISO15693_RES_ADDR_PARAM] = ISO15693_RES_ERR_BLK_CHG_LKD;
|
|
|
|
|
ResponseByteCount = 2;
|
|
|
|
|
if (LockStatus & ISO15693_MASK_FACTORY_LOCK) {
|
|
|
|
|
// FrameBuf[ISO15693_ADDR_FLAGS] = ISO15693_RES_FLAG_ERROR;
|
|
|
|
|
// FrameBuf[ISO15693_RES_ADDR_PARAM] = ISO15693_RES_ERR_OPT_NOT_SUPP;
|
|
|
|
|
ResponseByteCount = ISO15693_APP_NO_RESPONSE; /* real tag does not respond anyway - probably: no factory lock exists? */
|
|
|
|
|
} else if (LockStatus & ISO15693_MASK_USER_LOCK) {
|
|
|
|
|
// FrameBuf[ISO15693_ADDR_FLAGS] = ISO15693_RES_FLAG_ERROR;
|
|
|
|
|
// FrameBuf[ISO15693_RES_ADDR_PARAM] = ISO15693_RES_ERR_BLK_CHG_LKD;
|
|
|
|
|
ResponseByteCount = ISO15693_APP_NO_RESPONSE; /* real tag does not respond anyway */
|
|
|
|
|
} else {
|
|
|
|
|
MemoryWriteBlock(Dataptr, PageAddress * EM4233_BYTES_PER_BLCK, EM4233_BYTES_PER_BLCK);
|
|
|
|
|
FrameBuf[ISO15693_ADDR_FLAGS] = ISO15693_RES_FLAG_NO_ERROR;
|
|
|
|
|
ResponseByteCount = 1;
|
|
|
|
|
ResponseByteCount += 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ResponseByteCount;
|
|
|
|
@@ -127,7 +121,7 @@ uint16_t EM4233_Write_Single(uint8_t* FrameBuf, uint16_t FrameBytes)
|
|
|
|
|
uint16_t EM4233_Read_Single(uint8_t* FrameBuf, uint16_t FrameBytes)
|
|
|
|
|
{
|
|
|
|
|
uint16_t ResponseByteCount = ISO15693_APP_NO_RESPONSE;
|
|
|
|
|
uint8_t *FramePtr; /* holds the address where block's data will be put */
|
|
|
|
|
uint8_t FramePtr; /* holds the address where block's data will be put */
|
|
|
|
|
uint8_t PageAddress = *FrameInfo.Parameters;
|
|
|
|
|
uint8_t LockStatus = 0;
|
|
|
|
|
|
|
|
|
@@ -135,30 +129,293 @@ uint16_t EM4233_Read_Single(uint8_t* FrameBuf, uint16_t FrameBytes)
|
|
|
|
|
return ISO15693_APP_NO_RESPONSE; /* malformed: not enough or too much data */
|
|
|
|
|
|
|
|
|
|
if (PageAddress >= EM4233_NUMBER_OF_BLCKS) { /* the reader is requesting a sector out of bound */
|
|
|
|
|
FrameBuf[ISO15693_ADDR_FLAGS] = ISO15693_RES_FLAG_ERROR;
|
|
|
|
|
FrameBuf[ISO15693_RES_ADDR_PARAM] = ISO15693_RES_ERR_BLK_NOT_AVL; /* real TiTag standard reply with this error */
|
|
|
|
|
ResponseByteCount = 2;
|
|
|
|
|
// FrameBuf[ISO15693_ADDR_FLAGS] = ISO15693_RES_FLAG_ERROR;
|
|
|
|
|
// FrameBuf[ISO15693_RES_ADDR_PARAM] = ISO15693_RES_ERR_BLK_NOT_AVL;
|
|
|
|
|
ResponseByteCount = ISO15693_APP_NO_RESPONSE; /* real tag does not respond anyway */
|
|
|
|
|
return ResponseByteCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FramePtr = 1;
|
|
|
|
|
|
|
|
|
|
if (FrameBuf[ISO15693_ADDR_FLAGS] & ISO15693_REQ_FLAG_OPTION) { /* request with option flag set */
|
|
|
|
|
MemoryReadBlock(&LockStatus, (EM4233_MEM_LSM_ADDRESS + PageAddress), 1);
|
|
|
|
|
if (LockStatus & ISO15693_MASK_FACTORY_LOCK) { /* tests if the n-th bit of the factory bitmask if set to 1 */
|
|
|
|
|
FrameBuf[1] = 0x02; /* return bit 1 set as 1 (factory locked) */
|
|
|
|
|
FrameBuf[FramePtr] = 0x02; /* return bit 1 set as 1 (factory locked) */
|
|
|
|
|
} else if (LockStatus & ISO15693_MASK_USER_LOCK) { /* tests if the n-th bit of the user bitmask if set to 1 */
|
|
|
|
|
FrameBuf[1] = 0x01; /* return bit 0 set as 1 (user locked) */
|
|
|
|
|
FrameBuf[FramePtr] = 0x01; /* return bit 0 set as 1 (user locked) */
|
|
|
|
|
} else
|
|
|
|
|
FrameBuf[1] = 0x00; /* return lock status 00 (unlocked) */
|
|
|
|
|
FramePtr = FrameBuf + 2; /* block's data from byte 2 */
|
|
|
|
|
ResponseByteCount = 6;
|
|
|
|
|
} else { /* request with option flag not set */
|
|
|
|
|
FramePtr = FrameBuf + 1; /* block's data from byte 1 */
|
|
|
|
|
ResponseByteCount = 5;
|
|
|
|
|
FrameBuf[FramePtr] = 0x00; /* return lock status 00 (unlocked) */
|
|
|
|
|
FramePtr += 1; /* block's data from byte 2 */
|
|
|
|
|
ResponseByteCount += 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MemoryReadBlock(&FrameBuf[FramePtr], PageAddress * EM4233_BYTES_PER_BLCK, EM4233_BYTES_PER_BLCK);
|
|
|
|
|
ResponseByteCount += 4;
|
|
|
|
|
|
|
|
|
|
FrameBuf[ISO15693_ADDR_FLAGS] = ISO15693_RES_FLAG_NO_ERROR; /* flags */
|
|
|
|
|
ResponseByteCount += 1;
|
|
|
|
|
|
|
|
|
|
return ResponseByteCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint16_t EM4233_Read_Multiple(uint8_t* FrameBuf, uint16_t FrameBytes)
|
|
|
|
|
{
|
|
|
|
|
uint16_t ResponseByteCount = ISO15693_APP_NO_RESPONSE;
|
|
|
|
|
uint8_t FramePtr; /* holds the address where block's data will be put */
|
|
|
|
|
uint8_t BlockAddress = FrameInfo.Parameters[0];
|
|
|
|
|
uint8_t BlocksNumber = 0;
|
|
|
|
|
uint8_t LockStatus = 0;
|
|
|
|
|
|
|
|
|
|
if (FrameInfo.ParamLen != 2)
|
|
|
|
|
return ISO15693_APP_NO_RESPONSE; /* malformed: not enough or too much data */
|
|
|
|
|
|
|
|
|
|
BlocksNumber = FrameInfo.Parameters[1];
|
|
|
|
|
|
|
|
|
|
if (BlockAddress >= EM4233_NUMBER_OF_BLCKS || (BlockAddress + BlocksNumber) >= EM4233_NUMBER_OF_BLCKS) { /* the reader is requesting a sector out of bound */
|
|
|
|
|
FrameBuf[ISO15693_ADDR_FLAGS] = ISO15693_RES_FLAG_ERROR;
|
|
|
|
|
FrameBuf[ISO15693_RES_ADDR_PARAM] = ISO15693_RES_ERR_BLK_NOT_AVL; /* real TiTag standard reply with this error */
|
|
|
|
|
ResponseByteCount += 2;
|
|
|
|
|
return ResponseByteCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FramePtr = 1; /* Start of response data */
|
|
|
|
|
|
|
|
|
|
for (uint8_t blk = 0; blk <= BlocksNumber; blk++) {
|
|
|
|
|
if (FrameBuf[ISO15693_ADDR_FLAGS] & ISO15693_REQ_FLAG_OPTION) { /* request with option flag set */
|
|
|
|
|
MemoryReadBlock(&LockStatus, (EM4233_MEM_LSM_ADDRESS + (BlockAddress + blk)), 1);
|
|
|
|
|
|
|
|
|
|
if (LockStatus & ISO15693_MASK_FACTORY_LOCK) { /* tests if the n-th bit of the factory bitmask if set to 1 */
|
|
|
|
|
FrameBuf[FramePtr] = 0x02; /* return bit 1 set as 1 (factory locked) */
|
|
|
|
|
} else if (LockStatus & ISO15693_MASK_USER_LOCK) { /* tests if the n-th bit of the user bitmask if set to 1 */
|
|
|
|
|
FrameBuf[FramePtr] = 0x01; /* return bit 0 set as 1 (user locked) */
|
|
|
|
|
} else
|
|
|
|
|
FrameBuf[FramePtr] = 0x00; /* return lock status 00 (unlocked) */
|
|
|
|
|
|
|
|
|
|
FramePtr += 1; /* Move forward the buffer data pointer */
|
|
|
|
|
ResponseByteCount += 1; /* Increment the response count */
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MemoryReadBlock(&FrameBuf[FramePtr], (BlockAddress + blk ) * EM4233_BYTES_PER_BLCK, EM4233_BYTES_PER_BLCK);
|
|
|
|
|
FramePtr += 4; /* Move forward the buffer data pointer */
|
|
|
|
|
ResponseByteCount += 4; /* Increment the response count */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FrameBuf[ISO15693_ADDR_FLAGS] = ISO15693_RES_FLAG_NO_ERROR; /* flags */
|
|
|
|
|
ResponseByteCount += 1;
|
|
|
|
|
return ResponseByteCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint16_t EM4233_Write_AFI(uint8_t* FrameBuf, uint16_t FrameBytes)
|
|
|
|
|
{
|
|
|
|
|
uint16_t ResponseByteCount = ISO15693_APP_NO_RESPONSE;
|
|
|
|
|
uint8_t AFI = FrameInfo.Parameters[0];
|
|
|
|
|
uint8_t LockStatus = 0;
|
|
|
|
|
|
|
|
|
|
if (FrameInfo.ParamLen != 1)
|
|
|
|
|
return ISO15693_APP_NO_RESPONSE; /* malformed: not enough or too much data */
|
|
|
|
|
|
|
|
|
|
MemoryReadBlock(&LockStatus, EM4233_MEM_INF_ADDRESS, 1);
|
|
|
|
|
|
|
|
|
|
if (LockStatus & EM4233_MASK_AFI_STATUS ) { /* The afi is locked */
|
|
|
|
|
FrameBuf[ISO15693_ADDR_FLAGS] = ISO15693_RES_FLAG_ERROR;
|
|
|
|
|
FrameBuf[ISO15693_RES_ADDR_PARAM] = ISO15693_RES_ERR_GENERIC;
|
|
|
|
|
ResponseByteCount += 2;
|
|
|
|
|
return ResponseByteCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MemoryWriteBlock(&AFI, EM4233_MEM_AFI_ADDRESS, 1); /* Actually write new AFI */
|
|
|
|
|
|
|
|
|
|
FrameBuf[ISO15693_ADDR_FLAGS] = ISO15693_RES_FLAG_NO_ERROR; /* flags */
|
|
|
|
|
ResponseByteCount += 1;
|
|
|
|
|
return ResponseByteCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint16_t EM4233_Lock_AFI(uint8_t* FrameBuf, uint16_t FrameBytes)
|
|
|
|
|
{
|
|
|
|
|
uint16_t ResponseByteCount = ISO15693_APP_NO_RESPONSE;
|
|
|
|
|
uint8_t LockStatus = 0;
|
|
|
|
|
|
|
|
|
|
if (FrameInfo.ParamLen != 0)
|
|
|
|
|
return ISO15693_APP_NO_RESPONSE; /* malformed: not enough or too much data */
|
|
|
|
|
|
|
|
|
|
MemoryReadBlock(&LockStatus, EM4233_MEM_INF_ADDRESS, 1);
|
|
|
|
|
|
|
|
|
|
if (LockStatus & EM4233_MASK_AFI_STATUS ) { /* The afi is already locked */
|
|
|
|
|
FrameBuf[ISO15693_ADDR_FLAGS] = ISO15693_RES_FLAG_ERROR;
|
|
|
|
|
FrameBuf[ISO15693_RES_ADDR_PARAM] = ISO15693_RES_ERR_GENERIC;
|
|
|
|
|
ResponseByteCount += 2;
|
|
|
|
|
return ResponseByteCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LockStatus |= EM4233_MASK_AFI_STATUS;
|
|
|
|
|
|
|
|
|
|
MemoryWriteBlock(&LockStatus, EM4233_MEM_INF_ADDRESS, 1); /* Actually write new AFI */
|
|
|
|
|
|
|
|
|
|
FrameBuf[ISO15693_ADDR_FLAGS] = ISO15693_RES_FLAG_NO_ERROR; /* flags */
|
|
|
|
|
ResponseByteCount += 1;
|
|
|
|
|
return ResponseByteCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint16_t EM4233_Write_DSFID(uint8_t* FrameBuf, uint16_t FrameBytes)
|
|
|
|
|
{
|
|
|
|
|
uint16_t ResponseByteCount = ISO15693_APP_NO_RESPONSE;
|
|
|
|
|
uint8_t DSFID = FrameInfo.Parameters[0];
|
|
|
|
|
uint8_t LockStatus = 0;
|
|
|
|
|
|
|
|
|
|
if (FrameInfo.ParamLen != 1)
|
|
|
|
|
return ISO15693_APP_NO_RESPONSE; /* malformed: not enough or too much data */
|
|
|
|
|
|
|
|
|
|
MemoryReadBlock(&LockStatus, EM4233_MEM_INF_ADDRESS, 1);
|
|
|
|
|
|
|
|
|
|
if (LockStatus & EM4233_MASK_DSFID_STATUS ) { /* The afi is locked */
|
|
|
|
|
FrameBuf[ISO15693_ADDR_FLAGS] = ISO15693_RES_FLAG_ERROR;
|
|
|
|
|
FrameBuf[ISO15693_RES_ADDR_PARAM] = ISO15693_RES_ERR_GENERIC;
|
|
|
|
|
ResponseByteCount += 2;
|
|
|
|
|
return ResponseByteCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MemoryWriteBlock(&DSFID, EM4233_MEM_DSFID_ADDRESS, 1); /* Actually write new AFI */
|
|
|
|
|
|
|
|
|
|
FrameBuf[ISO15693_ADDR_FLAGS] = ISO15693_RES_FLAG_NO_ERROR; /* flags */
|
|
|
|
|
ResponseByteCount += 1;
|
|
|
|
|
return ResponseByteCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint16_t EM4233_Lock_DSFID(uint8_t* FrameBuf, uint16_t FrameBytes)
|
|
|
|
|
{
|
|
|
|
|
uint16_t ResponseByteCount = ISO15693_APP_NO_RESPONSE;
|
|
|
|
|
uint8_t LockStatus = 0;
|
|
|
|
|
|
|
|
|
|
if (FrameInfo.ParamLen != 0)
|
|
|
|
|
return ISO15693_APP_NO_RESPONSE; /* malformed: not enough or too much data */
|
|
|
|
|
|
|
|
|
|
MemoryReadBlock(&LockStatus, EM4233_MEM_INF_ADDRESS, 1);
|
|
|
|
|
|
|
|
|
|
if (LockStatus & EM4233_MASK_DSFID_STATUS ) { /* The afi is already locked */
|
|
|
|
|
FrameBuf[ISO15693_ADDR_FLAGS] = ISO15693_RES_FLAG_ERROR;
|
|
|
|
|
FrameBuf[ISO15693_RES_ADDR_PARAM] = ISO15693_RES_ERR_GENERIC;
|
|
|
|
|
ResponseByteCount += 2;
|
|
|
|
|
return ResponseByteCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LockStatus |= EM4233_MASK_DSFID_STATUS;
|
|
|
|
|
|
|
|
|
|
MemoryWriteBlock(&LockStatus, EM4233_MEM_INF_ADDRESS, 1); /* Actually write new AFI */
|
|
|
|
|
|
|
|
|
|
FrameBuf[ISO15693_ADDR_FLAGS] = ISO15693_RES_FLAG_NO_ERROR; /* flags */
|
|
|
|
|
ResponseByteCount += 1;
|
|
|
|
|
return ResponseByteCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint8_t EM4233_Get_SysInfo(uint8_t* FrameBuf, uint16_t FrameBytes)
|
|
|
|
|
{
|
|
|
|
|
uint16_t ResponseByteCount = ISO15693_APP_NO_RESPONSE;
|
|
|
|
|
uint8_t FramePtr; /* holds the address where block's data will be put */
|
|
|
|
|
|
|
|
|
|
if (FrameInfo.ParamLen != 0)
|
|
|
|
|
return ISO15693_APP_NO_RESPONSE; /* malformed: not enough or too much data */
|
|
|
|
|
|
|
|
|
|
FramePtr = 1;
|
|
|
|
|
|
|
|
|
|
/* I've no idea how this request could generate errors ._.
|
|
|
|
|
if ( ) {
|
|
|
|
|
FrameBuf[ISO15693_ADDR_FLAGS] = ISO15693_RES_FLAG_ERROR;
|
|
|
|
|
FrameBuf[ISO15693_RES_ADDR_PARAM] = ISO15693_RES_ERR_GENERIC;
|
|
|
|
|
ResponseByteCount += 2;
|
|
|
|
|
return ResponseByteCount;
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* System info flags */
|
|
|
|
|
FrameBuf[FramePtr] = EM4233_SYSINFO_BYTE; /* check pdf for this */
|
|
|
|
|
FramePtr += 1; /* Move forward the buffer data pointer */
|
|
|
|
|
ResponseByteCount += 1; /* Increment the response count */
|
|
|
|
|
|
|
|
|
|
/* Then append UID */
|
|
|
|
|
uint8_t Uid[ActiveConfiguration.UidSize];
|
|
|
|
|
EM4233GetUid(Uid);
|
|
|
|
|
ISO15693CopyUid(&FrameBuf[FramePtr], Uid);
|
|
|
|
|
FramePtr += ISO15693_GENERIC_UID_SIZE; /* Move forward the buffer data pointer */
|
|
|
|
|
ResponseByteCount += ISO15693_GENERIC_UID_SIZE; /* Increment the response count */
|
|
|
|
|
|
|
|
|
|
/* Append DSFID */
|
|
|
|
|
if ( EM4233_SYSINFO_BYTE & ( 1 << 0 )) {
|
|
|
|
|
MemoryReadBlock(&FrameBuf[FramePtr], EM4233_MEM_DSFID_ADDRESS, 1);
|
|
|
|
|
FramePtr += 1; /* Move forward the buffer data pointer */
|
|
|
|
|
ResponseByteCount += 1; /* Increment the response count */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Append AFI */
|
|
|
|
|
if ( EM4233_SYSINFO_BYTE & ( 1 << 1 )) {
|
|
|
|
|
MemoryReadBlock(&FrameBuf[FramePtr], EM4233_MEM_AFI_ADDRESS, 1);
|
|
|
|
|
FramePtr += 1; /* Move forward the buffer data pointer */
|
|
|
|
|
ResponseByteCount += 1; /* Increment the response count */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Append VICC memory size */
|
|
|
|
|
if ( EM4233_SYSINFO_BYTE & ( 1 << 2 )) {
|
|
|
|
|
FrameBuf[FramePtr] = EM4233_NUMBER_OF_BLCKS - 0x01;
|
|
|
|
|
FramePtr += 1; /* Move forward the buffer data pointer */
|
|
|
|
|
ResponseByteCount += 1; /* Increment the response count */
|
|
|
|
|
|
|
|
|
|
FrameBuf[FramePtr] = EM4233_BYTES_PER_BLCK - 0x01;
|
|
|
|
|
FramePtr += 1; /* Move forward the buffer data pointer */
|
|
|
|
|
ResponseByteCount += 1; /* Increment the response count */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Append IC reference */
|
|
|
|
|
if ( EM4233_SYSINFO_BYTE & ( 1 << 3 )) {
|
|
|
|
|
FrameBuf[FramePtr] = EM4233_IC_REFERENCE;
|
|
|
|
|
FramePtr += 1; /* Move forward the buffer data pointer */
|
|
|
|
|
ResponseByteCount += 1; /* Increment the response count */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FrameBuf[ISO15693_ADDR_FLAGS] = ISO15693_RES_FLAG_NO_ERROR; /* flags */
|
|
|
|
|
MemoryReadBlock(FramePtr, PageAddress * EM4233_BYTES_PER_BLCK, EM4233_BYTES_PER_BLCK);
|
|
|
|
|
ResponseByteCount += 1;
|
|
|
|
|
return ResponseByteCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint16_t EM4233_Get_Multi_Block_Sec_Stat(uint8_t* FrameBuf, uint16_t FrameBytes)
|
|
|
|
|
{
|
|
|
|
|
uint16_t ResponseByteCount = ISO15693_APP_NO_RESPONSE;
|
|
|
|
|
uint8_t FramePtr; /* holds the address where block's data will be put */
|
|
|
|
|
uint8_t BlockAddress = FrameInfo.Parameters[0];
|
|
|
|
|
uint8_t BlocksNumber = 0;
|
|
|
|
|
uint8_t LockStatus = 0;
|
|
|
|
|
|
|
|
|
|
if (FrameInfo.ParamLen != 2)
|
|
|
|
|
return ISO15693_APP_NO_RESPONSE; /* malformed: not enough or too much data */
|
|
|
|
|
|
|
|
|
|
BlocksNumber = FrameInfo.Parameters[1];
|
|
|
|
|
|
|
|
|
|
if (BlockAddress >= EM4233_NUMBER_OF_BLCKS || (BlockAddress + BlocksNumber) >= EM4233_NUMBER_OF_BLCKS) { /* the reader is requesting a sector out of bound */
|
|
|
|
|
FrameBuf[ISO15693_ADDR_FLAGS] = ISO15693_RES_FLAG_ERROR;
|
|
|
|
|
FrameBuf[ISO15693_RES_ADDR_PARAM] = ISO15693_RES_ERR_BLK_NOT_AVL; /* real TiTag standard reply with this error */
|
|
|
|
|
ResponseByteCount += 2;
|
|
|
|
|
return ResponseByteCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FramePtr = 1; /* Start of response data */
|
|
|
|
|
|
|
|
|
|
for (uint8_t blk = 0; blk <= BlocksNumber; blk++) {
|
|
|
|
|
|
|
|
|
|
MemoryReadBlock(&LockStatus, (EM4233_MEM_LSM_ADDRESS + (BlockAddress + blk)), 1);
|
|
|
|
|
|
|
|
|
|
if (LockStatus & ISO15693_MASK_FACTORY_LOCK) { /* tests if the n-th bit of the factory bitmask if set to 1 */
|
|
|
|
|
FrameBuf[FramePtr] = 0x02; /* return bit 1 set as 1 (factory locked) */
|
|
|
|
|
} else if (LockStatus & ISO15693_MASK_USER_LOCK) { /* tests if the n-th bit of the user bitmask if set to 1 */
|
|
|
|
|
FrameBuf[FramePtr] = 0x01; /* return bit 0 set as 1 (user locked) */
|
|
|
|
|
} else
|
|
|
|
|
FrameBuf[FramePtr] = 0x00; /* return lock status 00 (unlocked) */
|
|
|
|
|
|
|
|
|
|
FramePtr += 1; /* Move forward the buffer data pointer */
|
|
|
|
|
ResponseByteCount += 1; /* Increment the response count */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FrameBuf[ISO15693_ADDR_FLAGS] = ISO15693_RES_FLAG_NO_ERROR; /* flags */
|
|
|
|
|
ResponseByteCount += 1;
|
|
|
|
|
return ResponseByteCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -175,7 +432,7 @@ uint16_t EM4233AppProcess(uint8_t* FrameBuf, uint16_t FrameBytes)
|
|
|
|
|
case STATE_READY:
|
|
|
|
|
if (*FrameInfo.Command == ISO15693_CMD_INVENTORY) {
|
|
|
|
|
FrameBuf[ISO15693_ADDR_FLAGS] = ISO15693_RES_FLAG_NO_ERROR;
|
|
|
|
|
FrameBuf[ISO15693_RES_ADDR_PARAM] = ISO15693_RES_INVENTORY_DSFID;
|
|
|
|
|
MemoryReadBlock(&FrameBuf[ISO15693_RES_ADDR_PARAM], EM4233_MEM_DSFID_ADDRESS, 1);
|
|
|
|
|
ISO15693CopyUid(&FrameBuf[ISO15693_RES_ADDR_PARAM + 0x01], Uid);
|
|
|
|
|
ResponseByteCount = 10;
|
|
|
|
|
|
|
|
|
@@ -191,6 +448,27 @@ uint16_t EM4233AppProcess(uint8_t* FrameBuf, uint16_t FrameBytes)
|
|
|
|
|
} else if (*FrameInfo.Command == ISO15693_CMD_LOCK_BLOCK) {
|
|
|
|
|
ResponseByteCount = EM4233_Lock_Block(FrameBuf, FrameBytes);
|
|
|
|
|
|
|
|
|
|
} else if (*FrameInfo.Command == ISO15693_CMD_READ_MULTIPLE) {
|
|
|
|
|
ResponseByteCount = EM4233_Read_Multiple(FrameBuf, FrameBytes);
|
|
|
|
|
|
|
|
|
|
} else if (*FrameInfo.Command == ISO15693_CMD_WRITE_AFI) {
|
|
|
|
|
ResponseByteCount = EM4233_Write_AFI(FrameBuf, FrameBytes);
|
|
|
|
|
|
|
|
|
|
} else if (*FrameInfo.Command == ISO15693_CMD_LOCK_AFI) {
|
|
|
|
|
ResponseByteCount = EM4233_Lock_AFI(FrameBuf, FrameBytes);
|
|
|
|
|
|
|
|
|
|
} else if (*FrameInfo.Command == ISO15693_CMD_WRITE_DSFID) {
|
|
|
|
|
ResponseByteCount = EM4233_Write_DSFID(FrameBuf, FrameBytes);
|
|
|
|
|
|
|
|
|
|
} else if (*FrameInfo.Command == ISO15693_CMD_LOCK_DSFID) {
|
|
|
|
|
ResponseByteCount = EM4233_Lock_DSFID(FrameBuf, FrameBytes);
|
|
|
|
|
|
|
|
|
|
} else if (*FrameInfo.Command == ISO15693_CMD_GET_SYS_INFO) {
|
|
|
|
|
ResponseByteCount = EM4233_Get_SysInfo(FrameBuf, FrameBytes);
|
|
|
|
|
|
|
|
|
|
} else if (*FrameInfo.Command == ISO15693_CMD_GET_BLOCK_SEC) {
|
|
|
|
|
ResponseByteCount = EM4233_Get_Multi_Block_Sec_Stat(FrameBuf, FrameBytes);
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
FrameBuf[ISO15693_ADDR_FLAGS] = ISO15693_RES_FLAG_ERROR;
|
|
|
|
|
FrameBuf[ISO15693_RES_ADDR_PARAM] = ISO15693_RES_ERR_NOT_SUPP;
|
|
|
|
@@ -198,10 +476,6 @@ uint16_t EM4233AppProcess(uint8_t* FrameBuf, uint16_t FrameBytes)
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case STATE_SELECTED:
|
|
|
|
|
/* TO-DO */
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case STATE_QUIET:
|
|
|
|
|
if (*FrameInfo.Command == ISO15693_CMD_RESET_TO_READY) {
|
|
|
|
|
FrameBuf[ISO15693_ADDR_FLAGS] = ISO15693_RES_FLAG_NO_ERROR;
|
|
|
|
@@ -213,6 +487,7 @@ uint16_t EM4233AppProcess(uint8_t* FrameBuf, uint16_t FrameBytes)
|
|
|
|
|
FrameInfo.Parameters = NULL;
|
|
|
|
|
FrameInfo.ParamLen = 0;
|
|
|
|
|
FrameInfo.Addressed = false;
|
|
|
|
|
FrameInfo.Selected = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|