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 if (ext_feature_isset(ext_features, len,
670 NL80211_EXT_FEATURE_RADAR_BACKGROUND))
671 capa->flags2 |= WPA_DRIVER_RADAR_BACKGROUND;
672 }
673
674
wiphy_info_feature_flags(struct wiphy_info_data * info,struct nlattr * tb)675 static void wiphy_info_feature_flags(struct wiphy_info_data *info,
676 struct nlattr *tb)
677 {
678 u32 flags;
679 struct wpa_driver_capa *capa = info->capa;
680
681 if (tb == NULL)
682 return;
683
684 flags = nla_get_u32(tb);
685
686 if (flags & NL80211_FEATURE_SK_TX_STATUS)
687 info->data_tx_status = 1;
688
689 if (flags & NL80211_FEATURE_INACTIVITY_TIMER)
690 capa->flags |= WPA_DRIVER_FLAGS_INACTIVITY_TIMER;
691
692 if (flags & NL80211_FEATURE_SAE)
693 capa->flags |= WPA_DRIVER_FLAGS_SAE;
694
695 if (flags & NL80211_FEATURE_NEED_OBSS_SCAN)
696 capa->flags |= WPA_DRIVER_FLAGS_OBSS_SCAN;
697
698 if (flags & NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)
699 capa->flags |= WPA_DRIVER_FLAGS_HT_2040_COEX;
700
701 if (flags & NL80211_FEATURE_TDLS_CHANNEL_SWITCH) {
702 wpa_printf(MSG_DEBUG, "nl80211: TDLS channel switch");
703 capa->flags |= WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH;
704 }
705
706 if (flags & NL80211_FEATURE_P2P_GO_CTWIN)
707 info->p2p_go_ctwindow_supported = 1;
708
709 if (flags & NL80211_FEATURE_LOW_PRIORITY_SCAN)
710 info->have_low_prio_scan = 1;
711
712 if (flags & NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)
713 info->mac_addr_rand_scan_supported = 1;
714
715 if (flags & NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR)
716 info->mac_addr_rand_sched_scan_supported = 1;
717
718 if (flags & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
719 info->wmm_ac_supported = 1;
720
721 if (flags & NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES)
722 capa->rrm_flags |= WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES;
723
724 if (flags & NL80211_FEATURE_WFA_TPC_IE_IN_PROBES)
725 capa->rrm_flags |= WPA_DRIVER_FLAGS_WFA_TPC_IE_IN_PROBES;
726
727 if (flags & NL80211_FEATURE_QUIET)
728 capa->rrm_flags |= WPA_DRIVER_FLAGS_QUIET;
729
730 if (flags & NL80211_FEATURE_TX_POWER_INSERTION)
731 capa->rrm_flags |= WPA_DRIVER_FLAGS_TX_POWER_INSERTION;
732
733 if (flags & NL80211_FEATURE_HT_IBSS)
734 capa->flags |= WPA_DRIVER_FLAGS_HT_IBSS;
735
736 if (flags & NL80211_FEATURE_FULL_AP_CLIENT_STATE)
737 capa->flags |= WPA_DRIVER_FLAGS_FULL_AP_CLIENT_STATE;
738 }
739
740
wiphy_info_probe_resp_offload(struct wpa_driver_capa * capa,struct nlattr * tb)741 static void wiphy_info_probe_resp_offload(struct wpa_driver_capa *capa,
742 struct nlattr *tb)
743 {
744 u32 protocols;
745
746 if (tb == NULL)
747 return;
748
749 protocols = nla_get_u32(tb);
750 wpa_printf(MSG_DEBUG, "nl80211: Supports Probe Response offload in AP "
751 "mode");
752 capa->flags |= WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD;
753 capa->probe_resp_offloads = probe_resp_offload_support(protocols);
754 }
755
756
wiphy_info_wowlan_triggers(struct wpa_driver_capa * capa,struct nlattr * tb)757 static void wiphy_info_wowlan_triggers(struct wpa_driver_capa *capa,
758 struct nlattr *tb)
759 {
760 struct nlattr *triggers[MAX_NL80211_WOWLAN_TRIG + 1];
761
762 if (tb == NULL)
763 return;
764
765 if (nla_parse_nested(triggers, MAX_NL80211_WOWLAN_TRIG,
766 tb, NULL))
767 return;
768
769 if (triggers[NL80211_WOWLAN_TRIG_ANY])
770 capa->wowlan_triggers.any = 1;
771 if (triggers[NL80211_WOWLAN_TRIG_DISCONNECT])
772 capa->wowlan_triggers.disconnect = 1;
773 if (triggers[NL80211_WOWLAN_TRIG_MAGIC_PKT])
774 capa->wowlan_triggers.magic_pkt = 1;
775 if (triggers[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE])
776 capa->wowlan_triggers.gtk_rekey_failure = 1;
777 if (triggers[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST])
778 capa->wowlan_triggers.eap_identity_req = 1;
779 if (triggers[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE])
780 capa->wowlan_triggers.four_way_handshake = 1;
781 if (triggers[NL80211_WOWLAN_TRIG_RFKILL_RELEASE])
782 capa->wowlan_triggers.rfkill_release = 1;
783 }
784
785
wiphy_info_extended_capab(struct wpa_driver_nl80211_data * drv,struct nlattr * tb)786 static void wiphy_info_extended_capab(struct wpa_driver_nl80211_data *drv,
787 struct nlattr *tb)
788 {
789 int rem = 0, i;
790 struct nlattr *tb1[NL80211_ATTR_MAX + 1], *attr;
791
792 if (!tb || drv->num_iface_ext_capa == NL80211_IFTYPE_MAX)
793 return;
794
795 nla_for_each_nested(attr, tb, rem) {
796 unsigned int len;
797 struct drv_nl80211_ext_capa *capa;
798
799 nla_parse(tb1, NL80211_ATTR_MAX, nla_data(attr),
800 nla_len(attr), NULL);
801
802 if (!tb1[NL80211_ATTR_IFTYPE] ||
803 !tb1[NL80211_ATTR_EXT_CAPA] ||
804 !tb1[NL80211_ATTR_EXT_CAPA_MASK])
805 continue;
806
807 capa = &drv->iface_ext_capa[drv->num_iface_ext_capa];
808 capa->iftype = nla_get_u32(tb1[NL80211_ATTR_IFTYPE]);
809 wpa_printf(MSG_DEBUG,
810 "nl80211: Driver-advertised extended capabilities for interface type %s",
811 nl80211_iftype_str(capa->iftype));
812
813 len = nla_len(tb1[NL80211_ATTR_EXT_CAPA]);
814 capa->ext_capa = os_memdup(nla_data(tb1[NL80211_ATTR_EXT_CAPA]),
815 len);
816 if (!capa->ext_capa)
817 goto err;
818
819 capa->ext_capa_len = len;
820 wpa_hexdump(MSG_DEBUG, "nl80211: Extended capabilities",
821 capa->ext_capa, capa->ext_capa_len);
822
823 len = nla_len(tb1[NL80211_ATTR_EXT_CAPA_MASK]);
824 capa->ext_capa_mask =
825 os_memdup(nla_data(tb1[NL80211_ATTR_EXT_CAPA_MASK]),
826 len);
827 if (!capa->ext_capa_mask)
828 goto err;
829
830 wpa_hexdump(MSG_DEBUG, "nl80211: Extended capabilities mask",
831 capa->ext_capa_mask, capa->ext_capa_len);
832
833 drv->num_iface_ext_capa++;
834 if (drv->num_iface_ext_capa == NL80211_IFTYPE_MAX)
835 break;
836 }
837
838 return;
839
840 err:
841 /* Cleanup allocated memory on error */
842 for (i = 0; i < NL80211_IFTYPE_MAX; i++) {
843 os_free(drv->iface_ext_capa[i].ext_capa);
844 drv->iface_ext_capa[i].ext_capa = NULL;
845 os_free(drv->iface_ext_capa[i].ext_capa_mask);
846 drv->iface_ext_capa[i].ext_capa_mask = NULL;
847 drv->iface_ext_capa[i].ext_capa_len = 0;
848 }
849 drv->num_iface_ext_capa = 0;
850 }
851
852
wiphy_info_handler(struct nl_msg * msg,void * arg)853 static int wiphy_info_handler(struct nl_msg *msg, void *arg)
854 {
855 struct nlattr *tb[NL80211_ATTR_MAX + 1];
856 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
857 struct wiphy_info_data *info = arg;
858 struct wpa_driver_capa *capa = info->capa;
859 struct wpa_driver_nl80211_data *drv = info->drv;
860
861 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
862 genlmsg_attrlen(gnlh, 0), NULL);
863
864 if (tb[NL80211_ATTR_WIPHY])
865 drv->wiphy_idx = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
866
867 if (tb[NL80211_ATTR_WIPHY_NAME])
868 os_strlcpy(drv->phyname,
869 nla_get_string(tb[NL80211_ATTR_WIPHY_NAME]),
870 sizeof(drv->phyname));
871 if (tb[NL80211_ATTR_MAX_NUM_SCAN_SSIDS])
872 capa->max_scan_ssids =
873 nla_get_u8(tb[NL80211_ATTR_MAX_NUM_SCAN_SSIDS]);
874
875 if (tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS])
876 capa->max_sched_scan_ssids =
877 nla_get_u8(tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS]);
878
879 if (tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS] &&
880 tb[NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL] &&
881 tb[NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS]) {
882 capa->max_sched_scan_plans =
883 nla_get_u32(tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS]);
884
885 capa->max_sched_scan_plan_interval =
886 nla_get_u32(tb[NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL]);
887
888 capa->max_sched_scan_plan_iterations =
889 nla_get_u32(tb[NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS]);
890 }
891
892 if (tb[NL80211_ATTR_MAX_MATCH_SETS])
893 capa->max_match_sets =
894 nla_get_u8(tb[NL80211_ATTR_MAX_MATCH_SETS]);
895
896 if (tb[NL80211_ATTR_MAC_ACL_MAX])
897 capa->max_acl_mac_addrs =
898 nla_get_u32(tb[NL80211_ATTR_MAC_ACL_MAX]);
899
900 wiphy_info_supported_iftypes(info, tb[NL80211_ATTR_SUPPORTED_IFTYPES]);
901 wiphy_info_iface_comb(info, tb[NL80211_ATTR_INTERFACE_COMBINATIONS]);
902 wiphy_info_supp_cmds(info, tb[NL80211_ATTR_SUPPORTED_COMMANDS]);
903 wiphy_info_cipher_suites(info, tb[NL80211_ATTR_CIPHER_SUITES]);
904 wiphy_info_akm_suites(info, tb[NL80211_ATTR_AKM_SUITES]);
905 wiphy_info_iftype_akm_suites(info, tb[NL80211_ATTR_IFTYPE_AKM_SUITES]);
906
907 if (tb[NL80211_ATTR_OFFCHANNEL_TX_OK]) {
908 wpa_printf(MSG_DEBUG, "nl80211: Using driver-based "
909 "off-channel TX");
910 capa->flags |= WPA_DRIVER_FLAGS_OFFCHANNEL_TX;
911 }
912
913 if (tb[NL80211_ATTR_ROAM_SUPPORT]) {
914 wpa_printf(MSG_DEBUG, "nl80211: Using driver-based roaming");
915 capa->flags |= WPA_DRIVER_FLAGS_BSS_SELECTION;
916 }
917
918 wiphy_info_max_roc(capa,
919 tb[NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION]);
920
921 if (tb[NL80211_ATTR_SUPPORT_AP_UAPSD])
922 capa->flags |= WPA_DRIVER_FLAGS_AP_UAPSD;
923
924 wiphy_info_tdls(capa, tb[NL80211_ATTR_TDLS_SUPPORT],
925 tb[NL80211_ATTR_TDLS_EXTERNAL_SETUP]);
926
927 if (tb[NL80211_ATTR_DEVICE_AP_SME]) {
928 u32 ap_sme_features_flags =
929 nla_get_u32(tb[NL80211_ATTR_DEVICE_AP_SME]);
930
931 if (ap_sme_features_flags & NL80211_AP_SME_SA_QUERY_OFFLOAD)
932 capa->flags2 |= WPA_DRIVER_FLAGS2_SA_QUERY_OFFLOAD_AP;
933
934 info->device_ap_sme = 1;
935 }
936
937 wiphy_info_feature_flags(info, tb[NL80211_ATTR_FEATURE_FLAGS]);
938 wiphy_info_ext_feature_flags(info, tb[NL80211_ATTR_EXT_FEATURES]);
939 wiphy_info_probe_resp_offload(capa,
940 tb[NL80211_ATTR_PROBE_RESP_OFFLOAD]);
941
942 if (tb[NL80211_ATTR_EXT_CAPA] && tb[NL80211_ATTR_EXT_CAPA_MASK] &&
943 drv->extended_capa == NULL) {
944 drv->extended_capa =
945 os_malloc(nla_len(tb[NL80211_ATTR_EXT_CAPA]));
946 if (drv->extended_capa) {
947 os_memcpy(drv->extended_capa,
948 nla_data(tb[NL80211_ATTR_EXT_CAPA]),
949 nla_len(tb[NL80211_ATTR_EXT_CAPA]));
950 drv->extended_capa_len =
951 nla_len(tb[NL80211_ATTR_EXT_CAPA]);
952 wpa_hexdump(MSG_DEBUG,
953 "nl80211: Driver-advertised extended capabilities (default)",
954 drv->extended_capa, drv->extended_capa_len);
955 }
956 drv->extended_capa_mask =
957 os_malloc(nla_len(tb[NL80211_ATTR_EXT_CAPA_MASK]));
958 if (drv->extended_capa_mask) {
959 os_memcpy(drv->extended_capa_mask,
960 nla_data(tb[NL80211_ATTR_EXT_CAPA_MASK]),
961 nla_len(tb[NL80211_ATTR_EXT_CAPA_MASK]));
962 wpa_hexdump(MSG_DEBUG,
963 "nl80211: Driver-advertised extended capabilities mask (default)",
964 drv->extended_capa_mask,
965 drv->extended_capa_len);
966 } else {
967 os_free(drv->extended_capa);
968 drv->extended_capa = NULL;
969 drv->extended_capa_len = 0;
970 }
971 }
972
973 wiphy_info_extended_capab(drv, tb[NL80211_ATTR_IFTYPE_EXT_CAPA]);
974
975 if (tb[NL80211_ATTR_VENDOR_DATA]) {
976 struct nlattr *nl;
977 int rem;
978
979 nla_for_each_nested(nl, tb[NL80211_ATTR_VENDOR_DATA], rem) {
980 struct nl80211_vendor_cmd_info *vinfo;
981 if (nla_len(nl) != sizeof(*vinfo)) {
982 wpa_printf(MSG_DEBUG, "nl80211: Unexpected vendor data info");
983 continue;
984 }
985 vinfo = nla_data(nl);
986 if (vinfo->vendor_id == OUI_QCA) {
987 switch (vinfo->subcmd) {
988 case QCA_NL80211_VENDOR_SUBCMD_TEST:
989 drv->vendor_cmd_test_avail = 1;
990 break;
991 #ifdef CONFIG_DRIVER_NL80211_QCA
992 case QCA_NL80211_VENDOR_SUBCMD_ROAMING:
993 drv->roaming_vendor_cmd_avail = 1;
994 break;
995 case QCA_NL80211_VENDOR_SUBCMD_DFS_CAPABILITY:
996 drv->dfs_vendor_cmd_avail = 1;
997 break;
998 case QCA_NL80211_VENDOR_SUBCMD_GET_FEATURES:
999 drv->get_features_vendor_cmd_avail = 1;
1000 break;
1001 case QCA_NL80211_VENDOR_SUBCMD_GET_PREFERRED_FREQ_LIST:
1002 drv->get_pref_freq_list = 1;
1003 break;
1004 case QCA_NL80211_VENDOR_SUBCMD_SET_PROBABLE_OPER_CHANNEL:
1005 drv->set_prob_oper_freq = 1;
1006 break;
1007 case QCA_NL80211_VENDOR_SUBCMD_DO_ACS:
1008 drv->capa.flags |=
1009 WPA_DRIVER_FLAGS_ACS_OFFLOAD;
1010 drv->qca_do_acs = 1;
1011 break;
1012 case QCA_NL80211_VENDOR_SUBCMD_SETBAND:
1013 drv->setband_vendor_cmd_avail = 1;
1014 break;
1015 case QCA_NL80211_VENDOR_SUBCMD_TRIGGER_SCAN:
1016 drv->scan_vendor_cmd_avail = 1;
1017 break;
1018 case QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION:
1019 drv->set_wifi_conf_vendor_cmd_avail = 1;
1020 break;
1021 case QCA_NL80211_VENDOR_SUBCMD_FETCH_BSS_TRANSITION_STATUS:
1022 drv->fetch_bss_trans_status = 1;
1023 break;
1024 case QCA_NL80211_VENDOR_SUBCMD_ROAM:
1025 drv->roam_vendor_cmd_avail = 1;
1026 break;
1027 case QCA_NL80211_VENDOR_SUBCMD_ADD_STA_NODE:
1028 drv->add_sta_node_vendor_cmd_avail = 1;
1029 break;
1030 case QCA_NL80211_VENDOR_SUBCMD_GET_STA_INFO:
1031 drv->get_sta_info_vendor_cmd_avail = 1;
1032 break;
1033 #endif /* CONFIG_DRIVER_NL80211_QCA */
1034 }
1035 #ifdef CONFIG_DRIVER_NL80211_BRCM
1036 } else if (vinfo->vendor_id == OUI_BRCM) {
1037 switch (vinfo->subcmd) {
1038 case BRCM_VENDOR_SCMD_ACS:
1039 drv->capa.flags |=
1040 WPA_DRIVER_FLAGS_ACS_OFFLOAD;
1041 wpa_printf(MSG_DEBUG,
1042 "Enabled BRCM ACS");
1043 drv->brcm_do_acs = 1;
1044 break;
1045 }
1046 #endif /* CONFIG_DRIVER_NL80211_BRCM */
1047 }
1048
1049 wpa_printf(MSG_DEBUG, "nl80211: Supported vendor command: vendor_id=0x%x subcmd=%u",
1050 vinfo->vendor_id, vinfo->subcmd);
1051 }
1052 }
1053
1054 if (tb[NL80211_ATTR_VENDOR_EVENTS]) {
1055 struct nlattr *nl;
1056 int rem;
1057
1058 nla_for_each_nested(nl, tb[NL80211_ATTR_VENDOR_EVENTS], rem) {
1059 struct nl80211_vendor_cmd_info *vinfo;
1060 if (nla_len(nl) != sizeof(*vinfo)) {
1061 wpa_printf(MSG_DEBUG, "nl80211: Unexpected vendor data info");
1062 continue;
1063 }
1064 vinfo = nla_data(nl);
1065 wpa_printf(MSG_DEBUG, "nl80211: Supported vendor event: vendor_id=0x%x subcmd=%u",
1066 vinfo->vendor_id, vinfo->subcmd);
1067 }
1068 }
1069
1070 wiphy_info_wowlan_triggers(capa,
1071 tb[NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED]);
1072
1073 if (tb[NL80211_ATTR_MAX_AP_ASSOC_STA])
1074 capa->max_stations =
1075 nla_get_u32(tb[NL80211_ATTR_MAX_AP_ASSOC_STA]);
1076
1077 if (tb[NL80211_ATTR_MAX_CSA_COUNTERS])
1078 capa->max_csa_counters =
1079 nla_get_u8(tb[NL80211_ATTR_MAX_CSA_COUNTERS]);
1080
1081 if (tb[NL80211_ATTR_WIPHY_SELF_MANAGED_REG])
1082 capa->flags |= WPA_DRIVER_FLAGS_SELF_MANAGED_REGULATORY;
1083
1084 return NL_SKIP;
1085 }
1086
1087
wpa_driver_nl80211_get_info(struct wpa_driver_nl80211_data * drv,struct wiphy_info_data * info)1088 static int wpa_driver_nl80211_get_info(struct wpa_driver_nl80211_data *drv,
1089 struct wiphy_info_data *info)
1090 {
1091 u32 feat;
1092 struct nl_msg *msg;
1093 int flags = 0;
1094
1095 os_memset(info, 0, sizeof(*info));
1096 info->capa = &drv->capa;
1097 info->drv = drv;
1098
1099 feat = get_nl80211_protocol_features(drv);
1100 if (feat & NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)
1101 flags = NLM_F_DUMP;
1102 msg = nl80211_cmd_msg(drv->first_bss, flags, NL80211_CMD_GET_WIPHY);
1103 if (!msg || nla_put_flag(msg, NL80211_ATTR_SPLIT_WIPHY_DUMP)) {
1104 nlmsg_free(msg);
1105 return -1;
1106 }
1107
1108 if (send_and_recv_msgs(drv, msg, wiphy_info_handler, info, NULL, NULL))
1109 return -1;
1110
1111 if (info->auth_supported)
1112 drv->capa.flags |= WPA_DRIVER_FLAGS_SME;
1113 else if (!info->connect_supported) {
1114 wpa_printf(MSG_INFO, "nl80211: Driver does not support "
1115 "authentication/association or connect commands");
1116 info->error = 1;
1117 }
1118
1119 if (info->p2p_go_supported && info->p2p_client_supported)
1120 drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CAPABLE;
1121 if (info->p2p_concurrent) {
1122 wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group "
1123 "interface (driver advertised support)");
1124 drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT;
1125 drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P;
1126 }
1127 if (info->num_multichan_concurrent > 1) {
1128 wpa_printf(MSG_DEBUG, "nl80211: Enable multi-channel "
1129 "concurrent (driver advertised support)");
1130 drv->capa.num_multichan_concurrent =
1131 info->num_multichan_concurrent;
1132 }
1133 if (drv->capa.flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)
1134 wpa_printf(MSG_DEBUG, "nl80211: use P2P_DEVICE support");
1135
1136 /* default to 5000 since early versions of mac80211 don't set it */
1137 if (!drv->capa.max_remain_on_chan)
1138 drv->capa.max_remain_on_chan = 5000;
1139
1140 drv->capa.wmm_ac_supported = info->wmm_ac_supported;
1141
1142 drv->capa.mac_addr_rand_sched_scan_supported =
1143 info->mac_addr_rand_sched_scan_supported;
1144 drv->capa.mac_addr_rand_scan_supported =
1145 info->mac_addr_rand_scan_supported;
1146
1147 if (info->channel_switch_supported) {
1148 drv->capa.flags |= WPA_DRIVER_FLAGS_AP_CSA;
1149 if (!drv->capa.max_csa_counters)
1150 drv->capa.max_csa_counters = 1;
1151 }
1152
1153 if (!drv->capa.max_sched_scan_plans) {
1154 drv->capa.max_sched_scan_plans = 1;
1155 drv->capa.max_sched_scan_plan_interval = UINT32_MAX;
1156 drv->capa.max_sched_scan_plan_iterations = 0;
1157 }
1158
1159 if (info->update_ft_ies_supported)
1160 drv->capa.flags |= WPA_DRIVER_FLAGS_UPDATE_FT_IES;
1161
1162 return 0;
1163 }
1164
1165
1166 #ifdef CONFIG_DRIVER_NL80211_QCA
1167
dfs_info_handler(struct nl_msg * msg,void * arg)1168 static int dfs_info_handler(struct nl_msg *msg, void *arg)
1169 {
1170 struct nlattr *tb[NL80211_ATTR_MAX + 1];
1171 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1172 int *dfs_capability_ptr = arg;
1173
1174 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1175 genlmsg_attrlen(gnlh, 0), NULL);
1176
1177 if (tb[NL80211_ATTR_VENDOR_DATA]) {
1178 struct nlattr *nl_vend = tb[NL80211_ATTR_VENDOR_DATA];
1179 struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1];
1180
1181 nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX,
1182 nla_data(nl_vend), nla_len(nl_vend), NULL);
1183
1184 if (tb_vendor[QCA_WLAN_VENDOR_ATTR_DFS]) {
1185 u32 val;
1186 val = nla_get_u32(tb_vendor[QCA_WLAN_VENDOR_ATTR_DFS]);
1187 wpa_printf(MSG_DEBUG, "nl80211: DFS offload capability: %u",
1188 val);
1189 *dfs_capability_ptr = val;
1190 }
1191 }
1192
1193 return NL_SKIP;
1194 }
1195
1196
qca_nl80211_check_dfs_capa(struct wpa_driver_nl80211_data * drv)1197 static void qca_nl80211_check_dfs_capa(struct wpa_driver_nl80211_data *drv)
1198 {
1199 struct nl_msg *msg;
1200 int dfs_capability = 0;
1201 int ret;
1202
1203 if (!drv->dfs_vendor_cmd_avail)
1204 return;
1205
1206 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
1207 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
1208 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
1209 QCA_NL80211_VENDOR_SUBCMD_DFS_CAPABILITY)) {
1210 nlmsg_free(msg);
1211 return;
1212 }
1213
1214 ret = send_and_recv_msgs(drv, msg, dfs_info_handler, &dfs_capability,
1215 NULL, NULL);
1216 if (!ret && dfs_capability)
1217 drv->capa.flags |= WPA_DRIVER_FLAGS_DFS_OFFLOAD;
1218 }
1219
1220
1221 struct features_info {
1222 u8 *flags;
1223 size_t flags_len;
1224 struct wpa_driver_capa *capa;
1225 };
1226
1227
features_info_handler(struct nl_msg * msg,void * arg)1228 static int features_info_handler(struct nl_msg *msg, void *arg)
1229 {
1230 struct nlattr *tb[NL80211_ATTR_MAX + 1];
1231 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1232 struct features_info *info = arg;
1233 struct nlattr *nl_vend, *attr;
1234
1235 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1236 genlmsg_attrlen(gnlh, 0), NULL);
1237
1238 nl_vend = tb[NL80211_ATTR_VENDOR_DATA];
1239 if (nl_vend) {
1240 struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1];
1241
1242 nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX,
1243 nla_data(nl_vend), nla_len(nl_vend), NULL);
1244
1245 attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_FEATURE_FLAGS];
1246 if (attr) {
1247 int len = nla_len(attr);
1248 info->flags = os_malloc(len);
1249 if (info->flags != NULL) {
1250 os_memcpy(info->flags, nla_data(attr), len);
1251 info->flags_len = len;
1252 }
1253 }
1254 attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_CONCURRENCY_CAPA];
1255 if (attr)
1256 info->capa->conc_capab = nla_get_u32(attr);
1257
1258 attr = tb_vendor[
1259 QCA_WLAN_VENDOR_ATTR_MAX_CONCURRENT_CHANNELS_2_4_BAND];
1260 if (attr)
1261 info->capa->max_conc_chan_2_4 = nla_get_u32(attr);
1262
1263 attr = tb_vendor[
1264 QCA_WLAN_VENDOR_ATTR_MAX_CONCURRENT_CHANNELS_5_0_BAND];
1265 if (attr)
1266 info->capa->max_conc_chan_5_0 = nla_get_u32(attr);
1267 }
1268
1269 return NL_SKIP;
1270 }
1271
1272
check_feature(enum qca_wlan_vendor_features feature,struct features_info * info)1273 static int check_feature(enum qca_wlan_vendor_features feature,
1274 struct features_info *info)
1275 {
1276 size_t idx = feature / 8;
1277
1278 return (idx < info->flags_len) &&
1279 (info->flags[idx] & BIT(feature % 8));
1280 }
1281
1282
qca_nl80211_get_features(struct wpa_driver_nl80211_data * drv)1283 static void qca_nl80211_get_features(struct wpa_driver_nl80211_data *drv)
1284 {
1285 struct nl_msg *msg;
1286 struct features_info info;
1287 int ret;
1288
1289 if (!drv->get_features_vendor_cmd_avail)
1290 return;
1291
1292 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
1293 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
1294 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
1295 QCA_NL80211_VENDOR_SUBCMD_GET_FEATURES)) {
1296 nlmsg_free(msg);
1297 return;
1298 }
1299
1300 os_memset(&info, 0, sizeof(info));
1301 info.capa = &drv->capa;
1302 ret = send_and_recv_msgs(drv, msg, features_info_handler, &info,
1303 NULL, NULL);
1304 if (ret || !info.flags)
1305 return;
1306
1307 if (check_feature(QCA_WLAN_VENDOR_FEATURE_KEY_MGMT_OFFLOAD, &info))
1308 drv->capa.flags |= WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD;
1309
1310 if (check_feature(QCA_WLAN_VENDOR_FEATURE_SUPPORT_HW_MODE_ANY, &info))
1311 drv->capa.flags |= WPA_DRIVER_FLAGS_SUPPORT_HW_MODE_ANY;
1312
1313 if (check_feature(QCA_WLAN_VENDOR_FEATURE_OFFCHANNEL_SIMULTANEOUS,
1314 &info))
1315 drv->capa.flags |= WPA_DRIVER_FLAGS_OFFCHANNEL_SIMULTANEOUS;
1316 if (check_feature(QCA_WLAN_VENDOR_FEATURE_P2P_LISTEN_OFFLOAD, &info))
1317 drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD;
1318 if (check_feature(QCA_WLAN_VENDOR_FEATURE_OCE_STA, &info))
1319 drv->capa.flags |= WPA_DRIVER_FLAGS_OCE_STA;
1320 if (check_feature(QCA_WLAN_VENDOR_FEATURE_OCE_AP, &info))
1321 drv->capa.flags |= WPA_DRIVER_FLAGS_OCE_AP;
1322 if (check_feature(QCA_WLAN_VENDOR_FEATURE_OCE_STA_CFON, &info))
1323 drv->capa.flags |= WPA_DRIVER_FLAGS_OCE_STA_CFON;
1324 os_free(info.flags);
1325 }
1326
1327 #endif /* CONFIG_DRIVER_NL80211_QCA */
1328
1329
wpa_driver_nl80211_capa(struct wpa_driver_nl80211_data * drv)1330 int wpa_driver_nl80211_capa(struct wpa_driver_nl80211_data *drv)
1331 {
1332 struct wiphy_info_data info;
1333 int i;
1334
1335 if (wpa_driver_nl80211_get_info(drv, &info))
1336 return -1;
1337
1338 if (info.error)
1339 return -1;
1340
1341 drv->has_capability = 1;
1342 drv->has_driver_key_mgmt = info.has_key_mgmt | info.has_key_mgmt_iftype;
1343
1344 /* Fallback to hardcoded defaults if the driver does not advertise any
1345 * AKM capabilities. */
1346 if (!drv->has_driver_key_mgmt) {
1347 drv->capa.key_mgmt = WPA_DRIVER_CAPA_KEY_MGMT_WPA |
1348 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
1349 WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
1350 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK |
1351 WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B |
1352 WPA_DRIVER_CAPA_KEY_MGMT_OWE |
1353 WPA_DRIVER_CAPA_KEY_MGMT_DPP;
1354
1355 if (drv->capa.enc & (WPA_DRIVER_CAPA_ENC_CCMP_256 |
1356 WPA_DRIVER_CAPA_ENC_GCMP_256))
1357 drv->capa.key_mgmt |=
1358 WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192;
1359
1360 if (drv->capa.flags & WPA_DRIVER_FLAGS_SME)
1361 drv->capa.key_mgmt |=
1362 WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA256 |
1363 WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA384 |
1364 WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA256 |
1365 WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA384 |
1366 WPA_DRIVER_CAPA_KEY_MGMT_SAE;
1367 else if (drv->capa.flags & WPA_DRIVER_FLAGS_FILS_SK_OFFLOAD)
1368 drv->capa.key_mgmt |=
1369 WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA256 |
1370 WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA384;
1371 }
1372
1373 if (!info.has_key_mgmt_iftype) {
1374 /* If the driver does not advertize per interface AKM
1375 * capabilities, consider all interfaces to support default AKMs
1376 * in key_mgmt. */
1377 for (i = 0; i < WPA_IF_MAX; i++)
1378 drv->capa.key_mgmt_iftype[i] = drv->capa.key_mgmt;
1379 } else if (info.has_key_mgmt_iftype && !info.has_key_mgmt) {
1380 /* If the driver advertizes only per interface supported AKMs
1381 * but does not advertize per wiphy AKM capabilities, consider
1382 * the default key_mgmt as a mask of per interface supported
1383 * AKMs. */
1384 drv->capa.key_mgmt = 0;
1385 for (i = 0; i < WPA_IF_MAX; i++)
1386 drv->capa.key_mgmt |= drv->capa.key_mgmt_iftype[i];
1387 } else if (info.has_key_mgmt_iftype && info.has_key_mgmt) {
1388 /* If the driver advertizes AKM capabilities both per wiphy and
1389 * per interface, consider the interfaces for which per
1390 * interface AKM capabilities were not received to support the
1391 * default key_mgmt capabilities.
1392 */
1393 for (i = 0; i < WPA_IF_MAX; i++)
1394 if (!drv->capa.key_mgmt_iftype[i])
1395 drv->capa.key_mgmt_iftype[i] =
1396 drv->capa.key_mgmt;
1397 }
1398
1399 drv->capa.auth = WPA_DRIVER_AUTH_OPEN |
1400 WPA_DRIVER_AUTH_SHARED |
1401 WPA_DRIVER_AUTH_LEAP;
1402
1403 drv->capa.flags |= WPA_DRIVER_FLAGS_VALID_ERROR_CODES;
1404 drv->capa.flags |= WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE;
1405 drv->capa.flags |= WPA_DRIVER_FLAGS_EAPOL_TX_STATUS;
1406
1407 /*
1408 * As all cfg80211 drivers must support cases where the AP interface is
1409 * removed without the knowledge of wpa_supplicant/hostapd, e.g., in
1410 * case that the user space daemon has crashed, they must be able to
1411 * cleanup all stations and key entries in the AP tear down flow. Thus,
1412 * this flag can/should always be set for cfg80211 drivers.
1413 */
1414 drv->capa.flags |= WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT;
1415
1416 if (!info.device_ap_sme) {
1417 drv->capa.flags |= WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS;
1418 drv->capa.flags2 |= WPA_DRIVER_FLAGS2_AP_SME;
1419
1420 /*
1421 * No AP SME is currently assumed to also indicate no AP MLME
1422 * in the driver/firmware.
1423 */
1424 drv->capa.flags |= WPA_DRIVER_FLAGS_AP_MLME;
1425 }
1426
1427 drv->device_ap_sme = info.device_ap_sme;
1428 drv->poll_command_supported = info.poll_command_supported;
1429 drv->data_tx_status = info.data_tx_status;
1430 drv->p2p_go_ctwindow_supported = info.p2p_go_ctwindow_supported;
1431 if (info.set_qos_map_supported)
1432 drv->capa.flags |= WPA_DRIVER_FLAGS_QOS_MAPPING;
1433 drv->have_low_prio_scan = info.have_low_prio_scan;
1434
1435 /*
1436 * If poll command and tx status are supported, mac80211 is new enough
1437 * to have everything we need to not need monitor interfaces.
1438 */
1439 drv->use_monitor = !info.device_ap_sme &&
1440 (!info.poll_command_supported || !info.data_tx_status);
1441
1442 /*
1443 * If we aren't going to use monitor interfaces, but the
1444 * driver doesn't support data TX status, we won't get TX
1445 * status for EAPOL frames.
1446 */
1447 if (!drv->use_monitor && !info.data_tx_status)
1448 drv->capa.flags &= ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS;
1449
1450 #ifdef CONFIG_DRIVER_NL80211_QCA
1451 if (!(info.capa->flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD))
1452 qca_nl80211_check_dfs_capa(drv);
1453 qca_nl80211_get_features(drv);
1454
1455 /*
1456 * To enable offchannel simultaneous support in wpa_supplicant, the
1457 * underlying driver needs to support the same along with offchannel TX.
1458 * Offchannel TX support is needed since remain_on_channel and
1459 * action_tx use some common data structures and hence cannot be
1460 * scheduled simultaneously.
1461 */
1462 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX))
1463 drv->capa.flags &= ~WPA_DRIVER_FLAGS_OFFCHANNEL_SIMULTANEOUS;
1464 #endif /* CONFIG_DRIVER_NL80211_QCA */
1465
1466 wpa_printf(MSG_DEBUG,
1467 "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",
1468 drv->capa.key_mgmt, drv->capa.enc, drv->capa.auth,
1469 (unsigned long long) drv->capa.flags, drv->capa.rrm_flags,
1470 drv->capa.probe_resp_offloads, drv->capa.max_stations,
1471 drv->capa.max_remain_on_chan, drv->capa.max_scan_ssids);
1472 return 0;
1473 }
1474
1475
1476 struct phy_info_arg {
1477 u16 *num_modes;
1478 struct hostapd_hw_modes *modes;
1479 int last_mode, last_chan_idx;
1480 int failed;
1481 u8 dfs_domain;
1482 };
1483
phy_info_ht_capa(struct hostapd_hw_modes * mode,struct nlattr * capa,struct nlattr * ampdu_factor,struct nlattr * ampdu_density,struct nlattr * mcs_set)1484 static void phy_info_ht_capa(struct hostapd_hw_modes *mode, struct nlattr *capa,
1485 struct nlattr *ampdu_factor,
1486 struct nlattr *ampdu_density,
1487 struct nlattr *mcs_set)
1488 {
1489 if (capa)
1490 mode->ht_capab = nla_get_u16(capa);
1491
1492 if (ampdu_factor)
1493 mode->a_mpdu_params |= nla_get_u8(ampdu_factor) & 0x03;
1494
1495 if (ampdu_density)
1496 mode->a_mpdu_params |= nla_get_u8(ampdu_density) << 2;
1497
1498 if (mcs_set && nla_len(mcs_set) >= 16) {
1499 u8 *mcs;
1500 mcs = nla_data(mcs_set);
1501 os_memcpy(mode->mcs_set, mcs, 16);
1502 }
1503 }
1504
1505
phy_info_vht_capa(struct hostapd_hw_modes * mode,struct nlattr * capa,struct nlattr * mcs_set)1506 static void phy_info_vht_capa(struct hostapd_hw_modes *mode,
1507 struct nlattr *capa,
1508 struct nlattr *mcs_set)
1509 {
1510 if (capa)
1511 mode->vht_capab = nla_get_u32(capa);
1512
1513 if (mcs_set && nla_len(mcs_set) >= 8) {
1514 u8 *mcs;
1515 mcs = nla_data(mcs_set);
1516 os_memcpy(mode->vht_mcs_set, mcs, 8);
1517 }
1518 }
1519
1520
phy_info_edmg_capa(struct hostapd_hw_modes * mode,struct nlattr * bw_config,struct nlattr * channels)1521 static int phy_info_edmg_capa(struct hostapd_hw_modes *mode,
1522 struct nlattr *bw_config,
1523 struct nlattr *channels)
1524 {
1525 if (!bw_config || !channels)
1526 return NL_OK;
1527
1528 mode->edmg.bw_config = nla_get_u8(bw_config);
1529 mode->edmg.channels = nla_get_u8(channels);
1530
1531 if (!mode->edmg.channels || !mode->edmg.bw_config)
1532 return NL_STOP;
1533
1534 return NL_OK;
1535 }
1536
1537
cw2ecw(unsigned int cw)1538 static int cw2ecw(unsigned int cw)
1539 {
1540 int bit;
1541
1542 if (cw == 0)
1543 return 0;
1544
1545 for (bit = 1; cw != 1; bit++)
1546 cw >>= 1;
1547
1548 return bit;
1549 }
1550
1551
phy_info_freq(struct hostapd_hw_modes * mode,struct hostapd_channel_data * chan,struct nlattr * tb_freq[])1552 static void phy_info_freq(struct hostapd_hw_modes *mode,
1553 struct hostapd_channel_data *chan,
1554 struct nlattr *tb_freq[])
1555 {
1556 u8 channel;
1557
1558 os_memset(chan, 0, sizeof(*chan));
1559 chan->freq = nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_FREQ]);
1560 chan->flag = 0;
1561 chan->allowed_bw = ~0;
1562 chan->dfs_cac_ms = 0;
1563 if (ieee80211_freq_to_chan(chan->freq, &channel) != NUM_HOSTAPD_MODES)
1564 chan->chan = channel;
1565 else
1566 wpa_printf(MSG_DEBUG,
1567 "nl80211: No channel number found for frequency %u MHz",
1568 chan->freq);
1569
1570 if (tb_freq[NL80211_FREQUENCY_ATTR_DISABLED])
1571 chan->flag |= HOSTAPD_CHAN_DISABLED;
1572 if (tb_freq[NL80211_FREQUENCY_ATTR_NO_IR])
1573 chan->flag |= HOSTAPD_CHAN_NO_IR;
1574 if (tb_freq[NL80211_FREQUENCY_ATTR_RADAR])
1575 chan->flag |= HOSTAPD_CHAN_RADAR;
1576 if (tb_freq[NL80211_FREQUENCY_ATTR_INDOOR_ONLY])
1577 chan->flag |= HOSTAPD_CHAN_INDOOR_ONLY;
1578 if (tb_freq[NL80211_FREQUENCY_ATTR_GO_CONCURRENT])
1579 chan->flag |= HOSTAPD_CHAN_GO_CONCURRENT;
1580
1581 if (tb_freq[NL80211_FREQUENCY_ATTR_NO_10MHZ])
1582 chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_10;
1583 if (tb_freq[NL80211_FREQUENCY_ATTR_NO_20MHZ])
1584 chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_20;
1585 if (tb_freq[NL80211_FREQUENCY_ATTR_NO_HT40_PLUS])
1586 chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_40P;
1587 if (tb_freq[NL80211_FREQUENCY_ATTR_NO_HT40_MINUS])
1588 chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_40M;
1589 if (tb_freq[NL80211_FREQUENCY_ATTR_NO_80MHZ])
1590 chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_80;
1591 if (tb_freq[NL80211_FREQUENCY_ATTR_NO_160MHZ])
1592 chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_160;
1593
1594 if (tb_freq[NL80211_FREQUENCY_ATTR_DFS_STATE]) {
1595 enum nl80211_dfs_state state =
1596 nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_DFS_STATE]);
1597
1598 switch (state) {
1599 case NL80211_DFS_USABLE:
1600 chan->flag |= HOSTAPD_CHAN_DFS_USABLE;
1601 break;
1602 case NL80211_DFS_AVAILABLE:
1603 chan->flag |= HOSTAPD_CHAN_DFS_AVAILABLE;
1604 break;
1605 case NL80211_DFS_UNAVAILABLE:
1606 chan->flag |= HOSTAPD_CHAN_DFS_UNAVAILABLE;
1607 break;
1608 }
1609 }
1610
1611 if (tb_freq[NL80211_FREQUENCY_ATTR_DFS_CAC_TIME]) {
1612 chan->dfs_cac_ms = nla_get_u32(
1613 tb_freq[NL80211_FREQUENCY_ATTR_DFS_CAC_TIME]);
1614 }
1615
1616 chan->wmm_rules_valid = 0;
1617 if (tb_freq[NL80211_FREQUENCY_ATTR_WMM]) {
1618 static struct nla_policy wmm_policy[NL80211_WMMR_MAX + 1] = {
1619 [NL80211_WMMR_CW_MIN] = { .type = NLA_U16 },
1620 [NL80211_WMMR_CW_MAX] = { .type = NLA_U16 },
1621 [NL80211_WMMR_AIFSN] = { .type = NLA_U8 },
1622 [NL80211_WMMR_TXOP] = { .type = NLA_U16 },
1623 };
1624 static const u8 wmm_map[4] = {
1625 [NL80211_AC_BE] = WMM_AC_BE,
1626 [NL80211_AC_BK] = WMM_AC_BK,
1627 [NL80211_AC_VI] = WMM_AC_VI,
1628 [NL80211_AC_VO] = WMM_AC_VO,
1629 };
1630 struct nlattr *nl_wmm;
1631 struct nlattr *tb_wmm[NL80211_WMMR_MAX + 1];
1632 int rem_wmm, ac, count = 0;
1633
1634 nla_for_each_nested(nl_wmm, tb_freq[NL80211_FREQUENCY_ATTR_WMM],
1635 rem_wmm) {
1636 if (nla_parse_nested(tb_wmm, NL80211_WMMR_MAX, nl_wmm,
1637 wmm_policy)) {
1638 wpa_printf(MSG_DEBUG,
1639 "nl80211: Failed to parse WMM rules attribute");
1640 return;
1641 }
1642 if (!tb_wmm[NL80211_WMMR_CW_MIN] ||
1643 !tb_wmm[NL80211_WMMR_CW_MAX] ||
1644 !tb_wmm[NL80211_WMMR_AIFSN] ||
1645 !tb_wmm[NL80211_WMMR_TXOP]) {
1646 wpa_printf(MSG_DEBUG,
1647 "nl80211: Channel is missing WMM rule attribute");
1648 return;
1649 }
1650 ac = nl_wmm->nla_type;
1651 if ((unsigned int) ac >= ARRAY_SIZE(wmm_map)) {
1652 wpa_printf(MSG_DEBUG,
1653 "nl80211: Invalid AC value %d", ac);
1654 return;
1655 }
1656
1657 ac = wmm_map[ac];
1658 chan->wmm_rules[ac].min_cwmin =
1659 cw2ecw(nla_get_u16(
1660 tb_wmm[NL80211_WMMR_CW_MIN]));
1661 chan->wmm_rules[ac].min_cwmax =
1662 cw2ecw(nla_get_u16(
1663 tb_wmm[NL80211_WMMR_CW_MAX]));
1664 chan->wmm_rules[ac].min_aifs =
1665 nla_get_u8(tb_wmm[NL80211_WMMR_AIFSN]);
1666 chan->wmm_rules[ac].max_txop =
1667 nla_get_u16(tb_wmm[NL80211_WMMR_TXOP]) / 32;
1668 count++;
1669 }
1670
1671 /* Set valid flag if all the AC rules are present */
1672 if (count == WMM_AC_NUM)
1673 chan->wmm_rules_valid = 1;
1674 }
1675 }
1676
1677
phy_info_freqs(struct phy_info_arg * phy_info,struct hostapd_hw_modes * mode,struct nlattr * tb)1678 static int phy_info_freqs(struct phy_info_arg *phy_info,
1679 struct hostapd_hw_modes *mode, struct nlattr *tb)
1680 {
1681 static struct nla_policy freq_policy[NL80211_FREQUENCY_ATTR_MAX + 1] = {
1682 [NL80211_FREQUENCY_ATTR_FREQ] = { .type = NLA_U32 },
1683 [NL80211_FREQUENCY_ATTR_DISABLED] = { .type = NLA_FLAG },
1684 [NL80211_FREQUENCY_ATTR_NO_IR] = { .type = NLA_FLAG },
1685 [NL80211_FREQUENCY_ATTR_RADAR] = { .type = NLA_FLAG },
1686 [NL80211_FREQUENCY_ATTR_MAX_TX_POWER] = { .type = NLA_U32 },
1687 [NL80211_FREQUENCY_ATTR_DFS_STATE] = { .type = NLA_U32 },
1688 [NL80211_FREQUENCY_ATTR_NO_10MHZ] = { .type = NLA_FLAG },
1689 [NL80211_FREQUENCY_ATTR_NO_20MHZ] = { .type = NLA_FLAG },
1690 [NL80211_FREQUENCY_ATTR_NO_HT40_PLUS] = { .type = NLA_FLAG },
1691 [NL80211_FREQUENCY_ATTR_NO_HT40_MINUS] = { .type = NLA_FLAG },
1692 [NL80211_FREQUENCY_ATTR_NO_80MHZ] = { .type = NLA_FLAG },
1693 [NL80211_FREQUENCY_ATTR_NO_160MHZ] = { .type = NLA_FLAG },
1694 };
1695 int new_channels = 0;
1696 struct hostapd_channel_data *channel;
1697 struct nlattr *tb_freq[NL80211_FREQUENCY_ATTR_MAX + 1];
1698 struct nlattr *nl_freq;
1699 int rem_freq, idx;
1700
1701 if (tb == NULL)
1702 return NL_OK;
1703
1704 nla_for_each_nested(nl_freq, tb, rem_freq) {
1705 nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX,
1706 nla_data(nl_freq), nla_len(nl_freq), freq_policy);
1707 if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ])
1708 continue;
1709 new_channels++;
1710 }
1711
1712 channel = os_realloc_array(mode->channels,
1713 mode->num_channels + new_channels,
1714 sizeof(struct hostapd_channel_data));
1715 if (!channel)
1716 return NL_STOP;
1717
1718 mode->channels = channel;
1719 mode->num_channels += new_channels;
1720
1721 idx = phy_info->last_chan_idx;
1722
1723 nla_for_each_nested(nl_freq, tb, rem_freq) {
1724 nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX,
1725 nla_data(nl_freq), nla_len(nl_freq), freq_policy);
1726 if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ])
1727 continue;
1728 phy_info_freq(mode, &mode->channels[idx], tb_freq);
1729 idx++;
1730 }
1731 phy_info->last_chan_idx = idx;
1732
1733 return NL_OK;
1734 }
1735
1736
phy_info_rates(struct hostapd_hw_modes * mode,struct nlattr * tb)1737 static int phy_info_rates(struct hostapd_hw_modes *mode, struct nlattr *tb)
1738 {
1739 static struct nla_policy rate_policy[NL80211_BITRATE_ATTR_MAX + 1] = {
1740 [NL80211_BITRATE_ATTR_RATE] = { .type = NLA_U32 },
1741 [NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE] =
1742 { .type = NLA_FLAG },
1743 };
1744 struct nlattr *tb_rate[NL80211_BITRATE_ATTR_MAX + 1];
1745 struct nlattr *nl_rate;
1746 int rem_rate, idx;
1747
1748 if (tb == NULL)
1749 return NL_OK;
1750
1751 nla_for_each_nested(nl_rate, tb, rem_rate) {
1752 nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX,
1753 nla_data(nl_rate), nla_len(nl_rate),
1754 rate_policy);
1755 if (!tb_rate[NL80211_BITRATE_ATTR_RATE])
1756 continue;
1757 mode->num_rates++;
1758 }
1759
1760 mode->rates = os_calloc(mode->num_rates, sizeof(int));
1761 if (!mode->rates)
1762 return NL_STOP;
1763
1764 idx = 0;
1765
1766 nla_for_each_nested(nl_rate, tb, rem_rate) {
1767 nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX,
1768 nla_data(nl_rate), nla_len(nl_rate),
1769 rate_policy);
1770 if (!tb_rate[NL80211_BITRATE_ATTR_RATE])
1771 continue;
1772 mode->rates[idx] = nla_get_u32(
1773 tb_rate[NL80211_BITRATE_ATTR_RATE]);
1774 idx++;
1775 }
1776
1777 return NL_OK;
1778 }
1779
1780
phy_info_iftype_copy(struct he_capabilities * he_capab,enum ieee80211_op_mode opmode,struct nlattr ** tb,struct nlattr ** tb_flags)1781 static void phy_info_iftype_copy(struct he_capabilities *he_capab,
1782 enum ieee80211_op_mode opmode,
1783 struct nlattr **tb, struct nlattr **tb_flags)
1784 {
1785 enum nl80211_iftype iftype;
1786 size_t len;
1787
1788 switch (opmode) {
1789 case IEEE80211_MODE_INFRA:
1790 iftype = NL80211_IFTYPE_STATION;
1791 break;
1792 case IEEE80211_MODE_IBSS:
1793 iftype = NL80211_IFTYPE_ADHOC;
1794 break;
1795 case IEEE80211_MODE_AP:
1796 iftype = NL80211_IFTYPE_AP;
1797 break;
1798 case IEEE80211_MODE_MESH:
1799 iftype = NL80211_IFTYPE_MESH_POINT;
1800 break;
1801 default:
1802 return;
1803 }
1804
1805 if (!nla_get_flag(tb_flags[iftype]))
1806 return;
1807
1808 he_capab->he_supported = 1;
1809
1810 if (tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY]) {
1811 len = nla_len(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY]);
1812
1813 if (len > sizeof(he_capab->phy_cap))
1814 len = sizeof(he_capab->phy_cap);
1815 os_memcpy(he_capab->phy_cap,
1816 nla_data(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY]),
1817 len);
1818 }
1819
1820 if (tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC]) {
1821 len = nla_len(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC]);
1822
1823 if (len > sizeof(he_capab->mac_cap))
1824 len = sizeof(he_capab->mac_cap);
1825 os_memcpy(he_capab->mac_cap,
1826 nla_data(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC]),
1827 len);
1828 }
1829
1830 if (tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET]) {
1831 len = nla_len(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET]);
1832
1833 if (len > sizeof(he_capab->mcs))
1834 len = sizeof(he_capab->mcs);
1835 os_memcpy(he_capab->mcs,
1836 nla_data(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET]),
1837 len);
1838 }
1839
1840 if (tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE]) {
1841 len = nla_len(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE]);
1842
1843 if (len > sizeof(he_capab->ppet))
1844 len = sizeof(he_capab->ppet);
1845 os_memcpy(&he_capab->ppet,
1846 nla_data(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE]),
1847 len);
1848 }
1849
1850 if (tb[NL80211_BAND_IFTYPE_ATTR_HE_6GHZ_CAPA]) {
1851 u16 capa;
1852
1853 capa = nla_get_u16(tb[NL80211_BAND_IFTYPE_ATTR_HE_6GHZ_CAPA]);
1854 he_capab->he_6ghz_capa = le_to_host16(capa);
1855 }
1856 }
1857
1858
phy_info_iftype(struct hostapd_hw_modes * mode,struct nlattr * nl_iftype)1859 static int phy_info_iftype(struct hostapd_hw_modes *mode,
1860 struct nlattr *nl_iftype)
1861 {
1862 struct nlattr *tb[NL80211_BAND_IFTYPE_ATTR_MAX + 1];
1863 struct nlattr *tb_flags[NL80211_IFTYPE_MAX + 1];
1864 unsigned int i;
1865
1866 nla_parse(tb, NL80211_BAND_IFTYPE_ATTR_MAX,
1867 nla_data(nl_iftype), nla_len(nl_iftype), NULL);
1868
1869 if (!tb[NL80211_BAND_IFTYPE_ATTR_IFTYPES])
1870 return NL_STOP;
1871
1872 if (nla_parse_nested(tb_flags, NL80211_IFTYPE_MAX,
1873 tb[NL80211_BAND_IFTYPE_ATTR_IFTYPES], NULL))
1874 return NL_STOP;
1875
1876 for (i = 0; i < IEEE80211_MODE_NUM; i++)
1877 phy_info_iftype_copy(&mode->he_capab[i], i, tb, tb_flags);
1878
1879 return NL_OK;
1880 }
1881
1882
phy_info_band(struct phy_info_arg * phy_info,struct nlattr * nl_band)1883 static int phy_info_band(struct phy_info_arg *phy_info, struct nlattr *nl_band)
1884 {
1885 struct nlattr *tb_band[NL80211_BAND_ATTR_MAX + 1];
1886 struct hostapd_hw_modes *mode;
1887 int ret;
1888
1889 if (phy_info->last_mode != nl_band->nla_type) {
1890 mode = os_realloc_array(phy_info->modes,
1891 *phy_info->num_modes + 1,
1892 sizeof(*mode));
1893 if (!mode) {
1894 phy_info->failed = 1;
1895 return NL_STOP;
1896 }
1897 phy_info->modes = mode;
1898
1899 mode = &phy_info->modes[*(phy_info->num_modes)];
1900 os_memset(mode, 0, sizeof(*mode));
1901 mode->mode = NUM_HOSTAPD_MODES;
1902 mode->flags = HOSTAPD_MODE_FLAG_HT_INFO_KNOWN |
1903 HOSTAPD_MODE_FLAG_VHT_INFO_KNOWN;
1904
1905 /*
1906 * Unsupported VHT MCS stream is defined as value 3, so the VHT
1907 * MCS RX/TX map must be initialized with 0xffff to mark all 8
1908 * possible streams as unsupported. This will be overridden if
1909 * driver advertises VHT support.
1910 */
1911 mode->vht_mcs_set[0] = 0xff;
1912 mode->vht_mcs_set[1] = 0xff;
1913 mode->vht_mcs_set[4] = 0xff;
1914 mode->vht_mcs_set[5] = 0xff;
1915
1916 *(phy_info->num_modes) += 1;
1917 phy_info->last_mode = nl_band->nla_type;
1918 phy_info->last_chan_idx = 0;
1919 } else
1920 mode = &phy_info->modes[*(phy_info->num_modes) - 1];
1921
1922 nla_parse(tb_band, NL80211_BAND_ATTR_MAX, nla_data(nl_band),
1923 nla_len(nl_band), NULL);
1924
1925 phy_info_ht_capa(mode, tb_band[NL80211_BAND_ATTR_HT_CAPA],
1926 tb_band[NL80211_BAND_ATTR_HT_AMPDU_FACTOR],
1927 tb_band[NL80211_BAND_ATTR_HT_AMPDU_DENSITY],
1928 tb_band[NL80211_BAND_ATTR_HT_MCS_SET]);
1929 phy_info_vht_capa(mode, tb_band[NL80211_BAND_ATTR_VHT_CAPA],
1930 tb_band[NL80211_BAND_ATTR_VHT_MCS_SET]);
1931 ret = phy_info_edmg_capa(mode,
1932 tb_band[NL80211_BAND_ATTR_EDMG_BW_CONFIG],
1933 tb_band[NL80211_BAND_ATTR_EDMG_CHANNELS]);
1934 if (ret == NL_OK)
1935 ret = phy_info_freqs(phy_info, mode,
1936 tb_band[NL80211_BAND_ATTR_FREQS]);
1937 if (ret == NL_OK)
1938 ret = phy_info_rates(mode, tb_band[NL80211_BAND_ATTR_RATES]);
1939 if (ret != NL_OK) {
1940 phy_info->failed = 1;
1941 return ret;
1942 }
1943
1944 if (tb_band[NL80211_BAND_ATTR_IFTYPE_DATA]) {
1945 struct nlattr *nl_iftype;
1946 int rem_band;
1947
1948 nla_for_each_nested(nl_iftype,
1949 tb_band[NL80211_BAND_ATTR_IFTYPE_DATA],
1950 rem_band) {
1951 ret = phy_info_iftype(mode, nl_iftype);
1952 if (ret != NL_OK)
1953 return ret;
1954 }
1955 }
1956
1957 return NL_OK;
1958 }
1959
1960
phy_info_handler(struct nl_msg * msg,void * arg)1961 static int phy_info_handler(struct nl_msg *msg, void *arg)
1962 {
1963 struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
1964 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1965 struct phy_info_arg *phy_info = arg;
1966 struct nlattr *nl_band;
1967 int rem_band;
1968
1969 nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1970 genlmsg_attrlen(gnlh, 0), NULL);
1971
1972 if (!tb_msg[NL80211_ATTR_WIPHY_BANDS])
1973 return NL_SKIP;
1974
1975 nla_for_each_nested(nl_band, tb_msg[NL80211_ATTR_WIPHY_BANDS], rem_band)
1976 {
1977 int res = phy_info_band(phy_info, nl_band);
1978 if (res != NL_OK)
1979 return res;
1980 }
1981
1982 return NL_SKIP;
1983 }
1984
1985
1986 static struct hostapd_hw_modes *
wpa_driver_nl80211_postprocess_modes(struct hostapd_hw_modes * modes,u16 * num_modes)1987 wpa_driver_nl80211_postprocess_modes(struct hostapd_hw_modes *modes,
1988 u16 *num_modes)
1989 {
1990 u16 m;
1991 struct hostapd_hw_modes *mode11g = NULL, *nmodes, *mode;
1992 int i, mode11g_idx = -1;
1993
1994 /* heuristic to set up modes */
1995 for (m = 0; m < *num_modes; m++) {
1996 if (!modes[m].num_channels)
1997 continue;
1998 if (modes[m].channels[0].freq < 2000) {
1999 modes[m].num_channels = 0;
2000 continue;
2001 } else if (modes[m].channels[0].freq < 4000) {
2002 modes[m].mode = HOSTAPD_MODE_IEEE80211B;
2003 for (i = 0; i < modes[m].num_rates; i++) {
2004 if (modes[m].rates[i] > 200) {
2005 modes[m].mode = HOSTAPD_MODE_IEEE80211G;
2006 break;
2007 }
2008 }
2009 } else if (modes[m].channels[0].freq > 50000)
2010 modes[m].mode = HOSTAPD_MODE_IEEE80211AD;
2011 else
2012 modes[m].mode = HOSTAPD_MODE_IEEE80211A;
2013 }
2014
2015 /* Remove unsupported bands */
2016 m = 0;
2017 while (m < *num_modes) {
2018 if (modes[m].mode == NUM_HOSTAPD_MODES) {
2019 wpa_printf(MSG_DEBUG,
2020 "nl80211: Remove unsupported mode");
2021 os_free(modes[m].channels);
2022 os_free(modes[m].rates);
2023 if (m + 1 < *num_modes)
2024 os_memmove(&modes[m], &modes[m + 1],
2025 sizeof(struct hostapd_hw_modes) *
2026 (*num_modes - (m + 1)));
2027 (*num_modes)--;
2028 continue;
2029 }
2030 m++;
2031 }
2032
2033 /* If only 802.11g mode is included, use it to construct matching
2034 * 802.11b mode data. */
2035
2036 for (m = 0; m < *num_modes; m++) {
2037 if (modes[m].mode == HOSTAPD_MODE_IEEE80211B)
2038 return modes; /* 802.11b already included */
2039 if (modes[m].mode == HOSTAPD_MODE_IEEE80211G)
2040 mode11g_idx = m;
2041 }
2042
2043 if (mode11g_idx < 0)
2044 return modes; /* 2.4 GHz band not supported at all */
2045
2046 nmodes = os_realloc_array(modes, *num_modes + 1, sizeof(*nmodes));
2047 if (nmodes == NULL)
2048 return modes; /* Could not add 802.11b mode */
2049
2050 mode = &nmodes[*num_modes];
2051 os_memset(mode, 0, sizeof(*mode));
2052 (*num_modes)++;
2053 modes = nmodes;
2054
2055 mode->mode = HOSTAPD_MODE_IEEE80211B;
2056
2057 mode11g = &modes[mode11g_idx];
2058 mode->num_channels = mode11g->num_channels;
2059 mode->channels = os_memdup(mode11g->channels,
2060 mode11g->num_channels *
2061 sizeof(struct hostapd_channel_data));
2062 if (mode->channels == NULL) {
2063 (*num_modes)--;
2064 return modes; /* Could not add 802.11b mode */
2065 }
2066
2067 mode->num_rates = 0;
2068 mode->rates = os_malloc(4 * sizeof(int));
2069 if (mode->rates == NULL) {
2070 os_free(mode->channels);
2071 (*num_modes)--;
2072 return modes; /* Could not add 802.11b mode */
2073 }
2074
2075 for (i = 0; i < mode11g->num_rates; i++) {
2076 if (mode11g->rates[i] != 10 && mode11g->rates[i] != 20 &&
2077 mode11g->rates[i] != 55 && mode11g->rates[i] != 110)
2078 continue;
2079 mode->rates[mode->num_rates] = mode11g->rates[i];
2080 mode->num_rates++;
2081 if (mode->num_rates == 4)
2082 break;
2083 }
2084
2085 if (mode->num_rates == 0) {
2086 os_free(mode->channels);
2087 os_free(mode->rates);
2088 (*num_modes)--;
2089 return modes; /* No 802.11b rates */
2090 }
2091
2092 wpa_printf(MSG_DEBUG, "nl80211: Added 802.11b mode based on 802.11g "
2093 "information");
2094
2095 return modes;
2096 }
2097
2098
nl80211_set_ht40_mode(struct hostapd_hw_modes * mode,int start,int end)2099 static void nl80211_set_ht40_mode(struct hostapd_hw_modes *mode, int start,
2100 int end)
2101 {
2102 int c;
2103
2104 for (c = 0; c < mode->num_channels; c++) {
2105 struct hostapd_channel_data *chan = &mode->channels[c];
2106 if (chan->freq - 10 >= start && chan->freq + 10 <= end)
2107 chan->flag |= HOSTAPD_CHAN_HT40;
2108 }
2109 }
2110
2111
nl80211_set_ht40_mode_sec(struct hostapd_hw_modes * mode,int start,int end)2112 static void nl80211_set_ht40_mode_sec(struct hostapd_hw_modes *mode, int start,
2113 int end)
2114 {
2115 int c;
2116
2117 for (c = 0; c < mode->num_channels; c++) {
2118 struct hostapd_channel_data *chan = &mode->channels[c];
2119 if (!(chan->flag & HOSTAPD_CHAN_HT40))
2120 continue;
2121 if (chan->freq - 30 >= start && chan->freq - 10 <= end)
2122 chan->flag |= HOSTAPD_CHAN_HT40MINUS;
2123 if (chan->freq + 10 >= start && chan->freq + 30 <= end)
2124 chan->flag |= HOSTAPD_CHAN_HT40PLUS;
2125 }
2126 }
2127
2128
nl80211_reg_rule_max_eirp(u32 start,u32 end,u32 max_eirp,struct phy_info_arg * results)2129 static void nl80211_reg_rule_max_eirp(u32 start, u32 end, u32 max_eirp,
2130 struct phy_info_arg *results)
2131 {
2132 u16 m;
2133
2134 for (m = 0; m < *results->num_modes; m++) {
2135 int c;
2136 struct hostapd_hw_modes *mode = &results->modes[m];
2137
2138 for (c = 0; c < mode->num_channels; c++) {
2139 struct hostapd_channel_data *chan = &mode->channels[c];
2140 if ((u32) chan->freq - 10 >= start &&
2141 (u32) chan->freq + 10 <= end)
2142 chan->max_tx_power = max_eirp;
2143 }
2144 }
2145 }
2146
2147
nl80211_reg_rule_ht40(u32 start,u32 end,struct phy_info_arg * results)2148 static void nl80211_reg_rule_ht40(u32 start, u32 end,
2149 struct phy_info_arg *results)
2150 {
2151 u16 m;
2152
2153 for (m = 0; m < *results->num_modes; m++) {
2154 if (!(results->modes[m].ht_capab &
2155 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET))
2156 continue;
2157 nl80211_set_ht40_mode(&results->modes[m], start, end);
2158 }
2159 }
2160
2161
nl80211_reg_rule_sec(struct nlattr * tb[],struct phy_info_arg * results)2162 static void nl80211_reg_rule_sec(struct nlattr *tb[],
2163 struct phy_info_arg *results)
2164 {
2165 u32 start, end, max_bw;
2166 u16 m;
2167
2168 if (tb[NL80211_ATTR_FREQ_RANGE_START] == NULL ||
2169 tb[NL80211_ATTR_FREQ_RANGE_END] == NULL ||
2170 tb[NL80211_ATTR_FREQ_RANGE_MAX_BW] == NULL)
2171 return;
2172
2173 start = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]) / 1000;
2174 end = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]) / 1000;
2175 max_bw = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) / 1000;
2176
2177 if (max_bw < 20)
2178 return;
2179
2180 for (m = 0; m < *results->num_modes; m++) {
2181 if (!(results->modes[m].ht_capab &
2182 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET))
2183 continue;
2184 nl80211_set_ht40_mode_sec(&results->modes[m], start, end);
2185 }
2186 }
2187
2188
nl80211_set_vht_mode(struct hostapd_hw_modes * mode,int start,int end,int max_bw)2189 static void nl80211_set_vht_mode(struct hostapd_hw_modes *mode, int start,
2190 int end, int max_bw)
2191 {
2192 int c;
2193
2194 for (c = 0; c < mode->num_channels; c++) {
2195 struct hostapd_channel_data *chan = &mode->channels[c];
2196 if (chan->freq - 10 >= start && chan->freq + 70 <= end)
2197 chan->flag |= HOSTAPD_CHAN_VHT_10_70;
2198
2199 if (chan->freq - 30 >= start && chan->freq + 50 <= end)
2200 chan->flag |= HOSTAPD_CHAN_VHT_30_50;
2201
2202 if (chan->freq - 50 >= start && chan->freq + 30 <= end)
2203 chan->flag |= HOSTAPD_CHAN_VHT_50_30;
2204
2205 if (chan->freq - 70 >= start && chan->freq + 10 <= end)
2206 chan->flag |= HOSTAPD_CHAN_VHT_70_10;
2207
2208 if (max_bw >= 160) {
2209 if (chan->freq - 10 >= start && chan->freq + 150 <= end)
2210 chan->flag |= HOSTAPD_CHAN_VHT_10_150;
2211
2212 if (chan->freq - 30 >= start && chan->freq + 130 <= end)
2213 chan->flag |= HOSTAPD_CHAN_VHT_30_130;
2214
2215 if (chan->freq - 50 >= start && chan->freq + 110 <= end)
2216 chan->flag |= HOSTAPD_CHAN_VHT_50_110;
2217
2218 if (chan->freq - 70 >= start && chan->freq + 90 <= end)
2219 chan->flag |= HOSTAPD_CHAN_VHT_70_90;
2220
2221 if (chan->freq - 90 >= start && chan->freq + 70 <= end)
2222 chan->flag |= HOSTAPD_CHAN_VHT_90_70;
2223
2224 if (chan->freq - 110 >= start && chan->freq + 50 <= end)
2225 chan->flag |= HOSTAPD_CHAN_VHT_110_50;
2226
2227 if (chan->freq - 130 >= start && chan->freq + 30 <= end)
2228 chan->flag |= HOSTAPD_CHAN_VHT_130_30;
2229
2230 if (chan->freq - 150 >= start && chan->freq + 10 <= end)
2231 chan->flag |= HOSTAPD_CHAN_VHT_150_10;
2232 }
2233 }
2234 }
2235
2236
nl80211_reg_rule_vht(struct nlattr * tb[],struct phy_info_arg * results)2237 static void nl80211_reg_rule_vht(struct nlattr *tb[],
2238 struct phy_info_arg *results)
2239 {
2240 u32 start, end, max_bw;
2241 u16 m;
2242
2243 if (tb[NL80211_ATTR_FREQ_RANGE_START] == NULL ||
2244 tb[NL80211_ATTR_FREQ_RANGE_END] == NULL ||
2245 tb[NL80211_ATTR_FREQ_RANGE_MAX_BW] == NULL)
2246 return;
2247
2248 start = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]) / 1000;
2249 end = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]) / 1000;
2250 max_bw = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) / 1000;
2251
2252 if (max_bw < 80)
2253 return;
2254
2255 for (m = 0; m < *results->num_modes; m++) {
2256 if (!(results->modes[m].ht_capab &
2257 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET))
2258 continue;
2259 /* TODO: use a real VHT support indication */
2260 if (!results->modes[m].vht_capab)
2261 continue;
2262
2263 nl80211_set_vht_mode(&results->modes[m], start, end, max_bw);
2264 }
2265 }
2266
2267
nl80211_set_dfs_domain(enum nl80211_dfs_regions region,u8 * dfs_domain)2268 static void nl80211_set_dfs_domain(enum nl80211_dfs_regions region,
2269 u8 *dfs_domain)
2270 {
2271 if (region == NL80211_DFS_FCC)
2272 *dfs_domain = HOSTAPD_DFS_REGION_FCC;
2273 else if (region == NL80211_DFS_ETSI)
2274 *dfs_domain = HOSTAPD_DFS_REGION_ETSI;
2275 else if (region == NL80211_DFS_JP)
2276 *dfs_domain = HOSTAPD_DFS_REGION_JP;
2277 else
2278 *dfs_domain = 0;
2279 }
2280
2281
dfs_domain_name(enum nl80211_dfs_regions region)2282 static const char * dfs_domain_name(enum nl80211_dfs_regions region)
2283 {
2284 switch (region) {
2285 case NL80211_DFS_UNSET:
2286 return "DFS-UNSET";
2287 case NL80211_DFS_FCC:
2288 return "DFS-FCC";
2289 case NL80211_DFS_ETSI:
2290 return "DFS-ETSI";
2291 case NL80211_DFS_JP:
2292 return "DFS-JP";
2293 default:
2294 return "DFS-invalid";
2295 }
2296 }
2297
2298
nl80211_get_reg(struct nl_msg * msg,void * arg)2299 static int nl80211_get_reg(struct nl_msg *msg, void *arg)
2300 {
2301 struct phy_info_arg *results = arg;
2302 struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
2303 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
2304 struct nlattr *nl_rule;
2305 struct nlattr *tb_rule[NL80211_FREQUENCY_ATTR_MAX + 1];
2306 int rem_rule;
2307 static struct nla_policy reg_policy[NL80211_FREQUENCY_ATTR_MAX + 1] = {
2308 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
2309 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
2310 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
2311 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
2312 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
2313 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
2314 };
2315
2316 nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
2317 genlmsg_attrlen(gnlh, 0), NULL);
2318 if (!tb_msg[NL80211_ATTR_REG_ALPHA2] ||
2319 !tb_msg[NL80211_ATTR_REG_RULES]) {
2320 wpa_printf(MSG_DEBUG, "nl80211: No regulatory information "
2321 "available");
2322 return NL_SKIP;
2323 }
2324
2325 if (tb_msg[NL80211_ATTR_DFS_REGION]) {
2326 enum nl80211_dfs_regions dfs_domain;
2327 dfs_domain = nla_get_u8(tb_msg[NL80211_ATTR_DFS_REGION]);
2328 nl80211_set_dfs_domain(dfs_domain, &results->dfs_domain);
2329 wpa_printf(MSG_DEBUG, "nl80211: Regulatory information - country=%s (%s)",
2330 (char *) nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]),
2331 dfs_domain_name(dfs_domain));
2332 } else {
2333 wpa_printf(MSG_DEBUG, "nl80211: Regulatory information - country=%s",
2334 (char *) nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]));
2335 }
2336
2337 nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule)
2338 {
2339 u32 start, end, max_eirp = 0, max_bw = 0, flags = 0;
2340 nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX,
2341 nla_data(nl_rule), nla_len(nl_rule), reg_policy);
2342 if (tb_rule[NL80211_ATTR_FREQ_RANGE_START] == NULL ||
2343 tb_rule[NL80211_ATTR_FREQ_RANGE_END] == NULL)
2344 continue;
2345 start = nla_get_u32(tb_rule[NL80211_ATTR_FREQ_RANGE_START]) / 1000;
2346 end = nla_get_u32(tb_rule[NL80211_ATTR_FREQ_RANGE_END]) / 1000;
2347 if (tb_rule[NL80211_ATTR_POWER_RULE_MAX_EIRP])
2348 max_eirp = nla_get_u32(tb_rule[NL80211_ATTR_POWER_RULE_MAX_EIRP]) / 100;
2349 if (tb_rule[NL80211_ATTR_FREQ_RANGE_MAX_BW])
2350 max_bw = nla_get_u32(tb_rule[NL80211_ATTR_FREQ_RANGE_MAX_BW]) / 1000;
2351 if (tb_rule[NL80211_ATTR_REG_RULE_FLAGS])
2352 flags = nla_get_u32(tb_rule[NL80211_ATTR_REG_RULE_FLAGS]);
2353
2354 wpa_printf(MSG_DEBUG, "nl80211: %u-%u @ %u MHz %u mBm%s%s%s%s%s%s%s%s",
2355 start, end, max_bw, max_eirp,
2356 flags & NL80211_RRF_NO_OFDM ? " (no OFDM)" : "",
2357 flags & NL80211_RRF_NO_CCK ? " (no CCK)" : "",
2358 flags & NL80211_RRF_NO_INDOOR ? " (no indoor)" : "",
2359 flags & NL80211_RRF_NO_OUTDOOR ? " (no outdoor)" :
2360 "",
2361 flags & NL80211_RRF_DFS ? " (DFS)" : "",
2362 flags & NL80211_RRF_PTP_ONLY ? " (PTP only)" : "",
2363 flags & NL80211_RRF_PTMP_ONLY ? " (PTMP only)" : "",
2364 flags & NL80211_RRF_NO_IR ? " (no IR)" : "");
2365 if (max_bw >= 40)
2366 nl80211_reg_rule_ht40(start, end, results);
2367 if (tb_rule[NL80211_ATTR_POWER_RULE_MAX_EIRP])
2368 nl80211_reg_rule_max_eirp(start, end, max_eirp,
2369 results);
2370 }
2371
2372 nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule)
2373 {
2374 nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX,
2375 nla_data(nl_rule), nla_len(nl_rule), reg_policy);
2376 nl80211_reg_rule_sec(tb_rule, results);
2377 }
2378
2379 nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule)
2380 {
2381 nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX,
2382 nla_data(nl_rule), nla_len(nl_rule), reg_policy);
2383 nl80211_reg_rule_vht(tb_rule, results);
2384 }
2385
2386 return NL_SKIP;
2387 }
2388
2389
nl80211_set_regulatory_flags(struct wpa_driver_nl80211_data * drv,struct phy_info_arg * results)2390 static int nl80211_set_regulatory_flags(struct wpa_driver_nl80211_data *drv,
2391 struct phy_info_arg *results)
2392 {
2393 struct nl_msg *msg;
2394
2395 msg = nlmsg_alloc();
2396 if (!msg)
2397 return -ENOMEM;
2398
2399 nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG);
2400 if (drv->capa.flags & WPA_DRIVER_FLAGS_SELF_MANAGED_REGULATORY) {
2401 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, drv->wiphy_idx)) {
2402 nlmsg_free(msg);
2403 return -1;
2404 }
2405 }
2406
2407 return send_and_recv_msgs(drv, msg, nl80211_get_reg, results,
2408 NULL, NULL);
2409 }
2410
2411
modestr(enum hostapd_hw_mode mode)2412 static const char * modestr(enum hostapd_hw_mode mode)
2413 {
2414 switch (mode) {
2415 case HOSTAPD_MODE_IEEE80211B:
2416 return "802.11b";
2417 case HOSTAPD_MODE_IEEE80211G:
2418 return "802.11g";
2419 case HOSTAPD_MODE_IEEE80211A:
2420 return "802.11a";
2421 case HOSTAPD_MODE_IEEE80211AD:
2422 return "802.11ad";
2423 default:
2424 return "?";
2425 }
2426 }
2427
2428
nl80211_dump_chan_list(struct hostapd_hw_modes * modes,u16 num_modes)2429 static void nl80211_dump_chan_list(struct hostapd_hw_modes *modes,
2430 u16 num_modes)
2431 {
2432 int i;
2433
2434 if (!modes)
2435 return;
2436
2437 for (i = 0; i < num_modes; i++) {
2438 struct hostapd_hw_modes *mode = &modes[i];
2439 char str[200];
2440 char *pos = str;
2441 char *end = pos + sizeof(str);
2442 int j, res;
2443
2444 for (j = 0; j < mode->num_channels; j++) {
2445 struct hostapd_channel_data *chan = &mode->channels[j];
2446
2447 res = os_snprintf(pos, end - pos, " %d%s%s%s",
2448 chan->freq,
2449 (chan->flag & HOSTAPD_CHAN_DISABLED) ?
2450 "[DISABLED]" : "",
2451 (chan->flag & HOSTAPD_CHAN_NO_IR) ?
2452 "[NO_IR]" : "",
2453 (chan->flag & HOSTAPD_CHAN_RADAR) ?
2454 "[RADAR]" : "");
2455 if (os_snprintf_error(end - pos, res))
2456 break;
2457 pos += res;
2458 }
2459
2460 *pos = '\0';
2461 wpa_printf(MSG_DEBUG, "nl80211: Mode IEEE %s:%s",
2462 modestr(mode->mode), str);
2463 }
2464 }
2465
2466
2467 struct hostapd_hw_modes *
nl80211_get_hw_feature_data(void * priv,u16 * num_modes,u16 * flags,u8 * dfs_domain)2468 nl80211_get_hw_feature_data(void *priv, u16 *num_modes, u16 *flags,
2469 u8 *dfs_domain)
2470 {
2471 u32 feat;
2472 struct i802_bss *bss = priv;
2473 struct wpa_driver_nl80211_data *drv = bss->drv;
2474 int nl_flags = 0;
2475 struct nl_msg *msg;
2476 struct phy_info_arg result = {
2477 .num_modes = num_modes,
2478 .modes = NULL,
2479 .last_mode = -1,
2480 .failed = 0,
2481 .dfs_domain = 0,
2482 };
2483
2484 *num_modes = 0;
2485 *flags = 0;
2486 *dfs_domain = 0;
2487
2488 feat = get_nl80211_protocol_features(drv);
2489 if (feat & NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)
2490 nl_flags = NLM_F_DUMP;
2491 if (!(msg = nl80211_cmd_msg(bss, nl_flags, NL80211_CMD_GET_WIPHY)) ||
2492 nla_put_flag(msg, NL80211_ATTR_SPLIT_WIPHY_DUMP)) {
2493 nlmsg_free(msg);
2494 return NULL;
2495 }
2496
2497 if (send_and_recv_msgs(drv, msg, phy_info_handler, &result,
2498 NULL, NULL) == 0) {
2499 struct hostapd_hw_modes *modes;
2500
2501 nl80211_set_regulatory_flags(drv, &result);
2502 if (result.failed) {
2503 int i;
2504
2505 for (i = 0; result.modes && i < *num_modes; i++) {
2506 os_free(result.modes[i].channels);
2507 os_free(result.modes[i].rates);
2508 }
2509 os_free(result.modes);
2510 *num_modes = 0;
2511 return NULL;
2512 }
2513
2514 *dfs_domain = result.dfs_domain;
2515
2516 modes = wpa_driver_nl80211_postprocess_modes(result.modes,
2517 num_modes);
2518 nl80211_dump_chan_list(modes, *num_modes);
2519 return modes;
2520 }
2521
2522 return NULL;
2523 }
2524