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