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
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 if (!nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_PROTOCOL_FEATURES
)) {
52 if (send_and_recv_msgs(drv
, msg
, protocol_feature_handler
, &feat
) == 0)
59 struct wiphy_info_data
{
60 struct wpa_driver_nl80211_data
*drv
;
61 struct wpa_driver_capa
*capa
;
63 unsigned int num_multichan_concurrent
;
66 unsigned int device_ap_sme
:1;
67 unsigned int poll_command_supported
:1;
68 unsigned int data_tx_status
:1;
69 unsigned int monitor_supported
:1;
70 unsigned int auth_supported
:1;
71 unsigned int connect_supported
:1;
72 unsigned int p2p_go_supported
:1;
73 unsigned int p2p_client_supported
:1;
74 unsigned int p2p_go_ctwindow_supported
:1;
75 unsigned int p2p_concurrent
:1;
76 unsigned int channel_switch_supported
:1;
77 unsigned int set_qos_map_supported
:1;
78 unsigned int have_low_prio_scan
:1;
79 unsigned int wmm_ac_supported
:1;
80 unsigned int mac_addr_rand_scan_supported
:1;
81 unsigned int mac_addr_rand_sched_scan_supported
:1;
85 static unsigned int probe_resp_offload_support(int supp_protocols
)
87 unsigned int prot
= 0;
89 if (supp_protocols
& NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS
)
90 prot
|= WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS
;
91 if (supp_protocols
& NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2
)
92 prot
|= WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2
;
93 if (supp_protocols
& NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P
)
94 prot
|= WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P
;
95 if (supp_protocols
& NL80211_PROBE_RESP_OFFLOAD_SUPPORT_80211U
)
96 prot
|= WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING
;
102 static void wiphy_info_supported_iftypes(struct wiphy_info_data
*info
,
105 struct nlattr
*nl_mode
;
111 nla_for_each_nested(nl_mode
, tb
, i
) {
112 switch (nla_type(nl_mode
)) {
113 case NL80211_IFTYPE_AP
:
114 info
->capa
->flags
|= WPA_DRIVER_FLAGS_AP
;
116 case NL80211_IFTYPE_MESH_POINT
:
117 info
->capa
->flags
|= WPA_DRIVER_FLAGS_MESH
;
119 case NL80211_IFTYPE_ADHOC
:
120 info
->capa
->flags
|= WPA_DRIVER_FLAGS_IBSS
;
122 case NL80211_IFTYPE_P2P_DEVICE
:
124 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE
;
126 case NL80211_IFTYPE_P2P_GO
:
127 info
->p2p_go_supported
= 1;
129 case NL80211_IFTYPE_P2P_CLIENT
:
130 info
->p2p_client_supported
= 1;
132 case NL80211_IFTYPE_MONITOR
:
133 info
->monitor_supported
= 1;
140 static int wiphy_info_iface_comb_process(struct wiphy_info_data
*info
,
141 struct nlattr
*nl_combi
)
143 struct nlattr
*tb_comb
[NUM_NL80211_IFACE_COMB
];
144 struct nlattr
*tb_limit
[NUM_NL80211_IFACE_LIMIT
];
145 struct nlattr
*nl_limit
, *nl_mode
;
146 int err
, rem_limit
, rem_mode
;
147 int combination_has_p2p
= 0, combination_has_mgd
= 0;
148 static struct nla_policy
149 iface_combination_policy
[NUM_NL80211_IFACE_COMB
] = {
150 [NL80211_IFACE_COMB_LIMITS
] = { .type
= NLA_NESTED
},
151 [NL80211_IFACE_COMB_MAXNUM
] = { .type
= NLA_U32
},
152 [NL80211_IFACE_COMB_STA_AP_BI_MATCH
] = { .type
= NLA_FLAG
},
153 [NL80211_IFACE_COMB_NUM_CHANNELS
] = { .type
= NLA_U32
},
154 [NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS
] = { .type
= NLA_U32
},
156 iface_limit_policy
[NUM_NL80211_IFACE_LIMIT
] = {
157 [NL80211_IFACE_LIMIT_TYPES
] = { .type
= NLA_NESTED
},
158 [NL80211_IFACE_LIMIT_MAX
] = { .type
= NLA_U32
},
161 err
= nla_parse_nested(tb_comb
, MAX_NL80211_IFACE_COMB
,
162 nl_combi
, iface_combination_policy
);
163 if (err
|| !tb_comb
[NL80211_IFACE_COMB_LIMITS
] ||
164 !tb_comb
[NL80211_IFACE_COMB_MAXNUM
] ||
165 !tb_comb
[NL80211_IFACE_COMB_NUM_CHANNELS
])
166 return 0; /* broken combination */
168 if (tb_comb
[NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS
])
169 info
->capa
->flags
|= WPA_DRIVER_FLAGS_RADAR
;
171 nla_for_each_nested(nl_limit
, tb_comb
[NL80211_IFACE_COMB_LIMITS
],
173 err
= nla_parse_nested(tb_limit
, MAX_NL80211_IFACE_LIMIT
,
174 nl_limit
, iface_limit_policy
);
175 if (err
|| !tb_limit
[NL80211_IFACE_LIMIT_TYPES
])
176 return 0; /* broken combination */
178 nla_for_each_nested(nl_mode
,
179 tb_limit
[NL80211_IFACE_LIMIT_TYPES
],
181 int ift
= nla_type(nl_mode
);
182 if (ift
== NL80211_IFTYPE_P2P_GO
||
183 ift
== NL80211_IFTYPE_P2P_CLIENT
)
184 combination_has_p2p
= 1;
185 if (ift
== NL80211_IFTYPE_STATION
)
186 combination_has_mgd
= 1;
188 if (combination_has_p2p
&& combination_has_mgd
)
192 if (combination_has_p2p
&& combination_has_mgd
) {
193 unsigned int num_channels
=
194 nla_get_u32(tb_comb
[NL80211_IFACE_COMB_NUM_CHANNELS
]);
196 info
->p2p_concurrent
= 1;
197 if (info
->num_multichan_concurrent
< num_channels
)
198 info
->num_multichan_concurrent
= num_channels
;
205 static void wiphy_info_iface_comb(struct wiphy_info_data
*info
,
208 struct nlattr
*nl_combi
;
214 nla_for_each_nested(nl_combi
, tb
, rem_combi
) {
215 if (wiphy_info_iface_comb_process(info
, nl_combi
) > 0)
221 static void wiphy_info_supp_cmds(struct wiphy_info_data
*info
,
224 struct nlattr
*nl_cmd
;
230 nla_for_each_nested(nl_cmd
, tb
, i
) {
231 switch (nla_get_u32(nl_cmd
)) {
232 case NL80211_CMD_AUTHENTICATE
:
233 info
->auth_supported
= 1;
235 case NL80211_CMD_CONNECT
:
236 info
->connect_supported
= 1;
238 case NL80211_CMD_START_SCHED_SCAN
:
239 info
->capa
->sched_scan_supported
= 1;
241 case NL80211_CMD_PROBE_CLIENT
:
242 info
->poll_command_supported
= 1;
244 case NL80211_CMD_CHANNEL_SWITCH
:
245 info
->channel_switch_supported
= 1;
247 case NL80211_CMD_SET_QOS_MAP
:
248 info
->set_qos_map_supported
= 1;
255 static void wiphy_info_cipher_suites(struct wiphy_info_data
*info
,
264 num
= nla_len(tb
) / sizeof(u32
);
265 ciphers
= nla_data(tb
);
266 for (i
= 0; i
< num
; i
++) {
269 wpa_printf(MSG_DEBUG
, "nl80211: Supported cipher %02x-%02x-%02x:%d",
270 c
>> 24, (c
>> 16) & 0xff,
271 (c
>> 8) & 0xff, c
& 0xff);
273 case WLAN_CIPHER_SUITE_CCMP_256
:
274 info
->capa
->enc
|= WPA_DRIVER_CAPA_ENC_CCMP_256
;
276 case WLAN_CIPHER_SUITE_GCMP_256
:
277 info
->capa
->enc
|= WPA_DRIVER_CAPA_ENC_GCMP_256
;
279 case WLAN_CIPHER_SUITE_CCMP
:
280 info
->capa
->enc
|= WPA_DRIVER_CAPA_ENC_CCMP
;
282 case WLAN_CIPHER_SUITE_GCMP
:
283 info
->capa
->enc
|= WPA_DRIVER_CAPA_ENC_GCMP
;
285 case WLAN_CIPHER_SUITE_TKIP
:
286 info
->capa
->enc
|= WPA_DRIVER_CAPA_ENC_TKIP
;
288 case WLAN_CIPHER_SUITE_WEP104
:
289 info
->capa
->enc
|= WPA_DRIVER_CAPA_ENC_WEP104
;
291 case WLAN_CIPHER_SUITE_WEP40
:
292 info
->capa
->enc
|= WPA_DRIVER_CAPA_ENC_WEP40
;
294 case WLAN_CIPHER_SUITE_AES_CMAC
:
295 info
->capa
->enc
|= WPA_DRIVER_CAPA_ENC_BIP
;
297 case WLAN_CIPHER_SUITE_BIP_GMAC_128
:
298 info
->capa
->enc
|= WPA_DRIVER_CAPA_ENC_BIP_GMAC_128
;
300 case WLAN_CIPHER_SUITE_BIP_GMAC_256
:
301 info
->capa
->enc
|= WPA_DRIVER_CAPA_ENC_BIP_GMAC_256
;
303 case WLAN_CIPHER_SUITE_BIP_CMAC_256
:
304 info
->capa
->enc
|= WPA_DRIVER_CAPA_ENC_BIP_CMAC_256
;
306 case WLAN_CIPHER_SUITE_NO_GROUP_ADDR
:
307 info
->capa
->enc
|= WPA_DRIVER_CAPA_ENC_GTK_NOT_USED
;
314 static void wiphy_info_max_roc(struct wpa_driver_capa
*capa
,
318 capa
->max_remain_on_chan
= nla_get_u32(tb
);
322 static void wiphy_info_tdls(struct wpa_driver_capa
*capa
, struct nlattr
*tdls
,
323 struct nlattr
*ext_setup
)
328 wpa_printf(MSG_DEBUG
, "nl80211: TDLS supported");
329 capa
->flags
|= WPA_DRIVER_FLAGS_TDLS_SUPPORT
;
332 wpa_printf(MSG_DEBUG
, "nl80211: TDLS external setup");
333 capa
->flags
|= WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP
;
338 static int ext_feature_isset(const u8
*ext_features
, int ext_features_len
,
339 enum nl80211_ext_feature_index ftidx
)
343 if ((int) ftidx
/ 8 >= ext_features_len
)
346 ft_byte
= ext_features
[ftidx
/ 8];
347 return (ft_byte
& BIT(ftidx
% 8)) != 0;
351 static void wiphy_info_ext_feature_flags(struct wiphy_info_data
*info
,
354 struct wpa_driver_capa
*capa
= info
->capa
;
359 if (ext_feature_isset(nla_data(tb
), nla_len(tb
),
360 NL80211_EXT_FEATURE_VHT_IBSS
))
361 capa
->flags
|= WPA_DRIVER_FLAGS_VHT_IBSS
;
365 static void wiphy_info_feature_flags(struct wiphy_info_data
*info
,
369 struct wpa_driver_capa
*capa
= info
->capa
;
374 flags
= nla_get_u32(tb
);
376 if (flags
& NL80211_FEATURE_SK_TX_STATUS
)
377 info
->data_tx_status
= 1;
379 if (flags
& NL80211_FEATURE_INACTIVITY_TIMER
)
380 capa
->flags
|= WPA_DRIVER_FLAGS_INACTIVITY_TIMER
;
382 if (flags
& NL80211_FEATURE_SAE
)
383 capa
->flags
|= WPA_DRIVER_FLAGS_SAE
;
385 if (flags
& NL80211_FEATURE_NEED_OBSS_SCAN
)
386 capa
->flags
|= WPA_DRIVER_FLAGS_OBSS_SCAN
;
388 if (flags
& NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE
)
389 capa
->flags
|= WPA_DRIVER_FLAGS_HT_2040_COEX
;
391 if (flags
& NL80211_FEATURE_TDLS_CHANNEL_SWITCH
) {
392 wpa_printf(MSG_DEBUG
, "nl80211: TDLS channel switch");
393 capa
->flags
|= WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH
;
396 if (flags
& NL80211_FEATURE_P2P_GO_CTWIN
)
397 info
->p2p_go_ctwindow_supported
= 1;
399 if (flags
& NL80211_FEATURE_LOW_PRIORITY_SCAN
)
400 info
->have_low_prio_scan
= 1;
402 if (flags
& NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR
)
403 info
->mac_addr_rand_scan_supported
= 1;
405 if (flags
& NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR
)
406 info
->mac_addr_rand_sched_scan_supported
= 1;
408 if (flags
& NL80211_FEATURE_STATIC_SMPS
)
409 capa
->smps_modes
|= WPA_DRIVER_SMPS_MODE_STATIC
;
411 if (flags
& NL80211_FEATURE_DYNAMIC_SMPS
)
412 capa
->smps_modes
|= WPA_DRIVER_SMPS_MODE_DYNAMIC
;
414 if (flags
& NL80211_FEATURE_SUPPORTS_WMM_ADMISSION
)
415 info
->wmm_ac_supported
= 1;
417 if (flags
& NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES
)
418 capa
->rrm_flags
|= WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES
;
420 if (flags
& NL80211_FEATURE_WFA_TPC_IE_IN_PROBES
)
421 capa
->rrm_flags
|= WPA_DRIVER_FLAGS_WFA_TPC_IE_IN_PROBES
;
423 if (flags
& NL80211_FEATURE_QUIET
)
424 capa
->rrm_flags
|= WPA_DRIVER_FLAGS_QUIET
;
426 if (flags
& NL80211_FEATURE_TX_POWER_INSERTION
)
427 capa
->rrm_flags
|= WPA_DRIVER_FLAGS_TX_POWER_INSERTION
;
429 if (flags
& NL80211_FEATURE_HT_IBSS
)
430 capa
->flags
|= WPA_DRIVER_FLAGS_HT_IBSS
;
434 static void wiphy_info_probe_resp_offload(struct wpa_driver_capa
*capa
,
442 protocols
= nla_get_u32(tb
);
443 wpa_printf(MSG_DEBUG
, "nl80211: Supports Probe Response offload in AP "
445 capa
->flags
|= WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD
;
446 capa
->probe_resp_offloads
= probe_resp_offload_support(protocols
);
450 static void wiphy_info_wowlan_triggers(struct wpa_driver_capa
*capa
,
453 struct nlattr
*triggers
[MAX_NL80211_WOWLAN_TRIG
+ 1];
458 if (nla_parse_nested(triggers
, MAX_NL80211_WOWLAN_TRIG
,
462 if (triggers
[NL80211_WOWLAN_TRIG_ANY
])
463 capa
->wowlan_triggers
.any
= 1;
464 if (triggers
[NL80211_WOWLAN_TRIG_DISCONNECT
])
465 capa
->wowlan_triggers
.disconnect
= 1;
466 if (triggers
[NL80211_WOWLAN_TRIG_MAGIC_PKT
])
467 capa
->wowlan_triggers
.magic_pkt
= 1;
468 if (triggers
[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
])
469 capa
->wowlan_triggers
.gtk_rekey_failure
= 1;
470 if (triggers
[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
])
471 capa
->wowlan_triggers
.eap_identity_req
= 1;
472 if (triggers
[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
])
473 capa
->wowlan_triggers
.four_way_handshake
= 1;
474 if (triggers
[NL80211_WOWLAN_TRIG_RFKILL_RELEASE
])
475 capa
->wowlan_triggers
.rfkill_release
= 1;
479 static int wiphy_info_handler(struct nl_msg
*msg
, void *arg
)
481 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
482 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
483 struct wiphy_info_data
*info
= arg
;
484 struct wpa_driver_capa
*capa
= info
->capa
;
485 struct wpa_driver_nl80211_data
*drv
= info
->drv
;
487 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
488 genlmsg_attrlen(gnlh
, 0), NULL
);
490 if (tb
[NL80211_ATTR_WIPHY_NAME
])
491 os_strlcpy(drv
->phyname
,
492 nla_get_string(tb
[NL80211_ATTR_WIPHY_NAME
]),
493 sizeof(drv
->phyname
));
494 if (tb
[NL80211_ATTR_MAX_NUM_SCAN_SSIDS
])
495 capa
->max_scan_ssids
=
496 nla_get_u8(tb
[NL80211_ATTR_MAX_NUM_SCAN_SSIDS
]);
498 if (tb
[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS
])
499 capa
->max_sched_scan_ssids
=
500 nla_get_u8(tb
[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS
]);
502 if (tb
[NL80211_ATTR_MAX_MATCH_SETS
])
503 capa
->max_match_sets
=
504 nla_get_u8(tb
[NL80211_ATTR_MAX_MATCH_SETS
]);
506 if (tb
[NL80211_ATTR_MAC_ACL_MAX
])
507 capa
->max_acl_mac_addrs
=
508 nla_get_u8(tb
[NL80211_ATTR_MAC_ACL_MAX
]);
510 wiphy_info_supported_iftypes(info
, tb
[NL80211_ATTR_SUPPORTED_IFTYPES
]);
511 wiphy_info_iface_comb(info
, tb
[NL80211_ATTR_INTERFACE_COMBINATIONS
]);
512 wiphy_info_supp_cmds(info
, tb
[NL80211_ATTR_SUPPORTED_COMMANDS
]);
513 wiphy_info_cipher_suites(info
, tb
[NL80211_ATTR_CIPHER_SUITES
]);
515 if (tb
[NL80211_ATTR_OFFCHANNEL_TX_OK
]) {
516 wpa_printf(MSG_DEBUG
, "nl80211: Using driver-based "
518 capa
->flags
|= WPA_DRIVER_FLAGS_OFFCHANNEL_TX
;
521 if (tb
[NL80211_ATTR_ROAM_SUPPORT
]) {
522 wpa_printf(MSG_DEBUG
, "nl80211: Using driver-based roaming");
523 capa
->flags
|= WPA_DRIVER_FLAGS_BSS_SELECTION
;
526 wiphy_info_max_roc(capa
,
527 tb
[NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION
]);
529 if (tb
[NL80211_ATTR_SUPPORT_AP_UAPSD
])
530 capa
->flags
|= WPA_DRIVER_FLAGS_AP_UAPSD
;
532 wiphy_info_tdls(capa
, tb
[NL80211_ATTR_TDLS_SUPPORT
],
533 tb
[NL80211_ATTR_TDLS_EXTERNAL_SETUP
]);
535 if (tb
[NL80211_ATTR_DEVICE_AP_SME
])
536 info
->device_ap_sme
= 1;
538 wiphy_info_feature_flags(info
, tb
[NL80211_ATTR_FEATURE_FLAGS
]);
539 wiphy_info_ext_feature_flags(info
, tb
[NL80211_ATTR_EXT_FEATURES
]);
540 wiphy_info_probe_resp_offload(capa
,
541 tb
[NL80211_ATTR_PROBE_RESP_OFFLOAD
]);
543 if (tb
[NL80211_ATTR_EXT_CAPA
] && tb
[NL80211_ATTR_EXT_CAPA_MASK
] &&
544 drv
->extended_capa
== NULL
) {
546 os_malloc(nla_len(tb
[NL80211_ATTR_EXT_CAPA
]));
547 if (drv
->extended_capa
) {
548 os_memcpy(drv
->extended_capa
,
549 nla_data(tb
[NL80211_ATTR_EXT_CAPA
]),
550 nla_len(tb
[NL80211_ATTR_EXT_CAPA
]));
551 drv
->extended_capa_len
=
552 nla_len(tb
[NL80211_ATTR_EXT_CAPA
]);
554 drv
->extended_capa_mask
=
555 os_malloc(nla_len(tb
[NL80211_ATTR_EXT_CAPA_MASK
]));
556 if (drv
->extended_capa_mask
) {
557 os_memcpy(drv
->extended_capa_mask
,
558 nla_data(tb
[NL80211_ATTR_EXT_CAPA_MASK
]),
559 nla_len(tb
[NL80211_ATTR_EXT_CAPA_MASK
]));
561 os_free(drv
->extended_capa
);
562 drv
->extended_capa
= NULL
;
563 drv
->extended_capa_len
= 0;
567 if (tb
[NL80211_ATTR_VENDOR_DATA
]) {
571 nla_for_each_nested(nl
, tb
[NL80211_ATTR_VENDOR_DATA
], rem
) {
572 struct nl80211_vendor_cmd_info
*vinfo
;
573 if (nla_len(nl
) != sizeof(*vinfo
)) {
574 wpa_printf(MSG_DEBUG
, "nl80211: Unexpected vendor data info");
577 vinfo
= nla_data(nl
);
578 if (vinfo
->vendor_id
== OUI_QCA
) {
579 switch (vinfo
->subcmd
) {
580 case QCA_NL80211_VENDOR_SUBCMD_TEST
:
581 drv
->vendor_cmd_test_avail
= 1;
583 case QCA_NL80211_VENDOR_SUBCMD_ROAMING
:
584 drv
->roaming_vendor_cmd_avail
= 1;
586 case QCA_NL80211_VENDOR_SUBCMD_DFS_CAPABILITY
:
587 drv
->dfs_vendor_cmd_avail
= 1;
589 case QCA_NL80211_VENDOR_SUBCMD_GET_FEATURES
:
590 drv
->get_features_vendor_cmd_avail
= 1;
592 case QCA_NL80211_VENDOR_SUBCMD_DO_ACS
:
594 WPA_DRIVER_FLAGS_ACS_OFFLOAD
;
596 case QCA_NL80211_VENDOR_SUBCMD_SETBAND
:
597 drv
->setband_vendor_cmd_avail
= 1;
602 wpa_printf(MSG_DEBUG
, "nl80211: Supported vendor command: vendor_id=0x%x subcmd=%u",
603 vinfo
->vendor_id
, vinfo
->subcmd
);
607 if (tb
[NL80211_ATTR_VENDOR_EVENTS
]) {
611 nla_for_each_nested(nl
, tb
[NL80211_ATTR_VENDOR_EVENTS
], rem
) {
612 struct nl80211_vendor_cmd_info
*vinfo
;
613 if (nla_len(nl
) != sizeof(*vinfo
)) {
614 wpa_printf(MSG_DEBUG
, "nl80211: Unexpected vendor data info");
617 vinfo
= nla_data(nl
);
618 wpa_printf(MSG_DEBUG
, "nl80211: Supported vendor event: vendor_id=0x%x subcmd=%u",
619 vinfo
->vendor_id
, vinfo
->subcmd
);
623 wiphy_info_wowlan_triggers(capa
,
624 tb
[NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED
]);
626 if (tb
[NL80211_ATTR_MAX_AP_ASSOC_STA
])
628 nla_get_u32(tb
[NL80211_ATTR_MAX_AP_ASSOC_STA
]);
634 static int wpa_driver_nl80211_get_info(struct wpa_driver_nl80211_data
*drv
,
635 struct wiphy_info_data
*info
)
641 os_memset(info
, 0, sizeof(*info
));
642 info
->capa
= &drv
->capa
;
645 feat
= get_nl80211_protocol_features(drv
);
646 if (feat
& NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP
)
648 msg
= nl80211_cmd_msg(drv
->first_bss
, flags
, NL80211_CMD_GET_WIPHY
);
649 if (!msg
|| nla_put_flag(msg
, NL80211_ATTR_SPLIT_WIPHY_DUMP
)) {
654 if (send_and_recv_msgs(drv
, msg
, wiphy_info_handler
, info
))
657 if (info
->auth_supported
)
658 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_SME
;
659 else if (!info
->connect_supported
) {
660 wpa_printf(MSG_INFO
, "nl80211: Driver does not support "
661 "authentication/association or connect commands");
665 if (info
->p2p_go_supported
&& info
->p2p_client_supported
)
666 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_P2P_CAPABLE
;
667 if (info
->p2p_concurrent
) {
668 wpa_printf(MSG_DEBUG
, "nl80211: Use separate P2P group "
669 "interface (driver advertised support)");
670 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_P2P_CONCURRENT
;
671 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P
;
673 if (info
->num_multichan_concurrent
> 1) {
674 wpa_printf(MSG_DEBUG
, "nl80211: Enable multi-channel "
675 "concurrent (driver advertised support)");
676 drv
->capa
.num_multichan_concurrent
=
677 info
->num_multichan_concurrent
;
679 if (drv
->capa
.flags
& WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE
)
680 wpa_printf(MSG_DEBUG
, "nl80211: use P2P_DEVICE support");
682 /* default to 5000 since early versions of mac80211 don't set it */
683 if (!drv
->capa
.max_remain_on_chan
)
684 drv
->capa
.max_remain_on_chan
= 5000;
686 if (info
->channel_switch_supported
)
687 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_AP_CSA
;
688 drv
->capa
.wmm_ac_supported
= info
->wmm_ac_supported
;
690 drv
->capa
.mac_addr_rand_sched_scan_supported
=
691 info
->mac_addr_rand_sched_scan_supported
;
692 drv
->capa
.mac_addr_rand_scan_supported
=
693 info
->mac_addr_rand_scan_supported
;
699 static int dfs_info_handler(struct nl_msg
*msg
, void *arg
)
701 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
702 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
703 int *dfs_capability_ptr
= arg
;
705 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
706 genlmsg_attrlen(gnlh
, 0), NULL
);
708 if (tb
[NL80211_ATTR_VENDOR_DATA
]) {
709 struct nlattr
*nl_vend
= tb
[NL80211_ATTR_VENDOR_DATA
];
710 struct nlattr
*tb_vendor
[QCA_WLAN_VENDOR_ATTR_MAX
+ 1];
712 nla_parse(tb_vendor
, QCA_WLAN_VENDOR_ATTR_MAX
,
713 nla_data(nl_vend
), nla_len(nl_vend
), NULL
);
715 if (tb_vendor
[QCA_WLAN_VENDOR_ATTR_DFS
]) {
717 val
= nla_get_u32(tb_vendor
[QCA_WLAN_VENDOR_ATTR_DFS
]);
718 wpa_printf(MSG_DEBUG
, "nl80211: DFS offload capability: %u",
720 *dfs_capability_ptr
= val
;
728 static void qca_nl80211_check_dfs_capa(struct wpa_driver_nl80211_data
*drv
)
731 int dfs_capability
= 0;
734 if (!drv
->dfs_vendor_cmd_avail
)
737 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_VENDOR
)) ||
738 nla_put_u32(msg
, NL80211_ATTR_VENDOR_ID
, OUI_QCA
) ||
739 nla_put_u32(msg
, NL80211_ATTR_VENDOR_SUBCMD
,
740 QCA_NL80211_VENDOR_SUBCMD_DFS_CAPABILITY
)) {
745 ret
= send_and_recv_msgs(drv
, msg
, dfs_info_handler
, &dfs_capability
);
746 if (!ret
&& dfs_capability
)
747 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_DFS_OFFLOAD
;
751 struct features_info
{
757 static int features_info_handler(struct nl_msg
*msg
, void *arg
)
759 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
760 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
761 struct features_info
*info
= arg
;
762 struct nlattr
*nl_vend
, *attr
;
764 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
765 genlmsg_attrlen(gnlh
, 0), NULL
);
767 nl_vend
= tb
[NL80211_ATTR_VENDOR_DATA
];
769 struct nlattr
*tb_vendor
[QCA_WLAN_VENDOR_ATTR_MAX
+ 1];
771 nla_parse(tb_vendor
, QCA_WLAN_VENDOR_ATTR_MAX
,
772 nla_data(nl_vend
), nla_len(nl_vend
), NULL
);
774 attr
= tb_vendor
[QCA_WLAN_VENDOR_ATTR_FEATURE_FLAGS
];
776 info
->flags
= nla_data(attr
);
777 info
->flags_len
= nla_len(attr
);
785 static int check_feature(enum qca_wlan_vendor_features feature
,
786 struct features_info
*info
)
788 size_t idx
= feature
/ 8;
790 return (idx
< info
->flags_len
) &&
791 (info
->flags
[idx
] & BIT(feature
% 8));
795 static void qca_nl80211_get_features(struct wpa_driver_nl80211_data
*drv
)
798 struct features_info info
;
801 if (!drv
->get_features_vendor_cmd_avail
)
804 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_VENDOR
)) ||
805 nla_put_u32(msg
, NL80211_ATTR_VENDOR_ID
, OUI_QCA
) ||
806 nla_put_u32(msg
, NL80211_ATTR_VENDOR_SUBCMD
,
807 QCA_NL80211_VENDOR_SUBCMD_GET_FEATURES
)) {
812 os_memset(&info
, 0, sizeof(info
));
813 ret
= send_and_recv_msgs(drv
, msg
, features_info_handler
, &info
);
814 if (ret
|| !info
.flags
)
817 if (check_feature(QCA_WLAN_VENDOR_FEATURE_KEY_MGMT_OFFLOAD
, &info
))
818 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD
;
820 if (check_feature(QCA_WLAN_VENDOR_FEATURE_SUPPORT_HW_MODE_ANY
, &info
))
821 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_SUPPORT_HW_MODE_ANY
;
825 int wpa_driver_nl80211_capa(struct wpa_driver_nl80211_data
*drv
)
827 struct wiphy_info_data info
;
828 if (wpa_driver_nl80211_get_info(drv
, &info
))
834 drv
->has_capability
= 1;
835 drv
->capa
.key_mgmt
= WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
836 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
|
837 WPA_DRIVER_CAPA_KEY_MGMT_WPA2
|
838 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
|
839 WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B
|
840 WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192
;
841 drv
->capa
.auth
= WPA_DRIVER_AUTH_OPEN
|
842 WPA_DRIVER_AUTH_SHARED
|
843 WPA_DRIVER_AUTH_LEAP
;
845 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_SANE_ERROR_CODES
;
846 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE
;
847 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_EAPOL_TX_STATUS
;
850 * As all cfg80211 drivers must support cases where the AP interface is
851 * removed without the knowledge of wpa_supplicant/hostapd, e.g., in
852 * case that the user space daemon has crashed, they must be able to
853 * cleanup all stations and key entries in the AP tear down flow. Thus,
854 * this flag can/should always be set for cfg80211 drivers.
856 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT
;
858 if (!info
.device_ap_sme
) {
859 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS
;
862 * No AP SME is currently assumed to also indicate no AP MLME
863 * in the driver/firmware.
865 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_AP_MLME
;
868 drv
->device_ap_sme
= info
.device_ap_sme
;
869 drv
->poll_command_supported
= info
.poll_command_supported
;
870 drv
->data_tx_status
= info
.data_tx_status
;
871 drv
->p2p_go_ctwindow_supported
= info
.p2p_go_ctwindow_supported
;
872 if (info
.set_qos_map_supported
)
873 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_QOS_MAPPING
;
874 drv
->have_low_prio_scan
= info
.have_low_prio_scan
;
877 * If poll command and tx status are supported, mac80211 is new enough
878 * to have everything we need to not need monitor interfaces.
880 drv
->use_monitor
= !info
.poll_command_supported
|| !info
.data_tx_status
;
882 if (drv
->device_ap_sme
&& drv
->use_monitor
) {
884 * Non-mac80211 drivers may not support monitor interface.
885 * Make sure we do not get stuck with incorrect capability here
886 * by explicitly testing this.
888 if (!info
.monitor_supported
) {
889 wpa_printf(MSG_DEBUG
, "nl80211: Disable use_monitor "
890 "with device_ap_sme since no monitor mode "
892 drv
->use_monitor
= 0;
897 * If we aren't going to use monitor interfaces, but the
898 * driver doesn't support data TX status, we won't get TX
899 * status for EAPOL frames.
901 if (!drv
->use_monitor
&& !info
.data_tx_status
)
902 drv
->capa
.flags
&= ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS
;
904 qca_nl80211_check_dfs_capa(drv
);
905 qca_nl80211_get_features(drv
);
911 struct phy_info_arg
{
913 struct hostapd_hw_modes
*modes
;
914 int last_mode
, last_chan_idx
;
917 static void phy_info_ht_capa(struct hostapd_hw_modes
*mode
, struct nlattr
*capa
,
918 struct nlattr
*ampdu_factor
,
919 struct nlattr
*ampdu_density
,
920 struct nlattr
*mcs_set
)
923 mode
->ht_capab
= nla_get_u16(capa
);
926 mode
->a_mpdu_params
|= nla_get_u8(ampdu_factor
) & 0x03;
929 mode
->a_mpdu_params
|= nla_get_u8(ampdu_density
) << 2;
931 if (mcs_set
&& nla_len(mcs_set
) >= 16) {
933 mcs
= nla_data(mcs_set
);
934 os_memcpy(mode
->mcs_set
, mcs
, 16);
939 static void phy_info_vht_capa(struct hostapd_hw_modes
*mode
,
941 struct nlattr
*mcs_set
)
944 mode
->vht_capab
= nla_get_u32(capa
);
946 if (mcs_set
&& nla_len(mcs_set
) >= 8) {
948 mcs
= nla_data(mcs_set
);
949 os_memcpy(mode
->vht_mcs_set
, mcs
, 8);
954 static void phy_info_freq(struct hostapd_hw_modes
*mode
,
955 struct hostapd_channel_data
*chan
,
956 struct nlattr
*tb_freq
[])
959 chan
->freq
= nla_get_u32(tb_freq
[NL80211_FREQUENCY_ATTR_FREQ
]);
961 chan
->dfs_cac_ms
= 0;
962 if (ieee80211_freq_to_chan(chan
->freq
, &channel
) != NUM_HOSTAPD_MODES
)
963 chan
->chan
= channel
;
965 if (tb_freq
[NL80211_FREQUENCY_ATTR_DISABLED
])
966 chan
->flag
|= HOSTAPD_CHAN_DISABLED
;
967 if (tb_freq
[NL80211_FREQUENCY_ATTR_NO_IR
])
968 chan
->flag
|= HOSTAPD_CHAN_NO_IR
;
969 if (tb_freq
[NL80211_FREQUENCY_ATTR_RADAR
])
970 chan
->flag
|= HOSTAPD_CHAN_RADAR
;
971 if (tb_freq
[NL80211_FREQUENCY_ATTR_INDOOR_ONLY
])
972 chan
->flag
|= HOSTAPD_CHAN_INDOOR_ONLY
;
973 if (tb_freq
[NL80211_FREQUENCY_ATTR_GO_CONCURRENT
])
974 chan
->flag
|= HOSTAPD_CHAN_GO_CONCURRENT
;
976 if (tb_freq
[NL80211_FREQUENCY_ATTR_DFS_STATE
]) {
977 enum nl80211_dfs_state state
=
978 nla_get_u32(tb_freq
[NL80211_FREQUENCY_ATTR_DFS_STATE
]);
981 case NL80211_DFS_USABLE
:
982 chan
->flag
|= HOSTAPD_CHAN_DFS_USABLE
;
984 case NL80211_DFS_AVAILABLE
:
985 chan
->flag
|= HOSTAPD_CHAN_DFS_AVAILABLE
;
987 case NL80211_DFS_UNAVAILABLE
:
988 chan
->flag
|= HOSTAPD_CHAN_DFS_UNAVAILABLE
;
993 if (tb_freq
[NL80211_FREQUENCY_ATTR_DFS_CAC_TIME
]) {
994 chan
->dfs_cac_ms
= nla_get_u32(
995 tb_freq
[NL80211_FREQUENCY_ATTR_DFS_CAC_TIME
]);
1000 static int phy_info_freqs(struct phy_info_arg
*phy_info
,
1001 struct hostapd_hw_modes
*mode
, struct nlattr
*tb
)
1003 static struct nla_policy freq_policy
[NL80211_FREQUENCY_ATTR_MAX
+ 1] = {
1004 [NL80211_FREQUENCY_ATTR_FREQ
] = { .type
= NLA_U32
},
1005 [NL80211_FREQUENCY_ATTR_DISABLED
] = { .type
= NLA_FLAG
},
1006 [NL80211_FREQUENCY_ATTR_NO_IR
] = { .type
= NLA_FLAG
},
1007 [NL80211_FREQUENCY_ATTR_RADAR
] = { .type
= NLA_FLAG
},
1008 [NL80211_FREQUENCY_ATTR_MAX_TX_POWER
] = { .type
= NLA_U32
},
1009 [NL80211_FREQUENCY_ATTR_DFS_STATE
] = { .type
= NLA_U32
},
1011 int new_channels
= 0;
1012 struct hostapd_channel_data
*channel
;
1013 struct nlattr
*tb_freq
[NL80211_FREQUENCY_ATTR_MAX
+ 1];
1014 struct nlattr
*nl_freq
;
1020 nla_for_each_nested(nl_freq
, tb
, rem_freq
) {
1021 nla_parse(tb_freq
, NL80211_FREQUENCY_ATTR_MAX
,
1022 nla_data(nl_freq
), nla_len(nl_freq
), freq_policy
);
1023 if (!tb_freq
[NL80211_FREQUENCY_ATTR_FREQ
])
1028 channel
= os_realloc_array(mode
->channels
,
1029 mode
->num_channels
+ new_channels
,
1030 sizeof(struct hostapd_channel_data
));
1034 mode
->channels
= channel
;
1035 mode
->num_channels
+= new_channels
;
1037 idx
= phy_info
->last_chan_idx
;
1039 nla_for_each_nested(nl_freq
, tb
, rem_freq
) {
1040 nla_parse(tb_freq
, NL80211_FREQUENCY_ATTR_MAX
,
1041 nla_data(nl_freq
), nla_len(nl_freq
), freq_policy
);
1042 if (!tb_freq
[NL80211_FREQUENCY_ATTR_FREQ
])
1044 phy_info_freq(mode
, &mode
->channels
[idx
], tb_freq
);
1047 phy_info
->last_chan_idx
= idx
;
1053 static int phy_info_rates(struct hostapd_hw_modes
*mode
, struct nlattr
*tb
)
1055 static struct nla_policy rate_policy
[NL80211_BITRATE_ATTR_MAX
+ 1] = {
1056 [NL80211_BITRATE_ATTR_RATE
] = { .type
= NLA_U32
},
1057 [NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
] =
1058 { .type
= NLA_FLAG
},
1060 struct nlattr
*tb_rate
[NL80211_BITRATE_ATTR_MAX
+ 1];
1061 struct nlattr
*nl_rate
;
1067 nla_for_each_nested(nl_rate
, tb
, rem_rate
) {
1068 nla_parse(tb_rate
, NL80211_BITRATE_ATTR_MAX
,
1069 nla_data(nl_rate
), nla_len(nl_rate
),
1071 if (!tb_rate
[NL80211_BITRATE_ATTR_RATE
])
1076 mode
->rates
= os_calloc(mode
->num_rates
, sizeof(int));
1082 nla_for_each_nested(nl_rate
, tb
, rem_rate
) {
1083 nla_parse(tb_rate
, NL80211_BITRATE_ATTR_MAX
,
1084 nla_data(nl_rate
), nla_len(nl_rate
),
1086 if (!tb_rate
[NL80211_BITRATE_ATTR_RATE
])
1088 mode
->rates
[idx
] = nla_get_u32(
1089 tb_rate
[NL80211_BITRATE_ATTR_RATE
]);
1097 static int phy_info_band(struct phy_info_arg
*phy_info
, struct nlattr
*nl_band
)
1099 struct nlattr
*tb_band
[NL80211_BAND_ATTR_MAX
+ 1];
1100 struct hostapd_hw_modes
*mode
;
1103 if (phy_info
->last_mode
!= nl_band
->nla_type
) {
1104 mode
= os_realloc_array(phy_info
->modes
,
1105 *phy_info
->num_modes
+ 1,
1109 phy_info
->modes
= mode
;
1111 mode
= &phy_info
->modes
[*(phy_info
->num_modes
)];
1112 os_memset(mode
, 0, sizeof(*mode
));
1113 mode
->mode
= NUM_HOSTAPD_MODES
;
1114 mode
->flags
= HOSTAPD_MODE_FLAG_HT_INFO_KNOWN
|
1115 HOSTAPD_MODE_FLAG_VHT_INFO_KNOWN
;
1118 * Unsupported VHT MCS stream is defined as value 3, so the VHT
1119 * MCS RX/TX map must be initialized with 0xffff to mark all 8
1120 * possible streams as unsupported. This will be overridden if
1121 * driver advertises VHT support.
1123 mode
->vht_mcs_set
[0] = 0xff;
1124 mode
->vht_mcs_set
[1] = 0xff;
1125 mode
->vht_mcs_set
[4] = 0xff;
1126 mode
->vht_mcs_set
[5] = 0xff;
1128 *(phy_info
->num_modes
) += 1;
1129 phy_info
->last_mode
= nl_band
->nla_type
;
1130 phy_info
->last_chan_idx
= 0;
1132 mode
= &phy_info
->modes
[*(phy_info
->num_modes
) - 1];
1134 nla_parse(tb_band
, NL80211_BAND_ATTR_MAX
, nla_data(nl_band
),
1135 nla_len(nl_band
), NULL
);
1137 phy_info_ht_capa(mode
, tb_band
[NL80211_BAND_ATTR_HT_CAPA
],
1138 tb_band
[NL80211_BAND_ATTR_HT_AMPDU_FACTOR
],
1139 tb_band
[NL80211_BAND_ATTR_HT_AMPDU_DENSITY
],
1140 tb_band
[NL80211_BAND_ATTR_HT_MCS_SET
]);
1141 phy_info_vht_capa(mode
, tb_band
[NL80211_BAND_ATTR_VHT_CAPA
],
1142 tb_band
[NL80211_BAND_ATTR_VHT_MCS_SET
]);
1143 ret
= phy_info_freqs(phy_info
, mode
, tb_band
[NL80211_BAND_ATTR_FREQS
]);
1146 ret
= phy_info_rates(mode
, tb_band
[NL80211_BAND_ATTR_RATES
]);
1154 static int phy_info_handler(struct nl_msg
*msg
, void *arg
)
1156 struct nlattr
*tb_msg
[NL80211_ATTR_MAX
+ 1];
1157 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
1158 struct phy_info_arg
*phy_info
= arg
;
1159 struct nlattr
*nl_band
;
1162 nla_parse(tb_msg
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
1163 genlmsg_attrlen(gnlh
, 0), NULL
);
1165 if (!tb_msg
[NL80211_ATTR_WIPHY_BANDS
])
1168 nla_for_each_nested(nl_band
, tb_msg
[NL80211_ATTR_WIPHY_BANDS
], rem_band
)
1170 int res
= phy_info_band(phy_info
, nl_band
);
1179 static struct hostapd_hw_modes
*
1180 wpa_driver_nl80211_postprocess_modes(struct hostapd_hw_modes
*modes
,
1184 struct hostapd_hw_modes
*mode11g
= NULL
, *nmodes
, *mode
;
1185 int i
, mode11g_idx
= -1;
1187 /* heuristic to set up modes */
1188 for (m
= 0; m
< *num_modes
; m
++) {
1189 if (!modes
[m
].num_channels
)
1191 if (modes
[m
].channels
[0].freq
< 4000) {
1192 modes
[m
].mode
= HOSTAPD_MODE_IEEE80211B
;
1193 for (i
= 0; i
< modes
[m
].num_rates
; i
++) {
1194 if (modes
[m
].rates
[i
] > 200) {
1195 modes
[m
].mode
= HOSTAPD_MODE_IEEE80211G
;
1199 } else if (modes
[m
].channels
[0].freq
> 50000)
1200 modes
[m
].mode
= HOSTAPD_MODE_IEEE80211AD
;
1202 modes
[m
].mode
= HOSTAPD_MODE_IEEE80211A
;
1205 /* If only 802.11g mode is included, use it to construct matching
1206 * 802.11b mode data. */
1208 for (m
= 0; m
< *num_modes
; m
++) {
1209 if (modes
[m
].mode
== HOSTAPD_MODE_IEEE80211B
)
1210 return modes
; /* 802.11b already included */
1211 if (modes
[m
].mode
== HOSTAPD_MODE_IEEE80211G
)
1215 if (mode11g_idx
< 0)
1216 return modes
; /* 2.4 GHz band not supported at all */
1218 nmodes
= os_realloc_array(modes
, *num_modes
+ 1, sizeof(*nmodes
));
1220 return modes
; /* Could not add 802.11b mode */
1222 mode
= &nmodes
[*num_modes
];
1223 os_memset(mode
, 0, sizeof(*mode
));
1227 mode
->mode
= HOSTAPD_MODE_IEEE80211B
;
1229 mode11g
= &modes
[mode11g_idx
];
1230 mode
->num_channels
= mode11g
->num_channels
;
1231 mode
->channels
= os_malloc(mode11g
->num_channels
*
1232 sizeof(struct hostapd_channel_data
));
1233 if (mode
->channels
== NULL
) {
1235 return modes
; /* Could not add 802.11b mode */
1237 os_memcpy(mode
->channels
, mode11g
->channels
,
1238 mode11g
->num_channels
* sizeof(struct hostapd_channel_data
));
1240 mode
->num_rates
= 0;
1241 mode
->rates
= os_malloc(4 * sizeof(int));
1242 if (mode
->rates
== NULL
) {
1243 os_free(mode
->channels
);
1245 return modes
; /* Could not add 802.11b mode */
1248 for (i
= 0; i
< mode11g
->num_rates
; i
++) {
1249 if (mode11g
->rates
[i
] != 10 && mode11g
->rates
[i
] != 20 &&
1250 mode11g
->rates
[i
] != 55 && mode11g
->rates
[i
] != 110)
1252 mode
->rates
[mode
->num_rates
] = mode11g
->rates
[i
];
1254 if (mode
->num_rates
== 4)
1258 if (mode
->num_rates
== 0) {
1259 os_free(mode
->channels
);
1260 os_free(mode
->rates
);
1262 return modes
; /* No 802.11b rates */
1265 wpa_printf(MSG_DEBUG
, "nl80211: Added 802.11b mode based on 802.11g "
1272 static void nl80211_set_ht40_mode(struct hostapd_hw_modes
*mode
, int start
,
1277 for (c
= 0; c
< mode
->num_channels
; c
++) {
1278 struct hostapd_channel_data
*chan
= &mode
->channels
[c
];
1279 if (chan
->freq
- 10 >= start
&& chan
->freq
+ 10 <= end
)
1280 chan
->flag
|= HOSTAPD_CHAN_HT40
;
1285 static void nl80211_set_ht40_mode_sec(struct hostapd_hw_modes
*mode
, int start
,
1290 for (c
= 0; c
< mode
->num_channels
; c
++) {
1291 struct hostapd_channel_data
*chan
= &mode
->channels
[c
];
1292 if (!(chan
->flag
& HOSTAPD_CHAN_HT40
))
1294 if (chan
->freq
- 30 >= start
&& chan
->freq
- 10 <= end
)
1295 chan
->flag
|= HOSTAPD_CHAN_HT40MINUS
;
1296 if (chan
->freq
+ 10 >= start
&& chan
->freq
+ 30 <= end
)
1297 chan
->flag
|= HOSTAPD_CHAN_HT40PLUS
;
1302 static void nl80211_reg_rule_max_eirp(u32 start
, u32 end
, u32 max_eirp
,
1303 struct phy_info_arg
*results
)
1307 for (m
= 0; m
< *results
->num_modes
; m
++) {
1309 struct hostapd_hw_modes
*mode
= &results
->modes
[m
];
1311 for (c
= 0; c
< mode
->num_channels
; c
++) {
1312 struct hostapd_channel_data
*chan
= &mode
->channels
[c
];
1313 if ((u32
) chan
->freq
- 10 >= start
&&
1314 (u32
) chan
->freq
+ 10 <= end
)
1315 chan
->max_tx_power
= max_eirp
;
1321 static void nl80211_reg_rule_ht40(u32 start
, u32 end
,
1322 struct phy_info_arg
*results
)
1326 for (m
= 0; m
< *results
->num_modes
; m
++) {
1327 if (!(results
->modes
[m
].ht_capab
&
1328 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET
))
1330 nl80211_set_ht40_mode(&results
->modes
[m
], start
, end
);
1335 static void nl80211_reg_rule_sec(struct nlattr
*tb
[],
1336 struct phy_info_arg
*results
)
1338 u32 start
, end
, max_bw
;
1341 if (tb
[NL80211_ATTR_FREQ_RANGE_START
] == NULL
||
1342 tb
[NL80211_ATTR_FREQ_RANGE_END
] == NULL
||
1343 tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
] == NULL
)
1346 start
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]) / 1000;
1347 end
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]) / 1000;
1348 max_bw
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]) / 1000;
1353 for (m
= 0; m
< *results
->num_modes
; m
++) {
1354 if (!(results
->modes
[m
].ht_capab
&
1355 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET
))
1357 nl80211_set_ht40_mode_sec(&results
->modes
[m
], start
, end
);
1362 static void nl80211_set_vht_mode(struct hostapd_hw_modes
*mode
, int start
,
1367 for (c
= 0; c
< mode
->num_channels
; c
++) {
1368 struct hostapd_channel_data
*chan
= &mode
->channels
[c
];
1369 if (chan
->freq
- 10 >= start
&& chan
->freq
+ 70 <= end
)
1370 chan
->flag
|= HOSTAPD_CHAN_VHT_10_70
;
1372 if (chan
->freq
- 30 >= start
&& chan
->freq
+ 50 <= end
)
1373 chan
->flag
|= HOSTAPD_CHAN_VHT_30_50
;
1375 if (chan
->freq
- 50 >= start
&& chan
->freq
+ 30 <= end
)
1376 chan
->flag
|= HOSTAPD_CHAN_VHT_50_30
;
1378 if (chan
->freq
- 70 >= start
&& chan
->freq
+ 10 <= end
)
1379 chan
->flag
|= HOSTAPD_CHAN_VHT_70_10
;
1384 static void nl80211_reg_rule_vht(struct nlattr
*tb
[],
1385 struct phy_info_arg
*results
)
1387 u32 start
, end
, max_bw
;
1390 if (tb
[NL80211_ATTR_FREQ_RANGE_START
] == NULL
||
1391 tb
[NL80211_ATTR_FREQ_RANGE_END
] == NULL
||
1392 tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
] == NULL
)
1395 start
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]) / 1000;
1396 end
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]) / 1000;
1397 max_bw
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]) / 1000;
1402 for (m
= 0; m
< *results
->num_modes
; m
++) {
1403 if (!(results
->modes
[m
].ht_capab
&
1404 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET
))
1406 /* TODO: use a real VHT support indication */
1407 if (!results
->modes
[m
].vht_capab
)
1410 nl80211_set_vht_mode(&results
->modes
[m
], start
, end
);
1415 static const char * dfs_domain_name(enum nl80211_dfs_regions region
)
1418 case NL80211_DFS_UNSET
:
1420 case NL80211_DFS_FCC
:
1422 case NL80211_DFS_ETSI
:
1424 case NL80211_DFS_JP
:
1427 return "DFS-invalid";
1432 static int nl80211_get_reg(struct nl_msg
*msg
, void *arg
)
1434 struct phy_info_arg
*results
= arg
;
1435 struct nlattr
*tb_msg
[NL80211_ATTR_MAX
+ 1];
1436 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
1437 struct nlattr
*nl_rule
;
1438 struct nlattr
*tb_rule
[NL80211_FREQUENCY_ATTR_MAX
+ 1];
1440 static struct nla_policy reg_policy
[NL80211_FREQUENCY_ATTR_MAX
+ 1] = {
1441 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
1442 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
1443 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
1444 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
1445 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
1446 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
1449 nla_parse(tb_msg
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
1450 genlmsg_attrlen(gnlh
, 0), NULL
);
1451 if (!tb_msg
[NL80211_ATTR_REG_ALPHA2
] ||
1452 !tb_msg
[NL80211_ATTR_REG_RULES
]) {
1453 wpa_printf(MSG_DEBUG
, "nl80211: No regulatory information "
1458 if (tb_msg
[NL80211_ATTR_DFS_REGION
]) {
1459 enum nl80211_dfs_regions dfs_domain
;
1460 dfs_domain
= nla_get_u8(tb_msg
[NL80211_ATTR_DFS_REGION
]);
1461 wpa_printf(MSG_DEBUG
, "nl80211: Regulatory information - country=%s (%s)",
1462 (char *) nla_data(tb_msg
[NL80211_ATTR_REG_ALPHA2
]),
1463 dfs_domain_name(dfs_domain
));
1465 wpa_printf(MSG_DEBUG
, "nl80211: Regulatory information - country=%s",
1466 (char *) nla_data(tb_msg
[NL80211_ATTR_REG_ALPHA2
]));
1469 nla_for_each_nested(nl_rule
, tb_msg
[NL80211_ATTR_REG_RULES
], rem_rule
)
1471 u32 start
, end
, max_eirp
= 0, max_bw
= 0, flags
= 0;
1472 nla_parse(tb_rule
, NL80211_FREQUENCY_ATTR_MAX
,
1473 nla_data(nl_rule
), nla_len(nl_rule
), reg_policy
);
1474 if (tb_rule
[NL80211_ATTR_FREQ_RANGE_START
] == NULL
||
1475 tb_rule
[NL80211_ATTR_FREQ_RANGE_END
] == NULL
)
1477 start
= nla_get_u32(tb_rule
[NL80211_ATTR_FREQ_RANGE_START
]) / 1000;
1478 end
= nla_get_u32(tb_rule
[NL80211_ATTR_FREQ_RANGE_END
]) / 1000;
1479 if (tb_rule
[NL80211_ATTR_POWER_RULE_MAX_EIRP
])
1480 max_eirp
= nla_get_u32(tb_rule
[NL80211_ATTR_POWER_RULE_MAX_EIRP
]) / 100;
1481 if (tb_rule
[NL80211_ATTR_FREQ_RANGE_MAX_BW
])
1482 max_bw
= nla_get_u32(tb_rule
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]) / 1000;
1483 if (tb_rule
[NL80211_ATTR_REG_RULE_FLAGS
])
1484 flags
= nla_get_u32(tb_rule
[NL80211_ATTR_REG_RULE_FLAGS
]);
1486 wpa_printf(MSG_DEBUG
, "nl80211: %u-%u @ %u MHz %u mBm%s%s%s%s%s%s%s%s",
1487 start
, end
, max_bw
, max_eirp
,
1488 flags
& NL80211_RRF_NO_OFDM
? " (no OFDM)" : "",
1489 flags
& NL80211_RRF_NO_CCK
? " (no CCK)" : "",
1490 flags
& NL80211_RRF_NO_INDOOR
? " (no indoor)" : "",
1491 flags
& NL80211_RRF_NO_OUTDOOR
? " (no outdoor)" :
1493 flags
& NL80211_RRF_DFS
? " (DFS)" : "",
1494 flags
& NL80211_RRF_PTP_ONLY
? " (PTP only)" : "",
1495 flags
& NL80211_RRF_PTMP_ONLY
? " (PTMP only)" : "",
1496 flags
& NL80211_RRF_NO_IR
? " (no IR)" : "");
1498 nl80211_reg_rule_ht40(start
, end
, results
);
1499 if (tb_rule
[NL80211_ATTR_POWER_RULE_MAX_EIRP
])
1500 nl80211_reg_rule_max_eirp(start
, end
, max_eirp
,
1504 nla_for_each_nested(nl_rule
, tb_msg
[NL80211_ATTR_REG_RULES
], rem_rule
)
1506 nla_parse(tb_rule
, NL80211_FREQUENCY_ATTR_MAX
,
1507 nla_data(nl_rule
), nla_len(nl_rule
), reg_policy
);
1508 nl80211_reg_rule_sec(tb_rule
, results
);
1511 nla_for_each_nested(nl_rule
, tb_msg
[NL80211_ATTR_REG_RULES
], rem_rule
)
1513 nla_parse(tb_rule
, NL80211_FREQUENCY_ATTR_MAX
,
1514 nla_data(nl_rule
), nla_len(nl_rule
), reg_policy
);
1515 nl80211_reg_rule_vht(tb_rule
, results
);
1522 static int nl80211_set_regulatory_flags(struct wpa_driver_nl80211_data
*drv
,
1523 struct phy_info_arg
*results
)
1527 msg
= nlmsg_alloc();
1531 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_REG
);
1532 return send_and_recv_msgs(drv
, msg
, nl80211_get_reg
, results
);
1536 struct hostapd_hw_modes
*
1537 nl80211_get_hw_feature_data(void *priv
, u16
*num_modes
, u16
*flags
)
1540 struct i802_bss
*bss
= priv
;
1541 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
1544 struct phy_info_arg result
= {
1545 .num_modes
= num_modes
,
1553 feat
= get_nl80211_protocol_features(drv
);
1554 if (feat
& NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP
)
1555 nl_flags
= NLM_F_DUMP
;
1556 if (!(msg
= nl80211_cmd_msg(bss
, nl_flags
, NL80211_CMD_GET_WIPHY
)) ||
1557 nla_put_flag(msg
, NL80211_ATTR_SPLIT_WIPHY_DUMP
)) {
1562 if (send_and_recv_msgs(drv
, msg
, phy_info_handler
, &result
) == 0) {
1563 nl80211_set_regulatory_flags(drv
, &result
);
1564 return wpa_driver_nl80211_postprocess_modes(result
.modes
,