Add support for Pyramid tags (#1676)

* Add support for Pyramid tags
* Also add additional checks for AWID decoder to avoid missdetection

* lfrfid worker: reset GPIO_LOAD pin
* lfrfid: protocol viking, format
* lfrfid: protocol pyramid, format
* lfrfid: protocol paradox, format
* lfrfid: protocol jablotron, format
* lfrfid: protocol em4100, format
* lfrfid: increase reading time by 0.5s since protocol viking takes longer to read

Co-authored-by: SG <who.just.the.doctor@gmail.com>
This commit is contained in:
Sebastian Mauer
2022-08-29 17:31:28 +01:00
committed by GitHub
parent 611b7e15ed
commit d76ba20652
12 changed files with 438 additions and 29 deletions

View File

@@ -129,6 +129,45 @@ bool bit_lib_test_parity(
return result;
}
size_t bit_lib_add_parity(
const uint8_t* data,
size_t position,
uint8_t* dest,
size_t dest_position,
uint8_t source_length,
uint8_t parity_length,
BitLibParity parity) {
uint32_t parity_word = 0;
size_t j = 0, bit_count = 0;
for(int word = 0; word < source_length; word += parity_length - 1) {
for(int bit = 0; bit < parity_length - 1; bit++) {
parity_word = (parity_word << 1) | bit_lib_get_bit(data, position + word + bit);
bit_lib_set_bit(
dest, dest_position + j++, bit_lib_get_bit(data, position + word + bit));
}
// if parity fails then return 0
switch(parity) {
case BitLibParityAlways0:
bit_lib_set_bit(dest, dest_position + j++, 0);
break; // marker bit which should be a 0
case BitLibParityAlways1:
bit_lib_set_bit(dest, dest_position + j++, 1);
break; // marker bit which should be a 1
default:
bit_lib_set_bit(
dest,
dest_position + j++,
(bit_lib_test_parity_32(parity_word, BitLibParityOdd) ^ parity) ^ 1);
break;
}
bit_count += parity_length;
parity_word = 0;
}
// if we got here then all the parities passed
// return bit count
return bit_count;
}
size_t bit_lib_remove_bit_every_nth(uint8_t* data, size_t position, uint8_t length, uint8_t n) {
size_t counter = 0;
size_t result_counter = 0;
@@ -269,6 +308,36 @@ uint8_t bit_lib_reverse_8_fast(uint8_t byte) {
return byte;
}
uint16_t bit_lib_crc8(
uint8_t const* data,
size_t data_size,
uint8_t polynom,
uint8_t init,
bool ref_in,
bool ref_out,
uint8_t xor_out) {
uint8_t crc = init;
for(size_t i = 0; i < data_size; ++i) {
uint8_t byte = data[i];
if(ref_in) bit_lib_reverse_bits(&byte, 0, 8);
crc ^= byte;
for(size_t j = 8; j > 0; --j) {
if(crc & TOPBIT(8)) {
crc = (crc << 1) ^ polynom;
} else {
crc = (crc << 1);
}
}
}
if(ref_out) bit_lib_reverse_bits(&crc, 0, 8);
crc ^= xor_out;
return crc;
}
uint16_t bit_lib_crc16(
uint8_t const* data,
size_t data_size,

View File

@@ -7,6 +7,8 @@
extern "C" {
#endif
#define TOPBIT(X) (1 << (X - 1))
typedef enum {
BitLibParityEven,
BitLibParityOdd,
@@ -114,6 +116,27 @@ bool bit_lib_test_parity(
BitLibParity parity,
uint8_t parity_length);
/**
* @brief Add parity to bit array
*
* @param data Source bit array
* @param position Start position
* @param dest Destination bit array
* @param dest_position Destination position
* @param source_length Source bit count
* @param parity_length Parity block length
* @param parity Parity to test against
* @return size_t
*/
size_t bit_lib_add_parity(
const uint8_t* data,
size_t position,
uint8_t* dest,
size_t dest_position,
uint8_t source_length,
uint8_t parity_length,
BitLibParity parity);
/**
* @brief Remove bit every n in array and shift array left. Useful to remove parity.
*
@@ -202,6 +225,27 @@ uint16_t bit_lib_reverse_16_fast(uint16_t data);
*/
uint8_t bit_lib_reverse_8_fast(uint8_t byte);
/**
* @brief Slow, but generic CRC8 implementation
*
* @param data
* @param data_size
* @param polynom CRC polynom
* @param init init value
* @param ref_in true if the right bit is older
* @param ref_out true to reverse output
* @param xor_out xor output with this value
* @return uint8_t
*/
uint16_t bit_lib_crc8(
uint8_t const* data,
size_t data_size,
uint8_t polynom,
uint8_t init,
bool ref_in,
bool ref_out,
uint8_t xor_out);
/**
* @brief Slow, but generic CRC16 implementation
*