diff options
Diffstat (limited to 'src')
-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 |
6 files changed, 97 insertions, 40 deletions
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) { |