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