Skip to content

Commit

Permalink
Merge pull request #1 from flipperdevices/dev
Browse files Browse the repository at this point in the history
[FL-2706, FL-2709] SubGhz: checking saved key files for length (flipperdevices#1485)
  • Loading branch information
dummy-decoy authored Aug 1, 2022
2 parents 84550d5 + 4da6eba commit 08aaad3
Show file tree
Hide file tree
Showing 28 changed files with 390 additions and 46 deletions.
6 changes: 4 additions & 2 deletions applications/subghz/subghz_i.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,10 @@ bool subghz_key_load(SubGhz* subghz, const char* file_path, bool show_dialog) {
subghz->txrx->decoder_result = subghz_receiver_search_decoder_base_by_name(
subghz->txrx->receiver, string_get_cstr(temp_str));
if(subghz->txrx->decoder_result) {
subghz_protocol_decoder_base_deserialize(
subghz->txrx->decoder_result, subghz->txrx->fff_data);
if(!subghz_protocol_decoder_base_deserialize(
subghz->txrx->decoder_result, subghz->txrx->fff_data)) {
break;
}
} else {
FURI_LOG_E(TAG, "Protocol not found");
break;
Expand Down
4 changes: 2 additions & 2 deletions applications/subghz/views/subghz_read_raw.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ void subghz_read_raw_draw(Canvas* canvas, SubGhzReadRAWModel* model) {
uint8_t graphics_mode = 1;
canvas_set_color(canvas, ColorBlack);
canvas_set_font(canvas, FontSecondary);
canvas_draw_str(canvas, 5, 8, string_get_cstr(model->frequency_str));
canvas_draw_str(canvas, 40, 8, string_get_cstr(model->preset_str));
canvas_draw_str(canvas, 5, 7, string_get_cstr(model->frequency_str));
canvas_draw_str(canvas, 40, 7, string_get_cstr(model->preset_str));
canvas_draw_str_aligned(
canvas, 126, 0, AlignRight, AlignTop, string_get_cstr(model->sample_write));

Expand Down
24 changes: 22 additions & 2 deletions lib/subghz/protocols/came.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,13 @@ bool subghz_protocol_encoder_came_deserialize(void* context, FlipperFormat* flip
FURI_LOG_E(TAG, "Deserialize error");
break;
}

if((instance->generic.data_count_bit !=
subghz_protocol_came_const.min_count_bit_for_found) &&
(instance->generic.data_count_bit !=
2 * subghz_protocol_came_const.min_count_bit_for_found)) {
FURI_LOG_E(TAG, "Wrong number of bits in key");
break;
}
//optional parameter parameter
flipper_format_read_uint32(
flipper_format, "Repeat", (uint32_t*)&instance->encoder.repeat, 1);
Expand Down Expand Up @@ -293,7 +299,21 @@ bool subghz_protocol_decoder_came_serialize(
bool subghz_protocol_decoder_came_deserialize(void* context, FlipperFormat* flipper_format) {
furi_assert(context);
SubGhzProtocolDecoderCame* instance = context;
return subghz_block_generic_deserialize(&instance->generic, flipper_format);
bool ret = false;
do {
if(!subghz_block_generic_deserialize(&instance->generic, flipper_format)) {
break;
}
if((instance->generic.data_count_bit !=
subghz_protocol_came_const.min_count_bit_for_found) &&
(instance->generic.data_count_bit !=
2 * subghz_protocol_came_const.min_count_bit_for_found)) {
FURI_LOG_E(TAG, "Wrong number of bits in key");
break;
}
ret = true;
} while(false);
return ret;
}

void subghz_protocol_decoder_came_get_string(void* context, string_t output) {
Expand Down
14 changes: 13 additions & 1 deletion lib/subghz/protocols/came_atomo.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,19 @@ bool subghz_protocol_decoder_came_atomo_serialize(
bool subghz_protocol_decoder_came_atomo_deserialize(void* context, FlipperFormat* flipper_format) {
furi_assert(context);
SubGhzProtocolDecoderCameAtomo* instance = context;
return subghz_block_generic_deserialize(&instance->generic, flipper_format);
bool ret = false;
do {
if(!subghz_block_generic_deserialize(&instance->generic, flipper_format)) {
break;
}
if(instance->generic.data_count_bit !=
subghz_protocol_came_atomo_const.min_count_bit_for_found) {
FURI_LOG_E(TAG, "Wrong number of bits in key");
break;
}
ret = true;
} while(false);
return ret;
}

void subghz_protocol_decoder_came_atomo_get_string(void* context, string_t output) {
Expand Down
20 changes: 18 additions & 2 deletions lib/subghz/protocols/came_twee.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,11 @@ bool subghz_protocol_encoder_came_twee_deserialize(void* context, FlipperFormat*
FURI_LOG_E(TAG, "Deserialize error");
break;
}

if(instance->generic.data_count_bit !=
subghz_protocol_came_twee_const.min_count_bit_for_found) {
FURI_LOG_E(TAG, "Wrong number of bits in key");
break;
}
//optional parameter parameter
flipper_format_read_uint32(
flipper_format, "Repeat", (uint32_t*)&instance->encoder.repeat, 1);
Expand Down Expand Up @@ -427,7 +431,19 @@ bool subghz_protocol_decoder_came_twee_serialize(
bool subghz_protocol_decoder_came_twee_deserialize(void* context, FlipperFormat* flipper_format) {
furi_assert(context);
SubGhzProtocolDecoderCameTwee* instance = context;
return subghz_block_generic_deserialize(&instance->generic, flipper_format);
bool ret = false;
do {
if(!subghz_block_generic_deserialize(&instance->generic, flipper_format)) {
break;
}
if(instance->generic.data_count_bit !=
subghz_protocol_came_twee_const.min_count_bit_for_found) {
FURI_LOG_E(TAG, "Wrong number of bits in key");
break;
}
ret = true;
} while(false);
return ret;
}

void subghz_protocol_decoder_came_twee_get_string(void* context, string_t output) {
Expand Down
20 changes: 18 additions & 2 deletions lib/subghz/protocols/chamberlain_code.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,11 @@ bool subghz_protocol_encoder_chamb_code_deserialize(void* context, FlipperFormat
FURI_LOG_E(TAG, "Deserialize error");
break;
}

if(instance->generic.data_count_bit <
subghz_protocol_chamb_code_const.min_count_bit_for_found) {
FURI_LOG_E(TAG, "Wrong number of bits in key");
break;
}
//optional parameter parameter
flipper_format_read_uint32(
flipper_format, "Repeat", (uint32_t*)&instance->encoder.repeat, 1);
Expand Down Expand Up @@ -432,7 +436,19 @@ bool subghz_protocol_decoder_chamb_code_serialize(
bool subghz_protocol_decoder_chamb_code_deserialize(void* context, FlipperFormat* flipper_format) {
furi_assert(context);
SubGhzProtocolDecoderChamb_Code* instance = context;
return subghz_block_generic_deserialize(&instance->generic, flipper_format);
bool ret = false;
do {
if(!subghz_block_generic_deserialize(&instance->generic, flipper_format)) {
break;
}
if(instance->generic.data_count_bit <
subghz_protocol_chamb_code_const.min_count_bit_for_found) {
FURI_LOG_E(TAG, "Wrong number of bits in key");
break;
}
ret = true;
} while(false);
return ret;
}

void subghz_protocol_decoder_chamb_code_get_string(void* context, string_t output) {
Expand Down
16 changes: 14 additions & 2 deletions lib/subghz/protocols/faac_slh.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ void subghz_protocol_decoder_faac_slh_feed(void* context, bool level, uint32_t d
if(duration >= ((uint32_t)subghz_protocol_faac_slh_const.te_short * 3 +
subghz_protocol_faac_slh_const.te_delta)) {
instance->decoder.parser_step = FaacSLHDecoderStepFoundPreambula;
if(instance->decoder.decode_count_bit >=
if(instance->decoder.decode_count_bit ==
subghz_protocol_faac_slh_const.min_count_bit_for_found) {
instance->generic.data = instance->decoder.decode_data;
instance->generic.data_count_bit = instance->decoder.decode_count_bit;
Expand Down Expand Up @@ -192,7 +192,19 @@ bool subghz_protocol_decoder_faac_slh_serialize(
bool subghz_protocol_decoder_faac_slh_deserialize(void* context, FlipperFormat* flipper_format) {
furi_assert(context);
SubGhzProtocolDecoderFaacSLH* instance = context;
return subghz_block_generic_deserialize(&instance->generic, flipper_format);
bool ret = false;
do {
if(!subghz_block_generic_deserialize(&instance->generic, flipper_format)) {
break;
}
if(instance->generic.data_count_bit !=
subghz_protocol_faac_slh_const.min_count_bit_for_found) {
FURI_LOG_E(TAG, "Wrong number of bits in key");
break;
}
ret = true;
} while(false);
return ret;
}

void subghz_protocol_decoder_faac_slh_get_string(void* context, string_t output) {
Expand Down
20 changes: 18 additions & 2 deletions lib/subghz/protocols/gate_tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,11 @@ bool subghz_protocol_encoder_gate_tx_deserialize(void* context, FlipperFormat* f
FURI_LOG_E(TAG, "Deserialize error");
break;
}

if(instance->generic.data_count_bit !=
subghz_protocol_gate_tx_const.min_count_bit_for_found) {
FURI_LOG_E(TAG, "Wrong number of bits in key");
break;
}
//optional parameter parameter
flipper_format_read_uint32(
flipper_format, "Repeat", (uint32_t*)&instance->encoder.repeat, 1);
Expand Down Expand Up @@ -298,7 +302,19 @@ bool subghz_protocol_decoder_gate_tx_serialize(
bool subghz_protocol_decoder_gate_tx_deserialize(void* context, FlipperFormat* flipper_format) {
furi_assert(context);
SubGhzProtocolDecoderGateTx* instance = context;
return subghz_block_generic_deserialize(&instance->generic, flipper_format);
bool ret = false;
do {
if(!subghz_block_generic_deserialize(&instance->generic, flipper_format)) {
break;
}
if(instance->generic.data_count_bit !=
subghz_protocol_gate_tx_const.min_count_bit_for_found) {
FURI_LOG_E(TAG, "Wrong number of bits in key");
break;
}
ret = true;
} while(false);
return ret;
}

void subghz_protocol_decoder_gate_tx_get_string(void* context, string_t output) {
Expand Down
20 changes: 18 additions & 2 deletions lib/subghz/protocols/holtek.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,11 @@ bool subghz_protocol_encoder_holtek_deserialize(void* context, FlipperFormat* fl
FURI_LOG_E(TAG, "Deserialize error");
break;
}

if(instance->generic.data_count_bit !=
subghz_protocol_holtek_const.min_count_bit_for_found) {
FURI_LOG_E(TAG, "Wrong number of bits in key");
break;
}
//optional parameter parameter
flipper_format_read_uint32(
flipper_format, "Repeat", (uint32_t*)&instance->encoder.repeat, 1);
Expand Down Expand Up @@ -331,7 +335,19 @@ bool subghz_protocol_decoder_holtek_serialize(
bool subghz_protocol_decoder_holtek_deserialize(void* context, FlipperFormat* flipper_format) {
furi_assert(context);
SubGhzProtocolDecoderHoltek* instance = context;
return subghz_block_generic_deserialize(&instance->generic, flipper_format);
bool ret = false;
do {
if(!subghz_block_generic_deserialize(&instance->generic, flipper_format)) {
break;
}
if(instance->generic.data_count_bit !=
subghz_protocol_holtek_const.min_count_bit_for_found) {
FURI_LOG_E(TAG, "Wrong number of bits in key");
break;
}
ret = true;
} while(false);
return ret;
}

void subghz_protocol_decoder_holtek_get_string(void* context, string_t output) {
Expand Down
20 changes: 18 additions & 2 deletions lib/subghz/protocols/hormann.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,11 @@ bool subghz_protocol_encoder_hormann_deserialize(void* context, FlipperFormat* f
FURI_LOG_E(TAG, "Deserialize error");
break;
}

if(instance->generic.data_count_bit !=
subghz_protocol_hormann_const.min_count_bit_for_found) {
FURI_LOG_E(TAG, "Wrong number of bits in key");
break;
}
//optional parameter parameter
flipper_format_read_uint32(
flipper_format, "Repeat", (uint32_t*)&instance->encoder.repeat, 1);
Expand Down Expand Up @@ -319,7 +323,19 @@ bool subghz_protocol_decoder_hormann_serialize(
bool subghz_protocol_decoder_hormann_deserialize(void* context, FlipperFormat* flipper_format) {
furi_assert(context);
SubGhzProtocolDecoderHormann* instance = context;
return subghz_block_generic_deserialize(&instance->generic, flipper_format);
bool ret = false;
do {
if(!subghz_block_generic_deserialize(&instance->generic, flipper_format)) {
break;
}
if(instance->generic.data_count_bit !=
subghz_protocol_hormann_const.min_count_bit_for_found) {
FURI_LOG_E(TAG, "Wrong number of bits in key");
break;
}
ret = true;
} while(false);
return ret;
}

void subghz_protocol_decoder_hormann_get_string(void* context, string_t output) {
Expand Down
13 changes: 12 additions & 1 deletion lib/subghz/protocols/ido.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,18 @@ bool subghz_protocol_decoder_ido_serialize(
bool subghz_protocol_decoder_ido_deserialize(void* context, FlipperFormat* flipper_format) {
furi_assert(context);
SubGhzProtocolDecoderIDo* instance = context;
return subghz_block_generic_deserialize(&instance->generic, flipper_format);
bool ret = false;
do {
if(!subghz_block_generic_deserialize(&instance->generic, flipper_format)) {
break;
}
if(instance->generic.data_count_bit != subghz_protocol_ido_const.min_count_bit_for_found) {
FURI_LOG_E(TAG, "Wrong number of bits in key");
break;
}
ret = true;
} while(false);
return ret;
}

void subghz_protocol_decoder_ido_get_string(void* context, string_t output) {
Expand Down
11 changes: 10 additions & 1 deletion lib/subghz/protocols/keeloq.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,11 @@ bool subghz_protocol_encoder_keeloq_deserialize(void* context, FlipperFormat* fl
FURI_LOG_E(TAG, "Deserialize error");
break;
}

if(instance->generic.data_count_bit !=
subghz_protocol_keeloq_const.min_count_bit_for_found) {
FURI_LOG_E(TAG, "Wrong number of bits in key");
break;
}
subghz_protocol_keeloq_check_remote_controller(
&instance->generic, instance->keystore, &instance->manufacture_name);

Expand Down Expand Up @@ -656,6 +660,11 @@ bool subghz_protocol_decoder_keeloq_deserialize(void* context, FlipperFormat* fl
FURI_LOG_E(TAG, "Deserialize error");
break;
}
if(instance->generic.data_count_bit !=
subghz_protocol_keeloq_const.min_count_bit_for_found) {
FURI_LOG_E(TAG, "Wrong number of bits in key");
break;
}
res = true;
} while(false);

Expand Down
17 changes: 14 additions & 3 deletions lib/subghz/protocols/kia.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ static const SubGhzBlockConst subghz_protocol_kia_const = {
.te_short = 250,
.te_long = 500,
.te_delta = 100,
.min_count_bit_for_found = 60,
.min_count_bit_for_found = 61,
};

struct SubGhzProtocolDecoderKIA {
Expand Down Expand Up @@ -145,7 +145,7 @@ void subghz_protocol_decoder_kia_feed(void* context, bool level, uint32_t durati
(uint32_t)(subghz_protocol_kia_const.te_long + subghz_protocol_kia_const.te_delta * 2)) {
//Found stop bit
instance->decoder.parser_step = KIADecoderStepReset;
if(instance->decoder.decode_count_bit >=
if(instance->decoder.decode_count_bit ==
subghz_protocol_kia_const.min_count_bit_for_found) {
instance->generic.data = instance->decoder.decode_data;
instance->generic.data_count_bit = instance->decoder.decode_count_bit;
Expand Down Expand Up @@ -242,7 +242,18 @@ bool subghz_protocol_decoder_kia_serialize(
bool subghz_protocol_decoder_kia_deserialize(void* context, FlipperFormat* flipper_format) {
furi_assert(context);
SubGhzProtocolDecoderKIA* instance = context;
return subghz_block_generic_deserialize(&instance->generic, flipper_format);
bool ret = false;
do {
if(!subghz_block_generic_deserialize(&instance->generic, flipper_format)) {
break;
}
if(instance->generic.data_count_bit != subghz_protocol_kia_const.min_count_bit_for_found) {
FURI_LOG_E(TAG, "Wrong number of bits in key");
break;
}
ret = true;
} while(false);
return ret;
}

void subghz_protocol_decoder_kia_get_string(void* context, string_t output) {
Expand Down
20 changes: 18 additions & 2 deletions lib/subghz/protocols/linear.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,11 @@ bool subghz_protocol_encoder_linear_deserialize(void* context, FlipperFormat* fl
FURI_LOG_E(TAG, "Deserialize error");
break;
}

if(instance->generic.data_count_bit !=
subghz_protocol_linear_const.min_count_bit_for_found) {
FURI_LOG_E(TAG, "Wrong number of bits in key");
break;
}
//optional parameter parameter
flipper_format_read_uint32(
flipper_format, "Repeat", (uint32_t*)&instance->encoder.repeat, 1);
Expand Down Expand Up @@ -308,7 +312,19 @@ bool subghz_protocol_decoder_linear_serialize(
bool subghz_protocol_decoder_linear_deserialize(void* context, FlipperFormat* flipper_format) {
furi_assert(context);
SubGhzProtocolDecoderLinear* instance = context;
return subghz_block_generic_deserialize(&instance->generic, flipper_format);
bool ret = false;
do {
if(!subghz_block_generic_deserialize(&instance->generic, flipper_format)) {
break;
}
if(instance->generic.data_count_bit !=
subghz_protocol_linear_const.min_count_bit_for_found) {
FURI_LOG_E(TAG, "Wrong number of bits in key");
break;
}
ret = true;
} while(false);
return ret;
}

void subghz_protocol_decoder_linear_get_string(void* context, string_t output) {
Expand Down
Loading

0 comments on commit 08aaad3

Please sign in to comment.