diff --git a/applications/plugins/subbrute/helpers/subbrute_worker.c b/applications/plugins/subbrute/helpers/subbrute_worker.c index 8e1994b95..cb75876c4 100644 --- a/applications/plugins/subbrute/helpers/subbrute_worker.c +++ b/applications/plugins/subbrute/helpers/subbrute_worker.c @@ -9,6 +9,7 @@ struct SubBruteWorker { FuriThread* thread; volatile bool worker_running; + volatile bool worker_manual_mode; SubGhzEnvironment* environment; SubGhzTransmitter* transmitter; @@ -102,6 +103,7 @@ SubBruteWorker* subbrute_worker_alloc() { //instance->status = SubBruteWorkerStatusIDLE; instance->worker_running = false; + instance->worker_manual_mode = false; instance->flipper_format = flipper_format_string_alloc(); string_init(instance->protocol_name); @@ -127,7 +129,10 @@ bool subbrute_worker_start( FuriHalSubGhzPreset preset, const char* protocol_name) { furi_assert(instance); - furi_assert(!instance->worker_running); + + if (instance->worker_manual_mode) { + return false; + } instance->frequency = frequency; instance->preset = preset; @@ -203,5 +208,85 @@ bool subbrute_worker_transmit(SubBruteWorker* instance, const char* payload) { stream_write_cstring(stream, payload); subghz_transmitter_deserialize(instance->transmitter, instance->flipper_format); + return true; +} + +bool subbrute_worker_single_transmit(SubBruteWorker* instance, + uint32_t frequency, + FuriHalSubGhzPreset preset, + const char* protocol_name, + const char* payload) { + furi_assert(instance); + + if (instance->worker_manual_mode || !subbrute_worker_can_transmit(instance)) { +#ifdef FURI_DEBUG + FURI_LOG_D(TAG, "cannot transmit"); +#endif + return false; + } + if (instance->worker_running) { +#ifdef FURI_DEBUG + FURI_LOG_D(TAG, "subbrute_worker_stop"); +#endif + subbrute_worker_stop(instance); + } + + instance->last_time_tx_data = furi_get_tick(); + instance->worker_manual_mode = true; + + instance->preset = preset; + instance->frequency = frequency; + + string_clear(instance->protocol_name); + string_init_printf(instance->protocol_name, "%s", protocol_name); + + furi_hal_subghz_reset(); + furi_hal_subghz_idle(); + furi_hal_subghz_load_preset(instance->preset); + + furi_hal_subghz_set_frequency_and_path(instance->frequency); + furi_hal_subghz_flush_rx(); + + if(!furi_hal_subghz_is_tx_allowed(frequency)) { + instance->frequency = frequency; + instance->worker_manual_mode = false; + return false; + } + +#ifdef FURI_DEBUG + FURI_LOG_I(TAG, "Frequency: %d", frequency); +#endif + + instance->environment = subghz_environment_alloc(); + instance->transmitter = subghz_transmitter_alloc_init( + instance->environment, string_get_cstr(instance->protocol_name)); + + Stream* stream = flipper_format_get_raw_stream(instance->flipper_format); + stream_clean(stream); + stream_write_cstring(stream, payload); + subghz_transmitter_deserialize(instance->transmitter, instance->flipper_format); + + furi_hal_subghz_reset(); + furi_hal_subghz_load_preset(instance->preset); + frequency = furi_hal_subghz_set_frequency_and_path(frequency); + + furi_hal_power_suppress_charge_enter(); + furi_hal_subghz_start_async_tx(subghz_transmitter_yield, instance->transmitter); + + while(!furi_hal_subghz_is_async_tx_complete()) { + furi_delay_ms(SUBBRUTE_SEND_DELAY); + } + furi_hal_subghz_stop_async_tx(); + furi_hal_subghz_sleep(); + + furi_hal_power_suppress_charge_exit(); + + subghz_transmitter_free(instance->transmitter); + instance->transmitter = NULL; + subghz_environment_free(instance->environment); + instance->environment = NULL; + + instance->worker_manual_mode = false; + return true; } \ No newline at end of file diff --git a/applications/plugins/subbrute/helpers/subbrute_worker.h b/applications/plugins/subbrute/helpers/subbrute_worker.h index 5d2a21831..aa6c898bd 100644 --- a/applications/plugins/subbrute/helpers/subbrute_worker.h +++ b/applications/plugins/subbrute/helpers/subbrute_worker.h @@ -26,4 +26,9 @@ void subbrute_worker_stop(SubBruteWorker* instance); //bool subbrute_worker_write(SubBruteWorker* instance, uint8_t* data, size_t size); bool subbrute_worker_is_running(SubBruteWorker* instance); bool subbrute_worker_can_transmit(SubBruteWorker* instance); -bool subbrute_worker_transmit(SubBruteWorker* instance, const char* payload); \ No newline at end of file +bool subbrute_worker_transmit(SubBruteWorker* instance, const char* payload); +bool subbrute_worker_single_transmit(SubBruteWorker* instance, + uint32_t frequency, + FuriHalSubGhzPreset preset, + const char* protocol_name, + const char* payload); \ No newline at end of file diff --git a/applications/plugins/subbrute/scenes/subbrute_scene_run_attack.c b/applications/plugins/subbrute/scenes/subbrute_scene_run_attack.c index 55431cdd0..fbb6dccce 100644 --- a/applications/plugins/subbrute/scenes/subbrute_scene_run_attack.c +++ b/applications/plugins/subbrute/scenes/subbrute_scene_run_attack.c @@ -33,11 +33,11 @@ void subbrute_scene_run_attack_on_enter(void* context) { true); // Start worker if not started - subbrute_attack_view_start_worker( + /*subbrute_attack_view_start_worker( view, instance->device->frequency, instance->device->preset, - string_get_cstr(instance->device->protocol_name)); + string_get_cstr(instance->device->protocol_name));*/ } bool subbrute_scene_run_attack_on_event(void* context, SceneManagerEvent event) { @@ -58,7 +58,12 @@ bool subbrute_scene_run_attack_on_event(void* context, SceneManagerEvent event) // Blink notification_message(instance->notifications, &sequence_blink_yellow_100); - if(subbrute_attack_view_transmit(view, instance->device->payload)) { + if(subbrute_attack_view_single_transmit( + view, + instance->device->frequency, + instance->device->preset, + string_get_cstr(instance->device->protocol_name), + instance->device->payload)) { // Make payload for new iteration or exit if(instance->device->key_index + 1 > instance->device->max_value) { // End of list @@ -79,81 +84,4 @@ bool subbrute_scene_run_attack_on_event(void* context, SceneManagerEvent event) } return consumed; - - // if(event.evt_type == EventTypeKey) { - // if(event.input_type == InputTypeShort) { - // switch(event.key) { - // case InputKeyDown: - // break; - // case InputKeyUp: - // if(!context->is_attacking) { - // subbrute_send_packet_parsed(context); - // string_clear(context->flipper_format_string); - // toSave = true; - // context->current_scene = SceneSaveName; - // } - // break; - // case InputKeyLeft: - // if(!context->is_attacking && context->payload > 0x00) { - // context->payload--; - // subbrute_send_packet(context); - // notification_message(context->notify, &sequence_blink_blue_10); - // } else if(!context->is_attacking && context->payload == 0x00) { - // context->payload = max_value; - // subbrute_send_packet(context); - // notification_message(context->notify, &sequence_blink_blue_10); - // } - // break; - // case InputKeyRight: - // if(!context->is_attacking && context->payload < max_value) { - // context->payload++; - // subbrute_send_packet(context); - // notification_message(context->notify, &sequence_blink_blue_10); - // } else if(!context->is_attacking && context->payload == max_value) { - // context->payload = 0x00; - // subbrute_send_packet(context); - // notification_message(context->notify, &sequence_blink_blue_10); - // } - // break; - // case InputKeyOk: - // if(!context->is_attacking) { - // if(context->payload == max_value) { - // context->payload = 0x00; - // //subbrute_counter = 0; - // } - // context->is_attacking = true; - // start_bruthread(context); - // notification_message(context->notify, &sequence_blink_start_blue); - // } else { - // context->is_attacking = false; - // //context->close_thread_please = true; - // if(context->is_thread_running && context->bruthread) { - // furi_thread_join(context->bruthread); // wait until thread is finished - // } - // //context->close_thread_please = false; - // notification_message(context->notify, &sequence_blink_stop); - // notification_message(context->notify, &sequence_single_vibro); - // } - // break; - // case InputKeyBack: - // locked = false; - // //context->close_thread_please = true; - // context->is_attacking = false; - // if(context->is_thread_running && context->bruthread) { - // furi_thread_join(context->bruthread); // wait until thread is finished - // } - // //context->close_thread_please = false; - // string_reset(context->notification_msg); - // context->payload = 0x00; - // //subbrute_counter = 0; - // notification_message(context->notify, &sequence_blink_stop); - // if(context->attack == SubBruteAttackLoadFile) { - // context->current_scene = SceneSelectField; - // } else { - // context->current_scene = SceneEntryPoint; - // } - // break; - // } - // } - // } } diff --git a/applications/plugins/subbrute/scenes/subbrute_scene_setup_attack.c b/applications/plugins/subbrute/scenes/subbrute_scene_setup_attack.c index 1ce6a3cde..0b3f8494e 100644 --- a/applications/plugins/subbrute/scenes/subbrute_scene_setup_attack.c +++ b/applications/plugins/subbrute/scenes/subbrute_scene_setup_attack.c @@ -52,7 +52,7 @@ bool subbrute_scene_setup_attack_on_event(void* context, SceneManagerEvent event if(event.event == SubBruteCustomEventTypeTransmitStarted) { scene_manager_next_scene(instance->scene_manager, SubBruteSceneRunAttack); } else if(event.event == SubBruteCustomEventTypeSaveFile) { - subbrute_attack_view_stop_worker(view); + //subbrute_attack_view_stop_worker(view); subbrute_attack_view_init_values( view, @@ -66,7 +66,7 @@ bool subbrute_scene_setup_attack_on_event(void* context, SceneManagerEvent event FURI_LOG_D(TAG, "SubBruteCustomEventTypeBackPressed"); #endif instance->device->key_index = 0x00; - subbrute_attack_view_stop_worker(view); + //subbrute_attack_view_stop_worker(view); subbrute_attack_view_init_values( view, instance->device->attack, @@ -101,16 +101,21 @@ bool subbrute_scene_setup_attack_on_event(void* context, SceneManagerEvent event // Blink notification_message(instance->notifications, &sequence_blink_green_100); - if(!subbrute_attack_view_is_worker_running(view)) { - subbrute_attack_view_start_worker( - view, - instance->device->frequency, - instance->device->preset, - string_get_cstr(instance->device->protocol_name)); - } + // if(!subbrute_attack_view_is_worker_running(view)) { + // subbrute_attack_view_start_worker( + // view, + // instance->device->frequency, + // instance->device->preset, + // string_get_cstr(instance->device->protocol_name)); + // } subbrute_device_create_packet_parsed( instance->device, instance->device->key_index); - subbrute_attack_view_transmit(view, instance->device->payload); + subbrute_attack_view_single_transmit( + view, + instance->device->frequency, + instance->device->preset, + string_get_cstr(instance->device->protocol_name), + instance->device->payload); // Stop notification_message(instance->notifications, &sequence_blink_stop); diff --git a/applications/plugins/subbrute/views/subbrute_attack_view.c b/applications/plugins/subbrute/views/subbrute_attack_view.c index 069c7aac1..7c86e7292 100644 --- a/applications/plugins/subbrute/views/subbrute_attack_view.c +++ b/applications/plugins/subbrute/views/subbrute_attack_view.c @@ -295,6 +295,16 @@ bool subbrute_attack_view_transmit(SubBruteAttackView* instance, const char* pay return subbrute_worker_transmit(instance->worker, payload); } +bool subbrute_attack_view_single_transmit( + SubBruteAttackView* instance, + uint32_t frequency, + FuriHalSubGhzPreset preset, + const char* protocol_name, + const char* payload) { + return subbrute_worker_single_transmit( + instance->worker, frequency, preset, protocol_name, payload); +} + bool subbrute_attack_view_is_worker_running(SubBruteAttackView* instance) { furi_assert(instance); @@ -306,7 +316,6 @@ void subbrute_attack_view_exit(void* context) { SubBruteAttackView* instance = context; #ifdef FURI_DEBUG FURI_LOG_D(TAG, "subbrute_attack_view_exit"); - furi_delay_ms(150); #endif with_view_model( instance->view, (SubBruteAttackViewModel * model) { diff --git a/applications/plugins/subbrute/views/subbrute_attack_view.h b/applications/plugins/subbrute/views/subbrute_attack_view.h index 3858f7ec2..067ecc2c7 100644 --- a/applications/plugins/subbrute/views/subbrute_attack_view.h +++ b/applications/plugins/subbrute/views/subbrute_attack_view.h @@ -34,4 +34,10 @@ void subbrute_attack_view_start_worker( FuriHalSubGhzPreset preset, const char* protocol_name); bool subbrute_attack_view_transmit(SubBruteAttackView* instance, const char* payload); +bool subbrute_attack_view_single_transmit( + SubBruteAttackView* instance, + uint32_t frequency, + FuriHalSubGhzPreset preset, + const char* protocol_name, + const char* payload); bool subbrute_attack_view_is_worker_running(SubBruteAttackView* instance); \ No newline at end of file