1 // SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1)
2 /* src/prism2/driver/prism2mib.c
4 * Management request for mibset/mibget
6 * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved.
7 * --------------------------------------------------------------------
11 * The contents of this file are subject to the Mozilla Public
12 * License Version 1.1 (the "License"); you may not use this file
13 * except in compliance with the License. You may obtain a copy of
14 * the License at http://www.mozilla.org/MPL/
16 * Software distributed under the License is distributed on an "AS
17 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
18 * implied. See the License for the specific language governing
19 * rights and limitations under the License.
21 * Alternatively, the contents of this file may be used under the
22 * terms of the GNU Public License version 2 (the "GPL"), in which
23 * case the provisions of the GPL are applicable instead of the
24 * above. If you wish to allow the use of your version of this file
25 * only under the terms of the GPL and not to allow others to use
26 * your version of this file under the MPL, indicate your decision
27 * by deleting the provisions above and replace them with the notice
28 * and other provisions required by the GPL. If you do not delete
29 * the provisions above, a recipient may use your version of this
30 * file under either the MPL or the GPL.
32 * --------------------------------------------------------------------
34 * Inquiries regarding the linux-wlan Open Source project can be
37 * AbsoluteValue Systems Inc.
39 * http://www.linux-wlan.com
41 * --------------------------------------------------------------------
43 * Portions of the development of this software were funded by
44 * Intersil Corporation as part of PRISM(R) chipset product development.
46 * --------------------------------------------------------------------
48 * The functions in this file handle the mibset/mibget management
51 * --------------------------------------------------------------------
54 #include <linux/module.h>
55 #include <linux/kernel.h>
56 #include <linux/sched.h>
57 #include <linux/types.h>
58 #include <linux/wireless.h>
59 #include <linux/netdevice.h>
61 #include <linux/delay.h>
62 #include <asm/byteorder.h>
63 #include <linux/usb.h>
64 #include <linux/bitops.h>
66 #include "p80211types.h"
67 #include "p80211hdr.h"
68 #include "p80211mgmt.h"
69 #include "p80211conv.h"
70 #include "p80211msg.h"
71 #include "p80211netdev.h"
72 #include "p80211metadef.h"
73 #include "p80211metastruct.h"
75 #include "prism2mgmt.h"
77 #define MIB_TMP_MAXLEN 200 /* Max length of RID record (in bytes). */
79 #define F_STA 0x1 /* MIB is supported on stations. */
80 #define F_READ 0x2 /* MIB may be read. */
81 #define F_WRITE 0x4 /* MIB may be written. */
89 int (*func
)(struct mibrec
*mib
,
91 struct wlandevice
*wlandev
,
93 struct p80211msg_dot11req_mibset
*msg
, void *data
);
96 static int prism2mib_bytearea2pstr(struct mibrec
*mib
,
98 struct wlandevice
*wlandev
,
100 struct p80211msg_dot11req_mibset
*msg
,
103 static int prism2mib_uint32(struct mibrec
*mib
,
105 struct wlandevice
*wlandev
,
107 struct p80211msg_dot11req_mibset
*msg
, void *data
);
109 static int prism2mib_flag(struct mibrec
*mib
,
111 struct wlandevice
*wlandev
,
113 struct p80211msg_dot11req_mibset
*msg
, void *data
);
115 static int prism2mib_wepdefaultkey(struct mibrec
*mib
,
117 struct wlandevice
*wlandev
,
119 struct p80211msg_dot11req_mibset
*msg
,
122 static int prism2mib_privacyinvoked(struct mibrec
*mib
,
124 struct wlandevice
*wlandev
,
126 struct p80211msg_dot11req_mibset
*msg
,
129 static int prism2mib_excludeunencrypted(struct mibrec
*mib
,
131 struct wlandevice
*wlandev
,
133 struct p80211msg_dot11req_mibset
*msg
,
136 static int prism2mib_fragmentationthreshold(struct mibrec
*mib
,
138 struct wlandevice
*wlandev
,
140 struct p80211msg_dot11req_mibset
*msg
,
143 static int prism2mib_priv(struct mibrec
*mib
,
145 struct wlandevice
*wlandev
,
147 struct p80211msg_dot11req_mibset
*msg
, void *data
);
149 static struct mibrec mibtab
[] = {
151 {DIDmib_dot11smt_dot11WEPDefaultKeysTable_key(1),
153 HFA384x_RID_CNFWEPDEFAULTKEY0
, 0, 0,
154 prism2mib_wepdefaultkey
},
155 {DIDmib_dot11smt_dot11WEPDefaultKeysTable_key(2),
157 HFA384x_RID_CNFWEPDEFAULTKEY1
, 0, 0,
158 prism2mib_wepdefaultkey
},
159 {DIDmib_dot11smt_dot11WEPDefaultKeysTable_key(3),
161 HFA384x_RID_CNFWEPDEFAULTKEY2
, 0, 0,
162 prism2mib_wepdefaultkey
},
163 {DIDmib_dot11smt_dot11WEPDefaultKeysTable_key(4),
165 HFA384x_RID_CNFWEPDEFAULTKEY3
, 0, 0,
166 prism2mib_wepdefaultkey
},
167 {DIDmib_dot11smt_dot11PrivacyTable_dot11PrivacyInvoked
,
168 F_STA
| F_READ
| F_WRITE
,
169 HFA384x_RID_CNFWEPFLAGS
, HFA384x_WEPFLAGS_PRIVINVOKED
, 0,
170 prism2mib_privacyinvoked
},
171 {DIDmib_dot11smt_dot11PrivacyTable_dot11WEPDefaultKeyID
,
172 F_STA
| F_READ
| F_WRITE
,
173 HFA384x_RID_CNFWEPDEFAULTKEYID
, 0, 0,
175 {DIDmib_dot11smt_dot11PrivacyTable_dot11ExcludeUnencrypted
,
176 F_STA
| F_READ
| F_WRITE
,
177 HFA384x_RID_CNFWEPFLAGS
, HFA384x_WEPFLAGS_EXCLUDE
, 0,
178 prism2mib_excludeunencrypted
},
182 {DIDmib_dot11mac_dot11OperationTable_dot11MACAddress
,
183 F_STA
| F_READ
| F_WRITE
,
184 HFA384x_RID_CNFOWNMACADDR
, HFA384x_RID_CNFOWNMACADDR_LEN
, 0,
185 prism2mib_bytearea2pstr
},
186 {DIDmib_dot11mac_dot11OperationTable_dot11RTSThreshold
,
187 F_STA
| F_READ
| F_WRITE
,
188 HFA384x_RID_RTSTHRESH
, 0, 0,
190 {DIDmib_dot11mac_dot11OperationTable_dot11ShortRetryLimit
,
192 HFA384x_RID_SHORTRETRYLIMIT
, 0, 0,
194 {DIDmib_dot11mac_dot11OperationTable_dot11LongRetryLimit
,
196 HFA384x_RID_LONGRETRYLIMIT
, 0, 0,
198 {DIDmib_dot11mac_dot11OperationTable_dot11FragmentationThreshold
,
199 F_STA
| F_READ
| F_WRITE
,
200 HFA384x_RID_FRAGTHRESH
, 0, 0,
201 prism2mib_fragmentationthreshold
},
202 {DIDmib_dot11mac_dot11OperationTable_dot11MaxTransmitMSDULifetime
,
204 HFA384x_RID_MAXTXLIFETIME
, 0, 0,
209 {DIDmib_dot11phy_dot11PhyDSSSTable_dot11CurrentChannel
,
211 HFA384x_RID_CURRENTCHANNEL
, 0, 0,
213 {DIDmib_dot11phy_dot11PhyTxPowerTable_dot11CurrentTxPowerLevel
,
214 F_STA
| F_READ
| F_WRITE
,
215 HFA384x_RID_TXPOWERMAX
, 0, 0,
220 {DIDmib_p2_p2Static_p2CnfPortType
,
221 F_STA
| F_READ
| F_WRITE
,
222 HFA384x_RID_CNFPORTTYPE
, 0, 0,
227 {DIDmib_p2_p2MAC_p2CurrentTxRate
,
229 HFA384x_RID_CURRENTTXRATE
, 0, 0,
232 /* And finally, lnx mibs */
233 {DIDmib_lnx_lnxConfigTable_lnxRSNAIE
,
234 F_STA
| F_READ
| F_WRITE
,
235 HFA384x_RID_CNFWPADATA
, 0, 0,
237 {0, 0, 0, 0, 0, NULL
}
241 * prism2mgmt_mibset_mibget
243 * Set the value of a mib item.
246 * wlandev wlan device structure
247 * msgp ptr to msg buffer
251 * <0 success, but we're waiting for something to finish.
252 * >0 an error occurred while handling the message.
256 * process thread (usually)
260 int prism2mgmt_mibset_mibget(struct wlandevice
*wlandev
, void *msgp
)
262 struct hfa384x
*hw
= wlandev
->priv
;
268 struct p80211msg_dot11req_mibset
*msg
= msgp
;
269 struct p80211itemd
*mibitem
;
271 msg
->resultcode
.status
= P80211ENUM_msgitem_status_data_ok
;
272 msg
->resultcode
.data
= P80211ENUM_resultcode_success
;
275 ** Determine if this is an Access Point or a station.
281 ** Find the MIB in the MIB table. Note that a MIB may be in the
282 ** table twice...once for an AP and once for a station. Make sure
283 ** to get the correct one. Note that DID=0 marks the end of the
287 mibitem
= (struct p80211itemd
*)msg
->mibattribute
.data
;
289 for (mib
= mibtab
; mib
->did
!= 0; mib
++)
290 if (mib
->did
== mibitem
->did
&& (mib
->flag
& which
))
294 msg
->resultcode
.data
= P80211ENUM_resultcode_not_supported
;
299 ** Determine if this is a "mibget" or a "mibset". If this is a
300 ** "mibget", then make sure that the MIB may be read. Otherwise,
301 ** this is a "mibset" so make make sure that the MIB may be written.
304 isget
= (msg
->msgcode
== DIDmsg_dot11req_mibget
);
307 if (!(mib
->flag
& F_READ
)) {
308 msg
->resultcode
.data
=
309 P80211ENUM_resultcode_cant_get_writeonly_mib
;
313 if (!(mib
->flag
& F_WRITE
)) {
314 msg
->resultcode
.data
=
315 P80211ENUM_resultcode_cant_set_readonly_mib
;
321 ** Execute the MIB function. If things worked okay, then make
322 ** sure that the MIB function also worked okay. If so, and this
323 ** is a "mibget", then the status value must be set for both the
324 ** "mibattribute" parameter and the mib item within the data
325 ** portion of the "mibattribute".
328 result
= mib
->func(mib
, isget
, wlandev
, hw
, msg
, (void *)mibitem
->data
);
330 if (msg
->resultcode
.data
== P80211ENUM_resultcode_success
) {
332 pr_debug("get/set failure, result=%d\n", result
);
333 msg
->resultcode
.data
=
334 P80211ENUM_resultcode_implementation_failure
;
337 msg
->mibattribute
.status
=
338 P80211ENUM_msgitem_status_data_ok
;
340 P80211ENUM_msgitem_status_data_ok
;
350 * prism2mib_bytearea2pstr
352 * Get/set pstr data to/from a byte area.
354 * MIB record parameters:
355 * parm1 Prism2 RID value.
356 * parm2 Number of bytes of RID data.
361 * isget MIBGET/MIBSET flag.
362 * wlandev wlan device structure.
363 * priv "priv" structure.
365 * msg Message structure.
374 static int prism2mib_bytearea2pstr(struct mibrec
*mib
,
376 struct wlandevice
*wlandev
,
378 struct p80211msg_dot11req_mibset
*msg
,
382 struct p80211pstrd
*pstr
= data
;
383 u8 bytebuf
[MIB_TMP_MAXLEN
];
387 hfa384x_drvr_getconfig(hw
, mib
->parm1
, bytebuf
, mib
->parm2
);
388 prism2mgmt_bytearea2pstr(bytebuf
, pstr
, mib
->parm2
);
390 memset(bytebuf
, 0, mib
->parm2
);
391 memcpy(bytebuf
, pstr
->data
, pstr
->len
);
393 hfa384x_drvr_setconfig(hw
, mib
->parm1
, bytebuf
, mib
->parm2
);
402 * Get/set uint32 data.
404 * MIB record parameters:
405 * parm1 Prism2 RID value.
411 * isget MIBGET/MIBSET flag.
412 * wlandev wlan device structure.
413 * priv "priv" structure.
415 * msg Message structure.
424 static int prism2mib_uint32(struct mibrec
*mib
,
426 struct wlandevice
*wlandev
,
428 struct p80211msg_dot11req_mibset
*msg
, void *data
)
432 u8 bytebuf
[MIB_TMP_MAXLEN
];
433 u16
*wordbuf
= (u16
*)bytebuf
;
436 result
= hfa384x_drvr_getconfig16(hw
, mib
->parm1
, wordbuf
);
440 result
= hfa384x_drvr_setconfig16(hw
, mib
->parm1
, *wordbuf
);
451 * MIB record parameters:
452 * parm1 Prism2 RID value.
453 * parm2 Bit to get/set.
458 * isget MIBGET/MIBSET flag.
459 * wlandev wlan device structure.
460 * priv "priv" structure.
462 * msg Message structure.
471 static int prism2mib_flag(struct mibrec
*mib
,
473 struct wlandevice
*wlandev
,
475 struct p80211msg_dot11req_mibset
*msg
, void *data
)
479 u8 bytebuf
[MIB_TMP_MAXLEN
];
480 u16
*wordbuf
= (u16
*)bytebuf
;
483 result
= hfa384x_drvr_getconfig16(hw
, mib
->parm1
, wordbuf
);
487 *uint32
= (flags
& mib
->parm2
) ?
488 P80211ENUM_truth_true
: P80211ENUM_truth_false
;
490 if ((*uint32
) == P80211ENUM_truth_true
)
493 flags
&= ~mib
->parm2
;
496 hfa384x_drvr_setconfig16(hw
, mib
->parm1
, *wordbuf
);
504 * prism2mib_wepdefaultkey
506 * Get/set WEP default keys.
508 * MIB record parameters:
509 * parm1 Prism2 RID value.
510 * parm2 Number of bytes of RID data.
515 * isget MIBGET/MIBSET flag.
516 * wlandev wlan device structure.
517 * priv "priv" structure.
519 * msg Message structure.
528 static int prism2mib_wepdefaultkey(struct mibrec
*mib
,
530 struct wlandevice
*wlandev
,
532 struct p80211msg_dot11req_mibset
*msg
,
536 struct p80211pstrd
*pstr
= data
;
537 u8 bytebuf
[MIB_TMP_MAXLEN
];
541 result
= 0; /* Should never happen. */
543 len
= (pstr
->len
> 5) ? HFA384x_RID_CNFWEP128DEFAULTKEY_LEN
:
544 HFA384x_RID_CNFWEPDEFAULTKEY_LEN
;
545 memset(bytebuf
, 0, len
);
546 memcpy(bytebuf
, pstr
->data
, pstr
->len
);
547 result
= hfa384x_drvr_setconfig(hw
, mib
->parm1
, bytebuf
, len
);
554 * prism2mib_privacyinvoked
556 * Get/set the dot11PrivacyInvoked value.
558 * MIB record parameters:
559 * parm1 Prism2 RID value.
560 * parm2 Bit value for PrivacyInvoked flag.
565 * isget MIBGET/MIBSET flag.
566 * wlandev wlan device structure.
567 * priv "priv" structure.
569 * msg Message structure.
578 static int prism2mib_privacyinvoked(struct mibrec
*mib
,
580 struct wlandevice
*wlandev
,
582 struct p80211msg_dot11req_mibset
*msg
,
585 if (wlandev
->hostwep
& HOSTWEP_DECRYPT
) {
586 if (wlandev
->hostwep
& HOSTWEP_DECRYPT
)
587 mib
->parm2
|= HFA384x_WEPFLAGS_DISABLE_RXCRYPT
;
588 if (wlandev
->hostwep
& HOSTWEP_ENCRYPT
)
589 mib
->parm2
|= HFA384x_WEPFLAGS_DISABLE_TXCRYPT
;
592 return prism2mib_flag(mib
, isget
, wlandev
, hw
, msg
, data
);
596 * prism2mib_excludeunencrypted
598 * Get/set the dot11ExcludeUnencrypted value.
600 * MIB record parameters:
601 * parm1 Prism2 RID value.
602 * parm2 Bit value for ExcludeUnencrypted flag.
607 * isget MIBGET/MIBSET flag.
608 * wlandev wlan device structure.
609 * priv "priv" structure.
611 * msg Message structure.
620 static int prism2mib_excludeunencrypted(struct mibrec
*mib
,
622 struct wlandevice
*wlandev
,
624 struct p80211msg_dot11req_mibset
*msg
,
627 return prism2mib_flag(mib
, isget
, wlandev
, hw
, msg
, data
);
631 * prism2mib_fragmentationthreshold
633 * Get/set the fragmentation threshold.
635 * MIB record parameters:
636 * parm1 Prism2 RID value.
642 * isget MIBGET/MIBSET flag.
643 * wlandev wlan device structure.
644 * priv "priv" structure.
646 * msg Message structure.
655 static int prism2mib_fragmentationthreshold(struct mibrec
*mib
,
657 struct wlandevice
*wlandev
,
659 struct p80211msg_dot11req_mibset
*msg
,
666 netdev_warn(wlandev
->netdev
,
667 "Attempt to set odd number FragmentationThreshold\n");
668 msg
->resultcode
.data
=
669 P80211ENUM_resultcode_not_supported
;
673 return prism2mib_uint32(mib
, isget
, wlandev
, hw
, msg
, data
);
679 * Get/set values in the "priv" data structure.
681 * MIB record parameters:
688 * isget MIBGET/MIBSET flag.
689 * wlandev wlan device structure.
690 * priv "priv" structure.
692 * msg Message structure.
701 static int prism2mib_priv(struct mibrec
*mib
,
703 struct wlandevice
*wlandev
,
705 struct p80211msg_dot11req_mibset
*msg
, void *data
)
707 struct p80211pstrd
*pstr
= data
;
710 case DIDmib_lnx_lnxConfigTable_lnxRSNAIE
:{
711 struct hfa384x_wpa_data wpa
;
714 hfa384x_drvr_getconfig(hw
,
715 HFA384x_RID_CNFWPADATA
,
718 pstr
->len
= le16_to_cpu(wpa
.datalen
);
719 memcpy(pstr
->data
, wpa
.data
, pstr
->len
);
721 wpa
.datalen
= cpu_to_le16(pstr
->len
);
722 memcpy(wpa
.data
, pstr
->data
, pstr
->len
);
724 hfa384x_drvr_setconfig(hw
,
725 HFA384x_RID_CNFWPADATA
,
732 netdev_err(wlandev
->netdev
, "Unhandled DID 0x%08x\n", mib
->did
);
739 * prism2mgmt_pstr2bytestr
741 * Convert the pstr data in the WLAN message structure into an hfa384x
742 * byte string format.
745 * bytestr hfa384x byte string data type
746 * pstr wlan message data
753 void prism2mgmt_pstr2bytestr(struct hfa384x_bytestr
*bytestr
,
754 struct p80211pstrd
*pstr
)
756 bytestr
->len
= cpu_to_le16((u16
)(pstr
->len
));
757 memcpy(bytestr
->data
, pstr
->data
, pstr
->len
);
761 * prism2mgmt_bytestr2pstr
763 * Convert the data in an hfa384x byte string format into a
764 * pstr in the WLAN message.
767 * bytestr hfa384x byte string data type
775 void prism2mgmt_bytestr2pstr(struct hfa384x_bytestr
*bytestr
,
776 struct p80211pstrd
*pstr
)
778 pstr
->len
= (u8
)(le16_to_cpu(bytestr
->len
));
779 memcpy(pstr
->data
, bytestr
->data
, pstr
->len
);
783 * prism2mgmt_bytearea2pstr
785 * Convert the data in an hfa384x byte area format into a pstr
786 * in the WLAN message.
789 * bytearea hfa384x byte area data type
797 void prism2mgmt_bytearea2pstr(u8
*bytearea
, struct p80211pstrd
*pstr
, int len
)
800 memcpy(pstr
->data
, bytearea
, len
);