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/module.h>
54 #include <linux/kernel.h>
55 #include <linux/sched.h>
56 #include <linux/types.h>
57 #include <linux/wireless.h>
58 #include <linux/netdevice.h>
60 #include <linux/delay.h>
61 #include <asm/byteorder.h>
62 #include <linux/usb.h>
63 #include <linux/bitops.h>
65 #include "p80211types.h"
66 #include "p80211hdr.h"
67 #include "p80211mgmt.h"
68 #include "p80211conv.h"
69 #include "p80211msg.h"
70 #include "p80211netdev.h"
71 #include "p80211metadef.h"
72 #include "p80211metastruct.h"
74 #include "prism2mgmt.h"
76 #define MIB_TMP_MAXLEN 200 /* Max length of RID record (in bytes). */
78 #define F_STA 0x1 /* MIB is supported on stations. */
79 #define F_READ 0x2 /* MIB may be read. */
80 #define F_WRITE 0x4 /* MIB may be written. */
88 int (*func
)(struct mibrec
*mib
,
90 struct wlandevice
*wlandev
,
92 struct p80211msg_dot11req_mibset
*msg
, void *data
);
95 static int prism2mib_bytearea2pstr(struct mibrec
*mib
,
97 struct wlandevice
*wlandev
,
99 struct p80211msg_dot11req_mibset
*msg
,
102 static int prism2mib_uint32(struct mibrec
*mib
,
104 struct wlandevice
*wlandev
,
106 struct p80211msg_dot11req_mibset
*msg
, void *data
);
108 static int prism2mib_flag(struct mibrec
*mib
,
110 struct wlandevice
*wlandev
,
112 struct p80211msg_dot11req_mibset
*msg
, void *data
);
114 static int prism2mib_wepdefaultkey(struct mibrec
*mib
,
116 struct wlandevice
*wlandev
,
118 struct p80211msg_dot11req_mibset
*msg
,
121 static int prism2mib_privacyinvoked(struct mibrec
*mib
,
123 struct wlandevice
*wlandev
,
125 struct p80211msg_dot11req_mibset
*msg
,
128 static int prism2mib_excludeunencrypted(struct mibrec
*mib
,
130 struct wlandevice
*wlandev
,
132 struct p80211msg_dot11req_mibset
*msg
,
135 static int prism2mib_fragmentationthreshold(struct mibrec
*mib
,
137 struct wlandevice
*wlandev
,
139 struct p80211msg_dot11req_mibset
*msg
,
142 static int prism2mib_priv(struct mibrec
*mib
,
144 struct wlandevice
*wlandev
,
146 struct p80211msg_dot11req_mibset
*msg
, void *data
);
148 static struct mibrec mibtab
[] = {
150 {DIDmib_dot11smt_dot11WEPDefaultKeysTable_key(1),
152 HFA384x_RID_CNFWEPDEFAULTKEY0
, 0, 0,
153 prism2mib_wepdefaultkey
},
154 {DIDmib_dot11smt_dot11WEPDefaultKeysTable_key(2),
156 HFA384x_RID_CNFWEPDEFAULTKEY1
, 0, 0,
157 prism2mib_wepdefaultkey
},
158 {DIDmib_dot11smt_dot11WEPDefaultKeysTable_key(3),
160 HFA384x_RID_CNFWEPDEFAULTKEY2
, 0, 0,
161 prism2mib_wepdefaultkey
},
162 {DIDmib_dot11smt_dot11WEPDefaultKeysTable_key(4),
164 HFA384x_RID_CNFWEPDEFAULTKEY3
, 0, 0,
165 prism2mib_wepdefaultkey
},
166 {DIDmib_dot11smt_dot11PrivacyTable_dot11PrivacyInvoked
,
167 F_STA
| F_READ
| F_WRITE
,
168 HFA384x_RID_CNFWEPFLAGS
, HFA384x_WEPFLAGS_PRIVINVOKED
, 0,
169 prism2mib_privacyinvoked
},
170 {DIDmib_dot11smt_dot11PrivacyTable_dot11WEPDefaultKeyID
,
171 F_STA
| F_READ
| F_WRITE
,
172 HFA384x_RID_CNFWEPDEFAULTKEYID
, 0, 0,
174 {DIDmib_dot11smt_dot11PrivacyTable_dot11ExcludeUnencrypted
,
175 F_STA
| F_READ
| F_WRITE
,
176 HFA384x_RID_CNFWEPFLAGS
, HFA384x_WEPFLAGS_EXCLUDE
, 0,
177 prism2mib_excludeunencrypted
},
181 {DIDmib_dot11mac_dot11OperationTable_dot11MACAddress
,
182 F_STA
| F_READ
| F_WRITE
,
183 HFA384x_RID_CNFOWNMACADDR
, HFA384x_RID_CNFOWNMACADDR_LEN
, 0,
184 prism2mib_bytearea2pstr
},
185 {DIDmib_dot11mac_dot11OperationTable_dot11RTSThreshold
,
186 F_STA
| F_READ
| F_WRITE
,
187 HFA384x_RID_RTSTHRESH
, 0, 0,
189 {DIDmib_dot11mac_dot11OperationTable_dot11ShortRetryLimit
,
191 HFA384x_RID_SHORTRETRYLIMIT
, 0, 0,
193 {DIDmib_dot11mac_dot11OperationTable_dot11LongRetryLimit
,
195 HFA384x_RID_LONGRETRYLIMIT
, 0, 0,
197 {DIDmib_dot11mac_dot11OperationTable_dot11FragmentationThreshold
,
198 F_STA
| F_READ
| F_WRITE
,
199 HFA384x_RID_FRAGTHRESH
, 0, 0,
200 prism2mib_fragmentationthreshold
},
201 {DIDmib_dot11mac_dot11OperationTable_dot11MaxTransmitMSDULifetime
,
203 HFA384x_RID_MAXTXLIFETIME
, 0, 0,
208 {DIDmib_dot11phy_dot11PhyDSSSTable_dot11CurrentChannel
,
210 HFA384x_RID_CURRENTCHANNEL
, 0, 0,
212 {DIDmib_dot11phy_dot11PhyTxPowerTable_dot11CurrentTxPowerLevel
,
213 F_STA
| F_READ
| F_WRITE
,
214 HFA384x_RID_TXPOWERMAX
, 0, 0,
219 {DIDmib_p2_p2Static_p2CnfPortType
,
220 F_STA
| F_READ
| F_WRITE
,
221 HFA384x_RID_CNFPORTTYPE
, 0, 0,
226 {DIDmib_p2_p2MAC_p2CurrentTxRate
,
228 HFA384x_RID_CURRENTTXRATE
, 0, 0,
231 /* And finally, lnx mibs */
232 {DIDmib_lnx_lnxConfigTable_lnxRSNAIE
,
233 F_STA
| F_READ
| F_WRITE
,
234 HFA384x_RID_CNFWPADATA
, 0, 0,
236 {0, 0, 0, 0, 0, NULL
}
240 * prism2mgmt_mibset_mibget
242 * Set the value of a mib item.
245 * wlandev wlan device structure
246 * msgp ptr to msg buffer
250 * <0 success, but we're waiting for something to finish.
251 * >0 an error occurred while handling the message.
255 * process thread (usually)
259 int prism2mgmt_mibset_mibget(struct wlandevice
*wlandev
, void *msgp
)
261 struct hfa384x
*hw
= wlandev
->priv
;
267 struct p80211msg_dot11req_mibset
*msg
= msgp
;
268 struct p80211itemd
*mibitem
;
270 msg
->resultcode
.status
= P80211ENUM_msgitem_status_data_ok
;
271 msg
->resultcode
.data
= P80211ENUM_resultcode_success
;
274 ** Determine if this is an Access Point or a station.
280 ** Find the MIB in the MIB table. Note that a MIB may be in the
281 ** table twice...once for an AP and once for a station. Make sure
282 ** to get the correct one. Note that DID=0 marks the end of the
286 mibitem
= (struct p80211itemd
*)msg
->mibattribute
.data
;
288 for (mib
= mibtab
; mib
->did
!= 0; mib
++)
289 if (mib
->did
== mibitem
->did
&& (mib
->flag
& which
))
293 msg
->resultcode
.data
= P80211ENUM_resultcode_not_supported
;
298 ** Determine if this is a "mibget" or a "mibset". If this is a
299 ** "mibget", then make sure that the MIB may be read. Otherwise,
300 ** this is a "mibset" so make make sure that the MIB may be written.
303 isget
= (msg
->msgcode
== DIDmsg_dot11req_mibget
);
306 if (!(mib
->flag
& F_READ
)) {
307 msg
->resultcode
.data
=
308 P80211ENUM_resultcode_cant_get_writeonly_mib
;
312 if (!(mib
->flag
& F_WRITE
)) {
313 msg
->resultcode
.data
=
314 P80211ENUM_resultcode_cant_set_readonly_mib
;
320 ** Execute the MIB function. If things worked okay, then make
321 ** sure that the MIB function also worked okay. If so, and this
322 ** is a "mibget", then the status value must be set for both the
323 ** "mibattribute" parameter and the mib item within the data
324 ** portion of the "mibattribute".
327 result
= mib
->func(mib
, isget
, wlandev
, hw
, msg
, (void *)mibitem
->data
);
329 if (msg
->resultcode
.data
== P80211ENUM_resultcode_success
) {
331 pr_debug("get/set failure, result=%d\n", result
);
332 msg
->resultcode
.data
=
333 P80211ENUM_resultcode_implementation_failure
;
336 msg
->mibattribute
.status
=
337 P80211ENUM_msgitem_status_data_ok
;
339 P80211ENUM_msgitem_status_data_ok
;
349 * prism2mib_bytearea2pstr
351 * Get/set pstr data to/from a byte area.
353 * MIB record parameters:
354 * parm1 Prism2 RID value.
355 * parm2 Number of bytes of RID data.
360 * isget MIBGET/MIBSET flag.
361 * wlandev wlan device structure.
362 * priv "priv" structure.
364 * msg Message structure.
373 static int prism2mib_bytearea2pstr(struct mibrec
*mib
,
375 struct wlandevice
*wlandev
,
377 struct p80211msg_dot11req_mibset
*msg
,
381 struct p80211pstrd
*pstr
= data
;
382 u8 bytebuf
[MIB_TMP_MAXLEN
];
386 hfa384x_drvr_getconfig(hw
, mib
->parm1
, bytebuf
, mib
->parm2
);
387 prism2mgmt_bytearea2pstr(bytebuf
, pstr
, mib
->parm2
);
389 memset(bytebuf
, 0, mib
->parm2
);
390 memcpy(bytebuf
, pstr
->data
, pstr
->len
);
392 hfa384x_drvr_setconfig(hw
, mib
->parm1
, bytebuf
, mib
->parm2
);
401 * Get/set uint32 data.
403 * MIB record parameters:
404 * parm1 Prism2 RID value.
410 * isget MIBGET/MIBSET flag.
411 * wlandev wlan device structure.
412 * priv "priv" structure.
414 * msg Message structure.
423 static int prism2mib_uint32(struct mibrec
*mib
,
425 struct wlandevice
*wlandev
,
427 struct p80211msg_dot11req_mibset
*msg
, void *data
)
431 u8 bytebuf
[MIB_TMP_MAXLEN
];
432 u16
*wordbuf
= (u16
*)bytebuf
;
435 result
= hfa384x_drvr_getconfig16(hw
, mib
->parm1
, wordbuf
);
439 result
= hfa384x_drvr_setconfig16(hw
, mib
->parm1
, *wordbuf
);
450 * MIB record parameters:
451 * parm1 Prism2 RID value.
452 * parm2 Bit to get/set.
457 * isget MIBGET/MIBSET flag.
458 * wlandev wlan device structure.
459 * priv "priv" structure.
461 * msg Message structure.
470 static int prism2mib_flag(struct mibrec
*mib
,
472 struct wlandevice
*wlandev
,
474 struct p80211msg_dot11req_mibset
*msg
, void *data
)
478 u8 bytebuf
[MIB_TMP_MAXLEN
];
479 u16
*wordbuf
= (u16
*)bytebuf
;
482 result
= hfa384x_drvr_getconfig16(hw
, mib
->parm1
, wordbuf
);
486 *uint32
= (flags
& mib
->parm2
) ?
487 P80211ENUM_truth_true
: P80211ENUM_truth_false
;
489 if ((*uint32
) == P80211ENUM_truth_true
)
492 flags
&= ~mib
->parm2
;
495 hfa384x_drvr_setconfig16(hw
, mib
->parm1
, *wordbuf
);
503 * prism2mib_wepdefaultkey
505 * Get/set WEP default keys.
507 * MIB record parameters:
508 * parm1 Prism2 RID value.
509 * parm2 Number of bytes of RID data.
514 * isget MIBGET/MIBSET flag.
515 * wlandev wlan device structure.
516 * priv "priv" structure.
518 * msg Message structure.
527 static int prism2mib_wepdefaultkey(struct mibrec
*mib
,
529 struct wlandevice
*wlandev
,
531 struct p80211msg_dot11req_mibset
*msg
,
535 struct p80211pstrd
*pstr
= data
;
536 u8 bytebuf
[MIB_TMP_MAXLEN
];
540 result
= 0; /* Should never happen. */
542 len
= (pstr
->len
> 5) ? HFA384x_RID_CNFWEP128DEFAULTKEY_LEN
:
543 HFA384x_RID_CNFWEPDEFAULTKEY_LEN
;
544 memset(bytebuf
, 0, len
);
545 memcpy(bytebuf
, pstr
->data
, pstr
->len
);
546 result
= hfa384x_drvr_setconfig(hw
, mib
->parm1
, bytebuf
, len
);
553 * prism2mib_privacyinvoked
555 * Get/set the dot11PrivacyInvoked value.
557 * MIB record parameters:
558 * parm1 Prism2 RID value.
559 * parm2 Bit value for PrivacyInvoked flag.
564 * isget MIBGET/MIBSET flag.
565 * wlandev wlan device structure.
566 * priv "priv" structure.
568 * msg Message structure.
577 static int prism2mib_privacyinvoked(struct mibrec
*mib
,
579 struct wlandevice
*wlandev
,
581 struct p80211msg_dot11req_mibset
*msg
,
584 if (wlandev
->hostwep
& HOSTWEP_DECRYPT
) {
585 if (wlandev
->hostwep
& HOSTWEP_DECRYPT
)
586 mib
->parm2
|= HFA384x_WEPFLAGS_DISABLE_RXCRYPT
;
587 if (wlandev
->hostwep
& HOSTWEP_ENCRYPT
)
588 mib
->parm2
|= HFA384x_WEPFLAGS_DISABLE_TXCRYPT
;
591 return prism2mib_flag(mib
, isget
, wlandev
, hw
, msg
, data
);
595 * prism2mib_excludeunencrypted
597 * Get/set the dot11ExcludeUnencrypted value.
599 * MIB record parameters:
600 * parm1 Prism2 RID value.
601 * parm2 Bit value for ExcludeUnencrypted flag.
606 * isget MIBGET/MIBSET flag.
607 * wlandev wlan device structure.
608 * priv "priv" structure.
610 * msg Message structure.
619 static int prism2mib_excludeunencrypted(struct mibrec
*mib
,
621 struct wlandevice
*wlandev
,
623 struct p80211msg_dot11req_mibset
*msg
,
626 return prism2mib_flag(mib
, isget
, wlandev
, hw
, msg
, data
);
630 * prism2mib_fragmentationthreshold
632 * Get/set the fragmentation threshold.
634 * MIB record parameters:
635 * parm1 Prism2 RID value.
641 * isget MIBGET/MIBSET flag.
642 * wlandev wlan device structure.
643 * priv "priv" structure.
645 * msg Message structure.
654 static int prism2mib_fragmentationthreshold(struct mibrec
*mib
,
656 struct wlandevice
*wlandev
,
658 struct p80211msg_dot11req_mibset
*msg
,
665 netdev_warn(wlandev
->netdev
,
666 "Attempt to set odd number FragmentationThreshold\n");
667 msg
->resultcode
.data
=
668 P80211ENUM_resultcode_not_supported
;
672 return prism2mib_uint32(mib
, isget
, wlandev
, hw
, msg
, data
);
678 * Get/set values in the "priv" data structure.
680 * MIB record parameters:
687 * isget MIBGET/MIBSET flag.
688 * wlandev wlan device structure.
689 * priv "priv" structure.
691 * msg Message structure.
700 static int prism2mib_priv(struct mibrec
*mib
,
702 struct wlandevice
*wlandev
,
704 struct p80211msg_dot11req_mibset
*msg
, void *data
)
706 struct p80211pstrd
*pstr
= data
;
709 case DIDmib_lnx_lnxConfigTable_lnxRSNAIE
:{
710 struct hfa384x_wpa_data wpa
;
713 hfa384x_drvr_getconfig(hw
,
714 HFA384x_RID_CNFWPADATA
,
717 pstr
->len
= le16_to_cpu(wpa
.datalen
);
718 memcpy(pstr
->data
, wpa
.data
, pstr
->len
);
720 wpa
.datalen
= cpu_to_le16(pstr
->len
);
721 memcpy(wpa
.data
, pstr
->data
, pstr
->len
);
723 hfa384x_drvr_setconfig(hw
,
724 HFA384x_RID_CNFWPADATA
,
731 netdev_err(wlandev
->netdev
, "Unhandled DID 0x%08x\n", mib
->did
);
738 * prism2mgmt_pstr2bytestr
740 * Convert the pstr data in the WLAN message structure into an hfa384x
741 * byte string format.
744 * bytestr hfa384x byte string data type
745 * pstr wlan message data
752 void prism2mgmt_pstr2bytestr(struct hfa384x_bytestr
*bytestr
,
753 struct p80211pstrd
*pstr
)
755 bytestr
->len
= cpu_to_le16((u16
)(pstr
->len
));
756 memcpy(bytestr
->data
, pstr
->data
, pstr
->len
);
760 * prism2mgmt_bytestr2pstr
762 * Convert the data in an hfa384x byte string format into a
763 * pstr in the WLAN message.
766 * bytestr hfa384x byte string data type
774 void prism2mgmt_bytestr2pstr(struct hfa384x_bytestr
*bytestr
,
775 struct p80211pstrd
*pstr
)
777 pstr
->len
= (u8
)(le16_to_cpu(bytestr
->len
));
778 memcpy(pstr
->data
, bytestr
->data
, pstr
->len
);
782 * prism2mgmt_bytearea2pstr
784 * Convert the data in an hfa384x byte area format into a pstr
785 * in the WLAN message.
788 * bytearea hfa384x byte area data type
796 void prism2mgmt_bytearea2pstr(u8
*bytearea
, struct p80211pstrd
*pstr
, int len
)
799 memcpy(pstr
->data
, bytearea
, len
);