/src/hostap/src/ap/ieee802_11_uhr.c
Line | Count | Source |
1 | | /* |
2 | | * hostapd / IEEE 802.11bn UHR |
3 | | * Copyright (C) 2025 Intel Corporation |
4 | | * |
5 | | * This software may be distributed under the terms of the BSD license. |
6 | | * See README for more details. |
7 | | */ |
8 | | |
9 | | #include "utils/includes.h" |
10 | | #include "utils/common.h" |
11 | | #include "hostapd.h" |
12 | | #include "sta_info.h" |
13 | | #include "ieee802_11.h" |
14 | | |
15 | | |
16 | | size_t hostapd_eid_uhr_capab_len(struct hostapd_data *hapd, |
17 | | enum ieee80211_op_mode opmode) |
18 | 0 | { |
19 | 0 | struct hostapd_hw_modes *mode; |
20 | 0 | struct uhr_capabilities *uhr_cap; |
21 | 0 | size_t len = 3 /* ext elem header */ + |
22 | 0 | sizeof(struct ieee80211_uhr_capabilities); |
23 | |
|
24 | 0 | mode = hapd->iface->current_mode; |
25 | 0 | if (!mode) |
26 | 0 | return 0; |
27 | | |
28 | 0 | uhr_cap = &mode->uhr_capab[opmode]; |
29 | 0 | if (!uhr_cap->uhr_supported) |
30 | 0 | return 0; |
31 | | |
32 | 0 | if (uhr_cap->mac[1] & IEEE80211_UHR_MAC_CAP1_DBE_SUPP) |
33 | 0 | len += 3; |
34 | |
|
35 | 0 | return len; |
36 | 0 | } |
37 | | |
38 | | |
39 | | u8 * hostapd_eid_uhr_capab(struct hostapd_data *hapd, u8 *eid, |
40 | | enum ieee80211_op_mode opmode) |
41 | 0 | { |
42 | 0 | struct hostapd_hw_modes *mode; |
43 | 0 | struct he_capabilities *he_cap; |
44 | 0 | struct eht_capabilities *eht_cap; |
45 | 0 | struct uhr_capabilities *uhr_cap; |
46 | 0 | struct ieee80211_uhr_capabilities *cap; |
47 | 0 | u8 *pos = eid, *length_pos; |
48 | |
|
49 | 0 | mode = hapd->iface->current_mode; |
50 | 0 | if (!mode) |
51 | 0 | return eid; |
52 | | |
53 | 0 | he_cap = &mode->he_capab[opmode]; |
54 | 0 | eht_cap = &mode->eht_capab[opmode]; |
55 | 0 | uhr_cap = &mode->uhr_capab[opmode]; |
56 | 0 | if (!he_cap->he_supported || |
57 | 0 | !eht_cap->eht_supported || |
58 | 0 | !uhr_cap->uhr_supported) |
59 | 0 | return eid; |
60 | | |
61 | 0 | *pos++ = WLAN_EID_EXTENSION; |
62 | 0 | length_pos = pos++; |
63 | 0 | *pos++ = WLAN_EID_EXT_UHR_CAPABILITIES; |
64 | |
|
65 | 0 | cap = (struct ieee80211_uhr_capabilities *) pos; |
66 | 0 | os_memcpy(cap->mac, uhr_cap->mac, sizeof(cap->mac)); |
67 | 0 | os_memcpy(cap->phy, uhr_cap->phy, sizeof(cap->phy)); |
68 | 0 | pos += sizeof(*cap); |
69 | |
|
70 | 0 | if (opmode == IEEE80211_MODE_AP && |
71 | 0 | cap->mac[1] & IEEE80211_UHR_MAC_CAP1_DBE_SUPP) { |
72 | | /* |
73 | | * Assume that HE implies VHT implies 80 MHz at least, |
74 | | * DBE doesn't exist on 2.4 GHz and the capability |
75 | | * shouldn't be set by the driver. |
76 | | * |
77 | | * It's also not very relevant if DBE isn't enabled. |
78 | | */ |
79 | 0 | u8 dbe_bw = IEEE80211_UHR_DBE_CAP_MAX_BW_80MHZ; |
80 | |
|
81 | 0 | if (he_cap->phy_cap[HE_PHYCAP_CHANNEL_WIDTH_SET_IDX] & |
82 | 0 | HE_PHYCAP_CHANNEL_WIDTH_SET_160MHZ_IN_5G) |
83 | 0 | dbe_bw = IEEE80211_UHR_DBE_CAP_MAX_BW_160MHZ; |
84 | |
|
85 | 0 | if (is_6ghz_op_class(hapd->iconf->op_class) && |
86 | 0 | eht_cap->phy_cap[EHT_PHYCAP_320MHZ_IN_6GHZ_SUPPORT_IDX] & |
87 | 0 | EHT_PHYCAP_320MHZ_IN_6GHZ_SUPPORT_MASK) |
88 | 0 | dbe_bw = IEEE80211_UHR_DBE_CAP_MAX_BW_320MHZ; |
89 | | |
90 | | /* |
91 | | * No MCS maps or other further DBE capabilities since we just |
92 | | * use EHT capabilities and advertise full EHT capabilities |
93 | | * even if operating in a lower bandwidth. |
94 | | */ |
95 | 0 | *pos++ = dbe_bw; |
96 | 0 | *pos++ = 0; /* switch time period */ |
97 | 0 | *pos++ = 0; /* mode change interval */ |
98 | 0 | } |
99 | |
|
100 | 0 | *length_pos = pos - (eid + 2); |
101 | 0 | return pos; |
102 | 0 | } |
103 | | |
104 | | |
105 | | u8 * hostapd_eid_uhr_operation(struct hostapd_data *hapd, u8 *eid, bool beacon) |
106 | 0 | { |
107 | 0 | struct ieee80211_uhr_operation *oper; |
108 | 0 | u8 *pos = eid, *len, *start = eid; |
109 | 0 | u16 oper_ctrl = 0; |
110 | |
|
111 | 0 | if (!hapd->iface->current_mode) |
112 | 0 | return eid; |
113 | | |
114 | 0 | *pos++ = WLAN_EID_EXTENSION; |
115 | 0 | len = pos++; |
116 | 0 | *pos++ = WLAN_EID_EXT_UHR_OPERATION; |
117 | |
|
118 | 0 | oper = (struct ieee80211_uhr_operation *) pos; |
119 | |
|
120 | 0 | if (hapd->iconf->dbe_bandwidth) { |
121 | 0 | u8 dbe_bw = hapd->iconf->dbe_bandwidth << |
122 | 0 | UHR_OPER_CTRL_DBE_BW_SHIFT; |
123 | |
|
124 | 0 | oper_ctrl |= UHR_OPER_CTRL_DBE_ENA; |
125 | 0 | oper_ctrl |= dbe_bw; |
126 | 0 | } |
127 | |
|
128 | 0 | pos += sizeof(*oper); |
129 | | |
130 | | /* UHR Operation Parameters field */ |
131 | |
|
132 | 0 | if (!beacon && hapd->iconf->dbe_bandwidth) { |
133 | 0 | oper_ctrl |= UHR_OPER_CTRL_DPE_OP_PARAMS_PRES; |
134 | | |
135 | | /* DBE Operation Parameters field */ |
136 | 0 | *pos = hapd->iconf->dbe_bandwidth; |
137 | |
|
138 | 0 | if (hapd->iconf->dbe_punct_bitmap) |
139 | 0 | *pos |= IEEE80211_UHR_OPER_DBE_DIS_SUBCH_BMAP_PRES; |
140 | 0 | pos++; |
141 | |
|
142 | 0 | if (hapd->iconf->dbe_punct_bitmap) { |
143 | 0 | WPA_PUT_LE16(pos, hapd->iconf->dbe_punct_bitmap); |
144 | 0 | pos += sizeof(u16); |
145 | 0 | } |
146 | 0 | } |
147 | |
|
148 | 0 | oper->oper_ctrl = host_to_le16(oper_ctrl); |
149 | |
|
150 | 0 | *len = pos - start - 2; |
151 | 0 | return pos; |
152 | 0 | } |
153 | | |
154 | | |
155 | | static bool ieee80211_invalid_uhr_cap_size(enum hostapd_hw_mode mode, |
156 | | const u8 *uhr_cap, size_t len) |
157 | 0 | { |
158 | 0 | return len < sizeof(struct ieee80211_uhr_capabilities); |
159 | 0 | } |
160 | | |
161 | | |
162 | | u16 copy_sta_uhr_capab(struct hostapd_data *hapd, struct sta_info *sta, |
163 | | enum ieee80211_op_mode opmode, |
164 | | const u8 *uhr_capab, size_t uhr_capab_len) |
165 | 0 | { |
166 | 0 | struct hostapd_hw_modes *c_mode = hapd->iface->current_mode; |
167 | 0 | enum hostapd_hw_mode mode = c_mode ? c_mode->mode : NUM_HOSTAPD_MODES; |
168 | |
|
169 | 0 | if (!hostapd_is_uhr_enabled(hapd) || !uhr_capab || |
170 | 0 | ieee80211_invalid_uhr_cap_size(mode, uhr_capab, uhr_capab_len)) { |
171 | 0 | sta->flags &= ~WLAN_STA_UHR; |
172 | 0 | os_free(sta->uhr_capab); |
173 | 0 | sta->uhr_capab = NULL; |
174 | 0 | return WLAN_STATUS_SUCCESS; |
175 | 0 | } |
176 | | |
177 | 0 | os_free(sta->uhr_capab); |
178 | 0 | sta->uhr_capab = os_memdup(uhr_capab, uhr_capab_len); |
179 | 0 | if (!sta->uhr_capab) { |
180 | 0 | sta->uhr_capab_len = 0; |
181 | 0 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
182 | 0 | } |
183 | | |
184 | 0 | sta->flags |= WLAN_STA_UHR; |
185 | 0 | sta->uhr_capab_len = uhr_capab_len; |
186 | |
|
187 | 0 | return WLAN_STATUS_SUCCESS; |
188 | 0 | } |
189 | | |
190 | | |
191 | | void hostapd_get_uhr_capab(struct hostapd_data *hapd, |
192 | | const struct ieee80211_uhr_capabilities *src, |
193 | | struct ieee80211_uhr_capabilities *dest, |
194 | | size_t len) |
195 | 0 | { |
196 | 0 | if (!src || !dest) |
197 | 0 | return; |
198 | | |
199 | 0 | if (len > sizeof(*dest)) |
200 | 0 | len = sizeof(*dest); |
201 | | /* TODO: mask out unsupported features */ |
202 | |
|
203 | 0 | os_memset(dest, 0, sizeof(*dest)); |
204 | 0 | os_memcpy(dest, src, len); |
205 | 0 | } |