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