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 /*================================================================*/
63 #include <linux/if_arp.h>
64 #include <linux/module.h>
65 #include <linux/kernel.h>
66 #include <linux/wait.h>
67 #include <linux/sched.h>
68 #include <linux/types.h>
69 #include <linux/slab.h>
70 #include <linux/wireless.h>
71 #include <linux/netdevice.h>
72 #include <linux/delay.h>
74 #include <asm/byteorder.h>
75 #include <linux/random.h>
76 #include <linux/usb.h>
77 #include <linux/bitops.h>
79 #include "wlan_compat.h"
81 /*================================================================*/
82 /* Project Includes */
84 #include "p80211types.h"
85 #include "p80211hdr.h"
86 #include "p80211mgmt.h"
87 #include "p80211conv.h"
88 #include "p80211msg.h"
89 #include "p80211netdev.h"
90 #include "p80211metadef.h"
91 #include "p80211metastruct.h"
93 #include "prism2mgmt.h"
95 /* Converts 802.11 format rate specifications to prism2 */
96 #define p80211rate_to_p2bit(n) ((((n)&~BIT(7)) == 2) ? BIT(0) : \
97 (((n)&~BIT(7)) == 4) ? BIT(1) : \
98 (((n)&~BIT(7)) == 11) ? BIT(2) : \
99 (((n)&~BIT(7)) == 22) ? BIT(3) : 0)
101 /*----------------------------------------------------------------
104 * Initiate a scan for BSSs.
106 * This function corresponds to MLME-scan.request and part of
107 * MLME-scan.confirm. As far as I can tell in the standard, there
108 * are no restrictions on when a scan.request may be issued. We have
109 * to handle in whatever state the driver/MAC happen to be.
112 * wlandev wlan device structure
113 * msgp ptr to msg buffer
117 * <0 success, but we're waiting for something to finish.
118 * >0 an error occurred while handling the message.
122 * process thread (usually)
124 ----------------------------------------------------------------*/
125 int prism2mgmt_scan(wlandevice_t *wlandev, void *msgp)
128 hfa384x_t *hw = wlandev->priv;
129 p80211msg_dot11req_scan_t *msg = msgp;
130 u16 roamingmode, word;
134 hfa384x_HostScanRequest_data_t scanreq;
136 /* gatekeeper check */
137 if (HFA384x_FIRMWARE_VERSION(hw->ident_sta_fw.major,
138 hw->ident_sta_fw.minor,
139 hw->ident_sta_fw.variant) <
140 HFA384x_FIRMWARE_VERSION(1,3,2)) {
141 printk(KERN_ERR "HostScan not supported with current firmware (<1.3.2).\n");
143 msg->resultcode.data = P80211ENUM_resultcode_not_supported;
147 memset(&scanreq, 0, sizeof(scanreq));
149 /* save current roaming mode */
150 result = hfa384x_drvr_getconfig16(hw,
151 HFA384x_RID_CNFROAMINGMODE, &roamingmode);
153 printk(KERN_ERR "getconfig(ROAMMODE) failed. result=%d\n",
155 msg->resultcode.data =
156 P80211ENUM_resultcode_implementation_failure;
160 /* drop into mode 3 for the scan */
161 result = hfa384x_drvr_setconfig16(hw,
162 HFA384x_RID_CNFROAMINGMODE,
163 HFA384x_ROAMMODE_HOSTSCAN_HOSTROAM);
165 printk(KERN_ERR "setconfig(ROAMINGMODE) failed. result=%d\n",
167 msg->resultcode.data =
168 P80211ENUM_resultcode_implementation_failure;
172 /* active or passive? */
173 if (HFA384x_FIRMWARE_VERSION(hw->ident_sta_fw.major,
174 hw->ident_sta_fw.minor,
175 hw->ident_sta_fw.variant) >
176 HFA384x_FIRMWARE_VERSION(1,5,0)) {
177 if (msg->scantype.data != P80211ENUM_scantype_active) {
178 word = host2hfa384x_16(msg->maxchanneltime.data);
182 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFPASSIVESCANCTRL, word);
184 printk(KERN_WARNING "Passive scan not supported with "
185 "current firmware. (<1.5.1)\n");
189 /* set up the txrate to be 2MBPS. Should be fastest basicrate... */
190 word = HFA384x_RATEBIT_2;
191 scanreq.txRate = host2hfa384x_16(word);
193 /* set up the channel list */
195 for (i = 0; i < msg->channellist.data.len; i++) {
196 u8 channel = msg->channellist.data.data[i];
197 if (channel > 14) continue;
198 /* channel 1 is BIT 0 ... channel 14 is BIT 13 */
199 word |= (1 << (channel-1));
201 scanreq.channelList = host2hfa384x_16(word);
203 /* set up the ssid, if present. */
204 scanreq.ssid.len = host2hfa384x_16(msg->ssid.data.len);
205 memcpy(scanreq.ssid.data, msg->ssid.data.data, msg->ssid.data.len);
207 /* Enable the MAC port if it's not already enabled */
208 result = hfa384x_drvr_getconfig16(hw, HFA384x_RID_PORTSTATUS, &word);
210 printk(KERN_ERR "getconfig(PORTSTATUS) failed. "
211 "result=%d\n", result);
212 msg->resultcode.data =
213 P80211ENUM_resultcode_implementation_failure;
216 if (word == HFA384x_PORTSTATUS_DISABLED) {
219 result = hfa384x_drvr_setconfig16(hw,
220 HFA384x_RID_CNFROAMINGMODE,
221 HFA384x_ROAMMODE_HOSTSCAN_HOSTROAM);
223 printk(KERN_ERR "setconfig(ROAMINGMODE) failed. result=%d\n", result);
224 msg->resultcode.data =
225 P80211ENUM_resultcode_implementation_failure;
228 /* Construct a bogus SSID and assign it to OwnSSID and
231 wordbuf[0] = host2hfa384x_16(WLAN_SSID_MAXLEN);
232 get_random_bytes(&wordbuf[1], WLAN_SSID_MAXLEN);
233 result = hfa384x_drvr_setconfig( hw, HFA384x_RID_CNFOWNSSID,
234 wordbuf, HFA384x_RID_CNFOWNSSID_LEN);
236 printk(KERN_ERR "Failed to set OwnSSID.\n");
237 msg->resultcode.data =
238 P80211ENUM_resultcode_implementation_failure;
241 result = hfa384x_drvr_setconfig( hw, HFA384x_RID_CNFDESIREDSSID,
242 wordbuf, 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 WLAN_HEX_DUMP(5,"hscanreq", &scanreq, sizeof(scanreq));
289 result = hfa384x_drvr_setconfig( hw,
290 HFA384x_RID_HOSTSCAN, &scanreq,
291 sizeof(hfa384x_HostScanRequest_data_t));
293 printk(KERN_ERR "setconfig(SCANREQUEST) failed. result=%d\n",
295 msg->resultcode.data =
296 P80211ENUM_resultcode_implementation_failure;
300 /* sleep until info frame arrives */
301 wait_event_interruptible_timeout(hw->cmdq, hw->scanflag, timeout);
303 msg->numbss.status = P80211ENUM_msgitem_status_data_ok;
304 if (hw->scanflag == -1)
307 msg->numbss.data = hw->scanflag;
311 /* Disable port if we temporarily enabled it. */
313 result = hfa384x_drvr_disable(hw, 0);
315 printk(KERN_ERR "drvr_disable(0) failed. "
316 "result=%d\n", result);
317 msg->resultcode.data =
318 P80211ENUM_resultcode_implementation_failure;
323 /* restore original roaming mode */
324 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFROAMINGMODE,
327 printk(KERN_ERR "setconfig(ROAMMODE) failed. result=%d\n",
329 msg->resultcode.data =
330 P80211ENUM_resultcode_implementation_failure;
335 msg->resultcode.data = P80211ENUM_resultcode_success;
338 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
344 /*----------------------------------------------------------------
345 * prism2mgmt_scan_results
347 * Retrieve the BSS description for one of the BSSs identified in
351 * wlandev wlan device structure
352 * msgp ptr to msg buffer
356 * <0 success, but we're waiting for something to finish.
357 * >0 an error occurred while handling the message.
361 * process thread (usually)
363 ----------------------------------------------------------------*/
364 int prism2mgmt_scan_results(wlandevice_t *wlandev, void *msgp)
367 p80211msg_dot11req_scan_results_t *req;
368 hfa384x_t *hw = wlandev->priv;
369 hfa384x_HScanResultSub_t *item = NULL;
373 req = (p80211msg_dot11req_scan_results_t *) msgp;
375 req->resultcode.status = P80211ENUM_msgitem_status_data_ok;
377 if (! hw->scanresults) {
378 printk(KERN_ERR "dot11req_scan_results can only be used after a successful dot11req_scan.\n");
380 req->resultcode.data = P80211ENUM_resultcode_invalid_parameters;
384 count = (hw->scanresults->framelen - 3) / 32;
385 if (count > 32) count = 32;
387 if (req->bssindex.data >= count) {
388 WLAN_LOG_DEBUG(0, "requested index (%d) out of range (%d)\n",
389 req->bssindex.data, count);
391 req->resultcode.data = P80211ENUM_resultcode_invalid_parameters;
395 item = &(hw->scanresults->info.hscanresult.result[req->bssindex.data]);
396 /* signal and noise */
397 req->signal.status = P80211ENUM_msgitem_status_data_ok;
398 req->noise.status = P80211ENUM_msgitem_status_data_ok;
399 req->signal.data = hfa384x2host_16(item->sl);
400 req->noise.data = hfa384x2host_16(item->anl);
403 req->bssid.status = P80211ENUM_msgitem_status_data_ok;
404 req->bssid.data.len = WLAN_BSSID_LEN;
405 memcpy(req->bssid.data.data, item->bssid, WLAN_BSSID_LEN);
408 req->ssid.status = P80211ENUM_msgitem_status_data_ok;
409 req->ssid.data.len = hfa384x2host_16(item->ssid.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 = P80211ENUM_msgitem_status_data_ok; \
432 #define REQSUPPRATE(N) \
434 req->supprate ## N .data = item->supprates[(N)-1]; \
435 req->supprate ## N .status = P80211ENUM_msgitem_status_data_ok; \
448 req->beaconperiod.status = P80211ENUM_msgitem_status_data_ok;
449 req->beaconperiod.data = hfa384x2host_16(item->bcnint);
452 req->timestamp.status = P80211ENUM_msgitem_status_data_ok;
453 req->timestamp.data = jiffies;
454 req->localtime.status = P80211ENUM_msgitem_status_data_ok;
455 req->localtime.data = jiffies;
458 req->ibssatimwindow.status = P80211ENUM_msgitem_status_data_ok;
459 req->ibssatimwindow.data = hfa384x2host_16(item->atim);
462 req->dschannel.status = P80211ENUM_msgitem_status_data_ok;
463 req->dschannel.data = hfa384x2host_16(item->chid);
466 count = hfa384x2host_16(item->capinfo);
469 req->privacy.status = P80211ENUM_msgitem_status_data_ok;
470 req->privacy.data = WLAN_GET_MGMT_CAP_INFO_PRIVACY(count);
473 req->cfpollable.status = P80211ENUM_msgitem_status_data_ok;
474 req->cfpollable.data = WLAN_GET_MGMT_CAP_INFO_CFPOLLABLE(count);
477 req->cfpollreq.status = P80211ENUM_msgitem_status_data_ok;
478 req->cfpollreq.data = WLAN_GET_MGMT_CAP_INFO_CFPOLLREQ(count);
481 req->bsstype.status = P80211ENUM_msgitem_status_data_ok;
482 req->bsstype.data = (WLAN_GET_MGMT_CAP_INFO_ESS(count)) ?
483 P80211ENUM_bsstype_infrastructure :
484 P80211ENUM_bsstype_independent;
486 // item->proberesp_rate
496 req->resultcode.data = P80211ENUM_resultcode_success;
502 /*----------------------------------------------------------------
505 * Start a BSS. Any station can do this for IBSS, only AP for ESS.
508 * wlandev wlan device structure
509 * msgp ptr to msg buffer
513 * <0 success, but we're waiting for something to finish.
514 * >0 an error occurred while handling the message.
518 * process thread (usually)
520 ----------------------------------------------------------------*/
521 int prism2mgmt_start(wlandevice_t *wlandev, void *msgp)
524 hfa384x_t *hw = wlandev->priv;
525 p80211msg_dot11req_start_t *msg = msgp;
529 hfa384x_bytestr_t *p2bytestr = (hfa384x_bytestr_t*)bytebuf;
532 wlandev->macmode = WLAN_MACMODE_NONE;
535 memcpy(&wlandev->ssid, &msg->ssid.data, sizeof(msg->ssid.data));
538 /* see if current f/w is less than 8c3 */
539 if (HFA384x_FIRMWARE_VERSION(hw->ident_sta_fw.major,
540 hw->ident_sta_fw.minor,
541 hw->ident_sta_fw.variant) <
542 HFA384x_FIRMWARE_VERSION(0,8,3)) {
543 /* Ad-Hoc not quite supported on Prism2 */
544 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
545 msg->resultcode.data = P80211ENUM_resultcode_not_supported;
549 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
552 /* Set the REQUIRED config items */
554 pstr = (p80211pstrd_t*)&(msg->ssid.data);
555 prism2mgmt_pstr2bytestr(p2bytestr, pstr);
556 result = hfa384x_drvr_setconfig( hw, HFA384x_RID_CNFOWNSSID,
557 bytebuf, HFA384x_RID_CNFOWNSSID_LEN);
559 printk(KERN_ERR "Failed to set CnfOwnSSID\n");
562 result = hfa384x_drvr_setconfig( hw, HFA384x_RID_CNFDESIREDSSID,
563 bytebuf, HFA384x_RID_CNFDESIREDSSID_LEN);
565 printk(KERN_ERR "Failed to set CnfDesiredSSID\n");
569 /* bsstype - we use the default in the ap firmware */
571 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFPORTTYPE, 0);
574 word = msg->beaconperiod.data;
575 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFAPBCNint, word);
577 printk(KERN_ERR "Failed to set beacon period=%d.\n", word);
582 word = msg->dschannel.data;
583 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFOWNCHANNEL, word);
585 printk(KERN_ERR "Failed to set channel=%d.\n", word);
589 word = p80211rate_to_p2bit(msg->basicrate1.data);
590 if ( msg->basicrate2.status == P80211ENUM_msgitem_status_data_ok ) {
591 word |= p80211rate_to_p2bit(msg->basicrate2.data);
593 if ( msg->basicrate3.status == P80211ENUM_msgitem_status_data_ok ) {
594 word |= p80211rate_to_p2bit(msg->basicrate3.data);
596 if ( msg->basicrate4.status == P80211ENUM_msgitem_status_data_ok ) {
597 word |= p80211rate_to_p2bit(msg->basicrate4.data);
599 if ( msg->basicrate5.status == P80211ENUM_msgitem_status_data_ok ) {
600 word |= p80211rate_to_p2bit(msg->basicrate5.data);
602 if ( msg->basicrate6.status == P80211ENUM_msgitem_status_data_ok ) {
603 word |= p80211rate_to_p2bit(msg->basicrate6.data);
605 if ( msg->basicrate7.status == P80211ENUM_msgitem_status_data_ok ) {
606 word |= p80211rate_to_p2bit(msg->basicrate7.data);
608 if ( msg->basicrate8.status == P80211ENUM_msgitem_status_data_ok ) {
609 word |= p80211rate_to_p2bit(msg->basicrate8.data);
611 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFBASICRATES, word);
613 printk(KERN_ERR "Failed to set basicrates=%d.\n", word);
617 /* Operational rates (supprates and txratecontrol) */
618 word = p80211rate_to_p2bit(msg->operationalrate1.data);
619 if ( msg->operationalrate2.status == P80211ENUM_msgitem_status_data_ok ) {
620 word |= p80211rate_to_p2bit(msg->operationalrate2.data);
622 if ( msg->operationalrate3.status == P80211ENUM_msgitem_status_data_ok ) {
623 word |= p80211rate_to_p2bit(msg->operationalrate3.data);
625 if ( msg->operationalrate4.status == P80211ENUM_msgitem_status_data_ok ) {
626 word |= p80211rate_to_p2bit(msg->operationalrate4.data);
628 if ( msg->operationalrate5.status == P80211ENUM_msgitem_status_data_ok ) {
629 word |= p80211rate_to_p2bit(msg->operationalrate5.data);
631 if ( msg->operationalrate6.status == P80211ENUM_msgitem_status_data_ok ) {
632 word |= p80211rate_to_p2bit(msg->operationalrate6.data);
634 if ( msg->operationalrate7.status == P80211ENUM_msgitem_status_data_ok ) {
635 word |= p80211rate_to_p2bit(msg->operationalrate7.data);
637 if ( msg->operationalrate8.status == P80211ENUM_msgitem_status_data_ok ) {
638 word |= p80211rate_to_p2bit(msg->operationalrate8.data);
640 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFSUPPRATES, word);
642 printk(KERN_ERR "Failed to set supprates=%d.\n", word);
646 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_TXRATECNTL, word);
648 printk(KERN_ERR "Failed to set txrates=%d.\n", word);
652 /* Set the macmode so the frame setup code knows what to do */
653 if ( msg->bsstype.data == P80211ENUM_bsstype_independent ) {
654 wlandev->macmode = WLAN_MACMODE_IBSS_STA;
655 /* lets extend the data length a bit */
656 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFMAXDATALEN, 2304);
659 /* Enable the Port */
660 result = hfa384x_drvr_enable(hw, 0);
662 printk(KERN_ERR "Enable macport failed, result=%d.\n", result);
666 msg->resultcode.data = P80211ENUM_resultcode_success;
670 WLAN_LOG_DEBUG(1, "Failed to set a config option, result=%d\n", result);
671 msg->resultcode.data = P80211ENUM_resultcode_invalid_parameters;
679 /*----------------------------------------------------------------
682 * Collect the PDA data and put it in the message.
685 * wlandev wlan device structure
686 * msgp ptr to msg buffer
690 * <0 success, but we're waiting for something to finish.
691 * >0 an error occurred while handling the message.
695 * process thread (usually)
696 ----------------------------------------------------------------*/
697 int prism2mgmt_readpda(wlandevice_t *wlandev, void *msgp)
699 hfa384x_t *hw = wlandev->priv;
700 p80211msg_p2req_readpda_t *msg = msgp;
703 /* We only support collecting the PDA when in the FWLOAD
706 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
708 "PDA may only be read "
709 "in the fwload state.\n");
710 msg->resultcode.data =
711 P80211ENUM_resultcode_implementation_failure;
712 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
714 /* Call drvr_readpda(), it handles the auxport enable
715 * and validating the returned PDA.
717 result = hfa384x_drvr_readpda(
720 HFA384x_PDA_LEN_MAX);
723 "hfa384x_drvr_readpda() failed, "
727 msg->resultcode.data =
728 P80211ENUM_resultcode_implementation_failure;
729 msg->resultcode.status =
730 P80211ENUM_msgitem_status_data_ok;
733 msg->pda.status = P80211ENUM_msgitem_status_data_ok;
734 msg->resultcode.data = P80211ENUM_resultcode_success;
735 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
741 /*----------------------------------------------------------------
742 * prism2mgmt_ramdl_state
744 * Establishes the beginning/end of a card RAM download session.
746 * It is expected that the ramdl_write() function will be called
747 * one or more times between the 'enable' and 'disable' calls to
750 * Note: This function should not be called when a mac comm port
754 * wlandev wlan device structure
755 * msgp ptr to msg buffer
759 * <0 success, but we're waiting for something to finish.
760 * >0 an error occurred while handling the message.
764 * process thread (usually)
765 ----------------------------------------------------------------*/
766 int prism2mgmt_ramdl_state(wlandevice_t *wlandev, void *msgp)
768 hfa384x_t *hw = wlandev->priv;
769 p80211msg_p2req_ramdl_state_t *msg = msgp;
771 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
773 "ramdl_state(): may only be called "
774 "in the fwload state.\n");
775 msg->resultcode.data =
776 P80211ENUM_resultcode_implementation_failure;
777 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
782 ** Note: Interrupts are locked out if this is an AP and are NOT
783 ** locked out if this is a station.
786 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
787 if ( msg->enable.data == P80211ENUM_truth_true ) {
788 if ( hfa384x_drvr_ramdl_enable(hw, msg->exeaddr.data) ) {
789 msg->resultcode.data = P80211ENUM_resultcode_implementation_failure;
791 msg->resultcode.data = P80211ENUM_resultcode_success;
794 hfa384x_drvr_ramdl_disable(hw);
795 msg->resultcode.data = P80211ENUM_resultcode_success;
802 /*----------------------------------------------------------------
803 * prism2mgmt_ramdl_write
805 * Writes a buffer to the card RAM using the download state. This
806 * is for writing code to card RAM. To just read or write raw data
807 * use the aux functions.
810 * wlandev wlan device structure
811 * msgp ptr to msg buffer
815 * <0 success, but we're waiting for something to finish.
816 * >0 an error occurred while handling the message.
820 * process thread (usually)
821 ----------------------------------------------------------------*/
822 int prism2mgmt_ramdl_write(wlandevice_t *wlandev, void *msgp)
824 hfa384x_t *hw = wlandev->priv;
825 p80211msg_p2req_ramdl_write_t *msg = msgp;
830 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
832 "ramdl_write(): may only be called "
833 "in the fwload state.\n");
834 msg->resultcode.data =
835 P80211ENUM_resultcode_implementation_failure;
836 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
840 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
841 /* first validate the length */
842 if ( msg->len.data > sizeof(msg->data.data) ) {
843 msg->resultcode.status = P80211ENUM_resultcode_invalid_parameters;
846 /* call the hfa384x function to do the write */
847 addr = msg->addr.data;
849 buf = msg->data.data;
850 if ( hfa384x_drvr_ramdl_write(hw, addr, buf, len) ) {
851 msg->resultcode.data = P80211ENUM_resultcode_refused;
854 msg->resultcode.data = P80211ENUM_resultcode_success;
860 /*----------------------------------------------------------------
861 * prism2mgmt_flashdl_state
863 * Establishes the beginning/end of a card Flash download session.
865 * It is expected that the flashdl_write() function will be called
866 * one or more times between the 'enable' and 'disable' calls to
869 * Note: This function should not be called when a mac comm port
873 * wlandev wlan device structure
874 * msgp ptr to msg buffer
878 * <0 success, but we're waiting for something to finish.
879 * >0 an error occurred while handling the message.
883 * process thread (usually)
884 ----------------------------------------------------------------*/
885 int prism2mgmt_flashdl_state(wlandevice_t *wlandev, void *msgp)
888 hfa384x_t *hw = wlandev->priv;
889 p80211msg_p2req_flashdl_state_t *msg = msgp;
891 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
893 "flashdl_state(): may only be called "
894 "in the fwload state.\n");
895 msg->resultcode.data =
896 P80211ENUM_resultcode_implementation_failure;
897 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
902 ** Note: Interrupts are locked out if this is an AP and are NOT
903 ** locked out if this is a station.
906 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
907 if ( msg->enable.data == P80211ENUM_truth_true ) {
908 if ( hfa384x_drvr_flashdl_enable(hw) ) {
909 msg->resultcode.data = P80211ENUM_resultcode_implementation_failure;
911 msg->resultcode.data = P80211ENUM_resultcode_success;
914 hfa384x_drvr_flashdl_disable(hw);
915 msg->resultcode.data = P80211ENUM_resultcode_success;
916 /* NOTE: At this point, the MAC is in the post-reset
917 * state and the driver is in the fwload state.
918 * We need to get the MAC back into the fwload
919 * state. To do this, we set the nsdstate to HWPRESENT
920 * and then call the ifstate function to redo everything
921 * that got us into the fwload state.
923 wlandev->msdstate = WLAN_MSD_HWPRESENT;
924 result = prism2sta_ifstate(wlandev, P80211ENUM_ifstate_fwload);
925 if (result != P80211ENUM_resultcode_success) {
926 printk(KERN_ERR "prism2sta_ifstate(fwload) failed,"
927 "P80211ENUM_resultcode=%d\n", result);
928 msg->resultcode.data =
929 P80211ENUM_resultcode_implementation_failure;
938 /*----------------------------------------------------------------
939 * prism2mgmt_flashdl_write
944 * wlandev wlan device structure
945 * msgp ptr to msg buffer
949 * <0 success, but we're waiting for something to finish.
950 * >0 an error occurred while handling the message.
954 * process thread (usually)
955 ----------------------------------------------------------------*/
956 int prism2mgmt_flashdl_write(wlandevice_t *wlandev, void *msgp)
958 hfa384x_t *hw = wlandev->priv;
959 p80211msg_p2req_flashdl_write_t *msg = msgp;
964 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
966 "flashdl_write(): may only be called "
967 "in the fwload state.\n");
968 msg->resultcode.data =
969 P80211ENUM_resultcode_implementation_failure;
970 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
975 ** Note: Interrupts are locked out if this is an AP and are NOT
976 ** locked out if this is a station.
979 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
980 /* first validate the length */
981 if ( msg->len.data > sizeof(msg->data.data) ) {
982 msg->resultcode.status =
983 P80211ENUM_resultcode_invalid_parameters;
986 /* call the hfa384x function to do the write */
987 addr = msg->addr.data;
989 buf = msg->data.data;
990 if ( hfa384x_drvr_flashdl_write(hw, addr, buf, len) ) {
991 msg->resultcode.data = P80211ENUM_resultcode_refused;
994 msg->resultcode.data = P80211ENUM_resultcode_success;
999 /*----------------------------------------------------------------
1000 * prism2mgmt_autojoin
1002 * Associate with an ESS.
1005 * wlandev wlan device structure
1006 * msgp ptr to msg buffer
1009 * 0 success and done
1010 * <0 success, but we're waiting for something to finish.
1011 * >0 an error occurred while handling the message.
1015 * process thread (usually)
1017 ----------------------------------------------------------------*/
1018 int prism2mgmt_autojoin(wlandevice_t *wlandev, void *msgp)
1020 hfa384x_t *hw = wlandev->priv;
1024 p80211msg_lnxreq_autojoin_t *msg = msgp;
1025 p80211pstrd_t *pstr;
1027 hfa384x_bytestr_t *p2bytestr = (hfa384x_bytestr_t*)bytebuf;
1029 wlandev->macmode = WLAN_MACMODE_NONE;
1032 memcpy(&wlandev->ssid, &msg->ssid.data, sizeof(msg->ssid.data));
1034 /* Disable the Port */
1035 hfa384x_drvr_disable(hw, 0);
1038 /* Set the TxRates */
1039 hfa384x_drvr_setconfig16(hw, HFA384x_RID_TXRATECNTL, 0x000f);
1041 /* Set the auth type */
1042 if ( msg->authtype.data == P80211ENUM_authalg_sharedkey ) {
1043 reg = HFA384x_CNFAUTHENTICATION_SHAREDKEY;
1045 reg = HFA384x_CNFAUTHENTICATION_OPENSYSTEM;
1047 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFAUTHENTICATION, reg);
1050 memset(bytebuf, 0, 256);
1051 pstr = (p80211pstrd_t*)&(msg->ssid.data);
1052 prism2mgmt_pstr2bytestr(p2bytestr, pstr);
1053 result = hfa384x_drvr_setconfig(
1054 hw, HFA384x_RID_CNFDESIREDSSID,
1055 bytebuf, HFA384x_RID_CNFDESIREDSSID_LEN);
1056 port_type = HFA384x_PORTTYPE_BSS;
1057 /* Set the PortType */
1058 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFPORTTYPE, port_type);
1060 /* Enable the Port */
1061 hfa384x_drvr_enable(hw, 0);
1063 /* Set the resultcode */
1064 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
1065 msg->resultcode.data = P80211ENUM_resultcode_success;
1071 /*----------------------------------------------------------------
1072 * prism2mgmt_wlansniff
1074 * Start or stop sniffing.
1077 * wlandev wlan device structure
1078 * msgp ptr to msg buffer
1081 * 0 success and done
1082 * <0 success, but we're waiting for something to finish.
1083 * >0 an error occurred while handling the message.
1087 * process thread (usually)
1089 ----------------------------------------------------------------*/
1090 int prism2mgmt_wlansniff(wlandevice_t *wlandev, void *msgp)
1093 p80211msg_lnxreq_wlansniff_t *msg = msgp;
1095 hfa384x_t *hw = wlandev->priv;
1098 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
1099 switch (msg->enable.data)
1101 case P80211ENUM_truth_false:
1102 /* Confirm that we're in monitor mode */
1103 if ( wlandev->netdev->type == ARPHRD_ETHER ) {
1104 msg->resultcode.data = P80211ENUM_resultcode_invalid_parameters;
1108 /* Disable monitor mode */
1109 result = hfa384x_cmd_monitor(hw, HFA384x_MONITOR_DISABLE);
1112 "failed to disable monitor mode, result=%d\n",
1116 /* Disable port 0 */
1117 result = hfa384x_drvr_disable(hw, 0);
1120 "failed to disable port 0 after sniffing, result=%d\n",
1124 /* Clear the driver state */
1125 wlandev->netdev->type = ARPHRD_ETHER;
1127 /* Restore the wepflags */
1128 result = hfa384x_drvr_setconfig16(hw,
1129 HFA384x_RID_CNFWEPFLAGS,
1130 hw->presniff_wepflags);
1133 "failed to restore wepflags=0x%04x, result=%d\n",
1134 hw->presniff_wepflags,
1139 /* Set the port to its prior type and enable (if necessary) */
1140 if (hw->presniff_port_type != 0 ) {
1141 word = hw->presniff_port_type;
1142 result = hfa384x_drvr_setconfig16(hw,
1143 HFA384x_RID_CNFPORTTYPE, word);
1146 "failed to restore porttype, result=%d\n",
1151 /* Enable the port */
1152 result = hfa384x_drvr_enable(hw, 0);
1154 WLAN_LOG_DEBUG(1, "failed to enable port to presniff setting, result=%d\n", result);
1158 result = hfa384x_drvr_disable(hw, 0);
1162 printk(KERN_INFO "monitor mode disabled\n");
1163 msg->resultcode.data = P80211ENUM_resultcode_success;
1167 case P80211ENUM_truth_true:
1168 /* Disable the port (if enabled), only check Port 0 */
1169 if ( hw->port_enabled[0]) {
1170 if (wlandev->netdev->type == ARPHRD_ETHER) {
1171 /* Save macport 0 state */
1172 result = hfa384x_drvr_getconfig16(hw,
1173 HFA384x_RID_CNFPORTTYPE,
1174 &(hw->presniff_port_type));
1176 WLAN_LOG_DEBUG(1,"failed to read porttype, result=%d\n", result);
1179 /* Save the wepflags state */
1180 result = hfa384x_drvr_getconfig16(hw,
1181 HFA384x_RID_CNFWEPFLAGS,
1182 &(hw->presniff_wepflags));
1184 WLAN_LOG_DEBUG(1,"failed to read wepflags, result=%d\n", result);
1187 hfa384x_drvr_stop(hw);
1188 result = hfa384x_drvr_start(hw);
1191 "failed to restart the card for sniffing, result=%d\n",
1196 /* Disable the port */
1197 result = hfa384x_drvr_disable(hw, 0);
1200 "failed to enable port for sniffing, result=%d\n",
1206 hw->presniff_port_type = 0;
1209 /* Set the channel we wish to sniff */
1210 word = msg->channel.data;
1211 result = hfa384x_drvr_setconfig16(hw,
1212 HFA384x_RID_CNFOWNCHANNEL, word);
1213 hw->sniff_channel=word;
1217 "failed to set channel %d, result=%d\n",
1223 /* Now if we're already sniffing, we can skip the rest */
1224 if (wlandev->netdev->type != ARPHRD_ETHER) {
1225 /* Set the port type to pIbss */
1226 word = HFA384x_PORTTYPE_PSUEDOIBSS;
1227 result = hfa384x_drvr_setconfig16(hw,
1228 HFA384x_RID_CNFPORTTYPE, word);
1231 "failed to set porttype %d, result=%d\n",
1236 if ((msg->keepwepflags.status == P80211ENUM_msgitem_status_data_ok) && (msg->keepwepflags.data != P80211ENUM_truth_true)) {
1237 /* Set the wepflags for no decryption */
1238 word = HFA384x_WEPFLAGS_DISABLE_TXCRYPT |
1239 HFA384x_WEPFLAGS_DISABLE_RXCRYPT;
1240 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFWEPFLAGS, word);
1245 "failed to set wepflags=0x%04x, result=%d\n",
1252 /* Do we want to strip the FCS in monitor mode? */
1253 if ((msg->stripfcs.status == P80211ENUM_msgitem_status_data_ok) && (msg->stripfcs.data == P80211ENUM_truth_true)) {
1259 /* Do we want to truncate the packets? */
1260 if (msg->packet_trunc.status == 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);
1278 "failed to enable monitor mode, result=%d\n",
1283 if (wlandev->netdev->type == ARPHRD_ETHER) {
1284 printk(KERN_INFO "monitor mode enabled\n");
1287 /* Set the driver state */
1288 /* Do we want the prism2 header? */
1289 if ((msg->prismheader.status == P80211ENUM_msgitem_status_data_ok) && (msg->prismheader.data == P80211ENUM_truth_true)) {
1291 wlandev->netdev->type = ARPHRD_IEEE80211_PRISM;
1292 } else if ((msg->wlanheader.status == P80211ENUM_msgitem_status_data_ok) && (msg->wlanheader.data == P80211ENUM_truth_true)) {
1294 wlandev->netdev->type = ARPHRD_IEEE80211_PRISM;
1296 wlandev->netdev->type = ARPHRD_IEEE80211;
1299 msg->resultcode.data = P80211ENUM_resultcode_success;
1304 msg->resultcode.data = P80211ENUM_resultcode_invalid_parameters;
1311 msg->resultcode.data = P80211ENUM_resultcode_refused;