sta_ioctl.c 41 KB

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