cfg80211.c 43 KB

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