[FL-3106] SubGhz: better and more verbose error handling in protocols, stricter CAME validation (#2443)
* SubGhz: add error protocol * WS: add error protocol * SubGhz: error processing * SubGhz: more stringent CAME protocol restrictions * SubGhz: fix header duration CAME protocol * SubGhz: delete comments * SubGhz: sync SubGhzProtocolStatus with FuriStatus * SubGhz: update documentation and bump api_version Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
@@ -219,20 +219,23 @@ static bool subghz_protocol_encoder_bin_raw_get_upload(SubGhzProtocolEncoderBinR
|
||||
return true;
|
||||
}
|
||||
|
||||
bool subghz_protocol_encoder_bin_raw_deserialize(void* context, FlipperFormat* flipper_format) {
|
||||
SubGhzProtocolStatus
|
||||
subghz_protocol_encoder_bin_raw_deserialize(void* context, FlipperFormat* flipper_format) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolEncoderBinRAW* instance = context;
|
||||
|
||||
bool res = false;
|
||||
SubGhzProtocolStatus res = SubGhzProtocolStatusError;
|
||||
uint32_t temp_data = 0;
|
||||
|
||||
do {
|
||||
if(!flipper_format_rewind(flipper_format)) {
|
||||
FURI_LOG_E(TAG, "Rewind error");
|
||||
res = SubGhzProtocolStatusErrorParserOthers;
|
||||
break;
|
||||
}
|
||||
if(!flipper_format_read_uint32(flipper_format, "Bit", (uint32_t*)&temp_data, 1)) {
|
||||
FURI_LOG_E(TAG, "Missing Bit");
|
||||
res = SubGhzProtocolStatusErrorParserBitCount;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -240,6 +243,7 @@ bool subghz_protocol_encoder_bin_raw_deserialize(void* context, FlipperFormat* f
|
||||
|
||||
if(!flipper_format_read_uint32(flipper_format, "TE", (uint32_t*)&instance->te, 1)) {
|
||||
FURI_LOG_E(TAG, "Missing TE");
|
||||
res = SubGhzProtocolStatusErrorParserTe;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -251,11 +255,13 @@ bool subghz_protocol_encoder_bin_raw_deserialize(void* context, FlipperFormat* f
|
||||
while(flipper_format_read_uint32(flipper_format, "Bit_RAW", (uint32_t*)&temp_data, 1)) {
|
||||
if(ind >= BIN_RAW_MAX_MARKUP_COUNT) {
|
||||
FURI_LOG_E(TAG, "Markup overflow");
|
||||
res = SubGhzProtocolStatusErrorParserOthers;
|
||||
break;
|
||||
}
|
||||
byte_count += subghz_protocol_bin_raw_get_full_byte(temp_data);
|
||||
if(byte_count > BIN_RAW_BUF_DATA_SIZE) {
|
||||
FURI_LOG_E(TAG, "Receive buffer overflow");
|
||||
res = SubGhzProtocolStatusErrorParserOthers;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -270,6 +276,7 @@ bool subghz_protocol_encoder_bin_raw_deserialize(void* context, FlipperFormat* f
|
||||
subghz_protocol_bin_raw_get_full_byte(temp_data))) {
|
||||
instance->data_markup[ind].bit_count = 0;
|
||||
FURI_LOG_E(TAG, "Missing Data_RAW");
|
||||
res = SubGhzProtocolStatusErrorParserOthers;
|
||||
break;
|
||||
}
|
||||
ind++;
|
||||
@@ -297,16 +304,20 @@ bool subghz_protocol_encoder_bin_raw_deserialize(void* context, FlipperFormat* f
|
||||
#endif
|
||||
if(!flipper_format_rewind(flipper_format)) {
|
||||
FURI_LOG_E(TAG, "Rewind error");
|
||||
res = SubGhzProtocolStatusErrorParserOthers;
|
||||
break;
|
||||
}
|
||||
//optional parameter parameter
|
||||
flipper_format_read_uint32(
|
||||
flipper_format, "Repeat", (uint32_t*)&instance->encoder.repeat, 1);
|
||||
|
||||
if(!subghz_protocol_encoder_bin_raw_get_upload(instance)) break;
|
||||
if(!subghz_protocol_encoder_bin_raw_get_upload(instance)) {
|
||||
break;
|
||||
res = SubGhzProtocolStatusErrorEncoderGetUpload;
|
||||
}
|
||||
instance->encoder.is_running = true;
|
||||
|
||||
res = true;
|
||||
res = SubGhzProtocolStatusOk;
|
||||
} while(0);
|
||||
|
||||
return res;
|
||||
@@ -957,14 +968,14 @@ uint8_t subghz_protocol_decoder_bin_raw_get_hash_data(void* context) {
|
||||
subghz_protocol_bin_raw_get_full_byte(instance->data_markup[0].bit_count));
|
||||
}
|
||||
|
||||
bool subghz_protocol_decoder_bin_raw_serialize(
|
||||
SubGhzProtocolStatus subghz_protocol_decoder_bin_raw_serialize(
|
||||
void* context,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzRadioPreset* preset) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolDecoderBinRAW* instance = context;
|
||||
|
||||
bool res = false;
|
||||
SubGhzProtocolStatus res = SubGhzProtocolStatusError;
|
||||
FuriString* temp_str;
|
||||
temp_str = furi_string_alloc();
|
||||
do {
|
||||
@@ -972,11 +983,13 @@ bool subghz_protocol_decoder_bin_raw_serialize(
|
||||
if(!flipper_format_write_header_cstr(
|
||||
flipper_format, SUBGHZ_KEY_FILE_TYPE, SUBGHZ_KEY_FILE_VERSION)) {
|
||||
FURI_LOG_E(TAG, "Unable to add header");
|
||||
res = SubGhzProtocolStatusErrorParserHeader;
|
||||
break;
|
||||
}
|
||||
|
||||
if(!flipper_format_write_uint32(flipper_format, "Frequency", &preset->frequency, 1)) {
|
||||
FURI_LOG_E(TAG, "Unable to add Frequency");
|
||||
res = SubGhzProtocolStatusErrorParserFrequency;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -984,34 +997,40 @@ bool subghz_protocol_decoder_bin_raw_serialize(
|
||||
if(!flipper_format_write_string_cstr(
|
||||
flipper_format, "Preset", furi_string_get_cstr(temp_str))) {
|
||||
FURI_LOG_E(TAG, "Unable to add Preset");
|
||||
res = SubGhzProtocolStatusErrorParserPreset;
|
||||
break;
|
||||
}
|
||||
if(!strcmp(furi_string_get_cstr(temp_str), "FuriHalSubGhzPresetCustom")) {
|
||||
if(!flipper_format_write_string_cstr(
|
||||
flipper_format, "Custom_preset_module", "CC1101")) {
|
||||
FURI_LOG_E(TAG, "Unable to add Custom_preset_module");
|
||||
res = SubGhzProtocolStatusErrorParserCustomPreset;
|
||||
break;
|
||||
}
|
||||
if(!flipper_format_write_hex(
|
||||
flipper_format, "Custom_preset_data", preset->data, preset->data_size)) {
|
||||
FURI_LOG_E(TAG, "Unable to add Custom_preset_data");
|
||||
res = SubGhzProtocolStatusErrorParserCustomPreset;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!flipper_format_write_string_cstr(
|
||||
flipper_format, "Protocol", instance->generic.protocol_name)) {
|
||||
FURI_LOG_E(TAG, "Unable to add Protocol");
|
||||
res = SubGhzProtocolStatusErrorParserProtocolName;
|
||||
break;
|
||||
}
|
||||
|
||||
uint32_t temp = instance->generic.data_count_bit;
|
||||
if(!flipper_format_write_uint32(flipper_format, "Bit", &temp, 1)) {
|
||||
FURI_LOG_E(TAG, "Unable to add Bit");
|
||||
res = SubGhzProtocolStatusErrorParserBitCount;
|
||||
break;
|
||||
}
|
||||
|
||||
if(!flipper_format_write_uint32(flipper_format, "TE", &instance->te, 1)) {
|
||||
FURI_LOG_E(TAG, "Unable to add TE");
|
||||
res = SubGhzProtocolStatusErrorParserTe;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1020,6 +1039,7 @@ bool subghz_protocol_decoder_bin_raw_serialize(
|
||||
temp = instance->data_markup[i].bit_count;
|
||||
if(!flipper_format_write_uint32(flipper_format, "Bit_RAW", &temp, 1)) {
|
||||
FURI_LOG_E(TAG, "Bit_RAW");
|
||||
res = SubGhzProtocolStatusErrorParserOthers;
|
||||
break;
|
||||
}
|
||||
if(!flipper_format_write_hex(
|
||||
@@ -1028,31 +1048,35 @@ bool subghz_protocol_decoder_bin_raw_serialize(
|
||||
instance->data + instance->data_markup[i].byte_bias,
|
||||
subghz_protocol_bin_raw_get_full_byte(instance->data_markup[i].bit_count))) {
|
||||
FURI_LOG_E(TAG, "Unable to add Data_RAW");
|
||||
res = SubGhzProtocolStatusErrorParserOthers;
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
res = true;
|
||||
res = SubGhzProtocolStatusOk;
|
||||
} while(false);
|
||||
furi_string_free(temp_str);
|
||||
return res;
|
||||
}
|
||||
|
||||
bool subghz_protocol_decoder_bin_raw_deserialize(void* context, FlipperFormat* flipper_format) {
|
||||
SubGhzProtocolStatus
|
||||
subghz_protocol_decoder_bin_raw_deserialize(void* context, FlipperFormat* flipper_format) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolDecoderBinRAW* instance = context;
|
||||
|
||||
bool res = false;
|
||||
SubGhzProtocolStatus res = SubGhzProtocolStatusError;
|
||||
uint32_t temp_data = 0;
|
||||
|
||||
do {
|
||||
if(!flipper_format_rewind(flipper_format)) {
|
||||
FURI_LOG_E(TAG, "Rewind error");
|
||||
res = SubGhzProtocolStatusErrorParserOthers;
|
||||
break;
|
||||
}
|
||||
if(!flipper_format_read_uint32(flipper_format, "Bit", (uint32_t*)&temp_data, 1)) {
|
||||
FURI_LOG_E(TAG, "Missing Bit");
|
||||
res = SubGhzProtocolStatusErrorParserBitCount;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1060,6 +1084,7 @@ bool subghz_protocol_decoder_bin_raw_deserialize(void* context, FlipperFormat* f
|
||||
|
||||
if(!flipper_format_read_uint32(flipper_format, "TE", (uint32_t*)&instance->te, 1)) {
|
||||
FURI_LOG_E(TAG, "Missing TE");
|
||||
res = SubGhzProtocolStatusErrorParserTe;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1071,11 +1096,13 @@ bool subghz_protocol_decoder_bin_raw_deserialize(void* context, FlipperFormat* f
|
||||
while(flipper_format_read_uint32(flipper_format, "Bit_RAW", (uint32_t*)&temp_data, 1)) {
|
||||
if(ind >= BIN_RAW_MAX_MARKUP_COUNT) {
|
||||
FURI_LOG_E(TAG, "Markup overflow");
|
||||
res = SubGhzProtocolStatusErrorParserOthers;
|
||||
break;
|
||||
}
|
||||
byte_count += subghz_protocol_bin_raw_get_full_byte(temp_data);
|
||||
if(byte_count > BIN_RAW_BUF_DATA_SIZE) {
|
||||
FURI_LOG_E(TAG, "Receive buffer overflow");
|
||||
res = SubGhzProtocolStatusErrorParserOthers;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1090,12 +1117,13 @@ bool subghz_protocol_decoder_bin_raw_deserialize(void* context, FlipperFormat* f
|
||||
subghz_protocol_bin_raw_get_full_byte(temp_data))) {
|
||||
instance->data_markup[ind].bit_count = 0;
|
||||
FURI_LOG_E(TAG, "Missing Data_RAW");
|
||||
res = SubGhzProtocolStatusErrorParserOthers;
|
||||
break;
|
||||
}
|
||||
ind++;
|
||||
}
|
||||
|
||||
res = true;
|
||||
res = SubGhzProtocolStatusOk;
|
||||
} while(0);
|
||||
|
||||
return res;
|
||||
|
Reference in New Issue
Block a user