sta_ioctl.c 41 KB

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