blob: d43e85b5d49b6cc75d267895f226c55a89666a60 [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
sayli karnikc9573a82016-09-18 15:11:14 +053075static void p80211req_handlemsg(struct wlandevice *wlandev, struct p80211msg *msg);
76static void p80211req_mibset_mibget(struct wlandevice *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
Claudiu Beznea2f479122016-08-25 20:03:25 +030080static void p80211req_handle_action(struct wlandevice *wlandev, u32 *data,
81 int isget, u32 flag)
82{
83 if (isget) {
84 if (wlandev->hostwep & flag)
85 *data = P80211ENUM_truth_true;
86 else
87 *data = P80211ENUM_truth_false;
88 } else {
89 wlandev->hostwep &= ~flag;
90 if (*data == P80211ENUM_truth_true)
91 wlandev->hostwep |= flag;
92 }
93}
94
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -070095/*----------------------------------------------------------------
96* p80211req_dorequest
97*
Masanari Iida1a6dfce2014-12-01 00:29:00 +090098* Handles an MLME request/confirm message.
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -070099*
100* Arguments:
101* wlandev WLAN device struct
102* msgbuf Buffer containing a request message
103*
104* Returns:
105* 0 on success, an errno otherwise
106*
107* Call context:
108* Potentially blocks the caller, so it's a good idea to
109* not call this function from an interrupt context.
110----------------------------------------------------------------*/
sayli karnikc9573a82016-09-18 15:11:14 +0530111int p80211req_dorequest(struct wlandevice *wlandev, u8 *msgbuf)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700112{
Jannik Becher0e21fa42016-09-23 01:02:10 +0200113 struct p80211msg *msg = (struct p80211msg *)msgbuf;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700114
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700115 /* Check to make sure the MSD is running */
Moritz Muehlenhoffb1de9672009-02-08 02:20:46 +0100116 if (!((wlandev->msdstate == WLAN_MSD_HWPRESENT &&
117 msg->msgcode == DIDmsg_lnxreq_ifstate) ||
118 wlandev->msdstate == WLAN_MSD_RUNNING ||
119 wlandev->msdstate == WLAN_MSD_FWLOAD)) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700120 return -ENODEV;
121 }
122
123 /* Check Permissions */
Patrick Rooney67a7b372010-03-10 08:46:30 +0000124 if (!capable(CAP_NET_ADMIN) &&
125 (msg->msgcode != DIDmsg_dot11req_mibget)) {
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +1000126 netdev_err(wlandev->netdev,
127 "%s: only dot11req_mibget allowed for non-root.\n",
128 wlandev->name);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700129 return -EPERM;
130 }
131
132 /* Check for busy status */
Moritz Muehlenhoffb1de9672009-02-08 02:20:46 +0100133 if (test_and_set_bit(1, &(wlandev->request_pending)))
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700134 return -EBUSY;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700135
136 /* Allow p80211 to look at msg and handle if desired. */
137 /* So far, all p80211 msgs are immediate, no waitq/timer necessary */
138 /* This may change. */
139 p80211req_handlemsg(wlandev, msg);
140
141 /* Pass it down to wlandev via wlandev->mlmerequest */
Moritz Muehlenhoffb1de9672009-02-08 02:20:46 +0100142 if (wlandev->mlmerequest != NULL)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700143 wlandev->mlmerequest(wlandev, msg);
144
Moritz Muehlenhoffb1de9672009-02-08 02:20:46 +0100145 clear_bit(1, &(wlandev->request_pending));
Peter Senna Tschudin4764ca92014-05-26 16:08:50 +0200146 return 0; /* if result==0, msg->status still may contain an err */
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700147}
148
149/*----------------------------------------------------------------
150* p80211req_handlemsg
151*
152* p80211 message handler. Primarily looks for messages that
153* belong to p80211 and then dispatches the appropriate response.
154* TODO: we don't do anything yet. Once the linuxMIB is better
155* defined we'll need a get/set handler.
156*
157* Arguments:
158* wlandev WLAN device struct
159* msg message structure
160*
161* Returns:
162* nothing (any results are set in the status field of the msg)
163*
164* Call context:
165* Process thread
166----------------------------------------------------------------*/
sayli karnikc9573a82016-09-18 15:11:14 +0530167static void p80211req_handlemsg(struct wlandevice *wlandev, struct p80211msg *msg)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700168{
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700169 switch (msg->msgcode) {
170
Moritz Muehlenhoffb1de9672009-02-08 02:20:46 +0100171 case DIDmsg_lnxreq_hostwep:{
Devendra Naga009629e2012-09-09 18:40:56 +0530172 struct p80211msg_lnxreq_hostwep *req =
Jannik Becher0e21fa42016-09-23 01:02:10 +0200173 (struct p80211msg_lnxreq_hostwep *)msg;
Devendra Naga009629e2012-09-09 18:40:56 +0530174 wlandev->hostwep &=
175 ~(HOSTWEP_DECRYPT | HOSTWEP_ENCRYPT);
176 if (req->decrypt.data == P80211ENUM_truth_true)
177 wlandev->hostwep |= HOSTWEP_DECRYPT;
178 if (req->encrypt.data == P80211ENUM_truth_true)
179 wlandev->hostwep |= HOSTWEP_ENCRYPT;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700180
Devendra Naga009629e2012-09-09 18:40:56 +0530181 break;
182 }
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700183 case DIDmsg_dot11req_mibget:
Moritz Muehlenhoffb1de9672009-02-08 02:20:46 +0100184 case DIDmsg_dot11req_mibset:{
Devendra Naga009629e2012-09-09 18:40:56 +0530185 int isget = (msg->msgcode == DIDmsg_dot11req_mibget);
186 struct p80211msg_dot11req_mibget *mib_msg =
Jannik Becher0e21fa42016-09-23 01:02:10 +0200187 (struct p80211msg_dot11req_mibget *)msg;
Devendra Naga009629e2012-09-09 18:40:56 +0530188 p80211req_mibset_mibget(wlandev, mib_msg, isget);
189 break;
190 }
Moritz Muehlenhoffb1de9672009-02-08 02:20:46 +0100191 } /* switch msg->msgcode */
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700192}
193
sayli karnikc9573a82016-09-18 15:11:14 +0530194static void p80211req_mibset_mibget(struct wlandevice *wlandev,
Edgardo Hamesb6bb56e2010-08-02 16:20:39 -0300195 struct p80211msg_dot11req_mibget *mib_msg,
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700196 int isget)
197{
Sergio Paracuellosac033ec2016-09-25 15:34:59 +0200198 struct p80211itemd *mibitem = (struct p80211itemd *)mib_msg->mibattribute.data;
Sergio Paracuellos3fd1e3f2016-09-25 15:34:52 +0200199 struct p80211pstrd *pstr = (struct p80211pstrd *)mibitem->data;
200 u8 *key = mibitem->data + sizeof(struct p80211pstrd);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700201
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700202 switch (mibitem->did) {
Claudiu Beznea152f0442016-09-04 20:52:17 +0300203 case DIDmib_dot11smt_dot11WEPDefaultKeysTable_key(1):
Claudiu Beznea41e9b842016-09-04 20:52:18 +0300204 case DIDmib_dot11smt_dot11WEPDefaultKeysTable_key(2):
Claudiu Beznea8d3a2252016-09-04 20:52:19 +0300205 case DIDmib_dot11smt_dot11WEPDefaultKeysTable_key(3):
Claudiu Beznea17d9ff122016-09-04 20:52:20 +0300206 case DIDmib_dot11smt_dot11WEPDefaultKeysTable_key(4):
Devendra Naga76945382012-09-09 18:40:58 +0530207 if (!isget)
Claudiu Beznea37f92cf2016-08-23 21:26:42 +0300208 wep_change_key(wlandev,
209 P80211DID_ITEM(mibitem->did) - 1,
210 key, pstr->len);
211 break;
212
Moritz Muehlenhoffb1de9672009-02-08 02:20:46 +0100213 case DIDmib_dot11smt_dot11PrivacyTable_dot11WEPDefaultKeyID:{
Jannik Becher0e21fa42016-09-23 01:02:10 +0200214 u32 *data = (u32 *)mibitem->data;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700215
Devendra Naga76945382012-09-09 18:40:58 +0530216 if (isget) {
217 *data = wlandev->hostwep & HOSTWEP_DEFAULTKEY_MASK;
218 } else {
219 wlandev->hostwep &= ~(HOSTWEP_DEFAULTKEY_MASK);
220 wlandev->hostwep |= (*data & HOSTWEP_DEFAULTKEY_MASK);
Moritz Muehlenhoffb1de9672009-02-08 02:20:46 +0100221 }
Devendra Naga76945382012-09-09 18:40:58 +0530222 break;
223 }
Moritz Muehlenhoffb1de9672009-02-08 02:20:46 +0100224 case DIDmib_dot11smt_dot11PrivacyTable_dot11PrivacyInvoked:{
Jannik Becher0e21fa42016-09-23 01:02:10 +0200225 u32 *data = (u32 *)mibitem->data;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700226
Claudiu Beznea2f479122016-08-25 20:03:25 +0300227 p80211req_handle_action(wlandev, data, isget,
228 HOSTWEP_PRIVACYINVOKED);
Devendra Naga76945382012-09-09 18:40:58 +0530229 break;
230 }
Moritz Muehlenhoffb1de9672009-02-08 02:20:46 +0100231 case DIDmib_dot11smt_dot11PrivacyTable_dot11ExcludeUnencrypted:{
Jannik Becher0e21fa42016-09-23 01:02:10 +0200232 u32 *data = (u32 *)mibitem->data;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700233
Claudiu Beznea2f479122016-08-25 20:03:25 +0300234 p80211req_handle_action(wlandev, data, isget,
235 HOSTWEP_EXCLUDEUNENCRYPTED);
Devendra Naga76945382012-09-09 18:40:58 +0530236 break;
237 }
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700238 }
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700239}