Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added ISO15693 emulation codec #136

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 0 additions & 45 deletions Firmware/Chameleon-Mini/.cproject

This file was deleted.

26 changes: 0 additions & 26 deletions Firmware/Chameleon-Mini/.project

This file was deleted.

3 changes: 3 additions & 0 deletions Firmware/Chameleon-Mini/Application/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
#include "MifareUltralight.h"
#include "MifareClassic.h"
#include "Reader14443A.h"
#include "Vicinity.h"
#include "Sl2s2002.h"


/* Function wrappers */
INLINE void ApplicationInit(void) {
Expand Down
52 changes: 52 additions & 0 deletions Firmware/Chameleon-Mini/Application/ISO15693-A.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include "ISO15693-A.h"
#include "../Common.h"
#include <util/crc16.h>

//Refer to ISO/IEC 15693-3:2001 page 41
uint16_t calculateCRC(void* FrameBuf, uint16_t FrameBufSize)
{
uint16_t reg = ISO15693_CRC16_PRESET;
uint8_t i, j;

uint8_t *DataPtr = (uint8_t *)FrameBuf;

for(i = 0; i < FrameBufSize; i++) {
reg = reg ^ *DataPtr++;
for (j = 0; j < 8; j++) {
if (reg & 0x0001) {
reg = (reg >> 1) ^ ISO15693_CRC16_POLYNORMAL;
} else {
reg = (reg >> 1);
}
}
}

return ~reg;
}

void ISO15693AppendCRC(uint8_t* FrameBuf, uint16_t FrameBufSize)
{
uint16_t crc;

crc = calculateCRC(FrameBuf, FrameBufSize);

uint8_t crcLb = crc & 0xFF;
uint8_t crcHb = crc >> 8;


FrameBuf[FrameBufSize] = crcLb;
FrameBuf[FrameBufSize + 1] = crcHb;
}

bool ISO15693CheckCRC(void* FrameBuf, uint16_t FrameBufSize)
{
uint16_t crc;
uint8_t *DataPtr = (uint8_t *)FrameBuf;

crc = calculateCRC(DataPtr, FrameBufSize);

uint8_t crcLb = crc & 0xFF;
uint8_t crcHb = crc >> 8;

return (DataPtr[FrameBufSize] == crcLb && DataPtr[FrameBufSize + 1] == crcHb);
}
104 changes: 104 additions & 0 deletions Firmware/Chameleon-Mini/Application/ISO15693-A.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* ISO15693-3.h
*
* Created on: 24.08.2013
* Author: skuser
*/

#ifndef ISO15693_3_H_
#define ISO15693_3_H_

#include "../Common.h"

#define ISO15693_CMD_INVENTORY 0x01
#define ISO15693_CMD_STAY_QUIET 0x02
#define ISO15693_CMD_READ_SINGLE 0x20
#define ISO15693_CMD_WRITE_SINGLE 0x21
#define ISO15693_CMD_LOCK_BLOCK 0x22
#define ISO15693_CMD_READ_MULTIPLE 0x23
#define ISO15693_CMD_WRITE_MULTIPLE 0x24
#define ISO15693_CMD_SELECT 0x25
#define ISO15693_CMD_RESET_TO_READY 0x26
#define ISO15693_CMD_WRITE_AFI 0x27
#define ISO15693_CMD_LOCK_AFI 0x28
#define ISO15693_CMD_WRITE_DSFID 0x29
#define ISO15693_CMD_LOCK_DSFID 0x2A
#define ISO15693_CMD_GET_SYS_INFO 0x2B
#define ISO15693_CMD_GET_BLOCK_SEC 0x2C

#define ISO15693_REQ_FLAG_SUBCARRIER 0x01
#define ISO15693_REQ_FLAG_DATARATE 0x02
#define ISO15693_REQ_FLAG_INVENTORY 0x04
#define ISO15693_REQ_FLAG_PROT_EXT 0x08
#define ISO15693_REQ_FLAG_OPTION 0x40
#define ISO15693_REQ_FLAG_RFU 0x80
/* When INVENTORY flag is not set: */
#define ISO15693_REQ_FLAG_SELECT 0x10
#define ISO15693_REQ_FLAG_ADDRESS 0x20
/* When INVENTORY flag is set: */
#define ISO15693_REQ_FLAG_AFI 0x10
#define ISO15693_REQ_FLAG_NB_SLOTS 0x20

#define ISO15693_RES_FLAG_ERROR 0x01
#define ISO15693_RES_FLAG_PROT_EXT 0x08


#define ISO15693_MIN_FRAME_SIZE 5

#define ISO15693_CRC16_SIZE 2 /* Bytes */
#define ISO15693_CRC16_POLYNORMAL 0x8408
#define ISO15693_CRC16_PRESET 0xFFFF

typedef uint8_t ISO15693UidType[8];

void ISO15693AppendCRC(uint8_t* FrameBuf, uint16_t FrameBufSize);
bool ISO15693CheckCRC(void* FrameBuf, uint16_t FrameBufSize);

INLINE
bool ISO15693CompareUid(uint8_t* Uid1, uint8_t* Uid2)
{
if ( (Uid1[0] == Uid2[0])
&& (Uid1[1] == Uid2[1])
&& (Uid1[2] == Uid2[2])
&& (Uid1[3] == Uid2[3])
&& (Uid1[4] == Uid2[4])
&& (Uid1[5] == Uid2[5])
&& (Uid1[6] == Uid2[6])
&& (Uid1[7] == Uid2[7]) ) {
return true;
} else {
return false;
}
}

INLINE
void ISO15693CopyUid(uint8_t* DstUid, uint8_t* SrcUid)
{
DstUid[0] = SrcUid[0];
DstUid[1] = SrcUid[1];
DstUid[2] = SrcUid[2];
DstUid[3] = SrcUid[3];
DstUid[4] = SrcUid[4];
DstUid[5] = SrcUid[5];
DstUid[6] = SrcUid[6];
DstUid[7] = SrcUid[7];
}

INLINE
bool ISO15693Addressed(uint8_t* Buffer, uint8_t* MyUid) {
if (Buffer[0] & ISO15693_REQ_FLAG_ADDRESS) {
/* Addressed mode */
if ( ISO15693CompareUid(&Buffer[2], MyUid) ) {
/* Our UID addressed */
return true;
} else {
/* Our UID not addressed */
return false;
}
} else {
/* Non-Addressed mode */
return true;
}
}

#endif /* ISO15693_3_H_ */
Loading