changing {} style to match majority of previous style

This commit is contained in:
Philippe Teuwen 2019-03-10 11:20:22 +01:00
commit 961d929f4d
320 changed files with 5502 additions and 10485 deletions

View file

@ -11,8 +11,7 @@ static uint16_t crc_table[256];
static bool crc_table_init = false;
static CrcType_t crc_type = CRC_NONE;
void init_table(CrcType_t ct)
{
void init_table(CrcType_t ct) {
// same crc algo, and initialised already
if (ct == crc_type && crc_table_init)
@ -50,8 +49,7 @@ void init_table(CrcType_t ct)
}
}
void generate_table(uint16_t polynomial, bool refin)
{
void generate_table(uint16_t polynomial, bool refin) {
uint16_t i, j, crc, c;
@ -79,16 +77,14 @@ void generate_table(uint16_t polynomial, bool refin)
crc_table_init = true;
}
void reset_table(void)
{
void reset_table(void) {
memset(crc_table, 0, sizeof(crc_table));
crc_table_init = false;
crc_type = CRC_NONE;
}
// table lookup LUT solution
uint16_t crc16_fast(uint8_t const *d, size_t n, uint16_t initval, bool refin, bool refout)
{
uint16_t crc16_fast(uint8_t const *d, size_t n, uint16_t initval, bool refin, bool refout) {
// fast lookup table algorithm without augmented zero bytes, e.g. used in pkzip.
// only usable with polynom orders of 8, 16, 24 or 32.
@ -112,8 +108,7 @@ uint16_t crc16_fast(uint8_t const *d, size_t n, uint16_t initval, bool refin, bo
}
// bit looped solution TODO REMOVED
uint16_t update_crc16_ex(uint16_t crc, uint8_t c, uint16_t polynomial)
{
uint16_t update_crc16_ex(uint16_t crc, uint8_t c, uint16_t polynomial) {
uint16_t i, v, tmp = 0;
v = (crc ^ c) & 0xff;
@ -129,14 +124,12 @@ uint16_t update_crc16_ex(uint16_t crc, uint8_t c, uint16_t polynomial)
}
return ((crc >> 8) ^ tmp) & 0xffff;
}
uint16_t update_crc16(uint16_t crc, uint8_t c)
{
uint16_t update_crc16(uint16_t crc, uint8_t c) {
return update_crc16_ex(crc, c, CRC16_POLY_CCITT);
}
// two ways. msb or lsb loop.
uint16_t crc16(uint8_t const *d, size_t length, uint16_t remainder, uint16_t polynomial, bool refin, bool refout)
{
uint16_t crc16(uint8_t const *d, size_t length, uint16_t remainder, uint16_t polynomial, bool refin, bool refout) {
if (length == 0)
return (~remainder);
@ -163,8 +156,7 @@ uint16_t crc16(uint8_t const *d, size_t length, uint16_t remainder, uint16_t pol
return remainder;
}
void compute_crc(CrcType_t ct, const uint8_t *d, size_t n, uint8_t *first, uint8_t *second)
{
void compute_crc(CrcType_t ct, const uint8_t *d, size_t n, uint8_t *first, uint8_t *second) {
// can't calc a crc on less than 1 byte
if (n == 0) return;
@ -199,8 +191,7 @@ void compute_crc(CrcType_t ct, const uint8_t *d, size_t n, uint8_t *first, uint8
*first = (crc & 0xFF);
*second = ((crc >> 8) & 0xFF);
}
uint16_t crc(CrcType_t ct, const uint8_t *d, size_t n)
{
uint16_t crc(CrcType_t ct, const uint8_t *d, size_t n) {
// can't calc a crc on less than 3 byte. (1byte + 2 crc bytes)
if (n < 3) return 0;
@ -236,8 +227,7 @@ uint16_t crc(CrcType_t ct, const uint8_t *d, size_t n)
// crc16 algos like CRC-A become 0x000
// while CRC-15693 become 0x0F47
// If calculated with crc bytes, the residue should be 0xF0B8
bool check_crc(CrcType_t ct, const uint8_t *d, size_t n)
{
bool check_crc(CrcType_t ct, const uint8_t *d, size_t n) {
// can't calc a crc on less than 3 byte. (1byte + 2 crc bytes)
if (n < 3) return false;
@ -265,22 +255,19 @@ bool check_crc(CrcType_t ct, const uint8_t *d, size_t n)
}
// poly=0x1021 init=0xffff refin=false refout=false xorout=0x0000 check=0x29b1 residue=0x0000 name="CRC-16/CCITT-FALSE"
uint16_t crc16_ccitt(uint8_t const *d, size_t n)
{
uint16_t crc16_ccitt(uint8_t const *d, size_t n) {
return crc16_fast(d, n, 0xffff, false, false);
}
// FDX-B ISO11784/85) uses KERMIT
// poly=0x1021 init=0x0000 refin=true refout=true xorout=0x0000 name="KERMIT"
uint16_t crc16_kermit(uint8_t const *d, size_t n)
{
uint16_t crc16_kermit(uint8_t const *d, size_t n) {
return crc16_fast(d, n, 0x0000, true, true);
}
// FeliCa uses XMODEM
// poly=0x1021 init=0x0000 refin=false refout=false xorout=0x0000 name="XMODEM"
uint16_t crc16_xmodem(uint8_t const *d, size_t n)
{
uint16_t crc16_xmodem(uint8_t const *d, size_t n) {
return crc16_fast(d, n, 0x0000, false, false);
}
@ -289,16 +276,14 @@ uint16_t crc16_xmodem(uint8_t const *d, size_t n)
// ISO 14443 CRC-B
// ISO/IEC 13239 (formerly ISO/IEC 3309)
// poly=0x1021 init=0xffff refin=true refout=true xorout=0xffff name="X-25"
uint16_t crc16_x25(uint8_t const *d, size_t n)
{
uint16_t crc16_x25(uint8_t const *d, size_t n) {
uint16_t crc = crc16_fast(d, n, 0xffff, true, true);
crc = ~crc;
return crc;
}
// CRC-A (14443-3)
// poly=0x1021 init=0xc6c6 refin=true refout=true xorout=0x0000 name="CRC-A"
uint16_t crc16_a(uint8_t const *d, size_t n)
{
uint16_t crc16_a(uint8_t const *d, size_t n) {
return crc16_fast(d, n, 0xC6C6, true, true);
}
@ -306,15 +291,13 @@ uint16_t crc16_a(uint8_t const *d, size_t n)
// initvalue 0x4807 reflected 0xE012
// poly 0x1021 reflected 0x8408
// poly=0x1021 init=0x4807 refin=true refout=true xorout=0x0BC3 check=0xF0B8 name="CRC-16/ICLASS"
uint16_t crc16_iclass(uint8_t const *d, size_t n)
{
uint16_t crc16_iclass(uint8_t const *d, size_t n) {
return crc16_fast(d, n, 0x4807, true, true);
}
// This CRC-16 is used in Legic Advant systems.
// poly=0xB400, init=depends refin=true refout=true xorout=0x0000 check= name="CRC-16/LEGIC"
uint16_t crc16_legic(uint8_t const *d, size_t n, uint8_t uidcrc)
{
uint16_t crc16_legic(uint8_t const *d, size_t n, uint8_t uidcrc) {
uint16_t initial = uidcrc << 8 | uidcrc;
return crc16_fast(d, n, initial, true, true);
}