github.com/jlowellwofford/u-root@v1.0.0/pkg/wifi/wireless.go (about)

     1  // Copyright 2018 the u-root Authors. All rights reserved
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package wifi
     6  
     7  import "unsafe" // yuck
     8  // This file is from the linux wifi definitions. We leave the
     9  // original in here for reference.  We'll probably remove it later.
    10  var _ = `
    11  /*
    12   * This file define a set of standard wireless extensions
    13   *
    14   * Version :	22	16.3.07
    15   *
    16   * Authors :	Jean Tourrilhes - HPL - <jt@hpl.hp.com>
    17   * Copyright (c) 1997-2007 Jean Tourrilhes, All Rights Reserved.
    18   */
    19  
    20  #ifndef _LINUX_WIRELESS_H
    21  #define _LINUX_WIRELESS_H
    22  
    23  /************************** DOCUMENTATION **************************/
    24  /*
    25   * Initial APIs (1996 -> onward) :
    26   * -----------------------------
    27   * Basically, the wireless extensions are for now a set of standard ioctl
    28   * call + /proc/net/wireless
    29   *
    30   * The entry /proc/net/wireless give statistics and information on the
    31   * driver.
    32   * This is better than having each driver having its entry because
    33   * its centralised and we may remove the driver module safely.
    34   *
    35   * Ioctl are used to configure the driver and issue commands.  This is
    36   * better than command line options of insmod because we may want to
    37   * change dynamically (while the driver is running) some parameters.
    38   *
    39   * The ioctl mechanimsm are copied from standard devices ioctl.
    40   * We have the list of command plus a structure descibing the
    41   * data exchanged...
    42   * Note that to add these ioctl, I was obliged to modify :
    43   *	# net/core/dev.c (two place + add include)
    44   *	# net/ipv4/af_inet.c (one place + add include)
    45   *
    46   * /proc/net/wireless is a copy of /proc/net/dev.
    47   * We have a structure for data passed from the driver to /proc/net/wireless
    48   * Too add this, I've modified :
    49   *	# net/core/dev.c (two other places)
    50   *	# include/linux/netdevice.h (one place)
    51   *	# include/linux/proc_fs.h (one place)
    52   *
    53   * New driver API (2002 -> onward) :
    54   * -------------------------------
    55   * This file is only concerned with the user space API and common definitions.
    56   * The new driver API is defined and documented in :
    57   *	# include/net/iw_handler.h
    58   *
    59   * Note as well that /proc/net/wireless implementation has now moved in :
    60   *	# net/core/wireless.c
    61   *
    62   * Wireless Events (2002 -> onward) :
    63   * --------------------------------
    64   * Events are defined at the end of this file, and implemented in :
    65   *	# net/core/wireless.c
    66   *
    67   * Other comments :
    68   * --------------
    69   * Do not add here things that are redundant with other mechanisms
    70   * (drivers init, ifconfig, /proc/net/dev, ...) and with are not
    71   * wireless specific.
    72   *
    73   * These wireless extensions are not magic : each driver has to provide
    74   * support for them...
    75   *
    76   * IMPORTANT NOTE : As everything in the kernel, this is very much a
    77   * work in progress. Contact me if you have ideas of improvements...
    78   */
    79  
    80  /***************************** INCLUDES *****************************/
    81  
    82  #include <linux/types.h>		/* for __u* and __s* typedefs */
    83  #include <linux/socket.h>		/* for "struct sockaddr" et al	*/
    84  #include <linux/if.h>			/* for IFNAMSIZ and co... */
    85  
    86  /***************************** VERSION *****************************/
    87  /*
    88   * This constant is used to know the availability of the wireless
    89   * extensions and to know which version of wireless extensions it is
    90   * (there is some stuff that will be added in the future...)
    91   * I just plan to increment with each new version.
    92   */
    93  #define WIRELESS_EXT	22
    94  
    95  /*
    96   * Changes :
    97   *
    98   * V2 to V3
    99   * --------
   100   *	Alan Cox start some incompatibles changes. I've integrated a bit more.
   101   *	- Encryption renamed to Encode to avoid US regulation problems
   102   *	- Frequency changed from float to struct to avoid problems on old 386
   103   *
   104   * V3 to V4
   105   * --------
   106   *	- Add sensitivity
   107   *
   108   * V4 to V5
   109   * --------
   110   *	- Missing encoding definitions in range
   111   *	- Access points stuff
   112   *
   113   * V5 to V6
   114   * --------
   115   *	- 802.11 support (ESSID ioctls)
   116   *
   117   * V6 to V7
   118   * --------
   119   *	- define IW_ESSID_MAX_SIZE and IW_MAX_AP
   120   *
   121   * V7 to V8
   122   * --------
   123   *	- Changed my e-mail address
   124   *	- More 802.11 support (nickname, rate, rts, frag)
   125   *	- List index in frequencies
   126   *
   127   * V8 to V9
   128   * --------
   129   *	- Support for 'mode of operation' (ad-hoc, managed...)
   130   *	- Support for unicast and multicast power saving
   131   *	- Change encoding to support larger tokens (>64 bits)
   132   *	- Updated iw_params (disable, flags) and use it for NWID
   133   *	- Extracted iw_point from iwreq for clarity
   134   *
   135   * V9 to V10
   136   * ---------
   137   *	- Add PM capability to range structure
   138   *	- Add PM modifier : MAX/MIN/RELATIVE
   139   *	- Add encoding option : IW_ENCODE_NOKEY
   140   *	- Add TxPower ioctls (work like TxRate)
   141   *
   142   * V10 to V11
   143   * ----------
   144   *	- Add WE version in range (help backward/forward compatibility)
   145   *	- Add retry ioctls (work like PM)
   146   *
   147   * V11 to V12
   148   * ----------
   149   *	- Add SIOCSIWSTATS to get /proc/net/wireless programatically
   150   *	- Add DEV PRIVATE IOCTL to avoid collisions in SIOCDEVPRIVATE space
   151   *	- Add new statistics (frag, retry, beacon)
   152   *	- Add average quality (for user space calibration)
   153   *
   154   * V12 to V13
   155   * ----------
   156   *	- Document creation of new driver API.
   157   *	- Extract union iwreq_data from struct iwreq (for new driver API).
   158   *	- Rename SIOCSIWNAME as SIOCSIWCOMMIT
   159   *
   160   * V13 to V14
   161   * ----------
   162   *	- Wireless Events support : define struct iw_event
   163   *	- Define additional specific event numbers
   164   *	- Add "addr" and "param" fields in union iwreq_data
   165   *	- AP scanning stuff (SIOCSIWSCAN and friends)
   166   *
   167   * V14 to V15
   168   * ----------
   169   *	- Add IW_PRIV_TYPE_ADDR for struct sockaddr private arg
   170   *	- Make struct iw_freq signed (both m & e), add explicit padding
   171   *	- Add IWEVCUSTOM for driver specific event/scanning token
   172   *	- Add IW_MAX_GET_SPY for driver returning a lot of addresses
   173   *	- Add IW_TXPOW_RANGE for range of Tx Powers
   174   *	- Add IWEVREGISTERED & IWEVEXPIRED events for Access Points
   175   *	- Add IW_MODE_MONITOR for passive monitor
   176   *
   177   * V15 to V16
   178   * ----------
   179   *	- Increase the number of bitrates in iw_range to 32 (for 802.11g)
   180   *	- Increase the number of frequencies in iw_range to 32 (for 802.11b+a)
   181   *	- Reshuffle struct iw_range for increases, add filler
   182   *	- Increase IW_MAX_AP to 64 for driver returning a lot of addresses
   183   *	- Remove IW_MAX_GET_SPY because conflict with enhanced spy support
   184   *	- Add SIOCSIWTHRSPY/SIOCGIWTHRSPY and "struct iw_thrspy"
   185   *	- Add IW_ENCODE_TEMP and iw_range->encoding_login_index
   186   *
   187   * V16 to V17
   188   * ----------
   189   *	- Add flags to frequency -> auto/fixed
   190   *	- Document (struct iw_quality *)->updated, add new flags (INVALID)
   191   *	- Wireless Event capability in struct iw_range
   192   *	- Add support for relative TxPower (yick !)
   193   *
   194   * V17 to V18 (From Jouni Malinen <j@w1.fi>)
   195   * ----------
   196   *	- Add support for WPA/WPA2
   197   *	- Add extended encoding configuration (SIOCSIWENCODEEXT and
   198   *	  SIOCGIWENCODEEXT)
   199   *	- Add SIOCSIWGENIE/SIOCGIWGENIE
   200   *	- Add SIOCSIWMLME
   201   *	- Add SIOCSIWPMKSA
   202   *	- Add struct iw_range bit field for supported encoding capabilities
   203   *	- Add optional scan request parameters for SIOCSIWSCAN
   204   *	- Add SIOCSIWAUTH/SIOCGIWAUTH for setting authentication and WPA
   205   *	  related parameters (extensible up to 4096 parameter values)
   206   *	- Add wireless events: IWEVGENIE, IWEVMICHAELMICFAILURE,
   207   *	  IWEVASSOCREQIE, IWEVASSOCRESPIE, IWEVPMKIDCAND
   208   *
   209   * V18 to V19
   210   * ----------
   211   *	- Remove (struct iw_point *)->pointer from events and streams
   212   *	- Remove header includes to help user space
   213   *	- Increase IW_ENCODING_TOKEN_MAX from 32 to 64
   214   *	- Add IW_QUAL_ALL_UPDATED and IW_QUAL_ALL_INVALID macros
   215   *	- Add explicit flag to tell stats are in dBm : IW_QUAL_DBM
   216   *	- Add IW_IOCTL_IDX() and IW_EVENT_IDX() macros
   217   *
   218   * V19 to V20
   219   * ----------
   220   *	- RtNetlink requests support (SET/GET)
   221   *
   222   * V20 to V21
   223   * ----------
   224   *	- Remove (struct net_device *)->get_wireless_stats()
   225   *	- Change length in ESSID and NICK to strlen() instead of strlen()+1
   226   *	- Add IW_RETRY_SHORT/IW_RETRY_LONG retry modifiers
   227   *	- Power/Retry relative values no longer * 100000
   228   *	- Add explicit flag to tell stats are in 802.11k RCPI : IW_QUAL_RCPI
   229   *
   230   * V21 to V22
   231   * ----------
   232   *	- Prevent leaking of kernel space in stream on 64 bits.
   233   */
   234  
   235  /**************************** CONSTANTS ****************************/
   236  
   237  /* -------------------------- IOCTL LIST -------------------------- */
   238  
   239  /* Wireless Identification */
   240  #define SIOCSIWCOMMIT	0x8B00		/* Commit pending changes to driver */
   241  #define SIOCGIWNAME	0x8B01		/* get name == wireless protocol */
   242  /* SIOCGIWNAME is used to verify the presence of Wireless Extensions.
   243   * Common values : "IEEE 802.11-DS", "IEEE 802.11-FH", "IEEE 802.11b"...
   244   * Don't put the name of your driver there, it's useless. */
   245  
   246  /* Basic operations */
   247  #define SIOCSIWNWID	0x8B02		/* set network id (pre-802.11) */
   248  #define SIOCGIWNWID	0x8B03		/* get network id (the cell) */
   249  #define SIOCSIWFREQ	0x8B04		/* set channel/frequency (Hz) */
   250  #define SIOCGIWFREQ	0x8B05		/* get channel/frequency (Hz) */
   251  #define SIOCSIWMODE	0x8B06		/* set operation mode */
   252  #define SIOCGIWMODE	0x8B07		/* get operation mode */
   253  #define SIOCSIWSENS	0x8B08		/* set sensitivity (dBm) */
   254  #define SIOCGIWSENS	0x8B09		/* get sensitivity (dBm) */
   255  
   256  /* Informative stuff */
   257  #define SIOCSIWRANGE	0x8B0A		/* Unused */
   258  #define SIOCGIWRANGE	0x8B0B		/* Get range of parameters */
   259  #define SIOCSIWPRIV	0x8B0C		/* Unused */
   260  #define SIOCGIWPRIV	0x8B0D		/* get private ioctl interface info */
   261  #define SIOCSIWSTATS	0x8B0E		/* Unused */
   262  #define SIOCGIWSTATS	0x8B0F		/* Get /proc/net/wireless stats */
   263  /* SIOCGIWSTATS is strictly used between user space and the kernel, and
   264   * is never passed to the driver (i.e. the driver will never see it). */
   265  
   266  /* Spy support (statistics per MAC address - used for Mobile IP support) */
   267  #define SIOCSIWSPY	0x8B10		/* set spy addresses */
   268  #define SIOCGIWSPY	0x8B11		/* get spy info (quality of link) */
   269  #define SIOCSIWTHRSPY	0x8B12		/* set spy threshold (spy event) */
   270  #define SIOCGIWTHRSPY	0x8B13		/* get spy threshold */
   271  
   272  /* Access Point manipulation */
   273  #define SIOCSIWAP	0x8B14		/* set access point MAC addresses */
   274  #define SIOCGIWAP	0x8B15		/* get access point MAC addresses */
   275  #define SIOCGIWAPLIST	0x8B17		/* Deprecated in favor of scanning */
   276  #define SIOCSIWSCAN	0x8B18		/* trigger scanning (list cells) */
   277  #define SIOCGIWSCAN	0x8B19		/* get scanning results */
   278  
   279  /* 802.11 specific support */
   280  #define SIOCSIWESSID	0x8B1A		/* set ESSID (network name) */
   281  #define SIOCGIWESSID	0x8B1B		/* get ESSID */
   282  #define SIOCSIWNICKN	0x8B1C		/* set node name/nickname */
   283  #define SIOCGIWNICKN	0x8B1D		/* get node name/nickname */
   284  /* As the ESSID and NICKN are strings up to 32 bytes long, it doesn't fit
   285   * within the 'iwreq' structure, so we need to use the 'data' member to
   286   * point to a string in user space, like it is done for RANGE... */
   287  
   288  /* Other parameters useful in 802.11 and some other devices */
   289  #define SIOCSIWRATE	0x8B20		/* set default bit rate (bps) */
   290  #define SIOCGIWRATE	0x8B21		/* get default bit rate (bps) */
   291  #define SIOCSIWRTS	0x8B22		/* set RTS/CTS threshold (bytes) */
   292  #define SIOCGIWRTS	0x8B23		/* get RTS/CTS threshold (bytes) */
   293  #define SIOCSIWFRAG	0x8B24		/* set fragmentation thr (bytes) */
   294  #define SIOCGIWFRAG	0x8B25		/* get fragmentation thr (bytes) */
   295  #define SIOCSIWTXPOW	0x8B26		/* set transmit power (dBm) */
   296  #define SIOCGIWTXPOW	0x8B27		/* get transmit power (dBm) */
   297  #define SIOCSIWRETRY	0x8B28		/* set retry limits and lifetime */
   298  #define SIOCGIWRETRY	0x8B29		/* get retry limits and lifetime */
   299  
   300  /* Encoding stuff (scrambling, hardware security, WEP...) */
   301  #define SIOCSIWENCODE	0x8B2A		/* set encoding token & mode */
   302  #define SIOCGIWENCODE	0x8B2B		/* get encoding token & mode */
   303  /* Power saving stuff (power management, unicast and multicast) */
   304  #define SIOCSIWPOWER	0x8B2C		/* set Power Management settings */
   305  #define SIOCGIWPOWER	0x8B2D		/* get Power Management settings */
   306  
   307  /* WPA : Generic IEEE 802.11 informatiom element (e.g., for WPA/RSN/WMM).
   308   * This ioctl uses struct iw_point and data buffer that includes IE id and len
   309   * fields. More than one IE may be included in the request. Setting the generic
   310   * IE to empty buffer (len=0) removes the generic IE from the driver. Drivers
   311   * are allowed to generate their own WPA/RSN IEs, but in these cases, drivers
   312   * are required to report the used IE as a wireless event, e.g., when
   313   * associating with an AP. */
   314  #define SIOCSIWGENIE	0x8B30		/* set generic IE */
   315  #define SIOCGIWGENIE	0x8B31		/* get generic IE */
   316  
   317  /* WPA : IEEE 802.11 MLME requests */
   318  #define SIOCSIWMLME	0x8B16		/* request MLME operation; uses
   319  					 * struct iw_mlme */
   320  /* WPA : Authentication mode parameters */
   321  #define SIOCSIWAUTH	0x8B32		/* set authentication mode params */
   322  #define SIOCGIWAUTH	0x8B33		/* get authentication mode params */
   323  
   324  /* WPA : Extended version of encoding configuration */
   325  #define SIOCSIWENCODEEXT 0x8B34		/* set encoding token & mode */
   326  #define SIOCGIWENCODEEXT 0x8B35		/* get encoding token & mode */
   327  
   328  /* WPA2 : PMKSA cache management */
   329  #define SIOCSIWPMKSA	0x8B36		/* PMKSA cache operation */
   330  
   331  /* -------------------- DEV PRIVATE IOCTL LIST -------------------- */
   332  
   333  /* These 32 ioctl are wireless device private, for 16 commands.
   334   * Each driver is free to use them for whatever purpose it chooses,
   335   * however the driver *must* export the description of those ioctls
   336   * with SIOCGIWPRIV and *must* use arguments as defined below.
   337   * If you don't follow those rules, DaveM is going to hate you (reason :
   338   * it make mixed 32/64bit operation impossible).
   339   */
   340  #define SIOCIWFIRSTPRIV	0x8BE0
   341  #define SIOCIWLASTPRIV	0x8BFF
   342  /* Previously, we were using SIOCDEVPRIVATE, but we now have our
   343   * separate range because of collisions with other tools such as
   344   * 'mii-tool'.
   345   * We now have 32 commands, so a bit more space ;-).
   346   * Also, all 'even' commands are only usable by root and don't return the
   347   * content of ifr/iwr to user (but you are not obliged to use the set/get
   348   * convention, just use every other two command). More details in iwpriv.c.
   349   * And I repeat : you are not forced to use them with iwpriv, but you
   350   * must be compliant with it.
   351   */
   352  
   353  /* ------------------------- IOCTL STUFF ------------------------- */
   354  
   355  /* The first and the last (range) */
   356  #define SIOCIWFIRST	0x8B00
   357  #define SIOCIWLAST	SIOCIWLASTPRIV		/* 0x8BFF */
   358  #define IW_IOCTL_IDX(cmd)	((cmd) - SIOCIWFIRST)
   359  #define IW_HANDLER(id, func)			\
   360  	[IW_IOCTL_IDX(id)] = func
   361  
   362  /* Odd : get (world access), even : set (root access) */
   363  #define IW_IS_SET(cmd)	(!((cmd) & 0x1))
   364  #define IW_IS_GET(cmd)	((cmd) & 0x1)
   365  
   366  /* ----------------------- WIRELESS EVENTS ----------------------- */
   367  /* Those are *NOT* ioctls, do not issue request on them !!! */
   368  /* Most events use the same identifier as ioctl requests */
   369  
   370  #define IWEVTXDROP	0x8C00		/* Packet dropped to excessive retry */
   371  #define IWEVQUAL	0x8C01		/* Quality part of statistics (scan) */
   372  #define IWEVCUSTOM	0x8C02		/* Driver specific ascii string */
   373  #define IWEVREGISTERED	0x8C03		/* Discovered a new node (AP mode) */
   374  #define IWEVEXPIRED	0x8C04		/* Expired a node (AP mode) */
   375  #define IWEVGENIE	0x8C05		/* Generic IE (WPA, RSN, WMM, ..)
   376  					 * (scan results); This includes id and
   377  					 * length fields. One IWEVGENIE may
   378  					 * contain more than one IE. Scan
   379  					 * results may contain one or more
   380  					 * IWEVGENIE events. */
   381  #define IWEVMICHAELMICFAILURE 0x8C06	/* Michael MIC failure
   382  					 * (struct iw_michaelmicfailure)
   383  					 */
   384  #define IWEVASSOCREQIE	0x8C07		/* IEs used in (Re)Association Request.
   385  					 * The data includes id and length
   386  					 * fields and may contain more than one
   387  					 * IE. This event is required in
   388  					 * Managed mode if the driver
   389  					 * generates its own WPA/RSN IE. This
   390  					 * should be sent just before
   391  					 * IWEVREGISTERED event for the
   392  					 * association. */
   393  #define IWEVASSOCRESPIE	0x8C08		/* IEs used in (Re)Association
   394  					 * Response. The data includes id and
   395  					 * length fields and may contain more
   396  					 * than one IE. This may be sent
   397  					 * between IWEVASSOCREQIE and
   398  					 * IWEVREGISTERED events for the
   399  					 * association. */
   400  #define IWEVPMKIDCAND	0x8C09		/* PMKID candidate for RSN
   401  					 * pre-authentication
   402  					 * (struct iw_pmkid_cand) */
   403  
   404  #define IWEVFIRST	0x8C00
   405  #define IW_EVENT_IDX(cmd)	((cmd) - IWEVFIRST)
   406  
   407  /* ------------------------- PRIVATE INFO ------------------------- */
   408  /*
   409   * The following is used with SIOCGIWPRIV. It allow a driver to define
   410   * the interface (name, type of data) for its private ioctl.
   411   * Privates ioctl are SIOCIWFIRSTPRIV -> SIOCIWLASTPRIV
   412   */
   413  
   414  #define IW_PRIV_TYPE_MASK	0x7000	/* Type of arguments */
   415  #define IW_PRIV_TYPE_NONE	0x0000
   416  #define IW_PRIV_TYPE_BYTE	0x1000	/* Char as number */
   417  #define IW_PRIV_TYPE_CHAR	0x2000	/* Char as character */
   418  #define IW_PRIV_TYPE_INT	0x4000	/* 32 bits int */
   419  #define IW_PRIV_TYPE_FLOAT	0x5000	/* struct iw_freq */
   420  #define IW_PRIV_TYPE_ADDR	0x6000	/* struct sockaddr */
   421  
   422  #define IW_PRIV_SIZE_FIXED	0x0800	/* Variable or fixed number of args */
   423  
   424  #define IW_PRIV_SIZE_MASK	0x07FF	/* Max number of those args */
   425  
   426  /*
   427   * Note : if the number of args is fixed and the size < 16 octets,
   428   * instead of passing a pointer we will put args in the iwreq struct...
   429   */
   430  
   431  /* ----------------------- OTHER CONSTANTS ----------------------- */
   432  
   433  /* Maximum frequencies in the range struct */
   434  #define IW_MAX_FREQUENCIES	32
   435  /* Note : if you have something like 80 frequencies,
   436   * don't increase this constant and don't fill the frequency list.
   437   * The user will be able to set by channel anyway... */
   438  
   439  /* Maximum bit rates in the range struct */
   440  #define IW_MAX_BITRATES		32
   441  
   442  /* Maximum tx powers in the range struct */
   443  #define IW_MAX_TXPOWER		8
   444  /* Note : if you more than 8 TXPowers, just set the max and min or
   445   * a few of them in the struct iw_range. */
   446  
   447  /* Maximum of address that you may set with SPY */
   448  #define IW_MAX_SPY		8
   449  
   450  /* Maximum of address that you may get in the
   451     list of access points in range */
   452  #define IW_MAX_AP		64
   453  
   454  /* Maximum size of the ESSID and NICKN strings */
   455  #define IW_ESSID_MAX_SIZE	32
   456  
   457  /* Modes of operation */
   458  #define IW_MODE_AUTO	0	/* Let the driver decides */
   459  #define IW_MODE_ADHOC	1	/* Single cell network */
   460  #define IW_MODE_INFRA	2	/* Multi cell network, roaming, ... */
   461  #define IW_MODE_MASTER	3	/* Synchronisation master or Access Point */
   462  #define IW_MODE_REPEAT	4	/* Wireless Repeater (forwarder) */
   463  #define IW_MODE_SECOND	5	/* Secondary master/repeater (backup) */
   464  #define IW_MODE_MONITOR	6	/* Passive monitor (listen only) */
   465  #define IW_MODE_MESH	7	/* Mesh (IEEE 802.11s) network */
   466  
   467  /* Statistics flags (bitmask in updated) */
   468  #define IW_QUAL_QUAL_UPDATED	0x01	/* Value was updated since last read */
   469  #define IW_QUAL_LEVEL_UPDATED	0x02
   470  #define IW_QUAL_NOISE_UPDATED	0x04
   471  #define IW_QUAL_ALL_UPDATED	0x07
   472  #define IW_QUAL_DBM		0x08	/* Level + Noise are dBm */
   473  #define IW_QUAL_QUAL_INVALID	0x10	/* Driver doesn't provide value */
   474  #define IW_QUAL_LEVEL_INVALID	0x20
   475  #define IW_QUAL_NOISE_INVALID	0x40
   476  #define IW_QUAL_RCPI		0x80	/* Level + Noise are 802.11k RCPI */
   477  #define IW_QUAL_ALL_INVALID	0x70
   478  
   479  /* Frequency flags */
   480  #define IW_FREQ_AUTO		0x00	/* Let the driver decides */
   481  #define IW_FREQ_FIXED		0x01	/* Force a specific value */
   482  
   483  /* Maximum number of size of encoding token available
   484   * they are listed in the range structure */
   485  #define IW_MAX_ENCODING_SIZES	8
   486  
   487  /* Maximum size of the encoding token in bytes */
   488  #define IW_ENCODING_TOKEN_MAX	64	/* 512 bits (for now) */
   489  
   490  /* Flags for encoding (along with the token) */
   491  #define IW_ENCODE_INDEX		0x00FF	/* Token index (if needed) */
   492  #define IW_ENCODE_FLAGS		0xFF00	/* Flags defined below */
   493  #define IW_ENCODE_MODE		0xF000	/* Modes defined below */
   494  #define IW_ENCODE_DISABLED	0x8000	/* Encoding disabled */
   495  #define IW_ENCODE_ENABLED	0x0000	/* Encoding enabled */
   496  #define IW_ENCODE_RESTRICTED	0x4000	/* Refuse non-encoded packets */
   497  #define IW_ENCODE_OPEN		0x2000	/* Accept non-encoded packets */
   498  #define IW_ENCODE_NOKEY		0x0800  /* Key is write only, so not present */
   499  #define IW_ENCODE_TEMP		0x0400  /* Temporary key */
   500  
   501  /* Power management flags available (along with the value, if any) */
   502  #define IW_POWER_ON		0x0000	/* No details... */
   503  #define IW_POWER_TYPE		0xF000	/* Type of parameter */
   504  #define IW_POWER_PERIOD		0x1000	/* Value is a period/duration of  */
   505  #define IW_POWER_TIMEOUT	0x2000	/* Value is a timeout (to go asleep) */
   506  #define IW_POWER_MODE		0x0F00	/* Power Management mode */
   507  #define IW_POWER_UNICAST_R	0x0100	/* Receive only unicast messages */
   508  #define IW_POWER_MULTICAST_R	0x0200	/* Receive only multicast messages */
   509  #define IW_POWER_ALL_R		0x0300	/* Receive all messages though PM */
   510  #define IW_POWER_FORCE_S	0x0400	/* Force PM procedure for sending unicast */
   511  #define IW_POWER_REPEATER	0x0800	/* Repeat broadcast messages in PM period */
   512  #define IW_POWER_MODIFIER	0x000F	/* Modify a parameter */
   513  #define IW_POWER_MIN		0x0001	/* Value is a minimum  */
   514  #define IW_POWER_MAX		0x0002	/* Value is a maximum */
   515  #define IW_POWER_RELATIVE	0x0004	/* Value is not in seconds/ms/us */
   516  
   517  /* Transmit Power flags available */
   518  #define IW_TXPOW_TYPE		0x00FF	/* Type of value */
   519  #define IW_TXPOW_DBM		0x0000	/* Value is in dBm */
   520  #define IW_TXPOW_MWATT		0x0001	/* Value is in mW */
   521  #define IW_TXPOW_RELATIVE	0x0002	/* Value is in arbitrary units */
   522  #define IW_TXPOW_RANGE		0x1000	/* Range of value between min/max */
   523  
   524  /* Retry limits and lifetime flags available */
   525  #define IW_RETRY_ON		0x0000	/* No details... */
   526  #define IW_RETRY_TYPE		0xF000	/* Type of parameter */
   527  #define IW_RETRY_LIMIT		0x1000	/* Maximum number of retries*/
   528  #define IW_RETRY_LIFETIME	0x2000	/* Maximum duration of retries in us */
   529  #define IW_RETRY_MODIFIER	0x00FF	/* Modify a parameter */
   530  #define IW_RETRY_MIN		0x0001	/* Value is a minimum  */
   531  #define IW_RETRY_MAX		0x0002	/* Value is a maximum */
   532  #define IW_RETRY_RELATIVE	0x0004	/* Value is not in seconds/ms/us */
   533  #define IW_RETRY_SHORT		0x0010	/* Value is for short packets  */
   534  #define IW_RETRY_LONG		0x0020	/* Value is for long packets */
   535  
   536  /* Scanning request flags */
   537  #define IW_SCAN_DEFAULT		0x0000	/* Default scan of the driver */
   538  #define IW_SCAN_ALL_ESSID	0x0001	/* Scan all ESSIDs */
   539  #define IW_SCAN_THIS_ESSID	0x0002	/* Scan only this ESSID */
   540  #define IW_SCAN_ALL_FREQ	0x0004	/* Scan all Frequencies */
   541  #define IW_SCAN_THIS_FREQ	0x0008	/* Scan only this Frequency */
   542  #define IW_SCAN_ALL_MODE	0x0010	/* Scan all Modes */
   543  #define IW_SCAN_THIS_MODE	0x0020	/* Scan only this Mode */
   544  #define IW_SCAN_ALL_RATE	0x0040	/* Scan all Bit-Rates */
   545  #define IW_SCAN_THIS_RATE	0x0080	/* Scan only this Bit-Rate */
   546  /* struct iw_scan_req scan_type */
   547  #define IW_SCAN_TYPE_ACTIVE 0
   548  #define IW_SCAN_TYPE_PASSIVE 1
   549  /* Maximum size of returned data */
   550  #define IW_SCAN_MAX_DATA	4096	/* In bytes */
   551  
   552  /* Scan capability flags - in (struct iw_range *)->scan_capa */
   553  #define IW_SCAN_CAPA_NONE		0x00
   554  #define IW_SCAN_CAPA_ESSID		0x01
   555  #define IW_SCAN_CAPA_BSSID		0x02
   556  #define IW_SCAN_CAPA_CHANNEL	0x04
   557  #define IW_SCAN_CAPA_MODE		0x08
   558  #define IW_SCAN_CAPA_RATE		0x10
   559  #define IW_SCAN_CAPA_TYPE		0x20
   560  #define IW_SCAN_CAPA_TIME		0x40
   561  
   562  /* Max number of char in custom event - use multiple of them if needed */
   563  #define IW_CUSTOM_MAX		256	/* In bytes */
   564  
   565  /* Generic information element */
   566  #define IW_GENERIC_IE_MAX	1024
   567  
   568  /* MLME requests (SIOCSIWMLME / struct iw_mlme) */
   569  #define IW_MLME_DEAUTH		0
   570  #define IW_MLME_DISASSOC	1
   571  #define IW_MLME_AUTH		2
   572  #define IW_MLME_ASSOC		3
   573  
   574  /* SIOCSIWAUTH/SIOCGIWAUTH struct iw_param flags */
   575  #define IW_AUTH_INDEX		0x0FFF
   576  #define IW_AUTH_FLAGS		0xF000
   577  /* SIOCSIWAUTH/SIOCGIWAUTH parameters (0 .. 4095)
   578   * (IW_AUTH_INDEX mask in struct iw_param flags; this is the index of the
   579   * parameter that is being set/get to; value will be read/written to
   580   * struct iw_param value field) */
   581  #define IW_AUTH_WPA_VERSION		0
   582  #define IW_AUTH_CIPHER_PAIRWISE		1
   583  #define IW_AUTH_CIPHER_GROUP		2
   584  #define IW_AUTH_KEY_MGMT		3
   585  #define IW_AUTH_TKIP_COUNTERMEASURES	4
   586  #define IW_AUTH_DROP_UNENCRYPTED	5
   587  #define IW_AUTH_80211_AUTH_ALG		6
   588  #define IW_AUTH_WPA_ENABLED		7
   589  #define IW_AUTH_RX_UNENCRYPTED_EAPOL	8
   590  #define IW_AUTH_ROAMING_CONTROL		9
   591  #define IW_AUTH_PRIVACY_INVOKED		10
   592  #define IW_AUTH_CIPHER_GROUP_MGMT	11
   593  #define IW_AUTH_MFP			12
   594  
   595  /* IW_AUTH_WPA_VERSION values (bit field) */
   596  #define IW_AUTH_WPA_VERSION_DISABLED	0x00000001
   597  #define IW_AUTH_WPA_VERSION_WPA		0x00000002
   598  #define IW_AUTH_WPA_VERSION_WPA2	0x00000004
   599  
   600  /* IW_AUTH_PAIRWISE_CIPHER, IW_AUTH_GROUP_CIPHER, and IW_AUTH_CIPHER_GROUP_MGMT
   601   * values (bit field) */
   602  #define IW_AUTH_CIPHER_NONE	0x00000001
   603  #define IW_AUTH_CIPHER_WEP40	0x00000002
   604  #define IW_AUTH_CIPHER_TKIP	0x00000004
   605  #define IW_AUTH_CIPHER_CCMP	0x00000008
   606  #define IW_AUTH_CIPHER_WEP104	0x00000010
   607  #define IW_AUTH_CIPHER_AES_CMAC	0x00000020
   608  
   609  /* IW_AUTH_KEY_MGMT values (bit field) */
   610  #define IW_AUTH_KEY_MGMT_802_1X	1
   611  #define IW_AUTH_KEY_MGMT_PSK	2
   612  
   613  /* IW_AUTH_80211_AUTH_ALG values (bit field) */
   614  #define IW_AUTH_ALG_OPEN_SYSTEM	0x00000001
   615  #define IW_AUTH_ALG_SHARED_KEY	0x00000002
   616  #define IW_AUTH_ALG_LEAP	0x00000004
   617  
   618  /* IW_AUTH_ROAMING_CONTROL values */
   619  #define IW_AUTH_ROAMING_ENABLE	0	/* driver/firmware based roaming */
   620  #define IW_AUTH_ROAMING_DISABLE	1	/* user space program used for roaming
   621  					 * control */
   622  
   623  /* IW_AUTH_MFP (management frame protection) values */
   624  #define IW_AUTH_MFP_DISABLED	0	/* MFP disabled */
   625  #define IW_AUTH_MFP_OPTIONAL	1	/* MFP optional */
   626  #define IW_AUTH_MFP_REQUIRED	2	/* MFP required */
   627  
   628  /* SIOCSIWENCODEEXT definitions */
   629  #define IW_ENCODE_SEQ_MAX_SIZE	8
   630  /* struct iw_encode_ext ->alg */
   631  #define IW_ENCODE_ALG_NONE	0
   632  #define IW_ENCODE_ALG_WEP	1
   633  #define IW_ENCODE_ALG_TKIP	2
   634  #define IW_ENCODE_ALG_CCMP	3
   635  #define IW_ENCODE_ALG_PMK	4
   636  #define IW_ENCODE_ALG_AES_CMAC	5
   637  /* struct iw_encode_ext ->ext_flags */
   638  #define IW_ENCODE_EXT_TX_SEQ_VALID	0x00000001
   639  #define IW_ENCODE_EXT_RX_SEQ_VALID	0x00000002
   640  #define IW_ENCODE_EXT_GROUP_KEY		0x00000004
   641  #define IW_ENCODE_EXT_SET_TX_KEY	0x00000008
   642  
   643  /* IWEVMICHAELMICFAILURE : struct iw_michaelmicfailure ->flags */
   644  #define IW_MICFAILURE_KEY_ID	0x00000003 /* Key ID 0..3 */
   645  #define IW_MICFAILURE_GROUP	0x00000004
   646  #define IW_MICFAILURE_PAIRWISE	0x00000008
   647  #define IW_MICFAILURE_STAKEY	0x00000010
   648  #define IW_MICFAILURE_COUNT	0x00000060 /* 1 or 2 (0 = count not supported)
   649  					    */
   650  
   651  /* Bit field values for enc_capa in struct iw_range */
   652  #define IW_ENC_CAPA_WPA		0x00000001
   653  #define IW_ENC_CAPA_WPA2	0x00000002
   654  #define IW_ENC_CAPA_CIPHER_TKIP	0x00000004
   655  #define IW_ENC_CAPA_CIPHER_CCMP	0x00000008
   656  #define IW_ENC_CAPA_4WAY_HANDSHAKE	0x00000010
   657  
   658  /* Event capability macros - in (struct iw_range *)->event_capa
   659   * Because we have more than 32 possible events, we use an array of
   660   * 32 bit bitmasks. Note : 32 bits = 0x20 = 2^5. */
   661  #define IW_EVENT_CAPA_BASE(cmd)		((cmd >= SIOCIWFIRSTPRIV) ? \
   662  					 (cmd - SIOCIWFIRSTPRIV + 0x60) : \
   663  					 (cmd - SIOCIWFIRST))
   664  #define IW_EVENT_CAPA_INDEX(cmd)	(IW_EVENT_CAPA_BASE(cmd) >> 5)
   665  #define IW_EVENT_CAPA_MASK(cmd)		(1 << (IW_EVENT_CAPA_BASE(cmd) & 0x1F))
   666  /* Event capability constants - event autogenerated by the kernel
   667   * This list is valid for most 802.11 devices, customise as needed... */
   668  #define IW_EVENT_CAPA_K_0	(IW_EVENT_CAPA_MASK(0x8B04) | \
   669  				 IW_EVENT_CAPA_MASK(0x8B06) | \
   670  				 IW_EVENT_CAPA_MASK(0x8B1A))
   671  #define IW_EVENT_CAPA_K_1	(IW_EVENT_CAPA_MASK(0x8B2A))
   672  /* "Easy" macro to set events in iw_range (less efficient) */
   673  #define IW_EVENT_CAPA_SET(event_capa, cmd) (event_capa[IW_EVENT_CAPA_INDEX(cmd)] |= IW_EVENT_CAPA_MASK(cmd))
   674  #define IW_EVENT_CAPA_SET_KERNEL(event_capa) {event_capa[0] |= IW_EVENT_CAPA_K_0; event_capa[1] |= IW_EVENT_CAPA_K_1; }
   675  
   676  
   677  /****************************** TYPES ******************************/
   678  
   679  /* --------------------------- SUBTYPES --------------------------- */
   680  /*
   681   *	Generic format for most parameters that fit in an int
   682   */
   683  struct iw_param {
   684    __s32		value;		/* The value of the parameter itself */
   685    __u8		fixed;		/* Hardware should not use auto select */
   686    __u8		disabled;	/* Disable the feature */
   687    __u16		flags;		/* Various specifc flags (if any) */
   688  };
   689  
   690  /*
   691   *	For all data larger than 16 octets, we need to use a
   692   *	pointer to memory allocated in user space.
   693   */
   694  struct iw_point {
   695    void *pointer;	/* Pointer to the data  (in user space) */
   696    __u16		length;		/* number of fields or size in bytes */
   697    __u16		flags;		/* Optional params */
   698  };
   699  
   700  
   701  /*
   702   *	A frequency
   703   *	For numbers lower than 10^9, we encode the number in 'm' and
   704   *	set 'e' to 0
   705   *	For number greater than 10^9, we divide it by the lowest power
   706   *	of 10 to get 'm' lower than 10^9, with 'm'= f / (10^'e')...
   707   *	The power of 10 is in 'e', the result of the division is in 'm'.
   708   */
   709  struct iw_freq {
   710  	__s32		m;		/* Mantissa */
   711  	__s16		e;		/* Exponent */
   712  	__u8		i;		/* List index (when in range struct) */
   713  	__u8		flags;		/* Flags (fixed/auto) */
   714  };
   715  
   716  /*
   717   *	Quality of the link
   718   */
   719  struct iw_quality {
   720  	__u8		qual;		/* link quality (%retries, SNR,
   721  					   %missed beacons or better...) */
   722  	__u8		level;		/* signal level (dBm) */
   723  	__u8		noise;		/* noise level (dBm) */
   724  	__u8		updated;	/* Flags to know if updated */
   725  };
   726  
   727  /*
   728   *	Packet discarded in the wireless adapter due to
   729   *	"wireless" specific problems...
   730   *	Note : the list of counter and statistics in net_device_stats
   731   *	is already pretty exhaustive, and you should use that first.
   732   *	This is only additional stats...
   733   */
   734  struct iw_discarded {
   735  	__u32		nwid;		/* Rx : Wrong nwid/essid */
   736  	__u32		code;		/* Rx : Unable to code/decode (WEP) */
   737  	__u32		fragment;	/* Rx : Can't perform MAC reassembly */
   738  	__u32		retries;	/* Tx : Max MAC retries num reached */
   739  	__u32		misc;		/* Others cases */
   740  };
   741  
   742  /*
   743   *	Packet/Time period missed in the wireless adapter due to
   744   *	"wireless" specific problems...
   745   */
   746  struct iw_missed {
   747  	__u32		beacon;		/* Missed beacons/superframe */
   748  };
   749  
   750  /*
   751   *	Quality range (for spy threshold)
   752   */
   753  struct iw_thrspy {
   754  	struct sockaddr		addr;		/* Source address (hw/mac) */
   755  	struct iw_quality	qual;		/* Quality of the link */
   756  	struct iw_quality	low;		/* Low threshold */
   757  	struct iw_quality	high;		/* High threshold */
   758  };
   759  
   760  /*
   761   *	Optional data for scan request
   762   *
   763   *	Note: these optional parameters are controlling parameters for the
   764   *	scanning behavior, these do not apply to getting scan results
   765   *	(SIOCGIWSCAN). Drivers are expected to keep a local BSS table and
   766   *	provide a merged results with all BSSes even if the previous scan
   767   *	request limited scanning to a subset, e.g., by specifying an SSID.
   768   *	Especially, scan results are required to include an entry for the
   769   *	current BSS if the driver is in Managed mode and associated with an AP.
   770   */
   771  struct iw_scan_req {
   772  	__u8		scan_type; /* IW_SCAN_TYPE_{ACTIVE,PASSIVE} */
   773  	__u8		essid_len;
   774  	__u8		num_channels; /* num entries in channel_list;
   775  				       * 0 = scan all allowed channels */
   776  	__u8		flags; /* reserved as padding; use zero, this may
   777  				* be used in the future for adding flags
   778  				* to request different scan behavior */
   779  	struct sockaddr	bssid; /* ff:ff:ff:ff:ff:ff for broadcast BSSID or
   780  				* individual address of a specific BSS */
   781  
   782  	/*
   783  	 * Use this ESSID if IW_SCAN_THIS_ESSID flag is used instead of using
   784  	 * the current ESSID. This allows scan requests for specific ESSID
   785  	 * without having to change the current ESSID and potentially breaking
   786  	 * the current association.
   787  	 */
   788  	__u8		essid[IW_ESSID_MAX_SIZE];
   789  
   790  	/*
   791  	 * Optional parameters for changing the default scanning behavior.
   792  	 * These are based on the MLME-SCAN.request from IEEE Std 802.11.
   793  	 * TU is 1.024 ms. If these are set to 0, driver is expected to use
   794  	 * reasonable default values. min_channel_time defines the time that
   795  	 * will be used to wait for the first reply on each channel. If no
   796  	 * replies are received, next channel will be scanned after this. If
   797  	 * replies are received, total time waited on the channel is defined by
   798  	 * max_channel_time.
   799  	 */
   800  	__u32		min_channel_time; /* in TU */
   801  	__u32		max_channel_time; /* in TU */
   802  
   803  	struct iw_freq	channel_list[IW_MAX_FREQUENCIES];
   804  };
   805  
   806  /* ------------------------- WPA SUPPORT ------------------------- */
   807  
   808  /*
   809   *	Extended data structure for get/set encoding (this is used with
   810   *	SIOCSIWENCODEEXT/SIOCGIWENCODEEXT. struct iw_point and IW_ENCODE_*
   811   *	flags are used in the same way as with SIOCSIWENCODE/SIOCGIWENCODE and
   812   *	only the data contents changes (key data -> this structure, including
   813   *	key data).
   814   *
   815   *	If the new key is the first group key, it will be set as the default
   816   *	TX key. Otherwise, default TX key index is only changed if
   817   *	IW_ENCODE_EXT_SET_TX_KEY flag is set.
   818   *
   819   *	Key will be changed with SIOCSIWENCODEEXT in all cases except for
   820   *	special "change TX key index" operation which is indicated by setting
   821   *	key_len = 0 and ext_flags |= IW_ENCODE_EXT_SET_TX_KEY.
   822   *
   823   *	tx_seq/rx_seq are only used when respective
   824   *	IW_ENCODE_EXT_{TX,RX}_SEQ_VALID flag is set in ext_flags. Normal
   825   *	TKIP/CCMP operation is to set RX seq with SIOCSIWENCODEEXT and start
   826   *	TX seq from zero whenever key is changed. SIOCGIWENCODEEXT is normally
   827   *	used only by an Authenticator (AP or an IBSS station) to get the
   828   *	current TX sequence number. Using TX_SEQ_VALID for SIOCSIWENCODEEXT and
   829   *	RX_SEQ_VALID for SIOCGIWENCODEEXT are optional, but can be useful for
   830   *	debugging/testing.
   831   */
   832  struct iw_encode_ext {
   833  	__u32		ext_flags; /* IW_ENCODE_EXT_* */
   834  	__u8		tx_seq[IW_ENCODE_SEQ_MAX_SIZE]; /* LSB first */
   835  	__u8		rx_seq[IW_ENCODE_SEQ_MAX_SIZE]; /* LSB first */
   836  	struct sockaddr	addr; /* ff:ff:ff:ff:ff:ff for broadcast/multicast
   837  			       * (group) keys or unicast address for
   838  			       * individual keys */
   839  	__u16		alg; /* IW_ENCODE_ALG_* */
   840  	__u16		key_len;
   841  	__u8		key[0];
   842  };
   843  
   844  /* SIOCSIWMLME data */
   845  struct iw_mlme {
   846  	__u16		cmd; /* IW_MLME_* */
   847  	__u16		reason_code;
   848  	struct sockaddr	addr;
   849  };
   850  
   851  /* SIOCSIWPMKSA data */
   852  #define IW_PMKSA_ADD		1
   853  #define IW_PMKSA_REMOVE		2
   854  #define IW_PMKSA_FLUSH		3
   855  
   856  #define IW_PMKID_LEN	16
   857  
   858  struct iw_pmksa {
   859  	__u32		cmd; /* IW_PMKSA_* */
   860  	struct sockaddr	bssid;
   861  	__u8		pmkid[IW_PMKID_LEN];
   862  };
   863  
   864  /* IWEVMICHAELMICFAILURE data */
   865  struct iw_michaelmicfailure {
   866  	__u32		flags;
   867  	struct sockaddr	src_addr;
   868  	__u8		tsc[IW_ENCODE_SEQ_MAX_SIZE]; /* LSB first */
   869  };
   870  
   871  /* IWEVPMKIDCAND data */
   872  #define IW_PMKID_CAND_PREAUTH	0x00000001 /* RNS pre-authentication enabled */
   873  struct iw_pmkid_cand {
   874  	__u32		flags; /* IW_PMKID_CAND_* */
   875  	__u32		index; /* the smaller the index, the higher the
   876  				* priority */
   877  	struct sockaddr	bssid;
   878  };
   879  
   880  /* ------------------------ WIRELESS STATS ------------------------ */
   881  /*
   882   * Wireless statistics (used for /proc/net/wireless)
   883   */
   884  struct iw_statistics {
   885  	__u16		status;		/* Status
   886  					 * - device dependent for now */
   887  
   888  	struct iw_quality	qual;		/* Quality of the link
   889  						 * (instant/mean/max) */
   890  	struct iw_discarded	discard;	/* Packet discarded counts */
   891  	struct iw_missed	miss;		/* Packet missed counts */
   892  };
   893  
   894  /* ------------------------ IOCTL REQUEST ------------------------ */
   895  /*
   896   * This structure defines the payload of an ioctl, and is used
   897   * below.
   898   *
   899   * Note that this structure should fit on the memory footprint
   900   * of iwreq (which is the same as ifreq), which mean a max size of
   901   * 16 octets = 128 bits. Warning, pointers might be 64 bits wide...
   902   * You should check this when increasing the structures defined
   903   * above in this file...
   904   */
   905  union iwreq_data {
   906  	/* Config - generic */
   907  	char		name[IFNAMSIZ];
   908  	/* Name : used to verify the presence of  wireless extensions.
   909  	 * Name of the protocol/provider... */
   910  
   911  	struct iw_point	essid;		/* Extended network name */
   912  	struct iw_param	nwid;		/* network id (or domain - the cell) */
   913  	struct iw_freq	freq;		/* frequency or channel :
   914  					 * 0-1000 = channel
   915  					 * > 1000 = frequency in Hz */
   916  
   917  	struct iw_param	sens;		/* signal level threshold */
   918  	struct iw_param	bitrate;	/* default bit rate */
   919  	struct iw_param	txpower;	/* default transmit power */
   920  	struct iw_param	rts;		/* RTS threshold threshold */
   921  	struct iw_param	frag;		/* Fragmentation threshold */
   922  	__u32		mode;		/* Operation mode */
   923  	struct iw_param	retry;		/* Retry limits & lifetime */
   924  
   925  	struct iw_point	encoding;	/* Encoding stuff : tokens */
   926  	struct iw_param	power;		/* PM duration/timeout */
   927  	struct iw_quality qual;		/* Quality part of statistics */
   928  
   929  	struct sockaddr	ap_addr;	/* Access point address */
   930  	struct sockaddr	addr;		/* Destination address (hw/mac) */
   931  
   932  	struct iw_param	param;		/* Other small parameters */
   933  	struct iw_point	data;		/* Other large parameters */
   934  };
   935  
   936  /*
   937   * The structure to exchange data for ioctl.
   938   * This structure is the same as 'struct ifreq', but (re)defined for
   939   * convenience...
   940   * Do I need to remind you about structure size (32 octets) ?
   941   */
   942  struct iwreq {
   943  	union
   944  	{
   945  		char	ifrn_name[IFNAMSIZ];	/* if name, e.g. "eth0" */
   946  	} ifr_ifrn;
   947  
   948  	/* Data part (defined just above) */
   949  	union iwreq_data	u;
   950  };
   951  
   952  /* -------------------------- IOCTL DATA -------------------------- */
   953  /*
   954   *	For those ioctl which want to exchange mode data that what could
   955   *	fit in the above structure...
   956   */
   957  
   958  /*
   959   *	Range of parameters
   960   */
   961  
   962  struct iw_range {
   963  	/* Informative stuff (to choose between different interface) */
   964  	__u32		throughput;	/* To give an idea... */
   965  	/* In theory this value should be the maximum benchmarked
   966  	 * TCP/IP throughput, because with most of these devices the
   967  	 * bit rate is meaningless (overhead an co) to estimate how
   968  	 * fast the connection will go and pick the fastest one.
   969  	 * I suggest people to play with Netperf or any benchmark...
   970  	 */
   971  
   972  	/* NWID (or domain id) */
   973  	__u32		min_nwid;	/* Minimal NWID we are able to set */
   974  	__u32		max_nwid;	/* Maximal NWID we are able to set */
   975  
   976  	/* Old Frequency (backward compat - moved lower ) */
   977  	__u16		old_num_channels;
   978  	__u8		old_num_frequency;
   979  
   980  	/* Scan capabilities */
   981  	__u8		scan_capa; 	/* IW_SCAN_CAPA_* bit field */
   982  
   983  	/* Wireless event capability bitmasks */
   984  	__u32		event_capa[6];
   985  
   986  	/* signal level threshold range */
   987  	__s32		sensitivity;
   988  
   989  	/* Quality of link & SNR stuff */
   990  	/* Quality range (link, level, noise)
   991  	 * If the quality is absolute, it will be in the range [0 ; max_qual],
   992  	 * if the quality is dBm, it will be in the range [max_qual ; 0].
   993  	 * Don't forget that we use 8 bit arithmetics... */
   994  	struct iw_quality	max_qual;	/* Quality of the link */
   995  	/* This should contain the average/typical values of the quality
   996  	 * indicator. This should be the threshold between a "good" and
   997  	 * a "bad" link (example : monitor going from green to orange).
   998  	 * Currently, user space apps like quality monitors don't have any
   999  	 * way to calibrate the measurement. With this, they can split
  1000  	 * the range between 0 and max_qual in different quality level
  1001  	 * (using a geometric subdivision centered on the average).
  1002  	 * I expect that people doing the user space apps will feedback
  1003  	 * us on which value we need to put in each driver... */
  1004  	struct iw_quality	avg_qual;	/* Quality of the link */
  1005  
  1006  	/* Rates */
  1007  	__u8		num_bitrates;	/* Number of entries in the list */
  1008  	__s32		bitrate[IW_MAX_BITRATES];	/* list, in bps */
  1009  
  1010  	/* RTS threshold */
  1011  	__s32		min_rts;	/* Minimal RTS threshold */
  1012  	__s32		max_rts;	/* Maximal RTS threshold */
  1013  
  1014  	/* Frag threshold */
  1015  	__s32		min_frag;	/* Minimal frag threshold */
  1016  	__s32		max_frag;	/* Maximal frag threshold */
  1017  
  1018  	/* Power Management duration & timeout */
  1019  	__s32		min_pmp;	/* Minimal PM period */
  1020  	__s32		max_pmp;	/* Maximal PM period */
  1021  	__s32		min_pmt;	/* Minimal PM timeout */
  1022  	__s32		max_pmt;	/* Maximal PM timeout */
  1023  	__u16		pmp_flags;	/* How to decode max/min PM period */
  1024  	__u16		pmt_flags;	/* How to decode max/min PM timeout */
  1025  	__u16		pm_capa;	/* What PM options are supported */
  1026  
  1027  	/* Encoder stuff */
  1028  	__u16	encoding_size[IW_MAX_ENCODING_SIZES];	/* Different token sizes */
  1029  	__u8	num_encoding_sizes;	/* Number of entry in the list */
  1030  	__u8	max_encoding_tokens;	/* Max number of tokens */
  1031  	/* For drivers that need a "login/passwd" form */
  1032  	__u8	encoding_login_index;	/* token index for login token */
  1033  
  1034  	/* Transmit power */
  1035  	__u16		txpower_capa;	/* What options are supported */
  1036  	__u8		num_txpower;	/* Number of entries in the list */
  1037  	__s32		txpower[IW_MAX_TXPOWER];	/* list, in bps */
  1038  
  1039  	/* Wireless Extension version info */
  1040  	__u8		we_version_compiled;	/* Must be WIRELESS_EXT */
  1041  	__u8		we_version_source;	/* Last update of source */
  1042  
  1043  	/* Retry limits and lifetime */
  1044  	__u16		retry_capa;	/* What retry options are supported */
  1045  	__u16		retry_flags;	/* How to decode max/min retry limit */
  1046  	__u16		r_time_flags;	/* How to decode max/min retry life */
  1047  	__s32		min_retry;	/* Minimal number of retries */
  1048  	__s32		max_retry;	/* Maximal number of retries */
  1049  	__s32		min_r_time;	/* Minimal retry lifetime */
  1050  	__s32		max_r_time;	/* Maximal retry lifetime */
  1051  
  1052  	/* Frequency */
  1053  	__u16		num_channels;	/* Number of channels [0; num - 1] */
  1054  	__u8		num_frequency;	/* Number of entry in the list */
  1055  	struct iw_freq	freq[IW_MAX_FREQUENCIES];	/* list */
  1056  	/* Note : this frequency list doesn't need to fit channel numbers,
  1057  	 * because each entry contain its channel index */
  1058  
  1059  	__u32		enc_capa;	/* IW_ENC_CAPA_* bit field */
  1060  };
  1061  
  1062  /*
  1063   * Private ioctl interface information
  1064   */
  1065  
  1066  struct iw_priv_args {
  1067  	__u32		cmd;		/* Number of the ioctl to issue */
  1068  	__u16		set_args;	/* Type and number of args */
  1069  	__u16		get_args;	/* Type and number of args */
  1070  	char		name[IFNAMSIZ];	/* Name of the extension */
  1071  };
  1072  
  1073  /* ----------------------- WIRELESS EVENTS ----------------------- */
  1074  /*
  1075   * Wireless events are carried through the rtnetlink socket to user
  1076   * space. They are encapsulated in the IFLA_WIRELESS field of
  1077   * a RTM_NEWLINK message.
  1078   */
  1079  
  1080  /*
  1081   * A Wireless Event. Contains basically the same data as the ioctl...
  1082   */
  1083  struct iw_event {
  1084  	__u16		len;			/* Real length of this stuff */
  1085  	__u16		cmd;			/* Wireless IOCTL */
  1086  	union iwreq_data	u;		/* IOCTL fixed payload */
  1087  };
  1088  
  1089  /* Size of the Event prefix (including padding and alignement junk) */
  1090  #define IW_EV_LCP_LEN	(sizeof(struct iw_event) - sizeof(union iwreq_data))
  1091  /* Size of the various events */
  1092  #define IW_EV_CHAR_LEN	(IW_EV_LCP_LEN + IFNAMSIZ)
  1093  #define IW_EV_UINT_LEN	(IW_EV_LCP_LEN + sizeof(__u32))
  1094  #define IW_EV_FREQ_LEN	(IW_EV_LCP_LEN + sizeof(struct iw_freq))
  1095  #define IW_EV_PARAM_LEN	(IW_EV_LCP_LEN + sizeof(struct iw_param))
  1096  #define IW_EV_ADDR_LEN	(IW_EV_LCP_LEN + sizeof(struct sockaddr))
  1097  #define IW_EV_QUAL_LEN	(IW_EV_LCP_LEN + sizeof(struct iw_quality))
  1098  
  1099  /* iw_point events are special. First, the payload (extra data) come at
  1100   * the end of the event, so they are bigger than IW_EV_POINT_LEN. Second,
  1101   * we omit the pointer, so start at an offset. */
  1102  #define IW_EV_POINT_OFF (((char *) &(((struct iw_point *) NULL)->length)) - \
  1103  			  (char *) NULL)
  1104  #define IW_EV_POINT_LEN	(IW_EV_LCP_LEN + sizeof(struct iw_point) - \
  1105  			 IW_EV_POINT_OFF)
  1106  
  1107  
  1108  /* Size of the Event prefix when packed in stream */
  1109  #define IW_EV_LCP_PK_LEN	(4)
  1110  /* Size of the various events when packed in stream */
  1111  #define IW_EV_CHAR_PK_LEN	(IW_EV_LCP_PK_LEN + IFNAMSIZ)
  1112  #define IW_EV_UINT_PK_LEN	(IW_EV_LCP_PK_LEN + sizeof(__u32))
  1113  #define IW_EV_FREQ_PK_LEN	(IW_EV_LCP_PK_LEN + sizeof(struct iw_freq))
  1114  #define IW_EV_PARAM_PK_LEN	(IW_EV_LCP_PK_LEN + sizeof(struct iw_param))
  1115  #define IW_EV_ADDR_PK_LEN	(IW_EV_LCP_PK_LEN + sizeof(struct sockaddr))
  1116  #define IW_EV_QUAL_PK_LEN	(IW_EV_LCP_PK_LEN + sizeof(struct iw_quality))
  1117  #define IW_EV_POINT_PK_LEN	(IW_EV_LCP_PK_LEN + 4)
  1118  
  1119  #endif /* _LINUX_WIRELESS_H */
  1120  `
  1121  
  1122  // This is the standard Unix style binary blob interface with all the
  1123  // conversion fun that implies. Bummer.
  1124  
  1125  /*
  1126   * This file define a set of standard wireless extensions
  1127   *
  1128   * Version :	22	16.3.07
  1129   *
  1130   * Authors :	Jean Tourrilhes - HPL - <jt@hpl.hp.com>
  1131   * Copyright (c) 1997-2007 Jean Tourrilhes, All Rights Reserved.
  1132   */
  1133  
  1134  /************************** DOCUMENTATION **************************/
  1135  /*
  1136   * Initial APIs (1996 -> onward) :
  1137   * -----------------------------
  1138   * Basically, the wireless extensions are for now a set of standard ioctl
  1139   * call + /proc/net/wireless
  1140   *
  1141   * The entry /proc/net/wireless give statistics and information on the
  1142   * driver.
  1143   * This is better than having each driver having its entry because
  1144   * its centralised and we may remove the driver module safely.
  1145   *
  1146   * Ioctl are used to configure the driver and issue commands.  This is
  1147   * better than command line options of insmod because we may want to
  1148   * change dynamically (while the driver is running) some parameters.
  1149   *
  1150   * The ioctl mechanimsm are copied from standard devices ioctl.
  1151   * We have the list of command plus a structure descibing the
  1152   * data exchanged...
  1153   * Note that to add these ioctl, I was obliged to modify :
  1154   *	# net/core/dev.c (two place + add include)
  1155   *	# net/ipv4/af_inet.c (one place + add include)
  1156   *
  1157   * /proc/net/wireless is a copy of /proc/net/dev.
  1158   * We have a structure for data passed from the driver to /proc/net/wireless
  1159   * Too add this, I've modified :
  1160   *	# net/core/dev.c (two other places)
  1161   *	# include/linux/netdevice.h (one place)
  1162   *	# include/linux/proc_fs.h (one place)
  1163   *
  1164   * New driver API (2002 -> onward) :
  1165   * -------------------------------
  1166   * This file is only concerned with the user space API and common definitions.
  1167   * The new driver API is defined and documented in :
  1168   *	# include/net/iw_handler.h
  1169   *
  1170   * Note as well that /proc/net/wireless implementation has now moved in :
  1171   *	# net/core/wireless.c
  1172   *
  1173   * Wireless Events (2002 -> onward) :
  1174   * --------------------------------
  1175   * Events are defined at the end of this file, and implemented in :
  1176   *	# net/core/wireless.c
  1177   *
  1178   * Other comments :
  1179   * --------------
  1180   * Do not add here things that are redundant with other mechanisms
  1181   * (drivers init, ifconfig, /proc/net/dev, ...) and with are not
  1182   * wireless specific.
  1183   *
  1184   * These wireless extensions are not magic : each driver has to provide
  1185   * support for them...
  1186   *
  1187   * IMPORTANT NOTE : As everything in the kernel, this is very much a
  1188   * work in progress. Contact me if you have ideas of improvements...
  1189   */
  1190  
  1191  /***************************** VERSION *****************************/
  1192  /*
  1193   * This constant is used to know the availability of the wireless
  1194   * extensions and to know which version of wireless extensions it is
  1195   * (there is some stuff that will be added in the future...)
  1196   * I just plan to increment with each new version.
  1197   */
  1198  const WIRELESS_EXT = 22
  1199  
  1200  /*
  1201   * Changes :
  1202   *
  1203   * V2 to V3
  1204   * --------
  1205   *	Alan Cox start some incompatibles changes. I've integrated a bit more.
  1206   *	- Encryption renamed to Encode to avoid US regulation problems
  1207   *	- Frequency changed from float to struct to avoid problems on old 386
  1208   *
  1209   * V3 to V4
  1210   * --------
  1211   *	- Add sensitivity
  1212   *
  1213   * V4 to V5
  1214   * --------
  1215   *	- Missing encoding definitions in range
  1216   *	- Access points stuff
  1217   *
  1218   * V5 to V6
  1219   * --------
  1220   *	- 802.11 support (ESSID ioctls)
  1221   *
  1222   * V6 to V7
  1223   * --------
  1224   *	- define IW_ESSID_MAX_SIZE and IW_MAX_AP
  1225   *
  1226   * V7 to V8
  1227   * --------
  1228   *	- Changed my e-mail address
  1229   *	- More 802.11 support (nickname, rate, rts, frag)
  1230   *	- List index in frequencies
  1231   *
  1232   * V8 to V9
  1233   * --------
  1234   *	- Support for 'mode of operation' (ad-hoc, managed...)
  1235   *	- Support for unicast and multicast power saving
  1236   *	- Change encoding to support larger tokens (>64 bits)
  1237   *	- Updated iw_params (disable, flags) and use it for NWID
  1238   *	- Extracted iw_point from iwreq for clarity
  1239   *
  1240   * V9 to V10
  1241   * ---------
  1242   *	- Add PM capability to range structure
  1243   *	- Add PM modifier : MAX/MIN/RELATIVE
  1244   *	- Add encoding option : IW_ENCODE_NOKEY
  1245   *	- Add TxPower ioctls (work like TxRate)
  1246   *
  1247   * V10 to V11
  1248   * ----------
  1249   *	- Add WE version in range (help backward/forward compatibility)
  1250   *	- Add retry ioctls (work like PM)
  1251   *
  1252   * V11 to V12
  1253   * ----------
  1254   *	- Add SIOCSIWSTATS to get /proc/net/wireless programatically
  1255   *	- Add DEV PRIVATE IOCTL to avoid collisions in SIOCDEVPRIVATE space
  1256   *	- Add new statistics (frag, retry, beacon)
  1257   *	- Add average quality (for user space calibration)
  1258   *
  1259   * V12 to V13
  1260   * ----------
  1261   *	- Document creation of new driver API.
  1262   *	- Extract union iwreq_data from struct iwreq (for new driver API).
  1263   *	- Rename SIOCSIWNAME as SIOCSIWCOMMIT
  1264   *
  1265   * V13 to V14
  1266   * ----------
  1267   *	- Wireless Events support : define struct iw_event
  1268   *	- Define additional specific event numbers
  1269   *	- Add "addr" and "param" fields in union iwreq_data
  1270   *	- AP scanning stuff (SIOCSIWSCAN and friends)
  1271   *
  1272   * V14 to V15
  1273   * ----------
  1274   *	- Add IW_PRIV_TYPE_ADDR for struct sockaddr private arg
  1275   *	- Make struct iw_freq signed (both m & e), add explicit padding
  1276   *	- Add IWEVCUSTOM for driver specific event/scanning token
  1277   *	- Add IW_MAX_GET_SPY for driver returning a lot of addresses
  1278   *	- Add IW_TXPOW_RANGE for range of Tx Powers
  1279   *	- Add IWEVREGISTERED & IWEVEXPIRED events for Access Points
  1280   *	- Add IW_MODE_MONITOR for passive monitor
  1281   *
  1282   * V15 to V16
  1283   * ----------
  1284   *	- Increase the number of bitrates in iw_range to 32 (for 802.11g)
  1285   *	- Increase the number of frequencies in iw_range to 32 (for 802.11b+a)
  1286   *	- Reshuffle struct iw_range for increases, add filler
  1287   *	- Increase IW_MAX_AP to 64 for driver returning a lot of addresses
  1288   *	- Remove IW_MAX_GET_SPY because conflict with enhanced spy support
  1289   *	- Add SIOCSIWTHRSPY/SIOCGIWTHRSPY and "struct iw_thrspy"
  1290   *	- Add IW_ENCODE_TEMP and iw_range->encoding_login_index
  1291   *
  1292   * V16 to V17
  1293   * ----------
  1294   *	- Add flags to frequency -> auto/fixed
  1295   *	- Document (struct iw_quality *)->updated, add new flags (INVALID)
  1296   *	- Wireless Event capability in struct iw_range
  1297   *	- Add support for relative TxPower (yick !)
  1298   *
  1299   * V17 to V18 (From Jouni Malinen <j@w1.fi>)
  1300   * ----------
  1301   *	- Add support for WPA/WPA2
  1302   *	- Add extended encoding configuration (SIOCSIWENCODEEXT and
  1303   *	  SIOCGIWENCODEEXT)
  1304   *	- Add SIOCSIWGENIE/SIOCGIWGENIE
  1305   *	- Add SIOCSIWMLME
  1306   *	- Add SIOCSIWPMKSA
  1307   *	- Add struct iw_range bit field for supported encoding capabilities
  1308   *	- Add optional scan request parameters for SIOCSIWSCAN
  1309   *	- Add SIOCSIWAUTH/SIOCGIWAUTH for setting authentication and WPA
  1310   *	  related parameters (extensible up to 4096 parameter values)
  1311   *	- Add wireless events: IWEVGENIE, IWEVMICHAELMICFAILURE,
  1312   *	  IWEVASSOCREQIE, IWEVASSOCRESPIE, IWEVPMKIDCAND
  1313   *
  1314   * V18 to V19
  1315   * ----------
  1316   *	- Remove (struct iw_point *)->pointer from events and streams
  1317   *	- Remove header includes to help user space
  1318   *	- Increase IW_ENCODING_TOKEN_MAX from 32 to 64
  1319   *	- Add IW_QUAL_ALL_UPDATED and IW_QUAL_ALL_INVALID macros
  1320   *	- Add explicit flag to tell stats are in dBm : IW_QUAL_DBM
  1321   *	- Add IW_IOCTL_IDX() and IW_EVENT_IDX() macros
  1322   *
  1323   * V19 to V20
  1324   * ----------
  1325   *	- RtNetlink requests support (SET/GET)
  1326   *
  1327   * V20 to V21
  1328   * ----------
  1329   *	- Remove (struct net_device *)->get_wireless_stats()
  1330   *	- Change length in ESSID and NICK to strlen() instead of strlen()+1
  1331   *	- Add IW_RETRY_SHORT/IW_RETRY_LONG retry modifiers
  1332   *	- Power/Retry relative values no longer * 100000
  1333   *	- Add explicit flag to tell stats are in 802.11k RCPI : IW_QUAL_RCPI
  1334   *
  1335   * V21 to V22
  1336   * ----------
  1337   *	- Prevent leaking of kernel space in stream on 64 bits.
  1338   */
  1339  
  1340  /**************************** CONSTANTS ****************************/
  1341  
  1342  /* -------------------------- IOCTL LIST -------------------------- */
  1343  
  1344  /* Wireless Identification */
  1345  const SIOCSIWCOMMIT = 0x8B00 /* Commit pending changes to driver */
  1346  const SIOCGIWNAME = 0x8B01   /* get name == wireless protocol */
  1347  /* SIOCGIWNAME is used to verify the presence of Wireless Extensions.
  1348   * Common values : "IEEE 802.11-DS", "IEEE 802.11-FH", "IEEE 802.11b"...
  1349   * Don't put the name of your driver there, it's useless. */
  1350  
  1351  /* Basic operations */
  1352  const SIOCSIWNWID = 0x8B02 /* set network id (pre-802.11) */
  1353  const SIOCGIWNWID = 0x8B03 /* get network id (the cell) */
  1354  const SIOCSIWFREQ = 0x8B04 /* set channel/frequency (Hz) */
  1355  const SIOCGIWFREQ = 0x8B05 /* get channel/frequency (Hz) */
  1356  const SIOCSIWMODE = 0x8B06 /* set operation mode */
  1357  const SIOCGIWMODE = 0x8B07 /* get operation mode */
  1358  const SIOCSIWSENS = 0x8B08 /* set sensitivity (dBm) */
  1359  const SIOCGIWSENS = 0x8B09 /* get sensitivity (dBm) */
  1360  
  1361  /* Informative stuff */
  1362  const SIOCSIWRANGE = 0x8B0A /* Unused */
  1363  const SIOCGIWRANGE = 0x8B0B /* Get range of parameters */
  1364  const SIOCSIWPRIV = 0x8B0C  /* Unused */
  1365  const SIOCGIWPRIV = 0x8B0D  /* get private ioctl interface info */
  1366  const SIOCSIWSTATS = 0x8B0E /* Unused */
  1367  const SIOCGIWSTATS = 0x8B0F /* Get /proc/net/wireless stats */
  1368  /* SIOCGIWSTATS is strictly used between user space and the kernel, and
  1369   * is never passed to the driver (i.e. the driver will never see it). */
  1370  
  1371  /* Spy support (statistics per MAC address - used for Mobile IP support) */
  1372  const SIOCSIWSPY = 0x8B10    /* set spy addresses */
  1373  const SIOCGIWSPY = 0x8B11    /* get spy info (quality of link) */
  1374  const SIOCSIWTHRSPY = 0x8B12 /* set spy threshold (spy event) */
  1375  const SIOCGIWTHRSPY = 0x8B13 /* get spy threshold */
  1376  
  1377  /* Access Point manipulation */
  1378  const SIOCSIWAP = 0x8B14     /* set access point MAC addresses */
  1379  const SIOCGIWAP = 0x8B15     /* get access point MAC addresses */
  1380  const SIOCGIWAPLIST = 0x8B17 /* Deprecated in favor of scanning */
  1381  const SIOCSIWSCAN = 0x8B18   /* trigger scanning (list cells) */
  1382  const SIOCGIWSCAN = 0x8B19   /* get scanning results */
  1383  
  1384  /* 802.11 specific support */
  1385  const SIOCSIWESSID = 0x8B1A /* set ESSID (network name) */
  1386  const SIOCGIWESSID = 0x8B1B /* get ESSID */
  1387  const SIOCSIWNICKN = 0x8B1C /* set node name/nickname */
  1388  const SIOCGIWNICKN = 0x8B1D /* get node name/nickname */
  1389  /* As the ESSID and NICKN are strings up to 32 bytes long, it doesn't fit
  1390   * within the 'iwreq' structure, so we need to use the 'data' member to
  1391   * point to a string in user space, like it is done for RANGE... */
  1392  
  1393  /* Other parameters useful in 802.11 and some other devices */
  1394  const SIOCSIWRATE = 0x8B20  /* set default bit rate (bps) */
  1395  const SIOCGIWRATE = 0x8B21  /* get default bit rate (bps) */
  1396  const SIOCSIWRTS = 0x8B22   /* set RTS/CTS threshold (bytes) */
  1397  const SIOCGIWRTS = 0x8B23   /* get RTS/CTS threshold (bytes) */
  1398  const SIOCSIWFRAG = 0x8B24  /* set fragmentation thr (bytes) */
  1399  const SIOCGIWFRAG = 0x8B25  /* get fragmentation thr (bytes) */
  1400  const SIOCSIWTXPOW = 0x8B26 /* set transmit power (dBm) */
  1401  const SIOCGIWTXPOW = 0x8B27 /* get transmit power (dBm) */
  1402  const SIOCSIWRETRY = 0x8B28 /* set retry limits and lifetime */
  1403  const SIOCGIWRETRY = 0x8B29 /* get retry limits and lifetime */
  1404  
  1405  /* Encoding stuff (scrambling, hardware security, WEP...) */
  1406  const SIOCSIWENCODE = 0x8B2A /* set encoding token & mode */
  1407  const SIOCGIWENCODE = 0x8B2B /* get encoding token & mode */
  1408  /* Power saving stuff (power management, unicast and multicast) */
  1409  const SIOCSIWPOWER = 0x8B2C /* set Power Management settings */
  1410  const SIOCGIWPOWER = 0x8B2D /* get Power Management settings */
  1411  
  1412  /* WPA : Generic IEEE 802.11 informatiom element (e.g., for WPA/RSN/WMM).
  1413   * This ioctl uses struct iw_point and data buffer that includes IE id and len
  1414   * fields. More than one IE may be included in the request. Setting the generic
  1415   * IE to empty buffer (len=0) removes the generic IE from the driver. Drivers
  1416   * are allowed to generate their own WPA/RSN IEs, but in these cases, drivers
  1417   * are required to report the used IE as a wireless event, e.g., when
  1418   * associating with an AP. */
  1419  const SIOCSIWGENIE = 0x8B30 /* set generic IE */
  1420  const SIOCGIWGENIE = 0x8B31 /* get generic IE */
  1421  
  1422  /* WPA : IEEE 802.11 MLME requests */
  1423  const SIOCSIWMLME = 0x8B16 /* request MLME operation; uses
  1424   * struct iw_mlme */
  1425  /* WPA : Authentication mode parameters */
  1426  const SIOCSIWAUTH = 0x8B32 /* set authentication mode params */
  1427  const SIOCGIWAUTH = 0x8B33 /* get authentication mode params */
  1428  
  1429  /* WPA : Extended version of encoding configuration */
  1430  const SIOCSIWENCODEEXT = 0x8B34 /* set encoding token & mode */
  1431  const SIOCGIWENCODEEXT = 0x8B35 /* get encoding token & mode */
  1432  
  1433  /* WPA2 : PMKSA cache management */
  1434  const SIOCSIWPMKSA = 0x8B36 /* PMKSA cache operation */
  1435  
  1436  /* -------------------- DEV PRIVATE IOCTL LIST -------------------- */
  1437  
  1438  /* These 32 ioctl are wireless device private, for 16 commands.
  1439   * Each driver is free to use them for whatever purpose it chooses,
  1440   * however the driver *must* export the description of those ioctls
  1441   * with SIOCGIWPRIV and *must* use arguments as defined below.
  1442   * If you don't follow those rules, DaveM is going to hate you (reason :
  1443   * it make mixed 32/64bit operation impossible).
  1444   */
  1445  const SIOCIWFIRSTPRIV = 0x8BE0
  1446  const SIOCIWLASTPRIV = 0x8BFF
  1447  
  1448  /* Previously, we were using SIOCDEVPRIVATE, but we now have our
  1449   * separate range because of collisions with other tools such as
  1450   * 'mii-tool'.
  1451   * We now have 32 commands, so a bit more space ;-).
  1452   * Also, all 'even' commands are only usable by root and don't return the
  1453   * content of ifr/iwr to user (but you are not obliged to use the set/get
  1454   * convention, just use every other two command). More details in iwpriv.c.
  1455   * And I repeat : you are not forced to use them with iwpriv, but you
  1456   * must be compliant with it.
  1457   */
  1458  
  1459  /* ------------------------- IOCTL STUFF ------------------------- */
  1460  
  1461  /* The first and the last (range) */
  1462  const SIOCIWFIRST = 0x8B00
  1463  const SIOCIWLAST = SIOCIWLASTPRIV /* 0x8BFF */
  1464  //const IW_IOCTL_IDX(cmd) = ((cmd) - SIOCIWFIRST)
  1465  //const IW_HANDLER(id, = func)			 [IW_IOCTL_IDX(id)] = func
  1466  
  1467  // What is this stuff?
  1468  // Odd is right.
  1469  /* Odd : get (world access), even : set (root access) */
  1470  func IW_IS_SET(cmd uint32) bool {
  1471  	return !(((cmd) & 0x1) != 0)
  1472  }
  1473  func IW_IS_GET(cmd uint32) bool {
  1474  	return ((cmd) & 0x1) != 0
  1475  }
  1476  
  1477  /* ----------------------- WIRELESS EVENTS ----------------------- */
  1478  /* Those are *NOT* ioctls, do not issue request on them !!! */
  1479  /* Most events use the same identifier as ioctl requests */
  1480  
  1481  const IWEVTXDROP = 0x8C00     /* Packet dropped to excessive retry */
  1482  const IWEVQUAL = 0x8C01       /* Quality part of statistics (scan) */
  1483  const IWEVCUSTOM = 0x8C02     /* Driver specific ascii string */
  1484  const IWEVREGISTERED = 0x8C03 /* Discovered a new node (AP mode) */
  1485  const IWEVEXPIRED = 0x8C04    /* Expired a node (AP mode) */
  1486  const IWEVGENIE = 0x8C05      /* Generic IE (WPA, RSN, WMM, ..)
  1487   * (scan results); This includes id and
  1488   * length fields. One IWEVGENIE may
  1489   * contain more than one IE. Scan
  1490   * results may contain one or more
  1491   * IWEVGENIE events. */
  1492  const IWEVMICHAELMICFAILURE = 0x8C06 /* Michael MIC failure
  1493   * (struct iw_michaelmicfailure)
  1494   */
  1495  const IWEVASSOCREQIE = 0x8C07 /* IEs used in (Re)Association Request.
  1496   * The data includes id and length
  1497   * fields and may contain more than one
  1498   * IE. This event is required in
  1499   * Managed mode if the driver
  1500   * generates its own WPA/RSN IE. This
  1501   * should be sent just before
  1502   * IWEVREGISTERED event for the
  1503   * association. */
  1504  const IWEVASSOCRESPIE = 0x8C08 /* IEs used in (Re)Association
  1505   * Response. The data includes id and
  1506   * length fields and may contain more
  1507   * than one IE. This may be sent
  1508   * between IWEVASSOCREQIE and
  1509   * IWEVREGISTERED events for the
  1510   * association. */
  1511  const IWEVPMKIDCAND = 0x8C09 /* PMKID candidate for RSN
  1512   * pre-authentication
  1513   * (struct iw_pmkid_cand) */
  1514  
  1515  const IWEVFIRST = 0x8C00
  1516  
  1517  func IW_EVENT_IDX(cmd uint32) uint32 {
  1518  	return cmd - IWEVFIRST
  1519  }
  1520  
  1521  /* ------------------------- PRIVATE INFO ------------------------- */
  1522  /*
  1523   * The following is used with SIOCGIWPRIV. It allow a driver to define
  1524   * the interface (name, type of data) for its private ioctl.
  1525   * Privates ioctl are SIOCIWFIRSTPRIV -> SIOCIWLASTPRIV
  1526   */
  1527  
  1528  const IW_PRIV_TYPE_MASK = 0x7000 /* Type of arguments */
  1529  const IW_PRIV_TYPE_NONE = 0x0000
  1530  const IW_PRIV_TYPE_BYTE = 0x1000  /* Char as number */
  1531  const IW_PRIV_TYPE_CHAR = 0x2000  /* Char as character */
  1532  const IW_PRIV_TYPE_INT = 0x4000   /* 32 bits int */
  1533  const IW_PRIV_TYPE_FLOAT = 0x5000 /* struct iw_freq */
  1534  const IW_PRIV_TYPE_ADDR = 0x6000  /* struct sockaddr */
  1535  
  1536  const IW_PRIV_SIZE_FIXED = 0x0800 /* Variable or fixed number of args */
  1537  
  1538  const IW_PRIV_SIZE_MASK = 0x07FF /* Max number of those args */
  1539  
  1540  /*
  1541   * Note : if the number of args is fixed and the size < 16 octets,
  1542   * instead of passing a pointer we will put args in the iwreq struct...
  1543   */
  1544  
  1545  /* ----------------------- OTHER CONSTANTS ----------------------- */
  1546  
  1547  /* Maximum frequencies in the range struct */
  1548  const IW_MAX_FREQUENCIES = 32
  1549  
  1550  /* Note : if you have something like 80 frequencies,
  1551   * don't increase this constant and don't fill the frequency list.
  1552   * The user will be able to set by channel anyway... */
  1553  
  1554  /* Maximum bit rates in the range struct */
  1555  const IW_MAX_BITRATES = 32
  1556  
  1557  /* Maximum tx powers in the range struct */
  1558  const IW_MAX_TXPOWER = 8
  1559  
  1560  /* Note : if you more than 8 TXPowers, just set the max and min or
  1561   * a few of them in the struct iw_range. */
  1562  
  1563  /* Maximum of address that you may set with SPY */
  1564  const IW_MAX_SPY = 8
  1565  
  1566  /* Maximum of address that you may get in the
  1567     list of access points in range */
  1568  const IW_MAX_AP = 64
  1569  
  1570  /* Maximum size of the ESSID and NICKN strings */
  1571  const IW_ESSID_MAX_SIZE = 32
  1572  
  1573  /* Modes of operation */
  1574  const IW_MODE_AUTO = 0    /* Let the driver decides */
  1575  const IW_MODE_ADHOC = 1   /* Single cell network */
  1576  const IW_MODE_INFRA = 2   /* Multi cell network, roaming, ... */
  1577  const IW_MODE_MASTER = 3  /* Synchronisation master or Access Point */
  1578  const IW_MODE_REPEAT = 4  /* Wireless Repeater (forwarder) */
  1579  const IW_MODE_SECOND = 5  /* Secondary master/repeater (backup) */
  1580  const IW_MODE_MONITOR = 6 /* Passive monitor (listen only) */
  1581  const IW_MODE_MESH = 7    /* Mesh (IEEE 802.11s) network */
  1582  
  1583  /* Statistics flags (bitmask in updated) */
  1584  const IW_QUAL_QUAL_UPDATED = 0x01 /* Value was updated since last read */
  1585  const IW_QUAL_LEVEL_UPDATED = 0x02
  1586  const IW_QUAL_NOISE_UPDATED = 0x04
  1587  const IW_QUAL_ALL_UPDATED = 0x07
  1588  const IW_QUAL_DBM = 0x08          /* Level + Noise are dBm */
  1589  const IW_QUAL_QUAL_INVALID = 0x10 /* Driver doesn't provide value */
  1590  const IW_QUAL_LEVEL_INVALID = 0x20
  1591  const IW_QUAL_NOISE_INVALID = 0x40
  1592  const IW_QUAL_RCPI = 0x80 /* Level + Noise are 802.11k RCPI */
  1593  const IW_QUAL_ALL_INVALID = 0x70
  1594  
  1595  /* Frequency flags */
  1596  const IW_FREQ_AUTO = 0x00  /* Let the driver decides */
  1597  const IW_FREQ_FIXED = 0x01 /* Force a specific value */
  1598  
  1599  /* Maximum number of size of encoding token available
  1600   * they are listed in the range structure */
  1601  const IW_MAX_ENCODING_SIZES = 8
  1602  
  1603  /* Maximum size of the encoding token in bytes */
  1604  const IW_ENCODING_TOKEN_MAX = 64 /* 512 bits (for now) */
  1605  
  1606  /* Flags for encoding (along with the token) */
  1607  const IW_ENCODE_INDEX = 0x00FF      /* Token index (if needed) */
  1608  const IW_ENCODE_FLAGS = 0xFF00      /* Flags defined below */
  1609  const IW_ENCODE_MODE = 0xF000       /* Modes defined below */
  1610  const IW_ENCODE_DISABLED = 0x8000   /* Encoding disabled */
  1611  const IW_ENCODE_ENABLED = 0x0000    /* Encoding enabled */
  1612  const IW_ENCODE_RESTRICTED = 0x4000 /* Refuse non-encoded packets */
  1613  const IW_ENCODE_OPEN = 0x2000       /* Accept non-encoded packets */
  1614  const IW_ENCODE_NOKEY = 0x0800      /* Key is write only, so not present */
  1615  const IW_ENCODE_TEMP = 0x0400       /* Temporary key */
  1616  
  1617  /* Power management flags available (along with the value, if any) */
  1618  const IW_POWER_ON = 0x0000          /* No details... */
  1619  const IW_POWER_TYPE = 0xF000        /* Type of parameter */
  1620  const IW_POWER_PERIOD = 0x1000      /* Value is a period/duration of  */
  1621  const IW_POWER_TIMEOUT = 0x2000     /* Value is a timeout (to go asleep) */
  1622  const IW_POWER_MODE = 0x0F00        /* Power Management mode */
  1623  const IW_POWER_UNICAST_R = 0x0100   /* Receive only unicast messages */
  1624  const IW_POWER_MULTICAST_R = 0x0200 /* Receive only multicast messages */
  1625  const IW_POWER_ALL_R = 0x0300       /* Receive all messages though PM */
  1626  const IW_POWER_FORCE_S = 0x0400     /* Force PM procedure for sending unicast */
  1627  const IW_POWER_REPEATER = 0x0800    /* Repeat broadcast messages in PM period */
  1628  const IW_POWER_MODIFIER = 0x000F    /* Modify a parameter */
  1629  const IW_POWER_MIN = 0x0001         /* Value is a minimum  */
  1630  const IW_POWER_MAX = 0x0002         /* Value is a maximum */
  1631  const IW_POWER_RELATIVE = 0x0004    /* Value is not in seconds/ms/us */
  1632  
  1633  /* Transmit Power flags available */
  1634  const IW_TXPOW_TYPE = 0x00FF     /* Type of value */
  1635  const IW_TXPOW_DBM = 0x0000      /* Value is in dBm */
  1636  const IW_TXPOW_MWATT = 0x0001    /* Value is in mW */
  1637  const IW_TXPOW_RELATIVE = 0x0002 /* Value is in arbitrary units */
  1638  const IW_TXPOW_RANGE = 0x1000    /* Range of value between min/max */
  1639  
  1640  /* Retry limits and lifetime flags available */
  1641  const IW_RETRY_ON = 0x0000       /* No details... */
  1642  const IW_RETRY_TYPE = 0xF000     /* Type of parameter */
  1643  const IW_RETRY_LIMIT = 0x1000    /* Maximum number of retries*/
  1644  const IW_RETRY_LIFETIME = 0x2000 /* Maximum duration of retries in us */
  1645  const IW_RETRY_MODIFIER = 0x00FF /* Modify a parameter */
  1646  const IW_RETRY_MIN = 0x0001      /* Value is a minimum  */
  1647  const IW_RETRY_MAX = 0x0002      /* Value is a maximum */
  1648  const IW_RETRY_RELATIVE = 0x0004 /* Value is not in seconds/ms/us */
  1649  const IW_RETRY_SHORT = 0x0010    /* Value is for short packets  */
  1650  const IW_RETRY_LONG = 0x0020     /* Value is for long packets */
  1651  
  1652  /* Scanning request flags */
  1653  const IW_SCAN_DEFAULT = 0x0000    /* Default scan of the driver */
  1654  const IW_SCAN_ALL_ESSID = 0x0001  /* Scan all ESSIDs */
  1655  const IW_SCAN_THIS_ESSID = 0x0002 /* Scan only this ESSID */
  1656  const IW_SCAN_ALL_FREQ = 0x0004   /* Scan all Frequencies */
  1657  const IW_SCAN_THIS_FREQ = 0x0008  /* Scan only this Frequency */
  1658  const IW_SCAN_ALL_MODE = 0x0010   /* Scan all Modes */
  1659  const IW_SCAN_THIS_MODE = 0x0020  /* Scan only this Mode */
  1660  const IW_SCAN_ALL_RATE = 0x0040   /* Scan all Bit-Rates */
  1661  const IW_SCAN_THIS_RATE = 0x0080  /* Scan only this Bit-Rate */
  1662  /* struct iw_scan_req scan_type */
  1663  const IW_SCAN_TYPE_ACTIVE = 0
  1664  const IW_SCAN_TYPE_PASSIVE = 1
  1665  
  1666  /* Maximum size of returned data */
  1667  const IW_SCAN_MAX_DATA = 4096 /* In bytes */
  1668  
  1669  /* Scan capability flags - in (struct iw_range *)->scan_capa */
  1670  const IW_SCAN_CAPA_NONE = 0x00
  1671  const IW_SCAN_CAPA_ESSID = 0x01
  1672  const IW_SCAN_CAPA_BSSID = 0x02
  1673  const IW_SCAN_CAPA_CHANNEL = 0x04
  1674  const IW_SCAN_CAPA_MODE = 0x08
  1675  const IW_SCAN_CAPA_RATE = 0x10
  1676  const IW_SCAN_CAPA_TYPE = 0x20
  1677  const IW_SCAN_CAPA_TIME = 0x40
  1678  
  1679  /* Max number of char in custom event - use multiple of them if needed */
  1680  const IW_CUSTOM_MAX = 256 /* In bytes */
  1681  
  1682  /* Generic information element */
  1683  const IW_GENERIC_IE_MAX = 1024
  1684  
  1685  /* MLME requests (SIOCSIWMLME / struct iw_mlme) */
  1686  const IW_MLME_DEAUTH = 0
  1687  const IW_MLME_DISASSOC = 1
  1688  const IW_MLME_AUTH = 2
  1689  const IW_MLME_ASSOC = 3
  1690  
  1691  /* SIOCSIWAUTH/SIOCGIWAUTH struct iw_param flags */
  1692  const IW_AUTH_INDEX = 0x0FFF
  1693  const IW_AUTH_FLAGS = 0xF000
  1694  
  1695  /* SIOCSIWAUTH/SIOCGIWAUTH parameters (0 .. 4095)
  1696   * (IW_AUTH_INDEX mask in struct iw_param flags; this is the index of the
  1697   * parameter that is being set/get to; value will be read/written to
  1698   * struct iw_param value field) */
  1699  const IW_AUTH_WPA_VERSION = 0
  1700  const IW_AUTH_CIPHER_PAIRWISE = 1
  1701  const IW_AUTH_CIPHER_GROUP = 2
  1702  const IW_AUTH_KEY_MGMT = 3
  1703  const IW_AUTH_TKIP_COUNTERMEASURES = 4
  1704  const IW_AUTH_DROP_UNENCRYPTED = 5
  1705  const IW_AUTH_80211_AUTH_ALG = 6
  1706  const IW_AUTH_WPA_ENABLED = 7
  1707  const IW_AUTH_RX_UNENCRYPTED_EAPOL = 8
  1708  const IW_AUTH_ROAMING_CONTROL = 9
  1709  const IW_AUTH_PRIVACY_INVOKED = 10
  1710  const IW_AUTH_CIPHER_GROUP_MGMT = 11
  1711  const IW_AUTH_MFP = 12
  1712  
  1713  /* IW_AUTH_WPA_VERSION values (bit field) */
  1714  const IW_AUTH_WPA_VERSION_DISABLED = 0x00000001
  1715  const IW_AUTH_WPA_VERSION_WPA = 0x00000002
  1716  const IW_AUTH_WPA_VERSION_WPA2 = 0x00000004
  1717  
  1718  /* IW_AUTH_PAIRWISE_CIPHER, IW_AUTH_GROUP_CIPHER, and IW_AUTH_CIPHER_GROUP_MGMT
  1719   * values (bit field) */
  1720  const IW_AUTH_CIPHER_NONE = 0x00000001
  1721  const IW_AUTH_CIPHER_WEP40 = 0x00000002
  1722  const IW_AUTH_CIPHER_TKIP = 0x00000004
  1723  const IW_AUTH_CIPHER_CCMP = 0x00000008
  1724  const IW_AUTH_CIPHER_WEP104 = 0x00000010
  1725  const IW_AUTH_CIPHER_AES_CMAC = 0x00000020
  1726  
  1727  /* IW_AUTH_KEY_MGMT values (bit field) */
  1728  const IW_AUTH_KEY_MGMT_802_1X = 1
  1729  const IW_AUTH_KEY_MGMT_PSK = 2
  1730  
  1731  /* IW_AUTH_80211_AUTH_ALG values (bit field) */
  1732  const IW_AUTH_ALG_OPEN_SYSTEM = 0x00000001
  1733  const IW_AUTH_ALG_SHARED_KEY = 0x00000002
  1734  const IW_AUTH_ALG_LEAP = 0x00000004
  1735  
  1736  /* IW_AUTH_ROAMING_CONTROL values */
  1737  const IW_AUTH_ROAMING_ENABLE = 0  /* driver/firmware based roaming */
  1738  const IW_AUTH_ROAMING_DISABLE = 1 /* user space program used for roaming
  1739   * control */
  1740  
  1741  /* IW_AUTH_MFP (management frame protection) values */
  1742  const IW_AUTH_MFP_DISABLED = 0 /* MFP disabled */
  1743  const IW_AUTH_MFP_OPTIONAL = 1 /* MFP optional */
  1744  const IW_AUTH_MFP_REQUIRED = 2 /* MFP required */
  1745  
  1746  /* SIOCSIWENCODEEXT definitions */
  1747  const IW_ENCODE_SEQ_MAX_SIZE = 8
  1748  
  1749  /* struct iw_encode_ext ->alg */
  1750  const IW_ENCODE_ALG_NONE = 0
  1751  const IW_ENCODE_ALG_WEP = 1
  1752  const IW_ENCODE_ALG_TKIP = 2
  1753  const IW_ENCODE_ALG_CCMP = 3
  1754  const IW_ENCODE_ALG_PMK = 4
  1755  const IW_ENCODE_ALG_AES_CMAC = 5
  1756  
  1757  /* struct iw_encode_ext ->ext_flags */
  1758  const IW_ENCODE_EXT_TX_SEQ_VALID = 0x00000001
  1759  const IW_ENCODE_EXT_RX_SEQ_VALID = 0x00000002
  1760  const IW_ENCODE_EXT_GROUP_KEY = 0x00000004
  1761  const IW_ENCODE_EXT_SET_TX_KEY = 0x00000008
  1762  
  1763  /* IWEVMICHAELMICFAILURE : struct iw_michaelmicfailure ->flags */
  1764  const IW_MICFAILURE_KEY_ID = 0x00000003 /* Key ID 0..3 */
  1765  const IW_MICFAILURE_GROUP = 0x00000004
  1766  const IW_MICFAILURE_PAIRWISE = 0x00000008
  1767  const IW_MICFAILURE_STAKEY = 0x00000010
  1768  const IW_MICFAILURE_COUNT = 0x00000060 /* 1 or 2 (0 = count not supported)
  1769   */
  1770  
  1771  /* Bit field values for enc_capa in struct iw_range */
  1772  const IW_ENC_CAPA_WPA = 0x00000001
  1773  const IW_ENC_CAPA_WPA2 = 0x00000002
  1774  const IW_ENC_CAPA_CIPHER_TKIP = 0x00000004
  1775  const IW_ENC_CAPA_CIPHER_CCMP = 0x00000008
  1776  const IW_ENC_CAPA_4WAY_HANDSHAKE = 0x00000010
  1777  
  1778  /* Event capability macros - in (struct iw_range *)->event_capa
  1779   * Because we have more than 32 possible events, we use an array of
  1780   * 32 bit bitmasks. Note : 32 bits = 0x20 = 2^5. */
  1781  func IW_EVENT_CAPA_BASE(cmd uint32) uint32 {
  1782  	if cmd >= SIOCIWFIRSTPRIV {
  1783  		return cmd - SIOCIWFIRSTPRIV + 0x60
  1784  	}
  1785  	return cmd - SIOCIWFIRST
  1786  }
  1787  func IW_EVENT_CAPA_INDEX(cmd uint32) uint32 {
  1788  	return IW_EVENT_CAPA_BASE(cmd) >> 5
  1789  }
  1790  func IW_EVENT_CAPA_MASK(cmd uint32) uint32 {
  1791  	return (1 << (IW_EVENT_CAPA_BASE(cmd) & 0x1F))
  1792  }
  1793  
  1794  /* Event capability constants - event autogenerated by the kernel
  1795   * This list is valid for most 802.11 devices, customise as needed... */
  1796  var IW_EVENT_CAPA_K_0 = (IW_EVENT_CAPA_MASK(0x8B04) | IW_EVENT_CAPA_MASK(0x8B06) | IW_EVENT_CAPA_MASK(0x8B1A))
  1797  var IW_EVENT_CAPA_K_1 = (IW_EVENT_CAPA_MASK(0x8B2A))
  1798  
  1799  /* "Easy" macro to set events in iw_range (less efficient) */
  1800  func IW_EVENT_CAPA_SET(event_capa []uint32, cmd uint32) {
  1801  	event_capa[IW_EVENT_CAPA_INDEX(cmd)] |= IW_EVENT_CAPA_MASK(cmd)
  1802  }
  1803  
  1804  func IW_EVENT_CAPA_SET_KERNEL(event_capa []uint32) {
  1805  	event_capa[0] |= IW_EVENT_CAPA_K_0
  1806  	event_capa[1] |= IW_EVENT_CAPA_K_1
  1807  }
  1808  
  1809  /****************************** TYPES ******************************/
  1810  
  1811  /* --------------------------- SUBTYPES --------------------------- */
  1812  /*
  1813   *	Generic format for most parameters that fit in an int
  1814   */
  1815  type iw_param struct {
  1816  	value    int32  /* The value of the parameter itself */
  1817  	fixed    uint8  /* Hardware should not use auto select */
  1818  	disabled uint8  /* Disable the feature */
  1819  	flags    uint16 /* Various specifc flags (if any) */
  1820  }
  1821  
  1822  /*
  1823   *	For all data larger than 16 octets, we need to use a
  1824   *	pointer to memory allocated in user space.
  1825   */
  1826  type iw_point struct {
  1827  	pointer unsafe.Pointer /* Pointer to the data  (in user space) */
  1828  	length  uint16         /* number of fields or size in bytes */
  1829  	flags   uint16         /* Optional params */
  1830  }
  1831  
  1832  /*
  1833   *	A frequency
  1834   *	For numbers lower than 10^9, we encode the number in 'm' and
  1835   *	set 'e' to 0
  1836   *	For number greater than 10^9, we divide it by the lowest power
  1837   *	of 10 to get 'm' lower than 10^9, with 'm'= f / (10^'e')...
  1838   *	The power of 10 is in 'e', the result of the division is in 'm'.
  1839   */
  1840  type iw_freq struct {
  1841  	m     int32 /* Mantissa */
  1842  	e     int16 /* Exponent */
  1843  	i     uint8 /* List index (when in range struct) */
  1844  	flags uint8 /* Flags (fixed/auto) */
  1845  }
  1846  
  1847  /*
  1848   *	Quality of the link
  1849   */
  1850  type iw_quality struct {
  1851  	qual uint8 /* link quality (%retries, SNR,
  1852  	   %missed beacons or better...) */
  1853  	level   uint8 /* signal level (dBm) */
  1854  	noise   uint8 /* noise level (dBm) */
  1855  	updated uint8 /* Flags to know if updated */
  1856  }
  1857  
  1858  /*
  1859   *	Packet discarded in the wireless adapter due to
  1860   *	"wireless" specific problems...
  1861   *	Note : the list of counter and statistics in net_device_stats
  1862   *	is already pretty exhaustive, and you should use that first.
  1863   *	This is only additional stats...
  1864   */
  1865  type iw_discarded struct {
  1866  	nwid     uint32 /* Rx : Wrong nwid/essid */
  1867  	code     uint32 /* Rx : Unable to code/decode (WEP) */
  1868  	fragment uint32 /* Rx : Can't perform MAC reassembly */
  1869  	retries  uint32 /* Tx : Max MAC retries num reached */
  1870  	misc     uint32 /* Others cases */
  1871  }
  1872  
  1873  /*
  1874   *	Packet/Time period missed in the wireless adapter due to
  1875   *	"wireless" specific problems...
  1876   */
  1877  type iw_missed struct {
  1878  	beacon uint32 /* Missed beacons/superframe */
  1879  }
  1880  
  1881  type sockaddr []byte
  1882  
  1883  /*
  1884   *	Quality range (for spy threshold)
  1885   */
  1886  type iw_thrspy struct {
  1887  	addr sockaddr   /* Source address (hw/mac) */
  1888  	qual iw_quality /* Quality of the link */
  1889  	low  iw_quality /* Low threshold */
  1890  	high iw_quality /* High threshold */
  1891  }
  1892  
  1893  /*
  1894   *	Optional data for scan request
  1895   *
  1896   *	Note: these optional parameters are controlling parameters for the
  1897   *	scanning behavior, these do not apply to getting scan results
  1898   *	(SIOCGIWSCAN). Drivers are expected to keep a local BSS table and
  1899   *	provide a merged results with all BSSes even if the previous scan
  1900   *	request limited scanning to a subset, e.g., by specifying an SSID.
  1901   *	Especially, scan results are required to include an entry for the
  1902   *	current BSS if the driver is in Managed mode and associated with an AP.
  1903   */
  1904  type iw_scan_req struct {
  1905  	scan_type    uint8 /* IW_SCAN_TYPE_{ACTIVE,PASSIVE} */
  1906  	essid_len    uint8
  1907  	num_channels uint8 /* num entries in channel_list uint8
  1908  	 * 0 = scan all allowed channels */
  1909  	flags uint8 /* reserved as padding uint8 use zero, this may
  1910  	* be used in the future for adding flags
  1911  	* to request different scan behavior */
  1912  	bssid sockaddr /* ff:ff:ff:ff:ff:ff for broadcast BSSID or
  1913  	* individual address of a specific BSS */
  1914  
  1915  	/*
  1916  	 * Use this ESSID if IW_SCAN_THIS_ESSID flag is used instead of using
  1917  	 * the current ESSID. This allows scan requests for specific ESSID
  1918  	 * without having to change the current ESSID and potentially breaking
  1919  	 * the current association.
  1920  	 */
  1921  	essid [IW_ESSID_MAX_SIZE]uint8
  1922  	/*
  1923  	 * Optional parameters for changing the default scanning behavior.
  1924  	 * These are based on the MLME-SCAN.request from IEEE Std 802.11.
  1925  	 * TU is 1.024 ms. If these are set to 0, driver is expected to use
  1926  	 * reasonable default values. min_channel_time defines the time that
  1927  	 * will be used to wait for the first reply on each channel. If no
  1928  	 * replies are received, next channel will be scanned after this. If
  1929  	 * replies are received, total time waited on the channel is defined by
  1930  	 * max_channel_time.
  1931  	 */
  1932  	min_channel_time uint32 /* in TU */
  1933  	max_channel_time uint32 /* in TU */
  1934  
  1935  	channel_list [IW_MAX_FREQUENCIES]iw_freq
  1936  }
  1937  
  1938  /* ------------------------- WPA SUPPORT ------------------------- */
  1939  
  1940  /*
  1941   *	Extended data structure for get/set encoding (this is used with
  1942   *	SIOCSIWENCODEEXT/SIOCGIWENCODEEXT. struct iw_point and IW_ENCODE_*
  1943   *	flags are used in the same way as with SIOCSIWENCODE/SIOCGIWENCODE and
  1944   *	only the data contents changes (key data -> this structure, including
  1945   *	key data).
  1946   *
  1947   *	If the new key is the first group key, it will be set as the default
  1948   *	TX key. Otherwise, default TX key index is only changed if
  1949   *	IW_ENCODE_EXT_SET_TX_KEY flag is set.
  1950   *
  1951   *	Key will be changed with SIOCSIWENCODEEXT in all cases except for
  1952   *	special "change TX key index" operation which is indicated by setting
  1953   *	key_len = 0 and ext_flags |= IW_ENCODE_EXT_SET_TX_KEY.
  1954   *
  1955   *	tx_seq/rx_seq are only used when respective
  1956   *	IW_ENCODE_EXT_{TX,RX}_SEQ_VALID flag is set in ext_flags. Normal
  1957   *	TKIP/CCMP operation is to set RX seq with SIOCSIWENCODEEXT and start
  1958   *	TX seq from zero whenever key is changed. SIOCGIWENCODEEXT is normally
  1959   *	used only by an Authenticator (AP or an IBSS station) to get the
  1960   *	current TX sequence number. Using TX_SEQ_VALID for SIOCSIWENCODEEXT and
  1961   *	RX_SEQ_VALID for SIOCGIWENCODEEXT are optional, but can be useful for
  1962   *	debugging/testing.
  1963   */
  1964  type iw_encode_ext struct {
  1965  	ext_flags uint32                        /* IW_ENCODE_EXT_* */
  1966  	tx_seq    [IW_ENCODE_SEQ_MAX_SIZE]uint8 /* LSB first */
  1967  	rx_seq    [IW_ENCODE_SEQ_MAX_SIZE]uint8 /* LSB first */
  1968  	addr      sockaddr                      /* ff:ff:ff:ff:ff:ff for broadcast/multicast
  1969  	 * (group) keys or unicast address for
  1970  	 * individual keys */
  1971  	alg     uint16 /* IW_ENCODE_ALG_* */
  1972  	key_len uint16
  1973  	key     []uint8
  1974  }
  1975  
  1976  /* SIOCSIWMLME data */
  1977  type iw_mlme struct {
  1978  	cmd         uint16 /* IW_MLME_* */
  1979  	reason_code uint16
  1980  	addr        sockaddr
  1981  }
  1982  
  1983  /* SIOCSIWPMKSA data */
  1984  const IW_PMKSA_ADD = 1
  1985  const IW_PMKSA_REMOVE = 2
  1986  const IW_PMKSA_FLUSH = 3
  1987  
  1988  const IW_PMKID_LEN = 16
  1989  
  1990  type iw_pmksa struct {
  1991  	cmd   uint32 /* IW_PMKSA_* */
  1992  	bssid sockaddr
  1993  	pmkid [IW_PMKID_LEN]uint8
  1994  }
  1995  
  1996  /* IWEVMICHAELMICFAILURE data */
  1997  type iw_michaelmicfailure struct {
  1998  	flags    uint32
  1999  	src_addr sockaddr
  2000  	tsc      [IW_ENCODE_SEQ_MAX_SIZE]uint8 /* LSB first */
  2001  }
  2002  
  2003  /* IWEVPMKIDCAND data */
  2004  const IW_PMKID_CAND_PREAUTH = 0x00000001 /* RNS pre-authentication enabled */
  2005  type iw_pmkid_cand struct {
  2006  	flags uint32 /* IW_PMKID_CAND_* */
  2007  	index uint32 /* the smaller the index, the higher the
  2008  	* priority */
  2009  	bssid sockaddr
  2010  }
  2011  
  2012  /* ------------------------ WIRELESS STATS ------------------------ */
  2013  /*
  2014   * Wireless statistics (used for /proc/net/wireless)
  2015   */
  2016  type iw_statistics struct {
  2017  	status uint16 /* Status
  2018  	 * - device dependent for now */
  2019  
  2020  	qual iw_quality /* Quality of the link
  2021  	 * (instant/mean/max) */
  2022  	discard iw_quality /* Packet discarded counts */
  2023  	miss    iw_quality /* Packet missed counts */
  2024  }
  2025  
  2026  /* ------------------------ IOCTL REQUEST ------------------------ */
  2027  /*
  2028   * This structure defines the payload of an ioctl, and is used
  2029   * below.
  2030   *
  2031   * Note that this structure should fit on the memory footprint
  2032   * of iwreq (which is the same as ifreq), which mean a max size of
  2033   * 16 octets = 128 bits. Warning, pointers might be 64 bits wide...
  2034   * You should check this when increasing the structures defined
  2035   * above in this file...
  2036   *
  2037  union iwreq_data {
  2038  	/* Config - generic *
  2039  	char		name[IFNAMSIZ];
  2040  	/* Name : used to verify the presence of  wireless extensions.
  2041  	 * Name of the protocol/provider... *
  2042  
  2043  	iw_point	essid;		/* Extended network name *
  2044  	iw_param	nwid;		/* network id (or domain - the cell) *
  2045  	iw_freq	freq;		/* frequency or channel :
  2046  					 * 0-1000 = channel
  2047  					 * > 1000 = frequency in Hz *
  2048  
  2049  	iw_param	sens;		/* signal level threshold *
  2050  	iw_param	bitrate;	/* default bit rate *
  2051  	iw_param	txpower;	/* default transmit power *
  2052  	iw_param	rts;		/* RTS threshold threshold *
  2053  	iw_param	frag;		/* Fragmentation threshold *
  2054  mode uint32	 	/* Operation mode *
  2055  	iw_param	retry;		/* Retry limits & lifetime *
  2056  
  2057  	iw_point	encoding;	/* Encoding stuff : tokens *
  2058  	iw_param	power;		/* PM duration/timeout *
  2059  	iw_quality qual;		/* Quality part of statistics *
  2060  
  2061  	sockaddr	ap_addr;	/* Access point address *
  2062  	sockaddr	addr;		/* Destination address (hw/mac) *
  2063  
  2064  	iw_param	param;		/* Other small parameters *
  2065  	iw_point	data;		/* Other large parameters *
  2066  };
  2067  
  2068  /*
  2069   * The structure to exchange data for ioctl.
  2070   * This structure is the same as 'struct ifreq', but (re)defined for
  2071   * convenience...
  2072   * Do I need to remind you about structure size (32 octets) ?
  2073  */
  2074  type iwreq struct {
  2075  	//union
  2076  	//{
  2077  	//		char	ifrn_name[IFNAMSIZ];	/* if name, e.g. "eth0" */
  2078  	//	} ifr_ifrn;
  2079  
  2080  	/* Data part (defined just above) *
  2081  	union iwreq_data	u;
  2082  	*/
  2083  }
  2084  
  2085  /* -------------------------- IOCTL DATA -------------------------- */
  2086  /*
  2087   *	For those ioctl which want to exchange mode data that what could
  2088   *	fit in the above structure...
  2089   */
  2090  
  2091  /*
  2092   *	Range of parameters
  2093   */
  2094  
  2095  type IWRange struct {
  2096  	/* Informative stuff (to choose between different interface) */
  2097  	throughput uint32 /* To give an idea... */
  2098  	/* In theory this value should be the maximum benchmarked
  2099  	 * TCP/IP throughput, because with most of these devices the
  2100  	 * bit rate is meaningless (overhead an co) to estimate how
  2101  	 * fast the connection will go and pick the fastest one.
  2102  	 * I suggest people to play with Netperf or any benchmark...
  2103  	 */
  2104  
  2105  	/* NWID (or domain id) */
  2106  	min_nwid uint32 /* Minimal NWID we are able to set */
  2107  	max_nwid uint32 /* Maximal NWID we are able to set */
  2108  
  2109  	/* Old Frequency (backward compat - moved lower ) */
  2110  	old_num_channels  uint16
  2111  	old_num_frequency uint8
  2112  
  2113  	/* Scan capabilities */
  2114  	scan_capa uint8 /* IW_SCAN_CAPA_* bit field */
  2115  
  2116  	/* Wireless event capability bitmasks */
  2117  	event_capa [6]uint32
  2118  
  2119  	/* signal level threshold range */
  2120  	sensitivity int32
  2121  
  2122  	/* Quality of link & SNR stuff */
  2123  	/* Quality range (link, level, noise)
  2124  	 * If the quality is absolute, it will be in the range [0 ; max_qual],
  2125  	 * if the quality is dBm, it will be in the range [max_qual ; 0].
  2126  	 * Don't forget that we use 8 bit arithmetics... */
  2127  	max_qual iw_quality /* Quality of the link */
  2128  	/* This should contain the average/typical values of the quality
  2129  	 * indicator. This should be the threshold between a "good" and
  2130  	 * a "bad" link (example : monitor going from green to orange).
  2131  	 * Currently, user space apps like quality monitors don't have any
  2132  	 * way to calibrate the measurement. With this, they can split
  2133  	 * the range between 0 and max_qual in different quality level
  2134  	 * (using a geometric subdivision centered on the average).
  2135  	 * I expect that people doing the user space apps will feedback
  2136  	 * us on which value we need to put in each driver... */
  2137  	avg_qual iw_quality /* Quality of the link */
  2138  
  2139  	/* Rates */
  2140  	num_bitrates uint8                  /* Number of entries in the list */
  2141  	bitrate      [IW_MAX_BITRATES]int32 /* list, in bps */
  2142  
  2143  	/* RTS threshold */
  2144  	min_rts int32 /* Minimal RTS threshold */
  2145  	max_rts int32 /* Maximal RTS threshold */
  2146  
  2147  	/* Frag threshold */
  2148  	min_frag int32 /* Minimal frag threshold */
  2149  	max_frag int32 /* Maximal frag threshold */
  2150  
  2151  	/* Power Management duration & timeout */
  2152  	min_pmp   int32  /* Minimal PM period */
  2153  	max_pmp   int32  /* Maximal PM period */
  2154  	min_pmt   int32  /* Minimal PM timeout */
  2155  	max_pmt   int32  /* Maximal PM timeout */
  2156  	pmp_flags uint16 /* How to decode max/min PM period */
  2157  	pmt_flags uint16 /* How to decode max/min PM timeout */
  2158  	pm_capa   uint16 /* What PM options are supported */
  2159  
  2160  	/* Encoder stuff */
  2161  	encoding_size       [IW_MAX_ENCODING_SIZES]uint16 /* Different token sizes */
  2162  	num_encoding_sizes  uint8                         /* Number of entry in the list */
  2163  	max_encoding_tokens uint8                         /* Max number of tokens */
  2164  	/* For drivers that need a "login/passwd" form */
  2165  	encoding_login_index uint8 /* token index for login token */
  2166  
  2167  	/* Transmit power */
  2168  	txpower_capa uint16                /* What options are supported */
  2169  	num_txpower  uint8                 /* Number of entries in the list */
  2170  	txpower      [IW_MAX_TXPOWER]int32 /* list, in bps */
  2171  
  2172  	/* Wireless Extension version info */
  2173  	we_version_compiled uint8 /* Must be WIRELESS_EXT */
  2174  	we_version_source   uint8 /* Last update of source */
  2175  
  2176  	/* Retry limits and lifetime */
  2177  	retry_capa   uint16 /* What retry options are supported */
  2178  	retry_flags  uint16 /* How to decode max/min retry limit */
  2179  	r_time_flags uint16 /* How to decode max/min retry life */
  2180  	min_retry    int32  /* Minimal number of retries */
  2181  	max_retry    int32  /* Maximal number of retries */
  2182  	min_r_time   int32  /* Minimal retry lifetime */
  2183  	max_r_time   int32  /* Maximal retry lifetime */
  2184  
  2185  	/* Frequency */
  2186  	num_channels  uint16                      /* Number of channels [0; num - 1] */
  2187  	num_frequency uint8                       /* Number of entry in the list */
  2188  	freq          [IW_MAX_FREQUENCIES]iw_freq /* list */
  2189  	/* Note : this frequency list doesn't need to fit channel numbers,
  2190  	 * because each entry contain its channel index */
  2191  
  2192  	enc_capa uint32 /* IW_ENC_CAPA_* bit field */
  2193  }
  2194  
  2195  /*
  2196   * Private ioctl interface information
  2197   */
  2198  const IFNAMSIZ = 16
  2199  
  2200  type iw_priv_args struct {
  2201  	cmd      uint32         /* Number of the ioctl to issue */
  2202  	set_args uint16         /* Type and number of args */
  2203  	get_args uint16         /* Type and number of args */
  2204  	name     [IFNAMSIZ]byte /* Name of the extension */
  2205  }
  2206  
  2207  /* ----------------------- WIRELESS EVENTS ----------------------- */
  2208  /*
  2209   * Wireless events are carried through the rtnetlink socket to user
  2210   * space. They are encapsulated in the IFLA_WIRELESS field of
  2211   * a RTM_NEWLINK message.
  2212   */
  2213  
  2214  /*
  2215   * A Wireless Event. Contains basically the same data as the ioctl...
  2216   */
  2217  type iw_event struct {
  2218  	len uint16 /* Real length of this stuff */
  2219  	cmd uint16 /* Wireless IOCTL */
  2220  	//union iwreq_data	u;		/* IOCTL fixed payload */
  2221  }
  2222  
  2223  // stupid sizeof tricks for the inevitable binary interface.
  2224  /* Size of the Event prefix (including padding and alignement junk) *
  2225  const IW_EV_LCP_LEN = (sizeof(struct iw_event) - sizeof(union iwreq_data))
  2226  /* Size of the various events *
  2227  const IW_EV_CHAR_LEN = (IW_EV_LCP_LEN + IFNAMSIZ)
  2228  const IW_EV_UINT_LEN = (IW_EV_LCP_LEN + sizeof(uint32))
  2229  const IW_EV_FREQ_LEN = (IW_EV_LCP_LEN + sizeof(struct iw_freq))
  2230  const IW_EV_PARAM_LEN = (IW_EV_LCP_LEN + sizeof(struct iw_param))
  2231  const IW_EV_ADDR_LEN = (IW_EV_LCP_LEN + sizeof(struct sockaddr))
  2232  const IW_EV_QUAL_LEN = (IW_EV_LCP_LEN + sizeof(struct iw_quality))
  2233  
  2234  /* iw_point events are special. First, the payload (extra data) come at
  2235   * the end of the event, so they are bigger than IW_EV_POINT_LEN. Second,
  2236   * we omit the pointer, so start at an offset. *
  2237  const IW_EV_POINT_OFF = (((char *) &(((struct iw_point *) NULL)->length)) -  (char *) NULL)
  2238  const IW_EV_POINT_LEN = (IW_EV_LCP_LEN + sizeof(struct iw_point) -  IW_EV_POINT_OFF)
  2239  
  2240  
  2241  /* Size of the Event prefix when packed in stream */
  2242  const IW_EV_LCP_PK_LEN = (4)
  2243  
  2244  /* Size of the various events when packed in stream *
  2245  const IW_EV_CHAR_PK_LEN = (IW_EV_LCP_PK_LEN + IFNAMSIZ)
  2246  const IW_EV_UINT_PK_LEN = (IW_EV_LCP_PK_LEN + sizeof(uint32))
  2247  const IW_EV_FREQ_PK_LEN = (IW_EV_LCP_PK_LEN + sizeof(struct iw_freq))
  2248  const IW_EV_PARAM_PK_LEN = (IW_EV_LCP_PK_LEN + sizeof(struct iw_param))
  2249  const IW_EV_ADDR_PK_LEN = (IW_EV_LCP_PK_LEN + sizeof(struct sockaddr))
  2250  const IW_EV_QUAL_PK_LEN = (IW_EV_LCP_PK_LEN + sizeof(struct iw_quality))
  2251  */
  2252  const IW_EV_POINT_PK_LEN = (IW_EV_LCP_PK_LEN + 4)