From c6099dfcc9016ea50ee674ca5e21f916b1b5f20b Mon Sep 17 00:00:00 2001 From: Eng1n33r <101719414+Eng1n33r@users.noreply.github.com> Date: Thu, 21 Jul 2022 00:35:43 +0300 Subject: [PATCH] Add FAAC SLH 433 MHz create support --- .../subghz/helpers/subghz_custom_event.h | 3 +- .../subghz/scenes/subghz_scene_config.h | 9 +- ..._cnt.c => subghz_scene_set_cnt_faac_433.c} | 14 +-- .../scenes/subghz_scene_set_cnt_faac_868.c | 46 ++++++++ ..._fix.c => subghz_scene_set_fix_faac_433.c} | 14 +-- .../scenes/subghz_scene_set_fix_faac_868.c | 46 ++++++++ .../scenes/subghz_scene_set_seed_faac_433.c | 103 ++++++++++++++++++ ...eed.c => subghz_scene_set_seed_faac_868.c} | 12 +- .../subghz/scenes/subghz_scene_set_type.c | 15 ++- 9 files changed, 235 insertions(+), 27 deletions(-) rename applications/subghz/scenes/{subghz_scene_set_cnt.c => subghz_scene_set_cnt_faac_433.c} (72%) create mode 100644 applications/subghz/scenes/subghz_scene_set_cnt_faac_868.c rename applications/subghz/scenes/{subghz_scene_set_fix.c => subghz_scene_set_fix_faac_433.c} (72%) create mode 100644 applications/subghz/scenes/subghz_scene_set_fix_faac_868.c create mode 100644 applications/subghz/scenes/subghz_scene_set_seed_faac_433.c rename applications/subghz/scenes/{subghz_scene_set_seed.c => subghz_scene_set_seed_faac_868.c} (90%) diff --git a/applications/subghz/helpers/subghz_custom_event.h b/applications/subghz/helpers/subghz_custom_event.h index 11416f184..a4566cba3 100644 --- a/applications/subghz/helpers/subghz_custom_event.h +++ b/applications/subghz/helpers/subghz_custom_event.h @@ -6,7 +6,8 @@ typedef enum { SubGhzCustomEventManagerSetRAW, //SubmenuIndex - SubmenuIndexFaacSLH, + SubmenuIndexFaacSLH_433, + SubmenuIndexFaacSLH_868, SubmenuIndexBFT, SubmenuIndexPricenton, SubmenuIndexNiceFlo12bit, diff --git a/applications/subghz/scenes/subghz_scene_config.h b/applications/subghz/scenes/subghz_scene_config.h index ee4408971..47cfe8212 100644 --- a/applications/subghz/scenes/subghz_scene_config.h +++ b/applications/subghz/scenes/subghz_scene_config.h @@ -17,9 +17,12 @@ ADD_SCENE(subghz, test_static, TestStatic) ADD_SCENE(subghz, test_carrier, TestCarrier) ADD_SCENE(subghz, test_packet, TestPacket) ADD_SCENE(subghz, set_type, SetType) -ADD_SCENE(subghz, set_fix, SetFix) -ADD_SCENE(subghz, set_cnt, SetCnt) -ADD_SCENE(subghz, set_seed, SetSeed) +ADD_SCENE(subghz, set_fix_faac_868, SetFixFaac868) +ADD_SCENE(subghz, set_cnt_faac_868, SetCntFaac868) +ADD_SCENE(subghz, set_seed_faac_868, SetSeedFaac868) +ADD_SCENE(subghz, set_fix_faac_433, SetFixFaac433) +ADD_SCENE(subghz, set_cnt_faac_433, SetCntFaac433) +ADD_SCENE(subghz, set_seed_faac_433, SetSeedFaac433) ADD_SCENE(subghz, set_fix_bft, SetFixBft) ADD_SCENE(subghz, set_cnt_bft, SetCntBft) ADD_SCENE(subghz, set_seed_bft, SetSeedBft) diff --git a/applications/subghz/scenes/subghz_scene_set_cnt.c b/applications/subghz/scenes/subghz_scene_set_cnt_faac_433.c similarity index 72% rename from applications/subghz/scenes/subghz_scene_set_cnt.c rename to applications/subghz/scenes/subghz_scene_set_cnt_faac_433.c index 718e055db..4bb551db8 100644 --- a/applications/subghz/scenes/subghz_scene_set_cnt.c +++ b/applications/subghz/scenes/subghz_scene_set_cnt_faac_433.c @@ -1,14 +1,14 @@ #include "../subghz_i.h" -#define TAG "SubGhzSetCnt" +#define TAG "SubGhzSetCntFaac433" -void subghz_scene_set_cnt_byte_input_callback(void* context) { +void subghz_scene_set_cnt_faac_433_byte_input_callback(void* context) { SubGhz* subghz = context; view_dispatcher_send_custom_event(subghz->view_dispatcher, SubGhzCustomEventByteInputDone); } -void subghz_scene_set_cnt_on_enter(void* context) { +void subghz_scene_set_cnt_faac_433_on_enter(void* context) { SubGhz* subghz = context; // Setup view @@ -16,7 +16,7 @@ void subghz_scene_set_cnt_on_enter(void* context) { byte_input_set_header_text(byte_input, "Enter COUNTER in hex, 20bits"); byte_input_set_result_callback( byte_input, - subghz_scene_set_cnt_byte_input_callback, + subghz_scene_set_cnt_faac_433_byte_input_callback, NULL, subghz, subghz->txrx->secure_data->cnt, @@ -24,20 +24,20 @@ void subghz_scene_set_cnt_on_enter(void* context) { view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdByteInput); } -bool subghz_scene_set_cnt_on_event(void* context, SceneManagerEvent event) { +bool subghz_scene_set_cnt_faac_433_on_event(void* context, SceneManagerEvent event) { SubGhz* subghz = context; bool consumed = false; if(event.type == SceneManagerEventTypeCustom) { if(event.event == SubGhzCustomEventByteInputDone) { - scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSetSeed); + scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSetSeedFaac433); consumed = true; } } return consumed; } -void subghz_scene_set_cnt_on_exit(void* context) { +void subghz_scene_set_cnt_faac_433_on_exit(void* context) { SubGhz* subghz = context; // Clear view diff --git a/applications/subghz/scenes/subghz_scene_set_cnt_faac_868.c b/applications/subghz/scenes/subghz_scene_set_cnt_faac_868.c new file mode 100644 index 000000000..f4908f865 --- /dev/null +++ b/applications/subghz/scenes/subghz_scene_set_cnt_faac_868.c @@ -0,0 +1,46 @@ +#include "../subghz_i.h" + +#define TAG "SubGhzSetCntFaac868" + +void subghz_scene_set_cnt_faac_868_byte_input_callback(void* context) { + SubGhz* subghz = context; + + view_dispatcher_send_custom_event(subghz->view_dispatcher, SubGhzCustomEventByteInputDone); +} + +void subghz_scene_set_cnt_faac_868_on_enter(void* context) { + SubGhz* subghz = context; + + // Setup view + ByteInput* byte_input = subghz->byte_input; + byte_input_set_header_text(byte_input, "Enter COUNTER in hex, 20bits"); + byte_input_set_result_callback( + byte_input, + subghz_scene_set_cnt_faac_868_byte_input_callback, + NULL, + subghz, + subghz->txrx->secure_data->cnt, + 3); + view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdByteInput); +} + +bool subghz_scene_set_cnt_faac_868_on_event(void* context, SceneManagerEvent event) { + SubGhz* subghz = context; + bool consumed = false; + + if(event.type == SceneManagerEventTypeCustom) { + if(event.event == SubGhzCustomEventByteInputDone) { + scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSetSeedFaac868); + consumed = true; + } + } + return consumed; +} + +void subghz_scene_set_cnt_faac_868_on_exit(void* context) { + SubGhz* subghz = context; + + // Clear view + byte_input_set_result_callback(subghz->byte_input, NULL, NULL, NULL, NULL, 0); + byte_input_set_header_text(subghz->byte_input, ""); +} diff --git a/applications/subghz/scenes/subghz_scene_set_fix.c b/applications/subghz/scenes/subghz_scene_set_fix_faac_433.c similarity index 72% rename from applications/subghz/scenes/subghz_scene_set_fix.c rename to applications/subghz/scenes/subghz_scene_set_fix_faac_433.c index b17a1852a..62af59e2c 100644 --- a/applications/subghz/scenes/subghz_scene_set_fix.c +++ b/applications/subghz/scenes/subghz_scene_set_fix_faac_433.c @@ -1,14 +1,14 @@ #include "../subghz_i.h" -#define TAG "SubGhzSetFix" +#define TAG "SubGhzSetFixFaac433" -void subghz_scene_set_fix_byte_input_callback(void* context) { +void subghz_scene_set_fix_faac_433_byte_input_callback(void* context) { SubGhz* subghz = context; view_dispatcher_send_custom_event(subghz->view_dispatcher, SubGhzCustomEventByteInputDone); } -void subghz_scene_set_fix_on_enter(void* context) { +void subghz_scene_set_fix_faac_433_on_enter(void* context) { SubGhz* subghz = context; // Setup view @@ -16,7 +16,7 @@ void subghz_scene_set_fix_on_enter(void* context) { byte_input_set_header_text(byte_input, "Enter FIX in hex"); byte_input_set_result_callback( byte_input, - subghz_scene_set_fix_byte_input_callback, + subghz_scene_set_fix_faac_433_byte_input_callback, NULL, subghz, subghz->txrx->secure_data->fix, @@ -24,20 +24,20 @@ void subghz_scene_set_fix_on_enter(void* context) { view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdByteInput); } -bool subghz_scene_set_fix_on_event(void* context, SceneManagerEvent event) { +bool subghz_scene_set_fix_faac_433_on_event(void* context, SceneManagerEvent event) { SubGhz* subghz = context; bool consumed = false; if(event.type == SceneManagerEventTypeCustom) { if(event.event == SubGhzCustomEventByteInputDone) { - scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSetCnt); + scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSetCntFaac433); consumed = true; } } return consumed; } -void subghz_scene_set_fix_on_exit(void* context) { +void subghz_scene_set_fix_faac_433_on_exit(void* context) { SubGhz* subghz = context; // Clear view diff --git a/applications/subghz/scenes/subghz_scene_set_fix_faac_868.c b/applications/subghz/scenes/subghz_scene_set_fix_faac_868.c new file mode 100644 index 000000000..ea9759a4a --- /dev/null +++ b/applications/subghz/scenes/subghz_scene_set_fix_faac_868.c @@ -0,0 +1,46 @@ +#include "../subghz_i.h" + +#define TAG "SubGhzSetFixFaac868" + +void subghz_scene_set_fix_faac_868_byte_input_callback(void* context) { + SubGhz* subghz = context; + + view_dispatcher_send_custom_event(subghz->view_dispatcher, SubGhzCustomEventByteInputDone); +} + +void subghz_scene_set_fix_faac_868_on_enter(void* context) { + SubGhz* subghz = context; + + // Setup view + ByteInput* byte_input = subghz->byte_input; + byte_input_set_header_text(byte_input, "Enter FIX in hex"); + byte_input_set_result_callback( + byte_input, + subghz_scene_set_fix_faac_868_byte_input_callback, + NULL, + subghz, + subghz->txrx->secure_data->fix, + 4); + view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdByteInput); +} + +bool subghz_scene_set_fix_faac_868_on_event(void* context, SceneManagerEvent event) { + SubGhz* subghz = context; + bool consumed = false; + + if(event.type == SceneManagerEventTypeCustom) { + if(event.event == SubGhzCustomEventByteInputDone) { + scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSetCntFaac868); + consumed = true; + } + } + return consumed; +} + +void subghz_scene_set_fix_faac_868_on_exit(void* context) { + SubGhz* subghz = context; + + // Clear view + byte_input_set_result_callback(subghz->byte_input, NULL, NULL, NULL, NULL, 0); + byte_input_set_header_text(subghz->byte_input, ""); +} diff --git a/applications/subghz/scenes/subghz_scene_set_seed_faac_433.c b/applications/subghz/scenes/subghz_scene_set_seed_faac_433.c new file mode 100644 index 000000000..37ceea300 --- /dev/null +++ b/applications/subghz/scenes/subghz_scene_set_seed_faac_433.c @@ -0,0 +1,103 @@ +#include "../subghz_i.h" +#include +#include + +#define TAG "SubGhzSetSeedFaac433" + +void subghz_scene_set_seed_faac_433_byte_input_callback(void* context) { + SubGhz* subghz = context; + + view_dispatcher_send_custom_event(subghz->view_dispatcher, SubGhzCustomEventByteInputDone); +} + +void subghz_scene_set_seed_faac_433_on_enter(void* context) { + SubGhz* subghz = context; + + // Setup view + ByteInput* byte_input = subghz->byte_input; + byte_input_set_header_text(byte_input, "Enter SEED in hex"); + byte_input_set_result_callback( + byte_input, + subghz_scene_set_seed_faac_433_byte_input_callback, + NULL, + subghz, + subghz->txrx->secure_data->seed, + 4); + view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdByteInput); +} + +bool subghz_scene_set_seed_faac_433_on_event(void* context, SceneManagerEvent event) { + SubGhz* subghz = context; + bool consumed = false; + bool generated_protocol = false; + if(event.type == SceneManagerEventTypeCustom) { + if(event.event == SubGhzCustomEventByteInputDone) { + uint32_t fix_part = + subghz->txrx->secure_data->fix[0] << 24 | subghz->txrx->secure_data->fix[1] << 16 | + subghz->txrx->secure_data->fix[2] << 8 | subghz->txrx->secure_data->fix[3]; + + uint32_t cnt = subghz->txrx->secure_data->cnt[0] << 16 | + subghz->txrx->secure_data->cnt[1] << 8 | + subghz->txrx->secure_data->cnt[2]; + + uint32_t seed = subghz->txrx->secure_data->seed[0] << 24 | + subghz->txrx->secure_data->seed[1] << 16 | + subghz->txrx->secure_data->seed[2] << 8 | + subghz->txrx->secure_data->seed[3]; + + subghz->txrx->transmitter = + subghz_transmitter_alloc_init(subghz->txrx->environment, "Faac SLH"); + if(subghz->txrx->transmitter) { + subghz_protocol_faac_slh_create_data( + subghz_transmitter_get_protocol_instance(subghz->txrx->transmitter), + subghz->txrx->fff_data, + fix_part >> 4, + fix_part & 0xf, + (cnt & 0xFFFFF), + seed, + "FAAC_SLH", + 433920000, + FuriHalSubGhzPresetOok650Async); + + uint8_t seed_data[sizeof(uint32_t)] = {0}; + for(size_t i = 0; i < sizeof(uint32_t); i++) { + seed_data[sizeof(uint32_t) - i - 1] = (seed >> i * 8) & 0xFF; + } + + flipper_format_write_hex( + subghz->txrx->fff_data, "Seed", seed_data, sizeof(uint32_t)); + + generated_protocol = true; + } else { + generated_protocol = false; + } + + subghz_transmitter_free(subghz->txrx->transmitter); + + if(!generated_protocol) { + string_set_str( + subghz->error_str, "Function requires\nan SD card with\nfresh databases."); + scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowError); + } + consumed = true; + } + + if(generated_protocol) { + subghz_file_name_clear(subghz); + DOLPHIN_DEED(DolphinDeedSubGhzAddManually); + scene_manager_set_scene_state( + subghz->scene_manager, SubGhzSceneSetType, SubGhzCustomEventManagerSet); + scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSaveName); + return true; + } + } + return consumed; +} + +void subghz_scene_set_seed_faac_433_on_exit(void* context) { + SubGhz* subghz = context; + + // Clear view + byte_input_set_result_callback(subghz->byte_input, NULL, NULL, NULL, NULL, 0); + byte_input_set_header_text(subghz->byte_input, ""); +} diff --git a/applications/subghz/scenes/subghz_scene_set_seed.c b/applications/subghz/scenes/subghz_scene_set_seed_faac_868.c similarity index 90% rename from applications/subghz/scenes/subghz_scene_set_seed.c rename to applications/subghz/scenes/subghz_scene_set_seed_faac_868.c index 8e582f442..abdd7bf38 100644 --- a/applications/subghz/scenes/subghz_scene_set_seed.c +++ b/applications/subghz/scenes/subghz_scene_set_seed_faac_868.c @@ -2,15 +2,15 @@ #include #include -#define TAG "SubGhzSetSeed" +#define TAG "SubGhzSetSeedFaac868" -void subghz_scene_set_seed_byte_input_callback(void* context) { +void subghz_scene_set_seed_faac_868_byte_input_callback(void* context) { SubGhz* subghz = context; view_dispatcher_send_custom_event(subghz->view_dispatcher, SubGhzCustomEventByteInputDone); } -void subghz_scene_set_seed_on_enter(void* context) { +void subghz_scene_set_seed_faac_868_on_enter(void* context) { SubGhz* subghz = context; // Setup view @@ -18,7 +18,7 @@ void subghz_scene_set_seed_on_enter(void* context) { byte_input_set_header_text(byte_input, "Enter SEED in hex"); byte_input_set_result_callback( byte_input, - subghz_scene_set_seed_byte_input_callback, + subghz_scene_set_seed_faac_868_byte_input_callback, NULL, subghz, subghz->txrx->secure_data->seed, @@ -26,7 +26,7 @@ void subghz_scene_set_seed_on_enter(void* context) { view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdByteInput); } -bool subghz_scene_set_seed_on_event(void* context, SceneManagerEvent event) { +bool subghz_scene_set_seed_faac_868_on_event(void* context, SceneManagerEvent event) { SubGhz* subghz = context; bool consumed = false; bool generated_protocol = false; @@ -94,7 +94,7 @@ bool subghz_scene_set_seed_on_event(void* context, SceneManagerEvent event) { return consumed; } -void subghz_scene_set_seed_on_exit(void* context) { +void subghz_scene_set_seed_faac_868_on_exit(void* context) { SubGhz* subghz = context; // Clear view diff --git a/applications/subghz/scenes/subghz_scene_set_type.c b/applications/subghz/scenes/subghz_scene_set_type.c index 5695849ec..613067be6 100644 --- a/applications/subghz/scenes/subghz_scene_set_type.c +++ b/applications/subghz/scenes/subghz_scene_set_type.c @@ -69,7 +69,13 @@ void subghz_scene_set_type_on_enter(void* context) { submenu_add_item( subghz->submenu, "Faac SLH_868", - SubmenuIndexFaacSLH, + SubmenuIndexFaacSLH_868, + subghz_scene_set_type_submenu_callback, + subghz); + submenu_add_item( + subghz->submenu, + "Faac SLH_433", + SubmenuIndexFaacSLH_433, subghz_scene_set_type_submenu_callback, subghz); submenu_add_item( @@ -187,8 +193,11 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { //ToDo Fix uint32_t key = subghz_random_serial(); switch(event.event) { - case SubmenuIndexFaacSLH: - scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSetFix); + case SubmenuIndexFaacSLH_868: + scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSetFixFaac868); + break; + case SubmenuIndexFaacSLH_433: + scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSetFixFaac433); break; case SubmenuIndexBFT: scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSetFixBft);