Skip to content

Commit

Permalink
Merge pull request #83 from ceres-c/iso15_merge_rrg
Browse files Browse the repository at this point in the history
ISO15693 sniffing codec
  • Loading branch information
iceman1001 authored Feb 1, 2022
2 parents bea9cc4 + 59f68ac commit 17f3209
Show file tree
Hide file tree
Showing 18 changed files with 961 additions and 50 deletions.
1 change: 1 addition & 0 deletions Firmware/Chameleon-Mini/AntennaLevel.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

static inline
void AntennaLevelInit(void) {
ADCA.CAL = (PRODSIGNATURES_ADCACAL1 << 8) | PRODSIGNATURES_ADCACAL0; /* Load calibration data, source: https://www.avrfreaks.net/comment/2080211#comment-2080211 */
ADCA.CTRLA = ADC_ENABLE_bm;
ADCA.CTRLB = ADC_RESOLUTION_12BIT_gc;
ADCA.REFCTRL = ADC_REFSEL_INT1V_gc | ADC_BANDGAP_bm;
Expand Down
1 change: 1 addition & 0 deletions Firmware/Chameleon-Mini/Application/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "Sniff14443A.h"
#include "EM4233.h"
#include "NTAG215.h"
#include "Sniff15693.h"

/* Function wrappers */
INLINE void ApplicationInit(void) {
Expand Down
15 changes: 7 additions & 8 deletions Firmware/Chameleon-Mini/Application/Sniff14443A.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
extern bool checkParityBits(uint8_t *Buffer, uint16_t BitCount);

Sniff14443Command Sniff14443CurrentCommand = Sniff14443_Do_Nothing;
//bool selected = false;
static enum {
STATE_IDLE,
STATE_REQA,
Expand Down Expand Up @@ -68,7 +67,7 @@ uint16_t Sniff14443AAppProcess(uint8_t *Buffer, uint16_t BitCount) {
case STATE_REQA:
LED_PORT.OUTCLR = LED_RED;
// If received Reader REQA or WUPA
if (TrafficSource == TRAFFIC_READER &&
if (SniffTrafficSource == TRAFFIC_READER &&
(Buffer[0] == 0x26 || Buffer[0] == 0x52)) {
SniffState = STATE_ATQA;
} else {
Expand All @@ -77,7 +76,7 @@ uint16_t Sniff14443AAppProcess(uint8_t *Buffer, uint16_t BitCount) {
break;
case STATE_ATQA:
// ATQA: P RRRR XXXX P XXRX XXXX
if (TrafficSource == TRAFFIC_CARD &&
if (SniffTrafficSource == TRAFFIC_CARD &&
BitCount == 2 * 9 &&
(Buffer[0] & 0x20) == 0x00 && // Bit6 RFU shall be 0
(Buffer[1] & 0xE0) == 0x00 && // bit13-16 RFU shall be 0
Expand All @@ -88,7 +87,7 @@ uint16_t Sniff14443AAppProcess(uint8_t *Buffer, uint16_t BitCount) {
} else {
// If not ATQA, but REQA, then stay on this state,
// Reset to REQA, save the counter and reset the counter
if (TrafficSource == TRAFFIC_READER &&
if (SniffTrafficSource == TRAFFIC_READER &&
(Buffer[0] == 0x26 || Buffer[0] == 0x52)) {
} else {
// If not ATQA and not REQA then reset to REQA
Expand All @@ -98,7 +97,7 @@ uint16_t Sniff14443AAppProcess(uint8_t *Buffer, uint16_t BitCount) {
break;
case STATE_ANTICOLLI:
// SEL: 93/95/97
if (TrafficSource == TRAFFIC_READER &&
if (SniffTrafficSource == TRAFFIC_READER &&
BitCount == 2 * 8 &&
(Buffer[0] & 0xf0) == 0x90 &&
(Buffer[0] & 0x09) == 0x01) {
Expand All @@ -109,7 +108,7 @@ uint16_t Sniff14443AAppProcess(uint8_t *Buffer, uint16_t BitCount) {
}
break;
case STATE_UID:
if (TrafficSource == TRAFFIC_CARD &&
if (SniffTrafficSource == TRAFFIC_CARD &&
BitCount == 5 * 9 &&
checkParityBits(Buffer, BitCount)) {
SniffState = STATE_SELECT;
Expand All @@ -120,7 +119,7 @@ uint16_t Sniff14443AAppProcess(uint8_t *Buffer, uint16_t BitCount) {
case STATE_SELECT:

// SELECT: 9 bytes, SEL = 93/95/97, NVB=70
if (TrafficSource == TRAFFIC_READER &&
if (SniffTrafficSource == TRAFFIC_READER &&
BitCount == 9 * 8 &&
(Buffer[0] & 0xf0) == 0x90 &&
(Buffer[0] & 0x09) == 0x01 &&
Expand All @@ -133,7 +132,7 @@ uint16_t Sniff14443AAppProcess(uint8_t *Buffer, uint16_t BitCount) {
break;
case STATE_SAK:
// SAK: 1Byte SAK + CRC
if (TrafficSource == TRAFFIC_CARD &&
if (SniffTrafficSource == TRAFFIC_CARD &&
BitCount == 3 * 9 &&
checkParityBits(Buffer, BitCount)) {
if ((Buffer[0] & 0x04) == 0x00) {
Expand Down
38 changes: 38 additions & 0 deletions Firmware/Chameleon-Mini/Application/Sniff15693.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* SniffISO15693.h
*
* Created on: 05.11.2019
* Author: ceres-c
*/

#ifdef CONFIG_ISO15693_SNIFF_SUPPORT

#include "../Codec/SniffISO15693.h"
#include "Sniff15693.h"

void SniffISO15693AppInit(void)
{
}

void SniffISO15693AppReset(void)
{
}


void SniffISO15693AppTask(void)
{

}

void SniffISO15693AppTick(void)
{


}

uint16_t SniffISO15693AppProcess(uint8_t* FrameBuf, uint16_t FrameBytes)
{
return 0;
}

#endif /* CONFIG_ISO15693_SNIFF_SUPPORT */
20 changes: 20 additions & 0 deletions Firmware/Chameleon-Mini/Application/Sniff15693.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* SniffISO15693.h
*
* Created on: 05.11.2019
* Author: ceres-c
*/

#ifndef SNIFF_15693_H_
#define SNIFF_15693_H_

#include "Application.h"
#include "ISO15693-A.h"

void SniffISO15693AppInit(void);
void SniffISO15693AppReset(void);
void SniffISO15693AppTask(void);
void SniffISO15693AppTick(void);
uint16_t SniffISO15693AppProcess(uint8_t* FrameBuf, uint16_t FrameBytes);

#endif /* SNIFF_15693_H_ */
8 changes: 7 additions & 1 deletion Firmware/Chameleon-Mini/Codec/Codec.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,15 @@ static volatile struct {
uint8_t CodecBuffer[CODEC_BUFFER_SIZE];
uint8_t CodecBuffer2[CODEC_BUFFER_SIZE];

void (* volatile isr_func_CODEC_TIMER_LOADMOD_CCB_VECT)(void) = NULL;
enum RCTraffic SniffTrafficSource;

void (* volatile isr_func_TCD0_CCC_vect)(void) = NULL;
void (* volatile isr_func_CODEC_DEMOD_IN_INT0_VECT)(void) = NULL;
void (* volatile isr_func_ACA_AC0_vect)(void);
void (* volatile isr_func_CODEC_TIMER_LOADMOD_OVF_VECT)(void) = NULL;
void (* volatile isr_func_CODEC_TIMER_LOADMOD_CCA_VECT)(void) = NULL;
void (* volatile isr_func_CODEC_TIMER_LOADMOD_CCB_VECT)(void) = NULL;
void (* volatile isr_func_CODEC_TIMER_TIMESTAMPS_CCA_VECT)(void) = NULL;

// the following three functions prevent sending data directly after turning on the reader field
void CodecReaderFieldStart(void) { // DO NOT CALL THIS FUNCTION INSIDE APPLICATION!
Expand Down
21 changes: 18 additions & 3 deletions Firmware/Chameleon-Mini/Codec/Codec.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#define CODEC_SUBCARRIER_CCEN_PSK TC1_CCAEN_bm
#define CODEC_SUBCARRIER_CCEN_OOK TC1_CCBEN_bm
#define CODEC_TIMER_SAMPLING TCD0
#define CODEC_TIMER_SAMPLING_OVF_VECT TCD0_OVF_vect
#define CODEC_TIMER_SAMPLING_CCA_VECT TCD0_CCA_vect
#define CODEC_TIMER_SAMPLING_CCB_VECT TCD0_CCB_vect
#define CODEC_TIMER_SAMPLING_CCC_VECT TCD0_CCC_vect
Expand All @@ -64,6 +65,7 @@
#define CODEC_THRESHOLD_CALIBRATE_MAX 2048
#define CODEC_THRESHOLD_CALIBRATE_STEPS 16
#define CODEC_TIMER_TIMESTAMPS TCD1
#define CODEC_TIMER_TIMESTAMPS_OVF_VECT TCD1_OVF_vect
#define CODEC_TIMER_TIMESTAMPS_CCA_VECT TCD1_CCA_vect
#define CODEC_TIMER_TIMESTAMPS_CCB_VECT TCD1_CCB_vect

Expand All @@ -80,6 +82,7 @@
#include "Reader14443-2A.h"
#include "SniffISO14443-2A.h"
#include "ISO15693.h"
#include "SniffISO15693.h"

/* Timing definitions for ISO14443A */
#define ISO14443A_SUBCARRIER_DIVIDER 16
Expand Down Expand Up @@ -116,16 +119,31 @@ typedef enum {
extern uint8_t CodecBuffer[CODEC_BUFFER_SIZE];
extern uint8_t CodecBuffer2[CODEC_BUFFER_SIZE];

extern enum RCTraffic {TRAFFIC_READER, TRAFFIC_CARD} SniffTrafficSource;

/* Shared ISR pointers and handlers */
extern void (* volatile isr_func_TCD0_CCC_vect)(void);
void isr_Reader14443_2A_TCD0_CCC_vect(void);
void isr_ISO15693_CODEC_TIMER_SAMPLING_CCC_VECT(void);
extern void (* volatile isr_func_CODEC_DEMOD_IN_INT0_VECT)(void);
void isr_ISO14443_2A_TCD0_CCC_vect(void);
void isr_ISO15693_CODEC_DEMOD_IN_INT0_VECT(void);
extern void (* volatile isr_func_CODEC_TIMER_LOADMOD_OVF_VECT)(void);
void isr_ISO14443_2A_CODEC_TIMER_LOADMOD_OVF_VECT(void);
void isr_SNIFF_ISO15693_CODEC_TIMER_LOADMOD_OVF_VECT(void);
extern void (* volatile isr_func_CODEC_TIMER_LOADMOD_CCA_VECT)(void);
void isr_Reader14443_2A_CODEC_TIMER_LOADMOD_CCA_VECT(void);
void isr_SNIFF_ISO15693_CODEC_TIMER_LOADMOD_CCA_VECT(void);
extern void (* volatile isr_func_CODEC_TIMER_LOADMOD_CCB_VECT)(void);
void isr_ISO15693_CODEC_TIMER_LOADMOD_CCB_VECT(void);
void isr_SniffISO14443_2A_CODEC_TIMER_LOADMOD_CCB_VECT(void);
void isr_SNIFF_ISO15693_CODEC_TIMER_LOADMOD_CCA_VECT(void);
extern void (* volatile isr_func_CODEC_TIMER_TIMESTAMPS_CCA_VECT)(void);
void isr_Reader14443_2A_CODEC_TIMER_TIMESTAMPS_CCA_VECT(void);
void isr_SNIFF_ISO15693_CODEC_TIMER_TIMESTAMPS_CCA_VECT(void);
extern void (* volatile isr_func_ACA_AC0_vect)(void);
void isr_SniffISO14443_2A_ACA_AC0_VECT(void);
void isr_SNIFF_ISO15693_ACA_AC0_VECT(void);

INLINE void CodecInit(void) {
ActiveConfiguration.CodecInitFunc();
Expand Down Expand Up @@ -166,9 +184,6 @@ INLINE void CodecInitCommon(void) {
EVSYS.CH0MUX = CODEC_DEMOD_IN_EVMUX0;
EVSYS.CH1MUX = CODEC_DEMOD_IN_EVMUX1;

EVSYS.CH2MUX = CODEC_DEMOD_IN_EVMUX0;


/* Configure loadmod pin configuration and use a virtual port configuration
* for single instruction cycle access */
CODEC_LOADMOD_PORT.DIRSET = CODEC_LOADMOD_MASK;
Expand Down
3 changes: 2 additions & 1 deletion Firmware/Chameleon-Mini/Codec/ISO14443-2A.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ ISR(CODEC_TIMER_SAMPLING_CCA_VECT) {
}

// Enumulate as a card to send card responds
ISR(CODEC_TIMER_LOADMOD_OVF_VECT) {
ISR_SHARED isr_ISO14443_2A_CODEC_TIMER_LOADMOD_OVF_VECT(void) {
/* Bit rate timer. Output a half bit on the output. */

static void *JumpTable[] = {
Expand Down Expand Up @@ -386,6 +386,7 @@ void ISO14443ACodecInit(void) {

isr_func_TCD0_CCC_vect = &isr_Reader14443_2A_TCD0_CCC_vect;
isr_func_CODEC_DEMOD_IN_INT0_VECT = &isr_ISO14443_2A_TCD0_CCC_vect;
isr_func_CODEC_TIMER_LOADMOD_OVF_VECT = &isr_ISO14443_2A_CODEC_TIMER_LOADMOD_OVF_VECT;
CodecInitCommon();
StartDemod();
}
Expand Down
10 changes: 6 additions & 4 deletions Firmware/Chameleon-Mini/Codec/Reader14443-2A.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ void Reader14443ACodecInit(void) {
/* Initialize common peripherals and start listening
* for incoming data. */
CodecInitCommon();

// 中断回调
/* Register shared interrupt handlers */
isr_func_TCD0_CCC_vect = &isr_Reader14443_2A_TCD0_CCC_vect;
isr_func_CODEC_TIMER_LOADMOD_CCA_VECT = &isr_Reader14443_2A_CODEC_TIMER_LOADMOD_CCA_VECT;
isr_func_CODEC_TIMER_TIMESTAMPS_CCA_VECT = &isr_Reader14443_2A_CODEC_TIMER_TIMESTAMPS_CCA_VECT;
CodecSetDemodPower(true);

CODEC_TIMER_SAMPLING.PER = SAMPLE_RATE_SYSTEM_CYCLES - 1;
Expand Down Expand Up @@ -215,7 +216,7 @@ void Reader14443AMillerEOC(void) {
}

// EOC of Card->Reader found
ISR(CODEC_TIMER_TIMESTAMPS_CCA_VECT) { // EOC found
ISR_SHARED isr_Reader14443_2A_CODEC_TIMER_TIMESTAMPS_CCA_VECT(void) { // EOC found
Reader14443A_EOC();
}

Expand All @@ -231,7 +232,8 @@ ISR(ACA_AC1_vect) { // this interrupt either finds the SOC or gets triggered bef
// according to the pause and modulated period
// if the half bit duration is modulated, then add 1 to buffer
// if the half bit duration is not modulated, then add 0 to buffer
ISR(CODEC_TIMER_LOADMOD_CCA_VECT) { // pause found
// ISR(CODEC_TIMER_LOADMOD_CCA_VECT) { // pause found
ISR_SHARED isr_Reader14443_2A_CODEC_TIMER_LOADMOD_CCA_VECT(void) { // pause found
uint8_t tmp = CODEC_TIMER_TIMESTAMPS.CNTL;
CODEC_TIMER_TIMESTAMPS.CNT = 0;

Expand Down
10 changes: 4 additions & 6 deletions Firmware/Chameleon-Mini/Codec/SniffISO14443-2A.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ static volatile uint16_t ReaderBitCount;
static volatile uint16_t CardBitCount;
static volatile uint16_t rawBitCount;

enum RCTraffic TrafficSource;

INLINE void CardSniffInit(void);
INLINE void CardSniffDeinit(void);

Expand Down Expand Up @@ -347,8 +345,7 @@ INLINE void Insert1(void) {
}

// This interrupt find Card -> Reader SOC
ISR(ACA_AC0_vect) { // this interrupt either finds the SOC or gets triggered before

ISR_SHARED isr_SniffISO14443_2A_ACA_AC0_VECT (void) { // this interrupt either finds the SOC or gets triggered before
ACA.AC0CTRL &= ~AC_INTLVL_HI_gc; // disable this interrupt
// enable the pause-finding timer
CODEC_TIMER_LOADMOD.CTRLD = TC_EVACT_RESTART_gc | TC_EVSEL_CH2_gc;
Expand Down Expand Up @@ -480,6 +477,7 @@ void Sniff14443ACodecInit(void) {
#endif
// Common Codec Register settings
CodecInitCommon();
isr_func_ACA_AC0_vect = &isr_SniffISO14443_2A_ACA_AC0_VECT;
isr_func_CODEC_TIMER_LOADMOD_CCB_VECT = &isr_SniffISO14443_2A_CODEC_TIMER_LOADMOD_CCB_VECT;
// Enable demodulator power
CodecSetDemodPower(true);
Expand Down Expand Up @@ -510,7 +508,7 @@ void Sniff14443ACodecTask(void) {
// Let the Application layer know where this data comes from
LEDHook(LED_CODEC_RX, LED_PULSE);

TrafficSource = TRAFFIC_READER;
SniffTrafficSource = TRAFFIC_READER;
ApplicationProcess(CodecBuffer, ReaderBitCount);
}

Expand All @@ -523,7 +521,7 @@ void Sniff14443ACodecTask(void) {
LEDHook(LED_CODEC_RX, LED_PULSE);

// Let the Application layer know where this data comes from
TrafficSource = TRAFFIC_CARD;
SniffTrafficSource = TRAFFIC_CARD;
ApplicationProcess(CodecBuffer2, CardBitCount);
}

Expand Down
1 change: 0 additions & 1 deletion Firmware/Chameleon-Mini/Codec/SniffISO14443-2A.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "Codec.h"
#include "Terminal/CommandLine.h"

extern enum RCTraffic {TRAFFIC_READER, TRAFFIC_CARD} TrafficSource;
/* Codec Interface */
void Sniff14443ACodecInit(void);
void Sniff14443ACodecDeInit(void);
Expand Down
Loading

0 comments on commit 17f3209

Please sign in to comment.