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