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
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>
72 #include <linux/delay.h>
73 #include <asm/byteorder.h>
74 #include <linux/if_arp.h>
76 #include "wlan_compat.h"
78 /*================================================================*/
79 /* Project Includes */
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"
91 #include "prism2mgmt.h"
93 /*================================================================*/
96 /*================================================================*/
99 /*================================================================*/
102 /*================================================================*/
103 /* Local Static Definitions */
105 typedef char* dev_info_t;
107 static dev_info_t dev_info = "prism2_usb";
109 static wlandevice_t *create_wlan(void);
111 /*----------------------------------------------------------------*/
112 /* --Module Parameters */
114 int prism2_reset_holdtime=30; /* Reset hold time in ms */
115 int prism2_reset_settletime=100; /* Reset settle time in ms */
117 static int prism2_doreset=0; /* Do a reset at init? */
119 #ifdef WLAN_INCLUDE_DEBUG
121 module_param( prism2_debug, int, 0644);
122 MODULE_PARM_DESC(prism2_debug, "prism2 debugging");
125 module_param( prism2_doreset, int, 0644);
126 MODULE_PARM_DESC(prism2_doreset, "Issue a reset on initialization");
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");
133 MODULE_LICENSE("Dual MPL/GPL");
135 /*================================================================*/
136 /* Local Function Declarations */
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,
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);
169 #ifdef CONFIG_PROC_FS
180 /*================================================================*/
181 /* Function Definitions */
183 /*----------------------------------------------------------------
186 * Debug utility function to dump memory to the kernel debug log.
189 * buf ptr data we want dumped
199 ----------------------------------------------------------------*/
200 inline void dmpmem(void *buf, int n)
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");
208 if ( (c % 16) != 0 ) printk("\n");
212 /*----------------------------------------------------------------
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
221 * wlandev wlan device structure
225 * >0 f/w reported error
226 * <0 driver reported error
232 ----------------------------------------------------------------*/
233 static int prism2sta_open(wlandevice_t *wlandev)
237 /* We don't currently have to do anything else.
238 * The setup of the MAC should be subsequently completed via
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.
250 /*----------------------------------------------------------------
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
259 * wlandev wlan device structure
263 * >0 f/w reported error
264 * <0 driver reported error
270 ----------------------------------------------------------------*/
271 static int prism2sta_close(wlandevice_t *wlandev)
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.
286 /*----------------------------------------------------------------
289 * Not currently implented.
292 * wlandev wlan device structure
302 ----------------------------------------------------------------*/
303 static void prism2sta_reset(wlandevice_t *wlandev )
311 /*----------------------------------------------------------------
314 * Takes a frame from p80211 and queues it for transmission.
317 * wlandev wlan device structure
318 * pb packet buffer struct. Contains an 802.11
320 * p80211_hdr points to the 802.11 header for the packet.
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
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)
336 hfa384x_t *hw = (hfa384x_t *)wlandev->priv;
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));
345 result = hfa384x_drvr_txframe(hw, skb, p80211_hdr, p80211_wep);
352 /*----------------------------------------------------------------
353 * prism2sta_mlmerequest
355 * wlan command message handler. All we do here is pass the message
356 * over to the prism2sta_mgmt_handler.
359 * wlandev wlan device structure
360 * msg wlan command message
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
375 ----------------------------------------------------------------*/
376 static int prism2sta_mlmerequest(wlandevice_t *wlandev, p80211msg_t *msg)
378 hfa384x_t *hw = (hfa384x_t *)wlandev->priv;
383 switch( msg->msgcode )
385 case DIDmsg_dot11req_mibget :
386 WLAN_LOG_DEBUG(2,"Received mibget request\n");
387 result = prism2mgmt_mibset_mibget(wlandev, msg);
389 case DIDmsg_dot11req_mibset :
390 WLAN_LOG_DEBUG(2,"Received mibset request\n");
391 result = prism2mgmt_mibset_mibget(wlandev, msg);
393 case DIDmsg_dot11req_powermgmt :
394 WLAN_LOG_DEBUG(2,"Received powermgmt request\n");
395 result = prism2mgmt_powermgmt(wlandev, msg);
397 case DIDmsg_dot11req_scan :
398 WLAN_LOG_DEBUG(2,"Received scan request\n");
399 result = prism2mgmt_scan(wlandev, msg);
401 case DIDmsg_dot11req_scan_results :
402 WLAN_LOG_DEBUG(2,"Received scan_results request\n");
403 result = prism2mgmt_scan_results(wlandev, msg);
405 case DIDmsg_dot11req_join :
406 WLAN_LOG_DEBUG(2,"Received join request\n");
407 result = prism2mgmt_join(wlandev, msg);
409 case DIDmsg_dot11req_authenticate :
410 WLAN_LOG_DEBUG(2,"Received authenticate request\n");
411 result = prism2mgmt_authenticate(wlandev, msg);
413 case DIDmsg_dot11req_deauthenticate :
414 WLAN_LOG_DEBUG(2,"Received mlme deauthenticate request\n");
415 result = prism2mgmt_deauthenticate(wlandev, msg);
417 case DIDmsg_dot11req_associate :
418 WLAN_LOG_DEBUG(2,"Received mlme associate request\n");
419 result = prism2mgmt_associate(wlandev, msg);
421 case DIDmsg_dot11req_reassociate :
422 WLAN_LOG_DEBUG(2,"Received mlme reassociate request\n");
423 result = prism2mgmt_reassociate(wlandev, msg);
425 case DIDmsg_dot11req_disassociate :
426 WLAN_LOG_DEBUG(2,"Received mlme disassociate request\n");
427 result = prism2mgmt_disassociate(wlandev, msg);
429 case DIDmsg_dot11req_reset :
430 WLAN_LOG_DEBUG(2,"Received mlme reset request\n");
431 result = prism2mgmt_reset(wlandev, msg);
433 case DIDmsg_dot11req_start :
434 WLAN_LOG_DEBUG(2,"Received mlme start request\n");
435 result = prism2mgmt_start(wlandev, msg);
438 * Prism2 specific messages
440 case DIDmsg_p2req_join :
441 WLAN_LOG_DEBUG(2,"Received p2 join request\n");
442 result = prism2mgmt_p2_join(wlandev, msg);
444 case DIDmsg_p2req_readpda :
445 WLAN_LOG_DEBUG(2,"Received mlme readpda request\n");
446 result = prism2mgmt_readpda(wlandev, msg);
448 case DIDmsg_p2req_readcis :
449 WLAN_LOG_DEBUG(2,"Received mlme readcis request\n");
450 result = prism2mgmt_readcis(wlandev, msg);
452 case DIDmsg_p2req_auxport_state :
453 WLAN_LOG_DEBUG(2,"Received mlme auxport_state request\n");
454 result = prism2mgmt_auxport_state(wlandev, msg);
456 case DIDmsg_p2req_auxport_read :
457 WLAN_LOG_DEBUG(2,"Received mlme auxport_read request\n");
458 result = prism2mgmt_auxport_read(wlandev, msg);
460 case DIDmsg_p2req_auxport_write :
461 WLAN_LOG_DEBUG(2,"Received mlme auxport_write request\n");
462 result = prism2mgmt_auxport_write(wlandev, msg);
464 case DIDmsg_p2req_low_level :
465 WLAN_LOG_DEBUG(2,"Received mlme low_level request\n");
466 result = prism2mgmt_low_level(wlandev, msg);
468 case DIDmsg_p2req_test_command :
469 WLAN_LOG_DEBUG(2,"Received mlme test_command request\n");
470 result = prism2mgmt_test_command(wlandev, msg);
472 case DIDmsg_p2req_mmi_read :
473 WLAN_LOG_DEBUG(2,"Received mlme mmi_read request\n");
474 result = prism2mgmt_mmi_read(wlandev, msg);
476 case DIDmsg_p2req_mmi_write :
477 WLAN_LOG_DEBUG(2,"Received mlme mmi_write request\n");
478 result = prism2mgmt_mmi_write(wlandev, msg);
480 case DIDmsg_p2req_ramdl_state :
481 WLAN_LOG_DEBUG(2,"Received mlme ramdl_state request\n");
482 result = prism2mgmt_ramdl_state(wlandev, msg);
484 case DIDmsg_p2req_ramdl_write :
485 WLAN_LOG_DEBUG(2,"Received mlme ramdl_write request\n");
486 result = prism2mgmt_ramdl_write(wlandev, msg);
488 case DIDmsg_p2req_flashdl_state :
489 WLAN_LOG_DEBUG(2,"Received mlme flashdl_state request\n");
490 result = prism2mgmt_flashdl_state(wlandev, msg);
492 case DIDmsg_p2req_flashdl_write :
493 WLAN_LOG_DEBUG(2,"Received mlme flashdl_write request\n");
494 result = prism2mgmt_flashdl_write(wlandev, msg);
496 case DIDmsg_p2req_dump_state :
497 WLAN_LOG_DEBUG(2,"Received mlme dump_state request\n");
498 result = prism2mgmt_dump_state(wlandev, msg);
501 * Linux specific messages
503 case DIDmsg_lnxreq_hostwep :
505 case DIDmsg_lnxreq_ifstate :
507 p80211msg_lnxreq_ifstate_t *ifstatemsg;
508 WLAN_LOG_DEBUG(2,"Received mlme ifstate request\n");
509 ifstatemsg = (p80211msg_lnxreq_ifstate_t*)msg;
510 result = prism2sta_ifstate(wlandev, ifstatemsg->ifstate.data);
511 ifstatemsg->resultcode.status =
512 P80211ENUM_msgitem_status_data_ok;
513 ifstatemsg->resultcode.data = result;
517 case DIDmsg_lnxreq_wlansniff :
518 WLAN_LOG_DEBUG(2,"Received mlme wlansniff request\n");
519 result = prism2mgmt_wlansniff(wlandev, msg);
521 case DIDmsg_lnxreq_autojoin :
522 WLAN_LOG_DEBUG(2,"Received mlme autojoin request\n");
523 result = prism2mgmt_autojoin(wlandev, msg);
525 case DIDmsg_p2req_enable :
526 WLAN_LOG_DEBUG(2,"Received mlme enable request\n");
527 result = prism2mgmt_enable(wlandev, msg);
529 case DIDmsg_lnxreq_commsquality: {
530 p80211msg_lnxreq_commsquality_t *qualmsg;
532 WLAN_LOG_DEBUG(2,"Received commsquality request\n");
537 qualmsg = (p80211msg_lnxreq_commsquality_t*) msg;
539 qualmsg->link.status = P80211ENUM_msgitem_status_data_ok;
540 qualmsg->level.status = P80211ENUM_msgitem_status_data_ok;
541 qualmsg->noise.status = P80211ENUM_msgitem_status_data_ok;
544 qualmsg->link.data = hfa384x2host_16(hw->qual.CQ_currBSS);
545 qualmsg->level.data = hfa384x2host_16(hw->qual.ASL_currBSS);
546 qualmsg->noise.data = hfa384x2host_16(hw->qual.ANL_currFC);
551 WLAN_LOG_WARNING("Unknown mgmt request message 0x%08x", msg->msgcode);
560 /*----------------------------------------------------------------
563 * Interface state. This is the primary WLAN interface enable/disable
564 * handler. Following the driver/load/deviceprobe sequence, this
565 * function must be called with a state of "enable" before any other
566 * commands will be accepted.
569 * wlandev wlan device structure
570 * msgp ptr to msg buffer
573 * A p80211 message resultcode value.
578 * process thread (usually)
580 ----------------------------------------------------------------*/
581 UINT32 prism2sta_ifstate(wlandevice_t *wlandev, UINT32 ifstate)
583 hfa384x_t *hw = (hfa384x_t *)wlandev->priv;
587 result = P80211ENUM_resultcode_implementation_failure;
589 WLAN_LOG_DEBUG(2, "Current MSD state(%d), requesting(%d)\n",
590 wlandev->msdstate, ifstate);
593 case P80211ENUM_ifstate_fwload:
594 switch (wlandev->msdstate) {
595 case WLAN_MSD_HWPRESENT:
596 wlandev->msdstate = WLAN_MSD_FWLOAD_PENDING;
598 * Initialize the device+driver sufficiently
599 * for firmware loading.
601 if ((result=hfa384x_drvr_start(hw))) {
603 "hfa384x_drvr_start() failed,"
604 "result=%d\n", (int)result);
606 P80211ENUM_resultcode_implementation_failure;
607 wlandev->msdstate = WLAN_MSD_HWPRESENT;
610 wlandev->msdstate = WLAN_MSD_FWLOAD;
611 result = P80211ENUM_resultcode_success;
613 case WLAN_MSD_FWLOAD:
614 hfa384x_cmd_initialize(hw);
615 result = P80211ENUM_resultcode_success;
617 case WLAN_MSD_RUNNING:
619 "Cannot enter fwload state from enable state,"
620 "you must disable first.\n");
621 result = P80211ENUM_resultcode_invalid_parameters;
623 case WLAN_MSD_HWFAIL:
625 /* probe() had a problem or the msdstate contains
626 * an unrecognized value, there's nothing we can do.
628 result = P80211ENUM_resultcode_implementation_failure;
632 case P80211ENUM_ifstate_enable:
633 switch (wlandev->msdstate) {
634 case WLAN_MSD_HWPRESENT:
635 case WLAN_MSD_FWLOAD:
636 wlandev->msdstate = WLAN_MSD_RUNNING_PENDING;
637 /* Initialize the device+driver for full
638 * operation. Note that this might me an FWLOAD to
639 * to RUNNING transition so we must not do a chip
640 * or board level reset. Note that on failure,
641 * the MSD state is set to HWPRESENT because we
642 * can't make any assumptions about the state
643 * of the hardware or a previous firmware load.
645 if ((result=hfa384x_drvr_start(hw))) {
647 "hfa384x_drvr_start() failed,"
648 "result=%d\n", (int)result);
650 P80211ENUM_resultcode_implementation_failure;
651 wlandev->msdstate = WLAN_MSD_HWPRESENT;
655 if ((result=prism2sta_getcardinfo(wlandev))) {
657 "prism2sta_getcardinfo() failed,"
658 "result=%d\n", (int)result);
660 P80211ENUM_resultcode_implementation_failure;
661 hfa384x_drvr_stop(hw);
662 wlandev->msdstate = WLAN_MSD_HWPRESENT;
665 if ((result=prism2sta_globalsetup(wlandev))) {
667 "prism2sta_globalsetup() failed,"
668 "result=%d\n", (int)result);
670 P80211ENUM_resultcode_implementation_failure;
671 hfa384x_drvr_stop(hw);
672 wlandev->msdstate = WLAN_MSD_HWPRESENT;
675 wlandev->msdstate = WLAN_MSD_RUNNING;
677 hw->join_retries = 60;
678 result = P80211ENUM_resultcode_success;
680 case WLAN_MSD_RUNNING:
681 /* Do nothing, we're already in this state.*/
682 result = P80211ENUM_resultcode_success;
684 case WLAN_MSD_HWFAIL:
686 /* probe() had a problem or the msdstate contains
687 * an unrecognized value, there's nothing we can do.
689 result = P80211ENUM_resultcode_implementation_failure;
693 case P80211ENUM_ifstate_disable:
694 switch (wlandev->msdstate) {
695 case WLAN_MSD_HWPRESENT:
696 /* Do nothing, we're already in this state.*/
697 result = P80211ENUM_resultcode_success;
699 case WLAN_MSD_FWLOAD:
700 case WLAN_MSD_RUNNING:
701 wlandev->msdstate = WLAN_MSD_HWPRESENT_PENDING;
703 * TODO: Shut down the MAC completely. Here a chip
704 * or board level reset is probably called for.
705 * After a "disable" _all_ results are lost, even
706 * those from a fwload.
708 if (!wlandev->hwremoved)
709 netif_carrier_off(wlandev->netdev);
711 hfa384x_drvr_stop(hw);
713 wlandev->macmode = WLAN_MACMODE_NONE;
714 wlandev->msdstate = WLAN_MSD_HWPRESENT;
715 result = P80211ENUM_resultcode_success;
717 case WLAN_MSD_HWFAIL:
719 /* probe() had a problem or the msdstate contains
720 * an unrecognized value, there's nothing we can do.
722 result = P80211ENUM_resultcode_implementation_failure;
727 result = P80211ENUM_resultcode_invalid_parameters;
736 /*----------------------------------------------------------------
737 * prism2sta_getcardinfo
739 * Collect the NICID, firmware version and any other identifiers
740 * we'd like to have in host-side data structures.
743 * wlandev wlan device structure
747 * >0 f/w reported error
748 * <0 driver reported error
754 ----------------------------------------------------------------*/
755 static int prism2sta_getcardinfo(wlandevice_t *wlandev)
758 hfa384x_t *hw = (hfa384x_t *)wlandev->priv;
760 UINT8 snum[HFA384x_RID_NICSERIALNUMBER_LEN];
761 char pstr[(HFA384x_RID_NICSERIALNUMBER_LEN * 4) + 1];
765 /* Collect version and compatibility info */
766 /* Some are critical, some are not */
768 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_NICIDENTITY,
769 &hw->ident_nic, sizeof(hfa384x_compident_t));
771 WLAN_LOG_ERROR("Failed to retrieve NICIDENTITY\n");
775 /* get all the nic id fields in host byte order */
776 hw->ident_nic.id = hfa384x2host_16(hw->ident_nic.id);
777 hw->ident_nic.variant = hfa384x2host_16(hw->ident_nic.variant);
778 hw->ident_nic.major = hfa384x2host_16(hw->ident_nic.major);
779 hw->ident_nic.minor = hfa384x2host_16(hw->ident_nic.minor);
781 WLAN_LOG_INFO( "ident: nic h/w: id=0x%02x %d.%d.%d\n",
782 hw->ident_nic.id, hw->ident_nic.major,
783 hw->ident_nic.minor, hw->ident_nic.variant);
785 /* Primary f/w identity */
786 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_PRIIDENTITY,
787 &hw->ident_pri_fw, sizeof(hfa384x_compident_t));
789 WLAN_LOG_ERROR("Failed to retrieve PRIIDENTITY\n");
793 /* get all the private fw id fields in host byte order */
794 hw->ident_pri_fw.id = hfa384x2host_16(hw->ident_pri_fw.id);
795 hw->ident_pri_fw.variant = hfa384x2host_16(hw->ident_pri_fw.variant);
796 hw->ident_pri_fw.major = hfa384x2host_16(hw->ident_pri_fw.major);
797 hw->ident_pri_fw.minor = hfa384x2host_16(hw->ident_pri_fw.minor);
799 WLAN_LOG_INFO( "ident: pri f/w: id=0x%02x %d.%d.%d\n",
800 hw->ident_pri_fw.id, hw->ident_pri_fw.major,
801 hw->ident_pri_fw.minor, hw->ident_pri_fw.variant);
803 /* Station (Secondary?) f/w identity */
804 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_STAIDENTITY,
805 &hw->ident_sta_fw, sizeof(hfa384x_compident_t));
807 WLAN_LOG_ERROR("Failed to retrieve STAIDENTITY\n");
811 if (hw->ident_nic.id < 0x8000) {
812 WLAN_LOG_ERROR("FATAL: Card is not an Intersil Prism2/2.5/3\n");
817 /* get all the station fw id fields in host byte order */
818 hw->ident_sta_fw.id = hfa384x2host_16(hw->ident_sta_fw.id);
819 hw->ident_sta_fw.variant = hfa384x2host_16(hw->ident_sta_fw.variant);
820 hw->ident_sta_fw.major = hfa384x2host_16(hw->ident_sta_fw.major);
821 hw->ident_sta_fw.minor = hfa384x2host_16(hw->ident_sta_fw.minor);
823 /* strip out the 'special' variant bits */
824 hw->mm_mods = hw->ident_sta_fw.variant & (BIT14 | BIT15);
825 hw->ident_sta_fw.variant &= ~((UINT16)(BIT14 | BIT15));
827 if ( hw->ident_sta_fw.id == 0x1f ) {
830 "ident: sta f/w: id=0x%02x %d.%d.%d\n",
831 hw->ident_sta_fw.id, hw->ident_sta_fw.major,
832 hw->ident_sta_fw.minor, hw->ident_sta_fw.variant);
836 "ident: ap f/w: id=0x%02x %d.%d.%d\n",
837 hw->ident_sta_fw.id, hw->ident_sta_fw.major,
838 hw->ident_sta_fw.minor, hw->ident_sta_fw.variant);
841 /* Compatibility range, Modem supplier */
842 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_MFISUPRANGE,
843 &hw->cap_sup_mfi, sizeof(hfa384x_caplevel_t));
845 WLAN_LOG_ERROR("Failed to retrieve MFISUPRANGE\n");
849 /* get all the Compatibility range, modem interface supplier
850 fields in byte order */
851 hw->cap_sup_mfi.role = hfa384x2host_16(hw->cap_sup_mfi.role);
852 hw->cap_sup_mfi.id = hfa384x2host_16(hw->cap_sup_mfi.id);
853 hw->cap_sup_mfi.variant = hfa384x2host_16(hw->cap_sup_mfi.variant);
854 hw->cap_sup_mfi.bottom = hfa384x2host_16(hw->cap_sup_mfi.bottom);
855 hw->cap_sup_mfi.top = hfa384x2host_16(hw->cap_sup_mfi.top);
858 "MFI:SUP:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
859 hw->cap_sup_mfi.role, hw->cap_sup_mfi.id,
860 hw->cap_sup_mfi.variant, hw->cap_sup_mfi.bottom,
861 hw->cap_sup_mfi.top);
863 /* Compatibility range, Controller supplier */
864 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_CFISUPRANGE,
865 &hw->cap_sup_cfi, sizeof(hfa384x_caplevel_t));
867 WLAN_LOG_ERROR("Failed to retrieve CFISUPRANGE\n");
871 /* get all the Compatibility range, controller interface supplier
872 fields in byte order */
873 hw->cap_sup_cfi.role = hfa384x2host_16(hw->cap_sup_cfi.role);
874 hw->cap_sup_cfi.id = hfa384x2host_16(hw->cap_sup_cfi.id);
875 hw->cap_sup_cfi.variant = hfa384x2host_16(hw->cap_sup_cfi.variant);
876 hw->cap_sup_cfi.bottom = hfa384x2host_16(hw->cap_sup_cfi.bottom);
877 hw->cap_sup_cfi.top = hfa384x2host_16(hw->cap_sup_cfi.top);
880 "CFI:SUP:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
881 hw->cap_sup_cfi.role, hw->cap_sup_cfi.id,
882 hw->cap_sup_cfi.variant, hw->cap_sup_cfi.bottom,
883 hw->cap_sup_cfi.top);
885 /* Compatibility range, Primary f/w supplier */
886 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_PRISUPRANGE,
887 &hw->cap_sup_pri, sizeof(hfa384x_caplevel_t));
889 WLAN_LOG_ERROR("Failed to retrieve PRISUPRANGE\n");
893 /* get all the Compatibility range, primary firmware supplier
894 fields in byte order */
895 hw->cap_sup_pri.role = hfa384x2host_16(hw->cap_sup_pri.role);
896 hw->cap_sup_pri.id = hfa384x2host_16(hw->cap_sup_pri.id);
897 hw->cap_sup_pri.variant = hfa384x2host_16(hw->cap_sup_pri.variant);
898 hw->cap_sup_pri.bottom = hfa384x2host_16(hw->cap_sup_pri.bottom);
899 hw->cap_sup_pri.top = hfa384x2host_16(hw->cap_sup_pri.top);
902 "PRI:SUP:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
903 hw->cap_sup_pri.role, hw->cap_sup_pri.id,
904 hw->cap_sup_pri.variant, hw->cap_sup_pri.bottom,
905 hw->cap_sup_pri.top);
907 /* Compatibility range, Station f/w supplier */
908 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_STASUPRANGE,
909 &hw->cap_sup_sta, sizeof(hfa384x_caplevel_t));
911 WLAN_LOG_ERROR("Failed to retrieve STASUPRANGE\n");
915 /* get all the Compatibility range, station firmware supplier
916 fields in byte order */
917 hw->cap_sup_sta.role = hfa384x2host_16(hw->cap_sup_sta.role);
918 hw->cap_sup_sta.id = hfa384x2host_16(hw->cap_sup_sta.id);
919 hw->cap_sup_sta.variant = hfa384x2host_16(hw->cap_sup_sta.variant);
920 hw->cap_sup_sta.bottom = hfa384x2host_16(hw->cap_sup_sta.bottom);
921 hw->cap_sup_sta.top = hfa384x2host_16(hw->cap_sup_sta.top);
923 if ( hw->cap_sup_sta.id == 0x04 ) {
925 "STA:SUP:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
926 hw->cap_sup_sta.role, hw->cap_sup_sta.id,
927 hw->cap_sup_sta.variant, hw->cap_sup_sta.bottom,
928 hw->cap_sup_sta.top);
931 "AP:SUP:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
932 hw->cap_sup_sta.role, hw->cap_sup_sta.id,
933 hw->cap_sup_sta.variant, hw->cap_sup_sta.bottom,
934 hw->cap_sup_sta.top);
937 /* Compatibility range, primary f/w actor, CFI supplier */
938 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_PRI_CFIACTRANGES,
939 &hw->cap_act_pri_cfi, sizeof(hfa384x_caplevel_t));
941 WLAN_LOG_ERROR("Failed to retrieve PRI_CFIACTRANGES\n");
945 /* get all the Compatibility range, primary f/w actor, CFI supplier
946 fields in byte order */
947 hw->cap_act_pri_cfi.role = hfa384x2host_16(hw->cap_act_pri_cfi.role);
948 hw->cap_act_pri_cfi.id = hfa384x2host_16(hw->cap_act_pri_cfi.id);
949 hw->cap_act_pri_cfi.variant = hfa384x2host_16(hw->cap_act_pri_cfi.variant);
950 hw->cap_act_pri_cfi.bottom = hfa384x2host_16(hw->cap_act_pri_cfi.bottom);
951 hw->cap_act_pri_cfi.top = hfa384x2host_16(hw->cap_act_pri_cfi.top);
954 "PRI-CFI:ACT:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
955 hw->cap_act_pri_cfi.role, hw->cap_act_pri_cfi.id,
956 hw->cap_act_pri_cfi.variant, hw->cap_act_pri_cfi.bottom,
957 hw->cap_act_pri_cfi.top);
959 /* Compatibility range, sta f/w actor, CFI supplier */
960 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_STA_CFIACTRANGES,
961 &hw->cap_act_sta_cfi, sizeof(hfa384x_caplevel_t));
963 WLAN_LOG_ERROR("Failed to retrieve STA_CFIACTRANGES\n");
967 /* get all the Compatibility range, station f/w actor, CFI supplier
968 fields in byte order */
969 hw->cap_act_sta_cfi.role = hfa384x2host_16(hw->cap_act_sta_cfi.role);
970 hw->cap_act_sta_cfi.id = hfa384x2host_16(hw->cap_act_sta_cfi.id);
971 hw->cap_act_sta_cfi.variant = hfa384x2host_16(hw->cap_act_sta_cfi.variant);
972 hw->cap_act_sta_cfi.bottom = hfa384x2host_16(hw->cap_act_sta_cfi.bottom);
973 hw->cap_act_sta_cfi.top = hfa384x2host_16(hw->cap_act_sta_cfi.top);
976 "STA-CFI:ACT:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
977 hw->cap_act_sta_cfi.role, hw->cap_act_sta_cfi.id,
978 hw->cap_act_sta_cfi.variant, hw->cap_act_sta_cfi.bottom,
979 hw->cap_act_sta_cfi.top);
981 /* Compatibility range, sta f/w actor, MFI supplier */
982 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_STA_MFIACTRANGES,
983 &hw->cap_act_sta_mfi, sizeof(hfa384x_caplevel_t));
985 WLAN_LOG_ERROR("Failed to retrieve STA_MFIACTRANGES\n");
989 /* get all the Compatibility range, station f/w actor, MFI supplier
990 fields in byte order */
991 hw->cap_act_sta_mfi.role = hfa384x2host_16(hw->cap_act_sta_mfi.role);
992 hw->cap_act_sta_mfi.id = hfa384x2host_16(hw->cap_act_sta_mfi.id);
993 hw->cap_act_sta_mfi.variant = hfa384x2host_16(hw->cap_act_sta_mfi.variant);
994 hw->cap_act_sta_mfi.bottom = hfa384x2host_16(hw->cap_act_sta_mfi.bottom);
995 hw->cap_act_sta_mfi.top = hfa384x2host_16(hw->cap_act_sta_mfi.top);
998 "STA-MFI:ACT:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
999 hw->cap_act_sta_mfi.role, hw->cap_act_sta_mfi.id,
1000 hw->cap_act_sta_mfi.variant, hw->cap_act_sta_mfi.bottom,
1001 hw->cap_act_sta_mfi.top);
1004 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_NICSERIALNUMBER,
1005 snum, HFA384x_RID_NICSERIALNUMBER_LEN);
1007 wlan_mkprintstr(snum, HFA384x_RID_NICSERIALNUMBER_LEN,
1008 pstr, sizeof(pstr));
1009 WLAN_LOG_INFO("Prism2 card SN: %s\n", pstr);
1011 WLAN_LOG_ERROR("Failed to retrieve Prism2 Card SN\n");
1015 /* Collect the MAC address */
1016 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_CNFOWNMACADDR,
1017 wlandev->netdev->dev_addr, WLAN_ADDR_LEN);
1018 if ( result != 0 ) {
1019 WLAN_LOG_ERROR("Failed to retrieve mac address\n");
1023 /* short preamble is always implemented */
1024 wlandev->nsdcaps |= P80211_NSDCAP_SHORT_PREAMBLE;
1026 /* find out if hardware wep is implemented */
1027 hfa384x_drvr_getconfig16(hw, HFA384x_RID_PRIVACYOPTIMP, &temp);
1029 wlandev->nsdcaps |= P80211_NSDCAP_HARDWAREWEP;
1031 /* get the dBm Scaling constant */
1032 hfa384x_drvr_getconfig16(hw, HFA384x_RID_CNFDBMADJUST, &temp);
1033 hw->dbmadjust = temp;
1035 /* Only enable scan by default on newer firmware */
1036 if (HFA384x_FIRMWARE_VERSION(hw->ident_sta_fw.major,
1037 hw->ident_sta_fw.minor,
1038 hw->ident_sta_fw.variant) <
1039 HFA384x_FIRMWARE_VERSION(1,5,5)) {
1040 wlandev->nsdcaps |= P80211_NSDCAP_NOSCAN;
1043 /* TODO: Set any internally managed config items */
1047 WLAN_LOG_ERROR("Failed, result=%d\n", result);
1054 /*----------------------------------------------------------------
1055 * prism2sta_globalsetup
1057 * Set any global RIDs that we want to set at device activation.
1060 * wlandev wlan device structure
1064 * >0 f/w reported error
1065 * <0 driver reported error
1071 ----------------------------------------------------------------*/
1072 static int prism2sta_globalsetup(wlandevice_t *wlandev)
1074 hfa384x_t *hw = (hfa384x_t *)wlandev->priv;
1076 /* Set the maximum frame size */
1077 return hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFMAXDATALEN,
1081 static int prism2sta_setmulticast(wlandevice_t *wlandev, netdevice_t *dev)
1084 hfa384x_t *hw = (hfa384x_t *)wlandev->priv;
1090 /* If we're not ready, what's the point? */
1091 if ( hw->state != HFA384x_STATE_RUNNING )
1094 /* If we're an AP, do nothing here */
1098 if ( (dev->flags & (IFF_PROMISC | IFF_ALLMULTI)) != 0 )
1099 promisc = P80211ENUM_truth_true;
1101 promisc = P80211ENUM_truth_false;
1103 result = hfa384x_drvr_setconfig16_async(hw, HFA384x_RID_PROMISCMODE, promisc);
1105 /* XXX TODO: configure the multicast list */
1106 // CLEAR_HW_MULTICAST_LIST
1107 // struct dev_mc_list element = dev->mc_list;
1108 // while (element != null) {
1109 // HW_ADD_MULTICAST_ADDR(element->dmi_addr, dmi_addrlen)
1110 // element = element->next;
1118 /*----------------------------------------------------------------
1119 * prism2sta_inf_handover
1121 * Handles the receipt of a Handover info frame. Should only be present
1125 * wlandev wlan device structure
1126 * inf ptr to info frame (contents in hfa384x order)
1135 ----------------------------------------------------------------*/
1136 static void prism2sta_inf_handover(wlandevice_t *wlandev, hfa384x_InfFrame_t *inf)
1139 WLAN_LOG_DEBUG(2,"received infoframe:HANDOVER (unhandled)\n");
1145 /*----------------------------------------------------------------
1146 * prism2sta_inf_tallies
1148 * Handles the receipt of a CommTallies info frame.
1151 * wlandev wlan device structure
1152 * inf ptr to info frame (contents in hfa384x order)
1161 ----------------------------------------------------------------*/
1162 static void prism2sta_inf_tallies(wlandevice_t *wlandev, hfa384x_InfFrame_t *inf)
1164 hfa384x_t *hw = (hfa384x_t *)wlandev->priv;
1174 ** Determine if these are 16-bit or 32-bit tallies, based on the
1175 ** record length of the info record.
1178 cnt = sizeof(hfa384x_CommTallies32_t) / sizeof(UINT32);
1179 if (inf->framelen > 22) {
1180 dst = (UINT32 *) &hw->tallies;
1181 src32 = (UINT32 *) &inf->info.commtallies32;
1182 for (i = 0; i < cnt; i++, dst++, src32++)
1183 *dst += hfa384x2host_32(*src32);
1185 dst = (UINT32 *) &hw->tallies;
1186 src16 = (UINT16 *) &inf->info.commtallies16;
1187 for (i = 0; i < cnt; i++, dst++, src16++)
1188 *dst += hfa384x2host_16(*src16);
1196 /*----------------------------------------------------------------
1197 * prism2sta_inf_scanresults
1199 * Handles the receipt of a Scan Results info frame.
1202 * wlandev wlan device structure
1203 * inf ptr to info frame (contents in hfa384x order)
1212 ----------------------------------------------------------------*/
1213 static void prism2sta_inf_scanresults(wlandevice_t *wlandev,
1214 hfa384x_InfFrame_t *inf)
1217 hfa384x_t *hw = (hfa384x_t *)wlandev->priv;
1219 hfa384x_ScanResult_t *sr = &(inf->info.scanresult);
1221 hfa384x_JoinRequest_data_t joinreq;
1225 /* Get the number of results, first in bytes, then in results */
1226 nbss = (inf->framelen * sizeof(UINT16)) -
1227 sizeof(inf->infotype) -
1228 sizeof(inf->info.scanresult.scanreason);
1229 nbss /= sizeof(hfa384x_ScanResultSub_t);
1232 WLAN_LOG_DEBUG(1,"rx scanresults, reason=%d, nbss=%d:\n",
1233 inf->info.scanresult.scanreason, nbss);
1234 for ( i = 0; i < nbss; i++) {
1235 WLAN_LOG_DEBUG(1, "chid=%d anl=%d sl=%d bcnint=%d\n",
1239 sr->result[i].bcnint);
1240 WLAN_LOG_DEBUG(1, " capinfo=0x%04x proberesp_rate=%d\n",
1241 sr->result[i].capinfo,
1242 sr->result[i].proberesp_rate);
1244 /* issue a join request */
1245 joinreq.channel = sr->result[0].chid;
1246 memcpy( joinreq.bssid, sr->result[0].bssid, WLAN_BSSID_LEN);
1247 result = hfa384x_drvr_setconfig( hw,
1248 HFA384x_RID_JOINREQUEST,
1249 &joinreq, HFA384x_RID_JOINREQUEST_LEN);
1251 WLAN_LOG_ERROR("setconfig(joinreq) failed, result=%d\n", result);
1258 /*----------------------------------------------------------------
1259 * prism2sta_inf_hostscanresults
1261 * Handles the receipt of a Scan Results info frame.
1264 * wlandev wlan device structure
1265 * inf ptr to info frame (contents in hfa384x order)
1274 ----------------------------------------------------------------*/
1275 static void prism2sta_inf_hostscanresults(wlandevice_t *wlandev,
1276 hfa384x_InfFrame_t *inf)
1278 hfa384x_t *hw = (hfa384x_t *)wlandev->priv;
1282 nbss = (inf->framelen - 3) / 32;
1283 WLAN_LOG_DEBUG(1, "Received %d hostscan results\n", nbss);
1288 if (hw->scanresults)
1289 kfree(hw->scanresults);
1291 hw->scanresults = kmalloc(sizeof(hfa384x_InfFrame_t), GFP_ATOMIC);
1292 memcpy(hw->scanresults, inf, sizeof(hfa384x_InfFrame_t));
1297 /* Notify/wake the sleeping caller. */
1298 hw->scanflag = nbss;
1299 wake_up_interruptible(&hw->cmdq);
1304 /*----------------------------------------------------------------
1305 * prism2sta_inf_chinforesults
1307 * Handles the receipt of a Channel Info Results info frame.
1310 * wlandev wlan device structure
1311 * inf ptr to info frame (contents in hfa384x order)
1320 ----------------------------------------------------------------*/
1321 static void prism2sta_inf_chinforesults(wlandevice_t *wlandev,
1322 hfa384x_InfFrame_t *inf)
1324 hfa384x_t *hw = (hfa384x_t *)wlandev->priv;
1328 hw->channel_info.results.scanchannels =
1329 hfa384x2host_16(inf->info.chinforesult.scanchannels);
1331 memcpy(&inf->info.chinforesult, &hw->channel_info.results, sizeof(hfa384x_ChInfoResult_t));
1334 for (i=0, n=0; i<HFA384x_CHINFORESULT_MAX; i++) {
1335 if (hw->channel_info.results.scanchannels & (1<<i)) {
1336 int channel=hfa384x2host_16(inf->info.chinforesult.result[n].chid)-1;
1337 hfa384x_ChInfoResultSub_t *chinforesult=&hw->channel_info.results.result[channel];
1338 chinforesult->chid = channel;
1339 chinforesult->anl = hfa384x2host_16(inf->info.chinforesult.result[n].anl);
1340 chinforesult->pnl = hfa384x2host_16(inf->info.chinforesult.result[n].pnl);
1341 chinforesult->active = hfa384x2host_16(inf->info.chinforesult.result[n].active);
1342 WLAN_LOG_DEBUG(2, "chinfo: channel %d, %s level (avg/peak)=%d/%d dB, pcf %d\n",
1344 chinforesult->active &
1345 HFA384x_CHINFORESULT_BSSACTIVE ? "signal" : "noise",
1346 chinforesult->anl, chinforesult->pnl,
1347 chinforesult->active & HFA384x_CHINFORESULT_PCFACTIVE ? 1 : 0
1352 atomic_set(&hw->channel_info.done, 2);
1354 hw->channel_info.count = n;
1359 void prism2sta_processing_defer(struct work_struct *data)
1361 hfa384x_t *hw = container_of(data, struct hfa384x, link_bh);
1362 wlandevice_t *wlandev = hw->wlandev;
1363 hfa384x_bytestr32_t ssid;
1367 /* First let's process the auth frames */
1369 struct sk_buff *skb;
1370 hfa384x_InfFrame_t *inf;
1372 while ( (skb = skb_dequeue(&hw->authq)) ) {
1373 inf = (hfa384x_InfFrame_t *) skb->data;
1374 prism2sta_inf_authreq_defer(wlandev, inf);
1379 /* Now let's handle the linkstatus stuff */
1380 if (hw->link_status == hw->link_status_new)
1383 hw->link_status = hw->link_status_new;
1385 switch(hw->link_status) {
1386 case HFA384x_LINK_NOTCONNECTED:
1387 /* I'm currently assuming that this is the initial link
1388 * state. It should only be possible immediately
1389 * following an Enable command.
1391 * Block Transmits, Ignore receives of data frames
1393 netif_carrier_off(wlandev->netdev);
1395 WLAN_LOG_INFO("linkstatus=NOTCONNECTED (unhandled)\n");
1398 case HFA384x_LINK_CONNECTED:
1399 /* This one indicates a successful scan/join/auth/assoc.
1400 * When we have the full MLME complement, this event will
1401 * signify successful completion of both mlme_authenticate
1402 * and mlme_associate. State management will get a little
1405 * Indicate authentication and/or association
1406 * Enable Transmits, Receives and pass up data frames
1409 netif_carrier_on(wlandev->netdev);
1411 /* If we are joining a specific AP, set our state and reset retries */
1412 if(hw->join_ap == 1)
1414 hw->join_retries = 60;
1416 /* Don't call this in monitor mode */
1417 if ( wlandev->netdev->type == ARPHRD_ETHER ) {
1420 WLAN_LOG_INFO("linkstatus=CONNECTED\n");
1422 /* For non-usb devices, we can use the sync versions */
1423 /* Collect the BSSID, and set state to allow tx */
1425 result = hfa384x_drvr_getconfig(hw,
1426 HFA384x_RID_CURRENTBSSID,
1427 wlandev->bssid, WLAN_BSSID_LEN);
1430 "getconfig(0x%02x) failed, result = %d\n",
1431 HFA384x_RID_CURRENTBSSID, result);
1435 result = hfa384x_drvr_getconfig(hw,
1436 HFA384x_RID_CURRENTSSID,
1437 &ssid, sizeof(ssid));
1440 "getconfig(0x%02x) failed, result = %d\n",
1441 HFA384x_RID_CURRENTSSID, result);
1444 prism2mgmt_bytestr2pstr((hfa384x_bytestr_t *)&ssid,
1445 (p80211pstrd_t *) &wlandev->ssid);
1447 /* Collect the port status */
1448 result = hfa384x_drvr_getconfig16(hw,
1449 HFA384x_RID_PORTSTATUS, &portstatus);
1452 "getconfig(0x%02x) failed, result = %d\n",
1453 HFA384x_RID_PORTSTATUS, result);
1457 (portstatus == HFA384x_PSTATUS_CONN_IBSS) ?
1458 WLAN_MACMODE_IBSS_STA : WLAN_MACMODE_ESS_STA;
1460 /* Get the ball rolling on the comms quality stuff */
1461 prism2sta_commsqual_defer(&hw->commsqual_bh);
1465 case HFA384x_LINK_DISCONNECTED:
1466 /* This one indicates that our association is gone. We've
1467 * lost connection with the AP and/or been disassociated.
1468 * This indicates that the MAC has completely cleared it's
1469 * associated state. We * should send a deauth indication
1470 * (implying disassoc) up * to the MLME.
1472 * Indicate Deauthentication
1473 * Block Transmits, Ignore receives of data frames
1475 if(hw->join_ap == 2)
1477 hfa384x_JoinRequest_data_t joinreq;
1478 joinreq = hw->joinreq;
1479 /* Send the join request */
1480 hfa384x_drvr_setconfig( hw,
1481 HFA384x_RID_JOINREQUEST,
1482 &joinreq, HFA384x_RID_JOINREQUEST_LEN);
1483 WLAN_LOG_INFO("linkstatus=DISCONNECTED (re-submitting join)\n");
1485 if (wlandev->netdev->type == ARPHRD_ETHER)
1486 WLAN_LOG_INFO("linkstatus=DISCONNECTED (unhandled)\n");
1488 wlandev->macmode = WLAN_MACMODE_NONE;
1490 netif_carrier_off(wlandev->netdev);
1494 case HFA384x_LINK_AP_CHANGE:
1495 /* This one indicates that the MAC has decided to and
1496 * successfully completed a change to another AP. We
1497 * should probably implement a reassociation indication
1498 * in response to this one. I'm thinking that the the
1499 * p80211 layer needs to be notified in case of
1500 * buffering/queueing issues. User mode also needs to be
1501 * notified so that any BSS dependent elements can be
1503 * associated state. We * should send a deauth indication
1504 * (implying disassoc) up * to the MLME.
1506 * Indicate Reassociation
1507 * Enable Transmits, Receives and pass up data frames
1509 WLAN_LOG_INFO("linkstatus=AP_CHANGE\n");
1511 result = hfa384x_drvr_getconfig(hw,
1512 HFA384x_RID_CURRENTBSSID,
1513 wlandev->bssid, WLAN_BSSID_LEN);
1516 "getconfig(0x%02x) failed, result = %d\n",
1517 HFA384x_RID_CURRENTBSSID, result);
1521 result = hfa384x_drvr_getconfig(hw,
1522 HFA384x_RID_CURRENTSSID,
1523 &ssid, sizeof(ssid));
1526 "getconfig(0x%02x) failed, result = %d\n",
1527 HFA384x_RID_CURRENTSSID, result);
1530 prism2mgmt_bytestr2pstr((hfa384x_bytestr_t *)&ssid,
1531 (p80211pstrd_t *) &wlandev->ssid);
1534 hw->link_status = HFA384x_LINK_CONNECTED;
1535 netif_carrier_on(wlandev->netdev);
1539 case HFA384x_LINK_AP_OUTOFRANGE:
1540 /* This one indicates that the MAC has decided that the
1541 * AP is out of range, but hasn't found a better candidate
1542 * so the MAC maintains its "associated" state in case
1543 * we get back in range. We should block transmits and
1544 * receives in this state. Do we need an indication here?
1545 * Probably not since a polling user-mode element would
1546 * get this status from from p2PortStatus(FD40). What about
1549 * Block Transmits, Ignore receives of data frames
1551 WLAN_LOG_INFO("linkstatus=AP_OUTOFRANGE (unhandled)\n");
1553 netif_carrier_off(wlandev->netdev);
1557 case HFA384x_LINK_AP_INRANGE:
1558 /* This one indicates that the MAC has decided that the
1559 * AP is back in range. We continue working with our
1560 * existing association.
1562 * Enable Transmits, Receives and pass up data frames
1564 WLAN_LOG_INFO("linkstatus=AP_INRANGE\n");
1566 hw->link_status = HFA384x_LINK_CONNECTED;
1567 netif_carrier_on(wlandev->netdev);
1571 case HFA384x_LINK_ASSOCFAIL:
1572 /* This one is actually a peer to CONNECTED. We've
1573 * requested a join for a given SSID and optionally BSSID.
1574 * We can use this one to indicate authentication and
1575 * association failures. The trick is going to be
1576 * 1) identifying the failure, and 2) state management.
1578 * Disable Transmits, Ignore receives of data frames
1580 if(hw->join_ap && --hw->join_retries > 0)
1582 hfa384x_JoinRequest_data_t joinreq;
1583 joinreq = hw->joinreq;
1584 /* Send the join request */
1585 hfa384x_drvr_setconfig( hw,
1586 HFA384x_RID_JOINREQUEST,
1587 &joinreq, HFA384x_RID_JOINREQUEST_LEN);
1588 WLAN_LOG_INFO("linkstatus=ASSOCFAIL (re-submitting join)\n");
1590 WLAN_LOG_INFO("linkstatus=ASSOCFAIL (unhandled)\n");
1593 netif_carrier_off(wlandev->netdev);
1598 /* This is bad, IO port problems? */
1600 "unknown linkstatus=0x%02x\n", hw->link_status);
1605 wlandev->linkstatus = (hw->link_status == HFA384x_LINK_CONNECTED);
1607 p80211wext_event_associated(wlandev, wlandev->linkstatus);
1614 /*----------------------------------------------------------------
1615 * prism2sta_inf_linkstatus
1617 * Handles the receipt of a Link Status info frame.
1620 * wlandev wlan device structure
1621 * inf ptr to info frame (contents in hfa384x order)
1630 ----------------------------------------------------------------*/
1631 static void prism2sta_inf_linkstatus(wlandevice_t *wlandev,
1632 hfa384x_InfFrame_t *inf)
1634 hfa384x_t *hw = (hfa384x_t *)wlandev->priv;
1638 hw->link_status_new = hfa384x2host_16(inf->info.linkstatus.linkstatus);
1640 schedule_work(&hw->link_bh);
1646 /*----------------------------------------------------------------
1647 * prism2sta_inf_assocstatus
1649 * Handles the receipt of an Association Status info frame. Should
1650 * be present in APs only.
1653 * wlandev wlan device structure
1654 * inf ptr to info frame (contents in hfa384x order)
1663 ----------------------------------------------------------------*/
1664 static void prism2sta_inf_assocstatus(wlandevice_t *wlandev,
1665 hfa384x_InfFrame_t *inf)
1667 hfa384x_t *hw = (hfa384x_t *)wlandev->priv;
1668 hfa384x_AssocStatus_t rec;
1673 memcpy(&rec, &inf->info.assocstatus, sizeof(rec));
1674 rec.assocstatus = hfa384x2host_16(rec.assocstatus);
1675 rec.reason = hfa384x2host_16(rec.reason);
1678 ** Find the address in the list of authenticated stations. If it wasn't
1679 ** found, then this address has not been previously authenticated and
1680 ** something weird has happened if this is anything other than an
1681 ** "authentication failed" message. If the address was found, then
1682 ** set the "associated" flag for that station, based on whether the
1683 ** station is associating or losing its association. Something weird
1684 ** has also happened if we find the address in the list of authenticated
1685 ** stations but we are getting an "authentication failed" message.
1688 for (i = 0; i < hw->authlist.cnt; i++)
1689 if (memcmp(rec.sta_addr, hw->authlist.addr[i], WLAN_ADDR_LEN) == 0)
1692 if (i >= hw->authlist.cnt) {
1693 if (rec.assocstatus != HFA384x_ASSOCSTATUS_AUTHFAIL)
1694 WLAN_LOG_WARNING("assocstatus info frame received for non-authenticated station.\n");
1696 hw->authlist.assoc[i] =
1697 (rec.assocstatus == HFA384x_ASSOCSTATUS_STAASSOC ||
1698 rec.assocstatus == HFA384x_ASSOCSTATUS_REASSOC);
1700 if (rec.assocstatus == HFA384x_ASSOCSTATUS_AUTHFAIL)
1701 WLAN_LOG_WARNING("authfail assocstatus info frame received for authenticated station.\n");
1709 /*----------------------------------------------------------------
1710 * prism2sta_inf_authreq
1712 * Handles the receipt of an Authentication Request info frame. Should
1713 * be present in APs only.
1716 * wlandev wlan device structure
1717 * inf ptr to info frame (contents in hfa384x order)
1727 ----------------------------------------------------------------*/
1728 static void prism2sta_inf_authreq(wlandevice_t *wlandev,
1729 hfa384x_InfFrame_t *inf)
1731 hfa384x_t *hw = (hfa384x_t *)wlandev->priv;
1732 struct sk_buff *skb;
1736 skb = dev_alloc_skb(sizeof(*inf));
1738 skb_put(skb, sizeof(*inf));
1739 memcpy(skb->data, inf, sizeof(*inf));
1740 skb_queue_tail(&hw->authq, skb);
1741 schedule_work(&hw->link_bh);
1747 static void prism2sta_inf_authreq_defer(wlandevice_t *wlandev,
1748 hfa384x_InfFrame_t *inf)
1750 hfa384x_t *hw = (hfa384x_t *)wlandev->priv;
1751 hfa384x_authenticateStation_data_t rec;
1753 int i, added, result, cnt;
1759 ** Build the AuthenticateStation record. Initialize it for denying
1763 memcpy(rec.address, inf->info.authreq.sta_addr, WLAN_ADDR_LEN);
1764 rec.status = P80211ENUM_status_unspec_failure;
1767 ** Authenticate based on the access mode.
1770 switch (hw->accessmode) {
1771 case WLAN_ACCESS_NONE:
1774 ** Deny all new authentications. However, if a station
1775 ** is ALREADY authenticated, then accept it.
1778 for (i = 0; i < hw->authlist.cnt; i++)
1779 if (memcmp(rec.address, hw->authlist.addr[i],
1780 WLAN_ADDR_LEN) == 0) {
1781 rec.status = P80211ENUM_status_successful;
1787 case WLAN_ACCESS_ALL:
1790 ** Allow all authentications.
1793 rec.status = P80211ENUM_status_successful;
1796 case WLAN_ACCESS_ALLOW:
1799 ** Only allow the authentication if the MAC address
1800 ** is in the list of allowed addresses.
1802 ** Since this is the interrupt handler, we may be here
1803 ** while the access list is in the middle of being
1804 ** updated. Choose the list which is currently okay.
1805 ** See "prism2mib_priv_accessallow()" for details.
1808 if (hw->allow.modify == 0) {
1809 cnt = hw->allow.cnt;
1810 addr = hw->allow.addr[0];
1812 cnt = hw->allow.cnt1;
1813 addr = hw->allow.addr1[0];
1816 for (i = 0; i < cnt; i++, addr += WLAN_ADDR_LEN)
1817 if (memcmp(rec.address, addr, WLAN_ADDR_LEN) == 0) {
1818 rec.status = P80211ENUM_status_successful;
1824 case WLAN_ACCESS_DENY:
1827 ** Allow the authentication UNLESS the MAC address is
1828 ** in the list of denied addresses.
1830 ** Since this is the interrupt handler, we may be here
1831 ** while the access list is in the middle of being
1832 ** updated. Choose the list which is currently okay.
1833 ** See "prism2mib_priv_accessdeny()" for details.
1836 if (hw->deny.modify == 0) {
1838 addr = hw->deny.addr[0];
1840 cnt = hw->deny.cnt1;
1841 addr = hw->deny.addr1[0];
1844 rec.status = P80211ENUM_status_successful;
1846 for (i = 0; i < cnt; i++, addr += WLAN_ADDR_LEN)
1847 if (memcmp(rec.address, addr, WLAN_ADDR_LEN) == 0) {
1848 rec.status = P80211ENUM_status_unspec_failure;
1856 ** If the authentication is okay, then add the MAC address to the list
1857 ** of authenticated stations. Don't add the address if it is already in
1858 ** the list. (802.11b does not seem to disallow a station from issuing
1859 ** an authentication request when the station is already authenticated.
1860 ** Does this sort of thing ever happen? We might as well do the check
1866 if (rec.status == P80211ENUM_status_successful) {
1867 for (i = 0; i < hw->authlist.cnt; i++)
1868 if (memcmp(rec.address, hw->authlist.addr[i], WLAN_ADDR_LEN) == 0)
1871 if (i >= hw->authlist.cnt) {
1872 if (hw->authlist.cnt >= WLAN_AUTH_MAX) {
1873 rec.status = P80211ENUM_status_ap_full;
1875 memcpy(hw->authlist.addr[hw->authlist.cnt],
1876 rec.address, WLAN_ADDR_LEN);
1884 ** Send back the results of the authentication. If this doesn't work,
1885 ** then make sure to remove the address from the authenticated list if
1889 rec.status = host2hfa384x_16(rec.status);
1890 rec.algorithm = inf->info.authreq.algorithm;
1892 result = hfa384x_drvr_setconfig(hw, HFA384x_RID_AUTHENTICATESTA,
1895 if (added) hw->authlist.cnt--;
1896 WLAN_LOG_ERROR("setconfig(authenticatestation) failed, result=%d\n", result);
1905 /*----------------------------------------------------------------
1906 * prism2sta_inf_psusercnt
1908 * Handles the receipt of a PowerSaveUserCount info frame. Should
1909 * be present in APs only.
1912 * wlandev wlan device structure
1913 * inf ptr to info frame (contents in hfa384x order)
1922 ----------------------------------------------------------------*/
1923 static void prism2sta_inf_psusercnt(wlandevice_t *wlandev,
1924 hfa384x_InfFrame_t *inf)
1926 hfa384x_t *hw = (hfa384x_t *)wlandev->priv;
1930 hw->psusercount = hfa384x2host_16(inf->info.psusercnt.usercnt);
1937 /*----------------------------------------------------------------
1940 * Handles the DTIM early warning event.
1943 * wlandev wlan device structure
1952 ----------------------------------------------------------------*/
1953 void prism2sta_ev_dtim(wlandevice_t *wlandev)
1956 hfa384x_t *hw = (hfa384x_t *)wlandev->priv;
1959 WLAN_LOG_DEBUG(3, "DTIM event, currently unhandled.\n");
1965 /*----------------------------------------------------------------
1966 * prism2sta_ev_infdrop
1968 * Handles the InfDrop event.
1971 * wlandev wlan device structure
1980 ----------------------------------------------------------------*/
1981 void prism2sta_ev_infdrop(wlandevice_t *wlandev)
1984 hfa384x_t *hw = (hfa384x_t *)wlandev->priv;
1987 WLAN_LOG_DEBUG(3, "Info frame dropped due to card mem low.\n");
1993 /*----------------------------------------------------------------
1996 * Handles the Info event.
1999 * wlandev wlan device structure
2000 * inf ptr to a generic info frame
2009 ----------------------------------------------------------------*/
2010 void prism2sta_ev_info(wlandevice_t *wlandev, hfa384x_InfFrame_t *inf)
2013 inf->infotype = hfa384x2host_16(inf->infotype);
2015 switch ( inf->infotype ) {
2016 case HFA384x_IT_HANDOVERADDR:
2017 prism2sta_inf_handover(wlandev, inf);
2019 case HFA384x_IT_COMMTALLIES:
2020 prism2sta_inf_tallies(wlandev, inf);
2022 case HFA384x_IT_HOSTSCANRESULTS:
2023 prism2sta_inf_hostscanresults(wlandev, inf);
2025 case HFA384x_IT_SCANRESULTS:
2026 prism2sta_inf_scanresults(wlandev, inf);
2028 case HFA384x_IT_CHINFORESULTS:
2029 prism2sta_inf_chinforesults(wlandev, inf);
2031 case HFA384x_IT_LINKSTATUS:
2032 prism2sta_inf_linkstatus(wlandev, inf);
2034 case HFA384x_IT_ASSOCSTATUS:
2035 prism2sta_inf_assocstatus(wlandev, inf);
2037 case HFA384x_IT_AUTHREQ:
2038 prism2sta_inf_authreq(wlandev, inf);
2040 case HFA384x_IT_PSUSERCNT:
2041 prism2sta_inf_psusercnt(wlandev, inf);
2043 case HFA384x_IT_KEYIDCHANGED:
2044 WLAN_LOG_WARNING("Unhandled IT_KEYIDCHANGED\n");
2046 case HFA384x_IT_ASSOCREQ:
2047 WLAN_LOG_WARNING("Unhandled IT_ASSOCREQ\n");
2049 case HFA384x_IT_MICFAILURE:
2050 WLAN_LOG_WARNING("Unhandled IT_MICFAILURE\n");
2054 "Unknown info type=0x%02x\n", inf->infotype);
2062 /*----------------------------------------------------------------
2063 * prism2sta_ev_txexc
2065 * Handles the TxExc event. A Transmit Exception event indicates
2066 * that the MAC's TX process was unsuccessful - so the packet did
2067 * not get transmitted.
2070 * wlandev wlan device structure
2071 * status tx frame status word
2080 ----------------------------------------------------------------*/
2081 void prism2sta_ev_txexc(wlandevice_t *wlandev, UINT16 status)
2085 WLAN_LOG_DEBUG(3, "TxExc status=0x%x.\n", status);
2092 /*----------------------------------------------------------------
2095 * Handles the Tx event.
2098 * wlandev wlan device structure
2099 * status tx frame status word
2107 ----------------------------------------------------------------*/
2108 void prism2sta_ev_tx(wlandevice_t *wlandev, UINT16 status)
2111 WLAN_LOG_DEBUG(4, "Tx Complete, status=0x%04x\n", status);
2112 /* update linux network stats */
2113 wlandev->linux_stats.tx_packets++;
2119 /*----------------------------------------------------------------
2122 * Handles the Rx event.
2125 * wlandev wlan device structure
2134 ----------------------------------------------------------------*/
2135 void prism2sta_ev_rx(wlandevice_t *wlandev, struct sk_buff *skb)
2139 p80211netdev_rx(wlandev, skb);
2145 /*----------------------------------------------------------------
2146 * prism2sta_ev_alloc
2148 * Handles the Alloc event.
2151 * wlandev wlan device structure
2160 ----------------------------------------------------------------*/
2161 void prism2sta_ev_alloc(wlandevice_t *wlandev)
2165 p80211netdev_wake_queue(wlandev);
2171 /*----------------------------------------------------------------
2174 * Called at module init time. This creates the wlandevice_t structure
2175 * and initializes it with relevant bits.
2181 * the created wlandevice_t structure.
2184 * also allocates the priv/hw structures.
2189 ----------------------------------------------------------------*/
2190 static wlandevice_t *create_wlan(void)
2192 wlandevice_t *wlandev = NULL;
2193 hfa384x_t *hw = NULL;
2195 /* Alloc our structures */
2196 wlandev = kmalloc(sizeof(wlandevice_t), GFP_KERNEL);
2197 hw = kmalloc(sizeof(hfa384x_t), GFP_KERNEL);
2199 if (!wlandev || !hw) {
2200 WLAN_LOG_ERROR("%s: Memory allocation failure.\n", dev_info);
2201 if (wlandev) kfree(wlandev);
2206 /* Clear all the structs */
2207 memset(wlandev, 0, sizeof(wlandevice_t));
2208 memset(hw, 0, sizeof(hfa384x_t));
2210 /* Initialize the network device object. */
2211 wlandev->nsdname = dev_info;
2212 wlandev->msdstate = WLAN_MSD_HWPRESENT_PENDING;
2214 wlandev->open = prism2sta_open;
2215 wlandev->close = prism2sta_close;
2216 wlandev->reset = prism2sta_reset;
2217 #ifdef CONFIG_PROC_FS
2218 wlandev->nsd_proc_read = prism2sta_proc_read;
2220 wlandev->txframe = prism2sta_txframe;
2221 wlandev->mlmerequest = prism2sta_mlmerequest;
2222 wlandev->set_multicast_list = prism2sta_setmulticast;
2223 wlandev->tx_timeout = hfa384x_tx_timeout;
2225 wlandev->nsdcaps = P80211_NSDCAP_HWFRAGMENT |
2226 P80211_NSDCAP_AUTOJOIN;
2228 /* Initialize the device private data stucture. */
2229 hw->dot11_desired_bss_type = 1;
2234 #ifdef CONFIG_PROC_FS
2236 prism2sta_proc_read(
2245 wlandevice_t *wlandev = (wlandevice_t *) data;
2246 hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
2256 // XXX 0x0001 for prism2.5/3, 0x0000 for prism2.
2259 p += sprintf(p, "# %s version %s (%s)\n\n",
2261 WLAN_RELEASE, WLAN_BUILD_DATE);
2263 p += sprintf(p, "# nic h/w: id=0x%02x %d.%d.%d\n",
2264 hw->ident_nic.id, hw->ident_nic.major,
2265 hw->ident_nic.minor, hw->ident_nic.variant);
2267 p += sprintf(p, "# pri f/w: id=0x%02x %d.%d.%d\n",
2268 hw->ident_pri_fw.id, hw->ident_pri_fw.major,
2269 hw->ident_pri_fw.minor, hw->ident_pri_fw.variant);
2271 if (hw->ident_sta_fw.id == 0x1f) {
2272 p += sprintf(p, "# sta f/w: id=0x%02x %d.%d.%d\n",
2273 hw->ident_sta_fw.id, hw->ident_sta_fw.major,
2274 hw->ident_sta_fw.minor, hw->ident_sta_fw.variant);
2276 p += sprintf(p, "# ap f/w: id=0x%02x %d.%d.%d\n",
2277 hw->ident_sta_fw.id, hw->ident_sta_fw.major,
2278 hw->ident_sta_fw.minor, hw->ident_sta_fw.variant);
2287 void prism2sta_commsqual_defer(struct work_struct *data)
2289 hfa384x_t *hw = container_of(data, struct hfa384x, commsqual_bh);
2290 wlandevice_t *wlandev = hw->wlandev;
2291 hfa384x_bytestr32_t ssid;
2296 if (hw->wlandev->hwremoved)
2299 /* we don't care if we're in AP mode */
2300 if ((wlandev->macmode == WLAN_MACMODE_NONE) ||
2301 (wlandev->macmode == WLAN_MACMODE_ESS_AP)) {
2305 /* It only makes sense to poll these in non-IBSS */
2306 if (wlandev->macmode != WLAN_MACMODE_IBSS_STA) {
2307 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_DBMCOMMSQUALITY,
2309 HFA384x_RID_DBMCOMMSQUALITY_LEN);
2312 WLAN_LOG_ERROR("error fetching commsqual\n");
2316 // qual.CQ_currBSS; // link
2317 // ASL_currBSS; // level
2318 // qual.ANL_currFC; // noise
2320 WLAN_LOG_DEBUG(3, "commsqual %d %d %d\n",
2321 hfa384x2host_16(hw->qual.CQ_currBSS),
2322 hfa384x2host_16(hw->qual.ASL_currBSS),
2323 hfa384x2host_16(hw->qual.ANL_currFC));
2326 /* Lastly, we need to make sure the BSSID didn't change on us */
2327 result = hfa384x_drvr_getconfig(hw,
2328 HFA384x_RID_CURRENTBSSID,
2329 wlandev->bssid, WLAN_BSSID_LEN);
2332 "getconfig(0x%02x) failed, result = %d\n",
2333 HFA384x_RID_CURRENTBSSID, result);
2337 result = hfa384x_drvr_getconfig(hw,
2338 HFA384x_RID_CURRENTSSID,
2339 &ssid, sizeof(ssid));
2342 "getconfig(0x%02x) failed, result = %d\n",
2343 HFA384x_RID_CURRENTSSID, result);
2346 prism2mgmt_bytestr2pstr((hfa384x_bytestr_t *)&ssid,
2347 (p80211pstrd_t *) &wlandev->ssid);
2350 /* Reschedule timer */
2351 mod_timer(&hw->commsqual_timer, jiffies + HZ);
2357 void prism2sta_commsqual_timer(unsigned long data)
2359 hfa384x_t *hw = (hfa384x_t *) data;
2363 schedule_work(&hw->commsqual_bh);