unleashed-firmware/applications/main/subghz/scenes/subghz_scene_set_seed_faac.c

111 lines
4.3 KiB
C
Raw Normal View History

2022-04-19 00:32:25 +03:00
#include "../subghz_i.h"
2022-04-24 21:33:22 +03:00
#include <dolphin/dolphin.h>
#include <lib/subghz/protocols/faac_slh.h>
2022-04-19 00:32:25 +03:00
#define TAG "SubGhzSetSeedFaac"
2022-04-23 01:21:50 +03:00
void subghz_scene_set_seed_faac_byte_input_callback(void* context) {
2022-04-21 19:55:08 +03:00
SubGhz* subghz = context;
2022-04-19 00:32:25 +03:00
view_dispatcher_send_custom_event(subghz->view_dispatcher, SubGhzCustomEventByteInputDone);
}
void subghz_scene_set_seed_faac_on_enter(void* context) {
2022-04-21 19:55:08 +03:00
SubGhz* subghz = context;
2022-04-19 00:32:25 +03:00
// Setup view
ByteInput* byte_input = subghz->byte_input;
2022-04-20 20:47:32 +03:00
byte_input_set_header_text(byte_input, "Enter SEED in hex");
2022-04-19 00:32:25 +03:00
byte_input_set_result_callback(
byte_input,
subghz_scene_set_seed_faac_byte_input_callback,
2022-04-19 00:32:25 +03:00
NULL,
subghz,
2022-04-20 22:23:45 +03:00
subghz->txrx->secure_data->seed,
2022-04-19 00:32:25 +03:00
4);
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdByteInput);
}
bool subghz_scene_set_seed_faac_on_event(void* context, SceneManagerEvent event) {
2022-04-21 19:55:08 +03:00
SubGhz* subghz = context;
bool consumed = false;
2022-04-24 21:33:22 +03:00
bool generated_protocol = false;
2022-04-19 00:32:25 +03:00
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubGhzCustomEventByteInputDone) {
2022-06-24 13:01:41 +03:00
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];
2022-04-28 13:33:22 +03:00
2022-07-17 08:05:09 +03:00
uint32_t cnt = subghz->txrx->secure_data->cnt[0] << 16 |
subghz->txrx->secure_data->cnt[1] << 8 |
subghz->txrx->secure_data->cnt[2];
2022-06-24 13:01:41 +03:00
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];
2022-04-28 13:33:22 +03:00
2022-04-24 21:33:22 +03:00
subghz->txrx->transmitter =
subghz_transmitter_alloc_init(subghz->txrx->environment, "Faac SLH");
2022-04-26 18:30:45 +03:00
if(subghz->txrx->transmitter) {
SubGhzCustomEvent state =
scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneSetType);
if(state == SubmenuIndexFaacSLH_433) {
subghz_preset_init(subghz, "AM650", 433920000, NULL, 0);
} else if(state == SubmenuIndexFaacSLH_868) {
subghz_preset_init(subghz, "AM650", 868350000, NULL, 0);
}
2022-04-24 21:33:22 +03:00
subghz_protocol_faac_slh_create_data(
subghz_transmitter_get_protocol_instance(subghz->txrx->transmitter),
2022-04-24 21:33:22 +03:00
subghz->txrx->fff_data,
fix_part >> 4,
fix_part & 0xf,
2022-07-17 08:05:09 +03:00
(cnt & 0xFFFFF),
2022-04-24 21:33:22 +03:00
seed,
"FAAC_SLH",
2022-07-26 21:09:31 +03:00
subghz->txrx->preset);
// rogueemaster dont steal!
2022-04-26 22:57:31 +03:00
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;
2022-06-24 13:01:41 +03:00
}
flipper_format_write_hex(
subghz->txrx->fff_data, "Seed", seed_data, sizeof(uint32_t));
2022-04-27 17:39:08 +03:00
2022-04-24 21:33:22 +03:00
generated_protocol = true;
} else {
generated_protocol = false;
}
2022-04-27 17:39:08 +03:00
2022-04-24 21:33:22 +03:00
subghz_transmitter_free(subghz->txrx->transmitter);
2022-06-24 13:01:41 +03:00
2022-04-24 21:33:22 +03:00
if(!generated_protocol) {
2022-10-05 21:27:13 +03:00
furi_string_set(
2022-04-24 21:33:22 +03:00
subghz->error_str, "Function requires\nan SD card with\nfresh databases.");
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowError);
}
2022-04-21 19:55:08 +03:00
consumed = true;
2022-04-19 00:32:25 +03:00
}
2022-06-24 13:01:41 +03:00
2022-04-24 21:33:22 +03:00
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;
}
2022-04-19 00:32:25 +03:00
}
2022-06-24 13:01:41 +03:00
return consumed;
2022-04-19 00:32:25 +03:00
}
void subghz_scene_set_seed_faac_on_exit(void* context) {
2022-04-21 19:55:08 +03:00
SubGhz* subghz = context;
2022-06-24 13:01:41 +03:00
2022-04-19 00:32:25 +03:00
// Clear view
byte_input_set_result_callback(subghz->byte_input, NULL, NULL, NULL, NULL, 0);
byte_input_set_header_text(subghz->byte_input, "");
}