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>
63 #include <linux/ctype.h>
66 #include <linux/delay.h>
67 #include <asm/byteorder.h>
68 #include <linux/if_arp.h>
69 #include <linux/if_ether.h>
70 #include <linux/bitops.h>
72 #include "p80211types.h"
73 #include "p80211hdr.h"
74 #include "p80211mgmt.h"
75 #include "p80211conv.h"
76 #include "p80211msg.h"
77 #include "p80211netdev.h"
78 #include "p80211req.h"
79 #include "p80211metadef.h"
80 #include "p80211metastruct.h"
82 #include "prism2mgmt.h"
84 /* Create a string of printable chars from something that might not be */
85 /* It's recommended that the str be 4*len + 1 bytes long */
86 #define wlan_mkprintstr(buf, buflen, str, strlen) \
90 memset(str, 0, (strlen)); \
91 for (i = 0; i < (buflen); i++) { \
92 if (isprint((buf)[i])) { \
93 (str)[j] = (buf)[i]; \
98 (str)[j+2] = hex_asc_hi((buf)[i]); \
99 (str)[j+3] = hex_asc_lo((buf)[i]); \
105 static char *dev_info = "prism2_usb";
106 static wlandevice_t *create_wlan(void);
108 int prism2_reset_holdtime = 30; /* Reset hold time in ms */
109 int prism2_reset_settletime = 100; /* Reset settle time in ms */
111 static int prism2_doreset; /* Do a reset at init? */
113 module_param(prism2_doreset, int, 0644);
114 MODULE_PARM_DESC(prism2_doreset, "Issue a reset on initialization");
116 module_param(prism2_reset_holdtime, int, 0644);
117 MODULE_PARM_DESC(prism2_reset_holdtime, "reset hold time in ms");
118 module_param(prism2_reset_settletime, int, 0644);
119 MODULE_PARM_DESC(prism2_reset_settletime, "reset settle time in ms");
121 MODULE_LICENSE("Dual MPL/GPL");
123 static int prism2sta_open(wlandevice_t *wlandev);
124 static int prism2sta_close(wlandevice_t *wlandev);
125 static void prism2sta_reset(wlandevice_t *wlandev);
126 static int prism2sta_txframe(wlandevice_t *wlandev, struct sk_buff *skb,
127 union p80211_hdr *p80211_hdr,
128 struct p80211_metawep *p80211_wep);
129 static int prism2sta_mlmerequest(wlandevice_t *wlandev, struct p80211msg *msg);
130 static int prism2sta_getcardinfo(wlandevice_t *wlandev);
131 static int prism2sta_globalsetup(wlandevice_t *wlandev);
132 static int prism2sta_setmulticast(wlandevice_t *wlandev, netdevice_t *dev);
134 static void prism2sta_inf_handover(wlandevice_t *wlandev,
135 hfa384x_InfFrame_t *inf);
136 static void prism2sta_inf_tallies(wlandevice_t *wlandev,
137 hfa384x_InfFrame_t *inf);
138 static void prism2sta_inf_hostscanresults(wlandevice_t *wlandev,
139 hfa384x_InfFrame_t *inf);
140 static void prism2sta_inf_scanresults(wlandevice_t *wlandev,
141 hfa384x_InfFrame_t *inf);
142 static void prism2sta_inf_chinforesults(wlandevice_t *wlandev,
143 hfa384x_InfFrame_t *inf);
144 static void prism2sta_inf_linkstatus(wlandevice_t *wlandev,
145 hfa384x_InfFrame_t *inf);
146 static void prism2sta_inf_assocstatus(wlandevice_t *wlandev,
147 hfa384x_InfFrame_t *inf);
148 static void prism2sta_inf_authreq(wlandevice_t *wlandev,
149 hfa384x_InfFrame_t *inf);
150 static void prism2sta_inf_authreq_defer(wlandevice_t *wlandev,
151 hfa384x_InfFrame_t *inf);
152 static void prism2sta_inf_psusercnt(wlandevice_t *wlandev,
153 hfa384x_InfFrame_t *inf);
155 /*----------------------------------------------------------------
158 * WLAN device open method. Called from p80211netdev when kernel
159 * device open (start) method is called in response to the
160 * SIOCSIIFFLAGS ioctl changing the flags bit IFF_UP
164 * wlandev wlan device structure
168 * >0 f/w reported error
169 * <0 driver reported error
175 ----------------------------------------------------------------*/
176 static int prism2sta_open(wlandevice_t *wlandev)
178 /* We don't currently have to do anything else.
179 * The setup of the MAC should be subsequently completed via
181 * Higher layers know we're ready from dev->start==1 and
182 * dev->tbusy==0. Our rx path knows to pass up received/
183 * frames because of dev->flags&IFF_UP is true.
189 /*----------------------------------------------------------------
192 * WLAN device close method. Called from p80211netdev when kernel
193 * device close method is called in response to the
194 * SIOCSIIFFLAGS ioctl changing the flags bit IFF_UP
198 * wlandev wlan device structure
202 * >0 f/w reported error
203 * <0 driver reported error
209 ----------------------------------------------------------------*/
210 static int prism2sta_close(wlandevice_t *wlandev)
212 /* We don't currently have to do anything else.
213 * Higher layers know we're not ready from dev->start==0 and
214 * dev->tbusy==1. Our rx path knows to not pass up received
215 * frames because of dev->flags&IFF_UP is false.
221 /*----------------------------------------------------------------
224 * Not currently implented.
227 * wlandev wlan device structure
237 ----------------------------------------------------------------*/
238 static void prism2sta_reset(wlandevice_t *wlandev)
242 /*----------------------------------------------------------------
245 * Takes a frame from p80211 and queues it for transmission.
248 * wlandev wlan device structure
249 * pb packet buffer struct. Contains an 802.11
251 * p80211_hdr points to the 802.11 header for the packet.
253 * 0 Success and more buffs available
254 * 1 Success but no more buffs
255 * 2 Allocation failure
256 * 4 Buffer full or queue busy
262 ----------------------------------------------------------------*/
263 static int prism2sta_txframe(wlandevice_t *wlandev, struct sk_buff *skb,
264 union p80211_hdr *p80211_hdr,
265 struct p80211_metawep *p80211_wep)
267 hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
270 /* If necessary, set the 802.11 WEP bit */
271 if ((wlandev->hostwep & (HOSTWEP_PRIVACYINVOKED | HOSTWEP_ENCRYPT)) ==
272 HOSTWEP_PRIVACYINVOKED) {
273 p80211_hdr->a3.fc |= cpu_to_le16(WLAN_SET_FC_ISWEP(1));
276 result = hfa384x_drvr_txframe(hw, skb, p80211_hdr, p80211_wep);
281 /*----------------------------------------------------------------
282 * prism2sta_mlmerequest
284 * wlan command message handler. All we do here is pass the message
285 * over to the prism2sta_mgmt_handler.
288 * wlandev wlan device structure
289 * msg wlan command message
292 * <0 successful acceptance of message, but we're
293 * waiting for an async process to finish before
294 * we're done with the msg. When the asynch
295 * process is done, we'll call the p80211
296 * function p80211req_confirm() .
297 * >0 An error occurred while we were handling
304 ----------------------------------------------------------------*/
305 static int prism2sta_mlmerequest(wlandevice_t *wlandev, struct p80211msg *msg)
307 hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
311 switch (msg->msgcode) {
312 case DIDmsg_dot11req_mibget:
313 pr_debug("Received mibget request\n");
314 result = prism2mgmt_mibset_mibget(wlandev, msg);
316 case DIDmsg_dot11req_mibset:
317 pr_debug("Received mibset request\n");
318 result = prism2mgmt_mibset_mibget(wlandev, msg);
320 case DIDmsg_dot11req_scan:
321 pr_debug("Received scan request\n");
322 result = prism2mgmt_scan(wlandev, msg);
324 case DIDmsg_dot11req_scan_results:
325 pr_debug("Received scan_results request\n");
326 result = prism2mgmt_scan_results(wlandev, msg);
328 case DIDmsg_dot11req_start:
329 pr_debug("Received mlme start request\n");
330 result = prism2mgmt_start(wlandev, msg);
333 * Prism2 specific messages
335 case DIDmsg_p2req_readpda:
336 pr_debug("Received mlme readpda request\n");
337 result = prism2mgmt_readpda(wlandev, msg);
339 case DIDmsg_p2req_ramdl_state:
340 pr_debug("Received mlme ramdl_state request\n");
341 result = prism2mgmt_ramdl_state(wlandev, msg);
343 case DIDmsg_p2req_ramdl_write:
344 pr_debug("Received mlme ramdl_write request\n");
345 result = prism2mgmt_ramdl_write(wlandev, msg);
347 case DIDmsg_p2req_flashdl_state:
348 pr_debug("Received mlme flashdl_state request\n");
349 result = prism2mgmt_flashdl_state(wlandev, msg);
351 case DIDmsg_p2req_flashdl_write:
352 pr_debug("Received mlme flashdl_write request\n");
353 result = prism2mgmt_flashdl_write(wlandev, msg);
356 * Linux specific messages
358 case DIDmsg_lnxreq_hostwep:
359 break; /* ignore me. */
360 case DIDmsg_lnxreq_ifstate:
362 struct p80211msg_lnxreq_ifstate *ifstatemsg;
363 pr_debug("Received mlme ifstate request\n");
364 ifstatemsg = (struct p80211msg_lnxreq_ifstate *) msg;
366 prism2sta_ifstate(wlandev,
367 ifstatemsg->ifstate.data);
368 ifstatemsg->resultcode.status =
369 P80211ENUM_msgitem_status_data_ok;
370 ifstatemsg->resultcode.data = result;
374 case DIDmsg_lnxreq_wlansniff:
375 pr_debug("Received mlme wlansniff request\n");
376 result = prism2mgmt_wlansniff(wlandev, msg);
378 case DIDmsg_lnxreq_autojoin:
379 pr_debug("Received mlme autojoin request\n");
380 result = prism2mgmt_autojoin(wlandev, msg);
382 case DIDmsg_lnxreq_commsquality:{
383 struct p80211msg_lnxreq_commsquality *qualmsg;
385 pr_debug("Received commsquality request\n");
387 qualmsg = (struct p80211msg_lnxreq_commsquality *) msg;
389 qualmsg->link.status =
390 P80211ENUM_msgitem_status_data_ok;
391 qualmsg->level.status =
392 P80211ENUM_msgitem_status_data_ok;
393 qualmsg->noise.status =
394 P80211ENUM_msgitem_status_data_ok;
396 qualmsg->link.data = le16_to_cpu(hw->qual.CQ_currBSS);
397 qualmsg->level.data = le16_to_cpu(hw->qual.ASL_currBSS);
398 qualmsg->noise.data = le16_to_cpu(hw->qual.ANL_currFC);
399 qualmsg->txrate.data = hw->txrate;
404 netdev_warn(wlandev->netdev,
405 "Unknown mgmt request message 0x%08x",
413 /*----------------------------------------------------------------
416 * Interface state. This is the primary WLAN interface enable/disable
417 * handler. Following the driver/load/deviceprobe sequence, this
418 * function must be called with a state of "enable" before any other
419 * commands will be accepted.
422 * wlandev wlan device structure
423 * msgp ptr to msg buffer
426 * A p80211 message resultcode value.
431 * process thread (usually)
433 ----------------------------------------------------------------*/
434 u32 prism2sta_ifstate(wlandevice_t *wlandev, u32 ifstate)
436 hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
439 result = P80211ENUM_resultcode_implementation_failure;
441 pr_debug("Current MSD state(%d), requesting(%d)\n",
442 wlandev->msdstate, ifstate);
444 case P80211ENUM_ifstate_fwload:
445 switch (wlandev->msdstate) {
446 case WLAN_MSD_HWPRESENT:
447 wlandev->msdstate = WLAN_MSD_FWLOAD_PENDING;
449 * Initialize the device+driver sufficiently
450 * for firmware loading.
452 result = hfa384x_drvr_start(hw);
454 netdev_err(wlandev->netdev,
455 "hfa384x_drvr_start() failed,result=%d\n", (int)result);
457 P80211ENUM_resultcode_implementation_failure;
458 wlandev->msdstate = WLAN_MSD_HWPRESENT;
461 wlandev->msdstate = WLAN_MSD_FWLOAD;
462 result = P80211ENUM_resultcode_success;
464 case WLAN_MSD_FWLOAD:
465 hfa384x_cmd_initialize(hw);
466 result = P80211ENUM_resultcode_success;
468 case WLAN_MSD_RUNNING:
469 netdev_warn(wlandev->netdev,
470 "Cannot enter fwload state from enable state,"
471 "you must disable first.\n");
472 result = P80211ENUM_resultcode_invalid_parameters;
474 case WLAN_MSD_HWFAIL:
476 /* probe() had a problem or the msdstate contains
477 * an unrecognized value, there's nothing we can do.
479 result = P80211ENUM_resultcode_implementation_failure;
483 case P80211ENUM_ifstate_enable:
484 switch (wlandev->msdstate) {
485 case WLAN_MSD_HWPRESENT:
486 case WLAN_MSD_FWLOAD:
487 wlandev->msdstate = WLAN_MSD_RUNNING_PENDING;
488 /* Initialize the device+driver for full
489 * operation. Note that this might me an FWLOAD to
490 * to RUNNING transition so we must not do a chip
491 * or board level reset. Note that on failure,
492 * the MSD state is set to HWPRESENT because we
493 * can't make any assumptions about the state
494 * of the hardware or a previous firmware load.
496 result = hfa384x_drvr_start(hw);
498 netdev_err(wlandev->netdev,
499 "hfa384x_drvr_start() failed,result=%d\n", (int)result);
501 P80211ENUM_resultcode_implementation_failure;
502 wlandev->msdstate = WLAN_MSD_HWPRESENT;
506 result = prism2sta_getcardinfo(wlandev);
508 netdev_err(wlandev->netdev,
509 "prism2sta_getcardinfo() failed,result=%d\n", (int)result);
511 P80211ENUM_resultcode_implementation_failure;
512 hfa384x_drvr_stop(hw);
513 wlandev->msdstate = WLAN_MSD_HWPRESENT;
516 result = prism2sta_globalsetup(wlandev);
518 netdev_err(wlandev->netdev,
519 "prism2sta_globalsetup() failed,result=%d\n", (int)result);
521 P80211ENUM_resultcode_implementation_failure;
522 hfa384x_drvr_stop(hw);
523 wlandev->msdstate = WLAN_MSD_HWPRESENT;
526 wlandev->msdstate = WLAN_MSD_RUNNING;
528 hw->join_retries = 60;
529 result = P80211ENUM_resultcode_success;
531 case WLAN_MSD_RUNNING:
532 /* Do nothing, we're already in this state. */
533 result = P80211ENUM_resultcode_success;
535 case WLAN_MSD_HWFAIL:
537 /* probe() had a problem or the msdstate contains
538 * an unrecognized value, there's nothing we can do.
540 result = P80211ENUM_resultcode_implementation_failure;
544 case P80211ENUM_ifstate_disable:
545 switch (wlandev->msdstate) {
546 case WLAN_MSD_HWPRESENT:
547 /* Do nothing, we're already in this state. */
548 result = P80211ENUM_resultcode_success;
550 case WLAN_MSD_FWLOAD:
551 case WLAN_MSD_RUNNING:
552 wlandev->msdstate = WLAN_MSD_HWPRESENT_PENDING;
554 * TODO: Shut down the MAC completely. Here a chip
555 * or board level reset is probably called for.
556 * After a "disable" _all_ results are lost, even
557 * those from a fwload.
559 if (!wlandev->hwremoved)
560 netif_carrier_off(wlandev->netdev);
562 hfa384x_drvr_stop(hw);
564 wlandev->macmode = WLAN_MACMODE_NONE;
565 wlandev->msdstate = WLAN_MSD_HWPRESENT;
566 result = P80211ENUM_resultcode_success;
568 case WLAN_MSD_HWFAIL:
570 /* probe() had a problem or the msdstate contains
571 * an unrecognized value, there's nothing we can do.
573 result = P80211ENUM_resultcode_implementation_failure;
578 result = P80211ENUM_resultcode_invalid_parameters;
585 /*----------------------------------------------------------------
586 * prism2sta_getcardinfo
588 * Collect the NICID, firmware version and any other identifiers
589 * we'd like to have in host-side data structures.
592 * wlandev wlan device structure
596 * >0 f/w reported error
597 * <0 driver reported error
603 ----------------------------------------------------------------*/
604 static int prism2sta_getcardinfo(wlandevice_t *wlandev)
607 hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
609 u8 snum[HFA384x_RID_NICSERIALNUMBER_LEN];
610 char pstr[(HFA384x_RID_NICSERIALNUMBER_LEN * 4) + 1];
612 /* Collect version and compatibility info */
613 /* Some are critical, some are not */
615 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_NICIDENTITY,
617 sizeof(hfa384x_compident_t));
619 netdev_err(wlandev->netdev, "Failed to retrieve NICIDENTITY\n");
623 /* get all the nic id fields in host byte order */
624 hw->ident_nic.id = le16_to_cpu(hw->ident_nic.id);
625 hw->ident_nic.variant = le16_to_cpu(hw->ident_nic.variant);
626 hw->ident_nic.major = le16_to_cpu(hw->ident_nic.major);
627 hw->ident_nic.minor = le16_to_cpu(hw->ident_nic.minor);
629 netdev_info(wlandev->netdev, "ident: nic h/w: id=0x%02x %d.%d.%d\n",
630 hw->ident_nic.id, hw->ident_nic.major,
631 hw->ident_nic.minor, hw->ident_nic.variant);
633 /* Primary f/w identity */
634 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_PRIIDENTITY,
636 sizeof(hfa384x_compident_t));
638 netdev_err(wlandev->netdev, "Failed to retrieve PRIIDENTITY\n");
642 /* get all the private fw id fields in host byte order */
643 hw->ident_pri_fw.id = le16_to_cpu(hw->ident_pri_fw.id);
644 hw->ident_pri_fw.variant = le16_to_cpu(hw->ident_pri_fw.variant);
645 hw->ident_pri_fw.major = le16_to_cpu(hw->ident_pri_fw.major);
646 hw->ident_pri_fw.minor = le16_to_cpu(hw->ident_pri_fw.minor);
648 netdev_info(wlandev->netdev, "ident: pri f/w: id=0x%02x %d.%d.%d\n",
649 hw->ident_pri_fw.id, hw->ident_pri_fw.major,
650 hw->ident_pri_fw.minor, hw->ident_pri_fw.variant);
652 /* Station (Secondary?) f/w identity */
653 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_STAIDENTITY,
655 sizeof(hfa384x_compident_t));
657 netdev_err(wlandev->netdev, "Failed to retrieve STAIDENTITY\n");
661 if (hw->ident_nic.id < 0x8000) {
662 netdev_err(wlandev->netdev,
663 "FATAL: Card is not an Intersil Prism2/2.5/3\n");
668 /* get all the station fw id fields in host byte order */
669 hw->ident_sta_fw.id = le16_to_cpu(hw->ident_sta_fw.id);
670 hw->ident_sta_fw.variant = le16_to_cpu(hw->ident_sta_fw.variant);
671 hw->ident_sta_fw.major = le16_to_cpu(hw->ident_sta_fw.major);
672 hw->ident_sta_fw.minor = le16_to_cpu(hw->ident_sta_fw.minor);
674 /* strip out the 'special' variant bits */
675 hw->mm_mods = hw->ident_sta_fw.variant & (BIT(14) | BIT(15));
676 hw->ident_sta_fw.variant &= ~((u16) (BIT(14) | BIT(15)));
678 if (hw->ident_sta_fw.id == 0x1f) {
679 netdev_info(wlandev->netdev,
680 "ident: sta f/w: id=0x%02x %d.%d.%d\n",
681 hw->ident_sta_fw.id, hw->ident_sta_fw.major,
682 hw->ident_sta_fw.minor, hw->ident_sta_fw.variant);
684 netdev_info(wlandev->netdev,
685 "ident: ap f/w: id=0x%02x %d.%d.%d\n",
686 hw->ident_sta_fw.id, hw->ident_sta_fw.major,
687 hw->ident_sta_fw.minor, hw->ident_sta_fw.variant);
688 netdev_err(wlandev->netdev, "Unsupported Tertiary AP firmeare loaded!\n");
692 /* Compatibility range, Modem supplier */
693 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_MFISUPRANGE,
695 sizeof(hfa384x_caplevel_t));
697 netdev_err(wlandev->netdev, "Failed to retrieve MFISUPRANGE\n");
701 /* get all the Compatibility range, modem interface supplier
702 fields in byte order */
703 hw->cap_sup_mfi.role = le16_to_cpu(hw->cap_sup_mfi.role);
704 hw->cap_sup_mfi.id = le16_to_cpu(hw->cap_sup_mfi.id);
705 hw->cap_sup_mfi.variant = le16_to_cpu(hw->cap_sup_mfi.variant);
706 hw->cap_sup_mfi.bottom = le16_to_cpu(hw->cap_sup_mfi.bottom);
707 hw->cap_sup_mfi.top = le16_to_cpu(hw->cap_sup_mfi.top);
709 netdev_info(wlandev->netdev,
710 "MFI:SUP:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
711 hw->cap_sup_mfi.role, hw->cap_sup_mfi.id,
712 hw->cap_sup_mfi.variant, hw->cap_sup_mfi.bottom,
713 hw->cap_sup_mfi.top);
715 /* Compatibility range, Controller supplier */
716 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_CFISUPRANGE,
718 sizeof(hfa384x_caplevel_t));
720 netdev_err(wlandev->netdev, "Failed to retrieve CFISUPRANGE\n");
724 /* get all the Compatibility range, controller interface supplier
725 fields in byte order */
726 hw->cap_sup_cfi.role = le16_to_cpu(hw->cap_sup_cfi.role);
727 hw->cap_sup_cfi.id = le16_to_cpu(hw->cap_sup_cfi.id);
728 hw->cap_sup_cfi.variant = le16_to_cpu(hw->cap_sup_cfi.variant);
729 hw->cap_sup_cfi.bottom = le16_to_cpu(hw->cap_sup_cfi.bottom);
730 hw->cap_sup_cfi.top = le16_to_cpu(hw->cap_sup_cfi.top);
732 netdev_info(wlandev->netdev,
733 "CFI:SUP:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
734 hw->cap_sup_cfi.role, hw->cap_sup_cfi.id,
735 hw->cap_sup_cfi.variant, hw->cap_sup_cfi.bottom,
736 hw->cap_sup_cfi.top);
738 /* Compatibility range, Primary f/w supplier */
739 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_PRISUPRANGE,
741 sizeof(hfa384x_caplevel_t));
743 netdev_err(wlandev->netdev, "Failed to retrieve PRISUPRANGE\n");
747 /* get all the Compatibility range, primary firmware supplier
748 fields in byte order */
749 hw->cap_sup_pri.role = le16_to_cpu(hw->cap_sup_pri.role);
750 hw->cap_sup_pri.id = le16_to_cpu(hw->cap_sup_pri.id);
751 hw->cap_sup_pri.variant = le16_to_cpu(hw->cap_sup_pri.variant);
752 hw->cap_sup_pri.bottom = le16_to_cpu(hw->cap_sup_pri.bottom);
753 hw->cap_sup_pri.top = le16_to_cpu(hw->cap_sup_pri.top);
755 netdev_info(wlandev->netdev,
756 "PRI:SUP:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
757 hw->cap_sup_pri.role, hw->cap_sup_pri.id,
758 hw->cap_sup_pri.variant, hw->cap_sup_pri.bottom,
759 hw->cap_sup_pri.top);
761 /* Compatibility range, Station f/w supplier */
762 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_STASUPRANGE,
764 sizeof(hfa384x_caplevel_t));
766 netdev_err(wlandev->netdev, "Failed to retrieve STASUPRANGE\n");
770 /* get all the Compatibility range, station firmware supplier
771 fields in byte order */
772 hw->cap_sup_sta.role = le16_to_cpu(hw->cap_sup_sta.role);
773 hw->cap_sup_sta.id = le16_to_cpu(hw->cap_sup_sta.id);
774 hw->cap_sup_sta.variant = le16_to_cpu(hw->cap_sup_sta.variant);
775 hw->cap_sup_sta.bottom = le16_to_cpu(hw->cap_sup_sta.bottom);
776 hw->cap_sup_sta.top = le16_to_cpu(hw->cap_sup_sta.top);
778 if (hw->cap_sup_sta.id == 0x04) {
779 netdev_info(wlandev->netdev,
780 "STA:SUP:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
781 hw->cap_sup_sta.role, hw->cap_sup_sta.id,
782 hw->cap_sup_sta.variant, hw->cap_sup_sta.bottom,
783 hw->cap_sup_sta.top);
785 netdev_info(wlandev->netdev,
786 "AP:SUP:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
787 hw->cap_sup_sta.role, hw->cap_sup_sta.id,
788 hw->cap_sup_sta.variant, hw->cap_sup_sta.bottom,
789 hw->cap_sup_sta.top);
792 /* Compatibility range, primary f/w actor, CFI supplier */
793 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_PRI_CFIACTRANGES,
794 &hw->cap_act_pri_cfi,
795 sizeof(hfa384x_caplevel_t));
797 netdev_err(wlandev->netdev, "Failed to retrieve PRI_CFIACTRANGES\n");
801 /* get all the Compatibility range, primary f/w actor, CFI supplier
802 fields in byte order */
803 hw->cap_act_pri_cfi.role = le16_to_cpu(hw->cap_act_pri_cfi.role);
804 hw->cap_act_pri_cfi.id = le16_to_cpu(hw->cap_act_pri_cfi.id);
805 hw->cap_act_pri_cfi.variant = le16_to_cpu(hw->cap_act_pri_cfi.variant);
806 hw->cap_act_pri_cfi.bottom = le16_to_cpu(hw->cap_act_pri_cfi.bottom);
807 hw->cap_act_pri_cfi.top = le16_to_cpu(hw->cap_act_pri_cfi.top);
809 netdev_info(wlandev->netdev,
810 "PRI-CFI:ACT:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
811 hw->cap_act_pri_cfi.role, hw->cap_act_pri_cfi.id,
812 hw->cap_act_pri_cfi.variant, hw->cap_act_pri_cfi.bottom,
813 hw->cap_act_pri_cfi.top);
815 /* Compatibility range, sta f/w actor, CFI supplier */
816 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_STA_CFIACTRANGES,
817 &hw->cap_act_sta_cfi,
818 sizeof(hfa384x_caplevel_t));
820 netdev_err(wlandev->netdev, "Failed to retrieve STA_CFIACTRANGES\n");
824 /* get all the Compatibility range, station f/w actor, CFI supplier
825 fields in byte order */
826 hw->cap_act_sta_cfi.role = le16_to_cpu(hw->cap_act_sta_cfi.role);
827 hw->cap_act_sta_cfi.id = le16_to_cpu(hw->cap_act_sta_cfi.id);
828 hw->cap_act_sta_cfi.variant = le16_to_cpu(hw->cap_act_sta_cfi.variant);
829 hw->cap_act_sta_cfi.bottom = le16_to_cpu(hw->cap_act_sta_cfi.bottom);
830 hw->cap_act_sta_cfi.top = le16_to_cpu(hw->cap_act_sta_cfi.top);
832 netdev_info(wlandev->netdev,
833 "STA-CFI:ACT:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
834 hw->cap_act_sta_cfi.role, hw->cap_act_sta_cfi.id,
835 hw->cap_act_sta_cfi.variant, hw->cap_act_sta_cfi.bottom,
836 hw->cap_act_sta_cfi.top);
838 /* Compatibility range, sta f/w actor, MFI supplier */
839 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_STA_MFIACTRANGES,
840 &hw->cap_act_sta_mfi,
841 sizeof(hfa384x_caplevel_t));
843 netdev_err(wlandev->netdev, "Failed to retrieve STA_MFIACTRANGES\n");
847 /* get all the Compatibility range, station f/w actor, MFI supplier
848 fields in byte order */
849 hw->cap_act_sta_mfi.role = le16_to_cpu(hw->cap_act_sta_mfi.role);
850 hw->cap_act_sta_mfi.id = le16_to_cpu(hw->cap_act_sta_mfi.id);
851 hw->cap_act_sta_mfi.variant = le16_to_cpu(hw->cap_act_sta_mfi.variant);
852 hw->cap_act_sta_mfi.bottom = le16_to_cpu(hw->cap_act_sta_mfi.bottom);
853 hw->cap_act_sta_mfi.top = le16_to_cpu(hw->cap_act_sta_mfi.top);
855 netdev_info(wlandev->netdev,
856 "STA-MFI:ACT:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
857 hw->cap_act_sta_mfi.role, hw->cap_act_sta_mfi.id,
858 hw->cap_act_sta_mfi.variant, hw->cap_act_sta_mfi.bottom,
859 hw->cap_act_sta_mfi.top);
862 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_NICSERIALNUMBER,
863 snum, HFA384x_RID_NICSERIALNUMBER_LEN);
865 wlan_mkprintstr(snum, HFA384x_RID_NICSERIALNUMBER_LEN,
867 netdev_info(wlandev->netdev, "Prism2 card SN: %s\n", pstr);
869 netdev_err(wlandev->netdev, "Failed to retrieve Prism2 Card SN\n");
873 /* Collect the MAC address */
874 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_CNFOWNMACADDR,
875 wlandev->netdev->dev_addr, ETH_ALEN);
877 netdev_err(wlandev->netdev, "Failed to retrieve mac address\n");
881 /* short preamble is always implemented */
882 wlandev->nsdcaps |= P80211_NSDCAP_SHORT_PREAMBLE;
884 /* find out if hardware wep is implemented */
885 hfa384x_drvr_getconfig16(hw, HFA384x_RID_PRIVACYOPTIMP, &temp);
887 wlandev->nsdcaps |= P80211_NSDCAP_HARDWAREWEP;
889 /* get the dBm Scaling constant */
890 hfa384x_drvr_getconfig16(hw, HFA384x_RID_CNFDBMADJUST, &temp);
891 hw->dbmadjust = temp;
893 /* Only enable scan by default on newer firmware */
894 if (HFA384x_FIRMWARE_VERSION(hw->ident_sta_fw.major,
895 hw->ident_sta_fw.minor,
896 hw->ident_sta_fw.variant) <
897 HFA384x_FIRMWARE_VERSION(1, 5, 5)) {
898 wlandev->nsdcaps |= P80211_NSDCAP_NOSCAN;
901 /* TODO: Set any internally managed config items */
905 netdev_err(wlandev->netdev, "Failed, result=%d\n", result);
910 /*----------------------------------------------------------------
911 * prism2sta_globalsetup
913 * Set any global RIDs that we want to set at device activation.
916 * wlandev wlan device structure
920 * >0 f/w reported error
921 * <0 driver reported error
927 ----------------------------------------------------------------*/
928 static int prism2sta_globalsetup(wlandevice_t *wlandev)
930 hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
932 /* Set the maximum frame size */
933 return hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFMAXDATALEN,
937 static int prism2sta_setmulticast(wlandevice_t *wlandev, netdevice_t *dev)
940 hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
944 /* If we're not ready, what's the point? */
945 if (hw->state != HFA384x_STATE_RUNNING)
948 if ((dev->flags & (IFF_PROMISC | IFF_ALLMULTI)) != 0)
949 promisc = P80211ENUM_truth_true;
951 promisc = P80211ENUM_truth_false;
954 hfa384x_drvr_setconfig16_async(hw, HFA384x_RID_PROMISCMODE,
960 /*----------------------------------------------------------------
961 * prism2sta_inf_handover
963 * Handles the receipt of a Handover info frame. Should only be present
967 * wlandev wlan device structure
968 * inf ptr to info frame (contents in hfa384x order)
977 ----------------------------------------------------------------*/
978 static void prism2sta_inf_handover(wlandevice_t *wlandev,
979 hfa384x_InfFrame_t *inf)
981 pr_debug("received infoframe:HANDOVER (unhandled)\n");
984 /*----------------------------------------------------------------
985 * prism2sta_inf_tallies
987 * Handles the receipt of a CommTallies info frame.
990 * wlandev wlan device structure
991 * inf ptr to info frame (contents in hfa384x order)
1000 ----------------------------------------------------------------*/
1001 static void prism2sta_inf_tallies(wlandevice_t *wlandev,
1002 hfa384x_InfFrame_t *inf)
1004 hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
1012 ** Determine if these are 16-bit or 32-bit tallies, based on the
1013 ** record length of the info record.
1016 cnt = sizeof(hfa384x_CommTallies32_t) / sizeof(u32);
1017 if (inf->framelen > 22) {
1018 dst = (u32 *) &hw->tallies;
1019 src32 = (u32 *) &inf->info.commtallies32;
1020 for (i = 0; i < cnt; i++, dst++, src32++)
1021 *dst += le32_to_cpu(*src32);
1023 dst = (u32 *) &hw->tallies;
1024 src16 = (u16 *) &inf->info.commtallies16;
1025 for (i = 0; i < cnt; i++, dst++, src16++)
1026 *dst += le16_to_cpu(*src16);
1030 /*----------------------------------------------------------------
1031 * prism2sta_inf_scanresults
1033 * Handles the receipt of a Scan Results info frame.
1036 * wlandev wlan device structure
1037 * inf ptr to info frame (contents in hfa384x order)
1046 ----------------------------------------------------------------*/
1047 static void prism2sta_inf_scanresults(wlandevice_t *wlandev,
1048 hfa384x_InfFrame_t *inf)
1051 hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
1053 hfa384x_ScanResult_t *sr = &(inf->info.scanresult);
1055 hfa384x_JoinRequest_data_t joinreq;
1058 /* Get the number of results, first in bytes, then in results */
1059 nbss = (inf->framelen * sizeof(u16)) -
1060 sizeof(inf->infotype) - sizeof(inf->info.scanresult.scanreason);
1061 nbss /= sizeof(hfa384x_ScanResultSub_t);
1064 pr_debug("rx scanresults, reason=%d, nbss=%d:\n",
1065 inf->info.scanresult.scanreason, nbss);
1066 for (i = 0; i < nbss; i++) {
1067 pr_debug("chid=%d anl=%d sl=%d bcnint=%d\n",
1070 sr->result[i].sl, sr->result[i].bcnint);
1071 pr_debug(" capinfo=0x%04x proberesp_rate=%d\n",
1072 sr->result[i].capinfo, sr->result[i].proberesp_rate);
1074 /* issue a join request */
1075 joinreq.channel = sr->result[0].chid;
1076 memcpy(joinreq.bssid, sr->result[0].bssid, WLAN_BSSID_LEN);
1077 result = hfa384x_drvr_setconfig(hw,
1078 HFA384x_RID_JOINREQUEST,
1079 &joinreq, HFA384x_RID_JOINREQUEST_LEN);
1081 netdev_err(wlandev->netdev, "setconfig(joinreq) failed, result=%d\n",
1086 /*----------------------------------------------------------------
1087 * prism2sta_inf_hostscanresults
1089 * Handles the receipt of a Scan Results info frame.
1092 * wlandev wlan device structure
1093 * inf ptr to info frame (contents in hfa384x order)
1102 ----------------------------------------------------------------*/
1103 static void prism2sta_inf_hostscanresults(wlandevice_t *wlandev,
1104 hfa384x_InfFrame_t *inf)
1106 hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
1109 nbss = (inf->framelen - 3) / 32;
1110 pr_debug("Received %d hostscan results\n", nbss);
1115 kfree(hw->scanresults);
1117 hw->scanresults = kmemdup(inf, sizeof(hfa384x_InfFrame_t), GFP_ATOMIC);
1122 /* Notify/wake the sleeping caller. */
1123 hw->scanflag = nbss;
1124 wake_up_interruptible(&hw->cmdq);
1127 /*----------------------------------------------------------------
1128 * prism2sta_inf_chinforesults
1130 * Handles the receipt of a Channel Info Results info frame.
1133 * wlandev wlan device structure
1134 * inf ptr to info frame (contents in hfa384x order)
1143 ----------------------------------------------------------------*/
1144 static void prism2sta_inf_chinforesults(wlandevice_t *wlandev,
1145 hfa384x_InfFrame_t *inf)
1147 hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
1150 hw->channel_info.results.scanchannels =
1151 le16_to_cpu(inf->info.chinforesult.scanchannels);
1153 for (i = 0, n = 0; i < HFA384x_CHINFORESULT_MAX; i++) {
1154 hfa384x_ChInfoResultSub_t *result;
1155 hfa384x_ChInfoResultSub_t *chinforesult;
1158 if (!(hw->channel_info.results.scanchannels & (1 << i)))
1161 result = &inf->info.chinforesult.result[n];
1162 chan = le16_to_cpu(result->chid) - 1;
1164 if (chan < 0 || chan >= HFA384x_CHINFORESULT_MAX)
1167 chinforesult = &hw->channel_info.results.result[chan];
1168 chinforesult->chid = chan;
1169 chinforesult->anl = le16_to_cpu(result->anl);
1170 chinforesult->pnl = le16_to_cpu(result->pnl);
1171 chinforesult->active = le16_to_cpu(result->active);
1173 pr_debug("chinfo: channel %d, %s level (avg/peak)=%d/%d dB, pcf %d\n",
1175 (chinforesult->active & HFA384x_CHINFORESULT_BSSACTIVE)
1176 ? "signal" : "noise",
1177 chinforesult->anl, chinforesult->pnl,
1178 (chinforesult->active & HFA384x_CHINFORESULT_PCFACTIVE)
1182 atomic_set(&hw->channel_info.done, 2);
1184 hw->channel_info.count = n;
1187 void prism2sta_processing_defer(struct work_struct *data)
1189 hfa384x_t *hw = container_of(data, struct hfa384x, link_bh);
1190 wlandevice_t *wlandev = hw->wlandev;
1191 hfa384x_bytestr32_t ssid;
1194 /* First let's process the auth frames */
1196 struct sk_buff *skb;
1197 hfa384x_InfFrame_t *inf;
1199 while ((skb = skb_dequeue(&hw->authq))) {
1200 inf = (hfa384x_InfFrame_t *) skb->data;
1201 prism2sta_inf_authreq_defer(wlandev, inf);
1206 /* Now let's handle the linkstatus stuff */
1207 if (hw->link_status == hw->link_status_new)
1210 hw->link_status = hw->link_status_new;
1212 switch (hw->link_status) {
1213 case HFA384x_LINK_NOTCONNECTED:
1214 /* I'm currently assuming that this is the initial link
1215 * state. It should only be possible immediately
1216 * following an Enable command.
1218 * Block Transmits, Ignore receives of data frames
1220 netif_carrier_off(wlandev->netdev);
1222 netdev_info(wlandev->netdev, "linkstatus=NOTCONNECTED (unhandled)\n");
1225 case HFA384x_LINK_CONNECTED:
1226 /* This one indicates a successful scan/join/auth/assoc.
1227 * When we have the full MLME complement, this event will
1228 * signify successful completion of both mlme_authenticate
1229 * and mlme_associate. State management will get a little
1232 * Indicate authentication and/or association
1233 * Enable Transmits, Receives and pass up data frames
1236 netif_carrier_on(wlandev->netdev);
1238 /* If we are joining a specific AP, set our
1239 * state and reset retries
1241 if (hw->join_ap == 1)
1243 hw->join_retries = 60;
1245 /* Don't call this in monitor mode */
1246 if (wlandev->netdev->type == ARPHRD_ETHER) {
1249 netdev_info(wlandev->netdev, "linkstatus=CONNECTED\n");
1251 /* For non-usb devices, we can use the sync versions */
1252 /* Collect the BSSID, and set state to allow tx */
1254 result = hfa384x_drvr_getconfig(hw,
1255 HFA384x_RID_CURRENTBSSID,
1260 ("getconfig(0x%02x) failed, result = %d\n",
1261 HFA384x_RID_CURRENTBSSID, result);
1265 result = hfa384x_drvr_getconfig(hw,
1266 HFA384x_RID_CURRENTSSID,
1267 &ssid, sizeof(ssid));
1270 ("getconfig(0x%02x) failed, result = %d\n",
1271 HFA384x_RID_CURRENTSSID, result);
1274 prism2mgmt_bytestr2pstr((struct hfa384x_bytestr *) &ssid,
1278 /* Collect the port status */
1279 result = hfa384x_drvr_getconfig16(hw,
1280 HFA384x_RID_PORTSTATUS,
1284 ("getconfig(0x%02x) failed, result = %d\n",
1285 HFA384x_RID_PORTSTATUS, result);
1289 (portstatus == HFA384x_PSTATUS_CONN_IBSS) ?
1290 WLAN_MACMODE_IBSS_STA : WLAN_MACMODE_ESS_STA;
1292 /* signal back up to cfg80211 layer */
1293 prism2_connect_result(wlandev, P80211ENUM_truth_false);
1295 /* Get the ball rolling on the comms quality stuff */
1296 prism2sta_commsqual_defer(&hw->commsqual_bh);
1300 case HFA384x_LINK_DISCONNECTED:
1301 /* This one indicates that our association is gone. We've
1302 * lost connection with the AP and/or been disassociated.
1303 * This indicates that the MAC has completely cleared it's
1304 * associated state. We * should send a deauth indication
1305 * (implying disassoc) up * to the MLME.
1307 * Indicate Deauthentication
1308 * Block Transmits, Ignore receives of data frames
1310 if (wlandev->netdev->type == ARPHRD_ETHER)
1311 netdev_info(wlandev->netdev,
1312 "linkstatus=DISCONNECTED (unhandled)\n");
1313 wlandev->macmode = WLAN_MACMODE_NONE;
1315 netif_carrier_off(wlandev->netdev);
1317 /* signal back up to cfg80211 layer */
1318 prism2_disconnected(wlandev);
1322 case HFA384x_LINK_AP_CHANGE:
1323 /* This one indicates that the MAC has decided to and
1324 * successfully completed a change to another AP. We
1325 * should probably implement a reassociation indication
1326 * in response to this one. I'm thinking that the the
1327 * p80211 layer needs to be notified in case of
1328 * buffering/queueing issues. User mode also needs to be
1329 * notified so that any BSS dependent elements can be
1331 * associated state. We * should send a deauth indication
1332 * (implying disassoc) up * to the MLME.
1334 * Indicate Reassociation
1335 * Enable Transmits, Receives and pass up data frames
1337 netdev_info(wlandev->netdev, "linkstatus=AP_CHANGE\n");
1339 result = hfa384x_drvr_getconfig(hw,
1340 HFA384x_RID_CURRENTBSSID,
1341 wlandev->bssid, WLAN_BSSID_LEN);
1343 pr_debug("getconfig(0x%02x) failed, result = %d\n",
1344 HFA384x_RID_CURRENTBSSID, result);
1348 result = hfa384x_drvr_getconfig(hw,
1349 HFA384x_RID_CURRENTSSID,
1350 &ssid, sizeof(ssid));
1352 pr_debug("getconfig(0x%02x) failed, result = %d\n",
1353 HFA384x_RID_CURRENTSSID, result);
1356 prism2mgmt_bytestr2pstr((struct hfa384x_bytestr *) &ssid,
1357 (p80211pstrd_t *) &wlandev->ssid);
1359 hw->link_status = HFA384x_LINK_CONNECTED;
1360 netif_carrier_on(wlandev->netdev);
1362 /* signal back up to cfg80211 layer */
1363 prism2_roamed(wlandev);
1367 case HFA384x_LINK_AP_OUTOFRANGE:
1368 /* This one indicates that the MAC has decided that the
1369 * AP is out of range, but hasn't found a better candidate
1370 * so the MAC maintains its "associated" state in case
1371 * we get back in range. We should block transmits and
1372 * receives in this state. Do we need an indication here?
1373 * Probably not since a polling user-mode element would
1374 * get this status from from p2PortStatus(FD40). What about
1377 * Block Transmits, Ignore receives of data frames
1379 netdev_info(wlandev->netdev, "linkstatus=AP_OUTOFRANGE (unhandled)\n");
1381 netif_carrier_off(wlandev->netdev);
1385 case HFA384x_LINK_AP_INRANGE:
1386 /* This one indicates that the MAC has decided that the
1387 * AP is back in range. We continue working with our
1388 * existing association.
1390 * Enable Transmits, Receives and pass up data frames
1392 netdev_info(wlandev->netdev, "linkstatus=AP_INRANGE\n");
1394 hw->link_status = HFA384x_LINK_CONNECTED;
1395 netif_carrier_on(wlandev->netdev);
1399 case HFA384x_LINK_ASSOCFAIL:
1400 /* This one is actually a peer to CONNECTED. We've
1401 * requested a join for a given SSID and optionally BSSID.
1402 * We can use this one to indicate authentication and
1403 * association failures. The trick is going to be
1404 * 1) identifying the failure, and 2) state management.
1406 * Disable Transmits, Ignore receives of data frames
1408 if (hw->join_ap && --hw->join_retries > 0) {
1409 hfa384x_JoinRequest_data_t joinreq;
1410 joinreq = hw->joinreq;
1411 /* Send the join request */
1412 hfa384x_drvr_setconfig(hw,
1413 HFA384x_RID_JOINREQUEST,
1415 HFA384x_RID_JOINREQUEST_LEN);
1416 netdev_info(wlandev->netdev,
1417 "linkstatus=ASSOCFAIL (re-submitting join)\n");
1419 netdev_info(wlandev->netdev, "linkstatus=ASSOCFAIL (unhandled)\n");
1422 netif_carrier_off(wlandev->netdev);
1424 /* signal back up to cfg80211 layer */
1425 prism2_connect_result(wlandev, P80211ENUM_truth_true);
1430 /* This is bad, IO port problems? */
1431 netdev_warn(wlandev->netdev,
1432 "unknown linkstatus=0x%02x\n", hw->link_status);
1436 wlandev->linkstatus = (hw->link_status == HFA384x_LINK_CONNECTED);
1439 /*----------------------------------------------------------------
1440 * prism2sta_inf_linkstatus
1442 * Handles the receipt of a Link Status info frame.
1445 * wlandev wlan device structure
1446 * inf ptr to info frame (contents in hfa384x order)
1455 ----------------------------------------------------------------*/
1456 static void prism2sta_inf_linkstatus(wlandevice_t *wlandev,
1457 hfa384x_InfFrame_t *inf)
1459 hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
1461 hw->link_status_new = le16_to_cpu(inf->info.linkstatus.linkstatus);
1463 schedule_work(&hw->link_bh);
1466 /*----------------------------------------------------------------
1467 * prism2sta_inf_assocstatus
1469 * Handles the receipt of an Association Status info frame. Should
1470 * be present in APs only.
1473 * wlandev wlan device structure
1474 * inf ptr to info frame (contents in hfa384x order)
1483 ----------------------------------------------------------------*/
1484 static void prism2sta_inf_assocstatus(wlandevice_t *wlandev,
1485 hfa384x_InfFrame_t *inf)
1487 hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
1488 hfa384x_AssocStatus_t rec;
1491 memcpy(&rec, &inf->info.assocstatus, sizeof(rec));
1492 rec.assocstatus = le16_to_cpu(rec.assocstatus);
1493 rec.reason = le16_to_cpu(rec.reason);
1496 ** Find the address in the list of authenticated stations.
1497 ** If it wasn't found, then this address has not been previously
1498 ** authenticated and something weird has happened if this is
1499 ** anything other than an "authentication failed" message.
1500 ** If the address was found, then set the "associated" flag for
1501 ** that station, based on whether the station is associating or
1502 ** losing its association. Something weird has also happened
1503 ** if we find the address in the list of authenticated stations
1504 ** but we are getting an "authentication failed" message.
1507 for (i = 0; i < hw->authlist.cnt; i++)
1508 if (memcmp(rec.sta_addr, hw->authlist.addr[i], ETH_ALEN) == 0)
1511 if (i >= hw->authlist.cnt) {
1512 if (rec.assocstatus != HFA384x_ASSOCSTATUS_AUTHFAIL)
1513 netdev_warn(wlandev->netdev,
1514 "assocstatus info frame received for non-authenticated station.\n");
1516 hw->authlist.assoc[i] =
1517 (rec.assocstatus == HFA384x_ASSOCSTATUS_STAASSOC ||
1518 rec.assocstatus == HFA384x_ASSOCSTATUS_REASSOC);
1520 if (rec.assocstatus == HFA384x_ASSOCSTATUS_AUTHFAIL)
1521 netdev_warn(wlandev->netdev,
1522 "authfail assocstatus info frame received for authenticated station.\n");
1526 /*----------------------------------------------------------------
1527 * prism2sta_inf_authreq
1529 * Handles the receipt of an Authentication Request info frame. Should
1530 * be present in APs only.
1533 * wlandev wlan device structure
1534 * inf ptr to info frame (contents in hfa384x order)
1544 ----------------------------------------------------------------*/
1545 static void prism2sta_inf_authreq(wlandevice_t *wlandev,
1546 hfa384x_InfFrame_t *inf)
1548 hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
1549 struct sk_buff *skb;
1551 skb = dev_alloc_skb(sizeof(*inf));
1553 skb_put(skb, sizeof(*inf));
1554 memcpy(skb->data, inf, sizeof(*inf));
1555 skb_queue_tail(&hw->authq, skb);
1556 schedule_work(&hw->link_bh);
1560 static void prism2sta_inf_authreq_defer(wlandevice_t *wlandev,
1561 hfa384x_InfFrame_t *inf)
1563 hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
1564 hfa384x_authenticateStation_data_t rec;
1566 int i, added, result, cnt;
1570 ** Build the AuthenticateStation record. Initialize it for denying
1574 memcpy(rec.address, inf->info.authreq.sta_addr, ETH_ALEN);
1575 rec.status = P80211ENUM_status_unspec_failure;
1578 ** Authenticate based on the access mode.
1581 switch (hw->accessmode) {
1582 case WLAN_ACCESS_NONE:
1585 ** Deny all new authentications. However, if a station
1586 ** is ALREADY authenticated, then accept it.
1589 for (i = 0; i < hw->authlist.cnt; i++)
1590 if (memcmp(rec.address, hw->authlist.addr[i],
1592 rec.status = P80211ENUM_status_successful;
1598 case WLAN_ACCESS_ALL:
1601 ** Allow all authentications.
1604 rec.status = P80211ENUM_status_successful;
1607 case WLAN_ACCESS_ALLOW:
1610 ** Only allow the authentication if the MAC address
1611 ** is in the list of allowed addresses.
1613 ** Since this is the interrupt handler, we may be here
1614 ** while the access list is in the middle of being
1615 ** updated. Choose the list which is currently okay.
1616 ** See "prism2mib_priv_accessallow()" for details.
1619 if (hw->allow.modify == 0) {
1620 cnt = hw->allow.cnt;
1621 addr = hw->allow.addr[0];
1623 cnt = hw->allow.cnt1;
1624 addr = hw->allow.addr1[0];
1627 for (i = 0; i < cnt; i++, addr += ETH_ALEN)
1628 if (memcmp(rec.address, addr, ETH_ALEN) == 0) {
1629 rec.status = P80211ENUM_status_successful;
1635 case WLAN_ACCESS_DENY:
1638 ** Allow the authentication UNLESS the MAC address is
1639 ** in the list of denied addresses.
1641 ** Since this is the interrupt handler, we may be here
1642 ** while the access list is in the middle of being
1643 ** updated. Choose the list which is currently okay.
1644 ** See "prism2mib_priv_accessdeny()" for details.
1647 if (hw->deny.modify == 0) {
1649 addr = hw->deny.addr[0];
1651 cnt = hw->deny.cnt1;
1652 addr = hw->deny.addr1[0];
1655 rec.status = P80211ENUM_status_successful;
1657 for (i = 0; i < cnt; i++, addr += ETH_ALEN)
1658 if (memcmp(rec.address, addr, ETH_ALEN) == 0) {
1659 rec.status = P80211ENUM_status_unspec_failure;
1667 ** If the authentication is okay, then add the MAC address to the
1668 ** list of authenticated stations. Don't add the address if it
1669 ** is already in the list. (802.11b does not seem to disallow
1670 ** a station from issuing an authentication request when the
1671 ** station is already authenticated. Does this sort of thing
1672 ** ever happen? We might as well do the check just in case.)
1677 if (rec.status == P80211ENUM_status_successful) {
1678 for (i = 0; i < hw->authlist.cnt; i++)
1679 if (memcmp(rec.address, hw->authlist.addr[i], ETH_ALEN)
1683 if (i >= hw->authlist.cnt) {
1684 if (hw->authlist.cnt >= WLAN_AUTH_MAX) {
1685 rec.status = P80211ENUM_status_ap_full;
1687 memcpy(hw->authlist.addr[hw->authlist.cnt],
1688 rec.address, ETH_ALEN);
1696 ** Send back the results of the authentication. If this doesn't work,
1697 ** then make sure to remove the address from the authenticated list if
1701 rec.status = cpu_to_le16(rec.status);
1702 rec.algorithm = inf->info.authreq.algorithm;
1704 result = hfa384x_drvr_setconfig(hw, HFA384x_RID_AUTHENTICATESTA,
1709 netdev_err(wlandev->netdev,
1710 "setconfig(authenticatestation) failed, result=%d\n",
1715 /*----------------------------------------------------------------
1716 * prism2sta_inf_psusercnt
1718 * Handles the receipt of a PowerSaveUserCount info frame. Should
1719 * be present in APs only.
1722 * wlandev wlan device structure
1723 * inf ptr to info frame (contents in hfa384x order)
1732 ----------------------------------------------------------------*/
1733 static void prism2sta_inf_psusercnt(wlandevice_t *wlandev,
1734 hfa384x_InfFrame_t *inf)
1736 hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
1738 hw->psusercount = le16_to_cpu(inf->info.psusercnt.usercnt);
1741 /*----------------------------------------------------------------
1744 * Handles the Info event.
1747 * wlandev wlan device structure
1748 * inf ptr to a generic info frame
1757 ----------------------------------------------------------------*/
1758 void prism2sta_ev_info(wlandevice_t *wlandev, hfa384x_InfFrame_t *inf)
1760 inf->infotype = le16_to_cpu(inf->infotype);
1762 switch (inf->infotype) {
1763 case HFA384x_IT_HANDOVERADDR:
1764 prism2sta_inf_handover(wlandev, inf);
1766 case HFA384x_IT_COMMTALLIES:
1767 prism2sta_inf_tallies(wlandev, inf);
1769 case HFA384x_IT_HOSTSCANRESULTS:
1770 prism2sta_inf_hostscanresults(wlandev, inf);
1772 case HFA384x_IT_SCANRESULTS:
1773 prism2sta_inf_scanresults(wlandev, inf);
1775 case HFA384x_IT_CHINFORESULTS:
1776 prism2sta_inf_chinforesults(wlandev, inf);
1778 case HFA384x_IT_LINKSTATUS:
1779 prism2sta_inf_linkstatus(wlandev, inf);
1781 case HFA384x_IT_ASSOCSTATUS:
1782 prism2sta_inf_assocstatus(wlandev, inf);
1784 case HFA384x_IT_AUTHREQ:
1785 prism2sta_inf_authreq(wlandev, inf);
1787 case HFA384x_IT_PSUSERCNT:
1788 prism2sta_inf_psusercnt(wlandev, inf);
1790 case HFA384x_IT_KEYIDCHANGED:
1791 netdev_warn(wlandev->netdev, "Unhandled IT_KEYIDCHANGED\n");
1793 case HFA384x_IT_ASSOCREQ:
1794 netdev_warn(wlandev->netdev, "Unhandled IT_ASSOCREQ\n");
1796 case HFA384x_IT_MICFAILURE:
1797 netdev_warn(wlandev->netdev, "Unhandled IT_MICFAILURE\n");
1800 netdev_warn(wlandev->netdev,
1801 "Unknown info type=0x%02x\n", inf->infotype);
1806 /*----------------------------------------------------------------
1807 * prism2sta_ev_txexc
1809 * Handles the TxExc event. A Transmit Exception event indicates
1810 * that the MAC's TX process was unsuccessful - so the packet did
1811 * not get transmitted.
1814 * wlandev wlan device structure
1815 * status tx frame status word
1824 ----------------------------------------------------------------*/
1825 void prism2sta_ev_txexc(wlandevice_t *wlandev, u16 status)
1827 pr_debug("TxExc status=0x%x.\n", status);
1830 /*----------------------------------------------------------------
1833 * Handles the Tx event.
1836 * wlandev wlan device structure
1837 * status tx frame status word
1845 ----------------------------------------------------------------*/
1846 void prism2sta_ev_tx(wlandevice_t *wlandev, u16 status)
1848 pr_debug("Tx Complete, status=0x%04x\n", status);
1849 /* update linux network stats */
1850 wlandev->linux_stats.tx_packets++;
1853 /*----------------------------------------------------------------
1856 * Handles the Rx event.
1859 * wlandev wlan device structure
1868 ----------------------------------------------------------------*/
1869 void prism2sta_ev_rx(wlandevice_t *wlandev, struct sk_buff *skb)
1871 p80211netdev_rx(wlandev, skb);
1874 /*----------------------------------------------------------------
1875 * prism2sta_ev_alloc
1877 * Handles the Alloc event.
1880 * wlandev wlan device structure
1889 ----------------------------------------------------------------*/
1890 void prism2sta_ev_alloc(wlandevice_t *wlandev)
1892 netif_wake_queue(wlandev->netdev);
1895 /*----------------------------------------------------------------
1898 * Called at module init time. This creates the wlandevice_t structure
1899 * and initializes it with relevant bits.
1905 * the created wlandevice_t structure.
1908 * also allocates the priv/hw structures.
1913 ----------------------------------------------------------------*/
1914 static wlandevice_t *create_wlan(void)
1916 wlandevice_t *wlandev = NULL;
1917 hfa384x_t *hw = NULL;
1919 /* Alloc our structures */
1920 wlandev = kzalloc(sizeof(wlandevice_t), GFP_KERNEL);
1921 hw = kzalloc(sizeof(hfa384x_t), GFP_KERNEL);
1923 if (!wlandev || !hw) {
1924 pr_err("%s: Memory allocation failure.\n", dev_info);
1930 /* Initialize the network device object. */
1931 wlandev->nsdname = dev_info;
1932 wlandev->msdstate = WLAN_MSD_HWPRESENT_PENDING;
1934 wlandev->open = prism2sta_open;
1935 wlandev->close = prism2sta_close;
1936 wlandev->reset = prism2sta_reset;
1937 wlandev->txframe = prism2sta_txframe;
1938 wlandev->mlmerequest = prism2sta_mlmerequest;
1939 wlandev->set_multicast_list = prism2sta_setmulticast;
1940 wlandev->tx_timeout = hfa384x_tx_timeout;
1942 wlandev->nsdcaps = P80211_NSDCAP_HWFRAGMENT | P80211_NSDCAP_AUTOJOIN;
1944 /* Initialize the device private data structure. */
1945 hw->dot11_desired_bss_type = 1;
1950 void prism2sta_commsqual_defer(struct work_struct *data)
1952 hfa384x_t *hw = container_of(data, struct hfa384x, commsqual_bh);
1953 wlandevice_t *wlandev = hw->wlandev;
1954 hfa384x_bytestr32_t ssid;
1955 struct p80211msg_dot11req_mibget msg;
1956 p80211item_uint32_t *mibitem = (p80211item_uint32_t *)
1957 &msg.mibattribute.data;
1960 if (hw->wlandev->hwremoved)
1963 /* we don't care if we're in AP mode */
1964 if ((wlandev->macmode == WLAN_MACMODE_NONE) ||
1965 (wlandev->macmode == WLAN_MACMODE_ESS_AP)) {
1969 /* It only makes sense to poll these in non-IBSS */
1970 if (wlandev->macmode != WLAN_MACMODE_IBSS_STA) {
1971 result = hfa384x_drvr_getconfig(
1972 hw, HFA384x_RID_DBMCOMMSQUALITY,
1973 &hw->qual, HFA384x_RID_DBMCOMMSQUALITY_LEN);
1976 netdev_err(wlandev->netdev, "error fetching commsqual\n");
1980 pr_debug("commsqual %d %d %d\n",
1981 le16_to_cpu(hw->qual.CQ_currBSS),
1982 le16_to_cpu(hw->qual.ASL_currBSS),
1983 le16_to_cpu(hw->qual.ANL_currFC));
1986 /* Get the signal rate */
1987 msg.msgcode = DIDmsg_dot11req_mibget;
1988 mibitem->did = DIDmib_p2_p2MAC_p2CurrentTxRate;
1989 result = p80211req_dorequest(wlandev, (u8 *) &msg);
1992 pr_debug("get signal rate failed, result = %d\n",
1997 switch (mibitem->data) {
1998 case HFA384x_RATEBIT_1:
2001 case HFA384x_RATEBIT_2:
2004 case HFA384x_RATEBIT_5dot5:
2007 case HFA384x_RATEBIT_11:
2011 pr_debug("Bad ratebit (%d)\n", mibitem->data);
2014 /* Lastly, we need to make sure the BSSID didn't change on us */
2015 result = hfa384x_drvr_getconfig(hw,
2016 HFA384x_RID_CURRENTBSSID,
2017 wlandev->bssid, WLAN_BSSID_LEN);
2019 pr_debug("getconfig(0x%02x) failed, result = %d\n",
2020 HFA384x_RID_CURRENTBSSID, result);
2024 result = hfa384x_drvr_getconfig(hw,
2025 HFA384x_RID_CURRENTSSID,
2026 &ssid, sizeof(ssid));
2028 pr_debug("getconfig(0x%02x) failed, result = %d\n",
2029 HFA384x_RID_CURRENTSSID, result);
2032 prism2mgmt_bytestr2pstr((struct hfa384x_bytestr *) &ssid,
2033 (p80211pstrd_t *) &wlandev->ssid);
2035 /* Reschedule timer */
2036 mod_timer(&hw->commsqual_timer, jiffies + HZ);
2039 void prism2sta_commsqual_timer(unsigned long data)
2041 hfa384x_t *hw = (hfa384x_t *) data;
2043 schedule_work(&hw->commsqual_bh);