2022-08-11 09:21:56 +00:00
|
|
|
#include <furi_hal_region.h>
|
|
|
|
#include <furi_hal_version.h>
|
2024-03-19 14:43:52 +00:00
|
|
|
#include <furi.h>
|
2022-08-11 09:21:56 +00:00
|
|
|
|
|
|
|
const FuriHalRegion furi_hal_region_zero = {
|
|
|
|
.country_code = "00",
|
|
|
|
.bands_count = 1,
|
|
|
|
.bands = {
|
|
|
|
{
|
|
|
|
.start = 0,
|
|
|
|
.end = 1000000000,
|
|
|
|
.power_limit = 12,
|
|
|
|
.duty_cycle = 50,
|
|
|
|
},
|
|
|
|
}};
|
|
|
|
|
|
|
|
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,
|
|
|
|
}}};
|
|
|
|
|
2024-08-04 09:54:02 +00:00
|
|
|
static const FuriHalRegion* const furi_hal_static_regions[] = {
|
|
|
|
[FuriHalVersionRegionUnknown] = &furi_hal_region_zero,
|
|
|
|
[FuriHalVersionRegionEuRu] = &furi_hal_region_eu_ru,
|
|
|
|
[FuriHalVersionRegionUsCaAu] = &furi_hal_region_us_ca_au,
|
|
|
|
[FuriHalVersionRegionJp] = &furi_hal_region_jp,
|
|
|
|
};
|
|
|
|
|
|
|
|
static FuriHalRegion* furi_hal_dynamic_region;
|
|
|
|
static FuriMutex* furi_hal_dynamic_region_mutex;
|
2022-08-11 09:21:56 +00:00
|
|
|
|
2024-03-19 14:43:52 +00:00
|
|
|
void furi_hal_region_init(void) {
|
2024-08-04 09:54:02 +00:00
|
|
|
furi_assert(furi_hal_dynamic_region_mutex == NULL);
|
|
|
|
furi_hal_dynamic_region_mutex = furi_mutex_alloc(FuriMutexTypeNormal);
|
2022-08-11 09:21:56 +00:00
|
|
|
}
|
|
|
|
|
2024-03-19 14:43:52 +00:00
|
|
|
const FuriHalRegion* furi_hal_region_get(void) {
|
2024-08-04 09:54:02 +00:00
|
|
|
const FuriHalVersionRegion region = furi_hal_version_get_hw_region();
|
|
|
|
const FuriHalRegion* ret;
|
|
|
|
|
|
|
|
furi_check(furi_mutex_acquire(furi_hal_dynamic_region_mutex, FuriWaitForever) == FuriStatusOk);
|
|
|
|
|
|
|
|
if(region < FuriHalVersionRegionWorld && furi_hal_dynamic_region == NULL) {
|
|
|
|
ret = furi_hal_static_regions[region];
|
|
|
|
} else {
|
|
|
|
ret = furi_hal_dynamic_region;
|
|
|
|
}
|
|
|
|
|
|
|
|
furi_check(furi_mutex_release(furi_hal_dynamic_region_mutex) == FuriStatusOk);
|
|
|
|
|
|
|
|
return ret;
|
2022-08-11 09:21:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void furi_hal_region_set(FuriHalRegion* region) {
|
2024-03-19 14:43:52 +00:00
|
|
|
furi_check(region);
|
|
|
|
|
2024-08-04 09:54:02 +00:00
|
|
|
furi_check(furi_mutex_acquire(furi_hal_dynamic_region_mutex, FuriWaitForever) == FuriStatusOk);
|
|
|
|
|
|
|
|
if(furi_hal_dynamic_region) {
|
|
|
|
free(furi_hal_dynamic_region);
|
|
|
|
}
|
|
|
|
|
|
|
|
furi_hal_dynamic_region = region;
|
|
|
|
|
|
|
|
furi_check(furi_mutex_release(furi_hal_dynamic_region_mutex) == FuriStatusOk);
|
2022-08-11 09:21:56 +00:00
|
|
|
}
|
|
|
|
|
2024-03-19 14:43:52 +00:00
|
|
|
bool furi_hal_region_is_provisioned(void) {
|
2024-08-04 09:54:02 +00:00
|
|
|
return furi_hal_region_get() != NULL;
|
2022-08-11 09:21:56 +00:00
|
|
|
}
|
|
|
|
|
2024-03-19 14:43:52 +00:00
|
|
|
const char* furi_hal_region_get_name(void) {
|
2024-08-04 09:54:02 +00:00
|
|
|
const FuriHalRegion* region = furi_hal_region_get();
|
|
|
|
|
|
|
|
if(region) {
|
|
|
|
return region->country_code;
|
2022-08-11 09:21:56 +00:00
|
|
|
} else {
|
|
|
|
return "--";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool furi_hal_region_is_frequency_allowed(uint32_t frequency) {
|
2024-08-04 09:54:02 +00:00
|
|
|
return furi_hal_region_get_band(frequency) != NULL;
|
2022-08-11 09:21:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const FuriHalRegionBand* furi_hal_region_get_band(uint32_t frequency) {
|
2024-08-04 09:54:02 +00:00
|
|
|
const FuriHalRegion* region = furi_hal_region_get();
|
|
|
|
|
|
|
|
if(!region) {
|
2022-08-11 09:21:56 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2024-08-04 09:54:02 +00:00
|
|
|
for(size_t i = 0; i < region->bands_count; i++) {
|
|
|
|
if(region->bands[i].start <= frequency && region->bands[i].end >= frequency) {
|
|
|
|
return ®ion->bands[i];
|
2022-08-11 09:21:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|