prism2sta.c 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010
  1. // SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1)
  2. /* src/prism2/driver/prism2sta.c
  3. *
  4. * Implements the station functionality for prism2
  5. *
  6. * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved.
  7. * --------------------------------------------------------------------
  8. *
  9. * linux-wlan
  10. *
  11. * The contents of this file are subject to the Mozilla Public
  12. * License Version 1.1 (the "License"); you may not use this file
  13. * except in compliance with the License. You may obtain a copy of
  14. * the License at http://www.mozilla.org/MPL/
  15. *
  16. * Software distributed under the License is distributed on an "AS
  17. * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  18. * implied. See the License for the specific language governing
  19. * rights and limitations under the License.
  20. *
  21. * Alternatively, the contents of this file may be used under the
  22. * terms of the GNU Public License version 2 (the "GPL"), in which
  23. * case the provisions of the GPL are applicable instead of the
  24. * above. If you wish to allow the use of your version of this file
  25. * only under the terms of the GPL and not to allow others to use
  26. * your version of this file under the MPL, indicate your decision
  27. * by deleting the provisions above and replace them with the notice
  28. * and other provisions required by the GPL. If you do not delete
  29. * the provisions above, a recipient may use your version of this
  30. * file under either the MPL or the GPL.
  31. *
  32. * --------------------------------------------------------------------
  33. *
  34. * Inquiries regarding the linux-wlan Open Source project can be
  35. * made directly to:
  36. *
  37. * AbsoluteValue Systems Inc.
  38. * info@linux-wlan.com
  39. * http://www.linux-wlan.com
  40. *
  41. * --------------------------------------------------------------------
  42. *
  43. * Portions of the development of this software were funded by
  44. * Intersil Corporation as part of PRISM(R) chipset product development.
  45. *
  46. * --------------------------------------------------------------------
  47. *
  48. * This file implements the module and linux pcmcia routines for the
  49. * prism2 driver.
  50. *
  51. * --------------------------------------------------------------------
  52. */
  53. #include <linux/module.h>
  54. #include <linux/kernel.h>
  55. #include <linux/sched.h>
  56. #include <linux/types.h>
  57. #include <linux/slab.h>
  58. #include <linux/wireless.h>
  59. #include <linux/netdevice.h>
  60. #include <linux/workqueue.h>
  61. #include <linux/byteorder/generic.h>
  62. #include <linux/etherdevice.h>
  63. #include <linux/io.h>
  64. #include <linux/delay.h>
  65. #include <asm/byteorder.h>
  66. #include <linux/if_arp.h>
  67. #include <linux/if_ether.h>
  68. #include <linux/bitops.h>
  69. #include "p80211types.h"
  70. #include "p80211hdr.h"
  71. #include "p80211mgmt.h"
  72. #include "p80211conv.h"
  73. #include "p80211msg.h"
  74. #include "p80211netdev.h"
  75. #include "p80211req.h"
  76. #include "p80211metadef.h"
  77. #include "p80211metastruct.h"
  78. #include "hfa384x.h"
  79. #include "prism2mgmt.h"
  80. static char *dev_info = "prism2_usb";
  81. static struct wlandevice *create_wlan(void);
  82. int prism2_reset_holdtime = 30; /* Reset hold time in ms */
  83. int prism2_reset_settletime = 100; /* Reset settle time in ms */
  84. static int prism2_doreset; /* Do a reset at init? */
  85. module_param(prism2_doreset, int, 0644);
  86. MODULE_PARM_DESC(prism2_doreset, "Issue a reset on initialization");
  87. module_param(prism2_reset_holdtime, int, 0644);
  88. MODULE_PARM_DESC(prism2_reset_holdtime, "reset hold time in ms");
  89. module_param(prism2_reset_settletime, int, 0644);
  90. MODULE_PARM_DESC(prism2_reset_settletime, "reset settle time in ms");
  91. MODULE_LICENSE("Dual MPL/GPL");
  92. static int prism2sta_open(struct wlandevice *wlandev);
  93. static int prism2sta_close(struct wlandevice *wlandev);
  94. static void prism2sta_reset(struct wlandevice *wlandev);
  95. static int prism2sta_txframe(struct wlandevice *wlandev, struct sk_buff *skb,
  96. union p80211_hdr *p80211_hdr,
  97. struct p80211_metawep *p80211_wep);
  98. static int prism2sta_mlmerequest(struct wlandevice *wlandev,
  99. struct p80211msg *msg);
  100. static int prism2sta_getcardinfo(struct wlandevice *wlandev);
  101. static int prism2sta_globalsetup(struct wlandevice *wlandev);
  102. static int prism2sta_setmulticast(struct wlandevice *wlandev,
  103. struct net_device *dev);
  104. static void prism2sta_inf_handover(struct wlandevice *wlandev,
  105. struct hfa384x_inf_frame *inf);
  106. static void prism2sta_inf_tallies(struct wlandevice *wlandev,
  107. struct hfa384x_inf_frame *inf);
  108. static void prism2sta_inf_hostscanresults(struct wlandevice *wlandev,
  109. struct hfa384x_inf_frame *inf);
  110. static void prism2sta_inf_scanresults(struct wlandevice *wlandev,
  111. struct hfa384x_inf_frame *inf);
  112. static void prism2sta_inf_chinforesults(struct wlandevice *wlandev,
  113. struct hfa384x_inf_frame *inf);
  114. static void prism2sta_inf_linkstatus(struct wlandevice *wlandev,
  115. struct hfa384x_inf_frame *inf);
  116. static void prism2sta_inf_assocstatus(struct wlandevice *wlandev,
  117. struct hfa384x_inf_frame *inf);
  118. static void prism2sta_inf_authreq(struct wlandevice *wlandev,
  119. struct hfa384x_inf_frame *inf);
  120. static void prism2sta_inf_authreq_defer(struct wlandevice *wlandev,
  121. struct hfa384x_inf_frame *inf);
  122. static void prism2sta_inf_psusercnt(struct wlandevice *wlandev,
  123. struct hfa384x_inf_frame *inf);
  124. /*
  125. * prism2sta_open
  126. *
  127. * WLAN device open method. Called from p80211netdev when kernel
  128. * device open (start) method is called in response to the
  129. * SIOCSIIFFLAGS ioctl changing the flags bit IFF_UP
  130. * from clear to set.
  131. *
  132. * Arguments:
  133. * wlandev wlan device structure
  134. *
  135. * Returns:
  136. * 0 success
  137. * >0 f/w reported error
  138. * <0 driver reported error
  139. *
  140. * Side effects:
  141. *
  142. * Call context:
  143. * process thread
  144. */
  145. static int prism2sta_open(struct wlandevice *wlandev)
  146. {
  147. /* We don't currently have to do anything else.
  148. * The setup of the MAC should be subsequently completed via
  149. * the mlme commands.
  150. * Higher layers know we're ready from dev->start==1 and
  151. * dev->tbusy==0. Our rx path knows to pass up received/
  152. * frames because of dev->flags&IFF_UP is true.
  153. */
  154. return 0;
  155. }
  156. /*
  157. * prism2sta_close
  158. *
  159. * WLAN device close method. Called from p80211netdev when kernel
  160. * device close method is called in response to the
  161. * SIOCSIIFFLAGS ioctl changing the flags bit IFF_UP
  162. * from set to clear.
  163. *
  164. * Arguments:
  165. * wlandev wlan device structure
  166. *
  167. * Returns:
  168. * 0 success
  169. * >0 f/w reported error
  170. * <0 driver reported error
  171. *
  172. * Side effects:
  173. *
  174. * Call context:
  175. * process thread
  176. */
  177. static int prism2sta_close(struct wlandevice *wlandev)
  178. {
  179. /* We don't currently have to do anything else.
  180. * Higher layers know we're not ready from dev->start==0 and
  181. * dev->tbusy==1. Our rx path knows to not pass up received
  182. * frames because of dev->flags&IFF_UP is false.
  183. */
  184. return 0;
  185. }
  186. /*
  187. * prism2sta_reset
  188. *
  189. * Currently not implemented.
  190. *
  191. * Arguments:
  192. * wlandev wlan device structure
  193. * none
  194. *
  195. * Returns:
  196. * nothing
  197. *
  198. * Side effects:
  199. *
  200. * Call context:
  201. * process thread
  202. */
  203. static void prism2sta_reset(struct wlandevice *wlandev)
  204. {
  205. }
  206. /*
  207. * prism2sta_txframe
  208. *
  209. * Takes a frame from p80211 and queues it for transmission.
  210. *
  211. * Arguments:
  212. * wlandev wlan device structure
  213. * pb packet buffer struct. Contains an 802.11
  214. * data frame.
  215. * p80211_hdr points to the 802.11 header for the packet.
  216. * Returns:
  217. * 0 Success and more buffs available
  218. * 1 Success but no more buffs
  219. * 2 Allocation failure
  220. * 4 Buffer full or queue busy
  221. *
  222. * Side effects:
  223. *
  224. * Call context:
  225. * process thread
  226. */
  227. static int prism2sta_txframe(struct wlandevice *wlandev, struct sk_buff *skb,
  228. union p80211_hdr *p80211_hdr,
  229. struct p80211_metawep *p80211_wep)
  230. {
  231. struct hfa384x *hw = wlandev->priv;
  232. /* If necessary, set the 802.11 WEP bit */
  233. if ((wlandev->hostwep & (HOSTWEP_PRIVACYINVOKED | HOSTWEP_ENCRYPT)) ==
  234. HOSTWEP_PRIVACYINVOKED) {
  235. p80211_hdr->a3.fc |= cpu_to_le16(WLAN_SET_FC_ISWEP(1));
  236. }
  237. return hfa384x_drvr_txframe(hw, skb, p80211_hdr, p80211_wep);
  238. }
  239. /*
  240. * prism2sta_mlmerequest
  241. *
  242. * wlan command message handler. All we do here is pass the message
  243. * over to the prism2sta_mgmt_handler.
  244. *
  245. * Arguments:
  246. * wlandev wlan device structure
  247. * msg wlan command message
  248. * Returns:
  249. * 0 success
  250. * <0 successful acceptance of message, but we're
  251. * waiting for an async process to finish before
  252. * we're done with the msg. When the asynch
  253. * process is done, we'll call the p80211
  254. * function p80211req_confirm() .
  255. * >0 An error occurred while we were handling
  256. * the message.
  257. *
  258. * Side effects:
  259. *
  260. * Call context:
  261. * process thread
  262. */
  263. static int prism2sta_mlmerequest(struct wlandevice *wlandev,
  264. struct p80211msg *msg)
  265. {
  266. struct hfa384x *hw = wlandev->priv;
  267. int result = 0;
  268. switch (msg->msgcode) {
  269. case DIDmsg_dot11req_mibget:
  270. pr_debug("Received mibget request\n");
  271. result = prism2mgmt_mibset_mibget(wlandev, msg);
  272. break;
  273. case DIDmsg_dot11req_mibset:
  274. pr_debug("Received mibset request\n");
  275. result = prism2mgmt_mibset_mibget(wlandev, msg);
  276. break;
  277. case DIDmsg_dot11req_scan:
  278. pr_debug("Received scan request\n");
  279. result = prism2mgmt_scan(wlandev, msg);
  280. break;
  281. case DIDmsg_dot11req_scan_results:
  282. pr_debug("Received scan_results request\n");
  283. result = prism2mgmt_scan_results(wlandev, msg);
  284. break;
  285. case DIDmsg_dot11req_start:
  286. pr_debug("Received mlme start request\n");
  287. result = prism2mgmt_start(wlandev, msg);
  288. break;
  289. /*
  290. * Prism2 specific messages
  291. */
  292. case DIDmsg_p2req_readpda:
  293. pr_debug("Received mlme readpda request\n");
  294. result = prism2mgmt_readpda(wlandev, msg);
  295. break;
  296. case DIDmsg_p2req_ramdl_state:
  297. pr_debug("Received mlme ramdl_state request\n");
  298. result = prism2mgmt_ramdl_state(wlandev, msg);
  299. break;
  300. case DIDmsg_p2req_ramdl_write:
  301. pr_debug("Received mlme ramdl_write request\n");
  302. result = prism2mgmt_ramdl_write(wlandev, msg);
  303. break;
  304. case DIDmsg_p2req_flashdl_state:
  305. pr_debug("Received mlme flashdl_state request\n");
  306. result = prism2mgmt_flashdl_state(wlandev, msg);
  307. break;
  308. case DIDmsg_p2req_flashdl_write:
  309. pr_debug("Received mlme flashdl_write request\n");
  310. result = prism2mgmt_flashdl_write(wlandev, msg);
  311. break;
  312. /*
  313. * Linux specific messages
  314. */
  315. case DIDmsg_lnxreq_hostwep:
  316. break; /* ignore me. */
  317. case DIDmsg_lnxreq_ifstate:
  318. {
  319. struct p80211msg_lnxreq_ifstate *ifstatemsg;
  320. pr_debug("Received mlme ifstate request\n");
  321. ifstatemsg = (struct p80211msg_lnxreq_ifstate *)msg;
  322. result =
  323. prism2sta_ifstate(wlandev,
  324. ifstatemsg->ifstate.data);
  325. ifstatemsg->resultcode.status =
  326. P80211ENUM_msgitem_status_data_ok;
  327. ifstatemsg->resultcode.data = result;
  328. result = 0;
  329. }
  330. break;
  331. case DIDmsg_lnxreq_wlansniff:
  332. pr_debug("Received mlme wlansniff request\n");
  333. result = prism2mgmt_wlansniff(wlandev, msg);
  334. break;
  335. case DIDmsg_lnxreq_autojoin:
  336. pr_debug("Received mlme autojoin request\n");
  337. result = prism2mgmt_autojoin(wlandev, msg);
  338. break;
  339. case DIDmsg_lnxreq_commsquality:{
  340. struct p80211msg_lnxreq_commsquality *qualmsg;
  341. pr_debug("Received commsquality request\n");
  342. qualmsg = (struct p80211msg_lnxreq_commsquality *)msg;
  343. qualmsg->link.status =
  344. P80211ENUM_msgitem_status_data_ok;
  345. qualmsg->level.status =
  346. P80211ENUM_msgitem_status_data_ok;
  347. qualmsg->noise.status =
  348. P80211ENUM_msgitem_status_data_ok;
  349. qualmsg->link.data = le16_to_cpu(hw->qual.cq_curr_bss);
  350. qualmsg->level.data =
  351. le16_to_cpu(hw->qual.asl_curr_bss);
  352. qualmsg->noise.data = le16_to_cpu(hw->qual.anl_curr_fc);
  353. qualmsg->txrate.data = hw->txrate;
  354. break;
  355. }
  356. default:
  357. netdev_warn(wlandev->netdev,
  358. "Unknown mgmt request message 0x%08x",
  359. msg->msgcode);
  360. break;
  361. }
  362. return result;
  363. }
  364. /*
  365. * prism2sta_ifstate
  366. *
  367. * Interface state. This is the primary WLAN interface enable/disable
  368. * handler. Following the driver/load/deviceprobe sequence, this
  369. * function must be called with a state of "enable" before any other
  370. * commands will be accepted.
  371. *
  372. * Arguments:
  373. * wlandev wlan device structure
  374. * msgp ptr to msg buffer
  375. *
  376. * Returns:
  377. * A p80211 message resultcode value.
  378. *
  379. * Side effects:
  380. *
  381. * Call context:
  382. * process thread (usually)
  383. * interrupt
  384. */
  385. u32 prism2sta_ifstate(struct wlandevice *wlandev, u32 ifstate)
  386. {
  387. struct hfa384x *hw = wlandev->priv;
  388. u32 result;
  389. result = P80211ENUM_resultcode_implementation_failure;
  390. pr_debug("Current MSD state(%d), requesting(%d)\n",
  391. wlandev->msdstate, ifstate);
  392. switch (ifstate) {
  393. case P80211ENUM_ifstate_fwload:
  394. switch (wlandev->msdstate) {
  395. case WLAN_MSD_HWPRESENT:
  396. wlandev->msdstate = WLAN_MSD_FWLOAD_PENDING;
  397. /*
  398. * Initialize the device+driver sufficiently
  399. * for firmware loading.
  400. */
  401. result = hfa384x_drvr_start(hw);
  402. if (result) {
  403. netdev_err(wlandev->netdev,
  404. "hfa384x_drvr_start() failed,result=%d\n",
  405. (int)result);
  406. result =
  407. P80211ENUM_resultcode_implementation_failure;
  408. wlandev->msdstate = WLAN_MSD_HWPRESENT;
  409. break;
  410. }
  411. wlandev->msdstate = WLAN_MSD_FWLOAD;
  412. result = P80211ENUM_resultcode_success;
  413. break;
  414. case WLAN_MSD_FWLOAD:
  415. hfa384x_cmd_initialize(hw);
  416. result = P80211ENUM_resultcode_success;
  417. break;
  418. case WLAN_MSD_RUNNING:
  419. netdev_warn(wlandev->netdev,
  420. "Cannot enter fwload state from enable state, you must disable first.\n");
  421. result = P80211ENUM_resultcode_invalid_parameters;
  422. break;
  423. case WLAN_MSD_HWFAIL:
  424. default:
  425. /* probe() had a problem or the msdstate contains
  426. * an unrecognized value, there's nothing we can do.
  427. */
  428. result = P80211ENUM_resultcode_implementation_failure;
  429. break;
  430. }
  431. break;
  432. case P80211ENUM_ifstate_enable:
  433. switch (wlandev->msdstate) {
  434. case WLAN_MSD_HWPRESENT:
  435. case WLAN_MSD_FWLOAD:
  436. wlandev->msdstate = WLAN_MSD_RUNNING_PENDING;
  437. /* Initialize the device+driver for full
  438. * operation. Note that this might me an FWLOAD to
  439. * to RUNNING transition so we must not do a chip
  440. * or board level reset. Note that on failure,
  441. * the MSD state is set to HWPRESENT because we
  442. * can't make any assumptions about the state
  443. * of the hardware or a previous firmware load.
  444. */
  445. result = hfa384x_drvr_start(hw);
  446. if (result) {
  447. netdev_err(wlandev->netdev,
  448. "hfa384x_drvr_start() failed,result=%d\n",
  449. (int)result);
  450. result =
  451. P80211ENUM_resultcode_implementation_failure;
  452. wlandev->msdstate = WLAN_MSD_HWPRESENT;
  453. break;
  454. }
  455. result = prism2sta_getcardinfo(wlandev);
  456. if (result) {
  457. netdev_err(wlandev->netdev,
  458. "prism2sta_getcardinfo() failed,result=%d\n",
  459. (int)result);
  460. result =
  461. P80211ENUM_resultcode_implementation_failure;
  462. hfa384x_drvr_stop(hw);
  463. wlandev->msdstate = WLAN_MSD_HWPRESENT;
  464. break;
  465. }
  466. result = prism2sta_globalsetup(wlandev);
  467. if (result) {
  468. netdev_err(wlandev->netdev,
  469. "prism2sta_globalsetup() failed,result=%d\n",
  470. (int)result);
  471. result =
  472. P80211ENUM_resultcode_implementation_failure;
  473. hfa384x_drvr_stop(hw);
  474. wlandev->msdstate = WLAN_MSD_HWPRESENT;
  475. break;
  476. }
  477. wlandev->msdstate = WLAN_MSD_RUNNING;
  478. hw->join_ap = 0;
  479. hw->join_retries = 60;
  480. result = P80211ENUM_resultcode_success;
  481. break;
  482. case WLAN_MSD_RUNNING:
  483. /* Do nothing, we're already in this state. */
  484. result = P80211ENUM_resultcode_success;
  485. break;
  486. case WLAN_MSD_HWFAIL:
  487. default:
  488. /* probe() had a problem or the msdstate contains
  489. * an unrecognized value, there's nothing we can do.
  490. */
  491. result = P80211ENUM_resultcode_implementation_failure;
  492. break;
  493. }
  494. break;
  495. case P80211ENUM_ifstate_disable:
  496. switch (wlandev->msdstate) {
  497. case WLAN_MSD_HWPRESENT:
  498. /* Do nothing, we're already in this state. */
  499. result = P80211ENUM_resultcode_success;
  500. break;
  501. case WLAN_MSD_FWLOAD:
  502. case WLAN_MSD_RUNNING:
  503. wlandev->msdstate = WLAN_MSD_HWPRESENT_PENDING;
  504. /*
  505. * TODO: Shut down the MAC completely. Here a chip
  506. * or board level reset is probably called for.
  507. * After a "disable" _all_ results are lost, even
  508. * those from a fwload.
  509. */
  510. if (!wlandev->hwremoved)
  511. netif_carrier_off(wlandev->netdev);
  512. hfa384x_drvr_stop(hw);
  513. wlandev->macmode = WLAN_MACMODE_NONE;
  514. wlandev->msdstate = WLAN_MSD_HWPRESENT;
  515. result = P80211ENUM_resultcode_success;
  516. break;
  517. case WLAN_MSD_HWFAIL:
  518. default:
  519. /* probe() had a problem or the msdstate contains
  520. * an unrecognized value, there's nothing we can do.
  521. */
  522. result = P80211ENUM_resultcode_implementation_failure;
  523. break;
  524. }
  525. break;
  526. default:
  527. result = P80211ENUM_resultcode_invalid_parameters;
  528. break;
  529. }
  530. return result;
  531. }
  532. /*
  533. * prism2sta_getcardinfo
  534. *
  535. * Collect the NICID, firmware version and any other identifiers
  536. * we'd like to have in host-side data structures.
  537. *
  538. * Arguments:
  539. * wlandev wlan device structure
  540. *
  541. * Returns:
  542. * 0 success
  543. * >0 f/w reported error
  544. * <0 driver reported error
  545. *
  546. * Side effects:
  547. *
  548. * Call context:
  549. * Either.
  550. */
  551. static int prism2sta_getcardinfo(struct wlandevice *wlandev)
  552. {
  553. int result = 0;
  554. struct hfa384x *hw = wlandev->priv;
  555. u16 temp;
  556. u8 snum[HFA384x_RID_NICSERIALNUMBER_LEN];
  557. /* Collect version and compatibility info */
  558. /* Some are critical, some are not */
  559. /* NIC identity */
  560. result = hfa384x_drvr_getconfig(hw, HFA384x_RID_NICIDENTITY,
  561. &hw->ident_nic,
  562. sizeof(struct hfa384x_compident));
  563. if (result) {
  564. netdev_err(wlandev->netdev, "Failed to retrieve NICIDENTITY\n");
  565. goto failed;
  566. }
  567. /* get all the nic id fields in host byte order */
  568. le16_to_cpus(&hw->ident_nic.id);
  569. le16_to_cpus(&hw->ident_nic.variant);
  570. le16_to_cpus(&hw->ident_nic.major);
  571. le16_to_cpus(&hw->ident_nic.minor);
  572. netdev_info(wlandev->netdev, "ident: nic h/w: id=0x%02x %d.%d.%d\n",
  573. hw->ident_nic.id, hw->ident_nic.major,
  574. hw->ident_nic.minor, hw->ident_nic.variant);
  575. /* Primary f/w identity */
  576. result = hfa384x_drvr_getconfig(hw, HFA384x_RID_PRIIDENTITY,
  577. &hw->ident_pri_fw,
  578. sizeof(struct hfa384x_compident));
  579. if (result) {
  580. netdev_err(wlandev->netdev, "Failed to retrieve PRIIDENTITY\n");
  581. goto failed;
  582. }
  583. /* get all the private fw id fields in host byte order */
  584. le16_to_cpus(&hw->ident_pri_fw.id);
  585. le16_to_cpus(&hw->ident_pri_fw.variant);
  586. le16_to_cpus(&hw->ident_pri_fw.major);
  587. le16_to_cpus(&hw->ident_pri_fw.minor);
  588. netdev_info(wlandev->netdev, "ident: pri f/w: id=0x%02x %d.%d.%d\n",
  589. hw->ident_pri_fw.id, hw->ident_pri_fw.major,
  590. hw->ident_pri_fw.minor, hw->ident_pri_fw.variant);
  591. /* Station (Secondary?) f/w identity */
  592. result = hfa384x_drvr_getconfig(hw, HFA384x_RID_STAIDENTITY,
  593. &hw->ident_sta_fw,
  594. sizeof(struct hfa384x_compident));
  595. if (result) {
  596. netdev_err(wlandev->netdev, "Failed to retrieve STAIDENTITY\n");
  597. goto failed;
  598. }
  599. if (hw->ident_nic.id < 0x8000) {
  600. netdev_err(wlandev->netdev,
  601. "FATAL: Card is not an Intersil Prism2/2.5/3\n");
  602. result = -1;
  603. goto failed;
  604. }
  605. /* get all the station fw id fields in host byte order */
  606. le16_to_cpus(&hw->ident_sta_fw.id);
  607. le16_to_cpus(&hw->ident_sta_fw.variant);
  608. le16_to_cpus(&hw->ident_sta_fw.major);
  609. le16_to_cpus(&hw->ident_sta_fw.minor);
  610. /* strip out the 'special' variant bits */
  611. hw->mm_mods = hw->ident_sta_fw.variant & GENMASK(15, 14);
  612. hw->ident_sta_fw.variant &= ~((u16)GENMASK(15, 14));
  613. if (hw->ident_sta_fw.id == 0x1f) {
  614. netdev_info(wlandev->netdev,
  615. "ident: sta f/w: id=0x%02x %d.%d.%d\n",
  616. hw->ident_sta_fw.id, hw->ident_sta_fw.major,
  617. hw->ident_sta_fw.minor, hw->ident_sta_fw.variant);
  618. } else {
  619. netdev_info(wlandev->netdev,
  620. "ident: ap f/w: id=0x%02x %d.%d.%d\n",
  621. hw->ident_sta_fw.id, hw->ident_sta_fw.major,
  622. hw->ident_sta_fw.minor, hw->ident_sta_fw.variant);
  623. netdev_err(wlandev->netdev, "Unsupported Tertiary AP firmware loaded!\n");
  624. goto failed;
  625. }
  626. /* Compatibility range, Modem supplier */
  627. result = hfa384x_drvr_getconfig(hw, HFA384x_RID_MFISUPRANGE,
  628. &hw->cap_sup_mfi,
  629. sizeof(struct hfa384x_caplevel));
  630. if (result) {
  631. netdev_err(wlandev->netdev, "Failed to retrieve MFISUPRANGE\n");
  632. goto failed;
  633. }
  634. /* get all the Compatibility range, modem interface supplier
  635. * fields in byte order
  636. */
  637. le16_to_cpus(&hw->cap_sup_mfi.role);
  638. le16_to_cpus(&hw->cap_sup_mfi.id);
  639. le16_to_cpus(&hw->cap_sup_mfi.variant);
  640. le16_to_cpus(&hw->cap_sup_mfi.bottom);
  641. le16_to_cpus(&hw->cap_sup_mfi.top);
  642. netdev_info(wlandev->netdev,
  643. "MFI:SUP:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
  644. hw->cap_sup_mfi.role, hw->cap_sup_mfi.id,
  645. hw->cap_sup_mfi.variant, hw->cap_sup_mfi.bottom,
  646. hw->cap_sup_mfi.top);
  647. /* Compatibility range, Controller supplier */
  648. result = hfa384x_drvr_getconfig(hw, HFA384x_RID_CFISUPRANGE,
  649. &hw->cap_sup_cfi,
  650. sizeof(struct hfa384x_caplevel));
  651. if (result) {
  652. netdev_err(wlandev->netdev, "Failed to retrieve CFISUPRANGE\n");
  653. goto failed;
  654. }
  655. /* get all the Compatibility range, controller interface supplier
  656. * fields in byte order
  657. */
  658. le16_to_cpus(&hw->cap_sup_cfi.role);
  659. le16_to_cpus(&hw->cap_sup_cfi.id);
  660. le16_to_cpus(&hw->cap_sup_cfi.variant);
  661. le16_to_cpus(&hw->cap_sup_cfi.bottom);
  662. le16_to_cpus(&hw->cap_sup_cfi.top);
  663. netdev_info(wlandev->netdev,
  664. "CFI:SUP:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
  665. hw->cap_sup_cfi.role, hw->cap_sup_cfi.id,
  666. hw->cap_sup_cfi.variant, hw->cap_sup_cfi.bottom,
  667. hw->cap_sup_cfi.top);
  668. /* Compatibility range, Primary f/w supplier */
  669. result = hfa384x_drvr_getconfig(hw, HFA384x_RID_PRISUPRANGE,
  670. &hw->cap_sup_pri,
  671. sizeof(struct hfa384x_caplevel));
  672. if (result) {
  673. netdev_err(wlandev->netdev, "Failed to retrieve PRISUPRANGE\n");
  674. goto failed;
  675. }
  676. /* get all the Compatibility range, primary firmware supplier
  677. * fields in byte order
  678. */
  679. le16_to_cpus(&hw->cap_sup_pri.role);
  680. le16_to_cpus(&hw->cap_sup_pri.id);
  681. le16_to_cpus(&hw->cap_sup_pri.variant);
  682. le16_to_cpus(&hw->cap_sup_pri.bottom);
  683. le16_to_cpus(&hw->cap_sup_pri.top);
  684. netdev_info(wlandev->netdev,
  685. "PRI:SUP:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
  686. hw->cap_sup_pri.role, hw->cap_sup_pri.id,
  687. hw->cap_sup_pri.variant, hw->cap_sup_pri.bottom,
  688. hw->cap_sup_pri.top);
  689. /* Compatibility range, Station f/w supplier */
  690. result = hfa384x_drvr_getconfig(hw, HFA384x_RID_STASUPRANGE,
  691. &hw->cap_sup_sta,
  692. sizeof(struct hfa384x_caplevel));
  693. if (result) {
  694. netdev_err(wlandev->netdev, "Failed to retrieve STASUPRANGE\n");
  695. goto failed;
  696. }
  697. /* get all the Compatibility range, station firmware supplier
  698. * fields in byte order
  699. */
  700. le16_to_cpus(&hw->cap_sup_sta.role);
  701. le16_to_cpus(&hw->cap_sup_sta.id);
  702. le16_to_cpus(&hw->cap_sup_sta.variant);
  703. le16_to_cpus(&hw->cap_sup_sta.bottom);
  704. le16_to_cpus(&hw->cap_sup_sta.top);
  705. if (hw->cap_sup_sta.id == 0x04) {
  706. netdev_info(wlandev->netdev,
  707. "STA:SUP:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
  708. hw->cap_sup_sta.role, hw->cap_sup_sta.id,
  709. hw->cap_sup_sta.variant, hw->cap_sup_sta.bottom,
  710. hw->cap_sup_sta.top);
  711. } else {
  712. netdev_info(wlandev->netdev,
  713. "AP:SUP:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
  714. hw->cap_sup_sta.role, hw->cap_sup_sta.id,
  715. hw->cap_sup_sta.variant, hw->cap_sup_sta.bottom,
  716. hw->cap_sup_sta.top);
  717. }
  718. /* Compatibility range, primary f/w actor, CFI supplier */
  719. result = hfa384x_drvr_getconfig(hw, HFA384x_RID_PRI_CFIACTRANGES,
  720. &hw->cap_act_pri_cfi,
  721. sizeof(struct hfa384x_caplevel));
  722. if (result) {
  723. netdev_err(wlandev->netdev, "Failed to retrieve PRI_CFIACTRANGES\n");
  724. goto failed;
  725. }
  726. /* get all the Compatibility range, primary f/w actor, CFI supplier
  727. * fields in byte order
  728. */
  729. le16_to_cpus(&hw->cap_act_pri_cfi.role);
  730. le16_to_cpus(&hw->cap_act_pri_cfi.id);
  731. le16_to_cpus(&hw->cap_act_pri_cfi.variant);
  732. le16_to_cpus(&hw->cap_act_pri_cfi.bottom);
  733. le16_to_cpus(&hw->cap_act_pri_cfi.top);
  734. netdev_info(wlandev->netdev,
  735. "PRI-CFI:ACT:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
  736. hw->cap_act_pri_cfi.role, hw->cap_act_pri_cfi.id,
  737. hw->cap_act_pri_cfi.variant, hw->cap_act_pri_cfi.bottom,
  738. hw->cap_act_pri_cfi.top);
  739. /* Compatibility range, sta f/w actor, CFI supplier */
  740. result = hfa384x_drvr_getconfig(hw, HFA384x_RID_STA_CFIACTRANGES,
  741. &hw->cap_act_sta_cfi,
  742. sizeof(struct hfa384x_caplevel));
  743. if (result) {
  744. netdev_err(wlandev->netdev, "Failed to retrieve STA_CFIACTRANGES\n");
  745. goto failed;
  746. }
  747. /* get all the Compatibility range, station f/w actor, CFI supplier
  748. * fields in byte order
  749. */
  750. le16_to_cpus(&hw->cap_act_sta_cfi.role);
  751. le16_to_cpus(&hw->cap_act_sta_cfi.id);
  752. le16_to_cpus(&hw->cap_act_sta_cfi.variant);
  753. le16_to_cpus(&hw->cap_act_sta_cfi.bottom);
  754. le16_to_cpus(&hw->cap_act_sta_cfi.top);
  755. netdev_info(wlandev->netdev,
  756. "STA-CFI:ACT:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
  757. hw->cap_act_sta_cfi.role, hw->cap_act_sta_cfi.id,
  758. hw->cap_act_sta_cfi.variant, hw->cap_act_sta_cfi.bottom,
  759. hw->cap_act_sta_cfi.top);
  760. /* Compatibility range, sta f/w actor, MFI supplier */
  761. result = hfa384x_drvr_getconfig(hw, HFA384x_RID_STA_MFIACTRANGES,
  762. &hw->cap_act_sta_mfi,
  763. sizeof(struct hfa384x_caplevel));
  764. if (result) {
  765. netdev_err(wlandev->netdev, "Failed to retrieve STA_MFIACTRANGES\n");
  766. goto failed;
  767. }
  768. /* get all the Compatibility range, station f/w actor, MFI supplier
  769. * fields in byte order
  770. */
  771. le16_to_cpus(&hw->cap_act_sta_mfi.role);
  772. le16_to_cpus(&hw->cap_act_sta_mfi.id);
  773. le16_to_cpus(&hw->cap_act_sta_mfi.variant);
  774. le16_to_cpus(&hw->cap_act_sta_mfi.bottom);
  775. le16_to_cpus(&hw->cap_act_sta_mfi.top);
  776. netdev_info(wlandev->netdev,
  777. "STA-MFI:ACT:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
  778. hw->cap_act_sta_mfi.role, hw->cap_act_sta_mfi.id,
  779. hw->cap_act_sta_mfi.variant, hw->cap_act_sta_mfi.bottom,
  780. hw->cap_act_sta_mfi.top);
  781. /* Serial Number */
  782. result = hfa384x_drvr_getconfig(hw, HFA384x_RID_NICSERIALNUMBER,
  783. snum, HFA384x_RID_NICSERIALNUMBER_LEN);
  784. if (!result) {
  785. netdev_info(wlandev->netdev, "Prism2 card SN: %*pEhp\n",
  786. HFA384x_RID_NICSERIALNUMBER_LEN, snum);
  787. } else {
  788. netdev_err(wlandev->netdev, "Failed to retrieve Prism2 Card SN\n");
  789. goto failed;
  790. }
  791. /* Collect the MAC address */
  792. result = hfa384x_drvr_getconfig(hw, HFA384x_RID_CNFOWNMACADDR,
  793. wlandev->netdev->dev_addr, ETH_ALEN);
  794. if (result != 0) {
  795. netdev_err(wlandev->netdev, "Failed to retrieve mac address\n");
  796. goto failed;
  797. }
  798. /* short preamble is always implemented */
  799. wlandev->nsdcaps |= P80211_NSDCAP_SHORT_PREAMBLE;
  800. /* find out if hardware wep is implemented */
  801. hfa384x_drvr_getconfig16(hw, HFA384x_RID_PRIVACYOPTIMP, &temp);
  802. if (temp)
  803. wlandev->nsdcaps |= P80211_NSDCAP_HARDWAREWEP;
  804. /* get the dBm Scaling constant */
  805. hfa384x_drvr_getconfig16(hw, HFA384x_RID_CNFDBMADJUST, &temp);
  806. hw->dbmadjust = temp;
  807. /* Only enable scan by default on newer firmware */
  808. if (HFA384x_FIRMWARE_VERSION(hw->ident_sta_fw.major,
  809. hw->ident_sta_fw.minor,
  810. hw->ident_sta_fw.variant) <
  811. HFA384x_FIRMWARE_VERSION(1, 5, 5)) {
  812. wlandev->nsdcaps |= P80211_NSDCAP_NOSCAN;
  813. }
  814. /* TODO: Set any internally managed config items */
  815. goto done;
  816. failed:
  817. netdev_err(wlandev->netdev, "Failed, result=%d\n", result);
  818. done:
  819. return result;
  820. }
  821. /*
  822. * prism2sta_globalsetup
  823. *
  824. * Set any global RIDs that we want to set at device activation.
  825. *
  826. * Arguments:
  827. * wlandev wlan device structure
  828. *
  829. * Returns:
  830. * 0 success
  831. * >0 f/w reported error
  832. * <0 driver reported error
  833. *
  834. * Side effects:
  835. *
  836. * Call context:
  837. * process thread
  838. */
  839. static int prism2sta_globalsetup(struct wlandevice *wlandev)
  840. {
  841. struct hfa384x *hw = wlandev->priv;
  842. /* Set the maximum frame size */
  843. return hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFMAXDATALEN,
  844. WLAN_DATA_MAXLEN);
  845. }
  846. static int prism2sta_setmulticast(struct wlandevice *wlandev,
  847. struct net_device *dev)
  848. {
  849. int result = 0;
  850. struct hfa384x *hw = wlandev->priv;
  851. u16 promisc;
  852. /* If we're not ready, what's the point? */
  853. if (hw->state != HFA384x_STATE_RUNNING)
  854. goto exit;
  855. if ((dev->flags & (IFF_PROMISC | IFF_ALLMULTI)) != 0)
  856. promisc = P80211ENUM_truth_true;
  857. else
  858. promisc = P80211ENUM_truth_false;
  859. result =
  860. hfa384x_drvr_setconfig16_async(hw, HFA384x_RID_PROMISCMODE,
  861. promisc);
  862. exit:
  863. return result;
  864. }
  865. /*
  866. * prism2sta_inf_handover
  867. *
  868. * Handles the receipt of a Handover info frame. Should only be present
  869. * in APs only.
  870. *
  871. * Arguments:
  872. * wlandev wlan device structure
  873. * inf ptr to info frame (contents in hfa384x order)
  874. *
  875. * Returns:
  876. * nothing
  877. *
  878. * Side effects:
  879. *
  880. * Call context:
  881. * interrupt
  882. */
  883. static void prism2sta_inf_handover(struct wlandevice *wlandev,
  884. struct hfa384x_inf_frame *inf)
  885. {
  886. pr_debug("received infoframe:HANDOVER (unhandled)\n");
  887. }
  888. /*
  889. * prism2sta_inf_tallies
  890. *
  891. * Handles the receipt of a CommTallies info frame.
  892. *
  893. * Arguments:
  894. * wlandev wlan device structure
  895. * inf ptr to info frame (contents in hfa384x order)
  896. *
  897. * Returns:
  898. * nothing
  899. *
  900. * Side effects:
  901. *
  902. * Call context:
  903. * interrupt
  904. */
  905. static void prism2sta_inf_tallies(struct wlandevice *wlandev,
  906. struct hfa384x_inf_frame *inf)
  907. {
  908. struct hfa384x *hw = wlandev->priv;
  909. __le16 *src16;
  910. u32 *dst;
  911. __le32 *src32;
  912. int i;
  913. int cnt;
  914. /*
  915. * Determine if these are 16-bit or 32-bit tallies, based on the
  916. * record length of the info record.
  917. */
  918. cnt = sizeof(struct hfa384x_comm_tallies_32) / sizeof(u32);
  919. if (inf->framelen > 22) {
  920. dst = (u32 *)&hw->tallies;
  921. src32 = (__le32 *)&inf->info.commtallies32;
  922. for (i = 0; i < cnt; i++, dst++, src32++)
  923. *dst += le32_to_cpu(*src32);
  924. } else {
  925. dst = (u32 *)&hw->tallies;
  926. src16 = (__le16 *)&inf->info.commtallies16;
  927. for (i = 0; i < cnt; i++, dst++, src16++)
  928. *dst += le16_to_cpu(*src16);
  929. }
  930. }
  931. /*
  932. * prism2sta_inf_scanresults
  933. *
  934. * Handles the receipt of a Scan Results info frame.
  935. *
  936. * Arguments:
  937. * wlandev wlan device structure
  938. * inf ptr to info frame (contents in hfa384x order)
  939. *
  940. * Returns:
  941. * nothing
  942. *
  943. * Side effects:
  944. *
  945. * Call context:
  946. * interrupt
  947. */
  948. static void prism2sta_inf_scanresults(struct wlandevice *wlandev,
  949. struct hfa384x_inf_frame *inf)
  950. {
  951. struct hfa384x *hw = wlandev->priv;
  952. int nbss;
  953. struct hfa384x_scan_result *sr = &inf->info.scanresult;
  954. int i;
  955. struct hfa384x_join_request_data joinreq;
  956. int result;
  957. /* Get the number of results, first in bytes, then in results */
  958. nbss = (inf->framelen * sizeof(u16)) -
  959. sizeof(inf->infotype) - sizeof(inf->info.scanresult.scanreason);
  960. nbss /= sizeof(struct hfa384x_scan_result_sub);
  961. /* Print em */
  962. pr_debug("rx scanresults, reason=%d, nbss=%d:\n",
  963. inf->info.scanresult.scanreason, nbss);
  964. for (i = 0; i < nbss; i++) {
  965. pr_debug("chid=%d anl=%d sl=%d bcnint=%d\n",
  966. sr->result[i].chid,
  967. sr->result[i].anl,
  968. sr->result[i].sl, sr->result[i].bcnint);
  969. pr_debug(" capinfo=0x%04x proberesp_rate=%d\n",
  970. sr->result[i].capinfo, sr->result[i].proberesp_rate);
  971. }
  972. /* issue a join request */
  973. joinreq.channel = sr->result[0].chid;
  974. memcpy(joinreq.bssid, sr->result[0].bssid, WLAN_BSSID_LEN);
  975. result = hfa384x_drvr_setconfig(hw,
  976. HFA384x_RID_JOINREQUEST,
  977. &joinreq, HFA384x_RID_JOINREQUEST_LEN);
  978. if (result) {
  979. netdev_err(wlandev->netdev, "setconfig(joinreq) failed, result=%d\n",
  980. result);
  981. }
  982. }
  983. /*
  984. * prism2sta_inf_hostscanresults
  985. *
  986. * Handles the receipt of a Scan Results info frame.
  987. *
  988. * Arguments:
  989. * wlandev wlan device structure
  990. * inf ptr to info frame (contents in hfa384x order)
  991. *
  992. * Returns:
  993. * nothing
  994. *
  995. * Side effects:
  996. *
  997. * Call context:
  998. * interrupt
  999. */
  1000. static void prism2sta_inf_hostscanresults(struct wlandevice *wlandev,
  1001. struct hfa384x_inf_frame *inf)
  1002. {
  1003. struct hfa384x *hw = wlandev->priv;
  1004. int nbss;
  1005. nbss = (inf->framelen - 3) / 32;
  1006. pr_debug("Received %d hostscan results\n", nbss);
  1007. if (nbss > 32)
  1008. nbss = 32;
  1009. kfree(hw->scanresults);
  1010. hw->scanresults = kmemdup(inf, sizeof(*inf), GFP_ATOMIC);
  1011. if (nbss == 0)
  1012. nbss = -1;
  1013. /* Notify/wake the sleeping caller. */
  1014. hw->scanflag = nbss;
  1015. wake_up_interruptible(&hw->cmdq);
  1016. };
  1017. /*
  1018. * prism2sta_inf_chinforesults
  1019. *
  1020. * Handles the receipt of a Channel Info Results info frame.
  1021. *
  1022. * Arguments:
  1023. * wlandev wlan device structure
  1024. * inf ptr to info frame (contents in hfa384x order)
  1025. *
  1026. * Returns:
  1027. * nothing
  1028. *
  1029. * Side effects:
  1030. *
  1031. * Call context:
  1032. * interrupt
  1033. */
  1034. static void prism2sta_inf_chinforesults(struct wlandevice *wlandev,
  1035. struct hfa384x_inf_frame *inf)
  1036. {
  1037. struct hfa384x *hw = wlandev->priv;
  1038. unsigned int i, n;
  1039. hw->channel_info.results.scanchannels =
  1040. inf->info.chinforesult.scanchannels;
  1041. for (i = 0, n = 0; i < HFA384x_CHINFORESULT_MAX; i++) {
  1042. struct hfa384x_ch_info_result_sub *result;
  1043. struct hfa384x_ch_info_result_sub *chinforesult;
  1044. int chan;
  1045. if (!(hw->channel_info.results.scanchannels & (1 << i)))
  1046. continue;
  1047. result = &inf->info.chinforesult.result[n];
  1048. chan = result->chid - 1;
  1049. if (chan < 0 || chan >= HFA384x_CHINFORESULT_MAX)
  1050. continue;
  1051. chinforesult = &hw->channel_info.results.result[chan];
  1052. chinforesult->chid = chan;
  1053. chinforesult->anl = result->anl;
  1054. chinforesult->pnl = result->pnl;
  1055. chinforesult->active = result->active;
  1056. pr_debug("chinfo: channel %d, %s level (avg/peak)=%d/%d dB, pcf %d\n",
  1057. chan + 1,
  1058. (chinforesult->active & HFA384x_CHINFORESULT_BSSACTIVE)
  1059. ? "signal" : "noise",
  1060. chinforesult->anl, chinforesult->pnl,
  1061. (chinforesult->active & HFA384x_CHINFORESULT_PCFACTIVE)
  1062. ? 1 : 0);
  1063. n++;
  1064. }
  1065. atomic_set(&hw->channel_info.done, 2);
  1066. hw->channel_info.count = n;
  1067. }
  1068. void prism2sta_processing_defer(struct work_struct *data)
  1069. {
  1070. struct hfa384x *hw = container_of(data, struct hfa384x, link_bh);
  1071. struct wlandevice *wlandev = hw->wlandev;
  1072. struct hfa384x_bytestr32 ssid;
  1073. int result;
  1074. /* First let's process the auth frames */
  1075. {
  1076. struct sk_buff *skb;
  1077. struct hfa384x_inf_frame *inf;
  1078. while ((skb = skb_dequeue(&hw->authq))) {
  1079. inf = (struct hfa384x_inf_frame *)skb->data;
  1080. prism2sta_inf_authreq_defer(wlandev, inf);
  1081. }
  1082. }
  1083. /* Now let's handle the linkstatus stuff */
  1084. if (hw->link_status == hw->link_status_new)
  1085. return;
  1086. hw->link_status = hw->link_status_new;
  1087. switch (hw->link_status) {
  1088. case HFA384x_LINK_NOTCONNECTED:
  1089. /* I'm currently assuming that this is the initial link
  1090. * state. It should only be possible immediately
  1091. * following an Enable command.
  1092. * Response:
  1093. * Block Transmits, Ignore receives of data frames
  1094. */
  1095. netif_carrier_off(wlandev->netdev);
  1096. netdev_info(wlandev->netdev, "linkstatus=NOTCONNECTED (unhandled)\n");
  1097. break;
  1098. case HFA384x_LINK_CONNECTED:
  1099. /* This one indicates a successful scan/join/auth/assoc.
  1100. * When we have the full MLME complement, this event will
  1101. * signify successful completion of both mlme_authenticate
  1102. * and mlme_associate. State management will get a little
  1103. * ugly here.
  1104. * Response:
  1105. * Indicate authentication and/or association
  1106. * Enable Transmits, Receives and pass up data frames
  1107. */
  1108. netif_carrier_on(wlandev->netdev);
  1109. /* If we are joining a specific AP, set our
  1110. * state and reset retries
  1111. */
  1112. if (hw->join_ap == 1)
  1113. hw->join_ap = 2;
  1114. hw->join_retries = 60;
  1115. /* Don't call this in monitor mode */
  1116. if (wlandev->netdev->type == ARPHRD_ETHER) {
  1117. u16 portstatus;
  1118. netdev_info(wlandev->netdev, "linkstatus=CONNECTED\n");
  1119. /* For non-usb devices, we can use the sync versions */
  1120. /* Collect the BSSID, and set state to allow tx */
  1121. result = hfa384x_drvr_getconfig(hw,
  1122. HFA384x_RID_CURRENTBSSID,
  1123. wlandev->bssid,
  1124. WLAN_BSSID_LEN);
  1125. if (result) {
  1126. pr_debug
  1127. ("getconfig(0x%02x) failed, result = %d\n",
  1128. HFA384x_RID_CURRENTBSSID, result);
  1129. return;
  1130. }
  1131. result = hfa384x_drvr_getconfig(hw,
  1132. HFA384x_RID_CURRENTSSID,
  1133. &ssid, sizeof(ssid));
  1134. if (result) {
  1135. pr_debug
  1136. ("getconfig(0x%02x) failed, result = %d\n",
  1137. HFA384x_RID_CURRENTSSID, result);
  1138. return;
  1139. }
  1140. prism2mgmt_bytestr2pstr((struct hfa384x_bytestr *)&ssid,
  1141. (struct p80211pstrd *)&wlandev->ssid);
  1142. /* Collect the port status */
  1143. result = hfa384x_drvr_getconfig16(hw,
  1144. HFA384x_RID_PORTSTATUS,
  1145. &portstatus);
  1146. if (result) {
  1147. pr_debug
  1148. ("getconfig(0x%02x) failed, result = %d\n",
  1149. HFA384x_RID_PORTSTATUS, result);
  1150. return;
  1151. }
  1152. wlandev->macmode =
  1153. (portstatus == HFA384x_PSTATUS_CONN_IBSS) ?
  1154. WLAN_MACMODE_IBSS_STA : WLAN_MACMODE_ESS_STA;
  1155. /* signal back up to cfg80211 layer */
  1156. prism2_connect_result(wlandev, P80211ENUM_truth_false);
  1157. /* Get the ball rolling on the comms quality stuff */
  1158. prism2sta_commsqual_defer(&hw->commsqual_bh);
  1159. }
  1160. break;
  1161. case HFA384x_LINK_DISCONNECTED:
  1162. /* This one indicates that our association is gone. We've
  1163. * lost connection with the AP and/or been disassociated.
  1164. * This indicates that the MAC has completely cleared it's
  1165. * associated state. We * should send a deauth indication
  1166. * (implying disassoc) up * to the MLME.
  1167. * Response:
  1168. * Indicate Deauthentication
  1169. * Block Transmits, Ignore receives of data frames
  1170. */
  1171. if (wlandev->netdev->type == ARPHRD_ETHER)
  1172. netdev_info(wlandev->netdev,
  1173. "linkstatus=DISCONNECTED (unhandled)\n");
  1174. wlandev->macmode = WLAN_MACMODE_NONE;
  1175. netif_carrier_off(wlandev->netdev);
  1176. /* signal back up to cfg80211 layer */
  1177. prism2_disconnected(wlandev);
  1178. break;
  1179. case HFA384x_LINK_AP_CHANGE:
  1180. /* This one indicates that the MAC has decided to and
  1181. * successfully completed a change to another AP. We
  1182. * should probably implement a reassociation indication
  1183. * in response to this one. I'm thinking that the
  1184. * p80211 layer needs to be notified in case of
  1185. * buffering/queueing issues. User mode also needs to be
  1186. * notified so that any BSS dependent elements can be
  1187. * updated.
  1188. * associated state. We * should send a deauth indication
  1189. * (implying disassoc) up * to the MLME.
  1190. * Response:
  1191. * Indicate Reassociation
  1192. * Enable Transmits, Receives and pass up data frames
  1193. */
  1194. netdev_info(wlandev->netdev, "linkstatus=AP_CHANGE\n");
  1195. result = hfa384x_drvr_getconfig(hw,
  1196. HFA384x_RID_CURRENTBSSID,
  1197. wlandev->bssid, WLAN_BSSID_LEN);
  1198. if (result) {
  1199. pr_debug("getconfig(0x%02x) failed, result = %d\n",
  1200. HFA384x_RID_CURRENTBSSID, result);
  1201. return;
  1202. }
  1203. result = hfa384x_drvr_getconfig(hw,
  1204. HFA384x_RID_CURRENTSSID,
  1205. &ssid, sizeof(ssid));
  1206. if (result) {
  1207. pr_debug("getconfig(0x%02x) failed, result = %d\n",
  1208. HFA384x_RID_CURRENTSSID, result);
  1209. return;
  1210. }
  1211. prism2mgmt_bytestr2pstr((struct hfa384x_bytestr *)&ssid,
  1212. (struct p80211pstrd *)&wlandev->ssid);
  1213. hw->link_status = HFA384x_LINK_CONNECTED;
  1214. netif_carrier_on(wlandev->netdev);
  1215. /* signal back up to cfg80211 layer */
  1216. prism2_roamed(wlandev);
  1217. break;
  1218. case HFA384x_LINK_AP_OUTOFRANGE:
  1219. /* This one indicates that the MAC has decided that the
  1220. * AP is out of range, but hasn't found a better candidate
  1221. * so the MAC maintains its "associated" state in case
  1222. * we get back in range. We should block transmits and
  1223. * receives in this state. Do we need an indication here?
  1224. * Probably not since a polling user-mode element would
  1225. * get this status from from p2PortStatus(FD40). What about
  1226. * p80211?
  1227. * Response:
  1228. * Block Transmits, Ignore receives of data frames
  1229. */
  1230. netdev_info(wlandev->netdev, "linkstatus=AP_OUTOFRANGE (unhandled)\n");
  1231. netif_carrier_off(wlandev->netdev);
  1232. break;
  1233. case HFA384x_LINK_AP_INRANGE:
  1234. /* This one indicates that the MAC has decided that the
  1235. * AP is back in range. We continue working with our
  1236. * existing association.
  1237. * Response:
  1238. * Enable Transmits, Receives and pass up data frames
  1239. */
  1240. netdev_info(wlandev->netdev, "linkstatus=AP_INRANGE\n");
  1241. hw->link_status = HFA384x_LINK_CONNECTED;
  1242. netif_carrier_on(wlandev->netdev);
  1243. break;
  1244. case HFA384x_LINK_ASSOCFAIL:
  1245. /* This one is actually a peer to CONNECTED. We've
  1246. * requested a join for a given SSID and optionally BSSID.
  1247. * We can use this one to indicate authentication and
  1248. * association failures. The trick is going to be
  1249. * 1) identifying the failure, and 2) state management.
  1250. * Response:
  1251. * Disable Transmits, Ignore receives of data frames
  1252. */
  1253. if (hw->join_ap && --hw->join_retries > 0) {
  1254. struct hfa384x_join_request_data joinreq;
  1255. joinreq = hw->joinreq;
  1256. /* Send the join request */
  1257. hfa384x_drvr_setconfig(hw,
  1258. HFA384x_RID_JOINREQUEST,
  1259. &joinreq,
  1260. HFA384x_RID_JOINREQUEST_LEN);
  1261. netdev_info(wlandev->netdev,
  1262. "linkstatus=ASSOCFAIL (re-submitting join)\n");
  1263. } else {
  1264. netdev_info(wlandev->netdev, "linkstatus=ASSOCFAIL (unhandled)\n");
  1265. }
  1266. netif_carrier_off(wlandev->netdev);
  1267. /* signal back up to cfg80211 layer */
  1268. prism2_connect_result(wlandev, P80211ENUM_truth_true);
  1269. break;
  1270. default:
  1271. /* This is bad, IO port problems? */
  1272. netdev_warn(wlandev->netdev,
  1273. "unknown linkstatus=0x%02x\n", hw->link_status);
  1274. return;
  1275. }
  1276. wlandev->linkstatus = (hw->link_status == HFA384x_LINK_CONNECTED);
  1277. }
  1278. /*
  1279. * prism2sta_inf_linkstatus
  1280. *
  1281. * Handles the receipt of a Link Status info frame.
  1282. *
  1283. * Arguments:
  1284. * wlandev wlan device structure
  1285. * inf ptr to info frame (contents in hfa384x order)
  1286. *
  1287. * Returns:
  1288. * nothing
  1289. *
  1290. * Side effects:
  1291. *
  1292. * Call context:
  1293. * interrupt
  1294. */
  1295. static void prism2sta_inf_linkstatus(struct wlandevice *wlandev,
  1296. struct hfa384x_inf_frame *inf)
  1297. {
  1298. struct hfa384x *hw = wlandev->priv;
  1299. hw->link_status_new = le16_to_cpu(inf->info.linkstatus.linkstatus);
  1300. schedule_work(&hw->link_bh);
  1301. }
  1302. /*
  1303. * prism2sta_inf_assocstatus
  1304. *
  1305. * Handles the receipt of an Association Status info frame. Should
  1306. * be present in APs only.
  1307. *
  1308. * Arguments:
  1309. * wlandev wlan device structure
  1310. * inf ptr to info frame (contents in hfa384x order)
  1311. *
  1312. * Returns:
  1313. * nothing
  1314. *
  1315. * Side effects:
  1316. *
  1317. * Call context:
  1318. * interrupt
  1319. */
  1320. static void prism2sta_inf_assocstatus(struct wlandevice *wlandev,
  1321. struct hfa384x_inf_frame *inf)
  1322. {
  1323. struct hfa384x *hw = wlandev->priv;
  1324. struct hfa384x_assoc_status rec;
  1325. int i;
  1326. memcpy(&rec, &inf->info.assocstatus, sizeof(rec));
  1327. le16_to_cpus(&rec.assocstatus);
  1328. le16_to_cpus(&rec.reason);
  1329. /*
  1330. * Find the address in the list of authenticated stations.
  1331. * If it wasn't found, then this address has not been previously
  1332. * authenticated and something weird has happened if this is
  1333. * anything other than an "authentication failed" message.
  1334. * If the address was found, then set the "associated" flag for
  1335. * that station, based on whether the station is associating or
  1336. * losing its association. Something weird has also happened
  1337. * if we find the address in the list of authenticated stations
  1338. * but we are getting an "authentication failed" message.
  1339. */
  1340. for (i = 0; i < hw->authlist.cnt; i++)
  1341. if (ether_addr_equal(rec.sta_addr, hw->authlist.addr[i]))
  1342. break;
  1343. if (i >= hw->authlist.cnt) {
  1344. if (rec.assocstatus != HFA384x_ASSOCSTATUS_AUTHFAIL)
  1345. netdev_warn(wlandev->netdev,
  1346. "assocstatus info frame received for non-authenticated station.\n");
  1347. } else {
  1348. hw->authlist.assoc[i] =
  1349. (rec.assocstatus == HFA384x_ASSOCSTATUS_STAASSOC ||
  1350. rec.assocstatus == HFA384x_ASSOCSTATUS_REASSOC);
  1351. if (rec.assocstatus == HFA384x_ASSOCSTATUS_AUTHFAIL)
  1352. netdev_warn(wlandev->netdev,
  1353. "authfail assocstatus info frame received for authenticated station.\n");
  1354. }
  1355. }
  1356. /*
  1357. * prism2sta_inf_authreq
  1358. *
  1359. * Handles the receipt of an Authentication Request info frame. Should
  1360. * be present in APs only.
  1361. *
  1362. * Arguments:
  1363. * wlandev wlan device structure
  1364. * inf ptr to info frame (contents in hfa384x order)
  1365. *
  1366. * Returns:
  1367. * nothing
  1368. *
  1369. * Side effects:
  1370. *
  1371. * Call context:
  1372. * interrupt
  1373. *
  1374. */
  1375. static void prism2sta_inf_authreq(struct wlandevice *wlandev,
  1376. struct hfa384x_inf_frame *inf)
  1377. {
  1378. struct hfa384x *hw = wlandev->priv;
  1379. struct sk_buff *skb;
  1380. skb = dev_alloc_skb(sizeof(*inf));
  1381. if (skb) {
  1382. skb_put(skb, sizeof(*inf));
  1383. memcpy(skb->data, inf, sizeof(*inf));
  1384. skb_queue_tail(&hw->authq, skb);
  1385. schedule_work(&hw->link_bh);
  1386. }
  1387. }
  1388. static void prism2sta_inf_authreq_defer(struct wlandevice *wlandev,
  1389. struct hfa384x_inf_frame *inf)
  1390. {
  1391. struct hfa384x *hw = wlandev->priv;
  1392. struct hfa384x_authenticate_station_data rec;
  1393. int i, added, result, cnt;
  1394. u8 *addr;
  1395. /*
  1396. * Build the AuthenticateStation record. Initialize it for denying
  1397. * authentication.
  1398. */
  1399. ether_addr_copy(rec.address, inf->info.authreq.sta_addr);
  1400. rec.status = cpu_to_le16(P80211ENUM_status_unspec_failure);
  1401. /*
  1402. * Authenticate based on the access mode.
  1403. */
  1404. switch (hw->accessmode) {
  1405. case WLAN_ACCESS_NONE:
  1406. /*
  1407. * Deny all new authentications. However, if a station
  1408. * is ALREADY authenticated, then accept it.
  1409. */
  1410. for (i = 0; i < hw->authlist.cnt; i++)
  1411. if (ether_addr_equal(rec.address,
  1412. hw->authlist.addr[i])) {
  1413. rec.status = cpu_to_le16(P80211ENUM_status_successful);
  1414. break;
  1415. }
  1416. break;
  1417. case WLAN_ACCESS_ALL:
  1418. /*
  1419. * Allow all authentications.
  1420. */
  1421. rec.status = cpu_to_le16(P80211ENUM_status_successful);
  1422. break;
  1423. case WLAN_ACCESS_ALLOW:
  1424. /*
  1425. * Only allow the authentication if the MAC address
  1426. * is in the list of allowed addresses.
  1427. *
  1428. * Since this is the interrupt handler, we may be here
  1429. * while the access list is in the middle of being
  1430. * updated. Choose the list which is currently okay.
  1431. * See "prism2mib_priv_accessallow()" for details.
  1432. */
  1433. if (hw->allow.modify == 0) {
  1434. cnt = hw->allow.cnt;
  1435. addr = hw->allow.addr[0];
  1436. } else {
  1437. cnt = hw->allow.cnt1;
  1438. addr = hw->allow.addr1[0];
  1439. }
  1440. for (i = 0; i < cnt; i++, addr += ETH_ALEN)
  1441. if (ether_addr_equal(rec.address, addr)) {
  1442. rec.status = cpu_to_le16(P80211ENUM_status_successful);
  1443. break;
  1444. }
  1445. break;
  1446. case WLAN_ACCESS_DENY:
  1447. /*
  1448. * Allow the authentication UNLESS the MAC address is
  1449. * in the list of denied addresses.
  1450. *
  1451. * Since this is the interrupt handler, we may be here
  1452. * while the access list is in the middle of being
  1453. * updated. Choose the list which is currently okay.
  1454. * See "prism2mib_priv_accessdeny()" for details.
  1455. */
  1456. if (hw->deny.modify == 0) {
  1457. cnt = hw->deny.cnt;
  1458. addr = hw->deny.addr[0];
  1459. } else {
  1460. cnt = hw->deny.cnt1;
  1461. addr = hw->deny.addr1[0];
  1462. }
  1463. rec.status = cpu_to_le16(P80211ENUM_status_successful);
  1464. for (i = 0; i < cnt; i++, addr += ETH_ALEN)
  1465. if (ether_addr_equal(rec.address, addr)) {
  1466. rec.status = cpu_to_le16(P80211ENUM_status_unspec_failure);
  1467. break;
  1468. }
  1469. break;
  1470. }
  1471. /*
  1472. * If the authentication is okay, then add the MAC address to the
  1473. * list of authenticated stations. Don't add the address if it
  1474. * is already in the list. (802.11b does not seem to disallow
  1475. * a station from issuing an authentication request when the
  1476. * station is already authenticated. Does this sort of thing
  1477. * ever happen? We might as well do the check just in case.)
  1478. */
  1479. added = 0;
  1480. if (rec.status == cpu_to_le16(P80211ENUM_status_successful)) {
  1481. for (i = 0; i < hw->authlist.cnt; i++)
  1482. if (ether_addr_equal(rec.address,
  1483. hw->authlist.addr[i]))
  1484. break;
  1485. if (i >= hw->authlist.cnt) {
  1486. if (hw->authlist.cnt >= WLAN_AUTH_MAX) {
  1487. rec.status = cpu_to_le16(P80211ENUM_status_ap_full);
  1488. } else {
  1489. ether_addr_copy(hw->authlist.addr[hw->authlist.cnt],
  1490. rec.address);
  1491. hw->authlist.cnt++;
  1492. added = 1;
  1493. }
  1494. }
  1495. }
  1496. /*
  1497. * Send back the results of the authentication. If this doesn't work,
  1498. * then make sure to remove the address from the authenticated list if
  1499. * it was added.
  1500. */
  1501. rec.algorithm = inf->info.authreq.algorithm;
  1502. result = hfa384x_drvr_setconfig(hw, HFA384x_RID_AUTHENTICATESTA,
  1503. &rec, sizeof(rec));
  1504. if (result) {
  1505. if (added)
  1506. hw->authlist.cnt--;
  1507. netdev_err(wlandev->netdev,
  1508. "setconfig(authenticatestation) failed, result=%d\n",
  1509. result);
  1510. }
  1511. }
  1512. /*
  1513. * prism2sta_inf_psusercnt
  1514. *
  1515. * Handles the receipt of a PowerSaveUserCount info frame. Should
  1516. * be present in APs only.
  1517. *
  1518. * Arguments:
  1519. * wlandev wlan device structure
  1520. * inf ptr to info frame (contents in hfa384x order)
  1521. *
  1522. * Returns:
  1523. * nothing
  1524. *
  1525. * Side effects:
  1526. *
  1527. * Call context:
  1528. * interrupt
  1529. */
  1530. static void prism2sta_inf_psusercnt(struct wlandevice *wlandev,
  1531. struct hfa384x_inf_frame *inf)
  1532. {
  1533. struct hfa384x *hw = wlandev->priv;
  1534. hw->psusercount = le16_to_cpu(inf->info.psusercnt.usercnt);
  1535. }
  1536. /*
  1537. * prism2sta_ev_info
  1538. *
  1539. * Handles the Info event.
  1540. *
  1541. * Arguments:
  1542. * wlandev wlan device structure
  1543. * inf ptr to a generic info frame
  1544. *
  1545. * Returns:
  1546. * nothing
  1547. *
  1548. * Side effects:
  1549. *
  1550. * Call context:
  1551. * interrupt
  1552. */
  1553. void prism2sta_ev_info(struct wlandevice *wlandev,
  1554. struct hfa384x_inf_frame *inf)
  1555. {
  1556. le16_to_cpus(&inf->infotype);
  1557. /* Dispatch */
  1558. switch (inf->infotype) {
  1559. case HFA384x_IT_HANDOVERADDR:
  1560. prism2sta_inf_handover(wlandev, inf);
  1561. break;
  1562. case HFA384x_IT_COMMTALLIES:
  1563. prism2sta_inf_tallies(wlandev, inf);
  1564. break;
  1565. case HFA384x_IT_HOSTSCANRESULTS:
  1566. prism2sta_inf_hostscanresults(wlandev, inf);
  1567. break;
  1568. case HFA384x_IT_SCANRESULTS:
  1569. prism2sta_inf_scanresults(wlandev, inf);
  1570. break;
  1571. case HFA384x_IT_CHINFORESULTS:
  1572. prism2sta_inf_chinforesults(wlandev, inf);
  1573. break;
  1574. case HFA384x_IT_LINKSTATUS:
  1575. prism2sta_inf_linkstatus(wlandev, inf);
  1576. break;
  1577. case HFA384x_IT_ASSOCSTATUS:
  1578. prism2sta_inf_assocstatus(wlandev, inf);
  1579. break;
  1580. case HFA384x_IT_AUTHREQ:
  1581. prism2sta_inf_authreq(wlandev, inf);
  1582. break;
  1583. case HFA384x_IT_PSUSERCNT:
  1584. prism2sta_inf_psusercnt(wlandev, inf);
  1585. break;
  1586. case HFA384x_IT_KEYIDCHANGED:
  1587. netdev_warn(wlandev->netdev, "Unhandled IT_KEYIDCHANGED\n");
  1588. break;
  1589. case HFA384x_IT_ASSOCREQ:
  1590. netdev_warn(wlandev->netdev, "Unhandled IT_ASSOCREQ\n");
  1591. break;
  1592. case HFA384x_IT_MICFAILURE:
  1593. netdev_warn(wlandev->netdev, "Unhandled IT_MICFAILURE\n");
  1594. break;
  1595. default:
  1596. netdev_warn(wlandev->netdev,
  1597. "Unknown info type=0x%02x\n", inf->infotype);
  1598. break;
  1599. }
  1600. }
  1601. /*
  1602. * prism2sta_ev_txexc
  1603. *
  1604. * Handles the TxExc event. A Transmit Exception event indicates
  1605. * that the MAC's TX process was unsuccessful - so the packet did
  1606. * not get transmitted.
  1607. *
  1608. * Arguments:
  1609. * wlandev wlan device structure
  1610. * status tx frame status word
  1611. *
  1612. * Returns:
  1613. * nothing
  1614. *
  1615. * Side effects:
  1616. *
  1617. * Call context:
  1618. * interrupt
  1619. */
  1620. void prism2sta_ev_txexc(struct wlandevice *wlandev, u16 status)
  1621. {
  1622. pr_debug("TxExc status=0x%x.\n", status);
  1623. }
  1624. /*
  1625. * prism2sta_ev_tx
  1626. *
  1627. * Handles the Tx event.
  1628. *
  1629. * Arguments:
  1630. * wlandev wlan device structure
  1631. * status tx frame status word
  1632. * Returns:
  1633. * nothing
  1634. *
  1635. * Side effects:
  1636. *
  1637. * Call context:
  1638. * interrupt
  1639. */
  1640. void prism2sta_ev_tx(struct wlandevice *wlandev, u16 status)
  1641. {
  1642. pr_debug("Tx Complete, status=0x%04x\n", status);
  1643. /* update linux network stats */
  1644. wlandev->netdev->stats.tx_packets++;
  1645. }
  1646. /*
  1647. * prism2sta_ev_alloc
  1648. *
  1649. * Handles the Alloc event.
  1650. *
  1651. * Arguments:
  1652. * wlandev wlan device structure
  1653. *
  1654. * Returns:
  1655. * nothing
  1656. *
  1657. * Side effects:
  1658. *
  1659. * Call context:
  1660. * interrupt
  1661. */
  1662. void prism2sta_ev_alloc(struct wlandevice *wlandev)
  1663. {
  1664. netif_wake_queue(wlandev->netdev);
  1665. }
  1666. /*
  1667. * create_wlan
  1668. *
  1669. * Called at module init time. This creates the struct wlandevice structure
  1670. * and initializes it with relevant bits.
  1671. *
  1672. * Arguments:
  1673. * none
  1674. *
  1675. * Returns:
  1676. * the created struct wlandevice structure.
  1677. *
  1678. * Side effects:
  1679. * also allocates the priv/hw structures.
  1680. *
  1681. * Call context:
  1682. * process thread
  1683. *
  1684. */
  1685. static struct wlandevice *create_wlan(void)
  1686. {
  1687. struct wlandevice *wlandev = NULL;
  1688. struct hfa384x *hw = NULL;
  1689. /* Alloc our structures */
  1690. wlandev = kzalloc(sizeof(*wlandev), GFP_KERNEL);
  1691. hw = kzalloc(sizeof(*hw), GFP_KERNEL);
  1692. if (!wlandev || !hw) {
  1693. kfree(wlandev);
  1694. kfree(hw);
  1695. return NULL;
  1696. }
  1697. /* Initialize the network device object. */
  1698. wlandev->nsdname = dev_info;
  1699. wlandev->msdstate = WLAN_MSD_HWPRESENT_PENDING;
  1700. wlandev->priv = hw;
  1701. wlandev->open = prism2sta_open;
  1702. wlandev->close = prism2sta_close;
  1703. wlandev->reset = prism2sta_reset;
  1704. wlandev->txframe = prism2sta_txframe;
  1705. wlandev->mlmerequest = prism2sta_mlmerequest;
  1706. wlandev->set_multicast_list = prism2sta_setmulticast;
  1707. wlandev->tx_timeout = hfa384x_tx_timeout;
  1708. wlandev->nsdcaps = P80211_NSDCAP_HWFRAGMENT | P80211_NSDCAP_AUTOJOIN;
  1709. /* Initialize the device private data structure. */
  1710. hw->dot11_desired_bss_type = 1;
  1711. return wlandev;
  1712. }
  1713. void prism2sta_commsqual_defer(struct work_struct *data)
  1714. {
  1715. struct hfa384x *hw = container_of(data, struct hfa384x, commsqual_bh);
  1716. struct wlandevice *wlandev = hw->wlandev;
  1717. struct hfa384x_bytestr32 ssid;
  1718. struct p80211msg_dot11req_mibget msg;
  1719. struct p80211item_uint32 *mibitem = (struct p80211item_uint32 *)
  1720. &msg.mibattribute.data;
  1721. int result = 0;
  1722. if (hw->wlandev->hwremoved)
  1723. return;
  1724. /* we don't care if we're in AP mode */
  1725. if ((wlandev->macmode == WLAN_MACMODE_NONE) ||
  1726. (wlandev->macmode == WLAN_MACMODE_ESS_AP)) {
  1727. return;
  1728. }
  1729. /* It only makes sense to poll these in non-IBSS */
  1730. if (wlandev->macmode != WLAN_MACMODE_IBSS_STA) {
  1731. result = hfa384x_drvr_getconfig(hw, HFA384x_RID_DBMCOMMSQUALITY,
  1732. &hw->qual, HFA384x_RID_DBMCOMMSQUALITY_LEN);
  1733. if (result) {
  1734. netdev_err(wlandev->netdev, "error fetching commsqual\n");
  1735. return;
  1736. }
  1737. pr_debug("commsqual %d %d %d\n",
  1738. le16_to_cpu(hw->qual.cq_curr_bss),
  1739. le16_to_cpu(hw->qual.asl_curr_bss),
  1740. le16_to_cpu(hw->qual.anl_curr_fc));
  1741. }
  1742. /* Get the signal rate */
  1743. msg.msgcode = DIDmsg_dot11req_mibget;
  1744. mibitem->did = DIDmib_p2_p2MAC_p2CurrentTxRate;
  1745. result = p80211req_dorequest(wlandev, (u8 *)&msg);
  1746. if (result) {
  1747. pr_debug("get signal rate failed, result = %d\n",
  1748. result);
  1749. return;
  1750. }
  1751. switch (mibitem->data) {
  1752. case HFA384x_RATEBIT_1:
  1753. hw->txrate = 10;
  1754. break;
  1755. case HFA384x_RATEBIT_2:
  1756. hw->txrate = 20;
  1757. break;
  1758. case HFA384x_RATEBIT_5dot5:
  1759. hw->txrate = 55;
  1760. break;
  1761. case HFA384x_RATEBIT_11:
  1762. hw->txrate = 110;
  1763. break;
  1764. default:
  1765. pr_debug("Bad ratebit (%d)\n", mibitem->data);
  1766. }
  1767. /* Lastly, we need to make sure the BSSID didn't change on us */
  1768. result = hfa384x_drvr_getconfig(hw,
  1769. HFA384x_RID_CURRENTBSSID,
  1770. wlandev->bssid, WLAN_BSSID_LEN);
  1771. if (result) {
  1772. pr_debug("getconfig(0x%02x) failed, result = %d\n",
  1773. HFA384x_RID_CURRENTBSSID, result);
  1774. return;
  1775. }
  1776. result = hfa384x_drvr_getconfig(hw,
  1777. HFA384x_RID_CURRENTSSID,
  1778. &ssid, sizeof(ssid));
  1779. if (result) {
  1780. pr_debug("getconfig(0x%02x) failed, result = %d\n",
  1781. HFA384x_RID_CURRENTSSID, result);
  1782. return;
  1783. }
  1784. prism2mgmt_bytestr2pstr((struct hfa384x_bytestr *)&ssid,
  1785. (struct p80211pstrd *)&wlandev->ssid);
  1786. /* Reschedule timer */
  1787. mod_timer(&hw->commsqual_timer, jiffies + HZ);
  1788. }
  1789. void prism2sta_commsqual_timer(struct timer_list *t)
  1790. {
  1791. struct hfa384x *hw = from_timer(hw, t, commsqual_timer);
  1792. schedule_work(&hw->commsqual_bh);
  1793. }