sta_ioctl.c 40 KB

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