1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * This file define the new driver API for Wireless Extensions
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * Version : 8 16.3.07
6*4882a593Smuzhiyun *
7*4882a593Smuzhiyun * Authors : Jean Tourrilhes - HPL - <jt@hpl.hp.com>
8*4882a593Smuzhiyun * Copyright (c) 2001-2007 Jean Tourrilhes, All Rights Reserved.
9*4882a593Smuzhiyun */
10*4882a593Smuzhiyun
11*4882a593Smuzhiyun #ifndef _IW_HANDLER_H
12*4882a593Smuzhiyun #define _IW_HANDLER_H
13*4882a593Smuzhiyun
14*4882a593Smuzhiyun /************************** DOCUMENTATION **************************/
15*4882a593Smuzhiyun /*
16*4882a593Smuzhiyun * Initial driver API (1996 -> onward) :
17*4882a593Smuzhiyun * -----------------------------------
18*4882a593Smuzhiyun * The initial API just sends the IOCTL request received from user space
19*4882a593Smuzhiyun * to the driver (via the driver ioctl handler). The driver has to
20*4882a593Smuzhiyun * handle all the rest...
21*4882a593Smuzhiyun *
22*4882a593Smuzhiyun * The initial API also defines a specific handler in struct net_device
23*4882a593Smuzhiyun * to handle wireless statistics.
24*4882a593Smuzhiyun *
25*4882a593Smuzhiyun * The initial APIs served us well and has proven a reasonably good design.
26*4882a593Smuzhiyun * However, there is a few shortcommings :
27*4882a593Smuzhiyun * o No events, everything is a request to the driver.
28*4882a593Smuzhiyun * o Large ioctl function in driver with gigantic switch statement
29*4882a593Smuzhiyun * (i.e. spaghetti code).
30*4882a593Smuzhiyun * o Driver has to mess up with copy_to/from_user, and in many cases
31*4882a593Smuzhiyun * does it unproperly. Common mistakes are :
32*4882a593Smuzhiyun * * buffer overflows (no checks or off by one checks)
33*4882a593Smuzhiyun * * call copy_to/from_user with irq disabled
34*4882a593Smuzhiyun * o The user space interface is tied to ioctl because of the use
35*4882a593Smuzhiyun * copy_to/from_user.
36*4882a593Smuzhiyun *
37*4882a593Smuzhiyun * New driver API (2002 -> onward) :
38*4882a593Smuzhiyun * -------------------------------
39*4882a593Smuzhiyun * The new driver API is just a bunch of standard functions (handlers),
40*4882a593Smuzhiyun * each handling a specific Wireless Extension. The driver just export
41*4882a593Smuzhiyun * the list of handler it supports, and those will be called apropriately.
42*4882a593Smuzhiyun *
43*4882a593Smuzhiyun * I tried to keep the main advantage of the previous API (simplicity,
44*4882a593Smuzhiyun * efficiency and light weight), and also I provide a good dose of backward
45*4882a593Smuzhiyun * compatibility (most structures are the same, driver can use both API
46*4882a593Smuzhiyun * simultaneously, ...).
47*4882a593Smuzhiyun * Hopefully, I've also addressed the shortcomming of the initial API.
48*4882a593Smuzhiyun *
49*4882a593Smuzhiyun * The advantage of the new API are :
50*4882a593Smuzhiyun * o Handling of Extensions in driver broken in small contained functions
51*4882a593Smuzhiyun * o Tighter checks of ioctl before calling the driver
52*4882a593Smuzhiyun * o Flexible commit strategy (at least, the start of it)
53*4882a593Smuzhiyun * o Backward compatibility (can be mixed with old API)
54*4882a593Smuzhiyun * o Driver doesn't have to worry about memory and user-space issues
55*4882a593Smuzhiyun * The last point is important for the following reasons :
56*4882a593Smuzhiyun * o You are now able to call the new driver API from any API you
57*4882a593Smuzhiyun * want (including from within other parts of the kernel).
58*4882a593Smuzhiyun * o Common mistakes are avoided (buffer overflow, user space copy
59*4882a593Smuzhiyun * with irq disabled and so on).
60*4882a593Smuzhiyun *
61*4882a593Smuzhiyun * The Drawback of the new API are :
62*4882a593Smuzhiyun * o bloat (especially kernel)
63*4882a593Smuzhiyun * o need to migrate existing drivers to new API
64*4882a593Smuzhiyun * My initial testing shows that the new API adds around 3kB to the kernel
65*4882a593Smuzhiyun * and save between 0 and 5kB from a typical driver.
66*4882a593Smuzhiyun * Also, as all structures and data types are unchanged, the migration is
67*4882a593Smuzhiyun * quite straightforward (but tedious).
68*4882a593Smuzhiyun *
69*4882a593Smuzhiyun * ---
70*4882a593Smuzhiyun *
71*4882a593Smuzhiyun * The new driver API is defined below in this file. User space should
72*4882a593Smuzhiyun * not be aware of what's happening down there...
73*4882a593Smuzhiyun *
74*4882a593Smuzhiyun * A new kernel wrapper is in charge of validating the IOCTLs and calling
75*4882a593Smuzhiyun * the appropriate driver handler. This is implemented in :
76*4882a593Smuzhiyun * # net/core/wireless.c
77*4882a593Smuzhiyun *
78*4882a593Smuzhiyun * The driver export the list of handlers in :
79*4882a593Smuzhiyun * # include/linux/netdevice.h (one place)
80*4882a593Smuzhiyun *
81*4882a593Smuzhiyun * The new driver API is available for WIRELESS_EXT >= 13.
82*4882a593Smuzhiyun * Good luck with migration to the new API ;-)
83*4882a593Smuzhiyun */
84*4882a593Smuzhiyun
85*4882a593Smuzhiyun /* ---------------------- THE IMPLEMENTATION ---------------------- */
86*4882a593Smuzhiyun /*
87*4882a593Smuzhiyun * Some of the choice I've made are pretty controversials. Defining an
88*4882a593Smuzhiyun * API is very much weighting compromises. This goes into some of the
89*4882a593Smuzhiyun * details and the thinking behind the implementation.
90*4882a593Smuzhiyun *
91*4882a593Smuzhiyun * Implementation goals :
92*4882a593Smuzhiyun * --------------------
93*4882a593Smuzhiyun * The implementation goals were as follow :
94*4882a593Smuzhiyun * o Obvious : you should not need a PhD to understand what's happening,
95*4882a593Smuzhiyun * the benefit is easier maintenance.
96*4882a593Smuzhiyun * o Flexible : it should accommodate a wide variety of driver
97*4882a593Smuzhiyun * implementations and be as flexible as the old API.
98*4882a593Smuzhiyun * o Lean : it should be efficient memory wise to minimise the impact
99*4882a593Smuzhiyun * on kernel footprint.
100*4882a593Smuzhiyun * o Transparent to user space : the large number of user space
101*4882a593Smuzhiyun * applications that use Wireless Extensions should not need
102*4882a593Smuzhiyun * any modifications.
103*4882a593Smuzhiyun *
104*4882a593Smuzhiyun * Array of functions versus Struct of functions
105*4882a593Smuzhiyun * ---------------------------------------------
106*4882a593Smuzhiyun * 1) Having an array of functions allow the kernel code to access the
107*4882a593Smuzhiyun * handler in a single lookup, which is much more efficient (think hash
108*4882a593Smuzhiyun * table here).
109*4882a593Smuzhiyun * 2) The only drawback is that driver writer may put their handler in
110*4882a593Smuzhiyun * the wrong slot. This is trivial to test (I set the frequency, the
111*4882a593Smuzhiyun * bitrate changes). Once the handler is in the proper slot, it will be
112*4882a593Smuzhiyun * there forever, because the array is only extended at the end.
113*4882a593Smuzhiyun * 3) Backward/forward compatibility : adding new handler just require
114*4882a593Smuzhiyun * extending the array, so you can put newer driver in older kernel
115*4882a593Smuzhiyun * without having to patch the kernel code (and vice versa).
116*4882a593Smuzhiyun *
117*4882a593Smuzhiyun * All handler are of the same generic type
118*4882a593Smuzhiyun * ----------------------------------------
119*4882a593Smuzhiyun * That's a feature !!!
120*4882a593Smuzhiyun * 1) Having a generic handler allow to have generic code, which is more
121*4882a593Smuzhiyun * efficient. If each of the handler was individually typed I would need
122*4882a593Smuzhiyun * to add a big switch in the kernel (== more bloat). This solution is
123*4882a593Smuzhiyun * more scalable, adding new Wireless Extensions doesn't add new code.
124*4882a593Smuzhiyun * 2) You can use the same handler in different slots of the array. For
125*4882a593Smuzhiyun * hardware, it may be more efficient or logical to handle multiple
126*4882a593Smuzhiyun * Wireless Extensions with a single function, and the API allow you to
127*4882a593Smuzhiyun * do that. (An example would be a single record on the card to control
128*4882a593Smuzhiyun * both bitrate and frequency, the handler would read the old record,
129*4882a593Smuzhiyun * modify it according to info->cmd and rewrite it).
130*4882a593Smuzhiyun *
131*4882a593Smuzhiyun * Functions prototype uses union iwreq_data
132*4882a593Smuzhiyun * -----------------------------------------
133*4882a593Smuzhiyun * Some would have preferred functions defined this way :
134*4882a593Smuzhiyun * static int mydriver_ioctl_setrate(struct net_device *dev,
135*4882a593Smuzhiyun * long rate, int auto)
136*4882a593Smuzhiyun * 1) The kernel code doesn't "validate" the content of iwreq_data, and
137*4882a593Smuzhiyun * can't do it (different hardware may have different notion of what a
138*4882a593Smuzhiyun * valid frequency is), so we don't pretend that we do it.
139*4882a593Smuzhiyun * 2) The above form is not extendable. If I want to add a flag (for
140*4882a593Smuzhiyun * example to distinguish setting max rate and basic rate), I would
141*4882a593Smuzhiyun * break the prototype. Using iwreq_data is more flexible.
142*4882a593Smuzhiyun * 3) Also, the above form is not generic (see above).
143*4882a593Smuzhiyun * 4) I don't expect driver developper using the wrong field of the
144*4882a593Smuzhiyun * union (Doh !), so static typechecking doesn't add much value.
145*4882a593Smuzhiyun * 5) Lastly, you can skip the union by doing :
146*4882a593Smuzhiyun * static int mydriver_ioctl_setrate(struct net_device *dev,
147*4882a593Smuzhiyun * struct iw_request_info *info,
148*4882a593Smuzhiyun * struct iw_param *rrq,
149*4882a593Smuzhiyun * char *extra)
150*4882a593Smuzhiyun * And then adding the handler in the array like this :
151*4882a593Smuzhiyun * (iw_handler) mydriver_ioctl_setrate, // SIOCSIWRATE
152*4882a593Smuzhiyun *
153*4882a593Smuzhiyun * Using functions and not a registry
154*4882a593Smuzhiyun * ----------------------------------
155*4882a593Smuzhiyun * Another implementation option would have been for every instance to
156*4882a593Smuzhiyun * define a registry (a struct containing all the Wireless Extensions)
157*4882a593Smuzhiyun * and only have a function to commit the registry to the hardware.
158*4882a593Smuzhiyun * 1) This approach can be emulated by the current code, but not
159*4882a593Smuzhiyun * vice versa.
160*4882a593Smuzhiyun * 2) Some drivers don't keep any configuration in the driver, for them
161*4882a593Smuzhiyun * adding such a registry would be a significant bloat.
162*4882a593Smuzhiyun * 3) The code to translate from Wireless Extension to native format is
163*4882a593Smuzhiyun * needed anyway, so it would not reduce significantely the amount of code.
164*4882a593Smuzhiyun * 4) The current approach only selectively translate Wireless Extensions
165*4882a593Smuzhiyun * to native format and only selectively set, whereas the registry approach
166*4882a593Smuzhiyun * would require to translate all WE and set all parameters for any single
167*4882a593Smuzhiyun * change.
168*4882a593Smuzhiyun * 5) For many Wireless Extensions, the GET operation return the current
169*4882a593Smuzhiyun * dynamic value, not the value that was set.
170*4882a593Smuzhiyun *
171*4882a593Smuzhiyun * This header is <net/iw_handler.h>
172*4882a593Smuzhiyun * ---------------------------------
173*4882a593Smuzhiyun * 1) This header is kernel space only and should not be exported to
174*4882a593Smuzhiyun * user space. Headers in "include/linux/" are exported, headers in
175*4882a593Smuzhiyun * "include/net/" are not.
176*4882a593Smuzhiyun *
177*4882a593Smuzhiyun * Mixed 32/64 bit issues
178*4882a593Smuzhiyun * ----------------------
179*4882a593Smuzhiyun * The Wireless Extensions are designed to be 64 bit clean, by using only
180*4882a593Smuzhiyun * datatypes with explicit storage size.
181*4882a593Smuzhiyun * There are some issues related to kernel and user space using different
182*4882a593Smuzhiyun * memory model, and in particular 64bit kernel with 32bit user space.
183*4882a593Smuzhiyun * The problem is related to struct iw_point, that contains a pointer
184*4882a593Smuzhiyun * that *may* need to be translated.
185*4882a593Smuzhiyun * This is quite messy. The new API doesn't solve this problem (it can't),
186*4882a593Smuzhiyun * but is a step in the right direction :
187*4882a593Smuzhiyun * 1) Meta data about each ioctl is easily available, so we know what type
188*4882a593Smuzhiyun * of translation is needed.
189*4882a593Smuzhiyun * 2) The move of data between kernel and user space is only done in a single
190*4882a593Smuzhiyun * place in the kernel, so adding specific hooks in there is possible.
191*4882a593Smuzhiyun * 3) In the long term, it allows to move away from using ioctl as the
192*4882a593Smuzhiyun * user space API.
193*4882a593Smuzhiyun *
194*4882a593Smuzhiyun * So many comments and so few code
195*4882a593Smuzhiyun * --------------------------------
196*4882a593Smuzhiyun * That's a feature. Comments won't bloat the resulting kernel binary.
197*4882a593Smuzhiyun */
198*4882a593Smuzhiyun
199*4882a593Smuzhiyun /***************************** INCLUDES *****************************/
200*4882a593Smuzhiyun
201*4882a593Smuzhiyun #include <linux/wireless.h> /* IOCTL user space API */
202*4882a593Smuzhiyun #include <linux/if_ether.h>
203*4882a593Smuzhiyun
204*4882a593Smuzhiyun /***************************** VERSION *****************************/
205*4882a593Smuzhiyun /*
206*4882a593Smuzhiyun * This constant is used to know which version of the driver API is
207*4882a593Smuzhiyun * available. Hopefully, this will be pretty stable and no changes
208*4882a593Smuzhiyun * will be needed...
209*4882a593Smuzhiyun * I just plan to increment with each new version.
210*4882a593Smuzhiyun */
211*4882a593Smuzhiyun #define IW_HANDLER_VERSION 8
212*4882a593Smuzhiyun
213*4882a593Smuzhiyun /*
214*4882a593Smuzhiyun * Changes :
215*4882a593Smuzhiyun *
216*4882a593Smuzhiyun * V2 to V3
217*4882a593Smuzhiyun * --------
218*4882a593Smuzhiyun * - Move event definition in <linux/wireless.h>
219*4882a593Smuzhiyun * - Add Wireless Event support :
220*4882a593Smuzhiyun * o wireless_send_event() prototype
221*4882a593Smuzhiyun * o iwe_stream_add_event/point() inline functions
222*4882a593Smuzhiyun * V3 to V4
223*4882a593Smuzhiyun * --------
224*4882a593Smuzhiyun * - Reshuffle IW_HEADER_TYPE_XXX to map IW_PRIV_TYPE_XXX changes
225*4882a593Smuzhiyun *
226*4882a593Smuzhiyun * V4 to V5
227*4882a593Smuzhiyun * --------
228*4882a593Smuzhiyun * - Add new spy support : struct iw_spy_data & prototypes
229*4882a593Smuzhiyun *
230*4882a593Smuzhiyun * V5 to V6
231*4882a593Smuzhiyun * --------
232*4882a593Smuzhiyun * - Change the way we get to spy_data method for added safety
233*4882a593Smuzhiyun * - Remove spy #ifdef, they are always on -> cleaner code
234*4882a593Smuzhiyun * - Add IW_DESCR_FLAG_NOMAX flag for very large requests
235*4882a593Smuzhiyun * - Start migrating get_wireless_stats to struct iw_handler_def
236*4882a593Smuzhiyun *
237*4882a593Smuzhiyun * V6 to V7
238*4882a593Smuzhiyun * --------
239*4882a593Smuzhiyun * - Add struct ieee80211_device pointer in struct iw_public_data
240*4882a593Smuzhiyun * - Remove (struct iw_point *)->pointer from events and streams
241*4882a593Smuzhiyun * - Remove spy_offset from struct iw_handler_def
242*4882a593Smuzhiyun * - Add "check" version of event macros for ieee802.11 stack
243*4882a593Smuzhiyun *
244*4882a593Smuzhiyun * V7 to V8
245*4882a593Smuzhiyun * ----------
246*4882a593Smuzhiyun * - Prevent leaking of kernel space in stream on 64 bits.
247*4882a593Smuzhiyun */
248*4882a593Smuzhiyun
249*4882a593Smuzhiyun /**************************** CONSTANTS ****************************/
250*4882a593Smuzhiyun
251*4882a593Smuzhiyun /* Enhanced spy support available */
252*4882a593Smuzhiyun #define IW_WIRELESS_SPY
253*4882a593Smuzhiyun #define IW_WIRELESS_THRSPY
254*4882a593Smuzhiyun
255*4882a593Smuzhiyun /* Special error message for the driver to indicate that we
256*4882a593Smuzhiyun * should do a commit after return from the iw_handler */
257*4882a593Smuzhiyun #define EIWCOMMIT EINPROGRESS
258*4882a593Smuzhiyun
259*4882a593Smuzhiyun /* Flags available in struct iw_request_info */
260*4882a593Smuzhiyun #define IW_REQUEST_FLAG_COMPAT 0x0001 /* Compat ioctl call */
261*4882a593Smuzhiyun
262*4882a593Smuzhiyun /* Type of headers we know about (basically union iwreq_data) */
263*4882a593Smuzhiyun #define IW_HEADER_TYPE_NULL 0 /* Not available */
264*4882a593Smuzhiyun #define IW_HEADER_TYPE_CHAR 2 /* char [IFNAMSIZ] */
265*4882a593Smuzhiyun #define IW_HEADER_TYPE_UINT 4 /* __u32 */
266*4882a593Smuzhiyun #define IW_HEADER_TYPE_FREQ 5 /* struct iw_freq */
267*4882a593Smuzhiyun #define IW_HEADER_TYPE_ADDR 6 /* struct sockaddr */
268*4882a593Smuzhiyun #define IW_HEADER_TYPE_POINT 8 /* struct iw_point */
269*4882a593Smuzhiyun #define IW_HEADER_TYPE_PARAM 9 /* struct iw_param */
270*4882a593Smuzhiyun #define IW_HEADER_TYPE_QUAL 10 /* struct iw_quality */
271*4882a593Smuzhiyun
272*4882a593Smuzhiyun /* Handling flags */
273*4882a593Smuzhiyun /* Most are not implemented. I just use them as a reminder of some
274*4882a593Smuzhiyun * cool features we might need one day ;-) */
275*4882a593Smuzhiyun #define IW_DESCR_FLAG_NONE 0x0000 /* Obvious */
276*4882a593Smuzhiyun /* Wrapper level flags */
277*4882a593Smuzhiyun #define IW_DESCR_FLAG_DUMP 0x0001 /* Not part of the dump command */
278*4882a593Smuzhiyun #define IW_DESCR_FLAG_EVENT 0x0002 /* Generate an event on SET */
279*4882a593Smuzhiyun #define IW_DESCR_FLAG_RESTRICT 0x0004 /* GET : request is ROOT only */
280*4882a593Smuzhiyun /* SET : Omit payload from generated iwevent */
281*4882a593Smuzhiyun #define IW_DESCR_FLAG_NOMAX 0x0008 /* GET : no limit on request size */
282*4882a593Smuzhiyun /* Driver level flags */
283*4882a593Smuzhiyun #define IW_DESCR_FLAG_WAIT 0x0100 /* Wait for driver event */
284*4882a593Smuzhiyun
285*4882a593Smuzhiyun /****************************** TYPES ******************************/
286*4882a593Smuzhiyun
287*4882a593Smuzhiyun /* ----------------------- WIRELESS HANDLER ----------------------- */
288*4882a593Smuzhiyun /*
289*4882a593Smuzhiyun * A wireless handler is just a standard function, that looks like the
290*4882a593Smuzhiyun * ioctl handler.
291*4882a593Smuzhiyun * We also define there how a handler list look like... As the Wireless
292*4882a593Smuzhiyun * Extension space is quite dense, we use a simple array, which is faster
293*4882a593Smuzhiyun * (that's the perfect hash table ;-).
294*4882a593Smuzhiyun */
295*4882a593Smuzhiyun
296*4882a593Smuzhiyun /*
297*4882a593Smuzhiyun * Meta data about the request passed to the iw_handler.
298*4882a593Smuzhiyun * Most handlers can safely ignore what's in there.
299*4882a593Smuzhiyun * The 'cmd' field might come handy if you want to use the same handler
300*4882a593Smuzhiyun * for multiple command...
301*4882a593Smuzhiyun * This struct is also my long term insurance. I can add new fields here
302*4882a593Smuzhiyun * without breaking the prototype of iw_handler...
303*4882a593Smuzhiyun */
304*4882a593Smuzhiyun struct iw_request_info {
305*4882a593Smuzhiyun __u16 cmd; /* Wireless Extension command */
306*4882a593Smuzhiyun __u16 flags; /* More to come ;-) */
307*4882a593Smuzhiyun };
308*4882a593Smuzhiyun
309*4882a593Smuzhiyun struct net_device;
310*4882a593Smuzhiyun
311*4882a593Smuzhiyun /*
312*4882a593Smuzhiyun * This is how a function handling a Wireless Extension should look
313*4882a593Smuzhiyun * like (both get and set, standard and private).
314*4882a593Smuzhiyun */
315*4882a593Smuzhiyun typedef int (*iw_handler)(struct net_device *dev, struct iw_request_info *info,
316*4882a593Smuzhiyun union iwreq_data *wrqu, char *extra);
317*4882a593Smuzhiyun
318*4882a593Smuzhiyun /*
319*4882a593Smuzhiyun * This define all the handler that the driver export.
320*4882a593Smuzhiyun * As you need only one per driver type, please use a static const
321*4882a593Smuzhiyun * shared by all driver instances... Same for the members...
322*4882a593Smuzhiyun * This will be linked from net_device in <linux/netdevice.h>
323*4882a593Smuzhiyun */
324*4882a593Smuzhiyun struct iw_handler_def {
325*4882a593Smuzhiyun
326*4882a593Smuzhiyun /* Array of handlers for standard ioctls
327*4882a593Smuzhiyun * We will call dev->wireless_handlers->standard[ioctl - SIOCIWFIRST]
328*4882a593Smuzhiyun */
329*4882a593Smuzhiyun const iw_handler * standard;
330*4882a593Smuzhiyun /* Number of handlers defined (more precisely, index of the
331*4882a593Smuzhiyun * last defined handler + 1) */
332*4882a593Smuzhiyun __u16 num_standard;
333*4882a593Smuzhiyun
334*4882a593Smuzhiyun #ifdef CONFIG_WEXT_PRIV
335*4882a593Smuzhiyun __u16 num_private;
336*4882a593Smuzhiyun /* Number of private arg description */
337*4882a593Smuzhiyun __u16 num_private_args;
338*4882a593Smuzhiyun /* Array of handlers for private ioctls
339*4882a593Smuzhiyun * Will call dev->wireless_handlers->private[ioctl - SIOCIWFIRSTPRIV]
340*4882a593Smuzhiyun */
341*4882a593Smuzhiyun const iw_handler * private;
342*4882a593Smuzhiyun
343*4882a593Smuzhiyun /* Arguments of private handler. This one is just a list, so you
344*4882a593Smuzhiyun * can put it in any order you want and should not leave holes...
345*4882a593Smuzhiyun * We will automatically export that to user space... */
346*4882a593Smuzhiyun const struct iw_priv_args * private_args;
347*4882a593Smuzhiyun #endif
348*4882a593Smuzhiyun
349*4882a593Smuzhiyun /* New location of get_wireless_stats, to de-bloat struct net_device.
350*4882a593Smuzhiyun * The old pointer in struct net_device will be gradually phased
351*4882a593Smuzhiyun * out, and drivers are encouraged to use this one... */
352*4882a593Smuzhiyun struct iw_statistics* (*get_wireless_stats)(struct net_device *dev);
353*4882a593Smuzhiyun };
354*4882a593Smuzhiyun
355*4882a593Smuzhiyun /* ---------------------- IOCTL DESCRIPTION ---------------------- */
356*4882a593Smuzhiyun /*
357*4882a593Smuzhiyun * One of the main goal of the new interface is to deal entirely with
358*4882a593Smuzhiyun * user space/kernel space memory move.
359*4882a593Smuzhiyun * For that, we need to know :
360*4882a593Smuzhiyun * o if iwreq is a pointer or contain the full data
361*4882a593Smuzhiyun * o what is the size of the data to copy
362*4882a593Smuzhiyun *
363*4882a593Smuzhiyun * For private IOCTLs, we use the same rules as used by iwpriv and
364*4882a593Smuzhiyun * defined in struct iw_priv_args.
365*4882a593Smuzhiyun *
366*4882a593Smuzhiyun * For standard IOCTLs, things are quite different and we need to
367*4882a593Smuzhiyun * use the structures below. Actually, this struct is also more
368*4882a593Smuzhiyun * efficient, but that's another story...
369*4882a593Smuzhiyun */
370*4882a593Smuzhiyun
371*4882a593Smuzhiyun /*
372*4882a593Smuzhiyun * Describe how a standard IOCTL looks like.
373*4882a593Smuzhiyun */
374*4882a593Smuzhiyun struct iw_ioctl_description {
375*4882a593Smuzhiyun __u8 header_type; /* NULL, iw_point or other */
376*4882a593Smuzhiyun __u8 token_type; /* Future */
377*4882a593Smuzhiyun __u16 token_size; /* Granularity of payload */
378*4882a593Smuzhiyun __u16 min_tokens; /* Min acceptable token number */
379*4882a593Smuzhiyun __u16 max_tokens; /* Max acceptable token number */
380*4882a593Smuzhiyun __u32 flags; /* Special handling of the request */
381*4882a593Smuzhiyun };
382*4882a593Smuzhiyun
383*4882a593Smuzhiyun /* Need to think of short header translation table. Later. */
384*4882a593Smuzhiyun
385*4882a593Smuzhiyun /* --------------------- ENHANCED SPY SUPPORT --------------------- */
386*4882a593Smuzhiyun /*
387*4882a593Smuzhiyun * In the old days, the driver was handling spy support all by itself.
388*4882a593Smuzhiyun * Now, the driver can delegate this task to Wireless Extensions.
389*4882a593Smuzhiyun * It needs to include this struct in its private part and use the
390*4882a593Smuzhiyun * standard spy iw_handler.
391*4882a593Smuzhiyun */
392*4882a593Smuzhiyun
393*4882a593Smuzhiyun /*
394*4882a593Smuzhiyun * Instance specific spy data, i.e. addresses spied and quality for them.
395*4882a593Smuzhiyun */
396*4882a593Smuzhiyun struct iw_spy_data {
397*4882a593Smuzhiyun /* --- Standard spy support --- */
398*4882a593Smuzhiyun int spy_number;
399*4882a593Smuzhiyun u_char spy_address[IW_MAX_SPY][ETH_ALEN];
400*4882a593Smuzhiyun struct iw_quality spy_stat[IW_MAX_SPY];
401*4882a593Smuzhiyun /* --- Enhanced spy support (event) */
402*4882a593Smuzhiyun struct iw_quality spy_thr_low; /* Low threshold */
403*4882a593Smuzhiyun struct iw_quality spy_thr_high; /* High threshold */
404*4882a593Smuzhiyun u_char spy_thr_under[IW_MAX_SPY];
405*4882a593Smuzhiyun };
406*4882a593Smuzhiyun
407*4882a593Smuzhiyun /* --------------------- DEVICE WIRELESS DATA --------------------- */
408*4882a593Smuzhiyun /*
409*4882a593Smuzhiyun * This is all the wireless data specific to a device instance that
410*4882a593Smuzhiyun * is managed by the core of Wireless Extensions or the 802.11 layer.
411*4882a593Smuzhiyun * We only keep pointer to those structures, so that a driver is free
412*4882a593Smuzhiyun * to share them between instances.
413*4882a593Smuzhiyun * This structure should be initialised before registering the device.
414*4882a593Smuzhiyun * Access to this data follow the same rules as any other struct net_device
415*4882a593Smuzhiyun * data (i.e. valid as long as struct net_device exist, same locking rules).
416*4882a593Smuzhiyun */
417*4882a593Smuzhiyun /* Forward declaration */
418*4882a593Smuzhiyun struct libipw_device;
419*4882a593Smuzhiyun /* The struct */
420*4882a593Smuzhiyun struct iw_public_data {
421*4882a593Smuzhiyun /* Driver enhanced spy support */
422*4882a593Smuzhiyun struct iw_spy_data * spy_data;
423*4882a593Smuzhiyun /* Legacy structure managed by the ipw2x00-specific IEEE 802.11 layer */
424*4882a593Smuzhiyun struct libipw_device * libipw;
425*4882a593Smuzhiyun };
426*4882a593Smuzhiyun
427*4882a593Smuzhiyun /**************************** PROTOTYPES ****************************/
428*4882a593Smuzhiyun /*
429*4882a593Smuzhiyun * Functions part of the Wireless Extensions (defined in net/core/wireless.c).
430*4882a593Smuzhiyun * Those may be called only within the kernel.
431*4882a593Smuzhiyun */
432*4882a593Smuzhiyun
433*4882a593Smuzhiyun /* First : function strictly used inside the kernel */
434*4882a593Smuzhiyun
435*4882a593Smuzhiyun /* Handle /proc/net/wireless, called in net/code/dev.c */
436*4882a593Smuzhiyun int dev_get_wireless_info(char *buffer, char **start, off_t offset, int length);
437*4882a593Smuzhiyun
438*4882a593Smuzhiyun /* Second : functions that may be called by driver modules */
439*4882a593Smuzhiyun
440*4882a593Smuzhiyun /* Send a single event to user space */
441*4882a593Smuzhiyun void wireless_send_event(struct net_device *dev, unsigned int cmd,
442*4882a593Smuzhiyun union iwreq_data *wrqu, const char *extra);
443*4882a593Smuzhiyun #ifdef CONFIG_WEXT_CORE
444*4882a593Smuzhiyun /* flush all previous wext events - if work is done from netdev notifiers */
445*4882a593Smuzhiyun void wireless_nlevent_flush(void);
446*4882a593Smuzhiyun #else
wireless_nlevent_flush(void)447*4882a593Smuzhiyun static inline void wireless_nlevent_flush(void) {}
448*4882a593Smuzhiyun #endif
449*4882a593Smuzhiyun
450*4882a593Smuzhiyun /* We may need a function to send a stream of events to user space.
451*4882a593Smuzhiyun * More on that later... */
452*4882a593Smuzhiyun
453*4882a593Smuzhiyun /* Standard handler for SIOCSIWSPY */
454*4882a593Smuzhiyun int iw_handler_set_spy(struct net_device *dev, struct iw_request_info *info,
455*4882a593Smuzhiyun union iwreq_data *wrqu, char *extra);
456*4882a593Smuzhiyun /* Standard handler for SIOCGIWSPY */
457*4882a593Smuzhiyun int iw_handler_get_spy(struct net_device *dev, struct iw_request_info *info,
458*4882a593Smuzhiyun union iwreq_data *wrqu, char *extra);
459*4882a593Smuzhiyun /* Standard handler for SIOCSIWTHRSPY */
460*4882a593Smuzhiyun int iw_handler_set_thrspy(struct net_device *dev, struct iw_request_info *info,
461*4882a593Smuzhiyun union iwreq_data *wrqu, char *extra);
462*4882a593Smuzhiyun /* Standard handler for SIOCGIWTHRSPY */
463*4882a593Smuzhiyun int iw_handler_get_thrspy(struct net_device *dev, struct iw_request_info *info,
464*4882a593Smuzhiyun union iwreq_data *wrqu, char *extra);
465*4882a593Smuzhiyun /* Driver call to update spy records */
466*4882a593Smuzhiyun void wireless_spy_update(struct net_device *dev, unsigned char *address,
467*4882a593Smuzhiyun struct iw_quality *wstats);
468*4882a593Smuzhiyun
469*4882a593Smuzhiyun /************************* INLINE FUNTIONS *************************/
470*4882a593Smuzhiyun /*
471*4882a593Smuzhiyun * Function that are so simple that it's more efficient inlining them
472*4882a593Smuzhiyun */
473*4882a593Smuzhiyun
iwe_stream_lcp_len(struct iw_request_info * info)474*4882a593Smuzhiyun static inline int iwe_stream_lcp_len(struct iw_request_info *info)
475*4882a593Smuzhiyun {
476*4882a593Smuzhiyun #ifdef CONFIG_COMPAT
477*4882a593Smuzhiyun if (info->flags & IW_REQUEST_FLAG_COMPAT)
478*4882a593Smuzhiyun return IW_EV_COMPAT_LCP_LEN;
479*4882a593Smuzhiyun #endif
480*4882a593Smuzhiyun return IW_EV_LCP_LEN;
481*4882a593Smuzhiyun }
482*4882a593Smuzhiyun
iwe_stream_point_len(struct iw_request_info * info)483*4882a593Smuzhiyun static inline int iwe_stream_point_len(struct iw_request_info *info)
484*4882a593Smuzhiyun {
485*4882a593Smuzhiyun #ifdef CONFIG_COMPAT
486*4882a593Smuzhiyun if (info->flags & IW_REQUEST_FLAG_COMPAT)
487*4882a593Smuzhiyun return IW_EV_COMPAT_POINT_LEN;
488*4882a593Smuzhiyun #endif
489*4882a593Smuzhiyun return IW_EV_POINT_LEN;
490*4882a593Smuzhiyun }
491*4882a593Smuzhiyun
iwe_stream_event_len_adjust(struct iw_request_info * info,int event_len)492*4882a593Smuzhiyun static inline int iwe_stream_event_len_adjust(struct iw_request_info *info,
493*4882a593Smuzhiyun int event_len)
494*4882a593Smuzhiyun {
495*4882a593Smuzhiyun #ifdef CONFIG_COMPAT
496*4882a593Smuzhiyun if (info->flags & IW_REQUEST_FLAG_COMPAT) {
497*4882a593Smuzhiyun event_len -= IW_EV_LCP_LEN;
498*4882a593Smuzhiyun event_len += IW_EV_COMPAT_LCP_LEN;
499*4882a593Smuzhiyun }
500*4882a593Smuzhiyun #endif
501*4882a593Smuzhiyun
502*4882a593Smuzhiyun return event_len;
503*4882a593Smuzhiyun }
504*4882a593Smuzhiyun
505*4882a593Smuzhiyun /*------------------------------------------------------------------*/
506*4882a593Smuzhiyun /*
507*4882a593Smuzhiyun * Wrapper to add an Wireless Event to a stream of events.
508*4882a593Smuzhiyun */
509*4882a593Smuzhiyun char *iwe_stream_add_event(struct iw_request_info *info, char *stream,
510*4882a593Smuzhiyun char *ends, struct iw_event *iwe, int event_len);
511*4882a593Smuzhiyun
512*4882a593Smuzhiyun static inline char *
iwe_stream_add_event_check(struct iw_request_info * info,char * stream,char * ends,struct iw_event * iwe,int event_len)513*4882a593Smuzhiyun iwe_stream_add_event_check(struct iw_request_info *info, char *stream,
514*4882a593Smuzhiyun char *ends, struct iw_event *iwe, int event_len)
515*4882a593Smuzhiyun {
516*4882a593Smuzhiyun char *res = iwe_stream_add_event(info, stream, ends, iwe, event_len);
517*4882a593Smuzhiyun
518*4882a593Smuzhiyun if (res == stream)
519*4882a593Smuzhiyun return ERR_PTR(-E2BIG);
520*4882a593Smuzhiyun return res;
521*4882a593Smuzhiyun }
522*4882a593Smuzhiyun
523*4882a593Smuzhiyun /*------------------------------------------------------------------*/
524*4882a593Smuzhiyun /*
525*4882a593Smuzhiyun * Wrapper to add an short Wireless Event containing a pointer to a
526*4882a593Smuzhiyun * stream of events.
527*4882a593Smuzhiyun */
528*4882a593Smuzhiyun char *iwe_stream_add_point(struct iw_request_info *info, char *stream,
529*4882a593Smuzhiyun char *ends, struct iw_event *iwe, char *extra);
530*4882a593Smuzhiyun
531*4882a593Smuzhiyun static inline char *
iwe_stream_add_point_check(struct iw_request_info * info,char * stream,char * ends,struct iw_event * iwe,char * extra)532*4882a593Smuzhiyun iwe_stream_add_point_check(struct iw_request_info *info, char *stream,
533*4882a593Smuzhiyun char *ends, struct iw_event *iwe, char *extra)
534*4882a593Smuzhiyun {
535*4882a593Smuzhiyun char *res = iwe_stream_add_point(info, stream, ends, iwe, extra);
536*4882a593Smuzhiyun
537*4882a593Smuzhiyun if (res == stream)
538*4882a593Smuzhiyun return ERR_PTR(-E2BIG);
539*4882a593Smuzhiyun return res;
540*4882a593Smuzhiyun }
541*4882a593Smuzhiyun
542*4882a593Smuzhiyun /*------------------------------------------------------------------*/
543*4882a593Smuzhiyun /*
544*4882a593Smuzhiyun * Wrapper to add a value to a Wireless Event in a stream of events.
545*4882a593Smuzhiyun * Be careful, this one is tricky to use properly :
546*4882a593Smuzhiyun * At the first run, you need to have (value = event + IW_EV_LCP_LEN).
547*4882a593Smuzhiyun */
548*4882a593Smuzhiyun char *iwe_stream_add_value(struct iw_request_info *info, char *event,
549*4882a593Smuzhiyun char *value, char *ends, struct iw_event *iwe,
550*4882a593Smuzhiyun int event_len);
551*4882a593Smuzhiyun
552*4882a593Smuzhiyun #endif /* _IW_HANDLER_H */
553