shithub: riscv

Download patch

ref: dda7b2c49fe54d500769216f37b54d189b3b03a4
parent: 232dad19ad9b55895df872d5b1e7f8011b020e64
author: cinap_lenrek <cinap_lenrek@gmx.de>
date: Mon Aug 19 12:07:07 EDT 2013

wpa: repeat rsne setup after deassociation (roamng between access points)

the "auth" ctl command only sets the rsne of the current selected
access point. so on deassociation, we wait for the connection to
the potentially new access point and then setup new rsne before
processing eapol messages.

--- a/sys/src/cmd/aux/wpa.c
+++ b/sys/src/cmd/aux/wpa.c
@@ -57,6 +57,7 @@
 Cipher	*peercipher;
 Cipher	*groupcipher;
 
+int	background;
 int	prompt;
 int	debug;
 int	fd, cfd;
@@ -544,6 +545,7 @@
 main(int argc, char *argv[])
 {
 	uchar mac[Eaddrlen], buf[1024];
+	static uchar brsne[258];
 	char addr[128];
 	uchar *rsne;
 	int rsnelen;
@@ -614,13 +616,12 @@
 		free(s);
 	}
 
+Connect:
  	/* bss scan might not be complete yet, so check for 10 seconds.	*/
-	for(try = 10; try >= 0 && !connected(); try--)
+	for(try = 10; (background || try >= 0) && !connected(); try--)
 		sleep(1000);
 
-	if(rsnelen <= 0){
-		static uchar brsne[258];
-
+	if(rsnelen <= 0 || rsne == brsne){
 		rsne = brsne;
 		rsnelen = buildrsne(rsne);
 	}
@@ -644,18 +645,22 @@
 	if(write(cfd, buf, n) != n)
 		sysfatal("write auth: %r");
 
-	if(!debug){
-		switch(rfork(RFFDG|RFREND|RFPROC|RFNOWAIT)){
-		default:
-			exits(nil);
-		case -1:
-			sysfatal("fork: %r");
-			return;
-		case 0:
-			break;
+	if(!background){
+		background = 1;
+		if(!debug){
+			switch(rfork(RFFDG|RFREND|RFPROC|RFNOWAIT)){
+			default:
+				exits(nil);
+			case -1:
+				sysfatal("fork: %r");
+				return;
+			case 0:
+				break;
+			}
 		}
 	}
 	
+	lastrepc = 0ULL;
 	for(;;){
 		uchar smac[Eaddrlen], amac[Eaddrlen], snonce[Noncelen], anonce[Noncelen], *p, *e, *m;
 		int proto, eapver, flags, vers, datalen;
@@ -668,8 +673,7 @@
 		if(n == 0){
 			if(debug != 0)
 				fprint(2, "got deassociation\n");
-			lastrepc = 0ULL;
-			continue;
+			goto Connect;
 		}
 
 		p = buf;
--