summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWolfgang Wiedmeyer <wolfgit@wiedmeyer.de>2017-03-01 00:47:19 +0100
committerWolfgang Wiedmeyer <wolfgit@wiedmeyer.de>2017-03-01 01:02:41 +0100
commitccb6e97d1742f0627d016ab329ce1cdfb5e3fc4b (patch)
tree262743d8b506496ac198095a1c196b91db097ce4
parent4cd9fd86f62a0187edec86be440ffbeb2fedef9d (diff)
downloaduser-scripts-ccb6e97d1742f0627d016ab329ce1cdfb5e3fc4b.tar.gz
user-scripts-ccb6e97d1742f0627d016ab329ce1cdfb5e3fc4b.tar.bz2
user-scripts-ccb6e97d1742f0627d016ab329ce1cdfb5e3fc4b.zip
wifi: import Timothy Magee's changes
Fixes an issue where the scripts aren't pushed to the right directory on the device. Connecting to unsecured networks is now also supported. Full credit for these improvements goes to Timothy Magee.
-rw-r--r--networking/wifi/device-files/connect.sh42
-rw-r--r--networking/wifi/device-files/networks/add_network.sh33
-rw-r--r--networking/wifi/device-files/select_network.sh39
-rw-r--r--networking/wifi/setup.sh2
4 files changed, 78 insertions, 38 deletions
diff --git a/networking/wifi/device-files/connect.sh b/networking/wifi/device-files/connect.sh
index 133fbd5..7738422 100644
--- a/networking/wifi/device-files/connect.sh
+++ b/networking/wifi/device-files/connect.sh
@@ -24,22 +24,25 @@ if [ $? -ne 0 ]; then
exit 1
fi
-# parse arguments <ssid> <password>
+# parse arguments <ssid> [<password>]
+# If no <password>, then assume no authentication
if [ $# -eq 0 ]; then
- echo "Missing arguments <ssid> <password> "
- exit 1
-fi
-
-if [ $# -ne 2 ]; then
- echo "Wrong argument count!"
- exit 1
+ echo "Usage: bash connect.sh <ssid> [<password>] "
+ exit 1
+elif [ $# -eq 1 ]; then
+ # If no password, we assume that no authentication is necessary
+ SSID="$1"
+ NO_PASSWORD=1
+elif [ $# -eq 2 ]; then
+ #If a a password is passed, we assume WPA-Personal
+ SSID="$1"
+ PASSWORD="$2"
+ NO_PASSWORD=0
+else
+ echo "Usage: bash connect.sh <ssid> [<password>]"
+ exit 1
fi
-# Set SSID and password of your wifi access point
-# WPA-Personal authentication method is assumed
-SSID="$1"
-PASSWORD="$2"
-
wpa_comm="wpa_cli -p$socketfile -P$pidfile -i$ifacename"
sup_pid=$(pidof wpa_supplicant)
@@ -81,11 +84,20 @@ if [ $? -ne 0 ]; then
echo "[DEBUG]set_network ssid FAILED!"
exit 1
fi
-$wpa_comm set_network 0 psk '"'"$PASSWORD"'"'
-if [ $? -ne 0 ]; then
+
+if [ $NO_PASSWORD -eq 1 ]; then
+ $wpa_comm set_network 0 key_mgmt NONE
+ if [ $? -ne 0 ]; then
+ echo "[DEBUG]set_network 0 key_mgmt NONE FAILED!"
+ fi
+else
+ $wpa_comm set_network 0 psk '"'"$PASSWORD"'"'
+ if [ $? -ne 0 ]; then
echo "[DEBUG]set_network psk FAILED!"
exit 1
+ fi
fi
+
$wpa_comm select_network 0
if [ $? -ne 0 ]; then
echo "[DEBUG]select_network 0 FAILED!"
diff --git a/networking/wifi/device-files/networks/add_network.sh b/networking/wifi/device-files/networks/add_network.sh
index 230be42..04c93da 100644
--- a/networking/wifi/device-files/networks/add_network.sh
+++ b/networking/wifi/device-files/networks/add_network.sh
@@ -21,19 +21,26 @@ if [ $? -ne 0 ]; then
exit 1
fi
-# parse arguments <ssid> <password>
-if [ $# -eq 0 ]; then
- echo "Missing arguments <ssid> <password> "
- exit 1
-fi
-if [ $# -ne 2 ]; then
- echo "Wrong argument count!"
- exit 1
+# parse arguments <ssid> [<password>]
+# If no <password>, then assume no authentication
+if [ $# -eq 0 ]; then
+ echo "Usage: bash add_network.sh <ssid> [<password>] "
+ exit 1
+elif [ $# -eq 1 ]; then
+ # If no password, we assume that no authentication is necessary
+ curnet=$1
+ NO_PASSWORD=1
+elif [ $# -eq 2 ]; then
+ #If a a password is passed, we assume WPA-Personal
+ curnet=$1
+ pass=$2
+ NO_PASSWORD=0
+else
+ echo "Usage: bash add_network.sh <ssid> [<password>]"
+ exit 1
fi
-curnet=$1
-pass=$2
foundnet=$(bash "$knets_get" "$curnet")
if ! [ -z "$foundnet" ]; then
# the network is already a known one,
@@ -45,4 +52,8 @@ if ! [ -e "$knets_file" ]; then
echo -n "" > "$knets_file"
fi
-echo -e "$curnet""\t""$pass" >> $knets_file
+if [$NO_PASSWORD -eq 1]; then
+ echo -e "$curnet" >> $knets_file
+else
+ echo -e "$curnet""\t""$pass" >> $knets_file
+fi
diff --git a/networking/wifi/device-files/select_network.sh b/networking/wifi/device-files/select_network.sh
index cdb96ab..871a7eb 100644
--- a/networking/wifi/device-files/select_network.sh
+++ b/networking/wifi/device-files/select_network.sh
@@ -94,6 +94,7 @@ echo -e "\t---|------------------"
tmpLineFile="$workdir""/""tmpln"
idx=1
declare -a AR
+declare -a AUTH
while IFS= read -r line
do
# split the line into the different properties:
@@ -105,7 +106,8 @@ do
IFS=' '
read -r -a SUBAR < "$tmpLineFile"
AR[$idx]="${SUBAR[4]}" #the SSID is the 4th field
- echo -e "\t"$idx") | ""${SUBAR[4]}"
+ AUTH[$idx]="${SUBAR[3]}" #the auth method is the 3rd field
+ echo -e "\t"$idx") | ""${SUBAR[4]}"" | ${SUBAR[3]}"
idx=$(($idx+1))
done < "$tmpNetsFile"
@@ -126,40 +128,55 @@ if [ "$selnet" -le 0 ] || [ "$selnet" -gt "$netnum" ]; then
fi
selectedSSID="${AR[$selnet]}"
+selectedAuthScheme="${AUTH[$selnet]}"
# check if the selected network is a known one:
knownnet=$(bash "$knets_get" "$selectedSSID")
-if [ -z "$knownnet" ]; then
+
+#We now check if the network does not need a password
+echo "$selectedAuthScheme"
+if [ $selectedAuthScheme == "[ESS]" ]; then
+ echo "No password needed."
+else
+ if [ -z "$knownnet" ]; then
# network not found among the known ones
# ask for a password:
echo "Enter a password for "$selectedSSID
read password
-else
+ else
# extract the password from the tuple:
tmpTupleFile="$workdir""/tmptpl"
if [ -e "$tmpTupleFile" ]; then
- rm "$tmpTupleFile"
+ rm "$tmpTupleFile"
fi
echo "$knownnet" > "$tmpTupleFile"
IFS=$'\t'
read -r -a TUPLE < "$tmpTupleFile"
password="${TUPLE[1]}"
IFS=
+ fi
fi
-
#sleep 1s
echo "Do you want to connect to ""$selectedSSID"" now? [y/n] "
read answer
if [ $answer = "y" ] || [ $answer = "Y" ]; then
+ if [ $selectedAuthScheme == "[ESS]" ]; then
+ bash "$scriptConnect" ""$selectedSSID""
+ else
bash "$scriptConnect" ""$selectedSSID"" ""$password""
- if [ $? -eq 0 ]; then
- # successfully connected
- # save password for future connections
- source "$knets_add" "$selectedSSID" "$password"
- echo "CONNECTED"
+ fi
+ if [ $? -eq 0 ]; then
+ # successfully connected
+ # save password for future connections
+ if [ $selectedAuthScheme == "[ESS]" ]; then
+ source "$knets_add" "$selectedSSID"
else
- echo "FAILED TO CONNECT"
+ source "$knets_add" "$selectedSSID" "$password"
fi
+ echo "CONNECTED"
+ else
+ echo "FAILED TO CONNECT"
+ fi
fi
diff --git a/networking/wifi/setup.sh b/networking/wifi/setup.sh
index d31acf5..ec6edaf 100644
--- a/networking/wifi/setup.sh
+++ b/networking/wifi/setup.sh
@@ -3,5 +3,5 @@ adb root
sleep 3
adb shell rm -r "$root_dir"
adb shell mkdir "$root_dir"
-adb push ./device-files "$root_dir"
+adb push ./device-files/* "$root_dir"
adb push ./device-files/networks "$root_dir""/networks"