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