2010-10-19 22:25:17 +08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
|
|
|
|
// at your option, any later version. See the LICENSE.txt file for the text of
|
|
|
|
// the license.
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// ISO15693 CRC & other commons
|
|
|
|
//-----------------------------------------------------------------------------
|
2016-08-05 03:52:32 +08:00
|
|
|
#include "iso15693tools.h"
|
2014-09-12 05:23:46 +08:00
|
|
|
|
2010-10-19 22:25:17 +08:00
|
|
|
// The CRC as described in ISO 15693-Part 3-Annex C
|
2018-01-29 22:55:56 +08:00
|
|
|
uint16_t Iso15693Crc(uint8_t *d, size_t n){
|
|
|
|
init_table(CRC_15);
|
|
|
|
return crc16_x25(d, n);
|
|
|
|
}
|
2010-10-19 22:25:17 +08:00
|
|
|
|
|
|
|
// adds a CRC to a dataframe
|
2018-01-29 22:55:56 +08:00
|
|
|
// d[] iso15963 frame without crc
|
|
|
|
// n length without crc
|
2010-10-19 22:25:17 +08:00
|
|
|
// returns the new length of the dataframe.
|
2018-01-29 22:55:56 +08:00
|
|
|
int Iso15693AddCrc(uint8_t *d, size_t n) {
|
|
|
|
uint16_t crc = Iso15693Crc(d, n);
|
|
|
|
d[n] = crc & 0xff;
|
|
|
|
d[n+1] = crc >> 8;
|
|
|
|
return n + 2;
|
2010-10-19 22:25:17 +08:00
|
|
|
}
|
|
|
|
|
2018-01-17 04:07:58 +08:00
|
|
|
// check the CRC as described in ISO 15693-Part 3-Annex C
|
|
|
|
// v buffer with data
|
|
|
|
// n length (including crc)
|
2018-01-29 22:55:56 +08:00
|
|
|
// If calculated with crc bytes, the residue should be 0xF0B8
|
|
|
|
bool Iso15693CheckCrc(uint8_t *d, size_t n) {
|
|
|
|
return (Iso15693Crc(d, n) == ISO15_CRC_CHECK );
|
2018-01-17 04:07:58 +08:00
|
|
|
}
|
|
|
|
|
2010-10-19 22:25:17 +08:00
|
|
|
int sprintf(char *str, const char *format, ...);
|
|
|
|
|
|
|
|
// returns a string representation of the UID
|
|
|
|
// UID is transmitted and stored LSB first, displayed MSB first
|
|
|
|
// target char* buffer, where to put the UID, if NULL a static buffer is returned
|
|
|
|
// uid[] the UID in transmission order
|
|
|
|
// return: ptr to string
|
2016-10-11 03:54:26 +08:00
|
|
|
char* Iso15693sprintUID(char *target, uint8_t *uid) {
|
2017-09-05 14:25:23 +08:00
|
|
|
|
2016-10-11 03:54:26 +08:00
|
|
|
static char tempbuf[2*8+1] = {0};
|
2017-09-04 19:56:57 +08:00
|
|
|
if (target == NULL)
|
|
|
|
target = tempbuf;
|
2017-09-05 14:25:23 +08:00
|
|
|
sprintf(target, "%02X %02X %02X %02X %02X %02X %02X %02X",
|
2017-09-04 19:56:57 +08:00
|
|
|
uid[7], uid[6], uid[5], uid[4],
|
|
|
|
uid[3], uid[2], uid[1], uid[0]
|
|
|
|
);
|
2016-08-05 03:52:32 +08:00
|
|
|
return target;
|
2018-01-17 04:07:58 +08:00
|
|
|
}
|