shithub: riscv

Download patch

ref: 521a0b336c7df8ad79efc7848c95a7b060beea27
parent: b31e965ea36f21cf4da91ae33d840999e10a76d4
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sun Nov 17 14:04:38 EST 2019

bootrc: for wireless netbooting, set the WPA/WPA2 preshard key with wpapsk=password boot parameter

this allows automatic netbooting without password prompt
for the wirelss network.

--- a/sys/man/8/plan9.ini
+++ b/sys/man/8/plan9.ini
@@ -420,9 +420,6 @@
 	cat /net/ether1/ifstats
 .EE
 Ad-hoc mode or WEP encryption is currently not supported.
-To enable WPA/WPA2 encryption, see
-.IR wpa (8)
-for details.
 .TP
 .B rt2860
 Ralink Technology PCI/PCI-Express wireless adapters require
@@ -443,6 +440,14 @@
 or
 .B /boot. 
 See iwl section above for configuration details.
+.SS \fLwpapsk\fI=password\fP
+WPA/WPA2 encryption
+is detected automatically and a prompt for the
+.I password
+will appear when using the WIFI interface for netbooting.
+To avoid the prompt, the
+.I password
+can be specified with the boot parameter above.
 .SS \fLnora6=
 Disable automatic IPv6 configuration from incoming router advertisements.
 .SS DISKS, TAPES
--- a/sys/src/9/boot/net.rc
+++ b/sys/src/9/boot/net.rc
@@ -9,10 +9,23 @@
 	}
 
 	# setup wifi encryption if any
-	if(~ $1 ether && ~ $service terminal && test -x /bin/aux/wpa){
-		if(grep -s '^status: need authentication' $2/ifstats >[2]/dev/null){
-			aux/wpa -p $2
+	if(~ $1 ether && test -x /bin/aux/wpa){
+		essid=`{grep '^essid: ' $2/ifstats | sed 's/^essid: //; q'}
+		if(! ~ $#essid 0){
+			if(! ~ $#wpapsk 0 || grep -s '^status: need authentication' $2/ifstats >[2]/dev/null){
+				x=(aux/wpa -s $"essid)
+				if(! ~ $#wpapsk 0){
+					echo 'key proto=wpapsk' `{!password=$"wpapsk whatis essid !password} > /mnt/factotum/ctl
+					wpapsk=()
+				}
+				if not {
+					x=($x -p)		
+				}
+				$x $2
+			}
+			essid=()
 		}
+		rm -f /env/^(essid wpapsk)
 	}
 
 	if(~ $1 ether gbe && ~ $#* 2) @{