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