- return ~reg;
-}
-
-char *strcat(char *dest, const char *src)
-{
- size_t dest_len = strlen(dest);
- size_t i;
-
- for (i = 0 ; src[i] != '\0' ; i++)
- dest[dest_len + i] = src[i];
- dest[dest_len + i] = '\0';
-
- return dest;
-}
-
-////////////////////////////////////////// code to do 'itoa'
-
-/* reverse: reverse string s in place */
-void reverse(char s[])
-{
- int c, i, j;
-
- for (i = 0, j = strlen(s)-1; i<j; i++, j--) {
- c = s[i];
- s[i] = s[j];
- s[j] = c;
- }
-}
-
-/* itoa: convert n to characters in s */
-void itoa(int n, char s[])
-{
- int i, sign;
-
- if ((sign = n) < 0) /* record sign */
- n = -n; /* make n positive */
- i = 0;
- do { /* generate digits in reverse order */
- s[i++] = n % 10 + '0'; /* get next digit */
- } while ((n /= 10) > 0); /* delete it */
- if (sign < 0)
- s[i++] = '-';
- s[i] = '\0';
- reverse(s);
-}
-
-//////////////////////////////////////// END 'itoa' CODE
-
-//-----------------------------------------------------------------------------
-// Encode (into the ToSend buffers) an identify request, which is the first
-// thing that you must send to a tag to get a response.
-//-----------------------------------------------------------------------------
-static void BuildIdentifyRequest(void)
-{
- uint8_t cmd[5];
-
- uint16_t crc;
- // one sub-carrier, inventory, 1 slot, fast rate
- // AFI is at bit 5 (1<<4) when doing an INVENTORY
- cmd[0] = (1 << 2) | (1 << 5) | (1 << 1);
- // inventory command code
- cmd[1] = 0x01;
- // no mask
- cmd[2] = 0x00;
- //Now the CRC
- crc = Crc(cmd, 3);
- cmd[3] = crc & 0xff;
- cmd[4] = crc >> 8;
-
- CodeIso15693AsReader(cmd, sizeof(cmd));
-}
-
-static void __attribute__((unused)) BuildSysInfoRequest(uint8_t *uid)
-{
- uint8_t cmd[12];
-
- uint16_t crc;
- // If we set the Option_Flag in this request, the VICC will respond with the secuirty status of the block
- // followed by teh block data
- // one sub-carrier, inventory, 1 slot, fast rate
- cmd[0] = (1 << 5) | (1 << 1); // no SELECT bit
- // System Information command code
- cmd[1] = 0x2B;
- // UID may be optionally specified here
- // 64-bit UID
- cmd[2] = 0x32;
- cmd[3]= 0x4b;
- cmd[4] = 0x03;
- cmd[5] = 0x01;
- cmd[6] = 0x00;
- cmd[7] = 0x10;
- cmd[8] = 0x05;
- cmd[9]= 0xe0; // always e0 (not exactly unique)
- //Now the CRC
- crc = Crc(cmd, 10); // the crc needs to be calculated over 2 bytes
- cmd[10] = crc & 0xff;
- cmd[11] = crc >> 8;
-
- CodeIso15693AsReader(cmd, sizeof(cmd));
-}
-
-static void BuildSelectRequest( uint8_t uid[])
-{
-
-// uid[6]=0x31; // this is getting ignored - the uid array is not happening...
- uint8_t cmd[12];
-
- uint16_t crc;
- // one sub-carrier, inventory, 1 slot, fast rate
- //cmd[0] = (1 << 2) | (1 << 5) | (1 << 1); // INVENTROY FLAGS
- cmd[0] = (1 << 4) | (1 << 5) | (1 << 1); // Select and addressed FLAGS
- // SELECT command code
- cmd[1] = 0x25;
- // 64-bit UID
-// cmd[2] = uid[0];//0x32;
-// cmd[3]= uid[1];//0x4b;
-// cmd[4] = uid[2];//0x03;
-// cmd[5] = uid[3];//0x01;
-// cmd[6] = uid[4];//0x00;
-// cmd[7] = uid[5];//0x10;
-// cmd[8] = uid[6];//0x05;
- cmd[2] = 0x32;//
- cmd[3] = 0x4b;
- cmd[4] = 0x03;
- cmd[5] = 0x01;
- cmd[6] = 0x00;
- cmd[7] = 0x10;
- cmd[8] = 0x05; // infineon?
-
- cmd[9]= 0xe0; // always e0 (not exactly unique)
-
-// DbpIntegers(cmd[8],cmd[7],cmd[6]);
- // Now the CRC
- crc = Crc(cmd, 10); // the crc needs to be calculated over 10 bytes
- cmd[10] = crc & 0xff;
- cmd[11] = crc >> 8;
-
- CodeIso15693AsReader(cmd, sizeof(cmd));
-}
-
-static void __attribute__((unused)) BuildReadBlockRequest(uint8_t *uid, uint8_t blockNumber )
-{
- uint8_t cmd[13];
-
- uint16_t crc;
- // If we set the Option_Flag in this request, the VICC will respond with the secuirty status of the block
- // followed by teh block data
- // one sub-carrier, inventory, 1 slot, fast rate
- cmd[0] = (1 << 6)| (1 << 5) | (1 << 1); // no SELECT bit
- // READ BLOCK command code
- cmd[1] = 0x20;
- // UID may be optionally specified here
- // 64-bit UID
- cmd[2] = 0x32;
- cmd[3]= 0x4b;
- cmd[4] = 0x03;
- cmd[5] = 0x01;
- cmd[6] = 0x00;
- cmd[7] = 0x10;
- cmd[8] = 0x05;
- cmd[9]= 0xe0; // always e0 (not exactly unique)
- // Block number to read
- cmd[10] = blockNumber;//0x00;
- //Now the CRC
- crc = Crc(cmd, 11); // the crc needs to be calculated over 2 bytes
- cmd[11] = crc & 0xff;
- cmd[12] = crc >> 8;
-
- CodeIso15693AsReader(cmd, sizeof(cmd));
-}
-
-static void __attribute__((unused)) BuildReadMultiBlockRequest(uint8_t *uid)
-{
- uint8_t cmd[14];
-
- uint16_t crc;
- // If we set the Option_Flag in this request, the VICC will respond with the secuirty status of the block
- // followed by teh block data
- // one sub-carrier, inventory, 1 slot, fast rate
- cmd[0] = (1 << 5) | (1 << 1); // no SELECT bit
- // READ Multi BLOCK command code
- cmd[1] = 0x23;
- // UID may be optionally specified here
- // 64-bit UID
- cmd[2] = 0x32;
- cmd[3]= 0x4b;
- cmd[4] = 0x03;
- cmd[5] = 0x01;
- cmd[6] = 0x00;
- cmd[7] = 0x10;
- cmd[8] = 0x05;
- cmd[9]= 0xe0; // always e0 (not exactly unique)
- // First Block number to read
- cmd[10] = 0x00;
- // Number of Blocks to read
- cmd[11] = 0x2f; // read quite a few
- //Now the CRC
- crc = Crc(cmd, 12); // the crc needs to be calculated over 2 bytes
- cmd[12] = crc & 0xff;
- cmd[13] = crc >> 8;
-
- CodeIso15693AsReader(cmd, sizeof(cmd));
-}
-
-static void __attribute__((unused)) BuildArbitraryRequest(uint8_t *uid,uint8_t CmdCode)
-{
- uint8_t cmd[14];
-
- uint16_t crc;
- // If we set the Option_Flag in this request, the VICC will respond with the secuirty status of the block
- // followed by teh block data
- // one sub-carrier, inventory, 1 slot, fast rate
- cmd[0] = (1 << 5) | (1 << 1); // no SELECT bit
- // READ BLOCK command code
- cmd[1] = CmdCode;
- // UID may be optionally specified here
- // 64-bit UID
- cmd[2] = 0x32;
- cmd[3]= 0x4b;
- cmd[4] = 0x03;
- cmd[5] = 0x01;
- cmd[6] = 0x00;
- cmd[7] = 0x10;
- cmd[8] = 0x05;
- cmd[9]= 0xe0; // always e0 (not exactly unique)
- // Parameter
- cmd[10] = 0x00;
- cmd[11] = 0x0a;
-
-// cmd[12] = 0x00;
-// cmd[13] = 0x00; //Now the CRC
- crc = Crc(cmd, 12); // the crc needs to be calculated over 2 bytes
- cmd[12] = crc & 0xff;
- cmd[13] = crc >> 8;
-
- CodeIso15693AsReader(cmd, sizeof(cmd));
-}
-
-static void __attribute__((unused)) BuildArbitraryCustomRequest(uint8_t uid[], uint8_t CmdCode)
-{
- uint8_t cmd[14];
-
- uint16_t crc;
- // If we set the Option_Flag in this request, the VICC will respond with the secuirty status of the block
- // followed by teh block data
- // one sub-carrier, inventory, 1 slot, fast rate
- cmd[0] = (1 << 5) | (1 << 1); // no SELECT bit
- // READ BLOCK command code
- cmd[1] = CmdCode;
- // UID may be optionally specified here
- // 64-bit UID
- cmd[2] = 0x32;
- cmd[3]= 0x4b;
- cmd[4] = 0x03;
- cmd[5] = 0x01;
- cmd[6] = 0x00;
- cmd[7] = 0x10;
- cmd[8] = 0x05;
- cmd[9]= 0xe0; // always e0 (not exactly unique)
- // Parameter
- cmd[10] = 0x05; // for custom codes this must be manufcturer code
- cmd[11] = 0x00;
-
-// cmd[12] = 0x00;
-// cmd[13] = 0x00; //Now the CRC
- crc = Crc(cmd, 12); // the crc needs to be calculated over 2 bytes
- cmd[12] = crc & 0xff;
- cmd[13] = crc >> 8;
-
- CodeIso15693AsReader(cmd, sizeof(cmd));