sta_ioctl.c 37 KB

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