1 /* SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1) */
2 /*
3  *
4  * WLAN net device structure and functions
5  *
6  * Copyright (C) 1999 AbsoluteValue Systems, Inc.  All Rights Reserved.
7  * --------------------------------------------------------------------
8  *
9  * linux-wlan
10  *
11  *   The contents of this file are subject to the Mozilla Public
12  *   License Version 1.1 (the "License"); you may not use this file
13  *   except in compliance with the License. You may obtain a copy of
14  *   the License at http://www.mozilla.org/MPL/
15  *
16  *   Software distributed under the License is distributed on an "AS
17  *   IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
18  *   implied. See the License for the specific language governing
19  *   rights and limitations under the License.
20  *
21  *   Alternatively, the contents of this file may be used under the
22  *   terms of the GNU Public License version 2 (the "GPL"), in which
23  *   case the provisions of the GPL are applicable instead of the
24  *   above.  If you wish to allow the use of your version of this file
25  *   only under the terms of the GPL and not to allow others to use
26  *   your version of this file under the MPL, indicate your decision
27  *   by deleting the provisions above and replace them with the notice
28  *   and other provisions required by the GPL.  If you do not delete
29  *   the provisions above, a recipient may use your version of this
30  *   file under either the MPL or the GPL.
31  *
32  * --------------------------------------------------------------------
33  *
34  * Inquiries regarding the linux-wlan Open Source project can be
35  * made directly to:
36  *
37  * AbsoluteValue Systems Inc.
38  * info@linux-wlan.com
39  * http://www.linux-wlan.com
40  *
41  * --------------------------------------------------------------------
42  *
43  * Portions of the development of this software were funded by
44  * Intersil Corporation as part of PRISM(R) chipset product development.
45  *
46  * --------------------------------------------------------------------
47  *
48  * This file declares the structure type that represents each wlan
49  * interface.
50  *
51  * --------------------------------------------------------------------
52  */
53 
54 #ifndef _LINUX_P80211NETDEV_H
55 #define _LINUX_P80211NETDEV_H
56 
57 #include <linux/interrupt.h>
58 #include <linux/wireless.h>
59 #include <linux/netdevice.h>
60 
61 #define WLAN_RELEASE	"0.3.0-staging"
62 
63 #define WLAN_DEVICE_CLOSED	0
64 #define WLAN_DEVICE_OPEN	1
65 
66 #define WLAN_MACMODE_NONE	0
67 #define WLAN_MACMODE_IBSS_STA	1
68 #define WLAN_MACMODE_ESS_STA	2
69 #define WLAN_MACMODE_ESS_AP	3
70 
71 /* MSD States */
72 #define WLAN_MSD_HWPRESENT_PENDING	1
73 #define WLAN_MSD_HWFAIL			2
74 #define WLAN_MSD_HWPRESENT		3
75 #define WLAN_MSD_FWLOAD_PENDING		4
76 #define WLAN_MSD_FWLOAD			5
77 #define WLAN_MSD_RUNNING_PENDING	6
78 #define WLAN_MSD_RUNNING		7
79 
80 #ifndef ETH_P_ECONET
81 #define ETH_P_ECONET   0x0018	/* needed for 2.2.x kernels */
82 #endif
83 
84 #define ETH_P_80211_RAW        (ETH_P_ECONET + 1)
85 
86 #ifndef ARPHRD_IEEE80211
87 #define ARPHRD_IEEE80211 801	/* kernel 2.4.6 */
88 #endif
89 
90 #ifndef ARPHRD_IEEE80211_PRISM	/* kernel 2.4.18 */
91 #define ARPHRD_IEEE80211_PRISM 802
92 #endif
93 
94 /*--- NSD Capabilities Flags ------------------------------*/
95 #define P80211_NSDCAP_HARDWAREWEP           0x01  /* hardware wep engine */
96 #define P80211_NSDCAP_SHORT_PREAMBLE        0x10  /* hardware supports */
97 #define P80211_NSDCAP_HWFRAGMENT            0x80  /* nsd handles frag/defrag */
98 #define P80211_NSDCAP_AUTOJOIN              0x100 /* nsd does autojoin */
99 #define P80211_NSDCAP_NOSCAN                0x200 /* nsd can scan */
100 
101 /* Received frame statistics */
102 struct p80211_frmrx {
103 	u32 mgmt;
104 	u32 assocreq;
105 	u32 assocresp;
106 	u32 reassocreq;
107 	u32 reassocresp;
108 	u32 probereq;
109 	u32 proberesp;
110 	u32 beacon;
111 	u32 atim;
112 	u32 disassoc;
113 	u32 authen;
114 	u32 deauthen;
115 	u32 mgmt_unknown;
116 	u32 ctl;
117 	u32 pspoll;
118 	u32 rts;
119 	u32 cts;
120 	u32 ack;
121 	u32 cfend;
122 	u32 cfendcfack;
123 	u32 ctl_unknown;
124 	u32 data;
125 	u32 dataonly;
126 	u32 data_cfack;
127 	u32 data_cfpoll;
128 	u32 data__cfack_cfpoll;
129 	u32 null;
130 	u32 cfack;
131 	u32 cfpoll;
132 	u32 cfack_cfpoll;
133 	u32 data_unknown;
134 	u32 decrypt;
135 	u32 decrypt_err;
136 };
137 
138 /* called by /proc/net/wireless */
139 struct iw_statistics *p80211wext_get_wireless_stats(struct net_device *dev);
140 
141 /* WEP stuff */
142 #define NUM_WEPKEYS 4
143 #define MAX_KEYLEN 32
144 
145 #define HOSTWEP_DEFAULTKEY_MASK GENMASK(1, 0)
146 #define HOSTWEP_SHAREDKEY BIT(3)
147 #define HOSTWEP_DECRYPT  BIT(4)
148 #define HOSTWEP_ENCRYPT  BIT(5)
149 #define HOSTWEP_PRIVACYINVOKED BIT(6)
150 #define HOSTWEP_EXCLUDEUNENCRYPTED BIT(7)
151 
152 extern int wlan_watchdog;
153 extern int wlan_wext_write;
154 
155 /* WLAN device type */
156 struct wlandevice {
157 	void *priv;		/* private data for MSD */
158 
159 	/* Subsystem State */
160 	char name[WLAN_DEVNAMELEN_MAX];	/* Dev name, from register_wlandev() */
161 	char *nsdname;
162 
163 	u32 state;		/* Device I/F state (open/closed) */
164 	u32 msdstate;		/* state of underlying driver */
165 	u32 hwremoved;		/* Has the hw been yanked out? */
166 
167 	/* Hardware config */
168 	unsigned int irq;
169 	unsigned int iobase;
170 	unsigned int membase;
171 	u32 nsdcaps;		/* NSD Capabilities flags */
172 
173 	/* Config vars */
174 	unsigned int ethconv;
175 
176 	/* device methods (init by MSD, used by p80211 */
177 	int (*open)(struct wlandevice *wlandev);
178 	int (*close)(struct wlandevice *wlandev);
179 	void (*reset)(struct wlandevice *wlandev);
180 	int (*txframe)(struct wlandevice *wlandev, struct sk_buff *skb,
181 		       struct p80211_hdr *p80211_hdr,
182 		       struct p80211_metawep *p80211_wep);
183 	int (*mlmerequest)(struct wlandevice *wlandev, struct p80211msg *msg);
184 	int (*set_multicast_list)(struct wlandevice *wlandev,
185 				  struct net_device *dev);
186 	void (*tx_timeout)(struct wlandevice *wlandev);
187 
188 	/* 802.11 State */
189 	u8 bssid[WLAN_BSSID_LEN];
190 	struct p80211pstr32 ssid;
191 	u32 macmode;
192 	int linkstatus;
193 
194 	/* WEP State */
195 	u8 wep_keys[NUM_WEPKEYS][MAX_KEYLEN];
196 	u8 wep_keylens[NUM_WEPKEYS];
197 	int hostwep;
198 
199 	/* Request/Confirm i/f state (used by p80211) */
200 	unsigned long request_pending;	/* flag, access atomically */
201 
202 	/* netlink socket */
203 	/* queue for indications waiting for cmd completion */
204 	/* Linux netdevice and support */
205 	struct net_device *netdev;	/* ptr to linux netdevice */
206 
207 	/* Rx bottom half */
208 	struct tasklet_struct rx_bh;
209 
210 	struct sk_buff_head nsd_rxq;
211 
212 	/* 802.11 device statistics */
213 	struct p80211_frmrx rx;
214 
215 	struct iw_statistics wstats;
216 
217 	/* jkriegl: iwspy fields */
218 	u8 spy_number;
219 	char spy_address[IW_MAX_SPY][ETH_ALEN];
220 	struct iw_quality spy_stat[IW_MAX_SPY];
221 };
222 
223 /* WEP stuff */
224 int wep_change_key(struct wlandevice *wlandev, int keynum, u8 *key, int keylen);
225 int wep_decrypt(struct wlandevice *wlandev, u8 *buf, u32 len, int key_override,
226 		u8 *iv, u8 *icv);
227 int wep_encrypt(struct wlandevice *wlandev, u8 *buf, u8 *dst, u32 len,
228 		int keynum, u8 *iv, u8 *icv);
229 
230 int wlan_setup(struct wlandevice *wlandev, struct device *physdev);
231 void wlan_unsetup(struct wlandevice *wlandev);
232 int register_wlandev(struct wlandevice *wlandev);
233 int unregister_wlandev(struct wlandevice *wlandev);
234 void p80211netdev_rx(struct wlandevice *wlandev, struct sk_buff *skb);
235 void p80211netdev_hwremoved(struct wlandevice *wlandev);
236 #endif
237