Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ieee1394...
[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 =
405                             le16_to_cpu(hw->qual.CQ_currBSS);
406                         qualmsg->level.data =
407                             le16_to_cpu(hw->qual.ASL_currBSS);
408                         qualmsg->noise.data =
409                             le16_to_cpu(hw->qual.ANL_currFC);
410
411                         break;
412                 }
413         default:
414                 printk(KERN_WARNING "Unknown mgmt request message 0x%08x",
415                        msg->msgcode);
416                 break;
417         }
418
419         return result;
420 }
421
422 /*----------------------------------------------------------------
423 * prism2sta_ifstate
424 *
425 * Interface state.  This is the primary WLAN interface enable/disable
426 * handler.  Following the driver/load/deviceprobe sequence, this
427 * function must be called with a state of "enable" before any other
428 * commands will be accepted.
429 *
430 * Arguments:
431 *       wlandev         wlan device structure
432 *       msgp            ptr to msg buffer
433 *
434 * Returns:
435 *       A p80211 message resultcode value.
436 *
437 * Side effects:
438 *
439 * Call context:
440 *       process thread  (usually)
441 *       interrupt
442 ----------------------------------------------------------------*/
443 u32 prism2sta_ifstate(wlandevice_t *wlandev, u32 ifstate)
444 {
445         hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
446         u32 result;
447
448         result = P80211ENUM_resultcode_implementation_failure;
449
450         pr_debug("Current MSD state(%d), requesting(%d)\n",
451                wlandev->msdstate, ifstate);
452         switch (ifstate) {
453         case P80211ENUM_ifstate_fwload:
454                 switch (wlandev->msdstate) {
455                 case WLAN_MSD_HWPRESENT:
456                         wlandev->msdstate = WLAN_MSD_FWLOAD_PENDING;
457                         /*
458                          * Initialize the device+driver sufficiently
459                          * for firmware loading.
460                          */
461                         if ((result = hfa384x_drvr_start(hw))) {
462                                 printk(KERN_ERR
463                                        "hfa384x_drvr_start() failed,"
464                                        "result=%d\n", (int)result);
465                                 result =
466                                     P80211ENUM_resultcode_implementation_failure;
467                                 wlandev->msdstate = WLAN_MSD_HWPRESENT;
468                                 break;
469                         }
470                         wlandev->msdstate = WLAN_MSD_FWLOAD;
471                         result = P80211ENUM_resultcode_success;
472                         break;
473                 case WLAN_MSD_FWLOAD:
474                         hfa384x_cmd_initialize(hw);
475                         result = P80211ENUM_resultcode_success;
476                         break;
477                 case WLAN_MSD_RUNNING:
478                         printk(KERN_WARNING
479                                "Cannot enter fwload state from enable state,"
480                                "you must disable first.\n");
481                         result = P80211ENUM_resultcode_invalid_parameters;
482                         break;
483                 case WLAN_MSD_HWFAIL:
484                 default:
485                         /* probe() had a problem or the msdstate contains
486                          * an unrecognized value, there's nothing we can do.
487                          */
488                         result = P80211ENUM_resultcode_implementation_failure;
489                         break;
490                 }
491                 break;
492         case P80211ENUM_ifstate_enable:
493                 switch (wlandev->msdstate) {
494                 case WLAN_MSD_HWPRESENT:
495                 case WLAN_MSD_FWLOAD:
496                         wlandev->msdstate = WLAN_MSD_RUNNING_PENDING;
497                         /* Initialize the device+driver for full
498                          * operation. Note that this might me an FWLOAD to
499                          * to RUNNING transition so we must not do a chip
500                          * or board level reset.  Note that on failure,
501                          * the MSD state is set to HWPRESENT because we
502                          * can't make any assumptions about the state
503                          * of the hardware or a previous firmware load.
504                          */
505                         if ((result = hfa384x_drvr_start(hw))) {
506                                 printk(KERN_ERR
507                                        "hfa384x_drvr_start() failed,"
508                                        "result=%d\n", (int)result);
509                                 result =
510                                     P80211ENUM_resultcode_implementation_failure;
511                                 wlandev->msdstate = WLAN_MSD_HWPRESENT;
512                                 break;
513                         }
514
515                         if ((result = prism2sta_getcardinfo(wlandev))) {
516                                 printk(KERN_ERR
517                                        "prism2sta_getcardinfo() failed,"
518                                        "result=%d\n", (int)result);
519                                 result =
520                                     P80211ENUM_resultcode_implementation_failure;
521                                 hfa384x_drvr_stop(hw);
522                                 wlandev->msdstate = WLAN_MSD_HWPRESENT;
523                                 break;
524                         }
525                         if ((result = prism2sta_globalsetup(wlandev))) {
526                                 printk(KERN_ERR
527                                        "prism2sta_globalsetup() failed,"
528                                        "result=%d\n", (int)result);
529                                 result =
530                                     P80211ENUM_resultcode_implementation_failure;
531                                 hfa384x_drvr_stop(hw);
532                                 wlandev->msdstate = WLAN_MSD_HWPRESENT;
533                                 break;
534                         }
535                         wlandev->msdstate = WLAN_MSD_RUNNING;
536                         hw->join_ap = 0;
537                         hw->join_retries = 60;
538                         result = P80211ENUM_resultcode_success;
539                         break;
540                 case WLAN_MSD_RUNNING:
541                         /* Do nothing, we're already in this state. */
542                         result = P80211ENUM_resultcode_success;
543                         break;
544                 case WLAN_MSD_HWFAIL:
545                 default:
546                         /* probe() had a problem or the msdstate contains
547                          * an unrecognized value, there's nothing we can do.
548                          */
549                         result = P80211ENUM_resultcode_implementation_failure;
550                         break;
551                 }
552                 break;
553         case P80211ENUM_ifstate_disable:
554                 switch (wlandev->msdstate) {
555                 case WLAN_MSD_HWPRESENT:
556                         /* Do nothing, we're already in this state. */
557                         result = P80211ENUM_resultcode_success;
558                         break;
559                 case WLAN_MSD_FWLOAD:
560                 case WLAN_MSD_RUNNING:
561                         wlandev->msdstate = WLAN_MSD_HWPRESENT_PENDING;
562                         /*
563                          * TODO: Shut down the MAC completely. Here a chip
564                          * or board level reset is probably called for.
565                          * After a "disable" _all_ results are lost, even
566                          * those from a fwload.
567                          */
568                         if (!wlandev->hwremoved)
569                                 netif_carrier_off(wlandev->netdev);
570
571                         hfa384x_drvr_stop(hw);
572
573                         wlandev->macmode = WLAN_MACMODE_NONE;
574                         wlandev->msdstate = WLAN_MSD_HWPRESENT;
575                         result = P80211ENUM_resultcode_success;
576                         break;
577                 case WLAN_MSD_HWFAIL:
578                 default:
579                         /* probe() had a problem or the msdstate contains
580                          * an unrecognized value, there's nothing we can do.
581                          */
582                         result = P80211ENUM_resultcode_implementation_failure;
583                         break;
584                 }
585                 break;
586         default:
587                 result = P80211ENUM_resultcode_invalid_parameters;
588                 break;
589         }
590
591         return result;
592 }
593
594 /*----------------------------------------------------------------
595 * prism2sta_getcardinfo
596 *
597 * Collect the NICID, firmware version and any other identifiers
598 * we'd like to have in host-side data structures.
599 *
600 * Arguments:
601 *       wlandev         wlan device structure
602 *
603 * Returns:
604 *       0       success
605 *       >0      f/w reported error
606 *       <0      driver reported error
607 *
608 * Side effects:
609 *
610 * Call context:
611 *       Either.
612 ----------------------------------------------------------------*/
613 static int prism2sta_getcardinfo(wlandevice_t *wlandev)
614 {
615         int result = 0;
616         hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
617         u16 temp;
618         u8 snum[HFA384x_RID_NICSERIALNUMBER_LEN];
619         char pstr[(HFA384x_RID_NICSERIALNUMBER_LEN * 4) + 1];
620
621         /* Collect version and compatibility info */
622         /*  Some are critical, some are not */
623         /* NIC identity */
624         result = hfa384x_drvr_getconfig(hw, HFA384x_RID_NICIDENTITY,
625                                         &hw->ident_nic,
626                                         sizeof(hfa384x_compident_t));
627         if (result) {
628                 printk(KERN_ERR "Failed to retrieve NICIDENTITY\n");
629                 goto failed;
630         }
631
632         /* get all the nic id fields in host byte order */
633         hw->ident_nic.id = le16_to_cpu(hw->ident_nic.id);
634         hw->ident_nic.variant = le16_to_cpu(hw->ident_nic.variant);
635         hw->ident_nic.major = le16_to_cpu(hw->ident_nic.major);
636         hw->ident_nic.minor = le16_to_cpu(hw->ident_nic.minor);
637
638         printk(KERN_INFO "ident: nic h/w: id=0x%02x %d.%d.%d\n",
639                hw->ident_nic.id, hw->ident_nic.major,
640                hw->ident_nic.minor, hw->ident_nic.variant);
641
642         /* Primary f/w identity */
643         result = hfa384x_drvr_getconfig(hw, HFA384x_RID_PRIIDENTITY,
644                                         &hw->ident_pri_fw,
645                                         sizeof(hfa384x_compident_t));
646         if (result) {
647                 printk(KERN_ERR "Failed to retrieve PRIIDENTITY\n");
648                 goto failed;
649         }
650
651         /* get all the private fw id fields in host byte order */
652         hw->ident_pri_fw.id = le16_to_cpu(hw->ident_pri_fw.id);
653         hw->ident_pri_fw.variant = le16_to_cpu(hw->ident_pri_fw.variant);
654         hw->ident_pri_fw.major = le16_to_cpu(hw->ident_pri_fw.major);
655         hw->ident_pri_fw.minor = le16_to_cpu(hw->ident_pri_fw.minor);
656
657         printk(KERN_INFO "ident: pri f/w: id=0x%02x %d.%d.%d\n",
658                hw->ident_pri_fw.id, hw->ident_pri_fw.major,
659                hw->ident_pri_fw.minor, hw->ident_pri_fw.variant);
660
661         /* Station (Secondary?) f/w identity */
662         result = hfa384x_drvr_getconfig(hw, HFA384x_RID_STAIDENTITY,
663                                         &hw->ident_sta_fw,
664                                         sizeof(hfa384x_compident_t));
665         if (result) {
666                 printk(KERN_ERR "Failed to retrieve STAIDENTITY\n");
667                 goto failed;
668         }
669
670         if (hw->ident_nic.id < 0x8000) {
671                 printk(KERN_ERR
672                        "FATAL: Card is not an Intersil Prism2/2.5/3\n");
673                 result = -1;
674                 goto failed;
675         }
676
677         /* get all the station fw id fields in host byte order */
678         hw->ident_sta_fw.id = le16_to_cpu(hw->ident_sta_fw.id);
679         hw->ident_sta_fw.variant = le16_to_cpu(hw->ident_sta_fw.variant);
680         hw->ident_sta_fw.major = le16_to_cpu(hw->ident_sta_fw.major);
681         hw->ident_sta_fw.minor = le16_to_cpu(hw->ident_sta_fw.minor);
682
683         /* strip out the 'special' variant bits */
684         hw->mm_mods = hw->ident_sta_fw.variant & (BIT(14) | BIT(15));
685         hw->ident_sta_fw.variant &= ~((u16) (BIT(14) | BIT(15)));
686
687         if (hw->ident_sta_fw.id == 0x1f) {
688                 printk(KERN_INFO
689                        "ident: sta f/w: id=0x%02x %d.%d.%d\n",
690                        hw->ident_sta_fw.id, hw->ident_sta_fw.major,
691                        hw->ident_sta_fw.minor, hw->ident_sta_fw.variant);
692         } else {
693                 printk(KERN_INFO
694                        "ident:  ap f/w: id=0x%02x %d.%d.%d\n",
695                        hw->ident_sta_fw.id, hw->ident_sta_fw.major,
696                        hw->ident_sta_fw.minor, hw->ident_sta_fw.variant);
697                 printk(KERN_ERR "Unsupported Tertiary AP firmeare loaded!\n");
698                 goto failed;
699         }
700
701         /* Compatibility range, Modem supplier */
702         result = hfa384x_drvr_getconfig(hw, HFA384x_RID_MFISUPRANGE,
703                                         &hw->cap_sup_mfi,
704                                         sizeof(hfa384x_caplevel_t));
705         if (result) {
706                 printk(KERN_ERR "Failed to retrieve MFISUPRANGE\n");
707                 goto failed;
708         }
709
710         /* get all the Compatibility range, modem interface supplier
711            fields in byte order */
712         hw->cap_sup_mfi.role = le16_to_cpu(hw->cap_sup_mfi.role);
713         hw->cap_sup_mfi.id = le16_to_cpu(hw->cap_sup_mfi.id);
714         hw->cap_sup_mfi.variant = le16_to_cpu(hw->cap_sup_mfi.variant);
715         hw->cap_sup_mfi.bottom = le16_to_cpu(hw->cap_sup_mfi.bottom);
716         hw->cap_sup_mfi.top = le16_to_cpu(hw->cap_sup_mfi.top);
717
718         printk(KERN_INFO
719                "MFI:SUP:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
720                hw->cap_sup_mfi.role, hw->cap_sup_mfi.id,
721                hw->cap_sup_mfi.variant, hw->cap_sup_mfi.bottom,
722                hw->cap_sup_mfi.top);
723
724         /* Compatibility range, Controller supplier */
725         result = hfa384x_drvr_getconfig(hw, HFA384x_RID_CFISUPRANGE,
726                                         &hw->cap_sup_cfi,
727                                         sizeof(hfa384x_caplevel_t));
728         if (result) {
729                 printk(KERN_ERR "Failed to retrieve CFISUPRANGE\n");
730                 goto failed;
731         }
732
733         /* get all the Compatibility range, controller interface supplier
734            fields in byte order */
735         hw->cap_sup_cfi.role = le16_to_cpu(hw->cap_sup_cfi.role);
736         hw->cap_sup_cfi.id = le16_to_cpu(hw->cap_sup_cfi.id);
737         hw->cap_sup_cfi.variant = le16_to_cpu(hw->cap_sup_cfi.variant);
738         hw->cap_sup_cfi.bottom = le16_to_cpu(hw->cap_sup_cfi.bottom);
739         hw->cap_sup_cfi.top = le16_to_cpu(hw->cap_sup_cfi.top);
740
741         printk(KERN_INFO
742                "CFI:SUP:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
743                hw->cap_sup_cfi.role, hw->cap_sup_cfi.id,
744                hw->cap_sup_cfi.variant, hw->cap_sup_cfi.bottom,
745                hw->cap_sup_cfi.top);
746
747         /* Compatibility range, Primary f/w supplier */
748         result = hfa384x_drvr_getconfig(hw, HFA384x_RID_PRISUPRANGE,
749                                         &hw->cap_sup_pri,
750                                         sizeof(hfa384x_caplevel_t));
751         if (result) {
752                 printk(KERN_ERR "Failed to retrieve PRISUPRANGE\n");
753                 goto failed;
754         }
755
756         /* get all the Compatibility range, primary firmware supplier
757            fields in byte order */
758         hw->cap_sup_pri.role = le16_to_cpu(hw->cap_sup_pri.role);
759         hw->cap_sup_pri.id = le16_to_cpu(hw->cap_sup_pri.id);
760         hw->cap_sup_pri.variant = le16_to_cpu(hw->cap_sup_pri.variant);
761         hw->cap_sup_pri.bottom = le16_to_cpu(hw->cap_sup_pri.bottom);
762         hw->cap_sup_pri.top = le16_to_cpu(hw->cap_sup_pri.top);
763
764         printk(KERN_INFO
765                "PRI:SUP:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
766                hw->cap_sup_pri.role, hw->cap_sup_pri.id,
767                hw->cap_sup_pri.variant, hw->cap_sup_pri.bottom,
768                hw->cap_sup_pri.top);
769
770         /* Compatibility range, Station f/w supplier */
771         result = hfa384x_drvr_getconfig(hw, HFA384x_RID_STASUPRANGE,
772                                         &hw->cap_sup_sta,
773                                         sizeof(hfa384x_caplevel_t));
774         if (result) {
775                 printk(KERN_ERR "Failed to retrieve STASUPRANGE\n");
776                 goto failed;
777         }
778
779         /* get all the Compatibility range, station firmware supplier
780            fields in byte order */
781         hw->cap_sup_sta.role = le16_to_cpu(hw->cap_sup_sta.role);
782         hw->cap_sup_sta.id = le16_to_cpu(hw->cap_sup_sta.id);
783         hw->cap_sup_sta.variant = le16_to_cpu(hw->cap_sup_sta.variant);
784         hw->cap_sup_sta.bottom = le16_to_cpu(hw->cap_sup_sta.bottom);
785         hw->cap_sup_sta.top = le16_to_cpu(hw->cap_sup_sta.top);
786
787         if (hw->cap_sup_sta.id == 0x04) {
788                 printk(KERN_INFO
789                        "STA: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         } else {
794                 printk(KERN_INFO
795                        "AP:SUP:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
796                        hw->cap_sup_sta.role, hw->cap_sup_sta.id,
797                        hw->cap_sup_sta.variant, hw->cap_sup_sta.bottom,
798                        hw->cap_sup_sta.top);
799         }
800
801         /* Compatibility range, primary f/w actor, CFI supplier */
802         result = hfa384x_drvr_getconfig(hw, HFA384x_RID_PRI_CFIACTRANGES,
803                                         &hw->cap_act_pri_cfi,
804                                         sizeof(hfa384x_caplevel_t));
805         if (result) {
806                 printk(KERN_ERR "Failed to retrieve PRI_CFIACTRANGES\n");
807                 goto failed;
808         }
809
810         /* get all the Compatibility range, primary f/w actor, CFI supplier
811            fields in byte order */
812         hw->cap_act_pri_cfi.role = le16_to_cpu(hw->cap_act_pri_cfi.role);
813         hw->cap_act_pri_cfi.id = le16_to_cpu(hw->cap_act_pri_cfi.id);
814         hw->cap_act_pri_cfi.variant =
815             le16_to_cpu(hw->cap_act_pri_cfi.variant);
816         hw->cap_act_pri_cfi.bottom =
817             le16_to_cpu(hw->cap_act_pri_cfi.bottom);
818         hw->cap_act_pri_cfi.top = le16_to_cpu(hw->cap_act_pri_cfi.top);
819
820         printk(KERN_INFO
821                "PRI-CFI:ACT:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
822                hw->cap_act_pri_cfi.role, hw->cap_act_pri_cfi.id,
823                hw->cap_act_pri_cfi.variant, hw->cap_act_pri_cfi.bottom,
824                hw->cap_act_pri_cfi.top);
825
826         /* Compatibility range, sta f/w actor, CFI supplier */
827         result = hfa384x_drvr_getconfig(hw, HFA384x_RID_STA_CFIACTRANGES,
828                                         &hw->cap_act_sta_cfi,
829                                         sizeof(hfa384x_caplevel_t));
830         if (result) {
831                 printk(KERN_ERR "Failed to retrieve STA_CFIACTRANGES\n");
832                 goto failed;
833         }
834
835         /* get all the Compatibility range, station f/w actor, CFI supplier
836            fields in byte order */
837         hw->cap_act_sta_cfi.role = le16_to_cpu(hw->cap_act_sta_cfi.role);
838         hw->cap_act_sta_cfi.id = le16_to_cpu(hw->cap_act_sta_cfi.id);
839         hw->cap_act_sta_cfi.variant =
840             le16_to_cpu(hw->cap_act_sta_cfi.variant);
841         hw->cap_act_sta_cfi.bottom =
842             le16_to_cpu(hw->cap_act_sta_cfi.bottom);
843         hw->cap_act_sta_cfi.top = le16_to_cpu(hw->cap_act_sta_cfi.top);
844
845         printk(KERN_INFO
846                "STA-CFI:ACT:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
847                hw->cap_act_sta_cfi.role, hw->cap_act_sta_cfi.id,
848                hw->cap_act_sta_cfi.variant, hw->cap_act_sta_cfi.bottom,
849                hw->cap_act_sta_cfi.top);
850
851         /* Compatibility range, sta f/w actor, MFI supplier */
852         result = hfa384x_drvr_getconfig(hw, HFA384x_RID_STA_MFIACTRANGES,
853                                         &hw->cap_act_sta_mfi,
854                                         sizeof(hfa384x_caplevel_t));
855         if (result) {
856                 printk(KERN_ERR "Failed to retrieve STA_MFIACTRANGES\n");
857                 goto failed;
858         }
859
860         /* get all the Compatibility range, station f/w actor, MFI supplier
861            fields in byte order */
862         hw->cap_act_sta_mfi.role = le16_to_cpu(hw->cap_act_sta_mfi.role);
863         hw->cap_act_sta_mfi.id = le16_to_cpu(hw->cap_act_sta_mfi.id);
864         hw->cap_act_sta_mfi.variant =
865             le16_to_cpu(hw->cap_act_sta_mfi.variant);
866         hw->cap_act_sta_mfi.bottom =
867             le16_to_cpu(hw->cap_act_sta_mfi.bottom);
868         hw->cap_act_sta_mfi.top = le16_to_cpu(hw->cap_act_sta_mfi.top);
869
870         printk(KERN_INFO
871                "STA-MFI:ACT:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
872                hw->cap_act_sta_mfi.role, hw->cap_act_sta_mfi.id,
873                hw->cap_act_sta_mfi.variant, hw->cap_act_sta_mfi.bottom,
874                hw->cap_act_sta_mfi.top);
875
876         /* Serial Number */
877         result = hfa384x_drvr_getconfig(hw, HFA384x_RID_NICSERIALNUMBER,
878                                         snum, HFA384x_RID_NICSERIALNUMBER_LEN);
879         if (!result) {
880                 wlan_mkprintstr(snum, HFA384x_RID_NICSERIALNUMBER_LEN,
881                                 pstr, sizeof(pstr));
882                 printk(KERN_INFO "Prism2 card SN: %s\n", pstr);
883         } else {
884                 printk(KERN_ERR "Failed to retrieve Prism2 Card SN\n");
885                 goto failed;
886         }
887
888         /* Collect the MAC address */
889         result = hfa384x_drvr_getconfig(hw, HFA384x_RID_CNFOWNMACADDR,
890                                         wlandev->netdev->dev_addr, ETH_ALEN);
891         if (result != 0) {
892                 printk(KERN_ERR "Failed to retrieve mac address\n");
893                 goto failed;
894         }
895
896         /* short preamble is always implemented */
897         wlandev->nsdcaps |= P80211_NSDCAP_SHORT_PREAMBLE;
898
899         /* find out if hardware wep is implemented */
900         hfa384x_drvr_getconfig16(hw, HFA384x_RID_PRIVACYOPTIMP, &temp);
901         if (temp)
902                 wlandev->nsdcaps |= P80211_NSDCAP_HARDWAREWEP;
903
904         /* get the dBm Scaling constant */
905         hfa384x_drvr_getconfig16(hw, HFA384x_RID_CNFDBMADJUST, &temp);
906         hw->dbmadjust = temp;
907
908         /* Only enable scan by default on newer firmware */
909         if (HFA384x_FIRMWARE_VERSION(hw->ident_sta_fw.major,
910                                      hw->ident_sta_fw.minor,
911                                      hw->ident_sta_fw.variant) <
912             HFA384x_FIRMWARE_VERSION(1, 5, 5)) {
913                 wlandev->nsdcaps |= P80211_NSDCAP_NOSCAN;
914         }
915
916         /* TODO: Set any internally managed config items */
917
918         goto done;
919 failed:
920         printk(KERN_ERR "Failed, result=%d\n", result);
921 done:
922         return result;
923 }
924
925 /*----------------------------------------------------------------
926 * prism2sta_globalsetup
927 *
928 * Set any global RIDs that we want to set at device activation.
929 *
930 * Arguments:
931 *       wlandev         wlan device structure
932 *
933 * Returns:
934 *       0       success
935 *       >0      f/w reported error
936 *       <0      driver reported error
937 *
938 * Side effects:
939 *
940 * Call context:
941 *       process thread
942 ----------------------------------------------------------------*/
943 static int prism2sta_globalsetup(wlandevice_t *wlandev)
944 {
945         hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
946
947         /* Set the maximum frame size */
948         return hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFMAXDATALEN,
949                                         WLAN_DATA_MAXLEN);
950 }
951
952 static int prism2sta_setmulticast(wlandevice_t *wlandev, netdevice_t *dev)
953 {
954         int result = 0;
955         hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
956
957         u16 promisc;
958
959         /* If we're not ready, what's the point? */
960         if (hw->state != HFA384x_STATE_RUNNING)
961                 goto exit;
962
963         if ((dev->flags & (IFF_PROMISC | IFF_ALLMULTI)) != 0)
964                 promisc = P80211ENUM_truth_true;
965         else
966                 promisc = P80211ENUM_truth_false;
967
968         result =
969             hfa384x_drvr_setconfig16_async(hw, HFA384x_RID_PROMISCMODE,
970                                            promisc);
971 exit:
972         return result;
973 }
974
975 /*----------------------------------------------------------------
976 * prism2sta_inf_handover
977 *
978 * Handles the receipt of a Handover info frame. Should only be present
979 * in APs only.
980 *
981 * Arguments:
982 *       wlandev         wlan device structure
983 *       inf             ptr to info frame (contents in hfa384x order)
984 *
985 * Returns:
986 *       nothing
987 *
988 * Side effects:
989 *
990 * Call context:
991 *       interrupt
992 ----------------------------------------------------------------*/
993 static void prism2sta_inf_handover(wlandevice_t *wlandev,
994                                    hfa384x_InfFrame_t *inf)
995 {
996         pr_debug("received infoframe:HANDOVER (unhandled)\n");
997         return;
998 }
999
1000 /*----------------------------------------------------------------
1001 * prism2sta_inf_tallies
1002 *
1003 * Handles the receipt of a CommTallies info frame.
1004 *
1005 * Arguments:
1006 *       wlandev         wlan device structure
1007 *       inf             ptr to info frame (contents in hfa384x order)
1008 *
1009 * Returns:
1010 *       nothing
1011 *
1012 * Side effects:
1013 *
1014 * Call context:
1015 *       interrupt
1016 ----------------------------------------------------------------*/
1017 static void prism2sta_inf_tallies(wlandevice_t *wlandev,
1018                                   hfa384x_InfFrame_t *inf)
1019 {
1020         hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
1021         u16 *src16;
1022         u32 *dst;
1023         u32 *src32;
1024         int i;
1025         int cnt;
1026
1027         /*
1028          ** Determine if these are 16-bit or 32-bit tallies, based on the
1029          ** record length of the info record.
1030          */
1031
1032         cnt = sizeof(hfa384x_CommTallies32_t) / sizeof(u32);
1033         if (inf->framelen > 22) {
1034                 dst = (u32 *)&hw->tallies;
1035                 src32 = (u32 *)&inf->info.commtallies32;
1036                 for (i = 0; i < cnt; i++, dst++, src32++)
1037                         *dst += le32_to_cpu(*src32);
1038         } else {
1039                 dst = (u32 *)&hw->tallies;
1040                 src16 = (u16 *)&inf->info.commtallies16;
1041                 for (i = 0; i < cnt; i++, dst++, src16++)
1042                         *dst += le16_to_cpu(*src16);
1043         }
1044
1045         return;
1046 }
1047
1048 /*----------------------------------------------------------------
1049 * prism2sta_inf_scanresults
1050 *
1051 * Handles the receipt of a Scan Results info frame.
1052 *
1053 * Arguments:
1054 *       wlandev         wlan device structure
1055 *       inf             ptr to info frame (contents in hfa384x order)
1056 *
1057 * Returns:
1058 *       nothing
1059 *
1060 * Side effects:
1061 *
1062 * Call context:
1063 *       interrupt
1064 ----------------------------------------------------------------*/
1065 static void prism2sta_inf_scanresults(wlandevice_t *wlandev,
1066                                       hfa384x_InfFrame_t *inf)
1067 {
1068
1069         hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
1070         int nbss;
1071         hfa384x_ScanResult_t *sr = &(inf->info.scanresult);
1072         int i;
1073         hfa384x_JoinRequest_data_t joinreq;
1074         int result;
1075
1076         /* Get the number of results, first in bytes, then in results */
1077         nbss = (inf->framelen * sizeof(u16)) -
1078             sizeof(inf->infotype) - sizeof(inf->info.scanresult.scanreason);
1079         nbss /= sizeof(hfa384x_ScanResultSub_t);
1080
1081         /* Print em */
1082         pr_debug("rx scanresults, reason=%d, nbss=%d:\n",
1083                inf->info.scanresult.scanreason, nbss);
1084         for (i = 0; i < nbss; i++) {
1085                 pr_debug("chid=%d anl=%d sl=%d bcnint=%d\n",
1086                        sr->result[i].chid,
1087                        sr->result[i].anl,
1088                        sr->result[i].sl, sr->result[i].bcnint);
1089                 pr_debug("  capinfo=0x%04x proberesp_rate=%d\n",
1090                        sr->result[i].capinfo, sr->result[i].proberesp_rate);
1091         }
1092         /* issue a join request */
1093         joinreq.channel = sr->result[0].chid;
1094         memcpy(joinreq.bssid, sr->result[0].bssid, WLAN_BSSID_LEN);
1095         result = hfa384x_drvr_setconfig(hw,
1096                                         HFA384x_RID_JOINREQUEST,
1097                                         &joinreq, HFA384x_RID_JOINREQUEST_LEN);
1098         if (result) {
1099                 printk(KERN_ERR "setconfig(joinreq) failed, result=%d\n",
1100                        result);
1101         }
1102
1103         return;
1104 }
1105
1106 /*----------------------------------------------------------------
1107 * prism2sta_inf_hostscanresults
1108 *
1109 * Handles the receipt of a Scan Results info frame.
1110 *
1111 * Arguments:
1112 *       wlandev         wlan device structure
1113 *       inf             ptr to info frame (contents in hfa384x order)
1114 *
1115 * Returns:
1116 *       nothing
1117 *
1118 * Side effects:
1119 *
1120 * Call context:
1121 *       interrupt
1122 ----------------------------------------------------------------*/
1123 static void prism2sta_inf_hostscanresults(wlandevice_t *wlandev,
1124                                           hfa384x_InfFrame_t *inf)
1125 {
1126         hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
1127         int nbss;
1128
1129         nbss = (inf->framelen - 3) / 32;
1130         pr_debug("Received %d hostscan results\n", nbss);
1131
1132         if (nbss > 32)
1133                 nbss = 32;
1134
1135         kfree(hw->scanresults);
1136
1137         hw->scanresults = kmalloc(sizeof(hfa384x_InfFrame_t), GFP_ATOMIC);
1138         memcpy(hw->scanresults, inf, sizeof(hfa384x_InfFrame_t));
1139
1140         if (nbss == 0)
1141                 nbss = -1;
1142
1143         /* Notify/wake the sleeping caller. */
1144         hw->scanflag = nbss;
1145         wake_up_interruptible(&hw->cmdq);
1146 };
1147
1148 /*----------------------------------------------------------------
1149 * prism2sta_inf_chinforesults
1150 *
1151 * Handles the receipt of a Channel Info Results info frame.
1152 *
1153 * Arguments:
1154 *       wlandev         wlan device structure
1155 *       inf             ptr to info frame (contents in hfa384x order)
1156 *
1157 * Returns:
1158 *       nothing
1159 *
1160 * Side effects:
1161 *
1162 * Call context:
1163 *       interrupt
1164 ----------------------------------------------------------------*/
1165 static void prism2sta_inf_chinforesults(wlandevice_t *wlandev,
1166                                         hfa384x_InfFrame_t *inf)
1167 {
1168         hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
1169         unsigned int i, n;
1170
1171         hw->channel_info.results.scanchannels =
1172             le16_to_cpu(inf->info.chinforesult.scanchannels);
1173
1174         for (i = 0, n = 0; i < HFA384x_CHINFORESULT_MAX; i++) {
1175                 if (hw->channel_info.results.scanchannels & (1 << i)) {
1176                         int channel =
1177                             le16_to_cpu(inf->info.chinforesult.result[n].
1178                                             chid) - 1;
1179                         hfa384x_ChInfoResultSub_t *chinforesult =
1180                             &hw->channel_info.results.result[channel];
1181                         chinforesult->chid = channel;
1182                         chinforesult->anl =
1183                             le16_to_cpu(inf->info.chinforesult.result[n].
1184                                             anl);
1185                         chinforesult->pnl =
1186                             le16_to_cpu(inf->info.chinforesult.result[n].
1187                                             pnl);
1188                         chinforesult->active =
1189                             le16_to_cpu(inf->info.chinforesult.result[n].
1190                                             active);
1191                         printk(KERN_DEBUG
1192                                "chinfo: channel %d, %s level (avg/peak)=%d/%d dB, pcf %d\n",
1193                                channel + 1,
1194                                chinforesult->
1195                                active & HFA384x_CHINFORESULT_BSSACTIVE ?
1196                                "signal" : "noise", chinforesult->anl,
1197                                chinforesult->pnl,
1198                                chinforesult->
1199                                active & HFA384x_CHINFORESULT_PCFACTIVE ? 1 : 0);
1200                         n++;
1201                 }
1202         }
1203         atomic_set(&hw->channel_info.done, 2);
1204
1205         hw->channel_info.count = n;
1206         return;
1207 }
1208
1209 void prism2sta_processing_defer(struct work_struct *data)
1210 {
1211         hfa384x_t *hw = container_of(data, struct hfa384x, link_bh);
1212         wlandevice_t *wlandev = hw->wlandev;
1213         hfa384x_bytestr32_t ssid;
1214         int result;
1215
1216         /* First let's process the auth frames */
1217         {
1218                 struct sk_buff *skb;
1219                 hfa384x_InfFrame_t *inf;
1220
1221                 while ((skb = skb_dequeue(&hw->authq))) {
1222                         inf = (hfa384x_InfFrame_t *) skb->data;
1223                         prism2sta_inf_authreq_defer(wlandev, inf);
1224                 }
1225
1226         }
1227
1228         /* Now let's handle the linkstatus stuff */
1229         if (hw->link_status == hw->link_status_new)
1230                 goto failed;
1231
1232         hw->link_status = hw->link_status_new;
1233
1234         switch (hw->link_status) {
1235         case HFA384x_LINK_NOTCONNECTED:
1236                 /* I'm currently assuming that this is the initial link
1237                  * state.  It should only be possible immediately
1238                  * following an Enable command.
1239                  * Response:
1240                  * Block Transmits, Ignore receives of data frames
1241                  */
1242                 netif_carrier_off(wlandev->netdev);
1243
1244                 printk(KERN_INFO "linkstatus=NOTCONNECTED (unhandled)\n");
1245                 break;
1246
1247         case HFA384x_LINK_CONNECTED:
1248                 /* This one indicates a successful scan/join/auth/assoc.
1249                  * When we have the full MLME complement, this event will
1250                  * signify successful completion of both mlme_authenticate
1251                  * and mlme_associate.  State management will get a little
1252                  * ugly here.
1253                  * Response:
1254                  * Indicate authentication and/or association
1255                  * Enable Transmits, Receives and pass up data frames
1256                  */
1257
1258                 netif_carrier_on(wlandev->netdev);
1259
1260                 /* If we are joining a specific AP, set our state and reset retries */
1261                 if (hw->join_ap == 1)
1262                         hw->join_ap = 2;
1263                 hw->join_retries = 60;
1264
1265                 /* Don't call this in monitor mode */
1266                 if (wlandev->netdev->type == ARPHRD_ETHER) {
1267                         u16 portstatus;
1268
1269                         printk(KERN_INFO "linkstatus=CONNECTED\n");
1270
1271                         /* For non-usb devices, we can use the sync versions */
1272                         /* Collect the BSSID, and set state to allow tx */
1273
1274                         result = hfa384x_drvr_getconfig(hw,
1275                                                         HFA384x_RID_CURRENTBSSID,
1276                                                         wlandev->bssid,
1277                                                         WLAN_BSSID_LEN);
1278                         if (result) {
1279                                 printk(KERN_DEBUG
1280                                        "getconfig(0x%02x) failed, result = %d\n",
1281                                        HFA384x_RID_CURRENTBSSID, result);
1282                                 goto failed;
1283                         }
1284
1285                         result = hfa384x_drvr_getconfig(hw,
1286                                                         HFA384x_RID_CURRENTSSID,
1287                                                         &ssid, sizeof(ssid));
1288                         if (result) {
1289                                 printk(KERN_DEBUG
1290                                        "getconfig(0x%02x) failed, result = %d\n",
1291                                        HFA384x_RID_CURRENTSSID, result);
1292                                 goto failed;
1293                         }
1294                         prism2mgmt_bytestr2pstr((hfa384x_bytestr_t *)&ssid,
1295                                                 (p80211pstrd_t *)&wlandev->
1296                                                 ssid);
1297
1298                         /* Collect the port status */
1299                         result = hfa384x_drvr_getconfig16(hw,
1300                                                           HFA384x_RID_PORTSTATUS,
1301                                                           &portstatus);
1302                         if (result) {
1303                                 printk(KERN_DEBUG
1304                                        "getconfig(0x%02x) failed, result = %d\n",
1305                                        HFA384x_RID_PORTSTATUS, result);
1306                                 goto failed;
1307                         }
1308                         wlandev->macmode =
1309                             (portstatus == HFA384x_PSTATUS_CONN_IBSS) ?
1310                             WLAN_MACMODE_IBSS_STA : WLAN_MACMODE_ESS_STA;
1311
1312                         /* Get the ball rolling on the comms quality stuff */
1313                         prism2sta_commsqual_defer(&hw->commsqual_bh);
1314                 }
1315                 break;
1316
1317         case HFA384x_LINK_DISCONNECTED:
1318                 /* This one indicates that our association is gone.  We've
1319                  * lost connection with the AP and/or been disassociated.
1320                  * This indicates that the MAC has completely cleared it's
1321                  * associated state.  We * should send a deauth indication
1322                  * (implying disassoc) up * to the MLME.
1323                  * Response:
1324                  * Indicate Deauthentication
1325                  * Block Transmits, Ignore receives of data frames
1326                  */
1327                 if (hw->join_ap == 2) {
1328                         hfa384x_JoinRequest_data_t joinreq;
1329                         joinreq = hw->joinreq;
1330                         /* Send the join request */
1331                         hfa384x_drvr_setconfig(hw,
1332                                                HFA384x_RID_JOINREQUEST,
1333                                                &joinreq,
1334                                                HFA384x_RID_JOINREQUEST_LEN);
1335                         printk(KERN_INFO
1336                                "linkstatus=DISCONNECTED (re-submitting join)\n");
1337                 } else {
1338                         if (wlandev->netdev->type == ARPHRD_ETHER)
1339                                 printk(KERN_INFO
1340                                        "linkstatus=DISCONNECTED (unhandled)\n");
1341                 }
1342                 wlandev->macmode = WLAN_MACMODE_NONE;
1343
1344                 netif_carrier_off(wlandev->netdev);
1345
1346                 break;
1347
1348         case HFA384x_LINK_AP_CHANGE:
1349                 /* This one indicates that the MAC has decided to and
1350                  * successfully completed a change to another AP.  We
1351                  * should probably implement a reassociation indication
1352                  * in response to this one.  I'm thinking that the the
1353                  * p80211 layer needs to be notified in case of
1354                  * buffering/queueing issues.  User mode also needs to be
1355                  * notified so that any BSS dependent elements can be
1356                  * updated.
1357                  * associated state.  We * should send a deauth indication
1358                  * (implying disassoc) up * to the MLME.
1359                  * Response:
1360                  * Indicate Reassociation
1361                  * Enable Transmits, Receives and pass up data frames
1362                  */
1363                 printk(KERN_INFO "linkstatus=AP_CHANGE\n");
1364
1365                 result = hfa384x_drvr_getconfig(hw,
1366                                                 HFA384x_RID_CURRENTBSSID,
1367                                                 wlandev->bssid, WLAN_BSSID_LEN);
1368                 if (result) {
1369                         printk(KERN_DEBUG
1370                                "getconfig(0x%02x) failed, result = %d\n",
1371                                HFA384x_RID_CURRENTBSSID, result);
1372                         goto failed;
1373                 }
1374
1375                 result = hfa384x_drvr_getconfig(hw,
1376                                                 HFA384x_RID_CURRENTSSID,
1377                                                 &ssid, sizeof(ssid));
1378                 if (result) {
1379                         printk(KERN_DEBUG
1380                                "getconfig(0x%02x) failed, result = %d\n",
1381                                HFA384x_RID_CURRENTSSID, result);
1382                         goto failed;
1383                 }
1384                 prism2mgmt_bytestr2pstr((hfa384x_bytestr_t *)&ssid,
1385                                         (p80211pstrd_t *)&wlandev->ssid);
1386
1387                 hw->link_status = HFA384x_LINK_CONNECTED;
1388                 netif_carrier_on(wlandev->netdev);
1389
1390                 break;
1391
1392         case HFA384x_LINK_AP_OUTOFRANGE:
1393                 /* This one indicates that the MAC has decided that the
1394                  * AP is out of range, but hasn't found a better candidate
1395                  * so the MAC maintains its "associated" state in case
1396                  * we get back in range.  We should block transmits and
1397                  * receives in this state.  Do we need an indication here?
1398                  * Probably not since a polling user-mode element would
1399                  * get this status from from p2PortStatus(FD40). What about
1400                  * p80211?
1401                  * Response:
1402                  * Block Transmits, Ignore receives of data frames
1403                  */
1404                 printk(KERN_INFO "linkstatus=AP_OUTOFRANGE (unhandled)\n");
1405
1406                 netif_carrier_off(wlandev->netdev);
1407
1408                 break;
1409
1410         case HFA384x_LINK_AP_INRANGE:
1411                 /* This one indicates that the MAC has decided that the
1412                  * AP is back in range.  We continue working with our
1413                  * existing association.
1414                  * Response:
1415                  * Enable Transmits, Receives and pass up data frames
1416                  */
1417                 printk(KERN_INFO "linkstatus=AP_INRANGE\n");
1418
1419                 hw->link_status = HFA384x_LINK_CONNECTED;
1420                 netif_carrier_on(wlandev->netdev);
1421
1422                 break;
1423
1424         case HFA384x_LINK_ASSOCFAIL:
1425                 /* This one is actually a peer to CONNECTED.  We've
1426                  * requested a join for a given SSID and optionally BSSID.
1427                  * We can use this one to indicate authentication and
1428                  * association failures.  The trick is going to be
1429                  * 1) identifying the failure, and 2) state management.
1430                  * Response:
1431                  * Disable Transmits, Ignore receives of data frames
1432                  */
1433                 if (hw->join_ap && --hw->join_retries > 0) {
1434                         hfa384x_JoinRequest_data_t joinreq;
1435                         joinreq = hw->joinreq;
1436                         /* Send the join request */
1437                         hfa384x_drvr_setconfig(hw,
1438                                                HFA384x_RID_JOINREQUEST,
1439                                                &joinreq,
1440                                                HFA384x_RID_JOINREQUEST_LEN);
1441                         printk(KERN_INFO
1442                                "linkstatus=ASSOCFAIL (re-submitting join)\n");
1443                 } else {
1444                         printk(KERN_INFO "linkstatus=ASSOCFAIL (unhandled)\n");
1445                 }
1446
1447                 netif_carrier_off(wlandev->netdev);
1448
1449                 break;
1450
1451         default:
1452                 /* This is bad, IO port problems? */
1453                 printk(KERN_WARNING
1454                        "unknown linkstatus=0x%02x\n", hw->link_status);
1455                 goto failed;
1456                 break;
1457         }
1458
1459         wlandev->linkstatus = (hw->link_status == HFA384x_LINK_CONNECTED);
1460 #ifdef WIRELESS_EXT
1461         p80211wext_event_associated(wlandev, wlandev->linkstatus);
1462 #endif
1463
1464 failed:
1465         return;
1466 }
1467
1468 /*----------------------------------------------------------------
1469 * prism2sta_inf_linkstatus
1470 *
1471 * Handles the receipt of a Link Status info frame.
1472 *
1473 * Arguments:
1474 *       wlandev         wlan device structure
1475 *       inf             ptr to info frame (contents in hfa384x order)
1476 *
1477 * Returns:
1478 *       nothing
1479 *
1480 * Side effects:
1481 *
1482 * Call context:
1483 *       interrupt
1484 ----------------------------------------------------------------*/
1485 static void prism2sta_inf_linkstatus(wlandevice_t *wlandev,
1486                                      hfa384x_InfFrame_t *inf)
1487 {
1488         hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
1489
1490         hw->link_status_new = le16_to_cpu(inf->info.linkstatus.linkstatus);
1491
1492         schedule_work(&hw->link_bh);
1493
1494         return;
1495 }
1496
1497 /*----------------------------------------------------------------
1498 * prism2sta_inf_assocstatus
1499 *
1500 * Handles the receipt of an Association Status info frame. Should
1501 * be present in APs only.
1502 *
1503 * Arguments:
1504 *       wlandev         wlan device structure
1505 *       inf             ptr to info frame (contents in hfa384x order)
1506 *
1507 * Returns:
1508 *       nothing
1509 *
1510 * Side effects:
1511 *
1512 * Call context:
1513 *       interrupt
1514 ----------------------------------------------------------------*/
1515 static void prism2sta_inf_assocstatus(wlandevice_t *wlandev,
1516                                       hfa384x_InfFrame_t *inf)
1517 {
1518         hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
1519         hfa384x_AssocStatus_t rec;
1520         int i;
1521
1522         memcpy(&rec, &inf->info.assocstatus, sizeof(rec));
1523         rec.assocstatus = le16_to_cpu(rec.assocstatus);
1524         rec.reason = le16_to_cpu(rec.reason);
1525
1526         /*
1527          ** Find the address in the list of authenticated stations.  If it wasn't
1528          ** found, then this address has not been previously authenticated and
1529          ** something weird has happened if this is anything other than an
1530          ** "authentication failed" message.  If the address was found, then
1531          ** set the "associated" flag for that station, based on whether the
1532          ** station is associating or losing its association.  Something weird
1533          ** has also happened if we find the address in the list of authenticated
1534          ** stations but we are getting an "authentication failed" message.
1535          */
1536
1537         for (i = 0; i < hw->authlist.cnt; i++)
1538                 if (memcmp(rec.sta_addr, hw->authlist.addr[i], ETH_ALEN) == 0)
1539                         break;
1540
1541         if (i >= hw->authlist.cnt) {
1542                 if (rec.assocstatus != HFA384x_ASSOCSTATUS_AUTHFAIL)
1543                         printk(KERN_WARNING
1544                                "assocstatus info frame received for non-authenticated station.\n");
1545         } else {
1546                 hw->authlist.assoc[i] =
1547                     (rec.assocstatus == HFA384x_ASSOCSTATUS_STAASSOC ||
1548                      rec.assocstatus == HFA384x_ASSOCSTATUS_REASSOC);
1549
1550                 if (rec.assocstatus == HFA384x_ASSOCSTATUS_AUTHFAIL)
1551                         printk(KERN_WARNING
1552                                "authfail assocstatus info frame received for authenticated station.\n");
1553         }
1554
1555         return;
1556 }
1557
1558 /*----------------------------------------------------------------
1559 * prism2sta_inf_authreq
1560 *
1561 * Handles the receipt of an Authentication Request info frame. Should
1562 * be present in APs only.
1563 *
1564 * Arguments:
1565 *       wlandev         wlan device structure
1566 *       inf             ptr to info frame (contents in hfa384x order)
1567 *
1568 * Returns:
1569 *       nothing
1570 *
1571 * Side effects:
1572 *
1573 * Call context:
1574 *       interrupt
1575 *
1576 ----------------------------------------------------------------*/
1577 static void prism2sta_inf_authreq(wlandevice_t *wlandev,
1578                                   hfa384x_InfFrame_t *inf)
1579 {
1580         hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
1581         struct sk_buff *skb;
1582
1583         skb = dev_alloc_skb(sizeof(*inf));
1584         if (skb) {
1585                 skb_put(skb, sizeof(*inf));
1586                 memcpy(skb->data, inf, sizeof(*inf));
1587                 skb_queue_tail(&hw->authq, skb);
1588                 schedule_work(&hw->link_bh);
1589         }
1590 }
1591
1592 static void prism2sta_inf_authreq_defer(wlandevice_t *wlandev,
1593                                         hfa384x_InfFrame_t *inf)
1594 {
1595         hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
1596         hfa384x_authenticateStation_data_t rec;
1597
1598         int i, added, result, cnt;
1599         u8 *addr;
1600
1601         /*
1602          ** Build the AuthenticateStation record.  Initialize it for denying
1603          ** authentication.
1604          */
1605
1606         memcpy(rec.address, inf->info.authreq.sta_addr, ETH_ALEN);
1607         rec.status = P80211ENUM_status_unspec_failure;
1608
1609         /*
1610          ** Authenticate based on the access mode.
1611          */
1612
1613         switch (hw->accessmode) {
1614         case WLAN_ACCESS_NONE:
1615
1616                 /*
1617                  ** Deny all new authentications.  However, if a station
1618                  ** is ALREADY authenticated, then accept it.
1619                  */
1620
1621                 for (i = 0; i < hw->authlist.cnt; i++)
1622                         if (memcmp(rec.address, hw->authlist.addr[i],
1623                                    ETH_ALEN) == 0) {
1624                                 rec.status = P80211ENUM_status_successful;
1625                                 break;
1626                         }
1627
1628                 break;
1629
1630         case WLAN_ACCESS_ALL:
1631
1632                 /*
1633                  ** Allow all authentications.
1634                  */
1635
1636                 rec.status = P80211ENUM_status_successful;
1637                 break;
1638
1639         case WLAN_ACCESS_ALLOW:
1640
1641                 /*
1642                  ** Only allow the authentication if the MAC address
1643                  ** is in the list of allowed addresses.
1644                  **
1645                  ** Since this is the interrupt handler, we may be here
1646                  ** while the access list is in the middle of being
1647                  ** updated.  Choose the list which is currently okay.
1648                  ** See "prism2mib_priv_accessallow()" for details.
1649                  */
1650
1651                 if (hw->allow.modify == 0) {
1652                         cnt = hw->allow.cnt;
1653                         addr = hw->allow.addr[0];
1654                 } else {
1655                         cnt = hw->allow.cnt1;
1656                         addr = hw->allow.addr1[0];
1657                 }
1658
1659                 for (i = 0; i < cnt; i++, addr += ETH_ALEN)
1660                         if (memcmp(rec.address, addr, ETH_ALEN) == 0) {
1661                                 rec.status = P80211ENUM_status_successful;
1662                                 break;
1663                         }
1664
1665                 break;
1666
1667         case WLAN_ACCESS_DENY:
1668
1669                 /*
1670                  ** Allow the authentication UNLESS the MAC address is
1671                  ** in the list of denied addresses.
1672                  **
1673                  ** Since this is the interrupt handler, we may be here
1674                  ** while the access list is in the middle of being
1675                  ** updated.  Choose the list which is currently okay.
1676                  ** See "prism2mib_priv_accessdeny()" for details.
1677                  */
1678
1679                 if (hw->deny.modify == 0) {
1680                         cnt = hw->deny.cnt;
1681                         addr = hw->deny.addr[0];
1682                 } else {
1683                         cnt = hw->deny.cnt1;
1684                         addr = hw->deny.addr1[0];
1685                 }
1686
1687                 rec.status = P80211ENUM_status_successful;
1688
1689                 for (i = 0; i < cnt; i++, addr += ETH_ALEN)
1690                         if (memcmp(rec.address, addr, ETH_ALEN) == 0) {
1691                                 rec.status = P80211ENUM_status_unspec_failure;
1692                                 break;
1693                         }
1694
1695                 break;
1696         }
1697
1698         /*
1699          ** If the authentication is okay, then add the MAC address to the list
1700          ** of authenticated stations.  Don't add the address if it is already in
1701          ** the list.  (802.11b does not seem to disallow a station from issuing
1702          ** an authentication request when the station is already authenticated.
1703          ** Does this sort of thing ever happen?  We might as well do the check
1704          ** just in case.)
1705          */
1706
1707         added = 0;
1708
1709         if (rec.status == P80211ENUM_status_successful) {
1710                 for (i = 0; i < hw->authlist.cnt; i++)
1711                         if (memcmp(rec.address, hw->authlist.addr[i], ETH_ALEN)
1712                             == 0)
1713                                 break;
1714
1715                 if (i >= hw->authlist.cnt) {
1716                         if (hw->authlist.cnt >= WLAN_AUTH_MAX) {
1717                                 rec.status = P80211ENUM_status_ap_full;
1718                         } else {
1719                                 memcpy(hw->authlist.addr[hw->authlist.cnt],
1720                                        rec.address, ETH_ALEN);
1721                                 hw->authlist.cnt++;
1722                                 added = 1;
1723                         }
1724                 }
1725         }
1726
1727         /*
1728          ** Send back the results of the authentication.  If this doesn't work,
1729          ** then make sure to remove the address from the authenticated list if
1730          ** it was added.
1731          */
1732
1733         rec.status = cpu_to_le16(rec.status);
1734         rec.algorithm = inf->info.authreq.algorithm;
1735
1736         result = hfa384x_drvr_setconfig(hw, HFA384x_RID_AUTHENTICATESTA,
1737                                         &rec, sizeof(rec));
1738         if (result) {
1739                 if (added)
1740                         hw->authlist.cnt--;
1741                 printk(KERN_ERR
1742                        "setconfig(authenticatestation) failed, result=%d\n",
1743                        result);
1744         }
1745         return;
1746 }
1747
1748 /*----------------------------------------------------------------
1749 * prism2sta_inf_psusercnt
1750 *
1751 * Handles the receipt of a PowerSaveUserCount info frame. Should
1752 * be present in APs only.
1753 *
1754 * Arguments:
1755 *       wlandev         wlan device structure
1756 *       inf             ptr to info frame (contents in hfa384x order)
1757 *
1758 * Returns:
1759 *       nothing
1760 *
1761 * Side effects:
1762 *
1763 * Call context:
1764 *       interrupt
1765 ----------------------------------------------------------------*/
1766 static void prism2sta_inf_psusercnt(wlandevice_t *wlandev,
1767                                     hfa384x_InfFrame_t *inf)
1768 {
1769         hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
1770
1771         hw->psusercount = le16_to_cpu(inf->info.psusercnt.usercnt);
1772
1773         return;
1774 }
1775
1776 /*----------------------------------------------------------------
1777 * prism2sta_ev_info
1778 *
1779 * Handles the Info event.
1780 *
1781 * Arguments:
1782 *       wlandev         wlan device structure
1783 *       inf             ptr to a generic info frame
1784 *
1785 * Returns:
1786 *       nothing
1787 *
1788 * Side effects:
1789 *
1790 * Call context:
1791 *       interrupt
1792 ----------------------------------------------------------------*/
1793 void prism2sta_ev_info(wlandevice_t *wlandev, hfa384x_InfFrame_t *inf)
1794 {
1795         inf->infotype = le16_to_cpu(inf->infotype);
1796         /* Dispatch */
1797         switch (inf->infotype) {
1798         case HFA384x_IT_HANDOVERADDR:
1799                 prism2sta_inf_handover(wlandev, inf);
1800                 break;
1801         case HFA384x_IT_COMMTALLIES:
1802                 prism2sta_inf_tallies(wlandev, inf);
1803                 break;
1804         case HFA384x_IT_HOSTSCANRESULTS:
1805                 prism2sta_inf_hostscanresults(wlandev, inf);
1806                 break;
1807         case HFA384x_IT_SCANRESULTS:
1808                 prism2sta_inf_scanresults(wlandev, inf);
1809                 break;
1810         case HFA384x_IT_CHINFORESULTS:
1811                 prism2sta_inf_chinforesults(wlandev, inf);
1812                 break;
1813         case HFA384x_IT_LINKSTATUS:
1814                 prism2sta_inf_linkstatus(wlandev, inf);
1815                 break;
1816         case HFA384x_IT_ASSOCSTATUS:
1817                 prism2sta_inf_assocstatus(wlandev, inf);
1818                 break;
1819         case HFA384x_IT_AUTHREQ:
1820                 prism2sta_inf_authreq(wlandev, inf);
1821                 break;
1822         case HFA384x_IT_PSUSERCNT:
1823                 prism2sta_inf_psusercnt(wlandev, inf);
1824                 break;
1825         case HFA384x_IT_KEYIDCHANGED:
1826                 printk(KERN_WARNING "Unhandled IT_KEYIDCHANGED\n");
1827                 break;
1828         case HFA384x_IT_ASSOCREQ:
1829                 printk(KERN_WARNING "Unhandled IT_ASSOCREQ\n");
1830                 break;
1831         case HFA384x_IT_MICFAILURE:
1832                 printk(KERN_WARNING "Unhandled IT_MICFAILURE\n");
1833                 break;
1834         default:
1835                 printk(KERN_WARNING
1836                        "Unknown info type=0x%02x\n", inf->infotype);
1837                 break;
1838         }
1839         return;
1840 }
1841
1842 /*----------------------------------------------------------------
1843 * prism2sta_ev_txexc
1844 *
1845 * Handles the TxExc event.  A Transmit Exception event indicates
1846 * that the MAC's TX process was unsuccessful - so the packet did
1847 * not get transmitted.
1848 *
1849 * Arguments:
1850 *       wlandev         wlan device structure
1851 *       status          tx frame status word
1852 *
1853 * Returns:
1854 *       nothing
1855 *
1856 * Side effects:
1857 *
1858 * Call context:
1859 *       interrupt
1860 ----------------------------------------------------------------*/
1861 void prism2sta_ev_txexc(wlandevice_t *wlandev, u16 status)
1862 {
1863         pr_debug("TxExc status=0x%x.\n", status);
1864
1865         return;
1866 }
1867
1868 /*----------------------------------------------------------------
1869 * prism2sta_ev_tx
1870 *
1871 * Handles the Tx event.
1872 *
1873 * Arguments:
1874 *       wlandev         wlan device structure
1875 *       status          tx frame status word
1876 * Returns:
1877 *       nothing
1878 *
1879 * Side effects:
1880 *
1881 * Call context:
1882 *       interrupt
1883 ----------------------------------------------------------------*/
1884 void prism2sta_ev_tx(wlandevice_t *wlandev, u16 status)
1885 {
1886         pr_debug("Tx Complete, status=0x%04x\n", status);
1887         /* update linux network stats */
1888         wlandev->linux_stats.tx_packets++;
1889         return;
1890 }
1891
1892 /*----------------------------------------------------------------
1893 * prism2sta_ev_rx
1894 *
1895 * Handles the Rx event.
1896 *
1897 * Arguments:
1898 *       wlandev         wlan device structure
1899 *
1900 * Returns:
1901 *       nothing
1902 *
1903 * Side effects:
1904 *
1905 * Call context:
1906 *       interrupt
1907 ----------------------------------------------------------------*/
1908 void prism2sta_ev_rx(wlandevice_t *wlandev, struct sk_buff *skb)
1909 {
1910         p80211netdev_rx(wlandev, skb);
1911         return;
1912 }
1913
1914 /*----------------------------------------------------------------
1915 * prism2sta_ev_alloc
1916 *
1917 * Handles the Alloc event.
1918 *
1919 * Arguments:
1920 *       wlandev         wlan device structure
1921 *
1922 * Returns:
1923 *       nothing
1924 *
1925 * Side effects:
1926 *
1927 * Call context:
1928 *       interrupt
1929 ----------------------------------------------------------------*/
1930 void prism2sta_ev_alloc(wlandevice_t *wlandev)
1931 {
1932         netif_wake_queue(wlandev->netdev);
1933         return;
1934 }
1935
1936 /*----------------------------------------------------------------
1937 * create_wlan
1938 *
1939 * Called at module init time.  This creates the wlandevice_t structure
1940 * and initializes it with relevant bits.
1941 *
1942 * Arguments:
1943 *       none
1944 *
1945 * Returns:
1946 *       the created wlandevice_t structure.
1947 *
1948 * Side effects:
1949 *       also allocates the priv/hw structures.
1950 *
1951 * Call context:
1952 *       process thread
1953 *
1954 ----------------------------------------------------------------*/
1955 static wlandevice_t *create_wlan(void)
1956 {
1957         wlandevice_t *wlandev = NULL;
1958         hfa384x_t *hw = NULL;
1959
1960         /* Alloc our structures */
1961         wlandev = kmalloc(sizeof(wlandevice_t), GFP_KERNEL);
1962         hw = kmalloc(sizeof(hfa384x_t), GFP_KERNEL);
1963
1964         if (!wlandev || !hw) {
1965                 printk(KERN_ERR "%s: Memory allocation failure.\n", dev_info);
1966                 kfree(wlandev);
1967                 kfree(hw);
1968                 return NULL;
1969         }
1970
1971         /* Clear all the structs */
1972         memset(wlandev, 0, sizeof(wlandevice_t));
1973         memset(hw, 0, sizeof(hfa384x_t));
1974
1975         /* Initialize the network device object. */
1976         wlandev->nsdname = dev_info;
1977         wlandev->msdstate = WLAN_MSD_HWPRESENT_PENDING;
1978         wlandev->priv = hw;
1979         wlandev->open = prism2sta_open;
1980         wlandev->close = prism2sta_close;
1981         wlandev->reset = prism2sta_reset;
1982         wlandev->txframe = prism2sta_txframe;
1983         wlandev->mlmerequest = prism2sta_mlmerequest;
1984         wlandev->set_multicast_list = prism2sta_setmulticast;
1985         wlandev->tx_timeout = hfa384x_tx_timeout;
1986
1987         wlandev->nsdcaps = P80211_NSDCAP_HWFRAGMENT | P80211_NSDCAP_AUTOJOIN;
1988
1989         /* Initialize the device private data stucture. */
1990         hw->dot11_desired_bss_type = 1;
1991
1992         return wlandev;
1993 }
1994
1995 void prism2sta_commsqual_defer(struct work_struct *data)
1996 {
1997         hfa384x_t *hw = container_of(data, struct hfa384x, commsqual_bh);
1998         wlandevice_t *wlandev = hw->wlandev;
1999         hfa384x_bytestr32_t ssid;
2000         int result = 0;
2001
2002         if (hw->wlandev->hwremoved)
2003                 goto done;
2004
2005         /* we don't care if we're in AP mode */
2006         if ((wlandev->macmode == WLAN_MACMODE_NONE) ||
2007             (wlandev->macmode == WLAN_MACMODE_ESS_AP)) {
2008                 goto done;
2009         }
2010
2011         /* It only makes sense to poll these in non-IBSS */
2012         if (wlandev->macmode != WLAN_MACMODE_IBSS_STA) {
2013                 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_DBMCOMMSQUALITY,
2014                                                 &hw->qual,
2015                                                 HFA384x_RID_DBMCOMMSQUALITY_LEN);
2016
2017                 if (result) {
2018                         printk(KERN_ERR "error fetching commsqual\n");
2019                         goto done;
2020                 }
2021
2022                 pr_debug("commsqual %d %d %d\n",
2023                        le16_to_cpu(hw->qual.CQ_currBSS),
2024                        le16_to_cpu(hw->qual.ASL_currBSS),
2025                        le16_to_cpu(hw->qual.ANL_currFC));
2026         }
2027
2028         /* Lastly, we need to make sure the BSSID didn't change on us */
2029         result = hfa384x_drvr_getconfig(hw,
2030                                         HFA384x_RID_CURRENTBSSID,
2031                                         wlandev->bssid, WLAN_BSSID_LEN);
2032         if (result) {
2033                 printk(KERN_DEBUG
2034                        "getconfig(0x%02x) failed, result = %d\n",
2035                        HFA384x_RID_CURRENTBSSID, result);
2036                 goto done;
2037         }
2038
2039         result = hfa384x_drvr_getconfig(hw,
2040                                         HFA384x_RID_CURRENTSSID,
2041                                         &ssid, sizeof(ssid));
2042         if (result) {
2043                 printk(KERN_DEBUG
2044                        "getconfig(0x%02x) failed, result = %d\n",
2045                        HFA384x_RID_CURRENTSSID, result);
2046                 goto done;
2047         }
2048         prism2mgmt_bytestr2pstr((hfa384x_bytestr_t *)&ssid,
2049                                 (p80211pstrd_t *)&wlandev->ssid);
2050
2051         /* Reschedule timer */
2052         mod_timer(&hw->commsqual_timer, jiffies + HZ);
2053
2054 done:
2055         ;
2056 }
2057
2058 void prism2sta_commsqual_timer(unsigned long data)
2059 {
2060         hfa384x_t *hw = (hfa384x_t *) data;
2061
2062         schedule_work(&hw->commsqual_bh);
2063 }