diff options
author | Lennart Poettering <lennart@poettering.net> | 2004-01-26 15:23:01 +0000 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2004-01-26 15:23:01 +0000 |
commit | bc1fef7e4144a437293345c1dbd7f174b32dcbbd (patch) | |
tree | 84e91626aa1326e53fbc9df1c76146d8a47f66bc | |
parent | a084f62ea25f533b43233cdbb000fd0353585bcb (diff) |
multiple fixes
git-svn-id: file:///home/lennart/svn/public/waproamd/trunk@58 022f378f-78c4-0310-b860-d162c87e6274
-rwxr-xr-x | conf/default.in | 2 | ||||
-rwxr-xr-x | conf/waproamd.init.in | 2 | ||||
-rw-r--r-- | configure.ac | 1 | ||||
-rw-r--r-- | doc/README.html.in | 11 | ||||
-rw-r--r-- | src/interface.c | 39 | ||||
-rw-r--r-- | src/interface.h | 1 | ||||
-rw-r--r-- | src/iwapi.c | 34 | ||||
-rw-r--r-- | src/iwhostroam.c | 2 | ||||
-rw-r--r-- | src/nlapi.c | 2 | ||||
-rw-r--r-- | src/waproamd.c | 59 |
10 files changed, 108 insertions, 45 deletions
diff --git a/conf/default.in b/conf/default.in index 6a326fe..7067e28 100755 --- a/conf/default.in +++ b/conf/default.in @@ -47,7 +47,7 @@ case "$1.$METHOD" in ;; stop.aes) - aeswepd -i $IFACE -k + aeswepd -i $IFACE -kW iwconfig $IFACE key off ;; diff --git a/conf/waproamd.init.in b/conf/waproamd.init.in index 60694cc..638ba57 100755 --- a/conf/waproamd.init.in +++ b/conf/waproamd.init.in @@ -50,7 +50,7 @@ case "$VERB" in stop) echo -n "Stopping Wireless Access Point Roaming Daemon:" for IF in $INTERFACES ; do - $WAPROAMD -k -i $IF + $WAPROAMD -Wk -i $IF echo -n " $IF" done echo "." diff --git a/configure.ac b/configure.ac index bf1a480..e141891 100644 --- a/configure.ac +++ b/configure.ac @@ -64,7 +64,6 @@ AC_SUBST(LIBDAEMON_CFLAGS) AC_SUBST(LIBDAEMON_LIBS) # Set SysV init script directory -# Init script location AC_ARG_WITH(initdir, AS_HELP_STRING(--with-initdir=DIR,Install init script in DIR (system dependent default))) test "x$with_initdir" = xyes -o "x$with_initdir" = xno && with_initdir= diff --git a/doc/README.html.in b/doc/README.html.in index 1891d77..33d5aa4 100644 --- a/doc/README.html.in +++ b/doc/README.html.in @@ -10,7 +10,7 @@ <body> <h1><a name="top">waproamd @PACKAGE_VERSION@</a></h1> -<p><i>Copyright 2003 Lennart Poettering <@PACKAGE_BUGREPORT@></i></p> +<p><i>Copyright 2003,2004 Lennart Poettering <@PACKAGE_BUGREPORT@></i></p> <ul class="toc"> <li><a href="#license">License</a></li> @@ -42,6 +42,11 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.</p> <h2><a name="news">News</a></h2> +<div class="news-date">Sun Jan 25 2004: </div> <p class="news-text"><a +href="@PACKAGE_URL@waproamd-0.5.tar.gz">Version 0.5</a> released, +changes include: Better compatibility with wireless drivers, support +for disabling specific networks, assorted fixes, compatibility with newer kernels</p> + <div class="news-date">Mon Nov 17 2003: </div> <p class="news-text"><a href="@PACKAGE_URL@waproamd-0.4.tar.gz">Version 0.4</a> released, changes include: support for ESSID based configuration, @@ -191,8 +196,10 @@ for it.</p> <p>You may find a mostly up to date Debian package of <tt>waproamd</tt> on the <a href="http://packages.debian.org/waproamd">Debian package repository</a>. +<p>If you want to be notified whenever I release a new version of this software use the subscription feature of <a href="http://freshmeat.net/projects/waproamd/">Freshmeat</a>.</p> + <hr/> -<address class="grey">Lennart Poettering <@PACKAGE_BUGREPORT@>, October 2003</address> +<address class="grey">Lennart Poettering <@PACKAGE_BUGREPORT@>, January 2004</address> <div class="grey"><i>$Id$</i></div> </body> diff --git a/src/interface.c b/src/interface.c index 78602b0..1b6c941 100644 --- a/src/interface.c +++ b/src/interface.c @@ -25,6 +25,7 @@ #include <assert.h> #include <unistd.h> #include <sys/ioctl.h> +#include <netinet/in.h> #include <libdaemon/dlog.h> @@ -65,3 +66,41 @@ void interface_close(struct interface *i) { free(i); } + +void interface_up(struct interface *i) { + struct ifreq ifr; + assert(i && i->fd >= 0 && i->name); + + memset(&ifr, 0, sizeof(ifr)); + strncpy(ifr.ifr_name, i->name, sizeof(ifr.ifr_name)-1); + + if (ioctl(i->fd, SIOCGIFFLAGS, &ifr) < 0) { + daemon_log(LOG_WARNING, "Warning: Could not get interface flags."); + return; + } + + if ((ifr.ifr_flags & IFF_UP) == IFF_UP) + return; + + if (ioctl(i->fd, SIOCGIFADDR, &ifr) < 0) + daemon_log(LOG_WARNING, "Warning: Could not get interface address."); + else if (ifr.ifr_addr.sa_family != AF_INET) + daemon_log(LOG_WARNING, "Warning: The interface is not IP-based."); + else { + ((struct sockaddr_in *)(&ifr.ifr_addr))->sin_addr.s_addr = INADDR_ANY; + if (ioctl(i->fd, SIOCSIFADDR, &ifr) < 0) + daemon_log(LOG_WARNING, "Warning: Could not set interface address."); + } + + if (ioctl(i->fd, SIOCGIFFLAGS, &ifr) < 0) { + daemon_log(LOG_WARNING, "Warning: Could not get interface flags."); + return; + } + + ifr.ifr_flags |= IFF_UP; + + if (ioctl(i->fd, SIOCSIFFLAGS, &ifr) < 0) + daemon_log(LOG_WARNING, "Warning: Could not set interface flags."); + + daemon_log(LOG_INFO, "Interface set to status UP."); +} diff --git a/src/interface.h b/src/interface.h index c05c5b3..daa6d97 100644 --- a/src/interface.h +++ b/src/interface.h @@ -33,5 +33,6 @@ struct interface { struct interface *interface_open(char *name); void interface_close(struct interface *i); int interface_is_assoc(struct interface *i, struct hw_addr *a); +void interface_up(struct interface *i); #endif diff --git a/src/iwapi.c b/src/iwapi.c index 5d8afe8..64eb8b2 100644 --- a/src/iwapi.c +++ b/src/iwapi.c @@ -236,14 +236,19 @@ int iw_scan_result(struct interface *i, int (*callback)(struct ap_info* ap)) { } int iw_tune(struct interface *i, struct ap_info *ap) { + char c[67]; assert(i && ap); + snprint_hw_addr(c, sizeof(c), &ap->ap); + /* We are not interested in the return values of these functions due to driver issues */ + daemon_log(LOG_INFO, "Tuning %s ... %s", ap->essid, c); iw_set_mode(i, IW_MODE_INFRA); iw_set_essid(i, ap->essid); //iw_set_freq(i, &ap->freq); iw_set_ap(i, &ap->ap); + return 0; } @@ -302,21 +307,21 @@ int iw_get_mode(struct interface *i, int *m) { return 0; } -int iw_get_freq(struct interface *i, struct iw_freq *f) { - struct iwreq req; - assert(i && f); +/* int iw_get_freq(struct interface *i, struct iw_freq *f) { */ +/* struct iwreq req; */ +/* assert(i && f); */ - memset(&req, 0, sizeof(req)); - strncpy(req.ifr_ifrn.ifrn_name, i->name, IFNAMSIZ); +/* memset(&req, 0, sizeof(req)); */ +/* strncpy(req.ifr_ifrn.ifrn_name, i->name, IFNAMSIZ); */ - if (ioctl(i->fd, SIOCGIWFREQ, &req) < 0) { - memset(f, 0, sizeof(struct iw_freq)); /* hostap 0.1.2 fails to report the freq sometimes */ - return 0; - } +/* if (ioctl(i->fd, SIOCGIWFREQ, &req) < 0) { */ +/* memset(f, 0, sizeof(struct iw_freq)); /\* hostap 0.1.2 fails to report the freq sometimes *\/ */ +/* return 0; */ +/* } */ - *f = req.u.freq; - return 0; -} +/* *f = req.u.freq; */ +/* return 0; */ +/* } */ int iw_assoc(struct interface *i, struct ap_info *ap) { struct hw_addr hw; @@ -369,6 +374,7 @@ int iw_assoc(struct interface *i, struct ap_info *ap) { (q.qual.level > range.max_qual.level ? q.qual.level <= 156 : q.qual.level <= 0)) return 0; + if (ap) { memset(ap, 0, sizeof(struct ap_info)); @@ -377,8 +383,8 @@ int iw_assoc(struct interface *i, struct ap_info *ap) { if (iw_get_essid(i, ap->essid) < 0) return -1; - if (iw_get_freq(i, &ap->freq) < 0) - return -1; + /* if (iw_get_freq(i, &ap->freq) < 0) */ +/* return -1; */ } return 1; diff --git a/src/iwhostroam.c b/src/iwhostroam.c index 33d5d9c..f3cc997 100644 --- a/src/iwhostroam.c +++ b/src/iwhostroam.c @@ -1,4 +1,4 @@ -/* $Id: iwapi.c 45 2003-11-15 10:30:30Z lennart $ */ +/* $Id$ */ /* * This file is part of waproamd. diff --git a/src/nlapi.c b/src/nlapi.c index 1738325..3447a9a 100644 --- a/src/nlapi.c +++ b/src/nlapi.c @@ -67,7 +67,7 @@ int nlapi_work(int block) { for (;;) { int bytes; - char replybuf[1024]; + char replybuf[2048]; struct nlmsghdr *p = (struct nlmsghdr *) replybuf; if ((bytes = recv(nlapi_fd, &replybuf, sizeof(replybuf), block ? 0 : MSG_DONTWAIT)) < 0) { diff --git a/src/waproamd.c b/src/waproamd.c index 8e2d5ad..aa3381f 100644 --- a/src/waproamd.c +++ b/src/waproamd.c @@ -32,6 +32,7 @@ #include <signal.h> #include <stdlib.h> #include <getopt.h> +#include <sys/stat.h> #include <libdaemon/dpid.h> #include <libdaemon/dlog.h> @@ -68,12 +69,13 @@ int use_assocwatch = 1, use_userspace_roaming = 1; int poll_interval = 5, - scan_interval = 10; + scan_interval = 30; char log_ident[32], pid_ident[32]; int get_script_path(char *path, int l, struct ap_info *ai) { assert(path && l); + struct stat st; if (!ai) { snprintf(path, l, "%s/default", SCRIPTDIR); @@ -85,30 +87,30 @@ int get_script_path(char *path, int l, struct ap_info *ai) { ai->ap.addr[0], ai->ap.addr[1], ai->ap.addr[2], ai->ap.addr[3], ai->ap.addr[4], ai->ap.addr[5]); - if (!access(path, X_OK)) - return 0; + if (!stat(path, &st)) + return st.st_mode & S_IXUSR ? 0 : 1; snprintf(path, l, "%s/%02X:%02X:%02X:%02X:%02X:%02X", SCRIPTDIR, ai->ap.addr[0], ai->ap.addr[1], ai->ap.addr[2], ai->ap.addr[3], ai->ap.addr[4], ai->ap.addr[5]); - if (!access(path, X_OK)) - return 0; + if (!stat(path, &st)) + return st.st_mode & S_IXUSR ? 0 : 1; if (ai->essid[0]) { snprintf(path, l, "%s/essid:%s", SCRIPTDIR, escape_essid(ai->essid)); - if (!access(path, X_OK)) - return 0; + if (!stat(path, &st)) + return st.st_mode & S_IXUSR ? 0 : 1; } return -1; } -int aps_found_n; +int total_aps_found_n, aps_found_n; struct ap_info scan_ap; int scan_ap_has_script; @@ -119,19 +121,23 @@ static int scan_result_cb(struct ap_info*ai) { assert(ai); - aps_found_n++; - - if (aps_found_n == 1) + if (total_aps_found_n == 0) daemon_log(LOG_INFO, "Scan results:"); + total_aps_found_n++; + snprint_hw_addr(t, sizeof(t), &ai->ap); f = get_script_path(path, sizeof(path), ai); - daemon_log(LOG_INFO, "%i. Found AP %s, ESSID '%s', script: %s", aps_found_n, t, escape_essid(ai->essid), !f ? "yes" : "no"); + daemon_log(LOG_INFO, "%i. Found AP %s, ESSID '%s', script: %s", total_aps_found_n, t, escape_essid(ai->essid), f == 0 ? "yes" : (f < 0 ? "no" : "off")); - /* Select this AP, if no better was found before */ - if (aps_found_n <= 1 || (!scan_ap_has_script && f == 0)) { - memcpy(&scan_ap, ai, sizeof(struct ap_info)); - scan_ap_has_script = f == 0; + if (f <= 0) { + aps_found_n++; + + /* Select this AP, if no better was found before */ + if ((aps_found_n <= 1 || (!scan_ap_has_script && f == 0))) { + memcpy(&scan_ap, ai, sizeof(struct ap_info)); + scan_ap_has_script = f == 0; + } } return 0; @@ -139,7 +145,7 @@ static int scan_result_cb(struct ap_info*ai) { int read_scan(struct interface *i, struct ap_info **ap) { int r; - aps_found_n = 0; + aps_found_n = total_aps_found_n = 0; scan_ap_has_script = 0; memset(&scan_ap, 0, sizeof(scan_ap)); @@ -149,8 +155,7 @@ int read_scan(struct interface *i, struct ap_info **ap) { if (r == 1) return 1; - if (aps_found_n >= 1) - daemon_log(LOG_INFO, "Scan finished."); + daemon_log(LOG_INFO, "Scan completed with %u suitable networks. (total: %u)", aps_found_n, total_aps_found_n); *ap = aps_found_n > 0 ? &scan_ap : NULL; @@ -254,6 +259,8 @@ int go(struct interface *i) { if (nlapi_open(RTMGRP_LINK) < 0) goto finish; + interface_up(i); + /* Check whether interface is available */ if (use_ifmonitor) { int b; @@ -363,7 +370,7 @@ int go(struct interface *i) { if (nlapi_work(0) < 0) goto finish; - if (!disabled && !paused) { + if (!disabled && !paused && !scanning) { if ((associated = iw_assoc(i, &associated_ap)) < 0) { if (!use_ifmonitor) @@ -385,7 +392,7 @@ int go(struct interface *i) { /* Changed: enabled -> disabled */ if (!d && disabled) { - daemon_log(LOG_INFO, "Interface disabled"); + daemon_log(LOG_INFO, "Interface disabled."); if (associated) if (set_current_ap(i, NULL) < 0) @@ -396,11 +403,15 @@ int go(struct interface *i) { /* Changed: disabled -> enabled */ if (d && !disabled) { - daemon_log(LOG_INFO, "Interface enabled"); + daemon_log(LOG_INFO, "Interface enabled."); associated = scanning = 0; - if (iw_set_hostroam(i, 2) < 0) - daemon_log(LOG_WARNING, "Enabling user space roaming failed, doing without."); + interface_up(i); + + if (use_userspace_roaming) { + if (iw_set_hostroam(i, 2) < 0) + daemon_log(LOG_WARNING, "Enabling user space roaming failed, doing without."); + } } if (!disabled) { |