Skip to content

Commit

Permalink
Handle HALT properly
Browse files Browse the repository at this point in the history
  • Loading branch information
doegox committed Oct 20, 2016
1 parent c586b3d commit f56f270
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
6 changes: 4 additions & 2 deletions Firmware/Chameleon-Mini/Application/ISO14443-3A.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,12 @@ bool ISO14443ASelect(void* Buffer, uint16_t* BitCount, uint8_t* UidCL, uint8_t S
}
}

bool ISO14443AWakeUp(void* Buffer, uint16_t* BitCount, uint16_t ATQAValue)
bool ISO14443AWakeUp(void* Buffer, uint16_t* BitCount, uint16_t ATQAValue, bool FromHalt)
{
uint8_t* DataPtr = (uint8_t*) Buffer;

if ( (DataPtr[0] == ISO14443A_CMD_REQA) || (DataPtr[0] == ISO14443A_CMD_WUPA) ){
if ( ((! FromHalt) && (DataPtr[0] == ISO14443A_CMD_REQA)) ||
(DataPtr[0] == ISO14443A_CMD_WUPA) ){
DataPtr[0] = (ATQAValue >> 0) & 0x00FF;
DataPtr[1] = (ATQAValue >> 8) & 0x00FF;

Expand All @@ -153,4 +154,5 @@ bool ISO14443AWakeUp(void* Buffer, uint16_t* BitCount, uint16_t ATQAValue)
return false;
}
}

#endif
7 changes: 4 additions & 3 deletions Firmware/Chameleon-Mini/Application/ISO14443-3A.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void ISO14443AAppendCRCA(void* Buffer, uint16_t ByteCount);
bool ISO14443ACheckCRCA(void* Buffer, uint16_t ByteCount);

INLINE bool ISO14443ASelect(void* Buffer, uint16_t* BitCount, uint8_t* UidCL, uint8_t SAKValue);
INLINE bool ISO14443AWakeUp(void* Buffer, uint16_t* BitCount, uint16_t ATQAValue);
INLINE bool ISO14443AWakeUp(void* Buffer, uint16_t* BitCount, uint16_t ATQAValue, bool FromHalt);

INLINE
bool ISO14443ASelect(void* Buffer, uint16_t* BitCount, uint8_t* UidCL, uint8_t SAKValue)
Expand Down Expand Up @@ -98,11 +98,12 @@ bool ISO14443ASelect(void* Buffer, uint16_t* BitCount, uint8_t* UidCL, uint8_t S
}

INLINE
bool ISO14443AWakeUp(void* Buffer, uint16_t* BitCount, uint16_t ATQAValue)
bool ISO14443AWakeUp(void* Buffer, uint16_t* BitCount, uint16_t ATQAValue, bool FromHalt)
{
uint8_t* DataPtr = (uint8_t*) Buffer;

if ( (DataPtr[0] == ISO14443A_CMD_REQA) || (DataPtr[0] == ISO14443A_CMD_WUPA) ){
if ( ((! FromHalt) && (DataPtr[0] == ISO14443A_CMD_REQA)) ||
(DataPtr[0] == ISO14443A_CMD_WUPA) ){
DataPtr[0] = (ATQAValue >> 0) & 0x00FF;
DataPtr[1] = (ATQAValue >> 8) & 0x00FF;

Expand Down
8 changes: 4 additions & 4 deletions Firmware/Chameleon-Mini/Application/MifareClassic.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ uint16_t MifareClassicAppProcess(uint8_t* Buffer, uint16_t BitCount)
switch(State) {
case STATE_IDLE:
case STATE_HALT:
if (ISO14443AWakeUp(Buffer, &BitCount, CardATQAValue)) {
if (ISO14443AWakeUp(Buffer, &BitCount, CardATQAValue, State == STATE_HALT)) {
State = STATE_READY1;
return BitCount;
}
Expand Down Expand Up @@ -252,7 +252,7 @@ uint16_t MifareClassicAppProcess(uint8_t* Buffer, uint16_t BitCount)
#endif

case STATE_READY1:
if (ISO14443AWakeUp(Buffer, &BitCount, CardATQAValue)) {
if (ISO14443AWakeUp(Buffer, &BitCount, CardATQAValue, false)) {
State = STATE_READY1;
return BitCount;
} else if (Buffer[0] == ISO14443A_CMD_SELECT_CL1) {
Expand All @@ -278,7 +278,7 @@ uint16_t MifareClassicAppProcess(uint8_t* Buffer, uint16_t BitCount)
break;

case STATE_READY2:
if (ISO14443AWakeUp(Buffer, &BitCount, CardATQAValue)) {
if (ISO14443AWakeUp(Buffer, &BitCount, CardATQAValue, false)) {
State = STATE_READY1;
return BitCount;
} else if (Buffer[0] == ISO14443A_CMD_SELECT_CL2) {
Expand All @@ -297,7 +297,7 @@ uint16_t MifareClassicAppProcess(uint8_t* Buffer, uint16_t BitCount)
}
break;
case STATE_ACTIVE:
if (ISO14443AWakeUp(Buffer, &BitCount, MFCLASSIC_1K_ATQA_VALUE)) {
if (ISO14443AWakeUp(Buffer, &BitCount, MFCLASSIC_1K_ATQA_VALUE, false)) {
State = STATE_READY1;
return BitCount;
} else if (Buffer[0] == CMD_HALT) {
Expand Down
8 changes: 4 additions & 4 deletions Firmware/Chameleon-Mini/Application/MifareUltralight.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ uint16_t MifareUltralightAppProcess(uint8_t* Buffer, uint16_t BitCount)
switch(State) {
case STATE_IDLE:
case STATE_HALT:
if (ISO14443AWakeUp(Buffer, &BitCount, ATQA_VALUE)) {
if (ISO14443AWakeUp(Buffer, &BitCount, ATQA_VALUE, State == STATE_HALT)) {
/* We received a REQA or WUPA command, so wake up. */
State = STATE_READY1;
return BitCount;
}
break;

case STATE_READY1:
if (ISO14443AWakeUp(Buffer, &BitCount, ATQA_VALUE)) {
if (ISO14443AWakeUp(Buffer, &BitCount, ATQA_VALUE, false)) {
State = STATE_READY1;
return BitCount;
} else if (Cmd == ISO14443A_CMD_SELECT_CL1) {
Expand All @@ -118,7 +118,7 @@ uint16_t MifareUltralightAppProcess(uint8_t* Buffer, uint16_t BitCount)
break;

case STATE_READY2:
if (ISO14443AWakeUp(Buffer, &BitCount, ATQA_VALUE)) {
if (ISO14443AWakeUp(Buffer, &BitCount, ATQA_VALUE, false)) {
State = STATE_READY1;
return BitCount;
} else if (Cmd == ISO14443A_CMD_SELECT_CL2) {
Expand All @@ -141,7 +141,7 @@ uint16_t MifareUltralightAppProcess(uint8_t* Buffer, uint16_t BitCount)
break;

case STATE_ACTIVE:
if (ISO14443AWakeUp(Buffer, &BitCount, ATQA_VALUE)) {
if (ISO14443AWakeUp(Buffer, &BitCount, ATQA_VALUE, false)) {
State = STATE_READY1;
return BitCount;
} else if (Cmd == CMD_READ) {
Expand Down

0 comments on commit f56f270

Please sign in to comment.