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/slab.h>
67 #include <linux/wireless.h>
68 #include <linux/netdevice.h>
69 #include <linux/delay.h>
71 #include <asm/byteorder.h>
72 #include <linux/random.h>
73 #include <linux/usb.h>
74 #include <linux/bitops.h>
76 /*================================================================*/
77 /* Project Includes */
79 #include "p80211types.h"
80 #include "p80211hdr.h"
81 #include "p80211mgmt.h"
82 #include "p80211conv.h"
83 #include "p80211msg.h"
84 #include "p80211netdev.h"
85 #include "p80211metadef.h"
86 #include "p80211metastruct.h"
88 #include "prism2mgmt.h"
90 /* Converts 802.11 format rate specifications to prism2 */
91 #define p80211rate_to_p2bit(n) ((((n)&~BIT(7)) == 2) ? BIT(0) : \
92 (((n)&~BIT(7)) == 4) ? BIT(1) : \
93 (((n)&~BIT(7)) == 11) ? BIT(2) : \
94 (((n)&~BIT(7)) == 22) ? BIT(3) : 0)
96 /*----------------------------------------------------------------
99 * Initiate a scan for BSSs.
101 * This function corresponds to MLME-scan.request and part of
102 * MLME-scan.confirm. As far as I can tell in the standard, there
103 * are no restrictions on when a scan.request may be issued. We have
104 * to handle in whatever state the driver/MAC happen to be.
107 * wlandev wlan device structure
108 * msgp ptr to msg buffer
112 * <0 success, but we're waiting for something to finish.
113 * >0 an error occurred while handling the message.
117 * process thread (usually)
119 ----------------------------------------------------------------*/
120 int prism2mgmt_scan(wlandevice_t * wlandev, void *msgp)
123 hfa384x_t *hw = wlandev->priv;
124 p80211msg_dot11req_scan_t *msg = msgp;
125 u16 roamingmode, word;
129 hfa384x_HostScanRequest_data_t scanreq;
131 /* gatekeeper check */
132 if (HFA384x_FIRMWARE_VERSION(hw->ident_sta_fw.major,
133 hw->ident_sta_fw.minor,
134 hw->ident_sta_fw.variant) <
135 HFA384x_FIRMWARE_VERSION(1, 3, 2)) {
137 "HostScan not supported with current firmware (<1.3.2).\n");
139 msg->resultcode.data = P80211ENUM_resultcode_not_supported;
143 memset(&scanreq, 0, sizeof(scanreq));
145 /* save current roaming mode */
146 result = hfa384x_drvr_getconfig16(hw,
147 HFA384x_RID_CNFROAMINGMODE,
150 printk(KERN_ERR "getconfig(ROAMMODE) failed. result=%d\n",
152 msg->resultcode.data =
153 P80211ENUM_resultcode_implementation_failure;
157 /* drop into mode 3 for the scan */
158 result = hfa384x_drvr_setconfig16(hw,
159 HFA384x_RID_CNFROAMINGMODE,
160 HFA384x_ROAMMODE_HOSTSCAN_HOSTROAM);
162 printk(KERN_ERR "setconfig(ROAMINGMODE) failed. result=%d\n",
164 msg->resultcode.data =
165 P80211ENUM_resultcode_implementation_failure;
169 /* active or passive? */
170 if (HFA384x_FIRMWARE_VERSION(hw->ident_sta_fw.major,
171 hw->ident_sta_fw.minor,
172 hw->ident_sta_fw.variant) >
173 HFA384x_FIRMWARE_VERSION(1, 5, 0)) {
174 if (msg->scantype.data != P80211ENUM_scantype_active)
175 word = cpu_to_le16(msg->maxchanneltime.data);
180 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFPASSIVESCANCTRL,
183 printk(KERN_WARNING "Passive scan not supported with "
184 "current firmware. (<1.5.1)\n");
188 /* set up the txrate to be 2MBPS. Should be fastest basicrate... */
189 word = HFA384x_RATEBIT_2;
190 scanreq.txRate = cpu_to_le16(word);
192 /* set up the channel list */
194 for (i = 0; i < msg->channellist.data.len; i++) {
195 u8 channel = msg->channellist.data.data[i];
198 /* channel 1 is BIT 0 ... channel 14 is BIT 13 */
199 word |= (1 << (channel - 1));
201 scanreq.channelList = cpu_to_le16(word);
203 /* set up the ssid, if present. */
204 scanreq.ssid.len = cpu_to_le16(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);
224 "setconfig(ROAMINGMODE) failed. result=%d\n",
226 msg->resultcode.data =
227 P80211ENUM_resultcode_implementation_failure;
230 /* Construct a bogus SSID and assign it to OwnSSID and
233 wordbuf[0] = cpu_to_le16(WLAN_SSID_MAXLEN);
234 get_random_bytes(&wordbuf[1], WLAN_SSID_MAXLEN);
235 result = hfa384x_drvr_setconfig(hw, HFA384x_RID_CNFOWNSSID,
237 HFA384x_RID_CNFOWNSSID_LEN);
239 printk(KERN_ERR "Failed to set OwnSSID.\n");
240 msg->resultcode.data =
241 P80211ENUM_resultcode_implementation_failure;
244 result = hfa384x_drvr_setconfig(hw, HFA384x_RID_CNFDESIREDSSID,
246 HFA384x_RID_CNFDESIREDSSID_LEN);
248 printk(KERN_ERR "Failed to set DesiredSSID.\n");
249 msg->resultcode.data =
250 P80211ENUM_resultcode_implementation_failure;
254 result = hfa384x_drvr_setconfig16(hw,
255 HFA384x_RID_CNFPORTTYPE,
256 HFA384x_PORTTYPE_IBSS);
258 printk(KERN_ERR "Failed to set CNFPORTTYPE.\n");
259 msg->resultcode.data =
260 P80211ENUM_resultcode_implementation_failure;
264 result = hfa384x_drvr_setconfig16(hw,
265 HFA384x_RID_CREATEIBSS,
266 HFA384x_CREATEIBSS_JOINCREATEIBSS);
268 printk(KERN_ERR "Failed to set CREATEIBSS.\n");
269 msg->resultcode.data =
270 P80211ENUM_resultcode_implementation_failure;
273 result = hfa384x_drvr_enable(hw, 0);
275 printk(KERN_ERR "drvr_enable(0) failed. "
276 "result=%d\n", result);
277 msg->resultcode.data =
278 P80211ENUM_resultcode_implementation_failure;
284 /* Figure out our timeout first Kus, then HZ */
285 timeout = msg->channellist.data.len * msg->maxchanneltime.data;
286 timeout = (timeout * HZ) / 1000;
288 /* Issue the scan request */
291 result = hfa384x_drvr_setconfig(hw,
292 HFA384x_RID_HOSTSCAN, &scanreq,
293 sizeof(hfa384x_HostScanRequest_data_t));
295 printk(KERN_ERR "setconfig(SCANREQUEST) failed. result=%d\n",
297 msg->resultcode.data =
298 P80211ENUM_resultcode_implementation_failure;
302 /* sleep until info frame arrives */
303 wait_event_interruptible_timeout(hw->cmdq, hw->scanflag, timeout);
305 msg->numbss.status = P80211ENUM_msgitem_status_data_ok;
306 if (hw->scanflag == -1)
309 msg->numbss.data = hw->scanflag;
313 /* Disable port if we temporarily enabled it. */
315 result = hfa384x_drvr_disable(hw, 0);
317 printk(KERN_ERR "drvr_disable(0) failed. "
318 "result=%d\n", result);
319 msg->resultcode.data =
320 P80211ENUM_resultcode_implementation_failure;
325 /* restore original roaming mode */
326 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFROAMINGMODE,
329 printk(KERN_ERR "setconfig(ROAMMODE) failed. result=%d\n",
331 msg->resultcode.data =
332 P80211ENUM_resultcode_implementation_failure;
337 msg->resultcode.data = P80211ENUM_resultcode_success;
340 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
345 /*----------------------------------------------------------------
346 * prism2mgmt_scan_results
348 * Retrieve the BSS description for one of the BSSs identified in
352 * wlandev wlan device structure
353 * msgp ptr to msg buffer
357 * <0 success, but we're waiting for something to finish.
358 * >0 an error occurred while handling the message.
362 * process thread (usually)
364 ----------------------------------------------------------------*/
365 int prism2mgmt_scan_results(wlandevice_t * wlandev, void *msgp)
368 p80211msg_dot11req_scan_results_t *req;
369 hfa384x_t *hw = wlandev->priv;
370 hfa384x_HScanResultSub_t *item = NULL;
374 req = (p80211msg_dot11req_scan_results_t *) msgp;
376 req->resultcode.status = P80211ENUM_msgitem_status_data_ok;
378 if (!hw->scanresults) {
380 "dot11req_scan_results can only be used after a successful dot11req_scan.\n");
382 req->resultcode.data = P80211ENUM_resultcode_invalid_parameters;
386 count = (hw->scanresults->framelen - 3) / 32;
390 if (req->bssindex.data >= count) {
391 pr_debug("requested index (%d) out of range (%d)\n",
392 req->bssindex.data, count);
394 req->resultcode.data = P80211ENUM_resultcode_invalid_parameters;
398 item = &(hw->scanresults->info.hscanresult.result[req->bssindex.data]);
399 /* signal and noise */
400 req->signal.status = P80211ENUM_msgitem_status_data_ok;
401 req->noise.status = P80211ENUM_msgitem_status_data_ok;
402 req->signal.data = le16_to_cpu(item->sl);
403 req->noise.data = le16_to_cpu(item->anl);
406 req->bssid.status = P80211ENUM_msgitem_status_data_ok;
407 req->bssid.data.len = WLAN_BSSID_LEN;
408 memcpy(req->bssid.data.data, item->bssid, WLAN_BSSID_LEN);
411 req->ssid.status = P80211ENUM_msgitem_status_data_ok;
412 req->ssid.data.len = le16_to_cpu(item->ssid.len);
413 memcpy(req->ssid.data.data, item->ssid.data, req->ssid.data.len);
415 /* supported rates */
416 for (count = 0; count < 10; count++)
417 if (item->supprates[count] == 0)
420 #define REQBASICRATE(N) \
421 if ((count >= N) && DOT11_RATE5_ISBASIC_GET(item->supprates[(N)-1])) { \
422 req->basicrate ## N .data = item->supprates[(N)-1]; \
423 req->basicrate ## N .status = P80211ENUM_msgitem_status_data_ok; \
435 #define REQSUPPRATE(N) \
437 req->supprate ## N .data = item->supprates[(N)-1]; \
438 req->supprate ## N .status = P80211ENUM_msgitem_status_data_ok; \
451 req->beaconperiod.status = P80211ENUM_msgitem_status_data_ok;
452 req->beaconperiod.data = le16_to_cpu(item->bcnint);
455 req->timestamp.status = P80211ENUM_msgitem_status_data_ok;
456 req->timestamp.data = jiffies;
457 req->localtime.status = P80211ENUM_msgitem_status_data_ok;
458 req->localtime.data = jiffies;
461 req->ibssatimwindow.status = P80211ENUM_msgitem_status_data_ok;
462 req->ibssatimwindow.data = le16_to_cpu(item->atim);
465 req->dschannel.status = P80211ENUM_msgitem_status_data_ok;
466 req->dschannel.data = le16_to_cpu(item->chid);
469 count = le16_to_cpu(item->capinfo);
472 req->privacy.status = P80211ENUM_msgitem_status_data_ok;
473 req->privacy.data = WLAN_GET_MGMT_CAP_INFO_PRIVACY(count);
476 req->cfpollable.status = P80211ENUM_msgitem_status_data_ok;
477 req->cfpollable.data = WLAN_GET_MGMT_CAP_INFO_CFPOLLABLE(count);
480 req->cfpollreq.status = P80211ENUM_msgitem_status_data_ok;
481 req->cfpollreq.data = WLAN_GET_MGMT_CAP_INFO_CFPOLLREQ(count);
484 req->bsstype.status = P80211ENUM_msgitem_status_data_ok;
485 req->bsstype.data = (WLAN_GET_MGMT_CAP_INFO_ESS(count)) ?
486 P80211ENUM_bsstype_infrastructure : P80211ENUM_bsstype_independent;
489 req->resultcode.data = P80211ENUM_resultcode_success;
495 /*----------------------------------------------------------------
498 * Start a BSS. Any station can do this for IBSS, only AP for ESS.
501 * wlandev wlan device structure
502 * msgp ptr to msg buffer
506 * <0 success, but we're waiting for something to finish.
507 * >0 an error occurred while handling the message.
511 * process thread (usually)
513 ----------------------------------------------------------------*/
514 int prism2mgmt_start(wlandevice_t * wlandev, void *msgp)
517 hfa384x_t *hw = wlandev->priv;
518 p80211msg_dot11req_start_t *msg = msgp;
522 hfa384x_bytestr_t *p2bytestr = (hfa384x_bytestr_t *) bytebuf;
525 wlandev->macmode = WLAN_MACMODE_NONE;
528 memcpy(&wlandev->ssid, &msg->ssid.data, sizeof(msg->ssid.data));
531 /* see if current f/w is less than 8c3 */
532 if (HFA384x_FIRMWARE_VERSION(hw->ident_sta_fw.major,
533 hw->ident_sta_fw.minor,
534 hw->ident_sta_fw.variant) <
535 HFA384x_FIRMWARE_VERSION(0, 8, 3)) {
536 /* Ad-Hoc not quite supported on Prism2 */
537 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
538 msg->resultcode.data = P80211ENUM_resultcode_not_supported;
542 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
545 /* Set the REQUIRED config items */
547 pstr = (p80211pstrd_t *) & (msg->ssid.data);
548 prism2mgmt_pstr2bytestr(p2bytestr, pstr);
549 result = hfa384x_drvr_setconfig(hw, HFA384x_RID_CNFOWNSSID,
550 bytebuf, HFA384x_RID_CNFOWNSSID_LEN);
552 printk(KERN_ERR "Failed to set CnfOwnSSID\n");
555 result = hfa384x_drvr_setconfig(hw, HFA384x_RID_CNFDESIREDSSID,
557 HFA384x_RID_CNFDESIREDSSID_LEN);
559 printk(KERN_ERR "Failed to set CnfDesiredSSID\n");
563 /* bsstype - we use the default in the ap firmware */
565 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFPORTTYPE, 0);
568 word = msg->beaconperiod.data;
569 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFAPBCNint, word);
571 printk(KERN_ERR "Failed to set beacon period=%d.\n", word);
576 word = msg->dschannel.data;
577 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFOWNCHANNEL, word);
579 printk(KERN_ERR "Failed to set channel=%d.\n", word);
583 word = p80211rate_to_p2bit(msg->basicrate1.data);
584 if (msg->basicrate2.status == P80211ENUM_msgitem_status_data_ok)
585 word |= p80211rate_to_p2bit(msg->basicrate2.data);
587 if (msg->basicrate3.status == P80211ENUM_msgitem_status_data_ok)
588 word |= p80211rate_to_p2bit(msg->basicrate3.data);
590 if (msg->basicrate4.status == P80211ENUM_msgitem_status_data_ok)
591 word |= p80211rate_to_p2bit(msg->basicrate4.data);
593 if (msg->basicrate5.status == P80211ENUM_msgitem_status_data_ok)
594 word |= p80211rate_to_p2bit(msg->basicrate5.data);
596 if (msg->basicrate6.status == P80211ENUM_msgitem_status_data_ok)
597 word |= p80211rate_to_p2bit(msg->basicrate6.data);
599 if (msg->basicrate7.status == P80211ENUM_msgitem_status_data_ok)
600 word |= p80211rate_to_p2bit(msg->basicrate7.data);
602 if (msg->basicrate8.status == P80211ENUM_msgitem_status_data_ok)
603 word |= p80211rate_to_p2bit(msg->basicrate8.data);
605 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFBASICRATES, word);
607 printk(KERN_ERR "Failed to set basicrates=%d.\n", word);
611 /* Operational rates (supprates and txratecontrol) */
612 word = p80211rate_to_p2bit(msg->operationalrate1.data);
613 if (msg->operationalrate2.status == P80211ENUM_msgitem_status_data_ok)
614 word |= p80211rate_to_p2bit(msg->operationalrate2.data);
616 if (msg->operationalrate3.status == P80211ENUM_msgitem_status_data_ok)
617 word |= p80211rate_to_p2bit(msg->operationalrate3.data);
619 if (msg->operationalrate4.status == P80211ENUM_msgitem_status_data_ok)
620 word |= p80211rate_to_p2bit(msg->operationalrate4.data);
622 if (msg->operationalrate5.status == P80211ENUM_msgitem_status_data_ok)
623 word |= p80211rate_to_p2bit(msg->operationalrate5.data);
625 if (msg->operationalrate6.status == P80211ENUM_msgitem_status_data_ok)
626 word |= p80211rate_to_p2bit(msg->operationalrate6.data);
628 if (msg->operationalrate7.status == P80211ENUM_msgitem_status_data_ok)
629 word |= p80211rate_to_p2bit(msg->operationalrate7.data);
631 if (msg->operationalrate8.status == P80211ENUM_msgitem_status_data_ok)
632 word |= p80211rate_to_p2bit(msg->operationalrate8.data);
634 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFSUPPRATES, word);
636 printk(KERN_ERR "Failed to set supprates=%d.\n", word);
640 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_TXRATECNTL, word);
642 printk(KERN_ERR "Failed to set txrates=%d.\n", word);
646 /* Set the macmode so the frame setup code knows what to do */
647 if (msg->bsstype.data == P80211ENUM_bsstype_independent) {
648 wlandev->macmode = WLAN_MACMODE_IBSS_STA;
649 /* lets extend the data length a bit */
650 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFMAXDATALEN, 2304);
653 /* Enable the Port */
654 result = hfa384x_drvr_enable(hw, 0);
656 printk(KERN_ERR "Enable macport failed, result=%d.\n", result);
660 msg->resultcode.data = P80211ENUM_resultcode_success;
664 pr_debug("Failed to set a config option, result=%d\n", result);
665 msg->resultcode.data = P80211ENUM_resultcode_invalid_parameters;
673 /*----------------------------------------------------------------
676 * Collect the PDA data and put it in the message.
679 * wlandev wlan device structure
680 * msgp ptr to msg buffer
684 * <0 success, but we're waiting for something to finish.
685 * >0 an error occurred while handling the message.
689 * process thread (usually)
690 ----------------------------------------------------------------*/
691 int prism2mgmt_readpda(wlandevice_t * wlandev, void *msgp)
693 hfa384x_t *hw = wlandev->priv;
694 p80211msg_p2req_readpda_t *msg = msgp;
697 /* We only support collecting the PDA when in the FWLOAD
700 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
702 "PDA may only be read " "in the fwload state.\n");
703 msg->resultcode.data =
704 P80211ENUM_resultcode_implementation_failure;
705 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
707 /* Call drvr_readpda(), it handles the auxport enable
708 * and validating the returned PDA.
710 result = hfa384x_drvr_readpda(hw,
712 HFA384x_PDA_LEN_MAX);
715 "hfa384x_drvr_readpda() failed, "
716 "result=%d\n", result);
718 msg->resultcode.data =
719 P80211ENUM_resultcode_implementation_failure;
720 msg->resultcode.status =
721 P80211ENUM_msgitem_status_data_ok;
724 msg->pda.status = P80211ENUM_msgitem_status_data_ok;
725 msg->resultcode.data = P80211ENUM_resultcode_success;
726 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
732 /*----------------------------------------------------------------
733 * prism2mgmt_ramdl_state
735 * Establishes the beginning/end of a card RAM download session.
737 * It is expected that the ramdl_write() function will be called
738 * one or more times between the 'enable' and 'disable' calls to
741 * Note: This function should not be called when a mac comm port
745 * wlandev wlan device structure
746 * msgp ptr to msg buffer
750 * <0 success, but we're waiting for something to finish.
751 * >0 an error occurred while handling the message.
755 * process thread (usually)
756 ----------------------------------------------------------------*/
757 int prism2mgmt_ramdl_state(wlandevice_t * wlandev, void *msgp)
759 hfa384x_t *hw = wlandev->priv;
760 p80211msg_p2req_ramdl_state_t *msg = msgp;
762 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
764 "ramdl_state(): may only be called "
765 "in the fwload state.\n");
766 msg->resultcode.data =
767 P80211ENUM_resultcode_implementation_failure;
768 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
773 ** Note: Interrupts are locked out if this is an AP and are NOT
774 ** locked out if this is a station.
777 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
778 if (msg->enable.data == P80211ENUM_truth_true) {
779 if (hfa384x_drvr_ramdl_enable(hw, msg->exeaddr.data)) {
780 msg->resultcode.data =
781 P80211ENUM_resultcode_implementation_failure;
783 msg->resultcode.data = P80211ENUM_resultcode_success;
786 hfa384x_drvr_ramdl_disable(hw);
787 msg->resultcode.data = P80211ENUM_resultcode_success;
793 /*----------------------------------------------------------------
794 * prism2mgmt_ramdl_write
796 * Writes a buffer to the card RAM using the download state. This
797 * is for writing code to card RAM. To just read or write raw data
798 * use the aux functions.
801 * wlandev wlan device structure
802 * msgp ptr to msg buffer
806 * <0 success, but we're waiting for something to finish.
807 * >0 an error occurred while handling the message.
811 * process thread (usually)
812 ----------------------------------------------------------------*/
813 int prism2mgmt_ramdl_write(wlandevice_t * wlandev, void *msgp)
815 hfa384x_t *hw = wlandev->priv;
816 p80211msg_p2req_ramdl_write_t *msg = msgp;
821 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
823 "ramdl_write(): may only be called "
824 "in the fwload state.\n");
825 msg->resultcode.data =
826 P80211ENUM_resultcode_implementation_failure;
827 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
831 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
832 /* first validate the length */
833 if (msg->len.data > sizeof(msg->data.data)) {
834 msg->resultcode.status =
835 P80211ENUM_resultcode_invalid_parameters;
838 /* call the hfa384x function to do the write */
839 addr = msg->addr.data;
841 buf = msg->data.data;
842 if (hfa384x_drvr_ramdl_write(hw, addr, buf, len))
843 msg->resultcode.data = P80211ENUM_resultcode_refused;
845 msg->resultcode.data = P80211ENUM_resultcode_success;
850 /*----------------------------------------------------------------
851 * prism2mgmt_flashdl_state
853 * Establishes the beginning/end of a card Flash download session.
855 * It is expected that the flashdl_write() function will be called
856 * one or more times between the 'enable' and 'disable' calls to
859 * Note: This function should not be called when a mac comm port
863 * wlandev wlan device structure
864 * msgp ptr to msg buffer
868 * <0 success, but we're waiting for something to finish.
869 * >0 an error occurred while handling the message.
873 * process thread (usually)
874 ----------------------------------------------------------------*/
875 int prism2mgmt_flashdl_state(wlandevice_t * wlandev, void *msgp)
878 hfa384x_t *hw = wlandev->priv;
879 p80211msg_p2req_flashdl_state_t *msg = msgp;
881 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
883 "flashdl_state(): may only be called "
884 "in the fwload state.\n");
885 msg->resultcode.data =
886 P80211ENUM_resultcode_implementation_failure;
887 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
892 ** Note: Interrupts are locked out if this is an AP and are NOT
893 ** locked out if this is a station.
896 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
897 if (msg->enable.data == P80211ENUM_truth_true) {
898 if (hfa384x_drvr_flashdl_enable(hw)) {
899 msg->resultcode.data =
900 P80211ENUM_resultcode_implementation_failure;
902 msg->resultcode.data = P80211ENUM_resultcode_success;
905 hfa384x_drvr_flashdl_disable(hw);
906 msg->resultcode.data = P80211ENUM_resultcode_success;
907 /* NOTE: At this point, the MAC is in the post-reset
908 * state and the driver is in the fwload state.
909 * We need to get the MAC back into the fwload
910 * state. To do this, we set the nsdstate to HWPRESENT
911 * and then call the ifstate function to redo everything
912 * that got us into the fwload state.
914 wlandev->msdstate = WLAN_MSD_HWPRESENT;
915 result = prism2sta_ifstate(wlandev, P80211ENUM_ifstate_fwload);
916 if (result != P80211ENUM_resultcode_success) {
917 printk(KERN_ERR "prism2sta_ifstate(fwload) failed,"
918 "P80211ENUM_resultcode=%d\n", result);
919 msg->resultcode.data =
920 P80211ENUM_resultcode_implementation_failure;
928 /*----------------------------------------------------------------
929 * prism2mgmt_flashdl_write
934 * wlandev wlan device structure
935 * msgp ptr to msg buffer
939 * <0 success, but we're waiting for something to finish.
940 * >0 an error occurred while handling the message.
944 * process thread (usually)
945 ----------------------------------------------------------------*/
946 int prism2mgmt_flashdl_write(wlandevice_t * wlandev, void *msgp)
948 hfa384x_t *hw = wlandev->priv;
949 p80211msg_p2req_flashdl_write_t *msg = msgp;
954 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
956 "flashdl_write(): may only be called "
957 "in the fwload state.\n");
958 msg->resultcode.data =
959 P80211ENUM_resultcode_implementation_failure;
960 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
965 ** Note: Interrupts are locked out if this is an AP and are NOT
966 ** locked out if this is a station.
969 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
970 /* first validate the length */
971 if (msg->len.data > sizeof(msg->data.data)) {
972 msg->resultcode.status =
973 P80211ENUM_resultcode_invalid_parameters;
976 /* call the hfa384x function to do the write */
977 addr = msg->addr.data;
979 buf = msg->data.data;
980 if (hfa384x_drvr_flashdl_write(hw, addr, buf, len))
981 msg->resultcode.data = P80211ENUM_resultcode_refused;
983 msg->resultcode.data = P80211ENUM_resultcode_success;
988 /*----------------------------------------------------------------
989 * prism2mgmt_autojoin
991 * Associate with an ESS.
994 * wlandev wlan device structure
995 * msgp ptr to msg buffer
999 * <0 success, but we're waiting for something to finish.
1000 * >0 an error occurred while handling the message.
1004 * process thread (usually)
1006 ----------------------------------------------------------------*/
1007 int prism2mgmt_autojoin(wlandevice_t * wlandev, void *msgp)
1009 hfa384x_t *hw = wlandev->priv;
1013 p80211msg_lnxreq_autojoin_t *msg = msgp;
1014 p80211pstrd_t *pstr;
1016 hfa384x_bytestr_t *p2bytestr = (hfa384x_bytestr_t *) bytebuf;
1018 wlandev->macmode = WLAN_MACMODE_NONE;
1021 memcpy(&wlandev->ssid, &msg->ssid.data, sizeof(msg->ssid.data));
1023 /* Disable the Port */
1024 hfa384x_drvr_disable(hw, 0);
1027 /* Set the TxRates */
1028 hfa384x_drvr_setconfig16(hw, HFA384x_RID_TXRATECNTL, 0x000f);
1030 /* Set the auth type */
1031 if (msg->authtype.data == P80211ENUM_authalg_sharedkey)
1032 reg = HFA384x_CNFAUTHENTICATION_SHAREDKEY;
1034 reg = HFA384x_CNFAUTHENTICATION_OPENSYSTEM;
1036 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFAUTHENTICATION, reg);
1039 memset(bytebuf, 0, 256);
1040 pstr = (p80211pstrd_t *) & (msg->ssid.data);
1041 prism2mgmt_pstr2bytestr(p2bytestr, pstr);
1042 result = hfa384x_drvr_setconfig(hw, HFA384x_RID_CNFDESIREDSSID,
1044 HFA384x_RID_CNFDESIREDSSID_LEN);
1045 port_type = HFA384x_PORTTYPE_BSS;
1046 /* Set the PortType */
1047 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFPORTTYPE, port_type);
1049 /* Enable the Port */
1050 hfa384x_drvr_enable(hw, 0);
1052 /* Set the resultcode */
1053 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
1054 msg->resultcode.data = P80211ENUM_resultcode_success;
1059 /*----------------------------------------------------------------
1060 * prism2mgmt_wlansniff
1062 * Start or stop sniffing.
1065 * wlandev wlan device structure
1066 * msgp ptr to msg buffer
1069 * 0 success and done
1070 * <0 success, but we're waiting for something to finish.
1071 * >0 an error occurred while handling the message.
1075 * process thread (usually)
1077 ----------------------------------------------------------------*/
1078 int prism2mgmt_wlansniff(wlandevice_t * wlandev, void *msgp)
1081 p80211msg_lnxreq_wlansniff_t *msg = msgp;
1083 hfa384x_t *hw = wlandev->priv;
1086 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
1087 switch (msg->enable.data) {
1088 case P80211ENUM_truth_false:
1089 /* Confirm that we're in monitor mode */
1090 if (wlandev->netdev->type == ARPHRD_ETHER) {
1091 msg->resultcode.data =
1092 P80211ENUM_resultcode_invalid_parameters;
1096 /* Disable monitor mode */
1097 result = hfa384x_cmd_monitor(hw, HFA384x_MONITOR_DISABLE);
1099 pr_debug("failed to disable monitor mode, result=%d\n",
1103 /* Disable port 0 */
1104 result = hfa384x_drvr_disable(hw, 0);
1107 ("failed to disable port 0 after sniffing, result=%d\n",
1111 /* Clear the driver state */
1112 wlandev->netdev->type = ARPHRD_ETHER;
1114 /* Restore the wepflags */
1115 result = hfa384x_drvr_setconfig16(hw,
1116 HFA384x_RID_CNFWEPFLAGS,
1117 hw->presniff_wepflags);
1120 ("failed to restore wepflags=0x%04x, result=%d\n",
1121 hw->presniff_wepflags, result);
1125 /* Set the port to its prior type and enable (if necessary) */
1126 if (hw->presniff_port_type != 0) {
1127 word = hw->presniff_port_type;
1128 result = hfa384x_drvr_setconfig16(hw,
1129 HFA384x_RID_CNFPORTTYPE,
1133 ("failed to restore porttype, result=%d\n",
1138 /* Enable the port */
1139 result = hfa384x_drvr_enable(hw, 0);
1142 ("failed to enable port to presniff setting, result=%d\n",
1147 result = hfa384x_drvr_disable(hw, 0);
1151 printk(KERN_INFO "monitor mode disabled\n");
1152 msg->resultcode.data = P80211ENUM_resultcode_success;
1156 case P80211ENUM_truth_true:
1157 /* Disable the port (if enabled), only check Port 0 */
1158 if (hw->port_enabled[0]) {
1159 if (wlandev->netdev->type == ARPHRD_ETHER) {
1160 /* Save macport 0 state */
1161 result = hfa384x_drvr_getconfig16(hw,
1162 HFA384x_RID_CNFPORTTYPE,
1165 presniff_port_type));
1168 ("failed to read porttype, result=%d\n",
1172 /* Save the wepflags state */
1173 result = hfa384x_drvr_getconfig16(hw,
1174 HFA384x_RID_CNFWEPFLAGS,
1177 presniff_wepflags));
1180 ("failed to read wepflags, result=%d\n",
1184 hfa384x_drvr_stop(hw);
1185 result = hfa384x_drvr_start(hw);
1188 ("failed to restart the card for sniffing, result=%d\n",
1193 /* Disable the port */
1194 result = hfa384x_drvr_disable(hw, 0);
1197 ("failed to enable port for sniffing, result=%d\n",
1203 hw->presniff_port_type = 0;
1206 /* Set the channel we wish to sniff */
1207 word = msg->channel.data;
1208 result = hfa384x_drvr_setconfig16(hw,
1209 HFA384x_RID_CNFOWNCHANNEL,
1211 hw->sniff_channel = word;
1214 pr_debug("failed to set channel %d, result=%d\n",
1219 /* Now if we're already sniffing, we can skip the rest */
1220 if (wlandev->netdev->type != ARPHRD_ETHER) {
1221 /* Set the port type to pIbss */
1222 word = HFA384x_PORTTYPE_PSUEDOIBSS;
1223 result = hfa384x_drvr_setconfig16(hw,
1224 HFA384x_RID_CNFPORTTYPE,
1228 ("failed to set porttype %d, result=%d\n",
1232 if ((msg->keepwepflags.status ==
1233 P80211ENUM_msgitem_status_data_ok)
1234 && (msg->keepwepflags.data !=
1235 P80211ENUM_truth_true)) {
1236 /* Set the wepflags for no decryption */
1237 word = HFA384x_WEPFLAGS_DISABLE_TXCRYPT |
1238 HFA384x_WEPFLAGS_DISABLE_RXCRYPT;
1240 hfa384x_drvr_setconfig16(hw,
1241 HFA384x_RID_CNFWEPFLAGS,
1247 ("failed to set wepflags=0x%04x, result=%d\n",
1253 /* Do we want to strip the FCS in monitor mode? */
1254 if ((msg->stripfcs.status == P80211ENUM_msgitem_status_data_ok)
1255 && (msg->stripfcs.data == P80211ENUM_truth_true)) {
1261 /* Do we want to truncate the packets? */
1262 if (msg->packet_trunc.status ==
1263 P80211ENUM_msgitem_status_data_ok) {
1264 hw->sniff_truncate = msg->packet_trunc.data;
1266 hw->sniff_truncate = 0;
1269 /* Enable the port */
1270 result = hfa384x_drvr_enable(hw, 0);
1273 ("failed to enable port for sniffing, result=%d\n",
1277 /* Enable monitor mode */
1278 result = hfa384x_cmd_monitor(hw, HFA384x_MONITOR_ENABLE);
1280 pr_debug("failed to enable monitor mode, result=%d\n",
1285 if (wlandev->netdev->type == ARPHRD_ETHER)
1286 printk(KERN_INFO "monitor mode enabled\n");
1288 /* Set the driver state */
1289 /* Do we want the prism2 header? */
1290 if ((msg->prismheader.status ==
1291 P80211ENUM_msgitem_status_data_ok)
1292 && (msg->prismheader.data == P80211ENUM_truth_true)) {
1294 wlandev->netdev->type = ARPHRD_IEEE80211_PRISM;
1296 if ((msg->wlanheader.status ==
1297 P80211ENUM_msgitem_status_data_ok)
1298 && (msg->wlanheader.data == P80211ENUM_truth_true)) {
1300 wlandev->netdev->type = ARPHRD_IEEE80211_PRISM;
1302 wlandev->netdev->type = ARPHRD_IEEE80211;
1305 msg->resultcode.data = P80211ENUM_resultcode_success;
1310 msg->resultcode.data = P80211ENUM_resultcode_invalid_parameters;
1317 msg->resultcode.data = P80211ENUM_resultcode_refused;