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