sta_ioctl.c 44 KB

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