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