From 8ae758db52957939eeb6bc1c7da7be9d0339d3aa Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Sun, 5 Oct 2014 19:56:27 +0200 Subject: Initial commit Signed-off-by: Jo-Philipp Wich --- include/iwinfo.h | 194 +++++++++++++++++++++++++++++++++++++++++++++++++ include/iwinfo/lua.h | 79 ++++++++++++++++++++ include/iwinfo/utils.h | 47 ++++++++++++ 3 files changed, 320 insertions(+) create mode 100644 include/iwinfo.h create mode 100644 include/iwinfo/lua.h create mode 100644 include/iwinfo/utils.h (limited to 'include') diff --git a/include/iwinfo.h b/include/iwinfo.h new file mode 100644 index 0000000..68d459b --- /dev/null +++ b/include/iwinfo.h @@ -0,0 +1,194 @@ +#ifndef __IWINFO_H_ +#define __IWINFO_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + + +#define IWINFO_BUFSIZE 24 * 1024 +#define IWINFO_ESSID_MAX_SIZE 32 + +#define IWINFO_80211_A (1 << 0) +#define IWINFO_80211_B (1 << 1) +#define IWINFO_80211_G (1 << 2) +#define IWINFO_80211_N (1 << 3) +#define IWINFO_80211_AC (1 << 4) + +#define IWINFO_CIPHER_NONE (1 << 0) +#define IWINFO_CIPHER_WEP40 (1 << 1) +#define IWINFO_CIPHER_TKIP (1 << 2) +#define IWINFO_CIPHER_WRAP (1 << 3) +#define IWINFO_CIPHER_CCMP (1 << 4) +#define IWINFO_CIPHER_WEP104 (1 << 5) +#define IWINFO_CIPHER_AESOCB (1 << 6) +#define IWINFO_CIPHER_CKIP (1 << 7) + +#define IWINFO_KMGMT_NONE (1 << 0) +#define IWINFO_KMGMT_8021x (1 << 1) +#define IWINFO_KMGMT_PSK (1 << 2) + +#define IWINFO_AUTH_OPEN (1 << 0) +#define IWINFO_AUTH_SHARED (1 << 1) + +extern const char *IWINFO_CIPHER_NAMES[]; +extern const char *IWINFO_KMGMT_NAMES[]; +extern const char *IWINFO_AUTH_NAMES[]; + + +enum iwinfo_opmode { + IWINFO_OPMODE_UNKNOWN = 0, + IWINFO_OPMODE_MASTER = 1, + IWINFO_OPMODE_ADHOC = 2, + IWINFO_OPMODE_CLIENT = 3, + IWINFO_OPMODE_MONITOR = 4, + IWINFO_OPMODE_AP_VLAN = 5, + IWINFO_OPMODE_WDS = 6, + IWINFO_OPMODE_MESHPOINT = 7, + IWINFO_OPMODE_P2P_CLIENT = 8, + IWINFO_OPMODE_P2P_GO = 9, +}; + +extern const char *IWINFO_OPMODE_NAMES[]; + + +struct iwinfo_rate_entry { + uint32_t rate; + int8_t mcs; + uint8_t is_40mhz:1; + uint8_t is_short_gi:1; +}; + +struct iwinfo_assoclist_entry { + uint8_t mac[6]; + int8_t signal; + int8_t noise; + uint32_t inactive; + uint32_t rx_packets; + uint32_t tx_packets; + struct iwinfo_rate_entry rx_rate; + struct iwinfo_rate_entry tx_rate; +}; + +struct iwinfo_txpwrlist_entry { + uint8_t dbm; + uint16_t mw; +}; + +struct iwinfo_freqlist_entry { + uint8_t channel; + uint32_t mhz; + uint8_t restricted; +}; + +struct iwinfo_crypto_entry { + uint8_t enabled; + uint8_t wpa_version; + uint8_t group_ciphers; + uint8_t pair_ciphers; + uint8_t auth_suites; + uint8_t auth_algs; +}; + +struct iwinfo_scanlist_entry { + uint8_t mac[6]; + uint8_t ssid[IWINFO_ESSID_MAX_SIZE+1]; + enum iwinfo_opmode mode; + uint8_t channel; + uint8_t signal; + uint8_t quality; + uint8_t quality_max; + struct iwinfo_crypto_entry crypto; +}; + +struct iwinfo_country_entry { + uint16_t iso3166; + uint8_t ccode[4]; +}; + +struct iwinfo_iso3166_label { + uint16_t iso3166; + uint8_t name[28]; +}; + +struct iwinfo_hardware_id { + uint16_t vendor_id; + uint16_t device_id; + uint16_t subsystem_vendor_id; + uint16_t subsystem_device_id; +}; + +struct iwinfo_hardware_entry { + char vendor_name[64]; + char device_name[64]; + uint16_t vendor_id; + uint16_t device_id; + uint16_t subsystem_vendor_id; + uint16_t subsystem_device_id; + int16_t txpower_offset; + int16_t frequency_offset; +}; + +extern const struct iwinfo_iso3166_label IWINFO_ISO3166_NAMES[]; + +#define IWINFO_HARDWARE_FILE "/usr/share/libiwinfo/hardware.txt" + + +struct iwinfo_ops { + const char *name; + + int (*probe)(const char *ifname); + int (*mode)(const char *, int *); + int (*channel)(const char *, int *); + int (*frequency)(const char *, int *); + int (*frequency_offset)(const char *, int *); + int (*txpower)(const char *, int *); + int (*txpower_offset)(const char *, int *); + int (*bitrate)(const char *, int *); + int (*signal)(const char *, int *); + int (*noise)(const char *, int *); + int (*quality)(const char *, int *); + int (*quality_max)(const char *, int *); + int (*mbssid_support)(const char *, int *); + int (*hwmodelist)(const char *, int *); + int (*ssid)(const char *, char *); + int (*bssid)(const char *, char *); + int (*country)(const char *, char *); + int (*hardware_id)(const char *, char *); + int (*hardware_name)(const char *, char *); + int (*encryption)(const char *, char *); + int (*phyname)(const char *, char *); + int (*assoclist)(const char *, char *, int *); + int (*txpwrlist)(const char *, char *, int *); + int (*scanlist)(const char *, char *, int *); + int (*freqlist)(const char *, char *, int *); + int (*countrylist)(const char *, char *, int *); + void (*close)(void); +}; + +const char * iwinfo_type(const char *ifname); +const struct iwinfo_ops * iwinfo_backend(const char *ifname); +void iwinfo_finish(void); + +extern const struct iwinfo_ops wext_ops; +extern const struct iwinfo_ops madwifi_ops; +extern const struct iwinfo_ops nl80211_ops; +extern const struct iwinfo_ops wl_ops; + +#include "iwinfo/utils.h" + +#endif diff --git a/include/iwinfo/lua.h b/include/iwinfo/lua.h new file mode 100644 index 0000000..8b76b25 --- /dev/null +++ b/include/iwinfo/lua.h @@ -0,0 +1,79 @@ +/* + * iwinfo - Wireless Information Library - Lua Headers + * + * Copyright (C) 2009 Jo-Philipp Wich + * + * The iwinfo library is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation. + * + * The iwinfo library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with the iwinfo library. If not, see http://www.gnu.org/licenses/. + */ + +#ifndef __IWINFO_LUALUB_H_ +#define __IWINFO_LUALIB_H_ + +#include +#include +#include + +#include "iwinfo.h" + + +#define IWINFO_META "iwinfo" +#define IWINFO_WEXT_META "iwinfo.wext" + +#ifdef USE_WL +#define IWINFO_WL_META "iwinfo.wl" +#endif + +#ifdef USE_MADWIFI +#define IWINFO_MADWIFI_META "iwinfo.madwifi" +#endif + +#ifdef USE_NL80211 +#define IWINFO_NL80211_META "iwinfo.nl80211" +#endif + + +#define LUA_REG(type,op) \ + { #op, iwinfo_L_##type##_##op } + +#define LUA_WRAP_INT_OP(type,op) \ + static int iwinfo_L_##type##_##op(lua_State *L) \ + { \ + const char *ifname = luaL_checkstring(L, 1); \ + int rv; \ + if( !type##_ops.op(ifname, &rv) ) \ + lua_pushnumber(L, rv); \ + else \ + lua_pushnil(L); \ + return 1; \ + } + +#define LUA_WRAP_STRING_OP(type,op) \ + static int iwinfo_L_##type##_##op(lua_State *L) \ + { \ + const char *ifname = luaL_checkstring(L, 1); \ + char rv[IWINFO_BUFSIZE]; \ + memset(rv, 0, IWINFO_BUFSIZE); \ + if( !type##_ops.op(ifname, rv) ) \ + lua_pushstring(L, rv); \ + else \ + lua_pushnil(L); \ + return 1; \ + } + +#define LUA_WRAP_STRUCT_OP(type,op) \ + static int iwinfo_L_##type##_##op(lua_State *L) \ + { \ + return iwinfo_L_##op(L, type##_ops.op); \ + } + +#endif diff --git a/include/iwinfo/utils.h b/include/iwinfo/utils.h new file mode 100644 index 0000000..d58ec5f --- /dev/null +++ b/include/iwinfo/utils.h @@ -0,0 +1,47 @@ +/* + * iwinfo - Wireless Information Library - Utility Headers + * + * Copyright (C) 2010 Jo-Philipp Wich + * + * The iwinfo library is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation. + * + * The iwinfo library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with the iwinfo library. If not, see http://www.gnu.org/licenses/. + */ + +#ifndef __IWINFO_UTILS_H_ +#define __IWINFO_UTILS_H_ + +#include +#include + +#include "iwinfo.h" + +#define LOG10_MAGIC 1.25892541179 + +int iwinfo_ioctl(int cmd, void *ifr); + +int iwinfo_dbm2mw(int in); +int iwinfo_mw2dbm(int in); + +int iwinfo_ifup(const char *ifname); +int iwinfo_ifdown(const char *ifname); +int iwinfo_ifmac(const char *ifname); + +void iwinfo_close(void); + +struct iwinfo_hardware_entry * iwinfo_hardware(struct iwinfo_hardware_id *id); + +int iwinfo_hardware_id_from_mtd(struct iwinfo_hardware_id *id); + +void iwinfo_parse_rsn(struct iwinfo_crypto_entry *c, uint8_t *data, uint8_t len, + uint8_t defcipher, uint8_t defauth); + +#endif -- cgit v1.2.1