Skip to content

Commit 6cbb37d

Browse files
MaochenWang1kartben
authored andcommitted
net: l2: wifi: setting CMD only when net_if is up
Setting Wi-Fi cmd only when the net interface is up, avoid the case that driver deinit and net interface is down, then the L2 APIs interact with supplicant and driver, which may lead to CPU exception. Signed-off-by: Maochen Wang <[email protected]>
1 parent cd772b3 commit 6cbb37d

File tree

1 file changed

+113
-0
lines changed

1 file changed

+113
-0
lines changed

subsys/net/l2/wifi/wifi_mgmt.c

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,10 @@ static int wifi_connect(uint32_t mgmt_request, struct net_if *iface,
359359
return -ENOTSUP;
360360
}
361361

362+
if (!net_if_is_admin_up(iface)) {
363+
return -ENETDOWN;
364+
}
365+
362366
LOG_HEXDUMP_DBG(params->ssid, params->ssid_length, "ssid");
363367
LOG_HEXDUMP_DBG(params->psk, params->psk_length, "psk");
364368
if (params->sae_password) {
@@ -431,6 +435,10 @@ static int wifi_scan(uint32_t mgmt_request, struct net_if *iface,
431435
return -ENOTSUP;
432436
}
433437

438+
if (!net_if_is_admin_up(iface)) {
439+
return -ENETDOWN;
440+
}
441+
434442
#ifdef CONFIG_WIFI_MGMT_FORCED_PASSIVE_SCAN
435443
struct wifi_scan_params default_params = {0};
436444

@@ -455,6 +463,10 @@ static int wifi_disconnect(uint32_t mgmt_request, struct net_if *iface,
455463
return -ENOTSUP;
456464
}
457465

466+
if (!net_if_is_admin_up(iface)) {
467+
return -ENETDOWN;
468+
}
469+
458470
return wifi_mgmt_api->disconnect(dev);
459471
}
460472

