Linux-libre 2.6.32.54-gnu1
[librecmc/linux-libre.git] / drivers / staging / wlan-ng / prism2mgmt.c
1 /* src/prism2/driver/prism2mgmt.c
2 *
3 * Management request handler functions.
4 *
5 * Copyright (C) 1999 AbsoluteValue Systems, Inc.  All Rights Reserved.
6 * --------------------------------------------------------------------
7 *
8 * linux-wlan
9 *
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/
14 *
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.
19 *
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.
30 *
31 * --------------------------------------------------------------------
32 *
33 * Inquiries regarding the linux-wlan Open Source project can be
34 * made directly to:
35 *
36 * AbsoluteValue Systems Inc.
37 * info@linux-wlan.com
38 * http://www.linux-wlan.com
39 *
40 * --------------------------------------------------------------------
41 *
42 * Portions of the development of this software were funded by
43 * Intersil Corporation as part of PRISM(R) chipset product development.
44 *
45 * --------------------------------------------------------------------
46 *
47 * The functions in this file handle management requests sent from
48 * user mode.
49 *
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.
56 *
57 * --------------------------------------------------------------------
58 */
59
60 #include <linux/if_arp.h>
61 #include <linux/module.h>
62 #include <linux/kernel.h>
63 #include <linux/wait.h>
64 #include <linux/sched.h>
65 #include <linux/types.h>
66 #include <linux/slab.h>
67 #include <linux/wireless.h>
68 #include <linux/netdevice.h>
69 #include <linux/delay.h>
70 #include <asm/io.h>
71 #include <asm/byteorder.h>
72 #include <linux/random.h>
73 #include <linux/usb.h>
74 #include <linux/bitops.h>
75
76 #include "p80211types.h"
77 #include "p80211hdr.h"
78 #include "p80211mgmt.h"
79 #include "p80211conv.h"
80 #include "p80211msg.h"
81 #include "p80211netdev.h"
82 #include "p80211metadef.h"
83 #include "p80211metastruct.h"
84 #include "hfa384x.h"
85 #include "prism2mgmt.h"
86
87 /* Converts 802.11 format rate specifications to prism2 */
88 #define p80211rate_to_p2bit(n)  ((((n)&~BIT(7)) == 2) ? BIT(0) :  \
89                                  (((n)&~BIT(7)) == 4) ? BIT(1) : \
90                                  (((n)&~BIT(7)) == 11) ? BIT(2) : \
91                                  (((n)&~BIT(7)) == 22) ? BIT(3) : 0)
92
93 /*----------------------------------------------------------------
94 * prism2mgmt_scan
95 *
96 * Initiate a scan for BSSs.
97 *
98 * This function corresponds to MLME-scan.request and part of
99 * MLME-scan.confirm.  As far as I can tell in the standard, there
100 * are no restrictions on when a scan.request may be issued.  We have
101 * to handle in whatever state the driver/MAC happen to be.
102 *
103 * Arguments:
104 *       wlandev         wlan device structure
105 *       msgp            ptr to msg buffer
106 *
107 * Returns:
108 *       0       success and done
109 *       <0      success, but we're waiting for something to finish.
110 *       >0      an error occurred while handling the message.
111 * Side effects:
112 *
113 * Call context:
114 *       process thread  (usually)
115 *       interrupt
116 ----------------------------------------------------------------*/
117 int prism2mgmt_scan(wlandevice_t *wlandev, void *msgp)
118 {
119         int result = 0;
120         hfa384x_t *hw = wlandev->priv;
121         p80211msg_dot11req_scan_t *msg = msgp;
122         u16 roamingmode, word;
123         int i, timeout;
124         int istmpenable = 0;
125
126         hfa384x_HostScanRequest_data_t scanreq;
127
128         /* gatekeeper check */
129         if (HFA384x_FIRMWARE_VERSION(hw->ident_sta_fw.major,
130                                      hw->ident_sta_fw.minor,
131                                      hw->ident_sta_fw.variant) <
132             HFA384x_FIRMWARE_VERSION(1, 3, 2)) {
133                 printk(KERN_ERR
134                        "HostScan not supported with current firmware (<1.3.2).\n");
135                 result = 1;
136                 msg->resultcode.data = P80211ENUM_resultcode_not_supported;
137                 goto exit;
138         }
139
140         memset(&scanreq, 0, sizeof(scanreq));
141
142         /* save current roaming mode */
143         result = hfa384x_drvr_getconfig16(hw,
144                                           HFA384x_RID_CNFROAMINGMODE,
145                                           &roamingmode);
146         if (result) {
147                 printk(KERN_ERR "getconfig(ROAMMODE) failed. result=%d\n",
148                        result);
149                 msg->resultcode.data =
150                     P80211ENUM_resultcode_implementation_failure;
151                 goto exit;
152         }
153
154         /* drop into mode 3 for the scan */
155         result = hfa384x_drvr_setconfig16(hw,
156                                           HFA384x_RID_CNFROAMINGMODE,
157                                           HFA384x_ROAMMODE_HOSTSCAN_HOSTROAM);
158         if (result) {
159                 printk(KERN_ERR "setconfig(ROAMINGMODE) failed. result=%d\n",
160                        result);
161                 msg->resultcode.data =
162                     P80211ENUM_resultcode_implementation_failure;
163                 goto exit;
164         }
165
166         /* active or passive? */
167         if (HFA384x_FIRMWARE_VERSION(hw->ident_sta_fw.major,
168                                      hw->ident_sta_fw.minor,
169                                      hw->ident_sta_fw.variant) >
170             HFA384x_FIRMWARE_VERSION(1, 5, 0)) {
171                 if (msg->scantype.data != P80211ENUM_scantype_active)
172                         word = cpu_to_le16(msg->maxchanneltime.data);
173                 else
174                         word = 0;
175
176                 result =
177                     hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFPASSIVESCANCTRL,
178                                              word);
179                 if (result) {
180                         printk(KERN_WARNING "Passive scan not supported with "
181                                "current firmware.  (<1.5.1)\n");
182                 }
183         }
184
185         /* set up the txrate to be 2MBPS. Should be fastest basicrate... */
186         word = HFA384x_RATEBIT_2;
187         scanreq.txRate = cpu_to_le16(word);
188
189         /* set up the channel list */
190         word = 0;
191         for (i = 0; i < msg->channellist.data.len; i++) {
192                 u8 channel = msg->channellist.data.data[i];
193                 if (channel > 14)
194                         continue;
195                 /* channel 1 is BIT 0 ... channel 14 is BIT 13 */
196                 word |= (1 << (channel - 1));
197         }
198         scanreq.channelList = cpu_to_le16(word);
199
200         /* set up the ssid, if present. */
201         scanreq.ssid.len = cpu_to_le16(msg->ssid.data.len);
202         memcpy(scanreq.ssid.data, msg->ssid.data.data, msg->ssid.data.len);
203
204         /* Enable the MAC port if it's not already enabled  */
205         result = hfa384x_drvr_getconfig16(hw, HFA384x_RID_PORTSTATUS, &word);
206         if (result) {
207                 printk(KERN_ERR "getconfig(PORTSTATUS) failed. "
208                        "result=%d\n", result);
209                 msg->resultcode.data =
210                     P80211ENUM_resultcode_implementation_failure;
211                 goto exit;
212         }
213         if (word == HFA384x_PORTSTATUS_DISABLED) {
214                 u16 wordbuf[17];
215
216                 result = hfa384x_drvr_setconfig16(hw,
217                                                   HFA384x_RID_CNFROAMINGMODE,
218                                                   HFA384x_ROAMMODE_HOSTSCAN_HOSTROAM);
219                 if (result) {
220                         printk(KERN_ERR
221                                "setconfig(ROAMINGMODE) failed. result=%d\n",
222                                result);
223                         msg->resultcode.data =
224                             P80211ENUM_resultcode_implementation_failure;
225                         goto exit;
226                 }
227                 /* Construct a bogus SSID and assign it to OwnSSID and
228                  * DesiredSSID
229                  */
230                 wordbuf[0] = cpu_to_le16(WLAN_SSID_MAXLEN);
231                 get_random_bytes(&wordbuf[1], WLAN_SSID_MAXLEN);
232                 result = hfa384x_drvr_setconfig(hw, HFA384x_RID_CNFOWNSSID,
233                                                 wordbuf,
234                                                 HFA384x_RID_CNFOWNSSID_LEN);
235                 if (result) {
236                         printk(KERN_ERR "Failed to set OwnSSID.\n");
237                         msg->resultcode.data =
238                             P80211ENUM_resultcode_implementation_failure;
239                         goto exit;
240                 }
241                 result = hfa384x_drvr_setconfig(hw, HFA384x_RID_CNFDESIREDSSID,
242                                                 wordbuf,
243                                                 HFA384x_RID_CNFDESIREDSSID_LEN);
244                 if (result) {
245                         printk(KERN_ERR "Failed to set DesiredSSID.\n");
246                         msg->resultcode.data =
247                             P80211ENUM_resultcode_implementation_failure;
248                         goto exit;
249                 }
250                 /* bsstype */
251                 result = hfa384x_drvr_setconfig16(hw,
252                                                   HFA384x_RID_CNFPORTTYPE,
253                                                   HFA384x_PORTTYPE_IBSS);
254                 if (result) {
255                         printk(KERN_ERR "Failed to set CNFPORTTYPE.\n");
256                         msg->resultcode.data =
257                             P80211ENUM_resultcode_implementation_failure;
258                         goto exit;
259                 }
260                 /* ibss options */
261                 result = hfa384x_drvr_setconfig16(hw,
262                                                   HFA384x_RID_CREATEIBSS,
263                                                   HFA384x_CREATEIBSS_JOINCREATEIBSS);
264                 if (result) {
265                         printk(KERN_ERR "Failed to set CREATEIBSS.\n");
266                         msg->resultcode.data =
267                             P80211ENUM_resultcode_implementation_failure;
268                         goto exit;
269                 }
270                 result = hfa384x_drvr_enable(hw, 0);
271                 if (result) {
272                         printk(KERN_ERR "drvr_enable(0) failed. "
273                                "result=%d\n", result);
274                         msg->resultcode.data =
275                             P80211ENUM_resultcode_implementation_failure;
276                         goto exit;
277                 }
278                 istmpenable = 1;
279         }
280
281         /* Figure out our timeout first Kus, then HZ */
282         timeout = msg->channellist.data.len * msg->maxchanneltime.data;
283         timeout = (timeout * HZ) / 1000;
284
285         /* Issue the scan request */
286         hw->scanflag = 0;
287
288         result = hfa384x_drvr_setconfig(hw,
289                                         HFA384x_RID_HOSTSCAN, &scanreq,
290                                         sizeof(hfa384x_HostScanRequest_data_t));
291         if (result) {
292                 printk(KERN_ERR "setconfig(SCANREQUEST) failed. result=%d\n",
293                        result);
294                 msg->resultcode.data =
295                     P80211ENUM_resultcode_implementation_failure;
296                 goto exit;
297         }
298
299         /* sleep until info frame arrives */
300         wait_event_interruptible_timeout(hw->cmdq, hw->scanflag, timeout);
301
302         msg->numbss.status = P80211ENUM_msgitem_status_data_ok;
303         if (hw->scanflag == -1)
304                 hw->scanflag = 0;
305
306         msg->numbss.data = hw->scanflag;
307
308         hw->scanflag = 0;
309
310         /* Disable port if we temporarily enabled it. */
311         if (istmpenable) {
312                 result = hfa384x_drvr_disable(hw, 0);
313                 if (result) {
314                         printk(KERN_ERR "drvr_disable(0) failed. "
315                                "result=%d\n", result);
316                         msg->resultcode.data =
317                             P80211ENUM_resultcode_implementation_failure;
318                         goto exit;
319                 }
320         }
321
322         /* restore original roaming mode */
323         result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFROAMINGMODE,
324                                           roamingmode);
325         if (result) {
326                 printk(KERN_ERR "setconfig(ROAMMODE) failed. result=%d\n",
327                        result);
328                 msg->resultcode.data =
329                     P80211ENUM_resultcode_implementation_failure;
330                 goto exit;
331         }
332
333         result = 0;
334         msg->resultcode.data = P80211ENUM_resultcode_success;
335
336 exit:
337         msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
338
339         return result;
340 }
341
342 /*----------------------------------------------------------------
343 * prism2mgmt_scan_results
344 *
345 * Retrieve the BSS description for one of the BSSs identified in
346 * a scan.
347 *
348 * Arguments:
349 *       wlandev         wlan device structure
350 *       msgp            ptr to msg buffer
351 *
352 * Returns:
353 *       0       success and done
354 *       <0      success, but we're waiting for something to finish.
355 *       >0      an error occurred while handling the message.
356 * Side effects:
357 *
358 * Call context:
359 *       process thread  (usually)
360 *       interrupt
361 ----------------------------------------------------------------*/
362 int prism2mgmt_scan_results(wlandevice_t *wlandev, void *msgp)
363 {
364         int result = 0;
365         p80211msg_dot11req_scan_results_t *req;
366         hfa384x_t *hw = wlandev->priv;
367         hfa384x_HScanResultSub_t *item = NULL;
368
369         int count;
370
371         req = (p80211msg_dot11req_scan_results_t *) msgp;
372
373         req->resultcode.status = P80211ENUM_msgitem_status_data_ok;
374
375         if (!hw->scanresults) {
376                 printk(KERN_ERR
377                        "dot11req_scan_results can only be used after a successful dot11req_scan.\n");
378                 result = 2;
379                 req->resultcode.data = P80211ENUM_resultcode_invalid_parameters;
380                 goto exit;
381         }
382
383         count = (hw->scanresults->framelen - 3) / 32;
384         if (count > 32)
385                 count = 32;
386
387         if (req->bssindex.data >= count) {
388                 pr_debug("requested index (%d) out of range (%d)\n",
389                          req->bssindex.data, count);
390                 result = 2;
391                 req->resultcode.data = P80211ENUM_resultcode_invalid_parameters;
392                 goto exit;
393         }
394
395         item = &(hw->scanresults->info.hscanresult.result[req->bssindex.data]);
396         /* signal and noise */
397         req->signal.status = P80211ENUM_msgitem_status_data_ok;
398         req->noise.status = P80211ENUM_msgitem_status_data_ok;
399         req->signal.data = le16_to_cpu(item->sl);
400         req->noise.data = le16_to_cpu(item->anl);
401
402         /* BSSID */
403         req->bssid.status = P80211ENUM_msgitem_status_data_ok;
404         req->bssid.data.len = WLAN_BSSID_LEN;
405         memcpy(req->bssid.data.data, item->bssid, WLAN_BSSID_LEN);
406
407         /* SSID */
408         req->ssid.status = P80211ENUM_msgitem_status_data_ok;
409         req->ssid.data.len = le16_to_cpu(item->ssid.len);
410         memcpy(req->ssid.data.data, item->ssid.data, req->ssid.data.len);
411
412         /* supported rates */
413         for (count = 0; count < 10; count++)
414                 if (item->supprates[count] == 0)
415                         break;
416
417 #define REQBASICRATE(N) \
418         if ((count >= N) && DOT11_RATE5_ISBASIC_GET(item->supprates[(N)-1])) { \
419                 req->basicrate ## N .data = item->supprates[(N)-1]; \
420                 req->basicrate ## N .status = P80211ENUM_msgitem_status_data_ok; \
421         }
422
423         REQBASICRATE(1);
424         REQBASICRATE(2);
425         REQBASICRATE(3);
426         REQBASICRATE(4);
427         REQBASICRATE(5);
428         REQBASICRATE(6);
429         REQBASICRATE(7);
430         REQBASICRATE(8);
431
432 #define REQSUPPRATE(N) \
433         if (count >= N) { \
434                 req->supprate ## N .data = item->supprates[(N)-1]; \
435                 req->supprate ## N .status = P80211ENUM_msgitem_status_data_ok; \
436         }
437
438         REQSUPPRATE(1);
439         REQSUPPRATE(2);
440         REQSUPPRATE(3);
441         REQSUPPRATE(4);
442         REQSUPPRATE(5);
443         REQSUPPRATE(6);
444         REQSUPPRATE(7);
445         REQSUPPRATE(8);
446
447         /* beacon period */
448         req->beaconperiod.status = P80211ENUM_msgitem_status_data_ok;
449         req->beaconperiod.data = le16_to_cpu(item->bcnint);
450
451         /* timestamps */
452         req->timestamp.status = P80211ENUM_msgitem_status_data_ok;
453         req->timestamp.data = jiffies;
454         req->localtime.status = P80211ENUM_msgitem_status_data_ok;
455         req->localtime.data = jiffies;
456
457         /* atim window */
458         req->ibssatimwindow.status = P80211ENUM_msgitem_status_data_ok;
459         req->ibssatimwindow.data = le16_to_cpu(item->atim);
460
461         /* Channel */
462         req->dschannel.status = P80211ENUM_msgitem_status_data_ok;
463         req->dschannel.data = le16_to_cpu(item->chid);
464
465         /* capinfo bits */
466         count = le16_to_cpu(item->capinfo);
467
468         /* privacy flag */
469         req->privacy.status = P80211ENUM_msgitem_status_data_ok;
470         req->privacy.data = WLAN_GET_MGMT_CAP_INFO_PRIVACY(count);
471
472         /* cfpollable */
473         req->cfpollable.status = P80211ENUM_msgitem_status_data_ok;
474         req->cfpollable.data = WLAN_GET_MGMT_CAP_INFO_CFPOLLABLE(count);
475
476         /* cfpollreq */
477         req->cfpollreq.status = P80211ENUM_msgitem_status_data_ok;
478         req->cfpollreq.data = WLAN_GET_MGMT_CAP_INFO_CFPOLLREQ(count);
479
480         /* bsstype */
481         req->bsstype.status = P80211ENUM_msgitem_status_data_ok;
482         req->bsstype.data = (WLAN_GET_MGMT_CAP_INFO_ESS(count)) ?
483             P80211ENUM_bsstype_infrastructure : P80211ENUM_bsstype_independent;
484
485         result = 0;
486         req->resultcode.data = P80211ENUM_resultcode_success;
487
488 exit:
489         return result;
490 }
491
492 /*----------------------------------------------------------------
493 * prism2mgmt_start
494 *
495 * Start a BSS.  Any station can do this for IBSS, only AP for ESS.
496 *
497 * Arguments:
498 *       wlandev         wlan device structure
499 *       msgp            ptr to msg buffer
500 *
501 * Returns:
502 *       0       success and done
503 *       <0      success, but we're waiting for something to finish.
504 *       >0      an error occurred while handling the message.
505 * Side effects:
506 *
507 * Call context:
508 *       process thread  (usually)
509 *       interrupt
510 ----------------------------------------------------------------*/
511 int prism2mgmt_start(wlandevice_t *wlandev, void *msgp)
512 {
513         int result = 0;
514         hfa384x_t *hw = wlandev->priv;
515         p80211msg_dot11req_start_t *msg = msgp;
516
517         p80211pstrd_t *pstr;
518         u8 bytebuf[80];
519         hfa384x_bytestr_t *p2bytestr = (hfa384x_bytestr_t *) bytebuf;
520         u16 word;
521
522         wlandev->macmode = WLAN_MACMODE_NONE;
523
524         /* Set the SSID */
525         memcpy(&wlandev->ssid, &msg->ssid.data, sizeof(msg->ssid.data));
526
527         /*** ADHOC IBSS ***/
528         /* see if current f/w is less than 8c3 */
529         if (HFA384x_FIRMWARE_VERSION(hw->ident_sta_fw.major,
530                                      hw->ident_sta_fw.minor,
531                                      hw->ident_sta_fw.variant) <
532             HFA384x_FIRMWARE_VERSION(0, 8, 3)) {
533                 /* Ad-Hoc not quite supported on Prism2 */
534                 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
535                 msg->resultcode.data = P80211ENUM_resultcode_not_supported;
536                 goto done;
537         }
538
539         msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
540
541         /*** STATION ***/
542         /* Set the REQUIRED config items */
543         /* SSID */
544         pstr = (p80211pstrd_t *) & (msg->ssid.data);
545         prism2mgmt_pstr2bytestr(p2bytestr, pstr);
546         result = hfa384x_drvr_setconfig(hw, HFA384x_RID_CNFOWNSSID,
547                                         bytebuf, HFA384x_RID_CNFOWNSSID_LEN);
548         if (result) {
549                 printk(KERN_ERR "Failed to set CnfOwnSSID\n");
550                 goto failed;
551         }
552         result = hfa384x_drvr_setconfig(hw, HFA384x_RID_CNFDESIREDSSID,
553                                         bytebuf,
554                                         HFA384x_RID_CNFDESIREDSSID_LEN);
555         if (result) {
556                 printk(KERN_ERR "Failed to set CnfDesiredSSID\n");
557                 goto failed;
558         }
559
560         /* bsstype - we use the default in the ap firmware */
561         /* IBSS port */
562         hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFPORTTYPE, 0);
563
564         /* beacon period */
565         word = msg->beaconperiod.data;
566         result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFAPBCNint, word);
567         if (result) {
568                 printk(KERN_ERR "Failed to set beacon period=%d.\n", word);
569                 goto failed;
570         }
571
572         /* dschannel */
573         word = msg->dschannel.data;
574         result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFOWNCHANNEL, word);
575         if (result) {
576                 printk(KERN_ERR "Failed to set channel=%d.\n", word);
577                 goto failed;
578         }
579         /* Basic rates */
580         word = p80211rate_to_p2bit(msg->basicrate1.data);
581         if (msg->basicrate2.status == P80211ENUM_msgitem_status_data_ok)
582                 word |= p80211rate_to_p2bit(msg->basicrate2.data);
583
584         if (msg->basicrate3.status == P80211ENUM_msgitem_status_data_ok)
585                 word |= p80211rate_to_p2bit(msg->basicrate3.data);
586
587         if (msg->basicrate4.status == P80211ENUM_msgitem_status_data_ok)
588                 word |= p80211rate_to_p2bit(msg->basicrate4.data);
589
590         if (msg->basicrate5.status == P80211ENUM_msgitem_status_data_ok)
591                 word |= p80211rate_to_p2bit(msg->basicrate5.data);
592
593         if (msg->basicrate6.status == P80211ENUM_msgitem_status_data_ok)
594                 word |= p80211rate_to_p2bit(msg->basicrate6.data);
595
596         if (msg->basicrate7.status == P80211ENUM_msgitem_status_data_ok)
597                 word |= p80211rate_to_p2bit(msg->basicrate7.data);
598
599         if (msg->basicrate8.status == P80211ENUM_msgitem_status_data_ok)
600                 word |= p80211rate_to_p2bit(msg->basicrate8.data);
601
602         result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFBASICRATES, word);
603         if (result) {
604                 printk(KERN_ERR "Failed to set basicrates=%d.\n", word);
605                 goto failed;
606         }
607
608         /* Operational rates (supprates and txratecontrol) */
609         word = p80211rate_to_p2bit(msg->operationalrate1.data);
610         if (msg->operationalrate2.status == P80211ENUM_msgitem_status_data_ok)
611                 word |= p80211rate_to_p2bit(msg->operationalrate2.data);
612
613         if (msg->operationalrate3.status == P80211ENUM_msgitem_status_data_ok)
614                 word |= p80211rate_to_p2bit(msg->operationalrate3.data);
615
616         if (msg->operationalrate4.status == P80211ENUM_msgitem_status_data_ok)
617                 word |= p80211rate_to_p2bit(msg->operationalrate4.data);
618
619         if (msg->operationalrate5.status == P80211ENUM_msgitem_status_data_ok)
620                 word |= p80211rate_to_p2bit(msg->operationalrate5.data);
621
622         if (msg->operationalrate6.status == P80211ENUM_msgitem_status_data_ok)
623                 word |= p80211rate_to_p2bit(msg->operationalrate6.data);
624
625         if (msg->operationalrate7.status == P80211ENUM_msgitem_status_data_ok)
626                 word |= p80211rate_to_p2bit(msg->operationalrate7.data);
627
628         if (msg->operationalrate8.status == P80211ENUM_msgitem_status_data_ok)
629                 word |= p80211rate_to_p2bit(msg->operationalrate8.data);
630
631         result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFSUPPRATES, word);
632         if (result) {
633                 printk(KERN_ERR "Failed to set supprates=%d.\n", word);
634                 goto failed;
635         }
636
637         result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_TXRATECNTL, word);
638         if (result) {
639                 printk(KERN_ERR "Failed to set txrates=%d.\n", word);
640                 goto failed;
641         }
642
643         /* Set the macmode so the frame setup code knows what to do */
644         if (msg->bsstype.data == P80211ENUM_bsstype_independent) {
645                 wlandev->macmode = WLAN_MACMODE_IBSS_STA;
646                 /* lets extend the data length a bit */
647                 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFMAXDATALEN, 2304);
648         }
649
650         /* Enable the Port */
651         result = hfa384x_drvr_enable(hw, 0);
652         if (result) {
653                 printk(KERN_ERR "Enable macport failed, result=%d.\n", result);
654                 goto failed;
655         }
656
657         msg->resultcode.data = P80211ENUM_resultcode_success;
658
659         goto done;
660 failed:
661         pr_debug("Failed to set a config option, result=%d\n", result);
662         msg->resultcode.data = P80211ENUM_resultcode_invalid_parameters;
663
664 done:
665         result = 0;
666
667         return result;
668 }
669
670 /*----------------------------------------------------------------
671 * prism2mgmt_readpda
672 *
673 * Collect the PDA data and put it in the message.
674 *
675 * Arguments:
676 *       wlandev         wlan device structure
677 *       msgp            ptr to msg buffer
678 *
679 * Returns:
680 *       0       success and done
681 *       <0      success, but we're waiting for something to finish.
682 *       >0      an error occurred while handling the message.
683 * Side effects:
684 *
685 * Call context:
686 *       process thread  (usually)
687 ----------------------------------------------------------------*/
688 int prism2mgmt_readpda(wlandevice_t *wlandev, void *msgp)
689 {
690         hfa384x_t *hw = wlandev->priv;
691         p80211msg_p2req_readpda_t *msg = msgp;
692         int result;
693
694         /* We only support collecting the PDA when in the FWLOAD
695          * state.
696          */
697         if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
698                 printk(KERN_ERR
699                        "PDA may only be read " "in the fwload state.\n");
700                 msg->resultcode.data =
701                     P80211ENUM_resultcode_implementation_failure;
702                 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
703         } else {
704                 /*  Call drvr_readpda(), it handles the auxport enable
705                  *  and validating the returned PDA.
706                  */
707                 result = hfa384x_drvr_readpda(hw,
708                                               msg->pda.data,
709                                               HFA384x_PDA_LEN_MAX);
710                 if (result) {
711                         printk(KERN_ERR
712                                "hfa384x_drvr_readpda() failed, "
713                                "result=%d\n", result);
714
715                         msg->resultcode.data =
716                             P80211ENUM_resultcode_implementation_failure;
717                         msg->resultcode.status =
718                             P80211ENUM_msgitem_status_data_ok;
719                         return 0;
720                 }
721                 msg->pda.status = P80211ENUM_msgitem_status_data_ok;
722                 msg->resultcode.data = P80211ENUM_resultcode_success;
723                 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
724         }
725
726         return 0;
727 }
728
729 /*----------------------------------------------------------------
730 * prism2mgmt_ramdl_state
731 *
732 * Establishes the beginning/end of a card RAM download session.
733 *
734 * It is expected that the ramdl_write() function will be called
735 * one or more times between the 'enable' and 'disable' calls to
736 * this function.
737 *
738 * Note: This function should not be called when a mac comm port
739 *       is active.
740 *
741 * Arguments:
742 *       wlandev         wlan device structure
743 *       msgp            ptr to msg buffer
744 *
745 * Returns:
746 *       0       success and done
747 *       <0      success, but we're waiting for something to finish.
748 *       >0      an error occurred while handling the message.
749 * Side effects:
750 *
751 * Call context:
752 *       process thread  (usually)
753 ----------------------------------------------------------------*/
754 int prism2mgmt_ramdl_state(wlandevice_t *wlandev, void *msgp)
755 {
756         hfa384x_t *hw = wlandev->priv;
757         p80211msg_p2req_ramdl_state_t *msg = msgp;
758
759         if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
760                 printk(KERN_ERR
761                        "ramdl_state(): may only be called "
762                        "in the fwload state.\n");
763                 msg->resultcode.data =
764                     P80211ENUM_resultcode_implementation_failure;
765                 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
766                 return 0;
767         }
768
769         /*
770          ** Note: Interrupts are locked out if this is an AP and are NOT
771          ** locked out if this is a station.
772          */
773
774         msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
775         if (msg->enable.data == P80211ENUM_truth_true) {
776                 if (hfa384x_drvr_ramdl_enable(hw, msg->exeaddr.data)) {
777                         msg->resultcode.data =
778                             P80211ENUM_resultcode_implementation_failure;
779                 } else {
780                         msg->resultcode.data = P80211ENUM_resultcode_success;
781                 }
782         } else {
783                 hfa384x_drvr_ramdl_disable(hw);
784                 msg->resultcode.data = P80211ENUM_resultcode_success;
785         }
786
787         return 0;
788 }
789
790 /*----------------------------------------------------------------
791 * prism2mgmt_ramdl_write
792 *
793 * Writes a buffer to the card RAM using the download state.  This
794 * is for writing code to card RAM.  To just read or write raw data
795 * use the aux functions.
796 *
797 * Arguments:
798 *       wlandev         wlan device structure
799 *       msgp            ptr to msg buffer
800 *
801 * Returns:
802 *       0       success and done
803 *       <0      success, but we're waiting for something to finish.
804 *       >0      an error occurred while handling the message.
805 * Side effects:
806 *
807 * Call context:
808 *       process thread  (usually)
809 ----------------------------------------------------------------*/
810 int prism2mgmt_ramdl_write(wlandevice_t *wlandev, void *msgp)
811 {
812         hfa384x_t *hw = wlandev->priv;
813         p80211msg_p2req_ramdl_write_t *msg = msgp;
814         u32 addr;
815         u32 len;
816         u8 *buf;
817
818         if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
819                 printk(KERN_ERR
820                        "ramdl_write(): may only be called "
821                        "in the fwload state.\n");
822                 msg->resultcode.data =
823                     P80211ENUM_resultcode_implementation_failure;
824                 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
825                 return 0;
826         }
827
828         msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
829         /* first validate the length */
830         if (msg->len.data > sizeof(msg->data.data)) {
831                 msg->resultcode.status =
832                     P80211ENUM_resultcode_invalid_parameters;
833                 return 0;
834         }
835         /* call the hfa384x function to do the write */
836         addr = msg->addr.data;
837         len = msg->len.data;
838         buf = msg->data.data;
839         if (hfa384x_drvr_ramdl_write(hw, addr, buf, len))
840                 msg->resultcode.data = P80211ENUM_resultcode_refused;
841
842         msg->resultcode.data = P80211ENUM_resultcode_success;
843
844         return 0;
845 }
846
847 /*----------------------------------------------------------------
848 * prism2mgmt_flashdl_state
849 *
850 * Establishes the beginning/end of a card Flash download session.
851 *
852 * It is expected that the flashdl_write() function will be called
853 * one or more times between the 'enable' and 'disable' calls to
854 * this function.
855 *
856 * Note: This function should not be called when a mac comm port
857 *       is active.
858 *
859 * Arguments:
860 *       wlandev         wlan device structure
861 *       msgp            ptr to msg buffer
862 *
863 * Returns:
864 *       0       success and done
865 *       <0      success, but we're waiting for something to finish.
866 *       >0      an error occurred while handling the message.
867 * Side effects:
868 *
869 * Call context:
870 *       process thread  (usually)
871 ----------------------------------------------------------------*/
872 int prism2mgmt_flashdl_state(wlandevice_t *wlandev, void *msgp)
873 {
874         int result = 0;
875         hfa384x_t *hw = wlandev->priv;
876         p80211msg_p2req_flashdl_state_t *msg = msgp;
877
878         if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
879                 printk(KERN_ERR
880                        "flashdl_state(): may only be called "
881                        "in the fwload state.\n");
882                 msg->resultcode.data =
883                     P80211ENUM_resultcode_implementation_failure;
884                 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
885                 return 0;
886         }
887
888         /*
889          ** Note: Interrupts are locked out if this is an AP and are NOT
890          ** locked out if this is a station.
891          */
892
893         msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
894         if (msg->enable.data == P80211ENUM_truth_true) {
895                 if (hfa384x_drvr_flashdl_enable(hw)) {
896                         msg->resultcode.data =
897                             P80211ENUM_resultcode_implementation_failure;
898                 } else {
899                         msg->resultcode.data = P80211ENUM_resultcode_success;
900                 }
901         } else {
902                 hfa384x_drvr_flashdl_disable(hw);
903                 msg->resultcode.data = P80211ENUM_resultcode_success;
904                 /* NOTE: At this point, the MAC is in the post-reset
905                  * state and the driver is in the fwload state.
906                  * We need to get the MAC back into the fwload
907                  * state.  To do this, we set the nsdstate to HWPRESENT
908                  * and then call the ifstate function to redo everything
909                  * that got us into the fwload state.
910                  */
911                 wlandev->msdstate = WLAN_MSD_HWPRESENT;
912                 result = prism2sta_ifstate(wlandev, P80211ENUM_ifstate_fwload);
913                 if (result != P80211ENUM_resultcode_success) {
914                         printk(KERN_ERR "prism2sta_ifstate(fwload) failed,"
915                                "P80211ENUM_resultcode=%d\n", result);
916                         msg->resultcode.data =
917                             P80211ENUM_resultcode_implementation_failure;
918                         result = -1;
919                 }
920         }
921
922         return 0;
923 }
924
925 /*----------------------------------------------------------------
926 * prism2mgmt_flashdl_write
927 *
928 *
929 *
930 * Arguments:
931 *       wlandev         wlan device structure
932 *       msgp            ptr to msg buffer
933 *
934 * Returns:
935 *       0       success and done
936 *       <0      success, but we're waiting for something to finish.
937 *       >0      an error occurred while handling the message.
938 * Side effects:
939 *
940 * Call context:
941 *       process thread  (usually)
942 ----------------------------------------------------------------*/
943 int prism2mgmt_flashdl_write(wlandevice_t *wlandev, void *msgp)
944 {
945         hfa384x_t *hw = wlandev->priv;
946         p80211msg_p2req_flashdl_write_t *msg = msgp;
947         u32 addr;
948         u32 len;
949         u8 *buf;
950
951         if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
952                 printk(KERN_ERR
953                        "flashdl_write(): may only be called "
954                        "in the fwload state.\n");
955                 msg->resultcode.data =
956                     P80211ENUM_resultcode_implementation_failure;
957                 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
958                 return 0;
959         }
960
961         /*
962          ** Note: Interrupts are locked out if this is an AP and are NOT
963          ** locked out if this is a station.
964          */
965
966         msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
967         /* first validate the length */
968         if (msg->len.data > sizeof(msg->data.data)) {
969                 msg->resultcode.status =
970                     P80211ENUM_resultcode_invalid_parameters;
971                 return 0;
972         }
973         /* call the hfa384x function to do the write */
974         addr = msg->addr.data;
975         len = msg->len.data;
976         buf = msg->data.data;
977         if (hfa384x_drvr_flashdl_write(hw, addr, buf, len))
978                 msg->resultcode.data = P80211ENUM_resultcode_refused;
979
980         msg->resultcode.data = P80211ENUM_resultcode_success;
981
982         return 0;
983 }
984
985 /*----------------------------------------------------------------
986 * prism2mgmt_autojoin
987 *
988 * Associate with an ESS.
989 *
990 * Arguments:
991 *       wlandev         wlan device structure
992 *       msgp            ptr to msg buffer
993 *
994 * Returns:
995 *       0       success and done
996 *       <0      success, but we're waiting for something to finish.
997 *       >0      an error occurred while handling the message.
998 * Side effects:
999 *
1000 * Call context:
1001 *       process thread  (usually)
1002 *       interrupt
1003 ----------------------------------------------------------------*/
1004 int prism2mgmt_autojoin(wlandevice_t *wlandev, void *msgp)
1005 {
1006         hfa384x_t *hw = wlandev->priv;
1007         int result = 0;
1008         u16 reg;
1009         u16 port_type;
1010         p80211msg_lnxreq_autojoin_t *msg = msgp;
1011         p80211pstrd_t *pstr;
1012         u8 bytebuf[256];
1013         hfa384x_bytestr_t *p2bytestr = (hfa384x_bytestr_t *) bytebuf;
1014
1015         wlandev->macmode = WLAN_MACMODE_NONE;
1016
1017         /* Set the SSID */
1018         memcpy(&wlandev->ssid, &msg->ssid.data, sizeof(msg->ssid.data));
1019
1020         /* Disable the Port */
1021         hfa384x_drvr_disable(hw, 0);
1022
1023         /*** STATION ***/
1024         /* Set the TxRates */
1025         hfa384x_drvr_setconfig16(hw, HFA384x_RID_TXRATECNTL, 0x000f);
1026
1027         /* Set the auth type */
1028         if (msg->authtype.data == P80211ENUM_authalg_sharedkey)
1029                 reg = HFA384x_CNFAUTHENTICATION_SHAREDKEY;
1030         else
1031                 reg = HFA384x_CNFAUTHENTICATION_OPENSYSTEM;
1032
1033         hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFAUTHENTICATION, reg);
1034
1035         /* Set the ssid */
1036         memset(bytebuf, 0, 256);
1037         pstr = (p80211pstrd_t *) & (msg->ssid.data);
1038         prism2mgmt_pstr2bytestr(p2bytestr, pstr);
1039         result = hfa384x_drvr_setconfig(hw, HFA384x_RID_CNFDESIREDSSID,
1040                                         bytebuf,
1041                                         HFA384x_RID_CNFDESIREDSSID_LEN);
1042         port_type = HFA384x_PORTTYPE_BSS;
1043         /* Set the PortType */
1044         hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFPORTTYPE, port_type);
1045
1046         /* Enable the Port */
1047         hfa384x_drvr_enable(hw, 0);
1048
1049         /* Set the resultcode */
1050         msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
1051         msg->resultcode.data = P80211ENUM_resultcode_success;
1052
1053         return result;
1054 }
1055
1056 /*----------------------------------------------------------------
1057 * prism2mgmt_wlansniff
1058 *
1059 * Start or stop sniffing.
1060 *
1061 * Arguments:
1062 *       wlandev         wlan device structure
1063 *       msgp            ptr to msg buffer
1064 *
1065 * Returns:
1066 *       0       success and done
1067 *       <0      success, but we're waiting for something to finish.
1068 *       >0      an error occurred while handling the message.
1069 * Side effects:
1070 *
1071 * Call context:
1072 *       process thread  (usually)
1073 *       interrupt
1074 ----------------------------------------------------------------*/
1075 int prism2mgmt_wlansniff(wlandevice_t *wlandev, void *msgp)
1076 {
1077         int result = 0;
1078         p80211msg_lnxreq_wlansniff_t *msg = msgp;
1079
1080         hfa384x_t *hw = wlandev->priv;
1081         u16 word;
1082
1083         msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
1084         switch (msg->enable.data) {
1085         case P80211ENUM_truth_false:
1086                 /* Confirm that we're in monitor mode */
1087                 if (wlandev->netdev->type == ARPHRD_ETHER) {
1088                         msg->resultcode.data =
1089                             P80211ENUM_resultcode_invalid_parameters;
1090                         result = 0;
1091                         goto exit;
1092                 }
1093                 /* Disable monitor mode */
1094                 result = hfa384x_cmd_monitor(hw, HFA384x_MONITOR_DISABLE);
1095                 if (result) {
1096                         pr_debug("failed to disable monitor mode, result=%d\n",
1097                                  result);
1098                         goto failed;
1099                 }
1100                 /* Disable port 0 */
1101                 result = hfa384x_drvr_disable(hw, 0);
1102                 if (result) {
1103                         pr_debug
1104                             ("failed to disable port 0 after sniffing, result=%d\n",
1105                              result);
1106                         goto failed;
1107                 }
1108                 /* Clear the driver state */
1109                 wlandev->netdev->type = ARPHRD_ETHER;
1110
1111                 /* Restore the wepflags */
1112                 result = hfa384x_drvr_setconfig16(hw,
1113                                                   HFA384x_RID_CNFWEPFLAGS,
1114                                                   hw->presniff_wepflags);
1115                 if (result) {
1116                         pr_debug
1117                             ("failed to restore wepflags=0x%04x, result=%d\n",
1118                              hw->presniff_wepflags, result);
1119                         goto failed;
1120                 }
1121
1122                 /* Set the port to its prior type and enable (if necessary) */
1123                 if (hw->presniff_port_type != 0) {
1124                         word = hw->presniff_port_type;
1125                         result = hfa384x_drvr_setconfig16(hw,
1126                                                           HFA384x_RID_CNFPORTTYPE,
1127                                                           word);
1128                         if (result) {
1129                                 pr_debug
1130                                     ("failed to restore porttype, result=%d\n",
1131                                      result);
1132                                 goto failed;
1133                         }
1134
1135                         /* Enable the port */
1136                         result = hfa384x_drvr_enable(hw, 0);
1137                         if (result) {
1138                                 pr_debug
1139                                     ("failed to enable port to presniff setting, result=%d\n",
1140                                      result);
1141                                 goto failed;
1142                         }
1143                 } else {
1144                         result = hfa384x_drvr_disable(hw, 0);
1145
1146                 }
1147
1148                 printk(KERN_INFO "monitor mode disabled\n");
1149                 msg->resultcode.data = P80211ENUM_resultcode_success;
1150                 result = 0;
1151                 goto exit;
1152                 break;
1153         case P80211ENUM_truth_true:
1154                 /* Disable the port (if enabled), only check Port 0 */
1155                 if (hw->port_enabled[0]) {
1156                         if (wlandev->netdev->type == ARPHRD_ETHER) {
1157                                 /* Save macport 0 state */
1158                                 result = hfa384x_drvr_getconfig16(hw,
1159                                                                   HFA384x_RID_CNFPORTTYPE,
1160                                                                   &
1161                                                                   (hw->
1162                                                                    presniff_port_type));
1163                                 if (result) {
1164                                         pr_debug
1165                                             ("failed to read porttype, result=%d\n",
1166                                              result);
1167                                         goto failed;
1168                                 }
1169                                 /* Save the wepflags state */
1170                                 result = hfa384x_drvr_getconfig16(hw,
1171                                                                   HFA384x_RID_CNFWEPFLAGS,
1172                                                                   &
1173                                                                   (hw->
1174                                                                    presniff_wepflags));
1175                                 if (result) {
1176                                         pr_debug
1177                                             ("failed to read wepflags, result=%d\n",
1178                                              result);
1179                                         goto failed;
1180                                 }
1181                                 hfa384x_drvr_stop(hw);
1182                                 result = hfa384x_drvr_start(hw);
1183                                 if (result) {
1184                                         pr_debug
1185                                             ("failed to restart the card for sniffing, result=%d\n",
1186                                              result);
1187                                         goto failed;
1188                                 }
1189                         } else {
1190                                 /* Disable the port */
1191                                 result = hfa384x_drvr_disable(hw, 0);
1192                                 if (result) {
1193                                         pr_debug
1194                                             ("failed to enable port for sniffing, result=%d\n",
1195                                              result);
1196                                         goto failed;
1197                                 }
1198                         }
1199                 } else {
1200                         hw->presniff_port_type = 0;
1201                 }
1202
1203                 /* Set the channel we wish to sniff  */
1204                 word = msg->channel.data;
1205                 result = hfa384x_drvr_setconfig16(hw,
1206                                                   HFA384x_RID_CNFOWNCHANNEL,
1207                                                   word);
1208                 hw->sniff_channel = word;
1209
1210                 if (result) {
1211                         pr_debug("failed to set channel %d, result=%d\n",
1212                                  word, result);
1213                         goto failed;
1214                 }
1215
1216                 /* Now if we're already sniffing, we can skip the rest */
1217                 if (wlandev->netdev->type != ARPHRD_ETHER) {
1218                         /* Set the port type to pIbss */
1219                         word = HFA384x_PORTTYPE_PSUEDOIBSS;
1220                         result = hfa384x_drvr_setconfig16(hw,
1221                                                           HFA384x_RID_CNFPORTTYPE,
1222                                                           word);
1223                         if (result) {
1224                                 pr_debug
1225                                     ("failed to set porttype %d, result=%d\n",
1226                                      word, result);
1227                                 goto failed;
1228                         }
1229                         if ((msg->keepwepflags.status ==
1230                              P80211ENUM_msgitem_status_data_ok)
1231                             && (msg->keepwepflags.data !=
1232                                 P80211ENUM_truth_true)) {
1233                                 /* Set the wepflags for no decryption */
1234                                 word = HFA384x_WEPFLAGS_DISABLE_TXCRYPT |
1235                                     HFA384x_WEPFLAGS_DISABLE_RXCRYPT;
1236                                 result =
1237                                     hfa384x_drvr_setconfig16(hw,
1238                                                              HFA384x_RID_CNFWEPFLAGS,
1239                                                              word);
1240                         }
1241
1242                         if (result) {
1243                                 pr_debug
1244                                     ("failed to set wepflags=0x%04x, result=%d\n",
1245                                      word, result);
1246                                 goto failed;
1247                         }
1248                 }
1249
1250                 /* Do we want to strip the FCS in monitor mode? */
1251                 if ((msg->stripfcs.status == P80211ENUM_msgitem_status_data_ok)
1252                     && (msg->stripfcs.data == P80211ENUM_truth_true)) {
1253                         hw->sniff_fcs = 0;
1254                 } else {
1255                         hw->sniff_fcs = 1;
1256                 }
1257
1258                 /* Do we want to truncate the packets? */
1259                 if (msg->packet_trunc.status ==
1260                     P80211ENUM_msgitem_status_data_ok) {
1261                         hw->sniff_truncate = msg->packet_trunc.data;
1262                 } else {
1263                         hw->sniff_truncate = 0;
1264                 }
1265
1266                 /* Enable the port */
1267                 result = hfa384x_drvr_enable(hw, 0);
1268                 if (result) {
1269                         pr_debug
1270                             ("failed to enable port for sniffing, result=%d\n",
1271                              result);
1272                         goto failed;
1273                 }
1274                 /* Enable monitor mode */
1275                 result = hfa384x_cmd_monitor(hw, HFA384x_MONITOR_ENABLE);
1276                 if (result) {
1277                         pr_debug("failed to enable monitor mode, result=%d\n",
1278                                  result);
1279                         goto failed;
1280                 }
1281
1282                 if (wlandev->netdev->type == ARPHRD_ETHER)
1283                         printk(KERN_INFO "monitor mode enabled\n");
1284
1285                 /* Set the driver state */
1286                 /* Do we want the prism2 header? */
1287                 if ((msg->prismheader.status ==
1288                      P80211ENUM_msgitem_status_data_ok)
1289                     && (msg->prismheader.data == P80211ENUM_truth_true)) {
1290                         hw->sniffhdr = 0;
1291                         wlandev->netdev->type = ARPHRD_IEEE80211_PRISM;
1292                 } else
1293                     if ((msg->wlanheader.status ==
1294                          P80211ENUM_msgitem_status_data_ok)
1295                         && (msg->wlanheader.data == P80211ENUM_truth_true)) {
1296                         hw->sniffhdr = 1;
1297                         wlandev->netdev->type = ARPHRD_IEEE80211_PRISM;
1298                 } else {
1299                         wlandev->netdev->type = ARPHRD_IEEE80211;
1300                 }
1301
1302                 msg->resultcode.data = P80211ENUM_resultcode_success;
1303                 result = 0;
1304                 goto exit;
1305                 break;
1306         default:
1307                 msg->resultcode.data = P80211ENUM_resultcode_invalid_parameters;
1308                 result = 0;
1309                 goto exit;
1310                 break;
1311         }
1312
1313 failed:
1314         msg->resultcode.data = P80211ENUM_resultcode_refused;
1315         result = 0;
1316 exit:
1317         return result;
1318 }