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_defs.h" 165b9c547cSRui Paulo #include "common/ieee802_11_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) { 2695b9c547cSRui Paulo case WLAN_CIPHER_SUITE_CCMP_256: 2705b9c547cSRui Paulo info->capa->enc |= WPA_DRIVER_CAPA_ENC_CCMP_256; 2715b9c547cSRui Paulo break; 2725b9c547cSRui Paulo case WLAN_CIPHER_SUITE_GCMP_256: 2735b9c547cSRui Paulo info->capa->enc |= WPA_DRIVER_CAPA_ENC_GCMP_256; 2745b9c547cSRui Paulo break; 2755b9c547cSRui Paulo case WLAN_CIPHER_SUITE_CCMP: 2765b9c547cSRui Paulo info->capa->enc |= WPA_DRIVER_CAPA_ENC_CCMP; 2775b9c547cSRui Paulo break; 2785b9c547cSRui Paulo case WLAN_CIPHER_SUITE_GCMP: 2795b9c547cSRui Paulo info->capa->enc |= WPA_DRIVER_CAPA_ENC_GCMP; 2805b9c547cSRui Paulo break; 2815b9c547cSRui Paulo case WLAN_CIPHER_SUITE_TKIP: 2825b9c547cSRui Paulo info->capa->enc |= WPA_DRIVER_CAPA_ENC_TKIP; 2835b9c547cSRui Paulo break; 2845b9c547cSRui Paulo case WLAN_CIPHER_SUITE_WEP104: 2855b9c547cSRui Paulo info->capa->enc |= WPA_DRIVER_CAPA_ENC_WEP104; 2865b9c547cSRui Paulo break; 2875b9c547cSRui Paulo case WLAN_CIPHER_SUITE_WEP40: 2885b9c547cSRui Paulo info->capa->enc |= WPA_DRIVER_CAPA_ENC_WEP40; 2895b9c547cSRui Paulo break; 2905b9c547cSRui Paulo case WLAN_CIPHER_SUITE_AES_CMAC: 2915b9c547cSRui Paulo info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP; 2925b9c547cSRui Paulo break; 2935b9c547cSRui Paulo case WLAN_CIPHER_SUITE_BIP_GMAC_128: 2945b9c547cSRui Paulo info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP_GMAC_128; 2955b9c547cSRui Paulo break; 2965b9c547cSRui Paulo case WLAN_CIPHER_SUITE_BIP_GMAC_256: 2975b9c547cSRui Paulo info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP_GMAC_256; 2985b9c547cSRui Paulo break; 2995b9c547cSRui Paulo case WLAN_CIPHER_SUITE_BIP_CMAC_256: 3005b9c547cSRui Paulo info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP_CMAC_256; 3015b9c547cSRui Paulo break; 3025b9c547cSRui Paulo case WLAN_CIPHER_SUITE_NO_GROUP_ADDR: 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; 351*780fb4a2SCy Schubert u8 *ext_features; 352*780fb4a2SCy Schubert int len; 353325151a3SRui Paulo 354325151a3SRui Paulo if (tb == NULL) 355325151a3SRui Paulo return; 356325151a3SRui Paulo 357*780fb4a2SCy Schubert ext_features = nla_data(tb); 358*780fb4a2SCy Schubert len = nla_len(tb); 359*780fb4a2SCy Schubert 360*780fb4a2SCy Schubert if (ext_feature_isset(ext_features, len, NL80211_EXT_FEATURE_VHT_IBSS)) 361325151a3SRui Paulo capa->flags |= WPA_DRIVER_FLAGS_VHT_IBSS; 362*780fb4a2SCy Schubert 363*780fb4a2SCy Schubert if (ext_feature_isset(ext_features, len, NL80211_EXT_FEATURE_RRM)) 364*780fb4a2SCy Schubert capa->rrm_flags |= WPA_DRIVER_FLAGS_SUPPORT_RRM; 365325151a3SRui Paulo } 366325151a3SRui Paulo 367325151a3SRui Paulo 3685b9c547cSRui Paulo static void wiphy_info_feature_flags(struct wiphy_info_data *info, 3695b9c547cSRui Paulo struct nlattr *tb) 3705b9c547cSRui Paulo { 3715b9c547cSRui Paulo u32 flags; 3725b9c547cSRui Paulo struct wpa_driver_capa *capa = info->capa; 3735b9c547cSRui Paulo 3745b9c547cSRui Paulo if (tb == NULL) 3755b9c547cSRui Paulo return; 3765b9c547cSRui Paulo 3775b9c547cSRui Paulo flags = nla_get_u32(tb); 3785b9c547cSRui Paulo 3795b9c547cSRui Paulo if (flags & NL80211_FEATURE_SK_TX_STATUS) 3805b9c547cSRui Paulo info->data_tx_status = 1; 3815b9c547cSRui Paulo 3825b9c547cSRui Paulo if (flags & NL80211_FEATURE_INACTIVITY_TIMER) 3835b9c547cSRui Paulo capa->flags |= WPA_DRIVER_FLAGS_INACTIVITY_TIMER; 3845b9c547cSRui Paulo 3855b9c547cSRui Paulo if (flags & NL80211_FEATURE_SAE) 3865b9c547cSRui Paulo capa->flags |= WPA_DRIVER_FLAGS_SAE; 3875b9c547cSRui Paulo 3885b9c547cSRui Paulo if (flags & NL80211_FEATURE_NEED_OBSS_SCAN) 3895b9c547cSRui Paulo capa->flags |= WPA_DRIVER_FLAGS_OBSS_SCAN; 3905b9c547cSRui Paulo 3915b9c547cSRui Paulo if (flags & NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE) 3925b9c547cSRui Paulo capa->flags |= WPA_DRIVER_FLAGS_HT_2040_COEX; 3935b9c547cSRui Paulo 3945b9c547cSRui Paulo if (flags & NL80211_FEATURE_TDLS_CHANNEL_SWITCH) { 3955b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "nl80211: TDLS channel switch"); 3965b9c547cSRui Paulo capa->flags |= WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH; 3975b9c547cSRui Paulo } 3985b9c547cSRui Paulo 3995b9c547cSRui Paulo if (flags & NL80211_FEATURE_P2P_GO_CTWIN) 4005b9c547cSRui Paulo info->p2p_go_ctwindow_supported = 1; 4015b9c547cSRui Paulo 4025b9c547cSRui Paulo if (flags & NL80211_FEATURE_LOW_PRIORITY_SCAN) 4035b9c547cSRui Paulo info->have_low_prio_scan = 1; 4045b9c547cSRui Paulo 4055b9c547cSRui Paulo if (flags & NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR) 4065b9c547cSRui Paulo info->mac_addr_rand_scan_supported = 1; 4075b9c547cSRui Paulo 4085b9c547cSRui Paulo if (flags & NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR) 4095b9c547cSRui Paulo info->mac_addr_rand_sched_scan_supported = 1; 4105b9c547cSRui Paulo 4115b9c547cSRui Paulo if (flags & NL80211_FEATURE_STATIC_SMPS) 4125b9c547cSRui Paulo capa->smps_modes |= WPA_DRIVER_SMPS_MODE_STATIC; 4135b9c547cSRui Paulo 4145b9c547cSRui Paulo if (flags & NL80211_FEATURE_DYNAMIC_SMPS) 4155b9c547cSRui Paulo capa->smps_modes |= WPA_DRIVER_SMPS_MODE_DYNAMIC; 4165b9c547cSRui Paulo 4175b9c547cSRui Paulo if (flags & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION) 4185b9c547cSRui Paulo info->wmm_ac_supported = 1; 4195b9c547cSRui Paulo 4205b9c547cSRui Paulo if (flags & NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) 4215b9c547cSRui Paulo capa->rrm_flags |= WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES; 4225b9c547cSRui Paulo 4235b9c547cSRui Paulo if (flags & NL80211_FEATURE_WFA_TPC_IE_IN_PROBES) 4245b9c547cSRui Paulo capa->rrm_flags |= WPA_DRIVER_FLAGS_WFA_TPC_IE_IN_PROBES; 4255b9c547cSRui Paulo 4265b9c547cSRui Paulo if (flags & NL80211_FEATURE_QUIET) 4275b9c547cSRui Paulo capa->rrm_flags |= WPA_DRIVER_FLAGS_QUIET; 4285b9c547cSRui Paulo 4295b9c547cSRui Paulo if (flags & NL80211_FEATURE_TX_POWER_INSERTION) 4305b9c547cSRui Paulo capa->rrm_flags |= WPA_DRIVER_FLAGS_TX_POWER_INSERTION; 4315b9c547cSRui Paulo 4325b9c547cSRui Paulo if (flags & NL80211_FEATURE_HT_IBSS) 4335b9c547cSRui Paulo capa->flags |= WPA_DRIVER_FLAGS_HT_IBSS; 434*780fb4a2SCy Schubert 435*780fb4a2SCy Schubert if (flags & NL80211_FEATURE_FULL_AP_CLIENT_STATE) 436*780fb4a2SCy Schubert capa->flags |= WPA_DRIVER_FLAGS_FULL_AP_CLIENT_STATE; 4375b9c547cSRui Paulo } 4385b9c547cSRui Paulo 4395b9c547cSRui Paulo 4405b9c547cSRui Paulo static void wiphy_info_probe_resp_offload(struct wpa_driver_capa *capa, 4415b9c547cSRui Paulo struct nlattr *tb) 4425b9c547cSRui Paulo { 4435b9c547cSRui Paulo u32 protocols; 4445b9c547cSRui Paulo 4455b9c547cSRui Paulo if (tb == NULL) 4465b9c547cSRui Paulo return; 4475b9c547cSRui Paulo 4485b9c547cSRui Paulo protocols = nla_get_u32(tb); 4495b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "nl80211: Supports Probe Response offload in AP " 4505b9c547cSRui Paulo "mode"); 4515b9c547cSRui Paulo capa->flags |= WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD; 4525b9c547cSRui Paulo capa->probe_resp_offloads = probe_resp_offload_support(protocols); 4535b9c547cSRui Paulo } 4545b9c547cSRui Paulo 4555b9c547cSRui Paulo 4565b9c547cSRui Paulo static void wiphy_info_wowlan_triggers(struct wpa_driver_capa *capa, 4575b9c547cSRui Paulo struct nlattr *tb) 4585b9c547cSRui Paulo { 4595b9c547cSRui Paulo struct nlattr *triggers[MAX_NL80211_WOWLAN_TRIG + 1]; 4605b9c547cSRui Paulo 4615b9c547cSRui Paulo if (tb == NULL) 4625b9c547cSRui Paulo return; 4635b9c547cSRui Paulo 4645b9c547cSRui Paulo if (nla_parse_nested(triggers, MAX_NL80211_WOWLAN_TRIG, 4655b9c547cSRui Paulo tb, NULL)) 4665b9c547cSRui Paulo return; 4675b9c547cSRui Paulo 4685b9c547cSRui Paulo if (triggers[NL80211_WOWLAN_TRIG_ANY]) 4695b9c547cSRui Paulo capa->wowlan_triggers.any = 1; 4705b9c547cSRui Paulo if (triggers[NL80211_WOWLAN_TRIG_DISCONNECT]) 4715b9c547cSRui Paulo capa->wowlan_triggers.disconnect = 1; 4725b9c547cSRui Paulo if (triggers[NL80211_WOWLAN_TRIG_MAGIC_PKT]) 4735b9c547cSRui Paulo capa->wowlan_triggers.magic_pkt = 1; 4745b9c547cSRui Paulo if (triggers[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) 4755b9c547cSRui Paulo capa->wowlan_triggers.gtk_rekey_failure = 1; 4765b9c547cSRui Paulo if (triggers[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) 4775b9c547cSRui Paulo capa->wowlan_triggers.eap_identity_req = 1; 4785b9c547cSRui Paulo if (triggers[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) 4795b9c547cSRui Paulo capa->wowlan_triggers.four_way_handshake = 1; 4805b9c547cSRui Paulo if (triggers[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) 4815b9c547cSRui Paulo capa->wowlan_triggers.rfkill_release = 1; 4825b9c547cSRui Paulo } 4835b9c547cSRui Paulo 4845b9c547cSRui Paulo 485*780fb4a2SCy Schubert static void wiphy_info_extended_capab(struct wpa_driver_nl80211_data *drv, 486*780fb4a2SCy Schubert struct nlattr *tb) 487*780fb4a2SCy Schubert { 488*780fb4a2SCy Schubert int rem = 0, i; 489*780fb4a2SCy Schubert struct nlattr *tb1[NL80211_ATTR_MAX + 1], *attr; 490*780fb4a2SCy Schubert 491*780fb4a2SCy Schubert if (!tb || drv->num_iface_ext_capa == NL80211_IFTYPE_MAX) 492*780fb4a2SCy Schubert return; 493*780fb4a2SCy Schubert 494*780fb4a2SCy Schubert nla_for_each_nested(attr, tb, rem) { 495*780fb4a2SCy Schubert unsigned int len; 496*780fb4a2SCy Schubert struct drv_nl80211_ext_capa *capa; 497*780fb4a2SCy Schubert 498*780fb4a2SCy Schubert nla_parse(tb1, NL80211_ATTR_MAX, nla_data(attr), 499*780fb4a2SCy Schubert nla_len(attr), NULL); 500*780fb4a2SCy Schubert 501*780fb4a2SCy Schubert if (!tb1[NL80211_ATTR_IFTYPE] || 502*780fb4a2SCy Schubert !tb1[NL80211_ATTR_EXT_CAPA] || 503*780fb4a2SCy Schubert !tb1[NL80211_ATTR_EXT_CAPA_MASK]) 504*780fb4a2SCy Schubert continue; 505*780fb4a2SCy Schubert 506*780fb4a2SCy Schubert capa = &drv->iface_ext_capa[drv->num_iface_ext_capa]; 507*780fb4a2SCy Schubert capa->iftype = nla_get_u32(tb1[NL80211_ATTR_IFTYPE]); 508*780fb4a2SCy Schubert wpa_printf(MSG_DEBUG, 509*780fb4a2SCy Schubert "nl80211: Driver-advertised extended capabilities for interface type %s", 510*780fb4a2SCy Schubert nl80211_iftype_str(capa->iftype)); 511*780fb4a2SCy Schubert 512*780fb4a2SCy Schubert len = nla_len(tb1[NL80211_ATTR_EXT_CAPA]); 513*780fb4a2SCy Schubert capa->ext_capa = os_malloc(len); 514*780fb4a2SCy Schubert if (!capa->ext_capa) 515*780fb4a2SCy Schubert goto err; 516*780fb4a2SCy Schubert 517*780fb4a2SCy Schubert os_memcpy(capa->ext_capa, nla_data(tb1[NL80211_ATTR_EXT_CAPA]), 518*780fb4a2SCy Schubert len); 519*780fb4a2SCy Schubert capa->ext_capa_len = len; 520*780fb4a2SCy Schubert wpa_hexdump(MSG_DEBUG, "nl80211: Extended capabilities", 521*780fb4a2SCy Schubert capa->ext_capa, capa->ext_capa_len); 522*780fb4a2SCy Schubert 523*780fb4a2SCy Schubert len = nla_len(tb1[NL80211_ATTR_EXT_CAPA_MASK]); 524*780fb4a2SCy Schubert capa->ext_capa_mask = os_malloc(len); 525*780fb4a2SCy Schubert if (!capa->ext_capa_mask) 526*780fb4a2SCy Schubert goto err; 527*780fb4a2SCy Schubert 528*780fb4a2SCy Schubert os_memcpy(capa->ext_capa_mask, 529*780fb4a2SCy Schubert nla_data(tb1[NL80211_ATTR_EXT_CAPA_MASK]), len); 530*780fb4a2SCy Schubert wpa_hexdump(MSG_DEBUG, "nl80211: Extended capabilities mask", 531*780fb4a2SCy Schubert capa->ext_capa_mask, capa->ext_capa_len); 532*780fb4a2SCy Schubert 533*780fb4a2SCy Schubert drv->num_iface_ext_capa++; 534*780fb4a2SCy Schubert if (drv->num_iface_ext_capa == NL80211_IFTYPE_MAX) 535*780fb4a2SCy Schubert break; 536*780fb4a2SCy Schubert } 537*780fb4a2SCy Schubert 538*780fb4a2SCy Schubert return; 539*780fb4a2SCy Schubert 540*780fb4a2SCy Schubert err: 541*780fb4a2SCy Schubert /* Cleanup allocated memory on error */ 542*780fb4a2SCy Schubert for (i = 0; i < NL80211_IFTYPE_MAX; i++) { 543*780fb4a2SCy Schubert os_free(drv->iface_ext_capa[i].ext_capa); 544*780fb4a2SCy Schubert drv->iface_ext_capa[i].ext_capa = NULL; 545*780fb4a2SCy Schubert os_free(drv->iface_ext_capa[i].ext_capa_mask); 546*780fb4a2SCy Schubert drv->iface_ext_capa[i].ext_capa_mask = NULL; 547*780fb4a2SCy Schubert drv->iface_ext_capa[i].ext_capa_len = 0; 548*780fb4a2SCy Schubert } 549*780fb4a2SCy Schubert drv->num_iface_ext_capa = 0; 550*780fb4a2SCy Schubert } 551*780fb4a2SCy Schubert 552*780fb4a2SCy Schubert 5535b9c547cSRui Paulo static int wiphy_info_handler(struct nl_msg *msg, void *arg) 5545b9c547cSRui Paulo { 5555b9c547cSRui Paulo struct nlattr *tb[NL80211_ATTR_MAX + 1]; 5565b9c547cSRui Paulo struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); 5575b9c547cSRui Paulo struct wiphy_info_data *info = arg; 5585b9c547cSRui Paulo struct wpa_driver_capa *capa = info->capa; 5595b9c547cSRui Paulo struct wpa_driver_nl80211_data *drv = info->drv; 5605b9c547cSRui Paulo 5615b9c547cSRui Paulo nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), 5625b9c547cSRui Paulo genlmsg_attrlen(gnlh, 0), NULL); 5635b9c547cSRui Paulo 564*780fb4a2SCy Schubert if (tb[NL80211_ATTR_WIPHY]) 565*780fb4a2SCy Schubert drv->wiphy_idx = nla_get_u32(tb[NL80211_ATTR_WIPHY]); 566*780fb4a2SCy Schubert 5675b9c547cSRui Paulo if (tb[NL80211_ATTR_WIPHY_NAME]) 5685b9c547cSRui Paulo os_strlcpy(drv->phyname, 5695b9c547cSRui Paulo nla_get_string(tb[NL80211_ATTR_WIPHY_NAME]), 5705b9c547cSRui Paulo sizeof(drv->phyname)); 5715b9c547cSRui Paulo if (tb[NL80211_ATTR_MAX_NUM_SCAN_SSIDS]) 5725b9c547cSRui Paulo capa->max_scan_ssids = 5735b9c547cSRui Paulo nla_get_u8(tb[NL80211_ATTR_MAX_NUM_SCAN_SSIDS]); 5745b9c547cSRui Paulo 5755b9c547cSRui Paulo if (tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS]) 5765b9c547cSRui Paulo capa->max_sched_scan_ssids = 5775b9c547cSRui Paulo nla_get_u8(tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS]); 5785b9c547cSRui Paulo 579*780fb4a2SCy Schubert if (tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS] && 580*780fb4a2SCy Schubert tb[NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL] && 581*780fb4a2SCy Schubert tb[NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS]) { 582*780fb4a2SCy Schubert capa->max_sched_scan_plans = 583*780fb4a2SCy Schubert nla_get_u32(tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS]); 584*780fb4a2SCy Schubert 585*780fb4a2SCy Schubert capa->max_sched_scan_plan_interval = 586*780fb4a2SCy Schubert nla_get_u32(tb[NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL]); 587*780fb4a2SCy Schubert 588*780fb4a2SCy Schubert capa->max_sched_scan_plan_iterations = 589*780fb4a2SCy Schubert nla_get_u32(tb[NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS]); 590*780fb4a2SCy Schubert } 591*780fb4a2SCy Schubert 5925b9c547cSRui Paulo if (tb[NL80211_ATTR_MAX_MATCH_SETS]) 5935b9c547cSRui Paulo capa->max_match_sets = 5945b9c547cSRui Paulo nla_get_u8(tb[NL80211_ATTR_MAX_MATCH_SETS]); 5955b9c547cSRui Paulo 5965b9c547cSRui Paulo if (tb[NL80211_ATTR_MAC_ACL_MAX]) 5975b9c547cSRui Paulo capa->max_acl_mac_addrs = 5985b9c547cSRui Paulo nla_get_u8(tb[NL80211_ATTR_MAC_ACL_MAX]); 5995b9c547cSRui Paulo 6005b9c547cSRui Paulo wiphy_info_supported_iftypes(info, tb[NL80211_ATTR_SUPPORTED_IFTYPES]); 6015b9c547cSRui Paulo wiphy_info_iface_comb(info, tb[NL80211_ATTR_INTERFACE_COMBINATIONS]); 6025b9c547cSRui Paulo wiphy_info_supp_cmds(info, tb[NL80211_ATTR_SUPPORTED_COMMANDS]); 6035b9c547cSRui Paulo wiphy_info_cipher_suites(info, tb[NL80211_ATTR_CIPHER_SUITES]); 6045b9c547cSRui Paulo 6055b9c547cSRui Paulo if (tb[NL80211_ATTR_OFFCHANNEL_TX_OK]) { 6065b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "nl80211: Using driver-based " 6075b9c547cSRui Paulo "off-channel TX"); 6085b9c547cSRui Paulo capa->flags |= WPA_DRIVER_FLAGS_OFFCHANNEL_TX; 6095b9c547cSRui Paulo } 6105b9c547cSRui Paulo 6115b9c547cSRui Paulo if (tb[NL80211_ATTR_ROAM_SUPPORT]) { 6125b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "nl80211: Using driver-based roaming"); 6135b9c547cSRui Paulo capa->flags |= WPA_DRIVER_FLAGS_BSS_SELECTION; 6145b9c547cSRui Paulo } 6155b9c547cSRui Paulo 6165b9c547cSRui Paulo wiphy_info_max_roc(capa, 6175b9c547cSRui Paulo tb[NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION]); 6185b9c547cSRui Paulo 6195b9c547cSRui Paulo if (tb[NL80211_ATTR_SUPPORT_AP_UAPSD]) 6205b9c547cSRui Paulo capa->flags |= WPA_DRIVER_FLAGS_AP_UAPSD; 6215b9c547cSRui Paulo 6225b9c547cSRui Paulo wiphy_info_tdls(capa, tb[NL80211_ATTR_TDLS_SUPPORT], 6235b9c547cSRui Paulo tb[NL80211_ATTR_TDLS_EXTERNAL_SETUP]); 6245b9c547cSRui Paulo 6255b9c547cSRui Paulo if (tb[NL80211_ATTR_DEVICE_AP_SME]) 6265b9c547cSRui Paulo info->device_ap_sme = 1; 6275b9c547cSRui Paulo 6285b9c547cSRui Paulo wiphy_info_feature_flags(info, tb[NL80211_ATTR_FEATURE_FLAGS]); 629325151a3SRui Paulo wiphy_info_ext_feature_flags(info, tb[NL80211_ATTR_EXT_FEATURES]); 6305b9c547cSRui Paulo wiphy_info_probe_resp_offload(capa, 6315b9c547cSRui Paulo tb[NL80211_ATTR_PROBE_RESP_OFFLOAD]); 6325b9c547cSRui Paulo 6335b9c547cSRui Paulo if (tb[NL80211_ATTR_EXT_CAPA] && tb[NL80211_ATTR_EXT_CAPA_MASK] && 6345b9c547cSRui Paulo drv->extended_capa == NULL) { 6355b9c547cSRui Paulo drv->extended_capa = 6365b9c547cSRui Paulo os_malloc(nla_len(tb[NL80211_ATTR_EXT_CAPA])); 6375b9c547cSRui Paulo if (drv->extended_capa) { 6385b9c547cSRui Paulo os_memcpy(drv->extended_capa, 6395b9c547cSRui Paulo nla_data(tb[NL80211_ATTR_EXT_CAPA]), 6405b9c547cSRui Paulo nla_len(tb[NL80211_ATTR_EXT_CAPA])); 6415b9c547cSRui Paulo drv->extended_capa_len = 6425b9c547cSRui Paulo nla_len(tb[NL80211_ATTR_EXT_CAPA]); 643*780fb4a2SCy Schubert wpa_hexdump(MSG_DEBUG, 644*780fb4a2SCy Schubert "nl80211: Driver-advertised extended capabilities (default)", 645*780fb4a2SCy Schubert drv->extended_capa, drv->extended_capa_len); 6465b9c547cSRui Paulo } 6475b9c547cSRui Paulo drv->extended_capa_mask = 6485b9c547cSRui Paulo os_malloc(nla_len(tb[NL80211_ATTR_EXT_CAPA_MASK])); 6495b9c547cSRui Paulo if (drv->extended_capa_mask) { 6505b9c547cSRui Paulo os_memcpy(drv->extended_capa_mask, 6515b9c547cSRui Paulo nla_data(tb[NL80211_ATTR_EXT_CAPA_MASK]), 6525b9c547cSRui Paulo nla_len(tb[NL80211_ATTR_EXT_CAPA_MASK])); 653*780fb4a2SCy Schubert wpa_hexdump(MSG_DEBUG, 654*780fb4a2SCy Schubert "nl80211: Driver-advertised extended capabilities mask (default)", 655*780fb4a2SCy Schubert drv->extended_capa_mask, 656*780fb4a2SCy Schubert drv->extended_capa_len); 6575b9c547cSRui Paulo } else { 6585b9c547cSRui Paulo os_free(drv->extended_capa); 6595b9c547cSRui Paulo drv->extended_capa = NULL; 6605b9c547cSRui Paulo drv->extended_capa_len = 0; 6615b9c547cSRui Paulo } 6625b9c547cSRui Paulo } 6635b9c547cSRui Paulo 664*780fb4a2SCy Schubert wiphy_info_extended_capab(drv, tb[NL80211_ATTR_IFTYPE_EXT_CAPA]); 665*780fb4a2SCy Schubert 6665b9c547cSRui Paulo if (tb[NL80211_ATTR_VENDOR_DATA]) { 6675b9c547cSRui Paulo struct nlattr *nl; 6685b9c547cSRui Paulo int rem; 6695b9c547cSRui Paulo 6705b9c547cSRui Paulo nla_for_each_nested(nl, tb[NL80211_ATTR_VENDOR_DATA], rem) { 6715b9c547cSRui Paulo struct nl80211_vendor_cmd_info *vinfo; 6725b9c547cSRui Paulo if (nla_len(nl) != sizeof(*vinfo)) { 6735b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "nl80211: Unexpected vendor data info"); 6745b9c547cSRui Paulo continue; 6755b9c547cSRui Paulo } 6765b9c547cSRui Paulo vinfo = nla_data(nl); 677325151a3SRui Paulo if (vinfo->vendor_id == OUI_QCA) { 6785b9c547cSRui Paulo switch (vinfo->subcmd) { 6795b9c547cSRui Paulo case QCA_NL80211_VENDOR_SUBCMD_TEST: 6805b9c547cSRui Paulo drv->vendor_cmd_test_avail = 1; 6815b9c547cSRui Paulo break; 682*780fb4a2SCy Schubert #ifdef CONFIG_DRIVER_NL80211_QCA 6835b9c547cSRui Paulo case QCA_NL80211_VENDOR_SUBCMD_ROAMING: 6845b9c547cSRui Paulo drv->roaming_vendor_cmd_avail = 1; 6855b9c547cSRui Paulo break; 6865b9c547cSRui Paulo case QCA_NL80211_VENDOR_SUBCMD_DFS_CAPABILITY: 6875b9c547cSRui Paulo drv->dfs_vendor_cmd_avail = 1; 6885b9c547cSRui Paulo break; 6895b9c547cSRui Paulo case QCA_NL80211_VENDOR_SUBCMD_GET_FEATURES: 6905b9c547cSRui Paulo drv->get_features_vendor_cmd_avail = 1; 6915b9c547cSRui Paulo break; 692325151a3SRui Paulo case QCA_NL80211_VENDOR_SUBCMD_GET_PREFERRED_FREQ_LIST: 693325151a3SRui Paulo drv->get_pref_freq_list = 1; 6945b9c547cSRui Paulo break; 695325151a3SRui Paulo case QCA_NL80211_VENDOR_SUBCMD_SET_PROBABLE_OPER_CHANNEL: 696325151a3SRui Paulo drv->set_prob_oper_freq = 1; 697325151a3SRui Paulo break; 698325151a3SRui Paulo case QCA_NL80211_VENDOR_SUBCMD_DO_ACS: 699325151a3SRui Paulo drv->capa.flags |= 700325151a3SRui Paulo WPA_DRIVER_FLAGS_ACS_OFFLOAD; 701325151a3SRui Paulo break; 702325151a3SRui Paulo case QCA_NL80211_VENDOR_SUBCMD_SETBAND: 703325151a3SRui Paulo drv->setband_vendor_cmd_avail = 1; 704325151a3SRui Paulo break; 705*780fb4a2SCy Schubert case QCA_NL80211_VENDOR_SUBCMD_TRIGGER_SCAN: 706*780fb4a2SCy Schubert drv->scan_vendor_cmd_avail = 1; 707*780fb4a2SCy Schubert break; 708*780fb4a2SCy Schubert case QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION: 709*780fb4a2SCy Schubert drv->set_wifi_conf_vendor_cmd_avail = 1; 710*780fb4a2SCy Schubert break; 711*780fb4a2SCy Schubert #endif /* CONFIG_DRIVER_NL80211_QCA */ 712325151a3SRui Paulo } 7135b9c547cSRui Paulo } 7145b9c547cSRui Paulo 7155b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "nl80211: Supported vendor command: vendor_id=0x%x subcmd=%u", 7165b9c547cSRui Paulo vinfo->vendor_id, vinfo->subcmd); 7175b9c547cSRui Paulo } 7185b9c547cSRui Paulo } 7195b9c547cSRui Paulo 7205b9c547cSRui Paulo if (tb[NL80211_ATTR_VENDOR_EVENTS]) { 7215b9c547cSRui Paulo struct nlattr *nl; 7225b9c547cSRui Paulo int rem; 7235b9c547cSRui Paulo 7245b9c547cSRui Paulo nla_for_each_nested(nl, tb[NL80211_ATTR_VENDOR_EVENTS], rem) { 7255b9c547cSRui Paulo struct nl80211_vendor_cmd_info *vinfo; 7265b9c547cSRui Paulo if (nla_len(nl) != sizeof(*vinfo)) { 7275b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "nl80211: Unexpected vendor data info"); 7285b9c547cSRui Paulo continue; 7295b9c547cSRui Paulo } 7305b9c547cSRui Paulo vinfo = nla_data(nl); 7315b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "nl80211: Supported vendor event: vendor_id=0x%x subcmd=%u", 7325b9c547cSRui Paulo vinfo->vendor_id, vinfo->subcmd); 7335b9c547cSRui Paulo } 7345b9c547cSRui Paulo } 7355b9c547cSRui Paulo 7365b9c547cSRui Paulo wiphy_info_wowlan_triggers(capa, 7375b9c547cSRui Paulo tb[NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED]); 7385b9c547cSRui Paulo 7395b9c547cSRui Paulo if (tb[NL80211_ATTR_MAX_AP_ASSOC_STA]) 7405b9c547cSRui Paulo capa->max_stations = 7415b9c547cSRui Paulo nla_get_u32(tb[NL80211_ATTR_MAX_AP_ASSOC_STA]); 7425b9c547cSRui Paulo 743*780fb4a2SCy Schubert if (tb[NL80211_ATTR_MAX_CSA_COUNTERS]) 744*780fb4a2SCy Schubert capa->max_csa_counters = 745*780fb4a2SCy Schubert nla_get_u8(tb[NL80211_ATTR_MAX_CSA_COUNTERS]); 746*780fb4a2SCy Schubert 7475b9c547cSRui Paulo return NL_SKIP; 7485b9c547cSRui Paulo } 7495b9c547cSRui Paulo 7505b9c547cSRui Paulo 7515b9c547cSRui Paulo static int wpa_driver_nl80211_get_info(struct wpa_driver_nl80211_data *drv, 7525b9c547cSRui Paulo struct wiphy_info_data *info) 7535b9c547cSRui Paulo { 7545b9c547cSRui Paulo u32 feat; 7555b9c547cSRui Paulo struct nl_msg *msg; 7565b9c547cSRui Paulo int flags = 0; 7575b9c547cSRui Paulo 7585b9c547cSRui Paulo os_memset(info, 0, sizeof(*info)); 7595b9c547cSRui Paulo info->capa = &drv->capa; 7605b9c547cSRui Paulo info->drv = drv; 7615b9c547cSRui Paulo 7625b9c547cSRui Paulo feat = get_nl80211_protocol_features(drv); 7635b9c547cSRui Paulo if (feat & NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP) 7645b9c547cSRui Paulo flags = NLM_F_DUMP; 7655b9c547cSRui Paulo msg = nl80211_cmd_msg(drv->first_bss, flags, NL80211_CMD_GET_WIPHY); 7665b9c547cSRui Paulo if (!msg || nla_put_flag(msg, NL80211_ATTR_SPLIT_WIPHY_DUMP)) { 7675b9c547cSRui Paulo nlmsg_free(msg); 7685b9c547cSRui Paulo return -1; 7695b9c547cSRui Paulo } 7705b9c547cSRui Paulo 7715b9c547cSRui Paulo if (send_and_recv_msgs(drv, msg, wiphy_info_handler, info)) 7725b9c547cSRui Paulo return -1; 7735b9c547cSRui Paulo 7745b9c547cSRui Paulo if (info->auth_supported) 7755b9c547cSRui Paulo drv->capa.flags |= WPA_DRIVER_FLAGS_SME; 7765b9c547cSRui Paulo else if (!info->connect_supported) { 7775b9c547cSRui Paulo wpa_printf(MSG_INFO, "nl80211: Driver does not support " 7785b9c547cSRui Paulo "authentication/association or connect commands"); 7795b9c547cSRui Paulo info->error = 1; 7805b9c547cSRui Paulo } 7815b9c547cSRui Paulo 7825b9c547cSRui Paulo if (info->p2p_go_supported && info->p2p_client_supported) 7835b9c547cSRui Paulo drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CAPABLE; 7845b9c547cSRui Paulo if (info->p2p_concurrent) { 7855b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group " 7865b9c547cSRui Paulo "interface (driver advertised support)"); 7875b9c547cSRui Paulo drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT; 7885b9c547cSRui Paulo drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P; 7895b9c547cSRui Paulo } 7905b9c547cSRui Paulo if (info->num_multichan_concurrent > 1) { 7915b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "nl80211: Enable multi-channel " 7925b9c547cSRui Paulo "concurrent (driver advertised support)"); 7935b9c547cSRui Paulo drv->capa.num_multichan_concurrent = 7945b9c547cSRui Paulo info->num_multichan_concurrent; 7955b9c547cSRui Paulo } 7965b9c547cSRui Paulo if (drv->capa.flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) 7975b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "nl80211: use P2P_DEVICE support"); 7985b9c547cSRui Paulo 7995b9c547cSRui Paulo /* default to 5000 since early versions of mac80211 don't set it */ 8005b9c547cSRui Paulo if (!drv->capa.max_remain_on_chan) 8015b9c547cSRui Paulo drv->capa.max_remain_on_chan = 5000; 8025b9c547cSRui Paulo 8035b9c547cSRui Paulo drv->capa.wmm_ac_supported = info->wmm_ac_supported; 8045b9c547cSRui Paulo 8055b9c547cSRui Paulo drv->capa.mac_addr_rand_sched_scan_supported = 8065b9c547cSRui Paulo info->mac_addr_rand_sched_scan_supported; 8075b9c547cSRui Paulo drv->capa.mac_addr_rand_scan_supported = 8085b9c547cSRui Paulo info->mac_addr_rand_scan_supported; 8095b9c547cSRui Paulo 810*780fb4a2SCy Schubert if (info->channel_switch_supported) { 811*780fb4a2SCy Schubert drv->capa.flags |= WPA_DRIVER_FLAGS_AP_CSA; 812*780fb4a2SCy Schubert if (!drv->capa.max_csa_counters) 813*780fb4a2SCy Schubert drv->capa.max_csa_counters = 1; 814*780fb4a2SCy Schubert } 815*780fb4a2SCy Schubert 816*780fb4a2SCy Schubert if (!drv->capa.max_sched_scan_plans) { 817*780fb4a2SCy Schubert drv->capa.max_sched_scan_plans = 1; 818*780fb4a2SCy Schubert drv->capa.max_sched_scan_plan_interval = UINT32_MAX; 819*780fb4a2SCy Schubert drv->capa.max_sched_scan_plan_iterations = 0; 820*780fb4a2SCy Schubert } 821*780fb4a2SCy Schubert 8225b9c547cSRui Paulo return 0; 8235b9c547cSRui Paulo } 8245b9c547cSRui Paulo 8255b9c547cSRui Paulo 826*780fb4a2SCy Schubert #ifdef CONFIG_DRIVER_NL80211_QCA 827*780fb4a2SCy Schubert 8285b9c547cSRui Paulo static int dfs_info_handler(struct nl_msg *msg, void *arg) 8295b9c547cSRui Paulo { 8305b9c547cSRui Paulo struct nlattr *tb[NL80211_ATTR_MAX + 1]; 8315b9c547cSRui Paulo struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); 8325b9c547cSRui Paulo int *dfs_capability_ptr = arg; 8335b9c547cSRui Paulo 8345b9c547cSRui Paulo nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), 8355b9c547cSRui Paulo genlmsg_attrlen(gnlh, 0), NULL); 8365b9c547cSRui Paulo 8375b9c547cSRui Paulo if (tb[NL80211_ATTR_VENDOR_DATA]) { 8385b9c547cSRui Paulo struct nlattr *nl_vend = tb[NL80211_ATTR_VENDOR_DATA]; 8395b9c547cSRui Paulo struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1]; 8405b9c547cSRui Paulo 8415b9c547cSRui Paulo nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX, 8425b9c547cSRui Paulo nla_data(nl_vend), nla_len(nl_vend), NULL); 8435b9c547cSRui Paulo 8445b9c547cSRui Paulo if (tb_vendor[QCA_WLAN_VENDOR_ATTR_DFS]) { 8455b9c547cSRui Paulo u32 val; 8465b9c547cSRui Paulo val = nla_get_u32(tb_vendor[QCA_WLAN_VENDOR_ATTR_DFS]); 8475b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "nl80211: DFS offload capability: %u", 8485b9c547cSRui Paulo val); 8495b9c547cSRui Paulo *dfs_capability_ptr = val; 8505b9c547cSRui Paulo } 8515b9c547cSRui Paulo } 8525b9c547cSRui Paulo 8535b9c547cSRui Paulo return NL_SKIP; 8545b9c547cSRui Paulo } 8555b9c547cSRui Paulo 8565b9c547cSRui Paulo 8575b9c547cSRui Paulo static void qca_nl80211_check_dfs_capa(struct wpa_driver_nl80211_data *drv) 8585b9c547cSRui Paulo { 8595b9c547cSRui Paulo struct nl_msg *msg; 8605b9c547cSRui Paulo int dfs_capability = 0; 8615b9c547cSRui Paulo int ret; 8625b9c547cSRui Paulo 8635b9c547cSRui Paulo if (!drv->dfs_vendor_cmd_avail) 8645b9c547cSRui Paulo return; 8655b9c547cSRui Paulo 8665b9c547cSRui Paulo if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || 8675b9c547cSRui Paulo nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || 8685b9c547cSRui Paulo nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, 8695b9c547cSRui Paulo QCA_NL80211_VENDOR_SUBCMD_DFS_CAPABILITY)) { 8705b9c547cSRui Paulo nlmsg_free(msg); 8715b9c547cSRui Paulo return; 8725b9c547cSRui Paulo } 8735b9c547cSRui Paulo 8745b9c547cSRui Paulo ret = send_and_recv_msgs(drv, msg, dfs_info_handler, &dfs_capability); 8755b9c547cSRui Paulo if (!ret && dfs_capability) 8765b9c547cSRui Paulo drv->capa.flags |= WPA_DRIVER_FLAGS_DFS_OFFLOAD; 8775b9c547cSRui Paulo } 8785b9c547cSRui Paulo 8795b9c547cSRui Paulo 8805b9c547cSRui Paulo struct features_info { 8815b9c547cSRui Paulo u8 *flags; 8825b9c547cSRui Paulo size_t flags_len; 883325151a3SRui Paulo struct wpa_driver_capa *capa; 8845b9c547cSRui Paulo }; 8855b9c547cSRui Paulo 8865b9c547cSRui Paulo 8875b9c547cSRui Paulo static int features_info_handler(struct nl_msg *msg, void *arg) 8885b9c547cSRui Paulo { 8895b9c547cSRui Paulo struct nlattr *tb[NL80211_ATTR_MAX + 1]; 8905b9c547cSRui Paulo struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); 8915b9c547cSRui Paulo struct features_info *info = arg; 8925b9c547cSRui Paulo struct nlattr *nl_vend, *attr; 8935b9c547cSRui Paulo 8945b9c547cSRui Paulo nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), 8955b9c547cSRui Paulo genlmsg_attrlen(gnlh, 0), NULL); 8965b9c547cSRui Paulo 8975b9c547cSRui Paulo nl_vend = tb[NL80211_ATTR_VENDOR_DATA]; 8985b9c547cSRui Paulo if (nl_vend) { 8995b9c547cSRui Paulo struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1]; 9005b9c547cSRui Paulo 9015b9c547cSRui Paulo nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX, 9025b9c547cSRui Paulo nla_data(nl_vend), nla_len(nl_vend), NULL); 9035b9c547cSRui Paulo 9045b9c547cSRui Paulo attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_FEATURE_FLAGS]; 9055b9c547cSRui Paulo if (attr) { 906*780fb4a2SCy Schubert int len = nla_len(attr); 907*780fb4a2SCy Schubert info->flags = os_malloc(len); 908*780fb4a2SCy Schubert if (info->flags != NULL) { 909*780fb4a2SCy Schubert os_memcpy(info->flags, nla_data(attr), len); 910*780fb4a2SCy Schubert info->flags_len = len; 911*780fb4a2SCy Schubert } 9125b9c547cSRui Paulo } 913325151a3SRui Paulo attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_CONCURRENCY_CAPA]; 914325151a3SRui Paulo if (attr) 915325151a3SRui Paulo info->capa->conc_capab = nla_get_u32(attr); 916325151a3SRui Paulo 917325151a3SRui Paulo attr = tb_vendor[ 918325151a3SRui Paulo QCA_WLAN_VENDOR_ATTR_MAX_CONCURRENT_CHANNELS_2_4_BAND]; 919325151a3SRui Paulo if (attr) 920325151a3SRui Paulo info->capa->max_conc_chan_2_4 = nla_get_u32(attr); 921325151a3SRui Paulo 922325151a3SRui Paulo attr = tb_vendor[ 923325151a3SRui Paulo QCA_WLAN_VENDOR_ATTR_MAX_CONCURRENT_CHANNELS_5_0_BAND]; 924325151a3SRui Paulo if (attr) 925325151a3SRui Paulo info->capa->max_conc_chan_5_0 = nla_get_u32(attr); 9265b9c547cSRui Paulo } 9275b9c547cSRui Paulo 9285b9c547cSRui Paulo return NL_SKIP; 9295b9c547cSRui Paulo } 9305b9c547cSRui Paulo 9315b9c547cSRui Paulo 9325b9c547cSRui Paulo static int check_feature(enum qca_wlan_vendor_features feature, 9335b9c547cSRui Paulo struct features_info *info) 9345b9c547cSRui Paulo { 9355b9c547cSRui Paulo size_t idx = feature / 8; 9365b9c547cSRui Paulo 9375b9c547cSRui Paulo return (idx < info->flags_len) && 9385b9c547cSRui Paulo (info->flags[idx] & BIT(feature % 8)); 9395b9c547cSRui Paulo } 9405b9c547cSRui Paulo 9415b9c547cSRui Paulo 9425b9c547cSRui Paulo static void qca_nl80211_get_features(struct wpa_driver_nl80211_data *drv) 9435b9c547cSRui Paulo { 9445b9c547cSRui Paulo struct nl_msg *msg; 9455b9c547cSRui Paulo struct features_info info; 9465b9c547cSRui Paulo int ret; 9475b9c547cSRui Paulo 9485b9c547cSRui Paulo if (!drv->get_features_vendor_cmd_avail) 9495b9c547cSRui Paulo return; 9505b9c547cSRui Paulo 9515b9c547cSRui Paulo if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || 9525b9c547cSRui Paulo nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || 9535b9c547cSRui Paulo nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, 9545b9c547cSRui Paulo QCA_NL80211_VENDOR_SUBCMD_GET_FEATURES)) { 9555b9c547cSRui Paulo nlmsg_free(msg); 9565b9c547cSRui Paulo return; 9575b9c547cSRui Paulo } 9585b9c547cSRui Paulo 9595b9c547cSRui Paulo os_memset(&info, 0, sizeof(info)); 960325151a3SRui Paulo info.capa = &drv->capa; 9615b9c547cSRui Paulo ret = send_and_recv_msgs(drv, msg, features_info_handler, &info); 9625b9c547cSRui Paulo if (ret || !info.flags) 9635b9c547cSRui Paulo return; 9645b9c547cSRui Paulo 9655b9c547cSRui Paulo if (check_feature(QCA_WLAN_VENDOR_FEATURE_KEY_MGMT_OFFLOAD, &info)) 9665b9c547cSRui Paulo drv->capa.flags |= WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD; 967325151a3SRui Paulo 968325151a3SRui Paulo if (check_feature(QCA_WLAN_VENDOR_FEATURE_SUPPORT_HW_MODE_ANY, &info)) 969325151a3SRui Paulo drv->capa.flags |= WPA_DRIVER_FLAGS_SUPPORT_HW_MODE_ANY; 970*780fb4a2SCy Schubert 971*780fb4a2SCy Schubert if (check_feature(QCA_WLAN_VENDOR_FEATURE_OFFCHANNEL_SIMULTANEOUS, 972*780fb4a2SCy Schubert &info)) 973*780fb4a2SCy Schubert drv->capa.flags |= WPA_DRIVER_FLAGS_OFFCHANNEL_SIMULTANEOUS; 974*780fb4a2SCy Schubert if (check_feature(QCA_WLAN_VENDOR_FEATURE_P2P_LISTEN_OFFLOAD, &info)) 975*780fb4a2SCy Schubert drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD; 976*780fb4a2SCy Schubert os_free(info.flags); 9775b9c547cSRui Paulo } 9785b9c547cSRui Paulo 979*780fb4a2SCy Schubert #endif /* CONFIG_DRIVER_NL80211_QCA */ 980*780fb4a2SCy Schubert 9815b9c547cSRui Paulo 9825b9c547cSRui Paulo int wpa_driver_nl80211_capa(struct wpa_driver_nl80211_data *drv) 9835b9c547cSRui Paulo { 9845b9c547cSRui Paulo struct wiphy_info_data info; 9855b9c547cSRui Paulo if (wpa_driver_nl80211_get_info(drv, &info)) 9865b9c547cSRui Paulo return -1; 9875b9c547cSRui Paulo 9885b9c547cSRui Paulo if (info.error) 9895b9c547cSRui Paulo return -1; 9905b9c547cSRui Paulo 9915b9c547cSRui Paulo drv->has_capability = 1; 9925b9c547cSRui Paulo drv->capa.key_mgmt = WPA_DRIVER_CAPA_KEY_MGMT_WPA | 9935b9c547cSRui Paulo WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK | 9945b9c547cSRui Paulo WPA_DRIVER_CAPA_KEY_MGMT_WPA2 | 9955b9c547cSRui Paulo WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK | 9965b9c547cSRui Paulo WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B | 9975b9c547cSRui Paulo WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192; 9985b9c547cSRui Paulo drv->capa.auth = WPA_DRIVER_AUTH_OPEN | 9995b9c547cSRui Paulo WPA_DRIVER_AUTH_SHARED | 10005b9c547cSRui Paulo WPA_DRIVER_AUTH_LEAP; 10015b9c547cSRui Paulo 10025b9c547cSRui Paulo drv->capa.flags |= WPA_DRIVER_FLAGS_SANE_ERROR_CODES; 10035b9c547cSRui Paulo drv->capa.flags |= WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE; 10045b9c547cSRui Paulo drv->capa.flags |= WPA_DRIVER_FLAGS_EAPOL_TX_STATUS; 10055b9c547cSRui Paulo 10065b9c547cSRui Paulo /* 10075b9c547cSRui Paulo * As all cfg80211 drivers must support cases where the AP interface is 10085b9c547cSRui Paulo * removed without the knowledge of wpa_supplicant/hostapd, e.g., in 10095b9c547cSRui Paulo * case that the user space daemon has crashed, they must be able to 10105b9c547cSRui Paulo * cleanup all stations and key entries in the AP tear down flow. Thus, 10115b9c547cSRui Paulo * this flag can/should always be set for cfg80211 drivers. 10125b9c547cSRui Paulo */ 10135b9c547cSRui Paulo drv->capa.flags |= WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT; 10145b9c547cSRui Paulo 10155b9c547cSRui Paulo if (!info.device_ap_sme) { 10165b9c547cSRui Paulo drv->capa.flags |= WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS; 10175b9c547cSRui Paulo 10185b9c547cSRui Paulo /* 10195b9c547cSRui Paulo * No AP SME is currently assumed to also indicate no AP MLME 10205b9c547cSRui Paulo * in the driver/firmware. 10215b9c547cSRui Paulo */ 10225b9c547cSRui Paulo drv->capa.flags |= WPA_DRIVER_FLAGS_AP_MLME; 10235b9c547cSRui Paulo } 10245b9c547cSRui Paulo 10255b9c547cSRui Paulo drv->device_ap_sme = info.device_ap_sme; 10265b9c547cSRui Paulo drv->poll_command_supported = info.poll_command_supported; 10275b9c547cSRui Paulo drv->data_tx_status = info.data_tx_status; 10285b9c547cSRui Paulo drv->p2p_go_ctwindow_supported = info.p2p_go_ctwindow_supported; 10295b9c547cSRui Paulo if (info.set_qos_map_supported) 10305b9c547cSRui Paulo drv->capa.flags |= WPA_DRIVER_FLAGS_QOS_MAPPING; 10315b9c547cSRui Paulo drv->have_low_prio_scan = info.have_low_prio_scan; 10325b9c547cSRui Paulo 10335b9c547cSRui Paulo /* 10345b9c547cSRui Paulo * If poll command and tx status are supported, mac80211 is new enough 10355b9c547cSRui Paulo * to have everything we need to not need monitor interfaces. 10365b9c547cSRui Paulo */ 1037*780fb4a2SCy Schubert drv->use_monitor = !info.device_ap_sme && 1038*780fb4a2SCy Schubert (!info.poll_command_supported || !info.data_tx_status); 10395b9c547cSRui Paulo 10405b9c547cSRui Paulo /* 10415b9c547cSRui Paulo * If we aren't going to use monitor interfaces, but the 10425b9c547cSRui Paulo * driver doesn't support data TX status, we won't get TX 10435b9c547cSRui Paulo * status for EAPOL frames. 10445b9c547cSRui Paulo */ 10455b9c547cSRui Paulo if (!drv->use_monitor && !info.data_tx_status) 10465b9c547cSRui Paulo drv->capa.flags &= ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS; 10475b9c547cSRui Paulo 1048*780fb4a2SCy Schubert #ifdef CONFIG_DRIVER_NL80211_QCA 10495b9c547cSRui Paulo qca_nl80211_check_dfs_capa(drv); 10505b9c547cSRui Paulo qca_nl80211_get_features(drv); 10515b9c547cSRui Paulo 1052*780fb4a2SCy Schubert /* 1053*780fb4a2SCy Schubert * To enable offchannel simultaneous support in wpa_supplicant, the 1054*780fb4a2SCy Schubert * underlying driver needs to support the same along with offchannel TX. 1055*780fb4a2SCy Schubert * Offchannel TX support is needed since remain_on_channel and 1056*780fb4a2SCy Schubert * action_tx use some common data structures and hence cannot be 1057*780fb4a2SCy Schubert * scheduled simultaneously. 1058*780fb4a2SCy Schubert */ 1059*780fb4a2SCy Schubert if (!(drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX)) 1060*780fb4a2SCy Schubert drv->capa.flags &= ~WPA_DRIVER_FLAGS_OFFCHANNEL_SIMULTANEOUS; 1061*780fb4a2SCy Schubert #endif /* CONFIG_DRIVER_NL80211_QCA */ 1062*780fb4a2SCy Schubert 10635b9c547cSRui Paulo return 0; 10645b9c547cSRui Paulo } 10655b9c547cSRui Paulo 10665b9c547cSRui Paulo 10675b9c547cSRui Paulo struct phy_info_arg { 10685b9c547cSRui Paulo u16 *num_modes; 10695b9c547cSRui Paulo struct hostapd_hw_modes *modes; 10705b9c547cSRui Paulo int last_mode, last_chan_idx; 1071*780fb4a2SCy Schubert int failed; 10725b9c547cSRui Paulo }; 10735b9c547cSRui Paulo 10745b9c547cSRui Paulo static void phy_info_ht_capa(struct hostapd_hw_modes *mode, struct nlattr *capa, 10755b9c547cSRui Paulo struct nlattr *ampdu_factor, 10765b9c547cSRui Paulo struct nlattr *ampdu_density, 10775b9c547cSRui Paulo struct nlattr *mcs_set) 10785b9c547cSRui Paulo { 10795b9c547cSRui Paulo if (capa) 10805b9c547cSRui Paulo mode->ht_capab = nla_get_u16(capa); 10815b9c547cSRui Paulo 10825b9c547cSRui Paulo if (ampdu_factor) 10835b9c547cSRui Paulo mode->a_mpdu_params |= nla_get_u8(ampdu_factor) & 0x03; 10845b9c547cSRui Paulo 10855b9c547cSRui Paulo if (ampdu_density) 10865b9c547cSRui Paulo mode->a_mpdu_params |= nla_get_u8(ampdu_density) << 2; 10875b9c547cSRui Paulo 10885b9c547cSRui Paulo if (mcs_set && nla_len(mcs_set) >= 16) { 10895b9c547cSRui Paulo u8 *mcs; 10905b9c547cSRui Paulo mcs = nla_data(mcs_set); 10915b9c547cSRui Paulo os_memcpy(mode->mcs_set, mcs, 16); 10925b9c547cSRui Paulo } 10935b9c547cSRui Paulo } 10945b9c547cSRui Paulo 10955b9c547cSRui Paulo 10965b9c547cSRui Paulo static void phy_info_vht_capa(struct hostapd_hw_modes *mode, 10975b9c547cSRui Paulo struct nlattr *capa, 10985b9c547cSRui Paulo struct nlattr *mcs_set) 10995b9c547cSRui Paulo { 11005b9c547cSRui Paulo if (capa) 11015b9c547cSRui Paulo mode->vht_capab = nla_get_u32(capa); 11025b9c547cSRui Paulo 11035b9c547cSRui Paulo if (mcs_set && nla_len(mcs_set) >= 8) { 11045b9c547cSRui Paulo u8 *mcs; 11055b9c547cSRui Paulo mcs = nla_data(mcs_set); 11065b9c547cSRui Paulo os_memcpy(mode->vht_mcs_set, mcs, 8); 11075b9c547cSRui Paulo } 11085b9c547cSRui Paulo } 11095b9c547cSRui Paulo 11105b9c547cSRui Paulo 11115b9c547cSRui Paulo static void phy_info_freq(struct hostapd_hw_modes *mode, 11125b9c547cSRui Paulo struct hostapd_channel_data *chan, 11135b9c547cSRui Paulo struct nlattr *tb_freq[]) 11145b9c547cSRui Paulo { 11155b9c547cSRui Paulo u8 channel; 11165b9c547cSRui Paulo chan->freq = nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_FREQ]); 11175b9c547cSRui Paulo chan->flag = 0; 11185b9c547cSRui Paulo chan->dfs_cac_ms = 0; 11195b9c547cSRui Paulo if (ieee80211_freq_to_chan(chan->freq, &channel) != NUM_HOSTAPD_MODES) 11205b9c547cSRui Paulo chan->chan = channel; 11215b9c547cSRui Paulo 11225b9c547cSRui Paulo if (tb_freq[NL80211_FREQUENCY_ATTR_DISABLED]) 11235b9c547cSRui Paulo chan->flag |= HOSTAPD_CHAN_DISABLED; 11245b9c547cSRui Paulo if (tb_freq[NL80211_FREQUENCY_ATTR_NO_IR]) 11255b9c547cSRui Paulo chan->flag |= HOSTAPD_CHAN_NO_IR; 11265b9c547cSRui Paulo if (tb_freq[NL80211_FREQUENCY_ATTR_RADAR]) 11275b9c547cSRui Paulo chan->flag |= HOSTAPD_CHAN_RADAR; 11285b9c547cSRui Paulo if (tb_freq[NL80211_FREQUENCY_ATTR_INDOOR_ONLY]) 11295b9c547cSRui Paulo chan->flag |= HOSTAPD_CHAN_INDOOR_ONLY; 11305b9c547cSRui Paulo if (tb_freq[NL80211_FREQUENCY_ATTR_GO_CONCURRENT]) 11315b9c547cSRui Paulo chan->flag |= HOSTAPD_CHAN_GO_CONCURRENT; 11325b9c547cSRui Paulo 11335b9c547cSRui Paulo if (tb_freq[NL80211_FREQUENCY_ATTR_DFS_STATE]) { 11345b9c547cSRui Paulo enum nl80211_dfs_state state = 11355b9c547cSRui Paulo nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_DFS_STATE]); 11365b9c547cSRui Paulo 11375b9c547cSRui Paulo switch (state) { 11385b9c547cSRui Paulo case NL80211_DFS_USABLE: 11395b9c547cSRui Paulo chan->flag |= HOSTAPD_CHAN_DFS_USABLE; 11405b9c547cSRui Paulo break; 11415b9c547cSRui Paulo case NL80211_DFS_AVAILABLE: 11425b9c547cSRui Paulo chan->flag |= HOSTAPD_CHAN_DFS_AVAILABLE; 11435b9c547cSRui Paulo break; 11445b9c547cSRui Paulo case NL80211_DFS_UNAVAILABLE: 11455b9c547cSRui Paulo chan->flag |= HOSTAPD_CHAN_DFS_UNAVAILABLE; 11465b9c547cSRui Paulo break; 11475b9c547cSRui Paulo } 11485b9c547cSRui Paulo } 11495b9c547cSRui Paulo 11505b9c547cSRui Paulo if (tb_freq[NL80211_FREQUENCY_ATTR_DFS_CAC_TIME]) { 11515b9c547cSRui Paulo chan->dfs_cac_ms = nla_get_u32( 11525b9c547cSRui Paulo tb_freq[NL80211_FREQUENCY_ATTR_DFS_CAC_TIME]); 11535b9c547cSRui Paulo } 11545b9c547cSRui Paulo } 11555b9c547cSRui Paulo 11565b9c547cSRui Paulo 11575b9c547cSRui Paulo static int phy_info_freqs(struct phy_info_arg *phy_info, 11585b9c547cSRui Paulo struct hostapd_hw_modes *mode, struct nlattr *tb) 11595b9c547cSRui Paulo { 11605b9c547cSRui Paulo static struct nla_policy freq_policy[NL80211_FREQUENCY_ATTR_MAX + 1] = { 11615b9c547cSRui Paulo [NL80211_FREQUENCY_ATTR_FREQ] = { .type = NLA_U32 }, 11625b9c547cSRui Paulo [NL80211_FREQUENCY_ATTR_DISABLED] = { .type = NLA_FLAG }, 11635b9c547cSRui Paulo [NL80211_FREQUENCY_ATTR_NO_IR] = { .type = NLA_FLAG }, 11645b9c547cSRui Paulo [NL80211_FREQUENCY_ATTR_RADAR] = { .type = NLA_FLAG }, 11655b9c547cSRui Paulo [NL80211_FREQUENCY_ATTR_MAX_TX_POWER] = { .type = NLA_U32 }, 11665b9c547cSRui Paulo [NL80211_FREQUENCY_ATTR_DFS_STATE] = { .type = NLA_U32 }, 11675b9c547cSRui Paulo }; 11685b9c547cSRui Paulo int new_channels = 0; 11695b9c547cSRui Paulo struct hostapd_channel_data *channel; 11705b9c547cSRui Paulo struct nlattr *tb_freq[NL80211_FREQUENCY_ATTR_MAX + 1]; 11715b9c547cSRui Paulo struct nlattr *nl_freq; 11725b9c547cSRui Paulo int rem_freq, idx; 11735b9c547cSRui Paulo 11745b9c547cSRui Paulo if (tb == NULL) 11755b9c547cSRui Paulo return NL_OK; 11765b9c547cSRui Paulo 11775b9c547cSRui Paulo nla_for_each_nested(nl_freq, tb, rem_freq) { 11785b9c547cSRui Paulo nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX, 11795b9c547cSRui Paulo nla_data(nl_freq), nla_len(nl_freq), freq_policy); 11805b9c547cSRui Paulo if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ]) 11815b9c547cSRui Paulo continue; 11825b9c547cSRui Paulo new_channels++; 11835b9c547cSRui Paulo } 11845b9c547cSRui Paulo 11855b9c547cSRui Paulo channel = os_realloc_array(mode->channels, 11865b9c547cSRui Paulo mode->num_channels + new_channels, 11875b9c547cSRui Paulo sizeof(struct hostapd_channel_data)); 11885b9c547cSRui Paulo if (!channel) 1189*780fb4a2SCy Schubert return NL_STOP; 11905b9c547cSRui Paulo 11915b9c547cSRui Paulo mode->channels = channel; 11925b9c547cSRui Paulo mode->num_channels += new_channels; 11935b9c547cSRui Paulo 11945b9c547cSRui Paulo idx = phy_info->last_chan_idx; 11955b9c547cSRui Paulo 11965b9c547cSRui Paulo nla_for_each_nested(nl_freq, tb, rem_freq) { 11975b9c547cSRui Paulo nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX, 11985b9c547cSRui Paulo nla_data(nl_freq), nla_len(nl_freq), freq_policy); 11995b9c547cSRui Paulo if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ]) 12005b9c547cSRui Paulo continue; 12015b9c547cSRui Paulo phy_info_freq(mode, &mode->channels[idx], tb_freq); 12025b9c547cSRui Paulo idx++; 12035b9c547cSRui Paulo } 12045b9c547cSRui Paulo phy_info->last_chan_idx = idx; 12055b9c547cSRui Paulo 12065b9c547cSRui Paulo return NL_OK; 12075b9c547cSRui Paulo } 12085b9c547cSRui Paulo 12095b9c547cSRui Paulo 12105b9c547cSRui Paulo static int phy_info_rates(struct hostapd_hw_modes *mode, struct nlattr *tb) 12115b9c547cSRui Paulo { 12125b9c547cSRui Paulo static struct nla_policy rate_policy[NL80211_BITRATE_ATTR_MAX + 1] = { 12135b9c547cSRui Paulo [NL80211_BITRATE_ATTR_RATE] = { .type = NLA_U32 }, 12145b9c547cSRui Paulo [NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE] = 12155b9c547cSRui Paulo { .type = NLA_FLAG }, 12165b9c547cSRui Paulo }; 12175b9c547cSRui Paulo struct nlattr *tb_rate[NL80211_BITRATE_ATTR_MAX + 1]; 12185b9c547cSRui Paulo struct nlattr *nl_rate; 12195b9c547cSRui Paulo int rem_rate, idx; 12205b9c547cSRui Paulo 12215b9c547cSRui Paulo if (tb == NULL) 12225b9c547cSRui Paulo return NL_OK; 12235b9c547cSRui Paulo 12245b9c547cSRui Paulo nla_for_each_nested(nl_rate, tb, rem_rate) { 12255b9c547cSRui Paulo nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX, 12265b9c547cSRui Paulo nla_data(nl_rate), nla_len(nl_rate), 12275b9c547cSRui Paulo rate_policy); 12285b9c547cSRui Paulo if (!tb_rate[NL80211_BITRATE_ATTR_RATE]) 12295b9c547cSRui Paulo continue; 12305b9c547cSRui Paulo mode->num_rates++; 12315b9c547cSRui Paulo } 12325b9c547cSRui Paulo 12335b9c547cSRui Paulo mode->rates = os_calloc(mode->num_rates, sizeof(int)); 12345b9c547cSRui Paulo if (!mode->rates) 1235*780fb4a2SCy Schubert return NL_STOP; 12365b9c547cSRui Paulo 12375b9c547cSRui Paulo idx = 0; 12385b9c547cSRui Paulo 12395b9c547cSRui Paulo nla_for_each_nested(nl_rate, tb, rem_rate) { 12405b9c547cSRui Paulo nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX, 12415b9c547cSRui Paulo nla_data(nl_rate), nla_len(nl_rate), 12425b9c547cSRui Paulo rate_policy); 12435b9c547cSRui Paulo if (!tb_rate[NL80211_BITRATE_ATTR_RATE]) 12445b9c547cSRui Paulo continue; 12455b9c547cSRui Paulo mode->rates[idx] = nla_get_u32( 12465b9c547cSRui Paulo tb_rate[NL80211_BITRATE_ATTR_RATE]); 12475b9c547cSRui Paulo idx++; 12485b9c547cSRui Paulo } 12495b9c547cSRui Paulo 12505b9c547cSRui Paulo return NL_OK; 12515b9c547cSRui Paulo } 12525b9c547cSRui Paulo 12535b9c547cSRui Paulo 12545b9c547cSRui Paulo static int phy_info_band(struct phy_info_arg *phy_info, struct nlattr *nl_band) 12555b9c547cSRui Paulo { 12565b9c547cSRui Paulo struct nlattr *tb_band[NL80211_BAND_ATTR_MAX + 1]; 12575b9c547cSRui Paulo struct hostapd_hw_modes *mode; 12585b9c547cSRui Paulo int ret; 12595b9c547cSRui Paulo 12605b9c547cSRui Paulo if (phy_info->last_mode != nl_band->nla_type) { 12615b9c547cSRui Paulo mode = os_realloc_array(phy_info->modes, 12625b9c547cSRui Paulo *phy_info->num_modes + 1, 12635b9c547cSRui Paulo sizeof(*mode)); 1264*780fb4a2SCy Schubert if (!mode) { 1265*780fb4a2SCy Schubert phy_info->failed = 1; 1266*780fb4a2SCy Schubert return NL_STOP; 1267*780fb4a2SCy Schubert } 12685b9c547cSRui Paulo phy_info->modes = mode; 12695b9c547cSRui Paulo 12705b9c547cSRui Paulo mode = &phy_info->modes[*(phy_info->num_modes)]; 12715b9c547cSRui Paulo os_memset(mode, 0, sizeof(*mode)); 12725b9c547cSRui Paulo mode->mode = NUM_HOSTAPD_MODES; 12735b9c547cSRui Paulo mode->flags = HOSTAPD_MODE_FLAG_HT_INFO_KNOWN | 12745b9c547cSRui Paulo HOSTAPD_MODE_FLAG_VHT_INFO_KNOWN; 12755b9c547cSRui Paulo 12765b9c547cSRui Paulo /* 12775b9c547cSRui Paulo * Unsupported VHT MCS stream is defined as value 3, so the VHT 12785b9c547cSRui Paulo * MCS RX/TX map must be initialized with 0xffff to mark all 8 12795b9c547cSRui Paulo * possible streams as unsupported. This will be overridden if 12805b9c547cSRui Paulo * driver advertises VHT support. 12815b9c547cSRui Paulo */ 12825b9c547cSRui Paulo mode->vht_mcs_set[0] = 0xff; 12835b9c547cSRui Paulo mode->vht_mcs_set[1] = 0xff; 12845b9c547cSRui Paulo mode->vht_mcs_set[4] = 0xff; 12855b9c547cSRui Paulo mode->vht_mcs_set[5] = 0xff; 12865b9c547cSRui Paulo 12875b9c547cSRui Paulo *(phy_info->num_modes) += 1; 12885b9c547cSRui Paulo phy_info->last_mode = nl_band->nla_type; 12895b9c547cSRui Paulo phy_info->last_chan_idx = 0; 12905b9c547cSRui Paulo } else 12915b9c547cSRui Paulo mode = &phy_info->modes[*(phy_info->num_modes) - 1]; 12925b9c547cSRui Paulo 12935b9c547cSRui Paulo nla_parse(tb_band, NL80211_BAND_ATTR_MAX, nla_data(nl_band), 12945b9c547cSRui Paulo nla_len(nl_band), NULL); 12955b9c547cSRui Paulo 12965b9c547cSRui Paulo phy_info_ht_capa(mode, tb_band[NL80211_BAND_ATTR_HT_CAPA], 12975b9c547cSRui Paulo tb_band[NL80211_BAND_ATTR_HT_AMPDU_FACTOR], 12985b9c547cSRui Paulo tb_band[NL80211_BAND_ATTR_HT_AMPDU_DENSITY], 12995b9c547cSRui Paulo tb_band[NL80211_BAND_ATTR_HT_MCS_SET]); 13005b9c547cSRui Paulo phy_info_vht_capa(mode, tb_band[NL80211_BAND_ATTR_VHT_CAPA], 13015b9c547cSRui Paulo tb_band[NL80211_BAND_ATTR_VHT_MCS_SET]); 13025b9c547cSRui Paulo ret = phy_info_freqs(phy_info, mode, tb_band[NL80211_BAND_ATTR_FREQS]); 1303*780fb4a2SCy Schubert if (ret == NL_OK) 13045b9c547cSRui Paulo ret = phy_info_rates(mode, tb_band[NL80211_BAND_ATTR_RATES]); 1305*780fb4a2SCy Schubert if (ret != NL_OK) { 1306*780fb4a2SCy Schubert phy_info->failed = 1; 13075b9c547cSRui Paulo return ret; 1308*780fb4a2SCy Schubert } 13095b9c547cSRui Paulo 13105b9c547cSRui Paulo return NL_OK; 13115b9c547cSRui Paulo } 13125b9c547cSRui Paulo 13135b9c547cSRui Paulo 13145b9c547cSRui Paulo static int phy_info_handler(struct nl_msg *msg, void *arg) 13155b9c547cSRui Paulo { 13165b9c547cSRui Paulo struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; 13175b9c547cSRui Paulo struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); 13185b9c547cSRui Paulo struct phy_info_arg *phy_info = arg; 13195b9c547cSRui Paulo struct nlattr *nl_band; 13205b9c547cSRui Paulo int rem_band; 13215b9c547cSRui Paulo 13225b9c547cSRui Paulo nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), 13235b9c547cSRui Paulo genlmsg_attrlen(gnlh, 0), NULL); 13245b9c547cSRui Paulo 13255b9c547cSRui Paulo if (!tb_msg[NL80211_ATTR_WIPHY_BANDS]) 13265b9c547cSRui Paulo return NL_SKIP; 13275b9c547cSRui Paulo 13285b9c547cSRui Paulo nla_for_each_nested(nl_band, tb_msg[NL80211_ATTR_WIPHY_BANDS], rem_band) 13295b9c547cSRui Paulo { 13305b9c547cSRui Paulo int res = phy_info_band(phy_info, nl_band); 13315b9c547cSRui Paulo if (res != NL_OK) 13325b9c547cSRui Paulo return res; 13335b9c547cSRui Paulo } 13345b9c547cSRui Paulo 13355b9c547cSRui Paulo return NL_SKIP; 13365b9c547cSRui Paulo } 13375b9c547cSRui Paulo 13385b9c547cSRui Paulo 13395b9c547cSRui Paulo static struct hostapd_hw_modes * 13405b9c547cSRui Paulo wpa_driver_nl80211_postprocess_modes(struct hostapd_hw_modes *modes, 13415b9c547cSRui Paulo u16 *num_modes) 13425b9c547cSRui Paulo { 13435b9c547cSRui Paulo u16 m; 13445b9c547cSRui Paulo struct hostapd_hw_modes *mode11g = NULL, *nmodes, *mode; 13455b9c547cSRui Paulo int i, mode11g_idx = -1; 13465b9c547cSRui Paulo 13475b9c547cSRui Paulo /* heuristic to set up modes */ 13485b9c547cSRui Paulo for (m = 0; m < *num_modes; m++) { 13495b9c547cSRui Paulo if (!modes[m].num_channels) 13505b9c547cSRui Paulo continue; 13515b9c547cSRui Paulo if (modes[m].channels[0].freq < 4000) { 13525b9c547cSRui Paulo modes[m].mode = HOSTAPD_MODE_IEEE80211B; 13535b9c547cSRui Paulo for (i = 0; i < modes[m].num_rates; i++) { 13545b9c547cSRui Paulo if (modes[m].rates[i] > 200) { 13555b9c547cSRui Paulo modes[m].mode = HOSTAPD_MODE_IEEE80211G; 13565b9c547cSRui Paulo break; 13575b9c547cSRui Paulo } 13585b9c547cSRui Paulo } 13595b9c547cSRui Paulo } else if (modes[m].channels[0].freq > 50000) 13605b9c547cSRui Paulo modes[m].mode = HOSTAPD_MODE_IEEE80211AD; 13615b9c547cSRui Paulo else 13625b9c547cSRui Paulo modes[m].mode = HOSTAPD_MODE_IEEE80211A; 13635b9c547cSRui Paulo } 13645b9c547cSRui Paulo 13655b9c547cSRui Paulo /* If only 802.11g mode is included, use it to construct matching 13665b9c547cSRui Paulo * 802.11b mode data. */ 13675b9c547cSRui Paulo 13685b9c547cSRui Paulo for (m = 0; m < *num_modes; m++) { 13695b9c547cSRui Paulo if (modes[m].mode == HOSTAPD_MODE_IEEE80211B) 13705b9c547cSRui Paulo return modes; /* 802.11b already included */ 13715b9c547cSRui Paulo if (modes[m].mode == HOSTAPD_MODE_IEEE80211G) 13725b9c547cSRui Paulo mode11g_idx = m; 13735b9c547cSRui Paulo } 13745b9c547cSRui Paulo 13755b9c547cSRui Paulo if (mode11g_idx < 0) 13765b9c547cSRui Paulo return modes; /* 2.4 GHz band not supported at all */ 13775b9c547cSRui Paulo 13785b9c547cSRui Paulo nmodes = os_realloc_array(modes, *num_modes + 1, sizeof(*nmodes)); 13795b9c547cSRui Paulo if (nmodes == NULL) 13805b9c547cSRui Paulo return modes; /* Could not add 802.11b mode */ 13815b9c547cSRui Paulo 13825b9c547cSRui Paulo mode = &nmodes[*num_modes]; 13835b9c547cSRui Paulo os_memset(mode, 0, sizeof(*mode)); 13845b9c547cSRui Paulo (*num_modes)++; 13855b9c547cSRui Paulo modes = nmodes; 13865b9c547cSRui Paulo 13875b9c547cSRui Paulo mode->mode = HOSTAPD_MODE_IEEE80211B; 13885b9c547cSRui Paulo 13895b9c547cSRui Paulo mode11g = &modes[mode11g_idx]; 13905b9c547cSRui Paulo mode->num_channels = mode11g->num_channels; 13915b9c547cSRui Paulo mode->channels = os_malloc(mode11g->num_channels * 13925b9c547cSRui Paulo sizeof(struct hostapd_channel_data)); 13935b9c547cSRui Paulo if (mode->channels == NULL) { 13945b9c547cSRui Paulo (*num_modes)--; 13955b9c547cSRui Paulo return modes; /* Could not add 802.11b mode */ 13965b9c547cSRui Paulo } 13975b9c547cSRui Paulo os_memcpy(mode->channels, mode11g->channels, 13985b9c547cSRui Paulo mode11g->num_channels * sizeof(struct hostapd_channel_data)); 13995b9c547cSRui Paulo 14005b9c547cSRui Paulo mode->num_rates = 0; 14015b9c547cSRui Paulo mode->rates = os_malloc(4 * sizeof(int)); 14025b9c547cSRui Paulo if (mode->rates == NULL) { 14035b9c547cSRui Paulo os_free(mode->channels); 14045b9c547cSRui Paulo (*num_modes)--; 14055b9c547cSRui Paulo return modes; /* Could not add 802.11b mode */ 14065b9c547cSRui Paulo } 14075b9c547cSRui Paulo 14085b9c547cSRui Paulo for (i = 0; i < mode11g->num_rates; i++) { 14095b9c547cSRui Paulo if (mode11g->rates[i] != 10 && mode11g->rates[i] != 20 && 14105b9c547cSRui Paulo mode11g->rates[i] != 55 && mode11g->rates[i] != 110) 14115b9c547cSRui Paulo continue; 14125b9c547cSRui Paulo mode->rates[mode->num_rates] = mode11g->rates[i]; 14135b9c547cSRui Paulo mode->num_rates++; 14145b9c547cSRui Paulo if (mode->num_rates == 4) 14155b9c547cSRui Paulo break; 14165b9c547cSRui Paulo } 14175b9c547cSRui Paulo 14185b9c547cSRui Paulo if (mode->num_rates == 0) { 14195b9c547cSRui Paulo os_free(mode->channels); 14205b9c547cSRui Paulo os_free(mode->rates); 14215b9c547cSRui Paulo (*num_modes)--; 14225b9c547cSRui Paulo return modes; /* No 802.11b rates */ 14235b9c547cSRui Paulo } 14245b9c547cSRui Paulo 14255b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "nl80211: Added 802.11b mode based on 802.11g " 14265b9c547cSRui Paulo "information"); 14275b9c547cSRui Paulo 14285b9c547cSRui Paulo return modes; 14295b9c547cSRui Paulo } 14305b9c547cSRui Paulo 14315b9c547cSRui Paulo 14325b9c547cSRui Paulo static void nl80211_set_ht40_mode(struct hostapd_hw_modes *mode, int start, 14335b9c547cSRui Paulo int end) 14345b9c547cSRui Paulo { 14355b9c547cSRui Paulo int c; 14365b9c547cSRui Paulo 14375b9c547cSRui Paulo for (c = 0; c < mode->num_channels; c++) { 14385b9c547cSRui Paulo struct hostapd_channel_data *chan = &mode->channels[c]; 14395b9c547cSRui Paulo if (chan->freq - 10 >= start && chan->freq + 10 <= end) 14405b9c547cSRui Paulo chan->flag |= HOSTAPD_CHAN_HT40; 14415b9c547cSRui Paulo } 14425b9c547cSRui Paulo } 14435b9c547cSRui Paulo 14445b9c547cSRui Paulo 14455b9c547cSRui Paulo static void nl80211_set_ht40_mode_sec(struct hostapd_hw_modes *mode, int start, 14465b9c547cSRui Paulo int end) 14475b9c547cSRui Paulo { 14485b9c547cSRui Paulo int c; 14495b9c547cSRui Paulo 14505b9c547cSRui Paulo for (c = 0; c < mode->num_channels; c++) { 14515b9c547cSRui Paulo struct hostapd_channel_data *chan = &mode->channels[c]; 14525b9c547cSRui Paulo if (!(chan->flag & HOSTAPD_CHAN_HT40)) 14535b9c547cSRui Paulo continue; 14545b9c547cSRui Paulo if (chan->freq - 30 >= start && chan->freq - 10 <= end) 14555b9c547cSRui Paulo chan->flag |= HOSTAPD_CHAN_HT40MINUS; 14565b9c547cSRui Paulo if (chan->freq + 10 >= start && chan->freq + 30 <= end) 14575b9c547cSRui Paulo chan->flag |= HOSTAPD_CHAN_HT40PLUS; 14585b9c547cSRui Paulo } 14595b9c547cSRui Paulo } 14605b9c547cSRui Paulo 14615b9c547cSRui Paulo 14625b9c547cSRui Paulo static void nl80211_reg_rule_max_eirp(u32 start, u32 end, u32 max_eirp, 14635b9c547cSRui Paulo struct phy_info_arg *results) 14645b9c547cSRui Paulo { 14655b9c547cSRui Paulo u16 m; 14665b9c547cSRui Paulo 14675b9c547cSRui Paulo for (m = 0; m < *results->num_modes; m++) { 14685b9c547cSRui Paulo int c; 14695b9c547cSRui Paulo struct hostapd_hw_modes *mode = &results->modes[m]; 14705b9c547cSRui Paulo 14715b9c547cSRui Paulo for (c = 0; c < mode->num_channels; c++) { 14725b9c547cSRui Paulo struct hostapd_channel_data *chan = &mode->channels[c]; 14735b9c547cSRui Paulo if ((u32) chan->freq - 10 >= start && 14745b9c547cSRui Paulo (u32) chan->freq + 10 <= end) 14755b9c547cSRui Paulo chan->max_tx_power = max_eirp; 14765b9c547cSRui Paulo } 14775b9c547cSRui Paulo } 14785b9c547cSRui Paulo } 14795b9c547cSRui Paulo 14805b9c547cSRui Paulo 14815b9c547cSRui Paulo static void nl80211_reg_rule_ht40(u32 start, u32 end, 14825b9c547cSRui Paulo struct phy_info_arg *results) 14835b9c547cSRui Paulo { 14845b9c547cSRui Paulo u16 m; 14855b9c547cSRui Paulo 14865b9c547cSRui Paulo for (m = 0; m < *results->num_modes; m++) { 14875b9c547cSRui Paulo if (!(results->modes[m].ht_capab & 14885b9c547cSRui Paulo HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) 14895b9c547cSRui Paulo continue; 14905b9c547cSRui Paulo nl80211_set_ht40_mode(&results->modes[m], start, end); 14915b9c547cSRui Paulo } 14925b9c547cSRui Paulo } 14935b9c547cSRui Paulo 14945b9c547cSRui Paulo 14955b9c547cSRui Paulo static void nl80211_reg_rule_sec(struct nlattr *tb[], 14965b9c547cSRui Paulo struct phy_info_arg *results) 14975b9c547cSRui Paulo { 14985b9c547cSRui Paulo u32 start, end, max_bw; 14995b9c547cSRui Paulo u16 m; 15005b9c547cSRui Paulo 15015b9c547cSRui Paulo if (tb[NL80211_ATTR_FREQ_RANGE_START] == NULL || 15025b9c547cSRui Paulo tb[NL80211_ATTR_FREQ_RANGE_END] == NULL || 15035b9c547cSRui Paulo tb[NL80211_ATTR_FREQ_RANGE_MAX_BW] == NULL) 15045b9c547cSRui Paulo return; 15055b9c547cSRui Paulo 15065b9c547cSRui Paulo start = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]) / 1000; 15075b9c547cSRui Paulo end = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]) / 1000; 15085b9c547cSRui Paulo max_bw = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) / 1000; 15095b9c547cSRui Paulo 15105b9c547cSRui Paulo if (max_bw < 20) 15115b9c547cSRui Paulo return; 15125b9c547cSRui Paulo 15135b9c547cSRui Paulo for (m = 0; m < *results->num_modes; m++) { 15145b9c547cSRui Paulo if (!(results->modes[m].ht_capab & 15155b9c547cSRui Paulo HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) 15165b9c547cSRui Paulo continue; 15175b9c547cSRui Paulo nl80211_set_ht40_mode_sec(&results->modes[m], start, end); 15185b9c547cSRui Paulo } 15195b9c547cSRui Paulo } 15205b9c547cSRui Paulo 15215b9c547cSRui Paulo 15225b9c547cSRui Paulo static void nl80211_set_vht_mode(struct hostapd_hw_modes *mode, int start, 1523*780fb4a2SCy Schubert int end, int max_bw) 15245b9c547cSRui Paulo { 15255b9c547cSRui Paulo int c; 15265b9c547cSRui Paulo 15275b9c547cSRui Paulo for (c = 0; c < mode->num_channels; c++) { 15285b9c547cSRui Paulo struct hostapd_channel_data *chan = &mode->channels[c]; 15295b9c547cSRui Paulo if (chan->freq - 10 >= start && chan->freq + 70 <= end) 15305b9c547cSRui Paulo chan->flag |= HOSTAPD_CHAN_VHT_10_70; 15315b9c547cSRui Paulo 15325b9c547cSRui Paulo if (chan->freq - 30 >= start && chan->freq + 50 <= end) 15335b9c547cSRui Paulo chan->flag |= HOSTAPD_CHAN_VHT_30_50; 15345b9c547cSRui Paulo 15355b9c547cSRui Paulo if (chan->freq - 50 >= start && chan->freq + 30 <= end) 15365b9c547cSRui Paulo chan->flag |= HOSTAPD_CHAN_VHT_50_30; 15375b9c547cSRui Paulo 15385b9c547cSRui Paulo if (chan->freq - 70 >= start && chan->freq + 10 <= end) 15395b9c547cSRui Paulo chan->flag |= HOSTAPD_CHAN_VHT_70_10; 1540*780fb4a2SCy Schubert 1541*780fb4a2SCy Schubert if (max_bw >= 160) { 1542*780fb4a2SCy Schubert if (chan->freq - 10 >= start && chan->freq + 150 <= end) 1543*780fb4a2SCy Schubert chan->flag |= HOSTAPD_CHAN_VHT_10_150; 1544*780fb4a2SCy Schubert 1545*780fb4a2SCy Schubert if (chan->freq - 30 >= start && chan->freq + 130 <= end) 1546*780fb4a2SCy Schubert chan->flag |= HOSTAPD_CHAN_VHT_30_130; 1547*780fb4a2SCy Schubert 1548*780fb4a2SCy Schubert if (chan->freq - 50 >= start && chan->freq + 110 <= end) 1549*780fb4a2SCy Schubert chan->flag |= HOSTAPD_CHAN_VHT_50_110; 1550*780fb4a2SCy Schubert 1551*780fb4a2SCy Schubert if (chan->freq - 70 >= start && chan->freq + 90 <= end) 1552*780fb4a2SCy Schubert chan->flag |= HOSTAPD_CHAN_VHT_70_90; 1553*780fb4a2SCy Schubert 1554*780fb4a2SCy Schubert if (chan->freq - 90 >= start && chan->freq + 70 <= end) 1555*780fb4a2SCy Schubert chan->flag |= HOSTAPD_CHAN_VHT_90_70; 1556*780fb4a2SCy Schubert 1557*780fb4a2SCy Schubert if (chan->freq - 110 >= start && chan->freq + 50 <= end) 1558*780fb4a2SCy Schubert chan->flag |= HOSTAPD_CHAN_VHT_110_50; 1559*780fb4a2SCy Schubert 1560*780fb4a2SCy Schubert if (chan->freq - 130 >= start && chan->freq + 30 <= end) 1561*780fb4a2SCy Schubert chan->flag |= HOSTAPD_CHAN_VHT_130_30; 1562*780fb4a2SCy Schubert 1563*780fb4a2SCy Schubert if (chan->freq - 150 >= start && chan->freq + 10 <= end) 1564*780fb4a2SCy Schubert chan->flag |= HOSTAPD_CHAN_VHT_150_10; 1565*780fb4a2SCy Schubert } 15665b9c547cSRui Paulo } 15675b9c547cSRui Paulo } 15685b9c547cSRui Paulo 15695b9c547cSRui Paulo 15705b9c547cSRui Paulo static void nl80211_reg_rule_vht(struct nlattr *tb[], 15715b9c547cSRui Paulo struct phy_info_arg *results) 15725b9c547cSRui Paulo { 15735b9c547cSRui Paulo u32 start, end, max_bw; 15745b9c547cSRui Paulo u16 m; 15755b9c547cSRui Paulo 15765b9c547cSRui Paulo if (tb[NL80211_ATTR_FREQ_RANGE_START] == NULL || 15775b9c547cSRui Paulo tb[NL80211_ATTR_FREQ_RANGE_END] == NULL || 15785b9c547cSRui Paulo tb[NL80211_ATTR_FREQ_RANGE_MAX_BW] == NULL) 15795b9c547cSRui Paulo return; 15805b9c547cSRui Paulo 15815b9c547cSRui Paulo start = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]) / 1000; 15825b9c547cSRui Paulo end = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]) / 1000; 15835b9c547cSRui Paulo max_bw = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) / 1000; 15845b9c547cSRui Paulo 15855b9c547cSRui Paulo if (max_bw < 80) 15865b9c547cSRui Paulo return; 15875b9c547cSRui Paulo 15885b9c547cSRui Paulo for (m = 0; m < *results->num_modes; m++) { 15895b9c547cSRui Paulo if (!(results->modes[m].ht_capab & 15905b9c547cSRui Paulo HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) 15915b9c547cSRui Paulo continue; 15925b9c547cSRui Paulo /* TODO: use a real VHT support indication */ 15935b9c547cSRui Paulo if (!results->modes[m].vht_capab) 15945b9c547cSRui Paulo continue; 15955b9c547cSRui Paulo 1596*780fb4a2SCy Schubert nl80211_set_vht_mode(&results->modes[m], start, end, max_bw); 15975b9c547cSRui Paulo } 15985b9c547cSRui Paulo } 15995b9c547cSRui Paulo 16005b9c547cSRui Paulo 16015b9c547cSRui Paulo static const char * dfs_domain_name(enum nl80211_dfs_regions region) 16025b9c547cSRui Paulo { 16035b9c547cSRui Paulo switch (region) { 16045b9c547cSRui Paulo case NL80211_DFS_UNSET: 16055b9c547cSRui Paulo return "DFS-UNSET"; 16065b9c547cSRui Paulo case NL80211_DFS_FCC: 16075b9c547cSRui Paulo return "DFS-FCC"; 16085b9c547cSRui Paulo case NL80211_DFS_ETSI: 16095b9c547cSRui Paulo return "DFS-ETSI"; 16105b9c547cSRui Paulo case NL80211_DFS_JP: 16115b9c547cSRui Paulo return "DFS-JP"; 16125b9c547cSRui Paulo default: 16135b9c547cSRui Paulo return "DFS-invalid"; 16145b9c547cSRui Paulo } 16155b9c547cSRui Paulo } 16165b9c547cSRui Paulo 16175b9c547cSRui Paulo 16185b9c547cSRui Paulo static int nl80211_get_reg(struct nl_msg *msg, void *arg) 16195b9c547cSRui Paulo { 16205b9c547cSRui Paulo struct phy_info_arg *results = arg; 16215b9c547cSRui Paulo struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; 16225b9c547cSRui Paulo struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); 16235b9c547cSRui Paulo struct nlattr *nl_rule; 16245b9c547cSRui Paulo struct nlattr *tb_rule[NL80211_FREQUENCY_ATTR_MAX + 1]; 16255b9c547cSRui Paulo int rem_rule; 16265b9c547cSRui Paulo static struct nla_policy reg_policy[NL80211_FREQUENCY_ATTR_MAX + 1] = { 16275b9c547cSRui Paulo [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, 16285b9c547cSRui Paulo [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, 16295b9c547cSRui Paulo [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, 16305b9c547cSRui Paulo [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, 16315b9c547cSRui Paulo [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, 16325b9c547cSRui Paulo [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, 16335b9c547cSRui Paulo }; 16345b9c547cSRui Paulo 16355b9c547cSRui Paulo nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), 16365b9c547cSRui Paulo genlmsg_attrlen(gnlh, 0), NULL); 16375b9c547cSRui Paulo if (!tb_msg[NL80211_ATTR_REG_ALPHA2] || 16385b9c547cSRui Paulo !tb_msg[NL80211_ATTR_REG_RULES]) { 16395b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "nl80211: No regulatory information " 16405b9c547cSRui Paulo "available"); 16415b9c547cSRui Paulo return NL_SKIP; 16425b9c547cSRui Paulo } 16435b9c547cSRui Paulo 16445b9c547cSRui Paulo if (tb_msg[NL80211_ATTR_DFS_REGION]) { 16455b9c547cSRui Paulo enum nl80211_dfs_regions dfs_domain; 16465b9c547cSRui Paulo dfs_domain = nla_get_u8(tb_msg[NL80211_ATTR_DFS_REGION]); 16475b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "nl80211: Regulatory information - country=%s (%s)", 16485b9c547cSRui Paulo (char *) nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]), 16495b9c547cSRui Paulo dfs_domain_name(dfs_domain)); 16505b9c547cSRui Paulo } else { 16515b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "nl80211: Regulatory information - country=%s", 16525b9c547cSRui Paulo (char *) nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2])); 16535b9c547cSRui Paulo } 16545b9c547cSRui Paulo 16555b9c547cSRui Paulo nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule) 16565b9c547cSRui Paulo { 16575b9c547cSRui Paulo u32 start, end, max_eirp = 0, max_bw = 0, flags = 0; 16585b9c547cSRui Paulo nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX, 16595b9c547cSRui Paulo nla_data(nl_rule), nla_len(nl_rule), reg_policy); 16605b9c547cSRui Paulo if (tb_rule[NL80211_ATTR_FREQ_RANGE_START] == NULL || 16615b9c547cSRui Paulo tb_rule[NL80211_ATTR_FREQ_RANGE_END] == NULL) 16625b9c547cSRui Paulo continue; 16635b9c547cSRui Paulo start = nla_get_u32(tb_rule[NL80211_ATTR_FREQ_RANGE_START]) / 1000; 16645b9c547cSRui Paulo end = nla_get_u32(tb_rule[NL80211_ATTR_FREQ_RANGE_END]) / 1000; 16655b9c547cSRui Paulo if (tb_rule[NL80211_ATTR_POWER_RULE_MAX_EIRP]) 16665b9c547cSRui Paulo max_eirp = nla_get_u32(tb_rule[NL80211_ATTR_POWER_RULE_MAX_EIRP]) / 100; 16675b9c547cSRui Paulo if (tb_rule[NL80211_ATTR_FREQ_RANGE_MAX_BW]) 16685b9c547cSRui Paulo max_bw = nla_get_u32(tb_rule[NL80211_ATTR_FREQ_RANGE_MAX_BW]) / 1000; 16695b9c547cSRui Paulo if (tb_rule[NL80211_ATTR_REG_RULE_FLAGS]) 16705b9c547cSRui Paulo flags = nla_get_u32(tb_rule[NL80211_ATTR_REG_RULE_FLAGS]); 16715b9c547cSRui Paulo 16725b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "nl80211: %u-%u @ %u MHz %u mBm%s%s%s%s%s%s%s%s", 16735b9c547cSRui Paulo start, end, max_bw, max_eirp, 16745b9c547cSRui Paulo flags & NL80211_RRF_NO_OFDM ? " (no OFDM)" : "", 16755b9c547cSRui Paulo flags & NL80211_RRF_NO_CCK ? " (no CCK)" : "", 16765b9c547cSRui Paulo flags & NL80211_RRF_NO_INDOOR ? " (no indoor)" : "", 16775b9c547cSRui Paulo flags & NL80211_RRF_NO_OUTDOOR ? " (no outdoor)" : 16785b9c547cSRui Paulo "", 16795b9c547cSRui Paulo flags & NL80211_RRF_DFS ? " (DFS)" : "", 16805b9c547cSRui Paulo flags & NL80211_RRF_PTP_ONLY ? " (PTP only)" : "", 16815b9c547cSRui Paulo flags & NL80211_RRF_PTMP_ONLY ? " (PTMP only)" : "", 16825b9c547cSRui Paulo flags & NL80211_RRF_NO_IR ? " (no IR)" : ""); 16835b9c547cSRui Paulo if (max_bw >= 40) 16845b9c547cSRui Paulo nl80211_reg_rule_ht40(start, end, results); 16855b9c547cSRui Paulo if (tb_rule[NL80211_ATTR_POWER_RULE_MAX_EIRP]) 16865b9c547cSRui Paulo nl80211_reg_rule_max_eirp(start, end, max_eirp, 16875b9c547cSRui Paulo results); 16885b9c547cSRui Paulo } 16895b9c547cSRui Paulo 16905b9c547cSRui Paulo nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule) 16915b9c547cSRui Paulo { 16925b9c547cSRui Paulo nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX, 16935b9c547cSRui Paulo nla_data(nl_rule), nla_len(nl_rule), reg_policy); 16945b9c547cSRui Paulo nl80211_reg_rule_sec(tb_rule, results); 16955b9c547cSRui Paulo } 16965b9c547cSRui Paulo 16975b9c547cSRui Paulo nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule) 16985b9c547cSRui Paulo { 16995b9c547cSRui Paulo nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX, 17005b9c547cSRui Paulo nla_data(nl_rule), nla_len(nl_rule), reg_policy); 17015b9c547cSRui Paulo nl80211_reg_rule_vht(tb_rule, results); 17025b9c547cSRui Paulo } 17035b9c547cSRui Paulo 17045b9c547cSRui Paulo return NL_SKIP; 17055b9c547cSRui Paulo } 17065b9c547cSRui Paulo 17075b9c547cSRui Paulo 17085b9c547cSRui Paulo static int nl80211_set_regulatory_flags(struct wpa_driver_nl80211_data *drv, 17095b9c547cSRui Paulo struct phy_info_arg *results) 17105b9c547cSRui Paulo { 17115b9c547cSRui Paulo struct nl_msg *msg; 17125b9c547cSRui Paulo 17135b9c547cSRui Paulo msg = nlmsg_alloc(); 17145b9c547cSRui Paulo if (!msg) 17155b9c547cSRui Paulo return -ENOMEM; 17165b9c547cSRui Paulo 17175b9c547cSRui Paulo nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG); 17185b9c547cSRui Paulo return send_and_recv_msgs(drv, msg, nl80211_get_reg, results); 17195b9c547cSRui Paulo } 17205b9c547cSRui Paulo 17215b9c547cSRui Paulo 17225b9c547cSRui Paulo struct hostapd_hw_modes * 17235b9c547cSRui Paulo nl80211_get_hw_feature_data(void *priv, u16 *num_modes, u16 *flags) 17245b9c547cSRui Paulo { 17255b9c547cSRui Paulo u32 feat; 17265b9c547cSRui Paulo struct i802_bss *bss = priv; 17275b9c547cSRui Paulo struct wpa_driver_nl80211_data *drv = bss->drv; 17285b9c547cSRui Paulo int nl_flags = 0; 17295b9c547cSRui Paulo struct nl_msg *msg; 17305b9c547cSRui Paulo struct phy_info_arg result = { 17315b9c547cSRui Paulo .num_modes = num_modes, 17325b9c547cSRui Paulo .modes = NULL, 17335b9c547cSRui Paulo .last_mode = -1, 1734*780fb4a2SCy Schubert .failed = 0, 17355b9c547cSRui Paulo }; 17365b9c547cSRui Paulo 17375b9c547cSRui Paulo *num_modes = 0; 17385b9c547cSRui Paulo *flags = 0; 17395b9c547cSRui Paulo 17405b9c547cSRui Paulo feat = get_nl80211_protocol_features(drv); 17415b9c547cSRui Paulo if (feat & NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP) 17425b9c547cSRui Paulo nl_flags = NLM_F_DUMP; 17435b9c547cSRui Paulo if (!(msg = nl80211_cmd_msg(bss, nl_flags, NL80211_CMD_GET_WIPHY)) || 17445b9c547cSRui Paulo nla_put_flag(msg, NL80211_ATTR_SPLIT_WIPHY_DUMP)) { 17455b9c547cSRui Paulo nlmsg_free(msg); 17465b9c547cSRui Paulo return NULL; 17475b9c547cSRui Paulo } 17485b9c547cSRui Paulo 17495b9c547cSRui Paulo if (send_and_recv_msgs(drv, msg, phy_info_handler, &result) == 0) { 17505b9c547cSRui Paulo nl80211_set_regulatory_flags(drv, &result); 1751*780fb4a2SCy Schubert if (result.failed) { 1752*780fb4a2SCy Schubert int i; 1753*780fb4a2SCy Schubert 1754*780fb4a2SCy Schubert for (i = 0; result.modes && i < *num_modes; i++) { 1755*780fb4a2SCy Schubert os_free(result.modes[i].channels); 1756*780fb4a2SCy Schubert os_free(result.modes[i].rates); 1757*780fb4a2SCy Schubert } 1758*780fb4a2SCy Schubert os_free(result.modes); 1759*780fb4a2SCy Schubert return NULL; 1760*780fb4a2SCy Schubert } 17615b9c547cSRui Paulo return wpa_driver_nl80211_postprocess_modes(result.modes, 17625b9c547cSRui Paulo num_modes); 17635b9c547cSRui Paulo } 17645b9c547cSRui Paulo 17655b9c547cSRui Paulo return NULL; 17665b9c547cSRui Paulo } 1767