sta_ioctl.c 65 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478
  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 == MWIFIEX_BSS_MODE_INFRA) {
  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, MWIFIEX_BSS_MODE_INFRA);
  375. else
  376. i = mwifiex_find_bssid_in_list(priv,
  377. (u8 *) &ssid_bssid->bssid,
  378. MWIFIEX_BSS_MODE_INFRA);
  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. MWIFIEX_BSS_MODE_IBSS);
  408. else
  409. i = mwifiex_find_bssid_in_list(priv,
  410. (u8 *)&ssid_bssid->bssid,
  411. MWIFIEX_BSS_MODE_IBSS);
  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. /* Radio status */
  697. info->radio_on = adapter->radio_on;
  698. /* Tx power information */
  699. info->max_power_level = priv->max_tx_power_level;
  700. info->min_power_level = priv->min_tx_power_level;
  701. /* AdHoc state */
  702. info->adhoc_state = priv->adhoc_state;
  703. /* Last beacon NF */
  704. info->bcn_nf_last = priv->bcn_nf_last;
  705. /* wep status */
  706. if (priv->sec_info.wep_status == MWIFIEX_802_11_WEP_ENABLED)
  707. info->wep_status = true;
  708. else
  709. info->wep_status = false;
  710. info->is_hs_configured = adapter->is_hs_configured;
  711. info->is_deep_sleep = adapter->is_deep_sleep;
  712. return 0;
  713. }
  714. /*
  715. * IOCTL request handler to get extended version information.
  716. *
  717. * This function prepares the correct firmware command and
  718. * issues it to get the extended version information.
  719. */
  720. static int mwifiex_get_info_ver_ext(struct mwifiex_private *priv,
  721. struct mwifiex_wait_queue *wait,
  722. struct mwifiex_ver_ext *ver_ext)
  723. {
  724. int ret = 0;
  725. /* Send request to firmware */
  726. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_VERSION_EXT,
  727. HostCmd_ACT_GEN_GET, 0, wait, ver_ext);
  728. if (!ret)
  729. ret = -EINPROGRESS;
  730. return ret;
  731. }
  732. /*
  733. * IOCTL request handler to set/get SNMP MIB parameters.
  734. *
  735. * This function prepares the correct firmware command and
  736. * issues it.
  737. *
  738. * Currently the following parameters are supported -
  739. * Set/get RTS Threshold
  740. * Set/get fragmentation threshold
  741. * Set/get retry count
  742. */
  743. int mwifiex_snmp_mib_ioctl(struct mwifiex_private *priv,
  744. struct mwifiex_wait_queue *wait,
  745. u32 cmd_oid, u16 action, u32 *value)
  746. {
  747. int ret = 0;
  748. if (!value)
  749. return -1;
  750. /* Send request to firmware */
  751. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
  752. action, cmd_oid, wait, value);
  753. if (!ret)
  754. ret = -EINPROGRESS;
  755. return ret;
  756. }
  757. /*
  758. * IOCTL request handler to set/get band configurations.
  759. *
  760. * For SET operation, it performs extra checks to make sure the Ad-Hoc
  761. * band and channel are compatible. Otherwise it returns an error.
  762. *
  763. * For GET operation, this function retrieves the following information -
  764. * - Infra bands
  765. * - Ad-hoc band
  766. * - Ad-hoc channel
  767. * - Secondary channel offset
  768. */
  769. int mwifiex_radio_ioctl_band_cfg(struct mwifiex_private *priv,
  770. u16 action,
  771. struct mwifiex_ds_band_cfg *radio_cfg)
  772. {
  773. struct mwifiex_adapter *adapter = priv->adapter;
  774. u8 infra_band = 0;
  775. u8 adhoc_band = 0;
  776. u32 adhoc_channel = 0;
  777. if (action == HostCmd_ACT_GEN_GET) {
  778. /* Infra Bands */
  779. radio_cfg->config_bands = adapter->config_bands;
  780. /* Adhoc Band */
  781. radio_cfg->adhoc_start_band = adapter->adhoc_start_band;
  782. /* Adhoc channel */
  783. radio_cfg->adhoc_channel = priv->adhoc_channel;
  784. /* Secondary channel offset */
  785. radio_cfg->sec_chan_offset = adapter->chan_offset;
  786. return 0;
  787. }
  788. /* For action = SET */
  789. infra_band = (u8) radio_cfg->config_bands;
  790. adhoc_band = (u8) radio_cfg->adhoc_start_band;
  791. adhoc_channel = radio_cfg->adhoc_channel;
  792. /* SET Infra band */
  793. if ((infra_band | adapter->fw_bands) & ~adapter->fw_bands)
  794. return -1;
  795. adapter->config_bands = infra_band;
  796. /* SET Ad-hoc Band */
  797. if ((adhoc_band | adapter->fw_bands) & ~adapter->fw_bands)
  798. return -1;
  799. if (adhoc_band)
  800. adapter->adhoc_start_band = adhoc_band;
  801. adapter->chan_offset = (u8) radio_cfg->sec_chan_offset;
  802. /*
  803. * If no adhoc_channel is supplied verify if the existing adhoc
  804. * channel compiles with new adhoc_band
  805. */
  806. if (!adhoc_channel) {
  807. if (!mwifiex_get_cfp_by_band_and_channel_from_cfg80211
  808. (priv, adapter->adhoc_start_band,
  809. priv->adhoc_channel)) {
  810. /* Pass back the default channel */
  811. radio_cfg->adhoc_channel = DEFAULT_AD_HOC_CHANNEL;
  812. if ((adapter->adhoc_start_band & BAND_A)
  813. || (adapter->adhoc_start_band & BAND_AN))
  814. radio_cfg->adhoc_channel =
  815. DEFAULT_AD_HOC_CHANNEL_A;
  816. }
  817. } else { /* Retrurn error if adhoc_band and
  818. adhoc_channel combination is invalid */
  819. if (!mwifiex_get_cfp_by_band_and_channel_from_cfg80211
  820. (priv, adapter->adhoc_start_band, (u16) adhoc_channel))
  821. return -1;
  822. priv->adhoc_channel = (u8) adhoc_channel;
  823. }
  824. if ((adhoc_band & BAND_GN) || (adhoc_band & BAND_AN))
  825. adapter->adhoc_11n_enabled = true;
  826. else
  827. adapter->adhoc_11n_enabled = false;
  828. return 0;
  829. }
  830. /*
  831. * IOCTL request handler to set/get active channel.
  832. *
  833. * This function performs validity checking on channel/frequency
  834. * compatibility and returns failure if not valid.
  835. */
  836. int mwifiex_bss_ioctl_channel(struct mwifiex_private *priv, u16 action,
  837. struct mwifiex_chan_freq_power *chan)
  838. {
  839. struct mwifiex_adapter *adapter = priv->adapter;
  840. struct mwifiex_chan_freq_power *cfp = NULL;
  841. if (!chan)
  842. return -1;
  843. if (action == HostCmd_ACT_GEN_GET) {
  844. cfp = mwifiex_get_cfp_by_band_and_channel_from_cfg80211(priv,
  845. priv->curr_bss_params.band,
  846. (u16) priv->curr_bss_params.bss_descriptor.
  847. channel);
  848. chan->channel = cfp->channel;
  849. chan->freq = cfp->freq;
  850. return 0;
  851. }
  852. if (!chan->channel && !chan->freq)
  853. return -1;
  854. if (adapter->adhoc_start_band & BAND_AN)
  855. adapter->adhoc_start_band = BAND_G | BAND_B | BAND_GN;
  856. else if (adapter->adhoc_start_band & BAND_A)
  857. adapter->adhoc_start_band = BAND_G | BAND_B;
  858. if (chan->channel) {
  859. if (chan->channel <= MAX_CHANNEL_BAND_BG)
  860. cfp = mwifiex_get_cfp_by_band_and_channel_from_cfg80211
  861. (priv, 0, (u16) chan->channel);
  862. if (!cfp) {
  863. cfp = mwifiex_get_cfp_by_band_and_channel_from_cfg80211
  864. (priv, BAND_A, (u16) chan->channel);
  865. if (cfp) {
  866. if (adapter->adhoc_11n_enabled)
  867. adapter->adhoc_start_band = BAND_A
  868. | BAND_AN;
  869. else
  870. adapter->adhoc_start_band = BAND_A;
  871. }
  872. }
  873. } else {
  874. if (chan->freq <= MAX_FREQUENCY_BAND_BG)
  875. cfp = mwifiex_get_cfp_by_band_and_freq_from_cfg80211(
  876. priv, 0, chan->freq);
  877. if (!cfp) {
  878. cfp = mwifiex_get_cfp_by_band_and_freq_from_cfg80211
  879. (priv, BAND_A, chan->freq);
  880. if (cfp) {
  881. if (adapter->adhoc_11n_enabled)
  882. adapter->adhoc_start_band = BAND_A
  883. | BAND_AN;
  884. else
  885. adapter->adhoc_start_band = BAND_A;
  886. }
  887. }
  888. }
  889. if (!cfp || !cfp->channel) {
  890. dev_err(adapter->dev, "invalid channel/freq\n");
  891. return -1;
  892. }
  893. priv->adhoc_channel = (u8) cfp->channel;
  894. chan->channel = cfp->channel;
  895. chan->freq = cfp->freq;
  896. return 0;
  897. }
  898. /*
  899. * IOCTL request handler to set/get BSS mode.
  900. *
  901. * This function prepares the correct firmware command and
  902. * issues it to set or get the BSS mode.
  903. *
  904. * In case the mode is changed, a deauthentication is performed
  905. * first by the function automatically.
  906. */
  907. int mwifiex_bss_ioctl_mode(struct mwifiex_private *priv,
  908. struct mwifiex_wait_queue *wait,
  909. u16 action, int *mode)
  910. {
  911. int ret = 0;
  912. if (!mode)
  913. return -1;
  914. if (action == HostCmd_ACT_GEN_GET) {
  915. *mode = priv->bss_mode;
  916. return 0;
  917. }
  918. if ((priv->bss_mode == *mode) || (*mode == MWIFIEX_BSS_MODE_AUTO)) {
  919. dev_dbg(priv->adapter->dev,
  920. "info: Already set to required mode! No change!\n");
  921. priv->bss_mode = *mode;
  922. return 0;
  923. }
  924. ret = mwifiex_deauthenticate(priv, wait, NULL);
  925. priv->sec_info.authentication_mode = MWIFIEX_AUTH_MODE_OPEN;
  926. priv->bss_mode = *mode;
  927. if (priv->bss_mode != MWIFIEX_BSS_MODE_AUTO) {
  928. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
  929. HostCmd_ACT_GEN_SET, 0, wait, NULL);
  930. if (!ret)
  931. ret = -EINPROGRESS;
  932. }
  933. return ret;
  934. }
  935. /*
  936. * IOCTL request handler to set/get Ad-Hoc channel.
  937. *
  938. * This function prepares the correct firmware command and
  939. * issues it to set or get the ad-hoc channel.
  940. */
  941. static int mwifiex_bss_ioctl_ibss_channel(struct mwifiex_private *priv,
  942. struct mwifiex_wait_queue *wait,
  943. u16 action, u16 *channel)
  944. {
  945. int ret = 0;
  946. if (action == HostCmd_ACT_GEN_GET) {
  947. if (!priv->media_connected) {
  948. *channel = priv->adhoc_channel;
  949. return ret;
  950. }
  951. } else {
  952. priv->adhoc_channel = (u8) *channel;
  953. }
  954. /* Send request to firmware */
  955. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_802_11_RF_CHANNEL,
  956. action, 0, wait, channel);
  957. if (!ret)
  958. ret = -EINPROGRESS;
  959. return ret;
  960. }
  961. /*
  962. * IOCTL request handler to find a particular BSS.
  963. *
  964. * The BSS can be searched with either a BSSID or a SSID. If none of
  965. * these are provided, just the best BSS (best RSSI) is returned.
  966. */
  967. int mwifiex_bss_ioctl_find_bss(struct mwifiex_private *priv,
  968. struct mwifiex_wait_queue *wait,
  969. struct mwifiex_ssid_bssid *ssid_bssid)
  970. {
  971. struct mwifiex_adapter *adapter = priv->adapter;
  972. int ret = 0;
  973. struct mwifiex_bssdescriptor *bss_desc;
  974. u8 zero_mac[ETH_ALEN] = { 0, 0, 0, 0, 0, 0 };
  975. u8 mac[ETH_ALEN];
  976. int i = 0;
  977. if (memcmp(ssid_bssid->bssid, zero_mac, sizeof(zero_mac))) {
  978. i = mwifiex_find_bssid_in_list(priv,
  979. (u8 *) ssid_bssid->bssid,
  980. priv->bss_mode);
  981. if (i < 0) {
  982. memcpy(mac, ssid_bssid->bssid, sizeof(mac));
  983. dev_err(adapter->dev, "cannot find bssid %pM\n", mac);
  984. return -1;
  985. }
  986. bss_desc = &adapter->scan_table[i];
  987. memcpy(&ssid_bssid->ssid, &bss_desc->ssid,
  988. sizeof(struct mwifiex_802_11_ssid));
  989. } else if (ssid_bssid->ssid.ssid_len) {
  990. i = mwifiex_find_ssid_in_list(priv, &ssid_bssid->ssid, NULL,
  991. priv->bss_mode);
  992. if (i < 0) {
  993. dev_err(adapter->dev, "cannot find ssid %s\n",
  994. ssid_bssid->ssid.ssid);
  995. return -1;
  996. }
  997. bss_desc = &adapter->scan_table[i];
  998. memcpy(ssid_bssid->bssid, bss_desc->mac_address, ETH_ALEN);
  999. } else {
  1000. ret = mwifiex_find_best_network(priv, ssid_bssid);
  1001. }
  1002. return ret;
  1003. }
  1004. /*
  1005. * IOCTL request handler to change Ad-Hoc channel.
  1006. *
  1007. * This function allocates the IOCTL request buffer, fills it
  1008. * with requisite parameters and calls the IOCTL handler.
  1009. *
  1010. * The function follows the following steps to perform the change -
  1011. * - Get current IBSS information
  1012. * - Get current channel
  1013. * - If no change is required, return
  1014. * - If not connected, change channel and return
  1015. * - If connected,
  1016. * - Disconnect
  1017. * - Change channel
  1018. * - Perform specific SSID scan with same SSID
  1019. * - Start/Join the IBSS
  1020. */
  1021. int
  1022. mwifiex_drv_change_adhoc_chan(struct mwifiex_private *priv, int channel)
  1023. {
  1024. int ret = 0;
  1025. int status = 0;
  1026. struct mwifiex_bss_info bss_info;
  1027. struct mwifiex_wait_queue *wait = NULL;
  1028. u8 wait_option = MWIFIEX_IOCTL_WAIT;
  1029. struct mwifiex_ssid_bssid ssid_bssid;
  1030. u16 curr_chan = 0;
  1031. memset(&bss_info, 0, sizeof(bss_info));
  1032. /* Get BSS information */
  1033. if (mwifiex_get_bss_info(priv, &bss_info))
  1034. return -1;
  1035. /* Allocate wait buffer */
  1036. wait = mwifiex_alloc_fill_wait_queue(priv, wait_option);
  1037. if (!wait)
  1038. return -ENOMEM;
  1039. /* Get current channel */
  1040. status = mwifiex_bss_ioctl_ibss_channel(priv, wait, HostCmd_ACT_GEN_GET,
  1041. &curr_chan);
  1042. if (mwifiex_request_ioctl(priv, wait, status, wait_option)) {
  1043. ret = -1;
  1044. goto done;
  1045. }
  1046. if (curr_chan == channel) {
  1047. ret = 0;
  1048. goto done;
  1049. }
  1050. dev_dbg(priv->adapter->dev, "cmd: updating channel from %d to %d\n",
  1051. curr_chan, channel);
  1052. if (!bss_info.media_connected) {
  1053. ret = 0;
  1054. goto done;
  1055. }
  1056. /* Do disonnect */
  1057. memset(&ssid_bssid, 0, ETH_ALEN);
  1058. status = mwifiex_bss_ioctl_stop(priv, wait, ssid_bssid.bssid);
  1059. if (mwifiex_request_ioctl(priv, wait, status, wait_option)) {
  1060. ret = -1;
  1061. goto done;
  1062. }
  1063. status = mwifiex_bss_ioctl_ibss_channel(priv, wait, HostCmd_ACT_GEN_SET,
  1064. (u16 *) &channel);
  1065. if (mwifiex_request_ioctl(priv, wait, status, wait_option)) {
  1066. ret = -1;
  1067. goto done;
  1068. }
  1069. /* Do specific SSID scanning */
  1070. if (mwifiex_request_scan(priv, wait_option, &bss_info.ssid)) {
  1071. ret = -1;
  1072. goto done;
  1073. }
  1074. /* Start/Join Adhoc network */
  1075. memset(&ssid_bssid, 0, sizeof(struct mwifiex_ssid_bssid));
  1076. memcpy(&ssid_bssid.ssid, &bss_info.ssid,
  1077. sizeof(struct mwifiex_802_11_ssid));
  1078. status = mwifiex_bss_ioctl_start(priv, wait, &ssid_bssid);
  1079. if (mwifiex_request_ioctl(priv, wait, status, wait_option))
  1080. ret = -1;
  1081. done:
  1082. kfree(wait);
  1083. return ret;
  1084. }
  1085. /*
  1086. * IOCTL request handler to get current driver mode.
  1087. *
  1088. * This function allocates the IOCTL request buffer, fills it
  1089. * with requisite parameters and calls the IOCTL handler.
  1090. */
  1091. int
  1092. mwifiex_drv_get_mode(struct mwifiex_private *priv, u8 wait_option)
  1093. {
  1094. struct mwifiex_wait_queue *wait = NULL;
  1095. int status = 0;
  1096. int mode = -1;
  1097. /* Allocate wait buffer */
  1098. wait = mwifiex_alloc_fill_wait_queue(priv, wait_option);
  1099. if (!wait)
  1100. return -1;
  1101. status = mwifiex_bss_ioctl_mode(priv, wait, HostCmd_ACT_GEN_GET, &mode);
  1102. status = mwifiex_request_ioctl(priv, wait, status, wait_option);
  1103. if (wait && (status != -EINPROGRESS))
  1104. kfree(wait);
  1105. return mode;
  1106. }
  1107. /*
  1108. * IOCTL request handler to get rate.
  1109. *
  1110. * This function prepares the correct firmware command and
  1111. * issues it to get the current rate if it is connected,
  1112. * otherwise, the function returns the lowest supported rate
  1113. * for the band.
  1114. */
  1115. static int mwifiex_rate_ioctl_get_rate_value(struct mwifiex_private *priv,
  1116. struct mwifiex_wait_queue *wait,
  1117. struct mwifiex_rate_cfg *rate_cfg)
  1118. {
  1119. struct mwifiex_adapter *adapter = priv->adapter;
  1120. int ret = 0;
  1121. rate_cfg->is_rate_auto = priv->is_data_rate_auto;
  1122. if (!priv->media_connected) {
  1123. switch (adapter->config_bands) {
  1124. case BAND_B:
  1125. /* Return the lowest supported rate for B band */
  1126. rate_cfg->rate = supported_rates_b[0] & 0x7f;
  1127. break;
  1128. case BAND_G:
  1129. case BAND_G | BAND_GN:
  1130. /* Return the lowest supported rate for G band */
  1131. rate_cfg->rate = supported_rates_g[0] & 0x7f;
  1132. break;
  1133. case BAND_B | BAND_G:
  1134. case BAND_A | BAND_B | BAND_G:
  1135. case BAND_A | BAND_B:
  1136. case BAND_A | BAND_B | BAND_G | BAND_AN | BAND_GN:
  1137. case BAND_B | BAND_G | BAND_GN:
  1138. /* Return the lowest supported rate for BG band */
  1139. rate_cfg->rate = supported_rates_bg[0] & 0x7f;
  1140. break;
  1141. case BAND_A:
  1142. case BAND_A | BAND_G:
  1143. case BAND_A | BAND_G | BAND_AN | BAND_GN:
  1144. case BAND_A | BAND_AN:
  1145. /* Return the lowest supported rate for A band */
  1146. rate_cfg->rate = supported_rates_a[0] & 0x7f;
  1147. break;
  1148. case BAND_GN:
  1149. /* Return the lowest supported rate for N band */
  1150. rate_cfg->rate = supported_rates_n[0] & 0x7f;
  1151. break;
  1152. default:
  1153. dev_warn(adapter->dev, "invalid band %#x\n",
  1154. adapter->config_bands);
  1155. break;
  1156. }
  1157. } else {
  1158. /* Send request to firmware */
  1159. ret = mwifiex_prepare_cmd(priv,
  1160. HostCmd_CMD_802_11_TX_RATE_QUERY,
  1161. HostCmd_ACT_GEN_GET, 0, wait, NULL);
  1162. if (!ret)
  1163. ret = -EINPROGRESS;
  1164. }
  1165. return ret;
  1166. }
  1167. /*
  1168. * IOCTL request handler to set rate.
  1169. *
  1170. * This function prepares the correct firmware command and
  1171. * issues it to set the current rate.
  1172. *
  1173. * The function also performs validation checking on the supplied value.
  1174. */
  1175. static int mwifiex_rate_ioctl_set_rate_value(struct mwifiex_private *priv,
  1176. struct mwifiex_wait_queue *wait,
  1177. struct mwifiex_rate_cfg *rate_cfg)
  1178. {
  1179. u8 rates[MWIFIEX_SUPPORTED_RATES];
  1180. u8 *rate = NULL;
  1181. int rate_index = 0;
  1182. u16 bitmap_rates[MAX_BITMAP_RATES_SIZE];
  1183. u32 i = 0;
  1184. int ret = 0;
  1185. struct mwifiex_adapter *adapter = priv->adapter;
  1186. if (rate_cfg->is_rate_auto) {
  1187. memset(bitmap_rates, 0, sizeof(bitmap_rates));
  1188. /* Support all HR/DSSS rates */
  1189. bitmap_rates[0] = 0x000F;
  1190. /* Support all OFDM rates */
  1191. bitmap_rates[1] = 0x00FF;
  1192. /* Support all HT-MCSs rate */
  1193. for (i = 0; i < ARRAY_SIZE(priv->bitmap_rates) - 3; i++)
  1194. bitmap_rates[i + 2] = 0xFFFF;
  1195. bitmap_rates[9] = 0x3FFF;
  1196. } else {
  1197. memset(rates, 0, sizeof(rates));
  1198. mwifiex_get_active_data_rates(priv, rates);
  1199. rate = rates;
  1200. for (i = 0; (rate[i] && i < MWIFIEX_SUPPORTED_RATES); i++) {
  1201. dev_dbg(adapter->dev, "info: rate=%#x wanted=%#x\n",
  1202. rate[i], rate_cfg->rate);
  1203. if ((rate[i] & 0x7f) == (rate_cfg->rate & 0x7f))
  1204. break;
  1205. }
  1206. if (!rate[i] || (i == MWIFIEX_SUPPORTED_RATES)) {
  1207. dev_err(adapter->dev, "fixed data rate %#x is out "
  1208. "of range\n", rate_cfg->rate);
  1209. return -1;
  1210. }
  1211. memset(bitmap_rates, 0, sizeof(bitmap_rates));
  1212. rate_index =
  1213. mwifiex_data_rate_to_index(adapter, rate_cfg->rate);
  1214. /* Only allow b/g rates to be set */
  1215. if (rate_index >= MWIFIEX_RATE_INDEX_HRDSSS0 &&
  1216. rate_index <= MWIFIEX_RATE_INDEX_HRDSSS3) {
  1217. bitmap_rates[0] = 1 << rate_index;
  1218. } else {
  1219. rate_index -= 1; /* There is a 0x00 in the table */
  1220. if (rate_index >= MWIFIEX_RATE_INDEX_OFDM0 &&
  1221. rate_index <= MWIFIEX_RATE_INDEX_OFDM7)
  1222. bitmap_rates[1] = 1 << (rate_index -
  1223. MWIFIEX_RATE_INDEX_OFDM0);
  1224. }
  1225. }
  1226. /* Send request to firmware */
  1227. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_TX_RATE_CFG,
  1228. HostCmd_ACT_GEN_SET, 0, wait, bitmap_rates);
  1229. if (!ret)
  1230. ret = -EINPROGRESS;
  1231. return ret;
  1232. }
  1233. /*
  1234. * IOCTL request handler to set/get rate.
  1235. *
  1236. * This function can be used to set/get either the rate value or the
  1237. * rate index.
  1238. */
  1239. static int mwifiex_rate_ioctl_cfg(struct mwifiex_private *priv,
  1240. struct mwifiex_wait_queue *wait,
  1241. struct mwifiex_rate_cfg *rate_cfg)
  1242. {
  1243. int status = 0;
  1244. if (!rate_cfg)
  1245. return -1;
  1246. if (rate_cfg->action == HostCmd_ACT_GEN_GET)
  1247. status = mwifiex_rate_ioctl_get_rate_value(
  1248. priv, wait, rate_cfg);
  1249. else
  1250. status = mwifiex_rate_ioctl_set_rate_value(
  1251. priv, wait, rate_cfg);
  1252. return status;
  1253. }
  1254. /*
  1255. * Sends IOCTL request to get the data rate.
  1256. *
  1257. * This function allocates the IOCTL request buffer, fills it
  1258. * with requisite parameters and calls the IOCTL handler.
  1259. */
  1260. int mwifiex_drv_get_data_rate(struct mwifiex_private *priv,
  1261. struct mwifiex_rate_cfg *rate)
  1262. {
  1263. int ret = 0;
  1264. struct mwifiex_wait_queue *wait = NULL;
  1265. u8 wait_option = MWIFIEX_IOCTL_WAIT;
  1266. /* Allocate wait buffer */
  1267. wait = mwifiex_alloc_fill_wait_queue(priv, wait_option);
  1268. if (!wait)
  1269. return -ENOMEM;
  1270. memset(rate, 0, sizeof(struct mwifiex_rate_cfg));
  1271. rate->action = HostCmd_ACT_GEN_GET;
  1272. ret = mwifiex_rate_ioctl_cfg(priv, wait, rate);
  1273. ret = mwifiex_request_ioctl(priv, wait, ret, wait_option);
  1274. if (!ret) {
  1275. if (rate && rate->is_rate_auto)
  1276. rate->rate = mwifiex_index_to_data_rate(priv->adapter,
  1277. priv->tx_rate, priv->tx_htinfo);
  1278. else if (rate)
  1279. rate->rate = priv->data_rate;
  1280. } else {
  1281. ret = -1;
  1282. }
  1283. kfree(wait);
  1284. return ret;
  1285. }
  1286. /*
  1287. * IOCTL request handler to set tx power configuration.
  1288. *
  1289. * This function prepares the correct firmware command and
  1290. * issues it.
  1291. *
  1292. * For non-auto power mode, all the following power groups are set -
  1293. * - Modulation class HR/DSSS
  1294. * - Modulation class OFDM
  1295. * - Modulation class HTBW20
  1296. * - Modulation class HTBW40
  1297. */
  1298. static int mwifiex_power_ioctl_set_power(struct mwifiex_private *priv,
  1299. struct mwifiex_wait_queue *wait,
  1300. struct mwifiex_power_cfg *power_cfg)
  1301. {
  1302. int ret = 0;
  1303. struct host_cmd_ds_txpwr_cfg *txp_cfg = NULL;
  1304. struct mwifiex_types_power_group *pg_tlv = NULL;
  1305. struct mwifiex_power_group *pg = NULL;
  1306. u8 *buf = NULL;
  1307. u16 dbm = 0;
  1308. if (!power_cfg->is_power_auto) {
  1309. dbm = (u16) power_cfg->power_level;
  1310. if ((dbm < priv->min_tx_power_level) ||
  1311. (dbm > priv->max_tx_power_level)) {
  1312. dev_err(priv->adapter->dev, "txpower value %d dBm"
  1313. " is out of range (%d dBm-%d dBm)\n",
  1314. dbm, priv->min_tx_power_level,
  1315. priv->max_tx_power_level);
  1316. return -1;
  1317. }
  1318. }
  1319. buf = kzalloc(MWIFIEX_SIZE_OF_CMD_BUFFER, GFP_KERNEL);
  1320. if (!buf) {
  1321. dev_err(priv->adapter->dev, "%s: failed to alloc cmd buffer\n",
  1322. __func__);
  1323. return -1;
  1324. }
  1325. txp_cfg = (struct host_cmd_ds_txpwr_cfg *) buf;
  1326. txp_cfg->action = cpu_to_le16(HostCmd_ACT_GEN_SET);
  1327. if (!power_cfg->is_power_auto) {
  1328. txp_cfg->mode = cpu_to_le32(1);
  1329. pg_tlv = (struct mwifiex_types_power_group *) (buf +
  1330. sizeof(struct host_cmd_ds_txpwr_cfg));
  1331. pg_tlv->type = TLV_TYPE_POWER_GROUP;
  1332. pg_tlv->length = 4 * sizeof(struct mwifiex_power_group);
  1333. pg = (struct mwifiex_power_group *) (buf +
  1334. sizeof(struct host_cmd_ds_txpwr_cfg) +
  1335. sizeof(struct mwifiex_types_power_group));
  1336. /* Power group for modulation class HR/DSSS */
  1337. pg->first_rate_code = 0x00;
  1338. pg->last_rate_code = 0x03;
  1339. pg->modulation_class = MOD_CLASS_HR_DSSS;
  1340. pg->power_step = 0;
  1341. pg->power_min = (s8) dbm;
  1342. pg->power_max = (s8) dbm;
  1343. pg++;
  1344. /* Power group for modulation class OFDM */
  1345. pg->first_rate_code = 0x00;
  1346. pg->last_rate_code = 0x07;
  1347. pg->modulation_class = MOD_CLASS_OFDM;
  1348. pg->power_step = 0;
  1349. pg->power_min = (s8) dbm;
  1350. pg->power_max = (s8) dbm;
  1351. pg++;
  1352. /* Power group for modulation class HTBW20 */
  1353. pg->first_rate_code = 0x00;
  1354. pg->last_rate_code = 0x20;
  1355. pg->modulation_class = MOD_CLASS_HT;
  1356. pg->power_step = 0;
  1357. pg->power_min = (s8) dbm;
  1358. pg->power_max = (s8) dbm;
  1359. pg->ht_bandwidth = HT_BW_20;
  1360. pg++;
  1361. /* Power group for modulation class HTBW40 */
  1362. pg->first_rate_code = 0x00;
  1363. pg->last_rate_code = 0x20;
  1364. pg->modulation_class = MOD_CLASS_HT;
  1365. pg->power_step = 0;
  1366. pg->power_min = (s8) dbm;
  1367. pg->power_max = (s8) dbm;
  1368. pg->ht_bandwidth = HT_BW_40;
  1369. }
  1370. /* Send request to firmware */
  1371. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_TXPWR_CFG,
  1372. HostCmd_ACT_GEN_SET, 0, wait, buf);
  1373. if (!ret)
  1374. ret = -EINPROGRESS;
  1375. kfree(buf);
  1376. return ret;
  1377. }
  1378. /*
  1379. * IOCTL request handler to get power save mode.
  1380. *
  1381. * This function prepares the correct firmware command and
  1382. * issues it.
  1383. */
  1384. static int mwifiex_pm_ioctl_ps_mode(struct mwifiex_private *priv,
  1385. struct mwifiex_wait_queue *wait,
  1386. u32 *ps_mode, u16 action)
  1387. {
  1388. int ret = 0;
  1389. struct mwifiex_adapter *adapter = priv->adapter;
  1390. u16 sub_cmd;
  1391. if (action == HostCmd_ACT_GEN_SET) {
  1392. if (*ps_mode)
  1393. adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
  1394. else
  1395. adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM;
  1396. sub_cmd = (*ps_mode) ? EN_AUTO_PS : DIS_AUTO_PS;
  1397. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
  1398. sub_cmd, BITMAP_STA_PS, wait, NULL);
  1399. if ((!ret) && (sub_cmd == DIS_AUTO_PS))
  1400. ret = mwifiex_prepare_cmd(priv,
  1401. HostCmd_CMD_802_11_PS_MODE_ENH, GET_PS,
  1402. 0, NULL, NULL);
  1403. } else {
  1404. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
  1405. GET_PS, 0, wait, NULL);
  1406. }
  1407. if (!ret)
  1408. ret = -EINPROGRESS;
  1409. return ret;
  1410. }
  1411. /*
  1412. * IOCTL request handler to set/reset WPA IE.
  1413. *
  1414. * The supplied WPA IE is treated as a opaque buffer. Only the first field
  1415. * is checked to determine WPA version. If buffer length is zero, the existing
  1416. * WPA IE is reset.
  1417. */
  1418. static int mwifiex_set_wpa_ie_helper(struct mwifiex_private *priv,
  1419. u8 *ie_data_ptr, u16 ie_len)
  1420. {
  1421. if (ie_len) {
  1422. if (ie_len > sizeof(priv->wpa_ie)) {
  1423. dev_err(priv->adapter->dev,
  1424. "failed to copy WPA IE, too big\n");
  1425. return -1;
  1426. }
  1427. memcpy(priv->wpa_ie, ie_data_ptr, ie_len);
  1428. priv->wpa_ie_len = (u8) ie_len;
  1429. dev_dbg(priv->adapter->dev, "cmd: Set Wpa_ie_len=%d IE=%#x\n",
  1430. priv->wpa_ie_len, priv->wpa_ie[0]);
  1431. if (priv->wpa_ie[0] == WLAN_EID_WPA) {
  1432. priv->sec_info.wpa_enabled = true;
  1433. } else if (priv->wpa_ie[0] == WLAN_EID_RSN) {
  1434. priv->sec_info.wpa2_enabled = true;
  1435. } else {
  1436. priv->sec_info.wpa_enabled = false;
  1437. priv->sec_info.wpa2_enabled = false;
  1438. }
  1439. } else {
  1440. memset(priv->wpa_ie, 0, sizeof(priv->wpa_ie));
  1441. priv->wpa_ie_len = 0;
  1442. dev_dbg(priv->adapter->dev, "info: reset wpa_ie_len=%d IE=%#x\n",
  1443. priv->wpa_ie_len, priv->wpa_ie[0]);
  1444. priv->sec_info.wpa_enabled = false;
  1445. priv->sec_info.wpa2_enabled = false;
  1446. }
  1447. return 0;
  1448. }
  1449. /*
  1450. * IOCTL request handler to set/reset WAPI IE.
  1451. *
  1452. * The supplied WAPI IE is treated as a opaque buffer. Only the first field
  1453. * is checked to internally enable WAPI. If buffer length is zero, the existing
  1454. * WAPI IE is reset.
  1455. */
  1456. static int mwifiex_set_wapi_ie(struct mwifiex_private *priv,
  1457. u8 *ie_data_ptr, u16 ie_len)
  1458. {
  1459. if (ie_len) {
  1460. if (ie_len > sizeof(priv->wapi_ie)) {
  1461. dev_dbg(priv->adapter->dev,
  1462. "info: failed to copy WAPI IE, too big\n");
  1463. return -1;
  1464. }
  1465. memcpy(priv->wapi_ie, ie_data_ptr, ie_len);
  1466. priv->wapi_ie_len = ie_len;
  1467. dev_dbg(priv->adapter->dev, "cmd: Set wapi_ie_len=%d IE=%#x\n",
  1468. priv->wapi_ie_len, priv->wapi_ie[0]);
  1469. if (priv->wapi_ie[0] == WLAN_EID_BSS_AC_ACCESS_DELAY)
  1470. priv->sec_info.wapi_enabled = true;
  1471. } else {
  1472. memset(priv->wapi_ie, 0, sizeof(priv->wapi_ie));
  1473. priv->wapi_ie_len = ie_len;
  1474. dev_dbg(priv->adapter->dev,
  1475. "info: Reset wapi_ie_len=%d IE=%#x\n",
  1476. priv->wapi_ie_len, priv->wapi_ie[0]);
  1477. priv->sec_info.wapi_enabled = false;
  1478. }
  1479. return 0;
  1480. }
  1481. /*
  1482. * IOCTL request handler to set WAPI key.
  1483. *
  1484. * This function prepares the correct firmware command and
  1485. * issues it.
  1486. */
  1487. static int mwifiex_sec_ioctl_set_wapi_key(struct mwifiex_adapter *adapter,
  1488. struct mwifiex_wait_queue *wait,
  1489. struct mwifiex_ds_encrypt_key *encrypt_key)
  1490. {
  1491. int ret = 0;
  1492. struct mwifiex_private *priv = adapter->priv[wait->bss_index];
  1493. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
  1494. HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
  1495. wait, encrypt_key);
  1496. if (!ret)
  1497. ret = -EINPROGRESS;
  1498. return ret;
  1499. }
  1500. /*
  1501. * IOCTL request handler to set/get authentication mode.
  1502. */
  1503. static int mwifiex_set_auth_mode(struct mwifiex_private *priv, u32 auth_mode)
  1504. {
  1505. int ret = 0;
  1506. priv->sec_info.authentication_mode = auth_mode;
  1507. if (priv->sec_info.authentication_mode == MWIFIEX_AUTH_MODE_NETWORKEAP)
  1508. ret = mwifiex_set_wpa_ie_helper(priv, NULL, 0);
  1509. return ret;
  1510. }
  1511. /*
  1512. * IOCTL request handler to set WEP network key.
  1513. *
  1514. * This function prepares the correct firmware command and
  1515. * issues it, after validation checks.
  1516. */
  1517. static int mwifiex_sec_ioctl_set_wep_key(struct mwifiex_adapter *adapter,
  1518. struct mwifiex_wait_queue *wait,
  1519. struct mwifiex_ds_encrypt_key *encrypt_key)
  1520. {
  1521. int ret = 0;
  1522. struct mwifiex_private *priv = adapter->priv[wait->bss_index];
  1523. struct mwifiex_wep_key *wep_key = NULL;
  1524. int index;
  1525. if (priv->wep_key_curr_index >= NUM_WEP_KEYS)
  1526. priv->wep_key_curr_index = 0;
  1527. wep_key = &priv->wep_key[priv->wep_key_curr_index];
  1528. index = encrypt_key->key_index;
  1529. if (encrypt_key->key_disable) {
  1530. priv->sec_info.wep_status = MWIFIEX_802_11_WEP_DISABLED;
  1531. } else if (!encrypt_key->key_len) {
  1532. /* Copy the required key as the current key */
  1533. wep_key = &priv->wep_key[index];
  1534. if (!wep_key->key_length) {
  1535. dev_err(adapter->dev,
  1536. "key not set, so cannot enable it\n");
  1537. return -1;
  1538. }
  1539. priv->wep_key_curr_index = (u16) index;
  1540. priv->sec_info.wep_status = MWIFIEX_802_11_WEP_ENABLED;
  1541. } else {
  1542. wep_key = &priv->wep_key[index];
  1543. /* Cleanup */
  1544. memset(wep_key, 0, sizeof(struct mwifiex_wep_key));
  1545. /* Copy the key in the driver */
  1546. memcpy(wep_key->key_material,
  1547. encrypt_key->key_material,
  1548. encrypt_key->key_len);
  1549. wep_key->key_index = index;
  1550. wep_key->key_length = encrypt_key->key_len;
  1551. priv->sec_info.wep_status = MWIFIEX_802_11_WEP_ENABLED;
  1552. }
  1553. if (wep_key->key_length) {
  1554. /* Send request to firmware */
  1555. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
  1556. HostCmd_ACT_GEN_SET, 0, NULL, NULL);
  1557. if (ret)
  1558. return ret;
  1559. }
  1560. if (priv->sec_info.wep_status == MWIFIEX_802_11_WEP_ENABLED)
  1561. priv->curr_pkt_filter |= HostCmd_ACT_MAC_WEP_ENABLE;
  1562. else
  1563. priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_WEP_ENABLE;
  1564. /* Send request to firmware */
  1565. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_MAC_CONTROL,
  1566. HostCmd_ACT_GEN_SET, 0, wait,
  1567. &priv->curr_pkt_filter);
  1568. if (!ret)
  1569. ret = -EINPROGRESS;
  1570. return ret;
  1571. }
  1572. /*
  1573. * IOCTL request handler to set WPA key.
  1574. *
  1575. * This function prepares the correct firmware command and
  1576. * issues it, after validation checks.
  1577. *
  1578. * Current driver only supports key length of up to 32 bytes.
  1579. *
  1580. * This function can also be used to disable a currently set key.
  1581. */
  1582. static int mwifiex_sec_ioctl_set_wpa_key(struct mwifiex_adapter *adapter,
  1583. struct mwifiex_wait_queue *wait,
  1584. struct mwifiex_ds_encrypt_key *encrypt_key)
  1585. {
  1586. int ret = 0;
  1587. struct mwifiex_private *priv = adapter->priv[wait->bss_index];
  1588. u8 remove_key = false;
  1589. struct host_cmd_ds_802_11_key_material *ibss_key;
  1590. /* Current driver only supports key length of up to 32 bytes */
  1591. if (encrypt_key->key_len > MWIFIEX_MAX_KEY_LENGTH) {
  1592. dev_err(adapter->dev, "key length too long\n");
  1593. return -1;
  1594. }
  1595. if (priv->bss_mode == MWIFIEX_BSS_MODE_IBSS) {
  1596. /*
  1597. * IBSS/WPA-None uses only one key (Group) for both receiving
  1598. * and sending unicast and multicast packets.
  1599. */
  1600. /* Send the key as PTK to firmware */
  1601. encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
  1602. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
  1603. HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
  1604. NULL, encrypt_key);
  1605. if (ret)
  1606. return ret;
  1607. ibss_key = &priv->aes_key;
  1608. memset(ibss_key, 0,
  1609. sizeof(struct host_cmd_ds_802_11_key_material));
  1610. /* Copy the key in the driver */
  1611. memcpy(ibss_key->key_param_set.key, encrypt_key->key_material,
  1612. encrypt_key->key_len);
  1613. memcpy(&ibss_key->key_param_set.key_len, &encrypt_key->key_len,
  1614. sizeof(ibss_key->key_param_set.key_len));
  1615. ibss_key->key_param_set.key_type_id
  1616. = cpu_to_le16(KEY_TYPE_ID_TKIP);
  1617. ibss_key->key_param_set.key_info
  1618. = cpu_to_le16(KEY_INFO_TKIP_ENABLED);
  1619. /* Send the key as GTK to firmware */
  1620. encrypt_key->key_index = ~MWIFIEX_KEY_INDEX_UNICAST;
  1621. }
  1622. if (!encrypt_key->key_index)
  1623. encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
  1624. if (remove_key)
  1625. /* Send request to firmware */
  1626. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
  1627. HostCmd_ACT_GEN_SET,
  1628. !(KEY_INFO_ENABLED),
  1629. wait, encrypt_key);
  1630. else
  1631. /* Send request to firmware */
  1632. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
  1633. HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
  1634. wait, encrypt_key);
  1635. if (!ret)
  1636. ret = -EINPROGRESS;
  1637. return ret;
  1638. }
  1639. /*
  1640. * IOCTL request handler to set/get network keys.
  1641. *
  1642. * This is a generic key handling function which supports WEP, WPA
  1643. * and WAPI.
  1644. */
  1645. static int
  1646. mwifiex_sec_ioctl_encrypt_key(struct mwifiex_private *priv,
  1647. struct mwifiex_wait_queue *wait,
  1648. struct mwifiex_ds_encrypt_key *encrypt_key)
  1649. {
  1650. int status = 0;
  1651. struct mwifiex_adapter *adapter = priv->adapter;
  1652. if (encrypt_key->is_wapi_key)
  1653. status = mwifiex_sec_ioctl_set_wapi_key(adapter, wait,
  1654. encrypt_key);
  1655. else if (encrypt_key->key_len > WLAN_KEY_LEN_WEP104)
  1656. status = mwifiex_sec_ioctl_set_wpa_key(adapter, wait,
  1657. encrypt_key);
  1658. else
  1659. status = mwifiex_sec_ioctl_set_wep_key(adapter, wait,
  1660. encrypt_key);
  1661. return status;
  1662. }
  1663. /*
  1664. * This function returns the driver version.
  1665. */
  1666. int
  1667. mwifiex_drv_get_driver_version(struct mwifiex_adapter *adapter, char *version,
  1668. int max_len)
  1669. {
  1670. union {
  1671. u32 l;
  1672. u8 c[4];
  1673. } ver;
  1674. char fw_ver[32];
  1675. ver.l = adapter->fw_release_number;
  1676. sprintf(fw_ver, "%u.%u.%u.p%u", ver.c[2], ver.c[1], ver.c[0], ver.c[3]);
  1677. snprintf(version, max_len, driver_version, fw_ver);
  1678. dev_dbg(adapter->dev, "info: MWIFIEX VERSION: %s\n", version);
  1679. return 0;
  1680. }
  1681. /*
  1682. * Sends IOCTL request to set Tx power. It can be set to either auto
  1683. * or a fixed value.
  1684. *
  1685. * This function allocates the IOCTL request buffer, fills it
  1686. * with requisite parameters and calls the IOCTL handler.
  1687. */
  1688. int
  1689. mwifiex_set_tx_power(struct mwifiex_private *priv, int type, int dbm)
  1690. {
  1691. struct mwifiex_power_cfg power_cfg;
  1692. struct mwifiex_wait_queue *wait = NULL;
  1693. int status = 0;
  1694. int ret = 0;
  1695. wait = mwifiex_alloc_fill_wait_queue(priv, MWIFIEX_IOCTL_WAIT);
  1696. if (!wait)
  1697. return -ENOMEM;
  1698. if (type == NL80211_TX_POWER_FIXED) {
  1699. power_cfg.is_power_auto = 0;
  1700. power_cfg.power_level = dbm;
  1701. } else {
  1702. power_cfg.is_power_auto = 1;
  1703. }
  1704. status = mwifiex_power_ioctl_set_power(priv, wait, &power_cfg);
  1705. ret = mwifiex_request_ioctl(priv, wait, status, MWIFIEX_IOCTL_WAIT);
  1706. kfree(wait);
  1707. return ret;
  1708. }
  1709. /*
  1710. * Sends IOCTL request to get scan table.
  1711. *
  1712. * This function allocates the IOCTL request buffer, fills it
  1713. * with requisite parameters and calls the IOCTL handler.
  1714. */
  1715. int mwifiex_get_scan_table(struct mwifiex_private *priv, u8 wait_option,
  1716. struct mwifiex_scan_resp *scan_resp)
  1717. {
  1718. struct mwifiex_wait_queue *wait = NULL;
  1719. struct mwifiex_scan_resp scan;
  1720. int status = 0;
  1721. /* Allocate wait buffer */
  1722. wait = mwifiex_alloc_fill_wait_queue(priv, wait_option);
  1723. if (!wait)
  1724. return -ENOMEM;
  1725. status = mwifiex_scan_networks(priv, wait, HostCmd_ACT_GEN_GET,
  1726. NULL, &scan);
  1727. status = mwifiex_request_ioctl(priv, wait, status, wait_option);
  1728. if (!status) {
  1729. if (scan_resp)
  1730. memcpy(scan_resp, &scan,
  1731. sizeof(struct mwifiex_scan_resp));
  1732. }
  1733. if (wait && (status != -EINPROGRESS))
  1734. kfree(wait);
  1735. return status;
  1736. }
  1737. /*
  1738. * Sends IOCTL request to get signal information.
  1739. *
  1740. * This function allocates the IOCTL request buffer, fills it
  1741. * with requisite parameters and calls the IOCTL handler.
  1742. */
  1743. int mwifiex_get_signal_info(struct mwifiex_private *priv, u8 wait_option,
  1744. struct mwifiex_ds_get_signal *signal)
  1745. {
  1746. struct mwifiex_ds_get_signal info;
  1747. struct mwifiex_wait_queue *wait = NULL;
  1748. int status = 0;
  1749. /* Allocate wait buffer */
  1750. wait = mwifiex_alloc_fill_wait_queue(priv, wait_option);
  1751. if (!wait)
  1752. return -ENOMEM;
  1753. info.selector = ALL_RSSI_INFO_MASK;
  1754. status = mwifiex_get_info_signal(priv, wait, &info);
  1755. status = mwifiex_request_ioctl(priv, wait, status, wait_option);
  1756. if (!status) {
  1757. if (signal)
  1758. memcpy(signal, &info,
  1759. sizeof(struct mwifiex_ds_get_signal));
  1760. if (info.selector & BCN_RSSI_AVG_MASK)
  1761. priv->w_stats.qual.level = info.bcn_rssi_avg;
  1762. if (info.selector & BCN_NF_AVG_MASK)
  1763. priv->w_stats.qual.noise = info.bcn_nf_avg;
  1764. }
  1765. if (wait && (status != -EINPROGRESS))
  1766. kfree(wait);
  1767. return status;
  1768. }
  1769. /*
  1770. * Sends IOCTL request to set encryption mode.
  1771. *
  1772. * This function allocates the IOCTL request buffer, fills it
  1773. * with requisite parameters and calls the IOCTL handler.
  1774. */
  1775. static int mwifiex_set_encrypt_mode(struct mwifiex_private *priv,
  1776. u8 wait_option, u32 encrypt_mode)
  1777. {
  1778. priv->sec_info.encryption_mode = encrypt_mode;
  1779. return 0;
  1780. }
  1781. /*
  1782. * This function set the authentication parameters. It sets both encryption
  1783. * mode and authentication mode, and also enables WPA if required.
  1784. */
  1785. int
  1786. mwifiex_set_auth(struct mwifiex_private *priv, int encrypt_mode,
  1787. int auth_mode, int wpa_enabled)
  1788. {
  1789. if (mwifiex_set_encrypt_mode(priv, MWIFIEX_IOCTL_WAIT, encrypt_mode))
  1790. return -EFAULT;
  1791. if (mwifiex_set_auth_mode(priv, auth_mode))
  1792. return -EFAULT;
  1793. return 0;
  1794. }
  1795. /*
  1796. * Sends IOCTL request to set encoding parameters.
  1797. *
  1798. * This function allocates the IOCTL request buffer, fills it
  1799. * with requisite parameters and calls the IOCTL handler.
  1800. */
  1801. int mwifiex_set_encode(struct mwifiex_private *priv, const u8 *key,
  1802. int key_len, u8 key_index, int disable)
  1803. {
  1804. struct mwifiex_wait_queue *wait = NULL;
  1805. struct mwifiex_ds_encrypt_key encrypt_key;
  1806. int status = 0;
  1807. int ret = 0;
  1808. wait = mwifiex_alloc_fill_wait_queue(priv, MWIFIEX_IOCTL_WAIT);
  1809. if (!wait)
  1810. return -ENOMEM;
  1811. memset(&encrypt_key, 0, sizeof(struct mwifiex_ds_encrypt_key));
  1812. encrypt_key.key_len = key_len;
  1813. if (!disable) {
  1814. encrypt_key.key_index = key_index;
  1815. if (key_len)
  1816. memcpy(encrypt_key.key_material, key, key_len);
  1817. } else {
  1818. encrypt_key.key_disable = true;
  1819. }
  1820. status = mwifiex_sec_ioctl_encrypt_key(priv, wait, &encrypt_key);
  1821. if (mwifiex_request_ioctl(priv, wait, status, MWIFIEX_IOCTL_WAIT))
  1822. ret = -EFAULT;
  1823. kfree(wait);
  1824. return ret;
  1825. }
  1826. /*
  1827. * Sends IOCTL request to set power management parameters.
  1828. *
  1829. * This function allocates the IOCTL request buffer, fills it
  1830. * with requisite parameters and calls the IOCTL handler.
  1831. */
  1832. int
  1833. mwifiex_drv_set_power(struct mwifiex_private *priv, bool power_on)
  1834. {
  1835. int ret = 0;
  1836. int status = 0;
  1837. struct mwifiex_wait_queue *wait = NULL;
  1838. u32 ps_mode;
  1839. wait = mwifiex_alloc_fill_wait_queue(priv, MWIFIEX_IOCTL_WAIT);
  1840. if (!wait)
  1841. return -ENOMEM;
  1842. ps_mode = power_on;
  1843. status = mwifiex_pm_ioctl_ps_mode(priv, wait, &ps_mode,
  1844. HostCmd_ACT_GEN_SET);
  1845. ret = mwifiex_request_ioctl(priv, wait, status, MWIFIEX_IOCTL_WAIT);
  1846. kfree(wait);
  1847. return ret;
  1848. }
  1849. /*
  1850. * Sends IOCTL request to get extended version.
  1851. *
  1852. * This function allocates the IOCTL request buffer, fills it
  1853. * with requisite parameters and calls the IOCTL handler.
  1854. */
  1855. int
  1856. mwifiex_get_ver_ext(struct mwifiex_private *priv)
  1857. {
  1858. struct mwifiex_ver_ext ver_ext;
  1859. struct mwifiex_wait_queue *wait = NULL;
  1860. int status = 0;
  1861. int ret = 0;
  1862. u8 wait_option = MWIFIEX_IOCTL_WAIT;
  1863. /* Allocate wait buffer */
  1864. wait = mwifiex_alloc_fill_wait_queue(priv, wait_option);
  1865. if (!wait)
  1866. return -ENOMEM;
  1867. /* get fw version */
  1868. memset(&ver_ext, 0, sizeof(struct host_cmd_ds_version_ext));
  1869. status = mwifiex_get_info_ver_ext(priv, wait, &ver_ext);
  1870. ret = mwifiex_request_ioctl(priv, wait, status, wait_option);
  1871. if (ret)
  1872. ret = -1;
  1873. kfree(wait);
  1874. return ret;
  1875. }
  1876. /*
  1877. * Sends IOCTL request to get statistics information.
  1878. *
  1879. * This function allocates the IOCTL request buffer, fills it
  1880. * with requisite parameters and calls the IOCTL handler.
  1881. */
  1882. int
  1883. mwifiex_get_stats_info(struct mwifiex_private *priv,
  1884. struct mwifiex_ds_get_stats *log)
  1885. {
  1886. int ret = 0;
  1887. int status = 0;
  1888. struct mwifiex_wait_queue *wait = NULL;
  1889. struct mwifiex_ds_get_stats get_log;
  1890. u8 wait_option = MWIFIEX_IOCTL_WAIT;
  1891. /* Allocate wait buffer */
  1892. wait = mwifiex_alloc_fill_wait_queue(priv, wait_option);
  1893. if (!wait)
  1894. return -ENOMEM;
  1895. memset(&get_log, 0, sizeof(struct mwifiex_ds_get_stats));
  1896. status = mwifiex_get_info_stats(priv, wait, &get_log);
  1897. /* Send IOCTL request to MWIFIEX */
  1898. ret = mwifiex_request_ioctl(priv, wait, status, wait_option);
  1899. if (!ret) {
  1900. if (log)
  1901. memcpy(log, &get_log, sizeof(struct
  1902. mwifiex_ds_get_stats));
  1903. priv->w_stats.discard.fragment = get_log.fcs_error;
  1904. priv->w_stats.discard.retries = get_log.retry;
  1905. priv->w_stats.discard.misc = get_log.ack_failure;
  1906. }
  1907. kfree(wait);
  1908. return ret;
  1909. }
  1910. /*
  1911. * IOCTL request handler to read/write register.
  1912. *
  1913. * This function prepares the correct firmware command and
  1914. * issues it.
  1915. *
  1916. * Access to the following registers are supported -
  1917. * - MAC
  1918. * - BBP
  1919. * - RF
  1920. * - PMIC
  1921. * - CAU
  1922. */
  1923. static int mwifiex_reg_mem_ioctl_reg_rw(struct mwifiex_private *priv,
  1924. struct mwifiex_wait_queue *wait,
  1925. struct mwifiex_ds_reg_rw *reg_rw,
  1926. u16 action)
  1927. {
  1928. int ret = 0;
  1929. u16 cmd_no;
  1930. switch (le32_to_cpu(reg_rw->type)) {
  1931. case MWIFIEX_REG_MAC:
  1932. cmd_no = HostCmd_CMD_MAC_REG_ACCESS;
  1933. break;
  1934. case MWIFIEX_REG_BBP:
  1935. cmd_no = HostCmd_CMD_BBP_REG_ACCESS;
  1936. break;
  1937. case MWIFIEX_REG_RF:
  1938. cmd_no = HostCmd_CMD_RF_REG_ACCESS;
  1939. break;
  1940. case MWIFIEX_REG_PMIC:
  1941. cmd_no = HostCmd_CMD_PMIC_REG_ACCESS;
  1942. break;
  1943. case MWIFIEX_REG_CAU:
  1944. cmd_no = HostCmd_CMD_CAU_REG_ACCESS;
  1945. break;
  1946. default:
  1947. return -1;
  1948. }
  1949. /* Send request to firmware */
  1950. ret = mwifiex_prepare_cmd(priv, cmd_no, action, 0, wait, reg_rw);
  1951. if (!ret)
  1952. ret = -EINPROGRESS;
  1953. return ret;
  1954. }
  1955. /*
  1956. * Sends IOCTL request to write to a register.
  1957. *
  1958. * This function allocates the IOCTL request buffer, fills it
  1959. * with requisite parameters and calls the IOCTL handler.
  1960. */
  1961. int
  1962. mwifiex_reg_write(struct mwifiex_private *priv, u32 reg_type,
  1963. u32 reg_offset, u32 reg_value)
  1964. {
  1965. int ret = 0;
  1966. int status = 0;
  1967. struct mwifiex_wait_queue *wait = NULL;
  1968. struct mwifiex_ds_reg_rw reg_rw;
  1969. wait = mwifiex_alloc_fill_wait_queue(priv, MWIFIEX_IOCTL_WAIT);
  1970. if (!wait)
  1971. return -ENOMEM;
  1972. reg_rw.type = cpu_to_le32(reg_type);
  1973. reg_rw.offset = cpu_to_le32(reg_offset);
  1974. reg_rw.value = cpu_to_le32(reg_value);
  1975. status = mwifiex_reg_mem_ioctl_reg_rw(priv, wait, &reg_rw,
  1976. HostCmd_ACT_GEN_SET);
  1977. ret = mwifiex_request_ioctl(priv, wait, status, MWIFIEX_IOCTL_WAIT);
  1978. kfree(wait);
  1979. return ret;
  1980. }
  1981. /*
  1982. * Sends IOCTL request to read from a register.
  1983. *
  1984. * This function allocates the IOCTL request buffer, fills it
  1985. * with requisite parameters and calls the IOCTL handler.
  1986. */
  1987. int
  1988. mwifiex_reg_read(struct mwifiex_private *priv, u32 reg_type,
  1989. u32 reg_offset, u32 *value)
  1990. {
  1991. int ret = 0;
  1992. int status = 0;
  1993. struct mwifiex_wait_queue *wait = NULL;
  1994. struct mwifiex_ds_reg_rw reg_rw;
  1995. wait = mwifiex_alloc_fill_wait_queue(priv, MWIFIEX_IOCTL_WAIT);
  1996. if (!wait)
  1997. return -ENOMEM;
  1998. reg_rw.type = cpu_to_le32(reg_type);
  1999. reg_rw.offset = cpu_to_le32(reg_offset);
  2000. status = mwifiex_reg_mem_ioctl_reg_rw(priv, wait, &reg_rw,
  2001. HostCmd_ACT_GEN_GET);
  2002. ret = mwifiex_request_ioctl(priv, wait, status, MWIFIEX_IOCTL_WAIT);
  2003. if (ret)
  2004. goto done;
  2005. *value = le32_to_cpu(reg_rw.value);
  2006. done:
  2007. kfree(wait);
  2008. return ret;
  2009. }
  2010. /*
  2011. * IOCTL request handler to read EEPROM.
  2012. *
  2013. * This function prepares the correct firmware command and
  2014. * issues it.
  2015. */
  2016. static int
  2017. mwifiex_reg_mem_ioctl_read_eeprom(struct mwifiex_private *priv,
  2018. struct mwifiex_wait_queue *wait,
  2019. struct mwifiex_ds_read_eeprom *rd_eeprom)
  2020. {
  2021. int ret = 0;
  2022. /* Send request to firmware */
  2023. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_802_11_EEPROM_ACCESS,
  2024. HostCmd_ACT_GEN_GET, 0, wait, rd_eeprom);
  2025. if (!ret)
  2026. ret = -EINPROGRESS;
  2027. return ret;
  2028. }
  2029. /*
  2030. * Sends IOCTL request to read from EEPROM.
  2031. *
  2032. * This function allocates the IOCTL request buffer, fills it
  2033. * with requisite parameters and calls the IOCTL handler.
  2034. */
  2035. int
  2036. mwifiex_eeprom_read(struct mwifiex_private *priv, u16 offset, u16 bytes,
  2037. u8 *value)
  2038. {
  2039. int ret = 0;
  2040. int status = 0;
  2041. struct mwifiex_wait_queue *wait = NULL;
  2042. struct mwifiex_ds_read_eeprom rd_eeprom;
  2043. wait = mwifiex_alloc_fill_wait_queue(priv, MWIFIEX_IOCTL_WAIT);
  2044. if (!wait)
  2045. return -ENOMEM;
  2046. rd_eeprom.offset = cpu_to_le16((u16) offset);
  2047. rd_eeprom.byte_count = cpu_to_le16((u16) bytes);
  2048. status = mwifiex_reg_mem_ioctl_read_eeprom(priv, wait, &rd_eeprom);
  2049. ret = mwifiex_request_ioctl(priv, wait, status, MWIFIEX_IOCTL_WAIT);
  2050. if (ret)
  2051. goto done;
  2052. memcpy(value, rd_eeprom.value, MAX_EEPROM_DATA);
  2053. done:
  2054. kfree(wait);
  2055. return ret;
  2056. }
  2057. /*
  2058. * This function sets a generic IE. In addition to generic IE, it can
  2059. * also handle WPA, WPA2 and WAPI IEs.
  2060. */
  2061. static int
  2062. mwifiex_set_gen_ie_helper(struct mwifiex_private *priv, u8 *ie_data_ptr,
  2063. u16 ie_len)
  2064. {
  2065. int ret = 0;
  2066. struct ieee_types_vendor_header *pvendor_ie;
  2067. const u8 wpa_oui[] = { 0x00, 0x50, 0xf2, 0x01 };
  2068. const u8 wps_oui[] = { 0x00, 0x50, 0xf2, 0x04 };
  2069. /* If the passed length is zero, reset the buffer */
  2070. if (!ie_len) {
  2071. priv->gen_ie_buf_len = 0;
  2072. priv->wps.session_enable = false;
  2073. return 0;
  2074. } else if (!ie_data_ptr) {
  2075. return -1;
  2076. }
  2077. pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
  2078. /* Test to see if it is a WPA IE, if not, then it is a gen IE */
  2079. if (((pvendor_ie->element_id == WLAN_EID_WPA)
  2080. && (!memcmp(pvendor_ie->oui, wpa_oui, sizeof(wpa_oui))))
  2081. || (pvendor_ie->element_id == WLAN_EID_RSN)) {
  2082. /* IE is a WPA/WPA2 IE so call set_wpa function */
  2083. ret = mwifiex_set_wpa_ie_helper(priv, ie_data_ptr, ie_len);
  2084. priv->wps.session_enable = false;
  2085. return ret;
  2086. } else if (pvendor_ie->element_id == WLAN_EID_BSS_AC_ACCESS_DELAY) {
  2087. /* IE is a WAPI IE so call set_wapi function */
  2088. ret = mwifiex_set_wapi_ie(priv, ie_data_ptr, ie_len);
  2089. return ret;
  2090. }
  2091. /*
  2092. * Verify that the passed length is not larger than the
  2093. * available space remaining in the buffer
  2094. */
  2095. if (ie_len < (sizeof(priv->gen_ie_buf) - priv->gen_ie_buf_len)) {
  2096. /* Test to see if it is a WPS IE, if so, enable
  2097. * wps session flag
  2098. */
  2099. pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
  2100. if ((pvendor_ie->element_id == WLAN_EID_VENDOR_SPECIFIC)
  2101. && (!memcmp(pvendor_ie->oui, wps_oui,
  2102. sizeof(wps_oui)))) {
  2103. priv->wps.session_enable = true;
  2104. dev_dbg(priv->adapter->dev,
  2105. "info: WPS Session Enabled.\n");
  2106. }
  2107. /* Append the passed data to the end of the
  2108. genIeBuffer */
  2109. memcpy(priv->gen_ie_buf + priv->gen_ie_buf_len, ie_data_ptr,
  2110. ie_len);
  2111. /* Increment the stored buffer length by the
  2112. size passed */
  2113. priv->gen_ie_buf_len += ie_len;
  2114. } else {
  2115. /* Passed data does not fit in the remaining
  2116. buffer space */
  2117. ret = -1;
  2118. }
  2119. /* Return 0, or -1 for error case */
  2120. return ret;
  2121. }
  2122. /*
  2123. * IOCTL request handler to set/get generic IE.
  2124. *
  2125. * In addition to various generic IEs, this function can also be
  2126. * used to set the ARP filter.
  2127. */
  2128. static int mwifiex_misc_ioctl_gen_ie(struct mwifiex_private *priv,
  2129. struct mwifiex_ds_misc_gen_ie *gen_ie,
  2130. u16 action)
  2131. {
  2132. struct mwifiex_adapter *adapter = priv->adapter;
  2133. switch (gen_ie->type) {
  2134. case MWIFIEX_IE_TYPE_GEN_IE:
  2135. if (action == HostCmd_ACT_GEN_GET) {
  2136. gen_ie->len = priv->wpa_ie_len;
  2137. memcpy(gen_ie->ie_data, priv->wpa_ie, gen_ie->len);
  2138. } else {
  2139. mwifiex_set_gen_ie_helper(priv, gen_ie->ie_data,
  2140. (u16) gen_ie->len);
  2141. }
  2142. break;
  2143. case MWIFIEX_IE_TYPE_ARP_FILTER:
  2144. memset(adapter->arp_filter, 0, sizeof(adapter->arp_filter));
  2145. if (gen_ie->len > ARP_FILTER_MAX_BUF_SIZE) {
  2146. adapter->arp_filter_size = 0;
  2147. dev_err(adapter->dev, "invalid ARP filter size\n");
  2148. return -1;
  2149. } else {
  2150. memcpy(adapter->arp_filter, gen_ie->ie_data,
  2151. gen_ie->len);
  2152. adapter->arp_filter_size = gen_ie->len;
  2153. }
  2154. break;
  2155. default:
  2156. dev_err(adapter->dev, "invalid IE type\n");
  2157. return -1;
  2158. }
  2159. return 0;
  2160. }
  2161. /*
  2162. * Sends IOCTL request to set a generic IE.
  2163. *
  2164. * This function allocates the IOCTL request buffer, fills it
  2165. * with requisite parameters and calls the IOCTL handler.
  2166. */
  2167. int
  2168. mwifiex_set_gen_ie(struct mwifiex_private *priv, u8 *ie, int ie_len)
  2169. {
  2170. struct mwifiex_ds_misc_gen_ie gen_ie;
  2171. int status = 0;
  2172. if (ie_len > IW_CUSTOM_MAX)
  2173. return -EFAULT;
  2174. gen_ie.type = MWIFIEX_IE_TYPE_GEN_IE;
  2175. gen_ie.len = ie_len;
  2176. memcpy(gen_ie.ie_data, ie, ie_len);
  2177. status = mwifiex_misc_ioctl_gen_ie(priv, &gen_ie, HostCmd_ACT_GEN_SET);
  2178. if (status)
  2179. return -EFAULT;
  2180. return 0;
  2181. }