Linux Audio

Check our new training course

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