1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
21da177e4SLinus Torvalds /*
31da177e4SLinus Torvalds * This file define the new driver API for Wireless Extensions
41da177e4SLinus Torvalds *
5c2805fbbSJean Tourrilhes * Version : 8 16.3.07
61da177e4SLinus Torvalds *
71da177e4SLinus Torvalds * Authors : Jean Tourrilhes - HPL - <jt@hpl.hp.com>
8c2805fbbSJean Tourrilhes * Copyright (c) 2001-2007 Jean Tourrilhes, All Rights Reserved.
91da177e4SLinus Torvalds */
101da177e4SLinus Torvalds
111da177e4SLinus Torvalds #ifndef _IW_HANDLER_H
121da177e4SLinus Torvalds #define _IW_HANDLER_H
131da177e4SLinus Torvalds
141da177e4SLinus Torvalds /************************** DOCUMENTATION **************************/
151da177e4SLinus Torvalds /*
161da177e4SLinus Torvalds * Initial driver API (1996 -> onward) :
171da177e4SLinus Torvalds * -----------------------------------
181da177e4SLinus Torvalds * The initial API just sends the IOCTL request received from user space
191da177e4SLinus Torvalds * to the driver (via the driver ioctl handler). The driver has to
201da177e4SLinus Torvalds * handle all the rest...
211da177e4SLinus Torvalds *
221da177e4SLinus Torvalds * The initial API also defines a specific handler in struct net_device
231da177e4SLinus Torvalds * to handle wireless statistics.
241da177e4SLinus Torvalds *
251da177e4SLinus Torvalds * The initial APIs served us well and has proven a reasonably good design.
261da177e4SLinus Torvalds * However, there is a few shortcommings :
271da177e4SLinus Torvalds * o No events, everything is a request to the driver.
281da177e4SLinus Torvalds * o Large ioctl function in driver with gigantic switch statement
291da177e4SLinus Torvalds * (i.e. spaghetti code).
301da177e4SLinus Torvalds * o Driver has to mess up with copy_to/from_user, and in many cases
311da177e4SLinus Torvalds * does it unproperly. Common mistakes are :
321da177e4SLinus Torvalds * * buffer overflows (no checks or off by one checks)
331da177e4SLinus Torvalds * * call copy_to/from_user with irq disabled
341da177e4SLinus Torvalds * o The user space interface is tied to ioctl because of the use
351da177e4SLinus Torvalds * copy_to/from_user.
361da177e4SLinus Torvalds *
371da177e4SLinus Torvalds * New driver API (2002 -> onward) :
381da177e4SLinus Torvalds * -------------------------------
391da177e4SLinus Torvalds * The new driver API is just a bunch of standard functions (handlers),
401da177e4SLinus Torvalds * each handling a specific Wireless Extension. The driver just export
411da177e4SLinus Torvalds * the list of handler it supports, and those will be called apropriately.
421da177e4SLinus Torvalds *
431da177e4SLinus Torvalds * I tried to keep the main advantage of the previous API (simplicity,
441da177e4SLinus Torvalds * efficiency and light weight), and also I provide a good dose of backward
451da177e4SLinus Torvalds * compatibility (most structures are the same, driver can use both API
461da177e4SLinus Torvalds * simultaneously, ...).
471da177e4SLinus Torvalds * Hopefully, I've also addressed the shortcomming of the initial API.
481da177e4SLinus Torvalds *
491da177e4SLinus Torvalds * The advantage of the new API are :
501da177e4SLinus Torvalds * o Handling of Extensions in driver broken in small contained functions
511da177e4SLinus Torvalds * o Tighter checks of ioctl before calling the driver
521da177e4SLinus Torvalds * o Flexible commit strategy (at least, the start of it)
531da177e4SLinus Torvalds * o Backward compatibility (can be mixed with old API)
541da177e4SLinus Torvalds * o Driver doesn't have to worry about memory and user-space issues
551da177e4SLinus Torvalds * The last point is important for the following reasons :
561da177e4SLinus Torvalds * o You are now able to call the new driver API from any API you
571da177e4SLinus Torvalds * want (including from within other parts of the kernel).
581da177e4SLinus Torvalds * o Common mistakes are avoided (buffer overflow, user space copy
591da177e4SLinus Torvalds * with irq disabled and so on).
601da177e4SLinus Torvalds *
611da177e4SLinus Torvalds * The Drawback of the new API are :
621da177e4SLinus Torvalds * o bloat (especially kernel)
631da177e4SLinus Torvalds * o need to migrate existing drivers to new API
641da177e4SLinus Torvalds * My initial testing shows that the new API adds around 3kB to the kernel
651da177e4SLinus Torvalds * and save between 0 and 5kB from a typical driver.
661da177e4SLinus Torvalds * Also, as all structures and data types are unchanged, the migration is
671da177e4SLinus Torvalds * quite straightforward (but tedious).
681da177e4SLinus Torvalds *
691da177e4SLinus Torvalds * ---
701da177e4SLinus Torvalds *
711da177e4SLinus Torvalds * The new driver API is defined below in this file. User space should
721da177e4SLinus Torvalds * not be aware of what's happening down there...
731da177e4SLinus Torvalds *
741da177e4SLinus Torvalds * A new kernel wrapper is in charge of validating the IOCTLs and calling
751da177e4SLinus Torvalds * the appropriate driver handler. This is implemented in :
761da177e4SLinus Torvalds * # net/core/wireless.c
771da177e4SLinus Torvalds *
781da177e4SLinus Torvalds * The driver export the list of handlers in :
791da177e4SLinus Torvalds * # include/linux/netdevice.h (one place)
801da177e4SLinus Torvalds *
811da177e4SLinus Torvalds * The new driver API is available for WIRELESS_EXT >= 13.
821da177e4SLinus Torvalds * Good luck with migration to the new API ;-)
831da177e4SLinus Torvalds */
841da177e4SLinus Torvalds
851da177e4SLinus Torvalds /* ---------------------- THE IMPLEMENTATION ---------------------- */
861da177e4SLinus Torvalds /*
871da177e4SLinus Torvalds * Some of the choice I've made are pretty controversials. Defining an
881da177e4SLinus Torvalds * API is very much weighting compromises. This goes into some of the
891da177e4SLinus Torvalds * details and the thinking behind the implementation.
901da177e4SLinus Torvalds *
911da177e4SLinus Torvalds * Implementation goals :
921da177e4SLinus Torvalds * --------------------
931da177e4SLinus Torvalds * The implementation goals were as follow :
941da177e4SLinus Torvalds * o Obvious : you should not need a PhD to understand what's happening,
9525985edcSLucas De Marchi * the benefit is easier maintenance.
961da177e4SLinus Torvalds * o Flexible : it should accommodate a wide variety of driver
971da177e4SLinus Torvalds * implementations and be as flexible as the old API.
981da177e4SLinus Torvalds * o Lean : it should be efficient memory wise to minimise the impact
991da177e4SLinus Torvalds * on kernel footprint.
1001da177e4SLinus Torvalds * o Transparent to user space : the large number of user space
1011da177e4SLinus Torvalds * applications that use Wireless Extensions should not need
1021da177e4SLinus Torvalds * any modifications.
1031da177e4SLinus Torvalds *
1041da177e4SLinus Torvalds * Array of functions versus Struct of functions
1051da177e4SLinus Torvalds * ---------------------------------------------
1061da177e4SLinus Torvalds * 1) Having an array of functions allow the kernel code to access the
1071da177e4SLinus Torvalds * handler in a single lookup, which is much more efficient (think hash
1081da177e4SLinus Torvalds * table here).
1091da177e4SLinus Torvalds * 2) The only drawback is that driver writer may put their handler in
1101da177e4SLinus Torvalds * the wrong slot. This is trivial to test (I set the frequency, the
1111da177e4SLinus Torvalds * bitrate changes). Once the handler is in the proper slot, it will be
1121da177e4SLinus Torvalds * there forever, because the array is only extended at the end.
1131da177e4SLinus Torvalds * 3) Backward/forward compatibility : adding new handler just require
1141da177e4SLinus Torvalds * extending the array, so you can put newer driver in older kernel
1151da177e4SLinus Torvalds * without having to patch the kernel code (and vice versa).
1161da177e4SLinus Torvalds *
1171da177e4SLinus Torvalds * All handler are of the same generic type
1181da177e4SLinus Torvalds * ----------------------------------------
1191da177e4SLinus Torvalds * That's a feature !!!
1201da177e4SLinus Torvalds * 1) Having a generic handler allow to have generic code, which is more
1211da177e4SLinus Torvalds * efficient. If each of the handler was individually typed I would need
1221da177e4SLinus Torvalds * to add a big switch in the kernel (== more bloat). This solution is
1231da177e4SLinus Torvalds * more scalable, adding new Wireless Extensions doesn't add new code.
1241da177e4SLinus Torvalds * 2) You can use the same handler in different slots of the array. For
1251da177e4SLinus Torvalds * hardware, it may be more efficient or logical to handle multiple
1261da177e4SLinus Torvalds * Wireless Extensions with a single function, and the API allow you to
1271da177e4SLinus Torvalds * do that. (An example would be a single record on the card to control
1281da177e4SLinus Torvalds * both bitrate and frequency, the handler would read the old record,
1291da177e4SLinus Torvalds * modify it according to info->cmd and rewrite it).
1301da177e4SLinus Torvalds *
1311da177e4SLinus Torvalds * Functions prototype uses union iwreq_data
1321da177e4SLinus Torvalds * -----------------------------------------
13325985edcSLucas De Marchi * Some would have preferred functions defined this way :
1341da177e4SLinus Torvalds * static int mydriver_ioctl_setrate(struct net_device *dev,
1351da177e4SLinus Torvalds * long rate, int auto)
1361da177e4SLinus Torvalds * 1) The kernel code doesn't "validate" the content of iwreq_data, and
1371da177e4SLinus Torvalds * can't do it (different hardware may have different notion of what a
1381da177e4SLinus Torvalds * valid frequency is), so we don't pretend that we do it.
1391da177e4SLinus Torvalds * 2) The above form is not extendable. If I want to add a flag (for
1401da177e4SLinus Torvalds * example to distinguish setting max rate and basic rate), I would
1411da177e4SLinus Torvalds * break the prototype. Using iwreq_data is more flexible.
1421da177e4SLinus Torvalds * 3) Also, the above form is not generic (see above).
1431da177e4SLinus Torvalds * 4) I don't expect driver developper using the wrong field of the
1441da177e4SLinus Torvalds * union (Doh !), so static typechecking doesn't add much value.
1451da177e4SLinus Torvalds * 5) Lastly, you can skip the union by doing :
1461da177e4SLinus Torvalds * static int mydriver_ioctl_setrate(struct net_device *dev,
1471da177e4SLinus Torvalds * struct iw_request_info *info,
1481da177e4SLinus Torvalds * struct iw_param *rrq,
1491da177e4SLinus Torvalds * char *extra)
1501da177e4SLinus Torvalds * And then adding the handler in the array like this :
1511da177e4SLinus Torvalds * (iw_handler) mydriver_ioctl_setrate, // SIOCSIWRATE
1521da177e4SLinus Torvalds *
1531da177e4SLinus Torvalds * Using functions and not a registry
1541da177e4SLinus Torvalds * ----------------------------------
1551da177e4SLinus Torvalds * Another implementation option would have been for every instance to
1561da177e4SLinus Torvalds * define a registry (a struct containing all the Wireless Extensions)
1571da177e4SLinus Torvalds * and only have a function to commit the registry to the hardware.
1581da177e4SLinus Torvalds * 1) This approach can be emulated by the current code, but not
1591da177e4SLinus Torvalds * vice versa.
1601da177e4SLinus Torvalds * 2) Some drivers don't keep any configuration in the driver, for them
1611da177e4SLinus Torvalds * adding such a registry would be a significant bloat.
1621da177e4SLinus Torvalds * 3) The code to translate from Wireless Extension to native format is
1631da177e4SLinus Torvalds * needed anyway, so it would not reduce significantely the amount of code.
1641da177e4SLinus Torvalds * 4) The current approach only selectively translate Wireless Extensions
1651da177e4SLinus Torvalds * to native format and only selectively set, whereas the registry approach
1661da177e4SLinus Torvalds * would require to translate all WE and set all parameters for any single
1671da177e4SLinus Torvalds * change.
1681da177e4SLinus Torvalds * 5) For many Wireless Extensions, the GET operation return the current
1691da177e4SLinus Torvalds * dynamic value, not the value that was set.
1701da177e4SLinus Torvalds *
1711da177e4SLinus Torvalds * This header is <net/iw_handler.h>
1721da177e4SLinus Torvalds * ---------------------------------
1731da177e4SLinus Torvalds * 1) This header is kernel space only and should not be exported to
1741da177e4SLinus Torvalds * user space. Headers in "include/linux/" are exported, headers in
1751da177e4SLinus Torvalds * "include/net/" are not.
1761da177e4SLinus Torvalds *
1771da177e4SLinus Torvalds * Mixed 32/64 bit issues
1781da177e4SLinus Torvalds * ----------------------
1791da177e4SLinus Torvalds * The Wireless Extensions are designed to be 64 bit clean, by using only
1801da177e4SLinus Torvalds * datatypes with explicit storage size.
1811da177e4SLinus Torvalds * There are some issues related to kernel and user space using different
1821da177e4SLinus Torvalds * memory model, and in particular 64bit kernel with 32bit user space.
1831da177e4SLinus Torvalds * The problem is related to struct iw_point, that contains a pointer
1841da177e4SLinus Torvalds * that *may* need to be translated.
1851da177e4SLinus Torvalds * This is quite messy. The new API doesn't solve this problem (it can't),
1861da177e4SLinus Torvalds * but is a step in the right direction :
1871da177e4SLinus Torvalds * 1) Meta data about each ioctl is easily available, so we know what type
1881da177e4SLinus Torvalds * of translation is needed.
1891da177e4SLinus Torvalds * 2) The move of data between kernel and user space is only done in a single
1901da177e4SLinus Torvalds * place in the kernel, so adding specific hooks in there is possible.
1911da177e4SLinus Torvalds * 3) In the long term, it allows to move away from using ioctl as the
1921da177e4SLinus Torvalds * user space API.
1931da177e4SLinus Torvalds *
1941da177e4SLinus Torvalds * So many comments and so few code
1951da177e4SLinus Torvalds * --------------------------------
1961da177e4SLinus Torvalds * That's a feature. Comments won't bloat the resulting kernel binary.
1971da177e4SLinus Torvalds */
1981da177e4SLinus Torvalds
1991da177e4SLinus Torvalds /***************************** INCLUDES *****************************/
2001da177e4SLinus Torvalds
2011da177e4SLinus Torvalds #include <linux/wireless.h> /* IOCTL user space API */
2021da177e4SLinus Torvalds #include <linux/if_ether.h>
2031da177e4SLinus Torvalds
2041da177e4SLinus Torvalds /***************************** VERSION *****************************/
2051da177e4SLinus Torvalds /*
2061da177e4SLinus Torvalds * This constant is used to know which version of the driver API is
2071da177e4SLinus Torvalds * available. Hopefully, this will be pretty stable and no changes
2081da177e4SLinus Torvalds * will be needed...
2091da177e4SLinus Torvalds * I just plan to increment with each new version.
2101da177e4SLinus Torvalds */
211c2805fbbSJean Tourrilhes #define IW_HANDLER_VERSION 8
2121da177e4SLinus Torvalds
2131da177e4SLinus Torvalds /*
2141da177e4SLinus Torvalds * Changes :
2151da177e4SLinus Torvalds *
2161da177e4SLinus Torvalds * V2 to V3
2171da177e4SLinus Torvalds * --------
2181da177e4SLinus Torvalds * - Move event definition in <linux/wireless.h>
2191da177e4SLinus Torvalds * - Add Wireless Event support :
2201da177e4SLinus Torvalds * o wireless_send_event() prototype
2211da177e4SLinus Torvalds * o iwe_stream_add_event/point() inline functions
2221da177e4SLinus Torvalds * V3 to V4
2231da177e4SLinus Torvalds * --------
2241da177e4SLinus Torvalds * - Reshuffle IW_HEADER_TYPE_XXX to map IW_PRIV_TYPE_XXX changes
2251da177e4SLinus Torvalds *
2261da177e4SLinus Torvalds * V4 to V5
2271da177e4SLinus Torvalds * --------
2281da177e4SLinus Torvalds * - Add new spy support : struct iw_spy_data & prototypes
2291da177e4SLinus Torvalds *
2301da177e4SLinus Torvalds * V5 to V6
2311da177e4SLinus Torvalds * --------
2321da177e4SLinus Torvalds * - Change the way we get to spy_data method for added safety
2331da177e4SLinus Torvalds * - Remove spy #ifdef, they are always on -> cleaner code
2341da177e4SLinus Torvalds * - Add IW_DESCR_FLAG_NOMAX flag for very large requests
2351da177e4SLinus Torvalds * - Start migrating get_wireless_stats to struct iw_handler_def
2366582c164SJean Tourrilhes *
2376582c164SJean Tourrilhes * V6 to V7
2386582c164SJean Tourrilhes * --------
2396582c164SJean Tourrilhes * - Add struct ieee80211_device pointer in struct iw_public_data
2406582c164SJean Tourrilhes * - Remove (struct iw_point *)->pointer from events and streams
2416582c164SJean Tourrilhes * - Remove spy_offset from struct iw_handler_def
2426582c164SJean Tourrilhes * - Add "check" version of event macros for ieee802.11 stack
243c2805fbbSJean Tourrilhes *
244c2805fbbSJean Tourrilhes * V7 to V8
245c2805fbbSJean Tourrilhes * ----------
246c2805fbbSJean Tourrilhes * - Prevent leaking of kernel space in stream on 64 bits.
2471da177e4SLinus Torvalds */
2481da177e4SLinus Torvalds
2491da177e4SLinus Torvalds /**************************** CONSTANTS ****************************/
2501da177e4SLinus Torvalds
2511da177e4SLinus Torvalds /* Enhanced spy support available */
2521da177e4SLinus Torvalds #define IW_WIRELESS_SPY
2531da177e4SLinus Torvalds #define IW_WIRELESS_THRSPY
2541da177e4SLinus Torvalds
2551da177e4SLinus Torvalds /* Special error message for the driver to indicate that we
2561da177e4SLinus Torvalds * should do a commit after return from the iw_handler */
2571da177e4SLinus Torvalds #define EIWCOMMIT EINPROGRESS
2581da177e4SLinus Torvalds
2591da177e4SLinus Torvalds /* Flags available in struct iw_request_info */
2600f5cabbaSDavid S. Miller #define IW_REQUEST_FLAG_COMPAT 0x0001 /* Compat ioctl call */
2611da177e4SLinus Torvalds
2621da177e4SLinus Torvalds /* Type of headers we know about (basically union iwreq_data) */
2631da177e4SLinus Torvalds #define IW_HEADER_TYPE_NULL 0 /* Not available */
2641da177e4SLinus Torvalds #define IW_HEADER_TYPE_CHAR 2 /* char [IFNAMSIZ] */
2651da177e4SLinus Torvalds #define IW_HEADER_TYPE_UINT 4 /* __u32 */
2661da177e4SLinus Torvalds #define IW_HEADER_TYPE_FREQ 5 /* struct iw_freq */
2671da177e4SLinus Torvalds #define IW_HEADER_TYPE_ADDR 6 /* struct sockaddr */
2681da177e4SLinus Torvalds #define IW_HEADER_TYPE_POINT 8 /* struct iw_point */
2691da177e4SLinus Torvalds #define IW_HEADER_TYPE_PARAM 9 /* struct iw_param */
2701da177e4SLinus Torvalds #define IW_HEADER_TYPE_QUAL 10 /* struct iw_quality */
2711da177e4SLinus Torvalds
2721da177e4SLinus Torvalds /* Handling flags */
2731da177e4SLinus Torvalds /* Most are not implemented. I just use them as a reminder of some
2741da177e4SLinus Torvalds * cool features we might need one day ;-) */
2751da177e4SLinus Torvalds #define IW_DESCR_FLAG_NONE 0x0000 /* Obvious */
2761da177e4SLinus Torvalds /* Wrapper level flags */
2771da177e4SLinus Torvalds #define IW_DESCR_FLAG_DUMP 0x0001 /* Not part of the dump command */
2781da177e4SLinus Torvalds #define IW_DESCR_FLAG_EVENT 0x0002 /* Generate an event on SET */
2791da177e4SLinus Torvalds #define IW_DESCR_FLAG_RESTRICT 0x0004 /* GET : request is ROOT only */
2801da177e4SLinus Torvalds /* SET : Omit payload from generated iwevent */
2811da177e4SLinus Torvalds #define IW_DESCR_FLAG_NOMAX 0x0008 /* GET : no limit on request size */
2821da177e4SLinus Torvalds /* Driver level flags */
2831da177e4SLinus Torvalds #define IW_DESCR_FLAG_WAIT 0x0100 /* Wait for driver event */
2841da177e4SLinus Torvalds
2851da177e4SLinus Torvalds /****************************** TYPES ******************************/
2861da177e4SLinus Torvalds
2871da177e4SLinus Torvalds /* ----------------------- WIRELESS HANDLER ----------------------- */
2881da177e4SLinus Torvalds /*
2891da177e4SLinus Torvalds * A wireless handler is just a standard function, that looks like the
2901da177e4SLinus Torvalds * ioctl handler.
2911da177e4SLinus Torvalds * We also define there how a handler list look like... As the Wireless
2921da177e4SLinus Torvalds * Extension space is quite dense, we use a simple array, which is faster
2931da177e4SLinus Torvalds * (that's the perfect hash table ;-).
2941da177e4SLinus Torvalds */
2951da177e4SLinus Torvalds
2961da177e4SLinus Torvalds /*
2971da177e4SLinus Torvalds * Meta data about the request passed to the iw_handler.
2981da177e4SLinus Torvalds * Most handlers can safely ignore what's in there.
2991da177e4SLinus Torvalds * The 'cmd' field might come handy if you want to use the same handler
3001da177e4SLinus Torvalds * for multiple command...
3011da177e4SLinus Torvalds * This struct is also my long term insurance. I can add new fields here
3021da177e4SLinus Torvalds * without breaking the prototype of iw_handler...
3031da177e4SLinus Torvalds */
304fd2c3ef7SEric Dumazet struct iw_request_info {
3051da177e4SLinus Torvalds __u16 cmd; /* Wireless Extension command */
3061da177e4SLinus Torvalds __u16 flags; /* More to come ;-) */
3071da177e4SLinus Torvalds };
3081da177e4SLinus Torvalds
3091da177e4SLinus Torvalds struct net_device;
3101da177e4SLinus Torvalds
3111da177e4SLinus Torvalds /*
3121da177e4SLinus Torvalds * This is how a function handling a Wireless Extension should look
3131da177e4SLinus Torvalds * like (both get and set, standard and private).
3141da177e4SLinus Torvalds */
3151da177e4SLinus Torvalds typedef int (*iw_handler)(struct net_device *dev, struct iw_request_info *info,
3161da177e4SLinus Torvalds union iwreq_data *wrqu, char *extra);
3171da177e4SLinus Torvalds
3181da177e4SLinus Torvalds /*
3191da177e4SLinus Torvalds * This define all the handler that the driver export.
3201da177e4SLinus Torvalds * As you need only one per driver type, please use a static const
3211da177e4SLinus Torvalds * shared by all driver instances... Same for the members...
3221da177e4SLinus Torvalds * This will be linked from net_device in <linux/netdevice.h>
3231da177e4SLinus Torvalds */
324fd2c3ef7SEric Dumazet struct iw_handler_def {
3251da177e4SLinus Torvalds
3261da177e4SLinus Torvalds /* Array of handlers for standard ioctls
327f9ea3eb4SJoe Perches * We will call dev->wireless_handlers->standard[ioctl - SIOCIWFIRST]
3281da177e4SLinus Torvalds */
3291da177e4SLinus Torvalds const iw_handler * standard;
3303d23e349SJohannes Berg /* Number of handlers defined (more precisely, index of the
3313d23e349SJohannes Berg * last defined handler + 1) */
3323d23e349SJohannes Berg __u16 num_standard;
3331da177e4SLinus Torvalds
3343d23e349SJohannes Berg #ifdef CONFIG_WEXT_PRIV
3353d23e349SJohannes Berg __u16 num_private;
3363d23e349SJohannes Berg /* Number of private arg description */
3373d23e349SJohannes Berg __u16 num_private_args;
3381da177e4SLinus Torvalds /* Array of handlers for private ioctls
3391da177e4SLinus Torvalds * Will call dev->wireless_handlers->private[ioctl - SIOCIWFIRSTPRIV]
3401da177e4SLinus Torvalds */
3411da177e4SLinus Torvalds const iw_handler * private;
3421da177e4SLinus Torvalds
3431da177e4SLinus Torvalds /* Arguments of private handler. This one is just a list, so you
3441da177e4SLinus Torvalds * can put it in any order you want and should not leave holes...
3451da177e4SLinus Torvalds * We will automatically export that to user space... */
3461da177e4SLinus Torvalds const struct iw_priv_args * private_args;
3473d23e349SJohannes Berg #endif
3481da177e4SLinus Torvalds
3491da177e4SLinus Torvalds /* New location of get_wireless_stats, to de-bloat struct net_device.
3501da177e4SLinus Torvalds * The old pointer in struct net_device will be gradually phased
3511da177e4SLinus Torvalds * out, and drivers are encouraged to use this one... */
3521da177e4SLinus Torvalds struct iw_statistics* (*get_wireless_stats)(struct net_device *dev);
3531da177e4SLinus Torvalds };
3541da177e4SLinus Torvalds
3551da177e4SLinus Torvalds /* ---------------------- IOCTL DESCRIPTION ---------------------- */
3561da177e4SLinus Torvalds /*
3571da177e4SLinus Torvalds * One of the main goal of the new interface is to deal entirely with
3581da177e4SLinus Torvalds * user space/kernel space memory move.
3591da177e4SLinus Torvalds * For that, we need to know :
3601da177e4SLinus Torvalds * o if iwreq is a pointer or contain the full data
3611da177e4SLinus Torvalds * o what is the size of the data to copy
3621da177e4SLinus Torvalds *
3631da177e4SLinus Torvalds * For private IOCTLs, we use the same rules as used by iwpriv and
3641da177e4SLinus Torvalds * defined in struct iw_priv_args.
3651da177e4SLinus Torvalds *
3661da177e4SLinus Torvalds * For standard IOCTLs, things are quite different and we need to
367b903036aSGeert Uytterhoeven * use the structures below. Actually, this struct is also more
3681da177e4SLinus Torvalds * efficient, but that's another story...
3691da177e4SLinus Torvalds */
3701da177e4SLinus Torvalds
3711da177e4SLinus Torvalds /*
3721da177e4SLinus Torvalds * Describe how a standard IOCTL looks like.
3731da177e4SLinus Torvalds */
374fd2c3ef7SEric Dumazet struct iw_ioctl_description {
3751da177e4SLinus Torvalds __u8 header_type; /* NULL, iw_point or other */
3761da177e4SLinus Torvalds __u8 token_type; /* Future */
3771da177e4SLinus Torvalds __u16 token_size; /* Granularity of payload */
3781da177e4SLinus Torvalds __u16 min_tokens; /* Min acceptable token number */
3791da177e4SLinus Torvalds __u16 max_tokens; /* Max acceptable token number */
3801da177e4SLinus Torvalds __u32 flags; /* Special handling of the request */
3811da177e4SLinus Torvalds };
3821da177e4SLinus Torvalds
3831da177e4SLinus Torvalds /* Need to think of short header translation table. Later. */
3841da177e4SLinus Torvalds
3851da177e4SLinus Torvalds /* --------------------- ENHANCED SPY SUPPORT --------------------- */
3861da177e4SLinus Torvalds /*
3871da177e4SLinus Torvalds * In the old days, the driver was handling spy support all by itself.
3881da177e4SLinus Torvalds * Now, the driver can delegate this task to Wireless Extensions.
3891da177e4SLinus Torvalds * It needs to include this struct in its private part and use the
3901da177e4SLinus Torvalds * standard spy iw_handler.
3911da177e4SLinus Torvalds */
3921da177e4SLinus Torvalds
3931da177e4SLinus Torvalds /*
3941da177e4SLinus Torvalds * Instance specific spy data, i.e. addresses spied and quality for them.
3951da177e4SLinus Torvalds */
396fd2c3ef7SEric Dumazet struct iw_spy_data {
3971da177e4SLinus Torvalds /* --- Standard spy support --- */
3981da177e4SLinus Torvalds int spy_number;
3991da177e4SLinus Torvalds u_char spy_address[IW_MAX_SPY][ETH_ALEN];
4001da177e4SLinus Torvalds struct iw_quality spy_stat[IW_MAX_SPY];
4011da177e4SLinus Torvalds /* --- Enhanced spy support (event) */
4021da177e4SLinus Torvalds struct iw_quality spy_thr_low; /* Low threshold */
4031da177e4SLinus Torvalds struct iw_quality spy_thr_high; /* High threshold */
4041da177e4SLinus Torvalds u_char spy_thr_under[IW_MAX_SPY];
4051da177e4SLinus Torvalds };
4061da177e4SLinus Torvalds
4071da177e4SLinus Torvalds /* --------------------- DEVICE WIRELESS DATA --------------------- */
4081da177e4SLinus Torvalds /*
4091da177e4SLinus Torvalds * This is all the wireless data specific to a device instance that
4106582c164SJean Tourrilhes * is managed by the core of Wireless Extensions or the 802.11 layer.
4111da177e4SLinus Torvalds * We only keep pointer to those structures, so that a driver is free
4121da177e4SLinus Torvalds * to share them between instances.
4131da177e4SLinus Torvalds * This structure should be initialised before registering the device.
4141da177e4SLinus Torvalds * Access to this data follow the same rules as any other struct net_device
4151da177e4SLinus Torvalds * data (i.e. valid as long as struct net_device exist, same locking rules).
4161da177e4SLinus Torvalds */
4176582c164SJean Tourrilhes /* Forward declaration */
418b0a4e7d8SJohn W. Linville struct libipw_device;
4196582c164SJean Tourrilhes /* The struct */
4201da177e4SLinus Torvalds struct iw_public_data {
4211da177e4SLinus Torvalds /* Driver enhanced spy support */
4221da177e4SLinus Torvalds struct iw_spy_data * spy_data;
423b0a4e7d8SJohn W. Linville /* Legacy structure managed by the ipw2x00-specific IEEE 802.11 layer */
424b0a4e7d8SJohn W. Linville struct libipw_device * libipw;
4251da177e4SLinus Torvalds };
4261da177e4SLinus Torvalds
4271da177e4SLinus Torvalds /**************************** PROTOTYPES ****************************/
4281da177e4SLinus Torvalds /*
429*7bdfda42SYue Haibing * Functions part of the Wireless Extensions (defined in net/wireless/wext-core.c).
430*7bdfda42SYue Haibing * Those may be called by driver modules.
4311da177e4SLinus Torvalds */
4321da177e4SLinus Torvalds
4331da177e4SLinus Torvalds /* Send a single event to user space */
43470a3926fSJoe Perches void wireless_send_event(struct net_device *dev, unsigned int cmd,
43570a3926fSJoe Perches union iwreq_data *wrqu, const char *extra);
436cb150b9dSJohannes Berg #ifdef CONFIG_WEXT_CORE
437cb150b9dSJohannes Berg /* flush all previous wext events - if work is done from netdev notifiers */
438cb150b9dSJohannes Berg void wireless_nlevent_flush(void);
439cb150b9dSJohannes Berg #else
wireless_nlevent_flush(void)440cb150b9dSJohannes Berg static inline void wireless_nlevent_flush(void) {}
441cb150b9dSJohannes Berg #endif
4421da177e4SLinus Torvalds
4431da177e4SLinus Torvalds /* We may need a function to send a stream of events to user space.
4441da177e4SLinus Torvalds * More on that later... */
4451da177e4SLinus Torvalds
4461da177e4SLinus Torvalds /* Standard handler for SIOCSIWSPY */
44770a3926fSJoe Perches int iw_handler_set_spy(struct net_device *dev, struct iw_request_info *info,
44870a3926fSJoe Perches union iwreq_data *wrqu, char *extra);
4491da177e4SLinus Torvalds /* Standard handler for SIOCGIWSPY */
45070a3926fSJoe Perches int iw_handler_get_spy(struct net_device *dev, struct iw_request_info *info,
45170a3926fSJoe Perches union iwreq_data *wrqu, char *extra);
4521da177e4SLinus Torvalds /* Standard handler for SIOCSIWTHRSPY */
45370a3926fSJoe Perches int iw_handler_set_thrspy(struct net_device *dev, struct iw_request_info *info,
45470a3926fSJoe Perches union iwreq_data *wrqu, char *extra);
4551da177e4SLinus Torvalds /* Standard handler for SIOCGIWTHRSPY */
45670a3926fSJoe Perches int iw_handler_get_thrspy(struct net_device *dev, struct iw_request_info *info,
45770a3926fSJoe Perches union iwreq_data *wrqu, char *extra);
4581da177e4SLinus Torvalds /* Driver call to update spy records */
45970a3926fSJoe Perches void wireless_spy_update(struct net_device *dev, unsigned char *address,
4601da177e4SLinus Torvalds struct iw_quality *wstats);
4611da177e4SLinus Torvalds
4621da177e4SLinus Torvalds /************************* INLINE FUNTIONS *************************/
4631da177e4SLinus Torvalds /*
4641da177e4SLinus Torvalds * Function that are so simple that it's more efficient inlining them
4651da177e4SLinus Torvalds */
4661da177e4SLinus Torvalds
iwe_stream_lcp_len(struct iw_request_info * info)467ccc58057SDavid S. Miller static inline int iwe_stream_lcp_len(struct iw_request_info *info)
468ccc58057SDavid S. Miller {
469ccc58057SDavid S. Miller #ifdef CONFIG_COMPAT
470ccc58057SDavid S. Miller if (info->flags & IW_REQUEST_FLAG_COMPAT)
471ccc58057SDavid S. Miller return IW_EV_COMPAT_LCP_LEN;
472ccc58057SDavid S. Miller #endif
473ccc58057SDavid S. Miller return IW_EV_LCP_LEN;
474ccc58057SDavid S. Miller }
475ccc58057SDavid S. Miller
iwe_stream_point_len(struct iw_request_info * info)476ccc58057SDavid S. Miller static inline int iwe_stream_point_len(struct iw_request_info *info)
477ccc58057SDavid S. Miller {
478ccc58057SDavid S. Miller #ifdef CONFIG_COMPAT
479ccc58057SDavid S. Miller if (info->flags & IW_REQUEST_FLAG_COMPAT)
480ccc58057SDavid S. Miller return IW_EV_COMPAT_POINT_LEN;
481ccc58057SDavid S. Miller #endif
482ccc58057SDavid S. Miller return IW_EV_POINT_LEN;
483ccc58057SDavid S. Miller }
484ccc58057SDavid S. Miller
iwe_stream_event_len_adjust(struct iw_request_info * info,int event_len)485ccc58057SDavid S. Miller static inline int iwe_stream_event_len_adjust(struct iw_request_info *info,
486ccc58057SDavid S. Miller int event_len)
487ccc58057SDavid S. Miller {
488ccc58057SDavid S. Miller #ifdef CONFIG_COMPAT
489ccc58057SDavid S. Miller if (info->flags & IW_REQUEST_FLAG_COMPAT) {
490ccc58057SDavid S. Miller event_len -= IW_EV_LCP_LEN;
491ccc58057SDavid S. Miller event_len += IW_EV_COMPAT_LCP_LEN;
492ccc58057SDavid S. Miller }
493ccc58057SDavid S. Miller #endif
494ccc58057SDavid S. Miller
495ccc58057SDavid S. Miller return event_len;
496ccc58057SDavid S. Miller }
497ccc58057SDavid S. Miller
4981da177e4SLinus Torvalds /*------------------------------------------------------------------*/
4991da177e4SLinus Torvalds /*
5001da177e4SLinus Torvalds * Wrapper to add an Wireless Event to a stream of events.
5011da177e4SLinus Torvalds */
50210b2eb69SJohannes Berg char *iwe_stream_add_event(struct iw_request_info *info, char *stream,
50310b2eb69SJohannes Berg char *ends, struct iw_event *iwe, int event_len);
5041da177e4SLinus Torvalds
50536ef906eSJohannes Berg static inline char *
iwe_stream_add_event_check(struct iw_request_info * info,char * stream,char * ends,struct iw_event * iwe,int event_len)50636ef906eSJohannes Berg iwe_stream_add_event_check(struct iw_request_info *info, char *stream,
50736ef906eSJohannes Berg char *ends, struct iw_event *iwe, int event_len)
50836ef906eSJohannes Berg {
50936ef906eSJohannes Berg char *res = iwe_stream_add_event(info, stream, ends, iwe, event_len);
51036ef906eSJohannes Berg
51136ef906eSJohannes Berg if (res == stream)
51236ef906eSJohannes Berg return ERR_PTR(-E2BIG);
51336ef906eSJohannes Berg return res;
51436ef906eSJohannes Berg }
51536ef906eSJohannes Berg
5161da177e4SLinus Torvalds /*------------------------------------------------------------------*/
5171da177e4SLinus Torvalds /*
5181da177e4SLinus Torvalds * Wrapper to add an short Wireless Event containing a pointer to a
5191da177e4SLinus Torvalds * stream of events.
5201da177e4SLinus Torvalds */
52110b2eb69SJohannes Berg char *iwe_stream_add_point(struct iw_request_info *info, char *stream,
52210b2eb69SJohannes Berg char *ends, struct iw_event *iwe, char *extra);
5231da177e4SLinus Torvalds
52436ef906eSJohannes Berg static inline char *
iwe_stream_add_point_check(struct iw_request_info * info,char * stream,char * ends,struct iw_event * iwe,char * extra)52536ef906eSJohannes Berg iwe_stream_add_point_check(struct iw_request_info *info, char *stream,
52636ef906eSJohannes Berg char *ends, struct iw_event *iwe, char *extra)
52736ef906eSJohannes Berg {
52836ef906eSJohannes Berg char *res = iwe_stream_add_point(info, stream, ends, iwe, extra);
52936ef906eSJohannes Berg
53036ef906eSJohannes Berg if (res == stream)
53136ef906eSJohannes Berg return ERR_PTR(-E2BIG);
53236ef906eSJohannes Berg return res;
53336ef906eSJohannes Berg }
53436ef906eSJohannes Berg
5351da177e4SLinus Torvalds /*------------------------------------------------------------------*/
5361da177e4SLinus Torvalds /*
5371da177e4SLinus Torvalds * Wrapper to add a value to a Wireless Event in a stream of events.
5381da177e4SLinus Torvalds * Be careful, this one is tricky to use properly :
5391da177e4SLinus Torvalds * At the first run, you need to have (value = event + IW_EV_LCP_LEN).
5401da177e4SLinus Torvalds */
54110b2eb69SJohannes Berg char *iwe_stream_add_value(struct iw_request_info *info, char *event,
54210b2eb69SJohannes Berg char *value, char *ends, struct iw_event *iwe,
54310b2eb69SJohannes Berg int event_len);
5441da177e4SLinus Torvalds
5451da177e4SLinus Torvalds #endif /* _IW_HANDLER_H */
546