sta_ioctl.c 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360
  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. static int
  35. mwifiex_copy_mcast_addr(struct mwifiex_multicast_list *mlist,
  36. struct net_device *dev)
  37. {
  38. int i = 0;
  39. struct netdev_hw_addr *ha;
  40. netdev_for_each_mc_addr(ha, dev)
  41. memcpy(&mlist->mac_list[i++], ha->addr, ETH_ALEN);
  42. return i;
  43. }
  44. /*
  45. * Allocate and fills a wait queue with proper parameters.
  46. *
  47. * This function needs to be called before an IOCTL request can be made.
  48. * It can handle the following wait options:
  49. * MWIFIEX_NO_WAIT - Waiting is disabled
  50. * MWIFIEX_IOCTL_WAIT - Waiting is done on IOCTL wait queue
  51. * MWIFIEX_CMD_WAIT - Waiting is done on command wait queue
  52. * MWIFIEX_WSTATS_WAIT - Waiting is done on stats wait queue
  53. */
  54. struct mwifiex_wait_queue *
  55. mwifiex_alloc_fill_wait_queue(struct mwifiex_private *priv,
  56. u8 wait_option)
  57. {
  58. struct mwifiex_wait_queue *wait = NULL;
  59. wait = (struct mwifiex_wait_queue *)
  60. kzalloc(sizeof(struct mwifiex_wait_queue), GFP_ATOMIC);
  61. if (!wait) {
  62. dev_err(priv->adapter->dev, "%s: fail to alloc buffer\n",
  63. __func__);
  64. return wait;
  65. }
  66. wait->bss_index = priv->bss_index;
  67. switch (wait_option) {
  68. case MWIFIEX_NO_WAIT:
  69. wait->enabled = 0;
  70. break;
  71. case MWIFIEX_IOCTL_WAIT:
  72. priv->ioctl_wait_q_woken = false;
  73. wait->start_time = jiffies;
  74. wait->wait = &priv->ioctl_wait_q;
  75. wait->condition = &priv->ioctl_wait_q_woken;
  76. wait->enabled = 1;
  77. break;
  78. case MWIFIEX_CMD_WAIT:
  79. priv->cmd_wait_q_woken = false;
  80. wait->start_time = jiffies;
  81. wait->wait = &priv->cmd_wait_q;
  82. wait->condition = &priv->cmd_wait_q_woken;
  83. wait->enabled = 1;
  84. break;
  85. case MWIFIEX_WSTATS_WAIT:
  86. priv->w_stats_wait_q_woken = false;
  87. wait->start_time = jiffies;
  88. wait->wait = &priv->w_stats_wait_q;
  89. wait->condition = &priv->w_stats_wait_q_woken;
  90. wait->enabled = 1;
  91. break;
  92. }
  93. return wait;
  94. }
  95. /*
  96. * Wait queue completion handler.
  97. *
  98. * This function waits on a particular wait queue.
  99. * For NO_WAIT option, it returns immediately. It also cancels the
  100. * pending IOCTL request after waking up, in case of errors.
  101. */
  102. static void
  103. mwifiex_wait_ioctl_complete(struct mwifiex_private *priv,
  104. struct mwifiex_wait_queue *wait,
  105. u8 wait_option)
  106. {
  107. bool cancel_flag = false;
  108. switch (wait_option) {
  109. case MWIFIEX_NO_WAIT:
  110. break;
  111. case MWIFIEX_IOCTL_WAIT:
  112. wait_event_interruptible(priv->ioctl_wait_q,
  113. priv->ioctl_wait_q_woken);
  114. if (!priv->ioctl_wait_q_woken)
  115. cancel_flag = true;
  116. break;
  117. case MWIFIEX_CMD_WAIT:
  118. wait_event_interruptible(priv->cmd_wait_q,
  119. priv->cmd_wait_q_woken);
  120. if (!priv->cmd_wait_q_woken)
  121. cancel_flag = true;
  122. break;
  123. case MWIFIEX_WSTATS_WAIT:
  124. wait_event_interruptible(priv->w_stats_wait_q,
  125. priv->w_stats_wait_q_woken);
  126. if (!priv->w_stats_wait_q_woken)
  127. cancel_flag = true;
  128. break;
  129. }
  130. if (cancel_flag) {
  131. mwifiex_cancel_pending_ioctl(priv->adapter, wait);
  132. dev_dbg(priv->adapter->dev, "cmd: IOCTL cancel: wait=%p, wait_option=%d\n",
  133. wait, wait_option);
  134. }
  135. return;
  136. }
  137. /*
  138. * The function waits for the request to complete and issues the
  139. * completion handler, if required.
  140. */
  141. int mwifiex_request_ioctl(struct mwifiex_private *priv,
  142. struct mwifiex_wait_queue *wait,
  143. int status, u8 wait_option)
  144. {
  145. switch (status) {
  146. case -EINPROGRESS:
  147. dev_dbg(priv->adapter->dev, "cmd: IOCTL pending: wait=%p, wait_option=%d\n",
  148. wait, wait_option);
  149. atomic_inc(&priv->adapter->ioctl_pending);
  150. /* Status pending, wake up main process */
  151. queue_work(priv->adapter->workqueue, &priv->adapter->main_work);
  152. /* Wait for completion */
  153. if (wait_option) {
  154. mwifiex_wait_ioctl_complete(priv, wait, wait_option);
  155. status = wait->status;
  156. }
  157. break;
  158. case 0:
  159. case -1:
  160. case -EBUSY:
  161. default:
  162. break;
  163. }
  164. return status;
  165. }
  166. EXPORT_SYMBOL_GPL(mwifiex_request_ioctl);
  167. /*
  168. * IOCTL request handler to set/get MAC address.
  169. *
  170. * This function prepares the correct firmware command and
  171. * issues it to get the extended version information.
  172. */
  173. static int mwifiex_bss_ioctl_mac_address(struct mwifiex_private *priv,
  174. struct mwifiex_wait_queue *wait,
  175. u8 action, u8 *mac)
  176. {
  177. int ret = 0;
  178. if ((action == HostCmd_ACT_GEN_GET) && mac) {
  179. memcpy(mac, priv->curr_addr, ETH_ALEN);
  180. return 0;
  181. }
  182. /* Send request to firmware */
  183. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_802_11_MAC_ADDRESS,
  184. action, 0, wait, mac);
  185. if (!ret)
  186. ret = -EINPROGRESS;
  187. return ret;
  188. }
  189. /*
  190. * Sends IOCTL request to set MAC address.
  191. *
  192. * This function allocates the IOCTL request buffer, fills it
  193. * with requisite parameters and calls the IOCTL handler.
  194. */
  195. int mwifiex_request_set_mac_address(struct mwifiex_private *priv)
  196. {
  197. struct mwifiex_wait_queue *wait = NULL;
  198. int status = 0;
  199. u8 wait_option = MWIFIEX_CMD_WAIT;
  200. /* Allocate wait buffer */
  201. wait = mwifiex_alloc_fill_wait_queue(priv, wait_option);
  202. if (!wait)
  203. return -ENOMEM;
  204. status = mwifiex_bss_ioctl_mac_address(priv, wait, HostCmd_ACT_GEN_SET,
  205. NULL);
  206. status = mwifiex_request_ioctl(priv, wait, status, wait_option);
  207. if (!status)
  208. memcpy(priv->netdev->dev_addr, priv->curr_addr, ETH_ALEN);
  209. else
  210. dev_err(priv->adapter->dev, "set mac address failed: status=%d"
  211. " error_code=%#x\n", status, wait->status);
  212. kfree(wait);
  213. return status;
  214. }
  215. /*
  216. * IOCTL request handler to set multicast list.
  217. *
  218. * This function prepares the correct firmware command and
  219. * issues it to set the multicast list.
  220. *
  221. * This function can be used to enable promiscuous mode, or enable all
  222. * multicast packets, or to enable selective multicast.
  223. */
  224. static int
  225. mwifiex_bss_ioctl_multicast_list(struct mwifiex_private *priv,
  226. struct mwifiex_wait_queue *wait,
  227. u16 action,
  228. struct mwifiex_multicast_list *mcast_list)
  229. {
  230. int ret = 0;
  231. u16 old_pkt_filter;
  232. old_pkt_filter = priv->curr_pkt_filter;
  233. if (action == HostCmd_ACT_GEN_GET)
  234. return -1;
  235. if (mcast_list->mode == MWIFIEX_PROMISC_MODE) {
  236. dev_dbg(priv->adapter->dev, "info: Enable Promiscuous mode\n");
  237. priv->curr_pkt_filter |= HostCmd_ACT_MAC_PROMISCUOUS_ENABLE;
  238. priv->curr_pkt_filter &=
  239. ~HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
  240. } else {
  241. /* Multicast */
  242. priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_PROMISCUOUS_ENABLE;
  243. if (mcast_list->mode == MWIFIEX_MULTICAST_MODE) {
  244. dev_dbg(priv->adapter->dev,
  245. "info: Enabling All Multicast!\n");
  246. priv->curr_pkt_filter |=
  247. HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
  248. } else {
  249. priv->curr_pkt_filter &=
  250. ~HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
  251. if (mcast_list->num_multicast_addr) {
  252. dev_dbg(priv->adapter->dev,
  253. "info: Set multicast list=%d\n",
  254. mcast_list->num_multicast_addr);
  255. /* Set multicast addresses to firmware */
  256. if (old_pkt_filter == priv->curr_pkt_filter) {
  257. /* Send request to firmware */
  258. ret = mwifiex_prepare_cmd(priv,
  259. HostCmd_CMD_MAC_MULTICAST_ADR,
  260. action, 0, wait, mcast_list);
  261. if (!ret)
  262. ret = -EINPROGRESS;
  263. } else {
  264. /* Send request to firmware */
  265. ret = mwifiex_prepare_cmd(priv,
  266. HostCmd_CMD_MAC_MULTICAST_ADR,
  267. action, 0, NULL,
  268. mcast_list);
  269. }
  270. }
  271. }
  272. }
  273. dev_dbg(priv->adapter->dev,
  274. "info: old_pkt_filter=%#x, curr_pkt_filter=%#x\n",
  275. old_pkt_filter, priv->curr_pkt_filter);
  276. if (old_pkt_filter != priv->curr_pkt_filter) {
  277. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_MAC_CONTROL, action,
  278. 0, wait, &priv->curr_pkt_filter);
  279. if (!ret)
  280. ret = -EINPROGRESS;
  281. }
  282. return ret;
  283. }
  284. /*
  285. * Sends IOCTL request to set multicast list.
  286. *
  287. * This function allocates the IOCTL request buffer, fills it
  288. * with requisite parameters and calls the IOCTL handler.
  289. */
  290. void
  291. mwifiex_request_set_multicast_list(struct mwifiex_private *priv,
  292. struct net_device *dev)
  293. {
  294. struct mwifiex_wait_queue *wait = NULL;
  295. struct mwifiex_multicast_list mcast_list;
  296. u8 wait_option = MWIFIEX_NO_WAIT;
  297. int status = 0;
  298. /* Allocate wait buffer */
  299. wait = mwifiex_alloc_fill_wait_queue(priv, wait_option);
  300. if (!wait)
  301. return;
  302. if (dev->flags & IFF_PROMISC) {
  303. mcast_list.mode = MWIFIEX_PROMISC_MODE;
  304. } else if (dev->flags & IFF_ALLMULTI ||
  305. netdev_mc_count(dev) > MWIFIEX_MAX_MULTICAST_LIST_SIZE) {
  306. mcast_list.mode = MWIFIEX_ALL_MULTI_MODE;
  307. } else {
  308. mcast_list.mode = MWIFIEX_MULTICAST_MODE;
  309. if (netdev_mc_count(dev))
  310. mcast_list.num_multicast_addr =
  311. mwifiex_copy_mcast_addr(&mcast_list, dev);
  312. }
  313. status = mwifiex_bss_ioctl_multicast_list(priv, wait,
  314. HostCmd_ACT_GEN_SET,
  315. &mcast_list);
  316. status = mwifiex_request_ioctl(priv, wait, status, wait_option);
  317. if (wait && status != -EINPROGRESS)
  318. kfree(wait);
  319. return;
  320. }
  321. /*
  322. * IOCTL request handler to disconnect from a BSS/IBSS.
  323. */
  324. static int mwifiex_bss_ioctl_stop(struct mwifiex_private *priv,
  325. struct mwifiex_wait_queue *wait, u8 *mac)
  326. {
  327. return mwifiex_deauthenticate(priv, wait, mac);
  328. }
  329. /*
  330. * Sends IOCTL request to disconnect from a BSS.
  331. *
  332. * This function allocates the IOCTL request buffer, fills it
  333. * with requisite parameters and calls the IOCTL handler.
  334. */
  335. int mwifiex_disconnect(struct mwifiex_private *priv, u8 wait_option, u8 *mac)
  336. {
  337. struct mwifiex_wait_queue *wait = NULL;
  338. int status = 0;
  339. /* Allocate wait buffer */
  340. wait = mwifiex_alloc_fill_wait_queue(priv, wait_option);
  341. if (!wait)
  342. return -ENOMEM;
  343. status = mwifiex_bss_ioctl_stop(priv, wait, mac);
  344. status = mwifiex_request_ioctl(priv, wait, status, wait_option);
  345. kfree(wait);
  346. return status;
  347. }
  348. EXPORT_SYMBOL_GPL(mwifiex_disconnect);
  349. /*
  350. * IOCTL request handler to join a BSS/IBSS.
  351. *
  352. * In Ad-Hoc mode, the IBSS is created if not found in scan list.
  353. * In both Ad-Hoc and infra mode, an deauthentication is performed
  354. * first.
  355. */
  356. static int mwifiex_bss_ioctl_start(struct mwifiex_private *priv,
  357. struct mwifiex_wait_queue *wait,
  358. struct mwifiex_ssid_bssid *ssid_bssid)
  359. {
  360. int ret = 0;
  361. struct mwifiex_adapter *adapter = priv->adapter;
  362. s32 i = -1;
  363. priv->scan_block = false;
  364. if (!ssid_bssid)
  365. return -1;
  366. if (priv->bss_mode == NL80211_IFTYPE_STATION) {
  367. /* Infra mode */
  368. ret = mwifiex_deauthenticate(priv, NULL, NULL);
  369. if (ret)
  370. return ret;
  371. /* Search for the requested SSID in the scan table */
  372. if (ssid_bssid->ssid.ssid_len)
  373. i = mwifiex_find_ssid_in_list(priv, &ssid_bssid->ssid,
  374. NULL, NL80211_IFTYPE_STATION);
  375. else
  376. i = mwifiex_find_bssid_in_list(priv,
  377. (u8 *) &ssid_bssid->bssid,
  378. NL80211_IFTYPE_STATION);
  379. if (i < 0)
  380. return -1;
  381. dev_dbg(adapter->dev,
  382. "info: SSID found in scan list ... associating...\n");
  383. /* Clear any past association response stored for
  384. * application retrieval */
  385. priv->assoc_rsp_size = 0;
  386. ret = mwifiex_associate(priv, wait, &adapter->scan_table[i]);
  387. if (ret)
  388. return ret;
  389. } else {
  390. /* Adhoc mode */
  391. /* If the requested SSID matches current SSID, return */
  392. if (ssid_bssid->ssid.ssid_len &&
  393. (!mwifiex_ssid_cmp
  394. (&priv->curr_bss_params.bss_descriptor.ssid,
  395. &ssid_bssid->ssid)))
  396. return 0;
  397. /* Exit Adhoc mode first */
  398. dev_dbg(adapter->dev, "info: Sending Adhoc Stop\n");
  399. ret = mwifiex_deauthenticate(priv, NULL, NULL);
  400. if (ret)
  401. return ret;
  402. priv->adhoc_is_link_sensed = false;
  403. /* Search for the requested network in the scan table */
  404. if (ssid_bssid->ssid.ssid_len)
  405. i = mwifiex_find_ssid_in_list(priv,
  406. &ssid_bssid->ssid, NULL,
  407. NL80211_IFTYPE_ADHOC);
  408. else
  409. i = mwifiex_find_bssid_in_list(priv,
  410. (u8 *)&ssid_bssid->bssid,
  411. NL80211_IFTYPE_ADHOC);
  412. if (i >= 0) {
  413. dev_dbg(adapter->dev, "info: network found in scan"
  414. " list. Joining...\n");
  415. ret = mwifiex_adhoc_join(priv, wait,
  416. &adapter->scan_table[i]);
  417. if (ret)
  418. return ret;
  419. } else { /* i >= 0 */
  420. dev_dbg(adapter->dev, "info: Network not found in "
  421. "the list, creating adhoc with ssid = %s\n",
  422. ssid_bssid->ssid.ssid);
  423. ret = mwifiex_adhoc_start(priv, wait,
  424. &ssid_bssid->ssid);
  425. if (ret)
  426. return ret;
  427. }
  428. }
  429. if (!ret)
  430. ret = -EINPROGRESS;
  431. return ret;
  432. }
  433. /*
  434. * Sends IOCTL request to connect with a BSS.
  435. *
  436. * This function allocates the IOCTL request buffer, fills it
  437. * with requisite parameters and calls the IOCTL handler.
  438. */
  439. int mwifiex_bss_start(struct mwifiex_private *priv, u8 wait_option,
  440. struct mwifiex_ssid_bssid *ssid_bssid)
  441. {
  442. struct mwifiex_wait_queue *wait = NULL;
  443. struct mwifiex_ssid_bssid tmp_ssid_bssid;
  444. int status = 0;
  445. /* Stop the O.S. TX queue if needed */
  446. if (!netif_queue_stopped(priv->netdev))
  447. netif_stop_queue(priv->netdev);
  448. /* Allocate wait buffer */
  449. wait = mwifiex_alloc_fill_wait_queue(priv, wait_option);
  450. if (!wait)
  451. return -ENOMEM;
  452. if (ssid_bssid)
  453. memcpy(&tmp_ssid_bssid, ssid_bssid,
  454. sizeof(struct mwifiex_ssid_bssid));
  455. status = mwifiex_bss_ioctl_start(priv, wait, &tmp_ssid_bssid);
  456. status = mwifiex_request_ioctl(priv, wait, status, wait_option);
  457. kfree(wait);
  458. return status;
  459. }
  460. /*
  461. * IOCTL request handler to set host sleep configuration.
  462. *
  463. * This function prepares the correct firmware command and
  464. * issues it.
  465. */
  466. static int
  467. mwifiex_pm_ioctl_hs_cfg(struct mwifiex_private *priv,
  468. struct mwifiex_wait_queue *wait,
  469. u16 action, struct mwifiex_ds_hs_cfg *hs_cfg)
  470. {
  471. struct mwifiex_adapter *adapter = priv->adapter;
  472. int status = 0;
  473. u32 prev_cond = 0;
  474. switch (action) {
  475. case HostCmd_ACT_GEN_SET:
  476. if (adapter->pps_uapsd_mode) {
  477. dev_dbg(adapter->dev, "info: Host Sleep IOCTL"
  478. " is blocked in UAPSD/PPS mode\n");
  479. status = -1;
  480. break;
  481. }
  482. if (hs_cfg->is_invoke_hostcmd) {
  483. if (hs_cfg->conditions == HOST_SLEEP_CFG_CANCEL) {
  484. if (!adapter->is_hs_configured)
  485. /* Already cancelled */
  486. break;
  487. /* Save previous condition */
  488. prev_cond = le32_to_cpu(adapter->hs_cfg
  489. .conditions);
  490. adapter->hs_cfg.conditions =
  491. cpu_to_le32(hs_cfg->conditions);
  492. } else if (hs_cfg->conditions) {
  493. adapter->hs_cfg.conditions =
  494. cpu_to_le32(hs_cfg->conditions);
  495. adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
  496. if (hs_cfg->gap)
  497. adapter->hs_cfg.gap = (u8)hs_cfg->gap;
  498. } else if (adapter->hs_cfg.conditions ==
  499. cpu_to_le32(
  500. HOST_SLEEP_CFG_CANCEL)) {
  501. /* Return failure if no parameters for HS
  502. enable */
  503. status = -1;
  504. break;
  505. }
  506. status = mwifiex_prepare_cmd(priv,
  507. HostCmd_CMD_802_11_HS_CFG_ENH,
  508. HostCmd_ACT_GEN_SET,
  509. 0, wait, &adapter->hs_cfg);
  510. if (!status)
  511. status = -EINPROGRESS;
  512. if (hs_cfg->conditions == HOST_SLEEP_CFG_CANCEL)
  513. /* Restore previous condition */
  514. adapter->hs_cfg.conditions =
  515. cpu_to_le32(prev_cond);
  516. } else {
  517. adapter->hs_cfg.conditions =
  518. cpu_to_le32(hs_cfg->conditions);
  519. adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
  520. adapter->hs_cfg.gap = (u8)hs_cfg->gap;
  521. }
  522. break;
  523. case HostCmd_ACT_GEN_GET:
  524. hs_cfg->conditions = le32_to_cpu(adapter->hs_cfg.conditions);
  525. hs_cfg->gpio = adapter->hs_cfg.gpio;
  526. hs_cfg->gap = adapter->hs_cfg.gap;
  527. break;
  528. default:
  529. status = -1;
  530. break;
  531. }
  532. return status;
  533. }
  534. /*
  535. * Sends IOCTL request to set Host Sleep parameters.
  536. *
  537. * This function allocates the IOCTL request buffer, fills it
  538. * with requisite parameters and calls the IOCTL handler.
  539. */
  540. int mwifiex_set_hs_params(struct mwifiex_private *priv, u16 action,
  541. u8 wait_option,
  542. struct mwifiex_ds_hs_cfg *hscfg)
  543. {
  544. int ret = 0;
  545. struct mwifiex_wait_queue *wait = NULL;
  546. if (!hscfg)
  547. return -ENOMEM;
  548. /* Allocate wait buffer */
  549. wait = mwifiex_alloc_fill_wait_queue(priv, wait_option);
  550. if (!wait)
  551. return -ENOMEM;
  552. ret = mwifiex_pm_ioctl_hs_cfg(priv, wait, action, hscfg);
  553. ret = mwifiex_request_ioctl(priv, wait, ret, wait_option);
  554. if (wait && (ret != -EINPROGRESS))
  555. kfree(wait);
  556. return ret;
  557. }
  558. /*
  559. * Sends IOCTL request to cancel the existing Host Sleep configuration.
  560. *
  561. * This function allocates the IOCTL request buffer, fills it
  562. * with requisite parameters and calls the IOCTL handler.
  563. */
  564. int mwifiex_cancel_hs(struct mwifiex_private *priv, u8 wait_option)
  565. {
  566. int ret = 0;
  567. struct mwifiex_ds_hs_cfg hscfg;
  568. /* Cancel Host Sleep */
  569. hscfg.conditions = HOST_SLEEP_CFG_CANCEL;
  570. hscfg.is_invoke_hostcmd = true;
  571. ret = mwifiex_set_hs_params(priv, HostCmd_ACT_GEN_SET,
  572. wait_option, &hscfg);
  573. return ret;
  574. }
  575. EXPORT_SYMBOL_GPL(mwifiex_cancel_hs);
  576. /*
  577. * Sends IOCTL request to cancel the existing Host Sleep configuration.
  578. *
  579. * This function allocates the IOCTL request buffer, fills it
  580. * with requisite parameters and calls the IOCTL handler.
  581. */
  582. int mwifiex_enable_hs(struct mwifiex_adapter *adapter)
  583. {
  584. struct mwifiex_ds_hs_cfg hscfg;
  585. if (adapter->hs_activated) {
  586. dev_dbg(adapter->dev, "cmd: HS Already actived\n");
  587. return true;
  588. }
  589. /* Enable Host Sleep */
  590. adapter->hs_activate_wait_q_woken = false;
  591. memset(&hscfg, 0, sizeof(struct mwifiex_hs_config_param));
  592. hscfg.is_invoke_hostcmd = true;
  593. if (mwifiex_set_hs_params(mwifiex_get_priv(adapter,
  594. MWIFIEX_BSS_ROLE_STA),
  595. HostCmd_ACT_GEN_SET,
  596. MWIFIEX_IOCTL_WAIT, &hscfg)) {
  597. dev_err(adapter->dev, "IOCTL request HS enable failed\n");
  598. return false;
  599. }
  600. wait_event_interruptible(adapter->hs_activate_wait_q,
  601. adapter->hs_activate_wait_q_woken);
  602. return true;
  603. }
  604. EXPORT_SYMBOL_GPL(mwifiex_enable_hs);
  605. /*
  606. * IOCTL request handler to get signal information.
  607. *
  608. * This function prepares the correct firmware command and
  609. * issues it to get the signal (RSSI) information.
  610. *
  611. * This only works in the connected mode.
  612. */
  613. static int mwifiex_get_info_signal(struct mwifiex_private *priv,
  614. struct mwifiex_wait_queue *wait,
  615. struct mwifiex_ds_get_signal *signal)
  616. {
  617. int ret = 0;
  618. if (!wait) {
  619. dev_err(priv->adapter->dev, "WAIT information is not present\n");
  620. return -1;
  621. }
  622. /* Signal info can be obtained only if connected */
  623. if (!priv->media_connected) {
  624. dev_dbg(priv->adapter->dev,
  625. "info: Can not get signal in disconnected state\n");
  626. return -1;
  627. }
  628. /* Send request to firmware */
  629. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_RSSI_INFO,
  630. HostCmd_ACT_GEN_GET, 0, wait, signal);
  631. if (!ret)
  632. ret = -EINPROGRESS;
  633. return ret;
  634. }
  635. /*
  636. * IOCTL request handler to get statistics.
  637. *
  638. * This function prepares the correct firmware command and
  639. * issues it to get the statistics (RSSI) information.
  640. */
  641. static int mwifiex_get_info_stats(struct mwifiex_private *priv,
  642. struct mwifiex_wait_queue *wait,
  643. struct mwifiex_ds_get_stats *log)
  644. {
  645. int ret = 0;
  646. if (!wait) {
  647. dev_err(priv->adapter->dev, "MWIFIEX IOCTL information is not present\n");
  648. return -1;
  649. }
  650. /* Send request to firmware */
  651. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_802_11_GET_LOG,
  652. HostCmd_ACT_GEN_GET, 0, wait, log);
  653. if (!ret)
  654. ret = -EINPROGRESS;
  655. return ret;
  656. }
  657. /*
  658. * IOCTL request handler to get BSS information.
  659. *
  660. * This function collates the information from different driver structures
  661. * to send to the user.
  662. */
  663. int mwifiex_get_bss_info(struct mwifiex_private *priv,
  664. struct mwifiex_bss_info *info)
  665. {
  666. struct mwifiex_adapter *adapter = priv->adapter;
  667. struct mwifiex_bssdescriptor *bss_desc;
  668. s32 tbl_idx = 0;
  669. if (!info)
  670. return -1;
  671. /* Get current BSS info */
  672. bss_desc = &priv->curr_bss_params.bss_descriptor;
  673. /* BSS mode */
  674. info->bss_mode = priv->bss_mode;
  675. /* SSID */
  676. memcpy(&info->ssid, &bss_desc->ssid,
  677. sizeof(struct mwifiex_802_11_ssid));
  678. /* BSSID */
  679. memcpy(&info->bssid, &bss_desc->mac_address, ETH_ALEN);
  680. /* Channel */
  681. info->bss_chan = bss_desc->channel;
  682. /* Region code */
  683. info->region_code = adapter->region_code;
  684. /* Scan table index if connected */
  685. info->scan_table_idx = 0;
  686. if (priv->media_connected) {
  687. tbl_idx =
  688. mwifiex_find_ssid_in_list(priv, &bss_desc->ssid,
  689. bss_desc->mac_address,
  690. priv->bss_mode);
  691. if (tbl_idx >= 0)
  692. info->scan_table_idx = tbl_idx;
  693. }
  694. /* Connection status */
  695. info->media_connected = priv->media_connected;
  696. /* Tx power information */
  697. info->max_power_level = priv->max_tx_power_level;
  698. info->min_power_level = priv->min_tx_power_level;
  699. /* AdHoc state */
  700. info->adhoc_state = priv->adhoc_state;
  701. /* Last beacon NF */
  702. info->bcn_nf_last = priv->bcn_nf_last;
  703. /* wep status */
  704. if (priv->sec_info.wep_status == MWIFIEX_802_11_WEP_ENABLED)
  705. info->wep_status = true;
  706. else
  707. info->wep_status = false;
  708. info->is_hs_configured = adapter->is_hs_configured;
  709. info->is_deep_sleep = adapter->is_deep_sleep;
  710. return 0;
  711. }
  712. /*
  713. * IOCTL request handler to get extended version information.
  714. *
  715. * This function prepares the correct firmware command and
  716. * issues it to get the extended version information.
  717. */
  718. static int mwifiex_get_info_ver_ext(struct mwifiex_private *priv,
  719. struct mwifiex_wait_queue *wait,
  720. struct mwifiex_ver_ext *ver_ext)
  721. {
  722. int ret = 0;
  723. /* Send request to firmware */
  724. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_VERSION_EXT,
  725. HostCmd_ACT_GEN_GET, 0, wait, ver_ext);
  726. if (!ret)
  727. ret = -EINPROGRESS;
  728. return ret;
  729. }
  730. /*
  731. * IOCTL request handler to set/get SNMP MIB parameters.
  732. *
  733. * This function prepares the correct firmware command and
  734. * issues it.
  735. *
  736. * Currently the following parameters are supported -
  737. * Set/get RTS Threshold
  738. * Set/get fragmentation threshold
  739. * Set/get retry count
  740. */
  741. int mwifiex_snmp_mib_ioctl(struct mwifiex_private *priv,
  742. struct mwifiex_wait_queue *wait,
  743. u32 cmd_oid, u16 action, u32 *value)
  744. {
  745. int ret = 0;
  746. if (!value)
  747. return -1;
  748. /* Send request to firmware */
  749. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
  750. action, cmd_oid, wait, value);
  751. if (!ret)
  752. ret = -EINPROGRESS;
  753. return ret;
  754. }
  755. /*
  756. * IOCTL request handler to set/get band configurations.
  757. *
  758. * For SET operation, it performs extra checks to make sure the Ad-Hoc
  759. * band and channel are compatible. Otherwise it returns an error.
  760. *
  761. * For GET operation, this function retrieves the following information -
  762. * - Infra bands
  763. * - Ad-hoc band
  764. * - Ad-hoc channel
  765. * - Secondary channel offset
  766. */
  767. int mwifiex_radio_ioctl_band_cfg(struct mwifiex_private *priv,
  768. u16 action,
  769. struct mwifiex_ds_band_cfg *radio_cfg)
  770. {
  771. struct mwifiex_adapter *adapter = priv->adapter;
  772. u8 infra_band = 0;
  773. u8 adhoc_band = 0;
  774. u32 adhoc_channel = 0;
  775. if (action == HostCmd_ACT_GEN_GET) {
  776. /* Infra Bands */
  777. radio_cfg->config_bands = adapter->config_bands;
  778. /* Adhoc Band */
  779. radio_cfg->adhoc_start_band = adapter->adhoc_start_band;
  780. /* Adhoc channel */
  781. radio_cfg->adhoc_channel = priv->adhoc_channel;
  782. /* Secondary channel offset */
  783. radio_cfg->sec_chan_offset = adapter->chan_offset;
  784. return 0;
  785. }
  786. /* For action = SET */
  787. infra_band = (u8) radio_cfg->config_bands;
  788. adhoc_band = (u8) radio_cfg->adhoc_start_band;
  789. adhoc_channel = radio_cfg->adhoc_channel;
  790. /* SET Infra band */
  791. if ((infra_band | adapter->fw_bands) & ~adapter->fw_bands)
  792. return -1;
  793. adapter->config_bands = infra_band;
  794. /* SET Ad-hoc Band */
  795. if ((adhoc_band | adapter->fw_bands) & ~adapter->fw_bands)
  796. return -1;
  797. if (adhoc_band)
  798. adapter->adhoc_start_band = adhoc_band;
  799. adapter->chan_offset = (u8) radio_cfg->sec_chan_offset;
  800. /*
  801. * If no adhoc_channel is supplied verify if the existing adhoc
  802. * channel compiles with new adhoc_band
  803. */
  804. if (!adhoc_channel) {
  805. if (!mwifiex_get_cfp_by_band_and_channel_from_cfg80211
  806. (priv, adapter->adhoc_start_band,
  807. priv->adhoc_channel)) {
  808. /* Pass back the default channel */
  809. radio_cfg->adhoc_channel = DEFAULT_AD_HOC_CHANNEL;
  810. if ((adapter->adhoc_start_band & BAND_A)
  811. || (adapter->adhoc_start_band & BAND_AN))
  812. radio_cfg->adhoc_channel =
  813. DEFAULT_AD_HOC_CHANNEL_A;
  814. }
  815. } else { /* Retrurn error if adhoc_band and
  816. adhoc_channel combination is invalid */
  817. if (!mwifiex_get_cfp_by_band_and_channel_from_cfg80211
  818. (priv, adapter->adhoc_start_band, (u16) adhoc_channel))
  819. return -1;
  820. priv->adhoc_channel = (u8) adhoc_channel;
  821. }
  822. if ((adhoc_band & BAND_GN) || (adhoc_band & BAND_AN))
  823. adapter->adhoc_11n_enabled = true;
  824. else
  825. adapter->adhoc_11n_enabled = false;
  826. return 0;
  827. }
  828. /*
  829. * IOCTL request handler to set/get active channel.
  830. *
  831. * This function performs validity checking on channel/frequency
  832. * compatibility and returns failure if not valid.
  833. */
  834. int mwifiex_bss_ioctl_channel(struct mwifiex_private *priv, u16 action,
  835. struct mwifiex_chan_freq_power *chan)
  836. {
  837. struct mwifiex_adapter *adapter = priv->adapter;
  838. struct mwifiex_chan_freq_power *cfp = NULL;
  839. if (!chan)
  840. return -1;
  841. if (action == HostCmd_ACT_GEN_GET) {
  842. cfp = mwifiex_get_cfp_by_band_and_channel_from_cfg80211(priv,
  843. priv->curr_bss_params.band,
  844. (u16) priv->curr_bss_params.bss_descriptor.
  845. channel);
  846. chan->channel = cfp->channel;
  847. chan->freq = cfp->freq;
  848. return 0;
  849. }
  850. if (!chan->channel && !chan->freq)
  851. return -1;
  852. if (adapter->adhoc_start_band & BAND_AN)
  853. adapter->adhoc_start_band = BAND_G | BAND_B | BAND_GN;
  854. else if (adapter->adhoc_start_band & BAND_A)
  855. adapter->adhoc_start_band = BAND_G | BAND_B;
  856. if (chan->channel) {
  857. if (chan->channel <= MAX_CHANNEL_BAND_BG)
  858. cfp = mwifiex_get_cfp_by_band_and_channel_from_cfg80211
  859. (priv, 0, (u16) chan->channel);
  860. if (!cfp) {
  861. cfp = mwifiex_get_cfp_by_band_and_channel_from_cfg80211
  862. (priv, BAND_A, (u16) chan->channel);
  863. if (cfp) {
  864. if (adapter->adhoc_11n_enabled)
  865. adapter->adhoc_start_band = BAND_A
  866. | BAND_AN;
  867. else
  868. adapter->adhoc_start_band = BAND_A;
  869. }
  870. }
  871. } else {
  872. if (chan->freq <= MAX_FREQUENCY_BAND_BG)
  873. cfp = mwifiex_get_cfp_by_band_and_freq_from_cfg80211(
  874. priv, 0, chan->freq);
  875. if (!cfp) {
  876. cfp = mwifiex_get_cfp_by_band_and_freq_from_cfg80211
  877. (priv, BAND_A, chan->freq);
  878. if (cfp) {
  879. if (adapter->adhoc_11n_enabled)
  880. adapter->adhoc_start_band = BAND_A
  881. | BAND_AN;
  882. else
  883. adapter->adhoc_start_band = BAND_A;
  884. }
  885. }
  886. }
  887. if (!cfp || !cfp->channel) {
  888. dev_err(adapter->dev, "invalid channel/freq\n");
  889. return -1;
  890. }
  891. priv->adhoc_channel = (u8) cfp->channel;
  892. chan->channel = cfp->channel;
  893. chan->freq = cfp->freq;
  894. return 0;
  895. }
  896. /*
  897. * IOCTL request handler to set/get Ad-Hoc channel.
  898. *
  899. * This function prepares the correct firmware command and
  900. * issues it to set or get the ad-hoc channel.
  901. */
  902. static int mwifiex_bss_ioctl_ibss_channel(struct mwifiex_private *priv,
  903. struct mwifiex_wait_queue *wait,
  904. u16 action, u16 *channel)
  905. {
  906. int ret = 0;
  907. if (action == HostCmd_ACT_GEN_GET) {
  908. if (!priv->media_connected) {
  909. *channel = priv->adhoc_channel;
  910. return ret;
  911. }
  912. } else {
  913. priv->adhoc_channel = (u8) *channel;
  914. }
  915. /* Send request to firmware */
  916. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_802_11_RF_CHANNEL,
  917. action, 0, wait, channel);
  918. if (!ret)
  919. ret = -EINPROGRESS;
  920. return ret;
  921. }
  922. /*
  923. * IOCTL request handler to find a particular BSS.
  924. *
  925. * The BSS can be searched with either a BSSID or a SSID. If none of
  926. * these are provided, just the best BSS (best RSSI) is returned.
  927. */
  928. int mwifiex_bss_ioctl_find_bss(struct mwifiex_private *priv,
  929. struct mwifiex_wait_queue *wait,
  930. struct mwifiex_ssid_bssid *ssid_bssid)
  931. {
  932. struct mwifiex_adapter *adapter = priv->adapter;
  933. int ret = 0;
  934. struct mwifiex_bssdescriptor *bss_desc;
  935. u8 zero_mac[ETH_ALEN] = { 0, 0, 0, 0, 0, 0 };
  936. u8 mac[ETH_ALEN];
  937. int i = 0;
  938. if (memcmp(ssid_bssid->bssid, zero_mac, sizeof(zero_mac))) {
  939. i = mwifiex_find_bssid_in_list(priv,
  940. (u8 *) ssid_bssid->bssid,
  941. priv->bss_mode);
  942. if (i < 0) {
  943. memcpy(mac, ssid_bssid->bssid, sizeof(mac));
  944. dev_err(adapter->dev, "cannot find bssid %pM\n", mac);
  945. return -1;
  946. }
  947. bss_desc = &adapter->scan_table[i];
  948. memcpy(&ssid_bssid->ssid, &bss_desc->ssid,
  949. sizeof(struct mwifiex_802_11_ssid));
  950. } else if (ssid_bssid->ssid.ssid_len) {
  951. i = mwifiex_find_ssid_in_list(priv, &ssid_bssid->ssid, NULL,
  952. priv->bss_mode);
  953. if (i < 0) {
  954. dev_err(adapter->dev, "cannot find ssid %s\n",
  955. ssid_bssid->ssid.ssid);
  956. return -1;
  957. }
  958. bss_desc = &adapter->scan_table[i];
  959. memcpy(ssid_bssid->bssid, bss_desc->mac_address, ETH_ALEN);
  960. } else {
  961. ret = mwifiex_find_best_network(priv, ssid_bssid);
  962. }
  963. return ret;
  964. }
  965. /*
  966. * IOCTL request handler to change Ad-Hoc channel.
  967. *
  968. * This function allocates the IOCTL request buffer, fills it
  969. * with requisite parameters and calls the IOCTL handler.
  970. *
  971. * The function follows the following steps to perform the change -
  972. * - Get current IBSS information
  973. * - Get current channel
  974. * - If no change is required, return
  975. * - If not connected, change channel and return
  976. * - If connected,
  977. * - Disconnect
  978. * - Change channel
  979. * - Perform specific SSID scan with same SSID
  980. * - Start/Join the IBSS
  981. */
  982. int
  983. mwifiex_drv_change_adhoc_chan(struct mwifiex_private *priv, int channel)
  984. {
  985. int ret = 0;
  986. int status = 0;
  987. struct mwifiex_bss_info bss_info;
  988. struct mwifiex_wait_queue *wait = NULL;
  989. u8 wait_option = MWIFIEX_IOCTL_WAIT;
  990. struct mwifiex_ssid_bssid ssid_bssid;
  991. u16 curr_chan = 0;
  992. memset(&bss_info, 0, sizeof(bss_info));
  993. /* Get BSS information */
  994. if (mwifiex_get_bss_info(priv, &bss_info))
  995. return -1;
  996. /* Allocate wait buffer */
  997. wait = mwifiex_alloc_fill_wait_queue(priv, wait_option);
  998. if (!wait)
  999. return -ENOMEM;
  1000. /* Get current channel */
  1001. status = mwifiex_bss_ioctl_ibss_channel(priv, wait, HostCmd_ACT_GEN_GET,
  1002. &curr_chan);
  1003. if (mwifiex_request_ioctl(priv, wait, status, wait_option)) {
  1004. ret = -1;
  1005. goto done;
  1006. }
  1007. if (curr_chan == channel) {
  1008. ret = 0;
  1009. goto done;
  1010. }
  1011. dev_dbg(priv->adapter->dev, "cmd: updating channel from %d to %d\n",
  1012. curr_chan, channel);
  1013. if (!bss_info.media_connected) {
  1014. ret = 0;
  1015. goto done;
  1016. }
  1017. /* Do disonnect */
  1018. memset(&ssid_bssid, 0, ETH_ALEN);
  1019. status = mwifiex_bss_ioctl_stop(priv, wait, ssid_bssid.bssid);
  1020. if (mwifiex_request_ioctl(priv, wait, status, wait_option)) {
  1021. ret = -1;
  1022. goto done;
  1023. }
  1024. status = mwifiex_bss_ioctl_ibss_channel(priv, wait, HostCmd_ACT_GEN_SET,
  1025. (u16 *) &channel);
  1026. if (mwifiex_request_ioctl(priv, wait, status, wait_option)) {
  1027. ret = -1;
  1028. goto done;
  1029. }
  1030. /* Do specific SSID scanning */
  1031. if (mwifiex_request_scan(priv, wait_option, &bss_info.ssid)) {
  1032. ret = -1;
  1033. goto done;
  1034. }
  1035. /* Start/Join Adhoc network */
  1036. memset(&ssid_bssid, 0, sizeof(struct mwifiex_ssid_bssid));
  1037. memcpy(&ssid_bssid.ssid, &bss_info.ssid,
  1038. sizeof(struct mwifiex_802_11_ssid));
  1039. status = mwifiex_bss_ioctl_start(priv, wait, &ssid_bssid);
  1040. if (mwifiex_request_ioctl(priv, wait, status, wait_option))
  1041. ret = -1;
  1042. done:
  1043. kfree(wait);
  1044. return ret;
  1045. }
  1046. /*
  1047. * IOCTL request handler to get rate.
  1048. *
  1049. * This function prepares the correct firmware command and
  1050. * issues it to get the current rate if it is connected,
  1051. * otherwise, the function returns the lowest supported rate
  1052. * for the band.
  1053. */
  1054. static int mwifiex_rate_ioctl_get_rate_value(struct mwifiex_private *priv,
  1055. struct mwifiex_wait_queue *wait,
  1056. struct mwifiex_rate_cfg *rate_cfg)
  1057. {
  1058. struct mwifiex_adapter *adapter = priv->adapter;
  1059. int ret = 0;
  1060. rate_cfg->is_rate_auto = priv->is_data_rate_auto;
  1061. if (!priv->media_connected) {
  1062. switch (adapter->config_bands) {
  1063. case BAND_B:
  1064. /* Return the lowest supported rate for B band */
  1065. rate_cfg->rate = supported_rates_b[0] & 0x7f;
  1066. break;
  1067. case BAND_G:
  1068. case BAND_G | BAND_GN:
  1069. /* Return the lowest supported rate for G band */
  1070. rate_cfg->rate = supported_rates_g[0] & 0x7f;
  1071. break;
  1072. case BAND_B | BAND_G:
  1073. case BAND_A | BAND_B | BAND_G:
  1074. case BAND_A | BAND_B:
  1075. case BAND_A | BAND_B | BAND_G | BAND_AN | BAND_GN:
  1076. case BAND_B | BAND_G | BAND_GN:
  1077. /* Return the lowest supported rate for BG band */
  1078. rate_cfg->rate = supported_rates_bg[0] & 0x7f;
  1079. break;
  1080. case BAND_A:
  1081. case BAND_A | BAND_G:
  1082. case BAND_A | BAND_G | BAND_AN | BAND_GN:
  1083. case BAND_A | BAND_AN:
  1084. /* Return the lowest supported rate for A band */
  1085. rate_cfg->rate = supported_rates_a[0] & 0x7f;
  1086. break;
  1087. case BAND_GN:
  1088. /* Return the lowest supported rate for N band */
  1089. rate_cfg->rate = supported_rates_n[0] & 0x7f;
  1090. break;
  1091. default:
  1092. dev_warn(adapter->dev, "invalid band %#x\n",
  1093. adapter->config_bands);
  1094. break;
  1095. }
  1096. } else {
  1097. /* Send request to firmware */
  1098. ret = mwifiex_prepare_cmd(priv,
  1099. HostCmd_CMD_802_11_TX_RATE_QUERY,
  1100. HostCmd_ACT_GEN_GET, 0, wait, NULL);
  1101. if (!ret)
  1102. ret = -EINPROGRESS;
  1103. }
  1104. return ret;
  1105. }
  1106. /*
  1107. * IOCTL request handler to set rate.
  1108. *
  1109. * This function prepares the correct firmware command and
  1110. * issues it to set the current rate.
  1111. *
  1112. * The function also performs validation checking on the supplied value.
  1113. */
  1114. static int mwifiex_rate_ioctl_set_rate_value(struct mwifiex_private *priv,
  1115. struct mwifiex_wait_queue *wait,
  1116. struct mwifiex_rate_cfg *rate_cfg)
  1117. {
  1118. u8 rates[MWIFIEX_SUPPORTED_RATES];
  1119. u8 *rate = NULL;
  1120. int rate_index = 0;
  1121. u16 bitmap_rates[MAX_BITMAP_RATES_SIZE];
  1122. u32 i = 0;
  1123. int ret = 0;
  1124. struct mwifiex_adapter *adapter = priv->adapter;
  1125. if (rate_cfg->is_rate_auto) {
  1126. memset(bitmap_rates, 0, sizeof(bitmap_rates));
  1127. /* Support all HR/DSSS rates */
  1128. bitmap_rates[0] = 0x000F;
  1129. /* Support all OFDM rates */
  1130. bitmap_rates[1] = 0x00FF;
  1131. /* Support all HT-MCSs rate */
  1132. for (i = 0; i < ARRAY_SIZE(priv->bitmap_rates) - 3; i++)
  1133. bitmap_rates[i + 2] = 0xFFFF;
  1134. bitmap_rates[9] = 0x3FFF;
  1135. } else {
  1136. memset(rates, 0, sizeof(rates));
  1137. mwifiex_get_active_data_rates(priv, rates);
  1138. rate = rates;
  1139. for (i = 0; (rate[i] && i < MWIFIEX_SUPPORTED_RATES); i++) {
  1140. dev_dbg(adapter->dev, "info: rate=%#x wanted=%#x\n",
  1141. rate[i], rate_cfg->rate);
  1142. if ((rate[i] & 0x7f) == (rate_cfg->rate & 0x7f))
  1143. break;
  1144. }
  1145. if (!rate[i] || (i == MWIFIEX_SUPPORTED_RATES)) {
  1146. dev_err(adapter->dev, "fixed data rate %#x is out "
  1147. "of range\n", rate_cfg->rate);
  1148. return -1;
  1149. }
  1150. memset(bitmap_rates, 0, sizeof(bitmap_rates));
  1151. rate_index =
  1152. mwifiex_data_rate_to_index(adapter, rate_cfg->rate);
  1153. /* Only allow b/g rates to be set */
  1154. if (rate_index >= MWIFIEX_RATE_INDEX_HRDSSS0 &&
  1155. rate_index <= MWIFIEX_RATE_INDEX_HRDSSS3) {
  1156. bitmap_rates[0] = 1 << rate_index;
  1157. } else {
  1158. rate_index -= 1; /* There is a 0x00 in the table */
  1159. if (rate_index >= MWIFIEX_RATE_INDEX_OFDM0 &&
  1160. rate_index <= MWIFIEX_RATE_INDEX_OFDM7)
  1161. bitmap_rates[1] = 1 << (rate_index -
  1162. MWIFIEX_RATE_INDEX_OFDM0);
  1163. }
  1164. }
  1165. /* Send request to firmware */
  1166. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_TX_RATE_CFG,
  1167. HostCmd_ACT_GEN_SET, 0, wait, bitmap_rates);
  1168. if (!ret)
  1169. ret = -EINPROGRESS;
  1170. return ret;
  1171. }
  1172. /*
  1173. * IOCTL request handler to set/get rate.
  1174. *
  1175. * This function can be used to set/get either the rate value or the
  1176. * rate index.
  1177. */
  1178. static int mwifiex_rate_ioctl_cfg(struct mwifiex_private *priv,
  1179. struct mwifiex_wait_queue *wait,
  1180. struct mwifiex_rate_cfg *rate_cfg)
  1181. {
  1182. int status = 0;
  1183. if (!rate_cfg)
  1184. return -1;
  1185. if (rate_cfg->action == HostCmd_ACT_GEN_GET)
  1186. status = mwifiex_rate_ioctl_get_rate_value(
  1187. priv, wait, rate_cfg);
  1188. else
  1189. status = mwifiex_rate_ioctl_set_rate_value(
  1190. priv, wait, rate_cfg);
  1191. return status;
  1192. }
  1193. /*
  1194. * Sends IOCTL request to get the data rate.
  1195. *
  1196. * This function allocates the IOCTL request buffer, fills it
  1197. * with requisite parameters and calls the IOCTL handler.
  1198. */
  1199. int mwifiex_drv_get_data_rate(struct mwifiex_private *priv,
  1200. struct mwifiex_rate_cfg *rate)
  1201. {
  1202. int ret = 0;
  1203. struct mwifiex_wait_queue *wait = NULL;
  1204. u8 wait_option = MWIFIEX_IOCTL_WAIT;
  1205. /* Allocate wait buffer */
  1206. wait = mwifiex_alloc_fill_wait_queue(priv, wait_option);
  1207. if (!wait)
  1208. return -ENOMEM;
  1209. memset(rate, 0, sizeof(struct mwifiex_rate_cfg));
  1210. rate->action = HostCmd_ACT_GEN_GET;
  1211. ret = mwifiex_rate_ioctl_cfg(priv, wait, rate);
  1212. ret = mwifiex_request_ioctl(priv, wait, ret, wait_option);
  1213. if (!ret) {
  1214. if (rate && rate->is_rate_auto)
  1215. rate->rate = mwifiex_index_to_data_rate(priv->adapter,
  1216. priv->tx_rate, priv->tx_htinfo);
  1217. else if (rate)
  1218. rate->rate = priv->data_rate;
  1219. } else {
  1220. ret = -1;
  1221. }
  1222. kfree(wait);
  1223. return ret;
  1224. }
  1225. /*
  1226. * IOCTL request handler to set tx power configuration.
  1227. *
  1228. * This function prepares the correct firmware command and
  1229. * issues it.
  1230. *
  1231. * For non-auto power mode, all the following power groups are set -
  1232. * - Modulation class HR/DSSS
  1233. * - Modulation class OFDM
  1234. * - Modulation class HTBW20
  1235. * - Modulation class HTBW40
  1236. */
  1237. static int mwifiex_power_ioctl_set_power(struct mwifiex_private *priv,
  1238. struct mwifiex_wait_queue *wait,
  1239. struct mwifiex_power_cfg *power_cfg)
  1240. {
  1241. int ret = 0;
  1242. struct host_cmd_ds_txpwr_cfg *txp_cfg = NULL;
  1243. struct mwifiex_types_power_group *pg_tlv = NULL;
  1244. struct mwifiex_power_group *pg = NULL;
  1245. u8 *buf = NULL;
  1246. u16 dbm = 0;
  1247. if (!power_cfg->is_power_auto) {
  1248. dbm = (u16) power_cfg->power_level;
  1249. if ((dbm < priv->min_tx_power_level) ||
  1250. (dbm > priv->max_tx_power_level)) {
  1251. dev_err(priv->adapter->dev, "txpower value %d dBm"
  1252. " is out of range (%d dBm-%d dBm)\n",
  1253. dbm, priv->min_tx_power_level,
  1254. priv->max_tx_power_level);
  1255. return -1;
  1256. }
  1257. }
  1258. buf = kzalloc(MWIFIEX_SIZE_OF_CMD_BUFFER, GFP_KERNEL);
  1259. if (!buf) {
  1260. dev_err(priv->adapter->dev, "%s: failed to alloc cmd buffer\n",
  1261. __func__);
  1262. return -1;
  1263. }
  1264. txp_cfg = (struct host_cmd_ds_txpwr_cfg *) buf;
  1265. txp_cfg->action = cpu_to_le16(HostCmd_ACT_GEN_SET);
  1266. if (!power_cfg->is_power_auto) {
  1267. txp_cfg->mode = cpu_to_le32(1);
  1268. pg_tlv = (struct mwifiex_types_power_group *) (buf +
  1269. sizeof(struct host_cmd_ds_txpwr_cfg));
  1270. pg_tlv->type = TLV_TYPE_POWER_GROUP;
  1271. pg_tlv->length = 4 * sizeof(struct mwifiex_power_group);
  1272. pg = (struct mwifiex_power_group *) (buf +
  1273. sizeof(struct host_cmd_ds_txpwr_cfg) +
  1274. sizeof(struct mwifiex_types_power_group));
  1275. /* Power group for modulation class HR/DSSS */
  1276. pg->first_rate_code = 0x00;
  1277. pg->last_rate_code = 0x03;
  1278. pg->modulation_class = MOD_CLASS_HR_DSSS;
  1279. pg->power_step = 0;
  1280. pg->power_min = (s8) dbm;
  1281. pg->power_max = (s8) dbm;
  1282. pg++;
  1283. /* Power group for modulation class OFDM */
  1284. pg->first_rate_code = 0x00;
  1285. pg->last_rate_code = 0x07;
  1286. pg->modulation_class = MOD_CLASS_OFDM;
  1287. pg->power_step = 0;
  1288. pg->power_min = (s8) dbm;
  1289. pg->power_max = (s8) dbm;
  1290. pg++;
  1291. /* Power group for modulation class HTBW20 */
  1292. pg->first_rate_code = 0x00;
  1293. pg->last_rate_code = 0x20;
  1294. pg->modulation_class = MOD_CLASS_HT;
  1295. pg->power_step = 0;
  1296. pg->power_min = (s8) dbm;
  1297. pg->power_max = (s8) dbm;
  1298. pg->ht_bandwidth = HT_BW_20;
  1299. pg++;
  1300. /* Power group for modulation class HTBW40 */
  1301. pg->first_rate_code = 0x00;
  1302. pg->last_rate_code = 0x20;
  1303. pg->modulation_class = MOD_CLASS_HT;
  1304. pg->power_step = 0;
  1305. pg->power_min = (s8) dbm;
  1306. pg->power_max = (s8) dbm;
  1307. pg->ht_bandwidth = HT_BW_40;
  1308. }
  1309. /* Send request to firmware */
  1310. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_TXPWR_CFG,
  1311. HostCmd_ACT_GEN_SET, 0, wait, buf);
  1312. if (!ret)
  1313. ret = -EINPROGRESS;
  1314. kfree(buf);
  1315. return ret;
  1316. }
  1317. /*
  1318. * IOCTL request handler to get power save mode.
  1319. *
  1320. * This function prepares the correct firmware command and
  1321. * issues it.
  1322. */
  1323. static int mwifiex_pm_ioctl_ps_mode(struct mwifiex_private *priv,
  1324. struct mwifiex_wait_queue *wait,
  1325. u32 *ps_mode, u16 action)
  1326. {
  1327. int ret = 0;
  1328. struct mwifiex_adapter *adapter = priv->adapter;
  1329. u16 sub_cmd;
  1330. if (action == HostCmd_ACT_GEN_SET) {
  1331. if (*ps_mode)
  1332. adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
  1333. else
  1334. adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM;
  1335. sub_cmd = (*ps_mode) ? EN_AUTO_PS : DIS_AUTO_PS;
  1336. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
  1337. sub_cmd, BITMAP_STA_PS, wait, NULL);
  1338. if ((!ret) && (sub_cmd == DIS_AUTO_PS))
  1339. ret = mwifiex_prepare_cmd(priv,
  1340. HostCmd_CMD_802_11_PS_MODE_ENH, GET_PS,
  1341. 0, NULL, NULL);
  1342. } else {
  1343. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
  1344. GET_PS, 0, wait, NULL);
  1345. }
  1346. if (!ret)
  1347. ret = -EINPROGRESS;
  1348. return ret;
  1349. }
  1350. /*
  1351. * IOCTL request handler to set/reset WPA IE.
  1352. *
  1353. * The supplied WPA IE is treated as a opaque buffer. Only the first field
  1354. * is checked to determine WPA version. If buffer length is zero, the existing
  1355. * WPA IE is reset.
  1356. */
  1357. static int mwifiex_set_wpa_ie_helper(struct mwifiex_private *priv,
  1358. u8 *ie_data_ptr, u16 ie_len)
  1359. {
  1360. if (ie_len) {
  1361. if (ie_len > sizeof(priv->wpa_ie)) {
  1362. dev_err(priv->adapter->dev,
  1363. "failed to copy WPA IE, too big\n");
  1364. return -1;
  1365. }
  1366. memcpy(priv->wpa_ie, ie_data_ptr, ie_len);
  1367. priv->wpa_ie_len = (u8) ie_len;
  1368. dev_dbg(priv->adapter->dev, "cmd: Set Wpa_ie_len=%d IE=%#x\n",
  1369. priv->wpa_ie_len, priv->wpa_ie[0]);
  1370. if (priv->wpa_ie[0] == WLAN_EID_WPA) {
  1371. priv->sec_info.wpa_enabled = true;
  1372. } else if (priv->wpa_ie[0] == WLAN_EID_RSN) {
  1373. priv->sec_info.wpa2_enabled = true;
  1374. } else {
  1375. priv->sec_info.wpa_enabled = false;
  1376. priv->sec_info.wpa2_enabled = false;
  1377. }
  1378. } else {
  1379. memset(priv->wpa_ie, 0, sizeof(priv->wpa_ie));
  1380. priv->wpa_ie_len = 0;
  1381. dev_dbg(priv->adapter->dev, "info: reset wpa_ie_len=%d IE=%#x\n",
  1382. priv->wpa_ie_len, priv->wpa_ie[0]);
  1383. priv->sec_info.wpa_enabled = false;
  1384. priv->sec_info.wpa2_enabled = false;
  1385. }
  1386. return 0;
  1387. }
  1388. /*
  1389. * IOCTL request handler to set/reset WAPI IE.
  1390. *
  1391. * The supplied WAPI IE is treated as a opaque buffer. Only the first field
  1392. * is checked to internally enable WAPI. If buffer length is zero, the existing
  1393. * WAPI IE is reset.
  1394. */
  1395. static int mwifiex_set_wapi_ie(struct mwifiex_private *priv,
  1396. u8 *ie_data_ptr, u16 ie_len)
  1397. {
  1398. if (ie_len) {
  1399. if (ie_len > sizeof(priv->wapi_ie)) {
  1400. dev_dbg(priv->adapter->dev,
  1401. "info: failed to copy WAPI IE, too big\n");
  1402. return -1;
  1403. }
  1404. memcpy(priv->wapi_ie, ie_data_ptr, ie_len);
  1405. priv->wapi_ie_len = ie_len;
  1406. dev_dbg(priv->adapter->dev, "cmd: Set wapi_ie_len=%d IE=%#x\n",
  1407. priv->wapi_ie_len, priv->wapi_ie[0]);
  1408. if (priv->wapi_ie[0] == WLAN_EID_BSS_AC_ACCESS_DELAY)
  1409. priv->sec_info.wapi_enabled = true;
  1410. } else {
  1411. memset(priv->wapi_ie, 0, sizeof(priv->wapi_ie));
  1412. priv->wapi_ie_len = ie_len;
  1413. dev_dbg(priv->adapter->dev,
  1414. "info: Reset wapi_ie_len=%d IE=%#x\n",
  1415. priv->wapi_ie_len, priv->wapi_ie[0]);
  1416. priv->sec_info.wapi_enabled = false;
  1417. }
  1418. return 0;
  1419. }
  1420. /*
  1421. * IOCTL request handler to set WAPI key.
  1422. *
  1423. * This function prepares the correct firmware command and
  1424. * issues it.
  1425. */
  1426. static int mwifiex_sec_ioctl_set_wapi_key(struct mwifiex_adapter *adapter,
  1427. struct mwifiex_wait_queue *wait,
  1428. struct mwifiex_ds_encrypt_key *encrypt_key)
  1429. {
  1430. int ret = 0;
  1431. struct mwifiex_private *priv = adapter->priv[wait->bss_index];
  1432. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
  1433. HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
  1434. wait, encrypt_key);
  1435. if (!ret)
  1436. ret = -EINPROGRESS;
  1437. return ret;
  1438. }
  1439. /*
  1440. * IOCTL request handler to set WEP network key.
  1441. *
  1442. * This function prepares the correct firmware command and
  1443. * issues it, after validation checks.
  1444. */
  1445. static int mwifiex_sec_ioctl_set_wep_key(struct mwifiex_adapter *adapter,
  1446. struct mwifiex_wait_queue *wait,
  1447. struct mwifiex_ds_encrypt_key *encrypt_key)
  1448. {
  1449. int ret = 0;
  1450. struct mwifiex_private *priv = adapter->priv[wait->bss_index];
  1451. struct mwifiex_wep_key *wep_key = NULL;
  1452. int index;
  1453. if (priv->wep_key_curr_index >= NUM_WEP_KEYS)
  1454. priv->wep_key_curr_index = 0;
  1455. wep_key = &priv->wep_key[priv->wep_key_curr_index];
  1456. index = encrypt_key->key_index;
  1457. if (encrypt_key->key_disable) {
  1458. priv->sec_info.wep_status = MWIFIEX_802_11_WEP_DISABLED;
  1459. } else if (!encrypt_key->key_len) {
  1460. /* Copy the required key as the current key */
  1461. wep_key = &priv->wep_key[index];
  1462. if (!wep_key->key_length) {
  1463. dev_err(adapter->dev,
  1464. "key not set, so cannot enable it\n");
  1465. return -1;
  1466. }
  1467. priv->wep_key_curr_index = (u16) index;
  1468. priv->sec_info.wep_status = MWIFIEX_802_11_WEP_ENABLED;
  1469. } else {
  1470. wep_key = &priv->wep_key[index];
  1471. /* Cleanup */
  1472. memset(wep_key, 0, sizeof(struct mwifiex_wep_key));
  1473. /* Copy the key in the driver */
  1474. memcpy(wep_key->key_material,
  1475. encrypt_key->key_material,
  1476. encrypt_key->key_len);
  1477. wep_key->key_index = index;
  1478. wep_key->key_length = encrypt_key->key_len;
  1479. priv->sec_info.wep_status = MWIFIEX_802_11_WEP_ENABLED;
  1480. }
  1481. if (wep_key->key_length) {
  1482. /* Send request to firmware */
  1483. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
  1484. HostCmd_ACT_GEN_SET, 0, NULL, NULL);
  1485. if (ret)
  1486. return ret;
  1487. }
  1488. if (priv->sec_info.wep_status == MWIFIEX_802_11_WEP_ENABLED)
  1489. priv->curr_pkt_filter |= HostCmd_ACT_MAC_WEP_ENABLE;
  1490. else
  1491. priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_WEP_ENABLE;
  1492. /* Send request to firmware */
  1493. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_MAC_CONTROL,
  1494. HostCmd_ACT_GEN_SET, 0, wait,
  1495. &priv->curr_pkt_filter);
  1496. if (!ret)
  1497. ret = -EINPROGRESS;
  1498. return ret;
  1499. }
  1500. /*
  1501. * IOCTL request handler to set WPA key.
  1502. *
  1503. * This function prepares the correct firmware command and
  1504. * issues it, after validation checks.
  1505. *
  1506. * Current driver only supports key length of up to 32 bytes.
  1507. *
  1508. * This function can also be used to disable a currently set key.
  1509. */
  1510. static int mwifiex_sec_ioctl_set_wpa_key(struct mwifiex_adapter *adapter,
  1511. struct mwifiex_wait_queue *wait,
  1512. struct mwifiex_ds_encrypt_key *encrypt_key)
  1513. {
  1514. int ret = 0;
  1515. struct mwifiex_private *priv = adapter->priv[wait->bss_index];
  1516. u8 remove_key = false;
  1517. struct host_cmd_ds_802_11_key_material *ibss_key;
  1518. /* Current driver only supports key length of up to 32 bytes */
  1519. if (encrypt_key->key_len > MWIFIEX_MAX_KEY_LENGTH) {
  1520. dev_err(adapter->dev, "key length too long\n");
  1521. return -1;
  1522. }
  1523. if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
  1524. /*
  1525. * IBSS/WPA-None uses only one key (Group) for both receiving
  1526. * and sending unicast and multicast packets.
  1527. */
  1528. /* Send the key as PTK to firmware */
  1529. encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
  1530. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
  1531. HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
  1532. NULL, encrypt_key);
  1533. if (ret)
  1534. return ret;
  1535. ibss_key = &priv->aes_key;
  1536. memset(ibss_key, 0,
  1537. sizeof(struct host_cmd_ds_802_11_key_material));
  1538. /* Copy the key in the driver */
  1539. memcpy(ibss_key->key_param_set.key, encrypt_key->key_material,
  1540. encrypt_key->key_len);
  1541. memcpy(&ibss_key->key_param_set.key_len, &encrypt_key->key_len,
  1542. sizeof(ibss_key->key_param_set.key_len));
  1543. ibss_key->key_param_set.key_type_id
  1544. = cpu_to_le16(KEY_TYPE_ID_TKIP);
  1545. ibss_key->key_param_set.key_info
  1546. = cpu_to_le16(KEY_INFO_TKIP_ENABLED);
  1547. /* Send the key as GTK to firmware */
  1548. encrypt_key->key_index = ~MWIFIEX_KEY_INDEX_UNICAST;
  1549. }
  1550. if (!encrypt_key->key_index)
  1551. encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
  1552. if (remove_key)
  1553. /* Send request to firmware */
  1554. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
  1555. HostCmd_ACT_GEN_SET,
  1556. !(KEY_INFO_ENABLED),
  1557. wait, encrypt_key);
  1558. else
  1559. /* Send request to firmware */
  1560. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
  1561. HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
  1562. wait, encrypt_key);
  1563. if (!ret)
  1564. ret = -EINPROGRESS;
  1565. return ret;
  1566. }
  1567. /*
  1568. * IOCTL request handler to set/get network keys.
  1569. *
  1570. * This is a generic key handling function which supports WEP, WPA
  1571. * and WAPI.
  1572. */
  1573. static int
  1574. mwifiex_sec_ioctl_encrypt_key(struct mwifiex_private *priv,
  1575. struct mwifiex_wait_queue *wait,
  1576. struct mwifiex_ds_encrypt_key *encrypt_key)
  1577. {
  1578. int status = 0;
  1579. struct mwifiex_adapter *adapter = priv->adapter;
  1580. if (encrypt_key->is_wapi_key)
  1581. status = mwifiex_sec_ioctl_set_wapi_key(adapter, wait,
  1582. encrypt_key);
  1583. else if (encrypt_key->key_len > WLAN_KEY_LEN_WEP104)
  1584. status = mwifiex_sec_ioctl_set_wpa_key(adapter, wait,
  1585. encrypt_key);
  1586. else
  1587. status = mwifiex_sec_ioctl_set_wep_key(adapter, wait,
  1588. encrypt_key);
  1589. return status;
  1590. }
  1591. /*
  1592. * This function returns the driver version.
  1593. */
  1594. int
  1595. mwifiex_drv_get_driver_version(struct mwifiex_adapter *adapter, char *version,
  1596. int max_len)
  1597. {
  1598. union {
  1599. u32 l;
  1600. u8 c[4];
  1601. } ver;
  1602. char fw_ver[32];
  1603. ver.l = adapter->fw_release_number;
  1604. sprintf(fw_ver, "%u.%u.%u.p%u", ver.c[2], ver.c[1], ver.c[0], ver.c[3]);
  1605. snprintf(version, max_len, driver_version, fw_ver);
  1606. dev_dbg(adapter->dev, "info: MWIFIEX VERSION: %s\n", version);
  1607. return 0;
  1608. }
  1609. /*
  1610. * Sends IOCTL request to set Tx power. It can be set to either auto
  1611. * or a fixed value.
  1612. *
  1613. * This function allocates the IOCTL request buffer, fills it
  1614. * with requisite parameters and calls the IOCTL handler.
  1615. */
  1616. int
  1617. mwifiex_set_tx_power(struct mwifiex_private *priv, int type, int dbm)
  1618. {
  1619. struct mwifiex_power_cfg power_cfg;
  1620. struct mwifiex_wait_queue *wait = NULL;
  1621. int status = 0;
  1622. int ret = 0;
  1623. wait = mwifiex_alloc_fill_wait_queue(priv, MWIFIEX_IOCTL_WAIT);
  1624. if (!wait)
  1625. return -ENOMEM;
  1626. if (type == NL80211_TX_POWER_FIXED) {
  1627. power_cfg.is_power_auto = 0;
  1628. power_cfg.power_level = dbm;
  1629. } else {
  1630. power_cfg.is_power_auto = 1;
  1631. }
  1632. status = mwifiex_power_ioctl_set_power(priv, wait, &power_cfg);
  1633. ret = mwifiex_request_ioctl(priv, wait, status, MWIFIEX_IOCTL_WAIT);
  1634. kfree(wait);
  1635. return ret;
  1636. }
  1637. /*
  1638. * Sends IOCTL request to get scan table.
  1639. *
  1640. * This function allocates the IOCTL request buffer, fills it
  1641. * with requisite parameters and calls the IOCTL handler.
  1642. */
  1643. int mwifiex_get_scan_table(struct mwifiex_private *priv, u8 wait_option,
  1644. struct mwifiex_scan_resp *scan_resp)
  1645. {
  1646. struct mwifiex_wait_queue *wait = NULL;
  1647. struct mwifiex_scan_resp scan;
  1648. int status = 0;
  1649. /* Allocate wait buffer */
  1650. wait = mwifiex_alloc_fill_wait_queue(priv, wait_option);
  1651. if (!wait)
  1652. return -ENOMEM;
  1653. status = mwifiex_scan_networks(priv, wait, HostCmd_ACT_GEN_GET,
  1654. NULL, &scan);
  1655. status = mwifiex_request_ioctl(priv, wait, status, wait_option);
  1656. if (!status) {
  1657. if (scan_resp)
  1658. memcpy(scan_resp, &scan,
  1659. sizeof(struct mwifiex_scan_resp));
  1660. }
  1661. if (wait && (status != -EINPROGRESS))
  1662. kfree(wait);
  1663. return status;
  1664. }
  1665. /*
  1666. * Sends IOCTL request to get signal information.
  1667. *
  1668. * This function allocates the IOCTL request buffer, fills it
  1669. * with requisite parameters and calls the IOCTL handler.
  1670. */
  1671. int mwifiex_get_signal_info(struct mwifiex_private *priv, u8 wait_option,
  1672. struct mwifiex_ds_get_signal *signal)
  1673. {
  1674. struct mwifiex_ds_get_signal info;
  1675. struct mwifiex_wait_queue *wait = NULL;
  1676. int status = 0;
  1677. /* Allocate wait buffer */
  1678. wait = mwifiex_alloc_fill_wait_queue(priv, wait_option);
  1679. if (!wait)
  1680. return -ENOMEM;
  1681. info.selector = ALL_RSSI_INFO_MASK;
  1682. status = mwifiex_get_info_signal(priv, wait, &info);
  1683. status = mwifiex_request_ioctl(priv, wait, status, wait_option);
  1684. if (!status) {
  1685. if (signal)
  1686. memcpy(signal, &info,
  1687. sizeof(struct mwifiex_ds_get_signal));
  1688. if (info.selector & BCN_RSSI_AVG_MASK)
  1689. priv->w_stats.qual.level = info.bcn_rssi_avg;
  1690. if (info.selector & BCN_NF_AVG_MASK)
  1691. priv->w_stats.qual.noise = info.bcn_nf_avg;
  1692. }
  1693. if (wait && (status != -EINPROGRESS))
  1694. kfree(wait);
  1695. return status;
  1696. }
  1697. /*
  1698. * Sends IOCTL request to set encoding parameters.
  1699. *
  1700. * This function allocates the IOCTL request buffer, fills it
  1701. * with requisite parameters and calls the IOCTL handler.
  1702. */
  1703. int mwifiex_set_encode(struct mwifiex_private *priv, const u8 *key,
  1704. int key_len, u8 key_index, int disable)
  1705. {
  1706. struct mwifiex_wait_queue *wait = NULL;
  1707. struct mwifiex_ds_encrypt_key encrypt_key;
  1708. int status = 0;
  1709. int ret = 0;
  1710. wait = mwifiex_alloc_fill_wait_queue(priv, MWIFIEX_IOCTL_WAIT);
  1711. if (!wait)
  1712. return -ENOMEM;
  1713. memset(&encrypt_key, 0, sizeof(struct mwifiex_ds_encrypt_key));
  1714. encrypt_key.key_len = key_len;
  1715. if (!disable) {
  1716. encrypt_key.key_index = key_index;
  1717. if (key_len)
  1718. memcpy(encrypt_key.key_material, key, key_len);
  1719. } else {
  1720. encrypt_key.key_disable = true;
  1721. }
  1722. status = mwifiex_sec_ioctl_encrypt_key(priv, wait, &encrypt_key);
  1723. if (mwifiex_request_ioctl(priv, wait, status, MWIFIEX_IOCTL_WAIT))
  1724. ret = -EFAULT;
  1725. kfree(wait);
  1726. return ret;
  1727. }
  1728. /*
  1729. * Sends IOCTL request to set power management parameters.
  1730. *
  1731. * This function allocates the IOCTL request buffer, fills it
  1732. * with requisite parameters and calls the IOCTL handler.
  1733. */
  1734. int
  1735. mwifiex_drv_set_power(struct mwifiex_private *priv, bool power_on)
  1736. {
  1737. int ret = 0;
  1738. int status = 0;
  1739. struct mwifiex_wait_queue *wait = NULL;
  1740. u32 ps_mode;
  1741. wait = mwifiex_alloc_fill_wait_queue(priv, MWIFIEX_IOCTL_WAIT);
  1742. if (!wait)
  1743. return -ENOMEM;
  1744. ps_mode = power_on;
  1745. status = mwifiex_pm_ioctl_ps_mode(priv, wait, &ps_mode,
  1746. HostCmd_ACT_GEN_SET);
  1747. ret = mwifiex_request_ioctl(priv, wait, status, MWIFIEX_IOCTL_WAIT);
  1748. kfree(wait);
  1749. return ret;
  1750. }
  1751. /*
  1752. * Sends IOCTL request to get extended version.
  1753. *
  1754. * This function allocates the IOCTL request buffer, fills it
  1755. * with requisite parameters and calls the IOCTL handler.
  1756. */
  1757. int
  1758. mwifiex_get_ver_ext(struct mwifiex_private *priv)
  1759. {
  1760. struct mwifiex_ver_ext ver_ext;
  1761. struct mwifiex_wait_queue *wait = NULL;
  1762. int status = 0;
  1763. int ret = 0;
  1764. u8 wait_option = MWIFIEX_IOCTL_WAIT;
  1765. /* Allocate wait buffer */
  1766. wait = mwifiex_alloc_fill_wait_queue(priv, wait_option);
  1767. if (!wait)
  1768. return -ENOMEM;
  1769. /* get fw version */
  1770. memset(&ver_ext, 0, sizeof(struct host_cmd_ds_version_ext));
  1771. status = mwifiex_get_info_ver_ext(priv, wait, &ver_ext);
  1772. ret = mwifiex_request_ioctl(priv, wait, status, wait_option);
  1773. if (ret)
  1774. ret = -1;
  1775. kfree(wait);
  1776. return ret;
  1777. }
  1778. /*
  1779. * Sends IOCTL request to get statistics information.
  1780. *
  1781. * This function allocates the IOCTL request buffer, fills it
  1782. * with requisite parameters and calls the IOCTL handler.
  1783. */
  1784. int
  1785. mwifiex_get_stats_info(struct mwifiex_private *priv,
  1786. struct mwifiex_ds_get_stats *log)
  1787. {
  1788. int ret = 0;
  1789. int status = 0;
  1790. struct mwifiex_wait_queue *wait = NULL;
  1791. struct mwifiex_ds_get_stats get_log;
  1792. u8 wait_option = MWIFIEX_IOCTL_WAIT;
  1793. /* Allocate wait buffer */
  1794. wait = mwifiex_alloc_fill_wait_queue(priv, wait_option);
  1795. if (!wait)
  1796. return -ENOMEM;
  1797. memset(&get_log, 0, sizeof(struct mwifiex_ds_get_stats));
  1798. status = mwifiex_get_info_stats(priv, wait, &get_log);
  1799. /* Send IOCTL request to MWIFIEX */
  1800. ret = mwifiex_request_ioctl(priv, wait, status, wait_option);
  1801. if (!ret) {
  1802. if (log)
  1803. memcpy(log, &get_log, sizeof(struct
  1804. mwifiex_ds_get_stats));
  1805. priv->w_stats.discard.fragment = get_log.fcs_error;
  1806. priv->w_stats.discard.retries = get_log.retry;
  1807. priv->w_stats.discard.misc = get_log.ack_failure;
  1808. }
  1809. kfree(wait);
  1810. return ret;
  1811. }
  1812. /*
  1813. * IOCTL request handler to read/write register.
  1814. *
  1815. * This function prepares the correct firmware command and
  1816. * issues it.
  1817. *
  1818. * Access to the following registers are supported -
  1819. * - MAC
  1820. * - BBP
  1821. * - RF
  1822. * - PMIC
  1823. * - CAU
  1824. */
  1825. static int mwifiex_reg_mem_ioctl_reg_rw(struct mwifiex_private *priv,
  1826. struct mwifiex_wait_queue *wait,
  1827. struct mwifiex_ds_reg_rw *reg_rw,
  1828. u16 action)
  1829. {
  1830. int ret = 0;
  1831. u16 cmd_no;
  1832. switch (le32_to_cpu(reg_rw->type)) {
  1833. case MWIFIEX_REG_MAC:
  1834. cmd_no = HostCmd_CMD_MAC_REG_ACCESS;
  1835. break;
  1836. case MWIFIEX_REG_BBP:
  1837. cmd_no = HostCmd_CMD_BBP_REG_ACCESS;
  1838. break;
  1839. case MWIFIEX_REG_RF:
  1840. cmd_no = HostCmd_CMD_RF_REG_ACCESS;
  1841. break;
  1842. case MWIFIEX_REG_PMIC:
  1843. cmd_no = HostCmd_CMD_PMIC_REG_ACCESS;
  1844. break;
  1845. case MWIFIEX_REG_CAU:
  1846. cmd_no = HostCmd_CMD_CAU_REG_ACCESS;
  1847. break;
  1848. default:
  1849. return -1;
  1850. }
  1851. /* Send request to firmware */
  1852. ret = mwifiex_prepare_cmd(priv, cmd_no, action, 0, wait, reg_rw);
  1853. if (!ret)
  1854. ret = -EINPROGRESS;
  1855. return ret;
  1856. }
  1857. /*
  1858. * Sends IOCTL request to write to a register.
  1859. *
  1860. * This function allocates the IOCTL request buffer, fills it
  1861. * with requisite parameters and calls the IOCTL handler.
  1862. */
  1863. int
  1864. mwifiex_reg_write(struct mwifiex_private *priv, u32 reg_type,
  1865. u32 reg_offset, u32 reg_value)
  1866. {
  1867. int ret = 0;
  1868. int status = 0;
  1869. struct mwifiex_wait_queue *wait = NULL;
  1870. struct mwifiex_ds_reg_rw reg_rw;
  1871. wait = mwifiex_alloc_fill_wait_queue(priv, MWIFIEX_IOCTL_WAIT);
  1872. if (!wait)
  1873. return -ENOMEM;
  1874. reg_rw.type = cpu_to_le32(reg_type);
  1875. reg_rw.offset = cpu_to_le32(reg_offset);
  1876. reg_rw.value = cpu_to_le32(reg_value);
  1877. status = mwifiex_reg_mem_ioctl_reg_rw(priv, wait, &reg_rw,
  1878. HostCmd_ACT_GEN_SET);
  1879. ret = mwifiex_request_ioctl(priv, wait, status, MWIFIEX_IOCTL_WAIT);
  1880. kfree(wait);
  1881. return ret;
  1882. }
  1883. /*
  1884. * Sends IOCTL request to read from a register.
  1885. *
  1886. * This function allocates the IOCTL request buffer, fills it
  1887. * with requisite parameters and calls the IOCTL handler.
  1888. */
  1889. int
  1890. mwifiex_reg_read(struct mwifiex_private *priv, u32 reg_type,
  1891. u32 reg_offset, u32 *value)
  1892. {
  1893. int ret = 0;
  1894. int status = 0;
  1895. struct mwifiex_wait_queue *wait = NULL;
  1896. struct mwifiex_ds_reg_rw reg_rw;
  1897. wait = mwifiex_alloc_fill_wait_queue(priv, MWIFIEX_IOCTL_WAIT);
  1898. if (!wait)
  1899. return -ENOMEM;
  1900. reg_rw.type = cpu_to_le32(reg_type);
  1901. reg_rw.offset = cpu_to_le32(reg_offset);
  1902. status = mwifiex_reg_mem_ioctl_reg_rw(priv, wait, &reg_rw,
  1903. HostCmd_ACT_GEN_GET);
  1904. ret = mwifiex_request_ioctl(priv, wait, status, MWIFIEX_IOCTL_WAIT);
  1905. if (ret)
  1906. goto done;
  1907. *value = le32_to_cpu(reg_rw.value);
  1908. done:
  1909. kfree(wait);
  1910. return ret;
  1911. }
  1912. /*
  1913. * IOCTL request handler to read EEPROM.
  1914. *
  1915. * This function prepares the correct firmware command and
  1916. * issues it.
  1917. */
  1918. static int
  1919. mwifiex_reg_mem_ioctl_read_eeprom(struct mwifiex_private *priv,
  1920. struct mwifiex_wait_queue *wait,
  1921. struct mwifiex_ds_read_eeprom *rd_eeprom)
  1922. {
  1923. int ret = 0;
  1924. /* Send request to firmware */
  1925. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_802_11_EEPROM_ACCESS,
  1926. HostCmd_ACT_GEN_GET, 0, wait, rd_eeprom);
  1927. if (!ret)
  1928. ret = -EINPROGRESS;
  1929. return ret;
  1930. }
  1931. /*
  1932. * Sends IOCTL request to read from EEPROM.
  1933. *
  1934. * This function allocates the IOCTL request buffer, fills it
  1935. * with requisite parameters and calls the IOCTL handler.
  1936. */
  1937. int
  1938. mwifiex_eeprom_read(struct mwifiex_private *priv, u16 offset, u16 bytes,
  1939. u8 *value)
  1940. {
  1941. int ret = 0;
  1942. int status = 0;
  1943. struct mwifiex_wait_queue *wait = NULL;
  1944. struct mwifiex_ds_read_eeprom rd_eeprom;
  1945. wait = mwifiex_alloc_fill_wait_queue(priv, MWIFIEX_IOCTL_WAIT);
  1946. if (!wait)
  1947. return -ENOMEM;
  1948. rd_eeprom.offset = cpu_to_le16((u16) offset);
  1949. rd_eeprom.byte_count = cpu_to_le16((u16) bytes);
  1950. status = mwifiex_reg_mem_ioctl_read_eeprom(priv, wait, &rd_eeprom);
  1951. ret = mwifiex_request_ioctl(priv, wait, status, MWIFIEX_IOCTL_WAIT);
  1952. if (ret)
  1953. goto done;
  1954. memcpy(value, rd_eeprom.value, MAX_EEPROM_DATA);
  1955. done:
  1956. kfree(wait);
  1957. return ret;
  1958. }
  1959. /*
  1960. * This function sets a generic IE. In addition to generic IE, it can
  1961. * also handle WPA, WPA2 and WAPI IEs.
  1962. */
  1963. static int
  1964. mwifiex_set_gen_ie_helper(struct mwifiex_private *priv, u8 *ie_data_ptr,
  1965. u16 ie_len)
  1966. {
  1967. int ret = 0;
  1968. struct ieee_types_vendor_header *pvendor_ie;
  1969. const u8 wpa_oui[] = { 0x00, 0x50, 0xf2, 0x01 };
  1970. const u8 wps_oui[] = { 0x00, 0x50, 0xf2, 0x04 };
  1971. /* If the passed length is zero, reset the buffer */
  1972. if (!ie_len) {
  1973. priv->gen_ie_buf_len = 0;
  1974. priv->wps.session_enable = false;
  1975. return 0;
  1976. } else if (!ie_data_ptr) {
  1977. return -1;
  1978. }
  1979. pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
  1980. /* Test to see if it is a WPA IE, if not, then it is a gen IE */
  1981. if (((pvendor_ie->element_id == WLAN_EID_WPA)
  1982. && (!memcmp(pvendor_ie->oui, wpa_oui, sizeof(wpa_oui))))
  1983. || (pvendor_ie->element_id == WLAN_EID_RSN)) {
  1984. /* IE is a WPA/WPA2 IE so call set_wpa function */
  1985. ret = mwifiex_set_wpa_ie_helper(priv, ie_data_ptr, ie_len);
  1986. priv->wps.session_enable = false;
  1987. return ret;
  1988. } else if (pvendor_ie->element_id == WLAN_EID_BSS_AC_ACCESS_DELAY) {
  1989. /* IE is a WAPI IE so call set_wapi function */
  1990. ret = mwifiex_set_wapi_ie(priv, ie_data_ptr, ie_len);
  1991. return ret;
  1992. }
  1993. /*
  1994. * Verify that the passed length is not larger than the
  1995. * available space remaining in the buffer
  1996. */
  1997. if (ie_len < (sizeof(priv->gen_ie_buf) - priv->gen_ie_buf_len)) {
  1998. /* Test to see if it is a WPS IE, if so, enable
  1999. * wps session flag
  2000. */
  2001. pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
  2002. if ((pvendor_ie->element_id == WLAN_EID_VENDOR_SPECIFIC)
  2003. && (!memcmp(pvendor_ie->oui, wps_oui,
  2004. sizeof(wps_oui)))) {
  2005. priv->wps.session_enable = true;
  2006. dev_dbg(priv->adapter->dev,
  2007. "info: WPS Session Enabled.\n");
  2008. }
  2009. /* Append the passed data to the end of the
  2010. genIeBuffer */
  2011. memcpy(priv->gen_ie_buf + priv->gen_ie_buf_len, ie_data_ptr,
  2012. ie_len);
  2013. /* Increment the stored buffer length by the
  2014. size passed */
  2015. priv->gen_ie_buf_len += ie_len;
  2016. } else {
  2017. /* Passed data does not fit in the remaining
  2018. buffer space */
  2019. ret = -1;
  2020. }
  2021. /* Return 0, or -1 for error case */
  2022. return ret;
  2023. }
  2024. /*
  2025. * IOCTL request handler to set/get generic IE.
  2026. *
  2027. * In addition to various generic IEs, this function can also be
  2028. * used to set the ARP filter.
  2029. */
  2030. static int mwifiex_misc_ioctl_gen_ie(struct mwifiex_private *priv,
  2031. struct mwifiex_ds_misc_gen_ie *gen_ie,
  2032. u16 action)
  2033. {
  2034. struct mwifiex_adapter *adapter = priv->adapter;
  2035. switch (gen_ie->type) {
  2036. case MWIFIEX_IE_TYPE_GEN_IE:
  2037. if (action == HostCmd_ACT_GEN_GET) {
  2038. gen_ie->len = priv->wpa_ie_len;
  2039. memcpy(gen_ie->ie_data, priv->wpa_ie, gen_ie->len);
  2040. } else {
  2041. mwifiex_set_gen_ie_helper(priv, gen_ie->ie_data,
  2042. (u16) gen_ie->len);
  2043. }
  2044. break;
  2045. case MWIFIEX_IE_TYPE_ARP_FILTER:
  2046. memset(adapter->arp_filter, 0, sizeof(adapter->arp_filter));
  2047. if (gen_ie->len > ARP_FILTER_MAX_BUF_SIZE) {
  2048. adapter->arp_filter_size = 0;
  2049. dev_err(adapter->dev, "invalid ARP filter size\n");
  2050. return -1;
  2051. } else {
  2052. memcpy(adapter->arp_filter, gen_ie->ie_data,
  2053. gen_ie->len);
  2054. adapter->arp_filter_size = gen_ie->len;
  2055. }
  2056. break;
  2057. default:
  2058. dev_err(adapter->dev, "invalid IE type\n");
  2059. return -1;
  2060. }
  2061. return 0;
  2062. }
  2063. /*
  2064. * Sends IOCTL request to set a generic IE.
  2065. *
  2066. * This function allocates the IOCTL request buffer, fills it
  2067. * with requisite parameters and calls the IOCTL handler.
  2068. */
  2069. int
  2070. mwifiex_set_gen_ie(struct mwifiex_private *priv, u8 *ie, int ie_len)
  2071. {
  2072. struct mwifiex_ds_misc_gen_ie gen_ie;
  2073. int status = 0;
  2074. if (ie_len > IW_CUSTOM_MAX)
  2075. return -EFAULT;
  2076. gen_ie.type = MWIFIEX_IE_TYPE_GEN_IE;
  2077. gen_ie.len = ie_len;
  2078. memcpy(gen_ie.ie_data, ie, ie_len);
  2079. status = mwifiex_misc_ioctl_gen_ie(priv, &gen_ie, HostCmd_ACT_GEN_SET);
  2080. if (status)
  2081. return -EFAULT;
  2082. return 0;
  2083. }