From 745d91c53adf33aeaf60b39475e7c97ec061517d Mon Sep 17 00:00:00 2001 From: r3df0xx Date: Sun, 10 Apr 2022 22:47:37 +0300 Subject: [PATCH] input seed from device --- .../subghz/helpers/subghz_custom_event.h | 2 + .../scenes/subghz_scene_receiver_info.c | 37 ++++++++++++++++++ applications/subghz/subghz_i.h | 3 ++ lib/subghz/blocks/generic.h | 1 + lib/subghz/protocols/faac_slh.c | 39 ++----------------- lib/subghz/protocols/faac_slh.h | 23 ----------- 6 files changed, 46 insertions(+), 59 deletions(-) diff --git a/applications/subghz/helpers/subghz_custom_event.h b/applications/subghz/helpers/subghz_custom_event.h index 97920015a..1aa9a8289 100644 --- a/applications/subghz/helpers/subghz_custom_event.h +++ b/applications/subghz/helpers/subghz_custom_event.h @@ -13,6 +13,8 @@ typedef enum { SubGhzCustomEventSceneReceiverInfoTxStart, SubGhzCustomEventSceneReceiverInfoTxStop, SubGhzCustomEventSceneReceiverInfoSave, + SubGhzCustomEventSceneReceiverInfoNeedSeed, + SubGhzCustomEventSceneReceiverInfoDoneSeed, SubGhzCustomEventSceneSaveName, SubGhzCustomEventSceneSaveSuccess, SubGhzCustomEventSceneShowErrorBack, diff --git a/applications/subghz/scenes/subghz_scene_receiver_info.c b/applications/subghz/scenes/subghz_scene_receiver_info.c index b6ad12f42..8ebda6418 100644 --- a/applications/subghz/scenes/subghz_scene_receiver_info.c +++ b/applications/subghz/scenes/subghz_scene_receiver_info.c @@ -1,6 +1,7 @@ #include "../subghz_i.h" #include "../helpers/subghz_custom_event.h" #include +#include "applications/gui/modules/byte_input.h" void subghz_scene_receiver_info_callback(GuiButtonType result, InputType type, void* context) { furi_assert(context); @@ -15,6 +16,9 @@ void subghz_scene_receiver_info_callback(GuiButtonType result, InputType type, v } else if((result == GuiButtonTypeRight) && (type == InputTypeShort)) { view_dispatcher_send_custom_event( subghz->view_dispatcher, SubGhzCustomEventSceneReceiverInfoSave); + } else if((result == GuiButtonTypeLeft) && (type == InputTypeShort)) { + view_dispatcher_send_custom_event( + subghz->view_dispatcher, SubGhzCustomEventSceneReceiverInfoNeedSeed); } } @@ -94,6 +98,14 @@ void subghz_scene_receiver_info_on_enter(void* context) { subghz_scene_receiver_info_callback, subghz); } + if(strcmp(subghz->txrx->decoder_result->protocol->name, "Faac SLH") == 0) { + widget_add_button_element( + subghz->widget, + GuiButtonTypeLeft, + "Seed", + subghz_scene_receiver_info_callback, + subghz); + } } else { widget_add_icon_element(subghz->widget, 32, 12, &I_DolphinFirstStart7_61x51); widget_add_string_element( @@ -103,6 +115,11 @@ void subghz_scene_receiver_info_on_enter(void* context) { view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdWidget); } +void byte_input_callback(void* context) { + SubGhz* subghz = (SubGhz*)context; + view_dispatcher_send_custom_event(subghz->view_dispatcher, SubGhzCustomEventSceneReceiverInfoDoneSeed); +} + bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event) { SubGhz* subghz = context; if(event.type == SceneManagerEventTypeCustom) { @@ -165,6 +182,22 @@ bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event) } return true; } + else if(event.event == SubGhzCustomEventSceneReceiverInfoNeedSeed) { + //Need to input seed + SubGhz* subghz = (SubGhz*)context; + + // Setup view + ByteInput* byte_input = subghz->byte_input; + byte_input_set_header_text(byte_input, "Enter seed"); + byte_input_set_result_callback( + byte_input, + byte_input_callback, + NULL, + subghz, + NULL, + NULL); + view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdByteInput); + } } else if(event.type == SceneManagerEventTypeTick) { if(subghz->txrx->hopper_state != SubGhzHopperStateOFF) { subghz_hopper_update(subghz); @@ -186,4 +219,8 @@ bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event) void subghz_scene_receiver_info_on_exit(void* context) { SubGhz* subghz = context; widget_reset(subghz->widget); + + // 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/subghz_i.h b/applications/subghz/subghz_i.h index b2d7df71a..5d2596b13 100644 --- a/applications/subghz/subghz_i.h +++ b/applications/subghz/subghz_i.h @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -121,6 +122,7 @@ struct SubGhz { Submenu* submenu; Popup* popup; TextInput* text_input; + ByteInput* byte_input; Widget* widget; DialogsApp* dialogs; char file_name[SUBGHZ_MAX_LEN_NAME + 1]; @@ -144,6 +146,7 @@ typedef enum { SubGhzViewIdReceiver, SubGhzViewIdPopup, SubGhzViewIdTextInput, + SubGhzViewIdByteInput, SubGhzViewIdWidget, SubGhzViewIdTransmitter, SubGhzViewIdVariableItemList, diff --git a/lib/subghz/blocks/generic.h b/lib/subghz/blocks/generic.h index 0d8fe0a2d..aec78214c 100644 --- a/lib/subghz/blocks/generic.h +++ b/lib/subghz/blocks/generic.h @@ -17,6 +17,7 @@ struct SubGhzBlockGeneric { uint8_t data_count_bit; uint8_t btn; uint16_t cnt; + uint32_t seed; }; /** diff --git a/lib/subghz/protocols/faac_slh.c b/lib/subghz/protocols/faac_slh.c index 40dd6ed60..046a9f90f 100644 --- a/lib/subghz/protocols/faac_slh.c +++ b/lib/subghz/protocols/faac_slh.c @@ -120,7 +120,7 @@ static bool subghz_protocol_faac_slh_gen_data(SubGhzProtocolEncoderFaacSLH* inst uint32_t hop = 0; uint32_t decrypt = 0; uint64_t man = 0; - instance->seed = 0x77ED7698; + //instance->seed = 0x77ED7698; int res = 0; char fixx[8] = {}; int shiftby = 32; @@ -163,32 +163,6 @@ static bool subghz_protocol_faac_slh_gen_data(SubGhzProtocolEncoderFaacSLH* inst return true; } -bool subghz_protocol_faac_slh_create_data( - void* context, - FlipperFormat* flipper_format, - uint32_t serial, - uint8_t btn, - uint16_t cnt, - uint32_t seed, - const char* manufacture_name, - uint32_t frequency, - FuriHalSubGhzPreset preset) { - furi_assert(context); - SubGhzProtocolEncoderFaacSLH* instance = context; - instance->generic.serial = serial; - instance->generic.cnt = cnt; - instance->generic.btn = btn; - instance->seed = seed; - instance->manufacture_name = manufacture_name; - instance->generic.data_count_bit = 64; - bool res = subghz_protocol_faac_slh_gen_data(instance); - if(res) { - res = - subghz_block_generic_serialize(&instance->generic, flipper_format, frequency, preset); - } - return res; -} - /** * Generating an upload from data. * @param instance Pointer to a SubGhzProtocolEncoderFaacSLH instance @@ -198,13 +172,7 @@ static bool subghz_protocol_encoder_faac_slh_get_upload(SubGhzProtocolEncoderFaacSLH* instance) { furi_assert(instance); - //gen new key - if(subghz_protocol_faac_slh_gen_data(instance)) { - //ToDo if you need to add a callback to automatically update the data on the display - } else { - return false; - } - + subghz_protocol_faac_slh_gen_data(instance); size_t index = 0; size_t size_upload = 2 + (instance->generic.data_count_bit * 2); if(size_upload > instance->encoder.size_upload) { @@ -416,7 +384,6 @@ static void subghz_protocol_faac_slh_check_remote_controller instance->btn = code_fix & 0xF; uint32_t decrypt = 0; uint64_t man; - uint32_t seed = 0x77ED7698; for M_EACH(manufacture_code, *subghz_keystore_get_data(keystore), SubGhzKeyArray_t) { @@ -425,7 +392,7 @@ static void subghz_protocol_faac_slh_check_remote_controller switch(manufacture_code->type) { case KEELOQ_LEARNING_FAAC: // FAAC Learning - man = subghz_protocol_keeloq_common_faac_learning(seed, manufacture_code->key); + man = subghz_protocol_keeloq_common_faac_learning(instance->seed, manufacture_code->key); FURI_LOG_I(TAG, "mfkey: %08lX%08lX mf: %s\n", hi, lo, manufacture_code->name); uint32_t mlhi = man >> 32; uint32_t mllo = man & 0xFFFFFFFF; diff --git a/lib/subghz/protocols/faac_slh.h b/lib/subghz/protocols/faac_slh.h index 32e913f95..ae84d3244 100644 --- a/lib/subghz/protocols/faac_slh.h +++ b/lib/subghz/protocols/faac_slh.h @@ -24,29 +24,6 @@ void* subghz_protocol_encoder_faac_slh_alloc(SubGhzEnvironment* environment); */ void subghz_protocol_encoder_faac_slh_free(void* context); -/** - * Key generation from simple data. - * @param context Pointer to a SubGhzProtocolEncoderFaacSLH instance - * @param flipper_format Pointer to a FlipperFormat instance - * @param serial Serial number, 28 bit - * @param btn Button number, 4 bit - * @param cnt Counter value, 16 bit - * @param manufacture_name Name of manufacturer's key - * @param frequency Transmission frequency, Hz - * @param preset Modulation, FuriHalSubGhzPreset - * @return true On success - */ -bool subghz_protocol_faac_slh_create_data( - void* context, - FlipperFormat* flipper_format, - uint32_t serial, - uint8_t btn, - uint16_t cnt, - uint32_t seed, - const char* manufacture_name, - uint32_t frequency, - FuriHalSubGhzPreset preset); - /** * Deserialize and generating an upload to send. * @param context Pointer to a SubGhzProtocolEncoderFaacSLH instance