summaryrefslogtreecommitdiffstats
path: root/src/waproamd.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/waproamd.c')
-rw-r--r--src/waproamd.c89
1 files changed, 49 insertions, 40 deletions
diff --git a/src/waproamd.c b/src/waproamd.c
index 98cec2c..13e391c 100644
--- a/src/waproamd.c
+++ b/src/waproamd.c
@@ -41,6 +41,7 @@
#include "ifmonitor.h"
#include "assocwatch.h"
#include "waproamd.h"
+#include "iwhostroam.h"
#ifdef HAVE_CONFIG_H
#include <config.h>
@@ -65,7 +66,8 @@ int use_assocwatch = 1,
#ifdef DAEMON_PID_FILE_KILL_WAIT_AVAILABLE
wait_on_kill = 0,
#endif
- use_syslog = 1;
+ use_syslog = 1,
+ use_userspace_roaming = 1;
int poll_interval = 5,
scan_interval = 10;
@@ -172,15 +174,10 @@ int run_script(struct ap_info *ai, const char *arg) {
get_script_path(path, sizeof(path), NULL);
setenv("IFACE", interface_name, 1);
- if (!ai->adhoc) {
- snprint_hw_addr(t, sizeof(t), &ai->ap);
- setenv("AP", t, 1);
- } else
- setenv("AP", "n.a.", 1);
-
+ snprint_hw_addr(t, sizeof(t), &ai->ap);
+ setenv("AP", t, 1);
setenv("ESSID", ai->essid, 1);
setenv("ESSID_ESCAPED", escape_essid(ai->essid), 1);
- setenv("ADHOC", ai->adhoc ? "YES" : "NO", 1);
return log_exec(SCRIPTDIR, path, arg);
};
@@ -200,14 +197,9 @@ int set_current_ap(struct ap_info *a) {
memcpy(&current_ap, a, sizeof(struct ap_info));
if (current_ap_valid) {
-
- if (current_ap.adhoc)
- daemon_log(LOG_INFO, "Selected new ad hoc network with ESSID '%s'", escape_essid(a->essid));
- else {
- char t[20];
- snprint_hw_addr(t, sizeof(t), &current_ap.ap);
- daemon_log(LOG_INFO, "Selected new AP %s with ESSID '%s'", t, escape_essid(a->essid));
- }
+ char t[20];
+ snprint_hw_addr(t, sizeof(t), &current_ap.ap);
+ daemon_log(LOG_INFO, "Selected new AP %s with ESSID '%s'", t, escape_essid(a->essid));
if (run_script(&current_ap, "start") < 0)
return -1;
@@ -237,8 +229,6 @@ int assocwatch_cb(int index, struct hw_addr *a) {
if (strcmp(name, interface_name))
return 0;
- do_status_check = 1;
-
return 0;
}
@@ -265,6 +255,7 @@ int go(struct interface *i) {
if (nlapi_open(RTMGRP_LINK) < 0)
goto finish;
+ /* Check whether interface is available */
if (use_ifmonitor) {
int b;
@@ -275,16 +266,28 @@ int go(struct interface *i) {
} else
disabled = 0;
+ /* Try to enable userspace roaming in the driver */
+ if (!disabled && use_userspace_roaming) {
+
+ if (iw_set_hostroam(i, 2) < 0) {
+ daemon_log(LOG_WARNING, "Enabling user space roaming failed, doing without.");
+ use_userspace_roaming = 0;
+ }
+ }
+
memset(&current_ap, 0, sizeof(current_ap));
current_ap_valid = 0;
- if ((associated = iw_assoc(i, &associated_ap)) < 0) {
- if (!use_ifmonitor)
- goto finish;
-
- associated = 0;
+ /* Check association status */
+ if (!disabled) {
+ if ((associated = iw_assoc(i, &associated_ap)) < 0) {
+ if (!use_ifmonitor)
+ goto finish;
+
+ associated = 0;
+ }
}
-
+
daemon_log(LOG_INFO, "Currently %sassociated, interface %s.", associated ? "" : "not ", disabled ? "disabled" : "enabled");
if (use_assocwatch)
@@ -311,7 +314,7 @@ int go(struct interface *i) {
for (;;) {
fd_set qfds;
- struct timeval tv, *ptv = NULL;
+ struct timeval tv;
time_t now = time(NULL);
int a, d;
@@ -328,15 +331,12 @@ int go(struct interface *i) {
if (do_status_check) {
tv.tv_sec = 0;
tv.tv_usec = 0;
- ptv = &tv;
} if (scanning) {
tv.tv_sec = 0;
tv.tv_usec = 100000;
- ptv = &tv;
- } else if (!use_assocwatch) {
+ } else {
tv.tv_sec = poll_interval;
tv.tv_usec = 0;
- ptv = &tv;
}
if (next_scan != (time_t) -1) {
@@ -345,16 +345,13 @@ int go(struct interface *i) {
tv2.tv_sec = next_scan > now ? next_scan - now : 0;
tv2.tv_usec = 0;
- if (!ptv || tv2.tv_sec < tv.tv_sec) {
- tv.tv_sec = tv2.tv_sec;
- tv.tv_usec = tv2.tv_usec;
- ptv = &tv;
- }
+ if (tv2.tv_sec < tv.tv_sec)
+ tv = tv2;
}
qfds = fds;
-
- if (select(FD_SETSIZE, &qfds, NULL, NULL, ptv) < 0) {
+
+ if (select(FD_SETSIZE, &qfds, NULL, NULL, &tv) < 0) {
if (errno == EINTR)
continue;
@@ -369,7 +366,7 @@ int go(struct interface *i) {
if (nlapi_work(0) < 0)
goto finish;
- if (do_status_check || (!use_assocwatch && !disabled && !paused)) {
+ if (!disabled && !paused) {
if ((associated = iw_assoc(i, &associated_ap)) < 0) {
if (!use_ifmonitor)
@@ -378,10 +375,9 @@ int go(struct interface *i) {
associated = 0;
}
+ do_status_check = 0;
}
- do_status_check = 0;
-
if (paused) {
/* If paused ignore new data */
@@ -510,7 +506,13 @@ int go(struct interface *i) {
finish:
+ daemon_log(LOG_INFO, "Shutdown");
+
+
set_current_ap(NULL);
+
+ if (use_userspace_roaming)
+ iw_set_hostroam(i, 0);
if (send_retval && daemonize && wait_on_fork)
daemon_retval_send(1);
@@ -541,6 +543,7 @@ void usage(char *p) {
#endif
" -M --monitor Use interface monitoring (%s)\n"
" -e --no-event Don't use wireless event API (%s)\n"
+ " -U --no-userspace-roaming Don't enable user space roaming via private ioctl (%s)\n"
" -t --scan-interval=SECS Specify scan interval (%i)\n"
" -p --poll-interval=SECS Specify association poll interval, unless using -e (%i)\n"
" -h --help Show this help\n"
@@ -560,6 +563,7 @@ void usage(char *p) {
#endif
use_ifmonitor ? "on" : "off",
use_assocwatch ? "off" : "on",
+ use_userspace_roaming ? "off" : "on",
scan_interval,
poll_interval);
}
@@ -575,6 +579,7 @@ void parse_args(int argc, char *argv[]) {
#endif
{"monitor", no_argument, 0, 'M'},
{"no-event", no_argument, 0, 'e'},
+ {"no-userspace-roaming", no_argument, 0, 'U'},
{"scan-interval", required_argument, 0, 't'},
{"poll-interval", required_argument, 0, 'p'},
{"help", no_argument, 0, 'h'},
@@ -592,7 +597,7 @@ void parse_args(int argc, char *argv[]) {
for (;;) {
int c;
- if ((c = getopt_long(argc, argv, "nsi:whkcvMet:p:SRrWr", long_options, &option_index)) < 0)
+ if ((c = getopt_long(argc, argv, "nsi:whkcvMet:p:SRrWrU", long_options, &option_index)) < 0)
break;
switch (c) {
@@ -639,6 +644,10 @@ void parse_args(int argc, char *argv[]) {
use_assocwatch = !use_assocwatch;
break;
+ case 'U':
+ use_userspace_roaming = !use_userspace_roaming;
+ break;
+
case 't':
if ((scan_interval = atoi(optarg)) < 0) {
daemon_log(LOG_ERR, "Scan interval must be a positive, nonzero integer.");