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