Merge commit 'kumar/kumar-next' into next
[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 /*================================================================*/
54 /* System Includes */
55 #define WLAN_DBVAR      prism2_debug
56
57 #include "version.h"
58
59
60 #include <linux/version.h>
61
62 #include <linux/module.h>
63 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,25))
64 #include <linux/moduleparam.h>
65 #endif
66
67 #include <linux/kernel.h>
68 #include <linux/sched.h>
69 #include <linux/types.h>
70 #include <linux/init.h>
71 #include <linux/slab.h>
72 #include <linux/wireless.h>
73 #include <linux/netdevice.h>
74
75 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
76 #include <linux/tqueue.h>
77 #else
78 #include <linux/workqueue.h>
79 #endif
80
81 #include <asm/io.h>
82 #include <linux/delay.h>
83 #include <asm/byteorder.h>
84 #include <linux/if_arp.h>
85
86 #if (WLAN_HOSTIF == WLAN_PCMCIA)
87 #include <pcmcia/version.h>
88 #include <pcmcia/cs_types.h>
89 #include <pcmcia/cs.h>
90 #include <pcmcia/cistpl.h>
91 #include <pcmcia/ds.h>
92 #include <pcmcia/cisreg.h>
93 #endif
94
95 #include "wlan_compat.h"
96
97 #if ((WLAN_HOSTIF == WLAN_PLX) || (WLAN_HOSTIF == WLAN_PCI))
98 #include <linux/ioport.h>
99 #include <linux/pci.h>
100 #endif
101
102 /*================================================================*/
103 /* Project Includes */
104
105 #include "p80211types.h"
106 #include "p80211hdr.h"
107 #include "p80211mgmt.h"
108 #include "p80211conv.h"
109 #include "p80211msg.h"
110 #include "p80211netdev.h"
111 #include "p80211req.h"
112 #include "p80211metadef.h"
113 #include "p80211metastruct.h"
114 #include "hfa384x.h"
115 #include "prism2mgmt.h"
116
117 /*================================================================*/
118 /* Local Constants */
119
120 /*================================================================*/
121 /* Local Macros */
122
123 /*================================================================*/
124 /* Local Types */
125
126 /*================================================================*/
127 /* Local Static Definitions */
128
129 #if (WLAN_HOSTIF == WLAN_PCMCIA)
130 #define DRIVER_SUFFIX   "_cs"
131 #elif (WLAN_HOSTIF == WLAN_PLX)
132 #define DRIVER_SUFFIX   "_plx"
133 typedef char* dev_info_t;
134 #elif (WLAN_HOSTIF == WLAN_PCI)
135 #define DRIVER_SUFFIX   "_pci"
136 typedef char* dev_info_t;
137 #elif (WLAN_HOSTIF == WLAN_USB)
138 #define DRIVER_SUFFIX   "_usb"
139 typedef char* dev_info_t;
140 #else
141 #error "HOSTIF unsupported or undefined!"
142 #endif
143
144 static char             *version = "prism2" DRIVER_SUFFIX ".o: " WLAN_RELEASE;
145 static dev_info_t       dev_info = "prism2" DRIVER_SUFFIX;
146
147 #if (WLAN_HOSTIF == WLAN_PLX || WLAN_HOSTIF == WLAN_PCI)
148 #ifdef CONFIG_PM
149 static int prism2sta_suspend_pci(struct pci_dev *pdev, pm_message_t state);
150 static int prism2sta_resume_pci(struct pci_dev *pdev);
151 #endif
152 #endif
153
154 #if (WLAN_HOSTIF == WLAN_PCI)
155
156 #endif /* WLAN_PCI */
157
158 static wlandevice_t *create_wlan(void);
159
160 /*----------------------------------------------------------------*/
161 /* --Module Parameters */
162
163 int      prism2_reset_holdtime=30;      /* Reset hold time in ms */
164 int      prism2_reset_settletime=100;   /* Reset settle time in ms */
165
166 #if (WLAN_HOSTIF == WLAN_USB)
167 static int      prism2_doreset=0;               /* Do a reset at init? */
168 #else
169 static int      prism2_doreset=1;               /* Do a reset at init? */
170 int             prism2_bap_timeout=1000;        /* BAP timeout */
171 int             prism2_irq_evread_max=20;       /* Maximum number of
172                                                  * ev_reads (loops)
173                                                  * in irq handler
174                                                  */
175 #endif
176
177 #ifdef WLAN_INCLUDE_DEBUG
178 int prism2_debug=0;
179 module_param( prism2_debug, int, 0644);
180 MODULE_PARM_DESC(prism2_debug, "prism2 debugging");
181 #endif
182
183 module_param( prism2_doreset, int, 0644);
184 MODULE_PARM_DESC(prism2_doreset, "Issue a reset on initialization");
185
186 module_param( prism2_reset_holdtime, int, 0644);
187 MODULE_PARM_DESC( prism2_reset_holdtime, "reset hold time in ms");
188 module_param( prism2_reset_settletime, int, 0644);
189 MODULE_PARM_DESC( prism2_reset_settletime, "reset settle time in ms");
190
191 #if (WLAN_HOSTIF != WLAN_USB)
192 module_param( prism2_bap_timeout, int, 0644);
193 MODULE_PARM_DESC(prism2_bap_timeout, "BufferAccessPath Timeout in 10*n us");
194 module_param( prism2_irq_evread_max, int, 0644);
195 MODULE_PARM_DESC( prism2_irq_evread_max, "Maximim number of event reads in interrupt handler");
196 #endif
197
198 MODULE_LICENSE("Dual MPL/GPL");
199
200 /*================================================================*/
201 /* Local Function Declarations */
202
203 static int      prism2sta_open(wlandevice_t *wlandev);
204 static int      prism2sta_close(wlandevice_t *wlandev);
205 static void     prism2sta_reset(wlandevice_t *wlandev );
206 static int      prism2sta_txframe(wlandevice_t *wlandev, struct sk_buff *skb, p80211_hdr_t *p80211_hdr, p80211_metawep_t *p80211_wep);
207 static int      prism2sta_mlmerequest(wlandevice_t *wlandev, p80211msg_t *msg);
208 static int      prism2sta_getcardinfo(wlandevice_t *wlandev);
209 static int      prism2sta_globalsetup(wlandevice_t *wlandev);
210 static int      prism2sta_setmulticast(wlandevice_t *wlandev,
211                                        netdevice_t *dev);
212
213 static void     prism2sta_inf_handover(
214                         wlandevice_t *wlandev, hfa384x_InfFrame_t *inf);
215 static void     prism2sta_inf_tallies(
216                         wlandevice_t *wlandev, hfa384x_InfFrame_t *inf);
217 static void     prism2sta_inf_hostscanresults(
218                         wlandevice_t *wlandev, hfa384x_InfFrame_t *inf);
219 static void     prism2sta_inf_scanresults(
220                         wlandevice_t *wlandev, hfa384x_InfFrame_t *inf);
221 static void     prism2sta_inf_chinforesults(
222                         wlandevice_t *wlandev, hfa384x_InfFrame_t *inf);
223 static void     prism2sta_inf_linkstatus(
224                         wlandevice_t *wlandev, hfa384x_InfFrame_t *inf);
225 static void     prism2sta_inf_assocstatus(
226                         wlandevice_t *wlandev, hfa384x_InfFrame_t *inf);
227 static void     prism2sta_inf_authreq(
228                         wlandevice_t *wlandev, hfa384x_InfFrame_t *inf);
229 static void     prism2sta_inf_authreq_defer(
230                         wlandevice_t *wlandev, hfa384x_InfFrame_t *inf);
231 static void     prism2sta_inf_psusercnt(
232                         wlandevice_t *wlandev, hfa384x_InfFrame_t *inf);
233
234 #ifdef CONFIG_PROC_FS
235 static int
236 prism2sta_proc_read(
237         char    *page,
238         char    **start,
239         off_t   offset,
240         int     count,
241         int     *eof,
242         void    *data);
243 #endif
244
245 /*================================================================*/
246 /* Function Definitions */
247
248 /*----------------------------------------------------------------
249 * dmpmem
250 *
251 * Debug utility function to dump memory to the kernel debug log.
252 *
253 * Arguments:
254 *       buf     ptr data we want dumped
255 *       len     length of data
256 *
257 * Returns:
258 *       nothing
259 * Side effects:
260 *
261 * Call context:
262 *       process thread
263 *       interrupt
264 ----------------------------------------------------------------*/
265 inline void dmpmem(void *buf, int n)
266 {
267         int c;
268         for ( c= 0; c < n; c++) {
269                 if ( (c % 16) == 0 ) printk(KERN_DEBUG"dmp[%d]: ", c);
270                 printk("%02x ", ((UINT8*)buf)[c]);
271                 if ( (c % 16) == 15 ) printk("\n");
272         }
273         if ( (c % 16) != 0 ) printk("\n");
274 }
275
276
277 /*----------------------------------------------------------------
278 * prism2sta_open
279 *
280 * WLAN device open method.  Called from p80211netdev when kernel
281 * device open (start) method is called in response to the
282 * SIOCSIIFFLAGS ioctl changing the flags bit IFF_UP
283 * from clear to set.
284 *
285 * Arguments:
286 *       wlandev         wlan device structure
287 *
288 * Returns:
289 *       0       success
290 *       >0      f/w reported error
291 *       <0      driver reported error
292 *
293 * Side effects:
294 *
295 * Call context:
296 *       process thread
297 ----------------------------------------------------------------*/
298 static int prism2sta_open(wlandevice_t *wlandev)
299 {
300         DBFENTER;
301
302 #ifdef ANCIENT_MODULE_CODE
303         MOD_INC_USE_COUNT;
304 #endif
305
306         /* We don't currently have to do anything else.
307          * The setup of the MAC should be subsequently completed via
308          * the mlme commands.
309          * Higher layers know we're ready from dev->start==1 and
310          * dev->tbusy==0.  Our rx path knows to pass up received/
311          * frames because of dev->flags&IFF_UP is true.
312          */
313
314         DBFEXIT;
315         return 0;
316 }
317
318
319 /*----------------------------------------------------------------
320 * prism2sta_close
321 *
322 * WLAN device close method.  Called from p80211netdev when kernel
323 * device close method is called in response to the
324 * SIOCSIIFFLAGS ioctl changing the flags bit IFF_UP
325 * from set to clear.
326 *
327 * Arguments:
328 *       wlandev         wlan device structure
329 *
330 * Returns:
331 *       0       success
332 *       >0      f/w reported error
333 *       <0      driver reported error
334 *
335 * Side effects:
336 *
337 * Call context:
338 *       process thread
339 ----------------------------------------------------------------*/
340 static int prism2sta_close(wlandevice_t *wlandev)
341 {
342         DBFENTER;
343
344 #ifdef ANCIENT_MODULE_CODE
345         MOD_DEC_USE_COUNT;
346 #endif
347
348         /* We don't currently have to do anything else.
349          * Higher layers know we're not ready from dev->start==0 and
350          * dev->tbusy==1.  Our rx path knows to not pass up received
351          * frames because of dev->flags&IFF_UP is false.
352          */
353
354         DBFEXIT;
355         return 0;
356 }
357
358
359 /*----------------------------------------------------------------
360 * prism2sta_reset
361 *
362 * Not currently implented.
363 *
364 * Arguments:
365 *       wlandev         wlan device structure
366 *       none
367 *
368 * Returns:
369 *       nothing
370 *
371 * Side effects:
372 *
373 * Call context:
374 *       process thread
375 ----------------------------------------------------------------*/
376 static void prism2sta_reset(wlandevice_t *wlandev )
377 {
378         DBFENTER;
379         DBFEXIT;
380         return;
381 }
382
383
384 /*----------------------------------------------------------------
385 * prism2sta_txframe
386 *
387 * Takes a frame from p80211 and queues it for transmission.
388 *
389 * Arguments:
390 *       wlandev         wlan device structure
391 *       pb              packet buffer struct.  Contains an 802.11
392 *                       data frame.
393 *       p80211_hdr      points to the 802.11 header for the packet.
394 * Returns:
395 *       0               Success and more buffs available
396 *       1               Success but no more buffs
397 *       2               Allocation failure
398 *       4               Buffer full or queue busy
399 *
400 * Side effects:
401 *
402 * Call context:
403 *       process thread
404 ----------------------------------------------------------------*/
405 static int prism2sta_txframe(wlandevice_t *wlandev, struct sk_buff *skb,
406                              p80211_hdr_t *p80211_hdr,
407                              p80211_metawep_t *p80211_wep)
408 {
409         hfa384x_t               *hw = (hfa384x_t *)wlandev->priv;
410         int                     result;
411         DBFENTER;
412
413         /* If necessary, set the 802.11 WEP bit */
414         if ((wlandev->hostwep & (HOSTWEP_PRIVACYINVOKED | HOSTWEP_ENCRYPT)) == HOSTWEP_PRIVACYINVOKED) {
415                 p80211_hdr->a3.fc |= host2ieee16(WLAN_SET_FC_ISWEP(1));
416         }
417
418         result = hfa384x_drvr_txframe(hw, skb, p80211_hdr, p80211_wep);
419
420         DBFEXIT;
421         return result;
422 }
423
424
425 /*----------------------------------------------------------------
426 * prism2sta_mlmerequest
427 *
428 * wlan command message handler.  All we do here is pass the message
429 * over to the prism2sta_mgmt_handler.
430 *
431 * Arguments:
432 *       wlandev         wlan device structure
433 *       msg             wlan command message
434 * Returns:
435 *       0               success
436 *       <0              successful acceptance of message, but we're
437 *                       waiting for an async process to finish before
438 *                       we're done with the msg.  When the asynch
439 *                       process is done, we'll call the p80211
440 *                       function p80211req_confirm() .
441 *       >0              An error occurred while we were handling
442 *                       the message.
443 *
444 * Side effects:
445 *
446 * Call context:
447 *       process thread
448 ----------------------------------------------------------------*/
449 static int prism2sta_mlmerequest(wlandevice_t *wlandev, p80211msg_t *msg)
450 {
451         hfa384x_t               *hw = (hfa384x_t *)wlandev->priv;
452
453         int result = 0;
454         DBFENTER;
455
456         switch( msg->msgcode )
457         {
458         case DIDmsg_dot11req_mibget :
459                 WLAN_LOG_DEBUG(2,"Received mibget request\n");
460                 result = prism2mgmt_mibset_mibget(wlandev, msg);
461                 break;
462         case DIDmsg_dot11req_mibset :
463                 WLAN_LOG_DEBUG(2,"Received mibset request\n");
464                 result = prism2mgmt_mibset_mibget(wlandev, msg);
465                 break;
466         case DIDmsg_dot11req_powermgmt :
467                 WLAN_LOG_DEBUG(2,"Received powermgmt request\n");
468                 result = prism2mgmt_powermgmt(wlandev, msg);
469                 break;
470         case DIDmsg_dot11req_scan :
471                 WLAN_LOG_DEBUG(2,"Received scan request\n");
472                 result = prism2mgmt_scan(wlandev, msg);
473                 break;
474         case DIDmsg_dot11req_scan_results :
475                 WLAN_LOG_DEBUG(2,"Received scan_results request\n");
476                 result = prism2mgmt_scan_results(wlandev, msg);
477                 break;
478         case DIDmsg_dot11req_join :
479                 WLAN_LOG_DEBUG(2,"Received join request\n");
480                 result = prism2mgmt_join(wlandev, msg);
481                 break;
482         case DIDmsg_dot11req_authenticate :
483                 WLAN_LOG_DEBUG(2,"Received authenticate request\n");
484                 result = prism2mgmt_authenticate(wlandev, msg);
485                 break;
486         case DIDmsg_dot11req_deauthenticate :
487                 WLAN_LOG_DEBUG(2,"Received mlme deauthenticate request\n");
488                 result = prism2mgmt_deauthenticate(wlandev, msg);
489                 break;
490         case DIDmsg_dot11req_associate :
491                 WLAN_LOG_DEBUG(2,"Received mlme associate request\n");
492                 result = prism2mgmt_associate(wlandev, msg);
493                 break;
494         case DIDmsg_dot11req_reassociate :
495                 WLAN_LOG_DEBUG(2,"Received mlme reassociate request\n");
496                 result = prism2mgmt_reassociate(wlandev, msg);
497                 break;
498         case DIDmsg_dot11req_disassociate :
499                 WLAN_LOG_DEBUG(2,"Received mlme disassociate request\n");
500                 result = prism2mgmt_disassociate(wlandev, msg);
501                 break;
502         case DIDmsg_dot11req_reset :
503                 WLAN_LOG_DEBUG(2,"Received mlme reset request\n");
504                 result = prism2mgmt_reset(wlandev, msg);
505                 break;
506         case DIDmsg_dot11req_start :
507                 WLAN_LOG_DEBUG(2,"Received mlme start request\n");
508                 result = prism2mgmt_start(wlandev, msg);
509                 break;
510         /*
511          * Prism2 specific messages
512          */
513         case DIDmsg_p2req_join :
514                 WLAN_LOG_DEBUG(2,"Received p2 join request\n");
515                 result = prism2mgmt_p2_join(wlandev, msg);
516                 break;
517         case DIDmsg_p2req_readpda :
518                 WLAN_LOG_DEBUG(2,"Received mlme readpda request\n");
519                 result = prism2mgmt_readpda(wlandev, msg);
520                 break;
521         case DIDmsg_p2req_readcis :
522                 WLAN_LOG_DEBUG(2,"Received mlme readcis request\n");
523                 result = prism2mgmt_readcis(wlandev, msg);
524                 break;
525         case DIDmsg_p2req_auxport_state :
526                 WLAN_LOG_DEBUG(2,"Received mlme auxport_state request\n");
527                 result = prism2mgmt_auxport_state(wlandev, msg);
528                 break;
529         case DIDmsg_p2req_auxport_read :
530                 WLAN_LOG_DEBUG(2,"Received mlme auxport_read request\n");
531                 result = prism2mgmt_auxport_read(wlandev, msg);
532                 break;
533         case DIDmsg_p2req_auxport_write :
534                 WLAN_LOG_DEBUG(2,"Received mlme auxport_write request\n");
535                 result = prism2mgmt_auxport_write(wlandev, msg);
536                 break;
537         case DIDmsg_p2req_low_level :
538                 WLAN_LOG_DEBUG(2,"Received mlme low_level request\n");
539                 result = prism2mgmt_low_level(wlandev, msg);
540                 break;
541         case DIDmsg_p2req_test_command :
542                 WLAN_LOG_DEBUG(2,"Received mlme test_command request\n");
543                 result = prism2mgmt_test_command(wlandev, msg);
544                 break;
545         case DIDmsg_p2req_mmi_read :
546                 WLAN_LOG_DEBUG(2,"Received mlme mmi_read request\n");
547                 result = prism2mgmt_mmi_read(wlandev, msg);
548                 break;
549         case DIDmsg_p2req_mmi_write :
550                 WLAN_LOG_DEBUG(2,"Received mlme mmi_write request\n");
551                 result = prism2mgmt_mmi_write(wlandev, msg);
552                 break;
553         case DIDmsg_p2req_ramdl_state :
554                 WLAN_LOG_DEBUG(2,"Received mlme ramdl_state request\n");
555                 result = prism2mgmt_ramdl_state(wlandev, msg);
556                 break;
557         case DIDmsg_p2req_ramdl_write :
558                 WLAN_LOG_DEBUG(2,"Received mlme ramdl_write request\n");
559                 result = prism2mgmt_ramdl_write(wlandev, msg);
560                 break;
561         case DIDmsg_p2req_flashdl_state :
562                 WLAN_LOG_DEBUG(2,"Received mlme flashdl_state request\n");
563                 result = prism2mgmt_flashdl_state(wlandev, msg);
564                 break;
565         case DIDmsg_p2req_flashdl_write :
566                 WLAN_LOG_DEBUG(2,"Received mlme flashdl_write request\n");
567                 result = prism2mgmt_flashdl_write(wlandev, msg);
568                 break;
569         case DIDmsg_p2req_dump_state :
570                 WLAN_LOG_DEBUG(2,"Received mlme dump_state request\n");
571                 result = prism2mgmt_dump_state(wlandev, msg);
572                 break;
573         case DIDmsg_p2req_channel_info :
574                 WLAN_LOG_DEBUG(2,"Received mlme channel_info request\n");
575                 result = prism2mgmt_channel_info(wlandev, msg);
576                 break;
577         case DIDmsg_p2req_channel_info_results :
578                 WLAN_LOG_DEBUG(2,"Received mlme channel_info_results request\n");
579                 result = prism2mgmt_channel_info_results(wlandev, msg);
580                 break;
581         /*
582          * Linux specific messages
583          */
584         case DIDmsg_lnxreq_hostwep :
585                 break;   // ignore me.
586         case DIDmsg_lnxreq_ifstate :
587                 {
588                 p80211msg_lnxreq_ifstate_t      *ifstatemsg;
589                 WLAN_LOG_DEBUG(2,"Received mlme ifstate request\n");
590                 ifstatemsg = (p80211msg_lnxreq_ifstate_t*)msg;
591                 result = prism2sta_ifstate(wlandev, ifstatemsg->ifstate.data);
592                 ifstatemsg->resultcode.status =
593                         P80211ENUM_msgitem_status_data_ok;
594                 ifstatemsg->resultcode.data = result;
595                 result = 0;
596                 }
597                 break;
598         case DIDmsg_lnxreq_wlansniff :
599                 WLAN_LOG_DEBUG(2,"Received mlme wlansniff request\n");
600                 result = prism2mgmt_wlansniff(wlandev, msg);
601                 break;
602         case DIDmsg_lnxreq_autojoin :
603                 WLAN_LOG_DEBUG(2,"Received mlme autojoin request\n");
604                 result = prism2mgmt_autojoin(wlandev, msg);
605                 break;
606         case DIDmsg_p2req_enable :
607                 WLAN_LOG_DEBUG(2,"Received mlme enable request\n");
608                 result = prism2mgmt_enable(wlandev, msg);
609                 break;
610         case DIDmsg_lnxreq_commsquality: {
611                 p80211msg_lnxreq_commsquality_t *qualmsg;
612
613                 WLAN_LOG_DEBUG(2,"Received commsquality request\n");
614
615                 if (hw->ap)
616                         break;
617
618                 qualmsg = (p80211msg_lnxreq_commsquality_t*) msg;
619
620                 qualmsg->link.status = P80211ENUM_msgitem_status_data_ok;
621                 qualmsg->level.status = P80211ENUM_msgitem_status_data_ok;
622                 qualmsg->noise.status = P80211ENUM_msgitem_status_data_ok;
623
624
625                 qualmsg->link.data = hfa384x2host_16(hw->qual.CQ_currBSS);
626                 qualmsg->level.data = hfa384x2host_16(hw->qual.ASL_currBSS);
627                 qualmsg->noise.data = hfa384x2host_16(hw->qual.ANL_currFC);
628
629                 break;
630         }
631         default:
632                 WLAN_LOG_WARNING("Unknown mgmt request message 0x%08x", msg->msgcode);
633                 break;
634         }
635
636         DBFEXIT;
637         return result;
638 }
639
640
641 /*----------------------------------------------------------------
642 * prism2sta_ifstate
643 *
644 * Interface state.  This is the primary WLAN interface enable/disable
645 * handler.  Following the driver/load/deviceprobe sequence, this
646 * function must be called with a state of "enable" before any other
647 * commands will be accepted.
648 *
649 * Arguments:
650 *       wlandev         wlan device structure
651 *       msgp            ptr to msg buffer
652 *
653 * Returns:
654 *       A p80211 message resultcode value.
655 *
656 * Side effects:
657 *
658 * Call context:
659 *       process thread  (usually)
660 *       interrupt
661 ----------------------------------------------------------------*/
662 UINT32 prism2sta_ifstate(wlandevice_t *wlandev, UINT32 ifstate)
663 {
664         hfa384x_t               *hw = (hfa384x_t *)wlandev->priv;
665         UINT32                  result;
666         DBFENTER;
667
668         result = P80211ENUM_resultcode_implementation_failure;
669
670         WLAN_LOG_DEBUG(2, "Current MSD state(%d), requesting(%d)\n",
671                           wlandev->msdstate, ifstate);
672         switch (ifstate)
673         {
674         case P80211ENUM_ifstate_fwload:
675                 switch (wlandev->msdstate) {
676                 case WLAN_MSD_HWPRESENT:
677                         wlandev->msdstate = WLAN_MSD_FWLOAD_PENDING;
678                         /*
679                          * Initialize the device+driver sufficiently
680                          * for firmware loading.
681                          */
682 #if (WLAN_HOSTIF != WLAN_USB)
683                         result=hfa384x_cmd_initialize(hw);
684 #else
685                         if ((result=hfa384x_drvr_start(hw))) {
686                                 WLAN_LOG_ERROR(
687                                         "hfa384x_drvr_start() failed,"
688                                         "result=%d\n", (int)result);
689                                 result =
690                                 P80211ENUM_resultcode_implementation_failure;
691                                 wlandev->msdstate = WLAN_MSD_HWPRESENT;
692                                 break;
693                         }
694 #endif
695                         wlandev->msdstate = WLAN_MSD_FWLOAD;
696                         result = P80211ENUM_resultcode_success;
697                         break;
698                 case WLAN_MSD_FWLOAD:
699                         hfa384x_cmd_initialize(hw);
700                         result = P80211ENUM_resultcode_success;
701                         break;
702                 case WLAN_MSD_RUNNING:
703                         WLAN_LOG_WARNING(
704                                 "Cannot enter fwload state from enable state,"
705                                 "you must disable first.\n");
706                         result = P80211ENUM_resultcode_invalid_parameters;
707                         break;
708                 case WLAN_MSD_HWFAIL:
709                 default:
710                         /* probe() had a problem or the msdstate contains
711                          * an unrecognized value, there's nothing we can do.
712                          */
713                         result = P80211ENUM_resultcode_implementation_failure;
714                         break;
715                 }
716                 break;
717         case P80211ENUM_ifstate_enable:
718                 switch (wlandev->msdstate) {
719                 case WLAN_MSD_HWPRESENT:
720                 case WLAN_MSD_FWLOAD:
721                         wlandev->msdstate = WLAN_MSD_RUNNING_PENDING;
722                         /* Initialize the device+driver for full
723                          * operation. Note that this might me an FWLOAD to
724                          * to RUNNING transition so we must not do a chip
725                          * or board level reset.  Note that on failure,
726                          * the MSD state is set to HWPRESENT because we
727                          * can't make any assumptions about the state
728                          * of the hardware or a previous firmware load.
729                          */
730                         if ((result=hfa384x_drvr_start(hw))) {
731                                 WLAN_LOG_ERROR(
732                                         "hfa384x_drvr_start() failed,"
733                                         "result=%d\n", (int)result);
734                                 result =
735                                 P80211ENUM_resultcode_implementation_failure;
736                                 wlandev->msdstate = WLAN_MSD_HWPRESENT;
737                                 break;
738                         }
739
740                         if ((result=prism2sta_getcardinfo(wlandev))) {
741                                 WLAN_LOG_ERROR(
742                                         "prism2sta_getcardinfo() failed,"
743                                         "result=%d\n", (int)result);
744                                 result =
745                                 P80211ENUM_resultcode_implementation_failure;
746                                 hfa384x_drvr_stop(hw);
747                                 wlandev->msdstate = WLAN_MSD_HWPRESENT;
748                                 break;
749                         }
750                         if ((result=prism2sta_globalsetup(wlandev))) {
751                                 WLAN_LOG_ERROR(
752                                         "prism2sta_globalsetup() failed,"
753                                         "result=%d\n", (int)result);
754                                 result =
755                                 P80211ENUM_resultcode_implementation_failure;
756                                 hfa384x_drvr_stop(hw);
757                                 wlandev->msdstate = WLAN_MSD_HWPRESENT;
758                                 break;
759                         }
760                         wlandev->msdstate = WLAN_MSD_RUNNING;
761                         hw->join_ap = 0;
762                         hw->join_retries = 60;
763                         result = P80211ENUM_resultcode_success;
764                         break;
765                 case WLAN_MSD_RUNNING:
766                         /* Do nothing, we're already in this state.*/
767                         result = P80211ENUM_resultcode_success;
768                         break;
769                 case WLAN_MSD_HWFAIL:
770                 default:
771                         /* probe() had a problem or the msdstate contains
772                          * an unrecognized value, there's nothing we can do.
773                          */
774                         result = P80211ENUM_resultcode_implementation_failure;
775                         break;
776                 }
777                 break;
778         case P80211ENUM_ifstate_disable:
779                 switch (wlandev->msdstate) {
780                 case WLAN_MSD_HWPRESENT:
781                         /* Do nothing, we're already in this state.*/
782                         result = P80211ENUM_resultcode_success;
783                         break;
784                 case WLAN_MSD_FWLOAD:
785                 case WLAN_MSD_RUNNING:
786                         wlandev->msdstate = WLAN_MSD_HWPRESENT_PENDING;
787                         /*
788                          * TODO: Shut down the MAC completely. Here a chip
789                          * or board level reset is probably called for.
790                          * After a "disable" _all_ results are lost, even
791                          * those from a fwload.
792                          */
793                         if (!wlandev->hwremoved)
794                                 netif_carrier_off(wlandev->netdev);
795
796                         hfa384x_drvr_stop(hw);
797
798                         wlandev->macmode = WLAN_MACMODE_NONE;
799                         wlandev->msdstate = WLAN_MSD_HWPRESENT;
800                         result = P80211ENUM_resultcode_success;
801                         break;
802                 case WLAN_MSD_HWFAIL:
803                 default:
804                         /* probe() had a problem or the msdstate contains
805                          * an unrecognized value, there's nothing we can do.
806                          */
807                         result = P80211ENUM_resultcode_implementation_failure;
808                         break;
809                 }
810                 break;
811         default:
812                 result = P80211ENUM_resultcode_invalid_parameters;
813                 break;
814         }
815
816         DBFEXIT;
817         return result;
818 }
819
820
821 /*----------------------------------------------------------------
822 * prism2sta_getcardinfo
823 *
824 * Collect the NICID, firmware version and any other identifiers
825 * we'd like to have in host-side data structures.
826 *
827 * Arguments:
828 *       wlandev         wlan device structure
829 *
830 * Returns:
831 *       0       success
832 *       >0      f/w reported error
833 *       <0      driver reported error
834 *
835 * Side effects:
836 *
837 * Call context:
838 *       Either.
839 ----------------------------------------------------------------*/
840 static int prism2sta_getcardinfo(wlandevice_t *wlandev)
841 {
842         int                     result = 0;
843         hfa384x_t               *hw = (hfa384x_t *)wlandev->priv;
844         UINT16                  temp;
845         UINT8                   snum[HFA384x_RID_NICSERIALNUMBER_LEN];
846         char                    pstr[(HFA384x_RID_NICSERIALNUMBER_LEN * 4) + 1];
847
848         DBFENTER;
849
850         /* Collect version and compatibility info */
851         /*  Some are critical, some are not */
852         /* NIC identity */
853         result = hfa384x_drvr_getconfig(hw, HFA384x_RID_NICIDENTITY,
854                         &hw->ident_nic, sizeof(hfa384x_compident_t));
855         if ( result ) {
856                 WLAN_LOG_ERROR("Failed to retrieve NICIDENTITY\n");
857                 goto failed;
858         }
859
860         /* get all the nic id fields in host byte order */
861         hw->ident_nic.id = hfa384x2host_16(hw->ident_nic.id);
862         hw->ident_nic.variant = hfa384x2host_16(hw->ident_nic.variant);
863         hw->ident_nic.major = hfa384x2host_16(hw->ident_nic.major);
864         hw->ident_nic.minor = hfa384x2host_16(hw->ident_nic.minor);
865
866         WLAN_LOG_INFO( "ident: nic h/w: id=0x%02x %d.%d.%d\n",
867                         hw->ident_nic.id, hw->ident_nic.major,
868                         hw->ident_nic.minor, hw->ident_nic.variant);
869
870         /* Primary f/w identity */
871         result = hfa384x_drvr_getconfig(hw, HFA384x_RID_PRIIDENTITY,
872                         &hw->ident_pri_fw, sizeof(hfa384x_compident_t));
873         if ( result ) {
874                 WLAN_LOG_ERROR("Failed to retrieve PRIIDENTITY\n");
875                 goto failed;
876         }
877
878         /* get all the private fw id fields in host byte order */
879         hw->ident_pri_fw.id = hfa384x2host_16(hw->ident_pri_fw.id);
880         hw->ident_pri_fw.variant = hfa384x2host_16(hw->ident_pri_fw.variant);
881         hw->ident_pri_fw.major = hfa384x2host_16(hw->ident_pri_fw.major);
882         hw->ident_pri_fw.minor = hfa384x2host_16(hw->ident_pri_fw.minor);
883
884         WLAN_LOG_INFO( "ident: pri f/w: id=0x%02x %d.%d.%d\n",
885                         hw->ident_pri_fw.id, hw->ident_pri_fw.major,
886                         hw->ident_pri_fw.minor, hw->ident_pri_fw.variant);
887
888         /* Station (Secondary?) f/w identity */
889         result = hfa384x_drvr_getconfig(hw, HFA384x_RID_STAIDENTITY,
890                         &hw->ident_sta_fw, sizeof(hfa384x_compident_t));
891         if ( result ) {
892                 WLAN_LOG_ERROR("Failed to retrieve STAIDENTITY\n");
893                 goto failed;
894         }
895
896         if (hw->ident_nic.id < 0x8000) {
897                 WLAN_LOG_ERROR("FATAL: Card is not an Intersil Prism2/2.5/3\n");
898                 result = -1;
899                 goto failed;
900         }
901
902         /* get all the station fw id fields in host byte order */
903         hw->ident_sta_fw.id = hfa384x2host_16(hw->ident_sta_fw.id);
904         hw->ident_sta_fw.variant = hfa384x2host_16(hw->ident_sta_fw.variant);
905         hw->ident_sta_fw.major = hfa384x2host_16(hw->ident_sta_fw.major);
906         hw->ident_sta_fw.minor = hfa384x2host_16(hw->ident_sta_fw.minor);
907
908         /* strip out the 'special' variant bits */
909         hw->mm_mods = hw->ident_sta_fw.variant & (BIT14 | BIT15);
910         hw->ident_sta_fw.variant &= ~((UINT16)(BIT14 | BIT15));
911
912         if  ( hw->ident_sta_fw.id == 0x1f ) {
913                 hw->ap = 0;
914                 WLAN_LOG_INFO(
915                         "ident: sta f/w: id=0x%02x %d.%d.%d\n",
916                         hw->ident_sta_fw.id, hw->ident_sta_fw.major,
917                         hw->ident_sta_fw.minor, hw->ident_sta_fw.variant);
918         } else {
919                 hw->ap = 1;
920                 WLAN_LOG_INFO(
921                         "ident:  ap f/w: id=0x%02x %d.%d.%d\n",
922                         hw->ident_sta_fw.id, hw->ident_sta_fw.major,
923                         hw->ident_sta_fw.minor, hw->ident_sta_fw.variant);
924         }
925
926         /* Compatibility range, Modem supplier */
927         result = hfa384x_drvr_getconfig(hw, HFA384x_RID_MFISUPRANGE,
928                         &hw->cap_sup_mfi, sizeof(hfa384x_caplevel_t));
929         if ( result ) {
930                 WLAN_LOG_ERROR("Failed to retrieve MFISUPRANGE\n");
931                 goto failed;
932         }
933
934         /* get all the Compatibility range, modem interface supplier
935         fields in byte order */
936         hw->cap_sup_mfi.role = hfa384x2host_16(hw->cap_sup_mfi.role);
937         hw->cap_sup_mfi.id = hfa384x2host_16(hw->cap_sup_mfi.id);
938         hw->cap_sup_mfi.variant = hfa384x2host_16(hw->cap_sup_mfi.variant);
939         hw->cap_sup_mfi.bottom = hfa384x2host_16(hw->cap_sup_mfi.bottom);
940         hw->cap_sup_mfi.top = hfa384x2host_16(hw->cap_sup_mfi.top);
941
942         WLAN_LOG_INFO(
943                 "MFI:SUP:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
944                 hw->cap_sup_mfi.role, hw->cap_sup_mfi.id,
945                 hw->cap_sup_mfi.variant, hw->cap_sup_mfi.bottom,
946                 hw->cap_sup_mfi.top);
947
948         /* Compatibility range, Controller supplier */
949         result = hfa384x_drvr_getconfig(hw, HFA384x_RID_CFISUPRANGE,
950                         &hw->cap_sup_cfi, sizeof(hfa384x_caplevel_t));
951         if ( result ) {
952                 WLAN_LOG_ERROR("Failed to retrieve CFISUPRANGE\n");
953                 goto failed;
954         }
955
956         /* get all the Compatibility range, controller interface supplier
957         fields in byte order */
958         hw->cap_sup_cfi.role = hfa384x2host_16(hw->cap_sup_cfi.role);
959         hw->cap_sup_cfi.id = hfa384x2host_16(hw->cap_sup_cfi.id);
960         hw->cap_sup_cfi.variant = hfa384x2host_16(hw->cap_sup_cfi.variant);
961         hw->cap_sup_cfi.bottom = hfa384x2host_16(hw->cap_sup_cfi.bottom);
962         hw->cap_sup_cfi.top = hfa384x2host_16(hw->cap_sup_cfi.top);
963
964         WLAN_LOG_INFO(
965                 "CFI:SUP:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
966                 hw->cap_sup_cfi.role, hw->cap_sup_cfi.id,
967                 hw->cap_sup_cfi.variant, hw->cap_sup_cfi.bottom,
968                 hw->cap_sup_cfi.top);
969
970         /* Compatibility range, Primary f/w supplier */
971         result = hfa384x_drvr_getconfig(hw, HFA384x_RID_PRISUPRANGE,
972                         &hw->cap_sup_pri, sizeof(hfa384x_caplevel_t));
973         if ( result ) {
974                 WLAN_LOG_ERROR("Failed to retrieve PRISUPRANGE\n");
975                 goto failed;
976         }
977
978         /* get all the Compatibility range, primary firmware supplier
979         fields in byte order */
980         hw->cap_sup_pri.role = hfa384x2host_16(hw->cap_sup_pri.role);
981         hw->cap_sup_pri.id = hfa384x2host_16(hw->cap_sup_pri.id);
982         hw->cap_sup_pri.variant = hfa384x2host_16(hw->cap_sup_pri.variant);
983         hw->cap_sup_pri.bottom = hfa384x2host_16(hw->cap_sup_pri.bottom);
984         hw->cap_sup_pri.top = hfa384x2host_16(hw->cap_sup_pri.top);
985
986         WLAN_LOG_INFO(
987                 "PRI:SUP:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
988                 hw->cap_sup_pri.role, hw->cap_sup_pri.id,
989                 hw->cap_sup_pri.variant, hw->cap_sup_pri.bottom,
990                 hw->cap_sup_pri.top);
991
992         /* Compatibility range, Station f/w supplier */
993         result = hfa384x_drvr_getconfig(hw, HFA384x_RID_STASUPRANGE,
994                         &hw->cap_sup_sta, sizeof(hfa384x_caplevel_t));
995         if ( result ) {
996                 WLAN_LOG_ERROR("Failed to retrieve STASUPRANGE\n");
997                 goto failed;
998         }
999
1000         /* get all the Compatibility range, station firmware supplier
1001         fields in byte order */
1002         hw->cap_sup_sta.role = hfa384x2host_16(hw->cap_sup_sta.role);
1003         hw->cap_sup_sta.id = hfa384x2host_16(hw->cap_sup_sta.id);
1004         hw->cap_sup_sta.variant = hfa384x2host_16(hw->cap_sup_sta.variant);
1005         hw->cap_sup_sta.bottom = hfa384x2host_16(hw->cap_sup_sta.bottom);
1006         hw->cap_sup_sta.top = hfa384x2host_16(hw->cap_sup_sta.top);
1007
1008         if ( hw->cap_sup_sta.id == 0x04 ) {
1009                 WLAN_LOG_INFO(
1010                 "STA:SUP:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
1011                 hw->cap_sup_sta.role, hw->cap_sup_sta.id,
1012                 hw->cap_sup_sta.variant, hw->cap_sup_sta.bottom,
1013                 hw->cap_sup_sta.top);
1014         } else {
1015                 WLAN_LOG_INFO(
1016                 "AP:SUP:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
1017                 hw->cap_sup_sta.role, hw->cap_sup_sta.id,
1018                 hw->cap_sup_sta.variant, hw->cap_sup_sta.bottom,
1019                 hw->cap_sup_sta.top);
1020         }
1021
1022         /* Compatibility range, primary f/w actor, CFI supplier */
1023         result = hfa384x_drvr_getconfig(hw, HFA384x_RID_PRI_CFIACTRANGES,
1024                         &hw->cap_act_pri_cfi, sizeof(hfa384x_caplevel_t));
1025         if ( result ) {
1026                 WLAN_LOG_ERROR("Failed to retrieve PRI_CFIACTRANGES\n");
1027                 goto failed;
1028         }
1029
1030         /* get all the Compatibility range, primary f/w actor, CFI supplier
1031         fields in byte order */
1032         hw->cap_act_pri_cfi.role = hfa384x2host_16(hw->cap_act_pri_cfi.role);
1033         hw->cap_act_pri_cfi.id = hfa384x2host_16(hw->cap_act_pri_cfi.id);
1034         hw->cap_act_pri_cfi.variant = hfa384x2host_16(hw->cap_act_pri_cfi.variant);
1035         hw->cap_act_pri_cfi.bottom = hfa384x2host_16(hw->cap_act_pri_cfi.bottom);
1036         hw->cap_act_pri_cfi.top = hfa384x2host_16(hw->cap_act_pri_cfi.top);
1037
1038         WLAN_LOG_INFO(
1039                 "PRI-CFI:ACT:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
1040                 hw->cap_act_pri_cfi.role, hw->cap_act_pri_cfi.id,
1041                 hw->cap_act_pri_cfi.variant, hw->cap_act_pri_cfi.bottom,
1042                 hw->cap_act_pri_cfi.top);
1043
1044         /* Compatibility range, sta f/w actor, CFI supplier */
1045         result = hfa384x_drvr_getconfig(hw, HFA384x_RID_STA_CFIACTRANGES,
1046                         &hw->cap_act_sta_cfi, sizeof(hfa384x_caplevel_t));
1047         if ( result ) {
1048                 WLAN_LOG_ERROR("Failed to retrieve STA_CFIACTRANGES\n");
1049                 goto failed;
1050         }
1051
1052         /* get all the Compatibility range, station f/w actor, CFI supplier
1053         fields in byte order */
1054         hw->cap_act_sta_cfi.role = hfa384x2host_16(hw->cap_act_sta_cfi.role);
1055         hw->cap_act_sta_cfi.id = hfa384x2host_16(hw->cap_act_sta_cfi.id);
1056         hw->cap_act_sta_cfi.variant = hfa384x2host_16(hw->cap_act_sta_cfi.variant);
1057         hw->cap_act_sta_cfi.bottom = hfa384x2host_16(hw->cap_act_sta_cfi.bottom);
1058         hw->cap_act_sta_cfi.top = hfa384x2host_16(hw->cap_act_sta_cfi.top);
1059
1060         WLAN_LOG_INFO(
1061                 "STA-CFI:ACT:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
1062                 hw->cap_act_sta_cfi.role, hw->cap_act_sta_cfi.id,
1063                 hw->cap_act_sta_cfi.variant, hw->cap_act_sta_cfi.bottom,
1064                 hw->cap_act_sta_cfi.top);
1065
1066         /* Compatibility range, sta f/w actor, MFI supplier */
1067         result = hfa384x_drvr_getconfig(hw, HFA384x_RID_STA_MFIACTRANGES,
1068                         &hw->cap_act_sta_mfi, sizeof(hfa384x_caplevel_t));
1069         if ( result ) {
1070                 WLAN_LOG_ERROR("Failed to retrieve STA_MFIACTRANGES\n");
1071                 goto failed;
1072         }
1073
1074         /* get all the Compatibility range, station f/w actor, MFI supplier
1075         fields in byte order */
1076         hw->cap_act_sta_mfi.role = hfa384x2host_16(hw->cap_act_sta_mfi.role);
1077         hw->cap_act_sta_mfi.id = hfa384x2host_16(hw->cap_act_sta_mfi.id);
1078         hw->cap_act_sta_mfi.variant = hfa384x2host_16(hw->cap_act_sta_mfi.variant);
1079         hw->cap_act_sta_mfi.bottom = hfa384x2host_16(hw->cap_act_sta_mfi.bottom);
1080         hw->cap_act_sta_mfi.top = hfa384x2host_16(hw->cap_act_sta_mfi.top);
1081
1082         WLAN_LOG_INFO(
1083                 "STA-MFI:ACT:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
1084                 hw->cap_act_sta_mfi.role, hw->cap_act_sta_mfi.id,
1085                 hw->cap_act_sta_mfi.variant, hw->cap_act_sta_mfi.bottom,
1086                 hw->cap_act_sta_mfi.top);
1087
1088         /* Serial Number */
1089         result = hfa384x_drvr_getconfig(hw, HFA384x_RID_NICSERIALNUMBER,
1090                         snum, HFA384x_RID_NICSERIALNUMBER_LEN);
1091         if ( !result ) {
1092                 wlan_mkprintstr(snum, HFA384x_RID_NICSERIALNUMBER_LEN,
1093                                 pstr, sizeof(pstr));
1094                 WLAN_LOG_INFO("Prism2 card SN: %s\n", pstr);
1095         } else {
1096                 WLAN_LOG_ERROR("Failed to retrieve Prism2 Card SN\n");
1097                 goto failed;
1098         }
1099
1100         /* Collect the MAC address */
1101         result = hfa384x_drvr_getconfig(hw, HFA384x_RID_CNFOWNMACADDR,
1102                 wlandev->netdev->dev_addr, WLAN_ADDR_LEN);
1103         if ( result != 0 ) {
1104                 WLAN_LOG_ERROR("Failed to retrieve mac address\n");
1105                 goto failed;
1106         }
1107
1108         /* short preamble is always implemented */
1109         wlandev->nsdcaps |= P80211_NSDCAP_SHORT_PREAMBLE;
1110
1111         /* find out if hardware wep is implemented */
1112         hfa384x_drvr_getconfig16(hw, HFA384x_RID_PRIVACYOPTIMP, &temp);
1113         if (temp)
1114                 wlandev->nsdcaps |= P80211_NSDCAP_HARDWAREWEP;
1115
1116         /* get the dBm Scaling constant */
1117         hfa384x_drvr_getconfig16(hw, HFA384x_RID_CNFDBMADJUST, &temp);
1118         hw->dbmadjust = temp;
1119
1120         /* Only enable scan by default on newer firmware */
1121         if (HFA384x_FIRMWARE_VERSION(hw->ident_sta_fw.major,
1122                                      hw->ident_sta_fw.minor,
1123                                      hw->ident_sta_fw.variant) <
1124             HFA384x_FIRMWARE_VERSION(1,5,5)) {
1125                 wlandev->nsdcaps |= P80211_NSDCAP_NOSCAN;
1126         }
1127
1128         /* TODO: Set any internally managed config items */
1129
1130         goto done;
1131 failed:
1132         WLAN_LOG_ERROR("Failed, result=%d\n", result);
1133 done:
1134         DBFEXIT;
1135         return result;
1136 }
1137
1138
1139 /*----------------------------------------------------------------
1140 * prism2sta_globalsetup
1141 *
1142 * Set any global RIDs that we want to set at device activation.
1143 *
1144 * Arguments:
1145 *       wlandev         wlan device structure
1146 *
1147 * Returns:
1148 *       0       success
1149 *       >0      f/w reported error
1150 *       <0      driver reported error
1151 *
1152 * Side effects:
1153 *
1154 * Call context:
1155 *       process thread
1156 ----------------------------------------------------------------*/
1157 static int prism2sta_globalsetup(wlandevice_t *wlandev)
1158 {
1159         hfa384x_t               *hw = (hfa384x_t *)wlandev->priv;
1160
1161         /* Set the maximum frame size */
1162         return hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFMAXDATALEN,
1163                                             WLAN_DATA_MAXLEN);
1164 }
1165
1166 static int prism2sta_setmulticast(wlandevice_t *wlandev, netdevice_t *dev)
1167 {
1168         int result = 0;
1169         hfa384x_t               *hw = (hfa384x_t *)wlandev->priv;
1170
1171         UINT16  promisc;
1172
1173         DBFENTER;
1174
1175         /* If we're not ready, what's the point? */
1176         if ( hw->state != HFA384x_STATE_RUNNING )
1177                 goto exit;
1178
1179         /* If we're an AP, do nothing here */
1180         if (hw->ap)
1181                 goto exit;
1182
1183         if ( (dev->flags & (IFF_PROMISC | IFF_ALLMULTI)) != 0 )
1184                 promisc = P80211ENUM_truth_true;
1185         else
1186                 promisc = P80211ENUM_truth_false;
1187
1188         result = hfa384x_drvr_setconfig16_async(hw, HFA384x_RID_PROMISCMODE, promisc);
1189
1190         /* XXX TODO: configure the multicast list */
1191         // CLEAR_HW_MULTICAST_LIST
1192         // struct dev_mc_list element = dev->mc_list;
1193         // while (element != null) {
1194         //  HW_ADD_MULTICAST_ADDR(element->dmi_addr, dmi_addrlen)
1195         //  element = element->next;
1196         // }
1197
1198  exit:
1199         DBFEXIT;
1200         return result;
1201 }
1202
1203 /*----------------------------------------------------------------
1204 * prism2sta_inf_handover
1205 *
1206 * Handles the receipt of a Handover info frame. Should only be present
1207 * in APs only.
1208 *
1209 * Arguments:
1210 *       wlandev         wlan device structure
1211 *       inf             ptr to info frame (contents in hfa384x order)
1212 *
1213 * Returns:
1214 *       nothing
1215 *
1216 * Side effects:
1217 *
1218 * Call context:
1219 *       interrupt
1220 ----------------------------------------------------------------*/
1221 static void prism2sta_inf_handover(wlandevice_t *wlandev, hfa384x_InfFrame_t *inf)
1222 {
1223         DBFENTER;
1224         WLAN_LOG_DEBUG(2,"received infoframe:HANDOVER (unhandled)\n");
1225         DBFEXIT;
1226         return;
1227 }
1228
1229
1230 /*----------------------------------------------------------------
1231 * prism2sta_inf_tallies
1232 *
1233 * Handles the receipt of a CommTallies info frame.
1234 *
1235 * Arguments:
1236 *       wlandev         wlan device structure
1237 *       inf             ptr to info frame (contents in hfa384x order)
1238 *
1239 * Returns:
1240 *       nothing
1241 *
1242 * Side effects:
1243 *
1244 * Call context:
1245 *       interrupt
1246 ----------------------------------------------------------------*/
1247 static void prism2sta_inf_tallies(wlandevice_t *wlandev, hfa384x_InfFrame_t *inf)
1248 {
1249         hfa384x_t               *hw = (hfa384x_t *)wlandev->priv;
1250         UINT16                  *src16;
1251         UINT32                  *dst;
1252         UINT32                  *src32;
1253         int                     i;
1254         int                     cnt;
1255
1256         DBFENTER;
1257
1258         /*
1259         ** Determine if these are 16-bit or 32-bit tallies, based on the
1260         ** record length of the info record.
1261         */
1262
1263         cnt = sizeof(hfa384x_CommTallies32_t) / sizeof(UINT32);
1264         if (inf->framelen > 22) {
1265                 dst   = (UINT32 *) &hw->tallies;
1266                 src32 = (UINT32 *) &inf->info.commtallies32;
1267                 for (i = 0; i < cnt; i++, dst++, src32++)
1268                         *dst += hfa384x2host_32(*src32);
1269         } else {
1270                 dst   = (UINT32 *) &hw->tallies;
1271                 src16 = (UINT16 *) &inf->info.commtallies16;
1272                 for (i = 0; i < cnt; i++, dst++, src16++)
1273                         *dst += hfa384x2host_16(*src16);
1274         }
1275
1276         DBFEXIT;
1277
1278         return;
1279 }
1280
1281 /*----------------------------------------------------------------
1282 * prism2sta_inf_scanresults
1283 *
1284 * Handles the receipt of a Scan Results info frame.
1285 *
1286 * Arguments:
1287 *       wlandev         wlan device structure
1288 *       inf             ptr to info frame (contents in hfa384x order)
1289 *
1290 * Returns:
1291 *       nothing
1292 *
1293 * Side effects:
1294 *
1295 * Call context:
1296 *       interrupt
1297 ----------------------------------------------------------------*/
1298 static void prism2sta_inf_scanresults(wlandevice_t *wlandev,
1299                                       hfa384x_InfFrame_t *inf)
1300 {
1301
1302         hfa384x_t               *hw = (hfa384x_t *)wlandev->priv;
1303         int                     nbss;
1304         hfa384x_ScanResult_t    *sr = &(inf->info.scanresult);
1305         int                     i;
1306         hfa384x_JoinRequest_data_t      joinreq;
1307         int                     result;
1308         DBFENTER;
1309
1310         /* Get the number of results, first in bytes, then in results */
1311         nbss = (inf->framelen * sizeof(UINT16)) -
1312                 sizeof(inf->infotype) -
1313                 sizeof(inf->info.scanresult.scanreason);
1314         nbss /= sizeof(hfa384x_ScanResultSub_t);
1315
1316         /* Print em */
1317         WLAN_LOG_DEBUG(1,"rx scanresults, reason=%d, nbss=%d:\n",
1318                 inf->info.scanresult.scanreason, nbss);
1319         for ( i = 0; i < nbss; i++) {
1320                 WLAN_LOG_DEBUG(1, "chid=%d anl=%d sl=%d bcnint=%d\n",
1321                         sr->result[i].chid,
1322                         sr->result[i].anl,
1323                         sr->result[i].sl,
1324                         sr->result[i].bcnint);
1325                 WLAN_LOG_DEBUG(1, "  capinfo=0x%04x proberesp_rate=%d\n",
1326                         sr->result[i].capinfo,
1327                         sr->result[i].proberesp_rate);
1328         }
1329         /* issue a join request */
1330         joinreq.channel = sr->result[0].chid;
1331         memcpy( joinreq.bssid, sr->result[0].bssid, WLAN_BSSID_LEN);
1332         result = hfa384x_drvr_setconfig( hw,
1333                         HFA384x_RID_JOINREQUEST,
1334                         &joinreq, HFA384x_RID_JOINREQUEST_LEN);
1335         if (result) {
1336                 WLAN_LOG_ERROR("setconfig(joinreq) failed, result=%d\n", result);
1337         }
1338
1339         DBFEXIT;
1340         return;
1341 }
1342
1343 /*----------------------------------------------------------------
1344 * prism2sta_inf_hostscanresults
1345 *
1346 * Handles the receipt of a Scan Results info frame.
1347 *
1348 * Arguments:
1349 *       wlandev         wlan device structure
1350 *       inf             ptr to info frame (contents in hfa384x order)
1351 *
1352 * Returns:
1353 *       nothing
1354 *
1355 * Side effects:
1356 *
1357 * Call context:
1358 *       interrupt
1359 ----------------------------------------------------------------*/
1360 static void prism2sta_inf_hostscanresults(wlandevice_t *wlandev,
1361                                           hfa384x_InfFrame_t *inf)
1362 {
1363         hfa384x_t               *hw = (hfa384x_t *)wlandev->priv;
1364         int                     nbss;
1365         DBFENTER;
1366
1367         nbss = (inf->framelen - 3) / 32;
1368         WLAN_LOG_DEBUG(1, "Received %d hostscan results\n", nbss);
1369
1370         if (nbss > 32)
1371                 nbss = 32;
1372
1373         if (hw->scanresults)
1374                 kfree(hw->scanresults);
1375
1376         hw->scanresults = kmalloc(sizeof(hfa384x_InfFrame_t), GFP_ATOMIC);
1377         memcpy(hw->scanresults, inf, sizeof(hfa384x_InfFrame_t));
1378
1379         if (nbss == 0)
1380                 nbss = -1;
1381
1382         /* Notify/wake the sleeping caller. */
1383         hw->scanflag = nbss;
1384         wake_up_interruptible(&hw->cmdq);
1385
1386         DBFEXIT;
1387 };
1388
1389 /*----------------------------------------------------------------
1390 * prism2sta_inf_chinforesults
1391 *
1392 * Handles the receipt of a Channel Info Results info frame.
1393 *
1394 * Arguments:
1395 *       wlandev         wlan device structure
1396 *       inf             ptr to info frame (contents in hfa384x order)
1397 *
1398 * Returns:
1399 *       nothing
1400 *
1401 * Side effects:
1402 *
1403 * Call context:
1404 *       interrupt
1405 ----------------------------------------------------------------*/
1406 static void prism2sta_inf_chinforesults(wlandevice_t *wlandev,
1407                                         hfa384x_InfFrame_t *inf)
1408 {
1409         hfa384x_t               *hw = (hfa384x_t *)wlandev->priv;
1410         unsigned int            i, n;
1411
1412         DBFENTER;
1413         hw->channel_info.results.scanchannels =
1414                 hfa384x2host_16(inf->info.chinforesult.scanchannels);
1415 #if 0
1416         memcpy(&inf->info.chinforesult, &hw->channel_info.results, sizeof(hfa384x_ChInfoResult_t));
1417 #endif
1418
1419         for (i=0, n=0; i<HFA384x_CHINFORESULT_MAX; i++) {
1420                 if (hw->channel_info.results.scanchannels & (1<<i)) {
1421                         int     channel=hfa384x2host_16(inf->info.chinforesult.result[n].chid)-1;
1422                         hfa384x_ChInfoResultSub_t *chinforesult=&hw->channel_info.results.result[channel];
1423                         chinforesult->chid   = channel;
1424                         chinforesult->anl    = hfa384x2host_16(inf->info.chinforesult.result[n].anl);
1425                         chinforesult->pnl    = hfa384x2host_16(inf->info.chinforesult.result[n].pnl);
1426                         chinforesult->active = hfa384x2host_16(inf->info.chinforesult.result[n].active);
1427                         WLAN_LOG_DEBUG(2, "chinfo: channel %d, %s level (avg/peak)=%d/%d dB, pcf %d\n",
1428                                         channel+1,
1429                                         chinforesult->active &
1430                                         HFA384x_CHINFORESULT_BSSACTIVE ? "signal" : "noise",
1431                                         chinforesult->anl, chinforesult->pnl,
1432                                         chinforesult->active & HFA384x_CHINFORESULT_PCFACTIVE ? 1 : 0
1433                         );
1434                         n++;
1435                 }
1436         }
1437         atomic_set(&hw->channel_info.done, 2);
1438
1439         hw->channel_info.count = n;
1440         DBFEXIT;
1441         return;
1442 }
1443
1444 void prism2sta_processing_defer(struct work_struct *data)
1445 {
1446         hfa384x_t               *hw = container_of(data, struct hfa384x, link_bh);
1447         wlandevice_t            *wlandev = hw->wlandev;
1448         hfa384x_bytestr32_t ssid;
1449         int                     result;
1450
1451         DBFENTER;
1452         /* First let's process the auth frames */
1453         {
1454                 struct sk_buff          *skb;
1455                 hfa384x_InfFrame_t *inf;
1456
1457                 while ( (skb = skb_dequeue(&hw->authq)) ) {
1458                         inf = (hfa384x_InfFrame_t *) skb->data;
1459                         prism2sta_inf_authreq_defer(wlandev, inf);
1460                 }
1461
1462         }
1463
1464         /* Now let's handle the linkstatus stuff */
1465         if (hw->link_status == hw->link_status_new)
1466                 goto failed;
1467
1468         hw->link_status = hw->link_status_new;
1469
1470         switch(hw->link_status) {
1471         case HFA384x_LINK_NOTCONNECTED:
1472                 /* I'm currently assuming that this is the initial link
1473                  * state.  It should only be possible immediately
1474                  * following an Enable command.
1475                  * Response:
1476                  * Block Transmits, Ignore receives of data frames
1477                  */
1478                 netif_carrier_off(wlandev->netdev);
1479
1480                 WLAN_LOG_INFO("linkstatus=NOTCONNECTED (unhandled)\n");
1481                 break;
1482
1483         case HFA384x_LINK_CONNECTED:
1484                 /* This one indicates a successful scan/join/auth/assoc.
1485                  * When we have the full MLME complement, this event will
1486                  * signify successful completion of both mlme_authenticate
1487                  * and mlme_associate.  State management will get a little
1488                  * ugly here.
1489                  * Response:
1490                  * Indicate authentication and/or association
1491                  * Enable Transmits, Receives and pass up data frames
1492                  */
1493
1494                 netif_carrier_on(wlandev->netdev);
1495
1496                 /* If we are joining a specific AP, set our state and reset retries */
1497                 if(hw->join_ap == 1)
1498                         hw->join_ap = 2;
1499                 hw->join_retries = 60;
1500
1501                 /* Don't call this in monitor mode */
1502                 if ( wlandev->netdev->type == ARPHRD_ETHER ) {
1503                         UINT16                  portstatus;
1504
1505                         WLAN_LOG_INFO("linkstatus=CONNECTED\n");
1506
1507                         /* For non-usb devices, we can use the sync versions */
1508                         /* Collect the BSSID, and set state to allow tx */
1509
1510                         result = hfa384x_drvr_getconfig(hw,
1511                                                         HFA384x_RID_CURRENTBSSID,
1512                                                         wlandev->bssid, WLAN_BSSID_LEN);
1513                         if ( result ) {
1514                                 WLAN_LOG_DEBUG(1,
1515                                                "getconfig(0x%02x) failed, result = %d\n",
1516                                                HFA384x_RID_CURRENTBSSID, result);
1517                                 goto failed;
1518                         }
1519
1520                         result = hfa384x_drvr_getconfig(hw,
1521                                                         HFA384x_RID_CURRENTSSID,
1522                                                         &ssid, sizeof(ssid));
1523                         if ( result ) {
1524                                 WLAN_LOG_DEBUG(1,
1525                                                "getconfig(0x%02x) failed, result = %d\n",
1526                                                HFA384x_RID_CURRENTSSID, result);
1527                                 goto failed;
1528                         }
1529                         prism2mgmt_bytestr2pstr((hfa384x_bytestr_t *)&ssid,
1530                                                 (p80211pstrd_t *) &wlandev->ssid);
1531
1532                         /* Collect the port status */
1533                         result = hfa384x_drvr_getconfig16(hw,
1534                                                           HFA384x_RID_PORTSTATUS, &portstatus);
1535                         if ( result ) {
1536                                 WLAN_LOG_DEBUG(1,
1537                                                "getconfig(0x%02x) failed, result = %d\n",
1538                                                HFA384x_RID_PORTSTATUS, result);
1539                                 goto failed;
1540                         }
1541                         wlandev->macmode =
1542                                 (portstatus == HFA384x_PSTATUS_CONN_IBSS) ?
1543                                 WLAN_MACMODE_IBSS_STA : WLAN_MACMODE_ESS_STA;
1544
1545                         /* Get the ball rolling on the comms quality stuff */
1546                         prism2sta_commsqual_defer(&hw->commsqual_bh);
1547                 }
1548                 break;
1549
1550         case HFA384x_LINK_DISCONNECTED:
1551                 /* This one indicates that our association is gone.  We've
1552                  * lost connection with the AP and/or been disassociated.
1553                  * This indicates that the MAC has completely cleared it's
1554                  * associated state.  We * should send a deauth indication
1555                  * (implying disassoc) up * to the MLME.
1556                  * Response:
1557                  * Indicate Deauthentication
1558                  * Block Transmits, Ignore receives of data frames
1559                  */
1560                 if(hw->join_ap == 2)
1561                 {
1562                         hfa384x_JoinRequest_data_t      joinreq;
1563                         joinreq = hw->joinreq;
1564                         /* Send the join request */
1565                         hfa384x_drvr_setconfig( hw,
1566                                 HFA384x_RID_JOINREQUEST,
1567                                 &joinreq, HFA384x_RID_JOINREQUEST_LEN);
1568                         WLAN_LOG_INFO("linkstatus=DISCONNECTED (re-submitting join)\n");
1569                 } else {
1570                         if (wlandev->netdev->type == ARPHRD_ETHER)
1571                                 WLAN_LOG_INFO("linkstatus=DISCONNECTED (unhandled)\n");
1572                 }
1573                 wlandev->macmode = WLAN_MACMODE_NONE;
1574
1575                 netif_carrier_off(wlandev->netdev);
1576
1577                 break;
1578
1579         case HFA384x_LINK_AP_CHANGE:
1580                 /* This one indicates that the MAC has decided to and
1581                  * successfully completed a change to another AP.  We
1582                  * should probably implement a reassociation indication
1583                  * in response to this one.  I'm thinking that the the
1584                  * p80211 layer needs to be notified in case of
1585                  * buffering/queueing issues.  User mode also needs to be
1586                  * notified so that any BSS dependent elements can be
1587                  * updated.
1588                  * associated state.  We * should send a deauth indication
1589                  * (implying disassoc) up * to the MLME.
1590                  * Response:
1591                  * Indicate Reassociation
1592                  * Enable Transmits, Receives and pass up data frames
1593                  */
1594                 WLAN_LOG_INFO("linkstatus=AP_CHANGE\n");
1595
1596                 result = hfa384x_drvr_getconfig(hw,
1597                                                 HFA384x_RID_CURRENTBSSID,
1598                                                 wlandev->bssid, WLAN_BSSID_LEN);
1599                 if ( result ) {
1600                         WLAN_LOG_DEBUG(1,
1601                                        "getconfig(0x%02x) failed, result = %d\n",
1602                                        HFA384x_RID_CURRENTBSSID, result);
1603                         goto failed;
1604                 }
1605
1606                 result = hfa384x_drvr_getconfig(hw,
1607                                                 HFA384x_RID_CURRENTSSID,
1608                                                 &ssid, sizeof(ssid));
1609                 if ( result ) {
1610                         WLAN_LOG_DEBUG(1,
1611                                        "getconfig(0x%02x) failed, result = %d\n",
1612                                        HFA384x_RID_CURRENTSSID, result);
1613                         goto failed;
1614                 }
1615                 prism2mgmt_bytestr2pstr((hfa384x_bytestr_t *)&ssid,
1616                                         (p80211pstrd_t *) &wlandev->ssid);
1617
1618
1619                 hw->link_status = HFA384x_LINK_CONNECTED;
1620                 netif_carrier_on(wlandev->netdev);
1621
1622                 break;
1623
1624         case HFA384x_LINK_AP_OUTOFRANGE:
1625                 /* This one indicates that the MAC has decided that the
1626                  * AP is out of range, but hasn't found a better candidate
1627                  * so the MAC maintains its "associated" state in case
1628                  * we get back in range.  We should block transmits and
1629                  * receives in this state.  Do we need an indication here?
1630                  * Probably not since a polling user-mode element would
1631                  * get this status from from p2PortStatus(FD40). What about
1632                  * p80211?
1633                  * Response:
1634                  * Block Transmits, Ignore receives of data frames
1635                  */
1636                 WLAN_LOG_INFO("linkstatus=AP_OUTOFRANGE (unhandled)\n");
1637
1638                 netif_carrier_off(wlandev->netdev);
1639
1640                 break;
1641
1642         case HFA384x_LINK_AP_INRANGE:
1643                 /* This one indicates that the MAC has decided that the
1644                  * AP is back in range.  We continue working with our
1645                  * existing association.
1646                  * Response:
1647                  * Enable Transmits, Receives and pass up data frames
1648                  */
1649                 WLAN_LOG_INFO("linkstatus=AP_INRANGE\n");
1650
1651                 hw->link_status = HFA384x_LINK_CONNECTED;
1652                 netif_carrier_on(wlandev->netdev);
1653
1654                 break;
1655
1656         case HFA384x_LINK_ASSOCFAIL:
1657                 /* This one is actually a peer to CONNECTED.  We've
1658                  * requested a join for a given SSID and optionally BSSID.
1659                  * We can use this one to indicate authentication and
1660                  * association failures.  The trick is going to be
1661                  * 1) identifying the failure, and 2) state management.
1662                  * Response:
1663                  * Disable Transmits, Ignore receives of data frames
1664                  */
1665                 if(hw->join_ap && --hw->join_retries > 0)
1666                 {
1667                         hfa384x_JoinRequest_data_t      joinreq;
1668                         joinreq = hw->joinreq;
1669                         /* Send the join request */
1670                         hfa384x_drvr_setconfig( hw,
1671                                 HFA384x_RID_JOINREQUEST,
1672                                 &joinreq, HFA384x_RID_JOINREQUEST_LEN);
1673                         WLAN_LOG_INFO("linkstatus=ASSOCFAIL (re-submitting join)\n");
1674                 } else {
1675                         WLAN_LOG_INFO("linkstatus=ASSOCFAIL (unhandled)\n");
1676                 }
1677
1678                 netif_carrier_off(wlandev->netdev);
1679
1680                 break;
1681
1682         default:
1683                 /* This is bad, IO port problems? */
1684                 WLAN_LOG_WARNING(
1685                         "unknown linkstatus=0x%02x\n", hw->link_status);
1686                 goto failed;
1687                 break;
1688         }
1689
1690         wlandev->linkstatus = (hw->link_status == HFA384x_LINK_CONNECTED);
1691 #ifdef WIRELESS_EXT
1692         p80211wext_event_associated(wlandev, wlandev->linkstatus);
1693 #endif
1694
1695  failed:
1696         DBFEXIT;
1697 }
1698
1699 /*----------------------------------------------------------------
1700 * prism2sta_inf_linkstatus
1701 *
1702 * Handles the receipt of a Link Status info frame.
1703 *
1704 * Arguments:
1705 *       wlandev         wlan device structure
1706 *       inf             ptr to info frame (contents in hfa384x order)
1707 *
1708 * Returns:
1709 *       nothing
1710 *
1711 * Side effects:
1712 *
1713 * Call context:
1714 *       interrupt
1715 ----------------------------------------------------------------*/
1716 static void prism2sta_inf_linkstatus(wlandevice_t *wlandev,
1717                                      hfa384x_InfFrame_t *inf)
1718 {
1719         hfa384x_t               *hw = (hfa384x_t *)wlandev->priv;
1720
1721         DBFENTER;
1722
1723         hw->link_status_new = hfa384x2host_16(inf->info.linkstatus.linkstatus);
1724
1725         schedule_work(&hw->link_bh);
1726
1727         DBFEXIT;
1728         return;
1729 }
1730
1731 /*----------------------------------------------------------------
1732 * prism2sta_inf_assocstatus
1733 *
1734 * Handles the receipt of an Association Status info frame. Should
1735 * be present in APs only.
1736 *
1737 * Arguments:
1738 *       wlandev         wlan device structure
1739 *       inf             ptr to info frame (contents in hfa384x order)
1740 *
1741 * Returns:
1742 *       nothing
1743 *
1744 * Side effects:
1745 *
1746 * Call context:
1747 *       interrupt
1748 ----------------------------------------------------------------*/
1749 static void prism2sta_inf_assocstatus(wlandevice_t *wlandev,
1750                                       hfa384x_InfFrame_t *inf)
1751 {
1752         hfa384x_t               *hw = (hfa384x_t *)wlandev->priv;
1753         hfa384x_AssocStatus_t   rec;
1754         int                     i;
1755
1756         DBFENTER;
1757
1758         memcpy(&rec, &inf->info.assocstatus, sizeof(rec));
1759         rec.assocstatus = hfa384x2host_16(rec.assocstatus);
1760         rec.reason      = hfa384x2host_16(rec.reason);
1761
1762         /*
1763         ** Find the address in the list of authenticated stations.  If it wasn't
1764         ** found, then this address has not been previously authenticated and
1765         ** something weird has happened if this is anything other than an
1766         ** "authentication failed" message.  If the address was found, then
1767         ** set the "associated" flag for that station, based on whether the
1768         ** station is associating or losing its association.  Something weird
1769         ** has also happened if we find the address in the list of authenticated
1770         ** stations but we are getting an "authentication failed" message.
1771         */
1772
1773         for (i = 0; i < hw->authlist.cnt; i++)
1774                 if (memcmp(rec.sta_addr, hw->authlist.addr[i], WLAN_ADDR_LEN) == 0)
1775                         break;
1776
1777         if (i >= hw->authlist.cnt) {
1778                 if (rec.assocstatus != HFA384x_ASSOCSTATUS_AUTHFAIL)
1779                         WLAN_LOG_WARNING("assocstatus info frame received for non-authenticated station.\n");
1780         } else {
1781                 hw->authlist.assoc[i] =
1782                         (rec.assocstatus == HFA384x_ASSOCSTATUS_STAASSOC ||
1783                          rec.assocstatus == HFA384x_ASSOCSTATUS_REASSOC);
1784
1785                 if (rec.assocstatus == HFA384x_ASSOCSTATUS_AUTHFAIL)
1786                         WLAN_LOG_WARNING("authfail assocstatus info frame received for authenticated station.\n");
1787         }
1788
1789         DBFEXIT;
1790
1791         return;
1792 }
1793
1794 /*----------------------------------------------------------------
1795 * prism2sta_inf_authreq
1796 *
1797 * Handles the receipt of an Authentication Request info frame. Should
1798 * be present in APs only.
1799 *
1800 * Arguments:
1801 *       wlandev         wlan device structure
1802 *       inf             ptr to info frame (contents in hfa384x order)
1803 *
1804 * Returns:
1805 *       nothing
1806 *
1807 * Side effects:
1808 *
1809 * Call context:
1810 *       interrupt
1811 *
1812 ----------------------------------------------------------------*/
1813 static void prism2sta_inf_authreq(wlandevice_t *wlandev,
1814                                   hfa384x_InfFrame_t *inf)
1815 {
1816         hfa384x_t               *hw = (hfa384x_t *)wlandev->priv;
1817         struct sk_buff *skb;
1818
1819         DBFENTER;
1820
1821         skb = dev_alloc_skb(sizeof(*inf));
1822         if (skb) {
1823                 skb_put(skb, sizeof(*inf));
1824                 memcpy(skb->data, inf, sizeof(*inf));
1825                 skb_queue_tail(&hw->authq, skb);
1826                 schedule_work(&hw->link_bh);
1827         }
1828
1829         DBFEXIT;
1830 }
1831
1832 static void prism2sta_inf_authreq_defer(wlandevice_t *wlandev,
1833                                         hfa384x_InfFrame_t *inf)
1834 {
1835         hfa384x_t               *hw = (hfa384x_t *)wlandev->priv;
1836         hfa384x_authenticateStation_data_t  rec;
1837
1838         int    i, added, result, cnt;
1839         UINT8  *addr;
1840
1841         DBFENTER;
1842
1843         /*
1844         ** Build the AuthenticateStation record.  Initialize it for denying
1845         ** authentication.
1846         */
1847
1848         memcpy(rec.address, inf->info.authreq.sta_addr, WLAN_ADDR_LEN);
1849         rec.status = P80211ENUM_status_unspec_failure;
1850
1851         /*
1852         ** Authenticate based on the access mode.
1853         */
1854
1855         switch (hw->accessmode) {
1856                 case WLAN_ACCESS_NONE:
1857
1858                         /*
1859                         ** Deny all new authentications.  However, if a station
1860                         ** is ALREADY authenticated, then accept it.
1861                         */
1862
1863                         for (i = 0; i < hw->authlist.cnt; i++)
1864                                 if (memcmp(rec.address, hw->authlist.addr[i],
1865                                                 WLAN_ADDR_LEN) == 0) {
1866                                         rec.status = P80211ENUM_status_successful;
1867                                         break;
1868                                 }
1869
1870                         break;
1871
1872                 case WLAN_ACCESS_ALL:
1873
1874                         /*
1875                         ** Allow all authentications.
1876                         */
1877
1878                         rec.status = P80211ENUM_status_successful;
1879                         break;
1880
1881                 case WLAN_ACCESS_ALLOW:
1882
1883                         /*
1884                         ** Only allow the authentication if the MAC address
1885                         ** is in the list of allowed addresses.
1886                         **
1887                         ** Since this is the interrupt handler, we may be here
1888                         ** while the access list is in the middle of being
1889                         ** updated.  Choose the list which is currently okay.
1890                         ** See "prism2mib_priv_accessallow()" for details.
1891                         */
1892
1893                         if (hw->allow.modify == 0) {
1894                                 cnt  = hw->allow.cnt;
1895                                 addr = hw->allow.addr[0];
1896                         } else {
1897                                 cnt  = hw->allow.cnt1;
1898                                 addr = hw->allow.addr1[0];
1899                         }
1900
1901                         for (i = 0; i < cnt; i++, addr += WLAN_ADDR_LEN)
1902                                 if (memcmp(rec.address, addr, WLAN_ADDR_LEN) == 0) {
1903                                         rec.status = P80211ENUM_status_successful;
1904                                         break;
1905                                 }
1906
1907                         break;
1908
1909                 case WLAN_ACCESS_DENY:
1910
1911                         /*
1912                         ** Allow the authentication UNLESS the MAC address is
1913                         ** in the list of denied addresses.
1914                         **
1915                         ** Since this is the interrupt handler, we may be here
1916                         ** while the access list is in the middle of being
1917                         ** updated.  Choose the list which is currently okay.
1918                         ** See "prism2mib_priv_accessdeny()" for details.
1919                         */
1920
1921                         if (hw->deny.modify == 0) {
1922                                 cnt  = hw->deny.cnt;
1923                                 addr = hw->deny.addr[0];
1924                         } else {
1925                                 cnt  = hw->deny.cnt1;
1926                                 addr = hw->deny.addr1[0];
1927                         }
1928
1929                         rec.status = P80211ENUM_status_successful;
1930
1931                         for (i = 0; i < cnt; i++, addr += WLAN_ADDR_LEN)
1932                                 if (memcmp(rec.address, addr, WLAN_ADDR_LEN) == 0) {
1933                                         rec.status = P80211ENUM_status_unspec_failure;
1934                                         break;
1935                                 }
1936
1937                         break;
1938         }
1939
1940         /*
1941         ** If the authentication is okay, then add the MAC address to the list
1942         ** of authenticated stations.  Don't add the address if it is already in
1943         ** the list.  (802.11b does not seem to disallow a station from issuing
1944         ** an authentication request when the station is already authenticated.
1945         ** Does this sort of thing ever happen?  We might as well do the check
1946         ** just in case.)
1947         */
1948
1949         added = 0;
1950
1951         if (rec.status == P80211ENUM_status_successful) {
1952                 for (i = 0; i < hw->authlist.cnt; i++)
1953                         if (memcmp(rec.address, hw->authlist.addr[i], WLAN_ADDR_LEN) == 0)
1954                                 break;
1955
1956                 if (i >= hw->authlist.cnt) {
1957                         if (hw->authlist.cnt >= WLAN_AUTH_MAX) {
1958                                 rec.status = P80211ENUM_status_ap_full;
1959                         } else {
1960                                 memcpy(hw->authlist.addr[hw->authlist.cnt],
1961                                         rec.address, WLAN_ADDR_LEN);
1962                                 hw->authlist.cnt++;
1963                                 added = 1;
1964                         }
1965                 }
1966         }
1967
1968         /*
1969         ** Send back the results of the authentication.  If this doesn't work,
1970         ** then make sure to remove the address from the authenticated list if
1971         ** it was added.
1972         */
1973
1974         rec.status = host2hfa384x_16(rec.status);
1975         rec.algorithm = inf->info.authreq.algorithm;
1976
1977         result = hfa384x_drvr_setconfig(hw, HFA384x_RID_AUTHENTICATESTA,
1978                                                         &rec, sizeof(rec));
1979         if (result) {
1980                 if (added) hw->authlist.cnt--;
1981                 WLAN_LOG_ERROR("setconfig(authenticatestation) failed, result=%d\n", result);
1982         }
1983
1984         DBFEXIT;
1985
1986         return;
1987 }
1988
1989
1990 /*----------------------------------------------------------------
1991 * prism2sta_inf_psusercnt
1992 *
1993 * Handles the receipt of a PowerSaveUserCount info frame. Should
1994 * be present in APs only.
1995 *
1996 * Arguments:
1997 *       wlandev         wlan device structure
1998 *       inf             ptr to info frame (contents in hfa384x order)
1999 *
2000 * Returns:
2001 *       nothing
2002 *
2003 * Side effects:
2004 *
2005 * Call context:
2006 *       interrupt
2007 ----------------------------------------------------------------*/
2008 static void prism2sta_inf_psusercnt(wlandevice_t *wlandev,
2009                                     hfa384x_InfFrame_t *inf)
2010 {
2011         hfa384x_t               *hw = (hfa384x_t *)wlandev->priv;
2012
2013         DBFENTER;
2014
2015         hw->psusercount = hfa384x2host_16(inf->info.psusercnt.usercnt);
2016
2017         DBFEXIT;
2018
2019         return;
2020 }
2021
2022 /*----------------------------------------------------------------
2023 * prism2sta_ev_dtim
2024 *
2025 * Handles the DTIM early warning event.
2026 *
2027 * Arguments:
2028 *       wlandev         wlan device structure
2029 *
2030 * Returns:
2031 *       nothing
2032 *
2033 * Side effects:
2034 *
2035 * Call context:
2036 *       interrupt
2037 ----------------------------------------------------------------*/
2038 void prism2sta_ev_dtim(wlandevice_t *wlandev)
2039 {
2040 #if 0
2041         hfa384x_t               *hw = (hfa384x_t *)wlandev->priv;
2042 #endif
2043         DBFENTER;
2044         WLAN_LOG_DEBUG(3, "DTIM event, currently unhandled.\n");
2045         DBFEXIT;
2046         return;
2047 }
2048
2049
2050 /*----------------------------------------------------------------
2051 * prism2sta_ev_infdrop
2052 *
2053 * Handles the InfDrop event.
2054 *
2055 * Arguments:
2056 *       wlandev         wlan device structure
2057 *
2058 * Returns:
2059 *       nothing
2060 *
2061 * Side effects:
2062 *
2063 * Call context:
2064 *       interrupt
2065 ----------------------------------------------------------------*/
2066 void prism2sta_ev_infdrop(wlandevice_t *wlandev)
2067 {
2068 #if 0
2069         hfa384x_t               *hw = (hfa384x_t *)wlandev->priv;
2070 #endif
2071         DBFENTER;
2072         WLAN_LOG_DEBUG(3, "Info frame dropped due to card mem low.\n");
2073         DBFEXIT;
2074         return;
2075 }
2076
2077
2078 /*----------------------------------------------------------------
2079 * prism2sta_ev_info
2080 *
2081 * Handles the Info event.
2082 *
2083 * Arguments:
2084 *       wlandev         wlan device structure
2085 *       inf             ptr to a generic info frame
2086 *
2087 * Returns:
2088 *       nothing
2089 *
2090 * Side effects:
2091 *
2092 * Call context:
2093 *       interrupt
2094 ----------------------------------------------------------------*/
2095 void prism2sta_ev_info(wlandevice_t *wlandev, hfa384x_InfFrame_t *inf)
2096 {
2097         DBFENTER;
2098         inf->infotype = hfa384x2host_16(inf->infotype);
2099         /* Dispatch */
2100         switch ( inf->infotype ) {
2101                 case HFA384x_IT_HANDOVERADDR:
2102                         prism2sta_inf_handover(wlandev, inf);
2103                         break;
2104                 case HFA384x_IT_COMMTALLIES:
2105                         prism2sta_inf_tallies(wlandev, inf);
2106                         break;
2107                case HFA384x_IT_HOSTSCANRESULTS:
2108                         prism2sta_inf_hostscanresults(wlandev, inf);
2109                         break;
2110                 case HFA384x_IT_SCANRESULTS:
2111                         prism2sta_inf_scanresults(wlandev, inf);
2112                         break;
2113                 case HFA384x_IT_CHINFORESULTS:
2114                         prism2sta_inf_chinforesults(wlandev, inf);
2115                         break;
2116                 case HFA384x_IT_LINKSTATUS:
2117                         prism2sta_inf_linkstatus(wlandev, inf);
2118                         break;
2119                 case HFA384x_IT_ASSOCSTATUS:
2120                         prism2sta_inf_assocstatus(wlandev, inf);
2121                         break;
2122                 case HFA384x_IT_AUTHREQ:
2123                         prism2sta_inf_authreq(wlandev, inf);
2124                         break;
2125                 case HFA384x_IT_PSUSERCNT:
2126                         prism2sta_inf_psusercnt(wlandev, inf);
2127                         break;
2128                 case HFA384x_IT_KEYIDCHANGED:
2129                         WLAN_LOG_WARNING("Unhandled IT_KEYIDCHANGED\n");
2130                         break;
2131                 case HFA384x_IT_ASSOCREQ:
2132                         WLAN_LOG_WARNING("Unhandled IT_ASSOCREQ\n");
2133                         break;
2134                 case HFA384x_IT_MICFAILURE:
2135                         WLAN_LOG_WARNING("Unhandled IT_MICFAILURE\n");
2136                         break;
2137                 default:
2138                         WLAN_LOG_WARNING(
2139                                 "Unknown info type=0x%02x\n", inf->infotype);
2140                         break;
2141         }
2142         DBFEXIT;
2143         return;
2144 }
2145
2146
2147 /*----------------------------------------------------------------
2148 * prism2sta_ev_txexc
2149 *
2150 * Handles the TxExc event.  A Transmit Exception event indicates
2151 * that the MAC's TX process was unsuccessful - so the packet did
2152 * not get transmitted.
2153 *
2154 * Arguments:
2155 *       wlandev         wlan device structure
2156 *       status          tx frame status word
2157 *
2158 * Returns:
2159 *       nothing
2160 *
2161 * Side effects:
2162 *
2163 * Call context:
2164 *       interrupt
2165 ----------------------------------------------------------------*/
2166 void prism2sta_ev_txexc(wlandevice_t *wlandev, UINT16 status)
2167 {
2168         DBFENTER;
2169
2170         WLAN_LOG_DEBUG(3, "TxExc status=0x%x.\n", status);
2171
2172         DBFEXIT;
2173         return;
2174 }
2175
2176
2177 /*----------------------------------------------------------------
2178 * prism2sta_ev_tx
2179 *
2180 * Handles the Tx event.
2181 *
2182 * Arguments:
2183 *       wlandev         wlan device structure
2184 *       status          tx frame status word
2185 * Returns:
2186 *       nothing
2187 *
2188 * Side effects:
2189 *
2190 * Call context:
2191 *       interrupt
2192 ----------------------------------------------------------------*/
2193 void prism2sta_ev_tx(wlandevice_t *wlandev, UINT16 status)
2194 {
2195         DBFENTER;
2196         WLAN_LOG_DEBUG(4, "Tx Complete, status=0x%04x\n", status);
2197         /* update linux network stats */
2198         wlandev->linux_stats.tx_packets++;
2199         DBFEXIT;
2200         return;
2201 }
2202
2203
2204 /*----------------------------------------------------------------
2205 * prism2sta_ev_rx
2206 *
2207 * Handles the Rx event.
2208 *
2209 * Arguments:
2210 *       wlandev         wlan device structure
2211 *
2212 * Returns:
2213 *       nothing
2214 *
2215 * Side effects:
2216 *
2217 * Call context:
2218 *       interrupt
2219 ----------------------------------------------------------------*/
2220 void prism2sta_ev_rx(wlandevice_t *wlandev, struct sk_buff *skb)
2221 {
2222         DBFENTER;
2223
2224         p80211netdev_rx(wlandev, skb);
2225
2226         DBFEXIT;
2227         return;
2228 }
2229
2230 /*----------------------------------------------------------------
2231 * prism2sta_ev_alloc
2232 *
2233 * Handles the Alloc event.
2234 *
2235 * Arguments:
2236 *       wlandev         wlan device structure
2237 *
2238 * Returns:
2239 *       nothing
2240 *
2241 * Side effects:
2242 *
2243 * Call context:
2244 *       interrupt
2245 ----------------------------------------------------------------*/
2246 void prism2sta_ev_alloc(wlandevice_t *wlandev)
2247 {
2248         DBFENTER;
2249
2250         p80211netdev_wake_queue(wlandev);
2251
2252         DBFEXIT;
2253         return;
2254 }
2255
2256 #if (WLAN_HOSTIF == WLAN_PLX || WLAN_HOSTIF == WLAN_PCI)
2257 #ifdef CONFIG_PM
2258 static int prism2sta_suspend_pci(struct pci_dev *pdev, pm_message_t state)
2259 {
2260         wlandevice_t            *wlandev;
2261
2262         wlandev = (wlandevice_t *) pci_get_drvdata(pdev);
2263
2264         /* reset hardware */
2265         if (wlandev) {
2266                 prism2sta_ifstate(wlandev, P80211ENUM_ifstate_disable);
2267                 p80211_suspend(wlandev);
2268         }
2269
2270         // call a netif_device_detach(wlandev->netdev) ?
2271
2272         return 0;
2273 }
2274
2275 static int prism2sta_resume_pci (struct pci_dev *pdev)
2276 {
2277         wlandevice_t            *wlandev;
2278
2279         wlandev = (wlandevice_t *) pci_get_drvdata(pdev);
2280
2281         if (wlandev) {
2282                 prism2sta_ifstate(wlandev, P80211ENUM_ifstate_disable);
2283                 p80211_resume(wlandev);
2284         }
2285
2286         return 0;
2287 }
2288 #endif
2289 #endif
2290
2291 /*----------------------------------------------------------------
2292 * create_wlan
2293 *
2294 * Called at module init time.  This creates the wlandevice_t structure
2295 * and initializes it with relevant bits.
2296 *
2297 * Arguments:
2298 *       none
2299 *
2300 * Returns:
2301 *       the created wlandevice_t structure.
2302 *
2303 * Side effects:
2304 *       also allocates the priv/hw structures.
2305 *
2306 * Call context:
2307 *       process thread
2308 *
2309 ----------------------------------------------------------------*/
2310 static wlandevice_t *create_wlan(void)
2311 {
2312         wlandevice_t    *wlandev = NULL;
2313         hfa384x_t       *hw = NULL;
2314
2315         /* Alloc our structures */
2316         wlandev =       kmalloc(sizeof(wlandevice_t), GFP_KERNEL);
2317         hw =            kmalloc(sizeof(hfa384x_t), GFP_KERNEL);
2318
2319         if (!wlandev || !hw) {
2320                 WLAN_LOG_ERROR("%s: Memory allocation failure.\n", dev_info);
2321                 if (wlandev)    kfree(wlandev);
2322                 if (hw)         kfree(hw);
2323                 return NULL;
2324         }
2325
2326         /* Clear all the structs */
2327         memset(wlandev, 0, sizeof(wlandevice_t));
2328         memset(hw, 0, sizeof(hfa384x_t));
2329
2330         /* Initialize the network device object. */
2331         wlandev->nsdname = dev_info;
2332         wlandev->msdstate = WLAN_MSD_HWPRESENT_PENDING;
2333         wlandev->priv = hw;
2334         wlandev->open = prism2sta_open;
2335         wlandev->close = prism2sta_close;
2336         wlandev->reset = prism2sta_reset;
2337 #ifdef CONFIG_PROC_FS
2338         wlandev->nsd_proc_read = prism2sta_proc_read;
2339 #endif
2340         wlandev->txframe = prism2sta_txframe;
2341         wlandev->mlmerequest = prism2sta_mlmerequest;
2342         wlandev->set_multicast_list = prism2sta_setmulticast;
2343         wlandev->tx_timeout = hfa384x_tx_timeout;
2344
2345         wlandev->nsdcaps = P80211_NSDCAP_HWFRAGMENT |
2346                            P80211_NSDCAP_AUTOJOIN;
2347
2348         /* Initialize the device private data stucture. */
2349         hw->dot11_desired_bss_type = 1;
2350
2351         return wlandev;
2352 }
2353
2354 #ifdef CONFIG_PROC_FS
2355 static int
2356 prism2sta_proc_read(
2357         char    *page,
2358         char    **start,
2359         off_t   offset,
2360         int     count,
2361         int     *eof,
2362         void    *data)
2363 {
2364         char     *p = page;
2365         wlandevice_t *wlandev = (wlandevice_t *) data;
2366         hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
2367
2368         UINT16 hwtype = 0;
2369
2370         DBFENTER;
2371         if (offset != 0) {
2372                 *eof = 1;
2373                 goto exit;
2374         }
2375
2376         // XXX 0x0001 for prism2.5/3, 0x0000 for prism2.
2377         hwtype = BIT0;
2378
2379 #if (WLAN_HOSTIF != WLAN_USB)
2380         if (hw->isram16)
2381                 hwtype |= BIT1;
2382 #endif
2383
2384 #if (WLAN_HOSTIF == WLAN_PCI)
2385         hwtype |= BIT2;
2386 #endif
2387
2388 #define PRISM2_CVS_ID "$Id: prism2sta.c 1826 2007-03-19 15:37:00Z pizza $"
2389
2390         p += sprintf(p, "# %s version %s (%s) '%s'\n\n",
2391                      dev_info,
2392                      WLAN_RELEASE, WLAN_BUILD_DATE, PRISM2_CVS_ID);
2393
2394         p += sprintf(p, "# nic h/w: id=0x%02x %d.%d.%d\n",
2395                      hw->ident_nic.id, hw->ident_nic.major,
2396                      hw->ident_nic.minor, hw->ident_nic.variant);
2397
2398         p += sprintf(p, "# pri f/w: id=0x%02x %d.%d.%d\n",
2399                      hw->ident_pri_fw.id, hw->ident_pri_fw.major,
2400                      hw->ident_pri_fw.minor, hw->ident_pri_fw.variant);
2401
2402         if (hw->ident_sta_fw.id == 0x1f) {
2403                 p += sprintf(p, "# sta f/w: id=0x%02x %d.%d.%d\n",
2404                              hw->ident_sta_fw.id, hw->ident_sta_fw.major,
2405                              hw->ident_sta_fw.minor, hw->ident_sta_fw.variant);
2406         } else {
2407                 p += sprintf(p, "# ap f/w: id=0x%02x %d.%d.%d\n",
2408                              hw->ident_sta_fw.id, hw->ident_sta_fw.major,
2409                              hw->ident_sta_fw.minor, hw->ident_sta_fw.variant);
2410         }
2411
2412 #if (WLAN_HOSTIF != WLAN_USB)
2413         p += sprintf(p, "# initial nic hw type, needed for SSF ramdl\n");
2414         p += sprintf(p, "initnichw=%04x\n", hwtype);
2415 #endif
2416
2417  exit:
2418         DBFEXIT;
2419         return (p - page);
2420 }
2421 #endif
2422
2423 void prism2sta_commsqual_defer(struct work_struct *data)
2424 {
2425         hfa384x_t               *hw = container_of(data, struct hfa384x, commsqual_bh);
2426         wlandevice_t            *wlandev = hw->wlandev;
2427         hfa384x_bytestr32_t ssid;
2428         int result = 0;
2429
2430         DBFENTER;
2431
2432         if (hw->wlandev->hwremoved)
2433                 goto done;
2434
2435         /* we don't care if we're in AP mode */
2436         if ((wlandev->macmode == WLAN_MACMODE_NONE) ||
2437             (wlandev->macmode == WLAN_MACMODE_ESS_AP)) {
2438                 goto done;
2439         }
2440
2441         /* It only makes sense to poll these in non-IBSS */
2442         if (wlandev->macmode != WLAN_MACMODE_IBSS_STA) {
2443                 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_DBMCOMMSQUALITY,
2444                                                 &hw->qual,
2445                                                 HFA384x_RID_DBMCOMMSQUALITY_LEN);
2446
2447                 if (result) {
2448                         WLAN_LOG_ERROR("error fetching commsqual\n");
2449                         goto done;
2450                 }
2451
2452                 // qual.CQ_currBSS; // link
2453                 // ASL_currBSS;  // level
2454                 // qual.ANL_currFC; // noise
2455
2456                 WLAN_LOG_DEBUG(3, "commsqual %d %d %d\n",
2457                                hfa384x2host_16(hw->qual.CQ_currBSS),
2458                                hfa384x2host_16(hw->qual.ASL_currBSS),
2459                                hfa384x2host_16(hw->qual.ANL_currFC));
2460         }
2461
2462         /* Lastly, we need to make sure the BSSID didn't change on us */
2463         result = hfa384x_drvr_getconfig(hw,
2464                                         HFA384x_RID_CURRENTBSSID,
2465                                         wlandev->bssid, WLAN_BSSID_LEN);
2466         if ( result ) {
2467                 WLAN_LOG_DEBUG(1,
2468                                "getconfig(0x%02x) failed, result = %d\n",
2469                                HFA384x_RID_CURRENTBSSID, result);
2470                 goto done;
2471         }
2472
2473         result = hfa384x_drvr_getconfig(hw,
2474                                         HFA384x_RID_CURRENTSSID,
2475                                         &ssid, sizeof(ssid));
2476         if ( result ) {
2477                 WLAN_LOG_DEBUG(1,
2478                                "getconfig(0x%02x) failed, result = %d\n",
2479                                HFA384x_RID_CURRENTSSID, result);
2480                 goto done;
2481         }
2482         prism2mgmt_bytestr2pstr((hfa384x_bytestr_t *)&ssid,
2483                                 (p80211pstrd_t *) &wlandev->ssid);
2484
2485
2486         /* Reschedule timer */
2487         mod_timer(&hw->commsqual_timer, jiffies + HZ);
2488
2489  done:
2490         DBFEXIT;
2491 }
2492
2493 void prism2sta_commsqual_timer(unsigned long data)
2494 {
2495         hfa384x_t               *hw = (hfa384x_t *) data;
2496
2497         DBFENTER;
2498
2499         schedule_work(&hw->commsqual_bh);
2500
2501         DBFEXIT;
2502 }