Skip to content

Commit

Permalink
Restrict only on TX
Browse files Browse the repository at this point in the history
  • Loading branch information
Willy-JL committed Mar 20, 2024
1 parent 944cee1 commit 023223d
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 54 deletions.
4 changes: 2 additions & 2 deletions applications/main/momentum_app/momentum_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
1 change: 0 additions & 1 deletion targets/f7/api_symbols.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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*
Expand Down
7 changes: 6 additions & 1 deletion targets/f7/furi_hal/furi_hal_region.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions targets/f7/furi_hal/furi_hal_region_i.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

#include <stdint.h>

bool _furi_hal_region_is_frequency_allowed(uint32_t frequency);
70 changes: 23 additions & 47 deletions targets/f7/furi_hal/furi_hal_subghz.c
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
#include <furi_hal_subghz.h>
#include <lib/subghz/devices/cc1101_configs.h>

#include <furi_hal_region_i.h>
#include <furi_hal_version.h>
#include <furi_hal_rtc.h>
#include <furi_hal_spi.h>
#include <furi_hal_cortex.h>
#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 @@ -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)) {
Expand All @@ -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);
Expand All @@ -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) {
Expand Down
2 changes: 0 additions & 2 deletions targets/f7/furi_hal/furi_hal_subghz.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down

0 comments on commit 023223d

Please sign in to comment.