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