start.sh 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. #!/bin/sh
  2. DIR="$( cd "$( dirname "$0" )" && pwd )"
  3. WPAS=$DIR/../../wpa_supplicant/wpa_supplicant
  4. WPACLI=$DIR/../../wpa_supplicant/wpa_cli
  5. HAPD=$DIR/../../hostapd/hostapd
  6. HAPD_AS=$DIR/../../hostapd/hostapd
  7. HAPDCLI=$DIR/../../hostapd/hostapd_cli
  8. WLANTEST=$DIR/../../wlantest/wlantest
  9. HLR_AUC_GW=$DIR/../../hostapd/hlr_auc_gw
  10. DATE="$(date +%s)"
  11. if [ -z "$LOGDIR" ] ; then
  12. LOGDIR="$DIR/logs/$DATE"
  13. mkdir -p $LOGDIR
  14. else
  15. if [ -e $LOGDIR/alt-wpa_supplicant/wpa_supplicant/wpa_supplicant ]; then
  16. WPAS=$LOGDIR/alt-wpa_supplicant/wpa_supplicant/wpa_supplicant
  17. WPACLI=$LOGDIR/alt-wpa_supplicant/wpa_supplicant/wpa_cli
  18. # extra code coverage
  19. $WPAS > /dev/null 2>&1
  20. $WPAS -efoo -Ifoo -mfoo -ofoo -Ofoo -pfoo -Pfoo -h > /dev/null 2>&1
  21. $WPAS -bfoo -B -Cfoo -q -W -N -L > /dev/null 2>&1
  22. $WPAS -T -v > /dev/null 2>&1
  23. $WPAS -u -z > /dev/null 2>&1
  24. fi
  25. if [ -e $LOGDIR/alt-hostapd/hostapd/hostapd ]; then
  26. HAPD=$LOGDIR/alt-hostapd/hostapd/hostapd
  27. HAPDCLI=$LOGDIR/alt-hostapd/hostapd/hostapd_cli
  28. # extra code coverage
  29. $HAPD > /dev/null 2>&1
  30. $HAPD -v > /dev/null 2>&1
  31. $HAPD -B -efoo -Pfoo -T -bfoo -h > /dev/null 2>&1
  32. $HAPD -ufoo > /dev/null 2>&1
  33. $HAPD -u00:11:22:33:44:55 > /dev/null 2>&1
  34. $HAPD -gfoo > /dev/null 2>&1
  35. $HAPD -Gfoo-not-exists > /dev/null 2>&1
  36. $HAPD -z > /dev/null 2>&1
  37. fi
  38. if [ -e $LOGDIR/alt-hostapd-as/hostapd/hostapd ]; then
  39. HAPD_AS=$LOGDIR/alt-hostapd-as/hostapd/hostapd
  40. fi
  41. if [ -e $LOGDIR/alt-hlr_auc_gw/hostapd/hlr_auc_gw ]; then
  42. HLR_AUC_GW=$LOGDIR/alt-hlr_auc_gw/hostapd/hlr_auc_gw
  43. # extra code coverage
  44. $HLR_AUC_GW > /dev/null 2>&1
  45. $HLR_AUC_GW -Dfoo -i7 -sfoo -h > /dev/null 2>&1
  46. $HLR_AUC_GW -i100 > /dev/null 2>&1
  47. $HLR_AUC_GW -z > /dev/null 2>&1
  48. fi
  49. fi
  50. if test -w "$DIR/logs" ; then
  51. rm -rf $DIR/logs/current
  52. ln -sf $DATE $DIR/logs/current
  53. fi
  54. if groups | tr ' ' "\n" | grep -q ^admin$; then
  55. GROUP=admin
  56. else
  57. GROUP=adm
  58. fi
  59. for i in 0 1 2; do
  60. sed "s/ GROUP=.*$/ GROUP=$GROUP/" "$DIR/p2p$i.conf" > "$LOGDIR/p2p$i.conf"
  61. done
  62. sed "s/group=admin/group=$GROUP/" "$DIR/auth_serv/as.conf" > "$LOGDIR/as.conf"
  63. sed "s/group=admin/group=$GROUP/;s%LOGDIR%$LOGDIR%" "$DIR/auth_serv/as2.conf" > "$LOGDIR/as2.conf"
  64. if [ "$1" = "valgrind" ]; then
  65. VALGRIND=y
  66. VALGRIND_WPAS="valgrind --log-file=$LOGDIR/valgrind-wlan%d"
  67. VALGRIND_HAPD="valgrind --log-file=$LOGDIR/valgrind-hostapd"
  68. chmod -f a+rx $WPAS
  69. chmod -f a+rx $HAPD
  70. chmod -f a+rx $HAPD_AS
  71. HAPD_AS="valgrind --log-file=$LOGDIR/valgrind-auth-serv $HAPD_AS"
  72. shift
  73. else
  74. unset VALGRIND
  75. VALGRIND_WPAS=
  76. VALGRIND_HAPD=
  77. fi
  78. if [ "$1" = "trace" ]; then
  79. TRACE="T"
  80. shift
  81. else
  82. TRACE=""
  83. fi
  84. $DIR/stop.sh
  85. TMP=$1
  86. if [ x${TMP%=[0-9]*} = "xchannels" ]; then
  87. NUM_CH=${TMP#channels=}
  88. shift
  89. else
  90. NUM_CH=1
  91. fi
  92. test -f /proc/modules && sudo modprobe mac80211_hwsim radios=6 channels=$NUM_CH support_p2p_device=0
  93. sudo ifconfig hwsim0 up
  94. sudo $WLANTEST -i hwsim0 -n $LOGDIR/hwsim0.pcapng -c -dt -L $LOGDIR/hwsim0 &
  95. for i in 0 1 2; do
  96. DBUSARG=""
  97. if [ $i = "0" -a -r /var/run/dbus/pid -a -r /var/run/dbus/hwsim-test ]; then
  98. if $WPAS | grep -q -- -u; then
  99. DBUSARG="-u"
  100. fi
  101. fi
  102. sudo $(printf -- "$VALGRIND_WPAS" $i) $WPAS -g /tmp/wpas-wlan$i -G$GROUP -Dnl80211 -iwlan$i -c $LOGDIR/p2p$i.conf \
  103. -ddKt$TRACE -f $LOGDIR/log$i $DBUSARG &
  104. done
  105. sudo $(printf -- "$VALGRIND_WPAS" 5) $WPAS -g /tmp/wpas-wlan5 -G$GROUP \
  106. -ddKt$TRACE -f $LOGDIR/log5 &
  107. sudo $VALGRIND_HAPD $HAPD -ddKt$TRACE -g /var/run/hostapd-global -G $GROUP -ddKt -f $LOGDIR/hostapd &
  108. if [ -x $HLR_AUC_GW ]; then
  109. cp $DIR/auth_serv/hlr_auc_gw.milenage_db $LOGDIR/hlr_auc_gw.milenage_db
  110. sudo $HLR_AUC_GW -u -m $LOGDIR/hlr_auc_gw.milenage_db -g $DIR/auth_serv/hlr_auc_gw.gsm > $LOGDIR/hlr_auc_gw &
  111. fi
  112. touch $LOGDIR/hostapd.db
  113. sudo $HAPD_AS -ddKt $LOGDIR/as.conf $LOGDIR/as2.conf > $LOGDIR/auth_serv &
  114. # wait for programs to be fully initialized
  115. for i in 0 1 2 3 4 5 6 7 8 9; do
  116. if [ -e /tmp/wpas-wlan0 ]; then
  117. break
  118. fi
  119. sleep 0.05
  120. done
  121. for i in 0 1 2; do
  122. for j in `seq 1 10`; do
  123. if $WPACLI -g /tmp/wpas-wlan$i ping | grep -q PONG; then
  124. break
  125. fi
  126. if [ $j = "10" ]; then
  127. echo "Could not connect to /tmp/wpas-wlan$i"
  128. exit 1
  129. fi
  130. sleep 1
  131. done
  132. done
  133. for j in `seq 1 10`; do
  134. if $WPACLI -g /var/run/hostapd-global ping | grep -q PONG; then
  135. break
  136. fi
  137. if [ $j = "10" ]; then
  138. echo "Could not connect to /var/run/hostapd-global"
  139. exit 1
  140. fi
  141. sleep 1
  142. done
  143. for j in `seq 1 10`; do
  144. if $HAPDCLI -i as ping | grep -q PONG; then
  145. break
  146. fi
  147. if [ $j = "10" ]; then
  148. echo "Could not connect to hostapd-as-RADIUS-server"
  149. exit 1
  150. fi
  151. sleep 1
  152. done
  153. if [ $USER = "0" -o $USER = "root" ]; then
  154. exit 0
  155. fi
  156. sleep 0.75
  157. sudo chown -f $USER $LOGDIR/hwsim0.pcapng $LOGDIR/hwsim0 $LOGDIR/log* $LOGDIR/hostapd
  158. if [ "x$VALGRIND" = "xy" ]; then
  159. sudo chown -f $USER $LOGDIR/*valgrind*
  160. fi
  161. exit 0