summaryrefslogtreecommitdiffstats
path: root/usr/lib
diff options
context:
space:
mode:
authormakefu <github@syntax-fehler.de>2013-06-10 20:30:41 +0200
committermakefu <github@syntax-fehler.de>2013-06-10 20:30:41 +0200
commit20b1c6c2158fb12b6422c170d4a2a0f402864308 (patch)
treed31541c882bdb63624466877d3edc2db641c55a1 /usr/lib
parent910446fb3b32314f9a1efbab5d948d76021a8c7c (diff)
finish refactoring new wpa_supplicant autowifi
Diffstat (limited to 'usr/lib')
-rw-r--r--usr/lib/autowifi/lib/core20
-rw-r--r--usr/lib/autowifi/lib/network21
-rw-r--r--usr/lib/autowifi/lib/plugin_core4
-rw-r--r--usr/lib/autowifi/lib/wpa_supplicant56
-rw-r--r--usr/lib/autowifi/lib/wps19
-rwxr-xr-xusr/lib/autowifi/plugins/00profile2
-rwxr-xr-xusr/lib/autowifi/plugins/01open4
-rwxr-xr-xusr/lib/autowifi/plugins/30default_wps13
8 files changed, 125 insertions, 14 deletions
diff --git a/usr/lib/autowifi/lib/core b/usr/lib/autowifi/lib/core
new file mode 100644
index 00000000..80ae75b4
--- /dev/null
+++ b/usr/lib/autowifi/lib/core
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+exists() { type "$1" >/dev/null 2>/dev/null; }
+
+run_hooks(){
+ # (interface|profile) (pre|post)
+ typ=$1
+ action=$2
+ shift;shift
+ : ${interface?please provide interface}
+ if [ "$typ" = "interface" ];then
+ path=interface/$interface/$action
+ else
+ path=profile/$2/$action
+ fi
+ for hook in $(find "$root/etc/autowifi/hooks/$path" -type f 2>/dev/null | sort -u ); do
+ $hook "$@"
+ done
+}
+
diff --git a/usr/lib/autowifi/lib/network b/usr/lib/autowifi/lib/network
index 1b105f85..fd7e3b5a 100644
--- a/usr/lib/autowifi/lib/network
+++ b/usr/lib/autowifi/lib/network
@@ -1,4 +1,5 @@
#!/bin/sh
+
check_gateway(){
ping -c 1 -w 5 $(ip route | awk '/default/{print $3}')
}
@@ -10,3 +11,23 @@ check_internet(){
return 1
fi
}
+
+check_bandwidth(){
+ echo $(curl ftp://ftp.microsoft.com/Products/mspress/library/ANIMAT.ZIP -w "%{speed_download}" -o /dev/null 2>/dev/null | sed 's/\..*//')
+}
+
+ip_start(){
+ : ${interface?interface variable not set} ${1?please provide method to start ip}
+ # usage: method [extra parms]
+ case "$1" in
+ dhcp)
+ if exists dhcpcd; then
+ dhcpcd -x $interface
+ dhcpcd -w -A $interface
+ elif exists dhclient; then
+ dhclient -x $interface
+ dhclient $interface
+ fi ;;
+ *) echo "do not know ip starter $1";;
+ esac
+}
diff --git a/usr/lib/autowifi/lib/plugin_core b/usr/lib/autowifi/lib/plugin_core
index 025d9dbd..da003350 100644
--- a/usr/lib/autowifi/lib/plugin_core
+++ b/usr/lib/autowifi/lib/plugin_core
@@ -1,12 +1,10 @@
parse_plugin_args(){
- [ $# -ne 6 ] && plugin_usage && exit 1
+ [ $# -ne 4 ] && plugin_usage && exit 1
# convenience function to put args in ENV variables
ESSID="$1"
MAC="$2"
CHANNEL="$3"
ENC="$4"
- WPA="$5"
- WPA2="$6"
if [ ${#MAC} -ne 17 ] ;then
echo "MAC malformed"
exit 1
diff --git a/usr/lib/autowifi/lib/wpa_supplicant b/usr/lib/autowifi/lib/wpa_supplicant
new file mode 100644
index 00000000..28c327e9
--- /dev/null
+++ b/usr/lib/autowifi/lib/wpa_supplicant
@@ -0,0 +1,56 @@
+#!/bin/sh
+start_wpa_supplicant(){
+ wpa_conf=${1?please supply wpa_supplicant.conf path}
+ killall wpa_supplicant
+ sleep 1
+cat>$wpa_conf<<EOF
+ctrl_interface=/var/run/wpa_supplicant
+EOF
+ wpa_supplicant -i wlan0 -c $wpa_conf -B
+ sleep 4
+}
+connect_wifi(){
+ # bssid ssid encryption-string key
+
+ wpa_cli reconfigure
+
+ int=$(wpa_cli add_network | tail -1)
+ wpa_cli set_network $int ssid \"$2\"
+ wpa_cli set_network $int bssid $1
+ #wpa_cli set_network $int ap_scan 1
+
+ if [ "$3" = "[ESS]" ]; then
+ wpa_cli set_network $int key_mgmt NONE
+ else
+ wpa_cli set_network $int key_mgmt WPA-PSK
+ wpa_cli set_network $int psk \"$4\"
+ fi
+ wpa_cli enable_network $int
+}
+
+wifi_scan(){
+ # usage: iwlist_scan $wifi-itf
+
+ count=0
+ wpa_cli scan >/dev/null
+ sleep 10
+
+ wpa_cli scan_results 2>/dev/null | grep -E "^??:" | sed 's/ / /g' | (while IFS=' ' read MAC FREQ QUALITY ENCRYPTION ESSID
+ do
+ : $((count+=1))
+ print_wifi_env
+
+ done; echo WIFI_COUNT=$count)
+}
+
+print_wifi_env(){
+ # takes environment:
+ # MAC
+ # FREQ
+ # QUALITY
+ # ENCRYPTION
+ # ESSID
+ for i in MAC FREQ QUALITY ENCRYPTION ESSID;do
+ eval echo ${i}_${count}=\\\"\$"${i}"\\\"
+ done
+}
diff --git a/usr/lib/autowifi/lib/wps b/usr/lib/autowifi/lib/wps
index 668bbbff..9fa01801 100644
--- a/usr/lib/autowifi/lib/wps
+++ b/usr/lib/autowifi/lib/wps
@@ -1,5 +1,8 @@
#!/bin/sh
-
+has_wps(){
+ # the-wpa_supplicant-encryption-string
+ echo "$1" | grep -q "\[WPS\]"
+}
try_wps_pin(){
#
# ESSID MAC CHANNEL ENC WPA WPA2 PIN
@@ -7,14 +10,16 @@ try_wps_pin(){
ESSID="$1"
MAC="$2"
CHANNEL="$3"
+
+ # TODO refactor to use all the encryption
+ # the wpa_supplicant encryption string
ENC="$4"
- WPA="$5"
- WPA2="$6"
- PIN="$7"
- [ "$ENC" == off ] && return 2
- WPA_CONF=/tmp/wpa.conf
- WPA_LOG=/tmp/wpa.log
+ PIN="$5"
+
+ [ "$ENC" = "[ESS]" ] && return 2
+ WPA_CONF=/tmp/wpa_trywps.conf
+ WPA_LOG=/tmp/wpa_trywps.log
rm $WPA_LOG
#mkfifo $WPA_LOG
killall wpa_supplicant 2>/dev/null && sleep 1
diff --git a/usr/lib/autowifi/plugins/00profile b/usr/lib/autowifi/plugins/00profile
index fdba2c9e..d7fb9c75 100755
--- a/usr/lib/autowifi/plugins/00profile
+++ b/usr/lib/autowifi/plugins/00profile
@@ -3,7 +3,7 @@
# ENV:
# root (default: /)
root=${root:-/}
-cat $root/etc/autowifi/wifi_keys 2>/dev/null | (while IFS='|' read SSID MAC KEY; do
+cat $root/etc/autowifi/wifi_keys 2>/dev/null | (while IFS='|' read SSID MAC BANDWIDTH KEY; do
if [ "$1" == "$SSID" -a "$2" == "$MAC" ]; then
echo $KEY
exit 0
diff --git a/usr/lib/autowifi/plugins/01open b/usr/lib/autowifi/plugins/01open
index f3b9640c..881f47ea 100755
--- a/usr/lib/autowifi/plugins/01open
+++ b/usr/lib/autowifi/plugins/01open
@@ -1,6 +1,6 @@
#!/bin/sh
-#ESSID MAC CHANNEL ENCRYPTION WPA WPA2
-if [ "$4" == "off" ]; then
+#ESSID MAC CHANNEL ENCRYPTION
+if [ "$4" == "[ESS]" ]; then
exit 0
fi
exit 1
diff --git a/usr/lib/autowifi/plugins/30default_wps b/usr/lib/autowifi/plugins/30default_wps
index 98be6a66..7f66d117 100755
--- a/usr/lib/autowifi/plugins/30default_wps
+++ b/usr/lib/autowifi/plugins/30default_wps
@@ -3,4 +3,15 @@
# http://www.wotan.cc/?p=75
cd $(dirname $(readlink -f $0))
. ../lib/wps
-try_wps_pin "$@" 12345670
+. ../lib/plugin_core
+
+parse_plugin_args "$@"
+DEFAULT_PIN="${DEFAULT_PIN:-12345670}"
+
+if has_wps "$ENC"; then
+ echo "trying PIN $DEFAULT_PIN against $ESSID" >&2
+ try_wps_pin "$@" $DEFAULT_PIN
+else
+ echo "Network $ESSID not WPS enabled" >&2
+ exit 1
+fi