Skip to content

Commit

Permalink
[FL-1590] SubGhz: fix incorrect limits on frequency that were causing…
Browse files Browse the repository at this point in the history
… crashes #607
  • Loading branch information
skotopes committed Jul 30, 2021
1 parent 0c7a8ed commit 0bc3828
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 22 deletions.
29 changes: 10 additions & 19 deletions applications/subghz/subghz_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,8 @@
#include <stream_buffer.h>
#include <lib/subghz/protocols/subghz_protocol.h>

#define CC1101_FREQUENCY_RANGE_STR \
"300000000...348000000 or 387000000...464000000 or 779000000...928000000"

bool subghz_check_frequency_range(uint32_t frequency) {
if(!(frequency >= 300000000 && frequency <= 348000000) &&
!(frequency >= 387000000 && frequency <= 464000000) &&
!(frequency >= 779000000 && frequency <= 928000000)) {
return false;
}
return true;
}
#define SUBGHZ_FREQUENCY_RANGE_STR \
"299999755...348000000 or 386999938...464000000 or 778999847...928000000"

void subghz_cli_init() {
Cli* cli = furi_record_open("cli");
Expand All @@ -40,9 +31,9 @@ void subghz_cli_command_tx_carrier(Cli* cli, string_t args, void* context) {
cli_print_usage("subghz_tx_carrier", "<Frequency in HZ>", string_get_cstr(args));
return;
}
if(!subghz_check_frequency_range(frequency)) {
if(!api_hal_subghz_is_frequency_valid(frequency)) {
printf(
"Frequency must be in " CC1101_FREQUENCY_RANGE_STR " range, not %lu\r\n",
"Frequency must be in " SUBGHZ_FREQUENCY_RANGE_STR " range, not %lu\r\n",
frequency);
return;
}
Expand Down Expand Up @@ -77,9 +68,9 @@ void subghz_cli_command_rx_carrier(Cli* cli, string_t args, void* context) {
cli_print_usage("subghz_tx_carrier", "<Frequency in HZ>", string_get_cstr(args));
return;
}
if(!subghz_check_frequency_range(frequency)) {
if(!api_hal_subghz_is_frequency_valid(frequency)) {
printf(
"Frequency must be in " CC1101_FREQUENCY_RANGE_STR " range, not %lu\r\n",
"Frequency must be in " SUBGHZ_FREQUENCY_RANGE_STR " range, not %lu\r\n",
frequency);
return;
}
Expand Down Expand Up @@ -127,9 +118,9 @@ void subghz_cli_command_tx(Cli* cli, string_t args, void* context) {
string_get_cstr(args));
return;
}
if(!subghz_check_frequency_range(frequency)) {
if(!api_hal_subghz_is_frequency_valid(frequency)) {
printf(
"Frequency must be in " CC1101_FREQUENCY_RANGE_STR " range, not %lu\r\n",
"Frequency must be in " SUBGHZ_FREQUENCY_RANGE_STR " range, not %lu\r\n",
frequency);
return;
}
Expand Down Expand Up @@ -209,9 +200,9 @@ void subghz_cli_command_rx(Cli* cli, string_t args, void* context) {
cli_print_usage("subghz_rx", "<Frequency in HZ>", string_get_cstr(args));
return;
}
if(!subghz_check_frequency_range(frequency)) {
if(!api_hal_subghz_is_frequency_valid(frequency)) {
printf(
"Frequency must be in " CC1101_FREQUENCY_RANGE_STR " range, not %lu\r\n",
"Frequency must be in " SUBGHZ_FREQUENCY_RANGE_STR " range, not %lu\r\n",
frequency);
return;
}
Expand Down
5 changes: 5 additions & 0 deletions firmware/targets/api-hal-include/api-hal-subghz.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ void api_hal_subghz_tx();
/** Get RSSI value in dBm */
float api_hal_subghz_get_rssi();

/** Check if frequency is in valid range
* @return true if frequncy is valid, otherwise false
*/
bool api_hal_subghz_is_frequency_valid(uint32_t value);

/** Set frequency and path
* This function automatically selects antenna matching network
* @param frequency in herz
Expand Down
15 changes: 12 additions & 3 deletions firmware/targets/f6/api-hal/api-hal-subghz.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,13 +242,22 @@ float api_hal_subghz_get_rssi() {
return rssi;
}

bool api_hal_subghz_is_frequency_valid(uint32_t value) {
if(!(value >= 299999755 && value <= 348000335) &&
!(value >= 386999938 && value <= 464000000) &&
!(value >= 778999847 && value <= 928000000)) {
return false;
}
return true;
}

uint32_t api_hal_subghz_set_frequency_and_path(uint32_t value) {
value = api_hal_subghz_set_frequency(value);
if(value >= 300000000 && value <= 348000335) {
if(value >= 299999755 && value <= 348000335) {
api_hal_subghz_set_path(ApiHalSubGhzPath315);
} else if(value >= 387000000 && value <= 464000000) {
} else if(value >= 386999938 && value <= 464000000) {
api_hal_subghz_set_path(ApiHalSubGhzPath433);
} else if(value >= 779000000 && value <= 928000000) {
} else if(value >= 778999847 && value <= 928000000) {
api_hal_subghz_set_path(ApiHalSubGhzPath868);
} else {
furi_check(0);
Expand Down

0 comments on commit 0bc3828

Please sign in to comment.