summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2003-11-17 20:21:51 +0000
committerLennart Poettering <lennart@poettering.net>2003-11-17 20:21:51 +0000
commit525e8bcb518f643e9dd6a4f6af7aa064cd8ff497 (patch)
tree9c9a063799348ab32cd61c3593c9ed21413963a1
parente502657310238e9ec6917cc10484ec9929b97c08 (diff)
many fixes
git-svn-id: file:///home/lennart/svn/public/waproamd/trunk@49 022f378f-78c4-0310-b860-d162c87e6274
-rw-r--r--src/waproamd.c37
1 files changed, 21 insertions, 16 deletions
diff --git a/src/waproamd.c b/src/waproamd.c
index 13e391c..41cfa3f 100644
--- a/src/waproamd.c
+++ b/src/waproamd.c
@@ -75,10 +75,6 @@ int poll_interval = 5,
char log_ident[32], pid_ident[32];
int issue_scan(struct interface *i) {
- static int count = 0;
-
- daemon_log(LOG_ERR, "Scanning... %i", count++);
-
/* 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);
@@ -126,34 +122,40 @@ int get_script_path(char *path, int l, struct ap_info *ai) {
return -1;
}
+int aps_found_n;
+
struct ap_info scan_ap;
int scan_ap_has_script;
-int scan_ap_valid;
static int scan_result_cb(struct ap_info*ai) {
int f;
- char path[PATH_MAX];
+ char path[PATH_MAX], t[32];
assert(ai);
- /* Found something suitable earlier */
- if (scan_ap_valid && scan_ap_has_script)
- return 0;
+ aps_found_n++;
+
+ if (aps_found_n == 1)
+ daemon_log(LOG_INFO, "Scan results:");
+ snprint_hw_addr(t, sizeof(t), &ai->ap);
f = get_script_path(path, sizeof(path), ai);
- if (scan_ap_valid && !f)
- return 0;
+ daemon_log(LOG_INFO, "%i. Found AP %s, ESSID '%s', script: %s", aps_found_n, t, escape_essid(ai->essid), f == 0 ? "yes" : "no");
- memcpy(&scan_ap, ai, sizeof(struct ap_info));
- scan_ap_valid = 1;
- scan_ap_has_script = !f;
+ /* 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;
}
int read_scan(struct interface *i, struct ap_info **ap) {
int r;
- scan_ap_valid = 0;
+ 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;
@@ -161,7 +163,10 @@ int read_scan(struct interface *i, struct ap_info **ap) {
if (r == 1)
return 1;
- *ap = scan_ap_valid ? &scan_ap : NULL;
+ if (aps_found_n >= 1)
+ daemon_log(LOG_INFO, "Scan finished.");
+
+ *ap = aps_found_n > 0 ? &scan_ap : NULL;
return 0;
}