]> git.ipfire.org Git - thirdparty/hostap.git/blame - src/drivers/driver_nl80211_capa.c
tests: Verify DFS channel switch both in and outside ETSI
[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"
0fafeb54 15#include "common/ieee802_11_common.h"
a042e39a 16#include "common/wpa_common.h"
0fafeb54
JM
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) {
a042e39a 269 case RSN_CIPHER_SUITE_CCMP_256:
0fafeb54
JM
270 info->capa->enc |= WPA_DRIVER_CAPA_ENC_CCMP_256;
271 break;
a042e39a 272 case RSN_CIPHER_SUITE_GCMP_256:
0fafeb54
JM
273 info->capa->enc |= WPA_DRIVER_CAPA_ENC_GCMP_256;
274 break;
a042e39a 275 case RSN_CIPHER_SUITE_CCMP:
0fafeb54
JM
276 info->capa->enc |= WPA_DRIVER_CAPA_ENC_CCMP;
277 break;
a042e39a 278 case RSN_CIPHER_SUITE_GCMP:
0fafeb54
JM
279 info->capa->enc |= WPA_DRIVER_CAPA_ENC_GCMP;
280 break;
a042e39a 281 case RSN_CIPHER_SUITE_TKIP:
0fafeb54
JM
282 info->capa->enc |= WPA_DRIVER_CAPA_ENC_TKIP;
283 break;
a042e39a 284 case RSN_CIPHER_SUITE_WEP104:
0fafeb54
JM
285 info->capa->enc |= WPA_DRIVER_CAPA_ENC_WEP104;
286 break;
a042e39a 287 case RSN_CIPHER_SUITE_WEP40:
0fafeb54
JM
288 info->capa->enc |= WPA_DRIVER_CAPA_ENC_WEP40;
289 break;
a042e39a 290 case RSN_CIPHER_SUITE_AES_128_CMAC:
0fafeb54
JM
291 info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP;
292 break;
a042e39a 293 case RSN_CIPHER_SUITE_BIP_GMAC_128:
0fafeb54
JM
294 info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP_GMAC_128;
295 break;
a042e39a 296 case RSN_CIPHER_SUITE_BIP_GMAC_256:
0fafeb54
JM
297 info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP_GMAC_256;
298 break;
a042e39a 299 case RSN_CIPHER_SUITE_BIP_CMAC_256:
0fafeb54
JM
300 info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP_CMAC_256;
301 break;
a042e39a 302 case RSN_CIPHER_SUITE_NO_GROUP_ADDRESSED:
0fafeb54
JM
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;
8331c9b3
VK
392 if (ext_feature_isset(ext_features, len,
393 NL80211_EXT_FEATURE_MGMT_TX_RANDOM_TA))
394 capa->flags |= WPA_DRIVER_FLAGS_MGMT_TX_RANDOM_TA;
395 if (ext_feature_isset(ext_features, len,
396 NL80211_EXT_FEATURE_MGMT_TX_RANDOM_TA_CONNECTED))
397 capa->flags |= WPA_DRIVER_FLAGS_MGMT_TX_RANDOM_TA_CONNECTED;
20c846d9 398 if (ext_feature_isset(ext_features, len,
399 NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI))
400 capa->flags |= WPA_DRIVER_FLAGS_SCHED_SCAN_RELATIVE_RSSI;
ad295f3b
VK
401 if (ext_feature_isset(ext_features, len,
402 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD))
403 capa->flags |= WPA_DRIVER_FLAGS_FILS_SK_OFFLOAD;
4acdc48a
JD
404}
405
406
0fafeb54
JM
407static void wiphy_info_feature_flags(struct wiphy_info_data *info,
408 struct nlattr *tb)
409{
410 u32 flags;
411 struct wpa_driver_capa *capa = info->capa;
412
413 if (tb == NULL)
414 return;
415
416 flags = nla_get_u32(tb);
417
418 if (flags & NL80211_FEATURE_SK_TX_STATUS)
419 info->data_tx_status = 1;
420
421 if (flags & NL80211_FEATURE_INACTIVITY_TIMER)
422 capa->flags |= WPA_DRIVER_FLAGS_INACTIVITY_TIMER;
423
424 if (flags & NL80211_FEATURE_SAE)
425 capa->flags |= WPA_DRIVER_FLAGS_SAE;
426
427 if (flags & NL80211_FEATURE_NEED_OBSS_SCAN)
428 capa->flags |= WPA_DRIVER_FLAGS_OBSS_SCAN;
429
430 if (flags & NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)
431 capa->flags |= WPA_DRIVER_FLAGS_HT_2040_COEX;
432
4daa5729
AN
433 if (flags & NL80211_FEATURE_TDLS_CHANNEL_SWITCH) {
434 wpa_printf(MSG_DEBUG, "nl80211: TDLS channel switch");
435 capa->flags |= WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH;
436 }
437
abb8d08b
EP
438 if (flags & NL80211_FEATURE_P2P_GO_CTWIN)
439 info->p2p_go_ctwindow_supported = 1;
440
0fafeb54
JM
441 if (flags & NL80211_FEATURE_LOW_PRIORITY_SCAN)
442 info->have_low_prio_scan = 1;
443
86056fea
IP
444 if (flags & NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)
445 info->mac_addr_rand_scan_supported = 1;
446
447 if (flags & NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR)
448 info->mac_addr_rand_sched_scan_supported = 1;
449
0fafeb54
JM
450 if (flags & NL80211_FEATURE_STATIC_SMPS)
451 capa->smps_modes |= WPA_DRIVER_SMPS_MODE_STATIC;
452
453 if (flags & NL80211_FEATURE_DYNAMIC_SMPS)
454 capa->smps_modes |= WPA_DRIVER_SMPS_MODE_DYNAMIC;
dfa87878
MB
455
456 if (flags & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
457 info->wmm_ac_supported = 1;
58162adf
AK
458
459 if (flags & NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES)
460 capa->rrm_flags |= WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES;
461
462 if (flags & NL80211_FEATURE_WFA_TPC_IE_IN_PROBES)
463 capa->rrm_flags |= WPA_DRIVER_FLAGS_WFA_TPC_IE_IN_PROBES;
464
465 if (flags & NL80211_FEATURE_QUIET)
466 capa->rrm_flags |= WPA_DRIVER_FLAGS_QUIET;
467
468 if (flags & NL80211_FEATURE_TX_POWER_INSERTION)
469 capa->rrm_flags |= WPA_DRIVER_FLAGS_TX_POWER_INSERTION;
1830817e
JD
470
471 if (flags & NL80211_FEATURE_HT_IBSS)
472 capa->flags |= WPA_DRIVER_FLAGS_HT_IBSS;
dc55b6b6
AB
473
474 if (flags & NL80211_FEATURE_FULL_AP_CLIENT_STATE)
475 capa->flags |= WPA_DRIVER_FLAGS_FULL_AP_CLIENT_STATE;
0fafeb54
JM
476}
477
478
479static void wiphy_info_probe_resp_offload(struct wpa_driver_capa *capa,
480 struct nlattr *tb)
481{
482 u32 protocols;
483
484 if (tb == NULL)
485 return;
486
487 protocols = nla_get_u32(tb);
488 wpa_printf(MSG_DEBUG, "nl80211: Supports Probe Response offload in AP "
489 "mode");
490 capa->flags |= WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD;
491 capa->probe_resp_offloads = probe_resp_offload_support(protocols);
492}
493
494
495static void wiphy_info_wowlan_triggers(struct wpa_driver_capa *capa,
496 struct nlattr *tb)
497{
498 struct nlattr *triggers[MAX_NL80211_WOWLAN_TRIG + 1];
499
500 if (tb == NULL)
501 return;
502
503 if (nla_parse_nested(triggers, MAX_NL80211_WOWLAN_TRIG,
504 tb, NULL))
505 return;
506
507 if (triggers[NL80211_WOWLAN_TRIG_ANY])
508 capa->wowlan_triggers.any = 1;
509 if (triggers[NL80211_WOWLAN_TRIG_DISCONNECT])
510 capa->wowlan_triggers.disconnect = 1;
511 if (triggers[NL80211_WOWLAN_TRIG_MAGIC_PKT])
512 capa->wowlan_triggers.magic_pkt = 1;
513 if (triggers[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE])
514 capa->wowlan_triggers.gtk_rekey_failure = 1;
515 if (triggers[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST])
516 capa->wowlan_triggers.eap_identity_req = 1;
517 if (triggers[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE])
518 capa->wowlan_triggers.four_way_handshake = 1;
519 if (triggers[NL80211_WOWLAN_TRIG_RFKILL_RELEASE])
520 capa->wowlan_triggers.rfkill_release = 1;
521}
522
523
cc9a2575
KV
524static void wiphy_info_extended_capab(struct wpa_driver_nl80211_data *drv,
525 struct nlattr *tb)
526{
527 int rem = 0, i;
528 struct nlattr *tb1[NL80211_ATTR_MAX + 1], *attr;
529
530 if (!tb || drv->num_iface_ext_capa == NL80211_IFTYPE_MAX)
531 return;
532
533 nla_for_each_nested(attr, tb, rem) {
534 unsigned int len;
535 struct drv_nl80211_ext_capa *capa;
536
537 nla_parse(tb1, NL80211_ATTR_MAX, nla_data(attr),
538 nla_len(attr), NULL);
539
540 if (!tb1[NL80211_ATTR_IFTYPE] ||
541 !tb1[NL80211_ATTR_EXT_CAPA] ||
542 !tb1[NL80211_ATTR_EXT_CAPA_MASK])
543 continue;
544
545 capa = &drv->iface_ext_capa[drv->num_iface_ext_capa];
546 capa->iftype = nla_get_u32(tb1[NL80211_ATTR_IFTYPE]);
547 wpa_printf(MSG_DEBUG,
548 "nl80211: Driver-advertised extended capabilities for interface type %s",
549 nl80211_iftype_str(capa->iftype));
550
551 len = nla_len(tb1[NL80211_ATTR_EXT_CAPA]);
a1f11e34
JB
552 capa->ext_capa = os_memdup(nla_data(tb1[NL80211_ATTR_EXT_CAPA]),
553 len);
cc9a2575
KV
554 if (!capa->ext_capa)
555 goto err;
556
cc9a2575
KV
557 capa->ext_capa_len = len;
558 wpa_hexdump(MSG_DEBUG, "nl80211: Extended capabilities",
559 capa->ext_capa, capa->ext_capa_len);
560
561 len = nla_len(tb1[NL80211_ATTR_EXT_CAPA_MASK]);
a1f11e34
JB
562 capa->ext_capa_mask =
563 os_memdup(nla_data(tb1[NL80211_ATTR_EXT_CAPA_MASK]),
564 len);
cc9a2575
KV
565 if (!capa->ext_capa_mask)
566 goto err;
567
cc9a2575
KV
568 wpa_hexdump(MSG_DEBUG, "nl80211: Extended capabilities mask",
569 capa->ext_capa_mask, capa->ext_capa_len);
570
571 drv->num_iface_ext_capa++;
572 if (drv->num_iface_ext_capa == NL80211_IFTYPE_MAX)
573 break;
574 }
575
576 return;
577
578err:
579 /* Cleanup allocated memory on error */
580 for (i = 0; i < NL80211_IFTYPE_MAX; i++) {
581 os_free(drv->iface_ext_capa[i].ext_capa);
582 drv->iface_ext_capa[i].ext_capa = NULL;
583 os_free(drv->iface_ext_capa[i].ext_capa_mask);
584 drv->iface_ext_capa[i].ext_capa_mask = NULL;
585 drv->iface_ext_capa[i].ext_capa_len = 0;
586 }
587 drv->num_iface_ext_capa = 0;
588}
589
590
0fafeb54
JM
591static int wiphy_info_handler(struct nl_msg *msg, void *arg)
592{
593 struct nlattr *tb[NL80211_ATTR_MAX + 1];
594 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
595 struct wiphy_info_data *info = arg;
596 struct wpa_driver_capa *capa = info->capa;
597 struct wpa_driver_nl80211_data *drv = info->drv;
598
599 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
600 genlmsg_attrlen(gnlh, 0), NULL);
601
0e92fb8f
JB
602 if (tb[NL80211_ATTR_WIPHY])
603 drv->wiphy_idx = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
604
0fafeb54
JM
605 if (tb[NL80211_ATTR_WIPHY_NAME])
606 os_strlcpy(drv->phyname,
607 nla_get_string(tb[NL80211_ATTR_WIPHY_NAME]),
608 sizeof(drv->phyname));
609 if (tb[NL80211_ATTR_MAX_NUM_SCAN_SSIDS])
610 capa->max_scan_ssids =
611 nla_get_u8(tb[NL80211_ATTR_MAX_NUM_SCAN_SSIDS]);
612
613 if (tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS])
614 capa->max_sched_scan_ssids =
615 nla_get_u8(tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS]);
616
09ea4309
AS
617 if (tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS] &&
618 tb[NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL] &&
619 tb[NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS]) {
620 capa->max_sched_scan_plans =
621 nla_get_u32(tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS]);
622
623 capa->max_sched_scan_plan_interval =
624 nla_get_u32(tb[NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL]);
625
626 capa->max_sched_scan_plan_iterations =
627 nla_get_u32(tb[NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS]);
628 }
629
0fafeb54
JM
630 if (tb[NL80211_ATTR_MAX_MATCH_SETS])
631 capa->max_match_sets =
632 nla_get_u8(tb[NL80211_ATTR_MAX_MATCH_SETS]);
633
634 if (tb[NL80211_ATTR_MAC_ACL_MAX])
635 capa->max_acl_mac_addrs =
636 nla_get_u8(tb[NL80211_ATTR_MAC_ACL_MAX]);
637
638 wiphy_info_supported_iftypes(info, tb[NL80211_ATTR_SUPPORTED_IFTYPES]);
639 wiphy_info_iface_comb(info, tb[NL80211_ATTR_INTERFACE_COMBINATIONS]);
640 wiphy_info_supp_cmds(info, tb[NL80211_ATTR_SUPPORTED_COMMANDS]);
641 wiphy_info_cipher_suites(info, tb[NL80211_ATTR_CIPHER_SUITES]);
642
643 if (tb[NL80211_ATTR_OFFCHANNEL_TX_OK]) {
644 wpa_printf(MSG_DEBUG, "nl80211: Using driver-based "
645 "off-channel TX");
646 capa->flags |= WPA_DRIVER_FLAGS_OFFCHANNEL_TX;
647 }
648
649 if (tb[NL80211_ATTR_ROAM_SUPPORT]) {
650 wpa_printf(MSG_DEBUG, "nl80211: Using driver-based roaming");
651 capa->flags |= WPA_DRIVER_FLAGS_BSS_SELECTION;
652 }
653
654 wiphy_info_max_roc(capa,
655 tb[NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION]);
656
657 if (tb[NL80211_ATTR_SUPPORT_AP_UAPSD])
658 capa->flags |= WPA_DRIVER_FLAGS_AP_UAPSD;
659
660 wiphy_info_tdls(capa, tb[NL80211_ATTR_TDLS_SUPPORT],
661 tb[NL80211_ATTR_TDLS_EXTERNAL_SETUP]);
662
663 if (tb[NL80211_ATTR_DEVICE_AP_SME])
664 info->device_ap_sme = 1;
665
666 wiphy_info_feature_flags(info, tb[NL80211_ATTR_FEATURE_FLAGS]);
4acdc48a 667 wiphy_info_ext_feature_flags(info, tb[NL80211_ATTR_EXT_FEATURES]);
0fafeb54
JM
668 wiphy_info_probe_resp_offload(capa,
669 tb[NL80211_ATTR_PROBE_RESP_OFFLOAD]);
670
671 if (tb[NL80211_ATTR_EXT_CAPA] && tb[NL80211_ATTR_EXT_CAPA_MASK] &&
672 drv->extended_capa == NULL) {
673 drv->extended_capa =
674 os_malloc(nla_len(tb[NL80211_ATTR_EXT_CAPA]));
675 if (drv->extended_capa) {
676 os_memcpy(drv->extended_capa,
677 nla_data(tb[NL80211_ATTR_EXT_CAPA]),
678 nla_len(tb[NL80211_ATTR_EXT_CAPA]));
679 drv->extended_capa_len =
680 nla_len(tb[NL80211_ATTR_EXT_CAPA]);
cc9a2575
KV
681 wpa_hexdump(MSG_DEBUG,
682 "nl80211: Driver-advertised extended capabilities (default)",
683 drv->extended_capa, drv->extended_capa_len);
0fafeb54
JM
684 }
685 drv->extended_capa_mask =
7b7b4449 686 os_malloc(nla_len(tb[NL80211_ATTR_EXT_CAPA_MASK]));
0fafeb54
JM
687 if (drv->extended_capa_mask) {
688 os_memcpy(drv->extended_capa_mask,
7b7b4449
LC
689 nla_data(tb[NL80211_ATTR_EXT_CAPA_MASK]),
690 nla_len(tb[NL80211_ATTR_EXT_CAPA_MASK]));
cc9a2575
KV
691 wpa_hexdump(MSG_DEBUG,
692 "nl80211: Driver-advertised extended capabilities mask (default)",
693 drv->extended_capa_mask,
694 drv->extended_capa_len);
0fafeb54
JM
695 } else {
696 os_free(drv->extended_capa);
697 drv->extended_capa = NULL;
698 drv->extended_capa_len = 0;
699 }
700 }
701
cc9a2575
KV
702 wiphy_info_extended_capab(drv, tb[NL80211_ATTR_IFTYPE_EXT_CAPA]);
703
0fafeb54
JM
704 if (tb[NL80211_ATTR_VENDOR_DATA]) {
705 struct nlattr *nl;
706 int rem;
707
708 nla_for_each_nested(nl, tb[NL80211_ATTR_VENDOR_DATA], rem) {
709 struct nl80211_vendor_cmd_info *vinfo;
710 if (nla_len(nl) != sizeof(*vinfo)) {
711 wpa_printf(MSG_DEBUG, "nl80211: Unexpected vendor data info");
712 continue;
713 }
714 vinfo = nla_data(nl);
5f9c92f8
ZK
715 if (vinfo->vendor_id == OUI_QCA) {
716 switch (vinfo->subcmd) {
717 case QCA_NL80211_VENDOR_SUBCMD_TEST:
718 drv->vendor_cmd_test_avail = 1;
719 break;
b658547d 720#ifdef CONFIG_DRIVER_NL80211_QCA
5f9c92f8
ZK
721 case QCA_NL80211_VENDOR_SUBCMD_ROAMING:
722 drv->roaming_vendor_cmd_avail = 1;
723 break;
724 case QCA_NL80211_VENDOR_SUBCMD_DFS_CAPABILITY:
725 drv->dfs_vendor_cmd_avail = 1;
726 break;
727 case QCA_NL80211_VENDOR_SUBCMD_GET_FEATURES:
728 drv->get_features_vendor_cmd_avail = 1;
729 break;
98342208
AK
730 case QCA_NL80211_VENDOR_SUBCMD_GET_PREFERRED_FREQ_LIST:
731 drv->get_pref_freq_list = 1;
732 break;
7c813acf
AK
733 case QCA_NL80211_VENDOR_SUBCMD_SET_PROBABLE_OPER_CHANNEL:
734 drv->set_prob_oper_freq = 1;
735 break;
5f9c92f8
ZK
736 case QCA_NL80211_VENDOR_SUBCMD_DO_ACS:
737 drv->capa.flags |=
738 WPA_DRIVER_FLAGS_ACS_OFFLOAD;
739 break;
844dfeb8
SD
740 case QCA_NL80211_VENDOR_SUBCMD_SETBAND:
741 drv->setband_vendor_cmd_avail = 1;
742 break;
f22a080c
KV
743 case QCA_NL80211_VENDOR_SUBCMD_TRIGGER_SCAN:
744 drv->scan_vendor_cmd_avail = 1;
745 break;
cc9985d1 746 case QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION:
747 drv->set_wifi_conf_vendor_cmd_avail = 1;
748 break;
ca1ab9db
PX
749 case QCA_NL80211_VENDOR_SUBCMD_GET_HE_CAPABILITIES:
750 drv->he_capab_vendor_cmd_avail = 1;
751 break;
3ab48492
KV
752 case QCA_NL80211_VENDOR_SUBCMD_FETCH_BSS_TRANSITION_STATUS:
753 drv->fetch_bss_trans_status = 1;
754 break;
b658547d 755#endif /* CONFIG_DRIVER_NL80211_QCA */
5f9c92f8 756 }
0fafeb54
JM
757 }
758
759 wpa_printf(MSG_DEBUG, "nl80211: Supported vendor command: vendor_id=0x%x subcmd=%u",
760 vinfo->vendor_id, vinfo->subcmd);
761 }
762 }
763
764 if (tb[NL80211_ATTR_VENDOR_EVENTS]) {
765 struct nlattr *nl;
766 int rem;
767
768 nla_for_each_nested(nl, tb[NL80211_ATTR_VENDOR_EVENTS], rem) {
769 struct nl80211_vendor_cmd_info *vinfo;
770 if (nla_len(nl) != sizeof(*vinfo)) {
771 wpa_printf(MSG_DEBUG, "nl80211: Unexpected vendor data info");
772 continue;
773 }
774 vinfo = nla_data(nl);
0fafeb54
JM
775 wpa_printf(MSG_DEBUG, "nl80211: Supported vendor event: vendor_id=0x%x subcmd=%u",
776 vinfo->vendor_id, vinfo->subcmd);
777 }
778 }
779
780 wiphy_info_wowlan_triggers(capa,
781 tb[NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED]);
782
783 if (tb[NL80211_ATTR_MAX_AP_ASSOC_STA])
784 capa->max_stations =
785 nla_get_u32(tb[NL80211_ATTR_MAX_AP_ASSOC_STA]);
786
366179d2
AO
787 if (tb[NL80211_ATTR_MAX_CSA_COUNTERS])
788 capa->max_csa_counters =
789 nla_get_u8(tb[NL80211_ATTR_MAX_CSA_COUNTERS]);
790
0fafeb54
JM
791 return NL_SKIP;
792}
793
794
795static int wpa_driver_nl80211_get_info(struct wpa_driver_nl80211_data *drv,
796 struct wiphy_info_data *info)
797{
798 u32 feat;
799 struct nl_msg *msg;
9589a91e 800 int flags = 0;
0fafeb54
JM
801
802 os_memset(info, 0, sizeof(*info));
803 info->capa = &drv->capa;
804 info->drv = drv;
805
0fafeb54
JM
806 feat = get_nl80211_protocol_features(drv);
807 if (feat & NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)
9589a91e 808 flags = NLM_F_DUMP;
56f77852
JM
809 msg = nl80211_cmd_msg(drv->first_bss, flags, NL80211_CMD_GET_WIPHY);
810 if (!msg || nla_put_flag(msg, NL80211_ATTR_SPLIT_WIPHY_DUMP)) {
9589a91e
JM
811 nlmsg_free(msg);
812 return -1;
813 }
0fafeb54
JM
814
815 if (send_and_recv_msgs(drv, msg, wiphy_info_handler, info))
816 return -1;
817
818 if (info->auth_supported)
819 drv->capa.flags |= WPA_DRIVER_FLAGS_SME;
820 else if (!info->connect_supported) {
821 wpa_printf(MSG_INFO, "nl80211: Driver does not support "
822 "authentication/association or connect commands");
823 info->error = 1;
824 }
825
826 if (info->p2p_go_supported && info->p2p_client_supported)
827 drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CAPABLE;
828 if (info->p2p_concurrent) {
829 wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group "
830 "interface (driver advertised support)");
831 drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT;
832 drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P;
833 }
834 if (info->num_multichan_concurrent > 1) {
835 wpa_printf(MSG_DEBUG, "nl80211: Enable multi-channel "
836 "concurrent (driver advertised support)");
837 drv->capa.num_multichan_concurrent =
838 info->num_multichan_concurrent;
839 }
840 if (drv->capa.flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)
841 wpa_printf(MSG_DEBUG, "nl80211: use P2P_DEVICE support");
842
843 /* default to 5000 since early versions of mac80211 don't set it */
844 if (!drv->capa.max_remain_on_chan)
845 drv->capa.max_remain_on_chan = 5000;
846
dfa87878 847 drv->capa.wmm_ac_supported = info->wmm_ac_supported;
0fafeb54 848
86056fea
IP
849 drv->capa.mac_addr_rand_sched_scan_supported =
850 info->mac_addr_rand_sched_scan_supported;
851 drv->capa.mac_addr_rand_scan_supported =
852 info->mac_addr_rand_scan_supported;
853
366179d2
AO
854 if (info->channel_switch_supported) {
855 drv->capa.flags |= WPA_DRIVER_FLAGS_AP_CSA;
856 if (!drv->capa.max_csa_counters)
857 drv->capa.max_csa_counters = 1;
858 }
859
09ea4309
AS
860 if (!drv->capa.max_sched_scan_plans) {
861 drv->capa.max_sched_scan_plans = 1;
862 drv->capa.max_sched_scan_plan_interval = UINT32_MAX;
863 drv->capa.max_sched_scan_plan_iterations = 0;
864 }
865
0fafeb54 866 return 0;
0fafeb54
JM
867}
868
869
b658547d
JM
870#ifdef CONFIG_DRIVER_NL80211_QCA
871
0fafeb54
JM
872static int dfs_info_handler(struct nl_msg *msg, void *arg)
873{
874 struct nlattr *tb[NL80211_ATTR_MAX + 1];
875 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
876 int *dfs_capability_ptr = arg;
877
878 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
879 genlmsg_attrlen(gnlh, 0), NULL);
880
881 if (tb[NL80211_ATTR_VENDOR_DATA]) {
882 struct nlattr *nl_vend = tb[NL80211_ATTR_VENDOR_DATA];
883 struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1];
884
885 nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX,
886 nla_data(nl_vend), nla_len(nl_vend), NULL);
887
888 if (tb_vendor[QCA_WLAN_VENDOR_ATTR_DFS]) {
889 u32 val;
890 val = nla_get_u32(tb_vendor[QCA_WLAN_VENDOR_ATTR_DFS]);
891 wpa_printf(MSG_DEBUG, "nl80211: DFS offload capability: %u",
892 val);
893 *dfs_capability_ptr = val;
894 }
895 }
896
897 return NL_SKIP;
898}
899
900
901static void qca_nl80211_check_dfs_capa(struct wpa_driver_nl80211_data *drv)
902{
903 struct nl_msg *msg;
904 int dfs_capability = 0;
905 int ret;
906
907 if (!drv->dfs_vendor_cmd_avail)
908 return;
909
9725b784 910 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
9589a91e
JM
911 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
912 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
913 QCA_NL80211_VENDOR_SUBCMD_DFS_CAPABILITY)) {
914 nlmsg_free(msg);
915 return;
916 }
0fafeb54
JM
917
918 ret = send_and_recv_msgs(drv, msg, dfs_info_handler, &dfs_capability);
919 if (!ret && dfs_capability)
920 drv->capa.flags |= WPA_DRIVER_FLAGS_DFS_OFFLOAD;
0fafeb54
JM
921}
922
923
ca1ab9db
PX
924static int qca_nl80211_he_capab_handler(struct nl_msg *msg, void *arg)
925{
926 struct nlattr *tb[NL80211_ATTR_MAX + 1];
927 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
928 struct he_capabilities *he_capab = arg;
929 struct nlattr *nl_vend;
930 struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_HE_CAPABILITIES_MAX + 1];
931 size_t len;
932
933 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
934 genlmsg_attrlen(gnlh, 0), NULL);
935
936 if (!tb[NL80211_ATTR_VENDOR_DATA])
937 return NL_SKIP;
938
939 nl_vend = tb[NL80211_ATTR_VENDOR_DATA];
940 nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_HE_CAPABILITIES_MAX,
941 nla_data(nl_vend), nla_len(nl_vend), NULL);
942
943 if (tb_vendor[QCA_WLAN_VENDOR_ATTR_HE_SUPPORTED]) {
944 u8 he_supported;
945
946 he_supported = nla_get_u8(
947 tb_vendor[QCA_WLAN_VENDOR_ATTR_HE_SUPPORTED]);
948 wpa_printf(MSG_DEBUG, "nl80211: HE capabilities supported: %u",
949 he_supported);
950 he_capab->he_supported = he_supported;
951 if (!he_supported)
952 return NL_SKIP;
953 }
954
955 if (tb_vendor[QCA_WLAN_VENDOR_ATTR_PHY_CAPAB]) {
956 len = nla_len(tb_vendor[QCA_WLAN_VENDOR_ATTR_PHY_CAPAB]);
957
958 if (len > sizeof(he_capab->phy_cap))
959 len = sizeof(he_capab->phy_cap);
960 os_memcpy(he_capab->phy_cap,
961 nla_data(tb_vendor[QCA_WLAN_VENDOR_ATTR_PHY_CAPAB]),
962 len);
963 }
964
965 if (tb_vendor[QCA_WLAN_VENDOR_ATTR_MAC_CAPAB])
966 he_capab->mac_cap =
967 nla_get_u32(tb_vendor[QCA_WLAN_VENDOR_ATTR_MAC_CAPAB]);
968
969 if (tb_vendor[QCA_WLAN_VENDOR_ATTR_HE_MCS])
970 he_capab->mcs =
971 nla_get_u32(tb_vendor[QCA_WLAN_VENDOR_ATTR_HE_MCS]);
972
973 if (tb_vendor[QCA_WLAN_VENDOR_ATTR_NUM_SS])
974 he_capab->ppet.numss_m1 =
975 nla_get_u32(tb_vendor[QCA_WLAN_VENDOR_ATTR_NUM_SS]);
976
977 if (tb_vendor[QCA_WLAN_VENDOR_ATTR_RU_IDX_MASK])
978 he_capab->ppet.ru_count =
979 nla_get_u32(tb_vendor[QCA_WLAN_VENDOR_ATTR_RU_IDX_MASK]);
980
981 if (tb_vendor[QCA_WLAN_VENDOR_ATTR_PPE_THRESHOLD]) {
982 len = nla_len(tb_vendor[QCA_WLAN_VENDOR_ATTR_PPE_THRESHOLD]);
983
984 if (len > sizeof(he_capab->ppet.ppet16_ppet8_ru3_ru0))
985 len = sizeof(he_capab->ppet.ppet16_ppet8_ru3_ru0);
986 os_memcpy(he_capab->ppet.ppet16_ppet8_ru3_ru0,
987 nla_data(tb_vendor[QCA_WLAN_VENDOR_ATTR_PPE_THRESHOLD]),
988 len);
989 }
990
991 return NL_SKIP;
992}
993
994
995static void qca_nl80211_check_he_capab(struct wpa_driver_nl80211_data *drv)
996{
997 struct nl_msg *msg;
998 int ret;
999
1000 if (!drv->he_capab_vendor_cmd_avail)
1001 return;
1002
1003 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
1004 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
1005 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
1006 QCA_NL80211_VENDOR_SUBCMD_GET_HE_CAPABILITIES)) {
1007 nlmsg_free(msg);
1008 return;
1009 }
1010
1011 ret = send_and_recv_msgs(drv, msg, qca_nl80211_he_capab_handler,
1012 &drv->he_capab);
1013 if (!ret && drv->he_capab.he_supported)
1014 drv->capa.flags |= WPA_DRIVER_FLAGS_HE_CAPABILITIES;
1015}
1016
1017
15badebd
CL
1018struct features_info {
1019 u8 *flags;
1020 size_t flags_len;
079a28f7 1021 struct wpa_driver_capa *capa;
15badebd
CL
1022};
1023
1024
1025static int features_info_handler(struct nl_msg *msg, void *arg)
1026{
1027 struct nlattr *tb[NL80211_ATTR_MAX + 1];
1028 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1029 struct features_info *info = arg;
1030 struct nlattr *nl_vend, *attr;
1031
1032 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1033 genlmsg_attrlen(gnlh, 0), NULL);
1034
1035 nl_vend = tb[NL80211_ATTR_VENDOR_DATA];
1036 if (nl_vend) {
1037 struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1];
1038
1039 nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX,
1040 nla_data(nl_vend), nla_len(nl_vend), NULL);
1041
1042 attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_FEATURE_FLAGS];
1043 if (attr) {
fdc1188a
PS
1044 int len = nla_len(attr);
1045 info->flags = os_malloc(len);
1046 if (info->flags != NULL) {
1047 os_memcpy(info->flags, nla_data(attr), len);
1048 info->flags_len = len;
1049 }
15badebd 1050 }
079a28f7
AK
1051 attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_CONCURRENCY_CAPA];
1052 if (attr)
1053 info->capa->conc_capab = nla_get_u32(attr);
1054
1055 attr = tb_vendor[
1056 QCA_WLAN_VENDOR_ATTR_MAX_CONCURRENT_CHANNELS_2_4_BAND];
1057 if (attr)
1058 info->capa->max_conc_chan_2_4 = nla_get_u32(attr);
1059
1060 attr = tb_vendor[
1061 QCA_WLAN_VENDOR_ATTR_MAX_CONCURRENT_CHANNELS_5_0_BAND];
1062 if (attr)
1063 info->capa->max_conc_chan_5_0 = nla_get_u32(attr);
15badebd
CL
1064 }
1065
1066 return NL_SKIP;
1067}
1068
1069
1070static int check_feature(enum qca_wlan_vendor_features feature,
1071 struct features_info *info)
1072{
49e3eea8 1073 size_t idx = feature / 8;
15badebd 1074
49e3eea8
JM
1075 return (idx < info->flags_len) &&
1076 (info->flags[idx] & BIT(feature % 8));
15badebd
CL
1077}
1078
1079
1080static void qca_nl80211_get_features(struct wpa_driver_nl80211_data *drv)
1081{
1082 struct nl_msg *msg;
1083 struct features_info info;
1084 int ret;
1085
1086 if (!drv->get_features_vendor_cmd_avail)
1087 return;
1088
1089 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
1090 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
1091 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
1092 QCA_NL80211_VENDOR_SUBCMD_GET_FEATURES)) {
1093 nlmsg_free(msg);
1094 return;
1095 }
1096
1097 os_memset(&info, 0, sizeof(info));
079a28f7 1098 info.capa = &drv->capa;
15badebd
CL
1099 ret = send_and_recv_msgs(drv, msg, features_info_handler, &info);
1100 if (ret || !info.flags)
1101 return;
1102
1103 if (check_feature(QCA_WLAN_VENDOR_FEATURE_KEY_MGMT_OFFLOAD, &info))
1104 drv->capa.flags |= WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD;
3784c058
PX
1105
1106 if (check_feature(QCA_WLAN_VENDOR_FEATURE_SUPPORT_HW_MODE_ANY, &info))
1107 drv->capa.flags |= WPA_DRIVER_FLAGS_SUPPORT_HW_MODE_ANY;
8e509745
KV
1108
1109 if (check_feature(QCA_WLAN_VENDOR_FEATURE_OFFCHANNEL_SIMULTANEOUS,
1110 &info))
1111 drv->capa.flags |= WPA_DRIVER_FLAGS_OFFCHANNEL_SIMULTANEOUS;
a6f5b193
PX
1112 if (check_feature(QCA_WLAN_VENDOR_FEATURE_P2P_LISTEN_OFFLOAD, &info))
1113 drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD;
fdc1188a 1114 os_free(info.flags);
15badebd
CL
1115}
1116
b658547d
JM
1117#endif /* CONFIG_DRIVER_NL80211_QCA */
1118
15badebd 1119
0fafeb54
JM
1120int wpa_driver_nl80211_capa(struct wpa_driver_nl80211_data *drv)
1121{
1122 struct wiphy_info_data info;
1123 if (wpa_driver_nl80211_get_info(drv, &info))
1124 return -1;
1125
1126 if (info.error)
1127 return -1;
1128
1129 drv->has_capability = 1;
1130 drv->capa.key_mgmt = WPA_DRIVER_CAPA_KEY_MGMT_WPA |
1131 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
1132 WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
399e6135
JM
1133 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK |
1134 WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B |
f9561868
JM
1135 WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192 |
1136 WPA_DRIVER_CAPA_KEY_MGMT_OWE;
0fafeb54
JM
1137 drv->capa.auth = WPA_DRIVER_AUTH_OPEN |
1138 WPA_DRIVER_AUTH_SHARED |
1139 WPA_DRIVER_AUTH_LEAP;
1140
1141 drv->capa.flags |= WPA_DRIVER_FLAGS_SANE_ERROR_CODES;
1142 drv->capa.flags |= WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE;
1143 drv->capa.flags |= WPA_DRIVER_FLAGS_EAPOL_TX_STATUS;
1144
1145 /*
1146 * As all cfg80211 drivers must support cases where the AP interface is
1147 * removed without the knowledge of wpa_supplicant/hostapd, e.g., in
1148 * case that the user space daemon has crashed, they must be able to
1149 * cleanup all stations and key entries in the AP tear down flow. Thus,
1150 * this flag can/should always be set for cfg80211 drivers.
1151 */
1152 drv->capa.flags |= WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT;
1153
1154 if (!info.device_ap_sme) {
1155 drv->capa.flags |= WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS;
1156
1157 /*
1158 * No AP SME is currently assumed to also indicate no AP MLME
1159 * in the driver/firmware.
1160 */
1161 drv->capa.flags |= WPA_DRIVER_FLAGS_AP_MLME;
1162 }
1163
1164 drv->device_ap_sme = info.device_ap_sme;
1165 drv->poll_command_supported = info.poll_command_supported;
1166 drv->data_tx_status = info.data_tx_status;
abb8d08b 1167 drv->p2p_go_ctwindow_supported = info.p2p_go_ctwindow_supported;
0fafeb54
JM
1168 if (info.set_qos_map_supported)
1169 drv->capa.flags |= WPA_DRIVER_FLAGS_QOS_MAPPING;
1170 drv->have_low_prio_scan = info.have_low_prio_scan;
1171
1172 /*
1173 * If poll command and tx status are supported, mac80211 is new enough
1174 * to have everything we need to not need monitor interfaces.
1175 */
660103ec
SD
1176 drv->use_monitor = !info.device_ap_sme &&
1177 (!info.poll_command_supported || !info.data_tx_status);
0fafeb54
JM
1178
1179 /*
1180 * If we aren't going to use monitor interfaces, but the
1181 * driver doesn't support data TX status, we won't get TX
1182 * status for EAPOL frames.
1183 */
1184 if (!drv->use_monitor && !info.data_tx_status)
1185 drv->capa.flags &= ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS;
1186
b658547d 1187#ifdef CONFIG_DRIVER_NL80211_QCA
0fafeb54 1188 qca_nl80211_check_dfs_capa(drv);
15badebd 1189 qca_nl80211_get_features(drv);
ca1ab9db 1190 qca_nl80211_check_he_capab(drv);
0fafeb54 1191
8e509745
KV
1192 /*
1193 * To enable offchannel simultaneous support in wpa_supplicant, the
1194 * underlying driver needs to support the same along with offchannel TX.
1195 * Offchannel TX support is needed since remain_on_channel and
1196 * action_tx use some common data structures and hence cannot be
1197 * scheduled simultaneously.
1198 */
1199 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX))
1200 drv->capa.flags &= ~WPA_DRIVER_FLAGS_OFFCHANNEL_SIMULTANEOUS;
b658547d 1201#endif /* CONFIG_DRIVER_NL80211_QCA */
8e509745 1202
0fafeb54
JM
1203 return 0;
1204}
1205
1206
1207struct phy_info_arg {
1208 u16 *num_modes;
1209 struct hostapd_hw_modes *modes;
1210 int last_mode, last_chan_idx;
747ba106 1211 int failed;
0fafeb54
JM
1212};
1213
1214static void phy_info_ht_capa(struct hostapd_hw_modes *mode, struct nlattr *capa,
1215 struct nlattr *ampdu_factor,
1216 struct nlattr *ampdu_density,
1217 struct nlattr *mcs_set)
1218{
1219 if (capa)
1220 mode->ht_capab = nla_get_u16(capa);
1221
1222 if (ampdu_factor)
1223 mode->a_mpdu_params |= nla_get_u8(ampdu_factor) & 0x03;
1224
1225 if (ampdu_density)
1226 mode->a_mpdu_params |= nla_get_u8(ampdu_density) << 2;
1227
1228 if (mcs_set && nla_len(mcs_set) >= 16) {
1229 u8 *mcs;
1230 mcs = nla_data(mcs_set);
1231 os_memcpy(mode->mcs_set, mcs, 16);
1232 }
1233}
1234
1235
1236static void phy_info_vht_capa(struct hostapd_hw_modes *mode,
1237 struct nlattr *capa,
1238 struct nlattr *mcs_set)
1239{
1240 if (capa)
1241 mode->vht_capab = nla_get_u32(capa);
1242
1243 if (mcs_set && nla_len(mcs_set) >= 8) {
1244 u8 *mcs;
1245 mcs = nla_data(mcs_set);
1246 os_memcpy(mode->vht_mcs_set, mcs, 8);
1247 }
1248}
1249
1250
1251static void phy_info_freq(struct hostapd_hw_modes *mode,
1252 struct hostapd_channel_data *chan,
1253 struct nlattr *tb_freq[])
1254{
1255 u8 channel;
1256 chan->freq = nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_FREQ]);
1257 chan->flag = 0;
1258 chan->dfs_cac_ms = 0;
1259 if (ieee80211_freq_to_chan(chan->freq, &channel) != NUM_HOSTAPD_MODES)
1260 chan->chan = channel;
1261
1262 if (tb_freq[NL80211_FREQUENCY_ATTR_DISABLED])
1263 chan->flag |= HOSTAPD_CHAN_DISABLED;
1264 if (tb_freq[NL80211_FREQUENCY_ATTR_NO_IR])
1265 chan->flag |= HOSTAPD_CHAN_NO_IR;
1266 if (tb_freq[NL80211_FREQUENCY_ATTR_RADAR])
1267 chan->flag |= HOSTAPD_CHAN_RADAR;
1268 if (tb_freq[NL80211_FREQUENCY_ATTR_INDOOR_ONLY])
1269 chan->flag |= HOSTAPD_CHAN_INDOOR_ONLY;
1270 if (tb_freq[NL80211_FREQUENCY_ATTR_GO_CONCURRENT])
1271 chan->flag |= HOSTAPD_CHAN_GO_CONCURRENT;
1272
1273 if (tb_freq[NL80211_FREQUENCY_ATTR_DFS_STATE]) {
1274 enum nl80211_dfs_state state =
1275 nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_DFS_STATE]);
1276
1277 switch (state) {
1278 case NL80211_DFS_USABLE:
1279 chan->flag |= HOSTAPD_CHAN_DFS_USABLE;
1280 break;
1281 case NL80211_DFS_AVAILABLE:
1282 chan->flag |= HOSTAPD_CHAN_DFS_AVAILABLE;
1283 break;
1284 case NL80211_DFS_UNAVAILABLE:
1285 chan->flag |= HOSTAPD_CHAN_DFS_UNAVAILABLE;
1286 break;
1287 }
1288 }
1289
1290 if (tb_freq[NL80211_FREQUENCY_ATTR_DFS_CAC_TIME]) {
1291 chan->dfs_cac_ms = nla_get_u32(
1292 tb_freq[NL80211_FREQUENCY_ATTR_DFS_CAC_TIME]);
1293 }
1294}
1295
1296
1297static int phy_info_freqs(struct phy_info_arg *phy_info,
1298 struct hostapd_hw_modes *mode, struct nlattr *tb)
1299{
1300 static struct nla_policy freq_policy[NL80211_FREQUENCY_ATTR_MAX + 1] = {
1301 [NL80211_FREQUENCY_ATTR_FREQ] = { .type = NLA_U32 },
1302 [NL80211_FREQUENCY_ATTR_DISABLED] = { .type = NLA_FLAG },
1303 [NL80211_FREQUENCY_ATTR_NO_IR] = { .type = NLA_FLAG },
1304 [NL80211_FREQUENCY_ATTR_RADAR] = { .type = NLA_FLAG },
1305 [NL80211_FREQUENCY_ATTR_MAX_TX_POWER] = { .type = NLA_U32 },
1306 [NL80211_FREQUENCY_ATTR_DFS_STATE] = { .type = NLA_U32 },
1307 };
1308 int new_channels = 0;
1309 struct hostapd_channel_data *channel;
1310 struct nlattr *tb_freq[NL80211_FREQUENCY_ATTR_MAX + 1];
1311 struct nlattr *nl_freq;
1312 int rem_freq, idx;
1313
1314 if (tb == NULL)
1315 return NL_OK;
1316
1317 nla_for_each_nested(nl_freq, tb, rem_freq) {
1318 nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX,
1319 nla_data(nl_freq), nla_len(nl_freq), freq_policy);
1320 if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ])
1321 continue;
1322 new_channels++;
1323 }
1324
1325 channel = os_realloc_array(mode->channels,
1326 mode->num_channels + new_channels,
1327 sizeof(struct hostapd_channel_data));
1328 if (!channel)
747ba106 1329 return NL_STOP;
0fafeb54
JM
1330
1331 mode->channels = channel;
1332 mode->num_channels += new_channels;
1333
1334 idx = phy_info->last_chan_idx;
1335
1336 nla_for_each_nested(nl_freq, tb, rem_freq) {
1337 nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX,
1338 nla_data(nl_freq), nla_len(nl_freq), freq_policy);
1339 if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ])
1340 continue;
1341 phy_info_freq(mode, &mode->channels[idx], tb_freq);
1342 idx++;
1343 }
1344 phy_info->last_chan_idx = idx;
1345
1346 return NL_OK;
1347}
1348
1349
1350static int phy_info_rates(struct hostapd_hw_modes *mode, struct nlattr *tb)
1351{
1352 static struct nla_policy rate_policy[NL80211_BITRATE_ATTR_MAX + 1] = {
1353 [NL80211_BITRATE_ATTR_RATE] = { .type = NLA_U32 },
1354 [NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE] =
1355 { .type = NLA_FLAG },
1356 };
1357 struct nlattr *tb_rate[NL80211_BITRATE_ATTR_MAX + 1];
1358 struct nlattr *nl_rate;
1359 int rem_rate, idx;
1360
1361 if (tb == NULL)
1362 return NL_OK;
1363
1364 nla_for_each_nested(nl_rate, tb, rem_rate) {
1365 nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX,
1366 nla_data(nl_rate), nla_len(nl_rate),
1367 rate_policy);
1368 if (!tb_rate[NL80211_BITRATE_ATTR_RATE])
1369 continue;
1370 mode->num_rates++;
1371 }
1372
1373 mode->rates = os_calloc(mode->num_rates, sizeof(int));
1374 if (!mode->rates)
747ba106 1375 return NL_STOP;
0fafeb54
JM
1376
1377 idx = 0;
1378
1379 nla_for_each_nested(nl_rate, tb, rem_rate) {
1380 nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX,
1381 nla_data(nl_rate), nla_len(nl_rate),
1382 rate_policy);
1383 if (!tb_rate[NL80211_BITRATE_ATTR_RATE])
1384 continue;
1385 mode->rates[idx] = nla_get_u32(
1386 tb_rate[NL80211_BITRATE_ATTR_RATE]);
1387 idx++;
1388 }
1389
1390 return NL_OK;
1391}
1392
1393
1394static int phy_info_band(struct phy_info_arg *phy_info, struct nlattr *nl_band)
1395{
1396 struct nlattr *tb_band[NL80211_BAND_ATTR_MAX + 1];
1397 struct hostapd_hw_modes *mode;
1398 int ret;
1399
1400 if (phy_info->last_mode != nl_band->nla_type) {
1401 mode = os_realloc_array(phy_info->modes,
1402 *phy_info->num_modes + 1,
1403 sizeof(*mode));
747ba106
JM
1404 if (!mode) {
1405 phy_info->failed = 1;
1406 return NL_STOP;
1407 }
0fafeb54
JM
1408 phy_info->modes = mode;
1409
1410 mode = &phy_info->modes[*(phy_info->num_modes)];
1411 os_memset(mode, 0, sizeof(*mode));
1412 mode->mode = NUM_HOSTAPD_MODES;
1413 mode->flags = HOSTAPD_MODE_FLAG_HT_INFO_KNOWN |
1414 HOSTAPD_MODE_FLAG_VHT_INFO_KNOWN;
1415
1416 /*
1417 * Unsupported VHT MCS stream is defined as value 3, so the VHT
1418 * MCS RX/TX map must be initialized with 0xffff to mark all 8
1419 * possible streams as unsupported. This will be overridden if
1420 * driver advertises VHT support.
1421 */
1422 mode->vht_mcs_set[0] = 0xff;
1423 mode->vht_mcs_set[1] = 0xff;
1424 mode->vht_mcs_set[4] = 0xff;
1425 mode->vht_mcs_set[5] = 0xff;
1426
1427 *(phy_info->num_modes) += 1;
1428 phy_info->last_mode = nl_band->nla_type;
1429 phy_info->last_chan_idx = 0;
1430 } else
1431 mode = &phy_info->modes[*(phy_info->num_modes) - 1];
1432
1433 nla_parse(tb_band, NL80211_BAND_ATTR_MAX, nla_data(nl_band),
1434 nla_len(nl_band), NULL);
1435
1436 phy_info_ht_capa(mode, tb_band[NL80211_BAND_ATTR_HT_CAPA],
1437 tb_band[NL80211_BAND_ATTR_HT_AMPDU_FACTOR],
1438 tb_band[NL80211_BAND_ATTR_HT_AMPDU_DENSITY],
1439 tb_band[NL80211_BAND_ATTR_HT_MCS_SET]);
1440 phy_info_vht_capa(mode, tb_band[NL80211_BAND_ATTR_VHT_CAPA],
1441 tb_band[NL80211_BAND_ATTR_VHT_MCS_SET]);
1442 ret = phy_info_freqs(phy_info, mode, tb_band[NL80211_BAND_ATTR_FREQS]);
747ba106
JM
1443 if (ret == NL_OK)
1444 ret = phy_info_rates(mode, tb_band[NL80211_BAND_ATTR_RATES]);
1445 if (ret != NL_OK) {
1446 phy_info->failed = 1;
0fafeb54 1447 return ret;
747ba106 1448 }
0fafeb54
JM
1449
1450 return NL_OK;
1451}
1452
1453
1454static int phy_info_handler(struct nl_msg *msg, void *arg)
1455{
1456 struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
1457 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1458 struct phy_info_arg *phy_info = arg;
1459 struct nlattr *nl_band;
1460 int rem_band;
1461
1462 nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1463 genlmsg_attrlen(gnlh, 0), NULL);
1464
1465 if (!tb_msg[NL80211_ATTR_WIPHY_BANDS])
1466 return NL_SKIP;
1467
1468 nla_for_each_nested(nl_band, tb_msg[NL80211_ATTR_WIPHY_BANDS], rem_band)
1469 {
1470 int res = phy_info_band(phy_info, nl_band);
1471 if (res != NL_OK)
1472 return res;
1473 }
1474
1475 return NL_SKIP;
1476}
1477
1478
1479static struct hostapd_hw_modes *
1480wpa_driver_nl80211_postprocess_modes(struct hostapd_hw_modes *modes,
1481 u16 *num_modes)
1482{
1483 u16 m;
1484 struct hostapd_hw_modes *mode11g = NULL, *nmodes, *mode;
1485 int i, mode11g_idx = -1;
1486
1487 /* heuristic to set up modes */
1488 for (m = 0; m < *num_modes; m++) {
1489 if (!modes[m].num_channels)
1490 continue;
1491 if (modes[m].channels[0].freq < 4000) {
1492 modes[m].mode = HOSTAPD_MODE_IEEE80211B;
1493 for (i = 0; i < modes[m].num_rates; i++) {
1494 if (modes[m].rates[i] > 200) {
1495 modes[m].mode = HOSTAPD_MODE_IEEE80211G;
1496 break;
1497 }
1498 }
1499 } else if (modes[m].channels[0].freq > 50000)
1500 modes[m].mode = HOSTAPD_MODE_IEEE80211AD;
1501 else
1502 modes[m].mode = HOSTAPD_MODE_IEEE80211A;
1503 }
1504
1505 /* If only 802.11g mode is included, use it to construct matching
1506 * 802.11b mode data. */
1507
1508 for (m = 0; m < *num_modes; m++) {
1509 if (modes[m].mode == HOSTAPD_MODE_IEEE80211B)
1510 return modes; /* 802.11b already included */
1511 if (modes[m].mode == HOSTAPD_MODE_IEEE80211G)
1512 mode11g_idx = m;
1513 }
1514
1515 if (mode11g_idx < 0)
1516 return modes; /* 2.4 GHz band not supported at all */
1517
1518 nmodes = os_realloc_array(modes, *num_modes + 1, sizeof(*nmodes));
1519 if (nmodes == NULL)
1520 return modes; /* Could not add 802.11b mode */
1521
1522 mode = &nmodes[*num_modes];
1523 os_memset(mode, 0, sizeof(*mode));
1524 (*num_modes)++;
1525 modes = nmodes;
1526
1527 mode->mode = HOSTAPD_MODE_IEEE80211B;
1528
1529 mode11g = &modes[mode11g_idx];
1530 mode->num_channels = mode11g->num_channels;
a1f11e34
JB
1531 mode->channels = os_memdup(mode11g->channels,
1532 mode11g->num_channels *
0fafeb54
JM
1533 sizeof(struct hostapd_channel_data));
1534 if (mode->channels == NULL) {
1535 (*num_modes)--;
1536 return modes; /* Could not add 802.11b mode */
1537 }
0fafeb54
JM
1538
1539 mode->num_rates = 0;
1540 mode->rates = os_malloc(4 * sizeof(int));
1541 if (mode->rates == NULL) {
1542 os_free(mode->channels);
1543 (*num_modes)--;
1544 return modes; /* Could not add 802.11b mode */
1545 }
1546
1547 for (i = 0; i < mode11g->num_rates; i++) {
1548 if (mode11g->rates[i] != 10 && mode11g->rates[i] != 20 &&
1549 mode11g->rates[i] != 55 && mode11g->rates[i] != 110)
1550 continue;
1551 mode->rates[mode->num_rates] = mode11g->rates[i];
1552 mode->num_rates++;
1553 if (mode->num_rates == 4)
1554 break;
1555 }
1556
1557 if (mode->num_rates == 0) {
1558 os_free(mode->channels);
1559 os_free(mode->rates);
1560 (*num_modes)--;
1561 return modes; /* No 802.11b rates */
1562 }
1563
1564 wpa_printf(MSG_DEBUG, "nl80211: Added 802.11b mode based on 802.11g "
1565 "information");
1566
1567 return modes;
1568}
1569
1570
1571static void nl80211_set_ht40_mode(struct hostapd_hw_modes *mode, int start,
1572 int end)
1573{
1574 int c;
1575
1576 for (c = 0; c < mode->num_channels; c++) {
1577 struct hostapd_channel_data *chan = &mode->channels[c];
1578 if (chan->freq - 10 >= start && chan->freq + 10 <= end)
1579 chan->flag |= HOSTAPD_CHAN_HT40;
1580 }
1581}
1582
1583
1584static void nl80211_set_ht40_mode_sec(struct hostapd_hw_modes *mode, int start,
1585 int end)
1586{
1587 int c;
1588
1589 for (c = 0; c < mode->num_channels; c++) {
1590 struct hostapd_channel_data *chan = &mode->channels[c];
1591 if (!(chan->flag & HOSTAPD_CHAN_HT40))
1592 continue;
1593 if (chan->freq - 30 >= start && chan->freq - 10 <= end)
1594 chan->flag |= HOSTAPD_CHAN_HT40MINUS;
1595 if (chan->freq + 10 >= start && chan->freq + 30 <= end)
1596 chan->flag |= HOSTAPD_CHAN_HT40PLUS;
1597 }
1598}
1599
1600
1601static void nl80211_reg_rule_max_eirp(u32 start, u32 end, u32 max_eirp,
1602 struct phy_info_arg *results)
1603{
1604 u16 m;
1605
1606 for (m = 0; m < *results->num_modes; m++) {
1607 int c;
1608 struct hostapd_hw_modes *mode = &results->modes[m];
1609
1610 for (c = 0; c < mode->num_channels; c++) {
1611 struct hostapd_channel_data *chan = &mode->channels[c];
1612 if ((u32) chan->freq - 10 >= start &&
1613 (u32) chan->freq + 10 <= end)
1614 chan->max_tx_power = max_eirp;
1615 }
1616 }
1617}
1618
1619
1620static void nl80211_reg_rule_ht40(u32 start, u32 end,
1621 struct phy_info_arg *results)
1622{
1623 u16 m;
1624
1625 for (m = 0; m < *results->num_modes; m++) {
1626 if (!(results->modes[m].ht_capab &
1627 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET))
1628 continue;
1629 nl80211_set_ht40_mode(&results->modes[m], start, end);
1630 }
1631}
1632
1633
1634static void nl80211_reg_rule_sec(struct nlattr *tb[],
1635 struct phy_info_arg *results)
1636{
1637 u32 start, end, max_bw;
1638 u16 m;
1639
1640 if (tb[NL80211_ATTR_FREQ_RANGE_START] == NULL ||
1641 tb[NL80211_ATTR_FREQ_RANGE_END] == NULL ||
1642 tb[NL80211_ATTR_FREQ_RANGE_MAX_BW] == NULL)
1643 return;
1644
1645 start = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]) / 1000;
1646 end = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]) / 1000;
1647 max_bw = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) / 1000;
1648
1649 if (max_bw < 20)
1650 return;
1651
1652 for (m = 0; m < *results->num_modes; m++) {
1653 if (!(results->modes[m].ht_capab &
1654 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET))
1655 continue;
1656 nl80211_set_ht40_mode_sec(&results->modes[m], start, end);
1657 }
1658}
1659
1660
1661static void nl80211_set_vht_mode(struct hostapd_hw_modes *mode, int start,
bee5d8e0 1662 int end, int max_bw)
0fafeb54
JM
1663{
1664 int c;
1665
1666 for (c = 0; c < mode->num_channels; c++) {
1667 struct hostapd_channel_data *chan = &mode->channels[c];
1668 if (chan->freq - 10 >= start && chan->freq + 70 <= end)
1669 chan->flag |= HOSTAPD_CHAN_VHT_10_70;
1670
1671 if (chan->freq - 30 >= start && chan->freq + 50 <= end)
1672 chan->flag |= HOSTAPD_CHAN_VHT_30_50;
1673
1674 if (chan->freq - 50 >= start && chan->freq + 30 <= end)
1675 chan->flag |= HOSTAPD_CHAN_VHT_50_30;
1676
1677 if (chan->freq - 70 >= start && chan->freq + 10 <= end)
1678 chan->flag |= HOSTAPD_CHAN_VHT_70_10;
bee5d8e0
AK
1679
1680 if (max_bw >= 160) {
1681 if (chan->freq - 10 >= start && chan->freq + 150 <= end)
1682 chan->flag |= HOSTAPD_CHAN_VHT_10_150;
1683
1684 if (chan->freq - 30 >= start && chan->freq + 130 <= end)
1685 chan->flag |= HOSTAPD_CHAN_VHT_30_130;
1686
1687 if (chan->freq - 50 >= start && chan->freq + 110 <= end)
1688 chan->flag |= HOSTAPD_CHAN_VHT_50_110;
1689
1690 if (chan->freq - 70 >= start && chan->freq + 90 <= end)
1691 chan->flag |= HOSTAPD_CHAN_VHT_70_90;
1692
1693 if (chan->freq - 90 >= start && chan->freq + 70 <= end)
1694 chan->flag |= HOSTAPD_CHAN_VHT_90_70;
1695
1696 if (chan->freq - 110 >= start && chan->freq + 50 <= end)
1697 chan->flag |= HOSTAPD_CHAN_VHT_110_50;
1698
1699 if (chan->freq - 130 >= start && chan->freq + 30 <= end)
1700 chan->flag |= HOSTAPD_CHAN_VHT_130_30;
1701
1702 if (chan->freq - 150 >= start && chan->freq + 10 <= end)
1703 chan->flag |= HOSTAPD_CHAN_VHT_150_10;
1704 }
0fafeb54
JM
1705 }
1706}
1707
1708
1709static void nl80211_reg_rule_vht(struct nlattr *tb[],
1710 struct phy_info_arg *results)
1711{
1712 u32 start, end, max_bw;
1713 u16 m;
1714
1715 if (tb[NL80211_ATTR_FREQ_RANGE_START] == NULL ||
1716 tb[NL80211_ATTR_FREQ_RANGE_END] == NULL ||
1717 tb[NL80211_ATTR_FREQ_RANGE_MAX_BW] == NULL)
1718 return;
1719
1720 start = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]) / 1000;
1721 end = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]) / 1000;
1722 max_bw = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) / 1000;
1723
1724 if (max_bw < 80)
1725 return;
1726
1727 for (m = 0; m < *results->num_modes; m++) {
1728 if (!(results->modes[m].ht_capab &
1729 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET))
1730 continue;
1731 /* TODO: use a real VHT support indication */
1732 if (!results->modes[m].vht_capab)
1733 continue;
1734
bee5d8e0 1735 nl80211_set_vht_mode(&results->modes[m], start, end, max_bw);
0fafeb54
JM
1736 }
1737}
1738
1739
1740static const char * dfs_domain_name(enum nl80211_dfs_regions region)
1741{
1742 switch (region) {
1743 case NL80211_DFS_UNSET:
1744 return "DFS-UNSET";
1745 case NL80211_DFS_FCC:
1746 return "DFS-FCC";
1747 case NL80211_DFS_ETSI:
1748 return "DFS-ETSI";
1749 case NL80211_DFS_JP:
1750 return "DFS-JP";
1751 default:
1752 return "DFS-invalid";
1753 }
1754}
1755
1756
1757static int nl80211_get_reg(struct nl_msg *msg, void *arg)
1758{
1759 struct phy_info_arg *results = arg;
1760 struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
1761 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1762 struct nlattr *nl_rule;
1763 struct nlattr *tb_rule[NL80211_FREQUENCY_ATTR_MAX + 1];
1764 int rem_rule;
1765 static struct nla_policy reg_policy[NL80211_FREQUENCY_ATTR_MAX + 1] = {
1766 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
1767 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
1768 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
1769 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
1770 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
1771 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
1772 };
1773
1774 nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1775 genlmsg_attrlen(gnlh, 0), NULL);
1776 if (!tb_msg[NL80211_ATTR_REG_ALPHA2] ||
1777 !tb_msg[NL80211_ATTR_REG_RULES]) {
1778 wpa_printf(MSG_DEBUG, "nl80211: No regulatory information "
1779 "available");
1780 return NL_SKIP;
1781 }
1782
1783 if (tb_msg[NL80211_ATTR_DFS_REGION]) {
1784 enum nl80211_dfs_regions dfs_domain;
1785 dfs_domain = nla_get_u8(tb_msg[NL80211_ATTR_DFS_REGION]);
1786 wpa_printf(MSG_DEBUG, "nl80211: Regulatory information - country=%s (%s)",
1787 (char *) nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]),
1788 dfs_domain_name(dfs_domain));
1789 } else {
1790 wpa_printf(MSG_DEBUG, "nl80211: Regulatory information - country=%s",
1791 (char *) nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]));
1792 }
1793
1794 nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule)
1795 {
1796 u32 start, end, max_eirp = 0, max_bw = 0, flags = 0;
1797 nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX,
1798 nla_data(nl_rule), nla_len(nl_rule), reg_policy);
1799 if (tb_rule[NL80211_ATTR_FREQ_RANGE_START] == NULL ||
1800 tb_rule[NL80211_ATTR_FREQ_RANGE_END] == NULL)
1801 continue;
1802 start = nla_get_u32(tb_rule[NL80211_ATTR_FREQ_RANGE_START]) / 1000;
1803 end = nla_get_u32(tb_rule[NL80211_ATTR_FREQ_RANGE_END]) / 1000;
1804 if (tb_rule[NL80211_ATTR_POWER_RULE_MAX_EIRP])
1805 max_eirp = nla_get_u32(tb_rule[NL80211_ATTR_POWER_RULE_MAX_EIRP]) / 100;
1806 if (tb_rule[NL80211_ATTR_FREQ_RANGE_MAX_BW])
1807 max_bw = nla_get_u32(tb_rule[NL80211_ATTR_FREQ_RANGE_MAX_BW]) / 1000;
1808 if (tb_rule[NL80211_ATTR_REG_RULE_FLAGS])
1809 flags = nla_get_u32(tb_rule[NL80211_ATTR_REG_RULE_FLAGS]);
1810
1811 wpa_printf(MSG_DEBUG, "nl80211: %u-%u @ %u MHz %u mBm%s%s%s%s%s%s%s%s",
1812 start, end, max_bw, max_eirp,
1813 flags & NL80211_RRF_NO_OFDM ? " (no OFDM)" : "",
1814 flags & NL80211_RRF_NO_CCK ? " (no CCK)" : "",
1815 flags & NL80211_RRF_NO_INDOOR ? " (no indoor)" : "",
1816 flags & NL80211_RRF_NO_OUTDOOR ? " (no outdoor)" :
1817 "",
1818 flags & NL80211_RRF_DFS ? " (DFS)" : "",
1819 flags & NL80211_RRF_PTP_ONLY ? " (PTP only)" : "",
1820 flags & NL80211_RRF_PTMP_ONLY ? " (PTMP only)" : "",
1821 flags & NL80211_RRF_NO_IR ? " (no IR)" : "");
1822 if (max_bw >= 40)
1823 nl80211_reg_rule_ht40(start, end, results);
1824 if (tb_rule[NL80211_ATTR_POWER_RULE_MAX_EIRP])
1825 nl80211_reg_rule_max_eirp(start, end, max_eirp,
1826 results);
1827 }
1828
1829 nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule)
1830 {
1831 nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX,
1832 nla_data(nl_rule), nla_len(nl_rule), reg_policy);
1833 nl80211_reg_rule_sec(tb_rule, results);
1834 }
1835
1836 nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule)
1837 {
1838 nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX,
1839 nla_data(nl_rule), nla_len(nl_rule), reg_policy);
1840 nl80211_reg_rule_vht(tb_rule, results);
1841 }
1842
1843 return NL_SKIP;
1844}
1845
1846
1847static int nl80211_set_regulatory_flags(struct wpa_driver_nl80211_data *drv,
1848 struct phy_info_arg *results)
1849{
1850 struct nl_msg *msg;
1851
1852 msg = nlmsg_alloc();
1853 if (!msg)
1854 return -ENOMEM;
1855
1856 nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG);
1857 return send_and_recv_msgs(drv, msg, nl80211_get_reg, results);
1858}
1859
1860
1861struct hostapd_hw_modes *
1862nl80211_get_hw_feature_data(void *priv, u16 *num_modes, u16 *flags)
1863{
1864 u32 feat;
1865 struct i802_bss *bss = priv;
1866 struct wpa_driver_nl80211_data *drv = bss->drv;
9589a91e 1867 int nl_flags = 0;
0fafeb54
JM
1868 struct nl_msg *msg;
1869 struct phy_info_arg result = {
1870 .num_modes = num_modes,
1871 .modes = NULL,
1872 .last_mode = -1,
747ba106 1873 .failed = 0,
0fafeb54
JM
1874 };
1875
1876 *num_modes = 0;
1877 *flags = 0;
1878
0fafeb54
JM
1879 feat = get_nl80211_protocol_features(drv);
1880 if (feat & NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)
9589a91e 1881 nl_flags = NLM_F_DUMP;
56f77852
JM
1882 if (!(msg = nl80211_cmd_msg(bss, nl_flags, NL80211_CMD_GET_WIPHY)) ||
1883 nla_put_flag(msg, NL80211_ATTR_SPLIT_WIPHY_DUMP)) {
9589a91e
JM
1884 nlmsg_free(msg);
1885 return NULL;
1886 }
0fafeb54
JM
1887
1888 if (send_and_recv_msgs(drv, msg, phy_info_handler, &result) == 0) {
1889 nl80211_set_regulatory_flags(drv, &result);
747ba106
JM
1890 if (result.failed) {
1891 int i;
1892
1893 for (i = 0; result.modes && i < *num_modes; i++) {
1894 os_free(result.modes[i].channels);
1895 os_free(result.modes[i].rates);
1896 }
1897 os_free(result.modes);
517b5f92 1898 *num_modes = 0;
747ba106
JM
1899 return NULL;
1900 }
0fafeb54
JM
1901 return wpa_driver_nl80211_postprocess_modes(result.modes,
1902 num_modes);
1903 }
9589a91e 1904
0fafeb54
JM
1905 return NULL;
1906}