wil6210: wait for disconnect completion
[deliverable/linux.git] / drivers / net / wireless / ath / wil6210 / cfg80211.c
CommitLineData
2be7d22f 1/*
c5a157e4 2 * Copyright (c) 2012-2016 Qualcomm Atheros, Inc.
2be7d22f
VK
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
a82553bb 17#include <linux/etherdevice.h>
2be7d22f
VK
18#include "wil6210.h"
19#include "wmi.h"
20
21#define CHAN60G(_channel, _flags) { \
22 .band = IEEE80211_BAND_60GHZ, \
23 .center_freq = 56160 + (2160 * (_channel)), \
24 .hw_value = (_channel), \
25 .flags = (_flags), \
26 .max_antenna_gain = 0, \
27 .max_power = 40, \
28}
29
30static struct ieee80211_channel wil_60ghz_channels[] = {
31 CHAN60G(1, 0),
32 CHAN60G(2, 0),
33 CHAN60G(3, 0),
34/* channel 4 not supported yet */
35};
36
37static struct ieee80211_supported_band wil_band_60ghz = {
38 .channels = wil_60ghz_channels,
39 .n_channels = ARRAY_SIZE(wil_60ghz_channels),
40 .ht_cap = {
41 .ht_supported = true,
42 .cap = 0, /* TODO */
43 .ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K, /* TODO */
44 .ampdu_density = IEEE80211_HT_MPDU_DENSITY_8, /* TODO */
45 .mcs = {
46 /* MCS 1..12 - SC PHY */
47 .rx_mask = {0xfe, 0x1f}, /* 1..12 */
48 .tx_params = IEEE80211_HT_MCS_TX_DEFINED, /* TODO */
49 },
50 },
51};
52
53static const struct ieee80211_txrx_stypes
54wil_mgmt_stypes[NUM_NL80211_IFTYPES] = {
55 [NL80211_IFTYPE_STATION] = {
56 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
57 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
58 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
59 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
60 },
61 [NL80211_IFTYPE_AP] = {
62 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
63 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
64 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
65 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
66 },
67 [NL80211_IFTYPE_P2P_CLIENT] = {
68 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
69 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
70 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
71 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
72 },
73 [NL80211_IFTYPE_P2P_GO] = {
74 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
75 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
76 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
77 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
78 },
79};
80
81static const u32 wil_cipher_suites[] = {
82 WLAN_CIPHER_SUITE_GCMP,
83};
84
85int wil_iftype_nl2wmi(enum nl80211_iftype type)
86{
87 static const struct {
88 enum nl80211_iftype nl;
89 enum wmi_network_type wmi;
90 } __nl2wmi[] = {
91 {NL80211_IFTYPE_ADHOC, WMI_NETTYPE_ADHOC},
92 {NL80211_IFTYPE_STATION, WMI_NETTYPE_INFRA},
93 {NL80211_IFTYPE_AP, WMI_NETTYPE_AP},
94 {NL80211_IFTYPE_P2P_CLIENT, WMI_NETTYPE_P2P},
95 {NL80211_IFTYPE_P2P_GO, WMI_NETTYPE_P2P},
96 {NL80211_IFTYPE_MONITOR, WMI_NETTYPE_ADHOC}, /* FIXME */
97 };
98 uint i;
99
100 for (i = 0; i < ARRAY_SIZE(__nl2wmi); i++) {
101 if (__nl2wmi[i].nl == type)
102 return __nl2wmi[i].wmi;
103 }
104
105 return -EOPNOTSUPP;
106}
107
9eb82d43
VK
108int wil_cid_fill_sinfo(struct wil6210_priv *wil, int cid,
109 struct station_info *sinfo)
2be7d22f 110{
2be7d22f 111 struct wmi_notify_req_cmd cmd = {
3df2cd36 112 .cid = cid,
2be7d22f
VK
113 .interval_usec = 0,
114 };
ef28afdb
VK
115 struct {
116 struct wil6210_mbox_hdr_wmi wmi;
117 struct wmi_notify_req_done_event evt;
118 } __packed reply;
c8b78b5f 119 struct wil_net_stats *stats = &wil->sta[cid].stats;
ef28afdb 120 int rc;
2be7d22f 121
2be7d22f 122 rc = wmi_call(wil, WMI_NOTIFY_REQ_CMDID, &cmd, sizeof(cmd),
ef28afdb 123 WMI_NOTIFY_REQ_DONE_EVENTID, &reply, sizeof(reply), 20);
2be7d22f
VK
124 if (rc)
125 return rc;
126
c8b78b5f
VK
127 wil_dbg_wmi(wil, "Link status for CID %d: {\n"
128 " MCS %d TSF 0x%016llx\n"
b8b33a3a 129 " BF status 0x%08x SNR 0x%08x SQI %d%%\n"
c8b78b5f
VK
130 " Tx Tpt %d goodput %d Rx goodput %d\n"
131 " Sectors(rx:tx) my %d:%d peer %d:%d\n""}\n",
132 cid, le16_to_cpu(reply.evt.bf_mcs),
133 le64_to_cpu(reply.evt.tsf), reply.evt.status,
134 le32_to_cpu(reply.evt.snr_val),
b8b33a3a 135 reply.evt.sqi,
c8b78b5f
VK
136 le32_to_cpu(reply.evt.tx_tpt),
137 le32_to_cpu(reply.evt.tx_goodput),
138 le32_to_cpu(reply.evt.rx_goodput),
139 le16_to_cpu(reply.evt.my_rx_sector),
140 le16_to_cpu(reply.evt.my_tx_sector),
141 le16_to_cpu(reply.evt.other_rx_sector),
142 le16_to_cpu(reply.evt.other_tx_sector));
143
2be7d22f
VK
144 sinfo->generation = wil->sinfo_gen;
145
319090bf
JB
146 sinfo->filled = BIT(NL80211_STA_INFO_RX_BYTES) |
147 BIT(NL80211_STA_INFO_TX_BYTES) |
148 BIT(NL80211_STA_INFO_RX_PACKETS) |
149 BIT(NL80211_STA_INFO_TX_PACKETS) |
150 BIT(NL80211_STA_INFO_RX_BITRATE) |
151 BIT(NL80211_STA_INFO_TX_BITRATE) |
152 BIT(NL80211_STA_INFO_RX_DROP_MISC) |
153 BIT(NL80211_STA_INFO_TX_FAILED);
c8b78b5f 154
2be7d22f 155 sinfo->txrate.flags = RATE_INFO_FLAGS_MCS | RATE_INFO_FLAGS_60G;
ef28afdb 156 sinfo->txrate.mcs = le16_to_cpu(reply.evt.bf_mcs);
2be7d22f 157 sinfo->rxrate.flags = RATE_INFO_FLAGS_MCS | RATE_INFO_FLAGS_60G;
c8b78b5f
VK
158 sinfo->rxrate.mcs = stats->last_mcs_rx;
159 sinfo->rx_bytes = stats->rx_bytes;
160 sinfo->rx_packets = stats->rx_packets;
161 sinfo->rx_dropped_misc = stats->rx_dropped;
162 sinfo->tx_bytes = stats->tx_bytes;
163 sinfo->tx_packets = stats->tx_packets;
164 sinfo->tx_failed = stats->tx_errors;
2be7d22f 165
9419b6a2 166 if (test_bit(wil_status_fwconnected, wil->status)) {
319090bf 167 sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL);
b8b33a3a 168 sinfo->signal = reply.evt.sqi;
2be7d22f
VK
169 }
170
ef28afdb
VK
171 return rc;
172}
173
174static int wil_cfg80211_get_station(struct wiphy *wiphy,
175 struct net_device *ndev,
3b3a0162 176 const u8 *mac, struct station_info *sinfo)
ef28afdb
VK
177{
178 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
179 int rc;
180
181 int cid = wil_find_cid(wil, mac);
182
fa4a18e7 183 wil_dbg_misc(wil, "%s(%pM) CID %d\n", __func__, mac, cid);
ef28afdb 184 if (cid < 0)
c14c5d99 185 return cid;
ef28afdb
VK
186
187 rc = wil_cid_fill_sinfo(wil, cid, sinfo);
188
189 return rc;
190}
191
192/*
193 * Find @idx-th active STA for station dump.
194 */
195static int wil_find_cid_by_idx(struct wil6210_priv *wil, int idx)
196{
197 int i;
198
199 for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
200 if (wil->sta[i].status == wil_sta_unused)
201 continue;
202 if (idx == 0)
203 return i;
204 idx--;
205 }
206
207 return -ENOENT;
208}
209
210static int wil_cfg80211_dump_station(struct wiphy *wiphy,
211 struct net_device *dev, int idx,
212 u8 *mac, struct station_info *sinfo)
213{
214 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
215 int rc;
216 int cid = wil_find_cid_by_idx(wil, idx);
217
218 if (cid < 0)
219 return -ENOENT;
220
a82553bb 221 ether_addr_copy(mac, wil->sta[cid].addr);
fa4a18e7 222 wil_dbg_misc(wil, "%s(%pM) CID %d\n", __func__, mac, cid);
ef28afdb
VK
223
224 rc = wil_cid_fill_sinfo(wil, cid, sinfo);
225
226 return rc;
2be7d22f
VK
227}
228
229static int wil_cfg80211_change_iface(struct wiphy *wiphy,
230 struct net_device *ndev,
231 enum nl80211_iftype type, u32 *flags,
232 struct vif_params *params)
233{
234 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
235 struct wireless_dev *wdev = wil->wdev;
236
237 switch (type) {
238 case NL80211_IFTYPE_STATION:
239 case NL80211_IFTYPE_AP:
240 case NL80211_IFTYPE_P2P_CLIENT:
241 case NL80211_IFTYPE_P2P_GO:
242 break;
243 case NL80211_IFTYPE_MONITOR:
244 if (flags)
245 wil->monitor_flags = *flags;
246 else
247 wil->monitor_flags = 0;
248
249 break;
250 default:
251 return -EOPNOTSUPP;
252 }
253
254 wdev->iftype = type;
255
256 return 0;
257}
258
259static int wil_cfg80211_scan(struct wiphy *wiphy,
260 struct cfg80211_scan_request *request)
261{
262 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
263 struct wireless_dev *wdev = wil->wdev;
264 struct {
265 struct wmi_start_scan_cmd cmd;
266 u16 chnl[4];
267 } __packed cmd;
268 uint i, n;
ed6f9dc6 269 int rc;
2be7d22f
VK
270
271 if (wil->scan_request) {
272 wil_err(wil, "Already scanning\n");
273 return -EAGAIN;
274 }
275
276 /* check we are client side */
277 switch (wdev->iftype) {
278 case NL80211_IFTYPE_STATION:
279 case NL80211_IFTYPE_P2P_CLIENT:
280 break;
281 default:
282 return -EOPNOTSUPP;
2be7d22f
VK
283 }
284
285 /* FW don't support scan after connection attempt */
9419b6a2 286 if (test_bit(wil_status_dontscan, wil->status)) {
e83eb2fc 287 wil_err(wil, "Can't scan now\n");
2be7d22f
VK
288 return -EBUSY;
289 }
290
2a91d7d0 291 wil_dbg_misc(wil, "Start scan_request 0x%p\n", request);
8e52fe30
HK
292 wil_dbg_misc(wil, "SSID count: %d", request->n_ssids);
293
294 for (i = 0; i < request->n_ssids; i++) {
295 wil_dbg_misc(wil, "SSID[%d]", i);
296 print_hex_dump_bytes("SSID ", DUMP_PREFIX_OFFSET,
297 request->ssids[i].ssid,
298 request->ssids[i].ssid_len);
299 }
300
301 if (request->n_ssids)
302 rc = wmi_set_ssid(wil, request->ssids[0].ssid_len,
303 request->ssids[0].ssid);
304 else
305 rc = wmi_set_ssid(wil, 0, NULL);
306
307 if (rc) {
308 wil_err(wil, "set SSID for scan request failed: %d\n", rc);
309 return rc;
310 }
311
2be7d22f 312 wil->scan_request = request;
047e5d74 313 mod_timer(&wil->scan_timer, jiffies + WIL6210_SCAN_TO);
2be7d22f
VK
314
315 memset(&cmd, 0, sizeof(cmd));
316 cmd.cmd.num_channels = 0;
317 n = min(request->n_channels, 4U);
318 for (i = 0; i < n; i++) {
319 int ch = request->channels[i]->hw_value;
8fe59627 320
2be7d22f
VK
321 if (ch == 0) {
322 wil_err(wil,
323 "Scan requested for unknown frequency %dMhz\n",
324 request->channels[i]->center_freq);
325 continue;
326 }
327 /* 0-based channel indexes */
328 cmd.cmd.channel_list[cmd.cmd.num_channels++].channel = ch - 1;
7743882d 329 wil_dbg_misc(wil, "Scan for ch %d : %d MHz\n", ch,
2057ebb2 330 request->channels[i]->center_freq);
2be7d22f
VK
331 }
332
77c91295
VK
333 if (request->ie_len)
334 print_hex_dump_bytes("Scan IE ", DUMP_PREFIX_OFFSET,
335 request->ie, request->ie_len);
336 else
337 wil_dbg_misc(wil, "Scan has no IE's\n");
338
5421bf0c
VK
339 rc = wmi_set_ie(wil, WMI_FRAME_PROBE_REQ, request->ie_len, request->ie);
340 if (rc)
77c91295 341 goto out;
77c91295 342
ed6f9dc6 343 rc = wmi_send(wil, WMI_START_SCAN_CMDID, &cmd, sizeof(cmd.cmd) +
2be7d22f 344 cmd.cmd.num_channels * sizeof(cmd.cmd.channel_list[0]));
ed6f9dc6 345
77c91295 346out:
a2142086
VK
347 if (rc) {
348 del_timer_sync(&wil->scan_timer);
ed6f9dc6 349 wil->scan_request = NULL;
a2142086 350 }
ed6f9dc6
VK
351
352 return rc;
2be7d22f
VK
353}
354
feeac225
VK
355static void wil_print_crypto(struct wil6210_priv *wil,
356 struct cfg80211_crypto_settings *c)
357{
358 int i, n;
359
360 wil_dbg_misc(wil, "WPA versions: 0x%08x cipher group 0x%08x\n",
361 c->wpa_versions, c->cipher_group);
362 wil_dbg_misc(wil, "Pairwise ciphers [%d] {\n", c->n_ciphers_pairwise);
363 n = min_t(int, c->n_ciphers_pairwise, ARRAY_SIZE(c->ciphers_pairwise));
364 for (i = 0; i < n; i++)
365 wil_dbg_misc(wil, " [%d] = 0x%08x\n", i,
366 c->ciphers_pairwise[i]);
367 wil_dbg_misc(wil, "}\n");
368 wil_dbg_misc(wil, "AKM suites [%d] {\n", c->n_akm_suites);
369 n = min_t(int, c->n_akm_suites, ARRAY_SIZE(c->akm_suites));
370 for (i = 0; i < n; i++)
371 wil_dbg_misc(wil, " [%d] = 0x%08x\n", i,
372 c->akm_suites[i]);
373 wil_dbg_misc(wil, "}\n");
374 wil_dbg_misc(wil, "Control port : %d, eth_type 0x%04x no_encrypt %d\n",
375 c->control_port, be16_to_cpu(c->control_port_ethertype),
376 c->control_port_no_encrypt);
377}
378
8ca26163
VK
379static void wil_print_connect_params(struct wil6210_priv *wil,
380 struct cfg80211_connect_params *sme)
381{
382 wil_info(wil, "Connecting to:\n");
383 if (sme->channel) {
384 wil_info(wil, " Channel: %d freq %d\n",
385 sme->channel->hw_value, sme->channel->center_freq);
386 }
387 if (sme->bssid)
388 wil_info(wil, " BSSID: %pM\n", sme->bssid);
389 if (sme->ssid)
390 print_hex_dump(KERN_INFO, " SSID: ", DUMP_PREFIX_OFFSET,
391 16, 1, sme->ssid, sme->ssid_len, true);
392 wil_info(wil, " Privacy: %s\n", sme->privacy ? "secure" : "open");
feeac225 393 wil_print_crypto(wil, &sme->crypto);
8ca26163
VK
394}
395
2be7d22f
VK
396static int wil_cfg80211_connect(struct wiphy *wiphy,
397 struct net_device *ndev,
398 struct cfg80211_connect_params *sme)
399{
400 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
401 struct cfg80211_bss *bss;
402 struct wmi_connect_cmd conn;
403 const u8 *ssid_eid;
404 const u8 *rsn_eid;
405 int ch;
406 int rc = 0;
407
344a7024
VK
408 wil_print_connect_params(wil, sme);
409
9419b6a2
VK
410 if (test_bit(wil_status_fwconnecting, wil->status) ||
411 test_bit(wil_status_fwconnected, wil->status))
4cd9e837
VK
412 return -EALREADY;
413
344a7024
VK
414 if (sme->ie_len > WMI_MAX_IE_LEN) {
415 wil_err(wil, "IE too large (%td bytes)\n", sme->ie_len);
416 return -ERANGE;
417 }
418
419 rsn_eid = sme->ie ?
420 cfg80211_find_ie(WLAN_EID_RSN, sme->ie, sme->ie_len) :
421 NULL;
27aa6b71
VK
422 if (sme->privacy && !rsn_eid)
423 wil_info(wil, "WSC connection\n");
8ca26163 424
2be7d22f
VK
425 bss = cfg80211_get_bss(wiphy, sme->channel, sme->bssid,
426 sme->ssid, sme->ssid_len,
6eb18137 427 IEEE80211_BSS_TYPE_ESS, IEEE80211_PRIVACY_ANY);
2be7d22f
VK
428 if (!bss) {
429 wil_err(wil, "Unable to find BSS\n");
430 return -ENOENT;
431 }
432
433 ssid_eid = ieee80211_bss_get_ie(bss, WLAN_EID_SSID);
434 if (!ssid_eid) {
435 wil_err(wil, "No SSID\n");
436 rc = -ENOENT;
437 goto out;
438 }
344a7024 439 wil->privacy = sme->privacy;
2be7d22f 440
344a7024 441 if (wil->privacy) {
230d8442
VK
442 /* For secure assoc, remove old keys */
443 rc = wmi_del_cipher_key(wil, 0, bss->bssid,
444 WMI_KEY_USE_PAIRWISE);
2be7d22f 445 if (rc) {
230d8442
VK
446 wil_err(wil, "WMI_DELETE_CIPHER_KEY_CMD(PTK) failed\n");
447 goto out;
448 }
449 rc = wmi_del_cipher_key(wil, 0, bss->bssid,
450 WMI_KEY_USE_RX_GROUP);
451 if (rc) {
452 wil_err(wil, "WMI_DELETE_CIPHER_KEY_CMD(GTK) failed\n");
2be7d22f
VK
453 goto out;
454 }
ac4acdb7
VK
455 }
456
457 /* WMI_SET_APPIE_CMD. ie may contain rsn info as well as other info
458 * elements. Send it also in case it's empty, to erase previously set
459 * ies in FW.
460 */
461 rc = wmi_set_ie(wil, WMI_FRAME_ASSOC_REQ, sme->ie_len, sme->ie);
5421bf0c 462 if (rc)
ac4acdb7 463 goto out;
2be7d22f
VK
464
465 /* WMI_CONNECT_CMD */
466 memset(&conn, 0, sizeof(conn));
acc9780d 467 switch (bss->capability & WLAN_CAPABILITY_DMG_TYPE_MASK) {
2be7d22f
VK
468 case WLAN_CAPABILITY_DMG_TYPE_AP:
469 conn.network_type = WMI_NETTYPE_INFRA;
470 break;
471 case WLAN_CAPABILITY_DMG_TYPE_PBSS:
472 conn.network_type = WMI_NETTYPE_P2P;
473 break;
474 default:
475 wil_err(wil, "Unsupported BSS type, capability= 0x%04x\n",
476 bss->capability);
477 goto out;
478 }
344a7024 479 if (wil->privacy) {
27aa6b71
VK
480 if (rsn_eid) { /* regular secure connection */
481 conn.dot11_auth_mode = WMI_AUTH11_SHARED;
482 conn.auth_mode = WMI_AUTH_WPA2_PSK;
483 conn.pairwise_crypto_type = WMI_CRYPT_AES_GCMP;
484 conn.pairwise_crypto_len = 16;
485 conn.group_crypto_type = WMI_CRYPT_AES_GCMP;
486 conn.group_crypto_len = 16;
487 } else { /* WSC */
488 conn.dot11_auth_mode = WMI_AUTH11_WSC;
489 conn.auth_mode = WMI_AUTH_NONE;
490 }
491 } else { /* insecure connection */
2be7d22f
VK
492 conn.dot11_auth_mode = WMI_AUTH11_OPEN;
493 conn.auth_mode = WMI_AUTH_NONE;
494 }
495
496 conn.ssid_len = min_t(u8, ssid_eid[1], 32);
497 memcpy(conn.ssid, ssid_eid+2, conn.ssid_len);
498
499 ch = bss->channel->hw_value;
500 if (ch == 0) {
501 wil_err(wil, "BSS at unknown frequency %dMhz\n",
502 bss->channel->center_freq);
503 rc = -EOPNOTSUPP;
504 goto out;
505 }
506 conn.channel = ch - 1;
507
a82553bb
VK
508 ether_addr_copy(conn.bssid, bss->bssid);
509 ether_addr_copy(conn.dst_mac, bss->bssid);
e83eb2fc 510
9419b6a2 511 set_bit(wil_status_fwconnecting, wil->status);
2be7d22f
VK
512
513 rc = wmi_send(wil, WMI_CONNECT_CMDID, &conn, sizeof(conn));
514 if (rc == 0) {
c5e96c91 515 netif_carrier_on(ndev);
2be7d22f
VK
516 /* Connect can take lots of time */
517 mod_timer(&wil->connect_timer,
518 jiffies + msecs_to_jiffies(2000));
b338f74e 519 } else {
9419b6a2 520 clear_bit(wil_status_fwconnecting, wil->status);
2be7d22f
VK
521 }
522
523 out:
5b112d3d 524 cfg80211_put_bss(wiphy, bss);
2be7d22f
VK
525
526 return rc;
527}
528
529static int wil_cfg80211_disconnect(struct wiphy *wiphy,
530 struct net_device *ndev,
531 u16 reason_code)
532{
533 int rc;
534 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
535
de9084ef
VK
536 wil_dbg_misc(wil, "%s(reason=%d)\n", __func__, reason_code);
537
78771d76
VK
538 if (!(test_bit(wil_status_fwconnecting, wil->status) ||
539 test_bit(wil_status_fwconnected, wil->status))) {
540 wil_err(wil, "%s: Disconnect was called while disconnected\n",
541 __func__);
542 return 0;
543 }
544
545 rc = wmi_call(wil, WMI_DISCONNECT_CMDID, NULL, 0,
546 WMI_DISCONNECT_EVENTID, NULL, 0,
547 WIL6210_DISCONNECT_TO_MS);
548 if (rc)
549 wil_err(wil, "%s: disconnect error %d\n", __func__, rc);
2be7d22f
VK
550
551 return rc;
552}
553
0b39aaf2
VK
554int wil_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
555 struct cfg80211_mgmt_tx_params *params,
556 u64 *cookie)
1647f12f
VK
557{
558 const u8 *buf = params->buf;
559 size_t len = params->len;
560 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
561 int rc;
304464f4 562 bool tx_status = false;
1647f12f
VK
563 struct ieee80211_mgmt *mgmt_frame = (void *)buf;
564 struct wmi_sw_tx_req_cmd *cmd;
565 struct {
566 struct wil6210_mbox_hdr_wmi wmi;
567 struct wmi_sw_tx_complete_event evt;
568 } __packed evt;
569
570 cmd = kmalloc(sizeof(*cmd) + len, GFP_KERNEL);
304464f4
VK
571 if (!cmd) {
572 rc = -ENOMEM;
573 goto out;
574 }
1647f12f
VK
575
576 memcpy(cmd->dst_mac, mgmt_frame->da, WMI_MAC_LEN);
577 cmd->len = cpu_to_le16(len);
578 memcpy(cmd->payload, buf, len);
579
580 rc = wmi_call(wil, WMI_SW_TX_REQ_CMDID, cmd, sizeof(*cmd) + len,
581 WMI_SW_TX_COMPLETE_EVENTID, &evt, sizeof(evt), 2000);
582 if (rc == 0)
304464f4 583 tx_status = !evt.evt.status;
1647f12f
VK
584
585 kfree(cmd);
304464f4
VK
586 out:
587 cfg80211_mgmt_tx_status(wdev, cookie ? *cookie : 0, buf, len,
588 tx_status, GFP_KERNEL);
1647f12f
VK
589 return rc;
590}
591
2be7d22f
VK
592static int wil_cfg80211_set_channel(struct wiphy *wiphy,
593 struct cfg80211_chan_def *chandef)
594{
595 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
596 struct wireless_dev *wdev = wil->wdev;
597
598 wdev->preset_chandef = *chandef;
599
600 return 0;
601}
602
230d8442
VK
603static enum wmi_key_usage wil_detect_key_usage(struct wil6210_priv *wil,
604 bool pairwise)
605{
606 struct wireless_dev *wdev = wil->wdev;
607 enum wmi_key_usage rc;
608 static const char * const key_usage_str[] = {
609 [WMI_KEY_USE_PAIRWISE] = "WMI_KEY_USE_PAIRWISE",
610 [WMI_KEY_USE_RX_GROUP] = "WMI_KEY_USE_RX_GROUP",
611 [WMI_KEY_USE_TX_GROUP] = "WMI_KEY_USE_TX_GROUP",
612 };
613
614 if (pairwise) {
615 rc = WMI_KEY_USE_PAIRWISE;
616 } else {
617 switch (wdev->iftype) {
618 case NL80211_IFTYPE_STATION:
619 rc = WMI_KEY_USE_RX_GROUP;
620 break;
621 case NL80211_IFTYPE_AP:
622 rc = WMI_KEY_USE_TX_GROUP;
623 break;
624 default:
625 /* TODO: Rx GTK or Tx GTK? */
626 wil_err(wil, "Can't determine GTK type\n");
627 rc = WMI_KEY_USE_RX_GROUP;
628 break;
629 }
630 }
631 wil_dbg_misc(wil, "%s() -> %s\n", __func__, key_usage_str[rc]);
632
633 return rc;
634}
635
2be7d22f
VK
636static int wil_cfg80211_add_key(struct wiphy *wiphy,
637 struct net_device *ndev,
638 u8 key_index, bool pairwise,
639 const u8 *mac_addr,
640 struct key_params *params)
641{
642 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
230d8442 643 enum wmi_key_usage key_usage = wil_detect_key_usage(wil, pairwise);
2be7d22f 644
db8adcbf
VK
645 wil_dbg_misc(wil, "%s(%pM[%d] %s)\n", __func__, mac_addr, key_index,
646 pairwise ? "PTK" : "GTK");
647
230d8442
VK
648 return wmi_add_cipher_key(wil, key_index, mac_addr, params->key_len,
649 params->key, key_usage);
2be7d22f
VK
650}
651
652static int wil_cfg80211_del_key(struct wiphy *wiphy,
653 struct net_device *ndev,
654 u8 key_index, bool pairwise,
655 const u8 *mac_addr)
656{
657 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
230d8442 658 enum wmi_key_usage key_usage = wil_detect_key_usage(wil, pairwise);
2be7d22f 659
db8adcbf
VK
660 wil_dbg_misc(wil, "%s(%pM[%d] %s)\n", __func__, mac_addr, key_index,
661 pairwise ? "PTK" : "GTK");
662
230d8442 663 return wmi_del_cipher_key(wil, key_index, mac_addr, key_usage);
2be7d22f
VK
664}
665
666/* Need to be present or wiphy_new() will WARN */
667static int wil_cfg80211_set_default_key(struct wiphy *wiphy,
668 struct net_device *ndev,
669 u8 key_index, bool unicast,
670 bool multicast)
671{
672 return 0;
673}
674
1647f12f
VK
675static int wil_remain_on_channel(struct wiphy *wiphy,
676 struct wireless_dev *wdev,
677 struct ieee80211_channel *chan,
678 unsigned int duration,
679 u64 *cookie)
680{
681 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
682 int rc;
683
684 /* TODO: handle duration */
685 wil_info(wil, "%s(%d, %d ms)\n", __func__, chan->center_freq, duration);
686
687 rc = wmi_set_channel(wil, chan->hw_value);
688 if (rc)
689 return rc;
690
691 rc = wmi_rxon(wil, true);
692
693 return rc;
694}
695
696static int wil_cancel_remain_on_channel(struct wiphy *wiphy,
697 struct wireless_dev *wdev,
698 u64 cookie)
699{
700 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
701 int rc;
702
703 wil_info(wil, "%s()\n", __func__);
704
705 rc = wmi_rxon(wil, false);
706
707 return rc;
708}
709
c100c883
LD
710/**
711 * find a specific IE in a list of IEs
712 * return a pointer to the beginning of IE in the list
713 * or NULL if not found
714 */
715static const u8 *_wil_cfg80211_find_ie(const u8 *ies, u16 ies_len, const u8 *ie,
716 u16 ie_len)
717{
718 struct ieee80211_vendor_ie *vie;
719 u32 oui;
720
721 /* IE tag at offset 0, length at offset 1 */
722 if (ie_len < 2 || 2 + ie[1] > ie_len)
723 return NULL;
724
725 if (ie[0] != WLAN_EID_VENDOR_SPECIFIC)
726 return cfg80211_find_ie(ie[0], ies, ies_len);
727
728 /* make sure there is room for 3 bytes OUI + 1 byte OUI type */
729 if (ie[1] < 4)
730 return NULL;
731 vie = (struct ieee80211_vendor_ie *)ie;
732 oui = vie->oui[0] << 16 | vie->oui[1] << 8 | vie->oui[2];
733 return cfg80211_find_vendor_ie(oui, vie->oui_type, ies,
734 ies_len);
735}
736
737/**
738 * merge the IEs in two lists into a single list.
739 * do not include IEs from the second list which exist in the first list.
740 * add only vendor specific IEs from second list to keep
741 * the merged list sorted (since vendor-specific IE has the
742 * highest tag number)
743 * caller must free the allocated memory for merged IEs
744 */
745static int _wil_cfg80211_merge_extra_ies(const u8 *ies1, u16 ies1_len,
746 const u8 *ies2, u16 ies2_len,
747 u8 **merged_ies, u16 *merged_len)
748{
749 u8 *buf, *dpos;
750 const u8 *spos;
751
752 if (ies1_len == 0 && ies2_len == 0) {
753 *merged_ies = NULL;
754 *merged_len = 0;
755 return 0;
756 }
757
758 buf = kmalloc(ies1_len + ies2_len, GFP_KERNEL);
759 if (!buf)
760 return -ENOMEM;
761 memcpy(buf, ies1, ies1_len);
762 dpos = buf + ies1_len;
763 spos = ies2;
764 while (spos + 1 < ies2 + ies2_len) {
765 /* IE tag at offset 0, length at offset 1 */
766 u16 ielen = 2 + spos[1];
767
768 if (spos + ielen > ies2 + ies2_len)
769 break;
770 if (spos[0] == WLAN_EID_VENDOR_SPECIFIC &&
771 !_wil_cfg80211_find_ie(ies1, ies1_len, spos, ielen)) {
772 memcpy(dpos, spos, ielen);
773 dpos += ielen;
774 }
775 spos += ielen;
776 }
777
778 *merged_ies = buf;
779 *merged_len = dpos - buf;
780 return 0;
781}
782
ca959773
VK
783static void wil_print_bcon_data(struct cfg80211_beacon_data *b)
784{
785 print_hex_dump_bytes("head ", DUMP_PREFIX_OFFSET,
786 b->head, b->head_len);
787 print_hex_dump_bytes("tail ", DUMP_PREFIX_OFFSET,
788 b->tail, b->tail_len);
789 print_hex_dump_bytes("BCON IE ", DUMP_PREFIX_OFFSET,
790 b->beacon_ies, b->beacon_ies_len);
791 print_hex_dump_bytes("PROBE ", DUMP_PREFIX_OFFSET,
792 b->probe_resp, b->probe_resp_len);
793 print_hex_dump_bytes("PROBE IE ", DUMP_PREFIX_OFFSET,
794 b->proberesp_ies, b->proberesp_ies_len);
795 print_hex_dump_bytes("ASSOC IE ", DUMP_PREFIX_OFFSET,
796 b->assocresp_ies, b->assocresp_ies_len);
797}
798
33190ebf
VK
799/* internal functions for device reset and starting AP */
800static int _wil_cfg80211_set_ies(struct wiphy *wiphy,
cab5abbf 801 struct cfg80211_beacon_data *bcon)
33190ebf
VK
802{
803 int rc;
804 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
c100c883
LD
805 u16 len = 0, proberesp_len = 0;
806 u8 *ies = NULL, *proberesp = NULL;
807
808 if (bcon->probe_resp) {
809 struct ieee80211_mgmt *f =
810 (struct ieee80211_mgmt *)bcon->probe_resp;
811 size_t hlen = offsetof(struct ieee80211_mgmt,
812 u.probe_resp.variable);
813 proberesp = f->u.probe_resp.variable;
814 proberesp_len = bcon->probe_resp_len - hlen;
815 }
816 rc = _wil_cfg80211_merge_extra_ies(proberesp,
817 proberesp_len,
818 bcon->proberesp_ies,
819 bcon->proberesp_ies_len,
820 &ies, &len);
33190ebf 821
5421bf0c 822 if (rc)
c100c883
LD
823 goto out;
824
825 rc = wmi_set_ie(wil, WMI_FRAME_PROBE_RESP, len, ies);
826 if (rc)
827 goto out;
33190ebf 828
c100c883
LD
829 if (bcon->assocresp_ies)
830 rc = wmi_set_ie(wil, WMI_FRAME_ASSOC_RESP,
831 bcon->assocresp_ies_len, bcon->assocresp_ies);
832 else
833 rc = wmi_set_ie(wil, WMI_FRAME_ASSOC_RESP, len, ies);
cab5abbf 834#if 0 /* to use beacon IE's, remove this #if 0 */
5421bf0c 835 if (rc)
c100c883 836 goto out;
5421bf0c
VK
837
838 rc = wmi_set_ie(wil, WMI_FRAME_BEACON, bcon->tail_len, bcon->tail);
cab5abbf 839#endif
c100c883
LD
840out:
841 kfree(ies);
5421bf0c 842 return rc;
33190ebf
VK
843}
844
845static int _wil_cfg80211_start_ap(struct wiphy *wiphy,
846 struct net_device *ndev,
847 const u8 *ssid, size_t ssid_len, u32 privacy,
848 int bi, u8 chan,
cab5abbf 849 struct cfg80211_beacon_data *bcon,
33190ebf
VK
850 u8 hidden_ssid)
851{
852 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
853 int rc;
854 struct wireless_dev *wdev = ndev->ieee80211_ptr;
855 u8 wmi_nettype = wil_iftype_nl2wmi(wdev->iftype);
856
857 wil_set_recovery_state(wil, fw_recovery_idle);
858
859 mutex_lock(&wil->mutex);
860
861 __wil_down(wil);
862 rc = __wil_up(wil);
863 if (rc)
864 goto out;
865
866 rc = wmi_set_ssid(wil, ssid_len, ssid);
867 if (rc)
868 goto out;
869
cab5abbf 870 rc = _wil_cfg80211_set_ies(wiphy, bcon);
33190ebf
VK
871 if (rc)
872 goto out;
873
874 wil->privacy = privacy;
875 wil->channel = chan;
876 wil->hidden_ssid = hidden_ssid;
877
878 netif_carrier_on(ndev);
879
880 rc = wmi_pcp_start(wil, bi, wmi_nettype, chan, hidden_ssid);
881 if (rc)
882 goto err_pcp_start;
883
884 rc = wil_bcast_init(wil);
885 if (rc)
886 goto err_bcast;
887
888 goto out; /* success */
889
890err_bcast:
891 wmi_pcp_stop(wil);
892err_pcp_start:
893 netif_carrier_off(ndev);
894out:
895 mutex_unlock(&wil->mutex);
896 return rc;
897}
898
1bd922fc
VK
899static int wil_cfg80211_change_beacon(struct wiphy *wiphy,
900 struct net_device *ndev,
901 struct cfg80211_beacon_data *bcon)
902{
903 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
904 int rc;
33190ebf 905 u32 privacy = 0;
1bd922fc
VK
906
907 wil_dbg_misc(wil, "%s()\n", __func__);
1e7e5a0d
VK
908 wil_print_bcon_data(bcon);
909
c5a157e4
LD
910 if (bcon->tail &&
911 cfg80211_find_ie(WLAN_EID_RSN, bcon->tail,
912 bcon->tail_len))
33190ebf 913 privacy = 1;
1bd922fc 914
33190ebf
VK
915 /* in case privacy has changed, need to restart the AP */
916 if (wil->privacy != privacy) {
917 struct wireless_dev *wdev = ndev->ieee80211_ptr;
918
919 wil_dbg_misc(wil, "privacy changed %d=>%d. Restarting AP\n",
920 wil->privacy, privacy);
921
922 rc = _wil_cfg80211_start_ap(wiphy, ndev, wdev->ssid,
923 wdev->ssid_len, privacy,
924 wdev->beacon_interval,
cab5abbf 925 wil->channel, bcon,
33190ebf
VK
926 wil->hidden_ssid);
927 } else {
cab5abbf 928 rc = _wil_cfg80211_set_ies(wiphy, bcon);
1bd922fc
VK
929 }
930
33190ebf 931 return rc;
1bd922fc
VK
932}
933
2be7d22f
VK
934static int wil_cfg80211_start_ap(struct wiphy *wiphy,
935 struct net_device *ndev,
936 struct cfg80211_ap_settings *info)
937{
33190ebf 938 int rc;
2be7d22f 939 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
2be7d22f
VK
940 struct ieee80211_channel *channel = info->chandef.chan;
941 struct cfg80211_beacon_data *bcon = &info->beacon;
ca959773 942 struct cfg80211_crypto_settings *crypto = &info->crypto;
8e52fe30 943 u8 hidden_ssid;
2be7d22f 944
ca959773
VK
945 wil_dbg_misc(wil, "%s()\n", __func__);
946
2be7d22f
VK
947 if (!channel) {
948 wil_err(wil, "AP: No channel???\n");
949 return -EINVAL;
950 }
951
33190ebf
VK
952 switch (info->hidden_ssid) {
953 case NL80211_HIDDEN_SSID_NOT_IN_USE:
954 hidden_ssid = WMI_HIDDEN_SSID_DISABLED;
955 break;
956
957 case NL80211_HIDDEN_SSID_ZERO_LEN:
958 hidden_ssid = WMI_HIDDEN_SSID_SEND_EMPTY;
959 break;
960
961 case NL80211_HIDDEN_SSID_ZERO_CONTENTS:
962 hidden_ssid = WMI_HIDDEN_SSID_CLEAR;
963 break;
964
965 default:
966 wil_err(wil, "AP: Invalid hidden SSID %d\n", info->hidden_ssid);
967 return -EOPNOTSUPP;
968 }
7743882d 969 wil_dbg_misc(wil, "AP on Channel %d %d MHz, %s\n", channel->hw_value,
2057ebb2 970 channel->center_freq, info->privacy ? "secure" : "open");
ca959773
VK
971 wil_dbg_misc(wil, "Privacy: %d auth_type %d\n",
972 info->privacy, info->auth_type);
8e52fe30
HK
973 wil_dbg_misc(wil, "Hidden SSID mode: %d\n",
974 info->hidden_ssid);
ca959773
VK
975 wil_dbg_misc(wil, "BI %d DTIM %d\n", info->beacon_interval,
976 info->dtim_period);
2be7d22f
VK
977 print_hex_dump_bytes("SSID ", DUMP_PREFIX_OFFSET,
978 info->ssid, info->ssid_len);
ca959773
VK
979 wil_print_bcon_data(bcon);
980 wil_print_crypto(wil, crypto);
2be7d22f 981
33190ebf
VK
982 rc = _wil_cfg80211_start_ap(wiphy, ndev,
983 info->ssid, info->ssid_len, info->privacy,
984 info->beacon_interval, channel->hw_value,
cab5abbf 985 bcon, hidden_ssid);
2be7d22f
VK
986
987 return rc;
988}
989
990static int wil_cfg80211_stop_ap(struct wiphy *wiphy,
991 struct net_device *ndev)
992{
2be7d22f 993 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
2be7d22f 994
ca959773
VK
995 wil_dbg_misc(wil, "%s()\n", __func__);
996
c5e96c91 997 netif_carrier_off(ndev);
c33407a8
VK
998 wil_set_recovery_state(wil, fw_recovery_idle);
999
9c3bde56
VK
1000 mutex_lock(&wil->mutex);
1001
32a20d46 1002 wmi_pcp_stop(wil);
2be7d22f 1003
73d839ae 1004 __wil_down(wil);
73d839ae 1005
9c3bde56 1006 mutex_unlock(&wil->mutex);
73d839ae 1007
32a20d46 1008 return 0;
2be7d22f
VK
1009}
1010
4d55a0a1 1011static int wil_cfg80211_del_station(struct wiphy *wiphy,
89c771e5
JM
1012 struct net_device *dev,
1013 struct station_del_parameters *params)
4d55a0a1
VK
1014{
1015 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
097638a0 1016
de9084ef
VK
1017 wil_dbg_misc(wil, "%s(%pM, reason=%d)\n", __func__, params->mac,
1018 params->reason_code);
1019
097638a0 1020 mutex_lock(&wil->mutex);
4821e6d8 1021 wil6210_disconnect(wil, params->mac, params->reason_code, false);
097638a0
VK
1022 mutex_unlock(&wil->mutex);
1023
4d55a0a1
VK
1024 return 0;
1025}
1026
40822a90
VK
1027/* probe_client handling */
1028static void wil_probe_client_handle(struct wil6210_priv *wil,
1029 struct wil_probe_client_req *req)
1030{
1031 struct net_device *ndev = wil_to_ndev(wil);
1032 struct wil_sta_info *sta = &wil->sta[req->cid];
1033 /* assume STA is alive if it is still connected,
1034 * else FW will disconnect it
1035 */
1036 bool alive = (sta->status == wil_sta_connected);
1037
1038 cfg80211_probe_status(ndev, sta->addr, req->cookie, alive, GFP_KERNEL);
1039}
1040
1041static struct list_head *next_probe_client(struct wil6210_priv *wil)
1042{
1043 struct list_head *ret = NULL;
1044
1045 mutex_lock(&wil->probe_client_mutex);
1046
1047 if (!list_empty(&wil->probe_client_pending)) {
1048 ret = wil->probe_client_pending.next;
1049 list_del(ret);
1050 }
1051
1052 mutex_unlock(&wil->probe_client_mutex);
1053
1054 return ret;
1055}
1056
1057void wil_probe_client_worker(struct work_struct *work)
1058{
1059 struct wil6210_priv *wil = container_of(work, struct wil6210_priv,
1060 probe_client_worker);
1061 struct wil_probe_client_req *req;
1062 struct list_head *lh;
1063
1064 while ((lh = next_probe_client(wil)) != NULL) {
1065 req = list_entry(lh, struct wil_probe_client_req, list);
1066
1067 wil_probe_client_handle(wil, req);
1068 kfree(req);
1069 }
1070}
1071
1072void wil_probe_client_flush(struct wil6210_priv *wil)
1073{
1074 struct wil_probe_client_req *req, *t;
1075
1076 wil_dbg_misc(wil, "%s()\n", __func__);
1077
1078 mutex_lock(&wil->probe_client_mutex);
1079
1080 list_for_each_entry_safe(req, t, &wil->probe_client_pending, list) {
1081 list_del(&req->list);
1082 kfree(req);
1083 }
1084
1085 mutex_unlock(&wil->probe_client_mutex);
1086}
1087
1088static int wil_cfg80211_probe_client(struct wiphy *wiphy,
1089 struct net_device *dev,
1090 const u8 *peer, u64 *cookie)
1091{
1092 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1093 struct wil_probe_client_req *req;
1094 int cid = wil_find_cid(wil, peer);
1095
1096 wil_dbg_misc(wil, "%s(%pM => CID %d)\n", __func__, peer, cid);
1097
1098 if (cid < 0)
1099 return -ENOLINK;
1100
1101 req = kzalloc(sizeof(*req), GFP_KERNEL);
1102 if (!req)
1103 return -ENOMEM;
1104
1105 req->cid = cid;
1106 req->cookie = cid;
1107
1108 mutex_lock(&wil->probe_client_mutex);
1109 list_add_tail(&req->list, &wil->probe_client_pending);
1110 mutex_unlock(&wil->probe_client_mutex);
1111
1112 *cookie = req->cookie;
1113 queue_work(wil->wq_service, &wil->probe_client_worker);
1114 return 0;
1115}
1116
02beaf1a
VK
1117static int wil_cfg80211_change_bss(struct wiphy *wiphy,
1118 struct net_device *dev,
1119 struct bss_parameters *params)
1120{
1121 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1122
1123 if (params->ap_isolate >= 0) {
1124 wil_dbg_misc(wil, "%s(ap_isolate %d => %d)\n", __func__,
1125 wil->ap_isolate, params->ap_isolate);
1126 wil->ap_isolate = params->ap_isolate;
1127 }
1128
1129 return 0;
1130}
1131
2be7d22f
VK
1132static struct cfg80211_ops wil_cfg80211_ops = {
1133 .scan = wil_cfg80211_scan,
1134 .connect = wil_cfg80211_connect,
1135 .disconnect = wil_cfg80211_disconnect,
1136 .change_virtual_intf = wil_cfg80211_change_iface,
1137 .get_station = wil_cfg80211_get_station,
ef28afdb 1138 .dump_station = wil_cfg80211_dump_station,
1647f12f
VK
1139 .remain_on_channel = wil_remain_on_channel,
1140 .cancel_remain_on_channel = wil_cancel_remain_on_channel,
1141 .mgmt_tx = wil_cfg80211_mgmt_tx,
2be7d22f
VK
1142 .set_monitor_channel = wil_cfg80211_set_channel,
1143 .add_key = wil_cfg80211_add_key,
1144 .del_key = wil_cfg80211_del_key,
1145 .set_default_key = wil_cfg80211_set_default_key,
1146 /* AP mode */
1bd922fc 1147 .change_beacon = wil_cfg80211_change_beacon,
2be7d22f
VK
1148 .start_ap = wil_cfg80211_start_ap,
1149 .stop_ap = wil_cfg80211_stop_ap,
4d55a0a1 1150 .del_station = wil_cfg80211_del_station,
40822a90 1151 .probe_client = wil_cfg80211_probe_client,
02beaf1a 1152 .change_bss = wil_cfg80211_change_bss,
2be7d22f
VK
1153};
1154
1155static void wil_wiphy_init(struct wiphy *wiphy)
1156{
8e52fe30 1157 wiphy->max_scan_ssids = 1;
77c91295 1158 wiphy->max_scan_ie_len = WMI_MAX_IE_LEN;
2be7d22f
VK
1159 wiphy->max_num_pmkids = 0 /* TODO: */;
1160 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
1161 BIT(NL80211_IFTYPE_AP) |
1162 BIT(NL80211_IFTYPE_MONITOR);
1163 /* TODO: enable P2P when integrated with supplicant:
1164 * BIT(NL80211_IFTYPE_P2P_CLIENT) | BIT(NL80211_IFTYPE_P2P_GO)
1165 */
1166 wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME |
1167 WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
9cf10d62
VK
1168 dev_dbg(wiphy_dev(wiphy), "%s : flags = 0x%08x\n",
1169 __func__, wiphy->flags);
2be7d22f
VK
1170 wiphy->probe_resp_offload =
1171 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
1172 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
1173 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
1174
1175 wiphy->bands[IEEE80211_BAND_60GHZ] = &wil_band_60ghz;
1176
1177 /* TODO: figure this out */
b8b33a3a 1178 wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC;
2be7d22f
VK
1179
1180 wiphy->cipher_suites = wil_cipher_suites;
1181 wiphy->n_cipher_suites = ARRAY_SIZE(wil_cipher_suites);
1182 wiphy->mgmt_stypes = wil_mgmt_stypes;
713c8a29 1183 wiphy->features |= NL80211_FEATURE_SK_TX_STATUS;
2be7d22f
VK
1184}
1185
1186struct wireless_dev *wil_cfg80211_init(struct device *dev)
1187{
1188 int rc = 0;
1189 struct wireless_dev *wdev;
1190
9cf10d62
VK
1191 dev_dbg(dev, "%s()\n", __func__);
1192
8fe59627 1193 wdev = kzalloc(sizeof(*wdev), GFP_KERNEL);
2be7d22f
VK
1194 if (!wdev)
1195 return ERR_PTR(-ENOMEM);
1196
1197 wdev->wiphy = wiphy_new(&wil_cfg80211_ops,
1198 sizeof(struct wil6210_priv));
1199 if (!wdev->wiphy) {
1200 rc = -ENOMEM;
1201 goto out;
1202 }
1203
1204 set_wiphy_dev(wdev->wiphy, dev);
1205 wil_wiphy_init(wdev->wiphy);
1206
1207 rc = wiphy_register(wdev->wiphy);
1208 if (rc < 0)
1209 goto out_failed_reg;
1210
1211 return wdev;
1212
1213out_failed_reg:
1214 wiphy_free(wdev->wiphy);
1215out:
1216 kfree(wdev);
1217
1218 return ERR_PTR(rc);
1219}
1220
1221void wil_wdev_free(struct wil6210_priv *wil)
1222{
1223 struct wireless_dev *wdev = wil_to_wdev(wil);
1224
9cf10d62
VK
1225 dev_dbg(wil_to_dev(wil), "%s()\n", __func__);
1226
2be7d22f
VK
1227 if (!wdev)
1228 return;
1229
1230 wiphy_unregister(wdev->wiphy);
1231 wiphy_free(wdev->wiphy);
1232 kfree(wdev);
1233}
This page took 0.267755 seconds and 5 git commands to generate.