Some fixes for FloR-S

This commit is contained in:
r3df0xx 2022-03-20 20:57:38 +03:00
parent f4b6acb3cb
commit a014b496e9
2 changed files with 23 additions and 22 deletions

View file

@ -99,10 +99,10 @@ void subghz_protocol_encoder_nice_flor_s_free(void* context) {
free(instance);
}
static bool subghz_protocol_nice_flor_s_gen_data(SubGhzProtocolEncoderNiceFlorS* instance, uint8_t btn, const char* file_name) {
static bool subghz_protocol_nice_flor_s_gen_data(SubGhzProtocolEncoderNiceFlorS* instance, uint8_t btn, const char* nice_flor_s_rainbow_table_file_name) {
instance->generic.cnt++;
uint64_t data_to_encrypt = btn | instance->generic.serial | instance->generic.cnt;
instance->generic.data = subghz_protocol_nice_flor_s_encrypt(data_to_encrypt, file_name);
instance->generic.data = subghz_protocol_nice_flor_s_encrypt(data_to_encrypt, nice_flor_s_rainbow_table_file_name);
return true;
}
@ -114,13 +114,13 @@ bool subghz_protocol_nice_flor_s_create_data(
uint16_t cnt,
uint32_t frequency,
FuriHalSubGhzPreset preset,
const char* file_name) {
const char* nice_flor_s_rainbow_table_file_name) {
furi_assert(context);
SubGhzProtocolEncoderNiceFlorS* instance = context;
instance->generic.serial = serial;
instance->generic.cnt = cnt;
instance->generic.data_count_bit = 52;
bool res = subghz_protocol_nice_flor_s_gen_data(instance, btn, file_name);
bool res = subghz_protocol_nice_flor_s_gen_data(instance, btn, nice_flor_s_rainbow_table_file_name);
if (res) {
res =
subghz_block_generic_serialize(&instance->generic, flipper_format, frequency, preset);
@ -134,11 +134,11 @@ bool subghz_protocol_nice_flor_s_create_data(
* @return true On success
*/
static bool
subghz_protocol_encoder_nice_flor_s_get_upload(SubGhzProtocolEncoderNiceFlorS* instance, uint8_t btn, const char* file_name) {
subghz_protocol_encoder_nice_flor_s_get_upload(SubGhzProtocolEncoderNiceFlorS* instance, uint8_t btn, const char* nice_flor_s_rainbow_table_file_name) {
furi_assert(instance);
//gen new key
if(subghz_protocol_nice_flor_s_gen_data(instance, btn, file_name)) {
if(subghz_protocol_nice_flor_s_gen_data(instance, btn, nice_flor_s_rainbow_table_file_name)) {
//ToDo if you need to add a callback to automatically update the data on the display
} else {
return false;
@ -193,6 +193,7 @@ bool subghz_protocol_encoder_nice_flor_s_deserialize(void* context, FlipperForma
furi_assert(context);
SubGhzProtocolEncoderNiceFlorS* instance = context;
bool res = false;
const char* nice_flor_s_rainbow_table_file_name = nice_flor_s_rainbow_table_file_name;
do {
if(!subghz_block_generic_deserialize(&instance->generic, flipper_format)) {
FURI_LOG_E(TAG, "Deserialize error");
@ -203,7 +204,7 @@ bool subghz_protocol_encoder_nice_flor_s_deserialize(void* context, FlipperForma
flipper_format_read_uint32(
flipper_format, "Repeat", (uint32_t*)&instance->encoder.repeat, 1);
subghz_protocol_encoder_nice_flor_s_get_upload(instance, instance->generic.btn, file_name);
subghz_protocol_encoder_nice_flor_s_get_upload(instance, instance->generic.btn, nice_flor_s_rainbow_table_file_name);
if(!flipper_format_rewind(flipper_format)) {
FURI_LOG_E(TAG, "Rewind error");
@ -251,16 +252,16 @@ LevelDuration subghz_protocol_encoder_nice_flor_s_yield(void* context) {
/**
* Read bytes from rainbow table
* @param file_name Full path to rainbow table the file
* @param nice_flor_s_rainbow_table_file_name Full path to rainbow table the file
* @param address Byte address in file
* @return data
*/
static uint8_t
subghz_protocol_nice_flor_s_get_byte_in_file(const char* file_name, uint32_t address) {
if(!file_name) return 0;
subghz_protocol_nice_flor_s_get_byte_in_file(const char* nice_flor_s_rainbow_table_file_name, uint32_t address) {
if(!nice_flor_s_rainbow_table_file_name) return 0;
uint8_t buffer[1] = {0};
if(subghz_keystore_raw_get_data(file_name, address, buffer, sizeof(uint8_t))) {
if(subghz_keystore_raw_get_data(nice_flor_s_rainbow_table_file_name, address, buffer, sizeof(uint8_t))) {
return buffer[0];
} else {
return 0;
@ -273,17 +274,17 @@ static inline void subghz_protocol_decoder_nice_flor_s_magic_xor(uint8_t* p, uin
}
}
uint64_t subghz_protocol_nice_flor_s_encrypt(uint64_t data, const char* file_name) {
uint64_t subghz_protocol_nice_flor_s_encrypt(uint64_t data, const char* nice_flor_s_rainbow_table_file_name) {
uint8_t* p = (uint8_t*)&data;
uint8_t k = 0;
for(uint8_t y = 0; y < 2; y++) {
k = subghz_protocol_nice_flor_s_get_byte_in_file(file_name, p[0] & 0x1f);
k = subghz_protocol_nice_flor_s_get_byte_in_file(nice_flor_s_rainbow_table_file_name, p[0] & 0x1f);
subghz_protocol_decoder_nice_flor_s_magic_xor(p, k);
p[5] &= 0x0f;
p[0] ^= k & 0xe0;
k = subghz_protocol_nice_flor_s_get_byte_in_file(file_name, p[0] >> 3) + 0x25;
k = subghz_protocol_nice_flor_s_get_byte_in_file(nice_flor_s_rainbow_table_file_name, p[0] >> 3) + 0x25;
subghz_protocol_decoder_nice_flor_s_magic_xor(p, k);
p[5] &= 0x0f;
@ -308,7 +309,7 @@ uint64_t subghz_protocol_nice_flor_s_encrypt(uint64_t data, const char* file_nam
}
static uint64_t
subghz_protocol_nice_flor_s_decrypt(SubGhzBlockGeneric* instance, const char* file_name) {
subghz_protocol_nice_flor_s_decrypt(SubGhzBlockGeneric* instance, const char* nice_flor_s_rainbow_table_file_name) {
furi_assert(instance);
uint64_t data = instance->data;
uint8_t* p = (uint8_t*)&data;
@ -325,12 +326,12 @@ static uint64_t
p[1] = k;
for(uint8_t y = 0; y < 2; y++) {
k = subghz_protocol_nice_flor_s_get_byte_in_file(file_name, p[0] >> 3) + 0x25;
k = subghz_protocol_nice_flor_s_get_byte_in_file(nice_flor_s_rainbow_table_file_name, p[0] >> 3) + 0x25;
subghz_protocol_decoder_nice_flor_s_magic_xor(p, k);
p[5] &= 0x0f;
p[0] ^= k & 0x7;
k = subghz_protocol_nice_flor_s_get_byte_in_file(file_name, p[0] & 0x1f);
k = subghz_protocol_nice_flor_s_get_byte_in_file(nice_flor_s_rainbow_table_file_name, p[0] & 0x1f);
subghz_protocol_decoder_nice_flor_s_magic_xor(p, k);
p[5] &= 0x0f;
@ -453,11 +454,11 @@ void subghz_protocol_decoder_nice_flor_s_feed(void* context, bool level, uint32_
/**
* Analysis of received data
* @param instance Pointer to a SubGhzBlockGeneric* instance
* @param file_name Full path to rainbow table the file
* @param nice_flor_s_rainbow_table_file_name Full path to rainbow table the file
*/
static void subghz_protocol_nice_flor_s_remote_controller(
SubGhzBlockGeneric* instance,
const char* file_name) {
const char* nice_flor_s_rainbow_table_file_name) {
/*
* Packet format Nice Flor-s: START-P0-P1-P2-P3-P4-P5-P6-P7-STOP
* P0 (4-bit) - button positional code - 1:0x1, 2:0x2, 3:0x4, 4:0x8;
@ -480,12 +481,12 @@ static void subghz_protocol_nice_flor_s_remote_controller(
* decrypt => 0x10436c6820444 => 0x1 0436c682 0444
*
*/
if(!file_name) {
if(!nice_flor_s_rainbow_table_file_name) {
instance->cnt = 0;
instance->serial = 0;
instance->btn = 0;
} else {
uint64_t decrypt = subghz_protocol_nice_flor_s_decrypt(instance, file_name);
uint64_t decrypt = subghz_protocol_nice_flor_s_decrypt(instance, nice_flor_s_rainbow_table_file_name);
instance->cnt = decrypt & 0xFFFF;
instance->serial = (decrypt >> 16) & 0xFFFFFFF;
instance->btn = (decrypt >> 48) & 0xF;

View file

@ -43,7 +43,7 @@ bool subghz_protocol_nice_flor_s_create_data(
uint16_t cnt,
uint32_t frequency,
FuriHalSubGhzPreset preset,
const char* file_name);
const char* nice_flor_s_rainbow_table_file_name);
/**
* Deserialize and generating an upload to send.