Apply hal macro and modify script
[platform/adaptation/bluetooth-firmware-sprd.git] / scripts / bt-dev-end.sh
1 #!/bin/sh
2 PATH=/bin:/usr/bin:/sbin:/usr/sbin
3
4 #
5 # Script for stopping Broadcom UART Bluetooth stack
6 #
7
8 PGREP="/usr/bin/pgrep"
9
10 # Device down
11 /usr/bin/hciconfig hci0 down
12
13 # Turn off Bluetooth Chip
14 /usr/sbin/rfkill block bluetooth
15
16 #/usr/bin/killall hciattach
17 # Do NOT use killall due to smack
18 hciattach_pid=`${PGREP} hciattach`
19 kill $hciattach_pid
20
21 HCI_CONFIG=/usr/bin/hciconfig
22 TIMEOUT=20
23 for ((i=1; i<=$TIMEOUT; i++))
24 do
25         /bin/sleep 0.1
26         if [ $i -eq $TIMEOUT ]
27         then
28                 echo "time expired happen $i"
29                 exit 2
30         fi
31         if (${HCI_CONFIG} | grep DOWN); then
32                 echo "Bluetooth device is down"
33                 break
34         fi
35         if (${HCI_CONFIG} | grep hci); then
36                 echo "Bluetooth device still exist"
37         else
38                 echo "hci is removed"
39                 break
40         fi
41         echo "Continue...$i"
42 done
43
44 exit 0