2017-08-31 14:00:59 +02:00
|
|
|
/*
|
|
|
|
|
* ISO15693.c
|
|
|
|
|
*
|
|
|
|
|
* Created on: 01-03-2017
|
|
|
|
|
* Author: Phillip Nash
|
2019-11-15 10:21:40 +01:00
|
|
|
*
|
2018-11-10 20:56:17 +01:00
|
|
|
* TODO:
|
|
|
|
|
* - ISO15693AddressedLegacy should be replaced with ISO15693Addressed and appropriate check
|
|
|
|
|
* should be performed (see TITagitstandard.c) - ceres-c
|
2017-08-31 14:00:59 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "Vicinity.h"
|
|
|
|
|
#include "../Codec/ISO15693.h"
|
|
|
|
|
#include "../Memory.h"
|
|
|
|
|
#include "Crypto1.h"
|
|
|
|
|
#include "../Random.h"
|
|
|
|
|
#include "ISO15693-A.h"
|
|
|
|
|
|
2018-08-18 12:35:35 +02:00
|
|
|
#define MEM_UID_ADDRESS 0x00
|
2017-08-31 14:00:59 +02:00
|
|
|
|
|
|
|
|
static enum {
|
|
|
|
|
STATE_READY,
|
|
|
|
|
STATE_SELECTED,
|
|
|
|
|
STATE_QUIET
|
|
|
|
|
} State;
|
|
|
|
|
|
2019-11-15 10:21:40 +01:00
|
|
|
void VicinityAppInit(void) {
|
2017-08-31 14:00:59 +02:00
|
|
|
State = STATE_READY;
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-15 10:21:40 +01:00
|
|
|
void VicinityAppReset(void) {
|
2017-08-31 14:00:59 +02:00
|
|
|
State = STATE_READY;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2019-11-15 10:21:40 +01:00
|
|
|
void VicinityAppTask(void) {
|
|
|
|
|
|
2017-08-31 14:00:59 +02:00
|
|
|
}
|
|
|
|
|
|
2019-11-15 10:21:40 +01:00
|
|
|
void VicinityAppTick(void) {
|
|
|
|
|
|
2017-08-31 14:00:59 +02:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-15 10:21:40 +01:00
|
|
|
uint16_t VicinityAppProcess(uint8_t *FrameBuf, uint16_t FrameBytes) {
|
2017-08-31 14:00:59 +02:00
|
|
|
if (FrameBytes >= ISO15693_MIN_FRAME_SIZE) {
|
2019-11-15 10:21:40 +01:00
|
|
|
if (ISO15693CheckCRC(FrameBuf, FrameBytes - ISO15693_CRC16_SIZE)) {
|
2017-08-31 14:00:59 +02:00
|
|
|
// At this point, we have a valid ISO15693 frame
|
|
|
|
|
uint8_t Command = FrameBuf[1];
|
|
|
|
|
uint16_t ResponseByteCount = ISO15693_APP_NO_RESPONSE;
|
2018-08-18 12:35:35 +02:00
|
|
|
uint8_t Uid[8];
|
|
|
|
|
MemoryReadBlock(Uid, MEM_UID_ADDRESS, ActiveConfiguration.UidSize);
|
2019-11-15 10:21:40 +01:00
|
|
|
|
|
|
|
|
switch (State) {
|
|
|
|
|
case STATE_READY:
|
|
|
|
|
if (Command == ISO15693_CMD_INVENTORY) {
|
|
|
|
|
FrameBuf[0] = 0x00; /* Flags */
|
|
|
|
|
FrameBuf[1] = 0x00; /* DSFID */
|
2018-08-18 12:35:35 +02:00
|
|
|
ISO15693CopyUid(&FrameBuf[2], Uid);
|
2017-08-31 14:00:59 +02:00
|
|
|
ResponseByteCount = 10;
|
2019-11-15 10:21:40 +01:00
|
|
|
} else if (Command == ISO15693_CMD_STAY_QUIET) {
|
|
|
|
|
if (ISO15693AddressedLegacy(FrameBuf, Uid)) {
|
|
|
|
|
State = STATE_QUIET;
|
|
|
|
|
}
|
|
|
|
|
} else if (Command == ISO15693_CMD_GET_SYS_INFO) {
|
|
|
|
|
if (ISO15693AddressedLegacy(FrameBuf, Uid)) {
|
|
|
|
|
FrameBuf[0] = 0; /* Flags */
|
|
|
|
|
FrameBuf[1] = 0; /* InfoFlags */
|
|
|
|
|
ISO15693CopyUid(&FrameBuf[2], Uid);
|
|
|
|
|
ResponseByteCount = 10;
|
|
|
|
|
}
|
2017-08-31 14:00:59 +02:00
|
|
|
}
|
2019-11-15 10:21:40 +01:00
|
|
|
break;
|
2017-08-31 14:00:59 +02:00
|
|
|
|
2019-11-15 10:21:40 +01:00
|
|
|
case STATE_SELECTED:
|
2017-08-31 14:00:59 +02:00
|
|
|
|
2019-11-15 10:21:40 +01:00
|
|
|
break;
|
2017-08-31 14:00:59 +02:00
|
|
|
|
2019-11-15 10:21:40 +01:00
|
|
|
case STATE_QUIET:
|
|
|
|
|
if (Command == ISO15693_CMD_RESET_TO_READY) {
|
|
|
|
|
MemoryReadBlock(Uid, MEM_UID_ADDRESS, ActiveConfiguration.UidSize);
|
|
|
|
|
if (ISO15693AddressedLegacy(FrameBuf, Uid)) {
|
|
|
|
|
FrameBuf[0] = 0;
|
|
|
|
|
ResponseByteCount = 1;
|
|
|
|
|
State = STATE_READY;
|
|
|
|
|
}
|
2017-08-31 14:00:59 +02:00
|
|
|
}
|
2019-11-15 10:21:40 +01:00
|
|
|
break;
|
2017-08-31 14:00:59 +02:00
|
|
|
|
2019-11-15 10:21:40 +01:00
|
|
|
default:
|
|
|
|
|
break;
|
2017-08-31 14:00:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ResponseByteCount;
|
2019-11-15 10:21:40 +01:00
|
|
|
|
2017-08-31 14:00:59 +02:00
|
|
|
} else { // Invalid CRC
|
|
|
|
|
return ISO15693_APP_NO_RESPONSE;
|
|
|
|
|
}
|
|
|
|
|
} else { // Min frame size not met
|
|
|
|
|
return ISO15693_APP_NO_RESPONSE;
|
|
|
|
|
}
|
2019-11-15 10:21:40 +01:00
|
|
|
|
2017-08-31 14:00:59 +02:00
|
|
|
}
|
|
|
|
|
|
2019-11-15 10:21:40 +01:00
|
|
|
void VicinityGetUid(ConfigurationUidType Uid) {
|
2018-08-18 12:35:35 +02:00
|
|
|
MemoryReadBlock(&Uid[0], MEM_UID_ADDRESS, ActiveConfiguration.UidSize);
|
2017-08-31 14:00:59 +02:00
|
|
|
}
|
|
|
|
|
|
2019-11-15 10:21:40 +01:00
|
|
|
void VicinitySetUid(ConfigurationUidType Uid) {
|
2018-08-18 12:35:35 +02:00
|
|
|
MemoryWriteBlock(Uid, MEM_UID_ADDRESS, ActiveConfiguration.UidSize);
|
2017-08-31 14:00:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|