xref: /wlan-dirver/utils/sigma-dut/scripts/hs20-action.sh (revision affdb1b8c387503b72afa0d73af0f183236733ef)
1#!/system/bin/sh
2# HotSpot2.0 Release 2 action script - hs20-action.sh
3# Supports the testing of wpa_supplicant and wlan driver
4# support for HotSpot2.0 Release 2 on Android.
5# It assumes that busybox is installed.
6# Copyright (c) 2014, Qualcomm Atheros, Inc.
7# All Rights Reserved.
8# Licensed under the Clear BSD license. See README for more details.
9
10BASEDIR=$(busybox dirname $0)
11date >> $BASEDIR/Logs/hs20-action.log
12echo "$*" >> $BASEDIR/Logs/hs20-action.log
13if [ -e $BASEDIR/summary ]; then
14    echo "$*" >> $BASEDIR/summary
15fi
16IFNAME=$1
17CMD=$2
18
19echo "CMD=$CMD"
20
21echo "CMD=$CMD" >> $BASEDIR/Logs/hs20-action.log
22
23if [ -e /data/vendor/wifi/wpa/sockets/$IFNAME ]; then
24    IFACE_DIR=/data/vendor/wifi/wpa/sockets/
25else
26    IFACE_DIR=/data/misc/wifi/sockets/
27fi
28
29run_eloop_cmd()
30{
31rm -f $BASEDIR/Logs/e_loop.log
32echo "$1" > $BASEDIR/tag_file
33
34# Read back the status of the command issued to e_loop
35
36i=1
37while [ ! -e $BASEDIR/Logs/e_loop.log  ]
38do
39        sleep 1
40        echo "Waiting $i second(s) for result..." >> $BASEDIR/Logs/hs20-action.log
41        if [ "$i" = "30" ] ; then
42        echo "Something went wrong with e_loop, exiting" >> $BASEDIR/Logs/hs20-action.log
43        exit 0
44        fi
45        i=$(($i + 1))
46done
47
48cmd=$(grep "ELOOP_CMD :" $BASEDIR/Logs/e_loop.log)
49status=$(grep "ELOOP_CMD_STATUS :"  $BASEDIR/Logs/e_loop.log)
50echo "Eloop: $cmd ; $status" >> $BASEDIR/Logs/hs20-action.log
51}
52
53# generated cleanup url for system() command
54cleanup_url()
55{
56    sp_str="&"
57    mod_str="\\\\&"
58    URL="${1//$sp_str/$mod_str}"
59}
60
61if [ "$CMD" = "HS20-SUBSCRIPTION-REMEDIATION" ]; then
62    METHOD="$3"
63    cleanup_url "$4"
64    cd $BASEDIR
65    date >> Logs/hs20-osu-client.txt
66    echo "METHOD=$METHOD" >> Logs/hs20-osu-client.txt
67    echo "URL=$URL" >> Logs/hs20-osu-client.txt
68    if [ -e $BASEDIR/SP/wi-fi.org/pps.xml ]; then
69        run_eloop_cmd "nohup hs20-osu-client -w $IFACE_DIR -r hs20-osu-client.res -s summary -dddKt -f Logs/hs20-osu-client.txt sub_rem $URL SP/wi-fi.org/pps.xml SP/wi-fi.org/ca.pem >> Logs/browser.txt 2>&1 &"
70    else
71        if [ "$METHOD" = "0" ]; then
72            run_eloop_cmd "hs20-osu-client -w $IFACE_DIR -r hs20-osu-client.res -s summary -dddKt -f Logs/hs20-osu-client.txt oma_dm_sim_prov $URL osu-ca.pem"
73        else
74            run_eloop_cmd "hs20-osu-client -w $IFACE_DIR -r hs20-osu-client.res -s summary -dddKt -f Logs/hs20-osu-client.txt sim_prov $URL osu-ca.pem"
75        fi
76    fi
77    RES=$?
78    if [ -r hs20-osu-client.res ]; then
79#        notify-send "'cat hs20-osu-client.res'"
80        echo "hs20-osu-client: 'cat hs20-osu-client.res'" >> summary
81    elif [ "$RES" = "0" ]; then
82        echo "hs20-osu-client success" >> summary
83    else
84        echo "hs20-osu-client error" >> summary
85    fi
86    date >> Logs/hs20-osu-client.txt
87fi
88
89if [ "$CMD" = "CONNECTED" ]; then
90    if [ -e $BASEDIR/static-ip ]; then
91	if read ver addr mask gw < $BASEDIR/static-ip; then
92	    echo "ver=$ver addr=$addr mask=$mask gw=$gw" >> $BASEDIR/Logs/hs20-action.log
93	    if [ "$ver" = "6" ]; then
94
95		run_eloop_cmd "busybox sysctl -w net.ipv6.conf.$IFNAME.accept_dad=2 net.ipv6.conf.$IFNAME.dad_transmits=4 net.ipv6.conf.$IFNAME.autoconf=0 net.ipv6.conf.$IFNAME.ndisc_notify=1"
96		run_eloop_cmd "ip -6 addr del $addr/$mask dev $IFNAME"
97		run_eloop_cmd "busybox sysctl -w net.ipv6.conf.$IFNAME.disable_ipv6=0"
98		run_eloop_cmd "ip -6 addr add $addr/$mask dev $IFNAME"
99		sleep 4
100
101		run_eloop_cmd "ip addr show dev $IFNAME"
102		if [[ ! -z $(busybox grep -i $addr $BASEDIR/Logs/e_loop.log | grep -i dadfailed ) ]] ; then
103		    echo "Duplicate IPv6 address $addr found on $IFNAME" >> $BASEDIR/Logs/hs20-action.log
104		    #I need a version of the "notify-send" command that works in Android
105		    #notify-send "Duplicate IPv6 address $addr found on $IFNAME"
106		    exit 0
107		fi
108		if [[ -z $(grep -i $addr $BASEDIR/Logs/e_loop.log) ]] ; then
109		    echo "Could not assign the requested IPv6 address $addr on $IFNAME" >> $BASEDIR/Logs/hs20-action.log
110		    #notify-send "Could not assign the requested IPv6 address $addr on $IFNAME"
111		    exit 0
112		fi
113	    else
114		echo "Cleaning up and Sleeping 4 seconds..." >> $BASEDIR/Logs/hs20-action.log
115		rm -f $BASEDIR/Logs/e_loop.log
116		sleep 4
117		echo "Waking up..." >> $BASEDIR/Logs/hs20-action.log
118		run_eloop_cmd "busybox arping -c 4 -D -I $IFNAME -s 0.0.0.0 $addr"
119		#Search for the string "Unicast reply".  Then you know you have a duplicate IP address...
120		if [[ ! -z $(grep Unicast $BASEDIR/Logs/e_loop.log) ]] ; then
121		    echo "Duplicate IPv4 address $addr found on $IFNAME" >> $BASEDIR/Logs/hs20-action.log
122		    #notify-send "Duplicate IPv4 address $addr found on $IFNAME"
123		    exit 0
124		else
125		    echo "Duplicate IPv4 address $addr NOT found on $IFNAME. Configuring address." >> $BASEDIR/Logs/hs20-action.log
126		fi
127		ifconfig $IFNAME $addr netmask $mask
128		run_eloop_cmd "busybox arping -c 4 -I $IFNAME -s $addr $addr"
129		if [ "$gw" != "N/A" ]; then
130		    route add default gw "$gw"
131		    ip ro re default via "$gw"
132		fi
133	    fi
134	else
135	    echo "Could not parse static-ip" >> $BASEDIR/Logs/hs20-action.log
136	fi
137	exit
138    fi
139
140    run_eloop_cmd "busybox sysctl -w net.ipv6.conf.$IFNAME.disable_ipv6=1 net.ipv6.conf.$IFNAME.autoconf=1 net.ipv6.conf.$IFNAME.accept_ra=1 net.ipv6.conf.$IFNAME.ndisc_notify=1 net.ipv6.conf.$IFNAME.disable_ipv6=0"
141    # Do not run dhcpcd from here as sigma_dut is already starting appropriate
142    # dhcp binary on CTRL-EVENT-CONNECTED.
143fi
144
145if [ "$CMD" = "ESS-DISASSOC-IMMINENT" ]; then
146    cd $BASEDIR
147    PMF="$3"
148    TIME_IN_MS="$4"
149    cleanup_url "$5"
150    count=1
151    if [ "$PMF" = "0" ]; then
152	echo "Disassociation imminent notification received without PMF - ignored" >> summary
153	exit 0
154    fi
155    echo "Disassociation imminent notification received - URL: $URL" >> summary
156    case "$URL" in
157	http*)
158	    while [ $count -le 10 ]
159	    do
160		sleep 1
161		addr=$(busybox ip addr show dev $IFNAME | grep "inet ")
162		if [ -n "$addr" ]; then
163		    if ! busybox pidof hs20-osu-client; then
164			run_eloop_cmd "nohup hs20-osu-client -w $IFACE_DIR -f Logs/hs20-osu-client.txt browser $URL > Logs/browser.txt 2>&1 &"
165		    fi
166		    break
167		else
168		    echo "waiting $count seconds"
169		fi
170		count=$(($count + 1))
171	    done
172	    ;;
173    esac
174#    notify-send "Disassociation imminent"
175fi
176
177if [ "$CMD" = "HS20-DEAUTH-IMMINENT-NOTICE" ]; then
178    cd $BASEDIR
179    CODE="$3"
180    DELAY="$4"
181    cleanup_url "$5"
182    count=1
183    echo "HS 2.0 Deauthentication Imminent notification received - code=$CODE reauth_delay=$DELAY URL: $URL" >> summary
184    case "$URL" in
185	http*)
186	    while [ $count -le 10 ]
187	    do
188		sleep 1
189		addr=$(busybox ip addr show dev $IFNAME | grep "inet ")
190		if [ -n "$addr" ]; then
191		    if ! busybox pidof hs20-osu-client; then
192			run_eloop_cmd "nohup hs20-osu-client -w $IFACE_DIR -f Logs/hs20-osu-client.txt browser $URL > Logs/browser.txt 2>&1 &"
193		    fi
194		    break
195		else
196		    echo "waiting $count seconds"
197		fi
198		count=$(($count + 1))
199	    done
200	    ;;
201    esac
202#    notify-send "HS 2.0 Deauthentication imminent"
203fi
204
205if [ "$CMD" = "HS20-T-C-ACCEPTANCE" ]; then
206    cd $BASEDIR
207    cleanup_url "$3"
208    count=1
209    echo "HS 2.0 Terms and Conditions notification received - URL: $URL" >> summary
210    case "$URL" in
211	http*)
212	    while [ $count -le 10 ]
213	    do
214		sleep 1
215		addr=$(busybox ip addr show dev $IFNAME | grep "inet ")
216		if [ -n "$addr" ]; then
217		    if ! busybox pidof hs20-osu-client; then
218			run_eloop_cmd "nohup hs20-osu-client -w $IFACE_DIR -f Logs/hs20-osu-client.txt browser $URL > Logs/browser.txt 2>&1 &"
219		    fi
220		    break
221		else
222		    echo "waiting $count seconds"
223		fi
224		count=$(($count + 1))
225	    done
226	    ;;
227    esac
228fi
229