File Index
Files and directories
Sign in
FILE

cfg80211.c

File preview with syntax highlighting.

linux-6.19.14/drivers/net/wireless/microchip/wilc1000/cfg80211.c C
   1// SPDX-License-Identifier: GPL-2.0
   2/*
   3 * Copyright (c) 2012 - 2018 Microchip Technology Inc., and its subsidiaries.
   4 * All rights reserved.
   5 */
   6
   7#include "cfg80211.h"
   8
   9#define GO_NEG_REQ			0x00
  10#define GO_NEG_RSP			0x01
  11#define GO_NEG_CONF			0x02
  12#define P2P_INV_REQ			0x03
  13#define P2P_INV_RSP			0x04
  14
  15#define WILC_INVALID_CHANNEL		0
  16
  17/* Operation at 2.4 GHz with channels 1-13 */
  18#define WILC_WLAN_OPERATING_CLASS_2_4GHZ		0x51
  19
  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 set_wiphy_params(struct wiphy *wiphy, int radio_idx, u32 changed)
 798{
 799	int ret = -EINVAL;
 800	struct cfg_param_attr cfg_param_val;
 801	struct wilc *wl = wiphy_priv(wiphy);
 802	struct wilc_vif *vif;
 803	struct wilc_priv *priv;
 804	int srcu_idx;
 805
 806	srcu_idx = srcu_read_lock(&wl->srcu);
 807	vif = wilc_get_wl_to_vif(wl);
 808	if (IS_ERR(vif))
 809		goto out;
 810
 811	priv = &vif->priv;
 812	cfg_param_val.flag = 0;
 813
 814	if (changed & WIPHY_PARAM_RETRY_SHORT) {
 815		netdev_dbg(vif->ndev,
 816			   "Setting WIPHY_PARAM_RETRY_SHORT %d\n",
 817			   wiphy->retry_short);
 818		cfg_param_val.flag  |= WILC_CFG_PARAM_RETRY_SHORT;
 819		cfg_param_val.short_retry_limit = wiphy->retry_short;
 820	}
 821	if (changed & WIPHY_PARAM_RETRY_LONG) {
 822		netdev_dbg(vif->ndev,
 823			   "Setting WIPHY_PARAM_RETRY_LONG %d\n",
 824			   wiphy->retry_long);
 825		cfg_param_val.flag |= WILC_CFG_PARAM_RETRY_LONG;
 826		cfg_param_val.long_retry_limit = wiphy->retry_long;
 827	}
 828	if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
 829		if (wiphy->frag_threshold > 255 &&
 830		    wiphy->frag_threshold < 7937) {
 831			netdev_dbg(vif->ndev,
 832				   "Setting WIPHY_PARAM_FRAG_THRESHOLD %d\n",
 833				   wiphy->frag_threshold);
 834			cfg_param_val.flag |= WILC_CFG_PARAM_FRAG_THRESHOLD;
 835			cfg_param_val.frag_threshold = wiphy->frag_threshold;
 836		} else {
 837			netdev_err(vif->ndev,
 838				   "Fragmentation threshold out of range\n");
 839			goto out;
 840		}
 841	}
 842
 843	if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
 844		if (wiphy->rts_threshold > 255) {
 845			netdev_dbg(vif->ndev,
 846				   "Setting WIPHY_PARAM_RTS_THRESHOLD %d\n",
 847				   wiphy->rts_threshold);
 848			cfg_param_val.flag |= WILC_CFG_PARAM_RTS_THRESHOLD;
 849			cfg_param_val.rts_threshold = wiphy->rts_threshold;
 850		} else {
 851			netdev_err(vif->ndev, "RTS threshold out of range\n");
 852			goto out;
 853		}
 854	}
 855
 856	ret = wilc_hif_set_cfg(vif, &cfg_param_val);
 857	if (ret)
 858		netdev_err(priv->dev, "Error in setting WIPHY PARAMS\n");
 859
 860out:
 861	srcu_read_unlock(&wl->srcu, srcu_idx);
 862	return ret;
 863}
 864
 865static int set_pmksa(struct wiphy *wiphy, struct net_device *netdev,
 866		     struct cfg80211_pmksa *pmksa)
 867{
 868	struct wilc_vif *vif = netdev_priv(netdev);
 869	struct wilc_priv *priv = &vif->priv;
 870	u32 i;
 871	int ret = 0;
 872	u8 flag = 0;
 873
 874	for (i = 0; i < priv->pmkid_list.numpmkid; i++)	{
 875		if (!memcmp(pmksa->bssid, priv->pmkid_list.pmkidlist[i].bssid,
 876			    ETH_ALEN)) {
 877			flag = PMKID_FOUND;
 878			break;
 879		}
 880	}
 881	if (i < WILC_MAX_NUM_PMKIDS) {
 882		memcpy(priv->pmkid_list.pmkidlist[i].bssid, pmksa->bssid,
 883		       ETH_ALEN);
 884		memcpy(priv->pmkid_list.pmkidlist[i].pmkid, pmksa->pmkid,
 885		       WLAN_PMKID_LEN);
 886		if (!(flag == PMKID_FOUND))
 887			priv->pmkid_list.numpmkid++;
 888	} else {
 889		netdev_err(netdev, "Invalid PMKID index\n");
 890		ret = -EINVAL;
 891	}
 892
 893	if (!ret)
 894		ret = wilc_set_pmkid_info(vif, &priv->pmkid_list);
 895
 896	return ret;
 897}
 898
 899static int del_pmksa(struct wiphy *wiphy, struct net_device *netdev,
 900		     struct cfg80211_pmksa *pmksa)
 901{
 902	u32 i;
 903	struct wilc_vif *vif = netdev_priv(netdev);
 904	struct wilc_priv *priv = &vif->priv;
 905
 906	for (i = 0; i < priv->pmkid_list.numpmkid; i++)	{
 907		if (!memcmp(pmksa->bssid, priv->pmkid_list.pmkidlist[i].bssid,
 908			    ETH_ALEN)) {
 909			memset(&priv->pmkid_list.pmkidlist[i], 0,
 910			       sizeof(struct wilc_pmkid));
 911			break;
 912		}
 913	}
 914
 915	if (i == priv->pmkid_list.numpmkid)
 916		return -EINVAL;
 917
 918	for (; i < (priv->pmkid_list.numpmkid - 1); i++) {
 919		memcpy(priv->pmkid_list.pmkidlist[i].bssid,
 920		       priv->pmkid_list.pmkidlist[i + 1].bssid,
 921		       ETH_ALEN);
 922		memcpy(priv->pmkid_list.pmkidlist[i].pmkid,
 923		       priv->pmkid_list.pmkidlist[i + 1].pmkid,
 924		       WLAN_PMKID_LEN);
 925	}
 926	priv->pmkid_list.numpmkid--;
 927
 928	return 0;
 929}
 930
 931static int flush_pmksa(struct wiphy *wiphy, struct net_device *netdev)
 932{
 933	struct wilc_vif *vif = netdev_priv(netdev);
 934
 935	memset(&vif->priv.pmkid_list, 0, sizeof(struct wilc_pmkid_attr));
 936
 937	return 0;
 938}
 939
 940static inline void wilc_wfi_cfg_parse_ch_attr(u8 *buf, u32 len, u8 sta_ch)
 941{
 942	struct wilc_attr_entry *e;
 943	struct wilc_attr_ch_list *ch_list;
 944	struct wilc_attr_oper_ch *op_ch;
 945	u32 index = 0;
 946	u8 ch_list_idx = 0;
 947	u8 op_ch_idx = 0;
 948
 949	if (sta_ch == WILC_INVALID_CHANNEL)
 950		return;
 951
 952	while (index + sizeof(*e) <= len) {
 953		u16 attr_size;
 954
 955		e = (struct wilc_attr_entry *)&buf[index];
 956		attr_size = le16_to_cpu(e->attr_len);
 957
 958		if (index + sizeof(*e) + attr_size > len)
 959			return;
 960
 961		if (e->attr_type == IEEE80211_P2P_ATTR_CHANNEL_LIST &&
 962		    attr_size >= (sizeof(struct wilc_attr_ch_list) - sizeof(*e)))
 963			ch_list_idx = index;
 964		else if (e->attr_type == IEEE80211_P2P_ATTR_OPER_CHANNEL &&
 965			 attr_size == (sizeof(struct wilc_attr_oper_ch) - sizeof(*e)))
 966			op_ch_idx = index;
 967
 968		if (ch_list_idx && op_ch_idx)
 969			break;
 970
 971		index += sizeof(*e) + attr_size;
 972	}
 973
 974	if (ch_list_idx) {
 975		u16 elem_size;
 976
 977		ch_list = (struct wilc_attr_ch_list *)&buf[ch_list_idx];
 978		/* the number of bytes following the final 'elem' member */
 979		elem_size = le16_to_cpu(ch_list->attr_len) -
 980			(sizeof(*ch_list) - sizeof(struct wilc_attr_entry));
 981		for (unsigned int i = 0; i < elem_size;) {
 982			struct wilc_ch_list_elem *e;
 983
 984			e = (struct wilc_ch_list_elem *)(ch_list->elem + i);
 985
 986			i += sizeof(*e);
 987			if (i > elem_size)
 988				break;
 989
 990			i += e->no_of_channels;
 991			if (i > elem_size)
 992				break;
 993
 994			if (e->op_class == WILC_WLAN_OPERATING_CLASS_2_4GHZ) {
 995				memset(e->ch_list, sta_ch, e->no_of_channels);
 996				break;
 997			}
 998		}
 999	}
1000
1001	if (op_ch_idx) {
1002		op_ch = (struct wilc_attr_oper_ch *)&buf[op_ch_idx];
1003		op_ch->op_class = WILC_WLAN_OPERATING_CLASS_2_4GHZ;
1004		op_ch->op_channel = sta_ch;
1005	}
1006}
1007
1008bool wilc_wfi_mgmt_frame_rx(struct wilc_vif *vif, u8 *buff, u32 size)
1009{
1010	struct wilc *wl = vif->wilc;
1011	struct wilc_priv *priv = &vif->priv;
1012	int freq;
1013
1014	freq = ieee80211_channel_to_frequency(wl->op_ch, NL80211_BAND_2GHZ);
1015
1016	return cfg80211_rx_mgmt(&priv->wdev, freq, 0, buff, size, 0);
1017}
1018
1019void wilc_wfi_p2p_rx(struct wilc_vif *vif, u8 *buff, u32 size)
1020{
1021	struct wilc *wl = vif->wilc;
1022	struct wilc_priv *priv = &vif->priv;
1023	struct host_if_drv *wfi_drv = priv->hif_drv;
1024	struct ieee80211_mgmt *mgmt;
1025	struct wilc_vendor_specific_ie *p;
1026	struct wilc_p2p_pub_act_frame *d;
1027	int ie_offset = offsetof(struct ieee80211_mgmt, u) + sizeof(*d);
1028	const u8 *vendor_ie;
1029	u32 header, pkt_offset;
1030	s32 freq;
1031
1032	header = get_unaligned_le32(buff - HOST_HDR_OFFSET);
1033	pkt_offset = FIELD_GET(WILC_PKT_HDR_OFFSET_FIELD, header);
1034
1035	if (pkt_offset & IS_MANAGMEMENT_CALLBACK) {
1036		bool ack = false;
1037		struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)buff;
1038
1039		if (ieee80211_is_probe_resp(hdr->frame_control) ||
1040		    pkt_offset & IS_MGMT_STATUS_SUCCES)
1041			ack = true;
1042
1043		cfg80211_mgmt_tx_status(&priv->wdev, priv->tx_cookie, buff,
1044					size, ack, GFP_KERNEL);
1045		return;
1046	}
1047
1048	freq = ieee80211_channel_to_frequency(wl->op_ch, NL80211_BAND_2GHZ);
1049
1050	mgmt = (struct ieee80211_mgmt *)buff;
1051	if (!ieee80211_is_action(mgmt->frame_control))
1052		goto out_rx_mgmt;
1053
1054	if (priv->cfg_scanning &&
1055	    time_after_eq(jiffies, (unsigned long)wfi_drv->p2p_timeout)) {
1056		netdev_dbg(vif->ndev, "Receiving action wrong ch\n");
1057		return;
1058	}
1059
1060	if (!ieee80211_is_public_action((struct ieee80211_hdr *)buff, size))
1061		goto out_rx_mgmt;
1062
1063	d = (struct wilc_p2p_pub_act_frame *)(&mgmt->u.action);
1064	if (d->oui_subtype != GO_NEG_REQ && d->oui_subtype != GO_NEG_RSP &&
1065	    d->oui_subtype != P2P_INV_REQ && d->oui_subtype != P2P_INV_RSP)
1066		goto out_rx_mgmt;
1067
1068	vendor_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1069					    buff + ie_offset, size - ie_offset);
1070	if (!vendor_ie)
1071		goto out_rx_mgmt;
1072
1073	p = (struct wilc_vendor_specific_ie *)vendor_ie;
1074	wilc_wfi_cfg_parse_ch_attr(p->attr, p->tag_len - 4, vif->wilc->sta_ch);
1075
1076out_rx_mgmt:
1077	cfg80211_rx_mgmt(&priv->wdev, freq, 0, buff, size, 0);
1078}
1079
1080static void wilc_wfi_mgmt_tx_complete(void *priv, int status)
1081{
1082	struct wilc_p2p_mgmt_data *pv_data = priv;
1083
1084	kfree(pv_data->buff);
1085	kfree(pv_data);
1086}
1087
1088static void wilc_wfi_remain_on_channel_expired(struct wilc_vif *vif, u64 cookie)
1089{
1090	struct wilc_priv *priv = &vif->priv;
1091	struct wilc_wfi_p2p_listen_params *params = &priv->remain_on_ch_params;
1092
1093	if (cookie != params->listen_cookie)
1094		return;
1095
1096	priv->p2p_listen_state = false;
1097
1098	cfg80211_remain_on_channel_expired(&priv->wdev, params->listen_cookie,
1099					   params->listen_ch, GFP_KERNEL);
1100}
1101
1102static int remain_on_channel(struct wiphy *wiphy,
1103			     struct wireless_dev *wdev,
1104			     struct ieee80211_channel *chan,
1105			     unsigned int duration, u64 *cookie)
1106{
1107	int ret = 0;
1108	struct wilc_vif *vif = netdev_priv(wdev->netdev);
1109	struct wilc_priv *priv = &vif->priv;
1110	u64 id;
1111
1112	if (wdev->iftype == NL80211_IFTYPE_AP) {
1113		netdev_dbg(vif->ndev, "Required while in AP mode\n");
1114		return ret;
1115	}
1116
1117	id = ++priv->inc_roc_cookie;
1118	if (id == 0)
1119		id = ++priv->inc_roc_cookie;
1120
1121	ret = wilc_remain_on_channel(vif, id, chan->hw_value,
1122				     wilc_wfi_remain_on_channel_expired);
1123	if (ret)
1124		return ret;
1125
1126	vif->wilc->op_ch = chan->hw_value;
1127
1128	priv->remain_on_ch_params.listen_ch = chan;
1129	priv->remain_on_ch_params.listen_cookie = id;
1130	*cookie = id;
1131	priv->p2p_listen_state = true;
1132	priv->remain_on_ch_params.listen_duration = duration;
1133
1134	cfg80211_ready_on_channel(wdev, *cookie, chan, duration, GFP_KERNEL);
1135	mod_timer(&vif->hif_drv->remain_on_ch_timer,
1136		  jiffies + msecs_to_jiffies(duration + 1000));
1137
1138	return ret;
1139}
1140
1141static int cancel_remain_on_channel(struct wiphy *wiphy,
1142				    struct wireless_dev *wdev,
1143				    u64 cookie)
1144{
1145	struct wilc_vif *vif = netdev_priv(wdev->netdev);
1146	struct wilc_priv *priv = &vif->priv;
1147
1148	if (cookie != priv->remain_on_ch_params.listen_cookie)
1149		return -ENOENT;
1150
1151	return wilc_listen_state_expired(vif, cookie);
1152}
1153
1154static int mgmt_tx(struct wiphy *wiphy,
1155		   struct wireless_dev *wdev,
1156		   struct cfg80211_mgmt_tx_params *params,
1157		   u64 *cookie)
1158{
1159	struct ieee80211_channel *chan = params->chan;
1160	unsigned int wait = params->wait;
1161	const u8 *buf = params->buf;
1162	size_t len = params->len;
1163	const struct ieee80211_mgmt *mgmt;
1164	struct wilc_p2p_mgmt_data *mgmt_tx;
1165	struct wilc_vif *vif = netdev_priv(wdev->netdev);
1166	struct wilc_priv *priv = &vif->priv;
1167	struct host_if_drv *wfi_drv = priv->hif_drv;
1168	struct wilc_vendor_specific_ie *p;
1169	struct wilc_p2p_pub_act_frame *d;
1170	int ie_offset = offsetof(struct ieee80211_mgmt, u) + sizeof(*d);
1171	const u8 *vendor_ie;
1172	int ret = 0;
1173
1174	*cookie = get_random_u32();
1175	priv->tx_cookie = *cookie;
1176	mgmt = (const struct ieee80211_mgmt *)buf;
1177
1178	if (!ieee80211_is_mgmt(mgmt->frame_control))
1179		goto out;
1180
1181	mgmt_tx = kmalloc(sizeof(*mgmt_tx), GFP_KERNEL);
1182	if (!mgmt_tx) {
1183		ret = -ENOMEM;
1184		goto out;
1185	}
1186
1187	mgmt_tx->buff = kmemdup(buf, len, GFP_KERNEL);
1188	if (!mgmt_tx->buff) {
1189		ret = -ENOMEM;
1190		kfree(mgmt_tx);
1191		goto out;
1192	}
1193
1194	mgmt_tx->size = len;
1195
1196	if (ieee80211_is_probe_resp(mgmt->frame_control)) {
1197		wilc_set_mac_chnl_num(vif, chan->hw_value);
1198		vif->wilc->op_ch = chan->hw_value;
1199		goto out_txq_add_pkt;
1200	}
1201
1202	if (!ieee80211_is_public_action((struct ieee80211_hdr *)buf, len)) {
1203		if (chan)
1204			wilc_set_mac_chnl_num(vif, chan->hw_value);
1205		else
1206			wilc_set_mac_chnl_num(vif, vif->wilc->op_ch);
1207
1208		goto out_set_timeout;
1209	}
1210
1211	d = (struct wilc_p2p_pub_act_frame *)(&mgmt->u.action);
1212	if (d->oui_type != WLAN_OUI_TYPE_WFA_P2P ||
1213	    d->oui_subtype != GO_NEG_CONF) {
1214		wilc_set_mac_chnl_num(vif, chan->hw_value);
1215		vif->wilc->op_ch = chan->hw_value;
1216	}
1217
1218	if (d->oui_subtype != P2P_INV_REQ && d->oui_subtype != P2P_INV_RSP)
1219		goto out_set_timeout;
1220
1221	vendor_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1222					    mgmt_tx->buff + ie_offset,
1223					    len - ie_offset);
1224	if (!vendor_ie)
1225		goto out_set_timeout;
1226
1227	p = (struct wilc_vendor_specific_ie *)vendor_ie;
1228	wilc_wfi_cfg_parse_ch_attr(p->attr, p->tag_len - 4, vif->wilc->sta_ch);
1229
1230out_set_timeout:
1231	wfi_drv->p2p_timeout = (jiffies + msecs_to_jiffies(wait));
1232
1233out_txq_add_pkt:
1234
1235	wilc_wlan_txq_add_mgmt_pkt(wdev->netdev, mgmt_tx,
1236				   mgmt_tx->buff, mgmt_tx->size,
1237				   wilc_wfi_mgmt_tx_complete);
1238
1239out:
1240
1241	return ret;
1242}
1243
1244static int mgmt_tx_cancel_wait(struct wiphy *wiphy,
1245			       struct wireless_dev *wdev,
1246			       u64 cookie)
1247{
1248	struct wilc_vif *vif = netdev_priv(wdev->netdev);
1249	struct wilc_priv *priv = &vif->priv;
1250	struct host_if_drv *wfi_drv = priv->hif_drv;
1251
1252	wfi_drv->p2p_timeout = jiffies;
1253
1254	if (!priv->p2p_listen_state) {
1255		struct wilc_wfi_p2p_listen_params *params;
1256
1257		params = &priv->remain_on_ch_params;
1258
1259		cfg80211_remain_on_channel_expired(wdev,
1260						   params->listen_cookie,
1261						   params->listen_ch,
1262						   GFP_KERNEL);
1263	}
1264
1265	return 0;
1266}
1267
1268void wilc_update_mgmt_frame_registrations(struct wiphy *wiphy,
1269					  struct wireless_dev *wdev,
1270					  struct mgmt_frame_regs *upd)
1271{
1272	struct wilc *wl = wiphy_priv(wiphy);
1273	struct wilc_vif *vif = netdev_priv(wdev->netdev);
1274	u32 presp_bit = BIT(IEEE80211_STYPE_PROBE_REQ >> 4);
1275	u32 action_bit = BIT(IEEE80211_STYPE_ACTION >> 4);
1276	u32 pauth_bit = BIT(IEEE80211_STYPE_AUTH >> 4);
1277
1278	if (wl->initialized) {
1279		bool prev = vif->mgmt_reg_stypes & presp_bit;
1280		bool now = upd->interface_stypes & presp_bit;
1281
1282		if (now != prev)
1283			wilc_frame_register(vif, IEEE80211_STYPE_PROBE_REQ, now);
1284
1285		prev = vif->mgmt_reg_stypes & action_bit;
1286		now = upd->interface_stypes & action_bit;
1287
1288		if (now != prev)
1289			wilc_frame_register(vif, IEEE80211_STYPE_ACTION, now);
1290
1291		prev = vif->mgmt_reg_stypes & pauth_bit;
1292		now = upd->interface_stypes & pauth_bit;
1293		if (now != prev)
1294			wilc_frame_register(vif, IEEE80211_STYPE_AUTH, now);
1295	}
1296
1297	vif->mgmt_reg_stypes =
1298		upd->interface_stypes & (presp_bit | action_bit | pauth_bit);
1299}
1300
1301static int external_auth(struct wiphy *wiphy, struct net_device *dev,
1302			 struct cfg80211_external_auth_params *auth)
1303{
1304	struct wilc_vif *vif = netdev_priv(dev);
1305
1306	if (auth->status == WLAN_STATUS_SUCCESS)
1307		wilc_set_external_auth_param(vif, auth);
1308
1309	return 0;
1310}
1311
1312static int set_cqm_rssi_config(struct wiphy *wiphy, struct net_device *dev,
1313			       s32 rssi_thold, u32 rssi_hyst)
1314{
1315	return 0;
1316}
1317
1318static int dump_station(struct wiphy *wiphy, struct net_device *dev,
1319			int idx, u8 *mac, struct station_info *sinfo)
1320{
1321	struct wilc_vif *vif = netdev_priv(dev);
1322	int ret;
1323
1324	if (idx != 0)
1325		return -ENOENT;
1326
1327	ret = wilc_get_rssi(vif, &sinfo->signal);
1328	if (ret)
1329		return ret;
1330
1331	sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL);
1332	memcpy(mac, vif->priv.associated_bss, ETH_ALEN);
1333	return 0;
1334}
1335
1336static int set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
1337			  bool enabled, int timeout)
1338{
1339	struct wilc_vif *vif = netdev_priv(dev);
1340	struct wilc_priv *priv = &vif->priv;
1341
1342	if (!priv->hif_drv)
1343		return -EIO;
1344
1345	wilc_set_power_mgmt(vif, enabled, timeout);
1346
1347	return 0;
1348}
1349
1350static int change_virtual_intf(struct wiphy *wiphy, struct net_device *dev,
1351			       enum nl80211_iftype type,
1352			       struct vif_params *params)
1353{
1354	struct wilc *wl = wiphy_priv(wiphy);
1355	struct wilc_vif *vif = netdev_priv(dev);
1356	struct wilc_priv *priv = &vif->priv;
1357
1358	switch (type) {
1359	case NL80211_IFTYPE_STATION:
1360		vif->connecting = false;
1361		dev->ieee80211_ptr->iftype = type;
1362		priv->wdev.iftype = type;
1363		vif->monitor_flag = 0;
1364		if (vif->iftype == WILC_AP_MODE || vif->iftype == WILC_GO_MODE)
1365			wilc_wfi_deinit_mon_interface(wl, true);
1366		vif->iftype = WILC_STATION_MODE;
1367
1368		if (wl->initialized)
1369			wilc_set_operation_mode(vif, wilc_get_vif_idx(vif),
1370						WILC_STATION_MODE, vif->idx);
1371
1372		memset(priv->assoc_stainfo.sta_associated_bss, 0,
1373		       WILC_MAX_NUM_STA * ETH_ALEN);
1374		break;
1375
1376	case NL80211_IFTYPE_P2P_CLIENT:
1377		vif->connecting = false;
1378		dev->ieee80211_ptr->iftype = type;
1379		priv->wdev.iftype = type;
1380		vif->monitor_flag = 0;
1381		vif->iftype = WILC_CLIENT_MODE;
1382
1383		if (wl->initialized)
1384			wilc_set_operation_mode(vif, wilc_get_vif_idx(vif),
1385						WILC_STATION_MODE, vif->idx);
1386		break;
1387
1388	case NL80211_IFTYPE_AP:
1389		dev->ieee80211_ptr->iftype = type;
1390		priv->wdev.iftype = type;
1391		vif->iftype = WILC_AP_MODE;
1392
1393		if (wl->initialized)
1394			wilc_set_operation_mode(vif, wilc_get_vif_idx(vif),
1395						WILC_AP_MODE, vif->idx);
1396		break;
1397
1398	case NL80211_IFTYPE_P2P_GO:
1399		dev->ieee80211_ptr->iftype = type;
1400		priv->wdev.iftype = type;
1401		vif->iftype = WILC_GO_MODE;
1402
1403		if (wl->initialized)
1404			wilc_set_operation_mode(vif, wilc_get_vif_idx(vif),
1405						WILC_AP_MODE, vif->idx);
1406		break;
1407
1408	default:
1409		netdev_err(dev, "Unknown interface type= %d\n", type);
1410		return -EINVAL;
1411	}
1412
1413	return 0;
1414}
1415
1416static int start_ap(struct wiphy *wiphy, struct net_device *dev,
1417		    struct cfg80211_ap_settings *settings)
1418{
1419	struct wilc_vif *vif = netdev_priv(dev);
1420	int ret;
1421
1422	ret = set_channel(wiphy, dev, &settings->chandef);
1423	if (ret != 0)
1424		netdev_err(dev, "Error in setting channel\n");
1425
1426	wilc_wlan_set_bssid(dev, dev->dev_addr, WILC_AP_MODE);
1427
1428	return wilc_add_beacon(vif, settings->beacon_interval,
1429				   settings->dtim_period, &settings->beacon);
1430}
1431
1432static int change_beacon(struct wiphy *wiphy, struct net_device *dev,
1433			 struct cfg80211_ap_update *params)
1434{
1435	struct wilc_vif *vif = netdev_priv(dev);
1436
1437	return wilc_add_beacon(vif, 0, 0, &params->beacon);
1438}
1439
1440static int stop_ap(struct wiphy *wiphy, struct net_device *dev,
1441		   unsigned int link_id)
1442{
1443	int ret;
1444	struct wilc_vif *vif = netdev_priv(dev);
1445
1446	wilc_wlan_set_bssid(dev, NULL, WILC_AP_MODE);
1447
1448	ret = wilc_del_beacon(vif);
1449
1450	if (ret)
1451		netdev_err(dev, "Host delete beacon fail\n");
1452
1453	return ret;
1454}
1455
1456static int add_station(struct wiphy *wiphy, struct net_device *dev,
1457		       const u8 *mac, struct station_parameters *params)
1458{
1459	int ret = 0;
1460	struct wilc_vif *vif = netdev_priv(dev);
1461	struct wilc_priv *priv = &vif->priv;
1462
1463	if (vif->iftype == WILC_AP_MODE || vif->iftype == WILC_GO_MODE) {
1464		memcpy(priv->assoc_stainfo.sta_associated_bss[params->aid], mac,
1465		       ETH_ALEN);
1466
1467		ret = wilc_add_station(vif, mac, params);
1468		if (ret)
1469			netdev_err(dev, "Host add station fail\n");
1470	}
1471
1472	return ret;
1473}
1474
1475static int del_station(struct wiphy *wiphy, struct net_device *dev,
1476		       struct station_del_parameters *params)
1477{
1478	const u8 *mac = params->mac;
1479	int ret = 0;
1480	struct wilc_vif *vif = netdev_priv(dev);
1481	struct wilc_priv *priv = &vif->priv;
1482	struct sta_info *info;
1483
1484	if (!(vif->iftype == WILC_AP_MODE || vif->iftype == WILC_GO_MODE))
1485		return ret;
1486
1487	info = &priv->assoc_stainfo;
1488
1489	if (!mac)
1490		ret = wilc_del_allstation(vif, info->sta_associated_bss);
1491
1492	ret = wilc_del_station(vif, mac);
1493	if (ret)
1494		netdev_err(dev, "Host delete station fail\n");
1495	return ret;
1496}
1497
1498static int change_station(struct wiphy *wiphy, struct net_device *dev,
1499			  const u8 *mac, struct station_parameters *params)
1500{
1501	int ret = 0;
1502	struct wilc_vif *vif = netdev_priv(dev);
1503
1504	if (vif->iftype == WILC_AP_MODE || vif->iftype == WILC_GO_MODE) {
1505		ret = wilc_edit_station(vif, mac, params);
1506		if (ret)
1507			netdev_err(dev, "Host edit station fail\n");
1508	}
1509	return ret;
1510}
1511
1512static struct wilc_vif *wilc_get_vif_from_type(struct wilc *wl, int type)
1513{
1514	struct wilc_vif *vif;
1515
1516	wilc_for_each_vif(wl, vif) {
1517		if (vif->iftype == type)
1518			return vif;
1519	}
1520
1521	return NULL;
1522}
1523
1524static struct wireless_dev *add_virtual_intf(struct wiphy *wiphy,
1525					     const char *name,
1526					     unsigned char name_assign_type,
1527					     enum nl80211_iftype type,
1528					     struct vif_params *params)
1529{
1530	struct wilc *wl = wiphy_priv(wiphy);
1531	struct wilc_vif *vif;
1532	struct wireless_dev *wdev;
1533	int iftype;
1534
1535	if (type == NL80211_IFTYPE_MONITOR) {
1536		struct net_device *ndev;
1537		int srcu_idx;
1538
1539		srcu_idx = srcu_read_lock(&wl->srcu);
1540		vif = wilc_get_vif_from_type(wl, WILC_AP_MODE);
1541		if (!vif) {
1542			vif = wilc_get_vif_from_type(wl, WILC_GO_MODE);
1543			if (!vif) {
1544				srcu_read_unlock(&wl->srcu, srcu_idx);
1545				goto validate_interface;
1546			}
1547		}
1548
1549		if (vif->monitor_flag) {
1550			srcu_read_unlock(&wl->srcu, srcu_idx);
1551			goto validate_interface;
1552		}
1553
1554		ndev = wilc_wfi_init_mon_interface(wl, name, vif->ndev);
1555		if (ndev) {
1556			vif->monitor_flag = 1;
1557		} else {
1558			srcu_read_unlock(&wl->srcu, srcu_idx);
1559			return ERR_PTR(-EINVAL);
1560		}
1561
1562		wdev = &vif->priv.wdev;
1563		srcu_read_unlock(&wl->srcu, srcu_idx);
1564		return wdev;
1565	}
1566
1567validate_interface:
1568	mutex_lock(&wl->vif_mutex);
1569	if (wl->vif_num == WILC_NUM_CONCURRENT_IFC) {
1570		pr_err("Reached maximum number of interface\n");
1571		mutex_unlock(&wl->vif_mutex);
1572		return ERR_PTR(-EINVAL);
1573	}
1574	mutex_unlock(&wl->vif_mutex);
1575
1576	switch (type) {
1577	case NL80211_IFTYPE_STATION:
1578		iftype = WILC_STATION_MODE;
1579		break;
1580	case NL80211_IFTYPE_AP:
1581		iftype = WILC_AP_MODE;
1582		break;
1583	default:
1584		return ERR_PTR(-EOPNOTSUPP);
1585	}
1586
1587	vif = wilc_netdev_ifc_init(wl, name, iftype, type, true);
1588	if (IS_ERR(vif))
1589		return ERR_CAST(vif);
1590
1591	return &vif->priv.wdev;
1592}
1593
1594static int del_virtual_intf(struct wiphy *wiphy, struct wireless_dev *wdev)
1595{
1596	struct wilc *wl = wiphy_priv(wiphy);
1597	struct wilc_vif *vif;
1598
1599	if (wdev->iftype == NL80211_IFTYPE_AP ||
1600	    wdev->iftype == NL80211_IFTYPE_P2P_GO)
1601		wilc_wfi_deinit_mon_interface(wl, true);
1602	vif = netdev_priv(wdev->netdev);
1603	cfg80211_stop_iface(wiphy, wdev, GFP_KERNEL);
1604	cfg80211_unregister_netdevice(vif->ndev);
1605	vif->monitor_flag = 0;
1606
1607	mutex_lock(&wl->vif_mutex);
1608	list_del_rcu(&vif->list);
1609	wl->vif_num--;
1610	mutex_unlock(&wl->vif_mutex);
1611	synchronize_srcu(&wl->srcu);
1612	return 0;
1613}
1614
1615static void wilc_set_wakeup(struct wiphy *wiphy, bool enabled)
1616{
1617	struct wilc *wl = wiphy_priv(wiphy);
1618	struct wilc_vif *vif;
1619	int srcu_idx;
1620
1621	srcu_idx = srcu_read_lock(&wl->srcu);
1622	vif = wilc_get_wl_to_vif(wl);
1623	if (IS_ERR(vif)) {
1624		srcu_read_unlock(&wl->srcu, srcu_idx);
1625		return;
1626	}
1627
1628	netdev_info(vif->ndev, "cfg set wake up = %d\n", enabled);
1629	wilc_set_wowlan_trigger(vif, enabled);
1630	srcu_read_unlock(&wl->srcu, srcu_idx);
1631}
1632
1633static int set_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev,
1634			int radio_idx, enum nl80211_tx_power_setting type,
1635			int mbm)
1636{
1637	int ret;
1638	int srcu_idx;
1639	s32 tx_power = MBM_TO_DBM(mbm);
1640	struct wilc *wl = wiphy_priv(wiphy);
1641	struct wilc_vif *vif;
1642
1643	if (!wl->initialized)
1644		return -EIO;
1645
1646	srcu_idx = srcu_read_lock(&wl->srcu);
1647	vif = wilc_get_wl_to_vif(wl);
1648	if (IS_ERR(vif)) {
1649		srcu_read_unlock(&wl->srcu, srcu_idx);
1650		return -EINVAL;
1651	}
1652
1653	netdev_info(vif->ndev, "Setting tx power %d\n", tx_power);
1654	if (tx_power < 0)
1655		tx_power = 0;
1656	else if (tx_power > 18)
1657		tx_power = 18;
1658	ret = wilc_set_tx_power(vif, tx_power);
1659	if (ret)
1660		netdev_err(vif->ndev, "Failed to set tx power\n");
1661	srcu_read_unlock(&wl->srcu, srcu_idx);
1662
1663	return ret;
1664}
1665
1666static int get_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev,
1667			int radio_idx, unsigned int link_id, int *dbm)
1668{
1669	int ret;
1670	struct wilc_vif *vif = netdev_priv(wdev->netdev);
1671	struct wilc *wl = vif->wilc;
1672
1673	/* If firmware is not started, return. */
1674	if (!wl->initialized)
1675		return -EIO;
1676
1677	ret = wilc_get_tx_power(vif, (u8 *)dbm);
1678	if (ret)
1679		netdev_err(vif->ndev, "Failed to get tx power\n");
1680
1681	return ret;
1682}
1683
1684static const struct cfg80211_ops wilc_cfg80211_ops = {
1685	.set_monitor_channel = set_channel,
1686	.scan = scan,
1687	.connect = connect,
1688	.disconnect = disconnect,
1689	.add_key = add_key,
1690	.del_key = del_key,
1691	.get_key = get_key,
1692	.set_default_key = set_default_key,
1693	.set_default_mgmt_key = set_default_mgmt_key,
1694	.add_virtual_intf = add_virtual_intf,
1695	.del_virtual_intf = del_virtual_intf,
1696	.change_virtual_intf = change_virtual_intf,
1697
1698	.start_ap = start_ap,
1699	.change_beacon = change_beacon,
1700	.stop_ap = stop_ap,
1701	.add_station = add_station,
1702	.del_station = del_station,
1703	.change_station = change_station,
1704	.get_station = get_station,
1705	.dump_station = dump_station,
1706	.set_wiphy_params = set_wiphy_params,
1707
1708	.external_auth = external_auth,
1709	.set_pmksa = set_pmksa,
1710	.del_pmksa = del_pmksa,
1711	.flush_pmksa = flush_pmksa,
1712	.remain_on_channel = remain_on_channel,
1713	.cancel_remain_on_channel = cancel_remain_on_channel,
1714	.mgmt_tx_cancel_wait = mgmt_tx_cancel_wait,
1715	.mgmt_tx = mgmt_tx,
1716	.update_mgmt_frame_registrations = wilc_update_mgmt_frame_registrations,
1717	.set_power_mgmt = set_power_mgmt,
1718	.set_cqm_rssi_config = set_cqm_rssi_config,
1719
1720	.set_wakeup = wilc_set_wakeup,
1721	.set_tx_power = set_tx_power,
1722	.get_tx_power = get_tx_power,
1723
1724};
1725
1726static void wlan_init_locks(struct wilc *wl)
1727{
1728	mutex_init(&wl->hif_cs);
1729	mutex_init(&wl->rxq_cs);
1730	mutex_init(&wl->cfg_cmd_lock);
1731	mutex_init(&wl->vif_mutex);
1732	mutex_init(&wl->deinit_lock);
1733
1734	spin_lock_init(&wl->txq_spinlock);
1735	mutex_init(&wl->txq_add_to_head_cs);
1736
1737	init_completion(&wl->txq_event);
1738	init_completion(&wl->cfg_event);
1739	init_completion(&wl->sync_event);
1740	init_completion(&wl->txq_thread_started);
1741	init_srcu_struct(&wl->srcu);
1742}
1743
1744void wlan_deinit_locks(struct wilc *wilc)
1745{
1746	mutex_destroy(&wilc->hif_cs);
1747	mutex_destroy(&wilc->rxq_cs);
1748	mutex_destroy(&wilc->cfg_cmd_lock);
1749	mutex_destroy(&wilc->txq_add_to_head_cs);
1750	mutex_destroy(&wilc->vif_mutex);
1751	mutex_destroy(&wilc->deinit_lock);
1752	cleanup_srcu_struct(&wilc->srcu);
1753}
1754
1755static struct wilc *wilc_create_wiphy(struct device *dev)
1756{
1757	struct wiphy *wiphy;
1758	struct wilc *wl;
1759
1760	wiphy = wiphy_new(&wilc_cfg80211_ops, sizeof(*wl));
1761	if (!wiphy)
1762		return NULL;
1763
1764	wl = wiphy_priv(wiphy);
1765
1766	memcpy(wl->bitrates, wilc_bitrates, sizeof(wilc_bitrates));
1767	memcpy(wl->channels, wilc_2ghz_channels, sizeof(wilc_2ghz_channels));
1768	wl->band.bitrates = wl->bitrates;
1769	wl->band.n_bitrates = ARRAY_SIZE(wl->bitrates);
1770	wl->band.channels = wl->channels;
1771	wl->band.n_channels = ARRAY_SIZE(wilc_2ghz_channels);
1772
1773	wl->band.ht_cap.ht_supported = 1;
1774	wl->band.ht_cap.cap |= (1 << IEEE80211_HT_CAP_RX_STBC_SHIFT);
1775	wl->band.ht_cap.mcs.rx_mask[0] = 0xff;
1776	wl->band.ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_8K;
1777	wl->band.ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
1778
1779	wiphy->bands[NL80211_BAND_2GHZ] = &wl->band;
1780
1781	wiphy->max_scan_ssids = WILC_MAX_NUM_PROBED_SSID;
1782#ifdef CONFIG_PM
1783	wiphy->wowlan = &wowlan_support;
1784#endif
1785	wiphy->max_num_pmkids = WILC_MAX_NUM_PMKIDS;
1786	wiphy->max_scan_ie_len = 1000;
1787	wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
1788	memcpy(wl->cipher_suites, wilc_cipher_suites,
1789	       sizeof(wilc_cipher_suites));
1790	wiphy->cipher_suites = wl->cipher_suites;
1791	wiphy->n_cipher_suites = ARRAY_SIZE(wilc_cipher_suites);
1792	wiphy->mgmt_stypes = wilc_wfi_cfg80211_mgmt_types;
1793
1794	wiphy->max_remain_on_channel_duration = 500;
1795	wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
1796				BIT(NL80211_IFTYPE_AP) |
1797				BIT(NL80211_IFTYPE_MONITOR) |
1798				BIT(NL80211_IFTYPE_P2P_GO) |
1799				BIT(NL80211_IFTYPE_P2P_CLIENT);
1800	wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
1801	set_wiphy_dev(wiphy, dev);
1802	wl->wiphy = wiphy;
1803	return wl;
1804}
1805
1806int wilc_cfg80211_init(struct wilc **wilc, struct device *dev, int io_type,
1807		       const struct wilc_hif_func *ops)
1808{
1809	struct wilc *wl;
1810	int ret, i;
1811
1812	wl = wilc_create_wiphy(dev);
1813	if (!wl)
1814		return -EINVAL;
1815
1816	wlan_init_locks(wl);
1817
1818	ret = wilc_wlan_cfg_init(wl);
1819	if (ret)
1820		goto free_wl;
1821
1822	*wilc = wl;
1823	wl->io_type = io_type;
1824	wl->hif_func = ops;
1825
1826	for (i = 0; i < NQUEUES; i++)
1827		INIT_LIST_HEAD(&wl->txq[i].txq_head.list);
1828
1829	INIT_LIST_HEAD(&wl->rxq_head.list);
1830	INIT_LIST_HEAD(&wl->vif_list);
1831
1832	wl->hif_workqueue = alloc_ordered_workqueue("%s", WQ_MEM_RECLAIM,
1833						    wiphy_name(wl->wiphy));
1834	if (!wl->hif_workqueue) {
1835		ret = -ENOMEM;
1836		goto free_cfg;
1837	}
1838
1839	return 0;
1840
1841free_cfg:
1842	wilc_wlan_cfg_deinit(wl);
1843
1844free_wl:
1845	wlan_deinit_locks(wl);
1846	wiphy_free(wl->wiphy);
1847	return ret;
1848}
1849EXPORT_SYMBOL_GPL(wilc_cfg80211_init);
1850
1851int wilc_cfg80211_register(struct wilc *wilc)
1852{
1853	/* WPA3/SAE supported only on WILC1000 */
1854	if (is_wilc1000(wilc->chipid))
1855		wilc->wiphy->features |= NL80211_FEATURE_SAE;
1856
1857	return wiphy_register(wilc->wiphy);
1858}
1859EXPORT_SYMBOL_GPL(wilc_cfg80211_register);
1860
1861int wilc_init_host_int(struct net_device *net)
1862{
1863	int ret;
1864	struct wilc_vif *vif = netdev_priv(net);
1865	struct wilc_priv *priv = &vif->priv;
1866
1867	priv->p2p_listen_state = false;
1868
1869	mutex_init(&priv->scan_req_lock);
1870	ret = wilc_init(net, &priv->hif_drv);
1871	if (ret)
1872		netdev_err(net, "Error while initializing hostinterface\n");
1873
1874	return ret;
1875}
1876
1877void wilc_deinit_host_int(struct net_device *net)
1878{
1879	int ret;
1880	struct wilc_vif *vif = netdev_priv(net);
1881	struct wilc_priv *priv = &vif->priv;
1882
1883	priv->p2p_listen_state = false;
1884
1885	flush_workqueue(vif->wilc->hif_workqueue);
1886	mutex_destroy(&priv->scan_req_lock);
1887	ret = wilc_deinit(vif);
1888
1889	if (ret)
1890		netdev_err(net, "Error while deinitializing host interface\n");
1891}
1892
~/ Read-only file preview.