1 /* src/prism2/driver/prism2mib.c
3 * Management request for mibset/mibget
5 * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved.
6 * --------------------------------------------------------------------
10 * The contents of this file are subject to the Mozilla Public
11 * License Version 1.1 (the "License"); you may not use this file
12 * except in compliance with the License. You may obtain a copy of
13 * the License at http://www.mozilla.org/MPL/
15 * Software distributed under the License is distributed on an "AS
16 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
17 * implied. See the License for the specific language governing
18 * rights and limitations under the License.
20 * Alternatively, the contents of this file may be used under the
21 * terms of the GNU Public License version 2 (the "GPL"), in which
22 * case the provisions of the GPL are applicable instead of the
23 * above. If you wish to allow the use of your version of this file
24 * only under the terms of the GPL and not to allow others to use
25 * your version of this file under the MPL, indicate your decision
26 * by deleting the provisions above and replace them with the notice
27 * and other provisions required by the GPL. If you do not delete
28 * the provisions above, a recipient may use your version of this
29 * file under either the MPL or the GPL.
31 * --------------------------------------------------------------------
33 * Inquiries regarding the linux-wlan Open Source project can be
36 * AbsoluteValue Systems Inc.
38 * http://www.linux-wlan.com
40 * --------------------------------------------------------------------
42 * Portions of the development of this software were funded by
43 * Intersil Corporation as part of PRISM(R) chipset product development.
45 * --------------------------------------------------------------------
47 * The functions in this file handle the mibset/mibget management
50 * --------------------------------------------------------------------
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>
62 #include <linux/delay.h>
63 #include <asm/byteorder.h>
64 #include <linux/usb.h>
65 #include <linux/bitops.h>
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"
76 #include "prism2mgmt.h"
78 #define MIB_TMP_MAXLEN 200 /* Max length of RID record (in bytes). */
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. */
84 typedef struct mibrec {
90 int (*func) (struct mibrec *mib,
92 wlandevice_t *wlandev,
94 p80211msg_dot11req_mibset_t *msg, void *data);
97 static int prism2mib_bytearea2pstr(mibrec_t *mib,
99 wlandevice_t *wlandev,
101 p80211msg_dot11req_mibset_t *msg,
104 static int prism2mib_uint32(mibrec_t *mib,
106 wlandevice_t *wlandev,
108 p80211msg_dot11req_mibset_t *msg, void *data);
110 static int prism2mib_flag(mibrec_t *mib,
112 wlandevice_t *wlandev,
114 p80211msg_dot11req_mibset_t *msg, void *data);
116 static int prism2mib_wepdefaultkey(mibrec_t *mib,
118 wlandevice_t *wlandev,
120 p80211msg_dot11req_mibset_t *msg,
123 static int prism2mib_privacyinvoked(mibrec_t *mib,
125 wlandevice_t *wlandev,
127 p80211msg_dot11req_mibset_t *msg,
130 static int prism2mib_excludeunencrypted(mibrec_t *mib,
132 wlandevice_t *wlandev,
134 p80211msg_dot11req_mibset_t *msg,
137 static int prism2mib_fragmentationthreshold(mibrec_t *mib,
139 wlandevice_t *wlandev,
141 p80211msg_dot11req_mibset_t *msg,
144 static int prism2mib_priv(mibrec_t *mib,
146 wlandevice_t *wlandev,
148 p80211msg_dot11req_mibset_t *msg, void *data);
150 static mibrec_t mibtab[] = {
153 {DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey0,
155 HFA384x_RID_CNFWEPDEFAULTKEY0, 0, 0,
156 prism2mib_wepdefaultkey},
157 {DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey1,
159 HFA384x_RID_CNFWEPDEFAULTKEY1, 0, 0,
160 prism2mib_wepdefaultkey},
161 {DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey2,
163 HFA384x_RID_CNFWEPDEFAULTKEY2, 0, 0,
164 prism2mib_wepdefaultkey},
165 {DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey3,
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,
177 {DIDmib_dot11smt_dot11PrivacyTable_dot11ExcludeUnencrypted,
178 F_STA | F_READ | F_WRITE,
179 HFA384x_RID_CNFWEPFLAGS, HFA384x_WEPFLAGS_EXCLUDE, 0,
180 prism2mib_excludeunencrypted},
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,
192 {DIDmib_dot11mac_dot11OperationTable_dot11ShortRetryLimit,
194 HFA384x_RID_SHORTRETRYLIMIT, 0, 0,
196 {DIDmib_dot11mac_dot11OperationTable_dot11LongRetryLimit,
198 HFA384x_RID_LONGRETRYLIMIT, 0, 0,
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,
206 HFA384x_RID_MAXTXLIFETIME, 0, 0,
211 {DIDmib_dot11phy_dot11PhyDSSSTable_dot11CurrentChannel,
213 HFA384x_RID_CURRENTCHANNEL, 0, 0,
215 {DIDmib_dot11phy_dot11PhyTxPowerTable_dot11CurrentTxPowerLevel,
216 F_STA | F_READ | F_WRITE,
217 HFA384x_RID_TXPOWERMAX, 0, 0,
222 {DIDmib_p2_p2Static_p2CnfPortType,
223 F_STA | F_READ | F_WRITE,
224 HFA384x_RID_CNFPORTTYPE, 0, 0,
229 {DIDmib_p2_p2MAC_p2CurrentTxRate,
231 HFA384x_RID_CURRENTTXRATE, 0, 0,
234 /* And finally, lnx mibs */
235 {DIDmib_lnx_lnxConfigTable_lnxRSNAIE,
236 F_STA | F_READ | F_WRITE,
237 HFA384x_RID_CNFWPADATA, 0, 0,
239 {0, 0, 0, 0, 0, NULL}
242 /*----------------------------------------------------------------
243 * prism2mgmt_mibset_mibget
245 * Set the value of a mib item.
248 * wlandev wlan device structure
249 * msgp ptr to msg buffer
253 * <0 success, but we're waiting for something to finish.
254 * >0 an error occurred while handling the message.
258 * process thread (usually)
260 ----------------------------------------------------------------*/
262 int prism2mgmt_mibset_mibget(wlandevice_t *wlandev, void *msgp)
264 hfa384x_t *hw = wlandev->priv;
270 p80211msg_dot11req_mibset_t *msg = msgp;
271 p80211itemd_t *mibitem;
273 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
274 msg->resultcode.data = P80211ENUM_resultcode_success;
277 ** Determine if this is an Access Point or a station.
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
289 mibitem = (p80211itemd_t *) msg->mibattribute.data;
291 for (mib = mibtab; mib->did != 0; mib++)
292 if (mib->did == mibitem->did && (mib->flag & which))
296 msg->resultcode.data = P80211ENUM_resultcode_not_supported;
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.
306 isget = (msg->msgcode == DIDmsg_dot11req_mibget);
309 if (!(mib->flag & F_READ)) {
310 msg->resultcode.data =
311 P80211ENUM_resultcode_cant_get_writeonly_mib;
315 if (!(mib->flag & F_WRITE)) {
316 msg->resultcode.data =
317 P80211ENUM_resultcode_cant_set_readonly_mib;
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".
330 result = mib->func(mib, isget, wlandev, hw, msg, (void *)mibitem->data);
332 if (msg->resultcode.data == P80211ENUM_resultcode_success) {
334 pr_debug("get/set failure, result=%d\n",
336 msg->resultcode.data =
337 P80211ENUM_resultcode_implementation_failure;
340 msg->mibattribute.status =
341 P80211ENUM_msgitem_status_data_ok;
343 P80211ENUM_msgitem_status_data_ok;
352 /*----------------------------------------------------------------
353 * prism2mib_bytearea2pstr
355 * Get/set pstr data to/from a byte area.
357 * MIB record parameters:
358 * parm1 Prism2 RID value.
359 * parm2 Number of bytes of RID data.
364 * isget MIBGET/MIBSET flag.
365 * wlandev wlan device structure.
366 * priv "priv" structure.
368 * msg Message structure.
375 ----------------------------------------------------------------*/
377 static int prism2mib_bytearea2pstr(mibrec_t *mib,
379 wlandevice_t *wlandev,
381 p80211msg_dot11req_mibset_t *msg,
385 p80211pstrd_t *pstr = (p80211pstrd_t *) data;
386 u8 bytebuf[MIB_TMP_MAXLEN];
390 hfa384x_drvr_getconfig(hw, mib->parm1, bytebuf, mib->parm2);
391 prism2mgmt_bytearea2pstr(bytebuf, pstr, mib->parm2);
393 memset(bytebuf, 0, mib->parm2);
394 prism2mgmt_pstr2bytearea(bytebuf, pstr);
396 hfa384x_drvr_setconfig(hw, mib->parm1, bytebuf, mib->parm2);
402 /*----------------------------------------------------------------
405 * Get/set uint32 data.
407 * MIB record parameters:
408 * parm1 Prism2 RID value.
414 * isget MIBGET/MIBSET flag.
415 * wlandev wlan device structure.
416 * priv "priv" structure.
418 * msg Message structure.
425 ----------------------------------------------------------------*/
427 static int prism2mib_uint32(mibrec_t *mib,
429 wlandevice_t *wlandev,
431 p80211msg_dot11req_mibset_t *msg, void *data)
434 u32 *uint32 = (u32 *) data;
435 u8 bytebuf[MIB_TMP_MAXLEN];
436 u16 *wordbuf = (u16 *) bytebuf;
439 result = hfa384x_drvr_getconfig16(hw, mib->parm1, wordbuf);
443 result = hfa384x_drvr_setconfig16(hw, mib->parm1, *wordbuf);
449 /*----------------------------------------------------------------
454 * MIB record parameters:
455 * parm1 Prism2 RID value.
456 * parm2 Bit to get/set.
461 * isget MIBGET/MIBSET flag.
462 * wlandev wlan device structure.
463 * priv "priv" structure.
465 * msg Message structure.
472 ----------------------------------------------------------------*/
474 static int prism2mib_flag(mibrec_t *mib,
476 wlandevice_t *wlandev,
478 p80211msg_dot11req_mibset_t *msg, void *data)
481 u32 *uint32 = (u32 *) data;
482 u8 bytebuf[MIB_TMP_MAXLEN];
483 u16 *wordbuf = (u16 *) bytebuf;
486 result = hfa384x_drvr_getconfig16(hw, mib->parm1, wordbuf);
490 *uint32 = (flags & mib->parm2) ?
491 P80211ENUM_truth_true : P80211ENUM_truth_false;
493 if ((*uint32) == P80211ENUM_truth_true)
496 flags &= ~mib->parm2;
499 hfa384x_drvr_setconfig16(hw, mib->parm1, *wordbuf);
506 /*----------------------------------------------------------------
507 * prism2mib_wepdefaultkey
509 * Get/set WEP default keys.
511 * MIB record parameters:
512 * parm1 Prism2 RID value.
513 * parm2 Number of bytes of RID data.
518 * isget MIBGET/MIBSET flag.
519 * wlandev wlan device structure.
520 * priv "priv" structure.
522 * msg Message structure.
529 ----------------------------------------------------------------*/
531 static int prism2mib_wepdefaultkey(mibrec_t *mib,
533 wlandevice_t *wlandev,
535 p80211msg_dot11req_mibset_t *msg,
539 p80211pstrd_t *pstr = (p80211pstrd_t *) data;
540 u8 bytebuf[MIB_TMP_MAXLEN];
544 result = 0; /* Should never happen. */
546 len = (pstr->len > 5) ? HFA384x_RID_CNFWEP128DEFAULTKEY_LEN :
547 HFA384x_RID_CNFWEPDEFAULTKEY_LEN;
548 memset(bytebuf, 0, len);
549 prism2mgmt_pstr2bytearea(bytebuf, pstr);
550 result = hfa384x_drvr_setconfig(hw, mib->parm1, bytebuf, len);
556 /*----------------------------------------------------------------
557 * prism2mib_privacyinvoked
559 * Get/set the dot11PrivacyInvoked value.
561 * MIB record parameters:
562 * parm1 Prism2 RID value.
563 * parm2 Bit value for PrivacyInvoked flag.
568 * isget MIBGET/MIBSET flag.
569 * wlandev wlan device structure.
570 * priv "priv" structure.
572 * msg Message structure.
579 ----------------------------------------------------------------*/
581 static int prism2mib_privacyinvoked(mibrec_t *mib,
583 wlandevice_t *wlandev,
585 p80211msg_dot11req_mibset_t *msg,
590 if (wlandev->hostwep & HOSTWEP_DECRYPT) {
591 if (wlandev->hostwep & HOSTWEP_DECRYPT)
592 mib->parm2 |= HFA384x_WEPFLAGS_DISABLE_RXCRYPT;
593 if (wlandev->hostwep & HOSTWEP_ENCRYPT)
594 mib->parm2 |= HFA384x_WEPFLAGS_DISABLE_TXCRYPT;
597 result = prism2mib_flag(mib, isget, wlandev, hw, msg, data);
602 /*----------------------------------------------------------------
603 * prism2mib_excludeunencrypted
605 * Get/set the dot11ExcludeUnencrypted value.
607 * MIB record parameters:
608 * parm1 Prism2 RID value.
609 * parm2 Bit value for ExcludeUnencrypted flag.
614 * isget MIBGET/MIBSET flag.
615 * wlandev wlan device structure.
616 * priv "priv" structure.
618 * msg Message structure.
625 ----------------------------------------------------------------*/
627 static int prism2mib_excludeunencrypted(mibrec_t *mib,
629 wlandevice_t *wlandev,
631 p80211msg_dot11req_mibset_t *msg,
636 result = prism2mib_flag(mib, isget, wlandev, hw, msg, data);
641 /*----------------------------------------------------------------
642 * prism2mib_fragmentationthreshold
644 * Get/set the fragmentation threshold.
646 * MIB record parameters:
647 * parm1 Prism2 RID value.
653 * isget MIBGET/MIBSET flag.
654 * wlandev wlan device structure.
655 * priv "priv" structure.
657 * msg Message structure.
664 ----------------------------------------------------------------*/
666 static int prism2mib_fragmentationthreshold(mibrec_t *mib,
668 wlandevice_t *wlandev,
670 p80211msg_dot11req_mibset_t *msg,
674 u32 *uint32 = (u32 *) data;
678 printk(KERN_WARNING "Attempt to set odd number "
679 "FragmentationThreshold\n");
680 msg->resultcode.data =
681 P80211ENUM_resultcode_not_supported;
685 result = prism2mib_uint32(mib, isget, wlandev, hw, msg, data);
690 /*----------------------------------------------------------------
693 * Get/set values in the "priv" data structure.
695 * MIB record parameters:
702 * isget MIBGET/MIBSET flag.
703 * wlandev wlan device structure.
704 * priv "priv" structure.
706 * msg Message structure.
713 ----------------------------------------------------------------*/
715 static int prism2mib_priv(mibrec_t *mib,
717 wlandevice_t *wlandev,
719 p80211msg_dot11req_mibset_t *msg, void *data)
721 p80211pstrd_t *pstr = (p80211pstrd_t *) data;
726 case DIDmib_lnx_lnxConfigTable_lnxRSNAIE:{
727 hfa384x_WPAData_t wpa;
729 hfa384x_drvr_getconfig(hw,
730 HFA384x_RID_CNFWPADATA,
733 pstr->len = le16_to_cpu(wpa.datalen);
734 memcpy(pstr->data, wpa.data, pstr->len);
736 wpa.datalen = cpu_to_le16(pstr->len);
737 memcpy(wpa.data, pstr->data, pstr->len);
740 hfa384x_drvr_setconfig(hw,
741 HFA384x_RID_CNFWPADATA,
748 printk(KERN_ERR "Unhandled DID 0x%08x\n", mib->did);
754 /*----------------------------------------------------------------
755 * prism2mgmt_pstr2bytestr
757 * Convert the pstr data in the WLAN message structure into an hfa384x
758 * byte string format.
761 * bytestr hfa384x byte string data type
762 * pstr wlan message data
767 ----------------------------------------------------------------*/
769 void prism2mgmt_pstr2bytestr(hfa384x_bytestr_t *bytestr, p80211pstrd_t *pstr)
771 bytestr->len = cpu_to_le16((u16) (pstr->len));
772 memcpy(bytestr->data, pstr->data, pstr->len);
775 /*----------------------------------------------------------------
776 * prism2mgmt_pstr2bytearea
778 * Convert the pstr data in the WLAN message structure into an hfa384x
782 * bytearea hfa384x byte area data type
783 * pstr wlan message data
788 ----------------------------------------------------------------*/
790 void prism2mgmt_pstr2bytearea(u8 *bytearea, p80211pstrd_t *pstr)
792 memcpy(bytearea, pstr->data, pstr->len);
795 /*----------------------------------------------------------------
796 * prism2mgmt_bytestr2pstr
798 * Convert the data in an hfa384x byte string format into a
799 * pstr in the WLAN message.
802 * bytestr hfa384x byte string data type
808 ----------------------------------------------------------------*/
810 void prism2mgmt_bytestr2pstr(hfa384x_bytestr_t *bytestr, p80211pstrd_t *pstr)
812 pstr->len = (u8) (le16_to_cpu((u16) (bytestr->len)));
813 memcpy(pstr->data, bytestr->data, pstr->len);
816 /*----------------------------------------------------------------
817 * prism2mgmt_bytearea2pstr
819 * Convert the data in an hfa384x byte area format into a pstr
820 * in the WLAN message.
823 * bytearea hfa384x byte area data type
829 ----------------------------------------------------------------*/
831 void prism2mgmt_bytearea2pstr(u8 *bytearea, p80211pstrd_t *pstr, int len)
833 pstr->len = (u8) len;
834 memcpy(pstr->data, bytearea, len);