18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * This file define the new driver API for Wireless Extensions
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Version :	8	16.3.07
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Authors :	Jean Tourrilhes - HPL - <jt@hpl.hp.com>
88c2ecf20Sopenharmony_ci * Copyright (c) 2001-2007 Jean Tourrilhes, All Rights Reserved.
98c2ecf20Sopenharmony_ci */
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#ifndef _IW_HANDLER_H
128c2ecf20Sopenharmony_ci#define _IW_HANDLER_H
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci/************************** DOCUMENTATION **************************/
158c2ecf20Sopenharmony_ci/*
168c2ecf20Sopenharmony_ci * Initial driver API (1996 -> onward) :
178c2ecf20Sopenharmony_ci * -----------------------------------
188c2ecf20Sopenharmony_ci * The initial API just sends the IOCTL request received from user space
198c2ecf20Sopenharmony_ci * to the driver (via the driver ioctl handler). The driver has to
208c2ecf20Sopenharmony_ci * handle all the rest...
218c2ecf20Sopenharmony_ci *
228c2ecf20Sopenharmony_ci * The initial API also defines a specific handler in struct net_device
238c2ecf20Sopenharmony_ci * to handle wireless statistics.
248c2ecf20Sopenharmony_ci *
258c2ecf20Sopenharmony_ci * The initial APIs served us well and has proven a reasonably good design.
268c2ecf20Sopenharmony_ci * However, there is a few shortcommings :
278c2ecf20Sopenharmony_ci *	o No events, everything is a request to the driver.
288c2ecf20Sopenharmony_ci *	o Large ioctl function in driver with gigantic switch statement
298c2ecf20Sopenharmony_ci *	  (i.e. spaghetti code).
308c2ecf20Sopenharmony_ci *	o Driver has to mess up with copy_to/from_user, and in many cases
318c2ecf20Sopenharmony_ci *	  does it unproperly. Common mistakes are :
328c2ecf20Sopenharmony_ci *		* buffer overflows (no checks or off by one checks)
338c2ecf20Sopenharmony_ci *		* call copy_to/from_user with irq disabled
348c2ecf20Sopenharmony_ci *	o The user space interface is tied to ioctl because of the use
358c2ecf20Sopenharmony_ci *	  copy_to/from_user.
368c2ecf20Sopenharmony_ci *
378c2ecf20Sopenharmony_ci * New driver API (2002 -> onward) :
388c2ecf20Sopenharmony_ci * -------------------------------
398c2ecf20Sopenharmony_ci * The new driver API is just a bunch of standard functions (handlers),
408c2ecf20Sopenharmony_ci * each handling a specific Wireless Extension. The driver just export
418c2ecf20Sopenharmony_ci * the list of handler it supports, and those will be called apropriately.
428c2ecf20Sopenharmony_ci *
438c2ecf20Sopenharmony_ci * I tried to keep the main advantage of the previous API (simplicity,
448c2ecf20Sopenharmony_ci * efficiency and light weight), and also I provide a good dose of backward
458c2ecf20Sopenharmony_ci * compatibility (most structures are the same, driver can use both API
468c2ecf20Sopenharmony_ci * simultaneously, ...).
478c2ecf20Sopenharmony_ci * Hopefully, I've also addressed the shortcomming of the initial API.
488c2ecf20Sopenharmony_ci *
498c2ecf20Sopenharmony_ci * The advantage of the new API are :
508c2ecf20Sopenharmony_ci *	o Handling of Extensions in driver broken in small contained functions
518c2ecf20Sopenharmony_ci *	o Tighter checks of ioctl before calling the driver
528c2ecf20Sopenharmony_ci *	o Flexible commit strategy (at least, the start of it)
538c2ecf20Sopenharmony_ci *	o Backward compatibility (can be mixed with old API)
548c2ecf20Sopenharmony_ci *	o Driver doesn't have to worry about memory and user-space issues
558c2ecf20Sopenharmony_ci * The last point is important for the following reasons :
568c2ecf20Sopenharmony_ci *	o You are now able to call the new driver API from any API you
578c2ecf20Sopenharmony_ci *		want (including from within other parts of the kernel).
588c2ecf20Sopenharmony_ci *	o Common mistakes are avoided (buffer overflow, user space copy
598c2ecf20Sopenharmony_ci *		with irq disabled and so on).
608c2ecf20Sopenharmony_ci *
618c2ecf20Sopenharmony_ci * The Drawback of the new API are :
628c2ecf20Sopenharmony_ci *	o bloat (especially kernel)
638c2ecf20Sopenharmony_ci *	o need to migrate existing drivers to new API
648c2ecf20Sopenharmony_ci * My initial testing shows that the new API adds around 3kB to the kernel
658c2ecf20Sopenharmony_ci * and save between 0 and 5kB from a typical driver.
668c2ecf20Sopenharmony_ci * Also, as all structures and data types are unchanged, the migration is
678c2ecf20Sopenharmony_ci * quite straightforward (but tedious).
688c2ecf20Sopenharmony_ci *
698c2ecf20Sopenharmony_ci * ---
708c2ecf20Sopenharmony_ci *
718c2ecf20Sopenharmony_ci * The new driver API is defined below in this file. User space should
728c2ecf20Sopenharmony_ci * not be aware of what's happening down there...
738c2ecf20Sopenharmony_ci *
748c2ecf20Sopenharmony_ci * A new kernel wrapper is in charge of validating the IOCTLs and calling
758c2ecf20Sopenharmony_ci * the appropriate driver handler. This is implemented in :
768c2ecf20Sopenharmony_ci *	# net/core/wireless.c
778c2ecf20Sopenharmony_ci *
788c2ecf20Sopenharmony_ci * The driver export the list of handlers in :
798c2ecf20Sopenharmony_ci *	# include/linux/netdevice.h (one place)
808c2ecf20Sopenharmony_ci *
818c2ecf20Sopenharmony_ci * The new driver API is available for WIRELESS_EXT >= 13.
828c2ecf20Sopenharmony_ci * Good luck with migration to the new API ;-)
838c2ecf20Sopenharmony_ci */
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ci/* ---------------------- THE IMPLEMENTATION ---------------------- */
868c2ecf20Sopenharmony_ci/*
878c2ecf20Sopenharmony_ci * Some of the choice I've made are pretty controversials. Defining an
888c2ecf20Sopenharmony_ci * API is very much weighting compromises. This goes into some of the
898c2ecf20Sopenharmony_ci * details and the thinking behind the implementation.
908c2ecf20Sopenharmony_ci *
918c2ecf20Sopenharmony_ci * Implementation goals :
928c2ecf20Sopenharmony_ci * --------------------
938c2ecf20Sopenharmony_ci * The implementation goals were as follow :
948c2ecf20Sopenharmony_ci *	o Obvious : you should not need a PhD to understand what's happening,
958c2ecf20Sopenharmony_ci *		the benefit is easier maintenance.
968c2ecf20Sopenharmony_ci *	o Flexible : it should accommodate a wide variety of driver
978c2ecf20Sopenharmony_ci *		implementations and be as flexible as the old API.
988c2ecf20Sopenharmony_ci *	o Lean : it should be efficient memory wise to minimise the impact
998c2ecf20Sopenharmony_ci *		on kernel footprint.
1008c2ecf20Sopenharmony_ci *	o Transparent to user space : the large number of user space
1018c2ecf20Sopenharmony_ci *		applications that use Wireless Extensions should not need
1028c2ecf20Sopenharmony_ci *		any modifications.
1038c2ecf20Sopenharmony_ci *
1048c2ecf20Sopenharmony_ci * Array of functions versus Struct of functions
1058c2ecf20Sopenharmony_ci * ---------------------------------------------
1068c2ecf20Sopenharmony_ci * 1) Having an array of functions allow the kernel code to access the
1078c2ecf20Sopenharmony_ci * handler in a single lookup, which is much more efficient (think hash
1088c2ecf20Sopenharmony_ci * table here).
1098c2ecf20Sopenharmony_ci * 2) The only drawback is that driver writer may put their handler in
1108c2ecf20Sopenharmony_ci * the wrong slot. This is trivial to test (I set the frequency, the
1118c2ecf20Sopenharmony_ci * bitrate changes). Once the handler is in the proper slot, it will be
1128c2ecf20Sopenharmony_ci * there forever, because the array is only extended at the end.
1138c2ecf20Sopenharmony_ci * 3) Backward/forward compatibility : adding new handler just require
1148c2ecf20Sopenharmony_ci * extending the array, so you can put newer driver in older kernel
1158c2ecf20Sopenharmony_ci * without having to patch the kernel code (and vice versa).
1168c2ecf20Sopenharmony_ci *
1178c2ecf20Sopenharmony_ci * All handler are of the same generic type
1188c2ecf20Sopenharmony_ci * ----------------------------------------
1198c2ecf20Sopenharmony_ci * That's a feature !!!
1208c2ecf20Sopenharmony_ci * 1) Having a generic handler allow to have generic code, which is more
1218c2ecf20Sopenharmony_ci * efficient. If each of the handler was individually typed I would need
1228c2ecf20Sopenharmony_ci * to add a big switch in the kernel (== more bloat). This solution is
1238c2ecf20Sopenharmony_ci * more scalable, adding new Wireless Extensions doesn't add new code.
1248c2ecf20Sopenharmony_ci * 2) You can use the same handler in different slots of the array. For
1258c2ecf20Sopenharmony_ci * hardware, it may be more efficient or logical to handle multiple
1268c2ecf20Sopenharmony_ci * Wireless Extensions with a single function, and the API allow you to
1278c2ecf20Sopenharmony_ci * do that. (An example would be a single record on the card to control
1288c2ecf20Sopenharmony_ci * both bitrate and frequency, the handler would read the old record,
1298c2ecf20Sopenharmony_ci * modify it according to info->cmd and rewrite it).
1308c2ecf20Sopenharmony_ci *
1318c2ecf20Sopenharmony_ci * Functions prototype uses union iwreq_data
1328c2ecf20Sopenharmony_ci * -----------------------------------------
1338c2ecf20Sopenharmony_ci * Some would have preferred functions defined this way :
1348c2ecf20Sopenharmony_ci *	static int mydriver_ioctl_setrate(struct net_device *dev,
1358c2ecf20Sopenharmony_ci *					  long rate, int auto)
1368c2ecf20Sopenharmony_ci * 1) The kernel code doesn't "validate" the content of iwreq_data, and
1378c2ecf20Sopenharmony_ci * can't do it (different hardware may have different notion of what a
1388c2ecf20Sopenharmony_ci * valid frequency is), so we don't pretend that we do it.
1398c2ecf20Sopenharmony_ci * 2) The above form is not extendable. If I want to add a flag (for
1408c2ecf20Sopenharmony_ci * example to distinguish setting max rate and basic rate), I would
1418c2ecf20Sopenharmony_ci * break the prototype. Using iwreq_data is more flexible.
1428c2ecf20Sopenharmony_ci * 3) Also, the above form is not generic (see above).
1438c2ecf20Sopenharmony_ci * 4) I don't expect driver developper using the wrong field of the
1448c2ecf20Sopenharmony_ci * union (Doh !), so static typechecking doesn't add much value.
1458c2ecf20Sopenharmony_ci * 5) Lastly, you can skip the union by doing :
1468c2ecf20Sopenharmony_ci *	static int mydriver_ioctl_setrate(struct net_device *dev,
1478c2ecf20Sopenharmony_ci *					  struct iw_request_info *info,
1488c2ecf20Sopenharmony_ci *					  struct iw_param *rrq,
1498c2ecf20Sopenharmony_ci *					  char *extra)
1508c2ecf20Sopenharmony_ci * And then adding the handler in the array like this :
1518c2ecf20Sopenharmony_ci *        (iw_handler) mydriver_ioctl_setrate,             // SIOCSIWRATE
1528c2ecf20Sopenharmony_ci *
1538c2ecf20Sopenharmony_ci * Using functions and not a registry
1548c2ecf20Sopenharmony_ci * ----------------------------------
1558c2ecf20Sopenharmony_ci * Another implementation option would have been for every instance to
1568c2ecf20Sopenharmony_ci * define a registry (a struct containing all the Wireless Extensions)
1578c2ecf20Sopenharmony_ci * and only have a function to commit the registry to the hardware.
1588c2ecf20Sopenharmony_ci * 1) This approach can be emulated by the current code, but not
1598c2ecf20Sopenharmony_ci * vice versa.
1608c2ecf20Sopenharmony_ci * 2) Some drivers don't keep any configuration in the driver, for them
1618c2ecf20Sopenharmony_ci * adding such a registry would be a significant bloat.
1628c2ecf20Sopenharmony_ci * 3) The code to translate from Wireless Extension to native format is
1638c2ecf20Sopenharmony_ci * needed anyway, so it would not reduce significantely the amount of code.
1648c2ecf20Sopenharmony_ci * 4) The current approach only selectively translate Wireless Extensions
1658c2ecf20Sopenharmony_ci * to native format and only selectively set, whereas the registry approach
1668c2ecf20Sopenharmony_ci * would require to translate all WE and set all parameters for any single
1678c2ecf20Sopenharmony_ci * change.
1688c2ecf20Sopenharmony_ci * 5) For many Wireless Extensions, the GET operation return the current
1698c2ecf20Sopenharmony_ci * dynamic value, not the value that was set.
1708c2ecf20Sopenharmony_ci *
1718c2ecf20Sopenharmony_ci * This header is <net/iw_handler.h>
1728c2ecf20Sopenharmony_ci * ---------------------------------
1738c2ecf20Sopenharmony_ci * 1) This header is kernel space only and should not be exported to
1748c2ecf20Sopenharmony_ci * user space. Headers in "include/linux/" are exported, headers in
1758c2ecf20Sopenharmony_ci * "include/net/" are not.
1768c2ecf20Sopenharmony_ci *
1778c2ecf20Sopenharmony_ci * Mixed 32/64 bit issues
1788c2ecf20Sopenharmony_ci * ----------------------
1798c2ecf20Sopenharmony_ci * The Wireless Extensions are designed to be 64 bit clean, by using only
1808c2ecf20Sopenharmony_ci * datatypes with explicit storage size.
1818c2ecf20Sopenharmony_ci * There are some issues related to kernel and user space using different
1828c2ecf20Sopenharmony_ci * memory model, and in particular 64bit kernel with 32bit user space.
1838c2ecf20Sopenharmony_ci * The problem is related to struct iw_point, that contains a pointer
1848c2ecf20Sopenharmony_ci * that *may* need to be translated.
1858c2ecf20Sopenharmony_ci * This is quite messy. The new API doesn't solve this problem (it can't),
1868c2ecf20Sopenharmony_ci * but is a step in the right direction :
1878c2ecf20Sopenharmony_ci * 1) Meta data about each ioctl is easily available, so we know what type
1888c2ecf20Sopenharmony_ci * of translation is needed.
1898c2ecf20Sopenharmony_ci * 2) The move of data between kernel and user space is only done in a single
1908c2ecf20Sopenharmony_ci * place in the kernel, so adding specific hooks in there is possible.
1918c2ecf20Sopenharmony_ci * 3) In the long term, it allows to move away from using ioctl as the
1928c2ecf20Sopenharmony_ci * user space API.
1938c2ecf20Sopenharmony_ci *
1948c2ecf20Sopenharmony_ci * So many comments and so few code
1958c2ecf20Sopenharmony_ci * --------------------------------
1968c2ecf20Sopenharmony_ci * That's a feature. Comments won't bloat the resulting kernel binary.
1978c2ecf20Sopenharmony_ci */
1988c2ecf20Sopenharmony_ci
1998c2ecf20Sopenharmony_ci/***************************** INCLUDES *****************************/
2008c2ecf20Sopenharmony_ci
2018c2ecf20Sopenharmony_ci#include <linux/wireless.h>		/* IOCTL user space API */
2028c2ecf20Sopenharmony_ci#include <linux/if_ether.h>
2038c2ecf20Sopenharmony_ci
2048c2ecf20Sopenharmony_ci/***************************** VERSION *****************************/
2058c2ecf20Sopenharmony_ci/*
2068c2ecf20Sopenharmony_ci * This constant is used to know which version of the driver API is
2078c2ecf20Sopenharmony_ci * available. Hopefully, this will be pretty stable and no changes
2088c2ecf20Sopenharmony_ci * will be needed...
2098c2ecf20Sopenharmony_ci * I just plan to increment with each new version.
2108c2ecf20Sopenharmony_ci */
2118c2ecf20Sopenharmony_ci#define IW_HANDLER_VERSION	8
2128c2ecf20Sopenharmony_ci
2138c2ecf20Sopenharmony_ci/*
2148c2ecf20Sopenharmony_ci * Changes :
2158c2ecf20Sopenharmony_ci *
2168c2ecf20Sopenharmony_ci * V2 to V3
2178c2ecf20Sopenharmony_ci * --------
2188c2ecf20Sopenharmony_ci *	- Move event definition in <linux/wireless.h>
2198c2ecf20Sopenharmony_ci *	- Add Wireless Event support :
2208c2ecf20Sopenharmony_ci *		o wireless_send_event() prototype
2218c2ecf20Sopenharmony_ci *		o iwe_stream_add_event/point() inline functions
2228c2ecf20Sopenharmony_ci * V3 to V4
2238c2ecf20Sopenharmony_ci * --------
2248c2ecf20Sopenharmony_ci *	- Reshuffle IW_HEADER_TYPE_XXX to map IW_PRIV_TYPE_XXX changes
2258c2ecf20Sopenharmony_ci *
2268c2ecf20Sopenharmony_ci * V4 to V5
2278c2ecf20Sopenharmony_ci * --------
2288c2ecf20Sopenharmony_ci *	- Add new spy support : struct iw_spy_data & prototypes
2298c2ecf20Sopenharmony_ci *
2308c2ecf20Sopenharmony_ci * V5 to V6
2318c2ecf20Sopenharmony_ci * --------
2328c2ecf20Sopenharmony_ci *	- Change the way we get to spy_data method for added safety
2338c2ecf20Sopenharmony_ci *	- Remove spy #ifdef, they are always on -> cleaner code
2348c2ecf20Sopenharmony_ci *	- Add IW_DESCR_FLAG_NOMAX flag for very large requests
2358c2ecf20Sopenharmony_ci *	- Start migrating get_wireless_stats to struct iw_handler_def
2368c2ecf20Sopenharmony_ci *
2378c2ecf20Sopenharmony_ci * V6 to V7
2388c2ecf20Sopenharmony_ci * --------
2398c2ecf20Sopenharmony_ci *	- Add struct ieee80211_device pointer in struct iw_public_data
2408c2ecf20Sopenharmony_ci *	- Remove (struct iw_point *)->pointer from events and streams
2418c2ecf20Sopenharmony_ci *	- Remove spy_offset from struct iw_handler_def
2428c2ecf20Sopenharmony_ci *	- Add "check" version of event macros for ieee802.11 stack
2438c2ecf20Sopenharmony_ci *
2448c2ecf20Sopenharmony_ci * V7 to V8
2458c2ecf20Sopenharmony_ci * ----------
2468c2ecf20Sopenharmony_ci *	- Prevent leaking of kernel space in stream on 64 bits.
2478c2ecf20Sopenharmony_ci */
2488c2ecf20Sopenharmony_ci
2498c2ecf20Sopenharmony_ci/**************************** CONSTANTS ****************************/
2508c2ecf20Sopenharmony_ci
2518c2ecf20Sopenharmony_ci/* Enhanced spy support available */
2528c2ecf20Sopenharmony_ci#define IW_WIRELESS_SPY
2538c2ecf20Sopenharmony_ci#define IW_WIRELESS_THRSPY
2548c2ecf20Sopenharmony_ci
2558c2ecf20Sopenharmony_ci/* Special error message for the driver to indicate that we
2568c2ecf20Sopenharmony_ci * should do a commit after return from the iw_handler */
2578c2ecf20Sopenharmony_ci#define EIWCOMMIT	EINPROGRESS
2588c2ecf20Sopenharmony_ci
2598c2ecf20Sopenharmony_ci/* Flags available in struct iw_request_info */
2608c2ecf20Sopenharmony_ci#define IW_REQUEST_FLAG_COMPAT	0x0001	/* Compat ioctl call */
2618c2ecf20Sopenharmony_ci
2628c2ecf20Sopenharmony_ci/* Type of headers we know about (basically union iwreq_data) */
2638c2ecf20Sopenharmony_ci#define IW_HEADER_TYPE_NULL	0	/* Not available */
2648c2ecf20Sopenharmony_ci#define IW_HEADER_TYPE_CHAR	2	/* char [IFNAMSIZ] */
2658c2ecf20Sopenharmony_ci#define IW_HEADER_TYPE_UINT	4	/* __u32 */
2668c2ecf20Sopenharmony_ci#define IW_HEADER_TYPE_FREQ	5	/* struct iw_freq */
2678c2ecf20Sopenharmony_ci#define IW_HEADER_TYPE_ADDR	6	/* struct sockaddr */
2688c2ecf20Sopenharmony_ci#define IW_HEADER_TYPE_POINT	8	/* struct iw_point */
2698c2ecf20Sopenharmony_ci#define IW_HEADER_TYPE_PARAM	9	/* struct iw_param */
2708c2ecf20Sopenharmony_ci#define IW_HEADER_TYPE_QUAL	10	/* struct iw_quality */
2718c2ecf20Sopenharmony_ci
2728c2ecf20Sopenharmony_ci/* Handling flags */
2738c2ecf20Sopenharmony_ci/* Most are not implemented. I just use them as a reminder of some
2748c2ecf20Sopenharmony_ci * cool features we might need one day ;-) */
2758c2ecf20Sopenharmony_ci#define IW_DESCR_FLAG_NONE	0x0000	/* Obvious */
2768c2ecf20Sopenharmony_ci/* Wrapper level flags */
2778c2ecf20Sopenharmony_ci#define IW_DESCR_FLAG_DUMP	0x0001	/* Not part of the dump command */
2788c2ecf20Sopenharmony_ci#define IW_DESCR_FLAG_EVENT	0x0002	/* Generate an event on SET */
2798c2ecf20Sopenharmony_ci#define IW_DESCR_FLAG_RESTRICT	0x0004	/* GET : request is ROOT only */
2808c2ecf20Sopenharmony_ci				/* SET : Omit payload from generated iwevent */
2818c2ecf20Sopenharmony_ci#define IW_DESCR_FLAG_NOMAX	0x0008	/* GET : no limit on request size */
2828c2ecf20Sopenharmony_ci/* Driver level flags */
2838c2ecf20Sopenharmony_ci#define IW_DESCR_FLAG_WAIT	0x0100	/* Wait for driver event */
2848c2ecf20Sopenharmony_ci
2858c2ecf20Sopenharmony_ci/****************************** TYPES ******************************/
2868c2ecf20Sopenharmony_ci
2878c2ecf20Sopenharmony_ci/* ----------------------- WIRELESS HANDLER ----------------------- */
2888c2ecf20Sopenharmony_ci/*
2898c2ecf20Sopenharmony_ci * A wireless handler is just a standard function, that looks like the
2908c2ecf20Sopenharmony_ci * ioctl handler.
2918c2ecf20Sopenharmony_ci * We also define there how a handler list look like... As the Wireless
2928c2ecf20Sopenharmony_ci * Extension space is quite dense, we use a simple array, which is faster
2938c2ecf20Sopenharmony_ci * (that's the perfect hash table ;-).
2948c2ecf20Sopenharmony_ci */
2958c2ecf20Sopenharmony_ci
2968c2ecf20Sopenharmony_ci/*
2978c2ecf20Sopenharmony_ci * Meta data about the request passed to the iw_handler.
2988c2ecf20Sopenharmony_ci * Most handlers can safely ignore what's in there.
2998c2ecf20Sopenharmony_ci * The 'cmd' field might come handy if you want to use the same handler
3008c2ecf20Sopenharmony_ci * for multiple command...
3018c2ecf20Sopenharmony_ci * This struct is also my long term insurance. I can add new fields here
3028c2ecf20Sopenharmony_ci * without breaking the prototype of iw_handler...
3038c2ecf20Sopenharmony_ci */
3048c2ecf20Sopenharmony_cistruct iw_request_info {
3058c2ecf20Sopenharmony_ci	__u16		cmd;		/* Wireless Extension command */
3068c2ecf20Sopenharmony_ci	__u16		flags;		/* More to come ;-) */
3078c2ecf20Sopenharmony_ci};
3088c2ecf20Sopenharmony_ci
3098c2ecf20Sopenharmony_cistruct net_device;
3108c2ecf20Sopenharmony_ci
3118c2ecf20Sopenharmony_ci/*
3128c2ecf20Sopenharmony_ci * This is how a function handling a Wireless Extension should look
3138c2ecf20Sopenharmony_ci * like (both get and set, standard and private).
3148c2ecf20Sopenharmony_ci */
3158c2ecf20Sopenharmony_citypedef int (*iw_handler)(struct net_device *dev, struct iw_request_info *info,
3168c2ecf20Sopenharmony_ci			  union iwreq_data *wrqu, char *extra);
3178c2ecf20Sopenharmony_ci
3188c2ecf20Sopenharmony_ci/*
3198c2ecf20Sopenharmony_ci * This define all the handler that the driver export.
3208c2ecf20Sopenharmony_ci * As you need only one per driver type, please use a static const
3218c2ecf20Sopenharmony_ci * shared by all driver instances... Same for the members...
3228c2ecf20Sopenharmony_ci * This will be linked from net_device in <linux/netdevice.h>
3238c2ecf20Sopenharmony_ci */
3248c2ecf20Sopenharmony_cistruct iw_handler_def {
3258c2ecf20Sopenharmony_ci
3268c2ecf20Sopenharmony_ci	/* Array of handlers for standard ioctls
3278c2ecf20Sopenharmony_ci	 * We will call dev->wireless_handlers->standard[ioctl - SIOCIWFIRST]
3288c2ecf20Sopenharmony_ci	 */
3298c2ecf20Sopenharmony_ci	const iw_handler *	standard;
3308c2ecf20Sopenharmony_ci	/* Number of handlers defined (more precisely, index of the
3318c2ecf20Sopenharmony_ci	 * last defined handler + 1) */
3328c2ecf20Sopenharmony_ci	__u16			num_standard;
3338c2ecf20Sopenharmony_ci
3348c2ecf20Sopenharmony_ci#ifdef CONFIG_WEXT_PRIV
3358c2ecf20Sopenharmony_ci	__u16			num_private;
3368c2ecf20Sopenharmony_ci	/* Number of private arg description */
3378c2ecf20Sopenharmony_ci	__u16			num_private_args;
3388c2ecf20Sopenharmony_ci	/* Array of handlers for private ioctls
3398c2ecf20Sopenharmony_ci	 * Will call dev->wireless_handlers->private[ioctl - SIOCIWFIRSTPRIV]
3408c2ecf20Sopenharmony_ci	 */
3418c2ecf20Sopenharmony_ci	const iw_handler *	private;
3428c2ecf20Sopenharmony_ci
3438c2ecf20Sopenharmony_ci	/* Arguments of private handler. This one is just a list, so you
3448c2ecf20Sopenharmony_ci	 * can put it in any order you want and should not leave holes...
3458c2ecf20Sopenharmony_ci	 * We will automatically export that to user space... */
3468c2ecf20Sopenharmony_ci	const struct iw_priv_args *	private_args;
3478c2ecf20Sopenharmony_ci#endif
3488c2ecf20Sopenharmony_ci
3498c2ecf20Sopenharmony_ci	/* New location of get_wireless_stats, to de-bloat struct net_device.
3508c2ecf20Sopenharmony_ci	 * The old pointer in struct net_device will be gradually phased
3518c2ecf20Sopenharmony_ci	 * out, and drivers are encouraged to use this one... */
3528c2ecf20Sopenharmony_ci	struct iw_statistics*	(*get_wireless_stats)(struct net_device *dev);
3538c2ecf20Sopenharmony_ci};
3548c2ecf20Sopenharmony_ci
3558c2ecf20Sopenharmony_ci/* ---------------------- IOCTL DESCRIPTION ---------------------- */
3568c2ecf20Sopenharmony_ci/*
3578c2ecf20Sopenharmony_ci * One of the main goal of the new interface is to deal entirely with
3588c2ecf20Sopenharmony_ci * user space/kernel space memory move.
3598c2ecf20Sopenharmony_ci * For that, we need to know :
3608c2ecf20Sopenharmony_ci *	o if iwreq is a pointer or contain the full data
3618c2ecf20Sopenharmony_ci *	o what is the size of the data to copy
3628c2ecf20Sopenharmony_ci *
3638c2ecf20Sopenharmony_ci * For private IOCTLs, we use the same rules as used by iwpriv and
3648c2ecf20Sopenharmony_ci * defined in struct iw_priv_args.
3658c2ecf20Sopenharmony_ci *
3668c2ecf20Sopenharmony_ci * For standard IOCTLs, things are quite different and we need to
3678c2ecf20Sopenharmony_ci * use the structures below. Actually, this struct is also more
3688c2ecf20Sopenharmony_ci * efficient, but that's another story...
3698c2ecf20Sopenharmony_ci */
3708c2ecf20Sopenharmony_ci
3718c2ecf20Sopenharmony_ci/*
3728c2ecf20Sopenharmony_ci * Describe how a standard IOCTL looks like.
3738c2ecf20Sopenharmony_ci */
3748c2ecf20Sopenharmony_cistruct iw_ioctl_description {
3758c2ecf20Sopenharmony_ci	__u8	header_type;		/* NULL, iw_point or other */
3768c2ecf20Sopenharmony_ci	__u8	token_type;		/* Future */
3778c2ecf20Sopenharmony_ci	__u16	token_size;		/* Granularity of payload */
3788c2ecf20Sopenharmony_ci	__u16	min_tokens;		/* Min acceptable token number */
3798c2ecf20Sopenharmony_ci	__u16	max_tokens;		/* Max acceptable token number */
3808c2ecf20Sopenharmony_ci	__u32	flags;			/* Special handling of the request */
3818c2ecf20Sopenharmony_ci};
3828c2ecf20Sopenharmony_ci
3838c2ecf20Sopenharmony_ci/* Need to think of short header translation table. Later. */
3848c2ecf20Sopenharmony_ci
3858c2ecf20Sopenharmony_ci/* --------------------- ENHANCED SPY SUPPORT --------------------- */
3868c2ecf20Sopenharmony_ci/*
3878c2ecf20Sopenharmony_ci * In the old days, the driver was handling spy support all by itself.
3888c2ecf20Sopenharmony_ci * Now, the driver can delegate this task to Wireless Extensions.
3898c2ecf20Sopenharmony_ci * It needs to include this struct in its private part and use the
3908c2ecf20Sopenharmony_ci * standard spy iw_handler.
3918c2ecf20Sopenharmony_ci */
3928c2ecf20Sopenharmony_ci
3938c2ecf20Sopenharmony_ci/*
3948c2ecf20Sopenharmony_ci * Instance specific spy data, i.e. addresses spied and quality for them.
3958c2ecf20Sopenharmony_ci */
3968c2ecf20Sopenharmony_cistruct iw_spy_data {
3978c2ecf20Sopenharmony_ci	/* --- Standard spy support --- */
3988c2ecf20Sopenharmony_ci	int			spy_number;
3998c2ecf20Sopenharmony_ci	u_char			spy_address[IW_MAX_SPY][ETH_ALEN];
4008c2ecf20Sopenharmony_ci	struct iw_quality	spy_stat[IW_MAX_SPY];
4018c2ecf20Sopenharmony_ci	/* --- Enhanced spy support (event) */
4028c2ecf20Sopenharmony_ci	struct iw_quality	spy_thr_low;	/* Low threshold */
4038c2ecf20Sopenharmony_ci	struct iw_quality	spy_thr_high;	/* High threshold */
4048c2ecf20Sopenharmony_ci	u_char			spy_thr_under[IW_MAX_SPY];
4058c2ecf20Sopenharmony_ci};
4068c2ecf20Sopenharmony_ci
4078c2ecf20Sopenharmony_ci/* --------------------- DEVICE WIRELESS DATA --------------------- */
4088c2ecf20Sopenharmony_ci/*
4098c2ecf20Sopenharmony_ci * This is all the wireless data specific to a device instance that
4108c2ecf20Sopenharmony_ci * is managed by the core of Wireless Extensions or the 802.11 layer.
4118c2ecf20Sopenharmony_ci * We only keep pointer to those structures, so that a driver is free
4128c2ecf20Sopenharmony_ci * to share them between instances.
4138c2ecf20Sopenharmony_ci * This structure should be initialised before registering the device.
4148c2ecf20Sopenharmony_ci * Access to this data follow the same rules as any other struct net_device
4158c2ecf20Sopenharmony_ci * data (i.e. valid as long as struct net_device exist, same locking rules).
4168c2ecf20Sopenharmony_ci */
4178c2ecf20Sopenharmony_ci/* Forward declaration */
4188c2ecf20Sopenharmony_cistruct libipw_device;
4198c2ecf20Sopenharmony_ci/* The struct */
4208c2ecf20Sopenharmony_cistruct iw_public_data {
4218c2ecf20Sopenharmony_ci	/* Driver enhanced spy support */
4228c2ecf20Sopenharmony_ci	struct iw_spy_data *		spy_data;
4238c2ecf20Sopenharmony_ci	/* Legacy structure managed by the ipw2x00-specific IEEE 802.11 layer */
4248c2ecf20Sopenharmony_ci	struct libipw_device *		libipw;
4258c2ecf20Sopenharmony_ci};
4268c2ecf20Sopenharmony_ci
4278c2ecf20Sopenharmony_ci/**************************** PROTOTYPES ****************************/
4288c2ecf20Sopenharmony_ci/*
4298c2ecf20Sopenharmony_ci * Functions part of the Wireless Extensions (defined in net/core/wireless.c).
4308c2ecf20Sopenharmony_ci * Those may be called only within the kernel.
4318c2ecf20Sopenharmony_ci */
4328c2ecf20Sopenharmony_ci
4338c2ecf20Sopenharmony_ci/* First : function strictly used inside the kernel */
4348c2ecf20Sopenharmony_ci
4358c2ecf20Sopenharmony_ci/* Handle /proc/net/wireless, called in net/code/dev.c */
4368c2ecf20Sopenharmony_ciint dev_get_wireless_info(char *buffer, char **start, off_t offset, int length);
4378c2ecf20Sopenharmony_ci
4388c2ecf20Sopenharmony_ci/* Second : functions that may be called by driver modules */
4398c2ecf20Sopenharmony_ci
4408c2ecf20Sopenharmony_ci/* Send a single event to user space */
4418c2ecf20Sopenharmony_civoid wireless_send_event(struct net_device *dev, unsigned int cmd,
4428c2ecf20Sopenharmony_ci			 union iwreq_data *wrqu, const char *extra);
4438c2ecf20Sopenharmony_ci#ifdef CONFIG_WEXT_CORE
4448c2ecf20Sopenharmony_ci/* flush all previous wext events - if work is done from netdev notifiers */
4458c2ecf20Sopenharmony_civoid wireless_nlevent_flush(void);
4468c2ecf20Sopenharmony_ci#else
4478c2ecf20Sopenharmony_cistatic inline void wireless_nlevent_flush(void) {}
4488c2ecf20Sopenharmony_ci#endif
4498c2ecf20Sopenharmony_ci
4508c2ecf20Sopenharmony_ci/* We may need a function to send a stream of events to user space.
4518c2ecf20Sopenharmony_ci * More on that later... */
4528c2ecf20Sopenharmony_ci
4538c2ecf20Sopenharmony_ci/* Standard handler for SIOCSIWSPY */
4548c2ecf20Sopenharmony_ciint iw_handler_set_spy(struct net_device *dev, struct iw_request_info *info,
4558c2ecf20Sopenharmony_ci		       union iwreq_data *wrqu, char *extra);
4568c2ecf20Sopenharmony_ci/* Standard handler for SIOCGIWSPY */
4578c2ecf20Sopenharmony_ciint iw_handler_get_spy(struct net_device *dev, struct iw_request_info *info,
4588c2ecf20Sopenharmony_ci		       union iwreq_data *wrqu, char *extra);
4598c2ecf20Sopenharmony_ci/* Standard handler for SIOCSIWTHRSPY */
4608c2ecf20Sopenharmony_ciint iw_handler_set_thrspy(struct net_device *dev, struct iw_request_info *info,
4618c2ecf20Sopenharmony_ci			  union iwreq_data *wrqu, char *extra);
4628c2ecf20Sopenharmony_ci/* Standard handler for SIOCGIWTHRSPY */
4638c2ecf20Sopenharmony_ciint iw_handler_get_thrspy(struct net_device *dev, struct iw_request_info *info,
4648c2ecf20Sopenharmony_ci			  union iwreq_data *wrqu, char *extra);
4658c2ecf20Sopenharmony_ci/* Driver call to update spy records */
4668c2ecf20Sopenharmony_civoid wireless_spy_update(struct net_device *dev, unsigned char *address,
4678c2ecf20Sopenharmony_ci			 struct iw_quality *wstats);
4688c2ecf20Sopenharmony_ci
4698c2ecf20Sopenharmony_ci/************************* INLINE FUNTIONS *************************/
4708c2ecf20Sopenharmony_ci/*
4718c2ecf20Sopenharmony_ci * Function that are so simple that it's more efficient inlining them
4728c2ecf20Sopenharmony_ci */
4738c2ecf20Sopenharmony_ci
4748c2ecf20Sopenharmony_cistatic inline int iwe_stream_lcp_len(struct iw_request_info *info)
4758c2ecf20Sopenharmony_ci{
4768c2ecf20Sopenharmony_ci#ifdef CONFIG_COMPAT
4778c2ecf20Sopenharmony_ci	if (info->flags & IW_REQUEST_FLAG_COMPAT)
4788c2ecf20Sopenharmony_ci		return IW_EV_COMPAT_LCP_LEN;
4798c2ecf20Sopenharmony_ci#endif
4808c2ecf20Sopenharmony_ci	return IW_EV_LCP_LEN;
4818c2ecf20Sopenharmony_ci}
4828c2ecf20Sopenharmony_ci
4838c2ecf20Sopenharmony_cistatic inline int iwe_stream_point_len(struct iw_request_info *info)
4848c2ecf20Sopenharmony_ci{
4858c2ecf20Sopenharmony_ci#ifdef CONFIG_COMPAT
4868c2ecf20Sopenharmony_ci	if (info->flags & IW_REQUEST_FLAG_COMPAT)
4878c2ecf20Sopenharmony_ci		return IW_EV_COMPAT_POINT_LEN;
4888c2ecf20Sopenharmony_ci#endif
4898c2ecf20Sopenharmony_ci	return IW_EV_POINT_LEN;
4908c2ecf20Sopenharmony_ci}
4918c2ecf20Sopenharmony_ci
4928c2ecf20Sopenharmony_cistatic inline int iwe_stream_event_len_adjust(struct iw_request_info *info,
4938c2ecf20Sopenharmony_ci					      int event_len)
4948c2ecf20Sopenharmony_ci{
4958c2ecf20Sopenharmony_ci#ifdef CONFIG_COMPAT
4968c2ecf20Sopenharmony_ci	if (info->flags & IW_REQUEST_FLAG_COMPAT) {
4978c2ecf20Sopenharmony_ci		event_len -= IW_EV_LCP_LEN;
4988c2ecf20Sopenharmony_ci		event_len += IW_EV_COMPAT_LCP_LEN;
4998c2ecf20Sopenharmony_ci	}
5008c2ecf20Sopenharmony_ci#endif
5018c2ecf20Sopenharmony_ci
5028c2ecf20Sopenharmony_ci	return event_len;
5038c2ecf20Sopenharmony_ci}
5048c2ecf20Sopenharmony_ci
5058c2ecf20Sopenharmony_ci/*------------------------------------------------------------------*/
5068c2ecf20Sopenharmony_ci/*
5078c2ecf20Sopenharmony_ci * Wrapper to add an Wireless Event to a stream of events.
5088c2ecf20Sopenharmony_ci */
5098c2ecf20Sopenharmony_cichar *iwe_stream_add_event(struct iw_request_info *info, char *stream,
5108c2ecf20Sopenharmony_ci			   char *ends, struct iw_event *iwe, int event_len);
5118c2ecf20Sopenharmony_ci
5128c2ecf20Sopenharmony_cistatic inline char *
5138c2ecf20Sopenharmony_ciiwe_stream_add_event_check(struct iw_request_info *info, char *stream,
5148c2ecf20Sopenharmony_ci			   char *ends, struct iw_event *iwe, int event_len)
5158c2ecf20Sopenharmony_ci{
5168c2ecf20Sopenharmony_ci	char *res = iwe_stream_add_event(info, stream, ends, iwe, event_len);
5178c2ecf20Sopenharmony_ci
5188c2ecf20Sopenharmony_ci	if (res == stream)
5198c2ecf20Sopenharmony_ci		return ERR_PTR(-E2BIG);
5208c2ecf20Sopenharmony_ci	return res;
5218c2ecf20Sopenharmony_ci}
5228c2ecf20Sopenharmony_ci
5238c2ecf20Sopenharmony_ci/*------------------------------------------------------------------*/
5248c2ecf20Sopenharmony_ci/*
5258c2ecf20Sopenharmony_ci * Wrapper to add an short Wireless Event containing a pointer to a
5268c2ecf20Sopenharmony_ci * stream of events.
5278c2ecf20Sopenharmony_ci */
5288c2ecf20Sopenharmony_cichar *iwe_stream_add_point(struct iw_request_info *info, char *stream,
5298c2ecf20Sopenharmony_ci			   char *ends, struct iw_event *iwe, char *extra);
5308c2ecf20Sopenharmony_ci
5318c2ecf20Sopenharmony_cistatic inline char *
5328c2ecf20Sopenharmony_ciiwe_stream_add_point_check(struct iw_request_info *info, char *stream,
5338c2ecf20Sopenharmony_ci			   char *ends, struct iw_event *iwe, char *extra)
5348c2ecf20Sopenharmony_ci{
5358c2ecf20Sopenharmony_ci	char *res = iwe_stream_add_point(info, stream, ends, iwe, extra);
5368c2ecf20Sopenharmony_ci
5378c2ecf20Sopenharmony_ci	if (res == stream)
5388c2ecf20Sopenharmony_ci		return ERR_PTR(-E2BIG);
5398c2ecf20Sopenharmony_ci	return res;
5408c2ecf20Sopenharmony_ci}
5418c2ecf20Sopenharmony_ci
5428c2ecf20Sopenharmony_ci/*------------------------------------------------------------------*/
5438c2ecf20Sopenharmony_ci/*
5448c2ecf20Sopenharmony_ci * Wrapper to add a value to a Wireless Event in a stream of events.
5458c2ecf20Sopenharmony_ci * Be careful, this one is tricky to use properly :
5468c2ecf20Sopenharmony_ci * At the first run, you need to have (value = event + IW_EV_LCP_LEN).
5478c2ecf20Sopenharmony_ci */
5488c2ecf20Sopenharmony_cichar *iwe_stream_add_value(struct iw_request_info *info, char *event,
5498c2ecf20Sopenharmony_ci			   char *value, char *ends, struct iw_event *iwe,
5508c2ecf20Sopenharmony_ci			   int event_len);
5518c2ecf20Sopenharmony_ci
5528c2ecf20Sopenharmony_ci#endif	/* _IW_HANDLER_H */
553