sta_ioctl.c 38 KB

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