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 /*================================================================*/
62 #define WLAN_DBVAR prism2_debug
64 #include <linux/version.h>
66 #include <linux/if_arp.h>
67 #include <linux/module.h>
68 #include <linux/kernel.h>
69 #include <linux/wait.h>
70 #include <linux/sched.h>
71 #include <linux/types.h>
72 #include <linux/slab.h>
73 #include <linux/wireless.h>
74 #include <linux/netdevice.h>
75 #include <linux/delay.h>
77 #include <asm/byteorder.h>
78 #include <linux/random.h>
79 #include <linux/usb.h>
81 #include "wlan_compat.h"
83 /*================================================================*/
84 /* Project Includes */
86 #include "p80211types.h"
87 #include "p80211hdr.h"
88 #include "p80211mgmt.h"
89 #include "p80211conv.h"
90 #include "p80211msg.h"
91 #include "p80211netdev.h"
92 #include "p80211metadef.h"
93 #include "p80211metastruct.h"
95 #include "prism2mgmt.h"
97 /* Converts 802.11 format rate specifications to prism2 */
98 #define p80211rate_to_p2bit(n) ((((n)&~BIT7) == 2) ? BIT0 : \
99 (((n)&~BIT7) == 4) ? BIT1 : \
100 (((n)&~BIT7) == 11) ? BIT2 : \
101 (((n)&~BIT7) == 22) ? BIT3 : 0)
103 /*----------------------------------------------------------------
106 * Initiate a scan for BSSs.
108 * This function corresponds to MLME-scan.request and part of
109 * MLME-scan.confirm. As far as I can tell in the standard, there
110 * are no restrictions on when a scan.request may be issued. We have
111 * to handle in whatever state the driver/MAC happen to be.
114 * wlandev wlan device structure
115 * msgp ptr to msg buffer
119 * <0 success, but we're waiting for something to finish.
120 * >0 an error occurred while handling the message.
124 * process thread (usually)
126 ----------------------------------------------------------------*/
127 int prism2mgmt_scan(wlandevice_t *wlandev, void *msgp)
130 hfa384x_t *hw = wlandev->priv;
131 p80211msg_dot11req_scan_t *msg = msgp;
132 u16 roamingmode, word;
136 hfa384x_HostScanRequest_data_t scanreq;
140 /* gatekeeper check */
141 if (HFA384x_FIRMWARE_VERSION(hw->ident_sta_fw.major,
142 hw->ident_sta_fw.minor,
143 hw->ident_sta_fw.variant) <
144 HFA384x_FIRMWARE_VERSION(1,3,2)) {
145 WLAN_LOG_ERROR("HostScan not supported with current firmware (<1.3.2).\n");
147 msg->resultcode.data = P80211ENUM_resultcode_not_supported;
151 memset(&scanreq, 0, sizeof(scanreq));
153 /* save current roaming mode */
154 result = hfa384x_drvr_getconfig16(hw,
155 HFA384x_RID_CNFROAMINGMODE, &roamingmode);
157 WLAN_LOG_ERROR("getconfig(ROAMMODE) failed. result=%d\n",
159 msg->resultcode.data =
160 P80211ENUM_resultcode_implementation_failure;
164 /* drop into mode 3 for the scan */
165 result = hfa384x_drvr_setconfig16(hw,
166 HFA384x_RID_CNFROAMINGMODE,
167 HFA384x_ROAMMODE_HOSTSCAN_HOSTROAM);
169 WLAN_LOG_ERROR("setconfig(ROAMINGMODE) failed. result=%d\n",
171 msg->resultcode.data =
172 P80211ENUM_resultcode_implementation_failure;
176 /* active or passive? */
177 if (HFA384x_FIRMWARE_VERSION(hw->ident_sta_fw.major,
178 hw->ident_sta_fw.minor,
179 hw->ident_sta_fw.variant) >
180 HFA384x_FIRMWARE_VERSION(1,5,0)) {
181 if (msg->scantype.data != P80211ENUM_scantype_active) {
182 word = host2hfa384x_16(msg->maxchanneltime.data);
186 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFPASSIVESCANCTRL, word);
188 WLAN_LOG_WARNING("Passive scan not supported with "
189 "current firmware. (<1.5.1)\n");
193 /* set up the txrate to be 2MBPS. Should be fastest basicrate... */
194 word = HFA384x_RATEBIT_2;
195 scanreq.txRate = host2hfa384x_16(word);
197 /* set up the channel list */
199 for (i = 0; i < msg->channellist.data.len; i++) {
200 u8 channel = msg->channellist.data.data[i];
201 if (channel > 14) continue;
202 /* channel 1 is BIT0 ... channel 14 is BIT13 */
203 word |= (1 << (channel-1));
205 scanreq.channelList = host2hfa384x_16(word);
207 /* set up the ssid, if present. */
208 scanreq.ssid.len = host2hfa384x_16(msg->ssid.data.len);
209 memcpy(scanreq.ssid.data, msg->ssid.data.data, msg->ssid.data.len);
211 /* Enable the MAC port if it's not already enabled */
212 result = hfa384x_drvr_getconfig16(hw, HFA384x_RID_PORTSTATUS, &word);
214 WLAN_LOG_ERROR("getconfig(PORTSTATUS) failed. "
215 "result=%d\n", result);
216 msg->resultcode.data =
217 P80211ENUM_resultcode_implementation_failure;
220 if (word == HFA384x_PORTSTATUS_DISABLED) {
223 result = hfa384x_drvr_setconfig16(hw,
224 HFA384x_RID_CNFROAMINGMODE,
225 HFA384x_ROAMMODE_HOSTSCAN_HOSTROAM);
227 WLAN_LOG_ERROR("setconfig(ROAMINGMODE) failed. result=%d\n", result);
228 msg->resultcode.data =
229 P80211ENUM_resultcode_implementation_failure;
232 /* Construct a bogus SSID and assign it to OwnSSID and
235 wordbuf[0] = host2hfa384x_16(WLAN_SSID_MAXLEN);
236 get_random_bytes(&wordbuf[1], WLAN_SSID_MAXLEN);
237 result = hfa384x_drvr_setconfig( hw, HFA384x_RID_CNFOWNSSID,
238 wordbuf, HFA384x_RID_CNFOWNSSID_LEN);
240 WLAN_LOG_ERROR("Failed to set OwnSSID.\n");
241 msg->resultcode.data =
242 P80211ENUM_resultcode_implementation_failure;
245 result = hfa384x_drvr_setconfig( hw, HFA384x_RID_CNFDESIREDSSID,
246 wordbuf, HFA384x_RID_CNFDESIREDSSID_LEN);
248 WLAN_LOG_ERROR("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 WLAN_LOG_ERROR("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 WLAN_LOG_ERROR("Failed to set CREATEIBSS.\n");
269 msg->resultcode.data =
270 P80211ENUM_resultcode_implementation_failure;
273 result = hfa384x_drvr_enable(hw, 0);
275 WLAN_LOG_ERROR("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 WLAN_HEX_DUMP(5,"hscanreq", &scanreq, sizeof(scanreq));
293 result = hfa384x_drvr_setconfig( hw,
294 HFA384x_RID_HOSTSCAN, &scanreq,
295 sizeof(hfa384x_HostScanRequest_data_t));
297 WLAN_LOG_ERROR("setconfig(SCANREQUEST) failed. result=%d\n",
299 msg->resultcode.data =
300 P80211ENUM_resultcode_implementation_failure;
304 /* sleep until info frame arrives */
305 wait_event_interruptible_timeout(hw->cmdq, hw->scanflag, timeout);
307 msg->numbss.status = P80211ENUM_msgitem_status_data_ok;
308 if (hw->scanflag == -1)
311 msg->numbss.data = hw->scanflag;
315 /* Disable port if we temporarily enabled it. */
317 result = hfa384x_drvr_disable(hw, 0);
319 WLAN_LOG_ERROR("drvr_disable(0) failed. "
320 "result=%d\n", result);
321 msg->resultcode.data =
322 P80211ENUM_resultcode_implementation_failure;
327 /* restore original roaming mode */
328 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFROAMINGMODE,
331 WLAN_LOG_ERROR("setconfig(ROAMMODE) failed. result=%d\n",
333 msg->resultcode.data =
334 P80211ENUM_resultcode_implementation_failure;
339 msg->resultcode.data = P80211ENUM_resultcode_success;
342 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 p80211msg_dot11req_scan_results_t *req;
373 hfa384x_t *hw = wlandev->priv;
374 hfa384x_HScanResultSub_t *item = NULL;
380 req = (p80211msg_dot11req_scan_results_t *) msgp;
382 req->resultcode.status = P80211ENUM_msgitem_status_data_ok;
384 if (! hw->scanresults) {
385 WLAN_LOG_ERROR("dot11req_scan_results can only be used after a successful dot11req_scan.\n");
387 req->resultcode.data = P80211ENUM_resultcode_invalid_parameters;
391 count = (hw->scanresults->framelen - 3) / 32;
392 if (count > 32) count = 32;
394 if (req->bssindex.data >= count) {
395 WLAN_LOG_DEBUG(0, "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 = hfa384x2host_16(item->sl);
407 req->noise.data = hfa384x2host_16(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 = hfa384x2host_16(item->ssid.len);
417 memcpy(req->ssid.data.data, item->ssid.data, req->ssid.data.len);
419 /* supported rates */
420 for (count = 0; count < 10 ; count++)
421 if (item->supprates[count] == 0)
424 #define REQBASICRATE(N) \
425 if ((count >= N) && DOT11_RATE5_ISBASIC_GET(item->supprates[(N)-1])) { \
426 req->basicrate ## N .data = item->supprates[(N)-1]; \
427 req->basicrate ## N .status = P80211ENUM_msgitem_status_data_ok; \
439 #define REQSUPPRATE(N) \
441 req->supprate ## N .data = item->supprates[(N)-1]; \
442 req->supprate ## N .status = P80211ENUM_msgitem_status_data_ok; \
455 req->beaconperiod.status = P80211ENUM_msgitem_status_data_ok;
456 req->beaconperiod.data = hfa384x2host_16(item->bcnint);
459 req->timestamp.status = P80211ENUM_msgitem_status_data_ok;
460 req->timestamp.data = jiffies;
461 req->localtime.status = P80211ENUM_msgitem_status_data_ok;
462 req->localtime.data = jiffies;
465 req->ibssatimwindow.status = P80211ENUM_msgitem_status_data_ok;
466 req->ibssatimwindow.data = hfa384x2host_16(item->atim);
469 req->dschannel.status = P80211ENUM_msgitem_status_data_ok;
470 req->dschannel.data = hfa384x2host_16(item->chid);
473 count = hfa384x2host_16(item->capinfo);
476 req->privacy.status = P80211ENUM_msgitem_status_data_ok;
477 req->privacy.data = WLAN_GET_MGMT_CAP_INFO_PRIVACY(count);
480 req->cfpollable.status = P80211ENUM_msgitem_status_data_ok;
481 req->cfpollable.data = WLAN_GET_MGMT_CAP_INFO_CFPOLLABLE(count);
484 req->cfpollreq.status = P80211ENUM_msgitem_status_data_ok;
485 req->cfpollreq.data = WLAN_GET_MGMT_CAP_INFO_CFPOLLREQ(count);
488 req->bsstype.status = P80211ENUM_msgitem_status_data_ok;
489 req->bsstype.data = (WLAN_GET_MGMT_CAP_INFO_ESS(count)) ?
490 P80211ENUM_bsstype_infrastructure :
491 P80211ENUM_bsstype_independent;
493 // item->proberesp_rate
503 req->resultcode.data = P80211ENUM_resultcode_success;
510 /*----------------------------------------------------------------
513 * Start a BSS. Any station can do this for IBSS, only AP for ESS.
516 * wlandev wlan device structure
517 * msgp ptr to msg buffer
521 * <0 success, but we're waiting for something to finish.
522 * >0 an error occurred while handling the message.
526 * process thread (usually)
528 ----------------------------------------------------------------*/
529 int prism2mgmt_start(wlandevice_t *wlandev, void *msgp)
532 hfa384x_t *hw = wlandev->priv;
533 p80211msg_dot11req_start_t *msg = msgp;
537 hfa384x_bytestr_t *p2bytestr = (hfa384x_bytestr_t*)bytebuf;
541 wlandev->macmode = WLAN_MACMODE_NONE;
544 memcpy(&wlandev->ssid, &msg->ssid.data, sizeof(msg->ssid.data));
547 /* see if current f/w is less than 8c3 */
548 if (HFA384x_FIRMWARE_VERSION(hw->ident_sta_fw.major,
549 hw->ident_sta_fw.minor,
550 hw->ident_sta_fw.variant) <
551 HFA384x_FIRMWARE_VERSION(0,8,3)) {
552 /* Ad-Hoc not quite supported on Prism2 */
553 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
554 msg->resultcode.data = P80211ENUM_resultcode_not_supported;
558 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
561 /* Set the REQUIRED config items */
563 pstr = (p80211pstrd_t*)&(msg->ssid.data);
564 prism2mgmt_pstr2bytestr(p2bytestr, pstr);
565 result = hfa384x_drvr_setconfig( hw, HFA384x_RID_CNFOWNSSID,
566 bytebuf, HFA384x_RID_CNFOWNSSID_LEN);
568 WLAN_LOG_ERROR("Failed to set CnfOwnSSID\n");
571 result = hfa384x_drvr_setconfig( hw, HFA384x_RID_CNFDESIREDSSID,
572 bytebuf, HFA384x_RID_CNFDESIREDSSID_LEN);
574 WLAN_LOG_ERROR("Failed to set CnfDesiredSSID\n");
578 /* bsstype - we use the default in the ap firmware */
580 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFPORTTYPE, 0);
583 word = msg->beaconperiod.data;
584 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFAPBCNint, word);
586 WLAN_LOG_ERROR("Failed to set beacon period=%d.\n", word);
591 word = msg->dschannel.data;
592 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFOWNCHANNEL, word);
594 WLAN_LOG_ERROR("Failed to set channel=%d.\n", word);
598 word = p80211rate_to_p2bit(msg->basicrate1.data);
599 if ( msg->basicrate2.status == P80211ENUM_msgitem_status_data_ok ) {
600 word |= p80211rate_to_p2bit(msg->basicrate2.data);
602 if ( msg->basicrate3.status == P80211ENUM_msgitem_status_data_ok ) {
603 word |= p80211rate_to_p2bit(msg->basicrate3.data);
605 if ( msg->basicrate4.status == P80211ENUM_msgitem_status_data_ok ) {
606 word |= p80211rate_to_p2bit(msg->basicrate4.data);
608 if ( msg->basicrate5.status == P80211ENUM_msgitem_status_data_ok ) {
609 word |= p80211rate_to_p2bit(msg->basicrate5.data);
611 if ( msg->basicrate6.status == P80211ENUM_msgitem_status_data_ok ) {
612 word |= p80211rate_to_p2bit(msg->basicrate6.data);
614 if ( msg->basicrate7.status == P80211ENUM_msgitem_status_data_ok ) {
615 word |= p80211rate_to_p2bit(msg->basicrate7.data);
617 if ( msg->basicrate8.status == P80211ENUM_msgitem_status_data_ok ) {
618 word |= p80211rate_to_p2bit(msg->basicrate8.data);
620 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFBASICRATES, word);
622 WLAN_LOG_ERROR("Failed to set basicrates=%d.\n", word);
626 /* Operational rates (supprates and txratecontrol) */
627 word = p80211rate_to_p2bit(msg->operationalrate1.data);
628 if ( msg->operationalrate2.status == P80211ENUM_msgitem_status_data_ok ) {
629 word |= p80211rate_to_p2bit(msg->operationalrate2.data);
631 if ( msg->operationalrate3.status == P80211ENUM_msgitem_status_data_ok ) {
632 word |= p80211rate_to_p2bit(msg->operationalrate3.data);
634 if ( msg->operationalrate4.status == P80211ENUM_msgitem_status_data_ok ) {
635 word |= p80211rate_to_p2bit(msg->operationalrate4.data);
637 if ( msg->operationalrate5.status == P80211ENUM_msgitem_status_data_ok ) {
638 word |= p80211rate_to_p2bit(msg->operationalrate5.data);
640 if ( msg->operationalrate6.status == P80211ENUM_msgitem_status_data_ok ) {
641 word |= p80211rate_to_p2bit(msg->operationalrate6.data);
643 if ( msg->operationalrate7.status == P80211ENUM_msgitem_status_data_ok ) {
644 word |= p80211rate_to_p2bit(msg->operationalrate7.data);
646 if ( msg->operationalrate8.status == P80211ENUM_msgitem_status_data_ok ) {
647 word |= p80211rate_to_p2bit(msg->operationalrate8.data);
649 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFSUPPRATES, word);
651 WLAN_LOG_ERROR("Failed to set supprates=%d.\n", word);
655 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_TXRATECNTL, word);
657 WLAN_LOG_ERROR("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 WLAN_LOG_ERROR("Enable macport failed, result=%d.\n", result);
675 msg->resultcode.data = P80211ENUM_resultcode_success;
679 WLAN_LOG_DEBUG(1, "Failed to set a config option, result=%d\n", result);
680 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 p80211msg_p2req_readpda_t *msg = msgp;
714 /* We only support collecting the PDA when in the FWLOAD
717 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
719 "PDA may only be read "
720 "in the fwload state.\n");
721 msg->resultcode.data =
722 P80211ENUM_resultcode_implementation_failure;
723 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
725 /* Call drvr_readpda(), it handles the auxport enable
726 * and validating the returned PDA.
728 result = hfa384x_drvr_readpda(
731 HFA384x_PDA_LEN_MAX);
734 "hfa384x_drvr_readpda() failed, "
738 msg->resultcode.data =
739 P80211ENUM_resultcode_implementation_failure;
740 msg->resultcode.status =
741 P80211ENUM_msgitem_status_data_ok;
745 msg->pda.status = P80211ENUM_msgitem_status_data_ok;
746 msg->resultcode.data = P80211ENUM_resultcode_success;
747 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
754 /*----------------------------------------------------------------
755 * prism2mgmt_ramdl_state
757 * Establishes the beginning/end of a card RAM download session.
759 * It is expected that the ramdl_write() function will be called
760 * one or more times between the 'enable' and 'disable' calls to
763 * Note: This function should not be called when a mac comm port
767 * wlandev wlan device structure
768 * msgp ptr to msg buffer
772 * <0 success, but we're waiting for something to finish.
773 * >0 an error occurred while handling the message.
777 * process thread (usually)
778 ----------------------------------------------------------------*/
779 int prism2mgmt_ramdl_state(wlandevice_t *wlandev, void *msgp)
781 hfa384x_t *hw = wlandev->priv;
782 p80211msg_p2req_ramdl_state_t *msg = msgp;
785 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
787 "ramdl_state(): may only be called "
788 "in the fwload state.\n");
789 msg->resultcode.data =
790 P80211ENUM_resultcode_implementation_failure;
791 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
797 ** Note: Interrupts are locked out if this is an AP and are NOT
798 ** locked out if this is a station.
801 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
802 if ( msg->enable.data == P80211ENUM_truth_true ) {
803 if ( hfa384x_drvr_ramdl_enable(hw, msg->exeaddr.data) ) {
804 msg->resultcode.data = P80211ENUM_resultcode_implementation_failure;
806 msg->resultcode.data = P80211ENUM_resultcode_success;
809 hfa384x_drvr_ramdl_disable(hw);
810 msg->resultcode.data = P80211ENUM_resultcode_success;
818 /*----------------------------------------------------------------
819 * prism2mgmt_ramdl_write
821 * Writes a buffer to the card RAM using the download state. This
822 * is for writing code to card RAM. To just read or write raw data
823 * use the aux functions.
826 * wlandev wlan device structure
827 * msgp ptr to msg buffer
831 * <0 success, but we're waiting for something to finish.
832 * >0 an error occurred while handling the message.
836 * process thread (usually)
837 ----------------------------------------------------------------*/
838 int prism2mgmt_ramdl_write(wlandevice_t *wlandev, void *msgp)
840 hfa384x_t *hw = wlandev->priv;
841 p80211msg_p2req_ramdl_write_t *msg = msgp;
847 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
849 "ramdl_write(): may only be called "
850 "in the fwload state.\n");
851 msg->resultcode.data =
852 P80211ENUM_resultcode_implementation_failure;
853 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
858 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
859 /* first validate the length */
860 if ( msg->len.data > sizeof(msg->data.data) ) {
861 msg->resultcode.status = P80211ENUM_resultcode_invalid_parameters;
864 /* call the hfa384x function to do the write */
865 addr = msg->addr.data;
867 buf = msg->data.data;
868 if ( hfa384x_drvr_ramdl_write(hw, addr, buf, len) ) {
869 msg->resultcode.data = P80211ENUM_resultcode_refused;
872 msg->resultcode.data = P80211ENUM_resultcode_success;
879 /*----------------------------------------------------------------
880 * prism2mgmt_flashdl_state
882 * Establishes the beginning/end of a card Flash download session.
884 * It is expected that the flashdl_write() function will be called
885 * one or more times between the 'enable' and 'disable' calls to
888 * Note: This function should not be called when a mac comm port
892 * wlandev wlan device structure
893 * msgp ptr to msg buffer
897 * <0 success, but we're waiting for something to finish.
898 * >0 an error occurred while handling the message.
902 * process thread (usually)
903 ----------------------------------------------------------------*/
904 int prism2mgmt_flashdl_state(wlandevice_t *wlandev, void *msgp)
907 hfa384x_t *hw = wlandev->priv;
908 p80211msg_p2req_flashdl_state_t *msg = msgp;
911 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
913 "flashdl_state(): may only be called "
914 "in the fwload state.\n");
915 msg->resultcode.data =
916 P80211ENUM_resultcode_implementation_failure;
917 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
923 ** Note: Interrupts are locked out if this is an AP and are NOT
924 ** locked out if this is a station.
927 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
928 if ( msg->enable.data == P80211ENUM_truth_true ) {
929 if ( hfa384x_drvr_flashdl_enable(hw) ) {
930 msg->resultcode.data = P80211ENUM_resultcode_implementation_failure;
932 msg->resultcode.data = P80211ENUM_resultcode_success;
935 hfa384x_drvr_flashdl_disable(hw);
936 msg->resultcode.data = P80211ENUM_resultcode_success;
937 /* NOTE: At this point, the MAC is in the post-reset
938 * state and the driver is in the fwload state.
939 * We need to get the MAC back into the fwload
940 * state. To do this, we set the nsdstate to HWPRESENT
941 * and then call the ifstate function to redo everything
942 * that got us into the fwload state.
944 wlandev->msdstate = WLAN_MSD_HWPRESENT;
945 result = prism2sta_ifstate(wlandev, P80211ENUM_ifstate_fwload);
946 if (result != P80211ENUM_resultcode_success) {
947 WLAN_LOG_ERROR("prism2sta_ifstate(fwload) failed,"
948 "P80211ENUM_resultcode=%d\n", result);
949 msg->resultcode.data =
950 P80211ENUM_resultcode_implementation_failure;
960 /*----------------------------------------------------------------
961 * prism2mgmt_flashdl_write
966 * wlandev wlan device structure
967 * msgp ptr to msg buffer
971 * <0 success, but we're waiting for something to finish.
972 * >0 an error occurred while handling the message.
976 * process thread (usually)
977 ----------------------------------------------------------------*/
978 int prism2mgmt_flashdl_write(wlandevice_t *wlandev, void *msgp)
980 hfa384x_t *hw = wlandev->priv;
981 p80211msg_p2req_flashdl_write_t *msg = msgp;
987 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
989 "flashdl_write(): may only be called "
990 "in the fwload state.\n");
991 msg->resultcode.data =
992 P80211ENUM_resultcode_implementation_failure;
993 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
999 ** Note: Interrupts are locked out if this is an AP and are NOT
1000 ** locked out if this is a station.
1003 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
1004 /* first validate the length */
1005 if ( msg->len.data > sizeof(msg->data.data) ) {
1006 msg->resultcode.status =
1007 P80211ENUM_resultcode_invalid_parameters;
1010 /* call the hfa384x function to do the write */
1011 addr = msg->addr.data;
1012 len = msg->len.data;
1013 buf = msg->data.data;
1014 if ( hfa384x_drvr_flashdl_write(hw, addr, buf, len) ) {
1015 msg->resultcode.data = P80211ENUM_resultcode_refused;
1018 msg->resultcode.data = P80211ENUM_resultcode_success;
1024 /*----------------------------------------------------------------
1025 * prism2mgmt_autojoin
1027 * Associate with an ESS.
1030 * wlandev wlan device structure
1031 * msgp ptr to msg buffer
1034 * 0 success and done
1035 * <0 success, but we're waiting for something to finish.
1036 * >0 an error occurred while handling the message.
1040 * process thread (usually)
1042 ----------------------------------------------------------------*/
1043 int prism2mgmt_autojoin(wlandevice_t *wlandev, void *msgp)
1045 hfa384x_t *hw = wlandev->priv;
1049 p80211msg_lnxreq_autojoin_t *msg = msgp;
1050 p80211pstrd_t *pstr;
1052 hfa384x_bytestr_t *p2bytestr = (hfa384x_bytestr_t*)bytebuf;
1055 wlandev->macmode = WLAN_MACMODE_NONE;
1058 memcpy(&wlandev->ssid, &msg->ssid.data, sizeof(msg->ssid.data));
1060 /* Disable the Port */
1061 hfa384x_drvr_disable(hw, 0);
1064 /* Set the TxRates */
1065 hfa384x_drvr_setconfig16(hw, HFA384x_RID_TXRATECNTL, 0x000f);
1067 /* Set the auth type */
1068 if ( msg->authtype.data == P80211ENUM_authalg_sharedkey ) {
1069 reg = HFA384x_CNFAUTHENTICATION_SHAREDKEY;
1071 reg = HFA384x_CNFAUTHENTICATION_OPENSYSTEM;
1073 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFAUTHENTICATION, reg);
1076 memset(bytebuf, 0, 256);
1077 pstr = (p80211pstrd_t*)&(msg->ssid.data);
1078 prism2mgmt_pstr2bytestr(p2bytestr, pstr);
1079 result = hfa384x_drvr_setconfig(
1080 hw, HFA384x_RID_CNFDESIREDSSID,
1081 bytebuf, HFA384x_RID_CNFDESIREDSSID_LEN);
1083 /* we can use the new-fangled auto-unknown mode if the firmware
1084 is 1.3.3 or newer */
1085 if (HFA384x_FIRMARE_VERSION(hw->ident_sta_fw.major,
1086 hw->ident_sta_fw.minor,
1087 hw->ident_sta_fw.variant) >=
1088 HFA384x_FIRMWARE_VERSION(1,3,3)) {
1089 /* Set up the IBSS options */
1090 reg = HFA384x_CREATEIBSS_JOINESS_JOINCREATEIBSS;
1091 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CREATEIBSS, reg);
1093 /* Set the PortType */
1094 port_type = HFA384x_PORTTYPE_IBSS;
1096 port_type = HFA384x_PORTTYPE_BSS;
1099 port_type = HFA384x_PORTTYPE_BSS;
1101 /* Set the PortType */
1102 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFPORTTYPE, port_type);
1104 /* Enable the Port */
1105 hfa384x_drvr_enable(hw, 0);
1107 /* Set the resultcode */
1108 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
1109 msg->resultcode.data = P80211ENUM_resultcode_success;
1116 /*----------------------------------------------------------------
1117 * prism2mgmt_wlansniff
1119 * Start or stop sniffing.
1122 * wlandev wlan device structure
1123 * msgp ptr to msg buffer
1126 * 0 success and done
1127 * <0 success, but we're waiting for something to finish.
1128 * >0 an error occurred while handling the message.
1132 * process thread (usually)
1134 ----------------------------------------------------------------*/
1135 int prism2mgmt_wlansniff(wlandevice_t *wlandev, void *msgp)
1138 p80211msg_lnxreq_wlansniff_t *msg = msgp;
1140 hfa384x_t *hw = wlandev->priv;
1145 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
1146 switch (msg->enable.data)
1148 case P80211ENUM_truth_false:
1149 /* Confirm that we're in monitor mode */
1150 if ( wlandev->netdev->type == ARPHRD_ETHER ) {
1151 msg->resultcode.data = P80211ENUM_resultcode_invalid_parameters;
1155 /* Disable monitor mode */
1156 result = hfa384x_cmd_monitor(hw, HFA384x_MONITOR_DISABLE);
1159 "failed to disable monitor mode, result=%d\n",
1163 /* Disable port 0 */
1164 result = hfa384x_drvr_disable(hw, 0);
1167 "failed to disable port 0 after sniffing, result=%d\n",
1171 /* Clear the driver state */
1172 wlandev->netdev->type = ARPHRD_ETHER;
1174 /* Restore the wepflags */
1175 result = hfa384x_drvr_setconfig16(hw,
1176 HFA384x_RID_CNFWEPFLAGS,
1177 hw->presniff_wepflags);
1180 "failed to restore wepflags=0x%04x, result=%d\n",
1181 hw->presniff_wepflags,
1186 /* Set the port to its prior type and enable (if necessary) */
1187 if (hw->presniff_port_type != 0 ) {
1188 word = hw->presniff_port_type;
1189 result = hfa384x_drvr_setconfig16(hw,
1190 HFA384x_RID_CNFPORTTYPE, word);
1193 "failed to restore porttype, result=%d\n",
1198 /* Enable the port */
1199 result = hfa384x_drvr_enable(hw, 0);
1201 WLAN_LOG_DEBUG(1, "failed to enable port to presniff setting, result=%d\n", result);
1205 result = hfa384x_drvr_disable(hw, 0);
1209 WLAN_LOG_INFO("monitor mode disabled\n");
1210 msg->resultcode.data = P80211ENUM_resultcode_success;
1214 case P80211ENUM_truth_true:
1215 /* Disable the port (if enabled), only check Port 0 */
1216 if ( hw->port_enabled[0]) {
1217 if (wlandev->netdev->type == ARPHRD_ETHER) {
1218 /* Save macport 0 state */
1219 result = hfa384x_drvr_getconfig16(hw,
1220 HFA384x_RID_CNFPORTTYPE,
1221 &(hw->presniff_port_type));
1223 WLAN_LOG_DEBUG(1,"failed to read porttype, result=%d\n", result);
1226 /* Save the wepflags state */
1227 result = hfa384x_drvr_getconfig16(hw,
1228 HFA384x_RID_CNFWEPFLAGS,
1229 &(hw->presniff_wepflags));
1231 WLAN_LOG_DEBUG(1,"failed to read wepflags, result=%d\n", result);
1234 hfa384x_drvr_stop(hw);
1235 result = hfa384x_drvr_start(hw);
1238 "failed to restart the card for sniffing, result=%d\n",
1243 /* Disable the port */
1244 result = hfa384x_drvr_disable(hw, 0);
1247 "failed to enable port for sniffing, result=%d\n",
1253 hw->presniff_port_type = 0;
1256 /* Set the channel we wish to sniff */
1257 word = msg->channel.data;
1258 result = hfa384x_drvr_setconfig16(hw,
1259 HFA384x_RID_CNFOWNCHANNEL, word);
1260 hw->sniff_channel=word;
1264 "failed to set channel %d, result=%d\n",
1270 /* Now if we're already sniffing, we can skip the rest */
1271 if (wlandev->netdev->type != ARPHRD_ETHER) {
1272 /* Set the port type to pIbss */
1273 word = HFA384x_PORTTYPE_PSUEDOIBSS;
1274 result = hfa384x_drvr_setconfig16(hw,
1275 HFA384x_RID_CNFPORTTYPE, word);
1278 "failed to set porttype %d, result=%d\n",
1283 if ((msg->keepwepflags.status == P80211ENUM_msgitem_status_data_ok) && (msg->keepwepflags.data != P80211ENUM_truth_true)) {
1284 /* Set the wepflags for no decryption */
1285 word = HFA384x_WEPFLAGS_DISABLE_TXCRYPT |
1286 HFA384x_WEPFLAGS_DISABLE_RXCRYPT;
1287 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFWEPFLAGS, word);
1292 "failed to set wepflags=0x%04x, result=%d\n",
1299 /* Do we want to strip the FCS in monitor mode? */
1300 if ((msg->stripfcs.status == P80211ENUM_msgitem_status_data_ok) && (msg->stripfcs.data == P80211ENUM_truth_true)) {
1306 /* Do we want to truncate the packets? */
1307 if (msg->packet_trunc.status == P80211ENUM_msgitem_status_data_ok) {
1308 hw->sniff_truncate = msg->packet_trunc.data;
1310 hw->sniff_truncate = 0;
1313 /* Enable the port */
1314 result = hfa384x_drvr_enable(hw, 0);
1317 "failed to enable port for sniffing, result=%d\n",
1321 /* Enable monitor mode */
1322 result = hfa384x_cmd_monitor(hw, HFA384x_MONITOR_ENABLE);
1325 "failed to enable monitor mode, result=%d\n",
1330 if (wlandev->netdev->type == ARPHRD_ETHER) {
1331 WLAN_LOG_INFO("monitor mode enabled\n");
1334 /* Set the driver state */
1335 /* Do we want the prism2 header? */
1336 if ((msg->prismheader.status == P80211ENUM_msgitem_status_data_ok) && (msg->prismheader.data == P80211ENUM_truth_true)) {
1338 wlandev->netdev->type = ARPHRD_IEEE80211_PRISM;
1339 } else if ((msg->wlanheader.status == P80211ENUM_msgitem_status_data_ok) && (msg->wlanheader.data == P80211ENUM_truth_true)) {
1341 wlandev->netdev->type = ARPHRD_IEEE80211_PRISM;
1343 wlandev->netdev->type = ARPHRD_IEEE80211;
1346 msg->resultcode.data = P80211ENUM_resultcode_success;
1351 msg->resultcode.data = P80211ENUM_resultcode_invalid_parameters;
1358 msg->resultcode.data = P80211ENUM_resultcode_refused;