1 /* src/prism2/driver/prism2mgmt.c
3 * Management request handler functions.
5 * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved.
6 * --------------------------------------------------------------------
10 * The contents of this file are subject to the Mozilla Public
11 * License Version 1.1 (the "License"); you may not use this file
12 * except in compliance with the License. You may obtain a copy of
13 * the License at http://www.mozilla.org/MPL/
15 * Software distributed under the License is distributed on an "AS
16 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
17 * implied. See the License for the specific language governing
18 * rights and limitations under the License.
20 * Alternatively, the contents of this file may be used under the
21 * terms of the GNU Public License version 2 (the "GPL"), in which
22 * case the provisions of the GPL are applicable instead of the
23 * above. If you wish to allow the use of your version of this file
24 * only under the terms of the GPL and not to allow others to use
25 * your version of this file under the MPL, indicate your decision
26 * by deleting the provisions above and replace them with the notice
27 * and other provisions required by the GPL. If you do not delete
28 * the provisions above, a recipient may use your version of this
29 * file under either the MPL or the GPL.
31 * --------------------------------------------------------------------
33 * Inquiries regarding the linux-wlan Open Source project can be
36 * AbsoluteValue Systems Inc.
38 * http://www.linux-wlan.com
40 * --------------------------------------------------------------------
42 * Portions of the development of this software were funded by
43 * Intersil Corporation as part of PRISM(R) chipset product development.
45 * --------------------------------------------------------------------
47 * The functions in this file handle management requests sent from
50 * Most of these functions have two separate blocks of code that are
51 * conditional on whether this is a station or an AP. This is used
52 * to separate out the STA and AP responses to these management primitives.
53 * It's a choice (good, bad, indifferent?) to have the code in the same
54 * place so it's clear that the same primitive is implemented in both
55 * cases but has different behavior.
57 * --------------------------------------------------------------------
60 #include <linux/if_arp.h>
61 #include <linux/module.h>
62 #include <linux/kernel.h>
63 #include <linux/wait.h>
64 #include <linux/sched.h>
65 #include <linux/types.h>
66 #include <linux/wireless.h>
67 #include <linux/netdevice.h>
68 #include <linux/delay.h>
70 #include <asm/byteorder.h>
71 #include <linux/random.h>
72 #include <linux/usb.h>
73 #include <linux/bitops.h>
75 #include "p80211types.h"
76 #include "p80211hdr.h"
77 #include "p80211mgmt.h"
78 #include "p80211conv.h"
79 #include "p80211msg.h"
80 #include "p80211netdev.h"
81 #include "p80211metadef.h"
82 #include "p80211metastruct.h"
84 #include "prism2mgmt.h"
86 /* Converts 802.11 format rate specifications to prism2 */
87 #define p80211rate_to_p2bit(n) ((((n)&~BIT(7)) == 2) ? BIT(0) : \
88 (((n)&~BIT(7)) == 4) ? BIT(1) : \
89 (((n)&~BIT(7)) == 11) ? BIT(2) : \
90 (((n)&~BIT(7)) == 22) ? BIT(3) : 0)
92 /*----------------------------------------------------------------
95 * Initiate a scan for BSSs.
97 * This function corresponds to MLME-scan.request and part of
98 * MLME-scan.confirm. As far as I can tell in the standard, there
99 * are no restrictions on when a scan.request may be issued. We have
100 * to handle in whatever state the driver/MAC happen to be.
103 * wlandev wlan device structure
104 * msgp ptr to msg buffer
108 * <0 success, but we're waiting for something to finish.
109 * >0 an error occurred while handling the message.
113 * process thread (usually)
115 ----------------------------------------------------------------*/
116 int prism2mgmt_scan(wlandevice_t
*wlandev
, void *msgp
)
119 hfa384x_t
*hw
= wlandev
->priv
;
120 struct p80211msg_dot11req_scan
*msg
= msgp
;
121 u16 roamingmode
, word
;
125 hfa384x_HostScanRequest_data_t scanreq
;
127 /* gatekeeper check */
128 if (HFA384x_FIRMWARE_VERSION(hw
->ident_sta_fw
.major
,
129 hw
->ident_sta_fw
.minor
,
130 hw
->ident_sta_fw
.variant
) <
131 HFA384x_FIRMWARE_VERSION(1, 3, 2)) {
133 "HostScan not supported with current firmware (<1.3.2).\n");
135 msg
->resultcode
.data
= P80211ENUM_resultcode_not_supported
;
139 memset(&scanreq
, 0, sizeof(scanreq
));
141 /* save current roaming mode */
142 result
= hfa384x_drvr_getconfig16(hw
,
143 HFA384x_RID_CNFROAMINGMODE
,
146 printk(KERN_ERR
"getconfig(ROAMMODE) failed. result=%d\n",
148 msg
->resultcode
.data
=
149 P80211ENUM_resultcode_implementation_failure
;
153 /* drop into mode 3 for the scan */
154 result
= hfa384x_drvr_setconfig16(hw
,
155 HFA384x_RID_CNFROAMINGMODE
,
156 HFA384x_ROAMMODE_HOSTSCAN_HOSTROAM
);
158 printk(KERN_ERR
"setconfig(ROAMINGMODE) failed. result=%d\n",
160 msg
->resultcode
.data
=
161 P80211ENUM_resultcode_implementation_failure
;
165 /* active or passive? */
166 if (HFA384x_FIRMWARE_VERSION(hw
->ident_sta_fw
.major
,
167 hw
->ident_sta_fw
.minor
,
168 hw
->ident_sta_fw
.variant
) >
169 HFA384x_FIRMWARE_VERSION(1, 5, 0)) {
170 if (msg
->scantype
.data
!= P80211ENUM_scantype_active
)
171 word
= cpu_to_le16(msg
->maxchanneltime
.data
);
176 hfa384x_drvr_setconfig16(hw
, HFA384x_RID_CNFPASSIVESCANCTRL
,
179 printk(KERN_WARNING
"Passive scan not supported with "
180 "current firmware. (<1.5.1)\n");
184 /* set up the txrate to be 2MBPS. Should be fastest basicrate... */
185 word
= HFA384x_RATEBIT_2
;
186 scanreq
.txRate
= cpu_to_le16(word
);
188 /* set up the channel list */
190 for (i
= 0; i
< msg
->channellist
.data
.len
; i
++) {
191 u8 channel
= msg
->channellist
.data
.data
[i
];
194 /* channel 1 is BIT 0 ... channel 14 is BIT 13 */
195 word
|= (1 << (channel
- 1));
197 scanreq
.channelList
= cpu_to_le16(word
);
199 /* set up the ssid, if present. */
200 scanreq
.ssid
.len
= cpu_to_le16(msg
->ssid
.data
.len
);
201 memcpy(scanreq
.ssid
.data
, msg
->ssid
.data
.data
, msg
->ssid
.data
.len
);
203 /* Enable the MAC port if it's not already enabled */
204 result
= hfa384x_drvr_getconfig16(hw
, HFA384x_RID_PORTSTATUS
, &word
);
206 printk(KERN_ERR
"getconfig(PORTSTATUS) failed. "
207 "result=%d\n", result
);
208 msg
->resultcode
.data
=
209 P80211ENUM_resultcode_implementation_failure
;
212 if (word
== HFA384x_PORTSTATUS_DISABLED
) {
215 result
= hfa384x_drvr_setconfig16(hw
,
216 HFA384x_RID_CNFROAMINGMODE
,
217 HFA384x_ROAMMODE_HOSTSCAN_HOSTROAM
);
220 "setconfig(ROAMINGMODE) failed. result=%d\n",
222 msg
->resultcode
.data
=
223 P80211ENUM_resultcode_implementation_failure
;
226 /* Construct a bogus SSID and assign it to OwnSSID and
229 wordbuf
[0] = cpu_to_le16(WLAN_SSID_MAXLEN
);
230 get_random_bytes(&wordbuf
[1], WLAN_SSID_MAXLEN
);
231 result
= hfa384x_drvr_setconfig(hw
, HFA384x_RID_CNFOWNSSID
,
233 HFA384x_RID_CNFOWNSSID_LEN
);
235 printk(KERN_ERR
"Failed to set OwnSSID.\n");
236 msg
->resultcode
.data
=
237 P80211ENUM_resultcode_implementation_failure
;
240 result
= hfa384x_drvr_setconfig(hw
, HFA384x_RID_CNFDESIREDSSID
,
242 HFA384x_RID_CNFDESIREDSSID_LEN
);
244 printk(KERN_ERR
"Failed to set DesiredSSID.\n");
245 msg
->resultcode
.data
=
246 P80211ENUM_resultcode_implementation_failure
;
250 result
= hfa384x_drvr_setconfig16(hw
,
251 HFA384x_RID_CNFPORTTYPE
,
252 HFA384x_PORTTYPE_IBSS
);
254 printk(KERN_ERR
"Failed to set CNFPORTTYPE.\n");
255 msg
->resultcode
.data
=
256 P80211ENUM_resultcode_implementation_failure
;
260 result
= hfa384x_drvr_setconfig16(hw
,
261 HFA384x_RID_CREATEIBSS
,
262 HFA384x_CREATEIBSS_JOINCREATEIBSS
);
264 printk(KERN_ERR
"Failed to set CREATEIBSS.\n");
265 msg
->resultcode
.data
=
266 P80211ENUM_resultcode_implementation_failure
;
269 result
= hfa384x_drvr_enable(hw
, 0);
271 printk(KERN_ERR
"drvr_enable(0) failed. "
272 "result=%d\n", result
);
273 msg
->resultcode
.data
=
274 P80211ENUM_resultcode_implementation_failure
;
280 /* Figure out our timeout first Kus, then HZ */
281 timeout
= msg
->channellist
.data
.len
* msg
->maxchanneltime
.data
;
282 timeout
= (timeout
* HZ
) / 1000;
284 /* Issue the scan request */
287 result
= hfa384x_drvr_setconfig(hw
,
288 HFA384x_RID_HOSTSCAN
, &scanreq
,
289 sizeof(hfa384x_HostScanRequest_data_t
));
291 printk(KERN_ERR
"setconfig(SCANREQUEST) failed. result=%d\n",
293 msg
->resultcode
.data
=
294 P80211ENUM_resultcode_implementation_failure
;
298 /* sleep until info frame arrives */
299 wait_event_interruptible_timeout(hw
->cmdq
, hw
->scanflag
, timeout
);
301 msg
->numbss
.status
= P80211ENUM_msgitem_status_data_ok
;
302 if (hw
->scanflag
== -1)
305 msg
->numbss
.data
= hw
->scanflag
;
309 /* Disable port if we temporarily enabled it. */
311 result
= hfa384x_drvr_disable(hw
, 0);
313 printk(KERN_ERR
"drvr_disable(0) failed. "
314 "result=%d\n", result
);
315 msg
->resultcode
.data
=
316 P80211ENUM_resultcode_implementation_failure
;
321 /* restore original roaming mode */
322 result
= hfa384x_drvr_setconfig16(hw
, HFA384x_RID_CNFROAMINGMODE
,
325 printk(KERN_ERR
"setconfig(ROAMMODE) failed. result=%d\n",
327 msg
->resultcode
.data
=
328 P80211ENUM_resultcode_implementation_failure
;
333 msg
->resultcode
.data
= P80211ENUM_resultcode_success
;
336 msg
->resultcode
.status
= P80211ENUM_msgitem_status_data_ok
;
341 /*----------------------------------------------------------------
342 * prism2mgmt_scan_results
344 * Retrieve the BSS description for one of the BSSs identified in
348 * wlandev wlan device structure
349 * msgp ptr to msg buffer
353 * <0 success, but we're waiting for something to finish.
354 * >0 an error occurred while handling the message.
358 * process thread (usually)
360 ----------------------------------------------------------------*/
361 int prism2mgmt_scan_results(wlandevice_t
*wlandev
, void *msgp
)
364 struct p80211msg_dot11req_scan_results
*req
;
365 hfa384x_t
*hw
= wlandev
->priv
;
366 hfa384x_HScanResultSub_t
*item
= NULL
;
370 req
= (struct p80211msg_dot11req_scan_results
*) msgp
;
372 req
->resultcode
.status
= P80211ENUM_msgitem_status_data_ok
;
374 if (!hw
->scanresults
) {
376 "dot11req_scan_results can only be used after a successful dot11req_scan.\n");
378 req
->resultcode
.data
= P80211ENUM_resultcode_invalid_parameters
;
382 count
= (hw
->scanresults
->framelen
- 3) / 32;
383 if (count
> HFA384x_SCANRESULT_MAX
)
384 count
= HFA384x_SCANRESULT_MAX
;
386 if (req
->bssindex
.data
>= count
) {
387 pr_debug("requested index (%d) out of range (%d)\n",
388 req
->bssindex
.data
, count
);
390 req
->resultcode
.data
= P80211ENUM_resultcode_invalid_parameters
;
394 item
= &(hw
->scanresults
->info
.hscanresult
.result
[req
->bssindex
.data
]);
395 /* signal and noise */
396 req
->signal
.status
= P80211ENUM_msgitem_status_data_ok
;
397 req
->noise
.status
= P80211ENUM_msgitem_status_data_ok
;
398 req
->signal
.data
= le16_to_cpu(item
->sl
);
399 req
->noise
.data
= le16_to_cpu(item
->anl
);
402 req
->bssid
.status
= P80211ENUM_msgitem_status_data_ok
;
403 req
->bssid
.data
.len
= WLAN_BSSID_LEN
;
404 memcpy(req
->bssid
.data
.data
, item
->bssid
, WLAN_BSSID_LEN
);
407 req
->ssid
.status
= P80211ENUM_msgitem_status_data_ok
;
408 req
->ssid
.data
.len
= le16_to_cpu(item
->ssid
.len
);
409 req
->ssid
.data
.len
= min_t(u16
, req
->ssid
.data
.len
, WLAN_BSSID_LEN
);
410 memcpy(req
->ssid
.data
.data
, item
->ssid
.data
, req
->ssid
.data
.len
);
412 /* supported rates */
413 for (count
= 0; count
< 10; count
++)
414 if (item
->supprates
[count
] == 0)
417 #define REQBASICRATE(N) \
418 if ((count >= N) && DOT11_RATE5_ISBASIC_GET(item->supprates[(N)-1])) { \
419 req->basicrate ## N .data = item->supprates[(N)-1]; \
420 req->basicrate ## N .status = \
421 P80211ENUM_msgitem_status_data_ok; \
433 #define REQSUPPRATE(N) \
435 req->supprate ## N .data = item->supprates[(N)-1]; \
436 req->supprate ## N .status = \
437 P80211ENUM_msgitem_status_data_ok; \
450 req
->beaconperiod
.status
= P80211ENUM_msgitem_status_data_ok
;
451 req
->beaconperiod
.data
= le16_to_cpu(item
->bcnint
);
454 req
->timestamp
.status
= P80211ENUM_msgitem_status_data_ok
;
455 req
->timestamp
.data
= jiffies
;
456 req
->localtime
.status
= P80211ENUM_msgitem_status_data_ok
;
457 req
->localtime
.data
= jiffies
;
460 req
->ibssatimwindow
.status
= P80211ENUM_msgitem_status_data_ok
;
461 req
->ibssatimwindow
.data
= le16_to_cpu(item
->atim
);
464 req
->dschannel
.status
= P80211ENUM_msgitem_status_data_ok
;
465 req
->dschannel
.data
= le16_to_cpu(item
->chid
);
468 count
= le16_to_cpu(item
->capinfo
);
469 req
->capinfo
.status
= P80211ENUM_msgitem_status_data_ok
;
470 req
->capinfo
.data
= count
;
473 req
->privacy
.status
= P80211ENUM_msgitem_status_data_ok
;
474 req
->privacy
.data
= WLAN_GET_MGMT_CAP_INFO_PRIVACY(count
);
477 req
->cfpollable
.status
= P80211ENUM_msgitem_status_data_ok
;
478 req
->cfpollable
.data
= WLAN_GET_MGMT_CAP_INFO_CFPOLLABLE(count
);
481 req
->cfpollreq
.status
= P80211ENUM_msgitem_status_data_ok
;
482 req
->cfpollreq
.data
= WLAN_GET_MGMT_CAP_INFO_CFPOLLREQ(count
);
485 req
->bsstype
.status
= P80211ENUM_msgitem_status_data_ok
;
486 req
->bsstype
.data
= (WLAN_GET_MGMT_CAP_INFO_ESS(count
)) ?
487 P80211ENUM_bsstype_infrastructure
: P80211ENUM_bsstype_independent
;
490 req
->resultcode
.data
= P80211ENUM_resultcode_success
;
496 /*----------------------------------------------------------------
499 * Start a BSS. Any station can do this for IBSS, only AP for ESS.
502 * wlandev wlan device structure
503 * msgp ptr to msg buffer
507 * <0 success, but we're waiting for something to finish.
508 * >0 an error occurred while handling the message.
512 * process thread (usually)
514 ----------------------------------------------------------------*/
515 int prism2mgmt_start(wlandevice_t
*wlandev
, void *msgp
)
518 hfa384x_t
*hw
= wlandev
->priv
;
519 struct p80211msg_dot11req_start
*msg
= msgp
;
523 hfa384x_bytestr_t
*p2bytestr
= (hfa384x_bytestr_t
*) bytebuf
;
526 wlandev
->macmode
= WLAN_MACMODE_NONE
;
529 memcpy(&wlandev
->ssid
, &msg
->ssid
.data
, sizeof(msg
->ssid
.data
));
532 /* see if current f/w is less than 8c3 */
533 if (HFA384x_FIRMWARE_VERSION(hw
->ident_sta_fw
.major
,
534 hw
->ident_sta_fw
.minor
,
535 hw
->ident_sta_fw
.variant
) <
536 HFA384x_FIRMWARE_VERSION(0, 8, 3)) {
537 /* Ad-Hoc not quite supported on Prism2 */
538 msg
->resultcode
.status
= P80211ENUM_msgitem_status_data_ok
;
539 msg
->resultcode
.data
= P80211ENUM_resultcode_not_supported
;
543 msg
->resultcode
.status
= P80211ENUM_msgitem_status_data_ok
;
546 /* Set the REQUIRED config items */
548 pstr
= (p80211pstrd_t
*) &(msg
->ssid
.data
);
549 prism2mgmt_pstr2bytestr(p2bytestr
, pstr
);
550 result
= hfa384x_drvr_setconfig(hw
, HFA384x_RID_CNFOWNSSID
,
551 bytebuf
, HFA384x_RID_CNFOWNSSID_LEN
);
553 printk(KERN_ERR
"Failed to set CnfOwnSSID\n");
556 result
= hfa384x_drvr_setconfig(hw
, HFA384x_RID_CNFDESIREDSSID
,
558 HFA384x_RID_CNFDESIREDSSID_LEN
);
560 printk(KERN_ERR
"Failed to set CnfDesiredSSID\n");
564 /* bsstype - we use the default in the ap firmware */
566 hfa384x_drvr_setconfig16(hw
, HFA384x_RID_CNFPORTTYPE
, 0);
569 word
= msg
->beaconperiod
.data
;
570 result
= hfa384x_drvr_setconfig16(hw
, HFA384x_RID_CNFAPBCNint
, word
);
572 printk(KERN_ERR
"Failed to set beacon period=%d.\n", word
);
577 word
= msg
->dschannel
.data
;
578 result
= hfa384x_drvr_setconfig16(hw
, HFA384x_RID_CNFOWNCHANNEL
, word
);
580 printk(KERN_ERR
"Failed to set channel=%d.\n", word
);
584 word
= p80211rate_to_p2bit(msg
->basicrate1
.data
);
585 if (msg
->basicrate2
.status
== P80211ENUM_msgitem_status_data_ok
)
586 word
|= p80211rate_to_p2bit(msg
->basicrate2
.data
);
588 if (msg
->basicrate3
.status
== P80211ENUM_msgitem_status_data_ok
)
589 word
|= p80211rate_to_p2bit(msg
->basicrate3
.data
);
591 if (msg
->basicrate4
.status
== P80211ENUM_msgitem_status_data_ok
)
592 word
|= p80211rate_to_p2bit(msg
->basicrate4
.data
);
594 if (msg
->basicrate5
.status
== P80211ENUM_msgitem_status_data_ok
)
595 word
|= p80211rate_to_p2bit(msg
->basicrate5
.data
);
597 if (msg
->basicrate6
.status
== P80211ENUM_msgitem_status_data_ok
)
598 word
|= p80211rate_to_p2bit(msg
->basicrate6
.data
);
600 if (msg
->basicrate7
.status
== P80211ENUM_msgitem_status_data_ok
)
601 word
|= p80211rate_to_p2bit(msg
->basicrate7
.data
);
603 if (msg
->basicrate8
.status
== P80211ENUM_msgitem_status_data_ok
)
604 word
|= p80211rate_to_p2bit(msg
->basicrate8
.data
);
606 result
= hfa384x_drvr_setconfig16(hw
, HFA384x_RID_CNFBASICRATES
, word
);
608 printk(KERN_ERR
"Failed to set basicrates=%d.\n", word
);
612 /* Operational rates (supprates and txratecontrol) */
613 word
= p80211rate_to_p2bit(msg
->operationalrate1
.data
);
614 if (msg
->operationalrate2
.status
== P80211ENUM_msgitem_status_data_ok
)
615 word
|= p80211rate_to_p2bit(msg
->operationalrate2
.data
);
617 if (msg
->operationalrate3
.status
== P80211ENUM_msgitem_status_data_ok
)
618 word
|= p80211rate_to_p2bit(msg
->operationalrate3
.data
);
620 if (msg
->operationalrate4
.status
== P80211ENUM_msgitem_status_data_ok
)
621 word
|= p80211rate_to_p2bit(msg
->operationalrate4
.data
);
623 if (msg
->operationalrate5
.status
== P80211ENUM_msgitem_status_data_ok
)
624 word
|= p80211rate_to_p2bit(msg
->operationalrate5
.data
);
626 if (msg
->operationalrate6
.status
== P80211ENUM_msgitem_status_data_ok
)
627 word
|= p80211rate_to_p2bit(msg
->operationalrate6
.data
);
629 if (msg
->operationalrate7
.status
== P80211ENUM_msgitem_status_data_ok
)
630 word
|= p80211rate_to_p2bit(msg
->operationalrate7
.data
);
632 if (msg
->operationalrate8
.status
== P80211ENUM_msgitem_status_data_ok
)
633 word
|= p80211rate_to_p2bit(msg
->operationalrate8
.data
);
635 result
= hfa384x_drvr_setconfig16(hw
, HFA384x_RID_CNFSUPPRATES
, word
);
637 printk(KERN_ERR
"Failed to set supprates=%d.\n", word
);
641 result
= hfa384x_drvr_setconfig16(hw
, HFA384x_RID_TXRATECNTL
, word
);
643 printk(KERN_ERR
"Failed to set txrates=%d.\n", word
);
647 /* Set the macmode so the frame setup code knows what to do */
648 if (msg
->bsstype
.data
== P80211ENUM_bsstype_independent
) {
649 wlandev
->macmode
= WLAN_MACMODE_IBSS_STA
;
650 /* lets extend the data length a bit */
651 hfa384x_drvr_setconfig16(hw
, HFA384x_RID_CNFMAXDATALEN
, 2304);
654 /* Enable the Port */
655 result
= hfa384x_drvr_enable(hw
, 0);
657 printk(KERN_ERR
"Enable macport failed, result=%d.\n", result
);
661 msg
->resultcode
.data
= P80211ENUM_resultcode_success
;
665 pr_debug("Failed to set a config option, result=%d\n", result
);
666 msg
->resultcode
.data
= P80211ENUM_resultcode_invalid_parameters
;
674 /*----------------------------------------------------------------
677 * Collect the PDA data and put it in the message.
680 * wlandev wlan device structure
681 * msgp ptr to msg buffer
685 * <0 success, but we're waiting for something to finish.
686 * >0 an error occurred while handling the message.
690 * process thread (usually)
691 ----------------------------------------------------------------*/
692 int prism2mgmt_readpda(wlandevice_t
*wlandev
, void *msgp
)
694 hfa384x_t
*hw
= wlandev
->priv
;
695 struct p80211msg_p2req_readpda
*msg
= msgp
;
698 /* We only support collecting the PDA when in the FWLOAD
701 if (wlandev
->msdstate
!= WLAN_MSD_FWLOAD
) {
703 "PDA may only be read " "in the fwload state.\n");
704 msg
->resultcode
.data
=
705 P80211ENUM_resultcode_implementation_failure
;
706 msg
->resultcode
.status
= P80211ENUM_msgitem_status_data_ok
;
708 /* Call drvr_readpda(), it handles the auxport enable
709 * and validating the returned PDA.
711 result
= hfa384x_drvr_readpda(hw
,
713 HFA384x_PDA_LEN_MAX
);
716 "hfa384x_drvr_readpda() failed, "
717 "result=%d\n", result
);
719 msg
->resultcode
.data
=
720 P80211ENUM_resultcode_implementation_failure
;
721 msg
->resultcode
.status
=
722 P80211ENUM_msgitem_status_data_ok
;
725 msg
->pda
.status
= P80211ENUM_msgitem_status_data_ok
;
726 msg
->resultcode
.data
= P80211ENUM_resultcode_success
;
727 msg
->resultcode
.status
= P80211ENUM_msgitem_status_data_ok
;
733 /*----------------------------------------------------------------
734 * prism2mgmt_ramdl_state
736 * Establishes the beginning/end of a card RAM download session.
738 * It is expected that the ramdl_write() function will be called
739 * one or more times between the 'enable' and 'disable' calls to
742 * Note: This function should not be called when a mac comm port
746 * wlandev wlan device structure
747 * msgp ptr to msg buffer
751 * <0 success, but we're waiting for something to finish.
752 * >0 an error occurred while handling the message.
756 * process thread (usually)
757 ----------------------------------------------------------------*/
758 int prism2mgmt_ramdl_state(wlandevice_t
*wlandev
, void *msgp
)
760 hfa384x_t
*hw
= wlandev
->priv
;
761 struct p80211msg_p2req_ramdl_state
*msg
= msgp
;
763 if (wlandev
->msdstate
!= WLAN_MSD_FWLOAD
) {
765 "ramdl_state(): may only be called "
766 "in the fwload state.\n");
767 msg
->resultcode
.data
=
768 P80211ENUM_resultcode_implementation_failure
;
769 msg
->resultcode
.status
= P80211ENUM_msgitem_status_data_ok
;
774 ** Note: Interrupts are locked out if this is an AP and are NOT
775 ** locked out if this is a station.
778 msg
->resultcode
.status
= P80211ENUM_msgitem_status_data_ok
;
779 if (msg
->enable
.data
== P80211ENUM_truth_true
) {
780 if (hfa384x_drvr_ramdl_enable(hw
, msg
->exeaddr
.data
)) {
781 msg
->resultcode
.data
=
782 P80211ENUM_resultcode_implementation_failure
;
784 msg
->resultcode
.data
= P80211ENUM_resultcode_success
;
787 hfa384x_drvr_ramdl_disable(hw
);
788 msg
->resultcode
.data
= P80211ENUM_resultcode_success
;
794 /*----------------------------------------------------------------
795 * prism2mgmt_ramdl_write
797 * Writes a buffer to the card RAM using the download state. This
798 * is for writing code to card RAM. To just read or write raw data
799 * use the aux functions.
802 * wlandev wlan device structure
803 * msgp ptr to msg buffer
807 * <0 success, but we're waiting for something to finish.
808 * >0 an error occurred while handling the message.
812 * process thread (usually)
813 ----------------------------------------------------------------*/
814 int prism2mgmt_ramdl_write(wlandevice_t
*wlandev
, void *msgp
)
816 hfa384x_t
*hw
= wlandev
->priv
;
817 struct p80211msg_p2req_ramdl_write
*msg
= msgp
;
822 if (wlandev
->msdstate
!= WLAN_MSD_FWLOAD
) {
824 "ramdl_write(): may only be called "
825 "in the fwload state.\n");
826 msg
->resultcode
.data
=
827 P80211ENUM_resultcode_implementation_failure
;
828 msg
->resultcode
.status
= P80211ENUM_msgitem_status_data_ok
;
832 msg
->resultcode
.status
= P80211ENUM_msgitem_status_data_ok
;
833 /* first validate the length */
834 if (msg
->len
.data
> sizeof(msg
->data
.data
)) {
835 msg
->resultcode
.status
=
836 P80211ENUM_resultcode_invalid_parameters
;
839 /* call the hfa384x function to do the write */
840 addr
= msg
->addr
.data
;
842 buf
= msg
->data
.data
;
843 if (hfa384x_drvr_ramdl_write(hw
, addr
, buf
, len
))
844 msg
->resultcode
.data
= P80211ENUM_resultcode_refused
;
846 msg
->resultcode
.data
= P80211ENUM_resultcode_success
;
851 /*----------------------------------------------------------------
852 * prism2mgmt_flashdl_state
854 * Establishes the beginning/end of a card Flash download session.
856 * It is expected that the flashdl_write() function will be called
857 * one or more times between the 'enable' and 'disable' calls to
860 * Note: This function should not be called when a mac comm port
864 * wlandev wlan device structure
865 * msgp ptr to msg buffer
869 * <0 success, but we're waiting for something to finish.
870 * >0 an error occurred while handling the message.
874 * process thread (usually)
875 ----------------------------------------------------------------*/
876 int prism2mgmt_flashdl_state(wlandevice_t
*wlandev
, void *msgp
)
879 hfa384x_t
*hw
= wlandev
->priv
;
880 struct p80211msg_p2req_flashdl_state
*msg
= msgp
;
882 if (wlandev
->msdstate
!= WLAN_MSD_FWLOAD
) {
884 "flashdl_state(): may only be called "
885 "in the fwload state.\n");
886 msg
->resultcode
.data
=
887 P80211ENUM_resultcode_implementation_failure
;
888 msg
->resultcode
.status
= P80211ENUM_msgitem_status_data_ok
;
893 ** Note: Interrupts are locked out if this is an AP and are NOT
894 ** locked out if this is a station.
897 msg
->resultcode
.status
= P80211ENUM_msgitem_status_data_ok
;
898 if (msg
->enable
.data
== P80211ENUM_truth_true
) {
899 if (hfa384x_drvr_flashdl_enable(hw
)) {
900 msg
->resultcode
.data
=
901 P80211ENUM_resultcode_implementation_failure
;
903 msg
->resultcode
.data
= P80211ENUM_resultcode_success
;
906 hfa384x_drvr_flashdl_disable(hw
);
907 msg
->resultcode
.data
= P80211ENUM_resultcode_success
;
908 /* NOTE: At this point, the MAC is in the post-reset
909 * state and the driver is in the fwload state.
910 * We need to get the MAC back into the fwload
911 * state. To do this, we set the nsdstate to HWPRESENT
912 * and then call the ifstate function to redo everything
913 * that got us into the fwload state.
915 wlandev
->msdstate
= WLAN_MSD_HWPRESENT
;
916 result
= prism2sta_ifstate(wlandev
, P80211ENUM_ifstate_fwload
);
917 if (result
!= P80211ENUM_resultcode_success
) {
918 printk(KERN_ERR
"prism2sta_ifstate(fwload) failed,"
919 "P80211ENUM_resultcode=%d\n", result
);
920 msg
->resultcode
.data
=
921 P80211ENUM_resultcode_implementation_failure
;
929 /*----------------------------------------------------------------
930 * prism2mgmt_flashdl_write
935 * wlandev wlan device structure
936 * msgp ptr to msg buffer
940 * <0 success, but we're waiting for something to finish.
941 * >0 an error occurred while handling the message.
945 * process thread (usually)
946 ----------------------------------------------------------------*/
947 int prism2mgmt_flashdl_write(wlandevice_t
*wlandev
, void *msgp
)
949 hfa384x_t
*hw
= wlandev
->priv
;
950 struct p80211msg_p2req_flashdl_write
*msg
= msgp
;
955 if (wlandev
->msdstate
!= WLAN_MSD_FWLOAD
) {
957 "flashdl_write(): may only be called "
958 "in the fwload state.\n");
959 msg
->resultcode
.data
=
960 P80211ENUM_resultcode_implementation_failure
;
961 msg
->resultcode
.status
= P80211ENUM_msgitem_status_data_ok
;
966 ** Note: Interrupts are locked out if this is an AP and are NOT
967 ** locked out if this is a station.
970 msg
->resultcode
.status
= P80211ENUM_msgitem_status_data_ok
;
971 /* first validate the length */
972 if (msg
->len
.data
> sizeof(msg
->data
.data
)) {
973 msg
->resultcode
.status
=
974 P80211ENUM_resultcode_invalid_parameters
;
977 /* call the hfa384x function to do the write */
978 addr
= msg
->addr
.data
;
980 buf
= msg
->data
.data
;
981 if (hfa384x_drvr_flashdl_write(hw
, addr
, buf
, len
))
982 msg
->resultcode
.data
= P80211ENUM_resultcode_refused
;
984 msg
->resultcode
.data
= P80211ENUM_resultcode_success
;
989 /*----------------------------------------------------------------
990 * prism2mgmt_autojoin
992 * Associate with an ESS.
995 * wlandev wlan device structure
996 * msgp ptr to msg buffer
1000 * <0 success, but we're waiting for something to finish.
1001 * >0 an error occurred while handling the message.
1005 * process thread (usually)
1007 ----------------------------------------------------------------*/
1008 int prism2mgmt_autojoin(wlandevice_t
*wlandev
, void *msgp
)
1010 hfa384x_t
*hw
= wlandev
->priv
;
1014 struct p80211msg_lnxreq_autojoin
*msg
= msgp
;
1015 p80211pstrd_t
*pstr
;
1017 hfa384x_bytestr_t
*p2bytestr
= (hfa384x_bytestr_t
*) bytebuf
;
1019 wlandev
->macmode
= WLAN_MACMODE_NONE
;
1022 memcpy(&wlandev
->ssid
, &msg
->ssid
.data
, sizeof(msg
->ssid
.data
));
1024 /* Disable the Port */
1025 hfa384x_drvr_disable(hw
, 0);
1028 /* Set the TxRates */
1029 hfa384x_drvr_setconfig16(hw
, HFA384x_RID_TXRATECNTL
, 0x000f);
1031 /* Set the auth type */
1032 if (msg
->authtype
.data
== P80211ENUM_authalg_sharedkey
)
1033 reg
= HFA384x_CNFAUTHENTICATION_SHAREDKEY
;
1035 reg
= HFA384x_CNFAUTHENTICATION_OPENSYSTEM
;
1037 hfa384x_drvr_setconfig16(hw
, HFA384x_RID_CNFAUTHENTICATION
, reg
);
1040 memset(bytebuf
, 0, 256);
1041 pstr
= (p80211pstrd_t
*) &(msg
->ssid
.data
);
1042 prism2mgmt_pstr2bytestr(p2bytestr
, pstr
);
1043 result
= hfa384x_drvr_setconfig(hw
, HFA384x_RID_CNFDESIREDSSID
,
1045 HFA384x_RID_CNFDESIREDSSID_LEN
);
1046 port_type
= HFA384x_PORTTYPE_BSS
;
1047 /* Set the PortType */
1048 hfa384x_drvr_setconfig16(hw
, HFA384x_RID_CNFPORTTYPE
, port_type
);
1050 /* Enable the Port */
1051 hfa384x_drvr_enable(hw
, 0);
1053 /* Set the resultcode */
1054 msg
->resultcode
.status
= P80211ENUM_msgitem_status_data_ok
;
1055 msg
->resultcode
.data
= P80211ENUM_resultcode_success
;
1060 /*----------------------------------------------------------------
1061 * prism2mgmt_wlansniff
1063 * Start or stop sniffing.
1066 * wlandev wlan device structure
1067 * msgp ptr to msg buffer
1070 * 0 success and done
1071 * <0 success, but we're waiting for something to finish.
1072 * >0 an error occurred while handling the message.
1076 * process thread (usually)
1078 ----------------------------------------------------------------*/
1079 int prism2mgmt_wlansniff(wlandevice_t
*wlandev
, void *msgp
)
1082 struct p80211msg_lnxreq_wlansniff
*msg
= msgp
;
1084 hfa384x_t
*hw
= wlandev
->priv
;
1087 msg
->resultcode
.status
= P80211ENUM_msgitem_status_data_ok
;
1088 switch (msg
->enable
.data
) {
1089 case P80211ENUM_truth_false
:
1090 /* Confirm that we're in monitor mode */
1091 if (wlandev
->netdev
->type
== ARPHRD_ETHER
) {
1092 msg
->resultcode
.data
=
1093 P80211ENUM_resultcode_invalid_parameters
;
1097 /* Disable monitor mode */
1098 result
= hfa384x_cmd_monitor(hw
, HFA384x_MONITOR_DISABLE
);
1100 pr_debug("failed to disable monitor mode, result=%d\n",
1104 /* Disable port 0 */
1105 result
= hfa384x_drvr_disable(hw
, 0);
1108 ("failed to disable port 0 after sniffing, result=%d\n",
1112 /* Clear the driver state */
1113 wlandev
->netdev
->type
= ARPHRD_ETHER
;
1115 /* Restore the wepflags */
1116 result
= hfa384x_drvr_setconfig16(hw
,
1117 HFA384x_RID_CNFWEPFLAGS
,
1118 hw
->presniff_wepflags
);
1121 ("failed to restore wepflags=0x%04x, result=%d\n",
1122 hw
->presniff_wepflags
, result
);
1126 /* Set the port to its prior type and enable (if necessary) */
1127 if (hw
->presniff_port_type
!= 0) {
1128 word
= hw
->presniff_port_type
;
1129 result
= hfa384x_drvr_setconfig16(hw
,
1130 HFA384x_RID_CNFPORTTYPE
,
1134 ("failed to restore porttype, result=%d\n",
1139 /* Enable the port */
1140 result
= hfa384x_drvr_enable(hw
, 0);
1143 ("failed to enable port to presniff setting, result=%d\n",
1148 result
= hfa384x_drvr_disable(hw
, 0);
1152 printk(KERN_INFO
"monitor mode disabled\n");
1153 msg
->resultcode
.data
= P80211ENUM_resultcode_success
;
1157 case P80211ENUM_truth_true
:
1158 /* Disable the port (if enabled), only check Port 0 */
1159 if (hw
->port_enabled
[0]) {
1160 if (wlandev
->netdev
->type
== ARPHRD_ETHER
) {
1161 /* Save macport 0 state */
1162 result
= hfa384x_drvr_getconfig16(hw
,
1163 HFA384x_RID_CNFPORTTYPE
,
1164 &(hw
->presniff_port_type
));
1167 ("failed to read porttype, result=%d\n",
1171 /* Save the wepflags state */
1172 result
= hfa384x_drvr_getconfig16(hw
,
1173 HFA384x_RID_CNFWEPFLAGS
,
1174 &(hw
->presniff_wepflags
));
1177 ("failed to read wepflags, result=%d\n",
1181 hfa384x_drvr_stop(hw
);
1182 result
= hfa384x_drvr_start(hw
);
1185 ("failed to restart the card for sniffing, result=%d\n",
1190 /* Disable the port */
1191 result
= hfa384x_drvr_disable(hw
, 0);
1194 ("failed to enable port for sniffing, result=%d\n",
1200 hw
->presniff_port_type
= 0;
1203 /* Set the channel we wish to sniff */
1204 word
= msg
->channel
.data
;
1205 result
= hfa384x_drvr_setconfig16(hw
,
1206 HFA384x_RID_CNFOWNCHANNEL
,
1208 hw
->sniff_channel
= word
;
1211 pr_debug("failed to set channel %d, result=%d\n",
1216 /* Now if we're already sniffing, we can skip the rest */
1217 if (wlandev
->netdev
->type
!= ARPHRD_ETHER
) {
1218 /* Set the port type to pIbss */
1219 word
= HFA384x_PORTTYPE_PSUEDOIBSS
;
1220 result
= hfa384x_drvr_setconfig16(hw
,
1221 HFA384x_RID_CNFPORTTYPE
,
1225 ("failed to set porttype %d, result=%d\n",
1229 if ((msg
->keepwepflags
.status
==
1230 P80211ENUM_msgitem_status_data_ok
)
1231 && (msg
->keepwepflags
.data
!=
1232 P80211ENUM_truth_true
)) {
1233 /* Set the wepflags for no decryption */
1234 word
= HFA384x_WEPFLAGS_DISABLE_TXCRYPT
|
1235 HFA384x_WEPFLAGS_DISABLE_RXCRYPT
;
1237 hfa384x_drvr_setconfig16(hw
,
1238 HFA384x_RID_CNFWEPFLAGS
,
1244 ("failed to set wepflags=0x%04x, result=%d\n",
1250 /* Do we want to strip the FCS in monitor mode? */
1251 if ((msg
->stripfcs
.status
== P80211ENUM_msgitem_status_data_ok
)
1252 && (msg
->stripfcs
.data
== P80211ENUM_truth_true
)) {
1258 /* Do we want to truncate the packets? */
1259 if (msg
->packet_trunc
.status
==
1260 P80211ENUM_msgitem_status_data_ok
) {
1261 hw
->sniff_truncate
= msg
->packet_trunc
.data
;
1263 hw
->sniff_truncate
= 0;
1266 /* Enable the port */
1267 result
= hfa384x_drvr_enable(hw
, 0);
1270 ("failed to enable port for sniffing, result=%d\n",
1274 /* Enable monitor mode */
1275 result
= hfa384x_cmd_monitor(hw
, HFA384x_MONITOR_ENABLE
);
1277 pr_debug("failed to enable monitor mode, result=%d\n",
1282 if (wlandev
->netdev
->type
== ARPHRD_ETHER
)
1283 printk(KERN_INFO
"monitor mode enabled\n");
1285 /* Set the driver state */
1286 /* Do we want the prism2 header? */
1287 if ((msg
->prismheader
.status
==
1288 P80211ENUM_msgitem_status_data_ok
)
1289 && (msg
->prismheader
.data
== P80211ENUM_truth_true
)) {
1291 wlandev
->netdev
->type
= ARPHRD_IEEE80211_PRISM
;
1293 if ((msg
->wlanheader
.status
==
1294 P80211ENUM_msgitem_status_data_ok
)
1295 && (msg
->wlanheader
.data
== P80211ENUM_truth_true
)) {
1297 wlandev
->netdev
->type
= ARPHRD_IEEE80211_PRISM
;
1299 wlandev
->netdev
->type
= ARPHRD_IEEE80211
;
1302 msg
->resultcode
.data
= P80211ENUM_resultcode_success
;
1307 msg
->resultcode
.data
= P80211ENUM_resultcode_invalid_parameters
;
1314 msg
->resultcode
.data
= P80211ENUM_resultcode_refused
;