Browse Source

Initial commit

Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
master
Jo-Philipp Wich 5 years ago
commit
8ae758db52
21 changed files with 14737 additions and 0 deletions
  1. +339
    -0
      COPYING
  2. +44
    -0
      Makefile
  3. +146
    -0
      api/broadcom.h
  4. +160
    -0
      api/madwifi.h
  5. +4172
    -0
      api/nl80211.h
  6. +1139
    -0
      api/wext.h
  7. +57
    -0
      hardware.txt
  8. +194
    -0
      include/iwinfo.h
  9. +79
    -0
      include/iwinfo/lua.h
  10. +47
    -0
      include/iwinfo/utils.h
  11. +839
    -0
      iwinfo_cli.c
  12. +361
    -0
      iwinfo_lib.c
  13. +901
    -0
      iwinfo_lua.c
  14. +1133
    -0
      iwinfo_madwifi.c
  15. +2492
    -0
      iwinfo_nl80211.c
  16. +70
    -0
      iwinfo_nl80211.h
  17. +367
    -0
      iwinfo_utils.c
  18. +558
    -0
      iwinfo_wext.c
  19. +382
    -0
      iwinfo_wext.h
  20. +527
    -0
      iwinfo_wext_scan.c
  21. +730
    -0
      iwinfo_wl.c

+ 339
- 0
COPYING View File

@@ -0,0 +1,339 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991

Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.

Preamble

The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Lesser General Public License instead.) You can apply it to
your programs, too.

When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.

To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.

For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.

We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.

Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.

Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.

The precise terms and conditions for copying, distribution and
modification follow.

GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".

Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.

1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.

You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.

2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:

a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.

b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.

c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)

These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.

Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.

In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.

3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:

a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,

b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,

c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)

The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.

If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.

4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.

5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.

6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.

7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.

If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.

It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.

This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.

8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.

9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.

Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.

10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.

NO WARRANTY

11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.

12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.

END OF TERMS AND CONDITIONS

How to Apply These Terms to Your New Programs

If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.

To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.

<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

Also add information on how to contact you by electronic and paper mail.

If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:

Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.

The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.

You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:

Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.

<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice

This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License.

+ 44
- 0
Makefile View File

@@ -0,0 +1,44 @@
IWINFO_BACKENDS = $(BACKENDS)
IWINFO_CFLAGS = $(CFLAGS) -std=gnu99 -fstrict-aliasing -Iinclude

IWINFO_LIB = libiwinfo.so
IWINFO_LIB_LDFLAGS = $(LDFLAGS) -shared
IWINFO_LIB_OBJ = iwinfo_utils.o iwinfo_wext.o iwinfo_wext_scan.o iwinfo_lib.o

IWINFO_LUA = iwinfo.so
IWINFO_LUA_LDFLAGS = $(LDFLAGS) -shared -L. -liwinfo -llua
IWINFO_LUA_OBJ = iwinfo_lua.o

IWINFO_CLI = iwinfo
IWINFO_CLI_LDFLAGS = $(LDFLAGS) -L. -liwinfo
IWINFO_CLI_OBJ = iwinfo_cli.o


ifneq ($(filter wl,$(IWINFO_BACKENDS)),)
IWINFO_CFLAGS += -DUSE_WL
IWINFO_LIB_OBJ += iwinfo_wl.o
endif

ifneq ($(filter madwifi,$(IWINFO_BACKENDS)),)
IWINFO_CFLAGS += -DUSE_MADWIFI
IWINFO_LIB_OBJ += iwinfo_madwifi.o
endif

ifneq ($(filter nl80211,$(IWINFO_BACKENDS)),)
IWINFO_CFLAGS += -DUSE_NL80211
IWINFO_CLI_LDFLAGS += -lnl-tiny
IWINFO_LIB_LDFLAGS += -lnl-tiny
IWINFO_LIB_OBJ += iwinfo_nl80211.o
endif


%.o: %.c
$(CC) $(IWINFO_CFLAGS) $(FPIC) -c -o $@ $<

compile: clean $(IWINFO_LIB_OBJ) $(IWINFO_LUA_OBJ) $(IWINFO_CLI_OBJ)
$(CC) $(IWINFO_LIB_LDFLAGS) -o $(IWINFO_LIB) $(IWINFO_LIB_OBJ)
$(CC) $(IWINFO_LUA_LDFLAGS) -o $(IWINFO_LUA) $(IWINFO_LUA_OBJ)
$(CC) $(IWINFO_CLI_LDFLAGS) -o $(IWINFO_CLI) $(IWINFO_CLI_OBJ)

clean:
rm -f *.o $(IWINFO_LIB) $(IWINFO_LUA) $(IWINFO_CLI)

+ 146
- 0
api/broadcom.h View File

@@ -0,0 +1,146 @@
/*
* Custom OID/ioctl definitions for
* Broadcom 802.11abg Networking Device Driver
*
* Definitions subject to change without notice.
*
* Copyright 2006, Broadcom Corporation
* All Rights Reserved.
*
* THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
* KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
* SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
*
*/

#ifndef _BROADCOM_H
#define _BROADCOM_H

#define WL_MCSSET_LEN 16
#define WL_MAX_STA_COUNT 32

#define WL_BSS_RSSI_OFFSET 82
#define WL_BSS_NOISE_OFFSET 84

#define WLC_IOCTL_MAGIC 0x14e46c77
#define WLC_IOCTL_MAXLEN 8192

#define WLC_CNTRY_BUF_SZ 4

#define WLC_GET_MAGIC 0
#define WLC_GET_RATE 12
#define WLC_GET_INFRA 19
#define WLC_GET_AUTH 21
#define WLC_GET_BSSID 23
#define WLC_GET_SSID 25
#define WLC_GET_CHANNEL 29
#define WLC_GET_PHYTYPE 39
#define WLC_GET_PASSIVE 48
#define WLC_GET_COUNTRY 83
#define WLC_GET_REVINFO 98
#define WLC_GET_AP 117
#define WLC_GET_RSSI 127
#define WLC_GET_WSEC 133
#define WLC_GET_PHY_NOISE 135
#define WLC_GET_BSS_INFO 136
#define WLC_GET_BANDLIST 140
#define WLC_GET_ASSOCLIST 159
#define WLC_GET_WPA_AUTH 164
#define WLC_GET_COUNTRY_LIST 261
#define WLC_GET_VAR 262

#define WLC_PHY_TYPE_A 0
#define WLC_PHY_TYPE_B 1
#define WLC_PHY_TYPE_G 2
#define WLC_PHY_TYPE_N 4
#define WLC_PHY_TYPE_LP 5

#define WLC_BAND_5G 1
#define WLC_BAND_2G 2
#define WLC_BAND_ALL 3


struct wl_ether_addr {
uint8_t octet[6];
};

struct wl_maclist {
uint count;
struct wl_ether_addr ea[1];
};

typedef struct wl_sta_rssi {
int rssi;
char mac[6];
uint16_t foo;
} wl_sta_rssi_t;

#define WL_NUMRATES 255 /* max # of rates in a rateset */
typedef struct wl_rateset {
uint32_t count; /* # rates in this set */
uint8_t rates[WL_NUMRATES]; /* rates in 500kbps units w/hi bit set if basic */
} wl_rateset_t;

typedef struct wl_sta_info {
uint16_t ver; /* version of this struct */
uint16_t len; /* length in bytes of this structure */
uint16_t cap; /* sta's advertised capabilities */
uint32_t flags; /* flags defined below */
uint32_t idle; /* time since data pkt rx'd from sta */
unsigned char ea[6]; /* Station address */
wl_rateset_t rateset; /* rateset in use */
uint32_t in; /* seconds elapsed since associated */
uint32_t listen_interval_inms; /* Min Listen interval in ms for this STA */
uint32_t tx_pkts; /* # of packets transmitted */
uint32_t tx_failures; /* # of packets failed */
uint32_t rx_ucast_pkts; /* # of unicast packets received */
uint32_t rx_mcast_pkts; /* # of multicast packets received */
uint32_t tx_rate; /* Rate of last successful tx frame */
uint32_t rx_rate; /* Rate of last successful rx frame */
} wl_sta_info_t;

