diff options
Diffstat (limited to 'src/waproamd.c')
-rw-r--r-- | src/waproamd.c | 58 |
1 files changed, 22 insertions, 36 deletions
diff --git a/src/waproamd.c b/src/waproamd.c index 3dba456..8e2d5ad 100644 --- a/src/waproamd.c +++ b/src/waproamd.c @@ -72,18 +72,6 @@ int poll_interval = 5, char log_ident[32], pid_ident[32]; -int issue_scan(struct interface *i) { - /* Due to driver issues, the return codes of these function calls are no longer evaluated */ - iw_set_mode(i, IW_MODE_INFRA); - iw_set_ap(i, &null_ap); - iw_set_essid(i, NULL); - - if (iw_scan(i) < 0) - return -1; - - return 0; -} - int get_script_path(char *path, int l, struct ap_info *ai) { assert(path && l); @@ -138,7 +126,7 @@ static int scan_result_cb(struct ap_info*ai) { 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 == 0 ? "yes" : "no"); + daemon_log(LOG_INFO, "%i. Found AP %s, ESSID '%s', script: %s", aps_found_n, t, escape_essid(ai->essid), !f ? "yes" : "no"); /* Select this AP, if no better was found before */ if (aps_found_n <= 1 || (!scan_ap_has_script && f == 0)) { @@ -154,7 +142,7 @@ int read_scan(struct interface *i, struct ap_info **ap) { aps_found_n = 0; scan_ap_has_script = 0; memset(&scan_ap, 0, sizeof(scan_ap)); - + if ((r = iw_scan_result(i, scan_result_cb)) < 0) return -1; @@ -173,7 +161,7 @@ int run_script(struct ap_info *ai, const char *arg) { char t[32]; char path[PATH_MAX]; int ret = 0; - + if (get_script_path(path, sizeof(path), ai) < 0) get_script_path(path, sizeof(path), NULL); @@ -182,6 +170,8 @@ int run_script(struct ap_info *ai, const char *arg) { setenv("AP", t, 1); setenv("ESSID", ai->essid, 1); setenv("ESSID_ESCAPED", escape_essid(ai->essid), 1); + + daemon_log(LOG_INFO, "Running script '%s %s'", path, arg); if (daemon_exec(SCRIPTDIR, &ret, path, path, arg, (char*) 0) < 0) daemon_log(LOG_WARNING, "Script execution failed abnormously."); @@ -194,22 +184,19 @@ int run_script(struct ap_info *ai, const char *arg) { }; +int set_current_ap(struct interface *i, struct ap_info *a) { -int set_current_ap(struct ap_info *a) { - - if ((a && current_ap_valid && !iw_ap_info_equal(a, ¤t_ap)) || - (!!a != !!current_ap_valid)) { + if ((a && current_ap_valid && !iw_ap_info_equal(a, ¤t_ap)) || (!!a != !!current_ap_valid)) { if (current_ap_valid) { if (run_script(¤t_ap, "stop") < 0) return -1; } - if ((current_ap_valid = !!a)) - memcpy(¤t_ap, a, sizeof(struct ap_info)); - - if (current_ap_valid) { + if ((current_ap_valid = !!a)) { char t[20]; + + memcpy(¤t_ap, a, sizeof(struct ap_info)); snprint_hw_addr(t, sizeof(t), ¤t_ap.ap); daemon_log(LOG_INFO, "Selected new AP %s with ESSID '%s'", t, escape_essid(a->essid)); @@ -310,7 +297,7 @@ int go(struct interface *i) { daemon_log(LOG_INFO, "Initialization complete."); - set_current_ap(associated ? &associated_ap : NULL); + set_current_ap(i, associated ? &associated_ap : NULL); next_scan = associated || disabled ? (time_t) -1 : 0; if (daemonize && wait_on_fork) { @@ -329,7 +316,7 @@ int go(struct interface *i) { int a, d; if (next_scan != (time_t) -1 && next_scan <= now) { - if (issue_scan(i) < 0) { + if (iw_scan(i) < 0) { if (!use_ifmonitor) goto finish; } else @@ -401,7 +388,7 @@ int go(struct interface *i) { daemon_log(LOG_INFO, "Interface disabled"); if (associated) - if (set_current_ap(NULL) < 0) + if (set_current_ap(i, NULL) < 0) goto finish; associated = scanning = 0; @@ -425,7 +412,7 @@ int go(struct interface *i) { /* Changed: not associated -> associated */ if (!a && associated) { - if (set_current_ap(&associated_ap) < 0) + if (set_current_ap(i, &associated_ap) < 0) goto finish; daemon_log(LOG_INFO, "Associated."); @@ -443,17 +430,16 @@ int go(struct interface *i) { scanning = 0; } else if (!r) { - + scanning = 0; - - if (!associated && ai) { - - if (iw_tune(i, ai) < 0) + + if (set_current_ap(i, ai) < 0) + if (!use_ifmonitor) goto finish; - - if (set_current_ap(ai) < 0) + + if (ai && iw_tune(i, ai) < 0) + if (!use_ifmonitor) goto finish; - } } } } @@ -522,7 +508,7 @@ finish: daemon_log(LOG_INFO, "Shutdown"); - set_current_ap(NULL); + set_current_ap(i, NULL); if (use_userspace_roaming) iw_set_hostroam(i, 0); |