]> Git Repo - linux.git/blob - drivers/staging/wlan-ng/prism2sta.c
ring-buffer: Redefine the unimplemented RINGBUF_TYPE_TIME_STAMP
[linux.git] / drivers / staging / wlan-ng / prism2sta.c
1 // SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1)
2 /* src/prism2/driver/prism2sta.c
3  *
4  * Implements the station functionality for prism2
5  *
6  * Copyright (C) 1999 AbsoluteValue Systems, Inc.  All Rights Reserved.
7  * --------------------------------------------------------------------
8  *
9  * linux-wlan
10  *
11  *   The contents of this file are subject to the Mozilla Public
12  *   License Version 1.1 (the "License"); you may not use this file
13  *   except in compliance with the License. You may obtain a copy of
14  *   the License at http://www.mozilla.org/MPL/
15  *
16  *   Software distributed under the License is distributed on an "AS
17  *   IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
18  *   implied. See the License for the specific language governing
19  *   rights and limitations under the License.
20  *
21  *   Alternatively, the contents of this file may be used under the
22  *   terms of the GNU Public License version 2 (the "GPL"), in which
23  *   case the provisions of the GPL are applicable instead of the
24  *   above.  If you wish to allow the use of your version of this file
25  *   only under the terms of the GPL and not to allow others to use
26  *   your version of this file under the MPL, indicate your decision
27  *   by deleting the provisions above and replace them with the notice
28  *   and other provisions required by the GPL.  If you do not delete
29  *   the provisions above, a recipient may use your version of this
30  *   file under either the MPL or the GPL.
31  *
32  * --------------------------------------------------------------------
33  *
34  * Inquiries regarding the linux-wlan Open Source project can be
35  * made directly to:
36  *
37  * AbsoluteValue Systems Inc.
38  * [email protected]
39  * http://www.linux-wlan.com
40  *
41  * --------------------------------------------------------------------
42  *
43  * Portions of the development of this software were funded by
44  * Intersil Corporation as part of PRISM(R) chipset product development.
45  *
46  * --------------------------------------------------------------------
47  *
48  * This file implements the module and linux pcmcia routines for the
49  * prism2 driver.
50  *
51  * --------------------------------------------------------------------
52  */
53
54 #include <linux/module.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/etherdevice.h>
64
65 #include <linux/io.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>
71
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"
81 #include "hfa384x.h"
82 #include "prism2mgmt.h"
83
84 static char *dev_info = "prism2_usb";
85 static struct wlandevice *create_wlan(void);
86
87 int prism2_reset_holdtime = 30; /* Reset hold time in ms */
88 int prism2_reset_settletime = 100;      /* Reset settle time in ms */
89
90 static int prism2_doreset;      /* Do a reset at init? */
91
92 module_param(prism2_doreset, int, 0644);
93 MODULE_PARM_DESC(prism2_doreset, "Issue a reset on initialization");
94
95 module_param(prism2_reset_holdtime, int, 0644);
96 MODULE_PARM_DESC(prism2_reset_holdtime, "reset hold time in ms");
97 module_param(prism2_reset_settletime, int, 0644);
98 MODULE_PARM_DESC(prism2_reset_settletime, "reset settle time in ms");
99
100 MODULE_LICENSE("Dual MPL/GPL");
101
102 static int prism2sta_open(struct wlandevice *wlandev);
103 static int prism2sta_close(struct wlandevice *wlandev);
104 static void prism2sta_reset(struct wlandevice *wlandev);
105 static int prism2sta_txframe(struct wlandevice *wlandev, struct sk_buff *skb,
106                              union p80211_hdr *p80211_hdr,
107                              struct p80211_metawep *p80211_wep);
108 static int prism2sta_mlmerequest(struct wlandevice *wlandev,
109                                  struct p80211msg *msg);
110 static int prism2sta_getcardinfo(struct wlandevice *wlandev);
111 static int prism2sta_globalsetup(struct wlandevice *wlandev);
112 static int prism2sta_setmulticast(struct wlandevice *wlandev,
113                                   struct net_device *dev);
114
115 static void prism2sta_inf_handover(struct wlandevice *wlandev,
116                                    struct hfa384x_inf_frame *inf);
117 static void prism2sta_inf_tallies(struct wlandevice *wlandev,
118                                   struct hfa384x_inf_frame *inf);
119 static void prism2sta_inf_hostscanresults(struct wlandevice *wlandev,
120                                           struct hfa384x_inf_frame *inf);
121 static void prism2sta_inf_scanresults(struct wlandevice *wlandev,
122                                       struct hfa384x_inf_frame *inf);
123 static void prism2sta_inf_chinforesults(struct wlandevice *wlandev,
124                                         struct hfa384x_inf_frame *inf);
125 static void prism2sta_inf_linkstatus(struct wlandevice *wlandev,
126                                      struct hfa384x_inf_frame *inf);
127 static void prism2sta_inf_assocstatus(struct wlandevice *wlandev,
128                                       struct hfa384x_inf_frame *inf);
129 static void prism2sta_inf_authreq(struct wlandevice *wlandev,
130                                   struct hfa384x_inf_frame *inf);
131 static void prism2sta_inf_authreq_defer(struct wlandevice *wlandev,
132                                         struct hfa384x_inf_frame *inf);
133 static void prism2sta_inf_psusercnt(struct wlandevice *wlandev,
134                                     struct hfa384x_inf_frame *inf);
135
136 /*
137  * prism2sta_open
138  *
139  * WLAN device open method.  Called from p80211netdev when kernel
140  * device open (start) method is called in response to the
141  * SIOCSIIFFLAGS ioctl changing the flags bit IFF_UP
142  * from clear to set.
143  *
144  * Arguments:
145  *      wlandev         wlan device structure
146  *
147  * Returns:
148  *      0       success
149  *      >0      f/w reported error
150  *      <0      driver reported error
151  *
152  * Side effects:
153  *
154  * Call context:
155  *      process thread
156  */
157 static int prism2sta_open(struct wlandevice *wlandev)
158 {
159         /* We don't currently have to do anything else.
160          * The setup of the MAC should be subsequently completed via
161          * the mlme commands.
162          * Higher layers know we're ready from dev->start==1 and
163          * dev->tbusy==0.  Our rx path knows to pass up received/
164          * frames because of dev->flags&IFF_UP is true.
165          */
166
167         return 0;
168 }
169
170 /*
171  * prism2sta_close
172  *
173  * WLAN device close method.  Called from p80211netdev when kernel
174  * device close method is called in response to the
175  * SIOCSIIFFLAGS ioctl changing the flags bit IFF_UP
176  * from set to clear.
177  *
178  * Arguments:
179  *      wlandev         wlan device structure
180  *
181  * Returns:
182  *      0       success
183  *      >0      f/w reported error
184  *      <0      driver reported error
185  *
186  * Side effects:
187  *
188  * Call context:
189  *      process thread
190  */
191 static int prism2sta_close(struct wlandevice *wlandev)
192 {
193         /* We don't currently have to do anything else.
194          * Higher layers know we're not ready from dev->start==0 and
195          * dev->tbusy==1.  Our rx path knows to not pass up received
196          * frames because of dev->flags&IFF_UP is false.
197          */
198
199         return 0;
200 }
201
202 /*
203  * prism2sta_reset
204  *
205  * Currently not implemented.
206  *
207  * Arguments:
208  *      wlandev         wlan device structure
209  *      none
210  *
211  * Returns:
212  *      nothing
213  *
214  * Side effects:
215  *
216  * Call context:
217  *      process thread
218  */
219 static void prism2sta_reset(struct wlandevice *wlandev)
220 {
221 }
222
223 /*
224  * prism2sta_txframe
225  *
226  * Takes a frame from p80211 and queues it for transmission.
227  *
228  * Arguments:
229  *      wlandev         wlan device structure
230  *      pb              packet buffer struct.  Contains an 802.11
231  *                      data frame.
232  *       p80211_hdr      points to the 802.11 header for the packet.
233  * Returns:
234  *      0               Success and more buffs available
235  *      1               Success but no more buffs
236  *      2               Allocation failure
237  *      4               Buffer full or queue busy
238  *
239  * Side effects:
240  *
241  * Call context:
242  *      process thread
243  */
244 static int prism2sta_txframe(struct wlandevice *wlandev, struct sk_buff *skb,
245                              union p80211_hdr *p80211_hdr,
246                              struct p80211_metawep *p80211_wep)
247 {
248         struct hfa384x *hw = wlandev->priv;
249
250         /* If necessary, set the 802.11 WEP bit */
251         if ((wlandev->hostwep & (HOSTWEP_PRIVACYINVOKED | HOSTWEP_ENCRYPT)) ==
252             HOSTWEP_PRIVACYINVOKED) {
253                 p80211_hdr->a3.fc |= cpu_to_le16(WLAN_SET_FC_ISWEP(1));
254         }
255
256         return hfa384x_drvr_txframe(hw, skb, p80211_hdr, p80211_wep);
257 }
258
259 /*
260  * prism2sta_mlmerequest
261  *
262  * wlan command message handler.  All we do here is pass the message
263  * over to the prism2sta_mgmt_handler.
264  *
265  * Arguments:
266  *      wlandev         wlan device structure
267  *      msg             wlan command message
268  * Returns:
269  *      0               success
270  *      <0              successful acceptance of message, but we're
271  *                      waiting for an async process to finish before
272  *                      we're done with the msg.  When the asynch
273  *                      process is done, we'll call the p80211
274  *                      function p80211req_confirm() .
275  *      >0              An error occurred while we were handling
276  *                      the message.
277  *
278  * Side effects:
279  *
280  * Call context:
281  *      process thread
282  */
283 static int prism2sta_mlmerequest(struct wlandevice *wlandev,
284                                  struct p80211msg *msg)
285 {
286         struct hfa384x *hw = wlandev->priv;
287
288         int result = 0;
289
290         switch (msg->msgcode) {
291         case DIDmsg_dot11req_mibget:
292                 pr_debug("Received mibget request\n");
293                 result = prism2mgmt_mibset_mibget(wlandev, msg);
294                 break;
295         case DIDmsg_dot11req_mibset:
296                 pr_debug("Received mibset request\n");
297                 result = prism2mgmt_mibset_mibget(wlandev, msg);
298                 break;
299         case DIDmsg_dot11req_scan:
300                 pr_debug("Received scan request\n");
301                 result = prism2mgmt_scan(wlandev, msg);
302                 break;
303         case DIDmsg_dot11req_scan_results:
304                 pr_debug("Received scan_results request\n");
305                 result = prism2mgmt_scan_results(wlandev, msg);
306                 break;
307         case DIDmsg_dot11req_start:
308                 pr_debug("Received mlme start request\n");
309                 result = prism2mgmt_start(wlandev, msg);
310                 break;
311                 /*
312                  * Prism2 specific messages
313                  */
314         case DIDmsg_p2req_readpda:
315                 pr_debug("Received mlme readpda request\n");
316                 result = prism2mgmt_readpda(wlandev, msg);
317                 break;
318         case DIDmsg_p2req_ramdl_state:
319                 pr_debug("Received mlme ramdl_state request\n");
320                 result = prism2mgmt_ramdl_state(wlandev, msg);
321                 break;
322         case DIDmsg_p2req_ramdl_write:
323                 pr_debug("Received mlme ramdl_write request\n");
324                 result = prism2mgmt_ramdl_write(wlandev, msg);
325                 break;
326         case DIDmsg_p2req_flashdl_state:
327                 pr_debug("Received mlme flashdl_state request\n");
328                 result = prism2mgmt_flashdl_state(wlandev, msg);
329                 break;
330         case DIDmsg_p2req_flashdl_write:
331                 pr_debug("Received mlme flashdl_write request\n");
332                 result = prism2mgmt_flashdl_write(wlandev, msg);
333                 break;
334                 /*
335                  * Linux specific messages
336                  */
337         case DIDmsg_lnxreq_hostwep:
338                 break;          /* ignore me. */
339         case DIDmsg_lnxreq_ifstate:
340                 {
341                         struct p80211msg_lnxreq_ifstate *ifstatemsg;
342
343                         pr_debug("Received mlme ifstate request\n");
344                         ifstatemsg = (struct p80211msg_lnxreq_ifstate *)msg;
345                         result =
346                             prism2sta_ifstate(wlandev,
347                                               ifstatemsg->ifstate.data);
348                         ifstatemsg->resultcode.status =
349                             P80211ENUM_msgitem_status_data_ok;
350                         ifstatemsg->resultcode.data = result;
351                         result = 0;
352                 }
353                 break;
354         case DIDmsg_lnxreq_wlansniff:
355                 pr_debug("Received mlme wlansniff request\n");
356                 result = prism2mgmt_wlansniff(wlandev, msg);
357                 break;
358         case DIDmsg_lnxreq_autojoin:
359                 pr_debug("Received mlme autojoin request\n");
360                 result = prism2mgmt_autojoin(wlandev, msg);
361                 break;
362         case DIDmsg_lnxreq_commsquality:{
363                         struct p80211msg_lnxreq_commsquality *qualmsg;
364
365                         pr_debug("Received commsquality request\n");
366
367                         qualmsg = (struct p80211msg_lnxreq_commsquality *)msg;
368
369                         qualmsg->link.status =
370                             P80211ENUM_msgitem_status_data_ok;
371                         qualmsg->level.status =
372                             P80211ENUM_msgitem_status_data_ok;
373                         qualmsg->noise.status =
374                             P80211ENUM_msgitem_status_data_ok;
375
376                         qualmsg->link.data = le16_to_cpu(hw->qual.cq_curr_bss);
377                         qualmsg->level.data =
378                                 le16_to_cpu(hw->qual.asl_curr_bss);
379                         qualmsg->noise.data = le16_to_cpu(hw->qual.anl_curr_fc);
380                         qualmsg->txrate.data = hw->txrate;
381
382                         break;
383                 }
384         default:
385                 netdev_warn(wlandev->netdev,
386                             "Unknown mgmt request message 0x%08x",
387                             msg->msgcode);
388                 break;
389         }
390
391         return result;
392 }
393
394 /*
395  * prism2sta_ifstate
396  *
397  * Interface state.  This is the primary WLAN interface enable/disable
398  * handler.  Following the driver/load/deviceprobe sequence, this
399  * function must be called with a state of "enable" before any other
400  * commands will be accepted.
401  *
402  * Arguments:
403  *      wlandev         wlan device structure
404  *      msgp            ptr to msg buffer
405  *
406  * Returns:
407  *      A p80211 message resultcode value.
408  *
409  * Side effects:
410  *
411  * Call context:
412  *      process thread  (usually)
413  *      interrupt
414  */
415 u32 prism2sta_ifstate(struct wlandevice *wlandev, u32 ifstate)
416 {
417         struct hfa384x *hw = wlandev->priv;
418         u32 result;
419
420         result = P80211ENUM_resultcode_implementation_failure;
421
422         pr_debug("Current MSD state(%d), requesting(%d)\n",
423                  wlandev->msdstate, ifstate);
424         switch (ifstate) {
425         case P80211ENUM_ifstate_fwload:
426                 switch (wlandev->msdstate) {
427                 case WLAN_MSD_HWPRESENT:
428                         wlandev->msdstate = WLAN_MSD_FWLOAD_PENDING;
429                         /*
430                          * Initialize the device+driver sufficiently
431                          * for firmware loading.
432                          */
433                         result = hfa384x_drvr_start(hw);
434                         if (result) {
435                                 netdev_err(wlandev->netdev,
436                                            "hfa384x_drvr_start() failed,result=%d\n",
437                                            (int)result);
438                                 result =
439                                  P80211ENUM_resultcode_implementation_failure;
440                                 wlandev->msdstate = WLAN_MSD_HWPRESENT;
441                                 break;
442                         }
443                         wlandev->msdstate = WLAN_MSD_FWLOAD;
444                         result = P80211ENUM_resultcode_success;
445                         break;
446                 case WLAN_MSD_FWLOAD:
447                         hfa384x_cmd_initialize(hw);
448                         result = P80211ENUM_resultcode_success;
449                         break;
450                 case WLAN_MSD_RUNNING:
451                         netdev_warn(wlandev->netdev,
452                                     "Cannot enter fwload state from enable state, you must disable first.\n");
453                         result = P80211ENUM_resultcode_invalid_parameters;
454                         break;
455                 case WLAN_MSD_HWFAIL:
456                 default:
457                         /* probe() had a problem or the msdstate contains
458                          * an unrecognized value, there's nothing we can do.
459                          */
460                         result = P80211ENUM_resultcode_implementation_failure;
461                         break;
462                 }
463                 break;
464         case P80211ENUM_ifstate_enable:
465                 switch (wlandev->msdstate) {
466                 case WLAN_MSD_HWPRESENT:
467                 case WLAN_MSD_FWLOAD:
468                         wlandev->msdstate = WLAN_MSD_RUNNING_PENDING;
469                         /* Initialize the device+driver for full
470                          * operation. Note that this might me an FWLOAD to
471                          * to RUNNING transition so we must not do a chip
472                          * or board level reset.  Note that on failure,
473                          * the MSD state is set to HWPRESENT because we
474                          * can't make any assumptions about the state
475                          * of the hardware or a previous firmware load.
476                          */
477                         result = hfa384x_drvr_start(hw);
478                         if (result) {
479                                 netdev_err(wlandev->netdev,
480                                            "hfa384x_drvr_start() failed,result=%d\n",
481                                            (int)result);
482                                 result =
483                                   P80211ENUM_resultcode_implementation_failure;
484                                 wlandev->msdstate = WLAN_MSD_HWPRESENT;
485                                 break;
486                         }
487
488                         result = prism2sta_getcardinfo(wlandev);
489                         if (result) {
490                                 netdev_err(wlandev->netdev,
491                                            "prism2sta_getcardinfo() failed,result=%d\n",
492                                            (int)result);
493                                 result =
494                                   P80211ENUM_resultcode_implementation_failure;
495                                 hfa384x_drvr_stop(hw);
496                                 wlandev->msdstate = WLAN_MSD_HWPRESENT;
497                                 break;
498                         }
499                         result = prism2sta_globalsetup(wlandev);
500                         if (result) {
501                                 netdev_err(wlandev->netdev,
502                                            "prism2sta_globalsetup() failed,result=%d\n",
503                                            (int)result);
504                                 result =
505                                   P80211ENUM_resultcode_implementation_failure;
506                                 hfa384x_drvr_stop(hw);
507                                 wlandev->msdstate = WLAN_MSD_HWPRESENT;
508                                 break;
509                         }
510                         wlandev->msdstate = WLAN_MSD_RUNNING;
511                         hw->join_ap = 0;
512                         hw->join_retries = 60;
513                         result = P80211ENUM_resultcode_success;
514                         break;
515                 case WLAN_MSD_RUNNING:
516                         /* Do nothing, we're already in this state. */
517                         result = P80211ENUM_resultcode_success;
518                         break;
519                 case WLAN_MSD_HWFAIL:
520                 default:
521                         /* probe() had a problem or the msdstate contains
522                          * an unrecognized value, there's nothing we can do.
523                          */
524                         result = P80211ENUM_resultcode_implementation_failure;
525                         break;
526                 }
527                 break;
528         case P80211ENUM_ifstate_disable:
529                 switch (wlandev->msdstate) {
530                 case WLAN_MSD_HWPRESENT:
531                         /* Do nothing, we're already in this state. */
532                         result = P80211ENUM_resultcode_success;
533                         break;
534                 case WLAN_MSD_FWLOAD:
535                 case WLAN_MSD_RUNNING:
536                         wlandev->msdstate = WLAN_MSD_HWPRESENT_PENDING;
537                         /*
538                          * TODO: Shut down the MAC completely. Here a chip
539                          * or board level reset is probably called for.
540                          * After a "disable" _all_ results are lost, even
541                          * those from a fwload.
542                          */
543                         if (!wlandev->hwremoved)
544                                 netif_carrier_off(wlandev->netdev);
545
546                         hfa384x_drvr_stop(hw);
547
548                         wlandev->macmode = WLAN_MACMODE_NONE;
549                         wlandev->msdstate = WLAN_MSD_HWPRESENT;
550                         result = P80211ENUM_resultcode_success;
551                         break;
552                 case WLAN_MSD_HWFAIL:
553                 default:
554                         /* probe() had a problem or the msdstate contains
555                          * an unrecognized value, there's nothing we can do.
556                          */
557                         result = P80211ENUM_resultcode_implementation_failure;
558                         break;
559                 }
560                 break;
561         default:
562                 result = P80211ENUM_resultcode_invalid_parameters;
563                 break;
564         }
565
566         return result;
567 }
568
569 /*
570  * prism2sta_getcardinfo
571  *
572  * Collect the NICID, firmware version and any other identifiers
573  * we'd like to have in host-side data structures.
574  *
575  * Arguments:
576  *      wlandev         wlan device structure
577  *
578  * Returns:
579  *      0       success
580  *      >0      f/w reported error
581  *      <0      driver reported error
582  *
583  * Side effects:
584  *
585  * Call context:
586  *      Either.
587  */
588 static int prism2sta_getcardinfo(struct wlandevice *wlandev)
589 {
590         int result = 0;
591         struct hfa384x *hw = wlandev->priv;
592         u16 temp;
593         u8 snum[HFA384x_RID_NICSERIALNUMBER_LEN];
594
595         /* Collect version and compatibility info */
596         /*  Some are critical, some are not */
597         /* NIC identity */
598         result = hfa384x_drvr_getconfig(hw, HFA384x_RID_NICIDENTITY,
599                                         &hw->ident_nic,
600                                         sizeof(struct hfa384x_compident));
601         if (result) {
602                 netdev_err(wlandev->netdev, "Failed to retrieve NICIDENTITY\n");
603                 goto failed;
604         }
605
606         /* get all the nic id fields in host byte order */
607         le16_to_cpus(&hw->ident_nic.id);
608         le16_to_cpus(&hw->ident_nic.variant);
609         le16_to_cpus(&hw->ident_nic.major);
610         le16_to_cpus(&hw->ident_nic.minor);
611
612         netdev_info(wlandev->netdev, "ident: nic h/w: id=0x%02x %d.%d.%d\n",
613                     hw->ident_nic.id, hw->ident_nic.major,
614                     hw->ident_nic.minor, hw->ident_nic.variant);
615
616         /* Primary f/w identity */
617         result = hfa384x_drvr_getconfig(hw, HFA384x_RID_PRIIDENTITY,
618                                         &hw->ident_pri_fw,
619                                         sizeof(struct hfa384x_compident));
620         if (result) {
621                 netdev_err(wlandev->netdev, "Failed to retrieve PRIIDENTITY\n");
622                 goto failed;
623         }
624
625         /* get all the private fw id fields in host byte order */
626         le16_to_cpus(&hw->ident_pri_fw.id);
627         le16_to_cpus(&hw->ident_pri_fw.variant);
628         le16_to_cpus(&hw->ident_pri_fw.major);
629         le16_to_cpus(&hw->ident_pri_fw.minor);
630
631         netdev_info(wlandev->netdev, "ident: pri f/w: id=0x%02x %d.%d.%d\n",
632                     hw->ident_pri_fw.id, hw->ident_pri_fw.major,
633                     hw->ident_pri_fw.minor, hw->ident_pri_fw.variant);
634
635         /* Station (Secondary?) f/w identity */
636         result = hfa384x_drvr_getconfig(hw, HFA384x_RID_STAIDENTITY,
637                                         &hw->ident_sta_fw,
638                                         sizeof(struct hfa384x_compident));
639         if (result) {
640                 netdev_err(wlandev->netdev, "Failed to retrieve STAIDENTITY\n");
641                 goto failed;
642         }
643
644         if (hw->ident_nic.id < 0x8000) {
645                 netdev_err(wlandev->netdev,
646                            "FATAL: Card is not an Intersil Prism2/2.5/3\n");
647                 result = -1;
648                 goto failed;
649         }
650
651         /* get all the station fw id fields in host byte order */
652         le16_to_cpus(&hw->ident_sta_fw.id);
653         le16_to_cpus(&hw->ident_sta_fw.variant);
654         le16_to_cpus(&hw->ident_sta_fw.major);
655         le16_to_cpus(&hw->ident_sta_fw.minor);
656
657         /* strip out the 'special' variant bits */
658         hw->mm_mods = hw->ident_sta_fw.variant & GENMASK(15, 14);
659         hw->ident_sta_fw.variant &= ~((u16)GENMASK(15, 14));
660
661         if (hw->ident_sta_fw.id == 0x1f) {
662                 netdev_info(wlandev->netdev,
663                             "ident: sta f/w: id=0x%02x %d.%d.%d\n",
664                             hw->ident_sta_fw.id, hw->ident_sta_fw.major,
665                             hw->ident_sta_fw.minor, hw->ident_sta_fw.variant);
666         } else {
667                 netdev_info(wlandev->netdev,
668                             "ident:  ap f/w: id=0x%02x %d.%d.%d\n",
669                             hw->ident_sta_fw.id, hw->ident_sta_fw.major,
670                             hw->ident_sta_fw.minor, hw->ident_sta_fw.variant);
671                 netdev_err(wlandev->netdev, "Unsupported Tertiary AP firmware loaded!\n");
672                 goto failed;
673         }
674
675         /* Compatibility range, Modem supplier */
676         result = hfa384x_drvr_getconfig(hw, HFA384x_RID_MFISUPRANGE,
677                                         &hw->cap_sup_mfi,
678                                         sizeof(struct hfa384x_caplevel));
679         if (result) {
680                 netdev_err(wlandev->netdev, "Failed to retrieve MFISUPRANGE\n");
681                 goto failed;
682         }
683
684         /* get all the Compatibility range, modem interface supplier
685          * fields in byte order
686          */
687         le16_to_cpus(&hw->cap_sup_mfi.role);
688         le16_to_cpus(&hw->cap_sup_mfi.id);
689         le16_to_cpus(&hw->cap_sup_mfi.variant);
690         le16_to_cpus(&hw->cap_sup_mfi.bottom);
691         le16_to_cpus(&hw->cap_sup_mfi.top);
692
693         netdev_info(wlandev->netdev,
694                     "MFI:SUP:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
695                     hw->cap_sup_mfi.role, hw->cap_sup_mfi.id,
696                     hw->cap_sup_mfi.variant, hw->cap_sup_mfi.bottom,
697                     hw->cap_sup_mfi.top);
698
699         /* Compatibility range, Controller supplier */
700         result = hfa384x_drvr_getconfig(hw, HFA384x_RID_CFISUPRANGE,
701                                         &hw->cap_sup_cfi,
702                                         sizeof(struct hfa384x_caplevel));
703         if (result) {
704                 netdev_err(wlandev->netdev, "Failed to retrieve CFISUPRANGE\n");
705                 goto failed;
706         }
707
708         /* get all the Compatibility range, controller interface supplier
709          * fields in byte order
710          */
711         le16_to_cpus(&hw->cap_sup_cfi.role);
712         le16_to_cpus(&hw->cap_sup_cfi.id);
713         le16_to_cpus(&hw->cap_sup_cfi.variant);
714         le16_to_cpus(&hw->cap_sup_cfi.bottom);
715         le16_to_cpus(&hw->cap_sup_cfi.top);
716
717         netdev_info(wlandev->netdev,
718                     "CFI:SUP:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
719                     hw->cap_sup_cfi.role, hw->cap_sup_cfi.id,
720                     hw->cap_sup_cfi.variant, hw->cap_sup_cfi.bottom,
721                     hw->cap_sup_cfi.top);
722
723         /* Compatibility range, Primary f/w supplier */
724         result = hfa384x_drvr_getconfig(hw, HFA384x_RID_PRISUPRANGE,
725                                         &hw->cap_sup_pri,
726                                         sizeof(struct hfa384x_caplevel));
727         if (result) {
728                 netdev_err(wlandev->netdev, "Failed to retrieve PRISUPRANGE\n");
729                 goto failed;
730         }
731
732         /* get all the Compatibility range, primary firmware supplier
733          * fields in byte order
734          */
735         le16_to_cpus(&hw->cap_sup_pri.role);
736         le16_to_cpus(&hw->cap_sup_pri.id);
737         le16_to_cpus(&hw->cap_sup_pri.variant);
738         le16_to_cpus(&hw->cap_sup_pri.bottom);
739         le16_to_cpus(&hw->cap_sup_pri.top);
740
741         netdev_info(wlandev->netdev,
742                     "PRI:SUP:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
743                     hw->cap_sup_pri.role, hw->cap_sup_pri.id,
744                     hw->cap_sup_pri.variant, hw->cap_sup_pri.bottom,
745                     hw->cap_sup_pri.top);
746
747         /* Compatibility range, Station f/w supplier */
748         result = hfa384x_drvr_getconfig(hw, HFA384x_RID_STASUPRANGE,
749                                         &hw->cap_sup_sta,
750                                         sizeof(struct hfa384x_caplevel));
751         if (result) {
752                 netdev_err(wlandev->netdev, "Failed to retrieve STASUPRANGE\n");
753                 goto failed;
754         }
755
756         /* get all the Compatibility range, station firmware supplier
757          * fields in byte order
758          */
759         le16_to_cpus(&hw->cap_sup_sta.role);
760         le16_to_cpus(&hw->cap_sup_sta.id);
761         le16_to_cpus(&hw->cap_sup_sta.variant);
762         le16_to_cpus(&hw->cap_sup_sta.bottom);
763         le16_to_cpus(&hw->cap_sup_sta.top);
764
765         if (hw->cap_sup_sta.id == 0x04) {
766                 netdev_info(wlandev->netdev,
767                        "STA:SUP:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
768                        hw->cap_sup_sta.role, hw->cap_sup_sta.id,
769                        hw->cap_sup_sta.variant, hw->cap_sup_sta.bottom,
770                        hw->cap_sup_sta.top);
771         } else {
772                 netdev_info(wlandev->netdev,
773                        "AP:SUP:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
774                        hw->cap_sup_sta.role, hw->cap_sup_sta.id,
775                        hw->cap_sup_sta.variant, hw->cap_sup_sta.bottom,
776                        hw->cap_sup_sta.top);
777         }
778
779         /* Compatibility range, primary f/w actor, CFI supplier */
780         result = hfa384x_drvr_getconfig(hw, HFA384x_RID_PRI_CFIACTRANGES,
781                                         &hw->cap_act_pri_cfi,
782                                         sizeof(struct hfa384x_caplevel));
783         if (result) {
784                 netdev_err(wlandev->netdev, "Failed to retrieve PRI_CFIACTRANGES\n");
785                 goto failed;
786         }
787
788         /* get all the Compatibility range, primary f/w actor, CFI supplier
789          * fields in byte order
790          */
791         le16_to_cpus(&hw->cap_act_pri_cfi.role);
792         le16_to_cpus(&hw->cap_act_pri_cfi.id);
793         le16_to_cpus(&hw->cap_act_pri_cfi.variant);
794         le16_to_cpus(&hw->cap_act_pri_cfi.bottom);
795         le16_to_cpus(&hw->cap_act_pri_cfi.top);
796
797         netdev_info(wlandev->netdev,
798                     "PRI-CFI:ACT:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
799                     hw->cap_act_pri_cfi.role, hw->cap_act_pri_cfi.id,
800                     hw->cap_act_pri_cfi.variant, hw->cap_act_pri_cfi.bottom,
801                     hw->cap_act_pri_cfi.top);
802
803         /* Compatibility range, sta f/w actor, CFI supplier */
804         result = hfa384x_drvr_getconfig(hw, HFA384x_RID_STA_CFIACTRANGES,
805                                         &hw->cap_act_sta_cfi,
806                                         sizeof(struct hfa384x_caplevel));
807         if (result) {
808                 netdev_err(wlandev->netdev, "Failed to retrieve STA_CFIACTRANGES\n");
809                 goto failed;
810         }
811
812         /* get all the Compatibility range, station f/w actor, CFI supplier
813          * fields in byte order
814          */
815         le16_to_cpus(&hw->cap_act_sta_cfi.role);
816         le16_to_cpus(&hw->cap_act_sta_cfi.id);
817         le16_to_cpus(&hw->cap_act_sta_cfi.variant);
818         le16_to_cpus(&hw->cap_act_sta_cfi.bottom);
819         le16_to_cpus(&hw->cap_act_sta_cfi.top);
820
821         netdev_info(wlandev->netdev,
822                     "STA-CFI:ACT:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
823                     hw->cap_act_sta_cfi.role, hw->cap_act_sta_cfi.id,
824                     hw->cap_act_sta_cfi.variant, hw->cap_act_sta_cfi.bottom,
825                     hw->cap_act_sta_cfi.top);
826
827         /* Compatibility range, sta f/w actor, MFI supplier */
828         result = hfa384x_drvr_getconfig(hw, HFA384x_RID_STA_MFIACTRANGES,
829                                         &hw->cap_act_sta_mfi,
830                                         sizeof(struct hfa384x_caplevel));
831         if (result) {
832                 netdev_err(wlandev->netdev, "Failed to retrieve STA_MFIACTRANGES\n");
833                 goto failed;
834         }
835
836         /* get all the Compatibility range, station f/w actor, MFI supplier
837          * fields in byte order
838          */
839         le16_to_cpus(&hw->cap_act_sta_mfi.role);
840         le16_to_cpus(&hw->cap_act_sta_mfi.id);
841         le16_to_cpus(&hw->cap_act_sta_mfi.variant);
842         le16_to_cpus(&hw->cap_act_sta_mfi.bottom);
843         le16_to_cpus(&hw->cap_act_sta_mfi.top);
844
845         netdev_info(wlandev->netdev,
846                     "STA-MFI:ACT:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n",
847                     hw->cap_act_sta_mfi.role, hw->cap_act_sta_mfi.id,
848                     hw->cap_act_sta_mfi.variant, hw->cap_act_sta_mfi.bottom,
849                     hw->cap_act_sta_mfi.top);
850
851         /* Serial Number */
852         result = hfa384x_drvr_getconfig(hw, HFA384x_RID_NICSERIALNUMBER,
853                                         snum, HFA384x_RID_NICSERIALNUMBER_LEN);
854         if (!result) {
855                 netdev_info(wlandev->netdev, "Prism2 card SN: %*pEhp\n",
856                             HFA384x_RID_NICSERIALNUMBER_LEN, snum);
857         } else {
858                 netdev_err(wlandev->netdev, "Failed to retrieve Prism2 Card SN\n");
859                 goto failed;
860         }
861
862         /* Collect the MAC address */
863         result = hfa384x_drvr_getconfig(hw, HFA384x_RID_CNFOWNMACADDR,
864                                         wlandev->netdev->dev_addr, ETH_ALEN);
865         if (result != 0) {
866                 netdev_err(wlandev->netdev, "Failed to retrieve mac address\n");
867                 goto failed;
868         }
869
870         /* short preamble is always implemented */
871         wlandev->nsdcaps |= P80211_NSDCAP_SHORT_PREAMBLE;
872
873         /* find out if hardware wep is implemented */
874         hfa384x_drvr_getconfig16(hw, HFA384x_RID_PRIVACYOPTIMP, &temp);
875         if (temp)
876                 wlandev->nsdcaps |= P80211_NSDCAP_HARDWAREWEP;
877
878         /* get the dBm Scaling constant */
879         hfa384x_drvr_getconfig16(hw, HFA384x_RID_CNFDBMADJUST, &temp);
880         hw->dbmadjust = temp;
881
882         /* Only enable scan by default on newer firmware */
883         if (HFA384x_FIRMWARE_VERSION(hw->ident_sta_fw.major,
884                                      hw->ident_sta_fw.minor,
885                                      hw->ident_sta_fw.variant) <
886             HFA384x_FIRMWARE_VERSION(1, 5, 5)) {
887                 wlandev->nsdcaps |= P80211_NSDCAP_NOSCAN;
888         }
889
890         /* TODO: Set any internally managed config items */
891
892         goto done;
893 failed:
894         netdev_err(wlandev->netdev, "Failed, result=%d\n", result);
895 done:
896         return result;
897 }
898
899 /*
900  * prism2sta_globalsetup
901  *
902  * Set any global RIDs that we want to set at device activation.
903  *
904  * Arguments:
905  *      wlandev         wlan device structure
906  *
907  * Returns:
908  *      0       success
909  *      >0      f/w reported error
910  *      <0      driver reported error
911  *
912  * Side effects:
913  *
914  * Call context:
915  *      process thread
916  */
917 static int prism2sta_globalsetup(struct wlandevice *wlandev)
918 {
919         struct hfa384x *hw = wlandev->priv;
920
921         /* Set the maximum frame size */
922         return hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFMAXDATALEN,
923                                         WLAN_DATA_MAXLEN);
924 }
925
926 static int prism2sta_setmulticast(struct wlandevice *wlandev,
927                                   struct net_device *dev)
928 {
929         int result = 0;
930         struct hfa384x *hw = wlandev->priv;
931
932         u16 promisc;
933
934         /* If we're not ready, what's the point? */
935         if (hw->state != HFA384x_STATE_RUNNING)
936                 goto exit;
937
938         if ((dev->flags & (IFF_PROMISC | IFF_ALLMULTI)) != 0)
939                 promisc = P80211ENUM_truth_true;
940         else
941                 promisc = P80211ENUM_truth_false;
942
943         result =
944             hfa384x_drvr_setconfig16_async(hw, HFA384x_RID_PROMISCMODE,
945                                            promisc);
946 exit:
947         return result;
948 }
949
950 /*
951  * prism2sta_inf_handover
952  *
953  * Handles the receipt of a Handover info frame. Should only be present
954  * in APs only.
955  *
956  * Arguments:
957  *      wlandev         wlan device structure
958  *      inf             ptr to info frame (contents in hfa384x order)
959  *
960  * Returns:
961  *      nothing
962  *
963  * Side effects:
964  *
965  * Call context:
966  *      interrupt
967  */
968 static void prism2sta_inf_handover(struct wlandevice *wlandev,
969                                    struct hfa384x_inf_frame *inf)
970 {
971         pr_debug("received infoframe:HANDOVER (unhandled)\n");
972 }
973
974 /*
975  * prism2sta_inf_tallies
976  *
977  * Handles the receipt of a CommTallies info frame.
978  *
979  * Arguments:
980  *      wlandev         wlan device structure
981  *      inf             ptr to info frame (contents in hfa384x order)
982  *
983  * Returns:
984  *      nothing
985  *
986  * Side effects:
987  *
988  * Call context:
989  *      interrupt
990  */
991 static void prism2sta_inf_tallies(struct wlandevice *wlandev,
992                                   struct hfa384x_inf_frame *inf)
993 {
994         struct hfa384x *hw = wlandev->priv;
995         __le16 *src16;
996         u32 *dst;
997         __le32 *src32;
998         int i;
999         int cnt;
1000
1001         /*
1002          * Determine if these are 16-bit or 32-bit tallies, based on the
1003          * record length of the info record.
1004          */
1005
1006         cnt = sizeof(struct hfa384x_comm_tallies_32) / sizeof(u32);
1007         if (inf->framelen > 22) {
1008                 dst = (u32 *)&hw->tallies;
1009                 src32 = (__le32 *)&inf->info.commtallies32;
1010                 for (i = 0; i < cnt; i++, dst++, src32++)
1011                         *dst += le32_to_cpu(*src32);
1012         } else {
1013                 dst = (u32 *)&hw->tallies;
1014                 src16 = (__le16 *)&inf->info.commtallies16;
1015                 for (i = 0; i < cnt; i++, dst++, src16++)
1016                         *dst += le16_to_cpu(*src16);
1017         }
1018 }
1019
1020 /*
1021  * prism2sta_inf_scanresults
1022  *
1023  * Handles the receipt of a Scan Results info frame.
1024  *
1025  * Arguments:
1026  *      wlandev         wlan device structure
1027  *      inf             ptr to info frame (contents in hfa384x order)
1028  *
1029  * Returns:
1030  *      nothing
1031  *
1032  * Side effects:
1033  *
1034  * Call context:
1035  *      interrupt
1036  */
1037 static void prism2sta_inf_scanresults(struct wlandevice *wlandev,
1038                                       struct hfa384x_inf_frame *inf)
1039 {
1040         struct hfa384x *hw = wlandev->priv;
1041         int nbss;
1042         struct hfa384x_scan_result *sr = &inf->info.scanresult;
1043         int i;
1044         struct hfa384x_join_request_data joinreq;
1045         int result;
1046
1047         /* Get the number of results, first in bytes, then in results */
1048         nbss = (inf->framelen * sizeof(u16)) -
1049             sizeof(inf->infotype) - sizeof(inf->info.scanresult.scanreason);
1050         nbss /= sizeof(struct hfa384x_scan_result_sub);
1051
1052         /* Print em */
1053         pr_debug("rx scanresults, reason=%d, nbss=%d:\n",
1054                  inf->info.scanresult.scanreason, nbss);
1055         for (i = 0; i < nbss; i++) {
1056                 pr_debug("chid=%d anl=%d sl=%d bcnint=%d\n",
1057                          sr->result[i].chid,
1058                          sr->result[i].anl,
1059                          sr->result[i].sl, sr->result[i].bcnint);
1060                 pr_debug("  capinfo=0x%04x proberesp_rate=%d\n",
1061                          sr->result[i].capinfo, sr->result[i].proberesp_rate);
1062         }
1063         /* issue a join request */
1064         joinreq.channel = sr->result[0].chid;
1065         memcpy(joinreq.bssid, sr->result[0].bssid, WLAN_BSSID_LEN);
1066         result = hfa384x_drvr_setconfig(hw,
1067                                         HFA384x_RID_JOINREQUEST,
1068                                         &joinreq, HFA384x_RID_JOINREQUEST_LEN);
1069         if (result) {
1070                 netdev_err(wlandev->netdev, "setconfig(joinreq) failed, result=%d\n",
1071                            result);
1072         }
1073 }
1074
1075 /*
1076  * prism2sta_inf_hostscanresults
1077  *
1078  * Handles the receipt of a Scan Results info frame.
1079  *
1080  * Arguments:
1081  *      wlandev         wlan device structure
1082  *      inf             ptr to info frame (contents in hfa384x order)
1083  *
1084  * Returns:
1085  *      nothing
1086  *
1087  * Side effects:
1088  *
1089  * Call context:
1090  *      interrupt
1091  */
1092 static void prism2sta_inf_hostscanresults(struct wlandevice *wlandev,
1093                                           struct hfa384x_inf_frame *inf)
1094 {
1095         struct hfa384x *hw = wlandev->priv;
1096         int nbss;
1097
1098         nbss = (inf->framelen - 3) / 32;
1099         pr_debug("Received %d hostscan results\n", nbss);
1100
1101         if (nbss > 32)
1102                 nbss = 32;
1103
1104         kfree(hw->scanresults);
1105
1106         hw->scanresults = kmemdup(inf, sizeof(*inf), GFP_ATOMIC);
1107
1108         if (nbss == 0)
1109                 nbss = -1;
1110
1111         /* Notify/wake the sleeping caller. */
1112         hw->scanflag = nbss;
1113         wake_up_interruptible(&hw->cmdq);
1114 };
1115
1116 /*
1117  * prism2sta_inf_chinforesults
1118  *
1119  * Handles the receipt of a Channel Info Results info frame.
1120  *
1121  * Arguments:
1122  *      wlandev         wlan device structure
1123  *      inf             ptr to info frame (contents in hfa384x order)
1124  *
1125  * Returns:
1126  *      nothing
1127  *
1128  * Side effects:
1129  *
1130  * Call context:
1131  *      interrupt
1132  */
1133 static void prism2sta_inf_chinforesults(struct wlandevice *wlandev,
1134                                         struct hfa384x_inf_frame *inf)
1135 {
1136         struct hfa384x *hw = wlandev->priv;
1137         unsigned int i, n;
1138
1139         hw->channel_info.results.scanchannels =
1140             inf->info.chinforesult.scanchannels;
1141
1142         for (i = 0, n = 0; i < HFA384x_CHINFORESULT_MAX; i++) {
1143                 struct hfa384x_ch_info_result_sub *result;
1144                 struct hfa384x_ch_info_result_sub *chinforesult;
1145                 int chan;
1146
1147                 if (!(hw->channel_info.results.scanchannels & (1 << i)))
1148                         continue;
1149
1150                 result = &inf->info.chinforesult.result[n];
1151                 chan = result->chid - 1;
1152
1153                 if (chan < 0 || chan >= HFA384x_CHINFORESULT_MAX)
1154                         continue;
1155
1156                 chinforesult = &hw->channel_info.results.result[chan];
1157                 chinforesult->chid = chan;
1158                 chinforesult->anl = result->anl;
1159                 chinforesult->pnl = result->pnl;
1160                 chinforesult->active = result->active;
1161
1162                 pr_debug("chinfo: channel %d, %s level (avg/peak)=%d/%d dB, pcf %d\n",
1163                          chan + 1,
1164                          (chinforesult->active & HFA384x_CHINFORESULT_BSSACTIVE)
1165                                 ? "signal" : "noise",
1166                          chinforesult->anl, chinforesult->pnl,
1167                          (chinforesult->active & HFA384x_CHINFORESULT_PCFACTIVE)
1168                                 ? 1 : 0);
1169                 n++;
1170         }
1171         atomic_set(&hw->channel_info.done, 2);
1172
1173         hw->channel_info.count = n;
1174 }
1175
1176 void prism2sta_processing_defer(struct work_struct *data)
1177 {
1178         struct hfa384x *hw = container_of(data, struct hfa384x, link_bh);
1179         struct wlandevice *wlandev = hw->wlandev;
1180         struct hfa384x_bytestr32 ssid;
1181         int result;
1182
1183         /* First let's process the auth frames */
1184         {
1185                 struct sk_buff *skb;
1186                 struct hfa384x_inf_frame *inf;
1187
1188                 while ((skb = skb_dequeue(&hw->authq))) {
1189                         inf = (struct hfa384x_inf_frame *)skb->data;
1190                         prism2sta_inf_authreq_defer(wlandev, inf);
1191                 }
1192
1193         }
1194
1195         /* Now let's handle the linkstatus stuff */
1196         if (hw->link_status == hw->link_status_new)
1197                 return;
1198
1199         hw->link_status = hw->link_status_new;
1200
1201         switch (hw->link_status) {
1202         case HFA384x_LINK_NOTCONNECTED:
1203                 /* I'm currently assuming that this is the initial link
1204                  * state.  It should only be possible immediately
1205                  * following an Enable command.
1206                  * Response:
1207                  * Block Transmits, Ignore receives of data frames
1208                  */
1209                 netif_carrier_off(wlandev->netdev);
1210
1211                 netdev_info(wlandev->netdev, "linkstatus=NOTCONNECTED (unhandled)\n");
1212                 break;
1213
1214         case HFA384x_LINK_CONNECTED:
1215                 /* This one indicates a successful scan/join/auth/assoc.
1216                  * When we have the full MLME complement, this event will
1217                  * signify successful completion of both mlme_authenticate
1218                  * and mlme_associate.  State management will get a little
1219                  * ugly here.
1220                  * Response:
1221                  * Indicate authentication and/or association
1222                  * Enable Transmits, Receives and pass up data frames
1223                  */
1224
1225                 netif_carrier_on(wlandev->netdev);
1226
1227                 /* If we are joining a specific AP, set our
1228                  * state and reset retries
1229                  */
1230                 if (hw->join_ap == 1)
1231                         hw->join_ap = 2;
1232                 hw->join_retries = 60;
1233
1234                 /* Don't call this in monitor mode */
1235                 if (wlandev->netdev->type == ARPHRD_ETHER) {
1236                         u16 portstatus;
1237
1238                         netdev_info(wlandev->netdev, "linkstatus=CONNECTED\n");
1239
1240                         /* For non-usb devices, we can use the sync versions */
1241                         /* Collect the BSSID, and set state to allow tx */
1242
1243                         result = hfa384x_drvr_getconfig(hw,
1244                                                 HFA384x_RID_CURRENTBSSID,
1245                                                 wlandev->bssid,
1246                                                 WLAN_BSSID_LEN);
1247                         if (result) {
1248                                 pr_debug
1249                                     ("getconfig(0x%02x) failed, result = %d\n",
1250                                      HFA384x_RID_CURRENTBSSID, result);
1251                                 return;
1252                         }
1253
1254                         result = hfa384x_drvr_getconfig(hw,
1255                                                         HFA384x_RID_CURRENTSSID,
1256                                                         &ssid, sizeof(ssid));
1257                         if (result) {
1258                                 pr_debug
1259                                     ("getconfig(0x%02x) failed, result = %d\n",
1260                                      HFA384x_RID_CURRENTSSID, result);
1261                                 return;
1262                         }
1263                         prism2mgmt_bytestr2pstr(
1264                                         (struct hfa384x_bytestr *)&ssid,
1265                                         (struct p80211pstrd *)&wlandev->ssid);
1266
1267                         /* Collect the port status */
1268                         result = hfa384x_drvr_getconfig16(hw,
1269                                                         HFA384x_RID_PORTSTATUS,
1270                                                         &portstatus);
1271                         if (result) {
1272                                 pr_debug
1273                                     ("getconfig(0x%02x) failed, result = %d\n",
1274                                      HFA384x_RID_PORTSTATUS, result);
1275                                 return;
1276                         }
1277                         wlandev->macmode =
1278                             (portstatus == HFA384x_PSTATUS_CONN_IBSS) ?
1279                             WLAN_MACMODE_IBSS_STA : WLAN_MACMODE_ESS_STA;
1280
1281                         /* signal back up to cfg80211 layer */
1282                         prism2_connect_result(wlandev, P80211ENUM_truth_false);
1283
1284                         /* Get the ball rolling on the comms quality stuff */
1285                         prism2sta_commsqual_defer(&hw->commsqual_bh);
1286                 }
1287                 break;
1288
1289         case HFA384x_LINK_DISCONNECTED:
1290                 /* This one indicates that our association is gone.  We've
1291                  * lost connection with the AP and/or been disassociated.
1292                  * This indicates that the MAC has completely cleared it's
1293                  * associated state.  We * should send a deauth indication
1294                  * (implying disassoc) up * to the MLME.
1295                  * Response:
1296                  * Indicate Deauthentication
1297                  * Block Transmits, Ignore receives of data frames
1298                  */
1299                 if (wlandev->netdev->type == ARPHRD_ETHER)
1300                         netdev_info(wlandev->netdev,
1301                                     "linkstatus=DISCONNECTED (unhandled)\n");
1302                 wlandev->macmode = WLAN_MACMODE_NONE;
1303
1304                 netif_carrier_off(wlandev->netdev);
1305
1306                 /* signal back up to cfg80211 layer */
1307                 prism2_disconnected(wlandev);
1308
1309                 break;
1310
1311         case HFA384x_LINK_AP_CHANGE:
1312                 /* This one indicates that the MAC has decided to and
1313                  * successfully completed a change to another AP.  We
1314                  * should probably implement a reassociation indication
1315                  * in response to this one.  I'm thinking that the
1316                  * p80211 layer needs to be notified in case of
1317                  * buffering/queueing issues.  User mode also needs to be
1318                  * notified so that any BSS dependent elements can be
1319                  * updated.
1320                  * associated state.  We * should send a deauth indication
1321                  * (implying disassoc) up * to the MLME.
1322                  * Response:
1323                  * Indicate Reassociation
1324                  * Enable Transmits, Receives and pass up data frames
1325                  */
1326                 netdev_info(wlandev->netdev, "linkstatus=AP_CHANGE\n");
1327
1328                 result = hfa384x_drvr_getconfig(hw,
1329                                                 HFA384x_RID_CURRENTBSSID,
1330                                                 wlandev->bssid, WLAN_BSSID_LEN);
1331                 if (result) {
1332                         pr_debug("getconfig(0x%02x) failed, result = %d\n",
1333                                  HFA384x_RID_CURRENTBSSID, result);
1334                         return;
1335                 }
1336
1337                 result = hfa384x_drvr_getconfig(hw,
1338                                                 HFA384x_RID_CURRENTSSID,
1339                                                 &ssid, sizeof(ssid));
1340                 if (result) {
1341                         pr_debug("getconfig(0x%02x) failed, result = %d\n",
1342                                  HFA384x_RID_CURRENTSSID, result);
1343                         return;
1344                 }
1345                 prism2mgmt_bytestr2pstr((struct hfa384x_bytestr *)&ssid,
1346                                         (struct p80211pstrd *)&wlandev->ssid);
1347
1348                 hw->link_status = HFA384x_LINK_CONNECTED;
1349                 netif_carrier_on(wlandev->netdev);
1350
1351                 /* signal back up to cfg80211 layer */
1352                 prism2_roamed(wlandev);
1353
1354                 break;
1355
1356         case HFA384x_LINK_AP_OUTOFRANGE:
1357                 /* This one indicates that the MAC has decided that the
1358                  * AP is out of range, but hasn't found a better candidate
1359                  * so the MAC maintains its "associated" state in case
1360                  * we get back in range.  We should block transmits and
1361                  * receives in this state.  Do we need an indication here?
1362                  * Probably not since a polling user-mode element would
1363                  * get this status from from p2PortStatus(FD40). What about
1364                  * p80211?
1365                  * Response:
1366                  * Block Transmits, Ignore receives of data frames
1367                  */
1368                 netdev_info(wlandev->netdev, "linkstatus=AP_OUTOFRANGE (unhandled)\n");
1369
1370                 netif_carrier_off(wlandev->netdev);
1371
1372                 break;
1373
1374         case HFA384x_LINK_AP_INRANGE:
1375                 /* This one indicates that the MAC has decided that the
1376                  * AP is back in range.  We continue working with our
1377                  * existing association.
1378                  * Response:
1379                  * Enable Transmits, Receives and pass up data frames
1380                  */
1381                 netdev_info(wlandev->netdev, "linkstatus=AP_INRANGE\n");
1382
1383                 hw->link_status = HFA384x_LINK_CONNECTED;
1384                 netif_carrier_on(wlandev->netdev);
1385
1386                 break;
1387
1388         case HFA384x_LINK_ASSOCFAIL:
1389                 /* This one is actually a peer to CONNECTED.  We've
1390                  * requested a join for a given SSID and optionally BSSID.
1391                  * We can use this one to indicate authentication and
1392                  * association failures.  The trick is going to be
1393                  * 1) identifying the failure, and 2) state management.
1394                  * Response:
1395                  * Disable Transmits, Ignore receives of data frames
1396                  */
1397                 if (hw->join_ap && --hw->join_retries > 0) {
1398                         struct hfa384x_join_request_data joinreq;
1399
1400                         joinreq = hw->joinreq;
1401                         /* Send the join request */
1402                         hfa384x_drvr_setconfig(hw,
1403                                                HFA384x_RID_JOINREQUEST,
1404                                                &joinreq,
1405                                                HFA384x_RID_JOINREQUEST_LEN);
1406                         netdev_info(wlandev->netdev,
1407                                "linkstatus=ASSOCFAIL (re-submitting join)\n");
1408                 } else {
1409                         netdev_info(wlandev->netdev, "linkstatus=ASSOCFAIL (unhandled)\n");
1410                 }
1411
1412                 netif_carrier_off(wlandev->netdev);
1413
1414                 /* signal back up to cfg80211 layer */
1415                 prism2_connect_result(wlandev, P80211ENUM_truth_true);
1416
1417                 break;
1418
1419         default:
1420                 /* This is bad, IO port problems? */
1421                 netdev_warn(wlandev->netdev,
1422                             "unknown linkstatus=0x%02x\n", hw->link_status);
1423                 return;
1424         }
1425
1426         wlandev->linkstatus = (hw->link_status == HFA384x_LINK_CONNECTED);
1427 }
1428
1429 /*
1430  * prism2sta_inf_linkstatus
1431  *
1432  * Handles the receipt of a Link Status info frame.
1433  *
1434  * Arguments:
1435  *      wlandev         wlan device structure
1436  *      inf             ptr to info frame (contents in hfa384x order)
1437  *
1438  * Returns:
1439  *      nothing
1440  *
1441  * Side effects:
1442  *
1443  * Call context:
1444  *      interrupt
1445  */
1446 static void prism2sta_inf_linkstatus(struct wlandevice *wlandev,
1447                                      struct hfa384x_inf_frame *inf)
1448 {
1449         struct hfa384x *hw = wlandev->priv;
1450
1451         hw->link_status_new = le16_to_cpu(inf->info.linkstatus.linkstatus);
1452
1453         schedule_work(&hw->link_bh);
1454 }
1455
1456 /*
1457  * prism2sta_inf_assocstatus
1458  *
1459  * Handles the receipt of an Association Status info frame. Should
1460  * be present in APs only.
1461  *
1462  * Arguments:
1463  *      wlandev         wlan device structure
1464  *      inf             ptr to info frame (contents in hfa384x order)
1465  *
1466  * Returns:
1467  *      nothing
1468  *
1469  * Side effects:
1470  *
1471  * Call context:
1472  *      interrupt
1473  */
1474 static void prism2sta_inf_assocstatus(struct wlandevice *wlandev,
1475                                       struct hfa384x_inf_frame *inf)
1476 {
1477         struct hfa384x *hw = wlandev->priv;
1478         struct hfa384x_assoc_status rec;
1479         int i;
1480
1481         memcpy(&rec, &inf->info.assocstatus, sizeof(rec));
1482         le16_to_cpus(&rec.assocstatus);
1483         le16_to_cpus(&rec.reason);
1484
1485         /*
1486          * Find the address in the list of authenticated stations.
1487          * If it wasn't found, then this address has not been previously
1488          * authenticated and something weird has happened if this is
1489          * anything other than an "authentication failed" message.
1490          * If the address was found, then set the "associated" flag for
1491          * that station, based on whether the station is associating or
1492          * losing its association.  Something weird has also happened
1493          * if we find the address in the list of authenticated stations
1494          * but we are getting an "authentication failed" message.
1495          */
1496
1497         for (i = 0; i < hw->authlist.cnt; i++)
1498                 if (ether_addr_equal(rec.sta_addr, hw->authlist.addr[i]))
1499                         break;
1500
1501         if (i >= hw->authlist.cnt) {
1502                 if (rec.assocstatus != HFA384x_ASSOCSTATUS_AUTHFAIL)
1503                         netdev_warn(wlandev->netdev,
1504         "assocstatus info frame received for non-authenticated station.\n");
1505         } else {
1506                 hw->authlist.assoc[i] =
1507                     (rec.assocstatus == HFA384x_ASSOCSTATUS_STAASSOC ||
1508                      rec.assocstatus == HFA384x_ASSOCSTATUS_REASSOC);
1509
1510                 if (rec.assocstatus == HFA384x_ASSOCSTATUS_AUTHFAIL)
1511                         netdev_warn(wlandev->netdev,
1512 "authfail assocstatus info frame received for authenticated station.\n");
1513         }
1514 }
1515
1516 /*
1517  * prism2sta_inf_authreq
1518  *
1519  * Handles the receipt of an Authentication Request info frame. Should
1520  * be present in APs only.
1521  *
1522  * Arguments:
1523  *      wlandev         wlan device structure
1524  *      inf             ptr to info frame (contents in hfa384x order)
1525  *
1526  * Returns:
1527  *      nothing
1528  *
1529  * Side effects:
1530  *
1531  * Call context:
1532  *      interrupt
1533  *
1534  */
1535 static void prism2sta_inf_authreq(struct wlandevice *wlandev,
1536                                   struct hfa384x_inf_frame *inf)
1537 {
1538         struct hfa384x *hw = wlandev->priv;
1539         struct sk_buff *skb;
1540
1541         skb = dev_alloc_skb(sizeof(*inf));
1542         if (skb) {
1543                 skb_put(skb, sizeof(*inf));
1544                 memcpy(skb->data, inf, sizeof(*inf));
1545                 skb_queue_tail(&hw->authq, skb);
1546                 schedule_work(&hw->link_bh);
1547         }
1548 }
1549
1550 static void prism2sta_inf_authreq_defer(struct wlandevice *wlandev,
1551                                         struct hfa384x_inf_frame *inf)
1552 {
1553         struct hfa384x *hw = wlandev->priv;
1554         struct hfa384x_authenticate_station_data rec;
1555
1556         int i, added, result, cnt;
1557         u8 *addr;
1558
1559         /*
1560          * Build the AuthenticateStation record.  Initialize it for denying
1561          * authentication.
1562          */
1563
1564         ether_addr_copy(rec.address, inf->info.authreq.sta_addr);
1565         rec.status = cpu_to_le16(P80211ENUM_status_unspec_failure);
1566
1567         /*
1568          * Authenticate based on the access mode.
1569          */
1570
1571         switch (hw->accessmode) {
1572         case WLAN_ACCESS_NONE:
1573
1574                 /*
1575                  * Deny all new authentications.  However, if a station
1576                  * is ALREADY authenticated, then accept it.
1577                  */
1578
1579                 for (i = 0; i < hw->authlist.cnt; i++)
1580                         if (ether_addr_equal(rec.address,
1581                                              hw->authlist.addr[i])) {
1582                                 rec.status = cpu_to_le16(P80211ENUM_status_successful);
1583                                 break;
1584                         }
1585
1586                 break;
1587
1588         case WLAN_ACCESS_ALL:
1589
1590                 /*
1591                  * Allow all authentications.
1592                  */
1593
1594                 rec.status = cpu_to_le16(P80211ENUM_status_successful);
1595                 break;
1596
1597         case WLAN_ACCESS_ALLOW:
1598
1599                 /*
1600                  * Only allow the authentication if the MAC address
1601                  * is in the list of allowed addresses.
1602                  *
1603                  * Since this is the interrupt handler, we may be here
1604                  * while the access list is in the middle of being
1605                  * updated.  Choose the list which is currently okay.
1606                  * See "prism2mib_priv_accessallow()" for details.
1607                  */
1608
1609                 if (hw->allow.modify == 0) {
1610                         cnt = hw->allow.cnt;
1611                         addr = hw->allow.addr[0];
1612                 } else {
1613                         cnt = hw->allow.cnt1;
1614                         addr = hw->allow.addr1[0];
1615                 }
1616
1617                 for (i = 0; i < cnt; i++, addr += ETH_ALEN)
1618                         if (ether_addr_equal(rec.address, addr)) {
1619                                 rec.status = cpu_to_le16(P80211ENUM_status_successful);
1620                                 break;
1621                         }
1622
1623                 break;
1624
1625         case WLAN_ACCESS_DENY:
1626
1627                 /*
1628                  * Allow the authentication UNLESS the MAC address is
1629                  * in the list of denied addresses.
1630                  *
1631                  * Since this is the interrupt handler, we may be here
1632                  * while the access list is in the middle of being
1633                  * updated.  Choose the list which is currently okay.
1634                  * See "prism2mib_priv_accessdeny()" for details.
1635                  */
1636
1637                 if (hw->deny.modify == 0) {
1638                         cnt = hw->deny.cnt;
1639                         addr = hw->deny.addr[0];
1640                 } else {
1641                         cnt = hw->deny.cnt1;
1642                         addr = hw->deny.addr1[0];
1643                 }
1644
1645                 rec.status = cpu_to_le16(P80211ENUM_status_successful);
1646
1647                 for (i = 0; i < cnt; i++, addr += ETH_ALEN)
1648                         if (ether_addr_equal(rec.address, addr)) {
1649                                 rec.status = cpu_to_le16(P80211ENUM_status_unspec_failure);
1650                                 break;
1651                         }
1652
1653                 break;
1654         }
1655
1656         /*
1657          * If the authentication is okay, then add the MAC address to the
1658          * list of authenticated stations.  Don't add the address if it
1659          * is already in the list. (802.11b does not seem to disallow
1660          * a station from issuing an authentication request when the
1661          * station is already authenticated. Does this sort of thing
1662          * ever happen?  We might as well do the check just in case.)
1663          */
1664
1665         added = 0;
1666
1667         if (rec.status == cpu_to_le16(P80211ENUM_status_successful)) {
1668                 for (i = 0; i < hw->authlist.cnt; i++)
1669                         if (ether_addr_equal(rec.address,
1670                                              hw->authlist.addr[i]))
1671                                 break;
1672
1673                 if (i >= hw->authlist.cnt) {
1674                         if (hw->authlist.cnt >= WLAN_AUTH_MAX) {
1675                                 rec.status = cpu_to_le16(P80211ENUM_status_ap_full);
1676                         } else {
1677                                 ether_addr_copy(
1678                                         hw->authlist.addr[hw->authlist.cnt],
1679                                         rec.address);
1680                                 hw->authlist.cnt++;
1681                                 added = 1;
1682                         }
1683                 }
1684         }
1685
1686         /*
1687          * Send back the results of the authentication.  If this doesn't work,
1688          * then make sure to remove the address from the authenticated list if
1689          * it was added.
1690          */
1691
1692         rec.algorithm = inf->info.authreq.algorithm;
1693
1694         result = hfa384x_drvr_setconfig(hw, HFA384x_RID_AUTHENTICATESTA,
1695                                         &rec, sizeof(rec));
1696         if (result) {
1697                 if (added)
1698                         hw->authlist.cnt--;
1699                 netdev_err(wlandev->netdev,
1700                        "setconfig(authenticatestation) failed, result=%d\n",
1701                        result);
1702         }
1703 }
1704
1705 /*
1706  * prism2sta_inf_psusercnt
1707  *
1708  * Handles the receipt of a PowerSaveUserCount info frame. Should
1709  * be present in APs only.
1710  *
1711  * Arguments:
1712  *      wlandev         wlan device structure
1713  *      inf             ptr to info frame (contents in hfa384x order)
1714  *
1715  * Returns:
1716  *      nothing
1717  *
1718  * Side effects:
1719  *
1720  * Call context:
1721  *      interrupt
1722  */
1723 static void prism2sta_inf_psusercnt(struct wlandevice *wlandev,
1724                                     struct hfa384x_inf_frame *inf)
1725 {
1726         struct hfa384x *hw = wlandev->priv;
1727
1728         hw->psusercount = le16_to_cpu(inf->info.psusercnt.usercnt);
1729 }
1730
1731 /*
1732  * prism2sta_ev_info
1733  *
1734  * Handles the Info event.
1735  *
1736  * Arguments:
1737  *      wlandev         wlan device structure
1738  *      inf             ptr to a generic info frame
1739  *
1740  * Returns:
1741  *      nothing
1742  *
1743  * Side effects:
1744  *
1745  * Call context:
1746  *      interrupt
1747  */
1748 void prism2sta_ev_info(struct wlandevice *wlandev,
1749                        struct hfa384x_inf_frame *inf)
1750 {
1751         le16_to_cpus(&inf->infotype);
1752         /* Dispatch */
1753         switch (inf->infotype) {
1754         case HFA384x_IT_HANDOVERADDR:
1755                 prism2sta_inf_handover(wlandev, inf);
1756                 break;
1757         case HFA384x_IT_COMMTALLIES:
1758                 prism2sta_inf_tallies(wlandev, inf);
1759                 break;
1760         case HFA384x_IT_HOSTSCANRESULTS:
1761                 prism2sta_inf_hostscanresults(wlandev, inf);
1762                 break;
1763         case HFA384x_IT_SCANRESULTS:
1764                 prism2sta_inf_scanresults(wlandev, inf);
1765                 break;
1766         case HFA384x_IT_CHINFORESULTS:
1767                 prism2sta_inf_chinforesults(wlandev, inf);
1768                 break;
1769         case HFA384x_IT_LINKSTATUS:
1770                 prism2sta_inf_linkstatus(wlandev, inf);
1771                 break;
1772         case HFA384x_IT_ASSOCSTATUS:
1773                 prism2sta_inf_assocstatus(wlandev, inf);
1774                 break;
1775         case HFA384x_IT_AUTHREQ:
1776                 prism2sta_inf_authreq(wlandev, inf);
1777                 break;
1778         case HFA384x_IT_PSUSERCNT:
1779                 prism2sta_inf_psusercnt(wlandev, inf);
1780                 break;
1781         case HFA384x_IT_KEYIDCHANGED:
1782                 netdev_warn(wlandev->netdev, "Unhandled IT_KEYIDCHANGED\n");
1783                 break;
1784         case HFA384x_IT_ASSOCREQ:
1785                 netdev_warn(wlandev->netdev, "Unhandled IT_ASSOCREQ\n");
1786                 break;
1787         case HFA384x_IT_MICFAILURE:
1788                 netdev_warn(wlandev->netdev, "Unhandled IT_MICFAILURE\n");
1789                 break;
1790         default:
1791                 netdev_warn(wlandev->netdev,
1792                             "Unknown info type=0x%02x\n", inf->infotype);
1793                 break;
1794         }
1795 }
1796
1797 /*
1798  * prism2sta_ev_txexc
1799  *
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.
1803  *
1804  * Arguments:
1805  *      wlandev         wlan device structure
1806  *      status          tx frame status word
1807  *
1808  * Returns:
1809  *      nothing
1810  *
1811  * Side effects:
1812  *
1813  * Call context:
1814  *      interrupt
1815  */
1816 void prism2sta_ev_txexc(struct wlandevice *wlandev, u16 status)
1817 {
1818         pr_debug("TxExc status=0x%x.\n", status);
1819 }
1820
1821 /*
1822  * prism2sta_ev_tx
1823  *
1824  * Handles the Tx event.
1825  *
1826  * Arguments:
1827  *      wlandev         wlan device structure
1828  *      status          tx frame status word
1829  * Returns:
1830  *      nothing
1831  *
1832  * Side effects:
1833  *
1834  * Call context:
1835  *      interrupt
1836  */
1837 void prism2sta_ev_tx(struct wlandevice *wlandev, u16 status)
1838 {
1839         pr_debug("Tx Complete, status=0x%04x\n", status);
1840         /* update linux network stats */
1841         wlandev->netdev->stats.tx_packets++;
1842 }
1843
1844 /*
1845  * prism2sta_ev_alloc
1846  *
1847  * Handles the Alloc event.
1848  *
1849  * Arguments:
1850  *      wlandev         wlan device structure
1851  *
1852  * Returns:
1853  *      nothing
1854  *
1855  * Side effects:
1856  *
1857  * Call context:
1858  *      interrupt
1859  */
1860 void prism2sta_ev_alloc(struct wlandevice *wlandev)
1861 {
1862         netif_wake_queue(wlandev->netdev);
1863 }
1864
1865 /*
1866  * create_wlan
1867  *
1868  * Called at module init time.  This creates the struct wlandevice structure
1869  * and initializes it with relevant bits.
1870  *
1871  * Arguments:
1872  *      none
1873  *
1874  * Returns:
1875  *      the created struct wlandevice structure.
1876  *
1877  * Side effects:
1878  *      also allocates the priv/hw structures.
1879  *
1880  * Call context:
1881  *      process thread
1882  *
1883  */
1884 static struct wlandevice *create_wlan(void)
1885 {
1886         struct wlandevice *wlandev = NULL;
1887         struct hfa384x *hw = NULL;
1888
1889         /* Alloc our structures */
1890         wlandev = kzalloc(sizeof(*wlandev), GFP_KERNEL);
1891         hw = kzalloc(sizeof(*hw), GFP_KERNEL);
1892
1893         if (!wlandev || !hw) {
1894                 kfree(wlandev);
1895                 kfree(hw);
1896                 return NULL;
1897         }
1898
1899         /* Initialize the network device object. */
1900         wlandev->nsdname = dev_info;
1901         wlandev->msdstate = WLAN_MSD_HWPRESENT_PENDING;
1902         wlandev->priv = hw;
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;
1910
1911         wlandev->nsdcaps = P80211_NSDCAP_HWFRAGMENT | P80211_NSDCAP_AUTOJOIN;
1912
1913         /* Initialize the device private data structure. */
1914         hw->dot11_desired_bss_type = 1;
1915
1916         return wlandev;
1917 }
1918
1919 void prism2sta_commsqual_defer(struct work_struct *data)
1920 {
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;
1927         int result = 0;
1928
1929         if (hw->wlandev->hwremoved)
1930                 return;
1931
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)) {
1935                 return;
1936         }
1937
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);
1943
1944                 if (result) {
1945                         netdev_err(wlandev->netdev, "error fetching commsqual\n");
1946                         return;
1947                 }
1948
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));
1953         }
1954
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);
1959
1960         if (result) {
1961                 pr_debug("get signal rate failed, result = %d\n",
1962                          result);
1963                 return;
1964         }
1965
1966         switch (mibitem->data) {
1967         case HFA384x_RATEBIT_1:
1968                 hw->txrate = 10;
1969                 break;
1970         case HFA384x_RATEBIT_2:
1971                 hw->txrate = 20;
1972                 break;
1973         case HFA384x_RATEBIT_5dot5:
1974                 hw->txrate = 55;
1975                 break;
1976         case HFA384x_RATEBIT_11:
1977                 hw->txrate = 110;
1978                 break;
1979         default:
1980                 pr_debug("Bad ratebit (%d)\n", mibitem->data);
1981         }
1982
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);
1987         if (result) {
1988                 pr_debug("getconfig(0x%02x) failed, result = %d\n",
1989                          HFA384x_RID_CURRENTBSSID, result);
1990                 return;
1991         }
1992
1993         result = hfa384x_drvr_getconfig(hw,
1994                                         HFA384x_RID_CURRENTSSID,
1995                                         &ssid, sizeof(ssid));
1996         if (result) {
1997                 pr_debug("getconfig(0x%02x) failed, result = %d\n",
1998                          HFA384x_RID_CURRENTSSID, result);
1999                 return;
2000         }
2001         prism2mgmt_bytestr2pstr((struct hfa384x_bytestr *)&ssid,
2002                                 (struct p80211pstrd *)&wlandev->ssid);
2003
2004         /* Reschedule timer */
2005         mod_timer(&hw->commsqual_timer, jiffies + HZ);
2006 }
2007
2008 void prism2sta_commsqual_timer(struct timer_list *t)
2009 {
2010         struct hfa384x *hw = from_timer(hw, t, commsqual_timer);
2011
2012         schedule_work(&hw->commsqual_bh);
2013 }
This page took 0.156159 seconds and 4 git commands to generate.