]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/staging/wlan-ng/p80211req.c
UBUNTU: Ubuntu-4.13.0-45.50
[mirror_ubuntu-artful-kernel.git] / drivers / staging / wlan-ng / p80211req.c
CommitLineData
00b3ed16 1/* src/p80211/p80211req.c
3aa4ecf7
SP
2 *
3 * Request/Indication/MacMgmt interface handling functions
4 *
5 * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved.
6 * --------------------------------------------------------------------
7 *
8 * linux-wlan
9 *
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/
14 *
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.
19 *
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.
30 *
31 * --------------------------------------------------------------------
32 *
33 * Inquiries regarding the linux-wlan Open Source project can be
34 * made directly to:
35 *
36 * AbsoluteValue Systems Inc.
37 * info@linux-wlan.com
38 * http://www.linux-wlan.com
39 *
40 * --------------------------------------------------------------------
41 *
42 * Portions of the development of this software were funded by
43 * Intersil Corporation as part of PRISM(R) chipset product development.
44 *
45 * --------------------------------------------------------------------
46 *
47 * This file contains the functions, types, and macros to support the
48 * MLME request interface that's implemented via the device ioctls.
49 *
50 * --------------------------------------------------------------------
51 */
00b3ed16 52
00b3ed16
GKH
53#include <linux/module.h>
54#include <linux/kernel.h>
55#include <linux/sched.h>
56#include <linux/types.h>
57#include <linux/skbuff.h>
00b3ed16
GKH
58#include <linux/wireless.h>
59#include <linux/netdevice.h>
60#include <linux/etherdevice.h>
61#include <net/sock.h>
62#include <linux/netlink.h>
63
00b3ed16
GKH
64#include "p80211types.h"
65#include "p80211hdr.h"
66#include "p80211mgmt.h"
67#include "p80211conv.h"
68#include "p80211msg.h"
69#include "p80211netdev.h"
70#include "p80211ioctl.h"
71#include "p80211metadef.h"
72#include "p80211metastruct.h"
73#include "p80211req.h"
74
c97efa34
SP
75static void p80211req_handlemsg(struct wlandevice *wlandev,
76 struct p80211msg *msg);
c9573a8d 77static void p80211req_mibset_mibget(struct wlandevice *wlandev,
b1f3b305
SP
78 struct p80211msg_dot11req_mibget *mib_msg,
79 int isget);
00b3ed16 80
2f479125
CB
81static void p80211req_handle_action(struct wlandevice *wlandev, u32 *data,
82 int isget, u32 flag)
83{
84 if (isget) {
85 if (wlandev->hostwep & flag)
86 *data = P80211ENUM_truth_true;
87 else
88 *data = P80211ENUM_truth_false;
89 } else {
90 wlandev->hostwep &= ~flag;
91 if (*data == P80211ENUM_truth_true)
92 wlandev->hostwep |= flag;
93 }
94}
95
00b3ed16 96/*----------------------------------------------------------------
3aa4ecf7
SP
97 * p80211req_dorequest
98 *
99 * Handles an MLME request/confirm message.
100 *
101 * Arguments:
102 * wlandev WLAN device struct
103 * msgbuf Buffer containing a request message
104 *
105 * Returns:
106 * 0 on success, an errno otherwise
107 *
108 * Call context:
109 * Potentially blocks the caller, so it's a good idea to
110 * not call this function from an interrupt context.
111 *----------------------------------------------------------------
112 */
c9573a8d 113int p80211req_dorequest(struct wlandevice *wlandev, u8 *msgbuf)
00b3ed16 114{
0e21fa46 115 struct p80211msg *msg = (struct p80211msg *)msgbuf;
00b3ed16 116
00b3ed16 117 /* Check to make sure the MSD is running */
b1de9675
MM
118 if (!((wlandev->msdstate == WLAN_MSD_HWPRESENT &&
119 msg->msgcode == DIDmsg_lnxreq_ifstate) ||
120 wlandev->msdstate == WLAN_MSD_RUNNING ||
121 wlandev->msdstate == WLAN_MSD_FWLOAD)) {
00b3ed16
GKH
122 return -ENODEV;
123 }
124
125 /* Check Permissions */
67a7b378 126 if (!capable(CAP_NET_ADMIN) &&
b1f3b305 127 (msg->msgcode != DIDmsg_dot11req_mibget)) {
02d9b1eb
VO
128 netdev_err(wlandev->netdev,
129 "%s: only dot11req_mibget allowed for non-root.\n",
130 wlandev->name);
00b3ed16
GKH
131 return -EPERM;
132 }
133
134 /* Check for busy status */
d4e1818a 135 if (test_and_set_bit(1, &wlandev->request_pending))
00b3ed16 136 return -EBUSY;
00b3ed16
GKH
137
138 /* Allow p80211 to look at msg and handle if desired. */
139 /* So far, all p80211 msgs are immediate, no waitq/timer necessary */
140 /* This may change. */
141 p80211req_handlemsg(wlandev, msg);
142
143 /* Pass it down to wlandev via wlandev->mlmerequest */
6c55d50e 144 if (wlandev->mlmerequest)
00b3ed16
GKH
145 wlandev->mlmerequest(wlandev, msg);
146
d4e1818a 147 clear_bit(1, &wlandev->request_pending);
4764ca98 148 return 0; /* if result==0, msg->status still may contain an err */
00b3ed16
GKH
149}
150
151/*----------------------------------------------------------------
3aa4ecf7
SP
152 * p80211req_handlemsg
153 *
154 * p80211 message handler. Primarily looks for messages that
155 * belong to p80211 and then dispatches the appropriate response.
156 * TODO: we don't do anything yet. Once the linuxMIB is better
157 * defined we'll need a get/set handler.
158 *
159 * Arguments:
160 * wlandev WLAN device struct
161 * msg message structure
162 *
163 * Returns:
164 * nothing (any results are set in the status field of the msg)
165 *
166 * Call context:
167 * Process thread
168 *----------------------------------------------------------------
169 */
c97efa34
SP
170static void p80211req_handlemsg(struct wlandevice *wlandev,
171 struct p80211msg *msg)
00b3ed16 172{
00b3ed16 173 switch (msg->msgcode) {
b1de9675 174 case DIDmsg_lnxreq_hostwep:{
009629ef 175 struct p80211msg_lnxreq_hostwep *req =
0e21fa46 176 (struct p80211msg_lnxreq_hostwep *)msg;
009629ef
DN
177 wlandev->hostwep &=
178 ~(HOSTWEP_DECRYPT | HOSTWEP_ENCRYPT);
179 if (req->decrypt.data == P80211ENUM_truth_true)
180 wlandev->hostwep |= HOSTWEP_DECRYPT;
181 if (req->encrypt.data == P80211ENUM_truth_true)
182 wlandev->hostwep |= HOSTWEP_ENCRYPT;
00b3ed16 183
009629ef
DN
184 break;
185 }
00b3ed16 186 case DIDmsg_dot11req_mibget:
b1de9675 187 case DIDmsg_dot11req_mibset:{
009629ef
DN
188 int isget = (msg->msgcode == DIDmsg_dot11req_mibget);
189 struct p80211msg_dot11req_mibget *mib_msg =
0e21fa46 190 (struct p80211msg_dot11req_mibget *)msg;
009629ef
DN
191 p80211req_mibset_mibget(wlandev, mib_msg, isget);
192 break;
193 }
b1de9675 194 } /* switch msg->msgcode */
00b3ed16
GKH
195}
196
c9573a8d 197static void p80211req_mibset_mibget(struct wlandevice *wlandev,
b1f3b305
SP
198 struct p80211msg_dot11req_mibget *mib_msg,
199 int isget)
00b3ed16 200{
17475c50
IC
201 struct p80211itemd *mibitem =
202 (struct p80211itemd *)mib_msg->mibattribute.data;
3fd1e3fc
SP
203 struct p80211pstrd *pstr = (struct p80211pstrd *)mibitem->data;
204 u8 *key = mibitem->data + sizeof(struct p80211pstrd);
00b3ed16 205
00b3ed16 206 switch (mibitem->did) {
152f0448 207 case DIDmib_dot11smt_dot11WEPDefaultKeysTable_key(1):
41e9b844 208 case DIDmib_dot11smt_dot11WEPDefaultKeysTable_key(2):
8d3a2252 209 case DIDmib_dot11smt_dot11WEPDefaultKeysTable_key(3):
17d9ff12 210 case DIDmib_dot11smt_dot11WEPDefaultKeysTable_key(4):
7694538c 211 if (!isget)
37f92cf0
CB
212 wep_change_key(wlandev,
213 P80211DID_ITEM(mibitem->did) - 1,
214 key, pstr->len);
215 break;
216
b1de9675 217 case DIDmib_dot11smt_dot11PrivacyTable_dot11WEPDefaultKeyID:{
0e21fa46 218 u32 *data = (u32 *)mibitem->data;
00b3ed16 219
7694538c
DN
220 if (isget) {
221 *data = wlandev->hostwep & HOSTWEP_DEFAULTKEY_MASK;
222 } else {
223 wlandev->hostwep &= ~(HOSTWEP_DEFAULTKEY_MASK);
224 wlandev->hostwep |= (*data & HOSTWEP_DEFAULTKEY_MASK);
b1de9675 225 }
7694538c
DN
226 break;
227 }
b1de9675 228 case DIDmib_dot11smt_dot11PrivacyTable_dot11PrivacyInvoked:{
0e21fa46 229 u32 *data = (u32 *)mibitem->data;
7694538c 230
2f479125
CB
231 p80211req_handle_action(wlandev, data, isget,
232 HOSTWEP_PRIVACYINVOKED);
7694538c
DN
233 break;
234 }
b1de9675 235 case DIDmib_dot11smt_dot11PrivacyTable_dot11ExcludeUnencrypted:{
0e21fa46 236 u32 *data = (u32 *)mibitem->data;
7694538c 237
2f479125
CB
238 p80211req_handle_action(wlandev, data, isget,
239 HOSTWEP_EXCLUDEUNENCRYPTED);
7694538c
DN
240 break;
241 }
00b3ed16 242 }
00b3ed16 243}