1#!/usr/bin/env bash 2 3cd "`dirname $0`" 4 5if [ "shell" = "$1" ] 6then 7 WANTS_SHELL=1 8fi 9 10possibly_enter_shell() { 11 if [ "$WANTS_SHELL" = "1" ] 12 then 13 echo " *** Entering adb shell:" 14 adb shell 15 fi 16} 17 18die () { 19 set +x # Turn off printing commands 20 echo "" 21 echo " *** fatal error: $*" 22 possibly_enter_shell 23 exit 1 24} 25 26if [ -z $ANDROID_BUILD_TOP ]; then 27 echo "You need to source and lunch before you can use this script" 28 exit 1 29fi 30 31adb wait-for-device || die 32 33echo "Running join command test. . ." 34sleep 2 35 36adb shell killall wpantund 2> /dev/null 37 38adb shell wpantund -I wpan5 -s 'system:ot-ncp\ 1' -o Config:Daemon:ExternalNetifManagement 1 & 39WPANTUND_1_PID=$! 40adb shell wpantund -I wpan6 -s 'system:ot-ncp\ 2' -o Config:Daemon:ExternalNetifManagement 1 & 41WPANTUND_2_PID=$! 42trap "kill -HUP $WPANTUND_1_PID $WPANTUND_2_PID 2> /dev/null" EXIT INT TERM 43 44sleep 2 45 46kill -0 $WPANTUND_1_PID || die "wpantund failed to start" 47kill -0 $WPANTUND_2_PID || die "wpantund failed to start" 48 49sleep 2 50 51echo "+ adb shell lowpanctl -I wpan5 status" 52adb shell lowpanctl -I wpan5 status || die 53echo "+ adb shell lowpanctl -I wpan5 form blahnet --panid 1234 --xpanid 0011223344556677 --channel 11" 54adb shell lowpanctl -I wpan5 form blahnet --panid 1234 --xpanid 0011223344556677 --channel 11 || die 55echo "+ adb shell lowpanctl -I wpan5 status" 56adb shell lowpanctl -I wpan5 status || die 57echo "+ adb shell lowpanctl -I wpan5 show-credential" 58adb shell lowpanctl -I wpan5 show-credential || die 59 60CREDENTIAL=`adb shell lowpanctl -I wpan5 show-credential -r` || die 61 62echo "+ adb shell lowpanctl -I wpan6 status" 63adb shell lowpanctl -I wpan6 status || die 64echo "+ adb shell lowpanctl -I wpan6 scan" 65adb shell lowpanctl -I wpan6 scan || die 66echo "+ adb shell lowpanctl -I wpan6 join blahnet --panid 1234 --xpanid 0011223344556677 --channel 11 --master-key ${CREDENTIAL}" 67adb shell lowpanctl -I wpan6 join blahnet --panid 1234 --xpanid 0011223344556677 --channel 11 --master-key ${CREDENTIAL} || die 68 69sleep 2 70 71echo "+ adb shell lowpanctl -I wpan6 status" 72adb shell lowpanctl -I wpan6 status || die 73 74WPAN5_LL_ADDR=`adb shell lowpanctl -I wpan5 status | grep fe80:: | sed -e 's:^[^a-f:0-9]*\([a-f:0-9]*\)/.*:\1:i'` 75WPAN6_LL_ADDR=`adb shell lowpanctl -I wpan6 status | grep fe80:: | sed -e 's:^[^a-f:0-9]*\([a-f:0-9]*\)/.*:\1:i'` 76 77echo "+ ping6 -c 4 -w 6 ${WPAN5_LL_ADDR}%wpan6" 78adb shell ping6 -c 4 -w 6 ${WPAN5_LL_ADDR}%wpan6 || die 79echo "+ ping6 -c 4 -w 6 ${WPAN6_LL_ADDR}%wpan5" 80adb shell ping6 -c 4 -w 6 ${WPAN6_LL_ADDR}%wpan5 || die 81 82possibly_enter_shell 83 84echo "Finished join command test." 85