sta_ioctl.c 43 KB

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