Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012 Qualcomm Atheros, Inc. |
| 3 | * |
| 4 | * Permission to use, copy, modify, and/or distribute this software for any |
| 5 | * purpose with or without fee is hereby granted, provided that the above |
| 6 | * copyright notice and this permission notice appear in all copies. |
| 7 | * |
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 15 | */ |
| 16 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 17 | #include "wil6210.h" |
| 18 | #include "wmi.h" |
| 19 | |
| 20 | #define CHAN60G(_channel, _flags) { \ |
| 21 | .band = IEEE80211_BAND_60GHZ, \ |
| 22 | .center_freq = 56160 + (2160 * (_channel)), \ |
| 23 | .hw_value = (_channel), \ |
| 24 | .flags = (_flags), \ |
| 25 | .max_antenna_gain = 0, \ |
| 26 | .max_power = 40, \ |
| 27 | } |
| 28 | |
| 29 | static struct ieee80211_channel wil_60ghz_channels[] = { |
| 30 | CHAN60G(1, 0), |
| 31 | CHAN60G(2, 0), |
| 32 | CHAN60G(3, 0), |
| 33 | /* channel 4 not supported yet */ |
| 34 | }; |
| 35 | |
| 36 | static struct ieee80211_supported_band wil_band_60ghz = { |
| 37 | .channels = wil_60ghz_channels, |
| 38 | .n_channels = ARRAY_SIZE(wil_60ghz_channels), |
| 39 | .ht_cap = { |
| 40 | .ht_supported = true, |
| 41 | .cap = 0, /* TODO */ |
| 42 | .ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K, /* TODO */ |
| 43 | .ampdu_density = IEEE80211_HT_MPDU_DENSITY_8, /* TODO */ |
| 44 | .mcs = { |
| 45 | /* MCS 1..12 - SC PHY */ |
| 46 | .rx_mask = {0xfe, 0x1f}, /* 1..12 */ |
| 47 | .tx_params = IEEE80211_HT_MCS_TX_DEFINED, /* TODO */ |
| 48 | }, |
| 49 | }, |
| 50 | }; |
| 51 | |
| 52 | static const struct ieee80211_txrx_stypes |
| 53 | wil_mgmt_stypes[NUM_NL80211_IFTYPES] = { |
| 54 | [NL80211_IFTYPE_STATION] = { |
| 55 | .tx = BIT(IEEE80211_STYPE_ACTION >> 4) | |
| 56 | BIT(IEEE80211_STYPE_PROBE_RESP >> 4), |
| 57 | .rx = BIT(IEEE80211_STYPE_ACTION >> 4) | |
| 58 | BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
| 59 | }, |
| 60 | [NL80211_IFTYPE_AP] = { |
| 61 | .tx = BIT(IEEE80211_STYPE_ACTION >> 4) | |
| 62 | BIT(IEEE80211_STYPE_PROBE_RESP >> 4), |
| 63 | .rx = BIT(IEEE80211_STYPE_ACTION >> 4) | |
| 64 | BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
| 65 | }, |
| 66 | [NL80211_IFTYPE_P2P_CLIENT] = { |
| 67 | .tx = BIT(IEEE80211_STYPE_ACTION >> 4) | |
| 68 | BIT(IEEE80211_STYPE_PROBE_RESP >> 4), |
| 69 | .rx = BIT(IEEE80211_STYPE_ACTION >> 4) | |
| 70 | BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
| 71 | }, |
| 72 | [NL80211_IFTYPE_P2P_GO] = { |
| 73 | .tx = BIT(IEEE80211_STYPE_ACTION >> 4) | |
| 74 | BIT(IEEE80211_STYPE_PROBE_RESP >> 4), |
| 75 | .rx = BIT(IEEE80211_STYPE_ACTION >> 4) | |
| 76 | BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
| 77 | }, |
| 78 | }; |
| 79 | |
| 80 | static const u32 wil_cipher_suites[] = { |
| 81 | WLAN_CIPHER_SUITE_GCMP, |
| 82 | }; |
| 83 | |
| 84 | int wil_iftype_nl2wmi(enum nl80211_iftype type) |
| 85 | { |
| 86 | static const struct { |
| 87 | enum nl80211_iftype nl; |
| 88 | enum wmi_network_type wmi; |
| 89 | } __nl2wmi[] = { |
| 90 | {NL80211_IFTYPE_ADHOC, WMI_NETTYPE_ADHOC}, |
| 91 | {NL80211_IFTYPE_STATION, WMI_NETTYPE_INFRA}, |
| 92 | {NL80211_IFTYPE_AP, WMI_NETTYPE_AP}, |
| 93 | {NL80211_IFTYPE_P2P_CLIENT, WMI_NETTYPE_P2P}, |
| 94 | {NL80211_IFTYPE_P2P_GO, WMI_NETTYPE_P2P}, |
| 95 | {NL80211_IFTYPE_MONITOR, WMI_NETTYPE_ADHOC}, /* FIXME */ |
| 96 | }; |
| 97 | uint i; |
| 98 | |
| 99 | for (i = 0; i < ARRAY_SIZE(__nl2wmi); i++) { |
| 100 | if (__nl2wmi[i].nl == type) |
| 101 | return __nl2wmi[i].wmi; |
| 102 | } |
| 103 | |
| 104 | return -EOPNOTSUPP; |
| 105 | } |
| 106 | |
Vladimir Kondratiev | ef28afd | 2014-02-27 16:20:48 +0200 | [diff] [blame] | 107 | static int wil_cid_fill_sinfo(struct wil6210_priv *wil, int cid, |
| 108 | struct station_info *sinfo) |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 109 | { |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 110 | struct wmi_notify_req_cmd cmd = { |
Vladimir Kondratiev | 3df2cd36 | 2014-02-27 16:20:43 +0200 | [diff] [blame] | 111 | .cid = cid, |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 112 | .interval_usec = 0, |
| 113 | }; |
Vladimir Kondratiev | ef28afd | 2014-02-27 16:20:48 +0200 | [diff] [blame] | 114 | struct { |
| 115 | struct wil6210_mbox_hdr_wmi wmi; |
| 116 | struct wmi_notify_req_done_event evt; |
| 117 | } __packed reply; |
Vladimir Kondratiev | c8b78b5 | 2014-02-27 16:20:49 +0200 | [diff] [blame] | 118 | struct wil_net_stats *stats = &wil->sta[cid].stats; |
Vladimir Kondratiev | ef28afd | 2014-02-27 16:20:48 +0200 | [diff] [blame] | 119 | int rc; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 120 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 121 | rc = wmi_call(wil, WMI_NOTIFY_REQ_CMDID, &cmd, sizeof(cmd), |
Vladimir Kondratiev | ef28afd | 2014-02-27 16:20:48 +0200 | [diff] [blame] | 122 | WMI_NOTIFY_REQ_DONE_EVENTID, &reply, sizeof(reply), 20); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 123 | if (rc) |
| 124 | return rc; |
| 125 | |
Vladimir Kondratiev | c8b78b5 | 2014-02-27 16:20:49 +0200 | [diff] [blame] | 126 | wil_dbg_wmi(wil, "Link status for CID %d: {\n" |
| 127 | " MCS %d TSF 0x%016llx\n" |
Vladimir Kondratiev | b8b33a3 | 2014-02-27 16:20:52 +0200 | [diff] [blame] | 128 | " BF status 0x%08x SNR 0x%08x SQI %d%%\n" |
Vladimir Kondratiev | c8b78b5 | 2014-02-27 16:20:49 +0200 | [diff] [blame] | 129 | " Tx Tpt %d goodput %d Rx goodput %d\n" |
| 130 | " Sectors(rx:tx) my %d:%d peer %d:%d\n""}\n", |
| 131 | cid, le16_to_cpu(reply.evt.bf_mcs), |
| 132 | le64_to_cpu(reply.evt.tsf), reply.evt.status, |
| 133 | le32_to_cpu(reply.evt.snr_val), |
Vladimir Kondratiev | b8b33a3 | 2014-02-27 16:20:52 +0200 | [diff] [blame] | 134 | reply.evt.sqi, |
Vladimir Kondratiev | c8b78b5 | 2014-02-27 16:20:49 +0200 | [diff] [blame] | 135 | le32_to_cpu(reply.evt.tx_tpt), |
| 136 | le32_to_cpu(reply.evt.tx_goodput), |
| 137 | le32_to_cpu(reply.evt.rx_goodput), |
| 138 | le16_to_cpu(reply.evt.my_rx_sector), |
| 139 | le16_to_cpu(reply.evt.my_tx_sector), |
| 140 | le16_to_cpu(reply.evt.other_rx_sector), |
| 141 | le16_to_cpu(reply.evt.other_tx_sector)); |
| 142 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 143 | sinfo->generation = wil->sinfo_gen; |
| 144 | |
Vladimir Kondratiev | c8b78b5 | 2014-02-27 16:20:49 +0200 | [diff] [blame] | 145 | sinfo->filled = STATION_INFO_RX_BYTES | |
| 146 | STATION_INFO_TX_BYTES | |
| 147 | STATION_INFO_RX_PACKETS | |
| 148 | STATION_INFO_TX_PACKETS | |
| 149 | STATION_INFO_RX_BITRATE | |
| 150 | STATION_INFO_TX_BITRATE | |
| 151 | STATION_INFO_RX_DROP_MISC | |
| 152 | STATION_INFO_TX_FAILED; |
| 153 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 154 | sinfo->txrate.flags = RATE_INFO_FLAGS_MCS | RATE_INFO_FLAGS_60G; |
Vladimir Kondratiev | ef28afd | 2014-02-27 16:20:48 +0200 | [diff] [blame] | 155 | sinfo->txrate.mcs = le16_to_cpu(reply.evt.bf_mcs); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 156 | sinfo->rxrate.flags = RATE_INFO_FLAGS_MCS | RATE_INFO_FLAGS_60G; |
Vladimir Kondratiev | c8b78b5 | 2014-02-27 16:20:49 +0200 | [diff] [blame] | 157 | sinfo->rxrate.mcs = stats->last_mcs_rx; |
| 158 | sinfo->rx_bytes = stats->rx_bytes; |
| 159 | sinfo->rx_packets = stats->rx_packets; |
| 160 | sinfo->rx_dropped_misc = stats->rx_dropped; |
| 161 | sinfo->tx_bytes = stats->tx_bytes; |
| 162 | sinfo->tx_packets = stats->tx_packets; |
| 163 | sinfo->tx_failed = stats->tx_errors; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 164 | |
| 165 | if (test_bit(wil_status_fwconnected, &wil->status)) { |
| 166 | sinfo->filled |= STATION_INFO_SIGNAL; |
Vladimir Kondratiev | b8b33a3 | 2014-02-27 16:20:52 +0200 | [diff] [blame] | 167 | sinfo->signal = reply.evt.sqi; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 168 | } |
| 169 | |
Vladimir Kondratiev | ef28afd | 2014-02-27 16:20:48 +0200 | [diff] [blame] | 170 | return rc; |
| 171 | } |
| 172 | |
| 173 | static int wil_cfg80211_get_station(struct wiphy *wiphy, |
| 174 | struct net_device *ndev, |
| 175 | u8 *mac, struct station_info *sinfo) |
| 176 | { |
| 177 | struct wil6210_priv *wil = wiphy_to_wil(wiphy); |
| 178 | int rc; |
| 179 | |
| 180 | int cid = wil_find_cid(wil, mac); |
| 181 | |
Vladimir Kondratiev | fa4a18e | 2014-03-17 15:34:16 +0200 | [diff] [blame] | 182 | wil_dbg_misc(wil, "%s(%pM) CID %d\n", __func__, mac, cid); |
Vladimir Kondratiev | ef28afd | 2014-02-27 16:20:48 +0200 | [diff] [blame] | 183 | if (cid < 0) |
Vladimir Kondratiev | c14c5d9 | 2014-03-02 11:20:51 +0200 | [diff] [blame] | 184 | return cid; |
Vladimir Kondratiev | ef28afd | 2014-02-27 16:20:48 +0200 | [diff] [blame] | 185 | |
| 186 | rc = wil_cid_fill_sinfo(wil, cid, sinfo); |
| 187 | |
| 188 | return rc; |
| 189 | } |
| 190 | |
| 191 | /* |
| 192 | * Find @idx-th active STA for station dump. |
| 193 | */ |
| 194 | static int wil_find_cid_by_idx(struct wil6210_priv *wil, int idx) |
| 195 | { |
| 196 | int i; |
| 197 | |
| 198 | for (i = 0; i < ARRAY_SIZE(wil->sta); i++) { |
| 199 | if (wil->sta[i].status == wil_sta_unused) |
| 200 | continue; |
| 201 | if (idx == 0) |
| 202 | return i; |
| 203 | idx--; |
| 204 | } |
| 205 | |
| 206 | return -ENOENT; |
| 207 | } |
| 208 | |
| 209 | static int wil_cfg80211_dump_station(struct wiphy *wiphy, |
| 210 | struct net_device *dev, int idx, |
| 211 | u8 *mac, struct station_info *sinfo) |
| 212 | { |
| 213 | struct wil6210_priv *wil = wiphy_to_wil(wiphy); |
| 214 | int rc; |
| 215 | int cid = wil_find_cid_by_idx(wil, idx); |
| 216 | |
| 217 | if (cid < 0) |
| 218 | return -ENOENT; |
| 219 | |
| 220 | memcpy(mac, wil->sta[cid].addr, ETH_ALEN); |
Vladimir Kondratiev | fa4a18e | 2014-03-17 15:34:16 +0200 | [diff] [blame] | 221 | wil_dbg_misc(wil, "%s(%pM) CID %d\n", __func__, mac, cid); |
Vladimir Kondratiev | ef28afd | 2014-02-27 16:20:48 +0200 | [diff] [blame] | 222 | |
| 223 | rc = wil_cid_fill_sinfo(wil, cid, sinfo); |
| 224 | |
| 225 | return rc; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | static int wil_cfg80211_change_iface(struct wiphy *wiphy, |
| 229 | struct net_device *ndev, |
| 230 | enum nl80211_iftype type, u32 *flags, |
| 231 | struct vif_params *params) |
| 232 | { |
| 233 | struct wil6210_priv *wil = wiphy_to_wil(wiphy); |
| 234 | struct wireless_dev *wdev = wil->wdev; |
| 235 | |
| 236 | switch (type) { |
| 237 | case NL80211_IFTYPE_STATION: |
| 238 | case NL80211_IFTYPE_AP: |
| 239 | case NL80211_IFTYPE_P2P_CLIENT: |
| 240 | case NL80211_IFTYPE_P2P_GO: |
| 241 | break; |
| 242 | case NL80211_IFTYPE_MONITOR: |
| 243 | if (flags) |
| 244 | wil->monitor_flags = *flags; |
| 245 | else |
| 246 | wil->monitor_flags = 0; |
| 247 | |
| 248 | break; |
| 249 | default: |
| 250 | return -EOPNOTSUPP; |
| 251 | } |
| 252 | |
| 253 | wdev->iftype = type; |
| 254 | |
| 255 | return 0; |
| 256 | } |
| 257 | |
| 258 | static int wil_cfg80211_scan(struct wiphy *wiphy, |
| 259 | struct cfg80211_scan_request *request) |
| 260 | { |
| 261 | struct wil6210_priv *wil = wiphy_to_wil(wiphy); |
| 262 | struct wireless_dev *wdev = wil->wdev; |
| 263 | struct { |
| 264 | struct wmi_start_scan_cmd cmd; |
| 265 | u16 chnl[4]; |
| 266 | } __packed cmd; |
| 267 | uint i, n; |
Vladimir Kondratiev | ed6f9dc | 2014-03-17 15:34:19 +0200 | [diff] [blame] | 268 | int rc; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 269 | |
| 270 | if (wil->scan_request) { |
| 271 | wil_err(wil, "Already scanning\n"); |
| 272 | return -EAGAIN; |
| 273 | } |
| 274 | |
| 275 | /* check we are client side */ |
| 276 | switch (wdev->iftype) { |
| 277 | case NL80211_IFTYPE_STATION: |
| 278 | case NL80211_IFTYPE_P2P_CLIENT: |
| 279 | break; |
| 280 | default: |
| 281 | return -EOPNOTSUPP; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | /* FW don't support scan after connection attempt */ |
| 285 | if (test_bit(wil_status_dontscan, &wil->status)) { |
Vladimir Kondratiev | e83eb2f | 2014-03-17 15:34:07 +0200 | [diff] [blame] | 286 | wil_err(wil, "Can't scan now\n"); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 287 | return -EBUSY; |
| 288 | } |
| 289 | |
| 290 | wil->scan_request = request; |
| 291 | |
| 292 | memset(&cmd, 0, sizeof(cmd)); |
| 293 | cmd.cmd.num_channels = 0; |
| 294 | n = min(request->n_channels, 4U); |
| 295 | for (i = 0; i < n; i++) { |
| 296 | int ch = request->channels[i]->hw_value; |
| 297 | if (ch == 0) { |
| 298 | wil_err(wil, |
| 299 | "Scan requested for unknown frequency %dMhz\n", |
| 300 | request->channels[i]->center_freq); |
| 301 | continue; |
| 302 | } |
| 303 | /* 0-based channel indexes */ |
| 304 | cmd.cmd.channel_list[cmd.cmd.num_channels++].channel = ch - 1; |
Vladimir Kondratiev | 7743882 | 2013-01-28 18:31:06 +0200 | [diff] [blame] | 305 | wil_dbg_misc(wil, "Scan for ch %d : %d MHz\n", ch, |
Vladimir Kondratiev | 2057ebb | 2013-01-28 18:30:58 +0200 | [diff] [blame] | 306 | request->channels[i]->center_freq); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 307 | } |
| 308 | |
Vladimir Kondratiev | ed6f9dc | 2014-03-17 15:34:19 +0200 | [diff] [blame] | 309 | rc = wmi_send(wil, WMI_START_SCAN_CMDID, &cmd, sizeof(cmd.cmd) + |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 310 | cmd.cmd.num_channels * sizeof(cmd.cmd.channel_list[0])); |
Vladimir Kondratiev | ed6f9dc | 2014-03-17 15:34:19 +0200 | [diff] [blame] | 311 | |
| 312 | if (rc) |
| 313 | wil->scan_request = NULL; |
| 314 | |
| 315 | return rc; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | static int wil_cfg80211_connect(struct wiphy *wiphy, |
| 319 | struct net_device *ndev, |
| 320 | struct cfg80211_connect_params *sme) |
| 321 | { |
| 322 | struct wil6210_priv *wil = wiphy_to_wil(wiphy); |
| 323 | struct cfg80211_bss *bss; |
| 324 | struct wmi_connect_cmd conn; |
| 325 | const u8 *ssid_eid; |
| 326 | const u8 *rsn_eid; |
| 327 | int ch; |
| 328 | int rc = 0; |
| 329 | |
Vladimir Kondratiev | 4cd9e83 | 2014-03-17 15:34:20 +0200 | [diff] [blame^] | 330 | if (test_bit(wil_status_fwconnecting, &wil->status) || |
| 331 | test_bit(wil_status_fwconnected, &wil->status)) |
| 332 | return -EALREADY; |
| 333 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 334 | bss = cfg80211_get_bss(wiphy, sme->channel, sme->bssid, |
| 335 | sme->ssid, sme->ssid_len, |
| 336 | WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS); |
| 337 | if (!bss) { |
| 338 | wil_err(wil, "Unable to find BSS\n"); |
| 339 | return -ENOENT; |
| 340 | } |
| 341 | |
| 342 | ssid_eid = ieee80211_bss_get_ie(bss, WLAN_EID_SSID); |
| 343 | if (!ssid_eid) { |
| 344 | wil_err(wil, "No SSID\n"); |
| 345 | rc = -ENOENT; |
| 346 | goto out; |
| 347 | } |
| 348 | |
| 349 | rsn_eid = sme->ie ? |
| 350 | cfg80211_find_ie(WLAN_EID_RSN, sme->ie, sme->ie_len) : |
| 351 | NULL; |
| 352 | if (rsn_eid) { |
| 353 | if (sme->ie_len > WMI_MAX_IE_LEN) { |
| 354 | rc = -ERANGE; |
| 355 | wil_err(wil, "IE too large (%td bytes)\n", |
| 356 | sme->ie_len); |
| 357 | goto out; |
| 358 | } |
| 359 | /* |
| 360 | * For secure assoc, send: |
| 361 | * (1) WMI_DELETE_CIPHER_KEY_CMD |
| 362 | * (2) WMI_SET_APPIE_CMD |
| 363 | */ |
| 364 | rc = wmi_del_cipher_key(wil, 0, bss->bssid); |
| 365 | if (rc) { |
| 366 | wil_err(wil, "WMI_DELETE_CIPHER_KEY_CMD failed\n"); |
| 367 | goto out; |
| 368 | } |
| 369 | /* WMI_SET_APPIE_CMD */ |
| 370 | rc = wmi_set_ie(wil, WMI_FRAME_ASSOC_REQ, sme->ie_len, sme->ie); |
| 371 | if (rc) { |
| 372 | wil_err(wil, "WMI_SET_APPIE_CMD failed\n"); |
| 373 | goto out; |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | /* WMI_CONNECT_CMD */ |
| 378 | memset(&conn, 0, sizeof(conn)); |
Vladimir Kondratiev | acc9780 | 2013-03-13 14:12:47 +0200 | [diff] [blame] | 379 | switch (bss->capability & WLAN_CAPABILITY_DMG_TYPE_MASK) { |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 380 | case WLAN_CAPABILITY_DMG_TYPE_AP: |
| 381 | conn.network_type = WMI_NETTYPE_INFRA; |
| 382 | break; |
| 383 | case WLAN_CAPABILITY_DMG_TYPE_PBSS: |
| 384 | conn.network_type = WMI_NETTYPE_P2P; |
| 385 | break; |
| 386 | default: |
| 387 | wil_err(wil, "Unsupported BSS type, capability= 0x%04x\n", |
| 388 | bss->capability); |
| 389 | goto out; |
| 390 | } |
| 391 | if (rsn_eid) { |
| 392 | conn.dot11_auth_mode = WMI_AUTH11_SHARED; |
| 393 | conn.auth_mode = WMI_AUTH_WPA2_PSK; |
| 394 | conn.pairwise_crypto_type = WMI_CRYPT_AES_GCMP; |
| 395 | conn.pairwise_crypto_len = 16; |
| 396 | } else { |
| 397 | conn.dot11_auth_mode = WMI_AUTH11_OPEN; |
| 398 | conn.auth_mode = WMI_AUTH_NONE; |
| 399 | } |
| 400 | |
| 401 | conn.ssid_len = min_t(u8, ssid_eid[1], 32); |
| 402 | memcpy(conn.ssid, ssid_eid+2, conn.ssid_len); |
| 403 | |
| 404 | ch = bss->channel->hw_value; |
| 405 | if (ch == 0) { |
| 406 | wil_err(wil, "BSS at unknown frequency %dMhz\n", |
| 407 | bss->channel->center_freq); |
| 408 | rc = -EOPNOTSUPP; |
| 409 | goto out; |
| 410 | } |
| 411 | conn.channel = ch - 1; |
| 412 | |
Joe Perches | d458cdf | 2013-10-01 19:04:40 -0700 | [diff] [blame] | 413 | memcpy(conn.bssid, bss->bssid, ETH_ALEN); |
| 414 | memcpy(conn.dst_mac, bss->bssid, ETH_ALEN); |
Vladimir Kondratiev | e83eb2f | 2014-03-17 15:34:07 +0200 | [diff] [blame] | 415 | |
Vladimir Kondratiev | b338f74 | 2013-05-28 15:17:53 +0300 | [diff] [blame] | 416 | set_bit(wil_status_fwconnecting, &wil->status); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 417 | |
| 418 | rc = wmi_send(wil, WMI_CONNECT_CMDID, &conn, sizeof(conn)); |
| 419 | if (rc == 0) { |
| 420 | /* Connect can take lots of time */ |
| 421 | mod_timer(&wil->connect_timer, |
| 422 | jiffies + msecs_to_jiffies(2000)); |
Vladimir Kondratiev | b338f74 | 2013-05-28 15:17:53 +0300 | [diff] [blame] | 423 | } else { |
Vladimir Kondratiev | b338f74 | 2013-05-28 15:17:53 +0300 | [diff] [blame] | 424 | clear_bit(wil_status_fwconnecting, &wil->status); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | out: |
Johannes Berg | 5b112d3 | 2013-02-01 01:49:58 +0100 | [diff] [blame] | 428 | cfg80211_put_bss(wiphy, bss); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 429 | |
| 430 | return rc; |
| 431 | } |
| 432 | |
| 433 | static int wil_cfg80211_disconnect(struct wiphy *wiphy, |
| 434 | struct net_device *ndev, |
| 435 | u16 reason_code) |
| 436 | { |
| 437 | int rc; |
| 438 | struct wil6210_priv *wil = wiphy_to_wil(wiphy); |
| 439 | |
| 440 | rc = wmi_send(wil, WMI_DISCONNECT_CMDID, NULL, 0); |
| 441 | |
| 442 | return rc; |
| 443 | } |
| 444 | |
Vladimir Kondratiev | 1647f12 | 2014-02-27 16:20:40 +0200 | [diff] [blame] | 445 | static int wil_cfg80211_mgmt_tx(struct wiphy *wiphy, |
| 446 | struct wireless_dev *wdev, |
| 447 | struct cfg80211_mgmt_tx_params *params, |
| 448 | u64 *cookie) |
| 449 | { |
| 450 | const u8 *buf = params->buf; |
| 451 | size_t len = params->len; |
| 452 | struct wil6210_priv *wil = wiphy_to_wil(wiphy); |
| 453 | int rc; |
| 454 | struct ieee80211_mgmt *mgmt_frame = (void *)buf; |
| 455 | struct wmi_sw_tx_req_cmd *cmd; |
| 456 | struct { |
| 457 | struct wil6210_mbox_hdr_wmi wmi; |
| 458 | struct wmi_sw_tx_complete_event evt; |
| 459 | } __packed evt; |
| 460 | |
| 461 | cmd = kmalloc(sizeof(*cmd) + len, GFP_KERNEL); |
| 462 | if (!cmd) |
| 463 | return -ENOMEM; |
| 464 | |
| 465 | memcpy(cmd->dst_mac, mgmt_frame->da, WMI_MAC_LEN); |
| 466 | cmd->len = cpu_to_le16(len); |
| 467 | memcpy(cmd->payload, buf, len); |
| 468 | |
| 469 | rc = wmi_call(wil, WMI_SW_TX_REQ_CMDID, cmd, sizeof(*cmd) + len, |
| 470 | WMI_SW_TX_COMPLETE_EVENTID, &evt, sizeof(evt), 2000); |
| 471 | if (rc == 0) |
| 472 | rc = evt.evt.status; |
| 473 | |
| 474 | kfree(cmd); |
| 475 | |
| 476 | return rc; |
| 477 | } |
| 478 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 479 | static int wil_cfg80211_set_channel(struct wiphy *wiphy, |
| 480 | struct cfg80211_chan_def *chandef) |
| 481 | { |
| 482 | struct wil6210_priv *wil = wiphy_to_wil(wiphy); |
| 483 | struct wireless_dev *wdev = wil->wdev; |
| 484 | |
| 485 | wdev->preset_chandef = *chandef; |
| 486 | |
| 487 | return 0; |
| 488 | } |
| 489 | |
| 490 | static int wil_cfg80211_add_key(struct wiphy *wiphy, |
| 491 | struct net_device *ndev, |
| 492 | u8 key_index, bool pairwise, |
| 493 | const u8 *mac_addr, |
| 494 | struct key_params *params) |
| 495 | { |
| 496 | struct wil6210_priv *wil = wiphy_to_wil(wiphy); |
| 497 | |
| 498 | /* group key is not used */ |
| 499 | if (!pairwise) |
| 500 | return 0; |
| 501 | |
| 502 | return wmi_add_cipher_key(wil, key_index, mac_addr, |
| 503 | params->key_len, params->key); |
| 504 | } |
| 505 | |
| 506 | static int wil_cfg80211_del_key(struct wiphy *wiphy, |
| 507 | struct net_device *ndev, |
| 508 | u8 key_index, bool pairwise, |
| 509 | const u8 *mac_addr) |
| 510 | { |
| 511 | struct wil6210_priv *wil = wiphy_to_wil(wiphy); |
| 512 | |
| 513 | /* group key is not used */ |
| 514 | if (!pairwise) |
| 515 | return 0; |
| 516 | |
| 517 | return wmi_del_cipher_key(wil, key_index, mac_addr); |
| 518 | } |
| 519 | |
| 520 | /* Need to be present or wiphy_new() will WARN */ |
| 521 | static int wil_cfg80211_set_default_key(struct wiphy *wiphy, |
| 522 | struct net_device *ndev, |
| 523 | u8 key_index, bool unicast, |
| 524 | bool multicast) |
| 525 | { |
| 526 | return 0; |
| 527 | } |
| 528 | |
Vladimir Kondratiev | 1647f12 | 2014-02-27 16:20:40 +0200 | [diff] [blame] | 529 | static int wil_remain_on_channel(struct wiphy *wiphy, |
| 530 | struct wireless_dev *wdev, |
| 531 | struct ieee80211_channel *chan, |
| 532 | unsigned int duration, |
| 533 | u64 *cookie) |
| 534 | { |
| 535 | struct wil6210_priv *wil = wiphy_to_wil(wiphy); |
| 536 | int rc; |
| 537 | |
| 538 | /* TODO: handle duration */ |
| 539 | wil_info(wil, "%s(%d, %d ms)\n", __func__, chan->center_freq, duration); |
| 540 | |
| 541 | rc = wmi_set_channel(wil, chan->hw_value); |
| 542 | if (rc) |
| 543 | return rc; |
| 544 | |
| 545 | rc = wmi_rxon(wil, true); |
| 546 | |
| 547 | return rc; |
| 548 | } |
| 549 | |
| 550 | static int wil_cancel_remain_on_channel(struct wiphy *wiphy, |
| 551 | struct wireless_dev *wdev, |
| 552 | u64 cookie) |
| 553 | { |
| 554 | struct wil6210_priv *wil = wiphy_to_wil(wiphy); |
| 555 | int rc; |
| 556 | |
| 557 | wil_info(wil, "%s()\n", __func__); |
| 558 | |
| 559 | rc = wmi_rxon(wil, false); |
| 560 | |
| 561 | return rc; |
| 562 | } |
| 563 | |
Vladimir Kondratiev | 92646c9 | 2013-06-09 09:12:53 +0300 | [diff] [blame] | 564 | static int wil_fix_bcon(struct wil6210_priv *wil, |
| 565 | struct cfg80211_beacon_data *bcon) |
| 566 | { |
| 567 | struct ieee80211_mgmt *f = (struct ieee80211_mgmt *)bcon->probe_resp; |
| 568 | size_t hlen = offsetof(struct ieee80211_mgmt, u.probe_resp.variable); |
| 569 | int rc = 0; |
| 570 | |
| 571 | if (bcon->probe_resp_len <= hlen) |
| 572 | return 0; |
| 573 | |
| 574 | if (!bcon->proberesp_ies) { |
| 575 | bcon->proberesp_ies = f->u.probe_resp.variable; |
| 576 | bcon->proberesp_ies_len = bcon->probe_resp_len - hlen; |
| 577 | rc = 1; |
| 578 | } |
| 579 | if (!bcon->assocresp_ies) { |
| 580 | bcon->assocresp_ies = f->u.probe_resp.variable; |
| 581 | bcon->assocresp_ies_len = bcon->probe_resp_len - hlen; |
| 582 | rc = 1; |
| 583 | } |
| 584 | |
| 585 | return rc; |
| 586 | } |
| 587 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 588 | static int wil_cfg80211_start_ap(struct wiphy *wiphy, |
| 589 | struct net_device *ndev, |
| 590 | struct cfg80211_ap_settings *info) |
| 591 | { |
| 592 | int rc = 0; |
| 593 | struct wil6210_priv *wil = wiphy_to_wil(wiphy); |
| 594 | struct wireless_dev *wdev = ndev->ieee80211_ptr; |
| 595 | struct ieee80211_channel *channel = info->chandef.chan; |
| 596 | struct cfg80211_beacon_data *bcon = &info->beacon; |
| 597 | u8 wmi_nettype = wil_iftype_nl2wmi(wdev->iftype); |
| 598 | |
| 599 | if (!channel) { |
| 600 | wil_err(wil, "AP: No channel???\n"); |
| 601 | return -EINVAL; |
| 602 | } |
| 603 | |
Vladimir Kondratiev | 7743882 | 2013-01-28 18:31:06 +0200 | [diff] [blame] | 604 | wil_dbg_misc(wil, "AP on Channel %d %d MHz, %s\n", channel->hw_value, |
Vladimir Kondratiev | 2057ebb | 2013-01-28 18:30:58 +0200 | [diff] [blame] | 605 | channel->center_freq, info->privacy ? "secure" : "open"); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 606 | print_hex_dump_bytes("SSID ", DUMP_PREFIX_OFFSET, |
| 607 | info->ssid, info->ssid_len); |
| 608 | |
Vladimir Kondratiev | 92646c9 | 2013-06-09 09:12:53 +0300 | [diff] [blame] | 609 | if (wil_fix_bcon(wil, bcon)) |
| 610 | wil_dbg_misc(wil, "Fixed bcon\n"); |
| 611 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 612 | rc = wil_reset(wil); |
| 613 | if (rc) |
| 614 | return rc; |
| 615 | |
Vladimir Kondratiev | e31b256 | 2013-06-09 09:12:55 +0300 | [diff] [blame] | 616 | /* Rx VRING. */ |
| 617 | rc = wil_rx_init(wil); |
| 618 | if (rc) |
| 619 | return rc; |
| 620 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 621 | rc = wmi_set_ssid(wil, info->ssid_len, info->ssid); |
| 622 | if (rc) |
| 623 | return rc; |
| 624 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 625 | /* MAC address - pre-requisite for other commands */ |
| 626 | wmi_set_mac_address(wil, ndev->dev_addr); |
| 627 | |
| 628 | /* IE's */ |
| 629 | /* bcon 'head IE's are not relevant for 60g band */ |
Vladimir Kondratiev | b1defa4 | 2013-03-13 14:12:41 +0200 | [diff] [blame] | 630 | /* |
| 631 | * FW do not form regular beacon, so bcon IE's are not set |
| 632 | * For the DMG bcon, when it will be supported, bcon IE's will |
| 633 | * be reused; add something like: |
| 634 | * wmi_set_ie(wil, WMI_FRAME_BEACON, bcon->beacon_ies_len, |
| 635 | * bcon->beacon_ies); |
| 636 | */ |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 637 | wmi_set_ie(wil, WMI_FRAME_PROBE_RESP, bcon->proberesp_ies_len, |
| 638 | bcon->proberesp_ies); |
| 639 | wmi_set_ie(wil, WMI_FRAME_ASSOC_RESP, bcon->assocresp_ies_len, |
| 640 | bcon->assocresp_ies); |
| 641 | |
| 642 | wil->secure_pcp = info->privacy; |
| 643 | |
Vladimir Kondratiev | b802317 | 2013-03-13 14:12:50 +0200 | [diff] [blame] | 644 | rc = wmi_pcp_start(wil, info->beacon_interval, wmi_nettype, |
| 645 | channel->hw_value); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 646 | if (rc) |
| 647 | return rc; |
| 648 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 649 | |
| 650 | netif_carrier_on(ndev); |
| 651 | |
| 652 | return rc; |
| 653 | } |
| 654 | |
| 655 | static int wil_cfg80211_stop_ap(struct wiphy *wiphy, |
| 656 | struct net_device *ndev) |
| 657 | { |
| 658 | int rc = 0; |
| 659 | struct wil6210_priv *wil = wiphy_to_wil(wiphy); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 660 | |
Vladimir Kondratiev | b802317 | 2013-03-13 14:12:50 +0200 | [diff] [blame] | 661 | rc = wmi_pcp_stop(wil); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 662 | |
| 663 | return rc; |
| 664 | } |
| 665 | |
Vladimir Kondratiev | 4d55a0a | 2014-02-27 16:20:54 +0200 | [diff] [blame] | 666 | static int wil_cfg80211_del_station(struct wiphy *wiphy, |
| 667 | struct net_device *dev, u8 *mac) |
| 668 | { |
| 669 | struct wil6210_priv *wil = wiphy_to_wil(wiphy); |
| 670 | wil6210_disconnect(wil, mac); |
| 671 | return 0; |
| 672 | } |
| 673 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 674 | static struct cfg80211_ops wil_cfg80211_ops = { |
| 675 | .scan = wil_cfg80211_scan, |
| 676 | .connect = wil_cfg80211_connect, |
| 677 | .disconnect = wil_cfg80211_disconnect, |
| 678 | .change_virtual_intf = wil_cfg80211_change_iface, |
| 679 | .get_station = wil_cfg80211_get_station, |
Vladimir Kondratiev | ef28afd | 2014-02-27 16:20:48 +0200 | [diff] [blame] | 680 | .dump_station = wil_cfg80211_dump_station, |
Vladimir Kondratiev | 1647f12 | 2014-02-27 16:20:40 +0200 | [diff] [blame] | 681 | .remain_on_channel = wil_remain_on_channel, |
| 682 | .cancel_remain_on_channel = wil_cancel_remain_on_channel, |
| 683 | .mgmt_tx = wil_cfg80211_mgmt_tx, |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 684 | .set_monitor_channel = wil_cfg80211_set_channel, |
| 685 | .add_key = wil_cfg80211_add_key, |
| 686 | .del_key = wil_cfg80211_del_key, |
| 687 | .set_default_key = wil_cfg80211_set_default_key, |
| 688 | /* AP mode */ |
| 689 | .start_ap = wil_cfg80211_start_ap, |
| 690 | .stop_ap = wil_cfg80211_stop_ap, |
Vladimir Kondratiev | 4d55a0a | 2014-02-27 16:20:54 +0200 | [diff] [blame] | 691 | .del_station = wil_cfg80211_del_station, |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 692 | }; |
| 693 | |
| 694 | static void wil_wiphy_init(struct wiphy *wiphy) |
| 695 | { |
| 696 | /* TODO: set real value */ |
| 697 | wiphy->max_scan_ssids = 10; |
| 698 | wiphy->max_num_pmkids = 0 /* TODO: */; |
| 699 | wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | |
| 700 | BIT(NL80211_IFTYPE_AP) | |
| 701 | BIT(NL80211_IFTYPE_MONITOR); |
| 702 | /* TODO: enable P2P when integrated with supplicant: |
| 703 | * BIT(NL80211_IFTYPE_P2P_CLIENT) | BIT(NL80211_IFTYPE_P2P_GO) |
| 704 | */ |
| 705 | wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME | |
| 706 | WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD; |
| 707 | dev_warn(wiphy_dev(wiphy), "%s : flags = 0x%08x\n", |
| 708 | __func__, wiphy->flags); |
| 709 | wiphy->probe_resp_offload = |
| 710 | NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS | |
| 711 | NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 | |
| 712 | NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P; |
| 713 | |
| 714 | wiphy->bands[IEEE80211_BAND_60GHZ] = &wil_band_60ghz; |
| 715 | |
| 716 | /* TODO: figure this out */ |
Vladimir Kondratiev | b8b33a3 | 2014-02-27 16:20:52 +0200 | [diff] [blame] | 717 | wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 718 | |
| 719 | wiphy->cipher_suites = wil_cipher_suites; |
| 720 | wiphy->n_cipher_suites = ARRAY_SIZE(wil_cipher_suites); |
| 721 | wiphy->mgmt_stypes = wil_mgmt_stypes; |
| 722 | } |
| 723 | |
| 724 | struct wireless_dev *wil_cfg80211_init(struct device *dev) |
| 725 | { |
| 726 | int rc = 0; |
| 727 | struct wireless_dev *wdev; |
| 728 | |
| 729 | wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL); |
| 730 | if (!wdev) |
| 731 | return ERR_PTR(-ENOMEM); |
| 732 | |
| 733 | wdev->wiphy = wiphy_new(&wil_cfg80211_ops, |
| 734 | sizeof(struct wil6210_priv)); |
| 735 | if (!wdev->wiphy) { |
| 736 | rc = -ENOMEM; |
| 737 | goto out; |
| 738 | } |
| 739 | |
| 740 | set_wiphy_dev(wdev->wiphy, dev); |
| 741 | wil_wiphy_init(wdev->wiphy); |
| 742 | |
| 743 | rc = wiphy_register(wdev->wiphy); |
| 744 | if (rc < 0) |
| 745 | goto out_failed_reg; |
| 746 | |
| 747 | return wdev; |
| 748 | |
| 749 | out_failed_reg: |
| 750 | wiphy_free(wdev->wiphy); |
| 751 | out: |
| 752 | kfree(wdev); |
| 753 | |
| 754 | return ERR_PTR(rc); |
| 755 | } |
| 756 | |
| 757 | void wil_wdev_free(struct wil6210_priv *wil) |
| 758 | { |
| 759 | struct wireless_dev *wdev = wil_to_wdev(wil); |
| 760 | |
| 761 | if (!wdev) |
| 762 | return; |
| 763 | |
| 764 | wiphy_unregister(wdev->wiphy); |
| 765 | wiphy_free(wdev->wiphy); |
| 766 | kfree(wdev); |
| 767 | } |