| #!/bin/sh |
| |
| # Time to wait (in seconds) after resetting the BT chip to allow /dev/btusb0 to |
| # be created. |
| BT_RESET_DELAY=1 |
| |
| # Time to wait (in seconds) after starting bsa_server to allow the BT chip to be |
| # fully initialized. |
| BT_BSA_STARTUP_DELAY=2 |
| |
| case "$1" in |
| start) |
| . /etc/utils.sh |
| |
| BT_MAC=$(hnvram -rq MAC_ADDR_BT) |
| BT_NAME=$(cat /etc/platform) |
| |
| # A few platforms are populated with MAC_ADDR, but not MAC_ADDR_BT. |
| if [ -z "$BT_MAC" ]; then |
| MAC=$(hnvram -rq MAC_ADDR) |
| if [ ! -z "$MAC" ]; then |
| BT_MAC=$(echo "$MAC" | ( |
| IFS=: read m1 m2 m3 m4 m5 m6; \ |
| decimal=$(printf "%d" "0x$m6"); \ |
| m6=$(printf "%02x" $(($decimal + 2))); \ |
| echo "$m1:$m2:$m3:$m4:$m5:$m6" |
| )) |
| fi |
| fi |
| |
| # Run the following in a sub-shell in the background to avoid |
| # impacting boot time. |
| ( |
| if [ -e /dev/btusb0 ]; then |
| # BCM20702 USB Bluetooth chip |
| BSATTY=/dev/btusb0 |
| BSAFIRMWARE="-p /etc/bsa/BCM20702.hcd" |
| |
| wl reset_bt_chip 2>&1 |
| sleep $BT_RESET_DELAY |
| elif [ "$(cat /etc/platform)" = GFHD200 ]; then |
| # BCM20705 serial Bluetooth chip |
| BSATTY=/dev/ttyS1 |
| BSAFIRMWARE="-p /etc/bsa/BCM20705.hcd" |
| fi |
| |
| if [ ! -z $BSATTY ]; then |
| # Provide a mechanism for other processes to determine the Bluetooth MAC address |
| echo "$BT_MAC" >/tmp/btmacaddress |
| |
| cd /user/bsa |
| ( |
| LD_PRELOAD=/lib/stdoutline.so babysit 30 \ |
| bsa_server -d $BSATTY $BSAFIRMWARE -hci 2>&1 | logos bsa & |
| ) |
| sleep $BT_BSA_STARTUP_DELAY |
| |
| # Start app_gtv. |
| babysit 30 app_gtv -a "$BT_MAC" -n "$BT_NAME" -k 2>&1 | logos app_gtv & |
| fi |
| |
| ) & |
| ;; |
| stop) |
| pkillwait -x app_gtv |
| pkillwait -x bsa_server |
| ;; |
| restart) |
| $0 stop; $0 start |
| ;; |
| *) |
| echo "Usage: $0 {start|stop|restart}" |
| exit 1 |
| esac |