1
mirror of https://github.com/DarkFlippers/unleashed-firmware.git synced 2025-12-12 12:42:30 +04:00

Merge branch 'dev' into release

This commit is contained in:
MX
2024-06-22 19:17:15 +03:00
3 changed files with 199 additions and 126 deletions

View File

@@ -20,6 +20,7 @@
## Other changes ## Other changes
* SubGHz: Fix add manually princeton * SubGHz: Fix add manually princeton
* SubGHz: Sync signal delete scene with OFW * SubGHz: Sync signal delete scene with OFW
* SubGHz: Fix incorrect rx key state when opening Read menu
* SubGHz: Fix incorrect state in decode raw exit - causing keys to be not removed from history and showing up in Read menu after exit from decode raw * SubGHz: Fix incorrect state in decode raw exit - causing keys to be not removed from history and showing up in Read menu after exit from decode raw
* Misc: Remove outdated brew sdk install files * Misc: Remove outdated brew sdk install files
* Misc: Revert USB CDC changes to fix usb serial * Misc: Revert USB CDC changes to fix usb serial
@@ -28,6 +29,7 @@
* CLI: Move part of the CLI to microsd to free up space for COMPACT 0 builds (by @Willy-JL) * CLI: Move part of the CLI to microsd to free up space for COMPACT 0 builds (by @Willy-JL)
* NFC: Fix typo in parsers * NFC: Fix typo in parsers
* Apps: Fix `input_callback` and `timer_callback` usage of non `void` argument as input * Apps: Fix `input_callback` and `timer_callback` usage of non `void` argument as input
* LF RFID: OFW PR 3728: Securakey - Add Support for RKKTH Plain Text Format (by @zinongli)
* OFW: ReadMe: update outdated bits and pieces * OFW: ReadMe: update outdated bits and pieces
* OFW: Debug: backup openocd work area, fix crash after fresh debugger connect and continue * OFW: Debug: backup openocd work area, fix crash after fresh debugger connect and continue
* OFW: ELF, Flipper application: do not crash on "out of memory" * OFW: ELF, Flipper application: do not crash on "out of memory"

View File

@@ -73,6 +73,7 @@ bool subghz_scene_start_on_event(void* context, SceneManagerEvent event) {
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReadRAW); scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReadRAW);
return true; return true;
} else if(event.event == SubmenuIndexRead) { } else if(event.event == SubmenuIndexRead) {
subghz_rx_key_state_set(subghz, SubGhzRxKeyStateIDLE);
scene_manager_set_scene_state( scene_manager_set_scene_state(
subghz->scene_manager, SubGhzSceneStart, SubmenuIndexRead); subghz->scene_manager, SubGhzSceneStart, SubmenuIndexRead);
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReceiver); scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReceiver);

View File

