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_FETCH_BSS_TRANSITION_STATUS:
782 drv->fetch_bss_trans_status = 1;
783 break;
784 case QCA_NL80211_VENDOR_SUBCMD_ROAM:
785 drv->roam_vendor_cmd_avail = 1;
786 break;
787 case QCA_NL80211_VENDOR_SUBCMD_GET_SUPPORTED_AKMS:
788 drv->get_supported_akm_suites_avail = 1;
789 break;
790 #endif /* CONFIG_DRIVER_NL80211_QCA */
791 }
792 }
793
794 wpa_printf(MSG_DEBUG, "nl80211: Supported vendor command: vendor_id=0x%x subcmd=%u",
795 vinfo->vendor_id, vinfo->subcmd);
796 }
797 }
798
799 if (tb[NL80211_ATTR_VENDOR_EVENTS]) {
800 struct nlattr *nl;
801 int rem;
802
803 nla_for_each_nested(nl, tb[NL80211_ATTR_VENDOR_EVENTS], rem) {
804 struct nl80211_vendor_cmd_info *vinfo;
805 if (nla_len(nl) != sizeof(*vinfo)) {
806 wpa_printf(MSG_DEBUG, "nl80211: Unexpected vendor data info");
807 continue;
808 }
809 vinfo = nla_data(nl);
810 wpa_printf(MSG_DEBUG, "nl80211: Supported vendor event: vendor_id=0x%x subcmd=%u",
811 vinfo->vendor_id, vinfo->subcmd);
812 }
813 }
814
815 wiphy_info_wowlan_triggers(capa,
816 tb[NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED]);
817
818 if (tb[NL80211_ATTR_MAX_AP_ASSOC_STA])
819 capa->max_stations =
820 nla_get_u32(tb[NL80211_ATTR_MAX_AP_ASSOC_STA]);
821
822 if (tb[NL80211_ATTR_MAX_CSA_COUNTERS])
823 capa->max_csa_counters =
824 nla_get_u8(tb[NL80211_ATTR_MAX_CSA_COUNTERS]);
825
826 if (tb[NL80211_ATTR_WIPHY_SELF_MANAGED_REG])
827 capa->flags |= WPA_DRIVER_FLAGS_SELF_MANAGED_REGULATORY;
828
829 return NL_SKIP;
830 }
831
832
wpa_driver_nl80211_get_info(struct wpa_driver_nl80211_data * drv,struct wiphy_info_data * info)833 static int wpa_driver_nl80211_get_info(struct wpa_driver_nl80211_data *drv,
834 struct wiphy_info_data *info)
835 {
836 u32 feat;
837 struct nl_msg *msg;
838 int flags = 0;
839
840 os_memset(info, 0, sizeof(*info));
841 info->capa = &drv->capa;
842 info->drv = drv;
843
844 feat = get_nl80211_protocol_features(drv);
845 if (feat & NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)
846 flags = NLM_F_DUMP;
847 msg = nl80211_cmd_msg(drv->first_bss, flags, NL80211_CMD_GET_WIPHY);
848 if (!msg || nla_put_flag(msg, NL80211_ATTR_SPLIT_WIPHY_DUMP)) {
849 nlmsg_free(msg);
850 return -1;
851 }
852
853 if (send_and_recv_msgs(drv, msg, wiphy_info_handler, info))
854 return -1;
855
856 if (info->auth_supported)
857 drv->capa.flags |= WPA_DRIVER_FLAGS_SME;
858 else if (!info->connect_supported) {
859 wpa_printf(MSG_INFO, "nl80211: Driver does not support "
860 "authentication/association or connect commands");
861 info->error = 1;
862 }
863
864 if (info->p2p_go_supported && info->p2p_client_supported)
865 drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CAPABLE;
866 if (info->p2p_concurrent) {
867 wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group "
868 "interface (driver advertised support)");
869 drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT;
870 drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P;
871 }
872 if (info->num_multichan_concurrent > 1) {
873 wpa_printf(MSG_DEBUG, "nl80211: Enable multi-channel "
874 "concurrent (driver advertised support)");
875 drv->capa.num_multichan_concurrent =
876 info->num_multichan_concurrent;
877 }
878 if (drv->capa.flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)
879 {
880 wpa_printf(MSG_DEBUG, "nl80211: use P2P_DEVICE support");
881 #ifdef CONFIG_DRIVER_NL80211_HISI
882 drv->capa.flags &= (~WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE);
883 #endif /* CONFIG_DRIVER_NL80211_HISI*/
884 }
885 /* default to 5000 since early versions of mac80211 don't set it */
886 if (!drv->capa.max_remain_on_chan)
887 drv->capa.max_remain_on_chan = 5000;
888
889 drv->capa.wmm_ac_supported = info->wmm_ac_supported;
890
891 drv->capa.mac_addr_rand_sched_scan_supported =
892 info->mac_addr_rand_sched_scan_supported;
893 drv->capa.mac_addr_rand_scan_supported =
894 info->mac_addr_rand_scan_supported;
895
896 if (info->channel_switch_supported) {
897 drv->capa.flags |= WPA_DRIVER_FLAGS_AP_CSA;
898 if (!drv->capa.max_csa_counters)
899 drv->capa.max_csa_counters = 1;
900 }
901
902 if (!drv->capa.max_sched_scan_plans) {
903 drv->capa.max_sched_scan_plans = 1;
904 drv->capa.max_sched_scan_plan_interval = UINT32_MAX;
905 drv->capa.max_sched_scan_plan_iterations = 0;
906 }
907
908 return 0;
909 }
910
911
912 #ifdef CONFIG_DRIVER_NL80211_QCA
913
dfs_info_handler(struct nl_msg * msg,void * arg)914 static int dfs_info_handler(struct nl_msg *msg, void *arg)
915 {
916 struct nlattr *tb[NL80211_ATTR_MAX + 1];
917 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
918 int *dfs_capability_ptr = arg;
919
920 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
921 genlmsg_attrlen(gnlh, 0), NULL);
922
923 if (tb[NL80211_ATTR_VENDOR_DATA]) {
924 struct nlattr *nl_vend = tb[NL80211_ATTR_VENDOR_DATA];
925 struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1];
926
927 nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX,
928 nla_data(nl_vend), nla_len(nl_vend), NULL);
929
930 if (tb_vendor[QCA_WLAN_VENDOR_ATTR_DFS]) {
931 u32 val;
932 val = nla_get_u32(tb_vendor[QCA_WLAN_VENDOR_ATTR_DFS]);
933 wpa_printf(MSG_DEBUG, "nl80211: DFS offload capability: %u",
934 val);
935 *dfs_capability_ptr = val;
936 }
937 }
938
939 return NL_SKIP;
940 }
941
942
qca_nl80211_check_dfs_capa(struct wpa_driver_nl80211_data * drv)943 static void qca_nl80211_check_dfs_capa(struct wpa_driver_nl80211_data *drv)
944 {
945 struct nl_msg *msg;
946 int dfs_capability = 0;
947 int ret;
948
949 if (!drv->dfs_vendor_cmd_avail)
950 return;
951
952 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
953 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
954 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
955 QCA_NL80211_VENDOR_SUBCMD_DFS_CAPABILITY)) {
956 nlmsg_free(msg);
957 return;
958 }
959
960 ret = send_and_recv_msgs(drv, msg, dfs_info_handler, &dfs_capability);
961 if (!ret && dfs_capability)
962 drv->capa.flags |= WPA_DRIVER_FLAGS_DFS_OFFLOAD;
963 }
964
965
get_akm_suites_info(struct nlattr * tb)966 static unsigned int get_akm_suites_info(struct nlattr *tb)
967 {
968 int i, num;
969 unsigned int key_mgmt = 0;
970 u32 *akms;
971
972 if (!tb)
973 return 0;
974
975 num = nla_len(tb) / sizeof(u32);
976 akms = nla_data(tb);
977 for (i = 0; i < num; i++) {
978 u32 a = akms[i];
979
980 wpa_printf(MSG_DEBUG,
981 "nl80211: Supported AKM %02x-%02x-%02x:%u",
982 a >> 24, (a >> 16) & 0xff,
983 (a >> 8) & 0xff, a & 0xff);
984 switch (a) {
985 case RSN_AUTH_KEY_MGMT_UNSPEC_802_1X:
986 key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_WPA |
987 WPA_DRIVER_CAPA_KEY_MGMT_WPA2;
988 break;
989 case RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X:
990 key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
991 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK;
992 break;
993 case RSN_AUTH_KEY_MGMT_FT_802_1X:
994 key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT;
995 break;
996 case RSN_AUTH_KEY_MGMT_FT_PSK:
997 key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK;
998 break;
999 case RSN_AUTH_KEY_MGMT_802_1X_SUITE_B:
1000 key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B;
1001 break;
1002 case RSN_AUTH_KEY_MGMT_802_1X_SUITE_B_192:
1003 key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192;
1004 break;
1005 case RSN_AUTH_KEY_MGMT_OWE:
1006 key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_OWE;
1007 break;
1008 case RSN_AUTH_KEY_MGMT_DPP:
1009 key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_DPP;
1010 break;
1011 case RSN_AUTH_KEY_MGMT_FILS_SHA256:
1012 key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA256;
1013 break;
1014 case RSN_AUTH_KEY_MGMT_FILS_SHA384:
1015 key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA384;
1016 break;
1017 case RSN_AUTH_KEY_MGMT_FT_FILS_SHA256:
1018 key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA256;
1019 break;
1020 case RSN_AUTH_KEY_MGMT_FT_FILS_SHA384:
1021 key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA384;
1022 break;
1023 case RSN_AUTH_KEY_MGMT_SAE:
1024 key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_SAE;
1025 break;
1026 }
1027 }
1028
1029 return key_mgmt;
1030 }
1031
1032
get_akm_suites_handler(struct nl_msg * msg,void * arg)1033 static int get_akm_suites_handler(struct nl_msg *msg, void *arg)
1034 {
1035 struct nlattr *tb[NL80211_ATTR_MAX + 1];
1036 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1037 unsigned int *key_mgmt = arg;
1038
1039 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1040 genlmsg_attrlen(gnlh, 0), NULL);
1041
1042 if (tb[NL80211_ATTR_VENDOR_DATA]) {
1043 struct nlattr *nl_vend = tb[NL80211_ATTR_VENDOR_DATA];
1044 struct nlattr *tb_data[NL80211_ATTR_MAX + 1];
1045
1046 nla_parse(tb_data, NL80211_ATTR_MAX,
1047 nla_data(nl_vend), nla_len(nl_vend), NULL);
1048
1049 *key_mgmt =
1050 get_akm_suites_info(tb_data[NL80211_ATTR_AKM_SUITES]);
1051 }
1052
1053 return NL_SKIP;
1054 }
1055
1056
qca_nl80211_get_akm_suites(struct wpa_driver_nl80211_data * drv)1057 static int qca_nl80211_get_akm_suites(struct wpa_driver_nl80211_data *drv)
1058 {
1059 struct nl_msg *msg;
1060 unsigned int key_mgmt = 0;
1061 int ret;
1062
1063 if (!drv->get_supported_akm_suites_avail)
1064 return -1;
1065
1066 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
1067 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
1068 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
1069 QCA_NL80211_VENDOR_SUBCMD_GET_SUPPORTED_AKMS)) {
1070 nlmsg_free(msg);
1071 return -1;
1072 }
1073
1074 ret = send_and_recv_msgs(drv, msg, get_akm_suites_handler, &key_mgmt);
1075 if (!ret) {
1076 wpa_printf(MSG_DEBUG,
1077 "nl80211: Replace capa.key_mgmt based on driver advertised capabilities: 0x%x",
1078 key_mgmt);
1079 drv->capa.key_mgmt = key_mgmt;
1080 }
1081
1082 return ret;
1083 }
1084
1085
1086 struct features_info {
1087 u8 *flags;
1088 size_t flags_len;
1089 struct wpa_driver_capa *capa;
1090 };
1091
1092
features_info_handler(struct nl_msg * msg,void * arg)1093 static int features_info_handler(struct nl_msg *msg, void *arg)
1094 {
1095 struct nlattr *tb[NL80211_ATTR_MAX + 1];
1096 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1097 struct features_info *info = arg;
1098 struct nlattr *nl_vend, *attr;
1099
1100 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1101 genlmsg_attrlen(gnlh, 0), NULL);
1102
1103 nl_vend = tb[NL80211_ATTR_VENDOR_DATA];
1104 if (nl_vend) {
1105 struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1];
1106
1107 nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX,
1108 nla_data(nl_vend), nla_len(nl_vend), NULL);
1109
1110 attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_FEATURE_FLAGS];
1111 if (attr) {
1112 int len = nla_len(attr);
1113 info->flags = os_malloc(len);
1114 if (info->flags != NULL) {
1115 os_memcpy(info->flags, nla_data(attr), len);
1116 info->flags_len = len;
1117 }
1118 }
1119 attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_CONCURRENCY_CAPA];
1120 if (attr)
1121 info->capa->conc_capab = nla_get_u32(attr);
1122
1123 attr = tb_vendor[
1124 QCA_WLAN_VENDOR_ATTR_MAX_CONCURRENT_CHANNELS_2_4_BAND];
1125 if (attr)
1126 info->capa->max_conc_chan_2_4 = nla_get_u32(attr);
1127
1128 attr = tb_vendor[
1129 QCA_WLAN_VENDOR_ATTR_MAX_CONCURRENT_CHANNELS_5_0_BAND];
1130 if (attr)
1131 info->capa->max_conc_chan_5_0 = nla_get_u32(attr);
1132 }
1133
1134 return NL_SKIP;
1135 }
1136
1137
check_feature(enum qca_wlan_vendor_features feature,struct features_info * info)1138 static int check_feature(enum qca_wlan_vendor_features feature,
1139 struct features_info *info)
1140 {
1141 size_t idx = feature / 8;
1142
1143 return (idx < info->flags_len) &&
1144 (info->flags[idx] & BIT(feature % 8));
1145 }
1146
1147
qca_nl80211_get_features(struct wpa_driver_nl80211_data * drv)1148 static void qca_nl80211_get_features(struct wpa_driver_nl80211_data *drv)
1149 {
1150 struct nl_msg *msg;
1151 struct features_info info;
1152 int ret;
1153
1154 if (!drv->get_features_vendor_cmd_avail)
1155 return;
1156
1157 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
1158 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
1159 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
1160 QCA_NL80211_VENDOR_SUBCMD_GET_FEATURES)) {
1161 nlmsg_free(msg);
1162 return;
1163 }
1164
1165 os_memset(&info, 0, sizeof(info));
1166 info.capa = &drv->capa;
1167 ret = send_and_recv_msgs(drv, msg, features_info_handler, &info);
1168 if (ret || !info.flags)
1169 return;
1170
1171 if (check_feature(QCA_WLAN_VENDOR_FEATURE_KEY_MGMT_OFFLOAD, &info))
1172 drv->capa.flags |= WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD;
1173
1174 if (check_feature(QCA_WLAN_VENDOR_FEATURE_SUPPORT_HW_MODE_ANY, &info))
1175 drv->capa.flags |= WPA_DRIVER_FLAGS_SUPPORT_HW_MODE_ANY;
1176
1177 if (check_feature(QCA_WLAN_VENDOR_FEATURE_OFFCHANNEL_SIMULTANEOUS,
1178 &info))
1179 drv->capa.flags |= WPA_DRIVER_FLAGS_OFFCHANNEL_SIMULTANEOUS;
1180 if (check_feature(QCA_WLAN_VENDOR_FEATURE_P2P_LISTEN_OFFLOAD, &info))
1181 drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD;
1182 if (check_feature(QCA_WLAN_VENDOR_FEATURE_OCE_STA, &info))
1183 drv->capa.flags |= WPA_DRIVER_FLAGS_OCE_STA;
1184 if (check_feature(QCA_WLAN_VENDOR_FEATURE_OCE_AP, &info))
1185 drv->capa.flags |= WPA_DRIVER_FLAGS_OCE_AP;
1186 if (check_feature(QCA_WLAN_VENDOR_FEATURE_OCE_STA_CFON, &info))
1187 drv->capa.flags |= WPA_DRIVER_FLAGS_OCE_STA_CFON;
1188 os_free(info.flags);
1189 }
1190
1191 #endif /* CONFIG_DRIVER_NL80211_QCA */
1192
1193
wpa_driver_nl80211_capa(struct wpa_driver_nl80211_data * drv)1194 int wpa_driver_nl80211_capa(struct wpa_driver_nl80211_data *drv)
1195 {
1196 struct wiphy_info_data info;
1197 if (wpa_driver_nl80211_get_info(drv, &info))
1198 return -1;
1199
1200 if (info.error)
1201 return -1;
1202
1203 drv->has_capability = 1;
1204 drv->capa.key_mgmt = WPA_DRIVER_CAPA_KEY_MGMT_WPA |
1205 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
1206 WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
1207 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK |
1208 WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B |
1209 WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192 |
1210 WPA_DRIVER_CAPA_KEY_MGMT_OWE |
1211 WPA_DRIVER_CAPA_KEY_MGMT_DPP;
1212
1213 if (drv->capa.flags & WPA_DRIVER_FLAGS_SME)
1214 drv->capa.key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA256 |
1215 WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA384 |
1216 WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA256 |
1217 WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA384 |
1218 WPA_DRIVER_CAPA_KEY_MGMT_SAE;
1219 else if (drv->capa.flags & WPA_DRIVER_FLAGS_FILS_SK_OFFLOAD)
1220 drv->capa.key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA256 |
1221 WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA384;
1222
1223 #ifdef CONFIG_DRIVER_NL80211_QCA
1224 /* Override drv->capa.key_mgmt based on driver advertised capability
1225 * constraints, if available. */
1226 qca_nl80211_get_akm_suites(drv);
1227 #endif /* CONFIG_DRIVER_NL80211_QCA */
1228
1229 drv->capa.auth = WPA_DRIVER_AUTH_OPEN |
1230 WPA_DRIVER_AUTH_SHARED |
1231 WPA_DRIVER_AUTH_LEAP;
1232
1233 drv->capa.flags |= WPA_DRIVER_FLAGS_SANE_ERROR_CODES;
1234 drv->capa.flags |= WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE;
1235 drv->capa.flags |= WPA_DRIVER_FLAGS_EAPOL_TX_STATUS;
1236
1237 /*
1238 * As all cfg80211 drivers must support cases where the AP interface is
1239 * removed without the knowledge of wpa_supplicant/hostapd, e.g., in
1240 * case that the user space daemon has crashed, they must be able to
1241 * cleanup all stations and key entries in the AP tear down flow. Thus,
1242 * this flag can/should always be set for cfg80211 drivers.
1243 */
1244 drv->capa.flags |= WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT;
1245
1246 if (!info.device_ap_sme) {
1247 drv->capa.flags |= WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS;
1248
1249 /*
1250 * No AP SME is currently assumed to also indicate no AP MLME
1251 * in the driver/firmware.
1252 */
1253 drv->capa.flags |= WPA_DRIVER_FLAGS_AP_MLME;
1254 }
1255
1256 drv->device_ap_sme = info.device_ap_sme;
1257 drv->poll_command_supported = info.poll_command_supported;
1258 drv->data_tx_status = info.data_tx_status;
1259 drv->p2p_go_ctwindow_supported = info.p2p_go_ctwindow_supported;
1260 if (info.set_qos_map_supported)
1261 drv->capa.flags |= WPA_DRIVER_FLAGS_QOS_MAPPING;
1262 drv->have_low_prio_scan = info.have_low_prio_scan;
1263
1264 /*
1265 * If poll command and tx status are supported, mac80211 is new enough
1266 * to have everything we need to not need monitor interfaces.
1267 */
1268 drv->use_monitor = !info.device_ap_sme &&
1269 (!info.poll_command_supported || !info.data_tx_status);
1270
1271 /*
1272 * If we aren't going to use monitor interfaces, but the
1273 * driver doesn't support data TX status, we won't get TX
1274 * status for EAPOL frames.
1275 */
1276 if (!drv->use_monitor && !info.data_tx_status)
1277 drv->capa.flags &= ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS;
1278
1279 #ifdef CONFIG_DRIVER_NL80211_QCA
1280 if (!(info.capa->flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD))
1281 qca_nl80211_check_dfs_capa(drv);
1282 qca_nl80211_get_features(drv);
1283
1284 /*
1285 * To enable offchannel simultaneous support in wpa_supplicant, the
1286 * underlying driver needs to support the same along with offchannel TX.
1287 * Offchannel TX support is needed since remain_on_channel and
1288 * action_tx use some common data structures and hence cannot be
1289 * scheduled simultaneously.
1290 */
1291 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX))
1292 drv->capa.flags &= ~WPA_DRIVER_FLAGS_OFFCHANNEL_SIMULTANEOUS;
1293 #endif /* CONFIG_DRIVER_NL80211_QCA */
1294
1295 return 0;
1296 }
1297
1298
1299 struct phy_info_arg {
1300 u16 *num_modes;
1301 struct hostapd_hw_modes *modes;
1302 int last_mode, last_chan_idx;
1303 int failed;
1304 u8 dfs_domain;
1305 };
1306
phy_info_ht_capa(struct hostapd_hw_modes * mode,struct nlattr * capa,struct nlattr * ampdu_factor,struct nlattr * ampdu_density,struct nlattr * mcs_set)1307 static void phy_info_ht_capa(struct hostapd_hw_modes *mode, struct nlattr *capa,
1308 struct nlattr *ampdu_factor,
1309 struct nlattr *ampdu_density,
1310 struct nlattr *mcs_set)
1311 {
1312 if (capa)
1313 mode->ht_capab = nla_get_u16(capa);
1314
1315 if (ampdu_factor)
1316 mode->a_mpdu_params |= nla_get_u8(ampdu_factor) & 0x03;
1317
1318 if (ampdu_density)
1319 mode->a_mpdu_params |= nla_get_u8(ampdu_density) << 2;
1320
1321 if (mcs_set && nla_len(mcs_set) >= 16) {
1322 u8 *mcs;
1323 mcs = nla_data(mcs_set);
1324 os_memcpy(mode->mcs_set, mcs, 16);
1325 }
1326 }
1327
1328
phy_info_vht_capa(struct hostapd_hw_modes * mode,struct nlattr * capa,struct nlattr * mcs_set)1329 static void phy_info_vht_capa(struct hostapd_hw_modes *mode,
1330 struct nlattr *capa,
1331 struct nlattr *mcs_set)
1332 {
1333 if (capa)
1334 mode->vht_capab = nla_get_u32(capa);
1335
1336 if (mcs_set && nla_len(mcs_set) >= 8) {
1337 u8 *mcs;
1338 mcs = nla_data(mcs_set);
1339 os_memcpy(mode->vht_mcs_set, mcs, 8);
1340 }
1341 }
1342
1343
phy_info_freq(struct hostapd_hw_modes * mode,struct hostapd_channel_data * chan,struct nlattr * tb_freq[])1344 static void phy_info_freq(struct hostapd_hw_modes *mode,
1345 struct hostapd_channel_data *chan,
1346 struct nlattr *tb_freq[])
1347 {
1348 u8 channel;
1349 chan->freq = nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_FREQ]);
1350 chan->flag = 0;
1351 chan->allowed_bw = ~0;
1352 chan->dfs_cac_ms = 0;
1353 if (ieee80211_freq_to_chan(chan->freq, &channel) != NUM_HOSTAPD_MODES)
1354 chan->chan = channel;
1355
1356 if (tb_freq[NL80211_FREQUENCY_ATTR_DISABLED])
1357 chan->flag |= HOSTAPD_CHAN_DISABLED;
1358 if (tb_freq[NL80211_FREQUENCY_ATTR_NO_IR])
1359 chan->flag |= HOSTAPD_CHAN_NO_IR;
1360 if (tb_freq[NL80211_FREQUENCY_ATTR_RADAR])
1361 chan->flag |= HOSTAPD_CHAN_RADAR;
1362 if (tb_freq[NL80211_FREQUENCY_ATTR_INDOOR_ONLY])
1363 chan->flag |= HOSTAPD_CHAN_INDOOR_ONLY;
1364 if (tb_freq[NL80211_FREQUENCY_ATTR_GO_CONCURRENT])
1365 chan->flag |= HOSTAPD_CHAN_GO_CONCURRENT;
1366
1367 if (tb_freq[NL80211_FREQUENCY_ATTR_NO_10MHZ])
1368 chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_10;
1369 if (tb_freq[NL80211_FREQUENCY_ATTR_NO_20MHZ])
1370 chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_20;
1371 if (tb_freq[NL80211_FREQUENCY_ATTR_NO_HT40_PLUS])
1372 chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_40P;
1373 if (tb_freq[NL80211_FREQUENCY_ATTR_NO_HT40_MINUS])
1374 chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_40M;
1375 if (tb_freq[NL80211_FREQUENCY_ATTR_NO_80MHZ])
1376 chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_80;
1377 if (tb_freq[NL80211_FREQUENCY_ATTR_NO_160MHZ])
1378 chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_160;
1379
1380 if (tb_freq[NL80211_FREQUENCY_ATTR_DFS_STATE]) {
1381 enum nl80211_dfs_state state =
1382 nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_DFS_STATE]);
1383
1384 switch (state) {
1385 case NL80211_DFS_USABLE:
1386 chan->flag |= HOSTAPD_CHAN_DFS_USABLE;
1387 break;
1388 case NL80211_DFS_AVAILABLE:
1389 chan->flag |= HOSTAPD_CHAN_DFS_AVAILABLE;
1390 break;
1391 case NL80211_DFS_UNAVAILABLE:
1392 chan->flag |= HOSTAPD_CHAN_DFS_UNAVAILABLE;
1393 break;
1394 }
1395 }
1396
1397 if (tb_freq[NL80211_FREQUENCY_ATTR_DFS_CAC_TIME]) {
1398 chan->dfs_cac_ms = nla_get_u32(
1399 tb_freq[NL80211_FREQUENCY_ATTR_DFS_CAC_TIME]);
1400 }
1401
1402 chan->wmm_rules_valid = 0;
1403 if (tb_freq[NL80211_FREQUENCY_ATTR_WMM]) {
1404 static struct nla_policy wmm_policy[NL80211_WMMR_MAX + 1] = {
1405 [NL80211_WMMR_CW_MIN] = { .type = NLA_U16 },
1406 [NL80211_WMMR_CW_MAX] = { .type = NLA_U16 },
1407 [NL80211_WMMR_AIFSN] = { .type = NLA_U8 },
1408 [NL80211_WMMR_TXOP] = { .type = NLA_U16 },
1409 };
1410 struct nlattr *nl_wmm;
1411 struct nlattr *tb_wmm[NL80211_WMMR_MAX + 1];
1412 int rem_wmm, ac, count = 0;
1413
1414 nla_for_each_nested(nl_wmm, tb_freq[NL80211_FREQUENCY_ATTR_WMM],
1415 rem_wmm) {
1416 if (nla_parse_nested(tb_wmm, NL80211_WMMR_MAX, nl_wmm,
1417 wmm_policy)) {
1418 wpa_printf(MSG_DEBUG,
1419 "nl80211: Failed to parse WMM rules attribute");
1420 return;
1421 }
1422 if (!tb_wmm[NL80211_WMMR_CW_MIN] ||
1423 !tb_wmm[NL80211_WMMR_CW_MAX] ||
1424 !tb_wmm[NL80211_WMMR_AIFSN] ||
1425 !tb_wmm[NL80211_WMMR_TXOP]) {
1426 wpa_printf(MSG_DEBUG,
1427 "nl80211: Channel is missing WMM rule attribute");
1428 return;
1429 }
1430 ac = nl_wmm->nla_type;
1431 if (ac < 0 || ac >= WMM_AC_NUM) {
1432 wpa_printf(MSG_DEBUG,
1433 "nl80211: Invalid AC value %d", ac);
1434 return;
1435 }
1436
1437 chan->wmm_rules[ac].min_cwmin =
1438 nla_get_u16(tb_wmm[NL80211_WMMR_CW_MIN]);
1439 chan->wmm_rules[ac].min_cwmax =
1440 nla_get_u16(tb_wmm[NL80211_WMMR_CW_MAX]);
1441 chan->wmm_rules[ac].min_aifs =
1442 nla_get_u8(tb_wmm[NL80211_WMMR_AIFSN]);
1443 chan->wmm_rules[ac].max_txop =
1444 nla_get_u16(tb_wmm[NL80211_WMMR_TXOP]) / 32;
1445 count++;
1446 }
1447
1448 /* Set valid flag if all the AC rules are present */
1449 if (count == WMM_AC_NUM)
1450 chan->wmm_rules_valid = 1;
1451 }
1452 }
1453
1454
phy_info_freqs(struct phy_info_arg * phy_info,struct hostapd_hw_modes * mode,struct nlattr * tb)1455 static int phy_info_freqs(struct phy_info_arg *phy_info,
1456 struct hostapd_hw_modes *mode, struct nlattr *tb)
1457 {
1458 static struct nla_policy freq_policy[NL80211_FREQUENCY_ATTR_MAX + 1] = {
1459 [NL80211_FREQUENCY_ATTR_FREQ] = { .type = NLA_U32 },
1460 [NL80211_FREQUENCY_ATTR_DISABLED] = { .type = NLA_FLAG },
1461 [NL80211_FREQUENCY_ATTR_NO_IR] = { .type = NLA_FLAG },
1462 [NL80211_FREQUENCY_ATTR_RADAR] = { .type = NLA_FLAG },
1463 [NL80211_FREQUENCY_ATTR_MAX_TX_POWER] = { .type = NLA_U32 },
1464 [NL80211_FREQUENCY_ATTR_DFS_STATE] = { .type = NLA_U32 },
1465 [NL80211_FREQUENCY_ATTR_NO_10MHZ] = { .type = NLA_FLAG },
1466 [NL80211_FREQUENCY_ATTR_NO_20MHZ] = { .type = NLA_FLAG },
1467 [NL80211_FREQUENCY_ATTR_NO_HT40_PLUS] = { .type = NLA_FLAG },
1468 [NL80211_FREQUENCY_ATTR_NO_HT40_MINUS] = { .type = NLA_FLAG },
1469 [NL80211_FREQUENCY_ATTR_NO_80MHZ] = { .type = NLA_FLAG },
1470 [NL80211_FREQUENCY_ATTR_NO_160MHZ] = { .type = NLA_FLAG },
1471 };
1472 int new_channels = 0;
1473 struct hostapd_channel_data *channel;
1474 struct nlattr *tb_freq[NL80211_FREQUENCY_ATTR_MAX + 1];
1475 struct nlattr *nl_freq;
1476 int rem_freq, idx;
1477
1478 if (tb == NULL)
1479 return NL_OK;
1480
1481 nla_for_each_nested(nl_freq, tb, rem_freq) {
1482 nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX,
1483 nla_data(nl_freq), nla_len(nl_freq), freq_policy);
1484 if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ])
1485 continue;
1486 new_channels++;
1487 }
1488
1489 channel = os_realloc_array(mode->channels,
1490 mode->num_channels + new_channels,
1491 sizeof(struct hostapd_channel_data));
1492 if (!channel)
1493 return NL_STOP;
1494
1495 mode->channels = channel;
1496 mode->num_channels += new_channels;
1497
1498 idx = phy_info->last_chan_idx;
1499
1500 nla_for_each_nested(nl_freq, tb, rem_freq) {
1501 nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX,
1502 nla_data(nl_freq), nla_len(nl_freq), freq_policy);
1503 if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ])
1504 continue;
1505 phy_info_freq(mode, &mode->channels[idx], tb_freq);
1506 idx++;
1507 }
1508 phy_info->last_chan_idx = idx;
1509
1510 return NL_OK;
1511 }
1512
1513
phy_info_rates(struct hostapd_hw_modes * mode,struct nlattr * tb)1514 static int phy_info_rates(struct hostapd_hw_modes *mode, struct nlattr *tb)
1515 {
1516 static struct nla_policy rate_policy[NL80211_BITRATE_ATTR_MAX + 1] = {
1517 [NL80211_BITRATE_ATTR_RATE] = { .type = NLA_U32 },
1518 [NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE] =
1519 { .type = NLA_FLAG },
1520 };
1521 struct nlattr *tb_rate[NL80211_BITRATE_ATTR_MAX + 1];
1522 struct nlattr *nl_rate;
1523 int rem_rate, idx;
1524
1525 if (tb == NULL)
1526 return NL_OK;
1527
1528 nla_for_each_nested(nl_rate, tb, rem_rate) {
1529 nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX,
1530 nla_data(nl_rate), nla_len(nl_rate),
1531 rate_policy);
1532 if (!tb_rate[NL80211_BITRATE_ATTR_RATE])
1533 continue;
1534 mode->num_rates++;
1535 }
1536
1537 mode->rates = os_calloc(mode->num_rates, sizeof(int));
1538 if (!mode->rates)
1539 return NL_STOP;
1540
1541 idx = 0;
1542
1543 nla_for_each_nested(nl_rate, tb, rem_rate) {
1544 nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX,
1545 nla_data(nl_rate), nla_len(nl_rate),
1546 rate_policy);
1547 if (!tb_rate[NL80211_BITRATE_ATTR_RATE])
1548 continue;
1549 mode->rates[idx] = nla_get_u32(
1550 tb_rate[NL80211_BITRATE_ATTR_RATE]);
1551 idx++;
1552 }
1553
1554 return NL_OK;
1555 }
1556
1557
phy_info_iftype_copy(struct he_capabilities * he_capab,enum ieee80211_op_mode opmode,struct nlattr ** tb,struct nlattr ** tb_flags)1558 static void phy_info_iftype_copy(struct he_capabilities *he_capab,
1559 enum ieee80211_op_mode opmode,
1560 struct nlattr **tb, struct nlattr **tb_flags)
1561 {
1562 enum nl80211_iftype iftype;
1563 size_t len;
1564
1565 switch (opmode) {
1566 case IEEE80211_MODE_INFRA:
1567 iftype = NL80211_IFTYPE_STATION;
1568 break;
1569 case IEEE80211_MODE_IBSS:
1570 iftype = NL80211_IFTYPE_ADHOC;
1571 break;
1572 case IEEE80211_MODE_AP:
1573 iftype = NL80211_IFTYPE_AP;
1574 break;
1575 case IEEE80211_MODE_MESH:
1576 iftype = NL80211_IFTYPE_MESH_POINT;
1577 break;
1578 default:
1579 return;
1580 }
1581
1582 if (!nla_get_flag(tb_flags[iftype]))
1583 return;
1584
1585 he_capab->he_supported = 1;
1586
1587 if (tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY]) {
1588 len = nla_len(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY]);
1589
1590 if (len > sizeof(he_capab->phy_cap))
1591 len = sizeof(he_capab->phy_cap);
1592 os_memcpy(he_capab->phy_cap,
1593 nla_data(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY]),
1594 len);
1595 }
1596
1597 if (tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC]) {
1598 len = nla_len(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC]);
1599
1600 if (len > sizeof(he_capab->mac_cap))
1601 len = sizeof(he_capab->mac_cap);
1602 os_memcpy(he_capab->mac_cap,
1603 nla_data(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC]),
1604 len);
1605 }
1606
1607 if (tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET]) {
1608 len = nla_len(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET]);
1609
1610 if (len > sizeof(he_capab->mcs))
1611 len = sizeof(he_capab->mcs);
1612 os_memcpy(he_capab->mcs,
1613 nla_data(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET]),
1614 len);
1615 }
1616
1617 if (tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE]) {
1618 len = nla_len(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE]);
1619
1620 if (len > sizeof(he_capab->ppet))
1621 len = sizeof(he_capab->ppet);
1622 os_memcpy(&he_capab->ppet,
1623 nla_data(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE]),
1624 len);
1625 }
1626 }
1627
1628
phy_info_iftype(struct hostapd_hw_modes * mode,struct nlattr * nl_iftype)1629 static int phy_info_iftype(struct hostapd_hw_modes *mode,
1630 struct nlattr *nl_iftype)
1631 {
1632 struct nlattr *tb[NL80211_BAND_IFTYPE_ATTR_MAX + 1];
1633 struct nlattr *tb_flags[NL80211_IFTYPE_MAX + 1];
1634 unsigned int i;
1635
1636 nla_parse(tb, NL80211_BAND_IFTYPE_ATTR_MAX,
1637 nla_data(nl_iftype), nla_len(nl_iftype), NULL);
1638
1639 if (!tb[NL80211_BAND_IFTYPE_ATTR_IFTYPES])
1640 return NL_STOP;
1641
1642 if (nla_parse_nested(tb_flags, NL80211_IFTYPE_MAX,
1643 tb[NL80211_BAND_IFTYPE_ATTR_IFTYPES], NULL))
1644 return NL_STOP;
1645
1646 for (i = 0; i < IEEE80211_MODE_NUM; i++)
1647 phy_info_iftype_copy(&mode->he_capab[i], i, tb, tb_flags);
1648
1649 return NL_OK;
1650 }
1651
1652
phy_info_band(struct phy_info_arg * phy_info,struct nlattr * nl_band)1653 static int phy_info_band(struct phy_info_arg *phy_info, struct nlattr *nl_band)
1654 {
1655 struct nlattr *tb_band[NL80211_BAND_ATTR_MAX + 1];
1656 struct hostapd_hw_modes *mode;
1657 int ret;
1658
1659 if (phy_info->last_mode != nl_band->nla_type) {
1660 mode = os_realloc_array(phy_info->modes,
1661 *phy_info->num_modes + 1,
1662 sizeof(*mode));
1663 if (!mode) {
1664 phy_info->failed = 1;
1665 return NL_STOP;
1666 }
1667 phy_info->modes = mode;
1668
1669 mode = &phy_info->modes[*(phy_info->num_modes)];
1670 os_memset(mode, 0, sizeof(*mode));
1671 mode->mode = NUM_HOSTAPD_MODES;
1672 mode->flags = HOSTAPD_MODE_FLAG_HT_INFO_KNOWN |
1673 HOSTAPD_MODE_FLAG_VHT_INFO_KNOWN;
1674
1675 /*
1676 * Unsupported VHT MCS stream is defined as value 3, so the VHT
1677 * MCS RX/TX map must be initialized with 0xffff to mark all 8
1678 * possible streams as unsupported. This will be overridden if
1679 * driver advertises VHT support.
1680 */
1681 mode->vht_mcs_set[0] = 0xff;
1682 mode->vht_mcs_set[1] = 0xff;
1683 mode->vht_mcs_set[4] = 0xff;
1684 mode->vht_mcs_set[5] = 0xff;
1685
1686 *(phy_info->num_modes) += 1;
1687 phy_info->last_mode = nl_band->nla_type;
1688 phy_info->last_chan_idx = 0;
1689 } else
1690 mode = &phy_info->modes[*(phy_info->num_modes) - 1];
1691
1692 nla_parse(tb_band, NL80211_BAND_ATTR_MAX, nla_data(nl_band),
1693 nla_len(nl_band), NULL);
1694
1695 phy_info_ht_capa(mode, tb_band[NL80211_BAND_ATTR_HT_CAPA],
1696 tb_band[NL80211_BAND_ATTR_HT_AMPDU_FACTOR],
1697 tb_band[NL80211_BAND_ATTR_HT_AMPDU_DENSITY],
1698 tb_band[NL80211_BAND_ATTR_HT_MCS_SET]);
1699 phy_info_vht_capa(mode, tb_band[NL80211_BAND_ATTR_VHT_CAPA],
1700 tb_band[NL80211_BAND_ATTR_VHT_MCS_SET]);
1701 ret = phy_info_freqs(phy_info, mode, tb_band[NL80211_BAND_ATTR_FREQS]);
1702 if (ret == NL_OK)
1703 ret = phy_info_rates(mode, tb_band[NL80211_BAND_ATTR_RATES]);
1704 if (ret != NL_OK) {
1705 phy_info->failed = 1;
1706 return ret;
1707 }
1708
1709 if (tb_band[NL80211_BAND_ATTR_IFTYPE_DATA]) {
1710 struct nlattr *nl_iftype;
1711 int rem_band;
1712
1713 nla_for_each_nested(nl_iftype,
1714 tb_band[NL80211_BAND_ATTR_IFTYPE_DATA],
1715 rem_band) {
1716 ret = phy_info_iftype(mode, nl_iftype);
1717 if (ret != NL_OK)
1718 return ret;
1719 }
1720 }
1721
1722 return NL_OK;
1723 }
1724
1725
phy_info_handler(struct nl_msg * msg,void * arg)1726 static int phy_info_handler(struct nl_msg *msg, void *arg)
1727 {
1728 struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
1729 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1730 struct phy_info_arg *phy_info = arg;
1731 struct nlattr *nl_band;
1732 int rem_band;
1733
1734 nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1735 genlmsg_attrlen(gnlh, 0), NULL);
1736
1737 if (!tb_msg[NL80211_ATTR_WIPHY_BANDS])
1738 return NL_SKIP;
1739
1740 nla_for_each_nested(nl_band, tb_msg[NL80211_ATTR_WIPHY_BANDS], rem_band)
1741 {
1742 int res = phy_info_band(phy_info, nl_band);
1743 if (res != NL_OK)
1744 return res;
1745 }
1746
1747 return NL_SKIP;
1748 }
1749
1750
1751 static struct hostapd_hw_modes *
wpa_driver_nl80211_postprocess_modes(struct hostapd_hw_modes * modes,u16 * num_modes)1752 wpa_driver_nl80211_postprocess_modes(struct hostapd_hw_modes *modes,
1753 u16 *num_modes)
1754 {
1755 u16 m;
1756 struct hostapd_hw_modes *mode11g = NULL, *nmodes, *mode;
1757 int i, mode11g_idx = -1;
1758
1759 /* heuristic to set up modes */
1760 for (m = 0; m < *num_modes; m++) {
1761 if (!modes[m].num_channels)
1762 continue;
1763 if (modes[m].channels[0].freq < 4000) {
1764 modes[m].mode = HOSTAPD_MODE_IEEE80211B;
1765 for (i = 0; i < modes[m].num_rates; i++) {
1766 if (modes[m].rates[i] > 200) {
1767 modes[m].mode = HOSTAPD_MODE_IEEE80211G;
1768 break;
1769 }
1770 }
1771 } else if (modes[m].channels[0].freq > 50000)
1772 modes[m].mode = HOSTAPD_MODE_IEEE80211AD;
1773 else
1774 modes[m].mode = HOSTAPD_MODE_IEEE80211A;
1775 }
1776
1777 /* If only 802.11g mode is included, use it to construct matching
1778 * 802.11b mode data. */
1779
1780 for (m = 0; m < *num_modes; m++) {
1781 if (modes[m].mode == HOSTAPD_MODE_IEEE80211B)
1782 return modes; /* 802.11b already included */
1783 if (modes[m].mode == HOSTAPD_MODE_IEEE80211G)
1784 mode11g_idx = m;
1785 }
1786
1787 if (mode11g_idx < 0)
1788 return modes; /* 2.4 GHz band not supported at all */
1789
1790 nmodes = os_realloc_array(modes, *num_modes + 1, sizeof(*nmodes));
1791 if (nmodes == NULL)
1792 return modes; /* Could not add 802.11b mode */
1793
1794 mode = &nmodes[*num_modes];
1795 os_memset(mode, 0, sizeof(*mode));
1796 (*num_modes)++;
1797 modes = nmodes;
1798
1799 mode->mode = HOSTAPD_MODE_IEEE80211B;
1800
1801 mode11g = &modes[mode11g_idx];
1802 mode->num_channels = mode11g->num_channels;
1803 mode->channels = os_memdup(mode11g->channels,
1804 mode11g->num_channels *
1805 sizeof(struct hostapd_channel_data));
1806 if (mode->channels == NULL) {
1807 (*num_modes)--;
1808 return modes; /* Could not add 802.11b mode */
1809 }
1810
1811 mode->num_rates = 0;
1812 mode->rates = os_malloc(4 * sizeof(int));
1813 if (mode->rates == NULL) {
1814 os_free(mode->channels);
1815 (*num_modes)--;
1816 return modes; /* Could not add 802.11b mode */
1817 }
1818
1819 for (i = 0; i < mode11g->num_rates; i++) {
1820 if (mode11g->rates[i] != 10 && mode11g->rates[i] != 20 &&
1821 mode11g->rates[i] != 55 && mode11g->rates[i] != 110)
1822 continue;
1823 mode->rates[mode->num_rates] = mode11g->rates[i];
1824 mode->num_rates++;
1825 if (mode->num_rates == 4)
1826 break;
1827 }
1828
1829 if (mode->num_rates == 0) {
1830 os_free(mode->channels);
1831 os_free(mode->rates);
1832 (*num_modes)--;
1833 return modes; /* No 802.11b rates */
1834 }
1835
1836 wpa_printf(MSG_DEBUG, "nl80211: Added 802.11b mode based on 802.11g "
1837 "information");
1838
1839 return modes;
1840 }
1841
1842
nl80211_set_ht40_mode(struct hostapd_hw_modes * mode,int start,int end)1843 static void nl80211_set_ht40_mode(struct hostapd_hw_modes *mode, int start,
1844 int end)
1845 {
1846 int c;
1847
1848 for (c = 0; c < mode->num_channels; c++) {
1849 struct hostapd_channel_data *chan = &mode->channels[c];
1850 if (chan->freq - 10 >= start && chan->freq + 10 <= end)
1851 chan->flag |= HOSTAPD_CHAN_HT40;
1852 }
1853 }
1854
1855
nl80211_set_ht40_mode_sec(struct hostapd_hw_modes * mode,int start,int end)1856 static void nl80211_set_ht40_mode_sec(struct hostapd_hw_modes *mode, int start,
1857 int end)
1858 {
1859 int c;
1860
1861 for (c = 0; c < mode->num_channels; c++) {
1862 struct hostapd_channel_data *chan = &mode->channels[c];
1863 if (!(chan->flag & HOSTAPD_CHAN_HT40))
1864 continue;
1865 if (chan->freq - 30 >= start && chan->freq - 10 <= end)
1866 chan->flag |= HOSTAPD_CHAN_HT40MINUS;
1867 if (chan->freq + 10 >= start && chan->freq + 30 <= end)
1868 chan->flag |= HOSTAPD_CHAN_HT40PLUS;
1869 }
1870 }
1871
1872
nl80211_reg_rule_max_eirp(u32 start,u32 end,u32 max_eirp,struct phy_info_arg * results)1873 static void nl80211_reg_rule_max_eirp(u32 start, u32 end, u32 max_eirp,
1874 struct phy_info_arg *results)
1875 {
1876 u16 m;
1877
1878 for (m = 0; m < *results->num_modes; m++) {
1879 int c;
1880 struct hostapd_hw_modes *mode = &results->modes[m];
1881
1882 for (c = 0; c < mode->num_channels; c++) {
1883 struct hostapd_channel_data *chan = &mode->channels[c];
1884 if ((u32) chan->freq - 10 >= start &&
1885 (u32) chan->freq + 10 <= end)
1886 chan->max_tx_power = max_eirp;
1887 }
1888 }
1889 }
1890
1891
nl80211_reg_rule_ht40(u32 start,u32 end,struct phy_info_arg * results)1892 static void nl80211_reg_rule_ht40(u32 start, u32 end,
1893 struct phy_info_arg *results)
1894 {
1895 u16 m;
1896
1897 for (m = 0; m < *results->num_modes; m++) {
1898 if (!(results->modes[m].ht_capab &
1899 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET))
1900 continue;
1901 nl80211_set_ht40_mode(&results->modes[m], start, end);
1902 }
1903 }
1904
1905
nl80211_reg_rule_sec(struct nlattr * tb[],struct phy_info_arg * results)1906 static void nl80211_reg_rule_sec(struct nlattr *tb[],
1907 struct phy_info_arg *results)
1908 {
1909 u32 start, end, max_bw;
1910 u16 m;
1911
1912 if (tb[NL80211_ATTR_FREQ_RANGE_START] == NULL ||
1913 tb[NL80211_ATTR_FREQ_RANGE_END] == NULL ||
1914 tb[NL80211_ATTR_FREQ_RANGE_MAX_BW] == NULL)
1915 return;
1916
1917 start = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]) / 1000;
1918 end = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]) / 1000;
1919 max_bw = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) / 1000;
1920
1921 if (max_bw < 20)
1922 return;
1923
1924 for (m = 0; m < *results->num_modes; m++) {
1925 if (!(results->modes[m].ht_capab &
1926 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET))
1927 continue;
1928 nl80211_set_ht40_mode_sec(&results->modes[m], start, end);
1929 }
1930 }
1931
1932
nl80211_set_vht_mode(struct hostapd_hw_modes * mode,int start,int end,int max_bw)1933 static void nl80211_set_vht_mode(struct hostapd_hw_modes *mode, int start,
1934 int end, int max_bw)
1935 {
1936 int c;
1937
1938 for (c = 0; c < mode->num_channels; c++) {
1939 struct hostapd_channel_data *chan = &mode->channels[c];
1940 if (chan->freq - 10 >= start && chan->freq + 70 <= end)
1941 chan->flag |= HOSTAPD_CHAN_VHT_10_70;
1942
1943 if (chan->freq - 30 >= start && chan->freq + 50 <= end)
1944 chan->flag |= HOSTAPD_CHAN_VHT_30_50;
1945
1946 if (chan->freq - 50 >= start && chan->freq + 30 <= end)
1947 chan->flag |= HOSTAPD_CHAN_VHT_50_30;
1948
1949 if (chan->freq - 70 >= start && chan->freq + 10 <= end)
1950 chan->flag |= HOSTAPD_CHAN_VHT_70_10;
1951
1952 if (max_bw >= 160) {
1953 if (chan->freq - 10 >= start && chan->freq + 150 <= end)
1954 chan->flag |= HOSTAPD_CHAN_VHT_10_150;
1955
1956 if (chan->freq - 30 >= start && chan->freq + 130 <= end)
1957 chan->flag |= HOSTAPD_CHAN_VHT_30_130;
1958
1959 if (chan->freq - 50 >= start && chan->freq + 110 <= end)
1960 chan->flag |= HOSTAPD_CHAN_VHT_50_110;
1961
1962 if (chan->freq - 70 >= start && chan->freq + 90 <= end)
1963 chan->flag |= HOSTAPD_CHAN_VHT_70_90;
1964
1965 if (chan->freq - 90 >= start && chan->freq + 70 <= end)
1966 chan->flag |= HOSTAPD_CHAN_VHT_90_70;
1967
1968 if (chan->freq - 110 >= start && chan->freq + 50 <= end)
1969 chan->flag |= HOSTAPD_CHAN_VHT_110_50;
1970
1971 if (chan->freq - 130 >= start && chan->freq + 30 <= end)
1972 chan->flag |= HOSTAPD_CHAN_VHT_130_30;
1973
1974 if (chan->freq - 150 >= start && chan->freq + 10 <= end)
1975 chan->flag |= HOSTAPD_CHAN_VHT_150_10;
1976 }
1977 }
1978 }
1979
1980
nl80211_reg_rule_vht(struct nlattr * tb[],struct phy_info_arg * results)1981 static void nl80211_reg_rule_vht(struct nlattr *tb[],
1982 struct phy_info_arg *results)
1983 {
1984 u32 start, end, max_bw;
1985 u16 m;
1986
1987 if (tb[NL80211_ATTR_FREQ_RANGE_START] == NULL ||
1988 tb[NL80211_ATTR_FREQ_RANGE_END] == NULL ||
1989 tb[NL80211_ATTR_FREQ_RANGE_MAX_BW] == NULL)
1990 return;
1991
1992 start = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]) / 1000;
1993 end = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]) / 1000;
1994 max_bw = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) / 1000;
1995
1996 if (max_bw < 80)
1997 return;
1998
1999 for (m = 0; m < *results->num_modes; m++) {
2000 if (!(results->modes[m].ht_capab &
2001 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET))
2002 continue;
2003 /* TODO: use a real VHT support indication */
2004 if (!results->modes[m].vht_capab)
2005 continue;
2006
2007 nl80211_set_vht_mode(&results->modes[m], start, end, max_bw);
2008 }
2009 }
2010
2011
nl80211_set_dfs_domain(enum nl80211_dfs_regions region,u8 * dfs_domain)2012 static void nl80211_set_dfs_domain(enum nl80211_dfs_regions region,
2013 u8 *dfs_domain)
2014 {
2015 if (region == NL80211_DFS_FCC)
2016 *dfs_domain = HOSTAPD_DFS_REGION_FCC;
2017 else if (region == NL80211_DFS_ETSI)
2018 *dfs_domain = HOSTAPD_DFS_REGION_ETSI;
2019 else if (region == NL80211_DFS_JP)
2020 *dfs_domain = HOSTAPD_DFS_REGION_JP;
2021 else
2022 *dfs_domain = 0;
2023 }
2024
2025
dfs_domain_name(enum nl80211_dfs_regions region)2026 static const char * dfs_domain_name(enum nl80211_dfs_regions region)
2027 {
2028 switch (region) {
2029 case NL80211_DFS_UNSET:
2030 return "DFS-UNSET";
2031 case NL80211_DFS_FCC:
2032 return "DFS-FCC";
2033 case NL80211_DFS_ETSI:
2034 return "DFS-ETSI";
2035 case NL80211_DFS_JP:
2036 return "DFS-JP";
2037 default:
2038 return "DFS-invalid";
2039 }
2040 }
2041
2042
nl80211_get_reg(struct nl_msg * msg,void * arg)2043 static int nl80211_get_reg(struct nl_msg *msg, void *arg)
2044 {
2045 struct phy_info_arg *results = arg;
2046 struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
2047 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
2048 struct nlattr *nl_rule;
2049 struct nlattr *tb_rule[NL80211_FREQUENCY_ATTR_MAX + 1];
2050 int rem_rule;
2051 static struct nla_policy reg_policy[NL80211_FREQUENCY_ATTR_MAX + 1] = {
2052 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
2053 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
2054 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
2055 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
2056 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
2057 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
2058 };
2059
2060 nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
2061 genlmsg_attrlen(gnlh, 0), NULL);
2062 if (!tb_msg[NL80211_ATTR_REG_ALPHA2] ||
2063 !tb_msg[NL80211_ATTR_REG_RULES]) {
2064 wpa_printf(MSG_DEBUG, "nl80211: No regulatory information "
2065 "available");
2066 return NL_SKIP;
2067 }
2068
2069 if (tb_msg[NL80211_ATTR_DFS_REGION]) {
2070 enum nl80211_dfs_regions dfs_domain;
2071 dfs_domain = nla_get_u8(tb_msg[NL80211_ATTR_DFS_REGION]);
2072 nl80211_set_dfs_domain(dfs_domain, &results->dfs_domain);
2073 wpa_printf(MSG_DEBUG, "nl80211: Regulatory information - country=%s (%s)",
2074 (char *) nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]),
2075 dfs_domain_name(dfs_domain));
2076 } else {
2077 wpa_printf(MSG_DEBUG, "nl80211: Regulatory information - country=%s",
2078 (char *) nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]));
2079 }
2080
2081 nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule)
2082 {
2083 u32 start, end, max_eirp = 0, max_bw = 0, flags = 0;
2084 nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX,
2085 nla_data(nl_rule), nla_len(nl_rule), reg_policy);
2086 if (tb_rule[NL80211_ATTR_FREQ_RANGE_START] == NULL ||
2087 tb_rule[NL80211_ATTR_FREQ_RANGE_END] == NULL)
2088 continue;
2089 start = nla_get_u32(tb_rule[NL80211_ATTR_FREQ_RANGE_START]) / 1000;
2090 end = nla_get_u32(tb_rule[NL80211_ATTR_FREQ_RANGE_END]) / 1000;
2091 if (tb_rule[NL80211_ATTR_POWER_RULE_MAX_EIRP])
2092 max_eirp = nla_get_u32(tb_rule[NL80211_ATTR_POWER_RULE_MAX_EIRP]) / 100;
2093 if (tb_rule[NL80211_ATTR_FREQ_RANGE_MAX_BW])
2094 max_bw = nla_get_u32(tb_rule[NL80211_ATTR_FREQ_RANGE_MAX_BW]) / 1000;
2095 if (tb_rule[NL80211_ATTR_REG_RULE_FLAGS])
2096 flags = nla_get_u32(tb_rule[NL80211_ATTR_REG_RULE_FLAGS]);
2097
2098 wpa_printf(MSG_DEBUG, "nl80211: %u-%u @ %u MHz %u mBm%s%s%s%s%s%s%s%s",
2099 start, end, max_bw, max_eirp,
2100 flags & NL80211_RRF_NO_OFDM ? " (no OFDM)" : "",
2101 flags & NL80211_RRF_NO_CCK ? " (no CCK)" : "",
2102 flags & NL80211_RRF_NO_INDOOR ? " (no indoor)" : "",
2103 flags & NL80211_RRF_NO_OUTDOOR ? " (no outdoor)" :
2104 "",
2105 flags & NL80211_RRF_DFS ? " (DFS)" : "",
2106 flags & NL80211_RRF_PTP_ONLY ? " (PTP only)" : "",
2107 flags & NL80211_RRF_PTMP_ONLY ? " (PTMP only)" : "",
2108 flags & NL80211_RRF_NO_IR ? " (no IR)" : "");
2109 if (max_bw >= 40)
2110 nl80211_reg_rule_ht40(start, end, results);
2111 if (tb_rule[NL80211_ATTR_POWER_RULE_MAX_EIRP])
2112 nl80211_reg_rule_max_eirp(start, end, max_eirp,
2113 results);
2114 }
2115
2116 nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule)
2117 {
2118 nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX,
2119 nla_data(nl_rule), nla_len(nl_rule), reg_policy);
2120 nl80211_reg_rule_sec(tb_rule, results);
2121 }
2122
2123 nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule)
2124 {
2125 nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX,
2126 nla_data(nl_rule), nla_len(nl_rule), reg_policy);
2127 nl80211_reg_rule_vht(tb_rule, results);
2128 }
2129
2130 return NL_SKIP;
2131 }
2132
2133
nl80211_set_regulatory_flags(struct wpa_driver_nl80211_data * drv,struct phy_info_arg * results)2134 static int nl80211_set_regulatory_flags(struct wpa_driver_nl80211_data *drv,
2135 struct phy_info_arg *results)
2136 {
2137 struct nl_msg *msg;
2138
2139 msg = nlmsg_alloc();
2140 if (!msg)
2141 return -ENOMEM;
2142
2143 nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG);
2144 if (drv->capa.flags & WPA_DRIVER_FLAGS_SELF_MANAGED_REGULATORY) {
2145 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, drv->wiphy_idx)) {
2146 nlmsg_free(msg);
2147 return -1;
2148 }
2149 }
2150
2151 return send_and_recv_msgs(drv, msg, nl80211_get_reg, results);
2152 }
2153
2154
modestr(enum hostapd_hw_mode mode)2155 static const char * modestr(enum hostapd_hw_mode mode)
2156 {
2157 switch (mode) {
2158 case HOSTAPD_MODE_IEEE80211B:
2159 return "802.11b";
2160 case HOSTAPD_MODE_IEEE80211G:
2161 return "802.11g";
2162 case HOSTAPD_MODE_IEEE80211A:
2163 return "802.11a";
2164 case HOSTAPD_MODE_IEEE80211AD:
2165 return "802.11ad";
2166 default:
2167 return "?";
2168 }
2169 }
2170
2171
nl80211_dump_chan_list(struct hostapd_hw_modes * modes,u16 num_modes)2172 static void nl80211_dump_chan_list(struct hostapd_hw_modes *modes,
2173 u16 num_modes)
2174 {
2175 int i;
2176
2177 if (!modes)
2178 return;
2179
2180 for (i = 0; i < num_modes; i++) {
2181 struct hostapd_hw_modes *mode = &modes[i];
2182 char str[200];
2183 char *pos = str;
2184 char *end = pos + sizeof(str);
2185 int j, res;
2186
2187 for (j = 0; j < mode->num_channels; j++) {
2188 struct hostapd_channel_data *chan = &mode->channels[j];
2189
2190 res = os_snprintf(pos, end - pos, " %d%s%s%s",
2191 chan->freq,
2192 (chan->flag & HOSTAPD_CHAN_DISABLED) ?
2193 "[DISABLED]" : "",
2194 (chan->flag & HOSTAPD_CHAN_NO_IR) ?
2195 "[NO_IR]" : "",
2196 (chan->flag & HOSTAPD_CHAN_RADAR) ?
2197 "[RADAR]" : "");
2198 if (os_snprintf_error(end - pos, res))
2199 break;
2200 pos += res;
2201 }
2202
2203 *pos = '\0';
2204 wpa_printf(MSG_DEBUG, "nl80211: Mode IEEE %s:%s",
2205 modestr(mode->mode), str);
2206 }
2207 }
2208
2209
2210 struct hostapd_hw_modes *
nl80211_get_hw_feature_data(void * priv,u16 * num_modes,u16 * flags,u8 * dfs_domain)2211 nl80211_get_hw_feature_data(void *priv, u16 *num_modes, u16 *flags,
2212 u8 *dfs_domain)
2213 {
2214 u32 feat;
2215 struct i802_bss *bss = priv;
2216 struct wpa_driver_nl80211_data *drv = bss->drv;
2217 int nl_flags = 0;
2218 struct nl_msg *msg;
2219 struct phy_info_arg result = {
2220 .num_modes = num_modes,
2221 .modes = NULL,
2222 .last_mode = -1,
2223 .failed = 0,
2224 .dfs_domain = 0,
2225 };
2226
2227 *num_modes = 0;
2228 *flags = 0;
2229 *dfs_domain = 0;
2230
2231 feat = get_nl80211_protocol_features(drv);
2232 if (feat & NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)
2233 nl_flags = NLM_F_DUMP;
2234 if (!(msg = nl80211_cmd_msg(bss, nl_flags, NL80211_CMD_GET_WIPHY)) ||
2235 nla_put_flag(msg, NL80211_ATTR_SPLIT_WIPHY_DUMP)) {
2236 nlmsg_free(msg);
2237 return NULL;
2238 }
2239
2240 if (send_and_recv_msgs(drv, msg, phy_info_handler, &result) == 0) {
2241 struct hostapd_hw_modes *modes;
2242
2243 nl80211_set_regulatory_flags(drv, &result);
2244 if (result.failed) {
2245 int i;
2246
2247 for (i = 0; result.modes && i < *num_modes; i++) {
2248 os_free(result.modes[i].channels);
2249 os_free(result.modes[i].rates);
2250 }
2251 os_free(result.modes);
2252 *num_modes = 0;
2253 return NULL;
2254 }
2255
2256 *dfs_domain = result.dfs_domain;
2257
2258 modes = wpa_driver_nl80211_postprocess_modes(result.modes,
2259 num_modes);
2260 nl80211_dump_chan_list(modes, *num_modes);
2261 return modes;
2262 }
2263
2264 return NULL;
2265 }
2266