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
65 #include <linux/if_arp.h>
66 #include <linux/module.h>
67 #include <linux/kernel.h>
68 #include <linux/wait.h>
69 #include <linux/sched.h>
70 #include <linux/types.h>
71 #include <linux/slab.h>
72 #include <linux/wireless.h>
73 #include <linux/netdevice.h>
74 #include <linux/delay.h>
76 #include <asm/byteorder.h>
77 #include <linux/random.h>
78 #include <linux/usb.h>
79 #include <linux/bitops.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)&~BIT(7)) == 2) ? BIT(0) : \
99 (((n)&~BIT(7)) == 4) ? BIT(1) : \
100 (((n)&~BIT(7)) == 11) ? BIT(2) : \
101 (((n)&~BIT(7)) == 22) ? BIT(3) : 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;
138 /* gatekeeper check */
139 if (HFA384x_FIRMWARE_VERSION(hw->ident_sta_fw.major,
140 hw->ident_sta_fw.minor,
141 hw->ident_sta_fw.variant) <
142 HFA384x_FIRMWARE_VERSION(1,3,2)) {
143 WLAN_LOG_ERROR("HostScan not supported with current firmware (<1.3.2).\n");
145 msg->resultcode.data = P80211ENUM_resultcode_not_supported;
149 memset(&scanreq, 0, sizeof(scanreq));
151 /* save current roaming mode */
152 result = hfa384x_drvr_getconfig16(hw,
153 HFA384x_RID_CNFROAMINGMODE, &roamingmode);
155 WLAN_LOG_ERROR("getconfig(ROAMMODE) failed. result=%d\n",
157 msg->resultcode.data =
158 P80211ENUM_resultcode_implementation_failure;
162 /* drop into mode 3 for the scan */
163 result = hfa384x_drvr_setconfig16(hw,
164 HFA384x_RID_CNFROAMINGMODE,
165 HFA384x_ROAMMODE_HOSTSCAN_HOSTROAM);
167 WLAN_LOG_ERROR("setconfig(ROAMINGMODE) failed. result=%d\n",
169 msg->resultcode.data =
170 P80211ENUM_resultcode_implementation_failure;
174 /* active or passive? */
175 if (HFA384x_FIRMWARE_VERSION(hw->ident_sta_fw.major,
176 hw->ident_sta_fw.minor,
177 hw->ident_sta_fw.variant) >
178 HFA384x_FIRMWARE_VERSION(1,5,0)) {
179 if (msg->scantype.data != P80211ENUM_scantype_active) {
180 word = host2hfa384x_16(msg->maxchanneltime.data);
184 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFPASSIVESCANCTRL, word);
186 WLAN_LOG_WARNING("Passive scan not supported with "
187 "current firmware. (<1.5.1)\n");
191 /* set up the txrate to be 2MBPS. Should be fastest basicrate... */
192 word = HFA384x_RATEBIT_2;
193 scanreq.txRate = host2hfa384x_16(word);
195 /* set up the channel list */
197 for (i = 0; i < msg->channellist.data.len; i++) {
198 u8 channel = msg->channellist.data.data[i];
199 if (channel > 14) continue;
200 /* channel 1 is BIT 0 ... channel 14 is BIT 13 */
201 word |= (1 << (channel-1));
203 scanreq.channelList = host2hfa384x_16(word);
205 /* set up the ssid, if present. */
206 scanreq.ssid.len = host2hfa384x_16(msg->ssid.data.len);
207 memcpy(scanreq.ssid.data, msg->ssid.data.data, msg->ssid.data.len);
209 /* Enable the MAC port if it's not already enabled */
210 result = hfa384x_drvr_getconfig16(hw, HFA384x_RID_PORTSTATUS, &word);
212 WLAN_LOG_ERROR("getconfig(PORTSTATUS) failed. "
213 "result=%d\n", result);
214 msg->resultcode.data =
215 P80211ENUM_resultcode_implementation_failure;
218 if (word == HFA384x_PORTSTATUS_DISABLED) {
221 result = hfa384x_drvr_setconfig16(hw,
222 HFA384x_RID_CNFROAMINGMODE,
223 HFA384x_ROAMMODE_HOSTSCAN_HOSTROAM);
225 WLAN_LOG_ERROR("setconfig(ROAMINGMODE) failed. result=%d\n", result);
226 msg->resultcode.data =
227 P80211ENUM_resultcode_implementation_failure;
230 /* Construct a bogus SSID and assign it to OwnSSID and
233 wordbuf[0] = host2hfa384x_16(WLAN_SSID_MAXLEN);
234 get_random_bytes(&wordbuf[1], WLAN_SSID_MAXLEN);
235 result = hfa384x_drvr_setconfig( hw, HFA384x_RID_CNFOWNSSID,
236 wordbuf, HFA384x_RID_CNFOWNSSID_LEN);
238 WLAN_LOG_ERROR("Failed to set OwnSSID.\n");
239 msg->resultcode.data =
240 P80211ENUM_resultcode_implementation_failure;
243 result = hfa384x_drvr_setconfig( hw, HFA384x_RID_CNFDESIREDSSID,
244 wordbuf, HFA384x_RID_CNFDESIREDSSID_LEN);
246 WLAN_LOG_ERROR("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 WLAN_LOG_ERROR("Failed to set CNFPORTTYPE.\n");
257 msg->resultcode.data =
258 P80211ENUM_resultcode_implementation_failure;
262 result = hfa384x_drvr_setconfig16(hw,
263 HFA384x_RID_CREATEIBSS,
264 HFA384x_CREATEIBSS_JOINCREATEIBSS);
266 WLAN_LOG_ERROR("Failed to set CREATEIBSS.\n");
267 msg->resultcode.data =
268 P80211ENUM_resultcode_implementation_failure;
271 result = hfa384x_drvr_enable(hw, 0);
273 WLAN_LOG_ERROR("drvr_enable(0) failed. "
274 "result=%d\n", result);
275 msg->resultcode.data =
276 P80211ENUM_resultcode_implementation_failure;
282 /* Figure out our timeout first Kus, then HZ */
283 timeout = msg->channellist.data.len * msg->maxchanneltime.data;
284 timeout = (timeout * HZ)/1000;
286 /* Issue the scan request */
289 WLAN_HEX_DUMP(5,"hscanreq", &scanreq, sizeof(scanreq));
291 result = hfa384x_drvr_setconfig( hw,
292 HFA384x_RID_HOSTSCAN, &scanreq,
293 sizeof(hfa384x_HostScanRequest_data_t));
295 WLAN_LOG_ERROR("setconfig(SCANREQUEST) failed. result=%d\n",
297 msg->resultcode.data =
298 P80211ENUM_resultcode_implementation_failure;
302 /* sleep until info frame arrives */
303 wait_event_interruptible_timeout(hw->cmdq, hw->scanflag, timeout);
305 msg->numbss.status = P80211ENUM_msgitem_status_data_ok;
306 if (hw->scanflag == -1)
309 msg->numbss.data = hw->scanflag;
313 /* Disable port if we temporarily enabled it. */
315 result = hfa384x_drvr_disable(hw, 0);
317 WLAN_LOG_ERROR("drvr_disable(0) failed. "
318 "result=%d\n", result);
319 msg->resultcode.data =
320 P80211ENUM_resultcode_implementation_failure;
325 /* restore original roaming mode */
326 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFROAMINGMODE,
329 WLAN_LOG_ERROR("setconfig(ROAMMODE) failed. result=%d\n",
331 msg->resultcode.data =
332 P80211ENUM_resultcode_implementation_failure;
337 msg->resultcode.data = P80211ENUM_resultcode_success;
340 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
346 /*----------------------------------------------------------------
347 * prism2mgmt_scan_results
349 * Retrieve the BSS description for one of the BSSs identified in
353 * wlandev wlan device structure
354 * msgp ptr to msg buffer
358 * <0 success, but we're waiting for something to finish.
359 * >0 an error occurred while handling the message.
363 * process thread (usually)
365 ----------------------------------------------------------------*/
366 int prism2mgmt_scan_results(wlandevice_t *wlandev, void *msgp)
369 p80211msg_dot11req_scan_results_t *req;
370 hfa384x_t *hw = wlandev->priv;
371 hfa384x_HScanResultSub_t *item = NULL;
375 req = (p80211msg_dot11req_scan_results_t *) msgp;
377 req->resultcode.status = P80211ENUM_msgitem_status_data_ok;
379 if (! hw->scanresults) {
380 WLAN_LOG_ERROR("dot11req_scan_results can only be used after a successful dot11req_scan.\n");
382 req->resultcode.data = P80211ENUM_resultcode_invalid_parameters;
386 count = (hw->scanresults->framelen - 3) / 32;
387 if (count > 32) count = 32;
389 if (req->bssindex.data >= count) {
390 WLAN_LOG_DEBUG(0, "requested index (%d) out of range (%d)\n",
391 req->bssindex.data, count);
393 req->resultcode.data = P80211ENUM_resultcode_invalid_parameters;
397 item = &(hw->scanresults->info.hscanresult.result[req->bssindex.data]);
398 /* signal and noise */
399 req->signal.status = P80211ENUM_msgitem_status_data_ok;
400 req->noise.status = P80211ENUM_msgitem_status_data_ok;
401 req->signal.data = hfa384x2host_16(item->sl);
402 req->noise.data = hfa384x2host_16(item->anl);
405 req->bssid.status = P80211ENUM_msgitem_status_data_ok;
406 req->bssid.data.len = WLAN_BSSID_LEN;
407 memcpy(req->bssid.data.data, item->bssid, WLAN_BSSID_LEN);
410 req->ssid.status = P80211ENUM_msgitem_status_data_ok;
411 req->ssid.data.len = hfa384x2host_16(item->ssid.len);
412 memcpy(req->ssid.data.data, item->ssid.data, req->ssid.data.len);
414 /* supported rates */
415 for (count = 0; count < 10 ; count++)
416 if (item->supprates[count] == 0)
419 #define REQBASICRATE(N) \
420 if ((count >= N) && DOT11_RATE5_ISBASIC_GET(item->supprates[(N)-1])) { \
421 req->basicrate ## N .data = item->supprates[(N)-1]; \
422 req->basicrate ## N .status = P80211ENUM_msgitem_status_data_ok; \
434 #define REQSUPPRATE(N) \
436 req->supprate ## N .data = item->supprates[(N)-1]; \
437 req->supprate ## N .status = P80211ENUM_msgitem_status_data_ok; \
450 req->beaconperiod.status = P80211ENUM_msgitem_status_data_ok;
451 req->beaconperiod.data = hfa384x2host_16(item->bcnint);
454 req->timestamp.status = P80211ENUM_msgitem_status_data_ok;
455 req->timestamp.data = jiffies;
456 req->localtime.status = P80211ENUM_msgitem_status_data_ok;
457 req->localtime.data = jiffies;
460 req->ibssatimwindow.status = P80211ENUM_msgitem_status_data_ok;
461 req->ibssatimwindow.data = hfa384x2host_16(item->atim);
464 req->dschannel.status = P80211ENUM_msgitem_status_data_ok;
465 req->dschannel.data = hfa384x2host_16(item->chid);
468 count = hfa384x2host_16(item->capinfo);
471 req->privacy.status = P80211ENUM_msgitem_status_data_ok;
472 req->privacy.data = WLAN_GET_MGMT_CAP_INFO_PRIVACY(count);
475 req->cfpollable.status = P80211ENUM_msgitem_status_data_ok;
476 req->cfpollable.data = WLAN_GET_MGMT_CAP_INFO_CFPOLLABLE(count);
479 req->cfpollreq.status = P80211ENUM_msgitem_status_data_ok;
480 req->cfpollreq.data = WLAN_GET_MGMT_CAP_INFO_CFPOLLREQ(count);
483 req->bsstype.status = P80211ENUM_msgitem_status_data_ok;
484 req->bsstype.data = (WLAN_GET_MGMT_CAP_INFO_ESS(count)) ?
485 P80211ENUM_bsstype_infrastructure :
486 P80211ENUM_bsstype_independent;
488 // item->proberesp_rate
498 req->resultcode.data = P80211ENUM_resultcode_success;
504 /*----------------------------------------------------------------
507 * Start a BSS. Any station can do this for IBSS, only AP for ESS.
510 * wlandev wlan device structure
511 * msgp ptr to msg buffer
515 * <0 success, but we're waiting for something to finish.
516 * >0 an error occurred while handling the message.
520 * process thread (usually)
522 ----------------------------------------------------------------*/
523 int prism2mgmt_start(wlandevice_t *wlandev, void *msgp)
526 hfa384x_t *hw = wlandev->priv;
527 p80211msg_dot11req_start_t *msg = msgp;
531 hfa384x_bytestr_t *p2bytestr = (hfa384x_bytestr_t*)bytebuf;
534 wlandev->macmode = WLAN_MACMODE_NONE;
537 memcpy(&wlandev->ssid, &msg->ssid.data, sizeof(msg->ssid.data));
540 /* see if current f/w is less than 8c3 */
541 if (HFA384x_FIRMWARE_VERSION(hw->ident_sta_fw.major,
542 hw->ident_sta_fw.minor,
543 hw->ident_sta_fw.variant) <
544 HFA384x_FIRMWARE_VERSION(0,8,3)) {
545 /* Ad-Hoc not quite supported on Prism2 */
546 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
547 msg->resultcode.data = P80211ENUM_resultcode_not_supported;
551 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
554 /* Set the REQUIRED config items */
556 pstr = (p80211pstrd_t*)&(msg->ssid.data);
557 prism2mgmt_pstr2bytestr(p2bytestr, pstr);
558 result = hfa384x_drvr_setconfig( hw, HFA384x_RID_CNFOWNSSID,
559 bytebuf, HFA384x_RID_CNFOWNSSID_LEN);
561 WLAN_LOG_ERROR("Failed to set CnfOwnSSID\n");
564 result = hfa384x_drvr_setconfig( hw, HFA384x_RID_CNFDESIREDSSID,
565 bytebuf, HFA384x_RID_CNFDESIREDSSID_LEN);
567 WLAN_LOG_ERROR("Failed to set CnfDesiredSSID\n");
571 /* bsstype - we use the default in the ap firmware */
573 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFPORTTYPE, 0);
576 word = msg->beaconperiod.data;
577 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFAPBCNint, word);
579 WLAN_LOG_ERROR("Failed to set beacon period=%d.\n", word);
584 word = msg->dschannel.data;
585 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFOWNCHANNEL, word);
587 WLAN_LOG_ERROR("Failed to set channel=%d.\n", word);
591 word = p80211rate_to_p2bit(msg->basicrate1.data);
592 if ( msg->basicrate2.status == P80211ENUM_msgitem_status_data_ok ) {
593 word |= p80211rate_to_p2bit(msg->basicrate2.data);
595 if ( msg->basicrate3.status == P80211ENUM_msgitem_status_data_ok ) {
596 word |= p80211rate_to_p2bit(msg->basicrate3.data);
598 if ( msg->basicrate4.status == P80211ENUM_msgitem_status_data_ok ) {
599 word |= p80211rate_to_p2bit(msg->basicrate4.data);
601 if ( msg->basicrate5.status == P80211ENUM_msgitem_status_data_ok ) {
602 word |= p80211rate_to_p2bit(msg->basicrate5.data);
604 if ( msg->basicrate6.status == P80211ENUM_msgitem_status_data_ok ) {
605 word |= p80211rate_to_p2bit(msg->basicrate6.data);
607 if ( msg->basicrate7.status == P80211ENUM_msgitem_status_data_ok ) {
608 word |= p80211rate_to_p2bit(msg->basicrate7.data);
610 if ( msg->basicrate8.status == P80211ENUM_msgitem_status_data_ok ) {
611 word |= p80211rate_to_p2bit(msg->basicrate8.data);
613 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFBASICRATES, word);
615 WLAN_LOG_ERROR("Failed to set basicrates=%d.\n", word);
619 /* Operational rates (supprates and txratecontrol) */
620 word = p80211rate_to_p2bit(msg->operationalrate1.data);
621 if ( msg->operationalrate2.status == P80211ENUM_msgitem_status_data_ok ) {
622 word |= p80211rate_to_p2bit(msg->operationalrate2.data);
624 if ( msg->operationalrate3.status == P80211ENUM_msgitem_status_data_ok ) {
625 word |= p80211rate_to_p2bit(msg->operationalrate3.data);
627 if ( msg->operationalrate4.status == P80211ENUM_msgitem_status_data_ok ) {
628 word |= p80211rate_to_p2bit(msg->operationalrate4.data);
630 if ( msg->operationalrate5.status == P80211ENUM_msgitem_status_data_ok ) {
631 word |= p80211rate_to_p2bit(msg->operationalrate5.data);
633 if ( msg->operationalrate6.status == P80211ENUM_msgitem_status_data_ok ) {
634 word |= p80211rate_to_p2bit(msg->operationalrate6.data);
636 if ( msg->operationalrate7.status == P80211ENUM_msgitem_status_data_ok ) {
637 word |= p80211rate_to_p2bit(msg->operationalrate7.data);
639 if ( msg->operationalrate8.status == P80211ENUM_msgitem_status_data_ok ) {
640 word |= p80211rate_to_p2bit(msg->operationalrate8.data);
642 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFSUPPRATES, word);
644 WLAN_LOG_ERROR("Failed to set supprates=%d.\n", word);
648 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_TXRATECNTL, word);
650 WLAN_LOG_ERROR("Failed to set txrates=%d.\n", word);
654 /* Set the macmode so the frame setup code knows what to do */
655 if ( msg->bsstype.data == P80211ENUM_bsstype_independent ) {
656 wlandev->macmode = WLAN_MACMODE_IBSS_STA;
657 /* lets extend the data length a bit */
658 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFMAXDATALEN, 2304);
661 /* Enable the Port */
662 result = hfa384x_drvr_enable(hw, 0);
664 WLAN_LOG_ERROR("Enable macport failed, result=%d.\n", result);
668 msg->resultcode.data = P80211ENUM_resultcode_success;
672 WLAN_LOG_DEBUG(1, "Failed to set a config option, result=%d\n", result);
673 msg->resultcode.data = P80211ENUM_resultcode_invalid_parameters;
681 /*----------------------------------------------------------------
684 * Collect the PDA data and put it in the message.
687 * wlandev wlan device structure
688 * msgp ptr to msg buffer
692 * <0 success, but we're waiting for something to finish.
693 * >0 an error occurred while handling the message.
697 * process thread (usually)
698 ----------------------------------------------------------------*/
699 int prism2mgmt_readpda(wlandevice_t *wlandev, void *msgp)
701 hfa384x_t *hw = wlandev->priv;
702 p80211msg_p2req_readpda_t *msg = msgp;
705 /* We only support collecting the PDA when in the FWLOAD
708 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
710 "PDA may only be read "
711 "in the fwload state.\n");
712 msg->resultcode.data =
713 P80211ENUM_resultcode_implementation_failure;
714 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
716 /* Call drvr_readpda(), it handles the auxport enable
717 * and validating the returned PDA.
719 result = hfa384x_drvr_readpda(
722 HFA384x_PDA_LEN_MAX);
725 "hfa384x_drvr_readpda() failed, "
729 msg->resultcode.data =
730 P80211ENUM_resultcode_implementation_failure;
731 msg->resultcode.status =
732 P80211ENUM_msgitem_status_data_ok;
735 msg->pda.status = P80211ENUM_msgitem_status_data_ok;
736 msg->resultcode.data = P80211ENUM_resultcode_success;
737 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
743 /*----------------------------------------------------------------
744 * prism2mgmt_ramdl_state
746 * Establishes the beginning/end of a card RAM download session.
748 * It is expected that the ramdl_write() function will be called
749 * one or more times between the 'enable' and 'disable' calls to
752 * Note: This function should not be called when a mac comm port
756 * wlandev wlan device structure
757 * msgp ptr to msg buffer
761 * <0 success, but we're waiting for something to finish.
762 * >0 an error occurred while handling the message.
766 * process thread (usually)
767 ----------------------------------------------------------------*/
768 int prism2mgmt_ramdl_state(wlandevice_t *wlandev, void *msgp)
770 hfa384x_t *hw = wlandev->priv;
771 p80211msg_p2req_ramdl_state_t *msg = msgp;
773 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
775 "ramdl_state(): may only be called "
776 "in the fwload state.\n");
777 msg->resultcode.data =
778 P80211ENUM_resultcode_implementation_failure;
779 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
784 ** Note: Interrupts are locked out if this is an AP and are NOT
785 ** locked out if this is a station.
788 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
789 if ( msg->enable.data == P80211ENUM_truth_true ) {
790 if ( hfa384x_drvr_ramdl_enable(hw, msg->exeaddr.data) ) {
791 msg->resultcode.data = P80211ENUM_resultcode_implementation_failure;
793 msg->resultcode.data = P80211ENUM_resultcode_success;
796 hfa384x_drvr_ramdl_disable(hw);
797 msg->resultcode.data = P80211ENUM_resultcode_success;
804 /*----------------------------------------------------------------
805 * prism2mgmt_ramdl_write
807 * Writes a buffer to the card RAM using the download state. This
808 * is for writing code to card RAM. To just read or write raw data
809 * use the aux functions.
812 * wlandev wlan device structure
813 * msgp ptr to msg buffer
817 * <0 success, but we're waiting for something to finish.
818 * >0 an error occurred while handling the message.
822 * process thread (usually)
823 ----------------------------------------------------------------*/
824 int prism2mgmt_ramdl_write(wlandevice_t *wlandev, void *msgp)
826 hfa384x_t *hw = wlandev->priv;
827 p80211msg_p2req_ramdl_write_t *msg = msgp;
832 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
834 "ramdl_write(): may only be called "
835 "in the fwload state.\n");
836 msg->resultcode.data =
837 P80211ENUM_resultcode_implementation_failure;
838 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
842 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
843 /* first validate the length */
844 if ( msg->len.data > sizeof(msg->data.data) ) {
845 msg->resultcode.status = P80211ENUM_resultcode_invalid_parameters;
848 /* call the hfa384x function to do the write */
849 addr = msg->addr.data;
851 buf = msg->data.data;
852 if ( hfa384x_drvr_ramdl_write(hw, addr, buf, len) ) {
853 msg->resultcode.data = P80211ENUM_resultcode_refused;
856 msg->resultcode.data = P80211ENUM_resultcode_success;
862 /*----------------------------------------------------------------
863 * prism2mgmt_flashdl_state
865 * Establishes the beginning/end of a card Flash download session.
867 * It is expected that the flashdl_write() function will be called
868 * one or more times between the 'enable' and 'disable' calls to
871 * Note: This function should not be called when a mac comm port
875 * wlandev wlan device structure
876 * msgp ptr to msg buffer
880 * <0 success, but we're waiting for something to finish.
881 * >0 an error occurred while handling the message.
885 * process thread (usually)
886 ----------------------------------------------------------------*/
887 int prism2mgmt_flashdl_state(wlandevice_t *wlandev, void *msgp)
890 hfa384x_t *hw = wlandev->priv;
891 p80211msg_p2req_flashdl_state_t *msg = msgp;
893 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
895 "flashdl_state(): may only be called "
896 "in the fwload state.\n");
897 msg->resultcode.data =
898 P80211ENUM_resultcode_implementation_failure;
899 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
904 ** Note: Interrupts are locked out if this is an AP and are NOT
905 ** locked out if this is a station.
908 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
909 if ( msg->enable.data == P80211ENUM_truth_true ) {
910 if ( hfa384x_drvr_flashdl_enable(hw) ) {
911 msg->resultcode.data = P80211ENUM_resultcode_implementation_failure;
913 msg->resultcode.data = P80211ENUM_resultcode_success;
916 hfa384x_drvr_flashdl_disable(hw);
917 msg->resultcode.data = P80211ENUM_resultcode_success;
918 /* NOTE: At this point, the MAC is in the post-reset
919 * state and the driver is in the fwload state.
920 * We need to get the MAC back into the fwload
921 * state. To do this, we set the nsdstate to HWPRESENT
922 * and then call the ifstate function to redo everything
923 * that got us into the fwload state.
925 wlandev->msdstate = WLAN_MSD_HWPRESENT;
926 result = prism2sta_ifstate(wlandev, P80211ENUM_ifstate_fwload);
927 if (result != P80211ENUM_resultcode_success) {
928 WLAN_LOG_ERROR("prism2sta_ifstate(fwload) failed,"
929 "P80211ENUM_resultcode=%d\n", result);
930 msg->resultcode.data =
931 P80211ENUM_resultcode_implementation_failure;
940 /*----------------------------------------------------------------
941 * prism2mgmt_flashdl_write
946 * wlandev wlan device structure
947 * msgp ptr to msg buffer
951 * <0 success, but we're waiting for something to finish.
952 * >0 an error occurred while handling the message.
956 * process thread (usually)
957 ----------------------------------------------------------------*/
958 int prism2mgmt_flashdl_write(wlandevice_t *wlandev, void *msgp)
960 hfa384x_t *hw = wlandev->priv;
961 p80211msg_p2req_flashdl_write_t *msg = msgp;
966 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
968 "flashdl_write(): may only be called "
969 "in the fwload state.\n");
970 msg->resultcode.data =
971 P80211ENUM_resultcode_implementation_failure;
972 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
977 ** Note: Interrupts are locked out if this is an AP and are NOT
978 ** locked out if this is a station.
981 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
982 /* first validate the length */
983 if ( msg->len.data > sizeof(msg->data.data) ) {
984 msg->resultcode.status =
985 P80211ENUM_resultcode_invalid_parameters;
988 /* call the hfa384x function to do the write */
989 addr = msg->addr.data;
991 buf = msg->data.data;
992 if ( hfa384x_drvr_flashdl_write(hw, addr, buf, len) ) {
993 msg->resultcode.data = P80211ENUM_resultcode_refused;
996 msg->resultcode.data = P80211ENUM_resultcode_success;
1001 /*----------------------------------------------------------------
1002 * prism2mgmt_autojoin
1004 * Associate with an ESS.
1007 * wlandev wlan device structure
1008 * msgp ptr to msg buffer
1011 * 0 success and done
1012 * <0 success, but we're waiting for something to finish.
1013 * >0 an error occurred while handling the message.
1017 * process thread (usually)
1019 ----------------------------------------------------------------*/
1020 int prism2mgmt_autojoin(wlandevice_t *wlandev, void *msgp)
1022 hfa384x_t *hw = wlandev->priv;
1026 p80211msg_lnxreq_autojoin_t *msg = msgp;
1027 p80211pstrd_t *pstr;
1029 hfa384x_bytestr_t *p2bytestr = (hfa384x_bytestr_t*)bytebuf;
1031 wlandev->macmode = WLAN_MACMODE_NONE;
1034 memcpy(&wlandev->ssid, &msg->ssid.data, sizeof(msg->ssid.data));
1036 /* Disable the Port */
1037 hfa384x_drvr_disable(hw, 0);
1040 /* Set the TxRates */
1041 hfa384x_drvr_setconfig16(hw, HFA384x_RID_TXRATECNTL, 0x000f);
1043 /* Set the auth type */
1044 if ( msg->authtype.data == P80211ENUM_authalg_sharedkey ) {
1045 reg = HFA384x_CNFAUTHENTICATION_SHAREDKEY;
1047 reg = HFA384x_CNFAUTHENTICATION_OPENSYSTEM;
1049 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFAUTHENTICATION, reg);
1052 memset(bytebuf, 0, 256);
1053 pstr = (p80211pstrd_t*)&(msg->ssid.data);
1054 prism2mgmt_pstr2bytestr(p2bytestr, pstr);
1055 result = hfa384x_drvr_setconfig(
1056 hw, HFA384x_RID_CNFDESIREDSSID,
1057 bytebuf, HFA384x_RID_CNFDESIREDSSID_LEN);
1059 /* we can use the new-fangled auto-unknown mode if the firmware
1060 is 1.3.3 or newer */
1061 if (HFA384x_FIRMARE_VERSION(hw->ident_sta_fw.major,
1062 hw->ident_sta_fw.minor,
1063 hw->ident_sta_fw.variant) >=
1064 HFA384x_FIRMWARE_VERSION(1,3,3)) {
1065 /* Set up the IBSS options */
1066 reg = HFA384x_CREATEIBSS_JOINESS_JOINCREATEIBSS;
1067 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CREATEIBSS, reg);
1069 /* Set the PortType */
1070 port_type = HFA384x_PORTTYPE_IBSS;
1072 port_type = HFA384x_PORTTYPE_BSS;
1075 port_type = HFA384x_PORTTYPE_BSS;
1077 /* Set the PortType */
1078 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFPORTTYPE, port_type);
1080 /* Enable the Port */
1081 hfa384x_drvr_enable(hw, 0);
1083 /* Set the resultcode */
1084 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
1085 msg->resultcode.data = P80211ENUM_resultcode_success;
1091 /*----------------------------------------------------------------
1092 * prism2mgmt_wlansniff
1094 * Start or stop sniffing.
1097 * wlandev wlan device structure
1098 * msgp ptr to msg buffer
1101 * 0 success and done
1102 * <0 success, but we're waiting for something to finish.
1103 * >0 an error occurred while handling the message.
1107 * process thread (usually)
1109 ----------------------------------------------------------------*/
1110 int prism2mgmt_wlansniff(wlandevice_t *wlandev, void *msgp)
1113 p80211msg_lnxreq_wlansniff_t *msg = msgp;
1115 hfa384x_t *hw = wlandev->priv;
1118 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
1119 switch (msg->enable.data)
1121 case P80211ENUM_truth_false:
1122 /* Confirm that we're in monitor mode */
1123 if ( wlandev->netdev->type == ARPHRD_ETHER ) {
1124 msg->resultcode.data = P80211ENUM_resultcode_invalid_parameters;
1128 /* Disable monitor mode */
1129 result = hfa384x_cmd_monitor(hw, HFA384x_MONITOR_DISABLE);
1132 "failed to disable monitor mode, result=%d\n",
1136 /* Disable port 0 */
1137 result = hfa384x_drvr_disable(hw, 0);
1140 "failed to disable port 0 after sniffing, result=%d\n",
1144 /* Clear the driver state */
1145 wlandev->netdev->type = ARPHRD_ETHER;
1147 /* Restore the wepflags */
1148 result = hfa384x_drvr_setconfig16(hw,
1149 HFA384x_RID_CNFWEPFLAGS,
1150 hw->presniff_wepflags);
1153 "failed to restore wepflags=0x%04x, result=%d\n",
1154 hw->presniff_wepflags,
1159 /* Set the port to its prior type and enable (if necessary) */
1160 if (hw->presniff_port_type != 0 ) {
1161 word = hw->presniff_port_type;
1162 result = hfa384x_drvr_setconfig16(hw,
1163 HFA384x_RID_CNFPORTTYPE, word);
1166 "failed to restore porttype, result=%d\n",
1171 /* Enable the port */
1172 result = hfa384x_drvr_enable(hw, 0);
1174 WLAN_LOG_DEBUG(1, "failed to enable port to presniff setting, result=%d\n", result);
1178 result = hfa384x_drvr_disable(hw, 0);
1182 WLAN_LOG_INFO("monitor mode disabled\n");
1183 msg->resultcode.data = P80211ENUM_resultcode_success;
1187 case P80211ENUM_truth_true:
1188 /* Disable the port (if enabled), only check Port 0 */
1189 if ( hw->port_enabled[0]) {
1190 if (wlandev->netdev->type == ARPHRD_ETHER) {
1191 /* Save macport 0 state */
1192 result = hfa384x_drvr_getconfig16(hw,
1193 HFA384x_RID_CNFPORTTYPE,
1194 &(hw->presniff_port_type));
1196 WLAN_LOG_DEBUG(1,"failed to read porttype, result=%d\n", result);
1199 /* Save the wepflags state */
1200 result = hfa384x_drvr_getconfig16(hw,
1201 HFA384x_RID_CNFWEPFLAGS,
1202 &(hw->presniff_wepflags));
1204 WLAN_LOG_DEBUG(1,"failed to read wepflags, result=%d\n", result);
1207 hfa384x_drvr_stop(hw);
1208 result = hfa384x_drvr_start(hw);
1211 "failed to restart the card for sniffing, result=%d\n",
1216 /* Disable the port */
1217 result = hfa384x_drvr_disable(hw, 0);
1220 "failed to enable port for sniffing, result=%d\n",
1226 hw->presniff_port_type = 0;
1229 /* Set the channel we wish to sniff */
1230 word = msg->channel.data;
1231 result = hfa384x_drvr_setconfig16(hw,
1232 HFA384x_RID_CNFOWNCHANNEL, word);
1233 hw->sniff_channel=word;
1237 "failed to set channel %d, result=%d\n",
1243 /* Now if we're already sniffing, we can skip the rest */
1244 if (wlandev->netdev->type != ARPHRD_ETHER) {
1245 /* Set the port type to pIbss */
1246 word = HFA384x_PORTTYPE_PSUEDOIBSS;
1247 result = hfa384x_drvr_setconfig16(hw,
1248 HFA384x_RID_CNFPORTTYPE, word);
1251 "failed to set porttype %d, result=%d\n",
1256 if ((msg->keepwepflags.status == P80211ENUM_msgitem_status_data_ok) && (msg->keepwepflags.data != P80211ENUM_truth_true)) {
1257 /* Set the wepflags for no decryption */
1258 word = HFA384x_WEPFLAGS_DISABLE_TXCRYPT |
1259 HFA384x_WEPFLAGS_DISABLE_RXCRYPT;
1260 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFWEPFLAGS, word);
1265 "failed to set wepflags=0x%04x, result=%d\n",
1272 /* Do we want to strip the FCS in monitor mode? */
1273 if ((msg->stripfcs.status == P80211ENUM_msgitem_status_data_ok) && (msg->stripfcs.data == P80211ENUM_truth_true)) {
1279 /* Do we want to truncate the packets? */
1280 if (msg->packet_trunc.status == P80211ENUM_msgitem_status_data_ok) {
1281 hw->sniff_truncate = msg->packet_trunc.data;
1283 hw->sniff_truncate = 0;
1286 /* Enable the port */
1287 result = hfa384x_drvr_enable(hw, 0);
1290 "failed to enable port for sniffing, result=%d\n",
1294 /* Enable monitor mode */
1295 result = hfa384x_cmd_monitor(hw, HFA384x_MONITOR_ENABLE);
1298 "failed to enable monitor mode, result=%d\n",
1303 if (wlandev->netdev->type == ARPHRD_ETHER) {
1304 WLAN_LOG_INFO("monitor mode enabled\n");
1307 /* Set the driver state */
1308 /* Do we want the prism2 header? */
1309 if ((msg->prismheader.status == P80211ENUM_msgitem_status_data_ok) && (msg->prismheader.data == P80211ENUM_truth_true)) {
1311 wlandev->netdev->type = ARPHRD_IEEE80211_PRISM;
1312 } else if ((msg->wlanheader.status == P80211ENUM_msgitem_status_data_ok) && (msg->wlanheader.data == P80211ENUM_truth_true)) {
1314 wlandev->netdev->type = ARPHRD_IEEE80211_PRISM;
1316 wlandev->netdev->type = ARPHRD_IEEE80211;
1319 msg->resultcode.data = P80211ENUM_resultcode_success;
1324 msg->resultcode.data = P80211ENUM_resultcode_invalid_parameters;
1331 msg->resultcode.data = P80211ENUM_resultcode_refused;