// to the FPGA, to transmit that command to the tag.\r
//-----------------------------------------------------------------------------\r
\r
- \r
-\r
-\r
// The sampling rate is 106.353 ksps/s, for T = 18.8 us\r
\r
- // SOF defined as \r
+ // SOF defined as\r
// 1) Unmodulated time of 56.64us\r
// 2) 24 pulses of 423.75khz\r
// 3) logic '1' (unmodulated for 18.88us followed by 8 pulses of 423.75khz)\r
1, 1, 1, 1\r
};\r
\r
- // EOF defined as \r
+ // EOF defined as\r
// 1) logic '0' (8 pulses of 423.75khz followed by unmodulated for 18.88us)\r
// 2) 24 pulses of 423.75khz\r
// 3) Unmodulated time of 56.64us\r
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1\r
};\r
\r
-\r
-\r
-\r
static void CodeIso15693AsReader(BYTE *cmd, int n)\r
{\r
int i, j;\r
return ~reg;\r
}\r
\r
-////////////////////////////////////////// code to do 'itoa'\r
+char *strcat(char *dest, const char *src)\r
+{\r
+ size_t dest_len = strlen(dest);\r
+ size_t i;\r
+ \r
+ for (i = 0 ; src[i] != '\0' ; i++)\r
+ dest[dest_len + i] = src[i];\r
+ dest[dest_len + i] = '\0';\r
\r
+ return dest;\r
+}\r
\r
+////////////////////////////////////////// code to do 'itoa'\r
\r
/* reverse: reverse string s in place */\r
void reverse(char s[])\r
s[i++] = '-';\r
s[i] = '\0';\r
reverse(s);\r
-} \r
+}\r
\r
//////////////////////////////////////// END 'itoa' CODE\r
\r
-\r
//-----------------------------------------------------------------------------\r
// Encode (into the ToSend buffers) an identify request, which is the first\r
// thing that you must send to a tag to get a response.\r
WORD crc;\r
// one sub-carrier, inventory, 1 slot, fast rate\r
// AFI is at bit 5 (1<<4) when doing an INVENTORY\r
- cmd[0] = (1 << 2) | (1 << 5) | (1 << 1); \r
+ cmd[0] = (1 << 2) | (1 << 5) | (1 << 1);\r
// inventory command code\r
cmd[1] = 0x01;\r
// no mask\r
cmd[5] = 0x01;\r
cmd[6] = 0x00;\r
cmd[7] = 0x10;\r
- cmd[8] = 0x05; \r
- cmd[9]= 0xe0; // always e0 (not exactly unique) \r
+ cmd[8] = 0x05;\r
+ cmd[9]= 0xe0; // always e0 (not exactly unique)\r
//Now the CRC\r
- crc = Crc(cmd, 10); // the crc needs to be calculated over 2 bytes \r
+ crc = Crc(cmd, 10); // the crc needs to be calculated over 2 bytes\r
cmd[10] = crc & 0xff;\r
cmd[11] = crc >> 8;\r
\r
\r
static void BuildSelectRequest( BYTE uid[])\r
{\r
- \r
+\r
// uid[6]=0x31; // this is getting ignored - the uid array is not happening...\r
BYTE cmd[12];\r
\r
// cmd[5] = uid[3];//0x01;\r
// cmd[6] = uid[4];//0x00;\r
// cmd[7] = uid[5];//0x10;\r
-// cmd[8] = uid[6];//0x05; \r
+// cmd[8] = uid[6];//0x05;\r
cmd[2] = 0x32;//\r
- cmd[3]= 0x4b;\r
+ cmd[3] = 0x4b;\r
cmd[4] = 0x03;\r
cmd[5] = 0x01;\r
cmd[6] = 0x00;\r
cmd[7] = 0x10;\r
cmd[8] = 0x05; // infineon?\r
\r
- cmd[9]= 0xe0; // always e0 (not exactly unique) \r
+ cmd[9]= 0xe0; // always e0 (not exactly unique)\r
\r
// DbpIntegers(cmd[8],cmd[7],cmd[6]);\r
// Now the CRC\r
- crc = Crc(cmd, 10); // the crc needs to be calculated over 10 bytes \r
+ crc = Crc(cmd, 10); // the crc needs to be calculated over 10 bytes\r
cmd[10] = crc & 0xff;\r
cmd[11] = crc >> 8;\r
\r
cmd[5] = 0x01;\r
cmd[6] = 0x00;\r
cmd[7] = 0x10;\r
- cmd[8] = 0x05; \r
- cmd[9]= 0xe0; // always e0 (not exactly unique) \r
+ cmd[8] = 0x05;\r
+ cmd[9]= 0xe0; // always e0 (not exactly unique)\r
// Block number to read\r
cmd[10] = blockNumber;//0x00;\r
//Now the CRC\r
- crc = Crc(cmd, 11); // the crc needs to be calculated over 2 bytes \r
+ crc = Crc(cmd, 11); // the crc needs to be calculated over 2 bytes\r
cmd[11] = crc & 0xff;\r
cmd[12] = crc >> 8;\r
\r
CodeIso15693AsReader(cmd, sizeof(cmd));\r
}\r
\r
-\r
static void BuildReadMultiBlockRequest(BYTE *uid)\r
{\r
BYTE cmd[14];\r
cmd[5] = 0x01;\r
cmd[6] = 0x00;\r
cmd[7] = 0x10;\r
- cmd[8] = 0x05; \r
- cmd[9]= 0xe0; // always e0 (not exactly unique) \r
+ cmd[8] = 0x05;\r
+ cmd[9]= 0xe0; // always e0 (not exactly unique)\r
// First Block number to read\r
cmd[10] = 0x00;\r
// Number of Blocks to read\r
cmd[11] = 0x2f; // read quite a few\r
//Now the CRC\r
- crc = Crc(cmd, 12); // the crc needs to be calculated over 2 bytes \r
+ crc = Crc(cmd, 12); // the crc needs to be calculated over 2 bytes\r
cmd[12] = crc & 0xff;\r
cmd[13] = crc >> 8;\r
\r
cmd[5] = 0x01;\r
cmd[6] = 0x00;\r
cmd[7] = 0x10;\r
- cmd[8] = 0x05; \r
- cmd[9]= 0xe0; // always e0 (not exactly unique) \r
+ cmd[8] = 0x05;\r
+ cmd[9]= 0xe0; // always e0 (not exactly unique)\r
// Parameter\r
cmd[10] = 0x00;\r
cmd[11] = 0x0a;\r
\r
// cmd[12] = 0x00;\r
// cmd[13] = 0x00; //Now the CRC\r
- crc = Crc(cmd, 12); // the crc needs to be calculated over 2 bytes \r
+ crc = Crc(cmd, 12); // the crc needs to be calculated over 2 bytes\r
cmd[12] = crc & 0xff;\r
cmd[13] = crc >> 8;\r
\r
CodeIso15693AsReader(cmd, sizeof(cmd));\r
}\r
\r
-static void BuildArbitraryCustomRequest(BYTE *uid,BYTE CmdCode)\r
+static void BuildArbitraryCustomRequest(BYTE uid[], BYTE CmdCode)\r
{\r
BYTE cmd[14];\r
\r
cmd[5] = 0x01;\r
cmd[6] = 0x00;\r
cmd[7] = 0x10;\r
- cmd[8] = 0x05; \r
- cmd[9]= 0xe0; // always e0 (not exactly unique) \r
+ cmd[8] = 0x05;\r
+ cmd[9]= 0xe0; // always e0 (not exactly unique)\r
// Parameter\r
cmd[10] = 0x05; // for custom codes this must be manufcturer code\r
cmd[11] = 0x00;\r
\r
// cmd[12] = 0x00;\r
// cmd[13] = 0x00; //Now the CRC\r
- crc = Crc(cmd, 12); // the crc needs to be calculated over 2 bytes \r
+ crc = Crc(cmd, 12); // the crc needs to be calculated over 2 bytes\r
cmd[12] = crc & 0xff;\r
cmd[13] = crc >> 8;\r
\r
WORD crc;\r
// one sub-carrier, inventory, 1 slot, fast rate\r
// AFI is at bit 5 (1<<4) when doing an INVENTORY\r
- cmd[0] = 0; //(1 << 2) | (1 << 5) | (1 << 1); \r
+ cmd[0] = 0; //(1 << 2) | (1 << 5) | (1 << 1);\r
cmd[1] = 0;\r
// 64-bit UID\r
cmd[2] = 0x32;\r
cmd[5] = 0x01;\r
cmd[6] = 0x00;\r
cmd[7] = 0x10;\r
- cmd[8] = 0x05; \r
+ cmd[8] = 0x05;\r
cmd[9]= 0xe0;\r
//Now the CRC\r
crc = Crc(cmd, 10);\r
CodeIso15693AsReader(cmd, sizeof(cmd));\r
}\r
\r
-\r
//-----------------------------------------------------------------------------\r
// Transmit the command (to the tag) that was placed in ToSend[].\r
//-----------------------------------------------------------------------------\r
*samples = (c + *wait) << 3;\r
}\r
\r
-\r
//-----------------------------------------------------------------------------\r
// Transmit the command (to the reader) that was placed in ToSend[].\r
//-----------------------------------------------------------------------------\r
*samples = (c + *wait) << 3;\r
}\r
\r
-\r
-\r
-\r
-\r
-\r
-static int GetIso15693AnswerFromTag(BYTE *receivedResponse, int maxLen, int *samples, int *elapsed) \r
+static int GetIso15693AnswerFromTag(BYTE *receivedResponse, int maxLen, int *samples, int *elapsed)\r
{\r
int c = 0;\r
BYTE *dest = (BYTE *)BigBuf;\r
int getNext = 0;\r
\r
-\r
SBYTE prev = 0;\r
\r
// NOW READ RESPONSE\r
//////////////////////////////////////////\r
\r
int i, j;\r
- int max = 0, maxPos;\r
+ int max = 0, maxPos=0;\r
\r
int skip = 4;\r
\r
-\r
// if(GraphTraceLen < 1000) return; // THIS CHECKS FOR A BUFFER TO SMALL\r
\r
// First, correlate for SOF\r
int k = 0; // this will be our return value\r
\r
// greg - If correlation is less than 1 then there's little point in continuing\r
- if ((max/(arraylen(FrameSOF)/skip)) >= 1) \r
+ if ((max/(arraylen(FrameSOF)/skip)) >= 1)\r
{\r
\r
i = maxPos + arraylen(FrameSOF)/skip;\r
- \r
+\r
BYTE outBuf[20];\r
memset(outBuf, 0, sizeof(outBuf));\r
BYTE mask = 0x01;\r
\r
for(i = 0; i < k; i++) {\r
receivedResponse[i] = outBuf[i];\r
- } \r
+ }\r
} // "end if correlation > 0" (max/(arraylen(FrameSOF)/skip))\r
return k; // return the number of bytes demodulated\r
\r
/// DbpString("CRC=%04x", Iso15693Crc(outBuf, k-2));\r
\r
-\r
}\r
\r
// Now the GetISO15693 message from sniffing command\r
-static int GetIso15693AnswerFromSniff(BYTE *receivedResponse, int maxLen, int *samples, int *elapsed) \r
+static int GetIso15693AnswerFromSniff(BYTE *receivedResponse, int maxLen, int *samples, int *elapsed)\r
{\r
int c = 0;\r
BYTE *dest = (BYTE *)BigBuf;\r
int getNext = 0;\r
\r
-\r
SBYTE prev = 0;\r
\r
// NOW READ RESPONSE\r
//////////////////////////////////////////\r
\r
int i, j;\r
- int max = 0, maxPos;\r
+ int max = 0, maxPos=0;\r
\r
int skip = 4;\r
\r
-\r
// if(GraphTraceLen < 1000) return; // THIS CHECKS FOR A BUFFER TO SMALL\r
\r
// First, correlate for SOF\r
int k = 0; // this will be our return value\r
\r
// greg - If correlation is less than 1 then there's little point in continuing\r
- if ((max/(arraylen(FrameSOF)/skip)) >= 1) // THIS SHOULD BE 1 \r
+ if ((max/(arraylen(FrameSOF)/skip)) >= 1) // THIS SHOULD BE 1\r
{\r
\r
i = maxPos + arraylen(FrameSOF)/skip;\r
- \r
+\r
BYTE outBuf[20];\r
memset(outBuf, 0, sizeof(outBuf));\r
BYTE mask = 0x01;\r
\r
for(i = 0; i < k; i++) {\r
receivedResponse[i] = outBuf[i];\r
- } \r
+ }\r
} // "end if correlation > 0" (max/(arraylen(FrameSOF)/skip))\r
return k; // return the number of bytes demodulated\r
\r
/// DbpString("CRC=%04x", Iso15693Crc(outBuf, k-2));\r
-\r
-\r
}\r
\r
-\r
-\r
//-----------------------------------------------------------------------------\r
// Start to read an ISO 15693 tag. We send an identify request, then wait\r
// for the response. The response is not demodulated, just left in the buffer\r
}\r
}\r
\r
-\r
-\r
//-----------------------------------------------------------------------------\r
// Simulate an ISO15693 reader, perform anti-collision and then attempt to read a sector\r
// all demodulation performed in arm rather than host. - greg\r
LED_C_OFF();\r
LED_D_OFF();\r
\r
-\r
//DbpString(parameter);\r
\r
BYTE *receivedAnswer0 = (((BYTE *)BigBuf) + 3560); // allow 100 bytes per reponse (way too much)\r
- BYTE *receivedAnswer1 = (((BYTE *)BigBuf) + 3660); // \r
+ BYTE *receivedAnswer1 = (((BYTE *)BigBuf) + 3660); //\r
BYTE *receivedAnswer2 = (((BYTE *)BigBuf) + 3760);\r
BYTE *receivedAnswer3 = (((BYTE *)BigBuf) + 3860);\r
- //BYTE *TagUID= (((BYTE *)BigBuf) + 3960); // where we hold the uid for hi15reader \r
- int responseLen0 = 0;\r
+ //BYTE *TagUID= (((BYTE *)BigBuf) + 3960); // where we hold the uid for hi15reader\r
+// int responseLen0 = 0;\r
int responseLen1 = 0;\r
int responseLen2 = 0;\r
int responseLen3 = 0;\r
\r
// FIRST WE RUN AN INVENTORY TO GET THE TAG UID\r
// THIS MEANS WE CAN PRE-BUILD REQUESTS TO SAVE CPU TIME\r
- BYTE TagUID[7]; // where we hold the uid for hi15reader \r
-\r
+ BYTE TagUID[7]; // where we hold the uid for hi15reader\r
\r
// BuildIdentifyRequest();\r
-// //TransmitTo15693Tag(ToSend,ToSendMax+3,&tsamples, &wait); \r
+// //TransmitTo15693Tag(ToSend,ToSendMax+3,&tsamples, &wait);\r
// TransmitTo15693Tag(ToSend,ToSendMax,&tsamples, &wait); // No longer ToSendMax+3\r
// // Now wait for a response\r
-// responseLen0 = GetIso15693AnswerFromTag(receivedAnswer0, 100, &samples, &elapsed) ; \r
+// responseLen0 = GetIso15693AnswerFromTag(receivedAnswer0, 100, &samples, &elapsed) ;\r
// if (responseLen0 >=12) // we should do a better check than this\r
// {\r
// // really we should check it is a valid mesg\r
// TagUID[4] = receivedAnswer0[6];\r
// TagUID[5] = receivedAnswer0[7];\r
// TagUID[6] = receivedAnswer0[8]; // IC Manufacturer code\r
-// DbpIntegers(TagUID[6],TagUID[5],TagUID[4]); \r
+// DbpIntegers(TagUID[6],TagUID[5],TagUID[4]);\r
//}\r
\r
// Now send the IDENTIFY command\r
BuildIdentifyRequest();\r
- //TransmitTo15693Tag(ToSend,ToSendMax+3,&tsamples, &wait); \r
+ //TransmitTo15693Tag(ToSend,ToSendMax+3,&tsamples, &wait);\r
TransmitTo15693Tag(ToSend,ToSendMax,&tsamples, &wait); // No longer ToSendMax+3\r
// Now wait for a response\r
responseLen1 = GetIso15693AnswerFromTag(receivedAnswer1, 100, &samples, &elapsed) ;\r
- \r
+\r
if (responseLen1 >=12) // we should do a better check than this\r
{\r
- \r
+\r
TagUID[0] = receivedAnswer1[2];\r
TagUID[1] = receivedAnswer1[3];\r
TagUID[2] = receivedAnswer1[4];\r
TagUID[4] = receivedAnswer1[6];\r
TagUID[5] = receivedAnswer1[7];\r
TagUID[6] = receivedAnswer1[8]; // IC Manufacturer code\r
- \r
+\r
// Now send the SELECT command\r
- BuildSelectRequest(*TagUID);\r
+ BuildSelectRequest(TagUID);\r
TransmitTo15693Tag(ToSend,ToSendMax,&tsamples, &wait); // No longer ToSendMax+3\r
// Now wait for a response\r
- responseLen2 = GetIso15693AnswerFromTag(receivedAnswer2, 100, &samples, &elapsed); \r
+ responseLen2 = GetIso15693AnswerFromTag(receivedAnswer2, 100, &samples, &elapsed);\r
\r
// Now send the MULTI READ command\r
// BuildArbitraryRequest(*TagUID,parameter);\r
- BuildArbitraryCustomRequest(*TagUID,parameter);\r
+ BuildArbitraryCustomRequest(TagUID,parameter);\r
// BuildReadBlockRequest(*TagUID,parameter);\r
// BuildSysInfoRequest(*TagUID);\r
- //TransmitTo15693Tag(ToSend,ToSendMax+3,&tsamples, &wait); \r
- TransmitTo15693Tag(ToSend,ToSendMax,&tsamples, &wait); // No longer ToSendMax+3 \r
+ //TransmitTo15693Tag(ToSend,ToSendMax+3,&tsamples, &wait);\r
+ TransmitTo15693Tag(ToSend,ToSendMax,&tsamples, &wait); // No longer ToSendMax+3\r
// Now wait for a response\r
responseLen3 = GetIso15693AnswerFromTag(receivedAnswer3, 100, &samples, &elapsed) ;\r
\r
}\r
\r
-\r
-\r
- BYTE str1 [4];\r
+ char str1 [4];\r
//char str2 [200];\r
int i;\r
\r
for(i = 0; i < responseLen3; i+=3) {\r
DbpIntegers(receivedAnswer3[i],receivedAnswer3[i+1],receivedAnswer3[i+2]);\r
}\r
- \r
\r
// str2[0]=0;\r
// for(i = 0; i < responseLen3; i++) {\r
// itoa(str1,receivedAnswer3[i]);\r
// strcat(str2,str1);\r
// }\r
-// DbpString(str2); \r
+// DbpString(str2);\r
\r
LED_A_OFF();\r
LED_B_OFF();\r
LED_C_OFF();\r
LED_D_OFF();\r
-\r
-\r
}\r
\r
-\r
-\r
//-----------------------------------------------------------------------------\r
// Simulate an ISO15693 TAG, perform anti-collision and then print any reader commands\r
// all demodulation performed in arm rather than host. - greg\r
LED_C_OFF();\r
LED_D_OFF();\r
\r
-\r
//DbpString(parameter);\r
\r
BYTE *receivedAnswer0 = (((BYTE *)BigBuf) + 3560); // allow 100 bytes per reponse (way too much)\r
- BYTE *receivedAnswer1 = (((BYTE *)BigBuf) + 3660); // \r
+ BYTE *receivedAnswer1 = (((BYTE *)BigBuf) + 3660); //\r
BYTE *receivedAnswer2 = (((BYTE *)BigBuf) + 3760);\r
BYTE *receivedAnswer3 = (((BYTE *)BigBuf) + 3860);\r
- //BYTE *TagUID= (((BYTE *)BigBuf) + 3960); // where we hold the uid for hi15reader \r
- int responseLen0 = 0;\r
+ //BYTE *TagUID= (((BYTE *)BigBuf) + 3960); // where we hold the uid for hi15reader\r
+// int responseLen0 = 0;\r
int responseLen1 = 0;\r
- int responseLen2 = 0;\r
- int responseLen3 = 0;\r
+// int responseLen2 = 0;\r
+// int responseLen3 = 0;\r
\r
// Blank arrays\r
int j;\r
\r
// FIRST WE RUN AN INVENTORY TO GET THE TAG UID\r
// THIS MEANS WE CAN PRE-BUILD REQUESTS TO SAVE CPU TIME\r
- BYTE TagUID[7]; // where we hold the uid for hi15reader \r
-\r
-\r
+ // BYTE TagUID[7]; // where we hold the uid for hi15reader\r
\r
// Now send the IDENTIFY command\r
-// BuildIdentifyRequest();\r
-// TransmitTo15693Tag(ToSend,ToSendMax,&tsamples, &wait); // No longer ToSendMax+3\r
-\r
+ // BuildIdentifyRequest();\r
+ // TransmitTo15693Tag(ToSend,ToSendMax,&tsamples, &wait); // No longer ToSendMax+3\r
\r
// Now wait for a command from the reader\r
responseLen1=0;\r
-// while(responseLen1=0) {\r
-// if(BUTTON_PRESS()) break;\r
+ // while(responseLen1=0) {\r
+ // if(BUTTON_PRESS()) break;\r
responseLen1 = GetIso15693AnswerFromSniff(receivedAnswer1, 100, &samples, &elapsed) ;\r
-// }\r
+ // }\r
\r
- \r
if (responseLen1 >=1) // we should do a better check than this\r
{\r
// Build a suitable reponse to the reader INVENTORY cocmmand\r
- BuildInventoryResponse;\r
+ BuildInventoryResponse();\r
TransmitTo15693Reader(ToSend,ToSendMax,&tsamples, &wait);\r
\r
// Now wait for a command from the reader\r
-// responseLen2 = GetIso15693AnswerFromTag(receivedAnswer2, 100, &samples, &elapsed); \r
+// responseLen2 = GetIso15693AnswerFromTag(receivedAnswer2, 100, &samples, &elapsed);\r
\r
- \r
// Now wait for a command from the reader\r
// responseLen3 = GetIso15693AnswerFromTag(receivedAnswer3, 100, &samples, &elapsed) ;\r
\r
}\r
\r
-\r
-\r
- BYTE str1 [4];\r
+ char str1 [4];\r
//char str2 [200];\r
int i;\r
\r
// for(i = 0; i < responseLen3; i+=3) {\r
// DbpIntegers(receivedAnswer3[i],receivedAnswer3[i+1],receivedAnswer3[i+2]);\r
// }\r
- \r
\r
// str2[0]=0;\r
// for(i = 0; i < responseLen3; i++) {\r
// itoa(str1,receivedAnswer3[i]);\r
// strcat(str2,str1);\r
// }\r
-// DbpString(str2); \r
+// DbpString(str2);\r
\r
LED_A_OFF();\r
LED_B_OFF();\r
LED_C_OFF();\r
LED_D_OFF();\r
-\r
-\r
-}
\ No newline at end of file
+}\r