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)) {
132 netdev_err(wlandev->netdev,
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 netdev_err(wlandev->netdev,
147 "getconfig(ROAMMODE) failed. result=%d\n", result);
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 netdev_err(wlandev->netdev,
159 "setconfig(ROAMINGMODE) failed. result=%d\n",
161 msg->resultcode.data =
162 P80211ENUM_resultcode_implementation_failure;
166 /* active or passive? */
167 if (HFA384x_FIRMWARE_VERSION(hw->ident_sta_fw.major,
168 hw->ident_sta_fw.minor,
169 hw->ident_sta_fw.variant) >
170 HFA384x_FIRMWARE_VERSION(1, 5, 0)) {
171 if (msg->scantype.data != P80211ENUM_scantype_active)
172 word = cpu_to_le16(msg->maxchanneltime.data);
177 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFPASSIVESCANCTRL,
180 netdev_warn(wlandev->netdev,
181 "Passive scan not supported with current firmware. (<1.5.1)\n");
185 /* set up the txrate to be 2MBPS. Should be fastest basicrate... */
186 word = HFA384x_RATEBIT_2;
187 scanreq.txRate = cpu_to_le16(word);
189 /* set up the channel list */
191 for (i = 0; i < msg->channellist.data.len; i++) {
192 u8 channel = msg->channellist.data.data[i];
196 /* channel 1 is BIT 0 ... channel 14 is BIT 13 */
197 word |= (1 << (channel - 1));
199 scanreq.channelList = cpu_to_le16(word);
201 /* set up the ssid, if present. */
202 scanreq.ssid.len = cpu_to_le16(msg->ssid.data.len);
203 memcpy(scanreq.ssid.data, msg->ssid.data.data, msg->ssid.data.len);
205 /* Enable the MAC port if it's not already enabled */
206 result = hfa384x_drvr_getconfig16(hw, HFA384x_RID_PORTSTATUS, &word);
208 netdev_err(wlandev->netdev,
209 "getconfig(PORTSTATUS) failed. result=%d\n", result);
210 msg->resultcode.data =
211 P80211ENUM_resultcode_implementation_failure;
214 if (word == HFA384x_PORTSTATUS_DISABLED) {
217 result = hfa384x_drvr_setconfig16(hw,
218 HFA384x_RID_CNFROAMINGMODE,
219 HFA384x_ROAMMODE_HOSTSCAN_HOSTROAM);
221 netdev_err(wlandev->netdev,
222 "setconfig(ROAMINGMODE) failed. result=%d\n",
224 msg->resultcode.data =
225 P80211ENUM_resultcode_implementation_failure;
228 /* Construct a bogus SSID and assign it to OwnSSID and
231 wordbuf[0] = cpu_to_le16(WLAN_SSID_MAXLEN);
232 get_random_bytes(&wordbuf[1], WLAN_SSID_MAXLEN);
233 result = hfa384x_drvr_setconfig(hw, HFA384x_RID_CNFOWNSSID,
235 HFA384x_RID_CNFOWNSSID_LEN);
237 netdev_err(wlandev->netdev, "Failed to set OwnSSID.\n");
238 msg->resultcode.data =
239 P80211ENUM_resultcode_implementation_failure;
242 result = hfa384x_drvr_setconfig(hw, HFA384x_RID_CNFDESIREDSSID,
244 HFA384x_RID_CNFDESIREDSSID_LEN);
246 netdev_err(wlandev->netdev,
247 "Failed to set DesiredSSID.\n");
248 msg->resultcode.data =
249 P80211ENUM_resultcode_implementation_failure;
253 result = hfa384x_drvr_setconfig16(hw,
254 HFA384x_RID_CNFPORTTYPE,
255 HFA384x_PORTTYPE_IBSS);
257 netdev_err(wlandev->netdev,
258 "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 netdev_err(wlandev->netdev,
269 "Failed to set CREATEIBSS.\n");
270 msg->resultcode.data =
271 P80211ENUM_resultcode_implementation_failure;
274 result = hfa384x_drvr_enable(hw, 0);
276 netdev_err(wlandev->netdev,
277 "drvr_enable(0) failed. result=%d\n",
279 msg->resultcode.data =
280 P80211ENUM_resultcode_implementation_failure;
286 /* Figure out our timeout first Kus, then HZ */
287 timeout = msg->channellist.data.len * msg->maxchanneltime.data;
288 timeout = (timeout * HZ) / 1000;
290 /* Issue the scan request */
293 result = hfa384x_drvr_setconfig(hw,
294 HFA384x_RID_HOSTSCAN, &scanreq,
295 sizeof(hfa384x_HostScanRequest_data_t));
297 netdev_err(wlandev->netdev,
298 "setconfig(SCANREQUEST) failed. result=%d\n",
300 msg->resultcode.data =
301 P80211ENUM_resultcode_implementation_failure;
305 /* sleep until info frame arrives */
306 wait_event_interruptible_timeout(hw->cmdq, hw->scanflag, timeout);
308 msg->numbss.status = P80211ENUM_msgitem_status_data_ok;
309 if (hw->scanflag == -1)
312 msg->numbss.data = hw->scanflag;
316 /* Disable port if we temporarily enabled it. */
318 result = hfa384x_drvr_disable(hw, 0);
320 netdev_err(wlandev->netdev,
321 "drvr_disable(0) failed. result=%d\n",
323 msg->resultcode.data =
324 P80211ENUM_resultcode_implementation_failure;
329 /* restore original roaming mode */
330 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFROAMINGMODE,
333 netdev_err(wlandev->netdev,
334 "setconfig(ROAMMODE) failed. result=%d\n", result);
335 msg->resultcode.data =
336 P80211ENUM_resultcode_implementation_failure;
341 msg->resultcode.data = P80211ENUM_resultcode_success;
344 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
349 /*----------------------------------------------------------------
350 * prism2mgmt_scan_results
352 * Retrieve the BSS description for one of the BSSs identified in
356 * wlandev wlan device structure
357 * msgp ptr to msg buffer
361 * <0 success, but we're waiting for something to finish.
362 * >0 an error occurred while handling the message.
366 * process thread (usually)
368 ----------------------------------------------------------------*/
369 int prism2mgmt_scan_results(wlandevice_t *wlandev, void *msgp)
372 struct p80211msg_dot11req_scan_results *req;
373 hfa384x_t *hw = wlandev->priv;
374 hfa384x_HScanResultSub_t *item = NULL;
378 req = (struct p80211msg_dot11req_scan_results *) msgp;
380 req->resultcode.status = P80211ENUM_msgitem_status_data_ok;
382 if (!hw->scanresults) {
383 netdev_err(wlandev->netdev,
384 "dot11req_scan_results can only be used after a successful dot11req_scan.\n");
386 req->resultcode.data = P80211ENUM_resultcode_invalid_parameters;
390 count = (hw->scanresults->framelen - 3) / 32;
391 if (count > HFA384x_SCANRESULT_MAX)
392 count = HFA384x_SCANRESULT_MAX;
394 if (req->bssindex.data >= count) {
395 pr_debug("requested index (%d) out of range (%d)\n",
396 req->bssindex.data, count);
398 req->resultcode.data = P80211ENUM_resultcode_invalid_parameters;
402 item = &(hw->scanresults->info.hscanresult.result[req->bssindex.data]);
403 /* signal and noise */
404 req->signal.status = P80211ENUM_msgitem_status_data_ok;
405 req->noise.status = P80211ENUM_msgitem_status_data_ok;
406 req->signal.data = le16_to_cpu(item->sl);
407 req->noise.data = le16_to_cpu(item->anl);
410 req->bssid.status = P80211ENUM_msgitem_status_data_ok;
411 req->bssid.data.len = WLAN_BSSID_LEN;
412 memcpy(req->bssid.data.data, item->bssid, WLAN_BSSID_LEN);
415 req->ssid.status = P80211ENUM_msgitem_status_data_ok;
416 req->ssid.data.len = le16_to_cpu(item->ssid.len);
417 req->ssid.data.len = min_t(u16, req->ssid.data.len, WLAN_SSID_MAXLEN);
418 memcpy(req->ssid.data.data, item->ssid.data, req->ssid.data.len);
420 /* supported rates */
421 for (count = 0; count < 10; count++)
422 if (item->supprates[count] == 0)
425 #define REQBASICRATE(N) \
427 if ((count >= N) && DOT11_RATE5_ISBASIC_GET( \
428 item->supprates[(N)-1])) { \
429 req->basicrate ## N .data = item->supprates[(N)-1]; \
430 req->basicrate ## N .status = \
431 P80211ENUM_msgitem_status_data_ok; \
444 #define REQSUPPRATE(N) \
447 req->supprate ## N .data = item->supprates[(N)-1]; \
448 req->supprate ## N .status = \
449 P80211ENUM_msgitem_status_data_ok; \
463 req->beaconperiod.status = P80211ENUM_msgitem_status_data_ok;
464 req->beaconperiod.data = le16_to_cpu(item->bcnint);
467 req->timestamp.status = P80211ENUM_msgitem_status_data_ok;
468 req->timestamp.data = jiffies;
469 req->localtime.status = P80211ENUM_msgitem_status_data_ok;
470 req->localtime.data = jiffies;
473 req->ibssatimwindow.status = P80211ENUM_msgitem_status_data_ok;
474 req->ibssatimwindow.data = le16_to_cpu(item->atim);
477 req->dschannel.status = P80211ENUM_msgitem_status_data_ok;
478 req->dschannel.data = le16_to_cpu(item->chid);
481 count = le16_to_cpu(item->capinfo);
482 req->capinfo.status = P80211ENUM_msgitem_status_data_ok;
483 req->capinfo.data = count;
486 req->privacy.status = P80211ENUM_msgitem_status_data_ok;
487 req->privacy.data = WLAN_GET_MGMT_CAP_INFO_PRIVACY(count);
490 req->cfpollable.status = P80211ENUM_msgitem_status_data_ok;
491 req->cfpollable.data = WLAN_GET_MGMT_CAP_INFO_CFPOLLABLE(count);
494 req->cfpollreq.status = P80211ENUM_msgitem_status_data_ok;
495 req->cfpollreq.data = WLAN_GET_MGMT_CAP_INFO_CFPOLLREQ(count);
498 req->bsstype.status = P80211ENUM_msgitem_status_data_ok;
499 req->bsstype.data = (WLAN_GET_MGMT_CAP_INFO_ESS(count)) ?
500 P80211ENUM_bsstype_infrastructure : P80211ENUM_bsstype_independent;
503 req->resultcode.data = P80211ENUM_resultcode_success;
509 /*----------------------------------------------------------------
512 * Start a BSS. Any station can do this for IBSS, only AP for ESS.
515 * wlandev wlan device structure
516 * msgp ptr to msg buffer
520 * <0 success, but we're waiting for something to finish.
521 * >0 an error occurred while handling the message.
525 * process thread (usually)
527 ----------------------------------------------------------------*/
528 int prism2mgmt_start(wlandevice_t *wlandev, void *msgp)
531 hfa384x_t *hw = wlandev->priv;
532 struct p80211msg_dot11req_start *msg = msgp;
536 struct hfa384x_bytestr *p2bytestr = (struct hfa384x_bytestr *) bytebuf;
539 wlandev->macmode = WLAN_MACMODE_NONE;
542 memcpy(&wlandev->ssid, &msg->ssid.data, sizeof(msg->ssid.data));
545 /* see if current f/w is less than 8c3 */
546 if (HFA384x_FIRMWARE_VERSION(hw->ident_sta_fw.major,
547 hw->ident_sta_fw.minor,
548 hw->ident_sta_fw.variant) <
549 HFA384x_FIRMWARE_VERSION(0, 8, 3)) {
550 /* Ad-Hoc not quite supported on Prism2 */
551 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
552 msg->resultcode.data = P80211ENUM_resultcode_not_supported;
556 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
559 /* Set the REQUIRED config items */
561 pstr = (p80211pstrd_t *) &(msg->ssid.data);
562 prism2mgmt_pstr2bytestr(p2bytestr, pstr);
563 result = hfa384x_drvr_setconfig(hw, HFA384x_RID_CNFOWNSSID,
564 bytebuf, HFA384x_RID_CNFOWNSSID_LEN);
566 netdev_err(wlandev->netdev, "Failed to set CnfOwnSSID\n");
569 result = hfa384x_drvr_setconfig(hw, HFA384x_RID_CNFDESIREDSSID,
571 HFA384x_RID_CNFDESIREDSSID_LEN);
573 netdev_err(wlandev->netdev, "Failed to set CnfDesiredSSID\n");
577 /* bsstype - we use the default in the ap firmware */
579 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFPORTTYPE, 0);
582 word = msg->beaconperiod.data;
583 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFAPBCNint, word);
585 netdev_err(wlandev->netdev,
586 "Failed to set beacon period=%d.\n", word);
591 word = msg->dschannel.data;
592 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFOWNCHANNEL, word);
594 netdev_err(wlandev->netdev,
595 "Failed to set channel=%d.\n", word);
599 word = p80211rate_to_p2bit(msg->basicrate1.data);
600 if (msg->basicrate2.status == P80211ENUM_msgitem_status_data_ok)
601 word |= p80211rate_to_p2bit(msg->basicrate2.data);
603 if (msg->basicrate3.status == P80211ENUM_msgitem_status_data_ok)
604 word |= p80211rate_to_p2bit(msg->basicrate3.data);
606 if (msg->basicrate4.status == P80211ENUM_msgitem_status_data_ok)
607 word |= p80211rate_to_p2bit(msg->basicrate4.data);
609 if (msg->basicrate5.status == P80211ENUM_msgitem_status_data_ok)
610 word |= p80211rate_to_p2bit(msg->basicrate5.data);
612 if (msg->basicrate6.status == P80211ENUM_msgitem_status_data_ok)
613 word |= p80211rate_to_p2bit(msg->basicrate6.data);
615 if (msg->basicrate7.status == P80211ENUM_msgitem_status_data_ok)
616 word |= p80211rate_to_p2bit(msg->basicrate7.data);
618 if (msg->basicrate8.status == P80211ENUM_msgitem_status_data_ok)
619 word |= p80211rate_to_p2bit(msg->basicrate8.data);
621 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFBASICRATES, word);
623 netdev_err(wlandev->netdev,
624 "Failed to set basicrates=%d.\n", word);
628 /* Operational rates (supprates and txratecontrol) */
629 word = p80211rate_to_p2bit(msg->operationalrate1.data);
630 if (msg->operationalrate2.status == P80211ENUM_msgitem_status_data_ok)
631 word |= p80211rate_to_p2bit(msg->operationalrate2.data);
633 if (msg->operationalrate3.status == P80211ENUM_msgitem_status_data_ok)
634 word |= p80211rate_to_p2bit(msg->operationalrate3.data);
636 if (msg->operationalrate4.status == P80211ENUM_msgitem_status_data_ok)
637 word |= p80211rate_to_p2bit(msg->operationalrate4.data);
639 if (msg->operationalrate5.status == P80211ENUM_msgitem_status_data_ok)
640 word |= p80211rate_to_p2bit(msg->operationalrate5.data);
642 if (msg->operationalrate6.status == P80211ENUM_msgitem_status_data_ok)
643 word |= p80211rate_to_p2bit(msg->operationalrate6.data);
645 if (msg->operationalrate7.status == P80211ENUM_msgitem_status_data_ok)
646 word |= p80211rate_to_p2bit(msg->operationalrate7.data);
648 if (msg->operationalrate8.status == P80211ENUM_msgitem_status_data_ok)
649 word |= p80211rate_to_p2bit(msg->operationalrate8.data);
651 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFSUPPRATES, word);
653 netdev_err(wlandev->netdev,
654 "Failed to set supprates=%d.\n", word);
658 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_TXRATECNTL, word);
660 netdev_err(wlandev->netdev, "Failed to set txrates=%d.\n",
665 /* Set the macmode so the frame setup code knows what to do */
666 if (msg->bsstype.data == P80211ENUM_bsstype_independent) {
667 wlandev->macmode = WLAN_MACMODE_IBSS_STA;
668 /* lets extend the data length a bit */
669 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFMAXDATALEN, 2304);
672 /* Enable the Port */
673 result = hfa384x_drvr_enable(hw, 0);
675 netdev_err(wlandev->netdev,
676 "Enable macport failed, result=%d.\n", result);
680 msg->resultcode.data = P80211ENUM_resultcode_success;
684 pr_debug("Failed to set a config option, result=%d\n", result);
685 msg->resultcode.data = P80211ENUM_resultcode_invalid_parameters;
693 /*----------------------------------------------------------------
696 * Collect the PDA data and put it in the message.
699 * wlandev wlan device structure
700 * msgp ptr to msg buffer
704 * <0 success, but we're waiting for something to finish.
705 * >0 an error occurred while handling the message.
709 * process thread (usually)
710 ----------------------------------------------------------------*/
711 int prism2mgmt_readpda(wlandevice_t *wlandev, void *msgp)
713 hfa384x_t *hw = wlandev->priv;
714 struct p80211msg_p2req_readpda *msg = msgp;
717 /* We only support collecting the PDA when in the FWLOAD
720 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
721 netdev_err(wlandev->netdev,
722 "PDA may only be read in the fwload state.\n");
723 msg->resultcode.data =
724 P80211ENUM_resultcode_implementation_failure;
725 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
727 /* Call drvr_readpda(), it handles the auxport enable
728 * and validating the returned PDA.
730 result = hfa384x_drvr_readpda(hw,
732 HFA384x_PDA_LEN_MAX);
734 netdev_err(wlandev->netdev,
735 "hfa384x_drvr_readpda() failed, result=%d\n",
738 msg->resultcode.data =
739 P80211ENUM_resultcode_implementation_failure;
740 msg->resultcode.status =
741 P80211ENUM_msgitem_status_data_ok;
744 msg->pda.status = P80211ENUM_msgitem_status_data_ok;
745 msg->resultcode.data = P80211ENUM_resultcode_success;
746 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
752 /*----------------------------------------------------------------
753 * prism2mgmt_ramdl_state
755 * Establishes the beginning/end of a card RAM download session.
757 * It is expected that the ramdl_write() function will be called
758 * one or more times between the 'enable' and 'disable' calls to
761 * Note: This function should not be called when a mac comm port
765 * wlandev wlan device structure
766 * msgp ptr to msg buffer
770 * <0 success, but we're waiting for something to finish.
771 * >0 an error occurred while handling the message.
775 * process thread (usually)
776 ----------------------------------------------------------------*/
777 int prism2mgmt_ramdl_state(wlandevice_t *wlandev, void *msgp)
779 hfa384x_t *hw = wlandev->priv;
780 struct p80211msg_p2req_ramdl_state *msg = msgp;
782 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
783 netdev_err(wlandev->netdev,
784 "ramdl_state(): may only be called in the fwload state.\n");
785 msg->resultcode.data =
786 P80211ENUM_resultcode_implementation_failure;
787 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
792 ** Note: Interrupts are locked out if this is an AP and are NOT
793 ** locked out if this is a station.
796 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
797 if (msg->enable.data == P80211ENUM_truth_true) {
798 if (hfa384x_drvr_ramdl_enable(hw, msg->exeaddr.data)) {
799 msg->resultcode.data =
800 P80211ENUM_resultcode_implementation_failure;
802 msg->resultcode.data = P80211ENUM_resultcode_success;
805 hfa384x_drvr_ramdl_disable(hw);
806 msg->resultcode.data = P80211ENUM_resultcode_success;
812 /*----------------------------------------------------------------
813 * prism2mgmt_ramdl_write
815 * Writes a buffer to the card RAM using the download state. This
816 * is for writing code to card RAM. To just read or write raw data
817 * use the aux functions.
820 * wlandev wlan device structure
821 * msgp ptr to msg buffer
825 * <0 success, but we're waiting for something to finish.
826 * >0 an error occurred while handling the message.
830 * process thread (usually)
831 ----------------------------------------------------------------*/
832 int prism2mgmt_ramdl_write(wlandevice_t *wlandev, void *msgp)
834 hfa384x_t *hw = wlandev->priv;
835 struct p80211msg_p2req_ramdl_write *msg = msgp;
840 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
841 netdev_err(wlandev->netdev,
842 "ramdl_write(): may only be called in the fwload state.\n");
843 msg->resultcode.data =
844 P80211ENUM_resultcode_implementation_failure;
845 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
849 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
850 /* first validate the length */
851 if (msg->len.data > sizeof(msg->data.data)) {
852 msg->resultcode.status =
853 P80211ENUM_resultcode_invalid_parameters;
856 /* call the hfa384x function to do the write */
857 addr = msg->addr.data;
859 buf = msg->data.data;
860 if (hfa384x_drvr_ramdl_write(hw, addr, buf, len))
861 msg->resultcode.data = P80211ENUM_resultcode_refused;
863 msg->resultcode.data = P80211ENUM_resultcode_success;
868 /*----------------------------------------------------------------
869 * prism2mgmt_flashdl_state
871 * Establishes the beginning/end of a card Flash download session.
873 * It is expected that the flashdl_write() function will be called
874 * one or more times between the 'enable' and 'disable' calls to
877 * Note: This function should not be called when a mac comm port
881 * wlandev wlan device structure
882 * msgp ptr to msg buffer
886 * <0 success, but we're waiting for something to finish.
887 * >0 an error occurred while handling the message.
891 * process thread (usually)
892 ----------------------------------------------------------------*/
893 int prism2mgmt_flashdl_state(wlandevice_t *wlandev, void *msgp)
896 hfa384x_t *hw = wlandev->priv;
897 struct p80211msg_p2req_flashdl_state *msg = msgp;
899 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
900 netdev_err(wlandev->netdev,
901 "flashdl_state(): may only be called in the fwload state.\n");
902 msg->resultcode.data =
903 P80211ENUM_resultcode_implementation_failure;
904 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
909 ** Note: Interrupts are locked out if this is an AP and are NOT
910 ** locked out if this is a station.
913 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
914 if (msg->enable.data == P80211ENUM_truth_true) {
915 if (hfa384x_drvr_flashdl_enable(hw)) {
916 msg->resultcode.data =
917 P80211ENUM_resultcode_implementation_failure;
919 msg->resultcode.data = P80211ENUM_resultcode_success;
922 hfa384x_drvr_flashdl_disable(hw);
923 msg->resultcode.data = P80211ENUM_resultcode_success;
924 /* NOTE: At this point, the MAC is in the post-reset
925 * state and the driver is in the fwload state.
926 * We need to get the MAC back into the fwload
927 * state. To do this, we set the nsdstate to HWPRESENT
928 * and then call the ifstate function to redo everything
929 * that got us into the fwload state.
931 wlandev->msdstate = WLAN_MSD_HWPRESENT;
932 result = prism2sta_ifstate(wlandev, P80211ENUM_ifstate_fwload);
933 if (result != P80211ENUM_resultcode_success) {
934 netdev_err(wlandev->netdev,
935 "prism2sta_ifstate(fwload) failed, P80211ENUM_resultcode=%d\n",
937 msg->resultcode.data =
938 P80211ENUM_resultcode_implementation_failure;
946 /*----------------------------------------------------------------
947 * prism2mgmt_flashdl_write
952 * wlandev wlan device structure
953 * msgp ptr to msg buffer
957 * <0 success, but we're waiting for something to finish.
958 * >0 an error occurred while handling the message.
962 * process thread (usually)
963 ----------------------------------------------------------------*/
964 int prism2mgmt_flashdl_write(wlandevice_t *wlandev, void *msgp)
966 hfa384x_t *hw = wlandev->priv;
967 struct p80211msg_p2req_flashdl_write *msg = msgp;
972 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
973 netdev_err(wlandev->netdev,
974 "flashdl_write(): may only be called in the fwload state.\n");
975 msg->resultcode.data =
976 P80211ENUM_resultcode_implementation_failure;
977 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
982 ** Note: Interrupts are locked out if this is an AP and are NOT
983 ** locked out if this is a station.
986 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
987 /* first validate the length */
988 if (msg->len.data > sizeof(msg->data.data)) {
989 msg->resultcode.status =
990 P80211ENUM_resultcode_invalid_parameters;
993 /* call the hfa384x function to do the write */
994 addr = msg->addr.data;
996 buf = msg->data.data;
997 if (hfa384x_drvr_flashdl_write(hw, addr, buf, len))
998 msg->resultcode.data = P80211ENUM_resultcode_refused;
1000 msg->resultcode.data = P80211ENUM_resultcode_success;
1005 /*----------------------------------------------------------------
1006 * prism2mgmt_autojoin
1008 * Associate with an ESS.
1011 * wlandev wlan device structure
1012 * msgp ptr to msg buffer
1015 * 0 success and done
1016 * <0 success, but we're waiting for something to finish.
1017 * >0 an error occurred while handling the message.
1021 * process thread (usually)
1023 ----------------------------------------------------------------*/
1024 int prism2mgmt_autojoin(wlandevice_t *wlandev, void *msgp)
1026 hfa384x_t *hw = wlandev->priv;
1030 struct p80211msg_lnxreq_autojoin *msg = msgp;
1031 p80211pstrd_t *pstr;
1033 struct hfa384x_bytestr *p2bytestr = (struct hfa384x_bytestr *) bytebuf;
1035 wlandev->macmode = WLAN_MACMODE_NONE;
1038 memcpy(&wlandev->ssid, &msg->ssid.data, sizeof(msg->ssid.data));
1040 /* Disable the Port */
1041 hfa384x_drvr_disable(hw, 0);
1044 /* Set the TxRates */
1045 hfa384x_drvr_setconfig16(hw, HFA384x_RID_TXRATECNTL, 0x000f);
1047 /* Set the auth type */
1048 if (msg->authtype.data == P80211ENUM_authalg_sharedkey)
1049 reg = HFA384x_CNFAUTHENTICATION_SHAREDKEY;
1051 reg = HFA384x_CNFAUTHENTICATION_OPENSYSTEM;
1053 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFAUTHENTICATION, reg);
1056 memset(bytebuf, 0, 256);
1057 pstr = (p80211pstrd_t *) &(msg->ssid.data);
1058 prism2mgmt_pstr2bytestr(p2bytestr, pstr);
1059 result = hfa384x_drvr_setconfig(hw, HFA384x_RID_CNFDESIREDSSID,
1061 HFA384x_RID_CNFDESIREDSSID_LEN);
1062 port_type = HFA384x_PORTTYPE_BSS;
1063 /* Set the PortType */
1064 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFPORTTYPE, port_type);
1066 /* Enable the Port */
1067 hfa384x_drvr_enable(hw, 0);
1069 /* Set the resultcode */
1070 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
1071 msg->resultcode.data = P80211ENUM_resultcode_success;
1076 /*----------------------------------------------------------------
1077 * prism2mgmt_wlansniff
1079 * Start or stop sniffing.
1082 * wlandev wlan device structure
1083 * msgp ptr to msg buffer
1086 * 0 success and done
1087 * <0 success, but we're waiting for something to finish.
1088 * >0 an error occurred while handling the message.
1092 * process thread (usually)
1094 ----------------------------------------------------------------*/
1095 int prism2mgmt_wlansniff(wlandevice_t *wlandev, void *msgp)
1098 struct p80211msg_lnxreq_wlansniff *msg = msgp;
1100 hfa384x_t *hw = wlandev->priv;
1103 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
1104 switch (msg->enable.data) {
1105 case P80211ENUM_truth_false:
1106 /* Confirm that we're in monitor mode */
1107 if (wlandev->netdev->type == ARPHRD_ETHER) {
1108 msg->resultcode.data =
1109 P80211ENUM_resultcode_invalid_parameters;
1112 /* Disable monitor mode */
1113 result = hfa384x_cmd_monitor(hw, HFA384x_MONITOR_DISABLE);
1115 pr_debug("failed to disable monitor mode, result=%d\n",
1119 /* Disable port 0 */
1120 result = hfa384x_drvr_disable(hw, 0);
1123 ("failed to disable port 0 after sniffing, result=%d\n",
1127 /* Clear the driver state */
1128 wlandev->netdev->type = ARPHRD_ETHER;
1130 /* Restore the wepflags */
1131 result = hfa384x_drvr_setconfig16(hw,
1132 HFA384x_RID_CNFWEPFLAGS,
1133 hw->presniff_wepflags);
1136 ("failed to restore wepflags=0x%04x, result=%d\n",
1137 hw->presniff_wepflags, result);
1141 /* Set the port to its prior type and enable (if necessary) */
1142 if (hw->presniff_port_type != 0) {
1143 word = hw->presniff_port_type;
1144 result = hfa384x_drvr_setconfig16(hw,
1145 HFA384x_RID_CNFPORTTYPE,
1149 ("failed to restore porttype, result=%d\n",
1154 /* Enable the port */
1155 result = hfa384x_drvr_enable(hw, 0);
1157 pr_debug("failed to enable port to presniff setting, result=%d\n",
1162 result = hfa384x_drvr_disable(hw, 0);
1166 netdev_info(wlandev->netdev, "monitor mode disabled\n");
1167 msg->resultcode.data = P80211ENUM_resultcode_success;
1169 case P80211ENUM_truth_true:
1170 /* Disable the port (if enabled), only check Port 0 */
1171 if (hw->port_enabled[0]) {
1172 if (wlandev->netdev->type == ARPHRD_ETHER) {
1173 /* Save macport 0 state */
1174 result = hfa384x_drvr_getconfig16(hw,
1175 HFA384x_RID_CNFPORTTYPE,
1176 &(hw->presniff_port_type));
1179 ("failed to read porttype, result=%d\n",
1183 /* Save the wepflags state */
1184 result = hfa384x_drvr_getconfig16(hw,
1185 HFA384x_RID_CNFWEPFLAGS,
1186 &(hw->presniff_wepflags));
1189 ("failed to read wepflags, result=%d\n",
1193 hfa384x_drvr_stop(hw);
1194 result = hfa384x_drvr_start(hw);
1196 pr_debug("failed to restart the card for sniffing, result=%d\n",
1201 /* Disable the port */
1202 result = hfa384x_drvr_disable(hw, 0);
1204 pr_debug("failed to enable port for sniffing, result=%d\n",
1210 hw->presniff_port_type = 0;
1213 /* Set the channel we wish to sniff */
1214 word = msg->channel.data;
1215 result = hfa384x_drvr_setconfig16(hw,
1216 HFA384x_RID_CNFOWNCHANNEL,
1218 hw->sniff_channel = word;
1221 pr_debug("failed to set channel %d, result=%d\n",
1226 /* Now if we're already sniffing, we can skip the rest */
1227 if (wlandev->netdev->type != ARPHRD_ETHER) {
1228 /* Set the port type to pIbss */
1229 word = HFA384x_PORTTYPE_PSUEDOIBSS;
1230 result = hfa384x_drvr_setconfig16(hw,
1231 HFA384x_RID_CNFPORTTYPE,
1235 ("failed to set porttype %d, result=%d\n",
1239 if ((msg->keepwepflags.status ==
1240 P80211ENUM_msgitem_status_data_ok)
1241 && (msg->keepwepflags.data !=
1242 P80211ENUM_truth_true)) {
1243 /* Set the wepflags for no decryption */
1244 word = HFA384x_WEPFLAGS_DISABLE_TXCRYPT |
1245 HFA384x_WEPFLAGS_DISABLE_RXCRYPT;
1247 hfa384x_drvr_setconfig16(hw,
1248 HFA384x_RID_CNFWEPFLAGS,
1254 ("failed to set wepflags=0x%04x, result=%d\n",
1260 /* Do we want to strip the FCS in monitor mode? */
1261 if ((msg->stripfcs.status == P80211ENUM_msgitem_status_data_ok)
1262 && (msg->stripfcs.data == P80211ENUM_truth_true)) {
1268 /* Do we want to truncate the packets? */
1269 if (msg->packet_trunc.status ==
1270 P80211ENUM_msgitem_status_data_ok) {
1271 hw->sniff_truncate = msg->packet_trunc.data;
1273 hw->sniff_truncate = 0;
1276 /* Enable the port */
1277 result = hfa384x_drvr_enable(hw, 0);
1280 ("failed to enable port for sniffing, result=%d\n",
1284 /* Enable monitor mode */
1285 result = hfa384x_cmd_monitor(hw, HFA384x_MONITOR_ENABLE);
1287 pr_debug("failed to enable monitor mode, result=%d\n",
1292 if (wlandev->netdev->type == ARPHRD_ETHER)
1293 netdev_info(wlandev->netdev, "monitor mode enabled\n");
1295 /* Set the driver state */
1296 /* Do we want the prism2 header? */
1297 if ((msg->prismheader.status ==
1298 P80211ENUM_msgitem_status_data_ok)
1299 && (msg->prismheader.data == P80211ENUM_truth_true)) {
1301 wlandev->netdev->type = ARPHRD_IEEE80211_PRISM;
1303 if ((msg->wlanheader.status ==
1304 P80211ENUM_msgitem_status_data_ok)
1305 && (msg->wlanheader.data == P80211ENUM_truth_true)) {
1307 wlandev->netdev->type = ARPHRD_IEEE80211_PRISM;
1309 wlandev->netdev->type = ARPHRD_IEEE80211;
1312 msg->resultcode.data = P80211ENUM_resultcode_success;
1315 msg->resultcode.data = P80211ENUM_resultcode_invalid_parameters;
1320 msg->resultcode.data = P80211ENUM_resultcode_refused;