2 * Driver interaction with Linux nl80211/cfg80211 - Capabilities
3 * Copyright (c) 2002-2014, Jouni Malinen <j@w1.fi>
4 * Copyright (c) 2007, Johannes Berg <johannes@sipsolutions.net>
5 * Copyright (c) 2009-2010, Atheros Communications
7 * This software may be distributed under the terms of the BSD license.
8 * See README for more details.
12 #include <netlink/genl/genl.h>
14 #include "utils/common.h"
15 #include "common/ieee802_11_defs.h"
16 #include "common/ieee802_11_common.h"
17 #include "common/qca-vendor.h"
18 #include "common/qca-vendor-attr.h"
19 #include "driver_nl80211.h"
22 static int protocol_feature_handler(struct nl_msg *msg, void *arg)
25 struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
26 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
28 nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
29 genlmsg_attrlen(gnlh, 0), NULL);
31 if (tb_msg[NL80211_ATTR_PROTOCOL_FEATURES])
32 *feat = nla_get_u32(tb_msg[NL80211_ATTR_PROTOCOL_FEATURES]);
38 static u32 get_nl80211_protocol_features(struct wpa_driver_nl80211_data *drv)
47 nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_PROTOCOL_FEATURES);
48 if (send_and_recv_msgs(drv, msg, protocol_feature_handler, &feat) == 0)
58 struct wiphy_info_data {
59 struct wpa_driver_nl80211_data *drv;
60 struct wpa_driver_capa *capa;
62 unsigned int num_multichan_concurrent;
65 unsigned int device_ap_sme:1;
66 unsigned int poll_command_supported:1;
67 unsigned int data_tx_status:1;
68 unsigned int monitor_supported: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_concurrent:1;
74 unsigned int channel_switch_supported:1;
75 unsigned int set_qos_map_supported:1;
76 unsigned int have_low_prio_scan:1;
80 static unsigned int probe_resp_offload_support(int supp_protocols)
82 unsigned int prot = 0;
84 if (supp_protocols & NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS)
85 prot |= WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS;
86 if (supp_protocols & NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2)
87 prot |= WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2;
88 if (supp_protocols & NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P)
89 prot |= WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P;
90 if (supp_protocols & NL80211_PROBE_RESP_OFFLOAD_SUPPORT_80211U)
91 prot |= WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING;
97 static void wiphy_info_supported_iftypes(struct wiphy_info_data *info,
100 struct nlattr *nl_mode;
106 nla_for_each_nested(nl_mode, tb, i) {
107 switch (nla_type(nl_mode)) {
108 case NL80211_IFTYPE_AP:
109 info->capa->flags |= WPA_DRIVER_FLAGS_AP;
111 case NL80211_IFTYPE_MESH_POINT:
112 info->capa->flags |= WPA_DRIVER_FLAGS_MESH;
114 case NL80211_IFTYPE_ADHOC:
115 info->capa->flags |= WPA_DRIVER_FLAGS_IBSS;
117 case NL80211_IFTYPE_P2P_DEVICE:
119 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE;
121 case NL80211_IFTYPE_P2P_GO:
122 info->p2p_go_supported = 1;
124 case NL80211_IFTYPE_P2P_CLIENT:
125 info->p2p_client_supported = 1;
127 case NL80211_IFTYPE_MONITOR:
128 info->monitor_supported = 1;
135 static int wiphy_info_iface_comb_process(struct wiphy_info_data *info,
136 struct nlattr *nl_combi)
138 struct nlattr *tb_comb[NUM_NL80211_IFACE_COMB];
139 struct nlattr *tb_limit[NUM_NL80211_IFACE_LIMIT];
140 struct nlattr *nl_limit, *nl_mode;
141 int err, rem_limit, rem_mode;
142 int combination_has_p2p = 0, combination_has_mgd = 0;
143 static struct nla_policy
144 iface_combination_policy[NUM_NL80211_IFACE_COMB] = {
145 [NL80211_IFACE_COMB_LIMITS] = { .type = NLA_NESTED },
146 [NL80211_IFACE_COMB_MAXNUM] = { .type = NLA_U32 },
147 [NL80211_IFACE_COMB_STA_AP_BI_MATCH] = { .type = NLA_FLAG },
148 [NL80211_IFACE_COMB_NUM_CHANNELS] = { .type = NLA_U32 },
149 [NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS] = { .type = NLA_U32 },
151 iface_limit_policy[NUM_NL80211_IFACE_LIMIT] = {
152 [NL80211_IFACE_LIMIT_TYPES] = { .type = NLA_NESTED },
153 [NL80211_IFACE_LIMIT_MAX] = { .type = NLA_U32 },
156 err = nla_parse_nested(tb_comb, MAX_NL80211_IFACE_COMB,
157 nl_combi, iface_combination_policy);
158 if (err || !tb_comb[NL80211_IFACE_COMB_LIMITS] ||
159 !tb_comb[NL80211_IFACE_COMB_MAXNUM] ||
160 !tb_comb[NL80211_IFACE_COMB_NUM_CHANNELS])
161 return 0; /* broken combination */
163 if (tb_comb[NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS])
164 info->capa->flags |= WPA_DRIVER_FLAGS_RADAR;
166 nla_for_each_nested(nl_limit, tb_comb[NL80211_IFACE_COMB_LIMITS],
168 err = nla_parse_nested(tb_limit, MAX_NL80211_IFACE_LIMIT,
169 nl_limit, iface_limit_policy);
170 if (err || !tb_limit[NL80211_IFACE_LIMIT_TYPES])
171 return 0; /* broken combination */
173 nla_for_each_nested(nl_mode,
174 tb_limit[NL80211_IFACE_LIMIT_TYPES],
176 int ift = nla_type(nl_mode);
177 if (ift == NL80211_IFTYPE_P2P_GO ||
178 ift == NL80211_IFTYPE_P2P_CLIENT)
179 combination_has_p2p = 1;
180 if (ift == NL80211_IFTYPE_STATION)
181 combination_has_mgd = 1;
183 if (combination_has_p2p && combination_has_mgd)
187 if (combination_has_p2p && combination_has_mgd) {
188 unsigned int num_channels =
189 nla_get_u32(tb_comb[NL80211_IFACE_COMB_NUM_CHANNELS]);
191 info->p2p_concurrent = 1;
192 if (info->num_multichan_concurrent < num_channels)
193 info->num_multichan_concurrent = num_channels;
200 static void wiphy_info_iface_comb(struct wiphy_info_data *info,
203 struct nlattr *nl_combi;
209 nla_for_each_nested(nl_combi, tb, rem_combi) {
210 if (wiphy_info_iface_comb_process(info, nl_combi) > 0)
216 static void wiphy_info_supp_cmds(struct wiphy_info_data *info,
219 struct nlattr *nl_cmd;
225 nla_for_each_nested(nl_cmd, tb, i) {
226 switch (nla_get_u32(nl_cmd)) {
227 case NL80211_CMD_AUTHENTICATE:
228 info->auth_supported = 1;
230 case NL80211_CMD_CONNECT:
231 info->connect_supported = 1;
233 case NL80211_CMD_START_SCHED_SCAN:
234 info->capa->sched_scan_supported = 1;
236 case NL80211_CMD_PROBE_CLIENT:
237 info->poll_command_supported = 1;
239 case NL80211_CMD_CHANNEL_SWITCH:
240 info->channel_switch_supported = 1;
242 case NL80211_CMD_SET_QOS_MAP:
243 info->set_qos_map_supported = 1;
250 static void wiphy_info_cipher_suites(struct wiphy_info_data *info,
259 num = nla_len(tb) / sizeof(u32);
260 ciphers = nla_data(tb);
261 for (i = 0; i < num; i++) {
264 wpa_printf(MSG_DEBUG, "nl80211: Supported cipher %02x-%02x-%02x:%d",
265 c >> 24, (c >> 16) & 0xff,
266 (c >> 8) & 0xff, c & 0xff);
268 case WLAN_CIPHER_SUITE_CCMP_256:
269 info->capa->enc |= WPA_DRIVER_CAPA_ENC_CCMP_256;
271 case WLAN_CIPHER_SUITE_GCMP_256:
272 info->capa->enc |= WPA_DRIVER_CAPA_ENC_GCMP_256;
274 case WLAN_CIPHER_SUITE_CCMP:
275 info->capa->enc |= WPA_DRIVER_CAPA_ENC_CCMP;
277 case WLAN_CIPHER_SUITE_GCMP:
278 info->capa->enc |= WPA_DRIVER_CAPA_ENC_GCMP;
280 case WLAN_CIPHER_SUITE_TKIP:
281 info->capa->enc |= WPA_DRIVER_CAPA_ENC_TKIP;
283 case WLAN_CIPHER_SUITE_WEP104:
284 info->capa->enc |= WPA_DRIVER_CAPA_ENC_WEP104;
286 case WLAN_CIPHER_SUITE_WEP40:
287 info->capa->enc |= WPA_DRIVER_CAPA_ENC_WEP40;
289 case WLAN_CIPHER_SUITE_AES_CMAC:
290 info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP;
292 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
293 info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP_GMAC_128;
295 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
296 info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP_GMAC_256;
298 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
299 info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP_CMAC_256;
301 case WLAN_CIPHER_SUITE_NO_GROUP_ADDR:
302 info->capa->enc |= WPA_DRIVER_CAPA_ENC_GTK_NOT_USED;
309 static void wiphy_info_max_roc(struct wpa_driver_capa *capa,
313 capa->max_remain_on_chan = nla_get_u32(tb);
317 static void wiphy_info_tdls(struct wpa_driver_capa *capa, struct nlattr *tdls,
318 struct nlattr *ext_setup)
323 wpa_printf(MSG_DEBUG, "nl80211: TDLS supported");
324 capa->flags |= WPA_DRIVER_FLAGS_TDLS_SUPPORT;
327 wpa_printf(MSG_DEBUG, "nl80211: TDLS external setup");
328 capa->flags |= WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP;
333 static void wiphy_info_feature_flags(struct wiphy_info_data *info,
337 struct wpa_driver_capa *capa = info->capa;
342 flags = nla_get_u32(tb);
344 if (flags & NL80211_FEATURE_SK_TX_STATUS)
345 info->data_tx_status = 1;
347 if (flags & NL80211_FEATURE_INACTIVITY_TIMER)
348 capa->flags |= WPA_DRIVER_FLAGS_INACTIVITY_TIMER;
350 if (flags & NL80211_FEATURE_SAE)
351 capa->flags |= WPA_DRIVER_FLAGS_SAE;
353 if (flags & NL80211_FEATURE_NEED_OBSS_SCAN)
354 capa->flags |= WPA_DRIVER_FLAGS_OBSS_SCAN;
356 if (flags & NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)
357 capa->flags |= WPA_DRIVER_FLAGS_HT_2040_COEX;
359 if (flags & NL80211_FEATURE_LOW_PRIORITY_SCAN)
360 info->have_low_prio_scan = 1;
362 if (flags & NL80211_FEATURE_STATIC_SMPS)
363 capa->smps_modes |= WPA_DRIVER_SMPS_MODE_STATIC;
365 if (flags & NL80211_FEATURE_DYNAMIC_SMPS)
366 capa->smps_modes |= WPA_DRIVER_SMPS_MODE_DYNAMIC;
370 static void wiphy_info_probe_resp_offload(struct wpa_driver_capa *capa,
378 protocols = nla_get_u32(tb);
379 wpa_printf(MSG_DEBUG, "nl80211: Supports Probe Response offload in AP "
381 capa->flags |= WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD;
382 capa->probe_resp_offloads = probe_resp_offload_support(protocols);
386 static void wiphy_info_wowlan_triggers(struct wpa_driver_capa *capa,
389 struct nlattr *triggers[MAX_NL80211_WOWLAN_TRIG + 1];
394 if (nla_parse_nested(triggers, MAX_NL80211_WOWLAN_TRIG,
398 if (triggers[NL80211_WOWLAN_TRIG_ANY])
399 capa->wowlan_triggers.any = 1;
400 if (triggers[NL80211_WOWLAN_TRIG_DISCONNECT])
401 capa->wowlan_triggers.disconnect = 1;
402 if (triggers[NL80211_WOWLAN_TRIG_MAGIC_PKT])
403 capa->wowlan_triggers.magic_pkt = 1;
404 if (triggers[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE])
405 capa->wowlan_triggers.gtk_rekey_failure = 1;
406 if (triggers[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST])
407 capa->wowlan_triggers.eap_identity_req = 1;
408 if (triggers[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE])
409 capa->wowlan_triggers.four_way_handshake = 1;
410 if (triggers[NL80211_WOWLAN_TRIG_RFKILL_RELEASE])
411 capa->wowlan_triggers.rfkill_release = 1;
415 static int wiphy_info_handler(struct nl_msg *msg, void *arg)
417 struct nlattr *tb[NL80211_ATTR_MAX + 1];
418 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
419 struct wiphy_info_data *info = arg;
420 struct wpa_driver_capa *capa = info->capa;
421 struct wpa_driver_nl80211_data *drv = info->drv;
423 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
424 genlmsg_attrlen(gnlh, 0), NULL);
426 if (tb[NL80211_ATTR_WIPHY_NAME])
427 os_strlcpy(drv->phyname,
428 nla_get_string(tb[NL80211_ATTR_WIPHY_NAME]),
429 sizeof(drv->phyname));
430 if (tb[NL80211_ATTR_MAX_NUM_SCAN_SSIDS])
431 capa->max_scan_ssids =
432 nla_get_u8(tb[NL80211_ATTR_MAX_NUM_SCAN_SSIDS]);
434 if (tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS])
435 capa->max_sched_scan_ssids =
436 nla_get_u8(tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS]);
438 if (tb[NL80211_ATTR_MAX_MATCH_SETS])
439 capa->max_match_sets =
440 nla_get_u8(tb[NL80211_ATTR_MAX_MATCH_SETS]);
442 if (tb[NL80211_ATTR_MAC_ACL_MAX])
443 capa->max_acl_mac_addrs =
444 nla_get_u8(tb[NL80211_ATTR_MAC_ACL_MAX]);
446 wiphy_info_supported_iftypes(info, tb[NL80211_ATTR_SUPPORTED_IFTYPES]);
447 wiphy_info_iface_comb(info, tb[NL80211_ATTR_INTERFACE_COMBINATIONS]);
448 wiphy_info_supp_cmds(info, tb[NL80211_ATTR_SUPPORTED_COMMANDS]);
449 wiphy_info_cipher_suites(info, tb[NL80211_ATTR_CIPHER_SUITES]);
451 if (tb[NL80211_ATTR_OFFCHANNEL_TX_OK]) {
452 wpa_printf(MSG_DEBUG, "nl80211: Using driver-based "
454 capa->flags |= WPA_DRIVER_FLAGS_OFFCHANNEL_TX;
457 if (tb[NL80211_ATTR_ROAM_SUPPORT]) {
458 wpa_printf(MSG_DEBUG, "nl80211: Using driver-based roaming");
459 capa->flags |= WPA_DRIVER_FLAGS_BSS_SELECTION;
462 wiphy_info_max_roc(capa,
463 tb[NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION]);
465 if (tb[NL80211_ATTR_SUPPORT_AP_UAPSD])
466 capa->flags |= WPA_DRIVER_FLAGS_AP_UAPSD;
468 wiphy_info_tdls(capa, tb[NL80211_ATTR_TDLS_SUPPORT],
469 tb[NL80211_ATTR_TDLS_EXTERNAL_SETUP]);
471 if (tb[NL80211_ATTR_DEVICE_AP_SME])
472 info->device_ap_sme = 1;
474 wiphy_info_feature_flags(info, tb[NL80211_ATTR_FEATURE_FLAGS]);
475 wiphy_info_probe_resp_offload(capa,
476 tb[NL80211_ATTR_PROBE_RESP_OFFLOAD]);
478 if (tb[NL80211_ATTR_EXT_CAPA] && tb[NL80211_ATTR_EXT_CAPA_MASK] &&
479 drv->extended_capa == NULL) {
481 os_malloc(nla_len(tb[NL80211_ATTR_EXT_CAPA]));
482 if (drv->extended_capa) {
483 os_memcpy(drv->extended_capa,
484 nla_data(tb[NL80211_ATTR_EXT_CAPA]),
485 nla_len(tb[NL80211_ATTR_EXT_CAPA]));
486 drv->extended_capa_len =
487 nla_len(tb[NL80211_ATTR_EXT_CAPA]);
489 drv->extended_capa_mask =
490 os_malloc(nla_len(tb[NL80211_ATTR_EXT_CAPA]));
491 if (drv->extended_capa_mask) {
492 os_memcpy(drv->extended_capa_mask,
493 nla_data(tb[NL80211_ATTR_EXT_CAPA]),
494 nla_len(tb[NL80211_ATTR_EXT_CAPA]));
496 os_free(drv->extended_capa);
497 drv->extended_capa = NULL;
498 drv->extended_capa_len = 0;
502 if (tb[NL80211_ATTR_VENDOR_DATA]) {
506 nla_for_each_nested(nl, tb[NL80211_ATTR_VENDOR_DATA], rem) {
507 struct nl80211_vendor_cmd_info *vinfo;
508 if (nla_len(nl) != sizeof(*vinfo)) {
509 wpa_printf(MSG_DEBUG, "nl80211: Unexpected vendor data info");
512 vinfo = nla_data(nl);
513 switch (vinfo->subcmd) {
514 case QCA_NL80211_VENDOR_SUBCMD_ROAMING:
515 drv->roaming_vendor_cmd_avail = 1;
517 case QCA_NL80211_VENDOR_SUBCMD_DFS_CAPABILITY:
518 drv->dfs_vendor_cmd_avail = 1;
520 case QCA_NL80211_VENDOR_SUBCMD_KEY_MGMT_SET_KEY:
521 drv->key_mgmt_set_key_vendor_cmd_avail = 1;
525 wpa_printf(MSG_DEBUG, "nl80211: Supported vendor command: vendor_id=0x%x subcmd=%u",
526 vinfo->vendor_id, vinfo->subcmd);
530 if (tb[NL80211_ATTR_VENDOR_EVENTS]) {
534 nla_for_each_nested(nl, tb[NL80211_ATTR_VENDOR_EVENTS], rem) {
535 struct nl80211_vendor_cmd_info *vinfo;
536 if (nla_len(nl) != sizeof(*vinfo)) {
537 wpa_printf(MSG_DEBUG, "nl80211: Unexpected vendor data info");
540 vinfo = nla_data(nl);
542 QCA_NL80211_VENDOR_SUBCMD_KEY_MGMT_ROAM_AUTH)
543 drv->roam_auth_vendor_event_avail = 1;
544 wpa_printf(MSG_DEBUG, "nl80211: Supported vendor event: vendor_id=0x%x subcmd=%u",
545 vinfo->vendor_id, vinfo->subcmd);
549 wiphy_info_wowlan_triggers(capa,
550 tb[NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED]);
552 if (tb[NL80211_ATTR_MAX_AP_ASSOC_STA])
554 nla_get_u32(tb[NL80211_ATTR_MAX_AP_ASSOC_STA]);
560 static int wpa_driver_nl80211_get_info(struct wpa_driver_nl80211_data *drv,
561 struct wiphy_info_data *info)
566 os_memset(info, 0, sizeof(*info));
567 info->capa = &drv->capa;
574 feat = get_nl80211_protocol_features(drv);
575 if (feat & NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)
576 nl80211_cmd(drv, msg, NLM_F_DUMP, NL80211_CMD_GET_WIPHY);
578 nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_WIPHY);
580 NLA_PUT_FLAG(msg, NL80211_ATTR_SPLIT_WIPHY_DUMP);
581 if (nl80211_set_iface_id(msg, drv->first_bss) < 0)
582 goto nla_put_failure;
584 if (send_and_recv_msgs(drv, msg, wiphy_info_handler, info))
587 if (info->auth_supported)
588 drv->capa.flags |= WPA_DRIVER_FLAGS_SME;
589 else if (!info->connect_supported) {
590 wpa_printf(MSG_INFO, "nl80211: Driver does not support "
591 "authentication/association or connect commands");
595 if (info->p2p_go_supported && info->p2p_client_supported)
596 drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CAPABLE;
597 if (info->p2p_concurrent) {
598 wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group "
599 "interface (driver advertised support)");
600 drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT;
601 drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P;
603 if (info->num_multichan_concurrent > 1) {
604 wpa_printf(MSG_DEBUG, "nl80211: Enable multi-channel "
605 "concurrent (driver advertised support)");
606 drv->capa.num_multichan_concurrent =
607 info->num_multichan_concurrent;
609 if (drv->capa.flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)
610 wpa_printf(MSG_DEBUG, "nl80211: use P2P_DEVICE support");
612 /* default to 5000 since early versions of mac80211 don't set it */
613 if (!drv->capa.max_remain_on_chan)
614 drv->capa.max_remain_on_chan = 5000;
616 if (info->channel_switch_supported)
617 drv->capa.flags |= WPA_DRIVER_FLAGS_AP_CSA;
626 static int dfs_info_handler(struct nl_msg *msg, void *arg)
628 struct nlattr *tb[NL80211_ATTR_MAX + 1];
629 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
630 int *dfs_capability_ptr = arg;
632 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
633 genlmsg_attrlen(gnlh, 0), NULL);
635 if (tb[NL80211_ATTR_VENDOR_DATA]) {
636 struct nlattr *nl_vend = tb[NL80211_ATTR_VENDOR_DATA];
637 struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1];
639 nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX,
640 nla_data(nl_vend), nla_len(nl_vend), NULL);
642 if (tb_vendor[QCA_WLAN_VENDOR_ATTR_DFS]) {
644 val = nla_get_u32(tb_vendor[QCA_WLAN_VENDOR_ATTR_DFS]);
645 wpa_printf(MSG_DEBUG, "nl80211: DFS offload capability: %u",
647 *dfs_capability_ptr = val;
655 static void qca_nl80211_check_dfs_capa(struct wpa_driver_nl80211_data *drv)
658 int dfs_capability = 0;
661 if (!drv->dfs_vendor_cmd_avail)
669 nl80211_cmd(drv, msg, 0, NL80211_CMD_VENDOR);
671 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex);
672 NLA_PUT_U32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA);
673 NLA_PUT_U32(msg, NL80211_ATTR_VENDOR_SUBCMD,
674 QCA_NL80211_VENDOR_SUBCMD_DFS_CAPABILITY);
676 ret = send_and_recv_msgs(drv, msg, dfs_info_handler, &dfs_capability);
677 if (!ret && dfs_capability)
678 drv->capa.flags |= WPA_DRIVER_FLAGS_DFS_OFFLOAD;
686 int wpa_driver_nl80211_capa(struct wpa_driver_nl80211_data *drv)
688 struct wiphy_info_data info;
689 if (wpa_driver_nl80211_get_info(drv, &info))
695 drv->has_capability = 1;
696 drv->capa.key_mgmt = WPA_DRIVER_CAPA_KEY_MGMT_WPA |
697 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
698 WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
699 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK;
700 drv->capa.auth = WPA_DRIVER_AUTH_OPEN |
701 WPA_DRIVER_AUTH_SHARED |
702 WPA_DRIVER_AUTH_LEAP;
704 drv->capa.flags |= WPA_DRIVER_FLAGS_SANE_ERROR_CODES;
705 drv->capa.flags |= WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE;
706 drv->capa.flags |= WPA_DRIVER_FLAGS_EAPOL_TX_STATUS;
709 * As all cfg80211 drivers must support cases where the AP interface is
710 * removed without the knowledge of wpa_supplicant/hostapd, e.g., in
711 * case that the user space daemon has crashed, they must be able to
712 * cleanup all stations and key entries in the AP tear down flow. Thus,
713 * this flag can/should always be set for cfg80211 drivers.
715 drv->capa.flags |= WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT;
717 if (!info.device_ap_sme) {
718 drv->capa.flags |= WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS;
721 * No AP SME is currently assumed to also indicate no AP MLME
722 * in the driver/firmware.
724 drv->capa.flags |= WPA_DRIVER_FLAGS_AP_MLME;
727 drv->device_ap_sme = info.device_ap_sme;
728 drv->poll_command_supported = info.poll_command_supported;
729 drv->data_tx_status = info.data_tx_status;
730 if (info.set_qos_map_supported)
731 drv->capa.flags |= WPA_DRIVER_FLAGS_QOS_MAPPING;
732 drv->have_low_prio_scan = info.have_low_prio_scan;
735 * If poll command and tx status are supported, mac80211 is new enough
736 * to have everything we need to not need monitor interfaces.
738 drv->use_monitor = !info.poll_command_supported || !info.data_tx_status;
740 if (drv->device_ap_sme && drv->use_monitor) {
742 * Non-mac80211 drivers may not support monitor interface.
743 * Make sure we do not get stuck with incorrect capability here
744 * by explicitly testing this.
746 if (!info.monitor_supported) {
747 wpa_printf(MSG_DEBUG, "nl80211: Disable use_monitor "
748 "with device_ap_sme since no monitor mode "
750 drv->use_monitor = 0;
755 * If we aren't going to use monitor interfaces, but the
756 * driver doesn't support data TX status, we won't get TX
757 * status for EAPOL frames.
759 if (!drv->use_monitor && !info.data_tx_status)
760 drv->capa.flags &= ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS;
762 qca_nl80211_check_dfs_capa(drv);
768 struct phy_info_arg {
770 struct hostapd_hw_modes *modes;
771 int last_mode, last_chan_idx;
774 static void phy_info_ht_capa(struct hostapd_hw_modes *mode, struct nlattr *capa,
775 struct nlattr *ampdu_factor,
776 struct nlattr *ampdu_density,
777 struct nlattr *mcs_set)
780 mode->ht_capab = nla_get_u16(capa);
783 mode->a_mpdu_params |= nla_get_u8(ampdu_factor) & 0x03;
786 mode->a_mpdu_params |= nla_get_u8(ampdu_density) << 2;
788 if (mcs_set && nla_len(mcs_set) >= 16) {
790 mcs = nla_data(mcs_set);
791 os_memcpy(mode->mcs_set, mcs, 16);
796 static void phy_info_vht_capa(struct hostapd_hw_modes *mode,
798 struct nlattr *mcs_set)
801 mode->vht_capab = nla_get_u32(capa);
803 if (mcs_set && nla_len(mcs_set) >= 8) {
805 mcs = nla_data(mcs_set);
806 os_memcpy(mode->vht_mcs_set, mcs, 8);
811 static void phy_info_freq(struct hostapd_hw_modes *mode,
812 struct hostapd_channel_data *chan,
813 struct nlattr *tb_freq[])
816 chan->freq = nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_FREQ]);
818 chan->dfs_cac_ms = 0;
819 if (ieee80211_freq_to_chan(chan->freq, &channel) != NUM_HOSTAPD_MODES)
820 chan->chan = channel;
822 if (tb_freq[NL80211_FREQUENCY_ATTR_DISABLED])
823 chan->flag |= HOSTAPD_CHAN_DISABLED;
824 if (tb_freq[NL80211_FREQUENCY_ATTR_NO_IR])
825 chan->flag |= HOSTAPD_CHAN_NO_IR;
826 if (tb_freq[NL80211_FREQUENCY_ATTR_RADAR])
827 chan->flag |= HOSTAPD_CHAN_RADAR;
828 if (tb_freq[NL80211_FREQUENCY_ATTR_INDOOR_ONLY])
829 chan->flag |= HOSTAPD_CHAN_INDOOR_ONLY;
830 if (tb_freq[NL80211_FREQUENCY_ATTR_GO_CONCURRENT])
831 chan->flag |= HOSTAPD_CHAN_GO_CONCURRENT;
833 if (tb_freq[NL80211_FREQUENCY_ATTR_DFS_STATE]) {
834 enum nl80211_dfs_state state =
835 nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_DFS_STATE]);
838 case NL80211_DFS_USABLE:
839 chan->flag |= HOSTAPD_CHAN_DFS_USABLE;
841 case NL80211_DFS_AVAILABLE:
842 chan->flag |= HOSTAPD_CHAN_DFS_AVAILABLE;
844 case NL80211_DFS_UNAVAILABLE:
845 chan->flag |= HOSTAPD_CHAN_DFS_UNAVAILABLE;
850 if (tb_freq[NL80211_FREQUENCY_ATTR_DFS_CAC_TIME]) {
851 chan->dfs_cac_ms = nla_get_u32(
852 tb_freq[NL80211_FREQUENCY_ATTR_DFS_CAC_TIME]);
857 static int phy_info_freqs(struct phy_info_arg *phy_info,
858 struct hostapd_hw_modes *mode, struct nlattr *tb)
860 static struct nla_policy freq_policy[NL80211_FREQUENCY_ATTR_MAX + 1] = {
861 [NL80211_FREQUENCY_ATTR_FREQ] = { .type = NLA_U32 },
862 [NL80211_FREQUENCY_ATTR_DISABLED] = { .type = NLA_FLAG },
863 [NL80211_FREQUENCY_ATTR_NO_IR] = { .type = NLA_FLAG },
864 [NL80211_FREQUENCY_ATTR_RADAR] = { .type = NLA_FLAG },
865 [NL80211_FREQUENCY_ATTR_MAX_TX_POWER] = { .type = NLA_U32 },
866 [NL80211_FREQUENCY_ATTR_DFS_STATE] = { .type = NLA_U32 },
868 int new_channels = 0;
869 struct hostapd_channel_data *channel;
870 struct nlattr *tb_freq[NL80211_FREQUENCY_ATTR_MAX + 1];
871 struct nlattr *nl_freq;
877 nla_for_each_nested(nl_freq, tb, rem_freq) {
878 nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX,
879 nla_data(nl_freq), nla_len(nl_freq), freq_policy);
880 if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ])
885 channel = os_realloc_array(mode->channels,
886 mode->num_channels + new_channels,
887 sizeof(struct hostapd_channel_data));
891 mode->channels = channel;
892 mode->num_channels += new_channels;
894 idx = phy_info->last_chan_idx;
896 nla_for_each_nested(nl_freq, tb, rem_freq) {
897 nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX,
898 nla_data(nl_freq), nla_len(nl_freq), freq_policy);
899 if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ])
901 phy_info_freq(mode, &mode->channels[idx], tb_freq);
904 phy_info->last_chan_idx = idx;
910 static int phy_info_rates(struct hostapd_hw_modes *mode, struct nlattr *tb)
912 static struct nla_policy rate_policy[NL80211_BITRATE_ATTR_MAX + 1] = {
913 [NL80211_BITRATE_ATTR_RATE] = { .type = NLA_U32 },
914 [NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE] =
915 { .type = NLA_FLAG },
917 struct nlattr *tb_rate[NL80211_BITRATE_ATTR_MAX + 1];
918 struct nlattr *nl_rate;
924 nla_for_each_nested(nl_rate, tb, rem_rate) {
925 nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX,
926 nla_data(nl_rate), nla_len(nl_rate),
928 if (!tb_rate[NL80211_BITRATE_ATTR_RATE])
933 mode->rates = os_calloc(mode->num_rates, sizeof(int));
939 nla_for_each_nested(nl_rate, tb, rem_rate) {
940 nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX,
941 nla_data(nl_rate), nla_len(nl_rate),
943 if (!tb_rate[NL80211_BITRATE_ATTR_RATE])
945 mode->rates[idx] = nla_get_u32(
946 tb_rate[NL80211_BITRATE_ATTR_RATE]);
954 static int phy_info_band(struct phy_info_arg *phy_info, struct nlattr *nl_band)
956 struct nlattr *tb_band[NL80211_BAND_ATTR_MAX + 1];
957 struct hostapd_hw_modes *mode;
960 if (phy_info->last_mode != nl_band->nla_type) {
961 mode = os_realloc_array(phy_info->modes,
962 *phy_info->num_modes + 1,
966 phy_info->modes = mode;
968 mode = &phy_info->modes[*(phy_info->num_modes)];
969 os_memset(mode, 0, sizeof(*mode));
970 mode->mode = NUM_HOSTAPD_MODES;
971 mode->flags = HOSTAPD_MODE_FLAG_HT_INFO_KNOWN |
972 HOSTAPD_MODE_FLAG_VHT_INFO_KNOWN;
975 * Unsupported VHT MCS stream is defined as value 3, so the VHT
976 * MCS RX/TX map must be initialized with 0xffff to mark all 8
977 * possible streams as unsupported. This will be overridden if
978 * driver advertises VHT support.
980 mode->vht_mcs_set[0] = 0xff;
981 mode->vht_mcs_set[1] = 0xff;
982 mode->vht_mcs_set[4] = 0xff;
983 mode->vht_mcs_set[5] = 0xff;
985 *(phy_info->num_modes) += 1;
986 phy_info->last_mode = nl_band->nla_type;
987 phy_info->last_chan_idx = 0;
989 mode = &phy_info->modes[*(phy_info->num_modes) - 1];
991 nla_parse(tb_band, NL80211_BAND_ATTR_MAX, nla_data(nl_band),
992 nla_len(nl_band), NULL);
994 phy_info_ht_capa(mode, tb_band[NL80211_BAND_ATTR_HT_CAPA],
995 tb_band[NL80211_BAND_ATTR_HT_AMPDU_FACTOR],
996 tb_band[NL80211_BAND_ATTR_HT_AMPDU_DENSITY],
997 tb_band[NL80211_BAND_ATTR_HT_MCS_SET]);
998 phy_info_vht_capa(mode, tb_band[NL80211_BAND_ATTR_VHT_CAPA],
999 tb_band[NL80211_BAND_ATTR_VHT_MCS_SET]);
1000 ret = phy_info_freqs(phy_info, mode, tb_band[NL80211_BAND_ATTR_FREQS]);
1003 ret = phy_info_rates(mode, tb_band[NL80211_BAND_ATTR_RATES]);
1011 static int phy_info_handler(struct nl_msg *msg, void *arg)
1013 struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
1014 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1015 struct phy_info_arg *phy_info = arg;
1016 struct nlattr *nl_band;
1019 nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1020 genlmsg_attrlen(gnlh, 0), NULL);
1022 if (!tb_msg[NL80211_ATTR_WIPHY_BANDS])
1025 nla_for_each_nested(nl_band, tb_msg[NL80211_ATTR_WIPHY_BANDS], rem_band)
1027 int res = phy_info_band(phy_info, nl_band);
1036 static struct hostapd_hw_modes *
1037 wpa_driver_nl80211_postprocess_modes(struct hostapd_hw_modes *modes,
1041 struct hostapd_hw_modes *mode11g = NULL, *nmodes, *mode;
1042 int i, mode11g_idx = -1;
1044 /* heuristic to set up modes */
1045 for (m = 0; m < *num_modes; m++) {
1046 if (!modes[m].num_channels)
1048 if (modes[m].channels[0].freq < 4000) {
1049 modes[m].mode = HOSTAPD_MODE_IEEE80211B;
1050 for (i = 0; i < modes[m].num_rates; i++) {
1051 if (modes[m].rates[i] > 200) {
1052 modes[m].mode = HOSTAPD_MODE_IEEE80211G;
1056 } else if (modes[m].channels[0].freq > 50000)
1057 modes[m].mode = HOSTAPD_MODE_IEEE80211AD;
1059 modes[m].mode = HOSTAPD_MODE_IEEE80211A;
1062 /* If only 802.11g mode is included, use it to construct matching
1063 * 802.11b mode data. */
1065 for (m = 0; m < *num_modes; m++) {
1066 if (modes[m].mode == HOSTAPD_MODE_IEEE80211B)
1067 return modes; /* 802.11b already included */
1068 if (modes[m].mode == HOSTAPD_MODE_IEEE80211G)
1072 if (mode11g_idx < 0)
1073 return modes; /* 2.4 GHz band not supported at all */
1075 nmodes = os_realloc_array(modes, *num_modes + 1, sizeof(*nmodes));
1077 return modes; /* Could not add 802.11b mode */
1079 mode = &nmodes[*num_modes];
1080 os_memset(mode, 0, sizeof(*mode));
1084 mode->mode = HOSTAPD_MODE_IEEE80211B;
1086 mode11g = &modes[mode11g_idx];
1087 mode->num_channels = mode11g->num_channels;
1088 mode->channels = os_malloc(mode11g->num_channels *
1089 sizeof(struct hostapd_channel_data));
1090 if (mode->channels == NULL) {
1092 return modes; /* Could not add 802.11b mode */
1094 os_memcpy(mode->channels, mode11g->channels,
1095 mode11g->num_channels * sizeof(struct hostapd_channel_data));
1097 mode->num_rates = 0;
1098 mode->rates = os_malloc(4 * sizeof(int));
1099 if (mode->rates == NULL) {
1100 os_free(mode->channels);
1102 return modes; /* Could not add 802.11b mode */
1105 for (i = 0; i < mode11g->num_rates; i++) {
1106 if (mode11g->rates[i] != 10 && mode11g->rates[i] != 20 &&
1107 mode11g->rates[i] != 55 && mode11g->rates[i] != 110)
1109 mode->rates[mode->num_rates] = mode11g->rates[i];
1111 if (mode->num_rates == 4)
1115 if (mode->num_rates == 0) {
1116 os_free(mode->channels);
1117 os_free(mode->rates);
1119 return modes; /* No 802.11b rates */
1122 wpa_printf(MSG_DEBUG, "nl80211: Added 802.11b mode based on 802.11g "
1129 static void nl80211_set_ht40_mode(struct hostapd_hw_modes *mode, int start,
1134 for (c = 0; c < mode->num_channels; c++) {
1135 struct hostapd_channel_data *chan = &mode->channels[c];
1136 if (chan->freq - 10 >= start && chan->freq + 10 <= end)
1137 chan->flag |= HOSTAPD_CHAN_HT40;
1142 static void nl80211_set_ht40_mode_sec(struct hostapd_hw_modes *mode, int start,
1147 for (c = 0; c < mode->num_channels; c++) {
1148 struct hostapd_channel_data *chan = &mode->channels[c];
1149 if (!(chan->flag & HOSTAPD_CHAN_HT40))
1151 if (chan->freq - 30 >= start && chan->freq - 10 <= end)
1152 chan->flag |= HOSTAPD_CHAN_HT40MINUS;
1153 if (chan->freq + 10 >= start && chan->freq + 30 <= end)
1154 chan->flag |= HOSTAPD_CHAN_HT40PLUS;
1159 static void nl80211_reg_rule_max_eirp(u32 start, u32 end, u32 max_eirp,
1160 struct phy_info_arg *results)
1164 for (m = 0; m < *results->num_modes; m++) {
1166 struct hostapd_hw_modes *mode = &results->modes[m];
1168 for (c = 0; c < mode->num_channels; c++) {
1169 struct hostapd_channel_data *chan = &mode->channels[c];
1170 if ((u32) chan->freq - 10 >= start &&
1171 (u32) chan->freq + 10 <= end)
1172 chan->max_tx_power = max_eirp;
1178 static void nl80211_reg_rule_ht40(u32 start, u32 end,
1179 struct phy_info_arg *results)
1183 for (m = 0; m < *results->num_modes; m++) {
1184 if (!(results->modes[m].ht_capab &
1185 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET))
1187 nl80211_set_ht40_mode(&results->modes[m], start, end);
1192 static void nl80211_reg_rule_sec(struct nlattr *tb[],
1193 struct phy_info_arg *results)
1195 u32 start, end, max_bw;
1198 if (tb[NL80211_ATTR_FREQ_RANGE_START] == NULL ||
1199 tb[NL80211_ATTR_FREQ_RANGE_END] == NULL ||
1200 tb[NL80211_ATTR_FREQ_RANGE_MAX_BW] == NULL)
1203 start = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]) / 1000;
1204 end = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]) / 1000;
1205 max_bw = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) / 1000;
1210 for (m = 0; m < *results->num_modes; m++) {
1211 if (!(results->modes[m].ht_capab &
1212 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET))
1214 nl80211_set_ht40_mode_sec(&results->modes[m], start, end);
1219 static void nl80211_set_vht_mode(struct hostapd_hw_modes *mode, int start,
1224 for (c = 0; c < mode->num_channels; c++) {
1225 struct hostapd_channel_data *chan = &mode->channels[c];
1226 if (chan->freq - 10 >= start && chan->freq + 70 <= end)
1227 chan->flag |= HOSTAPD_CHAN_VHT_10_70;
1229 if (chan->freq - 30 >= start && chan->freq + 50 <= end)
1230 chan->flag |= HOSTAPD_CHAN_VHT_30_50;
1232 if (chan->freq - 50 >= start && chan->freq + 30 <= end)
1233 chan->flag |= HOSTAPD_CHAN_VHT_50_30;
1235 if (chan->freq - 70 >= start && chan->freq + 10 <= end)
1236 chan->flag |= HOSTAPD_CHAN_VHT_70_10;
1241 static void nl80211_reg_rule_vht(struct nlattr *tb[],
1242 struct phy_info_arg *results)
1244 u32 start, end, max_bw;
1247 if (tb[NL80211_ATTR_FREQ_RANGE_START] == NULL ||
1248 tb[NL80211_ATTR_FREQ_RANGE_END] == NULL ||
1249 tb[NL80211_ATTR_FREQ_RANGE_MAX_BW] == NULL)
1252 start = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]) / 1000;
1253 end = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]) / 1000;
1254 max_bw = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) / 1000;
1259 for (m = 0; m < *results->num_modes; m++) {
1260 if (!(results->modes[m].ht_capab &
1261 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET))
1263 /* TODO: use a real VHT support indication */
1264 if (!results->modes[m].vht_capab)
1267 nl80211_set_vht_mode(&results->modes[m], start, end);
1272 static const char * dfs_domain_name(enum nl80211_dfs_regions region)
1275 case NL80211_DFS_UNSET:
1277 case NL80211_DFS_FCC:
1279 case NL80211_DFS_ETSI:
1281 case NL80211_DFS_JP:
1284 return "DFS-invalid";
1289 static int nl80211_get_reg(struct nl_msg *msg, void *arg)
1291 struct phy_info_arg *results = arg;
1292 struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
1293 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1294 struct nlattr *nl_rule;
1295 struct nlattr *tb_rule[NL80211_FREQUENCY_ATTR_MAX + 1];
1297 static struct nla_policy reg_policy[NL80211_FREQUENCY_ATTR_MAX + 1] = {
1298 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
1299 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
1300 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
1301 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
1302 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
1303 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
1306 nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1307 genlmsg_attrlen(gnlh, 0), NULL);
1308 if (!tb_msg[NL80211_ATTR_REG_ALPHA2] ||
1309 !tb_msg[NL80211_ATTR_REG_RULES]) {
1310 wpa_printf(MSG_DEBUG, "nl80211: No regulatory information "
1315 if (tb_msg[NL80211_ATTR_DFS_REGION]) {
1316 enum nl80211_dfs_regions dfs_domain;
1317 dfs_domain = nla_get_u8(tb_msg[NL80211_ATTR_DFS_REGION]);
1318 wpa_printf(MSG_DEBUG, "nl80211: Regulatory information - country=%s (%s)",
1319 (char *) nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]),
1320 dfs_domain_name(dfs_domain));
1322 wpa_printf(MSG_DEBUG, "nl80211: Regulatory information - country=%s",
1323 (char *) nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]));
1326 nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule)
1328 u32 start, end, max_eirp = 0, max_bw = 0, flags = 0;
1329 nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX,
1330 nla_data(nl_rule), nla_len(nl_rule), reg_policy);
1331 if (tb_rule[NL80211_ATTR_FREQ_RANGE_START] == NULL ||
1332 tb_rule[NL80211_ATTR_FREQ_RANGE_END] == NULL)
1334 start = nla_get_u32(tb_rule[NL80211_ATTR_FREQ_RANGE_START]) / 1000;
1335 end = nla_get_u32(tb_rule[NL80211_ATTR_FREQ_RANGE_END]) / 1000;
1336 if (tb_rule[NL80211_ATTR_POWER_RULE_MAX_EIRP])
1337 max_eirp = nla_get_u32(tb_rule[NL80211_ATTR_POWER_RULE_MAX_EIRP]) / 100;
1338 if (tb_rule[NL80211_ATTR_FREQ_RANGE_MAX_BW])
1339 max_bw = nla_get_u32(tb_rule[NL80211_ATTR_FREQ_RANGE_MAX_BW]) / 1000;
1340 if (tb_rule[NL80211_ATTR_REG_RULE_FLAGS])
1341 flags = nla_get_u32(tb_rule[NL80211_ATTR_REG_RULE_FLAGS]);
1343 wpa_printf(MSG_DEBUG, "nl80211: %u-%u @ %u MHz %u mBm%s%s%s%s%s%s%s%s",
1344 start, end, max_bw, max_eirp,
1345 flags & NL80211_RRF_NO_OFDM ? " (no OFDM)" : "",
1346 flags & NL80211_RRF_NO_CCK ? " (no CCK)" : "",
1347 flags & NL80211_RRF_NO_INDOOR ? " (no indoor)" : "",
1348 flags & NL80211_RRF_NO_OUTDOOR ? " (no outdoor)" :
1350 flags & NL80211_RRF_DFS ? " (DFS)" : "",
1351 flags & NL80211_RRF_PTP_ONLY ? " (PTP only)" : "",
1352 flags & NL80211_RRF_PTMP_ONLY ? " (PTMP only)" : "",
1353 flags & NL80211_RRF_NO_IR ? " (no IR)" : "");
1355 nl80211_reg_rule_ht40(start, end, results);
1356 if (tb_rule[NL80211_ATTR_POWER_RULE_MAX_EIRP])
1357 nl80211_reg_rule_max_eirp(start, end, max_eirp,
1361 nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule)
1363 nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX,
1364 nla_data(nl_rule), nla_len(nl_rule), reg_policy);
1365 nl80211_reg_rule_sec(tb_rule, results);
1368 nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule)
1370 nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX,
1371 nla_data(nl_rule), nla_len(nl_rule), reg_policy);
1372 nl80211_reg_rule_vht(tb_rule, results);
1379 static int nl80211_set_regulatory_flags(struct wpa_driver_nl80211_data *drv,
1380 struct phy_info_arg *results)
1384 msg = nlmsg_alloc();
1388 nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG);
1389 return send_and_recv_msgs(drv, msg, nl80211_get_reg, results);
1393 struct hostapd_hw_modes *
1394 nl80211_get_hw_feature_data(void *priv, u16 *num_modes, u16 *flags)
1397 struct i802_bss *bss = priv;
1398 struct wpa_driver_nl80211_data *drv = bss->drv;
1400 struct phy_info_arg result = {
1401 .num_modes = num_modes,
1409 msg = nlmsg_alloc();
1413 feat = get_nl80211_protocol_features(drv);
1414 if (feat & NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)
1415 nl80211_cmd(drv, msg, NLM_F_DUMP, NL80211_CMD_GET_WIPHY);
1417 nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_WIPHY);
1419 NLA_PUT_FLAG(msg, NL80211_ATTR_SPLIT_WIPHY_DUMP);
1420 if (nl80211_set_iface_id(msg, bss) < 0)
1421 goto nla_put_failure;
1423 if (send_and_recv_msgs(drv, msg, phy_info_handler, &result) == 0) {
1424 nl80211_set_regulatory_flags(drv, &result);
1425 return wpa_driver_nl80211_postprocess_modes(result.modes,