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