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