diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2010-10-24 17:21:54 +0000 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2010-10-24 17:21:54 +0000 |
commit | eecec8b0f2a2cd86827115c1479de974ece00850 (patch) | |
tree | aeedae966fbdefb3c7ddeb8ba1aaf1afc498a93d /contrib/package/iwinfo | |
parent | 6ef55ba3276ba85cb30d07c528266d92067725d4 (diff) |
libiwinfo: move duplicated coded into iwinfo_utils.[ch]
Diffstat (limited to 'contrib/package/iwinfo')
-rw-r--r-- | contrib/package/iwinfo/Makefile | 2 | ||||
-rw-r--r-- | contrib/package/iwinfo/src/Makefile | 5 | ||||
-rw-r--r-- | contrib/package/iwinfo/src/iwinfo_lualib.c | 1 | ||||
-rw-r--r-- | contrib/package/iwinfo/src/iwinfo_madwifi.c | 69 | ||||
-rw-r--r-- | contrib/package/iwinfo/src/iwinfo_madwifi.h | 1 | ||||
-rw-r--r-- | contrib/package/iwinfo/src/iwinfo_nl80211.c | 89 | ||||
-rw-r--r-- | contrib/package/iwinfo/src/iwinfo_nl80211.h | 3 | ||||
-rw-r--r-- | contrib/package/iwinfo/src/iwinfo_utils.c | 126 | ||||
-rw-r--r-- | contrib/package/iwinfo/src/iwinfo_utils.h | 40 | ||||
-rw-r--r-- | contrib/package/iwinfo/src/iwinfo_wext.c | 61 | ||||
-rw-r--r-- | contrib/package/iwinfo/src/iwinfo_wext.h | 7 | ||||
-rw-r--r-- | contrib/package/iwinfo/src/iwinfo_wext_scan.c | 25 | ||||
-rw-r--r-- | contrib/package/iwinfo/src/iwinfo_wext_scan.h | 3 | ||||
-rw-r--r-- | contrib/package/iwinfo/src/iwinfo_wl.c | 15 | ||||
-rw-r--r-- | contrib/package/iwinfo/src/iwinfo_wl.h | 3 |
15 files changed, 216 insertions, 234 deletions
diff --git a/contrib/package/iwinfo/Makefile b/contrib/package/iwinfo/Makefile index 0ef0814306..7cad392586 100644 --- a/contrib/package/iwinfo/Makefile +++ b/contrib/package/iwinfo/Makefile @@ -7,7 +7,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=libiwinfo -PKG_RELEASE:=8 +PKG_RELEASE:=9 PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME) diff --git a/contrib/package/iwinfo/src/Makefile b/contrib/package/iwinfo/src/Makefile index 40b720ab93..024582b0be 100644 --- a/contrib/package/iwinfo/src/Makefile +++ b/contrib/package/iwinfo/src/Makefile @@ -2,7 +2,7 @@ IWINFO_BACKENDS = $(if $(BACKENDS),$(BACKENDS),madwifi nl80211) IWINFO_LDFLAGS = $(LDFLAGS) -shared -llua IWINFO_CFLAGS = $(CFLAGS) -std=gnu99 -fstrict-aliasing IWINFO_SO = iwinfo.so -IWINFO_OBJ = iwinfo_wext.o iwinfo_wext_scan.o iwinfo_lualib.o +IWINFO_OBJ = iwinfo_utils.o iwinfo_wext.o iwinfo_wext_scan.o iwinfo_lualib.o ifneq ($(filter wl,$(IWINFO_BACKENDS)),) IWINFO_CFLAGS += -DUSE_WL @@ -22,11 +22,10 @@ endif %.o: %.c - $(CC) $(IWINFO_CFLAGS) $(LUA_CFLAGS) $(FPIC) -c -o $@ $< + $(CC) $(IWINFO_CFLAGS) $(LUA_CFLAGS) $(FPIC) -c -o $@ $< compile: clean $(IWINFO_OBJ) $(LD) $(IWINFO_LDFLAGS) -o $(IWINFO_SO) $(IWINFO_OBJ) clean: rm -f *.o $(IWINFO_SO) - diff --git a/contrib/package/iwinfo/src/iwinfo_lualib.c b/contrib/package/iwinfo/src/iwinfo_lualib.c index 4309aa129f..b327d08d80 100644 --- a/contrib/package/iwinfo/src/iwinfo_lualib.c +++ b/contrib/package/iwinfo/src/iwinfo_lualib.c @@ -321,6 +321,7 @@ static int iwinfo_L__gc(lua_State *L) nl80211_close(); #endif wext_close(); + iwinfo_close(); } /* diff --git a/contrib/package/iwinfo/src/iwinfo_madwifi.c b/contrib/package/iwinfo/src/iwinfo_madwifi.c index d779be5a80..cb21ac5a02 100644 --- a/contrib/package/iwinfo/src/iwinfo_madwifi.c +++ b/contrib/package/iwinfo/src/iwinfo_madwifi.c @@ -1,7 +1,7 @@ /* * iwinfo - Wireless Information Library - Madwifi Backend * - * Copyright (C) 2009 Jo-Philipp Wich <xm@subsignal.org> + * Copyright (C) 2009-2010 Jo-Philipp Wich <xm@subsignal.org> * * The iwinfo library is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 @@ -196,26 +196,6 @@ static struct ISO3166_to_CCode }; -static int ioctl_socket = -1; - -static int madwifi_socket(void) -{ - /* Prepare socket */ - if( ioctl_socket == -1 ) - { - ioctl_socket = socket(AF_INET, SOCK_DGRAM, 0); - fcntl(ioctl_socket, F_SETFD, fcntl(ioctl_socket, F_GETFD) | FD_CLOEXEC); - } - - return ioctl_socket; -} - -static int madwifi_ioctl(int cmd, void *ifr) -{ - int s = madwifi_socket(); - return ioctl(s, cmd, ifr); -} - static int madwifi_wrq(struct iwreq *wrq, const char *ifname, int cmd, void *data, size_t len) { strncpy(wrq->ifr_name, ifname, IFNAMSIZ); @@ -233,7 +213,7 @@ static int madwifi_wrq(struct iwreq *wrq, const char *ifname, int cmd, void *dat } } - return madwifi_ioctl(cmd, wrq); + return iwinfo_ioctl(cmd, wrq); } static int get80211priv(const char *ifname, int op, void *data, size_t len) @@ -318,7 +298,7 @@ static char * madwifi_ifadd(const char *ifname) strncpy(ifr.ifr_name, wifidev, IFNAMSIZ); ifr.ifr_data = (void *)&cp; - if( !madwifi_ioctl(SIOC80211IFCREATE, &ifr) ) + if( !iwinfo_ioctl(SIOC80211IFCREATE, &ifr) ) return nif; } @@ -330,35 +310,7 @@ static void madwifi_ifdel(const char *ifname) struct ifreq ifr = { 0 }; strncpy(ifr.ifr_name, ifname, IFNAMSIZ); - madwifi_ioctl(SIOC80211IFDESTROY, &ifr); -} - -static int madwifi_ifup(const char *ifname) -{ - struct ifreq ifr; - - strncpy(ifr.ifr_name, ifname, IFNAMSIZ); - - if( madwifi_ioctl(SIOCGIFFLAGS, &ifr) ) - return 0; - - ifr.ifr_flags |= (IFF_UP | IFF_RUNNING); - - return !madwifi_ioctl(SIOCSIFFLAGS, &ifr); -} - -static int madwifi_ifdown(const char *ifname) -{ - struct ifreq ifr; - - strncpy(ifr.ifr_name, ifname, IFNAMSIZ); - - if( madwifi_ioctl(SIOCGIFFLAGS, &ifr) ) - return 0; - - ifr.ifr_flags &= ~(IFF_UP | IFF_RUNNING); - - return !madwifi_ioctl(SIOCSIFFLAGS, &ifr); + iwinfo_ioctl(SIOC80211IFDESTROY, &ifr); } @@ -369,8 +321,7 @@ int madwifi_probe(const char *ifname) void madwifi_close(void) { - if( ioctl_socket > -1 ) - close(ioctl_socket); + /* Nop */ } int madwifi_get_mode(const char *ifname, char *buf) @@ -804,7 +755,7 @@ int madwifi_get_scanlist(const char *ifname, char *buf, int *len) { if( !!madwifi_isvap(e->d_name, ifname) ) { - if( madwifi_ifup(e->d_name) ) + if( iwinfo_ifup(e->d_name) ) { ret = wext_get_scanlist(e->d_name, buf, len); break; @@ -820,10 +771,10 @@ int madwifi_get_scanlist(const char *ifname, char *buf, int *len) { if( (res = madwifi_ifadd(ifname)) != NULL ) { - if( madwifi_ifup(res) ) + if( iwinfo_ifup(res) ) ret = wext_get_scanlist(res, buf, len); - madwifi_ifdown(res); + iwinfo_ifdown(res); madwifi_ifdel(res); } } @@ -988,9 +939,9 @@ int madwifi_get_mbssid_support(const char *ifname, int *buf) if( nif ) { - *buf = madwifi_ifup(nif); + *buf = iwinfo_ifup(nif); - madwifi_ifdown(nif); + iwinfo_ifdown(nif); madwifi_ifdel(nif); return 0; diff --git a/contrib/package/iwinfo/src/iwinfo_madwifi.h b/contrib/package/iwinfo/src/iwinfo_madwifi.h index b16c36f82e..690177f50d 100644 --- a/contrib/package/iwinfo/src/iwinfo_madwifi.h +++ b/contrib/package/iwinfo/src/iwinfo_madwifi.h @@ -22,6 +22,7 @@ #include <fcntl.h> #include "iwinfo.h" +#include "iwinfo_utils.h" #include "include/madwifi.h" int madwifi_probe(const char *ifname); diff --git a/contrib/package/iwinfo/src/iwinfo_nl80211.c b/contrib/package/iwinfo/src/iwinfo_nl80211.c index 91ede2e99b..b5ab5ba070 100644 --- a/contrib/package/iwinfo/src/iwinfo_nl80211.c +++ b/contrib/package/iwinfo/src/iwinfo_nl80211.c @@ -29,7 +29,6 @@ extern struct iwinfo_iso3166_label ISO3166_Names[]; static struct nl80211_state *nls = NULL; -static int nl80211_ioctlsock = -1; static int nl80211_init(void) { @@ -37,19 +36,6 @@ static int nl80211_init(void) if( !nls ) { - nl80211_ioctlsock = socket(AF_INET, SOCK_DGRAM, 0); - if( nl80211_ioctlsock < 0 ) - { - err = -ENOLINK; - goto err; - } - else if( fcntl(nl80211_ioctlsock, F_SETFD, - fcntl(nl80211_ioctlsock, F_GETFD) | FD_CLOEXEC) < 0 ) - { - err = -EINVAL; - goto err; - } - nls = malloc(sizeof(struct nl80211_state)); if( !nls ) { err = -ENOMEM; @@ -504,49 +490,6 @@ static void nl80211_ifdel(const char *ifname) } } -static int nl80211_ifup(const char *ifname) -{ - struct ifreq ifr; - - strncpy(ifr.ifr_name, ifname, IFNAMSIZ); - - if( ioctl(nl80211_ioctlsock, SIOCGIFFLAGS, &ifr) ) - return 0; - - ifr.ifr_flags |= (IFF_UP | IFF_RUNNING); - - return !ioctl(nl80211_ioctlsock, SIOCSIFFLAGS, &ifr); -} - -static int nl80211_ifdown(const char *ifname) -{ - struct ifreq ifr; - - strncpy(ifr.ifr_name, ifname, IFNAMSIZ); - - if( ioctl(nl80211_ioctlsock, SIOCGIFFLAGS, &ifr) ) - return 0; - - ifr.ifr_flags &= ~(IFF_UP | IFF_RUNNING); - - return !ioctl(nl80211_ioctlsock, SIOCSIFFLAGS, &ifr); -} - -static int nl80211_ifmac(const char *ifname) -{ - struct ifreq ifr; - - strncpy(ifr.ifr_name, ifname, IFNAMSIZ); - - if( ioctl(nl80211_ioctlsock, SIOCGIFHWADDR, &ifr) ) - return 0; - - ifr.ifr_hwaddr.sa_data[1]++; - ifr.ifr_hwaddr.sa_data[2]++; - - return !ioctl(nl80211_ioctlsock, SIOCSIFHWADDR, &ifr); -} - static void nl80211_hostapd_hup(const char *ifname) { int fd, pid = 0; @@ -577,11 +520,6 @@ int nl80211_probe(const char *ifname) void nl80211_close(void) { - if( nl80211_ioctlsock > -1 ) - { - close(nl80211_ioctlsock); - } - if( nls ) { if( nls->nl_sock ) @@ -1169,13 +1107,13 @@ int nl80211_get_txpwrlist(const char *ifname, char *buf, int *len) dbm_cur += 2, dbm_cnt++ ) { entry.dbm = dbm_cur; - entry.mw = wext_dbm2mw(dbm_cur); + entry.mw = iwinfo_dbm2mw(dbm_cur); memcpy(&buf[dbm_cnt * sizeof(entry)], &entry, sizeof(entry)); } entry.dbm = dbm_max; - entry.mw = wext_dbm2mw(dbm_max); + entry.mw = iwinfo_dbm2mw(dbm_max); memcpy(&buf[dbm_cnt * sizeof(entry)], &entry, sizeof(entry)); dbm_cnt++; @@ -1266,8 +1204,7 @@ int nl80211_get_scanlist(const char *ifname, char *buf, int *len) struct iwinfo_scanlist_entry *e = (struct iwinfo_scanlist_entry *)buf; /* WPA supplicant */ - if( (res = nl80211_wpasupp_info(ifname, "SCAN")) && - !strcmp(res, "OK\n") ) + if( (res = nl80211_wpasupp_info(ifname, "SCAN")) && !strcmp(res, "OK\n") ) { sleep(2); @@ -1346,11 +1283,11 @@ int nl80211_get_scanlist(const char *ifname, char *buf, int *len) /* Got a temp interface, don't create yet another one */ if( !strncmp(ifname, "tmp.", 4) ) { - if( !nl80211_ifup(ifname) ) + if( !iwinfo_ifup(ifname) ) return -1; wext_get_scanlist(ifname, buf, len); - nl80211_ifdown(ifname); + iwinfo_ifdown(ifname); return 0; } @@ -1360,24 +1297,24 @@ int nl80211_get_scanlist(const char *ifname, char *buf, int *len) if( !(res = nl80211_ifadd(ifname)) ) goto out; - if( !nl80211_ifmac(res) ) + if( !iwinfo_ifmac(res) ) goto out; /* if we can take the new interface up, the driver supports an * additional interface and there's no need to tear down the ap */ - if( nl80211_ifup(res) ) + if( iwinfo_ifup(res) ) { wext_get_scanlist(res, buf, len); - nl80211_ifdown(res); + iwinfo_ifdown(res); } /* driver cannot create secondary interface, take down ap * during scan */ - else if( nl80211_ifdown(ifname) && nl80211_ifup(res) ) + else if( iwinfo_ifdown(ifname) && iwinfo_ifup(res) ) { wext_get_scanlist(res, buf, len); - nl80211_ifdown(res); - nl80211_ifup(ifname); + iwinfo_ifdown(res); + iwinfo_ifup(ifname); nl80211_hostapd_hup(ifname); } @@ -1552,9 +1489,9 @@ int nl80211_get_mbssid_support(const char *ifname, int *buf) if( nif ) { - *buf = (nl80211_ifmac(nif) && nl80211_ifup(nif)); + *buf = (iwinfo_ifmac(nif) && iwinfo_ifup(nif)); - nl80211_ifdown(nif); + iwinfo_ifdown(nif); nl80211_ifdel(nif); return 0; diff --git a/contrib/package/iwinfo/src/iwinfo_nl80211.h b/contrib/package/iwinfo/src/iwinfo_nl80211.h index 5fc1d74d25..7f6ffeaaa2 100644 --- a/contrib/package/iwinfo/src/iwinfo_nl80211.h +++ b/contrib/package/iwinfo/src/iwinfo_nl80211.h @@ -25,15 +25,14 @@ #include <string.h> #include <dirent.h> #include <signal.h> -#include <sys/socket.h> #include <sys/un.h> -#include <net/if.h> #include <netlink/netlink.h> #include <netlink/genl/genl.h> #include <netlink/genl/family.h> #include <netlink/genl/ctrl.h> #include "iwinfo.h" +#include "iwinfo_utils.h" #include "include/nl80211.h" struct nl80211_state { diff --git a/contrib/package/iwinfo/src/iwinfo_utils.c b/contrib/package/iwinfo/src/iwinfo_utils.c new file mode 100644 index 0000000000..edd431e003 --- /dev/null +++ b/contrib/package/iwinfo/src/iwinfo_utils.c @@ -0,0 +1,126 @@ +/* + * iwinfo - Wireless Information Library - Shared utility routines + * + * Copyright (C) 2010 Jo-Philipp Wich <xm@subsignal.org> + * + * The iwinfo library is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation. + * + * The iwinfo library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with the iwinfo library. If not, see http://www.gnu.org/licenses/. + * + * The signal handling code is derived from the official madwifi tools, + * wlanconfig.c in particular. The encryption property handling was + * inspired by the hostapd madwifi driver. + */ + +#include "iwinfo_utils.h" + + +static int ioctl_socket = -1; + +static int iwinfo_ioctl_socket(void) +{ + /* Prepare socket */ + if( ioctl_socket == -1 ) + { + ioctl_socket = socket(AF_INET, SOCK_DGRAM, 0); + fcntl(ioctl_socket, F_SETFD, fcntl(ioctl_socket, F_GETFD) | FD_CLOEXEC); + } + + return ioctl_socket; +} + +int iwinfo_ioctl(int cmd, void *ifr) +{ + int s = iwinfo_ioctl_socket(); + return ioctl(s, cmd, ifr); +} + +int iwinfo_dbm2mw(int in) +{ + double res = 1.0; + int ip = in / 10; + int fp = in % 10; + int k; + + for(k = 0; k < ip; k++) res *= 10; + for(k = 0; k < fp; k++) res *= LOG10_MAGIC; + + return (int)res; +} + +int iwinfo_mw2dbm(int in) +{ + double fin = (double) in; + int res = 0; + + while(fin > 10.0) + { + res += 10; + fin /= 10.0; + } + + while(fin > 1.000001) + { + res += 1; + fin /= LOG10_MAGIC; + } + + return (int)res; +} + +int iwinfo_ifup(const char *ifname) +{ + struct ifreq ifr; + + strncpy(ifr.ifr_name, ifname, IFNAMSIZ); + + if( iwinfo_ioctl(SIOCGIFFLAGS, &ifr) ) + return 0; + + ifr.ifr_flags |= (IFF_UP | IFF_RUNNING); + + return !iwinfo_ioctl(SIOCSIFFLAGS, &ifr); +} + +int iwinfo_ifdown(const char *ifname) +{ + struct ifreq ifr; + + strncpy(ifr.ifr_name, ifname, IFNAMSIZ); + + if( iwinfo_ioctl(SIOCGIFFLAGS, &ifr) ) + return 0; + + ifr.ifr_flags &= ~(IFF_UP | IFF_RUNNING); + + return !iwinfo_ioctl(SIOCSIFFLAGS, &ifr); +} + +int iwinfo_ifmac(const char *ifname) +{ + struct ifreq ifr; + + strncpy(ifr.ifr_name, ifname, IFNAMSIZ); + + if( iwinfo_ioctl(SIOCGIFHWADDR, &ifr) ) + return 0; + + ifr.ifr_hwaddr.sa_data[1]++; + ifr.ifr_hwaddr.sa_data[2]++; + + return !iwinfo_ioctl(SIOCSIFHWADDR, &ifr); +} + +void iwinfo_close(void) +{ + if( ioctl_socket > -1 ) + close(ioctl_socket); +} diff --git a/contrib/package/iwinfo/src/iwinfo_utils.h b/contrib/package/iwinfo/src/iwinfo_utils.h new file mode 100644 index 0000000000..57958b1b54 --- /dev/null +++ b/contrib/package/iwinfo/src/iwinfo_utils.h @@ -0,0 +1,40 @@ +/* + * iwinfo - Wireless Information Library - Utility Headers + * + * Copyright (C) 2010 Jo-Philipp Wich <xm@subsignal.org> + * + * The iwinfo library is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation. + * + * The iwinfo library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with the iwinfo library. If not, see http://www.gnu.org/licenses/. + */ + +#ifndef __IWINFO_UTILS_H_ +#define __IWINFO_UTILS_H_ + +#include <sys/socket.h> +#include <net/if.h> + +#include "iwinfo.h" + +#define LOG10_MAGIC 1.25892541179 + +int iwinfo_ioctl(int cmd, void *ifr); + +int iwinfo_dbm2mw(int in); +int iwinfo_mw2dbm(int in); + +int iwinfo_ifup(const char *ifname); +int iwinfo_ifdown(const char *ifname); +int iwinfo_ifmac(const char *ifname); + +void iwinfo_close(void); + +#endif diff --git a/contrib/package/iwinfo/src/iwinfo_wext.c b/contrib/package/iwinfo/src/iwinfo_wext.c index 5300f1b027..518551f7d5 100644 --- a/contrib/package/iwinfo/src/iwinfo_wext.c +++ b/contrib/package/iwinfo/src/iwinfo_wext.c @@ -22,10 +22,6 @@ #include "iwinfo.h" #include "iwinfo_wext.h" -#define LOG10_MAGIC 1.25892541179 - -static int ioctl_socket = -1; - static double wext_freq2float(const struct iw_freq *in) { int i; @@ -34,7 +30,7 @@ static double wext_freq2float(const struct iw_freq *in) return res; } -static int wext_freq2mhz(const struct iw_freq *in) +static inline int wext_freq2mhz(const struct iw_freq *in) { int i, mhz; @@ -52,54 +48,14 @@ static int wext_freq2mhz(const struct iw_freq *in) } } -int wext_dbm2mw(int in) +static inline int wext_ioctl(const char *ifname, int cmd, struct iwreq *wrq) { - double res = 1.0; - int ip = in / 10; - int fp = in % 10; - int k; - - for(k = 0; k < ip; k++) res *= 10; - for(k = 0; k < fp; k++) res *= LOG10_MAGIC; - - return (int)res; -} - -int wext_mw2dbm(int in) -{ - double fin = (double) in; - int res = 0; - - while(fin > 10.0) - { - res += 10; - fin /= 10.0; - } - - while(fin > 1.000001) - { - res += 1; - fin /= LOG10_MAGIC; - } - - return (int)res; -} - -static int wext_ioctl(const char *ifname, int cmd, struct iwreq *wrq) -{ - /* prepare socket */ - if( ioctl_socket == -1 ) - { - ioctl_socket = socket(AF_INET, SOCK_DGRAM, 0); - fcntl(ioctl_socket, F_SETFD, fcntl(ioctl_socket, F_GETFD) | FD_CLOEXEC); - } - if( !strncmp(ifname, "mon.", 4) ) strncpy(wrq->ifr_name, &ifname[4], IFNAMSIZ); else strncpy(wrq->ifr_name, ifname, IFNAMSIZ); - return ioctl(ioctl_socket, cmd, wrq); + return iwinfo_ioctl(cmd, wrq); } @@ -115,10 +71,7 @@ int wext_probe(const char *ifname) void wext_close(void) { - wext_scan_close(); - - if( ioctl_socket > -1 ) - close(ioctl_socket); + /* Nop */ } int wext_get_mode(const char *ifname, char *buf) @@ -296,7 +249,7 @@ int wext_get_txpower(const char *ifname, int *buf) if(wext_ioctl(ifname, SIOCGIWTXPOW, &wrq) >= 0) { if(wrq.u.txpower.flags & IW_TXPOW_MWATT) - *buf = wext_mw2dbm(wrq.u.txpower.value); + *buf = iwinfo_mw2dbm(wrq.u.txpower.value); else *buf = wrq.u.txpower.value; @@ -407,7 +360,7 @@ int wext_get_txpwrlist(const char *ifname, char *buf, int *len) { if( range.txpower_capa & IW_TXPOW_MWATT ) { - entry.dbm = wext_mw2dbm(range.txpower[i]); + entry.dbm = iwinfo_mw2dbm(range.txpower[i]); entry.mw = range.txpower[i]; } @@ -416,7 +369,7 @@ int wext_get_txpwrlist(const char *ifname, char *buf, int *len) else /* if( range.txpower_capa & IW_TXPOW_DBM ) */ { entry.dbm = range.txpower[i]; - entry.mw = wext_dbm2mw(range.txpower[i]); + entry.mw = iwinfo_dbm2mw(range.txpower[i]); } memcpy(&buf[i*sizeof(entry)], &entry, sizeof(entry)); diff --git a/contrib/package/iwinfo/src/iwinfo_wext.h b/contrib/package/iwinfo/src/iwinfo_wext.h index 03a5199b08..db213fccc6 100644 --- a/contrib/package/iwinfo/src/iwinfo_wext.h +++ b/contrib/package/iwinfo/src/iwinfo_wext.h @@ -1,7 +1,7 @@ /* * iwinfo - Wireless Information Library - Linux Wireless Extension Headers * - * Copyright (C) 2009 Jo-Philipp Wich <xm@subsignal.org> + * Copyright (C) 2009-2010 Jo-Philipp Wich <xm@subsignal.org> * * The iwinfo library is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 @@ -22,12 +22,10 @@ #include <fcntl.h> #include "iwinfo.h" +#include "iwinfo_utils.h" #include "include/wext.h" -int wext_dbm2mw(int in); -int wext_mw2dbm(int in); - int wext_probe(const char *ifname); int wext_get_mode(const char *ifname, char *buf); int wext_get_ssid(const char *ifname, char *buf); @@ -49,7 +47,6 @@ int wext_get_freqlist(const char *ifname, char *buf, int *len); int wext_get_countrylist(const char *ifname, char *buf, int *len); int wext_get_hwmodelist(const char *ifname, int *buf); int wext_get_mbssid_support(const char *ifname, int *buf); -void wext_scan_close(void); void wext_close(void); #endif diff --git a/contrib/package/iwinfo/src/iwinfo_wext_scan.c b/contrib/package/iwinfo/src/iwinfo_wext_scan.c index d5b486b7e4..93dd887422 100644 --- a/contrib/package/iwinfo/src/iwinfo_wext_scan.c +++ b/contrib/package/iwinfo/src/iwinfo_wext_scan.c @@ -1,7 +1,7 @@ /* * iwinfo - Wireless Information Library - Linux Wireless Extension Backend * - * Copyright (C) 2009 Jo-Philipp Wich <xm@subsignal.org> + * Copyright (C) 2009-2010 Jo-Philipp Wich <xm@subsignal.org> * * The iwinfo library is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 @@ -23,22 +23,13 @@ #include "iwinfo_wext_scan.h" -static int ioctl_socket = -1; - static int wext_ioctl(const char *ifname, int cmd, struct iwreq *wrq) { - /* prepare socket */ - if( ioctl_socket == -1 ) - { - ioctl_socket = socket(AF_INET, SOCK_DGRAM, 0); - fcntl(ioctl_socket, F_SETFD, fcntl(ioctl_socket, F_GETFD) | FD_CLOEXEC); - } - - strncpy(wrq->ifr_name, ifname, IFNAMSIZ); - return ioctl(ioctl_socket, cmd, wrq); + strncpy(wrq->ifr_name, ifname, IFNAMSIZ); + return iwinfo_ioctl(cmd, wrq); } -static double wext_freq2float(const struct iw_freq *in) +static inline double wext_freq2float(const struct iw_freq *in) { int i; double res = (double) in->m; @@ -46,7 +37,7 @@ static double wext_freq2float(const struct iw_freq *in) return res; } -static int wext_extract_event(struct stream_descr *stream, struct iw_event *iwe, int wev) +static inline int wext_extract_event(struct stream_descr *stream, struct iw_event *iwe, int wev) { const struct iw_ioctl_description *descr = NULL; int event_type = 0; @@ -653,9 +644,3 @@ int wext_get_scanlist(const char *ifname, char *buf, int *len) return -1; } - -void wext_scan_close(void) -{ - if( ioctl_socket > -1 ) - close(ioctl_socket); -} diff --git a/contrib/package/iwinfo/src/iwinfo_wext_scan.h b/contrib/package/iwinfo/src/iwinfo_wext_scan.h index 6456c28ffd..5193902fe6 100644 --- a/contrib/package/iwinfo/src/iwinfo_wext_scan.h +++ b/contrib/package/iwinfo/src/iwinfo_wext_scan.h @@ -1,7 +1,7 @@ /* * iwinfo - Wireless Information Library - Linux Wireless Extension Headers * - * Copyright (C) 2009 Jo-Philipp Wich <xm@subsignal.org> + * Copyright (C) 2009-2010 Jo-Philipp Wich <xm@subsignal.org> * * The iwinfo library is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 @@ -22,6 +22,7 @@ #include <fcntl.h> #include "iwinfo.h" +#include "iwinfo_utils.h" #include "include/wext.h" diff --git a/contrib/package/iwinfo/src/iwinfo_wl.c b/contrib/package/iwinfo/src/iwinfo_wl.c index a08dcd2a0d..1691e4b358 100644 --- a/contrib/package/iwinfo/src/iwinfo_wl.c +++ b/contrib/package/iwinfo/src/iwinfo_wl.c @@ -21,28 +21,20 @@ #include "iwinfo_wl.h" #include "iwinfo_wext.h" -static int ioctl_socket = -1; - static int wl_ioctl(const char *name, int cmd, void *buf, int len) { struct ifreq ifr; wl_ioctl_t ioc; - /* prepare socket */ - if( ioctl_socket == -1 ) - { - ioctl_socket = socket(AF_INET, SOCK_DGRAM, 0); - fcntl(ioctl_socket, F_SETFD, fcntl(ioctl_socket, F_GETFD) | FD_CLOEXEC); - } - /* do it */ ioc.cmd = cmd; ioc.buf = buf; ioc.len = len; + strncpy(ifr.ifr_name, name, IFNAMSIZ); ifr.ifr_data = (caddr_t) &ioc; - return ioctl(ioctl_socket, SIOCDEVPRIVATE, &ifr); + return iwinfo_ioctl(SIOCDEVPRIVATE, &ifr); } static struct wl_maclist * wl_read_assoclist(const char *ifname) @@ -77,8 +69,7 @@ int wl_probe(const char *ifname) void wl_close(void) { - if( ioctl_socket > -1 ) - close(ioctl_socket); + /* Nop */ } int wl_get_mode(const char *ifname, char *buf) diff --git a/contrib/package/iwinfo/src/iwinfo_wl.h b/contrib/package/iwinfo/src/iwinfo_wl.h index 97a8741b7b..95d4961432 100644 --- a/contrib/package/iwinfo/src/iwinfo_wl.h +++ b/contrib/package/iwinfo/src/iwinfo_wl.h @@ -1,7 +1,7 @@ /* * iwinfo - Wireless Information Library - Broadcom wl.o Headers * - * Copyright (C) 2009 Jo-Philipp Wich <xm@subsignal.org> + * Copyright (C) 2009-2010 Jo-Philipp Wich <xm@subsignal.org> * * The iwinfo library is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 @@ -22,6 +22,7 @@ #include <fcntl.h> #include "iwinfo.h" +#include "iwinfo_utils.h" #include "include/broadcom.h" int wl_probe(const char *ifname); |