input seed from device

This commit is contained in:
r3df0xx 2022-04-10 22:47:37 +03:00
parent 09e3055cc6
commit 745d91c53a
6 changed files with 46 additions and 59 deletions

View file

@ -13,6 +13,8 @@ typedef enum {
SubGhzCustomEventSceneReceiverInfoTxStart,
SubGhzCustomEventSceneReceiverInfoTxStop,
SubGhzCustomEventSceneReceiverInfoSave,
SubGhzCustomEventSceneReceiverInfoNeedSeed,
SubGhzCustomEventSceneReceiverInfoDoneSeed,
SubGhzCustomEventSceneSaveName,
SubGhzCustomEventSceneSaveSuccess,
SubGhzCustomEventSceneShowErrorBack,

View file

@ -1,6 +1,7 @@
#include "../subghz_i.h"
#include "../helpers/subghz_custom_event.h"
#include <dolphin/dolphin.h>
#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, "");
}

View file

@ -20,6 +20,7 @@
#include <gui/modules/submenu.h>
#include <gui/modules/popup.h>
#include <gui/modules/text_input.h>
#include <gui/modules/byte_input.h>
#include <gui/modules/widget.h>
#include <subghz/scenes/subghz_scene.h>
@ -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,

View file

@ -17,6 +17,7 @@ struct SubGhzBlockGeneric {
uint8_t data_count_bit;
uint8_t btn;
uint16_t cnt;
uint32_t seed;
};
/**

View file

@ -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;

View file

@ -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