From cef63f4c9810c6b16f198e61348b5bb14f97a2b5 Mon Sep 17 00:00:00 2001 From: Sil333033 <94360907+Sil333033@users.noreply.github.com> Date: Mon, 18 Mar 2024 18:58:41 +0100 Subject: [PATCH] Subghz: brought back manual region bypass --- applications/main/momentum_app/momentum_app.c | 3 + applications/main/momentum_app/momentum_app.h | 1 + .../scenes/momentum_app_scene_protocols.c | 14 +++ .../main/subghz/subghz_extended_freq.c | 3 + targets/f7/api_symbols.csv | 4 +- targets/f7/furi_hal/furi_hal.c | 1 + targets/f7/furi_hal/furi_hal_region.c | 95 +++++++++++++++++-- targets/f7/furi_hal/furi_hal_subghz.c | 60 +++++++++--- targets/f7/furi_hal/furi_hal_subghz.h | 2 + targets/furi_hal_include/furi_hal_region.h | 3 + 10 files changed, 165 insertions(+), 21 deletions(-) diff --git a/applications/main/momentum_app/momentum_app.c b/applications/main/momentum_app/momentum_app.c index d1ff7d6208..362caf64ac 100644 --- a/applications/main/momentum_app/momentum_app.c +++ b/applications/main/momentum_app/momentum_app.c @@ -76,6 +76,8 @@ bool momentum_app_apply(MomentumApp* app) { if(!flipper_format_write_bool( file, "use_ext_range_at_own_risk", &app->subghz_extend, 1)) break; + if(!flipper_format_write_bool(file, "ignore_default_tx_region", &app->subghz_bypass, 1)) + break; } while(0); flipper_format_free(file); } @@ -307,6 +309,7 @@ MomentumApp* momentum_app_alloc() { file = flipper_format_file_alloc(storage); if(flipper_format_file_open_existing(file, "/ext/subghz/assets/extend_range.txt")) { flipper_format_read_bool(file, "use_ext_range_at_own_risk", &app->subghz_extend, 1); + flipper_format_read_bool(file, "ignore_default_tx_region", &app->subghz_bypass, 1); } flipper_format_free(file); furi_record_close(RECORD_STORAGE); diff --git a/applications/main/momentum_app/momentum_app.h b/applications/main/momentum_app/momentum_app.h index 9511185d36..905bea3299 100644 --- a/applications/main/momentum_app/momentum_app.h +++ b/applications/main/momentum_app/momentum_app.h @@ -59,6 +59,7 @@ typedef struct { uint8_t subghz_hopper_index; char subghz_freq_buffer[7]; bool subghz_extend; + bool subghz_bypass; RgbColor lcd_color; Rgb565Color vgm_color; char device_name[FURI_HAL_VERSION_ARRAY_NAME_LENGTH]; diff --git a/applications/main/momentum_app/scenes/momentum_app_scene_protocols.c b/applications/main/momentum_app/scenes/momentum_app_scene_protocols.c index 7258a9d9a0..f94d6d5cd7 100644 --- a/applications/main/momentum_app/scenes/momentum_app_scene_protocols.c +++ b/applications/main/momentum_app/scenes/momentum_app_scene_protocols.c @@ -3,6 +3,7 @@ enum VarItemListIndex { VarItemListIndexSubghzFreqs, VarItemListIndexSubghzExtend, + VarItemListIndexSubghzBypass, VarItemListIndexGpioPins, }; @@ -18,6 +19,14 @@ static void momentum_app_scene_protocols_subghz_extend_changed(VariableItem* ite app->save_subghz = true; } +static void xtreme_app_scene_protocols_subghz_bypass_changed(VariableItem* item) { + MomentumApp* app = variable_item_get_context(item); + app->subghz_bypass = variable_item_get_current_value_index(item); + variable_item_set_current_value_text(item, app->subghz_bypass ? "ON" : "OFF"); + app->save_subghz = true; + app->require_reboot = true; +} + static void momentum_app_scene_protocols_file_naming_prefix_changed(VariableItem* item) { MomentumApp* app = variable_item_get_context(item); bool value = variable_item_get_current_value_index(item); @@ -39,6 +48,11 @@ void momentum_app_scene_protocols_on_enter(void* context) { variable_item_set_current_value_index(item, app->subghz_extend); variable_item_set_current_value_text(item, app->subghz_extend ? "ON" : "OFF"); + item = variable_item_list_add( + var_item_list, "SubGHz Bypass", 2, xtreme_app_scene_protocols_subghz_bypass_changed, app); + variable_item_set_current_value_index(item, app->subghz_bypass); + variable_item_set_current_value_text(item, app->subghz_bypass ? "ON" : "OFF"); + item = variable_item_list_add(var_item_list, "GPIO Pins", 0, NULL, app); variable_item_set_current_value_text(item, ">"); diff --git a/applications/main/subghz/subghz_extended_freq.c b/applications/main/subghz/subghz_extended_freq.c index 488b3312da..e3feb29f1b 100644 --- a/applications/main/subghz/subghz_extended_freq.c +++ b/applications/main/subghz/subghz_extended_freq.c @@ -6,14 +6,17 @@ void subghz_extended_freq() { bool is_extended_i = false; + bool is_bypassed = false; Storage* storage = furi_record_open(RECORD_STORAGE); FlipperFormat* file = flipper_format_file_alloc(storage); if(flipper_format_file_open_existing(file, "/ext/subghz/assets/extend_range.txt")) { flipper_format_read_bool(file, "use_ext_range_at_own_risk", &is_extended_i, 1); + flipper_format_read_bool(file, "ignore_default_tx_region", &is_bypassed, 1); } furi_hal_subghz_set_extended_frequency(is_extended_i); + furi_hal_subghz_set_bypass_regio(is_bypassed); flipper_format_free(file); furi_record_close(RECORD_STORAGE); diff --git a/targets/f7/api_symbols.csv b/targets/f7/api_symbols.csv index 5e9783b1fd..3aefba157c 100644 --- a/targets/f7/api_symbols.csv +++ b/targets/f7/api_symbols.csv @@ -1,5 +1,5 @@ entry,status,name,type,params -Version,+,58.1,, +Version,+,58.2,, Header,+,applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.h,, Header,+,applications/main/archive/helpers/archive_helpers_ext.h,, Header,+,applications/main/subghz/subghz_fap.h,, @@ -1522,6 +1522,7 @@ Function,+,furi_hal_random_init,void, Function,+,furi_hal_region_get,const FuriHalRegion*, Function,+,furi_hal_region_get_band,const FuriHalRegionBand*,uint32_t Function,+,furi_hal_region_get_name,const char*, +Function,+,furi_hal_region_init,void, Function,+,furi_hal_region_is_frequency_allowed,_Bool,uint32_t Function,+,furi_hal_region_is_provisioned,_Bool, Function,+,furi_hal_region_set,void,FuriHalRegion* @@ -1662,6 +1663,7 @@ Function,+,furi_hal_subghz_reset,void, Function,+,furi_hal_subghz_rx,void, Function,+,furi_hal_subghz_rx_pipe_not_empty,_Bool, Function,+,furi_hal_subghz_set_async_mirror_pin,void,const GpioPin* +Function,+,furi_hal_subghz_set_bypass_regio,void,_Bool Function,+,furi_hal_subghz_set_ext_power_amp,void,_Bool Function,+,furi_hal_subghz_set_frequency,uint32_t,uint32_t Function,+,furi_hal_subghz_set_frequency_and_path,uint32_t,uint32_t diff --git a/targets/f7/furi_hal/furi_hal.c b/targets/f7/furi_hal/furi_hal.c index 172ee38abb..12a0ee88ea 100644 --- a/targets/f7/furi_hal/furi_hal.c +++ b/targets/f7/furi_hal/furi_hal.c @@ -59,6 +59,7 @@ void furi_hal_init() { furi_hal_light_init(); furi_hal_bt_init(); furi_hal_memory_init(); + furi_hal_region_init(); #ifndef FURI_RAM_EXEC furi_hal_usb_init(); diff --git a/targets/f7/furi_hal/furi_hal_region.c b/targets/f7/furi_hal/furi_hal_region.c index 0f0cb855cb..84351cb7df 100644 --- a/targets/f7/furi_hal/furi_hal_region.c +++ b/targets/f7/furi_hal/furi_hal_region.c @@ -1,4 +1,5 @@ #include +#include #include const FuriHalRegion furi_hal_region_zero = { @@ -13,18 +14,88 @@ const FuriHalRegion furi_hal_region_zero = { }, }}; +const FuriHalRegion furi_hal_region_eu_ru = { + .country_code = "EU", + .bands_count = 2, + .bands = { + { + .start = 433050000, + .end = 434790000, + .power_limit = 12, + .duty_cycle = 50, + }, + { + .start = 868150000, + .end = 868550000, + .power_limit = 12, + .duty_cycle = 50, + }}}; + +const FuriHalRegion furi_hal_region_us_ca_au = { + .country_code = "US", + .bands_count = 3, + .bands = { + { + .start = 304100000, + .end = 321950000, + .power_limit = 12, + .duty_cycle = 50, + }, + { + .start = 433050000, + .end = 434790000, + .power_limit = 12, + .duty_cycle = 50, + }, + { + .start = 915000000, + .end = 928000000, + .power_limit = 12, + .duty_cycle = 50, + }}}; + +const FuriHalRegion furi_hal_region_jp = { + .country_code = "JP", + .bands_count = 2, + .bands = { + { + .start = 312000000, + .end = 315250000, + .power_limit = 12, + .duty_cycle = 50, + }, + { + .start = 920500000, + .end = 923500000, + .power_limit = 12, + .duty_cycle = 50, + }}}; + static const FuriHalRegion* furi_hal_region = NULL; +void furi_hal_region_init() { + FuriHalVersionRegion region = furi_hal_version_get_hw_region_otp(); + + if(region == FuriHalVersionRegionUnknown) { + furi_hal_region = &furi_hal_region_zero; + } else if(region == FuriHalVersionRegionEuRu) { + furi_hal_region = &furi_hal_region_eu_ru; + } else if(region == FuriHalVersionRegionUsCaAu) { + furi_hal_region = &furi_hal_region_us_ca_au; + } else if(region == FuriHalVersionRegionJp) { + furi_hal_region = &furi_hal_region_jp; + } +} + const FuriHalRegion* furi_hal_region_get() { - return &furi_hal_region_zero; + return furi_hal_region; } void furi_hal_region_set(FuriHalRegion* region) { - UNUSED(region); + furi_hal_region = region; } const FuriHalRegionBand* furi_hal_region_get_band(uint32_t frequency) { - furi_hal_region = &furi_hal_region_zero; if(!furi_hal_region) { return NULL; } @@ -40,14 +111,26 @@ const FuriHalRegionBand* furi_hal_region_get_band(uint32_t frequency) { } bool furi_hal_region_is_frequency_allowed(uint32_t frequency) { - UNUSED(frequency); + if(!furi_hal_region) { + return false; + } + + const FuriHalRegionBand* band = furi_hal_region_get_band(frequency); + if(!band) { + return false; + } + return true; } bool furi_hal_region_is_provisioned() { - return true; + return furi_hal_region != NULL; } const char* furi_hal_region_get_name() { - return "00"; + if(furi_hal_region) { + return furi_hal_region->country_code; + } else { + return "--"; + } } diff --git a/targets/f7/furi_hal/furi_hal_subghz.c b/targets/f7/furi_hal/furi_hal_subghz.c index 765730df06..cf57927fc4 100644 --- a/targets/f7/furi_hal/furi_hal_subghz.c +++ b/targets/f7/furi_hal/furi_hal_subghz.c @@ -8,6 +8,7 @@ #include #include #include +#include #include @@ -54,6 +55,7 @@ typedef struct { int8_t rolling_counter_mult; bool ext_power_amp : 1; bool extended_frequency_i : 1; + bool bypass_regio : 1; } FuriHalSubGhz; volatile FuriHalSubGhz furi_hal_subghz = { @@ -63,6 +65,7 @@ volatile FuriHalSubGhz furi_hal_subghz = { .rolling_counter_mult = 1, .ext_power_amp = false, .extended_frequency_i = false, + .bypass_regio = false, }; int8_t furi_hal_subghz_get_rolling_counter_mult(void) { @@ -77,6 +80,10 @@ void furi_hal_subghz_set_extended_frequency(bool state_i) { furi_hal_subghz.extended_frequency_i = state_i; } +void furi_hal_subghz_set_bypass_regio(bool enabled) { + furi_hal_subghz.bypass_regio = enabled; +} + void furi_hal_subghz_set_ext_power_amp(bool enabled) { furi_hal_subghz.ext_power_amp = enabled; } @@ -355,7 +362,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(uint32_t value) { +bool furi_hal_subghz_is_frequency_valid_extended(uint32_t value) { if(!(value >= 281000000 && value <= 361000000) && !(value >= 378000000 && value <= 481000000) && !(value >= 749000000 && value <= 962000000)) { @@ -365,6 +372,17 @@ bool furi_hal_subghz_is_frequency_valid(uint32_t value) { return true; } +// "safe" frequency range +bool furi_hal_subghz_is_frequency_valid(uint32_t value) { + 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; + } + + 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); @@ -382,21 +400,35 @@ 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_regio = furi_hal_subghz.bypass_regio; - 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 extended range"); - return false; - } + bool allowed = false; - return true; + do { + if(bypass_regio) { + 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; + } + + if(!furi_hal_region_is_frequency_allowed(value)) { + FURI_LOG_I(TAG, "Frequency blocked - outside region"); + break; + } + } + + allowed = true; + } while(false); + + return allowed; } 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 b901e85ea4..631404f398 100644 --- a/targets/f7/furi_hal/furi_hal_subghz.h +++ b/targets/f7/furi_hal/furi_hal_subghz.h @@ -287,6 +287,8 @@ void furi_hal_subghz_set_ext_power_amp(bool enabled); bool furi_hal_subghz_get_ext_power_amp(); +void furi_hal_subghz_set_bypass_regio(bool enabled); + #ifdef __cplusplus } #endif diff --git a/targets/furi_hal_include/furi_hal_region.h b/targets/furi_hal_include/furi_hal_region.h index 9586d51ed7..ddc8a6a430 100644 --- a/targets/furi_hal_include/furi_hal_region.h +++ b/targets/furi_hal_include/furi_hal_region.h @@ -21,6 +21,9 @@ typedef struct { FuriHalRegionBand bands[]; } FuriHalRegion; +/** Initialize region */ +void furi_hal_region_init(); + /** Get Region Data. * * Region data may be allocated in Flash or in RAM.