sta_ioctl.c 34 KB

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