sta_ioctl.c 43 KB

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