shithub: riscv

Download patch

ref: b9d2a9efd5cb230009b3181d4699017155187b19
parent: d13142b3daba5e76646cd36f718a1ff5ae9e25d4
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Wed Dec 27 23:34:03 EST 2017

wifi: don't implicitely update lastseen timestamp on nodelookup()

in case we continue to send traffic (like ping) with the ap gone,
the sending would keep updating bss->lastseen which prevents the
timeout to happen to switch bss.

--- a/sys/src/9/pc/wifi.c
+++ b/sys/src/9/pc/wifi.c
@@ -189,10 +189,8 @@
 	if(memcmp(bssid, wifi->ether->bcast, Eaddrlen) == 0)
 		return nil;
 	if((wn = wifi->bss) != nil){
-		if(memcmp(wn->bssid, bssid, Eaddrlen) == 0){
-			wn->lastseen = MACHP(0)->ticks;
+		if(memcmp(wn->bssid, bssid, Eaddrlen) == 0)
 			return wn;
-		}
 	}
 	if((nn = wifi->node) == wn)
 		nn++;
@@ -199,11 +197,10 @@
 	for(wn = wifi->node; wn != &wifi->node[nelem(wifi->node)]; wn++){
 		if(wn == wifi->bss)
 			continue;
-		if(memcmp(wn->bssid, bssid, Eaddrlen) == 0){
-			wn->lastseen = MACHP(0)->ticks;
+		if(memcmp(wn->bssid, bssid, Eaddrlen) == 0)
 			return wn;
-		}
-		if((long)(wn->lastseen - nn->lastseen) < 0)
+		if((long)(wn->lastsend - nn->lastsend) < 0
+		|| (long)(wn->lastseen - nn->lastseen) < 0)
 			nn = wn;
 	}
 	if(!new)
@@ -211,7 +208,6 @@
 	freewifikeys(wifi, nn);
 	memset(nn, 0, sizeof(Wnode));
 	memmove(nn->bssid, bssid, Eaddrlen);
-	nn->lastseen = MACHP(0)->ticks;
 	return nn;
 }
 
@@ -577,6 +573,7 @@
 			/* encrypted */
 			if((wn = nodelookup(wifi, w->a2, 0)) == nil)
 				continue;
+			wn->lastseen = MACHP(0)->ticks;
 			if((b = wifidecrypt(wifi, wn, b)) != nil){
 				w = (Wifipkt*)b->rp;
 				if(w->fc[1] & 0x40)
@@ -598,6 +595,7 @@
 		case 0x80:	/* beacon */
 			if((wn = nodelookup(wifi, w->a3, 1)) == nil)
 				continue;
+			wn->lastseen = MACHP(0)->ticks;
 			b->rp += wifihdrlen(w);
 			recvbeacon(wifi, wn, b->rp, BLEN(b));
 
@@ -615,6 +613,7 @@
 			continue;
 		if((wn = nodelookup(wifi, w->a3, 0)) == nil)
 			continue;
+		wn->lastseen = MACHP(0)->ticks;
 		switch(w->fc[0] & 0xf0){
 		case 0x10:	/* assoc response */
 		case 0x30:	/* reassoc response */