1 /*
2 * Driver interaction with Linux nl80211/cfg80211 - Capabilities
3 * Copyright (c) 2002-2015, Jouni Malinen <j@w1.fi>
4 * Copyright (c) 2007, Johannes Berg <johannes@sipsolutions.net>
5 * Copyright (c) 2009-2010, Atheros Communications
6 *
7 * This software may be distributed under the terms of the BSD license.
8 * See README for more details.
9 */
10
11 #include "includes.h"
12 #include <netlink/genl/genl.h>
13
14 #include "utils/common.h"
15 #include "common/ieee802_11_common.h"
16 #include "common/wpa_common.h"
17 #include "common/qca-vendor.h"
18 #include "common/qca-vendor-attr.h"
19 #include "driver_nl80211.h"
20
21
protocol_feature_handler(struct nl_msg * msg,void * arg)22 static 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
get_nl80211_protocol_features(struct wpa_driver_nl80211_data * drv)38 static 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)
45 return 0;
46
47 if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_PROTOCOL_FEATURES)) {
48 nlmsg_free(msg);
49 return 0;
50 }
51
52 if (send_and_recv_msgs(drv, msg, protocol_feature_handler, &feat) == 0)
53 return feat;
54
55 return 0;
56 }
57
58
59 struct 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;
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;
73 unsigned int p2p_go_ctwindow_supported:1;
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;
78 unsigned int wmm_ac_supported:1;
79 unsigned int mac_addr_rand_scan_supported:1;
80 unsigned int mac_addr_rand_sched_scan_supported:1;
81 };
82
83
probe_resp_offload_support(int supp_protocols)84 static 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
wiphy_info_supported_iftypes(struct wiphy_info_data * info,struct nlattr * tb)101 static 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;
131 }
132 }
133 }
134
135
wiphy_info_iface_comb_process(struct wiphy_info_data * info,struct nlattr * nl_combi)136 static 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
wiphy_info_iface_comb(struct wiphy_info_data * info,struct nlattr * tb)201 static 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
wiphy_info_supp_cmds(struct wiphy_info_data * info,struct nlattr * tb)217 static 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
wiphy_info_cipher_suites(struct wiphy_info_data * info,struct nlattr * tb)251 static 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 RSN_CIPHER_SUITE_CCMP_256:
270 info->capa->enc |= WPA_DRIVER_CAPA_ENC_CCMP_256;
271 break;
272 case RSN_CIPHER_SUITE_GCMP_256:
273 info->capa->enc |= WPA_DRIVER_CAPA_ENC_GCMP_256;
274 break;
275 case RSN_CIPHER_SUITE_CCMP:
276 info->capa->enc |= WPA_DRIVER_CAPA_ENC_CCMP;
277 break;
278 case RSN_CIPHER_SUITE_GCMP:
279 info->capa->enc |= WPA_DRIVER_CAPA_ENC_GCMP;
280 break;
281 case RSN_CIPHER_SUITE_TKIP:
282 info->capa->enc |= WPA_DRIVER_CAPA_ENC_TKIP;
283 break;
284 case RSN_CIPHER_SUITE_WEP104:
285 info->capa->enc |= WPA_DRIVER_CAPA_ENC_WEP104;
286 break;
287 case RSN_CIPHER_SUITE_WEP40:
288 info->capa->enc |= WPA_DRIVER_CAPA_ENC_WEP40;
289 break;
290 case RSN_CIPHER_SUITE_AES_128_CMAC:
291 info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP;
292 break;
293 case RSN_CIPHER_SUITE_BIP_GMAC_128:
294 info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP_GMAC_128;
295 break;
296 case RSN_CIPHER_SUITE_BIP_GMAC_256:
297 info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP_GMAC_256;
298 break;
299 case RSN_CIPHER_SUITE_BIP_CMAC_256:
300 info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP_CMAC_256;
301 break;
302 case RSN_CIPHER_SUITE_NO_GROUP_ADDRESSED:
303 info->capa->enc |= WPA_DRIVER_CAPA_ENC_GTK_NOT_USED;
304 break;
305 }
306 }
307 }
308
309
wiphy_info_max_roc(struct wpa_driver_capa * capa,struct nlattr * tb)310 static 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
wiphy_info_tdls(struct wpa_driver_capa * capa,struct nlattr * tdls,struct nlattr * ext_setup)318 static 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
ext_feature_isset(const u8 * ext_features,int ext_features_len,enum nl80211_ext_feature_index ftidx)334 static 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
wiphy_info_ext_feature_flags(struct wiphy_info_data * info,struct nlattr * tb)347 static void wiphy_info_ext_feature_flags(struct wiphy_info_data *info,
348 struct nlattr *tb)
349 {
350 struct wpa_driver_capa *capa = info->capa;
351 u8 *ext_features;
352 int len;
353
354 if (tb == NULL)
355 return;
356
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))
361 capa->flags |= WPA_DRIVER_FLAGS_VHT_IBSS;
362
363 if (ext_feature_isset(ext_features, len, NL80211_EXT_FEATURE_RRM))
364 capa->rrm_flags |= WPA_DRIVER_FLAGS_SUPPORT_RRM;
365
366 if (ext_feature_isset(ext_features, len, NL80211_EXT_FEATURE_FILS_STA))
367 capa->flags |= WPA_DRIVER_FLAGS_SUPPORT_FILS;
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;
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;
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;
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;
401 if (ext_feature_isset(ext_features, len,
402 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD))
403 capa->flags |= WPA_DRIVER_FLAGS_FILS_SK_OFFLOAD;
404
405 if (ext_feature_isset(ext_features, len,
406 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK))
407 capa->flags |= WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK;
408 if (ext_feature_isset(ext_features, len,
409 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
410 capa->flags |= WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X;
411
412 if (ext_feature_isset(ext_features, len,
413 NL80211_EXT_FEATURE_MFP_OPTIONAL))
414 capa->flags |= WPA_DRIVER_FLAGS_MFP_OPTIONAL;
415
416 if (ext_feature_isset(ext_features, len,
417 NL80211_EXT_FEATURE_DFS_OFFLOAD))
418 capa->flags |= WPA_DRIVER_FLAGS_DFS_OFFLOAD;
419
420 #ifdef CONFIG_MBO
421 if (ext_feature_isset(ext_features, len,
422 NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME) &&
423 ext_feature_isset(ext_features, len,
424 NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP) &&
425 ext_feature_isset(ext_features, len,
426 NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE) &&
427 ext_feature_isset(
428 ext_features, len,
429 NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION))
430 capa->flags |= WPA_DRIVER_FLAGS_OCE_STA;
431 #endif /* CONFIG_MBO */
432
433 if (ext_feature_isset(ext_features, len,
434 NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER))
435 capa->flags |= WPA_DRIVER_FLAGS_FTM_RESPONDER;
436 }
437
438
wiphy_info_feature_flags(struct wiphy_info_data * info,struct nlattr * tb)439 static void wiphy_info_feature_flags(struct wiphy_info_data *info,
440 struct nlattr *tb)
441 {
442 u32 flags;
443 struct wpa_driver_capa *capa = info->capa;
444
445 if (tb == NULL)
446 return;
447
448 flags = nla_get_u32(tb);
449
450 if (flags & NL80211_FEATURE_SK_TX_STATUS)
451 info->data_tx_status = 1;
452
453 if (flags & NL80211_FEATURE_INACTIVITY_TIMER)
454 capa->flags |= WPA_DRIVER_FLAGS_INACTIVITY_TIMER;
455
456 if (flags & NL80211_FEATURE_SAE)
457 capa->flags |= WPA_DRIVER_FLAGS_SAE;
458
459 if (flags & NL80211_FEATURE_NEED_OBSS_SCAN)
460 capa->flags |= WPA_DRIVER_FLAGS_OBSS_SCAN;
461
462 if (flags & NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)
463 capa->flags |= WPA_DRIVER_FLAGS_HT_2040_COEX;
464
465 if (flags & NL80211_FEATURE_TDLS_CHANNEL_SWITCH) {
466 wpa_printf(MSG_DEBUG, "nl80211: TDLS channel switch");
467 capa->flags |= WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH;
468 }
469
470 if (flags & NL80211_FEATURE_P2P_GO_CTWIN)
471 info->p2p_go_ctwindow_supported = 1;
472
473 if (flags & NL80211_FEATURE_LOW_PRIORITY_SCAN)
474 info->have_low_prio_scan = 1;
475
476 if (flags & NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)
477 info->mac_addr_rand_scan_supported = 1;
478
479 if (flags & NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR)
480 info->mac_addr_rand_sched_scan_supported = 1;
481
482 if (flags & NL80211_FEATURE_STATIC_SMPS)
483 capa->smps_modes |= WPA_DRIVER_SMPS_MODE_STATIC;
484
485 if (flags & NL80211_FEATURE_DYNAMIC_SMPS)
486 capa->smps_modes |= WPA_DRIVER_SMPS_MODE_DYNAMIC;
487
488 if (flags & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
489 info->wmm_ac_supported = 1;
490
491 if (flags & NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES)
492 capa->rrm_flags |= WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES;
493
494 if (flags & NL80211_FEATURE_WFA_TPC_IE_IN_PROBES)
495 capa->rrm_flags |= WPA_DRIVER_FLAGS_WFA_TPC_IE_IN_PROBES;
496
497 if (flags & NL80211_FEATURE_QUIET)
498 capa->rrm_flags |= WPA_DRIVER_FLAGS_QUIET;
499
500 if (flags & NL80211_FEATURE_TX_POWER_INSERTION)
501 capa->rrm_flags |= WPA_DRIVER_FLAGS_TX_POWER_INSERTION;
502
503 if (flags & NL80211_FEATURE_HT_IBSS)
504 capa->flags |= WPA_DRIVER_FLAGS_HT_IBSS;
505
506 if (flags & NL80211_FEATURE_FULL_AP_CLIENT_STATE)
507 capa->flags |= WPA_DRIVER_FLAGS_FULL_AP_CLIENT_STATE;
508 }
509
510
wiphy_info_probe_resp_offload(struct wpa_driver_capa * capa,struct nlattr * tb)511 static void wiphy_info_probe_resp_offload(struct wpa_driver_capa *capa,
512 struct nlattr *tb)
513 {
514 u32 protocols;
515
516 if (tb == NULL)
517 return;
518
519 protocols = nla_get_u32(tb);
520 wpa_printf(MSG_DEBUG, "nl80211: Supports Probe Response offload in AP "
521 "mode");
522 capa->flags |= WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD;
523 capa->probe_resp_offloads = probe_resp_offload_support(protocols);
524 }
525
526
wiphy_info_wowlan_triggers(struct wpa_driver_capa * capa,struct nlattr * tb)527 static void wiphy_info_wowlan_triggers(struct wpa_driver_capa *capa,
528 struct nlattr *tb)
529 {
530 struct nlattr *triggers[MAX_NL80211_WOWLAN_TRIG + 1];
531
532 if (tb == NULL)
533 return;
534
535 if (nla_parse_nested(triggers, MAX_NL80211_WOWLAN_TRIG,
536 tb, NULL))
537 return;
538
539 if (triggers[NL80211_WOWLAN_TRIG_ANY])
540 capa->wowlan_triggers.any = 1;
541 if (triggers[NL80211_WOWLAN_TRIG_DISCONNECT])
542 capa->wowlan_triggers.disconnect = 1;
543 if (triggers[NL80211_WOWLAN_TRIG_MAGIC_PKT])
544 capa->wowlan_triggers.magic_pkt = 1;
545 if (triggers[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE])
546 capa->wowlan_triggers.gtk_rekey_failure = 1;
547 if (triggers[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST])
548 capa->wowlan_triggers.eap_identity_req = 1;
549 if (triggers[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE])
550 capa->wowlan_triggers.four_way_handshake = 1;
551 if (triggers[NL80211_WOWLAN_TRIG_RFKILL_RELEASE])
552 capa->wowlan_triggers.rfkill_release = 1;
553 }
554
555
wiphy_info_extended_capab(struct wpa_driver_nl80211_data * drv,struct nlattr * tb)556 static void wiphy_info_extended_capab(struct wpa_driver_nl80211_data *drv,
557 struct nlattr *tb)
558 {
559 int rem = 0, i;
560 struct nlattr *tb1[NL80211_ATTR_MAX + 1], *attr;
561
562 if (!tb || drv->num_iface_ext_capa == NL80211_IFTYPE_MAX)
563 return;
564
565 nla_for_each_nested(attr, tb, rem) {
566 unsigned int len;
567 struct drv_nl80211_ext_capa *capa;
568
569 nla_parse(tb1, NL80211_ATTR_MAX, nla_data(attr),
570 nla_len(attr), NULL);
571
572 if (!tb1[NL80211_ATTR_IFTYPE] ||
573 !tb1[NL80211_ATTR_EXT_CAPA] ||
574 !tb1[NL80211_ATTR_EXT_CAPA_MASK])
575 continue;
576
577 capa = &drv->iface_ext_capa[drv->num_iface_ext_capa];
578 capa->iftype = nla_get_u32(tb1[NL80211_ATTR_IFTYPE]);
579 wpa_printf(MSG_DEBUG,
580 "nl80211: Driver-advertised extended capabilities for interface type %s",
581 nl80211_iftype_str(capa->iftype));
582
583 len = nla_len(tb1[NL80211_ATTR_EXT_CAPA]);
584 capa->ext_capa = os_memdup(nla_data(tb1[NL80211_ATTR_EXT_CAPA]),
585 len);
586 if (!capa->ext_capa)
587 goto err;
588
589 capa->ext_capa_len = len;
590 wpa_hexdump(MSG_DEBUG, "nl80211: Extended capabilities",
591 capa->ext_capa, capa->ext_capa_len);
592
593 len = nla_len(tb1[NL80211_ATTR_EXT_CAPA_MASK]);
594 capa->ext_capa_mask =
595 os_memdup(nla_data(tb1[NL80211_ATTR_EXT_CAPA_MASK]),
596 len);
597 if (!capa->ext_capa_mask)
598 goto err;
599
600 wpa_hexdump(MSG_DEBUG, "nl80211: Extended capabilities mask",
601 capa->ext_capa_mask, capa->ext_capa_len);
602
603 drv->num_iface_ext_capa++;
604 if (drv->num_iface_ext_capa == NL80211_IFTYPE_MAX)
605 break;
606 }
607
608 return;
609
610 err:
611 /* Cleanup allocated memory on error */
612 for (i = 0; i < NL80211_IFTYPE_MAX; i++) {
613 os_free(drv->iface_ext_capa[i].ext_capa);
614 drv->iface_ext_capa[i].ext_capa = NULL;
615 os_free(drv->iface_ext_capa[i].ext_capa_mask);
616 drv->iface_ext_capa[i].ext_capa_mask = NULL;
617 drv->iface_ext_capa[i].ext_capa_len = 0;
618 }
619 drv->num_iface_ext_capa = 0;
620 }
621
622
wiphy_info_handler(struct nl_msg * msg,void * arg)623 static int wiphy_info_handler(struct nl_msg *msg, void *arg)
624 {
625 struct nlattr *tb[NL80211_ATTR_MAX + 1];
626 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
627 struct wiphy_info_data *info = arg;
628 struct wpa_driver_capa *capa = info->capa;
629 struct wpa_driver_nl80211_data *drv = info->drv;
630
631 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
632 genlmsg_attrlen(gnlh, 0), NULL);
633
634 if (tb[NL80211_ATTR_WIPHY])
635 drv->wiphy_idx = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
636
637 if (tb[NL80211_ATTR_WIPHY_NAME])
638 os_strlcpy(drv->phyname,
639 nla_get_string(tb[NL80211_ATTR_WIPHY_NAME]),
640 sizeof(drv->phyname));
641 if (tb[NL80211_ATTR_MAX_NUM_SCAN_SSIDS])
642 capa->max_scan_ssids =
643 nla_get_u8(tb[NL80211_ATTR_MAX_NUM_SCAN_SSIDS]);
644
645 if (tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS])
646 capa->max_sched_scan_ssids =
647 nla_get_u8(tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS]);
648
649 if (tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS] &&
650 tb[NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL] &&
651 tb[NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS]) {
652 capa->max_sched_scan_plans =
653 nla_get_u32(tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS]);
654
655 capa->max_sched_scan_plan_interval =
656 nla_get_u32(tb[NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL]);
657
658 capa->max_sched_scan_plan_iterations =
659 nla_get_u32(tb[NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS]);
660 }
661
662 if (tb[NL80211_ATTR_MAX_MATCH_SETS])
663 capa->max_match_sets =
664 nla_get_u8(tb[NL80211_ATTR_MAX_MATCH_SETS]);
665
666 if (tb[NL80211_ATTR_MAC_ACL_MAX])
667 capa->max_acl_mac_addrs =
668 nla_get_u8(tb[NL80211_ATTR_MAC_ACL_MAX]);
669
670 wiphy_info_supported_iftypes(info, tb[NL80211_ATTR_SUPPORTED_IFTYPES]);
671 wiphy_info_iface_comb(info, tb[NL80211_ATTR_INTERFACE_COMBINATIONS]);
672 wiphy_info_supp_cmds(info, tb[NL80211_ATTR_SUPPORTED_COMMANDS]);
673 wiphy_info_cipher_suites(info, tb[NL80211_ATTR_CIPHER_SUITES]);
674
675 if (tb[NL80211_ATTR_OFFCHANNEL_TX_OK]) {
676 wpa_printf(MSG_DEBUG, "nl80211: Using driver-based "
677 "off-channel TX");
678 capa->flags |= WPA_DRIVER_FLAGS_OFFCHANNEL_TX;
679 }
680
681 if (tb[NL80211_ATTR_ROAM_SUPPORT]) {
682 wpa_printf(MSG_DEBUG, "nl80211: Using driver-based roaming");
683 capa->flags |= WPA_DRIVER_FLAGS_BSS_SELECTION;
684 }
685
686 wiphy_info_max_roc(capa,
687 tb[NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION]);
688
689 if (tb[NL80211_ATTR_SUPPORT_AP_UAPSD])
690 capa->flags |= WPA_DRIVER_FLAGS_AP_UAPSD;
691
692 wiphy_info_tdls(capa, tb[NL80211_ATTR_TDLS_SUPPORT],
693 tb[NL80211_ATTR_TDLS_EXTERNAL_SETUP]);
694
695 if (tb[NL80211_ATTR_DEVICE_AP_SME])
696 info->device_ap_sme = 1;
697
698 wiphy_info_feature_flags(info, tb[NL80211_ATTR_FEATURE_FLAGS]);
699 wiphy_info_ext_feature_flags(info, tb[NL80211_ATTR_EXT_FEATURES]);
700 wiphy_info_probe_resp_offload(capa,
701 tb[NL80211_ATTR_PROBE_RESP_OFFLOAD]);
702
703 if (tb[NL80211_ATTR_EXT_CAPA] && tb[NL80211_ATTR_EXT_CAPA_MASK] &&
704 drv->extended_capa == NULL) {
705 drv->extended_capa =
706 os_malloc(nla_len(tb[NL80211_ATTR_EXT_CAPA]));
707 if (drv->extended_capa) {
708 os_memcpy(drv->extended_capa,
709 nla_data(tb[NL80211_ATTR_EXT_CAPA]),
710 nla_len(tb[NL80211_ATTR_EXT_CAPA]));
711 drv->extended_capa_len =
712 nla_len(tb[NL80211_ATTR_EXT_CAPA]);
713 wpa_hexdump(MSG_DEBUG,
714 "nl80211: Driver-advertised extended capabilities (default)",
715 drv->extended_capa, drv->extended_capa_len);
716 }
717 drv->extended_capa_mask =
718 os_malloc(nla_len(tb[NL80211_ATTR_EXT_CAPA_MASK]));
719 if (drv->extended_capa_mask) {
720 os_memcpy(drv->extended_capa_mask,
721 nla_data(tb[NL80211_ATTR_EXT_CAPA_MASK]),
722 nla_len(tb[NL80211_ATTR_EXT_CAPA_MASK]));
723 wpa_hexdump(MSG_DEBUG,
724 "nl80211: Driver-advertised extended capabilities mask (default)",
725 drv->extended_capa_mask,
726 drv->extended_capa_len);
727 } else {
728 os_free(drv->extended_capa);
729 drv->extended_capa = NULL;
730 drv->extended_capa_len = 0;
731 }
732 }
733
734 wiphy_info_extended_capab(drv, tb[NL80211_ATTR_IFTYPE_EXT_CAPA]);
735
736 if (tb[NL80211_ATTR_VENDOR_DATA]) {
737 struct nlattr *nl;
738 int rem;
739
740 nla_for_each_nested(nl, tb[NL80211_ATTR_VENDOR_DATA], rem) {
741 struct nl80211_vendor_cmd_info *vinfo;
742 if (nla_len(nl) != sizeof(*vinfo)) {
743 wpa_printf(MSG_DEBUG, "nl80211: Unexpected vendor data info");
744 continue;
745 }
746 vinfo = nla_data(nl);
747 if (vinfo->vendor_id == OUI_QCA) {
748 switch (vinfo->subcmd) {
749 case QCA_NL80211_VENDOR_SUBCMD_TEST:
750 drv->vendor_cmd_test_avail = 1;
751 break;
752 #ifdef CONFIG_DRIVER_NL80211_QCA
753 case QCA_NL80211_VENDOR_SUBCMD_ROAMING:
754 drv->roaming_vendor_cmd_avail = 1;
755 break;
756 case QCA_NL80211_VENDOR_SUBCMD_DFS_CAPABILITY:
757 drv->dfs_vendor_cmd_avail = 1;
758 break;
759 case QCA_NL80211_VENDOR_SUBCMD_GET_FEATURES:
760 drv->get_features_vendor_cmd_avail = 1;
761 break;
762 case QCA_NL80211_VENDOR_SUBCMD_GET_PREFERRED_FREQ_LIST:
763 drv->get_pref_freq_list = 1;
764 break;
765 case QCA_NL80211_VENDOR_SUBCMD_SET_PROBABLE_OPER_CHANNEL:
766 drv->set_prob_oper_freq = 1;
767 break;
768 case QCA_NL80211_VENDOR_SUBCMD_DO_ACS:
769 drv->capa.flags |=
770 WPA_DRIVER_FLAGS_ACS_OFFLOAD;
771 break;
772 case QCA_NL80211_VENDOR_SUBCMD_SETBAND:
773 drv->setband_vendor_cmd_avail = 1;
774 break;
775 case QCA_NL80211_VENDOR_SUBCMD_TRIGGER_SCAN:
776 drv->scan_vendor_cmd_avail = 1;
777 break;
778 case QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION:
779 drv->set_wifi_conf_vendor_cmd_avail = 1;
780 break;
781 case QCA_NL80211_VENDOR_SUBCMD_GET_HE_CAPABILITIES:
782 drv->he_capab_vendor_cmd_avail = 1;
783 break;
784 case QCA_NL80211_VENDOR_SUBCMD_FETCH_BSS_TRANSITION_STATUS:
785 drv->fetch_bss_trans_status = 1;
786 break;
787 case QCA_NL80211_VENDOR_SUBCMD_ROAM:
788 drv->roam_vendor_cmd_avail = 1;
789 break;
790 case QCA_NL80211_VENDOR_SUBCMD_GET_SUPPORTED_AKMS:
791 drv->get_supported_akm_suites_avail = 1;
792 break;
793 #endif /* CONFIG_DRIVER_NL80211_QCA */
794 }
795 }
796
797 wpa_printf(MSG_DEBUG, "nl80211: Supported vendor command: vendor_id=0x%x subcmd=%u",
798 vinfo->vendor_id, vinfo->subcmd);
799 }
800 }
801
802 if (tb[NL80211_ATTR_VENDOR_EVENTS]) {
803 struct nlattr *nl;
804 int rem;
805
806 nla_for_each_nested(nl, tb[NL80211_ATTR_VENDOR_EVENTS], rem) {
807 struct nl80211_vendor_cmd_info *vinfo;
808 if (nla_len(nl) != sizeof(*vinfo)) {
809 wpa_printf(MSG_DEBUG, "nl80211: Unexpected vendor data info");
810 continue;
811 }
812 vinfo = nla_data(nl);
813 wpa_printf(MSG_DEBUG, "nl80211: Supported vendor event: vendor_id=0x%x subcmd=%u",
814 vinfo->vendor_id, vinfo->subcmd);
815 }
816 }
817
818 wiphy_info_wowlan_triggers(capa,
819 tb[NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED]);
820
821 if (tb[NL80211_ATTR_MAX_AP_ASSOC_STA])
822 capa->max_stations =
823 nla_get_u32(tb[NL80211_ATTR_MAX_AP_ASSOC_STA]);
824
825 if (tb[NL80211_ATTR_MAX_CSA_COUNTERS])
826 capa->max_csa_counters =
827 nla_get_u8(tb[NL80211_ATTR_MAX_CSA_COUNTERS]);
828
829 if (tb[NL80211_ATTR_WIPHY_SELF_MANAGED_REG])
830 capa->flags |= WPA_DRIVER_FLAGS_SELF_MANAGED_REGULATORY;
831
832 return NL_SKIP;
833 }
834
835
wpa_driver_nl80211_get_info(struct wpa_driver_nl80211_data * drv,struct wiphy_info_data * info)836 static int wpa_driver_nl80211_get_info(struct wpa_driver_nl80211_data *drv,
837 struct wiphy_info_data *info)
838 {
839 u32 feat;
840 struct nl_msg *msg;
841 int flags = 0;
842
843 os_memset(info, 0, sizeof(*info));
844 info->capa = &drv->capa;
845 info->drv = drv;
846
847 feat = get_nl80211_protocol_features(drv);
848 if (feat & NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)
849 flags = NLM_F_DUMP;
850 msg = nl80211_cmd_msg(drv->first_bss, flags, NL80211_CMD_GET_WIPHY);
851 if (!msg || nla_put_flag(msg, NL80211_ATTR_SPLIT_WIPHY_DUMP)) {
852 nlmsg_free(msg);
853 return -1;
854 }
855
856 if (send_and_recv_msgs(drv, msg, wiphy_info_handler, info))
857 return -1;
858
859 if (info->auth_supported)
860 drv->capa.flags |= WPA_DRIVER_FLAGS_SME;
861 else if (!info->connect_supported) {
862 wpa_printf(MSG_INFO, "nl80211: Driver does not support "
863 "authentication/association or connect commands");
864 info->error = 1;
865 }
866
867 if (info->p2p_go_supported && info->p2p_client_supported)
868 drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CAPABLE;
869 if (info->p2p_concurrent) {
870 wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group "
871 "interface (driver advertised support)");
872 drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT;
873 drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P;
874 }
875 if (info->num_multichan_concurrent > 1) {
876 wpa_printf(MSG_DEBUG, "nl80211: Enable multi-channel "
877 "concurrent (driver advertised support)");
878 drv->capa.num_multichan_concurrent =
879 info->num_multichan_concurrent;
880 }
881 if (drv->capa.flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)
882 wpa_printf(MSG_DEBUG, "nl80211: use P2P_DEVICE support");
883
884 /* default to 5000 since early versions of mac80211 don't set it */
885 if (!drv->capa.max_remain_on_chan)
886 drv->capa.max_remain_on_chan = 5000;
887
888 drv->capa.wmm_ac_supported = info->wmm_ac_supported;
889
890 drv->capa.mac_addr_rand_sched_scan_supported =
891 info->mac_addr_rand_sched_scan_supported;
892 drv->capa.mac_addr_rand_scan_supported =
893 info->mac_addr_rand_scan_supported;
894
895 if (info->channel_switch_supported) {
896 drv->capa.flags |= WPA_DRIVER_FLAGS_AP_CSA;
897 if (!drv->capa.max_csa_counters)
898 drv->capa.max_csa_counters = 1;
899 }
900
901 if (!drv->capa.max_sched_scan_plans) {
902 drv->capa.max_sched_scan_plans = 1;
903 drv->capa.max_sched_scan_plan_interval = UINT32_MAX;
904 drv->capa.max_sched_scan_plan_iterations = 0;
905 }
906
907 return 0;
908 }
909
910
911 #ifdef CONFIG_DRIVER_NL80211_QCA
912
dfs_info_handler(struct nl_msg * msg,void * arg)913 static int dfs_info_handler(struct nl_msg *msg, void *arg)
914 {
915 struct nlattr *tb[NL80211_ATTR_MAX + 1];
916 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
917 int *dfs_capability_ptr = arg;
918
919 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
920 genlmsg_attrlen(gnlh, 0), NULL);
921
922 if (tb[NL80211_ATTR_VENDOR_DATA]) {
923 struct nlattr *nl_vend = tb[NL80211_ATTR_VENDOR_DATA];
924 struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1];
925
926 nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX,
927 nla_data(nl_vend), nla_len(nl_vend), NULL);
928
929 if (tb_vendor[QCA_WLAN_VENDOR_ATTR_DFS]) {
930 u32 val;
931 val = nla_get_u32(tb_vendor[QCA_WLAN_VENDOR_ATTR_DFS]);
932 wpa_printf(MSG_DEBUG, "nl80211: DFS offload capability: %u",
933 val);
934 *dfs_capability_ptr = val;
935 }
936 }
937
938 return NL_SKIP;
939 }
940
941
qca_nl80211_check_dfs_capa(struct wpa_driver_nl80211_data * drv)942 static void qca_nl80211_check_dfs_capa(struct wpa_driver_nl80211_data *drv)
943 {
944 struct nl_msg *msg;
945 int dfs_capability = 0;
946 int ret;
947
948 if (!drv->dfs_vendor_cmd_avail)
949 return;
950
951 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
952 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
953 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
954 QCA_NL80211_VENDOR_SUBCMD_DFS_CAPABILITY)) {
955 nlmsg_free(msg);
956 return;
957 }
958
959 ret = send_and_recv_msgs(drv, msg, dfs_info_handler, &dfs_capability);
960 if (!ret && dfs_capability)
961 drv->capa.flags |= WPA_DRIVER_FLAGS_DFS_OFFLOAD;
962 }
963
964
get_akm_suites_info(struct nlattr * tb)965 static unsigned int get_akm_suites_info(struct nlattr *tb)
966 {
967 int i, num;
968 unsigned int key_mgmt = 0;
969 u32 *akms;
970
971 if (!tb)
972 return 0;
973
974 num = nla_len(tb) / sizeof(u32);
975 akms = nla_data(tb);
976 for (i = 0; i < num; i++) {
977 u32 a = akms[i];
978
979 wpa_printf(MSG_DEBUG,
980 "nl80211: Supported AKM %02x-%02x-%02x:%u",
981 a >> 24, (a >> 16) & 0xff,
982 (a >> 8) & 0xff, a & 0xff);
983 switch (a) {
984 case RSN_AUTH_KEY_MGMT_UNSPEC_802_1X:
985 key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_WPA |
986 WPA_DRIVER_CAPA_KEY_MGMT_WPA2;
987 break;
988 case RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X:
989 key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
990 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK;
991 break;
992 case RSN_AUTH_KEY_MGMT_FT_802_1X:
993 key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT;
994 break;
995 case RSN_AUTH_KEY_MGMT_FT_PSK:
996 key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK;
997 break;
998 case RSN_AUTH_KEY_MGMT_802_1X_SUITE_B:
999 key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B;
1000 break;
1001 case RSN_AUTH_KEY_MGMT_802_1X_SUITE_B_192:
1002 key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192;
1003 break;
1004 case RSN_AUTH_KEY_MGMT_OWE:
1005 key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_OWE;
1006 break;
1007 case RSN_AUTH_KEY_MGMT_DPP:
1008 key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_DPP;
1009 break;
1010 case RSN_AUTH_KEY_MGMT_FILS_SHA256:
1011 key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA256;
1012 break;
1013 case RSN_AUTH_KEY_MGMT_FILS_SHA384:
1014 key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA384;
1015 break;
1016 case RSN_AUTH_KEY_MGMT_FT_FILS_SHA256:
1017 key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA256;
1018 break;
1019 case RSN_AUTH_KEY_MGMT_FT_FILS_SHA384:
1020 key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA384;
1021 break;
1022 case RSN_AUTH_KEY_MGMT_SAE:
1023 key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_SAE;
1024 break;
1025 }
1026 }
1027
1028 return key_mgmt;
1029 }
1030
1031
get_akm_suites_handler(struct nl_msg * msg,void * arg)1032 static int get_akm_suites_handler(struct nl_msg *msg, void *arg)
1033 {
1034 struct nlattr *tb[NL80211_ATTR_MAX + 1];
1035 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1036 unsigned int *key_mgmt = arg;
1037
1038 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1039 genlmsg_attrlen(gnlh, 0), NULL);
1040
1041 if (tb[NL80211_ATTR_VENDOR_DATA]) {
1042 struct nlattr *nl_vend = tb[NL80211_ATTR_VENDOR_DATA];
1043 struct nlattr *tb_data[NL80211_ATTR_MAX + 1];
1044
1045 nla_parse(tb_data, NL80211_ATTR_MAX,
1046 nla_data(nl_vend), nla_len(nl_vend), NULL);
1047
1048 *key_mgmt =
1049 get_akm_suites_info(tb_data[NL80211_ATTR_AKM_SUITES]);
1050 }
1051
1052 return NL_SKIP;
1053 }
1054
1055
qca_nl80211_get_akm_suites(struct wpa_driver_nl80211_data * drv)1056 static int qca_nl80211_get_akm_suites(struct wpa_driver_nl80211_data *drv)
1057 {
1058 struct nl_msg *msg;
1059 unsigned int key_mgmt = 0;
1060 int ret;
1061
1062 if (!drv->get_supported_akm_suites_avail)
1063 return -1;
1064
1065 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
1066 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
1067 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
1068 QCA_NL80211_VENDOR_SUBCMD_GET_SUPPORTED_AKMS)) {
1069 nlmsg_free(msg);
1070 return -1;
1071 }
1072
1073 ret = send_and_recv_msgs(drv, msg, get_akm_suites_handler, &key_mgmt);
1074 if (!ret) {
1075 wpa_printf(MSG_DEBUG,
1076 "nl80211: Replace capa.key_mgmt based on driver advertised capabilities: 0x%x",
1077 key_mgmt);
1078 drv->capa.key_mgmt = key_mgmt;
1079 }
1080
1081 return ret;
1082 }
1083
1084
qca_nl80211_he_capab_handler(struct nl_msg * msg,void * arg)1085 static int qca_nl80211_he_capab_handler(struct nl_msg *msg, void *arg)
1086 {
1087 struct nlattr *tb[NL80211_ATTR_MAX + 1];
1088 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1089 struct he_capabilities *he_capab = arg;
1090 struct nlattr *nl_vend;
1091 struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_HE_CAPABILITIES_MAX + 1];
1092 size_t len;
1093
1094 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1095 genlmsg_attrlen(gnlh, 0), NULL);
1096
1097 if (!tb[NL80211_ATTR_VENDOR_DATA])
1098 return NL_SKIP;
1099
1100 nl_vend = tb[NL80211_ATTR_VENDOR_DATA];
1101 nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_HE_CAPABILITIES_MAX,
1102 nla_data(nl_vend), nla_len(nl_vend), NULL);
1103
1104 if (tb_vendor[QCA_WLAN_VENDOR_ATTR_HE_SUPPORTED]) {
1105 u8 he_supported;
1106
1107 he_supported = nla_get_u8(
1108 tb_vendor[QCA_WLAN_VENDOR_ATTR_HE_SUPPORTED]);
1109 wpa_printf(MSG_DEBUG, "nl80211: HE capabilities supported: %u",
1110 he_supported);
1111 he_capab->he_supported = he_supported;
1112 if (!he_supported)
1113 return NL_SKIP;
1114 }
1115
1116 if (tb_vendor[QCA_WLAN_VENDOR_ATTR_PHY_CAPAB]) {
1117 len = nla_len(tb_vendor[QCA_WLAN_VENDOR_ATTR_PHY_CAPAB]);
1118
1119 if (len > sizeof(he_capab->phy_cap))
1120 len = sizeof(he_capab->phy_cap);
1121 os_memcpy(he_capab->phy_cap,
1122 nla_data(tb_vendor[QCA_WLAN_VENDOR_ATTR_PHY_CAPAB]),
1123 len);
1124 }
1125
1126 if (tb_vendor[QCA_WLAN_VENDOR_ATTR_MAC_CAPAB])
1127 he_capab->mac_cap =
1128 nla_get_u32(tb_vendor[QCA_WLAN_VENDOR_ATTR_MAC_CAPAB]);
1129
1130 if (tb_vendor[QCA_WLAN_VENDOR_ATTR_HE_MCS])
1131 he_capab->mcs =
1132 nla_get_u32(tb_vendor[QCA_WLAN_VENDOR_ATTR_HE_MCS]);
1133
1134 if (tb_vendor[QCA_WLAN_VENDOR_ATTR_NUM_SS])
1135 he_capab->ppet.numss_m1 =
1136 nla_get_u32(tb_vendor[QCA_WLAN_VENDOR_ATTR_NUM_SS]);
1137
1138 if (tb_vendor[QCA_WLAN_VENDOR_ATTR_RU_IDX_MASK])
1139 he_capab->ppet.ru_count =
1140 nla_get_u32(tb_vendor[QCA_WLAN_VENDOR_ATTR_RU_IDX_MASK]);
1141
1142 if (tb_vendor[QCA_WLAN_VENDOR_ATTR_PPE_THRESHOLD]) {
1143 len = nla_len(tb_vendor[QCA_WLAN_VENDOR_ATTR_PPE_THRESHOLD]);
1144
1145 if (len > sizeof(he_capab->ppet.ppet16_ppet8_ru3_ru0))
1146 len = sizeof(he_capab->ppet.ppet16_ppet8_ru3_ru0);
1147 os_memcpy(he_capab->ppet.ppet16_ppet8_ru3_ru0,
1148 nla_data(tb_vendor[QCA_WLAN_VENDOR_ATTR_PPE_THRESHOLD]),
1149 len);
1150 }
1151
1152 return NL_SKIP;
1153 }
1154
1155
qca_nl80211_check_he_capab(struct wpa_driver_nl80211_data * drv)1156 static void qca_nl80211_check_he_capab(struct wpa_driver_nl80211_data *drv)
1157 {
1158 struct nl_msg *msg;
1159 int ret;
1160
1161 if (!drv->he_capab_vendor_cmd_avail)
1162 return;
1163
1164 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
1165 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
1166 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
1167 QCA_NL80211_VENDOR_SUBCMD_GET_HE_CAPABILITIES)) {
1168 nlmsg_free(msg);
1169 return;
1170 }
1171
1172 ret = send_and_recv_msgs(drv, msg, qca_nl80211_he_capab_handler,
1173 &drv->he_capab);
1174 if (!ret && drv->he_capab.he_supported)
1175 drv->capa.flags |= WPA_DRIVER_FLAGS_HE_CAPABILITIES;
1176 }
1177
1178
1179 struct features_info {
1180 u8 *flags;
1181 size_t flags_len;
1182 struct wpa_driver_capa *capa;
1183 };
1184
1185
features_info_handler(struct nl_msg * msg,void * arg)1186 static int features_info_handler(struct nl_msg *msg, void *arg)
1187 {
1188 struct nlattr *tb[NL80211_ATTR_MAX + 1];
1189 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1190 struct features_info *info = arg;
1191 struct nlattr *nl_vend, *attr;
1192
1193 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1194 genlmsg_attrlen(gnlh, 0), NULL);
1195
1196 nl_vend = tb[NL80211_ATTR_VENDOR_DATA];
1197 if (nl_vend) {
1198 struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1];
1199
1200 nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX,
1201 nla_data(nl_vend), nla_len(nl_vend), NULL);
1202
1203 attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_FEATURE_FLAGS];
1204 if (attr) {
1205 int len = nla_len(attr);
1206 info->flags = os_malloc(len);
1207 if (info->flags != NULL) {
1208 os_memcpy(info->flags, nla_data(attr), len);
1209 info->flags_len = len;
1210 }
1211 }
1212 attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_CONCURRENCY_CAPA];
1213 if (attr)
1214 info->capa->conc_capab = nla_get_u32(attr);
1215
1216 attr = tb_vendor[
1217 QCA_WLAN_VENDOR_ATTR_MAX_CONCURRENT_CHANNELS_2_4_BAND];
1218 if (attr)
1219 info->capa->max_conc_chan_2_4 = nla_get_u32(attr);
1220
1221 attr = tb_vendor[
1222 QCA_WLAN_VENDOR_ATTR_MAX_CONCURRENT_CHANNELS_5_0_BAND];
1223 if (attr)
1224 info->capa->max_conc_chan_5_0 = nla_get_u32(attr);
1225 }
1226
1227 return NL_SKIP;
1228 }
1229
1230
check_feature(enum qca_wlan_vendor_features feature,struct features_info * info)1231 static int check_feature(enum qca_wlan_vendor_features feature,
1232 struct features_info *info)
1233 {
1234 size_t idx = feature / 8;
1235
1236 return (idx < info->flags_len) &&
1237 (info->flags[idx] & BIT(feature % 8));
1238 }
1239
1240
qca_nl80211_get_features(struct wpa_driver_nl80211_data * drv)1241 static void qca_nl80211_get_features(struct wpa_driver_nl80211_data *drv)
1242 {
1243 struct nl_msg *msg;
1244 struct features_info info;
1245 int ret;
1246
1247 if (!drv->get_features_vendor_cmd_avail)
1248 return;
1249
1250 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
1251 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
1252 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
1253 QCA_NL80211_VENDOR_SUBCMD_GET_FEATURES)) {
1254 nlmsg_free(msg);
1255 return;
1256 }
1257
1258 os_memset(&info, 0, sizeof(info));
1259 info.capa = &drv->capa;
1260 ret = send_and_recv_msgs(drv, msg, features_info_handler, &info);
1261 if (ret || !info.flags)
1262 return;
1263
1264 if (check_feature(QCA_WLAN_VENDOR_FEATURE_KEY_MGMT_OFFLOAD, &info))
1265 drv->capa.flags |= WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD;
1266
1267 if (check_feature(QCA_WLAN_VENDOR_FEATURE_SUPPORT_HW_MODE_ANY, &info))
1268 drv->capa.flags |= WPA_DRIVER_FLAGS_SUPPORT_HW_MODE_ANY;
1269
1270 if (check_feature(QCA_WLAN_VENDOR_FEATURE_OFFCHANNEL_SIMULTANEOUS,
1271 &info))
1272 drv->capa.flags |= WPA_DRIVER_FLAGS_OFFCHANNEL_SIMULTANEOUS;
1273 if (check_feature(QCA_WLAN_VENDOR_FEATURE_P2P_LISTEN_OFFLOAD, &info))
1274 drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD;
1275 if (check_feature(QCA_WLAN_VENDOR_FEATURE_OCE_STA, &info))
1276 drv->capa.flags |= WPA_DRIVER_FLAGS_OCE_STA;
1277 if (check_feature(QCA_WLAN_VENDOR_FEATURE_OCE_AP, &info))
1278 drv->capa.flags |= WPA_DRIVER_FLAGS_OCE_AP;
1279 if (check_feature(QCA_WLAN_VENDOR_FEATURE_OCE_STA_CFON, &info))
1280 drv->capa.flags |= WPA_DRIVER_FLAGS_OCE_STA_CFON;
1281 os_free(info.flags);
1282 }
1283
1284 #endif /* CONFIG_DRIVER_NL80211_QCA */
1285
1286
wpa_driver_nl80211_capa(struct wpa_driver_nl80211_data * drv)1287 int wpa_driver_nl80211_capa(struct wpa_driver_nl80211_data *drv)
1288 {
1289 struct wiphy_info_data info;
1290 if (wpa_driver_nl80211_get_info(drv, &info))
1291 return -1;
1292
1293 if (info.error)
1294 return -1;
1295
1296 drv->has_capability = 1;
1297 drv->capa.key_mgmt = WPA_DRIVER_CAPA_KEY_MGMT_WPA |
1298 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
1299 WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
1300 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK |
1301 WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B |
1302 WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192 |
1303 WPA_DRIVER_CAPA_KEY_MGMT_OWE |
1304 WPA_DRIVER_CAPA_KEY_MGMT_DPP;
1305
1306 if (drv->capa.flags & WPA_DRIVER_FLAGS_SME)
1307 drv->capa.key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA256 |
1308 WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA384 |
1309 WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA256 |
1310 WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA384 |
1311 WPA_DRIVER_CAPA_KEY_MGMT_SAE;
1312 else if (drv->capa.flags & WPA_DRIVER_FLAGS_FILS_SK_OFFLOAD)
1313 drv->capa.key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA256 |
1314 WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA384;
1315
1316 #ifdef CONFIG_DRIVER_NL80211_QCA
1317 /* Override drv->capa.key_mgmt based on driver advertised capability
1318 * constraints, if available. */
1319 qca_nl80211_get_akm_suites(drv);
1320 #endif /* CONFIG_DRIVER_NL80211_QCA */
1321
1322 drv->capa.auth = WPA_DRIVER_AUTH_OPEN |
1323 WPA_DRIVER_AUTH_SHARED |
1324 WPA_DRIVER_AUTH_LEAP;
1325
1326 drv->capa.flags |= WPA_DRIVER_FLAGS_SANE_ERROR_CODES;
1327 drv->capa.flags |= WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE;
1328 drv->capa.flags |= WPA_DRIVER_FLAGS_EAPOL_TX_STATUS;
1329
1330 /*
1331 * As all cfg80211 drivers must support cases where the AP interface is
1332 * removed without the knowledge of wpa_supplicant/hostapd, e.g., in
1333 * case that the user space daemon has crashed, they must be able to
1334 * cleanup all stations and key entries in the AP tear down flow. Thus,
1335 * this flag can/should always be set for cfg80211 drivers.
1336 */
1337 drv->capa.flags |= WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT;
1338
1339 if (!info.device_ap_sme) {
1340 drv->capa.flags |= WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS;
1341
1342 /*
1343 * No AP SME is currently assumed to also indicate no AP MLME
1344 * in the driver/firmware.
1345 */
1346 drv->capa.flags |= WPA_DRIVER_FLAGS_AP_MLME;
1347 }
1348
1349 drv->device_ap_sme = info.device_ap_sme;
1350 drv->poll_command_supported = info.poll_command_supported;
1351 drv->data_tx_status = info.data_tx_status;
1352 drv->p2p_go_ctwindow_supported = info.p2p_go_ctwindow_supported;
1353 if (info.set_qos_map_supported)
1354 drv->capa.flags |= WPA_DRIVER_FLAGS_QOS_MAPPING;
1355 drv->have_low_prio_scan = info.have_low_prio_scan;
1356
1357 /*
1358 * If poll command and tx status are supported, mac80211 is new enough
1359 * to have everything we need to not need monitor interfaces.
1360 */
1361 drv->use_monitor = !info.device_ap_sme &&
1362 (!info.poll_command_supported || !info.data_tx_status);
1363
1364 /*
1365 * If we aren't going to use monitor interfaces, but the
1366 * driver doesn't support data TX status, we won't get TX
1367 * status for EAPOL frames.
1368 */
1369 if (!drv->use_monitor && !info.data_tx_status)
1370 drv->capa.flags &= ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS;
1371
1372 #ifdef CONFIG_DRIVER_NL80211_QCA
1373 if (!(info.capa->flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD))
1374 qca_nl80211_check_dfs_capa(drv);
1375 qca_nl80211_get_features(drv);
1376 qca_nl80211_check_he_capab(drv);
1377
1378 /*
1379 * To enable offchannel simultaneous support in wpa_supplicant, the
1380 * underlying driver needs to support the same along with offchannel TX.
1381 * Offchannel TX support is needed since remain_on_channel and
1382 * action_tx use some common data structures and hence cannot be
1383 * scheduled simultaneously.
1384 */
1385 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX))
1386 drv->capa.flags &= ~WPA_DRIVER_FLAGS_OFFCHANNEL_SIMULTANEOUS;
1387 #endif /* CONFIG_DRIVER_NL80211_QCA */
1388
1389 return 0;
1390 }
1391
1392
1393 struct phy_info_arg {
1394 u16 *num_modes;
1395 struct hostapd_hw_modes *modes;
1396 int last_mode, last_chan_idx;
1397 int failed;
1398 u8 dfs_domain;
1399 };
1400
phy_info_ht_capa(struct hostapd_hw_modes * mode,struct nlattr * capa,struct nlattr * ampdu_factor,struct nlattr * ampdu_density,struct nlattr * mcs_set)1401 static void phy_info_ht_capa(struct hostapd_hw_modes *mode, struct nlattr *capa,
1402 struct nlattr *ampdu_factor,
1403 struct nlattr *ampdu_density,
1404 struct nlattr *mcs_set)
1405 {
1406 if (capa)
1407 mode->ht_capab = nla_get_u16(capa);
1408
1409 if (ampdu_factor)
1410 mode->a_mpdu_params |= nla_get_u8(ampdu_factor) & 0x03;
1411
1412 if (ampdu_density)
1413 mode->a_mpdu_params |= nla_get_u8(ampdu_density) << 2;
1414
1415 if (mcs_set && nla_len(mcs_set) >= 16) {
1416 u8 *mcs;
1417 mcs = nla_data(mcs_set);
1418 os_memcpy(mode->mcs_set, mcs, 16);
1419 }
1420 }
1421
1422
phy_info_vht_capa(struct hostapd_hw_modes * mode,struct nlattr * capa,struct nlattr * mcs_set)1423 static void phy_info_vht_capa(struct hostapd_hw_modes *mode,
1424 struct nlattr *capa,
1425 struct nlattr *mcs_set)
1426 {
1427 if (capa)
1428 mode->vht_capab = nla_get_u32(capa);
1429
1430 if (mcs_set && nla_len(mcs_set) >= 8) {
1431 u8 *mcs;
1432 mcs = nla_data(mcs_set);
1433 os_memcpy(mode->vht_mcs_set, mcs, 8);
1434 }
1435 }
1436
1437
phy_info_freq(struct hostapd_hw_modes * mode,struct hostapd_channel_data * chan,struct nlattr * tb_freq[])1438 static void phy_info_freq(struct hostapd_hw_modes *mode,
1439 struct hostapd_channel_data *chan,
1440 struct nlattr *tb_freq[])
1441 {
1442 u8 channel;
1443 chan->freq = nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_FREQ]);
1444 chan->flag = 0;
1445 chan->allowed_bw = ~0;
1446 chan->dfs_cac_ms = 0;
1447 if (ieee80211_freq_to_chan(chan->freq, &channel) != NUM_HOSTAPD_MODES)
1448 chan->chan = channel;
1449
1450 if (tb_freq[NL80211_FREQUENCY_ATTR_DISABLED])
1451 chan->flag |= HOSTAPD_CHAN_DISABLED;
1452 if (tb_freq[NL80211_FREQUENCY_ATTR_NO_IR])
1453 chan->flag |= HOSTAPD_CHAN_NO_IR;
1454 if (tb_freq[NL80211_FREQUENCY_ATTR_RADAR])
1455 chan->flag |= HOSTAPD_CHAN_RADAR;
1456 if (tb_freq[NL80211_FREQUENCY_ATTR_INDOOR_ONLY])
1457 chan->flag |= HOSTAPD_CHAN_INDOOR_ONLY;
1458 if (tb_freq[NL80211_FREQUENCY_ATTR_GO_CONCURRENT])
1459 chan->flag |= HOSTAPD_CHAN_GO_CONCURRENT;
1460
1461 if (tb_freq[NL80211_FREQUENCY_ATTR_NO_10MHZ])
1462 chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_10;
1463 if (tb_freq[NL80211_FREQUENCY_ATTR_NO_20MHZ])
1464 chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_20;
1465 if (tb_freq[NL80211_FREQUENCY_ATTR_NO_HT40_PLUS])
1466 chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_40P;
1467 if (tb_freq[NL80211_FREQUENCY_ATTR_NO_HT40_MINUS])
1468 chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_40M;
1469 if (tb_freq[NL80211_FREQUENCY_ATTR_NO_80MHZ])
1470 chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_80;
1471 if (tb_freq[NL80211_FREQUENCY_ATTR_NO_160MHZ])
1472 chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_160;
1473
1474 if (tb_freq[NL80211_FREQUENCY_ATTR_DFS_STATE]) {
1475 enum nl80211_dfs_state state =
1476 nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_DFS_STATE]);
1477
1478 switch (state) {
1479 case NL80211_DFS_USABLE:
1480 chan->flag |= HOSTAPD_CHAN_DFS_USABLE;
1481 break;
1482 case NL80211_DFS_AVAILABLE:
1483 chan->flag |= HOSTAPD_CHAN_DFS_AVAILABLE;
1484 break;
1485 case NL80211_DFS_UNAVAILABLE:
1486 chan->flag |= HOSTAPD_CHAN_DFS_UNAVAILABLE;
1487 break;
1488 }
1489 }
1490
1491 if (tb_freq[NL80211_FREQUENCY_ATTR_DFS_CAC_TIME]) {
1492 chan->dfs_cac_ms = nla_get_u32(
1493 tb_freq[NL80211_FREQUENCY_ATTR_DFS_CAC_TIME]);
1494 }
1495 }
1496
1497
phy_info_freqs(struct phy_info_arg * phy_info,struct hostapd_hw_modes * mode,struct nlattr * tb)1498 static int phy_info_freqs(struct phy_info_arg *phy_info,
1499 struct hostapd_hw_modes *mode, struct nlattr *tb)
1500 {
1501 static struct nla_policy freq_policy[NL80211_FREQUENCY_ATTR_MAX + 1] = {
1502 [NL80211_FREQUENCY_ATTR_FREQ] = { .type = NLA_U32 },
1503 [NL80211_FREQUENCY_ATTR_DISABLED] = { .type = NLA_FLAG },
1504 [NL80211_FREQUENCY_ATTR_NO_IR] = { .type = NLA_FLAG },
1505 [NL80211_FREQUENCY_ATTR_RADAR] = { .type = NLA_FLAG },
1506 [NL80211_FREQUENCY_ATTR_MAX_TX_POWER] = { .type = NLA_U32 },
1507 [NL80211_FREQUENCY_ATTR_DFS_STATE] = { .type = NLA_U32 },
1508 [NL80211_FREQUENCY_ATTR_NO_10MHZ] = { .type = NLA_FLAG },
1509 [NL80211_FREQUENCY_ATTR_NO_20MHZ] = { .type = NLA_FLAG },
1510 [NL80211_FREQUENCY_ATTR_NO_HT40_PLUS] = { .type = NLA_FLAG },
1511 [NL80211_FREQUENCY_ATTR_NO_HT40_MINUS] = { .type = NLA_FLAG },
1512 [NL80211_FREQUENCY_ATTR_NO_80MHZ] = { .type = NLA_FLAG },
1513 [NL80211_FREQUENCY_ATTR_NO_160MHZ] = { .type = NLA_FLAG },
1514 };
1515 int new_channels = 0;
1516 struct hostapd_channel_data *channel;
1517 struct nlattr *tb_freq[NL80211_FREQUENCY_ATTR_MAX + 1];
1518 struct nlattr *nl_freq;
1519 int rem_freq, idx;
1520
1521 if (tb == NULL)
1522 return NL_OK;
1523
1524 nla_for_each_nested(nl_freq, tb, rem_freq) {
1525 nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX,
1526 nla_data(nl_freq), nla_len(nl_freq), freq_policy);
1527 if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ])
1528 continue;
1529 new_channels++;
1530 }
1531
1532 channel = os_realloc_array(mode->channels,
1533 mode->num_channels + new_channels,
1534 sizeof(struct hostapd_channel_data));
1535 if (!channel)
1536 return NL_STOP;
1537
1538 mode->channels = channel;
1539 mode->num_channels += new_channels;
1540
1541 idx = phy_info->last_chan_idx;
1542
1543 nla_for_each_nested(nl_freq, tb, rem_freq) {
1544 nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX,
1545 nla_data(nl_freq), nla_len(nl_freq), freq_policy);
1546 if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ])
1547 continue;
1548 phy_info_freq(mode, &mode->channels[idx], tb_freq);
1549 idx++;
1550 }
1551 phy_info->last_chan_idx = idx;
1552
1553 return NL_OK;
1554 }
1555
1556
phy_info_rates(struct hostapd_hw_modes * mode,struct nlattr * tb)1557 static int phy_info_rates(struct hostapd_hw_modes *mode, struct nlattr *tb)
1558 {
1559 static struct nla_policy rate_policy[NL80211_BITRATE_ATTR_MAX + 1] = {
1560 [NL80211_BITRATE_ATTR_RATE] = { .type = NLA_U32 },
1561 [NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE] =
1562 { .type = NLA_FLAG },
1563 };
1564 struct nlattr *tb_rate[NL80211_BITRATE_ATTR_MAX + 1];
1565 struct nlattr *nl_rate;
1566 int rem_rate, idx;
1567
1568 if (tb == NULL)
1569 return NL_OK;
1570
1571 nla_for_each_nested(nl_rate, tb, rem_rate) {
1572 nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX,
1573 nla_data(nl_rate), nla_len(nl_rate),
1574 rate_policy);
1575 if (!tb_rate[NL80211_BITRATE_ATTR_RATE])
1576 continue;
1577 mode->num_rates++;
1578 }
1579
1580 mode->rates = os_calloc(mode->num_rates, sizeof(int));
1581 if (!mode->rates)
1582 return NL_STOP;
1583
1584 idx = 0;
1585
1586 nla_for_each_nested(nl_rate, tb, rem_rate) {
1587 nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX,
1588 nla_data(nl_rate), nla_len(nl_rate),
1589 rate_policy);
1590 if (!tb_rate[NL80211_BITRATE_ATTR_RATE])
1591 continue;
1592 mode->rates[idx] = nla_get_u32(
1593 tb_rate[NL80211_BITRATE_ATTR_RATE]);
1594 idx++;
1595 }
1596
1597 return NL_OK;
1598 }
1599
1600
phy_info_band(struct phy_info_arg * phy_info,struct nlattr * nl_band)1601 static int phy_info_band(struct phy_info_arg *phy_info, struct nlattr *nl_band)
1602 {
1603 struct nlattr *tb_band[NL80211_BAND_ATTR_MAX + 1];
1604 struct hostapd_hw_modes *mode;
1605 int ret;
1606
1607 if (phy_info->last_mode != nl_band->nla_type) {
1608 mode = os_realloc_array(phy_info->modes,
1609 *phy_info->num_modes + 1,
1610 sizeof(*mode));
1611 if (!mode) {
1612 phy_info->failed = 1;
1613 return NL_STOP;
1614 }
1615 phy_info->modes = mode;
1616
1617 mode = &phy_info->modes[*(phy_info->num_modes)];
1618 os_memset(mode, 0, sizeof(*mode));
1619 mode->mode = NUM_HOSTAPD_MODES;
1620 mode->flags = HOSTAPD_MODE_FLAG_HT_INFO_KNOWN |
1621 HOSTAPD_MODE_FLAG_VHT_INFO_KNOWN;
1622
1623 /*
1624 * Unsupported VHT MCS stream is defined as value 3, so the VHT
1625 * MCS RX/TX map must be initialized with 0xffff to mark all 8
1626 * possible streams as unsupported. This will be overridden if
1627 * driver advertises VHT support.
1628 */
1629 mode->vht_mcs_set[0] = 0xff;
1630 mode->vht_mcs_set[1] = 0xff;
1631 mode->vht_mcs_set[4] = 0xff;
1632 mode->vht_mcs_set[5] = 0xff;
1633
1634 *(phy_info->num_modes) += 1;
1635 phy_info->last_mode = nl_band->nla_type;
1636 phy_info->last_chan_idx = 0;
1637 } else
1638 mode = &phy_info->modes[*(phy_info->num_modes) - 1];
1639
1640 nla_parse(tb_band, NL80211_BAND_ATTR_MAX, nla_data(nl_band),
1641 nla_len(nl_band), NULL);
1642
1643 phy_info_ht_capa(mode, tb_band[NL80211_BAND_ATTR_HT_CAPA],
1644 tb_band[NL80211_BAND_ATTR_HT_AMPDU_FACTOR],
1645 tb_band[NL80211_BAND_ATTR_HT_AMPDU_DENSITY],
1646 tb_band[NL80211_BAND_ATTR_HT_MCS_SET]);
1647 phy_info_vht_capa(mode, tb_band[NL80211_BAND_ATTR_VHT_CAPA],
1648 tb_band[NL80211_BAND_ATTR_VHT_MCS_SET]);
1649 ret = phy_info_freqs(phy_info, mode, tb_band[NL80211_BAND_ATTR_FREQS]);
1650 if (ret == NL_OK)
1651 ret = phy_info_rates(mode, tb_band[NL80211_BAND_ATTR_RATES]);
1652 if (ret != NL_OK) {
1653 phy_info->failed = 1;
1654 return ret;
1655 }
1656
1657 return NL_OK;
1658 }
1659
1660
phy_info_handler(struct nl_msg * msg,void * arg)1661 static int phy_info_handler(struct nl_msg *msg, void *arg)
1662 {
1663 struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
1664 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1665 struct phy_info_arg *phy_info = arg;
1666 struct nlattr *nl_band;
1667 int rem_band;
1668
1669 nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1670 genlmsg_attrlen(gnlh, 0), NULL);
1671
1672 if (!tb_msg[NL80211_ATTR_WIPHY_BANDS])
1673 return NL_SKIP;
1674
1675 nla_for_each_nested(nl_band, tb_msg[NL80211_ATTR_WIPHY_BANDS], rem_band)
1676 {
1677 int res = phy_info_band(phy_info, nl_band);
1678 if (res != NL_OK)
1679 return res;
1680 }
1681
1682 return NL_SKIP;
1683 }
1684
1685
1686 static struct hostapd_hw_modes *
wpa_driver_nl80211_postprocess_modes(struct hostapd_hw_modes * modes,u16 * num_modes)1687 wpa_driver_nl80211_postprocess_modes(struct hostapd_hw_modes *modes,
1688 u16 *num_modes)
1689 {
1690 u16 m;
1691 struct hostapd_hw_modes *mode11g = NULL, *nmodes, *mode;
1692 int i, mode11g_idx = -1;
1693
1694 /* heuristic to set up modes */
1695 for (m = 0; m < *num_modes; m++) {
1696 if (!modes[m].num_channels)
1697 continue;
1698 if (modes[m].channels[0].freq < 4000) {
1699 modes[m].mode = HOSTAPD_MODE_IEEE80211B;
1700 for (i = 0; i < modes[m].num_rates; i++) {
1701 if (modes[m].rates[i] > 200) {
1702 modes[m].mode = HOSTAPD_MODE_IEEE80211G;
1703 break;
1704 }
1705 }
1706 } else if (modes[m].channels[0].freq > 50000)
1707 modes[m].mode = HOSTAPD_MODE_IEEE80211AD;
1708 else
1709 modes[m].mode = HOSTAPD_MODE_IEEE80211A;
1710 }
1711
1712 /* If only 802.11g mode is included, use it to construct matching
1713 * 802.11b mode data. */
1714
1715 for (m = 0; m < *num_modes; m++) {
1716 if (modes[m].mode == HOSTAPD_MODE_IEEE80211B)
1717 return modes; /* 802.11b already included */
1718 if (modes[m].mode == HOSTAPD_MODE_IEEE80211G)
1719 mode11g_idx = m;
1720 }
1721
1722 if (mode11g_idx < 0)
1723 return modes; /* 2.4 GHz band not supported at all */
1724
1725 nmodes = os_realloc_array(modes, *num_modes + 1, sizeof(*nmodes));
1726 if (nmodes == NULL)
1727 return modes; /* Could not add 802.11b mode */
1728
1729 mode = &nmodes[*num_modes];
1730 os_memset(mode, 0, sizeof(*mode));
1731 (*num_modes)++;
1732 modes = nmodes;
1733
1734 mode->mode = HOSTAPD_MODE_IEEE80211B;
1735
1736 mode11g = &modes[mode11g_idx];
1737 mode->num_channels = mode11g->num_channels;
1738 mode->channels = os_memdup(mode11g->channels,
1739 mode11g->num_channels *
1740 sizeof(struct hostapd_channel_data));
1741 if (mode->channels == NULL) {
1742 (*num_modes)--;
1743 return modes; /* Could not add 802.11b mode */
1744 }
1745
1746 mode->num_rates = 0;
1747 mode->rates = os_malloc(4 * sizeof(int));
1748 if (mode->rates == NULL) {
1749 os_free(mode->channels);
1750 (*num_modes)--;
1751 return modes; /* Could not add 802.11b mode */
1752 }
1753
1754 for (i = 0; i < mode11g->num_rates; i++) {
1755 if (mode11g->rates[i] != 10 && mode11g->rates[i] != 20 &&
1756 mode11g->rates[i] != 55 && mode11g->rates[i] != 110)
1757 continue;
1758 mode->rates[mode->num_rates] = mode11g->rates[i];
1759 mode->num_rates++;
1760 if (mode->num_rates == 4)
1761 break;
1762 }
1763
1764 if (mode->num_rates == 0) {
1765 os_free(mode->channels);
1766 os_free(mode->rates);
1767 (*num_modes)--;
1768 return modes; /* No 802.11b rates */
1769 }
1770
1771 wpa_printf(MSG_DEBUG, "nl80211: Added 802.11b mode based on 802.11g "
1772 "information");
1773
1774 return modes;
1775 }
1776
1777
nl80211_set_ht40_mode(struct hostapd_hw_modes * mode,int start,int end)1778 static void nl80211_set_ht40_mode(struct hostapd_hw_modes *mode, int start,
1779 int end)
1780 {
1781 int c;
1782
1783 for (c = 0; c < mode->num_channels; c++) {
1784 struct hostapd_channel_data *chan = &mode->channels[c];
1785 if (chan->freq - 10 >= start && chan->freq + 10 <= end)
1786 chan->flag |= HOSTAPD_CHAN_HT40;
1787 }
1788 }
1789
1790
nl80211_set_ht40_mode_sec(struct hostapd_hw_modes * mode,int start,int end)1791 static void nl80211_set_ht40_mode_sec(struct hostapd_hw_modes *mode, int start,
1792 int end)
1793 {
1794 int c;
1795
1796 for (c = 0; c < mode->num_channels; c++) {
1797 struct hostapd_channel_data *chan = &mode->channels[c];
1798 if (!(chan->flag & HOSTAPD_CHAN_HT40))
1799 continue;
1800 if (chan->freq - 30 >= start && chan->freq - 10 <= end)
1801 chan->flag |= HOSTAPD_CHAN_HT40MINUS;
1802 if (chan->freq + 10 >= start && chan->freq + 30 <= end)
1803 chan->flag |= HOSTAPD_CHAN_HT40PLUS;
1804 }
1805 }
1806
1807
nl80211_reg_rule_max_eirp(u32 start,u32 end,u32 max_eirp,struct phy_info_arg * results)1808 static void nl80211_reg_rule_max_eirp(u32 start, u32 end, u32 max_eirp,
1809 struct phy_info_arg *results)
1810 {
1811 u16 m;
1812
1813 for (m = 0; m < *results->num_modes; m++) {
1814 int c;
1815 struct hostapd_hw_modes *mode = &results->modes[m];
1816
1817 for (c = 0; c < mode->num_channels; c++) {
1818 struct hostapd_channel_data *chan = &mode->channels[c];
1819 if ((u32) chan->freq - 10 >= start &&
1820 (u32) chan->freq + 10 <= end)
1821 chan->max_tx_power = max_eirp;
1822 }
1823 }
1824 }
1825
1826
nl80211_reg_rule_ht40(u32 start,u32 end,struct phy_info_arg * results)1827 static void nl80211_reg_rule_ht40(u32 start, u32 end,
1828 struct phy_info_arg *results)
1829 {
1830 u16 m;
1831
1832 for (m = 0; m < *results->num_modes; m++) {
1833 if (!(results->modes[m].ht_capab &
1834 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET))
1835 continue;
1836 nl80211_set_ht40_mode(&results->modes[m], start, end);
1837 }
1838 }
1839
1840
nl80211_reg_rule_sec(struct nlattr * tb[],struct phy_info_arg * results)1841 static void nl80211_reg_rule_sec(struct nlattr *tb[],
1842 struct phy_info_arg *results)
1843 {
1844 u32 start, end, max_bw;
1845 u16 m;
1846
1847 if (tb[NL80211_ATTR_FREQ_RANGE_START] == NULL ||
1848 tb[NL80211_ATTR_FREQ_RANGE_END] == NULL ||
1849 tb[NL80211_ATTR_FREQ_RANGE_MAX_BW] == NULL)
1850 return;
1851
1852 start = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]) / 1000;
1853 end = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]) / 1000;
1854 max_bw = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) / 1000;
1855
1856 if (max_bw < 20)
1857 return;
1858
1859 for (m = 0; m < *results->num_modes; m++) {
1860 if (!(results->modes[m].ht_capab &
1861 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET))
1862 continue;
1863 nl80211_set_ht40_mode_sec(&results->modes[m], start, end);
1864 }
1865 }
1866
1867
nl80211_set_vht_mode(struct hostapd_hw_modes * mode,int start,int end,int max_bw)1868 static void nl80211_set_vht_mode(struct hostapd_hw_modes *mode, int start,
1869 int end, int max_bw)
1870 {
1871 int c;
1872
1873 for (c = 0; c < mode->num_channels; c++) {
1874 struct hostapd_channel_data *chan = &mode->channels[c];
1875 if (chan->freq - 10 >= start && chan->freq + 70 <= end)
1876 chan->flag |= HOSTAPD_CHAN_VHT_10_70;
1877
1878 if (chan->freq - 30 >= start && chan->freq + 50 <= end)
1879 chan->flag |= HOSTAPD_CHAN_VHT_30_50;
1880
1881 if (chan->freq - 50 >= start && chan->freq + 30 <= end)
1882 chan->flag |= HOSTAPD_CHAN_VHT_50_30;
1883
1884 if (chan->freq - 70 >= start && chan->freq + 10 <= end)
1885 chan->flag |= HOSTAPD_CHAN_VHT_70_10;
1886
1887 if (max_bw >= 160) {
1888 if (chan->freq - 10 >= start && chan->freq + 150 <= end)
1889 chan->flag |= HOSTAPD_CHAN_VHT_10_150;
1890
1891 if (chan->freq - 30 >= start && chan->freq + 130 <= end)
1892 chan->flag |= HOSTAPD_CHAN_VHT_30_130;
1893
1894 if (chan->freq - 50 >= start && chan->freq + 110 <= end)
1895 chan->flag |= HOSTAPD_CHAN_VHT_50_110;
1896
1897 if (chan->freq - 70 >= start && chan->freq + 90 <= end)
1898 chan->flag |= HOSTAPD_CHAN_VHT_70_90;
1899
1900 if (chan->freq - 90 >= start && chan->freq + 70 <= end)
1901 chan->flag |= HOSTAPD_CHAN_VHT_90_70;
1902
1903 if (chan->freq - 110 >= start && chan->freq + 50 <= end)
1904 chan->flag |= HOSTAPD_CHAN_VHT_110_50;
1905
1906 if (chan->freq - 130 >= start && chan->freq + 30 <= end)
1907 chan->flag |= HOSTAPD_CHAN_VHT_130_30;
1908
1909 if (chan->freq - 150 >= start && chan->freq + 10 <= end)
1910 chan->flag |= HOSTAPD_CHAN_VHT_150_10;
1911 }
1912 }
1913 }
1914
1915
nl80211_reg_rule_vht(struct nlattr * tb[],struct phy_info_arg * results)1916 static void nl80211_reg_rule_vht(struct nlattr *tb[],
1917 struct phy_info_arg *results)
1918 {
1919 u32 start, end, max_bw;
1920 u16 m;
1921
1922 if (tb[NL80211_ATTR_FREQ_RANGE_START] == NULL ||
1923 tb[NL80211_ATTR_FREQ_RANGE_END] == NULL ||
1924 tb[NL80211_ATTR_FREQ_RANGE_MAX_BW] == NULL)
1925 return;
1926
1927 start = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]) / 1000;
1928 end = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]) / 1000;
1929 max_bw = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) / 1000;
1930
1931 if (max_bw < 80)
1932 return;
1933
1934 for (m = 0; m < *results->num_modes; m++) {
1935 if (!(results->modes[m].ht_capab &
1936 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET))
1937 continue;
1938 /* TODO: use a real VHT support indication */
1939 if (!results->modes[m].vht_capab)
1940 continue;
1941
1942 nl80211_set_vht_mode(&results->modes[m], start, end, max_bw);
1943 }
1944 }
1945
1946
nl80211_set_dfs_domain(enum nl80211_dfs_regions region,u8 * dfs_domain)1947 static void nl80211_set_dfs_domain(enum nl80211_dfs_regions region,
1948 u8 *dfs_domain)
1949 {
1950 if (region == NL80211_DFS_FCC)
1951 *dfs_domain = HOSTAPD_DFS_REGION_FCC;
1952 else if (region == NL80211_DFS_ETSI)
1953 *dfs_domain = HOSTAPD_DFS_REGION_ETSI;
1954 else if (region == NL80211_DFS_JP)
1955 *dfs_domain = HOSTAPD_DFS_REGION_JP;
1956 else
1957 *dfs_domain = 0;
1958 }
1959
1960
dfs_domain_name(enum nl80211_dfs_regions region)1961 static const char * dfs_domain_name(enum nl80211_dfs_regions region)
1962 {
1963 switch (region) {
1964 case NL80211_DFS_UNSET:
1965 return "DFS-UNSET";
1966 case NL80211_DFS_FCC:
1967 return "DFS-FCC";
1968 case NL80211_DFS_ETSI:
1969 return "DFS-ETSI";
1970 case NL80211_DFS_JP:
1971 return "DFS-JP";
1972 default:
1973 return "DFS-invalid";
1974 }
1975 }
1976
1977
nl80211_get_reg(struct nl_msg * msg,void * arg)1978 static int nl80211_get_reg(struct nl_msg *msg, void *arg)
1979 {
1980 struct phy_info_arg *results = arg;
1981 struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
1982 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1983 struct nlattr *nl_rule;
1984 struct nlattr *tb_rule[NL80211_FREQUENCY_ATTR_MAX + 1];
1985 int rem_rule;
1986 static struct nla_policy reg_policy[NL80211_FREQUENCY_ATTR_MAX + 1] = {
1987 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
1988 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
1989 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
1990 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
1991 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
1992 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
1993 };
1994
1995 nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1996 genlmsg_attrlen(gnlh, 0), NULL);
1997 if (!tb_msg[NL80211_ATTR_REG_ALPHA2] ||
1998 !tb_msg[NL80211_ATTR_REG_RULES]) {
1999 wpa_printf(MSG_DEBUG, "nl80211: No regulatory information "
2000 "available");
2001 return NL_SKIP;
2002 }
2003
2004 if (tb_msg[NL80211_ATTR_DFS_REGION]) {
2005 enum nl80211_dfs_regions dfs_domain;
2006 dfs_domain = nla_get_u8(tb_msg[NL80211_ATTR_DFS_REGION]);
2007 nl80211_set_dfs_domain(dfs_domain, &results->dfs_domain);
2008 wpa_printf(MSG_DEBUG, "nl80211: Regulatory information - country=%s (%s)",
2009 (char *) nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]),
2010 dfs_domain_name(dfs_domain));
2011 } else {
2012 wpa_printf(MSG_DEBUG, "nl80211: Regulatory information - country=%s",
2013 (char *) nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]));
2014 }
2015
2016 nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule)
2017 {
2018 u32 start, end, max_eirp = 0, max_bw = 0, flags = 0;
2019 nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX,
2020 nla_data(nl_rule), nla_len(nl_rule), reg_policy);
2021 if (tb_rule[NL80211_ATTR_FREQ_RANGE_START] == NULL ||
2022 tb_rule[NL80211_ATTR_FREQ_RANGE_END] == NULL)
2023 continue;
2024 start = nla_get_u32(tb_rule[NL80211_ATTR_FREQ_RANGE_START]) / 1000;
2025 end = nla_get_u32(tb_rule[NL80211_ATTR_FREQ_RANGE_END]) / 1000;
2026 if (tb_rule[NL80211_ATTR_POWER_RULE_MAX_EIRP])
2027 max_eirp = nla_get_u32(tb_rule[NL80211_ATTR_POWER_RULE_MAX_EIRP]) / 100;
2028 if (tb_rule[NL80211_ATTR_FREQ_RANGE_MAX_BW])
2029 max_bw = nla_get_u32(tb_rule[NL80211_ATTR_FREQ_RANGE_MAX_BW]) / 1000;
2030 if (tb_rule[NL80211_ATTR_REG_RULE_FLAGS])
2031 flags = nla_get_u32(tb_rule[NL80211_ATTR_REG_RULE_FLAGS]);
2032
2033 wpa_printf(MSG_DEBUG, "nl80211: %u-%u @ %u MHz %u mBm%s%s%s%s%s%s%s%s",
2034 start, end, max_bw, max_eirp,
2035 flags & NL80211_RRF_NO_OFDM ? " (no OFDM)" : "",
2036 flags & NL80211_RRF_NO_CCK ? " (no CCK)" : "",
2037 flags & NL80211_RRF_NO_INDOOR ? " (no indoor)" : "",
2038 flags & NL80211_RRF_NO_OUTDOOR ? " (no outdoor)" :
2039 "",
2040 flags & NL80211_RRF_DFS ? " (DFS)" : "",
2041 flags & NL80211_RRF_PTP_ONLY ? " (PTP only)" : "",
2042 flags & NL80211_RRF_PTMP_ONLY ? " (PTMP only)" : "",
2043 flags & NL80211_RRF_NO_IR ? " (no IR)" : "");
2044 if (max_bw >= 40)
2045 nl80211_reg_rule_ht40(start, end, results);
2046 if (tb_rule[NL80211_ATTR_POWER_RULE_MAX_EIRP])
2047 nl80211_reg_rule_max_eirp(start, end, max_eirp,
2048 results);
2049 }
2050
2051 nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule)
2052 {
2053 nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX,
2054 nla_data(nl_rule), nla_len(nl_rule), reg_policy);
2055 nl80211_reg_rule_sec(tb_rule, results);
2056 }
2057
2058 nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule)
2059 {
2060 nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX,
2061 nla_data(nl_rule), nla_len(nl_rule), reg_policy);
2062 nl80211_reg_rule_vht(tb_rule, results);
2063 }
2064
2065 return NL_SKIP;
2066 }
2067
2068
nl80211_set_regulatory_flags(struct wpa_driver_nl80211_data * drv,struct phy_info_arg * results)2069 static int nl80211_set_regulatory_flags(struct wpa_driver_nl80211_data *drv,
2070 struct phy_info_arg *results)
2071 {
2072 struct nl_msg *msg;
2073
2074 msg = nlmsg_alloc();
2075 if (!msg)
2076 return -ENOMEM;
2077
2078 nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG);
2079 if (drv->capa.flags & WPA_DRIVER_FLAGS_SELF_MANAGED_REGULATORY) {
2080 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, drv->wiphy_idx)) {
2081 nlmsg_free(msg);
2082 return -1;
2083 }
2084 }
2085
2086 return send_and_recv_msgs(drv, msg, nl80211_get_reg, results);
2087 }
2088
2089
modestr(enum hostapd_hw_mode mode)2090 static const char * modestr(enum hostapd_hw_mode mode)
2091 {
2092 switch (mode) {
2093 case HOSTAPD_MODE_IEEE80211B:
2094 return "802.11b";
2095 case HOSTAPD_MODE_IEEE80211G:
2096 return "802.11g";
2097 case HOSTAPD_MODE_IEEE80211A:
2098 return "802.11a";
2099 case HOSTAPD_MODE_IEEE80211AD:
2100 return "802.11ad";
2101 default:
2102 return "?";
2103 }
2104 }
2105
2106
nl80211_dump_chan_list(struct hostapd_hw_modes * modes,u16 num_modes)2107 static void nl80211_dump_chan_list(struct hostapd_hw_modes *modes,
2108 u16 num_modes)
2109 {
2110 int i;
2111
2112 if (!modes)
2113 return;
2114
2115 for (i = 0; i < num_modes; i++) {
2116 struct hostapd_hw_modes *mode = &modes[i];
2117 char str[200];
2118 char *pos = str;
2119 char *end = pos + sizeof(str);
2120 int j, res;
2121
2122 for (j = 0; j < mode->num_channels; j++) {
2123 struct hostapd_channel_data *chan = &mode->channels[j];
2124
2125 res = os_snprintf(pos, end - pos, " %d%s%s%s",
2126 chan->freq,
2127 (chan->flag & HOSTAPD_CHAN_DISABLED) ?
2128 "[DISABLED]" : "",
2129 (chan->flag & HOSTAPD_CHAN_NO_IR) ?
2130 "[NO_IR]" : "",
2131 (chan->flag & HOSTAPD_CHAN_RADAR) ?
2132 "[RADAR]" : "");
2133 if (os_snprintf_error(end - pos, res))
2134 break;
2135 pos += res;
2136 }
2137
2138 *pos = '\0';
2139 wpa_printf(MSG_DEBUG, "nl80211: Mode IEEE %s:%s",
2140 modestr(mode->mode), str);
2141 }
2142 }
2143
2144
2145 struct hostapd_hw_modes *
nl80211_get_hw_feature_data(void * priv,u16 * num_modes,u16 * flags,u8 * dfs_domain)2146 nl80211_get_hw_feature_data(void *priv, u16 *num_modes, u16 *flags,
2147 u8 *dfs_domain)
2148 {
2149 u32 feat;
2150 struct i802_bss *bss = priv;
2151 struct wpa_driver_nl80211_data *drv = bss->drv;
2152 int nl_flags = 0;
2153 struct nl_msg *msg;
2154 struct phy_info_arg result = {
2155 .num_modes = num_modes,
2156 .modes = NULL,
2157 .last_mode = -1,
2158 .failed = 0,
2159 .dfs_domain = 0,
2160 };
2161
2162 *num_modes = 0;
2163 *flags = 0;
2164 *dfs_domain = 0;
2165
2166 feat = get_nl80211_protocol_features(drv);
2167 if (feat & NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)
2168 nl_flags = NLM_F_DUMP;
2169 if (!(msg = nl80211_cmd_msg(bss, nl_flags, NL80211_CMD_GET_WIPHY)) ||
2170 nla_put_flag(msg, NL80211_ATTR_SPLIT_WIPHY_DUMP)) {
2171 nlmsg_free(msg);
2172 return NULL;
2173 }
2174
2175 if (send_and_recv_msgs(drv, msg, phy_info_handler, &result) == 0) {
2176 struct hostapd_hw_modes *modes;
2177
2178 nl80211_set_regulatory_flags(drv, &result);
2179 if (result.failed) {
2180 int i;
2181
2182 for (i = 0; result.modes && i < *num_modes; i++) {
2183 os_free(result.modes[i].channels);
2184 os_free(result.modes[i].rates);
2185 }
2186 os_free(result.modes);
2187 *num_modes = 0;
2188 return NULL;
2189 }
2190
2191 *dfs_domain = result.dfs_domain;
2192
2193 modes = wpa_driver_nl80211_postprocess_modes(result.modes,
2194 num_modes);
2195 nl80211_dump_chan_list(modes, *num_modes);
2196 return modes;
2197 }
2198
2199 return NULL;
2200 }
2201