1 /*
2 * Driver interaction with Linux nl80211/cfg80211 - Capabilities
3 * Copyright (c) 2002-2015, Jouni Malinen <j@w1.fi>
4 * Copyright (c) 2007, Johannes Berg <johannes@sipsolutions.net>
5 * Copyright (c) 2009-2010, Atheros Communications
6 *
7 * This software may be distributed under the terms of the BSD license.
8 * See README for more details.
9 */
10
11 #include "includes.h"
12 #include <netlink/genl/genl.h>
13
14 #include "utils/common.h"
15 #include "common/ieee802_11_common.h"
16 #include "common/wpa_common.h"
17 #include "common/qca-vendor.h"
18 #include "common/qca-vendor-attr.h"
19 #include "common/brcm_vendor.h"
20 #include "driver_nl80211.h"
21
22
protocol_feature_handler(struct nl_msg * msg,void * arg)23 static int protocol_feature_handler(struct nl_msg *msg, void *arg)
24 {
25 u32 *feat = arg;
26 struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
27 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
28
29 nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
30 genlmsg_attrlen(gnlh, 0), NULL);
31
32 if (tb_msg[NL80211_ATTR_PROTOCOL_FEATURES])
33 *feat = nla_get_u32(tb_msg[NL80211_ATTR_PROTOCOL_FEATURES]);
34
35 return NL_SKIP;
36 }
37
38
get_nl80211_protocol_features(struct wpa_driver_nl80211_data * drv)39 static u32 get_nl80211_protocol_features(struct wpa_driver_nl80211_data *drv)
40 {
41 u32 feat = 0;
42 struct nl_msg *msg;
43
44 msg = nlmsg_alloc();
45 if (!msg)
46 return 0;
47
48 if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_PROTOCOL_FEATURES)) {
49 nlmsg_free(msg);
50 return 0;
51 }
52
53 if (send_and_recv_msgs(drv, msg, protocol_feature_handler, &feat,
54 NULL, NULL) == 0)
55 return feat;
56
57 return 0;
58 }
59
60
61 struct wiphy_info_data {
62 struct wpa_driver_nl80211_data *drv;
63 struct wpa_driver_capa *capa;
64
65 unsigned int num_multichan_concurrent;
66
67 unsigned int error:1;
68 unsigned int device_ap_sme:1;
69 unsigned int poll_command_supported:1;
70 unsigned int data_tx_status:1;
71 unsigned int auth_supported:1;
72 unsigned int connect_supported:1;
73 unsigned int p2p_go_supported:1;
74 unsigned int p2p_client_supported:1;
75 unsigned int p2p_go_ctwindow_supported:1;
76 unsigned int p2p_concurrent:1;
77 unsigned int channel_switch_supported:1;
78 unsigned int set_qos_map_supported:1;
79 unsigned int have_low_prio_scan:1;
80 unsigned int wmm_ac_supported:1;
81 unsigned int mac_addr_rand_scan_supported:1;
82 unsigned int mac_addr_rand_sched_scan_supported:1;
83 unsigned int update_ft_ies_supported:1;
84 unsigned int has_key_mgmt:1;
85 unsigned int has_key_mgmt_iftype:1;
86 };
87
88
probe_resp_offload_support(int supp_protocols)89 static unsigned int probe_resp_offload_support(int supp_protocols)
90 {
91 unsigned int prot = 0;
92
93 if (supp_protocols & NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS)
94 prot |= WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS;
95 if (supp_protocols & NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2)
96 prot |= WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2;
97 if (supp_protocols & NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P)
98 prot |= WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P;
99 if (supp_protocols & NL80211_PROBE_RESP_OFFLOAD_SUPPORT_80211U)
100 prot |= WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING;
101
102 return prot;
103 }
104
105
wiphy_info_supported_iftypes(struct wiphy_info_data * info,struct nlattr * tb)106 static void wiphy_info_supported_iftypes(struct wiphy_info_data *info,
107 struct nlattr *tb)
108 {
109 struct nlattr *nl_mode;
110 int i;
111
112 if (tb == NULL)
113 return;
114
115 nla_for_each_nested(nl_mode, tb, i) {
116 switch (nla_type(nl_mode)) {
117 case NL80211_IFTYPE_AP:
118 info->capa->flags |= WPA_DRIVER_FLAGS_AP;
119 break;
120 case NL80211_IFTYPE_MESH_POINT:
121 info->capa->flags |= WPA_DRIVER_FLAGS_MESH;
122 break;
123 case NL80211_IFTYPE_ADHOC:
124 info->capa->flags |= WPA_DRIVER_FLAGS_IBSS;
125 break;
126 case NL80211_IFTYPE_P2P_DEVICE:
127 info->capa->flags |=
128 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE;
129 break;
130 case NL80211_IFTYPE_P2P_GO:
131 info->p2p_go_supported = 1;
132 break;
133 case NL80211_IFTYPE_P2P_CLIENT:
134 info->p2p_client_supported = 1;
135 break;
136 }
137 }
138 }
139
140
wiphy_info_iface_comb_process(struct wiphy_info_data * info,struct nlattr * nl_combi)141 static int wiphy_info_iface_comb_process(struct wiphy_info_data *info,
142 struct nlattr *nl_combi)
143 {
144 struct nlattr *tb_comb[NUM_NL80211_IFACE_COMB];
145 struct nlattr *tb_limit[NUM_NL80211_IFACE_LIMIT];
146 struct nlattr *nl_limit, *nl_mode;
147 int err, rem_limit, rem_mode;
148 int combination_has_p2p = 0, combination_has_mgd = 0;
149 static struct nla_policy
150 iface_combination_policy[NUM_NL80211_IFACE_COMB] = {
151 [NL80211_IFACE_COMB_LIMITS] = { .type = NLA_NESTED },
152 [NL80211_IFACE_COMB_MAXNUM] = { .type = NLA_U32 },
153 [NL80211_IFACE_COMB_STA_AP_BI_MATCH] = { .type = NLA_FLAG },
154 [NL80211_IFACE_COMB_NUM_CHANNELS] = { .type = NLA_U32 },
155 [NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS] = { .type = NLA_U32 },
156 },
157 iface_limit_policy[NUM_NL80211_IFACE_LIMIT] = {
158 [NL80211_IFACE_LIMIT_TYPES] = { .type = NLA_NESTED },
159 [NL80211_IFACE_LIMIT_MAX] = { .type = NLA_U32 },
160 };
161
162 err = nla_parse_nested(tb_comb, MAX_NL80211_IFACE_COMB,
163 nl_combi, iface_combination_policy);
164 if (err || !tb_comb[NL80211_IFACE_COMB_LIMITS] ||
165 !tb_comb[NL80211_IFACE_COMB_MAXNUM] ||
166 !tb_comb[NL80211_IFACE_COMB_NUM_CHANNELS])
167 return 0; /* broken combination */
168
169 if (tb_comb[NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS])
170 info->capa->flags |= WPA_DRIVER_FLAGS_RADAR;
171
172 nla_for_each_nested(nl_limit, tb_comb[NL80211_IFACE_COMB_LIMITS],
173 rem_limit) {
174 err = nla_parse_nested(tb_limit, MAX_NL80211_IFACE_LIMIT,
175 nl_limit, iface_limit_policy);
176 if (err || !tb_limit[NL80211_IFACE_LIMIT_TYPES])
177 return 0; /* broken combination */
178
179 nla_for_each_nested(nl_mode,
180 tb_limit[NL80211_IFACE_LIMIT_TYPES],
181 rem_mode) {
182 int ift = nla_type(nl_mode);
183 if (ift == NL80211_IFTYPE_P2P_GO ||
184 ift == NL80211_IFTYPE_P2P_CLIENT)
185 combination_has_p2p = 1;
186 if (ift == NL80211_IFTYPE_STATION)
187 combination_has_mgd = 1;
188 }
189 if (combination_has_p2p && combination_has_mgd)
190 break;
191 }
192
193 if (combination_has_p2p && combination_has_mgd) {
194 unsigned int num_channels =
195 nla_get_u32(tb_comb[NL80211_IFACE_COMB_NUM_CHANNELS]);
196
197 info->p2p_concurrent = 1;
198 if (info->num_multichan_concurrent < num_channels)
199 info->num_multichan_concurrent = num_channels;
200 }
201
202 return 0;
203 }
204
205
wiphy_info_iface_comb(struct wiphy_info_data * info,struct nlattr * tb)206 static void wiphy_info_iface_comb(struct wiphy_info_data *info,
207 struct nlattr *tb)
208 {
209 struct nlattr *nl_combi;
210 int rem_combi;
211
212 if (tb == NULL)
213 return;
214
215 nla_for_each_nested(nl_combi, tb, rem_combi) {
216 if (wiphy_info_iface_comb_process(info, nl_combi) > 0)
217 break;
218 }
219 }
220
221
wiphy_info_supp_cmds(struct wiphy_info_data * info,struct nlattr * tb)222 static void wiphy_info_supp_cmds(struct wiphy_info_data *info,
223 struct nlattr *tb)
224 {
225 struct nlattr *nl_cmd;
226 int i;
227
228 if (tb == NULL)
229 return;
230
231 nla_for_each_nested(nl_cmd, tb, i) {
232 switch (nla_get_u32(nl_cmd)) {
233 case NL80211_CMD_AUTHENTICATE:
234 info->auth_supported = 1;
235 break;
236 case NL80211_CMD_CONNECT:
237 info->connect_supported = 1;
238 break;
239 case NL80211_CMD_START_SCHED_SCAN:
240 info->capa->sched_scan_supported = 1;
241 break;
242 case NL80211_CMD_PROBE_CLIENT:
243 info->poll_command_supported = 1;
244 break;
245 case NL80211_CMD_CHANNEL_SWITCH:
246 info->channel_switch_supported = 1;
247 break;
248 case NL80211_CMD_SET_QOS_MAP:
249 info->set_qos_map_supported = 1;
250 break;
251 case NL80211_CMD_UPDATE_FT_IES:
252 info->update_ft_ies_supported = 1;
253 break;
254 }
255 }
256 }
257
258
get_akm_suites_info(struct nlattr * tb)259 static unsigned int get_akm_suites_info(struct nlattr *tb)
260 {
261 int i, num;
262 unsigned int key_mgmt = 0;
263 u32 *akms;
264
265 if (!tb)
266 return 0;
267
268 num = nla_len(tb) / sizeof(u32);
269 akms = nla_data(tb);
270 for (i = 0; i < num; i++) {
271 switch (akms[i]) {
272 case RSN_AUTH_KEY_MGMT_UNSPEC_802_1X:
273 key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_WPA |
274 WPA_DRIVER_CAPA_KEY_MGMT_WPA2;
275 break;
276 case RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X:
277 key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
278 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK;
279 break;
280 case RSN_AUTH_KEY_MGMT_FT_802_1X:
281 key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT;
282 break;
283 case RSN_AUTH_KEY_MGMT_FT_PSK:
284 key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK;
285 break;
286 case RSN_AUTH_KEY_MGMT_802_1X_SHA256:
287 key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_802_1X_SHA256;
288 break;
289 case RSN_AUTH_KEY_MGMT_PSK_SHA256:
290 key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_PSK_SHA256;
291 break;
292 case RSN_AUTH_KEY_MGMT_TPK_HANDSHAKE:
293 key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_TPK_HANDSHAKE;
294 break;
295 case RSN_AUTH_KEY_MGMT_FT_SAE:
296 key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT_SAE;
297 break;
298 case RSN_AUTH_KEY_MGMT_FT_802_1X_SHA384:
299 key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT_802_1X_SHA384;
300 break;
301 case RSN_AUTH_KEY_MGMT_CCKM:
302 key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_CCKM;
303 break;
304 case RSN_AUTH_KEY_MGMT_OSEN:
305 key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_OSEN;
306 break;
307 case RSN_AUTH_KEY_MGMT_802_1X_SUITE_B:
308 key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B;
309 break;
310 case RSN_AUTH_KEY_MGMT_802_1X_SUITE_B_192:
311 key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192;
312 break;
313 case RSN_AUTH_KEY_MGMT_OWE:
314 key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_OWE;
315 break;
316 case RSN_AUTH_KEY_MGMT_DPP:
317 key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_DPP;
318 break;
319 case RSN_AUTH_KEY_MGMT_FILS_SHA256:
320 key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA256;
321 break;
322 case RSN_AUTH_KEY_MGMT_FILS_SHA384:
323 key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA384;
324 break;
325 case RSN_AUTH_KEY_MGMT_FT_FILS_SHA256:
326 key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA256;
327 break;
328 case RSN_AUTH_KEY_MGMT_FT_FILS_SHA384:
329 key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA384;
330 break;
331 case RSN_AUTH_KEY_MGMT_SAE:
332 key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_SAE;
333 break;
334 }
335 }
336
337 return key_mgmt;
338 }
339
340
get_iface_akm_suites_info(struct wiphy_info_data * info,struct nlattr * nl_akms)341 static void get_iface_akm_suites_info(struct wiphy_info_data *info,
342 struct nlattr *nl_akms)
343 {
344 struct nlattr *tb[NL80211_IFTYPE_AKM_ATTR_MAX + 1];
345 struct nlattr *nl_iftype;
346 unsigned int key_mgmt;
347 int i;
348
349 if (!nl_akms)
350 return;
351
352 nla_parse(tb, NL80211_IFTYPE_AKM_ATTR_MAX,
353 nla_data(nl_akms), nla_len(nl_akms), NULL);
354
355 if (!tb[NL80211_IFTYPE_AKM_ATTR_IFTYPES] ||
356 !tb[NL80211_IFTYPE_AKM_ATTR_SUITES])
357 return;
358
359 info->has_key_mgmt_iftype = 1;
360 key_mgmt = get_akm_suites_info(tb[NL80211_IFTYPE_AKM_ATTR_SUITES]);
361
362 nla_for_each_nested(nl_iftype, tb[NL80211_IFTYPE_AKM_ATTR_IFTYPES], i) {
363 switch (nla_type(nl_iftype)) {
364 case NL80211_IFTYPE_ADHOC:
365 info->drv->capa.key_mgmt_iftype[WPA_IF_IBSS] = key_mgmt;
366 break;
367 case NL80211_IFTYPE_STATION:
368 info->drv->capa.key_mgmt_iftype[WPA_IF_STATION] =
369 key_mgmt;
370 break;
371 case NL80211_IFTYPE_AP:
372 info->drv->capa.key_mgmt_iftype[WPA_IF_AP_BSS] =
373 key_mgmt;
374 break;
375 case NL80211_IFTYPE_AP_VLAN:
376 info->drv->capa.key_mgmt_iftype[WPA_IF_AP_VLAN] =
377 key_mgmt;
378 break;
379 case NL80211_IFTYPE_MESH_POINT:
380 info->drv->capa.key_mgmt_iftype[WPA_IF_MESH] = key_mgmt;
381 break;
382 case NL80211_IFTYPE_P2P_CLIENT:
383 info->drv->capa.key_mgmt_iftype[WPA_IF_P2P_CLIENT] =
384 key_mgmt;
385 break;
386 case NL80211_IFTYPE_P2P_GO:
387 info->drv->capa.key_mgmt_iftype[WPA_IF_P2P_GO] =
388 key_mgmt;
389 break;
390 case NL80211_IFTYPE_P2P_DEVICE:
391 info->drv->capa.key_mgmt_iftype[WPA_IF_P2P_DEVICE] =
392 key_mgmt;
393 break;
394 case NL80211_IFTYPE_NAN:
395 info->drv->capa.key_mgmt_iftype[WPA_IF_NAN] = key_mgmt;
396 break;
397 }
398 wpa_printf(MSG_DEBUG, "nl80211: %s supported key_mgmt 0x%x",
399 nl80211_iftype_str(nla_type(nl_iftype)),
400 key_mgmt);
401 }
402 }
403
404
wiphy_info_iftype_akm_suites(struct wiphy_info_data * info,struct nlattr * tb)405 static void wiphy_info_iftype_akm_suites(struct wiphy_info_data *info,
406 struct nlattr *tb)
407 {
408 struct nlattr *nl_if;
409 int rem_if;
410
411 if (!tb)
412 return;
413
414 nla_for_each_nested(nl_if, tb, rem_if)
415 get_iface_akm_suites_info(info, nl_if);
416 }
417
418
wiphy_info_akm_suites(struct wiphy_info_data * info,struct nlattr * tb)419 static void wiphy_info_akm_suites(struct wiphy_info_data *info,
420 struct nlattr *tb)
421 {
422 if (!tb)
423 return;
424
425 info->has_key_mgmt = 1;
426 info->capa->key_mgmt = get_akm_suites_info(tb);
427 wpa_printf(MSG_DEBUG, "nl80211: wiphy supported key_mgmt 0x%x",
428 info->capa->key_mgmt);
429 }
430
431
wiphy_info_cipher_suites(struct wiphy_info_data * info,struct nlattr * tb)432 static void wiphy_info_cipher_suites(struct wiphy_info_data *info,
433 struct nlattr *tb)
434 {
435 int i, num;
436 u32 *ciphers;
437
438 if (tb == NULL)
439 return;
440
441 num = nla_len(tb) / sizeof(u32);
442 ciphers = nla_data(tb);
443 for (i = 0; i < num; i++) {
444 u32 c = ciphers[i];
445
446 wpa_printf(MSG_DEBUG, "nl80211: Supported cipher %02x-%02x-%02x:%d",
447 c >> 24, (c >> 16) & 0xff,
448 (c >> 8) & 0xff, c & 0xff);
449 switch (c) {
450 case RSN_CIPHER_SUITE_CCMP_256:
451 info->capa->enc |= WPA_DRIVER_CAPA_ENC_CCMP_256;
452 break;
453 case RSN_CIPHER_SUITE_GCMP_256:
454 info->capa->enc |= WPA_DRIVER_CAPA_ENC_GCMP_256;
455 break;
456 case RSN_CIPHER_SUITE_CCMP:
457 info->capa->enc |= WPA_DRIVER_CAPA_ENC_CCMP;
458 break;
459 case RSN_CIPHER_SUITE_GCMP:
460 info->capa->enc |= WPA_DRIVER_CAPA_ENC_GCMP;
461 break;
462 case RSN_CIPHER_SUITE_TKIP:
463 info->capa->enc |= WPA_DRIVER_CAPA_ENC_TKIP;
464 break;
465 case RSN_CIPHER_SUITE_WEP104:
466 info->capa->enc |= WPA_DRIVER_CAPA_ENC_WEP104;
467 break;
468 case RSN_CIPHER_SUITE_WEP40:
469 info->capa->enc |= WPA_DRIVER_CAPA_ENC_WEP40;
470 break;
471 case RSN_CIPHER_SUITE_AES_128_CMAC:
472 info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP;
473 break;
474 case RSN_CIPHER_SUITE_BIP_GMAC_128:
475 info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP_GMAC_128;
476 break;
477 case RSN_CIPHER_SUITE_BIP_GMAC_256:
478 info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP_GMAC_256;
479 break;
480 case RSN_CIPHER_SUITE_BIP_CMAC_256:
481 info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP_CMAC_256;
482 break;
483 case RSN_CIPHER_SUITE_NO_GROUP_ADDRESSED:
484 info->capa->enc |= WPA_DRIVER_CAPA_ENC_GTK_NOT_USED;
485 break;
486 }
487 }
488 }
489
490
wiphy_info_max_roc(struct wpa_driver_capa * capa,struct nlattr * tb)491 static void wiphy_info_max_roc(struct wpa_driver_capa *capa,
492 struct nlattr *tb)
493 {
494 if (tb)
495 capa->max_remain_on_chan = nla_get_u32(tb);
496 }
497
498
wiphy_info_tdls(struct wpa_driver_capa * capa,struct nlattr * tdls,struct nlattr * ext_setup)499 static void wiphy_info_tdls(struct wpa_driver_capa *capa, struct nlattr *tdls,
500 struct nlattr *ext_setup)
501 {
502 if (tdls == NULL)
503 return;
504
505 wpa_printf(MSG_DEBUG, "nl80211: TDLS supported");
506 capa->flags |= WPA_DRIVER_FLAGS_TDLS_SUPPORT;
507
508 if (ext_setup) {
509 wpa_printf(MSG_DEBUG, "nl80211: TDLS external setup");
510 capa->flags |= WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP;
511 }
512 }
513
514
ext_feature_isset(const u8 * ext_features,int ext_features_len,enum nl80211_ext_feature_index ftidx)515 static int ext_feature_isset(const u8 *ext_features, int ext_features_len,
516 enum nl80211_ext_feature_index ftidx)
517 {
518 u8 ft_byte;
519
520 if ((int) ftidx / 8 >= ext_features_len)
521 return 0;
522
523 ft_byte = ext_features[ftidx / 8];
524 return (ft_byte & BIT(ftidx % 8)) != 0;
525 }
526
527
wiphy_info_ext_feature_flags(struct wiphy_info_data * info,struct nlattr * tb)528 static void wiphy_info_ext_feature_flags(struct wiphy_info_data *info,
529 struct nlattr *tb)
530 {
531 struct wpa_driver_capa *capa = info->capa;
532 u8 *ext_features;
533 int len;
534
535 if (tb == NULL)
536 return;
537
538 ext_features = nla_data(tb);
539 len = nla_len(tb);
540
541 if (ext_feature_isset(ext_features, len, NL80211_EXT_FEATURE_VHT_IBSS))
542 capa->flags |= WPA_DRIVER_FLAGS_VHT_IBSS;
543
544 if (ext_feature_isset(ext_features, len, NL80211_EXT_FEATURE_RRM))
545 capa->rrm_flags |= WPA_DRIVER_FLAGS_SUPPORT_RRM;
546
547 if (ext_feature_isset(ext_features, len, NL80211_EXT_FEATURE_FILS_STA))
548 capa->flags |= WPA_DRIVER_FLAGS_SUPPORT_FILS;
549
550 if (ext_feature_isset(ext_features, len,
551 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY))
552 capa->flags |= WPA_DRIVER_FLAGS_BEACON_RATE_LEGACY;
553
554 if (ext_feature_isset(ext_features, len,
555 NL80211_EXT_FEATURE_BEACON_RATE_HT))
556 capa->flags |= WPA_DRIVER_FLAGS_BEACON_RATE_HT;
557
558 if (ext_feature_isset(ext_features, len,
559 NL80211_EXT_FEATURE_BEACON_RATE_VHT))
560 capa->flags |= WPA_DRIVER_FLAGS_BEACON_RATE_VHT;
561
562 if (ext_feature_isset(ext_features, len,
563 NL80211_EXT_FEATURE_BEACON_RATE_HE))
564 capa->flags2 |= WPA_DRIVER_FLAGS2_BEACON_RATE_HE;
565
566 if (ext_feature_isset(ext_features, len,
567 NL80211_EXT_FEATURE_SET_SCAN_DWELL))
568 capa->rrm_flags |= WPA_DRIVER_FLAGS_SUPPORT_SET_SCAN_DWELL;
569
570 if (ext_feature_isset(ext_features, len,
571 NL80211_EXT_FEATURE_SCAN_START_TIME) &&
572 ext_feature_isset(ext_features, len,
573 NL80211_EXT_FEATURE_BSS_PARENT_TSF) &&
574 ext_feature_isset(ext_features, len,
575 NL80211_EXT_FEATURE_SET_SCAN_DWELL))
576 capa->rrm_flags |= WPA_DRIVER_FLAGS_SUPPORT_BEACON_REPORT;
577 if (ext_feature_isset(ext_features, len,
578 NL80211_EXT_FEATURE_MGMT_TX_RANDOM_TA))
579 capa->flags |= WPA_DRIVER_FLAGS_MGMT_TX_RANDOM_TA;
580 if (ext_feature_isset(ext_features, len,
581 NL80211_EXT_FEATURE_MGMT_TX_RANDOM_TA_CONNECTED))
582 capa->flags |= WPA_DRIVER_FLAGS_MGMT_TX_RANDOM_TA_CONNECTED;
583 if (ext_feature_isset(ext_features, len,
584 NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI))
585 capa->flags |= WPA_DRIVER_FLAGS_SCHED_SCAN_RELATIVE_RSSI;
586 if (ext_feature_isset(ext_features, len,
587 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD))
588 capa->flags |= WPA_DRIVER_FLAGS_FILS_SK_OFFLOAD;
589
590 if (ext_feature_isset(ext_features, len,
591 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK))
592 capa->flags |= WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK;
593 if (ext_feature_isset(ext_features, len,
594 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
595 capa->flags |= WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X;
596
597 if (ext_feature_isset(ext_features, len,
598 NL80211_EXT_FEATURE_MFP_OPTIONAL))
599 capa->flags |= WPA_DRIVER_FLAGS_MFP_OPTIONAL;
600
601 if (ext_feature_isset(ext_features, len,
602 NL80211_EXT_FEATURE_DFS_OFFLOAD))
603 capa->flags |= WPA_DRIVER_FLAGS_DFS_OFFLOAD;
604
605 #ifdef CONFIG_MBO
606 if (ext_feature_isset(ext_features, len,
607 NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME) &&
608 ext_feature_isset(ext_features, len,
609 NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP) &&
610 ext_feature_isset(ext_features, len,
611 NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE) &&
612 ext_feature_isset(
613 ext_features, len,
614 NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION))
615 capa->flags |= WPA_DRIVER_FLAGS_OCE_STA;
616 #endif /* CONFIG_MBO */
617
618 if (ext_feature_isset(ext_features, len,
619 NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER))
620 capa->flags |= WPA_DRIVER_FLAGS_FTM_RESPONDER;
621
622 if (ext_feature_isset(ext_features, len,
623 NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211))
624 capa->flags |= WPA_DRIVER_FLAGS_CONTROL_PORT;
625 if (ext_feature_isset(ext_features, len,
626 NL80211_EXT_FEATURE_CONTROL_PORT_NO_PREAUTH))
627 capa->flags2 |= WPA_DRIVER_FLAGS2_CONTROL_PORT_RX;
628 if (ext_feature_isset(
629 ext_features, len,
630 NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211_TX_STATUS))
631 capa->flags2 |= WPA_DRIVER_FLAGS2_CONTROL_PORT_TX_STATUS;
632
633 if (ext_feature_isset(ext_features, len,
634 NL80211_EXT_FEATURE_VLAN_OFFLOAD))
635 capa->flags |= WPA_DRIVER_FLAGS_VLAN_OFFLOAD;
636
637 if (ext_feature_isset(ext_features, len,
638 NL80211_EXT_FEATURE_CAN_REPLACE_PTK0))
639 capa->flags |= WPA_DRIVER_FLAGS_SAFE_PTK0_REKEYS;
640
641 if (ext_feature_isset(ext_features, len,
642 NL80211_EXT_FEATURE_BEACON_PROTECTION))
643 capa->flags |= WPA_DRIVER_FLAGS_BEACON_PROTECTION;
644
645 if (ext_feature_isset(ext_features, len,
646 NL80211_EXT_FEATURE_EXT_KEY_ID))
647 capa->flags |= WPA_DRIVER_FLAGS_EXTENDED_KEY_ID;
648
649 if (ext_feature_isset(ext_features, len,
650 NL80211_EXT_FEATURE_MULTICAST_REGISTRATIONS))
651 info->drv->multicast_registrations = 1;
652
653 if (ext_feature_isset(ext_features, len,
654 NL80211_EXT_FEATURE_FILS_DISCOVERY))
655 info->drv->fils_discovery = 1;
656
657 if (ext_feature_isset(ext_features, len,
658 NL80211_EXT_FEATURE_UNSOL_BCAST_PROBE_RESP))
659 info->drv->unsol_bcast_probe_resp = 1;
660
661 if (ext_feature_isset(ext_features, len,
662 NL80211_EXT_FEATURE_BEACON_PROTECTION_CLIENT))
663 capa->flags2 |= WPA_DRIVER_FLAGS2_BEACON_PROTECTION_CLIENT;
664
665 if (ext_feature_isset(ext_features, len,
666 NL80211_EXT_FEATURE_OPERATING_CHANNEL_VALIDATION))
667 capa->flags2 |= WPA_DRIVER_FLAGS2_OCV;
668 }
669
670
wiphy_info_feature_flags(struct wiphy_info_data * info,struct nlattr * tb)671 static void wiphy_info_feature_flags(struct wiphy_info_data *info,
672 struct nlattr *tb)
673 {
674 u32 flags;
675 struct wpa_driver_capa *capa = info->capa;
676
677 if (tb == NULL)
678 return;
679
680 flags = nla_get_u32(tb);
681
682 if (flags & NL80211_FEATURE_SK_TX_STATUS)
683 info->data_tx_status = 1;
684
685 if (flags & NL80211_FEATURE_INACTIVITY_TIMER)
686 capa->flags |= WPA_DRIVER_FLAGS_INACTIVITY_TIMER;
687
688 if (flags & NL80211_FEATURE_SAE)
689 capa->flags |= WPA_DRIVER_FLAGS_SAE;
690
691 if (flags & NL80211_FEATURE_NEED_OBSS_SCAN)
692 capa->flags |= WPA_DRIVER_FLAGS_OBSS_SCAN;
693
694 if (flags & NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)
695 capa->flags |= WPA_DRIVER_FLAGS_HT_2040_COEX;
696
697 if (flags & NL80211_FEATURE_TDLS_CHANNEL_SWITCH) {
698 wpa_printf(MSG_DEBUG, "nl80211: TDLS channel switch");
699 capa->flags |= WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH;
700 }
701
702 if (flags & NL80211_FEATURE_P2P_GO_CTWIN)
703 info->p2p_go_ctwindow_supported = 1;
704
705 if (flags & NL80211_FEATURE_LOW_PRIORITY_SCAN)
706 info->have_low_prio_scan = 1;
707
708 if (flags & NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)
709 info->mac_addr_rand_scan_supported = 1;
710
711 if (flags & NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR)
712 info->mac_addr_rand_sched_scan_supported = 1;
713
714 if (flags & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
715 info->wmm_ac_supported = 1;
716
717 if (flags & NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES)
718 capa->rrm_flags |= WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES;
719
720 if (flags & NL80211_FEATURE_WFA_TPC_IE_IN_PROBES)
721 capa->rrm_flags |= WPA_DRIVER_FLAGS_WFA_TPC_IE_IN_PROBES;
722
723 if (flags & NL80211_FEATURE_QUIET)
724 capa->rrm_flags |= WPA_DRIVER_FLAGS_QUIET;
725
726 if (flags & NL80211_FEATURE_TX_POWER_INSERTION)
727 capa->rrm_flags |= WPA_DRIVER_FLAGS_TX_POWER_INSERTION;
728
729 if (flags & NL80211_FEATURE_HT_IBSS)
730 capa->flags |= WPA_DRIVER_FLAGS_HT_IBSS;
731
732 if (flags & NL80211_FEATURE_FULL_AP_CLIENT_STATE)
733 capa->flags |= WPA_DRIVER_FLAGS_FULL_AP_CLIENT_STATE;
734 }
735
736
wiphy_info_probe_resp_offload(struct wpa_driver_capa * capa,struct nlattr * tb)737 static void wiphy_info_probe_resp_offload(struct wpa_driver_capa *capa,
738 struct nlattr *tb)
739 {
740 u32 protocols;
741
742 if (tb == NULL)
743 return;
744
745 protocols = nla_get_u32(tb);
746 wpa_printf(MSG_DEBUG, "nl80211: Supports Probe Response offload in AP "
747 "mode");
748 capa->flags |= WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD;
749 capa->probe_resp_offloads = probe_resp_offload_support(protocols);
750 }
751
752
wiphy_info_wowlan_triggers(struct wpa_driver_capa * capa,struct nlattr * tb)753 static void wiphy_info_wowlan_triggers(struct wpa_driver_capa *capa,
754 struct nlattr *tb)
755 {
756 struct nlattr *triggers[MAX_NL80211_WOWLAN_TRIG + 1];
757
758 if (tb == NULL)
759 return;
760
761 if (nla_parse_nested(triggers, MAX_NL80211_WOWLAN_TRIG,
762 tb, NULL))
763 return;
764
765 if (triggers[NL80211_WOWLAN_TRIG_ANY])
766 capa->wowlan_triggers.any = 1;
767 if (triggers[NL80211_WOWLAN_TRIG_DISCONNECT])
768 capa->wowlan_triggers.disconnect = 1;
769 if (triggers[NL80211_WOWLAN_TRIG_MAGIC_PKT])
770 capa->wowlan_triggers.magic_pkt = 1;
771 if (triggers[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE])
772 capa->wowlan_triggers.gtk_rekey_failure = 1;
773 if (triggers[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST])
774 capa->wowlan_triggers.eap_identity_req = 1;
775 if (triggers[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE])
776 capa->wowlan_triggers.four_way_handshake = 1;
777 if (triggers[NL80211_WOWLAN_TRIG_RFKILL_RELEASE])
778 capa->wowlan_triggers.rfkill_release = 1;
779 }
780
781
wiphy_info_extended_capab(struct wpa_driver_nl80211_data * drv,struct nlattr * tb)782 static void wiphy_info_extended_capab(struct wpa_driver_nl80211_data *drv,
783 struct nlattr *tb)
784 {
785 int rem = 0, i;
786 struct nlattr *tb1[NL80211_ATTR_MAX + 1], *attr;
787
788 if (!tb || drv->num_iface_ext_capa == NL80211_IFTYPE_MAX)
789 return;
790
791 nla_for_each_nested(attr, tb, rem) {
792 unsigned int len;
793 struct drv_nl80211_ext_capa *capa;
794
795 nla_parse(tb1, NL80211_ATTR_MAX, nla_data(attr),
796 nla_len(attr), NULL);
797
798 if (!tb1[NL80211_ATTR_IFTYPE] ||
799 !tb1[NL80211_ATTR_EXT_CAPA] ||
800 !tb1[NL80211_ATTR_EXT_CAPA_MASK])
801 continue;
802
803 capa = &drv->iface_ext_capa[drv->num_iface_ext_capa];
804 capa->iftype = nla_get_u32(tb1[NL80211_ATTR_IFTYPE]);
805 wpa_printf(MSG_DEBUG,
806 "nl80211: Driver-advertised extended capabilities for interface type %s",
807 nl80211_iftype_str(capa->iftype));
808
809 len = nla_len(tb1[NL80211_ATTR_EXT_CAPA]);
810 capa->ext_capa = os_memdup(nla_data(tb1[NL80211_ATTR_EXT_CAPA]),
811 len);
812 if (!capa->ext_capa)
813 goto err;
814
815 capa->ext_capa_len = len;
816 wpa_hexdump(MSG_DEBUG, "nl80211: Extended capabilities",
817 capa->ext_capa, capa->ext_capa_len);
818
819 len = nla_len(tb1[NL80211_ATTR_EXT_CAPA_MASK]);
820 capa->ext_capa_mask =
821 os_memdup(nla_data(tb1[NL80211_ATTR_EXT_CAPA_MASK]),
822 len);
823 if (!capa->ext_capa_mask)
824 goto err;
825
826 wpa_hexdump(MSG_DEBUG, "nl80211: Extended capabilities mask",
827 capa->ext_capa_mask, capa->ext_capa_len);
828
829 drv->num_iface_ext_capa++;
830 if (drv->num_iface_ext_capa == NL80211_IFTYPE_MAX)
831 break;
832 }
833
834 return;
835
836 err:
837 /* Cleanup allocated memory on error */
838 for (i = 0; i < NL80211_IFTYPE_MAX; i++) {
839 os_free(drv->iface_ext_capa[i].ext_capa);
840 drv->iface_ext_capa[i].ext_capa = NULL;
841 os_free(drv->iface_ext_capa[i].ext_capa_mask);
842 drv->iface_ext_capa[i].ext_capa_mask = NULL;
843 drv->iface_ext_capa[i].ext_capa_len = 0;
844 }
845 drv->num_iface_ext_capa = 0;
846 }
847
848
wiphy_info_handler(struct nl_msg * msg,void * arg)849 static int wiphy_info_handler(struct nl_msg *msg, void *arg)
850 {
851 struct nlattr *tb[NL80211_ATTR_MAX + 1];
852 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
853 struct wiphy_info_data *info = arg;
854 struct wpa_driver_capa *capa = info->capa;
855 struct wpa_driver_nl80211_data *drv = info->drv;
856
857 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
858 genlmsg_attrlen(gnlh, 0), NULL);
859
860 if (tb[NL80211_ATTR_WIPHY])
861 drv->wiphy_idx = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
862
863 if (tb[NL80211_ATTR_WIPHY_NAME])
864 os_strlcpy(drv->phyname,
865 nla_get_string(tb[NL80211_ATTR_WIPHY_NAME]),
866 sizeof(drv->phyname));
867 if (tb[NL80211_ATTR_MAX_NUM_SCAN_SSIDS])
868 capa->max_scan_ssids =
869 nla_get_u8(tb[NL80211_ATTR_MAX_NUM_SCAN_SSIDS]);
870
871 if (tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS])
872 capa->max_sched_scan_ssids =
873 nla_get_u8(tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS]);
874
875 if (tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS] &&
876 tb[NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL] &&
877 tb[NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS]) {
878 capa->max_sched_scan_plans =
879 nla_get_u32(tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS]);
880
881 capa->max_sched_scan_plan_interval =
882 nla_get_u32(tb[NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL]);
883
884 capa->max_sched_scan_plan_iterations =
885 nla_get_u32(tb[NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS]);
886 }
887
888 if (tb[NL80211_ATTR_MAX_MATCH_SETS])
889 capa->max_match_sets =
890 nla_get_u8(tb[NL80211_ATTR_MAX_MATCH_SETS]);
891
892 if (tb[NL80211_ATTR_MAC_ACL_MAX])
893 capa->max_acl_mac_addrs =
894 nla_get_u32(tb[NL80211_ATTR_MAC_ACL_MAX]);
895
896 wiphy_info_supported_iftypes(info, tb[NL80211_ATTR_SUPPORTED_IFTYPES]);
897 wiphy_info_iface_comb(info, tb[NL80211_ATTR_INTERFACE_COMBINATIONS]);
898 wiphy_info_supp_cmds(info, tb[NL80211_ATTR_SUPPORTED_COMMANDS]);
899 wiphy_info_cipher_suites(info, tb[NL80211_ATTR_CIPHER_SUITES]);
900 wiphy_info_akm_suites(info, tb[NL80211_ATTR_AKM_SUITES]);
901 wiphy_info_iftype_akm_suites(info, tb[NL80211_ATTR_IFTYPE_AKM_SUITES]);
902
903 if (tb[NL80211_ATTR_OFFCHANNEL_TX_OK]) {
904 wpa_printf(MSG_DEBUG, "nl80211: Using driver-based "
905 "off-channel TX");
906 capa->flags |= WPA_DRIVER_FLAGS_OFFCHANNEL_TX;
907 }
908
909 if (tb[NL80211_ATTR_ROAM_SUPPORT]) {
910 wpa_printf(MSG_DEBUG, "nl80211: Using driver-based roaming");
911 capa->flags |= WPA_DRIVER_FLAGS_BSS_SELECTION;
912 }
913
914 if (tb[NL80211_ATTR_DFS_OFFLOAD_SUPPORT]) {
915 wpa_printf(MSG_DEBUG, "nl80211: Using driver-based dfs offload");
916 capa->flags |= WPA_DRIVER_FLAGS_DFS_OFFLOAD;
917 }
918
919 wiphy_info_max_roc(capa,
920 tb[NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION]);
921
922 if (tb[NL80211_ATTR_SUPPORT_AP_UAPSD])
923 capa->flags |= WPA_DRIVER_FLAGS_AP_UAPSD;
924
925 wiphy_info_tdls(capa, tb[NL80211_ATTR_TDLS_SUPPORT],
926 tb[NL80211_ATTR_TDLS_EXTERNAL_SETUP]);
927
928 if (tb[NL80211_ATTR_DEVICE_AP_SME])
929 info->device_ap_sme = 1;
930
931 wiphy_info_feature_flags(info, tb[NL80211_ATTR_FEATURE_FLAGS]);
932 wiphy_info_ext_feature_flags(info, tb[NL80211_ATTR_EXT_FEATURES]);
933 wiphy_info_probe_resp_offload(capa,
934 tb[NL80211_ATTR_PROBE_RESP_OFFLOAD]);
935
936 if (tb[NL80211_ATTR_EXT_CAPA] && tb[NL80211_ATTR_EXT_CAPA_MASK] &&
937 drv->extended_capa == NULL) {
938 drv->extended_capa =
939 os_malloc(nla_len(tb[NL80211_ATTR_EXT_CAPA]));
940 if (drv->extended_capa) {
941 os_memcpy(drv->extended_capa,
942 nla_data(tb[NL80211_ATTR_EXT_CAPA]),
943 nla_len(tb[NL80211_ATTR_EXT_CAPA]));
944 drv->extended_capa_len =
945 nla_len(tb[NL80211_ATTR_EXT_CAPA]);
946 wpa_hexdump(MSG_DEBUG,
947 "nl80211: Driver-advertised extended capabilities (default)",
948 drv->extended_capa, drv->extended_capa_len);
949 }
950 drv->extended_capa_mask =
951 os_malloc(nla_len(tb[NL80211_ATTR_EXT_CAPA_MASK]));
952 if (drv->extended_capa_mask) {
953 os_memcpy(drv->extended_capa_mask,
954 nla_data(tb[NL80211_ATTR_EXT_CAPA_MASK]),
955 nla_len(tb[NL80211_ATTR_EXT_CAPA_MASK]));
956 wpa_hexdump(MSG_DEBUG,
957 "nl80211: Driver-advertised extended capabilities mask (default)",
958 drv->extended_capa_mask,
959 drv->extended_capa_len);
960 } else {
961 os_free(drv->extended_capa);
962 drv->extended_capa = NULL;
963 drv->extended_capa_len = 0;
964 }
965 }
966
967 wiphy_info_extended_capab(drv, tb[NL80211_ATTR_IFTYPE_EXT_CAPA]);
968
969 if (tb[NL80211_ATTR_VENDOR_DATA]) {
970 struct nlattr *nl;
971 int rem;
972
973 nla_for_each_nested(nl, tb[NL80211_ATTR_VENDOR_DATA], rem) {
974 struct nl80211_vendor_cmd_info *vinfo;
975 if (nla_len(nl) != sizeof(*vinfo)) {
976 wpa_printf(MSG_DEBUG, "nl80211: Unexpected vendor data info");
977 continue;
978 }
979 vinfo = nla_data(nl);
980 if (vinfo->vendor_id == OUI_QCA) {
981 switch (vinfo->subcmd) {
982 case QCA_NL80211_VENDOR_SUBCMD_TEST:
983 drv->vendor_cmd_test_avail = 1;
984 break;
985 #ifdef CONFIG_DRIVER_NL80211_QCA
986 case QCA_NL80211_VENDOR_SUBCMD_ROAMING:
987 drv->roaming_vendor_cmd_avail = 1;
988 break;
989 case QCA_NL80211_VENDOR_SUBCMD_DFS_CAPABILITY:
990 drv->dfs_vendor_cmd_avail = 1;
991 break;
992 case QCA_NL80211_VENDOR_SUBCMD_GET_FEATURES:
993 drv->get_features_vendor_cmd_avail = 1;
994 break;
995 case QCA_NL80211_VENDOR_SUBCMD_GET_PREFERRED_FREQ_LIST:
996 drv->get_pref_freq_list = 1;
997 break;
998 case QCA_NL80211_VENDOR_SUBCMD_SET_PROBABLE_OPER_CHANNEL:
999 drv->set_prob_oper_freq = 1;
1000 break;
1001 case QCA_NL80211_VENDOR_SUBCMD_DO_ACS:
1002 drv->capa.flags |=
1003 WPA_DRIVER_FLAGS_ACS_OFFLOAD;
1004 drv->qca_do_acs = 1;
1005 break;
1006 case QCA_NL80211_VENDOR_SUBCMD_SETBAND:
1007 drv->setband_vendor_cmd_avail = 1;
1008 break;
1009 case QCA_NL80211_VENDOR_SUBCMD_TRIGGER_SCAN:
1010 drv->scan_vendor_cmd_avail = 1;
1011 break;
1012 case QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION:
1013 drv->set_wifi_conf_vendor_cmd_avail = 1;
1014 break;
1015 case QCA_NL80211_VENDOR_SUBCMD_FETCH_BSS_TRANSITION_STATUS:
1016 drv->fetch_bss_trans_status = 1;
1017 break;
1018 case QCA_NL80211_VENDOR_SUBCMD_ROAM:
1019 drv->roam_vendor_cmd_avail = 1;
1020 break;
1021 case QCA_NL80211_VENDOR_SUBCMD_ADD_STA_NODE:
1022 drv->add_sta_node_vendor_cmd_avail = 1;
1023 break;
1024 case QCA_NL80211_VENDOR_SUBCMD_GET_STA_INFO:
1025 drv->get_sta_info_vendor_cmd_avail = 1;
1026 break;
1027 #endif /* CONFIG_DRIVER_NL80211_QCA */
1028 }
1029 #ifdef CONFIG_DRIVER_NL80211_BRCM
1030 } else if (vinfo->vendor_id == OUI_BRCM) {
1031 switch (vinfo->subcmd) {
1032 case BRCM_VENDOR_SCMD_ACS:
1033 drv->capa.flags |=
1034 WPA_DRIVER_FLAGS_ACS_OFFLOAD;
1035 wpa_printf(MSG_DEBUG,
1036 "Enabled BRCM ACS");
1037 drv->brcm_do_acs = 1;
1038 break;
1039 }
1040 #endif /* CONFIG_DRIVER_NL80211_BRCM */
1041 }
1042
1043 wpa_printf(MSG_DEBUG, "nl80211: Supported vendor command: vendor_id=0x%x subcmd=%u",
1044 vinfo->vendor_id, vinfo->subcmd);
1045 }
1046 }
1047
1048 if (tb[NL80211_ATTR_VENDOR_EVENTS]) {
1049 struct nlattr *nl;
1050 int rem;
1051
1052 nla_for_each_nested(nl, tb[NL80211_ATTR_VENDOR_EVENTS], rem) {
1053 struct nl80211_vendor_cmd_info *vinfo;
1054 if (nla_len(nl) != sizeof(*vinfo)) {
1055 wpa_printf(MSG_DEBUG, "nl80211: Unexpected vendor data info");
1056 continue;
1057 }
1058 vinfo = nla_data(nl);
1059 wpa_printf(MSG_DEBUG, "nl80211: Supported vendor event: vendor_id=0x%x subcmd=%u",
1060 vinfo->vendor_id, vinfo->subcmd);
1061 }
1062 }
1063
1064 wiphy_info_wowlan_triggers(capa,
1065 tb[NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED]);
1066
1067 if (tb[NL80211_ATTR_MAX_AP_ASSOC_STA])
1068 capa->max_stations =
1069 nla_get_u32(tb[NL80211_ATTR_MAX_AP_ASSOC_STA]);
1070
1071 if (tb[NL80211_ATTR_MAX_CSA_COUNTERS])
1072 capa->max_csa_counters =
1073 nla_get_u8(tb[NL80211_ATTR_MAX_CSA_COUNTERS]);
1074
1075 if (tb[NL80211_ATTR_WIPHY_SELF_MANAGED_REG])
1076 capa->flags |= WPA_DRIVER_FLAGS_SELF_MANAGED_REGULATORY;
1077
1078 return NL_SKIP;
1079 }
1080
1081
wpa_driver_nl80211_get_info(struct wpa_driver_nl80211_data * drv,struct wiphy_info_data * info)1082 static int wpa_driver_nl80211_get_info(struct wpa_driver_nl80211_data *drv,
1083 struct wiphy_info_data *info)
1084 {
1085 u32 feat;
1086 struct nl_msg *msg;
1087 int flags = 0;
1088
1089 os_memset(info, 0, sizeof(*info));
1090 info->capa = &drv->capa;
1091 info->drv = drv;
1092
1093 feat = get_nl80211_protocol_features(drv);
1094 if (feat & NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)
1095 flags = NLM_F_DUMP;
1096 msg = nl80211_cmd_msg(drv->first_bss, flags, NL80211_CMD_GET_WIPHY);
1097 if (!msg || nla_put_flag(msg, NL80211_ATTR_SPLIT_WIPHY_DUMP)) {
1098 nlmsg_free(msg);
1099 return -1;
1100 }
1101
1102 if (send_and_recv_msgs(drv, msg, wiphy_info_handler, info, NULL, NULL))
1103 return -1;
1104
1105 if (info->auth_supported)
1106 drv->capa.flags |= WPA_DRIVER_FLAGS_SME;
1107 else if (!info->connect_supported) {
1108 wpa_printf(MSG_INFO, "nl80211: Driver does not support "
1109 "authentication/association or connect commands");
1110 info->error = 1;
1111 }
1112
1113 if (info->p2p_go_supported && info->p2p_client_supported)
1114 drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CAPABLE;
1115 if (info->p2p_concurrent) {
1116 wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group "
1117 "interface (driver advertised support)");
1118 drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT;
1119 drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P;
1120 }
1121 if (info->num_multichan_concurrent > 1) {
1122 wpa_printf(MSG_DEBUG, "nl80211: Enable multi-channel "
1123 "concurrent (driver advertised support)");
1124 drv->capa.num_multichan_concurrent =
1125 info->num_multichan_concurrent;
1126 }
1127 if (drv->capa.flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)
1128 {
1129 wpa_printf(MSG_DEBUG, "nl80211: use P2P_DEVICE support");
1130 #ifdef CONFIG_DRIVER_NL80211_HISI
1131 drv->capa.flags &= (~WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE);
1132 #endif /* CONFIG_DRIVER_NL80211_HISI*/
1133 }
1134 /* default to 5000 since early versions of mac80211 don't set it */
1135 if (!drv->capa.max_remain_on_chan)
1136 drv->capa.max_remain_on_chan = 5000;
1137
1138 drv->capa.wmm_ac_supported = info->wmm_ac_supported;
1139
1140 drv->capa.mac_addr_rand_sched_scan_supported =
1141 info->mac_addr_rand_sched_scan_supported;
1142 drv->capa.mac_addr_rand_scan_supported =
1143 info->mac_addr_rand_scan_supported;
1144
1145 if (info->channel_switch_supported) {
1146 drv->capa.flags |= WPA_DRIVER_FLAGS_AP_CSA;
1147 if (!drv->capa.max_csa_counters)
1148 drv->capa.max_csa_counters = 1;
1149 }
1150
1151 if (!drv->capa.max_sched_scan_plans) {
1152 drv->capa.max_sched_scan_plans = 1;
1153 drv->capa.max_sched_scan_plan_interval = UINT32_MAX;
1154 drv->capa.max_sched_scan_plan_iterations = 0;
1155 }
1156
1157 if (info->update_ft_ies_supported)
1158 drv->capa.flags |= WPA_DRIVER_FLAGS_UPDATE_FT_IES;
1159
1160 return 0;
1161 }
1162
1163
1164 #ifdef CONFIG_DRIVER_NL80211_QCA
1165
dfs_info_handler(struct nl_msg * msg,void * arg)1166 static int dfs_info_handler(struct nl_msg *msg, void *arg)
1167 {
1168 struct nlattr *tb[NL80211_ATTR_MAX + 1];
1169 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1170 int *dfs_capability_ptr = arg;
1171
1172 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1173 genlmsg_attrlen(gnlh, 0), NULL);
1174
1175 if (tb[NL80211_ATTR_VENDOR_DATA]) {
1176 struct nlattr *nl_vend = tb[NL80211_ATTR_VENDOR_DATA];
1177 struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1];
1178
1179 nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX,
1180 nla_data(nl_vend), nla_len(nl_vend), NULL);
1181
1182 if (tb_vendor[QCA_WLAN_VENDOR_ATTR_DFS]) {
1183 u32 val;
1184 val = nla_get_u32(tb_vendor[QCA_WLAN_VENDOR_ATTR_DFS]);
1185 wpa_printf(MSG_DEBUG, "nl80211: DFS offload capability: %u",
1186 val);
1187 *dfs_capability_ptr = val;
1188 }
1189 }
1190
1191 return NL_SKIP;
1192 }
1193
1194
qca_nl80211_check_dfs_capa(struct wpa_driver_nl80211_data * drv)1195 static void qca_nl80211_check_dfs_capa(struct wpa_driver_nl80211_data *drv)
1196 {
1197 struct nl_msg *msg;
1198 int dfs_capability = 0;
1199 int ret;
1200
1201 if (!drv->dfs_vendor_cmd_avail)
1202 return;
1203
1204 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
1205 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
1206 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
1207 QCA_NL80211_VENDOR_SUBCMD_DFS_CAPABILITY)) {
1208 nlmsg_free(msg);
1209 return;
1210 }
1211
1212 ret = send_and_recv_msgs(drv, msg, dfs_info_handler, &dfs_capability,
1213 NULL, NULL);
1214 if (!ret && dfs_capability)
1215 drv->capa.flags |= WPA_DRIVER_FLAGS_DFS_OFFLOAD;
1216 }
1217
1218
1219 struct features_info {
1220 u8 *flags;
1221 size_t flags_len;
1222 struct wpa_driver_capa *capa;
1223 };
1224
1225
features_info_handler(struct nl_msg * msg,void * arg)1226 static int features_info_handler(struct nl_msg *msg, void *arg)
1227 {
1228 struct nlattr *tb[NL80211_ATTR_MAX + 1];
1229 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1230 struct features_info *info = arg;
1231 struct nlattr *nl_vend, *attr;
1232
1233 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1234 genlmsg_attrlen(gnlh, 0), NULL);
1235
1236 nl_vend = tb[NL80211_ATTR_VENDOR_DATA];
1237 if (nl_vend) {
1238 struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1];
1239
1240 nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX,
1241 nla_data(nl_vend), nla_len(nl_vend), NULL);
1242
1243 attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_FEATURE_FLAGS];
1244 if (attr) {
1245 int len = nla_len(attr);
1246 info->flags = os_malloc(len);
1247 if (info->flags != NULL) {
1248 os_memcpy(info->flags, nla_data(attr), len);
1249 info->flags_len = len;
1250 }
1251 }
1252 attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_CONCURRENCY_CAPA];
1253 if (attr)
1254 info->capa->conc_capab = nla_get_u32(attr);
1255
1256 attr = tb_vendor[
1257 QCA_WLAN_VENDOR_ATTR_MAX_CONCURRENT_CHANNELS_2_4_BAND];
1258 if (attr)
1259 info->capa->max_conc_chan_2_4 = nla_get_u32(attr);
1260
1261 attr = tb_vendor[
1262 QCA_WLAN_VENDOR_ATTR_MAX_CONCURRENT_CHANNELS_5_0_BAND];
1263 if (attr)
1264 info->capa->max_conc_chan_5_0 = nla_get_u32(attr);
1265 }
1266
1267 return NL_SKIP;
1268 }
1269
1270
check_feature(enum qca_wlan_vendor_features feature,struct features_info * info)1271 static int check_feature(enum qca_wlan_vendor_features feature,
1272 struct features_info *info)
1273 {
1274 size_t idx = feature / 8;
1275
1276 return (idx < info->flags_len) &&
1277 (info->flags[idx] & BIT(feature % 8));
1278 }
1279
1280
qca_nl80211_get_features(struct wpa_driver_nl80211_data * drv)1281 static void qca_nl80211_get_features(struct wpa_driver_nl80211_data *drv)
1282 {
1283 struct nl_msg *msg;
1284 struct features_info info;
1285 int ret;
1286
1287 if (!drv->get_features_vendor_cmd_avail)
1288 return;
1289
1290 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
1291 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
1292 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
1293 QCA_NL80211_VENDOR_SUBCMD_GET_FEATURES)) {
1294 nlmsg_free(msg);
1295 return;
1296 }
1297
1298 os_memset(&info, 0, sizeof(info));
1299 info.capa = &drv->capa;
1300 ret = send_and_recv_msgs(drv, msg, features_info_handler, &info,
1301 NULL, NULL);
1302 if (ret || !info.flags)
1303 return;
1304
1305 if (check_feature(QCA_WLAN_VENDOR_FEATURE_KEY_MGMT_OFFLOAD, &info))
1306 drv->capa.flags |= WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD;
1307
1308 if (check_feature(QCA_WLAN_VENDOR_FEATURE_SUPPORT_HW_MODE_ANY, &info))
1309 drv->capa.flags |= WPA_DRIVER_FLAGS_SUPPORT_HW_MODE_ANY;
1310
1311 if (check_feature(QCA_WLAN_VENDOR_FEATURE_OFFCHANNEL_SIMULTANEOUS,
1312 &info))
1313 drv->capa.flags |= WPA_DRIVER_FLAGS_OFFCHANNEL_SIMULTANEOUS;
1314 if (check_feature(QCA_WLAN_VENDOR_FEATURE_P2P_LISTEN_OFFLOAD, &info))
1315 drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD;
1316 if (check_feature(QCA_WLAN_VENDOR_FEATURE_OCE_STA, &info))
1317 drv->capa.flags |= WPA_DRIVER_FLAGS_OCE_STA;
1318 if (check_feature(QCA_WLAN_VENDOR_FEATURE_OCE_AP, &info))
1319 drv->capa.flags |= WPA_DRIVER_FLAGS_OCE_AP;
1320 if (check_feature(QCA_WLAN_VENDOR_FEATURE_OCE_STA_CFON, &info))
1321 drv->capa.flags |= WPA_DRIVER_FLAGS_OCE_STA_CFON;
1322 os_free(info.flags);
1323 }
1324
1325 #endif /* CONFIG_DRIVER_NL80211_QCA */
1326
1327
wpa_driver_nl80211_capa(struct wpa_driver_nl80211_data * drv)1328 int wpa_driver_nl80211_capa(struct wpa_driver_nl80211_data *drv)
1329 {
1330 struct wiphy_info_data info;
1331 int i;
1332
1333 if (wpa_driver_nl80211_get_info(drv, &info))
1334 return -1;
1335
1336 if (info.error)
1337 return -1;
1338
1339 drv->has_capability = 1;
1340 drv->has_driver_key_mgmt = info.has_key_mgmt | info.has_key_mgmt_iftype;
1341
1342 /* Fallback to hardcoded defaults if the driver does nott advertize any
1343 * AKM capabilities. */
1344 if (!drv->has_driver_key_mgmt) {
1345 drv->capa.key_mgmt = WPA_DRIVER_CAPA_KEY_MGMT_WPA |
1346 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
1347 WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
1348 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK |
1349 WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B |
1350 WPA_DRIVER_CAPA_KEY_MGMT_OWE |
1351 #ifdef CONFIG_WAPI
1352 WPA_DRIVER_CAPA_KEY_MGMT_WAPI_PSK |
1353 #endif
1354 WPA_DRIVER_CAPA_KEY_MGMT_DPP;
1355
1356 if (drv->capa.enc & (WPA_DRIVER_CAPA_ENC_CCMP_256 |
1357 WPA_DRIVER_CAPA_ENC_GCMP_256))
1358 drv->capa.key_mgmt |=
1359 WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192;
1360
1361 if (drv->capa.flags & WPA_DRIVER_FLAGS_SME)
1362 drv->capa.key_mgmt |=
1363 WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA256 |
1364 WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA384 |
1365 WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA256 |
1366 WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA384 |
1367 WPA_DRIVER_CAPA_KEY_MGMT_SAE;
1368 else if (drv->capa.flags & WPA_DRIVER_FLAGS_FILS_SK_OFFLOAD)
1369 drv->capa.key_mgmt |=
1370 WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA256 |
1371 WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA384;
1372 }
1373
1374 if (!info.has_key_mgmt_iftype) {
1375 /* If the driver does not advertize per interface AKM
1376 * capabilities, consider all interfaces to support default AKMs
1377 * in key_mgmt. */
1378 for (i = 0; i < WPA_IF_MAX; i++)
1379 drv->capa.key_mgmt_iftype[i] = drv->capa.key_mgmt;
1380 } else if (info.has_key_mgmt_iftype && !info.has_key_mgmt) {
1381 /* If the driver advertizes only per interface supported AKMs
1382 * but does not advertize per wiphy AKM capabilities, consider
1383 * the default key_mgmt as a mask of per interface supported
1384 * AKMs. */
1385 drv->capa.key_mgmt = 0;
1386 for (i = 0; i < WPA_IF_MAX; i++)
1387 drv->capa.key_mgmt |= drv->capa.key_mgmt_iftype[i];
1388 } else if (info.has_key_mgmt_iftype && info.has_key_mgmt) {
1389 /* If the driver advertizes AKM capabilities both per wiphy and
1390 * per interface, consider the interfaces for which per
1391 * interface AKM capabilities were not received to support the
1392 * default key_mgmt capabilities.
1393 */
1394 for (i = 0; i < WPA_IF_MAX; i++)
1395 if (!drv->capa.key_mgmt_iftype[i])
1396 drv->capa.key_mgmt_iftype[i] =
1397 drv->capa.key_mgmt;
1398 }
1399
1400 drv->capa.auth = WPA_DRIVER_AUTH_OPEN |
1401 WPA_DRIVER_AUTH_SHARED |
1402 WPA_DRIVER_AUTH_LEAP;
1403
1404 drv->capa.flags |= WPA_DRIVER_FLAGS_VALID_ERROR_CODES;
1405 drv->capa.flags |= WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE;
1406 drv->capa.flags |= WPA_DRIVER_FLAGS_EAPOL_TX_STATUS;
1407
1408 /*
1409 * As all cfg80211 drivers must support cases where the AP interface is
1410 * removed without the knowledge of wpa_supplicant/hostapd, e.g., in
1411 * case that the user space daemon has crashed, they must be able to
1412 * cleanup all stations and key entries in the AP tear down flow. Thus,
1413 * this flag can/should always be set for cfg80211 drivers.
1414 */
1415 drv->capa.flags |= WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT;
1416
1417 if (!info.device_ap_sme) {
1418 drv->capa.flags |= WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS;
1419 drv->capa.flags2 |= WPA_DRIVER_FLAGS2_AP_SME;
1420
1421 /*
1422 * No AP SME is currently assumed to also indicate no AP MLME
1423 * in the driver/firmware.
1424 */
1425 drv->capa.flags |= WPA_DRIVER_FLAGS_AP_MLME;
1426 }
1427
1428 drv->device_ap_sme = info.device_ap_sme;
1429 drv->poll_command_supported = info.poll_command_supported;
1430 drv->data_tx_status = info.data_tx_status;
1431 drv->p2p_go_ctwindow_supported = info.p2p_go_ctwindow_supported;
1432 if (info.set_qos_map_supported)
1433 drv->capa.flags |= WPA_DRIVER_FLAGS_QOS_MAPPING;
1434 drv->have_low_prio_scan = info.have_low_prio_scan;
1435
1436 /*
1437 * If poll command and tx status are supported, mac80211 is new enough
1438 * to have everything we need to not need monitor interfaces.
1439 */
1440 drv->use_monitor = !info.device_ap_sme &&
1441 (!info.poll_command_supported || !info.data_tx_status);
1442
1443 /*
1444 * If we aren't going to use monitor interfaces, but the
1445 * driver doesn't support data TX status, we won't get TX
1446 * status for EAPOL frames.
1447 */
1448 if (!drv->use_monitor && !info.data_tx_status)
1449 drv->capa.flags &= ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS;
1450
1451 #ifdef CONFIG_DRIVER_NL80211_QCA
1452 if (!(info.capa->flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD))
1453 qca_nl80211_check_dfs_capa(drv);
1454 qca_nl80211_get_features(drv);
1455
1456 /*
1457 * To enable offchannel simultaneous support in wpa_supplicant, the
1458 * underlying driver needs to support the same along with offchannel TX.
1459 * Offchannel TX support is needed since remain_on_channel and
1460 * action_tx use some common data structures and hence cannot be
1461 * scheduled simultaneously.
1462 */
1463 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX))
1464 drv->capa.flags &= ~WPA_DRIVER_FLAGS_OFFCHANNEL_SIMULTANEOUS;
1465 #endif /* CONFIG_DRIVER_NL80211_QCA */
1466
1467 wpa_printf(MSG_DEBUG,
1468 "nl80211: key_mgmt=0x%x enc=0x%x auth=0x%x flags=0x%llx rrm_flags=0x%x probe_resp_offloads=0x%x max_stations=%u max_remain_on_chan=%u max_scan_ssids=%d",
1469 drv->capa.key_mgmt, drv->capa.enc, drv->capa.auth,
1470 (unsigned long long) drv->capa.flags, drv->capa.rrm_flags,
1471 drv->capa.probe_resp_offloads, drv->capa.max_stations,
1472 drv->capa.max_remain_on_chan, drv->capa.max_scan_ssids);
1473 return 0;
1474 }
1475
1476
1477 struct phy_info_arg {
1478 u16 *num_modes;
1479 struct hostapd_hw_modes *modes;
1480 int last_mode, last_chan_idx;
1481 int failed;
1482 u8 dfs_domain;
1483 };
1484
phy_info_ht_capa(struct hostapd_hw_modes * mode,struct nlattr * capa,struct nlattr * ampdu_factor,struct nlattr * ampdu_density,struct nlattr * mcs_set)1485 static void phy_info_ht_capa(struct hostapd_hw_modes *mode, struct nlattr *capa,
1486 struct nlattr *ampdu_factor,
1487 struct nlattr *ampdu_density,
1488 struct nlattr *mcs_set)
1489 {
1490 if (capa)
1491 mode->ht_capab = nla_get_u16(capa);
1492
1493 if (ampdu_factor)
1494 mode->a_mpdu_params |= nla_get_u8(ampdu_factor) & 0x03;
1495
1496 if (ampdu_density)
1497 mode->a_mpdu_params |= nla_get_u8(ampdu_density) << 2;
1498
1499 if (mcs_set && nla_len(mcs_set) >= 16) {
1500 u8 *mcs;
1501 mcs = nla_data(mcs_set);
1502 os_memcpy(mode->mcs_set, mcs, 16);
1503 }
1504 }
1505
1506
phy_info_vht_capa(struct hostapd_hw_modes * mode,struct nlattr * capa,struct nlattr * mcs_set)1507 static void phy_info_vht_capa(struct hostapd_hw_modes *mode,
1508 struct nlattr *capa,
1509 struct nlattr *mcs_set)
1510 {
1511 if (capa)
1512 mode->vht_capab = nla_get_u32(capa);
1513
1514 if (mcs_set && nla_len(mcs_set) >= 8) {
1515 u8 *mcs;
1516 mcs = nla_data(mcs_set);
1517 os_memcpy(mode->vht_mcs_set, mcs, 8);
1518 }
1519 }
1520
1521
phy_info_edmg_capa(struct hostapd_hw_modes * mode,struct nlattr * bw_config,struct nlattr * channels)1522 static int phy_info_edmg_capa(struct hostapd_hw_modes *mode,
1523 struct nlattr *bw_config,
1524 struct nlattr *channels)
1525 {
1526 if (!bw_config || !channels)
1527 return NL_OK;
1528
1529 mode->edmg.bw_config = nla_get_u8(bw_config);
1530 mode->edmg.channels = nla_get_u8(channels);
1531
1532 if (!mode->edmg.channels || !mode->edmg.bw_config)
1533 return NL_STOP;
1534
1535 return NL_OK;
1536 }
1537
1538
cw2ecw(unsigned int cw)1539 static int cw2ecw(unsigned int cw)
1540 {
1541 int bit;
1542
1543 if (cw == 0)
1544 return 0;
1545
1546 for (bit = 1; cw != 1; bit++)
1547 cw >>= 1;
1548
1549 return bit;
1550 }
1551
1552
phy_info_freq(struct hostapd_hw_modes * mode,struct hostapd_channel_data * chan,struct nlattr * tb_freq[])1553 static void phy_info_freq(struct hostapd_hw_modes *mode,
1554 struct hostapd_channel_data *chan,
1555 struct nlattr *tb_freq[])
1556 {
1557 u8 channel;
1558
1559 os_memset(chan, 0, sizeof(*chan));
1560 chan->freq = nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_FREQ]);
1561 chan->flag = 0;
1562 chan->allowed_bw = ~0;
1563 chan->dfs_cac_ms = 0;
1564 if (ieee80211_freq_to_chan(chan->freq, &channel) != NUM_HOSTAPD_MODES)
1565 chan->chan = channel;
1566 else
1567 wpa_printf(MSG_DEBUG,
1568 "nl80211: No channel number found for frequency %u MHz",
1569 chan->freq);
1570
1571 if (tb_freq[NL80211_FREQUENCY_ATTR_DISABLED])
1572 chan->flag |= HOSTAPD_CHAN_DISABLED;
1573 if (tb_freq[NL80211_FREQUENCY_ATTR_NO_IR])
1574 chan->flag |= HOSTAPD_CHAN_NO_IR;
1575 if (tb_freq[NL80211_FREQUENCY_ATTR_RADAR])
1576 chan->flag |= HOSTAPD_CHAN_RADAR;
1577 if (tb_freq[NL80211_FREQUENCY_ATTR_INDOOR_ONLY])
1578 chan->flag |= HOSTAPD_CHAN_INDOOR_ONLY;
1579 if (tb_freq[NL80211_FREQUENCY_ATTR_GO_CONCURRENT])
1580 chan->flag |= HOSTAPD_CHAN_GO_CONCURRENT;
1581
1582 if (tb_freq[NL80211_FREQUENCY_ATTR_NO_10MHZ])
1583 chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_10;
1584 if (tb_freq[NL80211_FREQUENCY_ATTR_NO_20MHZ])
1585 chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_20;
1586 if (tb_freq[NL80211_FREQUENCY_ATTR_NO_HT40_PLUS])
1587 chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_40P;
1588 if (tb_freq[NL80211_FREQUENCY_ATTR_NO_HT40_MINUS])
1589 chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_40M;
1590 if (tb_freq[NL80211_FREQUENCY_ATTR_NO_80MHZ])
1591 chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_80;
1592 if (tb_freq[NL80211_FREQUENCY_ATTR_NO_160MHZ])
1593 chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_160;
1594
1595 if (tb_freq[NL80211_FREQUENCY_ATTR_DFS_STATE]) {
1596 enum nl80211_dfs_state state =
1597 nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_DFS_STATE]);
1598
1599 switch (state) {
1600 case NL80211_DFS_USABLE:
1601 chan->flag |= HOSTAPD_CHAN_DFS_USABLE;
1602 break;
1603 case NL80211_DFS_AVAILABLE:
1604 chan->flag |= HOSTAPD_CHAN_DFS_AVAILABLE;
1605 break;
1606 case NL80211_DFS_UNAVAILABLE:
1607 chan->flag |= HOSTAPD_CHAN_DFS_UNAVAILABLE;
1608 break;
1609 }
1610 }
1611
1612 if (tb_freq[NL80211_FREQUENCY_ATTR_DFS_CAC_TIME]) {
1613 chan->dfs_cac_ms = nla_get_u32(
1614 tb_freq[NL80211_FREQUENCY_ATTR_DFS_CAC_TIME]);
1615 }
1616
1617 chan->wmm_rules_valid = 0;
1618 if (tb_freq[NL80211_FREQUENCY_ATTR_WMM]) {
1619 static struct nla_policy wmm_policy[NL80211_WMMR_MAX + 1] = {
1620 [NL80211_WMMR_CW_MIN] = { .type = NLA_U16 },
1621 [NL80211_WMMR_CW_MAX] = { .type = NLA_U16 },
1622 [NL80211_WMMR_AIFSN] = { .type = NLA_U8 },
1623 [NL80211_WMMR_TXOP] = { .type = NLA_U16 },
1624 };
1625 static const u8 wmm_map[4] = {
1626 [NL80211_AC_BE] = WMM_AC_BE,
1627 [NL80211_AC_BK] = WMM_AC_BK,
1628 [NL80211_AC_VI] = WMM_AC_VI,
1629 [NL80211_AC_VO] = WMM_AC_VO,
1630 };
1631 struct nlattr *nl_wmm;
1632 struct nlattr *tb_wmm[NL80211_WMMR_MAX + 1];
1633 int rem_wmm, ac, count = 0;
1634
1635 nla_for_each_nested(nl_wmm, tb_freq[NL80211_FREQUENCY_ATTR_WMM],
1636 rem_wmm) {
1637 if (nla_parse_nested(tb_wmm, NL80211_WMMR_MAX, nl_wmm,
1638 wmm_policy)) {
1639 wpa_printf(MSG_DEBUG,
1640 "nl80211: Failed to parse WMM rules attribute");
1641 return;
1642 }
1643 if (!tb_wmm[NL80211_WMMR_CW_MIN] ||
1644 !tb_wmm[NL80211_WMMR_CW_MAX] ||
1645 !tb_wmm[NL80211_WMMR_AIFSN] ||
1646 !tb_wmm[NL80211_WMMR_TXOP]) {
1647 wpa_printf(MSG_DEBUG,
1648 "nl80211: Channel is missing WMM rule attribute");
1649 return;
1650 }
1651 ac = nl_wmm->nla_type;
1652 if ((unsigned int) ac >= ARRAY_SIZE(wmm_map)) {
1653 wpa_printf(MSG_DEBUG,
1654 "nl80211: Invalid AC value %d", ac);
1655 return;
1656 }
1657
1658 ac = wmm_map[ac];
1659 chan->wmm_rules[ac].min_cwmin =
1660 cw2ecw(nla_get_u16(
1661 tb_wmm[NL80211_WMMR_CW_MIN]));
1662 chan->wmm_rules[ac].min_cwmax =
1663 cw2ecw(nla_get_u16(
1664 tb_wmm[NL80211_WMMR_CW_MAX]));
1665 chan->wmm_rules[ac].min_aifs =
1666 nla_get_u8(tb_wmm[NL80211_WMMR_AIFSN]);
1667 chan->wmm_rules[ac].max_txop =
1668 nla_get_u16(tb_wmm[NL80211_WMMR_TXOP]) / 32;
1669 count++;
1670 }
1671
1672 /* Set valid flag if all the AC rules are present */
1673 if (count == WMM_AC_NUM)
1674 chan->wmm_rules_valid = 1;
1675 }
1676 }
1677
1678
phy_info_freqs(struct phy_info_arg * phy_info,struct hostapd_hw_modes * mode,struct nlattr * tb)1679 static int phy_info_freqs(struct phy_info_arg *phy_info,
1680 struct hostapd_hw_modes *mode, struct nlattr *tb)
1681 {
1682 static struct nla_policy freq_policy[NL80211_FREQUENCY_ATTR_MAX + 1] = {
1683 [NL80211_FREQUENCY_ATTR_FREQ] = { .type = NLA_U32 },
1684 [NL80211_FREQUENCY_ATTR_DISABLED] = { .type = NLA_FLAG },
1685 [NL80211_FREQUENCY_ATTR_NO_IR] = { .type = NLA_FLAG },
1686 [NL80211_FREQUENCY_ATTR_RADAR] = { .type = NLA_FLAG },
1687 [NL80211_FREQUENCY_ATTR_MAX_TX_POWER] = { .type = NLA_U32 },
1688 [NL80211_FREQUENCY_ATTR_DFS_STATE] = { .type = NLA_U32 },
1689 [NL80211_FREQUENCY_ATTR_NO_10MHZ] = { .type = NLA_FLAG },
1690 [NL80211_FREQUENCY_ATTR_NO_20MHZ] = { .type = NLA_FLAG },
1691 [NL80211_FREQUENCY_ATTR_NO_HT40_PLUS] = { .type = NLA_FLAG },
1692 [NL80211_FREQUENCY_ATTR_NO_HT40_MINUS] = { .type = NLA_FLAG },
1693 [NL80211_FREQUENCY_ATTR_NO_80MHZ] = { .type = NLA_FLAG },
1694 [NL80211_FREQUENCY_ATTR_NO_160MHZ] = { .type = NLA_FLAG },
1695 };
1696 int new_channels = 0;
1697 struct hostapd_channel_data *channel;
1698 struct nlattr *tb_freq[NL80211_FREQUENCY_ATTR_MAX + 1];
1699 struct nlattr *nl_freq;
1700 int rem_freq, idx;
1701
1702 if (tb == NULL)
1703 return NL_OK;
1704
1705 nla_for_each_nested(nl_freq, tb, rem_freq) {
1706 nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX,
1707 nla_data(nl_freq), nla_len(nl_freq), freq_policy);
1708 if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ])
1709 continue;
1710 new_channels++;
1711 }
1712
1713 channel = os_realloc_array(mode->channels,
1714 mode->num_channels + new_channels,
1715 sizeof(struct hostapd_channel_data));
1716 if (!channel)
1717 return NL_STOP;
1718
1719 mode->channels = channel;
1720 mode->num_channels += new_channels;
1721
1722 idx = phy_info->last_chan_idx;
1723
1724 nla_for_each_nested(nl_freq, tb, rem_freq) {
1725 nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX,
1726 nla_data(nl_freq), nla_len(nl_freq), freq_policy);
1727 if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ])
1728 continue;
1729 phy_info_freq(mode, &mode->channels[idx], tb_freq);
1730 idx++;
1731 }
1732 phy_info->last_chan_idx = idx;
1733
1734 return NL_OK;
1735 }
1736
1737
phy_info_rates(struct hostapd_hw_modes * mode,struct nlattr * tb)1738 static int phy_info_rates(struct hostapd_hw_modes *mode, struct nlattr *tb)
1739 {
1740 static struct nla_policy rate_policy[NL80211_BITRATE_ATTR_MAX + 1] = {
1741 [NL80211_BITRATE_ATTR_RATE] = { .type = NLA_U32 },
1742 [NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE] =
1743 { .type = NLA_FLAG },
1744 };
1745 struct nlattr *tb_rate[NL80211_BITRATE_ATTR_MAX + 1];
1746 struct nlattr *nl_rate;
1747 int rem_rate, idx;
1748
1749 if (tb == NULL)
1750 return NL_OK;
1751
1752 nla_for_each_nested(nl_rate, tb, rem_rate) {
1753 nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX,
1754 nla_data(nl_rate), nla_len(nl_rate),
1755 rate_policy);
1756 if (!tb_rate[NL80211_BITRATE_ATTR_RATE])
1757 continue;
1758 mode->num_rates++;
1759 }
1760
1761 mode->rates = os_calloc(mode->num_rates, sizeof(int));
1762 if (!mode->rates)
1763 return NL_STOP;
1764
1765 idx = 0;
1766
1767 nla_for_each_nested(nl_rate, tb, rem_rate) {
1768 nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX,
1769 nla_data(nl_rate), nla_len(nl_rate),
1770 rate_policy);
1771 if (!tb_rate[NL80211_BITRATE_ATTR_RATE])
1772 continue;
1773 mode->rates[idx] = nla_get_u32(
1774 tb_rate[NL80211_BITRATE_ATTR_RATE]);
1775 idx++;
1776 }
1777
1778 return NL_OK;
1779 }
1780
1781
phy_info_iftype_copy(struct he_capabilities * he_capab,enum ieee80211_op_mode opmode,struct nlattr ** tb,struct nlattr ** tb_flags)1782 static void phy_info_iftype_copy(struct he_capabilities *he_capab,
1783 enum ieee80211_op_mode opmode,
1784 struct nlattr **tb, struct nlattr **tb_flags)
1785 {
1786 enum nl80211_iftype iftype;
1787 size_t len;
1788
1789 switch (opmode) {
1790 case IEEE80211_MODE_INFRA:
1791 iftype = NL80211_IFTYPE_STATION;
1792 break;
1793 case IEEE80211_MODE_IBSS:
1794 iftype = NL80211_IFTYPE_ADHOC;
1795 break;
1796 case IEEE80211_MODE_AP:
1797 iftype = NL80211_IFTYPE_AP;
1798 break;
1799 case IEEE80211_MODE_MESH:
1800 iftype = NL80211_IFTYPE_MESH_POINT;
1801 break;
1802 default:
1803 return;
1804 }
1805
1806 if (!nla_get_flag(tb_flags[iftype]))
1807 return;
1808
1809 he_capab->he_supported = 1;
1810
1811 if (tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY]) {
1812 len = nla_len(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY]);
1813
1814 if (len > sizeof(he_capab->phy_cap))
1815 len = sizeof(he_capab->phy_cap);
1816 os_memcpy(he_capab->phy_cap,
1817 nla_data(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY]),
1818 len);
1819 }
1820
1821 if (tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC]) {
1822 len = nla_len(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC]);
1823
1824 if (len > sizeof(he_capab->mac_cap))
1825 len = sizeof(he_capab->mac_cap);
1826 os_memcpy(he_capab->mac_cap,
1827 nla_data(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC]),
1828 len);
1829 }
1830
1831 if (tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET]) {
1832 len = nla_len(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET]);
1833
1834 if (len > sizeof(he_capab->mcs))
1835 len = sizeof(he_capab->mcs);
1836 os_memcpy(he_capab->mcs,
1837 nla_data(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET]),
1838 len);
1839 }
1840
1841 if (tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE]) {
1842 len = nla_len(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE]);
1843
1844 if (len > sizeof(he_capab->ppet))
1845 len = sizeof(he_capab->ppet);
1846 os_memcpy(&he_capab->ppet,
1847 nla_data(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE]),
1848 len);
1849 }
1850
1851 if (tb[NL80211_BAND_IFTYPE_ATTR_HE_6GHZ_CAPA]) {
1852 u16 capa;
1853
1854 capa = nla_get_u16(tb[NL80211_BAND_IFTYPE_ATTR_HE_6GHZ_CAPA]);
1855 he_capab->he_6ghz_capa = le_to_host16(capa);
1856 }
1857 }
1858
1859
phy_info_iftype(struct hostapd_hw_modes * mode,struct nlattr * nl_iftype)1860 static int phy_info_iftype(struct hostapd_hw_modes *mode,
1861 struct nlattr *nl_iftype)
1862 {
1863 struct nlattr *tb[NL80211_BAND_IFTYPE_ATTR_MAX + 1];
1864 struct nlattr *tb_flags[NL80211_IFTYPE_MAX + 1];
1865 unsigned int i;
1866
1867 nla_parse(tb, NL80211_BAND_IFTYPE_ATTR_MAX,
1868 nla_data(nl_iftype), nla_len(nl_iftype), NULL);
1869
1870 if (!tb[NL80211_BAND_IFTYPE_ATTR_IFTYPES])
1871 return NL_STOP;
1872
1873 if (nla_parse_nested(tb_flags, NL80211_IFTYPE_MAX,
1874 tb[NL80211_BAND_IFTYPE_ATTR_IFTYPES], NULL))
1875 return NL_STOP;
1876
1877 for (i = 0; i < IEEE80211_MODE_NUM; i++)
1878 phy_info_iftype_copy(&mode->he_capab[i], i, tb, tb_flags);
1879
1880 return NL_OK;
1881 }
1882
1883
phy_info_band(struct phy_info_arg * phy_info,struct nlattr * nl_band)1884 static int phy_info_band(struct phy_info_arg *phy_info, struct nlattr *nl_band)
1885 {
1886 struct nlattr *tb_band[NL80211_BAND_ATTR_MAX + 1];
1887 struct hostapd_hw_modes *mode;
1888 int ret;
1889
1890 if (phy_info->last_mode != nl_band->nla_type) {
1891 mode = os_realloc_array(phy_info->modes,
1892 *phy_info->num_modes + 1,
1893 sizeof(*mode));
1894 if (!mode) {
1895 phy_info->failed = 1;
1896 return NL_STOP;
1897 }
1898 phy_info->modes = mode;
1899
1900 mode = &phy_info->modes[*(phy_info->num_modes)];
1901 os_memset(mode, 0, sizeof(*mode));
1902 mode->mode = NUM_HOSTAPD_MODES;
1903 mode->flags = HOSTAPD_MODE_FLAG_HT_INFO_KNOWN |
1904 HOSTAPD_MODE_FLAG_VHT_INFO_KNOWN;
1905
1906 /*
1907 * Unsupported VHT MCS stream is defined as value 3, so the VHT
1908 * MCS RX/TX map must be initialized with 0xffff to mark all 8
1909 * possible streams as unsupported. This will be overridden if
1910 * driver advertises VHT support.
1911 */
1912 mode->vht_mcs_set[0] = 0xff;
1913 mode->vht_mcs_set[1] = 0xff;
1914 mode->vht_mcs_set[4] = 0xff;
1915 mode->vht_mcs_set[5] = 0xff;
1916
1917 *(phy_info->num_modes) += 1;
1918 phy_info->last_mode = nl_band->nla_type;
1919 phy_info->last_chan_idx = 0;
1920 } else
1921 mode = &phy_info->modes[*(phy_info->num_modes) - 1];
1922
1923 nla_parse(tb_band, NL80211_BAND_ATTR_MAX, nla_data(nl_band),
1924 nla_len(nl_band), NULL);
1925
1926 phy_info_ht_capa(mode, tb_band[NL80211_BAND_ATTR_HT_CAPA],
1927 tb_band[NL80211_BAND_ATTR_HT_AMPDU_FACTOR],
1928 tb_band[NL80211_BAND_ATTR_HT_AMPDU_DENSITY],
1929 tb_band[NL80211_BAND_ATTR_HT_MCS_SET]);
1930 phy_info_vht_capa(mode, tb_band[NL80211_BAND_ATTR_VHT_CAPA],
1931 tb_band[NL80211_BAND_ATTR_VHT_MCS_SET]);
1932 ret = phy_info_edmg_capa(mode,
1933 tb_band[NL80211_BAND_ATTR_EDMG_BW_CONFIG],
1934 tb_band[NL80211_BAND_ATTR_EDMG_CHANNELS]);
1935 if (ret == NL_OK)
1936 ret = phy_info_freqs(phy_info, mode,
1937 tb_band[NL80211_BAND_ATTR_FREQS]);
1938 if (ret == NL_OK)
1939 ret = phy_info_rates(mode, tb_band[NL80211_BAND_ATTR_RATES]);
1940 if (ret != NL_OK) {
1941 phy_info->failed = 1;
1942 return ret;
1943 }
1944
1945 if (tb_band[NL80211_BAND_ATTR_IFTYPE_DATA]) {
1946 struct nlattr *nl_iftype;
1947 int rem_band;
1948
1949 nla_for_each_nested(nl_iftype,
1950 tb_band[NL80211_BAND_ATTR_IFTYPE_DATA],
1951 rem_band) {
1952 ret = phy_info_iftype(mode, nl_iftype);
1953 if (ret != NL_OK)
1954 return ret;
1955 }
1956 }
1957
1958 return NL_OK;
1959 }
1960
1961
phy_info_handler(struct nl_msg * msg,void * arg)1962 static int phy_info_handler(struct nl_msg *msg, void *arg)
1963 {
1964 struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
1965 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1966 struct phy_info_arg *phy_info = arg;
1967 struct nlattr *nl_band;
1968 int rem_band;
1969
1970 nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1971 genlmsg_attrlen(gnlh, 0), NULL);
1972
1973 if (!tb_msg[NL80211_ATTR_WIPHY_BANDS])
1974 return NL_SKIP;
1975
1976 nla_for_each_nested(nl_band, tb_msg[NL80211_ATTR_WIPHY_BANDS], rem_band)
1977 {
1978 int res = phy_info_band(phy_info, nl_band);
1979 if (res != NL_OK)
1980 return res;
1981 }
1982
1983 return NL_SKIP;
1984 }
1985
1986
1987 static struct hostapd_hw_modes *
wpa_driver_nl80211_postprocess_modes(struct hostapd_hw_modes * modes,u16 * num_modes)1988 wpa_driver_nl80211_postprocess_modes(struct hostapd_hw_modes *modes,
1989 u16 *num_modes)
1990 {
1991 u16 m;
1992 struct hostapd_hw_modes *mode11g = NULL, *nmodes, *mode;
1993 int i, mode11g_idx = -1;
1994
1995 /* heuristic to set up modes */
1996 for (m = 0; m < *num_modes; m++) {
1997 if (!modes[m].num_channels)
1998 continue;
1999 if (modes[m].channels[0].freq < 2000) {
2000 modes[m].num_channels = 0;
2001 continue;
2002 } else if (modes[m].channels[0].freq < 4000) {
2003 modes[m].mode = HOSTAPD_MODE_IEEE80211B;
2004 for (i = 0; i < modes[m].num_rates; i++) {
2005 if (modes[m].rates[i] > 200) {
2006 modes[m].mode = HOSTAPD_MODE_IEEE80211G;
2007 break;
2008 }
2009 }
2010 } else if (modes[m].channels[0].freq > 50000)
2011 modes[m].mode = HOSTAPD_MODE_IEEE80211AD;
2012 else
2013 modes[m].mode = HOSTAPD_MODE_IEEE80211A;
2014 }
2015
2016 /* Remove unsupported bands */
2017 m = 0;
2018 while (m < *num_modes) {
2019 if (modes[m].mode == NUM_HOSTAPD_MODES) {
2020 wpa_printf(MSG_DEBUG,
2021 "nl80211: Remove unsupported mode");
2022 os_free(modes[m].channels);
2023 os_free(modes[m].rates);
2024 if (m + 1 < *num_modes)
2025 os_memmove(&modes[m], &modes[m + 1],
2026 sizeof(struct hostapd_hw_modes) *
2027 (*num_modes - (m + 1)));
2028 (*num_modes)--;
2029 continue;
2030 }
2031 m++;
2032 }
2033
2034 /* If only 802.11g mode is included, use it to construct matching
2035 * 802.11b mode data. */
2036
2037 for (m = 0; m < *num_modes; m++) {
2038 if (modes[m].mode == HOSTAPD_MODE_IEEE80211B)
2039 return modes; /* 802.11b already included */
2040 if (modes[m].mode == HOSTAPD_MODE_IEEE80211G)
2041 mode11g_idx = m;
2042 }
2043
2044 if (mode11g_idx < 0)
2045 return modes; /* 2.4 GHz band not supported at all */
2046
2047 nmodes = os_realloc_array(modes, *num_modes + 1, sizeof(*nmodes));
2048 if (nmodes == NULL)
2049 return modes; /* Could not add 802.11b mode */
2050
2051 mode = &nmodes[*num_modes];
2052 os_memset(mode, 0, sizeof(*mode));
2053 (*num_modes)++;
2054 modes = nmodes;
2055
2056 mode->mode = HOSTAPD_MODE_IEEE80211B;
2057
2058 mode11g = &modes[mode11g_idx];
2059 mode->num_channels = mode11g->num_channels;
2060 mode->channels = os_memdup(mode11g->channels,
2061 mode11g->num_channels *
2062 sizeof(struct hostapd_channel_data));
2063 if (mode->channels == NULL) {
2064 (*num_modes)--;
2065 return modes; /* Could not add 802.11b mode */
2066 }
2067
2068 mode->num_rates = 0;
2069 mode->rates = os_malloc(4 * sizeof(int));
2070 if (mode->rates == NULL) {
2071 os_free(mode->channels);
2072 (*num_modes)--;
2073 return modes; /* Could not add 802.11b mode */
2074 }
2075
2076 for (i = 0; i < mode11g->num_rates; i++) {
2077 if (mode11g->rates[i] != 10 && mode11g->rates[i] != 20 &&
2078 mode11g->rates[i] != 55 && mode11g->rates[i] != 110)
2079 continue;
2080 mode->rates[mode->num_rates] = mode11g->rates[i];
2081 mode->num_rates++;
2082 if (mode->num_rates == 4)
2083 break;
2084 }
2085
2086 if (mode->num_rates == 0) {
2087 os_free(mode->channels);
2088 os_free(mode->rates);
2089 (*num_modes)--;
2090 return modes; /* No 802.11b rates */
2091 }
2092
2093 wpa_printf(MSG_DEBUG, "nl80211: Added 802.11b mode based on 802.11g "
2094 "information");
2095
2096 return modes;
2097 }
2098
2099
nl80211_set_ht40_mode(struct hostapd_hw_modes * mode,int start,int end)2100 static void nl80211_set_ht40_mode(struct hostapd_hw_modes *mode, int start,
2101 int end)
2102 {
2103 int c;
2104
2105 for (c = 0; c < mode->num_channels; c++) {
2106 struct hostapd_channel_data *chan = &mode->channels[c];
2107 if (chan->freq - 10 >= start && chan->freq + 10 <= end)
2108 chan->flag |= HOSTAPD_CHAN_HT40;
2109 }
2110 }
2111
2112
nl80211_set_ht40_mode_sec(struct hostapd_hw_modes * mode,int start,int end)2113 static void nl80211_set_ht40_mode_sec(struct hostapd_hw_modes *mode, int start,
2114 int end)
2115 {
2116 int c;
2117
2118 for (c = 0; c < mode->num_channels; c++) {
2119 struct hostapd_channel_data *chan = &mode->channels[c];
2120 if (!(chan->flag & HOSTAPD_CHAN_HT40))
2121 continue;
2122 if (chan->freq - 30 >= start && chan->freq - 10 <= end)
2123 chan->flag |= HOSTAPD_CHAN_HT40MINUS;
2124 if (chan->freq + 10 >= start && chan->freq + 30 <= end)
2125 chan->flag |= HOSTAPD_CHAN_HT40PLUS;
2126 }
2127 }
2128
2129
nl80211_reg_rule_max_eirp(u32 start,u32 end,u32 max_eirp,struct phy_info_arg * results)2130 static void nl80211_reg_rule_max_eirp(u32 start, u32 end, u32 max_eirp,
2131 struct phy_info_arg *results)
2132 {
2133 u16 m;
2134
2135 for (m = 0; m < *results->num_modes; m++) {
2136 int c;
2137 struct hostapd_hw_modes *mode = &results->modes[m];
2138
2139 for (c = 0; c < mode->num_channels; c++) {
2140 struct hostapd_channel_data *chan = &mode->channels[c];
2141 if ((u32) chan->freq - 10 >= start &&
2142 (u32) chan->freq + 10 <= end)
2143 chan->max_tx_power = max_eirp;
2144 }
2145 }
2146 }
2147
2148
nl80211_reg_rule_ht40(u32 start,u32 end,struct phy_info_arg * results)2149 static void nl80211_reg_rule_ht40(u32 start, u32 end,
2150 struct phy_info_arg *results)
2151 {
2152 u16 m;
2153
2154 for (m = 0; m < *results->num_modes; m++) {
2155 if (!(results->modes[m].ht_capab &
2156 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET))
2157 continue;
2158 nl80211_set_ht40_mode(&results->modes[m], start, end);
2159 }
2160 }
2161
2162
nl80211_reg_rule_sec(struct nlattr * tb[],struct phy_info_arg * results)2163 static void nl80211_reg_rule_sec(struct nlattr *tb[],
2164 struct phy_info_arg *results)
2165 {
2166 u32 start, end, max_bw;
2167 u16 m;
2168
2169 if (tb[NL80211_ATTR_FREQ_RANGE_START] == NULL ||
2170 tb[NL80211_ATTR_FREQ_RANGE_END] == NULL ||
2171 tb[NL80211_ATTR_FREQ_RANGE_MAX_BW] == NULL)
2172 return;
2173
2174 start = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]) / 1000;
2175 end = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]) / 1000;
2176 max_bw = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) / 1000;
2177
2178 if (max_bw < 20)
2179 return;
2180
2181 for (m = 0; m < *results->num_modes; m++) {
2182 if (!(results->modes[m].ht_capab &
2183 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET))
2184 continue;
2185 nl80211_set_ht40_mode_sec(&results->modes[m], start, end);
2186 }
2187 }
2188
2189
nl80211_set_vht_mode(struct hostapd_hw_modes * mode,int start,int end,int max_bw)2190 static void nl80211_set_vht_mode(struct hostapd_hw_modes *mode, int start,
2191 int end, int max_bw)
2192 {
2193 int c;
2194
2195 for (c = 0; c < mode->num_channels; c++) {
2196 struct hostapd_channel_data *chan = &mode->channels[c];
2197 if (chan->freq - 10 >= start && chan->freq + 70 <= end)
2198 chan->flag |= HOSTAPD_CHAN_VHT_10_70;
2199
2200 if (chan->freq - 30 >= start && chan->freq + 50 <= end)
2201 chan->flag |= HOSTAPD_CHAN_VHT_30_50;
2202
2203 if (chan->freq - 50 >= start && chan->freq + 30 <= end)
2204 chan->flag |= HOSTAPD_CHAN_VHT_50_30;
2205
2206 if (chan->freq - 70 >= start && chan->freq + 10 <= end)
2207 chan->flag |= HOSTAPD_CHAN_VHT_70_10;
2208
2209 if (max_bw >= 160) {
2210 if (chan->freq - 10 >= start && chan->freq + 150 <= end)
2211 chan->flag |= HOSTAPD_CHAN_VHT_10_150;
2212
2213 if (chan->freq - 30 >= start && chan->freq + 130 <= end)
2214 chan->flag |= HOSTAPD_CHAN_VHT_30_130;
2215
2216 if (chan->freq - 50 >= start && chan->freq + 110 <= end)
2217 chan->flag |= HOSTAPD_CHAN_VHT_50_110;
2218
2219 if (chan->freq - 70 >= start && chan->freq + 90 <= end)
2220 chan->flag |= HOSTAPD_CHAN_VHT_70_90;
2221
2222 if (chan->freq - 90 >= start && chan->freq + 70 <= end)
2223 chan->flag |= HOSTAPD_CHAN_VHT_90_70;
2224
2225 if (chan->freq - 110 >= start && chan->freq + 50 <= end)
2226 chan->flag |= HOSTAPD_CHAN_VHT_110_50;
2227
2228 if (chan->freq - 130 >= start && chan->freq + 30 <= end)
2229 chan->flag |= HOSTAPD_CHAN_VHT_130_30;
2230
2231 if (chan->freq - 150 >= start && chan->freq + 10 <= end)
2232 chan->flag |= HOSTAPD_CHAN_VHT_150_10;
2233 }
2234 }
2235 }
2236
2237
nl80211_reg_rule_vht(struct nlattr * tb[],struct phy_info_arg * results)2238 static void nl80211_reg_rule_vht(struct nlattr *tb[],
2239 struct phy_info_arg *results)
2240 {
2241 u32 start, end, max_bw;
2242 u16 m;
2243
2244 if (tb[NL80211_ATTR_FREQ_RANGE_START] == NULL ||
2245 tb[NL80211_ATTR_FREQ_RANGE_END] == NULL ||
2246 tb[NL80211_ATTR_FREQ_RANGE_MAX_BW] == NULL)
2247 return;
2248
2249 start = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]) / 1000;
2250 end = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]) / 1000;
2251 max_bw = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) / 1000;
2252
2253 if (max_bw < 80)
2254 return;
2255
2256 for (m = 0; m < *results->num_modes; m++) {
2257 if (!(results->modes[m].ht_capab &
2258 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET))
2259 continue;
2260 /* TODO: use a real VHT support indication */
2261 if (!results->modes[m].vht_capab)
2262 continue;
2263
2264 nl80211_set_vht_mode(&results->modes[m], start, end, max_bw);
2265 }
2266 }
2267
2268
nl80211_set_dfs_domain(enum nl80211_dfs_regions region,u8 * dfs_domain)2269 static void nl80211_set_dfs_domain(enum nl80211_dfs_regions region,
2270 u8 *dfs_domain)
2271 {
2272 if (region == NL80211_DFS_FCC)
2273 *dfs_domain = HOSTAPD_DFS_REGION_FCC;
2274 else if (region == NL80211_DFS_ETSI)
2275 *dfs_domain = HOSTAPD_DFS_REGION_ETSI;
2276 else if (region == NL80211_DFS_JP)
2277 *dfs_domain = HOSTAPD_DFS_REGION_JP;
2278 else
2279 *dfs_domain = 0;
2280 }
2281
2282
dfs_domain_name(enum nl80211_dfs_regions region)2283 static const char * dfs_domain_name(enum nl80211_dfs_regions region)
2284 {
2285 switch (region) {
2286 case NL80211_DFS_UNSET:
2287 return "DFS-UNSET";
2288 case NL80211_DFS_FCC:
2289 return "DFS-FCC";
2290 case NL80211_DFS_ETSI:
2291 return "DFS-ETSI";
2292 case NL80211_DFS_JP:
2293 return "DFS-JP";
2294 default:
2295 return "DFS-invalid";
2296 }
2297 }
2298
2299
nl80211_get_reg(struct nl_msg * msg,void * arg)2300 static int nl80211_get_reg(struct nl_msg *msg, void *arg)
2301 {
2302 struct phy_info_arg *results = arg;
2303 struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
2304 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
2305 struct nlattr *nl_rule;
2306 struct nlattr *tb_rule[NL80211_FREQUENCY_ATTR_MAX + 1];
2307 int rem_rule;
2308 static struct nla_policy reg_policy[NL80211_FREQUENCY_ATTR_MAX + 1] = {
2309 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
2310 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
2311 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
2312 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
2313 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
2314 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
2315 };
2316
2317 nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
2318 genlmsg_attrlen(gnlh, 0), NULL);
2319 if (!tb_msg[NL80211_ATTR_REG_ALPHA2] ||
2320 !tb_msg[NL80211_ATTR_REG_RULES]) {
2321 wpa_printf(MSG_DEBUG, "nl80211: No regulatory information "
2322 "available");
2323 return NL_SKIP;
2324 }
2325
2326 if (tb_msg[NL80211_ATTR_DFS_REGION]) {
2327 enum nl80211_dfs_regions dfs_domain;
2328 dfs_domain = nla_get_u8(tb_msg[NL80211_ATTR_DFS_REGION]);
2329 nl80211_set_dfs_domain(dfs_domain, &results->dfs_domain);
2330 wpa_printf(MSG_INFO, "nl80211: Regulatory information - country=%s (%s)",
2331 (char *) nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]),
2332 dfs_domain_name(dfs_domain));
2333 } else {
2334 wpa_printf(MSG_INFO, "nl80211: Regulatory information - country=%s",
2335 (char *) nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]));
2336 }
2337
2338 nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule)
2339 {
2340 u32 start, end, max_eirp = 0, max_bw = 0, flags = 0;
2341 nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX,
2342 nla_data(nl_rule), nla_len(nl_rule), reg_policy);
2343 if (tb_rule[NL80211_ATTR_FREQ_RANGE_START] == NULL ||
2344 tb_rule[NL80211_ATTR_FREQ_RANGE_END] == NULL)
2345 continue;
2346 start = nla_get_u32(tb_rule[NL80211_ATTR_FREQ_RANGE_START]) / 1000;
2347 end = nla_get_u32(tb_rule[NL80211_ATTR_FREQ_RANGE_END]) / 1000;
2348 if (tb_rule[NL80211_ATTR_POWER_RULE_MAX_EIRP])
2349 max_eirp = nla_get_u32(tb_rule[NL80211_ATTR_POWER_RULE_MAX_EIRP]) / 100;
2350 if (tb_rule[NL80211_ATTR_FREQ_RANGE_MAX_BW])
2351 max_bw = nla_get_u32(tb_rule[NL80211_ATTR_FREQ_RANGE_MAX_BW]) / 1000;
2352 if (tb_rule[NL80211_ATTR_REG_RULE_FLAGS])
2353 flags = nla_get_u32(tb_rule[NL80211_ATTR_REG_RULE_FLAGS]);
2354
2355 wpa_printf(MSG_INFO, "nl80211: %u-%u @ %u MHz %u mBm%s%s%s%s%s%s%s%s",
2356 start, end, max_bw, max_eirp,
2357 flags & NL80211_RRF_NO_OFDM ? " (no OFDM)" : "",
2358 flags & NL80211_RRF_NO_CCK ? " (no CCK)" : "",
2359 flags & NL80211_RRF_NO_INDOOR ? " (no indoor)" : "",
2360 flags & NL80211_RRF_NO_OUTDOOR ? " (no outdoor)" :
2361 "",
2362 flags & NL80211_RRF_DFS ? " (DFS)" : "",
2363 flags & NL80211_RRF_PTP_ONLY ? " (PTP only)" : "",
2364 flags & NL80211_RRF_PTMP_ONLY ? " (PTMP only)" : "",
2365 flags & NL80211_RRF_NO_IR ? " (no IR)" : "");
2366 if (max_bw >= 40)
2367 nl80211_reg_rule_ht40(start, end, results);
2368 if (tb_rule[NL80211_ATTR_POWER_RULE_MAX_EIRP])
2369 nl80211_reg_rule_max_eirp(start, end, max_eirp,
2370 results);
2371 }
2372
2373 nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule)
2374 {
2375 nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX,
2376 nla_data(nl_rule), nla_len(nl_rule), reg_policy);
2377 nl80211_reg_rule_sec(tb_rule, results);
2378 }
2379
2380 nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule)
2381 {
2382 nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX,
2383 nla_data(nl_rule), nla_len(nl_rule), reg_policy);
2384 nl80211_reg_rule_vht(tb_rule, results);
2385 }
2386
2387 return NL_SKIP;
2388 }
2389
2390
nl80211_set_regulatory_flags(struct wpa_driver_nl80211_data * drv,struct phy_info_arg * results)2391 static int nl80211_set_regulatory_flags(struct wpa_driver_nl80211_data *drv,
2392 struct phy_info_arg *results)
2393 {
2394 struct nl_msg *msg;
2395
2396 msg = nlmsg_alloc();
2397 if (!msg)
2398 return -ENOMEM;
2399
2400 nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG);
2401 if (drv->capa.flags & WPA_DRIVER_FLAGS_SELF_MANAGED_REGULATORY) {
2402 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, drv->wiphy_idx)) {
2403 nlmsg_free(msg);
2404 return -1;
2405 }
2406 }
2407
2408 return send_and_recv_msgs(drv, msg, nl80211_get_reg, results,
2409 NULL, NULL);
2410 }
2411
2412
modestr(enum hostapd_hw_mode mode)2413 static const char * modestr(enum hostapd_hw_mode mode)
2414 {
2415 switch (mode) {
2416 case HOSTAPD_MODE_IEEE80211B:
2417 return "802.11b";
2418 case HOSTAPD_MODE_IEEE80211G:
2419 return "802.11g";
2420 case HOSTAPD_MODE_IEEE80211A:
2421 return "802.11a";
2422 case HOSTAPD_MODE_IEEE80211AD:
2423 return "802.11ad";
2424 default:
2425 return "?";
2426 }
2427 }
2428
2429
nl80211_dump_chan_list(struct hostapd_hw_modes * modes,u16 num_modes)2430 static void nl80211_dump_chan_list(struct hostapd_hw_modes *modes,
2431 u16 num_modes)
2432 {
2433 int i;
2434
2435 if (!modes)
2436 return;
2437
2438 for (i = 0; i < num_modes; i++) {
2439 struct hostapd_hw_modes *mode = &modes[i];
2440 char str[200];
2441 char *pos = str;
2442 char *end = pos + sizeof(str);
2443 int j, res;
2444
2445 for (j = 0; j < mode->num_channels; j++) {
2446 struct hostapd_channel_data *chan = &mode->channels[j];
2447
2448 res = os_snprintf(pos, end - pos, " %d%s%s%s",
2449 chan->freq,
2450 (chan->flag & HOSTAPD_CHAN_DISABLED) ?
2451 "[DISABLED]" : "",
2452 (chan->flag & HOSTAPD_CHAN_NO_IR) ?
2453 "[NO_IR]" : "",
2454 (chan->flag & HOSTAPD_CHAN_RADAR) ?
2455 "[RADAR]" : "");
2456 if (os_snprintf_error(end - pos, res))
2457 break;
2458 pos += res;
2459 }
2460
2461 *pos = '\0';
2462 wpa_printf(MSG_DEBUG, "nl80211: Mode IEEE %s:%s",
2463 modestr(mode->mode), str);
2464 }
2465 }
2466
2467
2468 struct hostapd_hw_modes *
nl80211_get_hw_feature_data(void * priv,u16 * num_modes,u16 * flags,u8 * dfs_domain)2469 nl80211_get_hw_feature_data(void *priv, u16 *num_modes, u16 *flags,
2470 u8 *dfs_domain)
2471 {
2472 if (priv == NULL) {
2473 return NULL;
2474 }
2475 u32 feat;
2476 struct i802_bss *bss = priv;
2477 struct wpa_driver_nl80211_data *drv = bss->drv;
2478 int nl_flags = 0;
2479 struct nl_msg *msg;
2480 struct phy_info_arg result = {
2481 .num_modes = num_modes,
2482 .modes = NULL,
2483 .last_mode = -1,
2484 .failed = 0,
2485 .dfs_domain = 0,
2486 };
2487
2488 *num_modes = 0;
2489 *flags = 0;
2490 *dfs_domain = 0;
2491
2492 feat = get_nl80211_protocol_features(drv);
2493 if (feat & NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)
2494 nl_flags = NLM_F_DUMP;
2495 if (!(msg = nl80211_cmd_msg(bss, nl_flags, NL80211_CMD_GET_WIPHY)) ||
2496 nla_put_flag(msg, NL80211_ATTR_SPLIT_WIPHY_DUMP)) {
2497 nlmsg_free(msg);
2498 return NULL;
2499 }
2500
2501 if (send_and_recv_msgs(drv, msg, phy_info_handler, &result,
2502 NULL, NULL) == 0) {
2503 struct hostapd_hw_modes *modes;
2504
2505 nl80211_set_regulatory_flags(drv, &result);
2506 if (result.failed) {
2507 int i;
2508
2509 for (i = 0; result.modes && i < *num_modes; i++) {
2510 os_free(result.modes[i].channels);
2511 os_free(result.modes[i].rates);
2512 }
2513 os_free(result.modes);
2514 *num_modes = 0;
2515 return NULL;
2516 }
2517
2518 *dfs_domain = result.dfs_domain;
2519
2520 modes = wpa_driver_nl80211_postprocess_modes(result.modes,
2521 num_modes);
2522 nl80211_dump_chan_list(modes, *num_modes);
2523 return modes;
2524 }
2525
2526 return NULL;
2527 }
2528