sta_ioctl.c 37 KB

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