sta_ioctl.c 37 KB

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