New LF-RFID app (#534)
* Hal lfrfid: add read timer pulse and period config fns * New debug application for lfrfid subsystem * New lfrfid: app, fix naming * App lfrfid: assets * Container view module * App ibutton: remove unused header * App lfrfid scenes * App notification, add yield to blocking operations, add speaker volume control * App lfrfid: reading key scene * Assets: placeholder icon * App lfrfid: reworked container view module * App lfrfid: new scenes * App lfrfid: write scene * App lfrfid: write hid * App lfrfid: emulate scene * App lfrfid: save name scene * App lfrfid: add missing file
This commit is contained in:
150
applications/lfrfid/helpers/protocols/protocol-emmarin.cpp
Normal file
150
applications/lfrfid/helpers/protocols/protocol-emmarin.cpp
Normal file
@@ -0,0 +1,150 @@
|
||||
#include "protocol-emmarin.h"
|
||||
#include <furi.h>
|
||||
|
||||
#define EM_HEADER_POS 55
|
||||
#define EM_HEADER_MASK (0x1FFLLU << EM_HEADER_POS)
|
||||
|
||||
#define EM_FIRST_ROW_POS 50
|
||||
|
||||
#define EM_ROW_COUNT 10
|
||||
#define EM_COLUMN_COUNT 4
|
||||
#define EM_BITS_PER_ROW_COUNT (EM_COLUMN_COUNT + 1)
|
||||
|
||||
#define EM_COLUMN_POS 4
|
||||
#define EM_STOP_POS 0
|
||||
#define EM_STOP_MASK (0x1LLU << EM_STOP_POS)
|
||||
|
||||
#define EM_HEADER_AND_STOP_MASK (EM_HEADER_MASK | EM_STOP_MASK)
|
||||
#define EM_HEADER_AND_STOP_DATA (EM_HEADER_MASK)
|
||||
|
||||
typedef uint64_t EMMarinCardData;
|
||||
|
||||
void write_nibble(bool low_nibble, uint8_t data, EMMarinCardData* card_data) {
|
||||
uint8_t parity_sum = 0;
|
||||
uint8_t start = 0;
|
||||
if(!low_nibble) start = 4;
|
||||
|
||||
for(int8_t i = (start + 3); i >= start; i--) {
|
||||
parity_sum += (data >> i) & 1;
|
||||
*card_data = (*card_data << 1) | ((data >> i) & 1);
|
||||
}
|
||||
|
||||
*card_data = (*card_data << 1) | ((parity_sum % 2) & 1);
|
||||
}
|
||||
|
||||
uint8_t ProtocolEMMarin::get_encoded_data_size() {
|
||||
return sizeof(EMMarinCardData);
|
||||
}
|
||||
|
||||
uint8_t ProtocolEMMarin::get_decoded_data_size() {
|
||||
return 5;
|
||||
}
|
||||
|
||||
void ProtocolEMMarin::encode(
|
||||
const uint8_t* decoded_data,
|
||||
const uint8_t decoded_data_size,
|
||||
uint8_t* encoded_data,
|
||||
const uint8_t encoded_data_size) {
|
||||
furi_check(decoded_data_size >= get_decoded_data_size());
|
||||
furi_check(encoded_data_size >= get_encoded_data_size());
|
||||
|
||||
EMMarinCardData card_data;
|
||||
|
||||
// header
|
||||
card_data = 0b111111111;
|
||||
|
||||
// data
|
||||
for(uint8_t i = 0; i < get_decoded_data_size(); i++) {
|
||||
write_nibble(false, decoded_data[i], &card_data);
|
||||
write_nibble(true, decoded_data[i], &card_data);
|
||||
}
|
||||
|
||||
// column parity and stop bit
|
||||
uint8_t parity_sum;
|
||||
|
||||
for(uint8_t c = 0; c < EM_COLUMN_COUNT; c++) {
|
||||
parity_sum = 0;
|
||||
for(uint8_t i = 1; i <= EM_ROW_COUNT; i++) {
|
||||
uint8_t parity_bit = (card_data >> (i * EM_BITS_PER_ROW_COUNT - 1)) & 1;
|
||||
parity_sum += parity_bit;
|
||||
}
|
||||
card_data = (card_data << 1) | ((parity_sum % 2) & 1);
|
||||
}
|
||||
|
||||
// stop bit
|
||||
card_data = (card_data << 1) | 0;
|
||||
|
||||
memcpy(encoded_data, &card_data, get_encoded_data_size());
|
||||
}
|
||||
|
||||
void ProtocolEMMarin::decode(
|
||||
const uint8_t* encoded_data,
|
||||
const uint8_t encoded_data_size,
|
||||
uint8_t* decoded_data,
|
||||
const uint8_t decoded_data_size) {
|
||||
furi_check(decoded_data_size >= get_decoded_data_size());
|
||||
furi_check(encoded_data_size >= get_encoded_data_size());
|
||||
|
||||
uint8_t decoded_data_index = 0;
|
||||
EMMarinCardData card_data = *(reinterpret_cast<const EMMarinCardData*>(encoded_data));
|
||||
|
||||
// clean result
|
||||
memset(decoded_data, 0, decoded_data_size);
|
||||
|
||||
// header
|
||||
for(uint8_t i = 0; i < 9; i++) {
|
||||
card_data = card_data << 1;
|
||||
}
|
||||
|
||||
// nibbles
|
||||
uint8_t value = 0;
|
||||
for(uint8_t r = 0; r < EM_ROW_COUNT; r++) {
|
||||
uint8_t nibble = 0;
|
||||
for(uint8_t i = 0; i < 5; i++) {
|
||||
if(i < 4) nibble = (nibble << 1) | (card_data & (1LLU << 63) ? 1 : 0);
|
||||
card_data = card_data << 1;
|
||||
}
|
||||
value = (value << 4) | nibble;
|
||||
if(r % 2) {
|
||||
decoded_data[decoded_data_index] |= value;
|
||||
decoded_data_index++;
|
||||
value = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool ProtocolEMMarin::can_be_decoded(const uint8_t* encoded_data, const uint8_t encoded_data_size) {
|
||||
furi_check(encoded_data_size >= get_encoded_data_size());
|
||||
const EMMarinCardData* card_data = reinterpret_cast<const EMMarinCardData*>(encoded_data);
|
||||
|
||||
// check header and stop bit
|
||||
if((*card_data & EM_HEADER_AND_STOP_MASK) != EM_HEADER_AND_STOP_DATA) return false;
|
||||
|
||||
// check row parity
|
||||
for(uint8_t i = 0; i < EM_ROW_COUNT; i++) {
|
||||
uint8_t parity_sum = 0;
|
||||
|
||||
for(uint8_t j = 0; j < EM_BITS_PER_ROW_COUNT; j++) {
|
||||
parity_sum += (*card_data >> (EM_FIRST_ROW_POS - i * EM_BITS_PER_ROW_COUNT + j)) & 1;
|
||||
}
|
||||
|
||||
if((parity_sum % 2)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// check columns parity
|
||||
for(uint8_t i = 0; i < EM_COLUMN_COUNT; i++) {
|
||||
uint8_t parity_sum = 0;
|
||||
|
||||
for(uint8_t j = 0; j < EM_ROW_COUNT + 1; j++) {
|
||||
parity_sum += (*card_data >> (EM_COLUMN_POS - i + j * EM_BITS_PER_ROW_COUNT)) & 1;
|
||||
}
|
||||
|
||||
if((parity_sum % 2)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
22
applications/lfrfid/helpers/protocols/protocol-emmarin.h
Normal file
22
applications/lfrfid/helpers/protocols/protocol-emmarin.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
#include "protocol-generic.h"
|
||||
|
||||
class ProtocolEMMarin : public ProtocolGeneric {
|
||||
public:
|
||||
uint8_t get_encoded_data_size() final;
|
||||
uint8_t get_decoded_data_size() final;
|
||||
|
||||
void encode(
|
||||
const uint8_t* decoded_data,
|
||||
const uint8_t decoded_data_size,
|
||||
uint8_t* encoded_data,
|
||||
const uint8_t encoded_data_size) final;
|
||||
|
||||
void decode(
|
||||
const uint8_t* encoded_data,
|
||||
const uint8_t encoded_data_size,
|
||||
uint8_t* decoded_data,
|
||||
const uint8_t decoded_data_size) final;
|
||||
|
||||
bool can_be_decoded(const uint8_t* encoded_data, const uint8_t encoded_data_size) final;
|
||||
};
|
60
applications/lfrfid/helpers/protocols/protocol-generic.h
Normal file
60
applications/lfrfid/helpers/protocols/protocol-generic.h
Normal file
@@ -0,0 +1,60 @@
|
||||
#pragma once
|
||||
#include "stdint.h"
|
||||
#include "stdbool.h"
|
||||
|
||||
class ProtocolGeneric {
|
||||
public:
|
||||
/**
|
||||
* @brief Get the encoded data size
|
||||
*
|
||||
* @return uint8_t size of encoded data in bytes
|
||||
*/
|
||||
virtual uint8_t get_encoded_data_size() = 0;
|
||||
|
||||
/**
|
||||
* @brief Get the decoded data size
|
||||
*
|
||||
* @return uint8_t size of decoded data in bytes
|
||||
*/
|
||||
virtual uint8_t get_decoded_data_size() = 0;
|
||||
|
||||
/**
|
||||
* @brief encode decoded data
|
||||
*
|
||||
* @param decoded_data
|
||||
* @param decoded_data_size
|
||||
* @param encoded_data
|
||||
* @param encoded_data_size
|
||||
*/
|
||||
virtual void encode(
|
||||
const uint8_t* decoded_data,
|
||||
const uint8_t decoded_data_size,
|
||||
uint8_t* encoded_data,
|
||||
const uint8_t encoded_data_size) = 0;
|
||||
|
||||
/**
|
||||
* @brief decode encoded data
|
||||
*
|
||||
* @param encoded_data
|
||||
* @param encoded_data_size
|
||||
* @param decoded_data
|
||||
* @param decoded_data_size
|
||||
*/
|
||||
virtual void decode(
|
||||
const uint8_t* encoded_data,
|
||||
const uint8_t encoded_data_size,
|
||||
uint8_t* decoded_data,
|
||||
const uint8_t decoded_data_size) = 0;
|
||||
|
||||
/**
|
||||
* @brief fast check that data can be correctly decoded
|
||||
*
|
||||
* @param encoded_data
|
||||
* @param encoded_data_size
|
||||
* @return true - can be correctly decoded
|
||||
* @return false - cannot be correctly decoded
|
||||
*/
|
||||
virtual bool can_be_decoded(const uint8_t* encoded_data, const uint8_t encoded_data_size) = 0;
|
||||
|
||||
virtual ~ProtocolGeneric(){};
|
||||
};
|
238
applications/lfrfid/helpers/protocols/protocol-hid-h10301.cpp
Normal file
238
applications/lfrfid/helpers/protocols/protocol-hid-h10301.cpp
Normal file
@@ -0,0 +1,238 @@
|
||||
#include "protocol-hid-h10301.h"
|
||||
#include <furi.h>
|
||||
|
||||
typedef uint32_t HID10301CardData;
|
||||
constexpr uint8_t HID10301Count = 3;
|
||||
constexpr uint8_t HID10301BitSize = sizeof(HID10301CardData) * 8;
|
||||
|
||||
static void write_raw_bit(bool bit, uint8_t position, HID10301CardData* card_data) {
|
||||
if(bit) {
|
||||
card_data[position / HID10301BitSize] |=
|
||||
1UL << (HID10301BitSize - (position % HID10301BitSize) - 1);
|
||||
} else {
|
||||
card_data[position / (sizeof(HID10301CardData) * 8)] &=
|
||||
~(1UL << (HID10301BitSize - (position % HID10301BitSize) - 1));
|
||||
}
|
||||
}
|
||||
|
||||
static void write_bit(bool bit, uint8_t position, HID10301CardData* card_data) {
|
||||
write_raw_bit(bit, position + 0, card_data);
|
||||
write_raw_bit(!bit, position + 1, card_data);
|
||||
}
|
||||
|
||||
uint8_t ProtocolHID10301::get_encoded_data_size() {
|
||||
return sizeof(HID10301CardData) * HID10301Count;
|
||||
}
|
||||
|
||||
uint8_t ProtocolHID10301::get_decoded_data_size() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
void ProtocolHID10301::encode(
|
||||
const uint8_t* decoded_data,
|
||||
const uint8_t decoded_data_size,
|
||||
uint8_t* encoded_data,
|
||||
const uint8_t encoded_data_size) {
|
||||
furi_check(decoded_data_size >= get_decoded_data_size());
|
||||
furi_check(encoded_data_size >= get_encoded_data_size());
|
||||
|
||||
HID10301CardData card_data[HID10301Count] = {0, 0, 0};
|
||||
|
||||
uint32_t fc_cn = (decoded_data[0] << 16) | (decoded_data[1] << 8) | decoded_data[2];
|
||||
|
||||
// even parity sum calculation (high 12 bits of data)
|
||||
uint8_t even_parity_sum = 0;
|
||||
for(int8_t i = 12; i < 24; i++) {
|
||||
if(((fc_cn >> i) & 1) == 1) {
|
||||
even_parity_sum++;
|
||||
}
|
||||
}
|
||||
|
||||
// odd parity sum calculation (low 12 bits of data)
|
||||
uint8_t odd_parity_sum = 1;
|
||||
for(int8_t i = 0; i < 12; i++) {
|
||||
if(((fc_cn >> i) & 1) == 1) {
|
||||
odd_parity_sum++;
|
||||
}
|
||||
}
|
||||
|
||||
// 0x1D preamble
|
||||
write_raw_bit(0, 0, card_data);
|
||||
write_raw_bit(0, 1, card_data);
|
||||
write_raw_bit(0, 2, card_data);
|
||||
write_raw_bit(1, 3, card_data);
|
||||
write_raw_bit(1, 4, card_data);
|
||||
write_raw_bit(1, 5, card_data);
|
||||
write_raw_bit(0, 6, card_data);
|
||||
write_raw_bit(1, 7, card_data);
|
||||
|
||||
// company / OEM code 1
|
||||
write_bit(0, 8, card_data);
|
||||
write_bit(0, 10, card_data);
|
||||
write_bit(0, 12, card_data);
|
||||
write_bit(0, 14, card_data);
|
||||
write_bit(0, 16, card_data);
|
||||
write_bit(0, 18, card_data);
|
||||
write_bit(1, 20, card_data);
|
||||
|
||||
// card format / length 1
|
||||
write_bit(0, 22, card_data);
|
||||
write_bit(0, 24, card_data);
|
||||
write_bit(0, 26, card_data);
|
||||
write_bit(0, 28, card_data);
|
||||
write_bit(0, 30, card_data);
|
||||
write_bit(0, 32, card_data);
|
||||
write_bit(0, 34, card_data);
|
||||
write_bit(0, 36, card_data);
|
||||
write_bit(0, 38, card_data);
|
||||
write_bit(0, 40, card_data);
|
||||
write_bit(1, 42, card_data);
|
||||
|
||||
// even parity bit
|
||||
write_bit((even_parity_sum % 2), 44, card_data);
|
||||
|
||||
// data
|
||||
for(uint8_t i = 0; i < 24; i++) {
|
||||
write_bit((fc_cn >> (23 - i)) & 1, 46 + (i * 2), card_data);
|
||||
}
|
||||
|
||||
// odd parity bit
|
||||
write_bit((odd_parity_sum % 2), 94, card_data);
|
||||
|
||||
memcpy(encoded_data, &card_data, get_encoded_data_size());
|
||||
}
|
||||
|
||||
void ProtocolHID10301::decode(
|
||||
const uint8_t* encoded_data,
|
||||
const uint8_t encoded_data_size,
|
||||
uint8_t* decoded_data,
|
||||
const uint8_t decoded_data_size) {
|
||||
furi_check(decoded_data_size >= get_decoded_data_size());
|
||||
furi_check(encoded_data_size >= get_encoded_data_size());
|
||||
|
||||
const HID10301CardData* card_data = reinterpret_cast<const HID10301CardData*>(encoded_data);
|
||||
|
||||
// data decoding
|
||||
uint32_t result = 0;
|
||||
|
||||
// decode from word 1
|
||||
// coded with 01 = 0, 10 = 1 transitions
|
||||
for(int8_t i = 9; i >= 0; i--) {
|
||||
switch((*(card_data + 1) >> (2 * i)) & 0b11) {
|
||||
case 0b01:
|
||||
result = (result << 1) | 0;
|
||||
break;
|
||||
case 0b10:
|
||||
result = (result << 1) | 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// decode from word 2
|
||||
// coded with 01 = 0, 10 = 1 transitions
|
||||
for(int8_t i = 15; i >= 0; i--) {
|
||||
switch((*(card_data + 2) >> (2 * i)) & 0b11) {
|
||||
case 0b01:
|
||||
result = (result << 1) | 0;
|
||||
break;
|
||||
case 0b10:
|
||||
result = (result << 1) | 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t data[3] = {(uint8_t)(result >> 17), (uint8_t)(result >> 9), (uint8_t)(result >> 1)};
|
||||
|
||||
memcpy(decoded_data, &data, get_decoded_data_size());
|
||||
}
|
||||
|
||||
bool ProtocolHID10301::can_be_decoded(const uint8_t* encoded_data, const uint8_t encoded_data_size) {
|
||||
furi_check(encoded_data_size >= get_encoded_data_size());
|
||||
|
||||
const HID10301CardData* card_data = reinterpret_cast<const HID10301CardData*>(encoded_data);
|
||||
|
||||
// packet preamble
|
||||
// raw data
|
||||
if(*(encoded_data + 3) != 0x1D) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// encoded company/oem
|
||||
// coded with 01 = 0, 10 = 1 transitions
|
||||
// stored in word 0
|
||||
if((*card_data >> 10 & 0x3FFF) != 0x1556) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// encoded format/length
|
||||
// coded with 01 = 0, 10 = 1 transitions
|
||||
// stored in word 0 and word 1
|
||||
if((((*card_data & 0x3FF) << 12) | ((*(card_data + 1) >> 20) & 0xFFF)) != 0x155556) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// data decoding
|
||||
uint32_t result = 0;
|
||||
|
||||
// decode from word 1
|
||||
// coded with 01 = 0, 10 = 1 transitions
|
||||
for(int8_t i = 9; i >= 0; i--) {
|
||||
switch((*(card_data + 1) >> (2 * i)) & 0b11) {
|
||||
case 0b01:
|
||||
result = (result << 1) | 0;
|
||||
break;
|
||||
case 0b10:
|
||||
result = (result << 1) | 1;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// decode from word 2
|
||||
// coded with 01 = 0, 10 = 1 transitions
|
||||
for(int8_t i = 15; i >= 0; i--) {
|
||||
switch((*(card_data + 2) >> (2 * i)) & 0b11) {
|
||||
case 0b01:
|
||||
result = (result << 1) | 0;
|
||||
break;
|
||||
case 0b10:
|
||||
result = (result << 1) | 1;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// trailing parity (odd) test
|
||||
uint8_t parity_sum = 0;
|
||||
for(int8_t i = 0; i < 13; i++) {
|
||||
if(((result >> i) & 1) == 1) {
|
||||
parity_sum++;
|
||||
}
|
||||
}
|
||||
|
||||
if((parity_sum % 2) != 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// leading parity (even) test
|
||||
parity_sum = 0;
|
||||
for(int8_t i = 13; i < 26; i++) {
|
||||
if(((result >> i) & 1) == 1) {
|
||||
parity_sum++;
|
||||
}
|
||||
}
|
||||
|
||||
if((parity_sum % 2) == 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
22
applications/lfrfid/helpers/protocols/protocol-hid-h10301.h
Normal file
22
applications/lfrfid/helpers/protocols/protocol-hid-h10301.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
#include "protocol-generic.h"
|
||||
|
||||
class ProtocolHID10301 : public ProtocolGeneric {
|
||||
public:
|
||||
uint8_t get_encoded_data_size() final;
|
||||
uint8_t get_decoded_data_size() final;
|
||||
|
||||
void encode(
|
||||
const uint8_t* decoded_data,
|
||||
const uint8_t decoded_data_size,
|
||||
uint8_t* encoded_data,
|
||||
const uint8_t encoded_data_size) final;
|
||||
|
||||
void decode(
|
||||
const uint8_t* encoded_data,
|
||||
const uint8_t encoded_data_size,
|
||||
uint8_t* decoded_data,
|
||||
const uint8_t decoded_data_size) final;
|
||||
|
||||
bool can_be_decoded(const uint8_t* encoded_data, const uint8_t encoded_data_size) final;
|
||||
};
|
131
applications/lfrfid/helpers/protocols/protocol-indala-40134.cpp
Normal file
131
applications/lfrfid/helpers/protocols/protocol-indala-40134.cpp
Normal file
@@ -0,0 +1,131 @@
|
||||
#include "protocol-indala-40134.h"
|
||||
#include <furi.h>
|
||||
|
||||
typedef uint64_t Indala40134CardData;
|
||||
|
||||
static void set_bit(bool bit, uint8_t position, Indala40134CardData* card_data) {
|
||||
position = (sizeof(Indala40134CardData) * 8) - 1 - position;
|
||||
if(bit) {
|
||||
*card_data |= 1ull << position;
|
||||
} else {
|
||||
*card_data &= ~(1ull << position);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t ProtocolIndala40134::get_encoded_data_size() {
|
||||
return sizeof(Indala40134CardData);
|
||||
}
|
||||
|
||||
uint8_t ProtocolIndala40134::get_decoded_data_size() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
void ProtocolIndala40134::encode(
|
||||
const uint8_t* decoded_data,
|
||||
const uint8_t decoded_data_size,
|
||||
uint8_t* encoded_data,
|
||||
const uint8_t encoded_data_size) {
|
||||
furi_check(decoded_data_size >= get_decoded_data_size());
|
||||
furi_check(encoded_data_size >= get_encoded_data_size());
|
||||
|
||||
uint32_t fc_and_card = (decoded_data[0] << 16) | (decoded_data[1] << 8) | decoded_data[2];
|
||||
Indala40134CardData card_data = 0;
|
||||
|
||||
// preamble
|
||||
set_bit(1, 0, &card_data);
|
||||
set_bit(1, 2, &card_data);
|
||||
set_bit(1, 32, &card_data);
|
||||
|
||||
// factory code
|
||||
set_bit(((fc_and_card >> 23) & 1), 57, &card_data);
|
||||
set_bit(((fc_and_card >> 22) & 1), 49, &card_data);
|
||||
set_bit(((fc_and_card >> 21) & 1), 44, &card_data);
|
||||
set_bit(((fc_and_card >> 20) & 1), 47, &card_data);
|
||||
set_bit(((fc_and_card >> 19) & 1), 48, &card_data);
|
||||
set_bit(((fc_and_card >> 18) & 1), 53, &card_data);
|
||||
set_bit(((fc_and_card >> 17) & 1), 39, &card_data);
|
||||
set_bit(((fc_and_card >> 16) & 1), 58, &card_data);
|
||||
|
||||
// card number
|
||||
set_bit(((fc_and_card >> 15) & 1), 42, &card_data);
|
||||
set_bit(((fc_and_card >> 14) & 1), 45, &card_data);
|
||||
set_bit(((fc_and_card >> 13) & 1), 43, &card_data);
|
||||
set_bit(((fc_and_card >> 12) & 1), 40, &card_data);
|
||||
set_bit(((fc_and_card >> 11) & 1), 52, &card_data);
|
||||
set_bit(((fc_and_card >> 10) & 1), 36, &card_data);
|
||||
set_bit(((fc_and_card >> 9) & 1), 35, &card_data);
|
||||
set_bit(((fc_and_card >> 8) & 1), 51, &card_data);
|
||||
set_bit(((fc_and_card >> 7) & 1), 46, &card_data);
|
||||
set_bit(((fc_and_card >> 6) & 1), 33, &card_data);
|
||||
set_bit(((fc_and_card >> 5) & 1), 37, &card_data);
|
||||
set_bit(((fc_and_card >> 4) & 1), 54, &card_data);
|
||||
set_bit(((fc_and_card >> 3) & 1), 56, &card_data);
|
||||
set_bit(((fc_and_card >> 2) & 1), 59, &card_data);
|
||||
set_bit(((fc_and_card >> 1) & 1), 50, &card_data);
|
||||
set_bit(((fc_and_card >> 0) & 1), 41, &card_data);
|
||||
|
||||
// checksum
|
||||
uint8_t checksum = 0;
|
||||
checksum += ((fc_and_card >> 14) & 1);
|
||||
checksum += ((fc_and_card >> 12) & 1);
|
||||
checksum += ((fc_and_card >> 9) & 1);
|
||||
checksum += ((fc_and_card >> 8) & 1);
|
||||
checksum += ((fc_and_card >> 6) & 1);
|
||||
checksum += ((fc_and_card >> 5) & 1);
|
||||
checksum += ((fc_and_card >> 2) & 1);
|
||||
checksum += ((fc_and_card >> 0) & 1);
|
||||
|
||||
// wiegand parity bits
|
||||
// even parity sum calculation (high 12 bits of data)
|
||||
uint8_t even_parity_sum = 0;
|
||||
for(int8_t i = 12; i < 24; i++) {
|
||||
if(((fc_and_card >> i) & 1) == 1) {
|
||||
even_parity_sum++;
|
||||
}
|
||||
}
|
||||
|
||||
// odd parity sum calculation (low 12 bits of data)
|
||||
uint8_t odd_parity_sum = 1;
|
||||
for(int8_t i = 0; i < 12; i++) {
|
||||
if(((fc_and_card >> i) & 1) == 1) {
|
||||
odd_parity_sum++;
|
||||
}
|
||||
}
|
||||
|
||||
// even parity bit
|
||||
set_bit((even_parity_sum % 2), 34, &card_data);
|
||||
|
||||
// odd parity bit
|
||||
set_bit((odd_parity_sum % 2), 38, &card_data);
|
||||
|
||||
// checksum
|
||||
if((checksum & 1) == 1) {
|
||||
set_bit(0, 62, &card_data);
|
||||
set_bit(1, 63, &card_data);
|
||||
} else {
|
||||
set_bit(1, 62, &card_data);
|
||||
set_bit(0, 63, &card_data);
|
||||
}
|
||||
|
||||
memcpy(encoded_data, &card_data, get_encoded_data_size());
|
||||
}
|
||||
|
||||
void ProtocolIndala40134::decode(
|
||||
const uint8_t* encoded_data,
|
||||
const uint8_t encoded_data_size,
|
||||
uint8_t* decoded_data,
|
||||
const uint8_t decoded_data_size) {
|
||||
furi_check(decoded_data_size >= get_decoded_data_size());
|
||||
furi_check(encoded_data_size >= get_encoded_data_size());
|
||||
// TODO implement decoding
|
||||
furi_check(0);
|
||||
}
|
||||
|
||||
bool ProtocolIndala40134::can_be_decoded(
|
||||
const uint8_t* encoded_data,
|
||||
const uint8_t encoded_data_size) {
|
||||
furi_check(encoded_data_size >= get_encoded_data_size());
|
||||
// TODO implement decoding
|
||||
furi_check(0);
|
||||
return false;
|
||||
}
|
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
#include "protocol-generic.h"
|
||||
|
||||
class ProtocolIndala40134 : public ProtocolGeneric {
|
||||
public:
|
||||
uint8_t get_encoded_data_size() final;
|
||||
uint8_t get_decoded_data_size() final;
|
||||
|
||||
void encode(
|
||||
const uint8_t* decoded_data,
|
||||
const uint8_t decoded_data_size,
|
||||
uint8_t* encoded_data,
|
||||
const uint8_t encoded_data_size) final;
|
||||
|
||||
void decode(
|
||||
const uint8_t* encoded_data,
|
||||
const uint8_t encoded_data_size,
|
||||
uint8_t* decoded_data,
|
||||
const uint8_t decoded_data_size) final;
|
||||
|
||||
bool can_be_decoded(const uint8_t* encoded_data, const uint8_t encoded_data_size) final;
|
||||
};
|
Reference in New Issue
Block a user