Commit | Line | Data |
---|---|---|
2be7d22f | 1 | /* |
02525a79 | 2 | * Copyright (c) 2012-2014 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 | ||
2be7d22f VK |
17 | #include "wil6210.h" |
18 | #include "wmi.h" | |
19 | ||
20 | #define CHAN60G(_channel, _flags) { \ | |
21 | .band = IEEE80211_BAND_60GHZ, \ | |
22 | .center_freq = 56160 + (2160 * (_channel)), \ | |
23 | .hw_value = (_channel), \ | |
24 | .flags = (_flags), \ | |
25 | .max_antenna_gain = 0, \ | |
26 | .max_power = 40, \ | |
27 | } | |
28 | ||
29 | static struct ieee80211_channel wil_60ghz_channels[] = { | |
30 | CHAN60G(1, 0), | |
31 | CHAN60G(2, 0), | |
32 | CHAN60G(3, 0), | |
33 | /* channel 4 not supported yet */ | |
34 | }; | |
35 | ||
36 | static struct ieee80211_supported_band wil_band_60ghz = { | |
37 | .channels = wil_60ghz_channels, | |
38 | .n_channels = ARRAY_SIZE(wil_60ghz_channels), | |
39 | .ht_cap = { | |
40 | .ht_supported = true, | |
41 | .cap = 0, /* TODO */ | |
42 | .ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K, /* TODO */ | |
43 | .ampdu_density = IEEE80211_HT_MPDU_DENSITY_8, /* TODO */ | |
44 | .mcs = { | |
45 | /* MCS 1..12 - SC PHY */ | |
46 | .rx_mask = {0xfe, 0x1f}, /* 1..12 */ | |
47 | .tx_params = IEEE80211_HT_MCS_TX_DEFINED, /* TODO */ | |
48 | }, | |
49 | }, | |
50 | }; | |
51 | ||
52 | static const struct ieee80211_txrx_stypes | |
53 | wil_mgmt_stypes[NUM_NL80211_IFTYPES] = { | |
54 | [NL80211_IFTYPE_STATION] = { | |
55 | .tx = BIT(IEEE80211_STYPE_ACTION >> 4) | | |
56 | BIT(IEEE80211_STYPE_PROBE_RESP >> 4), | |
57 | .rx = BIT(IEEE80211_STYPE_ACTION >> 4) | | |
58 | BIT(IEEE80211_STYPE_PROBE_REQ >> 4) | |
59 | }, | |
60 | [NL80211_IFTYPE_AP] = { | |
61 | .tx = BIT(IEEE80211_STYPE_ACTION >> 4) | | |
62 | BIT(IEEE80211_STYPE_PROBE_RESP >> 4), | |
63 | .rx = BIT(IEEE80211_STYPE_ACTION >> 4) | | |
64 | BIT(IEEE80211_STYPE_PROBE_REQ >> 4) | |
65 | }, | |
66 | [NL80211_IFTYPE_P2P_CLIENT] = { | |
67 | .tx = BIT(IEEE80211_STYPE_ACTION >> 4) | | |
68 | BIT(IEEE80211_STYPE_PROBE_RESP >> 4), | |
69 | .rx = BIT(IEEE80211_STYPE_ACTION >> 4) | | |
70 | BIT(IEEE80211_STYPE_PROBE_REQ >> 4) | |
71 | }, | |
72 | [NL80211_IFTYPE_P2P_GO] = { | |
73 | .tx = BIT(IEEE80211_STYPE_ACTION >> 4) | | |
74 | BIT(IEEE80211_STYPE_PROBE_RESP >> 4), | |
75 | .rx = BIT(IEEE80211_STYPE_ACTION >> 4) | | |
76 | BIT(IEEE80211_STYPE_PROBE_REQ >> 4) | |
77 | }, | |
78 | }; | |
79 | ||
80 | static const u32 wil_cipher_suites[] = { | |
81 | WLAN_CIPHER_SUITE_GCMP, | |
82 | }; | |
83 | ||
84 | int wil_iftype_nl2wmi(enum nl80211_iftype type) | |
85 | { | |
86 | static const struct { | |
87 | enum nl80211_iftype nl; | |
88 | enum wmi_network_type wmi; | |
89 | } __nl2wmi[] = { | |
90 | {NL80211_IFTYPE_ADHOC, WMI_NETTYPE_ADHOC}, | |
91 | {NL80211_IFTYPE_STATION, WMI_NETTYPE_INFRA}, | |
92 | {NL80211_IFTYPE_AP, WMI_NETTYPE_AP}, | |
93 | {NL80211_IFTYPE_P2P_CLIENT, WMI_NETTYPE_P2P}, | |
94 | {NL80211_IFTYPE_P2P_GO, WMI_NETTYPE_P2P}, | |
95 | {NL80211_IFTYPE_MONITOR, WMI_NETTYPE_ADHOC}, /* FIXME */ | |
96 | }; | |
97 | uint i; | |
98 | ||
99 | for (i = 0; i < ARRAY_SIZE(__nl2wmi); i++) { | |
100 | if (__nl2wmi[i].nl == type) | |
101 | return __nl2wmi[i].wmi; | |
102 | } | |
103 | ||
104 | return -EOPNOTSUPP; | |
105 | } | |
106 | ||
9eb82d43 VK |
107 | int wil_cid_fill_sinfo(struct wil6210_priv *wil, int cid, |
108 | struct station_info *sinfo) | |
2be7d22f | 109 | { |
2be7d22f | 110 | struct wmi_notify_req_cmd cmd = { |
3df2cd36 | 111 | .cid = cid, |
2be7d22f VK |
112 | .interval_usec = 0, |
113 | }; | |
ef28afdb VK |
114 | struct { |
115 | struct wil6210_mbox_hdr_wmi wmi; | |
116 | struct wmi_notify_req_done_event evt; | |
117 | } __packed reply; | |
c8b78b5f | 118 | struct wil_net_stats *stats = &wil->sta[cid].stats; |
ef28afdb | 119 | int rc; |
2be7d22f | 120 | |
2be7d22f | 121 | rc = wmi_call(wil, WMI_NOTIFY_REQ_CMDID, &cmd, sizeof(cmd), |
ef28afdb | 122 | WMI_NOTIFY_REQ_DONE_EVENTID, &reply, sizeof(reply), 20); |
2be7d22f VK |
123 | if (rc) |
124 | return rc; | |
125 | ||
c8b78b5f VK |
126 | wil_dbg_wmi(wil, "Link status for CID %d: {\n" |
127 | " MCS %d TSF 0x%016llx\n" | |
b8b33a3a | 128 | " BF status 0x%08x SNR 0x%08x SQI %d%%\n" |
c8b78b5f VK |
129 | " Tx Tpt %d goodput %d Rx goodput %d\n" |
130 | " Sectors(rx:tx) my %d:%d peer %d:%d\n""}\n", | |
131 | cid, le16_to_cpu(reply.evt.bf_mcs), | |
132 | le64_to_cpu(reply.evt.tsf), reply.evt.status, | |
133 | le32_to_cpu(reply.evt.snr_val), | |
b8b33a3a | 134 | reply.evt.sqi, |
c8b78b5f VK |
135 | le32_to_cpu(reply.evt.tx_tpt), |
136 | le32_to_cpu(reply.evt.tx_goodput), | |
137 | le32_to_cpu(reply.evt.rx_goodput), | |
138 | le16_to_cpu(reply.evt.my_rx_sector), | |
139 | le16_to_cpu(reply.evt.my_tx_sector), | |
140 | le16_to_cpu(reply.evt.other_rx_sector), | |
141 | le16_to_cpu(reply.evt.other_tx_sector)); | |
142 | ||
2be7d22f VK |
143 | sinfo->generation = wil->sinfo_gen; |
144 | ||
c8b78b5f VK |
145 | 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 | ||
2be7d22f | 154 | sinfo->txrate.flags = RATE_INFO_FLAGS_MCS | RATE_INFO_FLAGS_60G; |
ef28afdb | 155 | sinfo->txrate.mcs = le16_to_cpu(reply.evt.bf_mcs); |
2be7d22f | 156 | sinfo->rxrate.flags = RATE_INFO_FLAGS_MCS | RATE_INFO_FLAGS_60G; |
c8b78b5f VK |
157 | sinfo->rxrate.mcs = stats->last_mcs_rx; |
158 | sinfo->rx_bytes = stats->rx_bytes; | |
159 | sinfo->rx_packets = stats->rx_packets; | |
160 | sinfo->rx_dropped_misc = stats->rx_dropped; | |
161 | sinfo->tx_bytes = stats->tx_bytes; | |
162 | sinfo->tx_packets = stats->tx_packets; | |
163 | sinfo->tx_failed = stats->tx_errors; | |
2be7d22f VK |
164 | |
165 | if (test_bit(wil_status_fwconnected, &wil->status)) { | |
166 | sinfo->filled |= STATION_INFO_SIGNAL; | |
b8b33a3a | 167 | sinfo->signal = reply.evt.sqi; |
2be7d22f VK |
168 | } |
169 | ||
ef28afdb VK |
170 | return rc; |
171 | } | |
172 | ||
173 | static int wil_cfg80211_get_station(struct wiphy *wiphy, | |
174 | struct net_device *ndev, | |
3b3a0162 | 175 | const u8 *mac, struct station_info *sinfo) |
ef28afdb VK |
176 | { |
177 | struct wil6210_priv *wil = wiphy_to_wil(wiphy); | |
178 | int rc; | |
179 | ||
180 | int cid = wil_find_cid(wil, mac); | |
181 | ||
fa4a18e7 | 182 | wil_dbg_misc(wil, "%s(%pM) CID %d\n", __func__, mac, cid); |
ef28afdb | 183 | if (cid < 0) |
c14c5d99 | 184 | return cid; |
ef28afdb VK |
185 | |
186 | rc = wil_cid_fill_sinfo(wil, cid, sinfo); | |
187 | ||
188 | return rc; | |
189 | } | |
190 | ||
191 | /* | |
192 | * Find @idx-th active STA for station dump. | |
193 | */ | |
194 | static int wil_find_cid_by_idx(struct wil6210_priv *wil, int idx) | |
195 | { | |
196 | int i; | |
197 | ||
198 | for (i = 0; i < ARRAY_SIZE(wil->sta); i++) { | |
199 | if (wil->sta[i].status == wil_sta_unused) | |
200 | continue; | |
201 | if (idx == 0) | |
202 | return i; | |
203 | idx--; | |
204 | } | |
205 | ||
206 | return -ENOENT; | |
207 | } | |
208 | ||
209 | static int wil_cfg80211_dump_station(struct wiphy *wiphy, | |
210 | struct net_device *dev, int idx, | |
211 | u8 *mac, struct station_info *sinfo) | |
212 | { | |
213 | struct wil6210_priv *wil = wiphy_to_wil(wiphy); | |
214 | int rc; | |
215 | int cid = wil_find_cid_by_idx(wil, idx); | |
216 | ||
217 | if (cid < 0) | |
218 | return -ENOENT; | |
219 | ||
220 | memcpy(mac, wil->sta[cid].addr, ETH_ALEN); | |
fa4a18e7 | 221 | wil_dbg_misc(wil, "%s(%pM) CID %d\n", __func__, mac, cid); |
ef28afdb VK |
222 | |
223 | rc = wil_cid_fill_sinfo(wil, cid, sinfo); | |
224 | ||
225 | return rc; | |
2be7d22f VK |
226 | } |
227 | ||
228 | static int wil_cfg80211_change_iface(struct wiphy *wiphy, | |
229 | struct net_device *ndev, | |
230 | enum nl80211_iftype type, u32 *flags, | |
231 | struct vif_params *params) | |
232 | { | |
233 | struct wil6210_priv *wil = wiphy_to_wil(wiphy); | |
234 | struct wireless_dev *wdev = wil->wdev; | |
235 | ||
236 | switch (type) { | |
237 | case NL80211_IFTYPE_STATION: | |
238 | case NL80211_IFTYPE_AP: | |
239 | case NL80211_IFTYPE_P2P_CLIENT: | |
240 | case NL80211_IFTYPE_P2P_GO: | |
241 | break; | |
242 | case NL80211_IFTYPE_MONITOR: | |
243 | if (flags) | |
244 | wil->monitor_flags = *flags; | |
245 | else | |
246 | wil->monitor_flags = 0; | |
247 | ||
248 | break; | |
249 | default: | |
250 | return -EOPNOTSUPP; | |
251 | } | |
252 | ||
253 | wdev->iftype = type; | |
254 | ||
255 | return 0; | |
256 | } | |
257 | ||
258 | static int wil_cfg80211_scan(struct wiphy *wiphy, | |
259 | struct cfg80211_scan_request *request) | |
260 | { | |
261 | struct wil6210_priv *wil = wiphy_to_wil(wiphy); | |
262 | struct wireless_dev *wdev = wil->wdev; | |
263 | struct { | |
264 | struct wmi_start_scan_cmd cmd; | |
265 | u16 chnl[4]; | |
266 | } __packed cmd; | |
267 | uint i, n; | |
ed6f9dc6 | 268 | int rc; |
2be7d22f VK |
269 | |
270 | if (wil->scan_request) { | |
271 | wil_err(wil, "Already scanning\n"); | |
272 | return -EAGAIN; | |
273 | } | |
274 | ||
275 | /* check we are client side */ | |
276 | switch (wdev->iftype) { | |
277 | case NL80211_IFTYPE_STATION: | |
278 | case NL80211_IFTYPE_P2P_CLIENT: | |
279 | break; | |
280 | default: | |
281 | return -EOPNOTSUPP; | |
2be7d22f VK |
282 | } |
283 | ||
284 | /* FW don't support scan after connection attempt */ | |
285 | if (test_bit(wil_status_dontscan, &wil->status)) { | |
e83eb2fc | 286 | wil_err(wil, "Can't scan now\n"); |
2be7d22f VK |
287 | return -EBUSY; |
288 | } | |
289 | ||
2a91d7d0 | 290 | wil_dbg_misc(wil, "Start scan_request 0x%p\n", request); |
2be7d22f | 291 | wil->scan_request = request; |
047e5d74 | 292 | mod_timer(&wil->scan_timer, jiffies + WIL6210_SCAN_TO); |
2be7d22f VK |
293 | |
294 | memset(&cmd, 0, sizeof(cmd)); | |
295 | cmd.cmd.num_channels = 0; | |
296 | n = min(request->n_channels, 4U); | |
297 | for (i = 0; i < n; i++) { | |
298 | int ch = request->channels[i]->hw_value; | |
8fe59627 | 299 | |
2be7d22f VK |
300 | if (ch == 0) { |
301 | wil_err(wil, | |
302 | "Scan requested for unknown frequency %dMhz\n", | |
303 | request->channels[i]->center_freq); | |
304 | continue; | |
305 | } | |
306 | /* 0-based channel indexes */ | |
307 | cmd.cmd.channel_list[cmd.cmd.num_channels++].channel = ch - 1; | |
7743882d | 308 | wil_dbg_misc(wil, "Scan for ch %d : %d MHz\n", ch, |
2057ebb2 | 309 | request->channels[i]->center_freq); |
2be7d22f VK |
310 | } |
311 | ||
77c91295 VK |
312 | if (request->ie_len) |
313 | print_hex_dump_bytes("Scan IE ", DUMP_PREFIX_OFFSET, | |
314 | request->ie, request->ie_len); | |
315 | else | |
316 | wil_dbg_misc(wil, "Scan has no IE's\n"); | |
317 | ||
318 | rc = wmi_set_ie(wil, WMI_FRAME_PROBE_REQ, request->ie_len, | |
319 | request->ie); | |
320 | if (rc) { | |
321 | wil_err(wil, "Aborting scan, set_ie failed: %d\n", rc); | |
322 | goto out; | |
323 | } | |
324 | ||
ed6f9dc6 | 325 | rc = wmi_send(wil, WMI_START_SCAN_CMDID, &cmd, sizeof(cmd.cmd) + |
2be7d22f | 326 | cmd.cmd.num_channels * sizeof(cmd.cmd.channel_list[0])); |
ed6f9dc6 | 327 | |
77c91295 | 328 | out: |
a2142086 VK |
329 | if (rc) { |
330 | del_timer_sync(&wil->scan_timer); | |
ed6f9dc6 | 331 | wil->scan_request = NULL; |
a2142086 | 332 | } |
ed6f9dc6 VK |
333 | |
334 | return rc; | |
2be7d22f VK |
335 | } |
336 | ||
8ca26163 VK |
337 | static 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 | ||
2be7d22f VK |
353 | static 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 | ||
4cd9e837 VK |
365 | if (test_bit(wil_status_fwconnecting, &wil->status) || |
366 | test_bit(wil_status_fwconnected, &wil->status)) | |
367 | return -EALREADY; | |
368 | ||
8ca26163 VK |
369 | wil_print_connect_params(wil, sme); |
370 | ||
2be7d22f VK |
371 | 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 | } | |
ac4acdb7 | 396 | /* For secure assoc, send WMI_DELETE_CIPHER_KEY_CMD */ |
2be7d22f VK |
397 | 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 | } | |
ac4acdb7 VK |
402 | } |
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; | |
2be7d22f VK |
412 | } |
413 | ||
414 | /* WMI_CONNECT_CMD */ | |
415 | memset(&conn, 0, sizeof(conn)); | |
acc9780d | 416 | switch (bss->capability & WLAN_CAPABILITY_DMG_TYPE_MASK) { |
2be7d22f VK |
417 | 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 | ||
d458cdf7 JP |
450 | memcpy(conn.bssid, bss->bssid, ETH_ALEN); |
451 | memcpy(conn.dst_mac, bss->bssid, ETH_ALEN); | |
e83eb2fc | 452 | |
b338f74e | 453 | set_bit(wil_status_fwconnecting, &wil->status); |
2be7d22f VK |
454 | |
455 | rc = wmi_send(wil, WMI_CONNECT_CMDID, &conn, sizeof(conn)); | |
456 | if (rc == 0) { | |
457 | /* Connect can take lots of time */ | |
458 | mod_timer(&wil->connect_timer, | |
459 | jiffies + msecs_to_jiffies(2000)); | |
b338f74e | 460 | } else { |
b338f74e | 461 | clear_bit(wil_status_fwconnecting, &wil->status); |
2be7d22f VK |
462 | } |
463 | ||
464 | out: | |
5b112d3d | 465 | cfg80211_put_bss(wiphy, bss); |
2be7d22f VK |
466 | |
467 | return rc; | |
468 | } | |
469 | ||
470 | static int wil_cfg80211_disconnect(struct wiphy *wiphy, | |
471 | struct net_device *ndev, | |
472 | u16 reason_code) | |
473 | { | |
474 | int rc; | |
475 | struct wil6210_priv *wil = wiphy_to_wil(wiphy); | |
476 | ||
477 | rc = wmi_send(wil, WMI_DISCONNECT_CMDID, NULL, 0); | |
478 | ||
479 | return rc; | |
480 | } | |
481 | ||
0b39aaf2 VK |
482 | int wil_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev, |
483 | struct cfg80211_mgmt_tx_params *params, | |
484 | u64 *cookie) | |
1647f12f VK |
485 | { |
486 | const u8 *buf = params->buf; | |
487 | size_t len = params->len; | |
488 | struct wil6210_priv *wil = wiphy_to_wil(wiphy); | |
489 | int rc; | |
304464f4 | 490 | bool tx_status = false; |
1647f12f VK |
491 | struct ieee80211_mgmt *mgmt_frame = (void *)buf; |
492 | struct wmi_sw_tx_req_cmd *cmd; | |
493 | struct { | |
494 | struct wil6210_mbox_hdr_wmi wmi; | |
495 | struct wmi_sw_tx_complete_event evt; | |
496 | } __packed evt; | |
497 | ||
498 | cmd = kmalloc(sizeof(*cmd) + len, GFP_KERNEL); | |
304464f4 VK |
499 | if (!cmd) { |
500 | rc = -ENOMEM; | |
501 | goto out; | |
502 | } | |
1647f12f VK |
503 | |
504 | memcpy(cmd->dst_mac, mgmt_frame->da, WMI_MAC_LEN); | |
505 | cmd->len = cpu_to_le16(len); | |
506 | memcpy(cmd->payload, buf, len); | |
507 | ||
508 | rc = wmi_call(wil, WMI_SW_TX_REQ_CMDID, cmd, sizeof(*cmd) + len, | |
509 | WMI_SW_TX_COMPLETE_EVENTID, &evt, sizeof(evt), 2000); | |
510 | if (rc == 0) | |
304464f4 | 511 | tx_status = !evt.evt.status; |
1647f12f VK |
512 | |
513 | kfree(cmd); | |
304464f4 VK |
514 | out: |
515 | cfg80211_mgmt_tx_status(wdev, cookie ? *cookie : 0, buf, len, | |
516 | tx_status, GFP_KERNEL); | |
1647f12f VK |
517 | return rc; |
518 | } | |
519 | ||
2be7d22f VK |
520 | static int wil_cfg80211_set_channel(struct wiphy *wiphy, |
521 | struct cfg80211_chan_def *chandef) | |
522 | { | |
523 | struct wil6210_priv *wil = wiphy_to_wil(wiphy); | |
524 | struct wireless_dev *wdev = wil->wdev; | |
525 | ||
526 | wdev->preset_chandef = *chandef; | |
527 | ||
528 | return 0; | |
529 | } | |
530 | ||
531 | static int wil_cfg80211_add_key(struct wiphy *wiphy, | |
532 | struct net_device *ndev, | |
533 | u8 key_index, bool pairwise, | |
534 | const u8 *mac_addr, | |
535 | struct key_params *params) | |
536 | { | |
537 | struct wil6210_priv *wil = wiphy_to_wil(wiphy); | |
538 | ||
539 | /* group key is not used */ | |
540 | if (!pairwise) | |
541 | return 0; | |
542 | ||
543 | return wmi_add_cipher_key(wil, key_index, mac_addr, | |
544 | params->key_len, params->key); | |
545 | } | |
546 | ||
547 | static int wil_cfg80211_del_key(struct wiphy *wiphy, | |
548 | struct net_device *ndev, | |
549 | u8 key_index, bool pairwise, | |
550 | const u8 *mac_addr) | |
551 | { | |
552 | struct wil6210_priv *wil = wiphy_to_wil(wiphy); | |
553 | ||
554 | /* group key is not used */ | |
555 | if (!pairwise) | |
556 | return 0; | |
557 | ||
558 | return wmi_del_cipher_key(wil, key_index, mac_addr); | |
559 | } | |
560 | ||
561 | /* Need to be present or wiphy_new() will WARN */ | |
562 | static int wil_cfg80211_set_default_key(struct wiphy *wiphy, | |
563 | struct net_device *ndev, | |
564 | u8 key_index, bool unicast, | |
565 | bool multicast) | |
566 | { | |
567 | return 0; | |
568 | } | |
569 | ||
1647f12f VK |
570 | static int wil_remain_on_channel(struct wiphy *wiphy, |
571 | struct wireless_dev *wdev, | |
572 | struct ieee80211_channel *chan, | |
573 | unsigned int duration, | |
574 | u64 *cookie) | |
575 | { | |
576 | struct wil6210_priv *wil = wiphy_to_wil(wiphy); | |
577 | int rc; | |
578 | ||
579 | /* TODO: handle duration */ | |
580 | wil_info(wil, "%s(%d, %d ms)\n", __func__, chan->center_freq, duration); | |
581 | ||
582 | rc = wmi_set_channel(wil, chan->hw_value); | |
583 | if (rc) | |
584 | return rc; | |
585 | ||
586 | rc = wmi_rxon(wil, true); | |
587 | ||
588 | return rc; | |
589 | } | |
590 | ||
591 | static int wil_cancel_remain_on_channel(struct wiphy *wiphy, | |
592 | struct wireless_dev *wdev, | |
593 | u64 cookie) | |
594 | { | |
595 | struct wil6210_priv *wil = wiphy_to_wil(wiphy); | |
596 | int rc; | |
597 | ||
598 | wil_info(wil, "%s()\n", __func__); | |
599 | ||
600 | rc = wmi_rxon(wil, false); | |
601 | ||
602 | return rc; | |
603 | } | |
604 | ||
ca959773 VK |
605 | static void wil_print_bcon_data(struct cfg80211_beacon_data *b) |
606 | { | |
607 | print_hex_dump_bytes("head ", DUMP_PREFIX_OFFSET, | |
608 | b->head, b->head_len); | |
609 | print_hex_dump_bytes("tail ", DUMP_PREFIX_OFFSET, | |
610 | b->tail, b->tail_len); | |
611 | print_hex_dump_bytes("BCON IE ", DUMP_PREFIX_OFFSET, | |
612 | b->beacon_ies, b->beacon_ies_len); | |
613 | print_hex_dump_bytes("PROBE ", DUMP_PREFIX_OFFSET, | |
614 | b->probe_resp, b->probe_resp_len); | |
615 | print_hex_dump_bytes("PROBE IE ", DUMP_PREFIX_OFFSET, | |
616 | b->proberesp_ies, b->proberesp_ies_len); | |
617 | print_hex_dump_bytes("ASSOC IE ", DUMP_PREFIX_OFFSET, | |
618 | b->assocresp_ies, b->assocresp_ies_len); | |
619 | } | |
620 | ||
621 | static void wil_print_crypto(struct wil6210_priv *wil, | |
622 | struct cfg80211_crypto_settings *c) | |
623 | { | |
624 | wil_dbg_misc(wil, "WPA versions: 0x%08x cipher group 0x%08x\n", | |
625 | c->wpa_versions, c->cipher_group); | |
626 | wil_dbg_misc(wil, "Pairwise ciphers [%d]\n", c->n_ciphers_pairwise); | |
627 | wil_dbg_misc(wil, "AKM suites [%d]\n", c->n_akm_suites); | |
628 | wil_dbg_misc(wil, "Control port : %d, eth_type 0x%04x no_encrypt %d\n", | |
629 | c->control_port, be16_to_cpu(c->control_port_ethertype), | |
630 | c->control_port_no_encrypt); | |
631 | } | |
632 | ||
92646c9f VK |
633 | static int wil_fix_bcon(struct wil6210_priv *wil, |
634 | struct cfg80211_beacon_data *bcon) | |
635 | { | |
636 | struct ieee80211_mgmt *f = (struct ieee80211_mgmt *)bcon->probe_resp; | |
637 | size_t hlen = offsetof(struct ieee80211_mgmt, u.probe_resp.variable); | |
638 | int rc = 0; | |
639 | ||
640 | if (bcon->probe_resp_len <= hlen) | |
641 | return 0; | |
642 | ||
643 | if (!bcon->proberesp_ies) { | |
644 | bcon->proberesp_ies = f->u.probe_resp.variable; | |
645 | bcon->proberesp_ies_len = bcon->probe_resp_len - hlen; | |
646 | rc = 1; | |
647 | } | |
648 | if (!bcon->assocresp_ies) { | |
649 | bcon->assocresp_ies = f->u.probe_resp.variable; | |
650 | bcon->assocresp_ies_len = bcon->probe_resp_len - hlen; | |
651 | rc = 1; | |
652 | } | |
653 | ||
654 | return rc; | |
655 | } | |
656 | ||
1bd922fc VK |
657 | static int wil_cfg80211_change_beacon(struct wiphy *wiphy, |
658 | struct net_device *ndev, | |
659 | struct cfg80211_beacon_data *bcon) | |
660 | { | |
661 | struct wil6210_priv *wil = wiphy_to_wil(wiphy); | |
662 | int rc; | |
663 | ||
664 | wil_dbg_misc(wil, "%s()\n", __func__); | |
665 | ||
666 | if (wil_fix_bcon(wil, bcon)) { | |
667 | wil_dbg_misc(wil, "Fixed bcon\n"); | |
668 | wil_print_bcon_data(bcon); | |
669 | } | |
670 | ||
671 | /* FW do not form regular beacon, so bcon IE's are not set | |
672 | * For the DMG bcon, when it will be supported, bcon IE's will | |
673 | * be reused; add something like: | |
674 | * wmi_set_ie(wil, WMI_FRAME_BEACON, bcon->beacon_ies_len, | |
675 | * bcon->beacon_ies); | |
676 | */ | |
677 | rc = wmi_set_ie(wil, WMI_FRAME_PROBE_RESP, | |
678 | bcon->proberesp_ies_len, | |
679 | bcon->proberesp_ies); | |
680 | if (rc) { | |
681 | wil_err(wil, "set_ie(PROBE_RESP) failed\n"); | |
682 | return rc; | |
683 | } | |
684 | ||
685 | rc = wmi_set_ie(wil, WMI_FRAME_ASSOC_RESP, | |
686 | bcon->assocresp_ies_len, | |
687 | bcon->assocresp_ies); | |
688 | if (rc) { | |
689 | wil_err(wil, "set_ie(ASSOC_RESP) failed\n"); | |
690 | return rc; | |
691 | } | |
692 | ||
693 | return 0; | |
694 | } | |
695 | ||
2be7d22f VK |
696 | static int wil_cfg80211_start_ap(struct wiphy *wiphy, |
697 | struct net_device *ndev, | |
698 | struct cfg80211_ap_settings *info) | |
699 | { | |
700 | int rc = 0; | |
701 | struct wil6210_priv *wil = wiphy_to_wil(wiphy); | |
702 | struct wireless_dev *wdev = ndev->ieee80211_ptr; | |
703 | struct ieee80211_channel *channel = info->chandef.chan; | |
704 | struct cfg80211_beacon_data *bcon = &info->beacon; | |
ca959773 | 705 | struct cfg80211_crypto_settings *crypto = &info->crypto; |
2be7d22f VK |
706 | u8 wmi_nettype = wil_iftype_nl2wmi(wdev->iftype); |
707 | ||
ca959773 VK |
708 | wil_dbg_misc(wil, "%s()\n", __func__); |
709 | ||
2be7d22f VK |
710 | if (!channel) { |
711 | wil_err(wil, "AP: No channel???\n"); | |
712 | return -EINVAL; | |
713 | } | |
714 | ||
7743882d | 715 | wil_dbg_misc(wil, "AP on Channel %d %d MHz, %s\n", channel->hw_value, |
2057ebb2 | 716 | channel->center_freq, info->privacy ? "secure" : "open"); |
ca959773 VK |
717 | wil_dbg_misc(wil, "Privacy: %d auth_type %d\n", |
718 | info->privacy, info->auth_type); | |
719 | wil_dbg_misc(wil, "BI %d DTIM %d\n", info->beacon_interval, | |
720 | info->dtim_period); | |
2be7d22f VK |
721 | print_hex_dump_bytes("SSID ", DUMP_PREFIX_OFFSET, |
722 | info->ssid, info->ssid_len); | |
ca959773 VK |
723 | wil_print_bcon_data(bcon); |
724 | wil_print_crypto(wil, crypto); | |
2be7d22f | 725 | |
ca959773 | 726 | if (wil_fix_bcon(wil, bcon)) { |
92646c9f | 727 | wil_dbg_misc(wil, "Fixed bcon\n"); |
ca959773 VK |
728 | wil_print_bcon_data(bcon); |
729 | } | |
92646c9f | 730 | |
9c3bde56 VK |
731 | mutex_lock(&wil->mutex); |
732 | ||
73d839ae VK |
733 | __wil_down(wil); |
734 | rc = __wil_up(wil); | |
e31b2562 | 735 | if (rc) |
9c3bde56 | 736 | goto out; |
e31b2562 | 737 | |
2be7d22f VK |
738 | rc = wmi_set_ssid(wil, info->ssid_len, info->ssid); |
739 | if (rc) | |
9c3bde56 | 740 | goto out; |
2be7d22f | 741 | |
2be7d22f VK |
742 | /* IE's */ |
743 | /* bcon 'head IE's are not relevant for 60g band */ | |
b1defa4d VK |
744 | /* |
745 | * FW do not form regular beacon, so bcon IE's are not set | |
746 | * For the DMG bcon, when it will be supported, bcon IE's will | |
747 | * be reused; add something like: | |
748 | * wmi_set_ie(wil, WMI_FRAME_BEACON, bcon->beacon_ies_len, | |
749 | * bcon->beacon_ies); | |
750 | */ | |
2be7d22f VK |
751 | wmi_set_ie(wil, WMI_FRAME_PROBE_RESP, bcon->proberesp_ies_len, |
752 | bcon->proberesp_ies); | |
753 | wmi_set_ie(wil, WMI_FRAME_ASSOC_RESP, bcon->assocresp_ies_len, | |
754 | bcon->assocresp_ies); | |
755 | ||
756 | wil->secure_pcp = info->privacy; | |
757 | ||
b8023177 VK |
758 | rc = wmi_pcp_start(wil, info->beacon_interval, wmi_nettype, |
759 | channel->hw_value); | |
2be7d22f | 760 | if (rc) |
9c3bde56 | 761 | goto out; |
2be7d22f | 762 | |
2be7d22f VK |
763 | netif_carrier_on(ndev); |
764 | ||
9c3bde56 VK |
765 | out: |
766 | mutex_unlock(&wil->mutex); | |
2be7d22f VK |
767 | return rc; |
768 | } | |
769 | ||
770 | static int wil_cfg80211_stop_ap(struct wiphy *wiphy, | |
771 | struct net_device *ndev) | |
772 | { | |
73d839ae | 773 | int rc, rc1; |
2be7d22f | 774 | struct wil6210_priv *wil = wiphy_to_wil(wiphy); |
2be7d22f | 775 | |
ca959773 VK |
776 | wil_dbg_misc(wil, "%s()\n", __func__); |
777 | ||
9c3bde56 VK |
778 | mutex_lock(&wil->mutex); |
779 | ||
b8023177 | 780 | rc = wmi_pcp_stop(wil); |
2be7d22f | 781 | |
73d839ae VK |
782 | __wil_down(wil); |
783 | rc1 = __wil_up(wil); | |
784 | ||
9c3bde56 | 785 | mutex_unlock(&wil->mutex); |
73d839ae VK |
786 | |
787 | return min(rc, rc1); | |
2be7d22f VK |
788 | } |
789 | ||
4d55a0a1 | 790 | static int wil_cfg80211_del_station(struct wiphy *wiphy, |
3b3a0162 | 791 | struct net_device *dev, const u8 *mac) |
4d55a0a1 VK |
792 | { |
793 | struct wil6210_priv *wil = wiphy_to_wil(wiphy); | |
097638a0 VK |
794 | |
795 | mutex_lock(&wil->mutex); | |
4d55a0a1 | 796 | wil6210_disconnect(wil, mac); |
097638a0 VK |
797 | mutex_unlock(&wil->mutex); |
798 | ||
4d55a0a1 VK |
799 | return 0; |
800 | } | |
801 | ||
2be7d22f VK |
802 | static struct cfg80211_ops wil_cfg80211_ops = { |
803 | .scan = wil_cfg80211_scan, | |
804 | .connect = wil_cfg80211_connect, | |
805 | .disconnect = wil_cfg80211_disconnect, | |
806 | .change_virtual_intf = wil_cfg80211_change_iface, | |
807 | .get_station = wil_cfg80211_get_station, | |
ef28afdb | 808 | .dump_station = wil_cfg80211_dump_station, |
1647f12f VK |
809 | .remain_on_channel = wil_remain_on_channel, |
810 | .cancel_remain_on_channel = wil_cancel_remain_on_channel, | |
811 | .mgmt_tx = wil_cfg80211_mgmt_tx, | |
2be7d22f VK |
812 | .set_monitor_channel = wil_cfg80211_set_channel, |
813 | .add_key = wil_cfg80211_add_key, | |
814 | .del_key = wil_cfg80211_del_key, | |
815 | .set_default_key = wil_cfg80211_set_default_key, | |
816 | /* AP mode */ | |
1bd922fc | 817 | .change_beacon = wil_cfg80211_change_beacon, |
2be7d22f VK |
818 | .start_ap = wil_cfg80211_start_ap, |
819 | .stop_ap = wil_cfg80211_stop_ap, | |
4d55a0a1 | 820 | .del_station = wil_cfg80211_del_station, |
2be7d22f VK |
821 | }; |
822 | ||
823 | static void wil_wiphy_init(struct wiphy *wiphy) | |
824 | { | |
825 | /* TODO: set real value */ | |
826 | wiphy->max_scan_ssids = 10; | |
77c91295 | 827 | wiphy->max_scan_ie_len = WMI_MAX_IE_LEN; |
2be7d22f VK |
828 | wiphy->max_num_pmkids = 0 /* TODO: */; |
829 | wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | | |
830 | BIT(NL80211_IFTYPE_AP) | | |
831 | BIT(NL80211_IFTYPE_MONITOR); | |
832 | /* TODO: enable P2P when integrated with supplicant: | |
833 | * BIT(NL80211_IFTYPE_P2P_CLIENT) | BIT(NL80211_IFTYPE_P2P_GO) | |
834 | */ | |
835 | wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME | | |
836 | WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD; | |
9cf10d62 VK |
837 | dev_dbg(wiphy_dev(wiphy), "%s : flags = 0x%08x\n", |
838 | __func__, wiphy->flags); | |
2be7d22f VK |
839 | wiphy->probe_resp_offload = |
840 | NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS | | |
841 | NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 | | |
842 | NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P; | |
843 | ||
844 | wiphy->bands[IEEE80211_BAND_60GHZ] = &wil_band_60ghz; | |
845 | ||
846 | /* TODO: figure this out */ | |
b8b33a3a | 847 | wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC; |
2be7d22f VK |
848 | |
849 | wiphy->cipher_suites = wil_cipher_suites; | |
850 | wiphy->n_cipher_suites = ARRAY_SIZE(wil_cipher_suites); | |
851 | wiphy->mgmt_stypes = wil_mgmt_stypes; | |
852 | } | |
853 | ||
854 | struct wireless_dev *wil_cfg80211_init(struct device *dev) | |
855 | { | |
856 | int rc = 0; | |
857 | struct wireless_dev *wdev; | |
858 | ||
9cf10d62 VK |
859 | dev_dbg(dev, "%s()\n", __func__); |
860 | ||
8fe59627 | 861 | wdev = kzalloc(sizeof(*wdev), GFP_KERNEL); |
2be7d22f VK |
862 | if (!wdev) |
863 | return ERR_PTR(-ENOMEM); | |
864 | ||
865 | wdev->wiphy = wiphy_new(&wil_cfg80211_ops, | |
866 | sizeof(struct wil6210_priv)); | |
867 | if (!wdev->wiphy) { | |
868 | rc = -ENOMEM; | |
869 | goto out; | |
870 | } | |
871 | ||
872 | set_wiphy_dev(wdev->wiphy, dev); | |
873 | wil_wiphy_init(wdev->wiphy); | |
874 | ||
875 | rc = wiphy_register(wdev->wiphy); | |
876 | if (rc < 0) | |
877 | goto out_failed_reg; | |
878 | ||
879 | return wdev; | |
880 | ||
881 | out_failed_reg: | |
882 | wiphy_free(wdev->wiphy); | |
883 | out: | |
884 | kfree(wdev); | |
885 | ||
886 | return ERR_PTR(rc); | |
887 | } | |
888 | ||
889 | void wil_wdev_free(struct wil6210_priv *wil) | |
890 | { | |
891 | struct wireless_dev *wdev = wil_to_wdev(wil); | |
892 | ||
9cf10d62 VK |
893 | dev_dbg(wil_to_dev(wil), "%s()\n", __func__); |
894 | ||
2be7d22f VK |
895 | if (!wdev) |
896 | return; | |
897 | ||
898 | wiphy_unregister(wdev->wiphy); | |
899 | wiphy_free(wdev->wiphy); | |
900 | kfree(wdev); | |
901 | } |