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/kernel.h>
55 #include <linux/sched.h>
56 #include <linux/types.h>
57 #include <linux/slab.h>
58 #include <linux/wireless.h>
59 #include <linux/netdevice.h>
60 #include <linux/workqueue.h>
61 #include <linux/byteorder/generic.h>
62 #include <linux/etherdevice.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 struct wlandevice *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(struct wlandevice *wlandev);
102 static int prism2sta_close(struct wlandevice *wlandev);
103 static void prism2sta_reset(struct wlandevice *wlandev);
104 static int prism2sta_txframe(struct wlandevice *wlandev, struct sk_buff *skb,
105 union p80211_hdr *p80211_hdr,
106 struct p80211_metawep *p80211_wep);
107 static int prism2sta_mlmerequest(struct wlandevice *wlandev,
108 struct p80211msg *msg);
109 static int prism2sta_getcardinfo(struct wlandevice *wlandev);
110 static int prism2sta_globalsetup(struct wlandevice *wlandev);
111 static int prism2sta_setmulticast(struct wlandevice *wlandev,
112 struct net_device *dev);
114 static void prism2sta_inf_handover(struct wlandevice *wlandev,
115 struct hfa384x_inf_frame *inf);
116 static void prism2sta_inf_tallies(struct wlandevice *wlandev,
117 struct hfa384x_inf_frame *inf);
118 static void prism2sta_inf_hostscanresults(struct wlandevice *wlandev,
119 struct hfa384x_inf_frame *inf);
120 static void prism2sta_inf_scanresults(struct wlandevice *wlandev,
121 struct hfa384x_inf_frame *inf);
122 static void prism2sta_inf_chinforesults(struct wlandevice *wlandev,
123 struct hfa384x_inf_frame *inf);
124 static void prism2sta_inf_linkstatus(struct wlandevice *wlandev,
125 struct hfa384x_inf_frame *inf);
126 static void prism2sta_inf_assocstatus(struct wlandevice *wlandev,
127 struct hfa384x_inf_frame *inf);
128 static void prism2sta_inf_authreq(struct wlandevice *wlandev,
129 struct hfa384x_inf_frame *inf);
130 static void prism2sta_inf_authreq_defer(struct wlandevice *wlandev,
131 struct hfa384x_inf_frame *inf);
132 static void prism2sta_inf_psusercnt(struct wlandevice *wlandev,
133 struct hfa384x_inf_frame *inf);
138 * WLAN device open method. Called from p80211netdev when kernel
139 * device open (start) method is called in response to the
140 * SIOCSIIFFLAGS ioctl changing the flags bit IFF_UP
144 * wlandev wlan device structure
148 * >0 f/w reported error
149 * <0 driver reported error
156 static int prism2sta_open(struct wlandevice *wlandev)
158 /* We don't currently have to do anything else.
159 * The setup of the MAC should be subsequently completed via
161 * Higher layers know we're ready from dev->start==1 and
162 * dev->tbusy==0. Our rx path knows to pass up received/
163 * frames because of dev->flags&IFF_UP is true.
172 * WLAN device close method. Called from p80211netdev when kernel
173 * device close method is called in response to the
174 * SIOCSIIFFLAGS ioctl changing the flags bit IFF_UP
178 * wlandev wlan device structure
182 * >0 f/w reported error
183 * <0 driver reported error
190 static int prism2sta_close(struct wlandevice *wlandev)
192 /* We don't currently have to do anything else.
193 * Higher layers know we're not ready from dev->start==0 and
194 * dev->tbusy==1. Our rx path knows to not pass up received
195 * frames because of dev->flags&IFF_UP is false.
204 * Currently not implemented.
207 * wlandev wlan device structure
218 static void prism2sta_reset(struct wlandevice *wlandev)
225 * Takes a frame from p80211 and queues it for transmission.
228 * wlandev wlan device structure
229 * pb packet buffer struct. Contains an 802.11
231 * p80211_hdr points to the 802.11 header for the packet.
233 * 0 Success and more buffs available
234 * 1 Success but no more buffs
235 * 2 Allocation failure
236 * 4 Buffer full or queue busy
243 static int prism2sta_txframe(struct wlandevice *wlandev, struct sk_buff *skb,
244 union p80211_hdr *p80211_hdr,
245 struct p80211_metawep *p80211_wep)
247 struct hfa384x *hw = wlandev->priv;
249 /* If necessary, set the 802.11 WEP bit */
250 if ((wlandev->hostwep & (HOSTWEP_PRIVACYINVOKED | HOSTWEP_ENCRYPT)) ==
251 HOSTWEP_PRIVACYINVOKED) {
252 p80211_hdr->a3.fc |= cpu_to_le16(WLAN_SET_FC_ISWEP(1));
255 return hfa384x_drvr_txframe(hw, skb, p80211_hdr, p80211_wep);
259 * prism2sta_mlmerequest
261 * wlan command message handler. All we do here is pass the message
262 * over to the prism2sta_mgmt_handler.
265 * wlandev wlan device structure
266 * msg wlan command message
269 * <0 successful acceptance of message, but we're
270 * waiting for an async process to finish before
271 * we're done with the msg. When the asynch
272 * process is done, we'll call the p80211
273 * function p80211req_confirm() .
274 * >0 An error occurred while we were handling
282 static int prism2sta_mlmerequest(struct wlandevice *wlandev,
283 struct p80211msg *msg)
285 struct hfa384x *hw = 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_curr_bss);
376 qualmsg->level.data =
377 le16_to_cpu(hw->qual.asl_curr_bss);
378 qualmsg->noise.data = le16_to_cpu(hw->qual.anl_curr_fc);
379 qualmsg->txrate.data = hw->txrate;
384 netdev_warn(wlandev->netdev,
385 "Unknown mgmt request message 0x%08x",
396 * Interface state. This is the primary WLAN interface enable/disable
397 * handler. Following the driver/load/deviceprobe sequence, this
398 * function must be called with a state of "enable" before any other
399 * commands will be accepted.
402 * wlandev wlan device structure
403 * msgp ptr to msg buffer
406 * A p80211 message resultcode value.
411 * process thread (usually)
414 u32 prism2sta_ifstate(struct wlandevice *wlandev, u32 ifstate)
416 struct hfa384x *hw = wlandev->priv;
419 result = P80211ENUM_resultcode_implementation_failure;
421 pr_debug("Current MSD state(%d), requesting(%d)\n",
422 wlandev->msdstate, ifstate);
424 case P80211ENUM_ifstate_fwload:
425 switch (wlandev->msdstate) {
426 case WLAN_MSD_HWPRESENT:
427 wlandev->msdstate = WLAN_MSD_FWLOAD_PENDING;
429 * Initialize the device+driver sufficiently
430 * for firmware loading.
432 result = hfa384x_drvr_start(hw);
434 netdev_err(wlandev->netdev,
435 "hfa384x_drvr_start() failed,result=%d\n",
438 P80211ENUM_resultcode_implementation_failure;
439 wlandev->msdstate = WLAN_MSD_HWPRESENT;
442 wlandev->msdstate = WLAN_MSD_FWLOAD;
443 result = P80211ENUM_resultcode_success;
445 case WLAN_MSD_FWLOAD:
446 hfa384x_cmd_initialize(hw);
447 result = P80211ENUM_resultcode_success;
449 case WLAN_MSD_RUNNING:
450 netdev_warn(wlandev->netdev,
451 "Cannot enter fwload state from enable state, you must disable first.\n");
452 result = P80211ENUM_resultcode_invalid_parameters;
454 case WLAN_MSD_HWFAIL:
456 /* probe() had a problem or the msdstate contains
457 * an unrecognized value, there's nothing we can do.
459 result = P80211ENUM_resultcode_implementation_failure;
463 case P80211ENUM_ifstate_enable:
464 switch (wlandev->msdstate) {
465 case WLAN_MSD_HWPRESENT:
466 case WLAN_MSD_FWLOAD:
467 wlandev->msdstate = WLAN_MSD_RUNNING_PENDING;
468 /* Initialize the device+driver for full
469 * operation. Note that this might me an FWLOAD to
470 * to RUNNING transition so we must not do a chip
471 * or board level reset. Note that on failure,
472 * the MSD state is set to HWPRESENT because we
473 * can't make any assumptions about the state
474 * of the hardware or a previous firmware load.
476 result = hfa384x_drvr_start(hw);
478 netdev_err(wlandev->netdev,
479 "hfa384x_drvr_start() failed,result=%d\n",
482 P80211ENUM_resultcode_implementation_failure;
483 wlandev->msdstate = WLAN_MSD_HWPRESENT;
487 result = prism2sta_getcardinfo(wlandev);
489 netdev_err(wlandev->netdev,
490 "prism2sta_getcardinfo() failed,result=%d\n",
493 P80211ENUM_resultcode_implementation_failure;
494 hfa384x_drvr_stop(hw);
495 wlandev->msdstate = WLAN_MSD_HWPRESENT;
498 result = prism2sta_globalsetup(wlandev);
500 netdev_err(wlandev->netdev,
501 "prism2sta_globalsetup() failed,result=%d\n",
504 P80211ENUM_resultcode_implementation_failure;
505 hfa384x_drvr_stop(hw);
506 wlandev->msdstate = WLAN_MSD_HWPRESENT;
509 wlandev->msdstate = WLAN_MSD_RUNNING;
511 hw->join_retries = 60;
512 result = P80211ENUM_resultcode_success;
514 case WLAN_MSD_RUNNING:
515 /* Do nothing, we're already in this state. */
516 result = P80211ENUM_resultcode_success;
518 case WLAN_MSD_HWFAIL:
520 /* probe() had a problem or the msdstate contains
521 * an unrecognized value, there's nothing we can do.
523 result = P80211ENUM_resultcode_implementation_failure;
527 case P80211ENUM_ifstate_disable:
528 switch (wlandev->msdstate) {
529 case WLAN_MSD_HWPRESENT:
530 /* Do nothing, we're already in this state. */
531 result = P80211ENUM_resultcode_success;
533 case WLAN_MSD_FWLOAD:
534 case WLAN_MSD_RUNNING:
535 wlandev->msdstate = WLAN_MSD_HWPRESENT_PENDING;
537 * TODO: Shut down the MAC completely. Here a chip
538 * or board level reset is probably called for.
539 * After a "disable" _all_ results are lost, even
540 * those from a fwload.
542 if (!wlandev->hwremoved)
543 netif_carrier_off(wlandev->netdev);
545 hfa384x_drvr_stop(hw);
547 wlandev->macmode = WLAN_MACMODE_NONE;
548 wlandev->msdstate = WLAN_MSD_HWPRESENT;
549 result = P80211ENUM_resultcode_success;
551 case WLAN_MSD_HWFAIL:
553 /* probe() had a problem or the msdstate contains
554 * an unrecognized value, there's nothing we can do.
556 result = P80211ENUM_resultcode_implementation_failure;
561 result = P80211ENUM_resultcode_invalid_parameters;
569 * prism2sta_getcardinfo
571 * Collect the NICID, firmware version and any other identifiers
572 * we'd like to have in host-side data structures.
575 * wlandev wlan device structure
579 * >0 f/w reported error
580 * <0 driver reported error
587 static int prism2sta_getcardinfo(struct wlandevice *wlandev)
590 struct hfa384x *hw = wlandev->priv;
592 u8 snum[HFA384x_RID_NICSERIALNUMBER_LEN];
594 /* Collect version and compatibility info */
595 /* Some are critical, some are not */
597 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_NICIDENTITY,
599 sizeof(struct hfa384x_compident));
601 netdev_err(wlandev->netdev, "Failed to retrieve NICIDENTITY\n");
605 /* get all the nic id fields in host byte order */
606 hw->ident_nic.id = le16_to_cpu(hw->ident_nic.id);
607 hw->ident_nic.variant = le16_to_cpu(hw->ident_nic.variant);
608 hw->ident_nic.major = le16_to_cpu(hw->ident_nic.major);
609 hw->ident_nic.minor = le16_to_cpu(hw->ident_nic.minor);
611 netdev_info(wlandev->netdev, "ident: nic h/w: id=0x%02x %d.%d.%d\n",
612 hw->ident_nic.id, hw->ident_nic.major,
613 hw->ident_nic.minor, hw->ident_nic.variant);
615 /* Primary f/w identity */
616 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_PRIIDENTITY,
618 sizeof(struct hfa384x_compident));
620 netdev_err(wlandev->netdev, "Failed to retrieve PRIIDENTITY\n");
624 /* get all the private fw id fields in host byte order */
625 hw->ident_pri_fw.id = le16_to_cpu(hw->ident_pri_fw.id);
626 hw->ident_pri_fw.variant = le16_to_cpu(hw->ident_pri_fw.variant);
627 hw->ident_pri_fw.major = le16_to_cpu(hw->ident_pri_fw.major);
628 hw->ident_pri_fw.minor = le16_to_cpu(hw->ident_pri_fw.minor);
630 netdev_info(wlandev->netdev, "ident: pri f/w: id=0x%02x %d.%d.%d\n",
631 hw->ident_pri_fw.id, hw->ident_pri_fw.major,
632 hw->ident_pri_fw.minor, hw->ident_pri_fw.variant);
634 /* Station (Secondary?) f/w identity */
635 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_STAIDENTITY,
637 sizeof(struct hfa384x_compident));
639 netdev_err(wlandev->netdev, "Failed to retrieve STAIDENTITY\n");
643 if (hw->ident_nic.id < 0x8000) {
644 netdev_err(wlandev->netdev,
645 "FATAL: Card is not an Intersil Prism2/2.5/3\n");
650 /* get all the station fw id fields in host byte order */
651 hw->ident_sta_fw.id = le16_to_cpu(hw->ident_sta_fw.id);
652 hw->ident_sta_fw.variant = le16_to_cpu(hw->ident_sta_fw.variant);
653 hw->ident_sta_fw.major = le16_to_cpu(hw->ident_sta_fw.major);
654 hw->ident_sta_fw.minor = le16_to_cpu(hw->ident_sta_fw.minor);
656 /* strip out the 'special' variant bits */
657 hw->mm_mods = hw->ident_sta_fw.variant & GENMASK(15, 14);
658 hw->ident_sta_fw.variant &= ~((u16)GENMASK(15, 14));
660 if (hw->ident_sta_fw.id == 0x1f) {
661 netdev_info(wlandev->netdev,
662 "ident: sta 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);
666 netdev_info(wlandev->netdev,
667 "ident: ap f/w: id=0x%02x %d.%d.%d\n",
668 hw->ident_sta_fw.id, hw->ident_sta_fw.major,
669 hw->ident_sta_fw.minor, hw->ident_sta_fw.variant);
670 netdev_err(wlandev->netdev, "Unsupported Tertiary AP firmware loaded!\n");
674 /* Compatibility range, Modem supplier */
675 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_MFISUPRANGE,
677 sizeof(struct hfa384x_caplevel));
679 netdev_err(wlandev->netdev, "Failed to retrieve MFISUPRANGE\n");
683 /* get all the Compatibility range, modem interface supplier
684 * fields in byte order
686 hw->cap_sup_mfi.role = le16_to_cpu(hw->cap_sup_mfi.role);
687 hw->cap_sup_mfi.id = le16_to_cpu(hw->cap_sup_mfi.id);
688 hw->cap_sup_mfi.variant = le16_to_cpu(hw->cap_sup_mfi.variant);
689 hw->cap_sup_mfi.bottom = le16_to_cpu(hw->cap_sup_mfi.bottom);
690 hw->cap_sup_mfi.top = le16_to_cpu(hw->cap_sup_mfi.top);
692 netdev_info(wlandev->netdev,
693 "MFI:SUP:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
694 hw->cap_sup_mfi.role, hw->cap_sup_mfi.id,
695 hw->cap_sup_mfi.variant, hw->cap_sup_mfi.bottom,
696 hw->cap_sup_mfi.top);
698 /* Compatibility range, Controller supplier */
699 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_CFISUPRANGE,
701 sizeof(struct hfa384x_caplevel));
703 netdev_err(wlandev->netdev, "Failed to retrieve CFISUPRANGE\n");
707 /* get all the Compatibility range, controller interface supplier
708 * fields in byte order
710 hw->cap_sup_cfi.role = le16_to_cpu(hw->cap_sup_cfi.role);
711 hw->cap_sup_cfi.id = le16_to_cpu(hw->cap_sup_cfi.id);
712 hw->cap_sup_cfi.variant = le16_to_cpu(hw->cap_sup_cfi.variant);
713 hw->cap_sup_cfi.bottom = le16_to_cpu(hw->cap_sup_cfi.bottom);
714 hw->cap_sup_cfi.top = le16_to_cpu(hw->cap_sup_cfi.top);
716 netdev_info(wlandev->netdev,
717 "CFI:SUP:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
718 hw->cap_sup_cfi.role, hw->cap_sup_cfi.id,
719 hw->cap_sup_cfi.variant, hw->cap_sup_cfi.bottom,
720 hw->cap_sup_cfi.top);
722 /* Compatibility range, Primary f/w supplier */
723 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_PRISUPRANGE,
725 sizeof(struct hfa384x_caplevel));
727 netdev_err(wlandev->netdev, "Failed to retrieve PRISUPRANGE\n");
731 /* get all the Compatibility range, primary firmware supplier
732 * fields in byte order
734 hw->cap_sup_pri.role = le16_to_cpu(hw->cap_sup_pri.role);
735 hw->cap_sup_pri.id = le16_to_cpu(hw->cap_sup_pri.id);
736 hw->cap_sup_pri.variant = le16_to_cpu(hw->cap_sup_pri.variant);
737 hw->cap_sup_pri.bottom = le16_to_cpu(hw->cap_sup_pri.bottom);
738 hw->cap_sup_pri.top = le16_to_cpu(hw->cap_sup_pri.top);
740 netdev_info(wlandev->netdev,
741 "PRI:SUP:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
742 hw->cap_sup_pri.role, hw->cap_sup_pri.id,
743 hw->cap_sup_pri.variant, hw->cap_sup_pri.bottom,
744 hw->cap_sup_pri.top);
746 /* Compatibility range, Station f/w supplier */
747 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_STASUPRANGE,
749 sizeof(struct hfa384x_caplevel));
751 netdev_err(wlandev->netdev, "Failed to retrieve STASUPRANGE\n");
755 /* get all the Compatibility range, station firmware supplier
756 * fields in byte order
758 hw->cap_sup_sta.role = le16_to_cpu(hw->cap_sup_sta.role);
759 hw->cap_sup_sta.id = le16_to_cpu(hw->cap_sup_sta.id);
760 hw->cap_sup_sta.variant = le16_to_cpu(hw->cap_sup_sta.variant);
761 hw->cap_sup_sta.bottom = le16_to_cpu(hw->cap_sup_sta.bottom);
762 hw->cap_sup_sta.top = le16_to_cpu(hw->cap_sup_sta.top);
764 if (hw->cap_sup_sta.id == 0x04) {
765 netdev_info(wlandev->netdev,
766 "STA:SUP:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
767 hw->cap_sup_sta.role, hw->cap_sup_sta.id,
768 hw->cap_sup_sta.variant, hw->cap_sup_sta.bottom,
769 hw->cap_sup_sta.top);
771 netdev_info(wlandev->netdev,
772 "AP:SUP:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
773 hw->cap_sup_sta.role, hw->cap_sup_sta.id,
774 hw->cap_sup_sta.variant, hw->cap_sup_sta.bottom,
775 hw->cap_sup_sta.top);
778 /* Compatibility range, primary f/w actor, CFI supplier */
779 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_PRI_CFIACTRANGES,
780 &hw->cap_act_pri_cfi,
781 sizeof(struct hfa384x_caplevel));
783 netdev_err(wlandev->netdev, "Failed to retrieve PRI_CFIACTRANGES\n");
787 /* get all the Compatibility range, primary f/w actor, CFI supplier
788 * fields in byte order
790 hw->cap_act_pri_cfi.role = le16_to_cpu(hw->cap_act_pri_cfi.role);
791 hw->cap_act_pri_cfi.id = le16_to_cpu(hw->cap_act_pri_cfi.id);
792 hw->cap_act_pri_cfi.variant = le16_to_cpu(hw->cap_act_pri_cfi.variant);
793 hw->cap_act_pri_cfi.bottom = le16_to_cpu(hw->cap_act_pri_cfi.bottom);
794 hw->cap_act_pri_cfi.top = le16_to_cpu(hw->cap_act_pri_cfi.top);
796 netdev_info(wlandev->netdev,
797 "PRI-CFI:ACT:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
798 hw->cap_act_pri_cfi.role, hw->cap_act_pri_cfi.id,
799 hw->cap_act_pri_cfi.variant, hw->cap_act_pri_cfi.bottom,
800 hw->cap_act_pri_cfi.top);
802 /* Compatibility range, sta f/w actor, CFI supplier */
803 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_STA_CFIACTRANGES,
804 &hw->cap_act_sta_cfi,
805 sizeof(struct hfa384x_caplevel));
807 netdev_err(wlandev->netdev, "Failed to retrieve STA_CFIACTRANGES\n");
811 /* get all the Compatibility range, station f/w actor, CFI supplier
812 * fields in byte order
814 hw->cap_act_sta_cfi.role = le16_to_cpu(hw->cap_act_sta_cfi.role);
815 hw->cap_act_sta_cfi.id = le16_to_cpu(hw->cap_act_sta_cfi.id);
816 hw->cap_act_sta_cfi.variant = le16_to_cpu(hw->cap_act_sta_cfi.variant);
817 hw->cap_act_sta_cfi.bottom = le16_to_cpu(hw->cap_act_sta_cfi.bottom);
818 hw->cap_act_sta_cfi.top = le16_to_cpu(hw->cap_act_sta_cfi.top);
820 netdev_info(wlandev->netdev,
821 "STA-CFI:ACT:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
822 hw->cap_act_sta_cfi.role, hw->cap_act_sta_cfi.id,
823 hw->cap_act_sta_cfi.variant, hw->cap_act_sta_cfi.bottom,
824 hw->cap_act_sta_cfi.top);
826 /* Compatibility range, sta f/w actor, MFI supplier */
827 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_STA_MFIACTRANGES,
828 &hw->cap_act_sta_mfi,
829 sizeof(struct hfa384x_caplevel));
831 netdev_err(wlandev->netdev, "Failed to retrieve STA_MFIACTRANGES\n");
835 /* get all the Compatibility range, station f/w actor, MFI supplier
836 * fields in byte order
838 hw->cap_act_sta_mfi.role = le16_to_cpu(hw->cap_act_sta_mfi.role);
839 hw->cap_act_sta_mfi.id = le16_to_cpu(hw->cap_act_sta_mfi.id);
840 hw->cap_act_sta_mfi.variant = le16_to_cpu(hw->cap_act_sta_mfi.variant);
841 hw->cap_act_sta_mfi.bottom = le16_to_cpu(hw->cap_act_sta_mfi.bottom);
842 hw->cap_act_sta_mfi.top = le16_to_cpu(hw->cap_act_sta_mfi.top);
844 netdev_info(wlandev->netdev,
845 "STA-MFI:ACT:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
846 hw->cap_act_sta_mfi.role, hw->cap_act_sta_mfi.id,
847 hw->cap_act_sta_mfi.variant, hw->cap_act_sta_mfi.bottom,
848 hw->cap_act_sta_mfi.top);
851 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_NICSERIALNUMBER,
852 snum, HFA384x_RID_NICSERIALNUMBER_LEN);
854 netdev_info(wlandev->netdev, "Prism2 card SN: %*pEhp\n",
855 HFA384x_RID_NICSERIALNUMBER_LEN, snum);
857 netdev_err(wlandev->netdev, "Failed to retrieve Prism2 Card SN\n");
861 /* Collect the MAC address */
862 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_CNFOWNMACADDR,
863 wlandev->netdev->dev_addr, ETH_ALEN);
865 netdev_err(wlandev->netdev, "Failed to retrieve mac address\n");
869 /* short preamble is always implemented */
870 wlandev->nsdcaps |= P80211_NSDCAP_SHORT_PREAMBLE;
872 /* find out if hardware wep is implemented */
873 hfa384x_drvr_getconfig16(hw, HFA384x_RID_PRIVACYOPTIMP, &temp);
875 wlandev->nsdcaps |= P80211_NSDCAP_HARDWAREWEP;
877 /* get the dBm Scaling constant */
878 hfa384x_drvr_getconfig16(hw, HFA384x_RID_CNFDBMADJUST, &temp);
879 hw->dbmadjust = temp;
881 /* Only enable scan by default on newer firmware */
882 if (HFA384x_FIRMWARE_VERSION(hw->ident_sta_fw.major,
883 hw->ident_sta_fw.minor,
884 hw->ident_sta_fw.variant) <
885 HFA384x_FIRMWARE_VERSION(1, 5, 5)) {
886 wlandev->nsdcaps |= P80211_NSDCAP_NOSCAN;
889 /* TODO: Set any internally managed config items */
893 netdev_err(wlandev->netdev, "Failed, result=%d\n", result);
899 * prism2sta_globalsetup
901 * Set any global RIDs that we want to set at device activation.
904 * wlandev wlan device structure
908 * >0 f/w reported error
909 * <0 driver reported error
916 static int prism2sta_globalsetup(struct wlandevice *wlandev)
918 struct hfa384x *hw = wlandev->priv;
920 /* Set the maximum frame size */
921 return hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFMAXDATALEN,
925 static int prism2sta_setmulticast(struct wlandevice *wlandev,
926 struct net_device *dev)
929 struct hfa384x *hw = wlandev->priv;
933 /* If we're not ready, what's the point? */
934 if (hw->state != HFA384x_STATE_RUNNING)
937 if ((dev->flags & (IFF_PROMISC | IFF_ALLMULTI)) != 0)
938 promisc = P80211ENUM_truth_true;
940 promisc = P80211ENUM_truth_false;
943 hfa384x_drvr_setconfig16_async(hw, HFA384x_RID_PROMISCMODE,
950 * prism2sta_inf_handover
952 * Handles the receipt of a Handover info frame. Should only be present
956 * wlandev wlan device structure
957 * inf ptr to info frame (contents in hfa384x order)
967 static void prism2sta_inf_handover(struct wlandevice *wlandev,
968 struct hfa384x_inf_frame *inf)
970 pr_debug("received infoframe:HANDOVER (unhandled)\n");
974 * prism2sta_inf_tallies
976 * Handles the receipt of a CommTallies info frame.
979 * wlandev wlan device structure
980 * inf ptr to info frame (contents in hfa384x order)
990 static void prism2sta_inf_tallies(struct wlandevice *wlandev,
991 struct hfa384x_inf_frame *inf)
993 struct hfa384x *hw = wlandev->priv;
1001 * Determine if these are 16-bit or 32-bit tallies, based on the
1002 * record length of the info record.
1005 cnt = sizeof(struct hfa384x_comm_tallies_32) / sizeof(u32);
1006 if (inf->framelen > 22) {
1007 dst = (u32 *)&hw->tallies;
1008 src32 = (u32 *)&inf->info.commtallies32;
1009 for (i = 0; i < cnt; i++, dst++, src32++)
1010 *dst += le32_to_cpu(*src32);
1012 dst = (u32 *)&hw->tallies;
1013 src16 = (u16 *)&inf->info.commtallies16;
1014 for (i = 0; i < cnt; i++, dst++, src16++)
1015 *dst += le16_to_cpu(*src16);
1020 * prism2sta_inf_scanresults
1022 * Handles the receipt of a Scan Results info frame.
1025 * wlandev wlan device structure
1026 * inf ptr to info frame (contents in hfa384x order)
1036 static void prism2sta_inf_scanresults(struct wlandevice *wlandev,
1037 struct hfa384x_inf_frame *inf)
1039 struct hfa384x *hw = wlandev->priv;
1041 struct hfa384x_scan_result *sr = &inf->info.scanresult;
1043 struct hfa384x_join_request_data joinreq;
1046 /* Get the number of results, first in bytes, then in results */
1047 nbss = (inf->framelen * sizeof(u16)) -
1048 sizeof(inf->infotype) - sizeof(inf->info.scanresult.scanreason);
1049 nbss /= sizeof(struct hfa384x_scan_result_sub);
1052 pr_debug("rx scanresults, reason=%d, nbss=%d:\n",
1053 inf->info.scanresult.scanreason, nbss);
1054 for (i = 0; i < nbss; i++) {
1055 pr_debug("chid=%d anl=%d sl=%d bcnint=%d\n",
1058 sr->result[i].sl, sr->result[i].bcnint);
1059 pr_debug(" capinfo=0x%04x proberesp_rate=%d\n",
1060 sr->result[i].capinfo, sr->result[i].proberesp_rate);
1062 /* issue a join request */
1063 joinreq.channel = sr->result[0].chid;
1064 memcpy(joinreq.bssid, sr->result[0].bssid, WLAN_BSSID_LEN);
1065 result = hfa384x_drvr_setconfig(hw,
1066 HFA384x_RID_JOINREQUEST,
1067 &joinreq, HFA384x_RID_JOINREQUEST_LEN);
1069 netdev_err(wlandev->netdev, "setconfig(joinreq) failed, result=%d\n",
1075 * prism2sta_inf_hostscanresults
1077 * Handles the receipt of a Scan Results info frame.
1080 * wlandev wlan device structure
1081 * inf ptr to info frame (contents in hfa384x order)
1091 static void prism2sta_inf_hostscanresults(struct wlandevice *wlandev,
1092 struct hfa384x_inf_frame *inf)
1094 struct hfa384x *hw = wlandev->priv;
1097 nbss = (inf->framelen - 3) / 32;
1098 pr_debug("Received %d hostscan results\n", nbss);
1103 kfree(hw->scanresults);
1105 hw->scanresults = kmemdup(inf, sizeof(*inf), GFP_ATOMIC);
1110 /* Notify/wake the sleeping caller. */
1111 hw->scanflag = nbss;
1112 wake_up_interruptible(&hw->cmdq);
1116 * prism2sta_inf_chinforesults
1118 * Handles the receipt of a Channel Info Results info frame.
1121 * wlandev wlan device structure
1122 * inf ptr to info frame (contents in hfa384x order)
1132 static void prism2sta_inf_chinforesults(struct wlandevice *wlandev,
1133 struct hfa384x_inf_frame *inf)
1135 struct hfa384x *hw = wlandev->priv;
1138 hw->channel_info.results.scanchannels =
1139 le16_to_cpu(inf->info.chinforesult.scanchannels);
1141 for (i = 0, n = 0; i < HFA384x_CHINFORESULT_MAX; i++) {
1142 struct hfa384x_ch_info_result_sub *result;
1143 struct hfa384x_ch_info_result_sub *chinforesult;
1146 if (!(hw->channel_info.results.scanchannels & (1 << i)))
1149 result = &inf->info.chinforesult.result[n];
1150 chan = le16_to_cpu(result->chid) - 1;
1152 if (chan < 0 || chan >= HFA384x_CHINFORESULT_MAX)
1155 chinforesult = &hw->channel_info.results.result[chan];
1156 chinforesult->chid = chan;
1157 chinforesult->anl = le16_to_cpu(result->anl);
1158 chinforesult->pnl = le16_to_cpu(result->pnl);
1159 chinforesult->active = le16_to_cpu(result->active);
1161 pr_debug("chinfo: channel %d, %s level (avg/peak)=%d/%d dB, pcf %d\n",
1163 (chinforesult->active & HFA384x_CHINFORESULT_BSSACTIVE)
1164 ? "signal" : "noise",
1165 chinforesult->anl, chinforesult->pnl,
1166 (chinforesult->active & HFA384x_CHINFORESULT_PCFACTIVE)
1170 atomic_set(&hw->channel_info.done, 2);
1172 hw->channel_info.count = n;
1175 void prism2sta_processing_defer(struct work_struct *data)
1177 struct hfa384x *hw = container_of(data, struct hfa384x, link_bh);
1178 struct wlandevice *wlandev = hw->wlandev;
1179 struct hfa384x_bytestr32 ssid;
1182 /* First let's process the auth frames */
1184 struct sk_buff *skb;
1185 struct hfa384x_inf_frame *inf;
1187 while ((skb = skb_dequeue(&hw->authq))) {
1188 inf = (struct hfa384x_inf_frame *)skb->data;
1189 prism2sta_inf_authreq_defer(wlandev, inf);
1194 /* Now let's handle the linkstatus stuff */
1195 if (hw->link_status == hw->link_status_new)
1198 hw->link_status = hw->link_status_new;
1200 switch (hw->link_status) {
1201 case HFA384x_LINK_NOTCONNECTED:
1202 /* I'm currently assuming that this is the initial link
1203 * state. It should only be possible immediately
1204 * following an Enable command.
1206 * Block Transmits, Ignore receives of data frames
1208 netif_carrier_off(wlandev->netdev);
1210 netdev_info(wlandev->netdev, "linkstatus=NOTCONNECTED (unhandled)\n");
1213 case HFA384x_LINK_CONNECTED:
1214 /* This one indicates a successful scan/join/auth/assoc.
1215 * When we have the full MLME complement, this event will
1216 * signify successful completion of both mlme_authenticate
1217 * and mlme_associate. State management will get a little
1220 * Indicate authentication and/or association
1221 * Enable Transmits, Receives and pass up data frames
1224 netif_carrier_on(wlandev->netdev);
1226 /* If we are joining a specific AP, set our
1227 * state and reset retries
1229 if (hw->join_ap == 1)
1231 hw->join_retries = 60;
1233 /* Don't call this in monitor mode */
1234 if (wlandev->netdev->type == ARPHRD_ETHER) {
1237 netdev_info(wlandev->netdev, "linkstatus=CONNECTED\n");
1239 /* For non-usb devices, we can use the sync versions */
1240 /* Collect the BSSID, and set state to allow tx */
1242 result = hfa384x_drvr_getconfig(hw,
1243 HFA384x_RID_CURRENTBSSID,
1248 ("getconfig(0x%02x) failed, result = %d\n",
1249 HFA384x_RID_CURRENTBSSID, result);
1253 result = hfa384x_drvr_getconfig(hw,
1254 HFA384x_RID_CURRENTSSID,
1255 &ssid, sizeof(ssid));
1258 ("getconfig(0x%02x) failed, result = %d\n",
1259 HFA384x_RID_CURRENTSSID, result);
1262 prism2mgmt_bytestr2pstr(
1263 (struct hfa384x_bytestr *)&ssid,
1264 (struct p80211pstrd *)&wlandev->ssid);
1266 /* Collect the port status */
1267 result = hfa384x_drvr_getconfig16(hw,
1268 HFA384x_RID_PORTSTATUS,
1272 ("getconfig(0x%02x) failed, result = %d\n",
1273 HFA384x_RID_PORTSTATUS, result);
1277 (portstatus == HFA384x_PSTATUS_CONN_IBSS) ?
1278 WLAN_MACMODE_IBSS_STA : WLAN_MACMODE_ESS_STA;
1280 /* signal back up to cfg80211 layer */
1281 prism2_connect_result(wlandev, P80211ENUM_truth_false);
1283 /* Get the ball rolling on the comms quality stuff */
1284 prism2sta_commsqual_defer(&hw->commsqual_bh);
1288 case HFA384x_LINK_DISCONNECTED:
1289 /* This one indicates that our association is gone. We've
1290 * lost connection with the AP and/or been disassociated.
1291 * This indicates that the MAC has completely cleared it's
1292 * associated state. We * should send a deauth indication
1293 * (implying disassoc) up * to the MLME.
1295 * Indicate Deauthentication
1296 * Block Transmits, Ignore receives of data frames
1298 if (wlandev->netdev->type == ARPHRD_ETHER)
1299 netdev_info(wlandev->netdev,
1300 "linkstatus=DISCONNECTED (unhandled)\n");
1301 wlandev->macmode = WLAN_MACMODE_NONE;
1303 netif_carrier_off(wlandev->netdev);
1305 /* signal back up to cfg80211 layer */
1306 prism2_disconnected(wlandev);
1310 case HFA384x_LINK_AP_CHANGE:
1311 /* This one indicates that the MAC has decided to and
1312 * successfully completed a change to another AP. We
1313 * should probably implement a reassociation indication
1314 * in response to this one. I'm thinking that the the
1315 * p80211 layer needs to be notified in case of
1316 * buffering/queueing issues. User mode also needs to be
1317 * notified so that any BSS dependent elements can be
1319 * associated state. We * should send a deauth indication
1320 * (implying disassoc) up * to the MLME.
1322 * Indicate Reassociation
1323 * Enable Transmits, Receives and pass up data frames
1325 netdev_info(wlandev->netdev, "linkstatus=AP_CHANGE\n");
1327 result = hfa384x_drvr_getconfig(hw,
1328 HFA384x_RID_CURRENTBSSID,
1329 wlandev->bssid, WLAN_BSSID_LEN);
1331 pr_debug("getconfig(0x%02x) failed, result = %d\n",
1332 HFA384x_RID_CURRENTBSSID, result);
1336 result = hfa384x_drvr_getconfig(hw,
1337 HFA384x_RID_CURRENTSSID,
1338 &ssid, sizeof(ssid));
1340 pr_debug("getconfig(0x%02x) failed, result = %d\n",
1341 HFA384x_RID_CURRENTSSID, result);
1344 prism2mgmt_bytestr2pstr((struct hfa384x_bytestr *)&ssid,
1345 (struct p80211pstrd *)&wlandev->ssid);
1347 hw->link_status = HFA384x_LINK_CONNECTED;
1348 netif_carrier_on(wlandev->netdev);
1350 /* signal back up to cfg80211 layer */
1351 prism2_roamed(wlandev);
1355 case HFA384x_LINK_AP_OUTOFRANGE:
1356 /* This one indicates that the MAC has decided that the
1357 * AP is out of range, but hasn't found a better candidate
1358 * so the MAC maintains its "associated" state in case
1359 * we get back in range. We should block transmits and
1360 * receives in this state. Do we need an indication here?
1361 * Probably not since a polling user-mode element would
1362 * get this status from from p2PortStatus(FD40). What about
1365 * Block Transmits, Ignore receives of data frames
1367 netdev_info(wlandev->netdev, "linkstatus=AP_OUTOFRANGE (unhandled)\n");
1369 netif_carrier_off(wlandev->netdev);
1373 case HFA384x_LINK_AP_INRANGE:
1374 /* This one indicates that the MAC has decided that the
1375 * AP is back in range. We continue working with our
1376 * existing association.
1378 * Enable Transmits, Receives and pass up data frames
1380 netdev_info(wlandev->netdev, "linkstatus=AP_INRANGE\n");
1382 hw->link_status = HFA384x_LINK_CONNECTED;
1383 netif_carrier_on(wlandev->netdev);
1387 case HFA384x_LINK_ASSOCFAIL:
1388 /* This one is actually a peer to CONNECTED. We've
1389 * requested a join for a given SSID and optionally BSSID.
1390 * We can use this one to indicate authentication and
1391 * association failures. The trick is going to be
1392 * 1) identifying the failure, and 2) state management.
1394 * Disable Transmits, Ignore receives of data frames
1396 if (hw->join_ap && --hw->join_retries > 0) {
1397 struct hfa384x_join_request_data joinreq;
1399 joinreq = hw->joinreq;
1400 /* Send the join request */
1401 hfa384x_drvr_setconfig(hw,
1402 HFA384x_RID_JOINREQUEST,
1404 HFA384x_RID_JOINREQUEST_LEN);
1405 netdev_info(wlandev->netdev,
1406 "linkstatus=ASSOCFAIL (re-submitting join)\n");
1408 netdev_info(wlandev->netdev, "linkstatus=ASSOCFAIL (unhandled)\n");
1411 netif_carrier_off(wlandev->netdev);
1413 /* signal back up to cfg80211 layer */
1414 prism2_connect_result(wlandev, P80211ENUM_truth_true);
1419 /* This is bad, IO port problems? */
1420 netdev_warn(wlandev->netdev,
1421 "unknown linkstatus=0x%02x\n", hw->link_status);
1425 wlandev->linkstatus = (hw->link_status == HFA384x_LINK_CONNECTED);
1429 * prism2sta_inf_linkstatus
1431 * Handles the receipt of a Link Status info frame.
1434 * wlandev wlan device structure
1435 * inf ptr to info frame (contents in hfa384x order)
1445 static void prism2sta_inf_linkstatus(struct wlandevice *wlandev,
1446 struct hfa384x_inf_frame *inf)
1448 struct hfa384x *hw = wlandev->priv;
1450 hw->link_status_new = le16_to_cpu(inf->info.linkstatus.linkstatus);
1452 schedule_work(&hw->link_bh);
1456 * prism2sta_inf_assocstatus
1458 * Handles the receipt of an Association Status info frame. Should
1459 * be present in APs only.
1462 * wlandev wlan device structure
1463 * inf ptr to info frame (contents in hfa384x order)
1473 static void prism2sta_inf_assocstatus(struct wlandevice *wlandev,
1474 struct hfa384x_inf_frame *inf)
1476 struct hfa384x *hw = wlandev->priv;
1477 struct hfa384x_assoc_status rec;
1480 memcpy(&rec, &inf->info.assocstatus, sizeof(rec));
1481 rec.assocstatus = le16_to_cpu(rec.assocstatus);
1482 rec.reason = le16_to_cpu(rec.reason);
1485 * Find the address in the list of authenticated stations.
1486 * If it wasn't found, then this address has not been previously
1487 * authenticated and something weird has happened if this is
1488 * anything other than an "authentication failed" message.
1489 * If the address was found, then set the "associated" flag for
1490 * that station, based on whether the station is associating or
1491 * losing its association. Something weird has also happened
1492 * if we find the address in the list of authenticated stations
1493 * but we are getting an "authentication failed" message.
1496 for (i = 0; i < hw->authlist.cnt; i++)
1497 if (ether_addr_equal(rec.sta_addr, hw->authlist.addr[i]))
1500 if (i >= hw->authlist.cnt) {
1501 if (rec.assocstatus != HFA384x_ASSOCSTATUS_AUTHFAIL)
1502 netdev_warn(wlandev->netdev,
1503 "assocstatus info frame received for non-authenticated station.\n");
1505 hw->authlist.assoc[i] =
1506 (rec.assocstatus == HFA384x_ASSOCSTATUS_STAASSOC ||
1507 rec.assocstatus == HFA384x_ASSOCSTATUS_REASSOC);
1509 if (rec.assocstatus == HFA384x_ASSOCSTATUS_AUTHFAIL)
1510 netdev_warn(wlandev->netdev,
1511 "authfail assocstatus info frame received for authenticated station.\n");
1516 * prism2sta_inf_authreq
1518 * Handles the receipt of an Authentication Request info frame. Should
1519 * be present in APs only.
1522 * wlandev wlan device structure
1523 * inf ptr to info frame (contents in hfa384x order)
1534 static void prism2sta_inf_authreq(struct wlandevice *wlandev,
1535 struct hfa384x_inf_frame *inf)
1537 struct hfa384x *hw = wlandev->priv;
1538 struct sk_buff *skb;
1540 skb = dev_alloc_skb(sizeof(*inf));
1542 skb_put(skb, sizeof(*inf));
1543 memcpy(skb->data, inf, sizeof(*inf));
1544 skb_queue_tail(&hw->authq, skb);
1545 schedule_work(&hw->link_bh);
1549 static void prism2sta_inf_authreq_defer(struct wlandevice *wlandev,
1550 struct hfa384x_inf_frame *inf)
1552 struct hfa384x *hw = wlandev->priv;
1553 struct hfa384x_authenticate_station_data rec;
1555 int i, added, result, cnt;
1559 * Build the AuthenticateStation record. Initialize it for denying
1563 ether_addr_copy(rec.address, inf->info.authreq.sta_addr);
1564 rec.status = P80211ENUM_status_unspec_failure;
1567 * Authenticate based on the access mode.
1570 switch (hw->accessmode) {
1571 case WLAN_ACCESS_NONE:
1574 * Deny all new authentications. However, if a station
1575 * is ALREADY authenticated, then accept it.
1578 for (i = 0; i < hw->authlist.cnt; i++)
1579 if (ether_addr_equal(rec.address,
1580 hw->authlist.addr[i])) {
1581 rec.status = P80211ENUM_status_successful;
1587 case WLAN_ACCESS_ALL:
1590 * Allow all authentications.
1593 rec.status = P80211ENUM_status_successful;
1596 case WLAN_ACCESS_ALLOW:
1599 * Only allow the authentication if the MAC address
1600 * is in the list of allowed addresses.
1602 * Since this is the interrupt handler, we may be here
1603 * while the access list is in the middle of being
1604 * updated. Choose the list which is currently okay.
1605 * See "prism2mib_priv_accessallow()" for details.
1608 if (hw->allow.modify == 0) {
1609 cnt = hw->allow.cnt;
1610 addr = hw->allow.addr[0];
1612 cnt = hw->allow.cnt1;
1613 addr = hw->allow.addr1[0];
1616 for (i = 0; i < cnt; i++, addr += ETH_ALEN)
1617 if (ether_addr_equal(rec.address, addr)) {
1618 rec.status = P80211ENUM_status_successful;
1624 case WLAN_ACCESS_DENY:
1627 * Allow the authentication UNLESS the MAC address is
1628 * in the list of denied addresses.
1630 * Since this is the interrupt handler, we may be here
1631 * while the access list is in the middle of being
1632 * updated. Choose the list which is currently okay.
1633 * See "prism2mib_priv_accessdeny()" for details.
1636 if (hw->deny.modify == 0) {
1638 addr = hw->deny.addr[0];
1640 cnt = hw->deny.cnt1;
1641 addr = hw->deny.addr1[0];
1644 rec.status = P80211ENUM_status_successful;
1646 for (i = 0; i < cnt; i++, addr += ETH_ALEN)
1647 if (ether_addr_equal(rec.address, addr)) {
1648 rec.status = P80211ENUM_status_unspec_failure;
1656 * If the authentication is okay, then add the MAC address to the
1657 * list of authenticated stations. Don't add the address if it
1658 * is already in the list. (802.11b does not seem to disallow
1659 * a station from issuing an authentication request when the
1660 * station is already authenticated. Does this sort of thing
1661 * ever happen? We might as well do the check just in case.)
1666 if (rec.status == P80211ENUM_status_successful) {
1667 for (i = 0; i < hw->authlist.cnt; i++)
1668 if (ether_addr_equal(rec.address,
1669 hw->authlist.addr[i]))
1672 if (i >= hw->authlist.cnt) {
1673 if (hw->authlist.cnt >= WLAN_AUTH_MAX) {
1674 rec.status = P80211ENUM_status_ap_full;
1677 hw->authlist.addr[hw->authlist.cnt],
1686 * Send back the results of the authentication. If this doesn't work,
1687 * then make sure to remove the address from the authenticated list if
1691 rec.status = cpu_to_le16(rec.status);
1692 rec.algorithm = inf->info.authreq.algorithm;
1694 result = hfa384x_drvr_setconfig(hw, HFA384x_RID_AUTHENTICATESTA,
1699 netdev_err(wlandev->netdev,
1700 "setconfig(authenticatestation) failed, result=%d\n",
1706 * prism2sta_inf_psusercnt
1708 * Handles the receipt of a PowerSaveUserCount info frame. Should
1709 * be present in APs only.
1712 * wlandev wlan device structure
1713 * inf ptr to info frame (contents in hfa384x order)
1723 static void prism2sta_inf_psusercnt(struct wlandevice *wlandev,
1724 struct hfa384x_inf_frame *inf)
1726 struct hfa384x *hw = wlandev->priv;
1728 hw->psusercount = le16_to_cpu(inf->info.psusercnt.usercnt);
1734 * Handles the Info event.
1737 * wlandev wlan device structure
1738 * inf ptr to a generic info frame
1748 void prism2sta_ev_info(struct wlandevice *wlandev,
1749 struct hfa384x_inf_frame *inf)
1751 inf->infotype = le16_to_cpu(inf->infotype);
1753 switch (inf->infotype) {
1754 case HFA384x_IT_HANDOVERADDR:
1755 prism2sta_inf_handover(wlandev, inf);
1757 case HFA384x_IT_COMMTALLIES:
1758 prism2sta_inf_tallies(wlandev, inf);
1760 case HFA384x_IT_HOSTSCANRESULTS:
1761 prism2sta_inf_hostscanresults(wlandev, inf);
1763 case HFA384x_IT_SCANRESULTS:
1764 prism2sta_inf_scanresults(wlandev, inf);
1766 case HFA384x_IT_CHINFORESULTS:
1767 prism2sta_inf_chinforesults(wlandev, inf);
1769 case HFA384x_IT_LINKSTATUS:
1770 prism2sta_inf_linkstatus(wlandev, inf);
1772 case HFA384x_IT_ASSOCSTATUS:
1773 prism2sta_inf_assocstatus(wlandev, inf);
1775 case HFA384x_IT_AUTHREQ:
1776 prism2sta_inf_authreq(wlandev, inf);
1778 case HFA384x_IT_PSUSERCNT:
1779 prism2sta_inf_psusercnt(wlandev, inf);
1781 case HFA384x_IT_KEYIDCHANGED:
1782 netdev_warn(wlandev->netdev, "Unhandled IT_KEYIDCHANGED\n");
1784 case HFA384x_IT_ASSOCREQ:
1785 netdev_warn(wlandev->netdev, "Unhandled IT_ASSOCREQ\n");
1787 case HFA384x_IT_MICFAILURE:
1788 netdev_warn(wlandev->netdev, "Unhandled IT_MICFAILURE\n");
1791 netdev_warn(wlandev->netdev,
1792 "Unknown info type=0x%02x\n", inf->infotype);
1798 * prism2sta_ev_txexc
1800 * Handles the TxExc event. A Transmit Exception event indicates
1801 * that the MAC's TX process was unsuccessful - so the packet did
1802 * not get transmitted.
1805 * wlandev wlan device structure
1806 * status tx frame status word
1816 void prism2sta_ev_txexc(struct wlandevice *wlandev, u16 status)
1818 pr_debug("TxExc status=0x%x.\n", status);
1824 * Handles the Tx event.
1827 * wlandev wlan device structure
1828 * status tx frame status word
1837 void prism2sta_ev_tx(struct wlandevice *wlandev, u16 status)
1839 pr_debug("Tx Complete, status=0x%04x\n", status);
1840 /* update linux network stats */
1841 wlandev->netdev->stats.tx_packets++;
1845 * prism2sta_ev_alloc
1847 * Handles the Alloc event.
1850 * wlandev wlan device structure
1860 void prism2sta_ev_alloc(struct wlandevice *wlandev)
1862 netif_wake_queue(wlandev->netdev);
1868 * Called at module init time. This creates the struct wlandevice structure
1869 * and initializes it with relevant bits.
1875 * the created struct wlandevice structure.
1878 * also allocates the priv/hw structures.
1884 static struct wlandevice *create_wlan(void)
1886 struct wlandevice *wlandev = NULL;
1887 struct hfa384x *hw = NULL;
1889 /* Alloc our structures */
1890 wlandev = kzalloc(sizeof(*wlandev), GFP_KERNEL);
1891 hw = kzalloc(sizeof(*hw), GFP_KERNEL);
1893 if (!wlandev || !hw) {
1899 /* Initialize the network device object. */
1900 wlandev->nsdname = dev_info;
1901 wlandev->msdstate = WLAN_MSD_HWPRESENT_PENDING;
1903 wlandev->open = prism2sta_open;
1904 wlandev->close = prism2sta_close;
1905 wlandev->reset = prism2sta_reset;
1906 wlandev->txframe = prism2sta_txframe;
1907 wlandev->mlmerequest = prism2sta_mlmerequest;
1908 wlandev->set_multicast_list = prism2sta_setmulticast;
1909 wlandev->tx_timeout = hfa384x_tx_timeout;
1911 wlandev->nsdcaps = P80211_NSDCAP_HWFRAGMENT | P80211_NSDCAP_AUTOJOIN;
1913 /* Initialize the device private data structure. */
1914 hw->dot11_desired_bss_type = 1;
1919 void prism2sta_commsqual_defer(struct work_struct *data)
1921 struct hfa384x *hw = container_of(data, struct hfa384x, commsqual_bh);
1922 struct wlandevice *wlandev = hw->wlandev;
1923 struct hfa384x_bytestr32 ssid;
1924 struct p80211msg_dot11req_mibget msg;
1925 struct p80211item_uint32 *mibitem = (struct p80211item_uint32 *)
1926 &msg.mibattribute.data;
1929 if (hw->wlandev->hwremoved)
1932 /* we don't care if we're in AP mode */
1933 if ((wlandev->macmode == WLAN_MACMODE_NONE) ||
1934 (wlandev->macmode == WLAN_MACMODE_ESS_AP)) {
1938 /* It only makes sense to poll these in non-IBSS */
1939 if (wlandev->macmode != WLAN_MACMODE_IBSS_STA) {
1940 result = hfa384x_drvr_getconfig(
1941 hw, HFA384x_RID_DBMCOMMSQUALITY,
1942 &hw->qual, HFA384x_RID_DBMCOMMSQUALITY_LEN);
1945 netdev_err(wlandev->netdev, "error fetching commsqual\n");
1949 pr_debug("commsqual %d %d %d\n",
1950 le16_to_cpu(hw->qual.cq_curr_bss),
1951 le16_to_cpu(hw->qual.asl_curr_bss),
1952 le16_to_cpu(hw->qual.anl_curr_fc));
1955 /* Get the signal rate */
1956 msg.msgcode = DIDmsg_dot11req_mibget;
1957 mibitem->did = DIDmib_p2_p2MAC_p2CurrentTxRate;
1958 result = p80211req_dorequest(wlandev, (u8 *)&msg);
1961 pr_debug("get signal rate failed, result = %d\n",
1966 switch (mibitem->data) {
1967 case HFA384x_RATEBIT_1:
1970 case HFA384x_RATEBIT_2:
1973 case HFA384x_RATEBIT_5dot5:
1976 case HFA384x_RATEBIT_11:
1980 pr_debug("Bad ratebit (%d)\n", mibitem->data);
1983 /* Lastly, we need to make sure the BSSID didn't change on us */
1984 result = hfa384x_drvr_getconfig(hw,
1985 HFA384x_RID_CURRENTBSSID,
1986 wlandev->bssid, WLAN_BSSID_LEN);
1988 pr_debug("getconfig(0x%02x) failed, result = %d\n",
1989 HFA384x_RID_CURRENTBSSID, result);
1993 result = hfa384x_drvr_getconfig(hw,
1994 HFA384x_RID_CURRENTSSID,
1995 &ssid, sizeof(ssid));
1997 pr_debug("getconfig(0x%02x) failed, result = %d\n",
1998 HFA384x_RID_CURRENTSSID, result);
2001 prism2mgmt_bytestr2pstr((struct hfa384x_bytestr *)&ssid,
2002 (struct p80211pstrd *)&wlandev->ssid);
2004 /* Reschedule timer */
2005 mod_timer(&hw->commsqual_timer, jiffies + HZ);
2008 void prism2sta_commsqual_timer(unsigned long data)
2010 struct hfa384x *hw = (struct hfa384x *)data;
2012 schedule_work(&hw->commsqual_bh);