typedef struct wlc_ssid {
uint32_t ssid_len;
unsigned char ssid[32];
} wlc_ssid_t;

/* Linux network driver ioctl encoding */
typedef struct wl_ioctl {
uint32_t cmd; /* common ioctl definition */
void *buf; /* pointer to user buffer */
uint32_t len; /* length of user buffer */
uint8_t set; /* get or set request (optional) */
uint32_t used; /* bytes read or written (optional) */
uint32_t needed; /* bytes needed (optional) */
} wl_ioctl_t;

/* Revision info */
typedef struct wlc_rev_info {
uint vendorid; /* PCI vendor id */
uint deviceid; /* device id of chip */
uint radiorev; /* radio revision */
uint chiprev; /* chip revision */
uint corerev; /* core revision */
uint boardid; /* board identifier (usu. PCI sub-device id) */
uint boardvendor; /* board vendor (usu. PCI sub-vendor id) */
uint boardrev; /* board revision */
uint driverrev; /* driver version */
uint ucoderev; /* microcode version */
uint bus; /* bus type */
uint chipnum; /* chip number */
uint phytype; /* phy type */
uint phyrev; /* phy revision */
uint anarev; /* anacore rev */
} wlc_rev_info_t;

typedef struct wl_country_list {
uint32_t buflen;
uint32_t band_set;
uint32_t band;
uint32_t count;
char country_abbrev[1];
} wl_country_list_t;


#endif

+ 160
- 0
api/madwifi.h View File

@@ -0,0 +1,160 @@
/*
* Header bits derived from MadWifi source:
* Copyright (c) 2001 Atsushi Onoe
* Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
* All rights reserved.
*
* Distributed under the terms of the GPLv2 license.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef _MADWIFI_H
#define _MADWIFI_H

/* ieee80211.h */
#define IEEE80211_ADDR_LEN 6
#define IEEE80211_RATE_VAL 0x7f
#define IEEE80211_SEQ_SEQ_MASK 0xfff0
#define IEEE80211_SEQ_SEQ_SHIFT 4


/* ieee80211_crypto.h */
#define IEEE80211_KEYBUF_SIZE 16
#define IEEE80211_MICBUF_SIZE 16
#define IEEE80211_TID_SIZE 17

#define IEEE80211_CIPHER_WEP 0
#define IEEE80211_CIPHER_TKIP 1
#define IEEE80211_CIPHER_AES_OCB 2
#define IEEE80211_CIPHER_AES_CCM 3
#define IEEE80211_CIPHER_CKIP 5
#define IEEE80211_CIPHER_NONE 6
#define IEEE80211_CIPHER_MAX (IEEE80211_CIPHER_NONE + 1)


/* ieee80211_ioctl.h */
#define IEEE80211_KEY_DEFAULT 0x80
#define IEEE80211_CHAN_MAX 255
#define IEEE80211_CHAN_BYTES 32
#define IEEE80211_RATE_MAXSIZE 15

#define IEEE80211_IOCTL_GETKEY (SIOCDEVPRIVATE+3)
#define IEEE80211_IOCTL_STA_STATS (SIOCDEVPRIVATE+5)
#define IEEE80211_IOCTL_STA_INFO (SIOCDEVPRIVATE+6)

#define IEEE80211_IOCTL_GETPARAM (SIOCIWFIRSTPRIV+1)
#define IEEE80211_IOCTL_GETMODE (SIOCIWFIRSTPRIV+3)
#define IEEE80211_IOCTL_GETCHANLIST (SIOCIWFIRSTPRIV+7)
#define IEEE80211_IOCTL_GETCHANINFO (SIOCIWFIRSTPRIV+13)

#define SIOC80211IFCREATE (SIOCDEVPRIVATE+7)
#define SIOC80211IFDESTROY (SIOCDEVPRIVATE+8)

#define IEEE80211_CLONE_BSSID 0x0001 /* allocate unique mac/bssid */
#define IEEE80211_NO_STABEACONS 0x0002 /* Do not setup the station beacon timers */

struct ieee80211_clone_params {
char icp_name[IFNAMSIZ]; /* device name */
u_int16_t icp_opmode; /* operating mode */
u_int16_t icp_flags; /* see below */
};

enum ieee80211_opmode {
IEEE80211_M_STA = 1, /* infrastructure station */
IEEE80211_M_IBSS = 0, /* IBSS (adhoc) station */
IEEE80211_M_AHDEMO = 3, /* Old lucent compatible adhoc demo */
IEEE80211_M_HOSTAP = 6, /* Software Access Point */
IEEE80211_M_MONITOR = 8, /* Monitor mode */
IEEE80211_M_WDS = 2, /* WDS link */
};

enum {
IEEE80211_PARAM_AUTHMODE = 3, /* authentication mode */
IEEE80211_PARAM_MCASTCIPHER = 5, /* multicast/default cipher */
IEEE80211_PARAM_MCASTKEYLEN = 6, /* multicast key length */
IEEE80211_PARAM_UCASTCIPHERS = 7, /* unicast cipher suites */
IEEE80211_PARAM_WPA = 10, /* WPA mode (0,1,2) */
};

/*
* Authentication mode.
*/
enum ieee80211_authmode {
IEEE80211_AUTH_NONE = 0,
IEEE80211_AUTH_OPEN = 1, /* open */
IEEE80211_AUTH_SHARED = 2, /* shared-key */
IEEE80211_AUTH_8021X = 3, /* 802.1x */
IEEE80211_AUTH_AUTO = 4, /* auto-select/accept */
/* NB: these are used only for ioctls */
IEEE80211_AUTH_WPA = 5, /* WPA/RSN w/ 802.1x/PSK */
};

struct ieee80211_channel {
u_int16_t ic_freq; /* setting in MHz */
u_int16_t ic_flags; /* see below */
u_int8_t ic_ieee; /* IEEE channel number */
int8_t ic_maxregpower; /* maximum regulatory tx power in dBm */
int8_t ic_maxpower; /* maximum tx power in dBm */
int8_t ic_minpower; /* minimum tx power in dBm */
u_int8_t ic_scanflags;
u_int8_t ic_idletime; /* phy idle time in % */
};

struct ieee80211req_key {
u_int8_t ik_type; /* key/cipher type */
u_int8_t ik_pad;
u_int16_t ik_keyix; /* key index */
u_int8_t ik_keylen; /* key length in bytes */
u_int8_t ik_flags;
u_int8_t ik_macaddr[IEEE80211_ADDR_LEN];
u_int64_t ik_keyrsc; /* key receive sequence counter */
u_int64_t ik_keytsc; /* key transmit sequence counter */
u_int8_t ik_keydata[IEEE80211_KEYBUF_SIZE+IEEE80211_MICBUF_SIZE];
};

struct ieee80211req_chanlist {
u_int8_t ic_channels[IEEE80211_CHAN_BYTES];
};

struct ieee80211req_chaninfo {
u_int ic_nchans;
struct ieee80211_channel ic_chans[IEEE80211_CHAN_MAX];
};

struct ieee80211req_sta_info {
u_int16_t isi_len; /* length (mult of 4) */
u_int16_t isi_freq; /* MHz */
u_int16_t isi_flags; /* channel flags */
u_int16_t isi_state; /* state flags */
u_int8_t isi_authmode; /* authentication algorithm */
u_int8_t isi_rssi;
int8_t isi_noise;
u_int16_t isi_capinfo; /* capabilities */
u_int8_t isi_athflags; /* Atheros capabilities */
u_int8_t isi_erp; /* ERP element */
u_int8_t isi_macaddr[IEEE80211_ADDR_LEN];
u_int8_t isi_nrates; /* negotiated rates */
u_int8_t isi_rates[IEEE80211_RATE_MAXSIZE];
u_int8_t isi_txrate; /* index to isi_rates[] */
u_int16_t isi_ie_len; /* IE length */
u_int16_t isi_associd; /* assoc response */
u_int16_t isi_txpower; /* current tx power */
u_int16_t isi_vlan; /* vlan tag */
u_int16_t isi_txseqs[17]; /* seq to be transmitted */
u_int16_t isi_rxseqs[17]; /* seq previous for qos frames*/
u_int16_t isi_inact; /* inactivity timer */
u_int8_t isi_uapsd; /* UAPSD queues */
u_int8_t isi_opmode; /* sta operating mode */
};

