1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (c) 2012 - 2018 Microchip Technology Inc., and its subsidiaries.
4 * All rights reserved.
5 */
6
7 #include "cfg80211.h"
8
9 #define GO_NEG_REQ 0x00
10 #define GO_NEG_RSP 0x01
11 #define GO_NEG_CONF 0x02
12 #define P2P_INV_REQ 0x03
13 #define P2P_INV_RSP 0x04
14
15 #define WILC_INVALID_CHANNEL 0
16
17 /* Operation at 2.4 GHz with channels 1-13 */
18 #define WILC_WLAN_OPERATING_CLASS_2_4GHZ 0x51
19
20 static const struct ieee80211_txrx_stypes
21 wilc_wfi_cfg80211_mgmt_types[NUM_NL80211_IFTYPES] = {
22 [NL80211_IFTYPE_STATION] = {
23 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
24 BIT(IEEE80211_STYPE_AUTH >> 4),
25 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
26 BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
27 BIT(IEEE80211_STYPE_AUTH >> 4)
28 },
29 [NL80211_IFTYPE_AP] = {
30 .tx = 0xffff,
31 .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
32 BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
33 BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
34 BIT(IEEE80211_STYPE_DISASSOC >> 4) |
35 BIT(IEEE80211_STYPE_AUTH >> 4) |
36 BIT(IEEE80211_STYPE_DEAUTH >> 4) |
37 BIT(IEEE80211_STYPE_ACTION >> 4)
38 },
39 [NL80211_IFTYPE_P2P_CLIENT] = {
40 .tx = 0xffff,
41 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
42 BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
43 BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
44 BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
45 BIT(IEEE80211_STYPE_DISASSOC >> 4) |
46 BIT(IEEE80211_STYPE_AUTH >> 4) |
47 BIT(IEEE80211_STYPE_DEAUTH >> 4)
48 }
49 };
50
51 #ifdef CONFIG_PM
52 static const struct wiphy_wowlan_support wowlan_support = {
53 .flags = WIPHY_WOWLAN_ANY
54 };
55 #endif
56
57 struct wilc_p2p_mgmt_data {
58 int size;
59 u8 *buff;
60 };
61
62 struct wilc_p2p_pub_act_frame {
63 u8 category;
64 u8 action;
65 u8 oui[3];
66 u8 oui_type;
67 u8 oui_subtype;
68 u8 dialog_token;
69 u8 elem[];
70 } __packed;
71
72 struct wilc_vendor_specific_ie {
73 u8 tag_number;
74 u8 tag_len;
75 u8 oui[3];
76 u8 oui_type;
77 u8 attr[];
78 } __packed;
79
80 struct wilc_attr_entry {
81 u8 attr_type;
82 __le16 attr_len;
83 u8 val[];
84 } __packed;
85
86 struct wilc_attr_oper_ch {
87 u8 attr_type;
88 __le16 attr_len;
89 u8 country_code[IEEE80211_COUNTRY_STRING_LEN];
90 u8 op_class;
91 u8 op_channel;
92 } __packed;
93
94 struct wilc_attr_ch_list {
95 u8 attr_type;
96 __le16 attr_len;
97 u8 country_code[IEEE80211_COUNTRY_STRING_LEN];
98 u8 elem[];
99 } __packed;
100
101 struct wilc_ch_list_elem {
102 u8 op_class;
103 u8 no_of_channels;
104 u8 ch_list[];
105 } __packed;
106
cfg_scan_result(enum scan_event scan_event,struct wilc_rcvd_net_info * info,struct wilc_priv * priv)107 static void cfg_scan_result(enum scan_event scan_event,
108 struct wilc_rcvd_net_info *info,
109 struct wilc_priv *priv)
110 {
111 if (!priv->cfg_scanning)
112 return;
113
114 if (scan_event == SCAN_EVENT_NETWORK_FOUND) {
115 s32 freq;
116 struct ieee80211_channel *channel;
117 struct cfg80211_bss *bss;
118 struct wiphy *wiphy = priv->dev->ieee80211_ptr->wiphy;
119
120 if (!wiphy || !info)
121 return;
122
123 freq = ieee80211_channel_to_frequency((s32)info->ch,
124 NL80211_BAND_2GHZ);
125 channel = ieee80211_get_channel(wiphy, freq);
126 if (!channel)
127 return;
128
129 bss = cfg80211_inform_bss_frame(wiphy, channel, info->mgmt,
130 info->frame_len,
131 (s32)info->rssi * 100,
132 GFP_KERNEL);
133 cfg80211_put_bss(wiphy, bss);
134 } else if (scan_event == SCAN_EVENT_DONE) {
135 mutex_lock(&priv->scan_req_lock);
136
137 if (priv->scan_req) {
138 struct cfg80211_scan_info info = {
139 .aborted = false,
140 };
141
142 cfg80211_scan_done(priv->scan_req, &info);
143 priv->cfg_scanning = false;
144 priv->scan_req = NULL;
145 }
146 mutex_unlock(&priv->scan_req_lock);
147 } else if (scan_event == SCAN_EVENT_ABORTED) {
148 mutex_lock(&priv->scan_req_lock);
149
150 if (priv->scan_req) {
151 struct cfg80211_scan_info info = {
152 .aborted = false,
153 };
154
155 cfg80211_scan_done(priv->scan_req, &info);
156 priv->cfg_scanning = false;
157 priv->scan_req = NULL;
158 }
159 mutex_unlock(&priv->scan_req_lock);
160 }
161 }
162
cfg_connect_result(enum conn_event conn_disconn_evt,u8 mac_status,struct wilc_priv * priv)163 static void cfg_connect_result(enum conn_event conn_disconn_evt, u8 mac_status,
164 struct wilc_priv *priv)
165 {
166 struct net_device *dev = priv->dev;
167 struct wilc_vif *vif = netdev_priv(dev);
168 struct wilc *wl = vif->wilc;
169 struct host_if_drv *wfi_drv = priv->hif_drv;
170 struct wilc_conn_info *conn_info = &wfi_drv->conn_info;
171 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
172
173 vif->connecting = false;
174
175 if (conn_disconn_evt == CONN_DISCONN_EVENT_CONN_RESP) {
176 u16 connect_status = conn_info->status;
177
178 if (mac_status == WILC_MAC_STATUS_DISCONNECTED &&
179 connect_status == WLAN_STATUS_SUCCESS) {
180 connect_status = WLAN_STATUS_UNSPECIFIED_FAILURE;
181 wilc_wlan_set_bssid(priv->dev, NULL, WILC_STATION_MODE);
182
183 if (vif->iftype != WILC_CLIENT_MODE)
184 wl->sta_ch = WILC_INVALID_CHANNEL;
185
186 netdev_err(dev, "Unspecified failure\n");
187 }
188
189 if (connect_status == WLAN_STATUS_SUCCESS)
190 memcpy(priv->associated_bss, conn_info->bssid,
191 ETH_ALEN);
192
193 cfg80211_ref_bss(wiphy, vif->bss);
194 cfg80211_connect_bss(dev, conn_info->bssid, vif->bss,
195 conn_info->req_ies,
196 conn_info->req_ies_len,
197 conn_info->resp_ies,
198 conn_info->resp_ies_len,
199 connect_status, GFP_KERNEL,
200 NL80211_TIMEOUT_UNSPECIFIED);
201
202 vif->bss = NULL;
203 } else if (conn_disconn_evt == CONN_DISCONN_EVENT_DISCONN_NOTIF) {
204 u16 reason = 0;
205
206 eth_zero_addr(priv->associated_bss);
207 wilc_wlan_set_bssid(priv->dev, NULL, WILC_STATION_MODE);
208
209 if (vif->iftype != WILC_CLIENT_MODE) {
210 wl->sta_ch = WILC_INVALID_CHANNEL;
211 } else {
212 if (wfi_drv->ifc_up)
213 reason = 3;
214 else
215 reason = 1;
216 }
217
218 cfg80211_disconnected(dev, reason, NULL, 0, false, GFP_KERNEL);
219 }
220 }
221
wilc_get_wl_to_vif(struct wilc * wl)222 struct wilc_vif *wilc_get_wl_to_vif(struct wilc *wl)
223 {
224 struct wilc_vif *vif;
225
226 vif = list_first_or_null_rcu(&wl->vif_list, typeof(*vif), list);
227 if (!vif)
228 return ERR_PTR(-EINVAL);
229
230 return vif;
231 }
232
set_channel(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_chan_def * chandef)233 static int set_channel(struct wiphy *wiphy,
234 struct net_device *dev,
235 struct cfg80211_chan_def *chandef)
236 {
237 struct wilc *wl = wiphy_priv(wiphy);
238 struct wilc_vif *vif;
239 u32 channelnum;
240 int result;
241 int srcu_idx;
242
243 srcu_idx = srcu_read_lock(&wl->srcu);
244 vif = wilc_get_wl_to_vif(wl);
245 if (IS_ERR(vif)) {
246 srcu_read_unlock(&wl->srcu, srcu_idx);
247 return PTR_ERR(vif);
248 }
249
250 channelnum = ieee80211_frequency_to_channel(chandef->chan->center_freq);
251
252 wl->op_ch = channelnum;
253 result = wilc_set_mac_chnl_num(vif, channelnum);
254 if (result)
255 netdev_err(vif->ndev, "Error in setting channel\n");
256
257 srcu_read_unlock(&wl->srcu, srcu_idx);
258 return result;
259 }
260
scan(struct wiphy * wiphy,struct cfg80211_scan_request * request)261 static int scan(struct wiphy *wiphy, struct cfg80211_scan_request *request)
262 {
263 struct wilc_vif *vif = netdev_priv(request->wdev->netdev);
264 struct wilc_priv *priv = &vif->priv;
265 u32 i;
266 int ret = 0;
267 u8 scan_ch_list[WILC_MAX_NUM_SCANNED_CH];
268 u8 scan_type;
269
270 if (request->n_channels > WILC_MAX_NUM_SCANNED_CH) {
271 netdev_err(vif->ndev, "Requested scanned channels over\n");
272 return -EINVAL;
273 }
274
275 priv->scan_req = request;
276 priv->cfg_scanning = true;
277 for (i = 0; i < request->n_channels; i++) {
278 u16 freq = request->channels[i]->center_freq;
279
280 scan_ch_list[i] = ieee80211_frequency_to_channel(freq);
281 }
282
283 if (request->n_ssids)
284 scan_type = WILC_FW_ACTIVE_SCAN;
285 else
286 scan_type = WILC_FW_PASSIVE_SCAN;
287
288 ret = wilc_scan(vif, WILC_FW_USER_SCAN, scan_type,
289 scan_ch_list, cfg_scan_result, request);
290
291 if (ret) {
292 priv->scan_req = NULL;
293 priv->cfg_scanning = false;
294 }
295
296 return ret;
297 }
298
connect(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_connect_params * sme)299 static int connect(struct wiphy *wiphy, struct net_device *dev,
300 struct cfg80211_connect_params *sme)
301 {
302 struct wilc_vif *vif = netdev_priv(dev);
303 struct wilc_priv *priv = &vif->priv;
304 struct host_if_drv *wfi_drv = priv->hif_drv;
305 int ret;
306 u32 i;
307 u8 security = WILC_FW_SEC_NO;
308 enum mfptype mfp_type = WILC_FW_MFP_NONE;
309 enum authtype auth_type = WILC_FW_AUTH_ANY;
310 u32 cipher_group;
311 struct cfg80211_bss *bss;
312 void *join_params;
313 u8 ch;
314
315 vif->connecting = true;
316
317 cipher_group = sme->crypto.cipher_group;
318 if (cipher_group != 0) {
319 if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_2) {
320 if (cipher_group == WLAN_CIPHER_SUITE_TKIP)
321 security = WILC_FW_SEC_WPA2_TKIP;
322 else
323 security = WILC_FW_SEC_WPA2_AES;
324 } else if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_1) {
325 if (cipher_group == WLAN_CIPHER_SUITE_TKIP)
326 security = WILC_FW_SEC_WPA_TKIP;
327 else
328 security = WILC_FW_SEC_WPA_AES;
329 } else {
330 ret = -ENOTSUPP;
331 netdev_err(dev, "%s: Unsupported cipher\n",
332 __func__);
333 goto out_error;
334 }
335 }
336
337 if ((sme->crypto.wpa_versions & NL80211_WPA_VERSION_1) ||
338 (sme->crypto.wpa_versions & NL80211_WPA_VERSION_2)) {
339 for (i = 0; i < sme->crypto.n_ciphers_pairwise; i++) {
340 u32 ciphers_pairwise = sme->crypto.ciphers_pairwise[i];
341
342 if (ciphers_pairwise == WLAN_CIPHER_SUITE_TKIP)
343 security |= WILC_FW_TKIP;
344 else
345 security |= WILC_FW_AES;
346 }
347 }
348
349 switch (sme->auth_type) {
350 case NL80211_AUTHTYPE_OPEN_SYSTEM:
351 auth_type = WILC_FW_AUTH_OPEN_SYSTEM;
352 break;
353
354 case NL80211_AUTHTYPE_SAE:
355 auth_type = WILC_FW_AUTH_SAE;
356 if (sme->ssid_len) {
357 memcpy(vif->auth.ssid.ssid, sme->ssid, sme->ssid_len);
358 vif->auth.ssid.ssid_len = sme->ssid_len;
359 }
360 vif->auth.key_mgmt_suite = sme->crypto.akm_suites[0];
361 ether_addr_copy(vif->auth.bssid, sme->bssid);
362 break;
363
364 default:
365 break;
366 }
367
368 if (sme->crypto.n_akm_suites) {
369 if (sme->crypto.akm_suites[0] == WLAN_AKM_SUITE_8021X)
370 auth_type = WILC_FW_AUTH_IEEE8021;
371 else if (sme->crypto.akm_suites[0] == WLAN_AKM_SUITE_PSK_SHA256)
372 auth_type = WILC_FW_AUTH_OPEN_SYSTEM_SHA256;
373 else if (sme->crypto.akm_suites[0] == WLAN_AKM_SUITE_8021X_SHA256)
374 auth_type = WILC_FW_AUTH_IEE8021X_SHA256;
375 }
376
377 if (wfi_drv->usr_scan_req.scan_result) {
378 netdev_err(vif->ndev, "%s: Scan in progress\n", __func__);
379 ret = -EBUSY;
380 goto out_error;
381 }
382
383 bss = cfg80211_get_bss(wiphy, sme->channel, sme->bssid, sme->ssid,
384 sme->ssid_len, IEEE80211_BSS_TYPE_ANY,
385 IEEE80211_PRIVACY(sme->privacy));
386 if (!bss) {
387 ret = -EINVAL;
388 goto out_error;
389 }
390
391 if (ether_addr_equal_unaligned(vif->bssid, bss->bssid)) {
392 ret = -EALREADY;
393 goto out_put_bss;
394 }
395
396 join_params = wilc_parse_join_bss_param(bss, &sme->crypto);
397 if (!join_params) {
398 netdev_err(dev, "%s: failed to construct join param\n",
399 __func__);
400 ret = -EINVAL;
401 goto out_put_bss;
402 }
403
404 ch = ieee80211_frequency_to_channel(bss->channel->center_freq);
405 vif->wilc->op_ch = ch;
406 if (vif->iftype != WILC_CLIENT_MODE)
407 vif->wilc->sta_ch = ch;
408
409 wilc_wlan_set_bssid(dev, bss->bssid, WILC_STATION_MODE);
410
411 wfi_drv->conn_info.security = security;
412 wfi_drv->conn_info.auth_type = auth_type;
413 wfi_drv->conn_info.conn_result = cfg_connect_result;
414 wfi_drv->conn_info.priv = priv;
415 wfi_drv->conn_info.param = join_params;
416
417 if (sme->mfp == NL80211_MFP_OPTIONAL)
418 mfp_type = WILC_FW_MFP_OPTIONAL;
419 else if (sme->mfp == NL80211_MFP_REQUIRED)
420 mfp_type = WILC_FW_MFP_REQUIRED;
421
422 wfi_drv->conn_info.mfp_type = mfp_type;
423
424 ret = wilc_set_join_req(vif, bss->bssid, sme->ie, sme->ie_len);
425 if (ret) {
426 netdev_err(dev, "wilc_set_join_req(): Error\n");
427 ret = -ENOENT;
428 if (vif->iftype != WILC_CLIENT_MODE)
429 vif->wilc->sta_ch = WILC_INVALID_CHANNEL;
430 wilc_wlan_set_bssid(dev, NULL, WILC_STATION_MODE);
431 wfi_drv->conn_info.conn_result = NULL;
432 kfree(join_params);
433 goto out_put_bss;
434 }
435 kfree(join_params);
436 vif->bss = bss;
437 cfg80211_put_bss(wiphy, bss);
438 return 0;
439
440 out_put_bss:
441 cfg80211_put_bss(wiphy, bss);
442
443 out_error:
444 vif->connecting = false;
445 return ret;
446 }
447
disconnect(struct wiphy * wiphy,struct net_device * dev,u16 reason_code)448 static int disconnect(struct wiphy *wiphy, struct net_device *dev,
449 u16 reason_code)
450 {
451 struct wilc_vif *vif = netdev_priv(dev);
452 struct wilc_priv *priv = &vif->priv;
453 struct wilc *wilc = vif->wilc;
454 int ret;
455
456 vif->connecting = false;
457
458 if (!wilc)
459 return -EIO;
460
461 if (wilc->close) {
462 /* already disconnected done */
463 cfg80211_disconnected(dev, 0, NULL, 0, true, GFP_KERNEL);
464 return 0;
465 }
466
467 if (vif->iftype != WILC_CLIENT_MODE)
468 wilc->sta_ch = WILC_INVALID_CHANNEL;
469 wilc_wlan_set_bssid(priv->dev, NULL, WILC_STATION_MODE);
470
471 priv->hif_drv->p2p_timeout = 0;
472
473 ret = wilc_disconnect(vif);
474 if (ret != 0) {
475 netdev_err(priv->dev, "Error in disconnecting\n");
476 ret = -EINVAL;
477 }
478
479 vif->bss = NULL;
480
481 return ret;
482 }
483
wilc_wfi_cfg_allocate_wpa_entry(struct wilc_priv * priv,u8 idx)484 static int wilc_wfi_cfg_allocate_wpa_entry(struct wilc_priv *priv, u8 idx)
485 {
486 if (!priv->wilc_gtk[idx]) {
487 priv->wilc_gtk[idx] = kzalloc_obj(*priv->wilc_gtk[idx]);
488 if (!priv->wilc_gtk[idx])
489 return -ENOMEM;
490 }
491
492 if (!priv->wilc_ptk[idx]) {
493 priv->wilc_ptk[idx] = kzalloc_obj(*priv->wilc_ptk[idx]);
494 if (!priv->wilc_ptk[idx])
495 return -ENOMEM;
496 }
497
498 return 0;
499 }
500
wilc_wfi_cfg_allocate_wpa_igtk_entry(struct wilc_priv * priv,u8 idx)501 static int wilc_wfi_cfg_allocate_wpa_igtk_entry(struct wilc_priv *priv, u8 idx)
502 {
503 idx -= 4;
504 if (!priv->wilc_igtk[idx]) {
505 priv->wilc_igtk[idx] = kzalloc_obj(*priv->wilc_igtk[idx]);
506 if (!priv->wilc_igtk[idx])
507 return -ENOMEM;
508 }
509 return 0;
510 }
511
wilc_wfi_cfg_copy_wpa_info(struct wilc_wfi_key * key_info,struct key_params * params)512 static int wilc_wfi_cfg_copy_wpa_info(struct wilc_wfi_key *key_info,
513 struct key_params *params)
514 {
515 kfree(key_info->key);
516
517 key_info->key = kmemdup(params->key, params->key_len, GFP_KERNEL);
518 if (!key_info->key)
519 return -ENOMEM;
520
521 kfree(key_info->seq);
522
523 if (params->seq_len > 0) {
524 key_info->seq = kmemdup(params->seq, params->seq_len,
525 GFP_KERNEL);
526 if (!key_info->seq)
527 return -ENOMEM;
528 }
529
530 key_info->cipher = params->cipher;
531 key_info->key_len = params->key_len;
532 key_info->seq_len = params->seq_len;
533
534 return 0;
535 }
536
add_key(struct wiphy * wiphy,struct wireless_dev * wdev,int link_id,u8 key_index,bool pairwise,const u8 * mac_addr,struct key_params * params)537 static int add_key(struct wiphy *wiphy, struct wireless_dev *wdev, int link_id,
538 u8 key_index, bool pairwise, const u8 *mac_addr,
539 struct key_params *params)
540
541 {
542 int ret = 0, keylen = params->key_len;
543 const u8 *rx_mic = NULL;
544 const u8 *tx_mic = NULL;
545 u8 mode = WILC_FW_SEC_NO;
546 u8 op_mode;
547 struct wilc_vif *vif = netdev_priv(wdev->netdev);
548 struct wilc_priv *priv = &vif->priv;
549 struct wilc_wfi_key *key;
550
551 switch (params->cipher) {
552 case WLAN_CIPHER_SUITE_TKIP:
553 case WLAN_CIPHER_SUITE_CCMP:
554 if (priv->wdev.iftype == NL80211_IFTYPE_AP ||
555 priv->wdev.iftype == NL80211_IFTYPE_P2P_GO) {
556 struct wilc_wfi_key *key;
557
558 ret = wilc_wfi_cfg_allocate_wpa_entry(priv, key_index);
559 if (ret)
560 return -ENOMEM;
561
562 if (params->key_len > 16 &&
563 params->cipher == WLAN_CIPHER_SUITE_TKIP) {
564 tx_mic = params->key + 24;
565 rx_mic = params->key + 16;
566 keylen = params->key_len - 16;
567 }
568
569 if (!pairwise) {
570 if (params->cipher == WLAN_CIPHER_SUITE_TKIP)
571 mode = WILC_FW_SEC_WPA_TKIP;
572 else
573 mode = WILC_FW_SEC_WPA2_AES;
574
575 priv->wilc_groupkey = mode;
576
577 key = priv->wilc_gtk[key_index];
578 } else {
579 if (params->cipher == WLAN_CIPHER_SUITE_TKIP)
580 mode = WILC_FW_SEC_WPA_TKIP;
581 else
582 mode = priv->wilc_groupkey | WILC_FW_AES;
583
584 key = priv->wilc_ptk[key_index];
585 }
586 ret = wilc_wfi_cfg_copy_wpa_info(key, params);
587 if (ret)
588 return -ENOMEM;
589
590 op_mode = WILC_AP_MODE;
591 } else {
592 if (params->key_len > 16 &&
593 params->cipher == WLAN_CIPHER_SUITE_TKIP) {
594 rx_mic = params->key + 24;
595 tx_mic = params->key + 16;
596 keylen = params->key_len - 16;
597 }
598
599 op_mode = WILC_STATION_MODE;
600 }
601
602 if (!pairwise)
603 ret = wilc_add_rx_gtk(vif, params->key, keylen,
604 key_index, params->seq_len,
605 params->seq, rx_mic, tx_mic,
606 op_mode, mode);
607 else
608 ret = wilc_add_ptk(vif, params->key, keylen, mac_addr,
609 rx_mic, tx_mic, op_mode, mode,
610 key_index);
611
612 break;
613 case WLAN_CIPHER_SUITE_AES_CMAC:
614 ret = wilc_wfi_cfg_allocate_wpa_igtk_entry(priv, key_index);
615 if (ret)
616 return -ENOMEM;
617
618 key = priv->wilc_igtk[key_index - 4];
619 ret = wilc_wfi_cfg_copy_wpa_info(key, params);
620 if (ret)
621 return -ENOMEM;
622
623 if (priv->wdev.iftype == NL80211_IFTYPE_AP ||
624 priv->wdev.iftype == NL80211_IFTYPE_P2P_GO)
625 op_mode = WILC_AP_MODE;
626 else
627 op_mode = WILC_STATION_MODE;
628
629 ret = wilc_add_igtk(vif, params->key, keylen, params->seq,
630 params->seq_len, mac_addr, op_mode,
631 key_index);
632 break;
633
634 default:
635 netdev_err(wdev->netdev, "%s: Unsupported cipher\n", __func__);
636 ret = -ENOTSUPP;
637 }
638
639 return ret;
640 }
641
del_key(struct wiphy * wiphy,struct wireless_dev * wdev,int link_id,u8 key_index,bool pairwise,const u8 * mac_addr)642 static int del_key(struct wiphy *wiphy, struct wireless_dev *wdev, int link_id,
643 u8 key_index,
644 bool pairwise,
645 const u8 *mac_addr)
646 {
647 struct wilc_vif *vif = netdev_priv(wdev->netdev);
648 struct wilc_priv *priv = &vif->priv;
649
650 if (!pairwise && (key_index == 4 || key_index == 5)) {
651 key_index -= 4;
652 if (priv->wilc_igtk[key_index]) {
653 kfree(priv->wilc_igtk[key_index]->key);
654 priv->wilc_igtk[key_index]->key = NULL;
655 kfree(priv->wilc_igtk[key_index]->seq);
656 priv->wilc_igtk[key_index]->seq = NULL;
657 kfree(priv->wilc_igtk[key_index]);
658 priv->wilc_igtk[key_index] = NULL;
659 }
660 } else {
661 if (priv->wilc_gtk[key_index]) {
662 kfree(priv->wilc_gtk[key_index]->key);
663 priv->wilc_gtk[key_index]->key = NULL;
664 kfree(priv->wilc_gtk[key_index]->seq);
665 priv->wilc_gtk[key_index]->seq = NULL;
666
667 kfree(priv->wilc_gtk[key_index]);
668 priv->wilc_gtk[key_index] = NULL;
669 }
670 if (priv->wilc_ptk[key_index]) {
671 kfree(priv->wilc_ptk[key_index]->key);
672 priv->wilc_ptk[key_index]->key = NULL;
673 kfree(priv->wilc_ptk[key_index]->seq);
674 priv->wilc_ptk[key_index]->seq = NULL;
675 kfree(priv->wilc_ptk[key_index]);
676 priv->wilc_ptk[key_index] = NULL;
677 }
678 }
679
680 return 0;
681 }
682
get_key(struct wiphy * wiphy,struct wireless_dev * wdev,int link_id,u8 key_index,bool pairwise,const u8 * mac_addr,void * cookie,void (* callback)(void * cookie,struct key_params *))683 static int get_key(struct wiphy *wiphy, struct wireless_dev *wdev, int link_id,
684 u8 key_index, bool pairwise, const u8 *mac_addr,
685 void *cookie,
686 void (*callback)(void *cookie, struct key_params *))
687 {
688 struct wilc_vif *vif = netdev_priv(wdev->netdev);
689 struct wilc_priv *priv = &vif->priv;
690 struct key_params key_params;
691
692 if (!pairwise) {
693 if (key_index == 4 || key_index == 5) {
694 key_index -= 4;
695 key_params.key = priv->wilc_igtk[key_index]->key;
696 key_params.cipher = priv->wilc_igtk[key_index]->cipher;
697 key_params.key_len = priv->wilc_igtk[key_index]->key_len;
698 key_params.seq = priv->wilc_igtk[key_index]->seq;
699 key_params.seq_len = priv->wilc_igtk[key_index]->seq_len;
700 } else {
701 key_params.key = priv->wilc_gtk[key_index]->key;
702 key_params.cipher = priv->wilc_gtk[key_index]->cipher;
703 key_params.key_len = priv->wilc_gtk[key_index]->key_len;
704 key_params.seq = priv->wilc_gtk[key_index]->seq;
705 key_params.seq_len = priv->wilc_gtk[key_index]->seq_len;
706 }
707 } else {
708 key_params.key = priv->wilc_ptk[key_index]->key;
709 key_params.cipher = priv->wilc_ptk[key_index]->cipher;
710 key_params.key_len = priv->wilc_ptk[key_index]->key_len;
711 key_params.seq = priv->wilc_ptk[key_index]->seq;
712 key_params.seq_len = priv->wilc_ptk[key_index]->seq_len;
713 }
714
715 callback(cookie, &key_params);
716
717 return 0;
718 }
719
720 /* wiphy_new_nm() will WARNON if not present */
set_default_key(struct wiphy * wiphy,struct net_device * netdev,int link_id,u8 key_index,bool unicast,bool multicast)721 static int set_default_key(struct wiphy *wiphy, struct net_device *netdev,
722 int link_id, u8 key_index, bool unicast,
723 bool multicast)
724 {
725 return 0;
726 }
727
set_default_mgmt_key(struct wiphy * wiphy,struct wireless_dev * wdev,int link_id,u8 key_index)728 static int set_default_mgmt_key(struct wiphy *wiphy, struct wireless_dev *wdev,
729 int link_id, u8 key_index)
730 {
731 struct wilc_vif *vif = netdev_priv(wdev->netdev);
732
733 return wilc_set_default_mgmt_key_index(vif, key_index);
734 }
735
get_station(struct wiphy * wiphy,struct wireless_dev * wdev,const u8 * mac,struct station_info * sinfo)736 static int get_station(struct wiphy *wiphy, struct wireless_dev *wdev,
737 const u8 *mac, struct station_info *sinfo)
738 {
739 struct net_device *dev = wdev->netdev;
740 struct wilc_vif *vif = netdev_priv(dev);
741 struct wilc_priv *priv = &vif->priv;
742 struct wilc *wilc = vif->wilc;
743 u32 i = 0;
744 u32 associatedsta = ~0;
745 u32 inactive_time = 0;
746
747 if (vif->iftype == WILC_AP_MODE || vif->iftype == WILC_GO_MODE) {
748 for (i = 0; i < NUM_STA_ASSOCIATED; i++) {
749 if (!(memcmp(mac,
750 priv->assoc_stainfo.sta_associated_bss[i],
751 ETH_ALEN))) {
752 associatedsta = i;
753 break;
754 }
755 }
756
757 if (associatedsta == ~0) {
758 netdev_err(dev, "sta required is not associated\n");
759 return -ENOENT;
760 }
761
762 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_INACTIVE_TIME);
763
764 wilc_get_inactive_time(vif, mac, &inactive_time);
765 sinfo->inactive_time = 1000 * inactive_time;
766 } else if (vif->iftype == WILC_STATION_MODE) {
767 struct rf_info stats;
768
769 if (!wilc->initialized)
770 return -EBUSY;
771
772 wilc_get_statistics(vif, &stats);
773
774 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL) |
775 BIT_ULL(NL80211_STA_INFO_RX_PACKETS) |
776 BIT_ULL(NL80211_STA_INFO_TX_PACKETS) |
777 BIT_ULL(NL80211_STA_INFO_TX_FAILED) |
778 BIT_ULL(NL80211_STA_INFO_TX_BITRATE);
779
780 sinfo->signal = stats.rssi;
781 sinfo->rx_packets = stats.rx_cnt;
782 sinfo->tx_packets = stats.tx_cnt + stats.tx_fail_cnt;
783 sinfo->tx_failed = stats.tx_fail_cnt;
784 sinfo->txrate.legacy = stats.link_speed * 10;
785
786 if (stats.link_speed > TCP_ACK_FILTER_LINK_SPEED_THRESH &&
787 stats.link_speed != DEFAULT_LINK_SPEED)
788 wilc_enable_tcp_ack_filter(vif, true);
789 else if (stats.link_speed != DEFAULT_LINK_SPEED)
790 wilc_enable_tcp_ack_filter(vif, false);
791 }
792 return 0;
793 }
794
set_wiphy_params(struct wiphy * wiphy,int radio_idx,u32 changed)795 static int set_wiphy_params(struct wiphy *wiphy, int radio_idx, u32 changed)
796 {
797 int ret = -EINVAL;
798 struct cfg_param_attr cfg_param_val;
799 struct wilc *wl = wiphy_priv(wiphy);
800 struct wilc_vif *vif;
801 struct wilc_priv *priv;
802 int srcu_idx;
803
804 srcu_idx = srcu_read_lock(&wl->srcu);
805 vif = wilc_get_wl_to_vif(wl);
806 if (IS_ERR(vif))
807 goto out;
808
809 priv = &vif->priv;
810 cfg_param_val.flag = 0;
811
812 if (changed & WIPHY_PARAM_RETRY_SHORT) {
813 netdev_dbg(vif->ndev,
814 "Setting WIPHY_PARAM_RETRY_SHORT %d\n",
815 wiphy->retry_short);
816 cfg_param_val.flag |= WILC_CFG_PARAM_RETRY_SHORT;
817 cfg_param_val.short_retry_limit = wiphy->retry_short;
818 }
819 if (changed & WIPHY_PARAM_RETRY_LONG) {
820 netdev_dbg(vif->ndev,
821 "Setting WIPHY_PARAM_RETRY_LONG %d\n",
822 wiphy->retry_long);
823 cfg_param_val.flag |= WILC_CFG_PARAM_RETRY_LONG;
824 cfg_param_val.long_retry_limit = wiphy->retry_long;
825 }
826 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
827 if (wiphy->frag_threshold > 255 &&
828 wiphy->frag_threshold < 7937) {
829 netdev_dbg(vif->ndev,
830 "Setting WIPHY_PARAM_FRAG_THRESHOLD %d\n",
831 wiphy->frag_threshold);
832 cfg_param_val.flag |= WILC_CFG_PARAM_FRAG_THRESHOLD;
833 cfg_param_val.frag_threshold = wiphy->frag_threshold;
834 } else {
835 netdev_err(vif->ndev,
836 "Fragmentation threshold out of range\n");
837 goto out;
838 }
839 }
840
841 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
842 if (wiphy->rts_threshold > 255) {
843 netdev_dbg(vif->ndev,
844 "Setting WIPHY_PARAM_RTS_THRESHOLD %d\n",
845 wiphy->rts_threshold);
846 cfg_param_val.flag |= WILC_CFG_PARAM_RTS_THRESHOLD;
847 cfg_param_val.rts_threshold = wiphy->rts_threshold;
848 } else {
849 netdev_err(vif->ndev, "RTS threshold out of range\n");
850 goto out;
851 }
852 }
853
854 ret = wilc_hif_set_cfg(vif, &cfg_param_val);
855 if (ret)
856 netdev_err(priv->dev, "Error in setting WIPHY PARAMS\n");
857
858 out:
859 srcu_read_unlock(&wl->srcu, srcu_idx);
860 return ret;
861 }
862
set_pmksa(struct wiphy * wiphy,struct net_device * netdev,struct cfg80211_pmksa * pmksa)863 static int set_pmksa(struct wiphy *wiphy, struct net_device *netdev,
864 struct cfg80211_pmksa *pmksa)
865 {
866 struct wilc_vif *vif = netdev_priv(netdev);
867 struct wilc_priv *priv = &vif->priv;
868 u32 i;
869 int ret = 0;
870 u8 flag = 0;
871
872 for (i = 0; i < priv->pmkid_list.numpmkid; i++) {
873 if (!memcmp(pmksa->bssid, priv->pmkid_list.pmkidlist[i].bssid,
874 ETH_ALEN)) {
875 flag = PMKID_FOUND;
876 break;
877 }
878 }
879 if (i < WILC_MAX_NUM_PMKIDS) {
880 memcpy(priv->pmkid_list.pmkidlist[i].bssid, pmksa->bssid,
881 ETH_ALEN);
882 memcpy(priv->pmkid_list.pmkidlist[i].pmkid, pmksa->pmkid,
883 WLAN_PMKID_LEN);
884 if (!(flag == PMKID_FOUND))
885 priv->pmkid_list.numpmkid++;
886 } else {
887 netdev_err(netdev, "Invalid PMKID index\n");
888 ret = -EINVAL;
889 }
890
891 if (!ret)
892 ret = wilc_set_pmkid_info(vif, &priv->pmkid_list);
893
894 return ret;
895 }
896
del_pmksa(struct wiphy * wiphy,struct net_device * netdev,struct cfg80211_pmksa * pmksa)897 static int del_pmksa(struct wiphy *wiphy, struct net_device *netdev,
898 struct cfg80211_pmksa *pmksa)
899 {
900 u32 i;
901 struct wilc_vif *vif = netdev_priv(netdev);
902 struct wilc_priv *priv = &vif->priv;
903
904 for (i = 0; i < priv->pmkid_list.numpmkid; i++) {
905 if (!memcmp(pmksa->bssid, priv->pmkid_list.pmkidlist[i].bssid,
906 ETH_ALEN)) {
907 memset(&priv->pmkid_list.pmkidlist[i], 0,
908 sizeof(struct wilc_pmkid));
909 break;
910 }
911 }
912
913 if (i == priv->pmkid_list.numpmkid)
914 return -EINVAL;
915
916 for (; i < (priv->pmkid_list.numpmkid - 1); i++) {
917 memcpy(priv->pmkid_list.pmkidlist[i].bssid,
918 priv->pmkid_list.pmkidlist[i + 1].bssid,
919 ETH_ALEN);
920 memcpy(priv->pmkid_list.pmkidlist[i].pmkid,
921 priv->pmkid_list.pmkidlist[i + 1].pmkid,
922 WLAN_PMKID_LEN);
923 }
924 priv->pmkid_list.numpmkid--;
925
926 return 0;
927 }
928
flush_pmksa(struct wiphy * wiphy,struct net_device * netdev)929 static int flush_pmksa(struct wiphy *wiphy, struct net_device *netdev)
930 {
931 struct wilc_vif *vif = netdev_priv(netdev);
932
933 memset(&vif->priv.pmkid_list, 0, sizeof(struct wilc_pmkid_attr));
934
935 return 0;
936 }
937
wilc_wfi_cfg_parse_ch_attr(u8 * buf,u32 len,u8 sta_ch)938 static inline void wilc_wfi_cfg_parse_ch_attr(u8 *buf, u32 len, u8 sta_ch)
939 {
940 struct wilc_attr_entry *e;
941 struct wilc_attr_ch_list *ch_list;
942 struct wilc_attr_oper_ch *op_ch;
943 u32 index = 0;
944 u8 ch_list_idx = 0;
945 u8 op_ch_idx = 0;
946
947 if (sta_ch == WILC_INVALID_CHANNEL)
948 return;
949
950 while (index + sizeof(*e) <= len) {
951 u16 attr_size;
952
953 e = (struct wilc_attr_entry *)&buf[index];
954 attr_size = le16_to_cpu(e->attr_len);
955
956 if (index + sizeof(*e) + attr_size > len)
957 return;
958
959 if (e->attr_type == IEEE80211_P2P_ATTR_CHANNEL_LIST &&
960 attr_size >= (sizeof(struct wilc_attr_ch_list) - sizeof(*e)))
961 ch_list_idx = index;
962 else if (e->attr_type == IEEE80211_P2P_ATTR_OPER_CHANNEL &&
963 attr_size == (sizeof(struct wilc_attr_oper_ch) - sizeof(*e)))
964 op_ch_idx = index;
965
966 if (ch_list_idx && op_ch_idx)
967 break;
968
969 index += sizeof(*e) + attr_size;
970 }
971
972 if (ch_list_idx) {
973 u16 elem_size;
974
975 ch_list = (struct wilc_attr_ch_list *)&buf[ch_list_idx];
976 /* the number of bytes following the final 'elem' member */
977 elem_size = le16_to_cpu(ch_list->attr_len) -
978 (sizeof(*ch_list) - sizeof(struct wilc_attr_entry));
979 for (unsigned int i = 0; i < elem_size;) {
980 struct wilc_ch_list_elem *e;
981
982 e = (struct wilc_ch_list_elem *)(ch_list->elem + i);
983
984 i += sizeof(*e);
985 if (i > elem_size)
986 break;
987
988 i += e->no_of_channels;
989 if (i > elem_size)
990 break;
991
992 if (e->op_class == WILC_WLAN_OPERATING_CLASS_2_4GHZ) {
993 memset(e->ch_list, sta_ch, e->no_of_channels);
994 break;
995 }
996 }
997 }
998
999 if (op_ch_idx) {
1000 op_ch = (struct wilc_attr_oper_ch *)&buf[op_ch_idx];
1001 op_ch->op_class = WILC_WLAN_OPERATING_CLASS_2_4GHZ;
1002 op_ch->op_channel = sta_ch;
1003 }
1004 }
1005
wilc_wfi_mgmt_frame_rx(struct wilc_vif * vif,u8 * buff,u32 size)1006 bool wilc_wfi_mgmt_frame_rx(struct wilc_vif *vif, u8 *buff, u32 size)
1007 {
1008 struct wilc *wl = vif->wilc;
1009 struct wilc_priv *priv = &vif->priv;
1010 int freq;
1011
1012 freq = ieee80211_channel_to_frequency(wl->op_ch, NL80211_BAND_2GHZ);
1013
1014 return cfg80211_rx_mgmt(&priv->wdev, freq, 0, buff, size, 0);
1015 }
1016
wilc_wfi_p2p_rx(struct wilc_vif * vif,u8 * buff,u32 size)1017 void wilc_wfi_p2p_rx(struct wilc_vif *vif, u8 *buff, u32 size)
1018 {
1019 struct wilc *wl = vif->wilc;
1020 struct wilc_priv *priv = &vif->priv;
1021 struct host_if_drv *wfi_drv = priv->hif_drv;
1022 struct ieee80211_mgmt *mgmt;
1023 struct wilc_vendor_specific_ie *p;
1024 struct wilc_p2p_pub_act_frame *d;
1025 int ie_offset = offsetof(struct ieee80211_mgmt, u) + sizeof(*d);
1026 const u8 *vendor_ie;
1027 u32 header, pkt_offset;
1028 s32 freq;
1029
1030 header = get_unaligned_le32(buff - HOST_HDR_OFFSET);
1031 pkt_offset = FIELD_GET(WILC_PKT_HDR_OFFSET_FIELD, header);
1032
1033 if (pkt_offset & IS_MANAGMEMENT_CALLBACK) {
1034 bool ack = false;
1035 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)buff;
1036
1037 if (ieee80211_is_probe_resp(hdr->frame_control) ||
1038 pkt_offset & IS_MGMT_STATUS_SUCCES)
1039 ack = true;
1040
1041 cfg80211_mgmt_tx_status(&priv->wdev, priv->tx_cookie, buff,
1042 size, ack, GFP_KERNEL);
1043 return;
1044 }
1045
1046 freq = ieee80211_channel_to_frequency(wl->op_ch, NL80211_BAND_2GHZ);
1047
1048 mgmt = (struct ieee80211_mgmt *)buff;
1049 if (!ieee80211_is_action(mgmt->frame_control))
1050 goto out_rx_mgmt;
1051
1052 if (priv->cfg_scanning &&
1053 time_after_eq(jiffies, (unsigned long)wfi_drv->p2p_timeout)) {
1054 netdev_dbg(vif->ndev, "Receiving action wrong ch\n");
1055 return;
1056 }
1057
1058 if (!ieee80211_is_public_action((struct ieee80211_hdr *)buff, size))
1059 goto out_rx_mgmt;
1060
1061 /* ieee80211_is_public_action() only validates up to the category
1062 * byte, so reject frames too short for the P2P public action header
1063 * before dereferencing it or computing size - ie_offset.
1064 */
1065 if (size < ie_offset)
1066 goto out_rx_mgmt;
1067
1068 d = (struct wilc_p2p_pub_act_frame *)(&mgmt->u.action);
1069 if (d->oui_subtype != GO_NEG_REQ && d->oui_subtype != GO_NEG_RSP &&
1070 d->oui_subtype != P2P_INV_REQ && d->oui_subtype != P2P_INV_RSP)
1071 goto out_rx_mgmt;
1072
1073 vendor_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1074 buff + ie_offset, size - ie_offset);
1075 if (!vendor_ie)
1076 goto out_rx_mgmt;
1077
1078 p = (struct wilc_vendor_specific_ie *)vendor_ie;
1079 wilc_wfi_cfg_parse_ch_attr(p->attr, p->tag_len - 4, vif->wilc->sta_ch);
1080
1081 out_rx_mgmt:
1082 cfg80211_rx_mgmt(&priv->wdev, freq, 0, buff, size, 0);
1083 }
1084
wilc_wfi_mgmt_tx_complete(void * priv,int status)1085 static void wilc_wfi_mgmt_tx_complete(void *priv, int status)
1086 {
1087 struct wilc_p2p_mgmt_data *pv_data = priv;
1088
1089 kfree(pv_data->buff);
1090 kfree(pv_data);
1091 }
1092
wilc_wfi_remain_on_channel_expired(struct wilc_vif * vif,u64 cookie)1093 static void wilc_wfi_remain_on_channel_expired(struct wilc_vif *vif, u64 cookie)
1094 {
1095 struct wilc_priv *priv = &vif->priv;
1096 struct wilc_wfi_p2p_listen_params *params = &priv->remain_on_ch_params;
1097
1098 if (cookie != params->listen_cookie)
1099 return;
1100
1101 priv->p2p_listen_state = false;
1102
1103 cfg80211_remain_on_channel_expired(&priv->wdev, params->listen_cookie,
1104 params->listen_ch, GFP_KERNEL);
1105 }
1106
remain_on_channel(struct wiphy * wiphy,struct wireless_dev * wdev,struct ieee80211_channel * chan,unsigned int duration,u64 cookie,const u8 * rx_addr)1107 static int remain_on_channel(struct wiphy *wiphy,
1108 struct wireless_dev *wdev,
1109 struct ieee80211_channel *chan,
1110 unsigned int duration, u64 cookie,
1111 const u8 *rx_addr)
1112 {
1113 int ret = 0;
1114 struct wilc_vif *vif = netdev_priv(wdev->netdev);
1115 struct wilc_priv *priv = &vif->priv;
1116
1117 if (wdev->iftype == NL80211_IFTYPE_AP) {
1118 netdev_dbg(vif->ndev, "Required while in AP mode\n");
1119 return ret;
1120 }
1121
1122 ret = wilc_remain_on_channel(vif, cookie, chan->hw_value,
1123 wilc_wfi_remain_on_channel_expired);
1124 if (ret)
1125 return ret;
1126
1127 vif->wilc->op_ch = chan->hw_value;
1128
1129 priv->remain_on_ch_params.listen_ch = chan;
1130 priv->remain_on_ch_params.listen_cookie = cookie;
1131 priv->p2p_listen_state = true;
1132 priv->remain_on_ch_params.listen_duration = duration;
1133
1134 cfg80211_ready_on_channel(wdev, cookie, chan, duration, GFP_KERNEL);
1135 mod_timer(&vif->hif_drv->remain_on_ch_timer,
1136 jiffies + msecs_to_jiffies(duration + 1000));
1137
1138 return ret;
1139 }
1140
cancel_remain_on_channel(struct wiphy * wiphy,struct wireless_dev * wdev,u64 cookie)1141 static int cancel_remain_on_channel(struct wiphy *wiphy,
1142 struct wireless_dev *wdev,
1143 u64 cookie)
1144 {
1145 struct wilc_vif *vif = netdev_priv(wdev->netdev);
1146 struct wilc_priv *priv = &vif->priv;
1147
1148 if (cookie != priv->remain_on_ch_params.listen_cookie)
1149 return -ENOENT;
1150
1151 return wilc_listen_state_expired(vif, cookie);
1152 }
1153
mgmt_tx(struct wiphy * wiphy,struct wireless_dev * wdev,struct cfg80211_mgmt_tx_params * params,u64 cookie)1154 static int mgmt_tx(struct wiphy *wiphy,
1155 struct wireless_dev *wdev,
1156 struct cfg80211_mgmt_tx_params *params,
1157 u64 cookie)
1158 {
1159 struct ieee80211_channel *chan = params->chan;
1160 unsigned int wait = params->wait;
1161 const u8 *buf = params->buf;
1162 size_t len = params->len;
1163 const struct ieee80211_mgmt *mgmt;
1164 struct wilc_p2p_mgmt_data *mgmt_tx;
1165 struct wilc_vif *vif = netdev_priv(wdev->netdev);
1166 struct wilc_priv *priv = &vif->priv;
1167 struct host_if_drv *wfi_drv = priv->hif_drv;
1168 struct wilc_vendor_specific_ie *p;
1169 struct wilc_p2p_pub_act_frame *d;
1170 int ie_offset = offsetof(struct ieee80211_mgmt, u) + sizeof(*d);
1171 const u8 *vendor_ie;
1172 int ret = 0;
1173
1174 priv->tx_cookie = cookie;
1175 mgmt = (const struct ieee80211_mgmt *)buf;
1176
1177 if (!ieee80211_is_mgmt(mgmt->frame_control))
1178 goto out;
1179
1180 mgmt_tx = kmalloc_obj(*mgmt_tx);
1181 if (!mgmt_tx) {
1182 ret = -ENOMEM;
1183 goto out;
1184 }
1185
1186 mgmt_tx->buff = kmemdup(buf, len, GFP_KERNEL);
1187 if (!mgmt_tx->buff) {
1188 ret = -ENOMEM;
1189 kfree(mgmt_tx);
1190 goto out;
1191 }
1192
1193 mgmt_tx->size = len;
1194
1195 if (ieee80211_is_probe_resp(mgmt->frame_control)) {
1196 wilc_set_mac_chnl_num(vif, chan->hw_value);
1197 vif->wilc->op_ch = chan->hw_value;
1198 goto out_txq_add_pkt;
1199 }
1200
1201 if (!ieee80211_is_public_action((struct ieee80211_hdr *)buf, len)) {
1202 if (chan)
1203 wilc_set_mac_chnl_num(vif, chan->hw_value);
1204 else
1205 wilc_set_mac_chnl_num(vif, vif->wilc->op_ch);
1206
1207 goto out_set_timeout;
1208 }
1209
1210 /* ieee80211_is_public_action() only validates up to the category
1211 * byte, so reject frames too short for the P2P public action header
1212 * before dereferencing it or computing len - ie_offset.
1213 */
1214 if (len < ie_offset)
1215 goto out_set_timeout;
1216
1217 d = (struct wilc_p2p_pub_act_frame *)(&mgmt->u.action);
1218 if (d->oui_type != WLAN_OUI_TYPE_WFA_P2P ||
1219 d->oui_subtype != GO_NEG_CONF) {
1220 wilc_set_mac_chnl_num(vif, chan->hw_value);
1221 vif->wilc->op_ch = chan->hw_value;
1222 }
1223
1224 if (d->oui_subtype != P2P_INV_REQ && d->oui_subtype != P2P_INV_RSP)
1225 goto out_set_timeout;
1226
1227 vendor_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1228 mgmt_tx->buff + ie_offset,
1229 len - ie_offset);
1230 if (!vendor_ie)
1231 goto out_set_timeout;
1232
1233 p = (struct wilc_vendor_specific_ie *)vendor_ie;
1234 wilc_wfi_cfg_parse_ch_attr(p->attr, p->tag_len - 4, vif->wilc->sta_ch);
1235
1236 out_set_timeout:
1237 wfi_drv->p2p_timeout = (jiffies + msecs_to_jiffies(wait));
1238
1239 out_txq_add_pkt:
1240
1241 wilc_wlan_txq_add_mgmt_pkt(wdev->netdev, mgmt_tx,
1242 mgmt_tx->buff, mgmt_tx->size,
1243 wilc_wfi_mgmt_tx_complete);
1244
1245 out:
1246
1247 return ret;
1248 }
1249
mgmt_tx_cancel_wait(struct wiphy * wiphy,struct wireless_dev * wdev,u64 cookie)1250 static int mgmt_tx_cancel_wait(struct wiphy *wiphy,
1251 struct wireless_dev *wdev,
1252 u64 cookie)
1253 {
1254 struct wilc_vif *vif = netdev_priv(wdev->netdev);
1255 struct wilc_priv *priv = &vif->priv;
1256 struct host_if_drv *wfi_drv = priv->hif_drv;
1257
1258 wfi_drv->p2p_timeout = jiffies;
1259
1260 if (!priv->p2p_listen_state) {
1261 struct wilc_wfi_p2p_listen_params *params;
1262
1263 params = &priv->remain_on_ch_params;
1264
1265 cfg80211_remain_on_channel_expired(wdev,
1266 params->listen_cookie,
1267 params->listen_ch,
1268 GFP_KERNEL);
1269 }
1270
1271 return 0;
1272 }
1273
wilc_update_mgmt_frame_registrations(struct wiphy * wiphy,struct wireless_dev * wdev,struct mgmt_frame_regs * upd)1274 void wilc_update_mgmt_frame_registrations(struct wiphy *wiphy,
1275 struct wireless_dev *wdev,
1276 struct mgmt_frame_regs *upd)
1277 {
1278 struct wilc *wl = wiphy_priv(wiphy);
1279 struct wilc_vif *vif = netdev_priv(wdev->netdev);
1280 u32 presp_bit = BIT(IEEE80211_STYPE_PROBE_REQ >> 4);
1281 u32 action_bit = BIT(IEEE80211_STYPE_ACTION >> 4);
1282 u32 pauth_bit = BIT(IEEE80211_STYPE_AUTH >> 4);
1283
1284 if (wl->initialized) {
1285 bool prev = vif->mgmt_reg_stypes & presp_bit;
1286 bool now = upd->interface_stypes & presp_bit;
1287
1288 if (now != prev)
1289 wilc_frame_register(vif, IEEE80211_STYPE_PROBE_REQ, now);
1290
1291 prev = vif->mgmt_reg_stypes & action_bit;
1292 now = upd->interface_stypes & action_bit;
1293
1294 if (now != prev)
1295 wilc_frame_register(vif, IEEE80211_STYPE_ACTION, now);
1296
1297 prev = vif->mgmt_reg_stypes & pauth_bit;
1298 now = upd->interface_stypes & pauth_bit;
1299 if (now != prev)
1300 wilc_frame_register(vif, IEEE80211_STYPE_AUTH, now);
1301 }
1302
1303 vif->mgmt_reg_stypes =
1304 upd->interface_stypes & (presp_bit | action_bit | pauth_bit);
1305 }
1306
external_auth(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_external_auth_params * auth)1307 static int external_auth(struct wiphy *wiphy, struct net_device *dev,
1308 struct cfg80211_external_auth_params *auth)
1309 {
1310 struct wilc_vif *vif = netdev_priv(dev);
1311
1312 if (auth->status == WLAN_STATUS_SUCCESS)
1313 wilc_set_external_auth_param(vif, auth);
1314
1315 return 0;
1316 }
1317
set_cqm_rssi_config(struct wiphy * wiphy,struct net_device * dev,s32 rssi_thold,u32 rssi_hyst)1318 static int set_cqm_rssi_config(struct wiphy *wiphy, struct net_device *dev,
1319 s32 rssi_thold, u32 rssi_hyst)
1320 {
1321 return 0;
1322 }
1323
dump_station(struct wiphy * wiphy,struct wireless_dev * wdev,int idx,u8 * mac,struct station_info * sinfo)1324 static int dump_station(struct wiphy *wiphy, struct wireless_dev *wdev,
1325 int idx, u8 *mac, struct station_info *sinfo)
1326 {
1327 struct wilc_vif *vif = netdev_priv(wdev->netdev);
1328 int ret;
1329
1330 if (idx != 0)
1331 return -ENOENT;
1332
1333 ret = wilc_get_rssi(vif, &sinfo->signal);
1334 if (ret)
1335 return ret;
1336
1337 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL);
1338 memcpy(mac, vif->priv.associated_bss, ETH_ALEN);
1339 return 0;
1340 }
1341
set_power_mgmt(struct wiphy * wiphy,struct net_device * dev,bool enabled,int timeout)1342 static int set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
1343 bool enabled, int timeout)
1344 {
1345 struct wilc_vif *vif = netdev_priv(dev);
1346 struct wilc_priv *priv = &vif->priv;
1347
1348 if (!priv->hif_drv)
1349 return -EIO;
1350
1351 wilc_set_power_mgmt(vif, enabled, timeout);
1352
1353 return 0;
1354 }
1355
change_virtual_intf(struct wiphy * wiphy,struct net_device * dev,enum nl80211_iftype type,struct vif_params * params)1356 static int change_virtual_intf(struct wiphy *wiphy, struct net_device *dev,
1357 enum nl80211_iftype type,
1358 struct vif_params *params)
1359 {
1360 struct wilc *wl = wiphy_priv(wiphy);
1361 struct wilc_vif *vif = netdev_priv(dev);
1362 struct wilc_priv *priv = &vif->priv;
1363
1364 switch (type) {
1365 case NL80211_IFTYPE_STATION:
1366 vif->connecting = false;
1367 dev->ieee80211_ptr->iftype = type;
1368 priv->wdev.iftype = type;
1369 vif->monitor_flag = 0;
1370 if (vif->iftype == WILC_AP_MODE || vif->iftype == WILC_GO_MODE)
1371 wilc_wfi_deinit_mon_interface(wl, true);
1372 vif->iftype = WILC_STATION_MODE;
1373
1374 if (wl->initialized)
1375 wilc_set_operation_mode(vif, wilc_get_vif_idx(vif),
1376 WILC_STATION_MODE, vif->idx);
1377
1378 memset(priv->assoc_stainfo.sta_associated_bss, 0,
1379 WILC_MAX_NUM_STA * ETH_ALEN);
1380 break;
1381
1382 case NL80211_IFTYPE_P2P_CLIENT:
1383 vif->connecting = false;
1384 dev->ieee80211_ptr->iftype = type;
1385 priv->wdev.iftype = type;
1386 vif->monitor_flag = 0;
1387 vif->iftype = WILC_CLIENT_MODE;
1388
1389 if (wl->initialized)
1390 wilc_set_operation_mode(vif, wilc_get_vif_idx(vif),
1391 WILC_STATION_MODE, vif->idx);
1392 break;
1393
1394 case NL80211_IFTYPE_AP:
1395 dev->ieee80211_ptr->iftype = type;
1396 priv->wdev.iftype = type;
1397 vif->iftype = WILC_AP_MODE;
1398
1399 if (wl->initialized)
1400 wilc_set_operation_mode(vif, wilc_get_vif_idx(vif),
1401 WILC_AP_MODE, vif->idx);
1402 break;
1403
1404 case NL80211_IFTYPE_P2P_GO:
1405 dev->ieee80211_ptr->iftype = type;
1406 priv->wdev.iftype = type;
1407 vif->iftype = WILC_GO_MODE;
1408
1409 if (wl->initialized)
1410 wilc_set_operation_mode(vif, wilc_get_vif_idx(vif),
1411 WILC_AP_MODE, vif->idx);
1412 break;
1413
1414 default:
1415 netdev_err(dev, "Unknown interface type= %d\n", type);
1416 return -EINVAL;
1417 }
1418
1419 return 0;
1420 }
1421
start_ap(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_ap_settings * settings)1422 static int start_ap(struct wiphy *wiphy, struct net_device *dev,
1423 struct cfg80211_ap_settings *settings)
1424 {
1425 struct wilc_vif *vif = netdev_priv(dev);
1426 int ret;
1427
1428 ret = set_channel(wiphy, dev, &settings->chandef);
1429 if (ret != 0)
1430 netdev_err(dev, "Error in setting channel\n");
1431
1432 wilc_wlan_set_bssid(dev, dev->dev_addr, WILC_AP_MODE);
1433
1434 return wilc_add_beacon(vif, settings->beacon_interval,
1435 settings->dtim_period, &settings->beacon);
1436 }
1437
change_beacon(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_ap_update * params)1438 static int change_beacon(struct wiphy *wiphy, struct net_device *dev,
1439 struct cfg80211_ap_update *params)
1440 {
1441 struct wilc_vif *vif = netdev_priv(dev);
1442
1443 return wilc_add_beacon(vif, 0, 0, ¶ms->beacon);
1444 }
1445
stop_ap(struct wiphy * wiphy,struct net_device * dev,unsigned int link_id)1446 static int stop_ap(struct wiphy *wiphy, struct net_device *dev,
1447 unsigned int link_id)
1448 {
1449 int ret;
1450 struct wilc_vif *vif = netdev_priv(dev);
1451
1452 wilc_wlan_set_bssid(dev, NULL, WILC_AP_MODE);
1453
1454 ret = wilc_del_beacon(vif);
1455
1456 if (ret)
1457 netdev_err(dev, "Host delete beacon fail\n");
1458
1459 return ret;
1460 }
1461
add_station(struct wiphy * wiphy,struct wireless_dev * wdev,const u8 * mac,struct station_parameters * params)1462 static int add_station(struct wiphy *wiphy, struct wireless_dev *wdev,
1463 const u8 *mac, struct station_parameters *params)
1464 {
1465 int ret = 0;
1466 struct wilc_vif *vif = netdev_priv(wdev->netdev);
1467 struct wilc_priv *priv = &vif->priv;
1468
1469 if (vif->iftype == WILC_AP_MODE || vif->iftype == WILC_GO_MODE) {
1470 memcpy(priv->assoc_stainfo.sta_associated_bss[params->aid], mac,
1471 ETH_ALEN);
1472
1473 ret = wilc_add_station(vif, mac, params);
1474 if (ret)
1475 netdev_err(wdev->netdev, "Host add station fail\n");
1476 }
1477
1478 return ret;
1479 }
1480
del_station(struct wiphy * wiphy,struct wireless_dev * wdev,struct station_del_parameters * params)1481 static int del_station(struct wiphy *wiphy, struct wireless_dev *wdev,
1482 struct station_del_parameters *params)
1483 {
1484 const u8 *mac = params->mac;
1485 int ret = 0;
1486 struct wilc_vif *vif = netdev_priv(wdev->netdev);
1487 struct wilc_priv *priv = &vif->priv;
1488 struct sta_info *info;
1489
1490 if (!(vif->iftype == WILC_AP_MODE || vif->iftype == WILC_GO_MODE))
1491 return ret;
1492
1493 info = &priv->assoc_stainfo;
1494
1495 if (!mac)
1496 ret = wilc_del_allstation(vif, info->sta_associated_bss);
1497
1498 ret = wilc_del_station(vif, mac);
1499 if (ret)
1500 netdev_err(wdev->netdev, "Host delete station fail\n");
1501 return ret;
1502 }
1503
change_station(struct wiphy * wiphy,struct wireless_dev * wdev,const u8 * mac,struct station_parameters * params)1504 static int change_station(struct wiphy *wiphy, struct wireless_dev *wdev,
1505 const u8 *mac, struct station_parameters *params)
1506 {
1507 int ret = 0;
1508 struct wilc_vif *vif = netdev_priv(wdev->netdev);
1509 if (vif->iftype == WILC_AP_MODE || vif->iftype == WILC_GO_MODE) {
1510 ret = wilc_edit_station(vif, mac, params);
1511 if (ret)
1512 netdev_err(wdev->netdev, "Host edit station fail\n");
1513 }
1514 return ret;
1515 }
1516
wilc_get_vif_from_type(struct wilc * wl,int type)1517 static struct wilc_vif *wilc_get_vif_from_type(struct wilc *wl, int type)
1518 {
1519 struct wilc_vif *vif;
1520
1521 wilc_for_each_vif(wl, vif) {
1522 if (vif->iftype == type)
1523 return vif;
1524 }
1525
1526 return NULL;
1527 }
1528
add_virtual_intf(struct wiphy * wiphy,const char * name,unsigned char name_assign_type,enum nl80211_iftype type,struct vif_params * params)1529 static struct wireless_dev *add_virtual_intf(struct wiphy *wiphy,
1530 const char *name,
1531 unsigned char name_assign_type,
1532 enum nl80211_iftype type,
1533 struct vif_params *params)
1534 {
1535 struct wilc *wl = wiphy_priv(wiphy);
1536 struct wilc_vif *vif;
1537 struct wireless_dev *wdev;
1538 int iftype;
1539
1540 if (type == NL80211_IFTYPE_MONITOR) {
1541 struct net_device *ndev;
1542 int srcu_idx;
1543
1544 srcu_idx = srcu_read_lock(&wl->srcu);
1545 vif = wilc_get_vif_from_type(wl, WILC_AP_MODE);
1546 if (!vif) {
1547 vif = wilc_get_vif_from_type(wl, WILC_GO_MODE);
1548 if (!vif) {
1549 srcu_read_unlock(&wl->srcu, srcu_idx);
1550 goto validate_interface;
1551 }
1552 }
1553
1554 if (vif->monitor_flag) {
1555 srcu_read_unlock(&wl->srcu, srcu_idx);
1556 goto validate_interface;
1557 }
1558
1559 ndev = wilc_wfi_init_mon_interface(wl, name, vif->ndev);
1560 if (ndev) {
1561 vif->monitor_flag = 1;
1562 } else {
1563 srcu_read_unlock(&wl->srcu, srcu_idx);
1564 return ERR_PTR(-EINVAL);
1565 }
1566
1567 wdev = &vif->priv.wdev;
1568 srcu_read_unlock(&wl->srcu, srcu_idx);
1569 return wdev;
1570 }
1571
1572 validate_interface:
1573 mutex_lock(&wl->vif_mutex);
1574 if (wl->vif_num == WILC_NUM_CONCURRENT_IFC) {
1575 pr_err("Reached maximum number of interface\n");
1576 mutex_unlock(&wl->vif_mutex);
1577 return ERR_PTR(-EINVAL);
1578 }
1579 mutex_unlock(&wl->vif_mutex);
1580
1581 switch (type) {
1582 case NL80211_IFTYPE_STATION:
1583 iftype = WILC_STATION_MODE;
1584 break;
1585 case NL80211_IFTYPE_AP:
1586 iftype = WILC_AP_MODE;
1587 break;
1588 default:
1589 return ERR_PTR(-EOPNOTSUPP);
1590 }
1591
1592 vif = wilc_netdev_ifc_init(wl, name, iftype, type, true);
1593 if (IS_ERR(vif))
1594 return ERR_CAST(vif);
1595
1596 return &vif->priv.wdev;
1597 }
1598
del_virtual_intf(struct wiphy * wiphy,struct wireless_dev * wdev)1599 static int del_virtual_intf(struct wiphy *wiphy, struct wireless_dev *wdev)
1600 {
1601 struct wilc *wl = wiphy_priv(wiphy);
1602 struct wilc_vif *vif;
1603
1604 if (wdev->iftype == NL80211_IFTYPE_AP ||
1605 wdev->iftype == NL80211_IFTYPE_P2P_GO)
1606 wilc_wfi_deinit_mon_interface(wl, true);
1607 vif = netdev_priv(wdev->netdev);
1608 cfg80211_stop_iface(wiphy, wdev, GFP_KERNEL);
1609 cfg80211_unregister_netdevice(vif->ndev);
1610 vif->monitor_flag = 0;
1611
1612 mutex_lock(&wl->vif_mutex);
1613 list_del_rcu(&vif->list);
1614 wl->vif_num--;
1615 mutex_unlock(&wl->vif_mutex);
1616 synchronize_srcu(&wl->srcu);
1617 return 0;
1618 }
1619
wilc_set_wakeup(struct wiphy * wiphy,bool enabled)1620 static void wilc_set_wakeup(struct wiphy *wiphy, bool enabled)
1621 {
1622 struct wilc *wl = wiphy_priv(wiphy);
1623 struct wilc_vif *vif;
1624 int srcu_idx;
1625
1626 srcu_idx = srcu_read_lock(&wl->srcu);
1627 vif = wilc_get_wl_to_vif(wl);
1628 if (IS_ERR(vif)) {
1629 srcu_read_unlock(&wl->srcu, srcu_idx);
1630 return;
1631 }
1632
1633 netdev_info(vif->ndev, "cfg set wake up = %d\n", enabled);
1634 wilc_set_wowlan_trigger(vif, enabled);
1635 srcu_read_unlock(&wl->srcu, srcu_idx);
1636 }
1637
set_tx_power(struct wiphy * wiphy,struct wireless_dev * wdev,int radio_idx,enum nl80211_tx_power_setting type,int mbm)1638 static int set_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev,
1639 int radio_idx, enum nl80211_tx_power_setting type,
1640 int mbm)
1641 {
1642 int ret;
1643 int srcu_idx;
1644 s32 tx_power = MBM_TO_DBM(mbm);
1645 struct wilc *wl = wiphy_priv(wiphy);
1646 struct wilc_vif *vif;
1647
1648 if (!wl->initialized)
1649 return -EIO;
1650
1651 srcu_idx = srcu_read_lock(&wl->srcu);
1652 vif = wilc_get_wl_to_vif(wl);
1653 if (IS_ERR(vif)) {
1654 srcu_read_unlock(&wl->srcu, srcu_idx);
1655 return -EINVAL;
1656 }
1657
1658 netdev_info(vif->ndev, "Setting tx power %d\n", tx_power);
1659 if (tx_power < 0)
1660 tx_power = 0;
1661 else if (tx_power > 18)
1662 tx_power = 18;
1663 ret = wilc_set_tx_power(vif, tx_power);
1664 if (ret)
1665 netdev_err(vif->ndev, "Failed to set tx power\n");
1666 srcu_read_unlock(&wl->srcu, srcu_idx);
1667
1668 return ret;
1669 }
1670
get_tx_power(struct wiphy * wiphy,struct wireless_dev * wdev,int radio_idx,unsigned int link_id,int * dbm)1671 static int get_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev,
1672 int radio_idx, unsigned int link_id, int *dbm)
1673 {
1674 int ret;
1675 struct wilc_vif *vif = netdev_priv(wdev->netdev);
1676 struct wilc *wl = vif->wilc;
1677
1678 /* If firmware is not started, return. */
1679 if (!wl->initialized)
1680 return -EIO;
1681
1682 ret = wilc_get_tx_power(vif, (u8 *)dbm);
1683 if (ret)
1684 netdev_err(vif->ndev, "Failed to get tx power\n");
1685
1686 return ret;
1687 }
1688
1689 static const struct cfg80211_ops wilc_cfg80211_ops = {
1690 .set_monitor_channel = set_channel,
1691 .scan = scan,
1692 .connect = connect,
1693 .disconnect = disconnect,
1694 .add_key = add_key,
1695 .del_key = del_key,
1696 .get_key = get_key,
1697 .set_default_key = set_default_key,
1698 .set_default_mgmt_key = set_default_mgmt_key,
1699 .add_virtual_intf = add_virtual_intf,
1700 .del_virtual_intf = del_virtual_intf,
1701 .change_virtual_intf = change_virtual_intf,
1702
1703 .start_ap = start_ap,
1704 .change_beacon = change_beacon,
1705 .stop_ap = stop_ap,
1706 .add_station = add_station,
1707 .del_station = del_station,
1708 .change_station = change_station,
1709 .get_station = get_station,
1710 .dump_station = dump_station,
1711 .set_wiphy_params = set_wiphy_params,
1712
1713 .external_auth = external_auth,
1714 .set_pmksa = set_pmksa,
1715 .del_pmksa = del_pmksa,
1716 .flush_pmksa = flush_pmksa,
1717 .remain_on_channel = remain_on_channel,
1718 .cancel_remain_on_channel = cancel_remain_on_channel,
1719 .mgmt_tx_cancel_wait = mgmt_tx_cancel_wait,
1720 .mgmt_tx = mgmt_tx,
1721 .update_mgmt_frame_registrations = wilc_update_mgmt_frame_registrations,
1722 .set_power_mgmt = set_power_mgmt,
1723 .set_cqm_rssi_config = set_cqm_rssi_config,
1724
1725 .set_wakeup = wilc_set_wakeup,
1726 .set_tx_power = set_tx_power,
1727 .get_tx_power = get_tx_power,
1728
1729 };
1730
wlan_init_locks(struct wilc * wl)1731 static void wlan_init_locks(struct wilc *wl)
1732 {
1733 mutex_init(&wl->hif_cs);
1734 mutex_init(&wl->rxq_cs);
1735 mutex_init(&wl->cfg_cmd_lock);
1736 mutex_init(&wl->vif_mutex);
1737 mutex_init(&wl->deinit_lock);
1738
1739 spin_lock_init(&wl->txq_spinlock);
1740 mutex_init(&wl->txq_add_to_head_cs);
1741
1742 init_completion(&wl->txq_event);
1743 init_completion(&wl->cfg_event);
1744 init_completion(&wl->sync_event);
1745 init_completion(&wl->txq_thread_started);
1746 init_srcu_struct(&wl->srcu);
1747 }
1748
wlan_deinit_locks(struct wilc * wilc)1749 void wlan_deinit_locks(struct wilc *wilc)
1750 {
1751 mutex_destroy(&wilc->hif_cs);
1752 mutex_destroy(&wilc->rxq_cs);
1753 mutex_destroy(&wilc->cfg_cmd_lock);
1754 mutex_destroy(&wilc->txq_add_to_head_cs);
1755 mutex_destroy(&wilc->vif_mutex);
1756 mutex_destroy(&wilc->deinit_lock);
1757 cleanup_srcu_struct(&wilc->srcu);
1758 }
1759
wilc_create_wiphy(struct device * dev)1760 static struct wilc *wilc_create_wiphy(struct device *dev)
1761 {
1762 struct wiphy *wiphy;
1763 struct wilc *wl;
1764
1765 wiphy = wiphy_new(&wilc_cfg80211_ops, sizeof(*wl));
1766 if (!wiphy)
1767 return NULL;
1768
1769 wl = wiphy_priv(wiphy);
1770
1771 memcpy(wl->bitrates, wilc_bitrates, sizeof(wilc_bitrates));
1772 memcpy(wl->channels, wilc_2ghz_channels, sizeof(wilc_2ghz_channels));
1773 wl->band.bitrates = wl->bitrates;
1774 wl->band.n_bitrates = ARRAY_SIZE(wl->bitrates);
1775 wl->band.channels = wl->channels;
1776 wl->band.n_channels = ARRAY_SIZE(wilc_2ghz_channels);
1777
1778 wl->band.ht_cap.ht_supported = 1;
1779 wl->band.ht_cap.cap |= (1 << IEEE80211_HT_CAP_RX_STBC_SHIFT);
1780 wl->band.ht_cap.mcs.rx_mask[0] = 0xff;
1781 wl->band.ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_8K;
1782 wl->band.ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
1783
1784 wiphy->bands[NL80211_BAND_2GHZ] = &wl->band;
1785
1786 wiphy->max_scan_ssids = WILC_MAX_NUM_PROBED_SSID;
1787 #ifdef CONFIG_PM
1788 wiphy->wowlan = &wowlan_support;
1789 #endif
1790 wiphy->max_num_pmkids = WILC_MAX_NUM_PMKIDS;
1791 wiphy->max_scan_ie_len = 1000;
1792 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
1793 memcpy(wl->cipher_suites, wilc_cipher_suites,
1794 sizeof(wilc_cipher_suites));
1795 wiphy->cipher_suites = wl->cipher_suites;
1796 wiphy->n_cipher_suites = ARRAY_SIZE(wilc_cipher_suites);
1797 wiphy->mgmt_stypes = wilc_wfi_cfg80211_mgmt_types;
1798
1799 wiphy->max_remain_on_channel_duration = 500;
1800 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
1801 BIT(NL80211_IFTYPE_AP) |
1802 BIT(NL80211_IFTYPE_MONITOR) |
1803 BIT(NL80211_IFTYPE_P2P_GO) |
1804 BIT(NL80211_IFTYPE_P2P_CLIENT);
1805 wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
1806 set_wiphy_dev(wiphy, dev);
1807 wl->wiphy = wiphy;
1808 return wl;
1809 }
1810
wilc_cfg80211_init(struct wilc ** wilc,struct device * dev,int io_type,const struct wilc_hif_func * ops)1811 int wilc_cfg80211_init(struct wilc **wilc, struct device *dev, int io_type,
1812 const struct wilc_hif_func *ops)
1813 {
1814 struct wilc *wl;
1815 int ret, i;
1816
1817 wl = wilc_create_wiphy(dev);
1818 if (!wl)
1819 return -EINVAL;
1820
1821 wlan_init_locks(wl);
1822
1823 ret = wilc_wlan_cfg_init(wl);
1824 if (ret)
1825 goto free_wl;
1826
1827 *wilc = wl;
1828 wl->io_type = io_type;
1829 wl->hif_func = ops;
1830
1831 for (i = 0; i < NQUEUES; i++)
1832 INIT_LIST_HEAD(&wl->txq[i].txq_head.list);
1833
1834 INIT_LIST_HEAD(&wl->rxq_head.list);
1835 INIT_LIST_HEAD(&wl->vif_list);
1836
1837 wl->hif_workqueue = alloc_ordered_workqueue("%s", WQ_MEM_RECLAIM,
1838 wiphy_name(wl->wiphy));
1839 if (!wl->hif_workqueue) {
1840 ret = -ENOMEM;
1841 goto free_cfg;
1842 }
1843
1844 return 0;
1845
1846 free_cfg:
1847 wilc_wlan_cfg_deinit(wl);
1848
1849 free_wl:
1850 wlan_deinit_locks(wl);
1851 wiphy_free(wl->wiphy);
1852 return ret;
1853 }
1854 EXPORT_SYMBOL_GPL(wilc_cfg80211_init);
1855
wilc_cfg80211_register(struct wilc * wilc)1856 int wilc_cfg80211_register(struct wilc *wilc)
1857 {
1858 /* WPA3/SAE supported only on WILC1000 */
1859 if (is_wilc1000(wilc->chipid))
1860 wilc->wiphy->features |= NL80211_FEATURE_SAE;
1861
1862 return wiphy_register(wilc->wiphy);
1863 }
1864 EXPORT_SYMBOL_GPL(wilc_cfg80211_register);
1865
wilc_init_host_int(struct net_device * net)1866 int wilc_init_host_int(struct net_device *net)
1867 {
1868 int ret;
1869 struct wilc_vif *vif = netdev_priv(net);
1870 struct wilc_priv *priv = &vif->priv;
1871
1872 priv->p2p_listen_state = false;
1873
1874 mutex_init(&priv->scan_req_lock);
1875 ret = wilc_init(net, &priv->hif_drv);
1876 if (ret)
1877 netdev_err(net, "Error while initializing hostinterface\n");
1878
1879 return ret;
1880 }
1881
wilc_deinit_host_int(struct net_device * net)1882 void wilc_deinit_host_int(struct net_device *net)
1883 {
1884 int ret;
1885 struct wilc_vif *vif = netdev_priv(net);
1886 struct wilc_priv *priv = &vif->priv;
1887
1888 priv->p2p_listen_state = false;
1889
1890 flush_workqueue(vif->wilc->hif_workqueue);
1891 mutex_destroy(&priv->scan_req_lock);
1892 ret = wilc_deinit(vif);
1893
1894 if (ret)
1895 netdev_err(net, "Error while deinitializing host interface\n");
1896 }
1897
1898