Commit | Line | Data |
---|---|---|
2be7d22f | 1 | /* |
32a20d46 | 2 | * Copyright (c) 2012-2015 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 | ||
30 | static 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 | ||
37 | static 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 | ||
53 | static const struct ieee80211_txrx_stypes | |
54 | wil_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 | ||
81 | static const u32 wil_cipher_suites[] = { | |
82 | WLAN_CIPHER_SUITE_GCMP, | |
83 | }; | |
84 | ||
85 | int 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 |
108 | int 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 | ||
174 | static 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 | */ | |
195 | static 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 | ||
210 | static 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 | ||
229 | static 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 | ||
259 | static 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 | ||
339 | rc = wmi_set_ie(wil, WMI_FRAME_PROBE_REQ, request->ie_len, | |
340 | request->ie); | |
341 | if (rc) { | |
342 | wil_err(wil, "Aborting scan, set_ie failed: %d\n", rc); | |
343 | goto out; | |
344 | } | |
345 | ||
ed6f9dc6 | 346 | rc = wmi_send(wil, WMI_START_SCAN_CMDID, &cmd, sizeof(cmd.cmd) + |
2be7d22f | 347 | cmd.cmd.num_channels * sizeof(cmd.cmd.channel_list[0])); |
ed6f9dc6 | 348 | |
77c91295 | 349 | out: |
a2142086 VK |
350 | if (rc) { |
351 | del_timer_sync(&wil->scan_timer); | |
ed6f9dc6 | 352 | wil->scan_request = NULL; |
a2142086 | 353 | } |
ed6f9dc6 VK |
354 | |
355 | return rc; | |
2be7d22f VK |
356 | } |
357 | ||
feeac225 VK |
358 | static void wil_print_crypto(struct wil6210_priv *wil, |
359 | struct cfg80211_crypto_settings *c) | |
360 | { | |
361 | int i, n; | |
362 | ||
363 | wil_dbg_misc(wil, "WPA versions: 0x%08x cipher group 0x%08x\n", | |
364 | c->wpa_versions, c->cipher_group); | |
365 | wil_dbg_misc(wil, "Pairwise ciphers [%d] {\n", c->n_ciphers_pairwise); | |
366 | n = min_t(int, c->n_ciphers_pairwise, ARRAY_SIZE(c->ciphers_pairwise)); | |
367 | for (i = 0; i < n; i++) | |
368 | wil_dbg_misc(wil, " [%d] = 0x%08x\n", i, | |
369 | c->ciphers_pairwise[i]); | |
370 | wil_dbg_misc(wil, "}\n"); | |
371 | wil_dbg_misc(wil, "AKM suites [%d] {\n", c->n_akm_suites); | |
372 | n = min_t(int, c->n_akm_suites, ARRAY_SIZE(c->akm_suites)); | |
373 | for (i = 0; i < n; i++) | |
374 | wil_dbg_misc(wil, " [%d] = 0x%08x\n", i, | |
375 | c->akm_suites[i]); | |
376 | wil_dbg_misc(wil, "}\n"); | |
377 | wil_dbg_misc(wil, "Control port : %d, eth_type 0x%04x no_encrypt %d\n", | |
378 | c->control_port, be16_to_cpu(c->control_port_ethertype), | |
379 | c->control_port_no_encrypt); | |
380 | } | |
381 | ||
8ca26163 VK |
382 | static void wil_print_connect_params(struct wil6210_priv *wil, |
383 | struct cfg80211_connect_params *sme) | |
384 | { | |
385 | wil_info(wil, "Connecting to:\n"); | |
386 | if (sme->channel) { | |
387 | wil_info(wil, " Channel: %d freq %d\n", | |
388 | sme->channel->hw_value, sme->channel->center_freq); | |
389 | } | |
390 | if (sme->bssid) | |
391 | wil_info(wil, " BSSID: %pM\n", sme->bssid); | |
392 | if (sme->ssid) | |
393 | print_hex_dump(KERN_INFO, " SSID: ", DUMP_PREFIX_OFFSET, | |
394 | 16, 1, sme->ssid, sme->ssid_len, true); | |
395 | wil_info(wil, " Privacy: %s\n", sme->privacy ? "secure" : "open"); | |
feeac225 | 396 | wil_print_crypto(wil, &sme->crypto); |
8ca26163 VK |
397 | } |
398 | ||
2be7d22f VK |
399 | static int wil_cfg80211_connect(struct wiphy *wiphy, |
400 | struct net_device *ndev, | |
401 | struct cfg80211_connect_params *sme) | |
402 | { | |
403 | struct wil6210_priv *wil = wiphy_to_wil(wiphy); | |
404 | struct cfg80211_bss *bss; | |
405 | struct wmi_connect_cmd conn; | |
406 | const u8 *ssid_eid; | |
407 | const u8 *rsn_eid; | |
408 | int ch; | |
409 | int rc = 0; | |
410 | ||
344a7024 VK |
411 | wil_print_connect_params(wil, sme); |
412 | ||
9419b6a2 VK |
413 | if (test_bit(wil_status_fwconnecting, wil->status) || |
414 | test_bit(wil_status_fwconnected, wil->status)) | |
4cd9e837 VK |
415 | return -EALREADY; |
416 | ||
344a7024 VK |
417 | if (sme->ie_len > WMI_MAX_IE_LEN) { |
418 | wil_err(wil, "IE too large (%td bytes)\n", sme->ie_len); | |
419 | return -ERANGE; | |
420 | } | |
421 | ||
422 | rsn_eid = sme->ie ? | |
423 | cfg80211_find_ie(WLAN_EID_RSN, sme->ie, sme->ie_len) : | |
424 | NULL; | |
27aa6b71 VK |
425 | if (sme->privacy && !rsn_eid) |
426 | wil_info(wil, "WSC connection\n"); | |
8ca26163 | 427 | |
2be7d22f VK |
428 | bss = cfg80211_get_bss(wiphy, sme->channel, sme->bssid, |
429 | sme->ssid, sme->ssid_len, | |
6eb18137 | 430 | IEEE80211_BSS_TYPE_ESS, IEEE80211_PRIVACY_ANY); |
2be7d22f VK |
431 | if (!bss) { |
432 | wil_err(wil, "Unable to find BSS\n"); | |
433 | return -ENOENT; | |
434 | } | |
435 | ||
436 | ssid_eid = ieee80211_bss_get_ie(bss, WLAN_EID_SSID); | |
437 | if (!ssid_eid) { | |
438 | wil_err(wil, "No SSID\n"); | |
439 | rc = -ENOENT; | |
440 | goto out; | |
441 | } | |
344a7024 | 442 | wil->privacy = sme->privacy; |
2be7d22f | 443 | |
344a7024 | 444 | if (wil->privacy) { |
230d8442 VK |
445 | /* For secure assoc, remove old keys */ |
446 | rc = wmi_del_cipher_key(wil, 0, bss->bssid, | |
447 | WMI_KEY_USE_PAIRWISE); | |
2be7d22f | 448 | if (rc) { |
230d8442 VK |
449 | wil_err(wil, "WMI_DELETE_CIPHER_KEY_CMD(PTK) failed\n"); |
450 | goto out; | |
451 | } | |
452 | rc = wmi_del_cipher_key(wil, 0, bss->bssid, | |
453 | WMI_KEY_USE_RX_GROUP); | |
454 | if (rc) { | |
455 | wil_err(wil, "WMI_DELETE_CIPHER_KEY_CMD(GTK) failed\n"); | |
2be7d22f VK |
456 | goto out; |
457 | } | |
ac4acdb7 VK |
458 | } |
459 | ||
460 | /* WMI_SET_APPIE_CMD. ie may contain rsn info as well as other info | |
461 | * elements. Send it also in case it's empty, to erase previously set | |
462 | * ies in FW. | |
463 | */ | |
464 | rc = wmi_set_ie(wil, WMI_FRAME_ASSOC_REQ, sme->ie_len, sme->ie); | |
465 | if (rc) { | |
466 | wil_err(wil, "WMI_SET_APPIE_CMD failed\n"); | |
467 | goto out; | |
2be7d22f VK |
468 | } |
469 | ||
470 | /* WMI_CONNECT_CMD */ | |
471 | memset(&conn, 0, sizeof(conn)); | |
acc9780d | 472 | switch (bss->capability & WLAN_CAPABILITY_DMG_TYPE_MASK) { |
2be7d22f VK |
473 | case WLAN_CAPABILITY_DMG_TYPE_AP: |
474 | conn.network_type = WMI_NETTYPE_INFRA; | |
475 | break; | |
476 | case WLAN_CAPABILITY_DMG_TYPE_PBSS: | |
477 | conn.network_type = WMI_NETTYPE_P2P; | |
478 | break; | |
479 | default: | |
480 | wil_err(wil, "Unsupported BSS type, capability= 0x%04x\n", | |
481 | bss->capability); | |
482 | goto out; | |
483 | } | |
344a7024 | 484 | if (wil->privacy) { |
27aa6b71 VK |
485 | if (rsn_eid) { /* regular secure connection */ |
486 | conn.dot11_auth_mode = WMI_AUTH11_SHARED; | |
487 | conn.auth_mode = WMI_AUTH_WPA2_PSK; | |
488 | conn.pairwise_crypto_type = WMI_CRYPT_AES_GCMP; | |
489 | conn.pairwise_crypto_len = 16; | |
490 | conn.group_crypto_type = WMI_CRYPT_AES_GCMP; | |
491 | conn.group_crypto_len = 16; | |
492 | } else { /* WSC */ | |
493 | conn.dot11_auth_mode = WMI_AUTH11_WSC; | |
494 | conn.auth_mode = WMI_AUTH_NONE; | |
495 | } | |
496 | } else { /* insecure connection */ | |
2be7d22f VK |
497 | conn.dot11_auth_mode = WMI_AUTH11_OPEN; |
498 | conn.auth_mode = WMI_AUTH_NONE; | |
499 | } | |
500 | ||
501 | conn.ssid_len = min_t(u8, ssid_eid[1], 32); | |
502 | memcpy(conn.ssid, ssid_eid+2, conn.ssid_len); | |
503 | ||
504 | ch = bss->channel->hw_value; | |
505 | if (ch == 0) { | |
506 | wil_err(wil, "BSS at unknown frequency %dMhz\n", | |
507 | bss->channel->center_freq); | |
508 | rc = -EOPNOTSUPP; | |
509 | goto out; | |
510 | } | |
511 | conn.channel = ch - 1; | |
512 | ||
a82553bb VK |
513 | ether_addr_copy(conn.bssid, bss->bssid); |
514 | ether_addr_copy(conn.dst_mac, bss->bssid); | |
e83eb2fc | 515 | |
9419b6a2 | 516 | set_bit(wil_status_fwconnecting, wil->status); |
2be7d22f VK |
517 | |
518 | rc = wmi_send(wil, WMI_CONNECT_CMDID, &conn, sizeof(conn)); | |
519 | if (rc == 0) { | |
c5e96c91 | 520 | netif_carrier_on(ndev); |
2be7d22f VK |
521 | /* Connect can take lots of time */ |
522 | mod_timer(&wil->connect_timer, | |
523 | jiffies + msecs_to_jiffies(2000)); | |
b338f74e | 524 | } else { |
9419b6a2 | 525 | clear_bit(wil_status_fwconnecting, wil->status); |
2be7d22f VK |
526 | } |
527 | ||
528 | out: | |
5b112d3d | 529 | cfg80211_put_bss(wiphy, bss); |
2be7d22f VK |
530 | |
531 | return rc; | |
532 | } | |
533 | ||
534 | static int wil_cfg80211_disconnect(struct wiphy *wiphy, | |
535 | struct net_device *ndev, | |
536 | u16 reason_code) | |
537 | { | |
538 | int rc; | |
539 | struct wil6210_priv *wil = wiphy_to_wil(wiphy); | |
540 | ||
de9084ef VK |
541 | wil_dbg_misc(wil, "%s(reason=%d)\n", __func__, reason_code); |
542 | ||
2be7d22f VK |
543 | rc = wmi_send(wil, WMI_DISCONNECT_CMDID, NULL, 0); |
544 | ||
545 | return rc; | |
546 | } | |
547 | ||
0b39aaf2 VK |
548 | int wil_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev, |
549 | struct cfg80211_mgmt_tx_params *params, | |
550 | u64 *cookie) | |
1647f12f VK |
551 | { |
552 | const u8 *buf = params->buf; | |
553 | size_t len = params->len; | |
554 | struct wil6210_priv *wil = wiphy_to_wil(wiphy); | |
555 | int rc; | |
304464f4 | 556 | bool tx_status = false; |
1647f12f VK |
557 | struct ieee80211_mgmt *mgmt_frame = (void *)buf; |
558 | struct wmi_sw_tx_req_cmd *cmd; | |
559 | struct { | |
560 | struct wil6210_mbox_hdr_wmi wmi; | |
561 | struct wmi_sw_tx_complete_event evt; | |
562 | } __packed evt; | |
563 | ||
564 | cmd = kmalloc(sizeof(*cmd) + len, GFP_KERNEL); | |
304464f4 VK |
565 | if (!cmd) { |
566 | rc = -ENOMEM; | |
567 | goto out; | |
568 | } | |
1647f12f VK |
569 | |
570 | memcpy(cmd->dst_mac, mgmt_frame->da, WMI_MAC_LEN); | |
571 | cmd->len = cpu_to_le16(len); | |
572 | memcpy(cmd->payload, buf, len); | |
573 | ||
574 | rc = wmi_call(wil, WMI_SW_TX_REQ_CMDID, cmd, sizeof(*cmd) + len, | |
575 | WMI_SW_TX_COMPLETE_EVENTID, &evt, sizeof(evt), 2000); | |
576 | if (rc == 0) | |
304464f4 | 577 | tx_status = !evt.evt.status; |
1647f12f VK |
578 | |
579 | kfree(cmd); | |
304464f4 VK |
580 | out: |
581 | cfg80211_mgmt_tx_status(wdev, cookie ? *cookie : 0, buf, len, | |
582 | tx_status, GFP_KERNEL); | |
1647f12f VK |
583 | return rc; |
584 | } | |
585 | ||
2be7d22f VK |
586 | static int wil_cfg80211_set_channel(struct wiphy *wiphy, |
587 | struct cfg80211_chan_def *chandef) | |
588 | { | |
589 | struct wil6210_priv *wil = wiphy_to_wil(wiphy); | |
590 | struct wireless_dev *wdev = wil->wdev; | |
591 | ||
592 | wdev->preset_chandef = *chandef; | |
593 | ||
594 | return 0; | |
595 | } | |
596 | ||
230d8442 VK |
597 | static enum wmi_key_usage wil_detect_key_usage(struct wil6210_priv *wil, |
598 | bool pairwise) | |
599 | { | |
600 | struct wireless_dev *wdev = wil->wdev; | |
601 | enum wmi_key_usage rc; | |
602 | static const char * const key_usage_str[] = { | |
603 | [WMI_KEY_USE_PAIRWISE] = "WMI_KEY_USE_PAIRWISE", | |
604 | [WMI_KEY_USE_RX_GROUP] = "WMI_KEY_USE_RX_GROUP", | |
605 | [WMI_KEY_USE_TX_GROUP] = "WMI_KEY_USE_TX_GROUP", | |
606 | }; | |
607 | ||
608 | if (pairwise) { | |
609 | rc = WMI_KEY_USE_PAIRWISE; | |
610 | } else { | |
611 | switch (wdev->iftype) { | |
612 | case NL80211_IFTYPE_STATION: | |
613 | rc = WMI_KEY_USE_RX_GROUP; | |
614 | break; | |
615 | case NL80211_IFTYPE_AP: | |
616 | rc = WMI_KEY_USE_TX_GROUP; | |
617 | break; | |
618 | default: | |
619 | /* TODO: Rx GTK or Tx GTK? */ | |
620 | wil_err(wil, "Can't determine GTK type\n"); | |
621 | rc = WMI_KEY_USE_RX_GROUP; | |
622 | break; | |
623 | } | |
624 | } | |
625 | wil_dbg_misc(wil, "%s() -> %s\n", __func__, key_usage_str[rc]); | |
626 | ||
627 | return rc; | |
628 | } | |
629 | ||
2be7d22f VK |
630 | static int wil_cfg80211_add_key(struct wiphy *wiphy, |
631 | struct net_device *ndev, | |
632 | u8 key_index, bool pairwise, | |
633 | const u8 *mac_addr, | |
634 | struct key_params *params) | |
635 | { | |
636 | struct wil6210_priv *wil = wiphy_to_wil(wiphy); | |
230d8442 | 637 | enum wmi_key_usage key_usage = wil_detect_key_usage(wil, pairwise); |
2be7d22f | 638 | |
db8adcbf VK |
639 | wil_dbg_misc(wil, "%s(%pM[%d] %s)\n", __func__, mac_addr, key_index, |
640 | pairwise ? "PTK" : "GTK"); | |
641 | ||
230d8442 VK |
642 | return wmi_add_cipher_key(wil, key_index, mac_addr, params->key_len, |
643 | params->key, key_usage); | |
2be7d22f VK |
644 | } |
645 | ||
646 | static int wil_cfg80211_del_key(struct wiphy *wiphy, | |
647 | struct net_device *ndev, | |
648 | u8 key_index, bool pairwise, | |
649 | const u8 *mac_addr) | |
650 | { | |
651 | struct wil6210_priv *wil = wiphy_to_wil(wiphy); | |
230d8442 | 652 | enum wmi_key_usage key_usage = wil_detect_key_usage(wil, pairwise); |
2be7d22f | 653 | |
db8adcbf VK |
654 | wil_dbg_misc(wil, "%s(%pM[%d] %s)\n", __func__, mac_addr, key_index, |
655 | pairwise ? "PTK" : "GTK"); | |
656 | ||
230d8442 | 657 | return wmi_del_cipher_key(wil, key_index, mac_addr, key_usage); |
2be7d22f VK |
658 | } |
659 | ||
660 | /* Need to be present or wiphy_new() will WARN */ | |
661 | static int wil_cfg80211_set_default_key(struct wiphy *wiphy, | |
662 | struct net_device *ndev, | |
663 | u8 key_index, bool unicast, | |
664 | bool multicast) | |
665 | { | |
666 | return 0; | |
667 | } | |
668 | ||
1647f12f VK |
669 | static int wil_remain_on_channel(struct wiphy *wiphy, |
670 | struct wireless_dev *wdev, | |
671 | struct ieee80211_channel *chan, | |
672 | unsigned int duration, | |
673 | u64 *cookie) | |
674 | { | |
675 | struct wil6210_priv *wil = wiphy_to_wil(wiphy); | |
676 | int rc; | |
677 | ||
678 | /* TODO: handle duration */ | |
679 | wil_info(wil, "%s(%d, %d ms)\n", __func__, chan->center_freq, duration); | |
680 | ||
681 | rc = wmi_set_channel(wil, chan->hw_value); | |
682 | if (rc) | |
683 | return rc; | |
684 | ||
685 | rc = wmi_rxon(wil, true); | |
686 | ||
687 | return rc; | |
688 | } | |
689 | ||
690 | static int wil_cancel_remain_on_channel(struct wiphy *wiphy, | |
691 | struct wireless_dev *wdev, | |
692 | u64 cookie) | |
693 | { | |
694 | struct wil6210_priv *wil = wiphy_to_wil(wiphy); | |
695 | int rc; | |
696 | ||
697 | wil_info(wil, "%s()\n", __func__); | |
698 | ||
699 | rc = wmi_rxon(wil, false); | |
700 | ||
701 | return rc; | |
702 | } | |
703 | ||
ca959773 VK |
704 | static void wil_print_bcon_data(struct cfg80211_beacon_data *b) |
705 | { | |
706 | print_hex_dump_bytes("head ", DUMP_PREFIX_OFFSET, | |
707 | b->head, b->head_len); | |
708 | print_hex_dump_bytes("tail ", DUMP_PREFIX_OFFSET, | |
709 | b->tail, b->tail_len); | |
710 | print_hex_dump_bytes("BCON IE ", DUMP_PREFIX_OFFSET, | |
711 | b->beacon_ies, b->beacon_ies_len); | |
712 | print_hex_dump_bytes("PROBE ", DUMP_PREFIX_OFFSET, | |
713 | b->probe_resp, b->probe_resp_len); | |
714 | print_hex_dump_bytes("PROBE IE ", DUMP_PREFIX_OFFSET, | |
715 | b->proberesp_ies, b->proberesp_ies_len); | |
716 | print_hex_dump_bytes("ASSOC IE ", DUMP_PREFIX_OFFSET, | |
717 | b->assocresp_ies, b->assocresp_ies_len); | |
718 | } | |
719 | ||
92646c9f VK |
720 | static int wil_fix_bcon(struct wil6210_priv *wil, |
721 | struct cfg80211_beacon_data *bcon) | |
722 | { | |
723 | struct ieee80211_mgmt *f = (struct ieee80211_mgmt *)bcon->probe_resp; | |
724 | size_t hlen = offsetof(struct ieee80211_mgmt, u.probe_resp.variable); | |
725 | int rc = 0; | |
726 | ||
727 | if (bcon->probe_resp_len <= hlen) | |
728 | return 0; | |
729 | ||
92646c9f VK |
730 | if (!bcon->assocresp_ies) { |
731 | bcon->assocresp_ies = f->u.probe_resp.variable; | |
732 | bcon->assocresp_ies_len = bcon->probe_resp_len - hlen; | |
733 | rc = 1; | |
734 | } | |
735 | ||
736 | return rc; | |
737 | } | |
738 | ||
33190ebf VK |
739 | /* internal functions for device reset and starting AP */ |
740 | static int _wil_cfg80211_set_ies(struct wiphy *wiphy, | |
741 | size_t probe_ies_len, const u8 *probe_ies, | |
742 | size_t assoc_ies_len, const u8 *assoc_ies) | |
743 | ||
744 | { | |
745 | int rc; | |
746 | struct wil6210_priv *wil = wiphy_to_wil(wiphy); | |
747 | ||
748 | /* FW do not form regular beacon, so bcon IE's are not set | |
749 | * For the DMG bcon, when it will be supported, bcon IE's will | |
750 | * be reused; add something like: | |
751 | * wmi_set_ie(wil, WMI_FRAME_BEACON, bcon->beacon_ies_len, | |
752 | * bcon->beacon_ies); | |
753 | */ | |
754 | rc = wmi_set_ie(wil, WMI_FRAME_PROBE_RESP, probe_ies_len, probe_ies); | |
755 | if (rc) { | |
756 | wil_err(wil, "set_ie(PROBE_RESP) failed\n"); | |
757 | return rc; | |
758 | } | |
759 | ||
760 | rc = wmi_set_ie(wil, WMI_FRAME_ASSOC_RESP, assoc_ies_len, assoc_ies); | |
761 | if (rc) { | |
762 | wil_err(wil, "set_ie(ASSOC_RESP) failed\n"); | |
763 | return rc; | |
764 | } | |
765 | ||
766 | return 0; | |
767 | } | |
768 | ||
769 | static int _wil_cfg80211_start_ap(struct wiphy *wiphy, | |
770 | struct net_device *ndev, | |
771 | const u8 *ssid, size_t ssid_len, u32 privacy, | |
772 | int bi, u8 chan, | |
773 | size_t probe_ies_len, const u8 *probe_ies, | |
774 | size_t assoc_ies_len, const u8 *assoc_ies, | |
775 | u8 hidden_ssid) | |
776 | { | |
777 | struct wil6210_priv *wil = wiphy_to_wil(wiphy); | |
778 | int rc; | |
779 | struct wireless_dev *wdev = ndev->ieee80211_ptr; | |
780 | u8 wmi_nettype = wil_iftype_nl2wmi(wdev->iftype); | |
781 | ||
782 | wil_set_recovery_state(wil, fw_recovery_idle); | |
783 | ||
784 | mutex_lock(&wil->mutex); | |
785 | ||
786 | __wil_down(wil); | |
787 | rc = __wil_up(wil); | |
788 | if (rc) | |
789 | goto out; | |
790 | ||
791 | rc = wmi_set_ssid(wil, ssid_len, ssid); | |
792 | if (rc) | |
793 | goto out; | |
794 | ||
795 | rc = _wil_cfg80211_set_ies(wiphy, probe_ies_len, probe_ies, | |
796 | assoc_ies_len, assoc_ies); | |
797 | if (rc) | |
798 | goto out; | |
799 | ||
800 | wil->privacy = privacy; | |
801 | wil->channel = chan; | |
802 | wil->hidden_ssid = hidden_ssid; | |
803 | ||
804 | netif_carrier_on(ndev); | |
805 | ||
806 | rc = wmi_pcp_start(wil, bi, wmi_nettype, chan, hidden_ssid); | |
807 | if (rc) | |
808 | goto err_pcp_start; | |
809 | ||
810 | rc = wil_bcast_init(wil); | |
811 | if (rc) | |
812 | goto err_bcast; | |
813 | ||
814 | goto out; /* success */ | |
815 | ||
816 | err_bcast: | |
817 | wmi_pcp_stop(wil); | |
818 | err_pcp_start: | |
819 | netif_carrier_off(ndev); | |
820 | out: | |
821 | mutex_unlock(&wil->mutex); | |
822 | return rc; | |
823 | } | |
824 | ||
1bd922fc VK |
825 | static int wil_cfg80211_change_beacon(struct wiphy *wiphy, |
826 | struct net_device *ndev, | |
827 | struct cfg80211_beacon_data *bcon) | |
828 | { | |
829 | struct wil6210_priv *wil = wiphy_to_wil(wiphy); | |
1e7e5a0d VK |
830 | struct ieee80211_mgmt *f = (struct ieee80211_mgmt *)bcon->probe_resp; |
831 | size_t hlen = offsetof(struct ieee80211_mgmt, u.probe_resp.variable); | |
832 | const u8 *pr_ies = NULL; | |
833 | size_t pr_ies_len = 0; | |
1bd922fc | 834 | int rc; |
33190ebf | 835 | u32 privacy = 0; |
1bd922fc VK |
836 | |
837 | wil_dbg_misc(wil, "%s()\n", __func__); | |
1e7e5a0d VK |
838 | wil_print_bcon_data(bcon); |
839 | ||
840 | if (bcon->probe_resp_len > hlen) { | |
841 | pr_ies = f->u.probe_resp.variable; | |
842 | pr_ies_len = bcon->probe_resp_len - hlen; | |
843 | } | |
1bd922fc VK |
844 | |
845 | if (wil_fix_bcon(wil, bcon)) { | |
846 | wil_dbg_misc(wil, "Fixed bcon\n"); | |
847 | wil_print_bcon_data(bcon); | |
848 | } | |
849 | ||
33190ebf VK |
850 | if (pr_ies && cfg80211_find_ie(WLAN_EID_RSN, pr_ies, pr_ies_len)) |
851 | privacy = 1; | |
1bd922fc | 852 | |
33190ebf VK |
853 | /* in case privacy has changed, need to restart the AP */ |
854 | if (wil->privacy != privacy) { | |
855 | struct wireless_dev *wdev = ndev->ieee80211_ptr; | |
856 | ||
857 | wil_dbg_misc(wil, "privacy changed %d=>%d. Restarting AP\n", | |
858 | wil->privacy, privacy); | |
859 | ||
860 | rc = _wil_cfg80211_start_ap(wiphy, ndev, wdev->ssid, | |
861 | wdev->ssid_len, privacy, | |
862 | wdev->beacon_interval, | |
863 | wil->channel, pr_ies_len, pr_ies, | |
864 | bcon->assocresp_ies_len, | |
865 | bcon->assocresp_ies, | |
866 | wil->hidden_ssid); | |
867 | } else { | |
868 | rc = _wil_cfg80211_set_ies(wiphy, pr_ies_len, pr_ies, | |
869 | bcon->assocresp_ies_len, | |
870 | bcon->assocresp_ies); | |
1bd922fc VK |
871 | } |
872 | ||
33190ebf | 873 | return rc; |
1bd922fc VK |
874 | } |
875 | ||
2be7d22f VK |
876 | static int wil_cfg80211_start_ap(struct wiphy *wiphy, |
877 | struct net_device *ndev, | |
878 | struct cfg80211_ap_settings *info) | |
879 | { | |
33190ebf | 880 | int rc; |
2be7d22f | 881 | struct wil6210_priv *wil = wiphy_to_wil(wiphy); |
2be7d22f VK |
882 | struct ieee80211_channel *channel = info->chandef.chan; |
883 | struct cfg80211_beacon_data *bcon = &info->beacon; | |
ca959773 | 884 | struct cfg80211_crypto_settings *crypto = &info->crypto; |
1e7e5a0d VK |
885 | struct ieee80211_mgmt *f = (struct ieee80211_mgmt *)bcon->probe_resp; |
886 | size_t hlen = offsetof(struct ieee80211_mgmt, u.probe_resp.variable); | |
887 | const u8 *pr_ies = NULL; | |
888 | size_t pr_ies_len = 0; | |
8e52fe30 | 889 | u8 hidden_ssid; |
2be7d22f | 890 | |
ca959773 VK |
891 | wil_dbg_misc(wil, "%s()\n", __func__); |
892 | ||
2be7d22f VK |
893 | if (!channel) { |
894 | wil_err(wil, "AP: No channel???\n"); | |
895 | return -EINVAL; | |
896 | } | |
897 | ||
33190ebf VK |
898 | switch (info->hidden_ssid) { |
899 | case NL80211_HIDDEN_SSID_NOT_IN_USE: | |
900 | hidden_ssid = WMI_HIDDEN_SSID_DISABLED; | |
901 | break; | |
902 | ||
903 | case NL80211_HIDDEN_SSID_ZERO_LEN: | |
904 | hidden_ssid = WMI_HIDDEN_SSID_SEND_EMPTY; | |
905 | break; | |
906 | ||
907 | case NL80211_HIDDEN_SSID_ZERO_CONTENTS: | |
908 | hidden_ssid = WMI_HIDDEN_SSID_CLEAR; | |
909 | break; | |
910 | ||
911 | default: | |
912 | wil_err(wil, "AP: Invalid hidden SSID %d\n", info->hidden_ssid); | |
913 | return -EOPNOTSUPP; | |
914 | } | |
7743882d | 915 | wil_dbg_misc(wil, "AP on Channel %d %d MHz, %s\n", channel->hw_value, |
2057ebb2 | 916 | channel->center_freq, info->privacy ? "secure" : "open"); |
ca959773 VK |
917 | wil_dbg_misc(wil, "Privacy: %d auth_type %d\n", |
918 | info->privacy, info->auth_type); | |
8e52fe30 HK |
919 | wil_dbg_misc(wil, "Hidden SSID mode: %d\n", |
920 | info->hidden_ssid); | |
ca959773 VK |
921 | wil_dbg_misc(wil, "BI %d DTIM %d\n", info->beacon_interval, |
922 | info->dtim_period); | |
2be7d22f VK |
923 | print_hex_dump_bytes("SSID ", DUMP_PREFIX_OFFSET, |
924 | info->ssid, info->ssid_len); | |
ca959773 VK |
925 | wil_print_bcon_data(bcon); |
926 | wil_print_crypto(wil, crypto); | |
2be7d22f | 927 | |
1e7e5a0d VK |
928 | if (bcon->probe_resp_len > hlen) { |
929 | pr_ies = f->u.probe_resp.variable; | |
930 | pr_ies_len = bcon->probe_resp_len - hlen; | |
931 | } | |
932 | ||
ca959773 | 933 | if (wil_fix_bcon(wil, bcon)) { |
92646c9f | 934 | wil_dbg_misc(wil, "Fixed bcon\n"); |
ca959773 VK |
935 | wil_print_bcon_data(bcon); |
936 | } | |
92646c9f | 937 | |
33190ebf VK |
938 | rc = _wil_cfg80211_start_ap(wiphy, ndev, |
939 | info->ssid, info->ssid_len, info->privacy, | |
940 | info->beacon_interval, channel->hw_value, | |
941 | pr_ies_len, pr_ies, | |
942 | bcon->assocresp_ies_len, | |
943 | bcon->assocresp_ies, | |
944 | hidden_ssid); | |
2be7d22f VK |
945 | |
946 | return rc; | |
947 | } | |
948 | ||
949 | static int wil_cfg80211_stop_ap(struct wiphy *wiphy, | |
950 | struct net_device *ndev) | |
951 | { | |
2be7d22f | 952 | struct wil6210_priv *wil = wiphy_to_wil(wiphy); |
2be7d22f | 953 | |
ca959773 VK |
954 | wil_dbg_misc(wil, "%s()\n", __func__); |
955 | ||
c5e96c91 | 956 | netif_carrier_off(ndev); |
c33407a8 VK |
957 | wil_set_recovery_state(wil, fw_recovery_idle); |
958 | ||
9c3bde56 VK |
959 | mutex_lock(&wil->mutex); |
960 | ||
32a20d46 | 961 | wmi_pcp_stop(wil); |
2be7d22f | 962 | |
73d839ae | 963 | __wil_down(wil); |
73d839ae | 964 | |
9c3bde56 | 965 | mutex_unlock(&wil->mutex); |
73d839ae | 966 | |
32a20d46 | 967 | return 0; |
2be7d22f VK |
968 | } |
969 | ||
4d55a0a1 | 970 | static int wil_cfg80211_del_station(struct wiphy *wiphy, |
89c771e5 JM |
971 | struct net_device *dev, |
972 | struct station_del_parameters *params) | |
4d55a0a1 VK |
973 | { |
974 | struct wil6210_priv *wil = wiphy_to_wil(wiphy); | |
097638a0 | 975 | |
de9084ef VK |
976 | wil_dbg_misc(wil, "%s(%pM, reason=%d)\n", __func__, params->mac, |
977 | params->reason_code); | |
978 | ||
097638a0 | 979 | mutex_lock(&wil->mutex); |
4821e6d8 | 980 | wil6210_disconnect(wil, params->mac, params->reason_code, false); |
097638a0 VK |
981 | mutex_unlock(&wil->mutex); |
982 | ||
4d55a0a1 VK |
983 | return 0; |
984 | } | |
985 | ||
40822a90 VK |
986 | /* probe_client handling */ |
987 | static void wil_probe_client_handle(struct wil6210_priv *wil, | |
988 | struct wil_probe_client_req *req) | |
989 | { | |
990 | struct net_device *ndev = wil_to_ndev(wil); | |
991 | struct wil_sta_info *sta = &wil->sta[req->cid]; | |
992 | /* assume STA is alive if it is still connected, | |
993 | * else FW will disconnect it | |
994 | */ | |
995 | bool alive = (sta->status == wil_sta_connected); | |
996 | ||
997 | cfg80211_probe_status(ndev, sta->addr, req->cookie, alive, GFP_KERNEL); | |
998 | } | |
999 | ||
1000 | static struct list_head *next_probe_client(struct wil6210_priv *wil) | |
1001 | { | |
1002 | struct list_head *ret = NULL; | |
1003 | ||
1004 | mutex_lock(&wil->probe_client_mutex); | |
1005 | ||
1006 | if (!list_empty(&wil->probe_client_pending)) { | |
1007 | ret = wil->probe_client_pending.next; | |
1008 | list_del(ret); | |
1009 | } | |
1010 | ||
1011 | mutex_unlock(&wil->probe_client_mutex); | |
1012 | ||
1013 | return ret; | |
1014 | } | |
1015 | ||
1016 | void wil_probe_client_worker(struct work_struct *work) | |
1017 | { | |
1018 | struct wil6210_priv *wil = container_of(work, struct wil6210_priv, | |
1019 | probe_client_worker); | |
1020 | struct wil_probe_client_req *req; | |
1021 | struct list_head *lh; | |
1022 | ||
1023 | while ((lh = next_probe_client(wil)) != NULL) { | |
1024 | req = list_entry(lh, struct wil_probe_client_req, list); | |
1025 | ||
1026 | wil_probe_client_handle(wil, req); | |
1027 | kfree(req); | |
1028 | } | |
1029 | } | |
1030 | ||
1031 | void wil_probe_client_flush(struct wil6210_priv *wil) | |
1032 | { | |
1033 | struct wil_probe_client_req *req, *t; | |
1034 | ||
1035 | wil_dbg_misc(wil, "%s()\n", __func__); | |
1036 | ||
1037 | mutex_lock(&wil->probe_client_mutex); | |
1038 | ||
1039 | list_for_each_entry_safe(req, t, &wil->probe_client_pending, list) { | |
1040 | list_del(&req->list); | |
1041 | kfree(req); | |
1042 | } | |
1043 | ||
1044 | mutex_unlock(&wil->probe_client_mutex); | |
1045 | } | |
1046 | ||
1047 | static int wil_cfg80211_probe_client(struct wiphy *wiphy, | |
1048 | struct net_device *dev, | |
1049 | const u8 *peer, u64 *cookie) | |
1050 | { | |
1051 | struct wil6210_priv *wil = wiphy_to_wil(wiphy); | |
1052 | struct wil_probe_client_req *req; | |
1053 | int cid = wil_find_cid(wil, peer); | |
1054 | ||
1055 | wil_dbg_misc(wil, "%s(%pM => CID %d)\n", __func__, peer, cid); | |
1056 | ||
1057 | if (cid < 0) | |
1058 | return -ENOLINK; | |
1059 | ||
1060 | req = kzalloc(sizeof(*req), GFP_KERNEL); | |
1061 | if (!req) | |
1062 | return -ENOMEM; | |
1063 | ||
1064 | req->cid = cid; | |
1065 | req->cookie = cid; | |
1066 | ||
1067 | mutex_lock(&wil->probe_client_mutex); | |
1068 | list_add_tail(&req->list, &wil->probe_client_pending); | |
1069 | mutex_unlock(&wil->probe_client_mutex); | |
1070 | ||
1071 | *cookie = req->cookie; | |
1072 | queue_work(wil->wq_service, &wil->probe_client_worker); | |
1073 | return 0; | |
1074 | } | |
1075 | ||
02beaf1a VK |
1076 | static int wil_cfg80211_change_bss(struct wiphy *wiphy, |
1077 | struct net_device *dev, | |
1078 | struct bss_parameters *params) | |
1079 | { | |
1080 | struct wil6210_priv *wil = wiphy_to_wil(wiphy); | |
1081 | ||
1082 | if (params->ap_isolate >= 0) { | |
1083 | wil_dbg_misc(wil, "%s(ap_isolate %d => %d)\n", __func__, | |
1084 | wil->ap_isolate, params->ap_isolate); | |
1085 | wil->ap_isolate = params->ap_isolate; | |
1086 | } | |
1087 | ||
1088 | return 0; | |
1089 | } | |
1090 | ||
2be7d22f VK |
1091 | static struct cfg80211_ops wil_cfg80211_ops = { |
1092 | .scan = wil_cfg80211_scan, | |
1093 | .connect = wil_cfg80211_connect, | |
1094 | .disconnect = wil_cfg80211_disconnect, | |
1095 | .change_virtual_intf = wil_cfg80211_change_iface, | |
1096 | .get_station = wil_cfg80211_get_station, | |
ef28afdb | 1097 | .dump_station = wil_cfg80211_dump_station, |
1647f12f VK |
1098 | .remain_on_channel = wil_remain_on_channel, |
1099 | .cancel_remain_on_channel = wil_cancel_remain_on_channel, | |
1100 | .mgmt_tx = wil_cfg80211_mgmt_tx, | |
2be7d22f VK |
1101 | .set_monitor_channel = wil_cfg80211_set_channel, |
1102 | .add_key = wil_cfg80211_add_key, | |
1103 | .del_key = wil_cfg80211_del_key, | |
1104 | .set_default_key = wil_cfg80211_set_default_key, | |
1105 | /* AP mode */ | |
1bd922fc | 1106 | .change_beacon = wil_cfg80211_change_beacon, |
2be7d22f VK |
1107 | .start_ap = wil_cfg80211_start_ap, |
1108 | .stop_ap = wil_cfg80211_stop_ap, | |
4d55a0a1 | 1109 | .del_station = wil_cfg80211_del_station, |
40822a90 | 1110 | .probe_client = wil_cfg80211_probe_client, |
02beaf1a | 1111 | .change_bss = wil_cfg80211_change_bss, |
2be7d22f VK |
1112 | }; |
1113 | ||
1114 | static void wil_wiphy_init(struct wiphy *wiphy) | |
1115 | { | |
8e52fe30 | 1116 | wiphy->max_scan_ssids = 1; |
77c91295 | 1117 | wiphy->max_scan_ie_len = WMI_MAX_IE_LEN; |
2be7d22f VK |
1118 | wiphy->max_num_pmkids = 0 /* TODO: */; |
1119 | wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | | |
1120 | BIT(NL80211_IFTYPE_AP) | | |
1121 | BIT(NL80211_IFTYPE_MONITOR); | |
1122 | /* TODO: enable P2P when integrated with supplicant: | |
1123 | * BIT(NL80211_IFTYPE_P2P_CLIENT) | BIT(NL80211_IFTYPE_P2P_GO) | |
1124 | */ | |
1125 | wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME | | |
1126 | WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD; | |
9cf10d62 VK |
1127 | dev_dbg(wiphy_dev(wiphy), "%s : flags = 0x%08x\n", |
1128 | __func__, wiphy->flags); | |
2be7d22f VK |
1129 | wiphy->probe_resp_offload = |
1130 | NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS | | |
1131 | NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 | | |
1132 | NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P; | |
1133 | ||
1134 | wiphy->bands[IEEE80211_BAND_60GHZ] = &wil_band_60ghz; | |
1135 | ||
1136 | /* TODO: figure this out */ | |
b8b33a3a | 1137 | wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC; |
2be7d22f VK |
1138 | |
1139 | wiphy->cipher_suites = wil_cipher_suites; | |
1140 | wiphy->n_cipher_suites = ARRAY_SIZE(wil_cipher_suites); | |
1141 | wiphy->mgmt_stypes = wil_mgmt_stypes; | |
713c8a29 | 1142 | wiphy->features |= NL80211_FEATURE_SK_TX_STATUS; |
2be7d22f VK |
1143 | } |
1144 | ||
1145 | struct wireless_dev *wil_cfg80211_init(struct device *dev) | |
1146 | { | |
1147 | int rc = 0; | |
1148 | struct wireless_dev *wdev; | |
1149 | ||
9cf10d62 VK |
1150 | dev_dbg(dev, "%s()\n", __func__); |
1151 | ||
8fe59627 | 1152 | wdev = kzalloc(sizeof(*wdev), GFP_KERNEL); |
2be7d22f VK |
1153 | if (!wdev) |
1154 | return ERR_PTR(-ENOMEM); | |
1155 | ||
1156 | wdev->wiphy = wiphy_new(&wil_cfg80211_ops, | |
1157 | sizeof(struct wil6210_priv)); | |
1158 | if (!wdev->wiphy) { | |
1159 | rc = -ENOMEM; | |
1160 | goto out; | |
1161 | } | |
1162 | ||
1163 | set_wiphy_dev(wdev->wiphy, dev); | |
1164 | wil_wiphy_init(wdev->wiphy); | |
1165 | ||
1166 | rc = wiphy_register(wdev->wiphy); | |
1167 | if (rc < 0) | |
1168 | goto out_failed_reg; | |
1169 | ||
1170 | return wdev; | |
1171 | ||
1172 | out_failed_reg: | |
1173 | wiphy_free(wdev->wiphy); | |
1174 | out: | |
1175 | kfree(wdev); | |
1176 | ||
1177 | return ERR_PTR(rc); | |
1178 | } | |
1179 | ||
1180 | void wil_wdev_free(struct wil6210_priv *wil) | |
1181 | { | |
1182 | struct wireless_dev *wdev = wil_to_wdev(wil); | |
1183 | ||
9cf10d62 VK |
1184 | dev_dbg(wil_to_dev(wil), "%s()\n", __func__); |
1185 | ||
2be7d22f VK |
1186 | if (!wdev) |
1187 | return; | |
1188 | ||
1189 | wiphy_unregister(wdev->wiphy); | |
1190 | wiphy_free(wdev->wiphy); | |
1191 | kfree(wdev); | |
1192 | } |