cfg80211.c 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2012 - 2018 Microchip Technology Inc., and its subsidiaries.
  4. * All rights reserved.
  5. */
  6. #include "cfg80211.h"
  7. #define GO_NEG_REQ 0x00
  8. #define GO_NEG_RSP 0x01
  9. #define GO_NEG_CONF 0x02
  10. #define P2P_INV_REQ 0x03
  11. #define P2P_INV_RSP 0x04
  12. #define WILC_INVALID_CHANNEL 0
  13. /* Operation at 2.4 GHz with channels 1-13 */
  14. #define WILC_WLAN_OPERATING_CLASS_2_4GHZ 0x51
  15. static const struct ieee80211_txrx_stypes
  16. wilc_wfi_cfg80211_mgmt_types[NUM_NL80211_IFTYPES] = {
  17. [NL80211_IFTYPE_STATION] = {
  18. .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  19. BIT(IEEE80211_STYPE_AUTH >> 4),
  20. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  21. BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
  22. BIT(IEEE80211_STYPE_AUTH >> 4)
  23. },
  24. [NL80211_IFTYPE_AP] = {
  25. .tx = 0xffff,
  26. .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
  27. BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
  28. BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
  29. BIT(IEEE80211_STYPE_DISASSOC >> 4) |
  30. BIT(IEEE80211_STYPE_AUTH >> 4) |
  31. BIT(IEEE80211_STYPE_DEAUTH >> 4) |
  32. BIT(IEEE80211_STYPE_ACTION >> 4)
  33. },
  34. [NL80211_IFTYPE_P2P_CLIENT] = {
  35. .tx = 0xffff,
  36. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  37. BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
  38. BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
  39. BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
  40. BIT(IEEE80211_STYPE_DISASSOC >> 4) |
  41. BIT(IEEE80211_STYPE_AUTH >> 4) |
  42. BIT(IEEE80211_STYPE_DEAUTH >> 4)
  43. }
  44. };
  45. #ifdef CONFIG_PM
  46. static const struct wiphy_wowlan_support wowlan_support = {
  47. .flags = WIPHY_WOWLAN_ANY
  48. };
  49. #endif
  50. struct wilc_p2p_mgmt_data {
  51. int size;
  52. u8 *buff;
  53. };
  54. struct wilc_p2p_pub_act_frame {
  55. u8 category;
  56. u8 action;
  57. u8 oui[3];
  58. u8 oui_type;
  59. u8 oui_subtype;
  60. u8 dialog_token;
  61. u8 elem[];
  62. } __packed;
  63. struct wilc_vendor_specific_ie {
  64. u8 tag_number;
  65. u8 tag_len;
  66. u8 oui[3];
  67. u8 oui_type;
  68. u8 attr[];
  69. } __packed;
  70. struct wilc_attr_entry {
  71. u8 attr_type;
  72. __le16 attr_len;
  73. u8 val[];
  74. } __packed;
  75. struct wilc_attr_oper_ch {
  76. u8 attr_type;
  77. __le16 attr_len;
  78. u8 country_code[IEEE80211_COUNTRY_STRING_LEN];
  79. u8 op_class;
  80. u8 op_channel;
  81. } __packed;
  82. struct wilc_attr_ch_list {
  83. u8 attr_type;
  84. __le16 attr_len;
  85. u8 country_code[IEEE80211_COUNTRY_STRING_LEN];
  86. u8 elem[];
  87. } __packed;
  88. struct wilc_ch_list_elem {
  89. u8 op_class;
  90. u8 no_of_channels;
  91. u8 ch_list[];
  92. } __packed;
  93. static void cfg_scan_result(enum scan_event scan_event,
  94. struct wilc_rcvd_net_info *info, void *user_void)
  95. {
  96. struct wilc_priv *priv = user_void;
  97. if (!priv->cfg_scanning)
  98. return;
  99. if (scan_event == SCAN_EVENT_NETWORK_FOUND) {
  100. s32 freq;
  101. struct ieee80211_channel *channel;
  102. struct cfg80211_bss *bss;
  103. struct wiphy *wiphy = priv->dev->ieee80211_ptr->wiphy;
  104. if (!wiphy || !info)
  105. return;
  106. freq = ieee80211_channel_to_frequency((s32)info->ch,
  107. NL80211_BAND_2GHZ);
  108. channel = ieee80211_get_channel(wiphy, freq);
  109. if (!channel)
  110. return;
  111. bss = cfg80211_inform_bss_frame(wiphy, channel, info->mgmt,
  112. info->frame_len,
  113. (s32)info->rssi * 100,
  114. GFP_KERNEL);
  115. cfg80211_put_bss(wiphy, bss);
  116. } else if (scan_event == SCAN_EVENT_DONE) {
  117. mutex_lock(&priv->scan_req_lock);
  118. if (priv->scan_req) {
  119. struct cfg80211_scan_info info = {
  120. .aborted = false,
  121. };
  122. cfg80211_scan_done(priv->scan_req, &info);
  123. priv->cfg_scanning = false;
  124. priv->scan_req = NULL;
  125. }
  126. mutex_unlock(&priv->scan_req_lock);
  127. } else if (scan_event == SCAN_EVENT_ABORTED) {
  128. mutex_lock(&priv->scan_req_lock);
  129. if (priv->scan_req) {
  130. struct cfg80211_scan_info info = {
  131. .aborted = false,
  132. };
  133. cfg80211_scan_done(priv->scan_req, &info);
  134. priv->cfg_scanning = false;
  135. priv->scan_req = NULL;
  136. }
  137. mutex_unlock(&priv->scan_req_lock);
  138. }
  139. }
  140. static void cfg_connect_result(enum conn_event conn_disconn_evt, u8 mac_status,
  141. void *priv_data)
  142. {
  143. struct wilc_priv *priv = priv_data;
  144. struct net_device *dev = priv->dev;
  145. struct wilc_vif *vif = netdev_priv(dev);
  146. struct wilc *wl = vif->wilc;
  147. struct host_if_drv *wfi_drv = priv->hif_drv;
  148. struct wilc_conn_info *conn_info = &wfi_drv->conn_info;
  149. struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
  150. vif->connecting = false;
  151. if (conn_disconn_evt == CONN_DISCONN_EVENT_CONN_RESP) {
  152. u16 connect_status = conn_info->status;
  153. if (mac_status == WILC_MAC_STATUS_DISCONNECTED &&
  154. connect_status == WLAN_STATUS_SUCCESS) {
  155. connect_status = WLAN_STATUS_UNSPECIFIED_FAILURE;
  156. wilc_wlan_set_bssid(priv->dev, NULL, WILC_STATION_MODE);
  157. if (vif->iftype != WILC_CLIENT_MODE)
  158. wl->sta_ch = WILC_INVALID_CHANNEL;
  159. netdev_err(dev, "Unspecified failure\n");
  160. }
  161. if (connect_status == WLAN_STATUS_SUCCESS)
  162. memcpy(priv->associated_bss, conn_info->bssid,
  163. ETH_ALEN);
  164. cfg80211_ref_bss(wiphy, vif->bss);
  165. cfg80211_connect_bss(dev, conn_info->bssid, vif->bss,
  166. conn_info->req_ies,
  167. conn_info->req_ies_len,
  168. conn_info->resp_ies,
  169. conn_info->resp_ies_len,
  170. connect_status, GFP_KERNEL,
  171. NL80211_TIMEOUT_UNSPECIFIED);
  172. vif->bss = NULL;
  173. } else if (conn_disconn_evt == CONN_DISCONN_EVENT_DISCONN_NOTIF) {
  174. u16 reason = 0;
  175. eth_zero_addr(priv->associated_bss);
  176. wilc_wlan_set_bssid(priv->dev, NULL, WILC_STATION_MODE);
  177. if (vif->iftype != WILC_CLIENT_MODE) {
  178. wl->sta_ch = WILC_INVALID_CHANNEL;
  179. } else {
  180. if (wfi_drv->ifc_up)
  181. reason = 3;
  182. else
  183. reason = 1;
  184. }
  185. cfg80211_disconnected(dev, reason, NULL, 0, false, GFP_KERNEL);
  186. }
  187. }
  188. struct wilc_vif *wilc_get_wl_to_vif(struct wilc *wl)
  189. {
  190. struct wilc_vif *vif;
  191. vif = list_first_or_null_rcu(&wl->vif_list, typeof(*vif), list);
  192. if (!vif)
  193. return ERR_PTR(-EINVAL);
  194. return vif;
  195. }
  196. static int set_channel(struct wiphy *wiphy,
  197. struct cfg80211_chan_def *chandef)
  198. {
  199. struct wilc *wl = wiphy_priv(wiphy);
  200. struct wilc_vif *vif;
  201. u32 channelnum;
  202. int result;
  203. int srcu_idx;
  204. srcu_idx = srcu_read_lock(&wl->srcu);
  205. vif = wilc_get_wl_to_vif(wl);
  206. if (IS_ERR(vif)) {
  207. srcu_read_unlock(&wl->srcu, srcu_idx);
  208. return PTR_ERR(vif);
  209. }
  210. channelnum = ieee80211_frequency_to_channel(chandef->chan->center_freq);
  211. wl->op_ch = channelnum;
  212. result = wilc_set_mac_chnl_num(vif, channelnum);
  213. if (result)
  214. netdev_err(vif->ndev, "Error in setting channel\n");
  215. srcu_read_unlock(&wl->srcu, srcu_idx);
  216. return result;
  217. }
  218. static int scan(struct wiphy *wiphy, struct cfg80211_scan_request *request)
  219. {
  220. struct wilc_vif *vif = netdev_priv(request->wdev->netdev);
  221. struct wilc_priv *priv = &vif->priv;
  222. u32 i;
  223. int ret = 0;
  224. u8 scan_ch_list[WILC_MAX_NUM_SCANNED_CH];
  225. u8 scan_type;
  226. if (request->n_channels > WILC_MAX_NUM_SCANNED_CH) {
  227. netdev_err(vif->ndev, "Requested scanned channels over\n");
  228. return -EINVAL;
  229. }
  230. priv->scan_req = request;
  231. priv->cfg_scanning = true;
  232. for (i = 0; i < request->n_channels; i++) {
  233. u16 freq = request->channels[i]->center_freq;
  234. scan_ch_list[i] = ieee80211_frequency_to_channel(freq);
  235. }
  236. if (request->n_ssids)
  237. scan_type = WILC_FW_ACTIVE_SCAN;
  238. else
  239. scan_type = WILC_FW_PASSIVE_SCAN;
  240. ret = wilc_scan(vif, WILC_FW_USER_SCAN, scan_type, scan_ch_list,
  241. request->n_channels, cfg_scan_result, (void *)priv,
  242. request);
  243. if (ret) {
  244. priv->scan_req = NULL;
  245. priv->cfg_scanning = false;
  246. }
  247. return ret;
  248. }
  249. static int connect(struct wiphy *wiphy, struct net_device *dev,
  250. struct cfg80211_connect_params *sme)
  251. {
  252. struct wilc_vif *vif = netdev_priv(dev);
  253. struct wilc_priv *priv = &vif->priv;
  254. struct host_if_drv *wfi_drv = priv->hif_drv;
  255. int ret;
  256. u32 i;
  257. u8 security = WILC_FW_SEC_NO;
  258. enum mfptype mfp_type = WILC_FW_MFP_NONE;
  259. enum authtype auth_type = WILC_FW_AUTH_ANY;
  260. u32 cipher_group;
  261. struct cfg80211_bss *bss;
  262. void *join_params;
  263. u8 ch;
  264. vif->connecting = true;
  265. cipher_group = sme->crypto.cipher_group;
  266. if (cipher_group != 0) {
  267. if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_2) {
  268. if (cipher_group == WLAN_CIPHER_SUITE_TKIP)
  269. security = WILC_FW_SEC_WPA2_TKIP;
  270. else
  271. security = WILC_FW_SEC_WPA2_AES;
  272. } else if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_1) {
  273. if (cipher_group == WLAN_CIPHER_SUITE_TKIP)
  274. security = WILC_FW_SEC_WPA_TKIP;
  275. else
  276. security = WILC_FW_SEC_WPA_AES;
  277. } else {
  278. ret = -ENOTSUPP;
  279. netdev_err(dev, "%s: Unsupported cipher\n",
  280. __func__);
  281. goto out_error;
  282. }
  283. }
  284. if ((sme->crypto.wpa_versions & NL80211_WPA_VERSION_1) ||
  285. (sme->crypto.wpa_versions & NL80211_WPA_VERSION_2)) {
  286. for (i = 0; i < sme->crypto.n_ciphers_pairwise; i++) {
  287. u32 ciphers_pairwise = sme->crypto.ciphers_pairwise[i];
  288. if (ciphers_pairwise == WLAN_CIPHER_SUITE_TKIP)
  289. security |= WILC_FW_TKIP;
  290. else
  291. security |= WILC_FW_AES;
  292. }
  293. }
  294. switch (sme->auth_type) {
  295. case NL80211_AUTHTYPE_OPEN_SYSTEM:
  296. auth_type = WILC_FW_AUTH_OPEN_SYSTEM;
  297. break;
  298. case NL80211_AUTHTYPE_SAE:
  299. auth_type = WILC_FW_AUTH_SAE;
  300. if (sme->ssid_len) {
  301. memcpy(vif->auth.ssid.ssid, sme->ssid, sme->ssid_len);
  302. vif->auth.ssid.ssid_len = sme->ssid_len;
  303. }
  304. vif->auth.key_mgmt_suite = cpu_to_be32(sme->crypto.akm_suites[0]);
  305. ether_addr_copy(vif->auth.bssid, sme->bssid);
  306. break;
  307. default:
  308. break;
  309. }
  310. if (sme->crypto.n_akm_suites) {
  311. if (sme->crypto.akm_suites[0] == WLAN_AKM_SUITE_8021X)
  312. auth_type = WILC_FW_AUTH_IEEE8021;
  313. else if (sme->crypto.akm_suites[0] == WLAN_AKM_SUITE_PSK_SHA256)
  314. auth_type = WILC_FW_AUTH_OPEN_SYSTEM_SHA256;
  315. else if (sme->crypto.akm_suites[0] == WLAN_AKM_SUITE_8021X_SHA256)
  316. auth_type = WILC_FW_AUTH_IEE8021X_SHA256;
  317. }
  318. if (wfi_drv->usr_scan_req.scan_result) {
  319. netdev_err(vif->ndev, "%s: Scan in progress\n", __func__);
  320. ret = -EBUSY;
  321. goto out_error;
  322. }
  323. bss = cfg80211_get_bss(wiphy, sme->channel, sme->bssid, sme->ssid,
  324. sme->ssid_len, IEEE80211_BSS_TYPE_ANY,
  325. IEEE80211_PRIVACY(sme->privacy));
  326. if (!bss) {
  327. ret = -EINVAL;
  328. goto out_error;
  329. }
  330. if (ether_addr_equal_unaligned(vif->bssid, bss->bssid)) {
  331. ret = -EALREADY;
  332. goto out_put_bss;
  333. }
  334. join_params = wilc_parse_join_bss_param(bss, &sme->crypto);
  335. if (!join_params) {
  336. netdev_err(dev, "%s: failed to construct join param\n",
  337. __func__);
  338. ret = -EINVAL;
  339. goto out_put_bss;
  340. }
  341. ch = ieee80211_frequency_to_channel(bss->channel->center_freq);
  342. vif->wilc->op_ch = ch;
  343. if (vif->iftype != WILC_CLIENT_MODE)
  344. vif->wilc->sta_ch = ch;
  345. wilc_wlan_set_bssid(dev, bss->bssid, WILC_STATION_MODE);
  346. wfi_drv->conn_info.security = security;
  347. wfi_drv->conn_info.auth_type = auth_type;
  348. wfi_drv->conn_info.ch = ch;
  349. wfi_drv->conn_info.conn_result = cfg_connect_result;
  350. wfi_drv->conn_info.arg = priv;
  351. wfi_drv->conn_info.param = join_params;
  352. if (sme->mfp == NL80211_MFP_OPTIONAL)
  353. mfp_type = WILC_FW_MFP_OPTIONAL;
  354. else if (sme->mfp == NL80211_MFP_REQUIRED)
  355. mfp_type = WILC_FW_MFP_REQUIRED;
  356. wfi_drv->conn_info.mfp_type = mfp_type;
  357. ret = wilc_set_join_req(vif, bss->bssid, sme->ie, sme->ie_len);
  358. if (ret) {
  359. netdev_err(dev, "wilc_set_join_req(): Error\n");
  360. ret = -ENOENT;
  361. if (vif->iftype != WILC_CLIENT_MODE)
  362. vif->wilc->sta_ch = WILC_INVALID_CHANNEL;
  363. wilc_wlan_set_bssid(dev, NULL, WILC_STATION_MODE);
  364. wfi_drv->conn_info.conn_result = NULL;
  365. kfree(join_params);
  366. goto out_put_bss;
  367. }
  368. kfree(join_params);
  369. vif->bss = bss;
  370. cfg80211_put_bss(wiphy, bss);
  371. return 0;
  372. out_put_bss:
  373. cfg80211_put_bss(wiphy, bss);
  374. out_error:
  375. vif->connecting = false;
  376. return ret;
  377. }
  378. static int disconnect(struct wiphy *wiphy, struct net_device *dev,
  379. u16 reason_code)
  380. {
  381. struct wilc_vif *vif = netdev_priv(dev);
  382. struct wilc_priv *priv = &vif->priv;
  383. struct wilc *wilc = vif->wilc;
  384. int ret;
  385. vif->connecting = false;
  386. if (!wilc)
  387. return -EIO;
  388. if (wilc->close) {
  389. /* already disconnected done */
  390. cfg80211_disconnected(dev, 0, NULL, 0, true, GFP_KERNEL);
  391. return 0;
  392. }
  393. if (vif->iftype != WILC_CLIENT_MODE)
  394. wilc->sta_ch = WILC_INVALID_CHANNEL;
  395. wilc_wlan_set_bssid(priv->dev, NULL, WILC_STATION_MODE);
  396. priv->hif_drv->p2p_timeout = 0;
  397. ret = wilc_disconnect(vif);
  398. if (ret != 0) {
  399. netdev_err(priv->dev, "Error in disconnecting\n");
  400. ret = -EINVAL;
  401. }
  402. vif->bss = NULL;
  403. return ret;
  404. }
  405. static int wilc_wfi_cfg_allocate_wpa_entry(struct wilc_priv *priv, u8 idx)
  406. {
  407. if (!priv->wilc_gtk[idx]) {
  408. priv->wilc_gtk[idx] = kzalloc(sizeof(*priv->wilc_gtk[idx]),
  409. GFP_KERNEL);
  410. if (!priv->wilc_gtk[idx])
  411. return -ENOMEM;
  412. }
  413. if (!priv->wilc_ptk[idx]) {
  414. priv->wilc_ptk[idx] = kzalloc(sizeof(*priv->wilc_ptk[idx]),
  415. GFP_KERNEL);
  416. if (!priv->wilc_ptk[idx])
  417. return -ENOMEM;
  418. }
  419. return 0;
  420. }
  421. static int wilc_wfi_cfg_allocate_wpa_igtk_entry(struct wilc_priv *priv, u8 idx)
  422. {
  423. idx -= 4;
  424. if (!priv->wilc_igtk[idx]) {
  425. priv->wilc_igtk[idx] = kzalloc(sizeof(*priv->wilc_igtk[idx]),
  426. GFP_KERNEL);
  427. if (!priv->wilc_igtk[idx])
  428. return -ENOMEM;
  429. }
  430. return 0;
  431. }
  432. static int wilc_wfi_cfg_copy_wpa_info(struct wilc_wfi_key *key_info,
  433. struct key_params *params)
  434. {
  435. kfree(key_info->key);
  436. key_info->key = kmemdup(params->key, params->key_len, GFP_KERNEL);
  437. if (!key_info->key)
  438. return -ENOMEM;
  439. kfree(key_info->seq);
  440. if (params->seq_len > 0) {
  441. key_info->seq = kmemdup(params->seq, params->seq_len,
  442. GFP_KERNEL);
  443. if (!key_info->seq)
  444. return -ENOMEM;
  445. }
  446. key_info->cipher = params->cipher;
  447. key_info->key_len = params->key_len;
  448. key_info->seq_len = params->seq_len;
  449. return 0;
  450. }
  451. static int add_key(struct wiphy *wiphy, struct net_device *netdev, int link_id,
  452. u8 key_index, bool pairwise, const u8 *mac_addr,
  453. struct key_params *params)
  454. {
  455. int ret = 0, keylen = params->key_len;
  456. const u8 *rx_mic = NULL;
  457. const u8 *tx_mic = NULL;
  458. u8 mode = WILC_FW_SEC_NO;
  459. u8 op_mode;
  460. struct wilc_vif *vif = netdev_priv(netdev);
  461. struct wilc_priv *priv = &vif->priv;
  462. struct wilc_wfi_key *key;
  463. switch (params->cipher) {
  464. case WLAN_CIPHER_SUITE_TKIP:
  465. case WLAN_CIPHER_SUITE_CCMP:
  466. if (priv->wdev.iftype == NL80211_IFTYPE_AP ||
  467. priv->wdev.iftype == NL80211_IFTYPE_P2P_GO) {
  468. struct wilc_wfi_key *key;
  469. ret = wilc_wfi_cfg_allocate_wpa_entry(priv, key_index);
  470. if (ret)
  471. return -ENOMEM;
  472. if (params->key_len > 16 &&
  473. params->cipher == WLAN_CIPHER_SUITE_TKIP) {
  474. tx_mic = params->key + 24;
  475. rx_mic = params->key + 16;
  476. keylen = params->key_len - 16;
  477. }
  478. if (!pairwise) {
  479. if (params->cipher == WLAN_CIPHER_SUITE_TKIP)
  480. mode = WILC_FW_SEC_WPA_TKIP;
  481. else
  482. mode = WILC_FW_SEC_WPA2_AES;
  483. priv->wilc_groupkey = mode;
  484. key = priv->wilc_gtk[key_index];
  485. } else {
  486. if (params->cipher == WLAN_CIPHER_SUITE_TKIP)
  487. mode = WILC_FW_SEC_WPA_TKIP;
  488. else
  489. mode = priv->wilc_groupkey | WILC_FW_AES;
  490. key = priv->wilc_ptk[key_index];
  491. }
  492. ret = wilc_wfi_cfg_copy_wpa_info(key, params);
  493. if (ret)
  494. return -ENOMEM;
  495. op_mode = WILC_AP_MODE;
  496. } else {
  497. if (params->key_len > 16 &&
  498. params->cipher == WLAN_CIPHER_SUITE_TKIP) {
  499. rx_mic = params->key + 24;
  500. tx_mic = params->key + 16;
  501. keylen = params->key_len - 16;
  502. }
  503. op_mode = WILC_STATION_MODE;
  504. }
  505. if (!pairwise)
  506. ret = wilc_add_rx_gtk(vif, params->key, keylen,
  507. key_index, params->seq_len,
  508. params->seq, rx_mic, tx_mic,
  509. op_mode, mode);
  510. else
  511. ret = wilc_add_ptk(vif, params->key, keylen, mac_addr,
  512. rx_mic, tx_mic, op_mode, mode,
  513. key_index);
  514. break;
  515. case WLAN_CIPHER_SUITE_AES_CMAC:
  516. ret = wilc_wfi_cfg_allocate_wpa_igtk_entry(priv, key_index);
  517. if (ret)
  518. return -ENOMEM;
  519. key = priv->wilc_igtk[key_index - 4];
  520. ret = wilc_wfi_cfg_copy_wpa_info(key, params);
  521. if (ret)
  522. return -ENOMEM;
  523. if (priv->wdev.iftype == NL80211_IFTYPE_AP ||
  524. priv->wdev.iftype == NL80211_IFTYPE_P2P_GO)
  525. op_mode = WILC_AP_MODE;
  526. else
  527. op_mode = WILC_STATION_MODE;
  528. ret = wilc_add_igtk(vif, params->key, keylen, params->seq,
  529. params->seq_len, mac_addr, op_mode,
  530. key_index);
  531. break;
  532. default:
  533. netdev_err(netdev, "%s: Unsupported cipher\n", __func__);
  534. ret = -ENOTSUPP;
  535. }
  536. return ret;
  537. }
  538. static int del_key(struct wiphy *wiphy, struct net_device *netdev, int link_id,
  539. u8 key_index,
  540. bool pairwise,
  541. const u8 *mac_addr)
  542. {
  543. struct wilc_vif *vif = netdev_priv(netdev);
  544. struct wilc_priv *priv = &vif->priv;
  545. if (!pairwise && (key_index == 4 || key_index == 5)) {
  546. key_index -= 4;
  547. if (priv->wilc_igtk[key_index]) {
  548. kfree(priv->wilc_igtk[key_index]->key);
  549. priv->wilc_igtk[key_index]->key = NULL;
  550. kfree(priv->wilc_igtk[key_index]->seq);
  551. priv->wilc_igtk[key_index]->seq = NULL;
  552. kfree(priv->wilc_igtk[key_index]);
  553. priv->wilc_igtk[key_index] = NULL;
  554. }
  555. } else {
  556. if (priv->wilc_gtk[key_index]) {
  557. kfree(priv->wilc_gtk[key_index]->key);
  558. priv->wilc_gtk[key_index]->key = NULL;
  559. kfree(priv->wilc_gtk[key_index]->seq);
  560. priv->wilc_gtk[key_index]->seq = NULL;
  561. kfree(priv->wilc_gtk[key_index]);
  562. priv->wilc_gtk[key_index] = NULL;
  563. }
  564. if (priv->wilc_ptk[key_index]) {
  565. kfree(priv->wilc_ptk[key_index]->key);
  566. priv->wilc_ptk[key_index]->key = NULL;
  567. kfree(priv->wilc_ptk[key_index]->seq);
  568. priv->wilc_ptk[key_index]->seq = NULL;
  569. kfree(priv->wilc_ptk[key_index]);
  570. priv->wilc_ptk[key_index] = NULL;
  571. }
  572. }
  573. return 0;
  574. }
  575. static int get_key(struct wiphy *wiphy, struct net_device *netdev, int link_id,
  576. u8 key_index, bool pairwise, const u8 *mac_addr,
  577. void *cookie,
  578. void (*callback)(void *cookie, struct key_params *))
  579. {
  580. struct wilc_vif *vif = netdev_priv(netdev);
  581. struct wilc_priv *priv = &vif->priv;
  582. struct key_params key_params;
  583. if (!pairwise) {
  584. if (key_index == 4 || key_index == 5) {
  585. key_index -= 4;
  586. key_params.key = priv->wilc_igtk[key_index]->key;
  587. key_params.cipher = priv->wilc_igtk[key_index]->cipher;
  588. key_params.key_len = priv->wilc_igtk[key_index]->key_len;
  589. key_params.seq = priv->wilc_igtk[key_index]->seq;
  590. key_params.seq_len = priv->wilc_igtk[key_index]->seq_len;
  591. } else {
  592. key_params.key = priv->wilc_gtk[key_index]->key;
  593. key_params.cipher = priv->wilc_gtk[key_index]->cipher;
  594. key_params.key_len = priv->wilc_gtk[key_index]->key_len;
  595. key_params.seq = priv->wilc_gtk[key_index]->seq;
  596. key_params.seq_len = priv->wilc_gtk[key_index]->seq_len;
  597. }
  598. } else {
  599. key_params.key = priv->wilc_ptk[key_index]->key;
  600. key_params.cipher = priv->wilc_ptk[key_index]->cipher;
  601. key_params.key_len = priv->wilc_ptk[key_index]->key_len;
  602. key_params.seq = priv->wilc_ptk[key_index]->seq;
  603. key_params.seq_len = priv->wilc_ptk[key_index]->seq_len;
  604. }
  605. callback(cookie, &key_params);
  606. return 0;
  607. }
  608. /* wiphy_new_nm() will WARNON if not present */
  609. static int set_default_key(struct wiphy *wiphy, struct net_device *netdev,
  610. int link_id, u8 key_index, bool unicast,
  611. bool multicast)
  612. {
  613. return 0;
  614. }
  615. static int set_default_mgmt_key(struct wiphy *wiphy, struct net_device *netdev,
  616. int link_id, u8 key_index)
  617. {
  618. struct wilc_vif *vif = netdev_priv(netdev);
  619. return wilc_set_default_mgmt_key_index(vif, key_index);
  620. }
  621. static int get_station(struct wiphy *wiphy, struct net_device *dev,
  622. const u8 *mac, struct station_info *sinfo)
  623. {
  624. struct wilc_vif *vif = netdev_priv(dev);
  625. struct wilc_priv *priv = &vif->priv;
  626. struct wilc *wilc = vif->wilc;
  627. u32 i = 0;
  628. u32 associatedsta = ~0;
  629. u32 inactive_time = 0;
  630. if (vif->iftype == WILC_AP_MODE || vif->iftype == WILC_GO_MODE) {
  631. for (i = 0; i < NUM_STA_ASSOCIATED; i++) {
  632. if (!(memcmp(mac,
  633. priv->assoc_stainfo.sta_associated_bss[i],
  634. ETH_ALEN))) {
  635. associatedsta = i;
  636. break;
  637. }
  638. }
  639. if (associatedsta == ~0) {
  640. netdev_err(dev, "sta required is not associated\n");
  641. return -ENOENT;
  642. }
  643. sinfo->filled |= BIT_ULL(NL80211_STA_INFO_INACTIVE_TIME);
  644. wilc_get_inactive_time(vif, mac, &inactive_time);
  645. sinfo->inactive_time = 1000 * inactive_time;
  646. } else if (vif->iftype == WILC_STATION_MODE) {
  647. struct rf_info stats;
  648. if (!wilc->initialized)
  649. return -EBUSY;
  650. wilc_get_statistics(vif, &stats);
  651. sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL) |
  652. BIT_ULL(NL80211_STA_INFO_RX_PACKETS) |
  653. BIT_ULL(NL80211_STA_INFO_TX_PACKETS) |
  654. BIT_ULL(NL80211_STA_INFO_TX_FAILED) |
  655. BIT_ULL(NL80211_STA_INFO_TX_BITRATE);
  656. sinfo->signal = stats.rssi;
  657. sinfo->rx_packets = stats.rx_cnt;
  658. sinfo->tx_packets = stats.tx_cnt + stats.tx_fail_cnt;
  659. sinfo->tx_failed = stats.tx_fail_cnt;
  660. sinfo->txrate.legacy = stats.link_speed * 10;
  661. if (stats.link_speed > TCP_ACK_FILTER_LINK_SPEED_THRESH &&
  662. stats.link_speed != DEFAULT_LINK_SPEED)
  663. wilc_enable_tcp_ack_filter(vif, true);
  664. else if (stats.link_speed != DEFAULT_LINK_SPEED)
  665. wilc_enable_tcp_ack_filter(vif, false);
  666. }
  667. return 0;
  668. }
  669. static int change_bss(struct wiphy *wiphy, struct net_device *dev,
  670. struct bss_parameters *params)
  671. {
  672. return 0;
  673. }
  674. static int set_wiphy_params(struct wiphy *wiphy, u32 changed)
  675. {
  676. int ret = -EINVAL;
  677. struct cfg_param_attr cfg_param_val;
  678. struct wilc *wl = wiphy_priv(wiphy);
  679. struct wilc_vif *vif;
  680. struct wilc_priv *priv;
  681. int srcu_idx;
  682. srcu_idx = srcu_read_lock(&wl->srcu);
  683. vif = wilc_get_wl_to_vif(wl);
  684. if (IS_ERR(vif))
  685. goto out;
  686. priv = &vif->priv;
  687. cfg_param_val.flag = 0;
  688. if (changed & WIPHY_PARAM_RETRY_SHORT) {
  689. netdev_dbg(vif->ndev,
  690. "Setting WIPHY_PARAM_RETRY_SHORT %d\n",
  691. wiphy->retry_short);
  692. cfg_param_val.flag |= WILC_CFG_PARAM_RETRY_SHORT;
  693. cfg_param_val.short_retry_limit = wiphy->retry_short;
  694. }
  695. if (changed & WIPHY_PARAM_RETRY_LONG) {
  696. netdev_dbg(vif->ndev,
  697. "Setting WIPHY_PARAM_RETRY_LONG %d\n",
  698. wiphy->retry_long);
  699. cfg_param_val.flag |= WILC_CFG_PARAM_RETRY_LONG;
  700. cfg_param_val.long_retry_limit = wiphy->retry_long;
  701. }
  702. if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
  703. if (wiphy->frag_threshold > 255 &&
  704. wiphy->frag_threshold < 7937) {
  705. netdev_dbg(vif->ndev,
  706. "Setting WIPHY_PARAM_FRAG_THRESHOLD %d\n",
  707. wiphy->frag_threshold);
  708. cfg_param_val.flag |= WILC_CFG_PARAM_FRAG_THRESHOLD;
  709. cfg_param_val.frag_threshold = wiphy->frag_threshold;
  710. } else {
  711. netdev_err(vif->ndev,
  712. "Fragmentation threshold out of range\n");
  713. goto out;
  714. }
  715. }
  716. if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
  717. if (wiphy->rts_threshold > 255) {
  718. netdev_dbg(vif->ndev,
  719. "Setting WIPHY_PARAM_RTS_THRESHOLD %d\n",
  720. wiphy->rts_threshold);
  721. cfg_param_val.flag |= WILC_CFG_PARAM_RTS_THRESHOLD;
  722. cfg_param_val.rts_threshold = wiphy->rts_threshold;
  723. } else {
  724. netdev_err(vif->ndev, "RTS threshold out of range\n");
  725. goto out;
  726. }
  727. }
  728. ret = wilc_hif_set_cfg(vif, &cfg_param_val);
  729. if (ret)
  730. netdev_err(priv->dev, "Error in setting WIPHY PARAMS\n");
  731. out:
  732. srcu_read_unlock(&wl->srcu, srcu_idx);
  733. return ret;
  734. }
  735. static int set_pmksa(struct wiphy *wiphy, struct net_device *netdev,
  736. struct cfg80211_pmksa *pmksa)
  737. {
  738. struct wilc_vif *vif = netdev_priv(netdev);
  739. struct wilc_priv *priv = &vif->priv;
  740. u32 i;
  741. int ret = 0;
  742. u8 flag = 0;
  743. for (i = 0; i < priv->pmkid_list.numpmkid; i++) {
  744. if (!memcmp(pmksa->bssid, priv->pmkid_list.pmkidlist[i].bssid,
  745. ETH_ALEN)) {
  746. flag = PMKID_FOUND;
  747. break;
  748. }
  749. }
  750. if (i < WILC_MAX_NUM_PMKIDS) {
  751. memcpy(priv->pmkid_list.pmkidlist[i].bssid, pmksa->bssid,
  752. ETH_ALEN);
  753. memcpy(priv->pmkid_list.pmkidlist[i].pmkid, pmksa->pmkid,
  754. WLAN_PMKID_LEN);
  755. if (!(flag == PMKID_FOUND))
  756. priv->pmkid_list.numpmkid++;
  757. } else {
  758. netdev_err(netdev, "Invalid PMKID index\n");
  759. ret = -EINVAL;
  760. }
  761. if (!ret)
  762. ret = wilc_set_pmkid_info(vif, &priv->pmkid_list);
  763. return ret;
  764. }
  765. static int del_pmksa(struct wiphy *wiphy, struct net_device *netdev,
  766. struct cfg80211_pmksa *pmksa)
  767. {
  768. u32 i;
  769. struct wilc_vif *vif = netdev_priv(netdev);
  770. struct wilc_priv *priv = &vif->priv;
  771. for (i = 0; i < priv->pmkid_list.numpmkid; i++) {
  772. if (!memcmp(pmksa->bssid, priv->pmkid_list.pmkidlist[i].bssid,
  773. ETH_ALEN)) {
  774. memset(&priv->pmkid_list.pmkidlist[i], 0,
  775. sizeof(struct wilc_pmkid));
  776. break;
  777. }
  778. }
  779. if (i == priv->pmkid_list.numpmkid)
  780. return -EINVAL;
  781. for (; i < (priv->pmkid_list.numpmkid - 1); i++) {
  782. memcpy(priv->pmkid_list.pmkidlist[i].bssid,
  783. priv->pmkid_list.pmkidlist[i + 1].bssid,
  784. ETH_ALEN);
  785. memcpy(priv->pmkid_list.pmkidlist[i].pmkid,
  786. priv->pmkid_list.pmkidlist[i + 1].pmkid,
  787. WLAN_PMKID_LEN);
  788. }
  789. priv->pmkid_list.numpmkid--;
  790. return 0;
  791. }
  792. static int flush_pmksa(struct wiphy *wiphy, struct net_device *netdev)
  793. {
  794. struct wilc_vif *vif = netdev_priv(netdev);
  795. memset(&vif->priv.pmkid_list, 0, sizeof(struct wilc_pmkid_attr));
  796. return 0;
  797. }
  798. static inline void wilc_wfi_cfg_parse_ch_attr(u8 *buf, u32 len, u8 sta_ch)
  799. {
  800. struct wilc_attr_entry *e;
  801. struct wilc_attr_ch_list *ch_list;
  802. struct wilc_attr_oper_ch *op_ch;
  803. u32 index = 0;
  804. u8 ch_list_idx = 0;
  805. u8 op_ch_idx = 0;
  806. if (sta_ch == WILC_INVALID_CHANNEL)
  807. return;
  808. while (index + sizeof(*e) <= len) {
  809. u16 attr_size;
  810. e = (struct wilc_attr_entry *)&buf[index];
  811. attr_size = le16_to_cpu(e->attr_len);
  812. if (index + sizeof(*e) + attr_size > len)
  813. return;
  814. if (e->attr_type == IEEE80211_P2P_ATTR_CHANNEL_LIST &&
  815. attr_size >= (sizeof(struct wilc_attr_ch_list) - sizeof(*e)))
  816. ch_list_idx = index;
  817. else if (e->attr_type == IEEE80211_P2P_ATTR_OPER_CHANNEL &&
  818. attr_size == (sizeof(struct wilc_attr_oper_ch) - sizeof(*e)))
  819. op_ch_idx = index;
  820. if (ch_list_idx && op_ch_idx)
  821. break;
  822. index += sizeof(*e) + attr_size;
  823. }
  824. if (ch_list_idx) {
  825. u16 elem_size;
  826. ch_list = (struct wilc_attr_ch_list *)&buf[ch_list_idx];
  827. /* the number of bytes following the final 'elem' member */
  828. elem_size = le16_to_cpu(ch_list->attr_len) -
  829. (sizeof(*ch_list) - sizeof(struct wilc_attr_entry));
  830. for (unsigned int i = 0; i < elem_size;) {
  831. struct wilc_ch_list_elem *e;
  832. e = (struct wilc_ch_list_elem *)(ch_list->elem + i);
  833. i += sizeof(*e);
  834. if (i > elem_size)
  835. break;
  836. i += e->no_of_channels;
  837. if (i > elem_size)
  838. break;
  839. if (e->op_class == WILC_WLAN_OPERATING_CLASS_2_4GHZ) {
  840. memset(e->ch_list, sta_ch, e->no_of_channels);
  841. break;
  842. }
  843. }
  844. }
  845. if (op_ch_idx) {
  846. op_ch = (struct wilc_attr_oper_ch *)&buf[op_ch_idx];
  847. op_ch->op_class = WILC_WLAN_OPERATING_CLASS_2_4GHZ;
  848. op_ch->op_channel = sta_ch;
  849. }
  850. }
  851. bool wilc_wfi_mgmt_frame_rx(struct wilc_vif *vif, u8 *buff, u32 size)
  852. {
  853. struct wilc *wl = vif->wilc;
  854. struct wilc_priv *priv = &vif->priv;
  855. int freq;
  856. freq = ieee80211_channel_to_frequency(wl->op_ch, NL80211_BAND_2GHZ);
  857. return cfg80211_rx_mgmt(&priv->wdev, freq, 0, buff, size, 0);
  858. }
  859. void wilc_wfi_p2p_rx(struct wilc_vif *vif, u8 *buff, u32 size)
  860. {
  861. struct wilc *wl = vif->wilc;
  862. struct wilc_priv *priv = &vif->priv;
  863. struct host_if_drv *wfi_drv = priv->hif_drv;
  864. struct ieee80211_mgmt *mgmt;
  865. struct wilc_vendor_specific_ie *p;
  866. struct wilc_p2p_pub_act_frame *d;
  867. int ie_offset = offsetof(struct ieee80211_mgmt, u) + sizeof(*d);
  868. const u8 *vendor_ie;
  869. u32 header, pkt_offset;
  870. s32 freq;
  871. header = get_unaligned_le32(buff - HOST_HDR_OFFSET);
  872. pkt_offset = FIELD_GET(WILC_PKT_HDR_OFFSET_FIELD, header);
  873. if (pkt_offset & IS_MANAGMEMENT_CALLBACK) {
  874. bool ack = false;
  875. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)buff;
  876. if (ieee80211_is_probe_resp(hdr->frame_control) ||
  877. pkt_offset & IS_MGMT_STATUS_SUCCES)
  878. ack = true;
  879. cfg80211_mgmt_tx_status(&priv->wdev, priv->tx_cookie, buff,
  880. size, ack, GFP_KERNEL);
  881. return;
  882. }
  883. freq = ieee80211_channel_to_frequency(wl->op_ch, NL80211_BAND_2GHZ);
  884. mgmt = (struct ieee80211_mgmt *)buff;
  885. if (!ieee80211_is_action(mgmt->frame_control))
  886. goto out_rx_mgmt;
  887. if (priv->cfg_scanning &&
  888. time_after_eq(jiffies, (unsigned long)wfi_drv->p2p_timeout)) {
  889. netdev_dbg(vif->ndev, "Receiving action wrong ch\n");
  890. return;
  891. }
  892. if (!ieee80211_is_public_action((struct ieee80211_hdr *)buff, size))
  893. goto out_rx_mgmt;
  894. d = (struct wilc_p2p_pub_act_frame *)(&mgmt->u.action);
  895. if (d->oui_subtype != GO_NEG_REQ && d->oui_subtype != GO_NEG_RSP &&
  896. d->oui_subtype != P2P_INV_REQ && d->oui_subtype != P2P_INV_RSP)
  897. goto out_rx_mgmt;
  898. vendor_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
  899. buff + ie_offset, size - ie_offset);
  900. if (!vendor_ie)
  901. goto out_rx_mgmt;
  902. p = (struct wilc_vendor_specific_ie *)vendor_ie;
  903. wilc_wfi_cfg_parse_ch_attr(p->attr, p->tag_len - 4, vif->wilc->sta_ch);
  904. out_rx_mgmt:
  905. cfg80211_rx_mgmt(&priv->wdev, freq, 0, buff, size, 0);
  906. }
  907. static void wilc_wfi_mgmt_tx_complete(void *priv, int status)
  908. {
  909. struct wilc_p2p_mgmt_data *pv_data = priv;
  910. kfree(pv_data->buff);
  911. kfree(pv_data);
  912. }
  913. static void wilc_wfi_remain_on_channel_expired(void *data, u64 cookie)
  914. {
  915. struct wilc_vif *vif = data;
  916. struct wilc_priv *priv = &vif->priv;
  917. struct wilc_wfi_p2p_listen_params *params = &priv->remain_on_ch_params;
  918. if (cookie != params->listen_cookie)
  919. return;
  920. priv->p2p_listen_state = false;
  921. cfg80211_remain_on_channel_expired(&priv->wdev, params->listen_cookie,
  922. params->listen_ch, GFP_KERNEL);
  923. }
  924. static int remain_on_channel(struct wiphy *wiphy,
  925. struct wireless_dev *wdev,
  926. struct ieee80211_channel *chan,
  927. unsigned int duration, u64 *cookie)
  928. {
  929. int ret = 0;
  930. struct wilc_vif *vif = netdev_priv(wdev->netdev);
  931. struct wilc_priv *priv = &vif->priv;
  932. u64 id;
  933. if (wdev->iftype == NL80211_IFTYPE_AP) {
  934. netdev_dbg(vif->ndev, "Required while in AP mode\n");
  935. return ret;
  936. }
  937. id = ++priv->inc_roc_cookie;
  938. if (id == 0)
  939. id = ++priv->inc_roc_cookie;
  940. ret = wilc_remain_on_channel(vif, id, duration, chan->hw_value,
  941. wilc_wfi_remain_on_channel_expired,
  942. (void *)vif);
  943. if (ret)
  944. return ret;
  945. vif->wilc->op_ch = chan->hw_value;
  946. priv->remain_on_ch_params.listen_ch = chan;
  947. priv->remain_on_ch_params.listen_cookie = id;
  948. *cookie = id;
  949. priv->p2p_listen_state = true;
  950. priv->remain_on_ch_params.listen_duration = duration;
  951. cfg80211_ready_on_channel(wdev, *cookie, chan, duration, GFP_KERNEL);
  952. mod_timer(&vif->hif_drv->remain_on_ch_timer,
  953. jiffies + msecs_to_jiffies(duration + 1000));
  954. return ret;
  955. }
  956. static int cancel_remain_on_channel(struct wiphy *wiphy,
  957. struct wireless_dev *wdev,
  958. u64 cookie)
  959. {
  960. struct wilc_vif *vif = netdev_priv(wdev->netdev);
  961. struct wilc_priv *priv = &vif->priv;
  962. if (cookie != priv->remain_on_ch_params.listen_cookie)
  963. return -ENOENT;
  964. return wilc_listen_state_expired(vif, cookie);
  965. }
  966. static int mgmt_tx(struct wiphy *wiphy,
  967. struct wireless_dev *wdev,
  968. struct cfg80211_mgmt_tx_params *params,
  969. u64 *cookie)
  970. {
  971. struct ieee80211_channel *chan = params->chan;
  972. unsigned int wait = params->wait;
  973. const u8 *buf = params->buf;
  974. size_t len = params->len;
  975. const struct ieee80211_mgmt *mgmt;
  976. struct wilc_p2p_mgmt_data *mgmt_tx;
  977. struct wilc_vif *vif = netdev_priv(wdev->netdev);
  978. struct wilc_priv *priv = &vif->priv;
  979. struct host_if_drv *wfi_drv = priv->hif_drv;
  980. struct wilc_vendor_specific_ie *p;
  981. struct wilc_p2p_pub_act_frame *d;
  982. int ie_offset = offsetof(struct ieee80211_mgmt, u) + sizeof(*d);
  983. const u8 *vendor_ie;
  984. int ret = 0;
  985. *cookie = get_random_u32();
  986. priv->tx_cookie = *cookie;
  987. mgmt = (const struct ieee80211_mgmt *)buf;
  988. if (!ieee80211_is_mgmt(mgmt->frame_control))
  989. goto out;
  990. mgmt_tx = kmalloc(sizeof(*mgmt_tx), GFP_KERNEL);
  991. if (!mgmt_tx) {
  992. ret = -ENOMEM;
  993. goto out;
  994. }
  995. mgmt_tx->buff = kmemdup(buf, len, GFP_KERNEL);
  996. if (!mgmt_tx->buff) {
  997. ret = -ENOMEM;
  998. kfree(mgmt_tx);
  999. goto out;
  1000. }
  1001. mgmt_tx->size = len;
  1002. if (ieee80211_is_probe_resp(mgmt->frame_control)) {
  1003. wilc_set_mac_chnl_num(vif, chan->hw_value);
  1004. vif->wilc->op_ch = chan->hw_value;
  1005. goto out_txq_add_pkt;
  1006. }
  1007. if (!ieee80211_is_public_action((struct ieee80211_hdr *)buf, len)) {
  1008. if (chan)
  1009. wilc_set_mac_chnl_num(vif, chan->hw_value);
  1010. else
  1011. wilc_set_mac_chnl_num(vif, vif->wilc->op_ch);
  1012. goto out_set_timeout;
  1013. }
  1014. d = (struct wilc_p2p_pub_act_frame *)(&mgmt->u.action);
  1015. if (d->oui_type != WLAN_OUI_TYPE_WFA_P2P ||
  1016. d->oui_subtype != GO_NEG_CONF) {
  1017. wilc_set_mac_chnl_num(vif, chan->hw_value);
  1018. vif->wilc->op_ch = chan->hw_value;
  1019. }
  1020. if (d->oui_subtype != P2P_INV_REQ && d->oui_subtype != P2P_INV_RSP)
  1021. goto out_set_timeout;
  1022. vendor_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
  1023. mgmt_tx->buff + ie_offset,
  1024. len - ie_offset);
  1025. if (!vendor_ie)
  1026. goto out_set_timeout;
  1027. p = (struct wilc_vendor_specific_ie *)vendor_ie;
  1028. wilc_wfi_cfg_parse_ch_attr(p->attr, p->tag_len - 4, vif->wilc->sta_ch);
  1029. out_set_timeout:
  1030. wfi_drv->p2p_timeout = (jiffies + msecs_to_jiffies(wait));
  1031. out_txq_add_pkt:
  1032. wilc_wlan_txq_add_mgmt_pkt(wdev->netdev, mgmt_tx,
  1033. mgmt_tx->buff, mgmt_tx->size,
  1034. wilc_wfi_mgmt_tx_complete);
  1035. out:
  1036. return ret;
  1037. }
  1038. static int mgmt_tx_cancel_wait(struct wiphy *wiphy,
  1039. struct wireless_dev *wdev,
  1040. u64 cookie)
  1041. {
  1042. struct wilc_vif *vif = netdev_priv(wdev->netdev);
  1043. struct wilc_priv *priv = &vif->priv;
  1044. struct host_if_drv *wfi_drv = priv->hif_drv;
  1045. wfi_drv->p2p_timeout = jiffies;
  1046. if (!priv->p2p_listen_state) {
  1047. struct wilc_wfi_p2p_listen_params *params;
  1048. params = &priv->remain_on_ch_params;
  1049. cfg80211_remain_on_channel_expired(wdev,
  1050. params->listen_cookie,
  1051. params->listen_ch,
  1052. GFP_KERNEL);
  1053. }
  1054. return 0;
  1055. }
  1056. void wilc_update_mgmt_frame_registrations(struct wiphy *wiphy,
  1057. struct wireless_dev *wdev,
  1058. struct mgmt_frame_regs *upd)
  1059. {
  1060. struct wilc *wl = wiphy_priv(wiphy);
  1061. struct wilc_vif *vif = netdev_priv(wdev->netdev);
  1062. u32 presp_bit = BIT(IEEE80211_STYPE_PROBE_REQ >> 4);
  1063. u32 action_bit = BIT(IEEE80211_STYPE_ACTION >> 4);
  1064. u32 pauth_bit = BIT(IEEE80211_STYPE_AUTH >> 4);
  1065. if (wl->initialized) {
  1066. bool prev = vif->mgmt_reg_stypes & presp_bit;
  1067. bool now = upd->interface_stypes & presp_bit;
  1068. if (now != prev)
  1069. wilc_frame_register(vif, IEEE80211_STYPE_PROBE_REQ, now);
  1070. prev = vif->mgmt_reg_stypes & action_bit;
  1071. now = upd->interface_stypes & action_bit;
  1072. if (now != prev)
  1073. wilc_frame_register(vif, IEEE80211_STYPE_ACTION, now);
  1074. prev = vif->mgmt_reg_stypes & pauth_bit;
  1075. now = upd->interface_stypes & pauth_bit;
  1076. if (now != prev)
  1077. wilc_frame_register(vif, IEEE80211_STYPE_AUTH, now);
  1078. }
  1079. vif->mgmt_reg_stypes =
  1080. upd->interface_stypes & (presp_bit | action_bit | pauth_bit);
  1081. }
  1082. static int external_auth(struct wiphy *wiphy, struct net_device *dev,
  1083. struct cfg80211_external_auth_params *auth)
  1084. {
  1085. struct wilc_vif *vif = netdev_priv(dev);
  1086. if (auth->status == WLAN_STATUS_SUCCESS)
  1087. wilc_set_external_auth_param(vif, auth);
  1088. return 0;
  1089. }
  1090. static int set_cqm_rssi_config(struct wiphy *wiphy, struct net_device *dev,
  1091. s32 rssi_thold, u32 rssi_hyst)
  1092. {
  1093. return 0;
  1094. }
  1095. static int dump_station(struct wiphy *wiphy, struct net_device *dev,
  1096. int idx, u8 *mac, struct station_info *sinfo)
  1097. {
  1098. struct wilc_vif *vif = netdev_priv(dev);
  1099. int ret;
  1100. if (idx != 0)
  1101. return -ENOENT;
  1102. ret = wilc_get_rssi(vif, &sinfo->signal);
  1103. if (ret)
  1104. return ret;
  1105. sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL);
  1106. memcpy(mac, vif->priv.associated_bss, ETH_ALEN);
  1107. return 0;
  1108. }
  1109. static int set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
  1110. bool enabled, int timeout)
  1111. {
  1112. struct wilc_vif *vif = netdev_priv(dev);
  1113. struct wilc_priv *priv = &vif->priv;
  1114. if (!priv->hif_drv)
  1115. return -EIO;
  1116. wilc_set_power_mgmt(vif, enabled, timeout);
  1117. return 0;
  1118. }
  1119. static int change_virtual_intf(struct wiphy *wiphy, struct net_device *dev,
  1120. enum nl80211_iftype type,
  1121. struct vif_params *params)
  1122. {
  1123. struct wilc *wl = wiphy_priv(wiphy);
  1124. struct wilc_vif *vif = netdev_priv(dev);
  1125. struct wilc_priv *priv = &vif->priv;
  1126. switch (type) {
  1127. case NL80211_IFTYPE_STATION:
  1128. vif->connecting = false;
  1129. dev->ieee80211_ptr->iftype = type;
  1130. priv->wdev.iftype = type;
  1131. vif->monitor_flag = 0;
  1132. if (vif->iftype == WILC_AP_MODE || vif->iftype == WILC_GO_MODE)
  1133. wilc_wfi_deinit_mon_interface(wl, true);
  1134. vif->iftype = WILC_STATION_MODE;
  1135. if (wl->initialized)
  1136. wilc_set_operation_mode(vif, wilc_get_vif_idx(vif),
  1137. WILC_STATION_MODE, vif->idx);
  1138. memset(priv->assoc_stainfo.sta_associated_bss, 0,
  1139. WILC_MAX_NUM_STA * ETH_ALEN);
  1140. break;
  1141. case NL80211_IFTYPE_P2P_CLIENT:
  1142. vif->connecting = false;
  1143. dev->ieee80211_ptr->iftype = type;
  1144. priv->wdev.iftype = type;
  1145. vif->monitor_flag = 0;
  1146. vif->iftype = WILC_CLIENT_MODE;
  1147. if (wl->initialized)
  1148. wilc_set_operation_mode(vif, wilc_get_vif_idx(vif),
  1149. WILC_STATION_MODE, vif->idx);
  1150. break;
  1151. case NL80211_IFTYPE_AP:
  1152. dev->ieee80211_ptr->iftype = type;
  1153. priv->wdev.iftype = type;
  1154. vif->iftype = WILC_AP_MODE;
  1155. if (wl->initialized)
  1156. wilc_set_operation_mode(vif, wilc_get_vif_idx(vif),
  1157. WILC_AP_MODE, vif->idx);
  1158. break;
  1159. case NL80211_IFTYPE_P2P_GO:
  1160. dev->ieee80211_ptr->iftype = type;
  1161. priv->wdev.iftype = type;
  1162. vif->iftype = WILC_GO_MODE;
  1163. if (wl->initialized)
  1164. wilc_set_operation_mode(vif, wilc_get_vif_idx(vif),
  1165. WILC_AP_MODE, vif->idx);
  1166. break;
  1167. default:
  1168. netdev_err(dev, "Unknown interface type= %d\n", type);
  1169. return -EINVAL;
  1170. }
  1171. return 0;
  1172. }
  1173. static int start_ap(struct wiphy *wiphy, struct net_device *dev,
  1174. struct cfg80211_ap_settings *settings)
  1175. {
  1176. struct wilc_vif *vif = netdev_priv(dev);
  1177. int ret;
  1178. ret = set_channel(wiphy, &settings->chandef);
  1179. if (ret != 0)
  1180. netdev_err(dev, "Error in setting channel\n");
  1181. wilc_wlan_set_bssid(dev, dev->dev_addr, WILC_AP_MODE);
  1182. return wilc_add_beacon(vif, settings->beacon_interval,
  1183. settings->dtim_period, &settings->beacon);
  1184. }
  1185. static int change_beacon(struct wiphy *wiphy, struct net_device *dev,
  1186. struct cfg80211_beacon_data *beacon)
  1187. {
  1188. struct wilc_vif *vif = netdev_priv(dev);
  1189. return wilc_add_beacon(vif, 0, 0, beacon);
  1190. }
  1191. static int stop_ap(struct wiphy *wiphy, struct net_device *dev,
  1192. unsigned int link_id)
  1193. {
  1194. int ret;
  1195. struct wilc_vif *vif = netdev_priv(dev);
  1196. wilc_wlan_set_bssid(dev, NULL, WILC_AP_MODE);
  1197. ret = wilc_del_beacon(vif);
  1198. if (ret)
  1199. netdev_err(dev, "Host delete beacon fail\n");
  1200. return ret;
  1201. }
  1202. static int add_station(struct wiphy *wiphy, struct net_device *dev,
  1203. const u8 *mac, struct station_parameters *params)
  1204. {
  1205. int ret = 0;
  1206. struct wilc_vif *vif = netdev_priv(dev);
  1207. struct wilc_priv *priv = &vif->priv;
  1208. if (vif->iftype == WILC_AP_MODE || vif->iftype == WILC_GO_MODE) {
  1209. memcpy(priv->assoc_stainfo.sta_associated_bss[params->aid], mac,
  1210. ETH_ALEN);
  1211. ret = wilc_add_station(vif, mac, params);
  1212. if (ret)
  1213. netdev_err(dev, "Host add station fail\n");
  1214. }
  1215. return ret;
  1216. }
  1217. static int del_station(struct wiphy *wiphy, struct net_device *dev,
  1218. struct station_del_parameters *params)
  1219. {
  1220. const u8 *mac = params->mac;
  1221. int ret = 0;
  1222. struct wilc_vif *vif = netdev_priv(dev);
  1223. struct wilc_priv *priv = &vif->priv;
  1224. struct sta_info *info;
  1225. if (!(vif->iftype == WILC_AP_MODE || vif->iftype == WILC_GO_MODE))
  1226. return ret;
  1227. info = &priv->assoc_stainfo;
  1228. if (!mac)
  1229. ret = wilc_del_allstation(vif, info->sta_associated_bss);
  1230. ret = wilc_del_station(vif, mac);
  1231. if (ret)
  1232. netdev_err(dev, "Host delete station fail\n");
  1233. return ret;
  1234. }
  1235. static int change_station(struct wiphy *wiphy, struct net_device *dev,
  1236. const u8 *mac, struct station_parameters *params)
  1237. {
  1238. int ret = 0;
  1239. struct wilc_vif *vif = netdev_priv(dev);
  1240. if (vif->iftype == WILC_AP_MODE || vif->iftype == WILC_GO_MODE) {
  1241. ret = wilc_edit_station(vif, mac, params);
  1242. if (ret)
  1243. netdev_err(dev, "Host edit station fail\n");
  1244. }
  1245. return ret;
  1246. }
  1247. static struct wilc_vif *wilc_get_vif_from_type(struct wilc *wl, int type)
  1248. {
  1249. struct wilc_vif *vif;
  1250. list_for_each_entry_rcu(vif, &wl->vif_list, list) {
  1251. if (vif->iftype == type)
  1252. return vif;
  1253. }
  1254. return NULL;
  1255. }
  1256. static struct wireless_dev *add_virtual_intf(struct wiphy *wiphy,
  1257. const char *name,
  1258. unsigned char name_assign_type,
  1259. enum nl80211_iftype type,
  1260. struct vif_params *params)
  1261. {
  1262. struct wilc *wl = wiphy_priv(wiphy);
  1263. struct wilc_vif *vif;
  1264. struct wireless_dev *wdev;
  1265. int iftype;
  1266. if (type == NL80211_IFTYPE_MONITOR) {
  1267. struct net_device *ndev;
  1268. int srcu_idx;
  1269. srcu_idx = srcu_read_lock(&wl->srcu);
  1270. vif = wilc_get_vif_from_type(wl, WILC_AP_MODE);
  1271. if (!vif) {
  1272. vif = wilc_get_vif_from_type(wl, WILC_GO_MODE);
  1273. if (!vif) {
  1274. srcu_read_unlock(&wl->srcu, srcu_idx);
  1275. goto validate_interface;
  1276. }
  1277. }
  1278. if (vif->monitor_flag) {
  1279. srcu_read_unlock(&wl->srcu, srcu_idx);
  1280. goto validate_interface;
  1281. }
  1282. ndev = wilc_wfi_init_mon_interface(wl, name, vif->ndev);
  1283. if (ndev) {
  1284. vif->monitor_flag = 1;
  1285. } else {
  1286. srcu_read_unlock(&wl->srcu, srcu_idx);
  1287. return ERR_PTR(-EINVAL);
  1288. }
  1289. wdev = &vif->priv.wdev;
  1290. srcu_read_unlock(&wl->srcu, srcu_idx);
  1291. return wdev;
  1292. }
  1293. validate_interface:
  1294. mutex_lock(&wl->vif_mutex);
  1295. if (wl->vif_num == WILC_NUM_CONCURRENT_IFC) {
  1296. pr_err("Reached maximum number of interface\n");
  1297. mutex_unlock(&wl->vif_mutex);
  1298. return ERR_PTR(-EINVAL);
  1299. }
  1300. mutex_unlock(&wl->vif_mutex);
  1301. switch (type) {
  1302. case NL80211_IFTYPE_STATION:
  1303. iftype = WILC_STATION_MODE;
  1304. break;
  1305. case NL80211_IFTYPE_AP:
  1306. iftype = WILC_AP_MODE;
  1307. break;
  1308. default:
  1309. return ERR_PTR(-EOPNOTSUPP);
  1310. }
  1311. vif = wilc_netdev_ifc_init(wl, name, iftype, type, true);
  1312. if (IS_ERR(vif))
  1313. return ERR_CAST(vif);
  1314. return &vif->priv.wdev;
  1315. }
  1316. static int del_virtual_intf(struct wiphy *wiphy, struct wireless_dev *wdev)
  1317. {
  1318. struct wilc *wl = wiphy_priv(wiphy);
  1319. struct wilc_vif *vif;
  1320. if (wdev->iftype == NL80211_IFTYPE_AP ||
  1321. wdev->iftype == NL80211_IFTYPE_P2P_GO)
  1322. wilc_wfi_deinit_mon_interface(wl, true);
  1323. vif = netdev_priv(wdev->netdev);
  1324. cfg80211_stop_iface(wiphy, wdev, GFP_KERNEL);
  1325. cfg80211_unregister_netdevice(vif->ndev);
  1326. vif->monitor_flag = 0;
  1327. wilc_set_operation_mode(vif, 0, 0, 0);
  1328. mutex_lock(&wl->vif_mutex);
  1329. list_del_rcu(&vif->list);
  1330. wl->vif_num--;
  1331. mutex_unlock(&wl->vif_mutex);
  1332. synchronize_srcu(&wl->srcu);
  1333. return 0;
  1334. }
  1335. static int wilc_suspend(struct wiphy *wiphy, struct cfg80211_wowlan *wow)
  1336. {
  1337. struct wilc *wl = wiphy_priv(wiphy);
  1338. if (!wow && wilc_wlan_get_num_conn_ifcs(wl))
  1339. wl->suspend_event = true;
  1340. else
  1341. wl->suspend_event = false;
  1342. return 0;
  1343. }
  1344. static int wilc_resume(struct wiphy *wiphy)
  1345. {
  1346. return 0;
  1347. }
  1348. static void wilc_set_wakeup(struct wiphy *wiphy, bool enabled)
  1349. {
  1350. struct wilc *wl = wiphy_priv(wiphy);
  1351. struct wilc_vif *vif;
  1352. int srcu_idx;
  1353. srcu_idx = srcu_read_lock(&wl->srcu);
  1354. vif = wilc_get_wl_to_vif(wl);
  1355. if (IS_ERR(vif)) {
  1356. srcu_read_unlock(&wl->srcu, srcu_idx);
  1357. return;
  1358. }
  1359. netdev_info(vif->ndev, "cfg set wake up = %d\n", enabled);
  1360. wilc_set_wowlan_trigger(vif, enabled);
  1361. srcu_read_unlock(&wl->srcu, srcu_idx);
  1362. }
  1363. static int set_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev,
  1364. enum nl80211_tx_power_setting type, int mbm)
  1365. {
  1366. int ret;
  1367. int srcu_idx;
  1368. s32 tx_power = MBM_TO_DBM(mbm);
  1369. struct wilc *wl = wiphy_priv(wiphy);
  1370. struct wilc_vif *vif;
  1371. if (!wl->initialized)
  1372. return -EIO;
  1373. srcu_idx = srcu_read_lock(&wl->srcu);
  1374. vif = wilc_get_wl_to_vif(wl);
  1375. if (IS_ERR(vif)) {
  1376. srcu_read_unlock(&wl->srcu, srcu_idx);
  1377. return -EINVAL;
  1378. }
  1379. netdev_info(vif->ndev, "Setting tx power %d\n", tx_power);
  1380. if (tx_power < 0)
  1381. tx_power = 0;
  1382. else if (tx_power > 18)
  1383. tx_power = 18;
  1384. ret = wilc_set_tx_power(vif, tx_power);
  1385. if (ret)
  1386. netdev_err(vif->ndev, "Failed to set tx power\n");
  1387. srcu_read_unlock(&wl->srcu, srcu_idx);
  1388. return ret;
  1389. }
  1390. static int get_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev,
  1391. int *dbm)
  1392. {
  1393. int ret;
  1394. struct wilc_vif *vif = netdev_priv(wdev->netdev);
  1395. struct wilc *wl = vif->wilc;
  1396. /* If firmware is not started, return. */
  1397. if (!wl->initialized)
  1398. return -EIO;
  1399. ret = wilc_get_tx_power(vif, (u8 *)dbm);
  1400. if (ret)
  1401. netdev_err(vif->ndev, "Failed to get tx power\n");
  1402. return ret;
  1403. }
  1404. static const struct cfg80211_ops wilc_cfg80211_ops = {
  1405. .set_monitor_channel = set_channel,
  1406. .scan = scan,
  1407. .connect = connect,
  1408. .disconnect = disconnect,
  1409. .add_key = add_key,
  1410. .del_key = del_key,
  1411. .get_key = get_key,
  1412. .set_default_key = set_default_key,
  1413. .set_default_mgmt_key = set_default_mgmt_key,
  1414. .add_virtual_intf = add_virtual_intf,
  1415. .del_virtual_intf = del_virtual_intf,
  1416. .change_virtual_intf = change_virtual_intf,
  1417. .start_ap = start_ap,
  1418. .change_beacon = change_beacon,
  1419. .stop_ap = stop_ap,
  1420. .add_station = add_station,
  1421. .del_station = del_station,
  1422. .change_station = change_station,
  1423. .get_station = get_station,
  1424. .dump_station = dump_station,
  1425. .change_bss = change_bss,
  1426. .set_wiphy_params = set_wiphy_params,
  1427. .external_auth = external_auth,
  1428. .set_pmksa = set_pmksa,
  1429. .del_pmksa = del_pmksa,
  1430. .flush_pmksa = flush_pmksa,
  1431. .remain_on_channel = remain_on_channel,
  1432. .cancel_remain_on_channel = cancel_remain_on_channel,
  1433. .mgmt_tx_cancel_wait = mgmt_tx_cancel_wait,
  1434. .mgmt_tx = mgmt_tx,
  1435. .update_mgmt_frame_registrations = wilc_update_mgmt_frame_registrations,
  1436. .set_power_mgmt = set_power_mgmt,
  1437. .set_cqm_rssi_config = set_cqm_rssi_config,
  1438. .suspend = wilc_suspend,
  1439. .resume = wilc_resume,
  1440. .set_wakeup = wilc_set_wakeup,
  1441. .set_tx_power = set_tx_power,
  1442. .get_tx_power = get_tx_power,
  1443. };
  1444. static void wlan_init_locks(struct wilc *wl)
  1445. {
  1446. mutex_init(&wl->hif_cs);
  1447. mutex_init(&wl->rxq_cs);
  1448. mutex_init(&wl->cfg_cmd_lock);
  1449. mutex_init(&wl->vif_mutex);
  1450. mutex_init(&wl->deinit_lock);
  1451. spin_lock_init(&wl->txq_spinlock);
  1452. mutex_init(&wl->txq_add_to_head_cs);
  1453. init_completion(&wl->txq_event);
  1454. init_completion(&wl->cfg_event);
  1455. init_completion(&wl->sync_event);
  1456. init_completion(&wl->txq_thread_started);
  1457. init_srcu_struct(&wl->srcu);
  1458. }
  1459. void wlan_deinit_locks(struct wilc *wilc)
  1460. {
  1461. mutex_destroy(&wilc->hif_cs);
  1462. mutex_destroy(&wilc->rxq_cs);
  1463. mutex_destroy(&wilc->cfg_cmd_lock);
  1464. mutex_destroy(&wilc->txq_add_to_head_cs);
  1465. mutex_destroy(&wilc->vif_mutex);
  1466. mutex_destroy(&wilc->deinit_lock);
  1467. cleanup_srcu_struct(&wilc->srcu);
  1468. }
  1469. int wilc_cfg80211_init(struct wilc **wilc, struct device *dev, int io_type,
  1470. const struct wilc_hif_func *ops)
  1471. {
  1472. struct wilc *wl;
  1473. struct wilc_vif *vif;
  1474. int ret, i;
  1475. wl = wilc_create_wiphy(dev);
  1476. if (!wl)
  1477. return -EINVAL;
  1478. wlan_init_locks(wl);
  1479. ret = wilc_wlan_cfg_init(wl);
  1480. if (ret)
  1481. goto free_wl;
  1482. *wilc = wl;
  1483. wl->io_type = io_type;
  1484. wl->hif_func = ops;
  1485. for (i = 0; i < NQUEUES; i++)
  1486. INIT_LIST_HEAD(&wl->txq[i].txq_head.list);
  1487. INIT_LIST_HEAD(&wl->rxq_head.list);
  1488. INIT_LIST_HEAD(&wl->vif_list);
  1489. vif = wilc_netdev_ifc_init(wl, "wlan%d", WILC_STATION_MODE,
  1490. NL80211_IFTYPE_STATION, false);
  1491. if (IS_ERR(vif)) {
  1492. ret = PTR_ERR(vif);
  1493. goto free_cfg;
  1494. }
  1495. return 0;
  1496. free_cfg:
  1497. wilc_wlan_cfg_deinit(wl);
  1498. free_wl:
  1499. wlan_deinit_locks(wl);
  1500. wiphy_unregister(wl->wiphy);
  1501. wiphy_free(wl->wiphy);
  1502. return ret;
  1503. }
  1504. EXPORT_SYMBOL_GPL(wilc_cfg80211_init);
  1505. struct wilc *wilc_create_wiphy(struct device *dev)
  1506. {
  1507. struct wiphy *wiphy;
  1508. struct wilc *wl;
  1509. int ret;
  1510. wiphy = wiphy_new(&wilc_cfg80211_ops, sizeof(*wl));
  1511. if (!wiphy)
  1512. return NULL;
  1513. wl = wiphy_priv(wiphy);
  1514. memcpy(wl->bitrates, wilc_bitrates, sizeof(wilc_bitrates));
  1515. memcpy(wl->channels, wilc_2ghz_channels, sizeof(wilc_2ghz_channels));
  1516. wl->band.bitrates = wl->bitrates;
  1517. wl->band.n_bitrates = ARRAY_SIZE(wl->bitrates);
  1518. wl->band.channels = wl->channels;
  1519. wl->band.n_channels = ARRAY_SIZE(wilc_2ghz_channels);
  1520. wl->band.ht_cap.ht_supported = 1;
  1521. wl->band.ht_cap.cap |= (1 << IEEE80211_HT_CAP_RX_STBC_SHIFT);
  1522. wl->band.ht_cap.mcs.rx_mask[0] = 0xff;
  1523. wl->band.ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_8K;
  1524. wl->band.ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
  1525. wiphy->bands[NL80211_BAND_2GHZ] = &wl->band;
  1526. wiphy->max_scan_ssids = WILC_MAX_NUM_PROBED_SSID;
  1527. #ifdef CONFIG_PM
  1528. wiphy->wowlan = &wowlan_support;
  1529. #endif
  1530. wiphy->max_num_pmkids = WILC_MAX_NUM_PMKIDS;
  1531. wiphy->max_scan_ie_len = 1000;
  1532. wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
  1533. memcpy(wl->cipher_suites, wilc_cipher_suites,
  1534. sizeof(wilc_cipher_suites));
  1535. wiphy->cipher_suites = wl->cipher_suites;
  1536. wiphy->n_cipher_suites = ARRAY_SIZE(wilc_cipher_suites);
  1537. wiphy->mgmt_stypes = wilc_wfi_cfg80211_mgmt_types;
  1538. wiphy->max_remain_on_channel_duration = 500;
  1539. wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
  1540. BIT(NL80211_IFTYPE_AP) |
  1541. BIT(NL80211_IFTYPE_MONITOR) |
  1542. BIT(NL80211_IFTYPE_P2P_GO) |
  1543. BIT(NL80211_IFTYPE_P2P_CLIENT);
  1544. wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
  1545. wiphy->features |= NL80211_FEATURE_SAE;
  1546. set_wiphy_dev(wiphy, dev);
  1547. wl->wiphy = wiphy;
  1548. ret = wiphy_register(wiphy);
  1549. if (ret) {
  1550. wiphy_free(wiphy);
  1551. return NULL;
  1552. }
  1553. return wl;
  1554. }
  1555. int wilc_init_host_int(struct net_device *net)
  1556. {
  1557. int ret;
  1558. struct wilc_vif *vif = netdev_priv(net);
  1559. struct wilc_priv *priv = &vif->priv;
  1560. priv->p2p_listen_state = false;
  1561. mutex_init(&priv->scan_req_lock);
  1562. ret = wilc_init(net, &priv->hif_drv);
  1563. if (ret)
  1564. netdev_err(net, "Error while initializing hostinterface\n");
  1565. return ret;
  1566. }
  1567. void wilc_deinit_host_int(struct net_device *net)
  1568. {
  1569. int ret;
  1570. struct wilc_vif *vif = netdev_priv(net);
  1571. struct wilc_priv *priv = &vif->priv;
  1572. priv->p2p_listen_state = false;
  1573. flush_workqueue(vif->wilc->hif_workqueue);
  1574. mutex_destroy(&priv->scan_req_lock);
  1575. ret = wilc_deinit(vif);
  1576. if (ret)
  1577. netdev_err(net, "Error while deinitializing host interface\n");
  1578. }