Linux Audio

Check our new training course

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