blob: d117240d9a7303d1d0a6a83e73607b6353fcdaef [file] [log] [blame]
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001/*
Lior Davidc5a157e2016-01-17 12:39:06 +02002 * Copyright (c) 2012-2016 Qualcomm Atheros, Inc.
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08003 *
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 Kondratieva82553bb2015-03-15 16:00:21 +020017#include <linux/etherdevice.h>
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080018#include "wil6210.h"
19#include "wmi.h"
20
Dedy Lanskye6d68342016-03-01 19:18:12 +020021#define WIL_MAX_ROC_DURATION_MS 5000
22
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080023#define CHAN60G(_channel, _flags) { \
Johannes Berg57fbcce2016-04-12 15:56:15 +020024 .band = NL80211_BAND_60GHZ, \
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080025 .center_freq = 56160 + (2160 * (_channel)), \
26 .hw_value = (_channel), \
27 .flags = (_flags), \
28 .max_antenna_gain = 0, \
29 .max_power = 40, \
30}
31
32static struct ieee80211_channel wil_60ghz_channels[] = {
33 CHAN60G(1, 0),
34 CHAN60G(2, 0),
35 CHAN60G(3, 0),
36/* channel 4 not supported yet */
37};
38
39static struct ieee80211_supported_band wil_band_60ghz = {
40 .channels = wil_60ghz_channels,
41 .n_channels = ARRAY_SIZE(wil_60ghz_channels),
42 .ht_cap = {
43 .ht_supported = true,
44 .cap = 0, /* TODO */
45 .ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K, /* TODO */
46 .ampdu_density = IEEE80211_HT_MPDU_DENSITY_8, /* TODO */
47 .mcs = {
48 /* MCS 1..12 - SC PHY */
49 .rx_mask = {0xfe, 0x1f}, /* 1..12 */
50 .tx_params = IEEE80211_HT_MCS_TX_DEFINED, /* TODO */
51 },
52 },
53};
54
55static const struct ieee80211_txrx_stypes
56wil_mgmt_stypes[NUM_NL80211_IFTYPES] = {
57 [NL80211_IFTYPE_STATION] = {
58 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
59 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
60 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
61 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
62 },
63 [NL80211_IFTYPE_AP] = {
64 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
65 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
66 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
67 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
68 },
69 [NL80211_IFTYPE_P2P_CLIENT] = {
70 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
71 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
72 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
73 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
74 },
75 [NL80211_IFTYPE_P2P_GO] = {
76 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
77 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
78 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
79 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
80 },
Lior David4332cac2016-03-01 19:18:13 +020081 [NL80211_IFTYPE_P2P_DEVICE] = {
82 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
83 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
84 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
85 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
86 },
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080087};
88
89static const u32 wil_cipher_suites[] = {
90 WLAN_CIPHER_SUITE_GCMP,
91};
92
Vladimir Kondratiev58527422016-03-01 19:18:07 +020093static const char * const key_usage_str[] = {
94 [WMI_KEY_USE_PAIRWISE] = "PTK",
95 [WMI_KEY_USE_RX_GROUP] = "RX_GTK",
96 [WMI_KEY_USE_TX_GROUP] = "TX_GTK",
97};
98
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080099int wil_iftype_nl2wmi(enum nl80211_iftype type)
100{
101 static const struct {
102 enum nl80211_iftype nl;
103 enum wmi_network_type wmi;
104 } __nl2wmi[] = {
105 {NL80211_IFTYPE_ADHOC, WMI_NETTYPE_ADHOC},
106 {NL80211_IFTYPE_STATION, WMI_NETTYPE_INFRA},
107 {NL80211_IFTYPE_AP, WMI_NETTYPE_AP},
108 {NL80211_IFTYPE_P2P_CLIENT, WMI_NETTYPE_P2P},
109 {NL80211_IFTYPE_P2P_GO, WMI_NETTYPE_P2P},
110 {NL80211_IFTYPE_MONITOR, WMI_NETTYPE_ADHOC}, /* FIXME */
111 };
112 uint i;
113
114 for (i = 0; i < ARRAY_SIZE(__nl2wmi); i++) {
115 if (__nl2wmi[i].nl == type)
116 return __nl2wmi[i].wmi;
117 }
118
119 return -EOPNOTSUPP;
120}
121
Vladimir Kondratiev9eb82d42014-06-16 19:37:13 +0300122int wil_cid_fill_sinfo(struct wil6210_priv *wil, int cid,
123 struct station_info *sinfo)
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800124{
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800125 struct wmi_notify_req_cmd cmd = {
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +0200126 .cid = cid,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800127 .interval_usec = 0,
128 };
Vladimir Kondratievef28afd2014-02-27 16:20:48 +0200129 struct {
Lior Davidb874dde2016-03-01 19:18:09 +0200130 struct wmi_cmd_hdr wmi;
Vladimir Kondratievef28afd2014-02-27 16:20:48 +0200131 struct wmi_notify_req_done_event evt;
132 } __packed reply;
Vladimir Kondratievc8b78b52014-02-27 16:20:49 +0200133 struct wil_net_stats *stats = &wil->sta[cid].stats;
Vladimir Kondratievef28afd2014-02-27 16:20:48 +0200134 int rc;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800135
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800136 rc = wmi_call(wil, WMI_NOTIFY_REQ_CMDID, &cmd, sizeof(cmd),
Vladimir Kondratievef28afd2014-02-27 16:20:48 +0200137 WMI_NOTIFY_REQ_DONE_EVENTID, &reply, sizeof(reply), 20);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800138 if (rc)
139 return rc;
140
Vladimir Kondratievc8b78b52014-02-27 16:20:49 +0200141 wil_dbg_wmi(wil, "Link status for CID %d: {\n"
142 " MCS %d TSF 0x%016llx\n"
Vladimir Kondratievb8b33a32014-02-27 16:20:52 +0200143 " BF status 0x%08x SNR 0x%08x SQI %d%%\n"
Vladimir Kondratievc8b78b52014-02-27 16:20:49 +0200144 " Tx Tpt %d goodput %d Rx goodput %d\n"
145 " Sectors(rx:tx) my %d:%d peer %d:%d\n""}\n",
146 cid, le16_to_cpu(reply.evt.bf_mcs),
147 le64_to_cpu(reply.evt.tsf), reply.evt.status,
148 le32_to_cpu(reply.evt.snr_val),
Vladimir Kondratievb8b33a32014-02-27 16:20:52 +0200149 reply.evt.sqi,
Vladimir Kondratievc8b78b52014-02-27 16:20:49 +0200150 le32_to_cpu(reply.evt.tx_tpt),
151 le32_to_cpu(reply.evt.tx_goodput),
152 le32_to_cpu(reply.evt.rx_goodput),
153 le16_to_cpu(reply.evt.my_rx_sector),
154 le16_to_cpu(reply.evt.my_tx_sector),
155 le16_to_cpu(reply.evt.other_rx_sector),
156 le16_to_cpu(reply.evt.other_tx_sector));
157
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800158 sinfo->generation = wil->sinfo_gen;
159
Johannes Berg319090b2014-11-17 14:08:11 +0100160 sinfo->filled = BIT(NL80211_STA_INFO_RX_BYTES) |
161 BIT(NL80211_STA_INFO_TX_BYTES) |
162 BIT(NL80211_STA_INFO_RX_PACKETS) |
163 BIT(NL80211_STA_INFO_TX_PACKETS) |
164 BIT(NL80211_STA_INFO_RX_BITRATE) |
165 BIT(NL80211_STA_INFO_TX_BITRATE) |
166 BIT(NL80211_STA_INFO_RX_DROP_MISC) |
167 BIT(NL80211_STA_INFO_TX_FAILED);
Vladimir Kondratievc8b78b52014-02-27 16:20:49 +0200168
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800169 sinfo->txrate.flags = RATE_INFO_FLAGS_MCS | RATE_INFO_FLAGS_60G;
Vladimir Kondratievef28afd2014-02-27 16:20:48 +0200170 sinfo->txrate.mcs = le16_to_cpu(reply.evt.bf_mcs);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800171 sinfo->rxrate.flags = RATE_INFO_FLAGS_MCS | RATE_INFO_FLAGS_60G;
Vladimir Kondratievc8b78b52014-02-27 16:20:49 +0200172 sinfo->rxrate.mcs = stats->last_mcs_rx;
173 sinfo->rx_bytes = stats->rx_bytes;
174 sinfo->rx_packets = stats->rx_packets;
175 sinfo->rx_dropped_misc = stats->rx_dropped;
176 sinfo->tx_bytes = stats->tx_bytes;
177 sinfo->tx_packets = stats->tx_packets;
178 sinfo->tx_failed = stats->tx_errors;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800179
Vladimir Kondratiev9419b6a2014-12-23 09:47:14 +0200180 if (test_bit(wil_status_fwconnected, wil->status)) {
Johannes Berg319090b2014-11-17 14:08:11 +0100181 sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL);
Vladimir Kondratievb8b33a32014-02-27 16:20:52 +0200182 sinfo->signal = reply.evt.sqi;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800183 }
184
Vladimir Kondratievef28afd2014-02-27 16:20:48 +0200185 return rc;
186}
187
188static int wil_cfg80211_get_station(struct wiphy *wiphy,
189 struct net_device *ndev,
Johannes Berg3b3a0162014-05-19 17:19:31 +0200190 const u8 *mac, struct station_info *sinfo)
Vladimir Kondratievef28afd2014-02-27 16:20:48 +0200191{
192 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
193 int rc;
194
195 int cid = wil_find_cid(wil, mac);
196
Vladimir Kondratievfa4a18e2014-03-17 15:34:16 +0200197 wil_dbg_misc(wil, "%s(%pM) CID %d\n", __func__, mac, cid);
Vladimir Kondratievef28afd2014-02-27 16:20:48 +0200198 if (cid < 0)
Vladimir Kondratievc14c5d92014-03-02 11:20:51 +0200199 return cid;
Vladimir Kondratievef28afd2014-02-27 16:20:48 +0200200
201 rc = wil_cid_fill_sinfo(wil, cid, sinfo);
202
203 return rc;
204}
205
206/*
207 * Find @idx-th active STA for station dump.
208 */
209static int wil_find_cid_by_idx(struct wil6210_priv *wil, int idx)
210{
211 int i;
212
213 for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
214 if (wil->sta[i].status == wil_sta_unused)
215 continue;
216 if (idx == 0)
217 return i;
218 idx--;
219 }
220
221 return -ENOENT;
222}
223
224static int wil_cfg80211_dump_station(struct wiphy *wiphy,
225 struct net_device *dev, int idx,
226 u8 *mac, struct station_info *sinfo)
227{
228 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
229 int rc;
230 int cid = wil_find_cid_by_idx(wil, idx);
231
232 if (cid < 0)
233 return -ENOENT;
234
Vladimir Kondratieva82553bb2015-03-15 16:00:21 +0200235 ether_addr_copy(mac, wil->sta[cid].addr);
Vladimir Kondratievfa4a18e2014-03-17 15:34:16 +0200236 wil_dbg_misc(wil, "%s(%pM) CID %d\n", __func__, mac, cid);
Vladimir Kondratievef28afd2014-02-27 16:20:48 +0200237
238 rc = wil_cid_fill_sinfo(wil, cid, sinfo);
239
240 return rc;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800241}
242
Lior David4332cac2016-03-01 19:18:13 +0200243static struct wireless_dev *
244wil_cfg80211_add_iface(struct wiphy *wiphy, const char *name,
245 unsigned char name_assign_type,
246 enum nl80211_iftype type,
247 u32 *flags, struct vif_params *params)
248{
249 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
250 struct net_device *ndev = wil_to_ndev(wil);
251 struct wireless_dev *p2p_wdev;
252
253 wil_dbg_misc(wil, "%s()\n", __func__);
254
255 if (type != NL80211_IFTYPE_P2P_DEVICE) {
256 wil_err(wil, "%s: unsupported iftype %d\n", __func__, type);
257 return ERR_PTR(-EINVAL);
258 }
259
260 if (wil->p2p_wdev) {
261 wil_err(wil, "%s: P2P_DEVICE interface already created\n",
262 __func__);
263 return ERR_PTR(-EINVAL);
264 }
265
266 p2p_wdev = kzalloc(sizeof(*p2p_wdev), GFP_KERNEL);
267 if (!p2p_wdev)
268 return ERR_PTR(-ENOMEM);
269
270 p2p_wdev->iftype = type;
271 p2p_wdev->wiphy = wiphy;
272 /* use our primary ethernet address */
273 ether_addr_copy(p2p_wdev->address, ndev->perm_addr);
274
275 wil->p2p_wdev = p2p_wdev;
276
277 return p2p_wdev;
278}
279
280static int wil_cfg80211_del_iface(struct wiphy *wiphy,
281 struct wireless_dev *wdev)
282{
283 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
284
285 wil_dbg_misc(wil, "%s()\n", __func__);
286
287 if (wdev != wil->p2p_wdev) {
288 wil_err(wil, "%s: delete of incorrect interface 0x%p\n",
289 __func__, wdev);
290 return -EINVAL;
291 }
292
293 wil_p2p_wdev_free(wil);
294
295 return 0;
296}
297
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800298static int wil_cfg80211_change_iface(struct wiphy *wiphy,
299 struct net_device *ndev,
300 enum nl80211_iftype type, u32 *flags,
301 struct vif_params *params)
302{
303 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
Lior David4332cac2016-03-01 19:18:13 +0200304 struct wireless_dev *wdev = wil_to_wdev(wil);
Dedy Lanskye6d68342016-03-01 19:18:12 +0200305 int rc;
306
307 wil_dbg_misc(wil, "%s() type=%d\n", __func__, type);
308
Lior David375a1732016-03-01 19:18:16 +0200309 if (netif_running(wil_to_ndev(wil)) && !wil_is_recovery_blocked(wil)) {
Dedy Lanskye6d68342016-03-01 19:18:12 +0200310 wil_dbg_misc(wil, "interface is up. resetting...\n");
311 mutex_lock(&wil->mutex);
312 __wil_down(wil);
313 rc = __wil_up(wil);
314 mutex_unlock(&wil->mutex);
315
316 if (rc)
317 return rc;
318 }
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800319
320 switch (type) {
321 case NL80211_IFTYPE_STATION:
322 case NL80211_IFTYPE_AP:
323 case NL80211_IFTYPE_P2P_CLIENT:
324 case NL80211_IFTYPE_P2P_GO:
325 break;
326 case NL80211_IFTYPE_MONITOR:
327 if (flags)
328 wil->monitor_flags = *flags;
329 else
330 wil->monitor_flags = 0;
331
332 break;
333 default:
334 return -EOPNOTSUPP;
335 }
336
337 wdev->iftype = type;
338
339 return 0;
340}
341
342static int wil_cfg80211_scan(struct wiphy *wiphy,
343 struct cfg80211_scan_request *request)
344{
345 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
Lior David4332cac2016-03-01 19:18:13 +0200346 struct wireless_dev *wdev = request->wdev;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800347 struct {
348 struct wmi_start_scan_cmd cmd;
349 u16 chnl[4];
350 } __packed cmd;
351 uint i, n;
Vladimir Kondratieved6f9dc2014-03-17 15:34:19 +0200352 int rc;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800353
Lior David4332cac2016-03-01 19:18:13 +0200354 wil_dbg_misc(wil, "%s(), wdev=0x%p iftype=%d\n",
355 __func__, wdev, wdev->iftype);
Dedy Lanskye6d68342016-03-01 19:18:12 +0200356
Lior David5ffae432016-08-22 12:42:19 +0300357 mutex_lock(&wil->p2p_wdev_mutex);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800358 if (wil->scan_request) {
359 wil_err(wil, "Already scanning\n");
Lior David5ffae432016-08-22 12:42:19 +0300360 mutex_unlock(&wil->p2p_wdev_mutex);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800361 return -EAGAIN;
362 }
Lior David5ffae432016-08-22 12:42:19 +0300363 mutex_unlock(&wil->p2p_wdev_mutex);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800364
365 /* check we are client side */
366 switch (wdev->iftype) {
367 case NL80211_IFTYPE_STATION:
368 case NL80211_IFTYPE_P2P_CLIENT:
Lior David4332cac2016-03-01 19:18:13 +0200369 case NL80211_IFTYPE_P2P_DEVICE:
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800370 break;
371 default:
372 return -EOPNOTSUPP;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800373 }
374
375 /* FW don't support scan after connection attempt */
Vladimir Kondratiev9419b6a2014-12-23 09:47:14 +0200376 if (test_bit(wil_status_dontscan, wil->status)) {
Vladimir Kondratieve83eb2f2014-03-17 15:34:07 +0200377 wil_err(wil, "Can't scan now\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800378 return -EBUSY;
379 }
380
Lior David321a0002016-04-26 14:41:38 +0300381 /* social scan on P2P_DEVICE is handled as p2p search */
382 if (wdev->iftype == NL80211_IFTYPE_P2P_DEVICE &&
383 wil_p2p_is_social_scan(request)) {
Lior Davideb57a5b2016-06-08 20:07:48 +0300384 if (!wil->p2p.p2p_dev_started) {
385 wil_err(wil, "P2P search requested on stopped P2P device\n");
386 return -EIO;
387 }
Dedy Lanskye6d68342016-03-01 19:18:12 +0200388 wil->scan_request = request;
Lior David4332cac2016-03-01 19:18:13 +0200389 wil->radio_wdev = wdev;
390 rc = wil_p2p_search(wil, request);
391 if (rc) {
392 wil->radio_wdev = wil_to_wdev(wil);
393 wil->scan_request = NULL;
394 }
395 return rc;
Dedy Lanskye6d68342016-03-01 19:18:12 +0200396 }
397
Lior David280ab982016-03-01 19:18:14 +0200398 (void)wil_p2p_stop_discovery(wil);
Dedy Lanskye6d68342016-03-01 19:18:12 +0200399
Vladimir Kondratiev2a91d7d2014-06-16 19:37:11 +0300400 wil_dbg_misc(wil, "Start scan_request 0x%p\n", request);
Hamad Kadmany8e52fe32015-06-09 14:11:18 +0300401 wil_dbg_misc(wil, "SSID count: %d", request->n_ssids);
402
403 for (i = 0; i < request->n_ssids; i++) {
404 wil_dbg_misc(wil, "SSID[%d]", i);
405 print_hex_dump_bytes("SSID ", DUMP_PREFIX_OFFSET,
406 request->ssids[i].ssid,
407 request->ssids[i].ssid_len);
408 }
409
410 if (request->n_ssids)
411 rc = wmi_set_ssid(wil, request->ssids[0].ssid_len,
412 request->ssids[0].ssid);
413 else
414 rc = wmi_set_ssid(wil, 0, NULL);
415
416 if (rc) {
417 wil_err(wil, "set SSID for scan request failed: %d\n", rc);
418 return rc;
419 }
420
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800421 wil->scan_request = request;
Vladimir Kondratiev047e5d72014-05-27 14:45:48 +0300422 mod_timer(&wil->scan_timer, jiffies + WIL6210_SCAN_TO);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800423
424 memset(&cmd, 0, sizeof(cmd));
Lior David74997a52016-03-01 19:18:08 +0200425 cmd.cmd.scan_type = WMI_ACTIVE_SCAN;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800426 cmd.cmd.num_channels = 0;
427 n = min(request->n_channels, 4U);
428 for (i = 0; i < n; i++) {
429 int ch = request->channels[i]->hw_value;
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300430
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800431 if (ch == 0) {
432 wil_err(wil,
433 "Scan requested for unknown frequency %dMhz\n",
434 request->channels[i]->center_freq);
435 continue;
436 }
437 /* 0-based channel indexes */
438 cmd.cmd.channel_list[cmd.cmd.num_channels++].channel = ch - 1;
Vladimir Kondratiev77438822013-01-28 18:31:06 +0200439 wil_dbg_misc(wil, "Scan for ch %d : %d MHz\n", ch,
Vladimir Kondratiev2057ebb2013-01-28 18:30:58 +0200440 request->channels[i]->center_freq);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800441 }
442
Vladimir Kondratiev77c91292014-09-10 16:34:47 +0300443 if (request->ie_len)
444 print_hex_dump_bytes("Scan IE ", DUMP_PREFIX_OFFSET,
445 request->ie, request->ie_len);
446 else
447 wil_dbg_misc(wil, "Scan has no IE's\n");
448
Vladimir Kondratiev5421bf02015-07-30 13:52:00 +0300449 rc = wmi_set_ie(wil, WMI_FRAME_PROBE_REQ, request->ie_len, request->ie);
450 if (rc)
Vladimir Kondratiev77c91292014-09-10 16:34:47 +0300451 goto out;
Vladimir Kondratiev77c91292014-09-10 16:34:47 +0300452
Lior David74997a52016-03-01 19:18:08 +0200453 if (wil->discovery_mode && cmd.cmd.scan_type == WMI_ACTIVE_SCAN) {
454 cmd.cmd.discovery_mode = 1;
455 wil_dbg_misc(wil, "active scan with discovery_mode=1\n");
456 }
457
Lior David4332cac2016-03-01 19:18:13 +0200458 wil->radio_wdev = wdev;
Vladimir Kondratieved6f9dc2014-03-17 15:34:19 +0200459 rc = wmi_send(wil, WMI_START_SCAN_CMDID, &cmd, sizeof(cmd.cmd) +
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800460 cmd.cmd.num_channels * sizeof(cmd.cmd.channel_list[0]));
Vladimir Kondratieved6f9dc2014-03-17 15:34:19 +0200461
Vladimir Kondratiev77c91292014-09-10 16:34:47 +0300462out:
Vladimir Kondratieva2142082014-08-06 10:31:57 +0300463 if (rc) {
464 del_timer_sync(&wil->scan_timer);
Lior David4332cac2016-03-01 19:18:13 +0200465 wil->radio_wdev = wil_to_wdev(wil);
Vladimir Kondratieved6f9dc2014-03-17 15:34:19 +0200466 wil->scan_request = NULL;
Vladimir Kondratieva2142082014-08-06 10:31:57 +0300467 }
Vladimir Kondratieved6f9dc2014-03-17 15:34:19 +0200468
469 return rc;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800470}
471
Vladimir Kondratievfeeac222015-02-01 10:55:15 +0200472static void wil_print_crypto(struct wil6210_priv *wil,
473 struct cfg80211_crypto_settings *c)
474{
475 int i, n;
476
477 wil_dbg_misc(wil, "WPA versions: 0x%08x cipher group 0x%08x\n",
478 c->wpa_versions, c->cipher_group);
479 wil_dbg_misc(wil, "Pairwise ciphers [%d] {\n", c->n_ciphers_pairwise);
480 n = min_t(int, c->n_ciphers_pairwise, ARRAY_SIZE(c->ciphers_pairwise));
481 for (i = 0; i < n; i++)
482 wil_dbg_misc(wil, " [%d] = 0x%08x\n", i,
483 c->ciphers_pairwise[i]);
484 wil_dbg_misc(wil, "}\n");
485 wil_dbg_misc(wil, "AKM suites [%d] {\n", c->n_akm_suites);
486 n = min_t(int, c->n_akm_suites, ARRAY_SIZE(c->akm_suites));
487 for (i = 0; i < n; i++)
488 wil_dbg_misc(wil, " [%d] = 0x%08x\n", i,
489 c->akm_suites[i]);
490 wil_dbg_misc(wil, "}\n");
491 wil_dbg_misc(wil, "Control port : %d, eth_type 0x%04x no_encrypt %d\n",
492 c->control_port, be16_to_cpu(c->control_port_ethertype),
493 c->control_port_no_encrypt);
494}
495
Vladimir Kondratiev8ca26162014-09-10 16:34:32 +0300496static void wil_print_connect_params(struct wil6210_priv *wil,
497 struct cfg80211_connect_params *sme)
498{
499 wil_info(wil, "Connecting to:\n");
500 if (sme->channel) {
501 wil_info(wil, " Channel: %d freq %d\n",
502 sme->channel->hw_value, sme->channel->center_freq);
503 }
504 if (sme->bssid)
505 wil_info(wil, " BSSID: %pM\n", sme->bssid);
506 if (sme->ssid)
507 print_hex_dump(KERN_INFO, " SSID: ", DUMP_PREFIX_OFFSET,
508 16, 1, sme->ssid, sme->ssid_len, true);
509 wil_info(wil, " Privacy: %s\n", sme->privacy ? "secure" : "open");
Lior Davideabb03b2016-03-01 19:18:10 +0200510 wil_info(wil, " PBSS: %d\n", sme->pbss);
Vladimir Kondratievfeeac222015-02-01 10:55:15 +0200511 wil_print_crypto(wil, &sme->crypto);
Vladimir Kondratiev8ca26162014-09-10 16:34:32 +0300512}
513
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800514static int wil_cfg80211_connect(struct wiphy *wiphy,
515 struct net_device *ndev,
516 struct cfg80211_connect_params *sme)
517{
518 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
519 struct cfg80211_bss *bss;
520 struct wmi_connect_cmd conn;
521 const u8 *ssid_eid;
522 const u8 *rsn_eid;
523 int ch;
524 int rc = 0;
Lior Davideabb03b2016-03-01 19:18:10 +0200525 enum ieee80211_bss_type bss_type = IEEE80211_BSS_TYPE_ESS;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800526
Dedy Lanskye6d68342016-03-01 19:18:12 +0200527 wil_dbg_misc(wil, "%s()\n", __func__);
Vladimir Kondratiev344a7022015-02-15 14:02:37 +0200528 wil_print_connect_params(wil, sme);
529
Vladimir Kondratiev9419b6a2014-12-23 09:47:14 +0200530 if (test_bit(wil_status_fwconnecting, wil->status) ||
531 test_bit(wil_status_fwconnected, wil->status))
Vladimir Kondratiev4cd9e832014-03-17 15:34:20 +0200532 return -EALREADY;
533
Vladimir Kondratiev344a7022015-02-15 14:02:37 +0200534 if (sme->ie_len > WMI_MAX_IE_LEN) {
535 wil_err(wil, "IE too large (%td bytes)\n", sme->ie_len);
536 return -ERANGE;
537 }
538
539 rsn_eid = sme->ie ?
540 cfg80211_find_ie(WLAN_EID_RSN, sme->ie, sme->ie_len) :
541 NULL;
Vladimir Kondratiev27aa6b72015-04-30 16:25:11 +0300542 if (sme->privacy && !rsn_eid)
543 wil_info(wil, "WSC connection\n");
Vladimir Kondratiev8ca26162014-09-10 16:34:32 +0300544
Lior Davideabb03b2016-03-01 19:18:10 +0200545 if (sme->pbss)
546 bss_type = IEEE80211_BSS_TYPE_PBSS;
Lior David34d50512016-01-28 10:58:25 +0200547
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800548 bss = cfg80211_get_bss(wiphy, sme->channel, sme->bssid,
549 sme->ssid, sme->ssid_len,
Lior Davideabb03b2016-03-01 19:18:10 +0200550 bss_type, IEEE80211_PRIVACY_ANY);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800551 if (!bss) {
552 wil_err(wil, "Unable to find BSS\n");
553 return -ENOENT;
554 }
555
556 ssid_eid = ieee80211_bss_get_ie(bss, WLAN_EID_SSID);
557 if (!ssid_eid) {
558 wil_err(wil, "No SSID\n");
559 rc = -ENOENT;
560 goto out;
561 }
Vladimir Kondratiev344a7022015-02-15 14:02:37 +0200562 wil->privacy = sme->privacy;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800563
Vladimir Kondratiev344a7022015-02-15 14:02:37 +0200564 if (wil->privacy) {
Vladimir Kondratiev230d8442015-04-30 16:25:10 +0300565 /* For secure assoc, remove old keys */
566 rc = wmi_del_cipher_key(wil, 0, bss->bssid,
567 WMI_KEY_USE_PAIRWISE);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800568 if (rc) {
Vladimir Kondratiev230d8442015-04-30 16:25:10 +0300569 wil_err(wil, "WMI_DELETE_CIPHER_KEY_CMD(PTK) failed\n");
570 goto out;
571 }
572 rc = wmi_del_cipher_key(wil, 0, bss->bssid,
573 WMI_KEY_USE_RX_GROUP);
574 if (rc) {
575 wil_err(wil, "WMI_DELETE_CIPHER_KEY_CMD(GTK) failed\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800576 goto out;
577 }
Vladimir Kondratievac4acdb2014-09-10 16:34:43 +0300578 }
579
580 /* WMI_SET_APPIE_CMD. ie may contain rsn info as well as other info
581 * elements. Send it also in case it's empty, to erase previously set
582 * ies in FW.
583 */
584 rc = wmi_set_ie(wil, WMI_FRAME_ASSOC_REQ, sme->ie_len, sme->ie);
Vladimir Kondratiev5421bf02015-07-30 13:52:00 +0300585 if (rc)
Vladimir Kondratievac4acdb2014-09-10 16:34:43 +0300586 goto out;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800587
588 /* WMI_CONNECT_CMD */
589 memset(&conn, 0, sizeof(conn));
Vladimir Kondratievacc97802013-03-13 14:12:47 +0200590 switch (bss->capability & WLAN_CAPABILITY_DMG_TYPE_MASK) {
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800591 case WLAN_CAPABILITY_DMG_TYPE_AP:
592 conn.network_type = WMI_NETTYPE_INFRA;
593 break;
594 case WLAN_CAPABILITY_DMG_TYPE_PBSS:
595 conn.network_type = WMI_NETTYPE_P2P;
596 break;
597 default:
598 wil_err(wil, "Unsupported BSS type, capability= 0x%04x\n",
599 bss->capability);
600 goto out;
601 }
Vladimir Kondratiev344a7022015-02-15 14:02:37 +0200602 if (wil->privacy) {
Vladimir Kondratiev27aa6b72015-04-30 16:25:11 +0300603 if (rsn_eid) { /* regular secure connection */
604 conn.dot11_auth_mode = WMI_AUTH11_SHARED;
605 conn.auth_mode = WMI_AUTH_WPA2_PSK;
606 conn.pairwise_crypto_type = WMI_CRYPT_AES_GCMP;
607 conn.pairwise_crypto_len = 16;
608 conn.group_crypto_type = WMI_CRYPT_AES_GCMP;
609 conn.group_crypto_len = 16;
610 } else { /* WSC */
611 conn.dot11_auth_mode = WMI_AUTH11_WSC;
612 conn.auth_mode = WMI_AUTH_NONE;
613 }
614 } else { /* insecure connection */
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800615 conn.dot11_auth_mode = WMI_AUTH11_OPEN;
616 conn.auth_mode = WMI_AUTH_NONE;
617 }
618
619 conn.ssid_len = min_t(u8, ssid_eid[1], 32);
620 memcpy(conn.ssid, ssid_eid+2, conn.ssid_len);
621
622 ch = bss->channel->hw_value;
623 if (ch == 0) {
624 wil_err(wil, "BSS at unknown frequency %dMhz\n",
625 bss->channel->center_freq);
626 rc = -EOPNOTSUPP;
627 goto out;
628 }
629 conn.channel = ch - 1;
630
Vladimir Kondratieva82553bb2015-03-15 16:00:21 +0200631 ether_addr_copy(conn.bssid, bss->bssid);
632 ether_addr_copy(conn.dst_mac, bss->bssid);
Vladimir Kondratieve83eb2f2014-03-17 15:34:07 +0200633
Vladimir Kondratiev9419b6a2014-12-23 09:47:14 +0200634 set_bit(wil_status_fwconnecting, wil->status);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800635
636 rc = wmi_send(wil, WMI_CONNECT_CMDID, &conn, sizeof(conn));
637 if (rc == 0) {
Dedy Lanskyc5e96c92015-01-25 10:52:43 +0200638 netif_carrier_on(ndev);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800639 /* Connect can take lots of time */
640 mod_timer(&wil->connect_timer,
641 jiffies + msecs_to_jiffies(2000));
Vladimir Kondratievb338f742013-05-28 15:17:53 +0300642 } else {
Vladimir Kondratiev9419b6a2014-12-23 09:47:14 +0200643 clear_bit(wil_status_fwconnecting, wil->status);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800644 }
645
646 out:
Johannes Berg5b112d32013-02-01 01:49:58 +0100647 cfg80211_put_bss(wiphy, bss);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800648
649 return rc;
650}
651
652static int wil_cfg80211_disconnect(struct wiphy *wiphy,
653 struct net_device *ndev,
654 u16 reason_code)
655{
656 int rc;
657 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
658
Vladimir Kondratievde9084e2015-03-30 11:28:52 +0300659 wil_dbg_misc(wil, "%s(reason=%d)\n", __func__, reason_code);
660
Vladimir Kondratiev78771d72016-01-28 19:24:03 +0200661 if (!(test_bit(wil_status_fwconnecting, wil->status) ||
662 test_bit(wil_status_fwconnected, wil->status))) {
663 wil_err(wil, "%s: Disconnect was called while disconnected\n",
664 __func__);
665 return 0;
666 }
667
668 rc = wmi_call(wil, WMI_DISCONNECT_CMDID, NULL, 0,
669 WMI_DISCONNECT_EVENTID, NULL, 0,
670 WIL6210_DISCONNECT_TO_MS);
671 if (rc)
672 wil_err(wil, "%s: disconnect error %d\n", __func__, rc);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800673
674 return rc;
675}
676
Vladimir Kondratiev0b39aaf2014-06-16 19:36:59 +0300677int wil_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
678 struct cfg80211_mgmt_tx_params *params,
679 u64 *cookie)
Vladimir Kondratiev1647f122014-02-27 16:20:40 +0200680{
681 const u8 *buf = params->buf;
682 size_t len = params->len;
683 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
684 int rc;
Vladimir Kondratiev304464f2014-06-16 19:37:00 +0300685 bool tx_status = false;
Vladimir Kondratiev1647f122014-02-27 16:20:40 +0200686 struct ieee80211_mgmt *mgmt_frame = (void *)buf;
687 struct wmi_sw_tx_req_cmd *cmd;
688 struct {
Lior Davidb874dde2016-03-01 19:18:09 +0200689 struct wmi_cmd_hdr wmi;
Vladimir Kondratiev1647f122014-02-27 16:20:40 +0200690 struct wmi_sw_tx_complete_event evt;
691 } __packed evt;
692
Dedy Lanskye6d68342016-03-01 19:18:12 +0200693 /* Note, currently we do not support the "wait" parameter, user-space
694 * must call remain_on_channel before mgmt_tx or listen on a channel
695 * another way (AP/PCP or connected station)
696 * in addition we need to check if specified "chan" argument is
697 * different from currently "listened" channel and fail if it is.
698 */
699
700 wil_dbg_misc(wil, "%s()\n", __func__);
701 print_hex_dump_bytes("mgmt tx frame ", DUMP_PREFIX_OFFSET, buf, len);
702
Vladimir Kondratiev1647f122014-02-27 16:20:40 +0200703 cmd = kmalloc(sizeof(*cmd) + len, GFP_KERNEL);
Vladimir Kondratiev304464f2014-06-16 19:37:00 +0300704 if (!cmd) {
705 rc = -ENOMEM;
706 goto out;
707 }
Vladimir Kondratiev1647f122014-02-27 16:20:40 +0200708
709 memcpy(cmd->dst_mac, mgmt_frame->da, WMI_MAC_LEN);
710 cmd->len = cpu_to_le16(len);
711 memcpy(cmd->payload, buf, len);
712
713 rc = wmi_call(wil, WMI_SW_TX_REQ_CMDID, cmd, sizeof(*cmd) + len,
714 WMI_SW_TX_COMPLETE_EVENTID, &evt, sizeof(evt), 2000);
715 if (rc == 0)
Vladimir Kondratiev304464f2014-06-16 19:37:00 +0300716 tx_status = !evt.evt.status;
Vladimir Kondratiev1647f122014-02-27 16:20:40 +0200717
718 kfree(cmd);
Vladimir Kondratiev304464f2014-06-16 19:37:00 +0300719 out:
720 cfg80211_mgmt_tx_status(wdev, cookie ? *cookie : 0, buf, len,
721 tx_status, GFP_KERNEL);
Vladimir Kondratiev1647f122014-02-27 16:20:40 +0200722 return rc;
723}
724
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800725static int wil_cfg80211_set_channel(struct wiphy *wiphy,
726 struct cfg80211_chan_def *chandef)
727{
728 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
Lior David4332cac2016-03-01 19:18:13 +0200729 struct wireless_dev *wdev = wil_to_wdev(wil);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800730
731 wdev->preset_chandef = *chandef;
732
733 return 0;
734}
735
Vladimir Kondratiev230d8442015-04-30 16:25:10 +0300736static enum wmi_key_usage wil_detect_key_usage(struct wil6210_priv *wil,
737 bool pairwise)
738{
Lior David4332cac2016-03-01 19:18:13 +0200739 struct wireless_dev *wdev = wil_to_wdev(wil);
Vladimir Kondratiev230d8442015-04-30 16:25:10 +0300740 enum wmi_key_usage rc;
Vladimir Kondratiev230d8442015-04-30 16:25:10 +0300741
742 if (pairwise) {
743 rc = WMI_KEY_USE_PAIRWISE;
744 } else {
745 switch (wdev->iftype) {
746 case NL80211_IFTYPE_STATION:
Dedy Lanskye6d68342016-03-01 19:18:12 +0200747 case NL80211_IFTYPE_P2P_CLIENT:
Vladimir Kondratiev230d8442015-04-30 16:25:10 +0300748 rc = WMI_KEY_USE_RX_GROUP;
749 break;
750 case NL80211_IFTYPE_AP:
Dedy Lanskye6d68342016-03-01 19:18:12 +0200751 case NL80211_IFTYPE_P2P_GO:
Vladimir Kondratiev230d8442015-04-30 16:25:10 +0300752 rc = WMI_KEY_USE_TX_GROUP;
753 break;
754 default:
755 /* TODO: Rx GTK or Tx GTK? */
756 wil_err(wil, "Can't determine GTK type\n");
757 rc = WMI_KEY_USE_RX_GROUP;
758 break;
759 }
760 }
761 wil_dbg_misc(wil, "%s() -> %s\n", __func__, key_usage_str[rc]);
762
763 return rc;
764}
765
Maya Erez74b6ac52016-08-18 16:52:12 +0300766static struct wil_sta_info *
767wil_find_sta_by_key_usage(struct wil6210_priv *wil,
768 enum wmi_key_usage key_usage, const u8 *mac_addr)
Vladimir Kondratiev58527422016-03-01 19:18:07 +0200769{
770 int cid = -EINVAL;
Vladimir Kondratiev58527422016-03-01 19:18:07 +0200771
772 if (key_usage == WMI_KEY_USE_TX_GROUP)
773 return NULL; /* not needed */
774
775 /* supplicant provides Rx group key in STA mode with NULL MAC address */
776 if (mac_addr)
777 cid = wil_find_cid(wil, mac_addr);
778 else if (key_usage == WMI_KEY_USE_RX_GROUP)
779 cid = wil_find_cid_by_idx(wil, 0);
780 if (cid < 0) {
Maya Erez74b6ac52016-08-18 16:52:12 +0300781 wil_err(wil, "No CID for %pM %s\n", mac_addr,
782 key_usage_str[key_usage]);
Vladimir Kondratiev58527422016-03-01 19:18:07 +0200783 return ERR_PTR(cid);
784 }
785
Maya Erez74b6ac52016-08-18 16:52:12 +0300786 return &wil->sta[cid];
787}
Vladimir Kondratiev58527422016-03-01 19:18:07 +0200788
Maya Erez74b6ac52016-08-18 16:52:12 +0300789static void wil_set_crypto_rx(u8 key_index, enum wmi_key_usage key_usage,
790 struct wil_sta_info *cs,
791 struct key_params *params)
792{
793 struct wil_tid_crypto_rx_single *cc;
794 int tid;
795
796 if (!cs)
797 return;
798
799 switch (key_usage) {
800 case WMI_KEY_USE_PAIRWISE:
801 for (tid = 0; tid < WIL_STA_TID_NUM; tid++) {
802 cc = &cs->tid_crypto_rx[tid].key_id[key_index];
803 if (params->seq)
804 memcpy(cc->pn, params->seq,
805 IEEE80211_GCMP_PN_LEN);
806 else
807 memset(cc->pn, 0, IEEE80211_GCMP_PN_LEN);
808 cc->key_set = true;
809 }
810 break;
811 case WMI_KEY_USE_RX_GROUP:
812 cc = &cs->group_crypto_rx.key_id[key_index];
813 if (params->seq)
814 memcpy(cc->pn, params->seq, IEEE80211_GCMP_PN_LEN);
815 else
816 memset(cc->pn, 0, IEEE80211_GCMP_PN_LEN);
817 cc->key_set = true;
818 break;
819 default:
820 break;
821 }
822}
823
824static void wil_del_rx_key(u8 key_index, enum wmi_key_usage key_usage,
825 struct wil_sta_info *cs)
826{
827 struct wil_tid_crypto_rx_single *cc;
828 int tid;
829
830 if (!cs)
831 return;
832
833 switch (key_usage) {
834 case WMI_KEY_USE_PAIRWISE:
835 for (tid = 0; tid < WIL_STA_TID_NUM; tid++) {
836 cc = &cs->tid_crypto_rx[tid].key_id[key_index];
837 cc->key_set = false;
838 }
839 break;
840 case WMI_KEY_USE_RX_GROUP:
841 cc = &cs->group_crypto_rx.key_id[key_index];
842 cc->key_set = false;
843 break;
844 default:
845 break;
846 }
Vladimir Kondratiev58527422016-03-01 19:18:07 +0200847}
848
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800849static int wil_cfg80211_add_key(struct wiphy *wiphy,
850 struct net_device *ndev,
851 u8 key_index, bool pairwise,
852 const u8 *mac_addr,
853 struct key_params *params)
854{
Vladimir Kondratiev58527422016-03-01 19:18:07 +0200855 int rc;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800856 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
Vladimir Kondratiev230d8442015-04-30 16:25:10 +0300857 enum wmi_key_usage key_usage = wil_detect_key_usage(wil, pairwise);
Maya Erez74b6ac52016-08-18 16:52:12 +0300858 struct wil_sta_info *cs = wil_find_sta_by_key_usage(wil, key_usage,
859 mac_addr);
860
861 if (!params) {
862 wil_err(wil, "NULL params\n");
863 return -EINVAL;
864 }
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800865
Vladimir Kondratiev58527422016-03-01 19:18:07 +0200866 wil_dbg_misc(wil, "%s(%pM %s[%d] PN %*phN)\n", __func__,
867 mac_addr, key_usage_str[key_usage], key_index,
868 params->seq_len, params->seq);
Vladimir Kondratievdb8adcb2015-03-30 11:28:51 +0300869
Maya Erez74b6ac52016-08-18 16:52:12 +0300870 if (IS_ERR(cs)) {
Vladimir Kondratiev58527422016-03-01 19:18:07 +0200871 wil_err(wil, "Not connected, %s(%pM %s[%d] PN %*phN)\n",
872 __func__, mac_addr, key_usage_str[key_usage], key_index,
873 params->seq_len, params->seq);
874 return -EINVAL;
875 }
876
Maya Erez74b6ac52016-08-18 16:52:12 +0300877 wil_del_rx_key(key_index, key_usage, cs);
Vladimir Kondratiev58527422016-03-01 19:18:07 +0200878
879 if (params->seq && params->seq_len != IEEE80211_GCMP_PN_LEN) {
880 wil_err(wil,
881 "Wrong PN len %d, %s(%pM %s[%d] PN %*phN)\n",
882 params->seq_len, __func__, mac_addr,
883 key_usage_str[key_usage], key_index,
884 params->seq_len, params->seq);
885 return -EINVAL;
886 }
887
888 rc = wmi_add_cipher_key(wil, key_index, mac_addr, params->key_len,
889 params->key, key_usage);
Maya Erez74b6ac52016-08-18 16:52:12 +0300890 if (!rc)
891 wil_set_crypto_rx(key_index, key_usage, cs, params);
Vladimir Kondratiev58527422016-03-01 19:18:07 +0200892
893 return rc;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800894}
895
896static int wil_cfg80211_del_key(struct wiphy *wiphy,
897 struct net_device *ndev,
898 u8 key_index, bool pairwise,
899 const u8 *mac_addr)
900{
901 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
Vladimir Kondratiev230d8442015-04-30 16:25:10 +0300902 enum wmi_key_usage key_usage = wil_detect_key_usage(wil, pairwise);
Maya Erez74b6ac52016-08-18 16:52:12 +0300903 struct wil_sta_info *cs = wil_find_sta_by_key_usage(wil, key_usage,
904 mac_addr);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800905
Vladimir Kondratiev58527422016-03-01 19:18:07 +0200906 wil_dbg_misc(wil, "%s(%pM %s[%d])\n", __func__, mac_addr,
907 key_usage_str[key_usage], key_index);
908
Maya Erez74b6ac52016-08-18 16:52:12 +0300909 if (IS_ERR(cs))
Vladimir Kondratiev58527422016-03-01 19:18:07 +0200910 wil_info(wil, "Not connected, %s(%pM %s[%d])\n", __func__,
911 mac_addr, key_usage_str[key_usage], key_index);
912
Maya Erez74b6ac52016-08-18 16:52:12 +0300913 if (!IS_ERR_OR_NULL(cs))
914 wil_del_rx_key(key_index, key_usage, cs);
Vladimir Kondratievdb8adcb2015-03-30 11:28:51 +0300915
Vladimir Kondratiev230d8442015-04-30 16:25:10 +0300916 return wmi_del_cipher_key(wil, key_index, mac_addr, key_usage);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800917}
918
919/* Need to be present or wiphy_new() will WARN */
920static int wil_cfg80211_set_default_key(struct wiphy *wiphy,
921 struct net_device *ndev,
922 u8 key_index, bool unicast,
923 bool multicast)
924{
Lior David280ab982016-03-01 19:18:14 +0200925 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
926
927 wil_dbg_misc(wil, "%s: entered\n", __func__);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800928 return 0;
929}
930
Vladimir Kondratiev1647f122014-02-27 16:20:40 +0200931static int wil_remain_on_channel(struct wiphy *wiphy,
932 struct wireless_dev *wdev,
933 struct ieee80211_channel *chan,
934 unsigned int duration,
935 u64 *cookie)
936{
937 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
938 int rc;
939
Lior David4332cac2016-03-01 19:18:13 +0200940 wil_dbg_misc(wil, "%s() center_freq=%d, duration=%d iftype=%d\n",
941 __func__, chan->center_freq, duration, wdev->iftype);
Vladimir Kondratiev1647f122014-02-27 16:20:40 +0200942
Dedy Lanskye6d68342016-03-01 19:18:12 +0200943 rc = wil_p2p_listen(wil, duration, chan, cookie);
Vladimir Kondratiev1647f122014-02-27 16:20:40 +0200944 if (rc)
945 return rc;
946
Lior David4332cac2016-03-01 19:18:13 +0200947 wil->radio_wdev = wdev;
948
949 cfg80211_ready_on_channel(wdev, *cookie, chan, duration,
Dedy Lanskye6d68342016-03-01 19:18:12 +0200950 GFP_KERNEL);
Vladimir Kondratiev1647f122014-02-27 16:20:40 +0200951
Dedy Lanskye6d68342016-03-01 19:18:12 +0200952 return 0;
Vladimir Kondratiev1647f122014-02-27 16:20:40 +0200953}
954
955static int wil_cancel_remain_on_channel(struct wiphy *wiphy,
956 struct wireless_dev *wdev,
957 u64 cookie)
958{
959 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
Vladimir Kondratiev1647f122014-02-27 16:20:40 +0200960
Dedy Lanskye6d68342016-03-01 19:18:12 +0200961 wil_dbg_misc(wil, "%s()\n", __func__);
Vladimir Kondratiev1647f122014-02-27 16:20:40 +0200962
Lior David280ab982016-03-01 19:18:14 +0200963 return wil_p2p_cancel_listen(wil, cookie);
Vladimir Kondratiev1647f122014-02-27 16:20:40 +0200964}
965
Lior Davidc100c882016-01-17 12:39:07 +0200966/**
967 * find a specific IE in a list of IEs
968 * return a pointer to the beginning of IE in the list
969 * or NULL if not found
970 */
971static const u8 *_wil_cfg80211_find_ie(const u8 *ies, u16 ies_len, const u8 *ie,
972 u16 ie_len)
973{
974 struct ieee80211_vendor_ie *vie;
975 u32 oui;
976
977 /* IE tag at offset 0, length at offset 1 */
978 if (ie_len < 2 || 2 + ie[1] > ie_len)
979 return NULL;
980
981 if (ie[0] != WLAN_EID_VENDOR_SPECIFIC)
982 return cfg80211_find_ie(ie[0], ies, ies_len);
983
984 /* make sure there is room for 3 bytes OUI + 1 byte OUI type */
985 if (ie[1] < 4)
986 return NULL;
987 vie = (struct ieee80211_vendor_ie *)ie;
988 oui = vie->oui[0] << 16 | vie->oui[1] << 8 | vie->oui[2];
989 return cfg80211_find_vendor_ie(oui, vie->oui_type, ies,
990 ies_len);
991}
992
993/**
994 * merge the IEs in two lists into a single list.
995 * do not include IEs from the second list which exist in the first list.
996 * add only vendor specific IEs from second list to keep
997 * the merged list sorted (since vendor-specific IE has the
998 * highest tag number)
999 * caller must free the allocated memory for merged IEs
1000 */
1001static int _wil_cfg80211_merge_extra_ies(const u8 *ies1, u16 ies1_len,
1002 const u8 *ies2, u16 ies2_len,
1003 u8 **merged_ies, u16 *merged_len)
1004{
1005 u8 *buf, *dpos;
1006 const u8 *spos;
1007
1008 if (ies1_len == 0 && ies2_len == 0) {
1009 *merged_ies = NULL;
1010 *merged_len = 0;
1011 return 0;
1012 }
1013
1014 buf = kmalloc(ies1_len + ies2_len, GFP_KERNEL);
1015 if (!buf)
1016 return -ENOMEM;
1017 memcpy(buf, ies1, ies1_len);
1018 dpos = buf + ies1_len;
1019 spos = ies2;
1020 while (spos + 1 < ies2 + ies2_len) {
1021 /* IE tag at offset 0, length at offset 1 */
1022 u16 ielen = 2 + spos[1];
1023
1024 if (spos + ielen > ies2 + ies2_len)
1025 break;
1026 if (spos[0] == WLAN_EID_VENDOR_SPECIFIC &&
1027 !_wil_cfg80211_find_ie(ies1, ies1_len, spos, ielen)) {
1028 memcpy(dpos, spos, ielen);
1029 dpos += ielen;
1030 }
1031 spos += ielen;
1032 }
1033
1034 *merged_ies = buf;
1035 *merged_len = dpos - buf;
1036 return 0;
1037}
1038
Vladimir Kondratievca959772014-06-16 19:37:01 +03001039static void wil_print_bcon_data(struct cfg80211_beacon_data *b)
1040{
1041 print_hex_dump_bytes("head ", DUMP_PREFIX_OFFSET,
1042 b->head, b->head_len);
1043 print_hex_dump_bytes("tail ", DUMP_PREFIX_OFFSET,
1044 b->tail, b->tail_len);
1045 print_hex_dump_bytes("BCON IE ", DUMP_PREFIX_OFFSET,
1046 b->beacon_ies, b->beacon_ies_len);
1047 print_hex_dump_bytes("PROBE ", DUMP_PREFIX_OFFSET,
1048 b->probe_resp, b->probe_resp_len);
1049 print_hex_dump_bytes("PROBE IE ", DUMP_PREFIX_OFFSET,
1050 b->proberesp_ies, b->proberesp_ies_len);
1051 print_hex_dump_bytes("ASSOC IE ", DUMP_PREFIX_OFFSET,
1052 b->assocresp_ies, b->assocresp_ies_len);
1053}
1054
Vladimir Kondratiev33190eb2015-06-15 17:42:32 +03001055/* internal functions for device reset and starting AP */
1056static int _wil_cfg80211_set_ies(struct wiphy *wiphy,
Vladimir Kondratievcab5abb2015-07-30 13:51:59 +03001057 struct cfg80211_beacon_data *bcon)
Vladimir Kondratiev33190eb2015-06-15 17:42:32 +03001058{
1059 int rc;
1060 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
Lior Davidc100c882016-01-17 12:39:07 +02001061 u16 len = 0, proberesp_len = 0;
1062 u8 *ies = NULL, *proberesp = NULL;
Vladimir Kondratiev33190eb2015-06-15 17:42:32 +03001063
Lior Davidc100c882016-01-17 12:39:07 +02001064 if (bcon->probe_resp) {
1065 struct ieee80211_mgmt *f =
1066 (struct ieee80211_mgmt *)bcon->probe_resp;
1067 size_t hlen = offsetof(struct ieee80211_mgmt,
1068 u.probe_resp.variable);
1069 proberesp = f->u.probe_resp.variable;
1070 proberesp_len = bcon->probe_resp_len - hlen;
1071 }
1072 rc = _wil_cfg80211_merge_extra_ies(proberesp,
1073 proberesp_len,
1074 bcon->proberesp_ies,
1075 bcon->proberesp_ies_len,
1076 &ies, &len);
1077
Vladimir Kondratiev5421bf02015-07-30 13:52:00 +03001078 if (rc)
Lior Davidc100c882016-01-17 12:39:07 +02001079 goto out;
Vladimir Kondratiev33190eb2015-06-15 17:42:32 +03001080
Lior Davidc100c882016-01-17 12:39:07 +02001081 rc = wmi_set_ie(wil, WMI_FRAME_PROBE_RESP, len, ies);
1082 if (rc)
1083 goto out;
1084
1085 if (bcon->assocresp_ies)
1086 rc = wmi_set_ie(wil, WMI_FRAME_ASSOC_RESP,
1087 bcon->assocresp_ies_len, bcon->assocresp_ies);
1088 else
1089 rc = wmi_set_ie(wil, WMI_FRAME_ASSOC_RESP, len, ies);
Vladimir Kondratievcab5abb2015-07-30 13:51:59 +03001090#if 0 /* to use beacon IE's, remove this #if 0 */
Vladimir Kondratiev5421bf02015-07-30 13:52:00 +03001091 if (rc)
Lior Davidc100c882016-01-17 12:39:07 +02001092 goto out;
Vladimir Kondratiev5421bf02015-07-30 13:52:00 +03001093
1094 rc = wmi_set_ie(wil, WMI_FRAME_BEACON, bcon->tail_len, bcon->tail);
Vladimir Kondratievcab5abb2015-07-30 13:51:59 +03001095#endif
Lior Davidc100c882016-01-17 12:39:07 +02001096out:
1097 kfree(ies);
Vladimir Kondratiev5421bf02015-07-30 13:52:00 +03001098 return rc;
Vladimir Kondratiev33190eb2015-06-15 17:42:32 +03001099}
1100
1101static int _wil_cfg80211_start_ap(struct wiphy *wiphy,
1102 struct net_device *ndev,
1103 const u8 *ssid, size_t ssid_len, u32 privacy,
1104 int bi, u8 chan,
Vladimir Kondratievcab5abb2015-07-30 13:51:59 +03001105 struct cfg80211_beacon_data *bcon,
Lior Davideabb03b2016-03-01 19:18:10 +02001106 u8 hidden_ssid, u32 pbss)
Vladimir Kondratiev33190eb2015-06-15 17:42:32 +03001107{
1108 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1109 int rc;
1110 struct wireless_dev *wdev = ndev->ieee80211_ptr;
1111 u8 wmi_nettype = wil_iftype_nl2wmi(wdev->iftype);
Lior Davidb4944f22016-03-01 19:18:17 +02001112 u8 is_go = (wdev->iftype == NL80211_IFTYPE_P2P_GO);
Vladimir Kondratiev33190eb2015-06-15 17:42:32 +03001113
Lior Davideabb03b2016-03-01 19:18:10 +02001114 if (pbss)
1115 wmi_nettype = WMI_NETTYPE_P2P;
1116
Lior Davidb4944f22016-03-01 19:18:17 +02001117 wil_dbg_misc(wil, "%s: is_go=%d\n", __func__, is_go);
1118 if (is_go && !pbss) {
1119 wil_err(wil, "%s: P2P GO must be in PBSS\n", __func__);
1120 return -ENOTSUPP;
1121 }
1122
Vladimir Kondratiev33190eb2015-06-15 17:42:32 +03001123 wil_set_recovery_state(wil, fw_recovery_idle);
1124
1125 mutex_lock(&wil->mutex);
1126
1127 __wil_down(wil);
1128 rc = __wil_up(wil);
1129 if (rc)
1130 goto out;
1131
1132 rc = wmi_set_ssid(wil, ssid_len, ssid);
1133 if (rc)
1134 goto out;
1135
Vladimir Kondratievcab5abb2015-07-30 13:51:59 +03001136 rc = _wil_cfg80211_set_ies(wiphy, bcon);
Vladimir Kondratiev33190eb2015-06-15 17:42:32 +03001137 if (rc)
1138 goto out;
1139
1140 wil->privacy = privacy;
1141 wil->channel = chan;
1142 wil->hidden_ssid = hidden_ssid;
Lior Davideabb03b2016-03-01 19:18:10 +02001143 wil->pbss = pbss;
Vladimir Kondratiev33190eb2015-06-15 17:42:32 +03001144
1145 netif_carrier_on(ndev);
1146
Lior Davidb4944f22016-03-01 19:18:17 +02001147 rc = wmi_pcp_start(wil, bi, wmi_nettype, chan, hidden_ssid, is_go);
Vladimir Kondratiev33190eb2015-06-15 17:42:32 +03001148 if (rc)
1149 goto err_pcp_start;
1150
1151 rc = wil_bcast_init(wil);
1152 if (rc)
1153 goto err_bcast;
1154
1155 goto out; /* success */
1156
1157err_bcast:
1158 wmi_pcp_stop(wil);
1159err_pcp_start:
1160 netif_carrier_off(ndev);
1161out:
1162 mutex_unlock(&wil->mutex);
1163 return rc;
1164}
1165
Vladimir Kondratiev1bd922f2014-09-10 16:34:44 +03001166static int wil_cfg80211_change_beacon(struct wiphy *wiphy,
1167 struct net_device *ndev,
1168 struct cfg80211_beacon_data *bcon)
1169{
1170 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1171 int rc;
Vladimir Kondratiev33190eb2015-06-15 17:42:32 +03001172 u32 privacy = 0;
Vladimir Kondratiev1bd922f2014-09-10 16:34:44 +03001173
1174 wil_dbg_misc(wil, "%s()\n", __func__);
Vladimir Kondratiev1e7e5a02015-04-30 16:25:08 +03001175 wil_print_bcon_data(bcon);
1176
Lior Davidc5a157e2016-01-17 12:39:06 +02001177 if (bcon->tail &&
1178 cfg80211_find_ie(WLAN_EID_RSN, bcon->tail,
1179 bcon->tail_len))
Vladimir Kondratiev33190eb2015-06-15 17:42:32 +03001180 privacy = 1;
1181
1182 /* in case privacy has changed, need to restart the AP */
1183 if (wil->privacy != privacy) {
1184 struct wireless_dev *wdev = ndev->ieee80211_ptr;
1185
1186 wil_dbg_misc(wil, "privacy changed %d=>%d. Restarting AP\n",
1187 wil->privacy, privacy);
1188
1189 rc = _wil_cfg80211_start_ap(wiphy, ndev, wdev->ssid,
1190 wdev->ssid_len, privacy,
1191 wdev->beacon_interval,
Vladimir Kondratievcab5abb2015-07-30 13:51:59 +03001192 wil->channel, bcon,
Lior Davideabb03b2016-03-01 19:18:10 +02001193 wil->hidden_ssid,
1194 wil->pbss);
Vladimir Kondratiev33190eb2015-06-15 17:42:32 +03001195 } else {
Vladimir Kondratievcab5abb2015-07-30 13:51:59 +03001196 rc = _wil_cfg80211_set_ies(wiphy, bcon);
Vladimir Kondratiev1bd922f2014-09-10 16:34:44 +03001197 }
1198
Vladimir Kondratiev33190eb2015-06-15 17:42:32 +03001199 return rc;
Vladimir Kondratiev1bd922f2014-09-10 16:34:44 +03001200}
1201
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001202static int wil_cfg80211_start_ap(struct wiphy *wiphy,
1203 struct net_device *ndev,
1204 struct cfg80211_ap_settings *info)
1205{
Vladimir Kondratiev33190eb2015-06-15 17:42:32 +03001206 int rc;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001207 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001208 struct ieee80211_channel *channel = info->chandef.chan;
1209 struct cfg80211_beacon_data *bcon = &info->beacon;
Vladimir Kondratievca959772014-06-16 19:37:01 +03001210 struct cfg80211_crypto_settings *crypto = &info->crypto;
Hamad Kadmany8e52fe32015-06-09 14:11:18 +03001211 u8 hidden_ssid;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001212
Vladimir Kondratievca959772014-06-16 19:37:01 +03001213 wil_dbg_misc(wil, "%s()\n", __func__);
1214
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001215 if (!channel) {
1216 wil_err(wil, "AP: No channel???\n");
1217 return -EINVAL;
1218 }
1219
Vladimir Kondratiev33190eb2015-06-15 17:42:32 +03001220 switch (info->hidden_ssid) {
1221 case NL80211_HIDDEN_SSID_NOT_IN_USE:
1222 hidden_ssid = WMI_HIDDEN_SSID_DISABLED;
1223 break;
1224
1225 case NL80211_HIDDEN_SSID_ZERO_LEN:
1226 hidden_ssid = WMI_HIDDEN_SSID_SEND_EMPTY;
1227 break;
1228
1229 case NL80211_HIDDEN_SSID_ZERO_CONTENTS:
1230 hidden_ssid = WMI_HIDDEN_SSID_CLEAR;
1231 break;
1232
1233 default:
1234 wil_err(wil, "AP: Invalid hidden SSID %d\n", info->hidden_ssid);
1235 return -EOPNOTSUPP;
1236 }
Vladimir Kondratiev77438822013-01-28 18:31:06 +02001237 wil_dbg_misc(wil, "AP on Channel %d %d MHz, %s\n", channel->hw_value,
Vladimir Kondratiev2057ebb2013-01-28 18:30:58 +02001238 channel->center_freq, info->privacy ? "secure" : "open");
Vladimir Kondratievca959772014-06-16 19:37:01 +03001239 wil_dbg_misc(wil, "Privacy: %d auth_type %d\n",
1240 info->privacy, info->auth_type);
Hamad Kadmany8e52fe32015-06-09 14:11:18 +03001241 wil_dbg_misc(wil, "Hidden SSID mode: %d\n",
1242 info->hidden_ssid);
Vladimir Kondratievca959772014-06-16 19:37:01 +03001243 wil_dbg_misc(wil, "BI %d DTIM %d\n", info->beacon_interval,
1244 info->dtim_period);
Lior Davideabb03b2016-03-01 19:18:10 +02001245 wil_dbg_misc(wil, "PBSS %d\n", info->pbss);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001246 print_hex_dump_bytes("SSID ", DUMP_PREFIX_OFFSET,
1247 info->ssid, info->ssid_len);
Vladimir Kondratievca959772014-06-16 19:37:01 +03001248 wil_print_bcon_data(bcon);
1249 wil_print_crypto(wil, crypto);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001250
Vladimir Kondratiev33190eb2015-06-15 17:42:32 +03001251 rc = _wil_cfg80211_start_ap(wiphy, ndev,
1252 info->ssid, info->ssid_len, info->privacy,
1253 info->beacon_interval, channel->hw_value,
Lior Davideabb03b2016-03-01 19:18:10 +02001254 bcon, hidden_ssid, info->pbss);
Vladimir Kondratievc33407a2014-10-01 15:05:24 +03001255
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001256 return rc;
1257}
1258
1259static int wil_cfg80211_stop_ap(struct wiphy *wiphy,
1260 struct net_device *ndev)
1261{
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001262 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001263
Vladimir Kondratievca959772014-06-16 19:37:01 +03001264 wil_dbg_misc(wil, "%s()\n", __func__);
1265
Dedy Lanskyc5e96c92015-01-25 10:52:43 +02001266 netif_carrier_off(ndev);
Vladimir Kondratievc33407a2014-10-01 15:05:24 +03001267 wil_set_recovery_state(wil, fw_recovery_idle);
1268
Vladimir Kondratiev9c3bde52014-03-17 15:34:21 +02001269 mutex_lock(&wil->mutex);
1270
Dedy Lansky32a20d42015-01-25 10:52:44 +02001271 wmi_pcp_stop(wil);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001272
Vladimir Kondratiev73d839a2014-09-10 16:34:50 +03001273 __wil_down(wil);
Vladimir Kondratiev73d839a2014-09-10 16:34:50 +03001274
Vladimir Kondratiev9c3bde52014-03-17 15:34:21 +02001275 mutex_unlock(&wil->mutex);
Vladimir Kondratiev73d839a2014-09-10 16:34:50 +03001276
Dedy Lansky32a20d42015-01-25 10:52:44 +02001277 return 0;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001278}
1279
Vladimir Kondratiev4d55a0a2014-02-27 16:20:54 +02001280static int wil_cfg80211_del_station(struct wiphy *wiphy,
Jouni Malinen89c771e2014-10-10 20:52:40 +03001281 struct net_device *dev,
1282 struct station_del_parameters *params)
Vladimir Kondratiev4d55a0a2014-02-27 16:20:54 +02001283{
1284 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
Vladimir Kondratiev097638a2014-03-17 15:34:25 +02001285
Vladimir Kondratievde9084e2015-03-30 11:28:52 +03001286 wil_dbg_misc(wil, "%s(%pM, reason=%d)\n", __func__, params->mac,
1287 params->reason_code);
1288
Vladimir Kondratiev097638a2014-03-17 15:34:25 +02001289 mutex_lock(&wil->mutex);
Vladimir Kondratiev4821e6d2014-12-01 15:33:15 +02001290 wil6210_disconnect(wil, params->mac, params->reason_code, false);
Vladimir Kondratiev097638a2014-03-17 15:34:25 +02001291 mutex_unlock(&wil->mutex);
1292
Vladimir Kondratiev4d55a0a2014-02-27 16:20:54 +02001293 return 0;
1294}
1295
Vladimir Kondratiev40822a92015-01-25 10:52:50 +02001296/* probe_client handling */
1297static void wil_probe_client_handle(struct wil6210_priv *wil,
1298 struct wil_probe_client_req *req)
1299{
1300 struct net_device *ndev = wil_to_ndev(wil);
1301 struct wil_sta_info *sta = &wil->sta[req->cid];
1302 /* assume STA is alive if it is still connected,
1303 * else FW will disconnect it
1304 */
1305 bool alive = (sta->status == wil_sta_connected);
1306
1307 cfg80211_probe_status(ndev, sta->addr, req->cookie, alive, GFP_KERNEL);
1308}
1309
1310static struct list_head *next_probe_client(struct wil6210_priv *wil)
1311{
1312 struct list_head *ret = NULL;
1313
1314 mutex_lock(&wil->probe_client_mutex);
1315
1316 if (!list_empty(&wil->probe_client_pending)) {
1317 ret = wil->probe_client_pending.next;
1318 list_del(ret);
1319 }
1320
1321 mutex_unlock(&wil->probe_client_mutex);
1322
1323 return ret;
1324}
1325
1326void wil_probe_client_worker(struct work_struct *work)
1327{
1328 struct wil6210_priv *wil = container_of(work, struct wil6210_priv,
1329 probe_client_worker);
1330 struct wil_probe_client_req *req;
1331 struct list_head *lh;
1332
1333 while ((lh = next_probe_client(wil)) != NULL) {
1334 req = list_entry(lh, struct wil_probe_client_req, list);
1335
1336 wil_probe_client_handle(wil, req);
1337 kfree(req);
1338 }
1339}
1340
1341void wil_probe_client_flush(struct wil6210_priv *wil)
1342{
1343 struct wil_probe_client_req *req, *t;
1344
1345 wil_dbg_misc(wil, "%s()\n", __func__);
1346
1347 mutex_lock(&wil->probe_client_mutex);
1348
1349 list_for_each_entry_safe(req, t, &wil->probe_client_pending, list) {
1350 list_del(&req->list);
1351 kfree(req);
1352 }
1353
1354 mutex_unlock(&wil->probe_client_mutex);
1355}
1356
1357static int wil_cfg80211_probe_client(struct wiphy *wiphy,
1358 struct net_device *dev,
1359 const u8 *peer, u64 *cookie)
1360{
1361 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1362 struct wil_probe_client_req *req;
1363 int cid = wil_find_cid(wil, peer);
1364
1365 wil_dbg_misc(wil, "%s(%pM => CID %d)\n", __func__, peer, cid);
1366
1367 if (cid < 0)
1368 return -ENOLINK;
1369
1370 req = kzalloc(sizeof(*req), GFP_KERNEL);
1371 if (!req)
1372 return -ENOMEM;
1373
1374 req->cid = cid;
1375 req->cookie = cid;
1376
1377 mutex_lock(&wil->probe_client_mutex);
1378 list_add_tail(&req->list, &wil->probe_client_pending);
1379 mutex_unlock(&wil->probe_client_mutex);
1380
1381 *cookie = req->cookie;
1382 queue_work(wil->wq_service, &wil->probe_client_worker);
1383 return 0;
1384}
1385
Vladimir Kondratiev02beaf12015-03-08 15:42:03 +02001386static int wil_cfg80211_change_bss(struct wiphy *wiphy,
1387 struct net_device *dev,
1388 struct bss_parameters *params)
1389{
1390 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1391
1392 if (params->ap_isolate >= 0) {
1393 wil_dbg_misc(wil, "%s(ap_isolate %d => %d)\n", __func__,
1394 wil->ap_isolate, params->ap_isolate);
1395 wil->ap_isolate = params->ap_isolate;
1396 }
1397
1398 return 0;
1399}
1400
Lior David4332cac2016-03-01 19:18:13 +02001401static int wil_cfg80211_start_p2p_device(struct wiphy *wiphy,
1402 struct wireless_dev *wdev)
1403{
1404 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1405
1406 wil_dbg_misc(wil, "%s: entered\n", __func__);
Lior Davideb57a5b2016-06-08 20:07:48 +03001407 wil->p2p.p2p_dev_started = 1;
Lior David4332cac2016-03-01 19:18:13 +02001408 return 0;
1409}
1410
1411static void wil_cfg80211_stop_p2p_device(struct wiphy *wiphy,
1412 struct wireless_dev *wdev)
1413{
1414 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
Maya Erezd35c2b62016-08-18 16:52:14 +03001415 struct wil_p2p_info *p2p = &wil->p2p;
1416
1417 if (!p2p->p2p_dev_started)
1418 return;
Lior David4332cac2016-03-01 19:18:13 +02001419
1420 wil_dbg_misc(wil, "%s: entered\n", __func__);
Lior Davideb57a5b2016-06-08 20:07:48 +03001421 mutex_lock(&wil->mutex);
Maya Erezd35c2b62016-08-18 16:52:14 +03001422 wil_p2p_stop_radio_operations(wil);
1423 p2p->p2p_dev_started = 0;
Lior Davideb57a5b2016-06-08 20:07:48 +03001424 mutex_unlock(&wil->mutex);
Lior David4332cac2016-03-01 19:18:13 +02001425}
1426
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001427static struct cfg80211_ops wil_cfg80211_ops = {
Lior David4332cac2016-03-01 19:18:13 +02001428 .add_virtual_intf = wil_cfg80211_add_iface,
1429 .del_virtual_intf = wil_cfg80211_del_iface,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001430 .scan = wil_cfg80211_scan,
1431 .connect = wil_cfg80211_connect,
1432 .disconnect = wil_cfg80211_disconnect,
1433 .change_virtual_intf = wil_cfg80211_change_iface,
1434 .get_station = wil_cfg80211_get_station,
Vladimir Kondratievef28afd2014-02-27 16:20:48 +02001435 .dump_station = wil_cfg80211_dump_station,
Vladimir Kondratiev1647f122014-02-27 16:20:40 +02001436 .remain_on_channel = wil_remain_on_channel,
1437 .cancel_remain_on_channel = wil_cancel_remain_on_channel,
1438 .mgmt_tx = wil_cfg80211_mgmt_tx,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001439 .set_monitor_channel = wil_cfg80211_set_channel,
1440 .add_key = wil_cfg80211_add_key,
1441 .del_key = wil_cfg80211_del_key,
1442 .set_default_key = wil_cfg80211_set_default_key,
1443 /* AP mode */
Vladimir Kondratiev1bd922f2014-09-10 16:34:44 +03001444 .change_beacon = wil_cfg80211_change_beacon,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001445 .start_ap = wil_cfg80211_start_ap,
1446 .stop_ap = wil_cfg80211_stop_ap,
Vladimir Kondratiev4d55a0a2014-02-27 16:20:54 +02001447 .del_station = wil_cfg80211_del_station,
Vladimir Kondratiev40822a92015-01-25 10:52:50 +02001448 .probe_client = wil_cfg80211_probe_client,
Vladimir Kondratiev02beaf12015-03-08 15:42:03 +02001449 .change_bss = wil_cfg80211_change_bss,
Lior David4332cac2016-03-01 19:18:13 +02001450 /* P2P device */
1451 .start_p2p_device = wil_cfg80211_start_p2p_device,
1452 .stop_p2p_device = wil_cfg80211_stop_p2p_device,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001453};
1454
1455static void wil_wiphy_init(struct wiphy *wiphy)
1456{
Hamad Kadmany8e52fe32015-06-09 14:11:18 +03001457 wiphy->max_scan_ssids = 1;
Vladimir Kondratiev77c91292014-09-10 16:34:47 +03001458 wiphy->max_scan_ie_len = WMI_MAX_IE_LEN;
Dedy Lanskye6d68342016-03-01 19:18:12 +02001459 wiphy->max_remain_on_channel_duration = WIL_MAX_ROC_DURATION_MS;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001460 wiphy->max_num_pmkids = 0 /* TODO: */;
1461 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
1462 BIT(NL80211_IFTYPE_AP) |
Dedy Lanskye6d68342016-03-01 19:18:12 +02001463 BIT(NL80211_IFTYPE_P2P_CLIENT) |
1464 BIT(NL80211_IFTYPE_P2P_GO) |
Lior David4332cac2016-03-01 19:18:13 +02001465 BIT(NL80211_IFTYPE_P2P_DEVICE) |
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001466 BIT(NL80211_IFTYPE_MONITOR);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001467 wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME |
Dedy Lanskye6d68342016-03-01 19:18:12 +02001468 WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL |
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001469 WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
Vladimir Kondratiev9cf10d62014-09-10 16:34:36 +03001470 dev_dbg(wiphy_dev(wiphy), "%s : flags = 0x%08x\n",
1471 __func__, wiphy->flags);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001472 wiphy->probe_resp_offload =
1473 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
1474 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
1475 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
1476
Johannes Berg57fbcce2016-04-12 15:56:15 +02001477 wiphy->bands[NL80211_BAND_60GHZ] = &wil_band_60ghz;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001478
1479 /* TODO: figure this out */
Vladimir Kondratievb8b33a32014-02-27 16:20:52 +02001480 wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001481
1482 wiphy->cipher_suites = wil_cipher_suites;
1483 wiphy->n_cipher_suites = ARRAY_SIZE(wil_cipher_suites);
1484 wiphy->mgmt_stypes = wil_mgmt_stypes;
Vladimir Kondratiev713c8a22015-01-25 10:52:49 +02001485 wiphy->features |= NL80211_FEATURE_SK_TX_STATUS;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001486}
1487
1488struct wireless_dev *wil_cfg80211_init(struct device *dev)
1489{
1490 int rc = 0;
1491 struct wireless_dev *wdev;
1492
Vladimir Kondratiev9cf10d62014-09-10 16:34:36 +03001493 dev_dbg(dev, "%s()\n", __func__);
1494
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +03001495 wdev = kzalloc(sizeof(*wdev), GFP_KERNEL);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001496 if (!wdev)
1497 return ERR_PTR(-ENOMEM);
1498
1499 wdev->wiphy = wiphy_new(&wil_cfg80211_ops,
1500 sizeof(struct wil6210_priv));
1501 if (!wdev->wiphy) {
1502 rc = -ENOMEM;
1503 goto out;
1504 }
1505
1506 set_wiphy_dev(wdev->wiphy, dev);
1507 wil_wiphy_init(wdev->wiphy);
1508
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001509 return wdev;
1510
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001511out:
1512 kfree(wdev);
1513
1514 return ERR_PTR(rc);
1515}
1516
1517void wil_wdev_free(struct wil6210_priv *wil)
1518{
1519 struct wireless_dev *wdev = wil_to_wdev(wil);
1520
Vladimir Kondratiev9cf10d62014-09-10 16:34:36 +03001521 dev_dbg(wil_to_dev(wil), "%s()\n", __func__);
1522
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001523 if (!wdev)
1524 return;
1525
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001526 wiphy_free(wdev->wiphy);
1527 kfree(wdev);
1528}
Lior David4332cac2016-03-01 19:18:13 +02001529
1530void wil_p2p_wdev_free(struct wil6210_priv *wil)
1531{
1532 struct wireless_dev *p2p_wdev;
1533
1534 mutex_lock(&wil->p2p_wdev_mutex);
1535 p2p_wdev = wil->p2p_wdev;
Maya Erezd35c2b62016-08-18 16:52:14 +03001536 wil->p2p_wdev = NULL;
1537 wil->radio_wdev = wil_to_wdev(wil);
1538 mutex_unlock(&wil->p2p_wdev_mutex);
Lior David4332cac2016-03-01 19:18:13 +02001539 if (p2p_wdev) {
Lior David4332cac2016-03-01 19:18:13 +02001540 cfg80211_unregister_wdev(p2p_wdev);
1541 kfree(p2p_wdev);
1542 }
Lior David4332cac2016-03-01 19:18:13 +02001543}