Skip to content

Commit 2bbf9b6

Browse files
author
Jiang Jiang Jian
committed
Merge branch 'fix/chip_esp32c5_eco2_supp' into 'master'
Get operating class in dual band Closes IDF-10613 See merge request espressif/esp-idf!38892
2 parents 9651200 + 5a5b20f commit 2bbf9b6

File tree

5 files changed

+89
-16
lines changed

5 files changed

+89
-16
lines changed

components/wpa_supplicant/esp_supplicant/src/esp_common.c

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "rsn_supp/wpa_i.h"
2424
#include "rsn_supp/wpa.h"
2525
#include "esp_private/wifi.h"
26+
#include "esp_wifi_types_generic.h"
2627

2728
/* Utility Functions */
2829
esp_err_t esp_supplicant_str_to_mac(const char *str, uint8_t dest[6])
@@ -592,22 +593,53 @@ static size_t get_mbo_oce_assoc_ie(uint8_t *ie, size_t len)
592593
return mbo_ie_len;
593594
}
594595

595-
static uint8_t get_operating_class_ie(uint8_t *ie, size_t len)
596+
static uint8_t get_operating_class_ie(uint8_t *bssid, uint8_t *ie, size_t len)
596597
{
597-
uint8_t op_class_ie[4] = {0};
598-
uint8_t op_class_ie_len = 2;
599-
uint8_t *pos = op_class_ie;
598+
size_t res = 0;
599+
struct wpabuf *buf;
600+
u8 *ie_len;
601+
u8 op;
602+
channel_bitmap_t non_pref_channels[1] = { 0 };
603+
struct wpa_bss *bss = wpa_bss_get_bssid(&g_wpa_supp, bssid);
600604

601-
*pos++ = WLAN_EID_SUPPORTED_OPERATING_CLASSES;
602-
*pos++ = op_class_ie_len;
603-
#define OPER_CLASS 0x51
604-
/* Current Operating Class */
605-
*pos++ = OPER_CLASS;
606-
#undef OPER_CLASS
607-
*pos = 0;
608-
os_memcpy(ie, op_class_ie, sizeof(op_class_ie));
605+
if (!bss) {
606+
wpa_printf(MSG_ERROR, "bss not found");
607+
return 0;
608+
}
609609

610-
return op_class_ie_len + 2;
610+
/*
611+
* Need 3 bytes for EID, length, and current operating class, plus
612+
* 1 byte for every other supported operating class.
613+
*/
614+
buf = wpabuf_alloc(global_op_class_size + 3);
615+
if (!buf) {
616+
return 0;
617+
}
618+
wpabuf_put_u8(buf, WLAN_EID_SUPPORTED_OPERATING_CLASSES);
619+
/* Will set the length later, putting a placeholder */
620+
ie_len = wpabuf_put(buf, 1);
621+
wpabuf_put_u8(buf, get_operating_class(bss->channel, 0));
622+
for (op = 0; op < global_op_class_size; op++) {
623+
bool supp;
624+
u8 op_class = global_op_class[op].op_class;
625+
supp = esp_wifi_op_class_supported_internal(op_class, global_op_class[op].min_chan, global_op_class[op].max_chan,
626+
global_op_class[op].inc, global_op_class[op].bw, non_pref_channels);
627+
if (!supp) {
628+
continue;
629+
}
630+
/* Add a 1-octet operating class to the Operating Class field */
631+
wpabuf_put_u8(buf, op_class);
632+
}
633+
if (non_pref_channels[0].ghz_2_channels != 0 || non_pref_channels[0].ghz_5_channels != 0) {
634+
wpa_printf(MSG_WARNING,
635+
"It is recommended to forbid channels by operating class instead of channels for better compatibility.\n"
636+
"Non-preferred channels: 2Ghz=0x%04x, 5Ghz=0x%08x", non_pref_channels[0].ghz_2_channels, non_pref_channels[0].ghz_5_channels);
637+
}
638+
*ie_len = wpabuf_len(buf) - 2;
639+
os_memcpy(ie, wpabuf_head(buf), wpabuf_len(buf));
640+
res = wpabuf_len(buf);
641+
wpabuf_free(buf);
642+
return res;
611643
}
612644
#endif /* CONFIG_MBO */
613645

@@ -819,7 +851,7 @@ void esp_set_assoc_ie(uint8_t *bssid, const u8 *ies, size_t ies_len, bool mdie)
819851
len -= ie_len;
820852
#endif /* defined(CONFIG_RRM) */
821853
#ifdef CONFIG_MBO
822-
ie_len = get_operating_class_ie(pos, len);
854+
ie_len = get_operating_class_ie(bssid, pos, len);
823855
pos += ie_len;
824856
len -= ie_len;
825857
ie_len = get_mbo_oce_assoc_ie(pos, len);

components/wpa_supplicant/esp_supplicant/src/esp_wifi_driver.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include "esp_err.h"
1111
#include "esp_wifi.h"
12+
#include "esp_wifi_types_generic.h"
1213

