12be7d22fSVladimir Kondratiev /* 22be7d22fSVladimir Kondratiev * Copyright (c) 2012 Qualcomm Atheros, Inc. 32be7d22fSVladimir Kondratiev * 42be7d22fSVladimir Kondratiev * Permission to use, copy, modify, and/or distribute this software for any 52be7d22fSVladimir Kondratiev * purpose with or without fee is hereby granted, provided that the above 62be7d22fSVladimir Kondratiev * copyright notice and this permission notice appear in all copies. 72be7d22fSVladimir Kondratiev * 82be7d22fSVladimir Kondratiev * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 92be7d22fSVladimir Kondratiev * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 102be7d22fSVladimir Kondratiev * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 112be7d22fSVladimir Kondratiev * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 122be7d22fSVladimir Kondratiev * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 132be7d22fSVladimir Kondratiev * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 142be7d22fSVladimir Kondratiev * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 152be7d22fSVladimir Kondratiev */ 162be7d22fSVladimir Kondratiev 172be7d22fSVladimir Kondratiev #include "wil6210.h" 182be7d22fSVladimir Kondratiev #include "wmi.h" 192be7d22fSVladimir Kondratiev 202be7d22fSVladimir Kondratiev #define CHAN60G(_channel, _flags) { \ 212be7d22fSVladimir Kondratiev .band = IEEE80211_BAND_60GHZ, \ 222be7d22fSVladimir Kondratiev .center_freq = 56160 + (2160 * (_channel)), \ 232be7d22fSVladimir Kondratiev .hw_value = (_channel), \ 242be7d22fSVladimir Kondratiev .flags = (_flags), \ 252be7d22fSVladimir Kondratiev .max_antenna_gain = 0, \ 262be7d22fSVladimir Kondratiev .max_power = 40, \ 272be7d22fSVladimir Kondratiev } 282be7d22fSVladimir Kondratiev 292be7d22fSVladimir Kondratiev static struct ieee80211_channel wil_60ghz_channels[] = { 302be7d22fSVladimir Kondratiev CHAN60G(1, 0), 312be7d22fSVladimir Kondratiev CHAN60G(2, 0), 322be7d22fSVladimir Kondratiev CHAN60G(3, 0), 332be7d22fSVladimir Kondratiev /* channel 4 not supported yet */ 342be7d22fSVladimir Kondratiev }; 352be7d22fSVladimir Kondratiev 362be7d22fSVladimir Kondratiev static struct ieee80211_supported_band wil_band_60ghz = { 372be7d22fSVladimir Kondratiev .channels = wil_60ghz_channels, 382be7d22fSVladimir Kondratiev .n_channels = ARRAY_SIZE(wil_60ghz_channels), 392be7d22fSVladimir Kondratiev .ht_cap = { 402be7d22fSVladimir Kondratiev .ht_supported = true, 412be7d22fSVladimir Kondratiev .cap = 0, /* TODO */ 422be7d22fSVladimir Kondratiev .ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K, /* TODO */ 432be7d22fSVladimir Kondratiev .ampdu_density = IEEE80211_HT_MPDU_DENSITY_8, /* TODO */ 442be7d22fSVladimir Kondratiev .mcs = { 452be7d22fSVladimir Kondratiev /* MCS 1..12 - SC PHY */ 462be7d22fSVladimir Kondratiev .rx_mask = {0xfe, 0x1f}, /* 1..12 */ 472be7d22fSVladimir Kondratiev .tx_params = IEEE80211_HT_MCS_TX_DEFINED, /* TODO */ 482be7d22fSVladimir Kondratiev }, 492be7d22fSVladimir Kondratiev }, 502be7d22fSVladimir Kondratiev }; 512be7d22fSVladimir Kondratiev 522be7d22fSVladimir Kondratiev static const struct ieee80211_txrx_stypes 532be7d22fSVladimir Kondratiev wil_mgmt_stypes[NUM_NL80211_IFTYPES] = { 542be7d22fSVladimir Kondratiev [NL80211_IFTYPE_STATION] = { 552be7d22fSVladimir Kondratiev .tx = BIT(IEEE80211_STYPE_ACTION >> 4) | 562be7d22fSVladimir Kondratiev BIT(IEEE80211_STYPE_PROBE_RESP >> 4), 572be7d22fSVladimir Kondratiev .rx = BIT(IEEE80211_STYPE_ACTION >> 4) | 582be7d22fSVladimir Kondratiev BIT(IEEE80211_STYPE_PROBE_REQ >> 4) 592be7d22fSVladimir Kondratiev }, 602be7d22fSVladimir Kondratiev [NL80211_IFTYPE_AP] = { 612be7d22fSVladimir Kondratiev .tx = BIT(IEEE80211_STYPE_ACTION >> 4) | 622be7d22fSVladimir Kondratiev BIT(IEEE80211_STYPE_PROBE_RESP >> 4), 632be7d22fSVladimir Kondratiev .rx = BIT(IEEE80211_STYPE_ACTION >> 4) | 642be7d22fSVladimir Kondratiev BIT(IEEE80211_STYPE_PROBE_REQ >> 4) 652be7d22fSVladimir Kondratiev }, 662be7d22fSVladimir Kondratiev [NL80211_IFTYPE_P2P_CLIENT] = { 672be7d22fSVladimir Kondratiev .tx = BIT(IEEE80211_STYPE_ACTION >> 4) | 682be7d22fSVladimir Kondratiev BIT(IEEE80211_STYPE_PROBE_RESP >> 4), 692be7d22fSVladimir Kondratiev .rx = BIT(IEEE80211_STYPE_ACTION >> 4) | 702be7d22fSVladimir Kondratiev BIT(IEEE80211_STYPE_PROBE_REQ >> 4) 712be7d22fSVladimir Kondratiev }, 722be7d22fSVladimir Kondratiev [NL80211_IFTYPE_P2P_GO] = { 732be7d22fSVladimir Kondratiev .tx = BIT(IEEE80211_STYPE_ACTION >> 4) | 742be7d22fSVladimir Kondratiev BIT(IEEE80211_STYPE_PROBE_RESP >> 4), 752be7d22fSVladimir Kondratiev .rx = BIT(IEEE80211_STYPE_ACTION >> 4) | 762be7d22fSVladimir Kondratiev BIT(IEEE80211_STYPE_PROBE_REQ >> 4) 772be7d22fSVladimir Kondratiev }, 782be7d22fSVladimir Kondratiev }; 792be7d22fSVladimir Kondratiev 802be7d22fSVladimir Kondratiev static const u32 wil_cipher_suites[] = { 812be7d22fSVladimir Kondratiev WLAN_CIPHER_SUITE_GCMP, 822be7d22fSVladimir Kondratiev }; 832be7d22fSVladimir Kondratiev 842be7d22fSVladimir Kondratiev int wil_iftype_nl2wmi(enum nl80211_iftype type) 852be7d22fSVladimir Kondratiev { 862be7d22fSVladimir Kondratiev static const struct { 872be7d22fSVladimir Kondratiev enum nl80211_iftype nl; 882be7d22fSVladimir Kondratiev enum wmi_network_type wmi; 892be7d22fSVladimir Kondratiev } __nl2wmi[] = { 902be7d22fSVladimir Kondratiev {NL80211_IFTYPE_ADHOC, WMI_NETTYPE_ADHOC}, 912be7d22fSVladimir Kondratiev {NL80211_IFTYPE_STATION, WMI_NETTYPE_INFRA}, 922be7d22fSVladimir Kondratiev {NL80211_IFTYPE_AP, WMI_NETTYPE_AP}, 932be7d22fSVladimir Kondratiev {NL80211_IFTYPE_P2P_CLIENT, WMI_NETTYPE_P2P}, 942be7d22fSVladimir Kondratiev {NL80211_IFTYPE_P2P_GO, WMI_NETTYPE_P2P}, 952be7d22fSVladimir Kondratiev {NL80211_IFTYPE_MONITOR, WMI_NETTYPE_ADHOC}, /* FIXME */ 962be7d22fSVladimir Kondratiev }; 972be7d22fSVladimir Kondratiev uint i; 982be7d22fSVladimir Kondratiev 992be7d22fSVladimir Kondratiev for (i = 0; i < ARRAY_SIZE(__nl2wmi); i++) { 1002be7d22fSVladimir Kondratiev if (__nl2wmi[i].nl == type) 1012be7d22fSVladimir Kondratiev return __nl2wmi[i].wmi; 1022be7d22fSVladimir Kondratiev } 1032be7d22fSVladimir Kondratiev 1042be7d22fSVladimir Kondratiev return -EOPNOTSUPP; 1052be7d22fSVladimir Kondratiev } 1062be7d22fSVladimir Kondratiev 1072be7d22fSVladimir Kondratiev static int wil_cfg80211_get_station(struct wiphy *wiphy, 1082be7d22fSVladimir Kondratiev struct net_device *ndev, 1092be7d22fSVladimir Kondratiev u8 *mac, struct station_info *sinfo) 1102be7d22fSVladimir Kondratiev { 1112be7d22fSVladimir Kondratiev struct wil6210_priv *wil = wiphy_to_wil(wiphy); 1122be7d22fSVladimir Kondratiev int rc; 1132be7d22fSVladimir Kondratiev struct wmi_notify_req_cmd cmd = { 1142be7d22fSVladimir Kondratiev .cid = 0, 1152be7d22fSVladimir Kondratiev .interval_usec = 0, 1162be7d22fSVladimir Kondratiev }; 1172be7d22fSVladimir Kondratiev 1182be7d22fSVladimir Kondratiev if (memcmp(mac, wil->dst_addr[0], ETH_ALEN)) 1192be7d22fSVladimir Kondratiev return -ENOENT; 1202be7d22fSVladimir Kondratiev 1212be7d22fSVladimir Kondratiev /* WMI_NOTIFY_REQ_DONE_EVENTID handler fills wil->stats.bf_mcs */ 1222be7d22fSVladimir Kondratiev rc = wmi_call(wil, WMI_NOTIFY_REQ_CMDID, &cmd, sizeof(cmd), 1232be7d22fSVladimir Kondratiev WMI_NOTIFY_REQ_DONE_EVENTID, NULL, 0, 20); 1242be7d22fSVladimir Kondratiev if (rc) 1252be7d22fSVladimir Kondratiev return rc; 1262be7d22fSVladimir Kondratiev 1272be7d22fSVladimir Kondratiev sinfo->generation = wil->sinfo_gen; 1282be7d22fSVladimir Kondratiev 1292be7d22fSVladimir Kondratiev sinfo->filled |= STATION_INFO_TX_BITRATE; 1302be7d22fSVladimir Kondratiev sinfo->txrate.flags = RATE_INFO_FLAGS_MCS | RATE_INFO_FLAGS_60G; 1312be7d22fSVladimir Kondratiev sinfo->txrate.mcs = wil->stats.bf_mcs; 1322be7d22fSVladimir Kondratiev sinfo->filled |= STATION_INFO_RX_BITRATE; 1332be7d22fSVladimir Kondratiev sinfo->rxrate.flags = RATE_INFO_FLAGS_MCS | RATE_INFO_FLAGS_60G; 1342be7d22fSVladimir Kondratiev sinfo->rxrate.mcs = wil->stats.last_mcs_rx; 1352be7d22fSVladimir Kondratiev 1362be7d22fSVladimir Kondratiev if (test_bit(wil_status_fwconnected, &wil->status)) { 1372be7d22fSVladimir Kondratiev sinfo->filled |= STATION_INFO_SIGNAL; 1382be7d22fSVladimir Kondratiev sinfo->signal = 12; /* TODO: provide real value */ 1392be7d22fSVladimir Kondratiev } 1402be7d22fSVladimir Kondratiev 1412be7d22fSVladimir Kondratiev return 0; 1422be7d22fSVladimir Kondratiev } 1432be7d22fSVladimir Kondratiev 1442be7d22fSVladimir Kondratiev static int wil_cfg80211_change_iface(struct wiphy *wiphy, 1452be7d22fSVladimir Kondratiev struct net_device *ndev, 1462be7d22fSVladimir Kondratiev enum nl80211_iftype type, u32 *flags, 1472be7d22fSVladimir Kondratiev struct vif_params *params) 1482be7d22fSVladimir Kondratiev { 1492be7d22fSVladimir Kondratiev struct wil6210_priv *wil = wiphy_to_wil(wiphy); 1502be7d22fSVladimir Kondratiev struct wireless_dev *wdev = wil->wdev; 1512be7d22fSVladimir Kondratiev 1522be7d22fSVladimir Kondratiev switch (type) { 1532be7d22fSVladimir Kondratiev case NL80211_IFTYPE_STATION: 1542be7d22fSVladimir Kondratiev case NL80211_IFTYPE_AP: 1552be7d22fSVladimir Kondratiev case NL80211_IFTYPE_P2P_CLIENT: 1562be7d22fSVladimir Kondratiev case NL80211_IFTYPE_P2P_GO: 1572be7d22fSVladimir Kondratiev break; 1582be7d22fSVladimir Kondratiev case NL80211_IFTYPE_MONITOR: 1592be7d22fSVladimir Kondratiev if (flags) 1602be7d22fSVladimir Kondratiev wil->monitor_flags = *flags; 1612be7d22fSVladimir Kondratiev else 1622be7d22fSVladimir Kondratiev wil->monitor_flags = 0; 1632be7d22fSVladimir Kondratiev 1642be7d22fSVladimir Kondratiev break; 1652be7d22fSVladimir Kondratiev default: 1662be7d22fSVladimir Kondratiev return -EOPNOTSUPP; 1672be7d22fSVladimir Kondratiev } 1682be7d22fSVladimir Kondratiev 1692be7d22fSVladimir Kondratiev wdev->iftype = type; 1702be7d22fSVladimir Kondratiev 1712be7d22fSVladimir Kondratiev return 0; 1722be7d22fSVladimir Kondratiev } 1732be7d22fSVladimir Kondratiev 1742be7d22fSVladimir Kondratiev static int wil_cfg80211_scan(struct wiphy *wiphy, 1752be7d22fSVladimir Kondratiev struct cfg80211_scan_request *request) 1762be7d22fSVladimir Kondratiev { 1772be7d22fSVladimir Kondratiev struct wil6210_priv *wil = wiphy_to_wil(wiphy); 1782be7d22fSVladimir Kondratiev struct wireless_dev *wdev = wil->wdev; 1792be7d22fSVladimir Kondratiev struct { 1802be7d22fSVladimir Kondratiev struct wmi_start_scan_cmd cmd; 1812be7d22fSVladimir Kondratiev u16 chnl[4]; 1822be7d22fSVladimir Kondratiev } __packed cmd; 1832be7d22fSVladimir Kondratiev uint i, n; 1842be7d22fSVladimir Kondratiev 1852be7d22fSVladimir Kondratiev if (wil->scan_request) { 1862be7d22fSVladimir Kondratiev wil_err(wil, "Already scanning\n"); 1872be7d22fSVladimir Kondratiev return -EAGAIN; 1882be7d22fSVladimir Kondratiev } 1892be7d22fSVladimir Kondratiev 1902be7d22fSVladimir Kondratiev /* check we are client side */ 1912be7d22fSVladimir Kondratiev switch (wdev->iftype) { 1922be7d22fSVladimir Kondratiev case NL80211_IFTYPE_STATION: 1932be7d22fSVladimir Kondratiev case NL80211_IFTYPE_P2P_CLIENT: 1942be7d22fSVladimir Kondratiev break; 1952be7d22fSVladimir Kondratiev default: 1962be7d22fSVladimir Kondratiev return -EOPNOTSUPP; 1972be7d22fSVladimir Kondratiev } 1982be7d22fSVladimir Kondratiev 1992be7d22fSVladimir Kondratiev /* FW don't support scan after connection attempt */ 2002be7d22fSVladimir Kondratiev if (test_bit(wil_status_dontscan, &wil->status)) { 2012be7d22fSVladimir Kondratiev wil_err(wil, "Scan after connect attempt not supported\n"); 2022be7d22fSVladimir Kondratiev return -EBUSY; 2032be7d22fSVladimir Kondratiev } 2042be7d22fSVladimir Kondratiev 2052be7d22fSVladimir Kondratiev wil->scan_request = request; 2062be7d22fSVladimir Kondratiev 2072be7d22fSVladimir Kondratiev memset(&cmd, 0, sizeof(cmd)); 2082be7d22fSVladimir Kondratiev cmd.cmd.num_channels = 0; 2092be7d22fSVladimir Kondratiev n = min(request->n_channels, 4U); 2102be7d22fSVladimir Kondratiev for (i = 0; i < n; i++) { 2112be7d22fSVladimir Kondratiev int ch = request->channels[i]->hw_value; 2122be7d22fSVladimir Kondratiev if (ch == 0) { 2132be7d22fSVladimir Kondratiev wil_err(wil, 2142be7d22fSVladimir Kondratiev "Scan requested for unknown frequency %dMhz\n", 2152be7d22fSVladimir Kondratiev request->channels[i]->center_freq); 2162be7d22fSVladimir Kondratiev continue; 2172be7d22fSVladimir Kondratiev } 2182be7d22fSVladimir Kondratiev /* 0-based channel indexes */ 2192be7d22fSVladimir Kondratiev cmd.cmd.channel_list[cmd.cmd.num_channels++].channel = ch - 1; 2207743882dSVladimir Kondratiev wil_dbg_misc(wil, "Scan for ch %d : %d MHz\n", ch, 2212be7d22fSVladimir Kondratiev request->channels[i]->center_freq); 2222be7d22fSVladimir Kondratiev } 2232be7d22fSVladimir Kondratiev 2242be7d22fSVladimir Kondratiev return wmi_send(wil, WMI_START_SCAN_CMDID, &cmd, sizeof(cmd.cmd) + 2252be7d22fSVladimir Kondratiev cmd.cmd.num_channels * sizeof(cmd.cmd.channel_list[0])); 2262be7d22fSVladimir Kondratiev } 2272be7d22fSVladimir Kondratiev 2282be7d22fSVladimir Kondratiev static int wil_cfg80211_connect(struct wiphy *wiphy, 2292be7d22fSVladimir Kondratiev struct net_device *ndev, 2302be7d22fSVladimir Kondratiev struct cfg80211_connect_params *sme) 2312be7d22fSVladimir Kondratiev { 2322be7d22fSVladimir Kondratiev struct wil6210_priv *wil = wiphy_to_wil(wiphy); 2332be7d22fSVladimir Kondratiev struct cfg80211_bss *bss; 2342be7d22fSVladimir Kondratiev struct wmi_connect_cmd conn; 2352be7d22fSVladimir Kondratiev const u8 *ssid_eid; 2362be7d22fSVladimir Kondratiev const u8 *rsn_eid; 2372be7d22fSVladimir Kondratiev int ch; 2382be7d22fSVladimir Kondratiev int rc = 0; 2392be7d22fSVladimir Kondratiev 2402be7d22fSVladimir Kondratiev bss = cfg80211_get_bss(wiphy, sme->channel, sme->bssid, 2412be7d22fSVladimir Kondratiev sme->ssid, sme->ssid_len, 2422be7d22fSVladimir Kondratiev WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS); 2432be7d22fSVladimir Kondratiev if (!bss) { 2442be7d22fSVladimir Kondratiev wil_err(wil, "Unable to find BSS\n"); 2452be7d22fSVladimir Kondratiev return -ENOENT; 2462be7d22fSVladimir Kondratiev } 2472be7d22fSVladimir Kondratiev 2482be7d22fSVladimir Kondratiev ssid_eid = ieee80211_bss_get_ie(bss, WLAN_EID_SSID); 2492be7d22fSVladimir Kondratiev if (!ssid_eid) { 2502be7d22fSVladimir Kondratiev wil_err(wil, "No SSID\n"); 2512be7d22fSVladimir Kondratiev rc = -ENOENT; 2522be7d22fSVladimir Kondratiev goto out; 2532be7d22fSVladimir Kondratiev } 2542be7d22fSVladimir Kondratiev 2552be7d22fSVladimir Kondratiev rsn_eid = sme->ie ? 2562be7d22fSVladimir Kondratiev cfg80211_find_ie(WLAN_EID_RSN, sme->ie, sme->ie_len) : 2572be7d22fSVladimir Kondratiev NULL; 2582be7d22fSVladimir Kondratiev if (rsn_eid) { 2592be7d22fSVladimir Kondratiev if (sme->ie_len > WMI_MAX_IE_LEN) { 2602be7d22fSVladimir Kondratiev rc = -ERANGE; 2612be7d22fSVladimir Kondratiev wil_err(wil, "IE too large (%td bytes)\n", 2622be7d22fSVladimir Kondratiev sme->ie_len); 2632be7d22fSVladimir Kondratiev goto out; 2642be7d22fSVladimir Kondratiev } 2652be7d22fSVladimir Kondratiev /* 2662be7d22fSVladimir Kondratiev * For secure assoc, send: 2672be7d22fSVladimir Kondratiev * (1) WMI_DELETE_CIPHER_KEY_CMD 2682be7d22fSVladimir Kondratiev * (2) WMI_SET_APPIE_CMD 2692be7d22fSVladimir Kondratiev */ 2702be7d22fSVladimir Kondratiev rc = wmi_del_cipher_key(wil, 0, bss->bssid); 2712be7d22fSVladimir Kondratiev if (rc) { 2722be7d22fSVladimir Kondratiev wil_err(wil, "WMI_DELETE_CIPHER_KEY_CMD failed\n"); 2732be7d22fSVladimir Kondratiev goto out; 2742be7d22fSVladimir Kondratiev } 2752be7d22fSVladimir Kondratiev /* WMI_SET_APPIE_CMD */ 2762be7d22fSVladimir Kondratiev rc = wmi_set_ie(wil, WMI_FRAME_ASSOC_REQ, sme->ie_len, sme->ie); 2772be7d22fSVladimir Kondratiev if (rc) { 2782be7d22fSVladimir Kondratiev wil_err(wil, "WMI_SET_APPIE_CMD failed\n"); 2792be7d22fSVladimir Kondratiev goto out; 2802be7d22fSVladimir Kondratiev } 2812be7d22fSVladimir Kondratiev } 2822be7d22fSVladimir Kondratiev 2832be7d22fSVladimir Kondratiev /* WMI_CONNECT_CMD */ 2842be7d22fSVladimir Kondratiev memset(&conn, 0, sizeof(conn)); 285acc9780dSVladimir Kondratiev switch (bss->capability & WLAN_CAPABILITY_DMG_TYPE_MASK) { 2862be7d22fSVladimir Kondratiev case WLAN_CAPABILITY_DMG_TYPE_AP: 2872be7d22fSVladimir Kondratiev conn.network_type = WMI_NETTYPE_INFRA; 2882be7d22fSVladimir Kondratiev break; 2892be7d22fSVladimir Kondratiev case WLAN_CAPABILITY_DMG_TYPE_PBSS: 2902be7d22fSVladimir Kondratiev conn.network_type = WMI_NETTYPE_P2P; 2912be7d22fSVladimir Kondratiev break; 2922be7d22fSVladimir Kondratiev default: 2932be7d22fSVladimir Kondratiev wil_err(wil, "Unsupported BSS type, capability= 0x%04x\n", 2942be7d22fSVladimir Kondratiev bss->capability); 2952be7d22fSVladimir Kondratiev goto out; 2962be7d22fSVladimir Kondratiev } 2972be7d22fSVladimir Kondratiev if (rsn_eid) { 2982be7d22fSVladimir Kondratiev conn.dot11_auth_mode = WMI_AUTH11_SHARED; 2992be7d22fSVladimir Kondratiev conn.auth_mode = WMI_AUTH_WPA2_PSK; 3002be7d22fSVladimir Kondratiev conn.pairwise_crypto_type = WMI_CRYPT_AES_GCMP; 3012be7d22fSVladimir Kondratiev conn.pairwise_crypto_len = 16; 3022be7d22fSVladimir Kondratiev } else { 3032be7d22fSVladimir Kondratiev conn.dot11_auth_mode = WMI_AUTH11_OPEN; 3042be7d22fSVladimir Kondratiev conn.auth_mode = WMI_AUTH_NONE; 3052be7d22fSVladimir Kondratiev } 3062be7d22fSVladimir Kondratiev 3072be7d22fSVladimir Kondratiev conn.ssid_len = min_t(u8, ssid_eid[1], 32); 3082be7d22fSVladimir Kondratiev memcpy(conn.ssid, ssid_eid+2, conn.ssid_len); 3092be7d22fSVladimir Kondratiev 3102be7d22fSVladimir Kondratiev ch = bss->channel->hw_value; 3112be7d22fSVladimir Kondratiev if (ch == 0) { 3122be7d22fSVladimir Kondratiev wil_err(wil, "BSS at unknown frequency %dMhz\n", 3132be7d22fSVladimir Kondratiev bss->channel->center_freq); 3142be7d22fSVladimir Kondratiev rc = -EOPNOTSUPP; 3152be7d22fSVladimir Kondratiev goto out; 3162be7d22fSVladimir Kondratiev } 3172be7d22fSVladimir Kondratiev conn.channel = ch - 1; 3182be7d22fSVladimir Kondratiev 319d458cdf7SJoe Perches memcpy(conn.bssid, bss->bssid, ETH_ALEN); 320d458cdf7SJoe Perches memcpy(conn.dst_mac, bss->bssid, ETH_ALEN); 3212be7d22fSVladimir Kondratiev /* 3222be7d22fSVladimir Kondratiev * FW don't support scan after connection attempt 3232be7d22fSVladimir Kondratiev */ 3242be7d22fSVladimir Kondratiev set_bit(wil_status_dontscan, &wil->status); 325b338f74eSVladimir Kondratiev set_bit(wil_status_fwconnecting, &wil->status); 3262be7d22fSVladimir Kondratiev 3272be7d22fSVladimir Kondratiev rc = wmi_send(wil, WMI_CONNECT_CMDID, &conn, sizeof(conn)); 3282be7d22fSVladimir Kondratiev if (rc == 0) { 3292be7d22fSVladimir Kondratiev /* Connect can take lots of time */ 3302be7d22fSVladimir Kondratiev mod_timer(&wil->connect_timer, 3312be7d22fSVladimir Kondratiev jiffies + msecs_to_jiffies(2000)); 332b338f74eSVladimir Kondratiev } else { 333b338f74eSVladimir Kondratiev clear_bit(wil_status_dontscan, &wil->status); 334b338f74eSVladimir Kondratiev clear_bit(wil_status_fwconnecting, &wil->status); 3352be7d22fSVladimir Kondratiev } 3362be7d22fSVladimir Kondratiev 3372be7d22fSVladimir Kondratiev out: 3385b112d3dSJohannes Berg cfg80211_put_bss(wiphy, bss); 3392be7d22fSVladimir Kondratiev 3402be7d22fSVladimir Kondratiev return rc; 3412be7d22fSVladimir Kondratiev } 3422be7d22fSVladimir Kondratiev 3432be7d22fSVladimir Kondratiev static int wil_cfg80211_disconnect(struct wiphy *wiphy, 3442be7d22fSVladimir Kondratiev struct net_device *ndev, 3452be7d22fSVladimir Kondratiev u16 reason_code) 3462be7d22fSVladimir Kondratiev { 3472be7d22fSVladimir Kondratiev int rc; 3482be7d22fSVladimir Kondratiev struct wil6210_priv *wil = wiphy_to_wil(wiphy); 3492be7d22fSVladimir Kondratiev 3502be7d22fSVladimir Kondratiev rc = wmi_send(wil, WMI_DISCONNECT_CMDID, NULL, 0); 3512be7d22fSVladimir Kondratiev 3522be7d22fSVladimir Kondratiev return rc; 3532be7d22fSVladimir Kondratiev } 3542be7d22fSVladimir Kondratiev 3552be7d22fSVladimir Kondratiev static int wil_cfg80211_set_channel(struct wiphy *wiphy, 3562be7d22fSVladimir Kondratiev struct cfg80211_chan_def *chandef) 3572be7d22fSVladimir Kondratiev { 3582be7d22fSVladimir Kondratiev struct wil6210_priv *wil = wiphy_to_wil(wiphy); 3592be7d22fSVladimir Kondratiev struct wireless_dev *wdev = wil->wdev; 3602be7d22fSVladimir Kondratiev 3612be7d22fSVladimir Kondratiev wdev->preset_chandef = *chandef; 3622be7d22fSVladimir Kondratiev 3632be7d22fSVladimir Kondratiev return 0; 3642be7d22fSVladimir Kondratiev } 3652be7d22fSVladimir Kondratiev 3662be7d22fSVladimir Kondratiev static int wil_cfg80211_add_key(struct wiphy *wiphy, 3672be7d22fSVladimir Kondratiev struct net_device *ndev, 3682be7d22fSVladimir Kondratiev u8 key_index, bool pairwise, 3692be7d22fSVladimir Kondratiev const u8 *mac_addr, 3702be7d22fSVladimir Kondratiev struct key_params *params) 3712be7d22fSVladimir Kondratiev { 3722be7d22fSVladimir Kondratiev struct wil6210_priv *wil = wiphy_to_wil(wiphy); 3732be7d22fSVladimir Kondratiev 3742be7d22fSVladimir Kondratiev /* group key is not used */ 3752be7d22fSVladimir Kondratiev if (!pairwise) 3762be7d22fSVladimir Kondratiev return 0; 3772be7d22fSVladimir Kondratiev 3782be7d22fSVladimir Kondratiev return wmi_add_cipher_key(wil, key_index, mac_addr, 3792be7d22fSVladimir Kondratiev params->key_len, params->key); 3802be7d22fSVladimir Kondratiev } 3812be7d22fSVladimir Kondratiev 3822be7d22fSVladimir Kondratiev static int wil_cfg80211_del_key(struct wiphy *wiphy, 3832be7d22fSVladimir Kondratiev struct net_device *ndev, 3842be7d22fSVladimir Kondratiev u8 key_index, bool pairwise, 3852be7d22fSVladimir Kondratiev const u8 *mac_addr) 3862be7d22fSVladimir Kondratiev { 3872be7d22fSVladimir Kondratiev struct wil6210_priv *wil = wiphy_to_wil(wiphy); 3882be7d22fSVladimir Kondratiev 3892be7d22fSVladimir Kondratiev /* group key is not used */ 3902be7d22fSVladimir Kondratiev if (!pairwise) 3912be7d22fSVladimir Kondratiev return 0; 3922be7d22fSVladimir Kondratiev 3932be7d22fSVladimir Kondratiev return wmi_del_cipher_key(wil, key_index, mac_addr); 3942be7d22fSVladimir Kondratiev } 3952be7d22fSVladimir Kondratiev 3962be7d22fSVladimir Kondratiev /* Need to be present or wiphy_new() will WARN */ 3972be7d22fSVladimir Kondratiev static int wil_cfg80211_set_default_key(struct wiphy *wiphy, 3982be7d22fSVladimir Kondratiev struct net_device *ndev, 3992be7d22fSVladimir Kondratiev u8 key_index, bool unicast, 4002be7d22fSVladimir Kondratiev bool multicast) 4012be7d22fSVladimir Kondratiev { 4022be7d22fSVladimir Kondratiev return 0; 4032be7d22fSVladimir Kondratiev } 4042be7d22fSVladimir Kondratiev 40592646c9fSVladimir Kondratiev static int wil_fix_bcon(struct wil6210_priv *wil, 40692646c9fSVladimir Kondratiev struct cfg80211_beacon_data *bcon) 40792646c9fSVladimir Kondratiev { 40892646c9fSVladimir Kondratiev struct ieee80211_mgmt *f = (struct ieee80211_mgmt *)bcon->probe_resp; 40992646c9fSVladimir Kondratiev size_t hlen = offsetof(struct ieee80211_mgmt, u.probe_resp.variable); 41092646c9fSVladimir Kondratiev int rc = 0; 41192646c9fSVladimir Kondratiev 41292646c9fSVladimir Kondratiev if (bcon->probe_resp_len <= hlen) 41392646c9fSVladimir Kondratiev return 0; 41492646c9fSVladimir Kondratiev 41592646c9fSVladimir Kondratiev if (!bcon->proberesp_ies) { 41692646c9fSVladimir Kondratiev bcon->proberesp_ies = f->u.probe_resp.variable; 41792646c9fSVladimir Kondratiev bcon->proberesp_ies_len = bcon->probe_resp_len - hlen; 41892646c9fSVladimir Kondratiev rc = 1; 41992646c9fSVladimir Kondratiev } 42092646c9fSVladimir Kondratiev if (!bcon->assocresp_ies) { 42192646c9fSVladimir Kondratiev bcon->assocresp_ies = f->u.probe_resp.variable; 42292646c9fSVladimir Kondratiev bcon->assocresp_ies_len = bcon->probe_resp_len - hlen; 42392646c9fSVladimir Kondratiev rc = 1; 42492646c9fSVladimir Kondratiev } 42592646c9fSVladimir Kondratiev 42692646c9fSVladimir Kondratiev return rc; 42792646c9fSVladimir Kondratiev } 42892646c9fSVladimir Kondratiev 4292be7d22fSVladimir Kondratiev static int wil_cfg80211_start_ap(struct wiphy *wiphy, 4302be7d22fSVladimir Kondratiev struct net_device *ndev, 4312be7d22fSVladimir Kondratiev struct cfg80211_ap_settings *info) 4322be7d22fSVladimir Kondratiev { 4332be7d22fSVladimir Kondratiev int rc = 0; 4342be7d22fSVladimir Kondratiev struct wil6210_priv *wil = wiphy_to_wil(wiphy); 4352be7d22fSVladimir Kondratiev struct wireless_dev *wdev = ndev->ieee80211_ptr; 4362be7d22fSVladimir Kondratiev struct ieee80211_channel *channel = info->chandef.chan; 4372be7d22fSVladimir Kondratiev struct cfg80211_beacon_data *bcon = &info->beacon; 4382be7d22fSVladimir Kondratiev u8 wmi_nettype = wil_iftype_nl2wmi(wdev->iftype); 4392be7d22fSVladimir Kondratiev 4402be7d22fSVladimir Kondratiev if (!channel) { 4412be7d22fSVladimir Kondratiev wil_err(wil, "AP: No channel???\n"); 4422be7d22fSVladimir Kondratiev return -EINVAL; 4432be7d22fSVladimir Kondratiev } 4442be7d22fSVladimir Kondratiev 4457743882dSVladimir Kondratiev wil_dbg_misc(wil, "AP on Channel %d %d MHz, %s\n", channel->hw_value, 4462be7d22fSVladimir Kondratiev channel->center_freq, info->privacy ? "secure" : "open"); 4472be7d22fSVladimir Kondratiev print_hex_dump_bytes("SSID ", DUMP_PREFIX_OFFSET, 4482be7d22fSVladimir Kondratiev info->ssid, info->ssid_len); 4492be7d22fSVladimir Kondratiev 45092646c9fSVladimir Kondratiev if (wil_fix_bcon(wil, bcon)) 45192646c9fSVladimir Kondratiev wil_dbg_misc(wil, "Fixed bcon\n"); 45292646c9fSVladimir Kondratiev 4532be7d22fSVladimir Kondratiev rc = wil_reset(wil); 4542be7d22fSVladimir Kondratiev if (rc) 4552be7d22fSVladimir Kondratiev return rc; 4562be7d22fSVladimir Kondratiev 457e31b2562SVladimir Kondratiev /* Rx VRING. */ 458e31b2562SVladimir Kondratiev rc = wil_rx_init(wil); 459e31b2562SVladimir Kondratiev if (rc) 460e31b2562SVladimir Kondratiev return rc; 461e31b2562SVladimir Kondratiev 4622be7d22fSVladimir Kondratiev rc = wmi_set_ssid(wil, info->ssid_len, info->ssid); 4632be7d22fSVladimir Kondratiev if (rc) 4642be7d22fSVladimir Kondratiev return rc; 4652be7d22fSVladimir Kondratiev 4662be7d22fSVladimir Kondratiev /* MAC address - pre-requisite for other commands */ 4672be7d22fSVladimir Kondratiev wmi_set_mac_address(wil, ndev->dev_addr); 4682be7d22fSVladimir Kondratiev 4692be7d22fSVladimir Kondratiev /* IE's */ 4702be7d22fSVladimir Kondratiev /* bcon 'head IE's are not relevant for 60g band */ 471b1defa4dSVladimir Kondratiev /* 472b1defa4dSVladimir Kondratiev * FW do not form regular beacon, so bcon IE's are not set 473b1defa4dSVladimir Kondratiev * For the DMG bcon, when it will be supported, bcon IE's will 474b1defa4dSVladimir Kondratiev * be reused; add something like: 475b1defa4dSVladimir Kondratiev * wmi_set_ie(wil, WMI_FRAME_BEACON, bcon->beacon_ies_len, 476b1defa4dSVladimir Kondratiev * bcon->beacon_ies); 477b1defa4dSVladimir Kondratiev */ 4782be7d22fSVladimir Kondratiev wmi_set_ie(wil, WMI_FRAME_PROBE_RESP, bcon->proberesp_ies_len, 4792be7d22fSVladimir Kondratiev bcon->proberesp_ies); 4802be7d22fSVladimir Kondratiev wmi_set_ie(wil, WMI_FRAME_ASSOC_RESP, bcon->assocresp_ies_len, 4812be7d22fSVladimir Kondratiev bcon->assocresp_ies); 4822be7d22fSVladimir Kondratiev 4832be7d22fSVladimir Kondratiev wil->secure_pcp = info->privacy; 4842be7d22fSVladimir Kondratiev 485b8023177SVladimir Kondratiev rc = wmi_pcp_start(wil, info->beacon_interval, wmi_nettype, 486b8023177SVladimir Kondratiev channel->hw_value); 4872be7d22fSVladimir Kondratiev if (rc) 4882be7d22fSVladimir Kondratiev return rc; 4892be7d22fSVladimir Kondratiev 4902be7d22fSVladimir Kondratiev 4912be7d22fSVladimir Kondratiev netif_carrier_on(ndev); 4922be7d22fSVladimir Kondratiev 4932be7d22fSVladimir Kondratiev return rc; 4942be7d22fSVladimir Kondratiev } 4952be7d22fSVladimir Kondratiev 4962be7d22fSVladimir Kondratiev static int wil_cfg80211_stop_ap(struct wiphy *wiphy, 4972be7d22fSVladimir Kondratiev struct net_device *ndev) 4982be7d22fSVladimir Kondratiev { 4992be7d22fSVladimir Kondratiev int rc = 0; 5002be7d22fSVladimir Kondratiev struct wil6210_priv *wil = wiphy_to_wil(wiphy); 5012be7d22fSVladimir Kondratiev 502b8023177SVladimir Kondratiev rc = wmi_pcp_stop(wil); 5032be7d22fSVladimir Kondratiev 5042be7d22fSVladimir Kondratiev return rc; 5052be7d22fSVladimir Kondratiev } 5062be7d22fSVladimir Kondratiev 5072be7d22fSVladimir Kondratiev static struct cfg80211_ops wil_cfg80211_ops = { 5082be7d22fSVladimir Kondratiev .scan = wil_cfg80211_scan, 5092be7d22fSVladimir Kondratiev .connect = wil_cfg80211_connect, 5102be7d22fSVladimir Kondratiev .disconnect = wil_cfg80211_disconnect, 5112be7d22fSVladimir Kondratiev .change_virtual_intf = wil_cfg80211_change_iface, 5122be7d22fSVladimir Kondratiev .get_station = wil_cfg80211_get_station, 5132be7d22fSVladimir Kondratiev .set_monitor_channel = wil_cfg80211_set_channel, 5142be7d22fSVladimir Kondratiev .add_key = wil_cfg80211_add_key, 5152be7d22fSVladimir Kondratiev .del_key = wil_cfg80211_del_key, 5162be7d22fSVladimir Kondratiev .set_default_key = wil_cfg80211_set_default_key, 5172be7d22fSVladimir Kondratiev /* AP mode */ 5182be7d22fSVladimir Kondratiev .start_ap = wil_cfg80211_start_ap, 5192be7d22fSVladimir Kondratiev .stop_ap = wil_cfg80211_stop_ap, 5202be7d22fSVladimir Kondratiev }; 5212be7d22fSVladimir Kondratiev 5222be7d22fSVladimir Kondratiev static void wil_wiphy_init(struct wiphy *wiphy) 5232be7d22fSVladimir Kondratiev { 5242be7d22fSVladimir Kondratiev /* TODO: set real value */ 5252be7d22fSVladimir Kondratiev wiphy->max_scan_ssids = 10; 5262be7d22fSVladimir Kondratiev wiphy->max_num_pmkids = 0 /* TODO: */; 5272be7d22fSVladimir Kondratiev wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | 5282be7d22fSVladimir Kondratiev BIT(NL80211_IFTYPE_AP) | 5292be7d22fSVladimir Kondratiev BIT(NL80211_IFTYPE_MONITOR); 5302be7d22fSVladimir Kondratiev /* TODO: enable P2P when integrated with supplicant: 5312be7d22fSVladimir Kondratiev * BIT(NL80211_IFTYPE_P2P_CLIENT) | BIT(NL80211_IFTYPE_P2P_GO) 5322be7d22fSVladimir Kondratiev */ 5332be7d22fSVladimir Kondratiev wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME | 5342be7d22fSVladimir Kondratiev WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD; 5352be7d22fSVladimir Kondratiev dev_warn(wiphy_dev(wiphy), "%s : flags = 0x%08x\n", 5362be7d22fSVladimir Kondratiev __func__, wiphy->flags); 5372be7d22fSVladimir Kondratiev wiphy->probe_resp_offload = 5382be7d22fSVladimir Kondratiev NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS | 5392be7d22fSVladimir Kondratiev NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 | 5402be7d22fSVladimir Kondratiev NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P; 5412be7d22fSVladimir Kondratiev 5422be7d22fSVladimir Kondratiev wiphy->bands[IEEE80211_BAND_60GHZ] = &wil_band_60ghz; 5432be7d22fSVladimir Kondratiev 5442be7d22fSVladimir Kondratiev /* TODO: figure this out */ 5452be7d22fSVladimir Kondratiev wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM; 5462be7d22fSVladimir Kondratiev 5472be7d22fSVladimir Kondratiev wiphy->cipher_suites = wil_cipher_suites; 5482be7d22fSVladimir Kondratiev wiphy->n_cipher_suites = ARRAY_SIZE(wil_cipher_suites); 5492be7d22fSVladimir Kondratiev wiphy->mgmt_stypes = wil_mgmt_stypes; 5502be7d22fSVladimir Kondratiev } 5512be7d22fSVladimir Kondratiev 5522be7d22fSVladimir Kondratiev struct wireless_dev *wil_cfg80211_init(struct device *dev) 5532be7d22fSVladimir Kondratiev { 5542be7d22fSVladimir Kondratiev int rc = 0; 5552be7d22fSVladimir Kondratiev struct wireless_dev *wdev; 5562be7d22fSVladimir Kondratiev 5572be7d22fSVladimir Kondratiev wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL); 5582be7d22fSVladimir Kondratiev if (!wdev) 5592be7d22fSVladimir Kondratiev return ERR_PTR(-ENOMEM); 5602be7d22fSVladimir Kondratiev 5612be7d22fSVladimir Kondratiev wdev->wiphy = wiphy_new(&wil_cfg80211_ops, 5622be7d22fSVladimir Kondratiev sizeof(struct wil6210_priv)); 5632be7d22fSVladimir Kondratiev if (!wdev->wiphy) { 5642be7d22fSVladimir Kondratiev rc = -ENOMEM; 5652be7d22fSVladimir Kondratiev goto out; 5662be7d22fSVladimir Kondratiev } 5672be7d22fSVladimir Kondratiev 5682be7d22fSVladimir Kondratiev set_wiphy_dev(wdev->wiphy, dev); 5692be7d22fSVladimir Kondratiev wil_wiphy_init(wdev->wiphy); 5702be7d22fSVladimir Kondratiev 5712be7d22fSVladimir Kondratiev rc = wiphy_register(wdev->wiphy); 5722be7d22fSVladimir Kondratiev if (rc < 0) 5732be7d22fSVladimir Kondratiev goto out_failed_reg; 5742be7d22fSVladimir Kondratiev 5752be7d22fSVladimir Kondratiev return wdev; 5762be7d22fSVladimir Kondratiev 5772be7d22fSVladimir Kondratiev out_failed_reg: 5782be7d22fSVladimir Kondratiev wiphy_free(wdev->wiphy); 5792be7d22fSVladimir Kondratiev out: 5802be7d22fSVladimir Kondratiev kfree(wdev); 5812be7d22fSVladimir Kondratiev 5822be7d22fSVladimir Kondratiev return ERR_PTR(rc); 5832be7d22fSVladimir Kondratiev } 5842be7d22fSVladimir Kondratiev 5852be7d22fSVladimir Kondratiev void wil_wdev_free(struct wil6210_priv *wil) 5862be7d22fSVladimir Kondratiev { 5872be7d22fSVladimir Kondratiev struct wireless_dev *wdev = wil_to_wdev(wil); 5882be7d22fSVladimir Kondratiev 5892be7d22fSVladimir Kondratiev if (!wdev) 5902be7d22fSVladimir Kondratiev return; 5912be7d22fSVladimir Kondratiev 5922be7d22fSVladimir Kondratiev wiphy_unregister(wdev->wiphy); 5932be7d22fSVladimir Kondratiev wiphy_free(wdev->wiphy); 5942be7d22fSVladimir Kondratiev kfree(wdev); 5952be7d22fSVladimir Kondratiev } 596