sta_ioctl.c 37 KB

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