@@ -11,13 +11,15 @@
#include <toolbox/manchester_decoder.h> #include <toolbox/manchester_decoder.h>
#define TAG "SECURAKEY" #define TAG "SECURAKEY"
#define SECURAKEY_ENCODED_SIZE_BITS (84) #define SECURAKEY_RKKT_ENCODED_FULL_SIZE_BITS (96)
#define SECURAKEY_PREAMBLE_SIZE_BITS (12) #define SECURAKEY_RKKT_ENCODED_FULL_SIZE_BYTE (12)
#define SECURAKEY_ENCODED_FULL_SIZE_BITS \
(SECURAKEY_ENCODED_SIZE_BITS + SECURAKEY_PREAMBLE_SIZE_BITS) #define SECURAKEY_RKKTH_ENCODED_FULL_SIZE_BITS (64)
#define SECURAKEY_ENCODED_FULL_SIZE_BYTE (SECURAKEY_ENCODED_FULL_SIZE_BITS / 8) #define SECURAKEY_RKKTH_ENCODED_FULL_SIZE_BYTE (8)
#define SECURAKEY_DECODED_DATA_SIZE_BITS \
(48) // 16-bit for facility code/number, 16-bit for card number, 16-bit for two checksum #define SECURAKEY_DECODED_DATA_SIZE_BITS (48)
// RKKT: 16-bit for facility code/number, 16-bit for card number, 16-bit for two checksum
// RKKTH: 16-bit zero padding, 32-bit card number
#define SECURAKEY_DECODED_DATA_SIZE_BYTES (SECURAKEY_DECODED_DATA_SIZE_BITS / 8) #define SECURAKEY_DECODED_DATA_SIZE_BYTES (SECURAKEY_DECODED_DATA_SIZE_BITS / 8)
#define LFRFID_FREQUENCY (125000) #define LFRFID_FREQUENCY (125000)
#define SECURAKEY_CLOCK_PER_BIT (40) // RF/40 #define SECURAKEY_CLOCK_PER_BIT (40) // RF/40
@@ -34,7 +36,8 @@
typedef struct { typedef struct {
uint8_t data[SECURAKEY_DECODED_DATA_SIZE_BYTES]; uint8_t data[SECURAKEY_DECODED_DATA_SIZE_BYTES];
uint8_t encoded_data[SECURAKEY_ENCODED_FULL_SIZE_BYTE]; uint8_t RKKT_encoded_data[SECURAKEY_RKKT_ENCODED_FULL_SIZE_BYTE];
uint8_t RKKTH_encoded_data[SECURAKEY_RKKTH_ENCODED_FULL_SIZE_BYTE];
uint8_t encoded_data_index; uint8_t encoded_data_index;
bool encoded_polarity; bool encoded_polarity;
ManchesterState decoder_manchester_state; ManchesterState decoder_manchester_state;
@@ -55,15 +58,16 @@ uint8_t* protocol_securakey_get_data(ProtocolSecurakey* protocol) {
}; };
static bool protocol_securakey_can_be_decoded(ProtocolSecurakey* protocol) { static bool protocol_securakey_can_be_decoded(ProtocolSecurakey* protocol) {
// check 11 bits preamble // check 19 bits preamble + format flag
if(bit_lib_get_bits_16(protocol->encoded_data, 0, SECURAKEY_PREAMBLE_SIZE_BITS) == if(bit_lib_get_bits_32(protocol->RKKT_encoded_data, 0, 19) == 0b0111111111000000000) {
0b011111111100) { protocol->bit_format = 0;
if(bit_lib_get_bits(protocol->encoded_data, 13, 6) == 26 || return true;
bit_lib_get_bits(protocol->encoded_data, 13, 6) == 32) { } else if(bit_lib_get_bits_32(protocol->RKKT_encoded_data, 0, 19) == 0b0111111111001011010) {
protocol->bit_format = 26;
return true;
} else if(bit_lib_get_bits_32(protocol->RKKT_encoded_data, 0, 19) == 0b0111111111001100000) {
protocol->bit_format = 32;
return true; return true;
} else {
return false;
}
} else { } else {
return false; return false;
} }
@@ -71,7 +75,7 @@ static bool protocol_securakey_can_be_decoded(ProtocolSecurakey* protocol) {
static void protocol_securakey_decode(ProtocolSecurakey* protocol) { static void protocol_securakey_decode(ProtocolSecurakey* protocol) {
memset(protocol->data, 0, SECURAKEY_DECODED_DATA_SIZE_BYTES); memset(protocol->data, 0, SECURAKEY_DECODED_DATA_SIZE_BYTES);
// encoded_data looks like this (citation: pm3 repo): // RKKT_encoded_data looks like this (citation: pm3 repo):
// 26-bit format (1-bit even parity bit, 8-bit facility number, 16-bit card number, 1-bit odd parity bit) // 26-bit format (1-bit even parity bit, 8-bit facility number, 16-bit card number, 1-bit odd parity bit)
// preamble ??bitlen reserved EPf fffffffc cccccccc cccccccOP CS? CS2? // preamble ??bitlen reserved EPf fffffffc cccccccc cccccccOP CS? CS2?
// 0111111111 0 01011010 0 00000000 0 00000010 0 00110110 0 00111110 0 01100010 0 00001111 0 01100000 0 00000000 0 0000 // 0111111111 0 01011010 0 00000000 0 00000010 0 00110110 0 00111110 0 01100010 0 00001111 0 01100000 0 00000000 0 0000
@@ -80,34 +84,51 @@ static void protocol_securakey_decode(ProtocolSecurakey* protocol) {
// preamble ??bitlen reserved EPfffffff fffffffc cccccccc cccccccOP CS? CS2? // preamble ??bitlen reserved EPfffffff fffffffc cccccccc cccccccOP CS? CS2?
// 0111111111 0 01100000 0 00000000 0 10000100 0 11001010 0 01011011 0 01010110 0 00010110 0 11100000 0 00000000 0 0000 // 0111111111 0 01100000 0 00000000 0 10000100 0 11001010 0 01011011 0 01010110 0 00010110 0 11100000 0 00000000 0 0000
// RKKTH-02 encoded data sometimes look like this
// plaintext format (preamble and 32-bit? card number)
// preamble unknown unknown cccccccc cccccccc cccccccc cccccccc
// 0 1 2 3 4 5 6
// 0123456789 0 12345678 9 01234567 8 90123456 7 89012345 6 78901234 5 67890123
// 0111111111 0 00000000 0 00000000 0 00000000 0 00011101 0 00000100 0 01001010
if(bit_lib_get_bits(protocol->RKKT_encoded_data, 13, 6) == 0) {
FURI_LOG_D(TAG, "Plaintext RKKTH detected");
protocol->bit_format = 0;
// get card number (c)
bit_lib_copy_bits(protocol->data, 16, 8, protocol->RKKT_encoded_data, 29);
// skip spacers (0s)
bit_lib_copy_bits(protocol->data, 24, 8, protocol->RKKT_encoded_data, 38);
bit_lib_copy_bits(protocol->data, 32, 8, protocol->RKKT_encoded_data, 47);
bit_lib_copy_bits(protocol->data, 40, 8, protocol->RKKT_encoded_data, 56);
} else {
if(bit_lib_get_bits(protocol->RKKT_encoded_data, 13, 6) == 26) {
FURI_LOG_D(TAG, "26-bit RKKT detected");
protocol->bit_format = 26;
// left two 0 paddings in the beginning for easier parsing (00011010 = 011010) // left two 0 paddings in the beginning for easier parsing (00011010 = 011010)
// get facility number (f) // get facility number (f)
if(bit_lib_get_bits(protocol->encoded_data, 13, 6) == 26) { bit_lib_copy_bits(protocol->data, 8, 1, protocol->RKKT_encoded_data, 36);
FURI_LOG_D(TAG, "26-bit Securakey detected");
protocol->bit_format = 26;
bit_lib_copy_bits(protocol->data, 8, 1, protocol->encoded_data, 36);
// have to skip one spacer // have to skip one spacer
bit_lib_copy_bits(protocol->data, 9, 7, protocol->encoded_data, 38); bit_lib_copy_bits(protocol->data, 9, 7, protocol->RKKT_encoded_data, 38);
} else if(bit_lib_get_bits(protocol->encoded_data, 13, 6) == 32) { } else if(bit_lib_get_bits(protocol->RKKT_encoded_data, 13, 6) == 32) {
FURI_LOG_D(TAG, "32-bit Securakey detected"); FURI_LOG_D(TAG, "32-bit RKKT detected");
protocol->bit_format = 32; protocol->bit_format = 32;
// same two 0 paddings here, otherwise should be bit_lib_copy_bits(protocol->data, 8, 7, protocol->encoded_data, 30); // same two 0 paddings here, otherwise should be bit_lib_copy_bits(protocol->data, 8, 7, protocol->RKKT_encoded_data, 30);
bit_lib_copy_bits(protocol->data, 2, 7, protocol->encoded_data, 30); bit_lib_copy_bits(protocol->data, 2, 7, protocol->RKKT_encoded_data, 30);
// have to skip one spacer // have to skip one spacer
bit_lib_copy_bits(protocol->data, 9, 7, protocol->encoded_data, 38); bit_lib_copy_bits(protocol->data, 9, 7, protocol->RKKT_encoded_data, 38);
} }
// get card number (c) // get card number (c)
bit_lib_copy_bits(protocol->data, 16, 1, protocol->encoded_data, 45); bit_lib_copy_bits(protocol->data, 16, 1, protocol->RKKT_encoded_data, 45);
// same skips here // same skips here
bit_lib_copy_bits(protocol->data, 17, 8, protocol->encoded_data, 47); bit_lib_copy_bits(protocol->data, 17, 8, protocol->RKKT_encoded_data, 47);
bit_lib_copy_bits(protocol->data, 25, 7, protocol->encoded_data, 56); bit_lib_copy_bits(protocol->data, 25, 7, protocol->RKKT_encoded_data, 56);
// unsure about CS yet, might as well just save it // unsure about CS yet, might as well just save it
// CS1 // CS1
bit_lib_copy_bits(protocol->data, 32, 8, protocol->encoded_data, 65); bit_lib_copy_bits(protocol->data, 32, 8, protocol->RKKT_encoded_data, 65);
// CS2 // CS2
bit_lib_copy_bits(protocol->data, 40, 8, protocol->encoded_data, 74); bit_lib_copy_bits(protocol->data, 40, 8, protocol->RKKT_encoded_data, 74);
}
// (decoded) data looks like this (pp are zero paddings): // (decoded) data looks like this (pp are zero paddings):
// 26-bit format (1-bit EP, 8-bit facility number, 16-bit card number, 1-bit OP) // 26-bit format (1-bit EP, 8-bit facility number, 16-bit card number, 1-bit OP)
@@ -117,10 +138,16 @@ static void protocol_securakey_decode(ProtocolSecurakey* protocol) {
// 32-bit format (1-bit EP, 14-bit facility number, 16-bit card number, 1-bit OP) // 32-bit format (1-bit EP, 14-bit facility number, 16-bit card number, 1-bit OP)
// ppffffff ffffffff cccccccc cccccccc CS1 CS2 // ppffffff ffffffff cccccccc cccccccc CS1 CS2
// 00000010 01100101 00101101 10101011 00010110 11100000 // 00000010 01100101 00101101 10101011 00010110 11100000
// plaintext format (preamble and 32-bit? card number)
// pppppppp pppppppp cccccccc cccccccc cccccccc cccccccc
// 00000000 00000000 00101011 00011101 00000100 01001010
}; };
void protocol_securakey_decoder_start(ProtocolSecurakey* protocol) { void protocol_securakey_decoder_start(ProtocolSecurakey* protocol) {
memset(protocol->encoded_data, 0, SECURAKEY_ENCODED_FULL_SIZE_BYTE); // always takes in encoded data as RKKT for simplicity
// this part is feeding decoder which will delineate the format anyway
memset(protocol->RKKT_encoded_data, 0, SECURAKEY_RKKT_ENCODED_FULL_SIZE_BYTE);
manchester_advance( manchester_advance(
protocol->decoder_manchester_state, protocol->decoder_manchester_state,
ManchesterEventReset, ManchesterEventReset,
@@ -151,7 +178,8 @@ bool protocol_securakey_decoder_feed(ProtocolSecurakey* protocol, bool level, ui
bool data_ok = manchester_advance( bool data_ok = manchester_advance(
protocol->decoder_manchester_state, event, &protocol->decoder_manchester_state, &data); protocol->decoder_manchester_state, event, &protocol->decoder_manchester_state, &data);
if(data_ok) { if(data_ok) {
bit_lib_push_bit(protocol->encoded_data, SECURAKEY_ENCODED_FULL_SIZE_BYTE, data); bit_lib_push_bit(
protocol->RKKT_encoded_data, SECURAKEY_RKKT_ENCODED_FULL_SIZE_BYTE, data);
if(protocol_securakey_can_be_decoded(protocol)) { if(protocol_securakey_can_be_decoded(protocol)) {
protocol_securakey_decode(protocol); protocol_securakey_decode(protocol);
result = true; result = true;
@@ -162,6 +190,13 @@ bool protocol_securakey_decoder_feed(ProtocolSecurakey* protocol, bool level, ui
}; };
void protocol_securakey_render_data(ProtocolSecurakey* protocol, FuriString* result) { void protocol_securakey_render_data(ProtocolSecurakey* protocol, FuriString* result) {
if(bit_lib_get_bits_16(protocol->data, 0, 16) == 0) {
protocol->bit_format = 0;
furi_string_printf(
result,
"RKKTH Plaintext format\nCard number: %llu",
bit_lib_get_bits_64(protocol->data, 0, 48));
} else {
if(bit_lib_get_bits(protocol->data, 0, 8) == 0) { if(bit_lib_get_bits(protocol->data, 0, 8) == 0) {
protocol->bit_format = 26; protocol->bit_format = 26;
} else { } else {
@@ -169,65 +204,75 @@ void protocol_securakey_render_data(ProtocolSecurakey* protocol, FuriString* res
} }
furi_string_printf( furi_string_printf(
result, result,
"%u-bit format\nFacility code: %u\nCard number: %u", "RKKT %u-bit format\nFacility code: %u\nCard number: %u",
protocol->bit_format, protocol->bit_format,
bit_lib_get_bits_16(protocol->data, 0, 16), bit_lib_get_bits_16(protocol->data, 0, 16),
bit_lib_get_bits_16(protocol->data, 16, 16)); bit_lib_get_bits_16(protocol->data, 16, 16));
}
}; };
bool protocol_securakey_encoder_start(ProtocolSecurakey* protocol) { bool protocol_securakey_encoder_start(ProtocolSecurakey* protocol) {
// set all of our encoded_data bits to zeros. // set all of our encoded_data bits to zeros.
memset(protocol->encoded_data, 0, SECURAKEY_ENCODED_FULL_SIZE_BYTE); memset(protocol->RKKTH_encoded_data, 0, SECURAKEY_RKKTH_ENCODED_FULL_SIZE_BYTE);
memset(protocol->RKKT_encoded_data, 0, SECURAKEY_RKKT_ENCODED_FULL_SIZE_BYTE);
// write the preamble to the beginning of the encoded_data if(bit_lib_get_bits_16(protocol->data, 0, 16) == 0) {
bit_lib_set_bits(protocol->encoded_data, 0, 0b01111111, 8); // write the preamble to the beginning of the RKKT_encoded_data
bit_lib_set_bits(protocol->encoded_data, 8, 0b11001, 5); bit_lib_set_bits(protocol->RKKTH_encoded_data, 0, 0b01111111, 8);
bit_lib_set_bits(protocol->RKKTH_encoded_data, 8, 0b110, 3); //preamble cont.
// write card number (c)
bit_lib_copy_bits(protocol->RKKTH_encoded_data, 29, 8, protocol->data, 16);
// skip spacers (they are zero already by memset)
bit_lib_copy_bits(protocol->RKKTH_encoded_data, 38, 8, protocol->data, 24);
bit_lib_copy_bits(protocol->RKKTH_encoded_data, 47, 8, protocol->data, 32);
bit_lib_copy_bits(protocol->RKKTH_encoded_data, 56, 8, protocol->data, 40);
} else {
// write the preamble to the beginning of the RKKT_encoded_data
bit_lib_set_bits(protocol->RKKT_encoded_data, 0, 0b01111111, 8);
bit_lib_set_bits(protocol->RKKT_encoded_data, 8, 0b11001, 5); //preamble cont.
if(bit_lib_get_bits(protocol->data, 0, 8) == 0) { if(bit_lib_get_bits(protocol->data, 0, 8) == 0) {
protocol->bit_format = 26; protocol->bit_format = 26;
// set bit length // set bit length
bit_lib_set_bits(protocol->encoded_data, 13, protocol->bit_format, 6); bit_lib_set_bits(protocol->RKKT_encoded_data, 13, protocol->bit_format, 6);
// set even parity & odd parity // set even parity & odd parity
if(!bit_lib_test_parity(protocol->data, 8, 12, BitLibParityOdd, 12)) { if(!bit_lib_test_parity(protocol->data, 8, 12, BitLibParityOdd, 12)) {
bit_lib_set_bit(protocol->encoded_data, 35, 1); bit_lib_set_bit(protocol->RKKT_encoded_data, 35, 1);
} }
if(bit_lib_test_parity(protocol->data, 20, 12, BitLibParityOdd, 12)) { if(bit_lib_test_parity(protocol->data, 20, 12, BitLibParityOdd, 12)) {
bit_lib_set_bit(protocol->encoded_data, 63, 1); bit_lib_set_bit(protocol->RKKT_encoded_data, 63, 1);
} }
// write facility number (f) // write facility number (f)
bit_lib_copy_bits(protocol->encoded_data, 36, 1, protocol->data, 8); bit_lib_copy_bits(protocol->RKKT_encoded_data, 36, 1, protocol->data, 8);
// have to skip one spacer // have to skip one spacer
bit_lib_copy_bits(protocol->encoded_data, 38, 7, protocol->data, 9); bit_lib_copy_bits(protocol->RKKT_encoded_data, 38, 7, protocol->data, 9);
} else { } else {
protocol->bit_format = 32; protocol->bit_format = 32;
// set bit length // set bit length
bit_lib_set_bits(protocol->encoded_data, 13, protocol->bit_format, 6); bit_lib_set_bits(protocol->RKKT_encoded_data, 13, protocol->bit_format, 6);
// set EP & OP // set EP & OP
if(!bit_lib_test_parity(protocol->data, 2, 15, BitLibParityOdd, 15)) { if(!bit_lib_test_parity(protocol->data, 2, 15, BitLibParityOdd, 15)) {
bit_lib_set_bit(protocol->encoded_data, 29, 1); bit_lib_set_bit(protocol->RKKT_encoded_data, 29, 1);
} }
if(bit_lib_test_parity(protocol->data, 17, 15, BitLibParityOdd, 15)) { if(bit_lib_test_parity(protocol->data, 17, 15, BitLibParityOdd, 15)) {
bit_lib_set_bit(protocol->encoded_data, 63, 1); bit_lib_set_bit(protocol->RKKT_encoded_data, 63, 1);
} }
// write facility number (f) // write facility number (f)
bit_lib_copy_bits(protocol->encoded_data, 30, 7, protocol->data, 2); bit_lib_copy_bits(protocol->RKKT_encoded_data, 30, 7, protocol->data, 2);
// have to skip one spacer // have to skip one spacer
bit_lib_copy_bits(protocol->encoded_data, 38, 7, protocol->data, 3); bit_lib_copy_bits(protocol->RKKT_encoded_data, 38, 7, protocol->data, 3);
} }
// write card number (c) // write card number (c)
bit_lib_copy_bits(protocol->encoded_data, 45, 1, protocol->data, 16); bit_lib_copy_bits(protocol->RKKT_encoded_data, 45, 1, protocol->data, 16);
// same skips here // same skips here
bit_lib_copy_bits(protocol->encoded_data, 47, 8, protocol->data, 17); bit_lib_copy_bits(protocol->RKKT_encoded_data, 47, 8, protocol->data, 17);
bit_lib_copy_bits(protocol->encoded_data, 56, 7, protocol->data, 25); bit_lib_copy_bits(protocol->RKKT_encoded_data, 56, 7, protocol->data, 25);
// unsure about CS yet might as well just copy it from saved // unsure about CS yet might as well just copy it from saved
// CS1 // CS1
bit_lib_copy_bits(protocol->encoded_data, 65, 8, protocol->data, 32); bit_lib_copy_bits(protocol->RKKT_encoded_data, 65, 8, protocol->data, 32);
// CS2 // CS2
bit_lib_copy_bits(protocol->encoded_data, 74, 8, protocol->data, 40); bit_lib_copy_bits(protocol->RKKT_encoded_data, 74, 8, protocol->data, 40);
}
// for sending we start at bit 0. // for sending we start at bit 0.
protocol->encoded_data_index = 0; protocol->encoded_data_index = 0;
protocol->encoded_polarity = true; protocol->encoded_polarity = true;
@@ -235,37 +280,62 @@ bool protocol_securakey_encoder_start(ProtocolSecurakey* protocol) {
}; };
LevelDuration protocol_securakey_encoder_yield(ProtocolSecurakey* protocol) { LevelDuration protocol_securakey_encoder_yield(ProtocolSecurakey* protocol) {
bool level = bit_lib_get_bit(protocol->encoded_data, protocol->encoded_data_index); if(bit_lib_get_bits_16(protocol->data, 0, 16) == 0) {
bool level = bit_lib_get_bit(protocol->RKKTH_encoded_data, protocol->encoded_data_index);
uint32_t duration = SECURAKEY_CLOCK_PER_BIT / 2; uint32_t duration = SECURAKEY_CLOCK_PER_BIT / 2;
if(protocol->encoded_polarity) { if(protocol->encoded_polarity) {
protocol->encoded_polarity = false; protocol->encoded_polarity = false;
} else { } else {
level = !level; level = !level;
protocol->encoded_polarity = true; protocol->encoded_polarity = true;
bit_lib_increment_index(protocol->encoded_data_index, SECURAKEY_ENCODED_FULL_SIZE_BITS); bit_lib_increment_index(
protocol->encoded_data_index, SECURAKEY_RKKTH_ENCODED_FULL_SIZE_BITS);
} }
return level_duration_make(level, duration); return level_duration_make(level, duration);
} else {
bool level = bit_lib_get_bit(protocol->RKKT_encoded_data, protocol->encoded_data_index);
uint32_t duration = SECURAKEY_CLOCK_PER_BIT / 2;
if(protocol->encoded_polarity) {
protocol->encoded_polarity = false;
} else {
level = !level;
protocol->encoded_polarity = true;
bit_lib_increment_index(
protocol->encoded_data_index, SECURAKEY_RKKT_ENCODED_FULL_SIZE_BITS);
}
return level_duration_make(level, duration);
}
}; };
bool protocol_securakey_write_data(ProtocolSecurakey* protocol, void* data) { bool protocol_securakey_write_data(ProtocolSecurakey* protocol, void* data) {
protocol_securakey_encoder_start(protocol);
LFRFIDWriteRequest* request = (LFRFIDWriteRequest*)data; LFRFIDWriteRequest* request = (LFRFIDWriteRequest*)data;
bool result = false; bool result = false;
// Correct protocol data by redecoding
protocol_securakey_encoder_start(protocol);
protocol_securakey_decode(protocol);
protocol_securakey_encoder_start(protocol);
// Write T5577 // Write T5577
if(bit_lib_get_bits_16(protocol->data, 0, 16) == 0) {
if(request->write_type == LFRFIDWriteTypeT5577) {
request->t5577.block[0] =
(LFRFID_T5577_MODULATION_MANCHESTER | LFRFID_T5577_BITRATE_RF_40 |
(2
<< LFRFID_T5577_MAXBLOCK_SHIFT)); // we only need 2 32-bit blocks for our 64-bit encoded data
request->t5577.block[1] = bit_lib_get_bits_32(protocol->RKKTH_encoded_data, 0, 32);
request->t5577.block[2] = bit_lib_get_bits_32(protocol->RKKTH_encoded_data, 32, 32);
request->t5577.blocks_to_write = 3;
result = true;
}
} else {
if(request->write_type == LFRFIDWriteTypeT5577) { if(request->write_type == LFRFIDWriteTypeT5577) {
request->t5577.block[0] = request->t5577.block[0] =
(LFRFID_T5577_MODULATION_MANCHESTER | LFRFID_T5577_BITRATE_RF_40 | (LFRFID_T5577_MODULATION_MANCHESTER | LFRFID_T5577_BITRATE_RF_40 |
(3 (3
<< LFRFID_T5577_MAXBLOCK_SHIFT)); // we only need 3 32-bit blocks for our 96-bit encoded data << LFRFID_T5577_MAXBLOCK_SHIFT)); // we only need 3 32-bit blocks for our 96-bit encoded data
request->t5577.block[1] = bit_lib_get_bits_32(protocol->encoded_data, 0, 32); request->t5577.block[1] = bit_lib_get_bits_32(protocol->RKKT_encoded_data, 0, 32);
request->t5577.block[2] = bit_lib_get_bits_32(protocol->encoded_data, 32, 32); request->t5577.block[2] = bit_lib_get_bits_32(protocol->RKKT_encoded_data, 32, 32);
request->t5577.block[3] = bit_lib_get_bits_32(protocol->encoded_data, 64, 32); request->t5577.block[3] = bit_lib_get_bits_32(protocol->RKKT_encoded_data, 64, 32);
request->t5577.blocks_to_write = 4; request->t5577.blocks_to_write = 4;
result = true; result = true;
} }
}
return result; return result;
}; };