Advertisement
Mister_Magister

/system/etc/init.qcom.bt.sh

May 31st, 2017
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.15 KB | None | 0 0
  1. #!/system/bin/sh
  2. # Copyright (c) 2009-2013, The Linux Foundation. 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 The Linux Foundation 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. #Read the arguments passed to the script
  30. config="$1"
  31.  
  32. BLUETOOTH_SLEEP_PATH=/proc/bluetooth/sleep/proto
  33. LOG_TAG="qcom-bluetooth"
  34. LOG_NAME="${0}:"
  35. /system/bin/log -t $LOG_TAG -p e "$LOG_NAME $config"
  36.  
  37. hciattach_pid=""
  38.  
  39. loge ()
  40. {
  41. /system/bin/log -t $LOG_TAG -p e "$LOG_NAME $@"
  42. }
  43.  
  44. logi ()
  45. {
  46. /system/bin/log -t $LOG_TAG -p i "$LOG_NAME $@"
  47. }
  48.  
  49. failed ()
  50. {
  51. loge "$1: exit code $2"
  52. exit $2
  53. }
  54.  
  55. program_bdaddr ()
  56. {
  57. /system/bin/btnvtool -O
  58. logi "Bluetooth Address programmed successfully"
  59. }
  60.  
  61. #
  62. # enable bluetooth profiles dynamically
  63. #
  64. config_bt ()
  65. {
  66. baseband=`getprop ro.baseband`
  67. target=`getprop ro.board.platform`
  68. if [ -f /sys/devices/soc0/soc_id ]; then
  69. soc_hwid=`cat /sys/devices/soc0/soc_id`
  70. else
  71. soc_hwid=`cat /sys/devices/system/soc/soc0/id`
  72. fi
  73. btsoc=`getprop qcom.bluetooth.soc`
  74.  
  75. case $baseband in
  76. "apq")
  77. setprop ro.qualcomm.bluetooth.opp true
  78. setprop ro.qualcomm.bluetooth.ftp true
  79. setprop ro.qualcomm.bluetooth.nap false
  80. setprop ro.bluetooth.sap false
  81. setprop ro.bluetooth.dun false
  82. # For MPQ as baseband is same for both
  83. case $soc_hwid in
  84. "130")
  85. setprop ro.qualcomm.bluetooth.hsp true
  86. setprop ro.qualcomm.bluetooth.hfp true
  87. setprop ro.qualcomm.bluetooth.pbap false
  88. setprop ro.qualcomm.bluetooth.map false
  89. ;;
  90. *)
  91. setprop ro.qualcomm.bluetooth.hsp false
  92. setprop ro.qualcomm.bluetooth.hfp false
  93. setprop ro.qualcomm.bluetooth.pbap true
  94. setprop ro.qualcomm.bluetooth.map true
  95. ;;
  96. esac
  97. ;;
  98. "mdm" | "svlte2a" | "svlte1" | "csfb")
  99. setprop ro.qualcomm.bluetooth.opp true
  100. setprop ro.qualcomm.bluetooth.hfp true
  101. setprop ro.qualcomm.bluetooth.hsp true
  102. setprop ro.qualcomm.bluetooth.pbap true
  103. setprop ro.qualcomm.bluetooth.ftp true
  104. setprop ro.qualcomm.bluetooth.map true
  105. setprop ro.qualcomm.bluetooth.nap true
  106. setprop ro.bluetooth.sap true
  107. case $target in
  108. "apq8084")
  109. setprop ro.bluetooth.dun true
  110. logi "Enabling BT-DUN for APQ8084"
  111. ;;
  112. *)
  113. setprop ro.bluetooth.dun false
  114. ;;
  115. esac
  116. ;;
  117. "msm")
  118. setprop ro.qualcomm.bluetooth.opp true
  119. setprop ro.qualcomm.bluetooth.hfp true
  120. setprop ro.qualcomm.bluetooth.hsp true
  121. setprop ro.qualcomm.bluetooth.pbap true
  122. setprop ro.qualcomm.bluetooth.ftp true
  123. setprop ro.qualcomm.bluetooth.nap true
  124. setprop ro.bluetooth.sap true
  125. setprop ro.bluetooth.dun true
  126. case $btsoc in
  127. "ath3k")
  128. setprop ro.qualcomm.bluetooth.map false
  129. ;;
  130. *)
  131. setprop ro.qualcomm.bluetooth.map true
  132. ;;
  133. esac
  134. ;;
  135. *)
  136. setprop ro.qualcomm.bluetooth.opp true
  137. setprop ro.qualcomm.bluetooth.hfp true
  138. setprop ro.qualcomm.bluetooth.hsp true
  139. setprop ro.qualcomm.bluetooth.pbap true
  140. setprop ro.qualcomm.bluetooth.ftp true
  141. setprop ro.qualcomm.bluetooth.map true
  142. setprop ro.qualcomm.bluetooth.nap true
  143. setprop ro.bluetooth.sap true
  144. setprop ro.bluetooth.dun true
  145. ;;
  146. esac
  147.  
  148. #Enable Bluetooth Profiles specific to target Dynamically
  149. case $target in
  150. "msm8960")
  151. if [ "$btsoc" != "ath3k" ] && [ "$soc_hwid" != "130" ]
  152. then
  153. setprop ro.bluetooth.hfp.ver 1.6
  154. setprop ro.qualcomm.bt.hci_transport smd
  155. fi
  156. ;;
  157. "msm8974" | "msm8226" | "msm8610" | "msm8916" | "msm8909" )
  158. if [ "$btsoc" != "ath3k" ]
  159. then
  160. setprop ro.bluetooth.hfp.ver 1.6
  161. setprop ro.qualcomm.bt.hci_transport smd
  162. fi
  163. ;;
  164. "apq8084" | "mpq8092" | "msm8994" )
  165. if [ "$btsoc" != "rome" ]
  166. then
  167. setprop ro.qualcomm.bt.hci_transport smd
  168. elif [ "$btsoc" = "rome" ]
  169. then
  170. setprop ro.bluetooth.hfp.ver 1.6
  171. fi
  172. ;;
  173. *)
  174. ;;
  175. esac
  176.  
  177. if [ -f /system/etc/bluetooth/stack.conf ]; then
  178. stack=`cat /system/etc/bluetooth/stack.conf`
  179. fi
  180.  
  181. case "$stack" in
  182. "bluez")
  183. logi "Bluetooth stack is $stack"
  184. setprop ro.qc.bluetooth.stack $stack
  185. reason=`getprop vold.decrypt`
  186. case "$reason" in
  187. "trigger_restart_framework")
  188. start dbus
  189. ;;
  190. esac
  191. ;;
  192. *)
  193. logi "Bluetooth stack is Bluedroid"
  194. ;;
  195. esac
  196.  
  197. }
  198.  
  199. start_hciattach ()
  200. {
  201. /system/bin/hciattach -n $BTS_DEVICE $BTS_TYPE $BTS_BAUD &
  202. hciattach_pid=$!
  203. logi "start_hciattach: pid = $hciattach_pid"
  204. echo 1 > $BLUETOOTH_SLEEP_PATH
  205. }
  206.  
  207. kill_hciattach ()
  208. {
  209. echo 0 > $BLUETOOTH_SLEEP_PATH
  210. logi "kill_hciattach: pid = $hciattach_pid"
  211. ## careful not to kill zero or null!
  212. kill -TERM $hciattach_pid
  213. # this shell doesn't exit now -- wait returns for normal exit
  214. }
  215.  
  216. logi "init.qcom.bt.sh config = $config"
  217. case "$config" in
  218. "onboot")
  219. program_bdaddr
  220. exit 0
  221. ;;
  222. *)
  223. ;;
  224. esac
  225.  
  226. # mimic hciattach options parsing -- maybe a waste of effort
  227. USAGE="hciattach [-n] [-p] [-b] [-t timeout] [-s initial_speed] <tty> <type | id> [speed] [flow|noflow] [bdaddr]"
  228.  
  229. while getopts "blnpt:s:" f
  230. do
  231. case $f in
  232. b | l | n | p) opt_flags="$opt_flags -$f" ;;
  233. t) timeout=$OPTARG;;
  234. s) initial_speed=$OPTARG;;
  235. \?) echo $USAGE; exit 1;;
  236. esac
  237. done
  238. shift $(($OPTIND-1))
  239.  
  240. # Note that "hci_qcomm_init -e" prints expressions to set the shell variables
  241. # BTS_DEVICE, BTS_TYPE, BTS_BAUD, and BTS_ADDRESS.
  242.  
  243. #Selectively Disable sleep
  244. BOARD=`getprop ro.board.platform`
  245. STACK=`getprop ro.qc.bluetooth.stack`
  246.  
  247. # BR/EDR & LE power class configurations
  248. POWER_CLASS=`getprop qcom.bt.dev_power_class`
  249. LE_POWER_CLASS=`getprop qcom.bt.le_dev_pwr_class`
  250.  
  251. #find the transport type
  252. TRANSPORT=`getprop ro.qualcomm.bt.hci_transport`
  253. logi "Transport : $TRANSPORT"
  254. case $STACK in
  255. "bluez")
  256. logi "** Bluez stack **"
  257. ;;
  258. *)
  259. logi "** Bluedroid stack **"
  260. setprop bluetooth.status off
  261. ;;
  262. esac
  263.  
  264.  
  265. case $POWER_CLASS in
  266. 1) PWR_CLASS="-p 0" ;
  267. logi "Power Class: 1";;
  268. 2) PWR_CLASS="-p 1" ;
  269. logi "Power Class: 2";;
  270. 3) PWR_CLASS="-p 2" ;
  271. logi "Power Class: CUSTOM";;
  272. *) PWR_CLASS="";
  273. logi "Power Class: Ignored. Default(1) used (1-CLASS1/2-CLASS2/3-CUSTOM)";
  274. logi "Power Class: To override, Before turning BT ON; setprop qcom.bt.dev_power_class <1 or 2 or 3>";;
  275. esac
  276.  
  277. case $LE_POWER_CLASS in
  278. 1) LE_PWR_CLASS="-P 0" ;
  279. logi "LE Power Class: 1";;
  280. 2) LE_PWR_CLASS="-P 1" ;
  281. logi "LE Power Class: 2";;
  282. 3) LE_PWR_CLASS="-P 2" ;
  283. logi "LE Power Class: CUSTOM";;
  284. *) LE_PWR_CLASS="-P 1";
  285. logi "LE Power Class: Ignored. Default(2) used (1-CLASS1/2-CLASS2/3-CUSTOM)";
  286. logi "LE Power Class: To override, Before turning BT ON; setprop qcom.bt.le_dev_pwr_class <1 or 2 or 3>";;
  287. esac
  288.  
  289. eval $(/system/bin/hci_qcomm_init -e $PWR_CLASS $LE_PWR_CLASS && echo "exit_code_hci_qcomm_init=0" || echo "exit_code_hci_qcomm_init=1")
  290.  
  291. case $exit_code_hci_qcomm_init in
  292. 0) logi "Bluetooth QSoC firmware download succeeded, $BTS_DEVICE $BTS_TYPE $BTS_BAUD $BTS_ADDRESS";;
  293. *) failed "Bluetooth QSoC firmware download failed" $exit_code_hci_qcomm_init;
  294. case $STACK in
  295. "bluez")
  296. logi "** Bluez stack **"
  297. ;;
  298. *)
  299. logi "** Bluedroid stack **"
  300. setprop bluetooth.status off
  301. ;;
  302. esac
  303.  
  304. exit $exit_code_hci_qcomm_init;;
  305. esac
  306.  
  307. # init does SIGTERM on ctl.stop for service
  308. trap "kill_hciattach" TERM INT
  309.  
  310. case $TRANSPORT in
  311. "smd")
  312. case $STACK in
  313. "bluez")
  314. logi "** Bluez stack **"
  315. echo 1 > /sys/module/hci_smd/parameters/hcismd_set
  316. ;;
  317. *)
  318. logi "** Bluedroid stack **"
  319. setprop bluetooth.status on
  320. ;;
  321. esac
  322. ;;
  323. *)
  324. logi "start hciattach"
  325. start_hciattach
  326. case $STACK in
  327. "bluez")
  328. logi "Bluetooth is turning On with Bluez stack "
  329. ;;
  330. *)
  331. logi "** Bluedroid stack **"
  332. setprop bluetooth.status on
  333. ;;
  334. esac
  335.  
  336. wait $hciattach_pid
  337. logi "Bluetooth stopped"
  338. ;;
  339. esac
  340.  
  341. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement