Skip to content

Commit 56de0a3

Browse files
ajayparidacarlescufi
authored andcommitted
net: mgmt: Provide Regulatory channel info
Updated to provide regulatory channel information along with country code. Signed-off-by: Ajay Parida <ajay.parida@nordicsemi.no>
1 parent 0a26da9 commit 56de0a3

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

include/zephyr/net/wifi_mgmt.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,22 @@ enum wifi_mgmt_op {
548548
WIFI_MGMT_SET = 1,
549549
};
550550

551+
#define MAX_REG_CHAN_NUM 42
552+
553+
/** Per-channel regulatory attributes */
554+
struct wifi_reg_chan_info {
555+
/** Center frequency in MHz */
556+
unsigned short center_frequency;
557+
/** Maximum transmission power (in dBm) */
558+
unsigned short max_power:8;
559+
/** Is channel supported or not */
560+
unsigned short supported:1;
561+
/** Passive transmissions only */
562+
unsigned short passive_only:1;
563+
/** Is a DFS channel */
564+
unsigned short dfs:1;
565+
} __packed;
566+
551567
/** Regulatory domain information or configuration */
552568
struct wifi_reg_domain {
553569
/* Regulatory domain operation */
@@ -556,6 +572,10 @@ struct wifi_reg_domain {
556572
bool force;
557573
/** Country code: ISO/IEC 3166-1 alpha-2 */
558574
uint8_t country_code[WIFI_COUNTRY_CODE_LEN];
575+
/** Number of channels supported */
576+
unsigned int num_channels;
577+
/** Channels information */
578+
struct wifi_reg_chan_info *chan_info;
559579
};
560580

561581
/** Wi-Fi TWT sleep states */

subsys/net/l2/wifi/wifi_shell.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ static struct {
6565
static uint32_t scan_result;
6666

6767
static struct net_mgmt_event_callback wifi_shell_mgmt_cb;
68+
static struct wifi_reg_chan_info chan_info[MAX_REG_CHAN_NUM];
6869

6970
static K_MUTEX_DEFINE(wifi_ap_sta_list_lock);
7071
struct wifi_ap_sta_node {
@@ -135,7 +136,6 @@ static void handle_wifi_scan_result(struct net_mgmt_event_callback *cb)
135136
wifi_mfp_txt(entry->mfp));
136137
}
137138

138-
#ifdef CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS
139139
static int wifi_freq_to_channel(int frequency)
140140
{
141141
int channel = 0;
@@ -157,6 +157,7 @@ static int wifi_freq_to_channel(int frequency)
157157
return channel;
158158
}
159159

160+
#ifdef CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS
160161
static enum wifi_frequency_bands wifi_freq_to_band(int frequency)
161162
{
162163
enum wifi_frequency_bands band = WIFI_FREQ_BAND_2_4_GHZ;
@@ -1295,9 +1296,10 @@ static int cmd_wifi_reg_domain(const struct shell *sh, size_t argc,
12951296
{
12961297
struct net_if *iface = net_if_get_first_wifi();
12971298
struct wifi_reg_domain regd = {0};
1298-
int ret;
1299+
int ret, chan_idx = 0;
12991300

13001301
if (argc == 1) {
1302+
(&regd)->chan_info = &chan_info[0];
13011303
regd.oper = WIFI_MGMT_GET;
13021304
} else if (argc >= 2 && argc <= 3) {
13031305
regd.oper = WIFI_MGMT_SET;
@@ -1342,6 +1344,19 @@ static int cmd_wifi_reg_domain(const struct shell *sh, size_t argc,
13421344
if (regd.oper == WIFI_MGMT_GET) {
13431345
shell_fprintf(sh, SHELL_NORMAL, "Wi-Fi Regulatory domain is: %c%c\n",
13441346
regd.country_code[0], regd.country_code[1]);
1347+
shell_fprintf(sh, SHELL_NORMAL,
1348+
"<channel>\t<center frequency>\t<supported(y/n)>\t"
1349+
"<max power(dBm)>\t<passive scan supported(y/n)>\t<dfs supported(y/n)>\n");
1350+
for (chan_idx = 0; chan_idx < regd.num_channels; chan_idx++) {
1351+
shell_fprintf(sh, SHELL_NORMAL,
1352+
" %d\t\t\t\%d\t\t\t\%s\t\t\t%d\t\t\t%s\t\t\t\t%s\n",
1353+
wifi_freq_to_channel(chan_info[chan_idx].center_frequency),
1354+
chan_info[chan_idx].center_frequency,
1355+
chan_info[chan_idx].supported ? "y" : "n",
1356+
chan_info[chan_idx].max_power,
1357+
chan_info[chan_idx].passive_only ? "y" : "n",
1358+
chan_info[chan_idx].dfs ? "y" : "n");
1359+
}
13451360
} else {
13461361
shell_fprintf(sh, SHELL_NORMAL, "Wi-Fi Regulatory domain set to: %c%c\n",
13471362
regd.country_code[0], regd.country_code[1]);

0 commit comments

Comments
 (0)