android bluetooth系统自上而下包含了 驱动程序和协议,Bluez库,Bluetooth的android适配库,java中的bluetooth类等几部分:
1. 内核层:
蓝牙系统的内核部分,有两个层次,分别是蓝牙的驱动程序和蓝牙的协议层。
2. Bluez库:
代码路径:/external/bluetooth/*
生成libbluetooth.so, bluetoothd, 及hcidump等众多工具和库。
I checked the Bluetooth subsystem in our baseline code.
1. I found that maybe we didn't have WL1271 BT driver. There is only a CONFIG_BT_WL1271 in omap3_adlink_android_defconfig.
CONFIG_BT_WL1271 is only used in /drivers/tty/tty_io.c to control the power of BT_EN. Here I corrected the OMAP3_EVEM_BT_PWR_GPIO from 136 to 65.
2. And I have configed BT protocols as follow:
CONFIG_BT=y
CONFIG_BT_L2CAP=y
CONFIG_BT_SCO=y
CONFIG_BT_RFCOMM=y
CONFIG_BT_RFCOMM_TTY=y
CONFIG_BT_BNEP=y
CONFIG_BT_BNEP_MC_FILTER=y
CONFIG_BT_BNEP_PROTO_FILTER=y
CONFIG_BT_HIDP=y
CONFIG_BT_L2CAP=y
CONFIG_BT_SCO=y
CONFIG_BT_RFCOMM=y
CONFIG_BT_RFCOMM_TTY=y
CONFIG_BT_BNEP=y
CONFIG_BT_BNEP_MC_FILTER=y
CONFIG_BT_BNEP_PROTO_FILTER=y
CONFIG_BT_HIDP=y
#
# Bluetooth device drivers
#
# CONFIG_BT_HCIBTUSB is not set
# CONFIG_BT_HCIBTSDIO is not set
CONFIG_BT_HCIUART=y
CONFIG_BT_HCIUART_H4=y
# CONFIG_BT_HCIUART_BCSP is not set
# CONFIG_BT_HCIUART_ATH3K is not set
CONFIG_BT_HCIUART_LL=y
# CONFIG_BT_HCIBCM203X is not set
# CONFIG_BT_HCIBPA10X is not set
# CONFIG_BT_HCIBFUSB is not set
# CONFIG_BT_HCIVHCI is not set
# CONFIG_BT_MRVL is not set
CONFIG_BT_WL1271=y
# CONFIG_AF_RXRPC is not set
# Bluetooth device drivers
#
# CONFIG_BT_HCIBTUSB is not set
# CONFIG_BT_HCIBTSDIO is not set
CONFIG_BT_HCIUART=y
CONFIG_BT_HCIUART_H4=y
# CONFIG_BT_HCIUART_BCSP is not set
# CONFIG_BT_HCIUART_ATH3K is not set
CONFIG_BT_HCIUART_LL=y
# CONFIG_BT_HCIBCM203X is not set
# CONFIG_BT_HCIBPA10X is not set
# CONFIG_BT_HCIBFUSB is not set
# CONFIG_BT_HCIVHCI is not set
# CONFIG_BT_MRVL is not set
CONFIG_BT_WL1271=y
# CONFIG_AF_RXRPC is not set
3. In hardware/ti/wlan/WL1271_COMPAT, it only installed the firmwares and wl1271bt_enable . I think TIInit_7.2.31.bts is the firmware for BT. But I don't know how it loaded. And I don't sure whether it is loaded or not when open bluetooth in Setting.
@# Installing WLAN/BT firmwares and tools to rootfs..
@echo "Installing WLAN/BT firmwares and tools to rootfs.."
@install ../firmwares/TIInit_7.2.31.bts $(DESTDIR)/system/lib/firmware/
@install ../firmwares/ti-connectivity/wl1271-fw-2.bin $(DESTDIR)/system/etc/firmware/ti-connectivity/
@install ../firmwares/ti-connectivity/wl1271-nvs.bin $(DESTDIR)/system/etc/firmware/ti-connectivity/
@install ../tools/wl1271bt_enable $(DESTDIR)/root/
@echo "Installing WLAN/BT firmwares and tools to rootfs.."
@install ../firmwares/TIInit_7.2.31.bts $(DESTDIR)/system/lib/firmware/
@install ../firmwares/ti-connectivity/wl1271-fw-2.bin $(DESTDIR)/system/etc/firmware/ti-connectivity/
@install ../firmwares/ti-connectivity/wl1271-nvs.bin $(DESTDIR)/system/etc/firmware/ti-connectivity/
@install ../tools/wl1271bt_enable $(DESTDIR)/root/
4. In root/init.rc, the services are running well:
service dbus /system/bin/dbus-daemon --system --nofork
socket dbus stream 660 bluetooth bluetooth
user bluetooth
group bluetooth net_bt_admin
socket dbus stream 660 bluetooth bluetooth
user bluetooth
group bluetooth net_bt_admin
service bluetoothd /system/bin/bluetoothd -n
socket bluetooth stream 660 bluetooth bluetooth
socket dbus_bluetooth stream 660 bluetooth bluetooth
socket bluetooth stream 660 bluetooth bluetooth
socket dbus_bluetooth stream 660 bluetooth bluetooth
# init.rc does not yet support applying capabilities, so run as root and
# let bluetoothd drop uid to bluetooth with the right linux capabilities
group bluetooth net_bt_admin misc
disabled
# let bluetoothd drop uid to bluetooth with the right linux capabilities
group bluetooth net_bt_admin misc
disabled
service hfag /system/bin/sdptool add --channel=10 HFAG
user bluetooth
group bluetooth net_bt_admin
disabled
oneshot
user bluetooth
group bluetooth net_bt_admin
disabled
oneshot
service hsag /system/bin/sdptool add --channel=11 HSAG
user bluetooth
group bluetooth net_bt_admin
disabled
oneshot
user bluetooth
group bluetooth net_bt_admin
disabled
oneshot
service opush /system/bin/sdptool add --channel=12 OPUSH
user bluetooth
group bluetooth net_bt_admin
disabled
oneshot
user bluetooth
group bluetooth net_bt_admin
disabled
oneshot
service pbap /system/bin/sdptool add --channel=19 PBAP
user bluetooth
group bluetooth net_bt_admin
disabled
oneshot
user bluetooth
group bluetooth net_bt_admin
disabled
oneshot
# rfkill is not supported, use this instead
service btpwr /wl1271bt_enable /dev/ttyO1 // here it seems using btpwr to replace rfkill.
disabled
oneshot
service btpwr /wl1271bt_enable /dev/ttyO1 // here it seems using btpwr to replace rfkill.
disabled
oneshot
service hciattach /system/bin/hciattach -n /dev/ttyO1 texas 3000000
user root
user root
# changing user to root from bluetooth is a potential security issue
group bluetooth net_bt_admin misc
disabled
oneshot
group bluetooth net_bt_admin misc
disabled
oneshot
5. When I open the bluetooth in Setting, it reports logs as follow:
D/BluetoothService( 1221): Bluetooth state 10 -> 11
V/BluetoothEventRedirector( 1595): Received android.bluetooth.adapter.action.STATE_CHANGED
D/bluedroid( 1221): bt_enable
D/bluedroid( 1221): defined OMAP3EVM_BTPWR
[ 62.133941] Set BT_EN of WL1271
[ 62.137207] WL1271: Powering on
I/bluedroid( 1221): Starting hciattach daemon
E/bluedroid( 1221): bt_enable: Timeout waiting for HCI device to come up
D/BluetoothService( 1221): Bluetooth state 11 -> 10
V/BluetoothEventRedirector( 1595): Received android.bluetooth.adapter.action.STATE_CHANGED
D/dalvikvm( 1459): GC_EXPLICIT freed 495K, 52% free 2783K/5703K, external 716K/1038K, paused 24ms
V/BluetoothEventRedirector( 1595): Received android.bluetooth.adapter.action.STATE_CHANGED
D/bluedroid( 1221): bt_enable
D/bluedroid( 1221): defined OMAP3EVM_BTPWR
[ 62.133941] Set BT_EN of WL1271
[ 62.137207] WL1271: Powering on
I/bluedroid( 1221): Starting hciattach daemon
E/bluedroid( 1221): bt_enable: Timeout waiting for HCI device to come up
D/BluetoothService( 1221): Bluetooth state 11 -> 10
V/BluetoothEventRedirector( 1595): Received android.bluetooth.adapter.action.STATE_CHANGED
D/dalvikvm( 1459): GC_EXPLICIT freed 495K, 52% free 2783K/5703K, external 716K/1038K, paused 24ms