sta_ioctl.c 40 KB

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