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