Staging: wlan-ng: Replace WLAN_LOG_WARNING() with printk()
[linux-2.6] / drivers / staging / wlan-ng / prism2mib.c
1 /* src/prism2/driver/prism2mib.c
2 *
3 * Management request for mibset/mibget
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 the mibset/mibget management
48 * functions.
49 *
50 * --------------------------------------------------------------------
51 */
52
53 /*================================================================*/
54 /* System Includes */
55 #define WLAN_DBVAR      prism2_debug
56
57 #include <linux/version.h>
58
59 #include <linux/module.h>
60 #include <linux/kernel.h>
61 #include <linux/sched.h>
62 #include <linux/types.h>
63 #include <linux/slab.h>
64 #include <linux/wireless.h>
65 #include <linux/netdevice.h>
66 #include <asm/io.h>
67 #include <linux/delay.h>
68 #include <asm/byteorder.h>
69 #include <linux/usb.h>
70 #include <linux/bitops.h>
71
72 /*================================================================*/
73 /* Project Includes */
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 /*================================================================*/
87 /* Local Constants */
88
89 #define MIB_TMP_MAXLEN    200    /* Max length of RID record (in bytes). */
90
91 /*================================================================*/
92 /* Local Types */
93
94 #define  F_STA        0x1        /* MIB is supported on stations. */
95 #define  F_READ       0x2        /* MIB may be read. */
96 #define  F_WRITE      0x4        /* MIB may be written. */
97
98 typedef struct mibrec
99 {
100     u32   did;
101     u16   flag;
102     u16   parm1;
103     u16   parm2;
104     u16   parm3;
105     int      (*func)(struct mibrec                *mib,
106                      int                          isget,
107                      wlandevice_t                 *wlandev,
108                      hfa384x_t                    *hw,
109                      p80211msg_dot11req_mibset_t  *msg,
110                      void                         *data);
111 } mibrec_t;
112
113 /*================================================================*/
114 /* Local Function Declarations */
115
116 static int prism2mib_bytearea2pstr(
117 mibrec_t                     *mib,
118 int                          isget,
119 wlandevice_t                 *wlandev,
120 hfa384x_t                    *hw,
121 p80211msg_dot11req_mibset_t  *msg,
122 void                         *data);
123
124 static int prism2mib_uint32(
125 mibrec_t                     *mib,
126 int                          isget,
127 wlandevice_t                 *wlandev,
128 hfa384x_t                    *hw,
129 p80211msg_dot11req_mibset_t  *msg,
130 void                         *data);
131
132 static int prism2mib_flag(
133 mibrec_t                     *mib,
134 int                          isget,
135 wlandevice_t                 *wlandev,
136 hfa384x_t                    *hw,
137 p80211msg_dot11req_mibset_t  *msg,
138 void                         *data);
139
140 static int prism2mib_wepdefaultkey(
141 mibrec_t                     *mib,
142 int                          isget,
143 wlandevice_t                 *wlandev,
144 hfa384x_t                    *hw,
145 p80211msg_dot11req_mibset_t  *msg,
146 void                         *data);
147
148 static int prism2mib_privacyinvoked(
149 mibrec_t                     *mib,
150 int                          isget,
151 wlandevice_t                 *wlandev,
152 hfa384x_t                    *hw,
153 p80211msg_dot11req_mibset_t  *msg,
154 void                         *data);
155
156 static int prism2mib_excludeunencrypted(
157 mibrec_t                     *mib,
158 int                          isget,
159 wlandevice_t                 *wlandev,
160 hfa384x_t                    *hw,
161 p80211msg_dot11req_mibset_t  *msg,
162 void                         *data);
163
164 static int prism2mib_fragmentationthreshold(
165 mibrec_t                     *mib,
166 int                          isget,
167 wlandevice_t                 *wlandev,
168 hfa384x_t                    *hw,
169 p80211msg_dot11req_mibset_t  *msg,
170 void                         *data);
171
172 static int prism2mib_priv(
173 mibrec_t                     *mib,
174 int                          isget,
175 wlandevice_t                 *wlandev,
176 hfa384x_t                    *hw,
177 p80211msg_dot11req_mibset_t  *msg,
178 void                         *data);
179
180 /*================================================================*/
181 /* Local Static Definitions */
182
183 static mibrec_t mibtab[] = {
184
185     /* dot11smt MIB's */
186     { DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey0,
187           F_STA | F_WRITE,
188           HFA384x_RID_CNFWEPDEFAULTKEY0, 0, 0,
189           prism2mib_wepdefaultkey },
190     { DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey1,
191           F_STA | F_WRITE,
192           HFA384x_RID_CNFWEPDEFAULTKEY1, 0, 0,
193           prism2mib_wepdefaultkey },
194     { DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey2,
195           F_STA | F_WRITE,
196           HFA384x_RID_CNFWEPDEFAULTKEY2, 0, 0,
197           prism2mib_wepdefaultkey },
198     { DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey3,
199           F_STA | F_WRITE,
200           HFA384x_RID_CNFWEPDEFAULTKEY3, 0, 0,
201           prism2mib_wepdefaultkey },
202     { DIDmib_dot11smt_dot11PrivacyTable_dot11PrivacyInvoked,
203           F_STA | F_READ | F_WRITE,
204           HFA384x_RID_CNFWEPFLAGS, HFA384x_WEPFLAGS_PRIVINVOKED, 0,
205           prism2mib_privacyinvoked },
206     { DIDmib_dot11smt_dot11PrivacyTable_dot11WEPDefaultKeyID,
207           F_STA | F_READ | F_WRITE,
208           HFA384x_RID_CNFWEPDEFAULTKEYID, 0, 0,
209           prism2mib_uint32 },
210     { DIDmib_dot11smt_dot11PrivacyTable_dot11ExcludeUnencrypted,
211           F_STA | F_READ | F_WRITE,
212           HFA384x_RID_CNFWEPFLAGS, HFA384x_WEPFLAGS_EXCLUDE, 0,
213           prism2mib_excludeunencrypted },
214
215     /* dot11mac MIB's */
216
217     { DIDmib_dot11mac_dot11OperationTable_dot11MACAddress,
218           F_STA | F_READ | F_WRITE,
219           HFA384x_RID_CNFOWNMACADDR, HFA384x_RID_CNFOWNMACADDR_LEN, 0,
220           prism2mib_bytearea2pstr },
221     { DIDmib_dot11mac_dot11OperationTable_dot11RTSThreshold,
222           F_STA | F_READ | F_WRITE,
223           HFA384x_RID_RTSTHRESH, 0, 0,
224           prism2mib_uint32 },
225     { DIDmib_dot11mac_dot11OperationTable_dot11ShortRetryLimit,
226           F_STA | F_READ,
227           HFA384x_RID_SHORTRETRYLIMIT, 0, 0,
228           prism2mib_uint32 },
229     { DIDmib_dot11mac_dot11OperationTable_dot11LongRetryLimit,
230           F_STA | F_READ,
231           HFA384x_RID_LONGRETRYLIMIT, 0, 0,
232           prism2mib_uint32 },
233     { DIDmib_dot11mac_dot11OperationTable_dot11FragmentationThreshold,
234           F_STA | F_READ | F_WRITE,
235           HFA384x_RID_FRAGTHRESH, 0, 0,
236           prism2mib_fragmentationthreshold },
237     { DIDmib_dot11mac_dot11OperationTable_dot11MaxTransmitMSDULifetime,
238           F_STA | F_READ,
239           HFA384x_RID_MAXTXLIFETIME, 0, 0,
240           prism2mib_uint32 },
241
242     /* dot11phy MIB's */
243
244     { DIDmib_dot11phy_dot11PhyDSSSTable_dot11CurrentChannel,
245           F_STA | F_READ,
246           HFA384x_RID_CURRENTCHANNEL, 0, 0,
247           prism2mib_uint32 },
248     { DIDmib_dot11phy_dot11PhyTxPowerTable_dot11CurrentTxPowerLevel,
249           F_STA | F_READ | F_WRITE,
250           HFA384x_RID_TXPOWERMAX, 0, 0,
251           prism2mib_uint32 },
252
253     /* p2Static MIB's */
254
255     { DIDmib_p2_p2Static_p2CnfPortType,
256           F_STA | F_READ | F_WRITE,
257           HFA384x_RID_CNFPORTTYPE, 0, 0,
258           prism2mib_uint32 },
259
260     /* p2MAC MIB's */
261
262     { DIDmib_p2_p2MAC_p2CurrentTxRate,
263           F_STA | F_READ,
264           HFA384x_RID_CURRENTTXRATE, 0, 0,
265           prism2mib_uint32 },
266
267     /* And finally, lnx mibs */
268     { DIDmib_lnx_lnxConfigTable_lnxRSNAIE,
269           F_STA | F_READ | F_WRITE,
270           HFA384x_RID_CNFWPADATA, 0, 0,
271           prism2mib_priv },
272     { 0, 0, 0, 0, 0, NULL}};
273
274 /*================================================================*/
275 /* Function Definitions */
276
277 /*----------------------------------------------------------------
278 * prism2mgmt_mibset_mibget
279 *
280 * Set the value of a mib item.
281 *
282 * Arguments:
283 *       wlandev         wlan device structure
284 *       msgp            ptr to msg buffer
285 *
286 * Returns:
287 *       0       success and done
288 *       <0      success, but we're waiting for something to finish.
289 *       >0      an error occurred while handling the message.
290 * Side effects:
291 *
292 * Call context:
293 *       process thread  (usually)
294 *       interrupt
295 ----------------------------------------------------------------*/
296
297 int prism2mgmt_mibset_mibget(wlandevice_t *wlandev, void *msgp)
298 {
299         hfa384x_t               *hw = wlandev->priv;
300         int                     result, isget;
301         mibrec_t                *mib;
302
303         u16                     which;
304
305         p80211msg_dot11req_mibset_t     *msg = msgp;
306         p80211itemd_t                   *mibitem;
307
308         msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
309         msg->resultcode.data = P80211ENUM_resultcode_success;
310
311         /*
312         ** Determine if this is an Access Point or a station.
313         */
314
315         which = F_STA;
316
317         /*
318         ** Find the MIB in the MIB table.  Note that a MIB may be in the
319         ** table twice...once for an AP and once for a station.  Make sure
320         ** to get the correct one.  Note that DID=0 marks the end of the
321         ** MIB table.
322         */
323
324         mibitem = (p80211itemd_t *) msg->mibattribute.data;
325
326         for (mib = mibtab; mib->did != 0; mib++)
327                 if (mib->did == mibitem->did && (mib->flag & which))
328                         break;
329
330         if (mib->did == 0) {
331                 msg->resultcode.data = P80211ENUM_resultcode_not_supported;
332                 goto done;
333         }
334
335         /*
336         ** Determine if this is a "mibget" or a "mibset".  If this is a
337         ** "mibget", then make sure that the MIB may be read.  Otherwise,
338         ** this is a "mibset" so make make sure that the MIB may be written.
339         */
340
341         isget = (msg->msgcode == DIDmsg_dot11req_mibget);
342
343         if (isget) {
344                 if (!(mib->flag & F_READ)) {
345                         msg->resultcode.data =
346                                 P80211ENUM_resultcode_cant_get_writeonly_mib;
347                         goto done;
348                 }
349         } else {
350                 if (!(mib->flag & F_WRITE)) {
351                         msg->resultcode.data =
352                                 P80211ENUM_resultcode_cant_set_readonly_mib;
353                         goto done;
354                 }
355         }
356
357         /*
358         ** Execute the MIB function.  If things worked okay, then make
359         ** sure that the MIB function also worked okay.  If so, and this
360         ** is a "mibget", then the status value must be set for both the
361         ** "mibattribute" parameter and the mib item within the data
362         ** portion of the "mibattribute".
363         */
364
365         result = mib->func(mib, isget, wlandev, hw, msg,
366                            (void *) mibitem->data);
367
368         if (msg->resultcode.data == P80211ENUM_resultcode_success) {
369                 if (result != 0) {
370                         WLAN_LOG_DEBUG(1, "get/set failure, result=%d\n",
371                                         result);
372                         msg->resultcode.data =
373                                  P80211ENUM_resultcode_implementation_failure;
374                 } else {
375                         if (isget) {
376                                 msg->mibattribute.status =
377                                         P80211ENUM_msgitem_status_data_ok;
378                                 mibitem->status =
379                                         P80211ENUM_msgitem_status_data_ok;
380                         }
381                 }
382         }
383
384 done:
385         return(0);
386 }
387
388 /*----------------------------------------------------------------
389 * prism2mib_bytearea2pstr
390 *
391 * Get/set pstr data to/from a byte area.
392 *
393 * MIB record parameters:
394 *       parm1    Prism2 RID value.
395 *       parm2    Number of bytes of RID data.
396 *       parm3    Not used.
397 *
398 * Arguments:
399 *       mib      MIB record.
400 *       isget    MIBGET/MIBSET flag.
401 *       wlandev  wlan device structure.
402 *       priv     "priv" structure.
403 *       hw       "hw" structure.
404 *       msg      Message structure.
405 *       data     Data buffer.
406 *
407 * Returns:
408 *       0   - Success.
409 *       ~0  - Error.
410 *
411 ----------------------------------------------------------------*/
412
413 static int prism2mib_bytearea2pstr(
414 mibrec_t                     *mib,
415 int                          isget,
416 wlandevice_t                 *wlandev,
417 hfa384x_t                    *hw,
418 p80211msg_dot11req_mibset_t  *msg,
419 void                         *data)
420 {
421         int            result;
422         p80211pstrd_t  *pstr = (p80211pstrd_t*) data;
423         u8          bytebuf[MIB_TMP_MAXLEN];
424
425         if (isget) {
426                 result = hfa384x_drvr_getconfig(hw, mib->parm1, bytebuf, mib->parm2);
427                 prism2mgmt_bytearea2pstr(bytebuf, pstr, mib->parm2);
428         } else {
429                 memset(bytebuf, 0, mib->parm2);
430                 prism2mgmt_pstr2bytearea(bytebuf, pstr);
431                 result = hfa384x_drvr_setconfig(hw, mib->parm1, bytebuf, mib->parm2);
432         }
433
434         return(result);
435 }
436
437 /*----------------------------------------------------------------
438 * prism2mib_uint32
439 *
440 * Get/set uint32 data.
441 *
442 * MIB record parameters:
443 *       parm1    Prism2 RID value.
444 *       parm2    Not used.
445 *       parm3    Not used.
446 *
447 * Arguments:
448 *       mib      MIB record.
449 *       isget    MIBGET/MIBSET flag.
450 *       wlandev  wlan device structure.
451 *       priv     "priv" structure.
452 *       hw       "hw" structure.
453 *       msg      Message structure.
454 *       data     Data buffer.
455 *
456 * Returns:
457 *       0   - Success.
458 *       ~0  - Error.
459 *
460 ----------------------------------------------------------------*/
461
462 static int prism2mib_uint32(
463 mibrec_t                     *mib,
464 int                          isget,
465 wlandevice_t                 *wlandev,
466 hfa384x_t                    *hw,
467 p80211msg_dot11req_mibset_t  *msg,
468 void                         *data)
469 {
470         int     result;
471         u32  *uint32 = (u32*) data;
472         u8   bytebuf[MIB_TMP_MAXLEN];
473         u16  *wordbuf = (u16*) bytebuf;
474
475         if (isget) {
476                 result = hfa384x_drvr_getconfig16(hw, mib->parm1, wordbuf);
477                 *uint32 = *wordbuf;
478                 /* [MSM] Removed, getconfig16 returns the value in host order.
479                  * prism2mgmt_prism2int2p80211int(wordbuf, uint32);
480                  */
481         } else {
482                 /* [MSM] Removed, setconfig16 expects host order.
483                  * prism2mgmt_p80211int2prism2int(wordbuf, uint32);
484                  */
485                 *wordbuf = *uint32;
486                 result = hfa384x_drvr_setconfig16(hw, mib->parm1, *wordbuf);
487         }
488
489         return(result);
490 }
491
492 /*----------------------------------------------------------------
493 * prism2mib_flag
494 *
495 * Get/set a flag.
496 *
497 * MIB record parameters:
498 *       parm1    Prism2 RID value.
499 *       parm2    Bit to get/set.
500 *       parm3    Not used.
501 *
502 * Arguments:
503 *       mib      MIB record.
504 *       isget    MIBGET/MIBSET flag.
505 *       wlandev  wlan device structure.
506 *       priv     "priv" structure.
507 *       hw       "hw" structure.
508 *       msg      Message structure.
509 *       data     Data buffer.
510 *
511 * Returns:
512 *       0   - Success.
513 *       ~0  - Error.
514 *
515 ----------------------------------------------------------------*/
516
517 static int prism2mib_flag(
518 mibrec_t                     *mib,
519 int                          isget,
520 wlandevice_t                 *wlandev,
521 hfa384x_t                    *hw,
522 p80211msg_dot11req_mibset_t  *msg,
523 void                         *data)
524 {
525         int     result;
526         u32  *uint32 = (u32*) data;
527         u8   bytebuf[MIB_TMP_MAXLEN];
528         u16  *wordbuf = (u16*) bytebuf;
529         u32  flags;
530
531         result = hfa384x_drvr_getconfig16(hw, mib->parm1, wordbuf);
532         if (result == 0) {
533                 /* [MSM] Removed, getconfig16 returns the value in host order.
534                  * prism2mgmt_prism2int2p80211int(wordbuf, &flags);
535                  */
536                 flags = *wordbuf;
537                 if (isget) {
538                         *uint32 = (flags & mib->parm2) ?
539                                 P80211ENUM_truth_true : P80211ENUM_truth_false;
540                 } else {
541                         if ((*uint32) == P80211ENUM_truth_true)
542                                 flags |= mib->parm2;
543                         else
544                                 flags &= ~mib->parm2;
545                         /* [MSM] Removed, setconfig16 expects host order.
546                          * prism2mgmt_p80211int2prism2int(wordbuf, &flags);
547                          */
548                         *wordbuf = flags;
549                         result = hfa384x_drvr_setconfig16(hw, mib->parm1, *wordbuf);
550                 }
551         }
552
553         return(result);
554 }
555
556 /*----------------------------------------------------------------
557 * prism2mib_wepdefaultkey
558 *
559 * Get/set WEP default keys.
560 *
561 * MIB record parameters:
562 *       parm1    Prism2 RID value.
563 *       parm2    Number of bytes of RID data.
564 *       parm3    Not used.
565 *
566 * Arguments:
567 *       mib      MIB record.
568 *       isget    MIBGET/MIBSET flag.
569 *       wlandev  wlan device structure.
570 *       priv     "priv" structure.
571 *       hw       "hw" structure.
572 *       msg      Message structure.
573 *       data     Data buffer.
574 *
575 * Returns:
576 *       0   - Success.
577 *       ~0  - Error.
578 *
579 ----------------------------------------------------------------*/
580
581 static int prism2mib_wepdefaultkey(
582 mibrec_t                     *mib,
583 int                          isget,
584 wlandevice_t                 *wlandev,
585 hfa384x_t                    *hw,
586 p80211msg_dot11req_mibset_t  *msg,
587 void                         *data)
588 {
589         int            result;
590         p80211pstrd_t  *pstr = (p80211pstrd_t*) data;
591         u8          bytebuf[MIB_TMP_MAXLEN];
592         u16         len;
593
594         if (isget) {
595                 result = 0;    /* Should never happen. */
596         } else {
597                 len = (pstr->len > 5) ? HFA384x_RID_CNFWEP128DEFAULTKEY_LEN :
598                                         HFA384x_RID_CNFWEPDEFAULTKEY_LEN;
599                 memset(bytebuf, 0, len);
600                 prism2mgmt_pstr2bytearea(bytebuf, pstr);
601                 result = hfa384x_drvr_setconfig(hw, mib->parm1, bytebuf, len);
602         }
603
604         return(result);
605 }
606
607 /*----------------------------------------------------------------
608 * prism2mib_privacyinvoked
609 *
610 * Get/set the dot11PrivacyInvoked value.
611 *
612 * MIB record parameters:
613 *       parm1    Prism2 RID value.
614 *       parm2    Bit value for PrivacyInvoked flag.
615 *       parm3    Not used.
616 *
617 * Arguments:
618 *       mib      MIB record.
619 *       isget    MIBGET/MIBSET flag.
620 *       wlandev  wlan device structure.
621 *       priv     "priv" structure.
622 *       hw       "hw" structure.
623 *       msg      Message structure.
624 *       data     Data buffer.
625 *
626 * Returns:
627 *       0   - Success.
628 *       ~0  - Error.
629 *
630 ----------------------------------------------------------------*/
631
632 static int prism2mib_privacyinvoked(
633 mibrec_t                     *mib,
634 int                          isget,
635 wlandevice_t                 *wlandev,
636 hfa384x_t                    *hw,
637 p80211msg_dot11req_mibset_t  *msg,
638 void                         *data)
639 {
640         int     result;
641
642         if (wlandev->hostwep & HOSTWEP_DECRYPT) {
643                 if (wlandev->hostwep & HOSTWEP_DECRYPT)
644                         mib->parm2 |= HFA384x_WEPFLAGS_DISABLE_RXCRYPT;
645                 if (wlandev->hostwep & HOSTWEP_ENCRYPT)
646                         mib->parm2 |= HFA384x_WEPFLAGS_DISABLE_TXCRYPT;
647         }
648
649         result = prism2mib_flag(mib, isget, wlandev, hw, msg, data);
650
651         return(result);
652 }
653
654 /*----------------------------------------------------------------
655 * prism2mib_excludeunencrypted
656 *
657 * Get/set the dot11ExcludeUnencrypted value.
658 *
659 * MIB record parameters:
660 *       parm1    Prism2 RID value.
661 *       parm2    Bit value for ExcludeUnencrypted flag.
662 *       parm3    Not used.
663 *
664 * Arguments:
665 *       mib      MIB record.
666 *       isget    MIBGET/MIBSET flag.
667 *       wlandev  wlan device structure.
668 *       priv     "priv" structure.
669 *       hw       "hw" structure.
670 *       msg      Message structure.
671 *       data     Data buffer.
672 *
673 * Returns:
674 *       0   - Success.
675 *       ~0  - Error.
676 *
677 ----------------------------------------------------------------*/
678
679 static int prism2mib_excludeunencrypted(
680 mibrec_t                     *mib,
681 int                          isget,
682 wlandevice_t                 *wlandev,
683 hfa384x_t                    *hw,
684 p80211msg_dot11req_mibset_t  *msg,
685 void                         *data)
686 {
687         int     result;
688
689         result = prism2mib_flag(mib, isget, wlandev, hw, msg, data);
690
691         return(result);
692 }
693
694 /*----------------------------------------------------------------
695 * prism2mib_fragmentationthreshold
696 *
697 * Get/set the fragmentation threshold.
698 *
699 * MIB record parameters:
700 *       parm1    Prism2 RID value.
701 *       parm2    Not used.
702 *       parm3    Not used.
703 *
704 * Arguments:
705 *       mib      MIB record.
706 *       isget    MIBGET/MIBSET flag.
707 *       wlandev  wlan device structure.
708 *       priv     "priv" structure.
709 *       hw       "hw" structure.
710 *       msg      Message structure.
711 *       data     Data buffer.
712 *
713 * Returns:
714 *       0   - Success.
715 *       ~0  - Error.
716 *
717 ----------------------------------------------------------------*/
718
719 static int prism2mib_fragmentationthreshold(
720 mibrec_t                     *mib,
721 int                          isget,
722 wlandevice_t                 *wlandev,
723 hfa384x_t                    *hw,
724 p80211msg_dot11req_mibset_t  *msg,
725 void                         *data)
726 {
727         int     result;
728         u32  *uint32 = (u32*) data;
729
730         if (!isget)
731                 if ((*uint32) % 2) {
732                         printk(KERN_WARNING "Attempt to set odd number "
733                                           "FragmentationThreshold\n");
734                         msg->resultcode.data = P80211ENUM_resultcode_not_supported;
735                         return(0);
736                 }
737
738         result = prism2mib_uint32(mib, isget, wlandev, hw, msg, data);
739
740         return(result);
741 }
742
743 /*----------------------------------------------------------------
744 * prism2mib_priv
745 *
746 * Get/set values in the "priv" data structure.
747 *
748 * MIB record parameters:
749 *       parm1    Not used.
750 *       parm2    Not used.
751 *       parm3    Not used.
752 *
753 * Arguments:
754 *       mib      MIB record.
755 *       isget    MIBGET/MIBSET flag.
756 *       wlandev  wlan device structure.
757 *       priv     "priv" structure.
758 *       hw       "hw" structure.
759 *       msg      Message structure.
760 *       data     Data buffer.
761 *
762 * Returns:
763 *       0   - Success.
764 *       ~0  - Error.
765 *
766 ----------------------------------------------------------------*/
767
768 static int prism2mib_priv(
769 mibrec_t                     *mib,
770 int                          isget,
771 wlandevice_t                 *wlandev,
772 hfa384x_t                    *hw,
773 p80211msg_dot11req_mibset_t  *msg,
774 void                         *data)
775 {
776         p80211pstrd_t     *pstr = (p80211pstrd_t*) data;
777
778         int  result;
779
780         switch (mib->did) {
781         case DIDmib_lnx_lnxConfigTable_lnxRSNAIE: {
782                 hfa384x_WPAData_t wpa;
783                 if (isget) {
784                         hfa384x_drvr_getconfig( hw, HFA384x_RID_CNFWPADATA,
785                                                 (u8 *) &wpa, sizeof(wpa));
786                         pstr->len = hfa384x2host_16(wpa.datalen);
787                         memcpy(pstr->data, wpa.data, pstr->len);
788                 } else {
789                         wpa.datalen = host2hfa384x_16(pstr->len);
790                         memcpy(wpa.data, pstr->data, pstr->len);
791
792                         result = hfa384x_drvr_setconfig(hw, HFA384x_RID_CNFWPADATA,
793                                 (u8 *) &wpa, sizeof(wpa));
794                 }
795                 break;
796         }
797         default:
798                 printk(KERN_ERR "Unhandled DID 0x%08x\n", mib->did);
799         }
800
801         return(0);
802 }
803
804 /*----------------------------------------------------------------
805 * prism2mgmt_pstr2bytestr
806 *
807 * Convert the pstr data in the WLAN message structure into an hfa384x
808 * byte string format.
809 *
810 * Arguments:
811 *       bytestr         hfa384x byte string data type
812 *       pstr            wlan message data
813 *
814 * Returns:
815 *       Nothing
816 *
817 ----------------------------------------------------------------*/
818
819 void prism2mgmt_pstr2bytestr(hfa384x_bytestr_t *bytestr, p80211pstrd_t *pstr)
820 {
821         bytestr->len = host2hfa384x_16((u16)(pstr->len));
822         memcpy(bytestr->data, pstr->data, pstr->len);
823 }
824
825
826 /*----------------------------------------------------------------
827 * prism2mgmt_pstr2bytearea
828 *
829 * Convert the pstr data in the WLAN message structure into an hfa384x
830 * byte area format.
831 *
832 * Arguments:
833 *       bytearea        hfa384x byte area data type
834 *       pstr            wlan message data
835 *
836 * Returns:
837 *       Nothing
838 *
839 ----------------------------------------------------------------*/
840
841 void prism2mgmt_pstr2bytearea(u8 *bytearea, p80211pstrd_t *pstr)
842 {
843         memcpy(bytearea, pstr->data, pstr->len);
844 }
845
846
847 /*----------------------------------------------------------------
848 * prism2mgmt_bytestr2pstr
849 *
850 * Convert the data in an hfa384x byte string format into a
851 * pstr in the WLAN message.
852 *
853 * Arguments:
854 *       bytestr         hfa384x byte string data type
855 *       msg             wlan message
856 *
857 * Returns:
858 *       Nothing
859 *
860 ----------------------------------------------------------------*/
861
862 void prism2mgmt_bytestr2pstr(hfa384x_bytestr_t *bytestr, p80211pstrd_t *pstr)
863 {
864         pstr->len = (u8)(hfa384x2host_16((u16)(bytestr->len)));
865         memcpy(pstr->data, bytestr->data, pstr->len);
866 }
867
868
869 /*----------------------------------------------------------------
870 * prism2mgmt_bytearea2pstr
871 *
872 * Convert the data in an hfa384x byte area format into a pstr
873 * in the WLAN message.
874 *
875 * Arguments:
876 *       bytearea        hfa384x byte area data type
877 *       msg             wlan message
878 *
879 * Returns:
880 *       Nothing
881 *
882 ----------------------------------------------------------------*/
883
884 void prism2mgmt_bytearea2pstr(u8 *bytearea, p80211pstrd_t *pstr, int len)
885 {
886         pstr->len = (u8)len;
887         memcpy(pstr->data, bytearea, len);
888 }
889
890
891 /*----------------------------------------------------------------
892 * prism2mgmt_prism2int2p80211int
893 *
894 * Convert an hfa384x integer into a wlan integer
895 *
896 * Arguments:
897 *       prism2enum      pointer to hfa384x integer
898 *       wlanenum        pointer to p80211 integer
899 *
900 * Returns:
901 *       Nothing
902 *
903 ----------------------------------------------------------------*/
904
905 void prism2mgmt_prism2int2p80211int(u16 *prism2int, u32 *wlanint)
906 {
907         *wlanint = (u32)hfa384x2host_16(*prism2int);
908 }
909
910
911 /*----------------------------------------------------------------
912 * prism2mgmt_p80211int2prism2int
913 *
914 * Convert a wlan integer into an hfa384x integer
915 *
916 * Arguments:
917 *       prism2enum      pointer to hfa384x integer
918 *       wlanenum        pointer to p80211 integer
919 *
920 * Returns:
921 *       Nothing
922 *
923 ----------------------------------------------------------------*/
924
925 void prism2mgmt_p80211int2prism2int(u16 *prism2int, u32 *wlanint)
926 {
927         *prism2int = host2hfa384x_16((u16)(*wlanint));
928 }
929
930
931 /*----------------------------------------------------------------
932 * prism2mgmt_prism2enum2p80211enum
933 *
934 * Convert the hfa384x enumerated int into a p80211 enumerated int
935 *
936 * Arguments:
937 *       prism2enum      pointer to hfa384x integer
938 *       wlanenum        pointer to p80211 integer
939 *       rid             hfa384x record id
940 *
941 * Returns:
942 *       Nothing
943 *
944 ----------------------------------------------------------------*/
945 void prism2mgmt_prism2enum2p80211enum(u16 *prism2enum, u32 *wlanenum, u16 rid)
946 {
947         /* At the moment, the need for this functionality hasn't
948         presented itself. All the wlan enumerated values are
949         a 1-to-1 match against the Prism2 enumerated values*/
950         return;
951 }
952
953
954 /*----------------------------------------------------------------
955 * prism2mgmt_p80211enum2prism2enum
956 *
957 * Convert the p80211 enumerated int into an hfa384x enumerated int
958 *
959 * Arguments:
960 *       prism2enum      pointer to hfa384x integer
961 *       wlanenum        pointer to p80211 integer
962 *       rid             hfa384x record id
963 *
964 * Returns:
965 *       Nothing
966 *
967 ----------------------------------------------------------------*/
968 void prism2mgmt_p80211enum2prism2enum(u16 *prism2enum, u32 *wlanenum, u16 rid)
969 {
970         /* At the moment, the need for this functionality hasn't
971         presented itself. All the wlan enumerated values are
972         a 1-to-1 match against the Prism2 enumerated values*/
973         return;
974 }
975
976
977
978 /*----------------------------------------------------------------
979 * prism2mgmt_get_oprateset
980 *
981 * Convert the hfa384x bit area into a wlan octet string.
982 *
983 * Arguments:
984 *       rate            Prism2 bit area
985 *       pstr            wlan octet string
986 *
987 * Returns:
988 *       Nothing
989 *
990 ----------------------------------------------------------------*/
991 void prism2mgmt_get_oprateset(u16 *rate, p80211pstrd_t *pstr)
992 {
993         u8      len;
994         u8      *datarate;
995
996         len = 0;
997         datarate = pstr->data;
998
999         /* 1 Mbps */
1000         if ( BIT(0) & (*rate) ) {
1001                 len += (u8)1;
1002                 *datarate = (u8)2;
1003                 datarate++;
1004         }
1005
1006         /* 2 Mbps */
1007         if ( BIT(1) & (*rate) ) {
1008                 len += (u8)1;
1009                 *datarate = (u8)4;
1010                 datarate++;
1011         }
1012
1013         /* 5.5 Mbps */
1014         if ( BIT(2) & (*rate) ) {
1015                 len += (u8)1;
1016                 *datarate = (u8)11;
1017                 datarate++;
1018         }
1019
1020         /* 11 Mbps */
1021         if ( BIT(3) & (*rate) ) {
1022                 len += (u8)1;
1023                 *datarate = (u8)22;
1024                 datarate++;
1025         }
1026
1027         pstr->len = len;
1028
1029         return;
1030 }
1031
1032
1033
1034 /*----------------------------------------------------------------
1035 * prism2mgmt_set_oprateset
1036 *
1037 * Convert the wlan octet string into an hfa384x bit area.
1038 *
1039 * Arguments:
1040 *       rate            Prism2 bit area
1041 *       pstr            wlan octet string
1042 *
1043 * Returns:
1044 *       Nothing
1045 *
1046 ----------------------------------------------------------------*/
1047 void prism2mgmt_set_oprateset(u16 *rate, p80211pstrd_t *pstr)
1048 {
1049         u8      *datarate;
1050         int     i;
1051
1052         *rate = 0;
1053
1054         datarate = pstr->data;
1055
1056         for ( i=0; i < pstr->len; i++, datarate++ ) {
1057                 switch (*datarate) {
1058                 case 2: /* 1 Mbps */
1059                         *rate |= BIT(0);
1060                         break;
1061                 case 4: /* 2 Mbps */
1062                         *rate |= BIT(1);
1063                         break;
1064                 case 11: /* 5.5 Mbps */
1065                         *rate |= BIT(2);
1066                         break;
1067                 case 22: /* 11 Mbps */
1068                         *rate |= BIT(3);
1069                         break;
1070                 default:
1071                         WLAN_LOG_DEBUG(1, "Unrecoginzed Rate of %d\n",
1072                                 *datarate);
1073                         break;
1074                 }
1075         }
1076
1077         return;
1078 }