[FL-2274] Inventing streams and moving FFF to them (#981)
* Streams: string stream * String stream: updated insert/delete api * Streams: generic stream interface and string stream implementation * Streams: helpers for insert and delete_and_insert * FFF: now compatible with streams * MinUnit: introduced tests with arguments * FFF: stream access violation * Streams: copy data between streams * Streams: file stream * FFF: documentation * FFStream: documentation * FFF: alloc as file * MinUnit: support for nested tests * Streams: changed delete_and_insert, now it returns success flag. Added ability dump stream inner parameters and data to cout. * FFF: simplified file open function * Streams: unit tests * FFF: tests * Streams: declare cache_size constant as define, to allow variable modified arrays * FFF: lib moved to a separate folder * iButton: new FFF * RFID: new FFF * Animations: new FFF * IR: new FFF * NFC: new FFF * Flipper file format: delete lib * U2F: new FFF * Subghz: new FFF and streams * Streams: read line * Streams: split * FuriCore: implement memset with extra asserts * FuriCore: implement extra heap asserts without inventing memset * Scene manager: protected access to the scene id stack with a size check * NFC worker: dirty fix for issue where hal_nfc was busy on app start * Furi: update allocator to erase memory on allocation. Replace furi_alloc with malloc. * FuriCore: cleanup memmgr code. * Furi HAL: furi_hal_init is split into critical and non-critical parts. The critical part is currently clock and console. * Memmgr: added ability to track allocations and deallocations through console. * FFStream: some speedup * Streams, FF: minor fixes * Tests: restore * File stream: a slightly more thread-safe version of file_stream_delete_and_insert Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
@@ -19,7 +19,7 @@ typedef enum {
|
||||
} CameDecoderStep;
|
||||
|
||||
SubGhzProtocolCame* subghz_protocol_came_alloc() {
|
||||
SubGhzProtocolCame* instance = furi_alloc(sizeof(SubGhzProtocolCame));
|
||||
SubGhzProtocolCame* instance = malloc(sizeof(SubGhzProtocolCame));
|
||||
|
||||
instance->common.name = "CAME";
|
||||
instance->common.code_min_count_bit_for_found = 12;
|
||||
@@ -167,16 +167,16 @@ void subghz_protocol_came_to_str(SubGhzProtocolCame* instance, string_t output)
|
||||
code_found_reverse_lo);
|
||||
}
|
||||
|
||||
bool subghz_protocol_came_to_save_file(SubGhzProtocolCame* instance, FlipperFile* flipper_file) {
|
||||
return subghz_protocol_common_to_save_file((SubGhzProtocolCommon*)instance, flipper_file);
|
||||
bool subghz_protocol_came_to_save_file(SubGhzProtocolCame* instance, FlipperFormat* flipper_format) {
|
||||
return subghz_protocol_common_to_save_file((SubGhzProtocolCommon*)instance, flipper_format);
|
||||
}
|
||||
|
||||
bool subghz_protocol_came_to_load_protocol_from_file(
|
||||
FlipperFile* flipper_file,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzProtocolCame* instance,
|
||||
const char* file_path) {
|
||||
return subghz_protocol_common_to_load_protocol_from_file(
|
||||
(SubGhzProtocolCommon*)instance, flipper_file);
|
||||
(SubGhzProtocolCommon*)instance, flipper_format);
|
||||
}
|
||||
|
||||
void subghz_decoder_came_to_load_protocol(SubGhzProtocolCame* instance, void* context) {
|
||||
|
||||
@@ -48,20 +48,20 @@ void subghz_protocol_came_to_str(SubGhzProtocolCame* instance, string_t output);
|
||||
/** Adding data to a file
|
||||
*
|
||||
* @param instance - SubGhzProtocolCame instance
|
||||
* @param flipper_file - FlipperFile
|
||||
* @param flipper_format - FlipperFormat
|
||||
* @return bool
|
||||
*/
|
||||
bool subghz_protocol_came_to_save_file(SubGhzProtocolCame* instance, FlipperFile* flipper_file);
|
||||
bool subghz_protocol_came_to_save_file(SubGhzProtocolCame* instance, FlipperFormat* flipper_format);
|
||||
|
||||
/** Loading protocol from file
|
||||
*
|
||||
* @param flipper_file - FlipperFile
|
||||
* @param flipper_format - FlipperFormat
|
||||
* @param instance - SubGhzProtocolCame instance
|
||||
* @param file_path - file path
|
||||
* @return bool
|
||||
*/
|
||||
bool subghz_protocol_came_to_load_protocol_from_file(
|
||||
FlipperFile* flipper_file,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzProtocolCame* instance,
|
||||
const char* file_path);
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ typedef enum {
|
||||
} CameAtomoDecoderStep;
|
||||
|
||||
SubGhzProtocolCameAtomo* subghz_protocol_came_atomo_alloc() {
|
||||
SubGhzProtocolCameAtomo* instance = furi_alloc(sizeof(SubGhzProtocolCameAtomo));
|
||||
SubGhzProtocolCameAtomo* instance = malloc(sizeof(SubGhzProtocolCameAtomo));
|
||||
|
||||
instance->common.name = "CAME Atomo";
|
||||
instance->common.code_min_count_bit_for_found = 62;
|
||||
|
||||
@@ -27,7 +27,7 @@ typedef enum {
|
||||
} CameTweeDecoderStep;
|
||||
|
||||
SubGhzProtocolCameTwee* subghz_protocol_came_twee_alloc() {
|
||||
SubGhzProtocolCameTwee* instance = furi_alloc(sizeof(SubGhzProtocolCameTwee));
|
||||
SubGhzProtocolCameTwee* instance = malloc(sizeof(SubGhzProtocolCameTwee));
|
||||
|
||||
instance->common.name = "CAME TWEE";
|
||||
instance->common.code_min_count_bit_for_found = 54;
|
||||
@@ -327,16 +327,16 @@ void subghz_protocol_came_twee_to_str(SubGhzProtocolCameTwee* instance, string_t
|
||||
|
||||
bool subghz_protocol_came_twee_to_save_file(
|
||||
SubGhzProtocolCameTwee* instance,
|
||||
FlipperFile* flipper_file) {
|
||||
return subghz_protocol_common_to_save_file((SubGhzProtocolCommon*)instance, flipper_file);
|
||||
FlipperFormat* flipper_format) {
|
||||
return subghz_protocol_common_to_save_file((SubGhzProtocolCommon*)instance, flipper_format);
|
||||
}
|
||||
|
||||
bool subghz_protocol_came_twee_to_load_protocol_from_file(
|
||||
FlipperFile* flipper_file,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzProtocolCameTwee* instance,
|
||||
const char* file_path) {
|
||||
if(subghz_protocol_common_to_load_protocol_from_file(
|
||||
(SubGhzProtocolCommon*)instance, flipper_file)) {
|
||||
(SubGhzProtocolCommon*)instance, flipper_format)) {
|
||||
subghz_protocol_came_twee_remote_controller(instance);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -51,22 +51,22 @@ void subghz_protocol_came_twee_to_str(SubGhzProtocolCameTwee* instance, string_t
|
||||
/** Adding data to a file
|
||||
*
|
||||
* @param instance - SubGhzProtocolCameTwee instance
|
||||
* @param flipper_file - FlipperFile
|
||||
* @param flipper_format - FlipperFormat
|
||||
* @return bool
|
||||
*/
|
||||
bool subghz_protocol_came_twee_to_save_file(
|
||||
SubGhzProtocolCameTwee* instance,
|
||||
FlipperFile* flipper_file);
|
||||
FlipperFormat* flipper_format);
|
||||
|
||||
/** Loading protocol from file
|
||||
*
|
||||
* @param flipper_file - FlipperFile
|
||||
* @param flipper_format - FlipperFormat
|
||||
* @param instance - SubGhzProtocolCameTwee instance
|
||||
* @param file_path - file path
|
||||
* @return bool
|
||||
*/
|
||||
bool subghz_protocol_came_twee_to_load_protocol_from_file(
|
||||
FlipperFile* flipper_file,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzProtocolCameTwee* instance,
|
||||
const char* file_path);
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
#include <lib/toolbox/hex.h>
|
||||
|
||||
SubGhzProtocolCommonEncoder* subghz_protocol_encoder_common_alloc() {
|
||||
SubGhzProtocolCommonEncoder* instance = furi_alloc(sizeof(SubGhzProtocolCommonEncoder));
|
||||
instance->upload = furi_alloc(SUBGHZ_ENCODER_UPLOAD_MAX_SIZE * sizeof(LevelDuration));
|
||||
SubGhzProtocolCommonEncoder* instance = malloc(sizeof(SubGhzProtocolCommonEncoder));
|
||||
instance->upload = malloc(SUBGHZ_ENCODER_UPLOAD_MAX_SIZE * sizeof(LevelDuration));
|
||||
instance->start = true;
|
||||
instance->repeat = 10; //default number of repeat
|
||||
return instance;
|
||||
@@ -169,17 +169,19 @@ bool subghz_protocol_common_read_hex(string_t str, uint8_t* buff, uint16_t len)
|
||||
return parsed;
|
||||
}
|
||||
|
||||
bool subghz_protocol_common_to_save_file(SubGhzProtocolCommon* instance, FlipperFile* flipper_file) {
|
||||
bool subghz_protocol_common_to_save_file(
|
||||
SubGhzProtocolCommon* instance,
|
||||
FlipperFormat* flipper_format) {
|
||||
furi_assert(instance);
|
||||
furi_assert(flipper_file);
|
||||
furi_assert(flipper_format);
|
||||
bool res = false;
|
||||
do {
|
||||
if(!flipper_file_write_string_cstr(flipper_file, "Protocol", instance->name)) {
|
||||
if(!flipper_format_write_string_cstr(flipper_format, "Protocol", instance->name)) {
|
||||
FURI_LOG_E(SUBGHZ_PARSER_TAG, "Unable to add Protocol");
|
||||
break;
|
||||
}
|
||||
uint32_t temp = instance->code_last_count_bit;
|
||||
if(!flipper_file_write_uint32(flipper_file, "Bit", &temp, 1)) {
|
||||
if(!flipper_format_write_uint32(flipper_format, "Bit", &temp, 1)) {
|
||||
FURI_LOG_E(SUBGHZ_PARSER_TAG, "Unable to add Bit");
|
||||
break;
|
||||
}
|
||||
@@ -189,7 +191,7 @@ bool subghz_protocol_common_to_save_file(SubGhzProtocolCommon* instance, Flipper
|
||||
key_data[sizeof(uint64_t) - i - 1] = (instance->code_last_found >> i * 8) & 0xFF;
|
||||
}
|
||||
|
||||
if(!flipper_file_write_hex(flipper_file, "Key", key_data, sizeof(uint64_t))) {
|
||||
if(!flipper_format_write_hex(flipper_format, "Key", key_data, sizeof(uint64_t))) {
|
||||
FURI_LOG_E(SUBGHZ_PARSER_TAG, "Unable to add Key");
|
||||
break;
|
||||
}
|
||||
@@ -201,23 +203,23 @@ bool subghz_protocol_common_to_save_file(SubGhzProtocolCommon* instance, Flipper
|
||||
|
||||
bool subghz_protocol_common_to_load_protocol_from_file(
|
||||
SubGhzProtocolCommon* instance,
|
||||
FlipperFile* flipper_file) {
|
||||
FlipperFormat* flipper_format) {
|
||||
furi_assert(instance);
|
||||
furi_assert(flipper_file);
|
||||
furi_assert(flipper_format);
|
||||
bool loaded = false;
|
||||
string_t temp_str;
|
||||
string_init(temp_str);
|
||||
uint32_t temp_data = 0;
|
||||
|
||||
do {
|
||||
if(!flipper_file_read_uint32(flipper_file, "Bit", (uint32_t*)&temp_data, 1)) {
|
||||
if(!flipper_format_read_uint32(flipper_format, "Bit", (uint32_t*)&temp_data, 1)) {
|
||||
FURI_LOG_E(SUBGHZ_PARSER_TAG, "Missing Bit");
|
||||
break;
|
||||
}
|
||||
instance->code_last_count_bit = (uint8_t)temp_data;
|
||||
|
||||
uint8_t key_data[sizeof(uint64_t)] = {0};
|
||||
if(!flipper_file_read_hex(flipper_file, "Key", key_data, sizeof(uint64_t))) {
|
||||
if(!flipper_format_read_hex(flipper_format, "Key", key_data, sizeof(uint64_t))) {
|
||||
FURI_LOG_E(SUBGHZ_PARSER_TAG, "Missing Key");
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <m-string.h>
|
||||
#include <furi_hal.h>
|
||||
#include <stdint.h>
|
||||
#include <lib/flipper_file/flipper_file.h>
|
||||
#include <flipper_format/flipper_format.h>
|
||||
|
||||
#define bit_read(value, bit) (((value) >> (bit)) & 0x01)
|
||||
#define bit_set(value, bit) ((value) |= (1UL << (bit)))
|
||||
@@ -43,11 +43,11 @@ typedef void (*SubGhzProtocolCommonToStr)(SubGhzProtocolCommon* instance, string
|
||||
|
||||
//Get string to save
|
||||
typedef bool (
|
||||
*SubGhzProtocolCommonSaveFile)(SubGhzProtocolCommon* instance, FlipperFile* flipper_file);
|
||||
*SubGhzProtocolCommonSaveFile)(SubGhzProtocolCommon* instance, FlipperFormat* flipper_format);
|
||||
|
||||
//Load protocol from file
|
||||
typedef bool (*SubGhzProtocolCommonLoadFromFile)(
|
||||
FlipperFile* flipper_file,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzProtocolCommon* instance,
|
||||
const char* file_path);
|
||||
//Load protocol
|
||||
@@ -208,17 +208,19 @@ bool subghz_protocol_common_read_hex(string_t str, uint8_t* buff, uint16_t len);
|
||||
/** Adding data to a file
|
||||
*
|
||||
* @param instance - SubGhzProtocolCommon instance
|
||||
* @param flipper_file - FlipperFile
|
||||
* @param flipper_format - FlipperFormat
|
||||
* @return bool
|
||||
*/
|
||||
bool subghz_protocol_common_to_save_file(SubGhzProtocolCommon* instance, FlipperFile* flipper_file);
|
||||
bool subghz_protocol_common_to_save_file(
|
||||
SubGhzProtocolCommon* instance,
|
||||
FlipperFormat* flipper_format);
|
||||
|
||||
/** Loading data to a file
|
||||
*
|
||||
* @param instance - SubGhzProtocolCommon instance
|
||||
* @param flipper_file - FlipperFile
|
||||
* @param flipper_format - FlipperFormat
|
||||
* @return bool
|
||||
*/
|
||||
bool subghz_protocol_common_to_load_protocol_from_file(
|
||||
SubGhzProtocolCommon* instance,
|
||||
FlipperFile* flipper_file);
|
||||
FlipperFormat* flipper_format);
|
||||
|
||||
@@ -12,7 +12,7 @@ typedef enum {
|
||||
} FaacSLHDecoderStep;
|
||||
|
||||
SubGhzProtocolFaacSLH* subghz_protocol_faac_slh_alloc(void) {
|
||||
SubGhzProtocolFaacSLH* instance = furi_alloc(sizeof(SubGhzProtocolFaacSLH));
|
||||
SubGhzProtocolFaacSLH* instance = malloc(sizeof(SubGhzProtocolFaacSLH));
|
||||
|
||||
instance->common.name = "Faac SLH";
|
||||
instance->common.code_min_count_bit_for_found = 64;
|
||||
@@ -186,4 +186,4 @@ void subghz_decoder_faac_slh_to_load_protocol(SubGhzProtocolFaacSLH* instance, v
|
||||
instance->common.code_last_found = data->code_found;
|
||||
instance->common.code_last_count_bit = data->code_count_bit;
|
||||
subghz_protocol_faac_slh_check_remote_controller(instance);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ typedef enum {
|
||||
} GateTXDecoderStep;
|
||||
|
||||
SubGhzProtocolGateTX* subghz_protocol_gate_tx_alloc(void) {
|
||||
SubGhzProtocolGateTX* instance = furi_alloc(sizeof(SubGhzProtocolGateTX));
|
||||
SubGhzProtocolGateTX* instance = malloc(sizeof(SubGhzProtocolGateTX));
|
||||
|
||||
instance->common.name = "GateTX";
|
||||
instance->common.code_min_count_bit_for_found = 24;
|
||||
@@ -169,16 +169,16 @@ void subghz_protocol_gate_tx_to_str(SubGhzProtocolGateTX* instance, string_t out
|
||||
|
||||
bool subghz_protocol_gate_tx_to_save_file(
|
||||
SubGhzProtocolGateTX* instance,
|
||||
FlipperFile* flipper_file) {
|
||||
return subghz_protocol_common_to_save_file((SubGhzProtocolCommon*)instance, flipper_file);
|
||||
FlipperFormat* flipper_format) {
|
||||
return subghz_protocol_common_to_save_file((SubGhzProtocolCommon*)instance, flipper_format);
|
||||
}
|
||||
|
||||
bool subghz_protocol_gate_tx_to_load_protocol_from_file(
|
||||
FlipperFile* flipper_file,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzProtocolGateTX* instance,
|
||||
const char* file_path) {
|
||||
if(subghz_protocol_common_to_load_protocol_from_file(
|
||||
(SubGhzProtocolCommon*)instance, flipper_file)) {
|
||||
(SubGhzProtocolCommon*)instance, flipper_format)) {
|
||||
subghz_protocol_gate_tx_check_remote_controller(instance);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -48,22 +48,22 @@ void subghz_protocol_gate_tx_to_str(SubGhzProtocolGateTX* instance, string_t out
|
||||
/** Adding data to a file
|
||||
*
|
||||
* @param instance - SubGhzProtocolGateTX instance
|
||||
* @param flipper_file - FlipperFile
|
||||
* @param flipper_format - FlipperFormat
|
||||
* @return bool
|
||||
*/
|
||||
bool subghz_protocol_gate_tx_to_save_file(
|
||||
SubGhzProtocolGateTX* instance,
|
||||
FlipperFile* flipper_file);
|
||||
FlipperFormat* flipper_format);
|
||||
|
||||
/** Loading protocol from file
|
||||
*
|
||||
* @param flipper_file - FlipperFile
|
||||
* @param flipper_format - FlipperFormat
|
||||
* @param instance - SubGhzProtocolGateTX instance
|
||||
* @param file_path - file path
|
||||
* @return bool
|
||||
*/
|
||||
bool subghz_protocol_gate_tx_to_load_protocol_from_file(
|
||||
FlipperFile* flipper_file,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzProtocolGateTX* instance,
|
||||
const char* file_path);
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ typedef enum {
|
||||
} HormannDecoderStep;
|
||||
|
||||
SubGhzProtocolHormann* subghz_protocol_hormann_alloc() {
|
||||
SubGhzProtocolHormann* instance = furi_alloc(sizeof(SubGhzProtocolHormann));
|
||||
SubGhzProtocolHormann* instance = malloc(sizeof(SubGhzProtocolHormann));
|
||||
|
||||
instance->common.name = "Hormann HSM";
|
||||
instance->common.code_min_count_bit_for_found = 44;
|
||||
@@ -188,16 +188,16 @@ void subghz_protocol_hormann_to_str(SubGhzProtocolHormann* instance, string_t ou
|
||||
|
||||
bool subghz_protocol_hormann_to_save_file(
|
||||
SubGhzProtocolHormann* instance,
|
||||
FlipperFile* flipper_file) {
|
||||
return subghz_protocol_common_to_save_file((SubGhzProtocolCommon*)instance, flipper_file);
|
||||
FlipperFormat* flipper_format) {
|
||||
return subghz_protocol_common_to_save_file((SubGhzProtocolCommon*)instance, flipper_format);
|
||||
}
|
||||
|
||||
bool subghz_protocol_hormann_to_load_protocol_from_file(
|
||||
FlipperFile* flipper_file,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzProtocolHormann* instance,
|
||||
const char* file_path) {
|
||||
return subghz_protocol_common_to_load_protocol_from_file(
|
||||
(SubGhzProtocolCommon*)instance, flipper_file);
|
||||
(SubGhzProtocolCommon*)instance, flipper_format);
|
||||
}
|
||||
|
||||
void subghz_decoder_hormann_to_load_protocol(SubGhzProtocolHormann* instance, void* context) {
|
||||
|
||||
@@ -48,22 +48,22 @@ void subghz_protocol_hormann_to_str(SubGhzProtocolHormann* instance, string_t ou
|
||||
/** Adding data to a file
|
||||
*
|
||||
* @param instance - SubGhzProtocolHormann instance
|
||||
* @param flipper_file - FlipperFile
|
||||
* @param flipper_format - FlipperFormat
|
||||
* @return bool
|
||||
*/
|
||||
bool subghz_protocol_hormann_to_save_file(
|
||||
SubGhzProtocolHormann* instance,
|
||||
FlipperFile* flipper_file);
|
||||
FlipperFormat* flipper_format);
|
||||
|
||||
/** Loading protocol from file
|
||||
*
|
||||
* @param flipper_file - FlipperFile
|
||||
* @param flipper_format - FlipperFormat
|
||||
* @param instance - SubGhzProtocolHormann instance
|
||||
* @param file_path - file path
|
||||
* @return bool
|
||||
*/
|
||||
bool subghz_protocol_hormann_to_load_protocol_from_file(
|
||||
FlipperFile* flipper_file,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzProtocolHormann* instance,
|
||||
const char* file_path);
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ typedef enum {
|
||||
} IDoDecoderStep;
|
||||
|
||||
SubGhzProtocolIDo* subghz_protocol_ido_alloc(void) {
|
||||
SubGhzProtocolIDo* instance = furi_alloc(sizeof(SubGhzProtocolIDo));
|
||||
SubGhzProtocolIDo* instance = malloc(sizeof(SubGhzProtocolIDo));
|
||||
|
||||
instance->common.name = "iDo 117/111"; // PT4301-X";
|
||||
instance->common.code_min_count_bit_for_found = 48;
|
||||
@@ -186,4 +186,4 @@ void subghz_decoder_ido_to_load_protocol(SubGhzProtocolIDo* instance, void* cont
|
||||
instance->common.code_last_found = data->code_found;
|
||||
instance->common.code_last_count_bit = data->code_count_bit;
|
||||
subghz_protocol_ido_check_remote_controller(instance);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ typedef enum {
|
||||
} KeeloqDecoderStep;
|
||||
|
||||
SubGhzProtocolKeeloq* subghz_protocol_keeloq_alloc(SubGhzKeystore* keystore) {
|
||||
SubGhzProtocolKeeloq* instance = furi_alloc(sizeof(SubGhzProtocolKeeloq));
|
||||
SubGhzProtocolKeeloq* instance = malloc(sizeof(SubGhzProtocolKeeloq));
|
||||
|
||||
instance->keystore = keystore;
|
||||
|
||||
@@ -469,16 +469,18 @@ void subghz_protocol_keeloq_to_str(SubGhzProtocolKeeloq* instance, string_t outp
|
||||
instance->common.serial);
|
||||
}
|
||||
|
||||
bool subghz_protocol_keeloq_to_save_file(SubGhzProtocolKeeloq* instance, FlipperFile* flipper_file) {
|
||||
return subghz_protocol_common_to_save_file((SubGhzProtocolCommon*)instance, flipper_file);
|
||||
bool subghz_protocol_keeloq_to_save_file(
|
||||
SubGhzProtocolKeeloq* instance,
|
||||
FlipperFormat* flipper_format) {
|
||||
return subghz_protocol_common_to_save_file((SubGhzProtocolCommon*)instance, flipper_format);
|
||||
}
|
||||
|
||||
bool subghz_protocol_keeloq_to_load_protocol_from_file(
|
||||
FlipperFile* flipper_file,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzProtocolKeeloq* instance,
|
||||
const char* file_path) {
|
||||
return subghz_protocol_common_to_load_protocol_from_file(
|
||||
(SubGhzProtocolCommon*)instance, flipper_file);
|
||||
(SubGhzProtocolCommon*)instance, flipper_format);
|
||||
}
|
||||
|
||||
void subghz_decoder_keeloq_to_load_protocol(SubGhzProtocolKeeloq* instance, void* context) {
|
||||
|
||||
@@ -79,20 +79,22 @@ void subghz_protocol_keeloq_to_str(SubGhzProtocolKeeloq* instance, string_t outp
|
||||
/** Adding data to a file
|
||||
*
|
||||
* @param instance - SubGhzProtocolKeeloq instance
|
||||
* @param flipper_file - FlipperFile
|
||||
* @param flipper_format - FlipperFormat
|
||||
* @return bool
|
||||
*/
|
||||
bool subghz_protocol_keeloq_to_save_file(SubGhzProtocolKeeloq* instance, FlipperFile* flipper_file);
|
||||
bool subghz_protocol_keeloq_to_save_file(
|
||||
SubGhzProtocolKeeloq* instance,
|
||||
FlipperFormat* flipper_format);
|
||||
|
||||
/** Loading protocol from file
|
||||
*
|
||||
* @param flipper_file - FlipperFile
|
||||
* @param flipper_format - FlipperFormat
|
||||
* @param instance - SubGhzProtocolKeeloq instance
|
||||
* @param file_path - file path
|
||||
* @return bool
|
||||
*/
|
||||
bool subghz_protocol_keeloq_to_load_protocol_from_file(
|
||||
FlipperFile* flipper_file,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzProtocolKeeloq* instance,
|
||||
const char* file_path);
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ typedef enum {
|
||||
} KIADecoderStep;
|
||||
|
||||
SubGhzProtocolKIA* subghz_protocol_kia_alloc(void) {
|
||||
SubGhzProtocolKIA* instance = furi_alloc(sizeof(SubGhzProtocolKIA));
|
||||
SubGhzProtocolKIA* instance = malloc(sizeof(SubGhzProtocolKIA));
|
||||
|
||||
instance->common.name = "KIA";
|
||||
instance->common.code_min_count_bit_for_found = 60;
|
||||
@@ -185,4 +185,4 @@ void subghz_decoder_kia_to_load_protocol(SubGhzProtocolKIA* instance, void* cont
|
||||
instance->common.code_last_found = data->code_found;
|
||||
instance->common.code_last_count_bit = data->code_count_bit;
|
||||
subghz_protocol_kia_check_remote_controller(instance);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ typedef enum {
|
||||
} NeroRadioDecoderStep;
|
||||
|
||||
SubGhzProtocolNeroRadio* subghz_protocol_nero_radio_alloc(void) {
|
||||
SubGhzProtocolNeroRadio* instance = furi_alloc(sizeof(SubGhzProtocolNeroRadio));
|
||||
SubGhzProtocolNeroRadio* instance = malloc(sizeof(SubGhzProtocolNeroRadio));
|
||||
|
||||
instance->common.name = "Nero Radio";
|
||||
instance->common.code_min_count_bit_for_found = 55;
|
||||
@@ -211,16 +211,16 @@ void subghz_protocol_nero_radio_to_str(SubGhzProtocolNeroRadio* instance, string
|
||||
|
||||
bool subghz_protocol_nero_radio_to_save_file(
|
||||
SubGhzProtocolNeroRadio* instance,
|
||||
FlipperFile* flipper_file) {
|
||||
return subghz_protocol_common_to_save_file((SubGhzProtocolCommon*)instance, flipper_file);
|
||||
FlipperFormat* flipper_format) {
|
||||
return subghz_protocol_common_to_save_file((SubGhzProtocolCommon*)instance, flipper_format);
|
||||
}
|
||||
|
||||
bool subghz_protocol_nero_radio_to_load_protocol_from_file(
|
||||
FlipperFile* flipper_file,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzProtocolNeroRadio* instance,
|
||||
const char* file_path) {
|
||||
return subghz_protocol_common_to_load_protocol_from_file(
|
||||
(SubGhzProtocolCommon*)instance, flipper_file);
|
||||
(SubGhzProtocolCommon*)instance, flipper_format);
|
||||
}
|
||||
|
||||
void subghz_decoder_nero_radio_to_load_protocol(SubGhzProtocolNeroRadio* instance, void* context) {
|
||||
@@ -229,4 +229,4 @@ void subghz_decoder_nero_radio_to_load_protocol(SubGhzProtocolNeroRadio* instanc
|
||||
SubGhzProtocolCommonLoad* data = context;
|
||||
instance->common.code_last_found = data->code_found;
|
||||
instance->common.code_last_count_bit = data->code_count_bit;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,22 +57,22 @@ void subghz_protocol_nero_radio_to_str(SubGhzProtocolNeroRadio* instance, string
|
||||
/** Adding data to a file
|
||||
*
|
||||
* @param instance - SubGhzProtocolNeroRadio instance
|
||||
* @param flipper_file - FlipperFile
|
||||
* @param flipper_format - FlipperFormat
|
||||
* @return bool
|
||||
*/
|
||||
bool subghz_protocol_nero_radio_to_save_file(
|
||||
SubGhzProtocolNeroRadio* instance,
|
||||
FlipperFile* flipper_file);
|
||||
FlipperFormat* flipper_format);
|
||||
|
||||
/** Loading protocol from file
|
||||
*
|
||||
* @param flipper_file - FlipperFile
|
||||
* @param flipper_format - FlipperFormat
|
||||
* @param instance - SubGhzProtocolNeroRadio instance
|
||||
* @param file_path - file path
|
||||
* @return bool
|
||||
*/
|
||||
bool subghz_protocol_nero_radio_to_load_protocol_from_file(
|
||||
FlipperFile* flipper_file,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzProtocolNeroRadio* instance,
|
||||
const char* file_path);
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ typedef enum {
|
||||
} NeroSketchDecoderStep;
|
||||
|
||||
SubGhzProtocolNeroSketch* subghz_protocol_nero_sketch_alloc(void) {
|
||||
SubGhzProtocolNeroSketch* instance = furi_alloc(sizeof(SubGhzProtocolNeroSketch));
|
||||
SubGhzProtocolNeroSketch* instance = malloc(sizeof(SubGhzProtocolNeroSketch));
|
||||
|
||||
instance->common.name = "Nero Sketch";
|
||||
instance->common.code_min_count_bit_for_found = 40;
|
||||
@@ -204,16 +204,16 @@ void subghz_protocol_nero_sketch_to_str(SubGhzProtocolNeroSketch* instance, stri
|
||||
|
||||
bool subghz_protocol_nero_sketch_to_save_file(
|
||||
SubGhzProtocolNeroSketch* instance,
|
||||
FlipperFile* flipper_file) {
|
||||
return subghz_protocol_common_to_save_file((SubGhzProtocolCommon*)instance, flipper_file);
|
||||
FlipperFormat* flipper_format) {
|
||||
return subghz_protocol_common_to_save_file((SubGhzProtocolCommon*)instance, flipper_format);
|
||||
}
|
||||
|
||||
bool subghz_protocol_nero_sketch_to_load_protocol_from_file(
|
||||
FlipperFile* flipper_file,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzProtocolNeroSketch* instance,
|
||||
const char* file_path) {
|
||||
return subghz_protocol_common_to_load_protocol_from_file(
|
||||
(SubGhzProtocolCommon*)instance, flipper_file);
|
||||
(SubGhzProtocolCommon*)instance, flipper_format);
|
||||
}
|
||||
|
||||
void subghz_decoder_nero_sketch_to_load_protocol(SubGhzProtocolNeroSketch* instance, void* context) {
|
||||
|
||||
@@ -57,22 +57,22 @@ void subghz_protocol_nero_sketch_to_str(SubGhzProtocolNeroSketch* instance, stri
|
||||
/** Adding data to a file
|
||||
*
|
||||
* @param instance - SubGhzProtocolNeroSketch instance
|
||||
* @param flipper_file - FlipperFile
|
||||
* @param flipper_format - FlipperFormat
|
||||
* @return bool
|
||||
*/
|
||||
bool subghz_protocol_nero_sketch_to_save_file(
|
||||
SubGhzProtocolNeroSketch* instance,
|
||||
FlipperFile* flipper_file);
|
||||
FlipperFormat* flipper_format);
|
||||
|
||||
/** Loading protocol from file
|
||||
*
|
||||
* @param flipper_file - FlipperFile
|
||||
* @param flipper_format - FlipperFormat
|
||||
* @param instance - SubGhzProtocolNeroSketch instance
|
||||
* @param file_path - file path
|
||||
* @return bool
|
||||
*/
|
||||
bool subghz_protocol_nero_sketch_to_load_protocol_from_file(
|
||||
FlipperFile* flipper_file,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzProtocolNeroSketch* instance,
|
||||
const char* file_path);
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ typedef enum {
|
||||
} NiceFloDecoderStep;
|
||||
|
||||
SubGhzProtocolNiceFlo* subghz_protocol_nice_flo_alloc() {
|
||||
SubGhzProtocolNiceFlo* instance = furi_alloc(sizeof(SubGhzProtocolNiceFlo));
|
||||
SubGhzProtocolNiceFlo* instance = malloc(sizeof(SubGhzProtocolNiceFlo));
|
||||
|
||||
instance->common.name = "Nice FLO";
|
||||
instance->common.code_min_count_bit_for_found = 12;
|
||||
@@ -166,16 +166,16 @@ void subghz_protocol_nice_flo_to_str(SubGhzProtocolNiceFlo* instance, string_t o
|
||||
|
||||
bool subghz_protocol_nice_flo_to_save_file(
|
||||
SubGhzProtocolNiceFlo* instance,
|
||||
FlipperFile* flipper_file) {
|
||||
return subghz_protocol_common_to_save_file((SubGhzProtocolCommon*)instance, flipper_file);
|
||||
FlipperFormat* flipper_format) {
|
||||
return subghz_protocol_common_to_save_file((SubGhzProtocolCommon*)instance, flipper_format);
|
||||
}
|
||||
|
||||
bool subghz_protocol_nice_flo_to_load_protocol_from_file(
|
||||
FlipperFile* flipper_file,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzProtocolNiceFlo* instance,
|
||||
const char* file_path) {
|
||||
return subghz_protocol_common_to_load_protocol_from_file(
|
||||
(SubGhzProtocolCommon*)instance, flipper_file);
|
||||
(SubGhzProtocolCommon*)instance, flipper_format);
|
||||
}
|
||||
|
||||
void subghz_decoder_nice_flo_to_load_protocol(SubGhzProtocolNiceFlo* instance, void* context) {
|
||||
|
||||
@@ -48,22 +48,22 @@ void subghz_protocol_nice_flo_to_str(SubGhzProtocolNiceFlo* instance, string_t o
|
||||
/** Adding data to a file
|
||||
*
|
||||
* @param instance - SubGhzProtocolNiceFlo instance
|
||||
* @param flipper_file - FlipperFile
|
||||
* @param flipper_format - FlipperFormat
|
||||
* @return bool
|
||||
*/
|
||||
bool subghz_protocol_nice_flo_to_save_file(
|
||||
SubGhzProtocolNiceFlo* instance,
|
||||
FlipperFile* flipper_file);
|
||||
FlipperFormat* flipper_format);
|
||||
|
||||
/** Loading protocol from file
|
||||
*
|
||||
* @param flipper_file - FlipperFile
|
||||
* @param flipper_format - FlipperFormat
|
||||
* @param instance - SubGhzProtocolNiceFlo instance
|
||||
* @param file_path - file path
|
||||
* @return bool
|
||||
*/
|
||||
bool subghz_protocol_nice_flo_to_load_protocol_from_file(
|
||||
FlipperFile* flipper_file,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzProtocolNiceFlo* instance,
|
||||
const char* file_path);
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ typedef enum {
|
||||
} NiceFlorSDecoderStep;
|
||||
|
||||
SubGhzProtocolNiceFlorS* subghz_protocol_nice_flor_s_alloc() {
|
||||
SubGhzProtocolNiceFlorS* instance = furi_alloc(sizeof(SubGhzProtocolNiceFlorS));
|
||||
SubGhzProtocolNiceFlorS* instance = malloc(sizeof(SubGhzProtocolNiceFlorS));
|
||||
|
||||
instance->common.name = "Nice FloR-S";
|
||||
instance->common.code_min_count_bit_for_found = 52;
|
||||
@@ -261,4 +261,4 @@ void subghz_decoder_nice_flor_s_to_load_protocol(SubGhzProtocolNiceFlorS* instan
|
||||
instance->common.code_last_found = data->code_found;
|
||||
instance->common.code_last_count_bit = data->code_count_bit;
|
||||
subghz_nice_flor_s_decoder_decrypt(instance);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ typedef enum {
|
||||
} PrincetonDecoderStep;
|
||||
|
||||
SubGhzEncoderPrinceton* subghz_encoder_princeton_alloc() {
|
||||
SubGhzEncoderPrinceton* instance = furi_alloc(sizeof(SubGhzEncoderPrinceton));
|
||||
SubGhzEncoderPrinceton* instance = malloc(sizeof(SubGhzEncoderPrinceton));
|
||||
return instance;
|
||||
}
|
||||
|
||||
@@ -171,7 +171,7 @@ LevelDuration subghz_encoder_princeton_yield(void* context) {
|
||||
}
|
||||
|
||||
SubGhzDecoderPrinceton* subghz_decoder_princeton_alloc(void) {
|
||||
SubGhzDecoderPrinceton* instance = furi_alloc(sizeof(SubGhzDecoderPrinceton));
|
||||
SubGhzDecoderPrinceton* instance = malloc(sizeof(SubGhzDecoderPrinceton));
|
||||
|
||||
instance->te = SUBGHZ_PT_SHORT;
|
||||
instance->common.name = "Princeton";
|
||||
@@ -333,23 +333,24 @@ void subghz_decoder_princeton_to_str(SubGhzDecoderPrinceton* instance, string_t
|
||||
|
||||
bool subghz_decoder_princeton_to_save_file(
|
||||
SubGhzDecoderPrinceton* instance,
|
||||
FlipperFile* flipper_file) {
|
||||
bool res = subghz_protocol_common_to_save_file((SubGhzProtocolCommon*)instance, flipper_file);
|
||||
FlipperFormat* flipper_format) {
|
||||
bool res =
|
||||
subghz_protocol_common_to_save_file((SubGhzProtocolCommon*)instance, flipper_format);
|
||||
if(res) {
|
||||
res = flipper_file_write_uint32(flipper_file, "TE", &instance->te, 1);
|
||||
res = flipper_format_write_uint32(flipper_format, "TE", &instance->te, 1);
|
||||
if(!res) FURI_LOG_E(SUBGHZ_PARSER_TAG, "Unable to add Te");
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
bool subghz_decoder_princeton_to_load_protocol_from_file(
|
||||
FlipperFile* flipper_file,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzDecoderPrinceton* instance,
|
||||
const char* file_path) {
|
||||
bool loaded = subghz_protocol_common_to_load_protocol_from_file(
|
||||
(SubGhzProtocolCommon*)instance, flipper_file);
|
||||
(SubGhzProtocolCommon*)instance, flipper_format);
|
||||
if(loaded) {
|
||||
loaded = flipper_file_read_uint32(flipper_file, "TE", (uint32_t*)&instance->te, 1);
|
||||
loaded = flipper_format_read_uint32(flipper_format, "TE", (uint32_t*)&instance->te, 1);
|
||||
if(!loaded) FURI_LOG_E(SUBGHZ_PARSER_TAG, "Missing TE");
|
||||
}
|
||||
return loaded;
|
||||
|
||||
@@ -110,22 +110,22 @@ void subghz_decoder_princeton_to_str(SubGhzDecoderPrinceton* instance, string_t
|
||||
/** Adding data to a file
|
||||
*
|
||||
* @param instance - SubGhzDecoderPrinceton instance
|
||||
* @param flipper_file - FlipperFile
|
||||
* @param flipper_format - FlipperFormat
|
||||
* @return bool
|
||||
*/
|
||||
bool subghz_decoder_princeton_to_save_file(
|
||||
SubGhzDecoderPrinceton* instance,
|
||||
FlipperFile* flipper_file);
|
||||
FlipperFormat* flipper_format);
|
||||
|
||||
/** Loading protocol from file
|
||||
*
|
||||
* @param flipper_file - FlipperFile
|
||||
* @param flipper_format - FlipperFormat
|
||||
* @param instance - SubGhzDecoderPrinceton instance
|
||||
* @param file_path - file path
|
||||
* @return bool
|
||||
*/
|
||||
bool subghz_decoder_princeton_to_load_protocol_from_file(
|
||||
FlipperFile* flipper_file,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzDecoderPrinceton* instance,
|
||||
const char* file_path);
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ struct SubGhzProtocolRAW {
|
||||
int32_t* upload_raw;
|
||||
uint16_t ind_write;
|
||||
Storage* storage;
|
||||
FlipperFile* flipper_file;
|
||||
FlipperFormat* flipper_format;
|
||||
SubGhzFileEncoderWorker* file_worker_encoder;
|
||||
uint32_t file_is_open;
|
||||
string_t file_name;
|
||||
@@ -28,7 +28,7 @@ typedef enum {
|
||||
} RAWFilIsOpen;
|
||||
|
||||
SubGhzProtocolRAW* subghz_protocol_raw_alloc(void) {
|
||||
SubGhzProtocolRAW* instance = furi_alloc(sizeof(SubGhzProtocolRAW));
|
||||
SubGhzProtocolRAW* instance = malloc(sizeof(SubGhzProtocolRAW));
|
||||
|
||||
instance->upload_raw = NULL;
|
||||
instance->ind_write = 0;
|
||||
@@ -36,7 +36,7 @@ SubGhzProtocolRAW* subghz_protocol_raw_alloc(void) {
|
||||
instance->last_level = false;
|
||||
|
||||
instance->storage = furi_record_open("storage");
|
||||
instance->flipper_file = flipper_file_alloc(instance->storage);
|
||||
instance->flipper_format = flipper_format_file_alloc(instance->storage);
|
||||
instance->file_is_open = RAWFileIsOpenClose;
|
||||
string_init(instance->file_name);
|
||||
|
||||
@@ -61,7 +61,7 @@ void subghz_protocol_raw_free(SubGhzProtocolRAW* instance) {
|
||||
furi_assert(instance);
|
||||
string_clear(instance->file_name);
|
||||
|
||||
flipper_file_free(instance->flipper_file);
|
||||
flipper_format_free(instance->flipper_format);
|
||||
furi_record_close("storage");
|
||||
|
||||
free(instance);
|
||||
@@ -166,7 +166,7 @@ bool subghz_protocol_raw_save_to_file_init(
|
||||
const char* preset) {
|
||||
furi_assert(instance);
|
||||
|
||||
//instance->flipper_file = flipper_file_alloc(instance->storage);
|
||||
//instance->flipper_format = flipper_format_file_alloc(instance->storage);
|
||||
string_t dev_file_name;
|
||||
string_init(dev_file_name);
|
||||
bool init = false;
|
||||
@@ -186,34 +186,35 @@ bool subghz_protocol_raw_save_to_file_init(
|
||||
}
|
||||
|
||||
// Open file
|
||||
if(!flipper_file_open_always(instance->flipper_file, string_get_cstr(dev_file_name))) {
|
||||
if(!flipper_format_file_open_always(
|
||||
instance->flipper_format, string_get_cstr(dev_file_name))) {
|
||||
FURI_LOG_E(TAG, "Unable to open file for write: %s", dev_file_name);
|
||||
break;
|
||||
}
|
||||
|
||||
if(!flipper_file_write_header_cstr(
|
||||
instance->flipper_file, SUBGHZ_RAW_FILE_TYPE, SUBGHZ_RAW_FILE_VERSION)) {
|
||||
if(!flipper_format_write_header_cstr(
|
||||
instance->flipper_format, SUBGHZ_RAW_FILE_TYPE, SUBGHZ_RAW_FILE_VERSION)) {
|
||||
FURI_LOG_E(TAG, "Unable to add header");
|
||||
break;
|
||||
}
|
||||
|
||||
if(!flipper_file_write_uint32(instance->flipper_file, "Frequency", &frequency, 1)) {
|
||||
if(!flipper_format_write_uint32(instance->flipper_format, "Frequency", &frequency, 1)) {
|
||||
FURI_LOG_E(TAG, "Unable to add Frequency");
|
||||
break;
|
||||
}
|
||||
|
||||
if(!flipper_file_write_string_cstr(instance->flipper_file, "Preset", preset)) {
|
||||
if(!flipper_format_write_string_cstr(instance->flipper_format, "Preset", preset)) {
|
||||
FURI_LOG_E(TAG, "Unable to add Preset");
|
||||
break;
|
||||
}
|
||||
|
||||
if(!flipper_file_write_string_cstr(
|
||||
instance->flipper_file, "Protocol", instance->common.name)) {
|
||||
if(!flipper_format_write_string_cstr(
|
||||
instance->flipper_format, "Protocol", instance->common.name)) {
|
||||
FURI_LOG_E(TAG, "Unable to add Protocol");
|
||||
break;
|
||||
}
|
||||
|
||||
instance->upload_raw = furi_alloc(SUBGHZ_DOWNLOAD_MAX_SIZE * sizeof(int32_t));
|
||||
instance->upload_raw = malloc(SUBGHZ_DOWNLOAD_MAX_SIZE * sizeof(int32_t));
|
||||
instance->file_is_open = RAWFileIsOpenWrite;
|
||||
instance->sample_write = 0;
|
||||
init = true;
|
||||
@@ -234,7 +235,7 @@ void subghz_protocol_raw_save_to_file_stop(SubGhzProtocolRAW* instance) {
|
||||
instance->upload_raw = NULL;
|
||||
}
|
||||
|
||||
flipper_file_close(instance->flipper_file);
|
||||
flipper_format_file_close(instance->flipper_format);
|
||||
instance->file_is_open = RAWFileIsOpenClose;
|
||||
}
|
||||
|
||||
@@ -243,8 +244,8 @@ bool subghz_protocol_raw_save_to_file_write(SubGhzProtocolRAW* instance) {
|
||||
|
||||
bool is_write = false;
|
||||
if(instance->file_is_open == RAWFileIsOpenWrite) {
|
||||
if(!flipper_file_write_int32(
|
||||
instance->flipper_file, "RAW_Data", instance->upload_raw, instance->ind_write)) {
|
||||
if(!flipper_format_write_int32(
|
||||
instance->flipper_format, "RAW_Data", instance->upload_raw, instance->ind_write)) {
|
||||
FURI_LOG_E(TAG, "Unable to add RAW_Data");
|
||||
} else {
|
||||
instance->sample_write += instance->ind_write;
|
||||
@@ -260,10 +261,10 @@ size_t subghz_protocol_raw_get_sample_write(SubGhzProtocolRAW* instance) {
|
||||
}
|
||||
|
||||
bool subghz_protocol_raw_to_load_protocol_from_file(
|
||||
FlipperFile* flipper_file,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzProtocolRAW* instance,
|
||||
const char* file_path) {
|
||||
furi_assert(file_path);
|
||||
subghz_protocol_raw_set_last_file_name(instance, file_path);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,6 +66,6 @@ bool subghz_protocol_raw_save_to_file_write(SubGhzProtocolRAW* instance);
|
||||
size_t subghz_protocol_raw_get_sample_write(SubGhzProtocolRAW* instance);
|
||||
|
||||
bool subghz_protocol_raw_to_load_protocol_from_file(
|
||||
FlipperFile* flipper_file,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzProtocolRAW* instance,
|
||||
const char* file_path);
|
||||
@@ -18,7 +18,7 @@ typedef enum {
|
||||
} ScherKhanDecoderStep;
|
||||
|
||||
SubGhzProtocolScherKhan* subghz_protocol_scher_khan_alloc(void) {
|
||||
SubGhzProtocolScherKhan* instance = furi_alloc(sizeof(SubGhzProtocolScherKhan));
|
||||
SubGhzProtocolScherKhan* instance = malloc(sizeof(SubGhzProtocolScherKhan));
|
||||
|
||||
instance->common.name = "Scher-Khan";
|
||||
instance->common.code_min_count_bit_for_found = 35;
|
||||
@@ -241,4 +241,4 @@ void subghz_decoder_scher_khan_to_load_protocol(SubGhzProtocolScherKhan* instanc
|
||||
instance->common.code_last_found = data->code_found;
|
||||
instance->common.code_last_count_bit = data->code_count_bit;
|
||||
subghz_protocol_scher_khan_check_remote_controller(instance);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ typedef enum {
|
||||
} SomfyKeytisDecoderStep;
|
||||
|
||||
SubGhzProtocolSomfyKeytis* subghz_protocol_somfy_keytis_alloc() {
|
||||
SubGhzProtocolSomfyKeytis* instance = furi_alloc(sizeof(SubGhzProtocolSomfyKeytis));
|
||||
SubGhzProtocolSomfyKeytis* instance = malloc(sizeof(SubGhzProtocolSomfyKeytis));
|
||||
|
||||
instance->common.name = "Somfy Keytis";
|
||||
instance->common.code_min_count_bit_for_found = 80;
|
||||
|
||||
@@ -18,7 +18,7 @@ typedef enum {
|
||||
} SomfyTelisDecoderStep;
|
||||
|
||||
SubGhzProtocolSomfyTelis* subghz_protocol_somfy_telis_alloc() {
|
||||
SubGhzProtocolSomfyTelis* instance = furi_alloc(sizeof(SubGhzProtocolSomfyTelis));
|
||||
SubGhzProtocolSomfyTelis* instance = malloc(sizeof(SubGhzProtocolSomfyTelis));
|
||||
|
||||
instance->common.name = "Somfy Telis";
|
||||
instance->common.code_min_count_bit_for_found = 56;
|
||||
|
||||
@@ -22,7 +22,7 @@ typedef enum {
|
||||
} StarLineDecoderStep;
|
||||
|
||||
SubGhzProtocolStarLine* subghz_protocol_star_line_alloc(SubGhzKeystore* keystore) {
|
||||
SubGhzProtocolStarLine* instance = furi_alloc(sizeof(SubGhzProtocolStarLine));
|
||||
SubGhzProtocolStarLine* instance = malloc(sizeof(SubGhzProtocolStarLine));
|
||||
|
||||
instance->keystore = keystore;
|
||||
|
||||
@@ -338,4 +338,4 @@ void subghz_decoder_star_line_to_load_protocol(SubGhzProtocolStarLine* instance,
|
||||
instance->common.code_last_found = data->code_found;
|
||||
instance->common.code_last_count_bit = data->code_count_bit;
|
||||
subghz_protocol_star_line_check_remote_controller(instance);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
#include "subghz_file_encoder_worker.h"
|
||||
#include <stream_buffer.h>
|
||||
|
||||
#include <lib/flipper_file/flipper_file.h>
|
||||
#include <lib/flipper_file/file_helper.h>
|
||||
#include <toolbox/stream/stream.h>
|
||||
#include <flipper_format/flipper_format.h>
|
||||
#include <flipper_format/flipper_format_i.h>
|
||||
|
||||
#define TAG "SubGhzFileEncoderWorker"
|
||||
|
||||
@@ -13,7 +14,7 @@ struct SubGhzFileEncoderWorker {
|
||||
StreamBufferHandle_t stream;
|
||||
|
||||
Storage* storage;
|
||||
FlipperFile* flipper_file;
|
||||
FlipperFormat* flipper_format;
|
||||
|
||||
volatile bool worker_running;
|
||||
volatile bool worker_stoping;
|
||||
@@ -121,21 +122,21 @@ static int32_t subghz_file_encoder_worker_thread(void* context) {
|
||||
SubGhzFileEncoderWorker* instance = context;
|
||||
FURI_LOG_I(TAG, "Worker start");
|
||||
bool res = false;
|
||||
File* file = flipper_file_get_file(instance->flipper_file);
|
||||
Stream* stream = flipper_format_get_raw_stream(instance->flipper_format);
|
||||
do {
|
||||
if(!flipper_file_open_existing(
|
||||
instance->flipper_file, string_get_cstr(instance->file_path))) {
|
||||
if(!flipper_format_file_open_existing(
|
||||
instance->flipper_format, string_get_cstr(instance->file_path))) {
|
||||
FURI_LOG_E(
|
||||
TAG, "Unable to open file for read: %s", string_get_cstr(instance->file_path));
|
||||
break;
|
||||
}
|
||||
if(!flipper_file_read_string(instance->flipper_file, "Protocol", instance->str_data)) {
|
||||
if(!flipper_format_read_string(instance->flipper_format, "Protocol", instance->str_data)) {
|
||||
FURI_LOG_E(TAG, "Missing Protocol");
|
||||
break;
|
||||
}
|
||||
|
||||
//skip the end of the previous line "\n"
|
||||
storage_file_seek(file, 1, false);
|
||||
stream_seek(stream, 1, StreamOffsetFromCurrent);
|
||||
res = true;
|
||||
instance->worker_stoping = false;
|
||||
FURI_LOG_I(TAG, "Start transmission");
|
||||
@@ -144,9 +145,9 @@ static int32_t subghz_file_encoder_worker_thread(void* context) {
|
||||
while(res && instance->worker_running) {
|
||||
size_t stream_free_byte = xStreamBufferSpacesAvailable(instance->stream);
|
||||
if((stream_free_byte / sizeof(int32_t)) >= SUBGHZ_FILE_ENCODER_LOAD) {
|
||||
if(file_helper_read_line(file, instance->str_data)) {
|
||||
if(stream_read_line(stream, instance->str_data)) {
|
||||
//skip the end of the previous line "\n"
|
||||
storage_file_seek(file, 1, false);
|
||||
stream_seek(stream, 1, StreamOffsetFromCurrent);
|
||||
if(!subghz_file_encoder_worker_data_parse(
|
||||
instance,
|
||||
string_get_cstr(instance->str_data),
|
||||
@@ -174,14 +175,14 @@ static int32_t subghz_file_encoder_worker_thread(void* context) {
|
||||
}
|
||||
osDelay(50);
|
||||
}
|
||||
flipper_file_close(instance->flipper_file);
|
||||
flipper_format_file_close(instance->flipper_format);
|
||||
|
||||
FURI_LOG_I(TAG, "Worker stop");
|
||||
return 0;
|
||||
}
|
||||
|
||||
SubGhzFileEncoderWorker* subghz_file_encoder_worker_alloc() {
|
||||
SubGhzFileEncoderWorker* instance = furi_alloc(sizeof(SubGhzFileEncoderWorker));
|
||||
SubGhzFileEncoderWorker* instance = malloc(sizeof(SubGhzFileEncoderWorker));
|
||||
|
||||
instance->thread = furi_thread_alloc();
|
||||
furi_thread_set_name(instance->thread, "SubghzFEWorker");
|
||||
@@ -191,7 +192,7 @@ SubGhzFileEncoderWorker* subghz_file_encoder_worker_alloc() {
|
||||
instance->stream = xStreamBufferCreate(sizeof(int32_t) * 2048, sizeof(int32_t));
|
||||
|
||||
instance->storage = furi_record_open("storage");
|
||||
instance->flipper_file = flipper_file_alloc(instance->storage);
|
||||
instance->flipper_format = flipper_format_file_alloc(instance->storage);
|
||||
|
||||
string_init(instance->str_data);
|
||||
string_init(instance->file_path);
|
||||
@@ -210,7 +211,7 @@ void subghz_file_encoder_worker_free(SubGhzFileEncoderWorker* instance) {
|
||||
string_clear(instance->str_data);
|
||||
string_clear(instance->file_path);
|
||||
|
||||
flipper_file_free(instance->flipper_file);
|
||||
flipper_format_free(instance->flipper_format);
|
||||
furi_record_close("storage");
|
||||
|
||||
free(instance);
|
||||
|
||||
@@ -5,7 +5,9 @@
|
||||
|
||||
#include <storage/storage.h>
|
||||
#include <toolbox/hex.h>
|
||||
#include <flipper_file/flipper_file.h>
|
||||
#include <toolbox/stream/stream.h>
|
||||
#include <flipper_format/flipper_format.h>
|
||||
#include <flipper_format/flipper_format_i.h>
|
||||
|
||||
#define TAG "SubGhzKeystore"
|
||||
|
||||
@@ -29,7 +31,7 @@ struct SubGhzKeystore {
|
||||
};
|
||||
|
||||
SubGhzKeystore* subghz_keystore_alloc() {
|
||||
SubGhzKeystore* instance = furi_alloc(sizeof(SubGhzKeystore));
|
||||
SubGhzKeystore* instance = malloc(sizeof(SubGhzKeystore));
|
||||
|
||||
SubGhzKeyArray_init(instance->data);
|
||||
|
||||
@@ -104,19 +106,19 @@ static void subghz_keystore_mess_with_iv(uint8_t* iv) {
|
||||
: "r0", "r1", "r2", "r3", "memory");
|
||||
}
|
||||
|
||||
static bool subghz_keystore_read_file(SubGhzKeystore* instance, File* file, uint8_t* iv) {
|
||||
static bool subghz_keystore_read_file(SubGhzKeystore* instance, Stream* stream, uint8_t* iv) {
|
||||
bool result = true;
|
||||
char buffer[FILE_BUFFER_SIZE];
|
||||
uint8_t buffer[FILE_BUFFER_SIZE];
|
||||
|
||||
char* decrypted_line = furi_alloc(SUBGHZ_KEYSTORE_FILE_DECRYPTED_LINE_SIZE);
|
||||
char* encrypted_line = furi_alloc(SUBGHZ_KEYSTORE_FILE_ENCRYPTED_LINE_SIZE);
|
||||
char* decrypted_line = malloc(SUBGHZ_KEYSTORE_FILE_DECRYPTED_LINE_SIZE);
|
||||
char* encrypted_line = malloc(SUBGHZ_KEYSTORE_FILE_ENCRYPTED_LINE_SIZE);
|
||||
size_t encrypted_line_cursor = 0;
|
||||
|
||||
if(iv) furi_hal_crypto_store_load_key(SUBGHZ_KEYSTORE_FILE_ENCRYPTION_KEY_SLOT, iv);
|
||||
|
||||
size_t ret = 0;
|
||||
do {
|
||||
ret = storage_file_read(file, buffer, FILE_BUFFER_SIZE);
|
||||
ret = stream_read(stream, buffer, FILE_BUFFER_SIZE);
|
||||
for(uint16_t i = 0; i < ret; i++) {
|
||||
if(buffer[i] == '\n' && encrypted_line_cursor > 0) {
|
||||
// Process line
|
||||
@@ -187,17 +189,17 @@ bool subghz_keystore_load(SubGhzKeystore* instance, const char* file_name) {
|
||||
|
||||
Storage* storage = furi_record_open("storage");
|
||||
|
||||
FlipperFile* flipper_file = flipper_file_alloc(storage);
|
||||
FlipperFormat* flipper_format = flipper_format_file_alloc(storage);
|
||||
do {
|
||||
if(!flipper_file_open_existing(flipper_file, file_name)) {
|
||||
if(!flipper_format_file_open_existing(flipper_format, file_name)) {
|
||||
FURI_LOG_E(TAG, "Unable to open file for read: %s", file_name);
|
||||
break;
|
||||
}
|
||||
if(!flipper_file_read_header(flipper_file, filetype, &version)) {
|
||||
if(!flipper_format_read_header(flipper_format, filetype, &version)) {
|
||||
FURI_LOG_E(TAG, "Missing or incorrect header");
|
||||
break;
|
||||
}
|
||||
if(!flipper_file_read_uint32(flipper_file, "Encryption", (uint32_t*)&encryption, 1)) {
|
||||
if(!flipper_format_read_uint32(flipper_format, "Encryption", (uint32_t*)&encryption, 1)) {
|
||||
FURI_LOG_E(TAG, "Missing encryption type");
|
||||
break;
|
||||
}
|
||||
@@ -208,23 +210,22 @@ bool subghz_keystore_load(SubGhzKeystore* instance, const char* file_name) {
|
||||
break;
|
||||
}
|
||||
|
||||
File* file = flipper_file_get_file(flipper_file);
|
||||
Stream* stream = flipper_format_get_raw_stream(flipper_format);
|
||||
if(encryption == SubGhzKeystoreEncryptionNone) {
|
||||
result = subghz_keystore_read_file(instance, file, NULL);
|
||||
result = subghz_keystore_read_file(instance, stream, NULL);
|
||||
} else if(encryption == SubGhzKeystoreEncryptionAES256) {
|
||||
if(!flipper_file_read_hex(flipper_file, "IV", iv, 16)) {
|
||||
if(!flipper_format_read_hex(flipper_format, "IV", iv, 16)) {
|
||||
FURI_LOG_E(TAG, "Missing IV");
|
||||
break;
|
||||
}
|
||||
subghz_keystore_mess_with_iv(iv);
|
||||
result = subghz_keystore_read_file(instance, file, iv);
|
||||
result = subghz_keystore_read_file(instance, stream, iv);
|
||||
} else {
|
||||
FURI_LOG_E(TAG, "Unknown encryption");
|
||||
break;
|
||||
}
|
||||
} while(0);
|
||||
flipper_file_close(flipper_file);
|
||||
flipper_file_free(flipper_file);
|
||||
flipper_format_free(flipper_format);
|
||||
|
||||
furi_record_close("storage");
|
||||
|
||||
@@ -238,26 +239,26 @@ bool subghz_keystore_save(SubGhzKeystore* instance, const char* file_name, uint8
|
||||
bool result = false;
|
||||
|
||||
Storage* storage = furi_record_open("storage");
|
||||
char* decrypted_line = furi_alloc(SUBGHZ_KEYSTORE_FILE_DECRYPTED_LINE_SIZE);
|
||||
char* encrypted_line = furi_alloc(SUBGHZ_KEYSTORE_FILE_ENCRYPTED_LINE_SIZE);
|
||||
char* decrypted_line = malloc(SUBGHZ_KEYSTORE_FILE_DECRYPTED_LINE_SIZE);
|
||||
char* encrypted_line = malloc(SUBGHZ_KEYSTORE_FILE_ENCRYPTED_LINE_SIZE);
|
||||
|
||||
FlipperFile* flipper_file = flipper_file_alloc(storage);
|
||||
FlipperFormat* flipper_format = flipper_format_file_alloc(storage);
|
||||
do {
|
||||
if(!flipper_file_open_always(flipper_file, file_name)) {
|
||||
if(!flipper_format_file_open_always(flipper_format, file_name)) {
|
||||
FURI_LOG_E(TAG, "Unable to open file for write: %s", file_name);
|
||||
break;
|
||||
}
|
||||
if(!flipper_file_write_header_cstr(
|
||||
flipper_file, SUBGHZ_KEYSTORE_FILE_TYPE, SUBGHZ_KEYSTORE_FILE_VERSION)) {
|
||||
if(!flipper_format_write_header_cstr(
|
||||
flipper_format, SUBGHZ_KEYSTORE_FILE_TYPE, SUBGHZ_KEYSTORE_FILE_VERSION)) {
|
||||
FURI_LOG_E(TAG, "Unable to add header");
|
||||
break;
|
||||
}
|
||||
uint32_t encryption = SubGhzKeystoreEncryptionAES256;
|
||||
if(!flipper_file_write_uint32(flipper_file, "Encryption", &encryption, 1)) {
|
||||
if(!flipper_format_write_uint32(flipper_format, "Encryption", &encryption, 1)) {
|
||||
FURI_LOG_E(TAG, "Unable to add Encryption");
|
||||
break;
|
||||
}
|
||||
if(!flipper_file_write_hex(flipper_file, "IV", iv, 16)) {
|
||||
if(!flipper_format_write_hex(flipper_format, "IV", iv, 16)) {
|
||||
FURI_LOG_E(TAG, "Unable to add IV");
|
||||
break;
|
||||
}
|
||||
@@ -269,7 +270,7 @@ bool subghz_keystore_save(SubGhzKeystore* instance, const char* file_name, uint8
|
||||
break;
|
||||
}
|
||||
|
||||
File* file = flipper_file_get_file(flipper_file);
|
||||
Stream* stream = flipper_format_get_raw_stream(flipper_format);
|
||||
size_t encrypted_line_count = 0;
|
||||
for
|
||||
M_EACH(key, instance->data, SubGhzKeyArray_t) {
|
||||
@@ -306,8 +307,8 @@ bool subghz_keystore_save(SubGhzKeystore* instance, const char* file_name, uint8
|
||||
encrypted_line[hex_cursor] = xx[encrypted_line[cursor] & 0xF];
|
||||
encrypted_line[hex_cursor - 1] = xx[(encrypted_line[cursor] >> 4) & 0xF];
|
||||
}
|
||||
storage_file_write(file, encrypted_line, strlen(encrypted_line));
|
||||
storage_file_write(file, "\n", 1);
|
||||
stream_write_cstring(stream, encrypted_line);
|
||||
stream_write_char(stream, '\n');
|
||||
encrypted_line_count++;
|
||||
}
|
||||
furi_hal_crypto_store_unload_key(SUBGHZ_KEYSTORE_FILE_ENCRYPTION_KEY_SLOT);
|
||||
@@ -319,8 +320,7 @@ bool subghz_keystore_save(SubGhzKeystore* instance, const char* file_name, uint8
|
||||
FURI_LOG_E(TAG, "Failure. Encrypted: %d of %d", encrypted_line_count, total_keys);
|
||||
}
|
||||
} while(0);
|
||||
flipper_file_close(flipper_file);
|
||||
flipper_file_free(flipper_file);
|
||||
flipper_format_free(flipper_format);
|
||||
|
||||
free(encrypted_line);
|
||||
free(decrypted_line);
|
||||
@@ -346,19 +346,20 @@ bool subghz_keystore_raw_encrypted_save(
|
||||
|
||||
Storage* storage = furi_record_open("storage");
|
||||
|
||||
char* encrypted_line = furi_alloc(SUBGHZ_KEYSTORE_FILE_ENCRYPTED_LINE_SIZE);
|
||||
char* encrypted_line = malloc(SUBGHZ_KEYSTORE_FILE_ENCRYPTED_LINE_SIZE);
|
||||
|
||||
FlipperFile* input_flipper_file = flipper_file_alloc(storage);
|
||||
FlipperFormat* input_flipper_format = flipper_format_file_alloc(storage);
|
||||
do {
|
||||
if(!flipper_file_open_existing(input_flipper_file, input_file_name)) {
|
||||
if(!flipper_format_file_open_existing(input_flipper_format, input_file_name)) {
|
||||
FURI_LOG_E(TAG, "Unable to open file for read: %s", input_file_name);
|
||||
break;
|
||||
}
|
||||
if(!flipper_file_read_header(input_flipper_file, filetype, &version)) {
|
||||
if(!flipper_format_read_header(input_flipper_format, filetype, &version)) {
|
||||
FURI_LOG_E(TAG, "Missing or incorrect header");
|
||||
break;
|
||||
}
|
||||
if(!flipper_file_read_uint32(input_flipper_file, "Encryption", (uint32_t*)&encryption, 1)) {
|
||||
if(!flipper_format_read_uint32(
|
||||
input_flipper_format, "Encryption", (uint32_t*)&encryption, 1)) {
|
||||
FURI_LOG_E(TAG, "Missing encryption type");
|
||||
break;
|
||||
}
|
||||
@@ -373,30 +374,30 @@ bool subghz_keystore_raw_encrypted_save(
|
||||
FURI_LOG_E(TAG, "Already encryption");
|
||||
break;
|
||||
}
|
||||
File* input_file = flipper_file_get_file(input_flipper_file);
|
||||
Stream* input_stream = flipper_format_get_raw_stream(input_flipper_format);
|
||||
|
||||
FlipperFile* output_flipper_file = flipper_file_alloc(storage);
|
||||
FlipperFormat* output_flipper_format = flipper_format_file_alloc(storage);
|
||||
|
||||
if(!flipper_file_open_always(output_flipper_file, output_file_name)) {
|
||||
if(!flipper_format_file_open_always(output_flipper_format, output_file_name)) {
|
||||
FURI_LOG_E(TAG, "Unable to open file for write: %s", output_file_name);
|
||||
break;
|
||||
}
|
||||
if(!flipper_file_write_header_cstr(
|
||||
output_flipper_file, string_get_cstr(filetype), SUBGHZ_KEYSTORE_FILE_VERSION)) {
|
||||
if(!flipper_format_write_header_cstr(
|
||||
output_flipper_format, string_get_cstr(filetype), SUBGHZ_KEYSTORE_FILE_VERSION)) {
|
||||
FURI_LOG_E(TAG, "Unable to add header");
|
||||
break;
|
||||
}
|
||||
uint32_t encryption = SubGhzKeystoreEncryptionAES256;
|
||||
if(!flipper_file_write_uint32(output_flipper_file, "Encryption", &encryption, 1)) {
|
||||
if(!flipper_format_write_uint32(output_flipper_format, "Encryption", &encryption, 1)) {
|
||||
FURI_LOG_E(TAG, "Unable to add Encryption");
|
||||
break;
|
||||
}
|
||||
if(!flipper_file_write_hex(output_flipper_file, "IV", iv, 16)) {
|
||||
if(!flipper_format_write_hex(output_flipper_format, "IV", iv, 16)) {
|
||||
FURI_LOG_E(TAG, "Unable to add IV");
|
||||
break;
|
||||
}
|
||||
|
||||
if(!flipper_file_write_string_cstr(output_flipper_file, "Encrypt_data", "RAW")) {
|
||||
if(!flipper_format_write_string_cstr(output_flipper_format, "Encrypt_data", "RAW")) {
|
||||
FURI_LOG_E(TAG, "Unable to add Encrypt_data");
|
||||
break;
|
||||
}
|
||||
@@ -408,19 +409,19 @@ bool subghz_keystore_raw_encrypted_save(
|
||||
break;
|
||||
}
|
||||
|
||||
File* output_file = flipper_file_get_file(output_flipper_file);
|
||||
char buffer[FILE_BUFFER_SIZE];
|
||||
Stream* output_stream = flipper_format_get_raw_stream(output_flipper_format);
|
||||
uint8_t buffer[FILE_BUFFER_SIZE];
|
||||
bool result = true;
|
||||
|
||||
size_t ret = 0;
|
||||
furi_assert(FILE_BUFFER_SIZE % 16 == 0);
|
||||
|
||||
//skip the end of the previous line "\n"
|
||||
storage_file_read(input_file, buffer, 1);
|
||||
stream_read(input_stream, buffer, 1);
|
||||
|
||||
do {
|
||||
memset(buffer, 0, FILE_BUFFER_SIZE);
|
||||
ret = storage_file_read(input_file, buffer, FILE_BUFFER_SIZE);
|
||||
ret = stream_read(input_stream, buffer, FILE_BUFFER_SIZE);
|
||||
if(ret == 0) {
|
||||
break;
|
||||
}
|
||||
@@ -450,12 +451,11 @@ bool subghz_keystore_raw_encrypted_save(
|
||||
encrypted_line[hex_cursor] = xx[encrypted_line[cursor] & 0xF];
|
||||
encrypted_line[hex_cursor - 1] = xx[(encrypted_line[cursor] >> 4) & 0xF];
|
||||
}
|
||||
storage_file_write(output_file, encrypted_line, strlen(encrypted_line));
|
||||
stream_write_cstring(output_stream, encrypted_line);
|
||||
|
||||
} while(ret > 0 && result);
|
||||
|
||||
flipper_file_close(output_flipper_file);
|
||||
flipper_file_free(output_flipper_file);
|
||||
flipper_format_free(output_flipper_format);
|
||||
|
||||
furi_hal_crypto_store_unload_key(SUBGHZ_KEYSTORE_FILE_ENCRYPTION_KEY_SLOT);
|
||||
|
||||
@@ -464,8 +464,7 @@ bool subghz_keystore_raw_encrypted_save(
|
||||
encrypted = true;
|
||||
} while(0);
|
||||
|
||||
flipper_file_close(input_flipper_file);
|
||||
flipper_file_free(input_flipper_file);
|
||||
flipper_format_free(input_flipper_format);
|
||||
|
||||
free(encrypted_line);
|
||||
|
||||
@@ -484,19 +483,19 @@ bool subghz_keystore_raw_get_data(const char* file_name, size_t offset, uint8_t*
|
||||
string_init(str_temp);
|
||||
|
||||
Storage* storage = furi_record_open("storage");
|
||||
char* decrypted_line = furi_alloc(SUBGHZ_KEYSTORE_FILE_DECRYPTED_LINE_SIZE);
|
||||
char* decrypted_line = malloc(SUBGHZ_KEYSTORE_FILE_DECRYPTED_LINE_SIZE);
|
||||
|
||||
FlipperFile* flipper_file = flipper_file_alloc(storage);
|
||||
FlipperFormat* flipper_format = flipper_format_file_alloc(storage);
|
||||
do {
|
||||
if(!flipper_file_open_existing(flipper_file, file_name)) {
|
||||
if(!flipper_format_file_open_existing(flipper_format, file_name)) {
|
||||
FURI_LOG_E(TAG, "Unable to open file for read: %s", file_name);
|
||||
break;
|
||||
}
|
||||
if(!flipper_file_read_header(flipper_file, str_temp, &version)) {
|
||||
if(!flipper_format_read_header(flipper_format, str_temp, &version)) {
|
||||
FURI_LOG_E(TAG, "Missing or incorrect header");
|
||||
break;
|
||||
}
|
||||
if(!flipper_file_read_uint32(flipper_file, "Encryption", (uint32_t*)&encryption, 1)) {
|
||||
if(!flipper_format_read_uint32(flipper_format, "Encryption", (uint32_t*)&encryption, 1)) {
|
||||
FURI_LOG_E(TAG, "Missing encryption type");
|
||||
break;
|
||||
}
|
||||
@@ -507,21 +506,21 @@ bool subghz_keystore_raw_get_data(const char* file_name, size_t offset, uint8_t*
|
||||
break;
|
||||
}
|
||||
|
||||
File* file = flipper_file_get_file(flipper_file);
|
||||
Stream* stream = flipper_format_get_raw_stream(flipper_format);
|
||||
if(encryption != SubGhzKeystoreEncryptionAES256) {
|
||||
FURI_LOG_E(TAG, "Unknown encryption");
|
||||
break;
|
||||
}
|
||||
|
||||
if(offset < 16) {
|
||||
if(!flipper_file_read_hex(flipper_file, "IV", iv, 16)) {
|
||||
if(!flipper_format_read_hex(flipper_format, "IV", iv, 16)) {
|
||||
FURI_LOG_E(TAG, "Missing IV");
|
||||
break;
|
||||
}
|
||||
subghz_keystore_mess_with_iv(iv);
|
||||
}
|
||||
|
||||
if(!flipper_file_read_string(flipper_file, "Encrypt_data", str_temp)) {
|
||||
if(!flipper_format_read_string(flipper_format, "Encrypt_data", str_temp)) {
|
||||
FURI_LOG_E(TAG, "Missing Encrypt_data");
|
||||
break;
|
||||
}
|
||||
@@ -534,22 +533,22 @@ bool subghz_keystore_raw_get_data(const char* file_name, size_t offset, uint8_t*
|
||||
}
|
||||
furi_assert(SUBGHZ_KEYSTORE_FILE_DECRYPTED_LINE_SIZE >= bufer_size / 2);
|
||||
|
||||
char buffer[bufer_size];
|
||||
uint8_t buffer[bufer_size];
|
||||
size_t ret = 0;
|
||||
bool decrypted = true;
|
||||
//skip the end of the previous line "\n"
|
||||
storage_file_read(file, buffer, 1);
|
||||
stream_read(stream, buffer, 1);
|
||||
|
||||
size_t size = storage_file_size(file);
|
||||
size -= storage_file_tell(file);
|
||||
size_t size = stream_size(stream);
|
||||
size -= stream_tell(stream);
|
||||
if(size < (offset * 2 + len * 2)) {
|
||||
FURI_LOG_E(TAG, "Seek position exceeds file size");
|
||||
break;
|
||||
}
|
||||
|
||||
if(offset >= 16) {
|
||||
storage_file_seek(file, ((offset / 16) - 1) * 32, false);
|
||||
ret = storage_file_read(file, buffer, 32);
|
||||
stream_seek(stream, ((offset / 16) - 1) * 32, StreamOffsetFromCurrent);
|
||||
ret = stream_read(stream, buffer, 32);
|
||||
furi_assert(ret == 32);
|
||||
for(uint16_t i = 0; i < ret - 1; i += 2) {
|
||||
uint8_t hi_nibble = 0;
|
||||
@@ -567,7 +566,7 @@ bool subghz_keystore_raw_get_data(const char* file_name, size_t offset, uint8_t*
|
||||
|
||||
do {
|
||||
memset(buffer, 0, bufer_size);
|
||||
ret = storage_file_read(file, buffer, bufer_size);
|
||||
ret = stream_read(stream, buffer, bufer_size);
|
||||
furi_assert(ret == bufer_size);
|
||||
for(uint16_t i = 0; i < ret - 1; i += 2) {
|
||||
uint8_t hi_nibble = 0;
|
||||
@@ -591,8 +590,7 @@ bool subghz_keystore_raw_get_data(const char* file_name, size_t offset, uint8_t*
|
||||
furi_hal_crypto_store_unload_key(SUBGHZ_KEYSTORE_FILE_ENCRYPTION_KEY_SLOT);
|
||||
if(decrypted) result = true;
|
||||
} while(0);
|
||||
flipper_file_close(flipper_file);
|
||||
flipper_file_free(flipper_file);
|
||||
flipper_format_free(flipper_format);
|
||||
|
||||
furi_record_close("storage");
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ static void subghz_parser_parser_rx_callback(SubGhzProtocolCommon* parser, void*
|
||||
}
|
||||
|
||||
SubGhzParser* subghz_parser_alloc() {
|
||||
SubGhzParser* instance = furi_alloc(sizeof(SubGhzParser));
|
||||
SubGhzParser* instance = malloc(sizeof(SubGhzParser));
|
||||
|
||||
instance->keystore = subghz_keystore_alloc();
|
||||
|
||||
|
||||
@@ -197,7 +197,7 @@ static int32_t subghz_tx_rx_worker_thread(void* context) {
|
||||
}
|
||||
|
||||
SubGhzTxRxWorker* subghz_tx_rx_worker_alloc() {
|
||||
SubGhzTxRxWorker* instance = furi_alloc(sizeof(SubGhzTxRxWorker));
|
||||
SubGhzTxRxWorker* instance = malloc(sizeof(SubGhzTxRxWorker));
|
||||
|
||||
instance->thread = furi_thread_alloc();
|
||||
furi_thread_set_name(instance->thread, "SubghzTxRxWorker");
|
||||
|
||||
@@ -90,7 +90,7 @@ static int32_t subghz_worker_thread_callback(void* context) {
|
||||
}
|
||||
|
||||
SubGhzWorker* subghz_worker_alloc() {
|
||||
SubGhzWorker* instance = furi_alloc(sizeof(SubGhzWorker));
|
||||
SubGhzWorker* instance = malloc(sizeof(SubGhzWorker));
|
||||
|
||||
instance->thread = furi_thread_alloc();
|
||||
furi_thread_set_name(instance->thread, "SubghzWorker");
|
||||
|
||||
Reference in New Issue
Block a user