1314
#if CONFIG_NEWLIB_NANO_FORMAT
1415
#define TASK_STACK_SIZE_ADD 0
@@ -217,6 +218,8 @@ enum key_flag {
217218
KEY_FLAG_PMK = BIT(6),
218219
};
219220

221+
typedef wifi_scan_channel_bitmap_t channel_bitmap_t;
222+
220223
uint8_t *esp_wifi_ap_get_prof_pmk_internal(void);
221224
struct wifi_ssid *esp_wifi_ap_get_prof_ap_ssid_internal(void);
222225
uint8_t esp_wifi_ap_get_prof_authmode_internal(void);
@@ -306,5 +309,5 @@ uint8_t esp_wifi_ap_get_transition_disable_internal(void);
306309
int esp_wifi_softap_set_obss_overlap(bool overlap);
307310
void esp_wifi_set_sigma_internal(bool flag);
308311
void esp_wifi_ap_set_group_mgmt_cipher_internal(wifi_cipher_type_t cipher);
309-
312+
uint8_t esp_wifi_op_class_supported_internal(uint8_t op_class, uint8_t min_chan, uint8_t max_chan, uint8_t inc, uint8_t bw, channel_bitmap_t *non_pref_channels);
310313
#endif /* _ESP_WIFI_DRIVER_H_ */

components/wpa_supplicant/src/common/ieee802_11_common.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,30 @@ int ieee802_11_ext_capab(const u8 *ie, unsigned int capab)
355355
return !!(ie[2 + capab / 8] & BIT(capab % 8));
356356
}
357357

358+
const struct oper_class_map global_op_class[] = {
359+
{ HOSTAPD_MODE_IEEE80211G, 81, 1, 13, 1, BW20, P2P_SUPP },
360+
{ HOSTAPD_MODE_IEEE80211G, 82, 14, 14, 1, BW20, NO_P2P_SUPP },
361+
362+
{ HOSTAPD_MODE_IEEE80211G, 83, 1, 9, 1, BW40PLUS, NO_P2P_SUPP },
363+
{ HOSTAPD_MODE_IEEE80211G, 84, 5, 13, 1, BW40MINUS, NO_P2P_SUPP },
364+
365+
{ HOSTAPD_MODE_IEEE80211A, 115, 36, 48, 4, BW20, P2P_SUPP },
366+
{ HOSTAPD_MODE_IEEE80211A, 116, 36, 44, 8, BW40PLUS, P2P_SUPP },
367+
{ HOSTAPD_MODE_IEEE80211A, 117, 40, 48, 8, BW40MINUS, P2P_SUPP },
368+
{ HOSTAPD_MODE_IEEE80211A, 118, 52, 64, 4, BW20, NO_P2P_SUPP },
369+
{ HOSTAPD_MODE_IEEE80211A, 119, 52, 60, 8, BW40PLUS, NO_P2P_SUPP },
370+
{ HOSTAPD_MODE_IEEE80211A, 120, 56, 64, 8, BW40MINUS, NO_P2P_SUPP },
371+
{ HOSTAPD_MODE_IEEE80211A, 121, 100, 144, 4, BW20, NO_P2P_SUPP },
372+
{ HOSTAPD_MODE_IEEE80211A, 122, 100, 140, 8, BW40PLUS, NO_P2P_SUPP },
373+
{ HOSTAPD_MODE_IEEE80211A, 123, 104, 144, 8, BW40MINUS, NO_P2P_SUPP },
374+
{ HOSTAPD_MODE_IEEE80211A, 124, 149, 161, 4, BW20, P2P_SUPP },
375+
{ HOSTAPD_MODE_IEEE80211A, 125, 149, 177, 4, BW20, P2P_SUPP },
376+
{ HOSTAPD_MODE_IEEE80211A, 126, 149, 173, 8, BW40PLUS, P2P_SUPP },
377+
{ HOSTAPD_MODE_IEEE80211A, 127, 153, 177, 8, BW40MINUS, P2P_SUPP }
378+
};
379+
380+
size_t global_op_class_size = ARRAY_SIZE(global_op_class);
381+
358382
u8 get_operating_class(u8 chan, int sec_channel)
359383
{
360384
u8 op_class = 0;

components/wpa_supplicant/src/common/ieee802_11_common.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,20 @@ struct element {
3434

3535
struct wpa_supplicant;
3636

37+
struct oper_class_map {
38+
enum hostapd_hw_mode mode;
39+
u8 op_class;
40+
u8 min_chan;
41+
u8 max_chan;
42+
u8 inc;
43+
enum { BW20, BW40PLUS, BW40MINUS, BW40, BW80, BW2160, BW160, BW80P80,
44+
BW320, BW4320, BW6480, BW8640} bw;
45+
enum { P2P_SUPP, NO_P2P_SUPP } p2p;
46+
};
47+
48+
extern const struct oper_class_map global_op_class[];
49+
extern size_t global_op_class_size;
50+
3751
int ieee802_11_parse_candidate_list(const char *pos, u8 *nei_rep,
3852
size_t nei_rep_len);
3953
const u8 * get_ie(const u8 *ies, size_t len, u8 eid);

0 commit comments

Comments
 (0)