cfg80211.c 43 KB

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