15b9c547cSRui Paulo /* 25b9c547cSRui Paulo * Driver interaction with Linux nl80211/cfg80211 - Capabilities 35b9c547cSRui Paulo * Copyright (c) 2002-2015, Jouni Malinen <j@w1.fi> 45b9c547cSRui Paulo * Copyright (c) 2007, Johannes Berg <johannes@sipsolutions.net> 55b9c547cSRui Paulo * Copyright (c) 2009-2010, Atheros Communications 65b9c547cSRui Paulo * 75b9c547cSRui Paulo * This software may be distributed under the terms of the BSD license. 85b9c547cSRui Paulo * See README for more details. 95b9c547cSRui Paulo */ 105b9c547cSRui Paulo 115b9c547cSRui Paulo #include "includes.h" 125b9c547cSRui Paulo #include <netlink/genl/genl.h> 135b9c547cSRui Paulo 145b9c547cSRui Paulo #include "utils/common.h" 155b9c547cSRui Paulo #include "common/ieee802_11_common.h" 1685732ac8SCy Schubert #include "common/wpa_common.h" 175b9c547cSRui Paulo #include "common/qca-vendor.h" 185b9c547cSRui Paulo #include "common/qca-vendor-attr.h" 195b9c547cSRui Paulo #include "driver_nl80211.h" 205b9c547cSRui Paulo 215b9c547cSRui Paulo 225b9c547cSRui Paulo static int protocol_feature_handler(struct nl_msg *msg, void *arg) 235b9c547cSRui Paulo { 245b9c547cSRui Paulo u32 *feat = arg; 255b9c547cSRui Paulo struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; 265b9c547cSRui Paulo struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); 275b9c547cSRui Paulo 285b9c547cSRui Paulo nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), 295b9c547cSRui Paulo genlmsg_attrlen(gnlh, 0), NULL); 305b9c547cSRui Paulo 315b9c547cSRui Paulo if (tb_msg[NL80211_ATTR_PROTOCOL_FEATURES]) 325b9c547cSRui Paulo *feat = nla_get_u32(tb_msg[NL80211_ATTR_PROTOCOL_FEATURES]); 335b9c547cSRui Paulo 345b9c547cSRui Paulo return NL_SKIP; 355b9c547cSRui Paulo } 365b9c547cSRui Paulo 375b9c547cSRui Paulo 385b9c547cSRui Paulo static u32 get_nl80211_protocol_features(struct wpa_driver_nl80211_data *drv) 395b9c547cSRui Paulo { 405b9c547cSRui Paulo u32 feat = 0; 415b9c547cSRui Paulo struct nl_msg *msg; 425b9c547cSRui Paulo 435b9c547cSRui Paulo msg = nlmsg_alloc(); 445b9c547cSRui Paulo if (!msg) 455b9c547cSRui Paulo return 0; 465b9c547cSRui Paulo 475b9c547cSRui Paulo if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_PROTOCOL_FEATURES)) { 485b9c547cSRui Paulo nlmsg_free(msg); 495b9c547cSRui Paulo return 0; 505b9c547cSRui Paulo } 515b9c547cSRui Paulo 525b9c547cSRui Paulo if (send_and_recv_msgs(drv, msg, protocol_feature_handler, &feat) == 0) 535b9c547cSRui Paulo return feat; 545b9c547cSRui Paulo 555b9c547cSRui Paulo return 0; 565b9c547cSRui Paulo } 575b9c547cSRui Paulo 585b9c547cSRui Paulo 595b9c547cSRui Paulo struct wiphy_info_data { 605b9c547cSRui Paulo struct wpa_driver_nl80211_data *drv; 615b9c547cSRui Paulo struct wpa_driver_capa *capa; 625b9c547cSRui Paulo 635b9c547cSRui Paulo unsigned int num_multichan_concurrent; 645b9c547cSRui Paulo 655b9c547cSRui Paulo unsigned int error:1; 665b9c547cSRui Paulo unsigned int device_ap_sme:1; 675b9c547cSRui Paulo unsigned int poll_command_supported:1; 685b9c547cSRui Paulo unsigned int data_tx_status:1; 695b9c547cSRui Paulo unsigned int auth_supported:1; 705b9c547cSRui Paulo unsigned int connect_supported:1; 715b9c547cSRui Paulo unsigned int p2p_go_supported:1; 725b9c547cSRui Paulo unsigned int p2p_client_supported:1; 735b9c547cSRui Paulo unsigned int p2p_go_ctwindow_supported:1; 745b9c547cSRui Paulo unsigned int p2p_concurrent:1; 755b9c547cSRui Paulo unsigned int channel_switch_supported:1; 765b9c547cSRui Paulo unsigned int set_qos_map_supported:1; 775b9c547cSRui Paulo unsigned int have_low_prio_scan:1; 785b9c547cSRui Paulo unsigned int wmm_ac_supported:1; 795b9c547cSRui Paulo unsigned int mac_addr_rand_scan_supported:1; 805b9c547cSRui Paulo unsigned int mac_addr_rand_sched_scan_supported:1; 815b9c547cSRui Paulo }; 825b9c547cSRui Paulo 835b9c547cSRui Paulo 845b9c547cSRui Paulo static unsigned int probe_resp_offload_support(int supp_protocols) 855b9c547cSRui Paulo { 865b9c547cSRui Paulo unsigned int prot = 0; 875b9c547cSRui Paulo 885b9c547cSRui Paulo if (supp_protocols & NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS) 895b9c547cSRui Paulo prot |= WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS; 905b9c547cSRui Paulo if (supp_protocols & NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2) 915b9c547cSRui Paulo prot |= WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2; 925b9c547cSRui Paulo if (supp_protocols & NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P) 935b9c547cSRui Paulo prot |= WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P; 945b9c547cSRui Paulo if (supp_protocols & NL80211_PROBE_RESP_OFFLOAD_SUPPORT_80211U) 955b9c547cSRui Paulo prot |= WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING; 965b9c547cSRui Paulo 975b9c547cSRui Paulo return prot; 985b9c547cSRui Paulo } 995b9c547cSRui Paulo 1005b9c547cSRui Paulo 1015b9c547cSRui Paulo static void wiphy_info_supported_iftypes(struct wiphy_info_data *info, 1025b9c547cSRui Paulo struct nlattr *tb) 1035b9c547cSRui Paulo { 1045b9c547cSRui Paulo struct nlattr *nl_mode; 1055b9c547cSRui Paulo int i; 1065b9c547cSRui Paulo 1075b9c547cSRui Paulo if (tb == NULL) 1085b9c547cSRui Paulo return; 1095b9c547cSRui Paulo 1105b9c547cSRui Paulo nla_for_each_nested(nl_mode, tb, i) { 1115b9c547cSRui Paulo switch (nla_type(nl_mode)) { 1125b9c547cSRui Paulo case NL80211_IFTYPE_AP: 1135b9c547cSRui Paulo info->capa->flags |= WPA_DRIVER_FLAGS_AP; 1145b9c547cSRui Paulo break; 1155b9c547cSRui Paulo case NL80211_IFTYPE_MESH_POINT: 1165b9c547cSRui Paulo info->capa->flags |= WPA_DRIVER_FLAGS_MESH; 1175b9c547cSRui Paulo break; 1185b9c547cSRui Paulo case NL80211_IFTYPE_ADHOC: 1195b9c547cSRui Paulo info->capa->flags |= WPA_DRIVER_FLAGS_IBSS; 1205b9c547cSRui Paulo break; 1215b9c547cSRui Paulo case NL80211_IFTYPE_P2P_DEVICE: 1225b9c547cSRui Paulo info->capa->flags |= 1235b9c547cSRui Paulo WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE; 1245b9c547cSRui Paulo break; 1255b9c547cSRui Paulo case NL80211_IFTYPE_P2P_GO: 1265b9c547cSRui Paulo info->p2p_go_supported = 1; 1275b9c547cSRui Paulo break; 1285b9c547cSRui Paulo case NL80211_IFTYPE_P2P_CLIENT: 1295b9c547cSRui Paulo info->p2p_client_supported = 1; 1305b9c547cSRui Paulo break; 1315b9c547cSRui Paulo } 1325b9c547cSRui Paulo } 1335b9c547cSRui Paulo } 1345b9c547cSRui Paulo 1355b9c547cSRui Paulo 1365b9c547cSRui Paulo static int wiphy_info_iface_comb_process(struct wiphy_info_data *info, 1375b9c547cSRui Paulo struct nlattr *nl_combi) 1385b9c547cSRui Paulo { 1395b9c547cSRui Paulo struct nlattr *tb_comb[NUM_NL80211_IFACE_COMB]; 1405b9c547cSRui Paulo struct nlattr *tb_limit[NUM_NL80211_IFACE_LIMIT]; 1415b9c547cSRui Paulo struct nlattr *nl_limit, *nl_mode; 1425b9c547cSRui Paulo int err, rem_limit, rem_mode; 1435b9c547cSRui Paulo int combination_has_p2p = 0, combination_has_mgd = 0; 1445b9c547cSRui Paulo static struct nla_policy 1455b9c547cSRui Paulo iface_combination_policy[NUM_NL80211_IFACE_COMB] = { 1465b9c547cSRui Paulo [NL80211_IFACE_COMB_LIMITS] = { .type = NLA_NESTED }, 1475b9c547cSRui Paulo [NL80211_IFACE_COMB_MAXNUM] = { .type = NLA_U32 }, 1485b9c547cSRui Paulo [NL80211_IFACE_COMB_STA_AP_BI_MATCH] = { .type = NLA_FLAG }, 1495b9c547cSRui Paulo [NL80211_IFACE_COMB_NUM_CHANNELS] = { .type = NLA_U32 }, 1505b9c547cSRui Paulo [NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS] = { .type = NLA_U32 }, 1515b9c547cSRui Paulo }, 1525b9c547cSRui Paulo iface_limit_policy[NUM_NL80211_IFACE_LIMIT] = { 1535b9c547cSRui Paulo [NL80211_IFACE_LIMIT_TYPES] = { .type = NLA_NESTED }, 1545b9c547cSRui Paulo [NL80211_IFACE_LIMIT_MAX] = { .type = NLA_U32 }, 1555b9c547cSRui Paulo }; 1565b9c547cSRui Paulo 1575b9c547cSRui Paulo err = nla_parse_nested(tb_comb, MAX_NL80211_IFACE_COMB, 1585b9c547cSRui Paulo nl_combi, iface_combination_policy); 1595b9c547cSRui Paulo if (err || !tb_comb[NL80211_IFACE_COMB_LIMITS] || 1605b9c547cSRui Paulo !tb_comb[NL80211_IFACE_COMB_MAXNUM] || 1615b9c547cSRui Paulo !tb_comb[NL80211_IFACE_COMB_NUM_CHANNELS]) 1625b9c547cSRui Paulo return 0; /* broken combination */ 1635b9c547cSRui Paulo 1645b9c547cSRui Paulo if (tb_comb[NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS]) 1655b9c547cSRui Paulo info->capa->flags |= WPA_DRIVER_FLAGS_RADAR; 1665b9c547cSRui Paulo 1675b9c547cSRui Paulo nla_for_each_nested(nl_limit, tb_comb[NL80211_IFACE_COMB_LIMITS], 1685b9c547cSRui Paulo rem_limit) { 1695b9c547cSRui Paulo err = nla_parse_nested(tb_limit, MAX_NL80211_IFACE_LIMIT, 1705b9c547cSRui Paulo nl_limit, iface_limit_policy); 1715b9c547cSRui Paulo if (err || !tb_limit[NL80211_IFACE_LIMIT_TYPES]) 1725b9c547cSRui Paulo return 0; /* broken combination */ 1735b9c547cSRui Paulo 1745b9c547cSRui Paulo nla_for_each_nested(nl_mode, 1755b9c547cSRui Paulo tb_limit[NL80211_IFACE_LIMIT_TYPES], 1765b9c547cSRui Paulo rem_mode) { 1775b9c547cSRui Paulo int ift = nla_type(nl_mode); 1785b9c547cSRui Paulo if (ift == NL80211_IFTYPE_P2P_GO || 1795b9c547cSRui Paulo ift == NL80211_IFTYPE_P2P_CLIENT) 1805b9c547cSRui Paulo combination_has_p2p = 1; 1815b9c547cSRui Paulo if (ift == NL80211_IFTYPE_STATION) 1825b9c547cSRui Paulo combination_has_mgd = 1; 1835b9c547cSRui Paulo } 1845b9c547cSRui Paulo if (combination_has_p2p && combination_has_mgd) 1855b9c547cSRui Paulo break; 1865b9c547cSRui Paulo } 1875b9c547cSRui Paulo 1885b9c547cSRui Paulo if (combination_has_p2p && combination_has_mgd) { 1895b9c547cSRui Paulo unsigned int num_channels = 1905b9c547cSRui Paulo nla_get_u32(tb_comb[NL80211_IFACE_COMB_NUM_CHANNELS]); 1915b9c547cSRui Paulo 1925b9c547cSRui Paulo info->p2p_concurrent = 1; 1935b9c547cSRui Paulo if (info->num_multichan_concurrent < num_channels) 1945b9c547cSRui Paulo info->num_multichan_concurrent = num_channels; 1955b9c547cSRui Paulo } 1965b9c547cSRui Paulo 1975b9c547cSRui Paulo return 0; 1985b9c547cSRui Paulo } 1995b9c547cSRui Paulo 2005b9c547cSRui Paulo 2015b9c547cSRui Paulo static void wiphy_info_iface_comb(struct wiphy_info_data *info, 2025b9c547cSRui Paulo struct nlattr *tb) 2035b9c547cSRui Paulo { 2045b9c547cSRui Paulo struct nlattr *nl_combi; 2055b9c547cSRui Paulo int rem_combi; 2065b9c547cSRui Paulo 2075b9c547cSRui Paulo if (tb == NULL) 2085b9c547cSRui Paulo return; 2095b9c547cSRui Paulo 2105b9c547cSRui Paulo nla_for_each_nested(nl_combi, tb, rem_combi) { 2115b9c547cSRui Paulo if (wiphy_info_iface_comb_process(info, nl_combi) > 0) 2125b9c547cSRui Paulo break; 2135b9c547cSRui Paulo } 2145b9c547cSRui Paulo } 2155b9c547cSRui Paulo 2165b9c547cSRui Paulo 2175b9c547cSRui Paulo static void wiphy_info_supp_cmds(struct wiphy_info_data *info, 2185b9c547cSRui Paulo struct nlattr *tb) 2195b9c547cSRui Paulo { 2205b9c547cSRui Paulo struct nlattr *nl_cmd; 2215b9c547cSRui Paulo int i; 2225b9c547cSRui Paulo 2235b9c547cSRui Paulo if (tb == NULL) 2245b9c547cSRui Paulo return; 2255b9c547cSRui Paulo 2265b9c547cSRui Paulo nla_for_each_nested(nl_cmd, tb, i) { 2275b9c547cSRui Paulo switch (nla_get_u32(nl_cmd)) { 2285b9c547cSRui Paulo case NL80211_CMD_AUTHENTICATE: 2295b9c547cSRui Paulo info->auth_supported = 1; 2305b9c547cSRui Paulo break; 2315b9c547cSRui Paulo case NL80211_CMD_CONNECT: 2325b9c547cSRui Paulo info->connect_supported = 1; 2335b9c547cSRui Paulo break; 2345b9c547cSRui Paulo case NL80211_CMD_START_SCHED_SCAN: 2355b9c547cSRui Paulo info->capa->sched_scan_supported = 1; 2365b9c547cSRui Paulo break; 2375b9c547cSRui Paulo case NL80211_CMD_PROBE_CLIENT: 2385b9c547cSRui Paulo info->poll_command_supported = 1; 2395b9c547cSRui Paulo break; 2405b9c547cSRui Paulo case NL80211_CMD_CHANNEL_SWITCH: 2415b9c547cSRui Paulo info->channel_switch_supported = 1; 2425b9c547cSRui Paulo break; 2435b9c547cSRui Paulo case NL80211_CMD_SET_QOS_MAP: 2445b9c547cSRui Paulo info->set_qos_map_supported = 1; 2455b9c547cSRui Paulo break; 2465b9c547cSRui Paulo } 2475b9c547cSRui Paulo } 2485b9c547cSRui Paulo } 2495b9c547cSRui Paulo 2505b9c547cSRui Paulo 2515b9c547cSRui Paulo static void wiphy_info_cipher_suites(struct wiphy_info_data *info, 2525b9c547cSRui Paulo struct nlattr *tb) 2535b9c547cSRui Paulo { 2545b9c547cSRui Paulo int i, num; 2555b9c547cSRui Paulo u32 *ciphers; 2565b9c547cSRui Paulo 2575b9c547cSRui Paulo if (tb == NULL) 2585b9c547cSRui Paulo return; 2595b9c547cSRui Paulo 2605b9c547cSRui Paulo num = nla_len(tb) / sizeof(u32); 2615b9c547cSRui Paulo ciphers = nla_data(tb); 2625b9c547cSRui Paulo for (i = 0; i < num; i++) { 2635b9c547cSRui Paulo u32 c = ciphers[i]; 2645b9c547cSRui Paulo 2655b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "nl80211: Supported cipher %02x-%02x-%02x:%d", 2665b9c547cSRui Paulo c >> 24, (c >> 16) & 0xff, 2675b9c547cSRui Paulo (c >> 8) & 0xff, c & 0xff); 2685b9c547cSRui Paulo switch (c) { 26985732ac8SCy Schubert case RSN_CIPHER_SUITE_CCMP_256: 2705b9c547cSRui Paulo info->capa->enc |= WPA_DRIVER_CAPA_ENC_CCMP_256; 2715b9c547cSRui Paulo break; 27285732ac8SCy Schubert case RSN_CIPHER_SUITE_GCMP_256: 2735b9c547cSRui Paulo info->capa->enc |= WPA_DRIVER_CAPA_ENC_GCMP_256; 2745b9c547cSRui Paulo break; 27585732ac8SCy Schubert case RSN_CIPHER_SUITE_CCMP: 2765b9c547cSRui Paulo info->capa->enc |= WPA_DRIVER_CAPA_ENC_CCMP; 2775b9c547cSRui Paulo break; 27885732ac8SCy Schubert case RSN_CIPHER_SUITE_GCMP: 2795b9c547cSRui Paulo info->capa->enc |= WPA_DRIVER_CAPA_ENC_GCMP; 2805b9c547cSRui Paulo break; 28185732ac8SCy Schubert case RSN_CIPHER_SUITE_TKIP: 2825b9c547cSRui Paulo info->capa->enc |= WPA_DRIVER_CAPA_ENC_TKIP; 2835b9c547cSRui Paulo break; 28485732ac8SCy Schubert case RSN_CIPHER_SUITE_WEP104: 2855b9c547cSRui Paulo info->capa->enc |= WPA_DRIVER_CAPA_ENC_WEP104; 2865b9c547cSRui Paulo break; 28785732ac8SCy Schubert case RSN_CIPHER_SUITE_WEP40: 2885b9c547cSRui Paulo info->capa->enc |= WPA_DRIVER_CAPA_ENC_WEP40; 2895b9c547cSRui Paulo break; 29085732ac8SCy Schubert case RSN_CIPHER_SUITE_AES_128_CMAC: 2915b9c547cSRui Paulo info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP; 2925b9c547cSRui Paulo break; 29385732ac8SCy Schubert case RSN_CIPHER_SUITE_BIP_GMAC_128: 2945b9c547cSRui Paulo info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP_GMAC_128; 2955b9c547cSRui Paulo break; 29685732ac8SCy Schubert case RSN_CIPHER_SUITE_BIP_GMAC_256: 2975b9c547cSRui Paulo info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP_GMAC_256; 2985b9c547cSRui Paulo break; 29985732ac8SCy Schubert case RSN_CIPHER_SUITE_BIP_CMAC_256: 3005b9c547cSRui Paulo info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP_CMAC_256; 3015b9c547cSRui Paulo break; 30285732ac8SCy Schubert case RSN_CIPHER_SUITE_NO_GROUP_ADDRESSED: 3035b9c547cSRui Paulo info->capa->enc |= WPA_DRIVER_CAPA_ENC_GTK_NOT_USED; 3045b9c547cSRui Paulo break; 3055b9c547cSRui Paulo } 3065b9c547cSRui Paulo } 3075b9c547cSRui Paulo } 3085b9c547cSRui Paulo 3095b9c547cSRui Paulo 3105b9c547cSRui Paulo static void wiphy_info_max_roc(struct wpa_driver_capa *capa, 3115b9c547cSRui Paulo struct nlattr *tb) 3125b9c547cSRui Paulo { 3135b9c547cSRui Paulo if (tb) 3145b9c547cSRui Paulo capa->max_remain_on_chan = nla_get_u32(tb); 3155b9c547cSRui Paulo } 3165b9c547cSRui Paulo 3175b9c547cSRui Paulo 3185b9c547cSRui Paulo static void wiphy_info_tdls(struct wpa_driver_capa *capa, struct nlattr *tdls, 3195b9c547cSRui Paulo struct nlattr *ext_setup) 3205b9c547cSRui Paulo { 3215b9c547cSRui Paulo if (tdls == NULL) 3225b9c547cSRui Paulo return; 3235b9c547cSRui Paulo 3245b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "nl80211: TDLS supported"); 3255b9c547cSRui Paulo capa->flags |= WPA_DRIVER_FLAGS_TDLS_SUPPORT; 3265b9c547cSRui Paulo 3275b9c547cSRui Paulo if (ext_setup) { 3285b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "nl80211: TDLS external setup"); 3295b9c547cSRui Paulo capa->flags |= WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP; 3305b9c547cSRui Paulo } 3315b9c547cSRui Paulo } 3325b9c547cSRui Paulo 3335b9c547cSRui Paulo 334325151a3SRui Paulo static int ext_feature_isset(const u8 *ext_features, int ext_features_len, 335325151a3SRui Paulo enum nl80211_ext_feature_index ftidx) 336325151a3SRui Paulo { 337325151a3SRui Paulo u8 ft_byte; 338325151a3SRui Paulo 339325151a3SRui Paulo if ((int) ftidx / 8 >= ext_features_len) 340325151a3SRui Paulo return 0; 341325151a3SRui Paulo 342325151a3SRui Paulo ft_byte = ext_features[ftidx / 8]; 343325151a3SRui Paulo return (ft_byte & BIT(ftidx % 8)) != 0; 344325151a3SRui Paulo } 345325151a3SRui Paulo 346325151a3SRui Paulo 347325151a3SRui Paulo static void wiphy_info_ext_feature_flags(struct wiphy_info_data *info, 348325151a3SRui Paulo struct nlattr *tb) 349325151a3SRui Paulo { 350325151a3SRui Paulo struct wpa_driver_capa *capa = info->capa; 351780fb4a2SCy Schubert u8 *ext_features; 352780fb4a2SCy Schubert int len; 353325151a3SRui Paulo 354325151a3SRui Paulo if (tb == NULL) 355325151a3SRui Paulo return; 356325151a3SRui Paulo 357780fb4a2SCy Schubert ext_features = nla_data(tb); 358780fb4a2SCy Schubert len = nla_len(tb); 359780fb4a2SCy Schubert 360780fb4a2SCy Schubert if (ext_feature_isset(ext_features, len, NL80211_EXT_FEATURE_VHT_IBSS)) 361325151a3SRui Paulo capa->flags |= WPA_DRIVER_FLAGS_VHT_IBSS; 362780fb4a2SCy Schubert 363780fb4a2SCy Schubert if (ext_feature_isset(ext_features, len, NL80211_EXT_FEATURE_RRM)) 364780fb4a2SCy Schubert capa->rrm_flags |= WPA_DRIVER_FLAGS_SUPPORT_RRM; 36585732ac8SCy Schubert 36685732ac8SCy Schubert if (ext_feature_isset(ext_features, len, NL80211_EXT_FEATURE_FILS_STA)) 36785732ac8SCy Schubert capa->flags |= WPA_DRIVER_FLAGS_SUPPORT_FILS; 36885732ac8SCy Schubert 36985732ac8SCy Schubert if (ext_feature_isset(ext_features, len, 37085732ac8SCy Schubert NL80211_EXT_FEATURE_BEACON_RATE_LEGACY)) 37185732ac8SCy Schubert capa->flags |= WPA_DRIVER_FLAGS_BEACON_RATE_LEGACY; 37285732ac8SCy Schubert 37385732ac8SCy Schubert if (ext_feature_isset(ext_features, len, 37485732ac8SCy Schubert NL80211_EXT_FEATURE_BEACON_RATE_HT)) 37585732ac8SCy Schubert capa->flags |= WPA_DRIVER_FLAGS_BEACON_RATE_HT; 37685732ac8SCy Schubert 37785732ac8SCy Schubert if (ext_feature_isset(ext_features, len, 37885732ac8SCy Schubert NL80211_EXT_FEATURE_BEACON_RATE_VHT)) 37985732ac8SCy Schubert capa->flags |= WPA_DRIVER_FLAGS_BEACON_RATE_VHT; 38085732ac8SCy Schubert 38185732ac8SCy Schubert if (ext_feature_isset(ext_features, len, 38285732ac8SCy Schubert NL80211_EXT_FEATURE_SET_SCAN_DWELL)) 38385732ac8SCy Schubert capa->rrm_flags |= WPA_DRIVER_FLAGS_SUPPORT_SET_SCAN_DWELL; 38485732ac8SCy Schubert 38585732ac8SCy Schubert if (ext_feature_isset(ext_features, len, 38685732ac8SCy Schubert NL80211_EXT_FEATURE_SCAN_START_TIME) && 38785732ac8SCy Schubert ext_feature_isset(ext_features, len, 38885732ac8SCy Schubert NL80211_EXT_FEATURE_BSS_PARENT_TSF) && 38985732ac8SCy Schubert ext_feature_isset(ext_features, len, 39085732ac8SCy Schubert NL80211_EXT_FEATURE_SET_SCAN_DWELL)) 39185732ac8SCy Schubert capa->rrm_flags |= WPA_DRIVER_FLAGS_SUPPORT_BEACON_REPORT; 39285732ac8SCy Schubert if (ext_feature_isset(ext_features, len, 39385732ac8SCy Schubert NL80211_EXT_FEATURE_MGMT_TX_RANDOM_TA)) 39485732ac8SCy Schubert capa->flags |= WPA_DRIVER_FLAGS_MGMT_TX_RANDOM_TA; 39585732ac8SCy Schubert if (ext_feature_isset(ext_features, len, 39685732ac8SCy Schubert NL80211_EXT_FEATURE_MGMT_TX_RANDOM_TA_CONNECTED)) 39785732ac8SCy Schubert capa->flags |= WPA_DRIVER_FLAGS_MGMT_TX_RANDOM_TA_CONNECTED; 39885732ac8SCy Schubert if (ext_feature_isset(ext_features, len, 39985732ac8SCy Schubert NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI)) 40085732ac8SCy Schubert capa->flags |= WPA_DRIVER_FLAGS_SCHED_SCAN_RELATIVE_RSSI; 40185732ac8SCy Schubert if (ext_feature_isset(ext_features, len, 40285732ac8SCy Schubert NL80211_EXT_FEATURE_FILS_SK_OFFLOAD)) 40385732ac8SCy Schubert capa->flags |= WPA_DRIVER_FLAGS_FILS_SK_OFFLOAD; 40485732ac8SCy Schubert 40585732ac8SCy Schubert if (ext_feature_isset(ext_features, len, 4064bc52338SCy Schubert NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK)) 4074bc52338SCy Schubert capa->flags |= WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK; 4084bc52338SCy Schubert if (ext_feature_isset(ext_features, len, 40985732ac8SCy Schubert NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) 4104bc52338SCy Schubert capa->flags |= WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X; 41185732ac8SCy Schubert 41285732ac8SCy Schubert if (ext_feature_isset(ext_features, len, 41385732ac8SCy Schubert NL80211_EXT_FEATURE_MFP_OPTIONAL)) 41485732ac8SCy Schubert capa->flags |= WPA_DRIVER_FLAGS_MFP_OPTIONAL; 41585732ac8SCy Schubert 41685732ac8SCy Schubert if (ext_feature_isset(ext_features, len, 41785732ac8SCy Schubert NL80211_EXT_FEATURE_DFS_OFFLOAD)) 41885732ac8SCy Schubert capa->flags |= WPA_DRIVER_FLAGS_DFS_OFFLOAD; 41985732ac8SCy Schubert 42085732ac8SCy Schubert #ifdef CONFIG_MBO 42185732ac8SCy Schubert if (ext_feature_isset(ext_features, len, 42285732ac8SCy Schubert NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME) && 42385732ac8SCy Schubert ext_feature_isset(ext_features, len, 42485732ac8SCy Schubert NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP) && 42585732ac8SCy Schubert ext_feature_isset(ext_features, len, 42685732ac8SCy Schubert NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE) && 42785732ac8SCy Schubert ext_feature_isset( 42885732ac8SCy Schubert ext_features, len, 42985732ac8SCy Schubert NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION)) 43085732ac8SCy Schubert capa->flags |= WPA_DRIVER_FLAGS_OCE_STA; 43185732ac8SCy Schubert #endif /* CONFIG_MBO */ 4324bc52338SCy Schubert 4334bc52338SCy Schubert if (ext_feature_isset(ext_features, len, 4344bc52338SCy Schubert NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER)) 4354bc52338SCy Schubert capa->flags |= WPA_DRIVER_FLAGS_FTM_RESPONDER; 436325151a3SRui Paulo } 437325151a3SRui Paulo 438325151a3SRui Paulo 4395b9c547cSRui Paulo static void wiphy_info_feature_flags(struct wiphy_info_data *info, 4405b9c547cSRui Paulo struct nlattr *tb) 4415b9c547cSRui Paulo { 4425b9c547cSRui Paulo u32 flags; 4435b9c547cSRui Paulo struct wpa_driver_capa *capa = info->capa; 4445b9c547cSRui Paulo 4455b9c547cSRui Paulo if (tb == NULL) 4465b9c547cSRui Paulo return; 4475b9c547cSRui Paulo 4485b9c547cSRui Paulo flags = nla_get_u32(tb); 4495b9c547cSRui Paulo 4505b9c547cSRui Paulo if (flags & NL80211_FEATURE_SK_TX_STATUS) 4515b9c547cSRui Paulo info->data_tx_status = 1; 4525b9c547cSRui Paulo 4535b9c547cSRui Paulo if (flags & NL80211_FEATURE_INACTIVITY_TIMER) 4545b9c547cSRui Paulo capa->flags |= WPA_DRIVER_FLAGS_INACTIVITY_TIMER; 4555b9c547cSRui Paulo 4565b9c547cSRui Paulo if (flags & NL80211_FEATURE_SAE) 4575b9c547cSRui Paulo capa->flags |= WPA_DRIVER_FLAGS_SAE; 4585b9c547cSRui Paulo 4595b9c547cSRui Paulo if (flags & NL80211_FEATURE_NEED_OBSS_SCAN) 4605b9c547cSRui Paulo capa->flags |= WPA_DRIVER_FLAGS_OBSS_SCAN; 4615b9c547cSRui Paulo 4625b9c547cSRui Paulo if (flags & NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE) 4635b9c547cSRui Paulo capa->flags |= WPA_DRIVER_FLAGS_HT_2040_COEX; 4645b9c547cSRui Paulo 4655b9c547cSRui Paulo if (flags & NL80211_FEATURE_TDLS_CHANNEL_SWITCH) { 4665b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "nl80211: TDLS channel switch"); 4675b9c547cSRui Paulo capa->flags |= WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH; 4685b9c547cSRui Paulo } 4695b9c547cSRui Paulo 4705b9c547cSRui Paulo if (flags & NL80211_FEATURE_P2P_GO_CTWIN) 4715b9c547cSRui Paulo info->p2p_go_ctwindow_supported = 1; 4725b9c547cSRui Paulo 4735b9c547cSRui Paulo if (flags & NL80211_FEATURE_LOW_PRIORITY_SCAN) 4745b9c547cSRui Paulo info->have_low_prio_scan = 1; 4755b9c547cSRui Paulo 4765b9c547cSRui Paulo if (flags & NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR) 4775b9c547cSRui Paulo info->mac_addr_rand_scan_supported = 1; 4785b9c547cSRui Paulo 4795b9c547cSRui Paulo if (flags & NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR) 4805b9c547cSRui Paulo info->mac_addr_rand_sched_scan_supported = 1; 4815b9c547cSRui Paulo 4825b9c547cSRui Paulo if (flags & NL80211_FEATURE_STATIC_SMPS) 4835b9c547cSRui Paulo capa->smps_modes |= WPA_DRIVER_SMPS_MODE_STATIC; 4845b9c547cSRui Paulo 4855b9c547cSRui Paulo if (flags & NL80211_FEATURE_DYNAMIC_SMPS) 4865b9c547cSRui Paulo capa->smps_modes |= WPA_DRIVER_SMPS_MODE_DYNAMIC; 4875b9c547cSRui Paulo 4885b9c547cSRui Paulo if (flags & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION) 4895b9c547cSRui Paulo info->wmm_ac_supported = 1; 4905b9c547cSRui Paulo 4915b9c547cSRui Paulo if (flags & NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) 4925b9c547cSRui Paulo capa->rrm_flags |= WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES; 4935b9c547cSRui Paulo 4945b9c547cSRui Paulo if (flags & NL80211_FEATURE_WFA_TPC_IE_IN_PROBES) 4955b9c547cSRui Paulo capa->rrm_flags |= WPA_DRIVER_FLAGS_WFA_TPC_IE_IN_PROBES; 4965b9c547cSRui Paulo 4975b9c547cSRui Paulo if (flags & NL80211_FEATURE_QUIET) 4985b9c547cSRui Paulo capa->rrm_flags |= WPA_DRIVER_FLAGS_QUIET; 4995b9c547cSRui Paulo 5005b9c547cSRui Paulo if (flags & NL80211_FEATURE_TX_POWER_INSERTION) 5015b9c547cSRui Paulo capa->rrm_flags |= WPA_DRIVER_FLAGS_TX_POWER_INSERTION; 5025b9c547cSRui Paulo 5035b9c547cSRui Paulo if (flags & NL80211_FEATURE_HT_IBSS) 5045b9c547cSRui Paulo capa->flags |= WPA_DRIVER_FLAGS_HT_IBSS; 505780fb4a2SCy Schubert 506780fb4a2SCy Schubert if (flags & NL80211_FEATURE_FULL_AP_CLIENT_STATE) 507780fb4a2SCy Schubert capa->flags |= WPA_DRIVER_FLAGS_FULL_AP_CLIENT_STATE; 5085b9c547cSRui Paulo } 5095b9c547cSRui Paulo 5105b9c547cSRui Paulo 5115b9c547cSRui Paulo static void wiphy_info_probe_resp_offload(struct wpa_driver_capa *capa, 5125b9c547cSRui Paulo struct nlattr *tb) 5135b9c547cSRui Paulo { 5145b9c547cSRui Paulo u32 protocols; 5155b9c547cSRui Paulo 5165b9c547cSRui Paulo if (tb == NULL) 5175b9c547cSRui Paulo return; 5185b9c547cSRui Paulo 5195b9c547cSRui Paulo protocols = nla_get_u32(tb); 5205b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "nl80211: Supports Probe Response offload in AP " 5215b9c547cSRui Paulo "mode"); 5225b9c547cSRui Paulo capa->flags |= WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD; 5235b9c547cSRui Paulo capa->probe_resp_offloads = probe_resp_offload_support(protocols); 5245b9c547cSRui Paulo } 5255b9c547cSRui Paulo 5265b9c547cSRui Paulo 5275b9c547cSRui Paulo static void wiphy_info_wowlan_triggers(struct wpa_driver_capa *capa, 5285b9c547cSRui Paulo struct nlattr *tb) 5295b9c547cSRui Paulo { 5305b9c547cSRui Paulo struct nlattr *triggers[MAX_NL80211_WOWLAN_TRIG + 1]; 5315b9c547cSRui Paulo 5325b9c547cSRui Paulo if (tb == NULL) 5335b9c547cSRui Paulo return; 5345b9c547cSRui Paulo 5355b9c547cSRui Paulo if (nla_parse_nested(triggers, MAX_NL80211_WOWLAN_TRIG, 5365b9c547cSRui Paulo tb, NULL)) 5375b9c547cSRui Paulo return; 5385b9c547cSRui Paulo 5395b9c547cSRui Paulo if (triggers[NL80211_WOWLAN_TRIG_ANY]) 5405b9c547cSRui Paulo capa->wowlan_triggers.any = 1; 5415b9c547cSRui Paulo if (triggers[NL80211_WOWLAN_TRIG_DISCONNECT]) 5425b9c547cSRui Paulo capa->wowlan_triggers.disconnect = 1; 5435b9c547cSRui Paulo if (triggers[NL80211_WOWLAN_TRIG_MAGIC_PKT]) 5445b9c547cSRui Paulo capa->wowlan_triggers.magic_pkt = 1; 5455b9c547cSRui Paulo if (triggers[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) 5465b9c547cSRui Paulo capa->wowlan_triggers.gtk_rekey_failure = 1; 5475b9c547cSRui Paulo if (triggers[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) 5485b9c547cSRui Paulo capa->wowlan_triggers.eap_identity_req = 1; 5495b9c547cSRui Paulo if (triggers[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) 5505b9c547cSRui Paulo capa->wowlan_triggers.four_way_handshake = 1; 5515b9c547cSRui Paulo if (triggers[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) 5525b9c547cSRui Paulo capa->wowlan_triggers.rfkill_release = 1; 5535b9c547cSRui Paulo } 5545b9c547cSRui Paulo 5555b9c547cSRui Paulo 556780fb4a2SCy Schubert static void wiphy_info_extended_capab(struct wpa_driver_nl80211_data *drv, 557780fb4a2SCy Schubert struct nlattr *tb) 558780fb4a2SCy Schubert { 559780fb4a2SCy Schubert int rem = 0, i; 560780fb4a2SCy Schubert struct nlattr *tb1[NL80211_ATTR_MAX + 1], *attr; 561780fb4a2SCy Schubert 562780fb4a2SCy Schubert if (!tb || drv->num_iface_ext_capa == NL80211_IFTYPE_MAX) 563780fb4a2SCy Schubert return; 564780fb4a2SCy Schubert 565780fb4a2SCy Schubert nla_for_each_nested(attr, tb, rem) { 566780fb4a2SCy Schubert unsigned int len; 567780fb4a2SCy Schubert struct drv_nl80211_ext_capa *capa; 568780fb4a2SCy Schubert 569780fb4a2SCy Schubert nla_parse(tb1, NL80211_ATTR_MAX, nla_data(attr), 570780fb4a2SCy Schubert nla_len(attr), NULL); 571780fb4a2SCy Schubert 572780fb4a2SCy Schubert if (!tb1[NL80211_ATTR_IFTYPE] || 573780fb4a2SCy Schubert !tb1[NL80211_ATTR_EXT_CAPA] || 574780fb4a2SCy Schubert !tb1[NL80211_ATTR_EXT_CAPA_MASK]) 575780fb4a2SCy Schubert continue; 576780fb4a2SCy Schubert 577780fb4a2SCy Schubert capa = &drv->iface_ext_capa[drv->num_iface_ext_capa]; 578780fb4a2SCy Schubert capa->iftype = nla_get_u32(tb1[NL80211_ATTR_IFTYPE]); 579780fb4a2SCy Schubert wpa_printf(MSG_DEBUG, 580780fb4a2SCy Schubert "nl80211: Driver-advertised extended capabilities for interface type %s", 581780fb4a2SCy Schubert nl80211_iftype_str(capa->iftype)); 582780fb4a2SCy Schubert 583780fb4a2SCy Schubert len = nla_len(tb1[NL80211_ATTR_EXT_CAPA]); 58485732ac8SCy Schubert capa->ext_capa = os_memdup(nla_data(tb1[NL80211_ATTR_EXT_CAPA]), 58585732ac8SCy Schubert len); 586780fb4a2SCy Schubert if (!capa->ext_capa) 587780fb4a2SCy Schubert goto err; 588780fb4a2SCy Schubert 589780fb4a2SCy Schubert capa->ext_capa_len = len; 590780fb4a2SCy Schubert wpa_hexdump(MSG_DEBUG, "nl80211: Extended capabilities", 591780fb4a2SCy Schubert capa->ext_capa, capa->ext_capa_len); 592780fb4a2SCy Schubert 593780fb4a2SCy Schubert len = nla_len(tb1[NL80211_ATTR_EXT_CAPA_MASK]); 59485732ac8SCy Schubert capa->ext_capa_mask = 59585732ac8SCy Schubert os_memdup(nla_data(tb1[NL80211_ATTR_EXT_CAPA_MASK]), 59685732ac8SCy Schubert len); 597780fb4a2SCy Schubert if (!capa->ext_capa_mask) 598780fb4a2SCy Schubert goto err; 599780fb4a2SCy Schubert 600780fb4a2SCy Schubert wpa_hexdump(MSG_DEBUG, "nl80211: Extended capabilities mask", 601780fb4a2SCy Schubert capa->ext_capa_mask, capa->ext_capa_len); 602780fb4a2SCy Schubert 603780fb4a2SCy Schubert drv->num_iface_ext_capa++; 604780fb4a2SCy Schubert if (drv->num_iface_ext_capa == NL80211_IFTYPE_MAX) 605780fb4a2SCy Schubert break; 606780fb4a2SCy Schubert } 607780fb4a2SCy Schubert 608780fb4a2SCy Schubert return; 609780fb4a2SCy Schubert 610780fb4a2SCy Schubert err: 611780fb4a2SCy Schubert /* Cleanup allocated memory on error */ 612780fb4a2SCy Schubert for (i = 0; i < NL80211_IFTYPE_MAX; i++) { 613780fb4a2SCy Schubert os_free(drv->iface_ext_capa[i].ext_capa); 614780fb4a2SCy Schubert drv->iface_ext_capa[i].ext_capa = NULL; 615780fb4a2SCy Schubert os_free(drv->iface_ext_capa[i].ext_capa_mask); 616780fb4a2SCy Schubert drv->iface_ext_capa[i].ext_capa_mask = NULL; 617780fb4a2SCy Schubert drv->iface_ext_capa[i].ext_capa_len = 0; 618780fb4a2SCy Schubert } 619780fb4a2SCy Schubert drv->num_iface_ext_capa = 0; 620780fb4a2SCy Schubert } 621780fb4a2SCy Schubert 622780fb4a2SCy Schubert 6235b9c547cSRui Paulo static int wiphy_info_handler(struct nl_msg *msg, void *arg) 6245b9c547cSRui Paulo { 6255b9c547cSRui Paulo struct nlattr *tb[NL80211_ATTR_MAX + 1]; 6265b9c547cSRui Paulo struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); 6275b9c547cSRui Paulo struct wiphy_info_data *info = arg; 6285b9c547cSRui Paulo struct wpa_driver_capa *capa = info->capa; 6295b9c547cSRui Paulo struct wpa_driver_nl80211_data *drv = info->drv; 6305b9c547cSRui Paulo 6315b9c547cSRui Paulo nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), 6325b9c547cSRui Paulo genlmsg_attrlen(gnlh, 0), NULL); 6335b9c547cSRui Paulo 634780fb4a2SCy Schubert if (tb[NL80211_ATTR_WIPHY]) 635780fb4a2SCy Schubert drv->wiphy_idx = nla_get_u32(tb[NL80211_ATTR_WIPHY]); 636780fb4a2SCy Schubert 6375b9c547cSRui Paulo if (tb[NL80211_ATTR_WIPHY_NAME]) 6385b9c547cSRui Paulo os_strlcpy(drv->phyname, 6395b9c547cSRui Paulo nla_get_string(tb[NL80211_ATTR_WIPHY_NAME]), 6405b9c547cSRui Paulo sizeof(drv->phyname)); 6415b9c547cSRui Paulo if (tb[NL80211_ATTR_MAX_NUM_SCAN_SSIDS]) 6425b9c547cSRui Paulo capa->max_scan_ssids = 6435b9c547cSRui Paulo nla_get_u8(tb[NL80211_ATTR_MAX_NUM_SCAN_SSIDS]); 6445b9c547cSRui Paulo 6455b9c547cSRui Paulo if (tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS]) 6465b9c547cSRui Paulo capa->max_sched_scan_ssids = 6475b9c547cSRui Paulo nla_get_u8(tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS]); 6485b9c547cSRui Paulo 649780fb4a2SCy Schubert if (tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS] && 650780fb4a2SCy Schubert tb[NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL] && 651780fb4a2SCy Schubert tb[NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS]) { 652780fb4a2SCy Schubert capa->max_sched_scan_plans = 653780fb4a2SCy Schubert nla_get_u32(tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS]); 654780fb4a2SCy Schubert 655780fb4a2SCy Schubert capa->max_sched_scan_plan_interval = 656780fb4a2SCy Schubert nla_get_u32(tb[NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL]); 657780fb4a2SCy Schubert 658780fb4a2SCy Schubert capa->max_sched_scan_plan_iterations = 659780fb4a2SCy Schubert nla_get_u32(tb[NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS]); 660780fb4a2SCy Schubert } 661780fb4a2SCy Schubert 6625b9c547cSRui Paulo if (tb[NL80211_ATTR_MAX_MATCH_SETS]) 6635b9c547cSRui Paulo capa->max_match_sets = 6645b9c547cSRui Paulo nla_get_u8(tb[NL80211_ATTR_MAX_MATCH_SETS]); 6655b9c547cSRui Paulo 6665b9c547cSRui Paulo if (tb[NL80211_ATTR_MAC_ACL_MAX]) 6675b9c547cSRui Paulo capa->max_acl_mac_addrs = 6685b9c547cSRui Paulo nla_get_u8(tb[NL80211_ATTR_MAC_ACL_MAX]); 6695b9c547cSRui Paulo 6705b9c547cSRui Paulo wiphy_info_supported_iftypes(info, tb[NL80211_ATTR_SUPPORTED_IFTYPES]); 6715b9c547cSRui Paulo wiphy_info_iface_comb(info, tb[NL80211_ATTR_INTERFACE_COMBINATIONS]); 6725b9c547cSRui Paulo wiphy_info_supp_cmds(info, tb[NL80211_ATTR_SUPPORTED_COMMANDS]); 6735b9c547cSRui Paulo wiphy_info_cipher_suites(info, tb[NL80211_ATTR_CIPHER_SUITES]); 6745b9c547cSRui Paulo 6755b9c547cSRui Paulo if (tb[NL80211_ATTR_OFFCHANNEL_TX_OK]) { 6765b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "nl80211: Using driver-based " 6775b9c547cSRui Paulo "off-channel TX"); 6785b9c547cSRui Paulo capa->flags |= WPA_DRIVER_FLAGS_OFFCHANNEL_TX; 6795b9c547cSRui Paulo } 6805b9c547cSRui Paulo 6815b9c547cSRui Paulo if (tb[NL80211_ATTR_ROAM_SUPPORT]) { 6825b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "nl80211: Using driver-based roaming"); 6835b9c547cSRui Paulo capa->flags |= WPA_DRIVER_FLAGS_BSS_SELECTION; 6845b9c547cSRui Paulo } 6855b9c547cSRui Paulo 6865b9c547cSRui Paulo wiphy_info_max_roc(capa, 6875b9c547cSRui Paulo tb[NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION]); 6885b9c547cSRui Paulo 6895b9c547cSRui Paulo if (tb[NL80211_ATTR_SUPPORT_AP_UAPSD]) 6905b9c547cSRui Paulo capa->flags |= WPA_DRIVER_FLAGS_AP_UAPSD; 6915b9c547cSRui Paulo 6925b9c547cSRui Paulo wiphy_info_tdls(capa, tb[NL80211_ATTR_TDLS_SUPPORT], 6935b9c547cSRui Paulo tb[NL80211_ATTR_TDLS_EXTERNAL_SETUP]); 6945b9c547cSRui Paulo 6955b9c547cSRui Paulo if (tb[NL80211_ATTR_DEVICE_AP_SME]) 6965b9c547cSRui Paulo info->device_ap_sme = 1; 6975b9c547cSRui Paulo 6985b9c547cSRui Paulo wiphy_info_feature_flags(info, tb[NL80211_ATTR_FEATURE_FLAGS]); 699325151a3SRui Paulo wiphy_info_ext_feature_flags(info, tb[NL80211_ATTR_EXT_FEATURES]); 7005b9c547cSRui Paulo wiphy_info_probe_resp_offload(capa, 7015b9c547cSRui Paulo tb[NL80211_ATTR_PROBE_RESP_OFFLOAD]); 7025b9c547cSRui Paulo 7035b9c547cSRui Paulo if (tb[NL80211_ATTR_EXT_CAPA] && tb[NL80211_ATTR_EXT_CAPA_MASK] && 7045b9c547cSRui Paulo drv->extended_capa == NULL) { 7055b9c547cSRui Paulo drv->extended_capa = 7065b9c547cSRui Paulo os_malloc(nla_len(tb[NL80211_ATTR_EXT_CAPA])); 7075b9c547cSRui Paulo if (drv->extended_capa) { 7085b9c547cSRui Paulo os_memcpy(drv->extended_capa, 7095b9c547cSRui Paulo nla_data(tb[NL80211_ATTR_EXT_CAPA]), 7105b9c547cSRui Paulo nla_len(tb[NL80211_ATTR_EXT_CAPA])); 7115b9c547cSRui Paulo drv->extended_capa_len = 7125b9c547cSRui Paulo nla_len(tb[NL80211_ATTR_EXT_CAPA]); 713780fb4a2SCy Schubert wpa_hexdump(MSG_DEBUG, 714780fb4a2SCy Schubert "nl80211: Driver-advertised extended capabilities (default)", 715780fb4a2SCy Schubert drv->extended_capa, drv->extended_capa_len); 7165b9c547cSRui Paulo } 7175b9c547cSRui Paulo drv->extended_capa_mask = 7185b9c547cSRui Paulo os_malloc(nla_len(tb[NL80211_ATTR_EXT_CAPA_MASK])); 7195b9c547cSRui Paulo if (drv->extended_capa_mask) { 7205b9c547cSRui Paulo os_memcpy(drv->extended_capa_mask, 7215b9c547cSRui Paulo nla_data(tb[NL80211_ATTR_EXT_CAPA_MASK]), 7225b9c547cSRui Paulo nla_len(tb[NL80211_ATTR_EXT_CAPA_MASK])); 723780fb4a2SCy Schubert wpa_hexdump(MSG_DEBUG, 724780fb4a2SCy Schubert "nl80211: Driver-advertised extended capabilities mask (default)", 725780fb4a2SCy Schubert drv->extended_capa_mask, 726780fb4a2SCy Schubert drv->extended_capa_len); 7275b9c547cSRui Paulo } else { 7285b9c547cSRui Paulo os_free(drv->extended_capa); 7295b9c547cSRui Paulo drv->extended_capa = NULL; 7305b9c547cSRui Paulo drv->extended_capa_len = 0; 7315b9c547cSRui Paulo } 7325b9c547cSRui Paulo } 7335b9c547cSRui Paulo 734780fb4a2SCy Schubert wiphy_info_extended_capab(drv, tb[NL80211_ATTR_IFTYPE_EXT_CAPA]); 735780fb4a2SCy Schubert 7365b9c547cSRui Paulo if (tb[NL80211_ATTR_VENDOR_DATA]) { 7375b9c547cSRui Paulo struct nlattr *nl; 7385b9c547cSRui Paulo int rem; 7395b9c547cSRui Paulo 7405b9c547cSRui Paulo nla_for_each_nested(nl, tb[NL80211_ATTR_VENDOR_DATA], rem) { 7415b9c547cSRui Paulo struct nl80211_vendor_cmd_info *vinfo; 7425b9c547cSRui Paulo if (nla_len(nl) != sizeof(*vinfo)) { 7435b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "nl80211: Unexpected vendor data info"); 7445b9c547cSRui Paulo continue; 7455b9c547cSRui Paulo } 7465b9c547cSRui Paulo vinfo = nla_data(nl); 747325151a3SRui Paulo if (vinfo->vendor_id == OUI_QCA) { 7485b9c547cSRui Paulo switch (vinfo->subcmd) { 7495b9c547cSRui Paulo case QCA_NL80211_VENDOR_SUBCMD_TEST: 7505b9c547cSRui Paulo drv->vendor_cmd_test_avail = 1; 7515b9c547cSRui Paulo break; 752780fb4a2SCy Schubert #ifdef CONFIG_DRIVER_NL80211_QCA 7535b9c547cSRui Paulo case QCA_NL80211_VENDOR_SUBCMD_ROAMING: 7545b9c547cSRui Paulo drv->roaming_vendor_cmd_avail = 1; 7555b9c547cSRui Paulo break; 7565b9c547cSRui Paulo case QCA_NL80211_VENDOR_SUBCMD_DFS_CAPABILITY: 7575b9c547cSRui Paulo drv->dfs_vendor_cmd_avail = 1; 7585b9c547cSRui Paulo break; 7595b9c547cSRui Paulo case QCA_NL80211_VENDOR_SUBCMD_GET_FEATURES: 7605b9c547cSRui Paulo drv->get_features_vendor_cmd_avail = 1; 7615b9c547cSRui Paulo break; 762325151a3SRui Paulo case QCA_NL80211_VENDOR_SUBCMD_GET_PREFERRED_FREQ_LIST: 763325151a3SRui Paulo drv->get_pref_freq_list = 1; 7645b9c547cSRui Paulo break; 765325151a3SRui Paulo case QCA_NL80211_VENDOR_SUBCMD_SET_PROBABLE_OPER_CHANNEL: 766325151a3SRui Paulo drv->set_prob_oper_freq = 1; 767325151a3SRui Paulo break; 768325151a3SRui Paulo case QCA_NL80211_VENDOR_SUBCMD_DO_ACS: 769325151a3SRui Paulo drv->capa.flags |= 770325151a3SRui Paulo WPA_DRIVER_FLAGS_ACS_OFFLOAD; 771325151a3SRui Paulo break; 772325151a3SRui Paulo case QCA_NL80211_VENDOR_SUBCMD_SETBAND: 773325151a3SRui Paulo drv->setband_vendor_cmd_avail = 1; 774325151a3SRui Paulo break; 775780fb4a2SCy Schubert case QCA_NL80211_VENDOR_SUBCMD_TRIGGER_SCAN: 776780fb4a2SCy Schubert drv->scan_vendor_cmd_avail = 1; 777780fb4a2SCy Schubert break; 778780fb4a2SCy Schubert case QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION: 779780fb4a2SCy Schubert drv->set_wifi_conf_vendor_cmd_avail = 1; 780780fb4a2SCy Schubert break; 78185732ac8SCy Schubert case QCA_NL80211_VENDOR_SUBCMD_FETCH_BSS_TRANSITION_STATUS: 78285732ac8SCy Schubert drv->fetch_bss_trans_status = 1; 78385732ac8SCy Schubert break; 78485732ac8SCy Schubert case QCA_NL80211_VENDOR_SUBCMD_ROAM: 78585732ac8SCy Schubert drv->roam_vendor_cmd_avail = 1; 78685732ac8SCy Schubert break; 7874bc52338SCy Schubert case QCA_NL80211_VENDOR_SUBCMD_GET_SUPPORTED_AKMS: 7884bc52338SCy Schubert drv->get_supported_akm_suites_avail = 1; 7894bc52338SCy Schubert break; 790780fb4a2SCy Schubert #endif /* CONFIG_DRIVER_NL80211_QCA */ 791325151a3SRui Paulo } 7925b9c547cSRui Paulo } 7935b9c547cSRui Paulo 7945b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "nl80211: Supported vendor command: vendor_id=0x%x subcmd=%u", 7955b9c547cSRui Paulo vinfo->vendor_id, vinfo->subcmd); 7965b9c547cSRui Paulo } 7975b9c547cSRui Paulo } 7985b9c547cSRui Paulo 7995b9c547cSRui Paulo if (tb[NL80211_ATTR_VENDOR_EVENTS]) { 8005b9c547cSRui Paulo struct nlattr *nl; 8015b9c547cSRui Paulo int rem; 8025b9c547cSRui Paulo 8035b9c547cSRui Paulo nla_for_each_nested(nl, tb[NL80211_ATTR_VENDOR_EVENTS], rem) { 8045b9c547cSRui Paulo struct nl80211_vendor_cmd_info *vinfo; 8055b9c547cSRui Paulo if (nla_len(nl) != sizeof(*vinfo)) { 8065b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "nl80211: Unexpected vendor data info"); 8075b9c547cSRui Paulo continue; 8085b9c547cSRui Paulo } 8095b9c547cSRui Paulo vinfo = nla_data(nl); 8105b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "nl80211: Supported vendor event: vendor_id=0x%x subcmd=%u", 8115b9c547cSRui Paulo vinfo->vendor_id, vinfo->subcmd); 8125b9c547cSRui Paulo } 8135b9c547cSRui Paulo } 8145b9c547cSRui Paulo 8155b9c547cSRui Paulo wiphy_info_wowlan_triggers(capa, 8165b9c547cSRui Paulo tb[NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED]); 8175b9c547cSRui Paulo 8185b9c547cSRui Paulo if (tb[NL80211_ATTR_MAX_AP_ASSOC_STA]) 8195b9c547cSRui Paulo capa->max_stations = 8205b9c547cSRui Paulo nla_get_u32(tb[NL80211_ATTR_MAX_AP_ASSOC_STA]); 8215b9c547cSRui Paulo 822780fb4a2SCy Schubert if (tb[NL80211_ATTR_MAX_CSA_COUNTERS]) 823780fb4a2SCy Schubert capa->max_csa_counters = 824780fb4a2SCy Schubert nla_get_u8(tb[NL80211_ATTR_MAX_CSA_COUNTERS]); 825780fb4a2SCy Schubert 82685732ac8SCy Schubert if (tb[NL80211_ATTR_WIPHY_SELF_MANAGED_REG]) 82785732ac8SCy Schubert capa->flags |= WPA_DRIVER_FLAGS_SELF_MANAGED_REGULATORY; 82885732ac8SCy Schubert 8295b9c547cSRui Paulo return NL_SKIP; 8305b9c547cSRui Paulo } 8315b9c547cSRui Paulo 8325b9c547cSRui Paulo 8335b9c547cSRui Paulo static int wpa_driver_nl80211_get_info(struct wpa_driver_nl80211_data *drv, 8345b9c547cSRui Paulo struct wiphy_info_data *info) 8355b9c547cSRui Paulo { 8365b9c547cSRui Paulo u32 feat; 8375b9c547cSRui Paulo struct nl_msg *msg; 8385b9c547cSRui Paulo int flags = 0; 8395b9c547cSRui Paulo 8405b9c547cSRui Paulo os_memset(info, 0, sizeof(*info)); 8415b9c547cSRui Paulo info->capa = &drv->capa; 8425b9c547cSRui Paulo info->drv = drv; 8435b9c547cSRui Paulo 8445b9c547cSRui Paulo feat = get_nl80211_protocol_features(drv); 8455b9c547cSRui Paulo if (feat & NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP) 8465b9c547cSRui Paulo flags = NLM_F_DUMP; 8475b9c547cSRui Paulo msg = nl80211_cmd_msg(drv->first_bss, flags, NL80211_CMD_GET_WIPHY); 8485b9c547cSRui Paulo if (!msg || nla_put_flag(msg, NL80211_ATTR_SPLIT_WIPHY_DUMP)) { 8495b9c547cSRui Paulo nlmsg_free(msg); 8505b9c547cSRui Paulo return -1; 8515b9c547cSRui Paulo } 8525b9c547cSRui Paulo 8535b9c547cSRui Paulo if (send_and_recv_msgs(drv, msg, wiphy_info_handler, info)) 8545b9c547cSRui Paulo return -1; 8555b9c547cSRui Paulo 8565b9c547cSRui Paulo if (info->auth_supported) 8575b9c547cSRui Paulo drv->capa.flags |= WPA_DRIVER_FLAGS_SME; 8585b9c547cSRui Paulo else if (!info->connect_supported) { 8595b9c547cSRui Paulo wpa_printf(MSG_INFO, "nl80211: Driver does not support " 8605b9c547cSRui Paulo "authentication/association or connect commands"); 8615b9c547cSRui Paulo info->error = 1; 8625b9c547cSRui Paulo } 8635b9c547cSRui Paulo 8645b9c547cSRui Paulo if (info->p2p_go_supported && info->p2p_client_supported) 8655b9c547cSRui Paulo drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CAPABLE; 8665b9c547cSRui Paulo if (info->p2p_concurrent) { 8675b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group " 8685b9c547cSRui Paulo "interface (driver advertised support)"); 8695b9c547cSRui Paulo drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT; 8705b9c547cSRui Paulo drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P; 8715b9c547cSRui Paulo } 8725b9c547cSRui Paulo if (info->num_multichan_concurrent > 1) { 8735b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "nl80211: Enable multi-channel " 8745b9c547cSRui Paulo "concurrent (driver advertised support)"); 8755b9c547cSRui Paulo drv->capa.num_multichan_concurrent = 8765b9c547cSRui Paulo info->num_multichan_concurrent; 8775b9c547cSRui Paulo } 8785b9c547cSRui Paulo if (drv->capa.flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) 8795b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "nl80211: use P2P_DEVICE support"); 8805b9c547cSRui Paulo 8815b9c547cSRui Paulo /* default to 5000 since early versions of mac80211 don't set it */ 8825b9c547cSRui Paulo if (!drv->capa.max_remain_on_chan) 8835b9c547cSRui Paulo drv->capa.max_remain_on_chan = 5000; 8845b9c547cSRui Paulo 8855b9c547cSRui Paulo drv->capa.wmm_ac_supported = info->wmm_ac_supported; 8865b9c547cSRui Paulo 8875b9c547cSRui Paulo drv->capa.mac_addr_rand_sched_scan_supported = 8885b9c547cSRui Paulo info->mac_addr_rand_sched_scan_supported; 8895b9c547cSRui Paulo drv->capa.mac_addr_rand_scan_supported = 8905b9c547cSRui Paulo info->mac_addr_rand_scan_supported; 8915b9c547cSRui Paulo 892780fb4a2SCy Schubert if (info->channel_switch_supported) { 893780fb4a2SCy Schubert drv->capa.flags |= WPA_DRIVER_FLAGS_AP_CSA; 894780fb4a2SCy Schubert if (!drv->capa.max_csa_counters) 895780fb4a2SCy Schubert drv->capa.max_csa_counters = 1; 896780fb4a2SCy Schubert } 897780fb4a2SCy Schubert 898780fb4a2SCy Schubert if (!drv->capa.max_sched_scan_plans) { 899780fb4a2SCy Schubert drv->capa.max_sched_scan_plans = 1; 900780fb4a2SCy Schubert drv->capa.max_sched_scan_plan_interval = UINT32_MAX; 901780fb4a2SCy Schubert drv->capa.max_sched_scan_plan_iterations = 0; 902780fb4a2SCy Schubert } 903780fb4a2SCy Schubert 9045b9c547cSRui Paulo return 0; 9055b9c547cSRui Paulo } 9065b9c547cSRui Paulo 9075b9c547cSRui Paulo 908780fb4a2SCy Schubert #ifdef CONFIG_DRIVER_NL80211_QCA 909780fb4a2SCy Schubert 9105b9c547cSRui Paulo static int dfs_info_handler(struct nl_msg *msg, void *arg) 9115b9c547cSRui Paulo { 9125b9c547cSRui Paulo struct nlattr *tb[NL80211_ATTR_MAX + 1]; 9135b9c547cSRui Paulo struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); 9145b9c547cSRui Paulo int *dfs_capability_ptr = arg; 9155b9c547cSRui Paulo 9165b9c547cSRui Paulo nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), 9175b9c547cSRui Paulo genlmsg_attrlen(gnlh, 0), NULL); 9185b9c547cSRui Paulo 9195b9c547cSRui Paulo if (tb[NL80211_ATTR_VENDOR_DATA]) { 9205b9c547cSRui Paulo struct nlattr *nl_vend = tb[NL80211_ATTR_VENDOR_DATA]; 9215b9c547cSRui Paulo struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1]; 9225b9c547cSRui Paulo 9235b9c547cSRui Paulo nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX, 9245b9c547cSRui Paulo nla_data(nl_vend), nla_len(nl_vend), NULL); 9255b9c547cSRui Paulo 9265b9c547cSRui Paulo if (tb_vendor[QCA_WLAN_VENDOR_ATTR_DFS]) { 9275b9c547cSRui Paulo u32 val; 9285b9c547cSRui Paulo val = nla_get_u32(tb_vendor[QCA_WLAN_VENDOR_ATTR_DFS]); 9295b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "nl80211: DFS offload capability: %u", 9305b9c547cSRui Paulo val); 9315b9c547cSRui Paulo *dfs_capability_ptr = val; 9325b9c547cSRui Paulo } 9335b9c547cSRui Paulo } 9345b9c547cSRui Paulo 9355b9c547cSRui Paulo return NL_SKIP; 9365b9c547cSRui Paulo } 9375b9c547cSRui Paulo 9385b9c547cSRui Paulo 9395b9c547cSRui Paulo static void qca_nl80211_check_dfs_capa(struct wpa_driver_nl80211_data *drv) 9405b9c547cSRui Paulo { 9415b9c547cSRui Paulo struct nl_msg *msg; 9425b9c547cSRui Paulo int dfs_capability = 0; 9435b9c547cSRui Paulo int ret; 9445b9c547cSRui Paulo 9455b9c547cSRui Paulo if (!drv->dfs_vendor_cmd_avail) 9465b9c547cSRui Paulo return; 9475b9c547cSRui Paulo 9485b9c547cSRui Paulo if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || 9495b9c547cSRui Paulo nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || 9505b9c547cSRui Paulo nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, 9515b9c547cSRui Paulo QCA_NL80211_VENDOR_SUBCMD_DFS_CAPABILITY)) { 9525b9c547cSRui Paulo nlmsg_free(msg); 9535b9c547cSRui Paulo return; 9545b9c547cSRui Paulo } 9555b9c547cSRui Paulo 9565b9c547cSRui Paulo ret = send_and_recv_msgs(drv, msg, dfs_info_handler, &dfs_capability); 9575b9c547cSRui Paulo if (!ret && dfs_capability) 9585b9c547cSRui Paulo drv->capa.flags |= WPA_DRIVER_FLAGS_DFS_OFFLOAD; 9595b9c547cSRui Paulo } 9605b9c547cSRui Paulo 9615b9c547cSRui Paulo 9624bc52338SCy Schubert static unsigned int get_akm_suites_info(struct nlattr *tb) 9634bc52338SCy Schubert { 9644bc52338SCy Schubert int i, num; 9654bc52338SCy Schubert unsigned int key_mgmt = 0; 9664bc52338SCy Schubert u32 *akms; 9674bc52338SCy Schubert 9684bc52338SCy Schubert if (!tb) 9694bc52338SCy Schubert return 0; 9704bc52338SCy Schubert 9714bc52338SCy Schubert num = nla_len(tb) / sizeof(u32); 9724bc52338SCy Schubert akms = nla_data(tb); 9734bc52338SCy Schubert for (i = 0; i < num; i++) { 9744bc52338SCy Schubert u32 a = akms[i]; 9754bc52338SCy Schubert 9764bc52338SCy Schubert wpa_printf(MSG_DEBUG, 9774bc52338SCy Schubert "nl80211: Supported AKM %02x-%02x-%02x:%u", 9784bc52338SCy Schubert a >> 24, (a >> 16) & 0xff, 9794bc52338SCy Schubert (a >> 8) & 0xff, a & 0xff); 9804bc52338SCy Schubert switch (a) { 9814bc52338SCy Schubert case RSN_AUTH_KEY_MGMT_UNSPEC_802_1X: 9824bc52338SCy Schubert key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_WPA | 9834bc52338SCy Schubert WPA_DRIVER_CAPA_KEY_MGMT_WPA2; 9844bc52338SCy Schubert break; 9854bc52338SCy Schubert case RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X: 9864bc52338SCy Schubert key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK | 9874bc52338SCy Schubert WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK; 9884bc52338SCy Schubert break; 9894bc52338SCy Schubert case RSN_AUTH_KEY_MGMT_FT_802_1X: 9904bc52338SCy Schubert key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT; 9914bc52338SCy Schubert break; 9924bc52338SCy Schubert case RSN_AUTH_KEY_MGMT_FT_PSK: 9934bc52338SCy Schubert key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK; 9944bc52338SCy Schubert break; 9954bc52338SCy Schubert case RSN_AUTH_KEY_MGMT_802_1X_SUITE_B: 9964bc52338SCy Schubert key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B; 9974bc52338SCy Schubert break; 9984bc52338SCy Schubert case RSN_AUTH_KEY_MGMT_802_1X_SUITE_B_192: 9994bc52338SCy Schubert key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192; 10004bc52338SCy Schubert break; 10014bc52338SCy Schubert case RSN_AUTH_KEY_MGMT_OWE: 10024bc52338SCy Schubert key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_OWE; 10034bc52338SCy Schubert break; 10044bc52338SCy Schubert case RSN_AUTH_KEY_MGMT_DPP: 10054bc52338SCy Schubert key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_DPP; 10064bc52338SCy Schubert break; 10074bc52338SCy Schubert case RSN_AUTH_KEY_MGMT_FILS_SHA256: 10084bc52338SCy Schubert key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA256; 10094bc52338SCy Schubert break; 10104bc52338SCy Schubert case RSN_AUTH_KEY_MGMT_FILS_SHA384: 10114bc52338SCy Schubert key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA384; 10124bc52338SCy Schubert break; 10134bc52338SCy Schubert case RSN_AUTH_KEY_MGMT_FT_FILS_SHA256: 10144bc52338SCy Schubert key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA256; 10154bc52338SCy Schubert break; 10164bc52338SCy Schubert case RSN_AUTH_KEY_MGMT_FT_FILS_SHA384: 10174bc52338SCy Schubert key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA384; 10184bc52338SCy Schubert break; 10194bc52338SCy Schubert case RSN_AUTH_KEY_MGMT_SAE: 10204bc52338SCy Schubert key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_SAE; 10214bc52338SCy Schubert break; 10224bc52338SCy Schubert } 10234bc52338SCy Schubert } 10244bc52338SCy Schubert 10254bc52338SCy Schubert return key_mgmt; 10264bc52338SCy Schubert } 10274bc52338SCy Schubert 10284bc52338SCy Schubert 10294bc52338SCy Schubert static int get_akm_suites_handler(struct nl_msg *msg, void *arg) 10304bc52338SCy Schubert { 10314bc52338SCy Schubert struct nlattr *tb[NL80211_ATTR_MAX + 1]; 10324bc52338SCy Schubert struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); 10334bc52338SCy Schubert unsigned int *key_mgmt = arg; 10344bc52338SCy Schubert 10354bc52338SCy Schubert nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), 10364bc52338SCy Schubert genlmsg_attrlen(gnlh, 0), NULL); 10374bc52338SCy Schubert 10384bc52338SCy Schubert if (tb[NL80211_ATTR_VENDOR_DATA]) { 10394bc52338SCy Schubert struct nlattr *nl_vend = tb[NL80211_ATTR_VENDOR_DATA]; 10404bc52338SCy Schubert struct nlattr *tb_data[NL80211_ATTR_MAX + 1]; 10414bc52338SCy Schubert 10424bc52338SCy Schubert nla_parse(tb_data, NL80211_ATTR_MAX, 10434bc52338SCy Schubert nla_data(nl_vend), nla_len(nl_vend), NULL); 10444bc52338SCy Schubert 10454bc52338SCy Schubert *key_mgmt = 10464bc52338SCy Schubert get_akm_suites_info(tb_data[NL80211_ATTR_AKM_SUITES]); 10474bc52338SCy Schubert } 10484bc52338SCy Schubert 10494bc52338SCy Schubert return NL_SKIP; 10504bc52338SCy Schubert } 10514bc52338SCy Schubert 10524bc52338SCy Schubert 10534bc52338SCy Schubert static int qca_nl80211_get_akm_suites(struct wpa_driver_nl80211_data *drv) 10544bc52338SCy Schubert { 10554bc52338SCy Schubert struct nl_msg *msg; 10564bc52338SCy Schubert unsigned int key_mgmt = 0; 10574bc52338SCy Schubert int ret; 10584bc52338SCy Schubert 10594bc52338SCy Schubert if (!drv->get_supported_akm_suites_avail) 10604bc52338SCy Schubert return -1; 10614bc52338SCy Schubert 10624bc52338SCy Schubert if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || 10634bc52338SCy Schubert nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || 10644bc52338SCy Schubert nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, 10654bc52338SCy Schubert QCA_NL80211_VENDOR_SUBCMD_GET_SUPPORTED_AKMS)) { 10664bc52338SCy Schubert nlmsg_free(msg); 10674bc52338SCy Schubert return -1; 10684bc52338SCy Schubert } 10694bc52338SCy Schubert 10704bc52338SCy Schubert ret = send_and_recv_msgs(drv, msg, get_akm_suites_handler, &key_mgmt); 10714bc52338SCy Schubert if (!ret) { 10724bc52338SCy Schubert wpa_printf(MSG_DEBUG, 10734bc52338SCy Schubert "nl80211: Replace capa.key_mgmt based on driver advertised capabilities: 0x%x", 10744bc52338SCy Schubert key_mgmt); 10754bc52338SCy Schubert drv->capa.key_mgmt = key_mgmt; 10764bc52338SCy Schubert } 10774bc52338SCy Schubert 10784bc52338SCy Schubert return ret; 10794bc52338SCy Schubert } 10804bc52338SCy Schubert 10814bc52338SCy Schubert 10825b9c547cSRui Paulo struct features_info { 10835b9c547cSRui Paulo u8 *flags; 10845b9c547cSRui Paulo size_t flags_len; 1085325151a3SRui Paulo struct wpa_driver_capa *capa; 10865b9c547cSRui Paulo }; 10875b9c547cSRui Paulo 10885b9c547cSRui Paulo 10895b9c547cSRui Paulo static int features_info_handler(struct nl_msg *msg, void *arg) 10905b9c547cSRui Paulo { 10915b9c547cSRui Paulo struct nlattr *tb[NL80211_ATTR_MAX + 1]; 10925b9c547cSRui Paulo struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); 10935b9c547cSRui Paulo struct features_info *info = arg; 10945b9c547cSRui Paulo struct nlattr *nl_vend, *attr; 10955b9c547cSRui Paulo 10965b9c547cSRui Paulo nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), 10975b9c547cSRui Paulo genlmsg_attrlen(gnlh, 0), NULL); 10985b9c547cSRui Paulo 10995b9c547cSRui Paulo nl_vend = tb[NL80211_ATTR_VENDOR_DATA]; 11005b9c547cSRui Paulo if (nl_vend) { 11015b9c547cSRui Paulo struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1]; 11025b9c547cSRui Paulo 11035b9c547cSRui Paulo nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX, 11045b9c547cSRui Paulo nla_data(nl_vend), nla_len(nl_vend), NULL); 11055b9c547cSRui Paulo 11065b9c547cSRui Paulo attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_FEATURE_FLAGS]; 11075b9c547cSRui Paulo if (attr) { 1108780fb4a2SCy Schubert int len = nla_len(attr); 1109780fb4a2SCy Schubert info->flags = os_malloc(len); 1110780fb4a2SCy Schubert if (info->flags != NULL) { 1111780fb4a2SCy Schubert os_memcpy(info->flags, nla_data(attr), len); 1112780fb4a2SCy Schubert info->flags_len = len; 1113780fb4a2SCy Schubert } 11145b9c547cSRui Paulo } 1115325151a3SRui Paulo attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_CONCURRENCY_CAPA]; 1116325151a3SRui Paulo if (attr) 1117325151a3SRui Paulo info->capa->conc_capab = nla_get_u32(attr); 1118325151a3SRui Paulo 1119325151a3SRui Paulo attr = tb_vendor[ 1120325151a3SRui Paulo QCA_WLAN_VENDOR_ATTR_MAX_CONCURRENT_CHANNELS_2_4_BAND]; 1121325151a3SRui Paulo if (attr) 1122325151a3SRui Paulo info->capa->max_conc_chan_2_4 = nla_get_u32(attr); 1123325151a3SRui Paulo 1124325151a3SRui Paulo attr = tb_vendor[ 1125325151a3SRui Paulo QCA_WLAN_VENDOR_ATTR_MAX_CONCURRENT_CHANNELS_5_0_BAND]; 1126325151a3SRui Paulo if (attr) 1127325151a3SRui Paulo info->capa->max_conc_chan_5_0 = nla_get_u32(attr); 11285b9c547cSRui Paulo } 11295b9c547cSRui Paulo 11305b9c547cSRui Paulo return NL_SKIP; 11315b9c547cSRui Paulo } 11325b9c547cSRui Paulo 11335b9c547cSRui Paulo 11345b9c547cSRui Paulo static int check_feature(enum qca_wlan_vendor_features feature, 11355b9c547cSRui Paulo struct features_info *info) 11365b9c547cSRui Paulo { 11375b9c547cSRui Paulo size_t idx = feature / 8; 11385b9c547cSRui Paulo 11395b9c547cSRui Paulo return (idx < info->flags_len) && 11405b9c547cSRui Paulo (info->flags[idx] & BIT(feature % 8)); 11415b9c547cSRui Paulo } 11425b9c547cSRui Paulo 11435b9c547cSRui Paulo 11445b9c547cSRui Paulo static void qca_nl80211_get_features(struct wpa_driver_nl80211_data *drv) 11455b9c547cSRui Paulo { 11465b9c547cSRui Paulo struct nl_msg *msg; 11475b9c547cSRui Paulo struct features_info info; 11485b9c547cSRui Paulo int ret; 11495b9c547cSRui Paulo 11505b9c547cSRui Paulo if (!drv->get_features_vendor_cmd_avail) 11515b9c547cSRui Paulo return; 11525b9c547cSRui Paulo 11535b9c547cSRui Paulo if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || 11545b9c547cSRui Paulo nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || 11555b9c547cSRui Paulo nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, 11565b9c547cSRui Paulo QCA_NL80211_VENDOR_SUBCMD_GET_FEATURES)) { 11575b9c547cSRui Paulo nlmsg_free(msg); 11585b9c547cSRui Paulo return; 11595b9c547cSRui Paulo } 11605b9c547cSRui Paulo 11615b9c547cSRui Paulo os_memset(&info, 0, sizeof(info)); 1162325151a3SRui Paulo info.capa = &drv->capa; 11635b9c547cSRui Paulo ret = send_and_recv_msgs(drv, msg, features_info_handler, &info); 11645b9c547cSRui Paulo if (ret || !info.flags) 11655b9c547cSRui Paulo return; 11665b9c547cSRui Paulo 11675b9c547cSRui Paulo if (check_feature(QCA_WLAN_VENDOR_FEATURE_KEY_MGMT_OFFLOAD, &info)) 11685b9c547cSRui Paulo drv->capa.flags |= WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD; 1169325151a3SRui Paulo 1170325151a3SRui Paulo if (check_feature(QCA_WLAN_VENDOR_FEATURE_SUPPORT_HW_MODE_ANY, &info)) 1171325151a3SRui Paulo drv->capa.flags |= WPA_DRIVER_FLAGS_SUPPORT_HW_MODE_ANY; 1172780fb4a2SCy Schubert 1173780fb4a2SCy Schubert if (check_feature(QCA_WLAN_VENDOR_FEATURE_OFFCHANNEL_SIMULTANEOUS, 1174780fb4a2SCy Schubert &info)) 1175780fb4a2SCy Schubert drv->capa.flags |= WPA_DRIVER_FLAGS_OFFCHANNEL_SIMULTANEOUS; 1176780fb4a2SCy Schubert if (check_feature(QCA_WLAN_VENDOR_FEATURE_P2P_LISTEN_OFFLOAD, &info)) 1177780fb4a2SCy Schubert drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD; 117885732ac8SCy Schubert if (check_feature(QCA_WLAN_VENDOR_FEATURE_OCE_STA, &info)) 117985732ac8SCy Schubert drv->capa.flags |= WPA_DRIVER_FLAGS_OCE_STA; 118085732ac8SCy Schubert if (check_feature(QCA_WLAN_VENDOR_FEATURE_OCE_AP, &info)) 118185732ac8SCy Schubert drv->capa.flags |= WPA_DRIVER_FLAGS_OCE_AP; 118285732ac8SCy Schubert if (check_feature(QCA_WLAN_VENDOR_FEATURE_OCE_STA_CFON, &info)) 118385732ac8SCy Schubert drv->capa.flags |= WPA_DRIVER_FLAGS_OCE_STA_CFON; 1184780fb4a2SCy Schubert os_free(info.flags); 11855b9c547cSRui Paulo } 11865b9c547cSRui Paulo 1187780fb4a2SCy Schubert #endif /* CONFIG_DRIVER_NL80211_QCA */ 1188780fb4a2SCy Schubert 11895b9c547cSRui Paulo 11905b9c547cSRui Paulo int wpa_driver_nl80211_capa(struct wpa_driver_nl80211_data *drv) 11915b9c547cSRui Paulo { 11925b9c547cSRui Paulo struct wiphy_info_data info; 11935b9c547cSRui Paulo if (wpa_driver_nl80211_get_info(drv, &info)) 11945b9c547cSRui Paulo return -1; 11955b9c547cSRui Paulo 11965b9c547cSRui Paulo if (info.error) 11975b9c547cSRui Paulo return -1; 11985b9c547cSRui Paulo 11995b9c547cSRui Paulo drv->has_capability = 1; 12005b9c547cSRui Paulo drv->capa.key_mgmt = WPA_DRIVER_CAPA_KEY_MGMT_WPA | 12015b9c547cSRui Paulo WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK | 12025b9c547cSRui Paulo WPA_DRIVER_CAPA_KEY_MGMT_WPA2 | 12035b9c547cSRui Paulo WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK | 12045b9c547cSRui Paulo WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B | 120585732ac8SCy Schubert WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192 | 120685732ac8SCy Schubert WPA_DRIVER_CAPA_KEY_MGMT_OWE | 120785732ac8SCy Schubert WPA_DRIVER_CAPA_KEY_MGMT_DPP; 120885732ac8SCy Schubert 120985732ac8SCy Schubert if (drv->capa.flags & WPA_DRIVER_FLAGS_SME) 121085732ac8SCy Schubert drv->capa.key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA256 | 121185732ac8SCy Schubert WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA384 | 121285732ac8SCy Schubert WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA256 | 12134bc52338SCy Schubert WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA384 | 12144bc52338SCy Schubert WPA_DRIVER_CAPA_KEY_MGMT_SAE; 121585732ac8SCy Schubert else if (drv->capa.flags & WPA_DRIVER_FLAGS_FILS_SK_OFFLOAD) 121685732ac8SCy Schubert drv->capa.key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA256 | 121785732ac8SCy Schubert WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA384; 121885732ac8SCy Schubert 12194bc52338SCy Schubert #ifdef CONFIG_DRIVER_NL80211_QCA 12204bc52338SCy Schubert /* Override drv->capa.key_mgmt based on driver advertised capability 12214bc52338SCy Schubert * constraints, if available. */ 12224bc52338SCy Schubert qca_nl80211_get_akm_suites(drv); 12234bc52338SCy Schubert #endif /* CONFIG_DRIVER_NL80211_QCA */ 12244bc52338SCy Schubert 12255b9c547cSRui Paulo drv->capa.auth = WPA_DRIVER_AUTH_OPEN | 12265b9c547cSRui Paulo WPA_DRIVER_AUTH_SHARED | 12275b9c547cSRui Paulo WPA_DRIVER_AUTH_LEAP; 12285b9c547cSRui Paulo 12295b9c547cSRui Paulo drv->capa.flags |= WPA_DRIVER_FLAGS_SANE_ERROR_CODES; 12305b9c547cSRui Paulo drv->capa.flags |= WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE; 12315b9c547cSRui Paulo drv->capa.flags |= WPA_DRIVER_FLAGS_EAPOL_TX_STATUS; 12325b9c547cSRui Paulo 12335b9c547cSRui Paulo /* 12345b9c547cSRui Paulo * As all cfg80211 drivers must support cases where the AP interface is 12355b9c547cSRui Paulo * removed without the knowledge of wpa_supplicant/hostapd, e.g., in 12365b9c547cSRui Paulo * case that the user space daemon has crashed, they must be able to 12375b9c547cSRui Paulo * cleanup all stations and key entries in the AP tear down flow. Thus, 12385b9c547cSRui Paulo * this flag can/should always be set for cfg80211 drivers. 12395b9c547cSRui Paulo */ 12405b9c547cSRui Paulo drv->capa.flags |= WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT; 12415b9c547cSRui Paulo 12425b9c547cSRui Paulo if (!info.device_ap_sme) { 12435b9c547cSRui Paulo drv->capa.flags |= WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS; 12445b9c547cSRui Paulo 12455b9c547cSRui Paulo /* 12465b9c547cSRui Paulo * No AP SME is currently assumed to also indicate no AP MLME 12475b9c547cSRui Paulo * in the driver/firmware. 12485b9c547cSRui Paulo */ 12495b9c547cSRui Paulo drv->capa.flags |= WPA_DRIVER_FLAGS_AP_MLME; 12505b9c547cSRui Paulo } 12515b9c547cSRui Paulo 12525b9c547cSRui Paulo drv->device_ap_sme = info.device_ap_sme; 12535b9c547cSRui Paulo drv->poll_command_supported = info.poll_command_supported; 12545b9c547cSRui Paulo drv->data_tx_status = info.data_tx_status; 12555b9c547cSRui Paulo drv->p2p_go_ctwindow_supported = info.p2p_go_ctwindow_supported; 12565b9c547cSRui Paulo if (info.set_qos_map_supported) 12575b9c547cSRui Paulo drv->capa.flags |= WPA_DRIVER_FLAGS_QOS_MAPPING; 12585b9c547cSRui Paulo drv->have_low_prio_scan = info.have_low_prio_scan; 12595b9c547cSRui Paulo 12605b9c547cSRui Paulo /* 12615b9c547cSRui Paulo * If poll command and tx status are supported, mac80211 is new enough 12625b9c547cSRui Paulo * to have everything we need to not need monitor interfaces. 12635b9c547cSRui Paulo */ 1264780fb4a2SCy Schubert drv->use_monitor = !info.device_ap_sme && 1265780fb4a2SCy Schubert (!info.poll_command_supported || !info.data_tx_status); 12665b9c547cSRui Paulo 12675b9c547cSRui Paulo /* 12685b9c547cSRui Paulo * If we aren't going to use monitor interfaces, but the 12695b9c547cSRui Paulo * driver doesn't support data TX status, we won't get TX 12705b9c547cSRui Paulo * status for EAPOL frames. 12715b9c547cSRui Paulo */ 12725b9c547cSRui Paulo if (!drv->use_monitor && !info.data_tx_status) 12735b9c547cSRui Paulo drv->capa.flags &= ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS; 12745b9c547cSRui Paulo 1275780fb4a2SCy Schubert #ifdef CONFIG_DRIVER_NL80211_QCA 127685732ac8SCy Schubert if (!(info.capa->flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD)) 12775b9c547cSRui Paulo qca_nl80211_check_dfs_capa(drv); 12785b9c547cSRui Paulo qca_nl80211_get_features(drv); 12795b9c547cSRui Paulo 1280780fb4a2SCy Schubert /* 1281780fb4a2SCy Schubert * To enable offchannel simultaneous support in wpa_supplicant, the 1282780fb4a2SCy Schubert * underlying driver needs to support the same along with offchannel TX. 1283780fb4a2SCy Schubert * Offchannel TX support is needed since remain_on_channel and 1284780fb4a2SCy Schubert * action_tx use some common data structures and hence cannot be 1285780fb4a2SCy Schubert * scheduled simultaneously. 1286780fb4a2SCy Schubert */ 1287780fb4a2SCy Schubert if (!(drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX)) 1288780fb4a2SCy Schubert drv->capa.flags &= ~WPA_DRIVER_FLAGS_OFFCHANNEL_SIMULTANEOUS; 1289780fb4a2SCy Schubert #endif /* CONFIG_DRIVER_NL80211_QCA */ 1290780fb4a2SCy Schubert 12915b9c547cSRui Paulo return 0; 12925b9c547cSRui Paulo } 12935b9c547cSRui Paulo 12945b9c547cSRui Paulo 12955b9c547cSRui Paulo struct phy_info_arg { 12965b9c547cSRui Paulo u16 *num_modes; 12975b9c547cSRui Paulo struct hostapd_hw_modes *modes; 12985b9c547cSRui Paulo int last_mode, last_chan_idx; 1299780fb4a2SCy Schubert int failed; 130085732ac8SCy Schubert u8 dfs_domain; 13015b9c547cSRui Paulo }; 13025b9c547cSRui Paulo 13035b9c547cSRui Paulo static void phy_info_ht_capa(struct hostapd_hw_modes *mode, struct nlattr *capa, 13045b9c547cSRui Paulo struct nlattr *ampdu_factor, 13055b9c547cSRui Paulo struct nlattr *ampdu_density, 13065b9c547cSRui Paulo struct nlattr *mcs_set) 13075b9c547cSRui Paulo { 13085b9c547cSRui Paulo if (capa) 13095b9c547cSRui Paulo mode->ht_capab = nla_get_u16(capa); 13105b9c547cSRui Paulo 13115b9c547cSRui Paulo if (ampdu_factor) 13125b9c547cSRui Paulo mode->a_mpdu_params |= nla_get_u8(ampdu_factor) & 0x03; 13135b9c547cSRui Paulo 13145b9c547cSRui Paulo if (ampdu_density) 13155b9c547cSRui Paulo mode->a_mpdu_params |= nla_get_u8(ampdu_density) << 2; 13165b9c547cSRui Paulo 13175b9c547cSRui Paulo if (mcs_set && nla_len(mcs_set) >= 16) { 13185b9c547cSRui Paulo u8 *mcs; 13195b9c547cSRui Paulo mcs = nla_data(mcs_set); 13205b9c547cSRui Paulo os_memcpy(mode->mcs_set, mcs, 16); 13215b9c547cSRui Paulo } 13225b9c547cSRui Paulo } 13235b9c547cSRui Paulo 13245b9c547cSRui Paulo 13255b9c547cSRui Paulo static void phy_info_vht_capa(struct hostapd_hw_modes *mode, 13265b9c547cSRui Paulo struct nlattr *capa, 13275b9c547cSRui Paulo struct nlattr *mcs_set) 13285b9c547cSRui Paulo { 13295b9c547cSRui Paulo if (capa) 13305b9c547cSRui Paulo mode->vht_capab = nla_get_u32(capa); 13315b9c547cSRui Paulo 13325b9c547cSRui Paulo if (mcs_set && nla_len(mcs_set) >= 8) { 13335b9c547cSRui Paulo u8 *mcs; 13345b9c547cSRui Paulo mcs = nla_data(mcs_set); 13355b9c547cSRui Paulo os_memcpy(mode->vht_mcs_set, mcs, 8); 13365b9c547cSRui Paulo } 13375b9c547cSRui Paulo } 13385b9c547cSRui Paulo 13395b9c547cSRui Paulo 13405b9c547cSRui Paulo static void phy_info_freq(struct hostapd_hw_modes *mode, 13415b9c547cSRui Paulo struct hostapd_channel_data *chan, 13425b9c547cSRui Paulo struct nlattr *tb_freq[]) 13435b9c547cSRui Paulo { 13445b9c547cSRui Paulo u8 channel; 13455b9c547cSRui Paulo chan->freq = nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_FREQ]); 13465b9c547cSRui Paulo chan->flag = 0; 13474bc52338SCy Schubert chan->allowed_bw = ~0; 13485b9c547cSRui Paulo chan->dfs_cac_ms = 0; 13495b9c547cSRui Paulo if (ieee80211_freq_to_chan(chan->freq, &channel) != NUM_HOSTAPD_MODES) 13505b9c547cSRui Paulo chan->chan = channel; 13515b9c547cSRui Paulo 13525b9c547cSRui Paulo if (tb_freq[NL80211_FREQUENCY_ATTR_DISABLED]) 13535b9c547cSRui Paulo chan->flag |= HOSTAPD_CHAN_DISABLED; 13545b9c547cSRui Paulo if (tb_freq[NL80211_FREQUENCY_ATTR_NO_IR]) 13555b9c547cSRui Paulo chan->flag |= HOSTAPD_CHAN_NO_IR; 13565b9c547cSRui Paulo if (tb_freq[NL80211_FREQUENCY_ATTR_RADAR]) 13575b9c547cSRui Paulo chan->flag |= HOSTAPD_CHAN_RADAR; 13585b9c547cSRui Paulo if (tb_freq[NL80211_FREQUENCY_ATTR_INDOOR_ONLY]) 13595b9c547cSRui Paulo chan->flag |= HOSTAPD_CHAN_INDOOR_ONLY; 13605b9c547cSRui Paulo if (tb_freq[NL80211_FREQUENCY_ATTR_GO_CONCURRENT]) 13615b9c547cSRui Paulo chan->flag |= HOSTAPD_CHAN_GO_CONCURRENT; 13625b9c547cSRui Paulo 13634bc52338SCy Schubert if (tb_freq[NL80211_FREQUENCY_ATTR_NO_10MHZ]) 13644bc52338SCy Schubert chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_10; 13654bc52338SCy Schubert if (tb_freq[NL80211_FREQUENCY_ATTR_NO_20MHZ]) 13664bc52338SCy Schubert chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_20; 13674bc52338SCy Schubert if (tb_freq[NL80211_FREQUENCY_ATTR_NO_HT40_PLUS]) 13684bc52338SCy Schubert chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_40P; 13694bc52338SCy Schubert if (tb_freq[NL80211_FREQUENCY_ATTR_NO_HT40_MINUS]) 13704bc52338SCy Schubert chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_40M; 13714bc52338SCy Schubert if (tb_freq[NL80211_FREQUENCY_ATTR_NO_80MHZ]) 13724bc52338SCy Schubert chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_80; 13734bc52338SCy Schubert if (tb_freq[NL80211_FREQUENCY_ATTR_NO_160MHZ]) 13744bc52338SCy Schubert chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_160; 13754bc52338SCy Schubert 13765b9c547cSRui Paulo if (tb_freq[NL80211_FREQUENCY_ATTR_DFS_STATE]) { 13775b9c547cSRui Paulo enum nl80211_dfs_state state = 13785b9c547cSRui Paulo nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_DFS_STATE]); 13795b9c547cSRui Paulo 13805b9c547cSRui Paulo switch (state) { 13815b9c547cSRui Paulo case NL80211_DFS_USABLE: 13825b9c547cSRui Paulo chan->flag |= HOSTAPD_CHAN_DFS_USABLE; 13835b9c547cSRui Paulo break; 13845b9c547cSRui Paulo case NL80211_DFS_AVAILABLE: 13855b9c547cSRui Paulo chan->flag |= HOSTAPD_CHAN_DFS_AVAILABLE; 13865b9c547cSRui Paulo break; 13875b9c547cSRui Paulo case NL80211_DFS_UNAVAILABLE: 13885b9c547cSRui Paulo chan->flag |= HOSTAPD_CHAN_DFS_UNAVAILABLE; 13895b9c547cSRui Paulo break; 13905b9c547cSRui Paulo } 13915b9c547cSRui Paulo } 13925b9c547cSRui Paulo 13935b9c547cSRui Paulo if (tb_freq[NL80211_FREQUENCY_ATTR_DFS_CAC_TIME]) { 13945b9c547cSRui Paulo chan->dfs_cac_ms = nla_get_u32( 13955b9c547cSRui Paulo tb_freq[NL80211_FREQUENCY_ATTR_DFS_CAC_TIME]); 13965b9c547cSRui Paulo } 1397*206b73d0SCy Schubert 1398*206b73d0SCy Schubert chan->wmm_rules_valid = 0; 1399*206b73d0SCy Schubert if (tb_freq[NL80211_FREQUENCY_ATTR_WMM]) { 1400*206b73d0SCy Schubert static struct nla_policy wmm_policy[NL80211_WMMR_MAX + 1] = { 1401*206b73d0SCy Schubert [NL80211_WMMR_CW_MIN] = { .type = NLA_U16 }, 1402*206b73d0SCy Schubert [NL80211_WMMR_CW_MAX] = { .type = NLA_U16 }, 1403*206b73d0SCy Schubert [NL80211_WMMR_AIFSN] = { .type = NLA_U8 }, 1404*206b73d0SCy Schubert [NL80211_WMMR_TXOP] = { .type = NLA_U16 }, 1405*206b73d0SCy Schubert }; 1406*206b73d0SCy Schubert struct nlattr *nl_wmm; 1407*206b73d0SCy Schubert struct nlattr *tb_wmm[NL80211_WMMR_MAX + 1]; 1408*206b73d0SCy Schubert int rem_wmm, ac, count = 0; 1409*206b73d0SCy Schubert 1410*206b73d0SCy Schubert nla_for_each_nested(nl_wmm, tb_freq[NL80211_FREQUENCY_ATTR_WMM], 1411*206b73d0SCy Schubert rem_wmm) { 1412*206b73d0SCy Schubert if (nla_parse_nested(tb_wmm, NL80211_WMMR_MAX, nl_wmm, 1413*206b73d0SCy Schubert wmm_policy)) { 1414*206b73d0SCy Schubert wpa_printf(MSG_DEBUG, 1415*206b73d0SCy Schubert "nl80211: Failed to parse WMM rules attribute"); 1416*206b73d0SCy Schubert return; 1417*206b73d0SCy Schubert } 1418*206b73d0SCy Schubert if (!tb_wmm[NL80211_WMMR_CW_MIN] || 1419*206b73d0SCy Schubert !tb_wmm[NL80211_WMMR_CW_MAX] || 1420*206b73d0SCy Schubert !tb_wmm[NL80211_WMMR_AIFSN] || 1421*206b73d0SCy Schubert !tb_wmm[NL80211_WMMR_TXOP]) { 1422*206b73d0SCy Schubert wpa_printf(MSG_DEBUG, 1423*206b73d0SCy Schubert "nl80211: Channel is missing WMM rule attribute"); 1424*206b73d0SCy Schubert return; 1425*206b73d0SCy Schubert } 1426*206b73d0SCy Schubert ac = nl_wmm->nla_type; 1427*206b73d0SCy Schubert if (ac < 0 || ac >= WMM_AC_NUM) { 1428*206b73d0SCy Schubert wpa_printf(MSG_DEBUG, 1429*206b73d0SCy Schubert "nl80211: Invalid AC value %d", ac); 1430*206b73d0SCy Schubert return; 1431*206b73d0SCy Schubert } 1432*206b73d0SCy Schubert 1433*206b73d0SCy Schubert chan->wmm_rules[ac].min_cwmin = 1434*206b73d0SCy Schubert nla_get_u16(tb_wmm[NL80211_WMMR_CW_MIN]); 1435*206b73d0SCy Schubert chan->wmm_rules[ac].min_cwmax = 1436*206b73d0SCy Schubert nla_get_u16(tb_wmm[NL80211_WMMR_CW_MAX]); 1437*206b73d0SCy Schubert chan->wmm_rules[ac].min_aifs = 1438*206b73d0SCy Schubert nla_get_u8(tb_wmm[NL80211_WMMR_AIFSN]); 1439*206b73d0SCy Schubert chan->wmm_rules[ac].max_txop = 1440*206b73d0SCy Schubert nla_get_u16(tb_wmm[NL80211_WMMR_TXOP]) / 32; 1441*206b73d0SCy Schubert count++; 1442*206b73d0SCy Schubert } 1443*206b73d0SCy Schubert 1444*206b73d0SCy Schubert /* Set valid flag if all the AC rules are present */ 1445*206b73d0SCy Schubert if (count == WMM_AC_NUM) 1446*206b73d0SCy Schubert chan->wmm_rules_valid = 1; 1447*206b73d0SCy Schubert } 14485b9c547cSRui Paulo } 14495b9c547cSRui Paulo 14505b9c547cSRui Paulo 14515b9c547cSRui Paulo static int phy_info_freqs(struct phy_info_arg *phy_info, 14525b9c547cSRui Paulo struct hostapd_hw_modes *mode, struct nlattr *tb) 14535b9c547cSRui Paulo { 14545b9c547cSRui Paulo static struct nla_policy freq_policy[NL80211_FREQUENCY_ATTR_MAX + 1] = { 14555b9c547cSRui Paulo [NL80211_FREQUENCY_ATTR_FREQ] = { .type = NLA_U32 }, 14565b9c547cSRui Paulo [NL80211_FREQUENCY_ATTR_DISABLED] = { .type = NLA_FLAG }, 14575b9c547cSRui Paulo [NL80211_FREQUENCY_ATTR_NO_IR] = { .type = NLA_FLAG }, 14585b9c547cSRui Paulo [NL80211_FREQUENCY_ATTR_RADAR] = { .type = NLA_FLAG }, 14595b9c547cSRui Paulo [NL80211_FREQUENCY_ATTR_MAX_TX_POWER] = { .type = NLA_U32 }, 14605b9c547cSRui Paulo [NL80211_FREQUENCY_ATTR_DFS_STATE] = { .type = NLA_U32 }, 14614bc52338SCy Schubert [NL80211_FREQUENCY_ATTR_NO_10MHZ] = { .type = NLA_FLAG }, 14624bc52338SCy Schubert [NL80211_FREQUENCY_ATTR_NO_20MHZ] = { .type = NLA_FLAG }, 14634bc52338SCy Schubert [NL80211_FREQUENCY_ATTR_NO_HT40_PLUS] = { .type = NLA_FLAG }, 14644bc52338SCy Schubert [NL80211_FREQUENCY_ATTR_NO_HT40_MINUS] = { .type = NLA_FLAG }, 14654bc52338SCy Schubert [NL80211_FREQUENCY_ATTR_NO_80MHZ] = { .type = NLA_FLAG }, 14664bc52338SCy Schubert [NL80211_FREQUENCY_ATTR_NO_160MHZ] = { .type = NLA_FLAG }, 14675b9c547cSRui Paulo }; 14685b9c547cSRui Paulo int new_channels = 0; 14695b9c547cSRui Paulo struct hostapd_channel_data *channel; 14705b9c547cSRui Paulo struct nlattr *tb_freq[NL80211_FREQUENCY_ATTR_MAX + 1]; 14715b9c547cSRui Paulo struct nlattr *nl_freq; 14725b9c547cSRui Paulo int rem_freq, idx; 14735b9c547cSRui Paulo 14745b9c547cSRui Paulo if (tb == NULL) 14755b9c547cSRui Paulo return NL_OK; 14765b9c547cSRui Paulo 14775b9c547cSRui Paulo nla_for_each_nested(nl_freq, tb, rem_freq) { 14785b9c547cSRui Paulo nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX, 14795b9c547cSRui Paulo nla_data(nl_freq), nla_len(nl_freq), freq_policy); 14805b9c547cSRui Paulo if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ]) 14815b9c547cSRui Paulo continue; 14825b9c547cSRui Paulo new_channels++; 14835b9c547cSRui Paulo } 14845b9c547cSRui Paulo 14855b9c547cSRui Paulo channel = os_realloc_array(mode->channels, 14865b9c547cSRui Paulo mode->num_channels + new_channels, 14875b9c547cSRui Paulo sizeof(struct hostapd_channel_data)); 14885b9c547cSRui Paulo if (!channel) 1489780fb4a2SCy Schubert return NL_STOP; 14905b9c547cSRui Paulo 14915b9c547cSRui Paulo mode->channels = channel; 14925b9c547cSRui Paulo mode->num_channels += new_channels; 14935b9c547cSRui Paulo 14945b9c547cSRui Paulo idx = phy_info->last_chan_idx; 14955b9c547cSRui Paulo 14965b9c547cSRui Paulo nla_for_each_nested(nl_freq, tb, rem_freq) { 14975b9c547cSRui Paulo nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX, 14985b9c547cSRui Paulo nla_data(nl_freq), nla_len(nl_freq), freq_policy); 14995b9c547cSRui Paulo if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ]) 15005b9c547cSRui Paulo continue; 15015b9c547cSRui Paulo phy_info_freq(mode, &mode->channels[idx], tb_freq); 15025b9c547cSRui Paulo idx++; 15035b9c547cSRui Paulo } 15045b9c547cSRui Paulo phy_info->last_chan_idx = idx; 15055b9c547cSRui Paulo 15065b9c547cSRui Paulo return NL_OK; 15075b9c547cSRui Paulo } 15085b9c547cSRui Paulo 15095b9c547cSRui Paulo 15105b9c547cSRui Paulo static int phy_info_rates(struct hostapd_hw_modes *mode, struct nlattr *tb) 15115b9c547cSRui Paulo { 15125b9c547cSRui Paulo static struct nla_policy rate_policy[NL80211_BITRATE_ATTR_MAX + 1] = { 15135b9c547cSRui Paulo [NL80211_BITRATE_ATTR_RATE] = { .type = NLA_U32 }, 15145b9c547cSRui Paulo [NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE] = 15155b9c547cSRui Paulo { .type = NLA_FLAG }, 15165b9c547cSRui Paulo }; 15175b9c547cSRui Paulo struct nlattr *tb_rate[NL80211_BITRATE_ATTR_MAX + 1]; 15185b9c547cSRui Paulo struct nlattr *nl_rate; 15195b9c547cSRui Paulo int rem_rate, idx; 15205b9c547cSRui Paulo 15215b9c547cSRui Paulo if (tb == NULL) 15225b9c547cSRui Paulo return NL_OK; 15235b9c547cSRui Paulo 15245b9c547cSRui Paulo nla_for_each_nested(nl_rate, tb, rem_rate) { 15255b9c547cSRui Paulo nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX, 15265b9c547cSRui Paulo nla_data(nl_rate), nla_len(nl_rate), 15275b9c547cSRui Paulo rate_policy); 15285b9c547cSRui Paulo if (!tb_rate[NL80211_BITRATE_ATTR_RATE]) 15295b9c547cSRui Paulo continue; 15305b9c547cSRui Paulo mode->num_rates++; 15315b9c547cSRui Paulo } 15325b9c547cSRui Paulo 15335b9c547cSRui Paulo mode->rates = os_calloc(mode->num_rates, sizeof(int)); 15345b9c547cSRui Paulo if (!mode->rates) 1535780fb4a2SCy Schubert return NL_STOP; 15365b9c547cSRui Paulo 15375b9c547cSRui Paulo idx = 0; 15385b9c547cSRui Paulo 15395b9c547cSRui Paulo nla_for_each_nested(nl_rate, tb, rem_rate) { 15405b9c547cSRui Paulo nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX, 15415b9c547cSRui Paulo nla_data(nl_rate), nla_len(nl_rate), 15425b9c547cSRui Paulo rate_policy); 15435b9c547cSRui Paulo if (!tb_rate[NL80211_BITRATE_ATTR_RATE]) 15445b9c547cSRui Paulo continue; 15455b9c547cSRui Paulo mode->rates[idx] = nla_get_u32( 15465b9c547cSRui Paulo tb_rate[NL80211_BITRATE_ATTR_RATE]); 15475b9c547cSRui Paulo idx++; 15485b9c547cSRui Paulo } 15495b9c547cSRui Paulo 15505b9c547cSRui Paulo return NL_OK; 15515b9c547cSRui Paulo } 15525b9c547cSRui Paulo 15535b9c547cSRui Paulo 1554*206b73d0SCy Schubert static void phy_info_iftype_copy(struct he_capabilities *he_capab, 1555*206b73d0SCy Schubert enum ieee80211_op_mode opmode, 1556*206b73d0SCy Schubert struct nlattr **tb, struct nlattr **tb_flags) 1557*206b73d0SCy Schubert { 1558*206b73d0SCy Schubert enum nl80211_iftype iftype; 1559*206b73d0SCy Schubert size_t len; 1560*206b73d0SCy Schubert 1561*206b73d0SCy Schubert switch (opmode) { 1562*206b73d0SCy Schubert case IEEE80211_MODE_INFRA: 1563*206b73d0SCy Schubert iftype = NL80211_IFTYPE_STATION; 1564*206b73d0SCy Schubert break; 1565*206b73d0SCy Schubert case IEEE80211_MODE_IBSS: 1566*206b73d0SCy Schubert iftype = NL80211_IFTYPE_ADHOC; 1567*206b73d0SCy Schubert break; 1568*206b73d0SCy Schubert case IEEE80211_MODE_AP: 1569*206b73d0SCy Schubert iftype = NL80211_IFTYPE_AP; 1570*206b73d0SCy Schubert break; 1571*206b73d0SCy Schubert case IEEE80211_MODE_MESH: 1572*206b73d0SCy Schubert iftype = NL80211_IFTYPE_MESH_POINT; 1573*206b73d0SCy Schubert break; 1574*206b73d0SCy Schubert default: 1575*206b73d0SCy Schubert return; 1576*206b73d0SCy Schubert } 1577*206b73d0SCy Schubert 1578*206b73d0SCy Schubert if (!nla_get_flag(tb_flags[iftype])) 1579*206b73d0SCy Schubert return; 1580*206b73d0SCy Schubert 1581*206b73d0SCy Schubert he_capab->he_supported = 1; 1582*206b73d0SCy Schubert 1583*206b73d0SCy Schubert if (tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY]) { 1584*206b73d0SCy Schubert len = nla_len(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY]); 1585*206b73d0SCy Schubert 1586*206b73d0SCy Schubert if (len > sizeof(he_capab->phy_cap)) 1587*206b73d0SCy Schubert len = sizeof(he_capab->phy_cap); 1588*206b73d0SCy Schubert os_memcpy(he_capab->phy_cap, 1589*206b73d0SCy Schubert nla_data(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY]), 1590*206b73d0SCy Schubert len); 1591*206b73d0SCy Schubert } 1592*206b73d0SCy Schubert 1593*206b73d0SCy Schubert if (tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC]) { 1594*206b73d0SCy Schubert len = nla_len(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC]); 1595*206b73d0SCy Schubert 1596*206b73d0SCy Schubert if (len > sizeof(he_capab->mac_cap)) 1597*206b73d0SCy Schubert len = sizeof(he_capab->mac_cap); 1598*206b73d0SCy Schubert os_memcpy(he_capab->mac_cap, 1599*206b73d0SCy Schubert nla_data(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC]), 1600*206b73d0SCy Schubert len); 1601*206b73d0SCy Schubert } 1602*206b73d0SCy Schubert 1603*206b73d0SCy Schubert if (tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET]) { 1604*206b73d0SCy Schubert len = nla_len(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET]); 1605*206b73d0SCy Schubert 1606*206b73d0SCy Schubert if (len > sizeof(he_capab->mcs)) 1607*206b73d0SCy Schubert len = sizeof(he_capab->mcs); 1608*206b73d0SCy Schubert os_memcpy(he_capab->mcs, 1609*206b73d0SCy Schubert nla_data(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET]), 1610*206b73d0SCy Schubert len); 1611*206b73d0SCy Schubert } 1612*206b73d0SCy Schubert 1613*206b73d0SCy Schubert if (tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE]) { 1614*206b73d0SCy Schubert len = nla_len(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE]); 1615*206b73d0SCy Schubert 1616*206b73d0SCy Schubert if (len > sizeof(he_capab->ppet)) 1617*206b73d0SCy Schubert len = sizeof(he_capab->ppet); 1618*206b73d0SCy Schubert os_memcpy(&he_capab->ppet, 1619*206b73d0SCy Schubert nla_data(tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE]), 1620*206b73d0SCy Schubert len); 1621*206b73d0SCy Schubert } 1622*206b73d0SCy Schubert } 1623*206b73d0SCy Schubert 1624*206b73d0SCy Schubert 1625*206b73d0SCy Schubert static int phy_info_iftype(struct hostapd_hw_modes *mode, 1626*206b73d0SCy Schubert struct nlattr *nl_iftype) 1627*206b73d0SCy Schubert { 1628*206b73d0SCy Schubert struct nlattr *tb[NL80211_BAND_IFTYPE_ATTR_MAX + 1]; 1629*206b73d0SCy Schubert struct nlattr *tb_flags[NL80211_IFTYPE_MAX + 1]; 1630*206b73d0SCy Schubert unsigned int i; 1631*206b73d0SCy Schubert 1632*206b73d0SCy Schubert nla_parse(tb, NL80211_BAND_IFTYPE_ATTR_MAX, 1633*206b73d0SCy Schubert nla_data(nl_iftype), nla_len(nl_iftype), NULL); 1634*206b73d0SCy Schubert 1635*206b73d0SCy Schubert if (!tb[NL80211_BAND_IFTYPE_ATTR_IFTYPES]) 1636*206b73d0SCy Schubert return NL_STOP; 1637*206b73d0SCy Schubert 1638*206b73d0SCy Schubert if (nla_parse_nested(tb_flags, NL80211_IFTYPE_MAX, 1639*206b73d0SCy Schubert tb[NL80211_BAND_IFTYPE_ATTR_IFTYPES], NULL)) 1640*206b73d0SCy Schubert return NL_STOP; 1641*206b73d0SCy Schubert 1642*206b73d0SCy Schubert for (i = 0; i < IEEE80211_MODE_NUM; i++) 1643*206b73d0SCy Schubert phy_info_iftype_copy(&mode->he_capab[i], i, tb, tb_flags); 1644*206b73d0SCy Schubert 1645*206b73d0SCy Schubert return NL_OK; 1646*206b73d0SCy Schubert } 1647*206b73d0SCy Schubert 1648*206b73d0SCy Schubert 16495b9c547cSRui Paulo static int phy_info_band(struct phy_info_arg *phy_info, struct nlattr *nl_band) 16505b9c547cSRui Paulo { 16515b9c547cSRui Paulo struct nlattr *tb_band[NL80211_BAND_ATTR_MAX + 1]; 16525b9c547cSRui Paulo struct hostapd_hw_modes *mode; 16535b9c547cSRui Paulo int ret; 16545b9c547cSRui Paulo 16555b9c547cSRui Paulo if (phy_info->last_mode != nl_band->nla_type) { 16565b9c547cSRui Paulo mode = os_realloc_array(phy_info->modes, 16575b9c547cSRui Paulo *phy_info->num_modes + 1, 16585b9c547cSRui Paulo sizeof(*mode)); 1659780fb4a2SCy Schubert if (!mode) { 1660780fb4a2SCy Schubert phy_info->failed = 1; 1661780fb4a2SCy Schubert return NL_STOP; 1662780fb4a2SCy Schubert } 16635b9c547cSRui Paulo phy_info->modes = mode; 16645b9c547cSRui Paulo 16655b9c547cSRui Paulo mode = &phy_info->modes[*(phy_info->num_modes)]; 16665b9c547cSRui Paulo os_memset(mode, 0, sizeof(*mode)); 16675b9c547cSRui Paulo mode->mode = NUM_HOSTAPD_MODES; 16685b9c547cSRui Paulo mode->flags = HOSTAPD_MODE_FLAG_HT_INFO_KNOWN | 16695b9c547cSRui Paulo HOSTAPD_MODE_FLAG_VHT_INFO_KNOWN; 16705b9c547cSRui Paulo 16715b9c547cSRui Paulo /* 16725b9c547cSRui Paulo * Unsupported VHT MCS stream is defined as value 3, so the VHT 16735b9c547cSRui Paulo * MCS RX/TX map must be initialized with 0xffff to mark all 8 16745b9c547cSRui Paulo * possible streams as unsupported. This will be overridden if 16755b9c547cSRui Paulo * driver advertises VHT support. 16765b9c547cSRui Paulo */ 16775b9c547cSRui Paulo mode->vht_mcs_set[0] = 0xff; 16785b9c547cSRui Paulo mode->vht_mcs_set[1] = 0xff; 16795b9c547cSRui Paulo mode->vht_mcs_set[4] = 0xff; 16805b9c547cSRui Paulo mode->vht_mcs_set[5] = 0xff; 16815b9c547cSRui Paulo 16825b9c547cSRui Paulo *(phy_info->num_modes) += 1; 16835b9c547cSRui Paulo phy_info->last_mode = nl_band->nla_type; 16845b9c547cSRui Paulo phy_info->last_chan_idx = 0; 16855b9c547cSRui Paulo } else 16865b9c547cSRui Paulo mode = &phy_info->modes[*(phy_info->num_modes) - 1]; 16875b9c547cSRui Paulo 16885b9c547cSRui Paulo nla_parse(tb_band, NL80211_BAND_ATTR_MAX, nla_data(nl_band), 16895b9c547cSRui Paulo nla_len(nl_band), NULL); 16905b9c547cSRui Paulo 16915b9c547cSRui Paulo phy_info_ht_capa(mode, tb_band[NL80211_BAND_ATTR_HT_CAPA], 16925b9c547cSRui Paulo tb_band[NL80211_BAND_ATTR_HT_AMPDU_FACTOR], 16935b9c547cSRui Paulo tb_band[NL80211_BAND_ATTR_HT_AMPDU_DENSITY], 16945b9c547cSRui Paulo tb_band[NL80211_BAND_ATTR_HT_MCS_SET]); 16955b9c547cSRui Paulo phy_info_vht_capa(mode, tb_band[NL80211_BAND_ATTR_VHT_CAPA], 16965b9c547cSRui Paulo tb_band[NL80211_BAND_ATTR_VHT_MCS_SET]); 16975b9c547cSRui Paulo ret = phy_info_freqs(phy_info, mode, tb_band[NL80211_BAND_ATTR_FREQS]); 1698780fb4a2SCy Schubert if (ret == NL_OK) 16995b9c547cSRui Paulo ret = phy_info_rates(mode, tb_band[NL80211_BAND_ATTR_RATES]); 1700780fb4a2SCy Schubert if (ret != NL_OK) { 1701780fb4a2SCy Schubert phy_info->failed = 1; 17025b9c547cSRui Paulo return ret; 1703780fb4a2SCy Schubert } 17045b9c547cSRui Paulo 1705*206b73d0SCy Schubert if (tb_band[NL80211_BAND_ATTR_IFTYPE_DATA]) { 1706*206b73d0SCy Schubert struct nlattr *nl_iftype; 1707*206b73d0SCy Schubert int rem_band; 1708*206b73d0SCy Schubert 1709*206b73d0SCy Schubert nla_for_each_nested(nl_iftype, 1710*206b73d0SCy Schubert tb_band[NL80211_BAND_ATTR_IFTYPE_DATA], 1711*206b73d0SCy Schubert rem_band) { 1712*206b73d0SCy Schubert ret = phy_info_iftype(mode, nl_iftype); 1713*206b73d0SCy Schubert if (ret != NL_OK) 1714*206b73d0SCy Schubert return ret; 1715*206b73d0SCy Schubert } 1716*206b73d0SCy Schubert } 1717*206b73d0SCy Schubert 17185b9c547cSRui Paulo return NL_OK; 17195b9c547cSRui Paulo } 17205b9c547cSRui Paulo 17215b9c547cSRui Paulo 17225b9c547cSRui Paulo static int phy_info_handler(struct nl_msg *msg, void *arg) 17235b9c547cSRui Paulo { 17245b9c547cSRui Paulo struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; 17255b9c547cSRui Paulo struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); 17265b9c547cSRui Paulo struct phy_info_arg *phy_info = arg; 17275b9c547cSRui Paulo struct nlattr *nl_band; 17285b9c547cSRui Paulo int rem_band; 17295b9c547cSRui Paulo 17305b9c547cSRui Paulo nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), 17315b9c547cSRui Paulo genlmsg_attrlen(gnlh, 0), NULL); 17325b9c547cSRui Paulo 17335b9c547cSRui Paulo if (!tb_msg[NL80211_ATTR_WIPHY_BANDS]) 17345b9c547cSRui Paulo return NL_SKIP; 17355b9c547cSRui Paulo 17365b9c547cSRui Paulo nla_for_each_nested(nl_band, tb_msg[NL80211_ATTR_WIPHY_BANDS], rem_band) 17375b9c547cSRui Paulo { 17385b9c547cSRui Paulo int res = phy_info_band(phy_info, nl_band); 17395b9c547cSRui Paulo if (res != NL_OK) 17405b9c547cSRui Paulo return res; 17415b9c547cSRui Paulo } 17425b9c547cSRui Paulo 17435b9c547cSRui Paulo return NL_SKIP; 17445b9c547cSRui Paulo } 17455b9c547cSRui Paulo 17465b9c547cSRui Paulo 17475b9c547cSRui Paulo static struct hostapd_hw_modes * 17485b9c547cSRui Paulo wpa_driver_nl80211_postprocess_modes(struct hostapd_hw_modes *modes, 17495b9c547cSRui Paulo u16 *num_modes) 17505b9c547cSRui Paulo { 17515b9c547cSRui Paulo u16 m; 17525b9c547cSRui Paulo struct hostapd_hw_modes *mode11g = NULL, *nmodes, *mode; 17535b9c547cSRui Paulo int i, mode11g_idx = -1; 17545b9c547cSRui Paulo 17555b9c547cSRui Paulo /* heuristic to set up modes */ 17565b9c547cSRui Paulo for (m = 0; m < *num_modes; m++) { 17575b9c547cSRui Paulo if (!modes[m].num_channels) 17585b9c547cSRui Paulo continue; 17595b9c547cSRui Paulo if (modes[m].channels[0].freq < 4000) { 17605b9c547cSRui Paulo modes[m].mode = HOSTAPD_MODE_IEEE80211B; 17615b9c547cSRui Paulo for (i = 0; i < modes[m].num_rates; i++) { 17625b9c547cSRui Paulo if (modes[m].rates[i] > 200) { 17635b9c547cSRui Paulo modes[m].mode = HOSTAPD_MODE_IEEE80211G; 17645b9c547cSRui Paulo break; 17655b9c547cSRui Paulo } 17665b9c547cSRui Paulo } 17675b9c547cSRui Paulo } else if (modes[m].channels[0].freq > 50000) 17685b9c547cSRui Paulo modes[m].mode = HOSTAPD_MODE_IEEE80211AD; 17695b9c547cSRui Paulo else 17705b9c547cSRui Paulo modes[m].mode = HOSTAPD_MODE_IEEE80211A; 17715b9c547cSRui Paulo } 17725b9c547cSRui Paulo 17735b9c547cSRui Paulo /* If only 802.11g mode is included, use it to construct matching 17745b9c547cSRui Paulo * 802.11b mode data. */ 17755b9c547cSRui Paulo 17765b9c547cSRui Paulo for (m = 0; m < *num_modes; m++) { 17775b9c547cSRui Paulo if (modes[m].mode == HOSTAPD_MODE_IEEE80211B) 17785b9c547cSRui Paulo return modes; /* 802.11b already included */ 17795b9c547cSRui Paulo if (modes[m].mode == HOSTAPD_MODE_IEEE80211G) 17805b9c547cSRui Paulo mode11g_idx = m; 17815b9c547cSRui Paulo } 17825b9c547cSRui Paulo 17835b9c547cSRui Paulo if (mode11g_idx < 0) 17845b9c547cSRui Paulo return modes; /* 2.4 GHz band not supported at all */ 17855b9c547cSRui Paulo 17865b9c547cSRui Paulo nmodes = os_realloc_array(modes, *num_modes + 1, sizeof(*nmodes)); 17875b9c547cSRui Paulo if (nmodes == NULL) 17885b9c547cSRui Paulo return modes; /* Could not add 802.11b mode */ 17895b9c547cSRui Paulo 17905b9c547cSRui Paulo mode = &nmodes[*num_modes]; 17915b9c547cSRui Paulo os_memset(mode, 0, sizeof(*mode)); 17925b9c547cSRui Paulo (*num_modes)++; 17935b9c547cSRui Paulo modes = nmodes; 17945b9c547cSRui Paulo 17955b9c547cSRui Paulo mode->mode = HOSTAPD_MODE_IEEE80211B; 17965b9c547cSRui Paulo 17975b9c547cSRui Paulo mode11g = &modes[mode11g_idx]; 17985b9c547cSRui Paulo mode->num_channels = mode11g->num_channels; 179985732ac8SCy Schubert mode->channels = os_memdup(mode11g->channels, 180085732ac8SCy Schubert mode11g->num_channels * 18015b9c547cSRui Paulo sizeof(struct hostapd_channel_data)); 18025b9c547cSRui Paulo if (mode->channels == NULL) { 18035b9c547cSRui Paulo (*num_modes)--; 18045b9c547cSRui Paulo return modes; /* Could not add 802.11b mode */ 18055b9c547cSRui Paulo } 18065b9c547cSRui Paulo 18075b9c547cSRui Paulo mode->num_rates = 0; 18085b9c547cSRui Paulo mode->rates = os_malloc(4 * sizeof(int)); 18095b9c547cSRui Paulo if (mode->rates == NULL) { 18105b9c547cSRui Paulo os_free(mode->channels); 18115b9c547cSRui Paulo (*num_modes)--; 18125b9c547cSRui Paulo return modes; /* Could not add 802.11b mode */ 18135b9c547cSRui Paulo } 18145b9c547cSRui Paulo 18155b9c547cSRui Paulo for (i = 0; i < mode11g->num_rates; i++) { 18165b9c547cSRui Paulo if (mode11g->rates[i] != 10 && mode11g->rates[i] != 20 && 18175b9c547cSRui Paulo mode11g->rates[i] != 55 && mode11g->rates[i] != 110) 18185b9c547cSRui Paulo continue; 18195b9c547cSRui Paulo mode->rates[mode->num_rates] = mode11g->rates[i]; 18205b9c547cSRui Paulo mode->num_rates++; 18215b9c547cSRui Paulo if (mode->num_rates == 4) 18225b9c547cSRui Paulo break; 18235b9c547cSRui Paulo } 18245b9c547cSRui Paulo 18255b9c547cSRui Paulo if (mode->num_rates == 0) { 18265b9c547cSRui Paulo os_free(mode->channels); 18275b9c547cSRui Paulo os_free(mode->rates); 18285b9c547cSRui Paulo (*num_modes)--; 18295b9c547cSRui Paulo return modes; /* No 802.11b rates */ 18305b9c547cSRui Paulo } 18315b9c547cSRui Paulo 18325b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "nl80211: Added 802.11b mode based on 802.11g " 18335b9c547cSRui Paulo "information"); 18345b9c547cSRui Paulo 18355b9c547cSRui Paulo return modes; 18365b9c547cSRui Paulo } 18375b9c547cSRui Paulo 18385b9c547cSRui Paulo 18395b9c547cSRui Paulo static void nl80211_set_ht40_mode(struct hostapd_hw_modes *mode, int start, 18405b9c547cSRui Paulo int end) 18415b9c547cSRui Paulo { 18425b9c547cSRui Paulo int c; 18435b9c547cSRui Paulo 18445b9c547cSRui Paulo for (c = 0; c < mode->num_channels; c++) { 18455b9c547cSRui Paulo struct hostapd_channel_data *chan = &mode->channels[c]; 18465b9c547cSRui Paulo if (chan->freq - 10 >= start && chan->freq + 10 <= end) 18475b9c547cSRui Paulo chan->flag |= HOSTAPD_CHAN_HT40; 18485b9c547cSRui Paulo } 18495b9c547cSRui Paulo } 18505b9c547cSRui Paulo 18515b9c547cSRui Paulo 18525b9c547cSRui Paulo static void nl80211_set_ht40_mode_sec(struct hostapd_hw_modes *mode, int start, 18535b9c547cSRui Paulo int end) 18545b9c547cSRui Paulo { 18555b9c547cSRui Paulo int c; 18565b9c547cSRui Paulo 18575b9c547cSRui Paulo for (c = 0; c < mode->num_channels; c++) { 18585b9c547cSRui Paulo struct hostapd_channel_data *chan = &mode->channels[c]; 18595b9c547cSRui Paulo if (!(chan->flag & HOSTAPD_CHAN_HT40)) 18605b9c547cSRui Paulo continue; 18615b9c547cSRui Paulo if (chan->freq - 30 >= start && chan->freq - 10 <= end) 18625b9c547cSRui Paulo chan->flag |= HOSTAPD_CHAN_HT40MINUS; 18635b9c547cSRui Paulo if (chan->freq + 10 >= start && chan->freq + 30 <= end) 18645b9c547cSRui Paulo chan->flag |= HOSTAPD_CHAN_HT40PLUS; 18655b9c547cSRui Paulo } 18665b9c547cSRui Paulo } 18675b9c547cSRui Paulo 18685b9c547cSRui Paulo 18695b9c547cSRui Paulo static void nl80211_reg_rule_max_eirp(u32 start, u32 end, u32 max_eirp, 18705b9c547cSRui Paulo struct phy_info_arg *results) 18715b9c547cSRui Paulo { 18725b9c547cSRui Paulo u16 m; 18735b9c547cSRui Paulo 18745b9c547cSRui Paulo for (m = 0; m < *results->num_modes; m++) { 18755b9c547cSRui Paulo int c; 18765b9c547cSRui Paulo struct hostapd_hw_modes *mode = &results->modes[m]; 18775b9c547cSRui Paulo 18785b9c547cSRui Paulo for (c = 0; c < mode->num_channels; c++) { 18795b9c547cSRui Paulo struct hostapd_channel_data *chan = &mode->channels[c]; 18805b9c547cSRui Paulo if ((u32) chan->freq - 10 >= start && 18815b9c547cSRui Paulo (u32) chan->freq + 10 <= end) 18825b9c547cSRui Paulo chan->max_tx_power = max_eirp; 18835b9c547cSRui Paulo } 18845b9c547cSRui Paulo } 18855b9c547cSRui Paulo } 18865b9c547cSRui Paulo 18875b9c547cSRui Paulo 18885b9c547cSRui Paulo static void nl80211_reg_rule_ht40(u32 start, u32 end, 18895b9c547cSRui Paulo struct phy_info_arg *results) 18905b9c547cSRui Paulo { 18915b9c547cSRui Paulo u16 m; 18925b9c547cSRui Paulo 18935b9c547cSRui Paulo for (m = 0; m < *results->num_modes; m++) { 18945b9c547cSRui Paulo if (!(results->modes[m].ht_capab & 18955b9c547cSRui Paulo HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) 18965b9c547cSRui Paulo continue; 18975b9c547cSRui Paulo nl80211_set_ht40_mode(&results->modes[m], start, end); 18985b9c547cSRui Paulo } 18995b9c547cSRui Paulo } 19005b9c547cSRui Paulo 19015b9c547cSRui Paulo 19025b9c547cSRui Paulo static void nl80211_reg_rule_sec(struct nlattr *tb[], 19035b9c547cSRui Paulo struct phy_info_arg *results) 19045b9c547cSRui Paulo { 19055b9c547cSRui Paulo u32 start, end, max_bw; 19065b9c547cSRui Paulo u16 m; 19075b9c547cSRui Paulo 19085b9c547cSRui Paulo if (tb[NL80211_ATTR_FREQ_RANGE_START] == NULL || 19095b9c547cSRui Paulo tb[NL80211_ATTR_FREQ_RANGE_END] == NULL || 19105b9c547cSRui Paulo tb[NL80211_ATTR_FREQ_RANGE_MAX_BW] == NULL) 19115b9c547cSRui Paulo return; 19125b9c547cSRui Paulo 19135b9c547cSRui Paulo start = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]) / 1000; 19145b9c547cSRui Paulo end = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]) / 1000; 19155b9c547cSRui Paulo max_bw = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) / 1000; 19165b9c547cSRui Paulo 19175b9c547cSRui Paulo if (max_bw < 20) 19185b9c547cSRui Paulo return; 19195b9c547cSRui Paulo 19205b9c547cSRui Paulo for (m = 0; m < *results->num_modes; m++) { 19215b9c547cSRui Paulo if (!(results->modes[m].ht_capab & 19225b9c547cSRui Paulo HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) 19235b9c547cSRui Paulo continue; 19245b9c547cSRui Paulo nl80211_set_ht40_mode_sec(&results->modes[m], start, end); 19255b9c547cSRui Paulo } 19265b9c547cSRui Paulo } 19275b9c547cSRui Paulo 19285b9c547cSRui Paulo 19295b9c547cSRui Paulo static void nl80211_set_vht_mode(struct hostapd_hw_modes *mode, int start, 1930780fb4a2SCy Schubert int end, int max_bw) 19315b9c547cSRui Paulo { 19325b9c547cSRui Paulo int c; 19335b9c547cSRui Paulo 19345b9c547cSRui Paulo for (c = 0; c < mode->num_channels; c++) { 19355b9c547cSRui Paulo struct hostapd_channel_data *chan = &mode->channels[c]; 19365b9c547cSRui Paulo if (chan->freq - 10 >= start && chan->freq + 70 <= end) 19375b9c547cSRui Paulo chan->flag |= HOSTAPD_CHAN_VHT_10_70; 19385b9c547cSRui Paulo 19395b9c547cSRui Paulo if (chan->freq - 30 >= start && chan->freq + 50 <= end) 19405b9c547cSRui Paulo chan->flag |= HOSTAPD_CHAN_VHT_30_50; 19415b9c547cSRui Paulo 19425b9c547cSRui Paulo if (chan->freq - 50 >= start && chan->freq + 30 <= end) 19435b9c547cSRui Paulo chan->flag |= HOSTAPD_CHAN_VHT_50_30; 19445b9c547cSRui Paulo 19455b9c547cSRui Paulo if (chan->freq - 70 >= start && chan->freq + 10 <= end) 19465b9c547cSRui Paulo chan->flag |= HOSTAPD_CHAN_VHT_70_10; 1947780fb4a2SCy Schubert 1948780fb4a2SCy Schubert if (max_bw >= 160) { 1949780fb4a2SCy Schubert if (chan->freq - 10 >= start && chan->freq + 150 <= end) 1950780fb4a2SCy Schubert chan->flag |= HOSTAPD_CHAN_VHT_10_150; 1951780fb4a2SCy Schubert 1952780fb4a2SCy Schubert if (chan->freq - 30 >= start && chan->freq + 130 <= end) 1953780fb4a2SCy Schubert chan->flag |= HOSTAPD_CHAN_VHT_30_130; 1954780fb4a2SCy Schubert 1955780fb4a2SCy Schubert if (chan->freq - 50 >= start && chan->freq + 110 <= end) 1956780fb4a2SCy Schubert chan->flag |= HOSTAPD_CHAN_VHT_50_110; 1957780fb4a2SCy Schubert 1958780fb4a2SCy Schubert if (chan->freq - 70 >= start && chan->freq + 90 <= end) 1959780fb4a2SCy Schubert chan->flag |= HOSTAPD_CHAN_VHT_70_90; 1960780fb4a2SCy Schubert 1961780fb4a2SCy Schubert if (chan->freq - 90 >= start && chan->freq + 70 <= end) 1962780fb4a2SCy Schubert chan->flag |= HOSTAPD_CHAN_VHT_90_70; 1963780fb4a2SCy Schubert 1964780fb4a2SCy Schubert if (chan->freq - 110 >= start && chan->freq + 50 <= end) 1965780fb4a2SCy Schubert chan->flag |= HOSTAPD_CHAN_VHT_110_50; 1966780fb4a2SCy Schubert 1967780fb4a2SCy Schubert if (chan->freq - 130 >= start && chan->freq + 30 <= end) 1968780fb4a2SCy Schubert chan->flag |= HOSTAPD_CHAN_VHT_130_30; 1969780fb4a2SCy Schubert 1970780fb4a2SCy Schubert if (chan->freq - 150 >= start && chan->freq + 10 <= end) 1971780fb4a2SCy Schubert chan->flag |= HOSTAPD_CHAN_VHT_150_10; 1972780fb4a2SCy Schubert } 19735b9c547cSRui Paulo } 19745b9c547cSRui Paulo } 19755b9c547cSRui Paulo 19765b9c547cSRui Paulo 19775b9c547cSRui Paulo static void nl80211_reg_rule_vht(struct nlattr *tb[], 19785b9c547cSRui Paulo struct phy_info_arg *results) 19795b9c547cSRui Paulo { 19805b9c547cSRui Paulo u32 start, end, max_bw; 19815b9c547cSRui Paulo u16 m; 19825b9c547cSRui Paulo 19835b9c547cSRui Paulo if (tb[NL80211_ATTR_FREQ_RANGE_START] == NULL || 19845b9c547cSRui Paulo tb[NL80211_ATTR_FREQ_RANGE_END] == NULL || 19855b9c547cSRui Paulo tb[NL80211_ATTR_FREQ_RANGE_MAX_BW] == NULL) 19865b9c547cSRui Paulo return; 19875b9c547cSRui Paulo 19885b9c547cSRui Paulo start = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]) / 1000; 19895b9c547cSRui Paulo end = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]) / 1000; 19905b9c547cSRui Paulo max_bw = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) / 1000; 19915b9c547cSRui Paulo 19925b9c547cSRui Paulo if (max_bw < 80) 19935b9c547cSRui Paulo return; 19945b9c547cSRui Paulo 19955b9c547cSRui Paulo for (m = 0; m < *results->num_modes; m++) { 19965b9c547cSRui Paulo if (!(results->modes[m].ht_capab & 19975b9c547cSRui Paulo HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) 19985b9c547cSRui Paulo continue; 19995b9c547cSRui Paulo /* TODO: use a real VHT support indication */ 20005b9c547cSRui Paulo if (!results->modes[m].vht_capab) 20015b9c547cSRui Paulo continue; 20025b9c547cSRui Paulo 2003780fb4a2SCy Schubert nl80211_set_vht_mode(&results->modes[m], start, end, max_bw); 20045b9c547cSRui Paulo } 20055b9c547cSRui Paulo } 20065b9c547cSRui Paulo 20075b9c547cSRui Paulo 200885732ac8SCy Schubert static void nl80211_set_dfs_domain(enum nl80211_dfs_regions region, 200985732ac8SCy Schubert u8 *dfs_domain) 201085732ac8SCy Schubert { 201185732ac8SCy Schubert if (region == NL80211_DFS_FCC) 201285732ac8SCy Schubert *dfs_domain = HOSTAPD_DFS_REGION_FCC; 201385732ac8SCy Schubert else if (region == NL80211_DFS_ETSI) 201485732ac8SCy Schubert *dfs_domain = HOSTAPD_DFS_REGION_ETSI; 201585732ac8SCy Schubert else if (region == NL80211_DFS_JP) 201685732ac8SCy Schubert *dfs_domain = HOSTAPD_DFS_REGION_JP; 201785732ac8SCy Schubert else 201885732ac8SCy Schubert *dfs_domain = 0; 201985732ac8SCy Schubert } 202085732ac8SCy Schubert 202185732ac8SCy Schubert 20225b9c547cSRui Paulo static const char * dfs_domain_name(enum nl80211_dfs_regions region) 20235b9c547cSRui Paulo { 20245b9c547cSRui Paulo switch (region) { 20255b9c547cSRui Paulo case NL80211_DFS_UNSET: 20265b9c547cSRui Paulo return "DFS-UNSET"; 20275b9c547cSRui Paulo case NL80211_DFS_FCC: 20285b9c547cSRui Paulo return "DFS-FCC"; 20295b9c547cSRui Paulo case NL80211_DFS_ETSI: 20305b9c547cSRui Paulo return "DFS-ETSI"; 20315b9c547cSRui Paulo case NL80211_DFS_JP: 20325b9c547cSRui Paulo return "DFS-JP"; 20335b9c547cSRui Paulo default: 20345b9c547cSRui Paulo return "DFS-invalid"; 20355b9c547cSRui Paulo } 20365b9c547cSRui Paulo } 20375b9c547cSRui Paulo 20385b9c547cSRui Paulo 20395b9c547cSRui Paulo static int nl80211_get_reg(struct nl_msg *msg, void *arg) 20405b9c547cSRui Paulo { 20415b9c547cSRui Paulo struct phy_info_arg *results = arg; 20425b9c547cSRui Paulo struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; 20435b9c547cSRui Paulo struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); 20445b9c547cSRui Paulo struct nlattr *nl_rule; 20455b9c547cSRui Paulo struct nlattr *tb_rule[NL80211_FREQUENCY_ATTR_MAX + 1]; 20465b9c547cSRui Paulo int rem_rule; 20475b9c547cSRui Paulo static struct nla_policy reg_policy[NL80211_FREQUENCY_ATTR_MAX + 1] = { 20485b9c547cSRui Paulo [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, 20495b9c547cSRui Paulo [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, 20505b9c547cSRui Paulo [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, 20515b9c547cSRui Paulo [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, 20525b9c547cSRui Paulo [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, 20535b9c547cSRui Paulo [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, 20545b9c547cSRui Paulo }; 20555b9c547cSRui Paulo 20565b9c547cSRui Paulo nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), 20575b9c547cSRui Paulo genlmsg_attrlen(gnlh, 0), NULL); 20585b9c547cSRui Paulo if (!tb_msg[NL80211_ATTR_REG_ALPHA2] || 20595b9c547cSRui Paulo !tb_msg[NL80211_ATTR_REG_RULES]) { 20605b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "nl80211: No regulatory information " 20615b9c547cSRui Paulo "available"); 20625b9c547cSRui Paulo return NL_SKIP; 20635b9c547cSRui Paulo } 20645b9c547cSRui Paulo 20655b9c547cSRui Paulo if (tb_msg[NL80211_ATTR_DFS_REGION]) { 20665b9c547cSRui Paulo enum nl80211_dfs_regions dfs_domain; 20675b9c547cSRui Paulo dfs_domain = nla_get_u8(tb_msg[NL80211_ATTR_DFS_REGION]); 206885732ac8SCy Schubert nl80211_set_dfs_domain(dfs_domain, &results->dfs_domain); 20695b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "nl80211: Regulatory information - country=%s (%s)", 20705b9c547cSRui Paulo (char *) nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]), 20715b9c547cSRui Paulo dfs_domain_name(dfs_domain)); 20725b9c547cSRui Paulo } else { 20735b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "nl80211: Regulatory information - country=%s", 20745b9c547cSRui Paulo (char *) nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2])); 20755b9c547cSRui Paulo } 20765b9c547cSRui Paulo 20775b9c547cSRui Paulo nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule) 20785b9c547cSRui Paulo { 20795b9c547cSRui Paulo u32 start, end, max_eirp = 0, max_bw = 0, flags = 0; 20805b9c547cSRui Paulo nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX, 20815b9c547cSRui Paulo nla_data(nl_rule), nla_len(nl_rule), reg_policy); 20825b9c547cSRui Paulo if (tb_rule[NL80211_ATTR_FREQ_RANGE_START] == NULL || 20835b9c547cSRui Paulo tb_rule[NL80211_ATTR_FREQ_RANGE_END] == NULL) 20845b9c547cSRui Paulo continue; 20855b9c547cSRui Paulo start = nla_get_u32(tb_rule[NL80211_ATTR_FREQ_RANGE_START]) / 1000; 20865b9c547cSRui Paulo end = nla_get_u32(tb_rule[NL80211_ATTR_FREQ_RANGE_END]) / 1000; 20875b9c547cSRui Paulo if (tb_rule[NL80211_ATTR_POWER_RULE_MAX_EIRP]) 20885b9c547cSRui Paulo max_eirp = nla_get_u32(tb_rule[NL80211_ATTR_POWER_RULE_MAX_EIRP]) / 100; 20895b9c547cSRui Paulo if (tb_rule[NL80211_ATTR_FREQ_RANGE_MAX_BW]) 20905b9c547cSRui Paulo max_bw = nla_get_u32(tb_rule[NL80211_ATTR_FREQ_RANGE_MAX_BW]) / 1000; 20915b9c547cSRui Paulo if (tb_rule[NL80211_ATTR_REG_RULE_FLAGS]) 20925b9c547cSRui Paulo flags = nla_get_u32(tb_rule[NL80211_ATTR_REG_RULE_FLAGS]); 20935b9c547cSRui Paulo 20945b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "nl80211: %u-%u @ %u MHz %u mBm%s%s%s%s%s%s%s%s", 20955b9c547cSRui Paulo start, end, max_bw, max_eirp, 20965b9c547cSRui Paulo flags & NL80211_RRF_NO_OFDM ? " (no OFDM)" : "", 20975b9c547cSRui Paulo flags & NL80211_RRF_NO_CCK ? " (no CCK)" : "", 20985b9c547cSRui Paulo flags & NL80211_RRF_NO_INDOOR ? " (no indoor)" : "", 20995b9c547cSRui Paulo flags & NL80211_RRF_NO_OUTDOOR ? " (no outdoor)" : 21005b9c547cSRui Paulo "", 21015b9c547cSRui Paulo flags & NL80211_RRF_DFS ? " (DFS)" : "", 21025b9c547cSRui Paulo flags & NL80211_RRF_PTP_ONLY ? " (PTP only)" : "", 21035b9c547cSRui Paulo flags & NL80211_RRF_PTMP_ONLY ? " (PTMP only)" : "", 21045b9c547cSRui Paulo flags & NL80211_RRF_NO_IR ? " (no IR)" : ""); 21055b9c547cSRui Paulo if (max_bw >= 40) 21065b9c547cSRui Paulo nl80211_reg_rule_ht40(start, end, results); 21075b9c547cSRui Paulo if (tb_rule[NL80211_ATTR_POWER_RULE_MAX_EIRP]) 21085b9c547cSRui Paulo nl80211_reg_rule_max_eirp(start, end, max_eirp, 21095b9c547cSRui Paulo results); 21105b9c547cSRui Paulo } 21115b9c547cSRui Paulo 21125b9c547cSRui Paulo nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule) 21135b9c547cSRui Paulo { 21145b9c547cSRui Paulo nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX, 21155b9c547cSRui Paulo nla_data(nl_rule), nla_len(nl_rule), reg_policy); 21165b9c547cSRui Paulo nl80211_reg_rule_sec(tb_rule, results); 21175b9c547cSRui Paulo } 21185b9c547cSRui Paulo 21195b9c547cSRui Paulo nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule) 21205b9c547cSRui Paulo { 21215b9c547cSRui Paulo nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX, 21225b9c547cSRui Paulo nla_data(nl_rule), nla_len(nl_rule), reg_policy); 21235b9c547cSRui Paulo nl80211_reg_rule_vht(tb_rule, results); 21245b9c547cSRui Paulo } 21255b9c547cSRui Paulo 21265b9c547cSRui Paulo return NL_SKIP; 21275b9c547cSRui Paulo } 21285b9c547cSRui Paulo 21295b9c547cSRui Paulo 21305b9c547cSRui Paulo static int nl80211_set_regulatory_flags(struct wpa_driver_nl80211_data *drv, 21315b9c547cSRui Paulo struct phy_info_arg *results) 21325b9c547cSRui Paulo { 21335b9c547cSRui Paulo struct nl_msg *msg; 21345b9c547cSRui Paulo 21355b9c547cSRui Paulo msg = nlmsg_alloc(); 21365b9c547cSRui Paulo if (!msg) 21375b9c547cSRui Paulo return -ENOMEM; 21385b9c547cSRui Paulo 21395b9c547cSRui Paulo nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG); 214085732ac8SCy Schubert if (drv->capa.flags & WPA_DRIVER_FLAGS_SELF_MANAGED_REGULATORY) { 214185732ac8SCy Schubert if (nla_put_u32(msg, NL80211_ATTR_WIPHY, drv->wiphy_idx)) { 214285732ac8SCy Schubert nlmsg_free(msg); 214385732ac8SCy Schubert return -1; 214485732ac8SCy Schubert } 214585732ac8SCy Schubert } 214685732ac8SCy Schubert 21475b9c547cSRui Paulo return send_and_recv_msgs(drv, msg, nl80211_get_reg, results); 21485b9c547cSRui Paulo } 21495b9c547cSRui Paulo 21505b9c547cSRui Paulo 21514bc52338SCy Schubert static const char * modestr(enum hostapd_hw_mode mode) 21524bc52338SCy Schubert { 21534bc52338SCy Schubert switch (mode) { 21544bc52338SCy Schubert case HOSTAPD_MODE_IEEE80211B: 21554bc52338SCy Schubert return "802.11b"; 21564bc52338SCy Schubert case HOSTAPD_MODE_IEEE80211G: 21574bc52338SCy Schubert return "802.11g"; 21584bc52338SCy Schubert case HOSTAPD_MODE_IEEE80211A: 21594bc52338SCy Schubert return "802.11a"; 21604bc52338SCy Schubert case HOSTAPD_MODE_IEEE80211AD: 21614bc52338SCy Schubert return "802.11ad"; 21624bc52338SCy Schubert default: 21634bc52338SCy Schubert return "?"; 21644bc52338SCy Schubert } 21654bc52338SCy Schubert } 21664bc52338SCy Schubert 21674bc52338SCy Schubert 21684bc52338SCy Schubert static void nl80211_dump_chan_list(struct hostapd_hw_modes *modes, 21694bc52338SCy Schubert u16 num_modes) 21704bc52338SCy Schubert { 21714bc52338SCy Schubert int i; 21724bc52338SCy Schubert 21734bc52338SCy Schubert if (!modes) 21744bc52338SCy Schubert return; 21754bc52338SCy Schubert 21764bc52338SCy Schubert for (i = 0; i < num_modes; i++) { 21774bc52338SCy Schubert struct hostapd_hw_modes *mode = &modes[i]; 21784bc52338SCy Schubert char str[200]; 21794bc52338SCy Schubert char *pos = str; 21804bc52338SCy Schubert char *end = pos + sizeof(str); 21814bc52338SCy Schubert int j, res; 21824bc52338SCy Schubert 21834bc52338SCy Schubert for (j = 0; j < mode->num_channels; j++) { 21844bc52338SCy Schubert struct hostapd_channel_data *chan = &mode->channels[j]; 21854bc52338SCy Schubert 21864bc52338SCy Schubert res = os_snprintf(pos, end - pos, " %d%s%s%s", 21874bc52338SCy Schubert chan->freq, 21884bc52338SCy Schubert (chan->flag & HOSTAPD_CHAN_DISABLED) ? 21894bc52338SCy Schubert "[DISABLED]" : "", 21904bc52338SCy Schubert (chan->flag & HOSTAPD_CHAN_NO_IR) ? 21914bc52338SCy Schubert "[NO_IR]" : "", 21924bc52338SCy Schubert (chan->flag & HOSTAPD_CHAN_RADAR) ? 21934bc52338SCy Schubert "[RADAR]" : ""); 21944bc52338SCy Schubert if (os_snprintf_error(end - pos, res)) 21954bc52338SCy Schubert break; 21964bc52338SCy Schubert pos += res; 21974bc52338SCy Schubert } 21984bc52338SCy Schubert 21994bc52338SCy Schubert *pos = '\0'; 22004bc52338SCy Schubert wpa_printf(MSG_DEBUG, "nl80211: Mode IEEE %s:%s", 22014bc52338SCy Schubert modestr(mode->mode), str); 22024bc52338SCy Schubert } 22034bc52338SCy Schubert } 22044bc52338SCy Schubert 22054bc52338SCy Schubert 22065b9c547cSRui Paulo struct hostapd_hw_modes * 220785732ac8SCy Schubert nl80211_get_hw_feature_data(void *priv, u16 *num_modes, u16 *flags, 220885732ac8SCy Schubert u8 *dfs_domain) 22095b9c547cSRui Paulo { 22105b9c547cSRui Paulo u32 feat; 22115b9c547cSRui Paulo struct i802_bss *bss = priv; 22125b9c547cSRui Paulo struct wpa_driver_nl80211_data *drv = bss->drv; 22135b9c547cSRui Paulo int nl_flags = 0; 22145b9c547cSRui Paulo struct nl_msg *msg; 22155b9c547cSRui Paulo struct phy_info_arg result = { 22165b9c547cSRui Paulo .num_modes = num_modes, 22175b9c547cSRui Paulo .modes = NULL, 22185b9c547cSRui Paulo .last_mode = -1, 2219780fb4a2SCy Schubert .failed = 0, 222085732ac8SCy Schubert .dfs_domain = 0, 22215b9c547cSRui Paulo }; 22225b9c547cSRui Paulo 22235b9c547cSRui Paulo *num_modes = 0; 22245b9c547cSRui Paulo *flags = 0; 222585732ac8SCy Schubert *dfs_domain = 0; 22265b9c547cSRui Paulo 22275b9c547cSRui Paulo feat = get_nl80211_protocol_features(drv); 22285b9c547cSRui Paulo if (feat & NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP) 22295b9c547cSRui Paulo nl_flags = NLM_F_DUMP; 22305b9c547cSRui Paulo if (!(msg = nl80211_cmd_msg(bss, nl_flags, NL80211_CMD_GET_WIPHY)) || 22315b9c547cSRui Paulo nla_put_flag(msg, NL80211_ATTR_SPLIT_WIPHY_DUMP)) { 22325b9c547cSRui Paulo nlmsg_free(msg); 22335b9c547cSRui Paulo return NULL; 22345b9c547cSRui Paulo } 22355b9c547cSRui Paulo 22365b9c547cSRui Paulo if (send_and_recv_msgs(drv, msg, phy_info_handler, &result) == 0) { 22374bc52338SCy Schubert struct hostapd_hw_modes *modes; 22384bc52338SCy Schubert 22395b9c547cSRui Paulo nl80211_set_regulatory_flags(drv, &result); 2240780fb4a2SCy Schubert if (result.failed) { 2241780fb4a2SCy Schubert int i; 2242780fb4a2SCy Schubert 2243780fb4a2SCy Schubert for (i = 0; result.modes && i < *num_modes; i++) { 2244780fb4a2SCy Schubert os_free(result.modes[i].channels); 2245780fb4a2SCy Schubert os_free(result.modes[i].rates); 2246780fb4a2SCy Schubert } 2247780fb4a2SCy Schubert os_free(result.modes); 224885732ac8SCy Schubert *num_modes = 0; 2249780fb4a2SCy Schubert return NULL; 2250780fb4a2SCy Schubert } 225185732ac8SCy Schubert 225285732ac8SCy Schubert *dfs_domain = result.dfs_domain; 225385732ac8SCy Schubert 22544bc52338SCy Schubert modes = wpa_driver_nl80211_postprocess_modes(result.modes, 22555b9c547cSRui Paulo num_modes); 22564bc52338SCy Schubert nl80211_dump_chan_list(modes, *num_modes); 22574bc52338SCy Schubert return modes; 22585b9c547cSRui Paulo } 22595b9c547cSRui Paulo 22605b9c547cSRui Paulo return NULL; 22615b9c547cSRui Paulo } 2262