diff options
-rw-r--r-- | setup-interfaces.in | 14 | ||||
-rwxr-xr-x | tests/bin/iwlist | 66 | ||||
-rwxr-xr-x | tests/bin/wpa_passphrase | 9 | ||||
-rwxr-xr-x | tests/setup_interfaces_test | 27 |
4 files changed, 109 insertions, 7 deletions
diff --git a/setup-interfaces.in b/setup-interfaces.in index fe4dac3..5243256 100644 --- a/setup-interfaces.in +++ b/setup-interfaces.in @@ -58,7 +58,7 @@ get_default_addr() { if pidof dhcpcd > /dev/null && [ -f "$ROOT/var/lib/dhcpc/dhcpcd-$1.info" ]; then echo dhcp elif iface_exists $1; then - ip addr show $1 | awk '/inet / {print $2}' | head -n 1 | sed 's:/.*::' + $MOCK ip addr show $1 | awk '/inet / {print $2}' | head -n 1 | sed 's:/.*::' fi } @@ -72,7 +72,7 @@ get_default_mask() { get_default_gateway() { if iface_exists $1; then - ip route show dev $1 | awk '/^default/ {print $3}' + $MOCK ip route show dev $1 | awk '/^default/ {print $3}' fi } @@ -121,7 +121,7 @@ find_essids() { local iface=$1 export essids_list=wlans # Supports only open or PSK - ip link set dev "$iface" up + $MOCK ip link set dev "$iface" up iwlist $iface scanning | awk -F: ' /ESSID/ { gsub(/"/, "", $2); essid=$2 } /Authentication Suites/ { gsub(/^ +/, "", $2); printf "%s/%s\n", essid, $2 } @@ -136,7 +136,8 @@ find_essids() { config_wpa_supp() { local iface="$1" essid="$2" auth_type="$3" psk="$4" - local conffile=/etc/wpa_supplicant/wpa_supplicant.conf + local conffile="$ROOT"/etc/wpa_supplicant/wpa_supplicant.conf + mkdir -p "${conffile%/*}" if [ "$auth_type" = "WPA-PSK" ]; then (umask 0077 && wpa_passphrase "$essid" "$psk" | sed -e '/^\t#psk=.*/d' >> "$conffile") else @@ -147,10 +148,11 @@ network={ } EOF fi - if grep -q ^wpa_supplicant_args= /etc/conf.d/wpa_supplicant; then + mkdir -p "$ROOT/etc/conf.d" + if grep -q ^wpa_supplicant_args= "$ROOT"/etc/conf.d/wpa_supplicant 2>/dev/null; then sed -i -e "s/^wpa_supplicant_args=.*/wpa_supplicant_args=\"-i $iface\"/" /etc/conf.d/wpa_supplicant else - printf 'wpa_supplicant_args="-i%s"\n' "$iface" >> /etc/conf.d/wpa_supplicant + printf 'wpa_supplicant_args="-i%s"\n' "$iface" >> "$ROOT"/etc/conf.d/wpa_supplicant fi rc-update --quiet add wpa_supplicant boot rc-service wpa_supplicant start diff --git a/tests/bin/iwlist b/tests/bin/iwlist new file mode 100755 index 0000000..6b92726 --- /dev/null +++ b/tests/bin/iwlist @@ -0,0 +1,66 @@ +#!/bin/sh + +cat<<EOF +wlan0 Scan completed : + Cell 01 - Address: 98:77:E7:E6:75:2F + Channel:1 + Frequency:2.412 GHz (Channel 1) + Quality=45/70 Signal level=-65 dBm + Encryption key:on + ESSID:"Telenor0366rar" + Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 18 Mb/s + 24 Mb/s; 36 Mb/s; 54 Mb/s + Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 48 Mb/s + Mode:Master + Extra:tsf=00000167602af804 + Extra: Last beacon: 2067ms ago + IE: Unknown: 000E54656C656E6F7230333636726172 + IE: Unknown: 010882848B962430486C + IE: Unknown: 030101 + IE: Unknown: 07064E4F20010D14 + IE: Unknown: 200100 + IE: Unknown: 23021100 + IE: Unknown: 2A0104 + IE: Unknown: 32040C121860 + IE: IEEE 802.11i/WPA2 Version 1 + Group Cipher : CCMP + Pairwise Ciphers (1) : CCMP + Authentication Suites (1) : PSK + IE: Unknown: 0B0501002E0000 + IE: Unknown: 2D1ABC091BFFFF000000000000000000000000000000000000000000 + IE: Unknown: 3D1601080400000000000000000000000000000000000000 + IE: Unknown: 7F080400080000000040 + IE: Unknown: DD840050F204104A0001101044000102103B00010310470010393837374537F536F735323739383737102100044B616F6E10230008444732323030544E10240003312E311042000F3037313230323830343137323933381054000800060050F20400011011000A57694669205275746572100800020006103C0001031049000600372A000120 + IE: Unknown: DD090010180201001C0000 + IE: Unknown: DD180050F2020101000003A4000027A4000042435E0062322F00 + Cell 02 - Address: 98:77:E7:E6:75:30 + Channel:1 + Frequency:2.412 GHz (Channel 1) + Quality=45/70 Signal level=-65 dBm + Encryption key:on + ESSID:"Telenor0366rar-5GHz" + Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 18 Mb/s + 24 Mb/s; 36 Mb/s; 54 Mb/s + Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 48 Mb/s + Mode:Master + Extra:tsf=00000167602b053e + Extra: Last beacon: 2064ms ago + IE: Unknown: 001354656C656E6F72303336367261722D3547487A + IE: Unknown: 010882848B962430486C + IE: Unknown: 030101 + IE: Unknown: 07064E4F20010D14 + IE: Unknown: 200100 + IE: Unknown: 23021100 + IE: Unknown: 2A0104 + IE: Unknown: 32040C121860 + IE: IEEE 802.11i/WPA2 Version 1 + Group Cipher : CCMP + Pairwise Ciphers (1) : CCMP + Authentication Suites (1) : PSK + IE: Unknown: 0B0504002E0000 + IE: Unknown: 2D1ABC091BFFFF000000000000000000000000000000000000000000 + IE: Unknown: 3D1601080400000000000000000000000000000000000000 + IE: Unknown: 7F080400080000000040 + IE: Unknown: DD090010180204001C0000 + IE: Unknown: DD180050F2020101000003A4000027A4000042435E0062322F00 +EOF diff --git a/tests/bin/wpa_passphrase b/tests/bin/wpa_passphrase new file mode 100755 index 0000000..33e3c34 --- /dev/null +++ b/tests/bin/wpa_passphrase @@ -0,0 +1,9 @@ +#!/bin/sh + +cat<<EOF +network={ + ssid="Telenor0366rar" + #psk="0123456789" + psk=87ffb01b74e1ebecab3bf1588668728f2eb78440e3a757460012bb71943c22d9 +} +EOF diff --git a/tests/setup_interfaces_test b/tests/setup_interfaces_test index c189918..e210b26 100755 --- a/tests/setup_interfaces_test +++ b/tests/setup_interfaces_test @@ -8,7 +8,8 @@ init_tests \ setup_interfaces_interactive_vlan_ng \ setup_interfaces_interactive_vlan0_ng \ setup_interfaces_interactive_br0 \ - setup_interfaces_interactive_bond0 + setup_interfaces_interactive_bond0 \ + setup_interfaces_interactive_wlan0 setup_interfaces_usage_body() { test_usage setup-interfaces @@ -152,3 +153,27 @@ setup_interfaces_interactive_bond0_body() { -o match:"apk add.*bonding" \ setup-interfaces <answers } + +setup_interfaces_interactive_wlan0_body() { + init_env + create_fake_ifaces lo eth0 wlan2 + mkdir -p sys/class/net/wlan2/phy80211 + + ( + # Which one do you want to initialize? (or '?' or 'done') [eth0] + echo wlan2 + # Type the wireless network name to connect to: + echo Telenor0366rar + # Type the "Telenor0366rar" network Pre-Shared Key (will not echo): + echo 0123456789 + # Ip address for wlan0? (or 'dhcp', 'none', '?') [dhcp] + echo dhcp + # Do you want to do any manual network configuration? (y/n) [n] + echo n + )>answers + atf_check -s exit:0 \ + -o match:"Available interfaces are: eth0 wlan2" \ + -o match:"Type the \"Telenor0366rar\" network Pre-Shared Key" \ + -o match:"Ip address for wlan2" \ + setup-interfaces <answers +} |