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