sta_ioctl.c 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512
  1. /*
  2. * Marvell Wireless LAN device driver: functions for station ioctl
  3. *
  4. * Copyright (C) 2011, Marvell International Ltd.
  5. *
  6. * This software file (the "File") is distributed by Marvell International
  7. * Ltd. under the terms of the GNU General Public License Version 2, June 1991
  8. * (the "License"). You may use, redistribute and/or modify this File in
  9. * accordance with the terms and conditions of the License, a copy of which
  10. * is available by writing to the Free Software Foundation, Inc.,
  11. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
  12. * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
  13. *
  14. * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
  15. * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
  16. * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
  17. * this warranty disclaimer.
  18. */
  19. #include "decl.h"
  20. #include "ioctl.h"
  21. #include "util.h"
  22. #include "fw.h"
  23. #include "main.h"
  24. #include "wmm.h"
  25. #include "11n.h"
  26. #include "cfg80211.h"
  27. /*
  28. * Copies the multicast address list from device to driver.
  29. *
  30. * This function does not validate the destination memory for
  31. * size, and the calling function must ensure enough memory is
  32. * available.
  33. */
  34. int mwifiex_copy_mcast_addr(struct mwifiex_multicast_list *mlist,
  35. struct net_device *dev)
  36. {
  37. int i = 0;
  38. struct netdev_hw_addr *ha;
  39. netdev_for_each_mc_addr(ha, dev)
  40. memcpy(&mlist->mac_list[i++], ha->addr, ETH_ALEN);
  41. return i;
  42. }
  43. /*
  44. * Wait queue completion handler.
  45. *
  46. * This function waits on a cmd wait queue. It also cancels the pending
  47. * request after waking up, in case of errors.
  48. */
  49. int mwifiex_wait_queue_complete(struct mwifiex_adapter *adapter)
  50. {
  51. bool cancel_flag = false;
  52. int status = adapter->cmd_wait_q.status;
  53. struct cmd_ctrl_node *cmd_queued;
  54. if (!adapter->cmd_queued)
  55. return 0;
  56. cmd_queued = adapter->cmd_queued;
  57. adapter->cmd_queued = NULL;
  58. dev_dbg(adapter->dev, "cmd pending\n");
  59. atomic_inc(&adapter->cmd_pending);
  60. /* Status pending, wake up main process */
  61. queue_work(adapter->workqueue, &adapter->main_work);
  62. /* Wait for completion */
  63. wait_event_interruptible(adapter->cmd_wait_q.wait,
  64. *(cmd_queued->condition));
  65. if (!*(cmd_queued->condition))
  66. cancel_flag = true;
  67. if (cancel_flag) {
  68. mwifiex_cancel_pending_ioctl(adapter);
  69. dev_dbg(adapter->dev, "cmd cancel\n");
  70. }
  71. adapter->cmd_wait_q.status = 0;
  72. return status;
  73. }
  74. /*
  75. * This function prepares the correct firmware command and
  76. * issues it to set the multicast list.
  77. *
  78. * This function can be used to enable promiscuous mode, or enable all
  79. * multicast packets, or to enable selective multicast.
  80. */
  81. int mwifiex_request_set_multicast_list(struct mwifiex_private *priv,
  82. struct mwifiex_multicast_list *mcast_list)
  83. {
  84. int ret = 0;
  85. u16 old_pkt_filter;
  86. old_pkt_filter = priv->curr_pkt_filter;
  87. if (mcast_list->mode == MWIFIEX_PROMISC_MODE) {
  88. dev_dbg(priv->adapter->dev, "info: Enable Promiscuous mode\n");
  89. priv->curr_pkt_filter |= HostCmd_ACT_MAC_PROMISCUOUS_ENABLE;
  90. priv->curr_pkt_filter &=
  91. ~HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
  92. } else {
  93. /* Multicast */
  94. priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_PROMISCUOUS_ENABLE;
  95. if (mcast_list->mode == MWIFIEX_MULTICAST_MODE) {
  96. dev_dbg(priv->adapter->dev,
  97. "info: Enabling All Multicast!\n");
  98. priv->curr_pkt_filter |=
  99. HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
  100. } else {
  101. priv->curr_pkt_filter &=
  102. ~HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
  103. if (mcast_list->num_multicast_addr) {
  104. dev_dbg(priv->adapter->dev,
  105. "info: Set multicast list=%d\n",
  106. mcast_list->num_multicast_addr);
  107. /* Set multicast addresses to firmware */
  108. if (old_pkt_filter == priv->curr_pkt_filter) {
  109. /* Send request to firmware */
  110. ret = mwifiex_send_cmd_async(priv,
  111. HostCmd_CMD_MAC_MULTICAST_ADR,
  112. HostCmd_ACT_GEN_SET, 0,
  113. mcast_list);
  114. } else {
  115. /* Send request to firmware */
  116. ret = mwifiex_send_cmd_async(priv,
  117. HostCmd_CMD_MAC_MULTICAST_ADR,
  118. HostCmd_ACT_GEN_SET, 0,
  119. mcast_list);
  120. }
  121. }
  122. }
  123. }
  124. dev_dbg(priv->adapter->dev,
  125. "info: old_pkt_filter=%#x, curr_pkt_filter=%#x\n",
  126. old_pkt_filter, priv->curr_pkt_filter);
  127. if (old_pkt_filter != priv->curr_pkt_filter) {
  128. ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_MAC_CONTROL,
  129. HostCmd_ACT_GEN_SET,
  130. 0, &priv->curr_pkt_filter);
  131. }
  132. return ret;
  133. }
  134. /*
  135. * This function fills bss descriptor structure using provided
  136. * information.
  137. */
  138. int mwifiex_fill_new_bss_desc(struct mwifiex_private *priv,
  139. u8 *bssid, s32 rssi, u8 *ie_buf,
  140. size_t ie_len, u16 beacon_period,
  141. u16 cap_info_bitmap, u8 band,
  142. struct mwifiex_bssdescriptor *bss_desc)
  143. {
  144. int ret;
  145. memcpy(bss_desc->mac_address, bssid, ETH_ALEN);
  146. bss_desc->rssi = rssi;
  147. bss_desc->beacon_buf = ie_buf;
  148. bss_desc->beacon_buf_size = ie_len;
  149. bss_desc->beacon_period = beacon_period;
  150. bss_desc->cap_info_bitmap = cap_info_bitmap;
  151. bss_desc->bss_band = band;
  152. if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_PRIVACY) {
  153. dev_dbg(priv->adapter->dev, "info: InterpretIE: AP WEP enabled\n");
  154. bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_8021X_WEP;
  155. } else {
  156. bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_ACCEPT_ALL;
  157. }
  158. if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_IBSS)
  159. bss_desc->bss_mode = NL80211_IFTYPE_ADHOC;
  160. else
  161. bss_desc->bss_mode = NL80211_IFTYPE_STATION;
  162. ret = mwifiex_update_bss_desc_with_ie(priv->adapter, bss_desc,
  163. ie_buf, ie_len);
  164. return ret;
  165. }
  166. /*
  167. * In Ad-Hoc mode, the IBSS is created if not found in scan list.
  168. * In both Ad-Hoc and infra mode, an deauthentication is performed
  169. * first.
  170. */
  171. int mwifiex_bss_start(struct mwifiex_private *priv, struct cfg80211_bss *bss,
  172. struct mwifiex_802_11_ssid *req_ssid)
  173. {
  174. int ret;
  175. struct mwifiex_adapter *adapter = priv->adapter;
  176. struct mwifiex_bssdescriptor *bss_desc = NULL;
  177. u8 *beacon_ie = NULL;
  178. priv->scan_block = false;
  179. if (bss) {
  180. /* Allocate and fill new bss descriptor */
  181. bss_desc = kzalloc(sizeof(struct mwifiex_bssdescriptor),
  182. GFP_KERNEL);
  183. if (!bss_desc) {
  184. dev_err(priv->adapter->dev, " failed to alloc bss_desc\n");
  185. return -ENOMEM;
  186. }
  187. beacon_ie = kmemdup(bss->information_elements,
  188. bss->len_beacon_ies, GFP_KERNEL);
  189. if (!beacon_ie) {
  190. kfree(bss_desc);
  191. dev_err(priv->adapter->dev, " failed to alloc beacon_ie\n");
  192. return -ENOMEM;
  193. }
  194. ret = mwifiex_fill_new_bss_desc(priv, bss->bssid, bss->signal,
  195. beacon_ie, bss->len_beacon_ies,
  196. bss->beacon_interval,
  197. bss->capability,
  198. *(u8 *)bss->priv, bss_desc);
  199. if (ret)
  200. goto done;
  201. }
  202. if (priv->bss_mode == NL80211_IFTYPE_STATION) {
  203. /* Infra mode */
  204. ret = mwifiex_deauthenticate(priv, NULL);
  205. if (ret)
  206. goto done;
  207. ret = mwifiex_check_network_compatibility(priv, bss_desc);
  208. if (ret)
  209. goto done;
  210. dev_dbg(adapter->dev, "info: SSID found in scan list ... "
  211. "associating...\n");
  212. if (!netif_queue_stopped(priv->netdev))
  213. mwifiex_stop_net_dev_queue(priv->netdev, adapter);
  214. /* Clear any past association response stored for
  215. * application retrieval */
  216. priv->assoc_rsp_size = 0;
  217. ret = mwifiex_associate(priv, bss_desc);
  218. if (bss)
  219. cfg80211_put_bss(bss);
  220. } else {
  221. /* Adhoc mode */
  222. /* If the requested SSID matches current SSID, return */
  223. if (bss_desc && bss_desc->ssid.ssid_len &&
  224. (!mwifiex_ssid_cmp
  225. (&priv->curr_bss_params.bss_descriptor.ssid,
  226. &bss_desc->ssid))) {
  227. kfree(bss_desc);
  228. kfree(beacon_ie);
  229. return 0;
  230. }
  231. /* Exit Adhoc mode first */
  232. dev_dbg(adapter->dev, "info: Sending Adhoc Stop\n");
  233. ret = mwifiex_deauthenticate(priv, NULL);
  234. if (ret)
  235. goto done;
  236. priv->adhoc_is_link_sensed = false;
  237. ret = mwifiex_check_network_compatibility(priv, bss_desc);
  238. if (!netif_queue_stopped(priv->netdev))
  239. mwifiex_stop_net_dev_queue(priv->netdev, adapter);
  240. if (!ret) {
  241. dev_dbg(adapter->dev, "info: network found in scan"
  242. " list. Joining...\n");
  243. ret = mwifiex_adhoc_join(priv, bss_desc);
  244. if (bss)
  245. cfg80211_put_bss(bss);
  246. } else {
  247. dev_dbg(adapter->dev, "info: Network not found in "
  248. "the list, creating adhoc with ssid = %s\n",
  249. req_ssid->ssid);
  250. ret = mwifiex_adhoc_start(priv, req_ssid);
  251. }
  252. }
  253. done:
  254. kfree(bss_desc);
  255. kfree(beacon_ie);
  256. return ret;
  257. }
  258. /*
  259. * IOCTL request handler to set host sleep configuration.
  260. *
  261. * This function prepares the correct firmware command and
  262. * issues it.
  263. */
  264. static int mwifiex_set_hs_params(struct mwifiex_private *priv, u16 action,
  265. int cmd_type, struct mwifiex_ds_hs_cfg *hs_cfg)
  266. {
  267. struct mwifiex_adapter *adapter = priv->adapter;
  268. int status = 0;
  269. u32 prev_cond = 0;
  270. if (!hs_cfg)
  271. return -ENOMEM;
  272. switch (action) {
  273. case HostCmd_ACT_GEN_SET:
  274. if (adapter->pps_uapsd_mode) {
  275. dev_dbg(adapter->dev, "info: Host Sleep IOCTL"
  276. " is blocked in UAPSD/PPS mode\n");
  277. status = -1;
  278. break;
  279. }
  280. if (hs_cfg->is_invoke_hostcmd) {
  281. if (hs_cfg->conditions == HOST_SLEEP_CFG_CANCEL) {
  282. if (!adapter->is_hs_configured)
  283. /* Already cancelled */
  284. break;
  285. /* Save previous condition */
  286. prev_cond = le32_to_cpu(adapter->hs_cfg
  287. .conditions);
  288. adapter->hs_cfg.conditions =
  289. cpu_to_le32(hs_cfg->conditions);
  290. } else if (hs_cfg->conditions) {
  291. adapter->hs_cfg.conditions =
  292. cpu_to_le32(hs_cfg->conditions);
  293. adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
  294. if (hs_cfg->gap)
  295. adapter->hs_cfg.gap = (u8)hs_cfg->gap;
  296. } else if (adapter->hs_cfg.conditions ==
  297. cpu_to_le32(
  298. HOST_SLEEP_CFG_CANCEL)) {
  299. /* Return failure if no parameters for HS
  300. enable */
  301. status = -1;
  302. break;
  303. }
  304. if (cmd_type == MWIFIEX_SYNC_CMD)
  305. status = mwifiex_send_cmd_sync(priv,
  306. HostCmd_CMD_802_11_HS_CFG_ENH,
  307. HostCmd_ACT_GEN_SET, 0,
  308. &adapter->hs_cfg);
  309. else
  310. status = mwifiex_send_cmd_async(priv,
  311. HostCmd_CMD_802_11_HS_CFG_ENH,
  312. HostCmd_ACT_GEN_SET, 0,
  313. &adapter->hs_cfg);
  314. if (hs_cfg->conditions == HOST_SLEEP_CFG_CANCEL)
  315. /* Restore previous condition */
  316. adapter->hs_cfg.conditions =
  317. cpu_to_le32(prev_cond);
  318. } else {
  319. adapter->hs_cfg.conditions =
  320. cpu_to_le32(hs_cfg->conditions);
  321. adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
  322. adapter->hs_cfg.gap = (u8)hs_cfg->gap;
  323. }
  324. break;
  325. case HostCmd_ACT_GEN_GET:
  326. hs_cfg->conditions = le32_to_cpu(adapter->hs_cfg.conditions);
  327. hs_cfg->gpio = adapter->hs_cfg.gpio;
  328. hs_cfg->gap = adapter->hs_cfg.gap;
  329. break;
  330. default:
  331. status = -1;
  332. break;
  333. }
  334. return status;
  335. }
  336. /*
  337. * Sends IOCTL request to cancel the existing Host Sleep configuration.
  338. *
  339. * This function allocates the IOCTL request buffer, fills it
  340. * with requisite parameters and calls the IOCTL handler.
  341. */
  342. int mwifiex_cancel_hs(struct mwifiex_private *priv, int cmd_type)
  343. {
  344. struct mwifiex_ds_hs_cfg hscfg;
  345. hscfg.conditions = HOST_SLEEP_CFG_CANCEL;
  346. hscfg.is_invoke_hostcmd = true;
  347. return mwifiex_set_hs_params(priv, HostCmd_ACT_GEN_SET,
  348. cmd_type, &hscfg);
  349. }
  350. EXPORT_SYMBOL_GPL(mwifiex_cancel_hs);
  351. /*
  352. * Sends IOCTL request to cancel the existing Host Sleep configuration.
  353. *
  354. * This function allocates the IOCTL request buffer, fills it
  355. * with requisite parameters and calls the IOCTL handler.
  356. */
  357. int mwifiex_enable_hs(struct mwifiex_adapter *adapter)
  358. {
  359. struct mwifiex_ds_hs_cfg hscfg;
  360. if (adapter->hs_activated) {
  361. dev_dbg(adapter->dev, "cmd: HS Already actived\n");
  362. return true;
  363. }
  364. adapter->hs_activate_wait_q_woken = false;
  365. memset(&hscfg, 0, sizeof(struct mwifiex_hs_config_param));
  366. hscfg.is_invoke_hostcmd = true;
  367. if (mwifiex_set_hs_params(mwifiex_get_priv(adapter,
  368. MWIFIEX_BSS_ROLE_STA),
  369. HostCmd_ACT_GEN_SET, MWIFIEX_SYNC_CMD,
  370. &hscfg)) {
  371. dev_err(adapter->dev, "IOCTL request HS enable failed\n");
  372. return false;
  373. }
  374. wait_event_interruptible(adapter->hs_activate_wait_q,
  375. adapter->hs_activate_wait_q_woken);
  376. return true;
  377. }
  378. EXPORT_SYMBOL_GPL(mwifiex_enable_hs);
  379. /*
  380. * IOCTL request handler to get BSS information.
  381. *
  382. * This function collates the information from different driver structures
  383. * to send to the user.
  384. */
  385. int mwifiex_get_bss_info(struct mwifiex_private *priv,
  386. struct mwifiex_bss_info *info)
  387. {
  388. struct mwifiex_adapter *adapter = priv->adapter;
  389. struct mwifiex_bssdescriptor *bss_desc;
  390. if (!info)
  391. return -1;
  392. bss_desc = &priv->curr_bss_params.bss_descriptor;
  393. info->bss_mode = priv->bss_mode;
  394. memcpy(&info->ssid, &bss_desc->ssid,
  395. sizeof(struct mwifiex_802_11_ssid));
  396. memcpy(&info->bssid, &bss_desc->mac_address, ETH_ALEN);
  397. info->bss_chan = bss_desc->channel;
  398. info->region_code = adapter->region_code;
  399. info->media_connected = priv->media_connected;
  400. info->max_power_level = priv->max_tx_power_level;
  401. info->min_power_level = priv->min_tx_power_level;
  402. info->adhoc_state = priv->adhoc_state;
  403. info->bcn_nf_last = priv->bcn_nf_last;
  404. if (priv->sec_info.wep_status == MWIFIEX_802_11_WEP_ENABLED)
  405. info->wep_status = true;
  406. else
  407. info->wep_status = false;
  408. info->is_hs_configured = adapter->is_hs_configured;
  409. info->is_deep_sleep = adapter->is_deep_sleep;
  410. return 0;
  411. }
  412. /*
  413. * The function disables auto deep sleep mode.
  414. */
  415. int mwifiex_disable_auto_ds(struct mwifiex_private *priv)
  416. {
  417. struct mwifiex_ds_auto_ds auto_ds;
  418. auto_ds.auto_ds = DEEP_SLEEP_OFF;
  419. return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
  420. DIS_AUTO_PS, BITMAP_AUTO_DS, &auto_ds);
  421. }
  422. EXPORT_SYMBOL_GPL(mwifiex_disable_auto_ds);
  423. /*
  424. * IOCTL request handler to set/get active channel.
  425. *
  426. * This function performs validity checking on channel/frequency
  427. * compatibility and returns failure if not valid.
  428. */
  429. int mwifiex_bss_set_channel(struct mwifiex_private *priv,
  430. struct mwifiex_chan_freq_power *chan)
  431. {
  432. struct mwifiex_adapter *adapter = priv->adapter;
  433. struct mwifiex_chan_freq_power *cfp = NULL;
  434. if (!chan)
  435. return -1;
  436. if (!chan->channel && !chan->freq)
  437. return -1;
  438. if (adapter->adhoc_start_band & BAND_AN)
  439. adapter->adhoc_start_band = BAND_G | BAND_B | BAND_GN;
  440. else if (adapter->adhoc_start_band & BAND_A)
  441. adapter->adhoc_start_band = BAND_G | BAND_B;
  442. if (chan->channel) {
  443. if (chan->channel <= MAX_CHANNEL_BAND_BG)
  444. cfp = mwifiex_get_cfp_by_band_and_channel_from_cfg80211
  445. (priv, 0, (u16) chan->channel);
  446. if (!cfp) {
  447. cfp = mwifiex_get_cfp_by_band_and_channel_from_cfg80211
  448. (priv, BAND_A, (u16) chan->channel);
  449. if (cfp) {
  450. if (adapter->adhoc_11n_enabled)
  451. adapter->adhoc_start_band = BAND_A
  452. | BAND_AN;
  453. else
  454. adapter->adhoc_start_band = BAND_A;
  455. }
  456. }
  457. } else {
  458. if (chan->freq <= MAX_FREQUENCY_BAND_BG)
  459. cfp = mwifiex_get_cfp_by_band_and_freq_from_cfg80211(
  460. priv, 0, chan->freq);
  461. if (!cfp) {
  462. cfp = mwifiex_get_cfp_by_band_and_freq_from_cfg80211
  463. (priv, BAND_A, chan->freq);
  464. if (cfp) {
  465. if (adapter->adhoc_11n_enabled)
  466. adapter->adhoc_start_band = BAND_A
  467. | BAND_AN;
  468. else
  469. adapter->adhoc_start_band = BAND_A;
  470. }
  471. }
  472. }
  473. if (!cfp || !cfp->channel) {
  474. dev_err(adapter->dev, "invalid channel/freq\n");
  475. return -1;
  476. }
  477. priv->adhoc_channel = (u8) cfp->channel;
  478. chan->channel = cfp->channel;
  479. chan->freq = cfp->freq;
  480. return 0;
  481. }
  482. /*
  483. * IOCTL request handler to set/get Ad-Hoc channel.
  484. *
  485. * This function prepares the correct firmware command and
  486. * issues it to set or get the ad-hoc channel.
  487. */
  488. static int mwifiex_bss_ioctl_ibss_channel(struct mwifiex_private *priv,
  489. u16 action, u16 *channel)
  490. {
  491. if (action == HostCmd_ACT_GEN_GET) {
  492. if (!priv->media_connected) {
  493. *channel = priv->adhoc_channel;
  494. return 0;
  495. }
  496. } else {
  497. priv->adhoc_channel = (u8) *channel;
  498. }
  499. return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_RF_CHANNEL,
  500. action, 0, channel);
  501. }
  502. /*
  503. * IOCTL request handler to change Ad-Hoc channel.
  504. *
  505. * This function allocates the IOCTL request buffer, fills it
  506. * with requisite parameters and calls the IOCTL handler.
  507. *
  508. * The function follows the following steps to perform the change -
  509. * - Get current IBSS information
  510. * - Get current channel
  511. * - If no change is required, return
  512. * - If not connected, change channel and return
  513. * - If connected,
  514. * - Disconnect
  515. * - Change channel
  516. * - Perform specific SSID scan with same SSID
  517. * - Start/Join the IBSS
  518. */
  519. int
  520. mwifiex_drv_change_adhoc_chan(struct mwifiex_private *priv, int channel)
  521. {
  522. int ret;
  523. struct mwifiex_bss_info bss_info;
  524. struct mwifiex_ssid_bssid ssid_bssid;
  525. u16 curr_chan = 0;
  526. struct cfg80211_bss *bss = NULL;
  527. struct ieee80211_channel *chan;
  528. enum ieee80211_band band;
  529. memset(&bss_info, 0, sizeof(bss_info));
  530. /* Get BSS information */
  531. if (mwifiex_get_bss_info(priv, &bss_info))
  532. return -1;
  533. /* Get current channel */
  534. ret = mwifiex_bss_ioctl_ibss_channel(priv, HostCmd_ACT_GEN_GET,
  535. &curr_chan);
  536. if (curr_chan == channel) {
  537. ret = 0;
  538. goto done;
  539. }
  540. dev_dbg(priv->adapter->dev, "cmd: updating channel from %d to %d\n",
  541. curr_chan, channel);
  542. if (!bss_info.media_connected) {
  543. ret = 0;
  544. goto done;
  545. }
  546. /* Do disonnect */
  547. memset(&ssid_bssid, 0, ETH_ALEN);
  548. ret = mwifiex_deauthenticate(priv, ssid_bssid.bssid);
  549. ret = mwifiex_bss_ioctl_ibss_channel(priv, HostCmd_ACT_GEN_SET,
  550. (u16 *) &channel);
  551. /* Do specific SSID scanning */
  552. if (mwifiex_request_scan(priv, &bss_info.ssid)) {
  553. ret = -1;
  554. goto done;
  555. }
  556. band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
  557. chan = __ieee80211_get_channel(priv->wdev->wiphy,
  558. ieee80211_channel_to_frequency(channel, band));
  559. /* Find the BSS we want using available scan results */
  560. bss = cfg80211_get_bss(priv->wdev->wiphy, chan, bss_info.bssid,
  561. bss_info.ssid.ssid, bss_info.ssid.ssid_len,
  562. WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
  563. if (!bss)
  564. wiphy_warn(priv->wdev->wiphy, "assoc: bss %pM not in scan results\n",
  565. bss_info.bssid);
  566. ret = mwifiex_bss_start(priv, bss, &bss_info.ssid);
  567. done:
  568. return ret;
  569. }
  570. /*
  571. * IOCTL request handler to get rate.
  572. *
  573. * This function prepares the correct firmware command and
  574. * issues it to get the current rate if it is connected,
  575. * otherwise, the function returns the lowest supported rate
  576. * for the band.
  577. */
  578. static int mwifiex_rate_ioctl_get_rate_value(struct mwifiex_private *priv,
  579. struct mwifiex_rate_cfg *rate_cfg)
  580. {
  581. rate_cfg->is_rate_auto = priv->is_data_rate_auto;
  582. return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_TX_RATE_QUERY,
  583. HostCmd_ACT_GEN_GET, 0, NULL);
  584. }
  585. /*
  586. * IOCTL request handler to set rate.
  587. *
  588. * This function prepares the correct firmware command and
  589. * issues it to set the current rate.
  590. *
  591. * The function also performs validation checking on the supplied value.
  592. */
  593. static int mwifiex_rate_ioctl_set_rate_value(struct mwifiex_private *priv,
  594. struct mwifiex_rate_cfg *rate_cfg)
  595. {
  596. u8 rates[MWIFIEX_SUPPORTED_RATES];
  597. u8 *rate;
  598. int rate_index, ret;
  599. u16 bitmap_rates[MAX_BITMAP_RATES_SIZE];
  600. u32 i;
  601. struct mwifiex_adapter *adapter = priv->adapter;
  602. if (rate_cfg->is_rate_auto) {
  603. memset(bitmap_rates, 0, sizeof(bitmap_rates));
  604. /* Support all HR/DSSS rates */
  605. bitmap_rates[0] = 0x000F;
  606. /* Support all OFDM rates */
  607. bitmap_rates[1] = 0x00FF;
  608. /* Support all HT-MCSs rate */
  609. for (i = 0; i < ARRAY_SIZE(priv->bitmap_rates) - 3; i++)
  610. bitmap_rates[i + 2] = 0xFFFF;
  611. bitmap_rates[9] = 0x3FFF;
  612. } else {
  613. memset(rates, 0, sizeof(rates));
  614. mwifiex_get_active_data_rates(priv, rates);
  615. rate = rates;
  616. for (i = 0; (rate[i] && i < MWIFIEX_SUPPORTED_RATES); i++) {
  617. dev_dbg(adapter->dev, "info: rate=%#x wanted=%#x\n",
  618. rate[i], rate_cfg->rate);
  619. if ((rate[i] & 0x7f) == (rate_cfg->rate & 0x7f))
  620. break;
  621. }
  622. if ((i == MWIFIEX_SUPPORTED_RATES) || !rate[i]) {
  623. dev_err(adapter->dev, "fixed data rate %#x is out "
  624. "of range\n", rate_cfg->rate);
  625. return -1;
  626. }
  627. memset(bitmap_rates, 0, sizeof(bitmap_rates));
  628. rate_index = mwifiex_data_rate_to_index(rate_cfg->rate);
  629. /* Only allow b/g rates to be set */
  630. if (rate_index >= MWIFIEX_RATE_INDEX_HRDSSS0 &&
  631. rate_index <= MWIFIEX_RATE_INDEX_HRDSSS3) {
  632. bitmap_rates[0] = 1 << rate_index;
  633. } else {
  634. rate_index -= 1; /* There is a 0x00 in the table */
  635. if (rate_index >= MWIFIEX_RATE_INDEX_OFDM0 &&
  636. rate_index <= MWIFIEX_RATE_INDEX_OFDM7)
  637. bitmap_rates[1] = 1 << (rate_index -
  638. MWIFIEX_RATE_INDEX_OFDM0);
  639. }
  640. }
  641. ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_TX_RATE_CFG,
  642. HostCmd_ACT_GEN_SET, 0, bitmap_rates);
  643. return ret;
  644. }
  645. /*
  646. * IOCTL request handler to set/get rate.
  647. *
  648. * This function can be used to set/get either the rate value or the
  649. * rate index.
  650. */
  651. static int mwifiex_rate_ioctl_cfg(struct mwifiex_private *priv,
  652. struct mwifiex_rate_cfg *rate_cfg)
  653. {
  654. int status;
  655. if (!rate_cfg)
  656. return -1;
  657. if (rate_cfg->action == HostCmd_ACT_GEN_GET)
  658. status = mwifiex_rate_ioctl_get_rate_value(priv, rate_cfg);
  659. else
  660. status = mwifiex_rate_ioctl_set_rate_value(priv, rate_cfg);
  661. return status;
  662. }
  663. /*
  664. * Sends IOCTL request to get the data rate.
  665. *
  666. * This function allocates the IOCTL request buffer, fills it
  667. * with requisite parameters and calls the IOCTL handler.
  668. */
  669. int mwifiex_drv_get_data_rate(struct mwifiex_private *priv,
  670. struct mwifiex_rate_cfg *rate)
  671. {
  672. int ret;
  673. memset(rate, 0, sizeof(struct mwifiex_rate_cfg));
  674. rate->action = HostCmd_ACT_GEN_GET;
  675. ret = mwifiex_rate_ioctl_cfg(priv, rate);
  676. if (!ret) {
  677. if (rate->is_rate_auto)
  678. rate->rate = mwifiex_index_to_data_rate(priv,
  679. priv->tx_rate, priv->tx_htinfo);
  680. else
  681. rate->rate = priv->data_rate;
  682. } else {
  683. ret = -1;
  684. }
  685. return ret;
  686. }
  687. /*
  688. * IOCTL request handler to set tx power configuration.
  689. *
  690. * This function prepares the correct firmware command and
  691. * issues it.
  692. *
  693. * For non-auto power mode, all the following power groups are set -
  694. * - Modulation class HR/DSSS
  695. * - Modulation class OFDM
  696. * - Modulation class HTBW20
  697. * - Modulation class HTBW40
  698. */
  699. int mwifiex_set_tx_power(struct mwifiex_private *priv,
  700. struct mwifiex_power_cfg *power_cfg)
  701. {
  702. int ret;
  703. struct host_cmd_ds_txpwr_cfg *txp_cfg;
  704. struct mwifiex_types_power_group *pg_tlv;
  705. struct mwifiex_power_group *pg;
  706. u8 *buf;
  707. u16 dbm = 0;
  708. if (!power_cfg->is_power_auto) {
  709. dbm = (u16) power_cfg->power_level;
  710. if ((dbm < priv->min_tx_power_level) ||
  711. (dbm > priv->max_tx_power_level)) {
  712. dev_err(priv->adapter->dev, "txpower value %d dBm"
  713. " is out of range (%d dBm-%d dBm)\n",
  714. dbm, priv->min_tx_power_level,
  715. priv->max_tx_power_level);
  716. return -1;
  717. }
  718. }
  719. buf = kzalloc(MWIFIEX_SIZE_OF_CMD_BUFFER, GFP_KERNEL);
  720. if (!buf) {
  721. dev_err(priv->adapter->dev, "%s: failed to alloc cmd buffer\n",
  722. __func__);
  723. return -ENOMEM;
  724. }
  725. txp_cfg = (struct host_cmd_ds_txpwr_cfg *) buf;
  726. txp_cfg->action = cpu_to_le16(HostCmd_ACT_GEN_SET);
  727. if (!power_cfg->is_power_auto) {
  728. txp_cfg->mode = cpu_to_le32(1);
  729. pg_tlv = (struct mwifiex_types_power_group *) (buf +
  730. sizeof(struct host_cmd_ds_txpwr_cfg));
  731. pg_tlv->type = TLV_TYPE_POWER_GROUP;
  732. pg_tlv->length = 4 * sizeof(struct mwifiex_power_group);
  733. pg = (struct mwifiex_power_group *) (buf +
  734. sizeof(struct host_cmd_ds_txpwr_cfg) +
  735. sizeof(struct mwifiex_types_power_group));
  736. /* Power group for modulation class HR/DSSS */
  737. pg->first_rate_code = 0x00;
  738. pg->last_rate_code = 0x03;
  739. pg->modulation_class = MOD_CLASS_HR_DSSS;
  740. pg->power_step = 0;
  741. pg->power_min = (s8) dbm;
  742. pg->power_max = (s8) dbm;
  743. pg++;
  744. /* Power group for modulation class OFDM */
  745. pg->first_rate_code = 0x00;
  746. pg->last_rate_code = 0x07;
  747. pg->modulation_class = MOD_CLASS_OFDM;
  748. pg->power_step = 0;
  749. pg->power_min = (s8) dbm;
  750. pg->power_max = (s8) dbm;
  751. pg++;
  752. /* Power group for modulation class HTBW20 */
  753. pg->first_rate_code = 0x00;
  754. pg->last_rate_code = 0x20;
  755. pg->modulation_class = MOD_CLASS_HT;
  756. pg->power_step = 0;
  757. pg->power_min = (s8) dbm;
  758. pg->power_max = (s8) dbm;
  759. pg->ht_bandwidth = HT_BW_20;
  760. pg++;
  761. /* Power group for modulation class HTBW40 */
  762. pg->first_rate_code = 0x00;
  763. pg->last_rate_code = 0x20;
  764. pg->modulation_class = MOD_CLASS_HT;
  765. pg->power_step = 0;
  766. pg->power_min = (s8) dbm;
  767. pg->power_max = (s8) dbm;
  768. pg->ht_bandwidth = HT_BW_40;
  769. }
  770. ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_TXPWR_CFG,
  771. HostCmd_ACT_GEN_SET, 0, buf);
  772. kfree(buf);
  773. return ret;
  774. }
  775. /*
  776. * IOCTL request handler to get power save mode.
  777. *
  778. * This function prepares the correct firmware command and
  779. * issues it.
  780. */
  781. int mwifiex_drv_set_power(struct mwifiex_private *priv, u32 *ps_mode)
  782. {
  783. int ret;
  784. struct mwifiex_adapter *adapter = priv->adapter;
  785. u16 sub_cmd;
  786. if (*ps_mode)
  787. adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
  788. else
  789. adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM;
  790. sub_cmd = (*ps_mode) ? EN_AUTO_PS : DIS_AUTO_PS;
  791. ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
  792. sub_cmd, BITMAP_STA_PS, NULL);
  793. if ((!ret) && (sub_cmd == DIS_AUTO_PS))
  794. ret = mwifiex_send_cmd_async(priv,
  795. HostCmd_CMD_802_11_PS_MODE_ENH, GET_PS,
  796. 0, NULL);
  797. return ret;
  798. }
  799. /*
  800. * IOCTL request handler to set/reset WPA IE.
  801. *
  802. * The supplied WPA IE is treated as a opaque buffer. Only the first field
  803. * is checked to determine WPA version. If buffer length is zero, the existing
  804. * WPA IE is reset.
  805. */
  806. static int mwifiex_set_wpa_ie_helper(struct mwifiex_private *priv,
  807. u8 *ie_data_ptr, u16 ie_len)
  808. {
  809. if (ie_len) {
  810. if (ie_len > sizeof(priv->wpa_ie)) {
  811. dev_err(priv->adapter->dev,
  812. "failed to copy WPA IE, too big\n");
  813. return -1;
  814. }
  815. memcpy(priv->wpa_ie, ie_data_ptr, ie_len);
  816. priv->wpa_ie_len = (u8) ie_len;
  817. dev_dbg(priv->adapter->dev, "cmd: Set Wpa_ie_len=%d IE=%#x\n",
  818. priv->wpa_ie_len, priv->wpa_ie[0]);
  819. if (priv->wpa_ie[0] == WLAN_EID_WPA) {
  820. priv->sec_info.wpa_enabled = true;
  821. } else if (priv->wpa_ie[0] == WLAN_EID_RSN) {
  822. priv->sec_info.wpa2_enabled = true;
  823. } else {
  824. priv->sec_info.wpa_enabled = false;
  825. priv->sec_info.wpa2_enabled = false;
  826. }
  827. } else {
  828. memset(priv->wpa_ie, 0, sizeof(priv->wpa_ie));
  829. priv->wpa_ie_len = 0;
  830. dev_dbg(priv->adapter->dev, "info: reset wpa_ie_len=%d IE=%#x\n",
  831. priv->wpa_ie_len, priv->wpa_ie[0]);
  832. priv->sec_info.wpa_enabled = false;
  833. priv->sec_info.wpa2_enabled = false;
  834. }
  835. return 0;
  836. }
  837. /*
  838. * IOCTL request handler to set/reset WAPI IE.
  839. *
  840. * The supplied WAPI IE is treated as a opaque buffer. Only the first field
  841. * is checked to internally enable WAPI. If buffer length is zero, the existing
  842. * WAPI IE is reset.
  843. */
  844. static int mwifiex_set_wapi_ie(struct mwifiex_private *priv,
  845. u8 *ie_data_ptr, u16 ie_len)
  846. {
  847. if (ie_len) {
  848. if (ie_len > sizeof(priv->wapi_ie)) {
  849. dev_dbg(priv->adapter->dev,
  850. "info: failed to copy WAPI IE, too big\n");
  851. return -1;
  852. }
  853. memcpy(priv->wapi_ie, ie_data_ptr, ie_len);
  854. priv->wapi_ie_len = ie_len;
  855. dev_dbg(priv->adapter->dev, "cmd: Set wapi_ie_len=%d IE=%#x\n",
  856. priv->wapi_ie_len, priv->wapi_ie[0]);
  857. if (priv->wapi_ie[0] == WLAN_EID_BSS_AC_ACCESS_DELAY)
  858. priv->sec_info.wapi_enabled = true;
  859. } else {
  860. memset(priv->wapi_ie, 0, sizeof(priv->wapi_ie));
  861. priv->wapi_ie_len = ie_len;
  862. dev_dbg(priv->adapter->dev,
  863. "info: Reset wapi_ie_len=%d IE=%#x\n",
  864. priv->wapi_ie_len, priv->wapi_ie[0]);
  865. priv->sec_info.wapi_enabled = false;
  866. }
  867. return 0;
  868. }
  869. /*
  870. * IOCTL request handler to set WAPI key.
  871. *
  872. * This function prepares the correct firmware command and
  873. * issues it.
  874. */
  875. static int mwifiex_sec_ioctl_set_wapi_key(struct mwifiex_private *priv,
  876. struct mwifiex_ds_encrypt_key *encrypt_key)
  877. {
  878. return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
  879. HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
  880. encrypt_key);
  881. }
  882. /*
  883. * IOCTL request handler to set WEP network key.
  884. *
  885. * This function prepares the correct firmware command and
  886. * issues it, after validation checks.
  887. */
  888. static int mwifiex_sec_ioctl_set_wep_key(struct mwifiex_private *priv,
  889. struct mwifiex_ds_encrypt_key *encrypt_key)
  890. {
  891. int ret;
  892. struct mwifiex_wep_key *wep_key;
  893. int index;
  894. if (priv->wep_key_curr_index >= NUM_WEP_KEYS)
  895. priv->wep_key_curr_index = 0;
  896. wep_key = &priv->wep_key[priv->wep_key_curr_index];
  897. index = encrypt_key->key_index;
  898. if (encrypt_key->key_disable) {
  899. priv->sec_info.wep_status = MWIFIEX_802_11_WEP_DISABLED;
  900. } else if (!encrypt_key->key_len) {
  901. /* Copy the required key as the current key */
  902. wep_key = &priv->wep_key[index];
  903. if (!wep_key->key_length) {
  904. dev_err(priv->adapter->dev,
  905. "key not set, so cannot enable it\n");
  906. return -1;
  907. }
  908. priv->wep_key_curr_index = (u16) index;
  909. priv->sec_info.wep_status = MWIFIEX_802_11_WEP_ENABLED;
  910. } else {
  911. wep_key = &priv->wep_key[index];
  912. memset(wep_key, 0, sizeof(struct mwifiex_wep_key));
  913. /* Copy the key in the driver */
  914. memcpy(wep_key->key_material,
  915. encrypt_key->key_material,
  916. encrypt_key->key_len);
  917. wep_key->key_index = index;
  918. wep_key->key_length = encrypt_key->key_len;
  919. priv->sec_info.wep_status = MWIFIEX_802_11_WEP_ENABLED;
  920. }
  921. if (wep_key->key_length) {
  922. /* Send request to firmware */
  923. ret = mwifiex_send_cmd_async(priv,
  924. HostCmd_CMD_802_11_KEY_MATERIAL,
  925. HostCmd_ACT_GEN_SET, 0, NULL);
  926. if (ret)
  927. return ret;
  928. }
  929. if (priv->sec_info.wep_status == MWIFIEX_802_11_WEP_ENABLED)
  930. priv->curr_pkt_filter |= HostCmd_ACT_MAC_WEP_ENABLE;
  931. else
  932. priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_WEP_ENABLE;
  933. ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_MAC_CONTROL,
  934. HostCmd_ACT_GEN_SET, 0,
  935. &priv->curr_pkt_filter);
  936. return ret;
  937. }
  938. /*
  939. * IOCTL request handler to set WPA key.
  940. *
  941. * This function prepares the correct firmware command and
  942. * issues it, after validation checks.
  943. *
  944. * Current driver only supports key length of up to 32 bytes.
  945. *
  946. * This function can also be used to disable a currently set key.
  947. */
  948. static int mwifiex_sec_ioctl_set_wpa_key(struct mwifiex_private *priv,
  949. struct mwifiex_ds_encrypt_key *encrypt_key)
  950. {
  951. int ret;
  952. u8 remove_key = false;
  953. struct host_cmd_ds_802_11_key_material *ibss_key;
  954. /* Current driver only supports key length of up to 32 bytes */
  955. if (encrypt_key->key_len > WLAN_MAX_KEY_LEN) {
  956. dev_err(priv->adapter->dev, "key length too long\n");
  957. return -1;
  958. }
  959. if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
  960. /*
  961. * IBSS/WPA-None uses only one key (Group) for both receiving
  962. * and sending unicast and multicast packets.
  963. */
  964. /* Send the key as PTK to firmware */
  965. encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
  966. ret = mwifiex_send_cmd_async(priv,
  967. HostCmd_CMD_802_11_KEY_MATERIAL,
  968. HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
  969. encrypt_key);
  970. if (ret)
  971. return ret;
  972. ibss_key = &priv->aes_key;
  973. memset(ibss_key, 0,
  974. sizeof(struct host_cmd_ds_802_11_key_material));
  975. /* Copy the key in the driver */
  976. memcpy(ibss_key->key_param_set.key, encrypt_key->key_material,
  977. encrypt_key->key_len);
  978. memcpy(&ibss_key->key_param_set.key_len, &encrypt_key->key_len,
  979. sizeof(ibss_key->key_param_set.key_len));
  980. ibss_key->key_param_set.key_type_id
  981. = cpu_to_le16(KEY_TYPE_ID_TKIP);
  982. ibss_key->key_param_set.key_info = cpu_to_le16(KEY_ENABLED);
  983. /* Send the key as GTK to firmware */
  984. encrypt_key->key_index = ~MWIFIEX_KEY_INDEX_UNICAST;
  985. }
  986. if (!encrypt_key->key_index)
  987. encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
  988. if (remove_key)
  989. ret = mwifiex_send_cmd_sync(priv,
  990. HostCmd_CMD_802_11_KEY_MATERIAL,
  991. HostCmd_ACT_GEN_SET, !(KEY_INFO_ENABLED),
  992. encrypt_key);
  993. else
  994. ret = mwifiex_send_cmd_sync(priv,
  995. HostCmd_CMD_802_11_KEY_MATERIAL,
  996. HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
  997. encrypt_key);
  998. return ret;
  999. }
  1000. /*
  1001. * IOCTL request handler to set/get network keys.
  1002. *
  1003. * This is a generic key handling function which supports WEP, WPA
  1004. * and WAPI.
  1005. */
  1006. static int
  1007. mwifiex_sec_ioctl_encrypt_key(struct mwifiex_private *priv,
  1008. struct mwifiex_ds_encrypt_key *encrypt_key)
  1009. {
  1010. int status;
  1011. if (encrypt_key->is_wapi_key)
  1012. status = mwifiex_sec_ioctl_set_wapi_key(priv, encrypt_key);
  1013. else if (encrypt_key->key_len > WLAN_KEY_LEN_WEP104)
  1014. status = mwifiex_sec_ioctl_set_wpa_key(priv, encrypt_key);
  1015. else
  1016. status = mwifiex_sec_ioctl_set_wep_key(priv, encrypt_key);
  1017. return status;
  1018. }
  1019. /*
  1020. * This function returns the driver version.
  1021. */
  1022. int
  1023. mwifiex_drv_get_driver_version(struct mwifiex_adapter *adapter, char *version,
  1024. int max_len)
  1025. {
  1026. union {
  1027. u32 l;
  1028. u8 c[4];
  1029. } ver;
  1030. char fw_ver[32];
  1031. ver.l = adapter->fw_release_number;
  1032. sprintf(fw_ver, "%u.%u.%u.p%u", ver.c[2], ver.c[1], ver.c[0], ver.c[3]);
  1033. snprintf(version, max_len, driver_version, fw_ver);
  1034. dev_dbg(adapter->dev, "info: MWIFIEX VERSION: %s\n", version);
  1035. return 0;
  1036. }
  1037. /*
  1038. * Sends IOCTL request to get signal information.
  1039. *
  1040. * This function allocates the IOCTL request buffer, fills it
  1041. * with requisite parameters and calls the IOCTL handler.
  1042. */
  1043. int mwifiex_get_signal_info(struct mwifiex_private *priv,
  1044. struct mwifiex_ds_get_signal *signal)
  1045. {
  1046. int status;
  1047. signal->selector = ALL_RSSI_INFO_MASK;
  1048. /* Signal info can be obtained only if connected */
  1049. if (!priv->media_connected) {
  1050. dev_dbg(priv->adapter->dev,
  1051. "info: Can not get signal in disconnected state\n");
  1052. return -1;
  1053. }
  1054. status = mwifiex_send_cmd_sync(priv, HostCmd_CMD_RSSI_INFO,
  1055. HostCmd_ACT_GEN_GET, 0, signal);
  1056. if (!status) {
  1057. if (signal->selector & BCN_RSSI_AVG_MASK)
  1058. priv->qual_level = signal->bcn_rssi_avg;
  1059. if (signal->selector & BCN_NF_AVG_MASK)
  1060. priv->qual_noise = signal->bcn_nf_avg;
  1061. }
  1062. return status;
  1063. }
  1064. /*
  1065. * Sends IOCTL request to set encoding parameters.
  1066. *
  1067. * This function allocates the IOCTL request buffer, fills it
  1068. * with requisite parameters and calls the IOCTL handler.
  1069. */
  1070. int mwifiex_set_encode(struct mwifiex_private *priv, const u8 *key,
  1071. int key_len, u8 key_index, int disable)
  1072. {
  1073. struct mwifiex_ds_encrypt_key encrypt_key;
  1074. memset(&encrypt_key, 0, sizeof(struct mwifiex_ds_encrypt_key));
  1075. encrypt_key.key_len = key_len;
  1076. if (!disable) {
  1077. encrypt_key.key_index = key_index;
  1078. if (key_len)
  1079. memcpy(encrypt_key.key_material, key, key_len);
  1080. } else {
  1081. encrypt_key.key_disable = true;
  1082. }
  1083. return mwifiex_sec_ioctl_encrypt_key(priv, &encrypt_key);
  1084. }
  1085. /*
  1086. * Sends IOCTL request to get extended version.
  1087. *
  1088. * This function allocates the IOCTL request buffer, fills it
  1089. * with requisite parameters and calls the IOCTL handler.
  1090. */
  1091. int
  1092. mwifiex_get_ver_ext(struct mwifiex_private *priv)
  1093. {
  1094. struct mwifiex_ver_ext ver_ext;
  1095. memset(&ver_ext, 0, sizeof(struct host_cmd_ds_version_ext));
  1096. if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_VERSION_EXT,
  1097. HostCmd_ACT_GEN_GET, 0, &ver_ext))
  1098. return -1;
  1099. return 0;
  1100. }
  1101. /*
  1102. * Sends IOCTL request to get statistics information.
  1103. *
  1104. * This function allocates the IOCTL request buffer, fills it
  1105. * with requisite parameters and calls the IOCTL handler.
  1106. */
  1107. int
  1108. mwifiex_get_stats_info(struct mwifiex_private *priv,
  1109. struct mwifiex_ds_get_stats *log)
  1110. {
  1111. return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_GET_LOG,
  1112. HostCmd_ACT_GEN_GET, 0, log);
  1113. }
  1114. /*
  1115. * IOCTL request handler to read/write register.
  1116. *
  1117. * This function prepares the correct firmware command and
  1118. * issues it.
  1119. *
  1120. * Access to the following registers are supported -
  1121. * - MAC
  1122. * - BBP
  1123. * - RF
  1124. * - PMIC
  1125. * - CAU
  1126. */
  1127. static int mwifiex_reg_mem_ioctl_reg_rw(struct mwifiex_private *priv,
  1128. struct mwifiex_ds_reg_rw *reg_rw,
  1129. u16 action)
  1130. {
  1131. u16 cmd_no;
  1132. switch (le32_to_cpu(reg_rw->type)) {
  1133. case MWIFIEX_REG_MAC:
  1134. cmd_no = HostCmd_CMD_MAC_REG_ACCESS;
  1135. break;
  1136. case MWIFIEX_REG_BBP:
  1137. cmd_no = HostCmd_CMD_BBP_REG_ACCESS;
  1138. break;
  1139. case MWIFIEX_REG_RF:
  1140. cmd_no = HostCmd_CMD_RF_REG_ACCESS;
  1141. break;
  1142. case MWIFIEX_REG_PMIC:
  1143. cmd_no = HostCmd_CMD_PMIC_REG_ACCESS;
  1144. break;
  1145. case MWIFIEX_REG_CAU:
  1146. cmd_no = HostCmd_CMD_CAU_REG_ACCESS;
  1147. break;
  1148. default:
  1149. return -1;
  1150. }
  1151. return mwifiex_send_cmd_sync(priv, cmd_no, action, 0, reg_rw);
  1152. }
  1153. /*
  1154. * Sends IOCTL request to write to a register.
  1155. *
  1156. * This function allocates the IOCTL request buffer, fills it
  1157. * with requisite parameters and calls the IOCTL handler.
  1158. */
  1159. int
  1160. mwifiex_reg_write(struct mwifiex_private *priv, u32 reg_type,
  1161. u32 reg_offset, u32 reg_value)
  1162. {
  1163. struct mwifiex_ds_reg_rw reg_rw;
  1164. reg_rw.type = cpu_to_le32(reg_type);
  1165. reg_rw.offset = cpu_to_le32(reg_offset);
  1166. reg_rw.value = cpu_to_le32(reg_value);
  1167. return mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_SET);
  1168. }
  1169. /*
  1170. * Sends IOCTL request to read from a register.
  1171. *
  1172. * This function allocates the IOCTL request buffer, fills it
  1173. * with requisite parameters and calls the IOCTL handler.
  1174. */
  1175. int
  1176. mwifiex_reg_read(struct mwifiex_private *priv, u32 reg_type,
  1177. u32 reg_offset, u32 *value)
  1178. {
  1179. int ret;
  1180. struct mwifiex_ds_reg_rw reg_rw;
  1181. reg_rw.type = cpu_to_le32(reg_type);
  1182. reg_rw.offset = cpu_to_le32(reg_offset);
  1183. ret = mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_GET);
  1184. if (ret)
  1185. goto done;
  1186. *value = le32_to_cpu(reg_rw.value);
  1187. done:
  1188. return ret;
  1189. }
  1190. /*
  1191. * Sends IOCTL request to read from EEPROM.
  1192. *
  1193. * This function allocates the IOCTL request buffer, fills it
  1194. * with requisite parameters and calls the IOCTL handler.
  1195. */
  1196. int
  1197. mwifiex_eeprom_read(struct mwifiex_private *priv, u16 offset, u16 bytes,
  1198. u8 *value)
  1199. {
  1200. int ret;
  1201. struct mwifiex_ds_read_eeprom rd_eeprom;
  1202. rd_eeprom.offset = cpu_to_le16((u16) offset);
  1203. rd_eeprom.byte_count = cpu_to_le16((u16) bytes);
  1204. /* Send request to firmware */
  1205. ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_EEPROM_ACCESS,
  1206. HostCmd_ACT_GEN_GET, 0, &rd_eeprom);
  1207. if (!ret)
  1208. memcpy(value, rd_eeprom.value, MAX_EEPROM_DATA);
  1209. return ret;
  1210. }
  1211. /*
  1212. * This function sets a generic IE. In addition to generic IE, it can
  1213. * also handle WPA, WPA2 and WAPI IEs.
  1214. */
  1215. static int
  1216. mwifiex_set_gen_ie_helper(struct mwifiex_private *priv, u8 *ie_data_ptr,
  1217. u16 ie_len)
  1218. {
  1219. int ret = 0;
  1220. struct ieee_types_vendor_header *pvendor_ie;
  1221. const u8 wpa_oui[] = { 0x00, 0x50, 0xf2, 0x01 };
  1222. const u8 wps_oui[] = { 0x00, 0x50, 0xf2, 0x04 };
  1223. /* If the passed length is zero, reset the buffer */
  1224. if (!ie_len) {
  1225. priv->gen_ie_buf_len = 0;
  1226. priv->wps.session_enable = false;
  1227. return 0;
  1228. } else if (!ie_data_ptr) {
  1229. return -1;
  1230. }
  1231. pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
  1232. /* Test to see if it is a WPA IE, if not, then it is a gen IE */
  1233. if (((pvendor_ie->element_id == WLAN_EID_WPA)
  1234. && (!memcmp(pvendor_ie->oui, wpa_oui, sizeof(wpa_oui))))
  1235. || (pvendor_ie->element_id == WLAN_EID_RSN)) {
  1236. /* IE is a WPA/WPA2 IE so call set_wpa function */
  1237. ret = mwifiex_set_wpa_ie_helper(priv, ie_data_ptr, ie_len);
  1238. priv->wps.session_enable = false;
  1239. return ret;
  1240. } else if (pvendor_ie->element_id == WLAN_EID_BSS_AC_ACCESS_DELAY) {
  1241. /* IE is a WAPI IE so call set_wapi function */
  1242. ret = mwifiex_set_wapi_ie(priv, ie_data_ptr, ie_len);
  1243. return ret;
  1244. }
  1245. /*
  1246. * Verify that the passed length is not larger than the
  1247. * available space remaining in the buffer
  1248. */
  1249. if (ie_len < (sizeof(priv->gen_ie_buf) - priv->gen_ie_buf_len)) {
  1250. /* Test to see if it is a WPS IE, if so, enable
  1251. * wps session flag
  1252. */
  1253. pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
  1254. if ((pvendor_ie->element_id == WLAN_EID_VENDOR_SPECIFIC)
  1255. && (!memcmp(pvendor_ie->oui, wps_oui,
  1256. sizeof(wps_oui)))) {
  1257. priv->wps.session_enable = true;
  1258. dev_dbg(priv->adapter->dev,
  1259. "info: WPS Session Enabled.\n");
  1260. }
  1261. /* Append the passed data to the end of the
  1262. genIeBuffer */
  1263. memcpy(priv->gen_ie_buf + priv->gen_ie_buf_len, ie_data_ptr,
  1264. ie_len);
  1265. /* Increment the stored buffer length by the
  1266. size passed */
  1267. priv->gen_ie_buf_len += ie_len;
  1268. } else {
  1269. /* Passed data does not fit in the remaining
  1270. buffer space */
  1271. ret = -1;
  1272. }
  1273. /* Return 0, or -1 for error case */
  1274. return ret;
  1275. }
  1276. /*
  1277. * IOCTL request handler to set/get generic IE.
  1278. *
  1279. * In addition to various generic IEs, this function can also be
  1280. * used to set the ARP filter.
  1281. */
  1282. static int mwifiex_misc_ioctl_gen_ie(struct mwifiex_private *priv,
  1283. struct mwifiex_ds_misc_gen_ie *gen_ie,
  1284. u16 action)
  1285. {
  1286. struct mwifiex_adapter *adapter = priv->adapter;
  1287. switch (gen_ie->type) {
  1288. case MWIFIEX_IE_TYPE_GEN_IE:
  1289. if (action == HostCmd_ACT_GEN_GET) {
  1290. gen_ie->len = priv->wpa_ie_len;
  1291. memcpy(gen_ie->ie_data, priv->wpa_ie, gen_ie->len);
  1292. } else {
  1293. mwifiex_set_gen_ie_helper(priv, gen_ie->ie_data,
  1294. (u16) gen_ie->len);
  1295. }
  1296. break;
  1297. case MWIFIEX_IE_TYPE_ARP_FILTER:
  1298. memset(adapter->arp_filter, 0, sizeof(adapter->arp_filter));
  1299. if (gen_ie->len > ARP_FILTER_MAX_BUF_SIZE) {
  1300. adapter->arp_filter_size = 0;
  1301. dev_err(adapter->dev, "invalid ARP filter size\n");
  1302. return -1;
  1303. } else {
  1304. memcpy(adapter->arp_filter, gen_ie->ie_data,
  1305. gen_ie->len);
  1306. adapter->arp_filter_size = gen_ie->len;
  1307. }
  1308. break;
  1309. default:
  1310. dev_err(adapter->dev, "invalid IE type\n");
  1311. return -1;
  1312. }
  1313. return 0;
  1314. }
  1315. /*
  1316. * Sends IOCTL request to set a generic IE.
  1317. *
  1318. * This function allocates the IOCTL request buffer, fills it
  1319. * with requisite parameters and calls the IOCTL handler.
  1320. */
  1321. int
  1322. mwifiex_set_gen_ie(struct mwifiex_private *priv, u8 *ie, int ie_len)
  1323. {
  1324. struct mwifiex_ds_misc_gen_ie gen_ie;
  1325. if (ie_len > IEEE_MAX_IE_SIZE)
  1326. return -EFAULT;
  1327. gen_ie.type = MWIFIEX_IE_TYPE_GEN_IE;
  1328. gen_ie.len = ie_len;
  1329. memcpy(gen_ie.ie_data, ie, ie_len);
  1330. if (mwifiex_misc_ioctl_gen_ie(priv, &gen_ie, HostCmd_ACT_GEN_SET))
  1331. return -EFAULT;
  1332. return 0;
  1333. }