Skip to content

Commit f7eee5a

Browse files
tjobanpuHam22
authored andcommitted
Resolve the race condition between the BT HCI driver and BT init scripts
The BT initialization scripts interrupts the BT driver from enumerating the BT controller ensure the proper sequence is executed, driver loading, BT controller init, Bluetoothd daemon run, BT configuration Signed-off-by: Tushar Jobanputra <[email protected]>
1 parent 0d540be commit f7eee5a

File tree

3 files changed

+87
-12
lines changed

3 files changed

+87
-12
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/bin/sh /etc/rc.common
2+
#
3+
# Copyright (C) 2017 OpenWrt.org
4+
#
5+
# This is free software, licensed under the GNU General Public License v2.
6+
# See /LICENSE for more information.
7+
#
8+
9+
START=85
10+
STOP=85
11+
12+
config_bluetooth() {
13+
. /lib/functions/mac.sh
14+
. /lib/functions/utils.sh
15+
16+
local IS_BT_RUNNING
17+
local timeout=5
18+
local time=$(awk -F "." '{print $1}' /proc/uptime | awk '{print $1}')
19+
local elap_time=0
20+
21+
while [ -z "$IS_BT_RUNNING" ]
22+
do
23+
if [ $elap_time -lt $timeout ]
24+
then
25+
elap_time=$(elapsed_time $time)
26+
else
27+
logger " waiting for bluetoothd daemon: bt-config timed out "
28+
return 1
29+
fi
30+
IS_BT_RUNNING=$(pgrep bluetoothd)
31+
done
32+
# give some time for the bluetoothd to come up before applying
33+
# configuration
34+
sleep 3
35+
local MAC=$(get_bluetooth_mac)
36+
local BT_ADDR_MASK=10
37+
local BT_ADDR=$(echo $MAC | cut -c $BT_ADDR_MASK-)
38+
local BT_NAME=Creator-Ci40["$BT_ADDR"]
39+
hciconfig hci0 reset &&
40+
hciconfig hci0 up &&
41+
hciconfig hci0 piscan &&
42+
hciconfig hci0 version &&
43+
hciconfig hci0 name $BT_NAME || (logger "hciconfig failed" && return 1)
44+
hcitool dev
45+
}
46+
47+
start(){
48+
config_bluetooth
49+
}
50+
51+
stop(){
52+
hciconfig hci0 down
53+
}

target/linux/pistachio/base-files/etc/init.d/bt-csr

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -139,22 +139,28 @@ EOF
139139
}
140140

141141
fi
142-
143-
# Configure HCI and get some version info
144-
BT_ADDR_MASK=10
145-
hciconfig hci0 reset &&\
146-
hciconfig hci0 up &&\
147-
hciconfig hci0 piscan &&\
148-
hciconfig hci0 version &&\
149-
BT_ADDR=$(echo $MAC | cut -c $BT_ADDR_MASK-) &&\
150-
BT_NAME="Creator-Ci40["$BT_ADDR"]" &&\
151-
hciconfig hci0 name $BT_NAME &&\
152-
hcitool dev || (echo "Failed to configure" && exit 1)
153-
154142
}
155143

144+
156145
start() {
146+
. /lib/functions/utils.sh
147+
157148
echo "Starting Bluetooth..."
149+
local timeout=5
150+
local time=$(awk -F "." '{print $1}' /proc/uptime | awk '{print $1}')
151+
local elap_time=0
152+
153+
while ! lsmod | grep -q hci_uart
154+
do
155+
if [ $elap_time -lt $timeout ]
156+
then
157+
elap_time=$(elapsed_time $time)
158+
else
159+
logger " waiting for hci_uart module: bt-csr timed out "
160+
return 1
161+
fi
162+
done
163+
sleep 2
158164
reset_csr && sleep 1 && n_reset_csr && bringup_csr&
159165
}
160166

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/sh
2+
#
3+
# Copyright (C) 2017 OpenWrt.org
4+
#
5+
# This is free software, licensed under the GNU General Public License v2.
6+
# See /LICENSE for more information.
7+
#
8+
9+
10+
elapsed_time() {
11+
local time=$1
12+
current_time=$(awk -F "." '{print $1}' /proc/uptime | awk '{print $1}')
13+
local time_elapsed=0
14+
time_elapsed=$(expr $current_time - $time)
15+
echo "$time_elapsed"
16+
}

0 commit comments

Comments
 (0)