cfg80211.c 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159
  1. /*
  2. * Copyright (c) 2012-2015 Qualcomm Atheros, Inc.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include <linux/etherdevice.h>
  17. #include "wil6210.h"
  18. #include "wmi.h"
  19. #define CHAN60G(_channel, _flags) { \
  20. .band = IEEE80211_BAND_60GHZ, \
  21. .center_freq = 56160 + (2160 * (_channel)), \
  22. .hw_value = (_channel), \
  23. .flags = (_flags), \
  24. .max_antenna_gain = 0, \
  25. .max_power = 40, \
  26. }
  27. static struct ieee80211_channel wil_60ghz_channels[] = {
  28. CHAN60G(1, 0),
  29. CHAN60G(2, 0),
  30. CHAN60G(3, 0),
  31. /* channel 4 not supported yet */
  32. };
  33. static struct ieee80211_supported_band wil_band_60ghz = {
  34. .channels = wil_60ghz_channels,
  35. .n_channels = ARRAY_SIZE(wil_60ghz_channels),
  36. .ht_cap = {
  37. .ht_supported = true,
  38. .cap = 0, /* TODO */
  39. .ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K, /* TODO */
  40. .ampdu_density = IEEE80211_HT_MPDU_DENSITY_8, /* TODO */
  41. .mcs = {
  42. /* MCS 1..12 - SC PHY */
  43. .rx_mask = {0xfe, 0x1f}, /* 1..12 */
  44. .tx_params = IEEE80211_HT_MCS_TX_DEFINED, /* TODO */
  45. },
  46. },
  47. };
  48. static const struct ieee80211_txrx_stypes
  49. wil_mgmt_stypes[NUM_NL80211_IFTYPES] = {
  50. [NL80211_IFTYPE_STATION] = {
  51. .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  52. BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
  53. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  54. BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
  55. },
  56. [NL80211_IFTYPE_AP] = {
  57. .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  58. BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
  59. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  60. BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
  61. },
  62. [NL80211_IFTYPE_P2P_CLIENT] = {
  63. .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  64. BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
  65. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  66. BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
  67. },
  68. [NL80211_IFTYPE_P2P_GO] = {
  69. .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  70. BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
  71. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  72. BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
  73. },
  74. };
  75. static const u32 wil_cipher_suites[] = {
  76. WLAN_CIPHER_SUITE_GCMP,
  77. };
  78. int wil_iftype_nl2wmi(enum nl80211_iftype type)
  79. {
  80. static const struct {
  81. enum nl80211_iftype nl;
  82. enum wmi_network_type wmi;
  83. } __nl2wmi[] = {
  84. {NL80211_IFTYPE_ADHOC, WMI_NETTYPE_ADHOC},
  85. {NL80211_IFTYPE_STATION, WMI_NETTYPE_INFRA},
  86. {NL80211_IFTYPE_AP, WMI_NETTYPE_AP},
  87. {NL80211_IFTYPE_P2P_CLIENT, WMI_NETTYPE_P2P},
  88. {NL80211_IFTYPE_P2P_GO, WMI_NETTYPE_P2P},
  89. {NL80211_IFTYPE_MONITOR, WMI_NETTYPE_ADHOC}, /* FIXME */
  90. };
  91. uint i;
  92. for (i = 0; i < ARRAY_SIZE(__nl2wmi); i++) {
  93. if (__nl2wmi[i].nl == type)
  94. return __nl2wmi[i].wmi;
  95. }
  96. return -EOPNOTSUPP;
  97. }
  98. int wil_cid_fill_sinfo(struct wil6210_priv *wil, int cid,
  99. struct station_info *sinfo)
  100. {
  101. struct wmi_notify_req_cmd cmd = {
  102. .cid = cid,
  103. .interval_usec = 0,
  104. };
  105. struct {
  106. struct wil6210_mbox_hdr_wmi wmi;
  107. struct wmi_notify_req_done_event evt;
  108. } __packed reply;
  109. struct wil_net_stats *stats = &wil->sta[cid].stats;
  110. int rc;
  111. rc = wmi_call(wil, WMI_NOTIFY_REQ_CMDID, &cmd, sizeof(cmd),
  112. WMI_NOTIFY_REQ_DONE_EVENTID, &reply, sizeof(reply), 20);
  113. if (rc)
  114. return rc;
  115. wil_dbg_wmi(wil, "Link status for CID %d: {\n"
  116. " MCS %d TSF 0x%016llx\n"
  117. " BF status 0x%08x SNR 0x%08x SQI %d%%\n"
  118. " Tx Tpt %d goodput %d Rx goodput %d\n"
  119. " Sectors(rx:tx) my %d:%d peer %d:%d\n""}\n",
  120. cid, le16_to_cpu(reply.evt.bf_mcs),
  121. le64_to_cpu(reply.evt.tsf), reply.evt.status,
  122. le32_to_cpu(reply.evt.snr_val),
  123. reply.evt.sqi,
  124. le32_to_cpu(reply.evt.tx_tpt),
  125. le32_to_cpu(reply.evt.tx_goodput),
  126. le32_to_cpu(reply.evt.rx_goodput),
  127. le16_to_cpu(reply.evt.my_rx_sector),
  128. le16_to_cpu(reply.evt.my_tx_sector),
  129. le16_to_cpu(reply.evt.other_rx_sector),
  130. le16_to_cpu(reply.evt.other_tx_sector));
  131. sinfo->generation = wil->sinfo_gen;
  132. sinfo->filled = BIT(NL80211_STA_INFO_RX_BYTES) |
  133. BIT(NL80211_STA_INFO_TX_BYTES) |
  134. BIT(NL80211_STA_INFO_RX_PACKETS) |
  135. BIT(NL80211_STA_INFO_TX_PACKETS) |
  136. BIT(NL80211_STA_INFO_RX_BITRATE) |
  137. BIT(NL80211_STA_INFO_TX_BITRATE) |
  138. BIT(NL80211_STA_INFO_RX_DROP_MISC) |
  139. BIT(NL80211_STA_INFO_TX_FAILED);
  140. sinfo->txrate.flags = RATE_INFO_FLAGS_MCS | RATE_INFO_FLAGS_60G;
  141. sinfo->txrate.mcs = le16_to_cpu(reply.evt.bf_mcs);
  142. sinfo->rxrate.flags = RATE_INFO_FLAGS_MCS | RATE_INFO_FLAGS_60G;
  143. sinfo->rxrate.mcs = stats->last_mcs_rx;
  144. sinfo->rx_bytes = stats->rx_bytes;
  145. sinfo->rx_packets = stats->rx_packets;
  146. sinfo->rx_dropped_misc = stats->rx_dropped;
  147. sinfo->tx_bytes = stats->tx_bytes;
  148. sinfo->tx_packets = stats->tx_packets;
  149. sinfo->tx_failed = stats->tx_errors;
  150. if (test_bit(wil_status_fwconnected, wil->status)) {
  151. sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL);
  152. sinfo->signal = reply.evt.sqi;
  153. }
  154. return rc;
  155. }
  156. static int wil_cfg80211_get_station(struct wiphy *wiphy,
  157. struct net_device *ndev,
  158. const u8 *mac, struct station_info *sinfo)
  159. {
  160. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  161. int rc;
  162. int cid = wil_find_cid(wil, mac);
  163. wil_dbg_misc(wil, "%s(%pM) CID %d\n", __func__, mac, cid);
  164. if (cid < 0)
  165. return cid;
  166. rc = wil_cid_fill_sinfo(wil, cid, sinfo);
  167. return rc;
  168. }
  169. /*
  170. * Find @idx-th active STA for station dump.
  171. */
  172. static int wil_find_cid_by_idx(struct wil6210_priv *wil, int idx)
  173. {
  174. int i;
  175. for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
  176. if (wil->sta[i].status == wil_sta_unused)
  177. continue;
  178. if (idx == 0)
  179. return i;
  180. idx--;
  181. }
  182. return -ENOENT;
  183. }
  184. static int wil_cfg80211_dump_station(struct wiphy *wiphy,
  185. struct net_device *dev, int idx,
  186. u8 *mac, struct station_info *sinfo)
  187. {
  188. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  189. int rc;
  190. int cid = wil_find_cid_by_idx(wil, idx);
  191. if (cid < 0)
  192. return -ENOENT;
  193. ether_addr_copy(mac, wil->sta[cid].addr);
  194. wil_dbg_misc(wil, "%s(%pM) CID %d\n", __func__, mac, cid);
  195. rc = wil_cid_fill_sinfo(wil, cid, sinfo);
  196. return rc;
  197. }
  198. static int wil_cfg80211_change_iface(struct wiphy *wiphy,
  199. struct net_device *ndev,
  200. enum nl80211_iftype type, u32 *flags,
  201. struct vif_params *params)
  202. {
  203. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  204. struct wireless_dev *wdev = wil->wdev;
  205. switch (type) {
  206. case NL80211_IFTYPE_STATION:
  207. case NL80211_IFTYPE_AP:
  208. case NL80211_IFTYPE_P2P_CLIENT:
  209. case NL80211_IFTYPE_P2P_GO:
  210. break;
  211. case NL80211_IFTYPE_MONITOR:
  212. if (flags)
  213. wil->monitor_flags = *flags;
  214. else
  215. wil->monitor_flags = 0;
  216. break;
  217. default:
  218. return -EOPNOTSUPP;
  219. }
  220. wdev->iftype = type;
  221. return 0;
  222. }
  223. static int wil_cfg80211_scan(struct wiphy *wiphy,
  224. struct cfg80211_scan_request *request)
  225. {
  226. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  227. struct wireless_dev *wdev = wil->wdev;
  228. struct {
  229. struct wmi_start_scan_cmd cmd;
  230. u16 chnl[4];
  231. } __packed cmd;
  232. uint i, n;
  233. int rc;
  234. if (wil->scan_request) {
  235. wil_err(wil, "Already scanning\n");
  236. return -EAGAIN;
  237. }
  238. /* check we are client side */
  239. switch (wdev->iftype) {
  240. case NL80211_IFTYPE_STATION:
  241. case NL80211_IFTYPE_P2P_CLIENT:
  242. break;
  243. default:
  244. return -EOPNOTSUPP;
  245. }
  246. /* FW don't support scan after connection attempt */
  247. if (test_bit(wil_status_dontscan, wil->status)) {
  248. wil_err(wil, "Can't scan now\n");
  249. return -EBUSY;
  250. }
  251. wil_dbg_misc(wil, "Start scan_request 0x%p\n", request);
  252. wil_dbg_misc(wil, "SSID count: %d", request->n_ssids);
  253. for (i = 0; i < request->n_ssids; i++) {
  254. wil_dbg_misc(wil, "SSID[%d]", i);
  255. print_hex_dump_bytes("SSID ", DUMP_PREFIX_OFFSET,
  256. request->ssids[i].ssid,
  257. request->ssids[i].ssid_len);
  258. }
  259. if (request->n_ssids)
  260. rc = wmi_set_ssid(wil, request->ssids[0].ssid_len,
  261. request->ssids[0].ssid);
  262. else
  263. rc = wmi_set_ssid(wil, 0, NULL);
  264. if (rc) {
  265. wil_err(wil, "set SSID for scan request failed: %d\n", rc);
  266. return rc;
  267. }
  268. wil->scan_request = request;
  269. mod_timer(&wil->scan_timer, jiffies + WIL6210_SCAN_TO);
  270. memset(&cmd, 0, sizeof(cmd));
  271. cmd.cmd.num_channels = 0;
  272. n = min(request->n_channels, 4U);
  273. for (i = 0; i < n; i++) {
  274. int ch = request->channels[i]->hw_value;
  275. if (ch == 0) {
  276. wil_err(wil,
  277. "Scan requested for unknown frequency %dMhz\n",
  278. request->channels[i]->center_freq);
  279. continue;
  280. }
  281. /* 0-based channel indexes */
  282. cmd.cmd.channel_list[cmd.cmd.num_channels++].channel = ch - 1;
  283. wil_dbg_misc(wil, "Scan for ch %d : %d MHz\n", ch,
  284. request->channels[i]->center_freq);
  285. }
  286. if (request->ie_len)
  287. print_hex_dump_bytes("Scan IE ", DUMP_PREFIX_OFFSET,
  288. request->ie, request->ie_len);
  289. else
  290. wil_dbg_misc(wil, "Scan has no IE's\n");
  291. rc = wmi_set_ie(wil, WMI_FRAME_PROBE_REQ, request->ie_len, request->ie);
  292. if (rc)
  293. goto out;
  294. rc = wmi_send(wil, WMI_START_SCAN_CMDID, &cmd, sizeof(cmd.cmd) +
  295. cmd.cmd.num_channels * sizeof(cmd.cmd.channel_list[0]));
  296. out:
  297. if (rc) {
  298. del_timer_sync(&wil->scan_timer);
  299. wil->scan_request = NULL;
  300. }
  301. return rc;
  302. }
  303. static void wil_print_crypto(struct wil6210_priv *wil,
  304. struct cfg80211_crypto_settings *c)
  305. {
  306. int i, n;
  307. wil_dbg_misc(wil, "WPA versions: 0x%08x cipher group 0x%08x\n",
  308. c->wpa_versions, c->cipher_group);
  309. wil_dbg_misc(wil, "Pairwise ciphers [%d] {\n", c->n_ciphers_pairwise);
  310. n = min_t(int, c->n_ciphers_pairwise, ARRAY_SIZE(c->ciphers_pairwise));
  311. for (i = 0; i < n; i++)
  312. wil_dbg_misc(wil, " [%d] = 0x%08x\n", i,
  313. c->ciphers_pairwise[i]);
  314. wil_dbg_misc(wil, "}\n");
  315. wil_dbg_misc(wil, "AKM suites [%d] {\n", c->n_akm_suites);
  316. n = min_t(int, c->n_akm_suites, ARRAY_SIZE(c->akm_suites));
  317. for (i = 0; i < n; i++)
  318. wil_dbg_misc(wil, " [%d] = 0x%08x\n", i,
  319. c->akm_suites[i]);
  320. wil_dbg_misc(wil, "}\n");
  321. wil_dbg_misc(wil, "Control port : %d, eth_type 0x%04x no_encrypt %d\n",
  322. c->control_port, be16_to_cpu(c->control_port_ethertype),
  323. c->control_port_no_encrypt);
  324. }
  325. static void wil_print_connect_params(struct wil6210_priv *wil,
  326. struct cfg80211_connect_params *sme)
  327. {
  328. wil_info(wil, "Connecting to:\n");
  329. if (sme->channel) {
  330. wil_info(wil, " Channel: %d freq %d\n",
  331. sme->channel->hw_value, sme->channel->center_freq);
  332. }
  333. if (sme->bssid)
  334. wil_info(wil, " BSSID: %pM\n", sme->bssid);
  335. if (sme->ssid)
  336. print_hex_dump(KERN_INFO, " SSID: ", DUMP_PREFIX_OFFSET,
  337. 16, 1, sme->ssid, sme->ssid_len, true);
  338. wil_info(wil, " Privacy: %s\n", sme->privacy ? "secure" : "open");
  339. wil_print_crypto(wil, &sme->crypto);
  340. }
  341. static int wil_cfg80211_connect(struct wiphy *wiphy,
  342. struct net_device *ndev,
  343. struct cfg80211_connect_params *sme)
  344. {
  345. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  346. struct cfg80211_bss *bss;
  347. struct wmi_connect_cmd conn;
  348. const u8 *ssid_eid;
  349. const u8 *rsn_eid;
  350. int ch;
  351. int rc = 0;
  352. wil_print_connect_params(wil, sme);
  353. if (test_bit(wil_status_fwconnecting, wil->status) ||
  354. test_bit(wil_status_fwconnected, wil->status))
  355. return -EALREADY;
  356. if (sme->ie_len > WMI_MAX_IE_LEN) {
  357. wil_err(wil, "IE too large (%td bytes)\n", sme->ie_len);
  358. return -ERANGE;
  359. }
  360. rsn_eid = sme->ie ?
  361. cfg80211_find_ie(WLAN_EID_RSN, sme->ie, sme->ie_len) :
  362. NULL;
  363. if (sme->privacy && !rsn_eid)
  364. wil_info(wil, "WSC connection\n");
  365. bss = cfg80211_get_bss(wiphy, sme->channel, sme->bssid,
  366. sme->ssid, sme->ssid_len,
  367. IEEE80211_BSS_TYPE_ESS, IEEE80211_PRIVACY_ANY);
  368. if (!bss) {
  369. wil_err(wil, "Unable to find BSS\n");
  370. return -ENOENT;
  371. }
  372. ssid_eid = ieee80211_bss_get_ie(bss, WLAN_EID_SSID);
  373. if (!ssid_eid) {
  374. wil_err(wil, "No SSID\n");
  375. rc = -ENOENT;
  376. goto out;
  377. }
  378. wil->privacy = sme->privacy;
  379. if (wil->privacy) {
  380. /* For secure assoc, remove old keys */
  381. rc = wmi_del_cipher_key(wil, 0, bss->bssid,
  382. WMI_KEY_USE_PAIRWISE);
  383. if (rc) {
  384. wil_err(wil, "WMI_DELETE_CIPHER_KEY_CMD(PTK) failed\n");
  385. goto out;
  386. }
  387. rc = wmi_del_cipher_key(wil, 0, bss->bssid,
  388. WMI_KEY_USE_RX_GROUP);
  389. if (rc) {
  390. wil_err(wil, "WMI_DELETE_CIPHER_KEY_CMD(GTK) failed\n");
  391. goto out;
  392. }
  393. }
  394. /* WMI_SET_APPIE_CMD. ie may contain rsn info as well as other info
  395. * elements. Send it also in case it's empty, to erase previously set
  396. * ies in FW.
  397. */
  398. rc = wmi_set_ie(wil, WMI_FRAME_ASSOC_REQ, sme->ie_len, sme->ie);
  399. if (rc)
  400. goto out;
  401. /* WMI_CONNECT_CMD */
  402. memset(&conn, 0, sizeof(conn));
  403. switch (bss->capability & WLAN_CAPABILITY_DMG_TYPE_MASK) {
  404. case WLAN_CAPABILITY_DMG_TYPE_AP:
  405. conn.network_type = WMI_NETTYPE_INFRA;
  406. break;
  407. case WLAN_CAPABILITY_DMG_TYPE_PBSS:
  408. conn.network_type = WMI_NETTYPE_P2P;
  409. break;
  410. default:
  411. wil_err(wil, "Unsupported BSS type, capability= 0x%04x\n",
  412. bss->capability);
  413. goto out;
  414. }
  415. if (wil->privacy) {
  416. if (rsn_eid) { /* regular secure connection */
  417. conn.dot11_auth_mode = WMI_AUTH11_SHARED;
  418. conn.auth_mode = WMI_AUTH_WPA2_PSK;
  419. conn.pairwise_crypto_type = WMI_CRYPT_AES_GCMP;
  420. conn.pairwise_crypto_len = 16;
  421. conn.group_crypto_type = WMI_CRYPT_AES_GCMP;
  422. conn.group_crypto_len = 16;
  423. } else { /* WSC */
  424. conn.dot11_auth_mode = WMI_AUTH11_WSC;
  425. conn.auth_mode = WMI_AUTH_NONE;
  426. }
  427. } else { /* insecure connection */
  428. conn.dot11_auth_mode = WMI_AUTH11_OPEN;
  429. conn.auth_mode = WMI_AUTH_NONE;
  430. }
  431. conn.ssid_len = min_t(u8, ssid_eid[1], 32);
  432. memcpy(conn.ssid, ssid_eid+2, conn.ssid_len);
  433. ch = bss->channel->hw_value;
  434. if (ch == 0) {
  435. wil_err(wil, "BSS at unknown frequency %dMhz\n",
  436. bss->channel->center_freq);
  437. rc = -EOPNOTSUPP;
  438. goto out;
  439. }
  440. conn.channel = ch - 1;
  441. ether_addr_copy(conn.bssid, bss->bssid);
  442. ether_addr_copy(conn.dst_mac, bss->bssid);
  443. set_bit(wil_status_fwconnecting, wil->status);
  444. rc = wmi_send(wil, WMI_CONNECT_CMDID, &conn, sizeof(conn));
  445. if (rc == 0) {
  446. netif_carrier_on(ndev);
  447. /* Connect can take lots of time */
  448. mod_timer(&wil->connect_timer,
  449. jiffies + msecs_to_jiffies(2000));
  450. } else {
  451. clear_bit(wil_status_fwconnecting, wil->status);
  452. }
  453. out:
  454. cfg80211_put_bss(wiphy, bss);
  455. return rc;
  456. }
  457. static int wil_cfg80211_disconnect(struct wiphy *wiphy,
  458. struct net_device *ndev,
  459. u16 reason_code)
  460. {
  461. int rc;
  462. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  463. wil_dbg_misc(wil, "%s(reason=%d)\n", __func__, reason_code);
  464. rc = wmi_send(wil, WMI_DISCONNECT_CMDID, NULL, 0);
  465. return rc;
  466. }
  467. int wil_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
  468. struct cfg80211_mgmt_tx_params *params,
  469. u64 *cookie)
  470. {
  471. const u8 *buf = params->buf;
  472. size_t len = params->len;
  473. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  474. int rc;
  475. bool tx_status = false;
  476. struct ieee80211_mgmt *mgmt_frame = (void *)buf;
  477. struct wmi_sw_tx_req_cmd *cmd;
  478. struct {
  479. struct wil6210_mbox_hdr_wmi wmi;
  480. struct wmi_sw_tx_complete_event evt;
  481. } __packed evt;
  482. cmd = kmalloc(sizeof(*cmd) + len, GFP_KERNEL);
  483. if (!cmd) {
  484. rc = -ENOMEM;
  485. goto out;
  486. }
  487. memcpy(cmd->dst_mac, mgmt_frame->da, WMI_MAC_LEN);
  488. cmd->len = cpu_to_le16(len);
  489. memcpy(cmd->payload, buf, len);
  490. rc = wmi_call(wil, WMI_SW_TX_REQ_CMDID, cmd, sizeof(*cmd) + len,
  491. WMI_SW_TX_COMPLETE_EVENTID, &evt, sizeof(evt), 2000);
  492. if (rc == 0)
  493. tx_status = !evt.evt.status;
  494. kfree(cmd);
  495. out:
  496. cfg80211_mgmt_tx_status(wdev, cookie ? *cookie : 0, buf, len,
  497. tx_status, GFP_KERNEL);
  498. return rc;
  499. }
  500. static int wil_cfg80211_set_channel(struct wiphy *wiphy,
  501. struct cfg80211_chan_def *chandef)
  502. {
  503. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  504. struct wireless_dev *wdev = wil->wdev;
  505. wdev->preset_chandef = *chandef;
  506. return 0;
  507. }
  508. static enum wmi_key_usage wil_detect_key_usage(struct wil6210_priv *wil,
  509. bool pairwise)
  510. {
  511. struct wireless_dev *wdev = wil->wdev;
  512. enum wmi_key_usage rc;
  513. static const char * const key_usage_str[] = {
  514. [WMI_KEY_USE_PAIRWISE] = "WMI_KEY_USE_PAIRWISE",
  515. [WMI_KEY_USE_RX_GROUP] = "WMI_KEY_USE_RX_GROUP",
  516. [WMI_KEY_USE_TX_GROUP] = "WMI_KEY_USE_TX_GROUP",
  517. };
  518. if (pairwise) {
  519. rc = WMI_KEY_USE_PAIRWISE;
  520. } else {
  521. switch (wdev->iftype) {
  522. case NL80211_IFTYPE_STATION:
  523. rc = WMI_KEY_USE_RX_GROUP;
  524. break;
  525. case NL80211_IFTYPE_AP:
  526. rc = WMI_KEY_USE_TX_GROUP;
  527. break;
  528. default:
  529. /* TODO: Rx GTK or Tx GTK? */
  530. wil_err(wil, "Can't determine GTK type\n");
  531. rc = WMI_KEY_USE_RX_GROUP;
  532. break;
  533. }
  534. }
  535. wil_dbg_misc(wil, "%s() -> %s\n", __func__, key_usage_str[rc]);
  536. return rc;
  537. }
  538. static int wil_cfg80211_add_key(struct wiphy *wiphy,
  539. struct net_device *ndev,
  540. u8 key_index, bool pairwise,
  541. const u8 *mac_addr,
  542. struct key_params *params)
  543. {
  544. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  545. enum wmi_key_usage key_usage = wil_detect_key_usage(wil, pairwise);
  546. wil_dbg_misc(wil, "%s(%pM[%d] %s)\n", __func__, mac_addr, key_index,
  547. pairwise ? "PTK" : "GTK");
  548. return wmi_add_cipher_key(wil, key_index, mac_addr, params->key_len,
  549. params->key, key_usage);
  550. }
  551. static int wil_cfg80211_del_key(struct wiphy *wiphy,
  552. struct net_device *ndev,
  553. u8 key_index, bool pairwise,
  554. const u8 *mac_addr)
  555. {
  556. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  557. enum wmi_key_usage key_usage = wil_detect_key_usage(wil, pairwise);
  558. wil_dbg_misc(wil, "%s(%pM[%d] %s)\n", __func__, mac_addr, key_index,
  559. pairwise ? "PTK" : "GTK");
  560. return wmi_del_cipher_key(wil, key_index, mac_addr, key_usage);
  561. }
  562. /* Need to be present or wiphy_new() will WARN */
  563. static int wil_cfg80211_set_default_key(struct wiphy *wiphy,
  564. struct net_device *ndev,
  565. u8 key_index, bool unicast,
  566. bool multicast)
  567. {
  568. return 0;
  569. }
  570. static int wil_remain_on_channel(struct wiphy *wiphy,
  571. struct wireless_dev *wdev,
  572. struct ieee80211_channel *chan,
  573. unsigned int duration,
  574. u64 *cookie)
  575. {
  576. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  577. int rc;
  578. /* TODO: handle duration */
  579. wil_info(wil, "%s(%d, %d ms)\n", __func__, chan->center_freq, duration);
  580. rc = wmi_set_channel(wil, chan->hw_value);
  581. if (rc)
  582. return rc;
  583. rc = wmi_rxon(wil, true);
  584. return rc;
  585. }
  586. static int wil_cancel_remain_on_channel(struct wiphy *wiphy,
  587. struct wireless_dev *wdev,
  588. u64 cookie)
  589. {
  590. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  591. int rc;
  592. wil_info(wil, "%s()\n", __func__);
  593. rc = wmi_rxon(wil, false);
  594. return rc;
  595. }
  596. static void wil_print_bcon_data(struct cfg80211_beacon_data *b)
  597. {
  598. print_hex_dump_bytes("head ", DUMP_PREFIX_OFFSET,
  599. b->head, b->head_len);
  600. print_hex_dump_bytes("tail ", DUMP_PREFIX_OFFSET,
  601. b->tail, b->tail_len);
  602. print_hex_dump_bytes("BCON IE ", DUMP_PREFIX_OFFSET,
  603. b->beacon_ies, b->beacon_ies_len);
  604. print_hex_dump_bytes("PROBE ", DUMP_PREFIX_OFFSET,
  605. b->probe_resp, b->probe_resp_len);
  606. print_hex_dump_bytes("PROBE IE ", DUMP_PREFIX_OFFSET,
  607. b->proberesp_ies, b->proberesp_ies_len);
  608. print_hex_dump_bytes("ASSOC IE ", DUMP_PREFIX_OFFSET,
  609. b->assocresp_ies, b->assocresp_ies_len);
  610. }
  611. static int wil_fix_bcon(struct wil6210_priv *wil,
  612. struct cfg80211_beacon_data *bcon)
  613. {
  614. struct ieee80211_mgmt *f = (struct ieee80211_mgmt *)bcon->probe_resp;
  615. size_t hlen = offsetof(struct ieee80211_mgmt, u.probe_resp.variable);
  616. if (bcon->probe_resp_len <= hlen)
  617. return 0;
  618. /* always use IE's from full probe frame, they has more info
  619. * notable RSN
  620. */
  621. bcon->proberesp_ies = f->u.probe_resp.variable;
  622. bcon->proberesp_ies_len = bcon->probe_resp_len - hlen;
  623. if (!bcon->assocresp_ies) {
  624. bcon->assocresp_ies = bcon->proberesp_ies;
  625. bcon->assocresp_ies_len = bcon->proberesp_ies_len;
  626. }
  627. return 1;
  628. }
  629. /* internal functions for device reset and starting AP */
  630. static int _wil_cfg80211_set_ies(struct wiphy *wiphy,
  631. struct cfg80211_beacon_data *bcon)
  632. {
  633. int rc;
  634. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  635. rc = wmi_set_ie(wil, WMI_FRAME_PROBE_RESP, bcon->proberesp_ies_len,
  636. bcon->proberesp_ies);
  637. if (rc)
  638. return rc;
  639. rc = wmi_set_ie(wil, WMI_FRAME_ASSOC_RESP, bcon->assocresp_ies_len,
  640. bcon->assocresp_ies);
  641. #if 0 /* to use beacon IE's, remove this #if 0 */
  642. if (rc)
  643. return rc;
  644. rc = wmi_set_ie(wil, WMI_FRAME_BEACON, bcon->tail_len, bcon->tail);
  645. #endif
  646. return rc;
  647. }
  648. static int _wil_cfg80211_start_ap(struct wiphy *wiphy,
  649. struct net_device *ndev,
  650. const u8 *ssid, size_t ssid_len, u32 privacy,
  651. int bi, u8 chan,
  652. struct cfg80211_beacon_data *bcon,
  653. u8 hidden_ssid)
  654. {
  655. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  656. int rc;
  657. struct wireless_dev *wdev = ndev->ieee80211_ptr;
  658. u8 wmi_nettype = wil_iftype_nl2wmi(wdev->iftype);
  659. wil_set_recovery_state(wil, fw_recovery_idle);
  660. mutex_lock(&wil->mutex);
  661. __wil_down(wil);
  662. rc = __wil_up(wil);
  663. if (rc)
  664. goto out;
  665. rc = wmi_set_ssid(wil, ssid_len, ssid);
  666. if (rc)
  667. goto out;
  668. rc = _wil_cfg80211_set_ies(wiphy, bcon);
  669. if (rc)
  670. goto out;
  671. wil->privacy = privacy;
  672. wil->channel = chan;
  673. wil->hidden_ssid = hidden_ssid;
  674. netif_carrier_on(ndev);
  675. rc = wmi_pcp_start(wil, bi, wmi_nettype, chan, hidden_ssid);
  676. if (rc)
  677. goto err_pcp_start;
  678. rc = wil_bcast_init(wil);
  679. if (rc)
  680. goto err_bcast;
  681. goto out; /* success */
  682. err_bcast:
  683. wmi_pcp_stop(wil);
  684. err_pcp_start:
  685. netif_carrier_off(ndev);
  686. out:
  687. mutex_unlock(&wil->mutex);
  688. return rc;
  689. }
  690. static int wil_cfg80211_change_beacon(struct wiphy *wiphy,
  691. struct net_device *ndev,
  692. struct cfg80211_beacon_data *bcon)
  693. {
  694. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  695. int rc;
  696. u32 privacy = 0;
  697. wil_dbg_misc(wil, "%s()\n", __func__);
  698. wil_print_bcon_data(bcon);
  699. if (wil_fix_bcon(wil, bcon)) {
  700. wil_dbg_misc(wil, "Fixed bcon\n");
  701. wil_print_bcon_data(bcon);
  702. }
  703. if (bcon->proberesp_ies &&
  704. cfg80211_find_ie(WLAN_EID_RSN, bcon->proberesp_ies,
  705. bcon->proberesp_ies_len))
  706. privacy = 1;
  707. /* in case privacy has changed, need to restart the AP */
  708. if (wil->privacy != privacy) {
  709. struct wireless_dev *wdev = ndev->ieee80211_ptr;
  710. wil_dbg_misc(wil, "privacy changed %d=>%d. Restarting AP\n",
  711. wil->privacy, privacy);
  712. rc = _wil_cfg80211_start_ap(wiphy, ndev, wdev->ssid,
  713. wdev->ssid_len, privacy,
  714. wdev->beacon_interval,
  715. wil->channel, bcon,
  716. wil->hidden_ssid);
  717. } else {
  718. rc = _wil_cfg80211_set_ies(wiphy, bcon);
  719. }
  720. return rc;
  721. }
  722. static int wil_cfg80211_start_ap(struct wiphy *wiphy,
  723. struct net_device *ndev,
  724. struct cfg80211_ap_settings *info)
  725. {
  726. int rc;
  727. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  728. struct ieee80211_channel *channel = info->chandef.chan;
  729. struct cfg80211_beacon_data *bcon = &info->beacon;
  730. struct cfg80211_crypto_settings *crypto = &info->crypto;
  731. u8 hidden_ssid;
  732. wil_dbg_misc(wil, "%s()\n", __func__);
  733. if (!channel) {
  734. wil_err(wil, "AP: No channel???\n");
  735. return -EINVAL;
  736. }
  737. switch (info->hidden_ssid) {
  738. case NL80211_HIDDEN_SSID_NOT_IN_USE:
  739. hidden_ssid = WMI_HIDDEN_SSID_DISABLED;
  740. break;
  741. case NL80211_HIDDEN_SSID_ZERO_LEN:
  742. hidden_ssid = WMI_HIDDEN_SSID_SEND_EMPTY;
  743. break;
  744. case NL80211_HIDDEN_SSID_ZERO_CONTENTS:
  745. hidden_ssid = WMI_HIDDEN_SSID_CLEAR;
  746. break;
  747. default:
  748. wil_err(wil, "AP: Invalid hidden SSID %d\n", info->hidden_ssid);
  749. return -EOPNOTSUPP;
  750. }
  751. wil_dbg_misc(wil, "AP on Channel %d %d MHz, %s\n", channel->hw_value,
  752. channel->center_freq, info->privacy ? "secure" : "open");
  753. wil_dbg_misc(wil, "Privacy: %d auth_type %d\n",
  754. info->privacy, info->auth_type);
  755. wil_dbg_misc(wil, "Hidden SSID mode: %d\n",
  756. info->hidden_ssid);
  757. wil_dbg_misc(wil, "BI %d DTIM %d\n", info->beacon_interval,
  758. info->dtim_period);
  759. print_hex_dump_bytes("SSID ", DUMP_PREFIX_OFFSET,
  760. info->ssid, info->ssid_len);
  761. wil_print_bcon_data(bcon);
  762. wil_print_crypto(wil, crypto);
  763. if (wil_fix_bcon(wil, bcon)) {
  764. wil_dbg_misc(wil, "Fixed bcon\n");
  765. wil_print_bcon_data(bcon);
  766. }
  767. rc = _wil_cfg80211_start_ap(wiphy, ndev,
  768. info->ssid, info->ssid_len, info->privacy,
  769. info->beacon_interval, channel->hw_value,
  770. bcon, hidden_ssid);
  771. return rc;
  772. }
  773. static int wil_cfg80211_stop_ap(struct wiphy *wiphy,
  774. struct net_device *ndev)
  775. {
  776. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  777. wil_dbg_misc(wil, "%s()\n", __func__);
  778. netif_carrier_off(ndev);
  779. wil_set_recovery_state(wil, fw_recovery_idle);
  780. mutex_lock(&wil->mutex);
  781. wmi_pcp_stop(wil);
  782. __wil_down(wil);
  783. mutex_unlock(&wil->mutex);
  784. return 0;
  785. }
  786. static int wil_cfg80211_del_station(struct wiphy *wiphy,
  787. struct net_device *dev,
  788. struct station_del_parameters *params)
  789. {
  790. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  791. wil_dbg_misc(wil, "%s(%pM, reason=%d)\n", __func__, params->mac,
  792. params->reason_code);
  793. mutex_lock(&wil->mutex);
  794. wil6210_disconnect(wil, params->mac, params->reason_code, false);
  795. mutex_unlock(&wil->mutex);
  796. return 0;
  797. }
  798. /* probe_client handling */
  799. static void wil_probe_client_handle(struct wil6210_priv *wil,
  800. struct wil_probe_client_req *req)
  801. {
  802. struct net_device *ndev = wil_to_ndev(wil);
  803. struct wil_sta_info *sta = &wil->sta[req->cid];
  804. /* assume STA is alive if it is still connected,
  805. * else FW will disconnect it
  806. */
  807. bool alive = (sta->status == wil_sta_connected);
  808. cfg80211_probe_status(ndev, sta->addr, req->cookie, alive, GFP_KERNEL);
  809. }
  810. static struct list_head *next_probe_client(struct wil6210_priv *wil)
  811. {
  812. struct list_head *ret = NULL;
  813. mutex_lock(&wil->probe_client_mutex);
  814. if (!list_empty(&wil->probe_client_pending)) {
  815. ret = wil->probe_client_pending.next;
  816. list_del(ret);
  817. }
  818. mutex_unlock(&wil->probe_client_mutex);
  819. return ret;
  820. }
  821. void wil_probe_client_worker(struct work_struct *work)
  822. {
  823. struct wil6210_priv *wil = container_of(work, struct wil6210_priv,
  824. probe_client_worker);
  825. struct wil_probe_client_req *req;
  826. struct list_head *lh;
  827. while ((lh = next_probe_client(wil)) != NULL) {
  828. req = list_entry(lh, struct wil_probe_client_req, list);
  829. wil_probe_client_handle(wil, req);
  830. kfree(req);
  831. }
  832. }
  833. void wil_probe_client_flush(struct wil6210_priv *wil)
  834. {
  835. struct wil_probe_client_req *req, *t;
  836. wil_dbg_misc(wil, "%s()\n", __func__);
  837. mutex_lock(&wil->probe_client_mutex);
  838. list_for_each_entry_safe(req, t, &wil->probe_client_pending, list) {
  839. list_del(&req->list);
  840. kfree(req);
  841. }
  842. mutex_unlock(&wil->probe_client_mutex);
  843. }
  844. static int wil_cfg80211_probe_client(struct wiphy *wiphy,
  845. struct net_device *dev,
  846. const u8 *peer, u64 *cookie)
  847. {
  848. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  849. struct wil_probe_client_req *req;
  850. int cid = wil_find_cid(wil, peer);
  851. wil_dbg_misc(wil, "%s(%pM => CID %d)\n", __func__, peer, cid);
  852. if (cid < 0)
  853. return -ENOLINK;
  854. req = kzalloc(sizeof(*req), GFP_KERNEL);
  855. if (!req)
  856. return -ENOMEM;
  857. req->cid = cid;
  858. req->cookie = cid;
  859. mutex_lock(&wil->probe_client_mutex);
  860. list_add_tail(&req->list, &wil->probe_client_pending);
  861. mutex_unlock(&wil->probe_client_mutex);
  862. *cookie = req->cookie;
  863. queue_work(wil->wq_service, &wil->probe_client_worker);
  864. return 0;
  865. }
  866. static int wil_cfg80211_change_bss(struct wiphy *wiphy,
  867. struct net_device *dev,
  868. struct bss_parameters *params)
  869. {
  870. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  871. if (params->ap_isolate >= 0) {
  872. wil_dbg_misc(wil, "%s(ap_isolate %d => %d)\n", __func__,
  873. wil->ap_isolate, params->ap_isolate);
  874. wil->ap_isolate = params->ap_isolate;
  875. }
  876. return 0;
  877. }
  878. static struct cfg80211_ops wil_cfg80211_ops = {
  879. .scan = wil_cfg80211_scan,
  880. .connect = wil_cfg80211_connect,
  881. .disconnect = wil_cfg80211_disconnect,
  882. .change_virtual_intf = wil_cfg80211_change_iface,
  883. .get_station = wil_cfg80211_get_station,
  884. .dump_station = wil_cfg80211_dump_station,
  885. .remain_on_channel = wil_remain_on_channel,
  886. .cancel_remain_on_channel = wil_cancel_remain_on_channel,
  887. .mgmt_tx = wil_cfg80211_mgmt_tx,
  888. .set_monitor_channel = wil_cfg80211_set_channel,
  889. .add_key = wil_cfg80211_add_key,
  890. .del_key = wil_cfg80211_del_key,
  891. .set_default_key = wil_cfg80211_set_default_key,
  892. /* AP mode */
  893. .change_beacon = wil_cfg80211_change_beacon,
  894. .start_ap = wil_cfg80211_start_ap,
  895. .stop_ap = wil_cfg80211_stop_ap,
  896. .del_station = wil_cfg80211_del_station,
  897. .probe_client = wil_cfg80211_probe_client,
  898. .change_bss = wil_cfg80211_change_bss,
  899. };
  900. static void wil_wiphy_init(struct wiphy *wiphy)
  901. {
  902. wiphy->max_scan_ssids = 1;
  903. wiphy->max_scan_ie_len = WMI_MAX_IE_LEN;
  904. wiphy->max_num_pmkids = 0 /* TODO: */;
  905. wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
  906. BIT(NL80211_IFTYPE_AP) |
  907. BIT(NL80211_IFTYPE_MONITOR);
  908. /* TODO: enable P2P when integrated with supplicant:
  909. * BIT(NL80211_IFTYPE_P2P_CLIENT) | BIT(NL80211_IFTYPE_P2P_GO)
  910. */
  911. wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME |
  912. WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
  913. dev_dbg(wiphy_dev(wiphy), "%s : flags = 0x%08x\n",
  914. __func__, wiphy->flags);
  915. wiphy->probe_resp_offload =
  916. NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
  917. NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
  918. NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
  919. wiphy->bands[IEEE80211_BAND_60GHZ] = &wil_band_60ghz;
  920. /* TODO: figure this out */
  921. wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC;
  922. wiphy->cipher_suites = wil_cipher_suites;
  923. wiphy->n_cipher_suites = ARRAY_SIZE(wil_cipher_suites);
  924. wiphy->mgmt_stypes = wil_mgmt_stypes;
  925. wiphy->features |= NL80211_FEATURE_SK_TX_STATUS;
  926. }
  927. struct wireless_dev *wil_cfg80211_init(struct device *dev)
  928. {
  929. int rc = 0;
  930. struct wireless_dev *wdev;
  931. dev_dbg(dev, "%s()\n", __func__);
  932. wdev = kzalloc(sizeof(*wdev), GFP_KERNEL);
  933. if (!wdev)
  934. return ERR_PTR(-ENOMEM);
  935. wdev->wiphy = wiphy_new(&wil_cfg80211_ops,
  936. sizeof(struct wil6210_priv));
  937. if (!wdev->wiphy) {
  938. rc = -ENOMEM;
  939. goto out;
  940. }
  941. set_wiphy_dev(wdev->wiphy, dev);
  942. wil_wiphy_init(wdev->wiphy);
  943. rc = wiphy_register(wdev->wiphy);
  944. if (rc < 0)
  945. goto out_failed_reg;
  946. return wdev;
  947. out_failed_reg:
  948. wiphy_free(wdev->wiphy);
  949. out:
  950. kfree(wdev);
  951. return ERR_PTR(rc);
  952. }
  953. void wil_wdev_free(struct wil6210_priv *wil)
  954. {
  955. struct wireless_dev *wdev = wil_to_wdev(wil);
  956. dev_dbg(wil_to_dev(wil), "%s()\n", __func__);
  957. if (!wdev)
  958. return;
  959. wiphy_unregister(wdev->wiphy);
  960. wiphy_free(wdev->wiphy);
  961. kfree(wdev);
  962. }