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