2023-04-21 13:10:08 +00:00
|
|
|
#include "../subghz_i.h"
|
2023-05-10 18:48:48 +00:00
|
|
|
#include "../helpers/subghz_txrx_create_protocol_key.h"
|
2023-04-21 13:10:08 +00:00
|
|
|
|
|
|
|
#define TAG "SubGhzSetSeed"
|
|
|
|
|
|
|
|
void subghz_scene_set_seed_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) {
|
|
|
|
SubGhz* subghz = context;
|
|
|
|
|
|
|
|
// Setup view
|
|
|
|
ByteInput* byte_input = subghz->byte_input;
|
2023-09-05 02:31:03 +00:00
|
|
|
byte_input_set_header_text(byte_input, "Enter SEED in Hex");
|
2023-04-21 13:10:08 +00:00
|
|
|
byte_input_set_result_callback(
|
|
|
|
byte_input,
|
|
|
|
subghz_scene_set_seed_byte_input_callback,
|
|
|
|
NULL,
|
|
|
|
subghz,
|
2023-05-09 09:07:36 +00:00
|
|
|
subghz->secure_data->seed,
|
2023-04-21 13:10:08 +00:00
|
|
|
4);
|
|
|
|
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdByteInput);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool subghz_scene_set_seed_on_event(void* context, SceneManagerEvent event) {
|
|
|
|
SubGhz* subghz = context;
|
|
|
|
bool consumed = false;
|
|
|
|
bool generated_protocol = false;
|
|
|
|
uint32_t fix_part, cnt, seed;
|
|
|
|
if(event.type == SceneManagerEventTypeCustom) {
|
|
|
|
if(event.event == SubGhzCustomEventByteInputDone) {
|
|
|
|
SubGhzCustomEvent state =
|
|
|
|
scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneSetType);
|
|
|
|
|
|
|
|
switch(state) {
|
|
|
|
case SubmenuIndexBFTClone:
|
2023-05-09 09:07:36 +00:00
|
|
|
fix_part = subghz->secure_data->fix[0] << 24 | subghz->secure_data->fix[1] << 16 |
|
|
|
|
subghz->secure_data->fix[2] << 8 | subghz->secure_data->fix[3];
|
2023-04-21 13:10:08 +00:00
|
|
|
|
2023-05-09 09:07:36 +00:00
|
|
|
cnt = subghz->secure_data->cnt[0] << 8 | subghz->secure_data->cnt[1];
|
2023-04-21 13:10:08 +00:00
|
|
|
|
2023-05-09 09:07:36 +00:00
|
|
|
seed = subghz->secure_data->seed[0] << 24 | subghz->secure_data->seed[1] << 16 |
|
|
|
|
subghz->secure_data->seed[2] << 8 | subghz->secure_data->seed[3];
|
2023-04-21 13:10:08 +00:00
|
|
|
|
2023-05-10 20:12:50 +00:00
|
|
|
generated_protocol = subghz_txrx_gen_keeloq_bft_protocol(
|
2023-05-09 09:07:36 +00:00
|
|
|
subghz->txrx,
|
2023-05-08 18:55:51 +00:00
|
|
|
"AM650",
|
|
|
|
433920000,
|
|
|
|
fix_part & 0x0FFFFFFF,
|
|
|
|
fix_part >> 28,
|
|
|
|
cnt,
|
|
|
|
seed,
|
|
|
|
"BFT");
|
2023-04-21 13:10:08 +00:00
|
|
|
|
|
|
|
if(!generated_protocol) {
|
|
|
|
furi_string_set(
|
|
|
|
subghz->error_str, "Function requires\nan SD card with\nfresh databases.");
|
|
|
|
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowError);
|
|
|
|
}
|
|
|
|
consumed = true;
|
|
|
|
break;
|
2023-09-05 02:31:03 +00:00
|
|
|
case SubmenuIndexFaacSLH_Manual_433:
|
|
|
|
case SubmenuIndexFaacSLH_Manual_868:
|
2023-05-09 09:07:36 +00:00
|
|
|
fix_part = subghz->secure_data->fix[0] << 24 | subghz->secure_data->fix[1] << 16 |
|
|
|
|
subghz->secure_data->fix[2] << 8 | subghz->secure_data->fix[3];
|
2023-04-21 13:10:08 +00:00
|
|
|
|
2023-05-09 09:07:36 +00:00
|
|
|
cnt = subghz->secure_data->cnt[0] << 16 | subghz->secure_data->cnt[1] << 8 |
|
|
|
|
subghz->secure_data->cnt[2];
|
2023-04-21 13:10:08 +00:00
|
|
|
|
2023-05-09 09:07:36 +00:00
|
|
|
seed = subghz->secure_data->seed[0] << 24 | subghz->secure_data->seed[1] << 16 |
|
|
|
|
subghz->secure_data->seed[2] << 8 | subghz->secure_data->seed[3];
|
2023-04-21 13:10:08 +00:00
|
|
|
|
2023-09-05 02:31:03 +00:00
|
|
|
if(state == SubmenuIndexFaacSLH_Manual_433) {
|
2023-05-10 20:12:50 +00:00
|
|
|
generated_protocol = subghz_txrx_gen_faac_slh_protocol(
|
2023-05-09 09:07:36 +00:00
|
|
|
subghz->txrx,
|
2023-05-08 18:55:51 +00:00
|
|
|
"AM650",
|
|
|
|
433920000,
|
|
|
|
fix_part >> 4,
|
|
|
|
fix_part & 0xf,
|
|
|
|
(cnt & 0xFFFFF),
|
|
|
|
seed,
|
|
|
|
"FAAC_SLH");
|
2023-09-05 02:31:03 +00:00
|
|
|
} else if(state == SubmenuIndexFaacSLH_Manual_868) {
|
2023-05-10 20:12:50 +00:00
|
|
|
generated_protocol = subghz_txrx_gen_faac_slh_protocol(
|
2023-05-09 09:07:36 +00:00
|
|
|
subghz->txrx,
|
2023-05-08 18:55:51 +00:00
|
|
|
"AM650",
|
|
|
|
868350000,
|
2023-04-21 13:10:08 +00:00
|
|
|
fix_part >> 4,
|
|
|
|
fix_part & 0xf,
|
|
|
|
(cnt & 0xFFFFF),
|
|
|
|
seed,
|
2023-05-08 18:55:51 +00:00
|
|
|
"FAAC_SLH");
|
2023-04-21 13:10:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(!generated_protocol) {
|
|
|
|
furi_string_set(
|
|
|
|
subghz->error_str, "Function requires\nan SD card with\nfresh databases.");
|
|
|
|
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowError);
|
|
|
|
}
|
|
|
|
consumed = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-18 18:04:59 +00:00
|
|
|
// Reset Seed, Fix, Cnt in secure data after successful or unsuccessful generation
|
|
|
|
memset(subghz->secure_data->seed, 0, sizeof(subghz->secure_data->seed));
|
|
|
|
memset(subghz->secure_data->cnt, 0, sizeof(subghz->secure_data->cnt));
|
|
|
|
memset(subghz->secure_data->fix, 0, sizeof(subghz->secure_data->fix));
|
|
|
|
|
2023-04-21 13:10:08 +00:00
|
|
|
if(generated_protocol) {
|
|
|
|
subghz_file_name_clear(subghz);
|
2023-08-17 14:33:21 +00:00
|
|
|
|
2023-04-21 13:10:08 +00:00
|
|
|
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_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, "");
|
|
|
|
}
|