blob: 179194e7d2aaaff731b4675f1016b604cc9ecee0 [file] [log] [blame]
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001/* src/p80211/p80211req.c
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*/
52
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -070053#include <linux/module.h>
54#include <linux/kernel.h>
55#include <linux/sched.h>
56#include <linux/types.h>
57#include <linux/skbuff.h>
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -070058#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
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -070064#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
Edgardo Hames3d049432010-08-02 17:17:17 -030075static void p80211req_handlemsg(wlandevice_t *wlandev, struct p80211msg *msg);
Mithlesh Thukral297f06c2009-06-10 19:36:11 +053076static int p80211req_mibset_mibget(wlandevice_t *wlandev,
Edgardo Hamesb6bb56e2010-08-02 16:20:39 -030077 struct p80211msg_dot11req_mibget *mib_msg,
Moritz Muehlenhoffb1de9672009-02-08 02:20:46 +010078 int isget);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -070079
80/*----------------------------------------------------------------
81* p80211req_dorequest
82*
83* Handles an MLME reqest/confirm message.
84*
85* Arguments:
86* wlandev WLAN device struct
87* msgbuf Buffer containing a request message
88*
89* Returns:
90* 0 on success, an errno otherwise
91*
92* Call context:
93* Potentially blocks the caller, so it's a good idea to
94* not call this function from an interrupt context.
95----------------------------------------------------------------*/
Svenne Krap5dd8acc2010-02-14 18:59:00 +010096int p80211req_dorequest(wlandevice_t *wlandev, u8 *msgbuf)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -070097{
Moritz Muehlenhoffb1de9672009-02-08 02:20:46 +010098 int result = 0;
Edgardo Hames3d049432010-08-02 17:17:17 -030099 struct p80211msg *msg = (struct p80211msg *) msgbuf;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700100
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700101 /* Check to make sure the MSD is running */
Moritz Muehlenhoffb1de9672009-02-08 02:20:46 +0100102 if (!((wlandev->msdstate == WLAN_MSD_HWPRESENT &&
103 msg->msgcode == DIDmsg_lnxreq_ifstate) ||
104 wlandev->msdstate == WLAN_MSD_RUNNING ||
105 wlandev->msdstate == WLAN_MSD_FWLOAD)) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700106 return -ENODEV;
107 }
108
109 /* Check Permissions */
Patrick Rooney67a7b372010-03-10 08:46:30 +0000110 if (!capable(CAP_NET_ADMIN) &&
111 (msg->msgcode != DIDmsg_dot11req_mibget)) {
Moritz Muehlenhoffb1de9672009-02-08 02:20:46 +0100112 printk(KERN_ERR
113 "%s: only dot11req_mibget allowed for non-root.\n",
114 wlandev->name);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700115 return -EPERM;
116 }
117
118 /* Check for busy status */
Moritz Muehlenhoffb1de9672009-02-08 02:20:46 +0100119 if (test_and_set_bit(1, &(wlandev->request_pending)))
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700120 return -EBUSY;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700121
122 /* Allow p80211 to look at msg and handle if desired. */
123 /* So far, all p80211 msgs are immediate, no waitq/timer necessary */
124 /* This may change. */
125 p80211req_handlemsg(wlandev, msg);
126
127 /* Pass it down to wlandev via wlandev->mlmerequest */
Moritz Muehlenhoffb1de9672009-02-08 02:20:46 +0100128 if (wlandev->mlmerequest != NULL)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700129 wlandev->mlmerequest(wlandev, msg);
130
Moritz Muehlenhoffb1de9672009-02-08 02:20:46 +0100131 clear_bit(1, &(wlandev->request_pending));
Patrick Rooney67a7b372010-03-10 08:46:30 +0000132 return result; /* if result==0, msg->status still may contain an err */
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700133}
134
135/*----------------------------------------------------------------
136* p80211req_handlemsg
137*
138* p80211 message handler. Primarily looks for messages that
139* belong to p80211 and then dispatches the appropriate response.
140* TODO: we don't do anything yet. Once the linuxMIB is better
141* defined we'll need a get/set handler.
142*
143* Arguments:
144* wlandev WLAN device struct
145* msg message structure
146*
147* Returns:
148* nothing (any results are set in the status field of the msg)
149*
150* Call context:
151* Process thread
152----------------------------------------------------------------*/
Edgardo Hames3d049432010-08-02 17:17:17 -0300153static void p80211req_handlemsg(wlandevice_t *wlandev, struct p80211msg *msg)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700154{
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700155 switch (msg->msgcode) {
156
Moritz Muehlenhoffb1de9672009-02-08 02:20:46 +0100157 case DIDmsg_lnxreq_hostwep:{
Edgardo Hamesb6bb56e2010-08-02 16:20:39 -0300158 struct p80211msg_lnxreq_hostwep *req =
159 (struct p80211msg_lnxreq_hostwep *) msg;
Moritz Muehlenhoffb1de9672009-02-08 02:20:46 +0100160 wlandev->hostwep &=
161 ~(HOSTWEP_DECRYPT | HOSTWEP_ENCRYPT);
162 if (req->decrypt.data == P80211ENUM_truth_true)
163 wlandev->hostwep |= HOSTWEP_DECRYPT;
164 if (req->encrypt.data == P80211ENUM_truth_true)
165 wlandev->hostwep |= HOSTWEP_ENCRYPT;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700166
Moritz Muehlenhoffb1de9672009-02-08 02:20:46 +0100167 break;
168 }
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700169 case DIDmsg_dot11req_mibget:
Moritz Muehlenhoffb1de9672009-02-08 02:20:46 +0100170 case DIDmsg_dot11req_mibset:{
171 int isget = (msg->msgcode == DIDmsg_dot11req_mibget);
Edgardo Hamesb6bb56e2010-08-02 16:20:39 -0300172 struct p80211msg_dot11req_mibget *mib_msg =
173 (struct p80211msg_dot11req_mibget *) msg;
Moritz Muehlenhoffb1de9672009-02-08 02:20:46 +0100174 p80211req_mibset_mibget(wlandev, mib_msg, isget);
175 }
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700176 default:
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700177 ;
Moritz Muehlenhoffb1de9672009-02-08 02:20:46 +0100178 } /* switch msg->msgcode */
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700179
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700180 return;
181}
182
Mithlesh Thukral297f06c2009-06-10 19:36:11 +0530183static int p80211req_mibset_mibget(wlandevice_t *wlandev,
Edgardo Hamesb6bb56e2010-08-02 16:20:39 -0300184 struct p80211msg_dot11req_mibget *mib_msg,
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700185 int isget)
186{
Moritz Muehlenhoffb1de9672009-02-08 02:20:46 +0100187 p80211itemd_t *mibitem = (p80211itemd_t *) mib_msg->mibattribute.data;
188 p80211pstrd_t *pstr = (p80211pstrd_t *) mibitem->data;
Solomon Peachyaaad4302008-10-29 10:42:53 -0400189 u8 *key = mibitem->data + sizeof(p80211pstrd_t);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700190
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700191 switch (mibitem->did) {
Moritz Muehlenhoffb1de9672009-02-08 02:20:46 +0100192 case DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey0:{
193 if (!isget)
194 wep_change_key(wlandev, 0, key, pstr->len);
195 break;
196 }
197 case DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey1:{
198 if (!isget)
199 wep_change_key(wlandev, 1, key, pstr->len);
200 break;
201 }
202 case DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey2:{
203 if (!isget)
204 wep_change_key(wlandev, 2, key, pstr->len);
205 break;
206 }
207 case DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey3:{
208 if (!isget)
209 wep_change_key(wlandev, 3, key, pstr->len);
210 break;
211 }
212 case DIDmib_dot11smt_dot11PrivacyTable_dot11WEPDefaultKeyID:{
213 u32 *data = (u32 *) mibitem->data;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700214
Moritz Muehlenhoffb1de9672009-02-08 02:20:46 +0100215 if (isget) {
216 *data =
217 wlandev->hostwep & HOSTWEP_DEFAULTKEY_MASK;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700218 } else {
219 wlandev->hostwep &= ~(HOSTWEP_DEFAULTKEY_MASK);
220
Moritz Muehlenhoffb1de9672009-02-08 02:20:46 +0100221 wlandev->hostwep |=
222 (*data & HOSTWEP_DEFAULTKEY_MASK);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700223 }
Moritz Muehlenhoffb1de9672009-02-08 02:20:46 +0100224 break;
225 }
226 case DIDmib_dot11smt_dot11PrivacyTable_dot11PrivacyInvoked:{
227 u32 *data = (u32 *) mibitem->data;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700228
Moritz Muehlenhoffb1de9672009-02-08 02:20:46 +0100229 if (isget) {
230 if (wlandev->hostwep & HOSTWEP_PRIVACYINVOKED)
231 *data = P80211ENUM_truth_true;
232 else
233 *data = P80211ENUM_truth_false;
234 } else {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700235 wlandev->hostwep &= ~(HOSTWEP_PRIVACYINVOKED);
236 if (*data == P80211ENUM_truth_true)
Moritz Muehlenhoffb1de9672009-02-08 02:20:46 +0100237 wlandev->hostwep |=
238 HOSTWEP_PRIVACYINVOKED;
239 }
240 break;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700241 }
Moritz Muehlenhoffb1de9672009-02-08 02:20:46 +0100242 case DIDmib_dot11smt_dot11PrivacyTable_dot11ExcludeUnencrypted:{
243 u32 *data = (u32 *) mibitem->data;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700244
Moritz Muehlenhoffb1de9672009-02-08 02:20:46 +0100245 if (isget) {
Mithlesh Thukral75f49e02009-05-25 19:06:16 +0530246 if (wlandev->hostwep &
247 HOSTWEP_EXCLUDEUNENCRYPTED)
Moritz Muehlenhoffb1de9672009-02-08 02:20:46 +0100248 *data = P80211ENUM_truth_true;
249 else
250 *data = P80211ENUM_truth_false;
251 } else {
252 wlandev->hostwep &=
253 ~(HOSTWEP_EXCLUDEUNENCRYPTED);
254 if (*data == P80211ENUM_truth_true)
255 wlandev->hostwep |=
256 HOSTWEP_EXCLUDEUNENCRYPTED;
257 }
258 break;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700259 }
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700260 default:
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700261 ;
262 }
263
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700264 return 0;
265}