Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1 | /* |
Dedy Lansky | 32a20d4 | 2015-01-25 10:52:44 +0200 | [diff] [blame] | 2 | * Copyright (c) 2012-2015 Qualcomm Atheros, Inc. |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 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 | 9eb82d4 | 2014-06-16 19:37:13 +0300 | [diff] [blame] | 107 | 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 | |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 145 | sinfo->filled = BIT(NL80211_STA_INFO_RX_BYTES) | |
| 146 | BIT(NL80211_STA_INFO_TX_BYTES) | |
| 147 | BIT(NL80211_STA_INFO_RX_PACKETS) | |
| 148 | BIT(NL80211_STA_INFO_TX_PACKETS) | |
| 149 | BIT(NL80211_STA_INFO_RX_BITRATE) | |
| 150 | BIT(NL80211_STA_INFO_TX_BITRATE) | |
| 151 | BIT(NL80211_STA_INFO_RX_DROP_MISC) | |
| 152 | BIT(NL80211_STA_INFO_TX_FAILED); |
Vladimir Kondratiev | c8b78b5 | 2014-02-27 16:20:49 +0200 | [diff] [blame] | 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 | |
Vladimir Kondratiev | 9419b6a | 2014-12-23 09:47:14 +0200 | [diff] [blame] | 165 | if (test_bit(wil_status_fwconnected, wil->status)) { |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 166 | sinfo->filled |= BIT(NL80211_STA_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, |
Johannes Berg | 3b3a016 | 2014-05-19 17:19:31 +0200 | [diff] [blame] | 175 | const u8 *mac, struct station_info *sinfo) |
Vladimir Kondratiev | ef28afd | 2014-02-27 16:20:48 +0200 | [diff] [blame] | 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 */ |
Vladimir Kondratiev | 9419b6a | 2014-12-23 09:47:14 +0200 | [diff] [blame] | 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 | |
Vladimir Kondratiev | 2a91d7d | 2014-06-16 19:37:11 +0300 | [diff] [blame] | 290 | wil_dbg_misc(wil, "Start scan_request 0x%p\n", request); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 291 | wil->scan_request = request; |
Vladimir Kondratiev | 047e5d7 | 2014-05-27 14:45:48 +0300 | [diff] [blame] | 292 | mod_timer(&wil->scan_timer, jiffies + WIL6210_SCAN_TO); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 293 | |
| 294 | memset(&cmd, 0, sizeof(cmd)); |
| 295 | cmd.cmd.num_channels = 0; |
| 296 | n = min(request->n_channels, 4U); |
| 297 | for (i = 0; i < n; i++) { |
| 298 | int ch = request->channels[i]->hw_value; |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 299 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 300 | if (ch == 0) { |
| 301 | wil_err(wil, |
| 302 | "Scan requested for unknown frequency %dMhz\n", |
| 303 | request->channels[i]->center_freq); |
| 304 | continue; |
| 305 | } |
| 306 | /* 0-based channel indexes */ |
| 307 | cmd.cmd.channel_list[cmd.cmd.num_channels++].channel = ch - 1; |
Vladimir Kondratiev | 7743882 | 2013-01-28 18:31:06 +0200 | [diff] [blame] | 308 | wil_dbg_misc(wil, "Scan for ch %d : %d MHz\n", ch, |
Vladimir Kondratiev | 2057ebb | 2013-01-28 18:30:58 +0200 | [diff] [blame] | 309 | request->channels[i]->center_freq); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 310 | } |
| 311 | |
Vladimir Kondratiev | 77c9129 | 2014-09-10 16:34:47 +0300 | [diff] [blame] | 312 | if (request->ie_len) |
| 313 | print_hex_dump_bytes("Scan IE ", DUMP_PREFIX_OFFSET, |
| 314 | request->ie, request->ie_len); |
| 315 | else |
| 316 | wil_dbg_misc(wil, "Scan has no IE's\n"); |
| 317 | |
| 318 | rc = wmi_set_ie(wil, WMI_FRAME_PROBE_REQ, request->ie_len, |
| 319 | request->ie); |
| 320 | if (rc) { |
| 321 | wil_err(wil, "Aborting scan, set_ie failed: %d\n", rc); |
| 322 | goto out; |
| 323 | } |
| 324 | |
Vladimir Kondratiev | ed6f9dc | 2014-03-17 15:34:19 +0200 | [diff] [blame] | 325 | rc = wmi_send(wil, WMI_START_SCAN_CMDID, &cmd, sizeof(cmd.cmd) + |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 326 | cmd.cmd.num_channels * sizeof(cmd.cmd.channel_list[0])); |
Vladimir Kondratiev | ed6f9dc | 2014-03-17 15:34:19 +0200 | [diff] [blame] | 327 | |
Vladimir Kondratiev | 77c9129 | 2014-09-10 16:34:47 +0300 | [diff] [blame] | 328 | out: |
Vladimir Kondratiev | a214208 | 2014-08-06 10:31:57 +0300 | [diff] [blame] | 329 | if (rc) { |
| 330 | del_timer_sync(&wil->scan_timer); |
Vladimir Kondratiev | ed6f9dc | 2014-03-17 15:34:19 +0200 | [diff] [blame] | 331 | wil->scan_request = NULL; |
Vladimir Kondratiev | a214208 | 2014-08-06 10:31:57 +0300 | [diff] [blame] | 332 | } |
Vladimir Kondratiev | ed6f9dc | 2014-03-17 15:34:19 +0200 | [diff] [blame] | 333 | |
| 334 | return rc; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 335 | } |
| 336 | |
Vladimir Kondratiev | feeac22 | 2015-02-01 10:55:15 +0200 | [diff] [blame] | 337 | static void wil_print_crypto(struct wil6210_priv *wil, |
| 338 | struct cfg80211_crypto_settings *c) |
| 339 | { |
| 340 | int i, n; |
| 341 | |
| 342 | wil_dbg_misc(wil, "WPA versions: 0x%08x cipher group 0x%08x\n", |
| 343 | c->wpa_versions, c->cipher_group); |
| 344 | wil_dbg_misc(wil, "Pairwise ciphers [%d] {\n", c->n_ciphers_pairwise); |
| 345 | n = min_t(int, c->n_ciphers_pairwise, ARRAY_SIZE(c->ciphers_pairwise)); |
| 346 | for (i = 0; i < n; i++) |
| 347 | wil_dbg_misc(wil, " [%d] = 0x%08x\n", i, |
| 348 | c->ciphers_pairwise[i]); |
| 349 | wil_dbg_misc(wil, "}\n"); |
| 350 | wil_dbg_misc(wil, "AKM suites [%d] {\n", c->n_akm_suites); |
| 351 | n = min_t(int, c->n_akm_suites, ARRAY_SIZE(c->akm_suites)); |
| 352 | for (i = 0; i < n; i++) |
| 353 | wil_dbg_misc(wil, " [%d] = 0x%08x\n", i, |
| 354 | c->akm_suites[i]); |
| 355 | wil_dbg_misc(wil, "}\n"); |
| 356 | wil_dbg_misc(wil, "Control port : %d, eth_type 0x%04x no_encrypt %d\n", |
| 357 | c->control_port, be16_to_cpu(c->control_port_ethertype), |
| 358 | c->control_port_no_encrypt); |
| 359 | } |
| 360 | |
Vladimir Kondratiev | 8ca2616 | 2014-09-10 16:34:32 +0300 | [diff] [blame] | 361 | static void wil_print_connect_params(struct wil6210_priv *wil, |
| 362 | struct cfg80211_connect_params *sme) |
| 363 | { |
| 364 | wil_info(wil, "Connecting to:\n"); |
| 365 | if (sme->channel) { |
| 366 | wil_info(wil, " Channel: %d freq %d\n", |
| 367 | sme->channel->hw_value, sme->channel->center_freq); |
| 368 | } |
| 369 | if (sme->bssid) |
| 370 | wil_info(wil, " BSSID: %pM\n", sme->bssid); |
| 371 | if (sme->ssid) |
| 372 | print_hex_dump(KERN_INFO, " SSID: ", DUMP_PREFIX_OFFSET, |
| 373 | 16, 1, sme->ssid, sme->ssid_len, true); |
| 374 | wil_info(wil, " Privacy: %s\n", sme->privacy ? "secure" : "open"); |
Vladimir Kondratiev | feeac22 | 2015-02-01 10:55:15 +0200 | [diff] [blame] | 375 | wil_print_crypto(wil, &sme->crypto); |
Vladimir Kondratiev | 8ca2616 | 2014-09-10 16:34:32 +0300 | [diff] [blame] | 376 | } |
| 377 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 378 | static int wil_cfg80211_connect(struct wiphy *wiphy, |
| 379 | struct net_device *ndev, |
| 380 | struct cfg80211_connect_params *sme) |
| 381 | { |
| 382 | struct wil6210_priv *wil = wiphy_to_wil(wiphy); |
| 383 | struct cfg80211_bss *bss; |
| 384 | struct wmi_connect_cmd conn; |
| 385 | const u8 *ssid_eid; |
| 386 | const u8 *rsn_eid; |
| 387 | int ch; |
| 388 | int rc = 0; |
| 389 | |
Vladimir Kondratiev | 344a702 | 2015-02-15 14:02:37 +0200 | [diff] [blame] | 390 | wil_print_connect_params(wil, sme); |
| 391 | |
Vladimir Kondratiev | 9419b6a | 2014-12-23 09:47:14 +0200 | [diff] [blame] | 392 | if (test_bit(wil_status_fwconnecting, wil->status) || |
| 393 | test_bit(wil_status_fwconnected, wil->status)) |
Vladimir Kondratiev | 4cd9e83 | 2014-03-17 15:34:20 +0200 | [diff] [blame] | 394 | return -EALREADY; |
| 395 | |
Vladimir Kondratiev | 344a702 | 2015-02-15 14:02:37 +0200 | [diff] [blame] | 396 | if (sme->ie_len > WMI_MAX_IE_LEN) { |
| 397 | wil_err(wil, "IE too large (%td bytes)\n", sme->ie_len); |
| 398 | return -ERANGE; |
| 399 | } |
| 400 | |
| 401 | rsn_eid = sme->ie ? |
| 402 | cfg80211_find_ie(WLAN_EID_RSN, sme->ie, sme->ie_len) : |
| 403 | NULL; |
| 404 | |
| 405 | if (sme->privacy && !rsn_eid) { |
| 406 | wil_err(wil, "Missing RSN IE for secure connection\n"); |
| 407 | return -EINVAL; |
| 408 | } |
Vladimir Kondratiev | 8ca2616 | 2014-09-10 16:34:32 +0300 | [diff] [blame] | 409 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 410 | bss = cfg80211_get_bss(wiphy, sme->channel, sme->bssid, |
| 411 | sme->ssid, sme->ssid_len, |
| 412 | WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS); |
| 413 | if (!bss) { |
| 414 | wil_err(wil, "Unable to find BSS\n"); |
| 415 | return -ENOENT; |
| 416 | } |
| 417 | |
| 418 | ssid_eid = ieee80211_bss_get_ie(bss, WLAN_EID_SSID); |
| 419 | if (!ssid_eid) { |
| 420 | wil_err(wil, "No SSID\n"); |
| 421 | rc = -ENOENT; |
| 422 | goto out; |
| 423 | } |
Vladimir Kondratiev | 344a702 | 2015-02-15 14:02:37 +0200 | [diff] [blame] | 424 | wil->privacy = sme->privacy; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 425 | |
Vladimir Kondratiev | 344a702 | 2015-02-15 14:02:37 +0200 | [diff] [blame] | 426 | if (wil->privacy) { |
Vladimir Kondratiev | ac4acdb | 2014-09-10 16:34:43 +0300 | [diff] [blame] | 427 | /* For secure assoc, send WMI_DELETE_CIPHER_KEY_CMD */ |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 428 | rc = wmi_del_cipher_key(wil, 0, bss->bssid); |
| 429 | if (rc) { |
| 430 | wil_err(wil, "WMI_DELETE_CIPHER_KEY_CMD failed\n"); |
| 431 | goto out; |
| 432 | } |
Vladimir Kondratiev | ac4acdb | 2014-09-10 16:34:43 +0300 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | /* WMI_SET_APPIE_CMD. ie may contain rsn info as well as other info |
| 436 | * elements. Send it also in case it's empty, to erase previously set |
| 437 | * ies in FW. |
| 438 | */ |
| 439 | rc = wmi_set_ie(wil, WMI_FRAME_ASSOC_REQ, sme->ie_len, sme->ie); |
| 440 | if (rc) { |
| 441 | wil_err(wil, "WMI_SET_APPIE_CMD failed\n"); |
| 442 | goto out; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | /* WMI_CONNECT_CMD */ |
| 446 | memset(&conn, 0, sizeof(conn)); |
Vladimir Kondratiev | acc9780 | 2013-03-13 14:12:47 +0200 | [diff] [blame] | 447 | switch (bss->capability & WLAN_CAPABILITY_DMG_TYPE_MASK) { |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 448 | case WLAN_CAPABILITY_DMG_TYPE_AP: |
| 449 | conn.network_type = WMI_NETTYPE_INFRA; |
| 450 | break; |
| 451 | case WLAN_CAPABILITY_DMG_TYPE_PBSS: |
| 452 | conn.network_type = WMI_NETTYPE_P2P; |
| 453 | break; |
| 454 | default: |
| 455 | wil_err(wil, "Unsupported BSS type, capability= 0x%04x\n", |
| 456 | bss->capability); |
| 457 | goto out; |
| 458 | } |
Vladimir Kondratiev | 344a702 | 2015-02-15 14:02:37 +0200 | [diff] [blame] | 459 | if (wil->privacy) { |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 460 | conn.dot11_auth_mode = WMI_AUTH11_SHARED; |
| 461 | conn.auth_mode = WMI_AUTH_WPA2_PSK; |
| 462 | conn.pairwise_crypto_type = WMI_CRYPT_AES_GCMP; |
| 463 | conn.pairwise_crypto_len = 16; |
| 464 | } else { |
| 465 | conn.dot11_auth_mode = WMI_AUTH11_OPEN; |
| 466 | conn.auth_mode = WMI_AUTH_NONE; |
| 467 | } |
| 468 | |
| 469 | conn.ssid_len = min_t(u8, ssid_eid[1], 32); |
| 470 | memcpy(conn.ssid, ssid_eid+2, conn.ssid_len); |
| 471 | |
| 472 | ch = bss->channel->hw_value; |
| 473 | if (ch == 0) { |
| 474 | wil_err(wil, "BSS at unknown frequency %dMhz\n", |
| 475 | bss->channel->center_freq); |
| 476 | rc = -EOPNOTSUPP; |
| 477 | goto out; |
| 478 | } |
| 479 | conn.channel = ch - 1; |
| 480 | |
Joe Perches | d458cdf | 2013-10-01 19:04:40 -0700 | [diff] [blame] | 481 | memcpy(conn.bssid, bss->bssid, ETH_ALEN); |
| 482 | memcpy(conn.dst_mac, bss->bssid, ETH_ALEN); |
Vladimir Kondratiev | e83eb2f | 2014-03-17 15:34:07 +0200 | [diff] [blame] | 483 | |
Vladimir Kondratiev | 9419b6a | 2014-12-23 09:47:14 +0200 | [diff] [blame] | 484 | set_bit(wil_status_fwconnecting, wil->status); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 485 | |
| 486 | rc = wmi_send(wil, WMI_CONNECT_CMDID, &conn, sizeof(conn)); |
| 487 | if (rc == 0) { |
Dedy Lansky | c5e96c9 | 2015-01-25 10:52:43 +0200 | [diff] [blame] | 488 | netif_carrier_on(ndev); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 489 | /* Connect can take lots of time */ |
| 490 | mod_timer(&wil->connect_timer, |
| 491 | jiffies + msecs_to_jiffies(2000)); |
Vladimir Kondratiev | b338f74 | 2013-05-28 15:17:53 +0300 | [diff] [blame] | 492 | } else { |
Vladimir Kondratiev | 9419b6a | 2014-12-23 09:47:14 +0200 | [diff] [blame] | 493 | clear_bit(wil_status_fwconnecting, wil->status); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 494 | } |
| 495 | |
| 496 | out: |
Johannes Berg | 5b112d3 | 2013-02-01 01:49:58 +0100 | [diff] [blame] | 497 | cfg80211_put_bss(wiphy, bss); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 498 | |
| 499 | return rc; |
| 500 | } |
| 501 | |
| 502 | static int wil_cfg80211_disconnect(struct wiphy *wiphy, |
| 503 | struct net_device *ndev, |
| 504 | u16 reason_code) |
| 505 | { |
| 506 | int rc; |
| 507 | struct wil6210_priv *wil = wiphy_to_wil(wiphy); |
| 508 | |
| 509 | rc = wmi_send(wil, WMI_DISCONNECT_CMDID, NULL, 0); |
| 510 | |
| 511 | return rc; |
| 512 | } |
| 513 | |
Vladimir Kondratiev | 0b39aaf | 2014-06-16 19:36:59 +0300 | [diff] [blame] | 514 | int wil_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev, |
| 515 | struct cfg80211_mgmt_tx_params *params, |
| 516 | u64 *cookie) |
Vladimir Kondratiev | 1647f12 | 2014-02-27 16:20:40 +0200 | [diff] [blame] | 517 | { |
| 518 | const u8 *buf = params->buf; |
| 519 | size_t len = params->len; |
| 520 | struct wil6210_priv *wil = wiphy_to_wil(wiphy); |
| 521 | int rc; |
Vladimir Kondratiev | 304464f | 2014-06-16 19:37:00 +0300 | [diff] [blame] | 522 | bool tx_status = false; |
Vladimir Kondratiev | 1647f12 | 2014-02-27 16:20:40 +0200 | [diff] [blame] | 523 | struct ieee80211_mgmt *mgmt_frame = (void *)buf; |
| 524 | struct wmi_sw_tx_req_cmd *cmd; |
| 525 | struct { |
| 526 | struct wil6210_mbox_hdr_wmi wmi; |
| 527 | struct wmi_sw_tx_complete_event evt; |
| 528 | } __packed evt; |
| 529 | |
| 530 | cmd = kmalloc(sizeof(*cmd) + len, GFP_KERNEL); |
Vladimir Kondratiev | 304464f | 2014-06-16 19:37:00 +0300 | [diff] [blame] | 531 | if (!cmd) { |
| 532 | rc = -ENOMEM; |
| 533 | goto out; |
| 534 | } |
Vladimir Kondratiev | 1647f12 | 2014-02-27 16:20:40 +0200 | [diff] [blame] | 535 | |
| 536 | memcpy(cmd->dst_mac, mgmt_frame->da, WMI_MAC_LEN); |
| 537 | cmd->len = cpu_to_le16(len); |
| 538 | memcpy(cmd->payload, buf, len); |
| 539 | |
| 540 | rc = wmi_call(wil, WMI_SW_TX_REQ_CMDID, cmd, sizeof(*cmd) + len, |
| 541 | WMI_SW_TX_COMPLETE_EVENTID, &evt, sizeof(evt), 2000); |
| 542 | if (rc == 0) |
Vladimir Kondratiev | 304464f | 2014-06-16 19:37:00 +0300 | [diff] [blame] | 543 | tx_status = !evt.evt.status; |
Vladimir Kondratiev | 1647f12 | 2014-02-27 16:20:40 +0200 | [diff] [blame] | 544 | |
| 545 | kfree(cmd); |
Vladimir Kondratiev | 304464f | 2014-06-16 19:37:00 +0300 | [diff] [blame] | 546 | out: |
| 547 | cfg80211_mgmt_tx_status(wdev, cookie ? *cookie : 0, buf, len, |
| 548 | tx_status, GFP_KERNEL); |
Vladimir Kondratiev | 1647f12 | 2014-02-27 16:20:40 +0200 | [diff] [blame] | 549 | return rc; |
| 550 | } |
| 551 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 552 | static int wil_cfg80211_set_channel(struct wiphy *wiphy, |
| 553 | struct cfg80211_chan_def *chandef) |
| 554 | { |
| 555 | struct wil6210_priv *wil = wiphy_to_wil(wiphy); |
| 556 | struct wireless_dev *wdev = wil->wdev; |
| 557 | |
| 558 | wdev->preset_chandef = *chandef; |
| 559 | |
| 560 | return 0; |
| 561 | } |
| 562 | |
| 563 | static int wil_cfg80211_add_key(struct wiphy *wiphy, |
| 564 | struct net_device *ndev, |
| 565 | u8 key_index, bool pairwise, |
| 566 | const u8 *mac_addr, |
| 567 | struct key_params *params) |
| 568 | { |
| 569 | struct wil6210_priv *wil = wiphy_to_wil(wiphy); |
| 570 | |
| 571 | /* group key is not used */ |
| 572 | if (!pairwise) |
| 573 | return 0; |
| 574 | |
| 575 | return wmi_add_cipher_key(wil, key_index, mac_addr, |
| 576 | params->key_len, params->key); |
| 577 | } |
| 578 | |
| 579 | static int wil_cfg80211_del_key(struct wiphy *wiphy, |
| 580 | struct net_device *ndev, |
| 581 | u8 key_index, bool pairwise, |
| 582 | const u8 *mac_addr) |
| 583 | { |
| 584 | struct wil6210_priv *wil = wiphy_to_wil(wiphy); |
| 585 | |
| 586 | /* group key is not used */ |
| 587 | if (!pairwise) |
| 588 | return 0; |
| 589 | |
| 590 | return wmi_del_cipher_key(wil, key_index, mac_addr); |
| 591 | } |
| 592 | |
| 593 | /* Need to be present or wiphy_new() will WARN */ |
| 594 | static int wil_cfg80211_set_default_key(struct wiphy *wiphy, |
| 595 | struct net_device *ndev, |
| 596 | u8 key_index, bool unicast, |
| 597 | bool multicast) |
| 598 | { |
| 599 | return 0; |
| 600 | } |
| 601 | |
Vladimir Kondratiev | 1647f12 | 2014-02-27 16:20:40 +0200 | [diff] [blame] | 602 | static int wil_remain_on_channel(struct wiphy *wiphy, |
| 603 | struct wireless_dev *wdev, |
| 604 | struct ieee80211_channel *chan, |
| 605 | unsigned int duration, |
| 606 | u64 *cookie) |
| 607 | { |
| 608 | struct wil6210_priv *wil = wiphy_to_wil(wiphy); |
| 609 | int rc; |
| 610 | |
| 611 | /* TODO: handle duration */ |
| 612 | wil_info(wil, "%s(%d, %d ms)\n", __func__, chan->center_freq, duration); |
| 613 | |
| 614 | rc = wmi_set_channel(wil, chan->hw_value); |
| 615 | if (rc) |
| 616 | return rc; |
| 617 | |
| 618 | rc = wmi_rxon(wil, true); |
| 619 | |
| 620 | return rc; |
| 621 | } |
| 622 | |
| 623 | static int wil_cancel_remain_on_channel(struct wiphy *wiphy, |
| 624 | struct wireless_dev *wdev, |
| 625 | u64 cookie) |
| 626 | { |
| 627 | struct wil6210_priv *wil = wiphy_to_wil(wiphy); |
| 628 | int rc; |
| 629 | |
| 630 | wil_info(wil, "%s()\n", __func__); |
| 631 | |
| 632 | rc = wmi_rxon(wil, false); |
| 633 | |
| 634 | return rc; |
| 635 | } |
| 636 | |
Vladimir Kondratiev | ca95977 | 2014-06-16 19:37:01 +0300 | [diff] [blame] | 637 | static void wil_print_bcon_data(struct cfg80211_beacon_data *b) |
| 638 | { |
| 639 | print_hex_dump_bytes("head ", DUMP_PREFIX_OFFSET, |
| 640 | b->head, b->head_len); |
| 641 | print_hex_dump_bytes("tail ", DUMP_PREFIX_OFFSET, |
| 642 | b->tail, b->tail_len); |
| 643 | print_hex_dump_bytes("BCON IE ", DUMP_PREFIX_OFFSET, |
| 644 | b->beacon_ies, b->beacon_ies_len); |
| 645 | print_hex_dump_bytes("PROBE ", DUMP_PREFIX_OFFSET, |
| 646 | b->probe_resp, b->probe_resp_len); |
| 647 | print_hex_dump_bytes("PROBE IE ", DUMP_PREFIX_OFFSET, |
| 648 | b->proberesp_ies, b->proberesp_ies_len); |
| 649 | print_hex_dump_bytes("ASSOC IE ", DUMP_PREFIX_OFFSET, |
| 650 | b->assocresp_ies, b->assocresp_ies_len); |
| 651 | } |
| 652 | |
Vladimir Kondratiev | 92646c9 | 2013-06-09 09:12:53 +0300 | [diff] [blame] | 653 | static int wil_fix_bcon(struct wil6210_priv *wil, |
| 654 | struct cfg80211_beacon_data *bcon) |
| 655 | { |
| 656 | struct ieee80211_mgmt *f = (struct ieee80211_mgmt *)bcon->probe_resp; |
| 657 | size_t hlen = offsetof(struct ieee80211_mgmt, u.probe_resp.variable); |
| 658 | int rc = 0; |
| 659 | |
| 660 | if (bcon->probe_resp_len <= hlen) |
| 661 | return 0; |
| 662 | |
| 663 | if (!bcon->proberesp_ies) { |
| 664 | bcon->proberesp_ies = f->u.probe_resp.variable; |
| 665 | bcon->proberesp_ies_len = bcon->probe_resp_len - hlen; |
| 666 | rc = 1; |
| 667 | } |
| 668 | if (!bcon->assocresp_ies) { |
| 669 | bcon->assocresp_ies = f->u.probe_resp.variable; |
| 670 | bcon->assocresp_ies_len = bcon->probe_resp_len - hlen; |
| 671 | rc = 1; |
| 672 | } |
| 673 | |
| 674 | return rc; |
| 675 | } |
| 676 | |
Vladimir Kondratiev | 1bd922f | 2014-09-10 16:34:44 +0300 | [diff] [blame] | 677 | static int wil_cfg80211_change_beacon(struct wiphy *wiphy, |
| 678 | struct net_device *ndev, |
| 679 | struct cfg80211_beacon_data *bcon) |
| 680 | { |
| 681 | struct wil6210_priv *wil = wiphy_to_wil(wiphy); |
| 682 | int rc; |
| 683 | |
| 684 | wil_dbg_misc(wil, "%s()\n", __func__); |
| 685 | |
| 686 | if (wil_fix_bcon(wil, bcon)) { |
| 687 | wil_dbg_misc(wil, "Fixed bcon\n"); |
| 688 | wil_print_bcon_data(bcon); |
| 689 | } |
| 690 | |
| 691 | /* FW do not form regular beacon, so bcon IE's are not set |
| 692 | * For the DMG bcon, when it will be supported, bcon IE's will |
| 693 | * be reused; add something like: |
| 694 | * wmi_set_ie(wil, WMI_FRAME_BEACON, bcon->beacon_ies_len, |
| 695 | * bcon->beacon_ies); |
| 696 | */ |
| 697 | rc = wmi_set_ie(wil, WMI_FRAME_PROBE_RESP, |
| 698 | bcon->proberesp_ies_len, |
| 699 | bcon->proberesp_ies); |
| 700 | if (rc) { |
| 701 | wil_err(wil, "set_ie(PROBE_RESP) failed\n"); |
| 702 | return rc; |
| 703 | } |
| 704 | |
| 705 | rc = wmi_set_ie(wil, WMI_FRAME_ASSOC_RESP, |
| 706 | bcon->assocresp_ies_len, |
| 707 | bcon->assocresp_ies); |
| 708 | if (rc) { |
| 709 | wil_err(wil, "set_ie(ASSOC_RESP) failed\n"); |
| 710 | return rc; |
| 711 | } |
| 712 | |
| 713 | return 0; |
| 714 | } |
| 715 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 716 | static int wil_cfg80211_start_ap(struct wiphy *wiphy, |
| 717 | struct net_device *ndev, |
| 718 | struct cfg80211_ap_settings *info) |
| 719 | { |
| 720 | int rc = 0; |
| 721 | struct wil6210_priv *wil = wiphy_to_wil(wiphy); |
| 722 | struct wireless_dev *wdev = ndev->ieee80211_ptr; |
| 723 | struct ieee80211_channel *channel = info->chandef.chan; |
| 724 | struct cfg80211_beacon_data *bcon = &info->beacon; |
Vladimir Kondratiev | ca95977 | 2014-06-16 19:37:01 +0300 | [diff] [blame] | 725 | struct cfg80211_crypto_settings *crypto = &info->crypto; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 726 | u8 wmi_nettype = wil_iftype_nl2wmi(wdev->iftype); |
| 727 | |
Vladimir Kondratiev | ca95977 | 2014-06-16 19:37:01 +0300 | [diff] [blame] | 728 | wil_dbg_misc(wil, "%s()\n", __func__); |
| 729 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 730 | if (!channel) { |
| 731 | wil_err(wil, "AP: No channel???\n"); |
| 732 | return -EINVAL; |
| 733 | } |
| 734 | |
Vladimir Kondratiev | 7743882 | 2013-01-28 18:31:06 +0200 | [diff] [blame] | 735 | 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] | 736 | channel->center_freq, info->privacy ? "secure" : "open"); |
Vladimir Kondratiev | ca95977 | 2014-06-16 19:37:01 +0300 | [diff] [blame] | 737 | wil_dbg_misc(wil, "Privacy: %d auth_type %d\n", |
| 738 | info->privacy, info->auth_type); |
| 739 | wil_dbg_misc(wil, "BI %d DTIM %d\n", info->beacon_interval, |
| 740 | info->dtim_period); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 741 | print_hex_dump_bytes("SSID ", DUMP_PREFIX_OFFSET, |
| 742 | info->ssid, info->ssid_len); |
Vladimir Kondratiev | ca95977 | 2014-06-16 19:37:01 +0300 | [diff] [blame] | 743 | wil_print_bcon_data(bcon); |
| 744 | wil_print_crypto(wil, crypto); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 745 | |
Vladimir Kondratiev | ca95977 | 2014-06-16 19:37:01 +0300 | [diff] [blame] | 746 | if (wil_fix_bcon(wil, bcon)) { |
Vladimir Kondratiev | 92646c9 | 2013-06-09 09:12:53 +0300 | [diff] [blame] | 747 | wil_dbg_misc(wil, "Fixed bcon\n"); |
Vladimir Kondratiev | ca95977 | 2014-06-16 19:37:01 +0300 | [diff] [blame] | 748 | wil_print_bcon_data(bcon); |
| 749 | } |
Vladimir Kondratiev | 92646c9 | 2013-06-09 09:12:53 +0300 | [diff] [blame] | 750 | |
Vladimir Kondratiev | c33407a | 2014-10-01 15:05:24 +0300 | [diff] [blame] | 751 | wil_set_recovery_state(wil, fw_recovery_idle); |
| 752 | |
Vladimir Kondratiev | 9c3bde5 | 2014-03-17 15:34:21 +0200 | [diff] [blame] | 753 | mutex_lock(&wil->mutex); |
| 754 | |
Vladimir Kondratiev | 73d839a | 2014-09-10 16:34:50 +0300 | [diff] [blame] | 755 | __wil_down(wil); |
| 756 | rc = __wil_up(wil); |
Vladimir Kondratiev | e31b256 | 2013-06-09 09:12:55 +0300 | [diff] [blame] | 757 | if (rc) |
Vladimir Kondratiev | 9c3bde5 | 2014-03-17 15:34:21 +0200 | [diff] [blame] | 758 | goto out; |
Vladimir Kondratiev | e31b256 | 2013-06-09 09:12:55 +0300 | [diff] [blame] | 759 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 760 | rc = wmi_set_ssid(wil, info->ssid_len, info->ssid); |
| 761 | if (rc) |
Vladimir Kondratiev | 9c3bde5 | 2014-03-17 15:34:21 +0200 | [diff] [blame] | 762 | goto out; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 763 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 764 | /* IE's */ |
| 765 | /* bcon 'head IE's are not relevant for 60g band */ |
Vladimir Kondratiev | b1defa4 | 2013-03-13 14:12:41 +0200 | [diff] [blame] | 766 | /* |
| 767 | * FW do not form regular beacon, so bcon IE's are not set |
| 768 | * For the DMG bcon, when it will be supported, bcon IE's will |
| 769 | * be reused; add something like: |
| 770 | * wmi_set_ie(wil, WMI_FRAME_BEACON, bcon->beacon_ies_len, |
| 771 | * bcon->beacon_ies); |
| 772 | */ |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 773 | wmi_set_ie(wil, WMI_FRAME_PROBE_RESP, bcon->proberesp_ies_len, |
| 774 | bcon->proberesp_ies); |
| 775 | wmi_set_ie(wil, WMI_FRAME_ASSOC_RESP, bcon->assocresp_ies_len, |
| 776 | bcon->assocresp_ies); |
| 777 | |
Vladimir Kondratiev | 774974e | 2015-02-15 14:02:36 +0200 | [diff] [blame] | 778 | wil->privacy = info->privacy; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 779 | |
Dedy Lansky | c5e96c9 | 2015-01-25 10:52:43 +0200 | [diff] [blame] | 780 | netif_carrier_on(ndev); |
| 781 | |
Vladimir Kondratiev | b802317 | 2013-03-13 14:12:50 +0200 | [diff] [blame] | 782 | rc = wmi_pcp_start(wil, info->beacon_interval, wmi_nettype, |
| 783 | channel->hw_value); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 784 | if (rc) |
Dedy Lansky | c5e96c9 | 2015-01-25 10:52:43 +0200 | [diff] [blame] | 785 | netif_carrier_off(ndev); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 786 | |
Vladimir Kondratiev | 9c3bde5 | 2014-03-17 15:34:21 +0200 | [diff] [blame] | 787 | out: |
| 788 | mutex_unlock(&wil->mutex); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 789 | return rc; |
| 790 | } |
| 791 | |
| 792 | static int wil_cfg80211_stop_ap(struct wiphy *wiphy, |
| 793 | struct net_device *ndev) |
| 794 | { |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 795 | struct wil6210_priv *wil = wiphy_to_wil(wiphy); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 796 | |
Vladimir Kondratiev | ca95977 | 2014-06-16 19:37:01 +0300 | [diff] [blame] | 797 | wil_dbg_misc(wil, "%s()\n", __func__); |
| 798 | |
Dedy Lansky | c5e96c9 | 2015-01-25 10:52:43 +0200 | [diff] [blame] | 799 | netif_carrier_off(ndev); |
Vladimir Kondratiev | c33407a | 2014-10-01 15:05:24 +0300 | [diff] [blame] | 800 | wil_set_recovery_state(wil, fw_recovery_idle); |
| 801 | |
Vladimir Kondratiev | 9c3bde5 | 2014-03-17 15:34:21 +0200 | [diff] [blame] | 802 | mutex_lock(&wil->mutex); |
| 803 | |
Dedy Lansky | 32a20d4 | 2015-01-25 10:52:44 +0200 | [diff] [blame] | 804 | wmi_pcp_stop(wil); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 805 | |
Vladimir Kondratiev | 73d839a | 2014-09-10 16:34:50 +0300 | [diff] [blame] | 806 | __wil_down(wil); |
Dedy Lansky | 32a20d4 | 2015-01-25 10:52:44 +0200 | [diff] [blame] | 807 | __wil_up(wil); |
Vladimir Kondratiev | 73d839a | 2014-09-10 16:34:50 +0300 | [diff] [blame] | 808 | |
Vladimir Kondratiev | 9c3bde5 | 2014-03-17 15:34:21 +0200 | [diff] [blame] | 809 | mutex_unlock(&wil->mutex); |
Vladimir Kondratiev | 73d839a | 2014-09-10 16:34:50 +0300 | [diff] [blame] | 810 | |
Dedy Lansky | 32a20d4 | 2015-01-25 10:52:44 +0200 | [diff] [blame] | 811 | /* some functions above might fail (e.g. __wil_up). Nevertheless, we |
| 812 | * return success because AP has stopped |
| 813 | */ |
| 814 | return 0; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 815 | } |
| 816 | |
Vladimir Kondratiev | 4d55a0a | 2014-02-27 16:20:54 +0200 | [diff] [blame] | 817 | static int wil_cfg80211_del_station(struct wiphy *wiphy, |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 818 | struct net_device *dev, |
| 819 | struct station_del_parameters *params) |
Vladimir Kondratiev | 4d55a0a | 2014-02-27 16:20:54 +0200 | [diff] [blame] | 820 | { |
| 821 | struct wil6210_priv *wil = wiphy_to_wil(wiphy); |
Vladimir Kondratiev | 097638a | 2014-03-17 15:34:25 +0200 | [diff] [blame] | 822 | |
| 823 | mutex_lock(&wil->mutex); |
Vladimir Kondratiev | 4821e6d | 2014-12-01 15:33:15 +0200 | [diff] [blame] | 824 | wil6210_disconnect(wil, params->mac, params->reason_code, false); |
Vladimir Kondratiev | 097638a | 2014-03-17 15:34:25 +0200 | [diff] [blame] | 825 | mutex_unlock(&wil->mutex); |
| 826 | |
Vladimir Kondratiev | 4d55a0a | 2014-02-27 16:20:54 +0200 | [diff] [blame] | 827 | return 0; |
| 828 | } |
| 829 | |
Vladimir Kondratiev | 40822a9 | 2015-01-25 10:52:50 +0200 | [diff] [blame] | 830 | /* probe_client handling */ |
| 831 | static void wil_probe_client_handle(struct wil6210_priv *wil, |
| 832 | struct wil_probe_client_req *req) |
| 833 | { |
| 834 | struct net_device *ndev = wil_to_ndev(wil); |
| 835 | struct wil_sta_info *sta = &wil->sta[req->cid]; |
| 836 | /* assume STA is alive if it is still connected, |
| 837 | * else FW will disconnect it |
| 838 | */ |
| 839 | bool alive = (sta->status == wil_sta_connected); |
| 840 | |
| 841 | cfg80211_probe_status(ndev, sta->addr, req->cookie, alive, GFP_KERNEL); |
| 842 | } |
| 843 | |
| 844 | static struct list_head *next_probe_client(struct wil6210_priv *wil) |
| 845 | { |
| 846 | struct list_head *ret = NULL; |
| 847 | |
| 848 | mutex_lock(&wil->probe_client_mutex); |
| 849 | |
| 850 | if (!list_empty(&wil->probe_client_pending)) { |
| 851 | ret = wil->probe_client_pending.next; |
| 852 | list_del(ret); |
| 853 | } |
| 854 | |
| 855 | mutex_unlock(&wil->probe_client_mutex); |
| 856 | |
| 857 | return ret; |
| 858 | } |
| 859 | |
| 860 | void wil_probe_client_worker(struct work_struct *work) |
| 861 | { |
| 862 | struct wil6210_priv *wil = container_of(work, struct wil6210_priv, |
| 863 | probe_client_worker); |
| 864 | struct wil_probe_client_req *req; |
| 865 | struct list_head *lh; |
| 866 | |
| 867 | while ((lh = next_probe_client(wil)) != NULL) { |
| 868 | req = list_entry(lh, struct wil_probe_client_req, list); |
| 869 | |
| 870 | wil_probe_client_handle(wil, req); |
| 871 | kfree(req); |
| 872 | } |
| 873 | } |
| 874 | |
| 875 | void wil_probe_client_flush(struct wil6210_priv *wil) |
| 876 | { |
| 877 | struct wil_probe_client_req *req, *t; |
| 878 | |
| 879 | wil_dbg_misc(wil, "%s()\n", __func__); |
| 880 | |
| 881 | mutex_lock(&wil->probe_client_mutex); |
| 882 | |
| 883 | list_for_each_entry_safe(req, t, &wil->probe_client_pending, list) { |
| 884 | list_del(&req->list); |
| 885 | kfree(req); |
| 886 | } |
| 887 | |
| 888 | mutex_unlock(&wil->probe_client_mutex); |
| 889 | } |
| 890 | |
| 891 | static int wil_cfg80211_probe_client(struct wiphy *wiphy, |
| 892 | struct net_device *dev, |
| 893 | const u8 *peer, u64 *cookie) |
| 894 | { |
| 895 | struct wil6210_priv *wil = wiphy_to_wil(wiphy); |
| 896 | struct wil_probe_client_req *req; |
| 897 | int cid = wil_find_cid(wil, peer); |
| 898 | |
| 899 | wil_dbg_misc(wil, "%s(%pM => CID %d)\n", __func__, peer, cid); |
| 900 | |
| 901 | if (cid < 0) |
| 902 | return -ENOLINK; |
| 903 | |
| 904 | req = kzalloc(sizeof(*req), GFP_KERNEL); |
| 905 | if (!req) |
| 906 | return -ENOMEM; |
| 907 | |
| 908 | req->cid = cid; |
| 909 | req->cookie = cid; |
| 910 | |
| 911 | mutex_lock(&wil->probe_client_mutex); |
| 912 | list_add_tail(&req->list, &wil->probe_client_pending); |
| 913 | mutex_unlock(&wil->probe_client_mutex); |
| 914 | |
| 915 | *cookie = req->cookie; |
| 916 | queue_work(wil->wq_service, &wil->probe_client_worker); |
| 917 | return 0; |
| 918 | } |
| 919 | |
Vladimir Kondratiev | 02beaf1 | 2015-03-08 15:42:03 +0200 | [diff] [blame] | 920 | static int wil_cfg80211_change_bss(struct wiphy *wiphy, |
| 921 | struct net_device *dev, |
| 922 | struct bss_parameters *params) |
| 923 | { |
| 924 | struct wil6210_priv *wil = wiphy_to_wil(wiphy); |
| 925 | |
| 926 | if (params->ap_isolate >= 0) { |
| 927 | wil_dbg_misc(wil, "%s(ap_isolate %d => %d)\n", __func__, |
| 928 | wil->ap_isolate, params->ap_isolate); |
| 929 | wil->ap_isolate = params->ap_isolate; |
| 930 | } |
| 931 | |
| 932 | return 0; |
| 933 | } |
| 934 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 935 | static struct cfg80211_ops wil_cfg80211_ops = { |
| 936 | .scan = wil_cfg80211_scan, |
| 937 | .connect = wil_cfg80211_connect, |
| 938 | .disconnect = wil_cfg80211_disconnect, |
| 939 | .change_virtual_intf = wil_cfg80211_change_iface, |
| 940 | .get_station = wil_cfg80211_get_station, |
Vladimir Kondratiev | ef28afd | 2014-02-27 16:20:48 +0200 | [diff] [blame] | 941 | .dump_station = wil_cfg80211_dump_station, |
Vladimir Kondratiev | 1647f12 | 2014-02-27 16:20:40 +0200 | [diff] [blame] | 942 | .remain_on_channel = wil_remain_on_channel, |
| 943 | .cancel_remain_on_channel = wil_cancel_remain_on_channel, |
| 944 | .mgmt_tx = wil_cfg80211_mgmt_tx, |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 945 | .set_monitor_channel = wil_cfg80211_set_channel, |
| 946 | .add_key = wil_cfg80211_add_key, |
| 947 | .del_key = wil_cfg80211_del_key, |
| 948 | .set_default_key = wil_cfg80211_set_default_key, |
| 949 | /* AP mode */ |
Vladimir Kondratiev | 1bd922f | 2014-09-10 16:34:44 +0300 | [diff] [blame] | 950 | .change_beacon = wil_cfg80211_change_beacon, |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 951 | .start_ap = wil_cfg80211_start_ap, |
| 952 | .stop_ap = wil_cfg80211_stop_ap, |
Vladimir Kondratiev | 4d55a0a | 2014-02-27 16:20:54 +0200 | [diff] [blame] | 953 | .del_station = wil_cfg80211_del_station, |
Vladimir Kondratiev | 40822a9 | 2015-01-25 10:52:50 +0200 | [diff] [blame] | 954 | .probe_client = wil_cfg80211_probe_client, |
Vladimir Kondratiev | 02beaf1 | 2015-03-08 15:42:03 +0200 | [diff] [blame] | 955 | .change_bss = wil_cfg80211_change_bss, |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 956 | }; |
| 957 | |
| 958 | static void wil_wiphy_init(struct wiphy *wiphy) |
| 959 | { |
| 960 | /* TODO: set real value */ |
| 961 | wiphy->max_scan_ssids = 10; |
Vladimir Kondratiev | 77c9129 | 2014-09-10 16:34:47 +0300 | [diff] [blame] | 962 | wiphy->max_scan_ie_len = WMI_MAX_IE_LEN; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 963 | wiphy->max_num_pmkids = 0 /* TODO: */; |
| 964 | wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | |
| 965 | BIT(NL80211_IFTYPE_AP) | |
| 966 | BIT(NL80211_IFTYPE_MONITOR); |
| 967 | /* TODO: enable P2P when integrated with supplicant: |
| 968 | * BIT(NL80211_IFTYPE_P2P_CLIENT) | BIT(NL80211_IFTYPE_P2P_GO) |
| 969 | */ |
| 970 | wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME | |
| 971 | WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD; |
Vladimir Kondratiev | 9cf10d6 | 2014-09-10 16:34:36 +0300 | [diff] [blame] | 972 | dev_dbg(wiphy_dev(wiphy), "%s : flags = 0x%08x\n", |
| 973 | __func__, wiphy->flags); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 974 | wiphy->probe_resp_offload = |
| 975 | NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS | |
| 976 | NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 | |
| 977 | NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P; |
| 978 | |
| 979 | wiphy->bands[IEEE80211_BAND_60GHZ] = &wil_band_60ghz; |
| 980 | |
| 981 | /* TODO: figure this out */ |
Vladimir Kondratiev | b8b33a3 | 2014-02-27 16:20:52 +0200 | [diff] [blame] | 982 | wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 983 | |
| 984 | wiphy->cipher_suites = wil_cipher_suites; |
| 985 | wiphy->n_cipher_suites = ARRAY_SIZE(wil_cipher_suites); |
| 986 | wiphy->mgmt_stypes = wil_mgmt_stypes; |
Vladimir Kondratiev | 713c8a2 | 2015-01-25 10:52:49 +0200 | [diff] [blame] | 987 | wiphy->features |= NL80211_FEATURE_SK_TX_STATUS; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 988 | } |
| 989 | |
| 990 | struct wireless_dev *wil_cfg80211_init(struct device *dev) |
| 991 | { |
| 992 | int rc = 0; |
| 993 | struct wireless_dev *wdev; |
| 994 | |
Vladimir Kondratiev | 9cf10d6 | 2014-09-10 16:34:36 +0300 | [diff] [blame] | 995 | dev_dbg(dev, "%s()\n", __func__); |
| 996 | |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 997 | wdev = kzalloc(sizeof(*wdev), GFP_KERNEL); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 998 | if (!wdev) |
| 999 | return ERR_PTR(-ENOMEM); |
| 1000 | |
| 1001 | wdev->wiphy = wiphy_new(&wil_cfg80211_ops, |
| 1002 | sizeof(struct wil6210_priv)); |
| 1003 | if (!wdev->wiphy) { |
| 1004 | rc = -ENOMEM; |
| 1005 | goto out; |
| 1006 | } |
| 1007 | |
| 1008 | set_wiphy_dev(wdev->wiphy, dev); |
| 1009 | wil_wiphy_init(wdev->wiphy); |
| 1010 | |
| 1011 | rc = wiphy_register(wdev->wiphy); |
| 1012 | if (rc < 0) |
| 1013 | goto out_failed_reg; |
| 1014 | |
| 1015 | return wdev; |
| 1016 | |
| 1017 | out_failed_reg: |
| 1018 | wiphy_free(wdev->wiphy); |
| 1019 | out: |
| 1020 | kfree(wdev); |
| 1021 | |
| 1022 | return ERR_PTR(rc); |
| 1023 | } |
| 1024 | |
| 1025 | void wil_wdev_free(struct wil6210_priv *wil) |
| 1026 | { |
| 1027 | struct wireless_dev *wdev = wil_to_wdev(wil); |
| 1028 | |
Vladimir Kondratiev | 9cf10d6 | 2014-09-10 16:34:36 +0300 | [diff] [blame] | 1029 | dev_dbg(wil_to_dev(wil), "%s()\n", __func__); |
| 1030 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1031 | if (!wdev) |
| 1032 | return; |
| 1033 | |
| 1034 | wiphy_unregister(wdev->wiphy); |
| 1035 | wiphy_free(wdev->wiphy); |
| 1036 | kfree(wdev); |
| 1037 | } |