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, u8 key_index,
544 		   bool pairwise, const u8 *mac_addr, struct key_params *params)
545 
546 {
547 	int ret = 0, keylen = params->key_len;
548 	const u8 *rx_mic = NULL;
549 	const u8 *tx_mic = NULL;
550 	u8 mode = WILC_FW_SEC_NO;
551 	u8 op_mode;
552 	struct wilc_vif *vif = netdev_priv(netdev);
553 	struct wilc_priv *priv = &vif->priv;
554 	struct wilc_wfi_key *key;
555 
556 	switch (params->cipher) {
557 	case WLAN_CIPHER_SUITE_TKIP:
558 	case WLAN_CIPHER_SUITE_CCMP:
559 		if (priv->wdev.iftype == NL80211_IFTYPE_AP ||
560 		    priv->wdev.iftype == NL80211_IFTYPE_P2P_GO) {
561 			struct wilc_wfi_key *key;
562 
563 			ret = wilc_wfi_cfg_allocate_wpa_entry(priv, key_index);
564 			if (ret)
565 				return -ENOMEM;
566 
567 			if (params->key_len > 16 &&
568 			    params->cipher == WLAN_CIPHER_SUITE_TKIP) {
569 				tx_mic = params->key + 24;
570 				rx_mic = params->key + 16;
571 				keylen = params->key_len - 16;
572 			}
573 
574 			if (!pairwise) {
575 				if (params->cipher == WLAN_CIPHER_SUITE_TKIP)
576 					mode = WILC_FW_SEC_WPA_TKIP;
577 				else
578 					mode = WILC_FW_SEC_WPA2_AES;
579 
580 				priv->wilc_groupkey = mode;
581 
582 				key = priv->wilc_gtk[key_index];
583 			} else {
584 				if (params->cipher == WLAN_CIPHER_SUITE_TKIP)
585 					mode = WILC_FW_SEC_WPA_TKIP;
586 				else
587 					mode = priv->wilc_groupkey | WILC_FW_AES;
588 
589 				key = priv->wilc_ptk[key_index];
590 			}
591 			ret = wilc_wfi_cfg_copy_wpa_info(key, params);
592 			if (ret)
593 				return -ENOMEM;
594 
595 			op_mode = WILC_AP_MODE;
596 		} else {
597 			if (params->key_len > 16 &&
598 			    params->cipher == WLAN_CIPHER_SUITE_TKIP) {
599 				rx_mic = params->key + 24;
600 				tx_mic = params->key + 16;
601 				keylen = params->key_len - 16;
602 			}
603 
604 			op_mode = WILC_STATION_MODE;
605 		}
606 
607 		if (!pairwise)
608 			ret = wilc_add_rx_gtk(vif, params->key, keylen,
609 					      key_index, params->seq_len,
610 					      params->seq, rx_mic, tx_mic,
611 					      op_mode, mode);
612 		else
613 			ret = wilc_add_ptk(vif, params->key, keylen, mac_addr,
614 					   rx_mic, tx_mic, op_mode, mode,
615 					   key_index);
616 
617 		break;
618 	case WLAN_CIPHER_SUITE_AES_CMAC:
619 		ret = wilc_wfi_cfg_allocate_wpa_igtk_entry(priv, key_index);
620 		if (ret)
621 			return -ENOMEM;
622 
623 		key = priv->wilc_igtk[key_index - 4];
624 		ret = wilc_wfi_cfg_copy_wpa_info(key, params);
625 		if (ret)
626 			return -ENOMEM;
627 
628 		if (priv->wdev.iftype == NL80211_IFTYPE_AP ||
629 		    priv->wdev.iftype == NL80211_IFTYPE_P2P_GO)
630 			op_mode = WILC_AP_MODE;
631 		else
632 			op_mode = WILC_STATION_MODE;
633 
634 		ret = wilc_add_igtk(vif, params->key, keylen, params->seq,
635 				    params->seq_len, mac_addr, op_mode,
636 				    key_index);
637 		break;
638 
639 	default:
640 		netdev_err(netdev, "%s: Unsupported cipher\n", __func__);
641 		ret = -ENOTSUPP;
642 	}
643 
644 	return ret;
645 }
646 
647 static int del_key(struct wiphy *wiphy, struct net_device *netdev,
648 		   u8 key_index,
649 		   bool pairwise,
650 		   const u8 *mac_addr)
651 {
652 	struct wilc_vif *vif = netdev_priv(netdev);
653 	struct wilc_priv *priv = &vif->priv;
654 
655 	if (!pairwise && (key_index == 4 || key_index == 5)) {
656 		key_index -= 4;
657 		if (priv->wilc_igtk[key_index]) {
658 			kfree(priv->wilc_igtk[key_index]->key);
659 			priv->wilc_igtk[key_index]->key = NULL;
660 			kfree(priv->wilc_igtk[key_index]->seq);
661 			priv->wilc_igtk[key_index]->seq = NULL;
662 			kfree(priv->wilc_igtk[key_index]);
663 			priv->wilc_igtk[key_index] = NULL;
664 		}
665 	} else {
666 		if (priv->wilc_gtk[key_index]) {
667 			kfree(priv->wilc_gtk[key_index]->key);
668 			priv->wilc_gtk[key_index]->key = NULL;
669 			kfree(priv->wilc_gtk[key_index]->seq);
670 			priv->wilc_gtk[key_index]->seq = NULL;
671 
672 			kfree(priv->wilc_gtk[key_index]);
673 			priv->wilc_gtk[key_index] = NULL;
674 		}
675 		if (priv->wilc_ptk[key_index]) {
676 			kfree(priv->wilc_ptk[key_index]->key);
677 			priv->wilc_ptk[key_index]->key = NULL;
678 			kfree(priv->wilc_ptk[key_index]->seq);
679 			priv->wilc_ptk[key_index]->seq = NULL;
680 			kfree(priv->wilc_ptk[key_index]);
681 			priv->wilc_ptk[key_index] = NULL;
682 		}
683 	}
684 
685 	return 0;
686 }
687 
688 static int get_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
689 		   bool pairwise, const u8 *mac_addr, void *cookie,
690 		   void (*callback)(void *cookie, struct key_params *))
691 {
692 	struct wilc_vif *vif = netdev_priv(netdev);
693 	struct wilc_priv *priv = &vif->priv;
694 	struct  key_params key_params;
695 
696 	if (!pairwise) {
697 		if (key_index == 4 || key_index == 5) {
698 			key_index -= 4;
699 			key_params.key = priv->wilc_igtk[key_index]->key;
700 			key_params.cipher = priv->wilc_igtk[key_index]->cipher;
701 			key_params.key_len = priv->wilc_igtk[key_index]->key_len;
702 			key_params.seq = priv->wilc_igtk[key_index]->seq;
703 			key_params.seq_len = priv->wilc_igtk[key_index]->seq_len;
704 		} else {
705 			key_params.key = priv->wilc_gtk[key_index]->key;
706 			key_params.cipher = priv->wilc_gtk[key_index]->cipher;
707 			key_params.key_len = priv->wilc_gtk[key_index]->key_len;
708 			key_params.seq = priv->wilc_gtk[key_index]->seq;
709 			key_params.seq_len = priv->wilc_gtk[key_index]->seq_len;
710 		}
711 	} else {
712 		key_params.key = priv->wilc_ptk[key_index]->key;
713 		key_params.cipher = priv->wilc_ptk[key_index]->cipher;
714 		key_params.key_len = priv->wilc_ptk[key_index]->key_len;
715 		key_params.seq = priv->wilc_ptk[key_index]->seq;
716 		key_params.seq_len = priv->wilc_ptk[key_index]->seq_len;
717 	}
718 
719 	callback(cookie, &key_params);
720 
721 	return 0;
722 }
723 
724 /* wiphy_new_nm() will WARNON if not present */
725 static int set_default_key(struct wiphy *wiphy, struct net_device *netdev,
726 			   u8 key_index, bool unicast, bool multicast)
727 {
728 	return 0;
729 }
730 
731 static int set_default_mgmt_key(struct wiphy *wiphy, struct net_device *netdev,
732 				u8 key_index)
733 {
734 	struct wilc_vif *vif = netdev_priv(netdev);
735 
736 	return wilc_set_default_mgmt_key_index(vif, key_index);
737 }
738 
739 static int get_station(struct wiphy *wiphy, struct net_device *dev,
740 		       const u8 *mac, struct station_info *sinfo)
741 {
742 	struct wilc_vif *vif = netdev_priv(dev);
743 	struct wilc_priv *priv = &vif->priv;
744 	struct wilc *wilc = vif->wilc;
745 	u32 i = 0;
746 	u32 associatedsta = ~0;
747 	u32 inactive_time = 0;
748 
749 	if (vif->iftype == WILC_AP_MODE || vif->iftype == WILC_GO_MODE) {
750 		for (i = 0; i < NUM_STA_ASSOCIATED; i++) {
751 			if (!(memcmp(mac,
752 				     priv->assoc_stainfo.sta_associated_bss[i],
753 				     ETH_ALEN))) {
754 				associatedsta = i;
755 				break;
756 			}
757 		}
758 
759 		if (associatedsta == ~0) {
760 			netdev_err(dev, "sta required is not associated\n");
761 			return -ENOENT;
762 		}
763 
764 		sinfo->filled |= BIT_ULL(NL80211_STA_INFO_INACTIVE_TIME);
765 
766 		wilc_get_inactive_time(vif, mac, &inactive_time);
767 		sinfo->inactive_time = 1000 * inactive_time;
768 	} else if (vif->iftype == WILC_STATION_MODE) {
769 		struct rf_info stats;
770 
771 		if (!wilc->initialized)
772 			return -EBUSY;
773 
774 		wilc_get_statistics(vif, &stats);
775 
776 		sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL) |
777 				 BIT_ULL(NL80211_STA_INFO_RX_PACKETS) |
778 				 BIT_ULL(NL80211_STA_INFO_TX_PACKETS) |
779 				 BIT_ULL(NL80211_STA_INFO_TX_FAILED) |
780 				 BIT_ULL(NL80211_STA_INFO_TX_BITRATE);
781 
782 		sinfo->signal = stats.rssi;
783 		sinfo->rx_packets = stats.rx_cnt;
784 		sinfo->tx_packets = stats.tx_cnt + stats.tx_fail_cnt;
785 		sinfo->tx_failed = stats.tx_fail_cnt;
786 		sinfo->txrate.legacy = stats.link_speed * 10;
787 
788 		if (stats.link_speed > TCP_ACK_FILTER_LINK_SPEED_THRESH &&
789 		    stats.link_speed != DEFAULT_LINK_SPEED)
790 			wilc_enable_tcp_ack_filter(vif, true);
791 		else if (stats.link_speed != DEFAULT_LINK_SPEED)
792 			wilc_enable_tcp_ack_filter(vif, false);
793 	}
794 	return 0;
795 }
796 
797 static int change_bss(struct wiphy *wiphy, struct net_device *dev,
798 		      struct bss_parameters *params)
799 {
800 	return 0;
801 }
802 
803 static int set_wiphy_params(struct wiphy *wiphy, u32 changed)
804 {
805 	int ret = -EINVAL;
806 	struct cfg_param_attr cfg_param_val;
807 	struct wilc *wl = wiphy_priv(wiphy);
808 	struct wilc_vif *vif;
809 	struct wilc_priv *priv;
810 	int srcu_idx;
811 
812 	srcu_idx = srcu_read_lock(&wl->srcu);
813 	vif = wilc_get_wl_to_vif(wl);
814 	if (IS_ERR(vif))
815 		goto out;
816 
817 	priv = &vif->priv;
818 	cfg_param_val.flag = 0;
819 
820 	if (changed & WIPHY_PARAM_RETRY_SHORT) {
821 		netdev_dbg(vif->ndev,
822 			   "Setting WIPHY_PARAM_RETRY_SHORT %d\n",
823 			   wiphy->retry_short);
824 		cfg_param_val.flag  |= WILC_CFG_PARAM_RETRY_SHORT;
825 		cfg_param_val.short_retry_limit = wiphy->retry_short;
826 	}
827 	if (changed & WIPHY_PARAM_RETRY_LONG) {
828 		netdev_dbg(vif->ndev,
829 			   "Setting WIPHY_PARAM_RETRY_LONG %d\n",
830 			   wiphy->retry_long);
831 		cfg_param_val.flag |= WILC_CFG_PARAM_RETRY_LONG;
832 		cfg_param_val.long_retry_limit = wiphy->retry_long;
833 	}
834 	if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
835 		if (wiphy->frag_threshold > 255 &&
836 		    wiphy->frag_threshold < 7937) {
837 			netdev_dbg(vif->ndev,
838 				   "Setting WIPHY_PARAM_FRAG_THRESHOLD %d\n",
839 				   wiphy->frag_threshold);
840 			cfg_param_val.flag |= WILC_CFG_PARAM_FRAG_THRESHOLD;
841 			cfg_param_val.frag_threshold = wiphy->frag_threshold;
842 		} else {
843 			netdev_err(vif->ndev,
844 				   "Fragmentation threshold out of range\n");
845 			goto out;
846 		}
847 	}
848 
849 	if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
850 		if (wiphy->rts_threshold > 255) {
851 			netdev_dbg(vif->ndev,
852 				   "Setting WIPHY_PARAM_RTS_THRESHOLD %d\n",
853 				   wiphy->rts_threshold);
854 			cfg_param_val.flag |= WILC_CFG_PARAM_RTS_THRESHOLD;
855 			cfg_param_val.rts_threshold = wiphy->rts_threshold;
856 		} else {
857 			netdev_err(vif->ndev, "RTS threshold out of range\n");
858 			goto out;
859 		}
860 	}
861 
862 	ret = wilc_hif_set_cfg(vif, &cfg_param_val);
863 	if (ret)
864 		netdev_err(priv->dev, "Error in setting WIPHY PARAMS\n");
865 
866 out:
867 	srcu_read_unlock(&wl->srcu, srcu_idx);
868 	return ret;
869 }
870 
871 static int set_pmksa(struct wiphy *wiphy, struct net_device *netdev,
872 		     struct cfg80211_pmksa *pmksa)
873 {
874 	struct wilc_vif *vif = netdev_priv(netdev);
875 	struct wilc_priv *priv = &vif->priv;
876 	u32 i;
877 	int ret = 0;
878 	u8 flag = 0;
879 
880 	for (i = 0; i < priv->pmkid_list.numpmkid; i++)	{
881 		if (!memcmp(pmksa->bssid, priv->pmkid_list.pmkidlist[i].bssid,
882 			    ETH_ALEN)) {
883 			flag = PMKID_FOUND;
884 			break;
885 		}
886 	}
887 	if (i < WILC_MAX_NUM_PMKIDS) {
888 		memcpy(priv->pmkid_list.pmkidlist[i].bssid, pmksa->bssid,
889 		       ETH_ALEN);
890 		memcpy(priv->pmkid_list.pmkidlist[i].pmkid, pmksa->pmkid,
891 		       WLAN_PMKID_LEN);
892 		if (!(flag == PMKID_FOUND))
893 			priv->pmkid_list.numpmkid++;
894 	} else {
895 		netdev_err(netdev, "Invalid PMKID index\n");
896 		ret = -EINVAL;
897 	}
898 
899 	if (!ret)
900 		ret = wilc_set_pmkid_info(vif, &priv->pmkid_list);
901 
902 	return ret;
903 }
904 
905 static int del_pmksa(struct wiphy *wiphy, struct net_device *netdev,
906 		     struct cfg80211_pmksa *pmksa)
907 {
908 	u32 i;
909 	struct wilc_vif *vif = netdev_priv(netdev);
910 	struct wilc_priv *priv = &vif->priv;
911 
912 	for (i = 0; i < priv->pmkid_list.numpmkid; i++)	{
913 		if (!memcmp(pmksa->bssid, priv->pmkid_list.pmkidlist[i].bssid,
914 			    ETH_ALEN)) {
915 			memset(&priv->pmkid_list.pmkidlist[i], 0,
916 			       sizeof(struct wilc_pmkid));
917 			break;
918 		}
919 	}
920 
921 	if (i == priv->pmkid_list.numpmkid)
922 		return -EINVAL;
923 
924 	for (; i < (priv->pmkid_list.numpmkid - 1); i++) {
925 		memcpy(priv->pmkid_list.pmkidlist[i].bssid,
926 		       priv->pmkid_list.pmkidlist[i + 1].bssid,
927 		       ETH_ALEN);
928 		memcpy(priv->pmkid_list.pmkidlist[i].pmkid,
929 		       priv->pmkid_list.pmkidlist[i + 1].pmkid,
930 		       WLAN_PMKID_LEN);
931 	}
932 	priv->pmkid_list.numpmkid--;
933 
934 	return 0;
935 }
936 
937 static int flush_pmksa(struct wiphy *wiphy, struct net_device *netdev)
938 {
939 	struct wilc_vif *vif = netdev_priv(netdev);
940 
941 	memset(&vif->priv.pmkid_list, 0, sizeof(struct wilc_pmkid_attr));
942 
943 	return 0;
944 }
945 
946 static inline void wilc_wfi_cfg_parse_ch_attr(u8 *buf, u32 len, u8 sta_ch)
947 {
948 	struct wilc_attr_entry *e;
949 	struct wilc_attr_ch_list *ch_list;
950 	struct wilc_attr_oper_ch *op_ch;
951 	u32 index = 0;
952 	u8 ch_list_idx = 0;
953 	u8 op_ch_idx = 0;
954 
955 	if (sta_ch == WILC_INVALID_CHANNEL)
956 		return;
957 
958 	while (index + sizeof(*e) <= len) {
959 		e = (struct wilc_attr_entry *)&buf[index];
960 		if (e->attr_type == IEEE80211_P2P_ATTR_CHANNEL_LIST)
961 			ch_list_idx = index;
962 		else if (e->attr_type == IEEE80211_P2P_ATTR_OPER_CHANNEL)
963 			op_ch_idx = index;
964 		if (ch_list_idx && op_ch_idx)
965 			break;
966 		index += le16_to_cpu(e->attr_len) + sizeof(*e);
967 	}
968 
969 	if (ch_list_idx) {
970 		u16 attr_size;
971 		struct wilc_ch_list_elem *e;
972 		int i;
973 
974 		ch_list = (struct wilc_attr_ch_list *)&buf[ch_list_idx];
975 		attr_size = le16_to_cpu(ch_list->attr_len);
976 		for (i = 0; i < attr_size;) {
977 			e = (struct wilc_ch_list_elem *)(ch_list->elem + i);
978 			if (e->op_class == WILC_WLAN_OPERATING_CLASS_2_4GHZ) {
979 				memset(e->ch_list, sta_ch, e->no_of_channels);
980 				break;
981 			}
982 			i += e->no_of_channels;
983 		}
984 	}
985 
986 	if (op_ch_idx) {
987 		op_ch = (struct wilc_attr_oper_ch *)&buf[op_ch_idx];
988 		op_ch->op_class = WILC_WLAN_OPERATING_CLASS_2_4GHZ;
989 		op_ch->op_channel = sta_ch;
990 	}
991 }
992 
993 bool wilc_wfi_mgmt_frame_rx(struct wilc_vif *vif, u8 *buff, u32 size)
994 {
995 	struct wilc *wl = vif->wilc;
996 	struct wilc_priv *priv = &vif->priv;
997 	int freq, ret;
998 
999 	freq = ieee80211_channel_to_frequency(wl->op_ch, NL80211_BAND_2GHZ);
1000 	ret = cfg80211_rx_mgmt(&priv->wdev, freq, 0, buff, size, 0);
1001 
1002 	return ret;
1003 }
1004 
1005 void wilc_wfi_p2p_rx(struct wilc_vif *vif, u8 *buff, u32 size)
1006 {
1007 	struct wilc *wl = vif->wilc;
1008 	struct wilc_priv *priv = &vif->priv;
1009 	struct host_if_drv *wfi_drv = priv->hif_drv;
1010 	struct ieee80211_mgmt *mgmt;
1011 	struct wilc_vendor_specific_ie *p;
1012 	struct wilc_p2p_pub_act_frame *d;
1013 	int ie_offset = offsetof(struct ieee80211_mgmt, u) + sizeof(*d);
1014 	const u8 *vendor_ie;
1015 	u32 header, pkt_offset;
1016 	s32 freq;
1017 
1018 	header = get_unaligned_le32(buff - HOST_HDR_OFFSET);
1019 	pkt_offset = FIELD_GET(WILC_PKT_HDR_OFFSET_FIELD, header);
1020 
1021 	if (pkt_offset & IS_MANAGMEMENT_CALLBACK) {
1022 		bool ack = false;
1023 		struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)buff;
1024 
1025 		if (ieee80211_is_probe_resp(hdr->frame_control) ||
1026 		    pkt_offset & IS_MGMT_STATUS_SUCCES)
1027 			ack = true;
1028 
1029 		cfg80211_mgmt_tx_status(&priv->wdev, priv->tx_cookie, buff,
1030 					size, ack, GFP_KERNEL);
1031 		return;
1032 	}
1033 
1034 	freq = ieee80211_channel_to_frequency(wl->op_ch, NL80211_BAND_2GHZ);
1035 
1036 	mgmt = (struct ieee80211_mgmt *)buff;
1037 	if (!ieee80211_is_action(mgmt->frame_control))
1038 		goto out_rx_mgmt;
1039 
1040 	if (priv->cfg_scanning &&
1041 	    time_after_eq(jiffies, (unsigned long)wfi_drv->p2p_timeout)) {
1042 		netdev_dbg(vif->ndev, "Receiving action wrong ch\n");
1043 		return;
1044 	}
1045 
1046 	if (!ieee80211_is_public_action((struct ieee80211_hdr *)buff, size))
1047 		goto out_rx_mgmt;
1048 
1049 	d = (struct wilc_p2p_pub_act_frame *)(&mgmt->u.action);
1050 	if (d->oui_subtype != GO_NEG_REQ && d->oui_subtype != GO_NEG_RSP &&
1051 	    d->oui_subtype != P2P_INV_REQ && d->oui_subtype != P2P_INV_RSP)
1052 		goto out_rx_mgmt;
1053 
1054 	vendor_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1055 					    buff + ie_offset, size - ie_offset);
1056 	if (!vendor_ie)
1057 		goto out_rx_mgmt;
1058 
1059 	p = (struct wilc_vendor_specific_ie *)vendor_ie;
1060 	wilc_wfi_cfg_parse_ch_attr(p->attr, p->tag_len - 4, vif->wilc->sta_ch);
1061 
1062 out_rx_mgmt:
1063 	cfg80211_rx_mgmt(&priv->wdev, freq, 0, buff, size, 0);
1064 }
1065 
1066 static void wilc_wfi_mgmt_tx_complete(void *priv, int status)
1067 {
1068 	struct wilc_p2p_mgmt_data *pv_data = priv;
1069 
1070 	kfree(pv_data->buff);
1071 	kfree(pv_data);
1072 }
1073 
1074 static void wilc_wfi_remain_on_channel_expired(void *data, u64 cookie)
1075 {
1076 	struct wilc_vif *vif = data;
1077 	struct wilc_priv *priv = &vif->priv;
1078 	struct wilc_wfi_p2p_listen_params *params = &priv->remain_on_ch_params;
1079 
1080 	if (cookie != params->listen_cookie)
1081 		return;
1082 
1083 	priv->p2p_listen_state = false;
1084 
1085 	cfg80211_remain_on_channel_expired(&priv->wdev, params->listen_cookie,
1086 					   params->listen_ch, GFP_KERNEL);
1087 }
1088 
1089 static int remain_on_channel(struct wiphy *wiphy,
1090 			     struct wireless_dev *wdev,
1091 			     struct ieee80211_channel *chan,
1092 			     unsigned int duration, u64 *cookie)
1093 {
1094 	int ret = 0;
1095 	struct wilc_vif *vif = netdev_priv(wdev->netdev);
1096 	struct wilc_priv *priv = &vif->priv;
1097 	u64 id;
1098 
1099 	if (wdev->iftype == NL80211_IFTYPE_AP) {
1100 		netdev_dbg(vif->ndev, "Required while in AP mode\n");
1101 		return ret;
1102 	}
1103 
1104 	id = ++priv->inc_roc_cookie;
1105 	if (id == 0)
1106 		id = ++priv->inc_roc_cookie;
1107 
1108 	ret = wilc_remain_on_channel(vif, id, duration, chan->hw_value,
1109 				     wilc_wfi_remain_on_channel_expired,
1110 				     (void *)vif);
1111 	if (ret)
1112 		return ret;
1113 
1114 	vif->wilc->op_ch = chan->hw_value;
1115 
1116 	priv->remain_on_ch_params.listen_ch = chan;
1117 	priv->remain_on_ch_params.listen_cookie = id;
1118 	*cookie = id;
1119 	priv->p2p_listen_state = true;
1120 	priv->remain_on_ch_params.listen_duration = duration;
1121 
1122 	cfg80211_ready_on_channel(wdev, *cookie, chan, duration, GFP_KERNEL);
1123 	mod_timer(&vif->hif_drv->remain_on_ch_timer,
1124 		  jiffies + msecs_to_jiffies(duration + 1000));
1125 
1126 	return ret;
1127 }
1128 
1129 static int cancel_remain_on_channel(struct wiphy *wiphy,
1130 				    struct wireless_dev *wdev,
1131 				    u64 cookie)
1132 {
1133 	struct wilc_vif *vif = netdev_priv(wdev->netdev);
1134 	struct wilc_priv *priv = &vif->priv;
1135 
1136 	if (cookie != priv->remain_on_ch_params.listen_cookie)
1137 		return -ENOENT;
1138 
1139 	return wilc_listen_state_expired(vif, cookie);
1140 }
1141 
1142 static int mgmt_tx(struct wiphy *wiphy,
1143 		   struct wireless_dev *wdev,
1144 		   struct cfg80211_mgmt_tx_params *params,
1145 		   u64 *cookie)
1146 {
1147 	struct ieee80211_channel *chan = params->chan;
1148 	unsigned int wait = params->wait;
1149 	const u8 *buf = params->buf;
1150 	size_t len = params->len;
1151 	const struct ieee80211_mgmt *mgmt;
1152 	struct wilc_p2p_mgmt_data *mgmt_tx;
1153 	struct wilc_vif *vif = netdev_priv(wdev->netdev);
1154 	struct wilc_priv *priv = &vif->priv;
1155 	struct host_if_drv *wfi_drv = priv->hif_drv;
1156 	struct wilc_vendor_specific_ie *p;
1157 	struct wilc_p2p_pub_act_frame *d;
1158 	int ie_offset = offsetof(struct ieee80211_mgmt, u) + sizeof(*d);
1159 	const u8 *vendor_ie;
1160 	int ret = 0;
1161 
1162 	*cookie = prandom_u32();
1163 	priv->tx_cookie = *cookie;
1164 	mgmt = (const struct ieee80211_mgmt *)buf;
1165 
1166 	if (!ieee80211_is_mgmt(mgmt->frame_control))
1167 		goto out;
1168 
1169 	mgmt_tx = kmalloc(sizeof(*mgmt_tx), GFP_KERNEL);
1170 	if (!mgmt_tx) {
1171 		ret = -ENOMEM;
1172 		goto out;
1173 	}
1174 
1175 	mgmt_tx->buff = kmemdup(buf, len, GFP_KERNEL);
1176 	if (!mgmt_tx->buff) {
1177 		ret = -ENOMEM;
1178 		kfree(mgmt_tx);
1179 		goto out;
1180 	}
1181 
1182 	mgmt_tx->size = len;
1183 
1184 	if (ieee80211_is_probe_resp(mgmt->frame_control)) {
1185 		wilc_set_mac_chnl_num(vif, chan->hw_value);
1186 		vif->wilc->op_ch = chan->hw_value;
1187 		goto out_txq_add_pkt;
1188 	}
1189 
1190 	if (!ieee80211_is_public_action((struct ieee80211_hdr *)buf, len)) {
1191 		if (chan)
1192 			wilc_set_mac_chnl_num(vif, chan->hw_value);
1193 		else
1194 			wilc_set_mac_chnl_num(vif, vif->wilc->op_ch);
1195 
1196 		goto out_set_timeout;
1197 	}
1198 
1199 	d = (struct wilc_p2p_pub_act_frame *)(&mgmt->u.action);
1200 	if (d->oui_type != WLAN_OUI_TYPE_WFA_P2P ||
1201 	    d->oui_subtype != GO_NEG_CONF) {
1202 		wilc_set_mac_chnl_num(vif, chan->hw_value);
1203 		vif->wilc->op_ch = chan->hw_value;
1204 	}
1205 
1206 	if (d->oui_subtype != P2P_INV_REQ && d->oui_subtype != P2P_INV_RSP)
1207 		goto out_set_timeout;
1208 
1209 	vendor_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1210 					    mgmt_tx->buff + ie_offset,
1211 					    len - ie_offset);
1212 	if (!vendor_ie)
1213 		goto out_set_timeout;
1214 
1215 	p = (struct wilc_vendor_specific_ie *)vendor_ie;
1216 	wilc_wfi_cfg_parse_ch_attr(p->attr, p->tag_len - 4, vif->wilc->sta_ch);
1217 
1218 out_set_timeout:
1219 	wfi_drv->p2p_timeout = (jiffies + msecs_to_jiffies(wait));
1220 
1221 out_txq_add_pkt:
1222 
1223 	wilc_wlan_txq_add_mgmt_pkt(wdev->netdev, mgmt_tx,
1224 				   mgmt_tx->buff, mgmt_tx->size,
1225 				   wilc_wfi_mgmt_tx_complete);
1226 
1227 out:
1228 
1229 	return ret;
1230 }
1231 
1232 static int mgmt_tx_cancel_wait(struct wiphy *wiphy,
1233 			       struct wireless_dev *wdev,
1234 			       u64 cookie)
1235 {
1236 	struct wilc_vif *vif = netdev_priv(wdev->netdev);
1237 	struct wilc_priv *priv = &vif->priv;
1238 	struct host_if_drv *wfi_drv = priv->hif_drv;
1239 
1240 	wfi_drv->p2p_timeout = jiffies;
1241 
1242 	if (!priv->p2p_listen_state) {
1243 		struct wilc_wfi_p2p_listen_params *params;
1244 
1245 		params = &priv->remain_on_ch_params;
1246 
1247 		cfg80211_remain_on_channel_expired(wdev,
1248 						   params->listen_cookie,
1249 						   params->listen_ch,
1250 						   GFP_KERNEL);
1251 	}
1252 
1253 	return 0;
1254 }
1255 
1256 void wilc_update_mgmt_frame_registrations(struct wiphy *wiphy,
1257 					  struct wireless_dev *wdev,
1258 					  struct mgmt_frame_regs *upd)
1259 {
1260 	struct wilc *wl = wiphy_priv(wiphy);
1261 	struct wilc_vif *vif = netdev_priv(wdev->netdev);
1262 	u32 presp_bit = BIT(IEEE80211_STYPE_PROBE_REQ >> 4);
1263 	u32 action_bit = BIT(IEEE80211_STYPE_ACTION >> 4);
1264 	u32 pauth_bit = BIT(IEEE80211_STYPE_AUTH >> 4);
1265 
1266 	if (wl->initialized) {
1267 		bool prev = vif->mgmt_reg_stypes & presp_bit;
1268 		bool now = upd->interface_stypes & presp_bit;
1269 
1270 		if (now != prev)
1271 			wilc_frame_register(vif, IEEE80211_STYPE_PROBE_REQ, now);
1272 
1273 		prev = vif->mgmt_reg_stypes & action_bit;
1274 		now = upd->interface_stypes & action_bit;
1275 
1276 		if (now != prev)
1277 			wilc_frame_register(vif, IEEE80211_STYPE_ACTION, now);
1278 
1279 		prev = vif->mgmt_reg_stypes & pauth_bit;
1280 		now = upd->interface_stypes & pauth_bit;
1281 		if (now != prev)
1282 			wilc_frame_register(vif, IEEE80211_STYPE_AUTH, now);
1283 	}
1284 
1285 	vif->mgmt_reg_stypes =
1286 		upd->interface_stypes & (presp_bit | action_bit | pauth_bit);
1287 }
1288 
1289 static int external_auth(struct wiphy *wiphy, struct net_device *dev,
1290 			 struct cfg80211_external_auth_params *auth)
1291 {
1292 	struct wilc_vif *vif = netdev_priv(dev);
1293 
1294 	if (auth->status == WLAN_STATUS_SUCCESS)
1295 		wilc_set_external_auth_param(vif, auth);
1296 
1297 	return 0;
1298 }
1299 
1300 static int set_cqm_rssi_config(struct wiphy *wiphy, struct net_device *dev,
1301 			       s32 rssi_thold, u32 rssi_hyst)
1302 {
1303 	return 0;
1304 }
1305 
1306 static int dump_station(struct wiphy *wiphy, struct net_device *dev,
1307 			int idx, u8 *mac, struct station_info *sinfo)
1308 {
1309 	struct wilc_vif *vif = netdev_priv(dev);
1310 	int ret;
1311 
1312 	if (idx != 0)
1313 		return -ENOENT;
1314 
1315 	sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL);
1316 
1317 	ret = wilc_get_rssi(vif, &sinfo->signal);
1318 	if (ret)
1319 		return ret;
1320 
1321 	memcpy(mac, vif->priv.associated_bss, ETH_ALEN);
1322 	return 0;
1323 }
1324 
1325 static int set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
1326 			  bool enabled, int timeout)
1327 {
1328 	struct wilc_vif *vif = netdev_priv(dev);
1329 	struct wilc_priv *priv = &vif->priv;
1330 
1331 	if (!priv->hif_drv)
1332 		return -EIO;
1333 
1334 	wilc_set_power_mgmt(vif, enabled, timeout);
1335 
1336 	return 0;
1337 }
1338 
1339 static int change_virtual_intf(struct wiphy *wiphy, struct net_device *dev,
1340 			       enum nl80211_iftype type,
1341 			       struct vif_params *params)
1342 {
1343 	struct wilc *wl = wiphy_priv(wiphy);
1344 	struct wilc_vif *vif = netdev_priv(dev);
1345 	struct wilc_priv *priv = &vif->priv;
1346 
1347 	switch (type) {
1348 	case NL80211_IFTYPE_STATION:
1349 		vif->connecting = false;
1350 		dev->ieee80211_ptr->iftype = type;
1351 		priv->wdev.iftype = type;
1352 		vif->monitor_flag = 0;
1353 		if (vif->iftype == WILC_AP_MODE || vif->iftype == WILC_GO_MODE)
1354 			wilc_wfi_deinit_mon_interface(wl, true);
1355 		vif->iftype = WILC_STATION_MODE;
1356 
1357 		if (wl->initialized)
1358 			wilc_set_operation_mode(vif, wilc_get_vif_idx(vif),
1359 						WILC_STATION_MODE, vif->idx);
1360 
1361 		memset(priv->assoc_stainfo.sta_associated_bss, 0,
1362 		       WILC_MAX_NUM_STA * ETH_ALEN);
1363 		break;
1364 
1365 	case NL80211_IFTYPE_P2P_CLIENT:
1366 		vif->connecting = false;
1367 		dev->ieee80211_ptr->iftype = type;
1368 		priv->wdev.iftype = type;
1369 		vif->monitor_flag = 0;
1370 		vif->iftype = WILC_CLIENT_MODE;
1371 
1372 		if (wl->initialized)
1373 			wilc_set_operation_mode(vif, wilc_get_vif_idx(vif),
1374 						WILC_STATION_MODE, vif->idx);
1375 		break;
1376 
1377 	case NL80211_IFTYPE_AP:
1378 		dev->ieee80211_ptr->iftype = type;
1379 		priv->wdev.iftype = type;
1380 		vif->iftype = WILC_AP_MODE;
1381 
1382 		if (wl->initialized)
1383 			wilc_set_operation_mode(vif, wilc_get_vif_idx(vif),
1384 						WILC_AP_MODE, vif->idx);
1385 		break;
1386 
1387 	case NL80211_IFTYPE_P2P_GO:
1388 		dev->ieee80211_ptr->iftype = type;
1389 		priv->wdev.iftype = type;
1390 		vif->iftype = WILC_GO_MODE;
1391 
1392 		if (wl->initialized)
1393 			wilc_set_operation_mode(vif, wilc_get_vif_idx(vif),
1394 						WILC_AP_MODE, vif->idx);
1395 		break;
1396 
1397 	default:
1398 		netdev_err(dev, "Unknown interface type= %d\n", type);
1399 		return -EINVAL;
1400 	}
1401 
1402 	return 0;
1403 }
1404 
1405 static int start_ap(struct wiphy *wiphy, struct net_device *dev,
1406 		    struct cfg80211_ap_settings *settings)
1407 {
1408 	struct wilc_vif *vif = netdev_priv(dev);
1409 	int ret;
1410 
1411 	ret = set_channel(wiphy, &settings->chandef);
1412 	if (ret != 0)
1413 		netdev_err(dev, "Error in setting channel\n");
1414 
1415 	wilc_wlan_set_bssid(dev, dev->dev_addr, WILC_AP_MODE);
1416 
1417 	return wilc_add_beacon(vif, settings->beacon_interval,
1418 				   settings->dtim_period, &settings->beacon);
1419 }
1420 
1421 static int change_beacon(struct wiphy *wiphy, struct net_device *dev,
1422 			 struct cfg80211_beacon_data *beacon)
1423 {
1424 	struct wilc_vif *vif = netdev_priv(dev);
1425 
1426 	return wilc_add_beacon(vif, 0, 0, beacon);
1427 }
1428 
1429 static int stop_ap(struct wiphy *wiphy, struct net_device *dev)
1430 {
1431 	int ret;
1432 	struct wilc_vif *vif = netdev_priv(dev);
1433 
1434 	wilc_wlan_set_bssid(dev, NULL, WILC_AP_MODE);
1435 
1436 	ret = wilc_del_beacon(vif);
1437 
1438 	if (ret)
1439 		netdev_err(dev, "Host delete beacon fail\n");
1440 
1441 	return ret;
1442 }
1443 
1444 static int add_station(struct wiphy *wiphy, struct net_device *dev,
1445 		       const u8 *mac, struct station_parameters *params)
1446 {
1447 	int ret = 0;
1448 	struct wilc_vif *vif = netdev_priv(dev);
1449 	struct wilc_priv *priv = &vif->priv;
1450 
1451 	if (vif->iftype == WILC_AP_MODE || vif->iftype == WILC_GO_MODE) {
1452 		memcpy(priv->assoc_stainfo.sta_associated_bss[params->aid], mac,
1453 		       ETH_ALEN);
1454 
1455 		ret = wilc_add_station(vif, mac, params);
1456 		if (ret)
1457 			netdev_err(dev, "Host add station fail\n");
1458 	}
1459 
1460 	return ret;
1461 }
1462 
1463 static int del_station(struct wiphy *wiphy, struct net_device *dev,
1464 		       struct station_del_parameters *params)
1465 {
1466 	const u8 *mac = params->mac;
1467 	int ret = 0;
1468 	struct wilc_vif *vif = netdev_priv(dev);
1469 	struct wilc_priv *priv = &vif->priv;
1470 	struct sta_info *info;
1471 
1472 	if (!(vif->iftype == WILC_AP_MODE || vif->iftype == WILC_GO_MODE))
1473 		return ret;
1474 
1475 	info = &priv->assoc_stainfo;
1476 
1477 	if (!mac)
1478 		ret = wilc_del_allstation(vif, info->sta_associated_bss);
1479 
1480 	ret = wilc_del_station(vif, mac);
1481 	if (ret)
1482 		netdev_err(dev, "Host delete station fail\n");
1483 	return ret;
1484 }
1485 
1486 static int change_station(struct wiphy *wiphy, struct net_device *dev,
1487 			  const u8 *mac, struct station_parameters *params)
1488 {
1489 	int ret = 0;
1490 	struct wilc_vif *vif = netdev_priv(dev);
1491 
1492 	if (vif->iftype == WILC_AP_MODE || vif->iftype == WILC_GO_MODE) {
1493 		ret = wilc_edit_station(vif, mac, params);
1494 		if (ret)
1495 			netdev_err(dev, "Host edit station fail\n");
1496 	}
1497 	return ret;
1498 }
1499 
1500 static struct wilc_vif *wilc_get_vif_from_type(struct wilc *wl, int type)
1501 {
1502 	struct wilc_vif *vif;
1503 
1504 	list_for_each_entry_rcu(vif, &wl->vif_list, list) {
1505 		if (vif->iftype == type)
1506 			return vif;
1507 	}
1508 
1509 	return NULL;
1510 }
1511 
1512 static struct wireless_dev *add_virtual_intf(struct wiphy *wiphy,
1513 					     const char *name,
1514 					     unsigned char name_assign_type,
1515 					     enum nl80211_iftype type,
1516 					     struct vif_params *params)
1517 {
1518 	struct wilc *wl = wiphy_priv(wiphy);
1519 	struct wilc_vif *vif;
1520 	struct wireless_dev *wdev;
1521 	int iftype;
1522 
1523 	if (type == NL80211_IFTYPE_MONITOR) {
1524 		struct net_device *ndev;
1525 		int srcu_idx;
1526 
1527 		srcu_idx = srcu_read_lock(&wl->srcu);
1528 		vif = wilc_get_vif_from_type(wl, WILC_AP_MODE);
1529 		if (!vif) {
1530 			vif = wilc_get_vif_from_type(wl, WILC_GO_MODE);
1531 			if (!vif) {
1532 				srcu_read_unlock(&wl->srcu, srcu_idx);
1533 				goto validate_interface;
1534 			}
1535 		}
1536 
1537 		if (vif->monitor_flag) {
1538 			srcu_read_unlock(&wl->srcu, srcu_idx);
1539 			goto validate_interface;
1540 		}
1541 
1542 		ndev = wilc_wfi_init_mon_interface(wl, name, vif->ndev);
1543 		if (ndev) {
1544 			vif->monitor_flag = 1;
1545 		} else {
1546 			srcu_read_unlock(&wl->srcu, srcu_idx);
1547 			return ERR_PTR(-EINVAL);
1548 		}
1549 
1550 		wdev = &vif->priv.wdev;
1551 		srcu_read_unlock(&wl->srcu, srcu_idx);
1552 		return wdev;
1553 	}
1554 
1555 validate_interface:
1556 	mutex_lock(&wl->vif_mutex);
1557 	if (wl->vif_num == WILC_NUM_CONCURRENT_IFC) {
1558 		pr_err("Reached maximum number of interface\n");
1559 		mutex_unlock(&wl->vif_mutex);
1560 		return ERR_PTR(-EINVAL);
1561 	}
1562 	mutex_unlock(&wl->vif_mutex);
1563 
1564 	switch (type) {
1565 	case NL80211_IFTYPE_STATION:
1566 		iftype = WILC_STATION_MODE;
1567 		break;
1568 	case NL80211_IFTYPE_AP:
1569 		iftype = WILC_AP_MODE;
1570 		break;
1571 	default:
1572 		return ERR_PTR(-EOPNOTSUPP);
1573 	}
1574 
1575 	vif = wilc_netdev_ifc_init(wl, name, iftype, type, true);
1576 	if (IS_ERR(vif))
1577 		return ERR_CAST(vif);
1578 
1579 	return &vif->priv.wdev;
1580 }
1581 
1582 static int del_virtual_intf(struct wiphy *wiphy, struct wireless_dev *wdev)
1583 {
1584 	struct wilc *wl = wiphy_priv(wiphy);
1585 	struct wilc_vif *vif;
1586 
1587 	if (wdev->iftype == NL80211_IFTYPE_AP ||
1588 	    wdev->iftype == NL80211_IFTYPE_P2P_GO)
1589 		wilc_wfi_deinit_mon_interface(wl, true);
1590 	vif = netdev_priv(wdev->netdev);
1591 	cfg80211_stop_iface(wiphy, wdev, GFP_KERNEL);
1592 	cfg80211_unregister_netdevice(vif->ndev);
1593 	vif->monitor_flag = 0;
1594 
1595 	wilc_set_operation_mode(vif, 0, 0, 0);
1596 	mutex_lock(&wl->vif_mutex);
1597 	list_del_rcu(&vif->list);
1598 	wl->vif_num--;
1599 	mutex_unlock(&wl->vif_mutex);
1600 	synchronize_srcu(&wl->srcu);
1601 	return 0;
1602 }
1603 
1604 static int wilc_suspend(struct wiphy *wiphy, struct cfg80211_wowlan *wow)
1605 {
1606 	struct wilc *wl = wiphy_priv(wiphy);
1607 
1608 	if (!wow && wilc_wlan_get_num_conn_ifcs(wl))
1609 		wl->suspend_event = true;
1610 	else
1611 		wl->suspend_event = false;
1612 
1613 	return 0;
1614 }
1615 
1616 static int wilc_resume(struct wiphy *wiphy)
1617 {
1618 	return 0;
1619 }
1620 
1621 static void wilc_set_wakeup(struct wiphy *wiphy, bool enabled)
1622 {
1623 	struct wilc *wl = wiphy_priv(wiphy);
1624 	struct wilc_vif *vif;
1625 	int srcu_idx;
1626 
1627 	srcu_idx = srcu_read_lock(&wl->srcu);
1628 	vif = wilc_get_wl_to_vif(wl);
1629 	if (IS_ERR(vif)) {
1630 		srcu_read_unlock(&wl->srcu, srcu_idx);
1631 		return;
1632 	}
1633 
1634 	netdev_info(vif->ndev, "cfg set wake up = %d\n", enabled);
1635 	wilc_set_wowlan_trigger(vif, enabled);
1636 	srcu_read_unlock(&wl->srcu, srcu_idx);
1637 }
1638 
1639 static int set_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev,
1640 			enum nl80211_tx_power_setting type, 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 
1671 static int get_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev,
1672 			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 	.change_bss = change_bss,
1712 	.set_wiphy_params = set_wiphy_params,
1713 
1714 	.external_auth = external_auth,
1715 	.set_pmksa = set_pmksa,
1716 	.del_pmksa = del_pmksa,
1717 	.flush_pmksa = flush_pmksa,
1718 	.remain_on_channel = remain_on_channel,
1719 	.cancel_remain_on_channel = cancel_remain_on_channel,
1720 	.mgmt_tx_cancel_wait = mgmt_tx_cancel_wait,
1721 	.mgmt_tx = mgmt_tx,
1722 	.update_mgmt_frame_registrations = wilc_update_mgmt_frame_registrations,
1723 	.set_power_mgmt = set_power_mgmt,
1724 	.set_cqm_rssi_config = set_cqm_rssi_config,
1725 
1726 	.suspend = wilc_suspend,
1727 	.resume = wilc_resume,
1728 	.set_wakeup = wilc_set_wakeup,
1729 	.set_tx_power = set_tx_power,
1730 	.get_tx_power = get_tx_power,
1731 
1732 };
1733 
1734 static void wlan_init_locks(struct wilc *wl)
1735 {
1736 	mutex_init(&wl->hif_cs);
1737 	mutex_init(&wl->rxq_cs);
1738 	mutex_init(&wl->cfg_cmd_lock);
1739 	mutex_init(&wl->vif_mutex);
1740 	mutex_init(&wl->deinit_lock);
1741 
1742 	spin_lock_init(&wl->txq_spinlock);
1743 	mutex_init(&wl->txq_add_to_head_cs);
1744 
1745 	init_completion(&wl->txq_event);
1746 	init_completion(&wl->cfg_event);
1747 	init_completion(&wl->sync_event);
1748 	init_completion(&wl->txq_thread_started);
1749 	init_srcu_struct(&wl->srcu);
1750 }
1751 
1752 void wlan_deinit_locks(struct wilc *wilc)
1753 {
1754 	mutex_destroy(&wilc->hif_cs);
1755 	mutex_destroy(&wilc->rxq_cs);
1756 	mutex_destroy(&wilc->cfg_cmd_lock);
1757 	mutex_destroy(&wilc->txq_add_to_head_cs);
1758 	mutex_destroy(&wilc->vif_mutex);
1759 	mutex_destroy(&wilc->deinit_lock);
1760 	cleanup_srcu_struct(&wilc->srcu);
1761 }
1762 
1763 int wilc_cfg80211_init(struct wilc **wilc, struct device *dev, int io_type,
1764 		       const struct wilc_hif_func *ops)
1765 {
1766 	struct wilc *wl;
1767 	struct wilc_vif *vif;
1768 	int ret, i;
1769 
1770 	wl = wilc_create_wiphy(dev);
1771 	if (!wl)
1772 		return -EINVAL;
1773 
1774 	wlan_init_locks(wl);
1775 
1776 	ret = wilc_wlan_cfg_init(wl);
1777 	if (ret)
1778 		goto free_wl;
1779 
1780 	*wilc = wl;
1781 	wl->io_type = io_type;
1782 	wl->hif_func = ops;
1783 
1784 	for (i = 0; i < NQUEUES; i++)
1785 		INIT_LIST_HEAD(&wl->txq[i].txq_head.list);
1786 
1787 	INIT_LIST_HEAD(&wl->rxq_head.list);
1788 	INIT_LIST_HEAD(&wl->vif_list);
1789 
1790 	vif = wilc_netdev_ifc_init(wl, "wlan%d", WILC_STATION_MODE,
1791 				   NL80211_IFTYPE_STATION, false);
1792 	if (IS_ERR(vif)) {
1793 		ret = PTR_ERR(vif);
1794 		goto free_cfg;
1795 	}
1796 
1797 	return 0;
1798 
1799 free_cfg:
1800 	wilc_wlan_cfg_deinit(wl);
1801 
1802 free_wl:
1803 	wlan_deinit_locks(wl);
1804 	wiphy_unregister(wl->wiphy);
1805 	wiphy_free(wl->wiphy);
1806 	return ret;
1807 }
1808 EXPORT_SYMBOL_GPL(wilc_cfg80211_init);
1809 
1810 struct wilc *wilc_create_wiphy(struct device *dev)
1811 {
1812 	struct wiphy *wiphy;
1813 	struct wilc *wl;
1814 	int ret;
1815 
1816 	wiphy = wiphy_new(&wilc_cfg80211_ops, sizeof(*wl));
1817 	if (!wiphy)
1818 		return NULL;
1819 
1820 	wl = wiphy_priv(wiphy);
1821 
1822 	memcpy(wl->bitrates, wilc_bitrates, sizeof(wilc_bitrates));
1823 	memcpy(wl->channels, wilc_2ghz_channels, sizeof(wilc_2ghz_channels));
1824 	wl->band.bitrates = wl->bitrates;
1825 	wl->band.n_bitrates = ARRAY_SIZE(wl->bitrates);
1826 	wl->band.channels = wl->channels;
1827 	wl->band.n_channels = ARRAY_SIZE(wilc_2ghz_channels);
1828 
1829 	wl->band.ht_cap.ht_supported = 1;
1830 	wl->band.ht_cap.cap |= (1 << IEEE80211_HT_CAP_RX_STBC_SHIFT);
1831 	wl->band.ht_cap.mcs.rx_mask[0] = 0xff;
1832 	wl->band.ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_8K;
1833 	wl->band.ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
1834 
1835 	wiphy->bands[NL80211_BAND_2GHZ] = &wl->band;
1836 
1837 	wiphy->max_scan_ssids = WILC_MAX_NUM_PROBED_SSID;
1838 #ifdef CONFIG_PM
1839 	wiphy->wowlan = &wowlan_support;
1840 #endif
1841 	wiphy->max_num_pmkids = WILC_MAX_NUM_PMKIDS;
1842 	wiphy->max_scan_ie_len = 1000;
1843 	wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
1844 	memcpy(wl->cipher_suites, wilc_cipher_suites,
1845 	       sizeof(wilc_cipher_suites));
1846 	wiphy->cipher_suites = wl->cipher_suites;
1847 	wiphy->n_cipher_suites = ARRAY_SIZE(wilc_cipher_suites);
1848 	wiphy->mgmt_stypes = wilc_wfi_cfg80211_mgmt_types;
1849 
1850 	wiphy->max_remain_on_channel_duration = 500;
1851 	wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
1852 				BIT(NL80211_IFTYPE_AP) |
1853 				BIT(NL80211_IFTYPE_MONITOR) |
1854 				BIT(NL80211_IFTYPE_P2P_GO) |
1855 				BIT(NL80211_IFTYPE_P2P_CLIENT);
1856 	wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
1857 	wiphy->features |= NL80211_FEATURE_SAE;
1858 	set_wiphy_dev(wiphy, dev);
1859 	wl->wiphy = wiphy;
1860 	ret = wiphy_register(wiphy);
1861 	if (ret) {
1862 		wiphy_free(wiphy);
1863 		return NULL;
1864 	}
1865 	return wl;
1866 }
1867 
1868 int wilc_init_host_int(struct net_device *net)
1869 {
1870 	int ret;
1871 	struct wilc_vif *vif = netdev_priv(net);
1872 	struct wilc_priv *priv = &vif->priv;
1873 
1874 	priv->p2p_listen_state = false;
1875 
1876 	mutex_init(&priv->scan_req_lock);
1877 	ret = wilc_init(net, &priv->hif_drv);
1878 	if (ret)
1879 		netdev_err(net, "Error while initializing hostinterface\n");
1880 
1881 	return ret;
1882 }
1883 
1884 void wilc_deinit_host_int(struct net_device *net)
1885 {
1886 	int ret;
1887 	struct wilc_vif *vif = netdev_priv(net);
1888 	struct wilc_priv *priv = &vif->priv;
1889 
1890 	priv->p2p_listen_state = false;
1891 
1892 	flush_workqueue(vif->wilc->hif_workqueue);
1893 	mutex_destroy(&priv->scan_req_lock);
1894 	ret = wilc_deinit(vif);
1895 
1896 	if (ret)
1897 		netdev_err(net, "Error while deinitializing host interface\n");
1898 }
1899 
1900