1 /* src/prism2/driver/prism2sta.c
3 * Implements the station functionality for prism2
5 * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved.
6 * --------------------------------------------------------------------
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/
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.
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.
31 * --------------------------------------------------------------------
33 * Inquiries regarding the linux-wlan Open Source project can be
36 * AbsoluteValue Systems Inc.
38 * http://www.linux-wlan.com
40 * --------------------------------------------------------------------
42 * Portions of the development of this software were funded by
43 * Intersil Corporation as part of PRISM(R) chipset product development.
45 * --------------------------------------------------------------------
47 * This file implements the module and linux pcmcia routines for the
50 * --------------------------------------------------------------------
53 /*================================================================*/
55 #define WLAN_DBVAR prism2_debug
57 #include <linux/version.h>
58 #include <linux/module.h>
59 #include <linux/moduleparam.h>
60 #include <linux/kernel.h>
61 #include <linux/sched.h>
62 #include <linux/types.h>
63 #include <linux/init.h>
64 #include <linux/slab.h>
65 #include <linux/wireless.h>
66 #include <linux/netdevice.h>
67 #include <linux/workqueue.h>
68 #include <linux/byteorder/generic.h>
71 #include <linux/delay.h>
72 #include <asm/byteorder.h>
73 #include <linux/if_arp.h>
74 #include <linux/if_ether.h>
75 #include <linux/bitops.h>
77 #include "wlan_compat.h"
79 /*================================================================*/
80 /* Project Includes */
82 #include "p80211types.h"
83 #include "p80211hdr.h"
84 #include "p80211mgmt.h"
85 #include "p80211conv.h"
86 #include "p80211msg.h"
87 #include "p80211netdev.h"
88 #include "p80211req.h"
89 #include "p80211metadef.h"
90 #include "p80211metastruct.h"
92 #include "prism2mgmt.h"
94 /*================================================================*/
97 /*================================================================*/
100 /*================================================================*/
103 /*================================================================*/
104 /* Local Static Definitions */
106 static char *dev_info = "prism2_usb";
108 static wlandevice_t *create_wlan(void);
110 /*----------------------------------------------------------------*/
111 /* --Module Parameters */
113 int prism2_reset_holdtime=30; /* Reset hold time in ms */
114 int prism2_reset_settletime=100; /* Reset settle time in ms */
116 static int prism2_doreset=0; /* Do a reset at init? */
118 #ifdef WLAN_INCLUDE_DEBUG
120 module_param( prism2_debug, int, 0644);
121 MODULE_PARM_DESC(prism2_debug, "prism2 debugging");
124 module_param( prism2_doreset, int, 0644);
125 MODULE_PARM_DESC(prism2_doreset, "Issue a reset on initialization");
127 module_param( prism2_reset_holdtime, int, 0644);
128 MODULE_PARM_DESC( prism2_reset_holdtime, "reset hold time in ms");
129 module_param( prism2_reset_settletime, int, 0644);
130 MODULE_PARM_DESC( prism2_reset_settletime, "reset settle time in ms");
132 MODULE_LICENSE("Dual MPL/GPL");
134 /*================================================================*/
135 /* Local Function Declarations */
137 static int prism2sta_open(wlandevice_t *wlandev);
138 static int prism2sta_close(wlandevice_t *wlandev);
139 static void prism2sta_reset(wlandevice_t *wlandev );
140 static int prism2sta_txframe(wlandevice_t *wlandev, struct sk_buff *skb, p80211_hdr_t *p80211_hdr, p80211_metawep_t *p80211_wep);
141 static int prism2sta_mlmerequest(wlandevice_t *wlandev, p80211msg_t *msg);
142 static int prism2sta_getcardinfo(wlandevice_t *wlandev);
143 static int prism2sta_globalsetup(wlandevice_t *wlandev);
144 static int prism2sta_setmulticast(wlandevice_t *wlandev,
147 static void prism2sta_inf_handover(
148 wlandevice_t *wlandev, hfa384x_InfFrame_t *inf);
149 static void prism2sta_inf_tallies(
150 wlandevice_t *wlandev, hfa384x_InfFrame_t *inf);
151 static void prism2sta_inf_hostscanresults(
152 wlandevice_t *wlandev, hfa384x_InfFrame_t *inf);
153 static void prism2sta_inf_scanresults(
154 wlandevice_t *wlandev, hfa384x_InfFrame_t *inf);
155 static void prism2sta_inf_chinforesults(
156 wlandevice_t *wlandev, hfa384x_InfFrame_t *inf);
157 static void prism2sta_inf_linkstatus(
158 wlandevice_t *wlandev, hfa384x_InfFrame_t *inf);
159 static void prism2sta_inf_assocstatus(
160 wlandevice_t *wlandev, hfa384x_InfFrame_t *inf);
161 static void prism2sta_inf_authreq(
162 wlandevice_t *wlandev, hfa384x_InfFrame_t *inf);
163 static void prism2sta_inf_authreq_defer(
164 wlandevice_t *wlandev, hfa384x_InfFrame_t *inf);
165 static void prism2sta_inf_psusercnt(
166 wlandevice_t *wlandev, hfa384x_InfFrame_t *inf);
168 /*================================================================*/
169 /* Function Definitions */
171 /*----------------------------------------------------------------
174 * Debug utility function to dump memory to the kernel debug log.
177 * buf ptr data we want dumped
187 ----------------------------------------------------------------*/
188 inline void dmpmem(void *buf, int n)
191 for ( c= 0; c < n; c++) {
192 if ( (c % 16) == 0 ) printk(KERN_DEBUG"dmp[%d]: ", c);
193 printk("%02x ", ((u8*)buf)[c]);
194 if ( (c % 16) == 15 ) printk("\n");
196 if ( (c % 16) != 0 ) printk("\n");
200 /*----------------------------------------------------------------
203 * WLAN device open method. Called from p80211netdev when kernel
204 * device open (start) method is called in response to the
205 * SIOCSIIFFLAGS ioctl changing the flags bit IFF_UP
209 * wlandev wlan device structure
213 * >0 f/w reported error
214 * <0 driver reported error
220 ----------------------------------------------------------------*/
221 static int prism2sta_open(wlandevice_t *wlandev)
223 /* We don't currently have to do anything else.
224 * The setup of the MAC should be subsequently completed via
226 * Higher layers know we're ready from dev->start==1 and
227 * dev->tbusy==0. Our rx path knows to pass up received/
228 * frames because of dev->flags&IFF_UP is true.
235 /*----------------------------------------------------------------
238 * WLAN device close method. Called from p80211netdev when kernel
239 * device close method is called in response to the
240 * SIOCSIIFFLAGS ioctl changing the flags bit IFF_UP
244 * wlandev wlan device structure
248 * >0 f/w reported error
249 * <0 driver reported error
255 ----------------------------------------------------------------*/
256 static int prism2sta_close(wlandevice_t *wlandev)
258 /* We don't currently have to do anything else.
259 * Higher layers know we're not ready from dev->start==0 and
260 * dev->tbusy==1. Our rx path knows to not pass up received
261 * frames because of dev->flags&IFF_UP is false.
268 /*----------------------------------------------------------------
271 * Not currently implented.
274 * wlandev wlan device structure
284 ----------------------------------------------------------------*/
285 static void prism2sta_reset(wlandevice_t *wlandev )
291 /*----------------------------------------------------------------
294 * Takes a frame from p80211 and queues it for transmission.
297 * wlandev wlan device structure
298 * pb packet buffer struct. Contains an 802.11
300 * p80211_hdr points to the 802.11 header for the packet.
302 * 0 Success and more buffs available
303 * 1 Success but no more buffs
304 * 2 Allocation failure
305 * 4 Buffer full or queue busy
311 ----------------------------------------------------------------*/
312 static int prism2sta_txframe(wlandevice_t *wlandev, struct sk_buff *skb,
313 p80211_hdr_t *p80211_hdr,
314 p80211_metawep_t *p80211_wep)
316 hfa384x_t *hw = (hfa384x_t *)wlandev->priv;
319 /* If necessary, set the 802.11 WEP bit */
320 if ((wlandev->hostwep & (HOSTWEP_PRIVACYINVOKED | HOSTWEP_ENCRYPT)) == HOSTWEP_PRIVACYINVOKED) {
321 p80211_hdr->a3.fc |= cpu_to_le16(WLAN_SET_FC_ISWEP(1));
324 result = hfa384x_drvr_txframe(hw, skb, p80211_hdr, p80211_wep);
330 /*----------------------------------------------------------------
331 * prism2sta_mlmerequest
333 * wlan command message handler. All we do here is pass the message
334 * over to the prism2sta_mgmt_handler.
337 * wlandev wlan device structure
338 * msg wlan command message
341 * <0 successful acceptance of message, but we're
342 * waiting for an async process to finish before
343 * we're done with the msg. When the asynch
344 * process is done, we'll call the p80211
345 * function p80211req_confirm() .
346 * >0 An error occurred while we were handling
353 ----------------------------------------------------------------*/
354 static int prism2sta_mlmerequest(wlandevice_t *wlandev, p80211msg_t *msg)
356 hfa384x_t *hw = (hfa384x_t *)wlandev->priv;
360 switch( msg->msgcode )
362 case DIDmsg_dot11req_mibget :
363 WLAN_LOG_DEBUG(2,"Received mibget request\n");
364 result = prism2mgmt_mibset_mibget(wlandev, msg);
366 case DIDmsg_dot11req_mibset :
367 WLAN_LOG_DEBUG(2,"Received mibset request\n");
368 result = prism2mgmt_mibset_mibget(wlandev, msg);
370 case DIDmsg_dot11req_scan :
371 WLAN_LOG_DEBUG(2,"Received scan request\n");
372 result = prism2mgmt_scan(wlandev, msg);
374 case DIDmsg_dot11req_scan_results :
375 WLAN_LOG_DEBUG(2,"Received scan_results request\n");
376 result = prism2mgmt_scan_results(wlandev, msg);
378 case DIDmsg_dot11req_start :
379 WLAN_LOG_DEBUG(2,"Received mlme start request\n");
380 result = prism2mgmt_start(wlandev, msg);
383 * Prism2 specific messages
385 case DIDmsg_p2req_readpda :
386 WLAN_LOG_DEBUG(2,"Received mlme readpda request\n");
387 result = prism2mgmt_readpda(wlandev, msg);
389 case DIDmsg_p2req_ramdl_state :
390 WLAN_LOG_DEBUG(2,"Received mlme ramdl_state request\n");
391 result = prism2mgmt_ramdl_state(wlandev, msg);
393 case DIDmsg_p2req_ramdl_write :
394 WLAN_LOG_DEBUG(2,"Received mlme ramdl_write request\n");
395 result = prism2mgmt_ramdl_write(wlandev, msg);
397 case DIDmsg_p2req_flashdl_state :
398 WLAN_LOG_DEBUG(2,"Received mlme flashdl_state request\n");
399 result = prism2mgmt_flashdl_state(wlandev, msg);
401 case DIDmsg_p2req_flashdl_write :
402 WLAN_LOG_DEBUG(2,"Received mlme flashdl_write request\n");
403 result = prism2mgmt_flashdl_write(wlandev, msg);
406 * Linux specific messages
408 case DIDmsg_lnxreq_hostwep :
410 case DIDmsg_lnxreq_ifstate :
412 p80211msg_lnxreq_ifstate_t *ifstatemsg;
413 WLAN_LOG_DEBUG(2,"Received mlme ifstate request\n");
414 ifstatemsg = (p80211msg_lnxreq_ifstate_t*)msg;
415 result = prism2sta_ifstate(wlandev, ifstatemsg->ifstate.data);
416 ifstatemsg->resultcode.status =
417 P80211ENUM_msgitem_status_data_ok;
418 ifstatemsg->resultcode.data = result;
422 case DIDmsg_lnxreq_wlansniff :
423 WLAN_LOG_DEBUG(2,"Received mlme wlansniff request\n");
424 result = prism2mgmt_wlansniff(wlandev, msg);
426 case DIDmsg_lnxreq_autojoin :
427 WLAN_LOG_DEBUG(2,"Received mlme autojoin request\n");
428 result = prism2mgmt_autojoin(wlandev, msg);
430 case DIDmsg_lnxreq_commsquality: {
431 p80211msg_lnxreq_commsquality_t *qualmsg;
433 WLAN_LOG_DEBUG(2,"Received commsquality request\n");
435 qualmsg = (p80211msg_lnxreq_commsquality_t*) msg;
437 qualmsg->link.status = P80211ENUM_msgitem_status_data_ok;
438 qualmsg->level.status = P80211ENUM_msgitem_status_data_ok;
439 qualmsg->noise.status = P80211ENUM_msgitem_status_data_ok;
442 qualmsg->link.data = hfa384x2host_16(hw->qual.CQ_currBSS);
443 qualmsg->level.data = hfa384x2host_16(hw->qual.ASL_currBSS);
444 qualmsg->noise.data = hfa384x2host_16(hw->qual.ANL_currFC);
449 WLAN_LOG_WARNING("Unknown mgmt request message 0x%08x", msg->msgcode);
457 /*----------------------------------------------------------------
460 * Interface state. This is the primary WLAN interface enable/disable
461 * handler. Following the driver/load/deviceprobe sequence, this
462 * function must be called with a state of "enable" before any other
463 * commands will be accepted.
466 * wlandev wlan device structure
467 * msgp ptr to msg buffer
470 * A p80211 message resultcode value.
475 * process thread (usually)
477 ----------------------------------------------------------------*/
478 u32 prism2sta_ifstate(wlandevice_t *wlandev, u32 ifstate)
480 hfa384x_t *hw = (hfa384x_t *)wlandev->priv;
483 result = P80211ENUM_resultcode_implementation_failure;
485 WLAN_LOG_DEBUG(2, "Current MSD state(%d), requesting(%d)\n",
486 wlandev->msdstate, ifstate);
489 case P80211ENUM_ifstate_fwload:
490 switch (wlandev->msdstate) {
491 case WLAN_MSD_HWPRESENT:
492 wlandev->msdstate = WLAN_MSD_FWLOAD_PENDING;
494 * Initialize the device+driver sufficiently
495 * for firmware loading.
497 if ((result=hfa384x_drvr_start(hw))) {
499 "hfa384x_drvr_start() failed,"
500 "result=%d\n", (int)result);
502 P80211ENUM_resultcode_implementation_failure;
503 wlandev->msdstate = WLAN_MSD_HWPRESENT;
506 wlandev->msdstate = WLAN_MSD_FWLOAD;
507 result = P80211ENUM_resultcode_success;
509 case WLAN_MSD_FWLOAD:
510 hfa384x_cmd_initialize(hw);
511 result = P80211ENUM_resultcode_success;
513 case WLAN_MSD_RUNNING:
515 "Cannot enter fwload state from enable state,"
516 "you must disable first.\n");
517 result = P80211ENUM_resultcode_invalid_parameters;
519 case WLAN_MSD_HWFAIL:
521 /* probe() had a problem or the msdstate contains
522 * an unrecognized value, there's nothing we can do.
524 result = P80211ENUM_resultcode_implementation_failure;
528 case P80211ENUM_ifstate_enable:
529 switch (wlandev->msdstate) {
530 case WLAN_MSD_HWPRESENT:
531 case WLAN_MSD_FWLOAD:
532 wlandev->msdstate = WLAN_MSD_RUNNING_PENDING;
533 /* Initialize the device+driver for full
534 * operation. Note that this might me an FWLOAD to
535 * to RUNNING transition so we must not do a chip
536 * or board level reset. Note that on failure,
537 * the MSD state is set to HWPRESENT because we
538 * can't make any assumptions about the state
539 * of the hardware or a previous firmware load.
541 if ((result=hfa384x_drvr_start(hw))) {
543 "hfa384x_drvr_start() failed,"
544 "result=%d\n", (int)result);
546 P80211ENUM_resultcode_implementation_failure;
547 wlandev->msdstate = WLAN_MSD_HWPRESENT;
551 if ((result=prism2sta_getcardinfo(wlandev))) {
553 "prism2sta_getcardinfo() failed,"
554 "result=%d\n", (int)result);
556 P80211ENUM_resultcode_implementation_failure;
557 hfa384x_drvr_stop(hw);
558 wlandev->msdstate = WLAN_MSD_HWPRESENT;
561 if ((result=prism2sta_globalsetup(wlandev))) {
563 "prism2sta_globalsetup() failed,"
564 "result=%d\n", (int)result);
566 P80211ENUM_resultcode_implementation_failure;
567 hfa384x_drvr_stop(hw);
568 wlandev->msdstate = WLAN_MSD_HWPRESENT;
571 wlandev->msdstate = WLAN_MSD_RUNNING;
573 hw->join_retries = 60;
574 result = P80211ENUM_resultcode_success;
576 case WLAN_MSD_RUNNING:
577 /* Do nothing, we're already in this state.*/
578 result = P80211ENUM_resultcode_success;
580 case WLAN_MSD_HWFAIL:
582 /* probe() had a problem or the msdstate contains
583 * an unrecognized value, there's nothing we can do.
585 result = P80211ENUM_resultcode_implementation_failure;
589 case P80211ENUM_ifstate_disable:
590 switch (wlandev->msdstate) {
591 case WLAN_MSD_HWPRESENT:
592 /* Do nothing, we're already in this state.*/
593 result = P80211ENUM_resultcode_success;
595 case WLAN_MSD_FWLOAD:
596 case WLAN_MSD_RUNNING:
597 wlandev->msdstate = WLAN_MSD_HWPRESENT_PENDING;
599 * TODO: Shut down the MAC completely. Here a chip
600 * or board level reset is probably called for.
601 * After a "disable" _all_ results are lost, even
602 * those from a fwload.
604 if (!wlandev->hwremoved)
605 netif_carrier_off(wlandev->netdev);
607 hfa384x_drvr_stop(hw);
609 wlandev->macmode = WLAN_MACMODE_NONE;
610 wlandev->msdstate = WLAN_MSD_HWPRESENT;
611 result = P80211ENUM_resultcode_success;
613 case WLAN_MSD_HWFAIL:
615 /* probe() had a problem or the msdstate contains
616 * an unrecognized value, there's nothing we can do.
618 result = P80211ENUM_resultcode_implementation_failure;
623 result = P80211ENUM_resultcode_invalid_parameters;
631 /*----------------------------------------------------------------
632 * prism2sta_getcardinfo
634 * Collect the NICID, firmware version and any other identifiers
635 * we'd like to have in host-side data structures.
638 * wlandev wlan device structure
642 * >0 f/w reported error
643 * <0 driver reported error
649 ----------------------------------------------------------------*/
650 static int prism2sta_getcardinfo(wlandevice_t *wlandev)
653 hfa384x_t *hw = (hfa384x_t *)wlandev->priv;
655 u8 snum[HFA384x_RID_NICSERIALNUMBER_LEN];
656 char pstr[(HFA384x_RID_NICSERIALNUMBER_LEN * 4) + 1];
658 /* Collect version and compatibility info */
659 /* Some are critical, some are not */
661 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_NICIDENTITY,
662 &hw->ident_nic, sizeof(hfa384x_compident_t));
664 WLAN_LOG_ERROR("Failed to retrieve NICIDENTITY\n");
668 /* get all the nic id fields in host byte order */
669 hw->ident_nic.id = hfa384x2host_16(hw->ident_nic.id);
670 hw->ident_nic.variant = hfa384x2host_16(hw->ident_nic.variant);
671 hw->ident_nic.major = hfa384x2host_16(hw->ident_nic.major);
672 hw->ident_nic.minor = hfa384x2host_16(hw->ident_nic.minor);
674 printk(KERN_INFO "ident: nic h/w: id=0x%02x %d.%d.%d\n",
675 hw->ident_nic.id, hw->ident_nic.major,
676 hw->ident_nic.minor, hw->ident_nic.variant);
678 /* Primary f/w identity */
679 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_PRIIDENTITY,
680 &hw->ident_pri_fw, sizeof(hfa384x_compident_t));
682 WLAN_LOG_ERROR("Failed to retrieve PRIIDENTITY\n");
686 /* get all the private fw id fields in host byte order */
687 hw->ident_pri_fw.id = hfa384x2host_16(hw->ident_pri_fw.id);
688 hw->ident_pri_fw.variant = hfa384x2host_16(hw->ident_pri_fw.variant);
689 hw->ident_pri_fw.major = hfa384x2host_16(hw->ident_pri_fw.major);
690 hw->ident_pri_fw.minor = hfa384x2host_16(hw->ident_pri_fw.minor);
692 printk(KERN_INFO "ident: pri f/w: id=0x%02x %d.%d.%d\n",
693 hw->ident_pri_fw.id, hw->ident_pri_fw.major,
694 hw->ident_pri_fw.minor, hw->ident_pri_fw.variant);
696 /* Station (Secondary?) f/w identity */
697 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_STAIDENTITY,
698 &hw->ident_sta_fw, sizeof(hfa384x_compident_t));
700 WLAN_LOG_ERROR("Failed to retrieve STAIDENTITY\n");
704 if (hw->ident_nic.id < 0x8000) {
705 WLAN_LOG_ERROR("FATAL: Card is not an Intersil Prism2/2.5/3\n");
710 /* get all the station fw id fields in host byte order */
711 hw->ident_sta_fw.id = hfa384x2host_16(hw->ident_sta_fw.id);
712 hw->ident_sta_fw.variant = hfa384x2host_16(hw->ident_sta_fw.variant);
713 hw->ident_sta_fw.major = hfa384x2host_16(hw->ident_sta_fw.major);
714 hw->ident_sta_fw.minor = hfa384x2host_16(hw->ident_sta_fw.minor);
716 /* strip out the 'special' variant bits */
717 hw->mm_mods = hw->ident_sta_fw.variant & (BIT(14) | BIT(15));
718 hw->ident_sta_fw.variant &= ~((u16)(BIT(14) | BIT(15)));
720 if ( hw->ident_sta_fw.id == 0x1f ) {
722 "ident: sta f/w: id=0x%02x %d.%d.%d\n",
723 hw->ident_sta_fw.id, hw->ident_sta_fw.major,
724 hw->ident_sta_fw.minor, hw->ident_sta_fw.variant);
727 "ident: ap f/w: id=0x%02x %d.%d.%d\n",
728 hw->ident_sta_fw.id, hw->ident_sta_fw.major,
729 hw->ident_sta_fw.minor, hw->ident_sta_fw.variant);
730 WLAN_LOG_ERROR("Unsupported Tertiary AP firmeare loaded!\n");
734 /* Compatibility range, Modem supplier */
735 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_MFISUPRANGE,
736 &hw->cap_sup_mfi, sizeof(hfa384x_caplevel_t));
738 WLAN_LOG_ERROR("Failed to retrieve MFISUPRANGE\n");
742 /* get all the Compatibility range, modem interface supplier
743 fields in byte order */
744 hw->cap_sup_mfi.role = hfa384x2host_16(hw->cap_sup_mfi.role);
745 hw->cap_sup_mfi.id = hfa384x2host_16(hw->cap_sup_mfi.id);
746 hw->cap_sup_mfi.variant = hfa384x2host_16(hw->cap_sup_mfi.variant);
747 hw->cap_sup_mfi.bottom = hfa384x2host_16(hw->cap_sup_mfi.bottom);
748 hw->cap_sup_mfi.top = hfa384x2host_16(hw->cap_sup_mfi.top);
751 "MFI:SUP:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
752 hw->cap_sup_mfi.role, hw->cap_sup_mfi.id,
753 hw->cap_sup_mfi.variant, hw->cap_sup_mfi.bottom,
754 hw->cap_sup_mfi.top);
756 /* Compatibility range, Controller supplier */
757 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_CFISUPRANGE,
758 &hw->cap_sup_cfi, sizeof(hfa384x_caplevel_t));
760 WLAN_LOG_ERROR("Failed to retrieve CFISUPRANGE\n");
764 /* get all the Compatibility range, controller interface supplier
765 fields in byte order */
766 hw->cap_sup_cfi.role = hfa384x2host_16(hw->cap_sup_cfi.role);
767 hw->cap_sup_cfi.id = hfa384x2host_16(hw->cap_sup_cfi.id);
768 hw->cap_sup_cfi.variant = hfa384x2host_16(hw->cap_sup_cfi.variant);
769 hw->cap_sup_cfi.bottom = hfa384x2host_16(hw->cap_sup_cfi.bottom);
770 hw->cap_sup_cfi.top = hfa384x2host_16(hw->cap_sup_cfi.top);
773 "CFI:SUP:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
774 hw->cap_sup_cfi.role, hw->cap_sup_cfi.id,
775 hw->cap_sup_cfi.variant, hw->cap_sup_cfi.bottom,
776 hw->cap_sup_cfi.top);
778 /* Compatibility range, Primary f/w supplier */
779 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_PRISUPRANGE,
780 &hw->cap_sup_pri, sizeof(hfa384x_caplevel_t));
782 WLAN_LOG_ERROR("Failed to retrieve PRISUPRANGE\n");
786 /* get all the Compatibility range, primary firmware supplier
787 fields in byte order */
788 hw->cap_sup_pri.role = hfa384x2host_16(hw->cap_sup_pri.role);
789 hw->cap_sup_pri.id = hfa384x2host_16(hw->cap_sup_pri.id);
790 hw->cap_sup_pri.variant = hfa384x2host_16(hw->cap_sup_pri.variant);
791 hw->cap_sup_pri.bottom = hfa384x2host_16(hw->cap_sup_pri.bottom);
792 hw->cap_sup_pri.top = hfa384x2host_16(hw->cap_sup_pri.top);
795 "PRI:SUP:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
796 hw->cap_sup_pri.role, hw->cap_sup_pri.id,
797 hw->cap_sup_pri.variant, hw->cap_sup_pri.bottom,
798 hw->cap_sup_pri.top);
800 /* Compatibility range, Station f/w supplier */
801 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_STASUPRANGE,
802 &hw->cap_sup_sta, sizeof(hfa384x_caplevel_t));
804 WLAN_LOG_ERROR("Failed to retrieve STASUPRANGE\n");
808 /* get all the Compatibility range, station firmware supplier
809 fields in byte order */
810 hw->cap_sup_sta.role = hfa384x2host_16(hw->cap_sup_sta.role);
811 hw->cap_sup_sta.id = hfa384x2host_16(hw->cap_sup_sta.id);
812 hw->cap_sup_sta.variant = hfa384x2host_16(hw->cap_sup_sta.variant);
813 hw->cap_sup_sta.bottom = hfa384x2host_16(hw->cap_sup_sta.bottom);
814 hw->cap_sup_sta.top = hfa384x2host_16(hw->cap_sup_sta.top);
816 if ( hw->cap_sup_sta.id == 0x04 ) {
818 "STA:SUP:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
819 hw->cap_sup_sta.role, hw->cap_sup_sta.id,
820 hw->cap_sup_sta.variant, hw->cap_sup_sta.bottom,
821 hw->cap_sup_sta.top);
824 "AP:SUP:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
825 hw->cap_sup_sta.role, hw->cap_sup_sta.id,
826 hw->cap_sup_sta.variant, hw->cap_sup_sta.bottom,
827 hw->cap_sup_sta.top);
830 /* Compatibility range, primary f/w actor, CFI supplier */
831 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_PRI_CFIACTRANGES,
832 &hw->cap_act_pri_cfi, sizeof(hfa384x_caplevel_t));
834 WLAN_LOG_ERROR("Failed to retrieve PRI_CFIACTRANGES\n");
838 /* get all the Compatibility range, primary f/w actor, CFI supplier
839 fields in byte order */
840 hw->cap_act_pri_cfi.role = hfa384x2host_16(hw->cap_act_pri_cfi.role);
841 hw->cap_act_pri_cfi.id = hfa384x2host_16(hw->cap_act_pri_cfi.id);
842 hw->cap_act_pri_cfi.variant = hfa384x2host_16(hw->cap_act_pri_cfi.variant);
843 hw->cap_act_pri_cfi.bottom = hfa384x2host_16(hw->cap_act_pri_cfi.bottom);
844 hw->cap_act_pri_cfi.top = hfa384x2host_16(hw->cap_act_pri_cfi.top);
847 "PRI-CFI:ACT:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
848 hw->cap_act_pri_cfi.role, hw->cap_act_pri_cfi.id,
849 hw->cap_act_pri_cfi.variant, hw->cap_act_pri_cfi.bottom,
850 hw->cap_act_pri_cfi.top);
852 /* Compatibility range, sta f/w actor, CFI supplier */
853 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_STA_CFIACTRANGES,
854 &hw->cap_act_sta_cfi, sizeof(hfa384x_caplevel_t));
856 WLAN_LOG_ERROR("Failed to retrieve STA_CFIACTRANGES\n");
860 /* get all the Compatibility range, station f/w actor, CFI supplier
861 fields in byte order */
862 hw->cap_act_sta_cfi.role = hfa384x2host_16(hw->cap_act_sta_cfi.role);
863 hw->cap_act_sta_cfi.id = hfa384x2host_16(hw->cap_act_sta_cfi.id);
864 hw->cap_act_sta_cfi.variant = hfa384x2host_16(hw->cap_act_sta_cfi.variant);
865 hw->cap_act_sta_cfi.bottom = hfa384x2host_16(hw->cap_act_sta_cfi.bottom);
866 hw->cap_act_sta_cfi.top = hfa384x2host_16(hw->cap_act_sta_cfi.top);
869 "STA-CFI:ACT:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
870 hw->cap_act_sta_cfi.role, hw->cap_act_sta_cfi.id,
871 hw->cap_act_sta_cfi.variant, hw->cap_act_sta_cfi.bottom,
872 hw->cap_act_sta_cfi.top);
874 /* Compatibility range, sta f/w actor, MFI supplier */
875 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_STA_MFIACTRANGES,
876 &hw->cap_act_sta_mfi, sizeof(hfa384x_caplevel_t));
878 WLAN_LOG_ERROR("Failed to retrieve STA_MFIACTRANGES\n");
882 /* get all the Compatibility range, station f/w actor, MFI supplier
883 fields in byte order */
884 hw->cap_act_sta_mfi.role = hfa384x2host_16(hw->cap_act_sta_mfi.role);
885 hw->cap_act_sta_mfi.id = hfa384x2host_16(hw->cap_act_sta_mfi.id);
886 hw->cap_act_sta_mfi.variant = hfa384x2host_16(hw->cap_act_sta_mfi.variant);
887 hw->cap_act_sta_mfi.bottom = hfa384x2host_16(hw->cap_act_sta_mfi.bottom);
888 hw->cap_act_sta_mfi.top = hfa384x2host_16(hw->cap_act_sta_mfi.top);
891 "STA-MFI:ACT:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
892 hw->cap_act_sta_mfi.role, hw->cap_act_sta_mfi.id,
893 hw->cap_act_sta_mfi.variant, hw->cap_act_sta_mfi.bottom,
894 hw->cap_act_sta_mfi.top);
897 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_NICSERIALNUMBER,
898 snum, HFA384x_RID_NICSERIALNUMBER_LEN);
900 wlan_mkprintstr(snum, HFA384x_RID_NICSERIALNUMBER_LEN,
902 printk(KERN_INFO "Prism2 card SN: %s\n", pstr);
904 WLAN_LOG_ERROR("Failed to retrieve Prism2 Card SN\n");
908 /* Collect the MAC address */
909 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_CNFOWNMACADDR,
910 wlandev->netdev->dev_addr, ETH_ALEN);
912 WLAN_LOG_ERROR("Failed to retrieve mac address\n");
916 /* short preamble is always implemented */
917 wlandev->nsdcaps |= P80211_NSDCAP_SHORT_PREAMBLE;
919 /* find out if hardware wep is implemented */
920 hfa384x_drvr_getconfig16(hw, HFA384x_RID_PRIVACYOPTIMP, &temp);
922 wlandev->nsdcaps |= P80211_NSDCAP_HARDWAREWEP;
924 /* get the dBm Scaling constant */
925 hfa384x_drvr_getconfig16(hw, HFA384x_RID_CNFDBMADJUST, &temp);
926 hw->dbmadjust = temp;
928 /* Only enable scan by default on newer firmware */
929 if (HFA384x_FIRMWARE_VERSION(hw->ident_sta_fw.major,
930 hw->ident_sta_fw.minor,
931 hw->ident_sta_fw.variant) <
932 HFA384x_FIRMWARE_VERSION(1,5,5)) {
933 wlandev->nsdcaps |= P80211_NSDCAP_NOSCAN;
936 /* TODO: Set any internally managed config items */
940 WLAN_LOG_ERROR("Failed, result=%d\n", result);
946 /*----------------------------------------------------------------
947 * prism2sta_globalsetup
949 * Set any global RIDs that we want to set at device activation.
952 * wlandev wlan device structure
956 * >0 f/w reported error
957 * <0 driver reported error
963 ----------------------------------------------------------------*/
964 static int prism2sta_globalsetup(wlandevice_t *wlandev)
966 hfa384x_t *hw = (hfa384x_t *)wlandev->priv;
968 /* Set the maximum frame size */
969 return hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFMAXDATALEN,
973 static int prism2sta_setmulticast(wlandevice_t *wlandev, netdevice_t *dev)
976 hfa384x_t *hw = (hfa384x_t *)wlandev->priv;
980 /* If we're not ready, what's the point? */
981 if ( hw->state != HFA384x_STATE_RUNNING )
984 if ( (dev->flags & (IFF_PROMISC | IFF_ALLMULTI)) != 0 )
985 promisc = P80211ENUM_truth_true;
987 promisc = P80211ENUM_truth_false;
989 result = hfa384x_drvr_setconfig16_async(hw, HFA384x_RID_PROMISCMODE, promisc);
991 /* XXX TODO: configure the multicast list */
992 // CLEAR_HW_MULTICAST_LIST
993 // struct dev_mc_list element = dev->mc_list;
994 // while (element != null) {
995 // HW_ADD_MULTICAST_ADDR(element->dmi_addr, dmi_addrlen)
996 // element = element->next;
1003 /*----------------------------------------------------------------
1004 * prism2sta_inf_handover
1006 * Handles the receipt of a Handover info frame. Should only be present
1010 * wlandev wlan device structure
1011 * inf ptr to info frame (contents in hfa384x order)
1020 ----------------------------------------------------------------*/
1021 static void prism2sta_inf_handover(wlandevice_t *wlandev, hfa384x_InfFrame_t *inf)
1023 WLAN_LOG_DEBUG(2,"received infoframe:HANDOVER (unhandled)\n");
1028 /*----------------------------------------------------------------
1029 * prism2sta_inf_tallies
1031 * Handles the receipt of a CommTallies info frame.
1034 * wlandev wlan device structure
1035 * inf ptr to info frame (contents in hfa384x order)
1044 ----------------------------------------------------------------*/
1045 static void prism2sta_inf_tallies(wlandevice_t *wlandev, hfa384x_InfFrame_t *inf)
1047 hfa384x_t *hw = (hfa384x_t *)wlandev->priv;
1055 ** Determine if these are 16-bit or 32-bit tallies, based on the
1056 ** record length of the info record.
1059 cnt = sizeof(hfa384x_CommTallies32_t) / sizeof(u32);
1060 if (inf->framelen > 22) {
1061 dst = (u32 *) &hw->tallies;
1062 src32 = (u32 *) &inf->info.commtallies32;
1063 for (i = 0; i < cnt; i++, dst++, src32++)
1064 *dst += hfa384x2host_32(*src32);
1066 dst = (u32 *) &hw->tallies;
1067 src16 = (u16 *) &inf->info.commtallies16;
1068 for (i = 0; i < cnt; i++, dst++, src16++)
1069 *dst += hfa384x2host_16(*src16);
1075 /*----------------------------------------------------------------
1076 * prism2sta_inf_scanresults
1078 * Handles the receipt of a Scan Results info frame.
1081 * wlandev wlan device structure
1082 * inf ptr to info frame (contents in hfa384x order)
1091 ----------------------------------------------------------------*/
1092 static void prism2sta_inf_scanresults(wlandevice_t *wlandev,
1093 hfa384x_InfFrame_t *inf)
1096 hfa384x_t *hw = (hfa384x_t *)wlandev->priv;
1098 hfa384x_ScanResult_t *sr = &(inf->info.scanresult);
1100 hfa384x_JoinRequest_data_t joinreq;
1103 /* Get the number of results, first in bytes, then in results */
1104 nbss = (inf->framelen * sizeof(u16)) -
1105 sizeof(inf->infotype) -
1106 sizeof(inf->info.scanresult.scanreason);
1107 nbss /= sizeof(hfa384x_ScanResultSub_t);
1110 WLAN_LOG_DEBUG(1,"rx scanresults, reason=%d, nbss=%d:\n",
1111 inf->info.scanresult.scanreason, nbss);
1112 for ( i = 0; i < nbss; i++) {
1113 WLAN_LOG_DEBUG(1, "chid=%d anl=%d sl=%d bcnint=%d\n",
1117 sr->result[i].bcnint);
1118 WLAN_LOG_DEBUG(1, " capinfo=0x%04x proberesp_rate=%d\n",
1119 sr->result[i].capinfo,
1120 sr->result[i].proberesp_rate);
1122 /* issue a join request */
1123 joinreq.channel = sr->result[0].chid;
1124 memcpy( joinreq.bssid, sr->result[0].bssid, WLAN_BSSID_LEN);
1125 result = hfa384x_drvr_setconfig( hw,
1126 HFA384x_RID_JOINREQUEST,
1127 &joinreq, HFA384x_RID_JOINREQUEST_LEN);
1129 WLAN_LOG_ERROR("setconfig(joinreq) failed, result=%d\n", result);
1135 /*----------------------------------------------------------------
1136 * prism2sta_inf_hostscanresults
1138 * Handles the receipt of a Scan Results info frame.
1141 * wlandev wlan device structure
1142 * inf ptr to info frame (contents in hfa384x order)
1151 ----------------------------------------------------------------*/
1152 static void prism2sta_inf_hostscanresults(wlandevice_t *wlandev,
1153 hfa384x_InfFrame_t *inf)
1155 hfa384x_t *hw = (hfa384x_t *)wlandev->priv;
1158 nbss = (inf->framelen - 3) / 32;
1159 WLAN_LOG_DEBUG(1, "Received %d hostscan results\n", nbss);
1164 if (hw->scanresults)
1165 kfree(hw->scanresults);
1167 hw->scanresults = kmalloc(sizeof(hfa384x_InfFrame_t), GFP_ATOMIC);
1168 memcpy(hw->scanresults, inf, sizeof(hfa384x_InfFrame_t));
1173 /* Notify/wake the sleeping caller. */
1174 hw->scanflag = nbss;
1175 wake_up_interruptible(&hw->cmdq);
1178 /*----------------------------------------------------------------
1179 * prism2sta_inf_chinforesults
1181 * Handles the receipt of a Channel Info Results info frame.
1184 * wlandev wlan device structure
1185 * inf ptr to info frame (contents in hfa384x order)
1194 ----------------------------------------------------------------*/
1195 static void prism2sta_inf_chinforesults(wlandevice_t *wlandev,
1196 hfa384x_InfFrame_t *inf)
1198 hfa384x_t *hw = (hfa384x_t *)wlandev->priv;
1201 hw->channel_info.results.scanchannels =
1202 hfa384x2host_16(inf->info.chinforesult.scanchannels);
1204 memcpy(&inf->info.chinforesult, &hw->channel_info.results, sizeof(hfa384x_ChInfoResult_t));
1207 for (i=0, n=0; i<HFA384x_CHINFORESULT_MAX; i++) {
1208 if (hw->channel_info.results.scanchannels & (1<<i)) {
1209 int channel=hfa384x2host_16(inf->info.chinforesult.result[n].chid)-1;
1210 hfa384x_ChInfoResultSub_t *chinforesult=&hw->channel_info.results.result[channel];
1211 chinforesult->chid = channel;
1212 chinforesult->anl = hfa384x2host_16(inf->info.chinforesult.result[n].anl);
1213 chinforesult->pnl = hfa384x2host_16(inf->info.chinforesult.result[n].pnl);
1214 chinforesult->active = hfa384x2host_16(inf->info.chinforesult.result[n].active);
1215 WLAN_LOG_DEBUG(2, "chinfo: channel %d, %s level (avg/peak)=%d/%d dB, pcf %d\n",
1217 chinforesult->active &
1218 HFA384x_CHINFORESULT_BSSACTIVE ? "signal" : "noise",
1219 chinforesult->anl, chinforesult->pnl,
1220 chinforesult->active & HFA384x_CHINFORESULT_PCFACTIVE ? 1 : 0
1225 atomic_set(&hw->channel_info.done, 2);
1227 hw->channel_info.count = n;
1231 void prism2sta_processing_defer(struct work_struct *data)
1233 hfa384x_t *hw = container_of(data, struct hfa384x, link_bh);
1234 wlandevice_t *wlandev = hw->wlandev;
1235 hfa384x_bytestr32_t ssid;
1238 /* First let's process the auth frames */
1240 struct sk_buff *skb;
1241 hfa384x_InfFrame_t *inf;
1243 while ( (skb = skb_dequeue(&hw->authq)) ) {
1244 inf = (hfa384x_InfFrame_t *) skb->data;
1245 prism2sta_inf_authreq_defer(wlandev, inf);
1250 /* Now let's handle the linkstatus stuff */
1251 if (hw->link_status == hw->link_status_new)
1254 hw->link_status = hw->link_status_new;
1256 switch(hw->link_status) {
1257 case HFA384x_LINK_NOTCONNECTED:
1258 /* I'm currently assuming that this is the initial link
1259 * state. It should only be possible immediately
1260 * following an Enable command.
1262 * Block Transmits, Ignore receives of data frames
1264 netif_carrier_off(wlandev->netdev);
1266 printk(KERN_INFO "linkstatus=NOTCONNECTED (unhandled)\n");
1269 case HFA384x_LINK_CONNECTED:
1270 /* This one indicates a successful scan/join/auth/assoc.
1271 * When we have the full MLME complement, this event will
1272 * signify successful completion of both mlme_authenticate
1273 * and mlme_associate. State management will get a little
1276 * Indicate authentication and/or association
1277 * Enable Transmits, Receives and pass up data frames
1280 netif_carrier_on(wlandev->netdev);
1282 /* If we are joining a specific AP, set our state and reset retries */
1283 if(hw->join_ap == 1)
1285 hw->join_retries = 60;
1287 /* Don't call this in monitor mode */
1288 if ( wlandev->netdev->type == ARPHRD_ETHER ) {
1291 printk(KERN_INFO "linkstatus=CONNECTED\n");
1293 /* For non-usb devices, we can use the sync versions */
1294 /* Collect the BSSID, and set state to allow tx */
1296 result = hfa384x_drvr_getconfig(hw,
1297 HFA384x_RID_CURRENTBSSID,
1298 wlandev->bssid, WLAN_BSSID_LEN);
1301 "getconfig(0x%02x) failed, result = %d\n",
1302 HFA384x_RID_CURRENTBSSID, result);
1306 result = hfa384x_drvr_getconfig(hw,
1307 HFA384x_RID_CURRENTSSID,
1308 &ssid, sizeof(ssid));
1311 "getconfig(0x%02x) failed, result = %d\n",
1312 HFA384x_RID_CURRENTSSID, result);
1315 prism2mgmt_bytestr2pstr((hfa384x_bytestr_t *)&ssid,
1316 (p80211pstrd_t *) &wlandev->ssid);
1318 /* Collect the port status */
1319 result = hfa384x_drvr_getconfig16(hw,
1320 HFA384x_RID_PORTSTATUS, &portstatus);
1323 "getconfig(0x%02x) failed, result = %d\n",
1324 HFA384x_RID_PORTSTATUS, result);
1328 (portstatus == HFA384x_PSTATUS_CONN_IBSS) ?
1329 WLAN_MACMODE_IBSS_STA : WLAN_MACMODE_ESS_STA;
1331 /* Get the ball rolling on the comms quality stuff */
1332 prism2sta_commsqual_defer(&hw->commsqual_bh);
1336 case HFA384x_LINK_DISCONNECTED:
1337 /* This one indicates that our association is gone. We've
1338 * lost connection with the AP and/or been disassociated.
1339 * This indicates that the MAC has completely cleared it's
1340 * associated state. We * should send a deauth indication
1341 * (implying disassoc) up * to the MLME.
1343 * Indicate Deauthentication
1344 * Block Transmits, Ignore receives of data frames
1346 if(hw->join_ap == 2)
1348 hfa384x_JoinRequest_data_t joinreq;
1349 joinreq = hw->joinreq;
1350 /* Send the join request */
1351 hfa384x_drvr_setconfig( hw,
1352 HFA384x_RID_JOINREQUEST,
1353 &joinreq, HFA384x_RID_JOINREQUEST_LEN);
1354 printk(KERN_INFO "linkstatus=DISCONNECTED (re-submitting join)\n");
1356 if (wlandev->netdev->type == ARPHRD_ETHER)
1357 printk(KERN_INFO "linkstatus=DISCONNECTED (unhandled)\n");
1359 wlandev->macmode = WLAN_MACMODE_NONE;
1361 netif_carrier_off(wlandev->netdev);
1365 case HFA384x_LINK_AP_CHANGE:
1366 /* This one indicates that the MAC has decided to and
1367 * successfully completed a change to another AP. We
1368 * should probably implement a reassociation indication
1369 * in response to this one. I'm thinking that the the
1370 * p80211 layer needs to be notified in case of
1371 * buffering/queueing issues. User mode also needs to be
1372 * notified so that any BSS dependent elements can be
1374 * associated state. We * should send a deauth indication
1375 * (implying disassoc) up * to the MLME.
1377 * Indicate Reassociation
1378 * Enable Transmits, Receives and pass up data frames
1380 printk(KERN_INFO "linkstatus=AP_CHANGE\n");
1382 result = hfa384x_drvr_getconfig(hw,
1383 HFA384x_RID_CURRENTBSSID,
1384 wlandev->bssid, WLAN_BSSID_LEN);
1387 "getconfig(0x%02x) failed, result = %d\n",
1388 HFA384x_RID_CURRENTBSSID, result);
1392 result = hfa384x_drvr_getconfig(hw,
1393 HFA384x_RID_CURRENTSSID,
1394 &ssid, sizeof(ssid));
1397 "getconfig(0x%02x) failed, result = %d\n",
1398 HFA384x_RID_CURRENTSSID, result);
1401 prism2mgmt_bytestr2pstr((hfa384x_bytestr_t *)&ssid,
1402 (p80211pstrd_t *) &wlandev->ssid);
1405 hw->link_status = HFA384x_LINK_CONNECTED;
1406 netif_carrier_on(wlandev->netdev);
1410 case HFA384x_LINK_AP_OUTOFRANGE:
1411 /* This one indicates that the MAC has decided that the
1412 * AP is out of range, but hasn't found a better candidate
1413 * so the MAC maintains its "associated" state in case
1414 * we get back in range. We should block transmits and
1415 * receives in this state. Do we need an indication here?
1416 * Probably not since a polling user-mode element would
1417 * get this status from from p2PortStatus(FD40). What about
1420 * Block Transmits, Ignore receives of data frames
1422 printk(KERN_INFO "linkstatus=AP_OUTOFRANGE (unhandled)\n");
1424 netif_carrier_off(wlandev->netdev);
1428 case HFA384x_LINK_AP_INRANGE:
1429 /* This one indicates that the MAC has decided that the
1430 * AP is back in range. We continue working with our
1431 * existing association.
1433 * Enable Transmits, Receives and pass up data frames
1435 printk(KERN_INFO "linkstatus=AP_INRANGE\n");
1437 hw->link_status = HFA384x_LINK_CONNECTED;
1438 netif_carrier_on(wlandev->netdev);
1442 case HFA384x_LINK_ASSOCFAIL:
1443 /* This one is actually a peer to CONNECTED. We've
1444 * requested a join for a given SSID and optionally BSSID.
1445 * We can use this one to indicate authentication and
1446 * association failures. The trick is going to be
1447 * 1) identifying the failure, and 2) state management.
1449 * Disable Transmits, Ignore receives of data frames
1451 if(hw->join_ap && --hw->join_retries > 0)
1453 hfa384x_JoinRequest_data_t joinreq;
1454 joinreq = hw->joinreq;
1455 /* Send the join request */
1456 hfa384x_drvr_setconfig( hw,
1457 HFA384x_RID_JOINREQUEST,
1458 &joinreq, HFA384x_RID_JOINREQUEST_LEN);
1459 printk(KERN_INFO "linkstatus=ASSOCFAIL (re-submitting join)\n");
1461 printk(KERN_INFO "linkstatus=ASSOCFAIL (unhandled)\n");
1464 netif_carrier_off(wlandev->netdev);
1469 /* This is bad, IO port problems? */
1471 "unknown linkstatus=0x%02x\n", hw->link_status);
1476 wlandev->linkstatus = (hw->link_status == HFA384x_LINK_CONNECTED);
1478 p80211wext_event_associated(wlandev, wlandev->linkstatus);
1485 /*----------------------------------------------------------------
1486 * prism2sta_inf_linkstatus
1488 * Handles the receipt of a Link Status info frame.
1491 * wlandev wlan device structure
1492 * inf ptr to info frame (contents in hfa384x order)
1501 ----------------------------------------------------------------*/
1502 static void prism2sta_inf_linkstatus(wlandevice_t *wlandev,
1503 hfa384x_InfFrame_t *inf)
1505 hfa384x_t *hw = (hfa384x_t *)wlandev->priv;
1507 hw->link_status_new = hfa384x2host_16(inf->info.linkstatus.linkstatus);
1509 schedule_work(&hw->link_bh);
1514 /*----------------------------------------------------------------
1515 * prism2sta_inf_assocstatus
1517 * Handles the receipt of an Association Status info frame. Should
1518 * be present in APs only.
1521 * wlandev wlan device structure
1522 * inf ptr to info frame (contents in hfa384x order)
1531 ----------------------------------------------------------------*/
1532 static void prism2sta_inf_assocstatus(wlandevice_t *wlandev,
1533 hfa384x_InfFrame_t *inf)
1535 hfa384x_t *hw = (hfa384x_t *)wlandev->priv;
1536 hfa384x_AssocStatus_t rec;
1539 memcpy(&rec, &inf->info.assocstatus, sizeof(rec));
1540 rec.assocstatus = hfa384x2host_16(rec.assocstatus);
1541 rec.reason = hfa384x2host_16(rec.reason);
1544 ** Find the address in the list of authenticated stations. If it wasn't
1545 ** found, then this address has not been previously authenticated and
1546 ** something weird has happened if this is anything other than an
1547 ** "authentication failed" message. If the address was found, then
1548 ** set the "associated" flag for that station, based on whether the
1549 ** station is associating or losing its association. Something weird
1550 ** has also happened if we find the address in the list of authenticated
1551 ** stations but we are getting an "authentication failed" message.
1554 for (i = 0; i < hw->authlist.cnt; i++)
1555 if (memcmp(rec.sta_addr, hw->authlist.addr[i], ETH_ALEN) == 0)
1558 if (i >= hw->authlist.cnt) {
1559 if (rec.assocstatus != HFA384x_ASSOCSTATUS_AUTHFAIL)
1560 WLAN_LOG_WARNING("assocstatus info frame received for non-authenticated station.\n");
1562 hw->authlist.assoc[i] =
1563 (rec.assocstatus == HFA384x_ASSOCSTATUS_STAASSOC ||
1564 rec.assocstatus == HFA384x_ASSOCSTATUS_REASSOC);
1566 if (rec.assocstatus == HFA384x_ASSOCSTATUS_AUTHFAIL)
1567 WLAN_LOG_WARNING("authfail assocstatus info frame received for authenticated station.\n");
1573 /*----------------------------------------------------------------
1574 * prism2sta_inf_authreq
1576 * Handles the receipt of an Authentication Request info frame. Should
1577 * be present in APs only.
1580 * wlandev wlan device structure
1581 * inf ptr to info frame (contents in hfa384x order)
1591 ----------------------------------------------------------------*/
1592 static void prism2sta_inf_authreq(wlandevice_t *wlandev,
1593 hfa384x_InfFrame_t *inf)
1595 hfa384x_t *hw = (hfa384x_t *)wlandev->priv;
1596 struct sk_buff *skb;
1598 skb = dev_alloc_skb(sizeof(*inf));
1600 skb_put(skb, sizeof(*inf));
1601 memcpy(skb->data, inf, sizeof(*inf));
1602 skb_queue_tail(&hw->authq, skb);
1603 schedule_work(&hw->link_bh);
1607 static void prism2sta_inf_authreq_defer(wlandevice_t *wlandev,
1608 hfa384x_InfFrame_t *inf)
1610 hfa384x_t *hw = (hfa384x_t *)wlandev->priv;
1611 hfa384x_authenticateStation_data_t rec;
1613 int i, added, result, cnt;
1617 ** Build the AuthenticateStation record. Initialize it for denying
1621 memcpy(rec.address, inf->info.authreq.sta_addr, ETH_ALEN);
1622 rec.status = P80211ENUM_status_unspec_failure;
1625 ** Authenticate based on the access mode.
1628 switch (hw->accessmode) {
1629 case WLAN_ACCESS_NONE:
1632 ** Deny all new authentications. However, if a station
1633 ** is ALREADY authenticated, then accept it.
1636 for (i = 0; i < hw->authlist.cnt; i++)
1637 if (memcmp(rec.address, hw->authlist.addr[i],
1639 rec.status = P80211ENUM_status_successful;
1645 case WLAN_ACCESS_ALL:
1648 ** Allow all authentications.
1651 rec.status = P80211ENUM_status_successful;
1654 case WLAN_ACCESS_ALLOW:
1657 ** Only allow the authentication if the MAC address
1658 ** is in the list of allowed addresses.
1660 ** Since this is the interrupt handler, we may be here
1661 ** while the access list is in the middle of being
1662 ** updated. Choose the list which is currently okay.
1663 ** See "prism2mib_priv_accessallow()" for details.
1666 if (hw->allow.modify == 0) {
1667 cnt = hw->allow.cnt;
1668 addr = hw->allow.addr[0];
1670 cnt = hw->allow.cnt1;
1671 addr = hw->allow.addr1[0];
1674 for (i = 0; i < cnt; i++, addr += ETH_ALEN)
1675 if (memcmp(rec.address, addr, ETH_ALEN) == 0) {
1676 rec.status = P80211ENUM_status_successful;
1682 case WLAN_ACCESS_DENY:
1685 ** Allow the authentication UNLESS the MAC address is
1686 ** in the list of denied addresses.
1688 ** Since this is the interrupt handler, we may be here
1689 ** while the access list is in the middle of being
1690 ** updated. Choose the list which is currently okay.
1691 ** See "prism2mib_priv_accessdeny()" for details.
1694 if (hw->deny.modify == 0) {
1696 addr = hw->deny.addr[0];
1698 cnt = hw->deny.cnt1;
1699 addr = hw->deny.addr1[0];
1702 rec.status = P80211ENUM_status_successful;
1704 for (i = 0; i < cnt; i++, addr += ETH_ALEN)
1705 if (memcmp(rec.address, addr, ETH_ALEN) == 0) {
1706 rec.status = P80211ENUM_status_unspec_failure;
1714 ** If the authentication is okay, then add the MAC address to the list
1715 ** of authenticated stations. Don't add the address if it is already in
1716 ** the list. (802.11b does not seem to disallow a station from issuing
1717 ** an authentication request when the station is already authenticated.
1718 ** Does this sort of thing ever happen? We might as well do the check
1724 if (rec.status == P80211ENUM_status_successful) {
1725 for (i = 0; i < hw->authlist.cnt; i++)
1726 if (memcmp(rec.address, hw->authlist.addr[i], ETH_ALEN) == 0)
1729 if (i >= hw->authlist.cnt) {
1730 if (hw->authlist.cnt >= WLAN_AUTH_MAX) {
1731 rec.status = P80211ENUM_status_ap_full;
1733 memcpy(hw->authlist.addr[hw->authlist.cnt],
1734 rec.address, ETH_ALEN);
1742 ** Send back the results of the authentication. If this doesn't work,
1743 ** then make sure to remove the address from the authenticated list if
1747 rec.status = host2hfa384x_16(rec.status);
1748 rec.algorithm = inf->info.authreq.algorithm;
1750 result = hfa384x_drvr_setconfig(hw, HFA384x_RID_AUTHENTICATESTA,
1753 if (added) hw->authlist.cnt--;
1754 WLAN_LOG_ERROR("setconfig(authenticatestation) failed, result=%d\n", result);
1760 /*----------------------------------------------------------------
1761 * prism2sta_inf_psusercnt
1763 * Handles the receipt of a PowerSaveUserCount info frame. Should
1764 * be present in APs only.
1767 * wlandev wlan device structure
1768 * inf ptr to info frame (contents in hfa384x order)
1777 ----------------------------------------------------------------*/
1778 static void prism2sta_inf_psusercnt(wlandevice_t *wlandev,
1779 hfa384x_InfFrame_t *inf)
1781 hfa384x_t *hw = (hfa384x_t *)wlandev->priv;
1783 hw->psusercount = hfa384x2host_16(inf->info.psusercnt.usercnt);
1788 /*----------------------------------------------------------------
1791 * Handles the DTIM early warning event.
1794 * wlandev wlan device structure
1803 ----------------------------------------------------------------*/
1804 void prism2sta_ev_dtim(wlandevice_t *wlandev)
1807 hfa384x_t *hw = (hfa384x_t *)wlandev->priv;
1809 WLAN_LOG_DEBUG(3, "DTIM event, currently unhandled.\n");
1814 /*----------------------------------------------------------------
1815 * prism2sta_ev_infdrop
1817 * Handles the InfDrop event.
1820 * wlandev wlan device structure
1829 ----------------------------------------------------------------*/
1830 void prism2sta_ev_infdrop(wlandevice_t *wlandev)
1833 hfa384x_t *hw = (hfa384x_t *)wlandev->priv;
1835 WLAN_LOG_DEBUG(3, "Info frame dropped due to card mem low.\n");
1840 /*----------------------------------------------------------------
1843 * Handles the Info event.
1846 * wlandev wlan device structure
1847 * inf ptr to a generic info frame
1856 ----------------------------------------------------------------*/
1857 void prism2sta_ev_info(wlandevice_t *wlandev, hfa384x_InfFrame_t *inf)
1859 inf->infotype = hfa384x2host_16(inf->infotype);
1861 switch ( inf->infotype ) {
1862 case HFA384x_IT_HANDOVERADDR:
1863 prism2sta_inf_handover(wlandev, inf);
1865 case HFA384x_IT_COMMTALLIES:
1866 prism2sta_inf_tallies(wlandev, inf);
1868 case HFA384x_IT_HOSTSCANRESULTS:
1869 prism2sta_inf_hostscanresults(wlandev, inf);
1871 case HFA384x_IT_SCANRESULTS:
1872 prism2sta_inf_scanresults(wlandev, inf);
1874 case HFA384x_IT_CHINFORESULTS:
1875 prism2sta_inf_chinforesults(wlandev, inf);
1877 case HFA384x_IT_LINKSTATUS:
1878 prism2sta_inf_linkstatus(wlandev, inf);
1880 case HFA384x_IT_ASSOCSTATUS:
1881 prism2sta_inf_assocstatus(wlandev, inf);
1883 case HFA384x_IT_AUTHREQ:
1884 prism2sta_inf_authreq(wlandev, inf);
1886 case HFA384x_IT_PSUSERCNT:
1887 prism2sta_inf_psusercnt(wlandev, inf);
1889 case HFA384x_IT_KEYIDCHANGED:
1890 WLAN_LOG_WARNING("Unhandled IT_KEYIDCHANGED\n");
1892 case HFA384x_IT_ASSOCREQ:
1893 WLAN_LOG_WARNING("Unhandled IT_ASSOCREQ\n");
1895 case HFA384x_IT_MICFAILURE:
1896 WLAN_LOG_WARNING("Unhandled IT_MICFAILURE\n");
1900 "Unknown info type=0x%02x\n", inf->infotype);
1907 /*----------------------------------------------------------------
1908 * prism2sta_ev_txexc
1910 * Handles the TxExc event. A Transmit Exception event indicates
1911 * that the MAC's TX process was unsuccessful - so the packet did
1912 * not get transmitted.
1915 * wlandev wlan device structure
1916 * status tx frame status word
1925 ----------------------------------------------------------------*/
1926 void prism2sta_ev_txexc(wlandevice_t *wlandev, u16 status)
1928 WLAN_LOG_DEBUG(3, "TxExc status=0x%x.\n", status);
1934 /*----------------------------------------------------------------
1937 * Handles the Tx event.
1940 * wlandev wlan device structure
1941 * status tx frame status word
1949 ----------------------------------------------------------------*/
1950 void prism2sta_ev_tx(wlandevice_t *wlandev, u16 status)
1952 WLAN_LOG_DEBUG(4, "Tx Complete, status=0x%04x\n", status);
1953 /* update linux network stats */
1954 wlandev->linux_stats.tx_packets++;
1959 /*----------------------------------------------------------------
1962 * Handles the Rx event.
1965 * wlandev wlan device structure
1974 ----------------------------------------------------------------*/
1975 void prism2sta_ev_rx(wlandevice_t *wlandev, struct sk_buff *skb)
1977 p80211netdev_rx(wlandev, skb);
1981 /*----------------------------------------------------------------
1982 * prism2sta_ev_alloc
1984 * Handles the Alloc event.
1987 * wlandev wlan device structure
1996 ----------------------------------------------------------------*/
1997 void prism2sta_ev_alloc(wlandevice_t *wlandev)
1999 netif_wake_queue(wlandev->netdev);
2003 /*----------------------------------------------------------------
2006 * Called at module init time. This creates the wlandevice_t structure
2007 * and initializes it with relevant bits.
2013 * the created wlandevice_t structure.
2016 * also allocates the priv/hw structures.
2021 ----------------------------------------------------------------*/
2022 static wlandevice_t *create_wlan(void)
2024 wlandevice_t *wlandev = NULL;
2025 hfa384x_t *hw = NULL;
2027 /* Alloc our structures */
2028 wlandev = kmalloc(sizeof(wlandevice_t), GFP_KERNEL);
2029 hw = kmalloc(sizeof(hfa384x_t), GFP_KERNEL);
2031 if (!wlandev || !hw) {
2032 WLAN_LOG_ERROR("%s: Memory allocation failure.\n", dev_info);
2033 if (wlandev) kfree(wlandev);
2038 /* Clear all the structs */
2039 memset(wlandev, 0, sizeof(wlandevice_t));
2040 memset(hw, 0, sizeof(hfa384x_t));
2042 /* Initialize the network device object. */
2043 wlandev->nsdname = dev_info;
2044 wlandev->msdstate = WLAN_MSD_HWPRESENT_PENDING;
2046 wlandev->open = prism2sta_open;
2047 wlandev->close = prism2sta_close;
2048 wlandev->reset = prism2sta_reset;
2049 wlandev->txframe = prism2sta_txframe;
2050 wlandev->mlmerequest = prism2sta_mlmerequest;
2051 wlandev->set_multicast_list = prism2sta_setmulticast;
2052 wlandev->tx_timeout = hfa384x_tx_timeout;
2054 wlandev->nsdcaps = P80211_NSDCAP_HWFRAGMENT |
2055 P80211_NSDCAP_AUTOJOIN;
2057 /* Initialize the device private data stucture. */
2058 hw->dot11_desired_bss_type = 1;
2063 void prism2sta_commsqual_defer(struct work_struct *data)
2065 hfa384x_t *hw = container_of(data, struct hfa384x, commsqual_bh);
2066 wlandevice_t *wlandev = hw->wlandev;
2067 hfa384x_bytestr32_t ssid;
2070 if (hw->wlandev->hwremoved)
2073 /* we don't care if we're in AP mode */
2074 if ((wlandev->macmode == WLAN_MACMODE_NONE) ||
2075 (wlandev->macmode == WLAN_MACMODE_ESS_AP)) {
2079 /* It only makes sense to poll these in non-IBSS */
2080 if (wlandev->macmode != WLAN_MACMODE_IBSS_STA) {
2081 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_DBMCOMMSQUALITY,
2083 HFA384x_RID_DBMCOMMSQUALITY_LEN);
2086 WLAN_LOG_ERROR("error fetching commsqual\n");
2090 // qual.CQ_currBSS; // link
2091 // ASL_currBSS; // level
2092 // qual.ANL_currFC; // noise
2094 WLAN_LOG_DEBUG(3, "commsqual %d %d %d\n",
2095 hfa384x2host_16(hw->qual.CQ_currBSS),
2096 hfa384x2host_16(hw->qual.ASL_currBSS),
2097 hfa384x2host_16(hw->qual.ANL_currFC));
2100 /* Lastly, we need to make sure the BSSID didn't change on us */
2101 result = hfa384x_drvr_getconfig(hw,
2102 HFA384x_RID_CURRENTBSSID,
2103 wlandev->bssid, WLAN_BSSID_LEN);
2106 "getconfig(0x%02x) failed, result = %d\n",
2107 HFA384x_RID_CURRENTBSSID, result);
2111 result = hfa384x_drvr_getconfig(hw,
2112 HFA384x_RID_CURRENTSSID,
2113 &ssid, sizeof(ssid));
2116 "getconfig(0x%02x) failed, result = %d\n",
2117 HFA384x_RID_CURRENTSSID, result);
2120 prism2mgmt_bytestr2pstr((hfa384x_bytestr_t *)&ssid,
2121 (p80211pstrd_t *) &wlandev->ssid);
2124 /* Reschedule timer */
2125 mod_timer(&hw->commsqual_timer, jiffies + HZ);
2131 void prism2sta_commsqual_timer(unsigned long data)
2133 hfa384x_t *hw = (hfa384x_t *) data;
2135 schedule_work(&hw->commsqual_bh);