From 4755fce1dc286432a952fa5acb54c7fa880fe1b2 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Thu, 18 Jul 2013 16:16:31 +0200 Subject: wpa: wait for bss to connect waiting at the auth command is too late because we want to read the brsne first to build the rsne used in the auth message. --- sys/src/cmd/aux/wpa.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/sys/src/cmd/aux/wpa.c b/sys/src/cmd/aux/wpa.c index 61f765146..430d1b091 100644 --- a/sys/src/cmd/aux/wpa.c +++ b/sys/src/cmd/aux/wpa.c @@ -154,6 +154,22 @@ getessid(void) return getifstats("essid:", essid, sizeof(essid)); } +int +connected(void) +{ + char status[1024]; + + if(getifstats("status:", status, sizeof(status)) == nil) + return 0; + if(strcmp(status, "connecting") == 0) + return 0; + if(strcmp(status, "unauthenticated") == 0) + return 0; + if(debug) + fprint(2, "status: %s\n", status); + return 1; +} + int buildrsne(uchar rsne[258]) { @@ -598,6 +614,10 @@ main(int argc, char *argv[]) free(s); } + /* bss scan might not be complete yet, so check for 10 seconds. */ + for(try = 10; try >= 0 && !connected(); try--) + sleep(1000); + if(rsnelen <= 0){ static uchar brsne[258]; @@ -618,13 +638,10 @@ main(int argc, char *argv[]) /* * we use write() instead of fprint so the message gets written - * at once and not chunked up on fprint buffer. bss scan might - * not be complete yet, so retry for 10 seconds. + * at once and not chunked up on fprint buffer. */ n = sprint((char*)buf, "auth %.*H", rsnelen, rsne); - for(try = 10; try >= 0 && write(cfd, buf, n) != n; try--) - sleep(1000); - if(try < 0) + if(write(cfd, buf, n) != n) sysfatal("write auth: %r"); if(!debug){ -- cgit v1.2.3