From f9472effe38abe37f8e731cb648897d99226fefe Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Tue, 20 Jun 2023 11:02:14 +0300 Subject: [PATCH] Now really block transmission at dangerous freq --- .../drivers/subghz/cc1101_ext/cc1101_ext.c | 27 +++++++++++++++---- .../targets/f7/furi_hal/furi_hal_subghz.c | 12 ++++----- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/applications/drivers/subghz/cc1101_ext/cc1101_ext.c b/applications/drivers/subghz/cc1101_ext/cc1101_ext.c index b4e7e9eee..acce0989d 100644 --- a/applications/drivers/subghz/cc1101_ext/cc1101_ext.c +++ b/applications/drivers/subghz/cc1101_ext/cc1101_ext.c @@ -1,7 +1,6 @@ #include "cc1101_ext.h" #include -#include #include #include #include @@ -19,6 +18,7 @@ #define TAG "SubGhz_Device_CC1101_Ext" #define SUBGHZ_DEVICE_CC1101_EXT_TX_GPIO &gpio_ext_pb2 +#define SUBGHZ_DEVICE_CC1101_EXT_DANGEROUS_RANGE false /* DMA Channels definition */ #define SUBGHZ_DEVICE_CC1101_EXT_DMA DMA2 @@ -428,9 +428,26 @@ uint8_t subghz_device_cc1101_ext_get_lqi() { } bool subghz_device_cc1101_ext_is_frequency_valid(uint32_t value) { - if(!(value >= 299999755 && value <= 348000335) && - !(value >= 386999938 && value <= 464000000) && + if(!(value >= 281000000 && value <= 361000000) && + !(value >= 378000000 && value <= 481000000) && + !(value >= 749000000 && value <= 962000000)) { + return false; + } + + return true; +} + +bool subghz_device_cc1101_ext_is_tx_allowed(uint32_t value) { + if(!(SUBGHZ_DEVICE_CC1101_EXT_DANGEROUS_RANGE) && + !(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( + (SUBGHZ_DEVICE_CC1101_EXT_DANGEROUS_RANGE) && + !subghz_device_cc1101_ext_is_frequency_valid(value)) { + FURI_LOG_I(TAG, "Frequency blocked - outside dangerous range"); return false; } @@ -438,10 +455,10 @@ bool subghz_device_cc1101_ext_is_frequency_valid(uint32_t value) { } uint32_t subghz_device_cc1101_ext_set_frequency(uint32_t value) { - if(furi_hal_region_is_frequency_allowed(value)) { + if(subghz_device_cc1101_ext_is_tx_allowed(value)) { subghz_device_cc1101_ext->regulation = SubGhzDeviceCC1101ExtRegulationTxRx; } else { - subghz_device_cc1101_ext->regulation = SubGhzDeviceCC1101ExtRegulationOnlyRx; + subghz_device_cc1101_ext->regulation = SubGhzDeviceCC1101ExtRegulationTxRx; } furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle); diff --git a/firmware/targets/f7/furi_hal/furi_hal_subghz.c b/firmware/targets/f7/furi_hal/furi_hal_subghz.c index d6b08d7b7..dc26cffb5 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_subghz.c +++ b/firmware/targets/f7/furi_hal/furi_hal_subghz.c @@ -10,8 +10,6 @@ #include -#include // TODO - #include #include #include @@ -390,9 +388,7 @@ bool furi_hal_subghz_is_tx_allowed(uint32_t value) { return false; } else if( (allow_extended_for_int) && // - !(value >= 281000000 && value <= 361000000) && - !(value >= 378000000 && value <= 481000000) && - !(value >= 749000000 && value <= 962000000)) { + !furi_hal_subghz_is_frequency_valid(value)) { FURI_LOG_I(TAG, "Frequency blocked - outside dangerous range"); return false; } @@ -401,7 +397,11 @@ bool furi_hal_subghz_is_tx_allowed(uint32_t value) { } uint32_t furi_hal_subghz_set_frequency(uint32_t value) { - furi_hal_subghz.regulation = SubGhzRegulationTxRx; + if(furi_hal_subghz_is_tx_allowed(value)) { + furi_hal_subghz.regulation = SubGhzRegulationTxRx; + } else { + furi_hal_subghz.regulation = SubGhzRegulationOnlyRx; + } furi_hal_spi_acquire(&furi_hal_spi_bus_handle_subghz); uint32_t real_frequency = cc1101_set_frequency(&furi_hal_spi_bus_handle_subghz, value);