sta_ioctl.c 41 KB

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