cfg80211.c 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543
  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 WIL_MAX_ROC_DURATION_MS 5000
  20. #define CHAN60G(_channel, _flags) { \
  21. .band = NL80211_BAND_60GHZ, \
  22. .center_freq = 56160 + (2160 * (_channel)), \
  23. .hw_value = (_channel), \
  24. .flags = (_flags), \
  25. .max_antenna_gain = 0, \
  26. .max_power = 40, \
  27. }
  28. static struct ieee80211_channel wil_60ghz_channels[] = {
  29. CHAN60G(1, 0),
  30. CHAN60G(2, 0),
  31. CHAN60G(3, 0),
  32. /* channel 4 not supported yet */
  33. };
  34. static struct ieee80211_supported_band wil_band_60ghz = {
  35. .channels = wil_60ghz_channels,
  36. .n_channels = ARRAY_SIZE(wil_60ghz_channels),
  37. .ht_cap = {
  38. .ht_supported = true,
  39. .cap = 0, /* TODO */
  40. .ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K, /* TODO */
  41. .ampdu_density = IEEE80211_HT_MPDU_DENSITY_8, /* TODO */
  42. .mcs = {
  43. /* MCS 1..12 - SC PHY */
  44. .rx_mask = {0xfe, 0x1f}, /* 1..12 */
  45. .tx_params = IEEE80211_HT_MCS_TX_DEFINED, /* TODO */
  46. },
  47. },
  48. };
  49. static const struct ieee80211_txrx_stypes
  50. wil_mgmt_stypes[NUM_NL80211_IFTYPES] = {
  51. [NL80211_IFTYPE_STATION] = {
  52. .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  53. BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
  54. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  55. BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
  56. },
  57. [NL80211_IFTYPE_AP] = {
  58. .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  59. BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
  60. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  61. BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
  62. },
  63. [NL80211_IFTYPE_P2P_CLIENT] = {
  64. .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  65. BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
  66. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  67. BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
  68. },
  69. [NL80211_IFTYPE_P2P_GO] = {
  70. .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  71. BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
  72. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  73. BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
  74. },
  75. [NL80211_IFTYPE_P2P_DEVICE] = {
  76. .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  77. BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
  78. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  79. BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
  80. },
  81. };
  82. static const u32 wil_cipher_suites[] = {
  83. WLAN_CIPHER_SUITE_GCMP,
  84. };
  85. static const char * const key_usage_str[] = {
  86. [WMI_KEY_USE_PAIRWISE] = "PTK",
  87. [WMI_KEY_USE_RX_GROUP] = "RX_GTK",
  88. [WMI_KEY_USE_TX_GROUP] = "TX_GTK",
  89. };
  90. int wil_iftype_nl2wmi(enum nl80211_iftype type)
  91. {
  92. static const struct {
  93. enum nl80211_iftype nl;
  94. enum wmi_network_type wmi;
  95. } __nl2wmi[] = {
  96. {NL80211_IFTYPE_ADHOC, WMI_NETTYPE_ADHOC},
  97. {NL80211_IFTYPE_STATION, WMI_NETTYPE_INFRA},
  98. {NL80211_IFTYPE_AP, WMI_NETTYPE_AP},
  99. {NL80211_IFTYPE_P2P_CLIENT, WMI_NETTYPE_P2P},
  100. {NL80211_IFTYPE_P2P_GO, WMI_NETTYPE_P2P},
  101. {NL80211_IFTYPE_MONITOR, WMI_NETTYPE_ADHOC}, /* FIXME */
  102. };
  103. uint i;
  104. for (i = 0; i < ARRAY_SIZE(__nl2wmi); i++) {
  105. if (__nl2wmi[i].nl == type)
  106. return __nl2wmi[i].wmi;
  107. }
  108. return -EOPNOTSUPP;
  109. }
  110. int wil_cid_fill_sinfo(struct wil6210_priv *wil, int cid,
  111. struct station_info *sinfo)
  112. {
  113. struct wmi_notify_req_cmd cmd = {
  114. .cid = cid,
  115. .interval_usec = 0,
  116. };
  117. struct {
  118. struct wmi_cmd_hdr wmi;
  119. struct wmi_notify_req_done_event evt;
  120. } __packed reply;
  121. struct wil_net_stats *stats = &wil->sta[cid].stats;
  122. int rc;
  123. rc = wmi_call(wil, WMI_NOTIFY_REQ_CMDID, &cmd, sizeof(cmd),
  124. WMI_NOTIFY_REQ_DONE_EVENTID, &reply, sizeof(reply), 20);
  125. if (rc)
  126. return rc;
  127. wil_dbg_wmi(wil, "Link status for CID %d: {\n"
  128. " MCS %d TSF 0x%016llx\n"
  129. " BF status 0x%08x SNR 0x%08x SQI %d%%\n"
  130. " Tx Tpt %d goodput %d Rx goodput %d\n"
  131. " Sectors(rx:tx) my %d:%d peer %d:%d\n""}\n",
  132. cid, le16_to_cpu(reply.evt.bf_mcs),
  133. le64_to_cpu(reply.evt.tsf), reply.evt.status,
  134. le32_to_cpu(reply.evt.snr_val),
  135. reply.evt.sqi,
  136. le32_to_cpu(reply.evt.tx_tpt),
  137. le32_to_cpu(reply.evt.tx_goodput),
  138. le32_to_cpu(reply.evt.rx_goodput),
  139. le16_to_cpu(reply.evt.my_rx_sector),
  140. le16_to_cpu(reply.evt.my_tx_sector),
  141. le16_to_cpu(reply.evt.other_rx_sector),
  142. le16_to_cpu(reply.evt.other_tx_sector));
  143. sinfo->generation = wil->sinfo_gen;
  144. sinfo->filled = BIT(NL80211_STA_INFO_RX_BYTES) |
  145. BIT(NL80211_STA_INFO_TX_BYTES) |
  146. BIT(NL80211_STA_INFO_RX_PACKETS) |
  147. BIT(NL80211_STA_INFO_TX_PACKETS) |
  148. BIT(NL80211_STA_INFO_RX_BITRATE) |
  149. BIT(NL80211_STA_INFO_TX_BITRATE) |
  150. BIT(NL80211_STA_INFO_RX_DROP_MISC) |
  151. BIT(NL80211_STA_INFO_TX_FAILED);
  152. sinfo->txrate.flags = RATE_INFO_FLAGS_MCS | RATE_INFO_FLAGS_60G;
  153. sinfo->txrate.mcs = le16_to_cpu(reply.evt.bf_mcs);
  154. sinfo->rxrate.flags = RATE_INFO_FLAGS_MCS | RATE_INFO_FLAGS_60G;
  155. sinfo->rxrate.mcs = stats->last_mcs_rx;
  156. sinfo->rx_bytes = stats->rx_bytes;
  157. sinfo->rx_packets = stats->rx_packets;
  158. sinfo->rx_dropped_misc = stats->rx_dropped;
  159. sinfo->tx_bytes = stats->tx_bytes;
  160. sinfo->tx_packets = stats->tx_packets;
  161. sinfo->tx_failed = stats->tx_errors;
  162. if (test_bit(wil_status_fwconnected, wil->status)) {
  163. sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL);
  164. sinfo->signal = reply.evt.sqi;
  165. }
  166. return rc;
  167. }
  168. static int wil_cfg80211_get_station(struct wiphy *wiphy,
  169. struct net_device *ndev,
  170. const u8 *mac, struct station_info *sinfo)
  171. {
  172. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  173. int rc;
  174. int cid = wil_find_cid(wil, mac);
  175. wil_dbg_misc(wil, "%s(%pM) CID %d\n", __func__, mac, cid);
  176. if (cid < 0)
  177. return cid;
  178. rc = wil_cid_fill_sinfo(wil, cid, sinfo);
  179. return rc;
  180. }
  181. /*
  182. * Find @idx-th active STA for station dump.
  183. */
  184. static int wil_find_cid_by_idx(struct wil6210_priv *wil, int idx)
  185. {
  186. int i;
  187. for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
  188. if (wil->sta[i].status == wil_sta_unused)
  189. continue;
  190. if (idx == 0)
  191. return i;
  192. idx--;
  193. }
  194. return -ENOENT;
  195. }
  196. static int wil_cfg80211_dump_station(struct wiphy *wiphy,
  197. struct net_device *dev, int idx,
  198. u8 *mac, struct station_info *sinfo)
  199. {
  200. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  201. int rc;
  202. int cid = wil_find_cid_by_idx(wil, idx);
  203. if (cid < 0)
  204. return -ENOENT;
  205. ether_addr_copy(mac, wil->sta[cid].addr);
  206. wil_dbg_misc(wil, "%s(%pM) CID %d\n", __func__, mac, cid);
  207. rc = wil_cid_fill_sinfo(wil, cid, sinfo);
  208. return rc;
  209. }
  210. static struct wireless_dev *
  211. wil_cfg80211_add_iface(struct wiphy *wiphy, const char *name,
  212. unsigned char name_assign_type,
  213. enum nl80211_iftype type,
  214. u32 *flags, struct vif_params *params)
  215. {
  216. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  217. struct net_device *ndev = wil_to_ndev(wil);
  218. struct wireless_dev *p2p_wdev;
  219. wil_dbg_misc(wil, "%s()\n", __func__);
  220. if (type != NL80211_IFTYPE_P2P_DEVICE) {
  221. wil_err(wil, "%s: unsupported iftype %d\n", __func__, type);
  222. return ERR_PTR(-EINVAL);
  223. }
  224. if (wil->p2p_wdev) {
  225. wil_err(wil, "%s: P2P_DEVICE interface already created\n",
  226. __func__);
  227. return ERR_PTR(-EINVAL);
  228. }
  229. p2p_wdev = kzalloc(sizeof(*p2p_wdev), GFP_KERNEL);
  230. if (!p2p_wdev)
  231. return ERR_PTR(-ENOMEM);
  232. p2p_wdev->iftype = type;
  233. p2p_wdev->wiphy = wiphy;
  234. /* use our primary ethernet address */
  235. ether_addr_copy(p2p_wdev->address, ndev->perm_addr);
  236. wil->p2p_wdev = p2p_wdev;
  237. return p2p_wdev;
  238. }
  239. static int wil_cfg80211_del_iface(struct wiphy *wiphy,
  240. struct wireless_dev *wdev)
  241. {
  242. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  243. wil_dbg_misc(wil, "%s()\n", __func__);
  244. if (wdev != wil->p2p_wdev) {
  245. wil_err(wil, "%s: delete of incorrect interface 0x%p\n",
  246. __func__, wdev);
  247. return -EINVAL;
  248. }
  249. wil_p2p_wdev_free(wil);
  250. return 0;
  251. }
  252. static int wil_cfg80211_change_iface(struct wiphy *wiphy,
  253. struct net_device *ndev,
  254. enum nl80211_iftype type, u32 *flags,
  255. struct vif_params *params)
  256. {
  257. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  258. struct wireless_dev *wdev = wil_to_wdev(wil);
  259. int rc;
  260. wil_dbg_misc(wil, "%s() type=%d\n", __func__, type);
  261. if (netif_running(wil_to_ndev(wil)) && !wil_is_recovery_blocked(wil)) {
  262. wil_dbg_misc(wil, "interface is up. resetting...\n");
  263. mutex_lock(&wil->mutex);
  264. __wil_down(wil);
  265. rc = __wil_up(wil);
  266. mutex_unlock(&wil->mutex);
  267. if (rc)
  268. return rc;
  269. }
  270. switch (type) {
  271. case NL80211_IFTYPE_STATION:
  272. case NL80211_IFTYPE_AP:
  273. case NL80211_IFTYPE_P2P_CLIENT:
  274. case NL80211_IFTYPE_P2P_GO:
  275. break;
  276. case NL80211_IFTYPE_MONITOR:
  277. if (flags)
  278. wil->monitor_flags = *flags;
  279. else
  280. wil->monitor_flags = 0;
  281. break;
  282. default:
  283. return -EOPNOTSUPP;
  284. }
  285. wdev->iftype = type;
  286. return 0;
  287. }
  288. static int wil_cfg80211_scan(struct wiphy *wiphy,
  289. struct cfg80211_scan_request *request)
  290. {
  291. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  292. struct wireless_dev *wdev = request->wdev;
  293. struct {
  294. struct wmi_start_scan_cmd cmd;
  295. u16 chnl[4];
  296. } __packed cmd;
  297. uint i, n;
  298. int rc;
  299. wil_dbg_misc(wil, "%s(), wdev=0x%p iftype=%d\n",
  300. __func__, wdev, wdev->iftype);
  301. mutex_lock(&wil->p2p_wdev_mutex);
  302. if (wil->scan_request) {
  303. wil_err(wil, "Already scanning\n");
  304. mutex_unlock(&wil->p2p_wdev_mutex);
  305. return -EAGAIN;
  306. }
  307. mutex_unlock(&wil->p2p_wdev_mutex);
  308. /* check we are client side */
  309. switch (wdev->iftype) {
  310. case NL80211_IFTYPE_STATION:
  311. case NL80211_IFTYPE_P2P_CLIENT:
  312. case NL80211_IFTYPE_P2P_DEVICE:
  313. break;
  314. default:
  315. return -EOPNOTSUPP;
  316. }
  317. /* FW don't support scan after connection attempt */
  318. if (test_bit(wil_status_dontscan, wil->status)) {
  319. wil_err(wil, "Can't scan now\n");
  320. return -EBUSY;
  321. }
  322. /* social scan on P2P_DEVICE is handled as p2p search */
  323. if (wdev->iftype == NL80211_IFTYPE_P2P_DEVICE &&
  324. wil_p2p_is_social_scan(request)) {
  325. if (!wil->p2p.p2p_dev_started) {
  326. wil_err(wil, "P2P search requested on stopped P2P device\n");
  327. return -EIO;
  328. }
  329. wil->scan_request = request;
  330. wil->radio_wdev = wdev;
  331. rc = wil_p2p_search(wil, request);
  332. if (rc) {
  333. wil->radio_wdev = wil_to_wdev(wil);
  334. wil->scan_request = NULL;
  335. }
  336. return rc;
  337. }
  338. (void)wil_p2p_stop_discovery(wil);
  339. wil_dbg_misc(wil, "Start scan_request 0x%p\n", request);
  340. wil_dbg_misc(wil, "SSID count: %d", request->n_ssids);
  341. for (i = 0; i < request->n_ssids; i++) {
  342. wil_dbg_misc(wil, "SSID[%d]", i);
  343. print_hex_dump_bytes("SSID ", DUMP_PREFIX_OFFSET,
  344. request->ssids[i].ssid,
  345. request->ssids[i].ssid_len);
  346. }
  347. if (request->n_ssids)
  348. rc = wmi_set_ssid(wil, request->ssids[0].ssid_len,
  349. request->ssids[0].ssid);
  350. else
  351. rc = wmi_set_ssid(wil, 0, NULL);
  352. if (rc) {
  353. wil_err(wil, "set SSID for scan request failed: %d\n", rc);
  354. return rc;
  355. }
  356. wil->scan_request = request;
  357. mod_timer(&wil->scan_timer, jiffies + WIL6210_SCAN_TO);
  358. memset(&cmd, 0, sizeof(cmd));
  359. cmd.cmd.scan_type = WMI_ACTIVE_SCAN;
  360. cmd.cmd.num_channels = 0;
  361. n = min(request->n_channels, 4U);
  362. for (i = 0; i < n; i++) {
  363. int ch = request->channels[i]->hw_value;
  364. if (ch == 0) {
  365. wil_err(wil,
  366. "Scan requested for unknown frequency %dMhz\n",
  367. request->channels[i]->center_freq);
  368. continue;
  369. }
  370. /* 0-based channel indexes */
  371. cmd.cmd.channel_list[cmd.cmd.num_channels++].channel = ch - 1;
  372. wil_dbg_misc(wil, "Scan for ch %d : %d MHz\n", ch,
  373. request->channels[i]->center_freq);
  374. }
  375. if (request->ie_len)
  376. print_hex_dump_bytes("Scan IE ", DUMP_PREFIX_OFFSET,
  377. request->ie, request->ie_len);
  378. else
  379. wil_dbg_misc(wil, "Scan has no IE's\n");
  380. rc = wmi_set_ie(wil, WMI_FRAME_PROBE_REQ, request->ie_len, request->ie);
  381. if (rc)
  382. goto out;
  383. if (wil->discovery_mode && cmd.cmd.scan_type == WMI_ACTIVE_SCAN) {
  384. cmd.cmd.discovery_mode = 1;
  385. wil_dbg_misc(wil, "active scan with discovery_mode=1\n");
  386. }
  387. wil->radio_wdev = wdev;
  388. rc = wmi_send(wil, WMI_START_SCAN_CMDID, &cmd, sizeof(cmd.cmd) +
  389. cmd.cmd.num_channels * sizeof(cmd.cmd.channel_list[0]));
  390. out:
  391. if (rc) {
  392. del_timer_sync(&wil->scan_timer);
  393. wil->radio_wdev = wil_to_wdev(wil);
  394. wil->scan_request = NULL;
  395. }
  396. return rc;
  397. }
  398. static void wil_print_crypto(struct wil6210_priv *wil,
  399. struct cfg80211_crypto_settings *c)
  400. {
  401. int i, n;
  402. wil_dbg_misc(wil, "WPA versions: 0x%08x cipher group 0x%08x\n",
  403. c->wpa_versions, c->cipher_group);
  404. wil_dbg_misc(wil, "Pairwise ciphers [%d] {\n", c->n_ciphers_pairwise);
  405. n = min_t(int, c->n_ciphers_pairwise, ARRAY_SIZE(c->ciphers_pairwise));
  406. for (i = 0; i < n; i++)
  407. wil_dbg_misc(wil, " [%d] = 0x%08x\n", i,
  408. c->ciphers_pairwise[i]);
  409. wil_dbg_misc(wil, "}\n");
  410. wil_dbg_misc(wil, "AKM suites [%d] {\n", c->n_akm_suites);
  411. n = min_t(int, c->n_akm_suites, ARRAY_SIZE(c->akm_suites));
  412. for (i = 0; i < n; i++)
  413. wil_dbg_misc(wil, " [%d] = 0x%08x\n", i,
  414. c->akm_suites[i]);
  415. wil_dbg_misc(wil, "}\n");
  416. wil_dbg_misc(wil, "Control port : %d, eth_type 0x%04x no_encrypt %d\n",
  417. c->control_port, be16_to_cpu(c->control_port_ethertype),
  418. c->control_port_no_encrypt);
  419. }
  420. static void wil_print_connect_params(struct wil6210_priv *wil,
  421. struct cfg80211_connect_params *sme)
  422. {
  423. wil_info(wil, "Connecting to:\n");
  424. if (sme->channel) {
  425. wil_info(wil, " Channel: %d freq %d\n",
  426. sme->channel->hw_value, sme->channel->center_freq);
  427. }
  428. if (sme->bssid)
  429. wil_info(wil, " BSSID: %pM\n", sme->bssid);
  430. if (sme->ssid)
  431. print_hex_dump(KERN_INFO, " SSID: ", DUMP_PREFIX_OFFSET,
  432. 16, 1, sme->ssid, sme->ssid_len, true);
  433. wil_info(wil, " Privacy: %s\n", sme->privacy ? "secure" : "open");
  434. wil_info(wil, " PBSS: %d\n", sme->pbss);
  435. wil_print_crypto(wil, &sme->crypto);
  436. }
  437. static int wil_cfg80211_connect(struct wiphy *wiphy,
  438. struct net_device *ndev,
  439. struct cfg80211_connect_params *sme)
  440. {
  441. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  442. struct cfg80211_bss *bss;
  443. struct wmi_connect_cmd conn;
  444. const u8 *ssid_eid;
  445. const u8 *rsn_eid;
  446. int ch;
  447. int rc = 0;
  448. enum ieee80211_bss_type bss_type = IEEE80211_BSS_TYPE_ESS;
  449. wil_dbg_misc(wil, "%s()\n", __func__);
  450. wil_print_connect_params(wil, sme);
  451. if (test_bit(wil_status_fwconnecting, wil->status) ||
  452. test_bit(wil_status_fwconnected, wil->status))
  453. return -EALREADY;
  454. if (sme->ie_len > WMI_MAX_IE_LEN) {
  455. wil_err(wil, "IE too large (%td bytes)\n", sme->ie_len);
  456. return -ERANGE;
  457. }
  458. rsn_eid = sme->ie ?
  459. cfg80211_find_ie(WLAN_EID_RSN, sme->ie, sme->ie_len) :
  460. NULL;
  461. if (sme->privacy && !rsn_eid)
  462. wil_info(wil, "WSC connection\n");
  463. if (sme->pbss)
  464. bss_type = IEEE80211_BSS_TYPE_PBSS;
  465. bss = cfg80211_get_bss(wiphy, sme->channel, sme->bssid,
  466. sme->ssid, sme->ssid_len,
  467. bss_type, IEEE80211_PRIVACY_ANY);
  468. if (!bss) {
  469. wil_err(wil, "Unable to find BSS\n");
  470. return -ENOENT;
  471. }
  472. ssid_eid = ieee80211_bss_get_ie(bss, WLAN_EID_SSID);
  473. if (!ssid_eid) {
  474. wil_err(wil, "No SSID\n");
  475. rc = -ENOENT;
  476. goto out;
  477. }
  478. wil->privacy = sme->privacy;
  479. if (wil->privacy) {
  480. /* For secure assoc, remove old keys */
  481. rc = wmi_del_cipher_key(wil, 0, bss->bssid,
  482. WMI_KEY_USE_PAIRWISE);
  483. if (rc) {
  484. wil_err(wil, "WMI_DELETE_CIPHER_KEY_CMD(PTK) failed\n");
  485. goto out;
  486. }
  487. rc = wmi_del_cipher_key(wil, 0, bss->bssid,
  488. WMI_KEY_USE_RX_GROUP);
  489. if (rc) {
  490. wil_err(wil, "WMI_DELETE_CIPHER_KEY_CMD(GTK) failed\n");
  491. goto out;
  492. }
  493. }
  494. /* WMI_SET_APPIE_CMD. ie may contain rsn info as well as other info
  495. * elements. Send it also in case it's empty, to erase previously set
  496. * ies in FW.
  497. */
  498. rc = wmi_set_ie(wil, WMI_FRAME_ASSOC_REQ, sme->ie_len, sme->ie);
  499. if (rc)
  500. goto out;
  501. /* WMI_CONNECT_CMD */
  502. memset(&conn, 0, sizeof(conn));
  503. switch (bss->capability & WLAN_CAPABILITY_DMG_TYPE_MASK) {
  504. case WLAN_CAPABILITY_DMG_TYPE_AP:
  505. conn.network_type = WMI_NETTYPE_INFRA;
  506. break;
  507. case WLAN_CAPABILITY_DMG_TYPE_PBSS:
  508. conn.network_type = WMI_NETTYPE_P2P;
  509. break;
  510. default:
  511. wil_err(wil, "Unsupported BSS type, capability= 0x%04x\n",
  512. bss->capability);
  513. goto out;
  514. }
  515. if (wil->privacy) {
  516. if (rsn_eid) { /* regular secure connection */
  517. conn.dot11_auth_mode = WMI_AUTH11_SHARED;
  518. conn.auth_mode = WMI_AUTH_WPA2_PSK;
  519. conn.pairwise_crypto_type = WMI_CRYPT_AES_GCMP;
  520. conn.pairwise_crypto_len = 16;
  521. conn.group_crypto_type = WMI_CRYPT_AES_GCMP;
  522. conn.group_crypto_len = 16;
  523. } else { /* WSC */
  524. conn.dot11_auth_mode = WMI_AUTH11_WSC;
  525. conn.auth_mode = WMI_AUTH_NONE;
  526. }
  527. } else { /* insecure connection */
  528. conn.dot11_auth_mode = WMI_AUTH11_OPEN;
  529. conn.auth_mode = WMI_AUTH_NONE;
  530. }
  531. conn.ssid_len = min_t(u8, ssid_eid[1], 32);
  532. memcpy(conn.ssid, ssid_eid+2, conn.ssid_len);
  533. ch = bss->channel->hw_value;
  534. if (ch == 0) {
  535. wil_err(wil, "BSS at unknown frequency %dMhz\n",
  536. bss->channel->center_freq);
  537. rc = -EOPNOTSUPP;
  538. goto out;
  539. }
  540. conn.channel = ch - 1;
  541. ether_addr_copy(conn.bssid, bss->bssid);
  542. ether_addr_copy(conn.dst_mac, bss->bssid);
  543. set_bit(wil_status_fwconnecting, wil->status);
  544. rc = wmi_send(wil, WMI_CONNECT_CMDID, &conn, sizeof(conn));
  545. if (rc == 0) {
  546. netif_carrier_on(ndev);
  547. /* Connect can take lots of time */
  548. mod_timer(&wil->connect_timer,
  549. jiffies + msecs_to_jiffies(2000));
  550. } else {
  551. clear_bit(wil_status_fwconnecting, wil->status);
  552. }
  553. out:
  554. cfg80211_put_bss(wiphy, bss);
  555. return rc;
  556. }
  557. static int wil_cfg80211_disconnect(struct wiphy *wiphy,
  558. struct net_device *ndev,
  559. u16 reason_code)
  560. {
  561. int rc;
  562. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  563. wil_dbg_misc(wil, "%s(reason=%d)\n", __func__, reason_code);
  564. if (!(test_bit(wil_status_fwconnecting, wil->status) ||
  565. test_bit(wil_status_fwconnected, wil->status))) {
  566. wil_err(wil, "%s: Disconnect was called while disconnected\n",
  567. __func__);
  568. return 0;
  569. }
  570. rc = wmi_call(wil, WMI_DISCONNECT_CMDID, NULL, 0,
  571. WMI_DISCONNECT_EVENTID, NULL, 0,
  572. WIL6210_DISCONNECT_TO_MS);
  573. if (rc)
  574. wil_err(wil, "%s: disconnect error %d\n", __func__, rc);
  575. return rc;
  576. }
  577. int wil_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
  578. struct cfg80211_mgmt_tx_params *params,
  579. u64 *cookie)
  580. {
  581. const u8 *buf = params->buf;
  582. size_t len = params->len;
  583. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  584. int rc;
  585. bool tx_status = false;
  586. struct ieee80211_mgmt *mgmt_frame = (void *)buf;
  587. struct wmi_sw_tx_req_cmd *cmd;
  588. struct {
  589. struct wmi_cmd_hdr wmi;
  590. struct wmi_sw_tx_complete_event evt;
  591. } __packed evt;
  592. /* Note, currently we do not support the "wait" parameter, user-space
  593. * must call remain_on_channel before mgmt_tx or listen on a channel
  594. * another way (AP/PCP or connected station)
  595. * in addition we need to check if specified "chan" argument is
  596. * different from currently "listened" channel and fail if it is.
  597. */
  598. wil_dbg_misc(wil, "%s()\n", __func__);
  599. print_hex_dump_bytes("mgmt tx frame ", DUMP_PREFIX_OFFSET, buf, len);
  600. cmd = kmalloc(sizeof(*cmd) + len, GFP_KERNEL);
  601. if (!cmd) {
  602. rc = -ENOMEM;
  603. goto out;
  604. }
  605. memcpy(cmd->dst_mac, mgmt_frame->da, WMI_MAC_LEN);
  606. cmd->len = cpu_to_le16(len);
  607. memcpy(cmd->payload, buf, len);
  608. rc = wmi_call(wil, WMI_SW_TX_REQ_CMDID, cmd, sizeof(*cmd) + len,
  609. WMI_SW_TX_COMPLETE_EVENTID, &evt, sizeof(evt), 2000);
  610. if (rc == 0)
  611. tx_status = !evt.evt.status;
  612. kfree(cmd);
  613. out:
  614. cfg80211_mgmt_tx_status(wdev, cookie ? *cookie : 0, buf, len,
  615. tx_status, GFP_KERNEL);
  616. return rc;
  617. }
  618. static int wil_cfg80211_set_channel(struct wiphy *wiphy,
  619. struct cfg80211_chan_def *chandef)
  620. {
  621. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  622. struct wireless_dev *wdev = wil_to_wdev(wil);
  623. wdev->preset_chandef = *chandef;
  624. return 0;
  625. }
  626. static enum wmi_key_usage wil_detect_key_usage(struct wil6210_priv *wil,
  627. bool pairwise)
  628. {
  629. struct wireless_dev *wdev = wil_to_wdev(wil);
  630. enum wmi_key_usage rc;
  631. if (pairwise) {
  632. rc = WMI_KEY_USE_PAIRWISE;
  633. } else {
  634. switch (wdev->iftype) {
  635. case NL80211_IFTYPE_STATION:
  636. case NL80211_IFTYPE_P2P_CLIENT:
  637. rc = WMI_KEY_USE_RX_GROUP;
  638. break;
  639. case NL80211_IFTYPE_AP:
  640. case NL80211_IFTYPE_P2P_GO:
  641. rc = WMI_KEY_USE_TX_GROUP;
  642. break;
  643. default:
  644. /* TODO: Rx GTK or Tx GTK? */
  645. wil_err(wil, "Can't determine GTK type\n");
  646. rc = WMI_KEY_USE_RX_GROUP;
  647. break;
  648. }
  649. }
  650. wil_dbg_misc(wil, "%s() -> %s\n", __func__, key_usage_str[rc]);
  651. return rc;
  652. }
  653. static struct wil_sta_info *
  654. wil_find_sta_by_key_usage(struct wil6210_priv *wil,
  655. enum wmi_key_usage key_usage, const u8 *mac_addr)
  656. {
  657. int cid = -EINVAL;
  658. if (key_usage == WMI_KEY_USE_TX_GROUP)
  659. return NULL; /* not needed */
  660. /* supplicant provides Rx group key in STA mode with NULL MAC address */
  661. if (mac_addr)
  662. cid = wil_find_cid(wil, mac_addr);
  663. else if (key_usage == WMI_KEY_USE_RX_GROUP)
  664. cid = wil_find_cid_by_idx(wil, 0);
  665. if (cid < 0) {
  666. wil_err(wil, "No CID for %pM %s\n", mac_addr,
  667. key_usage_str[key_usage]);
  668. return ERR_PTR(cid);
  669. }
  670. return &wil->sta[cid];
  671. }
  672. static void wil_set_crypto_rx(u8 key_index, enum wmi_key_usage key_usage,
  673. struct wil_sta_info *cs,
  674. struct key_params *params)
  675. {
  676. struct wil_tid_crypto_rx_single *cc;
  677. int tid;
  678. if (!cs)
  679. return;
  680. switch (key_usage) {
  681. case WMI_KEY_USE_PAIRWISE:
  682. for (tid = 0; tid < WIL_STA_TID_NUM; tid++) {
  683. cc = &cs->tid_crypto_rx[tid].key_id[key_index];
  684. if (params->seq)
  685. memcpy(cc->pn, params->seq,
  686. IEEE80211_GCMP_PN_LEN);
  687. else
  688. memset(cc->pn, 0, IEEE80211_GCMP_PN_LEN);
  689. cc->key_set = true;
  690. }
  691. break;
  692. case WMI_KEY_USE_RX_GROUP:
  693. cc = &cs->group_crypto_rx.key_id[key_index];
  694. if (params->seq)
  695. memcpy(cc->pn, params->seq, IEEE80211_GCMP_PN_LEN);
  696. else
  697. memset(cc->pn, 0, IEEE80211_GCMP_PN_LEN);
  698. cc->key_set = true;
  699. break;
  700. default:
  701. break;
  702. }
  703. }
  704. static void wil_del_rx_key(u8 key_index, enum wmi_key_usage key_usage,
  705. struct wil_sta_info *cs)
  706. {
  707. struct wil_tid_crypto_rx_single *cc;
  708. int tid;
  709. if (!cs)
  710. return;
  711. switch (key_usage) {
  712. case WMI_KEY_USE_PAIRWISE:
  713. for (tid = 0; tid < WIL_STA_TID_NUM; tid++) {
  714. cc = &cs->tid_crypto_rx[tid].key_id[key_index];
  715. cc->key_set = false;
  716. }
  717. break;
  718. case WMI_KEY_USE_RX_GROUP:
  719. cc = &cs->group_crypto_rx.key_id[key_index];
  720. cc->key_set = false;
  721. break;
  722. default:
  723. break;
  724. }
  725. }
  726. static int wil_cfg80211_add_key(struct wiphy *wiphy,
  727. struct net_device *ndev,
  728. u8 key_index, bool pairwise,
  729. const u8 *mac_addr,
  730. struct key_params *params)
  731. {
  732. int rc;
  733. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  734. enum wmi_key_usage key_usage = wil_detect_key_usage(wil, pairwise);
  735. struct wil_sta_info *cs = wil_find_sta_by_key_usage(wil, key_usage,
  736. mac_addr);
  737. if (!params) {
  738. wil_err(wil, "NULL params\n");
  739. return -EINVAL;
  740. }
  741. wil_dbg_misc(wil, "%s(%pM %s[%d] PN %*phN)\n", __func__,
  742. mac_addr, key_usage_str[key_usage], key_index,
  743. params->seq_len, params->seq);
  744. if (IS_ERR(cs)) {
  745. wil_err(wil, "Not connected, %s(%pM %s[%d] PN %*phN)\n",
  746. __func__, mac_addr, key_usage_str[key_usage], key_index,
  747. params->seq_len, params->seq);
  748. return -EINVAL;
  749. }
  750. wil_del_rx_key(key_index, key_usage, cs);
  751. if (params->seq && params->seq_len != IEEE80211_GCMP_PN_LEN) {
  752. wil_err(wil,
  753. "Wrong PN len %d, %s(%pM %s[%d] PN %*phN)\n",
  754. params->seq_len, __func__, mac_addr,
  755. key_usage_str[key_usage], key_index,
  756. params->seq_len, params->seq);
  757. return -EINVAL;
  758. }
  759. rc = wmi_add_cipher_key(wil, key_index, mac_addr, params->key_len,
  760. params->key, key_usage);
  761. if (!rc)
  762. wil_set_crypto_rx(key_index, key_usage, cs, params);
  763. return rc;
  764. }
  765. static int wil_cfg80211_del_key(struct wiphy *wiphy,
  766. struct net_device *ndev,
  767. u8 key_index, bool pairwise,
  768. const u8 *mac_addr)
  769. {
  770. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  771. enum wmi_key_usage key_usage = wil_detect_key_usage(wil, pairwise);
  772. struct wil_sta_info *cs = wil_find_sta_by_key_usage(wil, key_usage,
  773. mac_addr);
  774. wil_dbg_misc(wil, "%s(%pM %s[%d])\n", __func__, mac_addr,
  775. key_usage_str[key_usage], key_index);
  776. if (IS_ERR(cs))
  777. wil_info(wil, "Not connected, %s(%pM %s[%d])\n", __func__,
  778. mac_addr, key_usage_str[key_usage], key_index);
  779. if (!IS_ERR_OR_NULL(cs))
  780. wil_del_rx_key(key_index, key_usage, cs);
  781. return wmi_del_cipher_key(wil, key_index, mac_addr, key_usage);
  782. }
  783. /* Need to be present or wiphy_new() will WARN */
  784. static int wil_cfg80211_set_default_key(struct wiphy *wiphy,
  785. struct net_device *ndev,
  786. u8 key_index, bool unicast,
  787. bool multicast)
  788. {
  789. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  790. wil_dbg_misc(wil, "%s: entered\n", __func__);
  791. return 0;
  792. }
  793. static int wil_remain_on_channel(struct wiphy *wiphy,
  794. struct wireless_dev *wdev,
  795. struct ieee80211_channel *chan,
  796. unsigned int duration,
  797. u64 *cookie)
  798. {
  799. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  800. int rc;
  801. wil_dbg_misc(wil, "%s() center_freq=%d, duration=%d iftype=%d\n",
  802. __func__, chan->center_freq, duration, wdev->iftype);
  803. rc = wil_p2p_listen(wil, duration, chan, cookie);
  804. if (rc)
  805. return rc;
  806. wil->radio_wdev = wdev;
  807. cfg80211_ready_on_channel(wdev, *cookie, chan, duration,
  808. GFP_KERNEL);
  809. return 0;
  810. }
  811. static int wil_cancel_remain_on_channel(struct wiphy *wiphy,
  812. struct wireless_dev *wdev,
  813. u64 cookie)
  814. {
  815. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  816. wil_dbg_misc(wil, "%s()\n", __func__);
  817. return wil_p2p_cancel_listen(wil, cookie);
  818. }
  819. /**
  820. * find a specific IE in a list of IEs
  821. * return a pointer to the beginning of IE in the list
  822. * or NULL if not found
  823. */
  824. static const u8 *_wil_cfg80211_find_ie(const u8 *ies, u16 ies_len, const u8 *ie,
  825. u16 ie_len)
  826. {
  827. struct ieee80211_vendor_ie *vie;
  828. u32 oui;
  829. /* IE tag at offset 0, length at offset 1 */
  830. if (ie_len < 2 || 2 + ie[1] > ie_len)
  831. return NULL;
  832. if (ie[0] != WLAN_EID_VENDOR_SPECIFIC)
  833. return cfg80211_find_ie(ie[0], ies, ies_len);
  834. /* make sure there is room for 3 bytes OUI + 1 byte OUI type */
  835. if (ie[1] < 4)
  836. return NULL;
  837. vie = (struct ieee80211_vendor_ie *)ie;
  838. oui = vie->oui[0] << 16 | vie->oui[1] << 8 | vie->oui[2];
  839. return cfg80211_find_vendor_ie(oui, vie->oui_type, ies,
  840. ies_len);
  841. }
  842. /**
  843. * merge the IEs in two lists into a single list.
  844. * do not include IEs from the second list which exist in the first list.
  845. * add only vendor specific IEs from second list to keep
  846. * the merged list sorted (since vendor-specific IE has the
  847. * highest tag number)
  848. * caller must free the allocated memory for merged IEs
  849. */
  850. static int _wil_cfg80211_merge_extra_ies(const u8 *ies1, u16 ies1_len,
  851. const u8 *ies2, u16 ies2_len,
  852. u8 **merged_ies, u16 *merged_len)
  853. {
  854. u8 *buf, *dpos;
  855. const u8 *spos;
  856. if (ies1_len == 0 && ies2_len == 0) {
  857. *merged_ies = NULL;
  858. *merged_len = 0;
  859. return 0;
  860. }
  861. buf = kmalloc(ies1_len + ies2_len, GFP_KERNEL);
  862. if (!buf)
  863. return -ENOMEM;
  864. memcpy(buf, ies1, ies1_len);
  865. dpos = buf + ies1_len;
  866. spos = ies2;
  867. while (spos + 1 < ies2 + ies2_len) {
  868. /* IE tag at offset 0, length at offset 1 */
  869. u16 ielen = 2 + spos[1];
  870. if (spos + ielen > ies2 + ies2_len)
  871. break;
  872. if (spos[0] == WLAN_EID_VENDOR_SPECIFIC &&
  873. !_wil_cfg80211_find_ie(ies1, ies1_len, spos, ielen)) {
  874. memcpy(dpos, spos, ielen);
  875. dpos += ielen;
  876. }
  877. spos += ielen;
  878. }
  879. *merged_ies = buf;
  880. *merged_len = dpos - buf;
  881. return 0;
  882. }
  883. static void wil_print_bcon_data(struct cfg80211_beacon_data *b)
  884. {
  885. print_hex_dump_bytes("head ", DUMP_PREFIX_OFFSET,
  886. b->head, b->head_len);
  887. print_hex_dump_bytes("tail ", DUMP_PREFIX_OFFSET,
  888. b->tail, b->tail_len);
  889. print_hex_dump_bytes("BCON IE ", DUMP_PREFIX_OFFSET,
  890. b->beacon_ies, b->beacon_ies_len);
  891. print_hex_dump_bytes("PROBE ", DUMP_PREFIX_OFFSET,
  892. b->probe_resp, b->probe_resp_len);
  893. print_hex_dump_bytes("PROBE IE ", DUMP_PREFIX_OFFSET,
  894. b->proberesp_ies, b->proberesp_ies_len);
  895. print_hex_dump_bytes("ASSOC IE ", DUMP_PREFIX_OFFSET,
  896. b->assocresp_ies, b->assocresp_ies_len);
  897. }
  898. /* internal functions for device reset and starting AP */
  899. static int _wil_cfg80211_set_ies(struct wiphy *wiphy,
  900. struct cfg80211_beacon_data *bcon)
  901. {
  902. int rc;
  903. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  904. u16 len = 0, proberesp_len = 0;
  905. u8 *ies = NULL, *proberesp = NULL;
  906. if (bcon->probe_resp) {
  907. struct ieee80211_mgmt *f =
  908. (struct ieee80211_mgmt *)bcon->probe_resp;
  909. size_t hlen = offsetof(struct ieee80211_mgmt,
  910. u.probe_resp.variable);
  911. proberesp = f->u.probe_resp.variable;
  912. proberesp_len = bcon->probe_resp_len - hlen;
  913. }
  914. rc = _wil_cfg80211_merge_extra_ies(proberesp,
  915. proberesp_len,
  916. bcon->proberesp_ies,
  917. bcon->proberesp_ies_len,
  918. &ies, &len);
  919. if (rc)
  920. goto out;
  921. rc = wmi_set_ie(wil, WMI_FRAME_PROBE_RESP, len, ies);
  922. if (rc)
  923. goto out;
  924. if (bcon->assocresp_ies)
  925. rc = wmi_set_ie(wil, WMI_FRAME_ASSOC_RESP,
  926. bcon->assocresp_ies_len, bcon->assocresp_ies);
  927. else
  928. rc = wmi_set_ie(wil, WMI_FRAME_ASSOC_RESP, len, ies);
  929. #if 0 /* to use beacon IE's, remove this #if 0 */
  930. if (rc)
  931. goto out;
  932. rc = wmi_set_ie(wil, WMI_FRAME_BEACON, bcon->tail_len, bcon->tail);
  933. #endif
  934. out:
  935. kfree(ies);
  936. return rc;
  937. }
  938. static int _wil_cfg80211_start_ap(struct wiphy *wiphy,
  939. struct net_device *ndev,
  940. const u8 *ssid, size_t ssid_len, u32 privacy,
  941. int bi, u8 chan,
  942. struct cfg80211_beacon_data *bcon,
  943. u8 hidden_ssid, u32 pbss)
  944. {
  945. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  946. int rc;
  947. struct wireless_dev *wdev = ndev->ieee80211_ptr;
  948. u8 wmi_nettype = wil_iftype_nl2wmi(wdev->iftype);
  949. u8 is_go = (wdev->iftype == NL80211_IFTYPE_P2P_GO);
  950. if (pbss)
  951. wmi_nettype = WMI_NETTYPE_P2P;
  952. wil_dbg_misc(wil, "%s: is_go=%d\n", __func__, is_go);
  953. if (is_go && !pbss) {
  954. wil_err(wil, "%s: P2P GO must be in PBSS\n", __func__);
  955. return -ENOTSUPP;
  956. }
  957. wil_set_recovery_state(wil, fw_recovery_idle);
  958. mutex_lock(&wil->mutex);
  959. __wil_down(wil);
  960. rc = __wil_up(wil);
  961. if (rc)
  962. goto out;
  963. rc = wmi_set_ssid(wil, ssid_len, ssid);
  964. if (rc)
  965. goto out;
  966. rc = _wil_cfg80211_set_ies(wiphy, bcon);
  967. if (rc)
  968. goto out;
  969. wil->privacy = privacy;
  970. wil->channel = chan;
  971. wil->hidden_ssid = hidden_ssid;
  972. wil->pbss = pbss;
  973. netif_carrier_on(ndev);
  974. rc = wmi_pcp_start(wil, bi, wmi_nettype, chan, hidden_ssid, is_go);
  975. if (rc)
  976. goto err_pcp_start;
  977. rc = wil_bcast_init(wil);
  978. if (rc)
  979. goto err_bcast;
  980. goto out; /* success */
  981. err_bcast:
  982. wmi_pcp_stop(wil);
  983. err_pcp_start:
  984. netif_carrier_off(ndev);
  985. out:
  986. mutex_unlock(&wil->mutex);
  987. return rc;
  988. }
  989. static int wil_cfg80211_change_beacon(struct wiphy *wiphy,
  990. struct net_device *ndev,
  991. struct cfg80211_beacon_data *bcon)
  992. {
  993. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  994. int rc;
  995. u32 privacy = 0;
  996. wil_dbg_misc(wil, "%s()\n", __func__);
  997. wil_print_bcon_data(bcon);
  998. if (bcon->tail &&
  999. cfg80211_find_ie(WLAN_EID_RSN, bcon->tail,
  1000. bcon->tail_len))
  1001. privacy = 1;
  1002. /* in case privacy has changed, need to restart the AP */
  1003. if (wil->privacy != privacy) {
  1004. struct wireless_dev *wdev = ndev->ieee80211_ptr;
  1005. wil_dbg_misc(wil, "privacy changed %d=>%d. Restarting AP\n",
  1006. wil->privacy, privacy);
  1007. rc = _wil_cfg80211_start_ap(wiphy, ndev, wdev->ssid,
  1008. wdev->ssid_len, privacy,
  1009. wdev->beacon_interval,
  1010. wil->channel, bcon,
  1011. wil->hidden_ssid,
  1012. wil->pbss);
  1013. } else {
  1014. rc = _wil_cfg80211_set_ies(wiphy, bcon);
  1015. }
  1016. return rc;
  1017. }
  1018. static int wil_cfg80211_start_ap(struct wiphy *wiphy,
  1019. struct net_device *ndev,
  1020. struct cfg80211_ap_settings *info)
  1021. {
  1022. int rc;
  1023. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  1024. struct ieee80211_channel *channel = info->chandef.chan;
  1025. struct cfg80211_beacon_data *bcon = &info->beacon;
  1026. struct cfg80211_crypto_settings *crypto = &info->crypto;
  1027. u8 hidden_ssid;
  1028. wil_dbg_misc(wil, "%s()\n", __func__);
  1029. if (!channel) {
  1030. wil_err(wil, "AP: No channel???\n");
  1031. return -EINVAL;
  1032. }
  1033. switch (info->hidden_ssid) {
  1034. case NL80211_HIDDEN_SSID_NOT_IN_USE:
  1035. hidden_ssid = WMI_HIDDEN_SSID_DISABLED;
  1036. break;
  1037. case NL80211_HIDDEN_SSID_ZERO_LEN:
  1038. hidden_ssid = WMI_HIDDEN_SSID_SEND_EMPTY;
  1039. break;
  1040. case NL80211_HIDDEN_SSID_ZERO_CONTENTS:
  1041. hidden_ssid = WMI_HIDDEN_SSID_CLEAR;
  1042. break;
  1043. default:
  1044. wil_err(wil, "AP: Invalid hidden SSID %d\n", info->hidden_ssid);
  1045. return -EOPNOTSUPP;
  1046. }
  1047. wil_dbg_misc(wil, "AP on Channel %d %d MHz, %s\n", channel->hw_value,
  1048. channel->center_freq, info->privacy ? "secure" : "open");
  1049. wil_dbg_misc(wil, "Privacy: %d auth_type %d\n",
  1050. info->privacy, info->auth_type);
  1051. wil_dbg_misc(wil, "Hidden SSID mode: %d\n",
  1052. info->hidden_ssid);
  1053. wil_dbg_misc(wil, "BI %d DTIM %d\n", info->beacon_interval,
  1054. info->dtim_period);
  1055. wil_dbg_misc(wil, "PBSS %d\n", info->pbss);
  1056. print_hex_dump_bytes("SSID ", DUMP_PREFIX_OFFSET,
  1057. info->ssid, info->ssid_len);
  1058. wil_print_bcon_data(bcon);
  1059. wil_print_crypto(wil, crypto);
  1060. rc = _wil_cfg80211_start_ap(wiphy, ndev,
  1061. info->ssid, info->ssid_len, info->privacy,
  1062. info->beacon_interval, channel->hw_value,
  1063. bcon, hidden_ssid, info->pbss);
  1064. return rc;
  1065. }
  1066. static int wil_cfg80211_stop_ap(struct wiphy *wiphy,
  1067. struct net_device *ndev)
  1068. {
  1069. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  1070. wil_dbg_misc(wil, "%s()\n", __func__);
  1071. netif_carrier_off(ndev);
  1072. wil_set_recovery_state(wil, fw_recovery_idle);
  1073. mutex_lock(&wil->mutex);
  1074. wmi_pcp_stop(wil);
  1075. __wil_down(wil);
  1076. mutex_unlock(&wil->mutex);
  1077. return 0;
  1078. }
  1079. static int wil_cfg80211_del_station(struct wiphy *wiphy,
  1080. struct net_device *dev,
  1081. struct station_del_parameters *params)
  1082. {
  1083. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  1084. wil_dbg_misc(wil, "%s(%pM, reason=%d)\n", __func__, params->mac,
  1085. params->reason_code);
  1086. mutex_lock(&wil->mutex);
  1087. wil6210_disconnect(wil, params->mac, params->reason_code, false);
  1088. mutex_unlock(&wil->mutex);
  1089. return 0;
  1090. }
  1091. /* probe_client handling */
  1092. static void wil_probe_client_handle(struct wil6210_priv *wil,
  1093. struct wil_probe_client_req *req)
  1094. {
  1095. struct net_device *ndev = wil_to_ndev(wil);
  1096. struct wil_sta_info *sta = &wil->sta[req->cid];
  1097. /* assume STA is alive if it is still connected,
  1098. * else FW will disconnect it
  1099. */
  1100. bool alive = (sta->status == wil_sta_connected);
  1101. cfg80211_probe_status(ndev, sta->addr, req->cookie, alive, GFP_KERNEL);
  1102. }
  1103. static struct list_head *next_probe_client(struct wil6210_priv *wil)
  1104. {
  1105. struct list_head *ret = NULL;
  1106. mutex_lock(&wil->probe_client_mutex);
  1107. if (!list_empty(&wil->probe_client_pending)) {
  1108. ret = wil->probe_client_pending.next;
  1109. list_del(ret);
  1110. }
  1111. mutex_unlock(&wil->probe_client_mutex);
  1112. return ret;
  1113. }
  1114. void wil_probe_client_worker(struct work_struct *work)
  1115. {
  1116. struct wil6210_priv *wil = container_of(work, struct wil6210_priv,
  1117. probe_client_worker);
  1118. struct wil_probe_client_req *req;
  1119. struct list_head *lh;
  1120. while ((lh = next_probe_client(wil)) != NULL) {
  1121. req = list_entry(lh, struct wil_probe_client_req, list);
  1122. wil_probe_client_handle(wil, req);
  1123. kfree(req);
  1124. }
  1125. }
  1126. void wil_probe_client_flush(struct wil6210_priv *wil)
  1127. {
  1128. struct wil_probe_client_req *req, *t;
  1129. wil_dbg_misc(wil, "%s()\n", __func__);
  1130. mutex_lock(&wil->probe_client_mutex);
  1131. list_for_each_entry_safe(req, t, &wil->probe_client_pending, list) {
  1132. list_del(&req->list);
  1133. kfree(req);
  1134. }
  1135. mutex_unlock(&wil->probe_client_mutex);
  1136. }
  1137. static int wil_cfg80211_probe_client(struct wiphy *wiphy,
  1138. struct net_device *dev,
  1139. const u8 *peer, u64 *cookie)
  1140. {
  1141. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  1142. struct wil_probe_client_req *req;
  1143. int cid = wil_find_cid(wil, peer);
  1144. wil_dbg_misc(wil, "%s(%pM => CID %d)\n", __func__, peer, cid);
  1145. if (cid < 0)
  1146. return -ENOLINK;
  1147. req = kzalloc(sizeof(*req), GFP_KERNEL);
  1148. if (!req)
  1149. return -ENOMEM;
  1150. req->cid = cid;
  1151. req->cookie = cid;
  1152. mutex_lock(&wil->probe_client_mutex);
  1153. list_add_tail(&req->list, &wil->probe_client_pending);
  1154. mutex_unlock(&wil->probe_client_mutex);
  1155. *cookie = req->cookie;
  1156. queue_work(wil->wq_service, &wil->probe_client_worker);
  1157. return 0;
  1158. }
  1159. static int wil_cfg80211_change_bss(struct wiphy *wiphy,
  1160. struct net_device *dev,
  1161. struct bss_parameters *params)
  1162. {
  1163. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  1164. if (params->ap_isolate >= 0) {
  1165. wil_dbg_misc(wil, "%s(ap_isolate %d => %d)\n", __func__,
  1166. wil->ap_isolate, params->ap_isolate);
  1167. wil->ap_isolate = params->ap_isolate;
  1168. }
  1169. return 0;
  1170. }
  1171. static int wil_cfg80211_start_p2p_device(struct wiphy *wiphy,
  1172. struct wireless_dev *wdev)
  1173. {
  1174. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  1175. wil_dbg_misc(wil, "%s: entered\n", __func__);
  1176. wil->p2p.p2p_dev_started = 1;
  1177. return 0;
  1178. }
  1179. static void wil_cfg80211_stop_p2p_device(struct wiphy *wiphy,
  1180. struct wireless_dev *wdev)
  1181. {
  1182. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  1183. struct wil_p2p_info *p2p = &wil->p2p;
  1184. if (!p2p->p2p_dev_started)
  1185. return;
  1186. wil_dbg_misc(wil, "%s: entered\n", __func__);
  1187. mutex_lock(&wil->mutex);
  1188. wil_p2p_stop_radio_operations(wil);
  1189. p2p->p2p_dev_started = 0;
  1190. mutex_unlock(&wil->mutex);
  1191. }
  1192. static struct cfg80211_ops wil_cfg80211_ops = {
  1193. .add_virtual_intf = wil_cfg80211_add_iface,
  1194. .del_virtual_intf = wil_cfg80211_del_iface,
  1195. .scan = wil_cfg80211_scan,
  1196. .connect = wil_cfg80211_connect,
  1197. .disconnect = wil_cfg80211_disconnect,
  1198. .change_virtual_intf = wil_cfg80211_change_iface,
  1199. .get_station = wil_cfg80211_get_station,
  1200. .dump_station = wil_cfg80211_dump_station,
  1201. .remain_on_channel = wil_remain_on_channel,
  1202. .cancel_remain_on_channel = wil_cancel_remain_on_channel,
  1203. .mgmt_tx = wil_cfg80211_mgmt_tx,
  1204. .set_monitor_channel = wil_cfg80211_set_channel,
  1205. .add_key = wil_cfg80211_add_key,
  1206. .del_key = wil_cfg80211_del_key,
  1207. .set_default_key = wil_cfg80211_set_default_key,
  1208. /* AP mode */
  1209. .change_beacon = wil_cfg80211_change_beacon,
  1210. .start_ap = wil_cfg80211_start_ap,
  1211. .stop_ap = wil_cfg80211_stop_ap,
  1212. .del_station = wil_cfg80211_del_station,
  1213. .probe_client = wil_cfg80211_probe_client,
  1214. .change_bss = wil_cfg80211_change_bss,
  1215. /* P2P device */
  1216. .start_p2p_device = wil_cfg80211_start_p2p_device,
  1217. .stop_p2p_device = wil_cfg80211_stop_p2p_device,
  1218. };
  1219. static void wil_wiphy_init(struct wiphy *wiphy)
  1220. {
  1221. wiphy->max_scan_ssids = 1;
  1222. wiphy->max_scan_ie_len = WMI_MAX_IE_LEN;
  1223. wiphy->max_remain_on_channel_duration = WIL_MAX_ROC_DURATION_MS;
  1224. wiphy->max_num_pmkids = 0 /* TODO: */;
  1225. wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
  1226. BIT(NL80211_IFTYPE_AP) |
  1227. BIT(NL80211_IFTYPE_P2P_CLIENT) |
  1228. BIT(NL80211_IFTYPE_P2P_GO) |
  1229. BIT(NL80211_IFTYPE_P2P_DEVICE) |
  1230. BIT(NL80211_IFTYPE_MONITOR);
  1231. wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME |
  1232. WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL |
  1233. WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
  1234. dev_dbg(wiphy_dev(wiphy), "%s : flags = 0x%08x\n",
  1235. __func__, wiphy->flags);
  1236. wiphy->probe_resp_offload =
  1237. NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
  1238. NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
  1239. NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
  1240. wiphy->bands[NL80211_BAND_60GHZ] = &wil_band_60ghz;
  1241. /* TODO: figure this out */
  1242. wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC;
  1243. wiphy->cipher_suites = wil_cipher_suites;
  1244. wiphy->n_cipher_suites = ARRAY_SIZE(wil_cipher_suites);
  1245. wiphy->mgmt_stypes = wil_mgmt_stypes;
  1246. wiphy->features |= NL80211_FEATURE_SK_TX_STATUS;
  1247. }
  1248. struct wireless_dev *wil_cfg80211_init(struct device *dev)
  1249. {
  1250. int rc = 0;
  1251. struct wireless_dev *wdev;
  1252. dev_dbg(dev, "%s()\n", __func__);
  1253. wdev = kzalloc(sizeof(*wdev), GFP_KERNEL);
  1254. if (!wdev)
  1255. return ERR_PTR(-ENOMEM);
  1256. wdev->wiphy = wiphy_new(&wil_cfg80211_ops,
  1257. sizeof(struct wil6210_priv));
  1258. if (!wdev->wiphy) {
  1259. rc = -ENOMEM;
  1260. goto out;
  1261. }
  1262. set_wiphy_dev(wdev->wiphy, dev);
  1263. wil_wiphy_init(wdev->wiphy);
  1264. return wdev;
  1265. out:
  1266. kfree(wdev);
  1267. return ERR_PTR(rc);
  1268. }
  1269. void wil_wdev_free(struct wil6210_priv *wil)
  1270. {
  1271. struct wireless_dev *wdev = wil_to_wdev(wil);
  1272. dev_dbg(wil_to_dev(wil), "%s()\n", __func__);
  1273. if (!wdev)
  1274. return;
  1275. wiphy_free(wdev->wiphy);
  1276. kfree(wdev);
  1277. }
  1278. void wil_p2p_wdev_free(struct wil6210_priv *wil)
  1279. {
  1280. struct wireless_dev *p2p_wdev;
  1281. mutex_lock(&wil->p2p_wdev_mutex);
  1282. p2p_wdev = wil->p2p_wdev;
  1283. wil->p2p_wdev = NULL;
  1284. wil->radio_wdev = wil_to_wdev(wil);
  1285. mutex_unlock(&wil->p2p_wdev_mutex);
  1286. if (p2p_wdev) {
  1287. cfg80211_unregister_wdev(p2p_wdev);
  1288. kfree(p2p_wdev);
  1289. }
  1290. }