Skip to content

Commit b4c8f2b

Browse files
authored
Fix 40 MHz bandwidth mode (#8)
1 parent d2578cd commit b4c8f2b

File tree

1 file changed

+35
-5
lines changed

1 file changed

+35
-5
lines changed

src/RadioManagementModule.cpp

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,42 @@
55
#include <chrono>
66
#include <map>
77
#include <thread>
8+
#include <unordered_map>
89
#include <vector>
910

11+
namespace {
12+
13+
int get_40mhz_center_channel(int channel) {
14+
static const std::unordered_map<int, int> channel_map = {
15+
// 2.4GHz 40MHz configuration: only one valid center channel (6)
16+
{4, 6}, // primary below center (extension above)
17+
{8, 6}, // primary above center (extension below)
18+
19+
// 5GHz UNII-1
20+
{36, 38}, {40, 38},
21+
// 5GHz UNII-1 / UNII-2
22+
{44, 46}, {48, 46},
23+
// 5GHz UNII-2A
24+
{52, 54}, {56, 54}, {60, 62}, {64, 62},
25+
// 5GHz UNII-2C
26+
{100, 102}, {104, 102},
27+
{108, 110}, {112, 110},
28+
{116, 118}, {120, 118},
29+
{124, 126}, {128, 126},
30+
// 5GHz UNII-2E (if applicable)
31+
{132, 134}, {136, 134},
32+
{140, 142}, {144, 142},
33+
// 5GHz UNII-3
34+
{149, 151}, {153, 151},
35+
{157, 159}, {161, 159}
36+
};
37+
38+
auto it = channel_map.find(channel);
39+
return (it != channel_map.end()) ? it->second : channel;
40+
}
41+
42+
}
43+
1044
RadioManagementModule::RadioManagementModule(
1145
RtlUsbAdapter device, std::shared_ptr<EepromManager> eepromManager,
1246
Logger_t logger)
@@ -89,11 +123,7 @@ static uint8_t rtw_get_center_ch(uint8_t channel, ChannelWidth_t chnl_bw,
89123
else if (channel <= 14)
90124
center_ch = 7;
91125
} else if (chnl_bw == ChannelWidth_t::CHANNEL_WIDTH_40) {
92-
if (chnl_offset == HAL_PRIME_CHNL_OFFSET_LOWER) {
93-
center_ch = (uint8_t)(channel + 2);
94-
} else {
95-
center_ch = (uint8_t)(channel - 2);
96-
}
126+
center_ch = get_40mhz_center_channel(center_ch);
97127
} else if (chnl_bw == ChannelWidth_t::CHANNEL_WIDTH_20) {
98128
center_ch = channel;
99129
} else {

0 commit comments

Comments
 (0)