1 // SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1)
2 /* src/p80211/p80211req.c
4 * Request/Indication/MacMgmt interface handling functions
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 * This file contains the functions, types, and macros to support the
49 * MLME request interface that's implemented via the device ioctls.
51 * --------------------------------------------------------------------
54 #include <linux/module.h>
55 #include <linux/kernel.h>
56 #include <linux/sched.h>
57 #include <linux/types.h>
58 #include <linux/skbuff.h>
59 #include <linux/wireless.h>
60 #include <linux/netdevice.h>
61 #include <linux/etherdevice.h>
63 #include <linux/netlink.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 "p80211ioctl.h"
72 #include "p80211metadef.h"
73 #include "p80211metastruct.h"
74 #include "p80211req.h"
76 static void p80211req_handlemsg(struct wlandevice
*wlandev
,
77 struct p80211msg
*msg
);
78 static void p80211req_mibset_mibget(struct wlandevice
*wlandev
,
79 struct p80211msg_dot11req_mibget
*mib_msg
,
82 static void p80211req_handle_action(struct wlandevice
*wlandev
, u32
*data
,
86 if (wlandev
->hostwep
& flag
)
87 *data
= P80211ENUM_truth_true
;
89 *data
= P80211ENUM_truth_false
;
91 wlandev
->hostwep
&= ~flag
;
92 if (*data
== P80211ENUM_truth_true
)
93 wlandev
->hostwep
|= flag
;
97 /*----------------------------------------------------------------
100 * Handles an MLME request/confirm message.
103 * wlandev WLAN device struct
104 * msgbuf Buffer containing a request message
107 * 0 on success, an errno otherwise
110 * Potentially blocks the caller, so it's a good idea to
111 * not call this function from an interrupt context.
112 *----------------------------------------------------------------
114 int p80211req_dorequest(struct wlandevice
*wlandev
, u8
*msgbuf
)
116 struct p80211msg
*msg
= (struct p80211msg
*)msgbuf
;
118 /* Check to make sure the MSD is running */
119 if (!((wlandev
->msdstate
== WLAN_MSD_HWPRESENT
&&
120 msg
->msgcode
== DIDmsg_lnxreq_ifstate
) ||
121 wlandev
->msdstate
== WLAN_MSD_RUNNING
||
122 wlandev
->msdstate
== WLAN_MSD_FWLOAD
)) {
126 /* Check Permissions */
127 if (!capable(CAP_NET_ADMIN
) &&
128 (msg
->msgcode
!= DIDmsg_dot11req_mibget
)) {
129 netdev_err(wlandev
->netdev
,
130 "%s: only dot11req_mibget allowed for non-root.\n",
135 /* Check for busy status */
136 if (test_and_set_bit(1, &wlandev
->request_pending
))
139 /* Allow p80211 to look at msg and handle if desired. */
140 /* So far, all p80211 msgs are immediate, no waitq/timer necessary */
141 /* This may change. */
142 p80211req_handlemsg(wlandev
, msg
);
144 /* Pass it down to wlandev via wlandev->mlmerequest */
145 if (wlandev
->mlmerequest
)
146 wlandev
->mlmerequest(wlandev
, msg
);
148 clear_bit(1, &wlandev
->request_pending
);
149 return 0; /* if result==0, msg->status still may contain an err */
152 /*----------------------------------------------------------------
153 * p80211req_handlemsg
155 * p80211 message handler. Primarily looks for messages that
156 * belong to p80211 and then dispatches the appropriate response.
157 * TODO: we don't do anything yet. Once the linuxMIB is better
158 * defined we'll need a get/set handler.
161 * wlandev WLAN device struct
162 * msg message structure
165 * nothing (any results are set in the status field of the msg)
169 *----------------------------------------------------------------
171 static void p80211req_handlemsg(struct wlandevice
*wlandev
,
172 struct p80211msg
*msg
)
174 switch (msg
->msgcode
) {
175 case DIDmsg_lnxreq_hostwep
:{
176 struct p80211msg_lnxreq_hostwep
*req
=
177 (struct p80211msg_lnxreq_hostwep
*)msg
;
179 ~(HOSTWEP_DECRYPT
| HOSTWEP_ENCRYPT
);
180 if (req
->decrypt
.data
== P80211ENUM_truth_true
)
181 wlandev
->hostwep
|= HOSTWEP_DECRYPT
;
182 if (req
->encrypt
.data
== P80211ENUM_truth_true
)
183 wlandev
->hostwep
|= HOSTWEP_ENCRYPT
;
187 case DIDmsg_dot11req_mibget
:
188 case DIDmsg_dot11req_mibset
:{
189 int isget
= (msg
->msgcode
== DIDmsg_dot11req_mibget
);
190 struct p80211msg_dot11req_mibget
*mib_msg
=
191 (struct p80211msg_dot11req_mibget
*)msg
;
192 p80211req_mibset_mibget(wlandev
, mib_msg
, isget
);
195 } /* switch msg->msgcode */
198 static void p80211req_mibset_mibget(struct wlandevice
*wlandev
,
199 struct p80211msg_dot11req_mibget
*mib_msg
,
202 struct p80211itemd
*mibitem
=
203 (struct p80211itemd
*)mib_msg
->mibattribute
.data
;
204 struct p80211pstrd
*pstr
= (struct p80211pstrd
*)mibitem
->data
;
205 u8
*key
= mibitem
->data
+ sizeof(struct p80211pstrd
);
207 switch (mibitem
->did
) {
208 case DIDmib_dot11smt_dot11WEPDefaultKeysTable_key(1):
209 case DIDmib_dot11smt_dot11WEPDefaultKeysTable_key(2):
210 case DIDmib_dot11smt_dot11WEPDefaultKeysTable_key(3):
211 case DIDmib_dot11smt_dot11WEPDefaultKeysTable_key(4):
213 wep_change_key(wlandev
,
214 P80211DID_ITEM(mibitem
->did
) - 1,
218 case DIDmib_dot11smt_dot11PrivacyTable_dot11WEPDefaultKeyID
:{
219 u32
*data
= (u32
*)mibitem
->data
;
222 *data
= wlandev
->hostwep
& HOSTWEP_DEFAULTKEY_MASK
;
224 wlandev
->hostwep
&= ~(HOSTWEP_DEFAULTKEY_MASK
);
225 wlandev
->hostwep
|= (*data
& HOSTWEP_DEFAULTKEY_MASK
);
229 case DIDmib_dot11smt_dot11PrivacyTable_dot11PrivacyInvoked
:{
230 u32
*data
= (u32
*)mibitem
->data
;
232 p80211req_handle_action(wlandev
, data
, isget
,
233 HOSTWEP_PRIVACYINVOKED
);
236 case DIDmib_dot11smt_dot11PrivacyTable_dot11ExcludeUnencrypted
:{
237 u32
*data
= (u32
*)mibitem
->data
;
239 p80211req_handle_action(wlandev
, data
, isget
,
240 HOSTWEP_EXCLUDEUNENCRYPTED
);