Skip to content

Commit

Permalink
added anticollision
Browse files Browse the repository at this point in the history
  • Loading branch information
geo-rg committed Oct 24, 2016
1 parent 28db247 commit 2df383b
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions Firmware/Chameleon-Mini/Application/ISO14443-3A.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#define ISO14443_3A_H_

#include "../Common.h"
#include <string.h>

#define ISO14443A_UID_SIZE_SINGLE 4 /* bytes */
#define ISO14443A_UID_SIZE_DOUBLE 7
Expand Down Expand Up @@ -91,6 +92,31 @@ bool ISO14443ASelect(void* Buffer, uint16_t* BitCount, uint8_t* UidCL, uint8_t S
return false;
}
default:
{
uint8_t CollisionByteCount = ((NVB >> 4) & 0x0f) - 2;
uint8_t CollisionBitCount = (NVB >> 0) & 0x0f;
uint8_t mask = 0xFF >> (8 - CollisionBitCount);
// Since the UidCL does not contain the BCC, we have to distinguish here
if (
((CollisionByteCount == 5 || (CollisionByteCount == 4 && CollisionBitCount > 0)) && memcmp(UidCL, &DataPtr[2], 4) == 0 && (ISO14443A_CALC_BCC(UidCL) & mask) == (DataPtr[6] & mask))
||
(CollisionByteCount == 4 && CollisionBitCount == 0 && memcmp(UidCL, &DataPtr[2], 4) == 0)
||
(CollisionByteCount < 4 && memcmp(UidCL, &DataPtr[2], CollisionByteCount) == 0 && (UidCL[CollisionByteCount] & mask) == (DataPtr[CollisionByteCount + 2] & mask))
)
{
DataPtr[0] = UidCL[0];
DataPtr[1] = UidCL[1];
DataPtr[2] = UidCL[2];
DataPtr[3] = UidCL[3];
DataPtr[4] = ISO14443A_CALC_BCC(DataPtr);

*BitCount = ISO14443A_CL_FRAME_SIZE;
} else {
*BitCount = 0;
}
return false;
}
/* TODO: No anticollision supported */
*BitCount = 0;
return false;
Expand All @@ -111,6 +137,8 @@ bool ISO14443AWakeUp(void* Buffer, uint16_t* BitCount, uint16_t ATQAValue, bool

return true;
} else {
*BitCount = 0;

return false;
}
}
Expand Down

0 comments on commit 2df383b

Please sign in to comment.