cfg80211.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243
  1. /*
  2. * Copyright (c) 2012-2016 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. if (sme->pbss) {
  366. wil_err(wil, "connect - PBSS not yet supported\n");
  367. return -EOPNOTSUPP;
  368. }
  369. bss = cfg80211_get_bss(wiphy, sme->channel, sme->bssid,
  370. sme->ssid, sme->ssid_len,
  371. IEEE80211_BSS_TYPE_ESS, IEEE80211_PRIVACY_ANY);
  372. if (!bss) {
  373. wil_err(wil, "Unable to find BSS\n");
  374. return -ENOENT;
  375. }
  376. ssid_eid = ieee80211_bss_get_ie(bss, WLAN_EID_SSID);
  377. if (!ssid_eid) {
  378. wil_err(wil, "No SSID\n");
  379. rc = -ENOENT;
  380. goto out;
  381. }
  382. wil->privacy = sme->privacy;
  383. if (wil->privacy) {
  384. /* For secure assoc, remove old keys */
  385. rc = wmi_del_cipher_key(wil, 0, bss->bssid,
  386. WMI_KEY_USE_PAIRWISE);
  387. if (rc) {
  388. wil_err(wil, "WMI_DELETE_CIPHER_KEY_CMD(PTK) failed\n");
  389. goto out;
  390. }
  391. rc = wmi_del_cipher_key(wil, 0, bss->bssid,
  392. WMI_KEY_USE_RX_GROUP);
  393. if (rc) {
  394. wil_err(wil, "WMI_DELETE_CIPHER_KEY_CMD(GTK) failed\n");
  395. goto out;
  396. }
  397. }
  398. /* WMI_SET_APPIE_CMD. ie may contain rsn info as well as other info
  399. * elements. Send it also in case it's empty, to erase previously set
  400. * ies in FW.
  401. */
  402. rc = wmi_set_ie(wil, WMI_FRAME_ASSOC_REQ, sme->ie_len, sme->ie);
  403. if (rc)
  404. goto out;
  405. /* WMI_CONNECT_CMD */
  406. memset(&conn, 0, sizeof(conn));
  407. switch (bss->capability & WLAN_CAPABILITY_DMG_TYPE_MASK) {
  408. case WLAN_CAPABILITY_DMG_TYPE_AP:
  409. conn.network_type = WMI_NETTYPE_INFRA;
  410. break;
  411. case WLAN_CAPABILITY_DMG_TYPE_PBSS:
  412. conn.network_type = WMI_NETTYPE_P2P;
  413. break;
  414. default:
  415. wil_err(wil, "Unsupported BSS type, capability= 0x%04x\n",
  416. bss->capability);
  417. goto out;
  418. }
  419. if (wil->privacy) {
  420. if (rsn_eid) { /* regular secure connection */
  421. conn.dot11_auth_mode = WMI_AUTH11_SHARED;
  422. conn.auth_mode = WMI_AUTH_WPA2_PSK;
  423. conn.pairwise_crypto_type = WMI_CRYPT_AES_GCMP;
  424. conn.pairwise_crypto_len = 16;
  425. conn.group_crypto_type = WMI_CRYPT_AES_GCMP;
  426. conn.group_crypto_len = 16;
  427. } else { /* WSC */
  428. conn.dot11_auth_mode = WMI_AUTH11_WSC;
  429. conn.auth_mode = WMI_AUTH_NONE;
  430. }
  431. } else { /* insecure connection */
  432. conn.dot11_auth_mode = WMI_AUTH11_OPEN;
  433. conn.auth_mode = WMI_AUTH_NONE;
  434. }
  435. conn.ssid_len = min_t(u8, ssid_eid[1], 32);
  436. memcpy(conn.ssid, ssid_eid+2, conn.ssid_len);
  437. ch = bss->channel->hw_value;
  438. if (ch == 0) {
  439. wil_err(wil, "BSS at unknown frequency %dMhz\n",
  440. bss->channel->center_freq);
  441. rc = -EOPNOTSUPP;
  442. goto out;
  443. }
  444. conn.channel = ch - 1;
  445. ether_addr_copy(conn.bssid, bss->bssid);
  446. ether_addr_copy(conn.dst_mac, bss->bssid);
  447. set_bit(wil_status_fwconnecting, wil->status);
  448. rc = wmi_send(wil, WMI_CONNECT_CMDID, &conn, sizeof(conn));
  449. if (rc == 0) {
  450. netif_carrier_on(ndev);
  451. /* Connect can take lots of time */
  452. mod_timer(&wil->connect_timer,
  453. jiffies + msecs_to_jiffies(2000));
  454. } else {
  455. clear_bit(wil_status_fwconnecting, wil->status);
  456. }
  457. out:
  458. cfg80211_put_bss(wiphy, bss);
  459. return rc;
  460. }
  461. static int wil_cfg80211_disconnect(struct wiphy *wiphy,
  462. struct net_device *ndev,
  463. u16 reason_code)
  464. {
  465. int rc;
  466. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  467. wil_dbg_misc(wil, "%s(reason=%d)\n", __func__, reason_code);
  468. if (!(test_bit(wil_status_fwconnecting, wil->status) ||
  469. test_bit(wil_status_fwconnected, wil->status))) {
  470. wil_err(wil, "%s: Disconnect was called while disconnected\n",
  471. __func__);
  472. return 0;
  473. }
  474. rc = wmi_call(wil, WMI_DISCONNECT_CMDID, NULL, 0,
  475. WMI_DISCONNECT_EVENTID, NULL, 0,
  476. WIL6210_DISCONNECT_TO_MS);
  477. if (rc)
  478. wil_err(wil, "%s: disconnect error %d\n", __func__, rc);
  479. return rc;
  480. }
  481. int wil_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
  482. struct cfg80211_mgmt_tx_params *params,
  483. u64 *cookie)
  484. {
  485. const u8 *buf = params->buf;
  486. size_t len = params->len;
  487. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  488. int rc;
  489. bool tx_status = false;
  490. struct ieee80211_mgmt *mgmt_frame = (void *)buf;
  491. struct wmi_sw_tx_req_cmd *cmd;
  492. struct {
  493. struct wil6210_mbox_hdr_wmi wmi;
  494. struct wmi_sw_tx_complete_event evt;
  495. } __packed evt;
  496. cmd = kmalloc(sizeof(*cmd) + len, GFP_KERNEL);
  497. if (!cmd) {
  498. rc = -ENOMEM;
  499. goto out;
  500. }
  501. memcpy(cmd->dst_mac, mgmt_frame->da, WMI_MAC_LEN);
  502. cmd->len = cpu_to_le16(len);
  503. memcpy(cmd->payload, buf, len);
  504. rc = wmi_call(wil, WMI_SW_TX_REQ_CMDID, cmd, sizeof(*cmd) + len,
  505. WMI_SW_TX_COMPLETE_EVENTID, &evt, sizeof(evt), 2000);
  506. if (rc == 0)
  507. tx_status = !evt.evt.status;
  508. kfree(cmd);
  509. out:
  510. cfg80211_mgmt_tx_status(wdev, cookie ? *cookie : 0, buf, len,
  511. tx_status, GFP_KERNEL);
  512. return rc;
  513. }
  514. static int wil_cfg80211_set_channel(struct wiphy *wiphy,
  515. struct cfg80211_chan_def *chandef)
  516. {
  517. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  518. struct wireless_dev *wdev = wil->wdev;
  519. wdev->preset_chandef = *chandef;
  520. return 0;
  521. }
  522. static enum wmi_key_usage wil_detect_key_usage(struct wil6210_priv *wil,
  523. bool pairwise)
  524. {
  525. struct wireless_dev *wdev = wil->wdev;
  526. enum wmi_key_usage rc;
  527. static const char * const key_usage_str[] = {
  528. [WMI_KEY_USE_PAIRWISE] = "WMI_KEY_USE_PAIRWISE",
  529. [WMI_KEY_USE_RX_GROUP] = "WMI_KEY_USE_RX_GROUP",
  530. [WMI_KEY_USE_TX_GROUP] = "WMI_KEY_USE_TX_GROUP",
  531. };
  532. if (pairwise) {
  533. rc = WMI_KEY_USE_PAIRWISE;
  534. } else {
  535. switch (wdev->iftype) {
  536. case NL80211_IFTYPE_STATION:
  537. rc = WMI_KEY_USE_RX_GROUP;
  538. break;
  539. case NL80211_IFTYPE_AP:
  540. rc = WMI_KEY_USE_TX_GROUP;
  541. break;
  542. default:
  543. /* TODO: Rx GTK or Tx GTK? */
  544. wil_err(wil, "Can't determine GTK type\n");
  545. rc = WMI_KEY_USE_RX_GROUP;
  546. break;
  547. }
  548. }
  549. wil_dbg_misc(wil, "%s() -> %s\n", __func__, key_usage_str[rc]);
  550. return rc;
  551. }
  552. static int wil_cfg80211_add_key(struct wiphy *wiphy,
  553. struct net_device *ndev,
  554. u8 key_index, bool pairwise,
  555. const u8 *mac_addr,
  556. struct key_params *params)
  557. {
  558. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  559. enum wmi_key_usage key_usage = wil_detect_key_usage(wil, pairwise);
  560. wil_dbg_misc(wil, "%s(%pM[%d] %s)\n", __func__, mac_addr, key_index,
  561. pairwise ? "PTK" : "GTK");
  562. return wmi_add_cipher_key(wil, key_index, mac_addr, params->key_len,
  563. params->key, key_usage);
  564. }
  565. static int wil_cfg80211_del_key(struct wiphy *wiphy,
  566. struct net_device *ndev,
  567. u8 key_index, bool pairwise,
  568. const u8 *mac_addr)
  569. {
  570. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  571. enum wmi_key_usage key_usage = wil_detect_key_usage(wil, pairwise);
  572. wil_dbg_misc(wil, "%s(%pM[%d] %s)\n", __func__, mac_addr, key_index,
  573. pairwise ? "PTK" : "GTK");
  574. return wmi_del_cipher_key(wil, key_index, mac_addr, key_usage);
  575. }
  576. /* Need to be present or wiphy_new() will WARN */
  577. static int wil_cfg80211_set_default_key(struct wiphy *wiphy,
  578. struct net_device *ndev,
  579. u8 key_index, bool unicast,
  580. bool multicast)
  581. {
  582. return 0;
  583. }
  584. static int wil_remain_on_channel(struct wiphy *wiphy,
  585. struct wireless_dev *wdev,
  586. struct ieee80211_channel *chan,
  587. unsigned int duration,
  588. u64 *cookie)
  589. {
  590. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  591. int rc;
  592. /* TODO: handle duration */
  593. wil_info(wil, "%s(%d, %d ms)\n", __func__, chan->center_freq, duration);
  594. rc = wmi_set_channel(wil, chan->hw_value);
  595. if (rc)
  596. return rc;
  597. rc = wmi_rxon(wil, true);
  598. return rc;
  599. }
  600. static int wil_cancel_remain_on_channel(struct wiphy *wiphy,
  601. struct wireless_dev *wdev,
  602. u64 cookie)
  603. {
  604. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  605. int rc;
  606. wil_info(wil, "%s()\n", __func__);
  607. rc = wmi_rxon(wil, false);
  608. return rc;
  609. }
  610. /**
  611. * find a specific IE in a list of IEs
  612. * return a pointer to the beginning of IE in the list
  613. * or NULL if not found
  614. */
  615. static const u8 *_wil_cfg80211_find_ie(const u8 *ies, u16 ies_len, const u8 *ie,
  616. u16 ie_len)
  617. {
  618. struct ieee80211_vendor_ie *vie;
  619. u32 oui;
  620. /* IE tag at offset 0, length at offset 1 */
  621. if (ie_len < 2 || 2 + ie[1] > ie_len)
  622. return NULL;
  623. if (ie[0] != WLAN_EID_VENDOR_SPECIFIC)
  624. return cfg80211_find_ie(ie[0], ies, ies_len);
  625. /* make sure there is room for 3 bytes OUI + 1 byte OUI type */
  626. if (ie[1] < 4)
  627. return NULL;
  628. vie = (struct ieee80211_vendor_ie *)ie;
  629. oui = vie->oui[0] << 16 | vie->oui[1] << 8 | vie->oui[2];
  630. return cfg80211_find_vendor_ie(oui, vie->oui_type, ies,
  631. ies_len);
  632. }
  633. /**
  634. * merge the IEs in two lists into a single list.
  635. * do not include IEs from the second list which exist in the first list.
  636. * add only vendor specific IEs from second list to keep
  637. * the merged list sorted (since vendor-specific IE has the
  638. * highest tag number)
  639. * caller must free the allocated memory for merged IEs
  640. */
  641. static int _wil_cfg80211_merge_extra_ies(const u8 *ies1, u16 ies1_len,
  642. const u8 *ies2, u16 ies2_len,
  643. u8 **merged_ies, u16 *merged_len)
  644. {
  645. u8 *buf, *dpos;
  646. const u8 *spos;
  647. if (ies1_len == 0 && ies2_len == 0) {
  648. *merged_ies = NULL;
  649. *merged_len = 0;
  650. return 0;
  651. }
  652. buf = kmalloc(ies1_len + ies2_len, GFP_KERNEL);
  653. if (!buf)
  654. return -ENOMEM;
  655. memcpy(buf, ies1, ies1_len);
  656. dpos = buf + ies1_len;
  657. spos = ies2;
  658. while (spos + 1 < ies2 + ies2_len) {
  659. /* IE tag at offset 0, length at offset 1 */
  660. u16 ielen = 2 + spos[1];
  661. if (spos + ielen > ies2 + ies2_len)
  662. break;
  663. if (spos[0] == WLAN_EID_VENDOR_SPECIFIC &&
  664. !_wil_cfg80211_find_ie(ies1, ies1_len, spos, ielen)) {
  665. memcpy(dpos, spos, ielen);
  666. dpos += ielen;
  667. }
  668. spos += ielen;
  669. }
  670. *merged_ies = buf;
  671. *merged_len = dpos - buf;
  672. return 0;
  673. }
  674. static void wil_print_bcon_data(struct cfg80211_beacon_data *b)
  675. {
  676. print_hex_dump_bytes("head ", DUMP_PREFIX_OFFSET,
  677. b->head, b->head_len);
  678. print_hex_dump_bytes("tail ", DUMP_PREFIX_OFFSET,
  679. b->tail, b->tail_len);
  680. print_hex_dump_bytes("BCON IE ", DUMP_PREFIX_OFFSET,
  681. b->beacon_ies, b->beacon_ies_len);
  682. print_hex_dump_bytes("PROBE ", DUMP_PREFIX_OFFSET,
  683. b->probe_resp, b->probe_resp_len);
  684. print_hex_dump_bytes("PROBE IE ", DUMP_PREFIX_OFFSET,
  685. b->proberesp_ies, b->proberesp_ies_len);
  686. print_hex_dump_bytes("ASSOC IE ", DUMP_PREFIX_OFFSET,
  687. b->assocresp_ies, b->assocresp_ies_len);
  688. }
  689. /* internal functions for device reset and starting AP */
  690. static int _wil_cfg80211_set_ies(struct wiphy *wiphy,
  691. struct cfg80211_beacon_data *bcon)
  692. {
  693. int rc;
  694. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  695. u16 len = 0, proberesp_len = 0;
  696. u8 *ies = NULL, *proberesp = NULL;
  697. if (bcon->probe_resp) {
  698. struct ieee80211_mgmt *f =
  699. (struct ieee80211_mgmt *)bcon->probe_resp;
  700. size_t hlen = offsetof(struct ieee80211_mgmt,
  701. u.probe_resp.variable);
  702. proberesp = f->u.probe_resp.variable;
  703. proberesp_len = bcon->probe_resp_len - hlen;
  704. }
  705. rc = _wil_cfg80211_merge_extra_ies(proberesp,
  706. proberesp_len,
  707. bcon->proberesp_ies,
  708. bcon->proberesp_ies_len,
  709. &ies, &len);
  710. if (rc)
  711. goto out;
  712. rc = wmi_set_ie(wil, WMI_FRAME_PROBE_RESP, len, ies);
  713. if (rc)
  714. goto out;
  715. if (bcon->assocresp_ies)
  716. rc = wmi_set_ie(wil, WMI_FRAME_ASSOC_RESP,
  717. bcon->assocresp_ies_len, bcon->assocresp_ies);
  718. else
  719. rc = wmi_set_ie(wil, WMI_FRAME_ASSOC_RESP, len, ies);
  720. #if 0 /* to use beacon IE's, remove this #if 0 */
  721. if (rc)
  722. goto out;
  723. rc = wmi_set_ie(wil, WMI_FRAME_BEACON, bcon->tail_len, bcon->tail);
  724. #endif
  725. out:
  726. kfree(ies);
  727. return rc;
  728. }
  729. static int _wil_cfg80211_start_ap(struct wiphy *wiphy,
  730. struct net_device *ndev,
  731. const u8 *ssid, size_t ssid_len, u32 privacy,
  732. int bi, u8 chan,
  733. struct cfg80211_beacon_data *bcon,
  734. u8 hidden_ssid)
  735. {
  736. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  737. int rc;
  738. struct wireless_dev *wdev = ndev->ieee80211_ptr;
  739. u8 wmi_nettype = wil_iftype_nl2wmi(wdev->iftype);
  740. wil_set_recovery_state(wil, fw_recovery_idle);
  741. mutex_lock(&wil->mutex);
  742. __wil_down(wil);
  743. rc = __wil_up(wil);
  744. if (rc)
  745. goto out;
  746. rc = wmi_set_ssid(wil, ssid_len, ssid);
  747. if (rc)
  748. goto out;
  749. rc = _wil_cfg80211_set_ies(wiphy, bcon);
  750. if (rc)
  751. goto out;
  752. wil->privacy = privacy;
  753. wil->channel = chan;
  754. wil->hidden_ssid = hidden_ssid;
  755. netif_carrier_on(ndev);
  756. rc = wmi_pcp_start(wil, bi, wmi_nettype, chan, hidden_ssid);
  757. if (rc)
  758. goto err_pcp_start;
  759. rc = wil_bcast_init(wil);
  760. if (rc)
  761. goto err_bcast;
  762. goto out; /* success */
  763. err_bcast:
  764. wmi_pcp_stop(wil);
  765. err_pcp_start:
  766. netif_carrier_off(ndev);
  767. out:
  768. mutex_unlock(&wil->mutex);
  769. return rc;
  770. }
  771. static int wil_cfg80211_change_beacon(struct wiphy *wiphy,
  772. struct net_device *ndev,
  773. struct cfg80211_beacon_data *bcon)
  774. {
  775. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  776. int rc;
  777. u32 privacy = 0;
  778. wil_dbg_misc(wil, "%s()\n", __func__);
  779. wil_print_bcon_data(bcon);
  780. if (bcon->tail &&
  781. cfg80211_find_ie(WLAN_EID_RSN, bcon->tail,
  782. bcon->tail_len))
  783. privacy = 1;
  784. /* in case privacy has changed, need to restart the AP */
  785. if (wil->privacy != privacy) {
  786. struct wireless_dev *wdev = ndev->ieee80211_ptr;
  787. wil_dbg_misc(wil, "privacy changed %d=>%d. Restarting AP\n",
  788. wil->privacy, privacy);
  789. rc = _wil_cfg80211_start_ap(wiphy, ndev, wdev->ssid,
  790. wdev->ssid_len, privacy,
  791. wdev->beacon_interval,
  792. wil->channel, bcon,
  793. wil->hidden_ssid);
  794. } else {
  795. rc = _wil_cfg80211_set_ies(wiphy, bcon);
  796. }
  797. return rc;
  798. }
  799. static int wil_cfg80211_start_ap(struct wiphy *wiphy,
  800. struct net_device *ndev,
  801. struct cfg80211_ap_settings *info)
  802. {
  803. int rc;
  804. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  805. struct ieee80211_channel *channel = info->chandef.chan;
  806. struct cfg80211_beacon_data *bcon = &info->beacon;
  807. struct cfg80211_crypto_settings *crypto = &info->crypto;
  808. u8 hidden_ssid;
  809. wil_dbg_misc(wil, "%s()\n", __func__);
  810. if (!channel) {
  811. wil_err(wil, "AP: No channel???\n");
  812. return -EINVAL;
  813. }
  814. if (info->pbss) {
  815. wil_err(wil, "AP: PBSS not yet supported\n");
  816. return -EOPNOTSUPP;
  817. }
  818. switch (info->hidden_ssid) {
  819. case NL80211_HIDDEN_SSID_NOT_IN_USE:
  820. hidden_ssid = WMI_HIDDEN_SSID_DISABLED;
  821. break;
  822. case NL80211_HIDDEN_SSID_ZERO_LEN:
  823. hidden_ssid = WMI_HIDDEN_SSID_SEND_EMPTY;
  824. break;
  825. case NL80211_HIDDEN_SSID_ZERO_CONTENTS:
  826. hidden_ssid = WMI_HIDDEN_SSID_CLEAR;
  827. break;
  828. default:
  829. wil_err(wil, "AP: Invalid hidden SSID %d\n", info->hidden_ssid);
  830. return -EOPNOTSUPP;
  831. }
  832. wil_dbg_misc(wil, "AP on Channel %d %d MHz, %s\n", channel->hw_value,
  833. channel->center_freq, info->privacy ? "secure" : "open");
  834. wil_dbg_misc(wil, "Privacy: %d auth_type %d\n",
  835. info->privacy, info->auth_type);
  836. wil_dbg_misc(wil, "Hidden SSID mode: %d\n",
  837. info->hidden_ssid);
  838. wil_dbg_misc(wil, "BI %d DTIM %d\n", info->beacon_interval,
  839. info->dtim_period);
  840. print_hex_dump_bytes("SSID ", DUMP_PREFIX_OFFSET,
  841. info->ssid, info->ssid_len);
  842. wil_print_bcon_data(bcon);
  843. wil_print_crypto(wil, crypto);
  844. rc = _wil_cfg80211_start_ap(wiphy, ndev,
  845. info->ssid, info->ssid_len, info->privacy,
  846. info->beacon_interval, channel->hw_value,
  847. bcon, hidden_ssid);
  848. return rc;
  849. }
  850. static int wil_cfg80211_stop_ap(struct wiphy *wiphy,
  851. struct net_device *ndev)
  852. {
  853. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  854. wil_dbg_misc(wil, "%s()\n", __func__);
  855. netif_carrier_off(ndev);
  856. wil_set_recovery_state(wil, fw_recovery_idle);
  857. mutex_lock(&wil->mutex);
  858. wmi_pcp_stop(wil);
  859. __wil_down(wil);
  860. mutex_unlock(&wil->mutex);
  861. return 0;
  862. }
  863. static int wil_cfg80211_del_station(struct wiphy *wiphy,
  864. struct net_device *dev,
  865. struct station_del_parameters *params)
  866. {
  867. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  868. wil_dbg_misc(wil, "%s(%pM, reason=%d)\n", __func__, params->mac,
  869. params->reason_code);
  870. mutex_lock(&wil->mutex);
  871. wil6210_disconnect(wil, params->mac, params->reason_code, false);
  872. mutex_unlock(&wil->mutex);
  873. return 0;
  874. }
  875. /* probe_client handling */
  876. static void wil_probe_client_handle(struct wil6210_priv *wil,
  877. struct wil_probe_client_req *req)
  878. {
  879. struct net_device *ndev = wil_to_ndev(wil);
  880. struct wil_sta_info *sta = &wil->sta[req->cid];
  881. /* assume STA is alive if it is still connected,
  882. * else FW will disconnect it
  883. */
  884. bool alive = (sta->status == wil_sta_connected);
  885. cfg80211_probe_status(ndev, sta->addr, req->cookie, alive, GFP_KERNEL);
  886. }
  887. static struct list_head *next_probe_client(struct wil6210_priv *wil)
  888. {
  889. struct list_head *ret = NULL;
  890. mutex_lock(&wil->probe_client_mutex);
  891. if (!list_empty(&wil->probe_client_pending)) {
  892. ret = wil->probe_client_pending.next;
  893. list_del(ret);
  894. }
  895. mutex_unlock(&wil->probe_client_mutex);
  896. return ret;
  897. }
  898. void wil_probe_client_worker(struct work_struct *work)
  899. {
  900. struct wil6210_priv *wil = container_of(work, struct wil6210_priv,
  901. probe_client_worker);
  902. struct wil_probe_client_req *req;
  903. struct list_head *lh;
  904. while ((lh = next_probe_client(wil)) != NULL) {
  905. req = list_entry(lh, struct wil_probe_client_req, list);
  906. wil_probe_client_handle(wil, req);
  907. kfree(req);
  908. }
  909. }
  910. void wil_probe_client_flush(struct wil6210_priv *wil)
  911. {
  912. struct wil_probe_client_req *req, *t;
  913. wil_dbg_misc(wil, "%s()\n", __func__);
  914. mutex_lock(&wil->probe_client_mutex);
  915. list_for_each_entry_safe(req, t, &wil->probe_client_pending, list) {
  916. list_del(&req->list);
  917. kfree(req);
  918. }
  919. mutex_unlock(&wil->probe_client_mutex);
  920. }
  921. static int wil_cfg80211_probe_client(struct wiphy *wiphy,
  922. struct net_device *dev,
  923. const u8 *peer, u64 *cookie)
  924. {
  925. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  926. struct wil_probe_client_req *req;
  927. int cid = wil_find_cid(wil, peer);
  928. wil_dbg_misc(wil, "%s(%pM => CID %d)\n", __func__, peer, cid);
  929. if (cid < 0)
  930. return -ENOLINK;
  931. req = kzalloc(sizeof(*req), GFP_KERNEL);
  932. if (!req)
  933. return -ENOMEM;
  934. req->cid = cid;
  935. req->cookie = cid;
  936. mutex_lock(&wil->probe_client_mutex);
  937. list_add_tail(&req->list, &wil->probe_client_pending);
  938. mutex_unlock(&wil->probe_client_mutex);
  939. *cookie = req->cookie;
  940. queue_work(wil->wq_service, &wil->probe_client_worker);
  941. return 0;
  942. }
  943. static int wil_cfg80211_change_bss(struct wiphy *wiphy,
  944. struct net_device *dev,
  945. struct bss_parameters *params)
  946. {
  947. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  948. if (params->ap_isolate >= 0) {
  949. wil_dbg_misc(wil, "%s(ap_isolate %d => %d)\n", __func__,
  950. wil->ap_isolate, params->ap_isolate);
  951. wil->ap_isolate = params->ap_isolate;
  952. }
  953. return 0;
  954. }
  955. static struct cfg80211_ops wil_cfg80211_ops = {
  956. .scan = wil_cfg80211_scan,
  957. .connect = wil_cfg80211_connect,
  958. .disconnect = wil_cfg80211_disconnect,
  959. .change_virtual_intf = wil_cfg80211_change_iface,
  960. .get_station = wil_cfg80211_get_station,
  961. .dump_station = wil_cfg80211_dump_station,
  962. .remain_on_channel = wil_remain_on_channel,
  963. .cancel_remain_on_channel = wil_cancel_remain_on_channel,
  964. .mgmt_tx = wil_cfg80211_mgmt_tx,
  965. .set_monitor_channel = wil_cfg80211_set_channel,
  966. .add_key = wil_cfg80211_add_key,
  967. .del_key = wil_cfg80211_del_key,
  968. .set_default_key = wil_cfg80211_set_default_key,
  969. /* AP mode */
  970. .change_beacon = wil_cfg80211_change_beacon,
  971. .start_ap = wil_cfg80211_start_ap,
  972. .stop_ap = wil_cfg80211_stop_ap,
  973. .del_station = wil_cfg80211_del_station,
  974. .probe_client = wil_cfg80211_probe_client,
  975. .change_bss = wil_cfg80211_change_bss,
  976. };
  977. static void wil_wiphy_init(struct wiphy *wiphy)
  978. {
  979. wiphy->max_scan_ssids = 1;
  980. wiphy->max_scan_ie_len = WMI_MAX_IE_LEN;
  981. wiphy->max_num_pmkids = 0 /* TODO: */;
  982. wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
  983. BIT(NL80211_IFTYPE_AP) |
  984. BIT(NL80211_IFTYPE_MONITOR);
  985. /* TODO: enable P2P when integrated with supplicant:
  986. * BIT(NL80211_IFTYPE_P2P_CLIENT) | BIT(NL80211_IFTYPE_P2P_GO)
  987. */
  988. wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME |
  989. WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
  990. dev_dbg(wiphy_dev(wiphy), "%s : flags = 0x%08x\n",
  991. __func__, wiphy->flags);
  992. wiphy->probe_resp_offload =
  993. NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
  994. NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
  995. NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
  996. wiphy->bands[IEEE80211_BAND_60GHZ] = &wil_band_60ghz;
  997. /* TODO: figure this out */
  998. wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC;
  999. wiphy->cipher_suites = wil_cipher_suites;
  1000. wiphy->n_cipher_suites = ARRAY_SIZE(wil_cipher_suites);
  1001. wiphy->mgmt_stypes = wil_mgmt_stypes;
  1002. wiphy->features |= NL80211_FEATURE_SK_TX_STATUS;
  1003. }
  1004. struct wireless_dev *wil_cfg80211_init(struct device *dev)
  1005. {
  1006. int rc = 0;
  1007. struct wireless_dev *wdev;
  1008. dev_dbg(dev, "%s()\n", __func__);
  1009. wdev = kzalloc(sizeof(*wdev), GFP_KERNEL);
  1010. if (!wdev)
  1011. return ERR_PTR(-ENOMEM);
  1012. wdev->wiphy = wiphy_new(&wil_cfg80211_ops,
  1013. sizeof(struct wil6210_priv));
  1014. if (!wdev->wiphy) {
  1015. rc = -ENOMEM;
  1016. goto out;
  1017. }
  1018. set_wiphy_dev(wdev->wiphy, dev);
  1019. wil_wiphy_init(wdev->wiphy);
  1020. rc = wiphy_register(wdev->wiphy);
  1021. if (rc < 0)
  1022. goto out_failed_reg;
  1023. return wdev;
  1024. out_failed_reg:
  1025. wiphy_free(wdev->wiphy);
  1026. out:
  1027. kfree(wdev);
  1028. return ERR_PTR(rc);
  1029. }
  1030. void wil_wdev_free(struct wil6210_priv *wil)
  1031. {
  1032. struct wireless_dev *wdev = wil_to_wdev(wil);
  1033. dev_dbg(wil_to_dev(wil), "%s()\n", __func__);
  1034. if (!wdev)
  1035. return;
  1036. wiphy_unregister(wdev->wiphy);
  1037. wiphy_free(wdev->wiphy);
  1038. kfree(wdev);
  1039. }