blob: e758f430ed8203aad7fdcb44d38f1445c0a0ebc8 [file] [log] [blame]
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001/*
Dedy Lansky32a20d42015-01-25 10:52:44 +02002 * Copyright (c) 2012-2015 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 Kondratiev2be7d222012-12-20 13:13:19 -080017#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
29static 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
36static 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
52static const struct ieee80211_txrx_stypes
53wil_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
80static const u32 wil_cipher_suites[] = {
81 WLAN_CIPHER_SUITE_GCMP,
82};
83
84int 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 Kondratiev9eb82d42014-06-16 19:37:13 +0300107int wil_cid_fill_sinfo(struct wil6210_priv *wil, int cid,
108 struct station_info *sinfo)
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800109{
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800110 struct wmi_notify_req_cmd cmd = {
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +0200111 .cid = cid,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800112 .interval_usec = 0,
113 };
Vladimir Kondratievef28afd2014-02-27 16:20:48 +0200114 struct {
115 struct wil6210_mbox_hdr_wmi wmi;
116 struct wmi_notify_req_done_event evt;
117 } __packed reply;
Vladimir Kondratievc8b78b52014-02-27 16:20:49 +0200118 struct wil_net_stats *stats = &wil->sta[cid].stats;
Vladimir Kondratievef28afd2014-02-27 16:20:48 +0200119 int rc;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800120
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800121 rc = wmi_call(wil, WMI_NOTIFY_REQ_CMDID, &cmd, sizeof(cmd),
Vladimir Kondratievef28afd2014-02-27 16:20:48 +0200122 WMI_NOTIFY_REQ_DONE_EVENTID, &reply, sizeof(reply), 20);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800123 if (rc)
124 return rc;
125
Vladimir Kondratievc8b78b52014-02-27 16:20:49 +0200126 wil_dbg_wmi(wil, "Link status for CID %d: {\n"
127 " MCS %d TSF 0x%016llx\n"
Vladimir Kondratievb8b33a32014-02-27 16:20:52 +0200128 " BF status 0x%08x SNR 0x%08x SQI %d%%\n"
Vladimir Kondratievc8b78b52014-02-27 16:20:49 +0200129 " 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 Kondratievb8b33a32014-02-27 16:20:52 +0200134 reply.evt.sqi,
Vladimir Kondratievc8b78b52014-02-27 16:20:49 +0200135 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 Kondratiev2be7d222012-12-20 13:13:19 -0800143 sinfo->generation = wil->sinfo_gen;
144
Johannes Berg319090b2014-11-17 14:08:11 +0100145 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 Kondratievc8b78b52014-02-27 16:20:49 +0200153
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800154 sinfo->txrate.flags = RATE_INFO_FLAGS_MCS | RATE_INFO_FLAGS_60G;
Vladimir Kondratievef28afd2014-02-27 16:20:48 +0200155 sinfo->txrate.mcs = le16_to_cpu(reply.evt.bf_mcs);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800156 sinfo->rxrate.flags = RATE_INFO_FLAGS_MCS | RATE_INFO_FLAGS_60G;
Vladimir Kondratievc8b78b52014-02-27 16:20:49 +0200157 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 Kondratiev2be7d222012-12-20 13:13:19 -0800164
Vladimir Kondratiev9419b6a2014-12-23 09:47:14 +0200165 if (test_bit(wil_status_fwconnected, wil->status)) {
Johannes Berg319090b2014-11-17 14:08:11 +0100166 sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL);
Vladimir Kondratievb8b33a32014-02-27 16:20:52 +0200167 sinfo->signal = reply.evt.sqi;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800168 }
169
Vladimir Kondratievef28afd2014-02-27 16:20:48 +0200170 return rc;
171}
172
173static int wil_cfg80211_get_station(struct wiphy *wiphy,
174 struct net_device *ndev,
Johannes Berg3b3a0162014-05-19 17:19:31 +0200175 const u8 *mac, struct station_info *sinfo)
Vladimir Kondratievef28afd2014-02-27 16:20:48 +0200176{
177 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
178 int rc;
179
180 int cid = wil_find_cid(wil, mac);
181
Vladimir Kondratievfa4a18e2014-03-17 15:34:16 +0200182 wil_dbg_misc(wil, "%s(%pM) CID %d\n", __func__, mac, cid);
Vladimir Kondratievef28afd2014-02-27 16:20:48 +0200183 if (cid < 0)
Vladimir Kondratievc14c5d92014-03-02 11:20:51 +0200184 return cid;
Vladimir Kondratievef28afd2014-02-27 16:20:48 +0200185
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 */
194static 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
209static 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 Kondratievfa4a18e2014-03-17 15:34:16 +0200221 wil_dbg_misc(wil, "%s(%pM) CID %d\n", __func__, mac, cid);
Vladimir Kondratievef28afd2014-02-27 16:20:48 +0200222
223 rc = wil_cid_fill_sinfo(wil, cid, sinfo);
224
225 return rc;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800226}
227
228static 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
258static 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 Kondratieved6f9dc2014-03-17 15:34:19 +0200268 int rc;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800269
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 Kondratiev2be7d222012-12-20 13:13:19 -0800282 }
283
284 /* FW don't support scan after connection attempt */
Vladimir Kondratiev9419b6a2014-12-23 09:47:14 +0200285 if (test_bit(wil_status_dontscan, wil->status)) {
Vladimir Kondratieve83eb2f2014-03-17 15:34:07 +0200286 wil_err(wil, "Can't scan now\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800287 return -EBUSY;
288 }
289
Vladimir Kondratiev2a91d7d2014-06-16 19:37:11 +0300290 wil_dbg_misc(wil, "Start scan_request 0x%p\n", request);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800291 wil->scan_request = request;
Vladimir Kondratiev047e5d72014-05-27 14:45:48 +0300292 mod_timer(&wil->scan_timer, jiffies + WIL6210_SCAN_TO);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800293
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 Kondratiev8fe59622014-09-10 16:34:34 +0300299
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800300 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 Kondratiev77438822013-01-28 18:31:06 +0200308 wil_dbg_misc(wil, "Scan for ch %d : %d MHz\n", ch,
Vladimir Kondratiev2057ebb2013-01-28 18:30:58 +0200309 request->channels[i]->center_freq);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800310 }
311
Vladimir Kondratiev77c91292014-09-10 16:34:47 +0300312 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 Kondratieved6f9dc2014-03-17 15:34:19 +0200325 rc = wmi_send(wil, WMI_START_SCAN_CMDID, &cmd, sizeof(cmd.cmd) +
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800326 cmd.cmd.num_channels * sizeof(cmd.cmd.channel_list[0]));
Vladimir Kondratieved6f9dc2014-03-17 15:34:19 +0200327
Vladimir Kondratiev77c91292014-09-10 16:34:47 +0300328out:
Vladimir Kondratieva2142082014-08-06 10:31:57 +0300329 if (rc) {
330 del_timer_sync(&wil->scan_timer);
Vladimir Kondratieved6f9dc2014-03-17 15:34:19 +0200331 wil->scan_request = NULL;
Vladimir Kondratieva2142082014-08-06 10:31:57 +0300332 }
Vladimir Kondratieved6f9dc2014-03-17 15:34:19 +0200333
334 return rc;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800335}
336
Vladimir Kondratiev8ca26162014-09-10 16:34:32 +0300337static void wil_print_connect_params(struct wil6210_priv *wil,
338 struct cfg80211_connect_params *sme)
339{
340 wil_info(wil, "Connecting to:\n");
341 if (sme->channel) {
342 wil_info(wil, " Channel: %d freq %d\n",
343 sme->channel->hw_value, sme->channel->center_freq);
344 }
345 if (sme->bssid)
346 wil_info(wil, " BSSID: %pM\n", sme->bssid);
347 if (sme->ssid)
348 print_hex_dump(KERN_INFO, " SSID: ", DUMP_PREFIX_OFFSET,
349 16, 1, sme->ssid, sme->ssid_len, true);
350 wil_info(wil, " Privacy: %s\n", sme->privacy ? "secure" : "open");
351}
352
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800353static int wil_cfg80211_connect(struct wiphy *wiphy,
354 struct net_device *ndev,
355 struct cfg80211_connect_params *sme)
356{
357 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
358 struct cfg80211_bss *bss;
359 struct wmi_connect_cmd conn;
360 const u8 *ssid_eid;
361 const u8 *rsn_eid;
362 int ch;
363 int rc = 0;
364
Vladimir Kondratiev9419b6a2014-12-23 09:47:14 +0200365 if (test_bit(wil_status_fwconnecting, wil->status) ||
366 test_bit(wil_status_fwconnected, wil->status))
Vladimir Kondratiev4cd9e832014-03-17 15:34:20 +0200367 return -EALREADY;
368
Vladimir Kondratiev8ca26162014-09-10 16:34:32 +0300369 wil_print_connect_params(wil, sme);
370
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800371 bss = cfg80211_get_bss(wiphy, sme->channel, sme->bssid,
372 sme->ssid, sme->ssid_len,
373 WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
374 if (!bss) {
375 wil_err(wil, "Unable to find BSS\n");
376 return -ENOENT;
377 }
378
379 ssid_eid = ieee80211_bss_get_ie(bss, WLAN_EID_SSID);
380 if (!ssid_eid) {
381 wil_err(wil, "No SSID\n");
382 rc = -ENOENT;
383 goto out;
384 }
385
386 rsn_eid = sme->ie ?
387 cfg80211_find_ie(WLAN_EID_RSN, sme->ie, sme->ie_len) :
388 NULL;
389 if (rsn_eid) {
390 if (sme->ie_len > WMI_MAX_IE_LEN) {
391 rc = -ERANGE;
392 wil_err(wil, "IE too large (%td bytes)\n",
393 sme->ie_len);
394 goto out;
395 }
Vladimir Kondratievac4acdb2014-09-10 16:34:43 +0300396 /* For secure assoc, send WMI_DELETE_CIPHER_KEY_CMD */
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800397 rc = wmi_del_cipher_key(wil, 0, bss->bssid);
398 if (rc) {
399 wil_err(wil, "WMI_DELETE_CIPHER_KEY_CMD failed\n");
400 goto out;
401 }
Vladimir Kondratievac4acdb2014-09-10 16:34:43 +0300402 }
403
404 /* WMI_SET_APPIE_CMD. ie may contain rsn info as well as other info
405 * elements. Send it also in case it's empty, to erase previously set
406 * ies in FW.
407 */
408 rc = wmi_set_ie(wil, WMI_FRAME_ASSOC_REQ, sme->ie_len, sme->ie);
409 if (rc) {
410 wil_err(wil, "WMI_SET_APPIE_CMD failed\n");
411 goto out;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800412 }
413
414 /* WMI_CONNECT_CMD */
415 memset(&conn, 0, sizeof(conn));
Vladimir Kondratievacc97802013-03-13 14:12:47 +0200416 switch (bss->capability & WLAN_CAPABILITY_DMG_TYPE_MASK) {
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800417 case WLAN_CAPABILITY_DMG_TYPE_AP:
418 conn.network_type = WMI_NETTYPE_INFRA;
419 break;
420 case WLAN_CAPABILITY_DMG_TYPE_PBSS:
421 conn.network_type = WMI_NETTYPE_P2P;
422 break;
423 default:
424 wil_err(wil, "Unsupported BSS type, capability= 0x%04x\n",
425 bss->capability);
426 goto out;
427 }
428 if (rsn_eid) {
429 conn.dot11_auth_mode = WMI_AUTH11_SHARED;
430 conn.auth_mode = WMI_AUTH_WPA2_PSK;
431 conn.pairwise_crypto_type = WMI_CRYPT_AES_GCMP;
432 conn.pairwise_crypto_len = 16;
433 } else {
434 conn.dot11_auth_mode = WMI_AUTH11_OPEN;
435 conn.auth_mode = WMI_AUTH_NONE;
436 }
437
438 conn.ssid_len = min_t(u8, ssid_eid[1], 32);
439 memcpy(conn.ssid, ssid_eid+2, conn.ssid_len);
440
441 ch = bss->channel->hw_value;
442 if (ch == 0) {
443 wil_err(wil, "BSS at unknown frequency %dMhz\n",
444 bss->channel->center_freq);
445 rc = -EOPNOTSUPP;
446 goto out;
447 }
448 conn.channel = ch - 1;
449
Joe Perchesd458cdf2013-10-01 19:04:40 -0700450 memcpy(conn.bssid, bss->bssid, ETH_ALEN);
451 memcpy(conn.dst_mac, bss->bssid, ETH_ALEN);
Vladimir Kondratieve83eb2f2014-03-17 15:34:07 +0200452
Vladimir Kondratiev9419b6a2014-12-23 09:47:14 +0200453 set_bit(wil_status_fwconnecting, wil->status);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800454
455 rc = wmi_send(wil, WMI_CONNECT_CMDID, &conn, sizeof(conn));
456 if (rc == 0) {
Dedy Lanskyc5e96c92015-01-25 10:52:43 +0200457 netif_carrier_on(ndev);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800458 /* Connect can take lots of time */
459 mod_timer(&wil->connect_timer,
460 jiffies + msecs_to_jiffies(2000));
Vladimir Kondratievb338f742013-05-28 15:17:53 +0300461 } else {
Vladimir Kondratiev9419b6a2014-12-23 09:47:14 +0200462 clear_bit(wil_status_fwconnecting, wil->status);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800463 }
464
465 out:
Johannes Berg5b112d32013-02-01 01:49:58 +0100466 cfg80211_put_bss(wiphy, bss);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800467
468 return rc;
469}
470
471static int wil_cfg80211_disconnect(struct wiphy *wiphy,
472 struct net_device *ndev,
473 u16 reason_code)
474{
475 int rc;
476 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
477
478 rc = wmi_send(wil, WMI_DISCONNECT_CMDID, NULL, 0);
479
480 return rc;
481}
482
Vladimir Kondratiev0b39aaf2014-06-16 19:36:59 +0300483int wil_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
484 struct cfg80211_mgmt_tx_params *params,
485 u64 *cookie)
Vladimir Kondratiev1647f122014-02-27 16:20:40 +0200486{
487 const u8 *buf = params->buf;
488 size_t len = params->len;
489 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
490 int rc;
Vladimir Kondratiev304464f2014-06-16 19:37:00 +0300491 bool tx_status = false;
Vladimir Kondratiev1647f122014-02-27 16:20:40 +0200492 struct ieee80211_mgmt *mgmt_frame = (void *)buf;
493 struct wmi_sw_tx_req_cmd *cmd;
494 struct {
495 struct wil6210_mbox_hdr_wmi wmi;
496 struct wmi_sw_tx_complete_event evt;
497 } __packed evt;
498
499 cmd = kmalloc(sizeof(*cmd) + len, GFP_KERNEL);
Vladimir Kondratiev304464f2014-06-16 19:37:00 +0300500 if (!cmd) {
501 rc = -ENOMEM;
502 goto out;
503 }
Vladimir Kondratiev1647f122014-02-27 16:20:40 +0200504
505 memcpy(cmd->dst_mac, mgmt_frame->da, WMI_MAC_LEN);
506 cmd->len = cpu_to_le16(len);
507 memcpy(cmd->payload, buf, len);
508
509 rc = wmi_call(wil, WMI_SW_TX_REQ_CMDID, cmd, sizeof(*cmd) + len,
510 WMI_SW_TX_COMPLETE_EVENTID, &evt, sizeof(evt), 2000);
511 if (rc == 0)
Vladimir Kondratiev304464f2014-06-16 19:37:00 +0300512 tx_status = !evt.evt.status;
Vladimir Kondratiev1647f122014-02-27 16:20:40 +0200513
514 kfree(cmd);
Vladimir Kondratiev304464f2014-06-16 19:37:00 +0300515 out:
516 cfg80211_mgmt_tx_status(wdev, cookie ? *cookie : 0, buf, len,
517 tx_status, GFP_KERNEL);
Vladimir Kondratiev1647f122014-02-27 16:20:40 +0200518 return rc;
519}
520
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800521static int wil_cfg80211_set_channel(struct wiphy *wiphy,
522 struct cfg80211_chan_def *chandef)
523{
524 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
525 struct wireless_dev *wdev = wil->wdev;
526
527 wdev->preset_chandef = *chandef;
528
529 return 0;
530}
531
532static int wil_cfg80211_add_key(struct wiphy *wiphy,
533 struct net_device *ndev,
534 u8 key_index, bool pairwise,
535 const u8 *mac_addr,
536 struct key_params *params)
537{
538 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
539
540 /* group key is not used */
541 if (!pairwise)
542 return 0;
543
544 return wmi_add_cipher_key(wil, key_index, mac_addr,
545 params->key_len, params->key);
546}
547
548static int wil_cfg80211_del_key(struct wiphy *wiphy,
549 struct net_device *ndev,
550 u8 key_index, bool pairwise,
551 const u8 *mac_addr)
552{
553 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
554
555 /* group key is not used */
556 if (!pairwise)
557 return 0;
558
559 return wmi_del_cipher_key(wil, key_index, mac_addr);
560}
561
562/* Need to be present or wiphy_new() will WARN */
563static int wil_cfg80211_set_default_key(struct wiphy *wiphy,
564 struct net_device *ndev,
565 u8 key_index, bool unicast,
566 bool multicast)
567{
568 return 0;
569}
570
Vladimir Kondratiev1647f122014-02-27 16:20:40 +0200571static int wil_remain_on_channel(struct wiphy *wiphy,
572 struct wireless_dev *wdev,
573 struct ieee80211_channel *chan,
574 unsigned int duration,
575 u64 *cookie)
576{
577 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
578 int rc;
579
580 /* TODO: handle duration */
581 wil_info(wil, "%s(%d, %d ms)\n", __func__, chan->center_freq, duration);
582
583 rc = wmi_set_channel(wil, chan->hw_value);
584 if (rc)
585 return rc;
586
587 rc = wmi_rxon(wil, true);
588
589 return rc;
590}
591
592static int wil_cancel_remain_on_channel(struct wiphy *wiphy,
593 struct wireless_dev *wdev,
594 u64 cookie)
595{
596 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
597 int rc;
598
599 wil_info(wil, "%s()\n", __func__);
600
601 rc = wmi_rxon(wil, false);
602
603 return rc;
604}
605
Vladimir Kondratievca959772014-06-16 19:37:01 +0300606static void wil_print_bcon_data(struct cfg80211_beacon_data *b)
607{
608 print_hex_dump_bytes("head ", DUMP_PREFIX_OFFSET,
609 b->head, b->head_len);
610 print_hex_dump_bytes("tail ", DUMP_PREFIX_OFFSET,
611 b->tail, b->tail_len);
612 print_hex_dump_bytes("BCON IE ", DUMP_PREFIX_OFFSET,
613 b->beacon_ies, b->beacon_ies_len);
614 print_hex_dump_bytes("PROBE ", DUMP_PREFIX_OFFSET,
615 b->probe_resp, b->probe_resp_len);
616 print_hex_dump_bytes("PROBE IE ", DUMP_PREFIX_OFFSET,
617 b->proberesp_ies, b->proberesp_ies_len);
618 print_hex_dump_bytes("ASSOC IE ", DUMP_PREFIX_OFFSET,
619 b->assocresp_ies, b->assocresp_ies_len);
620}
621
622static void wil_print_crypto(struct wil6210_priv *wil,
623 struct cfg80211_crypto_settings *c)
624{
625 wil_dbg_misc(wil, "WPA versions: 0x%08x cipher group 0x%08x\n",
626 c->wpa_versions, c->cipher_group);
627 wil_dbg_misc(wil, "Pairwise ciphers [%d]\n", c->n_ciphers_pairwise);
628 wil_dbg_misc(wil, "AKM suites [%d]\n", c->n_akm_suites);
629 wil_dbg_misc(wil, "Control port : %d, eth_type 0x%04x no_encrypt %d\n",
630 c->control_port, be16_to_cpu(c->control_port_ethertype),
631 c->control_port_no_encrypt);
632}
633
Vladimir Kondratiev92646c92013-06-09 09:12:53 +0300634static int wil_fix_bcon(struct wil6210_priv *wil,
635 struct cfg80211_beacon_data *bcon)
636{
637 struct ieee80211_mgmt *f = (struct ieee80211_mgmt *)bcon->probe_resp;
638 size_t hlen = offsetof(struct ieee80211_mgmt, u.probe_resp.variable);
639 int rc = 0;
640
641 if (bcon->probe_resp_len <= hlen)
642 return 0;
643
644 if (!bcon->proberesp_ies) {
645 bcon->proberesp_ies = f->u.probe_resp.variable;
646 bcon->proberesp_ies_len = bcon->probe_resp_len - hlen;
647 rc = 1;
648 }
649 if (!bcon->assocresp_ies) {
650 bcon->assocresp_ies = f->u.probe_resp.variable;
651 bcon->assocresp_ies_len = bcon->probe_resp_len - hlen;
652 rc = 1;
653 }
654
655 return rc;
656}
657
Vladimir Kondratiev1bd922f2014-09-10 16:34:44 +0300658static int wil_cfg80211_change_beacon(struct wiphy *wiphy,
659 struct net_device *ndev,
660 struct cfg80211_beacon_data *bcon)
661{
662 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
663 int rc;
664
665 wil_dbg_misc(wil, "%s()\n", __func__);
666
667 if (wil_fix_bcon(wil, bcon)) {
668 wil_dbg_misc(wil, "Fixed bcon\n");
669 wil_print_bcon_data(bcon);
670 }
671
672 /* FW do not form regular beacon, so bcon IE's are not set
673 * For the DMG bcon, when it will be supported, bcon IE's will
674 * be reused; add something like:
675 * wmi_set_ie(wil, WMI_FRAME_BEACON, bcon->beacon_ies_len,
676 * bcon->beacon_ies);
677 */
678 rc = wmi_set_ie(wil, WMI_FRAME_PROBE_RESP,
679 bcon->proberesp_ies_len,
680 bcon->proberesp_ies);
681 if (rc) {
682 wil_err(wil, "set_ie(PROBE_RESP) failed\n");
683 return rc;
684 }
685
686 rc = wmi_set_ie(wil, WMI_FRAME_ASSOC_RESP,
687 bcon->assocresp_ies_len,
688 bcon->assocresp_ies);
689 if (rc) {
690 wil_err(wil, "set_ie(ASSOC_RESP) failed\n");
691 return rc;
692 }
693
694 return 0;
695}
696
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800697static int wil_cfg80211_start_ap(struct wiphy *wiphy,
698 struct net_device *ndev,
699 struct cfg80211_ap_settings *info)
700{
701 int rc = 0;
702 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
703 struct wireless_dev *wdev = ndev->ieee80211_ptr;
704 struct ieee80211_channel *channel = info->chandef.chan;
705 struct cfg80211_beacon_data *bcon = &info->beacon;
Vladimir Kondratievca959772014-06-16 19:37:01 +0300706 struct cfg80211_crypto_settings *crypto = &info->crypto;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800707 u8 wmi_nettype = wil_iftype_nl2wmi(wdev->iftype);
708
Vladimir Kondratievca959772014-06-16 19:37:01 +0300709 wil_dbg_misc(wil, "%s()\n", __func__);
710
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800711 if (!channel) {
712 wil_err(wil, "AP: No channel???\n");
713 return -EINVAL;
714 }
715
Vladimir Kondratiev77438822013-01-28 18:31:06 +0200716 wil_dbg_misc(wil, "AP on Channel %d %d MHz, %s\n", channel->hw_value,
Vladimir Kondratiev2057ebb2013-01-28 18:30:58 +0200717 channel->center_freq, info->privacy ? "secure" : "open");
Vladimir Kondratievca959772014-06-16 19:37:01 +0300718 wil_dbg_misc(wil, "Privacy: %d auth_type %d\n",
719 info->privacy, info->auth_type);
720 wil_dbg_misc(wil, "BI %d DTIM %d\n", info->beacon_interval,
721 info->dtim_period);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800722 print_hex_dump_bytes("SSID ", DUMP_PREFIX_OFFSET,
723 info->ssid, info->ssid_len);
Vladimir Kondratievca959772014-06-16 19:37:01 +0300724 wil_print_bcon_data(bcon);
725 wil_print_crypto(wil, crypto);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800726
Vladimir Kondratievca959772014-06-16 19:37:01 +0300727 if (wil_fix_bcon(wil, bcon)) {
Vladimir Kondratiev92646c92013-06-09 09:12:53 +0300728 wil_dbg_misc(wil, "Fixed bcon\n");
Vladimir Kondratievca959772014-06-16 19:37:01 +0300729 wil_print_bcon_data(bcon);
730 }
Vladimir Kondratiev92646c92013-06-09 09:12:53 +0300731
Vladimir Kondratievc33407a2014-10-01 15:05:24 +0300732 wil_set_recovery_state(wil, fw_recovery_idle);
733
Vladimir Kondratiev9c3bde52014-03-17 15:34:21 +0200734 mutex_lock(&wil->mutex);
735
Vladimir Kondratiev73d839a2014-09-10 16:34:50 +0300736 __wil_down(wil);
737 rc = __wil_up(wil);
Vladimir Kondratieve31b2562013-06-09 09:12:55 +0300738 if (rc)
Vladimir Kondratiev9c3bde52014-03-17 15:34:21 +0200739 goto out;
Vladimir Kondratieve31b2562013-06-09 09:12:55 +0300740
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800741 rc = wmi_set_ssid(wil, info->ssid_len, info->ssid);
742 if (rc)
Vladimir Kondratiev9c3bde52014-03-17 15:34:21 +0200743 goto out;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800744
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800745 /* IE's */
746 /* bcon 'head IE's are not relevant for 60g band */
Vladimir Kondratievb1defa42013-03-13 14:12:41 +0200747 /*
748 * FW do not form regular beacon, so bcon IE's are not set
749 * For the DMG bcon, when it will be supported, bcon IE's will
750 * be reused; add something like:
751 * wmi_set_ie(wil, WMI_FRAME_BEACON, bcon->beacon_ies_len,
752 * bcon->beacon_ies);
753 */
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800754 wmi_set_ie(wil, WMI_FRAME_PROBE_RESP, bcon->proberesp_ies_len,
755 bcon->proberesp_ies);
756 wmi_set_ie(wil, WMI_FRAME_ASSOC_RESP, bcon->assocresp_ies_len,
757 bcon->assocresp_ies);
758
759 wil->secure_pcp = info->privacy;
760
Dedy Lanskyc5e96c92015-01-25 10:52:43 +0200761 netif_carrier_on(ndev);
762
Vladimir Kondratievb8023172013-03-13 14:12:50 +0200763 rc = wmi_pcp_start(wil, info->beacon_interval, wmi_nettype,
764 channel->hw_value);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800765 if (rc)
Dedy Lanskyc5e96c92015-01-25 10:52:43 +0200766 netif_carrier_off(ndev);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800767
Vladimir Kondratiev9c3bde52014-03-17 15:34:21 +0200768out:
769 mutex_unlock(&wil->mutex);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800770 return rc;
771}
772
773static int wil_cfg80211_stop_ap(struct wiphy *wiphy,
774 struct net_device *ndev)
775{
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800776 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800777
Vladimir Kondratievca959772014-06-16 19:37:01 +0300778 wil_dbg_misc(wil, "%s()\n", __func__);
779
Dedy Lanskyc5e96c92015-01-25 10:52:43 +0200780 netif_carrier_off(ndev);
Vladimir Kondratievc33407a2014-10-01 15:05:24 +0300781 wil_set_recovery_state(wil, fw_recovery_idle);
782
Vladimir Kondratiev9c3bde52014-03-17 15:34:21 +0200783 mutex_lock(&wil->mutex);
784
Dedy Lansky32a20d42015-01-25 10:52:44 +0200785 wmi_pcp_stop(wil);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800786
Vladimir Kondratiev73d839a2014-09-10 16:34:50 +0300787 __wil_down(wil);
Dedy Lansky32a20d42015-01-25 10:52:44 +0200788 __wil_up(wil);
Vladimir Kondratiev73d839a2014-09-10 16:34:50 +0300789
Vladimir Kondratiev9c3bde52014-03-17 15:34:21 +0200790 mutex_unlock(&wil->mutex);
Vladimir Kondratiev73d839a2014-09-10 16:34:50 +0300791
Dedy Lansky32a20d42015-01-25 10:52:44 +0200792 /* some functions above might fail (e.g. __wil_up). Nevertheless, we
793 * return success because AP has stopped
794 */
795 return 0;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800796}
797
Vladimir Kondratiev4d55a0a2014-02-27 16:20:54 +0200798static int wil_cfg80211_del_station(struct wiphy *wiphy,
Jouni Malinen89c771e2014-10-10 20:52:40 +0300799 struct net_device *dev,
800 struct station_del_parameters *params)
Vladimir Kondratiev4d55a0a2014-02-27 16:20:54 +0200801{
802 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
Vladimir Kondratiev097638a2014-03-17 15:34:25 +0200803
804 mutex_lock(&wil->mutex);
Vladimir Kondratiev4821e6d2014-12-01 15:33:15 +0200805 wil6210_disconnect(wil, params->mac, params->reason_code, false);
Vladimir Kondratiev097638a2014-03-17 15:34:25 +0200806 mutex_unlock(&wil->mutex);
807
Vladimir Kondratiev4d55a0a2014-02-27 16:20:54 +0200808 return 0;
809}
810
Vladimir Kondratiev40822a92015-01-25 10:52:50 +0200811/* probe_client handling */
812static void wil_probe_client_handle(struct wil6210_priv *wil,
813 struct wil_probe_client_req *req)
814{
815 struct net_device *ndev = wil_to_ndev(wil);
816 struct wil_sta_info *sta = &wil->sta[req->cid];
817 /* assume STA is alive if it is still connected,
818 * else FW will disconnect it
819 */
820 bool alive = (sta->status == wil_sta_connected);
821
822 cfg80211_probe_status(ndev, sta->addr, req->cookie, alive, GFP_KERNEL);
823}
824
825static struct list_head *next_probe_client(struct wil6210_priv *wil)
826{
827 struct list_head *ret = NULL;
828
829 mutex_lock(&wil->probe_client_mutex);
830
831 if (!list_empty(&wil->probe_client_pending)) {
832 ret = wil->probe_client_pending.next;
833 list_del(ret);
834 }
835
836 mutex_unlock(&wil->probe_client_mutex);
837
838 return ret;
839}
840
841void wil_probe_client_worker(struct work_struct *work)
842{
843 struct wil6210_priv *wil = container_of(work, struct wil6210_priv,
844 probe_client_worker);
845 struct wil_probe_client_req *req;
846 struct list_head *lh;
847
848 while ((lh = next_probe_client(wil)) != NULL) {
849 req = list_entry(lh, struct wil_probe_client_req, list);
850
851 wil_probe_client_handle(wil, req);
852 kfree(req);
853 }
854}
855
856void wil_probe_client_flush(struct wil6210_priv *wil)
857{
858 struct wil_probe_client_req *req, *t;
859
860 wil_dbg_misc(wil, "%s()\n", __func__);
861
862 mutex_lock(&wil->probe_client_mutex);
863
864 list_for_each_entry_safe(req, t, &wil->probe_client_pending, list) {
865 list_del(&req->list);
866 kfree(req);
867 }
868
869 mutex_unlock(&wil->probe_client_mutex);
870}
871
872static int wil_cfg80211_probe_client(struct wiphy *wiphy,
873 struct net_device *dev,
874 const u8 *peer, u64 *cookie)
875{
876 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
877 struct wil_probe_client_req *req;
878 int cid = wil_find_cid(wil, peer);
879
880 wil_dbg_misc(wil, "%s(%pM => CID %d)\n", __func__, peer, cid);
881
882 if (cid < 0)
883 return -ENOLINK;
884
885 req = kzalloc(sizeof(*req), GFP_KERNEL);
886 if (!req)
887 return -ENOMEM;
888
889 req->cid = cid;
890 req->cookie = cid;
891
892 mutex_lock(&wil->probe_client_mutex);
893 list_add_tail(&req->list, &wil->probe_client_pending);
894 mutex_unlock(&wil->probe_client_mutex);
895
896 *cookie = req->cookie;
897 queue_work(wil->wq_service, &wil->probe_client_worker);
898 return 0;
899}
900
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800901static struct cfg80211_ops wil_cfg80211_ops = {
902 .scan = wil_cfg80211_scan,
903 .connect = wil_cfg80211_connect,
904 .disconnect = wil_cfg80211_disconnect,
905 .change_virtual_intf = wil_cfg80211_change_iface,
906 .get_station = wil_cfg80211_get_station,
Vladimir Kondratievef28afd2014-02-27 16:20:48 +0200907 .dump_station = wil_cfg80211_dump_station,
Vladimir Kondratiev1647f122014-02-27 16:20:40 +0200908 .remain_on_channel = wil_remain_on_channel,
909 .cancel_remain_on_channel = wil_cancel_remain_on_channel,
910 .mgmt_tx = wil_cfg80211_mgmt_tx,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800911 .set_monitor_channel = wil_cfg80211_set_channel,
912 .add_key = wil_cfg80211_add_key,
913 .del_key = wil_cfg80211_del_key,
914 .set_default_key = wil_cfg80211_set_default_key,
915 /* AP mode */
Vladimir Kondratiev1bd922f2014-09-10 16:34:44 +0300916 .change_beacon = wil_cfg80211_change_beacon,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800917 .start_ap = wil_cfg80211_start_ap,
918 .stop_ap = wil_cfg80211_stop_ap,
Vladimir Kondratiev4d55a0a2014-02-27 16:20:54 +0200919 .del_station = wil_cfg80211_del_station,
Vladimir Kondratiev40822a92015-01-25 10:52:50 +0200920 .probe_client = wil_cfg80211_probe_client,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800921};
922
923static void wil_wiphy_init(struct wiphy *wiphy)
924{
925 /* TODO: set real value */
926 wiphy->max_scan_ssids = 10;
Vladimir Kondratiev77c91292014-09-10 16:34:47 +0300927 wiphy->max_scan_ie_len = WMI_MAX_IE_LEN;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800928 wiphy->max_num_pmkids = 0 /* TODO: */;
929 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
930 BIT(NL80211_IFTYPE_AP) |
931 BIT(NL80211_IFTYPE_MONITOR);
932 /* TODO: enable P2P when integrated with supplicant:
933 * BIT(NL80211_IFTYPE_P2P_CLIENT) | BIT(NL80211_IFTYPE_P2P_GO)
934 */
935 wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME |
936 WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
Vladimir Kondratiev9cf10d62014-09-10 16:34:36 +0300937 dev_dbg(wiphy_dev(wiphy), "%s : flags = 0x%08x\n",
938 __func__, wiphy->flags);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800939 wiphy->probe_resp_offload =
940 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
941 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
942 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
943
944 wiphy->bands[IEEE80211_BAND_60GHZ] = &wil_band_60ghz;
945
946 /* TODO: figure this out */
Vladimir Kondratievb8b33a32014-02-27 16:20:52 +0200947 wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800948
949 wiphy->cipher_suites = wil_cipher_suites;
950 wiphy->n_cipher_suites = ARRAY_SIZE(wil_cipher_suites);
951 wiphy->mgmt_stypes = wil_mgmt_stypes;
Vladimir Kondratiev713c8a22015-01-25 10:52:49 +0200952 wiphy->features |= NL80211_FEATURE_SK_TX_STATUS;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800953}
954
955struct wireless_dev *wil_cfg80211_init(struct device *dev)
956{
957 int rc = 0;
958 struct wireless_dev *wdev;
959
Vladimir Kondratiev9cf10d62014-09-10 16:34:36 +0300960 dev_dbg(dev, "%s()\n", __func__);
961
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300962 wdev = kzalloc(sizeof(*wdev), GFP_KERNEL);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800963 if (!wdev)
964 return ERR_PTR(-ENOMEM);
965
966 wdev->wiphy = wiphy_new(&wil_cfg80211_ops,
967 sizeof(struct wil6210_priv));
968 if (!wdev->wiphy) {
969 rc = -ENOMEM;
970 goto out;
971 }
972
973 set_wiphy_dev(wdev->wiphy, dev);
974 wil_wiphy_init(wdev->wiphy);
975
976 rc = wiphy_register(wdev->wiphy);
977 if (rc < 0)
978 goto out_failed_reg;
979
980 return wdev;
981
982out_failed_reg:
983 wiphy_free(wdev->wiphy);
984out:
985 kfree(wdev);
986
987 return ERR_PTR(rc);
988}
989
990void wil_wdev_free(struct wil6210_priv *wil)
991{
992 struct wireless_dev *wdev = wil_to_wdev(wil);
993
Vladimir Kondratiev9cf10d62014-09-10 16:34:36 +0300994 dev_dbg(wil_to_dev(wil), "%s()\n", __func__);
995
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800996 if (!wdev)
997 return;
998
999 wiphy_unregister(wdev->wiphy);
1000 wiphy_free(wdev->wiphy);
1001 kfree(wdev);
1002}