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/module.h>
54 #include <linux/moduleparam.h>
55 #include <linux/kernel.h>
56 #include <linux/sched.h>
57 #include <linux/types.h>
58 #include <linux/slab.h>
59 #include <linux/wireless.h>
60 #include <linux/netdevice.h>
61 #include <linux/workqueue.h>
62 #include <linux/byteorder/generic.h>
65 #include <linux/delay.h>
66 #include <asm/byteorder.h>
67 #include <linux/if_arp.h>
68 #include <linux/if_ether.h>
69 #include <linux/bitops.h>
71 #include "p80211types.h"
72 #include "p80211hdr.h"
73 #include "p80211mgmt.h"
74 #include "p80211conv.h"
75 #include "p80211msg.h"
76 #include "p80211netdev.h"
77 #include "p80211req.h"
78 #include "p80211metadef.h"
79 #include "p80211metastruct.h"
81 #include "prism2mgmt.h"
83 static char *dev_info = "prism2_usb";
84 static wlandevice_t *create_wlan(void);
86 int prism2_reset_holdtime = 30; /* Reset hold time in ms */
87 int prism2_reset_settletime = 100; /* Reset settle time in ms */
89 static int prism2_doreset; /* Do a reset at init? */
91 module_param(prism2_doreset, int, 0644);
92 MODULE_PARM_DESC(prism2_doreset, "Issue a reset on initialization");
94 module_param(prism2_reset_holdtime, int, 0644);
95 MODULE_PARM_DESC(prism2_reset_holdtime, "reset hold time in ms");
96 module_param(prism2_reset_settletime, int, 0644);
97 MODULE_PARM_DESC(prism2_reset_settletime, "reset settle time in ms");
99 MODULE_LICENSE("Dual MPL/GPL");
101 static int prism2sta_open(wlandevice_t *wlandev);
102 static int prism2sta_close(wlandevice_t *wlandev);
103 static void prism2sta_reset(wlandevice_t *wlandev);
104 static int prism2sta_txframe(wlandevice_t *wlandev, struct sk_buff *skb,
105 union p80211_hdr *p80211_hdr,
106 struct p80211_metawep *p80211_wep);
107 static int prism2sta_mlmerequest(wlandevice_t *wlandev, struct p80211msg *msg);
108 static int prism2sta_getcardinfo(wlandevice_t *wlandev);
109 static int prism2sta_globalsetup(wlandevice_t *wlandev);
110 static int prism2sta_setmulticast(wlandevice_t *wlandev, netdevice_t *dev);
112 static void prism2sta_inf_handover(wlandevice_t *wlandev,
113 hfa384x_InfFrame_t *inf);
114 static void prism2sta_inf_tallies(wlandevice_t *wlandev,
115 hfa384x_InfFrame_t *inf);
116 static void prism2sta_inf_hostscanresults(wlandevice_t *wlandev,
117 hfa384x_InfFrame_t *inf);
118 static void prism2sta_inf_scanresults(wlandevice_t *wlandev,
119 hfa384x_InfFrame_t *inf);
120 static void prism2sta_inf_chinforesults(wlandevice_t *wlandev,
121 hfa384x_InfFrame_t *inf);
122 static void prism2sta_inf_linkstatus(wlandevice_t *wlandev,
123 hfa384x_InfFrame_t *inf);
124 static void prism2sta_inf_assocstatus(wlandevice_t *wlandev,
125 hfa384x_InfFrame_t *inf);
126 static void prism2sta_inf_authreq(wlandevice_t *wlandev,
127 hfa384x_InfFrame_t *inf);
128 static void prism2sta_inf_authreq_defer(wlandevice_t *wlandev,
129 hfa384x_InfFrame_t *inf);
130 static void prism2sta_inf_psusercnt(wlandevice_t *wlandev,
131 hfa384x_InfFrame_t *inf);
133 /*----------------------------------------------------------------
136 * WLAN device open method. Called from p80211netdev when kernel
137 * device open (start) method is called in response to the
138 * SIOCSIIFFLAGS ioctl changing the flags bit IFF_UP
142 * wlandev wlan device structure
146 * >0 f/w reported error
147 * <0 driver reported error
153 ----------------------------------------------------------------*/
154 static int prism2sta_open(wlandevice_t *wlandev)
156 /* We don't currently have to do anything else.
157 * The setup of the MAC should be subsequently completed via
159 * Higher layers know we're ready from dev->start==1 and
160 * dev->tbusy==0. Our rx path knows to pass up received/
161 * frames because of dev->flags&IFF_UP is true.
167 /*----------------------------------------------------------------
170 * WLAN device close method. Called from p80211netdev when kernel
171 * device close method is called in response to the
172 * SIOCSIIFFLAGS ioctl changing the flags bit IFF_UP
176 * wlandev wlan device structure
180 * >0 f/w reported error
181 * <0 driver reported error
187 ----------------------------------------------------------------*/
188 static int prism2sta_close(wlandevice_t *wlandev)
190 /* We don't currently have to do anything else.
191 * Higher layers know we're not ready from dev->start==0 and
192 * dev->tbusy==1. Our rx path knows to not pass up received
193 * frames because of dev->flags&IFF_UP is false.
199 /*----------------------------------------------------------------
202 * Not currently implented.
205 * wlandev wlan device structure
215 ----------------------------------------------------------------*/
216 static void prism2sta_reset(wlandevice_t *wlandev)
220 /*----------------------------------------------------------------
223 * Takes a frame from p80211 and queues it for transmission.
226 * wlandev wlan device structure
227 * pb packet buffer struct. Contains an 802.11
229 * p80211_hdr points to the 802.11 header for the packet.
231 * 0 Success and more buffs available
232 * 1 Success but no more buffs
233 * 2 Allocation failure
234 * 4 Buffer full or queue busy
240 ----------------------------------------------------------------*/
241 static int prism2sta_txframe(wlandevice_t *wlandev, struct sk_buff *skb,
242 union p80211_hdr *p80211_hdr,
243 struct p80211_metawep *p80211_wep)
245 hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
248 /* If necessary, set the 802.11 WEP bit */
249 if ((wlandev->hostwep & (HOSTWEP_PRIVACYINVOKED | HOSTWEP_ENCRYPT)) ==
250 HOSTWEP_PRIVACYINVOKED) {
251 p80211_hdr->a3.fc |= cpu_to_le16(WLAN_SET_FC_ISWEP(1));
254 result = hfa384x_drvr_txframe(hw, skb, p80211_hdr, p80211_wep);
259 /*----------------------------------------------------------------
260 * prism2sta_mlmerequest
262 * wlan command message handler. All we do here is pass the message
263 * over to the prism2sta_mgmt_handler.
266 * wlandev wlan device structure
267 * msg wlan command message
270 * <0 successful acceptance of message, but we're
271 * waiting for an async process to finish before
272 * we're done with the msg. When the asynch
273 * process is done, we'll call the p80211
274 * function p80211req_confirm() .
275 * >0 An error occurred while we were handling
282 ----------------------------------------------------------------*/
283 static int prism2sta_mlmerequest(wlandevice_t *wlandev, struct p80211msg *msg)
285 hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
289 switch (msg->msgcode) {
290 case DIDmsg_dot11req_mibget:
291 pr_debug("Received mibget request\n");
292 result = prism2mgmt_mibset_mibget(wlandev, msg);
294 case DIDmsg_dot11req_mibset:
295 pr_debug("Received mibset request\n");
296 result = prism2mgmt_mibset_mibget(wlandev, msg);
298 case DIDmsg_dot11req_scan:
299 pr_debug("Received scan request\n");
300 result = prism2mgmt_scan(wlandev, msg);
302 case DIDmsg_dot11req_scan_results:
303 pr_debug("Received scan_results request\n");
304 result = prism2mgmt_scan_results(wlandev, msg);
306 case DIDmsg_dot11req_start:
307 pr_debug("Received mlme start request\n");
308 result = prism2mgmt_start(wlandev, msg);
311 * Prism2 specific messages
313 case DIDmsg_p2req_readpda:
314 pr_debug("Received mlme readpda request\n");
315 result = prism2mgmt_readpda(wlandev, msg);
317 case DIDmsg_p2req_ramdl_state:
318 pr_debug("Received mlme ramdl_state request\n");
319 result = prism2mgmt_ramdl_state(wlandev, msg);
321 case DIDmsg_p2req_ramdl_write:
322 pr_debug("Received mlme ramdl_write request\n");
323 result = prism2mgmt_ramdl_write(wlandev, msg);
325 case DIDmsg_p2req_flashdl_state:
326 pr_debug("Received mlme flashdl_state request\n");
327 result = prism2mgmt_flashdl_state(wlandev, msg);
329 case DIDmsg_p2req_flashdl_write:
330 pr_debug("Received mlme flashdl_write request\n");
331 result = prism2mgmt_flashdl_write(wlandev, msg);
334 * Linux specific messages
336 case DIDmsg_lnxreq_hostwep:
337 break; /* ignore me. */
338 case DIDmsg_lnxreq_ifstate:
340 struct p80211msg_lnxreq_ifstate *ifstatemsg;
342 pr_debug("Received mlme ifstate request\n");
343 ifstatemsg = (struct p80211msg_lnxreq_ifstate *) msg;
345 prism2sta_ifstate(wlandev,
346 ifstatemsg->ifstate.data);
347 ifstatemsg->resultcode.status =
348 P80211ENUM_msgitem_status_data_ok;
349 ifstatemsg->resultcode.data = result;
353 case DIDmsg_lnxreq_wlansniff:
354 pr_debug("Received mlme wlansniff request\n");
355 result = prism2mgmt_wlansniff(wlandev, msg);
357 case DIDmsg_lnxreq_autojoin:
358 pr_debug("Received mlme autojoin request\n");
359 result = prism2mgmt_autojoin(wlandev, msg);
361 case DIDmsg_lnxreq_commsquality:{
362 struct p80211msg_lnxreq_commsquality *qualmsg;
364 pr_debug("Received commsquality request\n");
366 qualmsg = (struct p80211msg_lnxreq_commsquality *) msg;
368 qualmsg->link.status =
369 P80211ENUM_msgitem_status_data_ok;
370 qualmsg->level.status =
371 P80211ENUM_msgitem_status_data_ok;
372 qualmsg->noise.status =
373 P80211ENUM_msgitem_status_data_ok;
375 qualmsg->link.data = le16_to_cpu(hw->qual.CQ_currBSS);
376 qualmsg->level.data = le16_to_cpu(hw->qual.ASL_currBSS);
377 qualmsg->noise.data = le16_to_cpu(hw->qual.ANL_currFC);
378 qualmsg->txrate.data = hw->txrate;
383 netdev_warn(wlandev->netdev,
384 "Unknown mgmt request message 0x%08x",
392 /*----------------------------------------------------------------
395 * Interface state. This is the primary WLAN interface enable/disable
396 * handler. Following the driver/load/deviceprobe sequence, this
397 * function must be called with a state of "enable" before any other
398 * commands will be accepted.
401 * wlandev wlan device structure
402 * msgp ptr to msg buffer
405 * A p80211 message resultcode value.
410 * process thread (usually)
412 ----------------------------------------------------------------*/
413 u32 prism2sta_ifstate(wlandevice_t *wlandev, u32 ifstate)
415 hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
418 result = P80211ENUM_resultcode_implementation_failure;
420 pr_debug("Current MSD state(%d), requesting(%d)\n",
421 wlandev->msdstate, ifstate);
423 case P80211ENUM_ifstate_fwload:
424 switch (wlandev->msdstate) {
425 case WLAN_MSD_HWPRESENT:
426 wlandev->msdstate = WLAN_MSD_FWLOAD_PENDING;
428 * Initialize the device+driver sufficiently
429 * for firmware loading.
431 result = hfa384x_drvr_start(hw);
433 netdev_err(wlandev->netdev,
434 "hfa384x_drvr_start() failed,result=%d\n", (int)result);
436 P80211ENUM_resultcode_implementation_failure;
437 wlandev->msdstate = WLAN_MSD_HWPRESENT;
440 wlandev->msdstate = WLAN_MSD_FWLOAD;
441 result = P80211ENUM_resultcode_success;
443 case WLAN_MSD_FWLOAD:
444 hfa384x_cmd_initialize(hw);
445 result = P80211ENUM_resultcode_success;
447 case WLAN_MSD_RUNNING:
448 netdev_warn(wlandev->netdev,
449 "Cannot enter fwload state from enable state, you must disable first.\n");
450 result = P80211ENUM_resultcode_invalid_parameters;
452 case WLAN_MSD_HWFAIL:
454 /* probe() had a problem or the msdstate contains
455 * an unrecognized value, there's nothing we can do.
457 result = P80211ENUM_resultcode_implementation_failure;
461 case P80211ENUM_ifstate_enable:
462 switch (wlandev->msdstate) {
463 case WLAN_MSD_HWPRESENT:
464 case WLAN_MSD_FWLOAD:
465 wlandev->msdstate = WLAN_MSD_RUNNING_PENDING;
466 /* Initialize the device+driver for full
467 * operation. Note that this might me an FWLOAD to
468 * to RUNNING transition so we must not do a chip
469 * or board level reset. Note that on failure,
470 * the MSD state is set to HWPRESENT because we
471 * can't make any assumptions about the state
472 * of the hardware or a previous firmware load.
474 result = hfa384x_drvr_start(hw);
476 netdev_err(wlandev->netdev,
477 "hfa384x_drvr_start() failed,result=%d\n", (int)result);
479 P80211ENUM_resultcode_implementation_failure;
480 wlandev->msdstate = WLAN_MSD_HWPRESENT;
484 result = prism2sta_getcardinfo(wlandev);
486 netdev_err(wlandev->netdev,
487 "prism2sta_getcardinfo() failed,result=%d\n", (int)result);
489 P80211ENUM_resultcode_implementation_failure;
490 hfa384x_drvr_stop(hw);
491 wlandev->msdstate = WLAN_MSD_HWPRESENT;
494 result = prism2sta_globalsetup(wlandev);
496 netdev_err(wlandev->netdev,
497 "prism2sta_globalsetup() failed,result=%d\n", (int)result);
499 P80211ENUM_resultcode_implementation_failure;
500 hfa384x_drvr_stop(hw);
501 wlandev->msdstate = WLAN_MSD_HWPRESENT;
504 wlandev->msdstate = WLAN_MSD_RUNNING;
506 hw->join_retries = 60;
507 result = P80211ENUM_resultcode_success;
509 case WLAN_MSD_RUNNING:
510 /* Do nothing, we're already in this state. */
511 result = P80211ENUM_resultcode_success;
513 case WLAN_MSD_HWFAIL:
515 /* probe() had a problem or the msdstate contains
516 * an unrecognized value, there's nothing we can do.
518 result = P80211ENUM_resultcode_implementation_failure;
522 case P80211ENUM_ifstate_disable:
523 switch (wlandev->msdstate) {
524 case WLAN_MSD_HWPRESENT:
525 /* Do nothing, we're already in this state. */
526 result = P80211ENUM_resultcode_success;
528 case WLAN_MSD_FWLOAD:
529 case WLAN_MSD_RUNNING:
530 wlandev->msdstate = WLAN_MSD_HWPRESENT_PENDING;
532 * TODO: Shut down the MAC completely. Here a chip
533 * or board level reset is probably called for.
534 * After a "disable" _all_ results are lost, even
535 * those from a fwload.
537 if (!wlandev->hwremoved)
538 netif_carrier_off(wlandev->netdev);
540 hfa384x_drvr_stop(hw);
542 wlandev->macmode = WLAN_MACMODE_NONE;
543 wlandev->msdstate = WLAN_MSD_HWPRESENT;
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;
556 result = P80211ENUM_resultcode_invalid_parameters;
563 /*----------------------------------------------------------------
564 * prism2sta_getcardinfo
566 * Collect the NICID, firmware version and any other identifiers
567 * we'd like to have in host-side data structures.
570 * wlandev wlan device structure
574 * >0 f/w reported error
575 * <0 driver reported error
581 ----------------------------------------------------------------*/
582 static int prism2sta_getcardinfo(wlandevice_t *wlandev)
585 hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
587 u8 snum[HFA384x_RID_NICSERIALNUMBER_LEN];
589 /* Collect version and compatibility info */
590 /* Some are critical, some are not */
592 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_NICIDENTITY,
594 sizeof(hfa384x_compident_t));
596 netdev_err(wlandev->netdev, "Failed to retrieve NICIDENTITY\n");
600 /* get all the nic id fields in host byte order */
601 hw->ident_nic.id = le16_to_cpu(hw->ident_nic.id);
602 hw->ident_nic.variant = le16_to_cpu(hw->ident_nic.variant);
603 hw->ident_nic.major = le16_to_cpu(hw->ident_nic.major);
604 hw->ident_nic.minor = le16_to_cpu(hw->ident_nic.minor);
606 netdev_info(wlandev->netdev, "ident: nic h/w: id=0x%02x %d.%d.%d\n",
607 hw->ident_nic.id, hw->ident_nic.major,
608 hw->ident_nic.minor, hw->ident_nic.variant);
610 /* Primary f/w identity */
611 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_PRIIDENTITY,
613 sizeof(hfa384x_compident_t));
615 netdev_err(wlandev->netdev, "Failed to retrieve PRIIDENTITY\n");
619 /* get all the private fw id fields in host byte order */
620 hw->ident_pri_fw.id = le16_to_cpu(hw->ident_pri_fw.id);
621 hw->ident_pri_fw.variant = le16_to_cpu(hw->ident_pri_fw.variant);
622 hw->ident_pri_fw.major = le16_to_cpu(hw->ident_pri_fw.major);
623 hw->ident_pri_fw.minor = le16_to_cpu(hw->ident_pri_fw.minor);
625 netdev_info(wlandev->netdev, "ident: pri f/w: id=0x%02x %d.%d.%d\n",
626 hw->ident_pri_fw.id, hw->ident_pri_fw.major,
627 hw->ident_pri_fw.minor, hw->ident_pri_fw.variant);
629 /* Station (Secondary?) f/w identity */
630 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_STAIDENTITY,
632 sizeof(hfa384x_compident_t));
634 netdev_err(wlandev->netdev, "Failed to retrieve STAIDENTITY\n");
638 if (hw->ident_nic.id < 0x8000) {
639 netdev_err(wlandev->netdev,
640 "FATAL: Card is not an Intersil Prism2/2.5/3\n");
645 /* get all the station fw id fields in host byte order */
646 hw->ident_sta_fw.id = le16_to_cpu(hw->ident_sta_fw.id);
647 hw->ident_sta_fw.variant = le16_to_cpu(hw->ident_sta_fw.variant);
648 hw->ident_sta_fw.major = le16_to_cpu(hw->ident_sta_fw.major);
649 hw->ident_sta_fw.minor = le16_to_cpu(hw->ident_sta_fw.minor);
651 /* strip out the 'special' variant bits */
652 hw->mm_mods = hw->ident_sta_fw.variant & (BIT(14) | BIT(15));
653 hw->ident_sta_fw.variant &= ~((u16) (BIT(14) | BIT(15)));
655 if (hw->ident_sta_fw.id == 0x1f) {
656 netdev_info(wlandev->netdev,
657 "ident: sta f/w: id=0x%02x %d.%d.%d\n",
658 hw->ident_sta_fw.id, hw->ident_sta_fw.major,
659 hw->ident_sta_fw.minor, hw->ident_sta_fw.variant);
661 netdev_info(wlandev->netdev,
662 "ident: ap f/w: id=0x%02x %d.%d.%d\n",
663 hw->ident_sta_fw.id, hw->ident_sta_fw.major,
664 hw->ident_sta_fw.minor, hw->ident_sta_fw.variant);
665 netdev_err(wlandev->netdev, "Unsupported Tertiary AP firmeare loaded!\n");
669 /* Compatibility range, Modem supplier */
670 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_MFISUPRANGE,
672 sizeof(hfa384x_caplevel_t));
674 netdev_err(wlandev->netdev, "Failed to retrieve MFISUPRANGE\n");
678 /* get all the Compatibility range, modem interface supplier
679 fields in byte order */
680 hw->cap_sup_mfi.role = le16_to_cpu(hw->cap_sup_mfi.role);
681 hw->cap_sup_mfi.id = le16_to_cpu(hw->cap_sup_mfi.id);
682 hw->cap_sup_mfi.variant = le16_to_cpu(hw->cap_sup_mfi.variant);
683 hw->cap_sup_mfi.bottom = le16_to_cpu(hw->cap_sup_mfi.bottom);
684 hw->cap_sup_mfi.top = le16_to_cpu(hw->cap_sup_mfi.top);
686 netdev_info(wlandev->netdev,
687 "MFI:SUP:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
688 hw->cap_sup_mfi.role, hw->cap_sup_mfi.id,
689 hw->cap_sup_mfi.variant, hw->cap_sup_mfi.bottom,
690 hw->cap_sup_mfi.top);
692 /* Compatibility range, Controller supplier */
693 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_CFISUPRANGE,
695 sizeof(hfa384x_caplevel_t));
697 netdev_err(wlandev->netdev, "Failed to retrieve CFISUPRANGE\n");
701 /* get all the Compatibility range, controller interface supplier
702 fields in byte order */
703 hw->cap_sup_cfi.role = le16_to_cpu(hw->cap_sup_cfi.role);
704 hw->cap_sup_cfi.id = le16_to_cpu(hw->cap_sup_cfi.id);
705 hw->cap_sup_cfi.variant = le16_to_cpu(hw->cap_sup_cfi.variant);
706 hw->cap_sup_cfi.bottom = le16_to_cpu(hw->cap_sup_cfi.bottom);
707 hw->cap_sup_cfi.top = le16_to_cpu(hw->cap_sup_cfi.top);
709 netdev_info(wlandev->netdev,
710 "CFI:SUP:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
711 hw->cap_sup_cfi.role, hw->cap_sup_cfi.id,
712 hw->cap_sup_cfi.variant, hw->cap_sup_cfi.bottom,
713 hw->cap_sup_cfi.top);
715 /* Compatibility range, Primary f/w supplier */
716 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_PRISUPRANGE,
718 sizeof(hfa384x_caplevel_t));
720 netdev_err(wlandev->netdev, "Failed to retrieve PRISUPRANGE\n");
724 /* get all the Compatibility range, primary firmware supplier
725 fields in byte order */
726 hw->cap_sup_pri.role = le16_to_cpu(hw->cap_sup_pri.role);
727 hw->cap_sup_pri.id = le16_to_cpu(hw->cap_sup_pri.id);
728 hw->cap_sup_pri.variant = le16_to_cpu(hw->cap_sup_pri.variant);
729 hw->cap_sup_pri.bottom = le16_to_cpu(hw->cap_sup_pri.bottom);
730 hw->cap_sup_pri.top = le16_to_cpu(hw->cap_sup_pri.top);
732 netdev_info(wlandev->netdev,
733 "PRI:SUP:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
734 hw->cap_sup_pri.role, hw->cap_sup_pri.id,
735 hw->cap_sup_pri.variant, hw->cap_sup_pri.bottom,
736 hw->cap_sup_pri.top);
738 /* Compatibility range, Station f/w supplier */
739 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_STASUPRANGE,
741 sizeof(hfa384x_caplevel_t));
743 netdev_err(wlandev->netdev, "Failed to retrieve STASUPRANGE\n");
747 /* get all the Compatibility range, station firmware supplier
748 fields in byte order */
749 hw->cap_sup_sta.role = le16_to_cpu(hw->cap_sup_sta.role);
750 hw->cap_sup_sta.id = le16_to_cpu(hw->cap_sup_sta.id);
751 hw->cap_sup_sta.variant = le16_to_cpu(hw->cap_sup_sta.variant);
752 hw->cap_sup_sta.bottom = le16_to_cpu(hw->cap_sup_sta.bottom);
753 hw->cap_sup_sta.top = le16_to_cpu(hw->cap_sup_sta.top);
755 if (hw->cap_sup_sta.id == 0x04) {
756 netdev_info(wlandev->netdev,
757 "STA:SUP:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
758 hw->cap_sup_sta.role, hw->cap_sup_sta.id,
759 hw->cap_sup_sta.variant, hw->cap_sup_sta.bottom,
760 hw->cap_sup_sta.top);
762 netdev_info(wlandev->netdev,
763 "AP:SUP:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
764 hw->cap_sup_sta.role, hw->cap_sup_sta.id,
765 hw->cap_sup_sta.variant, hw->cap_sup_sta.bottom,
766 hw->cap_sup_sta.top);
769 /* Compatibility range, primary f/w actor, CFI supplier */
770 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_PRI_CFIACTRANGES,
771 &hw->cap_act_pri_cfi,
772 sizeof(hfa384x_caplevel_t));
774 netdev_err(wlandev->netdev, "Failed to retrieve PRI_CFIACTRANGES\n");
778 /* get all the Compatibility range, primary f/w actor, CFI supplier
779 fields in byte order */
780 hw->cap_act_pri_cfi.role = le16_to_cpu(hw->cap_act_pri_cfi.role);
781 hw->cap_act_pri_cfi.id = le16_to_cpu(hw->cap_act_pri_cfi.id);
782 hw->cap_act_pri_cfi.variant = le16_to_cpu(hw->cap_act_pri_cfi.variant);
783 hw->cap_act_pri_cfi.bottom = le16_to_cpu(hw->cap_act_pri_cfi.bottom);
784 hw->cap_act_pri_cfi.top = le16_to_cpu(hw->cap_act_pri_cfi.top);
786 netdev_info(wlandev->netdev,
787 "PRI-CFI:ACT:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
788 hw->cap_act_pri_cfi.role, hw->cap_act_pri_cfi.id,
789 hw->cap_act_pri_cfi.variant, hw->cap_act_pri_cfi.bottom,
790 hw->cap_act_pri_cfi.top);
792 /* Compatibility range, sta f/w actor, CFI supplier */
793 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_STA_CFIACTRANGES,
794 &hw->cap_act_sta_cfi,
795 sizeof(hfa384x_caplevel_t));
797 netdev_err(wlandev->netdev, "Failed to retrieve STA_CFIACTRANGES\n");
801 /* get all the Compatibility range, station f/w actor, CFI supplier
802 fields in byte order */
803 hw->cap_act_sta_cfi.role = le16_to_cpu(hw->cap_act_sta_cfi.role);
804 hw->cap_act_sta_cfi.id = le16_to_cpu(hw->cap_act_sta_cfi.id);
805 hw->cap_act_sta_cfi.variant = le16_to_cpu(hw->cap_act_sta_cfi.variant);
806 hw->cap_act_sta_cfi.bottom = le16_to_cpu(hw->cap_act_sta_cfi.bottom);
807 hw->cap_act_sta_cfi.top = le16_to_cpu(hw->cap_act_sta_cfi.top);
809 netdev_info(wlandev->netdev,
810 "STA-CFI:ACT:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
811 hw->cap_act_sta_cfi.role, hw->cap_act_sta_cfi.id,
812 hw->cap_act_sta_cfi.variant, hw->cap_act_sta_cfi.bottom,
813 hw->cap_act_sta_cfi.top);
815 /* Compatibility range, sta f/w actor, MFI supplier */
816 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_STA_MFIACTRANGES,
817 &hw->cap_act_sta_mfi,
818 sizeof(hfa384x_caplevel_t));
820 netdev_err(wlandev->netdev, "Failed to retrieve STA_MFIACTRANGES\n");
824 /* get all the Compatibility range, station f/w actor, MFI supplier
825 fields in byte order */
826 hw->cap_act_sta_mfi.role = le16_to_cpu(hw->cap_act_sta_mfi.role);
827 hw->cap_act_sta_mfi.id = le16_to_cpu(hw->cap_act_sta_mfi.id);
828 hw->cap_act_sta_mfi.variant = le16_to_cpu(hw->cap_act_sta_mfi.variant);
829 hw->cap_act_sta_mfi.bottom = le16_to_cpu(hw->cap_act_sta_mfi.bottom);
830 hw->cap_act_sta_mfi.top = le16_to_cpu(hw->cap_act_sta_mfi.top);
832 netdev_info(wlandev->netdev,
833 "STA-MFI:ACT:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
834 hw->cap_act_sta_mfi.role, hw->cap_act_sta_mfi.id,
835 hw->cap_act_sta_mfi.variant, hw->cap_act_sta_mfi.bottom,
836 hw->cap_act_sta_mfi.top);
839 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_NICSERIALNUMBER,
840 snum, HFA384x_RID_NICSERIALNUMBER_LEN);
842 netdev_info(wlandev->netdev, "Prism2 card SN: %*pEhp\n",
843 HFA384x_RID_NICSERIALNUMBER_LEN, snum);
845 netdev_err(wlandev->netdev, "Failed to retrieve Prism2 Card SN\n");
849 /* Collect the MAC address */
850 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_CNFOWNMACADDR,
851 wlandev->netdev->dev_addr, ETH_ALEN);
853 netdev_err(wlandev->netdev, "Failed to retrieve mac address\n");
857 /* short preamble is always implemented */
858 wlandev->nsdcaps |= P80211_NSDCAP_SHORT_PREAMBLE;
860 /* find out if hardware wep is implemented */
861 hfa384x_drvr_getconfig16(hw, HFA384x_RID_PRIVACYOPTIMP, &temp);
863 wlandev->nsdcaps |= P80211_NSDCAP_HARDWAREWEP;
865 /* get the dBm Scaling constant */
866 hfa384x_drvr_getconfig16(hw, HFA384x_RID_CNFDBMADJUST, &temp);
867 hw->dbmadjust = temp;
869 /* Only enable scan by default on newer firmware */
870 if (HFA384x_FIRMWARE_VERSION(hw->ident_sta_fw.major,
871 hw->ident_sta_fw.minor,
872 hw->ident_sta_fw.variant) <
873 HFA384x_FIRMWARE_VERSION(1, 5, 5)) {
874 wlandev->nsdcaps |= P80211_NSDCAP_NOSCAN;
877 /* TODO: Set any internally managed config items */
881 netdev_err(wlandev->netdev, "Failed, result=%d\n", result);
886 /*----------------------------------------------------------------
887 * prism2sta_globalsetup
889 * Set any global RIDs that we want to set at device activation.
892 * wlandev wlan device structure
896 * >0 f/w reported error
897 * <0 driver reported error
903 ----------------------------------------------------------------*/
904 static int prism2sta_globalsetup(wlandevice_t *wlandev)
906 hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
908 /* Set the maximum frame size */
909 return hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFMAXDATALEN,
913 static int prism2sta_setmulticast(wlandevice_t *wlandev, netdevice_t *dev)
916 hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
920 /* If we're not ready, what's the point? */
921 if (hw->state != HFA384x_STATE_RUNNING)
924 if ((dev->flags & (IFF_PROMISC | IFF_ALLMULTI)) != 0)
925 promisc = P80211ENUM_truth_true;
927 promisc = P80211ENUM_truth_false;
930 hfa384x_drvr_setconfig16_async(hw, HFA384x_RID_PROMISCMODE,
936 /*----------------------------------------------------------------
937 * prism2sta_inf_handover
939 * Handles the receipt of a Handover info frame. Should only be present
943 * wlandev wlan device structure
944 * inf ptr to info frame (contents in hfa384x order)
953 ----------------------------------------------------------------*/
954 static void prism2sta_inf_handover(wlandevice_t *wlandev,
955 hfa384x_InfFrame_t *inf)
957 pr_debug("received infoframe:HANDOVER (unhandled)\n");
960 /*----------------------------------------------------------------
961 * prism2sta_inf_tallies
963 * Handles the receipt of a CommTallies info frame.
966 * wlandev wlan device structure
967 * inf ptr to info frame (contents in hfa384x order)
976 ----------------------------------------------------------------*/
977 static void prism2sta_inf_tallies(wlandevice_t *wlandev,
978 hfa384x_InfFrame_t *inf)
980 hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
988 ** Determine if these are 16-bit or 32-bit tallies, based on the
989 ** record length of the info record.
992 cnt = sizeof(hfa384x_CommTallies32_t) / sizeof(u32);
993 if (inf->framelen > 22) {
994 dst = (u32 *) &hw->tallies;
995 src32 = (u32 *) &inf->info.commtallies32;
996 for (i = 0; i < cnt; i++, dst++, src32++)
997 *dst += le32_to_cpu(*src32);
999 dst = (u32 *) &hw->tallies;
1000 src16 = (u16 *) &inf->info.commtallies16;
1001 for (i = 0; i < cnt; i++, dst++, src16++)
1002 *dst += le16_to_cpu(*src16);
1006 /*----------------------------------------------------------------
1007 * prism2sta_inf_scanresults
1009 * Handles the receipt of a Scan Results info frame.
1012 * wlandev wlan device structure
1013 * inf ptr to info frame (contents in hfa384x order)
1022 ----------------------------------------------------------------*/
1023 static void prism2sta_inf_scanresults(wlandevice_t *wlandev,
1024 hfa384x_InfFrame_t *inf)
1027 hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
1029 hfa384x_ScanResult_t *sr = &(inf->info.scanresult);
1031 hfa384x_JoinRequest_data_t joinreq;
1034 /* Get the number of results, first in bytes, then in results */
1035 nbss = (inf->framelen * sizeof(u16)) -
1036 sizeof(inf->infotype) - sizeof(inf->info.scanresult.scanreason);
1037 nbss /= sizeof(hfa384x_ScanResultSub_t);
1040 pr_debug("rx scanresults, reason=%d, nbss=%d:\n",
1041 inf->info.scanresult.scanreason, nbss);
1042 for (i = 0; i < nbss; i++) {
1043 pr_debug("chid=%d anl=%d sl=%d bcnint=%d\n",
1046 sr->result[i].sl, sr->result[i].bcnint);
1047 pr_debug(" capinfo=0x%04x proberesp_rate=%d\n",
1048 sr->result[i].capinfo, sr->result[i].proberesp_rate);
1050 /* issue a join request */
1051 joinreq.channel = sr->result[0].chid;
1052 memcpy(joinreq.bssid, sr->result[0].bssid, WLAN_BSSID_LEN);
1053 result = hfa384x_drvr_setconfig(hw,
1054 HFA384x_RID_JOINREQUEST,
1055 &joinreq, HFA384x_RID_JOINREQUEST_LEN);
1057 netdev_err(wlandev->netdev, "setconfig(joinreq) failed, result=%d\n",
1062 /*----------------------------------------------------------------
1063 * prism2sta_inf_hostscanresults
1065 * Handles the receipt of a Scan Results info frame.
1068 * wlandev wlan device structure
1069 * inf ptr to info frame (contents in hfa384x order)
1078 ----------------------------------------------------------------*/
1079 static void prism2sta_inf_hostscanresults(wlandevice_t *wlandev,
1080 hfa384x_InfFrame_t *inf)
1082 hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
1085 nbss = (inf->framelen - 3) / 32;
1086 pr_debug("Received %d hostscan results\n", nbss);
1091 kfree(hw->scanresults);
1093 hw->scanresults = kmemdup(inf, sizeof(hfa384x_InfFrame_t), GFP_ATOMIC);
1098 /* Notify/wake the sleeping caller. */
1099 hw->scanflag = nbss;
1100 wake_up_interruptible(&hw->cmdq);
1103 /*----------------------------------------------------------------
1104 * prism2sta_inf_chinforesults
1106 * Handles the receipt of a Channel Info Results info frame.
1109 * wlandev wlan device structure
1110 * inf ptr to info frame (contents in hfa384x order)
1119 ----------------------------------------------------------------*/
1120 static void prism2sta_inf_chinforesults(wlandevice_t *wlandev,
1121 hfa384x_InfFrame_t *inf)
1123 hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
1126 hw->channel_info.results.scanchannels =
1127 le16_to_cpu(inf->info.chinforesult.scanchannels);
1129 for (i = 0, n = 0; i < HFA384x_CHINFORESULT_MAX; i++) {
1130 hfa384x_ChInfoResultSub_t *result;
1131 hfa384x_ChInfoResultSub_t *chinforesult;
1134 if (!(hw->channel_info.results.scanchannels & (1 << i)))
1137 result = &inf->info.chinforesult.result[n];
1138 chan = le16_to_cpu(result->chid) - 1;
1140 if (chan < 0 || chan >= HFA384x_CHINFORESULT_MAX)
1143 chinforesult = &hw->channel_info.results.result[chan];
1144 chinforesult->chid = chan;
1145 chinforesult->anl = le16_to_cpu(result->anl);
1146 chinforesult->pnl = le16_to_cpu(result->pnl);
1147 chinforesult->active = le16_to_cpu(result->active);
1149 pr_debug("chinfo: channel %d, %s level (avg/peak)=%d/%d dB, pcf %d\n",
1151 (chinforesult->active & HFA384x_CHINFORESULT_BSSACTIVE)
1152 ? "signal" : "noise",
1153 chinforesult->anl, chinforesult->pnl,
1154 (chinforesult->active & HFA384x_CHINFORESULT_PCFACTIVE)
1158 atomic_set(&hw->channel_info.done, 2);
1160 hw->channel_info.count = n;
1163 void prism2sta_processing_defer(struct work_struct *data)
1165 hfa384x_t *hw = container_of(data, struct hfa384x, link_bh);
1166 wlandevice_t *wlandev = hw->wlandev;
1167 hfa384x_bytestr32_t ssid;
1170 /* First let's process the auth frames */
1172 struct sk_buff *skb;
1173 hfa384x_InfFrame_t *inf;
1175 while ((skb = skb_dequeue(&hw->authq))) {
1176 inf = (hfa384x_InfFrame_t *) skb->data;
1177 prism2sta_inf_authreq_defer(wlandev, inf);
1182 /* Now let's handle the linkstatus stuff */
1183 if (hw->link_status == hw->link_status_new)
1186 hw->link_status = hw->link_status_new;
1188 switch (hw->link_status) {
1189 case HFA384x_LINK_NOTCONNECTED:
1190 /* I'm currently assuming that this is the initial link
1191 * state. It should only be possible immediately
1192 * following an Enable command.
1194 * Block Transmits, Ignore receives of data frames
1196 netif_carrier_off(wlandev->netdev);
1198 netdev_info(wlandev->netdev, "linkstatus=NOTCONNECTED (unhandled)\n");
1201 case HFA384x_LINK_CONNECTED:
1202 /* This one indicates a successful scan/join/auth/assoc.
1203 * When we have the full MLME complement, this event will
1204 * signify successful completion of both mlme_authenticate
1205 * and mlme_associate. State management will get a little
1208 * Indicate authentication and/or association
1209 * Enable Transmits, Receives and pass up data frames
1212 netif_carrier_on(wlandev->netdev);
1214 /* If we are joining a specific AP, set our
1215 * state and reset retries
1217 if (hw->join_ap == 1)
1219 hw->join_retries = 60;
1221 /* Don't call this in monitor mode */
1222 if (wlandev->netdev->type == ARPHRD_ETHER) {
1225 netdev_info(wlandev->netdev, "linkstatus=CONNECTED\n");
1227 /* For non-usb devices, we can use the sync versions */
1228 /* Collect the BSSID, and set state to allow tx */
1230 result = hfa384x_drvr_getconfig(hw,
1231 HFA384x_RID_CURRENTBSSID,
1236 ("getconfig(0x%02x) failed, result = %d\n",
1237 HFA384x_RID_CURRENTBSSID, result);
1241 result = hfa384x_drvr_getconfig(hw,
1242 HFA384x_RID_CURRENTSSID,
1243 &ssid, sizeof(ssid));
1246 ("getconfig(0x%02x) failed, result = %d\n",
1247 HFA384x_RID_CURRENTSSID, result);
1250 prism2mgmt_bytestr2pstr((struct hfa384x_bytestr *) &ssid,
1254 /* Collect the port status */
1255 result = hfa384x_drvr_getconfig16(hw,
1256 HFA384x_RID_PORTSTATUS,
1260 ("getconfig(0x%02x) failed, result = %d\n",
1261 HFA384x_RID_PORTSTATUS, result);
1265 (portstatus == HFA384x_PSTATUS_CONN_IBSS) ?
1266 WLAN_MACMODE_IBSS_STA : WLAN_MACMODE_ESS_STA;
1268 /* signal back up to cfg80211 layer */
1269 prism2_connect_result(wlandev, P80211ENUM_truth_false);
1271 /* Get the ball rolling on the comms quality stuff */
1272 prism2sta_commsqual_defer(&hw->commsqual_bh);
1276 case HFA384x_LINK_DISCONNECTED:
1277 /* This one indicates that our association is gone. We've
1278 * lost connection with the AP and/or been disassociated.
1279 * This indicates that the MAC has completely cleared it's
1280 * associated state. We * should send a deauth indication
1281 * (implying disassoc) up * to the MLME.
1283 * Indicate Deauthentication
1284 * Block Transmits, Ignore receives of data frames
1286 if (wlandev->netdev->type == ARPHRD_ETHER)
1287 netdev_info(wlandev->netdev,
1288 "linkstatus=DISCONNECTED (unhandled)\n");
1289 wlandev->macmode = WLAN_MACMODE_NONE;
1291 netif_carrier_off(wlandev->netdev);
1293 /* signal back up to cfg80211 layer */
1294 prism2_disconnected(wlandev);
1298 case HFA384x_LINK_AP_CHANGE:
1299 /* This one indicates that the MAC has decided to and
1300 * successfully completed a change to another AP. We
1301 * should probably implement a reassociation indication
1302 * in response to this one. I'm thinking that the the
1303 * p80211 layer needs to be notified in case of
1304 * buffering/queueing issues. User mode also needs to be
1305 * notified so that any BSS dependent elements can be
1307 * associated state. We * should send a deauth indication
1308 * (implying disassoc) up * to the MLME.
1310 * Indicate Reassociation
1311 * Enable Transmits, Receives and pass up data frames
1313 netdev_info(wlandev->netdev, "linkstatus=AP_CHANGE\n");
1315 result = hfa384x_drvr_getconfig(hw,
1316 HFA384x_RID_CURRENTBSSID,
1317 wlandev->bssid, WLAN_BSSID_LEN);
1319 pr_debug("getconfig(0x%02x) failed, result = %d\n",
1320 HFA384x_RID_CURRENTBSSID, result);
1324 result = hfa384x_drvr_getconfig(hw,
1325 HFA384x_RID_CURRENTSSID,
1326 &ssid, sizeof(ssid));
1328 pr_debug("getconfig(0x%02x) failed, result = %d\n",
1329 HFA384x_RID_CURRENTSSID, result);
1332 prism2mgmt_bytestr2pstr((struct hfa384x_bytestr *) &ssid,
1333 (p80211pstrd_t *) &wlandev->ssid);
1335 hw->link_status = HFA384x_LINK_CONNECTED;
1336 netif_carrier_on(wlandev->netdev);
1338 /* signal back up to cfg80211 layer */
1339 prism2_roamed(wlandev);
1343 case HFA384x_LINK_AP_OUTOFRANGE:
1344 /* This one indicates that the MAC has decided that the
1345 * AP is out of range, but hasn't found a better candidate
1346 * so the MAC maintains its "associated" state in case
1347 * we get back in range. We should block transmits and
1348 * receives in this state. Do we need an indication here?
1349 * Probably not since a polling user-mode element would
1350 * get this status from from p2PortStatus(FD40). What about
1353 * Block Transmits, Ignore receives of data frames
1355 netdev_info(wlandev->netdev, "linkstatus=AP_OUTOFRANGE (unhandled)\n");
1357 netif_carrier_off(wlandev->netdev);
1361 case HFA384x_LINK_AP_INRANGE:
1362 /* This one indicates that the MAC has decided that the
1363 * AP is back in range. We continue working with our
1364 * existing association.
1366 * Enable Transmits, Receives and pass up data frames
1368 netdev_info(wlandev->netdev, "linkstatus=AP_INRANGE\n");
1370 hw->link_status = HFA384x_LINK_CONNECTED;
1371 netif_carrier_on(wlandev->netdev);
1375 case HFA384x_LINK_ASSOCFAIL:
1376 /* This one is actually a peer to CONNECTED. We've
1377 * requested a join for a given SSID and optionally BSSID.
1378 * We can use this one to indicate authentication and
1379 * association failures. The trick is going to be
1380 * 1) identifying the failure, and 2) state management.
1382 * Disable Transmits, Ignore receives of data frames
1384 if (hw->join_ap && --hw->join_retries > 0) {
1385 hfa384x_JoinRequest_data_t joinreq;
1387 joinreq = hw->joinreq;
1388 /* Send the join request */
1389 hfa384x_drvr_setconfig(hw,
1390 HFA384x_RID_JOINREQUEST,
1392 HFA384x_RID_JOINREQUEST_LEN);
1393 netdev_info(wlandev->netdev,
1394 "linkstatus=ASSOCFAIL (re-submitting join)\n");
1396 netdev_info(wlandev->netdev, "linkstatus=ASSOCFAIL (unhandled)\n");
1399 netif_carrier_off(wlandev->netdev);
1401 /* signal back up to cfg80211 layer */
1402 prism2_connect_result(wlandev, P80211ENUM_truth_true);
1407 /* This is bad, IO port problems? */
1408 netdev_warn(wlandev->netdev,
1409 "unknown linkstatus=0x%02x\n", hw->link_status);
1413 wlandev->linkstatus = (hw->link_status == HFA384x_LINK_CONNECTED);
1416 /*----------------------------------------------------------------
1417 * prism2sta_inf_linkstatus
1419 * Handles the receipt of a Link Status info frame.
1422 * wlandev wlan device structure
1423 * inf ptr to info frame (contents in hfa384x order)
1432 ----------------------------------------------------------------*/
1433 static void prism2sta_inf_linkstatus(wlandevice_t *wlandev,
1434 hfa384x_InfFrame_t *inf)
1436 hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
1438 hw->link_status_new = le16_to_cpu(inf->info.linkstatus.linkstatus);
1440 schedule_work(&hw->link_bh);
1443 /*----------------------------------------------------------------
1444 * prism2sta_inf_assocstatus
1446 * Handles the receipt of an Association Status info frame. Should
1447 * be present in APs only.
1450 * wlandev wlan device structure
1451 * inf ptr to info frame (contents in hfa384x order)
1460 ----------------------------------------------------------------*/
1461 static void prism2sta_inf_assocstatus(wlandevice_t *wlandev,
1462 hfa384x_InfFrame_t *inf)
1464 hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
1465 hfa384x_AssocStatus_t rec;
1468 memcpy(&rec, &inf->info.assocstatus, sizeof(rec));
1469 rec.assocstatus = le16_to_cpu(rec.assocstatus);
1470 rec.reason = le16_to_cpu(rec.reason);
1473 ** Find the address in the list of authenticated stations.
1474 ** If it wasn't found, then this address has not been previously
1475 ** authenticated and something weird has happened if this is
1476 ** anything other than an "authentication failed" message.
1477 ** If the address was found, then set the "associated" flag for
1478 ** that station, based on whether the station is associating or
1479 ** losing its association. Something weird has also happened
1480 ** if we find the address in the list of authenticated stations
1481 ** but we are getting an "authentication failed" message.
1484 for (i = 0; i < hw->authlist.cnt; i++)
1485 if (memcmp(rec.sta_addr, hw->authlist.addr[i], ETH_ALEN) == 0)
1488 if (i >= hw->authlist.cnt) {
1489 if (rec.assocstatus != HFA384x_ASSOCSTATUS_AUTHFAIL)
1490 netdev_warn(wlandev->netdev,
1491 "assocstatus info frame received for non-authenticated station.\n");
1493 hw->authlist.assoc[i] =
1494 (rec.assocstatus == HFA384x_ASSOCSTATUS_STAASSOC ||
1495 rec.assocstatus == HFA384x_ASSOCSTATUS_REASSOC);
1497 if (rec.assocstatus == HFA384x_ASSOCSTATUS_AUTHFAIL)
1498 netdev_warn(wlandev->netdev,
1499 "authfail assocstatus info frame received for authenticated station.\n");
1503 /*----------------------------------------------------------------
1504 * prism2sta_inf_authreq
1506 * Handles the receipt of an Authentication Request info frame. Should
1507 * be present in APs only.
1510 * wlandev wlan device structure
1511 * inf ptr to info frame (contents in hfa384x order)
1521 ----------------------------------------------------------------*/
1522 static void prism2sta_inf_authreq(wlandevice_t *wlandev,
1523 hfa384x_InfFrame_t *inf)
1525 hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
1526 struct sk_buff *skb;
1528 skb = dev_alloc_skb(sizeof(*inf));
1530 skb_put(skb, sizeof(*inf));
1531 memcpy(skb->data, inf, sizeof(*inf));
1532 skb_queue_tail(&hw->authq, skb);
1533 schedule_work(&hw->link_bh);
1537 static void prism2sta_inf_authreq_defer(wlandevice_t *wlandev,
1538 hfa384x_InfFrame_t *inf)
1540 hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
1541 hfa384x_authenticateStation_data_t rec;
1543 int i, added, result, cnt;
1547 ** Build the AuthenticateStation record. Initialize it for denying
1551 memcpy(rec.address, inf->info.authreq.sta_addr, ETH_ALEN);
1552 rec.status = P80211ENUM_status_unspec_failure;
1555 ** Authenticate based on the access mode.
1558 switch (hw->accessmode) {
1559 case WLAN_ACCESS_NONE:
1562 ** Deny all new authentications. However, if a station
1563 ** is ALREADY authenticated, then accept it.
1566 for (i = 0; i < hw->authlist.cnt; i++)
1567 if (memcmp(rec.address, hw->authlist.addr[i],
1569 rec.status = P80211ENUM_status_successful;
1575 case WLAN_ACCESS_ALL:
1578 ** Allow all authentications.
1581 rec.status = P80211ENUM_status_successful;
1584 case WLAN_ACCESS_ALLOW:
1587 ** Only allow the authentication if the MAC address
1588 ** is in the list of allowed addresses.
1590 ** Since this is the interrupt handler, we may be here
1591 ** while the access list is in the middle of being
1592 ** updated. Choose the list which is currently okay.
1593 ** See "prism2mib_priv_accessallow()" for details.
1596 if (hw->allow.modify == 0) {
1597 cnt = hw->allow.cnt;
1598 addr = hw->allow.addr[0];
1600 cnt = hw->allow.cnt1;
1601 addr = hw->allow.addr1[0];
1604 for (i = 0; i < cnt; i++, addr += ETH_ALEN)
1605 if (memcmp(rec.address, addr, ETH_ALEN) == 0) {
1606 rec.status = P80211ENUM_status_successful;
1612 case WLAN_ACCESS_DENY:
1615 ** Allow the authentication UNLESS the MAC address is
1616 ** in the list of denied addresses.
1618 ** Since this is the interrupt handler, we may be here
1619 ** while the access list is in the middle of being
1620 ** updated. Choose the list which is currently okay.
1621 ** See "prism2mib_priv_accessdeny()" for details.
1624 if (hw->deny.modify == 0) {
1626 addr = hw->deny.addr[0];
1628 cnt = hw->deny.cnt1;
1629 addr = hw->deny.addr1[0];
1632 rec.status = P80211ENUM_status_successful;
1634 for (i = 0; i < cnt; i++, addr += ETH_ALEN)
1635 if (memcmp(rec.address, addr, ETH_ALEN) == 0) {
1636 rec.status = P80211ENUM_status_unspec_failure;
1644 ** If the authentication is okay, then add the MAC address to the
1645 ** list of authenticated stations. Don't add the address if it
1646 ** is already in the list. (802.11b does not seem to disallow
1647 ** a station from issuing an authentication request when the
1648 ** station is already authenticated. Does this sort of thing
1649 ** ever happen? We might as well do the check just in case.)
1654 if (rec.status == P80211ENUM_status_successful) {
1655 for (i = 0; i < hw->authlist.cnt; i++)
1656 if (memcmp(rec.address, hw->authlist.addr[i], ETH_ALEN)
1660 if (i >= hw->authlist.cnt) {
1661 if (hw->authlist.cnt >= WLAN_AUTH_MAX) {
1662 rec.status = P80211ENUM_status_ap_full;
1664 memcpy(hw->authlist.addr[hw->authlist.cnt],
1665 rec.address, ETH_ALEN);
1673 ** Send back the results of the authentication. If this doesn't work,
1674 ** then make sure to remove the address from the authenticated list if
1678 rec.status = cpu_to_le16(rec.status);
1679 rec.algorithm = inf->info.authreq.algorithm;
1681 result = hfa384x_drvr_setconfig(hw, HFA384x_RID_AUTHENTICATESTA,
1686 netdev_err(wlandev->netdev,
1687 "setconfig(authenticatestation) failed, result=%d\n",
1692 /*----------------------------------------------------------------
1693 * prism2sta_inf_psusercnt
1695 * Handles the receipt of a PowerSaveUserCount info frame. Should
1696 * be present in APs only.
1699 * wlandev wlan device structure
1700 * inf ptr to info frame (contents in hfa384x order)
1709 ----------------------------------------------------------------*/
1710 static void prism2sta_inf_psusercnt(wlandevice_t *wlandev,
1711 hfa384x_InfFrame_t *inf)
1713 hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
1715 hw->psusercount = le16_to_cpu(inf->info.psusercnt.usercnt);
1718 /*----------------------------------------------------------------
1721 * Handles the Info event.
1724 * wlandev wlan device structure
1725 * inf ptr to a generic info frame
1734 ----------------------------------------------------------------*/
1735 void prism2sta_ev_info(wlandevice_t *wlandev, hfa384x_InfFrame_t *inf)
1737 inf->infotype = le16_to_cpu(inf->infotype);
1739 switch (inf->infotype) {
1740 case HFA384x_IT_HANDOVERADDR:
1741 prism2sta_inf_handover(wlandev, inf);
1743 case HFA384x_IT_COMMTALLIES:
1744 prism2sta_inf_tallies(wlandev, inf);
1746 case HFA384x_IT_HOSTSCANRESULTS:
1747 prism2sta_inf_hostscanresults(wlandev, inf);
1749 case HFA384x_IT_SCANRESULTS:
1750 prism2sta_inf_scanresults(wlandev, inf);
1752 case HFA384x_IT_CHINFORESULTS:
1753 prism2sta_inf_chinforesults(wlandev, inf);
1755 case HFA384x_IT_LINKSTATUS:
1756 prism2sta_inf_linkstatus(wlandev, inf);
1758 case HFA384x_IT_ASSOCSTATUS:
1759 prism2sta_inf_assocstatus(wlandev, inf);
1761 case HFA384x_IT_AUTHREQ:
1762 prism2sta_inf_authreq(wlandev, inf);
1764 case HFA384x_IT_PSUSERCNT:
1765 prism2sta_inf_psusercnt(wlandev, inf);
1767 case HFA384x_IT_KEYIDCHANGED:
1768 netdev_warn(wlandev->netdev, "Unhandled IT_KEYIDCHANGED\n");
1770 case HFA384x_IT_ASSOCREQ:
1771 netdev_warn(wlandev->netdev, "Unhandled IT_ASSOCREQ\n");
1773 case HFA384x_IT_MICFAILURE:
1774 netdev_warn(wlandev->netdev, "Unhandled IT_MICFAILURE\n");
1777 netdev_warn(wlandev->netdev,
1778 "Unknown info type=0x%02x\n", inf->infotype);
1783 /*----------------------------------------------------------------
1784 * prism2sta_ev_txexc
1786 * Handles the TxExc event. A Transmit Exception event indicates
1787 * that the MAC's TX process was unsuccessful - so the packet did
1788 * not get transmitted.
1791 * wlandev wlan device structure
1792 * status tx frame status word
1801 ----------------------------------------------------------------*/
1802 void prism2sta_ev_txexc(wlandevice_t *wlandev, u16 status)
1804 pr_debug("TxExc status=0x%x.\n", status);
1807 /*----------------------------------------------------------------
1810 * Handles the Tx event.
1813 * wlandev wlan device structure
1814 * status tx frame status word
1822 ----------------------------------------------------------------*/
1823 void prism2sta_ev_tx(wlandevice_t *wlandev, u16 status)
1825 pr_debug("Tx Complete, status=0x%04x\n", status);
1826 /* update linux network stats */
1827 wlandev->netdev->stats.tx_packets++;
1830 /*----------------------------------------------------------------
1833 * Handles the Rx event.
1836 * wlandev wlan device structure
1845 ----------------------------------------------------------------*/
1846 void prism2sta_ev_rx(wlandevice_t *wlandev, struct sk_buff *skb)
1848 p80211netdev_rx(wlandev, skb);
1851 /*----------------------------------------------------------------
1852 * prism2sta_ev_alloc
1854 * Handles the Alloc event.
1857 * wlandev wlan device structure
1866 ----------------------------------------------------------------*/
1867 void prism2sta_ev_alloc(wlandevice_t *wlandev)
1869 netif_wake_queue(wlandev->netdev);
1872 /*----------------------------------------------------------------
1875 * Called at module init time. This creates the wlandevice_t structure
1876 * and initializes it with relevant bits.
1882 * the created wlandevice_t structure.
1885 * also allocates the priv/hw structures.
1890 ----------------------------------------------------------------*/
1891 static wlandevice_t *create_wlan(void)
1893 wlandevice_t *wlandev = NULL;
1894 hfa384x_t *hw = NULL;
1896 /* Alloc our structures */
1897 wlandev = kzalloc(sizeof(wlandevice_t), GFP_KERNEL);
1898 hw = kzalloc(sizeof(hfa384x_t), GFP_KERNEL);
1900 if (!wlandev || !hw) {
1901 pr_err("%s: Memory allocation failure.\n", dev_info);
1907 /* Initialize the network device object. */
1908 wlandev->nsdname = dev_info;
1909 wlandev->msdstate = WLAN_MSD_HWPRESENT_PENDING;
1911 wlandev->open = prism2sta_open;
1912 wlandev->close = prism2sta_close;
1913 wlandev->reset = prism2sta_reset;
1914 wlandev->txframe = prism2sta_txframe;
1915 wlandev->mlmerequest = prism2sta_mlmerequest;
1916 wlandev->set_multicast_list = prism2sta_setmulticast;
1917 wlandev->tx_timeout = hfa384x_tx_timeout;
1919 wlandev->nsdcaps = P80211_NSDCAP_HWFRAGMENT | P80211_NSDCAP_AUTOJOIN;
1921 /* Initialize the device private data structure. */
1922 hw->dot11_desired_bss_type = 1;
1927 void prism2sta_commsqual_defer(struct work_struct *data)
1929 hfa384x_t *hw = container_of(data, struct hfa384x, commsqual_bh);
1930 wlandevice_t *wlandev = hw->wlandev;
1931 hfa384x_bytestr32_t ssid;
1932 struct p80211msg_dot11req_mibget msg;
1933 p80211item_uint32_t *mibitem = (p80211item_uint32_t *)
1934 &msg.mibattribute.data;
1937 if (hw->wlandev->hwremoved)
1940 /* we don't care if we're in AP mode */
1941 if ((wlandev->macmode == WLAN_MACMODE_NONE) ||
1942 (wlandev->macmode == WLAN_MACMODE_ESS_AP)) {
1946 /* It only makes sense to poll these in non-IBSS */
1947 if (wlandev->macmode != WLAN_MACMODE_IBSS_STA) {
1948 result = hfa384x_drvr_getconfig(
1949 hw, HFA384x_RID_DBMCOMMSQUALITY,
1950 &hw->qual, HFA384x_RID_DBMCOMMSQUALITY_LEN);
1953 netdev_err(wlandev->netdev, "error fetching commsqual\n");
1957 pr_debug("commsqual %d %d %d\n",
1958 le16_to_cpu(hw->qual.CQ_currBSS),
1959 le16_to_cpu(hw->qual.ASL_currBSS),
1960 le16_to_cpu(hw->qual.ANL_currFC));
1963 /* Get the signal rate */
1964 msg.msgcode = DIDmsg_dot11req_mibget;
1965 mibitem->did = DIDmib_p2_p2MAC_p2CurrentTxRate;
1966 result = p80211req_dorequest(wlandev, (u8 *) &msg);
1969 pr_debug("get signal rate failed, result = %d\n",
1974 switch (mibitem->data) {
1975 case HFA384x_RATEBIT_1:
1978 case HFA384x_RATEBIT_2:
1981 case HFA384x_RATEBIT_5dot5:
1984 case HFA384x_RATEBIT_11:
1988 pr_debug("Bad ratebit (%d)\n", mibitem->data);
1991 /* Lastly, we need to make sure the BSSID didn't change on us */
1992 result = hfa384x_drvr_getconfig(hw,
1993 HFA384x_RID_CURRENTBSSID,
1994 wlandev->bssid, WLAN_BSSID_LEN);
1996 pr_debug("getconfig(0x%02x) failed, result = %d\n",
1997 HFA384x_RID_CURRENTBSSID, result);
2001 result = hfa384x_drvr_getconfig(hw,
2002 HFA384x_RID_CURRENTSSID,
2003 &ssid, sizeof(ssid));
2005 pr_debug("getconfig(0x%02x) failed, result = %d\n",
2006 HFA384x_RID_CURRENTSSID, result);
2009 prism2mgmt_bytestr2pstr((struct hfa384x_bytestr *) &ssid,
2010 (p80211pstrd_t *) &wlandev->ssid);
2012 /* Reschedule timer */
2013 mod_timer(&hw->commsqual_timer, jiffies + HZ);
2016 void prism2sta_commsqual_timer(unsigned long data)
2018 hfa384x_t *hw = (hfa384x_t *) data;
2020 schedule_work(&hw->commsqual_bh);