]> git.ipfire.org Git - thirdparty/hostap.git/blame - src/drivers/driver_nl80211_capa.c
Define all RSN_CIPHER_SUITE_* values
[thirdparty/hostap.git] / src / drivers / driver_nl80211_capa.c
CommitLineData
0fafeb54
JM
1/*
2 * Driver interaction with Linux nl80211/cfg80211 - Capabilities
399e6135 3 * Copyright (c) 2002-2015, Jouni Malinen <j@w1.fi>
0fafeb54
JM
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_defs.h"
16#include "common/ieee802_11_common.h"
17#include "common/qca-vendor.h"
18#include "common/qca-vendor-attr.h"
19#include "driver_nl80211.h"
20
21
22static int protocol_feature_handler(struct nl_msg *msg, void *arg)
23{
24 u32 *feat = arg;
25 struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
26 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
27
28 nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
29 genlmsg_attrlen(gnlh, 0), NULL);
30
31 if (tb_msg[NL80211_ATTR_PROTOCOL_FEATURES])
32 *feat = nla_get_u32(tb_msg[NL80211_ATTR_PROTOCOL_FEATURES]);
33
34 return NL_SKIP;
35}
36
37
38static u32 get_nl80211_protocol_features(struct wpa_driver_nl80211_data *drv)
39{
40 u32 feat = 0;
41 struct nl_msg *msg;
42
43 msg = nlmsg_alloc();
44 if (!msg)
9589a91e
JM
45 return 0;
46
47 if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_PROTOCOL_FEATURES)) {
48 nlmsg_free(msg);
49 return 0;
50 }
0fafeb54 51
0fafeb54
JM
52 if (send_and_recv_msgs(drv, msg, protocol_feature_handler, &feat) == 0)
53 return feat;
54
0fafeb54
JM
55 return 0;
56}
57
58
59struct wiphy_info_data {
60 struct wpa_driver_nl80211_data *drv;
61 struct wpa_driver_capa *capa;
62
63 unsigned int num_multichan_concurrent;
64
65 unsigned int error:1;
66 unsigned int device_ap_sme:1;
67 unsigned int poll_command_supported:1;
68 unsigned int data_tx_status:1;
0fafeb54
JM
69 unsigned int auth_supported:1;
70 unsigned int connect_supported:1;
71 unsigned int p2p_go_supported:1;
72 unsigned int p2p_client_supported:1;
abb8d08b 73 unsigned int p2p_go_ctwindow_supported:1;
0fafeb54
JM
74 unsigned int p2p_concurrent:1;
75 unsigned int channel_switch_supported:1;
76 unsigned int set_qos_map_supported:1;
77 unsigned int have_low_prio_scan:1;
dfa87878 78 unsigned int wmm_ac_supported:1;
86056fea
IP
79 unsigned int mac_addr_rand_scan_supported:1;
80 unsigned int mac_addr_rand_sched_scan_supported:1;
0fafeb54
JM
81};
82
83
84static unsigned int probe_resp_offload_support(int supp_protocols)
85{
86 unsigned int prot = 0;
87
88 if (supp_protocols & NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS)
89 prot |= WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS;
90 if (supp_protocols & NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2)
91 prot |= WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2;
92 if (supp_protocols & NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P)
93 prot |= WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P;
94 if (supp_protocols & NL80211_PROBE_RESP_OFFLOAD_SUPPORT_80211U)
95 prot |= WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING;
96
97 return prot;
98}
99
100
101static void wiphy_info_supported_iftypes(struct wiphy_info_data *info,
102 struct nlattr *tb)
103{
104 struct nlattr *nl_mode;
105 int i;
106
107 if (tb == NULL)
108 return;
109
110 nla_for_each_nested(nl_mode, tb, i) {
111 switch (nla_type(nl_mode)) {
112 case NL80211_IFTYPE_AP:
113 info->capa->flags |= WPA_DRIVER_FLAGS_AP;
114 break;
115 case NL80211_IFTYPE_MESH_POINT:
116 info->capa->flags |= WPA_DRIVER_FLAGS_MESH;
117 break;
118 case NL80211_IFTYPE_ADHOC:
119 info->capa->flags |= WPA_DRIVER_FLAGS_IBSS;
120 break;
121 case NL80211_IFTYPE_P2P_DEVICE:
122 info->capa->flags |=
123 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE;
124 break;
125 case NL80211_IFTYPE_P2P_GO:
126 info->p2p_go_supported = 1;
127 break;
128 case NL80211_IFTYPE_P2P_CLIENT:
129 info->p2p_client_supported = 1;
130 break;
0fafeb54
JM
131 }
132 }
133}
134
135
136static int wiphy_info_iface_comb_process(struct wiphy_info_data *info,
137 struct nlattr *nl_combi)
138{
139 struct nlattr *tb_comb[NUM_NL80211_IFACE_COMB];
140 struct nlattr *tb_limit[NUM_NL80211_IFACE_LIMIT];
141 struct nlattr *nl_limit, *nl_mode;
142 int err, rem_limit, rem_mode;
143 int combination_has_p2p = 0, combination_has_mgd = 0;
144 static struct nla_policy
145 iface_combination_policy[NUM_NL80211_IFACE_COMB] = {
146 [NL80211_IFACE_COMB_LIMITS] = { .type = NLA_NESTED },
147 [NL80211_IFACE_COMB_MAXNUM] = { .type = NLA_U32 },
148 [NL80211_IFACE_COMB_STA_AP_BI_MATCH] = { .type = NLA_FLAG },
149 [NL80211_IFACE_COMB_NUM_CHANNELS] = { .type = NLA_U32 },
150 [NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS] = { .type = NLA_U32 },
151 },
152 iface_limit_policy[NUM_NL80211_IFACE_LIMIT] = {
153 [NL80211_IFACE_LIMIT_TYPES] = { .type = NLA_NESTED },
154 [NL80211_IFACE_LIMIT_MAX] = { .type = NLA_U32 },
155 };
156
157 err = nla_parse_nested(tb_comb, MAX_NL80211_IFACE_COMB,
158 nl_combi, iface_combination_policy);
159 if (err || !tb_comb[NL80211_IFACE_COMB_LIMITS] ||
160 !tb_comb[NL80211_IFACE_COMB_MAXNUM] ||
161 !tb_comb[NL80211_IFACE_COMB_NUM_CHANNELS])
162 return 0; /* broken combination */
163
164 if (tb_comb[NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS])
165 info->capa->flags |= WPA_DRIVER_FLAGS_RADAR;
166
167 nla_for_each_nested(nl_limit, tb_comb[NL80211_IFACE_COMB_LIMITS],
168 rem_limit) {
169 err = nla_parse_nested(tb_limit, MAX_NL80211_IFACE_LIMIT,
170 nl_limit, iface_limit_policy);
171 if (err || !tb_limit[NL80211_IFACE_LIMIT_TYPES])
172 return 0; /* broken combination */
173
174 nla_for_each_nested(nl_mode,
175 tb_limit[NL80211_IFACE_LIMIT_TYPES],
176 rem_mode) {
177 int ift = nla_type(nl_mode);
178 if (ift == NL80211_IFTYPE_P2P_GO ||
179 ift == NL80211_IFTYPE_P2P_CLIENT)
180 combination_has_p2p = 1;
181 if (ift == NL80211_IFTYPE_STATION)
182 combination_has_mgd = 1;
183 }
184 if (combination_has_p2p && combination_has_mgd)
185 break;
186 }
187
188 if (combination_has_p2p && combination_has_mgd) {
189 unsigned int num_channels =
190 nla_get_u32(tb_comb[NL80211_IFACE_COMB_NUM_CHANNELS]);
191
192 info->p2p_concurrent = 1;
193 if (info->num_multichan_concurrent < num_channels)
194 info->num_multichan_concurrent = num_channels;
195 }
196
197 return 0;
198}
199
200
201static void wiphy_info_iface_comb(struct wiphy_info_data *info,
202 struct nlattr *tb)
203{
204 struct nlattr *nl_combi;
205 int rem_combi;
206
207 if (tb == NULL)
208 return;
209
210 nla_for_each_nested(nl_combi, tb, rem_combi) {
211 if (wiphy_info_iface_comb_process(info, nl_combi) > 0)
212 break;
213 }
214}
215
216
217static void wiphy_info_supp_cmds(struct wiphy_info_data *info,
218 struct nlattr *tb)
219{
220 struct nlattr *nl_cmd;
221 int i;
222
223 if (tb == NULL)
224 return;
225
226 nla_for_each_nested(nl_cmd, tb, i) {
227 switch (nla_get_u32(nl_cmd)) {
228 case NL80211_CMD_AUTHENTICATE:
229 info->auth_supported = 1;
230 break;
231 case NL80211_CMD_CONNECT:
232 info->connect_supported = 1;
233 break;
234 case NL80211_CMD_START_SCHED_SCAN:
235 info->capa->sched_scan_supported = 1;
236 break;
237 case NL80211_CMD_PROBE_CLIENT:
238 info->poll_command_supported = 1;
239 break;
240 case NL80211_CMD_CHANNEL_SWITCH:
241 info->channel_switch_supported = 1;
242 break;
243 case NL80211_CMD_SET_QOS_MAP:
244 info->set_qos_map_supported = 1;
245 break;
246 }
247 }
248}
249
250
251static void wiphy_info_cipher_suites(struct wiphy_info_data *info,
252 struct nlattr *tb)
253{
254 int i, num;
255 u32 *ciphers;
256
257 if (tb == NULL)
258 return;
259
260 num = nla_len(tb) / sizeof(u32);
261 ciphers = nla_data(tb);
262 for (i = 0; i < num; i++) {
263 u32 c = ciphers[i];
264
265 wpa_printf(MSG_DEBUG, "nl80211: Supported cipher %02x-%02x-%02x:%d",
266 c >> 24, (c >> 16) & 0xff,
267 (c >> 8) & 0xff, c & 0xff);
268 switch (c) {
269 case WLAN_CIPHER_SUITE_CCMP_256:
270 info->capa->enc |= WPA_DRIVER_CAPA_ENC_CCMP_256;
271 break;
272 case WLAN_CIPHER_SUITE_GCMP_256:
273 info->capa->enc |= WPA_DRIVER_CAPA_ENC_GCMP_256;
274 break;
275 case WLAN_CIPHER_SUITE_CCMP:
276 info->capa->enc |= WPA_DRIVER_CAPA_ENC_CCMP;
277 break;
278 case WLAN_CIPHER_SUITE_GCMP:
279 info->capa->enc |= WPA_DRIVER_CAPA_ENC_GCMP;
280 break;
281 case WLAN_CIPHER_SUITE_TKIP:
282 info->capa->enc |= WPA_DRIVER_CAPA_ENC_TKIP;
283 break;
284 case WLAN_CIPHER_SUITE_WEP104:
285 info->capa->enc |= WPA_DRIVER_CAPA_ENC_WEP104;
286 break;
287 case WLAN_CIPHER_SUITE_WEP40:
288 info->capa->enc |= WPA_DRIVER_CAPA_ENC_WEP40;
289 break;
290 case WLAN_CIPHER_SUITE_AES_CMAC:
291 info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP;
292 break;
293 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
294 info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP_GMAC_128;
295 break;
296 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
297 info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP_GMAC_256;
298 break;
299 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
300 info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP_CMAC_256;
301 break;
302 case WLAN_CIPHER_SUITE_NO_GROUP_ADDR:
303 info->capa->enc |= WPA_DRIVER_CAPA_ENC_GTK_NOT_USED;
304 break;
305 }
306 }
307}
308
309
310static void wiphy_info_max_roc(struct wpa_driver_capa *capa,
311 struct nlattr *tb)
312{
313 if (tb)
314 capa->max_remain_on_chan = nla_get_u32(tb);
315}
316
317
318static void wiphy_info_tdls(struct wpa_driver_capa *capa, struct nlattr *tdls,
319 struct nlattr *ext_setup)
320{
321 if (tdls == NULL)
322 return;
323
324 wpa_printf(MSG_DEBUG, "nl80211: TDLS supported");
325 capa->flags |= WPA_DRIVER_FLAGS_TDLS_SUPPORT;
326
327 if (ext_setup) {
328 wpa_printf(MSG_DEBUG, "nl80211: TDLS external setup");
329 capa->flags |= WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP;
330 }
331}
332
333
4acdc48a
JD
334static int ext_feature_isset(const u8 *ext_features, int ext_features_len,
335 enum nl80211_ext_feature_index ftidx)
336{
337 u8 ft_byte;
338
339 if ((int) ftidx / 8 >= ext_features_len)
340 return 0;
341
342 ft_byte = ext_features[ftidx / 8];
343 return (ft_byte & BIT(ftidx % 8)) != 0;
344}
345
346
347static void wiphy_info_ext_feature_flags(struct wiphy_info_data *info,
348 struct nlattr *tb)
349{
350 struct wpa_driver_capa *capa = info->capa;
b5d172e5
BL
351 u8 *ext_features;
352 int len;
4acdc48a
JD
353
354 if (tb == NULL)
355 return;
356
b5d172e5
BL
357 ext_features = nla_data(tb);
358 len = nla_len(tb);
359
360 if (ext_feature_isset(ext_features, len, NL80211_EXT_FEATURE_VHT_IBSS))
4acdc48a 361 capa->flags |= WPA_DRIVER_FLAGS_VHT_IBSS;
b5d172e5
BL
362
363 if (ext_feature_isset(ext_features, len, NL80211_EXT_FEATURE_RRM))
364 capa->rrm_flags |= WPA_DRIVER_FLAGS_SUPPORT_RRM;
befdb2dc
JM
365
366 if (ext_feature_isset(ext_features, len, NL80211_EXT_FEATURE_FILS_STA))
367 capa->flags |= WPA_DRIVER_FLAGS_SUPPORT_FILS;
d4f3003c
PK
368
369 if (ext_feature_isset(ext_features, len,
370 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY))
371 capa->flags |= WPA_DRIVER_FLAGS_BEACON_RATE_LEGACY;
372
373 if (ext_feature_isset(ext_features, len,
374 NL80211_EXT_FEATURE_BEACON_RATE_HT))
375 capa->flags |= WPA_DRIVER_FLAGS_BEACON_RATE_HT;
376
377 if (ext_feature_isset(ext_features, len,
378 NL80211_EXT_FEATURE_BEACON_RATE_VHT))
379 capa->flags |= WPA_DRIVER_FLAGS_BEACON_RATE_VHT;
96a5f14e
AS
380
381 if (ext_feature_isset(ext_features, len,
382 NL80211_EXT_FEATURE_SET_SCAN_DWELL))
383 capa->rrm_flags |= WPA_DRIVER_FLAGS_SUPPORT_SET_SCAN_DWELL;
384
385 if (ext_feature_isset(ext_features, len,
386 NL80211_EXT_FEATURE_SCAN_START_TIME) &&
387 ext_feature_isset(ext_features, len,
388 NL80211_EXT_FEATURE_BSS_PARENT_TSF) &&
389 ext_feature_isset(ext_features, len,
390 NL80211_EXT_FEATURE_SET_SCAN_DWELL))
391 capa->rrm_flags |= WPA_DRIVER_FLAGS_SUPPORT_BEACON_REPORT;
4acdc48a
JD
392}
393
394
0fafeb54
JM
395static void wiphy_info_feature_flags(struct wiphy_info_data *info,
396 struct nlattr *tb)
397{
398 u32 flags;
399 struct wpa_driver_capa *capa = info->capa;
400
401 if (tb == NULL)
402 return;
403
404 flags = nla_get_u32(tb);
405
406 if (flags & NL80211_FEATURE_SK_TX_STATUS)
407 info->data_tx_status = 1;
408
409 if (flags & NL80211_FEATURE_INACTIVITY_TIMER)
410 capa->flags |= WPA_DRIVER_FLAGS_INACTIVITY_TIMER;
411
412 if (flags & NL80211_FEATURE_SAE)
413 capa->flags |= WPA_DRIVER_FLAGS_SAE;
414
415 if (flags & NL80211_FEATURE_NEED_OBSS_SCAN)
416 capa->flags |= WPA_DRIVER_FLAGS_OBSS_SCAN;
417
418 if (flags & NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)
419 capa->flags |= WPA_DRIVER_FLAGS_HT_2040_COEX;
420
4daa5729
AN
421 if (flags & NL80211_FEATURE_TDLS_CHANNEL_SWITCH) {
422 wpa_printf(MSG_DEBUG, "nl80211: TDLS channel switch");
423 capa->flags |= WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH;
424 }
425
abb8d08b
EP
426 if (flags & NL80211_FEATURE_P2P_GO_CTWIN)
427 info->p2p_go_ctwindow_supported = 1;
428
0fafeb54
JM
429 if (flags & NL80211_FEATURE_LOW_PRIORITY_SCAN)
430 info->have_low_prio_scan = 1;
431
86056fea
IP
432 if (flags & NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)
433 info->mac_addr_rand_scan_supported = 1;
434
435 if (flags & NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR)
436 info->mac_addr_rand_sched_scan_supported = 1;
437
0fafeb54
JM
438 if (flags & NL80211_FEATURE_STATIC_SMPS)
439 capa->smps_modes |= WPA_DRIVER_SMPS_MODE_STATIC;
440
441 if (flags & NL80211_FEATURE_DYNAMIC_SMPS)
442 capa->smps_modes |= WPA_DRIVER_SMPS_MODE_DYNAMIC;
dfa87878
MB
443
444 if (flags & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
445 info->wmm_ac_supported = 1;
58162adf
AK
446
447 if (flags & NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES)
448 capa->rrm_flags |= WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES;
449
450 if (flags & NL80211_FEATURE_WFA_TPC_IE_IN_PROBES)
451 capa->rrm_flags |= WPA_DRIVER_FLAGS_WFA_TPC_IE_IN_PROBES;
452
453 if (flags & NL80211_FEATURE_QUIET)
454 capa->rrm_flags |= WPA_DRIVER_FLAGS_QUIET;
455
456 if (flags & NL80211_FEATURE_TX_POWER_INSERTION)
457 capa->rrm_flags |= WPA_DRIVER_FLAGS_TX_POWER_INSERTION;
1830817e
JD
458
459 if (flags & NL80211_FEATURE_HT_IBSS)
460 capa->flags |= WPA_DRIVER_FLAGS_HT_IBSS;
dc55b6b6
AB
461
462 if (flags & NL80211_FEATURE_FULL_AP_CLIENT_STATE)
463 capa->flags |= WPA_DRIVER_FLAGS_FULL_AP_CLIENT_STATE;
0fafeb54
JM
464}
465
466
467static void wiphy_info_probe_resp_offload(struct wpa_driver_capa *capa,
468 struct nlattr *tb)
469{
470 u32 protocols;
471
472 if (tb == NULL)
473 return;
474
475 protocols = nla_get_u32(tb);
476 wpa_printf(MSG_DEBUG, "nl80211: Supports Probe Response offload in AP "
477 "mode");
478 capa->flags |= WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD;
479 capa->probe_resp_offloads = probe_resp_offload_support(protocols);
480}
481
482
483static void wiphy_info_wowlan_triggers(struct wpa_driver_capa *capa,
484 struct nlattr *tb)
485{
486 struct nlattr *triggers[MAX_NL80211_WOWLAN_TRIG + 1];
487
488 if (tb == NULL)
489 return;
490
491 if (nla_parse_nested(triggers, MAX_NL80211_WOWLAN_TRIG,
492 tb, NULL))
493 return;
494
495 if (triggers[NL80211_WOWLAN_TRIG_ANY])
496 capa->wowlan_triggers.any = 1;
497 if (triggers[NL80211_WOWLAN_TRIG_DISCONNECT])
498 capa->wowlan_triggers.disconnect = 1;
499 if (triggers[NL80211_WOWLAN_TRIG_MAGIC_PKT])
500 capa->wowlan_triggers.magic_pkt = 1;
501 if (triggers[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE])
502 capa->wowlan_triggers.gtk_rekey_failure = 1;
503 if (triggers[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST])
504 capa->wowlan_triggers.eap_identity_req = 1;
505 if (triggers[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE])
506 capa->wowlan_triggers.four_way_handshake = 1;
507 if (triggers[NL80211_WOWLAN_TRIG_RFKILL_RELEASE])
508 capa->wowlan_triggers.rfkill_release = 1;
509}
510
511
cc9a2575
KV
512static void wiphy_info_extended_capab(struct wpa_driver_nl80211_data *drv,
513 struct nlattr *tb)
514{
515 int rem = 0, i;
516 struct nlattr *tb1[NL80211_ATTR_MAX + 1], *attr;
517
518 if (!tb || drv->num_iface_ext_capa == NL80211_IFTYPE_MAX)
519 return;
520
521 nla_for_each_nested(attr, tb, rem) {
522 unsigned int len;
523 struct drv_nl80211_ext_capa *capa;
524
525 nla_parse(tb1, NL80211_ATTR_MAX, nla_data(attr),
526 nla_len(attr), NULL);
527
528 if (!tb1[NL80211_ATTR_IFTYPE] ||
529 !tb1[NL80211_ATTR_EXT_CAPA] ||
530 !tb1[NL80211_ATTR_EXT_CAPA_MASK])
531 continue;
532
533 capa = &drv->iface_ext_capa[drv->num_iface_ext_capa];
534 capa->iftype = nla_get_u32(tb1[NL80211_ATTR_IFTYPE]);
535 wpa_printf(MSG_DEBUG,
536 "nl80211: Driver-advertised extended capabilities for interface type %s",
537 nl80211_iftype_str(capa->iftype));
538
539 len = nla_len(tb1[NL80211_ATTR_EXT_CAPA]);
540 capa->ext_capa = os_malloc(len);
541 if (!capa->ext_capa)
542 goto err;
543
544 os_memcpy(capa->ext_capa, nla_data(tb1[NL80211_ATTR_EXT_CAPA]),
545 len);
546 capa->ext_capa_len = len;
547 wpa_hexdump(MSG_DEBUG, "nl80211: Extended capabilities",
548 capa->ext_capa, capa->ext_capa_len);
549
550 len = nla_len(tb1[NL80211_ATTR_EXT_CAPA_MASK]);
551 capa->ext_capa_mask = os_malloc(len);
552 if (!capa->ext_capa_mask)
553 goto err;
554
555 os_memcpy(capa->ext_capa_mask,
556 nla_data(tb1[NL80211_ATTR_EXT_CAPA_MASK]), len);
557 wpa_hexdump(MSG_DEBUG, "nl80211: Extended capabilities mask",
558 capa->ext_capa_mask, capa->ext_capa_len);
559
560 drv->num_iface_ext_capa++;
561 if (drv->num_iface_ext_capa == NL80211_IFTYPE_MAX)
562 break;
563 }
564
565 return;
566
567err:
568 /* Cleanup allocated memory on error */
569 for (i = 0; i < NL80211_IFTYPE_MAX; i++) {
570 os_free(drv->iface_ext_capa[i].ext_capa);
571 drv->iface_ext_capa[i].ext_capa = NULL;
572 os_free(drv->iface_ext_capa[i].ext_capa_mask);
573 drv->iface_ext_capa[i].ext_capa_mask = NULL;
574 drv->iface_ext_capa[i].ext_capa_len = 0;
575 }
576 drv->num_iface_ext_capa = 0;
577}
578
579
0fafeb54
JM
580static int wiphy_info_handler(struct nl_msg *msg, void *arg)
581{
582 struct nlattr *tb[NL80211_ATTR_MAX + 1];
583 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
584 struct wiphy_info_data *info = arg;
585 struct wpa_driver_capa *capa = info->capa;
586 struct wpa_driver_nl80211_data *drv = info->drv;
587
588 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
589 genlmsg_attrlen(gnlh, 0), NULL);
590
0e92fb8f
JB
591 if (tb[NL80211_ATTR_WIPHY])
592 drv->wiphy_idx = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
593
0fafeb54
JM
594 if (tb[NL80211_ATTR_WIPHY_NAME])
595 os_strlcpy(drv->phyname,
596 nla_get_string(tb[NL80211_ATTR_WIPHY_NAME]),
597 sizeof(drv->phyname));
598 if (tb[NL80211_ATTR_MAX_NUM_SCAN_SSIDS])
599 capa->max_scan_ssids =
600 nla_get_u8(tb[NL80211_ATTR_MAX_NUM_SCAN_SSIDS]);
601
602 if (tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS])
603 capa->max_sched_scan_ssids =
604 nla_get_u8(tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS]);
605
09ea4309
AS
606 if (tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS] &&
607 tb[NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL] &&
608 tb[NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS]) {
609 capa->max_sched_scan_plans =
610 nla_get_u32(tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS]);
611
612 capa->max_sched_scan_plan_interval =
613 nla_get_u32(tb[NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL]);
614
615 capa->max_sched_scan_plan_iterations =
616 nla_get_u32(tb[NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS]);
617 }
618
0fafeb54
JM
619 if (tb[NL80211_ATTR_MAX_MATCH_SETS])
620 capa->max_match_sets =
621 nla_get_u8(tb[NL80211_ATTR_MAX_MATCH_SETS]);
622
623 if (tb[NL80211_ATTR_MAC_ACL_MAX])
624 capa->max_acl_mac_addrs =
625 nla_get_u8(tb[NL80211_ATTR_MAC_ACL_MAX]);
626
627 wiphy_info_supported_iftypes(info, tb[NL80211_ATTR_SUPPORTED_IFTYPES]);
628 wiphy_info_iface_comb(info, tb[NL80211_ATTR_INTERFACE_COMBINATIONS]);
629 wiphy_info_supp_cmds(info, tb[NL80211_ATTR_SUPPORTED_COMMANDS]);
630 wiphy_info_cipher_suites(info, tb[NL80211_ATTR_CIPHER_SUITES]);
631
632 if (tb[NL80211_ATTR_OFFCHANNEL_TX_OK]) {
633 wpa_printf(MSG_DEBUG, "nl80211: Using driver-based "
634 "off-channel TX");
635 capa->flags |= WPA_DRIVER_FLAGS_OFFCHANNEL_TX;
636 }
637
638 if (tb[NL80211_ATTR_ROAM_SUPPORT]) {
639 wpa_printf(MSG_DEBUG, "nl80211: Using driver-based roaming");
640 capa->flags |= WPA_DRIVER_FLAGS_BSS_SELECTION;
641 }
642
643 wiphy_info_max_roc(capa,
644 tb[NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION]);
645
646 if (tb[NL80211_ATTR_SUPPORT_AP_UAPSD])
647 capa->flags |= WPA_DRIVER_FLAGS_AP_UAPSD;
648
649 wiphy_info_tdls(capa, tb[NL80211_ATTR_TDLS_SUPPORT],
650 tb[NL80211_ATTR_TDLS_EXTERNAL_SETUP]);
651
652 if (tb[NL80211_ATTR_DEVICE_AP_SME])
653 info->device_ap_sme = 1;
654
655 wiphy_info_feature_flags(info, tb[NL80211_ATTR_FEATURE_FLAGS]);
4acdc48a 656 wiphy_info_ext_feature_flags(info, tb[NL80211_ATTR_EXT_FEATURES]);
0fafeb54
JM
657 wiphy_info_probe_resp_offload(capa,
658 tb[NL80211_ATTR_PROBE_RESP_OFFLOAD]);
659
660 if (tb[NL80211_ATTR_EXT_CAPA] && tb[NL80211_ATTR_EXT_CAPA_MASK] &&
661 drv->extended_capa == NULL) {
662 drv->extended_capa =
663 os_malloc(nla_len(tb[NL80211_ATTR_EXT_CAPA]));
664 if (drv->extended_capa) {
665 os_memcpy(drv->extended_capa,
666 nla_data(tb[NL80211_ATTR_EXT_CAPA]),
667 nla_len(tb[NL80211_ATTR_EXT_CAPA]));
668 drv->extended_capa_len =
669 nla_len(tb[NL80211_ATTR_EXT_CAPA]);
cc9a2575
KV
670 wpa_hexdump(MSG_DEBUG,
671 "nl80211: Driver-advertised extended capabilities (default)",
672 drv->extended_capa, drv->extended_capa_len);
0fafeb54
JM
673 }
674 drv->extended_capa_mask =
7b7b4449 675 os_malloc(nla_len(tb[NL80211_ATTR_EXT_CAPA_MASK]));
0fafeb54
JM
676 if (drv->extended_capa_mask) {
677 os_memcpy(drv->extended_capa_mask,
7b7b4449
LC
678 nla_data(tb[NL80211_ATTR_EXT_CAPA_MASK]),
679 nla_len(tb[NL80211_ATTR_EXT_CAPA_MASK]));
cc9a2575
KV
680 wpa_hexdump(MSG_DEBUG,
681 "nl80211: Driver-advertised extended capabilities mask (default)",
682 drv->extended_capa_mask,
683 drv->extended_capa_len);
0fafeb54
JM
684 } else {
685 os_free(drv->extended_capa);
686 drv->extended_capa = NULL;
687 drv->extended_capa_len = 0;
688 }
689 }
690
cc9a2575
KV
691 wiphy_info_extended_capab(drv, tb[NL80211_ATTR_IFTYPE_EXT_CAPA]);
692
0fafeb54
JM
693 if (tb[NL80211_ATTR_VENDOR_DATA]) {
694 struct nlattr *nl;
695 int rem;
696
697 nla_for_each_nested(nl, tb[NL80211_ATTR_VENDOR_DATA], rem) {
698 struct nl80211_vendor_cmd_info *vinfo;
699 if (nla_len(nl) != sizeof(*vinfo)) {
700 wpa_printf(MSG_DEBUG, "nl80211: Unexpected vendor data info");
701 continue;
702 }
703 vinfo = nla_data(nl);
5f9c92f8
ZK
704 if (vinfo->vendor_id == OUI_QCA) {
705 switch (vinfo->subcmd) {
706 case QCA_NL80211_VENDOR_SUBCMD_TEST:
707 drv->vendor_cmd_test_avail = 1;
708 break;
b658547d 709#ifdef CONFIG_DRIVER_NL80211_QCA
5f9c92f8
ZK
710 case QCA_NL80211_VENDOR_SUBCMD_ROAMING:
711 drv->roaming_vendor_cmd_avail = 1;
712 break;
713 case QCA_NL80211_VENDOR_SUBCMD_DFS_CAPABILITY:
714 drv->dfs_vendor_cmd_avail = 1;
715 break;
716 case QCA_NL80211_VENDOR_SUBCMD_GET_FEATURES:
717 drv->get_features_vendor_cmd_avail = 1;
718 break;
98342208
AK
719 case QCA_NL80211_VENDOR_SUBCMD_GET_PREFERRED_FREQ_LIST:
720 drv->get_pref_freq_list = 1;
721 break;
7c813acf
AK
722 case QCA_NL80211_VENDOR_SUBCMD_SET_PROBABLE_OPER_CHANNEL:
723 drv->set_prob_oper_freq = 1;
724 break;
5f9c92f8
ZK
725 case QCA_NL80211_VENDOR_SUBCMD_DO_ACS:
726 drv->capa.flags |=
727 WPA_DRIVER_FLAGS_ACS_OFFLOAD;
728 break;
844dfeb8
SD
729 case QCA_NL80211_VENDOR_SUBCMD_SETBAND:
730 drv->setband_vendor_cmd_avail = 1;
731 break;
f22a080c
KV
732 case QCA_NL80211_VENDOR_SUBCMD_TRIGGER_SCAN:
733 drv->scan_vendor_cmd_avail = 1;
734 break;
cc9985d1 735 case QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION:
736 drv->set_wifi_conf_vendor_cmd_avail = 1;
737 break;
b658547d 738#endif /* CONFIG_DRIVER_NL80211_QCA */
5f9c92f8 739 }
0fafeb54
JM
740 }
741
742 wpa_printf(MSG_DEBUG, "nl80211: Supported vendor command: vendor_id=0x%x subcmd=%u",
743 vinfo->vendor_id, vinfo->subcmd);
744 }
745 }
746
747 if (tb[NL80211_ATTR_VENDOR_EVENTS]) {
748 struct nlattr *nl;
749 int rem;
750
751 nla_for_each_nested(nl, tb[NL80211_ATTR_VENDOR_EVENTS], rem) {
752 struct nl80211_vendor_cmd_info *vinfo;
753 if (nla_len(nl) != sizeof(*vinfo)) {
754 wpa_printf(MSG_DEBUG, "nl80211: Unexpected vendor data info");
755 continue;
756 }
757 vinfo = nla_data(nl);
0fafeb54
JM
758 wpa_printf(MSG_DEBUG, "nl80211: Supported vendor event: vendor_id=0x%x subcmd=%u",
759 vinfo->vendor_id, vinfo->subcmd);
760 }
761 }
762
763 wiphy_info_wowlan_triggers(capa,
764 tb[NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED]);
765
766 if (tb[NL80211_ATTR_MAX_AP_ASSOC_STA])
767 capa->max_stations =
768 nla_get_u32(tb[NL80211_ATTR_MAX_AP_ASSOC_STA]);
769
366179d2
AO
770 if (tb[NL80211_ATTR_MAX_CSA_COUNTERS])
771 capa->max_csa_counters =
772 nla_get_u8(tb[NL80211_ATTR_MAX_CSA_COUNTERS]);
773
0fafeb54
JM
774 return NL_SKIP;
775}
776
777
778static int wpa_driver_nl80211_get_info(struct wpa_driver_nl80211_data *drv,
779 struct wiphy_info_data *info)
780{
781 u32 feat;
782 struct nl_msg *msg;
9589a91e 783 int flags = 0;
0fafeb54
JM
784
785 os_memset(info, 0, sizeof(*info));
786 info->capa = &drv->capa;
787 info->drv = drv;
788
0fafeb54
JM
789 feat = get_nl80211_protocol_features(drv);
790 if (feat & NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)
9589a91e 791 flags = NLM_F_DUMP;
56f77852
JM
792 msg = nl80211_cmd_msg(drv->first_bss, flags, NL80211_CMD_GET_WIPHY);
793 if (!msg || nla_put_flag(msg, NL80211_ATTR_SPLIT_WIPHY_DUMP)) {
9589a91e
JM
794 nlmsg_free(msg);
795 return -1;
796 }
0fafeb54
JM
797
798 if (send_and_recv_msgs(drv, msg, wiphy_info_handler, info))
799 return -1;
800
801 if (info->auth_supported)
802 drv->capa.flags |= WPA_DRIVER_FLAGS_SME;
803 else if (!info->connect_supported) {
804 wpa_printf(MSG_INFO, "nl80211: Driver does not support "
805 "authentication/association or connect commands");
806 info->error = 1;
807 }
808
809 if (info->p2p_go_supported && info->p2p_client_supported)
810 drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CAPABLE;
811 if (info->p2p_concurrent) {
812 wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group "
813 "interface (driver advertised support)");
814 drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT;
815 drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P;
816 }
817 if (info->num_multichan_concurrent > 1) {
818 wpa_printf(MSG_DEBUG, "nl80211: Enable multi-channel "
819 "concurrent (driver advertised support)");
820 drv->capa.num_multichan_concurrent =
821 info->num_multichan_concurrent;
822 }
823 if (drv->capa.flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)
824 wpa_printf(MSG_DEBUG, "nl80211: use P2P_DEVICE support");
825
826 /* default to 5000 since early versions of mac80211 don't set it */
827 if (!drv->capa.max_remain_on_chan)
828 drv->capa.max_remain_on_chan = 5000;
829
dfa87878 830 drv->capa.wmm_ac_supported = info->wmm_ac_supported;
0fafeb54 831
86056fea
IP
832 drv->capa.mac_addr_rand_sched_scan_supported =
833 info->mac_addr_rand_sched_scan_supported;
834 drv->capa.mac_addr_rand_scan_supported =
835 info->mac_addr_rand_scan_supported;
836
366179d2
AO
837 if (info->channel_switch_supported) {
838 drv->capa.flags |= WPA_DRIVER_FLAGS_AP_CSA;
839 if (!drv->capa.max_csa_counters)
840 drv->capa.max_csa_counters = 1;
841 }
842
09ea4309
AS
843 if (!drv->capa.max_sched_scan_plans) {
844 drv->capa.max_sched_scan_plans = 1;
845 drv->capa.max_sched_scan_plan_interval = UINT32_MAX;
846 drv->capa.max_sched_scan_plan_iterations = 0;
847 }
848
0fafeb54 849 return 0;
0fafeb54
JM
850}
851
852
b658547d
JM
853#ifdef CONFIG_DRIVER_NL80211_QCA
854
0fafeb54
JM
855static int dfs_info_handler(struct nl_msg *msg, void *arg)
856{
857 struct nlattr *tb[NL80211_ATTR_MAX + 1];
858 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
859 int *dfs_capability_ptr = arg;
860
861 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
862 genlmsg_attrlen(gnlh, 0), NULL);
863
864 if (tb[NL80211_ATTR_VENDOR_DATA]) {
865 struct nlattr *nl_vend = tb[NL80211_ATTR_VENDOR_DATA];
866 struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1];
867
868 nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX,
869 nla_data(nl_vend), nla_len(nl_vend), NULL);
870
871 if (tb_vendor[QCA_WLAN_VENDOR_ATTR_DFS]) {
872 u32 val;
873 val = nla_get_u32(tb_vendor[QCA_WLAN_VENDOR_ATTR_DFS]);
874 wpa_printf(MSG_DEBUG, "nl80211: DFS offload capability: %u",
875 val);
876 *dfs_capability_ptr = val;
877 }
878 }
879
880 return NL_SKIP;
881}
882
883
884static void qca_nl80211_check_dfs_capa(struct wpa_driver_nl80211_data *drv)
885{
886 struct nl_msg *msg;
887 int dfs_capability = 0;
888 int ret;
889
890 if (!drv->dfs_vendor_cmd_avail)
891 return;
892
9725b784 893 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
9589a91e
JM
894 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
895 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
896 QCA_NL80211_VENDOR_SUBCMD_DFS_CAPABILITY)) {
897 nlmsg_free(msg);
898 return;
899 }
0fafeb54
JM
900
901 ret = send_and_recv_msgs(drv, msg, dfs_info_handler, &dfs_capability);
902 if (!ret && dfs_capability)
903 drv->capa.flags |= WPA_DRIVER_FLAGS_DFS_OFFLOAD;
0fafeb54
JM
904}
905
906
15badebd
CL
907struct features_info {
908 u8 *flags;
909 size_t flags_len;
079a28f7 910 struct wpa_driver_capa *capa;
15badebd
CL
911};
912
913
914static int features_info_handler(struct nl_msg *msg, void *arg)
915{
916 struct nlattr *tb[NL80211_ATTR_MAX + 1];
917 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
918 struct features_info *info = arg;
919 struct nlattr *nl_vend, *attr;
920
921 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
922 genlmsg_attrlen(gnlh, 0), NULL);
923
924 nl_vend = tb[NL80211_ATTR_VENDOR_DATA];
925 if (nl_vend) {
926 struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1];
927
928 nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX,
929 nla_data(nl_vend), nla_len(nl_vend), NULL);
930
931 attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_FEATURE_FLAGS];
932 if (attr) {
fdc1188a
PS
933 int len = nla_len(attr);
934 info->flags = os_malloc(len);
935 if (info->flags != NULL) {
936 os_memcpy(info->flags, nla_data(attr), len);
937 info->flags_len = len;
938 }
15badebd 939 }
079a28f7
AK
940 attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_CONCURRENCY_CAPA];
941 if (attr)
942 info->capa->conc_capab = nla_get_u32(attr);
943
944 attr = tb_vendor[
945 QCA_WLAN_VENDOR_ATTR_MAX_CONCURRENT_CHANNELS_2_4_BAND];
946 if (attr)
947 info->capa->max_conc_chan_2_4 = nla_get_u32(attr);
948
949 attr = tb_vendor[
950 QCA_WLAN_VENDOR_ATTR_MAX_CONCURRENT_CHANNELS_5_0_BAND];
951 if (attr)
952 info->capa->max_conc_chan_5_0 = nla_get_u32(attr);
15badebd
CL
953 }
954
955 return NL_SKIP;
956}
957
958
959static int check_feature(enum qca_wlan_vendor_features feature,
960 struct features_info *info)
961{
49e3eea8 962 size_t idx = feature / 8;
15badebd 963
49e3eea8
JM
964 return (idx < info->flags_len) &&
965 (info->flags[idx] & BIT(feature % 8));
15badebd
CL
966}
967
968
969static void qca_nl80211_get_features(struct wpa_driver_nl80211_data *drv)
970{
971 struct nl_msg *msg;
972 struct features_info info;
973 int ret;
974
975 if (!drv->get_features_vendor_cmd_avail)
976 return;
977
978 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
979 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
980 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
981 QCA_NL80211_VENDOR_SUBCMD_GET_FEATURES)) {
982 nlmsg_free(msg);
983 return;
984 }
985
986 os_memset(&info, 0, sizeof(info));
079a28f7 987 info.capa = &drv->capa;
15badebd
CL
988 ret = send_and_recv_msgs(drv, msg, features_info_handler, &info);
989 if (ret || !info.flags)
990 return;
991
992 if (check_feature(QCA_WLAN_VENDOR_FEATURE_KEY_MGMT_OFFLOAD, &info))
993 drv->capa.flags |= WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD;
3784c058
PX
994
995 if (check_feature(QCA_WLAN_VENDOR_FEATURE_SUPPORT_HW_MODE_ANY, &info))
996 drv->capa.flags |= WPA_DRIVER_FLAGS_SUPPORT_HW_MODE_ANY;
8e509745
KV
997
998 if (check_feature(QCA_WLAN_VENDOR_FEATURE_OFFCHANNEL_SIMULTANEOUS,
999 &info))
1000 drv->capa.flags |= WPA_DRIVER_FLAGS_OFFCHANNEL_SIMULTANEOUS;
a6f5b193
PX
1001 if (check_feature(QCA_WLAN_VENDOR_FEATURE_P2P_LISTEN_OFFLOAD, &info))
1002 drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD;
fdc1188a 1003 os_free(info.flags);
15badebd
CL
1004}
1005
b658547d
JM
1006#endif /* CONFIG_DRIVER_NL80211_QCA */
1007
15badebd 1008
0fafeb54
JM
1009int wpa_driver_nl80211_capa(struct wpa_driver_nl80211_data *drv)
1010{
1011 struct wiphy_info_data info;
1012 if (wpa_driver_nl80211_get_info(drv, &info))
1013 return -1;
1014
1015 if (info.error)
1016 return -1;
1017
1018 drv->has_capability = 1;
1019 drv->capa.key_mgmt = WPA_DRIVER_CAPA_KEY_MGMT_WPA |
1020 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
1021 WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
399e6135
JM
1022 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK |
1023 WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B |
1024 WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192;
0fafeb54
JM
1025 drv->capa.auth = WPA_DRIVER_AUTH_OPEN |
1026 WPA_DRIVER_AUTH_SHARED |
1027 WPA_DRIVER_AUTH_LEAP;
1028
1029 drv->capa.flags |= WPA_DRIVER_FLAGS_SANE_ERROR_CODES;
1030 drv->capa.flags |= WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE;
1031 drv->capa.flags |= WPA_DRIVER_FLAGS_EAPOL_TX_STATUS;
1032
1033 /*
1034 * As all cfg80211 drivers must support cases where the AP interface is
1035 * removed without the knowledge of wpa_supplicant/hostapd, e.g., in
1036 * case that the user space daemon has crashed, they must be able to
1037 * cleanup all stations and key entries in the AP tear down flow. Thus,
1038 * this flag can/should always be set for cfg80211 drivers.
1039 */
1040 drv->capa.flags |= WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT;
1041
1042 if (!info.device_ap_sme) {
1043 drv->capa.flags |= WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS;
1044
1045 /*
1046 * No AP SME is currently assumed to also indicate no AP MLME
1047 * in the driver/firmware.
1048 */
1049 drv->capa.flags |= WPA_DRIVER_FLAGS_AP_MLME;
1050 }
1051
1052 drv->device_ap_sme = info.device_ap_sme;
1053 drv->poll_command_supported = info.poll_command_supported;
1054 drv->data_tx_status = info.data_tx_status;
abb8d08b 1055 drv->p2p_go_ctwindow_supported = info.p2p_go_ctwindow_supported;
0fafeb54
JM
1056 if (info.set_qos_map_supported)
1057 drv->capa.flags |= WPA_DRIVER_FLAGS_QOS_MAPPING;
1058 drv->have_low_prio_scan = info.have_low_prio_scan;
1059
1060 /*
1061 * If poll command and tx status are supported, mac80211 is new enough
1062 * to have everything we need to not need monitor interfaces.
1063 */
660103ec
SD
1064 drv->use_monitor = !info.device_ap_sme &&
1065 (!info.poll_command_supported || !info.data_tx_status);
0fafeb54
JM
1066
1067 /*
1068 * If we aren't going to use monitor interfaces, but the
1069 * driver doesn't support data TX status, we won't get TX
1070 * status for EAPOL frames.
1071 */
1072 if (!drv->use_monitor && !info.data_tx_status)
1073 drv->capa.flags &= ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS;
1074
b658547d 1075#ifdef CONFIG_DRIVER_NL80211_QCA
0fafeb54 1076 qca_nl80211_check_dfs_capa(drv);
15badebd 1077 qca_nl80211_get_features(drv);
0fafeb54 1078
8e509745
KV
1079 /*
1080 * To enable offchannel simultaneous support in wpa_supplicant, the
1081 * underlying driver needs to support the same along with offchannel TX.
1082 * Offchannel TX support is needed since remain_on_channel and
1083 * action_tx use some common data structures and hence cannot be
1084 * scheduled simultaneously.
1085 */
1086 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX))
1087 drv->capa.flags &= ~WPA_DRIVER_FLAGS_OFFCHANNEL_SIMULTANEOUS;
b658547d 1088#endif /* CONFIG_DRIVER_NL80211_QCA */
8e509745 1089
0fafeb54
JM
1090 return 0;
1091}
1092
1093
1094struct phy_info_arg {
1095 u16 *num_modes;
1096 struct hostapd_hw_modes *modes;
1097 int last_mode, last_chan_idx;
747ba106 1098 int failed;
0fafeb54
JM
1099};
1100
1101static void phy_info_ht_capa(struct hostapd_hw_modes *mode, struct nlattr *capa,
1102 struct nlattr *ampdu_factor,
1103 struct nlattr *ampdu_density,
1104 struct nlattr *mcs_set)
1105{
1106 if (capa)
1107 mode->ht_capab = nla_get_u16(capa);
1108
1109 if (ampdu_factor)
1110 mode->a_mpdu_params |= nla_get_u8(ampdu_factor) & 0x03;
1111
1112 if (ampdu_density)
1113 mode->a_mpdu_params |= nla_get_u8(ampdu_density) << 2;
1114
1115 if (mcs_set && nla_len(mcs_set) >= 16) {
1116 u8 *mcs;
1117 mcs = nla_data(mcs_set);
1118 os_memcpy(mode->mcs_set, mcs, 16);
1119 }
1120}
1121
1122
1123static void phy_info_vht_capa(struct hostapd_hw_modes *mode,
1124 struct nlattr *capa,
1125 struct nlattr *mcs_set)
1126{
1127 if (capa)
1128 mode->vht_capab = nla_get_u32(capa);
1129
1130 if (mcs_set && nla_len(mcs_set) >= 8) {
1131 u8 *mcs;
1132 mcs = nla_data(mcs_set);
1133 os_memcpy(mode->vht_mcs_set, mcs, 8);
1134 }
1135}
1136
1137
1138static void phy_info_freq(struct hostapd_hw_modes *mode,
1139 struct hostapd_channel_data *chan,
1140 struct nlattr *tb_freq[])
1141{
1142 u8 channel;
1143 chan->freq = nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_FREQ]);
1144 chan->flag = 0;
1145 chan->dfs_cac_ms = 0;
1146 if (ieee80211_freq_to_chan(chan->freq, &channel) != NUM_HOSTAPD_MODES)
1147 chan->chan = channel;
1148
1149 if (tb_freq[NL80211_FREQUENCY_ATTR_DISABLED])
1150 chan->flag |= HOSTAPD_CHAN_DISABLED;
1151 if (tb_freq[NL80211_FREQUENCY_ATTR_NO_IR])
1152 chan->flag |= HOSTAPD_CHAN_NO_IR;
1153 if (tb_freq[NL80211_FREQUENCY_ATTR_RADAR])
1154 chan->flag |= HOSTAPD_CHAN_RADAR;
1155 if (tb_freq[NL80211_FREQUENCY_ATTR_INDOOR_ONLY])
1156 chan->flag |= HOSTAPD_CHAN_INDOOR_ONLY;
1157 if (tb_freq[NL80211_FREQUENCY_ATTR_GO_CONCURRENT])
1158 chan->flag |= HOSTAPD_CHAN_GO_CONCURRENT;
1159
1160 if (tb_freq[NL80211_FREQUENCY_ATTR_DFS_STATE]) {
1161 enum nl80211_dfs_state state =
1162 nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_DFS_STATE]);
1163
1164 switch (state) {
1165 case NL80211_DFS_USABLE:
1166 chan->flag |= HOSTAPD_CHAN_DFS_USABLE;
1167 break;
1168 case NL80211_DFS_AVAILABLE:
1169 chan->flag |= HOSTAPD_CHAN_DFS_AVAILABLE;
1170 break;
1171 case NL80211_DFS_UNAVAILABLE:
1172 chan->flag |= HOSTAPD_CHAN_DFS_UNAVAILABLE;
1173 break;
1174 }
1175 }
1176
1177 if (tb_freq[NL80211_FREQUENCY_ATTR_DFS_CAC_TIME]) {
1178 chan->dfs_cac_ms = nla_get_u32(
1179 tb_freq[NL80211_FREQUENCY_ATTR_DFS_CAC_TIME]);
1180 }
1181}
1182
1183
1184static int phy_info_freqs(struct phy_info_arg *phy_info,
1185 struct hostapd_hw_modes *mode, struct nlattr *tb)
1186{
1187 static struct nla_policy freq_policy[NL80211_FREQUENCY_ATTR_MAX + 1] = {
1188 [NL80211_FREQUENCY_ATTR_FREQ] = { .type = NLA_U32 },
1189 [NL80211_FREQUENCY_ATTR_DISABLED] = { .type = NLA_FLAG },
1190 [NL80211_FREQUENCY_ATTR_NO_IR] = { .type = NLA_FLAG },
1191 [NL80211_FREQUENCY_ATTR_RADAR] = { .type = NLA_FLAG },
1192 [NL80211_FREQUENCY_ATTR_MAX_TX_POWER] = { .type = NLA_U32 },
1193 [NL80211_FREQUENCY_ATTR_DFS_STATE] = { .type = NLA_U32 },
1194 };
1195 int new_channels = 0;
1196 struct hostapd_channel_data *channel;
1197 struct nlattr *tb_freq[NL80211_FREQUENCY_ATTR_MAX + 1];
1198 struct nlattr *nl_freq;
1199 int rem_freq, idx;
1200
1201 if (tb == NULL)
1202 return NL_OK;
1203
1204 nla_for_each_nested(nl_freq, tb, rem_freq) {
1205 nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX,
1206 nla_data(nl_freq), nla_len(nl_freq), freq_policy);
1207 if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ])
1208 continue;
1209 new_channels++;
1210 }
1211
1212 channel = os_realloc_array(mode->channels,
1213 mode->num_channels + new_channels,
1214 sizeof(struct hostapd_channel_data));
1215 if (!channel)
747ba106 1216 return NL_STOP;
0fafeb54
JM
1217
1218 mode->channels = channel;
1219 mode->num_channels += new_channels;
1220
1221 idx = phy_info->last_chan_idx;
1222
1223 nla_for_each_nested(nl_freq, tb, rem_freq) {
1224 nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX,
1225 nla_data(nl_freq), nla_len(nl_freq), freq_policy);
1226 if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ])
1227 continue;
1228 phy_info_freq(mode, &mode->channels[idx], tb_freq);
1229 idx++;
1230 }
1231 phy_info->last_chan_idx = idx;
1232
1233 return NL_OK;
1234}
1235
1236
1237static int phy_info_rates(struct hostapd_hw_modes *mode, struct nlattr *tb)
1238{
1239 static struct nla_policy rate_policy[NL80211_BITRATE_ATTR_MAX + 1] = {
1240 [NL80211_BITRATE_ATTR_RATE] = { .type = NLA_U32 },
1241 [NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE] =
1242 { .type = NLA_FLAG },
1243 };
1244 struct nlattr *tb_rate[NL80211_BITRATE_ATTR_MAX + 1];
1245 struct nlattr *nl_rate;
1246 int rem_rate, idx;
1247
1248 if (tb == NULL)
1249 return NL_OK;
1250
1251 nla_for_each_nested(nl_rate, tb, rem_rate) {
1252 nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX,
1253 nla_data(nl_rate), nla_len(nl_rate),
1254 rate_policy);
1255 if (!tb_rate[NL80211_BITRATE_ATTR_RATE])
1256 continue;
1257 mode->num_rates++;
1258 }
1259
1260 mode->rates = os_calloc(mode->num_rates, sizeof(int));
1261 if (!mode->rates)
747ba106 1262 return NL_STOP;
0fafeb54
JM
1263
1264 idx = 0;
1265
1266 nla_for_each_nested(nl_rate, tb, rem_rate) {
1267 nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX,
1268 nla_data(nl_rate), nla_len(nl_rate),
1269 rate_policy);
1270 if (!tb_rate[NL80211_BITRATE_ATTR_RATE])
1271 continue;
1272 mode->rates[idx] = nla_get_u32(
1273 tb_rate[NL80211_BITRATE_ATTR_RATE]);
1274 idx++;
1275 }
1276
1277 return NL_OK;
1278}
1279
1280
1281static int phy_info_band(struct phy_info_arg *phy_info, struct nlattr *nl_band)
1282{
1283 struct nlattr *tb_band[NL80211_BAND_ATTR_MAX + 1];
1284 struct hostapd_hw_modes *mode;
1285 int ret;
1286
1287 if (phy_info->last_mode != nl_band->nla_type) {
1288 mode = os_realloc_array(phy_info->modes,
1289 *phy_info->num_modes + 1,
1290 sizeof(*mode));
747ba106
JM
1291 if (!mode) {
1292 phy_info->failed = 1;
1293 return NL_STOP;
1294 }
0fafeb54
JM
1295 phy_info->modes = mode;
1296
1297 mode = &phy_info->modes[*(phy_info->num_modes)];
1298 os_memset(mode, 0, sizeof(*mode));
1299 mode->mode = NUM_HOSTAPD_MODES;
1300 mode->flags = HOSTAPD_MODE_FLAG_HT_INFO_KNOWN |
1301 HOSTAPD_MODE_FLAG_VHT_INFO_KNOWN;
1302
1303 /*
1304 * Unsupported VHT MCS stream is defined as value 3, so the VHT
1305 * MCS RX/TX map must be initialized with 0xffff to mark all 8
1306 * possible streams as unsupported. This will be overridden if
1307 * driver advertises VHT support.
1308 */
1309 mode->vht_mcs_set[0] = 0xff;
1310 mode->vht_mcs_set[1] = 0xff;
1311 mode->vht_mcs_set[4] = 0xff;
1312 mode->vht_mcs_set[5] = 0xff;
1313
1314 *(phy_info->num_modes) += 1;
1315 phy_info->last_mode = nl_band->nla_type;
1316 phy_info->last_chan_idx = 0;
1317 } else
1318 mode = &phy_info->modes[*(phy_info->num_modes) - 1];
1319
1320 nla_parse(tb_band, NL80211_BAND_ATTR_MAX, nla_data(nl_band),
1321 nla_len(nl_band), NULL);
1322
1323 phy_info_ht_capa(mode, tb_band[NL80211_BAND_ATTR_HT_CAPA],
1324 tb_band[NL80211_BAND_ATTR_HT_AMPDU_FACTOR],
1325 tb_band[NL80211_BAND_ATTR_HT_AMPDU_DENSITY],
1326 tb_band[NL80211_BAND_ATTR_HT_MCS_SET]);
1327 phy_info_vht_capa(mode, tb_band[NL80211_BAND_ATTR_VHT_CAPA],
1328 tb_band[NL80211_BAND_ATTR_VHT_MCS_SET]);
1329 ret = phy_info_freqs(phy_info, mode, tb_band[NL80211_BAND_ATTR_FREQS]);
747ba106
JM
1330 if (ret == NL_OK)
1331 ret = phy_info_rates(mode, tb_band[NL80211_BAND_ATTR_RATES]);
1332 if (ret != NL_OK) {
1333 phy_info->failed = 1;
0fafeb54 1334 return ret;
747ba106 1335 }
0fafeb54
JM
1336
1337 return NL_OK;
1338}
1339
1340
1341static int phy_info_handler(struct nl_msg *msg, void *arg)
1342{
1343 struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
1344 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1345 struct phy_info_arg *phy_info = arg;
1346 struct nlattr *nl_band;
1347 int rem_band;
1348
1349 nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1350 genlmsg_attrlen(gnlh, 0), NULL);
1351
1352 if (!tb_msg[NL80211_ATTR_WIPHY_BANDS])
1353 return NL_SKIP;
1354
1355 nla_for_each_nested(nl_band, tb_msg[NL80211_ATTR_WIPHY_BANDS], rem_band)
1356 {
1357 int res = phy_info_band(phy_info, nl_band);
1358 if (res != NL_OK)
1359 return res;
1360 }
1361
1362 return NL_SKIP;
1363}
1364
1365
1366static struct hostapd_hw_modes *
1367wpa_driver_nl80211_postprocess_modes(struct hostapd_hw_modes *modes,
1368 u16 *num_modes)
1369{
1370 u16 m;
1371 struct hostapd_hw_modes *mode11g = NULL, *nmodes, *mode;
1372 int i, mode11g_idx = -1;
1373
1374 /* heuristic to set up modes */
1375 for (m = 0; m < *num_modes; m++) {
1376 if (!modes[m].num_channels)
1377 continue;
1378 if (modes[m].channels[0].freq < 4000) {
1379 modes[m].mode = HOSTAPD_MODE_IEEE80211B;
1380 for (i = 0; i < modes[m].num_rates; i++) {
1381 if (modes[m].rates[i] > 200) {
1382 modes[m].mode = HOSTAPD_MODE_IEEE80211G;
1383 break;
1384 }
1385 }
1386 } else if (modes[m].channels[0].freq > 50000)
1387 modes[m].mode = HOSTAPD_MODE_IEEE80211AD;
1388 else
1389 modes[m].mode = HOSTAPD_MODE_IEEE80211A;
1390 }
1391
1392 /* If only 802.11g mode is included, use it to construct matching
1393 * 802.11b mode data. */
1394
1395 for (m = 0; m < *num_modes; m++) {
1396 if (modes[m].mode == HOSTAPD_MODE_IEEE80211B)
1397 return modes; /* 802.11b already included */
1398 if (modes[m].mode == HOSTAPD_MODE_IEEE80211G)
1399 mode11g_idx = m;
1400 }
1401
1402 if (mode11g_idx < 0)
1403 return modes; /* 2.4 GHz band not supported at all */
1404
1405 nmodes = os_realloc_array(modes, *num_modes + 1, sizeof(*nmodes));
1406 if (nmodes == NULL)
1407 return modes; /* Could not add 802.11b mode */
1408
1409 mode = &nmodes[*num_modes];
1410 os_memset(mode, 0, sizeof(*mode));
1411 (*num_modes)++;
1412 modes = nmodes;
1413
1414 mode->mode = HOSTAPD_MODE_IEEE80211B;
1415
1416 mode11g = &modes[mode11g_idx];
1417 mode->num_channels = mode11g->num_channels;
1418 mode->channels = os_malloc(mode11g->num_channels *
1419 sizeof(struct hostapd_channel_data));
1420 if (mode->channels == NULL) {
1421 (*num_modes)--;
1422 return modes; /* Could not add 802.11b mode */
1423 }
1424 os_memcpy(mode->channels, mode11g->channels,
1425 mode11g->num_channels * sizeof(struct hostapd_channel_data));
1426
1427 mode->num_rates = 0;
1428 mode->rates = os_malloc(4 * sizeof(int));
1429 if (mode->rates == NULL) {
1430 os_free(mode->channels);
1431 (*num_modes)--;
1432 return modes; /* Could not add 802.11b mode */
1433 }
1434
1435 for (i = 0; i < mode11g->num_rates; i++) {
1436 if (mode11g->rates[i] != 10 && mode11g->rates[i] != 20 &&
1437 mode11g->rates[i] != 55 && mode11g->rates[i] != 110)
1438 continue;
1439 mode->rates[mode->num_rates] = mode11g->rates[i];
1440 mode->num_rates++;
1441 if (mode->num_rates == 4)
1442 break;
1443 }
1444
1445 if (mode->num_rates == 0) {
1446 os_free(mode->channels);
1447 os_free(mode->rates);
1448 (*num_modes)--;
1449 return modes; /* No 802.11b rates */
1450 }
1451
1452 wpa_printf(MSG_DEBUG, "nl80211: Added 802.11b mode based on 802.11g "
1453 "information");
1454
1455 return modes;
1456}
1457
1458
1459static void nl80211_set_ht40_mode(struct hostapd_hw_modes *mode, int start,
1460 int end)
1461{
1462 int c;
1463
1464 for (c = 0; c < mode->num_channels; c++) {
1465 struct hostapd_channel_data *chan = &mode->channels[c];
1466 if (chan->freq - 10 >= start && chan->freq + 10 <= end)
1467 chan->flag |= HOSTAPD_CHAN_HT40;
1468 }
1469}
1470
1471
1472static void nl80211_set_ht40_mode_sec(struct hostapd_hw_modes *mode, int start,
1473 int end)
1474{
1475 int c;
1476
1477 for (c = 0; c < mode->num_channels; c++) {
1478 struct hostapd_channel_data *chan = &mode->channels[c];
1479 if (!(chan->flag & HOSTAPD_CHAN_HT40))
1480 continue;
1481 if (chan->freq - 30 >= start && chan->freq - 10 <= end)
1482 chan->flag |= HOSTAPD_CHAN_HT40MINUS;
1483 if (chan->freq + 10 >= start && chan->freq + 30 <= end)
1484 chan->flag |= HOSTAPD_CHAN_HT40PLUS;
1485 }
1486}
1487
1488
1489static void nl80211_reg_rule_max_eirp(u32 start, u32 end, u32 max_eirp,
1490 struct phy_info_arg *results)
1491{
1492 u16 m;
1493
1494 for (m = 0; m < *results->num_modes; m++) {
1495 int c;
1496 struct hostapd_hw_modes *mode = &results->modes[m];
1497
1498 for (c = 0; c < mode->num_channels; c++) {
1499 struct hostapd_channel_data *chan = &mode->channels[c];
1500 if ((u32) chan->freq - 10 >= start &&
1501 (u32) chan->freq + 10 <= end)
1502 chan->max_tx_power = max_eirp;
1503 }
1504 }
1505}
1506
1507
1508static void nl80211_reg_rule_ht40(u32 start, u32 end,
1509 struct phy_info_arg *results)
1510{
1511 u16 m;
1512
1513 for (m = 0; m < *results->num_modes; m++) {
1514 if (!(results->modes[m].ht_capab &
1515 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET))
1516 continue;
1517 nl80211_set_ht40_mode(&results->modes[m], start, end);
1518 }
1519}
1520
1521
1522static void nl80211_reg_rule_sec(struct nlattr *tb[],
1523 struct phy_info_arg *results)
1524{
1525 u32 start, end, max_bw;
1526 u16 m;
1527
1528 if (tb[NL80211_ATTR_FREQ_RANGE_START] == NULL ||
1529 tb[NL80211_ATTR_FREQ_RANGE_END] == NULL ||
1530 tb[NL80211_ATTR_FREQ_RANGE_MAX_BW] == NULL)
1531 return;
1532
1533 start = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]) / 1000;
1534 end = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]) / 1000;
1535 max_bw = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) / 1000;
1536
1537 if (max_bw < 20)
1538 return;
1539
1540 for (m = 0; m < *results->num_modes; m++) {
1541 if (!(results->modes[m].ht_capab &
1542 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET))
1543 continue;
1544 nl80211_set_ht40_mode_sec(&results->modes[m], start, end);
1545 }
1546}
1547
1548
1549static void nl80211_set_vht_mode(struct hostapd_hw_modes *mode, int start,
bee5d8e0 1550 int end, int max_bw)
0fafeb54
JM
1551{
1552 int c;
1553
1554 for (c = 0; c < mode->num_channels; c++) {
1555 struct hostapd_channel_data *chan = &mode->channels[c];
1556 if (chan->freq - 10 >= start && chan->freq + 70 <= end)
1557 chan->flag |= HOSTAPD_CHAN_VHT_10_70;
1558
1559 if (chan->freq - 30 >= start && chan->freq + 50 <= end)
1560 chan->flag |= HOSTAPD_CHAN_VHT_30_50;
1561
1562 if (chan->freq - 50 >= start && chan->freq + 30 <= end)
1563 chan->flag |= HOSTAPD_CHAN_VHT_50_30;
1564
1565 if (chan->freq - 70 >= start && chan->freq + 10 <= end)
1566 chan->flag |= HOSTAPD_CHAN_VHT_70_10;
bee5d8e0
AK
1567
1568 if (max_bw >= 160) {
1569 if (chan->freq - 10 >= start && chan->freq + 150 <= end)
1570 chan->flag |= HOSTAPD_CHAN_VHT_10_150;
1571
1572 if (chan->freq - 30 >= start && chan->freq + 130 <= end)
1573 chan->flag |= HOSTAPD_CHAN_VHT_30_130;
1574
1575 if (chan->freq - 50 >= start && chan->freq + 110 <= end)
1576 chan->flag |= HOSTAPD_CHAN_VHT_50_110;
1577
1578 if (chan->freq - 70 >= start && chan->freq + 90 <= end)
1579 chan->flag |= HOSTAPD_CHAN_VHT_70_90;
1580
1581 if (chan->freq - 90 >= start && chan->freq + 70 <= end)
1582 chan->flag |= HOSTAPD_CHAN_VHT_90_70;
1583
1584 if (chan->freq - 110 >= start && chan->freq + 50 <= end)
1585 chan->flag |= HOSTAPD_CHAN_VHT_110_50;
1586
1587 if (chan->freq - 130 >= start && chan->freq + 30 <= end)
1588 chan->flag |= HOSTAPD_CHAN_VHT_130_30;
1589
1590 if (chan->freq - 150 >= start && chan->freq + 10 <= end)
1591 chan->flag |= HOSTAPD_CHAN_VHT_150_10;
1592 }
0fafeb54
JM
1593 }
1594}
1595
1596
1597static void nl80211_reg_rule_vht(struct nlattr *tb[],
1598 struct phy_info_arg *results)
1599{
1600 u32 start, end, max_bw;
1601 u16 m;
1602
1603 if (tb[NL80211_ATTR_FREQ_RANGE_START] == NULL ||
1604 tb[NL80211_ATTR_FREQ_RANGE_END] == NULL ||
1605 tb[NL80211_ATTR_FREQ_RANGE_MAX_BW] == NULL)
1606 return;
1607
1608 start = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]) / 1000;
1609 end = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]) / 1000;
1610 max_bw = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) / 1000;
1611
1612 if (max_bw < 80)
1613 return;
1614
1615 for (m = 0; m < *results->num_modes; m++) {
1616 if (!(results->modes[m].ht_capab &
1617 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET))
1618 continue;
1619 /* TODO: use a real VHT support indication */
1620 if (!results->modes[m].vht_capab)
1621 continue;
1622
bee5d8e0 1623 nl80211_set_vht_mode(&results->modes[m], start, end, max_bw);
0fafeb54
JM
1624 }
1625}
1626
1627
1628static const char * dfs_domain_name(enum nl80211_dfs_regions region)
1629{
1630 switch (region) {
1631 case NL80211_DFS_UNSET:
1632 return "DFS-UNSET";
1633 case NL80211_DFS_FCC:
1634 return "DFS-FCC";
1635 case NL80211_DFS_ETSI:
1636 return "DFS-ETSI";
1637 case NL80211_DFS_JP:
1638 return "DFS-JP";
1639 default:
1640 return "DFS-invalid";
1641 }
1642}
1643
1644
1645static int nl80211_get_reg(struct nl_msg *msg, void *arg)
1646{
1647 struct phy_info_arg *results = arg;
1648 struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
1649 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1650 struct nlattr *nl_rule;
1651 struct nlattr *tb_rule[NL80211_FREQUENCY_ATTR_MAX + 1];
1652 int rem_rule;
1653 static struct nla_policy reg_policy[NL80211_FREQUENCY_ATTR_MAX + 1] = {
1654 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
1655 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
1656 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
1657 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
1658 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
1659 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
1660 };
1661
1662 nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1663 genlmsg_attrlen(gnlh, 0), NULL);
1664 if (!tb_msg[NL80211_ATTR_REG_ALPHA2] ||
1665 !tb_msg[NL80211_ATTR_REG_RULES]) {
1666 wpa_printf(MSG_DEBUG, "nl80211: No regulatory information "
1667 "available");
1668 return NL_SKIP;
1669 }
1670
1671 if (tb_msg[NL80211_ATTR_DFS_REGION]) {
1672 enum nl80211_dfs_regions dfs_domain;
1673 dfs_domain = nla_get_u8(tb_msg[NL80211_ATTR_DFS_REGION]);
1674 wpa_printf(MSG_DEBUG, "nl80211: Regulatory information - country=%s (%s)",
1675 (char *) nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]),
1676 dfs_domain_name(dfs_domain));
1677 } else {
1678 wpa_printf(MSG_DEBUG, "nl80211: Regulatory information - country=%s",
1679 (char *) nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]));
1680 }
1681
1682 nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule)
1683 {
1684 u32 start, end, max_eirp = 0, max_bw = 0, flags = 0;
1685 nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX,
1686 nla_data(nl_rule), nla_len(nl_rule), reg_policy);
1687 if (tb_rule[NL80211_ATTR_FREQ_RANGE_START] == NULL ||
1688 tb_rule[NL80211_ATTR_FREQ_RANGE_END] == NULL)
1689 continue;
1690 start = nla_get_u32(tb_rule[NL80211_ATTR_FREQ_RANGE_START]) / 1000;
1691 end = nla_get_u32(tb_rule[NL80211_ATTR_FREQ_RANGE_END]) / 1000;
1692 if (tb_rule[NL80211_ATTR_POWER_RULE_MAX_EIRP])
1693 max_eirp = nla_get_u32(tb_rule[NL80211_ATTR_POWER_RULE_MAX_EIRP]) / 100;
1694 if (tb_rule[NL80211_ATTR_FREQ_RANGE_MAX_BW])
1695 max_bw = nla_get_u32(tb_rule[NL80211_ATTR_FREQ_RANGE_MAX_BW]) / 1000;
1696 if (tb_rule[NL80211_ATTR_REG_RULE_FLAGS])
1697 flags = nla_get_u32(tb_rule[NL80211_ATTR_REG_RULE_FLAGS]);
1698
1699 wpa_printf(MSG_DEBUG, "nl80211: %u-%u @ %u MHz %u mBm%s%s%s%s%s%s%s%s",
1700 start, end, max_bw, max_eirp,
1701 flags & NL80211_RRF_NO_OFDM ? " (no OFDM)" : "",
1702 flags & NL80211_RRF_NO_CCK ? " (no CCK)" : "",
1703 flags & NL80211_RRF_NO_INDOOR ? " (no indoor)" : "",
1704 flags & NL80211_RRF_NO_OUTDOOR ? " (no outdoor)" :
1705 "",
1706 flags & NL80211_RRF_DFS ? " (DFS)" : "",
1707 flags & NL80211_RRF_PTP_ONLY ? " (PTP only)" : "",
1708 flags & NL80211_RRF_PTMP_ONLY ? " (PTMP only)" : "",
1709 flags & NL80211_RRF_NO_IR ? " (no IR)" : "");
1710 if (max_bw >= 40)
1711 nl80211_reg_rule_ht40(start, end, results);
1712 if (tb_rule[NL80211_ATTR_POWER_RULE_MAX_EIRP])
1713 nl80211_reg_rule_max_eirp(start, end, max_eirp,
1714 results);
1715 }
1716
1717 nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule)
1718 {
1719 nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX,
1720 nla_data(nl_rule), nla_len(nl_rule), reg_policy);
1721 nl80211_reg_rule_sec(tb_rule, results);
1722 }
1723
1724 nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule)
1725 {
1726 nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX,
1727 nla_data(nl_rule), nla_len(nl_rule), reg_policy);
1728 nl80211_reg_rule_vht(tb_rule, results);
1729 }
1730
1731 return NL_SKIP;
1732}
1733
1734
1735static int nl80211_set_regulatory_flags(struct wpa_driver_nl80211_data *drv,
1736 struct phy_info_arg *results)
1737{
1738 struct nl_msg *msg;
1739
1740 msg = nlmsg_alloc();
1741 if (!msg)
1742 return -ENOMEM;
1743
1744 nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG);
1745 return send_and_recv_msgs(drv, msg, nl80211_get_reg, results);
1746}
1747
1748
1749struct hostapd_hw_modes *
1750nl80211_get_hw_feature_data(void *priv, u16 *num_modes, u16 *flags)
1751{
1752 u32 feat;
1753 struct i802_bss *bss = priv;
1754 struct wpa_driver_nl80211_data *drv = bss->drv;
9589a91e 1755 int nl_flags = 0;
0fafeb54
JM
1756 struct nl_msg *msg;
1757 struct phy_info_arg result = {
1758 .num_modes = num_modes,
1759 .modes = NULL,
1760 .last_mode = -1,
747ba106 1761 .failed = 0,
0fafeb54
JM
1762 };
1763
1764 *num_modes = 0;
1765 *flags = 0;
1766
0fafeb54
JM
1767 feat = get_nl80211_protocol_features(drv);
1768 if (feat & NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)
9589a91e 1769 nl_flags = NLM_F_DUMP;
56f77852
JM
1770 if (!(msg = nl80211_cmd_msg(bss, nl_flags, NL80211_CMD_GET_WIPHY)) ||
1771 nla_put_flag(msg, NL80211_ATTR_SPLIT_WIPHY_DUMP)) {
9589a91e
JM
1772 nlmsg_free(msg);
1773 return NULL;
1774 }
0fafeb54
JM
1775
1776 if (send_and_recv_msgs(drv, msg, phy_info_handler, &result) == 0) {
1777 nl80211_set_regulatory_flags(drv, &result);
747ba106
JM
1778 if (result.failed) {
1779 int i;
1780
1781 for (i = 0; result.modes && i < *num_modes; i++) {
1782 os_free(result.modes[i].channels);
1783 os_free(result.modes[i].rates);
1784 }
1785 os_free(result.modes);
517b5f92 1786 *num_modes = 0;
747ba106
JM
1787 return NULL;
1788 }
0fafeb54
JM
1789 return wpa_driver_nl80211_postprocess_modes(result.modes,
1790 num_modes);
1791 }
9589a91e 1792
0fafeb54
JM
1793 return NULL;
1794}