cfg80211.c 41 KB

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