Skip to content

Commit 736056e

Browse files
committed
[nrf fromtree] drivers: nrfwifi: Fix regulatory domain regression
Recent WPA supplicant changes have broken nRF regulatory support, implement the new set/get country WPA supplicant ops. WPA supplicant: Regulatory SET through WPA supplicant, GET is direct to the driver Scan only: SET and GET direct calls to the driver Fixes #79916. Signed-off-by: Chaitanya Tata <[email protected]> (cherry picked from commit 2ea25ea)
1 parent 25f14b4 commit 736056e

File tree

3 files changed

+106
-46
lines changed

3 files changed

+106
-46
lines changed

drivers/wifi/nrfwifi/inc/wpa_supp_if.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ int nrf_wifi_supp_get_conn_info(void *if_priv, struct wpa_conn_info *info);
123123
void nrf_wifi_supp_event_proc_get_conn_info(void *os_vif_ctx,
124124
struct nrf_wifi_umac_event_conn_info *info,
125125
unsigned int event_len);
126+
int nrf_wifi_supp_set_country(void *if_priv, const char *alpha2);
127+
int nrf_wifi_supp_get_country(void *if_priv, char *alpha2);
126128

127129
#endif /* CONFIG_NRF70_STA_MODE */
128130
#ifdef CONFIG_NRF70_AP_MODE

drivers/wifi/nrfwifi/src/fmac_main.c

Lines changed: 31 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -343,28 +343,8 @@ int nrf_wifi_reg_domain(const struct device *dev, struct wifi_reg_domain *reg_do
343343
goto err;
344344
}
345345

346+
#ifdef CONFIG_NRF70_SCAN_ONLY
346347
if (reg_domain->oper == WIFI_MGMT_SET) {
347-
#ifndef CONFIG_NRF70_RADIO_TEST
348-
#ifdef CONFIG_NRF70_STA_MODE
349-
/* Need to check if WPA supplicant is initialized or not.
350-
* Must be checked when CONFIG_WIFI_NM_WPA_SUPPLICANT is enabled.
351-
* Not applicable for RADIO_TEST or when
352-
* CONFIG_WIFI_NM_WPA_SUPPLICANT is not enabled.
353-
*/
354-
/* It is possbile that during supplicant initialization driver may
355-
* get the command. lock will try to ensure that supplicant
356-
* initialization is complete.
357-
*/
358-
k_mutex_lock(&vif_ctx_zep->vif_lock, K_FOREVER);
359-
if ((!vif_ctx_zep->supp_drv_if_ctx) ||
360-
(!wifi_nm_get_instance_iface(vif_ctx_zep->zep_net_if_ctx))) {
361-
LOG_ERR("%s: WPA supplicant initialization not complete yet", __func__);
362-
k_mutex_unlock(&vif_ctx_zep->vif_lock);
363-
goto err;
364-
}
365-
k_mutex_unlock(&vif_ctx_zep->vif_lock);
366-
#endif /* CONFIG_NRF70_STA_MODE */
367-
#endif /* !CONFIG_NRF70_RADIO_TEST */
368348
memcpy(reg_domain_info.alpha2, reg_domain->country_code, WIFI_COUNTRY_CODE_LEN);
369349

370350
reg_domain_info.force = reg_domain->force;
@@ -374,36 +354,39 @@ int nrf_wifi_reg_domain(const struct device *dev, struct wifi_reg_domain *reg_do
374354
LOG_ERR("%s: Failed to set regulatory domain", __func__);
375355
goto err;
376356
}
377-
} else if (reg_domain->oper == WIFI_MGMT_GET) {
378357

379-
if (!reg_domain->chan_info) {
380-
LOG_ERR("%s: Invalid regulatory info (NULL)\n", __func__);
381-
goto err;
382-
}
358+
goto err;
359+
}
360+
#endif
361+
if (reg_domain->oper != WIFI_MGMT_GET) {
362+
LOG_ERR("%s: Invalid operation: %d", __func__, reg_domain->oper);
363+
goto err;
364+
}
383365

