sta_ioctl.c 35 KB

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