Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.35 KB | None | 0 0
  1. #!/system/bin/sh
  2. # Copyright (c) 2009-2010, Code Aurora Forum. All rights reserved.
  3. #
  4. # Redistribution and use in source and binary forms, with or without
  5. # modification, are permitted provided that the following conditions are met:
  6. #     * Redistributions of source code must retain the above copyright
  7. #       notice, this list of conditions and the following disclaimer.
  8. #     * Redistributions in binary form must reproduce the above copyright
  9. #       notice, this list of conditions and the following disclaimer in the
  10. #       documentation and/or other materials provided with the distribution.
  11. #     * Neither the name of Code Aurora nor
  12. #       the names of its contributors may be used to endorse or promote
  13. #       products derived from this software without specific prior written
  14. #       permission.
  15. #
  16. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  17. # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  18. # IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  19. # NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  20. # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  21. # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  22. # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  23. # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  24. # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  25. # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  26. # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. #
  28.  
  29. BLUETOOTH_SLEEP_PATH=/proc/bluetooth/sleep/proto
  30. LOG_TAG="qcom-bluetooth"
  31. LOG_NAME="${0}:"
  32.  
  33. hciattach_pid=""
  34.  
  35. loge ()
  36. {
  37.   /system/bin/log -t $LOG_TAG -p e "$LOG_NAME $@"
  38. }
  39.  
  40. logi ()
  41. {
  42.   /system/bin/log -t $LOG_TAG -p i "$LOG_NAME $@"
  43. }
  44.  
  45. failed ()
  46. {
  47.   loge "$1: exit code $2"
  48.   exit $2
  49. }
  50.  
  51. start_hciattach ()
  52. {
  53.   echo 1 > $BLUETOOTH_SLEEP_PATH
  54.   /system/bin/hciattach -n $BTS_DEVICE $BTS_TYPE $BTS_BAUD &
  55.   hciattach_pid=$!
  56.   logi "start_hciattach: pid = $hciattach_pid"
  57. }
  58.  
  59. kill_hciattach ()
  60. {
  61.   logi "kill_hciattach: pid = $hciattach_pid"
  62.   ## careful not to kill zero or null!
  63.   kill -TERM $hciattach_pid
  64.   echo 0 > $BLUETOOTH_SLEEP_PATH
  65.   # this shell doesn't exit now -- wait returns for normal exit
  66. }
  67.  
  68. # mimic hciattach options parsing -- maybe a waste of effort
  69. USAGE="hciattach [-n] [-p] [-b] [-t timeout] [-s initial_speed] <tty> <type | id> [speed] [flow|noflow] [bdaddr]"
  70.  
  71. while getopts "blnpt:s:" f
  72. do
  73.   case $f in
  74.   b | l | n | p)  opt_flags="$opt_flags -$f" ;;
  75.   t)      timeout=$OPTARG;;
  76.   s)      initial_speed=$OPTARG;;
  77.   \?)     echo $USAGE; exit 1;;
  78.   esac
  79. done
  80. shift $(($OPTIND-1))
  81.  
  82. # Note that "hci_qcomm_init -e" prints expressions to set the shell variables
  83. # BTS_DEVICE, BTS_TYPE, BTS_BAUD, and BTS_ADDRESS.
  84.  
  85. eval $(/system/bin/hci_qcomm_init -e && echo "exit_code_hci_qcomm_init=0" || echo "exit_code_hci_qcomm_init=1")
  86.  
  87. case $exit_code_hci_qcomm_init in
  88.   0) logi "Bluetooth QSoC firmware download succeeded, $BTS_DEVICE $BTS_TYPE $BTS_BAUD $BTS_ADDRESS";;
  89.   *) failed "Bluetooth QSoC firmware download failed" $exit_code_hci_qcomm_init;;
  90. esac
  91.  
  92. # init does SIGTERM on ctl.stop for service
  93. trap "kill_hciattach" TERM INT
  94.  
  95. start_hciattach
  96.  
  97. wait $hciattach_pid
  98.  
  99. logi "Bluetooth stopped"
  100.  
  101. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement