From 023223dda49f26ece48d1b54ec21e83753b2537a Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Wed, 20 Mar 2024 00:42:11 +0000 Subject: [PATCH] Restrict only on TX --- applications/main/momentum_app/momentum_app.c | 4 +- .../momentum_app_scene_protocols_freqs_add.c | 2 +- targets/f7/api_symbols.csv | 1 - targets/f7/furi_hal/furi_hal_region.c | 7 +- targets/f7/furi_hal/furi_hal_region_i.h | 5 ++ targets/f7/furi_hal/furi_hal_subghz.c | 70 ++++++------------- targets/f7/furi_hal/furi_hal_subghz.h | 2 - 7 files changed, 37 insertions(+), 54 deletions(-) create mode 100644 targets/f7/furi_hal/furi_hal_region_i.h diff --git a/applications/main/momentum_app/momentum_app.c b/applications/main/momentum_app/momentum_app.c index 271009143f..362caf64ac 100644 --- a/applications/main/momentum_app/momentum_app.c +++ b/applications/main/momentum_app/momentum_app.c @@ -292,14 +292,14 @@ MomentumApp* momentum_app_alloc() { if(!flipper_format_rewind(file)) break; while(flipper_format_read_uint32(file, "Frequency", &temp, 1)) { - if(furi_hal_subghz_is_frequency_valid_extended(temp)) { + if(furi_hal_subghz_is_frequency_valid(temp)) { FrequencyList_push_back(app->subghz_static_freqs, temp); } } if(!flipper_format_rewind(file)) break; while(flipper_format_read_uint32(file, "Hopper_frequency", &temp, 1)) { - if(furi_hal_subghz_is_frequency_valid_extended(temp)) { + if(furi_hal_subghz_is_frequency_valid(temp)) { FrequencyList_push_back(app->subghz_hopper_freqs, temp); } } diff --git a/applications/main/momentum_app/scenes/momentum_app_scene_protocols_freqs_add.c b/applications/main/momentum_app/scenes/momentum_app_scene_protocols_freqs_add.c index b2d80949c4..3481cb4fc4 100644 --- a/applications/main/momentum_app/scenes/momentum_app_scene_protocols_freqs_add.c +++ b/applications/main/momentum_app/scenes/momentum_app_scene_protocols_freqs_add.c @@ -10,7 +10,7 @@ static void momentum_app_scene_protocols_freqs_add_text_input_callback(void* con char* end; uint32_t value = strtol(app->subghz_freq_buffer, &end, 0) * 1000; - if(*end || !furi_hal_subghz_is_frequency_valid_extended(value)) { + if(*end || !furi_hal_subghz_is_frequency_valid(value)) { view_dispatcher_send_custom_event(app->view_dispatcher, TextInputResultError); return; } diff --git a/targets/f7/api_symbols.csv b/targets/f7/api_symbols.csv index 3c092dc2fc..df8d6a6109 100644 --- a/targets/f7/api_symbols.csv +++ b/targets/f7/api_symbols.csv @@ -1653,7 +1653,6 @@ Function,+,furi_hal_subghz_idle,void, Function,-,furi_hal_subghz_init,void, Function,+,furi_hal_subghz_is_async_tx_complete,_Bool, Function,+,furi_hal_subghz_is_frequency_valid,_Bool,uint32_t -Function,+,furi_hal_subghz_is_frequency_valid_extended,_Bool,uint32_t Function,+,furi_hal_subghz_is_rx_data_crc_valid,_Bool, Function,+,furi_hal_subghz_is_tx_allowed,_Bool,uint32_t Function,+,furi_hal_subghz_load_custom_preset,void,const uint8_t* diff --git a/targets/f7/furi_hal/furi_hal_region.c b/targets/f7/furi_hal/furi_hal_region.c index 143d5c18c2..1e25e92f79 100644 --- a/targets/f7/furi_hal/furi_hal_region.c +++ b/targets/f7/furi_hal/furi_hal_region.c @@ -106,7 +106,7 @@ const char* furi_hal_region_get_name() { } } -bool furi_hal_region_is_frequency_allowed(uint32_t frequency) { +bool _furi_hal_region_is_frequency_allowed(uint32_t frequency) { if(!furi_hal_region) { return false; } @@ -119,6 +119,11 @@ bool furi_hal_region_is_frequency_allowed(uint32_t frequency) { return true; } +// Check furi_hal_subghz settings for region bypass, if not it uses function above +bool furi_hal_region_is_frequency_allowed(uint32_t frequency) { + return furi_hal_subghz_is_tx_allowed(frequency); +} + const FuriHalRegionBand* furi_hal_region_get_band(uint32_t frequency) { if(!furi_hal_region) { return NULL; diff --git a/targets/f7/furi_hal/furi_hal_region_i.h b/targets/f7/furi_hal/furi_hal_region_i.h new file mode 100644 index 0000000000..6a98f47ee2 --- /dev/null +++ b/targets/f7/furi_hal/furi_hal_region_i.h @@ -0,0 +1,5 @@ +#pragma once + +#include + +bool _furi_hal_region_is_frequency_allowed(uint32_t frequency); diff --git a/targets/f7/furi_hal/furi_hal_subghz.c b/targets/f7/furi_hal/furi_hal_subghz.c index 5a632658b8..f4491bf9b2 100644 --- a/targets/f7/furi_hal/furi_hal_subghz.c +++ b/targets/f7/furi_hal/furi_hal_subghz.c @@ -1,6 +1,6 @@ #include #include - +#include #include #include #include @@ -8,7 +8,6 @@ #include #include #include -#include #include @@ -362,7 +361,7 @@ uint8_t furi_hal_subghz_get_lqi() { These changes are at your own risk. The PLL may not lock and FZ devs have warned of possible damage! */ -bool furi_hal_subghz_is_frequency_valid_extended(uint32_t value) { +bool furi_hal_subghz_is_frequency_valid(uint32_t value) { if(!(value >= 281000000 && value <= 361000000) && !(value >= 378000000 && value <= 481000000) && !(value >= 749000000 && value <= 962000000)) { @@ -372,24 +371,6 @@ bool furi_hal_subghz_is_frequency_valid_extended(uint32_t value) { return true; } -bool furi_hal_subghz_is_frequency_valid(uint32_t value) { - bool allow_extended_for_int = furi_hal_subghz.extended_frequency_i; - - if(!allow_extended_for_int) { - if(!(value >= 299999755 && value <= 350000335) && // was increased from 348 to 350 - !(value >= 386999938 && value <= 467750000) && // was increased from 464 to 467.75 - !(value >= 778999847 && value <= 928000000)) { - return false; - } - } else { - if(!furi_hal_subghz_is_frequency_valid_extended(value)) { - return false; - } - } - - return true; -} - uint32_t furi_hal_subghz_set_frequency_and_path(uint32_t value) { // Set these values to the extended frequency range only. They dont define if you can transmit but do select the correct RF path value = furi_hal_subghz_set_frequency(value); @@ -406,36 +387,31 @@ uint32_t furi_hal_subghz_set_frequency_and_path(uint32_t value) { } bool furi_hal_subghz_is_tx_allowed(uint32_t value) { - bool allow_extended_for_int = furi_hal_subghz.extended_frequency_i; - bool bypass_region = furi_hal_subghz.bypass_region; - - bool allowed = false; + if(!furi_hal_subghz.bypass_region) { + if(!_furi_hal_region_is_frequency_allowed(value)) { + FURI_LOG_I(TAG, "Frequency blocked - outside region range"); + return false; + } - do { - if(bypass_region) { - if(!allow_extended_for_int && !furi_hal_subghz_is_frequency_valid(value)) { - FURI_LOG_I(TAG, "Frequency blocked - outside default range"); - break; - } else if(allow_extended_for_int && !furi_hal_subghz_is_frequency_valid_extended(value)) { - FURI_LOG_I(TAG, "Frequency blocked - outside extended range"); - break; - } - } else { - if(!furi_hal_region_is_provisioned()) { - FURI_LOG_E(TAG, "Frequency blocked - region not provisioned"); - break; - } + return true; + } - if(!furi_hal_region_is_frequency_allowed(value)) { - FURI_LOG_I(TAG, "Frequency blocked - outside region"); - break; - } - } + bool allow_extended_for_int = furi_hal_subghz.extended_frequency_i; - allowed = true; - } while(false); + if(!(allow_extended_for_int) && + !(value >= 299999755 && value <= 350000335) && // was increased from 348 to 350 + !(value >= 386999938 && value <= 467750000) && // was increased from 464 to 467.75 + !(value >= 778999847 && value <= 928000000)) { + FURI_LOG_I(TAG, "Frequency blocked - outside default range"); + return false; + } else if( + (allow_extended_for_int) && // + !furi_hal_subghz_is_frequency_valid(value)) { + FURI_LOG_I(TAG, "Frequency blocked - outside dangerous range"); + return false; + } - return allowed; + return true; } uint32_t furi_hal_subghz_set_frequency(uint32_t value) { diff --git a/targets/f7/furi_hal/furi_hal_subghz.h b/targets/f7/furi_hal/furi_hal_subghz.h index 0373bda184..b901e85ea4 100644 --- a/targets/f7/furi_hal/furi_hal_subghz.h +++ b/targets/f7/furi_hal/furi_hal_subghz.h @@ -156,8 +156,6 @@ uint8_t furi_hal_subghz_get_lqi(); */ bool furi_hal_subghz_is_frequency_valid(uint32_t value); -bool furi_hal_subghz_is_frequency_valid_extended(uint32_t value); - /** Set frequency and path This function automatically selects antenna matching * network *