12be7d22fSVladimir Kondratiev /*
22be7d22fSVladimir Kondratiev  * Copyright (c) 2012 Qualcomm Atheros, Inc.
32be7d22fSVladimir Kondratiev  *
42be7d22fSVladimir Kondratiev  * Permission to use, copy, modify, and/or distribute this software for any
52be7d22fSVladimir Kondratiev  * purpose with or without fee is hereby granted, provided that the above
62be7d22fSVladimir Kondratiev  * copyright notice and this permission notice appear in all copies.
72be7d22fSVladimir Kondratiev  *
82be7d22fSVladimir Kondratiev  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
92be7d22fSVladimir Kondratiev  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
102be7d22fSVladimir Kondratiev  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
112be7d22fSVladimir Kondratiev  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
122be7d22fSVladimir Kondratiev  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
132be7d22fSVladimir Kondratiev  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
142be7d22fSVladimir Kondratiev  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
152be7d22fSVladimir Kondratiev  */
162be7d22fSVladimir Kondratiev 
172be7d22fSVladimir Kondratiev #include "wil6210.h"
182be7d22fSVladimir Kondratiev #include "wmi.h"
192be7d22fSVladimir Kondratiev 
202be7d22fSVladimir Kondratiev #define CHAN60G(_channel, _flags) {				\
212be7d22fSVladimir Kondratiev 	.band			= IEEE80211_BAND_60GHZ,		\
222be7d22fSVladimir Kondratiev 	.center_freq		= 56160 + (2160 * (_channel)),	\
232be7d22fSVladimir Kondratiev 	.hw_value		= (_channel),			\
242be7d22fSVladimir Kondratiev 	.flags			= (_flags),			\
252be7d22fSVladimir Kondratiev 	.max_antenna_gain	= 0,				\
262be7d22fSVladimir Kondratiev 	.max_power		= 40,				\
272be7d22fSVladimir Kondratiev }
282be7d22fSVladimir Kondratiev 
292be7d22fSVladimir Kondratiev static struct ieee80211_channel wil_60ghz_channels[] = {
302be7d22fSVladimir Kondratiev 	CHAN60G(1, 0),
312be7d22fSVladimir Kondratiev 	CHAN60G(2, 0),
322be7d22fSVladimir Kondratiev 	CHAN60G(3, 0),
332be7d22fSVladimir Kondratiev /* channel 4 not supported yet */
342be7d22fSVladimir Kondratiev };
352be7d22fSVladimir Kondratiev 
362be7d22fSVladimir Kondratiev static struct ieee80211_supported_band wil_band_60ghz = {
372be7d22fSVladimir Kondratiev 	.channels = wil_60ghz_channels,
382be7d22fSVladimir Kondratiev 	.n_channels = ARRAY_SIZE(wil_60ghz_channels),
392be7d22fSVladimir Kondratiev 	.ht_cap = {
402be7d22fSVladimir Kondratiev 		.ht_supported = true,
412be7d22fSVladimir Kondratiev 		.cap = 0, /* TODO */
422be7d22fSVladimir Kondratiev 		.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K, /* TODO */
432be7d22fSVladimir Kondratiev 		.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8, /* TODO */
442be7d22fSVladimir Kondratiev 		.mcs = {
452be7d22fSVladimir Kondratiev 				/* MCS 1..12 - SC PHY */
462be7d22fSVladimir Kondratiev 			.rx_mask = {0xfe, 0x1f}, /* 1..12 */
472be7d22fSVladimir Kondratiev 			.tx_params = IEEE80211_HT_MCS_TX_DEFINED, /* TODO */
482be7d22fSVladimir Kondratiev 		},
492be7d22fSVladimir Kondratiev 	},
502be7d22fSVladimir Kondratiev };
512be7d22fSVladimir Kondratiev 
522be7d22fSVladimir Kondratiev static const struct ieee80211_txrx_stypes
532be7d22fSVladimir Kondratiev wil_mgmt_stypes[NUM_NL80211_IFTYPES] = {
542be7d22fSVladimir Kondratiev 	[NL80211_IFTYPE_STATION] = {
552be7d22fSVladimir Kondratiev 		.tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
562be7d22fSVladimir Kondratiev 		BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
572be7d22fSVladimir Kondratiev 		.rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
582be7d22fSVladimir Kondratiev 		BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
592be7d22fSVladimir Kondratiev 	},
602be7d22fSVladimir Kondratiev 	[NL80211_IFTYPE_AP] = {
612be7d22fSVladimir Kondratiev 		.tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
622be7d22fSVladimir Kondratiev 		BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
632be7d22fSVladimir Kondratiev 		.rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
642be7d22fSVladimir Kondratiev 		BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
652be7d22fSVladimir Kondratiev 	},
662be7d22fSVladimir Kondratiev 	[NL80211_IFTYPE_P2P_CLIENT] = {
672be7d22fSVladimir Kondratiev 		.tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
682be7d22fSVladimir Kondratiev 		BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
692be7d22fSVladimir Kondratiev 		.rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
702be7d22fSVladimir Kondratiev 		BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
712be7d22fSVladimir Kondratiev 	},
722be7d22fSVladimir Kondratiev 	[NL80211_IFTYPE_P2P_GO] = {
732be7d22fSVladimir Kondratiev 		.tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
742be7d22fSVladimir Kondratiev 		BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
752be7d22fSVladimir Kondratiev 		.rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
762be7d22fSVladimir Kondratiev 		BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
772be7d22fSVladimir Kondratiev 	},
782be7d22fSVladimir Kondratiev };
792be7d22fSVladimir Kondratiev 
802be7d22fSVladimir Kondratiev static const u32 wil_cipher_suites[] = {
812be7d22fSVladimir Kondratiev 	WLAN_CIPHER_SUITE_GCMP,
822be7d22fSVladimir Kondratiev };
832be7d22fSVladimir Kondratiev 
842be7d22fSVladimir Kondratiev int wil_iftype_nl2wmi(enum nl80211_iftype type)
852be7d22fSVladimir Kondratiev {
862be7d22fSVladimir Kondratiev 	static const struct {
872be7d22fSVladimir Kondratiev 		enum nl80211_iftype nl;
882be7d22fSVladimir Kondratiev 		enum wmi_network_type wmi;
892be7d22fSVladimir Kondratiev 	} __nl2wmi[] = {
902be7d22fSVladimir Kondratiev 		{NL80211_IFTYPE_ADHOC,		WMI_NETTYPE_ADHOC},
912be7d22fSVladimir Kondratiev 		{NL80211_IFTYPE_STATION,	WMI_NETTYPE_INFRA},
922be7d22fSVladimir Kondratiev 		{NL80211_IFTYPE_AP,		WMI_NETTYPE_AP},
932be7d22fSVladimir Kondratiev 		{NL80211_IFTYPE_P2P_CLIENT,	WMI_NETTYPE_P2P},
942be7d22fSVladimir Kondratiev 		{NL80211_IFTYPE_P2P_GO,		WMI_NETTYPE_P2P},
952be7d22fSVladimir Kondratiev 		{NL80211_IFTYPE_MONITOR,	WMI_NETTYPE_ADHOC}, /* FIXME */
962be7d22fSVladimir Kondratiev 	};
972be7d22fSVladimir Kondratiev 	uint i;
982be7d22fSVladimir Kondratiev 
992be7d22fSVladimir Kondratiev 	for (i = 0; i < ARRAY_SIZE(__nl2wmi); i++) {
1002be7d22fSVladimir Kondratiev 		if (__nl2wmi[i].nl == type)
1012be7d22fSVladimir Kondratiev 			return __nl2wmi[i].wmi;
1022be7d22fSVladimir Kondratiev 	}
1032be7d22fSVladimir Kondratiev 
1042be7d22fSVladimir Kondratiev 	return -EOPNOTSUPP;
1052be7d22fSVladimir Kondratiev }
1062be7d22fSVladimir Kondratiev 
107ef28afdbSVladimir Kondratiev static int wil_cid_fill_sinfo(struct wil6210_priv *wil, int cid,
108ef28afdbSVladimir Kondratiev 			      struct station_info *sinfo)
1092be7d22fSVladimir Kondratiev {
1102be7d22fSVladimir Kondratiev 	struct wmi_notify_req_cmd cmd = {
1113df2cd36SVladimir Kondratiev 		.cid = cid,
1122be7d22fSVladimir Kondratiev 		.interval_usec = 0,
1132be7d22fSVladimir Kondratiev 	};
114ef28afdbSVladimir Kondratiev 	struct {
115ef28afdbSVladimir Kondratiev 		struct wil6210_mbox_hdr_wmi wmi;
116ef28afdbSVladimir Kondratiev 		struct wmi_notify_req_done_event evt;
117ef28afdbSVladimir Kondratiev 	} __packed reply;
118ef28afdbSVladimir Kondratiev 	int rc;
1192be7d22fSVladimir Kondratiev 
1202be7d22fSVladimir Kondratiev 	rc = wmi_call(wil, WMI_NOTIFY_REQ_CMDID, &cmd, sizeof(cmd),
121ef28afdbSVladimir Kondratiev 		      WMI_NOTIFY_REQ_DONE_EVENTID, &reply, sizeof(reply), 20);
1222be7d22fSVladimir Kondratiev 	if (rc)
1232be7d22fSVladimir Kondratiev 		return rc;
1242be7d22fSVladimir Kondratiev 
1252be7d22fSVladimir Kondratiev 	sinfo->generation = wil->sinfo_gen;
1262be7d22fSVladimir Kondratiev 
1272be7d22fSVladimir Kondratiev 	sinfo->filled |= STATION_INFO_TX_BITRATE;
1282be7d22fSVladimir Kondratiev 	sinfo->txrate.flags = RATE_INFO_FLAGS_MCS | RATE_INFO_FLAGS_60G;
129ef28afdbSVladimir Kondratiev 	sinfo->txrate.mcs = le16_to_cpu(reply.evt.bf_mcs);
1302be7d22fSVladimir Kondratiev 	sinfo->filled |= STATION_INFO_RX_BITRATE;
1312be7d22fSVladimir Kondratiev 	sinfo->rxrate.flags = RATE_INFO_FLAGS_MCS | RATE_INFO_FLAGS_60G;
1322be7d22fSVladimir Kondratiev 	sinfo->rxrate.mcs = wil->stats.last_mcs_rx;
1332be7d22fSVladimir Kondratiev 
1342be7d22fSVladimir Kondratiev 	if (test_bit(wil_status_fwconnected, &wil->status)) {
1352be7d22fSVladimir Kondratiev 		sinfo->filled |= STATION_INFO_SIGNAL;
1362be7d22fSVladimir Kondratiev 		sinfo->signal = 12; /* TODO: provide real value */
1372be7d22fSVladimir Kondratiev 	}
1382be7d22fSVladimir Kondratiev 
139ef28afdbSVladimir Kondratiev 	return rc;
140ef28afdbSVladimir Kondratiev }
141ef28afdbSVladimir Kondratiev 
142ef28afdbSVladimir Kondratiev static int wil_cfg80211_get_station(struct wiphy *wiphy,
143ef28afdbSVladimir Kondratiev 				    struct net_device *ndev,
144ef28afdbSVladimir Kondratiev 				    u8 *mac, struct station_info *sinfo)
145ef28afdbSVladimir Kondratiev {
146ef28afdbSVladimir Kondratiev 	struct wil6210_priv *wil = wiphy_to_wil(wiphy);
147ef28afdbSVladimir Kondratiev 	int rc;
148ef28afdbSVladimir Kondratiev 
149ef28afdbSVladimir Kondratiev 	int cid = wil_find_cid(wil, mac);
150ef28afdbSVladimir Kondratiev 
151ef28afdbSVladimir Kondratiev 	wil_info(wil, "%s(%pM) CID %d\n", __func__, mac, cid);
152ef28afdbSVladimir Kondratiev 	if (cid < 0)
153ef28afdbSVladimir Kondratiev 		return -ENOENT;
154ef28afdbSVladimir Kondratiev 
155ef28afdbSVladimir Kondratiev 	rc = wil_cid_fill_sinfo(wil, cid, sinfo);
156ef28afdbSVladimir Kondratiev 
157ef28afdbSVladimir Kondratiev 	return rc;
158ef28afdbSVladimir Kondratiev }
159ef28afdbSVladimir Kondratiev 
160ef28afdbSVladimir Kondratiev /*
161ef28afdbSVladimir Kondratiev  * Find @idx-th active STA for station dump.
162ef28afdbSVladimir Kondratiev  */
163ef28afdbSVladimir Kondratiev static int wil_find_cid_by_idx(struct wil6210_priv *wil, int idx)
164ef28afdbSVladimir Kondratiev {
165ef28afdbSVladimir Kondratiev 	int i;
166ef28afdbSVladimir Kondratiev 
167ef28afdbSVladimir Kondratiev 	for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
168ef28afdbSVladimir Kondratiev 		if (wil->sta[i].status == wil_sta_unused)
169ef28afdbSVladimir Kondratiev 			continue;
170ef28afdbSVladimir Kondratiev 		if (idx == 0)
171ef28afdbSVladimir Kondratiev 			return i;
172ef28afdbSVladimir Kondratiev 		idx--;
173ef28afdbSVladimir Kondratiev 	}
174ef28afdbSVladimir Kondratiev 
175ef28afdbSVladimir Kondratiev 	return -ENOENT;
176ef28afdbSVladimir Kondratiev }
177ef28afdbSVladimir Kondratiev 
178ef28afdbSVladimir Kondratiev static int wil_cfg80211_dump_station(struct wiphy *wiphy,
179ef28afdbSVladimir Kondratiev 				     struct net_device *dev, int idx,
180ef28afdbSVladimir Kondratiev 				     u8 *mac, struct station_info *sinfo)
181ef28afdbSVladimir Kondratiev {
182ef28afdbSVladimir Kondratiev 	struct wil6210_priv *wil = wiphy_to_wil(wiphy);
183ef28afdbSVladimir Kondratiev 	int rc;
184ef28afdbSVladimir Kondratiev 	int cid = wil_find_cid_by_idx(wil, idx);
185ef28afdbSVladimir Kondratiev 
186ef28afdbSVladimir Kondratiev 	if (cid < 0)
187ef28afdbSVladimir Kondratiev 		return -ENOENT;
188ef28afdbSVladimir Kondratiev 
189ef28afdbSVladimir Kondratiev 	memcpy(mac, wil->sta[cid].addr, ETH_ALEN);
190ef28afdbSVladimir Kondratiev 	wil_info(wil, "%s(%pM) CID %d\n", __func__, mac, cid);
191ef28afdbSVladimir Kondratiev 
192ef28afdbSVladimir Kondratiev 	rc = wil_cid_fill_sinfo(wil, cid, sinfo);
193ef28afdbSVladimir Kondratiev 
194ef28afdbSVladimir Kondratiev 	return rc;
1952be7d22fSVladimir Kondratiev }
1962be7d22fSVladimir Kondratiev 
1972be7d22fSVladimir Kondratiev static int wil_cfg80211_change_iface(struct wiphy *wiphy,
1982be7d22fSVladimir Kondratiev 				     struct net_device *ndev,
1992be7d22fSVladimir Kondratiev 				     enum nl80211_iftype type, u32 *flags,
2002be7d22fSVladimir Kondratiev 				     struct vif_params *params)
2012be7d22fSVladimir Kondratiev {
2022be7d22fSVladimir Kondratiev 	struct wil6210_priv *wil = wiphy_to_wil(wiphy);
2032be7d22fSVladimir Kondratiev 	struct wireless_dev *wdev = wil->wdev;
2042be7d22fSVladimir Kondratiev 
2052be7d22fSVladimir Kondratiev 	switch (type) {
2062be7d22fSVladimir Kondratiev 	case NL80211_IFTYPE_STATION:
2072be7d22fSVladimir Kondratiev 	case NL80211_IFTYPE_AP:
2082be7d22fSVladimir Kondratiev 	case NL80211_IFTYPE_P2P_CLIENT:
2092be7d22fSVladimir Kondratiev 	case NL80211_IFTYPE_P2P_GO:
2102be7d22fSVladimir Kondratiev 		break;
2112be7d22fSVladimir Kondratiev 	case NL80211_IFTYPE_MONITOR:
2122be7d22fSVladimir Kondratiev 		if (flags)
2132be7d22fSVladimir Kondratiev 			wil->monitor_flags = *flags;
2142be7d22fSVladimir Kondratiev 		else
2152be7d22fSVladimir Kondratiev 			wil->monitor_flags = 0;
2162be7d22fSVladimir Kondratiev 
2172be7d22fSVladimir Kondratiev 		break;
2182be7d22fSVladimir Kondratiev 	default:
2192be7d22fSVladimir Kondratiev 		return -EOPNOTSUPP;
2202be7d22fSVladimir Kondratiev 	}
2212be7d22fSVladimir Kondratiev 
2222be7d22fSVladimir Kondratiev 	wdev->iftype = type;
2232be7d22fSVladimir Kondratiev 
2242be7d22fSVladimir Kondratiev 	return 0;
2252be7d22fSVladimir Kondratiev }
2262be7d22fSVladimir Kondratiev 
2272be7d22fSVladimir Kondratiev static int wil_cfg80211_scan(struct wiphy *wiphy,
2282be7d22fSVladimir Kondratiev 			     struct cfg80211_scan_request *request)
2292be7d22fSVladimir Kondratiev {
2302be7d22fSVladimir Kondratiev 	struct wil6210_priv *wil = wiphy_to_wil(wiphy);
2312be7d22fSVladimir Kondratiev 	struct wireless_dev *wdev = wil->wdev;
2322be7d22fSVladimir Kondratiev 	struct {
2332be7d22fSVladimir Kondratiev 		struct wmi_start_scan_cmd cmd;
2342be7d22fSVladimir Kondratiev 		u16 chnl[4];
2352be7d22fSVladimir Kondratiev 	} __packed cmd;
2362be7d22fSVladimir Kondratiev 	uint i, n;
2372be7d22fSVladimir Kondratiev 
2382be7d22fSVladimir Kondratiev 	if (wil->scan_request) {
2392be7d22fSVladimir Kondratiev 		wil_err(wil, "Already scanning\n");
2402be7d22fSVladimir Kondratiev 		return -EAGAIN;
2412be7d22fSVladimir Kondratiev 	}
2422be7d22fSVladimir Kondratiev 
2432be7d22fSVladimir Kondratiev 	/* check we are client side */
2442be7d22fSVladimir Kondratiev 	switch (wdev->iftype) {
2452be7d22fSVladimir Kondratiev 	case NL80211_IFTYPE_STATION:
2462be7d22fSVladimir Kondratiev 	case NL80211_IFTYPE_P2P_CLIENT:
2472be7d22fSVladimir Kondratiev 		break;
2482be7d22fSVladimir Kondratiev 	default:
2492be7d22fSVladimir Kondratiev 		return -EOPNOTSUPP;
2502be7d22fSVladimir Kondratiev 	}
2512be7d22fSVladimir Kondratiev 
2522be7d22fSVladimir Kondratiev 	/* FW don't support scan after connection attempt */
2532be7d22fSVladimir Kondratiev 	if (test_bit(wil_status_dontscan, &wil->status)) {
2542be7d22fSVladimir Kondratiev 		wil_err(wil, "Scan after connect attempt not supported\n");
2552be7d22fSVladimir Kondratiev 		return -EBUSY;
2562be7d22fSVladimir Kondratiev 	}
2572be7d22fSVladimir Kondratiev 
2582be7d22fSVladimir Kondratiev 	wil->scan_request = request;
2592be7d22fSVladimir Kondratiev 
2602be7d22fSVladimir Kondratiev 	memset(&cmd, 0, sizeof(cmd));
2612be7d22fSVladimir Kondratiev 	cmd.cmd.num_channels = 0;
2622be7d22fSVladimir Kondratiev 	n = min(request->n_channels, 4U);
2632be7d22fSVladimir Kondratiev 	for (i = 0; i < n; i++) {
2642be7d22fSVladimir Kondratiev 		int ch = request->channels[i]->hw_value;
2652be7d22fSVladimir Kondratiev 		if (ch == 0) {
2662be7d22fSVladimir Kondratiev 			wil_err(wil,
2672be7d22fSVladimir Kondratiev 				"Scan requested for unknown frequency %dMhz\n",
2682be7d22fSVladimir Kondratiev 				request->channels[i]->center_freq);
2692be7d22fSVladimir Kondratiev 			continue;
2702be7d22fSVladimir Kondratiev 		}
2712be7d22fSVladimir Kondratiev 		/* 0-based channel indexes */
2722be7d22fSVladimir Kondratiev 		cmd.cmd.channel_list[cmd.cmd.num_channels++].channel = ch - 1;
2737743882dSVladimir Kondratiev 		wil_dbg_misc(wil, "Scan for ch %d  : %d MHz\n", ch,
2742be7d22fSVladimir Kondratiev 			     request->channels[i]->center_freq);
2752be7d22fSVladimir Kondratiev 	}
2762be7d22fSVladimir Kondratiev 
2772be7d22fSVladimir Kondratiev 	return wmi_send(wil, WMI_START_SCAN_CMDID, &cmd, sizeof(cmd.cmd) +
2782be7d22fSVladimir Kondratiev 			cmd.cmd.num_channels * sizeof(cmd.cmd.channel_list[0]));
2792be7d22fSVladimir Kondratiev }
2802be7d22fSVladimir Kondratiev 
2812be7d22fSVladimir Kondratiev static int wil_cfg80211_connect(struct wiphy *wiphy,
2822be7d22fSVladimir Kondratiev 				struct net_device *ndev,
2832be7d22fSVladimir Kondratiev 				struct cfg80211_connect_params *sme)
2842be7d22fSVladimir Kondratiev {
2852be7d22fSVladimir Kondratiev 	struct wil6210_priv *wil = wiphy_to_wil(wiphy);
2862be7d22fSVladimir Kondratiev 	struct cfg80211_bss *bss;
2872be7d22fSVladimir Kondratiev 	struct wmi_connect_cmd conn;
2882be7d22fSVladimir Kondratiev 	const u8 *ssid_eid;
2892be7d22fSVladimir Kondratiev 	const u8 *rsn_eid;
2902be7d22fSVladimir Kondratiev 	int ch;
2912be7d22fSVladimir Kondratiev 	int rc = 0;
2922be7d22fSVladimir Kondratiev 
2932be7d22fSVladimir Kondratiev 	bss = cfg80211_get_bss(wiphy, sme->channel, sme->bssid,
2942be7d22fSVladimir Kondratiev 			       sme->ssid, sme->ssid_len,
2952be7d22fSVladimir Kondratiev 			       WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
2962be7d22fSVladimir Kondratiev 	if (!bss) {
2972be7d22fSVladimir Kondratiev 		wil_err(wil, "Unable to find BSS\n");
2982be7d22fSVladimir Kondratiev 		return -ENOENT;
2992be7d22fSVladimir Kondratiev 	}
3002be7d22fSVladimir Kondratiev 
3012be7d22fSVladimir Kondratiev 	ssid_eid = ieee80211_bss_get_ie(bss, WLAN_EID_SSID);
3022be7d22fSVladimir Kondratiev 	if (!ssid_eid) {
3032be7d22fSVladimir Kondratiev 		wil_err(wil, "No SSID\n");
3042be7d22fSVladimir Kondratiev 		rc = -ENOENT;
3052be7d22fSVladimir Kondratiev 		goto out;
3062be7d22fSVladimir Kondratiev 	}
3072be7d22fSVladimir Kondratiev 
3082be7d22fSVladimir Kondratiev 	rsn_eid = sme->ie ?
3092be7d22fSVladimir Kondratiev 			cfg80211_find_ie(WLAN_EID_RSN, sme->ie, sme->ie_len) :
3102be7d22fSVladimir Kondratiev 			NULL;
3112be7d22fSVladimir Kondratiev 	if (rsn_eid) {
3122be7d22fSVladimir Kondratiev 		if (sme->ie_len > WMI_MAX_IE_LEN) {
3132be7d22fSVladimir Kondratiev 			rc = -ERANGE;
3142be7d22fSVladimir Kondratiev 			wil_err(wil, "IE too large (%td bytes)\n",
3152be7d22fSVladimir Kondratiev 				sme->ie_len);
3162be7d22fSVladimir Kondratiev 			goto out;
3172be7d22fSVladimir Kondratiev 		}
3182be7d22fSVladimir Kondratiev 		/*
3192be7d22fSVladimir Kondratiev 		 * For secure assoc, send:
3202be7d22fSVladimir Kondratiev 		 * (1) WMI_DELETE_CIPHER_KEY_CMD
3212be7d22fSVladimir Kondratiev 		 * (2) WMI_SET_APPIE_CMD
3222be7d22fSVladimir Kondratiev 		 */
3232be7d22fSVladimir Kondratiev 		rc = wmi_del_cipher_key(wil, 0, bss->bssid);
3242be7d22fSVladimir Kondratiev 		if (rc) {
3252be7d22fSVladimir Kondratiev 			wil_err(wil, "WMI_DELETE_CIPHER_KEY_CMD failed\n");
3262be7d22fSVladimir Kondratiev 			goto out;
3272be7d22fSVladimir Kondratiev 		}
3282be7d22fSVladimir Kondratiev 		/* WMI_SET_APPIE_CMD */
3292be7d22fSVladimir Kondratiev 		rc = wmi_set_ie(wil, WMI_FRAME_ASSOC_REQ, sme->ie_len, sme->ie);
3302be7d22fSVladimir Kondratiev 		if (rc) {
3312be7d22fSVladimir Kondratiev 			wil_err(wil, "WMI_SET_APPIE_CMD failed\n");
3322be7d22fSVladimir Kondratiev 			goto out;
3332be7d22fSVladimir Kondratiev 		}
3342be7d22fSVladimir Kondratiev 	}
3352be7d22fSVladimir Kondratiev 
3362be7d22fSVladimir Kondratiev 	/* WMI_CONNECT_CMD */
3372be7d22fSVladimir Kondratiev 	memset(&conn, 0, sizeof(conn));
338acc9780dSVladimir Kondratiev 	switch (bss->capability & WLAN_CAPABILITY_DMG_TYPE_MASK) {
3392be7d22fSVladimir Kondratiev 	case WLAN_CAPABILITY_DMG_TYPE_AP:
3402be7d22fSVladimir Kondratiev 		conn.network_type = WMI_NETTYPE_INFRA;
3412be7d22fSVladimir Kondratiev 		break;
3422be7d22fSVladimir Kondratiev 	case WLAN_CAPABILITY_DMG_TYPE_PBSS:
3432be7d22fSVladimir Kondratiev 		conn.network_type = WMI_NETTYPE_P2P;
3442be7d22fSVladimir Kondratiev 		break;
3452be7d22fSVladimir Kondratiev 	default:
3462be7d22fSVladimir Kondratiev 		wil_err(wil, "Unsupported BSS type, capability= 0x%04x\n",
3472be7d22fSVladimir Kondratiev 			bss->capability);
3482be7d22fSVladimir Kondratiev 		goto out;
3492be7d22fSVladimir Kondratiev 	}
3502be7d22fSVladimir Kondratiev 	if (rsn_eid) {
3512be7d22fSVladimir Kondratiev 		conn.dot11_auth_mode = WMI_AUTH11_SHARED;
3522be7d22fSVladimir Kondratiev 		conn.auth_mode = WMI_AUTH_WPA2_PSK;
3532be7d22fSVladimir Kondratiev 		conn.pairwise_crypto_type = WMI_CRYPT_AES_GCMP;
3542be7d22fSVladimir Kondratiev 		conn.pairwise_crypto_len = 16;
3552be7d22fSVladimir Kondratiev 	} else {
3562be7d22fSVladimir Kondratiev 		conn.dot11_auth_mode = WMI_AUTH11_OPEN;
3572be7d22fSVladimir Kondratiev 		conn.auth_mode = WMI_AUTH_NONE;
3582be7d22fSVladimir Kondratiev 	}
3592be7d22fSVladimir Kondratiev 
3602be7d22fSVladimir Kondratiev 	conn.ssid_len = min_t(u8, ssid_eid[1], 32);
3612be7d22fSVladimir Kondratiev 	memcpy(conn.ssid, ssid_eid+2, conn.ssid_len);
3622be7d22fSVladimir Kondratiev 
3632be7d22fSVladimir Kondratiev 	ch = bss->channel->hw_value;
3642be7d22fSVladimir Kondratiev 	if (ch == 0) {
3652be7d22fSVladimir Kondratiev 		wil_err(wil, "BSS at unknown frequency %dMhz\n",
3662be7d22fSVladimir Kondratiev 			bss->channel->center_freq);
3672be7d22fSVladimir Kondratiev 		rc = -EOPNOTSUPP;
3682be7d22fSVladimir Kondratiev 		goto out;
3692be7d22fSVladimir Kondratiev 	}
3702be7d22fSVladimir Kondratiev 	conn.channel = ch - 1;
3712be7d22fSVladimir Kondratiev 
372d458cdf7SJoe Perches 	memcpy(conn.bssid, bss->bssid, ETH_ALEN);
373d458cdf7SJoe Perches 	memcpy(conn.dst_mac, bss->bssid, ETH_ALEN);
3742be7d22fSVladimir Kondratiev 	/*
3752be7d22fSVladimir Kondratiev 	 * FW don't support scan after connection attempt
3762be7d22fSVladimir Kondratiev 	 */
3772be7d22fSVladimir Kondratiev 	set_bit(wil_status_dontscan, &wil->status);
378b338f74eSVladimir Kondratiev 	set_bit(wil_status_fwconnecting, &wil->status);
3792be7d22fSVladimir Kondratiev 
3802be7d22fSVladimir Kondratiev 	rc = wmi_send(wil, WMI_CONNECT_CMDID, &conn, sizeof(conn));
3812be7d22fSVladimir Kondratiev 	if (rc == 0) {
3822be7d22fSVladimir Kondratiev 		/* Connect can take lots of time */
3832be7d22fSVladimir Kondratiev 		mod_timer(&wil->connect_timer,
3842be7d22fSVladimir Kondratiev 			  jiffies + msecs_to_jiffies(2000));
385b338f74eSVladimir Kondratiev 	} else {
386b338f74eSVladimir Kondratiev 		clear_bit(wil_status_dontscan, &wil->status);
387b338f74eSVladimir Kondratiev 		clear_bit(wil_status_fwconnecting, &wil->status);
3882be7d22fSVladimir Kondratiev 	}
3892be7d22fSVladimir Kondratiev 
3902be7d22fSVladimir Kondratiev  out:
3915b112d3dSJohannes Berg 	cfg80211_put_bss(wiphy, bss);
3922be7d22fSVladimir Kondratiev 
3932be7d22fSVladimir Kondratiev 	return rc;
3942be7d22fSVladimir Kondratiev }
3952be7d22fSVladimir Kondratiev 
3962be7d22fSVladimir Kondratiev static int wil_cfg80211_disconnect(struct wiphy *wiphy,
3972be7d22fSVladimir Kondratiev 				   struct net_device *ndev,
3982be7d22fSVladimir Kondratiev 				   u16 reason_code)
3992be7d22fSVladimir Kondratiev {
4002be7d22fSVladimir Kondratiev 	int rc;
4012be7d22fSVladimir Kondratiev 	struct wil6210_priv *wil = wiphy_to_wil(wiphy);
4022be7d22fSVladimir Kondratiev 
4032be7d22fSVladimir Kondratiev 	rc = wmi_send(wil, WMI_DISCONNECT_CMDID, NULL, 0);
4042be7d22fSVladimir Kondratiev 
4052be7d22fSVladimir Kondratiev 	return rc;
4062be7d22fSVladimir Kondratiev }
4072be7d22fSVladimir Kondratiev 
4081647f12fSVladimir Kondratiev static int wil_cfg80211_mgmt_tx(struct wiphy *wiphy,
4091647f12fSVladimir Kondratiev 				struct wireless_dev *wdev,
4101647f12fSVladimir Kondratiev 				struct cfg80211_mgmt_tx_params *params,
4111647f12fSVladimir Kondratiev 				u64 *cookie)
4121647f12fSVladimir Kondratiev {
4131647f12fSVladimir Kondratiev 	const u8 *buf = params->buf;
4141647f12fSVladimir Kondratiev 	size_t len = params->len;
4151647f12fSVladimir Kondratiev 	struct wil6210_priv *wil = wiphy_to_wil(wiphy);
4161647f12fSVladimir Kondratiev 	int rc;
4171647f12fSVladimir Kondratiev 	struct ieee80211_mgmt *mgmt_frame = (void *)buf;
4181647f12fSVladimir Kondratiev 	struct wmi_sw_tx_req_cmd *cmd;
4191647f12fSVladimir Kondratiev 	struct {
4201647f12fSVladimir Kondratiev 		struct wil6210_mbox_hdr_wmi wmi;
4211647f12fSVladimir Kondratiev 		struct wmi_sw_tx_complete_event evt;
4221647f12fSVladimir Kondratiev 	} __packed evt;
4231647f12fSVladimir Kondratiev 
4241647f12fSVladimir Kondratiev 	cmd = kmalloc(sizeof(*cmd) + len, GFP_KERNEL);
4251647f12fSVladimir Kondratiev 	if (!cmd)
4261647f12fSVladimir Kondratiev 		return -ENOMEM;
4271647f12fSVladimir Kondratiev 
4281647f12fSVladimir Kondratiev 	memcpy(cmd->dst_mac, mgmt_frame->da, WMI_MAC_LEN);
4291647f12fSVladimir Kondratiev 	cmd->len = cpu_to_le16(len);
4301647f12fSVladimir Kondratiev 	memcpy(cmd->payload, buf, len);
4311647f12fSVladimir Kondratiev 
4321647f12fSVladimir Kondratiev 	rc = wmi_call(wil, WMI_SW_TX_REQ_CMDID, cmd, sizeof(*cmd) + len,
4331647f12fSVladimir Kondratiev 		      WMI_SW_TX_COMPLETE_EVENTID, &evt, sizeof(evt), 2000);
4341647f12fSVladimir Kondratiev 	if (rc == 0)
4351647f12fSVladimir Kondratiev 		rc = evt.evt.status;
4361647f12fSVladimir Kondratiev 
4371647f12fSVladimir Kondratiev 	kfree(cmd);
4381647f12fSVladimir Kondratiev 
4391647f12fSVladimir Kondratiev 	return rc;
4401647f12fSVladimir Kondratiev }
4411647f12fSVladimir Kondratiev 
4422be7d22fSVladimir Kondratiev static int wil_cfg80211_set_channel(struct wiphy *wiphy,
4432be7d22fSVladimir Kondratiev 				    struct cfg80211_chan_def *chandef)
4442be7d22fSVladimir Kondratiev {
4452be7d22fSVladimir Kondratiev 	struct wil6210_priv *wil = wiphy_to_wil(wiphy);
4462be7d22fSVladimir Kondratiev 	struct wireless_dev *wdev = wil->wdev;
4472be7d22fSVladimir Kondratiev 
4482be7d22fSVladimir Kondratiev 	wdev->preset_chandef = *chandef;
4492be7d22fSVladimir Kondratiev 
4502be7d22fSVladimir Kondratiev 	return 0;
4512be7d22fSVladimir Kondratiev }
4522be7d22fSVladimir Kondratiev 
4532be7d22fSVladimir Kondratiev static int wil_cfg80211_add_key(struct wiphy *wiphy,
4542be7d22fSVladimir Kondratiev 				struct net_device *ndev,
4552be7d22fSVladimir Kondratiev 				u8 key_index, bool pairwise,
4562be7d22fSVladimir Kondratiev 				const u8 *mac_addr,
4572be7d22fSVladimir Kondratiev 				struct key_params *params)
4582be7d22fSVladimir Kondratiev {
4592be7d22fSVladimir Kondratiev 	struct wil6210_priv *wil = wiphy_to_wil(wiphy);
4602be7d22fSVladimir Kondratiev 
4612be7d22fSVladimir Kondratiev 	/* group key is not used */
4622be7d22fSVladimir Kondratiev 	if (!pairwise)
4632be7d22fSVladimir Kondratiev 		return 0;
4642be7d22fSVladimir Kondratiev 
4652be7d22fSVladimir Kondratiev 	return wmi_add_cipher_key(wil, key_index, mac_addr,
4662be7d22fSVladimir Kondratiev 				  params->key_len, params->key);
4672be7d22fSVladimir Kondratiev }
4682be7d22fSVladimir Kondratiev 
4692be7d22fSVladimir Kondratiev static int wil_cfg80211_del_key(struct wiphy *wiphy,
4702be7d22fSVladimir Kondratiev 				struct net_device *ndev,
4712be7d22fSVladimir Kondratiev 				u8 key_index, bool pairwise,
4722be7d22fSVladimir Kondratiev 				const u8 *mac_addr)
4732be7d22fSVladimir Kondratiev {
4742be7d22fSVladimir Kondratiev 	struct wil6210_priv *wil = wiphy_to_wil(wiphy);
4752be7d22fSVladimir Kondratiev 
4762be7d22fSVladimir Kondratiev 	/* group key is not used */
4772be7d22fSVladimir Kondratiev 	if (!pairwise)
4782be7d22fSVladimir Kondratiev 		return 0;
4792be7d22fSVladimir Kondratiev 
4802be7d22fSVladimir Kondratiev 	return wmi_del_cipher_key(wil, key_index, mac_addr);
4812be7d22fSVladimir Kondratiev }
4822be7d22fSVladimir Kondratiev 
4832be7d22fSVladimir Kondratiev /* Need to be present or wiphy_new() will WARN */
4842be7d22fSVladimir Kondratiev static int wil_cfg80211_set_default_key(struct wiphy *wiphy,
4852be7d22fSVladimir Kondratiev 					struct net_device *ndev,
4862be7d22fSVladimir Kondratiev 					u8 key_index, bool unicast,
4872be7d22fSVladimir Kondratiev 					bool multicast)
4882be7d22fSVladimir Kondratiev {
4892be7d22fSVladimir Kondratiev 	return 0;
4902be7d22fSVladimir Kondratiev }
4912be7d22fSVladimir Kondratiev 
4921647f12fSVladimir Kondratiev static int wil_remain_on_channel(struct wiphy *wiphy,
4931647f12fSVladimir Kondratiev 				 struct wireless_dev *wdev,
4941647f12fSVladimir Kondratiev 				 struct ieee80211_channel *chan,
4951647f12fSVladimir Kondratiev 				 unsigned int duration,
4961647f12fSVladimir Kondratiev 				 u64 *cookie)
4971647f12fSVladimir Kondratiev {
4981647f12fSVladimir Kondratiev 	struct wil6210_priv *wil = wiphy_to_wil(wiphy);
4991647f12fSVladimir Kondratiev 	int rc;
5001647f12fSVladimir Kondratiev 
5011647f12fSVladimir Kondratiev 	/* TODO: handle duration */
5021647f12fSVladimir Kondratiev 	wil_info(wil, "%s(%d, %d ms)\n", __func__, chan->center_freq, duration);
5031647f12fSVladimir Kondratiev 
5041647f12fSVladimir Kondratiev 	rc = wmi_set_channel(wil, chan->hw_value);
5051647f12fSVladimir Kondratiev 	if (rc)
5061647f12fSVladimir Kondratiev 		return rc;
5071647f12fSVladimir Kondratiev 
5081647f12fSVladimir Kondratiev 	rc = wmi_rxon(wil, true);
5091647f12fSVladimir Kondratiev 
5101647f12fSVladimir Kondratiev 	return rc;
5111647f12fSVladimir Kondratiev }
5121647f12fSVladimir Kondratiev 
5131647f12fSVladimir Kondratiev static int wil_cancel_remain_on_channel(struct wiphy *wiphy,
5141647f12fSVladimir Kondratiev 					struct wireless_dev *wdev,
5151647f12fSVladimir Kondratiev 					u64 cookie)
5161647f12fSVladimir Kondratiev {
5171647f12fSVladimir Kondratiev 	struct wil6210_priv *wil = wiphy_to_wil(wiphy);
5181647f12fSVladimir Kondratiev 	int rc;
5191647f12fSVladimir Kondratiev 
5201647f12fSVladimir Kondratiev 	wil_info(wil, "%s()\n", __func__);
5211647f12fSVladimir Kondratiev 
5221647f12fSVladimir Kondratiev 	rc = wmi_rxon(wil, false);
5231647f12fSVladimir Kondratiev 
5241647f12fSVladimir Kondratiev 	return rc;
5251647f12fSVladimir Kondratiev }
5261647f12fSVladimir Kondratiev 
52792646c9fSVladimir Kondratiev static int wil_fix_bcon(struct wil6210_priv *wil,
52892646c9fSVladimir Kondratiev 			struct cfg80211_beacon_data *bcon)
52992646c9fSVladimir Kondratiev {
53092646c9fSVladimir Kondratiev 	struct ieee80211_mgmt *f = (struct ieee80211_mgmt *)bcon->probe_resp;
53192646c9fSVladimir Kondratiev 	size_t hlen = offsetof(struct ieee80211_mgmt, u.probe_resp.variable);
53292646c9fSVladimir Kondratiev 	int rc = 0;
53392646c9fSVladimir Kondratiev 
53492646c9fSVladimir Kondratiev 	if (bcon->probe_resp_len <= hlen)
53592646c9fSVladimir Kondratiev 		return 0;
53692646c9fSVladimir Kondratiev 
53792646c9fSVladimir Kondratiev 	if (!bcon->proberesp_ies) {
53892646c9fSVladimir Kondratiev 		bcon->proberesp_ies = f->u.probe_resp.variable;
53992646c9fSVladimir Kondratiev 		bcon->proberesp_ies_len = bcon->probe_resp_len - hlen;
54092646c9fSVladimir Kondratiev 		rc = 1;
54192646c9fSVladimir Kondratiev 	}
54292646c9fSVladimir Kondratiev 	if (!bcon->assocresp_ies) {
54392646c9fSVladimir Kondratiev 		bcon->assocresp_ies = f->u.probe_resp.variable;
54492646c9fSVladimir Kondratiev 		bcon->assocresp_ies_len = bcon->probe_resp_len - hlen;
54592646c9fSVladimir Kondratiev 		rc = 1;
54692646c9fSVladimir Kondratiev 	}
54792646c9fSVladimir Kondratiev 
54892646c9fSVladimir Kondratiev 	return rc;
54992646c9fSVladimir Kondratiev }
55092646c9fSVladimir Kondratiev 
5512be7d22fSVladimir Kondratiev static int wil_cfg80211_start_ap(struct wiphy *wiphy,
5522be7d22fSVladimir Kondratiev 				 struct net_device *ndev,
5532be7d22fSVladimir Kondratiev 				 struct cfg80211_ap_settings *info)
5542be7d22fSVladimir Kondratiev {
5552be7d22fSVladimir Kondratiev 	int rc = 0;
5562be7d22fSVladimir Kondratiev 	struct wil6210_priv *wil = wiphy_to_wil(wiphy);
5572be7d22fSVladimir Kondratiev 	struct wireless_dev *wdev = ndev->ieee80211_ptr;
5582be7d22fSVladimir Kondratiev 	struct ieee80211_channel *channel = info->chandef.chan;
5592be7d22fSVladimir Kondratiev 	struct cfg80211_beacon_data *bcon = &info->beacon;
5602be7d22fSVladimir Kondratiev 	u8 wmi_nettype = wil_iftype_nl2wmi(wdev->iftype);
5612be7d22fSVladimir Kondratiev 
5622be7d22fSVladimir Kondratiev 	if (!channel) {
5632be7d22fSVladimir Kondratiev 		wil_err(wil, "AP: No channel???\n");
5642be7d22fSVladimir Kondratiev 		return -EINVAL;
5652be7d22fSVladimir Kondratiev 	}
5662be7d22fSVladimir Kondratiev 
5677743882dSVladimir Kondratiev 	wil_dbg_misc(wil, "AP on Channel %d %d MHz, %s\n", channel->hw_value,
5682be7d22fSVladimir Kondratiev 		     channel->center_freq, info->privacy ? "secure" : "open");
5692be7d22fSVladimir Kondratiev 	print_hex_dump_bytes("SSID ", DUMP_PREFIX_OFFSET,
5702be7d22fSVladimir Kondratiev 			     info->ssid, info->ssid_len);
5712be7d22fSVladimir Kondratiev 
57292646c9fSVladimir Kondratiev 	if (wil_fix_bcon(wil, bcon))
57392646c9fSVladimir Kondratiev 		wil_dbg_misc(wil, "Fixed bcon\n");
57492646c9fSVladimir Kondratiev 
5752be7d22fSVladimir Kondratiev 	rc = wil_reset(wil);
5762be7d22fSVladimir Kondratiev 	if (rc)
5772be7d22fSVladimir Kondratiev 		return rc;
5782be7d22fSVladimir Kondratiev 
579e31b2562SVladimir Kondratiev 	/* Rx VRING. */
580e31b2562SVladimir Kondratiev 	rc = wil_rx_init(wil);
581e31b2562SVladimir Kondratiev 	if (rc)
582e31b2562SVladimir Kondratiev 		return rc;
583e31b2562SVladimir Kondratiev 
5842be7d22fSVladimir Kondratiev 	rc = wmi_set_ssid(wil, info->ssid_len, info->ssid);
5852be7d22fSVladimir Kondratiev 	if (rc)
5862be7d22fSVladimir Kondratiev 		return rc;
5872be7d22fSVladimir Kondratiev 
5882be7d22fSVladimir Kondratiev 	/* MAC address - pre-requisite for other commands */
5892be7d22fSVladimir Kondratiev 	wmi_set_mac_address(wil, ndev->dev_addr);
5902be7d22fSVladimir Kondratiev 
5912be7d22fSVladimir Kondratiev 	/* IE's */
5922be7d22fSVladimir Kondratiev 	/* bcon 'head IE's are not relevant for 60g band */
593b1defa4dSVladimir Kondratiev 	/*
594b1defa4dSVladimir Kondratiev 	 * FW do not form regular beacon, so bcon IE's are not set
595b1defa4dSVladimir Kondratiev 	 * For the DMG bcon, when it will be supported, bcon IE's will
596b1defa4dSVladimir Kondratiev 	 * be reused; add something like:
597b1defa4dSVladimir Kondratiev 	 * wmi_set_ie(wil, WMI_FRAME_BEACON, bcon->beacon_ies_len,
598b1defa4dSVladimir Kondratiev 	 * bcon->beacon_ies);
599b1defa4dSVladimir Kondratiev 	 */
6002be7d22fSVladimir Kondratiev 	wmi_set_ie(wil, WMI_FRAME_PROBE_RESP, bcon->proberesp_ies_len,
6012be7d22fSVladimir Kondratiev 		   bcon->proberesp_ies);
6022be7d22fSVladimir Kondratiev 	wmi_set_ie(wil, WMI_FRAME_ASSOC_RESP, bcon->assocresp_ies_len,
6032be7d22fSVladimir Kondratiev 		   bcon->assocresp_ies);
6042be7d22fSVladimir Kondratiev 
6052be7d22fSVladimir Kondratiev 	wil->secure_pcp = info->privacy;
6062be7d22fSVladimir Kondratiev 
607b8023177SVladimir Kondratiev 	rc = wmi_pcp_start(wil, info->beacon_interval, wmi_nettype,
608b8023177SVladimir Kondratiev 			   channel->hw_value);
6092be7d22fSVladimir Kondratiev 	if (rc)
6102be7d22fSVladimir Kondratiev 		return rc;
6112be7d22fSVladimir Kondratiev 
6122be7d22fSVladimir Kondratiev 
6132be7d22fSVladimir Kondratiev 	netif_carrier_on(ndev);
6142be7d22fSVladimir Kondratiev 
6152be7d22fSVladimir Kondratiev 	return rc;
6162be7d22fSVladimir Kondratiev }
6172be7d22fSVladimir Kondratiev 
6182be7d22fSVladimir Kondratiev static int wil_cfg80211_stop_ap(struct wiphy *wiphy,
6192be7d22fSVladimir Kondratiev 				struct net_device *ndev)
6202be7d22fSVladimir Kondratiev {
6212be7d22fSVladimir Kondratiev 	int rc = 0;
6222be7d22fSVladimir Kondratiev 	struct wil6210_priv *wil = wiphy_to_wil(wiphy);
6232be7d22fSVladimir Kondratiev 
624b8023177SVladimir Kondratiev 	rc = wmi_pcp_stop(wil);
6252be7d22fSVladimir Kondratiev 
6262be7d22fSVladimir Kondratiev 	return rc;
6272be7d22fSVladimir Kondratiev }
6282be7d22fSVladimir Kondratiev 
6292be7d22fSVladimir Kondratiev static struct cfg80211_ops wil_cfg80211_ops = {
6302be7d22fSVladimir Kondratiev 	.scan = wil_cfg80211_scan,
6312be7d22fSVladimir Kondratiev 	.connect = wil_cfg80211_connect,
6322be7d22fSVladimir Kondratiev 	.disconnect = wil_cfg80211_disconnect,
6332be7d22fSVladimir Kondratiev 	.change_virtual_intf = wil_cfg80211_change_iface,
6342be7d22fSVladimir Kondratiev 	.get_station = wil_cfg80211_get_station,
635ef28afdbSVladimir Kondratiev 	.dump_station = wil_cfg80211_dump_station,
6361647f12fSVladimir Kondratiev 	.remain_on_channel = wil_remain_on_channel,
6371647f12fSVladimir Kondratiev 	.cancel_remain_on_channel = wil_cancel_remain_on_channel,
6381647f12fSVladimir Kondratiev 	.mgmt_tx = wil_cfg80211_mgmt_tx,
6392be7d22fSVladimir Kondratiev 	.set_monitor_channel = wil_cfg80211_set_channel,
6402be7d22fSVladimir Kondratiev 	.add_key = wil_cfg80211_add_key,
6412be7d22fSVladimir Kondratiev 	.del_key = wil_cfg80211_del_key,
6422be7d22fSVladimir Kondratiev 	.set_default_key = wil_cfg80211_set_default_key,
6432be7d22fSVladimir Kondratiev 	/* AP mode */
6442be7d22fSVladimir Kondratiev 	.start_ap = wil_cfg80211_start_ap,
6452be7d22fSVladimir Kondratiev 	.stop_ap = wil_cfg80211_stop_ap,
6462be7d22fSVladimir Kondratiev };
6472be7d22fSVladimir Kondratiev 
6482be7d22fSVladimir Kondratiev static void wil_wiphy_init(struct wiphy *wiphy)
6492be7d22fSVladimir Kondratiev {
6502be7d22fSVladimir Kondratiev 	/* TODO: set real value */
6512be7d22fSVladimir Kondratiev 	wiphy->max_scan_ssids = 10;
6522be7d22fSVladimir Kondratiev 	wiphy->max_num_pmkids = 0 /* TODO: */;
6532be7d22fSVladimir Kondratiev 	wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
6542be7d22fSVladimir Kondratiev 				 BIT(NL80211_IFTYPE_AP) |
6552be7d22fSVladimir Kondratiev 				 BIT(NL80211_IFTYPE_MONITOR);
6562be7d22fSVladimir Kondratiev 	/* TODO: enable P2P when integrated with supplicant:
6572be7d22fSVladimir Kondratiev 	 * BIT(NL80211_IFTYPE_P2P_CLIENT) | BIT(NL80211_IFTYPE_P2P_GO)
6582be7d22fSVladimir Kondratiev 	 */
6592be7d22fSVladimir Kondratiev 	wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME |
6602be7d22fSVladimir Kondratiev 			WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
6612be7d22fSVladimir Kondratiev 	dev_warn(wiphy_dev(wiphy), "%s : flags = 0x%08x\n",
6622be7d22fSVladimir Kondratiev 		 __func__, wiphy->flags);
6632be7d22fSVladimir Kondratiev 	wiphy->probe_resp_offload =
6642be7d22fSVladimir Kondratiev 		NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
6652be7d22fSVladimir Kondratiev 		NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
6662be7d22fSVladimir Kondratiev 		NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
6672be7d22fSVladimir Kondratiev 
6682be7d22fSVladimir Kondratiev 	wiphy->bands[IEEE80211_BAND_60GHZ] = &wil_band_60ghz;
6692be7d22fSVladimir Kondratiev 
6702be7d22fSVladimir Kondratiev 	/* TODO: figure this out */
6712be7d22fSVladimir Kondratiev 	wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
6722be7d22fSVladimir Kondratiev 
6732be7d22fSVladimir Kondratiev 	wiphy->cipher_suites = wil_cipher_suites;
6742be7d22fSVladimir Kondratiev 	wiphy->n_cipher_suites = ARRAY_SIZE(wil_cipher_suites);
6752be7d22fSVladimir Kondratiev 	wiphy->mgmt_stypes = wil_mgmt_stypes;
6762be7d22fSVladimir Kondratiev }
6772be7d22fSVladimir Kondratiev 
6782be7d22fSVladimir Kondratiev struct wireless_dev *wil_cfg80211_init(struct device *dev)
6792be7d22fSVladimir Kondratiev {
6802be7d22fSVladimir Kondratiev 	int rc = 0;
6812be7d22fSVladimir Kondratiev 	struct wireless_dev *wdev;
6822be7d22fSVladimir Kondratiev 
6832be7d22fSVladimir Kondratiev 	wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
6842be7d22fSVladimir Kondratiev 	if (!wdev)
6852be7d22fSVladimir Kondratiev 		return ERR_PTR(-ENOMEM);
6862be7d22fSVladimir Kondratiev 
6872be7d22fSVladimir Kondratiev 	wdev->wiphy = wiphy_new(&wil_cfg80211_ops,
6882be7d22fSVladimir Kondratiev 				sizeof(struct wil6210_priv));
6892be7d22fSVladimir Kondratiev 	if (!wdev->wiphy) {
6902be7d22fSVladimir Kondratiev 		rc = -ENOMEM;
6912be7d22fSVladimir Kondratiev 		goto out;
6922be7d22fSVladimir Kondratiev 	}
6932be7d22fSVladimir Kondratiev 
6942be7d22fSVladimir Kondratiev 	set_wiphy_dev(wdev->wiphy, dev);
6952be7d22fSVladimir Kondratiev 	wil_wiphy_init(wdev->wiphy);
6962be7d22fSVladimir Kondratiev 
6972be7d22fSVladimir Kondratiev 	rc = wiphy_register(wdev->wiphy);
6982be7d22fSVladimir Kondratiev 	if (rc < 0)
6992be7d22fSVladimir Kondratiev 		goto out_failed_reg;
7002be7d22fSVladimir Kondratiev 
7012be7d22fSVladimir Kondratiev 	return wdev;
7022be7d22fSVladimir Kondratiev 
7032be7d22fSVladimir Kondratiev out_failed_reg:
7042be7d22fSVladimir Kondratiev 	wiphy_free(wdev->wiphy);
7052be7d22fSVladimir Kondratiev out:
7062be7d22fSVladimir Kondratiev 	kfree(wdev);
7072be7d22fSVladimir Kondratiev 
7082be7d22fSVladimir Kondratiev 	return ERR_PTR(rc);
7092be7d22fSVladimir Kondratiev }
7102be7d22fSVladimir Kondratiev 
7112be7d22fSVladimir Kondratiev void wil_wdev_free(struct wil6210_priv *wil)
7122be7d22fSVladimir Kondratiev {
7132be7d22fSVladimir Kondratiev 	struct wireless_dev *wdev = wil_to_wdev(wil);
7142be7d22fSVladimir Kondratiev 
7152be7d22fSVladimir Kondratiev 	if (!wdev)
7162be7d22fSVladimir Kondratiev 		return;
7172be7d22fSVladimir Kondratiev 
7182be7d22fSVladimir Kondratiev 	wiphy_unregister(wdev->wiphy);
7192be7d22fSVladimir Kondratiev 	wiphy_free(wdev->wiphy);
7202be7d22fSVladimir Kondratiev 	kfree(wdev);
7212be7d22fSVladimir Kondratiev }
722