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;
77 unsigned int wmm_ac_supported:1;
81 static unsigned int probe_resp_offload_support(int supp_protocols)
83 unsigned int prot = 0;
85 if (supp_protocols & NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS)
86 prot |= WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS;
87 if (supp_protocols & NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2)
88 prot |= WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2;
89 if (supp_protocols & NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P)
90 prot |= WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P;
91 if (supp_protocols & NL80211_PROBE_RESP_OFFLOAD_SUPPORT_80211U)
92 prot |= WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING;
98 static void wiphy_info_supported_iftypes(struct wiphy_info_data *info,
101 struct nlattr *nl_mode;
107 nla_for_each_nested(nl_mode, tb, i) {
108 switch (nla_type(nl_mode)) {
109 case NL80211_IFTYPE_AP:
110 info->capa->flags |= WPA_DRIVER_FLAGS_AP;
112 case NL80211_IFTYPE_MESH_POINT:
113 info->capa->flags |= WPA_DRIVER_FLAGS_MESH;
115 case NL80211_IFTYPE_ADHOC:
116 info->capa->flags |= WPA_DRIVER_FLAGS_IBSS;
118 case NL80211_IFTYPE_P2P_DEVICE:
120 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE;
122 case NL80211_IFTYPE_P2P_GO:
123 info->p2p_go_supported = 1;
125 case NL80211_IFTYPE_P2P_CLIENT:
126 info->p2p_client_supported = 1;
128 case NL80211_IFTYPE_MONITOR:
129 info->monitor_supported = 1;
136 static int wiphy_info_iface_comb_process(struct wiphy_info_data *info,
137 struct nlattr *nl_combi)
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 },
152 iface_limit_policy[NUM_NL80211_IFACE_LIMIT] = {
153 [NL80211_IFACE_LIMIT_TYPES] = { .type = NLA_NESTED },
154 [NL80211_IFACE_LIMIT_MAX] = { .type = NLA_U32 },
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 */
164 if (tb_comb[NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS])
165 info->capa->flags |= WPA_DRIVER_FLAGS_RADAR;
167 nla_for_each_nested(nl_limit, tb_comb[NL80211_IFACE_COMB_LIMITS],
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 */
174 nla_for_each_nested(nl_mode,
175 tb_limit[NL80211_IFACE_LIMIT_TYPES],
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;
184 if (combination_has_p2p && combination_has_mgd)
188 if (combination_has_p2p && combination_has_mgd) {
189 unsigned int num_channels =
190 nla_get_u32(tb_comb[NL80211_IFACE_COMB_NUM_CHANNELS]);
192 info->p2p_concurrent = 1;
193 if (info->num_multichan_concurrent < num_channels)
194 info->num_multichan_concurrent = num_channels;
201 static void wiphy_info_iface_comb(struct wiphy_info_data *info,
204 struct nlattr *nl_combi;
210 nla_for_each_nested(nl_combi, tb, rem_combi) {
211 if (wiphy_info_iface_comb_process(info, nl_combi) > 0)
217 static void wiphy_info_supp_cmds(struct wiphy_info_data *info,
220 struct nlattr *nl_cmd;
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;
231 case NL80211_CMD_CONNECT:
232 info->connect_supported = 1;
234 case NL80211_CMD_START_SCHED_SCAN:
235 info->capa->sched_scan_supported = 1;
237 case NL80211_CMD_PROBE_CLIENT:
238 info->poll_command_supported = 1;
240 case NL80211_CMD_CHANNEL_SWITCH:
241 info->channel_switch_supported = 1;
243 case NL80211_CMD_SET_QOS_MAP:
244 info->set_qos_map_supported = 1;
251 static void wiphy_info_cipher_suites(struct wiphy_info_data *info,
260 num = nla_len(tb) / sizeof(u32);
261 ciphers = nla_data(tb);
262 for (i = 0; i < num; i++) {
265 wpa_printf(MSG_DEBUG, "nl80211: Supported cipher %02x-%02x-%02x:%d",
266 c >> 24, (c >> 16) & 0xff,
267 (c >> 8) & 0xff, c & 0xff);
269 case WLAN_CIPHER_SUITE_CCMP_256:
270 info->capa->enc |= WPA_DRIVER_CAPA_ENC_CCMP_256;
272 case WLAN_CIPHER_SUITE_GCMP_256:
273 info->capa->enc |= WPA_DRIVER_CAPA_ENC_GCMP_256;
275 case WLAN_CIPHER_SUITE_CCMP:
276 info->capa->enc |= WPA_DRIVER_CAPA_ENC_CCMP;
278 case WLAN_CIPHER_SUITE_GCMP:
279 info->capa->enc |= WPA_DRIVER_CAPA_ENC_GCMP;
281 case WLAN_CIPHER_SUITE_TKIP:
282 info->capa->enc |= WPA_DRIVER_CAPA_ENC_TKIP;
284 case WLAN_CIPHER_SUITE_WEP104:
285 info->capa->enc |= WPA_DRIVER_CAPA_ENC_WEP104;
287 case WLAN_CIPHER_SUITE_WEP40:
288 info->capa->enc |= WPA_DRIVER_CAPA_ENC_WEP40;
290 case WLAN_CIPHER_SUITE_AES_CMAC:
291 info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP;
293 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
294 info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP_GMAC_128;
296 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
297 info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP_GMAC_256;
299 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
300 info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP_CMAC_256;
302 case WLAN_CIPHER_SUITE_NO_GROUP_ADDR:
303 info->capa->enc |= WPA_DRIVER_CAPA_ENC_GTK_NOT_USED;
310 static void wiphy_info_max_roc(struct wpa_driver_capa *capa,
314 capa->max_remain_on_chan = nla_get_u32(tb);
318 static void wiphy_info_tdls(struct wpa_driver_capa *capa, struct nlattr *tdls,
319 struct nlattr *ext_setup)
324 wpa_printf(MSG_DEBUG, "nl80211: TDLS supported");
325 capa->flags |= WPA_DRIVER_FLAGS_TDLS_SUPPORT;
328 wpa_printf(MSG_DEBUG, "nl80211: TDLS external setup");
329 capa->flags |= WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP;
334 static void wiphy_info_feature_flags(struct wiphy_info_data *info,
338 struct wpa_driver_capa *capa = info->capa;
343 flags = nla_get_u32(tb);
345 if (flags & NL80211_FEATURE_SK_TX_STATUS)
346 info->data_tx_status = 1;
348 if (flags & NL80211_FEATURE_INACTIVITY_TIMER)
349 capa->flags |= WPA_DRIVER_FLAGS_INACTIVITY_TIMER;
351 if (flags & NL80211_FEATURE_SAE)
352 capa->flags |= WPA_DRIVER_FLAGS_SAE;
354 if (flags & NL80211_FEATURE_NEED_OBSS_SCAN)
355 capa->flags |= WPA_DRIVER_FLAGS_OBSS_SCAN;
357 if (flags & NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)
358 capa->flags |= WPA_DRIVER_FLAGS_HT_2040_COEX;
360 if (flags & NL80211_FEATURE_LOW_PRIORITY_SCAN)
361 info->have_low_prio_scan = 1;
363 if (flags & NL80211_FEATURE_STATIC_SMPS)
364 capa->smps_modes |= WPA_DRIVER_SMPS_MODE_STATIC;
366 if (flags & NL80211_FEATURE_DYNAMIC_SMPS)
367 capa->smps_modes |= WPA_DRIVER_SMPS_MODE_DYNAMIC;
369 if (flags & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
370 info->wmm_ac_supported = 1;
372 if (flags & NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES)
373 capa->rrm_flags |= WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES;
375 if (flags & NL80211_FEATURE_WFA_TPC_IE_IN_PROBES)
376 capa->rrm_flags |= WPA_DRIVER_FLAGS_WFA_TPC_IE_IN_PROBES;
378 if (flags & NL80211_FEATURE_QUIET)
379 capa->rrm_flags |= WPA_DRIVER_FLAGS_QUIET;
381 if (flags & NL80211_FEATURE_TX_POWER_INSERTION)
382 capa->rrm_flags |= WPA_DRIVER_FLAGS_TX_POWER_INSERTION;
386 static void wiphy_info_probe_resp_offload(struct wpa_driver_capa *capa,
394 protocols = nla_get_u32(tb);
395 wpa_printf(MSG_DEBUG, "nl80211: Supports Probe Response offload in AP "
397 capa->flags |= WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD;
398 capa->probe_resp_offloads = probe_resp_offload_support(protocols);
402 static void wiphy_info_wowlan_triggers(struct wpa_driver_capa *capa,
405 struct nlattr *triggers[MAX_NL80211_WOWLAN_TRIG + 1];
410 if (nla_parse_nested(triggers, MAX_NL80211_WOWLAN_TRIG,
414 if (triggers[NL80211_WOWLAN_TRIG_ANY])
415 capa->wowlan_triggers.any = 1;
416 if (triggers[NL80211_WOWLAN_TRIG_DISCONNECT])
417 capa->wowlan_triggers.disconnect = 1;
418 if (triggers[NL80211_WOWLAN_TRIG_MAGIC_PKT])
419 capa->wowlan_triggers.magic_pkt = 1;
420 if (triggers[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE])
421 capa->wowlan_triggers.gtk_rekey_failure = 1;
422 if (triggers[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST])
423 capa->wowlan_triggers.eap_identity_req = 1;
424 if (triggers[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE])
425 capa->wowlan_triggers.four_way_handshake = 1;
426 if (triggers[NL80211_WOWLAN_TRIG_RFKILL_RELEASE])
427 capa->wowlan_triggers.rfkill_release = 1;
431 static int wiphy_info_handler(struct nl_msg *msg, void *arg)
433 struct nlattr *tb[NL80211_ATTR_MAX + 1];
434 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
435 struct wiphy_info_data *info = arg;
436 struct wpa_driver_capa *capa = info->capa;
437 struct wpa_driver_nl80211_data *drv = info->drv;
439 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
440 genlmsg_attrlen(gnlh, 0), NULL);
442 if (tb[NL80211_ATTR_WIPHY_NAME])
443 os_strlcpy(drv->phyname,
444 nla_get_string(tb[NL80211_ATTR_WIPHY_NAME]),
445 sizeof(drv->phyname));
446 if (tb[NL80211_ATTR_MAX_NUM_SCAN_SSIDS])
447 capa->max_scan_ssids =
448 nla_get_u8(tb[NL80211_ATTR_MAX_NUM_SCAN_SSIDS]);
450 if (tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS])
451 capa->max_sched_scan_ssids =
452 nla_get_u8(tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS]);
454 if (tb[NL80211_ATTR_MAX_MATCH_SETS])
455 capa->max_match_sets =
456 nla_get_u8(tb[NL80211_ATTR_MAX_MATCH_SETS]);
458 if (tb[NL80211_ATTR_MAC_ACL_MAX])
459 capa->max_acl_mac_addrs =
460 nla_get_u8(tb[NL80211_ATTR_MAC_ACL_MAX]);
462 wiphy_info_supported_iftypes(info, tb[NL80211_ATTR_SUPPORTED_IFTYPES]);
463 wiphy_info_iface_comb(info, tb[NL80211_ATTR_INTERFACE_COMBINATIONS]);
464 wiphy_info_supp_cmds(info, tb[NL80211_ATTR_SUPPORTED_COMMANDS]);
465 wiphy_info_cipher_suites(info, tb[NL80211_ATTR_CIPHER_SUITES]);
467 if (tb[NL80211_ATTR_OFFCHANNEL_TX_OK]) {
468 wpa_printf(MSG_DEBUG, "nl80211: Using driver-based "
470 capa->flags |= WPA_DRIVER_FLAGS_OFFCHANNEL_TX;
473 if (tb[NL80211_ATTR_ROAM_SUPPORT]) {
474 wpa_printf(MSG_DEBUG, "nl80211: Using driver-based roaming");
475 capa->flags |= WPA_DRIVER_FLAGS_BSS_SELECTION;
478 wiphy_info_max_roc(capa,
479 tb[NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION]);
481 if (tb[NL80211_ATTR_SUPPORT_AP_UAPSD])
482 capa->flags |= WPA_DRIVER_FLAGS_AP_UAPSD;
484 wiphy_info_tdls(capa, tb[NL80211_ATTR_TDLS_SUPPORT],
485 tb[NL80211_ATTR_TDLS_EXTERNAL_SETUP]);
487 if (tb[NL80211_ATTR_DEVICE_AP_SME])
488 info->device_ap_sme = 1;
490 wiphy_info_feature_flags(info, tb[NL80211_ATTR_FEATURE_FLAGS]);
491 wiphy_info_probe_resp_offload(capa,
492 tb[NL80211_ATTR_PROBE_RESP_OFFLOAD]);
494 if (tb[NL80211_ATTR_EXT_CAPA] && tb[NL80211_ATTR_EXT_CAPA_MASK] &&
495 drv->extended_capa == NULL) {
497 os_malloc(nla_len(tb[NL80211_ATTR_EXT_CAPA]));
498 if (drv->extended_capa) {
499 os_memcpy(drv->extended_capa,
500 nla_data(tb[NL80211_ATTR_EXT_CAPA]),
501 nla_len(tb[NL80211_ATTR_EXT_CAPA]));
502 drv->extended_capa_len =
503 nla_len(tb[NL80211_ATTR_EXT_CAPA]);
505 drv->extended_capa_mask =
506 os_malloc(nla_len(tb[NL80211_ATTR_EXT_CAPA]));
507 if (drv->extended_capa_mask) {
508 os_memcpy(drv->extended_capa_mask,
509 nla_data(tb[NL80211_ATTR_EXT_CAPA]),
510 nla_len(tb[NL80211_ATTR_EXT_CAPA]));
512 os_free(drv->extended_capa);
513 drv->extended_capa = NULL;
514 drv->extended_capa_len = 0;
518 if (tb[NL80211_ATTR_VENDOR_DATA]) {
522 nla_for_each_nested(nl, tb[NL80211_ATTR_VENDOR_DATA], rem) {
523 struct nl80211_vendor_cmd_info *vinfo;
524 if (nla_len(nl) != sizeof(*vinfo)) {
525 wpa_printf(MSG_DEBUG, "nl80211: Unexpected vendor data info");
528 vinfo = nla_data(nl);
529 switch (vinfo->subcmd) {
530 case QCA_NL80211_VENDOR_SUBCMD_ROAMING:
531 drv->roaming_vendor_cmd_avail = 1;
533 case QCA_NL80211_VENDOR_SUBCMD_DFS_CAPABILITY:
534 drv->dfs_vendor_cmd_avail = 1;
536 case QCA_NL80211_VENDOR_SUBCMD_KEY_MGMT_SET_KEY:
537 drv->key_mgmt_set_key_vendor_cmd_avail = 1;
541 wpa_printf(MSG_DEBUG, "nl80211: Supported vendor command: vendor_id=0x%x subcmd=%u",
542 vinfo->vendor_id, vinfo->subcmd);
546 if (tb[NL80211_ATTR_VENDOR_EVENTS]) {
550 nla_for_each_nested(nl, tb[NL80211_ATTR_VENDOR_EVENTS], rem) {
551 struct nl80211_vendor_cmd_info *vinfo;
552 if (nla_len(nl) != sizeof(*vinfo)) {
553 wpa_printf(MSG_DEBUG, "nl80211: Unexpected vendor data info");
556 vinfo = nla_data(nl);
558 QCA_NL80211_VENDOR_SUBCMD_KEY_MGMT_ROAM_AUTH)
559 drv->roam_auth_vendor_event_avail = 1;
560 wpa_printf(MSG_DEBUG, "nl80211: Supported vendor event: vendor_id=0x%x subcmd=%u",
561 vinfo->vendor_id, vinfo->subcmd);
565 wiphy_info_wowlan_triggers(capa,
566 tb[NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED]);
568 if (tb[NL80211_ATTR_MAX_AP_ASSOC_STA])
570 nla_get_u32(tb[NL80211_ATTR_MAX_AP_ASSOC_STA]);
576 static int wpa_driver_nl80211_get_info(struct wpa_driver_nl80211_data *drv,
577 struct wiphy_info_data *info)
582 os_memset(info, 0, sizeof(*info));
583 info->capa = &drv->capa;
590 feat = get_nl80211_protocol_features(drv);
591 if (feat & NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)
592 nl80211_cmd(drv, msg, NLM_F_DUMP, NL80211_CMD_GET_WIPHY);
594 nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_WIPHY);
596 NLA_PUT_FLAG(msg, NL80211_ATTR_SPLIT_WIPHY_DUMP);
597 if (nl80211_set_iface_id(msg, drv->first_bss) < 0)
598 goto nla_put_failure;
600 if (send_and_recv_msgs(drv, msg, wiphy_info_handler, info))
603 if (info->auth_supported)
604 drv->capa.flags |= WPA_DRIVER_FLAGS_SME;
605 else if (!info->connect_supported) {
606 wpa_printf(MSG_INFO, "nl80211: Driver does not support "
607 "authentication/association or connect commands");
611 if (info->p2p_go_supported && info->p2p_client_supported)
612 drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CAPABLE;
613 if (info->p2p_concurrent) {
614 wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group "
615 "interface (driver advertised support)");
616 drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT;
617 drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P;
619 if (info->num_multichan_concurrent > 1) {
620 wpa_printf(MSG_DEBUG, "nl80211: Enable multi-channel "
621 "concurrent (driver advertised support)");
622 drv->capa.num_multichan_concurrent =
623 info->num_multichan_concurrent;
625 if (drv->capa.flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)
626 wpa_printf(MSG_DEBUG, "nl80211: use P2P_DEVICE support");
628 /* default to 5000 since early versions of mac80211 don't set it */
629 if (!drv->capa.max_remain_on_chan)
630 drv->capa.max_remain_on_chan = 5000;
632 if (info->channel_switch_supported)
633 drv->capa.flags |= WPA_DRIVER_FLAGS_AP_CSA;
634 drv->capa.wmm_ac_supported = info->wmm_ac_supported;
643 static int dfs_info_handler(struct nl_msg *msg, void *arg)
645 struct nlattr *tb[NL80211_ATTR_MAX + 1];
646 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
647 int *dfs_capability_ptr = arg;
649 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
650 genlmsg_attrlen(gnlh, 0), NULL);
652 if (tb[NL80211_ATTR_VENDOR_DATA]) {
653 struct nlattr *nl_vend = tb[NL80211_ATTR_VENDOR_DATA];
654 struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1];
656 nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX,
657 nla_data(nl_vend), nla_len(nl_vend), NULL);
659 if (tb_vendor[QCA_WLAN_VENDOR_ATTR_DFS]) {
661 val = nla_get_u32(tb_vendor[QCA_WLAN_VENDOR_ATTR_DFS]);
662 wpa_printf(MSG_DEBUG, "nl80211: DFS offload capability: %u",
664 *dfs_capability_ptr = val;
672 static void qca_nl80211_check_dfs_capa(struct wpa_driver_nl80211_data *drv)
675 int dfs_capability = 0;
678 if (!drv->dfs_vendor_cmd_avail)
686 nl80211_cmd(drv, msg, 0, NL80211_CMD_VENDOR);
688 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex);
689 NLA_PUT_U32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA);
690 NLA_PUT_U32(msg, NL80211_ATTR_VENDOR_SUBCMD,
691 QCA_NL80211_VENDOR_SUBCMD_DFS_CAPABILITY);
693 ret = send_and_recv_msgs(drv, msg, dfs_info_handler, &dfs_capability);
694 if (!ret && dfs_capability)
695 drv->capa.flags |= WPA_DRIVER_FLAGS_DFS_OFFLOAD;
703 int wpa_driver_nl80211_capa(struct wpa_driver_nl80211_data *drv)
705 struct wiphy_info_data info;
706 if (wpa_driver_nl80211_get_info(drv, &info))
712 drv->has_capability = 1;
713 drv->capa.key_mgmt = WPA_DRIVER_CAPA_KEY_MGMT_WPA |
714 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
715 WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
716 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK;
717 drv->capa.auth = WPA_DRIVER_AUTH_OPEN |
718 WPA_DRIVER_AUTH_SHARED |
719 WPA_DRIVER_AUTH_LEAP;
721 drv->capa.flags |= WPA_DRIVER_FLAGS_SANE_ERROR_CODES;
722 drv->capa.flags |= WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE;
723 drv->capa.flags |= WPA_DRIVER_FLAGS_EAPOL_TX_STATUS;
726 * As all cfg80211 drivers must support cases where the AP interface is
727 * removed without the knowledge of wpa_supplicant/hostapd, e.g., in
728 * case that the user space daemon has crashed, they must be able to
729 * cleanup all stations and key entries in the AP tear down flow. Thus,
730 * this flag can/should always be set for cfg80211 drivers.
732 drv->capa.flags |= WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT;
734 if (!info.device_ap_sme) {
735 drv->capa.flags |= WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS;
738 * No AP SME is currently assumed to also indicate no AP MLME
739 * in the driver/firmware.
741 drv->capa.flags |= WPA_DRIVER_FLAGS_AP_MLME;
744 drv->device_ap_sme = info.device_ap_sme;
745 drv->poll_command_supported = info.poll_command_supported;
746 drv->data_tx_status = info.data_tx_status;
747 if (info.set_qos_map_supported)
748 drv->capa.flags |= WPA_DRIVER_FLAGS_QOS_MAPPING;
749 drv->have_low_prio_scan = info.have_low_prio_scan;
752 * If poll command and tx status are supported, mac80211 is new enough
753 * to have everything we need to not need monitor interfaces.
755 drv->use_monitor = !info.poll_command_supported || !info.data_tx_status;
757 if (drv->device_ap_sme && drv->use_monitor) {
759 * Non-mac80211 drivers may not support monitor interface.
760 * Make sure we do not get stuck with incorrect capability here
761 * by explicitly testing this.
763 if (!info.monitor_supported) {
764 wpa_printf(MSG_DEBUG, "nl80211: Disable use_monitor "
765 "with device_ap_sme since no monitor mode "
767 drv->use_monitor = 0;
772 * If we aren't going to use monitor interfaces, but the
773 * driver doesn't support data TX status, we won't get TX
774 * status for EAPOL frames.
776 if (!drv->use_monitor && !info.data_tx_status)
777 drv->capa.flags &= ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS;
779 qca_nl80211_check_dfs_capa(drv);
785 struct phy_info_arg {
787 struct hostapd_hw_modes *modes;
788 int last_mode, last_chan_idx;
791 static void phy_info_ht_capa(struct hostapd_hw_modes *mode, struct nlattr *capa,
792 struct nlattr *ampdu_factor,
793 struct nlattr *ampdu_density,
794 struct nlattr *mcs_set)
797 mode->ht_capab = nla_get_u16(capa);
800 mode->a_mpdu_params |= nla_get_u8(ampdu_factor) & 0x03;
803 mode->a_mpdu_params |= nla_get_u8(ampdu_density) << 2;
805 if (mcs_set && nla_len(mcs_set) >= 16) {
807 mcs = nla_data(mcs_set);
808 os_memcpy(mode->mcs_set, mcs, 16);
813 static void phy_info_vht_capa(struct hostapd_hw_modes *mode,
815 struct nlattr *mcs_set)
818 mode->vht_capab = nla_get_u32(capa);
820 if (mcs_set && nla_len(mcs_set) >= 8) {
822 mcs = nla_data(mcs_set);
823 os_memcpy(mode->vht_mcs_set, mcs, 8);
828 static void phy_info_freq(struct hostapd_hw_modes *mode,
829 struct hostapd_channel_data *chan,
830 struct nlattr *tb_freq[])
833 chan->freq = nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_FREQ]);
835 chan->dfs_cac_ms = 0;
836 if (ieee80211_freq_to_chan(chan->freq, &channel) != NUM_HOSTAPD_MODES)
837 chan->chan = channel;
839 if (tb_freq[NL80211_FREQUENCY_ATTR_DISABLED])
840 chan->flag |= HOSTAPD_CHAN_DISABLED;
841 if (tb_freq[NL80211_FREQUENCY_ATTR_NO_IR])
842 chan->flag |= HOSTAPD_CHAN_NO_IR;
843 if (tb_freq[NL80211_FREQUENCY_ATTR_RADAR])
844 chan->flag |= HOSTAPD_CHAN_RADAR;
845 if (tb_freq[NL80211_FREQUENCY_ATTR_INDOOR_ONLY])
846 chan->flag |= HOSTAPD_CHAN_INDOOR_ONLY;
847 if (tb_freq[NL80211_FREQUENCY_ATTR_GO_CONCURRENT])
848 chan->flag |= HOSTAPD_CHAN_GO_CONCURRENT;
850 if (tb_freq[NL80211_FREQUENCY_ATTR_DFS_STATE]) {
851 enum nl80211_dfs_state state =
852 nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_DFS_STATE]);
855 case NL80211_DFS_USABLE:
856 chan->flag |= HOSTAPD_CHAN_DFS_USABLE;
858 case NL80211_DFS_AVAILABLE:
859 chan->flag |= HOSTAPD_CHAN_DFS_AVAILABLE;
861 case NL80211_DFS_UNAVAILABLE:
862 chan->flag |= HOSTAPD_CHAN_DFS_UNAVAILABLE;
867 if (tb_freq[NL80211_FREQUENCY_ATTR_DFS_CAC_TIME]) {
868 chan->dfs_cac_ms = nla_get_u32(
869 tb_freq[NL80211_FREQUENCY_ATTR_DFS_CAC_TIME]);
874 static int phy_info_freqs(struct phy_info_arg *phy_info,
875 struct hostapd_hw_modes *mode, struct nlattr *tb)
877 static struct nla_policy freq_policy[NL80211_FREQUENCY_ATTR_MAX + 1] = {
878 [NL80211_FREQUENCY_ATTR_FREQ] = { .type = NLA_U32 },
879 [NL80211_FREQUENCY_ATTR_DISABLED] = { .type = NLA_FLAG },
880 [NL80211_FREQUENCY_ATTR_NO_IR] = { .type = NLA_FLAG },
881 [NL80211_FREQUENCY_ATTR_RADAR] = { .type = NLA_FLAG },
882 [NL80211_FREQUENCY_ATTR_MAX_TX_POWER] = { .type = NLA_U32 },
883 [NL80211_FREQUENCY_ATTR_DFS_STATE] = { .type = NLA_U32 },
885 int new_channels = 0;
886 struct hostapd_channel_data *channel;
887 struct nlattr *tb_freq[NL80211_FREQUENCY_ATTR_MAX + 1];
888 struct nlattr *nl_freq;
894 nla_for_each_nested(nl_freq, tb, rem_freq) {
895 nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX,
896 nla_data(nl_freq), nla_len(nl_freq), freq_policy);
897 if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ])
902 channel = os_realloc_array(mode->channels,
903 mode->num_channels + new_channels,
904 sizeof(struct hostapd_channel_data));
908 mode->channels = channel;
909 mode->num_channels += new_channels;
911 idx = phy_info->last_chan_idx;
913 nla_for_each_nested(nl_freq, tb, rem_freq) {
914 nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX,
915 nla_data(nl_freq), nla_len(nl_freq), freq_policy);
916 if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ])
918 phy_info_freq(mode, &mode->channels[idx], tb_freq);
921 phy_info->last_chan_idx = idx;
927 static int phy_info_rates(struct hostapd_hw_modes *mode, struct nlattr *tb)
929 static struct nla_policy rate_policy[NL80211_BITRATE_ATTR_MAX + 1] = {
930 [NL80211_BITRATE_ATTR_RATE] = { .type = NLA_U32 },
931 [NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE] =
932 { .type = NLA_FLAG },
934 struct nlattr *tb_rate[NL80211_BITRATE_ATTR_MAX + 1];
935 struct nlattr *nl_rate;
941 nla_for_each_nested(nl_rate, tb, rem_rate) {
942 nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX,
943 nla_data(nl_rate), nla_len(nl_rate),
945 if (!tb_rate[NL80211_BITRATE_ATTR_RATE])
950 mode->rates = os_calloc(mode->num_rates, sizeof(int));
956 nla_for_each_nested(nl_rate, tb, rem_rate) {
957 nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX,
958 nla_data(nl_rate), nla_len(nl_rate),
960 if (!tb_rate[NL80211_BITRATE_ATTR_RATE])
962 mode->rates[idx] = nla_get_u32(
963 tb_rate[NL80211_BITRATE_ATTR_RATE]);
971 static int phy_info_band(struct phy_info_arg *phy_info, struct nlattr *nl_band)
973 struct nlattr *tb_band[NL80211_BAND_ATTR_MAX + 1];
974 struct hostapd_hw_modes *mode;
977 if (phy_info->last_mode != nl_band->nla_type) {
978 mode = os_realloc_array(phy_info->modes,
979 *phy_info->num_modes + 1,
983 phy_info->modes = mode;
985 mode = &phy_info->modes[*(phy_info->num_modes)];
986 os_memset(mode, 0, sizeof(*mode));
987 mode->mode = NUM_HOSTAPD_MODES;
988 mode->flags = HOSTAPD_MODE_FLAG_HT_INFO_KNOWN |
989 HOSTAPD_MODE_FLAG_VHT_INFO_KNOWN;
992 * Unsupported VHT MCS stream is defined as value 3, so the VHT
993 * MCS RX/TX map must be initialized with 0xffff to mark all 8
994 * possible streams as unsupported. This will be overridden if
995 * driver advertises VHT support.
997 mode->vht_mcs_set[0] = 0xff;
998 mode->vht_mcs_set[1] = 0xff;
999 mode->vht_mcs_set[4] = 0xff;
1000 mode->vht_mcs_set[5] = 0xff;
1002 *(phy_info->num_modes) += 1;
1003 phy_info->last_mode = nl_band->nla_type;
1004 phy_info->last_chan_idx = 0;
1006 mode = &phy_info->modes[*(phy_info->num_modes) - 1];
1008 nla_parse(tb_band, NL80211_BAND_ATTR_MAX, nla_data(nl_band),
1009 nla_len(nl_band), NULL);
1011 phy_info_ht_capa(mode, tb_band[NL80211_BAND_ATTR_HT_CAPA],
1012 tb_band[NL80211_BAND_ATTR_HT_AMPDU_FACTOR],
1013 tb_band[NL80211_BAND_ATTR_HT_AMPDU_DENSITY],
1014 tb_band[NL80211_BAND_ATTR_HT_MCS_SET]);
1015 phy_info_vht_capa(mode, tb_band[NL80211_BAND_ATTR_VHT_CAPA],
1016 tb_band[NL80211_BAND_ATTR_VHT_MCS_SET]);
1017 ret = phy_info_freqs(phy_info, mode, tb_band[NL80211_BAND_ATTR_FREQS]);
1020 ret = phy_info_rates(mode, tb_band[NL80211_BAND_ATTR_RATES]);
1028 static int phy_info_handler(struct nl_msg *msg, void *arg)
1030 struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
1031 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1032 struct phy_info_arg *phy_info = arg;
1033 struct nlattr *nl_band;
1036 nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1037 genlmsg_attrlen(gnlh, 0), NULL);
1039 if (!tb_msg[NL80211_ATTR_WIPHY_BANDS])
1042 nla_for_each_nested(nl_band, tb_msg[NL80211_ATTR_WIPHY_BANDS], rem_band)
1044 int res = phy_info_band(phy_info, nl_band);
1053 static struct hostapd_hw_modes *
1054 wpa_driver_nl80211_postprocess_modes(struct hostapd_hw_modes *modes,
1058 struct hostapd_hw_modes *mode11g = NULL, *nmodes, *mode;
1059 int i, mode11g_idx = -1;
1061 /* heuristic to set up modes */
1062 for (m = 0; m < *num_modes; m++) {
1063 if (!modes[m].num_channels)
1065 if (modes[m].channels[0].freq < 4000) {
1066 modes[m].mode = HOSTAPD_MODE_IEEE80211B;
1067 for (i = 0; i < modes[m].num_rates; i++) {
1068 if (modes[m].rates[i] > 200) {
1069 modes[m].mode = HOSTAPD_MODE_IEEE80211G;
1073 } else if (modes[m].channels[0].freq > 50000)
1074 modes[m].mode = HOSTAPD_MODE_IEEE80211AD;
1076 modes[m].mode = HOSTAPD_MODE_IEEE80211A;
1079 /* If only 802.11g mode is included, use it to construct matching
1080 * 802.11b mode data. */
1082 for (m = 0; m < *num_modes; m++) {
1083 if (modes[m].mode == HOSTAPD_MODE_IEEE80211B)
1084 return modes; /* 802.11b already included */
1085 if (modes[m].mode == HOSTAPD_MODE_IEEE80211G)
1089 if (mode11g_idx < 0)
1090 return modes; /* 2.4 GHz band not supported at all */
1092 nmodes = os_realloc_array(modes, *num_modes + 1, sizeof(*nmodes));
1094 return modes; /* Could not add 802.11b mode */
1096 mode = &nmodes[*num_modes];
1097 os_memset(mode, 0, sizeof(*mode));
1101 mode->mode = HOSTAPD_MODE_IEEE80211B;
1103 mode11g = &modes[mode11g_idx];
1104 mode->num_channels = mode11g->num_channels;
1105 mode->channels = os_malloc(mode11g->num_channels *
1106 sizeof(struct hostapd_channel_data));
1107 if (mode->channels == NULL) {
1109 return modes; /* Could not add 802.11b mode */
1111 os_memcpy(mode->channels, mode11g->channels,
1112 mode11g->num_channels * sizeof(struct hostapd_channel_data));
1114 mode->num_rates = 0;
1115 mode->rates = os_malloc(4 * sizeof(int));
1116 if (mode->rates == NULL) {
1117 os_free(mode->channels);
1119 return modes; /* Could not add 802.11b mode */
1122 for (i = 0; i < mode11g->num_rates; i++) {
1123 if (mode11g->rates[i] != 10 && mode11g->rates[i] != 20 &&
1124 mode11g->rates[i] != 55 && mode11g->rates[i] != 110)
1126 mode->rates[mode->num_rates] = mode11g->rates[i];
1128 if (mode->num_rates == 4)
1132 if (mode->num_rates == 0) {
1133 os_free(mode->channels);
1134 os_free(mode->rates);
1136 return modes; /* No 802.11b rates */
1139 wpa_printf(MSG_DEBUG, "nl80211: Added 802.11b mode based on 802.11g "
1146 static void nl80211_set_ht40_mode(struct hostapd_hw_modes *mode, int start,
1151 for (c = 0; c < mode->num_channels; c++) {
1152 struct hostapd_channel_data *chan = &mode->channels[c];
1153 if (chan->freq - 10 >= start && chan->freq + 10 <= end)
1154 chan->flag |= HOSTAPD_CHAN_HT40;
1159 static void nl80211_set_ht40_mode_sec(struct hostapd_hw_modes *mode, int start,
1164 for (c = 0; c < mode->num_channels; c++) {
1165 struct hostapd_channel_data *chan = &mode->channels[c];
1166 if (!(chan->flag & HOSTAPD_CHAN_HT40))
1168 if (chan->freq - 30 >= start && chan->freq - 10 <= end)
1169 chan->flag |= HOSTAPD_CHAN_HT40MINUS;
1170 if (chan->freq + 10 >= start && chan->freq + 30 <= end)
1171 chan->flag |= HOSTAPD_CHAN_HT40PLUS;
1176 static void nl80211_reg_rule_max_eirp(u32 start, u32 end, u32 max_eirp,
1177 struct phy_info_arg *results)
1181 for (m = 0; m < *results->num_modes; m++) {
1183 struct hostapd_hw_modes *mode = &results->modes[m];
1185 for (c = 0; c < mode->num_channels; c++) {
1186 struct hostapd_channel_data *chan = &mode->channels[c];
1187 if ((u32) chan->freq - 10 >= start &&
1188 (u32) chan->freq + 10 <= end)
1189 chan->max_tx_power = max_eirp;
1195 static void nl80211_reg_rule_ht40(u32 start, u32 end,
1196 struct phy_info_arg *results)
1200 for (m = 0; m < *results->num_modes; m++) {
1201 if (!(results->modes[m].ht_capab &
1202 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET))
1204 nl80211_set_ht40_mode(&results->modes[m], start, end);
1209 static void nl80211_reg_rule_sec(struct nlattr *tb[],
1210 struct phy_info_arg *results)
1212 u32 start, end, max_bw;
1215 if (tb[NL80211_ATTR_FREQ_RANGE_START] == NULL ||
1216 tb[NL80211_ATTR_FREQ_RANGE_END] == NULL ||
1217 tb[NL80211_ATTR_FREQ_RANGE_MAX_BW] == NULL)
1220 start = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]) / 1000;
1221 end = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]) / 1000;
1222 max_bw = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) / 1000;
1227 for (m = 0; m < *results->num_modes; m++) {
1228 if (!(results->modes[m].ht_capab &
1229 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET))
1231 nl80211_set_ht40_mode_sec(&results->modes[m], start, end);
1236 static void nl80211_set_vht_mode(struct hostapd_hw_modes *mode, int start,
1241 for (c = 0; c < mode->num_channels; c++) {
1242 struct hostapd_channel_data *chan = &mode->channels[c];
1243 if (chan->freq - 10 >= start && chan->freq + 70 <= end)
1244 chan->flag |= HOSTAPD_CHAN_VHT_10_70;
1246 if (chan->freq - 30 >= start && chan->freq + 50 <= end)
1247 chan->flag |= HOSTAPD_CHAN_VHT_30_50;
1249 if (chan->freq - 50 >= start && chan->freq + 30 <= end)
1250 chan->flag |= HOSTAPD_CHAN_VHT_50_30;
1252 if (chan->freq - 70 >= start && chan->freq + 10 <= end)
1253 chan->flag |= HOSTAPD_CHAN_VHT_70_10;
1258 static void nl80211_reg_rule_vht(struct nlattr *tb[],
1259 struct phy_info_arg *results)
1261 u32 start, end, max_bw;
1264 if (tb[NL80211_ATTR_FREQ_RANGE_START] == NULL ||
1265 tb[NL80211_ATTR_FREQ_RANGE_END] == NULL ||
1266 tb[NL80211_ATTR_FREQ_RANGE_MAX_BW] == NULL)
1269 start = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]) / 1000;
1270 end = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]) / 1000;
1271 max_bw = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) / 1000;
1276 for (m = 0; m < *results->num_modes; m++) {
1277 if (!(results->modes[m].ht_capab &
1278 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET))
1280 /* TODO: use a real VHT support indication */
1281 if (!results->modes[m].vht_capab)
1284 nl80211_set_vht_mode(&results->modes[m], start, end);
1289 static const char * dfs_domain_name(enum nl80211_dfs_regions region)
1292 case NL80211_DFS_UNSET:
1294 case NL80211_DFS_FCC:
1296 case NL80211_DFS_ETSI:
1298 case NL80211_DFS_JP:
1301 return "DFS-invalid";
1306 static int nl80211_get_reg(struct nl_msg *msg, void *arg)
1308 struct phy_info_arg *results = arg;
1309 struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
1310 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1311 struct nlattr *nl_rule;
1312 struct nlattr *tb_rule[NL80211_FREQUENCY_ATTR_MAX + 1];
1314 static struct nla_policy reg_policy[NL80211_FREQUENCY_ATTR_MAX + 1] = {
1315 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
1316 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
1317 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
1318 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
1319 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
1320 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
1323 nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1324 genlmsg_attrlen(gnlh, 0), NULL);
1325 if (!tb_msg[NL80211_ATTR_REG_ALPHA2] ||
1326 !tb_msg[NL80211_ATTR_REG_RULES]) {
1327 wpa_printf(MSG_DEBUG, "nl80211: No regulatory information "
1332 if (tb_msg[NL80211_ATTR_DFS_REGION]) {
1333 enum nl80211_dfs_regions dfs_domain;
1334 dfs_domain = nla_get_u8(tb_msg[NL80211_ATTR_DFS_REGION]);
1335 wpa_printf(MSG_DEBUG, "nl80211: Regulatory information - country=%s (%s)",
1336 (char *) nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]),
1337 dfs_domain_name(dfs_domain));
1339 wpa_printf(MSG_DEBUG, "nl80211: Regulatory information - country=%s",
1340 (char *) nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]));
1343 nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule)
1345 u32 start, end, max_eirp = 0, max_bw = 0, flags = 0;
1346 nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX,
1347 nla_data(nl_rule), nla_len(nl_rule), reg_policy);
1348 if (tb_rule[NL80211_ATTR_FREQ_RANGE_START] == NULL ||
1349 tb_rule[NL80211_ATTR_FREQ_RANGE_END] == NULL)
1351 start = nla_get_u32(tb_rule[NL80211_ATTR_FREQ_RANGE_START]) / 1000;
1352 end = nla_get_u32(tb_rule[NL80211_ATTR_FREQ_RANGE_END]) / 1000;
1353 if (tb_rule[NL80211_ATTR_POWER_RULE_MAX_EIRP])
1354 max_eirp = nla_get_u32(tb_rule[NL80211_ATTR_POWER_RULE_MAX_EIRP]) / 100;
1355 if (tb_rule[NL80211_ATTR_FREQ_RANGE_MAX_BW])
1356 max_bw = nla_get_u32(tb_rule[NL80211_ATTR_FREQ_RANGE_MAX_BW]) / 1000;
1357 if (tb_rule[NL80211_ATTR_REG_RULE_FLAGS])
1358 flags = nla_get_u32(tb_rule[NL80211_ATTR_REG_RULE_FLAGS]);
1360 wpa_printf(MSG_DEBUG, "nl80211: %u-%u @ %u MHz %u mBm%s%s%s%s%s%s%s%s",
1361 start, end, max_bw, max_eirp,
1362 flags & NL80211_RRF_NO_OFDM ? " (no OFDM)" : "",
1363 flags & NL80211_RRF_NO_CCK ? " (no CCK)" : "",
1364 flags & NL80211_RRF_NO_INDOOR ? " (no indoor)" : "",
1365 flags & NL80211_RRF_NO_OUTDOOR ? " (no outdoor)" :
1367 flags & NL80211_RRF_DFS ? " (DFS)" : "",
1368 flags & NL80211_RRF_PTP_ONLY ? " (PTP only)" : "",
1369 flags & NL80211_RRF_PTMP_ONLY ? " (PTMP only)" : "",
1370 flags & NL80211_RRF_NO_IR ? " (no IR)" : "");
1372 nl80211_reg_rule_ht40(start, end, results);
1373 if (tb_rule[NL80211_ATTR_POWER_RULE_MAX_EIRP])
1374 nl80211_reg_rule_max_eirp(start, end, max_eirp,
1378 nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule)
1380 nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX,
1381 nla_data(nl_rule), nla_len(nl_rule), reg_policy);
1382 nl80211_reg_rule_sec(tb_rule, results);
1385 nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule)
1387 nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX,
1388 nla_data(nl_rule), nla_len(nl_rule), reg_policy);
1389 nl80211_reg_rule_vht(tb_rule, results);
1396 static int nl80211_set_regulatory_flags(struct wpa_driver_nl80211_data *drv,
1397 struct phy_info_arg *results)
1401 msg = nlmsg_alloc();
1405 nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG);
1406 return send_and_recv_msgs(drv, msg, nl80211_get_reg, results);
1410 struct hostapd_hw_modes *
1411 nl80211_get_hw_feature_data(void *priv, u16 *num_modes, u16 *flags)
1414 struct i802_bss *bss = priv;
1415 struct wpa_driver_nl80211_data *drv = bss->drv;
1417 struct phy_info_arg result = {
1418 .num_modes = num_modes,
1426 msg = nlmsg_alloc();
1430 feat = get_nl80211_protocol_features(drv);
1431 if (feat & NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)
1432 nl80211_cmd(drv, msg, NLM_F_DUMP, NL80211_CMD_GET_WIPHY);
1434 nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_WIPHY);
1436 NLA_PUT_FLAG(msg, NL80211_ATTR_SPLIT_WIPHY_DUMP);
1437 if (nl80211_set_iface_id(msg, bss) < 0)
1438 goto nla_put_failure;
1440 if (send_and_recv_msgs(drv, msg, phy_info_handler, &result) == 0) {
1441 nl80211_set_regulatory_flags(drv, &result);
1442 return wpa_driver_nl80211_postprocess_modes(result.modes,