Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input
[linux-2.6] / drivers / staging / wlan-ng / p80211req.c
1 /* 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
53 /*================================================================*/
54 /* System Includes */
55
56
57
58 #include <linux/module.h>
59 #include <linux/kernel.h>
60 #include <linux/sched.h>
61 #include <linux/types.h>
62 #include <linux/skbuff.h>
63 #include <linux/slab.h>
64 #include <linux/wireless.h>
65 #include <linux/netdevice.h>
66 #include <linux/etherdevice.h>
67 #include <net/sock.h>
68 #include <linux/netlink.h>
69
70 #include "wlan_compat.h"
71
72 /*================================================================*/
73 /* Project Includes */
74
75 #include "p80211types.h"
76 #include "p80211hdr.h"
77 #include "p80211mgmt.h"
78 #include "p80211conv.h"
79 #include "p80211msg.h"
80 #include "p80211netdev.h"
81 #include "p80211ioctl.h"
82 #include "p80211metadef.h"
83 #include "p80211metastruct.h"
84 #include "p80211req.h"
85
86 /*================================================================*/
87 /* Local Constants */
88
89 /* Maximum amount of time we'll wait for a request to complete */
90 #define P80211REQ_MAXTIME       3*HZ    /* 3 seconds */
91
92 /*================================================================*/
93 /* Local Macros */
94
95 /*================================================================*/
96 /* Local Types */
97
98 /*================================================================*/
99 /* Local Static Definitions */
100
101 /*================================================================*/
102 /* Local Function Declarations */
103
104 static void p80211req_handlemsg( wlandevice_t *wlandev, p80211msg_t *msg);
105 static int p80211req_mibset_mibget(wlandevice_t *wlandev, p80211msg_dot11req_mibget_t *mib_msg, int isget);
106
107 /*================================================================*/
108 /* Function Definitions */
109
110
111 /*----------------------------------------------------------------
112 * p80211req_dorequest
113 *
114 * Handles an MLME reqest/confirm message.
115 *
116 * Arguments:
117 *       wlandev         WLAN device struct
118 *       msgbuf          Buffer containing a request message
119 *
120 * Returns:
121 *       0 on success, an errno otherwise
122 *
123 * Call context:
124 *       Potentially blocks the caller, so it's a good idea to
125 *       not call this function from an interrupt context.
126 ----------------------------------------------------------------*/
127 int p80211req_dorequest( wlandevice_t *wlandev, u8 *msgbuf)
128 {
129         int             result = 0;
130         p80211msg_t     *msg = (p80211msg_t*)msgbuf;
131
132         DBFENTER;
133
134         /* Check to make sure the MSD is running */
135         if (
136         !((wlandev->msdstate == WLAN_MSD_HWPRESENT &&
137         msg->msgcode == DIDmsg_lnxreq_ifstate) ||
138         wlandev->msdstate == WLAN_MSD_RUNNING ||
139         wlandev->msdstate == WLAN_MSD_FWLOAD) ) {
140                 return -ENODEV;
141         }
142
143         /* Check Permissions */
144         if (!capable(CAP_NET_ADMIN) &&
145             (msg->msgcode != DIDmsg_dot11req_mibget)) {
146                 WLAN_LOG_ERROR("%s: only dot11req_mibget allowed for non-root.\n", wlandev->name);
147                 return -EPERM;
148         }
149
150         /* Check for busy status */
151         if ( test_and_set_bit(1, &(wlandev->request_pending))) {
152                 return -EBUSY;
153         }
154
155         /* Allow p80211 to look at msg and handle if desired. */
156         /* So far, all p80211 msgs are immediate, no waitq/timer necessary */
157         /* This may change. */
158         p80211req_handlemsg(wlandev, msg);
159
160         /* Pass it down to wlandev via wlandev->mlmerequest */
161         if ( wlandev->mlmerequest != NULL )
162                 wlandev->mlmerequest(wlandev, msg);
163
164         clear_bit( 1, &(wlandev->request_pending));
165         DBFEXIT;
166         return result;  /* if result==0, msg->status still may contain an err */
167 }
168
169 /*----------------------------------------------------------------
170 * p80211req_handlemsg
171 *
172 * p80211 message handler.  Primarily looks for messages that
173 * belong to p80211 and then dispatches the appropriate response.
174 * TODO: we don't do anything yet.  Once the linuxMIB is better
175 *       defined we'll need a get/set handler.
176 *
177 * Arguments:
178 *       wlandev         WLAN device struct
179 *       msg             message structure
180 *
181 * Returns:
182 *       nothing (any results are set in the status field of the msg)
183 *
184 * Call context:
185 *       Process thread
186 ----------------------------------------------------------------*/
187 static void p80211req_handlemsg( wlandevice_t *wlandev, p80211msg_t *msg)
188 {
189         DBFENTER;
190
191         switch (msg->msgcode) {
192
193         case DIDmsg_lnxreq_hostwep: {
194                 p80211msg_lnxreq_hostwep_t *req = (p80211msg_lnxreq_hostwep_t*) msg;
195                 wlandev->hostwep &= ~(HOSTWEP_DECRYPT|HOSTWEP_ENCRYPT);
196                 if (req->decrypt.data == P80211ENUM_truth_true)
197                         wlandev->hostwep |= HOSTWEP_DECRYPT;
198                 if (req->encrypt.data == P80211ENUM_truth_true)
199                         wlandev->hostwep |= HOSTWEP_ENCRYPT;
200
201                 break;
202         }
203         case DIDmsg_dot11req_mibget:
204         case DIDmsg_dot11req_mibset: {
205                 int isget = (msg->msgcode == DIDmsg_dot11req_mibget);
206                 p80211msg_dot11req_mibget_t  *mib_msg = (p80211msg_dot11req_mibget_t *) msg;
207                 p80211req_mibset_mibget (wlandev, mib_msg, isget);
208         }
209         default:
210                 // XXX do nothing!
211                 ;
212         } /* switch msg->msgcode */
213
214         DBFEXIT;
215
216         return;
217 }
218
219 static int p80211req_mibset_mibget(wlandevice_t *wlandev,
220                                    p80211msg_dot11req_mibget_t *mib_msg,
221                                    int isget)
222 {
223         p80211itemd_t   *mibitem = (p80211itemd_t *) mib_msg->mibattribute.data;
224         p80211pstrd_t  *pstr = (p80211pstrd_t*) mibitem->data;
225         u8 *key = mibitem->data + sizeof(p80211pstrd_t);
226
227         DBFENTER;
228
229         switch (mibitem->did) {
230         case DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey0: {
231                 if (!isget)
232                         wep_change_key(wlandev, 0, key, pstr->len);
233                 break;
234         }
235         case DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey1: {
236                 if (!isget)
237                         wep_change_key(wlandev, 1, key, pstr->len);
238                 break;
239         }
240         case DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey2: {
241                 if (!isget)
242                         wep_change_key(wlandev, 2, key, pstr->len);
243                 break;
244         }
245         case DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey3: {
246                 if (!isget)
247                         wep_change_key(wlandev, 3, key, pstr->len);
248                 break;
249         }
250         case DIDmib_dot11smt_dot11PrivacyTable_dot11WEPDefaultKeyID: {
251                 u32 *data = (u32 *) mibitem->data;
252
253                 if (isget) {
254                         *data = wlandev->hostwep & HOSTWEP_DEFAULTKEY_MASK;
255                         } else {
256                                 wlandev->hostwep &= ~(HOSTWEP_DEFAULTKEY_MASK);
257
258                                 wlandev->hostwep |= (*data & HOSTWEP_DEFAULTKEY_MASK);
259                         }
260                 break;
261         }
262         case DIDmib_dot11smt_dot11PrivacyTable_dot11PrivacyInvoked: {
263                 u32 *data = (u32 *) mibitem->data;
264
265                 if (isget) {
266                         if (wlandev->hostwep & HOSTWEP_PRIVACYINVOKED)
267                                 *data = P80211ENUM_truth_true;
268                         else
269                                 *data = P80211ENUM_truth_false;
270                 } else {
271                                 wlandev->hostwep &= ~(HOSTWEP_PRIVACYINVOKED);
272                                 if (*data == P80211ENUM_truth_true)
273                                         wlandev->hostwep |= HOSTWEP_PRIVACYINVOKED;
274                 }
275                 break;
276         }
277         case DIDmib_dot11smt_dot11PrivacyTable_dot11ExcludeUnencrypted: {
278                 u32 *data = (u32 *) mibitem->data;
279
280                 if (isget) {
281                         if (wlandev->hostwep & HOSTWEP_EXCLUDEUNENCRYPTED)
282                                 *data = P80211ENUM_truth_true;
283                         else
284                                 *data = P80211ENUM_truth_false;
285                 } else {
286                         wlandev->hostwep &= ~(HOSTWEP_EXCLUDEUNENCRYPTED);
287                         if (*data == P80211ENUM_truth_true)
288                                 wlandev->hostwep |= HOSTWEP_EXCLUDEUNENCRYPTED;
289                 }
290                 break;
291         }
292         default:
293                 // XXXX do nothing!
294                 ;
295         }
296
297         DBFEXIT;
298         return 0;
299 }
300