#endif

+ 4172
- 0
api/nl80211.h
File diff suppressed because it is too large
View File


+ 1139
- 0
api/wext.h
File diff suppressed because it is too large
View File


+ 57
- 0
hardware.txt View File

@@ -0,0 +1,57 @@
# libiwinfo hardware database
# vendor id | device id | subsystem vendor id | subsystem device id |
# txpower offset | frequency offset | "vendor name" | "device name"
0xffff 0xffff 0xffff 0xb102 0 0 "Ubiquiti" "PowerStation2 (18V)"
0xffff 0xffff 0xffff 0xb202 0 0 "Ubiquiti" "PowerStation2 (16D)"
0xffff 0xffff 0xffff 0xb302 0 0 "Ubiquiti" "PowerStation2 (EXT)"
0xffff 0xffff 0xffff 0xb105 0 0 "Ubiquiti" "PowerStation5 (22V)"
0xffff 0xffff 0xffff 0xb305 0 0 "Ubiquiti" "PowerStation5 (EXT)"
0xffff 0xffff 0xffff 0xc302 0 0 "Ubiquiti" "PicoStation2"
0xffff 0xffff 0xffff 0xc3a2 10 0 "Ubiquiti" "PicoStation2 HP"
0xffff 0xffff 0xffff 0xa105 0 0 "Ubiquiti" "WispStation5"
0xffff 0xffff 0xffff 0xa002 10 0 "Ubiquiti" "LiteStation2"
0xffff 0xffff 0xffff 0xa005 5 0 "Ubiquiti" "LiteStation5"
0xffff 0xffff 0xffff 0xc002 10 0 "Ubiquiti" "NanoStation2"
0xffff 0xffff 0xffff 0xc005 5 0 "Ubiquiti" "NanoStation5"
0xffff 0xffff 0xffff 0xc102 10 0 "Ubiquiti" "NanoStation Loco2"
0xffff 0xffff 0xffff 0xc105 5 0 "Ubiquiti" "NanoStation Loco5"
0xffff 0xffff 0xffff 0xc202 10 0 "Ubiquiti" "Bullet2"
0xffff 0xffff 0xffff 0xc205 5 0 "Ubiquiti" "Bullet5"
0x168c 0x001b 0x0777 0x3002 10 0 "Ubiquiti" "XR2"
0x168c 0x001b 0x7777 0x3002 10 0 "Ubiquiti" "XR2"
0x168c 0x001b 0x0777 0x3b02 10 0 "Ubiquiti" "XR2.3"
0x168c 0x001b 0x0777 0x3c02 10 0 "Ubiquiti" "XR2.6"
0x168c 0x001b 0x0777 0x3b03 10 0 "Ubiquiti" "XR3-2.8"
0x168c 0x001b 0x0777 0x3c03 10 0 "Ubiquiti" "XR3-3.6"
0x168c 0x001b 0x0777 0x3003 10 0 "Ubiquiti" "XR3"
0x168c 0x001b 0x0777 0x3004 10 0 "Ubiquiti" "XR4"
0x168c 0x001b 0x0777 0x3005 10 0 "Ubiquiti" "XR5"
0x168c 0x001b 0x7777 0x3005 10 0 "Ubiquiti" "XR5"
0x168c 0x001b 0x0777 0x3007 10 0 "Ubiquiti" "XR7"
0x168c 0x001b 0x0777 0x3009 10 -1520 "Ubiquiti" "XR9"
0x168c 0x001b 0x168c 0x2063 0 0 "Atheros" "AR5413"
0x168c 0x0013 0x168c 0x1042 1 0 "Ubiquiti" "SRC"
0x168c 0x0013 0x0777 0x2041 10 0 "Ubiquiti" "SR2"
0x168c 0x0013 0x0777 0x2004 6 0 "Ubiquiti" "SR4"
0x168c 0x0013 0x7777 0x2004 6 0 "Ubiquiti" "SR4"
0x168c 0x0013 0x0777 0x1004 6 0 "Ubiquiti" "SR4C"
0x168c 0x0013 0x7777 0x1004 6 0 "Ubiquiti" "SR4C"
0x168c 0x0013 0x168c 0x2042 7 0 "Ubiquiti" "SR5"
0x168c 0x0013 0x7777 0x2009 12 -1500 "Ubiquiti" "SR9"
0x168c 0x0027 0x168c 0x2082 7 0 "Ubiquiti" "SR71A"
0x168c 0x0027 0x0777 0x4082 7 0 "Ubiquiti" "SR71"
0x168c 0x0029 0x0777 0x4005 7 0 "Ubiquiti" "SR71-15"
0x168c 0x002a 0x0777 0xe302 12 0 "Ubiquiti" "PicoStation M2" /* ToDo: confirm offset */
0x168c 0x002a 0x0777 0xe012 12 0 "Ubiquiti" "NanoStation M2" /* ToDo: confirm offset */
0x168c 0x002a 0x0777 0xe005 5 0 "Ubiquiti" "NanoStation M5" /* ToDo: confirm offset */
0x168c 0x002a 0x0777 0xe202 12 0 "Ubiquiti" "Bullet M2"
0x168c 0x002a 0x0777 0xe805 5 0 "Ubiquiti" "Bullet M5"
0x168c 0x002a 0x0777 0xe345 0 0 "Ubiquiti" "WispStation M5" /* ToDo: confirm offset */
0x168c 0x0029 0x168c 0xa094 0 0 "Atheros" "AR9220"
0x168c 0x0029 0x168c 0xa095 0 0 "Atheros" "AR9223"
0x168c 0x002a 0x168c 0xa093 0 0 "Atheros" "AR9280"
0x168c 0x002b 0x168c 0xa091 0 0 "Atheros" "AR9285"
0x168c 0x0033 0x168c 0xa120 0 0 "Atheros" "AR9580"
0x1814 0x3050 0x1814 0x0005 0 0 "RaLink" "Rt3050"
0x1814 0x3052 0x1814 0x0008 0 0 "RaLink" "Rt3052"
0x1814 0x3352 0x1814 0x000c 0 0 "RaLink" "Rt3352"

+ 194
- 0
include/iwinfo.h View File

@@ -0,0 +1,194 @@
#ifndef __IWINFO_H_
#define __IWINFO_H_

#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <glob.h>
#include <ctype.h>
#include <dirent.h>
#include <stdint.h>

#include <sys/ioctl.h>
#include <sys/mman.h>
#include <net/if.h>
#include <errno.h>


#define IWINFO_BUFSIZE 24 * 1024
#define IWINFO_ESSID_MAX_SIZE 32

#define IWINFO_80211_A (1 << 0)
#define IWINFO_80211_B (1 << 1)
#define IWINFO_80211_G (1 << 2)
#define IWINFO_80211_N (1 << 3)
#define IWINFO_80211_AC (1 << 4)

#define IWINFO_CIPHER_NONE (1 << 0)
#define IWINFO_CIPHER_WEP40 (1 << 1)
#define IWINFO_CIPHER_TKIP (1 << 2)
#define IWINFO_CIPHER_WRAP (1 << 3)
#define IWINFO_CIPHER_CCMP (1 << 4)
#define IWINFO_CIPHER_WEP104 (1 << 5)
#define IWINFO_CIPHER_AESOCB (1 << 6)
#define IWINFO_CIPHER_CKIP (1 << 7)

