\r
if(BUTTON_PRESS()) return FALSE;\r
\r
- if(SSC_STATUS & (SSC_STATUS_TX_READY)) {\r
- SSC_TRANSMIT_HOLDING = 0x00;\r
+ if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) {\r
+ AT91C_BASE_SSC->SSC_THR = 0x00;\r
}\r
- if(SSC_STATUS & (SSC_STATUS_RX_READY)) {\r
- BYTE b = (BYTE)SSC_RECEIVE_HOLDING;\r
+ if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {\r
+ BYTE b = (BYTE)AT91C_BASE_SSC->SSC_RHR;\r
\r
mask = 0x80;\r
for(i = 0; i < 8; i++, mask >>= 1) {\r
LED_D_OFF();\r
FpgaWriteConfWord(\r
FPGA_MAJOR_MODE_HF_SIMULATOR | FPGA_HF_SIMULATOR_MODULATE_BPSK);\r
- SSC_TRANSMIT_HOLDING = 0xff;\r
+ AT91C_BASE_SSC->SSC_THR = 0xff;\r
FpgaSetupSsc();\r
\r
// Transmit the response.\r
i = 0;\r
for(;;) {\r
- if(SSC_STATUS & (SSC_STATUS_TX_READY)) {\r
+ if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) {\r
BYTE b = resp[i];\r
\r
- SSC_TRANSMIT_HOLDING = b;\r
+ AT91C_BASE_SSC->SSC_THR = b;\r
\r
i++;\r
if(i > respLen) {\r
break;\r
}\r
}\r
- if(SSC_STATUS & (SSC_STATUS_RX_READY)) {\r
- volatile BYTE b = (BYTE)SSC_RECEIVE_HOLDING;\r
+ if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {\r
+ volatile BYTE b = (BYTE)AT91C_BASE_SSC->SSC_RHR;\r
(void)b;\r
}\r
}\r
*\r
* Returns: true if we received a EOF\r
* false if we are still waiting for some more\r
- *
+ *\r
*/\r
static BOOL Handle14443SamplesDemod(int ci, int cq)\r
{\r
* Demodulate the samples we received from the tag\r
* weTx: set to 'TRUE' if we behave like a reader\r
* set to 'FALSE' if we behave like a snooper\r
- * quiet: set to 'TRUE' to disable debug output
+ * quiet: set to 'TRUE' to disable debug output\r
*/\r
static void GetSamplesFor14443Demod(BOOL weTx, int n, BOOL quiet)\r
{\r
(weTx ? 0 : FPGA_HF_READER_RX_XCORR_SNOOP));\r
\r
for(;;) {\r
- int behindBy = lastRxCounter - PDC_RX_COUNTER(SSC_BASE);\r
+ int behindBy = lastRxCounter - AT91C_BASE_PDC_SSC->PDC_RCR;\r
if(behindBy > max) max = behindBy;\r
\r
- while(((lastRxCounter-PDC_RX_COUNTER(SSC_BASE)) & (DMA_BUFFER_SIZE-1))\r
+ while(((lastRxCounter-AT91C_BASE_PDC_SSC->PDC_RCR) & (DMA_BUFFER_SIZE-1))\r
> 2)\r
{\r
ci = upTo[0];\r
upTo += 2;\r
if(upTo - dmaBuf > DMA_BUFFER_SIZE) {\r
upTo -= DMA_BUFFER_SIZE;\r
- PDC_RX_NEXT_POINTER(SSC_BASE) = (DWORD)upTo;\r
- PDC_RX_NEXT_COUNTER(SSC_BASE) = DMA_BUFFER_SIZE;\r
+ AT91C_BASE_PDC_SSC->PDC_RNPR = (DWORD)upTo;\r
+ AT91C_BASE_PDC_SSC->PDC_RNCR = DMA_BUFFER_SIZE;\r
}\r
lastRxCounter -= 2;\r
if(lastRxCounter <= 0) {\r
break;\r
}\r
}\r
- PDC_CONTROL(SSC_BASE) = PDC_RX_DISABLE;\r
+ AT91C_BASE_PDC_SSC->PDC_PTCR = AT91C_PDC_RXTDIS;\r
if (!quiet) DbpIntegers(max, gotFrame, Demod.len);\r
}\r
\r
\r
c = 0;\r
for(;;) {\r
- if(SSC_STATUS & (SSC_STATUS_TX_READY)) {\r
- SSC_TRANSMIT_HOLDING = 0x43;\r
+ if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) {\r
+ AT91C_BASE_SSC->SSC_THR = 0x43;\r
}\r
- if(SSC_STATUS & (SSC_STATUS_RX_READY)) {\r
+ if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {\r
SBYTE b;\r
- b = (SBYTE)SSC_RECEIVE_HOLDING;\r
+ b = (SBYTE)AT91C_BASE_SSC->SSC_RHR;\r
\r
dest[c++] = (BYTE)b;\r
\r
\r
FpgaSetupSsc();\r
\r
- while(SSC_STATUS & (SSC_STATUS_TX_READY)) {\r
- SSC_TRANSMIT_HOLDING = 0xff;\r
+ while(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) {\r
+ AT91C_BASE_SSC->SSC_THR = 0xff;\r
}\r
\r
// Signal field is ON with the appropriate Red LED\r
FPGA_MAJOR_MODE_HF_READER_TX | FPGA_HF_READER_TX_SHALLOW_MOD);\r
\r
for(c = 0; c < 10;) {\r
- if(SSC_STATUS & (SSC_STATUS_TX_READY)) {\r
- SSC_TRANSMIT_HOLDING = 0xff;\r
+ if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) {\r
+ AT91C_BASE_SSC->SSC_THR = 0xff;\r
c++;\r
}\r
- if(SSC_STATUS & (SSC_STATUS_RX_READY)) {\r
- volatile DWORD r = SSC_RECEIVE_HOLDING;\r
+ if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {\r
+ volatile DWORD r = AT91C_BASE_SSC->SSC_RHR;\r
(void)r;\r
}\r
WDT_HIT();\r
\r
c = 0;\r
for(;;) {\r
- if(SSC_STATUS & (SSC_STATUS_TX_READY)) {\r
- SSC_TRANSMIT_HOLDING = ToSend[c];\r
+ if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) {\r
+ AT91C_BASE_SSC->SSC_THR = ToSend[c];\r
c++;\r
if(c >= ToSendMax) {\r
break;\r
}\r
}\r
- if(SSC_STATUS & (SSC_STATUS_RX_READY)) {\r
- volatile DWORD r = SSC_RECEIVE_HOLDING;\r
+ if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {\r
+ volatile DWORD r = AT91C_BASE_SSC->SSC_RHR;\r
(void)r;\r
}\r
WDT_HIT();\r
\r
//-----------------------------------------------------------------------------\r
// Read an ISO 14443 tag. We send it some set of commands, and record the\r
-// responses.
-// The command name is misleading, it actually decodes the reponse in HEX
+// responses.\r
+// The command name is misleading, it actually decodes the reponse in HEX\r
// into the output buffer (read the result using hexsamples, not hisamples)\r
//-----------------------------------------------------------------------------\r
void AcquireRawAdcSamplesIso14443(DWORD parameter)\r
GetSamplesFor14443Demod(TRUE, 2000, FALSE);\r
// LED_A_OFF();\r
}\r
-
+\r
//-----------------------------------------------------------------------------\r
// Read a SRI512 ISO 14443 tag.\r
-//
-// SRI512 tags are just simple memory tags, here we're looking at making a dump
-// of the contents of the memory. No anticollision algorithm is done, we assume
-// we have a single tag in the field.
-//
+//\r
+// SRI512 tags are just simple memory tags, here we're looking at making a dump\r
+// of the contents of the memory. No anticollision algorithm is done, we assume\r
+// we have a single tag in the field.\r
+//\r
// I tried to be systematic and check every answer of the tag, every CRC, etc...\r
//-----------------------------------------------------------------------------\r
void ReadSRI512Iso14443(DWORD parameter)\r
{\r
- BYTE i = 0x00;
+ ReadSTMemoryIso14443(parameter,0x0F);
+}
+void ReadSRIX4KIso14443(DWORD parameter)
+{
+ ReadSTMemoryIso14443(parameter,0x7F);
+}
+
+void ReadSTMemoryIso14443(DWORD parameter,DWORD dwLast)
+{
+ BYTE i = 0x00;\r
\r
// Make sure that we start from off, since the tags are stateful;\r
// confusing things will happen if we don't reset them between reads.\r
FpgaWriteConfWord(\r
FPGA_MAJOR_MODE_HF_READER_RX_XCORR | FPGA_HF_READER_RX_XCORR_848_KHZ);\r
SpinDelay(200);\r
-
+\r
// First command: wake up the tag using the INITIATE command\r
BYTE cmd1[] = { 0x06, 0x00, 0x97, 0x5b};\r
CodeIso14443bAsReader(cmd1, sizeof(cmd1));\r
// LED_A_ON();\r
GetSamplesFor14443Demod(TRUE, 2000,TRUE);\r
// LED_A_OFF();\r
-
- if (Demod.len == 0) {
- DbpString("No response from tag");
- return;
- } else {
- DbpString("Randomly generated UID from tag (+ 2 byte CRC):");
- DbpIntegers(Demod.output[0], Demod.output[1],Demod.output[2]);
- }
- // There is a response, SELECT the uid
- DbpString("Now SELECT tag:");
- cmd1[0] = 0x0E; // 0x0E is SELECT
- cmd1[1] = Demod.output[0];
+\r
+ if (Demod.len == 0) {\r
+ DbpString("No response from tag");\r
+ return;\r
+ } else {\r
+ DbpString("Randomly generated UID from tag (+ 2 byte CRC):");\r
+ DbpIntegers(Demod.output[0], Demod.output[1],Demod.output[2]);\r
+ }\r
+ // There is a response, SELECT the uid\r
+ DbpString("Now SELECT tag:");\r
+ cmd1[0] = 0x0E; // 0x0E is SELECT\r
+ cmd1[1] = Demod.output[0];\r
ComputeCrc14443(CRC_14443_B, cmd1, 2, &cmd1[2], &cmd1[3]);\r
CodeIso14443bAsReader(cmd1, sizeof(cmd1));\r
TransmitFor14443();\r
// LED_A_ON();\r
GetSamplesFor14443Demod(TRUE, 2000,TRUE);\r
// LED_A_OFF();\r
- if (Demod.len != 3) {
- DbpString("Expected 3 bytes from tag, got:");
- DbpIntegers(Demod.len,0x0,0x0);
- return;
- }
- // Check the CRC of the answer:
+ if (Demod.len != 3) {\r
+ DbpString("Expected 3 bytes from tag, got:");\r
+ DbpIntegers(Demod.len,0x0,0x0);\r
+ return;\r
+ }\r
+ // Check the CRC of the answer:\r
ComputeCrc14443(CRC_14443_B, Demod.output, 1 , &cmd1[2], &cmd1[3]);\r
if(cmd1[2] != Demod.output[1] || cmd1[3] != Demod.output[2]) {\r
- DbpString("CRC Error reading select response.");
- return;
- }
- // Check response from the tag: should be the same UID as the command we just sent:
- if (cmd1[1] != Demod.output[0]) {
- DbpString("Bad response to SELECT from Tag, aborting:");
- DbpIntegers(cmd1[1],Demod.output[0],0x0);
- return;
- }
- // Tag is now selected,
- // First get the tag's UID:
- cmd1[0] = 0x0B;
- ComputeCrc14443(CRC_14443_B, cmd1, 1 , &cmd1[1], &cmd1[2]);
+ DbpString("CRC Error reading select response.");\r
+ return;\r
+ }\r
+ // Check response from the tag: should be the same UID as the command we just sent:\r
+ if (cmd1[1] != Demod.output[0]) {\r
+ DbpString("Bad response to SELECT from Tag, aborting:");\r
+ DbpIntegers(cmd1[1],Demod.output[0],0x0);\r
+ return;\r
+ }\r
+ // Tag is now selected,\r
+ // First get the tag's UID:\r
+ cmd1[0] = 0x0B;\r
+ ComputeCrc14443(CRC_14443_B, cmd1, 1 , &cmd1[1], &cmd1[2]);\r
CodeIso14443bAsReader(cmd1, 3); // Only first three bytes for this one\r
TransmitFor14443();\r
// LED_A_ON();\r
GetSamplesFor14443Demod(TRUE, 2000,TRUE);\r
// LED_A_OFF();\r
- if (Demod.len != 10) {
- DbpString("Expected 10 bytes from tag, got:");
- DbpIntegers(Demod.len,0x0,0x0);
- return;
- }
- // The check the CRC of the answer (use cmd1 as temporary variable):
+ if (Demod.len != 10) {\r
+ DbpString("Expected 10 bytes from tag, got:");\r
+ DbpIntegers(Demod.len,0x0,0x0);\r
+ return;\r
+ }\r
+ // The check the CRC of the answer (use cmd1 as temporary variable):\r
ComputeCrc14443(CRC_14443_B, Demod.output, 8, &cmd1[2], &cmd1[3]);\r
if(cmd1[2] != Demod.output[8] || cmd1[3] != Demod.output[9]) {\r
- DbpString("CRC Error reading block! - Below: expected, got");
- DbpIntegers( (cmd1[2]<<8)+cmd1[3], (Demod.output[8]<<8)+Demod.output[9],0);
- // Do not return;, let's go on... (we should retry, maybe ?)
- }
- DbpString("Tag UID (64 bits):");
- DbpIntegers((Demod.output[7]<<24) + (Demod.output[6]<<16) + (Demod.output[5]<<8) + Demod.output[4], (Demod.output[3]<<24) + (Demod.output[2]<<16) + (Demod.output[1]<<8) + Demod.output[0], 0);
-
- // Now loop to read all 16 blocks, address from 0 to 15
- DbpString("Tag memory dump, block 0 to 15");
- cmd1[0] = 0x08;
- i = 0x00;
- for (;;) {
- if (i == 0x10) {
- DbpString("System area block (0xff):");
- i = 0xff;
- }
- cmd1[1] = i;
+ DbpString("CRC Error reading block! - Below: expected, got");\r
+ DbpIntegers( (cmd1[2]<<8)+cmd1[3], (Demod.output[8]<<8)+Demod.output[9],0);\r
+ // Do not return;, let's go on... (we should retry, maybe ?)\r
+ }\r
+ DbpString("Tag UID (64 bits):");\r
+ DbpIntegers((Demod.output[7]<<24) + (Demod.output[6]<<16) + (Demod.output[5]<<8) + Demod.output[4], (Demod.output[3]<<24) + (Demod.output[2]<<16) + (Demod.output[1]<<8) + Demod.output[0], 0);\r
+\r
+ // Now loop to read all 16 blocks, address from 0 to 15\r
+ DbpString("Tag memory dump, block 0 to 15");\r
+ cmd1[0] = 0x08;\r
+ i = 0x00;\r
+ dwLast++;
+ for (;;) {\r
+ if (i == dwLast) {
+ DbpString("System area block (0xff):");\r
+ i = 0xff;\r
+ }\r
+ cmd1[1] = i;\r
ComputeCrc14443(CRC_14443_B, cmd1, 2, &cmd1[2], &cmd1[3]);\r
CodeIso14443bAsReader(cmd1, sizeof(cmd1));\r
TransmitFor14443();\r
// LED_A_ON();\r
GetSamplesFor14443Demod(TRUE, 2000,TRUE);\r
-// LED_A_OFF();
- if (Demod.len != 6) { // Check if we got an answer from the tag
- DbpString("Expected 6 bytes from tag, got less...");
- return;
- }
- // The check the CRC of the answer (use cmd1 as temporary variable):
+// LED_A_OFF();\r
+ if (Demod.len != 6) { // Check if we got an answer from the tag\r
+ DbpString("Expected 6 bytes from tag, got less...");\r
+ return;\r
+ }\r
+ // The check the CRC of the answer (use cmd1 as temporary variable):\r
ComputeCrc14443(CRC_14443_B, Demod.output, 4, &cmd1[2], &cmd1[3]);\r
if(cmd1[2] != Demod.output[4] || cmd1[3] != Demod.output[5]) {\r
- DbpString("CRC Error reading block! - Below: expected, got");
- DbpIntegers( (cmd1[2]<<8)+cmd1[3], (Demod.output[4]<<8)+Demod.output[5],0);
- // Do not return;, let's go on... (we should retry, maybe ?)
- }
- // Now print out the memory location:
- DbpString("Address , Contents, CRC");
- DbpIntegers(i, (Demod.output[3]<<24) + (Demod.output[2]<<16) + (Demod.output[1]<<8) + Demod.output[0], (Demod.output[4]<<8)+Demod.output[5]);
- if (i == 0xff) {
- break;
- }
- i++;
- }
+ DbpString("CRC Error reading block! - Below: expected, got");\r
+ DbpIntegers( (cmd1[2]<<8)+cmd1[3], (Demod.output[4]<<8)+Demod.output[5],0);\r
+ // Do not return;, let's go on... (we should retry, maybe ?)\r
+ }\r
+ // Now print out the memory location:\r
+ DbpString("Address , Contents, CRC");\r
+ DbpIntegers(i, (Demod.output[3]<<24) + (Demod.output[2]<<16) + (Demod.output[1]<<8) + Demod.output[0], (Demod.output[4]<<8)+Demod.output[5]);\r
+ if (i == 0xff) {\r
+ break;\r
+ }\r
+ i++;\r
+ }\r
}\r
-
+\r
\r
//=============================================================================\r
// Finally, the `sniffer' combines elements from both the reader and\r
* 0-1023 : Demodulated samples receive (1024 bytes)\r
* 1024-1535 : Last Received command, 512 bytes (reader->tag)\r
* 1536-2047 : Last Received command, 512 bytes(tag->reader)\r
- * 2048-2304 : DMA Buffer, 256 bytes (samples)
+ * 2048-2304 : DMA Buffer, 256 bytes (samples)\r
*/\r
void SnoopIso14443(void)\r
{\r
FpgaSetupSscDma((BYTE *)dmaBuf, DMA_BUFFER_SIZE);\r
// And now we loop, receiving samples.\r
for(;;) {\r
- int behindBy = (lastRxCounter - PDC_RX_COUNTER(SSC_BASE)) &\r
+ int behindBy = (lastRxCounter - AT91C_BASE_PDC_SSC->PDC_RCR) &\r
(DMA_BUFFER_SIZE-1);\r
if(behindBy > maxBehindBy) {\r
maxBehindBy = behindBy;\r
if(upTo - dmaBuf > DMA_BUFFER_SIZE) {\r
upTo -= DMA_BUFFER_SIZE;\r
lastRxCounter += DMA_BUFFER_SIZE;\r
- PDC_RX_NEXT_POINTER(SSC_BASE) = (DWORD) upTo;\r
- PDC_RX_NEXT_COUNTER(SSC_BASE) = DMA_BUFFER_SIZE;\r
+ AT91C_BASE_PDC_SSC->PDC_RNPR = (DWORD) upTo;\r
+ AT91C_BASE_PDC_SSC->PDC_RNCR = DMA_BUFFER_SIZE;\r
}\r
\r
samples += 2;\r
\r
done:\r
LED_D_OFF();\r
- PDC_CONTROL(SSC_BASE) = PDC_RX_DISABLE;\r
+ AT91C_BASE_PDC_SSC->PDC_PTCR = AT91C_PDC_RXTDIS;\r
}\r