├── .gitignore ├── LICENSE ├── Makefile.OpenWrt ├── README.md ├── SConstruct ├── doc ├── Doxyfile ├── hostapd.dox ├── main.dox └── presentation │ ├── Makefile │ ├── dox1.jpg │ ├── dox2.jpg │ ├── dox3.jpg │ ├── dox4.jpg │ ├── feeling-lucky.jpg │ ├── slide.pdf │ └── slide.tex ├── examples ├── conf.c ├── hostapd.cpp ├── ifadd.c ├── ifdel.c ├── ifnames.c ├── mainskel.c ├── recover.c ├── routes.c ├── sample-get.c ├── sample-set.c └── scan.c ├── include └── wapi.h └── src ├── network.c ├── util.c ├── util.h └── wireless.c /.gitignore: -------------------------------------------------------------------------------- 1 | .sconsign.dblite 2 | examples/*.o 3 | examples/*.so 4 | gmon.out 5 | doc/html 6 | lib/* 7 | semantic.cache 8 | src/*.o 9 | src/*.os 10 | TAGS 11 | .sconf_temp 12 | config.log 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010, Volkan YAZICI 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | - Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | - Redistributions in binary form must reproduce the above copyright notice, this 11 | list of conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 15 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 18 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 21 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | -------------------------------------------------------------------------------- /Makefile.OpenWrt: -------------------------------------------------------------------------------- 1 | include $(TOPDIR)/rules.mk 2 | 3 | PKG_NAME:=wapi 4 | PKG_VERSION:=0.1 5 | PKG_RELEASE:=1 6 | 7 | PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz 8 | PKG_SOURCE_URL:=http://vy.github.com/wapi/files/ 9 | PKG_MD5SUM:=a8f947ebf0215f8dcbf87d20702219fd 10 | 11 | include $(INCLUDE_DIR)/package.mk 12 | 13 | define Package/wapi 14 | SECTION:=libs 15 | CATEGORY:=Libraries 16 | TITLE:=generic C API for network interfaces 17 | URL:=http://vy.github.com/wapi/ 18 | DEPENDS:=+libiw +libnl 19 | endef 20 | 21 | define Package/wapi/description 22 | This package provides an easy-to-use generic C API to network interfaces in 23 | GNU/Linux systems. One can think WAPI as a lightweight C API for iwconfig, 24 | wlanconfig, ifconfig, and route commands. (But it is not a thin wrapper for 25 | these command line tools.) 26 | endef 27 | 28 | define Build/Compile 29 | $(INSTALL_DIR) $(PKG_BUILD_DIR)/lib 30 | $(TARGET_CC) \ 31 | $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) $(TARGET_LDFLAGS) $(FPIC) \ 32 | -shared -fno-strict-aliasing -DLIBNL1 -lnl -lm -liw \ 33 | -I$(PKG_BUILD_DIR)/include \ 34 | -I$(PKG_BUILD_DIR)/src \ 35 | $(PKG_BUILD_DIR)/src/util.c \ 36 | $(PKG_BUILD_DIR)/src/network.c \ 37 | $(PKG_BUILD_DIR)/src/wireless.c \ 38 | -o $(PKG_BUILD_DIR)/lib/libwapi.so 39 | endef 40 | 41 | define Build/InstallDev 42 | $(INSTALL_DIR) $(1)/usr/include 43 | $(CP) $(PKG_BUILD_DIR)/include/wapi.h $(1)/usr/include/ 44 | $(INSTALL_DIR) $(1)/usr/lib 45 | $(CP) $(PKG_BUILD_DIR)/lib/libwapi.so $(1)/usr/lib/ 46 | endef 47 | 48 | define Package/wapi/install 49 | $(INSTALL_DIR) $(1)/usr/lib 50 | $(CP) $(PKG_BUILD_DIR)/lib/libwapi.so $(1)/usr/lib/ 51 | endef 52 | 53 | $(eval $(call BuildPackage,wapi)) 54 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | `_`_`_`_____`_____`__` 2 | |`|`|`|``_``|``_``|``| 3 | |`|`|`|`````|```__|``| 4 | |_____|__|__|__|``|__| 5 | 6 | WAPI (Wireless API) provides an easy-to-use function set to configure wireless network interfaces on a GNU/Linux system. One can think WAPI as a lightweight C API for `iwconfig`, `wlanconfig`, `ifconfig`, and `route` commands. (But it is not a thin wrapper for these command line tools.) It is currently being used in [WISERLAB](http://www.wiserlab.org/) test-bed to configure 802.11 based wireless interfaces. The development is partially supported by European Commission Grant Number PIRG06-GA-2009-256326. 7 | 8 | For source codes, see [http://github.com/vy/wapi](http://github.com/vy/wapi). While you can manually generate the documentation via Doxygen, the most recent version of the documentation is (hopefully) always available online at [http://vy.github.com/wapi](http://vy.github.com/wapi). 9 | 10 | You can also easily integrate WAPI to OpenWrt platform as well. For this purpose, just see `Makefile.OpenWrt` in the root directory. 11 | -------------------------------------------------------------------------------- /SConstruct: -------------------------------------------------------------------------------- 1 | from os.path import join as opj 2 | from os import getenv 3 | from sys import stderr, stdout 4 | 5 | 6 | ### Common Variables ########################################################### 7 | 8 | INCDIR = 'include' 9 | LIBDIR = 'lib' 10 | SRCDIR = 'src' 11 | EXADIR = 'examples' 12 | 13 | 14 | ### Common Utilities ########################################################### 15 | 16 | def to_src_path(file): 17 | return opj(SRCDIR, file) 18 | 19 | 20 | ### Parse Command Line Arguments ############################################### 21 | 22 | vars = Variables() 23 | vars.AddVariables( 24 | BoolVariable('debug', 'Enable debug symbols.', True), 25 | BoolVariable('optimize', 'Compile with optimization flags turned on.', True), 26 | BoolVariable('profile', 'Enable profile information.', False), 27 | BoolVariable('check', 'Enable library/header checks.', True), 28 | BoolVariable('examples', 'Compile examples.', False), 29 | ) 30 | env = Environment(variables = vars) 31 | Help(vars.GenerateHelpText(env)) 32 | 33 | if env['debug']: 34 | env.Append(CCFLAGS = '-g') 35 | 36 | if env['optimize']: 37 | env.Append(CCFLAGS = '-O3 -pipe') 38 | if not env['profile']: 39 | env.Append(CCFLAGS = '-fomit-frame-pointer') 40 | 41 | if env['profile']: 42 | env.Append(CCFLAGS = '-pg') 43 | env.Append(LINKFLAGS = '-pg') 44 | 45 | 46 | ### Generic Compiler Flags ##################################################### 47 | 48 | env.Append(CCFLAGS = '-Wall') 49 | env.Append(CPPPATH = [INCDIR]) 50 | env.Append(LIBPATH = LIBDIR) 51 | 52 | 53 | ### Parse Environment Variables ################################################ 54 | 55 | env.Append(CCFLAGS = getenv('CFLAGS', '')) 56 | env.Append(CCFLAGS = '-fno-strict-aliasing') 57 | env.Append(LINKFLAGS = getenv('LDFLAGS', '')) 58 | 59 | 60 | ### Library/Header Check ####################################################### 61 | 62 | common_libs = ['m', 'iw'] 63 | common_hdrs = [ 64 | 'ctype.h', 65 | 'errno.h', 66 | 'iwlib.h', 67 | 'libgen.h', 68 | 'linux/nl80211.h', 69 | 'math.h', 70 | 'netinet/in.h', 71 | 'net/route.h', 72 | 'stdio.h', 73 | 'stdlib.h', 74 | 'string.h', 75 | 'sys/ioctl.h', 76 | 'sys/socket.h', 77 | 'sys/types.h', 78 | ] 79 | 80 | def CheckPkgConfig(ctx): 81 | ctx.Message('Checking for pkg-config... ') 82 | ret = ctx.TryAction('pkg-config pkg-config')[0] 83 | ctx.Result(ret) 84 | return ret 85 | 86 | def CheckPkg(ctx, pkg, ver): 87 | ctx.Message('Checking for package %s... ' % pkg) 88 | ret = ctx.TryAction('pkg-config --atleast-version=%s %s' % (ver, pkg))[0] 89 | ctx.Result(ret) 90 | return ret 91 | 92 | conf = Configure( 93 | env, 94 | custom_tests = { 95 | 'CheckPkgConfig': CheckPkgConfig, 96 | 'CheckPkg': CheckPkg}) 97 | 98 | def require_lib(lib): 99 | if not conf.CheckLib(lib): 100 | Exit(1) 101 | 102 | def require_hdr(hdr): 103 | if not conf.CheckCHeader(hdr): 104 | Exit(1) 105 | 106 | src = env.Clone() # Library sources. 107 | exa = env.Clone() # Examples. 108 | 109 | if not (env.GetOption('clean') or env.GetOption('help')): 110 | if env['check']: 111 | # Checking common libraries. 112 | map(require_hdr, common_hdrs) 113 | map(require_lib, common_libs) 114 | # Check pkg-config. 115 | if not conf.CheckPkgConfig(): 116 | stderr.write("pkg-config is missing!\n") 117 | Exit(1) 118 | # Configuring nl80211. 119 | if conf.CheckPkg('libnl-1', '1'): 120 | src.ParseConfig('pkg-config --libs --cflags libnl-1') 121 | src.Append(CCFLAGS = '-DLIBNL1') 122 | elif conf.CheckPkg('libnl-2.0', '2'): 123 | src.ParseConfig('pkg-config --libs --cflags libnl-2.0') 124 | src.Append(CCFLAGS = '-DLIBNL2') 125 | elif conf.CheckPkg('libnl-3.0', '3'): 126 | src.ParseConfig('pkg-config --libs --cflags libnl-3.0') 127 | src.Append(CCFLAGS = '-DLIBNL3') 128 | else: 129 | stderr.write('libnl could not be found!') 130 | Exit(1) 131 | 132 | 133 | ### Compile WAPI ############################################################### 134 | 135 | common_srcs = map(to_src_path, ['util.c', 'network.c', 'wireless.c']) 136 | 137 | src.Append(LIBS = common_libs) 138 | src.Append(CPPPATH = [SRCDIR]) 139 | 140 | src.SharedLibrary( 141 | opj(LIBDIR, 'wapi'), 142 | map(src.SharedObject, common_srcs)) 143 | src.StaticLibrary( 144 | opj(LIBDIR, 'wapi_static'), 145 | map(src.StaticObject, common_srcs) 146 | ) 147 | 148 | 149 | ### Compile Examples ########################################################### 150 | 151 | if env['examples']: 152 | exa.Program(opj(EXADIR, 'sample-get.c'), LIBS = ['wapi']) 153 | exa.Program(opj(EXADIR, 'sample-set.c'), LIBS = ['wapi']) 154 | exa.Program(opj(EXADIR, 'ifadd.c'), LIBS = ['wapi']) 155 | exa.Program(opj(EXADIR, 'ifdel.c'), LIBS = ['wapi']) 156 | exa.Program(opj(EXADIR, 'recover.c'), LIBS = ['wapi']) 157 | exa.Program(opj(EXADIR, 'hostapd.cpp')) 158 | -------------------------------------------------------------------------------- /doc/Doxyfile: -------------------------------------------------------------------------------- 1 | # Doxyfile 1.7.1 2 | 3 | # This file describes the settings to be used by the documentation system 4 | # doxygen (www.doxygen.org) for a project 5 | # 6 | # All text after a hash (#) is considered a comment and will be ignored 7 | # The format is: 8 | # TAG = value [value, ...] 9 | # For lists items can also be appended using: 10 | # TAG += value [value, ...] 11 | # Values that contain spaces should be placed between quotes (" ") 12 | 13 | #--------------------------------------------------------------------------- 14 | # Project related configuration options 15 | #--------------------------------------------------------------------------- 16 | 17 | # This tag specifies the encoding used for all characters in the config file 18 | # that follow. The default is UTF-8 which is also the encoding used for all 19 | # text before the first occurrence of this tag. Doxygen uses libiconv (or the 20 | # iconv built into libc) for the transcoding. See 21 | # http://www.gnu.org/software/libiconv for the list of possible encodings. 22 | 23 | DOXYFILE_ENCODING = UTF-8 24 | 25 | # The PROJECT_NAME tag is a single word (or a sequence of words surrounded 26 | # by quotes) that should identify the project. 27 | 28 | PROJECT_NAME = WAPI 29 | 30 | # The PROJECT_NUMBER tag can be used to enter a project or revision number. 31 | # This could be handy for archiving the generated documentation or 32 | # if some version control system is used. 33 | 34 | PROJECT_NUMBER = 35 | 36 | # The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) 37 | # base path where the generated documentation will be put. 38 | # If a relative path is entered, it will be relative to the location 39 | # where doxygen was started. If left blank the current directory will be used. 40 | 41 | OUTPUT_DIRECTORY = 42 | 43 | # If the CREATE_SUBDIRS tag is set to YES, then doxygen will create 44 | # 4096 sub-directories (in 2 levels) under the output directory of each output 45 | # format and will distribute the generated files over these directories. 46 | # Enabling this option can be useful when feeding doxygen a huge amount of 47 | # source files, where putting all generated files in the same directory would 48 | # otherwise cause performance problems for the file system. 49 | 50 | CREATE_SUBDIRS = NO 51 | 52 | # The OUTPUT_LANGUAGE tag is used to specify the language in which all 53 | # documentation generated by doxygen is written. Doxygen will use this 54 | # information to generate all constant output in the proper language. 55 | # The default language is English, other supported languages are: 56 | # Afrikaans, Arabic, Brazilian, Catalan, Chinese, Chinese-Traditional, 57 | # Croatian, Czech, Danish, Dutch, Esperanto, Farsi, Finnish, French, German, 58 | # Greek, Hungarian, Italian, Japanese, Japanese-en (Japanese with English 59 | # messages), Korean, Korean-en, Lithuanian, Norwegian, Macedonian, Persian, 60 | # Polish, Portuguese, Romanian, Russian, Serbian, Serbian-Cyrilic, Slovak, 61 | # Slovene, Spanish, Swedish, Ukrainian, and Vietnamese. 62 | 63 | OUTPUT_LANGUAGE = English 64 | 65 | # If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will 66 | # include brief member descriptions after the members that are listed in 67 | # the file and class documentation (similar to JavaDoc). 68 | # Set to NO to disable this. 69 | 70 | BRIEF_MEMBER_DESC = YES 71 | 72 | # If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend 73 | # the brief description of a member or function before the detailed description. 74 | # Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the 75 | # brief descriptions will be completely suppressed. 76 | 77 | REPEAT_BRIEF = YES 78 | 79 | # This tag implements a quasi-intelligent brief description abbreviator 80 | # that is used to form the text in various listings. Each string 81 | # in this list, if found as the leading text of the brief description, will be 82 | # stripped from the text and the result after processing the whole list, is 83 | # used as the annotated text. Otherwise, the brief description is used as-is. 84 | # If left blank, the following values are used ("$name" is automatically 85 | # replaced with the name of the entity): "The $name class" "The $name widget" 86 | # "The $name file" "is" "provides" "specifies" "contains" 87 | # "represents" "a" "an" "the" 88 | 89 | ABBREVIATE_BRIEF = 90 | 91 | # If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then 92 | # Doxygen will generate a detailed section even if there is only a brief 93 | # description. 94 | 95 | ALWAYS_DETAILED_SEC = NO 96 | 97 | # If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all 98 | # inherited members of a class in the documentation of that class as if those 99 | # members were ordinary class members. Constructors, destructors and assignment 100 | # operators of the base classes will not be shown. 101 | 102 | INLINE_INHERITED_MEMB = NO 103 | 104 | # If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full 105 | # path before files name in the file list and in the header files. If set 106 | # to NO the shortest path that makes the file name unique will be used. 107 | 108 | FULL_PATH_NAMES = NO 109 | 110 | # If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag 111 | # can be used to strip a user-defined part of the path. Stripping is 112 | # only done if one of the specified strings matches the left-hand part of 113 | # the path. The tag can be used to show relative paths in the file list. 114 | # If left blank the directory from which doxygen is run is used as the 115 | # path to strip. 116 | 117 | STRIP_FROM_PATH = 118 | 119 | # The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of 120 | # the path mentioned in the documentation of a class, which tells 121 | # the reader which header file to include in order to use a class. 122 | # If left blank only the name of the header file containing the class 123 | # definition is used. Otherwise one should specify the include paths that 124 | # are normally passed to the compiler using the -I flag. 125 | 126 | STRIP_FROM_INC_PATH = 127 | 128 | # If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter 129 | # (but less readable) file names. This can be useful is your file systems 130 | # doesn't support long names like on DOS, Mac, or CD-ROM. 131 | 132 | SHORT_NAMES = NO 133 | 134 | # If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen 135 | # will interpret the first line (until the first dot) of a JavaDoc-style 136 | # comment as the brief description. If set to NO, the JavaDoc 137 | # comments will behave just like regular Qt-style comments 138 | # (thus requiring an explicit @brief command for a brief description.) 139 | 140 | JAVADOC_AUTOBRIEF = YES 141 | 142 | # If the QT_AUTOBRIEF tag is set to YES then Doxygen will 143 | # interpret the first line (until the first dot) of a Qt-style 144 | # comment as the brief description. If set to NO, the comments 145 | # will behave just like regular Qt-style comments (thus requiring 146 | # an explicit \brief command for a brief description.) 147 | 148 | QT_AUTOBRIEF = NO 149 | 150 | # The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen 151 | # treat a multi-line C++ special comment block (i.e. a block of //! or /// 152 | # comments) as a brief description. This used to be the default behaviour. 153 | # The new default is to treat a multi-line C++ comment block as a detailed 154 | # description. Set this tag to YES if you prefer the old behaviour instead. 155 | 156 | MULTILINE_CPP_IS_BRIEF = NO 157 | 158 | # If the INHERIT_DOCS tag is set to YES (the default) then an undocumented 159 | # member inherits the documentation from any documented member that it 160 | # re-implements. 161 | 162 | INHERIT_DOCS = YES 163 | 164 | # If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce 165 | # a new page for each member. If set to NO, the documentation of a member will 166 | # be part of the file/class/namespace that contains it. 167 | 168 | SEPARATE_MEMBER_PAGES = NO 169 | 170 | # The TAB_SIZE tag can be used to set the number of spaces in a tab. 171 | # Doxygen uses this value to replace tabs by spaces in code fragments. 172 | 173 | TAB_SIZE = 4 174 | 175 | # This tag can be used to specify a number of aliases that acts 176 | # as commands in the documentation. An alias has the form "name=value". 177 | # For example adding "sideeffect=\par Side Effects:\n" will allow you to 178 | # put the command \sideeffect (or @sideeffect) in the documentation, which 179 | # will result in a user-defined paragraph with heading "Side Effects:". 180 | # You can put \n's in the value part of an alias to insert newlines. 181 | 182 | ALIASES = 183 | 184 | # Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C 185 | # sources only. Doxygen will then generate output that is more tailored for C. 186 | # For instance, some of the names that are used will be different. The list 187 | # of all members will be omitted, etc. 188 | 189 | OPTIMIZE_OUTPUT_FOR_C = YES 190 | 191 | # Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java 192 | # sources only. Doxygen will then generate output that is more tailored for 193 | # Java. For instance, namespaces will be presented as packages, qualified 194 | # scopes will look different, etc. 195 | 196 | OPTIMIZE_OUTPUT_JAVA = NO 197 | 198 | # Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran 199 | # sources only. Doxygen will then generate output that is more tailored for 200 | # Fortran. 201 | 202 | OPTIMIZE_FOR_FORTRAN = NO 203 | 204 | # Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL 205 | # sources. Doxygen will then generate output that is tailored for 206 | # VHDL. 207 | 208 | OPTIMIZE_OUTPUT_VHDL = NO 209 | 210 | # Doxygen selects the parser to use depending on the extension of the files it 211 | # parses. With this tag you can assign which parser to use for a given extension. 212 | # Doxygen has a built-in mapping, but you can override or extend it using this 213 | # tag. The format is ext=language, where ext is a file extension, and language 214 | # is one of the parsers supported by doxygen: IDL, Java, Javascript, CSharp, C, 215 | # C++, D, PHP, Objective-C, Python, Fortran, VHDL, C, C++. For instance to make 216 | # doxygen treat .inc files as Fortran files (default is PHP), and .f files as C 217 | # (default is Fortran), use: inc=Fortran f=C. Note that for custom extensions 218 | # you also need to set FILE_PATTERNS otherwise the files are not read by doxygen. 219 | 220 | EXTENSION_MAPPING = 221 | 222 | # If you use STL classes (i.e. std::string, std::vector, etc.) but do not want 223 | # to include (a tag file for) the STL sources as input, then you should 224 | # set this tag to YES in order to let doxygen match functions declarations and 225 | # definitions whose arguments contain STL classes (e.g. func(std::string); v.s. 226 | # func(std::string) {}). This also make the inheritance and collaboration 227 | # diagrams that involve STL classes more complete and accurate. 228 | 229 | BUILTIN_STL_SUPPORT = NO 230 | 231 | # If you use Microsoft's C++/CLI language, you should set this option to YES to 232 | # enable parsing support. 233 | 234 | CPP_CLI_SUPPORT = NO 235 | 236 | # Set the SIP_SUPPORT tag to YES if your project consists of sip sources only. 237 | # Doxygen will parse them like normal C++ but will assume all classes use public 238 | # instead of private inheritance when no explicit protection keyword is present. 239 | 240 | SIP_SUPPORT = NO 241 | 242 | # For Microsoft's IDL there are propget and propput attributes to indicate getter 243 | # and setter methods for a property. Setting this option to YES (the default) 244 | # will make doxygen to replace the get and set methods by a property in the 245 | # documentation. This will only work if the methods are indeed getting or 246 | # setting a simple type. If this is not the case, or you want to show the 247 | # methods anyway, you should set this option to NO. 248 | 249 | IDL_PROPERTY_SUPPORT = YES 250 | 251 | # If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC 252 | # tag is set to YES, then doxygen will reuse the documentation of the first 253 | # member in the group (if any) for the other members of the group. By default 254 | # all members of a group must be documented explicitly. 255 | 256 | DISTRIBUTE_GROUP_DOC = NO 257 | 258 | # Set the SUBGROUPING tag to YES (the default) to allow class member groups of 259 | # the same type (for instance a group of public functions) to be put as a 260 | # subgroup of that type (e.g. under the Public Functions section). Set it to 261 | # NO to prevent subgrouping. Alternatively, this can be done per class using 262 | # the \nosubgrouping command. 263 | 264 | SUBGROUPING = YES 265 | 266 | # When TYPEDEF_HIDES_STRUCT is enabled, a typedef of a struct, union, or enum 267 | # is documented as struct, union, or enum with the name of the typedef. So 268 | # typedef struct TypeS {} TypeT, will appear in the documentation as a struct 269 | # with name TypeT. When disabled the typedef will appear as a member of a file, 270 | # namespace, or class. And the struct will be named TypeS. This can typically 271 | # be useful for C code in case the coding convention dictates that all compound 272 | # types are typedef'ed and only the typedef is referenced, never the tag name. 273 | 274 | TYPEDEF_HIDES_STRUCT = NO 275 | 276 | # The SYMBOL_CACHE_SIZE determines the size of the internal cache use to 277 | # determine which symbols to keep in memory and which to flush to disk. 278 | # When the cache is full, less often used symbols will be written to disk. 279 | # For small to medium size projects (<1000 input files) the default value is 280 | # probably good enough. For larger projects a too small cache size can cause 281 | # doxygen to be busy swapping symbols to and from disk most of the time 282 | # causing a significant performance penality. 283 | # If the system has enough physical memory increasing the cache will improve the 284 | # performance by keeping more symbols in memory. Note that the value works on 285 | # a logarithmic scale so increasing the size by one will rougly double the 286 | # memory usage. The cache size is given by this formula: 287 | # 2^(16+SYMBOL_CACHE_SIZE). The valid range is 0..9, the default is 0, 288 | # corresponding to a cache size of 2^16 = 65536 symbols 289 | 290 | SYMBOL_CACHE_SIZE = 0 291 | 292 | #--------------------------------------------------------------------------- 293 | # Build related configuration options 294 | #--------------------------------------------------------------------------- 295 | 296 | # If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in 297 | # documentation are documented, even if no documentation was available. 298 | # Private class members and static file members will be hidden unless 299 | # the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES 300 | 301 | EXTRACT_ALL = YES 302 | 303 | # If the EXTRACT_PRIVATE tag is set to YES all private members of a class 304 | # will be included in the documentation. 305 | 306 | EXTRACT_PRIVATE = NO 307 | 308 | # If the EXTRACT_STATIC tag is set to YES all static members of a file 309 | # will be included in the documentation. 310 | 311 | EXTRACT_STATIC = NO 312 | 313 | # If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) 314 | # defined locally in source files will be included in the documentation. 315 | # If set to NO only classes defined in header files are included. 316 | 317 | EXTRACT_LOCAL_CLASSES = YES 318 | 319 | # This flag is only useful for Objective-C code. When set to YES local 320 | # methods, which are defined in the implementation section but not in 321 | # the interface are included in the documentation. 322 | # If set to NO (the default) only methods in the interface are included. 323 | 324 | EXTRACT_LOCAL_METHODS = NO 325 | 326 | # If this flag is set to YES, the members of anonymous namespaces will be 327 | # extracted and appear in the documentation as a namespace called 328 | # 'anonymous_namespace{file}', where file will be replaced with the base 329 | # name of the file that contains the anonymous namespace. By default 330 | # anonymous namespace are hidden. 331 | 332 | EXTRACT_ANON_NSPACES = NO 333 | 334 | # If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all 335 | # undocumented members of documented classes, files or namespaces. 336 | # If set to NO (the default) these members will be included in the 337 | # various overviews, but no documentation section is generated. 338 | # This option has no effect if EXTRACT_ALL is enabled. 339 | 340 | HIDE_UNDOC_MEMBERS = NO 341 | 342 | # If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all 343 | # undocumented classes that are normally visible in the class hierarchy. 344 | # If set to NO (the default) these classes will be included in the various 345 | # overviews. This option has no effect if EXTRACT_ALL is enabled. 346 | 347 | HIDE_UNDOC_CLASSES = NO 348 | 349 | # If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all 350 | # friend (class|struct|union) declarations. 351 | # If set to NO (the default) these declarations will be included in the 352 | # documentation. 353 | 354 | HIDE_FRIEND_COMPOUNDS = NO 355 | 356 | # If the HIDE_IN_BODY_DOCS tag is set to YES, Doxygen will hide any 357 | # documentation blocks found inside the body of a function. 358 | # If set to NO (the default) these blocks will be appended to the 359 | # function's detailed documentation block. 360 | 361 | HIDE_IN_BODY_DOCS = NO 362 | 363 | # The INTERNAL_DOCS tag determines if documentation 364 | # that is typed after a \internal command is included. If the tag is set 365 | # to NO (the default) then the documentation will be excluded. 366 | # Set it to YES to include the internal documentation. 367 | 368 | INTERNAL_DOCS = NO 369 | 370 | # If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate 371 | # file names in lower-case letters. If set to YES upper-case letters are also 372 | # allowed. This is useful if you have classes or files whose names only differ 373 | # in case and if your file system supports case sensitive file names. Windows 374 | # and Mac users are advised to set this option to NO. 375 | 376 | CASE_SENSE_NAMES = YES 377 | 378 | # If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen 379 | # will show members with their full class and namespace scopes in the 380 | # documentation. If set to YES the scope will be hidden. 381 | 382 | HIDE_SCOPE_NAMES = NO 383 | 384 | # If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen 385 | # will put a list of the files that are included by a file in the documentation 386 | # of that file. 387 | 388 | SHOW_INCLUDE_FILES = YES 389 | 390 | # If the FORCE_LOCAL_INCLUDES tag is set to YES then Doxygen 391 | # will list include files with double quotes in the documentation 392 | # rather than with sharp brackets. 393 | 394 | FORCE_LOCAL_INCLUDES = NO 395 | 396 | # If the INLINE_INFO tag is set to YES (the default) then a tag [inline] 397 | # is inserted in the documentation for inline members. 398 | 399 | INLINE_INFO = YES 400 | 401 | # If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen 402 | # will sort the (detailed) documentation of file and class members 403 | # alphabetically by member name. If set to NO the members will appear in 404 | # declaration order. 405 | 406 | SORT_MEMBER_DOCS = YES 407 | 408 | # If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the 409 | # brief documentation of file, namespace and class members alphabetically 410 | # by member name. If set to NO (the default) the members will appear in 411 | # declaration order. 412 | 413 | SORT_BRIEF_DOCS = NO 414 | 415 | # If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen 416 | # will sort the (brief and detailed) documentation of class members so that 417 | # constructors and destructors are listed first. If set to NO (the default) 418 | # the constructors will appear in the respective orders defined by 419 | # SORT_MEMBER_DOCS and SORT_BRIEF_DOCS. 420 | # This tag will be ignored for brief docs if SORT_BRIEF_DOCS is set to NO 421 | # and ignored for detailed docs if SORT_MEMBER_DOCS is set to NO. 422 | 423 | SORT_MEMBERS_CTORS_1ST = NO 424 | 425 | # If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the 426 | # hierarchy of group names into alphabetical order. If set to NO (the default) 427 | # the group names will appear in their defined order. 428 | 429 | SORT_GROUP_NAMES = NO 430 | 431 | # If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be 432 | # sorted by fully-qualified names, including namespaces. If set to 433 | # NO (the default), the class list will be sorted only by class name, 434 | # not including the namespace part. 435 | # Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. 436 | # Note: This option applies only to the class list, not to the 437 | # alphabetical list. 438 | 439 | SORT_BY_SCOPE_NAME = NO 440 | 441 | # The GENERATE_TODOLIST tag can be used to enable (YES) or 442 | # disable (NO) the todo list. This list is created by putting \todo 443 | # commands in the documentation. 444 | 445 | GENERATE_TODOLIST = YES 446 | 447 | # The GENERATE_TESTLIST tag can be used to enable (YES) or 448 | # disable (NO) the test list. This list is created by putting \test 449 | # commands in the documentation. 450 | 451 | GENERATE_TESTLIST = YES 452 | 453 | # The GENERATE_BUGLIST tag can be used to enable (YES) or 454 | # disable (NO) the bug list. This list is created by putting \bug 455 | # commands in the documentation. 456 | 457 | GENERATE_BUGLIST = YES 458 | 459 | # The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or 460 | # disable (NO) the deprecated list. This list is created by putting 461 | # \deprecated commands in the documentation. 462 | 463 | GENERATE_DEPRECATEDLIST= YES 464 | 465 | # The ENABLED_SECTIONS tag can be used to enable conditional 466 | # documentation sections, marked by \if sectionname ... \endif. 467 | 468 | ENABLED_SECTIONS = 469 | 470 | # The MAX_INITIALIZER_LINES tag determines the maximum number of lines 471 | # the initial value of a variable or define consists of for it to appear in 472 | # the documentation. If the initializer consists of more lines than specified 473 | # here it will be hidden. Use a value of 0 to hide initializers completely. 474 | # The appearance of the initializer of individual variables and defines in the 475 | # documentation can be controlled using \showinitializer or \hideinitializer 476 | # command in the documentation regardless of this setting. 477 | 478 | MAX_INITIALIZER_LINES = 30 479 | 480 | # Set the SHOW_USED_FILES tag to NO to disable the list of files generated 481 | # at the bottom of the documentation of classes and structs. If set to YES the 482 | # list will mention the files that were used to generate the documentation. 483 | 484 | SHOW_USED_FILES = YES 485 | 486 | # If the sources in your project are distributed over multiple directories 487 | # then setting the SHOW_DIRECTORIES tag to YES will show the directory hierarchy 488 | # in the documentation. The default is NO. 489 | 490 | SHOW_DIRECTORIES = YES 491 | 492 | # Set the SHOW_FILES tag to NO to disable the generation of the Files page. 493 | # This will remove the Files entry from the Quick Index and from the 494 | # Folder Tree View (if specified). The default is YES. 495 | 496 | SHOW_FILES = YES 497 | 498 | # Set the SHOW_NAMESPACES tag to NO to disable the generation of the 499 | # Namespaces page. 500 | # This will remove the Namespaces entry from the Quick Index 501 | # and from the Folder Tree View (if specified). The default is YES. 502 | 503 | SHOW_NAMESPACES = YES 504 | 505 | # The FILE_VERSION_FILTER tag can be used to specify a program or script that 506 | # doxygen should invoke to get the current version for each file (typically from 507 | # the version control system). Doxygen will invoke the program by executing (via 508 | # popen()) the command , where is the value of 509 | # the FILE_VERSION_FILTER tag, and is the name of an input file 510 | # provided by doxygen. Whatever the program writes to standard output 511 | # is used as the file version. See the manual for examples. 512 | 513 | FILE_VERSION_FILTER = 514 | 515 | # The LAYOUT_FILE tag can be used to specify a layout file which will be parsed 516 | # by doxygen. The layout file controls the global structure of the generated 517 | # output files in an output format independent way. The create the layout file 518 | # that represents doxygen's defaults, run doxygen with the -l option. 519 | # You can optionally specify a file name after the option, if omitted 520 | # DoxygenLayout.xml will be used as the name of the layout file. 521 | 522 | LAYOUT_FILE = 523 | 524 | #--------------------------------------------------------------------------- 525 | # configuration options related to warning and progress messages 526 | #--------------------------------------------------------------------------- 527 | 528 | # The QUIET tag can be used to turn on/off the messages that are generated 529 | # by doxygen. Possible values are YES and NO. If left blank NO is used. 530 | 531 | QUIET = NO 532 | 533 | # The WARNINGS tag can be used to turn on/off the warning messages that are 534 | # generated by doxygen. Possible values are YES and NO. If left blank 535 | # NO is used. 536 | 537 | WARNINGS = YES 538 | 539 | # If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings 540 | # for undocumented members. If EXTRACT_ALL is set to YES then this flag will 541 | # automatically be disabled. 542 | 543 | WARN_IF_UNDOCUMENTED = YES 544 | 545 | # If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for 546 | # potential errors in the documentation, such as not documenting some 547 | # parameters in a documented function, or documenting parameters that 548 | # don't exist or using markup commands wrongly. 549 | 550 | WARN_IF_DOC_ERROR = YES 551 | 552 | # This WARN_NO_PARAMDOC option can be abled to get warnings for 553 | # functions that are documented, but have no documentation for their parameters 554 | # or return value. If set to NO (the default) doxygen will only warn about 555 | # wrong or incomplete parameter documentation, but not about the absence of 556 | # documentation. 557 | 558 | WARN_NO_PARAMDOC = NO 559 | 560 | # The WARN_FORMAT tag determines the format of the warning messages that 561 | # doxygen can produce. The string should contain the $file, $line, and $text 562 | # tags, which will be replaced by the file and line number from which the 563 | # warning originated and the warning text. Optionally the format may contain 564 | # $version, which will be replaced by the version of the file (if it could 565 | # be obtained via FILE_VERSION_FILTER) 566 | 567 | WARN_FORMAT = "$file:$line: $text" 568 | 569 | # The WARN_LOGFILE tag can be used to specify a file to which warning 570 | # and error messages should be written. If left blank the output is written 571 | # to stderr. 572 | 573 | WARN_LOGFILE = 574 | 575 | #--------------------------------------------------------------------------- 576 | # configuration options related to the input files 577 | #--------------------------------------------------------------------------- 578 | 579 | # The INPUT tag can be used to specify the files and/or directories that contain 580 | # documented source files. You may enter file names like "myfile.cpp" or 581 | # directories like "/usr/src/myproject". Separate the files or directories 582 | # with spaces. 583 | 584 | INPUT = main.dox hostapd.dox ../include ../src 585 | 586 | # This tag can be used to specify the character encoding of the source files 587 | # that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is 588 | # also the default input encoding. Doxygen uses libiconv (or the iconv built 589 | # into libc) for the transcoding. See http://www.gnu.org/software/libiconv for 590 | # the list of possible encodings. 591 | 592 | INPUT_ENCODING = UTF-8 593 | 594 | # If the value of the INPUT tag contains directories, you can use the 595 | # FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp 596 | # and *.h) to filter out the source-files in the directories. If left 597 | # blank the following patterns are tested: 598 | # *.c *.cc *.cxx *.cpp *.c++ *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh *.hxx 599 | # *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm *.py *.f90 600 | 601 | FILE_PATTERNS = 602 | 603 | # The RECURSIVE tag can be used to turn specify whether or not subdirectories 604 | # should be searched for input files as well. Possible values are YES and NO. 605 | # If left blank NO is used. 606 | 607 | RECURSIVE = YES 608 | 609 | # The EXCLUDE tag can be used to specify files and/or directories that should 610 | # excluded from the INPUT source files. This way you can easily exclude a 611 | # subdirectory from a directory tree whose root is specified with the INPUT tag. 612 | 613 | EXCLUDE = 614 | 615 | # The EXCLUDE_SYMLINKS tag can be used select whether or not files or 616 | # directories that are symbolic links (a Unix filesystem feature) are excluded 617 | # from the input. 618 | 619 | EXCLUDE_SYMLINKS = NO 620 | 621 | # If the value of the INPUT tag contains directories, you can use the 622 | # EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude 623 | # certain files from those directories. Note that the wildcards are matched 624 | # against the file with absolute path, so to exclude all test directories 625 | # for example use the pattern */test/* 626 | 627 | EXCLUDE_PATTERNS = 628 | 629 | # The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names 630 | # (namespaces, classes, functions, etc.) that should be excluded from the 631 | # output. The symbol name can be a fully qualified name, a word, or if the 632 | # wildcard * is used, a substring. Examples: ANamespace, AClass, 633 | # AClass::ANamespace, ANamespace::*Test 634 | 635 | EXCLUDE_SYMBOLS = 636 | 637 | # The EXAMPLE_PATH tag can be used to specify one or more files or 638 | # directories that contain example code fragments that are included (see 639 | # the \include command). 640 | 641 | EXAMPLE_PATH = ../examples 642 | 643 | # If the value of the EXAMPLE_PATH tag contains directories, you can use the 644 | # EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp 645 | # and *.h) to filter out the source-files in the directories. If left 646 | # blank all files are included. 647 | 648 | EXAMPLE_PATTERNS = 649 | 650 | # If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be 651 | # searched for input files to be used with the \include or \dontinclude 652 | # commands irrespective of the value of the RECURSIVE tag. 653 | # Possible values are YES and NO. If left blank NO is used. 654 | 655 | EXAMPLE_RECURSIVE = NO 656 | 657 | # The IMAGE_PATH tag can be used to specify one or more files or 658 | # directories that contain image that are included in the documentation (see 659 | # the \image command). 660 | 661 | IMAGE_PATH = 662 | 663 | # The INPUT_FILTER tag can be used to specify a program that doxygen should 664 | # invoke to filter for each input file. Doxygen will invoke the filter program 665 | # by executing (via popen()) the command , where 666 | # is the value of the INPUT_FILTER tag, and is the name of an 667 | # input file. Doxygen will then use the output that the filter program writes 668 | # to standard output. 669 | # If FILTER_PATTERNS is specified, this tag will be 670 | # ignored. 671 | 672 | INPUT_FILTER = 673 | 674 | # The FILTER_PATTERNS tag can be used to specify filters on a per file pattern 675 | # basis. 676 | # Doxygen will compare the file name with each pattern and apply the 677 | # filter if there is a match. 678 | # The filters are a list of the form: 679 | # pattern=filter (like *.cpp=my_cpp_filter). See INPUT_FILTER for further 680 | # info on how filters are used. If FILTER_PATTERNS is empty, INPUT_FILTER 681 | # is applied to all files. 682 | 683 | FILTER_PATTERNS = 684 | 685 | # If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using 686 | # INPUT_FILTER) will be used to filter the input files when producing source 687 | # files to browse (i.e. when SOURCE_BROWSER is set to YES). 688 | 689 | FILTER_SOURCE_FILES = NO 690 | 691 | #--------------------------------------------------------------------------- 692 | # configuration options related to source browsing 693 | #--------------------------------------------------------------------------- 694 | 695 | # If the SOURCE_BROWSER tag is set to YES then a list of source files will 696 | # be generated. Documented entities will be cross-referenced with these sources. 697 | # Note: To get rid of all source code in the generated output, make sure also 698 | # VERBATIM_HEADERS is set to NO. 699 | 700 | SOURCE_BROWSER = YES 701 | 702 | # Setting the INLINE_SOURCES tag to YES will include the body 703 | # of functions and classes directly in the documentation. 704 | 705 | INLINE_SOURCES = NO 706 | 707 | # Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct 708 | # doxygen to hide any special comment blocks from generated source code 709 | # fragments. Normal C and C++ comments will always remain visible. 710 | 711 | STRIP_CODE_COMMENTS = NO 712 | 713 | # If the REFERENCED_BY_RELATION tag is set to YES 714 | # then for each documented function all documented 715 | # functions referencing it will be listed. 716 | 717 | REFERENCED_BY_RELATION = YES 718 | 719 | # If the REFERENCES_RELATION tag is set to YES 720 | # then for each documented function all documented entities 721 | # called/used by that function will be listed. 722 | 723 | REFERENCES_RELATION = YES 724 | 725 | # If the REFERENCES_LINK_SOURCE tag is set to YES (the default) 726 | # and SOURCE_BROWSER tag is set to YES, then the hyperlinks from 727 | # functions in REFERENCES_RELATION and REFERENCED_BY_RELATION lists will 728 | # link to the source code. 729 | # Otherwise they will link to the documentation. 730 | 731 | REFERENCES_LINK_SOURCE = YES 732 | 733 | # If the USE_HTAGS tag is set to YES then the references to source code 734 | # will point to the HTML generated by the htags(1) tool instead of doxygen 735 | # built-in source browser. The htags tool is part of GNU's global source 736 | # tagging system (see http://www.gnu.org/software/global/global.html). You 737 | # will need version 4.8.6 or higher. 738 | 739 | USE_HTAGS = NO 740 | 741 | # If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen 742 | # will generate a verbatim copy of the header file for each class for 743 | # which an include is specified. Set to NO to disable this. 744 | 745 | VERBATIM_HEADERS = YES 746 | 747 | #--------------------------------------------------------------------------- 748 | # configuration options related to the alphabetical class index 749 | #--------------------------------------------------------------------------- 750 | 751 | # If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index 752 | # of all compounds will be generated. Enable this if the project 753 | # contains a lot of classes, structs, unions or interfaces. 754 | 755 | ALPHABETICAL_INDEX = YES 756 | 757 | # If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then 758 | # the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns 759 | # in which this list will be split (can be a number in the range [1..20]) 760 | 761 | COLS_IN_ALPHA_INDEX = 5 762 | 763 | # In case all classes in a project start with a common prefix, all 764 | # classes will be put under the same header in the alphabetical index. 765 | # The IGNORE_PREFIX tag can be used to specify one or more prefixes that 766 | # should be ignored while generating the index headers. 767 | 768 | IGNORE_PREFIX = 769 | 770 | #--------------------------------------------------------------------------- 771 | # configuration options related to the HTML output 772 | #--------------------------------------------------------------------------- 773 | 774 | # If the GENERATE_HTML tag is set to YES (the default) Doxygen will 775 | # generate HTML output. 776 | 777 | GENERATE_HTML = YES 778 | 779 | # The HTML_OUTPUT tag is used to specify where the HTML docs will be put. 780 | # If a relative path is entered the value of OUTPUT_DIRECTORY will be 781 | # put in front of it. If left blank `html' will be used as the default path. 782 | 783 | HTML_OUTPUT = html 784 | 785 | # The HTML_FILE_EXTENSION tag can be used to specify the file extension for 786 | # each generated HTML page (for example: .htm,.php,.asp). If it is left blank 787 | # doxygen will generate files with .html extension. 788 | 789 | HTML_FILE_EXTENSION = .html 790 | 791 | # The HTML_HEADER tag can be used to specify a personal HTML header for 792 | # each generated HTML page. If it is left blank doxygen will generate a 793 | # standard header. 794 | 795 | HTML_HEADER = 796 | 797 | # The HTML_FOOTER tag can be used to specify a personal HTML footer for 798 | # each generated HTML page. If it is left blank doxygen will generate a 799 | # standard footer. 800 | 801 | HTML_FOOTER = 802 | 803 | # The HTML_STYLESHEET tag can be used to specify a user-defined cascading 804 | # style sheet that is used by each HTML page. It can be used to 805 | # fine-tune the look of the HTML output. If the tag is left blank doxygen 806 | # will generate a default style sheet. Note that doxygen will try to copy 807 | # the style sheet file to the HTML output directory, so don't put your own 808 | # stylesheet in the HTML output directory as well, or it will be erased! 809 | 810 | HTML_STYLESHEET = 811 | 812 | # The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. 813 | # Doxygen will adjust the colors in the stylesheet and background images 814 | # according to this color. Hue is specified as an angle on a colorwheel, 815 | # see http://en.wikipedia.org/wiki/Hue for more information. 816 | # For instance the value 0 represents red, 60 is yellow, 120 is green, 817 | # 180 is cyan, 240 is blue, 300 purple, and 360 is red again. 818 | # The allowed range is 0 to 359. 819 | 820 | HTML_COLORSTYLE_HUE = 220 821 | 822 | # The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of 823 | # the colors in the HTML output. For a value of 0 the output will use 824 | # grayscales only. A value of 255 will produce the most vivid colors. 825 | 826 | HTML_COLORSTYLE_SAT = 100 827 | 828 | # The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to 829 | # the luminance component of the colors in the HTML output. Values below 830 | # 100 gradually make the output lighter, whereas values above 100 make 831 | # the output darker. The value divided by 100 is the actual gamma applied, 832 | # so 80 represents a gamma of 0.8, The value 220 represents a gamma of 2.2, 833 | # and 100 does not change the gamma. 834 | 835 | HTML_COLORSTYLE_GAMMA = 80 836 | 837 | # If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML 838 | # page will contain the date and time when the page was generated. Setting 839 | # this to NO can help when comparing the output of multiple runs. 840 | 841 | HTML_TIMESTAMP = YES 842 | 843 | # If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes, 844 | # files or namespaces will be aligned in HTML using tables. If set to 845 | # NO a bullet list will be used. 846 | 847 | HTML_ALIGN_MEMBERS = YES 848 | 849 | # If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML 850 | # documentation will contain sections that can be hidden and shown after the 851 | # page has loaded. For this to work a browser that supports 852 | # JavaScript and DHTML is required (for instance Mozilla 1.0+, Firefox 853 | # Netscape 6.0+, Internet explorer 5.0+, Konqueror, or Safari). 854 | 855 | HTML_DYNAMIC_SECTIONS = NO 856 | 857 | # If the GENERATE_DOCSET tag is set to YES, additional index files 858 | # will be generated that can be used as input for Apple's Xcode 3 859 | # integrated development environment, introduced with OSX 10.5 (Leopard). 860 | # To create a documentation set, doxygen will generate a Makefile in the 861 | # HTML output directory. Running make will produce the docset in that 862 | # directory and running "make install" will install the docset in 863 | # ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find 864 | # it at startup. 865 | # See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html 866 | # for more information. 867 | 868 | GENERATE_DOCSET = NO 869 | 870 | # When GENERATE_DOCSET tag is set to YES, this tag determines the name of the 871 | # feed. A documentation feed provides an umbrella under which multiple 872 | # documentation sets from a single provider (such as a company or product suite) 873 | # can be grouped. 874 | 875 | DOCSET_FEEDNAME = "Doxygen generated docs" 876 | 877 | # When GENERATE_DOCSET tag is set to YES, this tag specifies a string that 878 | # should uniquely identify the documentation set bundle. This should be a 879 | # reverse domain-name style string, e.g. com.mycompany.MyDocSet. Doxygen 880 | # will append .docset to the name. 881 | 882 | DOCSET_BUNDLE_ID = org.doxygen.Project 883 | 884 | # When GENERATE_PUBLISHER_ID tag specifies a string that should uniquely identify 885 | # the documentation publisher. This should be a reverse domain-name style 886 | # string, e.g. com.mycompany.MyDocSet.documentation. 887 | 888 | DOCSET_PUBLISHER_ID = org.doxygen.Publisher 889 | 890 | # The GENERATE_PUBLISHER_NAME tag identifies the documentation publisher. 891 | 892 | DOCSET_PUBLISHER_NAME = Publisher 893 | 894 | # If the GENERATE_HTMLHELP tag is set to YES, additional index files 895 | # will be generated that can be used as input for tools like the 896 | # Microsoft HTML help workshop to generate a compiled HTML help file (.chm) 897 | # of the generated HTML documentation. 898 | 899 | GENERATE_HTMLHELP = NO 900 | 901 | # If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can 902 | # be used to specify the file name of the resulting .chm file. You 903 | # can add a path in front of the file if the result should not be 904 | # written to the html output directory. 905 | 906 | CHM_FILE = 907 | 908 | # If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can 909 | # be used to specify the location (absolute path including file name) of 910 | # the HTML help compiler (hhc.exe). If non-empty doxygen will try to run 911 | # the HTML help compiler on the generated index.hhp. 912 | 913 | HHC_LOCATION = 914 | 915 | # If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag 916 | # controls if a separate .chi index file is generated (YES) or that 917 | # it should be included in the master .chm file (NO). 918 | 919 | GENERATE_CHI = NO 920 | 921 | # If the GENERATE_HTMLHELP tag is set to YES, the CHM_INDEX_ENCODING 922 | # is used to encode HtmlHelp index (hhk), content (hhc) and project file 923 | # content. 924 | 925 | CHM_INDEX_ENCODING = 926 | 927 | # If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag 928 | # controls whether a binary table of contents is generated (YES) or a 929 | # normal table of contents (NO) in the .chm file. 930 | 931 | BINARY_TOC = NO 932 | 933 | # The TOC_EXPAND flag can be set to YES to add extra items for group members 934 | # to the contents of the HTML help documentation and to the tree view. 935 | 936 | TOC_EXPAND = NO 937 | 938 | # If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and 939 | # QHP_VIRTUAL_FOLDER are set, an additional index file will be generated 940 | # that can be used as input for Qt's qhelpgenerator to generate a 941 | # Qt Compressed Help (.qch) of the generated HTML documentation. 942 | 943 | GENERATE_QHP = NO 944 | 945 | # If the QHG_LOCATION tag is specified, the QCH_FILE tag can 946 | # be used to specify the file name of the resulting .qch file. 947 | # The path specified is relative to the HTML output folder. 948 | 949 | QCH_FILE = 950 | 951 | # The QHP_NAMESPACE tag specifies the namespace to use when generating 952 | # Qt Help Project output. For more information please see 953 | # http://doc.trolltech.com/qthelpproject.html#namespace 954 | 955 | QHP_NAMESPACE = org.doxygen.Project 956 | 957 | # The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating 958 | # Qt Help Project output. For more information please see 959 | # http://doc.trolltech.com/qthelpproject.html#virtual-folders 960 | 961 | QHP_VIRTUAL_FOLDER = doc 962 | 963 | # If QHP_CUST_FILTER_NAME is set, it specifies the name of a custom filter to 964 | # add. For more information please see 965 | # http://doc.trolltech.com/qthelpproject.html#custom-filters 966 | 967 | QHP_CUST_FILTER_NAME = 968 | 969 | # The QHP_CUST_FILT_ATTRS tag specifies the list of the attributes of the 970 | # custom filter to add. For more information please see 971 | # 972 | # Qt Help Project / Custom Filters. 973 | 974 | QHP_CUST_FILTER_ATTRS = 975 | 976 | # The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this 977 | # project's 978 | # filter section matches. 979 | # 980 | # Qt Help Project / Filter Attributes. 981 | 982 | QHP_SECT_FILTER_ATTRS = 983 | 984 | # If the GENERATE_QHP tag is set to YES, the QHG_LOCATION tag can 985 | # be used to specify the location of Qt's qhelpgenerator. 986 | # If non-empty doxygen will try to run qhelpgenerator on the generated 987 | # .qhp file. 988 | 989 | QHG_LOCATION = 990 | 991 | # If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files 992 | # will be generated, which together with the HTML files, form an Eclipse help 993 | # plugin. To install this plugin and make it available under the help contents 994 | # menu in Eclipse, the contents of the directory containing the HTML and XML 995 | # files needs to be copied into the plugins directory of eclipse. The name of 996 | # the directory within the plugins directory should be the same as 997 | # the ECLIPSE_DOC_ID value. After copying Eclipse needs to be restarted before 998 | # the help appears. 999 | 1000 | GENERATE_ECLIPSEHELP = NO 1001 | 1002 | # A unique identifier for the eclipse help plugin. When installing the plugin 1003 | # the directory name containing the HTML and XML files should also have 1004 | # this name. 1005 | 1006 | ECLIPSE_DOC_ID = org.doxygen.Project 1007 | 1008 | # The DISABLE_INDEX tag can be used to turn on/off the condensed index at 1009 | # top of each HTML page. The value NO (the default) enables the index and 1010 | # the value YES disables it. 1011 | 1012 | DISABLE_INDEX = NO 1013 | 1014 | # This tag can be used to set the number of enum values (range [1..20]) 1015 | # that doxygen will group on one line in the generated HTML documentation. 1016 | 1017 | ENUM_VALUES_PER_LINE = 4 1018 | 1019 | # The GENERATE_TREEVIEW tag is used to specify whether a tree-like index 1020 | # structure should be generated to display hierarchical information. 1021 | # If the tag value is set to YES, a side panel will be generated 1022 | # containing a tree-like index structure (just like the one that 1023 | # is generated for HTML Help). For this to work a browser that supports 1024 | # JavaScript, DHTML, CSS and frames is required (i.e. any modern browser). 1025 | # Windows users are probably better off using the HTML help feature. 1026 | 1027 | GENERATE_TREEVIEW = YES 1028 | 1029 | # By enabling USE_INLINE_TREES, doxygen will generate the Groups, Directories, 1030 | # and Class Hierarchy pages using a tree view instead of an ordered list. 1031 | 1032 | USE_INLINE_TREES = NO 1033 | 1034 | # If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be 1035 | # used to set the initial width (in pixels) of the frame in which the tree 1036 | # is shown. 1037 | 1038 | TREEVIEW_WIDTH = 250 1039 | 1040 | # When the EXT_LINKS_IN_WINDOW option is set to YES doxygen will open 1041 | # links to external symbols imported via tag files in a separate window. 1042 | 1043 | EXT_LINKS_IN_WINDOW = NO 1044 | 1045 | # Use this tag to change the font size of Latex formulas included 1046 | # as images in the HTML documentation. The default is 10. Note that 1047 | # when you change the font size after a successful doxygen run you need 1048 | # to manually remove any form_*.png images from the HTML output directory 1049 | # to force them to be regenerated. 1050 | 1051 | FORMULA_FONTSIZE = 10 1052 | 1053 | # Use the FORMULA_TRANPARENT tag to determine whether or not the images 1054 | # generated for formulas are transparent PNGs. Transparent PNGs are 1055 | # not supported properly for IE 6.0, but are supported on all modern browsers. 1056 | # Note that when changing this option you need to delete any form_*.png files 1057 | # in the HTML output before the changes have effect. 1058 | 1059 | FORMULA_TRANSPARENT = YES 1060 | 1061 | # When the SEARCHENGINE tag is enabled doxygen will generate a search box 1062 | # for the HTML output. The underlying search engine uses javascript 1063 | # and DHTML and should work on any modern browser. Note that when using 1064 | # HTML help (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets 1065 | # (GENERATE_DOCSET) there is already a search function so this one should 1066 | # typically be disabled. For large projects the javascript based search engine 1067 | # can be slow, then enabling SERVER_BASED_SEARCH may provide a better solution. 1068 | 1069 | SEARCHENGINE = YES 1070 | 1071 | # When the SERVER_BASED_SEARCH tag is enabled the search engine will be 1072 | # implemented using a PHP enabled web server instead of at the web client 1073 | # using Javascript. Doxygen will generate the search PHP script and index 1074 | # file to put on the web server. The advantage of the server 1075 | # based approach is that it scales better to large projects and allows 1076 | # full text search. The disadvances is that it is more difficult to setup 1077 | # and does not have live searching capabilities. 1078 | 1079 | SERVER_BASED_SEARCH = NO 1080 | 1081 | #--------------------------------------------------------------------------- 1082 | # configuration options related to the LaTeX output 1083 | #--------------------------------------------------------------------------- 1084 | 1085 | # If the GENERATE_LATEX tag is set to YES (the default) Doxygen will 1086 | # generate Latex output. 1087 | 1088 | GENERATE_LATEX = NO 1089 | 1090 | # The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. 1091 | # If a relative path is entered the value of OUTPUT_DIRECTORY will be 1092 | # put in front of it. If left blank `latex' will be used as the default path. 1093 | 1094 | LATEX_OUTPUT = latex 1095 | 1096 | # The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be 1097 | # invoked. If left blank `latex' will be used as the default command name. 1098 | # Note that when enabling USE_PDFLATEX this option is only used for 1099 | # generating bitmaps for formulas in the HTML output, but not in the 1100 | # Makefile that is written to the output directory. 1101 | 1102 | LATEX_CMD_NAME = latex 1103 | 1104 | # The MAKEINDEX_CMD_NAME tag can be used to specify the command name to 1105 | # generate index for LaTeX. If left blank `makeindex' will be used as the 1106 | # default command name. 1107 | 1108 | MAKEINDEX_CMD_NAME = makeindex 1109 | 1110 | # If the COMPACT_LATEX tag is set to YES Doxygen generates more compact 1111 | # LaTeX documents. This may be useful for small projects and may help to 1112 | # save some trees in general. 1113 | 1114 | COMPACT_LATEX = NO 1115 | 1116 | # The PAPER_TYPE tag can be used to set the paper type that is used 1117 | # by the printer. Possible values are: a4, a4wide, letter, legal and 1118 | # executive. If left blank a4wide will be used. 1119 | 1120 | PAPER_TYPE = a4wide 1121 | 1122 | # The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX 1123 | # packages that should be included in the LaTeX output. 1124 | 1125 | EXTRA_PACKAGES = 1126 | 1127 | # The LATEX_HEADER tag can be used to specify a personal LaTeX header for 1128 | # the generated latex document. The header should contain everything until 1129 | # the first chapter. If it is left blank doxygen will generate a 1130 | # standard header. Notice: only use this tag if you know what you are doing! 1131 | 1132 | LATEX_HEADER = 1133 | 1134 | # If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated 1135 | # is prepared for conversion to pdf (using ps2pdf). The pdf file will 1136 | # contain links (just like the HTML output) instead of page references 1137 | # This makes the output suitable for online browsing using a pdf viewer. 1138 | 1139 | PDF_HYPERLINKS = YES 1140 | 1141 | # If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of 1142 | # plain latex in the generated Makefile. Set this option to YES to get a 1143 | # higher quality PDF documentation. 1144 | 1145 | USE_PDFLATEX = YES 1146 | 1147 | # If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode. 1148 | # command to the generated LaTeX files. This will instruct LaTeX to keep 1149 | # running if errors occur, instead of asking the user for help. 1150 | # This option is also used when generating formulas in HTML. 1151 | 1152 | LATEX_BATCHMODE = NO 1153 | 1154 | # If LATEX_HIDE_INDICES is set to YES then doxygen will not 1155 | # include the index chapters (such as File Index, Compound Index, etc.) 1156 | # in the output. 1157 | 1158 | LATEX_HIDE_INDICES = NO 1159 | 1160 | # If LATEX_SOURCE_CODE is set to YES then doxygen will include 1161 | # source code with syntax highlighting in the LaTeX output. 1162 | # Note that which sources are shown also depends on other settings 1163 | # such as SOURCE_BROWSER. 1164 | 1165 | LATEX_SOURCE_CODE = NO 1166 | 1167 | #--------------------------------------------------------------------------- 1168 | # configuration options related to the RTF output 1169 | #--------------------------------------------------------------------------- 1170 | 1171 | # If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output 1172 | # The RTF output is optimized for Word 97 and may not look very pretty with 1173 | # other RTF readers or editors. 1174 | 1175 | GENERATE_RTF = NO 1176 | 1177 | # The RTF_OUTPUT tag is used to specify where the RTF docs will be put. 1178 | # If a relative path is entered the value of OUTPUT_DIRECTORY will be 1179 | # put in front of it. If left blank `rtf' will be used as the default path. 1180 | 1181 | RTF_OUTPUT = rtf 1182 | 1183 | # If the COMPACT_RTF tag is set to YES Doxygen generates more compact 1184 | # RTF documents. This may be useful for small projects and may help to 1185 | # save some trees in general. 1186 | 1187 | COMPACT_RTF = NO 1188 | 1189 | # If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated 1190 | # will contain hyperlink fields. The RTF file will 1191 | # contain links (just like the HTML output) instead of page references. 1192 | # This makes the output suitable for online browsing using WORD or other 1193 | # programs which support those fields. 1194 | # Note: wordpad (write) and others do not support links. 1195 | 1196 | RTF_HYPERLINKS = NO 1197 | 1198 | # Load stylesheet definitions from file. Syntax is similar to doxygen's 1199 | # config file, i.e. a series of assignments. You only have to provide 1200 | # replacements, missing definitions are set to their default value. 1201 | 1202 | RTF_STYLESHEET_FILE = 1203 | 1204 | # Set optional variables used in the generation of an rtf document. 1205 | # Syntax is similar to doxygen's config file. 1206 | 1207 | RTF_EXTENSIONS_FILE = 1208 | 1209 | #--------------------------------------------------------------------------- 1210 | # configuration options related to the man page output 1211 | #--------------------------------------------------------------------------- 1212 | 1213 | # If the GENERATE_MAN tag is set to YES (the default) Doxygen will 1214 | # generate man pages 1215 | 1216 | GENERATE_MAN = NO 1217 | 1218 | # The MAN_OUTPUT tag is used to specify where the man pages will be put. 1219 | # If a relative path is entered the value of OUTPUT_DIRECTORY will be 1220 | # put in front of it. If left blank `man' will be used as the default path. 1221 | 1222 | MAN_OUTPUT = man 1223 | 1224 | # The MAN_EXTENSION tag determines the extension that is added to 1225 | # the generated man pages (default is the subroutine's section .3) 1226 | 1227 | MAN_EXTENSION = .3 1228 | 1229 | # If the MAN_LINKS tag is set to YES and Doxygen generates man output, 1230 | # then it will generate one additional man file for each entity 1231 | # documented in the real man page(s). These additional files 1232 | # only source the real man page, but without them the man command 1233 | # would be unable to find the correct page. The default is NO. 1234 | 1235 | MAN_LINKS = NO 1236 | 1237 | #--------------------------------------------------------------------------- 1238 | # configuration options related to the XML output 1239 | #--------------------------------------------------------------------------- 1240 | 1241 | # If the GENERATE_XML tag is set to YES Doxygen will 1242 | # generate an XML file that captures the structure of 1243 | # the code including all documentation. 1244 | 1245 | GENERATE_XML = NO 1246 | 1247 | # The XML_OUTPUT tag is used to specify where the XML pages will be put. 1248 | # If a relative path is entered the value of OUTPUT_DIRECTORY will be 1249 | # put in front of it. If left blank `xml' will be used as the default path. 1250 | 1251 | XML_OUTPUT = xml 1252 | 1253 | # The XML_SCHEMA tag can be used to specify an XML schema, 1254 | # which can be used by a validating XML parser to check the 1255 | # syntax of the XML files. 1256 | 1257 | XML_SCHEMA = 1258 | 1259 | # The XML_DTD tag can be used to specify an XML DTD, 1260 | # which can be used by a validating XML parser to check the 1261 | # syntax of the XML files. 1262 | 1263 | XML_DTD = 1264 | 1265 | # If the XML_PROGRAMLISTING tag is set to YES Doxygen will 1266 | # dump the program listings (including syntax highlighting 1267 | # and cross-referencing information) to the XML output. Note that 1268 | # enabling this will significantly increase the size of the XML output. 1269 | 1270 | XML_PROGRAMLISTING = YES 1271 | 1272 | #--------------------------------------------------------------------------- 1273 | # configuration options for the AutoGen Definitions output 1274 | #--------------------------------------------------------------------------- 1275 | 1276 | # If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will 1277 | # generate an AutoGen Definitions (see autogen.sf.net) file 1278 | # that captures the structure of the code including all 1279 | # documentation. Note that this feature is still experimental 1280 | # and incomplete at the moment. 1281 | 1282 | GENERATE_AUTOGEN_DEF = NO 1283 | 1284 | #--------------------------------------------------------------------------- 1285 | # configuration options related to the Perl module output 1286 | #--------------------------------------------------------------------------- 1287 | 1288 | # If the GENERATE_PERLMOD tag is set to YES Doxygen will 1289 | # generate a Perl module file that captures the structure of 1290 | # the code including all documentation. Note that this 1291 | # feature is still experimental and incomplete at the 1292 | # moment. 1293 | 1294 | GENERATE_PERLMOD = NO 1295 | 1296 | # If the PERLMOD_LATEX tag is set to YES Doxygen will generate 1297 | # the necessary Makefile rules, Perl scripts and LaTeX code to be able 1298 | # to generate PDF and DVI output from the Perl module output. 1299 | 1300 | PERLMOD_LATEX = NO 1301 | 1302 | # If the PERLMOD_PRETTY tag is set to YES the Perl module output will be 1303 | # nicely formatted so it can be parsed by a human reader. 1304 | # This is useful 1305 | # if you want to understand what is going on. 1306 | # On the other hand, if this 1307 | # tag is set to NO the size of the Perl module output will be much smaller 1308 | # and Perl will parse it just the same. 1309 | 1310 | PERLMOD_PRETTY = YES 1311 | 1312 | # The names of the make variables in the generated doxyrules.make file 1313 | # are prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. 1314 | # This is useful so different doxyrules.make files included by the same 1315 | # Makefile don't overwrite each other's variables. 1316 | 1317 | PERLMOD_MAKEVAR_PREFIX = 1318 | 1319 | #--------------------------------------------------------------------------- 1320 | # Configuration options related to the preprocessor 1321 | #--------------------------------------------------------------------------- 1322 | 1323 | # If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will 1324 | # evaluate all C-preprocessor directives found in the sources and include 1325 | # files. 1326 | 1327 | ENABLE_PREPROCESSING = YES 1328 | 1329 | # If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro 1330 | # names in the source code. If set to NO (the default) only conditional 1331 | # compilation will be performed. Macro expansion can be done in a controlled 1332 | # way by setting EXPAND_ONLY_PREDEF to YES. 1333 | 1334 | MACRO_EXPANSION = NO 1335 | 1336 | # If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES 1337 | # then the macro expansion is limited to the macros specified with the 1338 | # PREDEFINED and EXPAND_AS_DEFINED tags. 1339 | 1340 | EXPAND_ONLY_PREDEF = NO 1341 | 1342 | # If the SEARCH_INCLUDES tag is set to YES (the default) the includes files 1343 | # in the INCLUDE_PATH (see below) will be search if a #include is found. 1344 | 1345 | SEARCH_INCLUDES = YES 1346 | 1347 | # The INCLUDE_PATH tag can be used to specify one or more directories that 1348 | # contain include files that are not input files but should be processed by 1349 | # the preprocessor. 1350 | 1351 | INCLUDE_PATH = 1352 | 1353 | # You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard 1354 | # patterns (like *.h and *.hpp) to filter out the header-files in the 1355 | # directories. If left blank, the patterns specified with FILE_PATTERNS will 1356 | # be used. 1357 | 1358 | INCLUDE_FILE_PATTERNS = 1359 | 1360 | # The PREDEFINED tag can be used to specify one or more macro names that 1361 | # are defined before the preprocessor is started (similar to the -D option of 1362 | # gcc). The argument of the tag is a list of macros of the form: name 1363 | # or name=definition (no spaces). If the definition and the = are 1364 | # omitted =1 is assumed. To prevent a macro definition from being 1365 | # undefined via #undef or recursively expanded use the := operator 1366 | # instead of the = operator. 1367 | 1368 | PREDEFINED = 1369 | 1370 | # If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then 1371 | # this tag can be used to specify a list of macro names that should be expanded. 1372 | # The macro definition that is found in the sources will be used. 1373 | # Use the PREDEFINED tag if you want to use a different macro definition. 1374 | 1375 | EXPAND_AS_DEFINED = 1376 | 1377 | # If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then 1378 | # doxygen's preprocessor will remove all function-like macros that are alone 1379 | # on a line, have an all uppercase name, and do not end with a semicolon. Such 1380 | # function macros are typically used for boiler-plate code, and will confuse 1381 | # the parser if not removed. 1382 | 1383 | SKIP_FUNCTION_MACROS = YES 1384 | 1385 | #--------------------------------------------------------------------------- 1386 | # Configuration::additions related to external references 1387 | #--------------------------------------------------------------------------- 1388 | 1389 | # The TAGFILES option can be used to specify one or more tagfiles. 1390 | # Optionally an initial location of the external documentation 1391 | # can be added for each tagfile. The format of a tag file without 1392 | # this location is as follows: 1393 | # 1394 | # TAGFILES = file1 file2 ... 1395 | # Adding location for the tag files is done as follows: 1396 | # 1397 | # TAGFILES = file1=loc1 "file2 = loc2" ... 1398 | # where "loc1" and "loc2" can be relative or absolute paths or 1399 | # URLs. If a location is present for each tag, the installdox tool 1400 | # does not have to be run to correct the links. 1401 | # Note that each tag file must have a unique name 1402 | # (where the name does NOT include the path) 1403 | # If a tag file is not located in the directory in which doxygen 1404 | # is run, you must also specify the path to the tagfile here. 1405 | 1406 | TAGFILES = 1407 | 1408 | # When a file name is specified after GENERATE_TAGFILE, doxygen will create 1409 | # a tag file that is based on the input files it reads. 1410 | 1411 | GENERATE_TAGFILE = 1412 | 1413 | # If the ALLEXTERNALS tag is set to YES all external classes will be listed 1414 | # in the class index. If set to NO only the inherited external classes 1415 | # will be listed. 1416 | 1417 | ALLEXTERNALS = NO 1418 | 1419 | # If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed 1420 | # in the modules index. If set to NO, only the current project's groups will 1421 | # be listed. 1422 | 1423 | EXTERNAL_GROUPS = YES 1424 | 1425 | # The PERL_PATH should be the absolute path and name of the perl script 1426 | # interpreter (i.e. the result of `which perl'). 1427 | 1428 | PERL_PATH = /usr/bin/perl 1429 | 1430 | #--------------------------------------------------------------------------- 1431 | # Configuration options related to the dot tool 1432 | #--------------------------------------------------------------------------- 1433 | 1434 | # If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will 1435 | # generate a inheritance diagram (in HTML, RTF and LaTeX) for classes with base 1436 | # or super classes. Setting the tag to NO turns the diagrams off. Note that 1437 | # this option is superseded by the HAVE_DOT option below. This is only a 1438 | # fallback. It is recommended to install and use dot, since it yields more 1439 | # powerful graphs. 1440 | 1441 | CLASS_DIAGRAMS = YES 1442 | 1443 | # You can define message sequence charts within doxygen comments using the \msc 1444 | # command. Doxygen will then run the mscgen tool (see 1445 | # http://www.mcternan.me.uk/mscgen/) to produce the chart and insert it in the 1446 | # documentation. The MSCGEN_PATH tag allows you to specify the directory where 1447 | # the mscgen tool resides. If left empty the tool is assumed to be found in the 1448 | # default search path. 1449 | 1450 | MSCGEN_PATH = 1451 | 1452 | # If set to YES, the inheritance and collaboration graphs will hide 1453 | # inheritance and usage relations if the target is undocumented 1454 | # or is not a class. 1455 | 1456 | HIDE_UNDOC_RELATIONS = YES 1457 | 1458 | # If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is 1459 | # available from the path. This tool is part of Graphviz, a graph visualization 1460 | # toolkit from AT&T and Lucent Bell Labs. The other options in this section 1461 | # have no effect if this option is set to NO (the default) 1462 | 1463 | HAVE_DOT = NO 1464 | 1465 | # The DOT_NUM_THREADS specifies the number of dot invocations doxygen is 1466 | # allowed to run in parallel. When set to 0 (the default) doxygen will 1467 | # base this on the number of processors available in the system. You can set it 1468 | # explicitly to a value larger than 0 to get control over the balance 1469 | # between CPU load and processing speed. 1470 | 1471 | DOT_NUM_THREADS = 0 1472 | 1473 | # By default doxygen will write a font called FreeSans.ttf to the output 1474 | # directory and reference it in all dot files that doxygen generates. This 1475 | # font does not include all possible unicode characters however, so when you need 1476 | # these (or just want a differently looking font) you can specify the font name 1477 | # using DOT_FONTNAME. You need need to make sure dot is able to find the font, 1478 | # which can be done by putting it in a standard location or by setting the 1479 | # DOTFONTPATH environment variable or by setting DOT_FONTPATH to the directory 1480 | # containing the font. 1481 | 1482 | DOT_FONTNAME = FreeSans.ttf 1483 | 1484 | # The DOT_FONTSIZE tag can be used to set the size of the font of dot graphs. 1485 | # The default size is 10pt. 1486 | 1487 | DOT_FONTSIZE = 10 1488 | 1489 | # By default doxygen will tell dot to use the output directory to look for the 1490 | # FreeSans.ttf font (which doxygen will put there itself). If you specify a 1491 | # different font using DOT_FONTNAME you can set the path where dot 1492 | # can find it using this tag. 1493 | 1494 | DOT_FONTPATH = 1495 | 1496 | # If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen 1497 | # will generate a graph for each documented class showing the direct and 1498 | # indirect inheritance relations. Setting this tag to YES will force the 1499 | # the CLASS_DIAGRAMS tag to NO. 1500 | 1501 | CLASS_GRAPH = YES 1502 | 1503 | # If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen 1504 | # will generate a graph for each documented class showing the direct and 1505 | # indirect implementation dependencies (inheritance, containment, and 1506 | # class references variables) of the class with other documented classes. 1507 | 1508 | COLLABORATION_GRAPH = YES 1509 | 1510 | # If the GROUP_GRAPHS and HAVE_DOT tags are set to YES then doxygen 1511 | # will generate a graph for groups, showing the direct groups dependencies 1512 | 1513 | GROUP_GRAPHS = YES 1514 | 1515 | # If the UML_LOOK tag is set to YES doxygen will generate inheritance and 1516 | # collaboration diagrams in a style similar to the OMG's Unified Modeling 1517 | # Language. 1518 | 1519 | UML_LOOK = NO 1520 | 1521 | # If set to YES, the inheritance and collaboration graphs will show the 1522 | # relations between templates and their instances. 1523 | 1524 | TEMPLATE_RELATIONS = NO 1525 | 1526 | # If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT 1527 | # tags are set to YES then doxygen will generate a graph for each documented 1528 | # file showing the direct and indirect include dependencies of the file with 1529 | # other documented files. 1530 | 1531 | INCLUDE_GRAPH = YES 1532 | 1533 | # If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and 1534 | # HAVE_DOT tags are set to YES then doxygen will generate a graph for each 1535 | # documented header file showing the documented files that directly or 1536 | # indirectly include this file. 1537 | 1538 | INCLUDED_BY_GRAPH = YES 1539 | 1540 | # If the CALL_GRAPH and HAVE_DOT options are set to YES then 1541 | # doxygen will generate a call dependency graph for every global function 1542 | # or class method. Note that enabling this option will significantly increase 1543 | # the time of a run. So in most cases it will be better to enable call graphs 1544 | # for selected functions only using the \callgraph command. 1545 | 1546 | CALL_GRAPH = NO 1547 | 1548 | # If the CALLER_GRAPH and HAVE_DOT tags are set to YES then 1549 | # doxygen will generate a caller dependency graph for every global function 1550 | # or class method. Note that enabling this option will significantly increase 1551 | # the time of a run. So in most cases it will be better to enable caller 1552 | # graphs for selected functions only using the \callergraph command. 1553 | 1554 | CALLER_GRAPH = NO 1555 | 1556 | # If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen 1557 | # will graphical hierarchy of all classes instead of a textual one. 1558 | 1559 | GRAPHICAL_HIERARCHY = YES 1560 | 1561 | # If the DIRECTORY_GRAPH, SHOW_DIRECTORIES and HAVE_DOT tags are set to YES 1562 | # then doxygen will show the dependencies a directory has on other directories 1563 | # in a graphical way. The dependency relations are determined by the #include 1564 | # relations between the files in the directories. 1565 | 1566 | DIRECTORY_GRAPH = YES 1567 | 1568 | # The DOT_IMAGE_FORMAT tag can be used to set the image format of the images 1569 | # generated by dot. Possible values are png, jpg, or gif 1570 | # If left blank png will be used. 1571 | 1572 | DOT_IMAGE_FORMAT = png 1573 | 1574 | # The tag DOT_PATH can be used to specify the path where the dot tool can be 1575 | # found. If left blank, it is assumed the dot tool can be found in the path. 1576 | 1577 | DOT_PATH = 1578 | 1579 | # The DOTFILE_DIRS tag can be used to specify one or more directories that 1580 | # contain dot files that are included in the documentation (see the 1581 | # \dotfile command). 1582 | 1583 | DOTFILE_DIRS = 1584 | 1585 | # The DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of 1586 | # nodes that will be shown in the graph. If the number of nodes in a graph 1587 | # becomes larger than this value, doxygen will truncate the graph, which is 1588 | # visualized by representing a node as a red box. Note that doxygen if the 1589 | # number of direct children of the root node in a graph is already larger than 1590 | # DOT_GRAPH_MAX_NODES then the graph will not be shown at all. Also note 1591 | # that the size of a graph can be further restricted by MAX_DOT_GRAPH_DEPTH. 1592 | 1593 | DOT_GRAPH_MAX_NODES = 50 1594 | 1595 | # The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the 1596 | # graphs generated by dot. A depth value of 3 means that only nodes reachable 1597 | # from the root by following a path via at most 3 edges will be shown. Nodes 1598 | # that lay further from the root node will be omitted. Note that setting this 1599 | # option to 1 or 2 may greatly reduce the computation time needed for large 1600 | # code bases. Also note that the size of a graph can be further restricted by 1601 | # DOT_GRAPH_MAX_NODES. Using a depth of 0 means no depth restriction. 1602 | 1603 | MAX_DOT_GRAPH_DEPTH = 0 1604 | 1605 | # Set the DOT_TRANSPARENT tag to YES to generate images with a transparent 1606 | # background. This is disabled by default, because dot on Windows does not 1607 | # seem to support this out of the box. Warning: Depending on the platform used, 1608 | # enabling this option may lead to badly anti-aliased labels on the edges of 1609 | # a graph (i.e. they become hard to read). 1610 | 1611 | DOT_TRANSPARENT = NO 1612 | 1613 | # Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output 1614 | # files in one run (i.e. multiple -o and -T options on the command line). This 1615 | # makes dot run faster, but since only newer versions of dot (>1.8.10) 1616 | # support this, this feature is disabled by default. 1617 | 1618 | DOT_MULTI_TARGETS = YES 1619 | 1620 | # If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will 1621 | # generate a legend page explaining the meaning of the various boxes and 1622 | # arrows in the dot generated graphs. 1623 | 1624 | GENERATE_LEGEND = YES 1625 | 1626 | # If the DOT_CLEANUP tag is set to YES (the default) Doxygen will 1627 | # remove the intermediate dot files that are used to generate 1628 | # the various graphs. 1629 | 1630 | DOT_CLEANUP = YES 1631 | -------------------------------------------------------------------------------- /doc/hostapd.dox: -------------------------------------------------------------------------------- 1 | /** 2 | 3 | @defgroup hostapd hostapd Configuration 4 | 5 | @c hostapd is the de-facto user 6 | space daemon for 802.11 access point and authentication servers. It implements 7 | IEEE 802.11 access point (AP) management, IEEE 802.1X/WPA/WPA2/EAP 8 | Authenticators, RADIUS client, EAP server, and RADIUS authentication server. @c 9 | hostapd is used from embedded commercial systems (Wi-Fi access points, etc.) to 10 | commodity desktop computers. Since WAPI is all about providing access to 11 | wireless device configurations, one might expect WAPI to work with @c hostapd as 12 | well. But, as of time of this writing, this is practically impossible due to 13 | technical limitations. 14 | 15 | @note One would desire to change AP configurations on-the-fly without losing 16 | established connections. Despite this scheme is supported by 802.11, it is not 17 | currently provided by hostapd. (See Changing 19 | Channel On-The-Fly.) You are warned. 20 | 21 | @c hostapd is designed as a standalone application and doesn't allow external 22 | programs to play with the configurations of wireless device it is currently 23 | operating at. Moreover, the decions (e.g. channel change) made by @c hostapd 24 | generally cannot be observed by external applications. (See SIGHUP 26 | and iwconfig channel anomaly.) For this purpose, there are two ways to 27 | communicate with @c hostapd to alter wireless device configurations. 28 | 29 | @section hostapdconffile Accessing hostapd Through hostapd.conf 30 | 31 | This is the most straightforward method to communicate with @c hostapd. Steps 32 | are, as expected, trivial: 33 | 34 | -# Read configurations from @c /etc/hostapd/hostapd.conf. 35 | -# Make necessary changes to the read configurations and write them back. 36 | -# Send a @c SIGHUP to @c hostapd process. (You can use @c /var/run/hostapd.pid 37 | file.) 38 | 39 | Below is a sample C++ code (see @c examples/hostapd.cpp) implementing this 40 | method. 41 | 42 | @include hostapd.cpp 43 | 44 | @section hostapdwpactrl Accessing hostapd Through Control Interface 45 | 46 | @c hostapd provides a control 48 | interface that can be used by external programs to control the operations of 49 | the hostapd daemon and to get status information and event notifications. There 50 | is a small C library, in a form of a single C file, @c wpa_ctrl.c, that provides 51 | helper functions to facilitate the use of the control interface. External 52 | programs can link this file into them and then use the library functions 53 | documented in @c wpa_ctrl.h to interact with @c hostapd. 54 | 55 | However, as of time of this writing, @c hostapd control interface commands lack 56 | documentation and are not that easy to implement compared to the straightforward 57 | approach given above. At the moment neither us, nor @c hostapd guys provide any 58 | entrance level examples regarding this control interface. You might want to 59 | check out hostapd_cli.c 61 | in the @c hostapd sources. 62 | 63 | @section recover Recovering Client Associations 64 | 65 | As noted above, hostapd doesn't preserve associated connections after a 66 | configuration change on-the-fly. For this purpose, you can recover the 67 | associations from client side by searching for the same ESSID/AP and then 68 | switching back to new AP configurations. @c examples/recover.c implements a 69 | similar trick: 70 | 71 | @include recover.c 72 | 73 | */ 74 | -------------------------------------------------------------------------------- /doc/main.dox: -------------------------------------------------------------------------------- 1 | /** 2 | 3 | @mainpage Wireless API (WAPI) 4 | 5 | WAPI provides an easy-to-use function 6 | set to configure wireless network interfaces in a GNU/Linux system. One can 7 | think WAPI as a lightweight C API for @c iwconfig, @c wlanconfig, @c ifconfig, 8 | and @c route commands. (But it is not a thin wrapper for these command line 9 | tools.) It is currently being used in WISERLAB test-bed to 12 | configure 802.11 based wireless interfaces. The development is partially 13 | supported by European Commission Grant Number PIRG06-GA-2009-256326. 14 | 15 | For @c iwconfig, @c ifconfig, and @c route command functionalities, WAPI issues 16 | same set of ioctl() calls to the netlink kernel. While @c ifconfig and @c route 17 | doesn't have that many ad-hoc hacks for backward compatibility issues, @c 18 | iwconfig is messed with dozens of such stuff in all around the code. In WAPI, we 19 | try to avoid all such hacks and target recent hardware and kernel versions 20 | (>2.6). But most of the time, it should just work fine. For virtual (wireless) 21 | interface management, we rely on nl80211 23 | netlink interface. (Which is actually intended to replace Wireless Extensions.) 24 | 25 | 26 | @section dload Download 27 | 28 | You can track the changes and obtain the sources from http://github.com/vy/wapi address. You can 30 | also directly download the sources of the most recent version from here (wapi-0.1.tar.gz) as well. SCons, wireless-tools, 34 | and libnl packages are 35 | required to compile the sources. 36 | 37 | 38 | @section faq Frequently Asked Questions 39 | 40 | 41 | @subsection whatiswapi What is WAPI? 42 | 43 | WAPI is a C library that provides a developer friendly API to a majority of the 44 | network interface configurations in a GNU/Linux system. One can think it as an 45 | interface to the ifconfig, iwconfig, route, and wlanconfig command line tools. 46 | But WAPI just shares the functionality of these tools, nothing more. That is, 47 | instead of calling ifconfig, etc. and parsing its console output, WAPI directly 48 | communicates with the Linux kernel via appropriate ioctl() and nl80211 interface 49 | calls. 50 | 51 | 52 | @subsection whatareothers What are other similar projects? 53 | 54 | There is just iwlib of wireless-tools project, which just provides access to 55 | some of the wireless network interface configurations. There are no other 56 | libraries for ifconfig, route, and wlanconfig functionalities. 57 | 58 | @subsection whatisiwlib What is wrong with iwlib? 59 | 60 | Honestly, for the configuration of wireless network interfaces, iwlib is nearly 61 | a swiss army knife. But the problem is, it is just restricted to wireless 62 | network interfaces and suffers from some performance problems. (That is, if you 63 | just want to change the operating frequency of your wireless device and using 64 | iwlib, you must first collect all of its available configurations, just update 65 | frequency in there, and write back all available configurations to driver again. 66 | In other words, no attribute specific access.) And considering its age, iwlib 67 | code base is bloated with backwards compatibility hacks in everywhere. Being 68 | said that, WAPI still uses iwlib for some particular operations. (For instance, 69 | while parsing event streams supplied by WEXT module.) 70 | 71 | @subsection whatisnl80211 Why not using nl80211? 72 | 73 | nl80211 is the new 802.11 netlink interface for Linux kernel. For particular 74 | feature sets (e.g. virtual interface management) we rely on nl80211. While 75 | nl80211 is quite mature, it doesn't support as many devices as wext does. But it 76 | would be a good TODO item to port all wireless interface related ioctl() calls 77 | to their nl80211 correspondents. 78 | 79 | @subsection wapifeatures Does WAPI provides all available feature sets? 80 | 81 | Ofcourse, not. (At least not at this point.) WAPI is just designed to meet our 82 | research needs. If you need any other feature implementations, just drop me a 83 | mail. 84 | 85 | @subsection openwrt Can I integrate WAPI to OpenWrt as well? 86 | 87 | Sure! Just see @c Makefile.OpenWrt in the root directory. 88 | 89 | @subsection foundbug I found a bug. What then? 90 | 91 | Just report me via e-mail. (A detailed explanation to reproduce the problem 92 | would be awesome.) I will try to fix it ASAP. 93 | 94 | */ 95 | -------------------------------------------------------------------------------- /doc/presentation/Makefile: -------------------------------------------------------------------------------- 1 | TEXNAME = slide 2 | TARGET = $(TEXNAME).pdf 3 | IMGFILES = dox1.jpg dox2.jpg dox3.jpg dox4.jpg feeling-lucky.jpg 4 | TMPFILES = \ 5 | $(TEXNAME).aux \ 6 | $(TEXNAME).log \ 7 | $(TEXNAME).nav \ 8 | $(TEXNAME).out \ 9 | $(TEXNAME).snm \ 10 | $(TEXNAME).vrb \ 11 | $(TEXNAME).toc 12 | 13 | %.pdf: %.tex 14 | pdflatex -halt-on-error $< $@ 15 | pdflatex -halt-on-error $< $@ 16 | 17 | all: $(IMGFILES) $(TARGET) 18 | 19 | cleantemp: 20 | rm -f $(TMPFILES) 21 | 22 | clean: cleantemp 23 | rm -f $(TARGET) 24 | 25 | .PHONY: all clean cleantemp 26 | -------------------------------------------------------------------------------- /doc/presentation/dox1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vy/wapi/a191c7828c818834874a2768ad76d3bc8e207f29/doc/presentation/dox1.jpg -------------------------------------------------------------------------------- /doc/presentation/dox2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vy/wapi/a191c7828c818834874a2768ad76d3bc8e207f29/doc/presentation/dox2.jpg -------------------------------------------------------------------------------- /doc/presentation/dox3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vy/wapi/a191c7828c818834874a2768ad76d3bc8e207f29/doc/presentation/dox3.jpg -------------------------------------------------------------------------------- /doc/presentation/dox4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vy/wapi/a191c7828c818834874a2768ad76d3bc8e207f29/doc/presentation/dox4.jpg -------------------------------------------------------------------------------- /doc/presentation/feeling-lucky.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vy/wapi/a191c7828c818834874a2768ad76d3bc8e207f29/doc/presentation/feeling-lucky.jpg -------------------------------------------------------------------------------- /doc/presentation/slide.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vy/wapi/a191c7828c818834874a2768ad76d3bc8e207f29/doc/presentation/slide.pdf -------------------------------------------------------------------------------- /doc/presentation/slide.tex: -------------------------------------------------------------------------------- 1 | \documentclass[turkish,12pt,red,compress,mathserif]{beamer} 2 | \usepackage[utf8]{inputenc} 3 | \usepackage{verbatim} 4 | \usepackage{listings} 5 | \usepackage{url} 6 | 7 | \usetheme{Warsaw} 8 | \setbeamertemplate{navigation symbols}{} 9 | \setbeamertemplate{footline}[page number] 10 | \lstset{basicstyle=\tiny,showstringspaces=false} 11 | 12 | \title{A Generic C/C++ API \\ 13 | for Wireless Interfaces \\ 14 | in GNU/Linux Systems} 15 | \author{Volkan Yazıcı \\ 16 | Özyeğin University \\ 17 | Dept. of Electrical \& Electronics Engineering \\ 18 | \emph{volkan.yazici@ozyegin.edu.tr}} 19 | 20 | \date[Fall 2010]{WISERLAB Group Meeting, İstanbul, 2010} 21 | 22 | \begin{document} 23 | 24 | \begin{frame}\titlepage\end{frame} 25 | \begin{frame}\tableofcontents\end{frame} 26 | 27 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 28 | 29 | \section{Intro.} 30 | 31 | %------------------------------------------------------------------------------- 32 | 33 | \subsection{Motivation} 34 | 35 | \begin{frame}{Motivation} 36 | \begin{itemize} 37 | \item A generic C/C++ API for network interfaces. 38 | \begin{itemize} 39 | \item Almost full coverage of wireless network configurations. 40 | \begin{itemize} 41 | \item \texttt{iwconfig} 42 | \item \texttt{iwlist} 43 | \item \texttt{wlanconfig} 44 | \end{itemize} 45 | \item Generic network interface operations. 46 | \begin{itemize} 47 | \item \texttt{ifconfig} 48 | \item \texttt{route} 49 | \end{itemize} 50 | \end{itemize} 51 | \item A \alert{library}, not a command line tool. 52 | \item A core component of the \alert{Connectivity Brokerage}. 53 | \end{itemize} 54 | \end{frame} 55 | 56 | %------------------------------------------------------------------------------- 57 | 58 | \subsection{Literature} 59 | 60 | \begin{frame}{Literature} 61 | \begin{itemize} 62 | \item A majority of the previous works were basically parsing command (e.g. 63 | \texttt{iwlist}) outputs. 64 | \item Accessing command line tools within a program execution flow is 65 | dangerous and not convenient. 66 | \begin{itemize} 67 | \item Command outputs are unreliable. 68 | \begin{itemize} 69 | \item High possibility of unknown outputs (bugs). 70 | \item Hard to be in sync. with every release. 71 | \item Requires a significant amount of work to parse and extract certain 72 | tokens. 73 | \end{itemize} 74 | \end{itemize} 75 | \end{itemize} 76 | \end{frame} 77 | 78 | \begin{frame}{Literature (Cont'd)} 79 | \begin{itemize} 80 | \item Other libraries with similar goals: 81 | \begin{itemize} 82 | \item \texttt{libiw} of Wireless Tools for Linux, 83 | \item \texttt{libnm} of NetworkManager. 84 | \end{itemize} 85 | \item Cons: 86 | \begin{itemize} 87 | \item not designed for embedded environments (library dependencies), 88 | \item function calls are blocking, 89 | \item lacks ifup/ifdown and routing table functionalities, 90 | \item no fine-grained access to the configurations, 91 | \item doesn't provide an easy to use unified API. 92 | \end{itemize} 93 | \end{itemize} 94 | \end{frame} 95 | 96 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 97 | 98 | \section{Contrib.} 99 | 100 | \begin{frame}{Contribution} 101 | \begin{itemize} 102 | \item a \textbf{unified C/C++ library} with on par features compared to 103 | \texttt{iwconfig}, \texttt{iwlist}, \texttt{wlanconfig}, \texttt{ifconfig}, 104 | \texttt{route} tools. 105 | \item not yet another command wrapper, but a written from scratch library 106 | accessing network drivers through \textbf{\texttt{ioctl()} calls to the 107 | kernel} and \textbf{nl80211} netlink. 108 | \item \textbf{fine-grained access}, that is, just get/set a single property at 109 | a time. 110 | \item \textbf{non-blocking function calls}. 111 | \item code base is not bloated with 10 year old backward compatibility issues. 112 | \item fully \textbf{documented, clean code}; suitable for research \& 113 | education purposes. 114 | \end{itemize} 115 | \end{frame} 116 | 117 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 118 | 119 | \section{Status} 120 | 121 | \subsection{Where Are We?} 122 | 123 | \begin{frame}{Where Are We?} 124 | \begin{itemize} 125 | \item \textbf{Finished!} 126 | \begin{itemize} 127 | \item Website \& Docs.: \url{http://vy.github.com/wapi/} 128 | \item Source Code: \url{http://www.github.com/vy/wapi/} 129 | \end{itemize} 130 | \item Tested on various hardware. (Atheros, Broadcom, etc.) 131 | \item Fully documented code base. (Thanks Doxygen.) 132 | \item Now available as an \textbf{official OpenWrt package}! 133 | \end{itemize} 134 | \end{frame} 135 | 136 | %------------------------------------------------------------------------------- 137 | 138 | \subsection{hostapd} 139 | 140 | \begin{frame}{hostapd} 141 | \begin{itemize} 142 | \item We can alter client side configurations? 143 | \item What about AP side? 144 | \item \texttt{hostapd} is the de-facto user space daemon, 145 | \item but provides restrictions in terms of access: 146 | \begin{itemize} 147 | \item You are not allowed to externally alter the configurations of wireless 148 | devices that are allocated by \texttt{hostapd}. 149 | \item Access to \texttt{hostapd} is allowed in two ways: 150 | \begin{itemize} 151 | \item \texttt{hostapd} control interface (undocumented) 152 | \item \texttt{hostapd.conf} (in machine-readable, mature format) 153 | \end{itemize} 154 | \end{itemize} 155 | \end{itemize} 156 | \end{frame} 157 | 158 | %------------------------------------------------------------------------------- 159 | 160 | \subsection{Roadmap} 161 | 162 | \begin{frame}{Roadmap} 163 | \begin{itemize} 164 | \item Get rid off \texttt{libiw} dependency. 165 | \begin{itemize} 166 | \item Because of a race-condition bug in \texttt{nl80211}, delayed for a 167 | while. 168 | \end{itemize} 169 | \end{itemize} 170 | \end{frame} 171 | 172 | 173 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 174 | 175 | \section{Demo} 176 | 177 | %------------------------------------------------------------------------------- 178 | 179 | \subsection{Getters} 180 | 181 | \begin{frame}[fragile]{Getters: Source Code} 182 | \begin{lstlisting}[language=c] 183 | int ret; 184 | double freq; 185 | wapi_freq_flag_t freq_flag; 186 | char essid[WAPI_ESSID_MAX_SIZE + 1]; 187 | wapi_essid_flag_t essid_flag; 188 | 189 | ... 190 | 191 | /* freq */ 192 | ret = wapi_get_freq(sock, ifname, &freq, &freq_flag); 193 | printf("freq: %g\n", freq); 194 | printf("freq_flags: %s\n", wapi_freq_flags[freq_flag]); 195 | 196 | /* essid */ 197 | ret = wapi_get_essid(sock, ifname, essid, &essid_flag); 198 | printf("essid: %s\n", essid); 199 | printf("essid_flag: %s\n", wapi_essid_flags[essid_flag]); 200 | 201 | ... 202 | \end{lstlisting} 203 | \end{frame} 204 | 205 | \begin{frame}[fragile]{Getters: Output} 206 | \begin{lstlisting} 207 | ip: 192.168.1.111 208 | netmask: 255.255.255.0 209 | freq: 2.412e+09 210 | freq_flag: WAPI_FREQ_AUTO 211 | chan: 1 212 | freq: 2.412e+09 213 | essid: ozu 214 | essid_flag: WAPI_ESSID_ON 215 | mode: WAPI_MODE_MANAGED 216 | ap: 00:14:C1:34:CE:83 217 | wireless.c:451:wapi_get_bitrate(): Bitrate is disabled. 218 | wireless.c:546:wapi_get_txpower():ioctl(SIOCGIWTXPOW): Invalid argument 219 | \end{lstlisting} 220 | \end{frame} 221 | 222 | %------------------------------------------------------------------------------- 223 | 224 | \subsection{Scanning} 225 | 226 | \begin{frame}[fragile]{Scanning: Source Code} 227 | \begin{lstlisting}[language=c] 228 | int sleepdur = 1; 229 | int sleeptries = 5; 230 | wapi_list_t list; 231 | wapi_scan_info_t *info; 232 | int ret; 233 | 234 | /* start scan */ 235 | ret = wapi_scan_init(sock, ifname); 236 | printf("wapi_scan_init(): ret: %d\n", ret); 237 | 238 | /* wait for completion */ 239 | do { 240 | sleep(sleepdur); 241 | ret = wapi_scan_stat(sock, ifname); 242 | printf("wapi_scan_stat(): ret: %d, sleeptries: %d\n", ret, sleeptries); 243 | } while (--sleeptries > 0 && ret > 0); 244 | if (ret < 0) return; 245 | 246 | /* collect results */ 247 | bzero(&list, sizeof(wapi_list_t)); 248 | ret = wapi_scan_coll(sock, ifname, &list); 249 | printf("wapi_scan_coll(): ret: %d\n", ret); 250 | 251 | /* print found aps */ 252 | for (info = list.head.scan; info; info = info->next) 253 | printf(">> @%xl %s\n", (size_t) info, (info->has_essid ? info->essid : "")); 254 | \end{lstlisting} 255 | \end{frame} 256 | 257 | \begin{frame}[fragile]{Scanning: Output} 258 | \begin{lstlisting} 259 | wapi_scan_init(): ret: 0 260 | wapi_scan_stat(): ret: 1, sleeptries: 5 261 | wapi_scan_stat(): ret: 0, sleeptries: 4 262 | wapi_scan_coll(): ret: 0 263 | >> @8214ce8l OzuNet.Visitors 264 | >> @8214c90l Wozunacad 265 | >> @8214c38l OzuNet.Visitors 266 | >> @8214be0l canbazoglu 267 | >> @8214b88l NWii 268 | >> @8214b30l wozunguest 269 | >> @8214ad8l Wozunacad 270 | >> @8214a80l ZQNET29 271 | >> @8214a28l wozunvisitor 272 | >> ... 273 | \end{lstlisting} 274 | \end{frame} 275 | 276 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 277 | 278 | \section{Doc.} 279 | 280 | \begin{frame}{Doxygen} 281 | \begin{itemize} 282 | \item All available public API (functions, variables, constants, structs, 283 | enums, etc.) is fully documented. 284 | \item Driver specific turnarounds are documented. 285 | \item All documentation is integrated within the source code itself as comment 286 | lines. 287 | \item Using Doxygen to produce HTML, LaTeX, RTF, etc. output from these 288 | comment lines. 289 | \end{itemize} 290 | \end{frame} 291 | 292 | \begin{frame} 293 | \centering\includegraphics[width=\textwidth]{dox1.jpg} 294 | \end{frame} 295 | 296 | \begin{frame} 297 | \centering\includegraphics[width=\textwidth]{dox2.jpg} 298 | \end{frame} 299 | 300 | \begin{frame} 301 | \centering\includegraphics[width=\textwidth]{dox3.jpg} 302 | \end{frame} 303 | 304 | \begin{frame} 305 | \centering\includegraphics[width=\textwidth]{dox4.jpg} 306 | \end{frame} 307 | 308 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 309 | 310 | \section{Questions} 311 | 312 | \begin{frame}{Questions?} 313 | \begin{figure} 314 | \centering\includegraphics{feeling-lucky.jpg} 315 | \end{figure} 316 | \end{frame} 317 | 318 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 319 | 320 | \end{document} 321 | -------------------------------------------------------------------------------- /examples/conf.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Gets current configuration of the @a ifname using WAPI accessors and prints 3 | * them in a pretty fashion. If a getter succeeds (and if @a set_ok is set), we 4 | * try to set that property with the same value to test the setters as well. 5 | */ 6 | static void 7 | conf(int sock, const char *ifname, int set_ok) 8 | { 9 | struct in_addr addr; 10 | double freq; 11 | wapi_freq_flag_t freq_flag; 12 | char essid[WAPI_ESSID_MAX_SIZE + 1]; 13 | wapi_essid_flag_t essid_flag; 14 | wapi_mode_t mode; 15 | struct ether_addr ap; 16 | int bitrate; 17 | wapi_bitrate_flag_t bitrate_flag; 18 | int txpower; 19 | wapi_txpower_flag_t txpower_flag; 20 | 21 | /* get ip */ 22 | bzero(&addr, sizeof(struct in_addr)); 23 | if (wapi_get_ip(sock, ifname, &addr) >= 0) 24 | { 25 | printf("ip: %s\n", inet_ntoa(addr)); 26 | 27 | if (set_ok) 28 | /* set ip (Make sure sin.sin_family is set to AF_INET.) */ 29 | wapi_set_ip(sock, ifname, &addr); 30 | } 31 | 32 | /* get netmask */ 33 | bzero(&addr, sizeof(struct in_addr)); 34 | if (wapi_get_netmask(sock, ifname, &addr) >= 0) 35 | { 36 | printf("netmask: %s\n", inet_ntoa(addr)); 37 | 38 | if (set_ok) 39 | /* set netmask (Make sure sin.sin_family is set to AF_INET.) */ 40 | wapi_set_netmask(sock, ifname, &addr); 41 | } 42 | 43 | /* get freq */ 44 | if (wapi_get_freq(sock, ifname, &freq, &freq_flag) >= 0) 45 | { 46 | int chan; 47 | double tmpfreq; 48 | 49 | printf("freq: %g\n", freq); 50 | printf("freq_flag: %s\n", wapi_freq_flags[freq_flag]); 51 | 52 | if (wapi_freq2chan(sock, ifname, freq, &chan) >= 0) 53 | printf("chan: %d\n", chan); 54 | 55 | if (wapi_chan2freq(sock, ifname, chan, &tmpfreq) >= 0) 56 | printf("freq: %g\n", tmpfreq); 57 | 58 | if (set_ok) 59 | /* set freq */ 60 | wapi_set_freq(sock, ifname, freq, freq_flag); 61 | } 62 | 63 | /* get essid */ 64 | if (wapi_get_essid(sock, ifname, essid, &essid_flag) >= 0) 65 | { 66 | printf("essid: %s\n", essid); 67 | printf("essid_flag: %s\n", wapi_essid_flags[essid_flag]); 68 | 69 | if (set_ok) 70 | /* set essid */ 71 | wapi_set_essid(sock, ifname, essid, essid_flag); 72 | } 73 | 74 | /* get operating mode */ 75 | if (wapi_get_mode(sock, ifname, &mode) >= 0) 76 | { 77 | printf("mode: %s\n", wapi_modes[mode]); 78 | 79 | if (set_ok) 80 | /* set operating mode */ 81 | wapi_set_mode(sock, ifname, mode); 82 | } 83 | 84 | /* get ap */ 85 | if (wapi_get_ap(sock, ifname, &ap) >= 0) 86 | { 87 | printf( 88 | "ap: %02X:%02X:%02X:%02X:%02X:%02X\n", 89 | ap.ether_addr_octet[0], 90 | ap.ether_addr_octet[1], 91 | ap.ether_addr_octet[2], 92 | ap.ether_addr_octet[3], 93 | ap.ether_addr_octet[4], 94 | ap.ether_addr_octet[5]); 95 | 96 | if (set_ok) 97 | /* set ap */ 98 | wapi_set_ap(sock, ifname, &ap); 99 | } 100 | 101 | /* get bitrate */ 102 | if (wapi_get_bitrate(sock, ifname, &bitrate, &bitrate_flag) >= 0) 103 | { 104 | printf("bitrate: %d\n", bitrate); 105 | printf("bitrate_flag: %s\n", wapi_bitrate_flags[bitrate_flag]); 106 | 107 | if (set_ok) 108 | /* set bitrate */ 109 | wapi_set_bitrate(sock, ifname, bitrate, bitrate_flag); 110 | } 111 | 112 | /* get txpower */ 113 | if (wapi_get_txpower(sock, ifname, &txpower, &txpower_flag) >= 0) 114 | { 115 | printf("txpower: %d\n", txpower); 116 | printf("txpower_flag: %s\n", wapi_txpower_flags[txpower_flag]); 117 | 118 | if (set_ok) 119 | /* set txpower */ 120 | wapi_set_txpower(sock, ifname, txpower, txpower_flag); 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /examples/hostapd.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | using namespace std; 12 | 13 | 14 | static pair 15 | hostapd_split_conf(const string line) 16 | { 17 | size_t eqchar = line.find("="); 18 | return make_pair( 19 | line.substr(0, eqchar), 20 | line.substr((eqchar+1), line.length()) 21 | ); 22 | } 23 | 24 | 25 | static bool 26 | hostapd_read_conf(const char *conffile, map& conf) 27 | { 28 | ifstream ifs(conffile); 29 | if (!ifs) 30 | { 31 | fprintf( 32 | stderr, "Couldn't open %s for reading: %s", 33 | conffile, strerror(errno)); 34 | return false; 35 | } 36 | 37 | string line; 38 | while (getline(ifs, line)) 39 | { 40 | pair entry = hostapd_split_conf(line); 41 | conf[entry.first] = entry.second; 42 | } 43 | 44 | return true; 45 | } 46 | 47 | 48 | static bool 49 | hostapd_write_conf(const char *conffile, const map conf) 50 | { 51 | ofstream ofs(conffile); 52 | if (!ofs) 53 | { 54 | fprintf( 55 | stderr, "Couldn't open %s for writing: %s", 56 | conffile, strerror(errno)); 57 | return false; 58 | } 59 | 60 | for (map::const_iterator it = conf.begin(); 61 | it != conf.end(); 62 | ++it) 63 | ofs << it->first << "=" << it->second << endl; 64 | return true; 65 | } 66 | 67 | 68 | static bool 69 | hostapd_reload(const char *pidfile) 70 | { 71 | ifstream ifs(pidfile); 72 | string line; 73 | int pid; 74 | return ( 75 | getline(ifs, line) && 76 | sscanf(line.c_str(), "%d", &pid) && 77 | !kill(pid, SIGHUP)); 78 | } 79 | 80 | 81 | int 82 | main(int argc, char *argv[]) 83 | { 84 | if (argc != 5) 85 | { 86 | fprintf(stderr, "Usage: %s \n", argv[0]); 87 | return 1; 88 | } 89 | const char *pidfile = argv[1]; 90 | const char *conffile = argv[2]; 91 | const string var = string(argv[3]); 92 | const string val = string(argv[4]); 93 | 94 | map conf; 95 | hostapd_read_conf(conffile, conf); 96 | conf[var] = val; 97 | hostapd_write_conf(conffile, conf); 98 | hostapd_reload(pidfile); 99 | 100 | return 0; 101 | } 102 | -------------------------------------------------------------------------------- /examples/ifadd.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "wapi.h" 6 | 7 | 8 | static int 9 | parse_wapi_mode(const char *s, wapi_mode_t *mode) 10 | { 11 | int ret = 0; 12 | 13 | if (!strcmp(s, "auto")) *mode = WAPI_MODE_AUTO; 14 | else if (!strcmp(s, "adhoc")) *mode = WAPI_MODE_ADHOC; 15 | else if (!strcmp(s, "managed")) *mode = WAPI_MODE_MANAGED; 16 | else if (!strcmp(s, "master")) *mode = WAPI_MODE_MASTER; 17 | else if (!strcmp(s, "repeat")) *mode = WAPI_MODE_REPEAT; 18 | else if (!strcmp(s, "second")) *mode = WAPI_MODE_SECOND; 19 | else if (!strcmp(s, "monitor")) *mode = WAPI_MODE_MONITOR; 20 | else ret = 1; 21 | 22 | return ret; 23 | } 24 | 25 | 26 | int 27 | main(int argc, char *argv[]) 28 | { 29 | wapi_mode_t mode; 30 | const char *ifname; 31 | const char *name; 32 | int ret; 33 | 34 | if (argc != 4) 35 | { 36 | fprintf(stderr, "Usage: %s \n", argv[0]); 37 | return EXIT_FAILURE; 38 | } 39 | ifname = argv[1]; 40 | name = argv[2]; 41 | 42 | if (parse_wapi_mode(argv[3], &mode)) 43 | { 44 | fprintf(stderr, "Unknown mode: %s!\n", argv[3]); 45 | return EXIT_FAILURE; 46 | } 47 | 48 | ret = wapi_if_add(-1, ifname, name, mode); 49 | fprintf(stderr, "wapi_if_add(): ret: %d\n", ret); 50 | 51 | return ret; 52 | } 53 | -------------------------------------------------------------------------------- /examples/ifdel.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "wapi.h" 5 | 6 | 7 | int 8 | main(int argc, char *argv[]) 9 | { 10 | int ret; 11 | 12 | if (argc != 2) 13 | { 14 | fprintf(stderr, "Usage: %s \n", argv[0]); 15 | return EXIT_FAILURE; 16 | } 17 | 18 | ret = wapi_if_del(-1, argv[1]); 19 | fprintf(stderr, "wapi_if_del(): ret: %d\n", ret); 20 | 21 | return ret; 22 | } 23 | -------------------------------------------------------------------------------- /examples/ifnames.c: -------------------------------------------------------------------------------- 1 | static void 2 | getifnames(void) 3 | { 4 | wapi_list_t list; 5 | 6 | bzero(&list, sizeof(wapi_list_t)); 7 | if (wapi_get_ifnames(&list) >= 0) 8 | { 9 | wapi_string_t *str; 10 | 11 | /* print ifnames */ 12 | printf("ifnames:"); 13 | for (str = list.head.string; str; str = str->next) 14 | printf(" %s", str->data); 15 | 16 | /* free ifnames */ 17 | str = list.head.string; 18 | while (str) 19 | { 20 | wapi_string_t *tmp; 21 | 22 | tmp = str->next; 23 | free(str->data); 24 | free(str); 25 | str = tmp; 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /examples/mainskel.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "wapi.h" 10 | 11 | 12 | #include "conf.c" 13 | #include "scan.c" 14 | #include "ifnames.c" 15 | #include "routes.c" 16 | 17 | 18 | static int 19 | mainskel(int argc, char *argv[], int set_ok) 20 | { 21 | const char *ifname; 22 | int sock; 23 | 24 | /* check command line args */ 25 | if (argc != 2) 26 | { 27 | fprintf(stderr, "Usage: %s \n", argv[0]); 28 | return EXIT_FAILURE; 29 | } 30 | ifname = argv[1]; 31 | 32 | /* get ifnames */ 33 | getifnames(); 34 | putchar('\n'); 35 | 36 | /* get routes */ 37 | printf("\nroutes:\n"); 38 | printf("-------\n"); 39 | getroutes(); 40 | putchar('\n'); 41 | 42 | /* make a comm. sock. */ 43 | sock = wapi_make_socket(); 44 | if (sock >= 0) 45 | { 46 | /* list conf */ 47 | printf("\nconf\n"); 48 | printf("------------\n"); 49 | conf(sock, ifname, set_ok); 50 | 51 | /* scan aps */ 52 | printf("\nscan\n"); 53 | printf("----\n"); 54 | scan(sock, ifname); 55 | 56 | /* close comm. sock. */ 57 | close(sock); 58 | } 59 | 60 | return EXIT_SUCCESS; 61 | } 62 | -------------------------------------------------------------------------------- /examples/recover.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "wapi.h" 8 | 9 | 10 | static inline unsigned int 11 | epoch_millitm(void) 12 | { 13 | struct timeb t; 14 | ftime(&t); 15 | return (t.time * 1000) + t.millitm; 16 | } 17 | 18 | 19 | static int 20 | recover_for_essid( 21 | int sock, const char *ifname, const char *essid, unsigned int maxdur) 22 | { 23 | const unsigned int maxtm = epoch_millitm() + maxdur; 24 | const unsigned int sleepdur = 100; 25 | wapi_list_t list; 26 | wapi_scan_info_t *info; 27 | double freq; 28 | int ret; 29 | 30 | scan: 31 | /* Initiate scan. */ 32 | if ((ret = wapi_scan_init(sock, ifname)) < 0) 33 | return ret; 34 | 35 | /* Wait for scan to complete. */ 36 | for (;epoch_millitm() <= maxtm; usleep(sleepdur * 1000)) 37 | switch ((ret = wapi_scan_stat(sock, ifname))) 38 | { 39 | case 0: break; 40 | case 1: continue; 41 | default: return ret; 42 | } 43 | 44 | /* Data is not ready. */ 45 | if (ret == 1) return 1; 46 | 47 | /* Collect results. */ 48 | if ((ret = wapi_scan_coll(sock, ifname, &list)) < 0) 49 | return ret; 50 | 51 | /* See if we have an AP with the given ESSID. */ 52 | freq = -1; 53 | for (info = list.head.scan; info; info = info->next) 54 | if (info->has_essid && info->has_freq && !strcmp(info->essid, essid)) 55 | { 56 | freq = info->freq; 57 | break; 58 | } 59 | 60 | /* If no such AP, try again. */ 61 | if (freq < 0) 62 | { 63 | ret = 1; 64 | goto scan; 65 | } 66 | 67 | /* Switch to AP freq and ESSID. */ 68 | if ((ret = wapi_set_freq(sock, ifname, freq, WAPI_FREQ_FIXED)) > 0) 69 | ret = wapi_set_essid(sock, ifname, essid, WAPI_ESSID_ON); 70 | 71 | return ret; 72 | } 73 | 74 | 75 | int 76 | main(int argc, char *argv[]) 77 | { 78 | const char *ifname; 79 | const char *essid; 80 | unsigned int maxdur; 81 | int sock; 82 | int ret; 83 | 84 | /* Parse command line arguments. */ 85 | if (argc != 4) 86 | { 87 | fprintf(stderr, "Usage: %s \n", argv[0]); 88 | return EXIT_FAILURE; 89 | } 90 | ifname = argv[1]; 91 | essid = argv[2]; 92 | maxdur = atoi(argv[3]); 93 | 94 | if ((sock = wapi_make_socket()) < 0) return EXIT_FAILURE; 95 | ret = recover_for_essid(sock, ifname, essid, maxdur); 96 | close(sock); 97 | 98 | return ret; 99 | } 100 | -------------------------------------------------------------------------------- /examples/routes.c: -------------------------------------------------------------------------------- 1 | static void 2 | getroutes(void) 3 | { 4 | wapi_list_t list; 5 | 6 | bzero(&list, sizeof(wapi_list_t)); 7 | if (wapi_get_routes(&list) >= 0) 8 | { 9 | wapi_route_info_t *ri; 10 | 11 | /* print route */ 12 | for (ri = list.head.route; ri; ri = ri->next) 13 | printf( 14 | ">> dest: %s, gw: %s, netmask: %s\n", 15 | inet_ntoa(ri->dest), inet_ntoa(ri->gw), inet_ntoa(ri->netmask)); 16 | 17 | /* free routes */ 18 | ri = list.head.route; 19 | while (ri) 20 | { 21 | wapi_route_info_t *tmpri; 22 | 23 | tmpri = ri->next; 24 | free(ri->ifname); 25 | free(ri); 26 | ri = tmpri; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /examples/sample-get.c: -------------------------------------------------------------------------------- 1 | #include "mainskel.c" 2 | 3 | int 4 | main(int argc, char *argv[]) 5 | { 6 | return mainskel(argc, argv, 0); 7 | } 8 | -------------------------------------------------------------------------------- /examples/sample-set.c: -------------------------------------------------------------------------------- 1 | #include "mainskel.c" 2 | 3 | int 4 | main(int argc, char *argv[]) 5 | { 6 | return mainskel(argc, argv, 1); 7 | } 8 | -------------------------------------------------------------------------------- /examples/scan.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Scans available APs in the range using given @a ifname interface. 3 | */ 4 | static void 5 | scan(int sock, const char *ifname) 6 | { 7 | int sleepdur = 1; 8 | int sleeptries = 5; 9 | wapi_list_t list; 10 | wapi_scan_info_t *info; 11 | int ret; 12 | 13 | /* start scan */ 14 | if (wapi_scan_init(sock, ifname) < 0) 15 | return; 16 | 17 | /* wait for completion */ 18 | do { 19 | printf("scan(): sleeptries: %d\n", sleeptries); 20 | sleep(sleepdur); 21 | ret = wapi_scan_stat(sock, ifname); 22 | } while (--sleeptries > 0 && ret > 0); 23 | 24 | /* check wait result */ 25 | if (ret < 0) 26 | { 27 | if (!sleeptries) 28 | fprintf(stderr, "scan(): sleeptries exceeded!\n"); 29 | return; 30 | } 31 | 32 | /* collect results */ 33 | bzero(&list, sizeof(wapi_list_t)); 34 | if (wapi_scan_coll(sock, ifname, &list) >= 0) 35 | for (info = list.head.scan; info; info = info->next) 36 | printf( 37 | ">> %02x:%02x:%02x:%02x:%02x:%02x %s\n", 38 | info->ap.ether_addr_octet[0], 39 | info->ap.ether_addr_octet[1], 40 | info->ap.ether_addr_octet[2], 41 | info->ap.ether_addr_octet[3], 42 | info->ap.ether_addr_octet[4], 43 | info->ap.ether_addr_octet[5], 44 | (info->has_essid ? info->essid : "")); 45 | 46 | /* free ap list */ 47 | info = list.head.scan; 48 | while (info) 49 | { 50 | wapi_scan_info_t *temp; 51 | 52 | temp = info->next; 53 | free(info); 54 | info = temp; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /include/wapi.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * Public API declarations. 4 | */ 5 | 6 | 7 | #ifndef WAPI_H 8 | #define WAPI_H 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | 20 | /* Generic linked list (dummy) decleration. (No definition!) */ 21 | typedef struct wapi_list_t wapi_list_t; 22 | 23 | 24 | /** 25 | * @defgroup accessors Network Interface Accessors 26 | * 27 | * This section is composed of accessors (getters and setters) for various 28 | * network interface configurations. Each accessor requires a socket (see 29 | * wapi_make_socket()) to issue kernel commands. Since each accessor is a 30 | * user-friendly wrapper over various ioctl() calls, unless stated otherwise, 31 | * return values of the accessors are generally obtained by related ioctl() 32 | * calls. In other words, on success, zero is returned. 33 | * 34 | * Pay attention that, all setters require root privileges. 35 | * 36 | * Below is an example usage of some accessor routines. 37 | * 38 | * @include conf.c 39 | * 40 | * A sample output of the above function is as follows. 41 | * 42 | @verbatim 43 | ip: 192.168.1.111 44 | netmask: 255.255.255.0 45 | freq: 2.412e+09 46 | freq_flag: WAPI_FREQ_AUTO 47 | chan: 1 48 | freq: 2.412e+09 49 | essid: ozu 50 | essid_flag: WAPI_ESSID_ON 51 | mode: WAPI_MODE_MANAGED 52 | ap: 00:14:C1:34:CE:83 53 | wireless.c:451:wapi_get_bitrate(): Bitrate is disabled. 54 | wireless.c:546:wapi_get_txpower():ioctl(SIOCGIWTXPOW): Invalid argument 55 | @endverbatim 56 | * 57 | * As can be seen from the output, some functionalities are not supported by the 58 | * underlying wireless network card of the test system. 59 | */ 60 | 61 | 62 | /** 63 | * @defgroup ifaccessors Generic Network Interface Accessors 64 | * @ingroup accessors 65 | * 66 | * This section consists of generic network interface accessors (IP address, 67 | * gateway, netmask) without any device specific features. 68 | */ 69 | 70 | 71 | /** 72 | * @defgroup misc Miscellaneous Accessors 73 | * @ingroup ifaccessors 74 | * @{ 75 | */ 76 | 77 | 78 | /** 79 | * Gets the interface up status. 80 | * 81 | * @param[out] is_up Set to 0, if up; 1, otherwise. 82 | */ 83 | int wapi_get_ifup(int sock, const char *ifname, int *is_up); 84 | 85 | 86 | /** 87 | * Activates the interface. 88 | */ 89 | int wapi_set_ifup(int sock, const char *ifname); 90 | 91 | 92 | /** 93 | * Shuts down the interface. 94 | */ 95 | int wapi_set_ifdown(int sock, const char *ifname); 96 | 97 | 98 | /** @} misc/ifaccessors */ 99 | 100 | 101 | /** 102 | * @defgroup ip IP (Internet Protocol) Accessors 103 | * @ingroup ifaccessors 104 | * @{ 105 | */ 106 | 107 | 108 | /** 109 | * Gets IP address of the given network interface. 110 | */ 111 | int wapi_get_ip(int sock, const char *ifname, struct in_addr *addr); 112 | 113 | 114 | /** 115 | * Sets IP adress of the given network interface. 116 | */ 117 | int wapi_set_ip(int sock, const char *ifname, const struct in_addr *addr); 118 | 119 | 120 | /** 121 | * Gets netmask of the given network interface. 122 | */ 123 | int wapi_get_netmask(int sock, const char *ifname, struct in_addr *addr); 124 | 125 | 126 | /** 127 | * Sets netmask of the given network interface. 128 | */ 129 | int wapi_set_netmask(int sock, const char *ifname, const struct in_addr *addr); 130 | 131 | 132 | /** @} ip/ifaccessors */ 133 | 134 | 135 | /** 136 | * @defgroup route Routing Table Accessors 137 | * @ingroup ifaccessors 138 | * @{ 139 | */ 140 | 141 | 142 | /** 143 | * Parses routing table rows from @c WAPI_PROC_NET_ROUTE. 144 | * 145 | * @param[out] list Pushes collected @c wapi_route_info_t into this list. 146 | * 147 | * Below is example usage of wapi_get_routes(). 148 | * 149 | * @include routes.c 150 | * 151 | * Here is a sample output of the above getroutes(). 152 | * 153 | @verbatim 154 | >> dest: 0.0.0.0, gw: 0.0.0.0, netmask: 0.0.0.0 155 | >> dest: 192.168.1.0, gw: 192.168.1.0, netmask: 192.168.1.0 156 | @endverbatim 157 | */ 158 | int wapi_get_routes(wapi_list_t *list); 159 | 160 | 161 | /** Route target types. */ 162 | typedef enum { 163 | WAPI_ROUTE_TARGET_NET, /**< The target is a network. */ 164 | WAPI_ROUTE_TARGET_HOST /**< The target is a host. */ 165 | } wapi_route_target_t; 166 | 167 | 168 | /** 169 | * Adds @a gateway for the given @a target network. 170 | */ 171 | int 172 | wapi_add_route_gw( 173 | int sock, 174 | wapi_route_target_t targettype, 175 | const struct in_addr *target, 176 | const struct in_addr *netmask, 177 | const struct in_addr *gw); 178 | 179 | 180 | /** 181 | * Deletes @a gateway for the given @a target network. 182 | */ 183 | int 184 | wapi_del_route_gw( 185 | int sock, 186 | wapi_route_target_t targettype, 187 | const struct in_addr *target, 188 | const struct in_addr *netmask, 189 | const struct in_addr *gw); 190 | 191 | 192 | /** @} route/ifaccessors */ 193 | 194 | 195 | /** 196 | * @defgroup wifaccessors Wireless Interface Accessors 197 | * @ingroup accessors 198 | * 199 | * This section consists of accessor functions dedicated to wireless network 200 | * interfaces. 201 | */ 202 | 203 | /** 204 | * @defgroup misc Miscellaneous Accessors 205 | * @ingroup wifaccessors 206 | * @{ 207 | */ 208 | 209 | 210 | /** 211 | * Gets kernel WE (Wireless Extensions) version. 212 | * 213 | * @param[out] we_version Set to @c we_version_compiled of range information. 214 | * 215 | * @return zero on success. 216 | */ 217 | int wapi_get_we_version(int sock, const char *ifname, int *we_version); 218 | 219 | 220 | /** @} misc/wifaccessors */ 221 | 222 | 223 | /** 224 | * @defgroup freq Frequency Accessors 225 | * @ingroup wifaccessors 226 | * @{ 227 | */ 228 | 229 | 230 | /** Frequency flags. */ 231 | typedef enum { 232 | WAPI_FREQ_AUTO = IW_FREQ_AUTO, 233 | WAPI_FREQ_FIXED = IW_FREQ_FIXED 234 | } wapi_freq_flag_t; 235 | 236 | 237 | /** Frequency flag names. */ 238 | extern const char *wapi_freq_flags[]; 239 | 240 | 241 | /** 242 | * Gets the operating frequency of the device. 243 | */ 244 | int wapi_get_freq( 245 | int sock, 246 | const char *ifname, 247 | double *freq, 248 | wapi_freq_flag_t *flag); 249 | 250 | 251 | /** 252 | * Sets the operating frequency of the device. 253 | */ 254 | int 255 | wapi_set_freq( 256 | int sock, 257 | const char *ifname, 258 | double freq, 259 | wapi_freq_flag_t flag); 260 | 261 | 262 | /** 263 | * Finds corresponding channel for the supplied @a freq. 264 | * 265 | * @return 0, on success; -2, if not found; otherwise, ioctl() return value. 266 | */ 267 | int wapi_freq2chan(int sock, const char *ifname, double freq, int *chan); 268 | 269 | 270 | /** 271 | * Finds corresponding frequency for the supplied @a chan. 272 | * 273 | * @return 0, on success; -2, if not found; otherwise, ioctl() return value. 274 | */ 275 | int wapi_chan2freq(int sock, const char *ifname, int chan, double *freq); 276 | 277 | 278 | /** @} freq/wifaccessors */ 279 | 280 | 281 | /** 282 | * @defgroup essid ESSID (Extended Service Set Identifier) Accessors 283 | * @ingroup wifaccessors 284 | * @{ 285 | */ 286 | 287 | 288 | /** Maximum allowed ESSID size. */ 289 | #define WAPI_ESSID_MAX_SIZE IW_ESSID_MAX_SIZE 290 | 291 | 292 | /** ESSID flags. */ 293 | typedef enum { 294 | WAPI_ESSID_ON, 295 | WAPI_ESSID_OFF 296 | } wapi_essid_flag_t; 297 | 298 | 299 | /** ESSID flag names. */ 300 | extern const char *wapi_essid_flags[]; 301 | 302 | 303 | /** 304 | * Gets ESSID of the device. 305 | * 306 | * @param[out] essid Used to store the ESSID of the device. Buffer must have 307 | * enough space to store @c WAPI_ESSID_MAX_SIZE+1 characters. 308 | */ 309 | int 310 | wapi_get_essid( 311 | int sock, 312 | const char *ifname, 313 | char *essid, 314 | wapi_essid_flag_t *flag); 315 | 316 | 317 | /** 318 | * Sets ESSID of the device. 319 | * 320 | * @a essid At most @c WAPI_ESSID_MAX_SIZE characters are read. 321 | */ 322 | int 323 | wapi_set_essid( 324 | int sock, 325 | const char *ifname, 326 | const char *essid, 327 | wapi_essid_flag_t flag); 328 | 329 | 330 | /** @} essid/wifaccessors */ 331 | 332 | 333 | /** 334 | * @defgroup mode Operating Mode 335 | * @ingroup wifaccessors 336 | * @{ 337 | */ 338 | 339 | 340 | /** Supported operation modes. */ 341 | typedef enum { 342 | WAPI_MODE_AUTO = IW_MODE_AUTO, /**< Driver decides. */ 343 | WAPI_MODE_ADHOC = IW_MODE_ADHOC, /**< Single cell network. */ 344 | WAPI_MODE_MANAGED = IW_MODE_INFRA, /**< Multi cell network, roaming, ... */ 345 | WAPI_MODE_MASTER = IW_MODE_MASTER, /**< Synchronisation master or access point. */ 346 | WAPI_MODE_REPEAT = IW_MODE_REPEAT, /**< Wireless repeater, forwarder. */ 347 | WAPI_MODE_SECOND = IW_MODE_SECOND, /**< Secondary master/repeater, backup. */ 348 | WAPI_MODE_MONITOR = IW_MODE_MONITOR /**< Passive monitor, listen only. */ 349 | } wapi_mode_t; 350 | 351 | 352 | /** Supported operation mode names. */ 353 | extern const char *wapi_modes[]; 354 | 355 | 356 | /** 357 | * Gets the operating mode of the device. 358 | */ 359 | int wapi_get_mode(int sock, const char *ifname, wapi_mode_t *mode); 360 | 361 | 362 | /** 363 | * Sets the operating mode of the device. 364 | */ 365 | int wapi_set_mode(int sock, const char *ifname, wapi_mode_t mode); 366 | 367 | 368 | /** @} mode/wifaccessors */ 369 | 370 | 371 | /** 372 | * @defgroup ap Access Point 373 | * @ingroup wifaccessors 374 | * @{ 375 | */ 376 | 377 | 378 | /** 379 | * Creates an ethernet broadcast address. 380 | */ 381 | int wapi_make_broad_ether(struct ether_addr *sa); 382 | 383 | 384 | /** 385 | * Creates an ethernet NULL address. 386 | */ 387 | int wapi_make_null_ether(struct ether_addr *sa); 388 | 389 | 390 | /** 391 | * Gets access point address of the device. 392 | * 393 | * @param[out] ap Set the to MAC address of the device. (For "any", a broadcast 394 | * ethernet address; for "off", a null ethernet address is used.) 395 | */ 396 | int wapi_get_ap(int sock, const char *ifname, struct ether_addr *ap); 397 | 398 | 399 | /** 400 | * Sets access point address of the device. 401 | */ 402 | int wapi_set_ap(int sock, const char *ifname, const struct ether_addr *ap); 403 | 404 | 405 | /** @} ap/wifaccessors */ 406 | 407 | 408 | /** 409 | * @defgroup bitrate Bit Rate 410 | * @ingroup wifaccessors 411 | * @{ 412 | */ 413 | 414 | 415 | /** 416 | * Bitrate flags. 417 | * 418 | * At the moment, unicast (@c IW_BITRATE_UNICAST) and broadcast (@c 419 | * IW_BITRATE_BROADCAST) bitrate flags are not supported. 420 | */ 421 | typedef enum { 422 | WAPI_BITRATE_AUTO, 423 | WAPI_BITRATE_FIXED 424 | } wapi_bitrate_flag_t; 425 | 426 | 427 | /** Bitrate flag names. */ 428 | extern const char *wapi_bitrate_flags[]; 429 | 430 | 431 | /** 432 | * Gets bitrate of the device. 433 | */ 434 | int wapi_get_bitrate( 435 | int sock, 436 | const char *ifname, 437 | int *bitrate, 438 | wapi_bitrate_flag_t *flag); 439 | 440 | 441 | /** 442 | * Sets bitrate of the device. 443 | */ 444 | int 445 | wapi_set_bitrate( 446 | int sock, 447 | const char *ifname, 448 | int bitrate, 449 | wapi_bitrate_flag_t flag); 450 | 451 | 452 | /** @} bitrate/wifaccessors */ 453 | 454 | 455 | /** 456 | * @defgroup txpower Transmit Power 457 | * @ingroup wifaccessors 458 | * @{ 459 | */ 460 | 461 | 462 | /** Transmit power (txpower) flags. */ 463 | typedef enum { 464 | WAPI_TXPOWER_DBM, /**< Value is in dBm. */ 465 | WAPI_TXPOWER_MWATT, /**< Value is in mW. */ 466 | WAPI_TXPOWER_RELATIVE /**< Value is in arbitrary units. */ 467 | } wapi_txpower_flag_t; 468 | 469 | 470 | /** Transmit power flag names. */ 471 | extern const char *wapi_txpower_flags[]; 472 | 473 | 474 | /** 475 | * Converts a value in dBm to a value in milliWatt. 476 | */ 477 | int wapi_dbm2mwatt(int dbm); 478 | 479 | 480 | /** 481 | * Converts a value in milliWatt to a value in dBm. 482 | */ 483 | int wapi_mwatt2dbm(int mwatt); 484 | 485 | 486 | /** 487 | * Gets txpower of the device. 488 | */ 489 | int 490 | wapi_get_txpower( 491 | int sock, 492 | const char *ifname, 493 | int *power, 494 | wapi_txpower_flag_t *flag); 495 | 496 | 497 | /** 498 | * Sets txpower of the device. 499 | */ 500 | int 501 | wapi_set_txpower( 502 | int sock, 503 | const char *ifname, 504 | int power, 505 | wapi_txpower_flag_t flag); 506 | 507 | 508 | /** @} txpower/wifaccessors */ 509 | 510 | 511 | /** 512 | * @defgroup ifadddel Add/Delete Virtual Interfaces 513 | * @ingroup wifaccessors 514 | * 515 | * nl80211 routines to add/delete virtual interfaces. Some of these features 516 | * require dedicated hardware to work properly. Since these features utilize 517 | * nl80211 interface, @c sock arguments are there just for the function 518 | * footprint uniformness purposes, hence are ignored totally. 519 | * 520 | * @{ 521 | */ 522 | 523 | 524 | /** 525 | * Creates a virtual interface with @a name for interface @a ifname. 526 | */ 527 | int 528 | wapi_if_add(int sock, const char *ifname, const char *name, wapi_mode_t mode); 529 | 530 | 531 | /** 532 | * Deletes a virtual interface with @a name. 533 | */ 534 | int 535 | wapi_if_del(int sock, const char *ifname); 536 | 537 | 538 | /** @} ifadddel/wifaccessors */ 539 | 540 | 541 | /** 542 | * @defgroup utils Utility Routines 543 | * @{ 544 | */ 545 | 546 | 547 | /** 548 | * Creates an AF_INET socket to be used in ioctl() calls. 549 | * 550 | * @return non-negative on success. 551 | */ 552 | int wapi_make_socket(void); 553 | 554 | 555 | /** 556 | * Parses @c WAPI_PROC_NET_WIRELESS according to hardcoded mechanisms in @c 557 | * linux/net/wireless/wext-proc.c sources. 558 | * 559 | * @param[out] list Pushes collected @c wapi_string_t into this list. 560 | * 561 | * Here is an example usage of the wapi_get_ifnames(). 562 | * 563 | * @include ifnames.c 564 | */ 565 | int wapi_get_ifnames(wapi_list_t *list); 566 | 567 | 568 | /** @} utils */ 569 | 570 | 571 | /** 572 | * @defgroup scan Scanning 573 | * 574 | * This group consists of functions for scanning accessible access points (APs) 575 | * in the range. 576 | * 577 | * Unfortunately provided scanning API by wireless-tools libraries (libiw) is 578 | * quite limited, and doesn't list all APs in the range. (See iw_process_scan() 579 | * of libiw. For iwlist case, it has its own hardcoded magic for this stuff and 580 | * it is not provided by libiw.) For this purpose, we needed to implement our 581 | * own scanning routines. Furthermore, scanning requires extracting binary 582 | * results returned from kernel over a @c char buffer, hence it causes dozens of 583 | * hairy binary compatibility issues. Luckily, libiw provides an API method to 584 | * cope with this: iw_extract_event_stream(). That's the only place in this 585 | * project relying on libiw. 586 | * 587 | * The scanning operation disable normal network traffic, and therefore you 588 | * should not abuse of scan. The scan need to check the presence of network on 589 | * other frequencies. While you are checking those other frequencies, you can 590 | * not be on your normal frequency to listen to normal traffic in the cell. You 591 | * need typically in the order of one second to actively probe all 802.11b 592 | * channels (do the maths). Some cards may do that in background, to reply to 593 | * scan commands faster, but they still have to do it. Leaving the cell for such 594 | * an extended period of time is pretty bad. Any kind of streaming/low latency 595 | * traffic will be impacted, and the user will perceive it (easily checked with 596 | * telnet). People trying to send traffic to you will retry packets and waste 597 | * bandwidth. Some applications may be sensitive to those packet losses in weird 598 | * ways, and tracing those weird behavior back to scanning may take time. If you 599 | * are in ad-hoc mode, if two nodes scan approx at the same time, they won't see 600 | * each other, which may create associations issues. For those reasons, the 601 | * scanning activity should be limited to what's really needed, and continuous 602 | * scanning is a bad idea. --- Jean Tourrilhes 603 | * 604 | * Here is an example demonstrating the usage of the scanning API. 605 | * 606 | * @include scan.c 607 | * 608 | * A sample output of the above function is as follows. 609 | * 610 | @verbatim 611 | scan(): sleeptries: 5 612 | scan(): sleeptries: 4 613 | >> 00:23:f8:d2:90:3f ednz 614 | >> 00:1c:a8:14:6d:16 meddev 615 | >> 00:1a:2a:c0:47:84 suat 616 | >> 00:1c:a8:fe:93:8c home 617 | >> 00:25:86:cf:e6:e5 TP-LINK 618 | >> 00:02:cf:af:d9:96 ZyXEL 619 | >> 00:14:c1:34:ce:83 ozu 620 | @endverbatim 621 | * 622 | * Considering @c scan() function, pay attention that scanning requires root 623 | * privileges. (See wapi_scan_init() for details.) 624 | * 625 | * @{ 626 | */ 627 | 628 | 629 | /** 630 | * Starts a scan on the given interface. Root privileges are required to start a 631 | * scan. 632 | */ 633 | int wapi_scan_init(int sock, const char *ifname); 634 | 635 | 636 | /** 637 | * Checks the status of the scan process. 638 | * 639 | * @return zero, if data is ready; 1, if data is not ready; negative on failure. 640 | */ 641 | int wapi_scan_stat(int sock, const char *ifname); 642 | 643 | 644 | /** 645 | * Collects the results of a scan process. 646 | * 647 | * @param[out] aps Pushes collected @c wapi_scan_info_t into this list. 648 | */ 649 | int wapi_scan_coll(int sock, const char *ifname, wapi_list_t *aps); 650 | 651 | 652 | /** @} scan */ 653 | 654 | 655 | /** 656 | * @defgroup commons Common Data Structures & Definitions 657 | * @{ 658 | */ 659 | 660 | 661 | /** Path to @c /proc/net/wireless. (Requires procfs mounted.) */ 662 | #define WAPI_PROC_NET_WIRELESS "/proc/net/wireless" 663 | 664 | /** Path to @c /proc/net/route. (Requires procfs mounted.) */ 665 | #define WAPI_PROC_NET_ROUTE "/proc/net/route" 666 | 667 | /** Buffer size while reading lines from PROC_NET_ files. */ 668 | #define WAPI_PROC_LINE_SIZE 1024 669 | 670 | 671 | /** Linked list container for strings. */ 672 | typedef struct wapi_string_t { 673 | struct wapi_string_t *next; 674 | char *data; 675 | } wapi_string_t; 676 | 677 | 678 | /** Linked list container for scan results. */ 679 | typedef struct wapi_scan_info_t { 680 | struct wapi_scan_info_t *next; 681 | struct ether_addr ap; 682 | int has_essid; 683 | char essid[WAPI_ESSID_MAX_SIZE+1]; 684 | wapi_essid_flag_t essid_flag; 685 | int has_freq; 686 | double freq; 687 | int has_mode; 688 | wapi_mode_t mode; 689 | int has_bitrate; 690 | int bitrate; 691 | } wapi_scan_info_t; 692 | 693 | 694 | /** Linked list container for routing table rows. */ 695 | typedef struct wapi_route_info_t { 696 | struct wapi_route_info_t *next; 697 | char *ifname; 698 | struct in_addr dest; 699 | struct in_addr gw; 700 | unsigned int flags; /**< See @c RTF_* in @c net/route.h for available values. */ 701 | unsigned int refcnt; 702 | unsigned int use; 703 | unsigned int metric; 704 | struct in_addr netmask; 705 | unsigned int mtu; 706 | unsigned int window; 707 | unsigned int irtt; 708 | } wapi_route_info_t; 709 | 710 | 711 | /** 712 | * A generic linked list container. For functions taking @c wapi_list_t type of 713 | * argument, caller is resposible for releasing allocated memory. 714 | */ 715 | struct wapi_list_t { 716 | union wapi_list_head_t { 717 | wapi_string_t *string; 718 | wapi_scan_info_t *scan; 719 | wapi_route_info_t *route; 720 | } head; 721 | }; 722 | 723 | 724 | /** @} commons */ 725 | 726 | #ifdef __cplusplus 727 | } 728 | #endif 729 | 730 | #endif /* WAPI_H */ 731 | -------------------------------------------------------------------------------- /src/network.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * Generic network interface accessors. 4 | */ 5 | 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include "util.h" 16 | #include "wapi.h" 17 | 18 | 19 | /*-- Up & Down ---------------------------------------------------------------*/ 20 | 21 | 22 | int 23 | wapi_get_ifup(int sock, const char *ifname, int *is_up) 24 | { 25 | struct ifreq ifr; 26 | int ret; 27 | 28 | WAPI_VALIDATE_PTR(is_up); 29 | 30 | strncpy(ifr.ifr_name, ifname, IFNAMSIZ); 31 | if ((ret = ioctl(sock, SIOCGIFFLAGS, &ifr)) >= 0) 32 | *is_up = (ifr.ifr_flags & IFF_UP) == IFF_UP; 33 | else WAPI_IOCTL_STRERROR(SIOCGIFFLAGS); 34 | 35 | return ret; 36 | } 37 | 38 | 39 | int 40 | wapi_set_ifup(int sock, const char *ifname) 41 | { 42 | struct ifreq ifr; 43 | int ret; 44 | 45 | strncpy(ifr.ifr_name, ifname, IFNAMSIZ); 46 | if ((ret = ioctl(sock, SIOCGIFFLAGS, &ifr)) >= 0) 47 | { 48 | ifr.ifr_flags |= (IFF_UP | IFF_RUNNING); 49 | ret = ioctl(sock, SIOCSIFFLAGS, &ifr); 50 | } 51 | else WAPI_IOCTL_STRERROR(SIOCGIFFLAGS); 52 | 53 | return ret; 54 | } 55 | 56 | 57 | int 58 | wapi_set_ifdown(int sock, const char *ifname) 59 | { 60 | struct ifreq ifr; 61 | int ret; 62 | 63 | strncpy(ifr.ifr_name, ifname, IFNAMSIZ); 64 | if ((ret = ioctl(sock, SIOCGIFFLAGS, &ifr)) >= 0) 65 | { 66 | ifr.ifr_flags &= ~IFF_UP; 67 | ret = ioctl(sock, SIOCSIFFLAGS, &ifr); 68 | } 69 | else WAPI_IOCTL_STRERROR(SIOCGIFFLAGS); 70 | 71 | return ret; 72 | } 73 | 74 | 75 | /*-- IP & Netmask ------------------------------------------------------------*/ 76 | 77 | 78 | static int 79 | wapi_get_addr(int sock, const char *ifname, int cmd, struct in_addr *addr) 80 | { 81 | struct ifreq ifr; 82 | int ret; 83 | 84 | WAPI_VALIDATE_PTR(addr); 85 | 86 | strncpy(ifr.ifr_name, ifname, IFNAMSIZ); 87 | if ((ret = ioctl(sock, cmd, &ifr)) >= 0) 88 | { 89 | struct sockaddr_in *sin = (struct sockaddr_in *) &ifr.ifr_addr; 90 | memcpy(addr, &sin->sin_addr, sizeof(struct in_addr)); 91 | } 92 | else WAPI_IOCTL_STRERROR(cmd); 93 | 94 | return ret; 95 | } 96 | 97 | 98 | static int 99 | wapi_set_addr(int sock, const char *ifname, int cmd, const struct in_addr *addr) 100 | { 101 | struct sockaddr_in sin; 102 | struct ifreq ifr; 103 | int ret; 104 | 105 | WAPI_VALIDATE_PTR(addr); 106 | 107 | sin.sin_family = AF_INET; 108 | memcpy(&sin.sin_addr, addr, sizeof(struct in_addr)); 109 | memcpy(&ifr.ifr_addr, &sin, sizeof(struct sockaddr_in)); 110 | strncpy(ifr.ifr_name, ifname, IFNAMSIZ); 111 | if ((ret = ioctl(sock, cmd, &ifr)) < 0) 112 | WAPI_IOCTL_STRERROR(cmd); 113 | 114 | return ret; 115 | } 116 | 117 | 118 | int 119 | wapi_get_ip(int sock, const char *ifname, struct in_addr *addr) 120 | { 121 | return wapi_get_addr(sock, ifname, SIOCGIFADDR, addr); 122 | } 123 | 124 | 125 | int 126 | wapi_set_ip(int sock, const char *ifname, const struct in_addr *addr) 127 | { 128 | return wapi_set_addr(sock, ifname, SIOCSIFADDR, addr); 129 | } 130 | 131 | 132 | int 133 | wapi_get_netmask(int sock, const char *ifname, struct in_addr *addr) 134 | { 135 | return wapi_get_addr(sock, ifname, SIOCGIFNETMASK, addr); 136 | } 137 | 138 | 139 | int 140 | wapi_set_netmask(int sock, const char *ifname, const struct in_addr *addr) 141 | { 142 | return wapi_set_addr(sock, ifname, SIOCSIFNETMASK, addr); 143 | } 144 | 145 | 146 | /*-- Routing -----------------------------------------------------------------*/ 147 | 148 | 149 | int 150 | wapi_get_routes(wapi_list_t *list) 151 | { 152 | FILE *fp; 153 | int ret; 154 | size_t bufsiz = WAPI_PROC_LINE_SIZE * sizeof(char); 155 | char buf[WAPI_PROC_LINE_SIZE]; 156 | 157 | WAPI_VALIDATE_PTR(list); 158 | 159 | /* Open file for reading. */ 160 | fp = fopen(WAPI_PROC_NET_ROUTE, "r"); 161 | if (!fp) 162 | { 163 | WAPI_STRERROR("fopen(\"%s\", \"r\")", WAPI_PROC_NET_ROUTE); 164 | return -1; 165 | } 166 | 167 | /* Skip header line. */ 168 | if (!fgets(buf, bufsiz, fp)) 169 | { 170 | WAPI_ERROR("Invalid \"%s\" content!\n", WAPI_PROC_NET_ROUTE); 171 | return -1; 172 | } 173 | 174 | /* Read lines. */ 175 | ret = 0; 176 | while (fgets(buf, bufsiz, fp)) 177 | { 178 | wapi_route_info_t *ri; 179 | char ifname[WAPI_PROC_LINE_SIZE]; 180 | int refcnt, use, metric, mtu, window, irtt; 181 | unsigned int dest, gw, flags, netmask; 182 | 183 | /* Allocate route row buffer. */ 184 | ri = malloc(sizeof(wapi_route_info_t)); 185 | if (!ri) 186 | { 187 | WAPI_STRERROR("malloc()"); 188 | ret = -1; 189 | break; 190 | } 191 | 192 | /* Read and tokenize fields. */ 193 | sscanf( 194 | buf, 195 | "%s\t" /* ifname */ 196 | "%x\t" /* dest */ 197 | "%x\t" /* gw */ 198 | "%x\t" /* flags */ 199 | "%d\t" /* refcnt */ 200 | "%d\t" /* use */ 201 | "%d\t" /* metric */ 202 | "%x\t" /* mask */ 203 | "%d\t" /* mtu */ 204 | "%d\t" /* window */ 205 | "%d\t", /* irtt */ 206 | ifname, &dest, &gw, &flags, &refcnt, &use, &metric, &netmask, &mtu, 207 | &window, &irtt); 208 | 209 | /* Allocate "ifname". */ 210 | ri->ifname = malloc((strlen(ifname) + 1) * sizeof(char)); 211 | if (!ri->ifname) 212 | { 213 | WAPI_STRERROR("malloc()"); 214 | free(ri); 215 | ret = -1; 216 | break; 217 | } 218 | 219 | /* Copy fields. */ 220 | sprintf(ri->ifname, "%s", ifname); 221 | ri->dest.s_addr = dest; 222 | ri->gw.s_addr = gw; 223 | ri->flags = flags; 224 | ri->refcnt = refcnt; 225 | ri->use = use; 226 | ri->metric = metric; 227 | ri->netmask.s_addr = netmask; 228 | ri->mtu = mtu; 229 | ri->window = window; 230 | ri->irtt = irtt; 231 | 232 | /* Push parsed node to the list. */ 233 | ri->next = list->head.route; 234 | list->head.route = ri; 235 | } 236 | 237 | /* Close file. */ 238 | fclose(fp); 239 | 240 | return 0; 241 | } 242 | 243 | 244 | static int 245 | wapi_act_route_gw( 246 | int sock, 247 | int act, 248 | wapi_route_target_t targettype, 249 | const struct in_addr *target, 250 | const struct in_addr *netmask, 251 | const struct in_addr *gw) 252 | { 253 | int ret; 254 | struct rtentry rt; 255 | struct sockaddr_in *sin; 256 | 257 | /* Clean out rtentry. */ 258 | bzero(&rt, sizeof(struct rtentry)); 259 | 260 | /* Set target. */ 261 | sin = (struct sockaddr_in *) &rt.rt_dst; 262 | sin->sin_family = AF_INET; 263 | memcpy(&sin->sin_addr, target, sizeof(struct in_addr)); 264 | 265 | /* Set netmask. */ 266 | sin = (struct sockaddr_in *) &rt.rt_genmask; 267 | sin->sin_family = AF_INET; 268 | memcpy(&sin->sin_addr, netmask, sizeof(struct in_addr)); 269 | 270 | /* Set gateway. */ 271 | sin = (struct sockaddr_in *) &rt.rt_gateway; 272 | sin->sin_family = AF_INET; 273 | memcpy(&sin->sin_addr, gw, sizeof(struct in_addr)); 274 | 275 | /* Set rt_flags. */ 276 | rt.rt_flags = RTF_UP | RTF_GATEWAY; 277 | if (targettype == WAPI_ROUTE_TARGET_HOST) rt.rt_flags |= RTF_HOST; 278 | 279 | if ((ret = ioctl(sock, act, &rt)) < 0) 280 | WAPI_IOCTL_STRERROR(act); 281 | 282 | return ret; 283 | } 284 | 285 | 286 | int 287 | wapi_add_route_gw( 288 | int sock, 289 | wapi_route_target_t targettype, 290 | const struct in_addr *target, 291 | const struct in_addr *netmask, 292 | const struct in_addr *gw) 293 | { 294 | return wapi_act_route_gw(sock, SIOCADDRT, targettype, target, netmask, gw); 295 | } 296 | 297 | 298 | int 299 | wapi_del_route_gw( 300 | int sock, 301 | wapi_route_target_t targettype, 302 | const struct in_addr *target, 303 | const struct in_addr *netmask, 304 | const struct in_addr *gw) 305 | { 306 | return wapi_act_route_gw(sock, SIOCDELRT, targettype, target, netmask, gw); 307 | } 308 | -------------------------------------------------------------------------------- /src/util.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * Utility routines. 4 | */ 5 | 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include "wapi.h" 15 | #include "util.h" 16 | 17 | 18 | int 19 | wapi_make_socket(void) 20 | { 21 | int ret = socket(AF_INET, SOCK_DGRAM, 0); 22 | if (ret < 0) WAPI_STRERROR("socket(AF_INET, SOCK_DGRAM, 0)"); 23 | return ret; 24 | } 25 | 26 | 27 | int 28 | wapi_get_ifnames(wapi_list_t *list) 29 | { 30 | FILE *fp; 31 | int ret; 32 | size_t tmpsize = WAPI_PROC_LINE_SIZE * sizeof(char); 33 | char tmp[WAPI_PROC_LINE_SIZE]; 34 | 35 | WAPI_VALIDATE_PTR(list); 36 | 37 | /* Open file for reading. */ 38 | fp = fopen(WAPI_PROC_NET_WIRELESS, "r"); 39 | if (!fp) 40 | { 41 | WAPI_STRERROR("fopen(\"%s\", \"r\")", WAPI_PROC_NET_WIRELESS); 42 | return -1; 43 | } 44 | 45 | /* Skip first two lines. */ 46 | if (!fgets(tmp, tmpsize, fp) || ! fgets(tmp, tmpsize, fp)) 47 | { 48 | WAPI_ERROR("Invalid \"%s\" content!\n", WAPI_PROC_NET_WIRELESS); 49 | return -1; 50 | } 51 | 52 | /* Iterate over available lines. */ 53 | ret = 0; 54 | while (fgets(tmp, tmpsize, fp)) 55 | { 56 | char *beg; 57 | char *end; 58 | wapi_string_t *string; 59 | 60 | /* Locate the interface name region. */ 61 | for (beg = tmp; *beg && isspace(*beg); beg++); 62 | for (end = beg; *end && *end != ':'; end++); 63 | 64 | /* Allocate both wapi_string_t and char vector. */ 65 | string = malloc(sizeof(wapi_string_t)); 66 | if (string) string->data = malloc(end - beg + sizeof(char)); 67 | if (!string || !string->data) 68 | { 69 | WAPI_STRERROR("malloc()"); 70 | ret = -1; 71 | break; 72 | } 73 | 74 | /* Copy region into the buffer. */ 75 | snprintf(string->data, (end - beg + sizeof(char)), "%s", beg); 76 | 77 | /* Push string into the list. */ 78 | string->next = list->head.string; 79 | list->head.string = string; 80 | } 81 | 82 | fclose(fp); 83 | return ret; 84 | } 85 | 86 | 87 | #define wapi_ioctl_command_name_bufsiz 128 /* Is fairly enough to print an integer. */ 88 | static char wapi_ioctl_command_name_buf[wapi_ioctl_command_name_bufsiz]; 89 | 90 | 91 | const char * 92 | wapi_ioctl_command_name(int cmd) 93 | { 94 | switch (cmd) 95 | { 96 | case SIOCADDRT: return "SIOCADDRT"; 97 | case SIOCDELRT: return "SIOCDELRT"; 98 | case SIOCGIFADDR: return "SIOCGIFADDR"; 99 | case SIOCGIWAP: return "SIOCGIWAP"; 100 | case SIOCGIWESSID: return "SIOCGIWESSID"; 101 | case SIOCGIWFREQ: return "SIOCGIWFREQ"; 102 | case SIOCGIWMODE: return "SIOCGIWMODE"; 103 | case SIOCGIWRANGE: return "SIOCGIWRANGE"; 104 | case SIOCGIWRATE: return "SIOCGIWRATE"; 105 | case SIOCGIWSCAN: return "SIOCGIWSCAN"; 106 | case SIOCGIWTXPOW: return "SIOCGIWTXPOW"; 107 | case SIOCSIFADDR: return "SIOCSIFADDR"; 108 | case SIOCSIWAP: return "SIOCSIWAP"; 109 | case SIOCSIWESSID: return "SIOCSIWESSID"; 110 | case SIOCSIWFREQ: return "SIOCSIWFREQ"; 111 | case SIOCSIWMODE: return "SIOCSIWMODE"; 112 | case SIOCSIWRATE: return "SIOCSIWRATE"; 113 | case SIOCSIWSCAN: return "SIOCSIWSCAN"; 114 | case SIOCSIWTXPOW: return "SIOCSIWTXPOW"; 115 | default: 116 | snprintf( 117 | wapi_ioctl_command_name_buf, wapi_ioctl_command_name_bufsiz, 118 | "0x%x", cmd); 119 | return wapi_ioctl_command_name_buf; 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /src/util.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * Utility macros & declarations. 4 | */ 5 | 6 | 7 | #ifndef UTIL_H 8 | #define UTIL_H 9 | 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | 16 | #define WAPI_IOCTL_STRERROR(cmd) \ 17 | fprintf( \ 18 | stderr, "%s:%d:%s():ioctl(%s): %s\n", \ 19 | basename(__FILE__), __LINE__, __func__, \ 20 | wapi_ioctl_command_name(cmd), strerror(errno)) 21 | 22 | 23 | #define WAPI_STRERROR(fmt, ...) \ 24 | fprintf( \ 25 | stderr, "%s:%d:%s():" fmt ": %s\n", \ 26 | basename(__FILE__), __LINE__, __func__, \ 27 | ## __VA_ARGS__, strerror(errno)) 28 | 29 | 30 | #define WAPI_ERROR(fmt, ...) \ 31 | fprintf( \ 32 | stderr, "%s:%d:%s(): " fmt , \ 33 | basename(__FILE__), __LINE__, __func__, ## __VA_ARGS__) 34 | 35 | 36 | #define WAPI_VALIDATE_PTR(ptr) \ 37 | if (!ptr) \ 38 | { \ 39 | WAPI_ERROR("Null pointer: %s.\n", #ptr); \ 40 | return -1; \ 41 | } 42 | 43 | 44 | const char *wapi_ioctl_command_name(int cmd); 45 | 46 | 47 | #endif /* UTIL_H */ 48 | -------------------------------------------------------------------------------- /src/wireless.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * Wireless network interface accessors. 4 | */ 5 | 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #include 19 | 20 | #include "wapi.h" 21 | #include "util.h" 22 | 23 | 24 | /*-- Misc --------------------------------------------------------------------*/ 25 | 26 | 27 | int 28 | wapi_get_we_version(int sock, const char *ifname, int *we_version) 29 | { 30 | struct iwreq wrq; 31 | char buf[sizeof(struct iw_range) * 2]; 32 | int ret; 33 | 34 | WAPI_VALIDATE_PTR(we_version); 35 | 36 | /* Prepare request. */ 37 | bzero(buf, sizeof(buf)); 38 | wrq.u.data.pointer = buf; 39 | wrq.u.data.length = sizeof(buf); 40 | wrq.u.data.flags = 0; 41 | 42 | /* Get WE version. */ 43 | strncpy(wrq.ifr_name, ifname, IFNAMSIZ); 44 | if ((ret = ioctl(sock, SIOCGIWRANGE, &wrq)) >= 0) 45 | { 46 | struct iw_range *range = (struct iw_range *) buf; 47 | *we_version = (int) range->we_version_compiled; 48 | } 49 | else WAPI_IOCTL_STRERROR(SIOCGIWRANGE); 50 | 51 | return ret; 52 | } 53 | 54 | 55 | /*-- Frequency ---------------------------------------------------------------*/ 56 | 57 | 58 | const char *wapi_freq_flags[] = { 59 | "WAPI_FREQ_AUTO", 60 | "WAPI_FREQ_FIXED" 61 | }; 62 | 63 | 64 | /** 65 | * Converts internal representation of frequencies to a floating point. 66 | */ 67 | static inline double 68 | wapi_freq2float(const struct iw_freq *freq) 69 | { 70 | return ((double) freq->m) * pow(10, freq->e); 71 | } 72 | 73 | 74 | /** 75 | * Converts a floating point the our internal representation of frequencies. 76 | */ 77 | static inline void 78 | wapi_float2freq(double floatfreq, struct iw_freq *freq) 79 | { 80 | freq->e = (short) floor(log10(floatfreq)); 81 | if (freq->e > 8) 82 | { 83 | freq->m = ((long) (floor(floatfreq / pow(10,freq->e - 6)))) * 100; 84 | freq->e -= 8; 85 | } 86 | else 87 | { 88 | freq->m = (long) floatfreq; 89 | freq->e = 0; 90 | } 91 | } 92 | 93 | 94 | int 95 | wapi_get_freq(int sock, const char *ifname, double *freq, wapi_freq_flag_t *flag) 96 | { 97 | struct iwreq wrq; 98 | int ret; 99 | 100 | WAPI_VALIDATE_PTR(freq); 101 | WAPI_VALIDATE_PTR(flag); 102 | 103 | strncpy(wrq.ifr_name, ifname, IFNAMSIZ); 104 | if ((ret = ioctl(sock, SIOCGIWFREQ, &wrq)) >= 0) 105 | { 106 | /* Set flag. */ 107 | if (IW_FREQ_AUTO == (wrq.u.freq.flags & IW_FREQ_AUTO)) 108 | *flag = WAPI_FREQ_AUTO; 109 | else if (IW_FREQ_FIXED == (wrq.u.freq.flags & IW_FREQ_FIXED)) 110 | *flag = WAPI_FREQ_FIXED; 111 | else 112 | { 113 | WAPI_ERROR("Unknown flag: %d.\n", wrq.u.freq.flags); 114 | return -1; 115 | } 116 | 117 | /* Set freq. */ 118 | *freq = wapi_freq2float(&(wrq.u.freq)); 119 | } 120 | 121 | return ret; 122 | } 123 | 124 | 125 | int 126 | wapi_set_freq(int sock, const char *ifname, double freq, wapi_freq_flag_t flag) 127 | { 128 | struct iwreq wrq; 129 | int ret; 130 | 131 | /* Set freq. */ 132 | wapi_float2freq(freq, &(wrq.u.freq)); 133 | 134 | /* Set flag. */ 135 | switch (flag) 136 | { 137 | case WAPI_FREQ_AUTO: 138 | wrq.u.freq.flags = IW_FREQ_AUTO; 139 | break; 140 | case WAPI_FREQ_FIXED: 141 | wrq.u.freq.flags = IW_FREQ_FIXED; 142 | break; 143 | } 144 | 145 | strncpy(wrq.ifr_name, ifname, IFNAMSIZ); 146 | ret = ioctl(sock, SIOCSIWFREQ, &wrq); 147 | if (ret < 0) WAPI_IOCTL_STRERROR(SIOCSIWFREQ); 148 | 149 | return ret; 150 | } 151 | 152 | 153 | int 154 | wapi_freq2chan(int sock, const char *ifname, double freq, int *chan) 155 | { 156 | struct iwreq wrq; 157 | char buf[sizeof(struct iw_range) * 2]; 158 | int ret; 159 | 160 | WAPI_VALIDATE_PTR(chan); 161 | 162 | /* Prepare request. */ 163 | bzero(buf, sizeof(buf)); 164 | wrq.u.data.pointer = buf; 165 | wrq.u.data.length = sizeof(buf); 166 | wrq.u.data.flags = 0; 167 | 168 | /* Get range. */ 169 | strncpy(wrq.ifr_name, ifname, IFNAMSIZ); 170 | if ((ret = ioctl(sock, SIOCGIWRANGE, &wrq)) >= 0) 171 | { 172 | struct iw_range *range = (struct iw_range *) buf; 173 | int k; 174 | 175 | /* Compare the frequencies as double to ignore differences in encoding. 176 | * Slower, but safer... */ 177 | for (k = 0; k < range->num_frequency; k++) 178 | if (freq == wapi_freq2float(&(range->freq[k]))) 179 | { 180 | *chan = range->freq[k].i; 181 | return 0; 182 | } 183 | 184 | /* Oops! Nothing found. */ 185 | WAPI_ERROR("No channel matches for the given frequency!\n"); 186 | ret = -2; 187 | } 188 | else WAPI_IOCTL_STRERROR(SIOCGIWRANGE); 189 | 190 | return ret; 191 | } 192 | 193 | 194 | int 195 | wapi_chan2freq(int sock, const char *ifname, int chan, double *freq) 196 | { 197 | struct iwreq wrq; 198 | char buf[sizeof(struct iw_range) * 2]; 199 | int ret; 200 | 201 | WAPI_VALIDATE_PTR(freq); 202 | 203 | /* Prepare request. */ 204 | bzero(buf, sizeof(buf)); 205 | wrq.u.data.pointer = buf; 206 | wrq.u.data.length = sizeof(buf); 207 | wrq.u.data.flags = 0; 208 | 209 | /* Get range. */ 210 | strncpy(wrq.ifr_name, ifname, IFNAMSIZ); 211 | if ((ret = ioctl(sock, SIOCGIWRANGE, &wrq)) >= 0) 212 | { 213 | struct iw_range *range = (struct iw_range *) buf; 214 | int k; 215 | 216 | for (k = 0; k < range->num_frequency; k++) 217 | if (chan == range->freq[k].i) 218 | { 219 | *freq = wapi_freq2float(&(range->freq[k])); 220 | return 0; 221 | } 222 | 223 | /* Oops! Nothing found. */ 224 | WAPI_ERROR("No frequency matches for the given channel!\n"); 225 | ret = -2; 226 | } 227 | else WAPI_IOCTL_STRERROR(SIOCGIWRANGE); 228 | 229 | return ret; 230 | } 231 | 232 | 233 | /*-- ESSID -------------------------------------------------------------------*/ 234 | 235 | 236 | const char *wapi_essid_flags[] = { 237 | "WAPI_ESSID_ON", 238 | "WAPI_ESSID_OFF" 239 | }; 240 | 241 | 242 | int 243 | wapi_get_essid( 244 | int sock, 245 | const char *ifname, 246 | char *essid, 247 | wapi_essid_flag_t *flag) 248 | { 249 | struct iwreq wrq; 250 | int ret; 251 | 252 | WAPI_VALIDATE_PTR(essid); 253 | WAPI_VALIDATE_PTR(flag); 254 | 255 | wrq.u.essid.pointer = essid; 256 | wrq.u.essid.length = WAPI_ESSID_MAX_SIZE + 1; 257 | wrq.u.essid.flags = 0; 258 | 259 | strncpy(wrq.ifr_name, ifname, IFNAMSIZ); 260 | ret = ioctl(sock, SIOCGIWESSID, &wrq); 261 | if (ret < 0) WAPI_IOCTL_STRERROR(SIOCGIWESSID); 262 | else *flag = (wrq.u.essid.flags) ? WAPI_ESSID_ON : WAPI_ESSID_OFF; 263 | 264 | return ret; 265 | } 266 | 267 | 268 | int 269 | wapi_set_essid( 270 | int sock, 271 | const char *ifname, 272 | const char *essid, 273 | wapi_essid_flag_t flag) 274 | { 275 | char buf[WAPI_ESSID_MAX_SIZE + 1]; 276 | struct iwreq wrq; 277 | int ret; 278 | 279 | /* Prepare request. */ 280 | wrq.u.essid.pointer = buf; 281 | wrq.u.essid.length = 282 | snprintf(buf, ((WAPI_ESSID_MAX_SIZE + 1) * sizeof(char)), "%s", essid); 283 | wrq.u.essid.flags = (flag == WAPI_ESSID_ON); 284 | 285 | strncpy(wrq.ifr_name, ifname, IFNAMSIZ); 286 | ret = ioctl(sock, SIOCSIWESSID, &wrq); 287 | if (ret < 0) WAPI_IOCTL_STRERROR(SIOCSIWESSID); 288 | 289 | return ret; 290 | } 291 | 292 | 293 | /*-- Operating Mode ----------------------------------------------------------*/ 294 | 295 | 296 | const char *wapi_modes[] = { 297 | "WAPI_MODE_AUTO", 298 | "WAPI_MODE_ADHOC", 299 | "WAPI_MODE_MANAGED", 300 | "WAPI_MODE_MASTER", 301 | "WAPI_MODE_REPEAT", 302 | "WAPI_MODE_SECOND", 303 | "WAPI_MODE_MONITOR" 304 | }; 305 | 306 | 307 | static int 308 | wapi_parse_mode(int iw_mode, wapi_mode_t *wapi_mode) 309 | { 310 | switch (iw_mode) 311 | { 312 | case WAPI_MODE_AUTO: 313 | case WAPI_MODE_ADHOC: 314 | case WAPI_MODE_MANAGED: 315 | case WAPI_MODE_MASTER: 316 | case WAPI_MODE_REPEAT: 317 | case WAPI_MODE_SECOND: 318 | case WAPI_MODE_MONITOR: 319 | *wapi_mode = iw_mode; 320 | return 0; 321 | 322 | default: 323 | WAPI_ERROR("Unknown mode: %d.\n", iw_mode); 324 | return -1; 325 | } 326 | } 327 | 328 | 329 | int 330 | wapi_get_mode(int sock, const char *ifname, wapi_mode_t *mode) 331 | { 332 | struct iwreq wrq; 333 | int ret; 334 | 335 | WAPI_VALIDATE_PTR(mode); 336 | 337 | strncpy(wrq.ifr_name, ifname, IFNAMSIZ); 338 | if ((ret = ioctl(sock, SIOCGIWMODE, &wrq)) >= 0) 339 | ret = wapi_parse_mode(wrq.u.mode, mode); 340 | else WAPI_IOCTL_STRERROR(SIOCGIWMODE); 341 | 342 | return ret; 343 | } 344 | 345 | 346 | int 347 | wapi_set_mode(int sock, const char *ifname, wapi_mode_t mode) 348 | { 349 | struct iwreq wrq; 350 | int ret; 351 | 352 | wrq.u.mode = mode; 353 | 354 | strncpy(wrq.ifr_name, ifname, IFNAMSIZ); 355 | ret = ioctl(sock, SIOCSIWMODE, &wrq); 356 | if (ret < 0) WAPI_IOCTL_STRERROR(SIOCSIWMODE); 357 | 358 | return ret; 359 | } 360 | 361 | 362 | /*-- Access Point ------------------------------------------------------------*/ 363 | 364 | 365 | static int 366 | wapi_make_ether(struct ether_addr *addr, int byte) 367 | { 368 | WAPI_VALIDATE_PTR(addr); 369 | memset(addr, byte, sizeof(struct ether_addr)); 370 | return 0; 371 | } 372 | 373 | 374 | int 375 | wapi_make_broad_ether(struct ether_addr *addr) 376 | { 377 | return wapi_make_ether(addr, 0xFF); 378 | } 379 | 380 | 381 | int 382 | wapi_make_null_ether(struct ether_addr *sa) 383 | { 384 | return wapi_make_ether(sa, 0x00); 385 | } 386 | 387 | 388 | int 389 | wapi_get_ap(int sock, const char *ifname, struct ether_addr *ap) 390 | { 391 | struct iwreq wrq; 392 | int ret; 393 | 394 | WAPI_VALIDATE_PTR(ap); 395 | 396 | strncpy(wrq.ifr_name, ifname, IFNAMSIZ); 397 | if ((ret = ioctl(sock, SIOCGIWAP, &wrq)) >= 0) 398 | memcpy(ap, wrq.u.ap_addr.sa_data, sizeof(struct ether_addr)); 399 | else WAPI_IOCTL_STRERROR(SIOCGIWAP); 400 | 401 | return ret; 402 | } 403 | 404 | 405 | int 406 | wapi_set_ap(int sock, const char *ifname, const struct ether_addr *ap) 407 | { 408 | struct iwreq wrq; 409 | int ret; 410 | 411 | WAPI_VALIDATE_PTR(ap); 412 | 413 | wrq.u.ap_addr.sa_family = ARPHRD_ETHER; 414 | memcpy(wrq.u.ap_addr.sa_data, ap, sizeof(struct ether_addr)); 415 | strncpy(wrq.ifr_name, ifname, IFNAMSIZ); 416 | ret = ioctl(sock, SIOCSIWAP, &wrq); 417 | if (ret < 0) WAPI_IOCTL_STRERROR(SIOCSIWAP); 418 | 419 | return ret; 420 | } 421 | 422 | 423 | /*-- Bit Rate ----------------------------------------------------------------*/ 424 | 425 | 426 | const char *wapi_bitrate_flags[] = { 427 | "WAPI_BITRATE_AUTO", 428 | "WAPI_BITRATE_FIXED" 429 | }; 430 | 431 | 432 | int 433 | wapi_get_bitrate( 434 | int sock, 435 | const char *ifname, 436 | int *bitrate, 437 | wapi_bitrate_flag_t *flag) 438 | { 439 | struct iwreq wrq; 440 | int ret; 441 | 442 | WAPI_VALIDATE_PTR(bitrate); 443 | WAPI_VALIDATE_PTR(flag); 444 | 445 | strncpy(wrq.ifr_name, ifname, IFNAMSIZ); 446 | if ((ret = ioctl(sock, SIOCGIWRATE, &wrq)) >= 0) 447 | { 448 | /* Check if enabled. */ 449 | if (wrq.u.bitrate.disabled) 450 | { 451 | WAPI_ERROR("Bitrate is disabled.\n"); 452 | return -1; 453 | } 454 | 455 | /* Get bitrate. */ 456 | *bitrate = wrq.u.bitrate.value; 457 | *flag = wrq.u.bitrate.fixed ? WAPI_BITRATE_FIXED : WAPI_BITRATE_AUTO; 458 | } 459 | else WAPI_IOCTL_STRERROR(SIOCGIWRATE); 460 | 461 | return ret; 462 | } 463 | 464 | 465 | int 466 | wapi_set_bitrate( 467 | int sock, 468 | const char *ifname, 469 | int bitrate, 470 | wapi_bitrate_flag_t flag) 471 | { 472 | struct iwreq wrq; 473 | int ret; 474 | 475 | wrq.u.bitrate.value = bitrate; 476 | wrq.u.bitrate.fixed = (flag == WAPI_BITRATE_FIXED); 477 | 478 | strncpy(wrq.ifr_name, ifname, IFNAMSIZ); 479 | ret = ioctl(sock, SIOCSIWRATE, &wrq); 480 | if (ret < 0) WAPI_IOCTL_STRERROR(SIOCSIWRATE); 481 | 482 | return ret; 483 | } 484 | 485 | 486 | /*-- Transmit Power ----------------------------------------------------------*/ 487 | 488 | 489 | const char *wapi_txpower_flags[] = { 490 | "WAPI_TXPOWER_DBM", 491 | "WAPI_TXPOWER_MWATT", 492 | "WAPI_TXPOWER_RELATIVE" 493 | }; 494 | 495 | 496 | int 497 | wapi_dbm2mwatt(int dbm) 498 | { 499 | return floor(pow(10, (((double) dbm) / 10))); 500 | } 501 | 502 | 503 | int 504 | wapi_mwatt2dbm(int mwatt) 505 | { 506 | return ceil(10 * log10(mwatt)); 507 | } 508 | 509 | 510 | int 511 | wapi_get_txpower( 512 | int sock, 513 | const char *ifname, 514 | int *power, 515 | wapi_txpower_flag_t *flag) 516 | { 517 | struct iwreq wrq; 518 | int ret; 519 | 520 | WAPI_VALIDATE_PTR(power); 521 | WAPI_VALIDATE_PTR(flag); 522 | 523 | strncpy(wrq.ifr_name, ifname, IFNAMSIZ); 524 | if ((ret = ioctl(sock, SIOCGIWTXPOW, &wrq)) >= 0) 525 | { 526 | /* Check if enabled. */ 527 | if (wrq.u.txpower.disabled) 528 | return -1; 529 | 530 | /* Get flag. */ 531 | if (IW_TXPOW_DBM == (wrq.u.txpower.flags & IW_TXPOW_DBM)) 532 | *flag = WAPI_TXPOWER_DBM; 533 | else if (IW_TXPOW_MWATT == (wrq.u.txpower.flags & IW_TXPOW_MWATT)) 534 | *flag = WAPI_TXPOWER_MWATT; 535 | else if (IW_TXPOW_RELATIVE == (wrq.u.txpower.flags & IW_TXPOW_RELATIVE)) 536 | *flag = WAPI_TXPOWER_RELATIVE; 537 | else 538 | { 539 | WAPI_ERROR("Unknown flag: %d.\n", wrq.u.txpower.flags); 540 | return -1; 541 | } 542 | 543 | /* Get power. */ 544 | *power = wrq.u.txpower.value; 545 | } 546 | else WAPI_IOCTL_STRERROR(SIOCGIWTXPOW); 547 | 548 | return ret; 549 | } 550 | 551 | 552 | int 553 | wapi_set_txpower( 554 | int sock, 555 | const char *ifname, 556 | int power, 557 | wapi_txpower_flag_t flag) 558 | { 559 | struct iwreq wrq; 560 | int ret; 561 | 562 | /* Construct the request. */ 563 | wrq.u.txpower.value = power; 564 | switch (flag) 565 | { 566 | case WAPI_TXPOWER_DBM: 567 | wrq.u.txpower.flags = IW_TXPOW_DBM; 568 | break; 569 | case WAPI_TXPOWER_MWATT: 570 | wrq.u.txpower.flags = IW_TXPOW_MWATT; 571 | break; 572 | case WAPI_TXPOWER_RELATIVE: 573 | wrq.u.txpower.flags = IW_TXPOW_RELATIVE; 574 | break; 575 | } 576 | 577 | /* Issue the set command. */ 578 | strncpy(wrq.ifr_name, ifname, IFNAMSIZ); 579 | ret = ioctl(sock, SIOCSIWTXPOW, &wrq); 580 | if (ret < 0) WAPI_IOCTL_STRERROR(SIOCSIWTXPOW); 581 | 582 | return ret; 583 | } 584 | 585 | 586 | /*-- Event & Stream Routines -------------------------------------------------*/ 587 | 588 | 589 | struct iw_event_stream { 590 | char *end; /* end of the stream */ 591 | char *current; /* current event in stream of events */ 592 | char *value; /* current value in event */ 593 | }; 594 | 595 | 596 | static void 597 | iw_event_stream_init(struct iw_event_stream *stream, char *data, size_t len) 598 | { 599 | memset(stream, 0, sizeof(struct iw_event_stream)); 600 | stream->current = data; 601 | stream->end = &data[len]; 602 | } 603 | 604 | 605 | static int 606 | iw_event_stream_pop( 607 | struct iw_event_stream *stream, 608 | struct iw_event *iwe, 609 | int we_version) 610 | { 611 | return iw_extract_event_stream( 612 | (struct stream_descr *) stream, iwe, we_version); 613 | } 614 | 615 | 616 | /*-- Scanning ----------------------------------------------------------------*/ 617 | 618 | 619 | int 620 | wapi_scan_init(int sock, const char *ifname) 621 | { 622 | struct iwreq wrq; 623 | int ret; 624 | 625 | wrq.u.data.pointer = NULL; 626 | wrq.u.data.flags = 0; 627 | wrq.u.data.length = 0; 628 | 629 | strncpy(wrq.ifr_name, ifname, IFNAMSIZ); 630 | ret = ioctl(sock, SIOCSIWSCAN, &wrq); 631 | if (ret < 0) WAPI_IOCTL_STRERROR(SIOCSIWSCAN); 632 | 633 | return ret; 634 | } 635 | 636 | 637 | int 638 | wapi_scan_stat(int sock, const char *ifname) 639 | { 640 | struct iwreq wrq; 641 | int ret; 642 | char buf; 643 | 644 | wrq.u.data.pointer = &buf; 645 | wrq.u.data.flags = 0; 646 | wrq.u.data.length = 0; 647 | 648 | strncpy(wrq.ifr_name, ifname, IFNAMSIZ); 649 | if ((ret = ioctl(sock, SIOCGIWSCAN, &wrq)) < 0) 650 | { 651 | if (errno == E2BIG) 652 | /* Data is ready, but not enough space, which is expected. */ 653 | return 0; 654 | else if (errno == EAGAIN) 655 | /* Data is not ready. */ 656 | return 1; 657 | 658 | printf("err[%d]: %s\n", errno, strerror(errno)); 659 | } 660 | else WAPI_IOCTL_STRERROR(SIOCGIWSCAN); 661 | 662 | return ret; 663 | } 664 | 665 | 666 | static int 667 | wapi_scan_event(struct iw_event *event, wapi_list_t *list) 668 | { 669 | wapi_scan_info_t *info; 670 | 671 | /* Get current "wapi_info_t". */ 672 | info = list->head.scan; 673 | 674 | /* Decode the event. */ 675 | switch (event->cmd) 676 | { 677 | case SIOCGIWAP: 678 | { 679 | wapi_scan_info_t *temp; 680 | 681 | /* Allocate a new cell. */ 682 | temp = malloc(sizeof(wapi_scan_info_t)); 683 | if (!temp) 684 | { 685 | WAPI_STRERROR("malloc()"); 686 | return -1; 687 | } 688 | 689 | /* Reset it. */ 690 | bzero(temp, sizeof(wapi_scan_info_t)); 691 | 692 | /* Save cell identifier. */ 693 | memcpy(&temp->ap, &event->u.ap_addr.sa_data, sizeof(struct ether_addr)); 694 | 695 | /* Push it to the head of the list. */ 696 | temp->next = info; 697 | list->head.scan = temp; 698 | 699 | break; 700 | } 701 | 702 | case SIOCGIWFREQ: 703 | info->has_freq = 1; 704 | info->freq = wapi_freq2float(&(event->u.freq)); 705 | break; 706 | 707 | case SIOCGIWMODE: 708 | { 709 | int ret = wapi_parse_mode(event->u.mode, &info->mode); 710 | if (ret >= 0) 711 | { 712 | info->has_mode = 1; 713 | break; 714 | } 715 | else return ret; 716 | } 717 | 718 | case SIOCGIWESSID: 719 | info->has_essid = 1; 720 | info->essid_flag = (event->u.data.flags) ? WAPI_ESSID_ON : WAPI_ESSID_OFF; 721 | memset(info->essid, 0, (WAPI_ESSID_MAX_SIZE + 1)); 722 | if ((event->u.essid.pointer) && (event->u.essid.length)) 723 | memcpy(info->essid, event->u.essid.pointer, event->u.essid.length); 724 | break; 725 | 726 | case SIOCGIWRATE: 727 | /* Scan may return a list of bitrates. As we have space for only a 728 | * single bitrate, we only keep the largest one. */ 729 | if (!info->has_bitrate || event->u.bitrate.value > info->bitrate) 730 | { 731 | info->has_bitrate = 1; 732 | info->bitrate = event->u.bitrate.value; 733 | } 734 | break; 735 | } 736 | 737 | return 0; 738 | } 739 | 740 | 741 | int 742 | wapi_scan_coll(int sock, const char *ifname, wapi_list_t *aps) 743 | { 744 | char *buf; 745 | int buflen; 746 | struct iwreq wrq; 747 | int we_version; 748 | int ret; 749 | 750 | WAPI_VALIDATE_PTR(aps); 751 | 752 | /* Get WE version. (Required for event extraction via libiw.) */ 753 | if ((ret = wapi_get_we_version(sock, ifname, &we_version)) < 0) 754 | return ret; 755 | 756 | buflen = IW_SCAN_MAX_DATA; 757 | buf = malloc(buflen * sizeof(char)); 758 | if (!buf) 759 | { 760 | WAPI_STRERROR("malloc()"); 761 | return -1; 762 | } 763 | 764 | alloc: 765 | /* Collect results. */ 766 | wrq.u.data.pointer = buf; 767 | wrq.u.data.length = buflen; 768 | wrq.u.data.flags = 0; 769 | strncpy(wrq.ifr_name, ifname, IFNAMSIZ); 770 | if ((ret = ioctl(sock, SIOCGIWSCAN, &wrq)) < 0 && errno == E2BIG) 771 | { 772 | char *tmp; 773 | 774 | buflen *= 2; 775 | tmp = realloc(buf, buflen); 776 | if (!tmp) 777 | { 778 | WAPI_STRERROR("realloc()"); 779 | free(buf); 780 | return -1; 781 | } 782 | 783 | buf = tmp; 784 | goto alloc; 785 | } 786 | 787 | /* There is still something wrong. It's either EAGAIN or some other ioctl() 788 | * failure. We don't bother, let the user deal with it. */ 789 | if (ret < 0) 790 | { 791 | WAPI_IOCTL_STRERROR(SIOCGIWSCAN); 792 | free(buf); 793 | return ret; 794 | } 795 | 796 | /* We have the results, process them. */ 797 | if (wrq.u.data.length) 798 | { 799 | struct iw_event iwe; 800 | struct iw_event_stream stream; 801 | 802 | iw_event_stream_init(&stream, buf, wrq.u.data.length); 803 | do { 804 | if ((ret = iw_event_stream_pop(&stream, &iwe, we_version)) >= 0) 805 | { 806 | int eventret = wapi_scan_event(&iwe, aps); 807 | if (eventret < 0) 808 | ret = eventret; 809 | } 810 | else WAPI_ERROR("iw_event_stream_pop() failed!\n"); 811 | } while (ret > 0); 812 | } 813 | 814 | /* Free request buffer. */ 815 | free(buf); 816 | 817 | return ret; 818 | } 819 | 820 | 821 | /*-- Add/Del Interface -------------------------------------------------------*/ 822 | 823 | 824 | typedef enum { 825 | WAPI_NL80211_CMD_IFADD, 826 | WAPI_NL80211_CMD_IFDEL 827 | } wapi_nl80211_cmd_t; 828 | 829 | 830 | typedef struct wapi_nl80211_ifadd_ctx_t { 831 | const char *name; 832 | wapi_mode_t mode; 833 | } wapi_nl80211_ifadd_ctx_t; 834 | 835 | 836 | typedef struct wapi_nl80211_ifdel_ctx_t { 837 | } wapi_nl80211_ifdel_ctx_t; 838 | 839 | 840 | typedef struct wapi_nl80211_ctx_t { 841 | const char *ifname; 842 | wapi_nl80211_cmd_t cmd; 843 | union { 844 | wapi_nl80211_ifadd_ctx_t ifadd; 845 | wapi_nl80211_ifdel_ctx_t ifdel; 846 | } u; 847 | } wapi_nl80211_ctx_t; 848 | 849 | 850 | #ifdef LIBNL1 851 | #define nl_sock nl_handle 852 | 853 | 854 | static struct nl_handle *nl_socket_alloc(void) 855 | { 856 | return nl_handle_alloc(); 857 | } 858 | 859 | 860 | static void nl_socket_free(struct nl_sock *h) 861 | { 862 | nl_handle_destroy(h); 863 | } 864 | #endif 865 | 866 | 867 | static int 868 | wapi_mode_to_iftype(wapi_mode_t mode, enum nl80211_iftype *type) 869 | { 870 | int ret = 0; 871 | 872 | switch (mode) 873 | { 874 | case WAPI_MODE_AUTO: *type = NL80211_IFTYPE_UNSPECIFIED; break; 875 | case WAPI_MODE_ADHOC: *type = NL80211_IFTYPE_ADHOC; break; 876 | case WAPI_MODE_MANAGED: *type = NL80211_IFTYPE_STATION; break; 877 | case WAPI_MODE_MASTER: *type = NL80211_IFTYPE_AP; break; 878 | case WAPI_MODE_MONITOR: *type = NL80211_IFTYPE_MONITOR; break; 879 | default: 880 | WAPI_ERROR( 881 | "No supported nl80211 iftype for mode: %s!\n", 882 | wapi_modes[mode]); 883 | ret = -1; 884 | } 885 | 886 | return ret; 887 | } 888 | 889 | 890 | static int 891 | nl80211_err_handler(struct sockaddr_nl *nla, struct nlmsgerr *err, void *arg) 892 | { 893 | int *ret = arg; 894 | *ret = err->error; 895 | return NL_STOP; 896 | } 897 | 898 | 899 | static int 900 | nl80211_fin_handler(struct nl_msg *msg, void *arg) 901 | { 902 | int *ret = arg; 903 | *ret = 0; 904 | return NL_SKIP; 905 | } 906 | 907 | 908 | static int 909 | nl80211_ack_handler(struct nl_msg *msg, void *arg) 910 | { 911 | int *ret = arg; 912 | *ret = 0; 913 | return NL_STOP; 914 | } 915 | 916 | 917 | static int 918 | nl80211_cmd_handler(const wapi_nl80211_ctx_t *ctx) 919 | { 920 | struct nl_sock *sock; 921 | struct nl_msg *msg; 922 | struct nl_cb *cb; 923 | int family; 924 | int ifidx; 925 | int ret; 926 | 927 | /* Allocate netlink socket. */ 928 | sock = nl_socket_alloc(); 929 | if (!sock) 930 | { 931 | WAPI_ERROR("Failed to allocate netlink socket!\n"); 932 | return -ENOMEM; 933 | } 934 | 935 | /* Reset "msg" and "cb". */ 936 | msg = NULL; 937 | cb = NULL; 938 | 939 | /* Connect to generic netlink socket on kernel side. */ 940 | if (genl_connect(sock)) 941 | { 942 | WAPI_ERROR("Failed to connect to generic netlink!\n"); 943 | ret = -ENOLINK; 944 | goto exit; 945 | } 946 | 947 | /* Ask kernel to resolve family name to family id. */ 948 | ret = family = genl_ctrl_resolve(sock, "nl80211"); 949 | if (ret < 0) 950 | { 951 | WAPI_ERROR("genl_ctrl_resolve() failed!\n"); 952 | goto exit; 953 | } 954 | 955 | /* Map given network interface name (ifname) to its corresponding index. */ 956 | ifidx = if_nametoindex(ctx->ifname); 957 | if (!ifidx) 958 | { 959 | WAPI_STRERROR("if_nametoindex(\"%s\")", ctx->ifname); 960 | ret = -errno; 961 | goto exit; 962 | } 963 | 964 | /* Construct a generic netlink by allocating a new message. */ 965 | msg = nlmsg_alloc(); 966 | if (!msg) 967 | { 968 | WAPI_ERROR("nlmsg_alloc() failed!\n"); 969 | ret = -ENOMEM; 970 | goto exit; 971 | } 972 | 973 | /* Append the requested command to the message. */ 974 | switch (ctx->cmd) 975 | { 976 | case WAPI_NL80211_CMD_IFADD: 977 | { 978 | enum nl80211_iftype iftype; 979 | 980 | genlmsg_put( 981 | msg, NL_AUTO_PID, NL_AUTO_SEQ, family, 0, 0, 982 | NL80211_CMD_NEW_INTERFACE, 0); 983 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifidx); 984 | 985 | /* Get NL80211_IFTYPE_* for the given WAPI mode. */ 986 | ret = wapi_mode_to_iftype(ctx->u.ifadd.mode, &iftype); 987 | if (ret < 0) goto exit; 988 | 989 | NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, ctx->u.ifadd.name); 990 | NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, iftype); 991 | 992 | break; 993 | } 994 | 995 | case WAPI_NL80211_CMD_IFDEL: 996 | genlmsg_put( 997 | msg, NL_AUTO_PID, NL_AUTO_SEQ, family, 0, 0, 998 | NL80211_CMD_DEL_INTERFACE, 0); 999 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifidx); 1000 | break; 1001 | } 1002 | 1003 | /* Finalize (send) the message. */ 1004 | ret = nl_send_auto_complete(sock, msg); 1005 | if (ret < 0) 1006 | { 1007 | WAPI_ERROR("nl_send_auto_complete() failed!\n"); 1008 | goto exit; 1009 | } 1010 | 1011 | /* Allocate a new callback handle. */ 1012 | cb = nl_cb_alloc(NL_CB_VERBOSE); 1013 | if (!cb) 1014 | { 1015 | WAPI_ERROR("nl_cb_alloc() failed\n"); 1016 | ret = -1; 1017 | goto exit; 1018 | } 1019 | 1020 | /* Configure callback handlers. */ 1021 | nl_cb_err(cb, NL_CB_CUSTOM, nl80211_err_handler, &ret); 1022 | nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, nl80211_fin_handler, &ret); 1023 | nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, nl80211_ack_handler, &ret); 1024 | 1025 | /* Consume netlink replies. */ 1026 | for (ret = 1; ret > 0; ) nl_recvmsgs(sock, cb); 1027 | if (ret) WAPI_ERROR("nl_recvmsgs() failed!\n"); 1028 | 1029 | exit: 1030 | /* Release resources and exit with "ret". */ 1031 | nl_socket_free(sock); 1032 | if (msg) nlmsg_free(msg); 1033 | if (cb) free(cb); 1034 | return ret; 1035 | 1036 | nla_put_failure: 1037 | WAPI_ERROR("nla_put_failure!\n"); 1038 | ret = -1; 1039 | goto exit; 1040 | } 1041 | 1042 | 1043 | int 1044 | wapi_if_add(int sock, const char *ifname, const char *name, wapi_mode_t mode) 1045 | { 1046 | wapi_nl80211_ctx_t ctx; 1047 | ctx.ifname = ifname; 1048 | ctx.cmd = WAPI_NL80211_CMD_IFADD; 1049 | ctx.u.ifadd.name = name; 1050 | ctx.u.ifadd.mode = mode; 1051 | return nl80211_cmd_handler(&ctx); 1052 | } 1053 | 1054 | 1055 | int 1056 | wapi_if_del(int sock, const char *ifname) 1057 | { 1058 | wapi_nl80211_ctx_t ctx; 1059 | ctx.ifname = ifname; 1060 | ctx.cmd = WAPI_NL80211_CMD_IFDEL; 1061 | return nl80211_cmd_handler(&ctx); 1062 | } 1063 | --------------------------------------------------------------------------------