cfg80211.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. /*
  2. * Copyright (c) 2012 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 "wil6210.h"
  17. #include "wmi.h"
  18. #define CHAN60G(_channel, _flags) { \
  19. .band = IEEE80211_BAND_60GHZ, \
  20. .center_freq = 56160 + (2160 * (_channel)), \
  21. .hw_value = (_channel), \
  22. .flags = (_flags), \
  23. .max_antenna_gain = 0, \
  24. .max_power = 40, \
  25. }
  26. static struct ieee80211_channel wil_60ghz_channels[] = {
  27. CHAN60G(1, 0),
  28. CHAN60G(2, 0),
  29. CHAN60G(3, 0),
  30. /* channel 4 not supported yet */
  31. };
  32. static struct ieee80211_supported_band wil_band_60ghz = {
  33. .channels = wil_60ghz_channels,
  34. .n_channels = ARRAY_SIZE(wil_60ghz_channels),
  35. .ht_cap = {
  36. .ht_supported = true,
  37. .cap = 0, /* TODO */
  38. .ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K, /* TODO */
  39. .ampdu_density = IEEE80211_HT_MPDU_DENSITY_8, /* TODO */
  40. .mcs = {
  41. /* MCS 1..12 - SC PHY */
  42. .rx_mask = {0xfe, 0x1f}, /* 1..12 */
  43. .tx_params = IEEE80211_HT_MCS_TX_DEFINED, /* TODO */
  44. },
  45. },
  46. };
  47. static const struct ieee80211_txrx_stypes
  48. wil_mgmt_stypes[NUM_NL80211_IFTYPES] = {
  49. [NL80211_IFTYPE_STATION] = {
  50. .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  51. BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
  52. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  53. BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
  54. },
  55. [NL80211_IFTYPE_AP] = {
  56. .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  57. BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
  58. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  59. BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
  60. },
  61. [NL80211_IFTYPE_P2P_CLIENT] = {
  62. .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  63. BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
  64. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  65. BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
  66. },
  67. [NL80211_IFTYPE_P2P_GO] = {
  68. .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  69. BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
  70. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  71. BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
  72. },
  73. };
  74. static const u32 wil_cipher_suites[] = {
  75. WLAN_CIPHER_SUITE_GCMP,
  76. };
  77. int wil_iftype_nl2wmi(enum nl80211_iftype type)
  78. {
  79. static const struct {
  80. enum nl80211_iftype nl;
  81. enum wmi_network_type wmi;
  82. } __nl2wmi[] = {
  83. {NL80211_IFTYPE_ADHOC, WMI_NETTYPE_ADHOC},
  84. {NL80211_IFTYPE_STATION, WMI_NETTYPE_INFRA},
  85. {NL80211_IFTYPE_AP, WMI_NETTYPE_AP},
  86. {NL80211_IFTYPE_P2P_CLIENT, WMI_NETTYPE_P2P},
  87. {NL80211_IFTYPE_P2P_GO, WMI_NETTYPE_P2P},
  88. {NL80211_IFTYPE_MONITOR, WMI_NETTYPE_ADHOC}, /* FIXME */
  89. };
  90. uint i;
  91. for (i = 0; i < ARRAY_SIZE(__nl2wmi); i++) {
  92. if (__nl2wmi[i].nl == type)
  93. return __nl2wmi[i].wmi;
  94. }
  95. return -EOPNOTSUPP;
  96. }
  97. static int wil_cfg80211_get_station(struct wiphy *wiphy,
  98. struct net_device *ndev,
  99. u8 *mac, struct station_info *sinfo)
  100. {
  101. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  102. int rc;
  103. struct wmi_notify_req_cmd cmd = {
  104. .cid = 0,
  105. .interval_usec = 0,
  106. };
  107. if (memcmp(mac, wil->dst_addr[0], ETH_ALEN))
  108. return -ENOENT;
  109. /* WMI_NOTIFY_REQ_DONE_EVENTID handler fills wil->stats.bf_mcs */
  110. rc = wmi_call(wil, WMI_NOTIFY_REQ_CMDID, &cmd, sizeof(cmd),
  111. WMI_NOTIFY_REQ_DONE_EVENTID, NULL, 0, 20);
  112. if (rc)
  113. return rc;
  114. sinfo->generation = wil->sinfo_gen;
  115. sinfo->filled |= STATION_INFO_TX_BITRATE;
  116. sinfo->txrate.flags = RATE_INFO_FLAGS_MCS | RATE_INFO_FLAGS_60G;
  117. sinfo->txrate.mcs = wil->stats.bf_mcs;
  118. sinfo->filled |= STATION_INFO_RX_BITRATE;
  119. sinfo->rxrate.flags = RATE_INFO_FLAGS_MCS | RATE_INFO_FLAGS_60G;
  120. sinfo->rxrate.mcs = wil->stats.last_mcs_rx;
  121. if (test_bit(wil_status_fwconnected, &wil->status)) {
  122. sinfo->filled |= STATION_INFO_SIGNAL;
  123. sinfo->signal = 12; /* TODO: provide real value */
  124. }
  125. return 0;
  126. }
  127. static int wil_cfg80211_change_iface(struct wiphy *wiphy,
  128. struct net_device *ndev,
  129. enum nl80211_iftype type, u32 *flags,
  130. struct vif_params *params)
  131. {
  132. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  133. struct wireless_dev *wdev = wil->wdev;
  134. switch (type) {
  135. case NL80211_IFTYPE_STATION:
  136. case NL80211_IFTYPE_AP:
  137. case NL80211_IFTYPE_P2P_CLIENT:
  138. case NL80211_IFTYPE_P2P_GO:
  139. break;
  140. case NL80211_IFTYPE_MONITOR:
  141. if (flags)
  142. wil->monitor_flags = *flags;
  143. else
  144. wil->monitor_flags = 0;
  145. break;
  146. default:
  147. return -EOPNOTSUPP;
  148. }
  149. wdev->iftype = type;
  150. return 0;
  151. }
  152. static int wil_cfg80211_scan(struct wiphy *wiphy,
  153. struct cfg80211_scan_request *request)
  154. {
  155. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  156. struct wireless_dev *wdev = wil->wdev;
  157. struct {
  158. struct wmi_start_scan_cmd cmd;
  159. u16 chnl[4];
  160. } __packed cmd;
  161. uint i, n;
  162. if (wil->scan_request) {
  163. wil_err(wil, "Already scanning\n");
  164. return -EAGAIN;
  165. }
  166. /* check we are client side */
  167. switch (wdev->iftype) {
  168. case NL80211_IFTYPE_STATION:
  169. case NL80211_IFTYPE_P2P_CLIENT:
  170. break;
  171. default:
  172. return -EOPNOTSUPP;
  173. }
  174. /* FW don't support scan after connection attempt */
  175. if (test_bit(wil_status_dontscan, &wil->status)) {
  176. wil_err(wil, "Scan after connect attempt not supported\n");
  177. return -EBUSY;
  178. }
  179. wil->scan_request = request;
  180. memset(&cmd, 0, sizeof(cmd));
  181. cmd.cmd.num_channels = 0;
  182. n = min(request->n_channels, 4U);
  183. for (i = 0; i < n; i++) {
  184. int ch = request->channels[i]->hw_value;
  185. if (ch == 0) {
  186. wil_err(wil,
  187. "Scan requested for unknown frequency %dMhz\n",
  188. request->channels[i]->center_freq);
  189. continue;
  190. }
  191. /* 0-based channel indexes */
  192. cmd.cmd.channel_list[cmd.cmd.num_channels++].channel = ch - 1;
  193. wil_dbg_misc(wil, "Scan for ch %d : %d MHz\n", ch,
  194. request->channels[i]->center_freq);
  195. }
  196. return wmi_send(wil, WMI_START_SCAN_CMDID, &cmd, sizeof(cmd.cmd) +
  197. cmd.cmd.num_channels * sizeof(cmd.cmd.channel_list[0]));
  198. }
  199. static int wil_cfg80211_connect(struct wiphy *wiphy,
  200. struct net_device *ndev,
  201. struct cfg80211_connect_params *sme)
  202. {
  203. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  204. struct cfg80211_bss *bss;
  205. struct wmi_connect_cmd conn;
  206. const u8 *ssid_eid;
  207. const u8 *rsn_eid;
  208. int ch;
  209. int rc = 0;
  210. bss = cfg80211_get_bss(wiphy, sme->channel, sme->bssid,
  211. sme->ssid, sme->ssid_len,
  212. WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
  213. if (!bss) {
  214. wil_err(wil, "Unable to find BSS\n");
  215. return -ENOENT;
  216. }
  217. ssid_eid = ieee80211_bss_get_ie(bss, WLAN_EID_SSID);
  218. if (!ssid_eid) {
  219. wil_err(wil, "No SSID\n");
  220. rc = -ENOENT;
  221. goto out;
  222. }
  223. rsn_eid = sme->ie ?
  224. cfg80211_find_ie(WLAN_EID_RSN, sme->ie, sme->ie_len) :
  225. NULL;
  226. if (rsn_eid) {
  227. if (sme->ie_len > WMI_MAX_IE_LEN) {
  228. rc = -ERANGE;
  229. wil_err(wil, "IE too large (%td bytes)\n",
  230. sme->ie_len);
  231. goto out;
  232. }
  233. /*
  234. * For secure assoc, send:
  235. * (1) WMI_DELETE_CIPHER_KEY_CMD
  236. * (2) WMI_SET_APPIE_CMD
  237. */
  238. rc = wmi_del_cipher_key(wil, 0, bss->bssid);
  239. if (rc) {
  240. wil_err(wil, "WMI_DELETE_CIPHER_KEY_CMD failed\n");
  241. goto out;
  242. }
  243. /* WMI_SET_APPIE_CMD */
  244. rc = wmi_set_ie(wil, WMI_FRAME_ASSOC_REQ, sme->ie_len, sme->ie);
  245. if (rc) {
  246. wil_err(wil, "WMI_SET_APPIE_CMD failed\n");
  247. goto out;
  248. }
  249. }
  250. /* WMI_CONNECT_CMD */
  251. memset(&conn, 0, sizeof(conn));
  252. switch (bss->capability & WLAN_CAPABILITY_DMG_TYPE_MASK) {
  253. case WLAN_CAPABILITY_DMG_TYPE_AP:
  254. conn.network_type = WMI_NETTYPE_INFRA;
  255. break;
  256. case WLAN_CAPABILITY_DMG_TYPE_PBSS:
  257. conn.network_type = WMI_NETTYPE_P2P;
  258. break;
  259. default:
  260. wil_err(wil, "Unsupported BSS type, capability= 0x%04x\n",
  261. bss->capability);
  262. goto out;
  263. }
  264. if (rsn_eid) {
  265. conn.dot11_auth_mode = WMI_AUTH11_SHARED;
  266. conn.auth_mode = WMI_AUTH_WPA2_PSK;
  267. conn.pairwise_crypto_type = WMI_CRYPT_AES_GCMP;
  268. conn.pairwise_crypto_len = 16;
  269. } else {
  270. conn.dot11_auth_mode = WMI_AUTH11_OPEN;
  271. conn.auth_mode = WMI_AUTH_NONE;
  272. }
  273. conn.ssid_len = min_t(u8, ssid_eid[1], 32);
  274. memcpy(conn.ssid, ssid_eid+2, conn.ssid_len);
  275. ch = bss->channel->hw_value;
  276. if (ch == 0) {
  277. wil_err(wil, "BSS at unknown frequency %dMhz\n",
  278. bss->channel->center_freq);
  279. rc = -EOPNOTSUPP;
  280. goto out;
  281. }
  282. conn.channel = ch - 1;
  283. memcpy(conn.bssid, bss->bssid, 6);
  284. memcpy(conn.dst_mac, bss->bssid, 6);
  285. /*
  286. * FW don't support scan after connection attempt
  287. */
  288. set_bit(wil_status_dontscan, &wil->status);
  289. set_bit(wil_status_fwconnecting, &wil->status);
  290. rc = wmi_send(wil, WMI_CONNECT_CMDID, &conn, sizeof(conn));
  291. if (rc == 0) {
  292. /* Connect can take lots of time */
  293. mod_timer(&wil->connect_timer,
  294. jiffies + msecs_to_jiffies(2000));
  295. } else {
  296. clear_bit(wil_status_dontscan, &wil->status);
  297. clear_bit(wil_status_fwconnecting, &wil->status);
  298. }
  299. out:
  300. cfg80211_put_bss(wiphy, bss);
  301. return rc;
  302. }
  303. static int wil_cfg80211_disconnect(struct wiphy *wiphy,
  304. struct net_device *ndev,
  305. u16 reason_code)
  306. {
  307. int rc;
  308. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  309. rc = wmi_send(wil, WMI_DISCONNECT_CMDID, NULL, 0);
  310. return rc;
  311. }
  312. static int wil_cfg80211_set_channel(struct wiphy *wiphy,
  313. struct cfg80211_chan_def *chandef)
  314. {
  315. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  316. struct wireless_dev *wdev = wil->wdev;
  317. wdev->preset_chandef = *chandef;
  318. return 0;
  319. }
  320. static int wil_cfg80211_add_key(struct wiphy *wiphy,
  321. struct net_device *ndev,
  322. u8 key_index, bool pairwise,
  323. const u8 *mac_addr,
  324. struct key_params *params)
  325. {
  326. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  327. /* group key is not used */
  328. if (!pairwise)
  329. return 0;
  330. return wmi_add_cipher_key(wil, key_index, mac_addr,
  331. params->key_len, params->key);
  332. }
  333. static int wil_cfg80211_del_key(struct wiphy *wiphy,
  334. struct net_device *ndev,
  335. u8 key_index, bool pairwise,
  336. const u8 *mac_addr)
  337. {
  338. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  339. /* group key is not used */
  340. if (!pairwise)
  341. return 0;
  342. return wmi_del_cipher_key(wil, key_index, mac_addr);
  343. }
  344. /* Need to be present or wiphy_new() will WARN */
  345. static int wil_cfg80211_set_default_key(struct wiphy *wiphy,
  346. struct net_device *ndev,
  347. u8 key_index, bool unicast,
  348. bool multicast)
  349. {
  350. return 0;
  351. }
  352. static int wil_fix_bcon(struct wil6210_priv *wil,
  353. struct cfg80211_beacon_data *bcon)
  354. {
  355. struct ieee80211_mgmt *f = (struct ieee80211_mgmt *)bcon->probe_resp;
  356. size_t hlen = offsetof(struct ieee80211_mgmt, u.probe_resp.variable);
  357. int rc = 0;
  358. if (bcon->probe_resp_len <= hlen)
  359. return 0;
  360. if (!bcon->proberesp_ies) {
  361. bcon->proberesp_ies = f->u.probe_resp.variable;
  362. bcon->proberesp_ies_len = bcon->probe_resp_len - hlen;
  363. rc = 1;
  364. }
  365. if (!bcon->assocresp_ies) {
  366. bcon->assocresp_ies = f->u.probe_resp.variable;
  367. bcon->assocresp_ies_len = bcon->probe_resp_len - hlen;
  368. rc = 1;
  369. }
  370. return rc;
  371. }
  372. static int wil_cfg80211_start_ap(struct wiphy *wiphy,
  373. struct net_device *ndev,
  374. struct cfg80211_ap_settings *info)
  375. {
  376. int rc = 0;
  377. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  378. struct wireless_dev *wdev = ndev->ieee80211_ptr;
  379. struct ieee80211_channel *channel = info->chandef.chan;
  380. struct cfg80211_beacon_data *bcon = &info->beacon;
  381. u8 wmi_nettype = wil_iftype_nl2wmi(wdev->iftype);
  382. if (!channel) {
  383. wil_err(wil, "AP: No channel???\n");
  384. return -EINVAL;
  385. }
  386. wil_dbg_misc(wil, "AP on Channel %d %d MHz, %s\n", channel->hw_value,
  387. channel->center_freq, info->privacy ? "secure" : "open");
  388. print_hex_dump_bytes("SSID ", DUMP_PREFIX_OFFSET,
  389. info->ssid, info->ssid_len);
  390. if (wil_fix_bcon(wil, bcon))
  391. wil_dbg_misc(wil, "Fixed bcon\n");
  392. rc = wil_reset(wil);
  393. if (rc)
  394. return rc;
  395. /* Rx VRING. */
  396. rc = wil_rx_init(wil);
  397. if (rc)
  398. return rc;
  399. rc = wmi_set_ssid(wil, info->ssid_len, info->ssid);
  400. if (rc)
  401. return rc;
  402. /* MAC address - pre-requisite for other commands */
  403. wmi_set_mac_address(wil, ndev->dev_addr);
  404. /* IE's */
  405. /* bcon 'head IE's are not relevant for 60g band */
  406. /*
  407. * FW do not form regular beacon, so bcon IE's are not set
  408. * For the DMG bcon, when it will be supported, bcon IE's will
  409. * be reused; add something like:
  410. * wmi_set_ie(wil, WMI_FRAME_BEACON, bcon->beacon_ies_len,
  411. * bcon->beacon_ies);
  412. */
  413. wmi_set_ie(wil, WMI_FRAME_PROBE_RESP, bcon->proberesp_ies_len,
  414. bcon->proberesp_ies);
  415. wmi_set_ie(wil, WMI_FRAME_ASSOC_RESP, bcon->assocresp_ies_len,
  416. bcon->assocresp_ies);
  417. wil->secure_pcp = info->privacy;
  418. rc = wmi_pcp_start(wil, info->beacon_interval, wmi_nettype,
  419. channel->hw_value);
  420. if (rc)
  421. return rc;
  422. netif_carrier_on(ndev);
  423. return rc;
  424. }
  425. static int wil_cfg80211_stop_ap(struct wiphy *wiphy,
  426. struct net_device *ndev)
  427. {
  428. int rc = 0;
  429. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  430. rc = wmi_pcp_stop(wil);
  431. return rc;
  432. }
  433. static struct cfg80211_ops wil_cfg80211_ops = {
  434. .scan = wil_cfg80211_scan,
  435. .connect = wil_cfg80211_connect,
  436. .disconnect = wil_cfg80211_disconnect,
  437. .change_virtual_intf = wil_cfg80211_change_iface,
  438. .get_station = wil_cfg80211_get_station,
  439. .set_monitor_channel = wil_cfg80211_set_channel,
  440. .add_key = wil_cfg80211_add_key,
  441. .del_key = wil_cfg80211_del_key,
  442. .set_default_key = wil_cfg80211_set_default_key,
  443. /* AP mode */
  444. .start_ap = wil_cfg80211_start_ap,
  445. .stop_ap = wil_cfg80211_stop_ap,
  446. };
  447. static void wil_wiphy_init(struct wiphy *wiphy)
  448. {
  449. /* TODO: set real value */
  450. wiphy->max_scan_ssids = 10;
  451. wiphy->max_num_pmkids = 0 /* TODO: */;
  452. wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
  453. BIT(NL80211_IFTYPE_AP) |
  454. BIT(NL80211_IFTYPE_MONITOR);
  455. /* TODO: enable P2P when integrated with supplicant:
  456. * BIT(NL80211_IFTYPE_P2P_CLIENT) | BIT(NL80211_IFTYPE_P2P_GO)
  457. */
  458. wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME |
  459. WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
  460. dev_warn(wiphy_dev(wiphy), "%s : flags = 0x%08x\n",
  461. __func__, wiphy->flags);
  462. wiphy->probe_resp_offload =
  463. NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
  464. NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
  465. NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
  466. wiphy->bands[IEEE80211_BAND_60GHZ] = &wil_band_60ghz;
  467. /* TODO: figure this out */
  468. wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
  469. wiphy->cipher_suites = wil_cipher_suites;
  470. wiphy->n_cipher_suites = ARRAY_SIZE(wil_cipher_suites);
  471. wiphy->mgmt_stypes = wil_mgmt_stypes;
  472. }
  473. struct wireless_dev *wil_cfg80211_init(struct device *dev)
  474. {
  475. int rc = 0;
  476. struct wireless_dev *wdev;
  477. wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
  478. if (!wdev)
  479. return ERR_PTR(-ENOMEM);
  480. wdev->wiphy = wiphy_new(&wil_cfg80211_ops,
  481. sizeof(struct wil6210_priv));
  482. if (!wdev->wiphy) {
  483. rc = -ENOMEM;
  484. goto out;
  485. }
  486. set_wiphy_dev(wdev->wiphy, dev);
  487. wil_wiphy_init(wdev->wiphy);
  488. rc = wiphy_register(wdev->wiphy);
  489. if (rc < 0)
  490. goto out_failed_reg;
  491. return wdev;
  492. out_failed_reg:
  493. wiphy_free(wdev->wiphy);
  494. out:
  495. kfree(wdev);
  496. return ERR_PTR(rc);
  497. }
  498. void wil_wdev_free(struct wil6210_priv *wil)
  499. {
  500. struct wireless_dev *wdev = wil_to_wdev(wil);
  501. if (!wdev)
  502. return;
  503. wiphy_unregister(wdev->wiphy);
  504. wiphy_free(wdev->wiphy);
  505. kfree(wdev);
  506. }