#define IWINFO_KMGMT_NONE (1 << 0)
#define IWINFO_KMGMT_8021x (1 << 1)
#define IWINFO_KMGMT_PSK (1 << 2)

#define IWINFO_AUTH_OPEN (1 << 0)
#define IWINFO_AUTH_SHARED (1 << 1)

extern const char *IWINFO_CIPHER_NAMES[];
extern const char *IWINFO_KMGMT_NAMES[];
extern const char *IWINFO_AUTH_NAMES[];


enum iwinfo_opmode {
IWINFO_OPMODE_UNKNOWN = 0,
IWINFO_OPMODE_MASTER = 1,
IWINFO_OPMODE_ADHOC = 2,
IWINFO_OPMODE_CLIENT = 3,
IWINFO_OPMODE_MONITOR = 4,
IWINFO_OPMODE_AP_VLAN = 5,
IWINFO_OPMODE_WDS = 6,
IWINFO_OPMODE_MESHPOINT = 7,
IWINFO_OPMODE_P2P_CLIENT = 8,
IWINFO_OPMODE_P2P_GO = 9,
};

extern const char *IWINFO_OPMODE_NAMES[];


struct iwinfo_rate_entry {
uint32_t rate;
int8_t mcs;
uint8_t is_40mhz:1;
uint8_t is_short_gi:1;
};

struct iwinfo_assoclist_entry {
uint8_t mac[6];
int8_t signal;
int8_t noise;
uint32_t inactive;
uint32_t rx_packets;
uint32_t tx_packets;
struct iwinfo_rate_entry rx_rate;
struct iwinfo_rate_entry tx_rate;
};

struct iwinfo_txpwrlist_entry {
uint8_t dbm;
uint16_t mw;
};

struct iwinfo_freqlist_entry {
uint8_t channel;
uint32_t mhz;
uint8_t restricted;
};

struct iwinfo_crypto_entry {
uint8_t enabled;
uint8_t wpa_version;
uint8_t group_ciphers;
uint8_t pair_ciphers;
uint8_t auth_suites;
uint8_t auth_algs;
};

struct iwinfo_scanlist_entry {
uint8_t mac[6];
uint8_t ssid[IWINFO_ESSID_MAX_SIZE+1];
enum iwinfo_opmode mode;
uint8_t channel;
uint8_t signal;
uint8_t quality;
uint8_t quality_max;
struct iwinfo_crypto_entry crypto;
};

struct iwinfo_country_entry {
uint16_t iso3166;
uint8_t ccode[4];
};

struct iwinfo_iso3166_label {
uint16_t iso3166;
uint8_t name[28];
};

struct iwinfo_hardware_id {
uint16_t vendor_id;
uint16_t device_id;
uint16_t subsystem_vendor_id;
uint16_t subsystem_device_id;
};

struct iwinfo_hardware_entry {
char vendor_name[64];
char device_name[64];
uint16_t vendor_id;
uint16_t device_id;
uint16_t subsystem_vendor_id;
uint16_t subsystem_device_id;
int16_t txpower_offset;
int16_t frequency_offset;
};

extern const struct iwinfo_iso3166_label IWINFO_ISO3166_NAMES[];

#define IWINFO_HARDWARE_FILE "/usr/share/libiwinfo/hardware.txt"


struct iwinfo_ops {
const char *name;

int (*probe)(const char *ifname);
int (*mode)(const char *, int *);
int (*channel)(const char *, int *);
int (*frequency)(const char *, int *);
int (*frequency_offset)(const char *, int *);
int (*txpower)(const char *, int *);
int (*txpower_offset)(const char *, int *);
int (*bitrate)(const char *, int *);
int (*signal)(const char *, int *);
int (*noise)(const char *, int *);
int (*quality)(const char *, int *);
int (*quality_max)(const char *, int *);
int (*mbssid_support)(const char *, int *);
int (*hwmodelist)(const char *, int *);
int (*ssid)(const char *, char *);
int (*bssid)(const char *, char *);
int (*country)(const char *, char *);
int (*hardware_id)(const char *, char *);
int (*hardware_name)(const char *, char *);
int (*encryption)(const char *, char *);
int (*phyname)(const char *, char *);
int (*assoclist)(const char *, char *, int *);
int (*txpwrlist)(const char *, char *, int *);
int (*scanlist)(const char *, char *, int *);
int (*freqlist)(const char *, char *, int *);
int (*countrylist)(const char *, char *, int *);
void (*close)(void);
};

const char * iwinfo_type(const char *ifname);
const struct iwinfo_ops * iwinfo_backend(const char *ifname);
void iwinfo_finish(void);

extern const struct iwinfo_ops wext_ops;
extern const struct iwinfo_ops madwifi_ops;
extern const struct iwinfo_ops nl80211_ops;
extern const struct iwinfo_ops wl_ops;

#include "iwinfo/utils.h"

#endif

+ 79
- 0
include/iwinfo/lua.h View File

@@ -0,0 +1,79 @@
/*
* iwinfo - Wireless Information Library - Lua Headers
*
* Copyright (C) 2009 Jo-Philipp Wich <xm@subsignal.org>
*
* The iwinfo library is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* The iwinfo library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with the iwinfo library. If not, see http://www.gnu.org/licenses/.
*/

#ifndef __IWINFO_LUALUB_H_
#define __IWINFO_LUALIB_H_

#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>

#include "iwinfo.h"


#define IWINFO_META "iwinfo"
#define IWINFO_WEXT_META "iwinfo.wext"

#ifdef USE_WL
#define IWINFO_WL_META "iwinfo.wl"
#endif

#ifdef USE_MADWIFI
#define IWINFO_MADWIFI_META "iwinfo.madwifi"
#endif

#ifdef USE_NL80211
#define IWINFO_NL80211_META "iwinfo.nl80211"
#endif


