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 #include <linux/version.h>
54 #include <linux/module.h>
55 #include <linux/moduleparam.h>
56 #include <linux/kernel.h>
57 #include <linux/sched.h>
58 #include <linux/types.h>
59 #include <linux/init.h>
60 #include <linux/slab.h>
61 #include <linux/wireless.h>
62 #include <linux/netdevice.h>
63 #include <linux/workqueue.h>
64 #include <linux/byteorder/generic.h>
65 #include <linux/ctype.h>
68 #include <linux/delay.h>
69 #include <asm/byteorder.h>
70 #include <linux/if_arp.h>
71 #include <linux/if_ether.h>
72 #include <linux/bitops.h>
74 #include "wlan_compat.h"
76 /*================================================================*/
77 /* Project Includes */
79 #include "p80211types.h"
80 #include "p80211hdr.h"
81 #include "p80211mgmt.h"
82 #include "p80211conv.h"
83 #include "p80211msg.h"
84 #include "p80211netdev.h"
85 #include "p80211req.h"
86 #include "p80211metadef.h"
87 #include "p80211metastruct.h"
89 #include "prism2mgmt.h"
91 #define wlan_hexchar(x) (((x) < 0x0a) ? ('0' + (x)) : ('a' + ((x) - 0x0a)))
93 /* Create a string of printable chars from something that might not be */
94 /* It's recommended that the str be 4*len + 1 bytes long */
95 #define wlan_mkprintstr(buf, buflen, str, strlen) \
99 memset(str, 0, (strlen)); \
100 for (i = 0; i < (buflen); i++) { \
101 if (isprint((buf)[i])) { \
102 (str)[j] = (buf)[i]; \
107 (str)[j+2] = wlan_hexchar(((buf)[i] & 0xf0) >> 4); \
108 (str)[j+3] = wlan_hexchar(((buf)[i] & 0x0f)); \
114 static char *dev_info = "prism2_usb";
115 static wlandevice_t *create_wlan(void);
117 int prism2_reset_holdtime = 30; /* Reset hold time in ms */
118 int prism2_reset_settletime = 100; /* Reset settle time in ms */
120 static int prism2_doreset = 0; /* Do a reset at init? */
122 module_param(prism2_doreset, int, 0644);
123 MODULE_PARM_DESC(prism2_doreset, "Issue a reset on initialization");
125 module_param(prism2_reset_holdtime, int, 0644);
126 MODULE_PARM_DESC(prism2_reset_holdtime, "reset hold time in ms");
127 module_param(prism2_reset_settletime, int, 0644);
128 MODULE_PARM_DESC(prism2_reset_settletime, "reset settle time in ms");
130 MODULE_LICENSE("Dual MPL/GPL");
132 static int prism2sta_open(wlandevice_t *wlandev);
133 static int prism2sta_close(wlandevice_t *wlandev);
134 static void prism2sta_reset(wlandevice_t *wlandev);
135 static int prism2sta_txframe(wlandevice_t *wlandev, struct sk_buff *skb,
136 p80211_hdr_t *p80211_hdr,
137 p80211_metawep_t *p80211_wep);
138 static int prism2sta_mlmerequest(wlandevice_t *wlandev, p80211msg_t *msg);
139 static int prism2sta_getcardinfo(wlandevice_t *wlandev);
140 static int prism2sta_globalsetup(wlandevice_t *wlandev);
141 static int prism2sta_setmulticast(wlandevice_t *wlandev, netdevice_t *dev);
143 static void prism2sta_inf_handover(wlandevice_t *wlandev,
144 hfa384x_InfFrame_t *inf);
145 static void prism2sta_inf_tallies(wlandevice_t *wlandev,
146 hfa384x_InfFrame_t *inf);
147 static void prism2sta_inf_hostscanresults(wlandevice_t *wlandev,
148 hfa384x_InfFrame_t *inf);
149 static void prism2sta_inf_scanresults(wlandevice_t *wlandev,
150 hfa384x_InfFrame_t *inf);
151 static void prism2sta_inf_chinforesults(wlandevice_t *wlandev,
152 hfa384x_InfFrame_t *inf);
153 static void prism2sta_inf_linkstatus(wlandevice_t *wlandev,
154 hfa384x_InfFrame_t *inf);
155 static void prism2sta_inf_assocstatus(wlandevice_t *wlandev,
156 hfa384x_InfFrame_t *inf);
157 static void prism2sta_inf_authreq(wlandevice_t *wlandev,
158 hfa384x_InfFrame_t *inf);
159 static void prism2sta_inf_authreq_defer(wlandevice_t *wlandev,
160 hfa384x_InfFrame_t *inf);
161 static void prism2sta_inf_psusercnt(wlandevice_t *wlandev,
162 hfa384x_InfFrame_t *inf);
164 /*----------------------------------------------------------------
167 * WLAN device open method. Called from p80211netdev when kernel
168 * device open (start) method is called in response to the
169 * SIOCSIIFFLAGS ioctl changing the flags bit IFF_UP
173 * wlandev wlan device structure
177 * >0 f/w reported error
178 * <0 driver reported error
184 ----------------------------------------------------------------*/
185 static int prism2sta_open(wlandevice_t *wlandev)
187 /* We don't currently have to do anything else.
188 * The setup of the MAC should be subsequently completed via
190 * Higher layers know we're ready from dev->start==1 and
191 * dev->tbusy==0. Our rx path knows to pass up received/
192 * frames because of dev->flags&IFF_UP is true.
198 /*----------------------------------------------------------------
201 * WLAN device close method. Called from p80211netdev when kernel
202 * device close method is called in response to the
203 * SIOCSIIFFLAGS ioctl changing the flags bit IFF_UP
207 * wlandev wlan device structure
211 * >0 f/w reported error
212 * <0 driver reported error
218 ----------------------------------------------------------------*/
219 static int prism2sta_close(wlandevice_t *wlandev)
221 /* We don't currently have to do anything else.
222 * Higher layers know we're not ready from dev->start==0 and
223 * dev->tbusy==1. Our rx path knows to not pass up received
224 * frames because of dev->flags&IFF_UP is false.
230 /*----------------------------------------------------------------
233 * Not currently implented.
236 * wlandev wlan device structure
246 ----------------------------------------------------------------*/
247 static void prism2sta_reset(wlandevice_t *wlandev)
252 /*----------------------------------------------------------------
255 * Takes a frame from p80211 and queues it for transmission.
258 * wlandev wlan device structure
259 * pb packet buffer struct. Contains an 802.11
261 * p80211_hdr points to the 802.11 header for the packet.
263 * 0 Success and more buffs available
264 * 1 Success but no more buffs
265 * 2 Allocation failure
266 * 4 Buffer full or queue busy
272 ----------------------------------------------------------------*/
273 static int prism2sta_txframe(wlandevice_t *wlandev, struct sk_buff *skb,
274 p80211_hdr_t *p80211_hdr,
275 p80211_metawep_t *p80211_wep)
277 hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
280 /* If necessary, set the 802.11 WEP bit */
281 if ((wlandev->hostwep & (HOSTWEP_PRIVACYINVOKED | HOSTWEP_ENCRYPT)) ==
282 HOSTWEP_PRIVACYINVOKED) {
283 p80211_hdr->a3.fc |= cpu_to_le16(WLAN_SET_FC_ISWEP(1));
286 result = hfa384x_drvr_txframe(hw, skb, p80211_hdr, p80211_wep);
291 /*----------------------------------------------------------------
292 * prism2sta_mlmerequest
294 * wlan command message handler. All we do here is pass the message
295 * over to the prism2sta_mgmt_handler.
298 * wlandev wlan device structure
299 * msg wlan command message
302 * <0 successful acceptance of message, but we're
303 * waiting for an async process to finish before
304 * we're done with the msg. When the asynch
305 * process is done, we'll call the p80211
306 * function p80211req_confirm() .
307 * >0 An error occurred while we were handling
314 ----------------------------------------------------------------*/
315 static int prism2sta_mlmerequest(wlandevice_t *wlandev, p80211msg_t *msg)
317 hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
321 switch (msg->msgcode) {
322 case DIDmsg_dot11req_mibget:
323 pr_debug("Received mibget request\n");
324 result = prism2mgmt_mibset_mibget(wlandev, msg);
326 case DIDmsg_dot11req_mibset:
327 pr_debug("Received mibset request\n");
328 result = prism2mgmt_mibset_mibget(wlandev, msg);
330 case DIDmsg_dot11req_scan:
331 pr_debug("Received scan request\n");
332 result = prism2mgmt_scan(wlandev, msg);
334 case DIDmsg_dot11req_scan_results:
335 pr_debug("Received scan_results request\n");
336 result = prism2mgmt_scan_results(wlandev, msg);
338 case DIDmsg_dot11req_start:
339 pr_debug("Received mlme start request\n");
340 result = prism2mgmt_start(wlandev, msg);
343 * Prism2 specific messages
345 case DIDmsg_p2req_readpda:
346 pr_debug("Received mlme readpda request\n");
347 result = prism2mgmt_readpda(wlandev, msg);
349 case DIDmsg_p2req_ramdl_state:
350 pr_debug("Received mlme ramdl_state request\n");
351 result = prism2mgmt_ramdl_state(wlandev, msg);
353 case DIDmsg_p2req_ramdl_write:
354 pr_debug("Received mlme ramdl_write request\n");
355 result = prism2mgmt_ramdl_write(wlandev, msg);
357 case DIDmsg_p2req_flashdl_state:
358 pr_debug("Received mlme flashdl_state request\n");
359 result = prism2mgmt_flashdl_state(wlandev, msg);
361 case DIDmsg_p2req_flashdl_write:
362 pr_debug("Received mlme flashdl_write request\n");
363 result = prism2mgmt_flashdl_write(wlandev, msg);
366 * Linux specific messages
368 case DIDmsg_lnxreq_hostwep:
369 break; /* ignore me. */
370 case DIDmsg_lnxreq_ifstate:
372 p80211msg_lnxreq_ifstate_t *ifstatemsg;
373 pr_debug("Received mlme ifstate request\n");
374 ifstatemsg = (p80211msg_lnxreq_ifstate_t *) msg;
376 prism2sta_ifstate(wlandev,
377 ifstatemsg->ifstate.data);
378 ifstatemsg->resultcode.status =
379 P80211ENUM_msgitem_status_data_ok;
380 ifstatemsg->resultcode.data = result;
384 case DIDmsg_lnxreq_wlansniff:
385 pr_debug("Received mlme wlansniff request\n");
386 result = prism2mgmt_wlansniff(wlandev, msg);
388 case DIDmsg_lnxreq_autojoin:
389 pr_debug("Received mlme autojoin request\n");
390 result = prism2mgmt_autojoin(wlandev, msg);
392 case DIDmsg_lnxreq_commsquality:{
393 p80211msg_lnxreq_commsquality_t *qualmsg;
395 pr_debug("Received commsquality request\n");
397 qualmsg = (p80211msg_lnxreq_commsquality_t *) msg;
399 qualmsg->link.status =
400 P80211ENUM_msgitem_status_data_ok;
401 qualmsg->level.status =
402 P80211ENUM_msgitem_status_data_ok;
403 qualmsg->noise.status =
404 P80211ENUM_msgitem_status_data_ok;
407 hfa384x2host_16(hw->qual.CQ_currBSS);
408 qualmsg->level.data =
409 hfa384x2host_16(hw->qual.ASL_currBSS);
410 qualmsg->noise.data =
411 hfa384x2host_16(hw->qual.ANL_currFC);
416 printk(KERN_WARNING "Unknown mgmt request message 0x%08x",
424 /*----------------------------------------------------------------
427 * Interface state. This is the primary WLAN interface enable/disable
428 * handler. Following the driver/load/deviceprobe sequence, this
429 * function must be called with a state of "enable" before any other
430 * commands will be accepted.
433 * wlandev wlan device structure
434 * msgp ptr to msg buffer
437 * A p80211 message resultcode value.
442 * process thread (usually)
444 ----------------------------------------------------------------*/
445 u32 prism2sta_ifstate(wlandevice_t *wlandev, u32 ifstate)
447 hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
450 result = P80211ENUM_resultcode_implementation_failure;
452 pr_debug("Current MSD state(%d), requesting(%d)\n",
453 wlandev->msdstate, ifstate);
455 case P80211ENUM_ifstate_fwload:
456 switch (wlandev->msdstate) {
457 case WLAN_MSD_HWPRESENT:
458 wlandev->msdstate = WLAN_MSD_FWLOAD_PENDING;
460 * Initialize the device+driver sufficiently
461 * for firmware loading.
463 if ((result = hfa384x_drvr_start(hw))) {
465 "hfa384x_drvr_start() failed,"
466 "result=%d\n", (int)result);
468 P80211ENUM_resultcode_implementation_failure;
469 wlandev->msdstate = WLAN_MSD_HWPRESENT;
472 wlandev->msdstate = WLAN_MSD_FWLOAD;
473 result = P80211ENUM_resultcode_success;
475 case WLAN_MSD_FWLOAD:
476 hfa384x_cmd_initialize(hw);
477 result = P80211ENUM_resultcode_success;
479 case WLAN_MSD_RUNNING:
481 "Cannot enter fwload state from enable state,"
482 "you must disable first.\n");
483 result = P80211ENUM_resultcode_invalid_parameters;
485 case WLAN_MSD_HWFAIL:
487 /* probe() had a problem or the msdstate contains
488 * an unrecognized value, there's nothing we can do.
490 result = P80211ENUM_resultcode_implementation_failure;
494 case P80211ENUM_ifstate_enable:
495 switch (wlandev->msdstate) {
496 case WLAN_MSD_HWPRESENT:
497 case WLAN_MSD_FWLOAD:
498 wlandev->msdstate = WLAN_MSD_RUNNING_PENDING;
499 /* Initialize the device+driver for full
500 * operation. Note that this might me an FWLOAD to
501 * to RUNNING transition so we must not do a chip
502 * or board level reset. Note that on failure,
503 * the MSD state is set to HWPRESENT because we
504 * can't make any assumptions about the state
505 * of the hardware or a previous firmware load.
507 if ((result = hfa384x_drvr_start(hw))) {
509 "hfa384x_drvr_start() failed,"
510 "result=%d\n", (int)result);
512 P80211ENUM_resultcode_implementation_failure;
513 wlandev->msdstate = WLAN_MSD_HWPRESENT;
517 if ((result = prism2sta_getcardinfo(wlandev))) {
519 "prism2sta_getcardinfo() failed,"
520 "result=%d\n", (int)result);
522 P80211ENUM_resultcode_implementation_failure;
523 hfa384x_drvr_stop(hw);
524 wlandev->msdstate = WLAN_MSD_HWPRESENT;
527 if ((result = prism2sta_globalsetup(wlandev))) {
529 "prism2sta_globalsetup() failed,"
530 "result=%d\n", (int)result);
532 P80211ENUM_resultcode_implementation_failure;
533 hfa384x_drvr_stop(hw);
534 wlandev->msdstate = WLAN_MSD_HWPRESENT;
537 wlandev->msdstate = WLAN_MSD_RUNNING;
539 hw->join_retries = 60;
540 result = P80211ENUM_resultcode_success;
542 case WLAN_MSD_RUNNING:
543 /* Do nothing, we're already in this state. */
544 result = P80211ENUM_resultcode_success;
546 case WLAN_MSD_HWFAIL:
548 /* probe() had a problem or the msdstate contains
549 * an unrecognized value, there's nothing we can do.
551 result = P80211ENUM_resultcode_implementation_failure;
555 case P80211ENUM_ifstate_disable:
556 switch (wlandev->msdstate) {
557 case WLAN_MSD_HWPRESENT:
558 /* Do nothing, we're already in this state. */
559 result = P80211ENUM_resultcode_success;
561 case WLAN_MSD_FWLOAD:
562 case WLAN_MSD_RUNNING:
563 wlandev->msdstate = WLAN_MSD_HWPRESENT_PENDING;
565 * TODO: Shut down the MAC completely. Here a chip
566 * or board level reset is probably called for.
567 * After a "disable" _all_ results are lost, even
568 * those from a fwload.
570 if (!wlandev->hwremoved)
571 netif_carrier_off(wlandev->netdev);
573 hfa384x_drvr_stop(hw);
575 wlandev->macmode = WLAN_MACMODE_NONE;
576 wlandev->msdstate = WLAN_MSD_HWPRESENT;
577 result = P80211ENUM_resultcode_success;
579 case WLAN_MSD_HWFAIL:
581 /* probe() had a problem or the msdstate contains
582 * an unrecognized value, there's nothing we can do.
584 result = P80211ENUM_resultcode_implementation_failure;
589 result = P80211ENUM_resultcode_invalid_parameters;
596 /*----------------------------------------------------------------
597 * prism2sta_getcardinfo
599 * Collect the NICID, firmware version and any other identifiers
600 * we'd like to have in host-side data structures.
603 * wlandev wlan device structure
607 * >0 f/w reported error
608 * <0 driver reported error
614 ----------------------------------------------------------------*/
615 static int prism2sta_getcardinfo(wlandevice_t *wlandev)
618 hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
620 u8 snum[HFA384x_RID_NICSERIALNUMBER_LEN];
621 char pstr[(HFA384x_RID_NICSERIALNUMBER_LEN * 4) + 1];
623 /* Collect version and compatibility info */
624 /* Some are critical, some are not */
626 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_NICIDENTITY,
628 sizeof(hfa384x_compident_t));
630 printk(KERN_ERR "Failed to retrieve NICIDENTITY\n");
634 /* get all the nic id fields in host byte order */
635 hw->ident_nic.id = hfa384x2host_16(hw->ident_nic.id);
636 hw->ident_nic.variant = hfa384x2host_16(hw->ident_nic.variant);
637 hw->ident_nic.major = hfa384x2host_16(hw->ident_nic.major);
638 hw->ident_nic.minor = hfa384x2host_16(hw->ident_nic.minor);
640 printk(KERN_INFO "ident: nic h/w: id=0x%02x %d.%d.%d\n",
641 hw->ident_nic.id, hw->ident_nic.major,
642 hw->ident_nic.minor, hw->ident_nic.variant);
644 /* Primary f/w identity */
645 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_PRIIDENTITY,
647 sizeof(hfa384x_compident_t));
649 printk(KERN_ERR "Failed to retrieve PRIIDENTITY\n");
653 /* get all the private fw id fields in host byte order */
654 hw->ident_pri_fw.id = hfa384x2host_16(hw->ident_pri_fw.id);
655 hw->ident_pri_fw.variant = hfa384x2host_16(hw->ident_pri_fw.variant);
656 hw->ident_pri_fw.major = hfa384x2host_16(hw->ident_pri_fw.major);
657 hw->ident_pri_fw.minor = hfa384x2host_16(hw->ident_pri_fw.minor);
659 printk(KERN_INFO "ident: pri f/w: id=0x%02x %d.%d.%d\n",
660 hw->ident_pri_fw.id, hw->ident_pri_fw.major,
661 hw->ident_pri_fw.minor, hw->ident_pri_fw.variant);
663 /* Station (Secondary?) f/w identity */
664 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_STAIDENTITY,
666 sizeof(hfa384x_compident_t));
668 printk(KERN_ERR "Failed to retrieve STAIDENTITY\n");
672 if (hw->ident_nic.id < 0x8000) {
674 "FATAL: Card is not an Intersil Prism2/2.5/3\n");
679 /* get all the station fw id fields in host byte order */
680 hw->ident_sta_fw.id = hfa384x2host_16(hw->ident_sta_fw.id);
681 hw->ident_sta_fw.variant = hfa384x2host_16(hw->ident_sta_fw.variant);
682 hw->ident_sta_fw.major = hfa384x2host_16(hw->ident_sta_fw.major);
683 hw->ident_sta_fw.minor = hfa384x2host_16(hw->ident_sta_fw.minor);
685 /* strip out the 'special' variant bits */
686 hw->mm_mods = hw->ident_sta_fw.variant & (BIT(14) | BIT(15));
687 hw->ident_sta_fw.variant &= ~((u16) (BIT(14) | BIT(15)));
689 if (hw->ident_sta_fw.id == 0x1f) {
691 "ident: sta f/w: id=0x%02x %d.%d.%d\n",
692 hw->ident_sta_fw.id, hw->ident_sta_fw.major,
693 hw->ident_sta_fw.minor, hw->ident_sta_fw.variant);
696 "ident: ap f/w: id=0x%02x %d.%d.%d\n",
697 hw->ident_sta_fw.id, hw->ident_sta_fw.major,
698 hw->ident_sta_fw.minor, hw->ident_sta_fw.variant);
699 printk(KERN_ERR "Unsupported Tertiary AP firmeare loaded!\n");
703 /* Compatibility range, Modem supplier */
704 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_MFISUPRANGE,
706 sizeof(hfa384x_caplevel_t));
708 printk(KERN_ERR "Failed to retrieve MFISUPRANGE\n");
712 /* get all the Compatibility range, modem interface supplier
713 fields in byte order */
714 hw->cap_sup_mfi.role = hfa384x2host_16(hw->cap_sup_mfi.role);
715 hw->cap_sup_mfi.id = hfa384x2host_16(hw->cap_sup_mfi.id);
716 hw->cap_sup_mfi.variant = hfa384x2host_16(hw->cap_sup_mfi.variant);
717 hw->cap_sup_mfi.bottom = hfa384x2host_16(hw->cap_sup_mfi.bottom);
718 hw->cap_sup_mfi.top = hfa384x2host_16(hw->cap_sup_mfi.top);
721 "MFI:SUP:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
722 hw->cap_sup_mfi.role, hw->cap_sup_mfi.id,
723 hw->cap_sup_mfi.variant, hw->cap_sup_mfi.bottom,
724 hw->cap_sup_mfi.top);
726 /* Compatibility range, Controller supplier */
727 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_CFISUPRANGE,
729 sizeof(hfa384x_caplevel_t));
731 printk(KERN_ERR "Failed to retrieve CFISUPRANGE\n");
735 /* get all the Compatibility range, controller interface supplier
736 fields in byte order */
737 hw->cap_sup_cfi.role = hfa384x2host_16(hw->cap_sup_cfi.role);
738 hw->cap_sup_cfi.id = hfa384x2host_16(hw->cap_sup_cfi.id);
739 hw->cap_sup_cfi.variant = hfa384x2host_16(hw->cap_sup_cfi.variant);
740 hw->cap_sup_cfi.bottom = hfa384x2host_16(hw->cap_sup_cfi.bottom);
741 hw->cap_sup_cfi.top = hfa384x2host_16(hw->cap_sup_cfi.top);
744 "CFI:SUP:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
745 hw->cap_sup_cfi.role, hw->cap_sup_cfi.id,
746 hw->cap_sup_cfi.variant, hw->cap_sup_cfi.bottom,
747 hw->cap_sup_cfi.top);
749 /* Compatibility range, Primary f/w supplier */
750 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_PRISUPRANGE,
752 sizeof(hfa384x_caplevel_t));
754 printk(KERN_ERR "Failed to retrieve PRISUPRANGE\n");
758 /* get all the Compatibility range, primary firmware supplier
759 fields in byte order */
760 hw->cap_sup_pri.role = hfa384x2host_16(hw->cap_sup_pri.role);
761 hw->cap_sup_pri.id = hfa384x2host_16(hw->cap_sup_pri.id);
762 hw->cap_sup_pri.variant = hfa384x2host_16(hw->cap_sup_pri.variant);
763 hw->cap_sup_pri.bottom = hfa384x2host_16(hw->cap_sup_pri.bottom);
764 hw->cap_sup_pri.top = hfa384x2host_16(hw->cap_sup_pri.top);
767 "PRI:SUP:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
768 hw->cap_sup_pri.role, hw->cap_sup_pri.id,
769 hw->cap_sup_pri.variant, hw->cap_sup_pri.bottom,
770 hw->cap_sup_pri.top);
772 /* Compatibility range, Station f/w supplier */
773 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_STASUPRANGE,
775 sizeof(hfa384x_caplevel_t));
777 printk(KERN_ERR "Failed to retrieve STASUPRANGE\n");
781 /* get all the Compatibility range, station firmware supplier
782 fields in byte order */
783 hw->cap_sup_sta.role = hfa384x2host_16(hw->cap_sup_sta.role);
784 hw->cap_sup_sta.id = hfa384x2host_16(hw->cap_sup_sta.id);
785 hw->cap_sup_sta.variant = hfa384x2host_16(hw->cap_sup_sta.variant);
786 hw->cap_sup_sta.bottom = hfa384x2host_16(hw->cap_sup_sta.bottom);
787 hw->cap_sup_sta.top = hfa384x2host_16(hw->cap_sup_sta.top);
789 if (hw->cap_sup_sta.id == 0x04) {
791 "STA:SUP:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
792 hw->cap_sup_sta.role, hw->cap_sup_sta.id,
793 hw->cap_sup_sta.variant, hw->cap_sup_sta.bottom,
794 hw->cap_sup_sta.top);
797 "AP:SUP:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
798 hw->cap_sup_sta.role, hw->cap_sup_sta.id,
799 hw->cap_sup_sta.variant, hw->cap_sup_sta.bottom,
800 hw->cap_sup_sta.top);
803 /* Compatibility range, primary f/w actor, CFI supplier */
804 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_PRI_CFIACTRANGES,
805 &hw->cap_act_pri_cfi,
806 sizeof(hfa384x_caplevel_t));
808 printk(KERN_ERR "Failed to retrieve PRI_CFIACTRANGES\n");
812 /* get all the Compatibility range, primary f/w actor, CFI supplier
813 fields in byte order */
814 hw->cap_act_pri_cfi.role = hfa384x2host_16(hw->cap_act_pri_cfi.role);
815 hw->cap_act_pri_cfi.id = hfa384x2host_16(hw->cap_act_pri_cfi.id);
816 hw->cap_act_pri_cfi.variant =
817 hfa384x2host_16(hw->cap_act_pri_cfi.variant);
818 hw->cap_act_pri_cfi.bottom =
819 hfa384x2host_16(hw->cap_act_pri_cfi.bottom);
820 hw->cap_act_pri_cfi.top = hfa384x2host_16(hw->cap_act_pri_cfi.top);
823 "PRI-CFI:ACT:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
824 hw->cap_act_pri_cfi.role, hw->cap_act_pri_cfi.id,
825 hw->cap_act_pri_cfi.variant, hw->cap_act_pri_cfi.bottom,
826 hw->cap_act_pri_cfi.top);
828 /* Compatibility range, sta f/w actor, CFI supplier */
829 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_STA_CFIACTRANGES,
830 &hw->cap_act_sta_cfi,
831 sizeof(hfa384x_caplevel_t));
833 printk(KERN_ERR "Failed to retrieve STA_CFIACTRANGES\n");
837 /* get all the Compatibility range, station f/w actor, CFI supplier
838 fields in byte order */
839 hw->cap_act_sta_cfi.role = hfa384x2host_16(hw->cap_act_sta_cfi.role);
840 hw->cap_act_sta_cfi.id = hfa384x2host_16(hw->cap_act_sta_cfi.id);
841 hw->cap_act_sta_cfi.variant =
842 hfa384x2host_16(hw->cap_act_sta_cfi.variant);
843 hw->cap_act_sta_cfi.bottom =
844 hfa384x2host_16(hw->cap_act_sta_cfi.bottom);
845 hw->cap_act_sta_cfi.top = hfa384x2host_16(hw->cap_act_sta_cfi.top);
848 "STA-CFI:ACT:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
849 hw->cap_act_sta_cfi.role, hw->cap_act_sta_cfi.id,
850 hw->cap_act_sta_cfi.variant, hw->cap_act_sta_cfi.bottom,
851 hw->cap_act_sta_cfi.top);
853 /* Compatibility range, sta f/w actor, MFI supplier */
854 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_STA_MFIACTRANGES,
855 &hw->cap_act_sta_mfi,
856 sizeof(hfa384x_caplevel_t));
858 printk(KERN_ERR "Failed to retrieve STA_MFIACTRANGES\n");
862 /* get all the Compatibility range, station f/w actor, MFI supplier
863 fields in byte order */
864 hw->cap_act_sta_mfi.role = hfa384x2host_16(hw->cap_act_sta_mfi.role);
865 hw->cap_act_sta_mfi.id = hfa384x2host_16(hw->cap_act_sta_mfi.id);
866 hw->cap_act_sta_mfi.variant =
867 hfa384x2host_16(hw->cap_act_sta_mfi.variant);
868 hw->cap_act_sta_mfi.bottom =
869 hfa384x2host_16(hw->cap_act_sta_mfi.bottom);
870 hw->cap_act_sta_mfi.top = hfa384x2host_16(hw->cap_act_sta_mfi.top);
873 "STA-MFI:ACT:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
874 hw->cap_act_sta_mfi.role, hw->cap_act_sta_mfi.id,
875 hw->cap_act_sta_mfi.variant, hw->cap_act_sta_mfi.bottom,
876 hw->cap_act_sta_mfi.top);
879 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_NICSERIALNUMBER,
880 snum, HFA384x_RID_NICSERIALNUMBER_LEN);
882 wlan_mkprintstr(snum, HFA384x_RID_NICSERIALNUMBER_LEN,
884 printk(KERN_INFO "Prism2 card SN: %s\n", pstr);
886 printk(KERN_ERR "Failed to retrieve Prism2 Card SN\n");
890 /* Collect the MAC address */
891 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_CNFOWNMACADDR,
892 wlandev->netdev->dev_addr, ETH_ALEN);
894 printk(KERN_ERR "Failed to retrieve mac address\n");
898 /* short preamble is always implemented */
899 wlandev->nsdcaps |= P80211_NSDCAP_SHORT_PREAMBLE;
901 /* find out if hardware wep is implemented */
902 hfa384x_drvr_getconfig16(hw, HFA384x_RID_PRIVACYOPTIMP, &temp);
904 wlandev->nsdcaps |= P80211_NSDCAP_HARDWAREWEP;
906 /* get the dBm Scaling constant */
907 hfa384x_drvr_getconfig16(hw, HFA384x_RID_CNFDBMADJUST, &temp);
908 hw->dbmadjust = temp;
910 /* Only enable scan by default on newer firmware */
911 if (HFA384x_FIRMWARE_VERSION(hw->ident_sta_fw.major,
912 hw->ident_sta_fw.minor,
913 hw->ident_sta_fw.variant) <
914 HFA384x_FIRMWARE_VERSION(1, 5, 5)) {
915 wlandev->nsdcaps |= P80211_NSDCAP_NOSCAN;
918 /* TODO: Set any internally managed config items */
922 printk(KERN_ERR "Failed, result=%d\n", result);
927 /*----------------------------------------------------------------
928 * prism2sta_globalsetup
930 * Set any global RIDs that we want to set at device activation.
933 * wlandev wlan device structure
937 * >0 f/w reported error
938 * <0 driver reported error
944 ----------------------------------------------------------------*/
945 static int prism2sta_globalsetup(wlandevice_t *wlandev)
947 hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
949 /* Set the maximum frame size */
950 return hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFMAXDATALEN,
954 static int prism2sta_setmulticast(wlandevice_t *wlandev, netdevice_t *dev)
957 hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
961 /* If we're not ready, what's the point? */
962 if (hw->state != HFA384x_STATE_RUNNING)
965 if ((dev->flags & (IFF_PROMISC | IFF_ALLMULTI)) != 0)
966 promisc = P80211ENUM_truth_true;
968 promisc = P80211ENUM_truth_false;
971 hfa384x_drvr_setconfig16_async(hw, HFA384x_RID_PROMISCMODE,
977 /*----------------------------------------------------------------
978 * prism2sta_inf_handover
980 * Handles the receipt of a Handover info frame. Should only be present
984 * wlandev wlan device structure
985 * inf ptr to info frame (contents in hfa384x order)
994 ----------------------------------------------------------------*/
995 static void prism2sta_inf_handover(wlandevice_t *wlandev,
996 hfa384x_InfFrame_t *inf)
998 pr_debug("received infoframe:HANDOVER (unhandled)\n");
1002 /*----------------------------------------------------------------
1003 * prism2sta_inf_tallies
1005 * Handles the receipt of a CommTallies info frame.
1008 * wlandev wlan device structure
1009 * inf ptr to info frame (contents in hfa384x order)
1018 ----------------------------------------------------------------*/
1019 static void prism2sta_inf_tallies(wlandevice_t *wlandev,
1020 hfa384x_InfFrame_t *inf)
1022 hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
1030 ** Determine if these are 16-bit or 32-bit tallies, based on the
1031 ** record length of the info record.
1034 cnt = sizeof(hfa384x_CommTallies32_t) / sizeof(u32);
1035 if (inf->framelen > 22) {
1036 dst = (u32 *)&hw->tallies;
1037 src32 = (u32 *)&inf->info.commtallies32;
1038 for (i = 0; i < cnt; i++, dst++, src32++)
1039 *dst += hfa384x2host_32(*src32);
1041 dst = (u32 *)&hw->tallies;
1042 src16 = (u16 *)&inf->info.commtallies16;
1043 for (i = 0; i < cnt; i++, dst++, src16++)
1044 *dst += hfa384x2host_16(*src16);
1050 /*----------------------------------------------------------------
1051 * prism2sta_inf_scanresults
1053 * Handles the receipt of a Scan Results info frame.
1056 * wlandev wlan device structure
1057 * inf ptr to info frame (contents in hfa384x order)
1066 ----------------------------------------------------------------*/
1067 static void prism2sta_inf_scanresults(wlandevice_t *wlandev,
1068 hfa384x_InfFrame_t *inf)
1071 hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
1073 hfa384x_ScanResult_t *sr = &(inf->info.scanresult);
1075 hfa384x_JoinRequest_data_t joinreq;
1078 /* Get the number of results, first in bytes, then in results */
1079 nbss = (inf->framelen * sizeof(u16)) -
1080 sizeof(inf->infotype) - sizeof(inf->info.scanresult.scanreason);
1081 nbss /= sizeof(hfa384x_ScanResultSub_t);
1084 pr_debug("rx scanresults, reason=%d, nbss=%d:\n",
1085 inf->info.scanresult.scanreason, nbss);
1086 for (i = 0; i < nbss; i++) {
1087 pr_debug("chid=%d anl=%d sl=%d bcnint=%d\n",
1090 sr->result[i].sl, sr->result[i].bcnint);
1091 pr_debug(" capinfo=0x%04x proberesp_rate=%d\n",
1092 sr->result[i].capinfo, sr->result[i].proberesp_rate);
1094 /* issue a join request */
1095 joinreq.channel = sr->result[0].chid;
1096 memcpy(joinreq.bssid, sr->result[0].bssid, WLAN_BSSID_LEN);
1097 result = hfa384x_drvr_setconfig(hw,
1098 HFA384x_RID_JOINREQUEST,
1099 &joinreq, HFA384x_RID_JOINREQUEST_LEN);
1101 printk(KERN_ERR "setconfig(joinreq) failed, result=%d\n",
1108 /*----------------------------------------------------------------
1109 * prism2sta_inf_hostscanresults
1111 * Handles the receipt of a Scan Results info frame.
1114 * wlandev wlan device structure
1115 * inf ptr to info frame (contents in hfa384x order)
1124 ----------------------------------------------------------------*/
1125 static void prism2sta_inf_hostscanresults(wlandevice_t *wlandev,
1126 hfa384x_InfFrame_t *inf)
1128 hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
1131 nbss = (inf->framelen - 3) / 32;
1132 pr_debug("Received %d hostscan results\n", nbss);
1137 if (hw->scanresults)
1138 kfree(hw->scanresults);
1140 hw->scanresults = kmalloc(sizeof(hfa384x_InfFrame_t), GFP_ATOMIC);
1141 memcpy(hw->scanresults, inf, sizeof(hfa384x_InfFrame_t));
1146 /* Notify/wake the sleeping caller. */
1147 hw->scanflag = nbss;
1148 wake_up_interruptible(&hw->cmdq);
1151 /*----------------------------------------------------------------
1152 * prism2sta_inf_chinforesults
1154 * Handles the receipt of a Channel Info Results info frame.
1157 * wlandev wlan device structure
1158 * inf ptr to info frame (contents in hfa384x order)
1167 ----------------------------------------------------------------*/
1168 static void prism2sta_inf_chinforesults(wlandevice_t *wlandev,
1169 hfa384x_InfFrame_t *inf)
1171 hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
1174 hw->channel_info.results.scanchannels =
1175 hfa384x2host_16(inf->info.chinforesult.scanchannels);
1177 for (i = 0, n = 0; i < HFA384x_CHINFORESULT_MAX; i++) {
1178 if (hw->channel_info.results.scanchannels & (1 << i)) {
1180 hfa384x2host_16(inf->info.chinforesult.result[n].
1182 hfa384x_ChInfoResultSub_t *chinforesult =
1183 &hw->channel_info.results.result[channel];
1184 chinforesult->chid = channel;
1186 hfa384x2host_16(inf->info.chinforesult.result[n].
1189 hfa384x2host_16(inf->info.chinforesult.result[n].
1191 chinforesult->active =
1192 hfa384x2host_16(inf->info.chinforesult.result[n].
1195 "chinfo: channel %d, %s level (avg/peak)=%d/%d dB, pcf %d\n",
1198 active & HFA384x_CHINFORESULT_BSSACTIVE ?
1199 "signal" : "noise", chinforesult->anl,
1202 active & HFA384x_CHINFORESULT_PCFACTIVE ? 1 : 0);
1206 atomic_set(&hw->channel_info.done, 2);
1208 hw->channel_info.count = n;
1212 void prism2sta_processing_defer(struct work_struct *data)
1214 hfa384x_t *hw = container_of(data, struct hfa384x, link_bh);
1215 wlandevice_t *wlandev = hw->wlandev;
1216 hfa384x_bytestr32_t ssid;
1219 /* First let's process the auth frames */
1221 struct sk_buff *skb;
1222 hfa384x_InfFrame_t *inf;
1224 while ((skb = skb_dequeue(&hw->authq))) {
1225 inf = (hfa384x_InfFrame_t *) skb->data;
1226 prism2sta_inf_authreq_defer(wlandev, inf);
1231 /* Now let's handle the linkstatus stuff */
1232 if (hw->link_status == hw->link_status_new)
1235 hw->link_status = hw->link_status_new;
1237 switch (hw->link_status) {
1238 case HFA384x_LINK_NOTCONNECTED:
1239 /* I'm currently assuming that this is the initial link
1240 * state. It should only be possible immediately
1241 * following an Enable command.
1243 * Block Transmits, Ignore receives of data frames
1245 netif_carrier_off(wlandev->netdev);
1247 printk(KERN_INFO "linkstatus=NOTCONNECTED (unhandled)\n");
1250 case HFA384x_LINK_CONNECTED:
1251 /* This one indicates a successful scan/join/auth/assoc.
1252 * When we have the full MLME complement, this event will
1253 * signify successful completion of both mlme_authenticate
1254 * and mlme_associate. State management will get a little
1257 * Indicate authentication and/or association
1258 * Enable Transmits, Receives and pass up data frames
1261 netif_carrier_on(wlandev->netdev);
1263 /* If we are joining a specific AP, set our state and reset retries */
1264 if (hw->join_ap == 1)
1266 hw->join_retries = 60;
1268 /* Don't call this in monitor mode */
1269 if (wlandev->netdev->type == ARPHRD_ETHER) {
1272 printk(KERN_INFO "linkstatus=CONNECTED\n");
1274 /* For non-usb devices, we can use the sync versions */
1275 /* Collect the BSSID, and set state to allow tx */
1277 result = hfa384x_drvr_getconfig(hw,
1278 HFA384x_RID_CURRENTBSSID,
1283 "getconfig(0x%02x) failed, result = %d\n",
1284 HFA384x_RID_CURRENTBSSID, result);
1288 result = hfa384x_drvr_getconfig(hw,
1289 HFA384x_RID_CURRENTSSID,
1290 &ssid, sizeof(ssid));
1293 "getconfig(0x%02x) failed, result = %d\n",
1294 HFA384x_RID_CURRENTSSID, result);
1297 prism2mgmt_bytestr2pstr((hfa384x_bytestr_t *)&ssid,
1298 (p80211pstrd_t *)&wlandev->
1301 /* Collect the port status */
1302 result = hfa384x_drvr_getconfig16(hw,
1303 HFA384x_RID_PORTSTATUS,
1307 "getconfig(0x%02x) failed, result = %d\n",
1308 HFA384x_RID_PORTSTATUS, result);
1312 (portstatus == HFA384x_PSTATUS_CONN_IBSS) ?
1313 WLAN_MACMODE_IBSS_STA : WLAN_MACMODE_ESS_STA;
1315 /* Get the ball rolling on the comms quality stuff */
1316 prism2sta_commsqual_defer(&hw->commsqual_bh);
1320 case HFA384x_LINK_DISCONNECTED:
1321 /* This one indicates that our association is gone. We've
1322 * lost connection with the AP and/or been disassociated.
1323 * This indicates that the MAC has completely cleared it's
1324 * associated state. We * should send a deauth indication
1325 * (implying disassoc) up * to the MLME.
1327 * Indicate Deauthentication
1328 * Block Transmits, Ignore receives of data frames
1330 if (hw->join_ap == 2) {
1331 hfa384x_JoinRequest_data_t joinreq;
1332 joinreq = hw->joinreq;
1333 /* Send the join request */
1334 hfa384x_drvr_setconfig(hw,
1335 HFA384x_RID_JOINREQUEST,
1337 HFA384x_RID_JOINREQUEST_LEN);
1339 "linkstatus=DISCONNECTED (re-submitting join)\n");
1341 if (wlandev->netdev->type == ARPHRD_ETHER)
1343 "linkstatus=DISCONNECTED (unhandled)\n");
1345 wlandev->macmode = WLAN_MACMODE_NONE;
1347 netif_carrier_off(wlandev->netdev);
1351 case HFA384x_LINK_AP_CHANGE:
1352 /* This one indicates that the MAC has decided to and
1353 * successfully completed a change to another AP. We
1354 * should probably implement a reassociation indication
1355 * in response to this one. I'm thinking that the the
1356 * p80211 layer needs to be notified in case of
1357 * buffering/queueing issues. User mode also needs to be
1358 * notified so that any BSS dependent elements can be
1360 * associated state. We * should send a deauth indication
1361 * (implying disassoc) up * to the MLME.
1363 * Indicate Reassociation
1364 * Enable Transmits, Receives and pass up data frames
1366 printk(KERN_INFO "linkstatus=AP_CHANGE\n");
1368 result = hfa384x_drvr_getconfig(hw,
1369 HFA384x_RID_CURRENTBSSID,
1370 wlandev->bssid, WLAN_BSSID_LEN);
1373 "getconfig(0x%02x) failed, result = %d\n",
1374 HFA384x_RID_CURRENTBSSID, result);
1378 result = hfa384x_drvr_getconfig(hw,
1379 HFA384x_RID_CURRENTSSID,
1380 &ssid, sizeof(ssid));
1383 "getconfig(0x%02x) failed, result = %d\n",
1384 HFA384x_RID_CURRENTSSID, result);
1387 prism2mgmt_bytestr2pstr((hfa384x_bytestr_t *)&ssid,
1388 (p80211pstrd_t *)&wlandev->ssid);
1390 hw->link_status = HFA384x_LINK_CONNECTED;
1391 netif_carrier_on(wlandev->netdev);
1395 case HFA384x_LINK_AP_OUTOFRANGE:
1396 /* This one indicates that the MAC has decided that the
1397 * AP is out of range, but hasn't found a better candidate
1398 * so the MAC maintains its "associated" state in case
1399 * we get back in range. We should block transmits and
1400 * receives in this state. Do we need an indication here?
1401 * Probably not since a polling user-mode element would
1402 * get this status from from p2PortStatus(FD40). What about
1405 * Block Transmits, Ignore receives of data frames
1407 printk(KERN_INFO "linkstatus=AP_OUTOFRANGE (unhandled)\n");
1409 netif_carrier_off(wlandev->netdev);
1413 case HFA384x_LINK_AP_INRANGE:
1414 /* This one indicates that the MAC has decided that the
1415 * AP is back in range. We continue working with our
1416 * existing association.
1418 * Enable Transmits, Receives and pass up data frames
1420 printk(KERN_INFO "linkstatus=AP_INRANGE\n");
1422 hw->link_status = HFA384x_LINK_CONNECTED;
1423 netif_carrier_on(wlandev->netdev);
1427 case HFA384x_LINK_ASSOCFAIL:
1428 /* This one is actually a peer to CONNECTED. We've
1429 * requested a join for a given SSID and optionally BSSID.
1430 * We can use this one to indicate authentication and
1431 * association failures. The trick is going to be
1432 * 1) identifying the failure, and 2) state management.
1434 * Disable Transmits, Ignore receives of data frames
1436 if (hw->join_ap && --hw->join_retries > 0) {
1437 hfa384x_JoinRequest_data_t joinreq;
1438 joinreq = hw->joinreq;
1439 /* Send the join request */
1440 hfa384x_drvr_setconfig(hw,
1441 HFA384x_RID_JOINREQUEST,
1443 HFA384x_RID_JOINREQUEST_LEN);
1445 "linkstatus=ASSOCFAIL (re-submitting join)\n");
1447 printk(KERN_INFO "linkstatus=ASSOCFAIL (unhandled)\n");
1450 netif_carrier_off(wlandev->netdev);
1455 /* This is bad, IO port problems? */
1457 "unknown linkstatus=0x%02x\n", hw->link_status);
1462 wlandev->linkstatus = (hw->link_status == HFA384x_LINK_CONNECTED);
1464 p80211wext_event_associated(wlandev, wlandev->linkstatus);
1471 /*----------------------------------------------------------------
1472 * prism2sta_inf_linkstatus
1474 * Handles the receipt of a Link Status info frame.
1477 * wlandev wlan device structure
1478 * inf ptr to info frame (contents in hfa384x order)
1487 ----------------------------------------------------------------*/
1488 static void prism2sta_inf_linkstatus(wlandevice_t *wlandev,
1489 hfa384x_InfFrame_t *inf)
1491 hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
1493 hw->link_status_new = hfa384x2host_16(inf->info.linkstatus.linkstatus);
1495 schedule_work(&hw->link_bh);
1500 /*----------------------------------------------------------------
1501 * prism2sta_inf_assocstatus
1503 * Handles the receipt of an Association Status info frame. Should
1504 * be present in APs only.
1507 * wlandev wlan device structure
1508 * inf ptr to info frame (contents in hfa384x order)
1517 ----------------------------------------------------------------*/
1518 static void prism2sta_inf_assocstatus(wlandevice_t *wlandev,
1519 hfa384x_InfFrame_t *inf)
1521 hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
1522 hfa384x_AssocStatus_t rec;
1525 memcpy(&rec, &inf->info.assocstatus, sizeof(rec));
1526 rec.assocstatus = hfa384x2host_16(rec.assocstatus);
1527 rec.reason = hfa384x2host_16(rec.reason);
1530 ** Find the address in the list of authenticated stations. If it wasn't
1531 ** found, then this address has not been previously authenticated and
1532 ** something weird has happened if this is anything other than an
1533 ** "authentication failed" message. If the address was found, then
1534 ** set the "associated" flag for that station, based on whether the
1535 ** station is associating or losing its association. Something weird
1536 ** has also happened if we find the address in the list of authenticated
1537 ** stations but we are getting an "authentication failed" message.
1540 for (i = 0; i < hw->authlist.cnt; i++)
1541 if (memcmp(rec.sta_addr, hw->authlist.addr[i], ETH_ALEN) == 0)
1544 if (i >= hw->authlist.cnt) {
1545 if (rec.assocstatus != HFA384x_ASSOCSTATUS_AUTHFAIL)
1547 "assocstatus info frame received for non-authenticated station.\n");
1549 hw->authlist.assoc[i] =
1550 (rec.assocstatus == HFA384x_ASSOCSTATUS_STAASSOC ||
1551 rec.assocstatus == HFA384x_ASSOCSTATUS_REASSOC);
1553 if (rec.assocstatus == HFA384x_ASSOCSTATUS_AUTHFAIL)
1555 "authfail assocstatus info frame received for authenticated station.\n");
1561 /*----------------------------------------------------------------
1562 * prism2sta_inf_authreq
1564 * Handles the receipt of an Authentication Request info frame. Should
1565 * be present in APs only.
1568 * wlandev wlan device structure
1569 * inf ptr to info frame (contents in hfa384x order)
1579 ----------------------------------------------------------------*/
1580 static void prism2sta_inf_authreq(wlandevice_t *wlandev,
1581 hfa384x_InfFrame_t *inf)
1583 hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
1584 struct sk_buff *skb;
1586 skb = dev_alloc_skb(sizeof(*inf));
1588 skb_put(skb, sizeof(*inf));
1589 memcpy(skb->data, inf, sizeof(*inf));
1590 skb_queue_tail(&hw->authq, skb);
1591 schedule_work(&hw->link_bh);
1595 static void prism2sta_inf_authreq_defer(wlandevice_t *wlandev,
1596 hfa384x_InfFrame_t *inf)
1598 hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
1599 hfa384x_authenticateStation_data_t rec;
1601 int i, added, result, cnt;
1605 ** Build the AuthenticateStation record. Initialize it for denying
1609 memcpy(rec.address, inf->info.authreq.sta_addr, ETH_ALEN);
1610 rec.status = P80211ENUM_status_unspec_failure;
1613 ** Authenticate based on the access mode.
1616 switch (hw->accessmode) {
1617 case WLAN_ACCESS_NONE:
1620 ** Deny all new authentications. However, if a station
1621 ** is ALREADY authenticated, then accept it.
1624 for (i = 0; i < hw->authlist.cnt; i++)
1625 if (memcmp(rec.address, hw->authlist.addr[i],
1627 rec.status = P80211ENUM_status_successful;
1633 case WLAN_ACCESS_ALL:
1636 ** Allow all authentications.
1639 rec.status = P80211ENUM_status_successful;
1642 case WLAN_ACCESS_ALLOW:
1645 ** Only allow the authentication if the MAC address
1646 ** is in the list of allowed addresses.
1648 ** Since this is the interrupt handler, we may be here
1649 ** while the access list is in the middle of being
1650 ** updated. Choose the list which is currently okay.
1651 ** See "prism2mib_priv_accessallow()" for details.
1654 if (hw->allow.modify == 0) {
1655 cnt = hw->allow.cnt;
1656 addr = hw->allow.addr[0];
1658 cnt = hw->allow.cnt1;
1659 addr = hw->allow.addr1[0];
1662 for (i = 0; i < cnt; i++, addr += ETH_ALEN)
1663 if (memcmp(rec.address, addr, ETH_ALEN) == 0) {
1664 rec.status = P80211ENUM_status_successful;
1670 case WLAN_ACCESS_DENY:
1673 ** Allow the authentication UNLESS the MAC address is
1674 ** in the list of denied addresses.
1676 ** Since this is the interrupt handler, we may be here
1677 ** while the access list is in the middle of being
1678 ** updated. Choose the list which is currently okay.
1679 ** See "prism2mib_priv_accessdeny()" for details.
1682 if (hw->deny.modify == 0) {
1684 addr = hw->deny.addr[0];
1686 cnt = hw->deny.cnt1;
1687 addr = hw->deny.addr1[0];
1690 rec.status = P80211ENUM_status_successful;
1692 for (i = 0; i < cnt; i++, addr += ETH_ALEN)
1693 if (memcmp(rec.address, addr, ETH_ALEN) == 0) {
1694 rec.status = P80211ENUM_status_unspec_failure;
1702 ** If the authentication is okay, then add the MAC address to the list
1703 ** of authenticated stations. Don't add the address if it is already in
1704 ** the list. (802.11b does not seem to disallow a station from issuing
1705 ** an authentication request when the station is already authenticated.
1706 ** Does this sort of thing ever happen? We might as well do the check
1712 if (rec.status == P80211ENUM_status_successful) {
1713 for (i = 0; i < hw->authlist.cnt; i++)
1714 if (memcmp(rec.address, hw->authlist.addr[i], ETH_ALEN)
1718 if (i >= hw->authlist.cnt) {
1719 if (hw->authlist.cnt >= WLAN_AUTH_MAX) {
1720 rec.status = P80211ENUM_status_ap_full;
1722 memcpy(hw->authlist.addr[hw->authlist.cnt],
1723 rec.address, ETH_ALEN);
1731 ** Send back the results of the authentication. If this doesn't work,
1732 ** then make sure to remove the address from the authenticated list if
1736 rec.status = host2hfa384x_16(rec.status);
1737 rec.algorithm = inf->info.authreq.algorithm;
1739 result = hfa384x_drvr_setconfig(hw, HFA384x_RID_AUTHENTICATESTA,
1745 "setconfig(authenticatestation) failed, result=%d\n",
1751 /*----------------------------------------------------------------
1752 * prism2sta_inf_psusercnt
1754 * Handles the receipt of a PowerSaveUserCount info frame. Should
1755 * be present in APs only.
1758 * wlandev wlan device structure
1759 * inf ptr to info frame (contents in hfa384x order)
1768 ----------------------------------------------------------------*/
1769 static void prism2sta_inf_psusercnt(wlandevice_t *wlandev,
1770 hfa384x_InfFrame_t *inf)
1772 hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
1774 hw->psusercount = hfa384x2host_16(inf->info.psusercnt.usercnt);
1779 /*----------------------------------------------------------------
1782 * Handles the Info event.
1785 * wlandev wlan device structure
1786 * inf ptr to a generic info frame
1795 ----------------------------------------------------------------*/
1796 void prism2sta_ev_info(wlandevice_t *wlandev, hfa384x_InfFrame_t *inf)
1798 inf->infotype = hfa384x2host_16(inf->infotype);
1800 switch (inf->infotype) {
1801 case HFA384x_IT_HANDOVERADDR:
1802 prism2sta_inf_handover(wlandev, inf);
1804 case HFA384x_IT_COMMTALLIES:
1805 prism2sta_inf_tallies(wlandev, inf);
1807 case HFA384x_IT_HOSTSCANRESULTS:
1808 prism2sta_inf_hostscanresults(wlandev, inf);
1810 case HFA384x_IT_SCANRESULTS:
1811 prism2sta_inf_scanresults(wlandev, inf);
1813 case HFA384x_IT_CHINFORESULTS:
1814 prism2sta_inf_chinforesults(wlandev, inf);
1816 case HFA384x_IT_LINKSTATUS:
1817 prism2sta_inf_linkstatus(wlandev, inf);
1819 case HFA384x_IT_ASSOCSTATUS:
1820 prism2sta_inf_assocstatus(wlandev, inf);
1822 case HFA384x_IT_AUTHREQ:
1823 prism2sta_inf_authreq(wlandev, inf);
1825 case HFA384x_IT_PSUSERCNT:
1826 prism2sta_inf_psusercnt(wlandev, inf);
1828 case HFA384x_IT_KEYIDCHANGED:
1829 printk(KERN_WARNING "Unhandled IT_KEYIDCHANGED\n");
1831 case HFA384x_IT_ASSOCREQ:
1832 printk(KERN_WARNING "Unhandled IT_ASSOCREQ\n");
1834 case HFA384x_IT_MICFAILURE:
1835 printk(KERN_WARNING "Unhandled IT_MICFAILURE\n");
1839 "Unknown info type=0x%02x\n", inf->infotype);
1845 /*----------------------------------------------------------------
1846 * prism2sta_ev_txexc
1848 * Handles the TxExc event. A Transmit Exception event indicates
1849 * that the MAC's TX process was unsuccessful - so the packet did
1850 * not get transmitted.
1853 * wlandev wlan device structure
1854 * status tx frame status word
1863 ----------------------------------------------------------------*/
1864 void prism2sta_ev_txexc(wlandevice_t *wlandev, u16 status)
1866 pr_debug("TxExc status=0x%x.\n", status);
1871 /*----------------------------------------------------------------
1874 * Handles the Tx event.
1877 * wlandev wlan device structure
1878 * status tx frame status word
1886 ----------------------------------------------------------------*/
1887 void prism2sta_ev_tx(wlandevice_t *wlandev, u16 status)
1889 pr_debug("Tx Complete, status=0x%04x\n", status);
1890 /* update linux network stats */
1891 wlandev->linux_stats.tx_packets++;
1895 /*----------------------------------------------------------------
1898 * Handles the Rx event.
1901 * wlandev wlan device structure
1910 ----------------------------------------------------------------*/
1911 void prism2sta_ev_rx(wlandevice_t *wlandev, struct sk_buff *skb)
1913 p80211netdev_rx(wlandev, skb);
1917 /*----------------------------------------------------------------
1918 * prism2sta_ev_alloc
1920 * Handles the Alloc event.
1923 * wlandev wlan device structure
1932 ----------------------------------------------------------------*/
1933 void prism2sta_ev_alloc(wlandevice_t *wlandev)
1935 netif_wake_queue(wlandev->netdev);
1939 /*----------------------------------------------------------------
1942 * Called at module init time. This creates the wlandevice_t structure
1943 * and initializes it with relevant bits.
1949 * the created wlandevice_t structure.
1952 * also allocates the priv/hw structures.
1957 ----------------------------------------------------------------*/
1958 static wlandevice_t *create_wlan(void)
1960 wlandevice_t *wlandev = NULL;
1961 hfa384x_t *hw = NULL;
1963 /* Alloc our structures */
1964 wlandev = kmalloc(sizeof(wlandevice_t), GFP_KERNEL);
1965 hw = kmalloc(sizeof(hfa384x_t), GFP_KERNEL);
1967 if (!wlandev || !hw) {
1968 printk(KERN_ERR "%s: Memory allocation failure.\n", dev_info);
1976 /* Clear all the structs */
1977 memset(wlandev, 0, sizeof(wlandevice_t));
1978 memset(hw, 0, sizeof(hfa384x_t));
1980 /* Initialize the network device object. */
1981 wlandev->nsdname = dev_info;
1982 wlandev->msdstate = WLAN_MSD_HWPRESENT_PENDING;
1984 wlandev->open = prism2sta_open;
1985 wlandev->close = prism2sta_close;
1986 wlandev->reset = prism2sta_reset;
1987 wlandev->txframe = prism2sta_txframe;
1988 wlandev->mlmerequest = prism2sta_mlmerequest;
1989 wlandev->set_multicast_list = prism2sta_setmulticast;
1990 wlandev->tx_timeout = hfa384x_tx_timeout;
1992 wlandev->nsdcaps = P80211_NSDCAP_HWFRAGMENT | P80211_NSDCAP_AUTOJOIN;
1994 /* Initialize the device private data stucture. */
1995 hw->dot11_desired_bss_type = 1;
2000 void prism2sta_commsqual_defer(struct work_struct *data)
2002 hfa384x_t *hw = container_of(data, struct hfa384x, commsqual_bh);
2003 wlandevice_t *wlandev = hw->wlandev;
2004 hfa384x_bytestr32_t ssid;
2007 if (hw->wlandev->hwremoved)
2010 /* we don't care if we're in AP mode */
2011 if ((wlandev->macmode == WLAN_MACMODE_NONE) ||
2012 (wlandev->macmode == WLAN_MACMODE_ESS_AP)) {
2016 /* It only makes sense to poll these in non-IBSS */
2017 if (wlandev->macmode != WLAN_MACMODE_IBSS_STA) {
2018 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_DBMCOMMSQUALITY,
2020 HFA384x_RID_DBMCOMMSQUALITY_LEN);
2023 printk(KERN_ERR "error fetching commsqual\n");
2027 pr_debug("commsqual %d %d %d\n",
2028 hfa384x2host_16(hw->qual.CQ_currBSS),
2029 hfa384x2host_16(hw->qual.ASL_currBSS),
2030 hfa384x2host_16(hw->qual.ANL_currFC));
2033 /* Lastly, we need to make sure the BSSID didn't change on us */
2034 result = hfa384x_drvr_getconfig(hw,
2035 HFA384x_RID_CURRENTBSSID,
2036 wlandev->bssid, WLAN_BSSID_LEN);
2039 "getconfig(0x%02x) failed, result = %d\n",
2040 HFA384x_RID_CURRENTBSSID, result);
2044 result = hfa384x_drvr_getconfig(hw,
2045 HFA384x_RID_CURRENTSSID,
2046 &ssid, sizeof(ssid));
2049 "getconfig(0x%02x) failed, result = %d\n",
2050 HFA384x_RID_CURRENTSSID, result);
2053 prism2mgmt_bytestr2pstr((hfa384x_bytestr_t *)&ssid,
2054 (p80211pstrd_t *)&wlandev->ssid);
2056 /* Reschedule timer */
2057 mod_timer(&hw->commsqual_timer, jiffies + HZ);
2063 void prism2sta_commsqual_timer(unsigned long data)
2065 hfa384x_t *hw = (hfa384x_t *) data;
2067 schedule_work(&hw->commsqual_bh);