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 UINT16 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 UINT8 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 * Join a specific BSS
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_p2_join(wlandevice_t *wlandev, void *msgp)
532 hfa384x_t *hw = wlandev->priv;
533 p80211msg_p2req_join_t *msg = msgp;
537 hfa384x_bytestr_t *p2bytestr = (hfa384x_bytestr_t*)bytebuf;
538 hfa384x_JoinRequest_data_t joinreq;
541 wlandev->macmode = WLAN_MACMODE_NONE;
543 /* Set the PortType */
544 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
545 msg->resultcode.data = P80211ENUM_resultcode_success;
548 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFPORTTYPE, 1);
550 WLAN_LOG_ERROR("Failed to set Port Type\n");
554 /* Set the auth type */
555 if ( msg->authtype.data == P80211ENUM_authalg_sharedkey ) {
556 reg = HFA384x_CNFAUTHENTICATION_SHAREDKEY;
558 reg = HFA384x_CNFAUTHENTICATION_OPENSYSTEM;
560 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFAUTHENTICATION, reg);
562 WLAN_LOG_ERROR("Failed to set Authentication\n");
566 /* Turn off all roaming */
567 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFROAMINGMODE, 3);
569 WLAN_LOG_ERROR("Failed to Turn off Roaming\n");
575 if ( msg->basicrate1.status == P80211ENUM_msgitem_status_data_ok ) {
576 reg = p80211rate_to_p2bit(msg->basicrate1.data);
578 if ( msg->basicrate2.status == P80211ENUM_msgitem_status_data_ok ) {
579 reg |= p80211rate_to_p2bit(msg->basicrate2.data);
581 if ( msg->basicrate3.status == P80211ENUM_msgitem_status_data_ok ) {
582 reg |= p80211rate_to_p2bit(msg->basicrate3.data);
584 if ( msg->basicrate4.status == P80211ENUM_msgitem_status_data_ok ) {
585 reg |= p80211rate_to_p2bit(msg->basicrate4.data);
587 if ( msg->basicrate5.status == P80211ENUM_msgitem_status_data_ok ) {
588 reg |= p80211rate_to_p2bit(msg->basicrate5.data);
590 if ( msg->basicrate6.status == P80211ENUM_msgitem_status_data_ok ) {
591 reg |= p80211rate_to_p2bit(msg->basicrate6.data);
593 if ( msg->basicrate7.status == P80211ENUM_msgitem_status_data_ok ) {
594 reg |= p80211rate_to_p2bit(msg->basicrate7.data);
596 if ( msg->basicrate8.status == P80211ENUM_msgitem_status_data_ok ) {
597 reg |= p80211rate_to_p2bit(msg->basicrate8.data);
601 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFBASICRATES, reg);
603 WLAN_LOG_ERROR("Failed to set basicrates=%d.\n", reg);
607 /* Operational rates (supprates and txratecontrol) */
609 if ( msg->operationalrate1.status == P80211ENUM_msgitem_status_data_ok ) {
610 reg = p80211rate_to_p2bit(msg->operationalrate1.data);
612 if ( msg->operationalrate2.status == P80211ENUM_msgitem_status_data_ok ) {
613 reg |= p80211rate_to_p2bit(msg->operationalrate2.data);
615 if ( msg->operationalrate3.status == P80211ENUM_msgitem_status_data_ok ) {
616 reg |= p80211rate_to_p2bit(msg->operationalrate3.data);
618 if ( msg->operationalrate4.status == P80211ENUM_msgitem_status_data_ok ) {
619 reg |= p80211rate_to_p2bit(msg->operationalrate4.data);
621 if ( msg->operationalrate5.status == P80211ENUM_msgitem_status_data_ok ) {
622 reg |= p80211rate_to_p2bit(msg->operationalrate5.data);
624 if ( msg->operationalrate6.status == P80211ENUM_msgitem_status_data_ok ) {
625 reg |= p80211rate_to_p2bit(msg->operationalrate6.data);
627 if ( msg->operationalrate7.status == P80211ENUM_msgitem_status_data_ok ) {
628 reg |= p80211rate_to_p2bit(msg->operationalrate7.data);
630 if ( msg->operationalrate8.status == P80211ENUM_msgitem_status_data_ok ) {
631 reg |= p80211rate_to_p2bit(msg->operationalrate8.data);
635 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFSUPPRATES, reg);
637 WLAN_LOG_ERROR("Failed to set supprates=%d.\n", reg);
641 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_TXRATECNTL, reg);
643 WLAN_LOG_ERROR("Failed to set txrates=%d.\n", reg);
648 memset(bytebuf, 0, 256);
649 pstr = (p80211pstrd_t*)&(msg->ssid.data);
650 prism2mgmt_pstr2bytestr(p2bytestr, pstr);
651 result = hfa384x_drvr_setconfig(
652 hw, HFA384x_RID_CNFDESIREDSSID,
653 bytebuf, HFA384x_RID_CNFDESIREDSSID_LEN);
655 WLAN_LOG_ERROR("Failed to set SSID\n");
659 /* Enable the Port */
660 result = hfa384x_cmd_enable(hw, 0);
662 WLAN_LOG_ERROR("Enable macport failed, result=%d.\n", result);
666 /* Fill in the join request */
667 joinreq.channel = msg->channel.data;
668 memcpy( joinreq.bssid, ((unsigned char *) &msg->bssid.data) + 1, WLAN_BSSID_LEN);
669 hw->joinreq = joinreq;
672 /* Send the join request */
673 result = hfa384x_drvr_setconfig( hw,
674 HFA384x_RID_JOINREQUEST,
675 &joinreq, HFA384x_RID_JOINREQUEST_LEN);
677 WLAN_LOG_ERROR("Join request failed, result=%d.\n", result);
683 WLAN_LOG_DEBUG(1, "Failed to set a config option, result=%d\n", result);
684 msg->resultcode.data = P80211ENUM_resultcode_invalid_parameters;
693 /*----------------------------------------------------------------
694 * prism2mgmt_associate
696 * Associate with an ESS.
699 * wlandev wlan device structure
700 * msgp ptr to msg buffer
704 * <0 success, but we're waiting for something to finish.
705 * >0 an error occurred while handling the message.
709 * process thread (usually)
711 ----------------------------------------------------------------*/
712 int prism2mgmt_associate(wlandevice_t *wlandev, void *msgp)
714 hfa384x_t *hw = wlandev->priv;
716 p80211msg_dot11req_associate_t *msg = msgp;
720 /* Set the TxRates */
722 hfa384x_drvr_setconfig16(hw, HFA384x_RID_TXRATECNTL, reg);
725 /* Set the PortType */
727 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFPORTTYPE, 1);
729 /* Enable the Port */
730 hfa384x_drvr_enable(hw, 0);
732 /* Set the resultcode */
733 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
734 msg->resultcode.data = P80211ENUM_resultcode_success;
740 /*----------------------------------------------------------------
743 * Reset the MAC and MSD. The p80211 layer has it's own handling
744 * that should be done before and after this function.
746 * - disable system interrupts ??
747 * - disable MAC interrupts
748 * - restore system interrupts
749 * - issue the MAC initialize command
750 * - clear any MSD level state (including timers, queued events,
751 * etc.). Note that if we're removing timer'd/queue events, we may
752 * need to have remained in the system interrupt disabled state.
753 * We should be left in the same state that we're in following
754 * driver initialization.
757 * wlandev wlan device structure
758 * msgp ptr to msg buffer, MAY BE NULL! for a driver local
763 * <0 success, but we're waiting for something to finish.
764 * >0 an error occurred while handling the message.
768 * process thread, commonly wlanctl, but might be rmmod/pci_close.
769 ----------------------------------------------------------------*/
770 int prism2mgmt_reset(wlandevice_t *wlandev, void *msgp)
773 hfa384x_t *hw = wlandev->priv;
774 p80211msg_dot11req_reset_t *msg = msgp;
778 * This is supported on both AP and STA and it's not allowed
782 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
783 msg->resultcode.data = P80211ENUM_resultcode_success;
784 WLAN_LOG_INFO("dot11req_reset: the macaddress and "
785 "setdefaultmib arguments are currently unsupported.\n");
789 * If we got this far, the MSD must be in the MSDRUNNING state
790 * therefore, we must stop and then restart the hw/MAC combo.
792 hfa384x_drvr_stop(hw);
793 result = hfa384x_drvr_start(hw);
795 WLAN_LOG_ERROR("dot11req_reset: Initialize command failed,"
796 " bad things will happen from here.\n");
805 /*----------------------------------------------------------------
808 * Start a BSS. Any station can do this for IBSS, only AP for ESS.
811 * wlandev wlan device structure
812 * msgp ptr to msg buffer
816 * <0 success, but we're waiting for something to finish.
817 * >0 an error occurred while handling the message.
821 * process thread (usually)
823 ----------------------------------------------------------------*/
824 int prism2mgmt_start(wlandevice_t *wlandev, void *msgp)
827 hfa384x_t *hw = wlandev->priv;
828 p80211msg_dot11req_start_t *msg = msgp;
832 hfa384x_bytestr_t *p2bytestr = (hfa384x_bytestr_t*)bytebuf;
836 wlandev->macmode = WLAN_MACMODE_NONE;
839 memcpy(&wlandev->ssid, &msg->ssid.data, sizeof(msg->ssid.data));
842 /* see if current f/w is less than 8c3 */
843 if (HFA384x_FIRMWARE_VERSION(hw->ident_sta_fw.major,
844 hw->ident_sta_fw.minor,
845 hw->ident_sta_fw.variant) <
846 HFA384x_FIRMWARE_VERSION(0,8,3)) {
847 /* Ad-Hoc not quite supported on Prism2 */
848 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
849 msg->resultcode.data = P80211ENUM_resultcode_not_supported;
853 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
856 /* Set the REQUIRED config items */
858 pstr = (p80211pstrd_t*)&(msg->ssid.data);
859 prism2mgmt_pstr2bytestr(p2bytestr, pstr);
860 result = hfa384x_drvr_setconfig( hw, HFA384x_RID_CNFOWNSSID,
861 bytebuf, HFA384x_RID_CNFOWNSSID_LEN);
863 WLAN_LOG_ERROR("Failed to set CnfOwnSSID\n");
866 result = hfa384x_drvr_setconfig( hw, HFA384x_RID_CNFDESIREDSSID,
867 bytebuf, HFA384x_RID_CNFDESIREDSSID_LEN);
869 WLAN_LOG_ERROR("Failed to set CnfDesiredSSID\n");
873 /* bsstype - we use the default in the ap firmware */
875 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFPORTTYPE, 0);
878 word = msg->beaconperiod.data;
879 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFAPBCNINT, word);
881 WLAN_LOG_ERROR("Failed to set beacon period=%d.\n", word);
886 word = msg->dschannel.data;
887 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFOWNCHANNEL, word);
889 WLAN_LOG_ERROR("Failed to set channel=%d.\n", word);
893 word = p80211rate_to_p2bit(msg->basicrate1.data);
894 if ( msg->basicrate2.status == P80211ENUM_msgitem_status_data_ok ) {
895 word |= p80211rate_to_p2bit(msg->basicrate2.data);
897 if ( msg->basicrate3.status == P80211ENUM_msgitem_status_data_ok ) {
898 word |= p80211rate_to_p2bit(msg->basicrate3.data);
900 if ( msg->basicrate4.status == P80211ENUM_msgitem_status_data_ok ) {
901 word |= p80211rate_to_p2bit(msg->basicrate4.data);
903 if ( msg->basicrate5.status == P80211ENUM_msgitem_status_data_ok ) {
904 word |= p80211rate_to_p2bit(msg->basicrate5.data);
906 if ( msg->basicrate6.status == P80211ENUM_msgitem_status_data_ok ) {
907 word |= p80211rate_to_p2bit(msg->basicrate6.data);
909 if ( msg->basicrate7.status == P80211ENUM_msgitem_status_data_ok ) {
910 word |= p80211rate_to_p2bit(msg->basicrate7.data);
912 if ( msg->basicrate8.status == P80211ENUM_msgitem_status_data_ok ) {
913 word |= p80211rate_to_p2bit(msg->basicrate8.data);
915 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFBASICRATES, word);
917 WLAN_LOG_ERROR("Failed to set basicrates=%d.\n", word);
921 /* Operational rates (supprates and txratecontrol) */
922 word = p80211rate_to_p2bit(msg->operationalrate1.data);
923 if ( msg->operationalrate2.status == P80211ENUM_msgitem_status_data_ok ) {
924 word |= p80211rate_to_p2bit(msg->operationalrate2.data);
926 if ( msg->operationalrate3.status == P80211ENUM_msgitem_status_data_ok ) {
927 word |= p80211rate_to_p2bit(msg->operationalrate3.data);
929 if ( msg->operationalrate4.status == P80211ENUM_msgitem_status_data_ok ) {
930 word |= p80211rate_to_p2bit(msg->operationalrate4.data);
932 if ( msg->operationalrate5.status == P80211ENUM_msgitem_status_data_ok ) {
933 word |= p80211rate_to_p2bit(msg->operationalrate5.data);
935 if ( msg->operationalrate6.status == P80211ENUM_msgitem_status_data_ok ) {
936 word |= p80211rate_to_p2bit(msg->operationalrate6.data);
938 if ( msg->operationalrate7.status == P80211ENUM_msgitem_status_data_ok ) {
939 word |= p80211rate_to_p2bit(msg->operationalrate7.data);
941 if ( msg->operationalrate8.status == P80211ENUM_msgitem_status_data_ok ) {
942 word |= p80211rate_to_p2bit(msg->operationalrate8.data);
944 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFSUPPRATES, word);
946 WLAN_LOG_ERROR("Failed to set supprates=%d.\n", word);
950 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_TXRATECNTL, word);
952 WLAN_LOG_ERROR("Failed to set txrates=%d.\n", word);
956 /* Set the macmode so the frame setup code knows what to do */
957 if ( msg->bsstype.data == P80211ENUM_bsstype_independent ) {
958 wlandev->macmode = WLAN_MACMODE_IBSS_STA;
959 /* lets extend the data length a bit */
960 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFMAXDATALEN, 2304);
963 /* Enable the Port */
964 result = hfa384x_drvr_enable(hw, 0);
966 WLAN_LOG_ERROR("Enable macport failed, result=%d.\n", result);
970 msg->resultcode.data = P80211ENUM_resultcode_success;
974 WLAN_LOG_DEBUG(1, "Failed to set a config option, result=%d\n", result);
975 msg->resultcode.data = P80211ENUM_resultcode_invalid_parameters;
984 /*----------------------------------------------------------------
987 * Collect the PDA data and put it in the message.
990 * wlandev wlan device structure
991 * msgp ptr to msg buffer
995 * <0 success, but we're waiting for something to finish.
996 * >0 an error occurred while handling the message.
1000 * process thread (usually)
1001 ----------------------------------------------------------------*/
1002 int prism2mgmt_readpda(wlandevice_t *wlandev, void *msgp)
1004 hfa384x_t *hw = wlandev->priv;
1005 p80211msg_p2req_readpda_t *msg = msgp;
1009 /* We only support collecting the PDA when in the FWLOAD
1012 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
1014 "PDA may only be read "
1015 "in the fwload state.\n");
1016 msg->resultcode.data =
1017 P80211ENUM_resultcode_implementation_failure;
1018 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
1020 /* Call drvr_readpda(), it handles the auxport enable
1021 * and validating the returned PDA.
1023 result = hfa384x_drvr_readpda(
1026 HFA384x_PDA_LEN_MAX);
1029 "hfa384x_drvr_readpda() failed, "
1033 msg->resultcode.data =
1034 P80211ENUM_resultcode_implementation_failure;
1035 msg->resultcode.status =
1036 P80211ENUM_msgitem_status_data_ok;
1040 msg->pda.status = P80211ENUM_msgitem_status_data_ok;
1041 msg->resultcode.data = P80211ENUM_resultcode_success;
1042 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
1049 /*----------------------------------------------------------------
1050 * prism2mgmt_readcis
1052 * Collect the CIS data and put it in the message.
1055 * wlandev wlan device structure
1056 * msgp ptr to msg buffer
1059 * 0 success and done
1060 * <0 success, but we're waiting for something to finish.
1061 * >0 an error occurred while handling the message.
1065 * process thread (usually)
1066 ----------------------------------------------------------------*/
1067 int prism2mgmt_readcis(wlandevice_t *wlandev, void *msgp)
1070 hfa384x_t *hw = wlandev->priv;
1071 p80211msg_p2req_readcis_t *msg = msgp;
1075 memset(msg->cis.data, 0, sizeof(msg->cis.data));
1077 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_CIS,
1078 msg->cis.data, HFA384x_RID_CIS_LEN);
1080 WLAN_LOG_INFO("prism2mgmt_readcis: read(cis) failed.\n");
1081 msg->cis.status = P80211ENUM_msgitem_status_no_value;
1082 msg->resultcode.data = P80211ENUM_resultcode_implementation_failure;
1086 msg->cis.status = P80211ENUM_msgitem_status_data_ok;
1087 msg->resultcode.data = P80211ENUM_resultcode_success;
1090 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
1096 /*----------------------------------------------------------------
1097 * prism2mgmt_auxport_state
1099 * Enables/Disables the card's auxiliary port. Should be called
1100 * before and after a sequence of auxport_read()/auxport_write()
1104 * wlandev wlan device structure
1105 * msgp ptr to msg buffer
1108 * 0 success and done
1109 * <0 success, but we're waiting for something to finish.
1110 * >0 an error occurred while handling the message.
1114 * process thread (usually)
1115 ----------------------------------------------------------------*/
1116 int prism2mgmt_auxport_state(wlandevice_t *wlandev, void *msgp)
1118 p80211msg_p2req_auxport_state_t *msg = msgp;
1122 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
1123 msg->resultcode.data = P80211ENUM_resultcode_not_supported;
1130 /*----------------------------------------------------------------
1131 * prism2mgmt_auxport_read
1133 * Copies data from the card using the auxport. The auxport must
1134 * have previously been enabled. Note: this is not the way to
1135 * do downloads, see the [ram|flash]dl functions.
1138 * wlandev wlan device structure
1139 * msgp ptr to msg buffer
1142 * 0 success and done
1143 * <0 success, but we're waiting for something to finish.
1144 * >0 an error occurred while handling the message.
1148 * process thread (usually)
1149 ----------------------------------------------------------------*/
1150 int prism2mgmt_auxport_read(wlandevice_t *wlandev, void *msgp)
1154 WLAN_LOG_ERROR("prism2mgmt_auxport_read: Not supported on USB.\n");
1161 /*----------------------------------------------------------------
1162 * prism2mgmt_auxport_write
1164 * Copies data to the card using the auxport. The auxport must
1165 * have previously been enabled. Note: this is not the way to
1166 * do downloads, see the [ram|flash]dl functions.
1169 * wlandev wlan device structure
1170 * msgp ptr to msg buffer
1173 * 0 success and done
1174 * <0 success, but we're waiting for something to finish.
1175 * >0 an error occurred while handling the message.
1179 * process thread (usually)
1180 ----------------------------------------------------------------*/
1181 int prism2mgmt_auxport_write(wlandevice_t *wlandev, void *msgp)
1184 WLAN_LOG_ERROR("prism2mgmt_auxport_read: Not supported on USB.\n");
1189 /*----------------------------------------------------------------
1190 * prism2mgmt_low_level
1192 * Puts the card into the desired test mode.
1195 * wlandev wlan device structure
1196 * msgp ptr to msg buffer
1199 * 0 success and done
1200 * <0 success, but we're waiting for something to finish.
1201 * >0 an error occurred while handling the message.
1205 * process thread (usually)
1206 ----------------------------------------------------------------*/
1207 int prism2mgmt_low_level(wlandevice_t *wlandev, void *msgp)
1209 hfa384x_t *hw = wlandev->priv;
1210 p80211msg_p2req_low_level_t *msg = msgp;
1211 hfa384x_metacmd_t cmd;
1214 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
1216 /* call some routine to execute the test command */
1217 cmd.cmd = (UINT16) msg->command.data;
1218 cmd.parm0 = (UINT16) msg->param0.data;
1219 cmd.parm1 = (UINT16) msg->param1.data;
1220 cmd.parm2 = (UINT16) msg->param2.data;
1222 hfa384x_drvr_low_level(hw,&cmd);
1224 msg->resp0.data = (UINT32) cmd.result.resp0;
1225 msg->resp1.data = (UINT32) cmd.result.resp1;
1226 msg->resp2.data = (UINT32) cmd.result.resp2;
1228 msg->resultcode.data = P80211ENUM_resultcode_success;
1234 /*----------------------------------------------------------------
1235 * prism2mgmt_test_command
1237 * Puts the card into the desired test mode.
1240 * wlandev wlan device structure
1241 * msgp ptr to msg buffer
1244 * 0 success and done
1245 * <0 success, but we're waiting for something to finish.
1246 * >0 an error occurred while handling the message.
1250 * process thread (usually)
1251 ----------------------------------------------------------------*/
1252 int prism2mgmt_test_command(wlandevice_t *wlandev, void *msgp)
1254 hfa384x_t *hw = wlandev->priv;
1255 p80211msg_p2req_test_command_t *msg = msgp;
1256 hfa384x_metacmd_t cmd;
1260 cmd.cmd = ((UINT16) msg->testcode.data) << 8 | 0x38;
1261 cmd.parm0 = (UINT16) msg->testparam.data;
1265 /* call some routine to execute the test command */
1267 hfa384x_drvr_low_level(hw,&cmd);
1269 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
1270 msg->resultcode.data = P80211ENUM_resultcode_success;
1272 msg->status.status = P80211ENUM_msgitem_status_data_ok;
1273 msg->status.data = cmd.result.status;
1274 msg->resp0.status = P80211ENUM_msgitem_status_data_ok;
1275 msg->resp0.data = cmd.result.resp0;
1276 msg->resp1.status = P80211ENUM_msgitem_status_data_ok;
1277 msg->resp1.data = cmd.result.resp1;
1278 msg->resp2.status = P80211ENUM_msgitem_status_data_ok;
1279 msg->resp2.data = cmd.result.resp2;
1286 /*----------------------------------------------------------------
1287 * prism2mgmt_mmi_read
1289 * Read from one of the MMI registers.
1292 * wlandev wlan device structure
1293 * msgp ptr to msg buffer
1296 * 0 success and done
1297 * <0 success, but we're waiting for something to finish.
1298 * >0 an error occurred while handling the message.
1302 * process thread (usually)
1303 ----------------------------------------------------------------*/
1304 int prism2mgmt_mmi_read(wlandevice_t *wlandev, void *msgp)
1306 hfa384x_t *hw = wlandev->priv;
1307 p80211msg_p2req_mmi_read_t *msg = msgp;
1312 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
1314 /* call some routine to execute the test command */
1316 hfa384x_drvr_mmi_read(hw, msg->addr.data, &resp);
1318 /* I'm not sure if this is "architecturally" correct, but it
1321 msg->value.status = P80211ENUM_msgitem_status_data_ok;
1322 msg->value.data = resp;
1323 msg->resultcode.data = P80211ENUM_resultcode_success;
1329 /*----------------------------------------------------------------
1330 * prism2mgmt_mmi_write
1332 * Write a data value to one of the MMI registers.
1335 * wlandev wlan device structure
1336 * msgp ptr to msg buffer
1339 * 0 success and done
1340 * <0 success, but we're waiting for something to finish.
1341 * >0 an error occurred while handling the message.
1345 * process thread (usually)
1346 ----------------------------------------------------------------*/
1347 int prism2mgmt_mmi_write(wlandevice_t *wlandev, void *msgp)
1349 hfa384x_t *hw = wlandev->priv;
1350 p80211msg_p2req_mmi_write_t *msg = msgp;
1353 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
1355 /* call some routine to execute the test command */
1357 hfa384x_drvr_mmi_write(hw, msg->addr.data, msg->data.data);
1359 msg->resultcode.data = P80211ENUM_resultcode_success;
1365 /*----------------------------------------------------------------
1366 * prism2mgmt_ramdl_state
1368 * Establishes the beginning/end of a card RAM download session.
1370 * It is expected that the ramdl_write() function will be called
1371 * one or more times between the 'enable' and 'disable' calls to
1374 * Note: This function should not be called when a mac comm port
1378 * wlandev wlan device structure
1379 * msgp ptr to msg buffer
1382 * 0 success and done
1383 * <0 success, but we're waiting for something to finish.
1384 * >0 an error occurred while handling the message.
1388 * process thread (usually)
1389 ----------------------------------------------------------------*/
1390 int prism2mgmt_ramdl_state(wlandevice_t *wlandev, void *msgp)
1392 hfa384x_t *hw = wlandev->priv;
1393 p80211msg_p2req_ramdl_state_t *msg = msgp;
1396 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
1398 "ramdl_state(): may only be called "
1399 "in the fwload state.\n");
1400 msg->resultcode.data =
1401 P80211ENUM_resultcode_implementation_failure;
1402 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
1408 ** Note: Interrupts are locked out if this is an AP and are NOT
1409 ** locked out if this is a station.
1412 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
1413 if ( msg->enable.data == P80211ENUM_truth_true ) {
1414 if ( hfa384x_drvr_ramdl_enable(hw, msg->exeaddr.data) ) {
1415 msg->resultcode.data = P80211ENUM_resultcode_implementation_failure;
1417 msg->resultcode.data = P80211ENUM_resultcode_success;
1420 hfa384x_drvr_ramdl_disable(hw);
1421 msg->resultcode.data = P80211ENUM_resultcode_success;
1429 /*----------------------------------------------------------------
1430 * prism2mgmt_ramdl_write
1432 * Writes a buffer to the card RAM using the download state. This
1433 * is for writing code to card RAM. To just read or write raw data
1434 * use the aux functions.
1437 * wlandev wlan device structure
1438 * msgp ptr to msg buffer
1441 * 0 success and done
1442 * <0 success, but we're waiting for something to finish.
1443 * >0 an error occurred while handling the message.
1447 * process thread (usually)
1448 ----------------------------------------------------------------*/
1449 int prism2mgmt_ramdl_write(wlandevice_t *wlandev, void *msgp)
1451 hfa384x_t *hw = wlandev->priv;
1452 p80211msg_p2req_ramdl_write_t *msg = msgp;
1458 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
1460 "ramdl_write(): may only be called "
1461 "in the fwload state.\n");
1462 msg->resultcode.data =
1463 P80211ENUM_resultcode_implementation_failure;
1464 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
1469 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
1470 /* first validate the length */
1471 if ( msg->len.data > sizeof(msg->data.data) ) {
1472 msg->resultcode.status = P80211ENUM_resultcode_invalid_parameters;
1475 /* call the hfa384x function to do the write */
1476 addr = msg->addr.data;
1477 len = msg->len.data;
1478 buf = msg->data.data;
1479 if ( hfa384x_drvr_ramdl_write(hw, addr, buf, len) ) {
1480 msg->resultcode.data = P80211ENUM_resultcode_refused;
1483 msg->resultcode.data = P80211ENUM_resultcode_success;
1490 /*----------------------------------------------------------------
1491 * prism2mgmt_flashdl_state
1493 * Establishes the beginning/end of a card Flash download session.
1495 * It is expected that the flashdl_write() function will be called
1496 * one or more times between the 'enable' and 'disable' calls to
1499 * Note: This function should not be called when a mac comm port
1503 * wlandev wlan device structure
1504 * msgp ptr to msg buffer
1507 * 0 success and done
1508 * <0 success, but we're waiting for something to finish.
1509 * >0 an error occurred while handling the message.
1513 * process thread (usually)
1514 ----------------------------------------------------------------*/
1515 int prism2mgmt_flashdl_state(wlandevice_t *wlandev, void *msgp)
1518 hfa384x_t *hw = wlandev->priv;
1519 p80211msg_p2req_flashdl_state_t *msg = msgp;
1522 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
1524 "flashdl_state(): may only be called "
1525 "in the fwload state.\n");
1526 msg->resultcode.data =
1527 P80211ENUM_resultcode_implementation_failure;
1528 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
1534 ** Note: Interrupts are locked out if this is an AP and are NOT
1535 ** locked out if this is a station.
1538 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
1539 if ( msg->enable.data == P80211ENUM_truth_true ) {
1540 if ( hfa384x_drvr_flashdl_enable(hw) ) {
1541 msg->resultcode.data = P80211ENUM_resultcode_implementation_failure;
1543 msg->resultcode.data = P80211ENUM_resultcode_success;
1546 hfa384x_drvr_flashdl_disable(hw);
1547 msg->resultcode.data = P80211ENUM_resultcode_success;
1548 /* NOTE: At this point, the MAC is in the post-reset
1549 * state and the driver is in the fwload state.
1550 * We need to get the MAC back into the fwload
1551 * state. To do this, we set the nsdstate to HWPRESENT
1552 * and then call the ifstate function to redo everything
1553 * that got us into the fwload state.
1555 wlandev->msdstate = WLAN_MSD_HWPRESENT;
1556 result = prism2sta_ifstate(wlandev, P80211ENUM_ifstate_fwload);
1557 if (result != P80211ENUM_resultcode_success) {
1558 WLAN_LOG_ERROR("prism2sta_ifstate(fwload) failed,"
1559 "P80211ENUM_resultcode=%d\n", result);
1560 msg->resultcode.data =
1561 P80211ENUM_resultcode_implementation_failure;
1571 /*----------------------------------------------------------------
1572 * prism2mgmt_flashdl_write
1577 * wlandev wlan device structure
1578 * msgp ptr to msg buffer
1581 * 0 success and done
1582 * <0 success, but we're waiting for something to finish.
1583 * >0 an error occurred while handling the message.
1587 * process thread (usually)
1588 ----------------------------------------------------------------*/
1589 int prism2mgmt_flashdl_write(wlandevice_t *wlandev, void *msgp)
1591 hfa384x_t *hw = wlandev->priv;
1592 p80211msg_p2req_flashdl_write_t *msg = msgp;
1598 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
1600 "flashdl_write(): may only be called "
1601 "in the fwload state.\n");
1602 msg->resultcode.data =
1603 P80211ENUM_resultcode_implementation_failure;
1604 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
1610 ** Note: Interrupts are locked out if this is an AP and are NOT
1611 ** locked out if this is a station.
1614 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
1615 /* first validate the length */
1616 if ( msg->len.data > sizeof(msg->data.data) ) {
1617 msg->resultcode.status =
1618 P80211ENUM_resultcode_invalid_parameters;
1621 /* call the hfa384x function to do the write */
1622 addr = msg->addr.data;
1623 len = msg->len.data;
1624 buf = msg->data.data;
1625 if ( hfa384x_drvr_flashdl_write(hw, addr, buf, len) ) {
1626 msg->resultcode.data = P80211ENUM_resultcode_refused;
1629 msg->resultcode.data = P80211ENUM_resultcode_success;
1636 /*----------------------------------------------------------------
1637 * prism2mgmt_dump_state
1639 * Dumps the driver's and hardware's current state via the kernel
1640 * log at KERN_NOTICE level.
1643 * wlandev wlan device structure
1644 * msgp ptr to msg buffer
1647 * 0 success and done
1648 * <0 success, but we're waiting for something to finish.
1649 * >0 an error occurred while handling the message.
1653 * process thread (usually)
1654 ----------------------------------------------------------------*/
1655 int prism2mgmt_dump_state(wlandevice_t *wlandev, void *msgp)
1657 p80211msg_p2req_dump_state_t *msg = msgp;
1662 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
1663 msg->resultcode.data = P80211ENUM_resultcode_not_supported;
1671 /*----------------------------------------------------------------
1672 * prism2mgmt_autojoin
1674 * Associate with an ESS.
1677 * wlandev wlan device structure
1678 * msgp ptr to msg buffer
1681 * 0 success and done
1682 * <0 success, but we're waiting for something to finish.
1683 * >0 an error occurred while handling the message.
1687 * process thread (usually)
1689 ----------------------------------------------------------------*/
1690 int prism2mgmt_autojoin(wlandevice_t *wlandev, void *msgp)
1692 hfa384x_t *hw = wlandev->priv;
1696 p80211msg_lnxreq_autojoin_t *msg = msgp;
1697 p80211pstrd_t *pstr;
1699 hfa384x_bytestr_t *p2bytestr = (hfa384x_bytestr_t*)bytebuf;
1702 wlandev->macmode = WLAN_MACMODE_NONE;
1705 memcpy(&wlandev->ssid, &msg->ssid.data, sizeof(msg->ssid.data));
1707 /* Disable the Port */
1708 hfa384x_drvr_disable(hw, 0);
1711 /* Set the TxRates */
1712 hfa384x_drvr_setconfig16(hw, HFA384x_RID_TXRATECNTL, 0x000f);
1714 /* Set the auth type */
1715 if ( msg->authtype.data == P80211ENUM_authalg_sharedkey ) {
1716 reg = HFA384x_CNFAUTHENTICATION_SHAREDKEY;
1718 reg = HFA384x_CNFAUTHENTICATION_OPENSYSTEM;
1720 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFAUTHENTICATION, reg);
1723 memset(bytebuf, 0, 256);
1724 pstr = (p80211pstrd_t*)&(msg->ssid.data);
1725 prism2mgmt_pstr2bytestr(p2bytestr, pstr);
1726 result = hfa384x_drvr_setconfig(
1727 hw, HFA384x_RID_CNFDESIREDSSID,
1728 bytebuf, HFA384x_RID_CNFDESIREDSSID_LEN);
1730 /* we can use the new-fangled auto-unknown mode if the firmware
1731 is 1.3.3 or newer */
1732 if (HFA384x_FIRMARE_VERSION(hw->ident_sta_fw.major,
1733 hw->ident_sta_fw.minor,
1734 hw->ident_sta_fw.variant) >=
1735 HFA384x_FIRMWARE_VERSION(1,3,3)) {
1736 /* Set up the IBSS options */
1737 reg = HFA384x_CREATEIBSS_JOINESS_JOINCREATEIBSS;
1738 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CREATEIBSS, reg);
1740 /* Set the PortType */
1741 port_type = HFA384x_PORTTYPE_IBSS;
1743 port_type = HFA384x_PORTTYPE_BSS;
1746 port_type = HFA384x_PORTTYPE_BSS;
1748 /* Set the PortType */
1749 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFPORTTYPE, port_type);
1751 /* Enable the Port */
1752 hfa384x_drvr_enable(hw, 0);
1754 /* Set the resultcode */
1755 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
1756 msg->resultcode.data = P80211ENUM_resultcode_success;
1763 /*----------------------------------------------------------------
1764 * prism2mgmt_wlansniff
1766 * Start or stop sniffing.
1769 * wlandev wlan device structure
1770 * msgp ptr to msg buffer
1773 * 0 success and done
1774 * <0 success, but we're waiting for something to finish.
1775 * >0 an error occurred while handling the message.
1779 * process thread (usually)
1781 ----------------------------------------------------------------*/
1782 int prism2mgmt_wlansniff(wlandevice_t *wlandev, void *msgp)
1785 p80211msg_lnxreq_wlansniff_t *msg = msgp;
1787 hfa384x_t *hw = wlandev->priv;
1792 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
1793 switch (msg->enable.data)
1795 case P80211ENUM_truth_false:
1796 /* Confirm that we're in monitor mode */
1797 if ( wlandev->netdev->type == ARPHRD_ETHER ) {
1798 msg->resultcode.data = P80211ENUM_resultcode_invalid_parameters;
1802 /* Disable monitor mode */
1803 result = hfa384x_cmd_monitor(hw, HFA384x_MONITOR_DISABLE);
1806 "failed to disable monitor mode, result=%d\n",
1810 /* Disable port 0 */
1811 result = hfa384x_drvr_disable(hw, 0);
1814 "failed to disable port 0 after sniffing, result=%d\n",
1818 /* Clear the driver state */
1819 wlandev->netdev->type = ARPHRD_ETHER;
1821 /* Restore the wepflags */
1822 result = hfa384x_drvr_setconfig16(hw,
1823 HFA384x_RID_CNFWEPFLAGS,
1824 hw->presniff_wepflags);
1827 "failed to restore wepflags=0x%04x, result=%d\n",
1828 hw->presniff_wepflags,
1833 /* Set the port to its prior type and enable (if necessary) */
1834 if (hw->presniff_port_type != 0 ) {
1835 word = hw->presniff_port_type;
1836 result = hfa384x_drvr_setconfig16(hw,
1837 HFA384x_RID_CNFPORTTYPE, word);
1840 "failed to restore porttype, result=%d\n",
1845 /* Enable the port */
1846 result = hfa384x_drvr_enable(hw, 0);
1848 WLAN_LOG_DEBUG(1, "failed to enable port to presniff setting, result=%d\n", result);
1852 result = hfa384x_drvr_disable(hw, 0);
1856 WLAN_LOG_INFO("monitor mode disabled\n");
1857 msg->resultcode.data = P80211ENUM_resultcode_success;
1861 case P80211ENUM_truth_true:
1862 /* Disable the port (if enabled), only check Port 0 */
1863 if ( hw->port_enabled[0]) {
1864 if (wlandev->netdev->type == ARPHRD_ETHER) {
1865 /* Save macport 0 state */
1866 result = hfa384x_drvr_getconfig16(hw,
1867 HFA384x_RID_CNFPORTTYPE,
1868 &(hw->presniff_port_type));
1870 WLAN_LOG_DEBUG(1,"failed to read porttype, result=%d\n", result);
1873 /* Save the wepflags state */
1874 result = hfa384x_drvr_getconfig16(hw,
1875 HFA384x_RID_CNFWEPFLAGS,
1876 &(hw->presniff_wepflags));
1878 WLAN_LOG_DEBUG(1,"failed to read wepflags, result=%d\n", result);
1881 hfa384x_drvr_stop(hw);
1882 result = hfa384x_drvr_start(hw);
1885 "failed to restart the card for sniffing, result=%d\n",
1890 /* Disable the port */
1891 result = hfa384x_drvr_disable(hw, 0);
1894 "failed to enable port for sniffing, result=%d\n",
1900 hw->presniff_port_type = 0;
1903 /* Set the channel we wish to sniff */
1904 word = msg->channel.data;
1905 result = hfa384x_drvr_setconfig16(hw,
1906 HFA384x_RID_CNFOWNCHANNEL, word);
1907 hw->sniff_channel=word;
1911 "failed to set channel %d, result=%d\n",
1917 /* Now if we're already sniffing, we can skip the rest */
1918 if (wlandev->netdev->type != ARPHRD_ETHER) {
1919 /* Set the port type to pIbss */
1920 word = HFA384x_PORTTYPE_PSUEDOIBSS;
1921 result = hfa384x_drvr_setconfig16(hw,
1922 HFA384x_RID_CNFPORTTYPE, word);
1925 "failed to set porttype %d, result=%d\n",
1930 if ((msg->keepwepflags.status == P80211ENUM_msgitem_status_data_ok) && (msg->keepwepflags.data != P80211ENUM_truth_true)) {
1931 /* Set the wepflags for no decryption */
1932 word = HFA384x_WEPFLAGS_DISABLE_TXCRYPT |
1933 HFA384x_WEPFLAGS_DISABLE_RXCRYPT;
1934 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFWEPFLAGS, word);
1939 "failed to set wepflags=0x%04x, result=%d\n",
1946 /* Do we want to strip the FCS in monitor mode? */
1947 if ((msg->stripfcs.status == P80211ENUM_msgitem_status_data_ok) && (msg->stripfcs.data == P80211ENUM_truth_true)) {
1953 /* Do we want to truncate the packets? */
1954 if (msg->packet_trunc.status == P80211ENUM_msgitem_status_data_ok) {
1955 hw->sniff_truncate = msg->packet_trunc.data;
1957 hw->sniff_truncate = 0;
1960 /* Enable the port */
1961 result = hfa384x_drvr_enable(hw, 0);
1964 "failed to enable port for sniffing, result=%d\n",
1968 /* Enable monitor mode */
1969 result = hfa384x_cmd_monitor(hw, HFA384x_MONITOR_ENABLE);
1972 "failed to enable monitor mode, result=%d\n",
1977 if (wlandev->netdev->type == ARPHRD_ETHER) {
1978 WLAN_LOG_INFO("monitor mode enabled\n");
1981 /* Set the driver state */
1982 /* Do we want the prism2 header? */
1983 if ((msg->prismheader.status == P80211ENUM_msgitem_status_data_ok) && (msg->prismheader.data == P80211ENUM_truth_true)) {
1985 wlandev->netdev->type = ARPHRD_IEEE80211_PRISM;
1986 } else if ((msg->wlanheader.status == P80211ENUM_msgitem_status_data_ok) && (msg->wlanheader.data == P80211ENUM_truth_true)) {
1988 wlandev->netdev->type = ARPHRD_IEEE80211_PRISM;
1990 wlandev->netdev->type = ARPHRD_IEEE80211;
1993 msg->resultcode.data = P80211ENUM_resultcode_success;
1998 msg->resultcode.data = P80211ENUM_resultcode_invalid_parameters;
2005 msg->resultcode.data = P80211ENUM_resultcode_refused;