#define LUA_REG(type,op) \
{ #op, iwinfo_L_##type##_##op }

#define LUA_WRAP_INT_OP(type,op) \
static int iwinfo_L_##type##_##op(lua_State *L) \
{ \
const char *ifname = luaL_checkstring(L, 1); \
int rv; \
if( !type##_ops.op(ifname, &rv) ) \
lua_pushnumber(L, rv); \
else \
lua_pushnil(L); \
return 1; \
}

#define LUA_WRAP_STRING_OP(type,op) \
static int iwinfo_L_##type##_##op(lua_State *L) \
{ \
const char *ifname = luaL_checkstring(L, 1); \
char rv[IWINFO_BUFSIZE]; \
memset(rv, 0, IWINFO_BUFSIZE); \
if( !type##_ops.op(ifname, rv) ) \
lua_pushstring(L, rv); \
else \
lua_pushnil(L); \
return 1; \
}

#define LUA_WRAP_STRUCT_OP(type,op) \
static int iwinfo_L_##type##_##op(lua_State *L) \
{ \
return iwinfo_L_##op(L, type##_ops.op); \
}

#endif

+ 47
- 0
include/iwinfo/utils.h View File

@@ -0,0 +1,47 @@
/*
* iwinfo - Wireless Information Library - Utility Headers
*
* Copyright (C) 2010 Jo-Philipp Wich <xm@subsignal.org>
*
* The iwinfo library is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* The iwinfo library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with the iwinfo library. If not, see http://www.gnu.org/licenses/.
*/

#ifndef __IWINFO_UTILS_H_
#define __IWINFO_UTILS_H_

#include <sys/socket.h>
#include <net/if.h>

#include "iwinfo.h"

#define LOG10_MAGIC 1.25892541179

int iwinfo_ioctl(int cmd, void *ifr);

int iwinfo_dbm2mw(int in);
int iwinfo_mw2dbm(int in);

int iwinfo_ifup(const char *ifname);
int iwinfo_ifdown(const char *ifname);
int iwinfo_ifmac(const char *ifname);

void iwinfo_close(void);

struct iwinfo_hardware_entry * iwinfo_hardware(struct iwinfo_hardware_id *id);

int iwinfo_hardware_id_from_mtd(struct iwinfo_hardware_id *id);

void iwinfo_parse_rsn(struct iwinfo_crypto_entry *c, uint8_t *data, uint8_t len,
uint8_t defcipher, uint8_t defauth);

#endif

+ 839
- 0
iwinfo_cli.c View File

@@ -0,0 +1,839 @@
/*
* iwinfo - Wireless Information Library - Command line frontend
*
* Copyright (C) 2011 Jo-Philipp Wich <xm@subsignal.org>
*
* The iwinfo library is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* The iwinfo library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with the iwinfo library. If not, see http://www.gnu.org/licenses/.
*/

#include <stdio.h>
#include <glob.h>

#include "iwinfo.h"


static char * format_bssid(unsigned char *mac)
{
static char buf[18];

snprintf(buf, sizeof(buf), "%02X:%02X:%02X:%02X:%02X:%02X",
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);

return buf;
}

static char * format_ssid(char *ssid)
{
static char buf[IWINFO_ESSID_MAX_SIZE+3];

if (ssid && ssid[0])
snprintf(buf, sizeof(buf), "\"%s\"", ssid);
else
snprintf(buf, sizeof(buf), "unknown");

return buf;
}

static char * format_channel(int ch)
{
static char buf[8];

if (ch <= 0)
snprintf(buf, sizeof(buf), "unknown");
else
snprintf(buf, sizeof(buf), "%d", ch);

return buf;
}

static char * format_frequency(int freq)
{
static char buf[10];

if (freq <= 0)
snprintf(buf, sizeof(buf), "unknown");
else
snprintf(buf, sizeof(buf), "%.3f GHz", ((float)freq / 1000.0));

return buf;
}

static char * format_txpower(int pwr)
{
static char buf[10];

if (pwr < 0)
snprintf(buf, sizeof(buf), "unknown");
else
snprintf(buf, sizeof(buf), "%d dBm", pwr);

return buf;
}

static char * format_quality(int qual)
{
static char buf[8];

if (qual < 0)
snprintf(buf, sizeof(buf), "unknown");
else
snprintf(buf, sizeof(buf), "%d", qual);

return buf;
}

static char * format_quality_max(int qmax)
{
static char buf[8];

if (qmax < 0)
snprintf(buf, sizeof(buf), "unknown");
else
snprintf(buf, sizeof(buf), "%d", qmax);

return buf;
}

static char * format_signal(int sig)
{
static char buf[10];

if (!sig)
snprintf(buf, sizeof(buf), "unknown");
else
snprintf(buf, sizeof(buf), "%d dBm", sig);

return buf;
}

static char * format_noise(int noise)
{
static char buf[10];

if (!noise)
snprintf(buf, sizeof(buf), "unknown");
else
snprintf(buf, sizeof(buf), "%d dBm", noise);

return buf;
}

static char * format_rate(int rate)
{
static char buf[14];

if (rate <= 0)
snprintf(buf, sizeof(buf), "unknown");
else
snprintf(buf, sizeof(buf), "%d.%d MBit/s",
rate / 1000, (rate % 1000) / 100);

return buf;
}

static char * format_enc_ciphers(int ciphers)
{
static char str[128] = { 0 };
char *pos = str;

if (ciphers & IWINFO_CIPHER_WEP40)
pos += sprintf(pos, "WEP-40, ");

if (ciphers & IWINFO_CIPHER_WEP104)
pos += sprintf(pos, "WEP-104, ");

if (ciphers & IWINFO_CIPHER_TKIP)
pos += sprintf(pos, "TKIP, ");

if (ciphers & IWINFO_CIPHER_CCMP)
pos += sprintf(pos, "CCMP, ");

if (ciphers & IWINFO_CIPHER_WRAP)
pos += sprintf(pos, "WRAP, ");

if (ciphers & IWINFO_CIPHER_AESOCB)
pos += sprintf(pos, "AES-OCB, ");

if (ciphers & IWINFO_CIPHER_CKIP)
pos += sprintf(pos, "CKIP, ");

if (!ciphers || (ciphers & IWINFO_CIPHER_NONE))
pos += sprintf(pos, "NONE, ");

*(pos - 2) = 0;

return str;
}

static char * format_enc_suites(int suites)
{
static char str[64] = { 0 };
char *pos = str;

if (suites & IWINFO_KMGMT_PSK)
pos += sprintf(pos, "PSK/");

if (suites & IWINFO_KMGMT_8021x)
pos += sprintf(pos, "802.1X/");

if (!suites || (suites & IWINFO_KMGMT_NONE))
pos += sprintf(pos, "NONE/");

*(pos - 1) = 0;

return str;
}

static char * format_encryption(struct iwinfo_crypto_entry *c)
{
static char buf[512];

if (!c)
{
snprintf(buf, sizeof(buf), "unknown");
}
else if (c->enabled)
{
/* WEP */
if (c->auth_algs && !c->wpa_version)
{
if ((c->auth_algs & IWINFO_AUTH_OPEN) &&
(c->auth_algs & IWINFO_AUTH_SHARED))
{
snprintf(buf, sizeof(buf), "WEP Open/Shared (%s)",
format_enc_ciphers(c->pair_ciphers));
}
else if (c->auth_algs & IWINFO_AUTH_OPEN)
{
snprintf(buf, sizeof(buf), "WEP Open System (%s)",
format_enc_ciphers(c->pair_ciphers));
}
else if (c->auth_algs & IWINFO_AUTH_SHARED)
{
snprintf(buf, sizeof(buf), "WEP Shared Auth (%s)",
format_enc_ciphers(c->pair_ciphers));
}
}

/* WPA */
else if (c->wpa_version)
{
switch (c->wpa_version) {
case 3:
snprintf(buf, sizeof(buf), "mixed WPA/WPA2 %s (%s)",
format_enc_suites(c->auth_suites),
format_enc_ciphers(c->pair_ciphers | c->group_ciphers));
break;

case 2:
snprintf(buf, sizeof(buf), "WPA2 %s (%s)",
format_enc_suites(c->auth_suites),
format_enc_ciphers(c->pair_ciphers | c->group_ciphers));
break;

case 1:
snprintf(buf, sizeof(buf), "WPA %s (%s)",
format_enc_suites(c->auth_suites),
format_enc_ciphers(c->pair_ciphers | c->group_ciphers));
break;
}
}
else
{
snprintf(buf, sizeof(buf), "none");
}
}
else
{
snprintf(buf, sizeof(buf), "none");
}

return buf;
}

static char * format_hwmodes(int modes)
{
static char buf[12];

if (modes <= 0)
snprintf(buf, sizeof(buf), "unknown");
else
snprintf(buf, sizeof(buf), "802.11%s%s%s%s%s",
(modes & IWINFO_80211_A) ? "a" : "",
(modes & IWINFO_80211_B) ? "b" : "",
(modes & IWINFO_80211_G) ? "g" : "",
(modes & IWINFO_80211_N) ? "n" : "",
(modes & IWINFO_80211_AC) ? "ac" : "");

return buf;
}

static char * format_assocrate(struct iwinfo_rate_entry *r)
{
static char buf[40];
char *p = buf;
int l = sizeof(buf);

if (r->rate <= 0)
{
snprintf(buf, sizeof(buf), "unknown");
}
else
{
p += snprintf(p, l, "%s", format_rate(r->rate));
l = sizeof(buf) - (p - buf);

if (r->mcs >= 0)
{
p += snprintf(p, l, ", MCS %d, %dMHz", r->mcs, 20 + r->is_40mhz*20);
l = sizeof(buf) - (p - buf);

if (r->is_short_gi)
p += snprintf(p, l, ", short GI");
}
}

return buf;
}


static const char * print_type(const struct iwinfo_ops *iw, const char *ifname)
{
const char *type = iwinfo_type(ifname);
return type ? type : "unknown";
}

static char * print_hardware_id(const struct iwinfo_ops *iw, const char *ifname)
{
static char buf[20];
struct iwinfo_hardware_id ids;

if (!iw->hardware_id(ifname, (char *)&ids))
{
snprintf(buf, sizeof(buf), "%04X:%04X %04X:%04X",
ids.vendor_id, ids.device_id,
ids.subsystem_vendor_id, ids.subsystem_device_id);
}
else
{
snprintf(buf, sizeof(buf), "unknown");
}

return buf;
}

static char * print_hardware_name(const struct iwinfo_ops *iw, const char *ifname)
{
static char buf[128];

if (iw->hardware_name(ifname, buf))
snprintf(buf, sizeof(buf), "unknown");

return buf;
}

static char * print_txpower_offset(const struct iwinfo_ops *iw, const char *ifname)
{
int off;
static char buf[12];

if (iw->txpower_offset(ifname, &off))
snprintf(buf, sizeof(buf), "unknown");
else if (off != 0)
snprintf(buf, sizeof(buf), "%d dB", off);
else
snprintf(buf, sizeof(buf), "none");

return buf;
}

static char * print_frequency_offset(const struct iwinfo_ops *iw, const char *ifname)
{
int off;
static char buf[12];

if (iw->frequency_offset(ifname, &off))
snprintf(buf, sizeof(buf), "unknown");
else if (off != 0)
snprintf(buf, sizeof(buf), "%.3f GHz", ((float)off / 1000.0));
else
snprintf(buf, sizeof(buf), "none");

return buf;
}

static char * print_ssid(const struct iwinfo_ops *iw, const char *ifname)
{
char buf[IWINFO_ESSID_MAX_SIZE+1] = { 0 };

if (iw->ssid(ifname, buf))
memset(buf, 0, sizeof(buf));

return format_ssid(buf);
}

static char * print_bssid(const struct iwinfo_ops *iw, const char *ifname)
{
static char buf[18] = { 0 };

if (iw->bssid(ifname, buf))
snprintf(buf, sizeof(buf), "00:00:00:00:00:00");

return buf;
}

static char * print_mode(const struct iwinfo_ops *iw, const char *ifname)
{
int mode;
static char buf[128];

if (iw->mode(ifname, &mode))
mode = IWINFO_OPMODE_UNKNOWN;

snprintf(buf, sizeof(buf), "%s", IWINFO_OPMODE_NAMES[mode]);

return buf;
}

static char * print_channel(const struct iwinfo_ops *iw, const char *ifname)
{
int ch;
if (iw->channel(ifname, &ch))
ch = -1;

return format_channel(ch);
}

static char * print_frequency(const struct iwinfo_ops *iw, const char *ifname)
{
int freq;
if (iw->frequency(ifname, &freq))
freq = -1;

return format_frequency(freq);
}

static char * print_txpower(const struct iwinfo_ops *iw, const char *ifname)
{
int pwr, off;
if (iw->txpower_offset(ifname, &off))
off = 0;

if (iw->txpower(ifname, &pwr))
pwr = -1;
else
pwr += off;

return format_txpower(pwr);
}

static char * print_quality(const struct iwinfo_ops *iw, const char *ifname)
{
int qual;
if (iw->quality(ifname, &qual))
qual = -1;

return format_quality(qual);
}

static char * print_quality_max(const struct iwinfo_ops *iw, const char *ifname)
{
int qmax;
if (iw->quality_max(ifname, &qmax))
qmax = -1;

return format_quality_max(qmax);
}

static char * print_signal(const struct iwinfo_ops *iw, const char *ifname)
{
int sig;
if (iw->signal(ifname, &sig))
sig = 0;

return format_signal(sig);
}

static char * print_noise(const struct iwinfo_ops *iw, const char *ifname)
{
int noise;
if (iw->noise(ifname, &noise))
noise = 0;

return format_noise(noise);
}

static char * print_rate(const struct iwinfo_ops *iw, const char *ifname)
{
int rate;
if (iw->bitrate(ifname, &rate))
rate = -1;

return format_rate(rate);
}

static char * print_encryption(const struct iwinfo_ops *iw, const char *ifname)
{
struct iwinfo_crypto_entry c = { 0 };
if (iw->encryption(ifname, (char *)&c))
return format_encryption(NULL);

return format_encryption(&c);
}

static char * print_hwmodes(const struct iwinfo_ops *iw, const char *ifname)
{
int modes;
if (iw->hwmodelist(ifname, &modes))
modes = -1;

return format_hwmodes(modes);
}

static char * print_mbssid_supp(const struct iwinfo_ops *iw, const char *ifname)
{
int supp;
static char buf[4];

if (iw->mbssid_support(ifname, &supp))
snprintf(buf, sizeof(buf), "no");
else
snprintf(buf, sizeof(buf), "%s", supp ? "yes" : "no");

return buf;
}

static char * print_phyname(const struct iwinfo_ops *iw, const char *ifname)
{
static char buf[32];

if (!iw->phyname(ifname, buf))
return buf;

return "?";
}


static void print_info(const struct iwinfo_ops *iw, const char *ifname)
{
printf("%-9s ESSID: %s\n",
ifname,
print_ssid(iw, ifname));
printf(" Access Point: %s\n",
print_bssid(iw, ifname));
printf(" Mode: %s Channel: %s (%s)\n",
print_mode(iw, ifname),
print_channel(iw, ifname),
print_frequency(iw, ifname));
printf(" Tx-Power: %s Link Quality: %s/%s\n",
print_txpower(iw, ifname),
print_quality(iw, ifname),
print_quality_max(iw, ifname));
printf(" Signal: %s Noise: %s\n",
print_signal(iw, ifname),
print_noise(iw, ifname));
printf(" Bit Rate: %s\n",
print_rate(iw, ifname));
printf(" Encryption: %s\n",
print_encryption(iw, ifname));
printf(" Type: %s HW Mode(s): %s\n",
print_type(iw, ifname),
print_hwmodes(iw, ifname));
printf(" Hardware: %s [%s]\n",
print_hardware_id(iw, ifname),
print_hardware_name(iw, ifname));
printf(" TX power offset: %s\n",
print_txpower_offset(iw, ifname));
printf(" Frequency offset: %s\n",
print_frequency_offset(iw, ifname));
printf(" Supports VAPs: %s PHY name: %s\n",
print_mbssid_supp(iw, ifname),
print_phyname(iw, ifname));
}


static void print_scanlist(const struct iwinfo_ops *iw, const char *ifname)
{
int i, x, len;
char buf[IWINFO_BUFSIZE];
struct iwinfo_scanlist_entry *e;

if (iw->scanlist(ifname, buf, &len))
{
printf("Scanning not possible\n\n");
return;
}
else if (len <= 0)
{
printf("No scan results\n\n");
return;
}

for (i = 0, x = 1; i < len; i += sizeof(struct iwinfo_scanlist_entry), x++)
{
e = (struct iwinfo_scanlist_entry *) &buf[i];

printf("Cell %02d - Address: %s\n",
x,
format_bssid(e->mac));
printf(" ESSID: %s\n",
format_ssid(e->ssid));
printf(" Mode: %s Channel: %s\n",
IWINFO_OPMODE_NAMES[e->mode],
format_channel(e->channel));
printf(" Signal: %s Quality: %s/%s\n",
format_signal(e->signal - 0x100),
format_quality(e->quality),
format_quality_max(e->quality_max));
printf(" Encryption: %s\n\n",
format_encryption(&e->crypto));
}
}


static void print_txpwrlist(const struct iwinfo_ops *iw, const char *ifname)
{
int len, pwr, off, i;
char buf[IWINFO_BUFSIZE];
struct iwinfo_txpwrlist_entry *e;

if (iw->txpwrlist(ifname, buf, &len) || len <= 0)
{
printf("No TX power information available\n");
return;
}

if (iw->txpower(ifname, &pwr))
pwr = -1;

if (iw->txpower_offset(ifname, &off))
off = 0;

for (i = 0; i < len; i += sizeof(struct iwinfo_txpwrlist_entry))
{
e = (struct iwinfo_txpwrlist_entry *) &buf[i];

printf("%s%3d dBm (%4d mW)\n",
(pwr == e->dbm) ? "*" : " ",
e->dbm + off,
iwinfo_dbm2mw(e->dbm + off));
}
}


static void print_freqlist(const struct iwinfo_ops *iw, const char *ifname)
{
int i, len, ch;
char buf[IWINFO_BUFSIZE];
struct iwinfo_freqlist_entry *e;

if (iw->freqlist(ifname, buf, &len) || len <= 0)
{
printf("No frequency information available\n");
return;
}

if (iw->channel(ifname, &ch))
ch = -1;

for (i = 0; i < len; i += sizeof(struct iwinfo_freqlist_entry))
{
e = (struct iwinfo_freqlist_entry *) &buf[i];

printf("%s %s (Channel %s)%s\n",
(ch == e->channel) ? "*" : " ",
format_frequency(e->mhz),
format_channel(e->channel),
e->restricted ? " [restricted]" : "");
}
}


static void print_assoclist(const struct iwinfo_ops *iw, const char *ifname)
{
int i, len;
char buf[IWINFO_BUFSIZE];
struct iwinfo_assoclist_entry *e;

if (iw->assoclist(ifname, buf, &len))
{
printf("No information available\n");
return;
}
else if (len <= 0)
{
printf("No station connected\n");
return;
}

for (i = 0; i < len; i += sizeof(struct iwinfo_assoclist_entry))
{
e = (struct iwinfo_assoclist_entry *) &buf[i];

printf("%s %s / %s (SNR %d) %d ms ago\n",
format_bssid(e->mac),
format_signal(e->signal),
format_noise(e->noise),
(e->signal - e->noise),
e->inactive);

printf(" RX: %-38s %8d Pkts.\n",
format_assocrate(&e->rx_rate),
e->rx_packets
);

printf(" TX: %-38s %8d Pkts.\n\n",
format_assocrate(&e->tx_rate),
e->tx_packets
);
}
}


static char * lookup_country(char *buf, int len, int iso3166)
{
int i;
struct iwinfo_country_entry *c;

for (i = 0; i < len; i += sizeof(struct iwinfo_country_entry))
{
c = (struct iwinfo_country_entry *) &buf[i];

if (c->iso3166 == iso3166)
return c->ccode;
}

return NULL;
}

static void print_countrylist(const struct iwinfo_ops *iw, const char *ifname)
{
int len;
char buf[IWINFO_BUFSIZE];
char *ccode;
char curcode[3];
const struct iwinfo_iso3166_label *l;

if (iw->countrylist(ifname, buf, &len))
{
printf("No country code information available\n");
return;
}

if (iw->country(ifname, curcode))
memset(curcode, 0, sizeof(curcode));

for (l = IWINFO_ISO3166_NAMES; l->iso3166; l++)
{
if ((ccode = lookup_country(buf, len, l->iso3166)) != NULL)
{
printf("%s %4s %c%c\n",
strncmp(ccode, curcode, 2) ? " " : "*",
ccode, (l->iso3166 / 256), (l->iso3166 % 256));
}
}
}


int main(int argc, char **argv)
{
int i;
char *p;
const struct iwinfo_ops *iw;
glob_t globbuf;

if (argc > 1 && argc < 3)
{
fprintf(stderr,
"Usage:\n"
" iwinfo <device> info\n"
" iwinfo <device> scan\n"
" iwinfo <device> txpowerlist\n"
" iwinfo <device> freqlist\n"
" iwinfo <device> assoclist\n"
" iwinfo <device> countrylist\n"
);

return 1;
}

if (argc == 1)
{
glob("/sys/class/net/*", 0, NULL, &globbuf);

for (i = 0; i < globbuf.gl_pathc; i++)
{
p = strrchr(globbuf.gl_pathv[i], '/');

if (!p)
continue;

iw = iwinfo_backend(++p);

if (!iw)
continue;

print_info(iw, p);
printf("\n");
}

globfree(&globbuf);
return 0;
}

iw = iwinfo_backend(argv[1]);

if (!iw)
{
fprintf(stderr, "No such wireless device: %s\n", argv[1]);
return 1;
}

for (i = 2; i < argc; i++)
{
switch(argv[i][0])
{
case 'i':
print_info(iw, argv[1]);
break;

case 's':
print_scanlist(iw, argv[1]);
break;

case 't':
print_txpwrlist(iw, argv[1]);
break;

case 'f':
print_freqlist(iw, argv[1]);
break;

case 'a':
print_assoclist(iw, argv[1]);
break;

case 'c':
print_countrylist(iw, argv[1]);
break;

default:
fprintf(stderr, "Unknown command: %s\n", argv[i]);
return 1;
}
}

iwinfo_finish();

return 0;
}

+ 361
- 0
iwinfo_lib.c View File

@@ -0,0 +1,361 @@
/*
* iwinfo - Wireless Information Library - Lua Bindings
*
* Copyright (C) 2009-2013 Jo-Philipp Wich <xm@subsignal.org>
*
* The iwinfo library is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* The iwinfo library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with the iwinfo library. If not, see http://www.gnu.org/licenses/.
*/

#include "iwinfo.h"


/*
* name constants
*/
const char *IWINFO_CIPHER_NAMES[] = {
"NONE",
"WEP40",
"TKIP",
"WRAP",
"CCMP",
"WEP104",
"AES-OCB",
"CKIP",
};

const char *IWINFO_KMGMT_NAMES[] = {
"NONE",
"802.1X",
"PSK",
};

const char *IWINFO_AUTH_NAMES[] = {
"OPEN",
"SHARED",
};

const char *IWINFO_OPMODE_NAMES[] = {
"Unknown",
"Master",
"Ad-Hoc",
"Client",
"Monitor",
"Master (VLAN)",
"WDS",
"Mesh Point",
"P2P Client",
"P2P Go",
};


/*
* ISO3166 country labels
*/

const struct iwinfo_iso3166_label IWINFO_ISO3166_NAMES[] = {
{ 0x3030 /* 00 */, "World" },
{ 0x4144 /* AD */, "Andorra" },
{ 0x4145 /* AE */, "United Arab Emirates" },
{ 0x4146 /* AF */, "Afghanistan" },
{ 0x4147 /* AG */, "Antigua and Barbuda" },
{ 0x4149 /* AI */, "Anguilla" },
{ 0x414C /* AL */, "Albania" },
{ 0x414D /* AM */, "Armenia" },
{ 0x414E /* AN */, "Netherlands Antilles" },
{ 0x414F /* AO */, "Angola" },
{ 0x4151 /* AQ */, "Antarctica" },
{ 0x4152 /* AR */, "Argentina" },
{ 0x4153 /* AS */, "American Samoa" },
{ 0x4154 /* AT */, "Austria" },
{ 0x4155 /* AU */, "Australia" },
{ 0x4157 /* AW */, "Aruba" },
{ 0x4158 /* AX */, "Aland Islands" },
{ 0x415A /* AZ */, "Azerbaijan" },
{ 0x4241 /* BA */, "Bosnia and Herzegovina" },
{ 0x4242 /* BB */, "Barbados" },
{ 0x4244 /* BD */, "Bangladesh" },
{ 0x4245 /* BE */, "Belgium" },
{ 0x4246 /* BF */, "Burkina Faso" },
{ 0x4247 /* BG */, "Bulgaria" },
{ 0x4248 /* BH */, "Bahrain" },
{ 0x4249 /* BI */, "Burundi" },
{ 0x424A /* BJ */, "Benin" },
{ 0x424C /* BL */, "Saint Barthelemy" },
{ 0x424D /* BM */, "Bermuda" },
{ 0x424E /* BN */, "Brunei Darussalam" },
{ 0x424F /* BO */, "Bolivia" },
{ 0x4252 /* BR */, "Brazil" },
{ 0x4253 /* BS */, "Bahamas" },
{ 0x4254 /* BT */, "Bhutan" },
{ 0x4256 /* BV */, "Bouvet Island" },
{ 0x4257 /* BW */, "Botswana" },
{ 0x4259 /* BY */, "Belarus" },
{ 0x425A /* BZ */, "Belize" },
{ 0x4341 /* CA */, "Canada" },
{ 0x4343 /* CC */, "Cocos (Keeling) Islands" },
{ 0x4344 /* CD */, "Congo" },
{ 0x4346 /* CF */, "Central African Republic" },
{ 0x4347 /* CG */, "Congo" },
{ 0x4348 /* CH */, "Switzerland" },
{ 0x4349 /* CI */, "Cote d'Ivoire" },
{ 0x434B /* CK */, "Cook Islands" },
{ 0x434C /* CL */, "Chile" },
{ 0x434D /* CM */, "Cameroon" },
{ 0x434E /* CN */, "China" },
{ 0x434F /* CO */, "Colombia" },
{ 0x4352 /* CR */, "Costa Rica" },
{ 0x4355 /* CU */, "Cuba" },
{ 0x4356 /* CV */, "Cape Verde" },
{ 0x4358 /* CX */, "Christmas Island" },
{ 0x4359 /* CY */, "Cyprus" },
{ 0x435A /* CZ */, "Czech Republic" },
{ 0x4445 /* DE */, "Germany" },
{ 0x444A /* DJ */, "Djibouti" },
{ 0x444B /* DK */, "Denmark" },
{ 0x444D /* DM */, "Dominica" },
{ 0x444F /* DO */, "Dominican Republic" },
{ 0x445A /* DZ */, "Algeria" },
{ 0x4543 /* EC */, "Ecuador" },
{ 0x4545 /* EE */, "Estonia" },
{ 0x4547 /* EG */, "Egypt" },
{ 0x4548 /* EH */, "Western Sahara" },
{ 0x4552 /* ER */, "Eritrea" },
{ 0x4553 /* ES */, "Spain" },
{ 0x4554 /* ET */, "Ethiopia" },
{ 0x4649 /* FI */, "Finland" },
{ 0x464A /* FJ */, "Fiji" },
{ 0x464B /* FK */, "Falkland Islands" },
{ 0x464D /* FM */, "Micronesia" },
{ 0x464F /* FO */, "Faroe Islands" },
{ 0x4652 /* FR */, "France" },
{ 0x4741 /* GA */, "Gabon" },
{ 0x4742 /* GB */, "United Kingdom" },
{ 0x4744 /* GD */, "Grenada" },
{ 0x4745 /* GE */, "Georgia" },
{ 0x4746 /* GF */, "French Guiana" },
{ 0x4747 /* GG */, "Guernsey" },
{ 0x4748 /* GH */, "Ghana" },
{ 0x4749 /* GI */, "Gibraltar" },
{ 0x474C /* GL */, "Greenland" },
{ 0x474D /* GM */, "Gambia" },
{ 0x474E /* GN */, "Guinea" },
{ 0x4750 /* GP */, "Guadeloupe" },
{ 0x4751 /* GQ */, "Equatorial Guinea" },
{ 0x4752 /* GR */, "Greece" },
{ 0x4753 /* GS */, "South Georgia" },
{ 0x4754 /* GT */, "Guatemala" },
{ 0x4755 /* GU */, "Guam" },
{ 0x4757 /* GW */, "Guinea-Bissau" },
{ 0x4759 /* GY */, "Guyana" },
{ 0x484B /* HK */, "Hong Kong" },
{ 0x484D /* HM */, "Heard and McDonald Islands" },
{ 0x484E /* HN */, "Honduras" },
{ 0x4852 /* HR */, "Croatia" },
{ 0x4854 /* HT */, "Haiti" },
{ 0x4855 /* HU */, "Hungary" },
{ 0x4944 /* ID */, "Indonesia" },
{ 0x4945 /* IE */, "Ireland" },
{ 0x494C /* IL */, "Israel" },
{ 0x494D /* IM */, "Isle of Man" },
{ 0x494E /* IN */, "India" },
{ 0x494F /* IO */, "Chagos Islands" },
{ 0x4951 /* IQ */, "Iraq" },
{ 0x4952 /* IR */, "Iran" },
{ 0x4953 /* IS */, "Iceland" },
{ 0x4954 /* IT */, "Italy" },
{ 0x4A45 /* JE */, "Jersey" },
{ 0x4A4D /* JM */, "Jamaica" },
{ 0x4A4F /* JO */, "Jordan" },
{ 0x4A50 /* JP */, "Japan" },
{ 0x4B45 /* KE */, "Kenya" },
{ 0x4B47 /* KG */, "Kyrgyzstan" },
{ 0x4B48 /* KH */, "Cambodia" },
{ 0x4B49 /* KI */, "Kiribati" },
{ 0x4B4D /* KM */, "Comoros" },
{ 0x4B4E /* KN */, "Saint Kitts and Nevis" },
{ 0x4B50 /* KP */, "North Korea" },
{ 0x4B52 /* KR */, "South Korea" },
{ 0x4B57 /* KW */, "Kuwait" },
{ 0x4B59 /* KY */, "Cayman Islands" },
{ 0x4B5A /* KZ */, "Kazakhstan" },
{ 0x4C41 /* LA */, "Laos" },
{ 0x4C42 /* LB */, "Lebanon" },
{ 0x4C43 /* LC */, "Saint Lucia" },
{ 0x4C49 /* LI */, "Liechtenstein" },
{ 0x4C4B /* LK */, "Sri Lanka" },
{ 0x4C52 /* LR */, "Liberia" },
{ 0x4C53 /* LS */, "Lesotho" },
{ 0x4C54 /* LT */, "Lithuania" },
{ 0x4C55 /* LU */, "Luxembourg" },
{ 0x4C56 /* LV */, "Latvia" },
{ 0x4C59 /* LY */, "Libyan Arab Jamahiriya" },
{ 0x4D41 /* MA */, "Morocco" },
{ 0x4D43 /* MC */, "Monaco" },
{ 0x4D44 /* MD */, "Moldova" },
{ 0x4D45 /* ME */, "Montenegro" },
{ 0x4D46 /* MF */, "Saint Martin (French part)" },
{ 0x4D47 /* MG */, "Madagascar" },
{ 0x4D48 /* MH */, "Marshall Islands" },
{ 0x4D4B /* MK */, "Macedonia" },
{ 0x4D4C /* ML */, "Mali" },
{ 0x4D4D /* MM */, "Myanmar" },
{ 0x4D4E /* MN */, "Mongolia" },
{ 0x4D4F /* MO */, "Macao" },
{ 0x4D50 /* MP */, "Northern Mariana Islands" },
{ 0x4D51 /* MQ */, "Martinique" },
{ 0x4D52 /* MR */, "Mauritania" },
{ 0x4D53 /* MS */, "Montserrat" },
{ 0x4D54 /* MT */, "Malta" },
{ 0x4D55 /* MU */, "Mauritius" },
{ 0x4D56 /* MV */, "Maldives" },
{ 0x4D57 /* MW */, "Malawi" },
{ 0x4D58 /* MX */, "Mexico" },
{ 0x4D59 /* MY */, "Malaysia" },
{ 0x4D5A /* MZ */, "Mozambique" },
{ 0x4E41 /* NA */, "Namibia" },
{ 0x4E43 /* NC */, "New Caledonia" },
{ 0x4E45 /* NE */, "Niger" },
{ 0x4E46 /* NF */, "Norfolk Island" },
{ 0x4E47 /* NG */, "Nigeria" },
{ 0x4E49 /* NI */, "Nicaragua" },
{ 0x4E4C /* NL */, "Netherlands" },
{ 0x4E4F /* NO */, "Norway" },
{ 0x4E50 /* NP */, "Nepal" },
{ 0x4E52 /* NR */, "Nauru" },
{ 0x4E55 /* NU */, "Niue" },
{ 0x4E5A /* NZ */, "New Zealand" },