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", result);
160 msg->resultcode.data =
161 P80211ENUM_resultcode_implementation_failure;
165 /* active or passive? */
166 if (HFA384x_FIRMWARE_VERSION(hw->ident_sta_fw.major,
167 hw->ident_sta_fw.minor,
168 hw->ident_sta_fw.variant) >
169 HFA384x_FIRMWARE_VERSION(1, 5, 0)) {
170 if (msg->scantype.data != P80211ENUM_scantype_active)
171 word = cpu_to_le16(msg->maxchanneltime.data);
176 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFPASSIVESCANCTRL,
179 netdev_warn(wlandev->netdev,
180 "Passive scan not supported with "
181 "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];
195 /* channel 1 is BIT 0 ... channel 14 is BIT 13 */
196 word |= (1 << (channel - 1));
198 scanreq.channelList = cpu_to_le16(word);
200 /* set up the ssid, if present. */
201 scanreq.ssid.len = cpu_to_le16(msg->ssid.data.len);
202 memcpy(scanreq.ssid.data, msg->ssid.data.data, msg->ssid.data.len);
204 /* Enable the MAC port if it's not already enabled */
205 result = hfa384x_drvr_getconfig16(hw, HFA384x_RID_PORTSTATUS, &word);
207 netdev_err(wlandev->netdev,
208 "getconfig(PORTSTATUS) failed. result=%d\n", result);
209 msg->resultcode.data =
210 P80211ENUM_resultcode_implementation_failure;
213 if (word == HFA384x_PORTSTATUS_DISABLED) {
216 result = hfa384x_drvr_setconfig16(hw,
217 HFA384x_RID_CNFROAMINGMODE,
218 HFA384x_ROAMMODE_HOSTSCAN_HOSTROAM);
220 netdev_err(wlandev->netdev,
221 "setconfig(ROAMINGMODE) failed. result=%d\n",
223 msg->resultcode.data =
224 P80211ENUM_resultcode_implementation_failure;
227 /* Construct a bogus SSID and assign it to OwnSSID and
230 wordbuf[0] = cpu_to_le16(WLAN_SSID_MAXLEN);
231 get_random_bytes(&wordbuf[1], WLAN_SSID_MAXLEN);
232 result = hfa384x_drvr_setconfig(hw, HFA384x_RID_CNFOWNSSID,
234 HFA384x_RID_CNFOWNSSID_LEN);
236 netdev_err(wlandev->netdev, "Failed to set OwnSSID.\n");
237 msg->resultcode.data =
238 P80211ENUM_resultcode_implementation_failure;
241 result = hfa384x_drvr_setconfig(hw, HFA384x_RID_CNFDESIREDSSID,
243 HFA384x_RID_CNFDESIREDSSID_LEN);
245 netdev_err(wlandev->netdev,
246 "Failed to set DesiredSSID.\n");
247 msg->resultcode.data =
248 P80211ENUM_resultcode_implementation_failure;
252 result = hfa384x_drvr_setconfig16(hw,
253 HFA384x_RID_CNFPORTTYPE,
254 HFA384x_PORTTYPE_IBSS);
256 netdev_err(wlandev->netdev,
257 "Failed to set CNFPORTTYPE.\n");
258 msg->resultcode.data =
259 P80211ENUM_resultcode_implementation_failure;
263 result = hfa384x_drvr_setconfig16(hw,
264 HFA384x_RID_CREATEIBSS,
265 HFA384x_CREATEIBSS_JOINCREATEIBSS);
267 netdev_err(wlandev->netdev,
268 "Failed to set CREATEIBSS.\n");
269 msg->resultcode.data =
270 P80211ENUM_resultcode_implementation_failure;
273 result = hfa384x_drvr_enable(hw, 0);
275 netdev_err(wlandev->netdev,
276 "drvr_enable(0) failed. 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 netdev_err(wlandev->netdev,
296 "setconfig(SCANREQUEST) failed. result=%d\n", result);
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 netdev_err(wlandev->netdev,
318 "drvr_disable(0) failed. 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 netdev_err(wlandev->netdev,
330 "setconfig(ROAMMODE) failed. result=%d\n", result);
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 struct p80211msg_dot11req_scan_results *req;
369 hfa384x_t *hw = wlandev->priv;
370 hfa384x_HScanResultSub_t *item = NULL;
374 req = (struct p80211msg_dot11req_scan_results *) msgp;
376 req->resultcode.status = P80211ENUM_msgitem_status_data_ok;
378 if (!hw->scanresults) {
379 netdev_err(wlandev->netdev,
380 "dot11req_scan_results can only be used after "
381 "a successful dot11req_scan.\n");
383 req->resultcode.data = P80211ENUM_resultcode_invalid_parameters;
387 count = (hw->scanresults->framelen - 3) / 32;
388 if (count > HFA384x_SCANRESULT_MAX)
389 count = HFA384x_SCANRESULT_MAX;
391 if (req->bssindex.data >= count) {
392 pr_debug("requested index (%d) out of range (%d)\n",
393 req->bssindex.data, count);
395 req->resultcode.data = P80211ENUM_resultcode_invalid_parameters;
399 item = &(hw->scanresults->info.hscanresult.result[req->bssindex.data]);
400 /* signal and noise */
401 req->signal.status = P80211ENUM_msgitem_status_data_ok;
402 req->noise.status = P80211ENUM_msgitem_status_data_ok;
403 req->signal.data = le16_to_cpu(item->sl);
404 req->noise.data = le16_to_cpu(item->anl);
407 req->bssid.status = P80211ENUM_msgitem_status_data_ok;
408 req->bssid.data.len = WLAN_BSSID_LEN;
409 memcpy(req->bssid.data.data, item->bssid, WLAN_BSSID_LEN);
412 req->ssid.status = P80211ENUM_msgitem_status_data_ok;
413 req->ssid.data.len = le16_to_cpu(item->ssid.len);
414 req->ssid.data.len = min_t(u16, req->ssid.data.len, WLAN_SSID_MAXLEN);
415 memcpy(req->ssid.data.data, item->ssid.data, req->ssid.data.len);
417 /* supported rates */
418 for (count = 0; count < 10; count++)
419 if (item->supprates[count] == 0)
422 #define REQBASICRATE(N) \
424 if ((count >= N) && DOT11_RATE5_ISBASIC_GET( \
425 item->supprates[(N)-1])) { \
426 req->basicrate ## N .data = item->supprates[(N)-1]; \
427 req->basicrate ## N .status = \
428 P80211ENUM_msgitem_status_data_ok; \
441 #define REQSUPPRATE(N) \
444 req->supprate ## N .data = item->supprates[(N)-1]; \
445 req->supprate ## N .status = \
446 P80211ENUM_msgitem_status_data_ok; \
460 req->beaconperiod.status = P80211ENUM_msgitem_status_data_ok;
461 req->beaconperiod.data = le16_to_cpu(item->bcnint);
464 req->timestamp.status = P80211ENUM_msgitem_status_data_ok;
465 req->timestamp.data = jiffies;
466 req->localtime.status = P80211ENUM_msgitem_status_data_ok;
467 req->localtime.data = jiffies;
470 req->ibssatimwindow.status = P80211ENUM_msgitem_status_data_ok;
471 req->ibssatimwindow.data = le16_to_cpu(item->atim);
474 req->dschannel.status = P80211ENUM_msgitem_status_data_ok;
475 req->dschannel.data = le16_to_cpu(item->chid);
478 count = le16_to_cpu(item->capinfo);
479 req->capinfo.status = P80211ENUM_msgitem_status_data_ok;
480 req->capinfo.data = count;
483 req->privacy.status = P80211ENUM_msgitem_status_data_ok;
484 req->privacy.data = WLAN_GET_MGMT_CAP_INFO_PRIVACY(count);
487 req->cfpollable.status = P80211ENUM_msgitem_status_data_ok;
488 req->cfpollable.data = WLAN_GET_MGMT_CAP_INFO_CFPOLLABLE(count);
491 req->cfpollreq.status = P80211ENUM_msgitem_status_data_ok;
492 req->cfpollreq.data = WLAN_GET_MGMT_CAP_INFO_CFPOLLREQ(count);
495 req->bsstype.status = P80211ENUM_msgitem_status_data_ok;
496 req->bsstype.data = (WLAN_GET_MGMT_CAP_INFO_ESS(count)) ?
497 P80211ENUM_bsstype_infrastructure : P80211ENUM_bsstype_independent;
500 req->resultcode.data = P80211ENUM_resultcode_success;
506 /*----------------------------------------------------------------
509 * Start a BSS. Any station can do this for IBSS, only AP for ESS.
512 * wlandev wlan device structure
513 * msgp ptr to msg buffer
517 * <0 success, but we're waiting for something to finish.
518 * >0 an error occurred while handling the message.
522 * process thread (usually)
524 ----------------------------------------------------------------*/
525 int prism2mgmt_start(wlandevice_t *wlandev, void *msgp)
528 hfa384x_t *hw = wlandev->priv;
529 struct p80211msg_dot11req_start *msg = msgp;
533 struct hfa384x_bytestr *p2bytestr = (struct hfa384x_bytestr *) bytebuf;
536 wlandev->macmode = WLAN_MACMODE_NONE;
539 memcpy(&wlandev->ssid, &msg->ssid.data, sizeof(msg->ssid.data));
542 /* see if current f/w is less than 8c3 */
543 if (HFA384x_FIRMWARE_VERSION(hw->ident_sta_fw.major,
544 hw->ident_sta_fw.minor,
545 hw->ident_sta_fw.variant) <
546 HFA384x_FIRMWARE_VERSION(0, 8, 3)) {
547 /* Ad-Hoc not quite supported on Prism2 */
548 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
549 msg->resultcode.data = P80211ENUM_resultcode_not_supported;
553 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
556 /* Set the REQUIRED config items */
558 pstr = (p80211pstrd_t *) &(msg->ssid.data);
559 prism2mgmt_pstr2bytestr(p2bytestr, pstr);
560 result = hfa384x_drvr_setconfig(hw, HFA384x_RID_CNFOWNSSID,
561 bytebuf, HFA384x_RID_CNFOWNSSID_LEN);
563 netdev_err(wlandev->netdev, "Failed to set CnfOwnSSID\n");
566 result = hfa384x_drvr_setconfig(hw, HFA384x_RID_CNFDESIREDSSID,
568 HFA384x_RID_CNFDESIREDSSID_LEN);
570 netdev_err(wlandev->netdev, "Failed to set CnfDesiredSSID\n");
574 /* bsstype - we use the default in the ap firmware */
576 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFPORTTYPE, 0);
579 word = msg->beaconperiod.data;
580 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFAPBCNint, word);
582 netdev_err(wlandev->netdev,
583 "Failed to set beacon period=%d.\n", word);
588 word = msg->dschannel.data;
589 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFOWNCHANNEL, word);
591 netdev_err(wlandev->netdev,
592 "Failed to set channel=%d.\n", word);
596 word = p80211rate_to_p2bit(msg->basicrate1.data);
597 if (msg->basicrate2.status == P80211ENUM_msgitem_status_data_ok)
598 word |= p80211rate_to_p2bit(msg->basicrate2.data);
600 if (msg->basicrate3.status == P80211ENUM_msgitem_status_data_ok)
601 word |= p80211rate_to_p2bit(msg->basicrate3.data);
603 if (msg->basicrate4.status == P80211ENUM_msgitem_status_data_ok)
604 word |= p80211rate_to_p2bit(msg->basicrate4.data);
606 if (msg->basicrate5.status == P80211ENUM_msgitem_status_data_ok)
607 word |= p80211rate_to_p2bit(msg->basicrate5.data);
609 if (msg->basicrate6.status == P80211ENUM_msgitem_status_data_ok)
610 word |= p80211rate_to_p2bit(msg->basicrate6.data);
612 if (msg->basicrate7.status == P80211ENUM_msgitem_status_data_ok)
613 word |= p80211rate_to_p2bit(msg->basicrate7.data);
615 if (msg->basicrate8.status == P80211ENUM_msgitem_status_data_ok)
616 word |= p80211rate_to_p2bit(msg->basicrate8.data);
618 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFBASICRATES, word);
620 netdev_err(wlandev->netdev,
621 "Failed to set basicrates=%d.\n", word);
625 /* Operational rates (supprates and txratecontrol) */
626 word = p80211rate_to_p2bit(msg->operationalrate1.data);
627 if (msg->operationalrate2.status == P80211ENUM_msgitem_status_data_ok)
628 word |= p80211rate_to_p2bit(msg->operationalrate2.data);
630 if (msg->operationalrate3.status == P80211ENUM_msgitem_status_data_ok)
631 word |= p80211rate_to_p2bit(msg->operationalrate3.data);
633 if (msg->operationalrate4.status == P80211ENUM_msgitem_status_data_ok)
634 word |= p80211rate_to_p2bit(msg->operationalrate4.data);
636 if (msg->operationalrate5.status == P80211ENUM_msgitem_status_data_ok)
637 word |= p80211rate_to_p2bit(msg->operationalrate5.data);
639 if (msg->operationalrate6.status == P80211ENUM_msgitem_status_data_ok)
640 word |= p80211rate_to_p2bit(msg->operationalrate6.data);
642 if (msg->operationalrate7.status == P80211ENUM_msgitem_status_data_ok)
643 word |= p80211rate_to_p2bit(msg->operationalrate7.data);
645 if (msg->operationalrate8.status == P80211ENUM_msgitem_status_data_ok)
646 word |= p80211rate_to_p2bit(msg->operationalrate8.data);
648 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFSUPPRATES, word);
650 netdev_err(wlandev->netdev,
651 "Failed to set supprates=%d.\n", word);
655 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_TXRATECNTL, word);
657 netdev_err(wlandev->netdev, "Failed to set txrates=%d.\n", word);
661 /* Set the macmode so the frame setup code knows what to do */
662 if (msg->bsstype.data == P80211ENUM_bsstype_independent) {
663 wlandev->macmode = WLAN_MACMODE_IBSS_STA;
664 /* lets extend the data length a bit */
665 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFMAXDATALEN, 2304);
668 /* Enable the Port */
669 result = hfa384x_drvr_enable(hw, 0);
671 netdev_err(wlandev->netdev,
672 "Enable macport failed, result=%d.\n", result);
676 msg->resultcode.data = P80211ENUM_resultcode_success;
680 pr_debug("Failed to set a config option, result=%d\n", result);
681 msg->resultcode.data = P80211ENUM_resultcode_invalid_parameters;
689 /*----------------------------------------------------------------
692 * Collect the PDA data and put it in the message.
695 * wlandev wlan device structure
696 * msgp ptr to msg buffer
700 * <0 success, but we're waiting for something to finish.
701 * >0 an error occurred while handling the message.
705 * process thread (usually)
706 ----------------------------------------------------------------*/
707 int prism2mgmt_readpda(wlandevice_t *wlandev, void *msgp)
709 hfa384x_t *hw = wlandev->priv;
710 struct p80211msg_p2req_readpda *msg = msgp;
713 /* We only support collecting the PDA when in the FWLOAD
716 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
717 netdev_err(wlandev->netdev,
718 "PDA may only be read in the fwload state.\n");
719 msg->resultcode.data =
720 P80211ENUM_resultcode_implementation_failure;
721 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
723 /* Call drvr_readpda(), it handles the auxport enable
724 * and validating the returned PDA.
726 result = hfa384x_drvr_readpda(hw,
728 HFA384x_PDA_LEN_MAX);
730 netdev_err(wlandev->netdev,
731 "hfa384x_drvr_readpda() failed, "
732 "result=%d\n", result);
734 msg->resultcode.data =
735 P80211ENUM_resultcode_implementation_failure;
736 msg->resultcode.status =
737 P80211ENUM_msgitem_status_data_ok;
740 msg->pda.status = P80211ENUM_msgitem_status_data_ok;
741 msg->resultcode.data = P80211ENUM_resultcode_success;
742 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
748 /*----------------------------------------------------------------
749 * prism2mgmt_ramdl_state
751 * Establishes the beginning/end of a card RAM download session.
753 * It is expected that the ramdl_write() function will be called
754 * one or more times between the 'enable' and 'disable' calls to
757 * Note: This function should not be called when a mac comm port
761 * wlandev wlan device structure
762 * msgp ptr to msg buffer
766 * <0 success, but we're waiting for something to finish.
767 * >0 an error occurred while handling the message.
771 * process thread (usually)
772 ----------------------------------------------------------------*/
773 int prism2mgmt_ramdl_state(wlandevice_t *wlandev, void *msgp)
775 hfa384x_t *hw = wlandev->priv;
776 struct p80211msg_p2req_ramdl_state *msg = msgp;
778 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
779 netdev_err(wlandev->netdev,
780 "ramdl_state(): may only be called "
781 "in the fwload state.\n");
782 msg->resultcode.data =
783 P80211ENUM_resultcode_implementation_failure;
784 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
789 ** Note: Interrupts are locked out if this is an AP and are NOT
790 ** locked out if this is a station.
793 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
794 if (msg->enable.data == P80211ENUM_truth_true) {
795 if (hfa384x_drvr_ramdl_enable(hw, msg->exeaddr.data)) {
796 msg->resultcode.data =
797 P80211ENUM_resultcode_implementation_failure;
799 msg->resultcode.data = P80211ENUM_resultcode_success;
802 hfa384x_drvr_ramdl_disable(hw);
803 msg->resultcode.data = P80211ENUM_resultcode_success;
809 /*----------------------------------------------------------------
810 * prism2mgmt_ramdl_write
812 * Writes a buffer to the card RAM using the download state. This
813 * is for writing code to card RAM. To just read or write raw data
814 * use the aux functions.
817 * wlandev wlan device structure
818 * msgp ptr to msg buffer
822 * <0 success, but we're waiting for something to finish.
823 * >0 an error occurred while handling the message.
827 * process thread (usually)
828 ----------------------------------------------------------------*/
829 int prism2mgmt_ramdl_write(wlandevice_t *wlandev, void *msgp)
831 hfa384x_t *hw = wlandev->priv;
832 struct p80211msg_p2req_ramdl_write *msg = msgp;
837 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
838 netdev_err(wlandev->netdev,
839 "ramdl_write(): may only be called "
840 "in the fwload state.\n");
841 msg->resultcode.data =
842 P80211ENUM_resultcode_implementation_failure;
843 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
847 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
848 /* first validate the length */
849 if (msg->len.data > sizeof(msg->data.data)) {
850 msg->resultcode.status =
851 P80211ENUM_resultcode_invalid_parameters;
854 /* call the hfa384x function to do the write */
855 addr = msg->addr.data;
857 buf = msg->data.data;
858 if (hfa384x_drvr_ramdl_write(hw, addr, buf, len))
859 msg->resultcode.data = P80211ENUM_resultcode_refused;
861 msg->resultcode.data = P80211ENUM_resultcode_success;
866 /*----------------------------------------------------------------
867 * prism2mgmt_flashdl_state
869 * Establishes the beginning/end of a card Flash download session.
871 * It is expected that the flashdl_write() function will be called
872 * one or more times between the 'enable' and 'disable' calls to
875 * Note: This function should not be called when a mac comm port
879 * wlandev wlan device structure
880 * msgp ptr to msg buffer
884 * <0 success, but we're waiting for something to finish.
885 * >0 an error occurred while handling the message.
889 * process thread (usually)
890 ----------------------------------------------------------------*/
891 int prism2mgmt_flashdl_state(wlandevice_t *wlandev, void *msgp)
894 hfa384x_t *hw = wlandev->priv;
895 struct p80211msg_p2req_flashdl_state *msg = msgp;
897 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
898 netdev_err(wlandev->netdev,
899 "flashdl_state(): may only be called "
900 "in the fwload state.\n");
901 msg->resultcode.data =
902 P80211ENUM_resultcode_implementation_failure;
903 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
908 ** Note: Interrupts are locked out if this is an AP and are NOT
909 ** locked out if this is a station.
912 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
913 if (msg->enable.data == P80211ENUM_truth_true) {
914 if (hfa384x_drvr_flashdl_enable(hw)) {
915 msg->resultcode.data =
916 P80211ENUM_resultcode_implementation_failure;
918 msg->resultcode.data = P80211ENUM_resultcode_success;
921 hfa384x_drvr_flashdl_disable(hw);
922 msg->resultcode.data = P80211ENUM_resultcode_success;
923 /* NOTE: At this point, the MAC is in the post-reset
924 * state and the driver is in the fwload state.
925 * We need to get the MAC back into the fwload
926 * state. To do this, we set the nsdstate to HWPRESENT
927 * and then call the ifstate function to redo everything
928 * that got us into the fwload state.
930 wlandev->msdstate = WLAN_MSD_HWPRESENT;
931 result = prism2sta_ifstate(wlandev, P80211ENUM_ifstate_fwload);
932 if (result != P80211ENUM_resultcode_success) {
933 netdev_err(wlandev->netdev,
934 "prism2sta_ifstate(fwload) failed,"
935 "P80211ENUM_resultcode=%d\n", result);
936 msg->resultcode.data =
937 P80211ENUM_resultcode_implementation_failure;
945 /*----------------------------------------------------------------
946 * prism2mgmt_flashdl_write
951 * wlandev wlan device structure
952 * msgp ptr to msg buffer
956 * <0 success, but we're waiting for something to finish.
957 * >0 an error occurred while handling the message.
961 * process thread (usually)
962 ----------------------------------------------------------------*/
963 int prism2mgmt_flashdl_write(wlandevice_t *wlandev, void *msgp)
965 hfa384x_t *hw = wlandev->priv;
966 struct p80211msg_p2req_flashdl_write *msg = msgp;
971 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
972 netdev_err(wlandev->netdev,
973 "flashdl_write(): may only be called "
974 "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;
1113 /* Disable monitor mode */
1114 result = hfa384x_cmd_monitor(hw, HFA384x_MONITOR_DISABLE);
1116 pr_debug("failed to disable monitor mode, result=%d\n",
1120 /* Disable port 0 */
1121 result = hfa384x_drvr_disable(hw, 0);
1124 ("failed to disable port 0 after sniffing, result=%d\n",
1128 /* Clear the driver state */
1129 wlandev->netdev->type = ARPHRD_ETHER;
1131 /* Restore the wepflags */
1132 result = hfa384x_drvr_setconfig16(hw,
1133 HFA384x_RID_CNFWEPFLAGS,
1134 hw->presniff_wepflags);
1137 ("failed to restore wepflags=0x%04x, result=%d\n",
1138 hw->presniff_wepflags, result);
1142 /* Set the port to its prior type and enable (if necessary) */
1143 if (hw->presniff_port_type != 0) {
1144 word = hw->presniff_port_type;
1145 result = hfa384x_drvr_setconfig16(hw,
1146 HFA384x_RID_CNFPORTTYPE,
1150 ("failed to restore porttype, result=%d\n",
1155 /* Enable the port */
1156 result = hfa384x_drvr_enable(hw, 0);
1158 pr_debug("failed to enable port to presniff setting, result=%d\n",
1163 result = hfa384x_drvr_disable(hw, 0);
1167 netdev_info(wlandev->netdev, "monitor mode disabled\n");
1168 msg->resultcode.data = P80211ENUM_resultcode_success;
1172 case P80211ENUM_truth_true:
1173 /* Disable the port (if enabled), only check Port 0 */
1174 if (hw->port_enabled[0]) {
1175 if (wlandev->netdev->type == ARPHRD_ETHER) {
1176 /* Save macport 0 state */
1177 result = hfa384x_drvr_getconfig16(hw,
1178 HFA384x_RID_CNFPORTTYPE,
1179 &(hw->presniff_port_type));
1182 ("failed to read porttype, result=%d\n",
1186 /* Save the wepflags state */
1187 result = hfa384x_drvr_getconfig16(hw,
1188 HFA384x_RID_CNFWEPFLAGS,
1189 &(hw->presniff_wepflags));
1192 ("failed to read wepflags, result=%d\n",
1196 hfa384x_drvr_stop(hw);
1197 result = hfa384x_drvr_start(hw);
1199 pr_debug("failed to restart the card for sniffing, result=%d\n",
1204 /* Disable the port */
1205 result = hfa384x_drvr_disable(hw, 0);
1207 pr_debug("failed to enable port for sniffing, result=%d\n",
1213 hw->presniff_port_type = 0;
1216 /* Set the channel we wish to sniff */
1217 word = msg->channel.data;
1218 result = hfa384x_drvr_setconfig16(hw,
1219 HFA384x_RID_CNFOWNCHANNEL,
1221 hw->sniff_channel = word;
1224 pr_debug("failed to set channel %d, result=%d\n",
1229 /* Now if we're already sniffing, we can skip the rest */
1230 if (wlandev->netdev->type != ARPHRD_ETHER) {
1231 /* Set the port type to pIbss */
1232 word = HFA384x_PORTTYPE_PSUEDOIBSS;
1233 result = hfa384x_drvr_setconfig16(hw,
1234 HFA384x_RID_CNFPORTTYPE,
1238 ("failed to set porttype %d, result=%d\n",
1242 if ((msg->keepwepflags.status ==
1243 P80211ENUM_msgitem_status_data_ok)
1244 && (msg->keepwepflags.data !=
1245 P80211ENUM_truth_true)) {
1246 /* Set the wepflags for no decryption */
1247 word = HFA384x_WEPFLAGS_DISABLE_TXCRYPT |
1248 HFA384x_WEPFLAGS_DISABLE_RXCRYPT;
1250 hfa384x_drvr_setconfig16(hw,
1251 HFA384x_RID_CNFWEPFLAGS,
1257 ("failed to set wepflags=0x%04x, result=%d\n",
1263 /* Do we want to strip the FCS in monitor mode? */
1264 if ((msg->stripfcs.status == P80211ENUM_msgitem_status_data_ok)
1265 && (msg->stripfcs.data == P80211ENUM_truth_true)) {
1271 /* Do we want to truncate the packets? */
1272 if (msg->packet_trunc.status ==
1273 P80211ENUM_msgitem_status_data_ok) {
1274 hw->sniff_truncate = msg->packet_trunc.data;
1276 hw->sniff_truncate = 0;
1279 /* Enable the port */
1280 result = hfa384x_drvr_enable(hw, 0);
1283 ("failed to enable port for sniffing, result=%d\n",
1287 /* Enable monitor mode */
1288 result = hfa384x_cmd_monitor(hw, HFA384x_MONITOR_ENABLE);
1290 pr_debug("failed to enable monitor mode, result=%d\n",
1295 if (wlandev->netdev->type == ARPHRD_ETHER)
1296 netdev_info(wlandev->netdev, "monitor mode enabled\n");
1298 /* Set the driver state */
1299 /* Do we want the prism2 header? */
1300 if ((msg->prismheader.status ==
1301 P80211ENUM_msgitem_status_data_ok)
1302 && (msg->prismheader.data == P80211ENUM_truth_true)) {
1304 wlandev->netdev->type = ARPHRD_IEEE80211_PRISM;
1306 if ((msg->wlanheader.status ==
1307 P80211ENUM_msgitem_status_data_ok)
1308 && (msg->wlanheader.data == P80211ENUM_truth_true)) {
1310 wlandev->netdev->type = ARPHRD_IEEE80211_PRISM;
1312 wlandev->netdev->type = ARPHRD_IEEE80211;
1315 msg->resultcode.data = P80211ENUM_resultcode_success;
1320 msg->resultcode.data = P80211ENUM_resultcode_invalid_parameters;
1327 msg->resultcode.data = P80211ENUM_resultcode_refused;