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
67 #include <linux/version.h>
69 #include <linux/if_arp.h>
70 #include <linux/module.h>
71 #include <linux/kernel.h>
72 #include <linux/wait.h>
73 #include <linux/sched.h>
74 #include <linux/types.h>
75 #include <linux/slab.h>
76 #include <linux/wireless.h>
77 #include <linux/netdevice.h>
78 #include <linux/delay.h>
80 #include <asm/byteorder.h>
81 #include <linux/random.h>
82 #include <linux/usb.h>
84 #include "wlan_compat.h"
86 /*================================================================*/
87 /* Project Includes */
89 #include "p80211types.h"
90 #include "p80211hdr.h"
91 #include "p80211mgmt.h"
92 #include "p80211conv.h"
93 #include "p80211msg.h"
94 #include "p80211netdev.h"
95 #include "p80211metadef.h"
96 #include "p80211metastruct.h"
98 #include "prism2mgmt.h"
100 /* Converts 802.11 format rate specifications to prism2 */
101 #define p80211rate_to_p2bit(n) ((((n)&~BIT7) == 2) ? BIT0 : \
102 (((n)&~BIT7) == 4) ? BIT1 : \
103 (((n)&~BIT7) == 11) ? BIT2 : \
104 (((n)&~BIT7) == 22) ? BIT3 : 0)
106 /*----------------------------------------------------------------
109 * Initiate a scan for BSSs.
111 * This function corresponds to MLME-scan.request and part of
112 * MLME-scan.confirm. As far as I can tell in the standard, there
113 * are no restrictions on when a scan.request may be issued. We have
114 * to handle in whatever state the driver/MAC happen to be.
117 * wlandev wlan device structure
118 * msgp ptr to msg buffer
122 * <0 success, but we're waiting for something to finish.
123 * >0 an error occurred while handling the message.
127 * process thread (usually)
129 ----------------------------------------------------------------*/
130 int prism2mgmt_scan(wlandevice_t *wlandev, void *msgp)
133 hfa384x_t *hw = wlandev->priv;
134 p80211msg_dot11req_scan_t *msg = msgp;
135 UINT16 roamingmode, word;
139 hfa384x_HostScanRequest_data_t scanreq;
143 /* gatekeeper check */
144 if (HFA384x_FIRMWARE_VERSION(hw->ident_sta_fw.major,
145 hw->ident_sta_fw.minor,
146 hw->ident_sta_fw.variant) <
147 HFA384x_FIRMWARE_VERSION(1,3,2)) {
148 WLAN_LOG_ERROR("HostScan not supported with current firmware (<1.3.2).\n");
150 msg->resultcode.data = P80211ENUM_resultcode_not_supported;
154 memset(&scanreq, 0, sizeof(scanreq));
156 /* save current roaming mode */
157 result = hfa384x_drvr_getconfig16(hw,
158 HFA384x_RID_CNFROAMINGMODE, &roamingmode);
160 WLAN_LOG_ERROR("getconfig(ROAMMODE) failed. result=%d\n",
162 msg->resultcode.data =
163 P80211ENUM_resultcode_implementation_failure;
167 /* drop into mode 3 for the scan */
168 result = hfa384x_drvr_setconfig16(hw,
169 HFA384x_RID_CNFROAMINGMODE,
170 HFA384x_ROAMMODE_HOSTSCAN_HOSTROAM);
172 WLAN_LOG_ERROR("setconfig(ROAMINGMODE) failed. result=%d\n",
174 msg->resultcode.data =
175 P80211ENUM_resultcode_implementation_failure;
179 /* active or passive? */
180 if (HFA384x_FIRMWARE_VERSION(hw->ident_sta_fw.major,
181 hw->ident_sta_fw.minor,
182 hw->ident_sta_fw.variant) >
183 HFA384x_FIRMWARE_VERSION(1,5,0)) {
184 if (msg->scantype.data != P80211ENUM_scantype_active) {
185 word = host2hfa384x_16(msg->maxchanneltime.data);
189 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFPASSIVESCANCTRL, word);
191 WLAN_LOG_WARNING("Passive scan not supported with "
192 "current firmware. (<1.5.1)\n");
196 /* set up the txrate to be 2MBPS. Should be fastest basicrate... */
197 word = HFA384x_RATEBIT_2;
198 scanreq.txRate = host2hfa384x_16(word);
200 /* set up the channel list */
202 for (i = 0; i < msg->channellist.data.len; i++) {
203 UINT8 channel = msg->channellist.data.data[i];
204 if (channel > 14) continue;
205 /* channel 1 is BIT0 ... channel 14 is BIT13 */
206 word |= (1 << (channel-1));
208 scanreq.channelList = host2hfa384x_16(word);
210 /* set up the ssid, if present. */
211 scanreq.ssid.len = host2hfa384x_16(msg->ssid.data.len);
212 memcpy(scanreq.ssid.data, msg->ssid.data.data, msg->ssid.data.len);
214 /* Enable the MAC port if it's not already enabled */
215 result = hfa384x_drvr_getconfig16(hw, HFA384x_RID_PORTSTATUS, &word);
217 WLAN_LOG_ERROR("getconfig(PORTSTATUS) failed. "
218 "result=%d\n", result);
219 msg->resultcode.data =
220 P80211ENUM_resultcode_implementation_failure;
223 if (word == HFA384x_PORTSTATUS_DISABLED) {
226 result = hfa384x_drvr_setconfig16(hw,
227 HFA384x_RID_CNFROAMINGMODE,
228 HFA384x_ROAMMODE_HOSTSCAN_HOSTROAM);
230 WLAN_LOG_ERROR("setconfig(ROAMINGMODE) failed. result=%d\n", result);
231 msg->resultcode.data =
232 P80211ENUM_resultcode_implementation_failure;
235 /* Construct a bogus SSID and assign it to OwnSSID and
238 wordbuf[0] = host2hfa384x_16(WLAN_SSID_MAXLEN);
239 get_random_bytes(&wordbuf[1], WLAN_SSID_MAXLEN);
240 result = hfa384x_drvr_setconfig( hw, HFA384x_RID_CNFOWNSSID,
241 wordbuf, HFA384x_RID_CNFOWNSSID_LEN);
243 WLAN_LOG_ERROR("Failed to set OwnSSID.\n");
244 msg->resultcode.data =
245 P80211ENUM_resultcode_implementation_failure;
248 result = hfa384x_drvr_setconfig( hw, HFA384x_RID_CNFDESIREDSSID,
249 wordbuf, HFA384x_RID_CNFDESIREDSSID_LEN);
251 WLAN_LOG_ERROR("Failed to set DesiredSSID.\n");
252 msg->resultcode.data =
253 P80211ENUM_resultcode_implementation_failure;
257 result = hfa384x_drvr_setconfig16(hw,
258 HFA384x_RID_CNFPORTTYPE,
259 HFA384x_PORTTYPE_IBSS);
261 WLAN_LOG_ERROR("Failed to set CNFPORTTYPE.\n");
262 msg->resultcode.data =
263 P80211ENUM_resultcode_implementation_failure;
267 result = hfa384x_drvr_setconfig16(hw,
268 HFA384x_RID_CREATEIBSS,
269 HFA384x_CREATEIBSS_JOINCREATEIBSS);
271 WLAN_LOG_ERROR("Failed to set CREATEIBSS.\n");
272 msg->resultcode.data =
273 P80211ENUM_resultcode_implementation_failure;
276 result = hfa384x_drvr_enable(hw, 0);
278 WLAN_LOG_ERROR("drvr_enable(0) failed. "
279 "result=%d\n", result);
280 msg->resultcode.data =
281 P80211ENUM_resultcode_implementation_failure;
287 /* Figure out our timeout first Kus, then HZ */
288 timeout = msg->channellist.data.len * msg->maxchanneltime.data;
289 timeout = (timeout * HZ)/1000;
291 /* Issue the scan request */
294 WLAN_HEX_DUMP(5,"hscanreq", &scanreq, sizeof(scanreq));
296 result = hfa384x_drvr_setconfig( hw,
297 HFA384x_RID_HOSTSCAN, &scanreq,
298 sizeof(hfa384x_HostScanRequest_data_t));
300 WLAN_LOG_ERROR("setconfig(SCANREQUEST) failed. result=%d\n",
302 msg->resultcode.data =
303 P80211ENUM_resultcode_implementation_failure;
307 /* sleep until info frame arrives */
308 wait_event_interruptible_timeout(hw->cmdq, hw->scanflag, timeout);
310 msg->numbss.status = P80211ENUM_msgitem_status_data_ok;
311 if (hw->scanflag == -1)
314 msg->numbss.data = hw->scanflag;
318 /* Disable port if we temporarily enabled it. */
320 result = hfa384x_drvr_disable(hw, 0);
322 WLAN_LOG_ERROR("drvr_disable(0) failed. "
323 "result=%d\n", result);
324 msg->resultcode.data =
325 P80211ENUM_resultcode_implementation_failure;
330 /* restore original roaming mode */
331 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFROAMINGMODE,
334 WLAN_LOG_ERROR("setconfig(ROAMMODE) failed. result=%d\n",
336 msg->resultcode.data =
337 P80211ENUM_resultcode_implementation_failure;
342 msg->resultcode.data = P80211ENUM_resultcode_success;
345 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
352 /*----------------------------------------------------------------
353 * prism2mgmt_scan_results
355 * Retrieve the BSS description for one of the BSSs identified in
359 * wlandev wlan device structure
360 * msgp ptr to msg buffer
364 * <0 success, but we're waiting for something to finish.
365 * >0 an error occurred while handling the message.
369 * process thread (usually)
371 ----------------------------------------------------------------*/
372 int prism2mgmt_scan_results(wlandevice_t *wlandev, void *msgp)
375 p80211msg_dot11req_scan_results_t *req;
376 hfa384x_t *hw = wlandev->priv;
377 hfa384x_HScanResultSub_t *item = NULL;
383 req = (p80211msg_dot11req_scan_results_t *) msgp;
385 req->resultcode.status = P80211ENUM_msgitem_status_data_ok;
387 if (! hw->scanresults) {
388 WLAN_LOG_ERROR("dot11req_scan_results can only be used after a successful dot11req_scan.\n");
390 req->resultcode.data = P80211ENUM_resultcode_invalid_parameters;
394 count = (hw->scanresults->framelen - 3) / 32;
395 if (count > 32) count = 32;
397 if (req->bssindex.data >= count) {
398 WLAN_LOG_DEBUG(0, "requested index (%d) out of range (%d)\n",
399 req->bssindex.data, count);
401 req->resultcode.data = P80211ENUM_resultcode_invalid_parameters;
405 item = &(hw->scanresults->info.hscanresult.result[req->bssindex.data]);
406 /* signal and noise */
407 req->signal.status = P80211ENUM_msgitem_status_data_ok;
408 req->noise.status = P80211ENUM_msgitem_status_data_ok;
409 req->signal.data = hfa384x2host_16(item->sl);
410 req->noise.data = hfa384x2host_16(item->anl);
413 req->bssid.status = P80211ENUM_msgitem_status_data_ok;
414 req->bssid.data.len = WLAN_BSSID_LEN;
415 memcpy(req->bssid.data.data, item->bssid, WLAN_BSSID_LEN);
418 req->ssid.status = P80211ENUM_msgitem_status_data_ok;
419 req->ssid.data.len = hfa384x2host_16(item->ssid.len);
420 memcpy(req->ssid.data.data, item->ssid.data, req->ssid.data.len);
422 /* supported rates */
423 for (count = 0; count < 10 ; count++)
424 if (item->supprates[count] == 0)
427 #define REQBASICRATE(N) \
428 if ((count >= N) && DOT11_RATE5_ISBASIC_GET(item->supprates[(N)-1])) { \
429 req->basicrate ## N .data = item->supprates[(N)-1]; \
430 req->basicrate ## N .status = P80211ENUM_msgitem_status_data_ok; \
442 #define REQSUPPRATE(N) \
444 req->supprate ## N .data = item->supprates[(N)-1]; \
445 req->supprate ## N .status = P80211ENUM_msgitem_status_data_ok; \
458 req->beaconperiod.status = P80211ENUM_msgitem_status_data_ok;
459 req->beaconperiod.data = hfa384x2host_16(item->bcnint);
462 req->timestamp.status = P80211ENUM_msgitem_status_data_ok;
463 req->timestamp.data = jiffies;
464 req->localtime.status = P80211ENUM_msgitem_status_data_ok;
465 req->localtime.data = jiffies;
468 req->ibssatimwindow.status = P80211ENUM_msgitem_status_data_ok;
469 req->ibssatimwindow.data = hfa384x2host_16(item->atim);
472 req->dschannel.status = P80211ENUM_msgitem_status_data_ok;
473 req->dschannel.data = hfa384x2host_16(item->chid);
476 count = hfa384x2host_16(item->capinfo);
479 req->privacy.status = P80211ENUM_msgitem_status_data_ok;
480 req->privacy.data = WLAN_GET_MGMT_CAP_INFO_PRIVACY(count);
483 req->cfpollable.status = P80211ENUM_msgitem_status_data_ok;
484 req->cfpollable.data = WLAN_GET_MGMT_CAP_INFO_CFPOLLABLE(count);
487 req->cfpollreq.status = P80211ENUM_msgitem_status_data_ok;
488 req->cfpollreq.data = WLAN_GET_MGMT_CAP_INFO_CFPOLLREQ(count);
491 req->bsstype.status = P80211ENUM_msgitem_status_data_ok;
492 req->bsstype.data = (WLAN_GET_MGMT_CAP_INFO_ESS(count)) ?
493 P80211ENUM_bsstype_infrastructure :
494 P80211ENUM_bsstype_independent;
496 // item->proberesp_rate
506 req->resultcode.data = P80211ENUM_resultcode_success;
513 /*----------------------------------------------------------------
516 * Join a specific BSS
519 * wlandev wlan device structure
520 * msgp ptr to msg buffer
524 * <0 success, but we're waiting for something to finish.
525 * >0 an error occurred while handling the message.
529 * process thread (usually)
531 ----------------------------------------------------------------*/
532 int prism2mgmt_p2_join(wlandevice_t *wlandev, void *msgp)
535 hfa384x_t *hw = wlandev->priv;
536 p80211msg_p2req_join_t *msg = msgp;
540 hfa384x_bytestr_t *p2bytestr = (hfa384x_bytestr_t*)bytebuf;
541 hfa384x_JoinRequest_data_t joinreq;
544 wlandev->macmode = WLAN_MACMODE_NONE;
546 /* Set the PortType */
547 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
548 msg->resultcode.data = P80211ENUM_resultcode_success;
551 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFPORTTYPE, 1);
553 WLAN_LOG_ERROR("Failed to set Port Type\n");
557 /* Set the auth type */
558 if ( msg->authtype.data == P80211ENUM_authalg_sharedkey ) {
559 reg = HFA384x_CNFAUTHENTICATION_SHAREDKEY;
561 reg = HFA384x_CNFAUTHENTICATION_OPENSYSTEM;
563 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFAUTHENTICATION, reg);
565 WLAN_LOG_ERROR("Failed to set Authentication\n");
569 /* Turn off all roaming */
570 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFROAMINGMODE, 3);
572 WLAN_LOG_ERROR("Failed to Turn off Roaming\n");
578 if ( msg->basicrate1.status == P80211ENUM_msgitem_status_data_ok ) {
579 reg = p80211rate_to_p2bit(msg->basicrate1.data);
581 if ( msg->basicrate2.status == P80211ENUM_msgitem_status_data_ok ) {
582 reg |= p80211rate_to_p2bit(msg->basicrate2.data);
584 if ( msg->basicrate3.status == P80211ENUM_msgitem_status_data_ok ) {
585 reg |= p80211rate_to_p2bit(msg->basicrate3.data);
587 if ( msg->basicrate4.status == P80211ENUM_msgitem_status_data_ok ) {
588 reg |= p80211rate_to_p2bit(msg->basicrate4.data);
590 if ( msg->basicrate5.status == P80211ENUM_msgitem_status_data_ok ) {
591 reg |= p80211rate_to_p2bit(msg->basicrate5.data);
593 if ( msg->basicrate6.status == P80211ENUM_msgitem_status_data_ok ) {
594 reg |= p80211rate_to_p2bit(msg->basicrate6.data);
596 if ( msg->basicrate7.status == P80211ENUM_msgitem_status_data_ok ) {
597 reg |= p80211rate_to_p2bit(msg->basicrate7.data);
599 if ( msg->basicrate8.status == P80211ENUM_msgitem_status_data_ok ) {
600 reg |= p80211rate_to_p2bit(msg->basicrate8.data);
604 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFBASICRATES, reg);
606 WLAN_LOG_ERROR("Failed to set basicrates=%d.\n", reg);
610 /* Operational rates (supprates and txratecontrol) */
612 if ( msg->operationalrate1.status == P80211ENUM_msgitem_status_data_ok ) {
613 reg = p80211rate_to_p2bit(msg->operationalrate1.data);
615 if ( msg->operationalrate2.status == P80211ENUM_msgitem_status_data_ok ) {
616 reg |= p80211rate_to_p2bit(msg->operationalrate2.data);
618 if ( msg->operationalrate3.status == P80211ENUM_msgitem_status_data_ok ) {
619 reg |= p80211rate_to_p2bit(msg->operationalrate3.data);
621 if ( msg->operationalrate4.status == P80211ENUM_msgitem_status_data_ok ) {
622 reg |= p80211rate_to_p2bit(msg->operationalrate4.data);
624 if ( msg->operationalrate5.status == P80211ENUM_msgitem_status_data_ok ) {
625 reg |= p80211rate_to_p2bit(msg->operationalrate5.data);
627 if ( msg->operationalrate6.status == P80211ENUM_msgitem_status_data_ok ) {
628 reg |= p80211rate_to_p2bit(msg->operationalrate6.data);
630 if ( msg->operationalrate7.status == P80211ENUM_msgitem_status_data_ok ) {
631 reg |= p80211rate_to_p2bit(msg->operationalrate7.data);
633 if ( msg->operationalrate8.status == P80211ENUM_msgitem_status_data_ok ) {
634 reg |= p80211rate_to_p2bit(msg->operationalrate8.data);
638 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFSUPPRATES, reg);
640 WLAN_LOG_ERROR("Failed to set supprates=%d.\n", reg);
644 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_TXRATECNTL, reg);
646 WLAN_LOG_ERROR("Failed to set txrates=%d.\n", reg);
651 memset(bytebuf, 0, 256);
652 pstr = (p80211pstrd_t*)&(msg->ssid.data);
653 prism2mgmt_pstr2bytestr(p2bytestr, pstr);
654 result = hfa384x_drvr_setconfig(
655 hw, HFA384x_RID_CNFDESIREDSSID,
656 bytebuf, HFA384x_RID_CNFDESIREDSSID_LEN);
658 WLAN_LOG_ERROR("Failed to set SSID\n");
662 /* Enable the Port */
663 result = hfa384x_cmd_enable(hw, 0);
665 WLAN_LOG_ERROR("Enable macport failed, result=%d.\n", result);
669 /* Fill in the join request */
670 joinreq.channel = msg->channel.data;
671 memcpy( joinreq.bssid, ((unsigned char *) &msg->bssid.data) + 1, WLAN_BSSID_LEN);
672 hw->joinreq = joinreq;
675 /* Send the join request */
676 result = hfa384x_drvr_setconfig( hw,
677 HFA384x_RID_JOINREQUEST,
678 &joinreq, HFA384x_RID_JOINREQUEST_LEN);
680 WLAN_LOG_ERROR("Join request failed, result=%d.\n", result);
686 WLAN_LOG_DEBUG(1, "Failed to set a config option, result=%d\n", result);
687 msg->resultcode.data = P80211ENUM_resultcode_invalid_parameters;
696 /*----------------------------------------------------------------
697 * prism2mgmt_associate
699 * Associate with an ESS.
702 * wlandev wlan device structure
703 * msgp ptr to msg buffer
707 * <0 success, but we're waiting for something to finish.
708 * >0 an error occurred while handling the message.
712 * process thread (usually)
714 ----------------------------------------------------------------*/
715 int prism2mgmt_associate(wlandevice_t *wlandev, void *msgp)
717 hfa384x_t *hw = wlandev->priv;
719 p80211msg_dot11req_associate_t *msg = msgp;
723 /* Set the TxRates */
725 hfa384x_drvr_setconfig16(hw, HFA384x_RID_TXRATECNTL, reg);
728 /* Set the PortType */
730 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFPORTTYPE, 1);
732 /* Enable the Port */
733 hfa384x_drvr_enable(hw, 0);
735 /* Set the resultcode */
736 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
737 msg->resultcode.data = P80211ENUM_resultcode_success;
743 /*----------------------------------------------------------------
746 * Reset the MAC and MSD. The p80211 layer has it's own handling
747 * that should be done before and after this function.
749 * - disable system interrupts ??
750 * - disable MAC interrupts
751 * - restore system interrupts
752 * - issue the MAC initialize command
753 * - clear any MSD level state (including timers, queued events,
754 * etc.). Note that if we're removing timer'd/queue events, we may
755 * need to have remained in the system interrupt disabled state.
756 * We should be left in the same state that we're in following
757 * driver initialization.
760 * wlandev wlan device structure
761 * msgp ptr to msg buffer, MAY BE NULL! for a driver local
766 * <0 success, but we're waiting for something to finish.
767 * >0 an error occurred while handling the message.
771 * process thread, commonly wlanctl, but might be rmmod/pci_close.
772 ----------------------------------------------------------------*/
773 int prism2mgmt_reset(wlandevice_t *wlandev, void *msgp)
776 hfa384x_t *hw = wlandev->priv;
777 p80211msg_dot11req_reset_t *msg = msgp;
781 * This is supported on both AP and STA and it's not allowed
785 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
786 msg->resultcode.data = P80211ENUM_resultcode_success;
787 WLAN_LOG_INFO("dot11req_reset: the macaddress and "
788 "setdefaultmib arguments are currently unsupported.\n");
792 * If we got this far, the MSD must be in the MSDRUNNING state
793 * therefore, we must stop and then restart the hw/MAC combo.
795 hfa384x_drvr_stop(hw);
796 result = hfa384x_drvr_start(hw);
798 WLAN_LOG_ERROR("dot11req_reset: Initialize command failed,"
799 " bad things will happen from here.\n");
808 /*----------------------------------------------------------------
811 * Start a BSS. Any station can do this for IBSS, only AP for ESS.
814 * wlandev wlan device structure
815 * msgp ptr to msg buffer
819 * <0 success, but we're waiting for something to finish.
820 * >0 an error occurred while handling the message.
824 * process thread (usually)
826 ----------------------------------------------------------------*/
827 int prism2mgmt_start(wlandevice_t *wlandev, void *msgp)
830 hfa384x_t *hw = wlandev->priv;
831 p80211msg_dot11req_start_t *msg = msgp;
835 hfa384x_bytestr_t *p2bytestr = (hfa384x_bytestr_t*)bytebuf;
839 wlandev->macmode = WLAN_MACMODE_NONE;
842 memcpy(&wlandev->ssid, &msg->ssid.data, sizeof(msg->ssid.data));
845 /* see if current f/w is less than 8c3 */
846 if (HFA384x_FIRMWARE_VERSION(hw->ident_sta_fw.major,
847 hw->ident_sta_fw.minor,
848 hw->ident_sta_fw.variant) <
849 HFA384x_FIRMWARE_VERSION(0,8,3)) {
850 /* Ad-Hoc not quite supported on Prism2 */
851 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
852 msg->resultcode.data = P80211ENUM_resultcode_not_supported;
856 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
859 /* Set the REQUIRED config items */
861 pstr = (p80211pstrd_t*)&(msg->ssid.data);
862 prism2mgmt_pstr2bytestr(p2bytestr, pstr);
863 result = hfa384x_drvr_setconfig( hw, HFA384x_RID_CNFOWNSSID,
864 bytebuf, HFA384x_RID_CNFOWNSSID_LEN);
866 WLAN_LOG_ERROR("Failed to set CnfOwnSSID\n");
869 result = hfa384x_drvr_setconfig( hw, HFA384x_RID_CNFDESIREDSSID,
870 bytebuf, HFA384x_RID_CNFDESIREDSSID_LEN);
872 WLAN_LOG_ERROR("Failed to set CnfDesiredSSID\n");
876 /* bsstype - we use the default in the ap firmware */
878 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFPORTTYPE, 0);
881 word = msg->beaconperiod.data;
882 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFAPBCNINT, word);
884 WLAN_LOG_ERROR("Failed to set beacon period=%d.\n", word);
889 word = msg->dschannel.data;
890 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFOWNCHANNEL, word);
892 WLAN_LOG_ERROR("Failed to set channel=%d.\n", word);
896 word = p80211rate_to_p2bit(msg->basicrate1.data);
897 if ( msg->basicrate2.status == P80211ENUM_msgitem_status_data_ok ) {
898 word |= p80211rate_to_p2bit(msg->basicrate2.data);
900 if ( msg->basicrate3.status == P80211ENUM_msgitem_status_data_ok ) {
901 word |= p80211rate_to_p2bit(msg->basicrate3.data);
903 if ( msg->basicrate4.status == P80211ENUM_msgitem_status_data_ok ) {
904 word |= p80211rate_to_p2bit(msg->basicrate4.data);
906 if ( msg->basicrate5.status == P80211ENUM_msgitem_status_data_ok ) {
907 word |= p80211rate_to_p2bit(msg->basicrate5.data);
909 if ( msg->basicrate6.status == P80211ENUM_msgitem_status_data_ok ) {
910 word |= p80211rate_to_p2bit(msg->basicrate6.data);
912 if ( msg->basicrate7.status == P80211ENUM_msgitem_status_data_ok ) {
913 word |= p80211rate_to_p2bit(msg->basicrate7.data);
915 if ( msg->basicrate8.status == P80211ENUM_msgitem_status_data_ok ) {
916 word |= p80211rate_to_p2bit(msg->basicrate8.data);
918 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFBASICRATES, word);
920 WLAN_LOG_ERROR("Failed to set basicrates=%d.\n", word);
924 /* Operational rates (supprates and txratecontrol) */
925 word = p80211rate_to_p2bit(msg->operationalrate1.data);
926 if ( msg->operationalrate2.status == P80211ENUM_msgitem_status_data_ok ) {
927 word |= p80211rate_to_p2bit(msg->operationalrate2.data);
929 if ( msg->operationalrate3.status == P80211ENUM_msgitem_status_data_ok ) {
930 word |= p80211rate_to_p2bit(msg->operationalrate3.data);
932 if ( msg->operationalrate4.status == P80211ENUM_msgitem_status_data_ok ) {
933 word |= p80211rate_to_p2bit(msg->operationalrate4.data);
935 if ( msg->operationalrate5.status == P80211ENUM_msgitem_status_data_ok ) {
936 word |= p80211rate_to_p2bit(msg->operationalrate5.data);
938 if ( msg->operationalrate6.status == P80211ENUM_msgitem_status_data_ok ) {
939 word |= p80211rate_to_p2bit(msg->operationalrate6.data);
941 if ( msg->operationalrate7.status == P80211ENUM_msgitem_status_data_ok ) {
942 word |= p80211rate_to_p2bit(msg->operationalrate7.data);
944 if ( msg->operationalrate8.status == P80211ENUM_msgitem_status_data_ok ) {
945 word |= p80211rate_to_p2bit(msg->operationalrate8.data);
947 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFSUPPRATES, word);
949 WLAN_LOG_ERROR("Failed to set supprates=%d.\n", word);
953 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_TXRATECNTL, word);
955 WLAN_LOG_ERROR("Failed to set txrates=%d.\n", word);
959 /* Set the macmode so the frame setup code knows what to do */
960 if ( msg->bsstype.data == P80211ENUM_bsstype_independent ) {
961 wlandev->macmode = WLAN_MACMODE_IBSS_STA;
962 /* lets extend the data length a bit */
963 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFMAXDATALEN, 2304);
966 /* Enable the Port */
967 result = hfa384x_drvr_enable(hw, 0);
969 WLAN_LOG_ERROR("Enable macport failed, result=%d.\n", result);
973 msg->resultcode.data = P80211ENUM_resultcode_success;
977 WLAN_LOG_DEBUG(1, "Failed to set a config option, result=%d\n", result);
978 msg->resultcode.data = P80211ENUM_resultcode_invalid_parameters;
987 /*----------------------------------------------------------------
990 * Collect the PDA data and put it in the message.
993 * wlandev wlan device structure
994 * msgp ptr to msg buffer
998 * <0 success, but we're waiting for something to finish.
999 * >0 an error occurred while handling the message.
1003 * process thread (usually)
1004 ----------------------------------------------------------------*/
1005 int prism2mgmt_readpda(wlandevice_t *wlandev, void *msgp)
1007 hfa384x_t *hw = wlandev->priv;
1008 p80211msg_p2req_readpda_t *msg = msgp;
1012 /* We only support collecting the PDA when in the FWLOAD
1015 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
1017 "PDA may only be read "
1018 "in the fwload state.\n");
1019 msg->resultcode.data =
1020 P80211ENUM_resultcode_implementation_failure;
1021 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
1023 /* Call drvr_readpda(), it handles the auxport enable
1024 * and validating the returned PDA.
1026 result = hfa384x_drvr_readpda(
1029 HFA384x_PDA_LEN_MAX);
1032 "hfa384x_drvr_readpda() failed, "
1036 msg->resultcode.data =
1037 P80211ENUM_resultcode_implementation_failure;
1038 msg->resultcode.status =
1039 P80211ENUM_msgitem_status_data_ok;
1043 msg->pda.status = P80211ENUM_msgitem_status_data_ok;
1044 msg->resultcode.data = P80211ENUM_resultcode_success;
1045 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
1052 /*----------------------------------------------------------------
1053 * prism2mgmt_readcis
1055 * Collect the CIS data and put it in the message.
1058 * wlandev wlan device structure
1059 * msgp ptr to msg buffer
1062 * 0 success and done
1063 * <0 success, but we're waiting for something to finish.
1064 * >0 an error occurred while handling the message.
1068 * process thread (usually)
1069 ----------------------------------------------------------------*/
1070 int prism2mgmt_readcis(wlandevice_t *wlandev, void *msgp)
1073 hfa384x_t *hw = wlandev->priv;
1074 p80211msg_p2req_readcis_t *msg = msgp;
1078 memset(msg->cis.data, 0, sizeof(msg->cis.data));
1080 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_CIS,
1081 msg->cis.data, HFA384x_RID_CIS_LEN);
1083 WLAN_LOG_INFO("prism2mgmt_readcis: read(cis) failed.\n");
1084 msg->cis.status = P80211ENUM_msgitem_status_no_value;
1085 msg->resultcode.data = P80211ENUM_resultcode_implementation_failure;
1089 msg->cis.status = P80211ENUM_msgitem_status_data_ok;
1090 msg->resultcode.data = P80211ENUM_resultcode_success;
1093 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
1099 /*----------------------------------------------------------------
1100 * prism2mgmt_auxport_state
1102 * Enables/Disables the card's auxiliary port. Should be called
1103 * before and after a sequence of auxport_read()/auxport_write()
1107 * wlandev wlan device structure
1108 * msgp ptr to msg buffer
1111 * 0 success and done
1112 * <0 success, but we're waiting for something to finish.
1113 * >0 an error occurred while handling the message.
1117 * process thread (usually)
1118 ----------------------------------------------------------------*/
1119 int prism2mgmt_auxport_state(wlandevice_t *wlandev, void *msgp)
1121 p80211msg_p2req_auxport_state_t *msg = msgp;
1125 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
1126 msg->resultcode.data = P80211ENUM_resultcode_not_supported;
1133 /*----------------------------------------------------------------
1134 * prism2mgmt_auxport_read
1136 * Copies data from the card using the auxport. The auxport must
1137 * have previously been enabled. Note: this is not the way to
1138 * do downloads, see the [ram|flash]dl functions.
1141 * wlandev wlan device structure
1142 * msgp ptr to msg buffer
1145 * 0 success and done
1146 * <0 success, but we're waiting for something to finish.
1147 * >0 an error occurred while handling the message.
1151 * process thread (usually)
1152 ----------------------------------------------------------------*/
1153 int prism2mgmt_auxport_read(wlandevice_t *wlandev, void *msgp)
1157 WLAN_LOG_ERROR("prism2mgmt_auxport_read: Not supported on USB.\n");
1164 /*----------------------------------------------------------------
1165 * prism2mgmt_auxport_write
1167 * Copies data to the card using the auxport. The auxport must
1168 * have previously been enabled. Note: this is not the way to
1169 * do downloads, see the [ram|flash]dl functions.
1172 * wlandev wlan device structure
1173 * msgp ptr to msg buffer
1176 * 0 success and done
1177 * <0 success, but we're waiting for something to finish.
1178 * >0 an error occurred while handling the message.
1182 * process thread (usually)
1183 ----------------------------------------------------------------*/
1184 int prism2mgmt_auxport_write(wlandevice_t *wlandev, void *msgp)
1187 WLAN_LOG_ERROR("prism2mgmt_auxport_read: Not supported on USB.\n");
1192 /*----------------------------------------------------------------
1193 * prism2mgmt_low_level
1195 * Puts the card into the desired test mode.
1198 * wlandev wlan device structure
1199 * msgp ptr to msg buffer
1202 * 0 success and done
1203 * <0 success, but we're waiting for something to finish.
1204 * >0 an error occurred while handling the message.
1208 * process thread (usually)
1209 ----------------------------------------------------------------*/
1210 int prism2mgmt_low_level(wlandevice_t *wlandev, void *msgp)
1212 hfa384x_t *hw = wlandev->priv;
1213 p80211msg_p2req_low_level_t *msg = msgp;
1214 hfa384x_metacmd_t cmd;
1217 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
1219 /* call some routine to execute the test command */
1220 cmd.cmd = (UINT16) msg->command.data;
1221 cmd.parm0 = (UINT16) msg->param0.data;
1222 cmd.parm1 = (UINT16) msg->param1.data;
1223 cmd.parm2 = (UINT16) msg->param2.data;
1225 hfa384x_drvr_low_level(hw,&cmd);
1227 msg->resp0.data = (UINT32) cmd.result.resp0;
1228 msg->resp1.data = (UINT32) cmd.result.resp1;
1229 msg->resp2.data = (UINT32) cmd.result.resp2;
1231 msg->resultcode.data = P80211ENUM_resultcode_success;
1237 /*----------------------------------------------------------------
1238 * prism2mgmt_test_command
1240 * Puts the card into the desired test mode.
1243 * wlandev wlan device structure
1244 * msgp ptr to msg buffer
1247 * 0 success and done
1248 * <0 success, but we're waiting for something to finish.
1249 * >0 an error occurred while handling the message.
1253 * process thread (usually)
1254 ----------------------------------------------------------------*/
1255 int prism2mgmt_test_command(wlandevice_t *wlandev, void *msgp)
1257 hfa384x_t *hw = wlandev->priv;
1258 p80211msg_p2req_test_command_t *msg = msgp;
1259 hfa384x_metacmd_t cmd;
1263 cmd.cmd = ((UINT16) msg->testcode.data) << 8 | 0x38;
1264 cmd.parm0 = (UINT16) msg->testparam.data;
1268 /* call some routine to execute the test command */
1270 hfa384x_drvr_low_level(hw,&cmd);
1272 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
1273 msg->resultcode.data = P80211ENUM_resultcode_success;
1275 msg->status.status = P80211ENUM_msgitem_status_data_ok;
1276 msg->status.data = cmd.result.status;
1277 msg->resp0.status = P80211ENUM_msgitem_status_data_ok;
1278 msg->resp0.data = cmd.result.resp0;
1279 msg->resp1.status = P80211ENUM_msgitem_status_data_ok;
1280 msg->resp1.data = cmd.result.resp1;
1281 msg->resp2.status = P80211ENUM_msgitem_status_data_ok;
1282 msg->resp2.data = cmd.result.resp2;
1289 /*----------------------------------------------------------------
1290 * prism2mgmt_mmi_read
1292 * Read from one of the MMI registers.
1295 * wlandev wlan device structure
1296 * msgp ptr to msg buffer
1299 * 0 success and done
1300 * <0 success, but we're waiting for something to finish.
1301 * >0 an error occurred while handling the message.
1305 * process thread (usually)
1306 ----------------------------------------------------------------*/
1307 int prism2mgmt_mmi_read(wlandevice_t *wlandev, void *msgp)
1309 hfa384x_t *hw = wlandev->priv;
1310 p80211msg_p2req_mmi_read_t *msg = msgp;
1315 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
1317 /* call some routine to execute the test command */
1319 hfa384x_drvr_mmi_read(hw, msg->addr.data, &resp);
1321 /* I'm not sure if this is "architecturally" correct, but it
1324 msg->value.status = P80211ENUM_msgitem_status_data_ok;
1325 msg->value.data = resp;
1326 msg->resultcode.data = P80211ENUM_resultcode_success;
1332 /*----------------------------------------------------------------
1333 * prism2mgmt_mmi_write
1335 * Write a data value to one of the MMI registers.
1338 * wlandev wlan device structure
1339 * msgp ptr to msg buffer
1342 * 0 success and done
1343 * <0 success, but we're waiting for something to finish.
1344 * >0 an error occurred while handling the message.
1348 * process thread (usually)
1349 ----------------------------------------------------------------*/
1350 int prism2mgmt_mmi_write(wlandevice_t *wlandev, void *msgp)
1352 hfa384x_t *hw = wlandev->priv;
1353 p80211msg_p2req_mmi_write_t *msg = msgp;
1356 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
1358 /* call some routine to execute the test command */
1360 hfa384x_drvr_mmi_write(hw, msg->addr.data, msg->data.data);
1362 msg->resultcode.data = P80211ENUM_resultcode_success;
1368 /*----------------------------------------------------------------
1369 * prism2mgmt_ramdl_state
1371 * Establishes the beginning/end of a card RAM download session.
1373 * It is expected that the ramdl_write() function will be called
1374 * one or more times between the 'enable' and 'disable' calls to
1377 * Note: This function should not be called when a mac comm port
1381 * wlandev wlan device structure
1382 * msgp ptr to msg buffer
1385 * 0 success and done
1386 * <0 success, but we're waiting for something to finish.
1387 * >0 an error occurred while handling the message.
1391 * process thread (usually)
1392 ----------------------------------------------------------------*/
1393 int prism2mgmt_ramdl_state(wlandevice_t *wlandev, void *msgp)
1395 hfa384x_t *hw = wlandev->priv;
1396 p80211msg_p2req_ramdl_state_t *msg = msgp;
1399 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
1401 "ramdl_state(): may only be called "
1402 "in the fwload state.\n");
1403 msg->resultcode.data =
1404 P80211ENUM_resultcode_implementation_failure;
1405 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
1411 ** Note: Interrupts are locked out if this is an AP and are NOT
1412 ** locked out if this is a station.
1415 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
1416 if ( msg->enable.data == P80211ENUM_truth_true ) {
1417 if ( hfa384x_drvr_ramdl_enable(hw, msg->exeaddr.data) ) {
1418 msg->resultcode.data = P80211ENUM_resultcode_implementation_failure;
1420 msg->resultcode.data = P80211ENUM_resultcode_success;
1423 hfa384x_drvr_ramdl_disable(hw);
1424 msg->resultcode.data = P80211ENUM_resultcode_success;
1432 /*----------------------------------------------------------------
1433 * prism2mgmt_ramdl_write
1435 * Writes a buffer to the card RAM using the download state. This
1436 * is for writing code to card RAM. To just read or write raw data
1437 * use the aux functions.
1440 * wlandev wlan device structure
1441 * msgp ptr to msg buffer
1444 * 0 success and done
1445 * <0 success, but we're waiting for something to finish.
1446 * >0 an error occurred while handling the message.
1450 * process thread (usually)
1451 ----------------------------------------------------------------*/
1452 int prism2mgmt_ramdl_write(wlandevice_t *wlandev, void *msgp)
1454 hfa384x_t *hw = wlandev->priv;
1455 p80211msg_p2req_ramdl_write_t *msg = msgp;
1461 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
1463 "ramdl_write(): may only be called "
1464 "in the fwload state.\n");
1465 msg->resultcode.data =
1466 P80211ENUM_resultcode_implementation_failure;
1467 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
1472 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
1473 /* first validate the length */
1474 if ( msg->len.data > sizeof(msg->data.data) ) {
1475 msg->resultcode.status = P80211ENUM_resultcode_invalid_parameters;
1478 /* call the hfa384x function to do the write */
1479 addr = msg->addr.data;
1480 len = msg->len.data;
1481 buf = msg->data.data;
1482 if ( hfa384x_drvr_ramdl_write(hw, addr, buf, len) ) {
1483 msg->resultcode.data = P80211ENUM_resultcode_refused;
1486 msg->resultcode.data = P80211ENUM_resultcode_success;
1493 /*----------------------------------------------------------------
1494 * prism2mgmt_flashdl_state
1496 * Establishes the beginning/end of a card Flash download session.
1498 * It is expected that the flashdl_write() function will be called
1499 * one or more times between the 'enable' and 'disable' calls to
1502 * Note: This function should not be called when a mac comm port
1506 * wlandev wlan device structure
1507 * msgp ptr to msg buffer
1510 * 0 success and done
1511 * <0 success, but we're waiting for something to finish.
1512 * >0 an error occurred while handling the message.
1516 * process thread (usually)
1517 ----------------------------------------------------------------*/
1518 int prism2mgmt_flashdl_state(wlandevice_t *wlandev, void *msgp)
1521 hfa384x_t *hw = wlandev->priv;
1522 p80211msg_p2req_flashdl_state_t *msg = msgp;
1525 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
1527 "flashdl_state(): may only be called "
1528 "in the fwload state.\n");
1529 msg->resultcode.data =
1530 P80211ENUM_resultcode_implementation_failure;
1531 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
1537 ** Note: Interrupts are locked out if this is an AP and are NOT
1538 ** locked out if this is a station.
1541 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
1542 if ( msg->enable.data == P80211ENUM_truth_true ) {
1543 if ( hfa384x_drvr_flashdl_enable(hw) ) {
1544 msg->resultcode.data = P80211ENUM_resultcode_implementation_failure;
1546 msg->resultcode.data = P80211ENUM_resultcode_success;
1549 hfa384x_drvr_flashdl_disable(hw);
1550 msg->resultcode.data = P80211ENUM_resultcode_success;
1551 /* NOTE: At this point, the MAC is in the post-reset
1552 * state and the driver is in the fwload state.
1553 * We need to get the MAC back into the fwload
1554 * state. To do this, we set the nsdstate to HWPRESENT
1555 * and then call the ifstate function to redo everything
1556 * that got us into the fwload state.
1558 wlandev->msdstate = WLAN_MSD_HWPRESENT;
1559 result = prism2sta_ifstate(wlandev, P80211ENUM_ifstate_fwload);
1560 if (result != P80211ENUM_resultcode_success) {
1561 WLAN_LOG_ERROR("prism2sta_ifstate(fwload) failed,"
1562 "P80211ENUM_resultcode=%d\n", result);
1563 msg->resultcode.data =
1564 P80211ENUM_resultcode_implementation_failure;
1574 /*----------------------------------------------------------------
1575 * prism2mgmt_flashdl_write
1580 * wlandev wlan device structure
1581 * msgp ptr to msg buffer
1584 * 0 success and done
1585 * <0 success, but we're waiting for something to finish.
1586 * >0 an error occurred while handling the message.
1590 * process thread (usually)
1591 ----------------------------------------------------------------*/
1592 int prism2mgmt_flashdl_write(wlandevice_t *wlandev, void *msgp)
1594 hfa384x_t *hw = wlandev->priv;
1595 p80211msg_p2req_flashdl_write_t *msg = msgp;
1601 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
1603 "flashdl_write(): may only be called "
1604 "in the fwload state.\n");
1605 msg->resultcode.data =
1606 P80211ENUM_resultcode_implementation_failure;
1607 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
1613 ** Note: Interrupts are locked out if this is an AP and are NOT
1614 ** locked out if this is a station.
1617 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
1618 /* first validate the length */
1619 if ( msg->len.data > sizeof(msg->data.data) ) {
1620 msg->resultcode.status =
1621 P80211ENUM_resultcode_invalid_parameters;
1624 /* call the hfa384x function to do the write */
1625 addr = msg->addr.data;
1626 len = msg->len.data;
1627 buf = msg->data.data;
1628 if ( hfa384x_drvr_flashdl_write(hw, addr, buf, len) ) {
1629 msg->resultcode.data = P80211ENUM_resultcode_refused;
1632 msg->resultcode.data = P80211ENUM_resultcode_success;
1639 /*----------------------------------------------------------------
1640 * prism2mgmt_dump_state
1642 * Dumps the driver's and hardware's current state via the kernel
1643 * log at KERN_NOTICE level.
1646 * wlandev wlan device structure
1647 * msgp ptr to msg buffer
1650 * 0 success and done
1651 * <0 success, but we're waiting for something to finish.
1652 * >0 an error occurred while handling the message.
1656 * process thread (usually)
1657 ----------------------------------------------------------------*/
1658 int prism2mgmt_dump_state(wlandevice_t *wlandev, void *msgp)
1660 p80211msg_p2req_dump_state_t *msg = msgp;
1665 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
1666 msg->resultcode.data = P80211ENUM_resultcode_not_supported;
1674 /*----------------------------------------------------------------
1675 * prism2mgmt_autojoin
1677 * Associate with an ESS.
1680 * wlandev wlan device structure
1681 * msgp ptr to msg buffer
1684 * 0 success and done
1685 * <0 success, but we're waiting for something to finish.
1686 * >0 an error occurred while handling the message.
1690 * process thread (usually)
1692 ----------------------------------------------------------------*/
1693 int prism2mgmt_autojoin(wlandevice_t *wlandev, void *msgp)
1695 hfa384x_t *hw = wlandev->priv;
1699 p80211msg_lnxreq_autojoin_t *msg = msgp;
1700 p80211pstrd_t *pstr;
1702 hfa384x_bytestr_t *p2bytestr = (hfa384x_bytestr_t*)bytebuf;
1705 wlandev->macmode = WLAN_MACMODE_NONE;
1708 memcpy(&wlandev->ssid, &msg->ssid.data, sizeof(msg->ssid.data));
1710 /* Disable the Port */
1711 hfa384x_drvr_disable(hw, 0);
1714 /* Set the TxRates */
1715 hfa384x_drvr_setconfig16(hw, HFA384x_RID_TXRATECNTL, 0x000f);
1717 /* Set the auth type */
1718 if ( msg->authtype.data == P80211ENUM_authalg_sharedkey ) {
1719 reg = HFA384x_CNFAUTHENTICATION_SHAREDKEY;
1721 reg = HFA384x_CNFAUTHENTICATION_OPENSYSTEM;
1723 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFAUTHENTICATION, reg);
1726 memset(bytebuf, 0, 256);
1727 pstr = (p80211pstrd_t*)&(msg->ssid.data);
1728 prism2mgmt_pstr2bytestr(p2bytestr, pstr);
1729 result = hfa384x_drvr_setconfig(
1730 hw, HFA384x_RID_CNFDESIREDSSID,
1731 bytebuf, HFA384x_RID_CNFDESIREDSSID_LEN);
1733 /* we can use the new-fangled auto-unknown mode if the firmware
1734 is 1.3.3 or newer */
1735 if (HFA384x_FIRMARE_VERSION(hw->ident_sta_fw.major,
1736 hw->ident_sta_fw.minor,
1737 hw->ident_sta_fw.variant) >=
1738 HFA384x_FIRMWARE_VERSION(1,3,3)) {
1739 /* Set up the IBSS options */
1740 reg = HFA384x_CREATEIBSS_JOINESS_JOINCREATEIBSS;
1741 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CREATEIBSS, reg);
1743 /* Set the PortType */
1744 port_type = HFA384x_PORTTYPE_IBSS;
1746 port_type = HFA384x_PORTTYPE_BSS;
1749 port_type = HFA384x_PORTTYPE_BSS;
1751 /* Set the PortType */
1752 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFPORTTYPE, port_type);
1754 /* Enable the Port */
1755 hfa384x_drvr_enable(hw, 0);
1757 /* Set the resultcode */
1758 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
1759 msg->resultcode.data = P80211ENUM_resultcode_success;
1766 /*----------------------------------------------------------------
1767 * prism2mgmt_wlansniff
1769 * Start or stop sniffing.
1772 * wlandev wlan device structure
1773 * msgp ptr to msg buffer
1776 * 0 success and done
1777 * <0 success, but we're waiting for something to finish.
1778 * >0 an error occurred while handling the message.
1782 * process thread (usually)
1784 ----------------------------------------------------------------*/
1785 int prism2mgmt_wlansniff(wlandevice_t *wlandev, void *msgp)
1788 p80211msg_lnxreq_wlansniff_t *msg = msgp;
1790 hfa384x_t *hw = wlandev->priv;
1795 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
1796 switch (msg->enable.data)
1798 case P80211ENUM_truth_false:
1799 /* Confirm that we're in monitor mode */
1800 if ( wlandev->netdev->type == ARPHRD_ETHER ) {
1801 msg->resultcode.data = P80211ENUM_resultcode_invalid_parameters;
1805 /* Disable monitor mode */
1806 result = hfa384x_cmd_monitor(hw, HFA384x_MONITOR_DISABLE);
1809 "failed to disable monitor mode, result=%d\n",
1813 /* Disable port 0 */
1814 result = hfa384x_drvr_disable(hw, 0);
1817 "failed to disable port 0 after sniffing, result=%d\n",
1821 /* Clear the driver state */
1822 wlandev->netdev->type = ARPHRD_ETHER;
1824 /* Restore the wepflags */
1825 result = hfa384x_drvr_setconfig16(hw,
1826 HFA384x_RID_CNFWEPFLAGS,
1827 hw->presniff_wepflags);
1830 "failed to restore wepflags=0x%04x, result=%d\n",
1831 hw->presniff_wepflags,
1836 /* Set the port to its prior type and enable (if necessary) */
1837 if (hw->presniff_port_type != 0 ) {
1838 word = hw->presniff_port_type;
1839 result = hfa384x_drvr_setconfig16(hw,
1840 HFA384x_RID_CNFPORTTYPE, word);
1843 "failed to restore porttype, result=%d\n",
1848 /* Enable the port */
1849 result = hfa384x_drvr_enable(hw, 0);
1851 WLAN_LOG_DEBUG(1, "failed to enable port to presniff setting, result=%d\n", result);
1855 result = hfa384x_drvr_disable(hw, 0);
1859 WLAN_LOG_INFO("monitor mode disabled\n");
1860 msg->resultcode.data = P80211ENUM_resultcode_success;
1864 case P80211ENUM_truth_true:
1865 /* Disable the port (if enabled), only check Port 0 */
1866 if ( hw->port_enabled[0]) {
1867 if (wlandev->netdev->type == ARPHRD_ETHER) {
1868 /* Save macport 0 state */
1869 result = hfa384x_drvr_getconfig16(hw,
1870 HFA384x_RID_CNFPORTTYPE,
1871 &(hw->presniff_port_type));
1873 WLAN_LOG_DEBUG(1,"failed to read porttype, result=%d\n", result);
1876 /* Save the wepflags state */
1877 result = hfa384x_drvr_getconfig16(hw,
1878 HFA384x_RID_CNFWEPFLAGS,
1879 &(hw->presniff_wepflags));
1881 WLAN_LOG_DEBUG(1,"failed to read wepflags, result=%d\n", result);
1884 hfa384x_drvr_stop(hw);
1885 result = hfa384x_drvr_start(hw);
1888 "failed to restart the card for sniffing, result=%d\n",
1893 /* Disable the port */
1894 result = hfa384x_drvr_disable(hw, 0);
1897 "failed to enable port for sniffing, result=%d\n",
1903 hw->presniff_port_type = 0;
1906 /* Set the channel we wish to sniff */
1907 word = msg->channel.data;
1908 result = hfa384x_drvr_setconfig16(hw,
1909 HFA384x_RID_CNFOWNCHANNEL, word);
1910 hw->sniff_channel=word;
1914 "failed to set channel %d, result=%d\n",
1920 /* Now if we're already sniffing, we can skip the rest */
1921 if (wlandev->netdev->type != ARPHRD_ETHER) {
1922 /* Set the port type to pIbss */
1923 word = HFA384x_PORTTYPE_PSUEDOIBSS;
1924 result = hfa384x_drvr_setconfig16(hw,
1925 HFA384x_RID_CNFPORTTYPE, word);
1928 "failed to set porttype %d, result=%d\n",
1933 if ((msg->keepwepflags.status == P80211ENUM_msgitem_status_data_ok) && (msg->keepwepflags.data != P80211ENUM_truth_true)) {
1934 /* Set the wepflags for no decryption */
1935 word = HFA384x_WEPFLAGS_DISABLE_TXCRYPT |
1936 HFA384x_WEPFLAGS_DISABLE_RXCRYPT;
1937 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFWEPFLAGS, word);
1942 "failed to set wepflags=0x%04x, result=%d\n",
1949 /* Do we want to strip the FCS in monitor mode? */
1950 if ((msg->stripfcs.status == P80211ENUM_msgitem_status_data_ok) && (msg->stripfcs.data == P80211ENUM_truth_true)) {
1956 /* Do we want to truncate the packets? */
1957 if (msg->packet_trunc.status == P80211ENUM_msgitem_status_data_ok) {
1958 hw->sniff_truncate = msg->packet_trunc.data;
1960 hw->sniff_truncate = 0;
1963 /* Enable the port */
1964 result = hfa384x_drvr_enable(hw, 0);
1967 "failed to enable port for sniffing, result=%d\n",
1971 /* Enable monitor mode */
1972 result = hfa384x_cmd_monitor(hw, HFA384x_MONITOR_ENABLE);
1975 "failed to enable monitor mode, result=%d\n",
1980 if (wlandev->netdev->type == ARPHRD_ETHER) {
1981 WLAN_LOG_INFO("monitor mode enabled\n");
1984 /* Set the driver state */
1985 /* Do we want the prism2 header? */
1986 if ((msg->prismheader.status == P80211ENUM_msgitem_status_data_ok) && (msg->prismheader.data == P80211ENUM_truth_true)) {
1988 wlandev->netdev->type = ARPHRD_IEEE80211_PRISM;
1989 } else if ((msg->wlanheader.status == P80211ENUM_msgitem_status_data_ok) && (msg->wlanheader.data == P80211ENUM_truth_true)) {
1991 wlandev->netdev->type = ARPHRD_IEEE80211_PRISM;
1993 wlandev->netdev->type = ARPHRD_IEEE80211;
1996 msg->resultcode.data = P80211ENUM_resultcode_success;
2001 msg->resultcode.data = P80211ENUM_resultcode_invalid_parameters;
2008 msg->resultcode.data = P80211ENUM_resultcode_refused;