sta_ioctl.c 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367
  1. /*
  2. * Marvell Wireless LAN device driver: functions for station ioctl
  3. *
  4. * Copyright (C) 2011, Marvell International Ltd.
  5. *
  6. * This software file (the "File") is distributed by Marvell International
  7. * Ltd. under the terms of the GNU General Public License Version 2, June 1991
  8. * (the "License"). You may use, redistribute and/or modify this File in
  9. * accordance with the terms and conditions of the License, a copy of which
  10. * is available by writing to the Free Software Foundation, Inc.,
  11. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
  12. * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
  13. *
  14. * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
  15. * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
  16. * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
  17. * this warranty disclaimer.
  18. */
  19. #include "decl.h"
  20. #include "ioctl.h"
  21. #include "util.h"
  22. #include "fw.h"
  23. #include "main.h"
  24. #include "wmm.h"
  25. #include "11n.h"
  26. #include "cfg80211.h"
  27. static int disconnect_on_suspend = 1;
  28. module_param(disconnect_on_suspend, int, 0644);
  29. /*
  30. * Copies the multicast address list from device to driver.
  31. *
  32. * This function does not validate the destination memory for
  33. * size, and the calling function must ensure enough memory is
  34. * available.
  35. */
  36. int mwifiex_copy_mcast_addr(struct mwifiex_multicast_list *mlist,
  37. struct net_device *dev)
  38. {
  39. int i = 0;
  40. struct netdev_hw_addr *ha;
  41. netdev_for_each_mc_addr(ha, dev)
  42. memcpy(&mlist->mac_list[i++], ha->addr, ETH_ALEN);
  43. return i;
  44. }
  45. /*
  46. * Wait queue completion handler.
  47. *
  48. * This function waits on a cmd wait queue. It also cancels the pending
  49. * request after waking up, in case of errors.
  50. */
  51. int mwifiex_wait_queue_complete(struct mwifiex_adapter *adapter)
  52. {
  53. bool cancel_flag = false;
  54. int status;
  55. struct cmd_ctrl_node *cmd_queued;
  56. if (!adapter->cmd_queued)
  57. return 0;
  58. cmd_queued = adapter->cmd_queued;
  59. adapter->cmd_queued = NULL;
  60. dev_dbg(adapter->dev, "cmd pending\n");
  61. atomic_inc(&adapter->cmd_pending);
  62. /* Wait for completion */
  63. wait_event_interruptible(adapter->cmd_wait_q.wait,
  64. *(cmd_queued->condition));
  65. if (!*(cmd_queued->condition))
  66. cancel_flag = true;
  67. if (cancel_flag) {
  68. mwifiex_cancel_pending_ioctl(adapter);
  69. dev_dbg(adapter->dev, "cmd cancel\n");
  70. }
  71. status = adapter->cmd_wait_q.status;
  72. adapter->cmd_wait_q.status = 0;
  73. return status;
  74. }
  75. /*
  76. * This function prepares the correct firmware command and
  77. * issues it to set the multicast list.
  78. *
  79. * This function can be used to enable promiscuous mode, or enable all
  80. * multicast packets, or to enable selective multicast.
  81. */
  82. int mwifiex_request_set_multicast_list(struct mwifiex_private *priv,
  83. struct mwifiex_multicast_list *mcast_list)
  84. {
  85. int ret = 0;
  86. u16 old_pkt_filter;
  87. old_pkt_filter = priv->curr_pkt_filter;
  88. if (mcast_list->mode == MWIFIEX_PROMISC_MODE) {
  89. dev_dbg(priv->adapter->dev, "info: Enable Promiscuous mode\n");
  90. priv->curr_pkt_filter |= HostCmd_ACT_MAC_PROMISCUOUS_ENABLE;
  91. priv->curr_pkt_filter &=
  92. ~HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
  93. } else {
  94. /* Multicast */
  95. priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_PROMISCUOUS_ENABLE;
  96. if (mcast_list->mode == MWIFIEX_MULTICAST_MODE) {
  97. dev_dbg(priv->adapter->dev,
  98. "info: Enabling All Multicast!\n");
  99. priv->curr_pkt_filter |=
  100. HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
  101. } else {
  102. priv->curr_pkt_filter &=
  103. ~HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
  104. if (mcast_list->num_multicast_addr) {
  105. dev_dbg(priv->adapter->dev,
  106. "info: Set multicast list=%d\n",
  107. mcast_list->num_multicast_addr);
  108. /* Set multicast addresses to firmware */
  109. if (old_pkt_filter == priv->curr_pkt_filter) {
  110. /* Send request to firmware */
  111. ret = mwifiex_send_cmd_async(priv,
  112. HostCmd_CMD_MAC_MULTICAST_ADR,
  113. HostCmd_ACT_GEN_SET, 0,
  114. mcast_list);
  115. } else {
  116. /* Send request to firmware */
  117. ret = mwifiex_send_cmd_async(priv,
  118. HostCmd_CMD_MAC_MULTICAST_ADR,
  119. HostCmd_ACT_GEN_SET, 0,
  120. mcast_list);
  121. }
  122. }
  123. }
  124. }
  125. dev_dbg(priv->adapter->dev,
  126. "info: old_pkt_filter=%#x, curr_pkt_filter=%#x\n",
  127. old_pkt_filter, priv->curr_pkt_filter);
  128. if (old_pkt_filter != priv->curr_pkt_filter) {
  129. ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_MAC_CONTROL,
  130. HostCmd_ACT_GEN_SET,
  131. 0, &priv->curr_pkt_filter);
  132. }
  133. return ret;
  134. }
  135. /*
  136. * This function fills bss descriptor structure using provided
  137. * information.
  138. */
  139. int mwifiex_fill_new_bss_desc(struct mwifiex_private *priv,
  140. struct cfg80211_bss *bss,
  141. struct mwifiex_bssdescriptor *bss_desc)
  142. {
  143. int ret;
  144. u8 *beacon_ie;
  145. struct mwifiex_bss_priv *bss_priv = (void *)bss->priv;
  146. beacon_ie = kmemdup(bss->information_elements, bss->len_beacon_ies,
  147. GFP_KERNEL);
  148. if (!beacon_ie) {
  149. dev_err(priv->adapter->dev, " failed to alloc beacon_ie\n");
  150. return -ENOMEM;
  151. }
  152. memcpy(bss_desc->mac_address, bss->bssid, ETH_ALEN);
  153. bss_desc->rssi = bss->signal;
  154. bss_desc->beacon_buf = beacon_ie;
  155. bss_desc->beacon_buf_size = bss->len_beacon_ies;
  156. bss_desc->beacon_period = bss->beacon_interval;
  157. bss_desc->cap_info_bitmap = bss->capability;
  158. bss_desc->bss_band = bss_priv->band;
  159. bss_desc->fw_tsf = bss_priv->fw_tsf;
  160. bss_desc->timestamp = bss->tsf;
  161. if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_PRIVACY) {
  162. dev_dbg(priv->adapter->dev, "info: InterpretIE: AP WEP enabled\n");
  163. bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_8021X_WEP;
  164. } else {
  165. bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_ACCEPT_ALL;
  166. }
  167. if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_IBSS)
  168. bss_desc->bss_mode = NL80211_IFTYPE_ADHOC;
  169. else
  170. bss_desc->bss_mode = NL80211_IFTYPE_STATION;
  171. ret = mwifiex_update_bss_desc_with_ie(priv->adapter, bss_desc);
  172. kfree(beacon_ie);
  173. return ret;
  174. }
  175. static int mwifiex_process_country_ie(struct mwifiex_private *priv,
  176. struct cfg80211_bss *bss)
  177. {
  178. u8 *country_ie, country_ie_len;
  179. struct mwifiex_802_11d_domain_reg *domain_info =
  180. &priv->adapter->domain_reg;
  181. country_ie = (u8 *)ieee80211_bss_get_ie(bss, WLAN_EID_COUNTRY);
  182. if (!country_ie)
  183. return 0;
  184. country_ie_len = country_ie[1];
  185. if (country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN)
  186. return 0;
  187. domain_info->country_code[0] = country_ie[2];
  188. domain_info->country_code[1] = country_ie[3];
  189. domain_info->country_code[2] = ' ';
  190. country_ie_len -= IEEE80211_COUNTRY_STRING_LEN;
  191. domain_info->no_of_triplet =
  192. country_ie_len / sizeof(struct ieee80211_country_ie_triplet);
  193. memcpy((u8 *)domain_info->triplet,
  194. &country_ie[2] + IEEE80211_COUNTRY_STRING_LEN, country_ie_len);
  195. if (mwifiex_send_cmd_async(priv, HostCmd_CMD_802_11D_DOMAIN_INFO,
  196. HostCmd_ACT_GEN_SET, 0, NULL)) {
  197. wiphy_err(priv->adapter->wiphy,
  198. "11D: setting domain info in FW\n");
  199. return -1;
  200. }
  201. return 0;
  202. }
  203. /*
  204. * In Ad-Hoc mode, the IBSS is created if not found in scan list.
  205. * In both Ad-Hoc and infra mode, an deauthentication is performed
  206. * first.
  207. */
  208. int mwifiex_bss_start(struct mwifiex_private *priv, struct cfg80211_bss *bss,
  209. struct cfg80211_ssid *req_ssid)
  210. {
  211. int ret;
  212. struct mwifiex_adapter *adapter = priv->adapter;
  213. struct mwifiex_bssdescriptor *bss_desc = NULL;
  214. priv->scan_block = false;
  215. if (bss) {
  216. mwifiex_process_country_ie(priv, bss);
  217. /* Allocate and fill new bss descriptor */
  218. bss_desc = kzalloc(sizeof(struct mwifiex_bssdescriptor),
  219. GFP_KERNEL);
  220. if (!bss_desc) {
  221. dev_err(priv->adapter->dev, " failed to alloc bss_desc\n");
  222. return -ENOMEM;
  223. }
  224. ret = mwifiex_fill_new_bss_desc(priv, bss, bss_desc);
  225. if (ret)
  226. goto done;
  227. }
  228. if (priv->bss_mode == NL80211_IFTYPE_STATION) {
  229. /* Infra mode */
  230. ret = mwifiex_deauthenticate(priv, NULL);
  231. if (ret)
  232. goto done;
  233. ret = mwifiex_check_network_compatibility(priv, bss_desc);
  234. if (ret)
  235. goto done;
  236. dev_dbg(adapter->dev, "info: SSID found in scan list ... "
  237. "associating...\n");
  238. if (!netif_queue_stopped(priv->netdev))
  239. mwifiex_stop_net_dev_queue(priv->netdev, adapter);
  240. if (netif_carrier_ok(priv->netdev))
  241. netif_carrier_off(priv->netdev);
  242. /* Clear any past association response stored for
  243. * application retrieval */
  244. priv->assoc_rsp_size = 0;
  245. ret = mwifiex_associate(priv, bss_desc);
  246. /* If auth type is auto and association fails using open mode,
  247. * try to connect using shared mode */
  248. if (ret == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG &&
  249. priv->sec_info.is_authtype_auto &&
  250. priv->sec_info.wep_enabled) {
  251. priv->sec_info.authentication_mode =
  252. NL80211_AUTHTYPE_SHARED_KEY;
  253. ret = mwifiex_associate(priv, bss_desc);
  254. }
  255. if (bss)
  256. cfg80211_put_bss(bss);
  257. } else {
  258. /* Adhoc mode */
  259. /* If the requested SSID matches current SSID, return */
  260. if (bss_desc && bss_desc->ssid.ssid_len &&
  261. (!mwifiex_ssid_cmp(&priv->curr_bss_params.bss_descriptor.
  262. ssid, &bss_desc->ssid))) {
  263. kfree(bss_desc);
  264. return 0;
  265. }
  266. /* Exit Adhoc mode first */
  267. dev_dbg(adapter->dev, "info: Sending Adhoc Stop\n");
  268. ret = mwifiex_deauthenticate(priv, NULL);
  269. if (ret)
  270. goto done;
  271. priv->adhoc_is_link_sensed = false;
  272. ret = mwifiex_check_network_compatibility(priv, bss_desc);
  273. if (!netif_queue_stopped(priv->netdev))
  274. mwifiex_stop_net_dev_queue(priv->netdev, adapter);
  275. if (netif_carrier_ok(priv->netdev))
  276. netif_carrier_off(priv->netdev);
  277. if (!ret) {
  278. dev_dbg(adapter->dev, "info: network found in scan"
  279. " list. Joining...\n");
  280. ret = mwifiex_adhoc_join(priv, bss_desc);
  281. if (bss)
  282. cfg80211_put_bss(bss);
  283. } else {
  284. dev_dbg(adapter->dev, "info: Network not found in "
  285. "the list, creating adhoc with ssid = %s\n",
  286. req_ssid->ssid);
  287. ret = mwifiex_adhoc_start(priv, req_ssid);
  288. }
  289. }
  290. done:
  291. kfree(bss_desc);
  292. return ret;
  293. }
  294. /*
  295. * IOCTL request handler to set host sleep configuration.
  296. *
  297. * This function prepares the correct firmware command and
  298. * issues it.
  299. */
  300. static int mwifiex_set_hs_params(struct mwifiex_private *priv, u16 action,
  301. int cmd_type, struct mwifiex_ds_hs_cfg *hs_cfg)
  302. {
  303. struct mwifiex_adapter *adapter = priv->adapter;
  304. int status = 0;
  305. u32 prev_cond = 0;
  306. if (!hs_cfg)
  307. return -ENOMEM;
  308. switch (action) {
  309. case HostCmd_ACT_GEN_SET:
  310. if (adapter->pps_uapsd_mode) {
  311. dev_dbg(adapter->dev, "info: Host Sleep IOCTL"
  312. " is blocked in UAPSD/PPS mode\n");
  313. status = -1;
  314. break;
  315. }
  316. if (hs_cfg->is_invoke_hostcmd) {
  317. if (hs_cfg->conditions == HOST_SLEEP_CFG_CANCEL) {
  318. if (!adapter->is_hs_configured)
  319. /* Already cancelled */
  320. break;
  321. /* Save previous condition */
  322. prev_cond = le32_to_cpu(adapter->hs_cfg
  323. .conditions);
  324. adapter->hs_cfg.conditions =
  325. cpu_to_le32(hs_cfg->conditions);
  326. } else if (hs_cfg->conditions) {
  327. adapter->hs_cfg.conditions =
  328. cpu_to_le32(hs_cfg->conditions);
  329. adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
  330. if (hs_cfg->gap)
  331. adapter->hs_cfg.gap = (u8)hs_cfg->gap;
  332. } else if (adapter->hs_cfg.conditions
  333. == cpu_to_le32(HOST_SLEEP_CFG_CANCEL)) {
  334. /* Return failure if no parameters for HS
  335. enable */
  336. status = -1;
  337. break;
  338. }
  339. if (cmd_type == MWIFIEX_SYNC_CMD)
  340. status = mwifiex_send_cmd_sync(priv,
  341. HostCmd_CMD_802_11_HS_CFG_ENH,
  342. HostCmd_ACT_GEN_SET, 0,
  343. &adapter->hs_cfg);
  344. else
  345. status = mwifiex_send_cmd_async(priv,
  346. HostCmd_CMD_802_11_HS_CFG_ENH,
  347. HostCmd_ACT_GEN_SET, 0,
  348. &adapter->hs_cfg);
  349. if (hs_cfg->conditions == HOST_SLEEP_CFG_CANCEL)
  350. /* Restore previous condition */
  351. adapter->hs_cfg.conditions =
  352. cpu_to_le32(prev_cond);
  353. } else {
  354. adapter->hs_cfg.conditions =
  355. cpu_to_le32(hs_cfg->conditions);
  356. adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
  357. adapter->hs_cfg.gap = (u8)hs_cfg->gap;
  358. }
  359. break;
  360. case HostCmd_ACT_GEN_GET:
  361. hs_cfg->conditions = le32_to_cpu(adapter->hs_cfg.conditions);
  362. hs_cfg->gpio = adapter->hs_cfg.gpio;
  363. hs_cfg->gap = adapter->hs_cfg.gap;
  364. break;
  365. default:
  366. status = -1;
  367. break;
  368. }
  369. return status;
  370. }
  371. /*
  372. * Sends IOCTL request to cancel the existing Host Sleep configuration.
  373. *
  374. * This function allocates the IOCTL request buffer, fills it
  375. * with requisite parameters and calls the IOCTL handler.
  376. */
  377. int mwifiex_cancel_hs(struct mwifiex_private *priv, int cmd_type)
  378. {
  379. struct mwifiex_ds_hs_cfg hscfg;
  380. hscfg.conditions = HOST_SLEEP_CFG_CANCEL;
  381. hscfg.is_invoke_hostcmd = true;
  382. return mwifiex_set_hs_params(priv, HostCmd_ACT_GEN_SET,
  383. cmd_type, &hscfg);
  384. }
  385. EXPORT_SYMBOL_GPL(mwifiex_cancel_hs);
  386. /*
  387. * Sends IOCTL request to cancel the existing Host Sleep configuration.
  388. *
  389. * This function allocates the IOCTL request buffer, fills it
  390. * with requisite parameters and calls the IOCTL handler.
  391. */
  392. int mwifiex_enable_hs(struct mwifiex_adapter *adapter)
  393. {
  394. struct mwifiex_ds_hs_cfg hscfg;
  395. struct mwifiex_private *priv;
  396. int i;
  397. if (disconnect_on_suspend) {
  398. for (i = 0; i < adapter->priv_num; i++) {
  399. priv = adapter->priv[i];
  400. if (priv)
  401. mwifiex_deauthenticate(priv, NULL);
  402. }
  403. }
  404. if (adapter->hs_activated) {
  405. dev_dbg(adapter->dev, "cmd: HS Already actived\n");
  406. return true;
  407. }
  408. adapter->hs_activate_wait_q_woken = false;
  409. memset(&hscfg, 0, sizeof(struct mwifiex_ds_hs_cfg));
  410. hscfg.is_invoke_hostcmd = true;
  411. if (mwifiex_set_hs_params(mwifiex_get_priv(adapter,
  412. MWIFIEX_BSS_ROLE_STA),
  413. HostCmd_ACT_GEN_SET, MWIFIEX_SYNC_CMD,
  414. &hscfg)) {
  415. dev_err(adapter->dev, "IOCTL request HS enable failed\n");
  416. return false;
  417. }
  418. wait_event_interruptible(adapter->hs_activate_wait_q,
  419. adapter->hs_activate_wait_q_woken);
  420. return true;
  421. }
  422. EXPORT_SYMBOL_GPL(mwifiex_enable_hs);
  423. /*
  424. * IOCTL request handler to get BSS information.
  425. *
  426. * This function collates the information from different driver structures
  427. * to send to the user.
  428. */
  429. int mwifiex_get_bss_info(struct mwifiex_private *priv,
  430. struct mwifiex_bss_info *info)
  431. {
  432. struct mwifiex_adapter *adapter = priv->adapter;
  433. struct mwifiex_bssdescriptor *bss_desc;
  434. if (!info)
  435. return -1;
  436. bss_desc = &priv->curr_bss_params.bss_descriptor;
  437. info->bss_mode = priv->bss_mode;
  438. memcpy(&info->ssid, &bss_desc->ssid, sizeof(struct cfg80211_ssid));
  439. memcpy(&info->bssid, &bss_desc->mac_address, ETH_ALEN);
  440. info->bss_chan = bss_desc->channel;
  441. memcpy(info->country_code, adapter->country_code,
  442. IEEE80211_COUNTRY_STRING_LEN);
  443. info->media_connected = priv->media_connected;
  444. info->max_power_level = priv->max_tx_power_level;
  445. info->min_power_level = priv->min_tx_power_level;
  446. info->adhoc_state = priv->adhoc_state;
  447. info->bcn_nf_last = priv->bcn_nf_last;
  448. if (priv->sec_info.wep_enabled)
  449. info->wep_status = true;
  450. else
  451. info->wep_status = false;
  452. info->is_hs_configured = adapter->is_hs_configured;
  453. info->is_deep_sleep = adapter->is_deep_sleep;
  454. return 0;
  455. }
  456. /*
  457. * The function disables auto deep sleep mode.
  458. */
  459. int mwifiex_disable_auto_ds(struct mwifiex_private *priv)
  460. {
  461. struct mwifiex_ds_auto_ds auto_ds;
  462. auto_ds.auto_ds = DEEP_SLEEP_OFF;
  463. return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
  464. DIS_AUTO_PS, BITMAP_AUTO_DS, &auto_ds);
  465. }
  466. EXPORT_SYMBOL_GPL(mwifiex_disable_auto_ds);
  467. /*
  468. * Sends IOCTL request to get the data rate.
  469. *
  470. * This function allocates the IOCTL request buffer, fills it
  471. * with requisite parameters and calls the IOCTL handler.
  472. */
  473. int mwifiex_drv_get_data_rate(struct mwifiex_private *priv, u32 *rate)
  474. {
  475. int ret;
  476. ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_TX_RATE_QUERY,
  477. HostCmd_ACT_GEN_GET, 0, NULL);
  478. if (!ret) {
  479. if (priv->is_data_rate_auto)
  480. *rate = mwifiex_index_to_data_rate(priv, priv->tx_rate,
  481. priv->tx_htinfo);
  482. else
  483. *rate = priv->data_rate;
  484. }
  485. return ret;
  486. }
  487. /*
  488. * IOCTL request handler to set tx power configuration.
  489. *
  490. * This function prepares the correct firmware command and
  491. * issues it.
  492. *
  493. * For non-auto power mode, all the following power groups are set -
  494. * - Modulation class HR/DSSS
  495. * - Modulation class OFDM
  496. * - Modulation class HTBW20
  497. * - Modulation class HTBW40
  498. */
  499. int mwifiex_set_tx_power(struct mwifiex_private *priv,
  500. struct mwifiex_power_cfg *power_cfg)
  501. {
  502. int ret;
  503. struct host_cmd_ds_txpwr_cfg *txp_cfg;
  504. struct mwifiex_types_power_group *pg_tlv;
  505. struct mwifiex_power_group *pg;
  506. u8 *buf;
  507. u16 dbm = 0;
  508. if (!power_cfg->is_power_auto) {
  509. dbm = (u16) power_cfg->power_level;
  510. if ((dbm < priv->min_tx_power_level) ||
  511. (dbm > priv->max_tx_power_level)) {
  512. dev_err(priv->adapter->dev, "txpower value %d dBm"
  513. " is out of range (%d dBm-%d dBm)\n",
  514. dbm, priv->min_tx_power_level,
  515. priv->max_tx_power_level);
  516. return -1;
  517. }
  518. }
  519. buf = kzalloc(MWIFIEX_SIZE_OF_CMD_BUFFER, GFP_KERNEL);
  520. if (!buf) {
  521. dev_err(priv->adapter->dev, "%s: failed to alloc cmd buffer\n",
  522. __func__);
  523. return -ENOMEM;
  524. }
  525. txp_cfg = (struct host_cmd_ds_txpwr_cfg *) buf;
  526. txp_cfg->action = cpu_to_le16(HostCmd_ACT_GEN_SET);
  527. if (!power_cfg->is_power_auto) {
  528. txp_cfg->mode = cpu_to_le32(1);
  529. pg_tlv = (struct mwifiex_types_power_group *)
  530. (buf + sizeof(struct host_cmd_ds_txpwr_cfg));
  531. pg_tlv->type = TLV_TYPE_POWER_GROUP;
  532. pg_tlv->length = 4 * sizeof(struct mwifiex_power_group);
  533. pg = (struct mwifiex_power_group *)
  534. (buf + sizeof(struct host_cmd_ds_txpwr_cfg)
  535. + sizeof(struct mwifiex_types_power_group));
  536. /* Power group for modulation class HR/DSSS */
  537. pg->first_rate_code = 0x00;
  538. pg->last_rate_code = 0x03;
  539. pg->modulation_class = MOD_CLASS_HR_DSSS;
  540. pg->power_step = 0;
  541. pg->power_min = (s8) dbm;
  542. pg->power_max = (s8) dbm;
  543. pg++;
  544. /* Power group for modulation class OFDM */
  545. pg->first_rate_code = 0x00;
  546. pg->last_rate_code = 0x07;
  547. pg->modulation_class = MOD_CLASS_OFDM;
  548. pg->power_step = 0;
  549. pg->power_min = (s8) dbm;
  550. pg->power_max = (s8) dbm;
  551. pg++;
  552. /* Power group for modulation class HTBW20 */
  553. pg->first_rate_code = 0x00;
  554. pg->last_rate_code = 0x20;
  555. pg->modulation_class = MOD_CLASS_HT;
  556. pg->power_step = 0;
  557. pg->power_min = (s8) dbm;
  558. pg->power_max = (s8) dbm;
  559. pg->ht_bandwidth = HT_BW_20;
  560. pg++;
  561. /* Power group for modulation class HTBW40 */
  562. pg->first_rate_code = 0x00;
  563. pg->last_rate_code = 0x20;
  564. pg->modulation_class = MOD_CLASS_HT;
  565. pg->power_step = 0;
  566. pg->power_min = (s8) dbm;
  567. pg->power_max = (s8) dbm;
  568. pg->ht_bandwidth = HT_BW_40;
  569. }
  570. ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_TXPWR_CFG,
  571. HostCmd_ACT_GEN_SET, 0, buf);
  572. kfree(buf);
  573. return ret;
  574. }
  575. /*
  576. * IOCTL request handler to get power save mode.
  577. *
  578. * This function prepares the correct firmware command and
  579. * issues it.
  580. */
  581. int mwifiex_drv_set_power(struct mwifiex_private *priv, u32 *ps_mode)
  582. {
  583. int ret;
  584. struct mwifiex_adapter *adapter = priv->adapter;
  585. u16 sub_cmd;
  586. if (*ps_mode)
  587. adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
  588. else
  589. adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM;
  590. sub_cmd = (*ps_mode) ? EN_AUTO_PS : DIS_AUTO_PS;
  591. ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
  592. sub_cmd, BITMAP_STA_PS, NULL);
  593. if ((!ret) && (sub_cmd == DIS_AUTO_PS))
  594. ret = mwifiex_send_cmd_async(priv,
  595. HostCmd_CMD_802_11_PS_MODE_ENH,
  596. GET_PS, 0, NULL);
  597. return ret;
  598. }
  599. /*
  600. * IOCTL request handler to set/reset WPA IE.
  601. *
  602. * The supplied WPA IE is treated as a opaque buffer. Only the first field
  603. * is checked to determine WPA version. If buffer length is zero, the existing
  604. * WPA IE is reset.
  605. */
  606. static int mwifiex_set_wpa_ie_helper(struct mwifiex_private *priv,
  607. u8 *ie_data_ptr, u16 ie_len)
  608. {
  609. if (ie_len) {
  610. if (ie_len > sizeof(priv->wpa_ie)) {
  611. dev_err(priv->adapter->dev,
  612. "failed to copy WPA IE, too big\n");
  613. return -1;
  614. }
  615. memcpy(priv->wpa_ie, ie_data_ptr, ie_len);
  616. priv->wpa_ie_len = (u8) ie_len;
  617. dev_dbg(priv->adapter->dev, "cmd: Set Wpa_ie_len=%d IE=%#x\n",
  618. priv->wpa_ie_len, priv->wpa_ie[0]);
  619. if (priv->wpa_ie[0] == WLAN_EID_VENDOR_SPECIFIC) {
  620. priv->sec_info.wpa_enabled = true;
  621. } else if (priv->wpa_ie[0] == WLAN_EID_RSN) {
  622. priv->sec_info.wpa2_enabled = true;
  623. } else {
  624. priv->sec_info.wpa_enabled = false;
  625. priv->sec_info.wpa2_enabled = false;
  626. }
  627. } else {
  628. memset(priv->wpa_ie, 0, sizeof(priv->wpa_ie));
  629. priv->wpa_ie_len = 0;
  630. dev_dbg(priv->adapter->dev, "info: reset wpa_ie_len=%d IE=%#x\n",
  631. priv->wpa_ie_len, priv->wpa_ie[0]);
  632. priv->sec_info.wpa_enabled = false;
  633. priv->sec_info.wpa2_enabled = false;
  634. }
  635. return 0;
  636. }
  637. /*
  638. * IOCTL request handler to set/reset WAPI IE.
  639. *
  640. * The supplied WAPI IE is treated as a opaque buffer. Only the first field
  641. * is checked to internally enable WAPI. If buffer length is zero, the existing
  642. * WAPI IE is reset.
  643. */
  644. static int mwifiex_set_wapi_ie(struct mwifiex_private *priv,
  645. u8 *ie_data_ptr, u16 ie_len)
  646. {
  647. if (ie_len) {
  648. if (ie_len > sizeof(priv->wapi_ie)) {
  649. dev_dbg(priv->adapter->dev,
  650. "info: failed to copy WAPI IE, too big\n");
  651. return -1;
  652. }
  653. memcpy(priv->wapi_ie, ie_data_ptr, ie_len);
  654. priv->wapi_ie_len = ie_len;
  655. dev_dbg(priv->adapter->dev, "cmd: Set wapi_ie_len=%d IE=%#x\n",
  656. priv->wapi_ie_len, priv->wapi_ie[0]);
  657. if (priv->wapi_ie[0] == WLAN_EID_BSS_AC_ACCESS_DELAY)
  658. priv->sec_info.wapi_enabled = true;
  659. } else {
  660. memset(priv->wapi_ie, 0, sizeof(priv->wapi_ie));
  661. priv->wapi_ie_len = ie_len;
  662. dev_dbg(priv->adapter->dev,
  663. "info: Reset wapi_ie_len=%d IE=%#x\n",
  664. priv->wapi_ie_len, priv->wapi_ie[0]);
  665. priv->sec_info.wapi_enabled = false;
  666. }
  667. return 0;
  668. }
  669. /*
  670. * IOCTL request handler to set/reset WPS IE.
  671. *
  672. * The supplied WPS IE is treated as a opaque buffer. Only the first field
  673. * is checked to internally enable WPS. If buffer length is zero, the existing
  674. * WPS IE is reset.
  675. */
  676. static int mwifiex_set_wps_ie(struct mwifiex_private *priv,
  677. u8 *ie_data_ptr, u16 ie_len)
  678. {
  679. if (ie_len) {
  680. priv->wps_ie = kzalloc(MWIFIEX_MAX_VSIE_LEN, GFP_KERNEL);
  681. if (!priv->wps_ie)
  682. return -ENOMEM;
  683. if (ie_len > sizeof(priv->wps_ie)) {
  684. dev_dbg(priv->adapter->dev,
  685. "info: failed to copy WPS IE, too big\n");
  686. kfree(priv->wps_ie);
  687. return -1;
  688. }
  689. memcpy(priv->wps_ie, ie_data_ptr, ie_len);
  690. priv->wps_ie_len = ie_len;
  691. dev_dbg(priv->adapter->dev, "cmd: Set wps_ie_len=%d IE=%#x\n",
  692. priv->wps_ie_len, priv->wps_ie[0]);
  693. } else {
  694. kfree(priv->wps_ie);
  695. priv->wps_ie_len = ie_len;
  696. dev_dbg(priv->adapter->dev,
  697. "info: Reset wps_ie_len=%d\n", priv->wps_ie_len);
  698. }
  699. return 0;
  700. }
  701. /*
  702. * IOCTL request handler to set WAPI key.
  703. *
  704. * This function prepares the correct firmware command and
  705. * issues it.
  706. */
  707. static int mwifiex_sec_ioctl_set_wapi_key(struct mwifiex_private *priv,
  708. struct mwifiex_ds_encrypt_key *encrypt_key)
  709. {
  710. return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
  711. HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
  712. encrypt_key);
  713. }
  714. /*
  715. * IOCTL request handler to set WEP network key.
  716. *
  717. * This function prepares the correct firmware command and
  718. * issues it, after validation checks.
  719. */
  720. static int mwifiex_sec_ioctl_set_wep_key(struct mwifiex_private *priv,
  721. struct mwifiex_ds_encrypt_key *encrypt_key)
  722. {
  723. int ret;
  724. struct mwifiex_wep_key *wep_key;
  725. int index;
  726. if (priv->wep_key_curr_index >= NUM_WEP_KEYS)
  727. priv->wep_key_curr_index = 0;
  728. wep_key = &priv->wep_key[priv->wep_key_curr_index];
  729. index = encrypt_key->key_index;
  730. if (encrypt_key->key_disable) {
  731. priv->sec_info.wep_enabled = 0;
  732. } else if (!encrypt_key->key_len) {
  733. /* Copy the required key as the current key */
  734. wep_key = &priv->wep_key[index];
  735. if (!wep_key->key_length) {
  736. dev_err(priv->adapter->dev,
  737. "key not set, so cannot enable it\n");
  738. return -1;
  739. }
  740. priv->wep_key_curr_index = (u16) index;
  741. priv->sec_info.wep_enabled = 1;
  742. } else {
  743. wep_key = &priv->wep_key[index];
  744. memset(wep_key, 0, sizeof(struct mwifiex_wep_key));
  745. /* Copy the key in the driver */
  746. memcpy(wep_key->key_material,
  747. encrypt_key->key_material,
  748. encrypt_key->key_len);
  749. wep_key->key_index = index;
  750. wep_key->key_length = encrypt_key->key_len;
  751. priv->sec_info.wep_enabled = 1;
  752. }
  753. if (wep_key->key_length) {
  754. /* Send request to firmware */
  755. ret = mwifiex_send_cmd_async(priv,
  756. HostCmd_CMD_802_11_KEY_MATERIAL,
  757. HostCmd_ACT_GEN_SET, 0, NULL);
  758. if (ret)
  759. return ret;
  760. }
  761. if (priv->sec_info.wep_enabled)
  762. priv->curr_pkt_filter |= HostCmd_ACT_MAC_WEP_ENABLE;
  763. else
  764. priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_WEP_ENABLE;
  765. ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_MAC_CONTROL,
  766. HostCmd_ACT_GEN_SET, 0,
  767. &priv->curr_pkt_filter);
  768. return ret;
  769. }
  770. /*
  771. * IOCTL request handler to set WPA key.
  772. *
  773. * This function prepares the correct firmware command and
  774. * issues it, after validation checks.
  775. *
  776. * Current driver only supports key length of up to 32 bytes.
  777. *
  778. * This function can also be used to disable a currently set key.
  779. */
  780. static int mwifiex_sec_ioctl_set_wpa_key(struct mwifiex_private *priv,
  781. struct mwifiex_ds_encrypt_key *encrypt_key)
  782. {
  783. int ret;
  784. u8 remove_key = false;
  785. struct host_cmd_ds_802_11_key_material *ibss_key;
  786. /* Current driver only supports key length of up to 32 bytes */
  787. if (encrypt_key->key_len > WLAN_MAX_KEY_LEN) {
  788. dev_err(priv->adapter->dev, "key length too long\n");
  789. return -1;
  790. }
  791. if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
  792. /*
  793. * IBSS/WPA-None uses only one key (Group) for both receiving
  794. * and sending unicast and multicast packets.
  795. */
  796. /* Send the key as PTK to firmware */
  797. encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
  798. ret = mwifiex_send_cmd_async(priv,
  799. HostCmd_CMD_802_11_KEY_MATERIAL,
  800. HostCmd_ACT_GEN_SET,
  801. KEY_INFO_ENABLED, encrypt_key);
  802. if (ret)
  803. return ret;
  804. ibss_key = &priv->aes_key;
  805. memset(ibss_key, 0,
  806. sizeof(struct host_cmd_ds_802_11_key_material));
  807. /* Copy the key in the driver */
  808. memcpy(ibss_key->key_param_set.key, encrypt_key->key_material,
  809. encrypt_key->key_len);
  810. memcpy(&ibss_key->key_param_set.key_len, &encrypt_key->key_len,
  811. sizeof(ibss_key->key_param_set.key_len));
  812. ibss_key->key_param_set.key_type_id
  813. = cpu_to_le16(KEY_TYPE_ID_TKIP);
  814. ibss_key->key_param_set.key_info = cpu_to_le16(KEY_ENABLED);
  815. /* Send the key as GTK to firmware */
  816. encrypt_key->key_index = ~MWIFIEX_KEY_INDEX_UNICAST;
  817. }
  818. if (!encrypt_key->key_index)
  819. encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
  820. if (remove_key)
  821. ret = mwifiex_send_cmd_sync(priv,
  822. HostCmd_CMD_802_11_KEY_MATERIAL,
  823. HostCmd_ACT_GEN_SET,
  824. !KEY_INFO_ENABLED, encrypt_key);
  825. else
  826. ret = mwifiex_send_cmd_sync(priv,
  827. HostCmd_CMD_802_11_KEY_MATERIAL,
  828. HostCmd_ACT_GEN_SET,
  829. KEY_INFO_ENABLED, encrypt_key);
  830. return ret;
  831. }
  832. /*
  833. * IOCTL request handler to set/get network keys.
  834. *
  835. * This is a generic key handling function which supports WEP, WPA
  836. * and WAPI.
  837. */
  838. static int
  839. mwifiex_sec_ioctl_encrypt_key(struct mwifiex_private *priv,
  840. struct mwifiex_ds_encrypt_key *encrypt_key)
  841. {
  842. int status;
  843. if (encrypt_key->is_wapi_key)
  844. status = mwifiex_sec_ioctl_set_wapi_key(priv, encrypt_key);
  845. else if (encrypt_key->key_len > WLAN_KEY_LEN_WEP104)
  846. status = mwifiex_sec_ioctl_set_wpa_key(priv, encrypt_key);
  847. else
  848. status = mwifiex_sec_ioctl_set_wep_key(priv, encrypt_key);
  849. return status;
  850. }
  851. /*
  852. * This function returns the driver version.
  853. */
  854. int
  855. mwifiex_drv_get_driver_version(struct mwifiex_adapter *adapter, char *version,
  856. int max_len)
  857. {
  858. union {
  859. u32 l;
  860. u8 c[4];
  861. } ver;
  862. char fw_ver[32];
  863. ver.l = adapter->fw_release_number;
  864. sprintf(fw_ver, "%u.%u.%u.p%u", ver.c[2], ver.c[1], ver.c[0], ver.c[3]);
  865. snprintf(version, max_len, driver_version, fw_ver);
  866. dev_dbg(adapter->dev, "info: MWIFIEX VERSION: %s\n", version);
  867. return 0;
  868. }
  869. /*
  870. * Sends IOCTL request to set encoding parameters.
  871. *
  872. * This function allocates the IOCTL request buffer, fills it
  873. * with requisite parameters and calls the IOCTL handler.
  874. */
  875. int mwifiex_set_encode(struct mwifiex_private *priv, struct key_params *kp,
  876. const u8 *key, int key_len, u8 key_index,
  877. const u8 *mac_addr, int disable)
  878. {
  879. struct mwifiex_ds_encrypt_key encrypt_key;
  880. memset(&encrypt_key, 0, sizeof(struct mwifiex_ds_encrypt_key));
  881. encrypt_key.key_len = key_len;
  882. if (kp && kp->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
  883. encrypt_key.is_igtk_key = true;
  884. if (!disable) {
  885. encrypt_key.key_index = key_index;
  886. if (key_len)
  887. memcpy(encrypt_key.key_material, key, key_len);
  888. if (mac_addr)
  889. memcpy(encrypt_key.mac_addr, mac_addr, ETH_ALEN);
  890. if (kp && kp->seq && kp->seq_len)
  891. memcpy(encrypt_key.pn, kp->seq, kp->seq_len);
  892. } else {
  893. encrypt_key.key_disable = true;
  894. if (mac_addr)
  895. memcpy(encrypt_key.mac_addr, mac_addr, ETH_ALEN);
  896. }
  897. return mwifiex_sec_ioctl_encrypt_key(priv, &encrypt_key);
  898. }
  899. /*
  900. * Sends IOCTL request to get extended version.
  901. *
  902. * This function allocates the IOCTL request buffer, fills it
  903. * with requisite parameters and calls the IOCTL handler.
  904. */
  905. int
  906. mwifiex_get_ver_ext(struct mwifiex_private *priv)
  907. {
  908. struct mwifiex_ver_ext ver_ext;
  909. memset(&ver_ext, 0, sizeof(struct host_cmd_ds_version_ext));
  910. if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_VERSION_EXT,
  911. HostCmd_ACT_GEN_GET, 0, &ver_ext))
  912. return -1;
  913. return 0;
  914. }
  915. int
  916. mwifiex_remain_on_chan_cfg(struct mwifiex_private *priv, u16 action,
  917. struct ieee80211_channel *chan,
  918. unsigned int duration)
  919. {
  920. struct host_cmd_ds_remain_on_chan roc_cfg;
  921. u8 sc;
  922. memset(&roc_cfg, 0, sizeof(roc_cfg));
  923. roc_cfg.action = cpu_to_le16(action);
  924. if (action == HostCmd_ACT_GEN_SET) {
  925. roc_cfg.band_cfg = chan->band;
  926. sc = mwifiex_chan_type_to_sec_chan_offset(NL80211_CHAN_NO_HT);
  927. roc_cfg.band_cfg |= (sc << 2);
  928. roc_cfg.channel =
  929. ieee80211_frequency_to_channel(chan->center_freq);
  930. roc_cfg.duration = cpu_to_le32(duration);
  931. }
  932. if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_REMAIN_ON_CHAN,
  933. action, 0, &roc_cfg)) {
  934. dev_err(priv->adapter->dev, "failed to remain on channel\n");
  935. return -1;
  936. }
  937. return roc_cfg.status;
  938. }
  939. int
  940. mwifiex_set_bss_role(struct mwifiex_private *priv, u8 bss_role)
  941. {
  942. if (GET_BSS_ROLE(priv) == bss_role) {
  943. dev_dbg(priv->adapter->dev,
  944. "info: already in the desired role.\n");
  945. return 0;
  946. }
  947. mwifiex_free_priv(priv);
  948. mwifiex_init_priv(priv);
  949. priv->bss_role = bss_role;
  950. switch (bss_role) {
  951. case MWIFIEX_BSS_ROLE_UAP:
  952. priv->bss_mode = NL80211_IFTYPE_AP;
  953. break;
  954. case MWIFIEX_BSS_ROLE_STA:
  955. case MWIFIEX_BSS_ROLE_ANY:
  956. default:
  957. priv->bss_mode = NL80211_IFTYPE_STATION;
  958. break;
  959. }
  960. mwifiex_send_cmd_sync(priv, HostCmd_CMD_SET_BSS_MODE,
  961. HostCmd_ACT_GEN_SET, 0, NULL);
  962. return mwifiex_sta_init_cmd(priv, false);
  963. }
  964. /*
  965. * Sends IOCTL request to get statistics information.
  966. *
  967. * This function allocates the IOCTL request buffer, fills it
  968. * with requisite parameters and calls the IOCTL handler.
  969. */
  970. int
  971. mwifiex_get_stats_info(struct mwifiex_private *priv,
  972. struct mwifiex_ds_get_stats *log)
  973. {
  974. return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_GET_LOG,
  975. HostCmd_ACT_GEN_GET, 0, log);
  976. }
  977. /*
  978. * IOCTL request handler to read/write register.
  979. *
  980. * This function prepares the correct firmware command and
  981. * issues it.
  982. *
  983. * Access to the following registers are supported -
  984. * - MAC
  985. * - BBP
  986. * - RF
  987. * - PMIC
  988. * - CAU
  989. */
  990. static int mwifiex_reg_mem_ioctl_reg_rw(struct mwifiex_private *priv,
  991. struct mwifiex_ds_reg_rw *reg_rw,
  992. u16 action)
  993. {
  994. u16 cmd_no;
  995. switch (le32_to_cpu(reg_rw->type)) {
  996. case MWIFIEX_REG_MAC:
  997. cmd_no = HostCmd_CMD_MAC_REG_ACCESS;
  998. break;
  999. case MWIFIEX_REG_BBP:
  1000. cmd_no = HostCmd_CMD_BBP_REG_ACCESS;
  1001. break;
  1002. case MWIFIEX_REG_RF:
  1003. cmd_no = HostCmd_CMD_RF_REG_ACCESS;
  1004. break;
  1005. case MWIFIEX_REG_PMIC:
  1006. cmd_no = HostCmd_CMD_PMIC_REG_ACCESS;
  1007. break;
  1008. case MWIFIEX_REG_CAU:
  1009. cmd_no = HostCmd_CMD_CAU_REG_ACCESS;
  1010. break;
  1011. default:
  1012. return -1;
  1013. }
  1014. return mwifiex_send_cmd_sync(priv, cmd_no, action, 0, reg_rw);
  1015. }
  1016. /*
  1017. * Sends IOCTL request to write to a register.
  1018. *
  1019. * This function allocates the IOCTL request buffer, fills it
  1020. * with requisite parameters and calls the IOCTL handler.
  1021. */
  1022. int
  1023. mwifiex_reg_write(struct mwifiex_private *priv, u32 reg_type,
  1024. u32 reg_offset, u32 reg_value)
  1025. {
  1026. struct mwifiex_ds_reg_rw reg_rw;
  1027. reg_rw.type = cpu_to_le32(reg_type);
  1028. reg_rw.offset = cpu_to_le32(reg_offset);
  1029. reg_rw.value = cpu_to_le32(reg_value);
  1030. return mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_SET);
  1031. }
  1032. /*
  1033. * Sends IOCTL request to read from a register.
  1034. *
  1035. * This function allocates the IOCTL request buffer, fills it
  1036. * with requisite parameters and calls the IOCTL handler.
  1037. */
  1038. int
  1039. mwifiex_reg_read(struct mwifiex_private *priv, u32 reg_type,
  1040. u32 reg_offset, u32 *value)
  1041. {
  1042. int ret;
  1043. struct mwifiex_ds_reg_rw reg_rw;
  1044. reg_rw.type = cpu_to_le32(reg_type);
  1045. reg_rw.offset = cpu_to_le32(reg_offset);
  1046. ret = mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_GET);
  1047. if (ret)
  1048. goto done;
  1049. *value = le32_to_cpu(reg_rw.value);
  1050. done:
  1051. return ret;
  1052. }
  1053. /*
  1054. * Sends IOCTL request to read from EEPROM.
  1055. *
  1056. * This function allocates the IOCTL request buffer, fills it
  1057. * with requisite parameters and calls the IOCTL handler.
  1058. */
  1059. int
  1060. mwifiex_eeprom_read(struct mwifiex_private *priv, u16 offset, u16 bytes,
  1061. u8 *value)
  1062. {
  1063. int ret;
  1064. struct mwifiex_ds_read_eeprom rd_eeprom;
  1065. rd_eeprom.offset = cpu_to_le16((u16) offset);
  1066. rd_eeprom.byte_count = cpu_to_le16((u16) bytes);
  1067. /* Send request to firmware */
  1068. ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_EEPROM_ACCESS,
  1069. HostCmd_ACT_GEN_GET, 0, &rd_eeprom);
  1070. if (!ret)
  1071. memcpy(value, rd_eeprom.value, MAX_EEPROM_DATA);
  1072. return ret;
  1073. }
  1074. /*
  1075. * This function sets a generic IE. In addition to generic IE, it can
  1076. * also handle WPA, WPA2 and WAPI IEs.
  1077. */
  1078. static int
  1079. mwifiex_set_gen_ie_helper(struct mwifiex_private *priv, u8 *ie_data_ptr,
  1080. u16 ie_len)
  1081. {
  1082. int ret = 0;
  1083. struct ieee_types_vendor_header *pvendor_ie;
  1084. const u8 wpa_oui[] = { 0x00, 0x50, 0xf2, 0x01 };
  1085. const u8 wps_oui[] = { 0x00, 0x50, 0xf2, 0x04 };
  1086. /* If the passed length is zero, reset the buffer */
  1087. if (!ie_len) {
  1088. priv->gen_ie_buf_len = 0;
  1089. priv->wps.session_enable = false;
  1090. return 0;
  1091. } else if (!ie_data_ptr) {
  1092. return -1;
  1093. }
  1094. pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
  1095. /* Test to see if it is a WPA IE, if not, then it is a gen IE */
  1096. if (((pvendor_ie->element_id == WLAN_EID_VENDOR_SPECIFIC) &&
  1097. (!memcmp(pvendor_ie->oui, wpa_oui, sizeof(wpa_oui)))) ||
  1098. (pvendor_ie->element_id == WLAN_EID_RSN)) {
  1099. /* IE is a WPA/WPA2 IE so call set_wpa function */
  1100. ret = mwifiex_set_wpa_ie_helper(priv, ie_data_ptr, ie_len);
  1101. priv->wps.session_enable = false;
  1102. return ret;
  1103. } else if (pvendor_ie->element_id == WLAN_EID_BSS_AC_ACCESS_DELAY) {
  1104. /* IE is a WAPI IE so call set_wapi function */
  1105. ret = mwifiex_set_wapi_ie(priv, ie_data_ptr, ie_len);
  1106. return ret;
  1107. }
  1108. /*
  1109. * Verify that the passed length is not larger than the
  1110. * available space remaining in the buffer
  1111. */
  1112. if (ie_len < (sizeof(priv->gen_ie_buf) - priv->gen_ie_buf_len)) {
  1113. /* Test to see if it is a WPS IE, if so, enable
  1114. * wps session flag
  1115. */
  1116. pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
  1117. if ((pvendor_ie->element_id == WLAN_EID_VENDOR_SPECIFIC) &&
  1118. (!memcmp(pvendor_ie->oui, wps_oui, sizeof(wps_oui)))) {
  1119. priv->wps.session_enable = true;
  1120. dev_dbg(priv->adapter->dev,
  1121. "info: WPS Session Enabled.\n");
  1122. ret = mwifiex_set_wps_ie(priv, ie_data_ptr, ie_len);
  1123. }
  1124. /* Append the passed data to the end of the
  1125. genIeBuffer */
  1126. memcpy(priv->gen_ie_buf + priv->gen_ie_buf_len, ie_data_ptr,
  1127. ie_len);
  1128. /* Increment the stored buffer length by the
  1129. size passed */
  1130. priv->gen_ie_buf_len += ie_len;
  1131. } else {
  1132. /* Passed data does not fit in the remaining
  1133. buffer space */
  1134. ret = -1;
  1135. }
  1136. /* Return 0, or -1 for error case */
  1137. return ret;
  1138. }
  1139. /*
  1140. * IOCTL request handler to set/get generic IE.
  1141. *
  1142. * In addition to various generic IEs, this function can also be
  1143. * used to set the ARP filter.
  1144. */
  1145. static int mwifiex_misc_ioctl_gen_ie(struct mwifiex_private *priv,
  1146. struct mwifiex_ds_misc_gen_ie *gen_ie,
  1147. u16 action)
  1148. {
  1149. struct mwifiex_adapter *adapter = priv->adapter;
  1150. switch (gen_ie->type) {
  1151. case MWIFIEX_IE_TYPE_GEN_IE:
  1152. if (action == HostCmd_ACT_GEN_GET) {
  1153. gen_ie->len = priv->wpa_ie_len;
  1154. memcpy(gen_ie->ie_data, priv->wpa_ie, gen_ie->len);
  1155. } else {
  1156. mwifiex_set_gen_ie_helper(priv, gen_ie->ie_data,
  1157. (u16) gen_ie->len);
  1158. }
  1159. break;
  1160. case MWIFIEX_IE_TYPE_ARP_FILTER:
  1161. memset(adapter->arp_filter, 0, sizeof(adapter->arp_filter));
  1162. if (gen_ie->len > ARP_FILTER_MAX_BUF_SIZE) {
  1163. adapter->arp_filter_size = 0;
  1164. dev_err(adapter->dev, "invalid ARP filter size\n");
  1165. return -1;
  1166. } else {
  1167. memcpy(adapter->arp_filter, gen_ie->ie_data,
  1168. gen_ie->len);
  1169. adapter->arp_filter_size = gen_ie->len;
  1170. }
  1171. break;
  1172. default:
  1173. dev_err(adapter->dev, "invalid IE type\n");
  1174. return -1;
  1175. }
  1176. return 0;
  1177. }
  1178. /*
  1179. * Sends IOCTL request to set a generic IE.
  1180. *
  1181. * This function allocates the IOCTL request buffer, fills it
  1182. * with requisite parameters and calls the IOCTL handler.
  1183. */
  1184. int
  1185. mwifiex_set_gen_ie(struct mwifiex_private *priv, u8 *ie, int ie_len)
  1186. {
  1187. struct mwifiex_ds_misc_gen_ie gen_ie;
  1188. if (ie_len > IEEE_MAX_IE_SIZE)
  1189. return -EFAULT;
  1190. gen_ie.type = MWIFIEX_IE_TYPE_GEN_IE;
  1191. gen_ie.len = ie_len;
  1192. memcpy(gen_ie.ie_data, ie, ie_len);
  1193. if (mwifiex_misc_ioctl_gen_ie(priv, &gen_ie, HostCmd_ACT_GEN_SET))
  1194. return -EFAULT;
  1195. return 0;
  1196. }