From ccb6e97d1742f0627d016ab329ce1cdfb5e3fc4b Mon Sep 17 00:00:00 2001 From: Wolfgang Wiedmeyer Date: Wed, 1 Mar 2017 00:47:19 +0100 Subject: 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. --- networking/wifi/device-files/connect.sh | 42 ++++++++++++++-------- .../wifi/device-files/networks/add_network.sh | 33 +++++++++++------ networking/wifi/device-files/select_network.sh | 39 ++++++++++++++------ networking/wifi/setup.sh | 2 +- 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 +# parse arguments [] +# If no , then assume no authentication if [ $# -eq 0 ]; then - echo "Missing arguments " - exit 1 -fi - -if [ $# -ne 2 ]; then - echo "Wrong argument count!" - exit 1 + echo "Usage: bash connect.sh [] " + 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 []" + 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 -if [ $# -eq 0 ]; then - echo "Missing arguments " - exit 1 -fi -if [ $# -ne 2 ]; then - echo "Wrong argument count!" - exit 1 +# parse arguments [] +# If no , then assume no authentication +if [ $# -eq 0 ]; then + echo "Usage: bash add_network.sh [] " + 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 []" + 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" -- cgit v1.2.3