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