@@ -492,6 +504,11 @@ static int wifi_start_roaming(uint32_t mgmt_request, struct net_if *iface,
492504
if (wifi_mgmt_api == NULL) {
493505
return -ENOTSUP;
494506
}
507+
508+
if (!net_if_is_admin_up(iface)) {
509+
return -ENETDOWN;
510+
}
511+
495512
if (roaming_params.is_11r_used) {
496513
if (wifi_mgmt_api->start_11r_roaming == NULL) {
497514
return -ENOTSUP;
@@ -528,6 +545,10 @@ static int wifi_neighbor_rep_complete(uint32_t mgmt_request, struct net_if *ifac
528545
const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_api(iface);
529546
struct wifi_scan_params params = {0};
530547

548+
if (!net_if_is_admin_up(iface)) {
549+
return -ENETDOWN;
550+
}
551+
531552
for (int i = 0; i < roaming_params.neighbor_rep.neighbor_cnt; i++) {
532553
params.band_chan[i].channel = roaming_params.neighbor_rep.neighbor_ap[i].channel;
533554
if (params.band_chan[i].channel > 14) {
@@ -624,6 +645,10 @@ static int wifi_ap_enable(uint32_t mgmt_request, struct net_if *iface,
624645
return -ENOTSUP;
625646
}
626647

648+
if (!net_if_is_admin_up(iface)) {
649+
return -ENETDOWN;
650+
}
651+
627652
return wifi_mgmt_api->ap_enable(dev, params);
628653
}
629654

@@ -639,6 +664,10 @@ static int wifi_ap_disable(uint32_t mgmt_request, struct net_if *iface,
639664
return -ENOTSUP;
640665
}
641666

667+
if (!net_if_is_admin_up(iface)) {
668+
return -ENETDOWN;
669+
}
670+
642671
return wifi_mgmt_api->ap_disable(dev);
643672
}
644673

@@ -659,6 +688,10 @@ static int wifi_ap_sta_disconnect(uint32_t mgmt_request, struct net_if *iface,
659688
return -ENOTSUP;
660689
}
661690

691+
if (!net_if_is_admin_up(iface)) {
692+
return -ENETDOWN;
693+
}
694+
662695
if (!data || len != sizeof(uint8_t) * WIFI_MAC_ADDR_LEN) {
663696
return -EINVAL;
664697
}
@@ -684,6 +717,10 @@ static int wifi_ap_config_params(uint32_t mgmt_request, struct net_if *iface,
684717
return -ENOTSUP;
685718
}
686719

720+
if (!net_if_is_admin_up(iface)) {
721+
return -ENETDOWN;
722+
}
723+
687724
if (!data || len != sizeof(*params)) {
688725
return -EINVAL;
689726
}
@@ -713,6 +750,10 @@ static int wifi_ap_set_rts_threshold(uint32_t mgmt_request, struct net_if *iface
713750
return -ENOTSUP;
714751
}
715752

753+
if (!net_if_is_admin_up(iface)) {
754+
return -ENETDOWN;
755+
}
756+
716757
if (data == NULL || len != sizeof(*rts_threshold)) {
717758
return -EINVAL;
718759
}
@@ -795,6 +836,10 @@ static int wifi_11k_cfg(uint32_t mgmt_request, struct net_if *iface,
795836
return -ENOTSUP;
796837
}
797838

839+
if (!net_if_is_admin_up(iface)) {
840+
return -ENETDOWN;
841+
}
842+
798843
#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_ROAMING
799844
if (params->oper == WIFI_MGMT_SET) {
800845
roaming_params.is_11k_enabled = params->enable_11k;
@@ -817,6 +862,10 @@ static int wifi_11k_neighbor_request(uint32_t mgmt_request, struct net_if *iface
817862
return -ENOTSUP;
818863
}
819864

865+
if (!net_if_is_admin_up(iface)) {
866+
return -ENETDOWN;
867+
}
868+
820869
return wifi_mgmt_api->send_11k_neighbor_request(dev, params);
821870
}
822871

@@ -835,6 +884,10 @@ static int wifi_set_power_save(uint32_t mgmt_request, struct net_if *iface,
835884
return -ENOTSUP;
836885
}
837886

887+
if (!net_if_is_admin_up(iface)) {
888+
return -ENETDOWN;
889+
}
890+
838891
switch (ps_params->type) {
839892
case WIFI_PS_PARAM_LISTEN_INTERVAL:
840893
case WIFI_PS_PARAM_MODE:
@@ -884,6 +937,10 @@ static int wifi_get_power_save_config(uint32_t mgmt_request, struct net_if *ifac
884937
return -ENOTSUP;
885938
}
886939

940+
if (!net_if_is_admin_up(iface)) {
941+
return -ENETDOWN;
942+
}
943+
887944
if (!data || len != sizeof(*ps_config)) {
888945
return -EINVAL;
889946
}
@@ -907,6 +964,10 @@ static int wifi_set_twt(uint32_t mgmt_request, struct net_if *iface,
907964
return -ENOTSUP;
908965
}
909966

967+
if (!net_if_is_admin_up(iface)) {
968+
return -ENETDOWN;
969+
}
970+
910971
if (twt_params->operation == WIFI_TWT_TEARDOWN) {
911972
return wifi_mgmt_api->set_twt(dev, twt_params);
912973
}
@@ -970,6 +1031,10 @@ static int wifi_set_btwt(uint32_t mgmt_request, struct net_if *iface,
9701031
return -ENOTSUP;
9711032
}
9721033

1034+
if (!net_if_is_admin_up(iface)) {
1035+
return -ENETDOWN;
1036+
}
1037+
9731038
if (net_mgmt(NET_REQUEST_WIFI_IFACE_STATUS, iface, &info,
9741039
sizeof(struct wifi_iface_status))) {
9751040
twt_params->fail_reason =
@@ -1003,6 +1068,10 @@ static int wifi_reg_domain(uint32_t mgmt_request, struct net_if *iface,
10031068
return -ENOTSUP;
10041069
}
10051070

1071+
if (!net_if_is_admin_up(iface)) {
1072+
return -ENETDOWN;
1073+
}
1074+
10061075
if (!data || len != sizeof(*reg_domain)) {
10071076
return -EINVAL;
10081077
}
@@ -1035,6 +1104,10 @@ static int wifi_mode(uint32_t mgmt_request, struct net_if *iface,
10351104
return -ENOTSUP;
10361105
}
10371106

1107+
if (!net_if_is_admin_up(iface)) {
1108+
return -ENETDOWN;
1109+
}
1110+
10381111
return wifi_mgmt_api->mode(dev, mode_info);
10391112
}
10401113

@@ -1055,6 +1128,10 @@ static int wifi_packet_filter(uint32_t mgmt_request, struct net_if *iface,
10551128
return -ENOTSUP;
10561129
}
10571130

1131+
if (!net_if_is_admin_up(iface)) {
1132+
return -ENETDOWN;
1133+
}
1134+
10581135
return wifi_mgmt_api->filter(dev, filter_info);
10591136
}
10601137

@@ -1075,6 +1152,10 @@ static int wifi_channel(uint32_t mgmt_request, struct net_if *iface,
10751152
return -ENOTSUP;
10761153
}
10771154

1155+
if (!net_if_is_admin_up(iface)) {
1156+
return -ENETDOWN;
1157+
}
1158+
10781159
return wifi_mgmt_api->channel(dev, channel_info);
10791160
}
10801161

@@ -1107,6 +1188,10 @@ static int wifi_btm_query(uint32_t mgmt_request, struct net_if *iface, void *dat
11071188
return -ENOTSUP;
11081189
}
11091190

1191+
if (!net_if_is_admin_up(iface)) {
1192+
return -ENETDOWN;
1193+
}
1194+
11101195
if (query_reason >= WIFI_BTM_QUERY_REASON_UNSPECIFIED &&
11111196
query_reason <= WIFI_BTM_QUERY_REASON_LEAVING_ESS) {
11121197
return wifi_mgmt_api->btm_query(dev, query_reason);
@@ -1129,6 +1214,10 @@ static int wifi_get_connection_params(uint32_t mgmt_request, struct net_if *ifac
11291214
return -ENOTSUP;
11301215
}
11311216

1217+
if (!net_if_is_admin_up(iface)) {
1218+
return -ENETDOWN;
1219+
}
1220+
11321221
return wifi_mgmt_api->get_conn_params(dev, conn_params);
11331222
}
11341223

@@ -1144,6 +1233,10 @@ static int wifi_wps_config(uint32_t mgmt_request, struct net_if *iface, void *da
11441233
return -ENOTSUP;
11451234
}
11461235

1236+
if (!net_if_is_admin_up(iface)) {
1237+
return -ENETDOWN;
1238+
}
1239+
11471240
return wifi_mgmt_api->wps_config(dev, params);
11481241
}
11491242

@@ -1160,6 +1253,10 @@ static int wifi_set_rts_threshold(uint32_t mgmt_request, struct net_if *iface,
11601253
return -ENOTSUP;
11611254
}
11621255

1256+
if (!net_if_is_admin_up(iface)) {
1257+
return -ENETDOWN;
1258+
}
1259+
11631260
if (!data || len != sizeof(*rts_threshold)) {
11641261
return -EINVAL;
11651262
}
@@ -1181,6 +1278,10 @@ static int wifi_dpp(uint32_t mgmt_request, struct net_if *iface,
11811278
return -ENOTSUP;
11821279
}
11831280

1281+
if (!net_if_is_admin_up(iface)) {
1282+
return -ENETDOWN;
1283+
}
1284+
11841285
return wifi_mgmt_api->dpp_dispatch(dev, params);
11851286
}
11861287

@@ -1198,6 +1299,10 @@ static int wifi_pmksa_flush(uint32_t mgmt_request, struct net_if *iface,
11981299
return -ENOTSUP;
11991300
}
12001301

1302+
if (!net_if_is_admin_up(iface)) {
1303+
return -ENETDOWN;
1304+
}
1305+
12011306
return wifi_mgmt_api->pmksa_flush(dev);
12021307
}
12031308

@@ -1214,6 +1319,10 @@ static int wifi_get_rts_threshold(uint32_t mgmt_request, struct net_if *iface,
12141319
return -ENOTSUP;
12151320
}
12161321

1322+
if (!net_if_is_admin_up(iface)) {
1323+
return -ENETDOWN;
1324+
}
1325+
12171326
if (!data || len != sizeof(*rts_threshold)) {
12181327
return -EINVAL;
12191328
}
@@ -1235,6 +1344,10 @@ static int wifi_set_enterprise_creds(uint32_t mgmt_request, struct net_if *iface
12351344
return -ENOTSUP;
12361345
}
12371346

1347+
if (!net_if_is_admin_up(iface)) {
1348+
return -ENETDOWN;
1349+
}
1350+
12381351
return wifi_mgmt_api->enterprise_creds(dev, params);
12391352
}
12401353

0 commit comments

Comments
 (0)