sta_ioctl.c 40 KB

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