blob: b1bc00724cd23bff62fa7312c4aee9e4b4af0c58 [file] [log] [blame]
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001/*
2 * Copyright (c) 2012 Qualcomm Atheros, Inc.
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
Vladimir 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 Kondratievef28afd2014-02-27 16:20:48 +0200107static int 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
Vladimir Kondratievc8b78b52014-02-27 16:20:49 +0200145 sinfo->filled = STATION_INFO_RX_BYTES |
146 STATION_INFO_TX_BYTES |
147 STATION_INFO_RX_PACKETS |
148 STATION_INFO_TX_PACKETS |
149 STATION_INFO_RX_BITRATE |
150 STATION_INFO_TX_BITRATE |
151 STATION_INFO_RX_DROP_MISC |
152 STATION_INFO_TX_FAILED;
153
Vladimir 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
165 if (test_bit(wil_status_fwconnected, &wil->status)) {
166 sinfo->filled |= STATION_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,
175 u8 *mac, struct station_info *sinfo)
176{
177 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
178 int rc;
179
180 int cid = wil_find_cid(wil, mac);
181
182 wil_info(wil, "%s(%pM) CID %d\n", __func__, mac, cid);
183 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);
221 wil_info(wil, "%s(%pM) CID %d\n", __func__, mac, cid);
222
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;
268
269 if (wil->scan_request) {
270 wil_err(wil, "Already scanning\n");
271 return -EAGAIN;
272 }
273
274 /* check we are client side */
275 switch (wdev->iftype) {
276 case NL80211_IFTYPE_STATION:
277 case NL80211_IFTYPE_P2P_CLIENT:
278 break;
279 default:
280 return -EOPNOTSUPP;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800281 }
282
283 /* FW don't support scan after connection attempt */
284 if (test_bit(wil_status_dontscan, &wil->status)) {
Vladimir Kondratieve83eb2f2014-03-17 15:34:07 +0200285 wil_err(wil, "Can't scan now\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800286 return -EBUSY;
287 }
288
289 wil->scan_request = request;
290
291 memset(&cmd, 0, sizeof(cmd));
292 cmd.cmd.num_channels = 0;
293 n = min(request->n_channels, 4U);
294 for (i = 0; i < n; i++) {
295 int ch = request->channels[i]->hw_value;
296 if (ch == 0) {
297 wil_err(wil,
298 "Scan requested for unknown frequency %dMhz\n",
299 request->channels[i]->center_freq);
300 continue;
301 }
302 /* 0-based channel indexes */
303 cmd.cmd.channel_list[cmd.cmd.num_channels++].channel = ch - 1;
Vladimir Kondratiev77438822013-01-28 18:31:06 +0200304 wil_dbg_misc(wil, "Scan for ch %d : %d MHz\n", ch,
Vladimir Kondratiev2057ebb2013-01-28 18:30:58 +0200305 request->channels[i]->center_freq);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800306 }
307
308 return wmi_send(wil, WMI_START_SCAN_CMDID, &cmd, sizeof(cmd.cmd) +
309 cmd.cmd.num_channels * sizeof(cmd.cmd.channel_list[0]));
310}
311
312static int wil_cfg80211_connect(struct wiphy *wiphy,
313 struct net_device *ndev,
314 struct cfg80211_connect_params *sme)
315{
316 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
317 struct cfg80211_bss *bss;
318 struct wmi_connect_cmd conn;
319 const u8 *ssid_eid;
320 const u8 *rsn_eid;
321 int ch;
322 int rc = 0;
323
324 bss = cfg80211_get_bss(wiphy, sme->channel, sme->bssid,
325 sme->ssid, sme->ssid_len,
326 WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
327 if (!bss) {
328 wil_err(wil, "Unable to find BSS\n");
329 return -ENOENT;
330 }
331
332 ssid_eid = ieee80211_bss_get_ie(bss, WLAN_EID_SSID);
333 if (!ssid_eid) {
334 wil_err(wil, "No SSID\n");
335 rc = -ENOENT;
336 goto out;
337 }
338
339 rsn_eid = sme->ie ?
340 cfg80211_find_ie(WLAN_EID_RSN, sme->ie, sme->ie_len) :
341 NULL;
342 if (rsn_eid) {
343 if (sme->ie_len > WMI_MAX_IE_LEN) {
344 rc = -ERANGE;
345 wil_err(wil, "IE too large (%td bytes)\n",
346 sme->ie_len);
347 goto out;
348 }
349 /*
350 * For secure assoc, send:
351 * (1) WMI_DELETE_CIPHER_KEY_CMD
352 * (2) WMI_SET_APPIE_CMD
353 */
354 rc = wmi_del_cipher_key(wil, 0, bss->bssid);
355 if (rc) {
356 wil_err(wil, "WMI_DELETE_CIPHER_KEY_CMD failed\n");
357 goto out;
358 }
359 /* WMI_SET_APPIE_CMD */
360 rc = wmi_set_ie(wil, WMI_FRAME_ASSOC_REQ, sme->ie_len, sme->ie);
361 if (rc) {
362 wil_err(wil, "WMI_SET_APPIE_CMD failed\n");
363 goto out;
364 }
365 }
366
367 /* WMI_CONNECT_CMD */
368 memset(&conn, 0, sizeof(conn));
Vladimir Kondratievacc97802013-03-13 14:12:47 +0200369 switch (bss->capability & WLAN_CAPABILITY_DMG_TYPE_MASK) {
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800370 case WLAN_CAPABILITY_DMG_TYPE_AP:
371 conn.network_type = WMI_NETTYPE_INFRA;
372 break;
373 case WLAN_CAPABILITY_DMG_TYPE_PBSS:
374 conn.network_type = WMI_NETTYPE_P2P;
375 break;
376 default:
377 wil_err(wil, "Unsupported BSS type, capability= 0x%04x\n",
378 bss->capability);
379 goto out;
380 }
381 if (rsn_eid) {
382 conn.dot11_auth_mode = WMI_AUTH11_SHARED;
383 conn.auth_mode = WMI_AUTH_WPA2_PSK;
384 conn.pairwise_crypto_type = WMI_CRYPT_AES_GCMP;
385 conn.pairwise_crypto_len = 16;
386 } else {
387 conn.dot11_auth_mode = WMI_AUTH11_OPEN;
388 conn.auth_mode = WMI_AUTH_NONE;
389 }
390
391 conn.ssid_len = min_t(u8, ssid_eid[1], 32);
392 memcpy(conn.ssid, ssid_eid+2, conn.ssid_len);
393
394 ch = bss->channel->hw_value;
395 if (ch == 0) {
396 wil_err(wil, "BSS at unknown frequency %dMhz\n",
397 bss->channel->center_freq);
398 rc = -EOPNOTSUPP;
399 goto out;
400 }
401 conn.channel = ch - 1;
402
Joe Perchesd458cdf2013-10-01 19:04:40 -0700403 memcpy(conn.bssid, bss->bssid, ETH_ALEN);
404 memcpy(conn.dst_mac, bss->bssid, ETH_ALEN);
Vladimir Kondratieve83eb2f2014-03-17 15:34:07 +0200405
Vladimir Kondratievb338f742013-05-28 15:17:53 +0300406 set_bit(wil_status_fwconnecting, &wil->status);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800407
408 rc = wmi_send(wil, WMI_CONNECT_CMDID, &conn, sizeof(conn));
409 if (rc == 0) {
410 /* Connect can take lots of time */
411 mod_timer(&wil->connect_timer,
412 jiffies + msecs_to_jiffies(2000));
Vladimir Kondratievb338f742013-05-28 15:17:53 +0300413 } else {
Vladimir Kondratievb338f742013-05-28 15:17:53 +0300414 clear_bit(wil_status_fwconnecting, &wil->status);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800415 }
416
417 out:
Johannes Berg5b112d32013-02-01 01:49:58 +0100418 cfg80211_put_bss(wiphy, bss);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800419
420 return rc;
421}
422
423static int wil_cfg80211_disconnect(struct wiphy *wiphy,
424 struct net_device *ndev,
425 u16 reason_code)
426{
427 int rc;
428 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
429
430 rc = wmi_send(wil, WMI_DISCONNECT_CMDID, NULL, 0);
431
432 return rc;
433}
434
Vladimir Kondratiev1647f122014-02-27 16:20:40 +0200435static int wil_cfg80211_mgmt_tx(struct wiphy *wiphy,
436 struct wireless_dev *wdev,
437 struct cfg80211_mgmt_tx_params *params,
438 u64 *cookie)
439{
440 const u8 *buf = params->buf;
441 size_t len = params->len;
442 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
443 int rc;
444 struct ieee80211_mgmt *mgmt_frame = (void *)buf;
445 struct wmi_sw_tx_req_cmd *cmd;
446 struct {
447 struct wil6210_mbox_hdr_wmi wmi;
448 struct wmi_sw_tx_complete_event evt;
449 } __packed evt;
450
451 cmd = kmalloc(sizeof(*cmd) + len, GFP_KERNEL);
452 if (!cmd)
453 return -ENOMEM;
454
455 memcpy(cmd->dst_mac, mgmt_frame->da, WMI_MAC_LEN);
456 cmd->len = cpu_to_le16(len);
457 memcpy(cmd->payload, buf, len);
458
459 rc = wmi_call(wil, WMI_SW_TX_REQ_CMDID, cmd, sizeof(*cmd) + len,
460 WMI_SW_TX_COMPLETE_EVENTID, &evt, sizeof(evt), 2000);
461 if (rc == 0)
462 rc = evt.evt.status;
463
464 kfree(cmd);
465
466 return rc;
467}
468
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800469static int wil_cfg80211_set_channel(struct wiphy *wiphy,
470 struct cfg80211_chan_def *chandef)
471{
472 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
473 struct wireless_dev *wdev = wil->wdev;
474
475 wdev->preset_chandef = *chandef;
476
477 return 0;
478}
479
480static int wil_cfg80211_add_key(struct wiphy *wiphy,
481 struct net_device *ndev,
482 u8 key_index, bool pairwise,
483 const u8 *mac_addr,
484 struct key_params *params)
485{
486 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
487
488 /* group key is not used */
489 if (!pairwise)
490 return 0;
491
492 return wmi_add_cipher_key(wil, key_index, mac_addr,
493 params->key_len, params->key);
494}
495
496static int wil_cfg80211_del_key(struct wiphy *wiphy,
497 struct net_device *ndev,
498 u8 key_index, bool pairwise,
499 const u8 *mac_addr)
500{
501 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
502
503 /* group key is not used */
504 if (!pairwise)
505 return 0;
506
507 return wmi_del_cipher_key(wil, key_index, mac_addr);
508}
509
510/* Need to be present or wiphy_new() will WARN */
511static int wil_cfg80211_set_default_key(struct wiphy *wiphy,
512 struct net_device *ndev,
513 u8 key_index, bool unicast,
514 bool multicast)
515{
516 return 0;
517}
518
Vladimir Kondratiev1647f122014-02-27 16:20:40 +0200519static int wil_remain_on_channel(struct wiphy *wiphy,
520 struct wireless_dev *wdev,
521 struct ieee80211_channel *chan,
522 unsigned int duration,
523 u64 *cookie)
524{
525 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
526 int rc;
527
528 /* TODO: handle duration */
529 wil_info(wil, "%s(%d, %d ms)\n", __func__, chan->center_freq, duration);
530
531 rc = wmi_set_channel(wil, chan->hw_value);
532 if (rc)
533 return rc;
534
535 rc = wmi_rxon(wil, true);
536
537 return rc;
538}
539
540static int wil_cancel_remain_on_channel(struct wiphy *wiphy,
541 struct wireless_dev *wdev,
542 u64 cookie)
543{
544 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
545 int rc;
546
547 wil_info(wil, "%s()\n", __func__);
548
549 rc = wmi_rxon(wil, false);
550
551 return rc;
552}
553
Vladimir Kondratiev92646c92013-06-09 09:12:53 +0300554static int wil_fix_bcon(struct wil6210_priv *wil,
555 struct cfg80211_beacon_data *bcon)
556{
557 struct ieee80211_mgmt *f = (struct ieee80211_mgmt *)bcon->probe_resp;
558 size_t hlen = offsetof(struct ieee80211_mgmt, u.probe_resp.variable);
559 int rc = 0;
560
561 if (bcon->probe_resp_len <= hlen)
562 return 0;
563
564 if (!bcon->proberesp_ies) {
565 bcon->proberesp_ies = f->u.probe_resp.variable;
566 bcon->proberesp_ies_len = bcon->probe_resp_len - hlen;
567 rc = 1;
568 }
569 if (!bcon->assocresp_ies) {
570 bcon->assocresp_ies = f->u.probe_resp.variable;
571 bcon->assocresp_ies_len = bcon->probe_resp_len - hlen;
572 rc = 1;
573 }
574
575 return rc;
576}
577
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800578static int wil_cfg80211_start_ap(struct wiphy *wiphy,
579 struct net_device *ndev,
580 struct cfg80211_ap_settings *info)
581{
582 int rc = 0;
583 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
584 struct wireless_dev *wdev = ndev->ieee80211_ptr;
585 struct ieee80211_channel *channel = info->chandef.chan;
586 struct cfg80211_beacon_data *bcon = &info->beacon;
587 u8 wmi_nettype = wil_iftype_nl2wmi(wdev->iftype);
588
589 if (!channel) {
590 wil_err(wil, "AP: No channel???\n");
591 return -EINVAL;
592 }
593
Vladimir Kondratiev77438822013-01-28 18:31:06 +0200594 wil_dbg_misc(wil, "AP on Channel %d %d MHz, %s\n", channel->hw_value,
Vladimir Kondratiev2057ebb2013-01-28 18:30:58 +0200595 channel->center_freq, info->privacy ? "secure" : "open");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800596 print_hex_dump_bytes("SSID ", DUMP_PREFIX_OFFSET,
597 info->ssid, info->ssid_len);
598
Vladimir Kondratiev92646c92013-06-09 09:12:53 +0300599 if (wil_fix_bcon(wil, bcon))
600 wil_dbg_misc(wil, "Fixed bcon\n");
601
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800602 rc = wil_reset(wil);
603 if (rc)
604 return rc;
605
Vladimir Kondratieve31b2562013-06-09 09:12:55 +0300606 /* Rx VRING. */
607 rc = wil_rx_init(wil);
608 if (rc)
609 return rc;
610
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800611 rc = wmi_set_ssid(wil, info->ssid_len, info->ssid);
612 if (rc)
613 return rc;
614
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800615 /* MAC address - pre-requisite for other commands */
616 wmi_set_mac_address(wil, ndev->dev_addr);
617
618 /* IE's */
619 /* bcon 'head IE's are not relevant for 60g band */
Vladimir Kondratievb1defa42013-03-13 14:12:41 +0200620 /*
621 * FW do not form regular beacon, so bcon IE's are not set
622 * For the DMG bcon, when it will be supported, bcon IE's will
623 * be reused; add something like:
624 * wmi_set_ie(wil, WMI_FRAME_BEACON, bcon->beacon_ies_len,
625 * bcon->beacon_ies);
626 */
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800627 wmi_set_ie(wil, WMI_FRAME_PROBE_RESP, bcon->proberesp_ies_len,
628 bcon->proberesp_ies);
629 wmi_set_ie(wil, WMI_FRAME_ASSOC_RESP, bcon->assocresp_ies_len,
630 bcon->assocresp_ies);
631
632 wil->secure_pcp = info->privacy;
633
Vladimir Kondratievb8023172013-03-13 14:12:50 +0200634 rc = wmi_pcp_start(wil, info->beacon_interval, wmi_nettype,
635 channel->hw_value);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800636 if (rc)
637 return rc;
638
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800639
640 netif_carrier_on(ndev);
641
642 return rc;
643}
644
645static int wil_cfg80211_stop_ap(struct wiphy *wiphy,
646 struct net_device *ndev)
647{
648 int rc = 0;
649 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800650
Vladimir Kondratievb8023172013-03-13 14:12:50 +0200651 rc = wmi_pcp_stop(wil);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800652
653 return rc;
654}
655
Vladimir Kondratiev4d55a0a2014-02-27 16:20:54 +0200656static int wil_cfg80211_del_station(struct wiphy *wiphy,
657 struct net_device *dev, u8 *mac)
658{
659 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
660 wil6210_disconnect(wil, mac);
661 return 0;
662}
663
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800664static struct cfg80211_ops wil_cfg80211_ops = {
665 .scan = wil_cfg80211_scan,
666 .connect = wil_cfg80211_connect,
667 .disconnect = wil_cfg80211_disconnect,
668 .change_virtual_intf = wil_cfg80211_change_iface,
669 .get_station = wil_cfg80211_get_station,
Vladimir Kondratievef28afd2014-02-27 16:20:48 +0200670 .dump_station = wil_cfg80211_dump_station,
Vladimir Kondratiev1647f122014-02-27 16:20:40 +0200671 .remain_on_channel = wil_remain_on_channel,
672 .cancel_remain_on_channel = wil_cancel_remain_on_channel,
673 .mgmt_tx = wil_cfg80211_mgmt_tx,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800674 .set_monitor_channel = wil_cfg80211_set_channel,
675 .add_key = wil_cfg80211_add_key,
676 .del_key = wil_cfg80211_del_key,
677 .set_default_key = wil_cfg80211_set_default_key,
678 /* AP mode */
679 .start_ap = wil_cfg80211_start_ap,
680 .stop_ap = wil_cfg80211_stop_ap,
Vladimir Kondratiev4d55a0a2014-02-27 16:20:54 +0200681 .del_station = wil_cfg80211_del_station,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800682};
683
684static void wil_wiphy_init(struct wiphy *wiphy)
685{
686 /* TODO: set real value */
687 wiphy->max_scan_ssids = 10;
688 wiphy->max_num_pmkids = 0 /* TODO: */;
689 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
690 BIT(NL80211_IFTYPE_AP) |
691 BIT(NL80211_IFTYPE_MONITOR);
692 /* TODO: enable P2P when integrated with supplicant:
693 * BIT(NL80211_IFTYPE_P2P_CLIENT) | BIT(NL80211_IFTYPE_P2P_GO)
694 */
695 wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME |
696 WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
697 dev_warn(wiphy_dev(wiphy), "%s : flags = 0x%08x\n",
698 __func__, wiphy->flags);
699 wiphy->probe_resp_offload =
700 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
701 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
702 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
703
704 wiphy->bands[IEEE80211_BAND_60GHZ] = &wil_band_60ghz;
705
706 /* TODO: figure this out */
Vladimir Kondratievb8b33a32014-02-27 16:20:52 +0200707 wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800708
709 wiphy->cipher_suites = wil_cipher_suites;
710 wiphy->n_cipher_suites = ARRAY_SIZE(wil_cipher_suites);
711 wiphy->mgmt_stypes = wil_mgmt_stypes;
712}
713
714struct wireless_dev *wil_cfg80211_init(struct device *dev)
715{
716 int rc = 0;
717 struct wireless_dev *wdev;
718
719 wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
720 if (!wdev)
721 return ERR_PTR(-ENOMEM);
722
723 wdev->wiphy = wiphy_new(&wil_cfg80211_ops,
724 sizeof(struct wil6210_priv));
725 if (!wdev->wiphy) {
726 rc = -ENOMEM;
727 goto out;
728 }
729
730 set_wiphy_dev(wdev->wiphy, dev);
731 wil_wiphy_init(wdev->wiphy);
732
733 rc = wiphy_register(wdev->wiphy);
734 if (rc < 0)
735 goto out_failed_reg;
736
737 return wdev;
738
739out_failed_reg:
740 wiphy_free(wdev->wiphy);
741out:
742 kfree(wdev);
743
744 return ERR_PTR(rc);
745}
746
747void wil_wdev_free(struct wil6210_priv *wil)
748{
749 struct wireless_dev *wdev = wil_to_wdev(wil);
750
751 if (!wdev)
752 return;
753
754 wiphy_unregister(wdev->wiphy);
755 wiphy_free(wdev->wiphy);
756 kfree(wdev);
757}