Skip to content

Commit

Permalink
Subghz: brought back manual region bypass
Browse files Browse the repository at this point in the history
  • Loading branch information
Sil333033 committed Mar 18, 2024
1 parent bec4947 commit cef63f4
Show file tree
Hide file tree
Showing 10 changed files with 165 additions and 21 deletions.
3 changes: 3 additions & 0 deletions applications/main/momentum_app/momentum_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions applications/main/momentum_app/momentum_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
enum VarItemListIndex {
VarItemListIndexSubghzFreqs,
VarItemListIndexSubghzExtend,
VarItemListIndexSubghzBypass,
VarItemListIndexGpioPins,
};

Expand All @@ -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);
Expand All @@ -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, ">");

Expand Down
3 changes: 3 additions & 0 deletions applications/main/subghz/subghz_extended_freq.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion targets/f7/api_symbols.csv
Original file line number Diff line number Diff line change
@@ -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,,
Expand Down Expand Up @@ -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*
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions targets/f7/furi_hal/furi_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
95 changes: 89 additions & 6 deletions targets/f7/furi_hal/furi_hal_region.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <furi_hal_region.h>
#include <furi_hal_version.h>
#include <furi.h>

const FuriHalRegion furi_hal_region_zero = {
Expand All @@ -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;
}
Expand All @@ -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 "--";
}
}
60 changes: 46 additions & 14 deletions targets/f7/furi_hal/furi_hal_subghz.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <furi_hal_interrupt.h>
#include <furi_hal_resources.h>
#include <furi_hal_bus.h>
#include <furi_hal_region.h>

#include <stm32wbxx_ll_dma.h>

Expand Down Expand Up @@ -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 = {
Expand All @@ -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) {
Expand All @@ -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;
}
Expand Down Expand Up @@ -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)) {
Expand All @@ -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);
Expand All @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions targets/f7/furi_hal/furi_hal_subghz.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions targets/furi_hal_include/furi_hal_region.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit cef63f4

Please sign in to comment.