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