1 /* src/p80211/p80211req.c
3 * Request/Indication/MacMgmt interface handling functions
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 * This file contains the functions, types, and macros to support the
48 * MLME request interface that's implemented via the device ioctls.
50 * --------------------------------------------------------------------
53 /*================================================================*/
57 #include <linux/version.h>
59 #include <linux/module.h>
60 #include <linux/kernel.h>
61 #include <linux/sched.h>
62 #include <linux/types.h>
63 #include <linux/skbuff.h>
64 #include <linux/slab.h>
65 #include <linux/wireless.h>
66 #include <linux/netdevice.h>
67 #include <linux/etherdevice.h>
69 #include <linux/netlink.h>
71 #include "wlan_compat.h"
73 /*================================================================*/
74 /* Project Includes */
76 #include "p80211types.h"
77 #include "p80211hdr.h"
78 #include "p80211mgmt.h"
79 #include "p80211conv.h"
80 #include "p80211msg.h"
81 #include "p80211netdev.h"
82 #include "p80211ioctl.h"
83 #include "p80211metadef.h"
84 #include "p80211metastruct.h"
85 #include "p80211req.h"
87 /*================================================================*/
90 /* Maximum amount of time we'll wait for a request to complete */
91 #define P80211REQ_MAXTIME 3*HZ /* 3 seconds */
93 /*================================================================*/
96 /*================================================================*/
99 /*================================================================*/
100 /* Local Static Definitions */
102 /*================================================================*/
103 /* Local Function Declarations */
105 static void p80211req_handlemsg( wlandevice_t *wlandev, p80211msg_t *msg);
106 static int p80211req_mibset_mibget(wlandevice_t *wlandev, p80211msg_dot11req_mibget_t *mib_msg, int isget);
108 /*================================================================*/
109 /* Function Definitions */
112 /*----------------------------------------------------------------
113 * p80211req_dorequest
115 * Handles an MLME reqest/confirm message.
118 * wlandev WLAN device struct
119 * msgbuf Buffer containing a request message
122 * 0 on success, an errno otherwise
125 * Potentially blocks the caller, so it's a good idea to
126 * not call this function from an interrupt context.
127 ----------------------------------------------------------------*/
128 int p80211req_dorequest( wlandevice_t *wlandev, u8 *msgbuf)
131 p80211msg_t *msg = (p80211msg_t*)msgbuf;
135 /* Check to make sure the MSD is running */
137 !((wlandev->msdstate == WLAN_MSD_HWPRESENT &&
138 msg->msgcode == DIDmsg_lnxreq_ifstate) ||
139 wlandev->msdstate == WLAN_MSD_RUNNING ||
140 wlandev->msdstate == WLAN_MSD_FWLOAD) ) {
144 /* Check Permissions */
145 if (!capable(CAP_NET_ADMIN) &&
146 (msg->msgcode != DIDmsg_dot11req_mibget)) {
147 WLAN_LOG_ERROR("%s: only dot11req_mibget allowed for non-root.\n", wlandev->name);
151 /* Check for busy status */
152 if ( test_and_set_bit(1, &(wlandev->request_pending))) {
156 /* Allow p80211 to look at msg and handle if desired. */
157 /* So far, all p80211 msgs are immediate, no waitq/timer necessary */
158 /* This may change. */
159 p80211req_handlemsg(wlandev, msg);
161 /* Pass it down to wlandev via wlandev->mlmerequest */
162 if ( wlandev->mlmerequest != NULL )
163 wlandev->mlmerequest(wlandev, msg);
165 clear_bit( 1, &(wlandev->request_pending));
167 return result; /* if result==0, msg->status still may contain an err */
170 /*----------------------------------------------------------------
171 * p80211req_handlemsg
173 * p80211 message handler. Primarily looks for messages that
174 * belong to p80211 and then dispatches the appropriate response.
175 * TODO: we don't do anything yet. Once the linuxMIB is better
176 * defined we'll need a get/set handler.
179 * wlandev WLAN device struct
180 * msg message structure
183 * nothing (any results are set in the status field of the msg)
187 ----------------------------------------------------------------*/
188 static void p80211req_handlemsg( wlandevice_t *wlandev, p80211msg_t *msg)
192 switch (msg->msgcode) {
194 case DIDmsg_lnxreq_hostwep: {
195 p80211msg_lnxreq_hostwep_t *req = (p80211msg_lnxreq_hostwep_t*) msg;
196 wlandev->hostwep &= ~(HOSTWEP_DECRYPT|HOSTWEP_ENCRYPT);
197 if (req->decrypt.data == P80211ENUM_truth_true)
198 wlandev->hostwep |= HOSTWEP_DECRYPT;
199 if (req->encrypt.data == P80211ENUM_truth_true)
200 wlandev->hostwep |= HOSTWEP_ENCRYPT;
204 case DIDmsg_dot11req_mibget:
205 case DIDmsg_dot11req_mibset: {
206 int isget = (msg->msgcode == DIDmsg_dot11req_mibget);
207 p80211msg_dot11req_mibget_t *mib_msg = (p80211msg_dot11req_mibget_t *) msg;
208 p80211req_mibset_mibget (wlandev, mib_msg, isget);
213 } /* switch msg->msgcode */
220 static int p80211req_mibset_mibget(wlandevice_t *wlandev,
221 p80211msg_dot11req_mibget_t *mib_msg,
224 p80211itemd_t *mibitem = (p80211itemd_t *) mib_msg->mibattribute.data;
225 p80211pstrd_t *pstr = (p80211pstrd_t*) mibitem->data;
226 u8 *key = mibitem->data + sizeof(p80211pstrd_t);
230 switch (mibitem->did) {
231 case DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey0: {
233 wep_change_key(wlandev, 0, key, pstr->len);
236 case DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey1: {
238 wep_change_key(wlandev, 1, key, pstr->len);
241 case DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey2: {
243 wep_change_key(wlandev, 2, key, pstr->len);
246 case DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey3: {
248 wep_change_key(wlandev, 3, key, pstr->len);
251 case DIDmib_dot11smt_dot11PrivacyTable_dot11WEPDefaultKeyID: {
252 u32 *data = (u32 *) mibitem->data;
255 *data = wlandev->hostwep & HOSTWEP_DEFAULTKEY_MASK;
257 wlandev->hostwep &= ~(HOSTWEP_DEFAULTKEY_MASK);
259 wlandev->hostwep |= (*data & HOSTWEP_DEFAULTKEY_MASK);
263 case DIDmib_dot11smt_dot11PrivacyTable_dot11PrivacyInvoked: {
264 u32 *data = (u32 *) mibitem->data;
267 if (wlandev->hostwep & HOSTWEP_PRIVACYINVOKED)
268 *data = P80211ENUM_truth_true;
270 *data = P80211ENUM_truth_false;
272 wlandev->hostwep &= ~(HOSTWEP_PRIVACYINVOKED);
273 if (*data == P80211ENUM_truth_true)
274 wlandev->hostwep |= HOSTWEP_PRIVACYINVOKED;
278 case DIDmib_dot11smt_dot11PrivacyTable_dot11ExcludeUnencrypted: {
279 u32 *data = (u32 *) mibitem->data;
282 if (wlandev->hostwep & HOSTWEP_EXCLUDEUNENCRYPTED)
283 *data = P80211ENUM_truth_true;
285 *data = P80211ENUM_truth_false;
287 wlandev->hostwep &= ~(HOSTWEP_EXCLUDEUNENCRYPTED);
288 if (*data == P80211ENUM_truth_true)
289 wlandev->hostwep |= HOSTWEP_EXCLUDEUNENCRYPTED;