Merge tag 'driver-core-3.18-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git...
[cascardo/linux.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
364                         pr_debug("Received mlme ifstate request\n");
365                         ifstatemsg = (struct p80211msg_lnxreq_ifstate *) msg;
366                         result =
367                             prism2sta_ifstate(wlandev,
368                                               ifstatemsg->ifstate.data);
369                         ifstatemsg->resultcode.status =
370                             P80211ENUM_msgitem_status_data_ok;
371                         ifstatemsg->resultcode.data = result;
372                         result = 0;
373                 }
374                 break;
375         case DIDmsg_lnxreq_wlansniff:
376                 pr_debug("Received mlme wlansniff request\n");
377                 result = prism2mgmt_wlansniff(wlandev, msg);
378                 break;
379         case DIDmsg_lnxreq_autojoin:
380                 pr_debug("Received mlme autojoin request\n");
381                 result = prism2mgmt_autojoin(wlandev, msg);
382                 break;
383         case DIDmsg_lnxreq_commsquality:{
384                         struct p80211msg_lnxreq_commsquality *qualmsg;
385
386                         pr_debug("Received commsquality request\n");
387
388                         qualmsg = (struct p80211msg_lnxreq_commsquality *) msg;
389
390                         qualmsg->link.status =
391                             P80211ENUM_msgitem_status_data_ok;
392                         qualmsg->level.status =
393                             P80211ENUM_msgitem_status_data_ok;
394                         qualmsg->noise.status =
395                             P80211ENUM_msgitem_status_data_ok;
396
397                         qualmsg->link.data = le16_to_cpu(hw->qual.CQ_currBSS);
398                         qualmsg->level.data = le16_to_cpu(hw->qual.ASL_currBSS);
399                         qualmsg->noise.data = le16_to_cpu(hw->qual.ANL_currFC);
400                         qualmsg->txrate.data = hw->txrate;
401
402                         break;
403                 }
404         default:
405                 netdev_warn(wlandev->netdev,
406                             "Unknown mgmt request message 0x%08x",
407                             msg->msgcode);
408                 break;
409         }
410
411         return result;
412 }
413
414 /*----------------------------------------------------------------
415 * prism2sta_ifstate
416 *
417 * Interface state.  This is the primary WLAN interface enable/disable
418 * handler.  Following the driver/load/deviceprobe sequence, this
419 * function must be called with a state of "enable" before any other
420 * commands will be accepted.
421 *
422 * Arguments:
423 *       wlandev         wlan device structure
424 *       msgp            ptr to msg buffer
425 *
426 * Returns:
427 *       A p80211 message resultcode value.
428 *
429 * Side effects:
430 *
431 * Call context:
432 *       process thread  (usually)
433 *       interrupt
434 ----------------------------------------------------------------*/
435 u32 prism2sta_ifstate(wlandevice_t *wlandev, u32 ifstate)
436 {
437         hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
438         u32 result;
439
440         result = P80211ENUM_resultcode_implementation_failure;
441
442         pr_debug("Current MSD state(%d), requesting(%d)\n",
443                  wlandev->msdstate, ifstate);
444         switch (ifstate) {
445         case P80211ENUM_ifstate_fwload:
446                 switch (wlandev->msdstate) {
447                 case WLAN_MSD_HWPRESENT:
448                         wlandev->msdstate = WLAN_MSD_FWLOAD_PENDING;
449                         /*
450                          * Initialize the device+driver sufficiently
451                          * for firmware loading.
452                          */
453                         result = hfa384x_drvr_start(hw);
454                         if (result) {
455                                 netdev_err(wlandev->netdev,
456                                        "hfa384x_drvr_start() failed,result=%d\n", (int)result);
457                                 result =
458                                  P80211ENUM_resultcode_implementation_failure;
459                                 wlandev->msdstate = WLAN_MSD_HWPRESENT;
460                                 break;
461                         }
462                         wlandev->msdstate = WLAN_MSD_FWLOAD;
463                         result = P80211ENUM_resultcode_success;
464                         break;
465                 case WLAN_MSD_FWLOAD:
466                         hfa384x_cmd_initialize(hw);
467                         result = P80211ENUM_resultcode_success;
468                         break;
469                 case WLAN_MSD_RUNNING:
470                         netdev_warn(wlandev->netdev,
471                                     "Cannot enter fwload state from enable state, 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
1411                         joinreq = hw->joinreq;
1412                         /* Send the join request */
1413                         hfa384x_drvr_setconfig(hw,
1414                                                HFA384x_RID_JOINREQUEST,
1415                                                &joinreq,
1416                                                HFA384x_RID_JOINREQUEST_LEN);
1417                         netdev_info(wlandev->netdev,
1418                                "linkstatus=ASSOCFAIL (re-submitting join)\n");
1419                 } else {
1420                         netdev_info(wlandev->netdev, "linkstatus=ASSOCFAIL (unhandled)\n");
1421                 }
1422
1423                 netif_carrier_off(wlandev->netdev);
1424
1425                 /* signal back up to cfg80211 layer */
1426                 prism2_connect_result(wlandev, P80211ENUM_truth_true);
1427
1428                 break;
1429
1430         default:
1431                 /* This is bad, IO port problems? */
1432                 netdev_warn(wlandev->netdev,
1433                        "unknown linkstatus=0x%02x\n", hw->link_status);
1434                 return;
1435         }
1436
1437         wlandev->linkstatus = (hw->link_status == HFA384x_LINK_CONNECTED);
1438 }
1439
1440 /*----------------------------------------------------------------
1441 * prism2sta_inf_linkstatus
1442 *
1443 * Handles the receipt of a Link Status info frame.
1444 *
1445 * Arguments:
1446 *       wlandev         wlan device structure
1447 *       inf             ptr to info frame (contents in hfa384x order)
1448 *
1449 * Returns:
1450 *       nothing
1451 *
1452 * Side effects:
1453 *
1454 * Call context:
1455 *       interrupt
1456 ----------------------------------------------------------------*/
1457 static void prism2sta_inf_linkstatus(wlandevice_t *wlandev,
1458                                      hfa384x_InfFrame_t *inf)
1459 {
1460         hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
1461
1462         hw->link_status_new = le16_to_cpu(inf->info.linkstatus.linkstatus);
1463
1464         schedule_work(&hw->link_bh);
1465 }
1466
1467 /*----------------------------------------------------------------
1468 * prism2sta_inf_assocstatus
1469 *
1470 * Handles the receipt of an Association Status info frame. Should
1471 * be present in APs only.
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_assocstatus(wlandevice_t *wlandev,
1486                                       hfa384x_InfFrame_t *inf)
1487 {
1488         hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
1489         hfa384x_AssocStatus_t rec;
1490         int i;
1491
1492         memcpy(&rec, &inf->info.assocstatus, sizeof(rec));
1493         rec.assocstatus = le16_to_cpu(rec.assocstatus);
1494         rec.reason = le16_to_cpu(rec.reason);
1495
1496         /*
1497          ** Find the address in the list of authenticated stations.
1498          ** If it wasn't found, then this address has not been previously
1499          ** authenticated and something weird has happened if this is
1500          ** anything other than an "authentication failed" message.
1501          ** If the address was found, then set the "associated" flag for
1502          ** that station, based on whether the station is associating or
1503          ** losing its association.  Something weird has also happened
1504          ** if we find the address in the list of authenticated stations
1505          ** but we are getting an "authentication failed" message.
1506          */
1507
1508         for (i = 0; i < hw->authlist.cnt; i++)
1509                 if (memcmp(rec.sta_addr, hw->authlist.addr[i], ETH_ALEN) == 0)
1510                         break;
1511
1512         if (i >= hw->authlist.cnt) {
1513                 if (rec.assocstatus != HFA384x_ASSOCSTATUS_AUTHFAIL)
1514                         netdev_warn(wlandev->netdev,
1515         "assocstatus info frame received for non-authenticated station.\n");
1516         } else {
1517                 hw->authlist.assoc[i] =
1518                     (rec.assocstatus == HFA384x_ASSOCSTATUS_STAASSOC ||
1519                      rec.assocstatus == HFA384x_ASSOCSTATUS_REASSOC);
1520
1521                 if (rec.assocstatus == HFA384x_ASSOCSTATUS_AUTHFAIL)
1522                         netdev_warn(wlandev->netdev,
1523 "authfail assocstatus info frame received for authenticated station.\n");
1524         }
1525 }
1526
1527 /*----------------------------------------------------------------
1528 * prism2sta_inf_authreq
1529 *
1530 * Handles the receipt of an Authentication Request info frame. Should
1531 * be present in APs only.
1532 *
1533 * Arguments:
1534 *       wlandev         wlan device structure
1535 *       inf             ptr to info frame (contents in hfa384x order)
1536 *
1537 * Returns:
1538 *       nothing
1539 *
1540 * Side effects:
1541 *
1542 * Call context:
1543 *       interrupt
1544 *
1545 ----------------------------------------------------------------*/
1546 static void prism2sta_inf_authreq(wlandevice_t *wlandev,
1547                                   hfa384x_InfFrame_t *inf)
1548 {
1549         hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
1550         struct sk_buff *skb;
1551
1552         skb = dev_alloc_skb(sizeof(*inf));
1553         if (skb) {
1554                 skb_put(skb, sizeof(*inf));
1555                 memcpy(skb->data, inf, sizeof(*inf));
1556                 skb_queue_tail(&hw->authq, skb);
1557                 schedule_work(&hw->link_bh);
1558         }
1559 }
1560
1561 static void prism2sta_inf_authreq_defer(wlandevice_t *wlandev,
1562                                         hfa384x_InfFrame_t *inf)
1563 {
1564         hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
1565         hfa384x_authenticateStation_data_t rec;
1566
1567         int i, added, result, cnt;
1568         u8 *addr;
1569
1570         /*
1571          ** Build the AuthenticateStation record.  Initialize it for denying
1572          ** authentication.
1573          */
1574
1575         memcpy(rec.address, inf->info.authreq.sta_addr, ETH_ALEN);
1576         rec.status = P80211ENUM_status_unspec_failure;
1577
1578         /*
1579          ** Authenticate based on the access mode.
1580          */
1581
1582         switch (hw->accessmode) {
1583         case WLAN_ACCESS_NONE:
1584
1585                 /*
1586                  ** Deny all new authentications.  However, if a station
1587                  ** is ALREADY authenticated, then accept it.
1588                  */
1589
1590                 for (i = 0; i < hw->authlist.cnt; i++)
1591                         if (memcmp(rec.address, hw->authlist.addr[i],
1592                                    ETH_ALEN) == 0) {
1593                                 rec.status = P80211ENUM_status_successful;
1594                                 break;
1595                         }
1596
1597                 break;
1598
1599         case WLAN_ACCESS_ALL:
1600
1601                 /*
1602                  ** Allow all authentications.
1603                  */
1604
1605                 rec.status = P80211ENUM_status_successful;
1606                 break;
1607
1608         case WLAN_ACCESS_ALLOW:
1609
1610                 /*
1611                  ** Only allow the authentication if the MAC address
1612                  ** is in the list of allowed addresses.
1613                  **
1614                  ** Since this is the interrupt handler, we may be here
1615                  ** while the access list is in the middle of being
1616                  ** updated.  Choose the list which is currently okay.
1617                  ** See "prism2mib_priv_accessallow()" for details.
1618                  */
1619
1620                 if (hw->allow.modify == 0) {
1621                         cnt = hw->allow.cnt;
1622                         addr = hw->allow.addr[0];
1623                 } else {
1624                         cnt = hw->allow.cnt1;
1625                         addr = hw->allow.addr1[0];
1626                 }
1627
1628                 for (i = 0; i < cnt; i++, addr += ETH_ALEN)
1629                         if (memcmp(rec.address, addr, ETH_ALEN) == 0) {
1630                                 rec.status = P80211ENUM_status_successful;
1631                                 break;
1632                         }
1633
1634                 break;
1635
1636         case WLAN_ACCESS_DENY:
1637
1638                 /*
1639                  ** Allow the authentication UNLESS the MAC address is
1640                  ** in the list of denied addresses.
1641                  **
1642                  ** Since this is the interrupt handler, we may be here
1643                  ** while the access list is in the middle of being
1644                  ** updated.  Choose the list which is currently okay.
1645                  ** See "prism2mib_priv_accessdeny()" for details.
1646                  */
1647
1648                 if (hw->deny.modify == 0) {
1649                         cnt = hw->deny.cnt;
1650                         addr = hw->deny.addr[0];
1651                 } else {
1652                         cnt = hw->deny.cnt1;
1653                         addr = hw->deny.addr1[0];
1654                 }
1655
1656                 rec.status = P80211ENUM_status_successful;
1657
1658                 for (i = 0; i < cnt; i++, addr += ETH_ALEN)
1659                         if (memcmp(rec.address, addr, ETH_ALEN) == 0) {
1660                                 rec.status = P80211ENUM_status_unspec_failure;
1661                                 break;
1662                         }
1663
1664                 break;
1665         }
1666
1667         /*
1668          ** If the authentication is okay, then add the MAC address to the
1669          ** list of authenticated stations.  Don't add the address if it
1670          ** is already in the list. (802.11b does not seem to disallow
1671          ** a station from issuing an authentication request when the
1672          ** station is already authenticated. Does this sort of thing
1673          ** ever happen?  We might as well do the check just in case.)
1674          */
1675
1676         added = 0;
1677
1678         if (rec.status == P80211ENUM_status_successful) {
1679                 for (i = 0; i < hw->authlist.cnt; i++)
1680                         if (memcmp(rec.address, hw->authlist.addr[i], ETH_ALEN)
1681                             == 0)
1682                                 break;
1683
1684                 if (i >= hw->authlist.cnt) {
1685                         if (hw->authlist.cnt >= WLAN_AUTH_MAX) {
1686                                 rec.status = P80211ENUM_status_ap_full;
1687                         } else {
1688                                 memcpy(hw->authlist.addr[hw->authlist.cnt],
1689                                        rec.address, ETH_ALEN);
1690                                 hw->authlist.cnt++;
1691                                 added = 1;
1692                         }
1693                 }
1694         }
1695
1696         /*
1697          ** Send back the results of the authentication.  If this doesn't work,
1698          ** then make sure to remove the address from the authenticated list if
1699          ** it was added.
1700          */
1701
1702         rec.status = cpu_to_le16(rec.status);
1703         rec.algorithm = inf->info.authreq.algorithm;
1704
1705         result = hfa384x_drvr_setconfig(hw, HFA384x_RID_AUTHENTICATESTA,
1706                                         &rec, sizeof(rec));
1707         if (result) {
1708                 if (added)
1709                         hw->authlist.cnt--;
1710                 netdev_err(wlandev->netdev,
1711                        "setconfig(authenticatestation) failed, result=%d\n",
1712                        result);
1713         }
1714 }
1715
1716 /*----------------------------------------------------------------
1717 * prism2sta_inf_psusercnt
1718 *
1719 * Handles the receipt of a PowerSaveUserCount info frame. Should
1720 * be present in APs only.
1721 *
1722 * Arguments:
1723 *       wlandev         wlan device structure
1724 *       inf             ptr to info frame (contents in hfa384x order)
1725 *
1726 * Returns:
1727 *       nothing
1728 *
1729 * Side effects:
1730 *
1731 * Call context:
1732 *       interrupt
1733 ----------------------------------------------------------------*/
1734 static void prism2sta_inf_psusercnt(wlandevice_t *wlandev,
1735                                     hfa384x_InfFrame_t *inf)
1736 {
1737         hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
1738
1739         hw->psusercount = le16_to_cpu(inf->info.psusercnt.usercnt);
1740 }
1741
1742 /*----------------------------------------------------------------
1743 * prism2sta_ev_info
1744 *
1745 * Handles the Info event.
1746 *
1747 * Arguments:
1748 *       wlandev         wlan device structure
1749 *       inf             ptr to a generic info frame
1750 *
1751 * Returns:
1752 *       nothing
1753 *
1754 * Side effects:
1755 *
1756 * Call context:
1757 *       interrupt
1758 ----------------------------------------------------------------*/
1759 void prism2sta_ev_info(wlandevice_t *wlandev, hfa384x_InfFrame_t *inf)
1760 {
1761         inf->infotype = le16_to_cpu(inf->infotype);
1762         /* Dispatch */
1763         switch (inf->infotype) {
1764         case HFA384x_IT_HANDOVERADDR:
1765                 prism2sta_inf_handover(wlandev, inf);
1766                 break;
1767         case HFA384x_IT_COMMTALLIES:
1768                 prism2sta_inf_tallies(wlandev, inf);
1769                 break;
1770         case HFA384x_IT_HOSTSCANRESULTS:
1771                 prism2sta_inf_hostscanresults(wlandev, inf);
1772                 break;
1773         case HFA384x_IT_SCANRESULTS:
1774                 prism2sta_inf_scanresults(wlandev, inf);
1775                 break;
1776         case HFA384x_IT_CHINFORESULTS:
1777                 prism2sta_inf_chinforesults(wlandev, inf);
1778                 break;
1779         case HFA384x_IT_LINKSTATUS:
1780                 prism2sta_inf_linkstatus(wlandev, inf);
1781                 break;
1782         case HFA384x_IT_ASSOCSTATUS:
1783                 prism2sta_inf_assocstatus(wlandev, inf);
1784                 break;
1785         case HFA384x_IT_AUTHREQ:
1786                 prism2sta_inf_authreq(wlandev, inf);
1787                 break;
1788         case HFA384x_IT_PSUSERCNT:
1789                 prism2sta_inf_psusercnt(wlandev, inf);
1790                 break;
1791         case HFA384x_IT_KEYIDCHANGED:
1792                 netdev_warn(wlandev->netdev, "Unhandled IT_KEYIDCHANGED\n");
1793                 break;
1794         case HFA384x_IT_ASSOCREQ:
1795                 netdev_warn(wlandev->netdev, "Unhandled IT_ASSOCREQ\n");
1796                 break;
1797         case HFA384x_IT_MICFAILURE:
1798                 netdev_warn(wlandev->netdev, "Unhandled IT_MICFAILURE\n");
1799                 break;
1800         default:
1801                 netdev_warn(wlandev->netdev,
1802                        "Unknown info type=0x%02x\n", inf->infotype);
1803                 break;
1804         }
1805 }
1806
1807 /*----------------------------------------------------------------
1808 * prism2sta_ev_txexc
1809 *
1810 * Handles the TxExc event.  A Transmit Exception event indicates
1811 * that the MAC's TX process was unsuccessful - so the packet did
1812 * not get transmitted.
1813 *
1814 * Arguments:
1815 *       wlandev         wlan device structure
1816 *       status          tx frame status word
1817 *
1818 * Returns:
1819 *       nothing
1820 *
1821 * Side effects:
1822 *
1823 * Call context:
1824 *       interrupt
1825 ----------------------------------------------------------------*/
1826 void prism2sta_ev_txexc(wlandevice_t *wlandev, u16 status)
1827 {
1828         pr_debug("TxExc status=0x%x.\n", status);
1829 }
1830
1831 /*----------------------------------------------------------------
1832 * prism2sta_ev_tx
1833 *
1834 * Handles the Tx event.
1835 *
1836 * Arguments:
1837 *       wlandev         wlan device structure
1838 *       status          tx frame status word
1839 * Returns:
1840 *       nothing
1841 *
1842 * Side effects:
1843 *
1844 * Call context:
1845 *       interrupt
1846 ----------------------------------------------------------------*/
1847 void prism2sta_ev_tx(wlandevice_t *wlandev, u16 status)
1848 {
1849         pr_debug("Tx Complete, status=0x%04x\n", status);
1850         /* update linux network stats */
1851         wlandev->netdev->stats.tx_packets++;
1852 }
1853
1854 /*----------------------------------------------------------------
1855 * prism2sta_ev_rx
1856 *
1857 * Handles the Rx event.
1858 *
1859 * Arguments:
1860 *       wlandev         wlan device structure
1861 *
1862 * Returns:
1863 *       nothing
1864 *
1865 * Side effects:
1866 *
1867 * Call context:
1868 *       interrupt
1869 ----------------------------------------------------------------*/
1870 void prism2sta_ev_rx(wlandevice_t *wlandev, struct sk_buff *skb)
1871 {
1872         p80211netdev_rx(wlandev, skb);
1873 }
1874
1875 /*----------------------------------------------------------------
1876 * prism2sta_ev_alloc
1877 *
1878 * Handles the Alloc event.
1879 *
1880 * Arguments:
1881 *       wlandev         wlan device structure
1882 *
1883 * Returns:
1884 *       nothing
1885 *
1886 * Side effects:
1887 *
1888 * Call context:
1889 *       interrupt
1890 ----------------------------------------------------------------*/
1891 void prism2sta_ev_alloc(wlandevice_t *wlandev)
1892 {
1893         netif_wake_queue(wlandev->netdev);
1894 }
1895
1896 /*----------------------------------------------------------------
1897 * create_wlan
1898 *
1899 * Called at module init time.  This creates the wlandevice_t structure
1900 * and initializes it with relevant bits.
1901 *
1902 * Arguments:
1903 *       none
1904 *
1905 * Returns:
1906 *       the created wlandevice_t structure.
1907 *
1908 * Side effects:
1909 *       also allocates the priv/hw structures.
1910 *
1911 * Call context:
1912 *       process thread
1913 *
1914 ----------------------------------------------------------------*/
1915 static wlandevice_t *create_wlan(void)
1916 {
1917         wlandevice_t *wlandev = NULL;
1918         hfa384x_t *hw = NULL;
1919
1920         /* Alloc our structures */
1921         wlandev = kzalloc(sizeof(wlandevice_t), GFP_KERNEL);
1922         hw = kzalloc(sizeof(hfa384x_t), GFP_KERNEL);
1923
1924         if (!wlandev || !hw) {
1925                 pr_err("%s: Memory allocation failure.\n", dev_info);
1926                 kfree(wlandev);
1927                 kfree(hw);
1928                 return NULL;
1929         }
1930
1931         /* Initialize the network device object. */
1932         wlandev->nsdname = dev_info;
1933         wlandev->msdstate = WLAN_MSD_HWPRESENT_PENDING;
1934         wlandev->priv = hw;
1935         wlandev->open = prism2sta_open;
1936         wlandev->close = prism2sta_close;
1937         wlandev->reset = prism2sta_reset;
1938         wlandev->txframe = prism2sta_txframe;
1939         wlandev->mlmerequest = prism2sta_mlmerequest;
1940         wlandev->set_multicast_list = prism2sta_setmulticast;
1941         wlandev->tx_timeout = hfa384x_tx_timeout;
1942
1943         wlandev->nsdcaps = P80211_NSDCAP_HWFRAGMENT | P80211_NSDCAP_AUTOJOIN;
1944
1945         /* Initialize the device private data structure. */
1946         hw->dot11_desired_bss_type = 1;
1947
1948         return wlandev;
1949 }
1950
1951 void prism2sta_commsqual_defer(struct work_struct *data)
1952 {
1953         hfa384x_t *hw = container_of(data, struct hfa384x, commsqual_bh);
1954         wlandevice_t *wlandev = hw->wlandev;
1955         hfa384x_bytestr32_t ssid;
1956         struct p80211msg_dot11req_mibget msg;
1957         p80211item_uint32_t *mibitem = (p80211item_uint32_t *)
1958                                                 &msg.mibattribute.data;
1959         int result = 0;
1960
1961         if (hw->wlandev->hwremoved)
1962                 return;
1963
1964         /* we don't care if we're in AP mode */
1965         if ((wlandev->macmode == WLAN_MACMODE_NONE) ||
1966             (wlandev->macmode == WLAN_MACMODE_ESS_AP)) {
1967                 return;
1968         }
1969
1970         /* It only makes sense to poll these in non-IBSS */
1971         if (wlandev->macmode != WLAN_MACMODE_IBSS_STA) {
1972                 result = hfa384x_drvr_getconfig(
1973                                 hw, HFA384x_RID_DBMCOMMSQUALITY,
1974                                 &hw->qual, HFA384x_RID_DBMCOMMSQUALITY_LEN);
1975
1976                 if (result) {
1977                         netdev_err(wlandev->netdev, "error fetching commsqual\n");
1978                         return;
1979                 }
1980
1981                 pr_debug("commsqual %d %d %d\n",
1982                          le16_to_cpu(hw->qual.CQ_currBSS),
1983                          le16_to_cpu(hw->qual.ASL_currBSS),
1984                          le16_to_cpu(hw->qual.ANL_currFC));
1985         }
1986
1987         /* Get the signal rate */
1988         msg.msgcode = DIDmsg_dot11req_mibget;
1989         mibitem->did = DIDmib_p2_p2MAC_p2CurrentTxRate;
1990         result = p80211req_dorequest(wlandev, (u8 *) &msg);
1991
1992         if (result) {
1993                 pr_debug("get signal rate failed, result = %d\n",
1994                          result);
1995                 return;
1996         }
1997
1998         switch (mibitem->data) {
1999         case HFA384x_RATEBIT_1:
2000                 hw->txrate = 10;
2001                 break;
2002         case HFA384x_RATEBIT_2:
2003                 hw->txrate = 20;
2004                 break;
2005         case HFA384x_RATEBIT_5dot5:
2006                 hw->txrate = 55;
2007                 break;
2008         case HFA384x_RATEBIT_11:
2009                 hw->txrate = 110;
2010                 break;
2011         default:
2012                 pr_debug("Bad ratebit (%d)\n", mibitem->data);
2013         }
2014
2015         /* Lastly, we need to make sure the BSSID didn't change on us */
2016         result = hfa384x_drvr_getconfig(hw,
2017                                         HFA384x_RID_CURRENTBSSID,
2018                                         wlandev->bssid, WLAN_BSSID_LEN);
2019         if (result) {
2020                 pr_debug("getconfig(0x%02x) failed, result = %d\n",
2021                          HFA384x_RID_CURRENTBSSID, result);
2022                 return;
2023         }
2024
2025         result = hfa384x_drvr_getconfig(hw,
2026                                         HFA384x_RID_CURRENTSSID,
2027                                         &ssid, sizeof(ssid));
2028         if (result) {
2029                 pr_debug("getconfig(0x%02x) failed, result = %d\n",
2030                          HFA384x_RID_CURRENTSSID, result);
2031                 return;
2032         }
2033         prism2mgmt_bytestr2pstr((struct hfa384x_bytestr *) &ssid,
2034                                 (p80211pstrd_t *) &wlandev->ssid);
2035
2036         /* Reschedule timer */
2037         mod_timer(&hw->commsqual_timer, jiffies + HZ);
2038 }
2039
2040 void prism2sta_commsqual_timer(unsigned long data)
2041 {
2042         hfa384x_t *hw = (hfa384x_t *) data;
2043
2044         schedule_work(&hw->commsqual_bh);
2045 }