cfg80211.c 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508
  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. if (wil->scan_request) {
  302. wil_err(wil, "Already scanning\n");
  303. return -EAGAIN;
  304. }
  305. /* check we are client side */
  306. switch (wdev->iftype) {
  307. case NL80211_IFTYPE_STATION:
  308. case NL80211_IFTYPE_P2P_CLIENT:
  309. case NL80211_IFTYPE_P2P_DEVICE:
  310. break;
  311. default:
  312. return -EOPNOTSUPP;
  313. }
  314. /* FW don't support scan after connection attempt */
  315. if (test_bit(wil_status_dontscan, wil->status)) {
  316. wil_err(wil, "Can't scan now\n");
  317. return -EBUSY;
  318. }
  319. /* social scan on P2P_DEVICE is handled as p2p search */
  320. if (wdev->iftype == NL80211_IFTYPE_P2P_DEVICE &&
  321. wil_p2p_is_social_scan(request)) {
  322. if (!wil->p2p.p2p_dev_started) {
  323. wil_err(wil, "P2P search requested on stopped P2P device\n");
  324. return -EIO;
  325. }
  326. wil->scan_request = request;
  327. wil->radio_wdev = wdev;
  328. rc = wil_p2p_search(wil, request);
  329. if (rc) {
  330. wil->radio_wdev = wil_to_wdev(wil);
  331. wil->scan_request = NULL;
  332. }
  333. return rc;
  334. }
  335. (void)wil_p2p_stop_discovery(wil);
  336. wil_dbg_misc(wil, "Start scan_request 0x%p\n", request);
  337. wil_dbg_misc(wil, "SSID count: %d", request->n_ssids);
  338. for (i = 0; i < request->n_ssids; i++) {
  339. wil_dbg_misc(wil, "SSID[%d]", i);
  340. print_hex_dump_bytes("SSID ", DUMP_PREFIX_OFFSET,
  341. request->ssids[i].ssid,
  342. request->ssids[i].ssid_len);
  343. }
  344. if (request->n_ssids)
  345. rc = wmi_set_ssid(wil, request->ssids[0].ssid_len,
  346. request->ssids[0].ssid);
  347. else
  348. rc = wmi_set_ssid(wil, 0, NULL);
  349. if (rc) {
  350. wil_err(wil, "set SSID for scan request failed: %d\n", rc);
  351. return rc;
  352. }
  353. wil->scan_request = request;
  354. mod_timer(&wil->scan_timer, jiffies + WIL6210_SCAN_TO);
  355. memset(&cmd, 0, sizeof(cmd));
  356. cmd.cmd.scan_type = WMI_ACTIVE_SCAN;
  357. cmd.cmd.num_channels = 0;
  358. n = min(request->n_channels, 4U);
  359. for (i = 0; i < n; i++) {
  360. int ch = request->channels[i]->hw_value;
  361. if (ch == 0) {
  362. wil_err(wil,
  363. "Scan requested for unknown frequency %dMhz\n",
  364. request->channels[i]->center_freq);
  365. continue;
  366. }
  367. /* 0-based channel indexes */
  368. cmd.cmd.channel_list[cmd.cmd.num_channels++].channel = ch - 1;
  369. wil_dbg_misc(wil, "Scan for ch %d : %d MHz\n", ch,
  370. request->channels[i]->center_freq);
  371. }
  372. if (request->ie_len)
  373. print_hex_dump_bytes("Scan IE ", DUMP_PREFIX_OFFSET,
  374. request->ie, request->ie_len);
  375. else
  376. wil_dbg_misc(wil, "Scan has no IE's\n");
  377. rc = wmi_set_ie(wil, WMI_FRAME_PROBE_REQ, request->ie_len, request->ie);
  378. if (rc)
  379. goto out;
  380. if (wil->discovery_mode && cmd.cmd.scan_type == WMI_ACTIVE_SCAN) {
  381. cmd.cmd.discovery_mode = 1;
  382. wil_dbg_misc(wil, "active scan with discovery_mode=1\n");
  383. }
  384. wil->radio_wdev = wdev;
  385. rc = wmi_send(wil, WMI_START_SCAN_CMDID, &cmd, sizeof(cmd.cmd) +
  386. cmd.cmd.num_channels * sizeof(cmd.cmd.channel_list[0]));
  387. out:
  388. if (rc) {
  389. del_timer_sync(&wil->scan_timer);
  390. wil->radio_wdev = wil_to_wdev(wil);
  391. wil->scan_request = NULL;
  392. }
  393. return rc;
  394. }
  395. static void wil_print_crypto(struct wil6210_priv *wil,
  396. struct cfg80211_crypto_settings *c)
  397. {
  398. int i, n;
  399. wil_dbg_misc(wil, "WPA versions: 0x%08x cipher group 0x%08x\n",
  400. c->wpa_versions, c->cipher_group);
  401. wil_dbg_misc(wil, "Pairwise ciphers [%d] {\n", c->n_ciphers_pairwise);
  402. n = min_t(int, c->n_ciphers_pairwise, ARRAY_SIZE(c->ciphers_pairwise));
  403. for (i = 0; i < n; i++)
  404. wil_dbg_misc(wil, " [%d] = 0x%08x\n", i,
  405. c->ciphers_pairwise[i]);
  406. wil_dbg_misc(wil, "}\n");
  407. wil_dbg_misc(wil, "AKM suites [%d] {\n", c->n_akm_suites);
  408. n = min_t(int, c->n_akm_suites, ARRAY_SIZE(c->akm_suites));
  409. for (i = 0; i < n; i++)
  410. wil_dbg_misc(wil, " [%d] = 0x%08x\n", i,
  411. c->akm_suites[i]);
  412. wil_dbg_misc(wil, "}\n");
  413. wil_dbg_misc(wil, "Control port : %d, eth_type 0x%04x no_encrypt %d\n",
  414. c->control_port, be16_to_cpu(c->control_port_ethertype),
  415. c->control_port_no_encrypt);
  416. }
  417. static void wil_print_connect_params(struct wil6210_priv *wil,
  418. struct cfg80211_connect_params *sme)
  419. {
  420. wil_info(wil, "Connecting to:\n");
  421. if (sme->channel) {
  422. wil_info(wil, " Channel: %d freq %d\n",
  423. sme->channel->hw_value, sme->channel->center_freq);
  424. }
  425. if (sme->bssid)
  426. wil_info(wil, " BSSID: %pM\n", sme->bssid);
  427. if (sme->ssid)
  428. print_hex_dump(KERN_INFO, " SSID: ", DUMP_PREFIX_OFFSET,
  429. 16, 1, sme->ssid, sme->ssid_len, true);
  430. wil_info(wil, " Privacy: %s\n", sme->privacy ? "secure" : "open");
  431. wil_info(wil, " PBSS: %d\n", sme->pbss);
  432. wil_print_crypto(wil, &sme->crypto);
  433. }
  434. static int wil_cfg80211_connect(struct wiphy *wiphy,
  435. struct net_device *ndev,
  436. struct cfg80211_connect_params *sme)
  437. {
  438. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  439. struct cfg80211_bss *bss;
  440. struct wmi_connect_cmd conn;
  441. const u8 *ssid_eid;
  442. const u8 *rsn_eid;
  443. int ch;
  444. int rc = 0;
  445. enum ieee80211_bss_type bss_type = IEEE80211_BSS_TYPE_ESS;
  446. wil_dbg_misc(wil, "%s()\n", __func__);
  447. wil_print_connect_params(wil, sme);
  448. if (test_bit(wil_status_fwconnecting, wil->status) ||
  449. test_bit(wil_status_fwconnected, wil->status))
  450. return -EALREADY;
  451. if (sme->ie_len > WMI_MAX_IE_LEN) {
  452. wil_err(wil, "IE too large (%td bytes)\n", sme->ie_len);
  453. return -ERANGE;
  454. }
  455. rsn_eid = sme->ie ?
  456. cfg80211_find_ie(WLAN_EID_RSN, sme->ie, sme->ie_len) :
  457. NULL;
  458. if (sme->privacy && !rsn_eid)
  459. wil_info(wil, "WSC connection\n");
  460. if (sme->pbss)
  461. bss_type = IEEE80211_BSS_TYPE_PBSS;
  462. bss = cfg80211_get_bss(wiphy, sme->channel, sme->bssid,
  463. sme->ssid, sme->ssid_len,
  464. bss_type, IEEE80211_PRIVACY_ANY);
  465. if (!bss) {
  466. wil_err(wil, "Unable to find BSS\n");
  467. return -ENOENT;
  468. }
  469. ssid_eid = ieee80211_bss_get_ie(bss, WLAN_EID_SSID);
  470. if (!ssid_eid) {
  471. wil_err(wil, "No SSID\n");
  472. rc = -ENOENT;
  473. goto out;
  474. }
  475. wil->privacy = sme->privacy;
  476. if (wil->privacy) {
  477. /* For secure assoc, remove old keys */
  478. rc = wmi_del_cipher_key(wil, 0, bss->bssid,
  479. WMI_KEY_USE_PAIRWISE);
  480. if (rc) {
  481. wil_err(wil, "WMI_DELETE_CIPHER_KEY_CMD(PTK) failed\n");
  482. goto out;
  483. }
  484. rc = wmi_del_cipher_key(wil, 0, bss->bssid,
  485. WMI_KEY_USE_RX_GROUP);
  486. if (rc) {
  487. wil_err(wil, "WMI_DELETE_CIPHER_KEY_CMD(GTK) failed\n");
  488. goto out;
  489. }
  490. }
  491. /* WMI_SET_APPIE_CMD. ie may contain rsn info as well as other info
  492. * elements. Send it also in case it's empty, to erase previously set
  493. * ies in FW.
  494. */
  495. rc = wmi_set_ie(wil, WMI_FRAME_ASSOC_REQ, sme->ie_len, sme->ie);
  496. if (rc)
  497. goto out;
  498. /* WMI_CONNECT_CMD */
  499. memset(&conn, 0, sizeof(conn));
  500. switch (bss->capability & WLAN_CAPABILITY_DMG_TYPE_MASK) {
  501. case WLAN_CAPABILITY_DMG_TYPE_AP:
  502. conn.network_type = WMI_NETTYPE_INFRA;
  503. break;
  504. case WLAN_CAPABILITY_DMG_TYPE_PBSS:
  505. conn.network_type = WMI_NETTYPE_P2P;
  506. break;
  507. default:
  508. wil_err(wil, "Unsupported BSS type, capability= 0x%04x\n",
  509. bss->capability);
  510. goto out;
  511. }
  512. if (wil->privacy) {
  513. if (rsn_eid) { /* regular secure connection */
  514. conn.dot11_auth_mode = WMI_AUTH11_SHARED;
  515. conn.auth_mode = WMI_AUTH_WPA2_PSK;
  516. conn.pairwise_crypto_type = WMI_CRYPT_AES_GCMP;
  517. conn.pairwise_crypto_len = 16;
  518. conn.group_crypto_type = WMI_CRYPT_AES_GCMP;
  519. conn.group_crypto_len = 16;
  520. } else { /* WSC */
  521. conn.dot11_auth_mode = WMI_AUTH11_WSC;
  522. conn.auth_mode = WMI_AUTH_NONE;
  523. }
  524. } else { /* insecure connection */
  525. conn.dot11_auth_mode = WMI_AUTH11_OPEN;
  526. conn.auth_mode = WMI_AUTH_NONE;
  527. }
  528. conn.ssid_len = min_t(u8, ssid_eid[1], 32);
  529. memcpy(conn.ssid, ssid_eid+2, conn.ssid_len);
  530. ch = bss->channel->hw_value;
  531. if (ch == 0) {
  532. wil_err(wil, "BSS at unknown frequency %dMhz\n",
  533. bss->channel->center_freq);
  534. rc = -EOPNOTSUPP;
  535. goto out;
  536. }
  537. conn.channel = ch - 1;
  538. ether_addr_copy(conn.bssid, bss->bssid);
  539. ether_addr_copy(conn.dst_mac, bss->bssid);
  540. set_bit(wil_status_fwconnecting, wil->status);
  541. rc = wmi_send(wil, WMI_CONNECT_CMDID, &conn, sizeof(conn));
  542. if (rc == 0) {
  543. netif_carrier_on(ndev);
  544. /* Connect can take lots of time */
  545. mod_timer(&wil->connect_timer,
  546. jiffies + msecs_to_jiffies(2000));
  547. } else {
  548. clear_bit(wil_status_fwconnecting, wil->status);
  549. }
  550. out:
  551. cfg80211_put_bss(wiphy, bss);
  552. return rc;
  553. }
  554. static int wil_cfg80211_disconnect(struct wiphy *wiphy,
  555. struct net_device *ndev,
  556. u16 reason_code)
  557. {
  558. int rc;
  559. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  560. wil_dbg_misc(wil, "%s(reason=%d)\n", __func__, reason_code);
  561. if (!(test_bit(wil_status_fwconnecting, wil->status) ||
  562. test_bit(wil_status_fwconnected, wil->status))) {
  563. wil_err(wil, "%s: Disconnect was called while disconnected\n",
  564. __func__);
  565. return 0;
  566. }
  567. rc = wmi_call(wil, WMI_DISCONNECT_CMDID, NULL, 0,
  568. WMI_DISCONNECT_EVENTID, NULL, 0,
  569. WIL6210_DISCONNECT_TO_MS);
  570. if (rc)
  571. wil_err(wil, "%s: disconnect error %d\n", __func__, rc);
  572. return rc;
  573. }
  574. int wil_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
  575. struct cfg80211_mgmt_tx_params *params,
  576. u64 *cookie)
  577. {
  578. const u8 *buf = params->buf;
  579. size_t len = params->len;
  580. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  581. int rc;
  582. bool tx_status = false;
  583. struct ieee80211_mgmt *mgmt_frame = (void *)buf;
  584. struct wmi_sw_tx_req_cmd *cmd;
  585. struct {
  586. struct wmi_cmd_hdr wmi;
  587. struct wmi_sw_tx_complete_event evt;
  588. } __packed evt;
  589. /* Note, currently we do not support the "wait" parameter, user-space
  590. * must call remain_on_channel before mgmt_tx or listen on a channel
  591. * another way (AP/PCP or connected station)
  592. * in addition we need to check if specified "chan" argument is
  593. * different from currently "listened" channel and fail if it is.
  594. */
  595. wil_dbg_misc(wil, "%s()\n", __func__);
  596. print_hex_dump_bytes("mgmt tx frame ", DUMP_PREFIX_OFFSET, buf, len);
  597. cmd = kmalloc(sizeof(*cmd) + len, GFP_KERNEL);
  598. if (!cmd) {
  599. rc = -ENOMEM;
  600. goto out;
  601. }
  602. memcpy(cmd->dst_mac, mgmt_frame->da, WMI_MAC_LEN);
  603. cmd->len = cpu_to_le16(len);
  604. memcpy(cmd->payload, buf, len);
  605. rc = wmi_call(wil, WMI_SW_TX_REQ_CMDID, cmd, sizeof(*cmd) + len,
  606. WMI_SW_TX_COMPLETE_EVENTID, &evt, sizeof(evt), 2000);
  607. if (rc == 0)
  608. tx_status = !evt.evt.status;
  609. kfree(cmd);
  610. out:
  611. cfg80211_mgmt_tx_status(wdev, cookie ? *cookie : 0, buf, len,
  612. tx_status, GFP_KERNEL);
  613. return rc;
  614. }
  615. static int wil_cfg80211_set_channel(struct wiphy *wiphy,
  616. struct cfg80211_chan_def *chandef)
  617. {
  618. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  619. struct wireless_dev *wdev = wil_to_wdev(wil);
  620. wdev->preset_chandef = *chandef;
  621. return 0;
  622. }
  623. static enum wmi_key_usage wil_detect_key_usage(struct wil6210_priv *wil,
  624. bool pairwise)
  625. {
  626. struct wireless_dev *wdev = wil_to_wdev(wil);
  627. enum wmi_key_usage rc;
  628. if (pairwise) {
  629. rc = WMI_KEY_USE_PAIRWISE;
  630. } else {
  631. switch (wdev->iftype) {
  632. case NL80211_IFTYPE_STATION:
  633. case NL80211_IFTYPE_P2P_CLIENT:
  634. rc = WMI_KEY_USE_RX_GROUP;
  635. break;
  636. case NL80211_IFTYPE_AP:
  637. case NL80211_IFTYPE_P2P_GO:
  638. rc = WMI_KEY_USE_TX_GROUP;
  639. break;
  640. default:
  641. /* TODO: Rx GTK or Tx GTK? */
  642. wil_err(wil, "Can't determine GTK type\n");
  643. rc = WMI_KEY_USE_RX_GROUP;
  644. break;
  645. }
  646. }
  647. wil_dbg_misc(wil, "%s() -> %s\n", __func__, key_usage_str[rc]);
  648. return rc;
  649. }
  650. static struct wil_tid_crypto_rx_single *
  651. wil_find_crypto_ctx(struct wil6210_priv *wil, u8 key_index,
  652. enum wmi_key_usage key_usage, const u8 *mac_addr)
  653. {
  654. int cid = -EINVAL;
  655. int tid = 0;
  656. struct wil_sta_info *s;
  657. struct wil_tid_crypto_rx *c;
  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[%d]\n", mac_addr,
  667. key_usage_str[key_usage], key_index);
  668. return ERR_PTR(cid);
  669. }
  670. s = &wil->sta[cid];
  671. if (key_usage == WMI_KEY_USE_PAIRWISE)
  672. c = &s->tid_crypto_rx[tid];
  673. else
  674. c = &s->group_crypto_rx;
  675. return &c->key_id[key_index];
  676. }
  677. static int wil_cfg80211_add_key(struct wiphy *wiphy,
  678. struct net_device *ndev,
  679. u8 key_index, bool pairwise,
  680. const u8 *mac_addr,
  681. struct key_params *params)
  682. {
  683. int rc;
  684. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  685. enum wmi_key_usage key_usage = wil_detect_key_usage(wil, pairwise);
  686. struct wil_tid_crypto_rx_single *cc = wil_find_crypto_ctx(wil,
  687. key_index,
  688. key_usage,
  689. mac_addr);
  690. wil_dbg_misc(wil, "%s(%pM %s[%d] PN %*phN)\n", __func__,
  691. mac_addr, key_usage_str[key_usage], key_index,
  692. params->seq_len, params->seq);
  693. if (IS_ERR(cc)) {
  694. wil_err(wil, "Not connected, %s(%pM %s[%d] PN %*phN)\n",
  695. __func__, mac_addr, key_usage_str[key_usage], key_index,
  696. params->seq_len, params->seq);
  697. return -EINVAL;
  698. }
  699. if (cc)
  700. cc->key_set = false;
  701. if (params->seq && params->seq_len != IEEE80211_GCMP_PN_LEN) {
  702. wil_err(wil,
  703. "Wrong PN len %d, %s(%pM %s[%d] PN %*phN)\n",
  704. params->seq_len, __func__, mac_addr,
  705. key_usage_str[key_usage], key_index,
  706. params->seq_len, params->seq);
  707. return -EINVAL;
  708. }
  709. rc = wmi_add_cipher_key(wil, key_index, mac_addr, params->key_len,
  710. params->key, key_usage);
  711. if ((rc == 0) && cc) {
  712. if (params->seq)
  713. memcpy(cc->pn, params->seq, IEEE80211_GCMP_PN_LEN);
  714. else
  715. memset(cc->pn, 0, IEEE80211_GCMP_PN_LEN);
  716. cc->key_set = true;
  717. }
  718. return rc;
  719. }
  720. static int wil_cfg80211_del_key(struct wiphy *wiphy,
  721. struct net_device *ndev,
  722. u8 key_index, bool pairwise,
  723. const u8 *mac_addr)
  724. {
  725. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  726. enum wmi_key_usage key_usage = wil_detect_key_usage(wil, pairwise);
  727. struct wil_tid_crypto_rx_single *cc = wil_find_crypto_ctx(wil,
  728. key_index,
  729. key_usage,
  730. mac_addr);
  731. wil_dbg_misc(wil, "%s(%pM %s[%d])\n", __func__, mac_addr,
  732. key_usage_str[key_usage], key_index);
  733. if (IS_ERR(cc))
  734. wil_info(wil, "Not connected, %s(%pM %s[%d])\n", __func__,
  735. mac_addr, key_usage_str[key_usage], key_index);
  736. if (!IS_ERR_OR_NULL(cc))
  737. cc->key_set = false;
  738. return wmi_del_cipher_key(wil, key_index, mac_addr, key_usage);
  739. }
  740. /* Need to be present or wiphy_new() will WARN */
  741. static int wil_cfg80211_set_default_key(struct wiphy *wiphy,
  742. struct net_device *ndev,
  743. u8 key_index, bool unicast,
  744. bool multicast)
  745. {
  746. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  747. wil_dbg_misc(wil, "%s: entered\n", __func__);
  748. return 0;
  749. }
  750. static int wil_remain_on_channel(struct wiphy *wiphy,
  751. struct wireless_dev *wdev,
  752. struct ieee80211_channel *chan,
  753. unsigned int duration,
  754. u64 *cookie)
  755. {
  756. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  757. int rc;
  758. wil_dbg_misc(wil, "%s() center_freq=%d, duration=%d iftype=%d\n",
  759. __func__, chan->center_freq, duration, wdev->iftype);
  760. rc = wil_p2p_listen(wil, duration, chan, cookie);
  761. if (rc)
  762. return rc;
  763. wil->radio_wdev = wdev;
  764. cfg80211_ready_on_channel(wdev, *cookie, chan, duration,
  765. GFP_KERNEL);
  766. return 0;
  767. }
  768. static int wil_cancel_remain_on_channel(struct wiphy *wiphy,
  769. struct wireless_dev *wdev,
  770. u64 cookie)
  771. {
  772. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  773. wil_dbg_misc(wil, "%s()\n", __func__);
  774. return wil_p2p_cancel_listen(wil, cookie);
  775. }
  776. /**
  777. * find a specific IE in a list of IEs
  778. * return a pointer to the beginning of IE in the list
  779. * or NULL if not found
  780. */
  781. static const u8 *_wil_cfg80211_find_ie(const u8 *ies, u16 ies_len, const u8 *ie,
  782. u16 ie_len)
  783. {
  784. struct ieee80211_vendor_ie *vie;
  785. u32 oui;
  786. /* IE tag at offset 0, length at offset 1 */
  787. if (ie_len < 2 || 2 + ie[1] > ie_len)
  788. return NULL;
  789. if (ie[0] != WLAN_EID_VENDOR_SPECIFIC)
  790. return cfg80211_find_ie(ie[0], ies, ies_len);
  791. /* make sure there is room for 3 bytes OUI + 1 byte OUI type */
  792. if (ie[1] < 4)
  793. return NULL;
  794. vie = (struct ieee80211_vendor_ie *)ie;
  795. oui = vie->oui[0] << 16 | vie->oui[1] << 8 | vie->oui[2];
  796. return cfg80211_find_vendor_ie(oui, vie->oui_type, ies,
  797. ies_len);
  798. }
  799. /**
  800. * merge the IEs in two lists into a single list.
  801. * do not include IEs from the second list which exist in the first list.
  802. * add only vendor specific IEs from second list to keep
  803. * the merged list sorted (since vendor-specific IE has the
  804. * highest tag number)
  805. * caller must free the allocated memory for merged IEs
  806. */
  807. static int _wil_cfg80211_merge_extra_ies(const u8 *ies1, u16 ies1_len,
  808. const u8 *ies2, u16 ies2_len,
  809. u8 **merged_ies, u16 *merged_len)
  810. {
  811. u8 *buf, *dpos;
  812. const u8 *spos;
  813. if (ies1_len == 0 && ies2_len == 0) {
  814. *merged_ies = NULL;
  815. *merged_len = 0;
  816. return 0;
  817. }
  818. buf = kmalloc(ies1_len + ies2_len, GFP_KERNEL);
  819. if (!buf)
  820. return -ENOMEM;
  821. memcpy(buf, ies1, ies1_len);
  822. dpos = buf + ies1_len;
  823. spos = ies2;
  824. while (spos + 1 < ies2 + ies2_len) {
  825. /* IE tag at offset 0, length at offset 1 */
  826. u16 ielen = 2 + spos[1];
  827. if (spos + ielen > ies2 + ies2_len)
  828. break;
  829. if (spos[0] == WLAN_EID_VENDOR_SPECIFIC &&
  830. !_wil_cfg80211_find_ie(ies1, ies1_len, spos, ielen)) {
  831. memcpy(dpos, spos, ielen);
  832. dpos += ielen;
  833. }
  834. spos += ielen;
  835. }
  836. *merged_ies = buf;
  837. *merged_len = dpos - buf;
  838. return 0;
  839. }
  840. static void wil_print_bcon_data(struct cfg80211_beacon_data *b)
  841. {
  842. print_hex_dump_bytes("head ", DUMP_PREFIX_OFFSET,
  843. b->head, b->head_len);
  844. print_hex_dump_bytes("tail ", DUMP_PREFIX_OFFSET,
  845. b->tail, b->tail_len);
  846. print_hex_dump_bytes("BCON IE ", DUMP_PREFIX_OFFSET,
  847. b->beacon_ies, b->beacon_ies_len);
  848. print_hex_dump_bytes("PROBE ", DUMP_PREFIX_OFFSET,
  849. b->probe_resp, b->probe_resp_len);
  850. print_hex_dump_bytes("PROBE IE ", DUMP_PREFIX_OFFSET,
  851. b->proberesp_ies, b->proberesp_ies_len);
  852. print_hex_dump_bytes("ASSOC IE ", DUMP_PREFIX_OFFSET,
  853. b->assocresp_ies, b->assocresp_ies_len);
  854. }
  855. /* internal functions for device reset and starting AP */
  856. static int _wil_cfg80211_set_ies(struct wiphy *wiphy,
  857. struct cfg80211_beacon_data *bcon)
  858. {
  859. int rc;
  860. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  861. u16 len = 0, proberesp_len = 0;
  862. u8 *ies = NULL, *proberesp = NULL;
  863. if (bcon->probe_resp) {
  864. struct ieee80211_mgmt *f =
  865. (struct ieee80211_mgmt *)bcon->probe_resp;
  866. size_t hlen = offsetof(struct ieee80211_mgmt,
  867. u.probe_resp.variable);
  868. proberesp = f->u.probe_resp.variable;
  869. proberesp_len = bcon->probe_resp_len - hlen;
  870. }
  871. rc = _wil_cfg80211_merge_extra_ies(proberesp,
  872. proberesp_len,
  873. bcon->proberesp_ies,
  874. bcon->proberesp_ies_len,
  875. &ies, &len);
  876. if (rc)
  877. goto out;
  878. rc = wmi_set_ie(wil, WMI_FRAME_PROBE_RESP, len, ies);
  879. if (rc)
  880. goto out;
  881. if (bcon->assocresp_ies)
  882. rc = wmi_set_ie(wil, WMI_FRAME_ASSOC_RESP,
  883. bcon->assocresp_ies_len, bcon->assocresp_ies);
  884. else
  885. rc = wmi_set_ie(wil, WMI_FRAME_ASSOC_RESP, len, ies);
  886. #if 0 /* to use beacon IE's, remove this #if 0 */
  887. if (rc)
  888. goto out;
  889. rc = wmi_set_ie(wil, WMI_FRAME_BEACON, bcon->tail_len, bcon->tail);
  890. #endif
  891. out:
  892. kfree(ies);
  893. return rc;
  894. }
  895. static int _wil_cfg80211_start_ap(struct wiphy *wiphy,
  896. struct net_device *ndev,
  897. const u8 *ssid, size_t ssid_len, u32 privacy,
  898. int bi, u8 chan,
  899. struct cfg80211_beacon_data *bcon,
  900. u8 hidden_ssid, u32 pbss)
  901. {
  902. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  903. int rc;
  904. struct wireless_dev *wdev = ndev->ieee80211_ptr;
  905. u8 wmi_nettype = wil_iftype_nl2wmi(wdev->iftype);
  906. u8 is_go = (wdev->iftype == NL80211_IFTYPE_P2P_GO);
  907. if (pbss)
  908. wmi_nettype = WMI_NETTYPE_P2P;
  909. wil_dbg_misc(wil, "%s: is_go=%d\n", __func__, is_go);
  910. if (is_go && !pbss) {
  911. wil_err(wil, "%s: P2P GO must be in PBSS\n", __func__);
  912. return -ENOTSUPP;
  913. }
  914. wil_set_recovery_state(wil, fw_recovery_idle);
  915. mutex_lock(&wil->mutex);
  916. __wil_down(wil);
  917. rc = __wil_up(wil);
  918. if (rc)
  919. goto out;
  920. rc = wmi_set_ssid(wil, ssid_len, ssid);
  921. if (rc)
  922. goto out;
  923. rc = _wil_cfg80211_set_ies(wiphy, bcon);
  924. if (rc)
  925. goto out;
  926. wil->privacy = privacy;
  927. wil->channel = chan;
  928. wil->hidden_ssid = hidden_ssid;
  929. wil->pbss = pbss;
  930. netif_carrier_on(ndev);
  931. rc = wmi_pcp_start(wil, bi, wmi_nettype, chan, hidden_ssid, is_go);
  932. if (rc)
  933. goto err_pcp_start;
  934. rc = wil_bcast_init(wil);
  935. if (rc)
  936. goto err_bcast;
  937. goto out; /* success */
  938. err_bcast:
  939. wmi_pcp_stop(wil);
  940. err_pcp_start:
  941. netif_carrier_off(ndev);
  942. out:
  943. mutex_unlock(&wil->mutex);
  944. return rc;
  945. }
  946. static int wil_cfg80211_change_beacon(struct wiphy *wiphy,
  947. struct net_device *ndev,
  948. struct cfg80211_beacon_data *bcon)
  949. {
  950. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  951. int rc;
  952. u32 privacy = 0;
  953. wil_dbg_misc(wil, "%s()\n", __func__);
  954. wil_print_bcon_data(bcon);
  955. if (bcon->tail &&
  956. cfg80211_find_ie(WLAN_EID_RSN, bcon->tail,
  957. bcon->tail_len))
  958. privacy = 1;
  959. /* in case privacy has changed, need to restart the AP */
  960. if (wil->privacy != privacy) {
  961. struct wireless_dev *wdev = ndev->ieee80211_ptr;
  962. wil_dbg_misc(wil, "privacy changed %d=>%d. Restarting AP\n",
  963. wil->privacy, privacy);
  964. rc = _wil_cfg80211_start_ap(wiphy, ndev, wdev->ssid,
  965. wdev->ssid_len, privacy,
  966. wdev->beacon_interval,
  967. wil->channel, bcon,
  968. wil->hidden_ssid,
  969. wil->pbss);
  970. } else {
  971. rc = _wil_cfg80211_set_ies(wiphy, bcon);
  972. }
  973. return rc;
  974. }
  975. static int wil_cfg80211_start_ap(struct wiphy *wiphy,
  976. struct net_device *ndev,
  977. struct cfg80211_ap_settings *info)
  978. {
  979. int rc;
  980. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  981. struct ieee80211_channel *channel = info->chandef.chan;
  982. struct cfg80211_beacon_data *bcon = &info->beacon;
  983. struct cfg80211_crypto_settings *crypto = &info->crypto;
  984. u8 hidden_ssid;
  985. wil_dbg_misc(wil, "%s()\n", __func__);
  986. if (!channel) {
  987. wil_err(wil, "AP: No channel???\n");
  988. return -EINVAL;
  989. }
  990. switch (info->hidden_ssid) {
  991. case NL80211_HIDDEN_SSID_NOT_IN_USE:
  992. hidden_ssid = WMI_HIDDEN_SSID_DISABLED;
  993. break;
  994. case NL80211_HIDDEN_SSID_ZERO_LEN:
  995. hidden_ssid = WMI_HIDDEN_SSID_SEND_EMPTY;
  996. break;
  997. case NL80211_HIDDEN_SSID_ZERO_CONTENTS:
  998. hidden_ssid = WMI_HIDDEN_SSID_CLEAR;
  999. break;
  1000. default:
  1001. wil_err(wil, "AP: Invalid hidden SSID %d\n", info->hidden_ssid);
  1002. return -EOPNOTSUPP;
  1003. }
  1004. wil_dbg_misc(wil, "AP on Channel %d %d MHz, %s\n", channel->hw_value,
  1005. channel->center_freq, info->privacy ? "secure" : "open");
  1006. wil_dbg_misc(wil, "Privacy: %d auth_type %d\n",
  1007. info->privacy, info->auth_type);
  1008. wil_dbg_misc(wil, "Hidden SSID mode: %d\n",
  1009. info->hidden_ssid);
  1010. wil_dbg_misc(wil, "BI %d DTIM %d\n", info->beacon_interval,
  1011. info->dtim_period);
  1012. wil_dbg_misc(wil, "PBSS %d\n", info->pbss);
  1013. print_hex_dump_bytes("SSID ", DUMP_PREFIX_OFFSET,
  1014. info->ssid, info->ssid_len);
  1015. wil_print_bcon_data(bcon);
  1016. wil_print_crypto(wil, crypto);
  1017. rc = _wil_cfg80211_start_ap(wiphy, ndev,
  1018. info->ssid, info->ssid_len, info->privacy,
  1019. info->beacon_interval, channel->hw_value,
  1020. bcon, hidden_ssid, info->pbss);
  1021. return rc;
  1022. }
  1023. static int wil_cfg80211_stop_ap(struct wiphy *wiphy,
  1024. struct net_device *ndev)
  1025. {
  1026. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  1027. wil_dbg_misc(wil, "%s()\n", __func__);
  1028. netif_carrier_off(ndev);
  1029. wil_set_recovery_state(wil, fw_recovery_idle);
  1030. mutex_lock(&wil->mutex);
  1031. wmi_pcp_stop(wil);
  1032. __wil_down(wil);
  1033. mutex_unlock(&wil->mutex);
  1034. return 0;
  1035. }
  1036. static int wil_cfg80211_del_station(struct wiphy *wiphy,
  1037. struct net_device *dev,
  1038. struct station_del_parameters *params)
  1039. {
  1040. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  1041. wil_dbg_misc(wil, "%s(%pM, reason=%d)\n", __func__, params->mac,
  1042. params->reason_code);
  1043. mutex_lock(&wil->mutex);
  1044. wil6210_disconnect(wil, params->mac, params->reason_code, false);
  1045. mutex_unlock(&wil->mutex);
  1046. return 0;
  1047. }
  1048. /* probe_client handling */
  1049. static void wil_probe_client_handle(struct wil6210_priv *wil,
  1050. struct wil_probe_client_req *req)
  1051. {
  1052. struct net_device *ndev = wil_to_ndev(wil);
  1053. struct wil_sta_info *sta = &wil->sta[req->cid];
  1054. /* assume STA is alive if it is still connected,
  1055. * else FW will disconnect it
  1056. */
  1057. bool alive = (sta->status == wil_sta_connected);
  1058. cfg80211_probe_status(ndev, sta->addr, req->cookie, alive, GFP_KERNEL);
  1059. }
  1060. static struct list_head *next_probe_client(struct wil6210_priv *wil)
  1061. {
  1062. struct list_head *ret = NULL;
  1063. mutex_lock(&wil->probe_client_mutex);
  1064. if (!list_empty(&wil->probe_client_pending)) {
  1065. ret = wil->probe_client_pending.next;
  1066. list_del(ret);
  1067. }
  1068. mutex_unlock(&wil->probe_client_mutex);
  1069. return ret;
  1070. }
  1071. void wil_probe_client_worker(struct work_struct *work)
  1072. {
  1073. struct wil6210_priv *wil = container_of(work, struct wil6210_priv,
  1074. probe_client_worker);
  1075. struct wil_probe_client_req *req;
  1076. struct list_head *lh;
  1077. while ((lh = next_probe_client(wil)) != NULL) {
  1078. req = list_entry(lh, struct wil_probe_client_req, list);
  1079. wil_probe_client_handle(wil, req);
  1080. kfree(req);
  1081. }
  1082. }
  1083. void wil_probe_client_flush(struct wil6210_priv *wil)
  1084. {
  1085. struct wil_probe_client_req *req, *t;
  1086. wil_dbg_misc(wil, "%s()\n", __func__);
  1087. mutex_lock(&wil->probe_client_mutex);
  1088. list_for_each_entry_safe(req, t, &wil->probe_client_pending, list) {
  1089. list_del(&req->list);
  1090. kfree(req);
  1091. }
  1092. mutex_unlock(&wil->probe_client_mutex);
  1093. }
  1094. static int wil_cfg80211_probe_client(struct wiphy *wiphy,
  1095. struct net_device *dev,
  1096. const u8 *peer, u64 *cookie)
  1097. {
  1098. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  1099. struct wil_probe_client_req *req;
  1100. int cid = wil_find_cid(wil, peer);
  1101. wil_dbg_misc(wil, "%s(%pM => CID %d)\n", __func__, peer, cid);
  1102. if (cid < 0)
  1103. return -ENOLINK;
  1104. req = kzalloc(sizeof(*req), GFP_KERNEL);
  1105. if (!req)
  1106. return -ENOMEM;
  1107. req->cid = cid;
  1108. req->cookie = cid;
  1109. mutex_lock(&wil->probe_client_mutex);
  1110. list_add_tail(&req->list, &wil->probe_client_pending);
  1111. mutex_unlock(&wil->probe_client_mutex);
  1112. *cookie = req->cookie;
  1113. queue_work(wil->wq_service, &wil->probe_client_worker);
  1114. return 0;
  1115. }
  1116. static int wil_cfg80211_change_bss(struct wiphy *wiphy,
  1117. struct net_device *dev,
  1118. struct bss_parameters *params)
  1119. {
  1120. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  1121. if (params->ap_isolate >= 0) {
  1122. wil_dbg_misc(wil, "%s(ap_isolate %d => %d)\n", __func__,
  1123. wil->ap_isolate, params->ap_isolate);
  1124. wil->ap_isolate = params->ap_isolate;
  1125. }
  1126. return 0;
  1127. }
  1128. static int wil_cfg80211_start_p2p_device(struct wiphy *wiphy,
  1129. struct wireless_dev *wdev)
  1130. {
  1131. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  1132. wil_dbg_misc(wil, "%s: entered\n", __func__);
  1133. wil->p2p.p2p_dev_started = 1;
  1134. return 0;
  1135. }
  1136. static void wil_cfg80211_stop_p2p_device(struct wiphy *wiphy,
  1137. struct wireless_dev *wdev)
  1138. {
  1139. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  1140. u8 started;
  1141. wil_dbg_misc(wil, "%s: entered\n", __func__);
  1142. mutex_lock(&wil->mutex);
  1143. started = wil_p2p_stop_discovery(wil);
  1144. if (started && wil->scan_request) {
  1145. struct cfg80211_scan_info info = {
  1146. .aborted = true,
  1147. };
  1148. cfg80211_scan_done(wil->scan_request, &info);
  1149. wil->scan_request = NULL;
  1150. wil->radio_wdev = wil->wdev;
  1151. }
  1152. mutex_unlock(&wil->mutex);
  1153. wil->p2p.p2p_dev_started = 0;
  1154. }
  1155. static struct cfg80211_ops wil_cfg80211_ops = {
  1156. .add_virtual_intf = wil_cfg80211_add_iface,
  1157. .del_virtual_intf = wil_cfg80211_del_iface,
  1158. .scan = wil_cfg80211_scan,
  1159. .connect = wil_cfg80211_connect,
  1160. .disconnect = wil_cfg80211_disconnect,
  1161. .change_virtual_intf = wil_cfg80211_change_iface,
  1162. .get_station = wil_cfg80211_get_station,
  1163. .dump_station = wil_cfg80211_dump_station,
  1164. .remain_on_channel = wil_remain_on_channel,
  1165. .cancel_remain_on_channel = wil_cancel_remain_on_channel,
  1166. .mgmt_tx = wil_cfg80211_mgmt_tx,
  1167. .set_monitor_channel = wil_cfg80211_set_channel,
  1168. .add_key = wil_cfg80211_add_key,
  1169. .del_key = wil_cfg80211_del_key,
  1170. .set_default_key = wil_cfg80211_set_default_key,
  1171. /* AP mode */
  1172. .change_beacon = wil_cfg80211_change_beacon,
  1173. .start_ap = wil_cfg80211_start_ap,
  1174. .stop_ap = wil_cfg80211_stop_ap,
  1175. .del_station = wil_cfg80211_del_station,
  1176. .probe_client = wil_cfg80211_probe_client,
  1177. .change_bss = wil_cfg80211_change_bss,
  1178. /* P2P device */
  1179. .start_p2p_device = wil_cfg80211_start_p2p_device,
  1180. .stop_p2p_device = wil_cfg80211_stop_p2p_device,
  1181. };
  1182. static void wil_wiphy_init(struct wiphy *wiphy)
  1183. {
  1184. wiphy->max_scan_ssids = 1;
  1185. wiphy->max_scan_ie_len = WMI_MAX_IE_LEN;
  1186. wiphy->max_remain_on_channel_duration = WIL_MAX_ROC_DURATION_MS;
  1187. wiphy->max_num_pmkids = 0 /* TODO: */;
  1188. wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
  1189. BIT(NL80211_IFTYPE_AP) |
  1190. BIT(NL80211_IFTYPE_P2P_CLIENT) |
  1191. BIT(NL80211_IFTYPE_P2P_GO) |
  1192. BIT(NL80211_IFTYPE_P2P_DEVICE) |
  1193. BIT(NL80211_IFTYPE_MONITOR);
  1194. wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME |
  1195. WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL |
  1196. WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
  1197. dev_dbg(wiphy_dev(wiphy), "%s : flags = 0x%08x\n",
  1198. __func__, wiphy->flags);
  1199. wiphy->probe_resp_offload =
  1200. NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
  1201. NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
  1202. NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
  1203. wiphy->bands[NL80211_BAND_60GHZ] = &wil_band_60ghz;
  1204. /* TODO: figure this out */
  1205. wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC;
  1206. wiphy->cipher_suites = wil_cipher_suites;
  1207. wiphy->n_cipher_suites = ARRAY_SIZE(wil_cipher_suites);
  1208. wiphy->mgmt_stypes = wil_mgmt_stypes;
  1209. wiphy->features |= NL80211_FEATURE_SK_TX_STATUS;
  1210. }
  1211. struct wireless_dev *wil_cfg80211_init(struct device *dev)
  1212. {
  1213. int rc = 0;
  1214. struct wireless_dev *wdev;
  1215. dev_dbg(dev, "%s()\n", __func__);
  1216. wdev = kzalloc(sizeof(*wdev), GFP_KERNEL);
  1217. if (!wdev)
  1218. return ERR_PTR(-ENOMEM);
  1219. wdev->wiphy = wiphy_new(&wil_cfg80211_ops,
  1220. sizeof(struct wil6210_priv));
  1221. if (!wdev->wiphy) {
  1222. rc = -ENOMEM;
  1223. goto out;
  1224. }
  1225. set_wiphy_dev(wdev->wiphy, dev);
  1226. wil_wiphy_init(wdev->wiphy);
  1227. rc = wiphy_register(wdev->wiphy);
  1228. if (rc < 0)
  1229. goto out_failed_reg;
  1230. return wdev;
  1231. out_failed_reg:
  1232. wiphy_free(wdev->wiphy);
  1233. out:
  1234. kfree(wdev);
  1235. return ERR_PTR(rc);
  1236. }
  1237. void wil_wdev_free(struct wil6210_priv *wil)
  1238. {
  1239. struct wireless_dev *wdev = wil_to_wdev(wil);
  1240. dev_dbg(wil_to_dev(wil), "%s()\n", __func__);
  1241. if (!wdev)
  1242. return;
  1243. wiphy_unregister(wdev->wiphy);
  1244. wiphy_free(wdev->wiphy);
  1245. kfree(wdev);
  1246. }
  1247. void wil_p2p_wdev_free(struct wil6210_priv *wil)
  1248. {
  1249. struct wireless_dev *p2p_wdev;
  1250. mutex_lock(&wil->p2p_wdev_mutex);
  1251. p2p_wdev = wil->p2p_wdev;
  1252. if (p2p_wdev) {
  1253. wil->p2p_wdev = NULL;
  1254. wil->radio_wdev = wil_to_wdev(wil);
  1255. cfg80211_unregister_wdev(p2p_wdev);
  1256. kfree(p2p_wdev);
  1257. }
  1258. mutex_unlock(&wil->p2p_wdev_mutex);
  1259. }