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