summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2004-01-16 16:10:58 +0000
committerLennart Poettering <lennart@poettering.net>2004-01-16 16:10:58 +0000
commita084f62ea25f533b43233cdbb000fd0353585bcb (patch)
tree2f655c24f2e3302494fe44826499d91c0c16dbbd
parent17a2f212c279786e9a24a8fdf0d0973f8c5bdecb (diff)
fixes for hostap 0.1.2
git-svn-id: file:///home/lennart/svn/public/waproamd/trunk@57 022f378f-78c4-0310-b860-d162c87e6274
-rw-r--r--doc/README.html.in4
-rw-r--r--doc/style.css5
-rw-r--r--src/iwapi.c76
-rw-r--r--src/iwapi.h2
-rw-r--r--src/waproamd.c58
5 files changed, 71 insertions, 74 deletions
diff --git a/doc/README.html.in b/doc/README.html.in
index e94b2c9..1891d77 100644
--- a/doc/README.html.in
+++ b/doc/README.html.in
@@ -192,8 +192,8 @@ 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>.
<hr/>
-<address>Lennart Poettering &lt;@PACKAGE_BUGREPORT@&gt;, October 2003</address>
-<div><i>$Id$</i></div>
+<address class="grey">Lennart Poettering &lt;@PACKAGE_BUGREPORT@&gt;, October 2003</address>
+<div class="grey"><i>$Id$</i></div>
</body>
</html>
diff --git a/doc/style.css b/doc/style.css
index f71e501..7ac5cc2 100644
--- a/doc/style.css
+++ b/doc/style.css
@@ -23,7 +23,10 @@ a:link, a:visited { color: #900000; }
p { margin-left: 0.5cm; margin-right: 0.5cm; }
div.news-date { margin-left: 0.5cm; font-size: 80%; color: #4f0000; }
p.news-text { margin-left: 1cm; }
-ul { margin-left: 0.5cm; }
h1 { color: #00009F; }
h2 { color: #00009F; }
h3 { color: #00004F; margin-left: 0.5cm; }
+ul { margin-left: .5cm; }
+ol { margin-left: .5cm; }
+pre { margin-left: .5cm; background-color: #f0f0f0; padding: 0.4cm;}
+.grey { color: #afafaf; }
diff --git a/src/iwapi.c b/src/iwapi.c
index f5338f6..5d8afe8 100644
--- a/src/iwapi.c
+++ b/src/iwapi.c
@@ -44,7 +44,7 @@ int iw_set_essid(struct interface *i, const char* essid) {
}
if (ioctl(i->fd, SIOCSIWESSID, &req) < 0) {
- daemon_log(LOG_ERR, "ioctl(SIOCSIWESSID): %s\n", strerror(errno));
+ daemon_log(LOG_ERR, "ioctl(SIOCSIWESSID): %s", strerror(errno));
return -1;
}
@@ -60,28 +60,28 @@ int iw_set_mode(struct interface *i, int m) {
req.u.mode = m;
if (ioctl(i->fd, SIOCSIWMODE, &req) < 0) {
- daemon_log(LOG_ERR, "ioctl(SIOCSIWMODE): %s\n", strerror(errno));
+ daemon_log(LOG_ERR, "ioctl(SIOCSIWMODE): %s", strerror(errno));
return -1;
}
return 0;
}
-int iw_set_freq(struct interface *i, const struct iw_freq *f) {
- struct iwreq req;
- assert(i && f);
+/* int iw_set_freq(struct interface *i, const struct iw_freq *f) { */
+/* struct iwreq req; */
+/* assert(i && f); */
- memset(&req, 0, sizeof(req));
- strncpy(req.ifr_ifrn.ifrn_name, i->name, IFNAMSIZ);
- req.u.freq = *f;
+/* memset(&req, 0, sizeof(req)); */
+/* strncpy(req.ifr_ifrn.ifrn_name, i->name, IFNAMSIZ); */
+/* req.u.freq = *f; */
- if (ioctl(i->fd, SIOCSIWFREQ, &req) < 0) {
- daemon_log(LOG_ERR, "ioctl(SIOCSIWFREQ): %s\n", strerror(errno));
- return -1;
- }
+/* if (ioctl(i->fd, SIOCSIWFREQ, &req) < 0) { */
+/* daemon_log(LOG_ERR, "ioctl(SIOCSIWFREQ): %s", strerror(errno)); */
+/* return -1; */
+/* } */
- return 0;
-}
+/* return 0; */
+/* } */
int iw_set_ap(struct interface *i, const struct hw_addr *ap) {
struct iwreq req;
@@ -94,7 +94,7 @@ int iw_set_ap(struct interface *i, const struct hw_addr *ap) {
memcpy(req.u.ap_addr.sa_data, ap->addr, ETH_ALEN);
if (ioctl(i->fd, SIOCSIWAP, &req) < 0) {
- daemon_log(LOG_ERR, "ioctl(SIOCSIWAP): %s\n", strerror(errno));
+ daemon_log(LOG_ERR, "ioctl(SIOCSIWAP): %s", strerror(errno));
return -1;
}
@@ -105,6 +105,12 @@ int iw_scan(struct interface *i) {
struct iwreq req;
assert(i);
+ daemon_log(LOG_INFO, "Scanning...");
+
+ iw_set_mode(i, IW_MODE_INFRA);
+ iw_set_essid(i, NULL);
+ /* Due to driver issues, the return codes of these function calls are no longer evaluated */
+
memset(&req, 0, sizeof(req));
strncpy(req.ifr_ifrn.ifrn_name, i->name, IFNAMSIZ);
@@ -112,7 +118,7 @@ int iw_scan(struct interface *i) {
req.u.param.value = 0;
if (ioctl(i->fd, SIOCSIWSCAN, &req) < 0) {
- daemon_log(LOG_ERR, "ioctl(SIOCSIWSCAN): %s\n", strerror(errno));
+ daemon_log(LOG_ERR, "ioctl(SIOCSIWSCAN): %s", strerror(errno));
return -1;
}
@@ -140,7 +146,7 @@ int iw_scan_result(struct interface *i, int (*callback)(struct ap_info* ap)) {
if (errno == EAGAIN)
return 1;
- daemon_log(LOG_ERR, "ioctl(SIOCGIWSCAN): %s\n", strerror(errno));
+ daemon_log(LOG_ERR, "ioctl(SIOCGIWSCAN): %s", strerror(errno));
return -1;
}
@@ -148,9 +154,11 @@ int iw_scan_result(struct interface *i, int (*callback)(struct ap_info* ap)) {
l = req.u.data.length;
f = 0;
hs = sizeof(struct iw_event)-sizeof(union iwreq_data);
+
while (l >= sizeof(struct iw_event)) {
+
if (e->len < hs) {
- daemon_log(LOG_ERR, "Recieved bogus wireless event\n");
+ daemon_log(LOG_ERR, "Recieved bogus wireless event");
return -1;
}
@@ -162,9 +170,9 @@ int iw_scan_result(struct interface *i, int (*callback)(struct ap_info* ap)) {
case SIOCGIWAP:
f = 1;
-
+
if (e->len < hs + sizeof(struct sockaddr)) {
- daemon_log(LOG_ERR, "Corrupt scan result (1)\n");
+ daemon_log(LOG_ERR, "Corrupt scan result (1)");
return -1;
}
@@ -175,7 +183,7 @@ int iw_scan_result(struct interface *i, int (*callback)(struct ap_info* ap)) {
case SIOCGIWESSID:
if (e->len < hs + sizeof(struct iw_point)) {
- daemon_log(LOG_ERR, "Corrupt scan result (2)\n");
+ daemon_log(LOG_ERR, "Corrupt scan result (2)");
return -1;
}
@@ -189,7 +197,7 @@ int iw_scan_result(struct interface *i, int (*callback)(struct ap_info* ap)) {
case SIOCGIWMODE:
if (e->len < hs + sizeof(__u32)) {
- daemon_log(LOG_ERR, "Corrupt scan result (3)\n");
+ daemon_log(LOG_ERR, "Corrupt scan result (3)");
return -1;
}
@@ -203,7 +211,7 @@ int iw_scan_result(struct interface *i, int (*callback)(struct ap_info* ap)) {
case SIOCGIWFREQ:
if (e->len < hs + sizeof(struct iw_freq)) {
- daemon_log(LOG_ERR, "Corrupt scan result (4)\n");
+ daemon_log(LOG_ERR, "Corrupt scan result (4)");
return -1;
}
@@ -233,7 +241,7 @@ int iw_tune(struct interface *i, struct ap_info *ap) {
/* We are not interested in the return values of these functions due to driver issues */
iw_set_mode(i, IW_MODE_INFRA);
iw_set_essid(i, ap->essid);
- iw_set_freq(i, &ap->freq);
+ //iw_set_freq(i, &ap->freq);
iw_set_ap(i, &ap->ap);
return 0;
@@ -247,7 +255,7 @@ int iw_get_ap(struct interface *i, struct hw_addr *ap) {
strncpy(req.ifr_ifrn.ifrn_name, i->name, IFNAMSIZ);
if (ioctl(i->fd, SIOCGIWAP, &req) < 0) {
- daemon_log(LOG_ERR, "ioctl(SIOCGIWAP): %s\n", strerror(errno));
+ daemon_log(LOG_ERR, "ioctl(SIOCGIWAP): %s", strerror(errno));
return -1;
}
@@ -269,7 +277,7 @@ int iw_get_essid(struct interface *i, char *essid) {
req.u.essid.flags = 1;
if (ioctl(i->fd, SIOCGIWESSID, &req) < 0) {
- daemon_log(LOG_ERR, "ioctl(SIOCGSIWESSID): %s\n", strerror(errno));
+ daemon_log(LOG_ERR, "ioctl(SIOCGSIWESSID): %s", strerror(errno));
return -1;
}
@@ -286,7 +294,7 @@ int iw_get_mode(struct interface *i, int *m) {
req.u.mode = 0;
if (ioctl(i->fd, SIOCGIWMODE, &req) < 0) {
- daemon_log(LOG_ERR, "ioctl(SIOCGIWMODE): %s\n", strerror(errno));
+ daemon_log(LOG_ERR, "ioctl(SIOCGIWMODE): %s", strerror(errno));
return -1;
}
@@ -302,8 +310,8 @@ int iw_get_freq(struct interface *i, struct iw_freq *f) {
strncpy(req.ifr_ifrn.ifrn_name, i->name, IFNAMSIZ);
if (ioctl(i->fd, SIOCGIWFREQ, &req) < 0) {
- daemon_log(LOG_ERR, "ioctl(SIOCGIWFREQ): %s\n", strerror(errno));
- return -1;
+ memset(f, 0, sizeof(struct iw_freq)); /* hostap 0.1.2 fails to report the freq sometimes */
+ return 0;
}
*f = req.u.freq;
@@ -339,7 +347,7 @@ int iw_assoc(struct interface *i, struct ap_info *ap) {
req.u.data.flags = 1;
if (ioctl(i->fd, SIOCGIWSTATS, &req) < 0) {
- daemon_log(LOG_ERR, "Failed to get interface quality\n");
+ daemon_log(LOG_ERR, "Failed to get interface quality");
return -1;
}
@@ -352,7 +360,7 @@ int iw_assoc(struct interface *i, struct ap_info *ap) {
req.u.data.flags = 0;
if (ioctl(i->fd, SIOCGIWRANGE, &req) < 0) {
- fprintf(stderr, "SIOCGIWRANGE failed: %s\n", strerror(errno));
+ fprintf(stderr, "SIOCGIWRANGE failed: %s", strerror(errno));
return -1;
}
@@ -368,9 +376,9 @@ 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)
- memset(&ap->freq, 0, sizeof(ap->freq)); /* hostap 0.1.2 fails to report the freq sometimes */
+ return -1;
}
return 1;
@@ -379,5 +387,5 @@ int iw_assoc(struct interface *i, struct ap_info *ap) {
int iw_ap_info_equal(const struct ap_info *a, const struct ap_info *b) {
assert(a && b);
- return !strcmp(a->essid, b->essid) && !memcmp(&a->freq, &b->freq, sizeof(a->freq));
+ return !strcmp(a->essid, b->essid) && !memcmp(&a->ap, &b->ap, sizeof(struct hw_addr));
}
diff --git a/src/iwapi.h b/src/iwapi.h
index b81b2dd..1ec830c 100644
--- a/src/iwapi.h
+++ b/src/iwapi.h
@@ -33,7 +33,7 @@ struct ap_info {
int iw_set_essid(struct interface *i, const char* essid);
int iw_set_mode(struct interface *i, int m);
-int iw_set_freq(struct interface *i, const struct iw_freq *f);
+/*int iw_set_freq(struct interface *i, const struct iw_freq *f);*/
int iw_set_ap(struct interface *i, const struct hw_addr *ap);
/* Size of string essid must be at least IW_ESSID_MAX_SIZE + 1 characters long */
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, &current_ap)) ||
- (!!a != !!current_ap_valid)) {
+ if ((a && current_ap_valid && !iw_ap_info_equal(a, &current_ap)) || (!!a != !!current_ap_valid)) {
if (current_ap_valid) {
if (run_script(&current_ap, "stop") < 0)
return -1;
}
- if ((current_ap_valid = !!a))
- memcpy(&current_ap, a, sizeof(struct ap_info));
-
- if (current_ap_valid) {
+ if ((current_ap_valid = !!a)) {
char t[20];
+
+ memcpy(&current_ap, a, sizeof(struct ap_info));
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));
@@ -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);