384-
status = nrf_wifi_fmac_get_reg(fmac_dev_ctx, &reg_domain_info);
385-
if (status != NRF_WIFI_STATUS_SUCCESS) {
386-
LOG_ERR("%s: Failed to get regulatory domain", __func__);
387-
goto err;
388-
}
366+
if (!reg_domain->chan_info) {
367+
LOG_ERR("%s: Invalid regulatory info (NULL)\n", __func__);
368+
goto err;
369+
}
389370

390-
memcpy(reg_domain->country_code, reg_domain_info.alpha2, WIFI_COUNTRY_CODE_LEN);
391-
reg_domain->num_channels = reg_domain_info.reg_chan_count;
392-
393-
for (chan_idx = 0; chan_idx < reg_domain_info.reg_chan_count; chan_idx++) {
394-
chan_info = &(reg_domain->chan_info[chan_idx]);
395-
reg_domain_chan_info = &(reg_domain_info.reg_chan_info[chan_idx]);
396-
chan_info->center_frequency = reg_domain_chan_info->center_frequency;
397-
chan_info->dfs = !!reg_domain_chan_info->dfs;
398-
chan_info->max_power = reg_domain_chan_info->max_power;
399-
chan_info->passive_only = !!reg_domain_chan_info->passive_channel;
400-
chan_info->supported = !!reg_domain_chan_info->supported;
401-
}
402-
} else {
403-
LOG_ERR("%s: Invalid operation: %d", __func__, reg_domain->oper);
371+
status = nrf_wifi_fmac_get_reg(fmac_dev_ctx, &reg_domain_info);
372+
if (status != NRF_WIFI_STATUS_SUCCESS) {
373+
LOG_ERR("%s: Failed to get regulatory domain", __func__);
404374
goto err;
405375
}
406376

377+
memcpy(reg_domain->country_code, reg_domain_info.alpha2, WIFI_COUNTRY_CODE_LEN);
378+
reg_domain->num_channels = reg_domain_info.reg_chan_count;
379+
380+
for (chan_idx = 0; chan_idx < reg_domain_info.reg_chan_count; chan_idx++) {
381+
chan_info = &(reg_domain->chan_info[chan_idx]);
382+
reg_domain_chan_info = &(reg_domain_info.reg_chan_info[chan_idx]);
383+
chan_info->center_frequency = reg_domain_chan_info->center_frequency;
384+
chan_info->dfs = !!reg_domain_chan_info->dfs;
385+
chan_info->max_power = reg_domain_chan_info->max_power;
386+
chan_info->passive_only = !!reg_domain_chan_info->passive_channel;
387+
chan_info->supported = !!reg_domain_chan_info->supported;
388+
}
389+
407390
ret = 0;
408391
err:
409392
k_mutex_unlock(&reg_lock);
@@ -850,7 +833,7 @@ static struct wifi_mgmt_ops nrf_wifi_mgmt_ops = {
850833
.get_power_save_config = nrf_wifi_get_power_save_config,
851834
.set_rts_threshold = nrf_wifi_set_rts_threshold,
852835
.get_rts_threshold = nrf_wifi_get_rts_threshold,
853-
#endif /* CONFIG_NRF70_STA_MODE */
836+
#endif
854837
#ifdef CONFIG_NRF70_SYSTEM_WITH_RAW_MODES
855838
.mode = nrf_wifi_mode,
856839
#endif
@@ -883,6 +866,8 @@ static struct zep_wpa_supp_dev_ops wpa_supp_ops = {
883866
.register_frame = nrf_wifi_supp_register_frame,
884867
.get_capa = nrf_wifi_supp_get_capa,
885868
.get_conn_info = nrf_wifi_supp_get_conn_info,
869+
.set_country = nrf_wifi_supp_set_country,
870+
.get_country = nrf_wifi_supp_get_country,
886871
#ifdef CONFIG_NRF70_AP_MODE
887872
.init_ap = nrf_wifi_wpa_supp_init_ap,
888873
.start_ap = nrf_wifi_wpa_supp_start_ap,

drivers/wifi/nrfwifi/src/wpa_supp_if.c

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,6 +1861,79 @@ int nrf_wifi_supp_get_conn_info(void *if_priv, struct wpa_conn_info *info)
18611861
return ret;
18621862
}
18631863

1864+
int nrf_wifi_supp_set_country(void *if_priv, const char *alpha2)
1865+
{
1866+
struct nrf_wifi_vif_ctx_zep *vif_ctx_zep = NULL;
1867+
struct nrf_wifi_ctx_zep *rpu_ctx_zep = NULL;
1868+
enum nrf_wifi_status status = NRF_WIFI_STATUS_FAIL;
1869+
struct nrf_wifi_fmac_reg_info reg_domain_info = {0};
1870+
1871+
if (!if_priv || !alpha2) {
1872+
LOG_ERR("%s: Invalid params", __func__);
1873+
return -1;
1874+
}
1875+
1876+
vif_ctx_zep = if_priv;
1877+
rpu_ctx_zep = vif_ctx_zep->rpu_ctx_zep;
1878+
if (!rpu_ctx_zep) {
1879+
LOG_ERR("%s: rpu_ctx_zep is NULL", __func__);
1880+
return -1;
1881+
}
1882+
1883+
k_mutex_lock(&vif_ctx_zep->vif_lock, K_FOREVER);
1884+
if (!rpu_ctx_zep->rpu_ctx) {
1885+
LOG_DBG("%s: RPU context not initialized", __func__);
1886+
goto out;
1887+
}
1888+
1889+
memcpy(reg_domain_info.alpha2, alpha2, NRF_WIFI_COUNTRY_CODE_LEN);
1890+
1891+
status = nrf_wifi_fmac_set_reg(rpu_ctx_zep->rpu_ctx, &reg_domain_info);
1892+
if (status != NRF_WIFI_STATUS_SUCCESS) {
1893+
LOG_ERR("%s: nrf_wifi_fmac_set_reg failed", __func__);
1894+
goto out;
1895+
}
1896+
out:
1897+
k_mutex_unlock(&vif_ctx_zep->vif_lock);
1898+
return status;
1899+
}
1900+
1901+
int nrf_wifi_supp_get_country(void *if_priv, char *alpha2)
1902+
{
1903+
struct nrf_wifi_vif_ctx_zep *vif_ctx_zep = NULL;
1904+
struct nrf_wifi_ctx_zep *rpu_ctx_zep = NULL;
1905+
enum nrf_wifi_status status = NRF_WIFI_STATUS_FAIL;
1906+
struct nrf_wifi_fmac_reg_info reg_domain_info = {0};
1907+
1908+
if (!if_priv || !alpha2) {
1909+
LOG_ERR("%s: Invalid params", __func__);
1910+
return -1;
1911+
}
1912+
1913+
vif_ctx_zep = if_priv;
1914+
rpu_ctx_zep = vif_ctx_zep->rpu_ctx_zep;
1915+
if (!rpu_ctx_zep) {
1916+
LOG_ERR("%s: rpu_ctx_zep is NULL", __func__);
1917+
return -1;
1918+
}
1919+
1920+
k_mutex_lock(&vif_ctx_zep->vif_lock, K_FOREVER);
1921+
if (!rpu_ctx_zep->rpu_ctx) {
1922+
LOG_DBG("%s: RPU context not initialized", __func__);
1923+
goto out;
1924+
}
1925+
1926+
status = nrf_wifi_fmac_get_reg(rpu_ctx_zep->rpu_ctx, &reg_domain_info);
1927+
if (status != NRF_WIFI_STATUS_SUCCESS) {
1928+
LOG_ERR("%s: nrf_wifi_fmac_get_reg failed", __func__);
1929+
goto out;
1930+
}
1931+
1932+
memcpy(alpha2, reg_domain_info.alpha2, NRF_WIFI_COUNTRY_CODE_LEN);
1933+
out:
1934+
k_mutex_unlock(&vif_ctx_zep->vif_lock);
1935+
return status;
1936+
}
18641937

18651938
void nrf_wifi_supp_event_proc_get_conn_info(void *if_priv,
18661939
struct nrf_wifi_umac_event_conn_info *info,

0 commit comments

Comments
 (0)