bluedroid的通用架构框图:
由上图可知,bluedroid包含如下的核心组件:
Bluetooth core stack library
HCI library
Vendor Specific HCI library
UART, RFKILL,TUN/TAP and UHID device drivers
移植过程
基于android上bluedroid上的蓝牙移植涉及到文件有:
bluetooth.apk
bludroid协议栈涉及到的库:
bluetooth.default.so
libbt-hci.so
libbt-utils.so
libbt-vendor.so
audio.a2dp.default.so
android.hardware.bluetooth.xml:该文件用于控制是否显示蓝牙的设置界面,位于/etc/permissions/目录下
bluetooth.default.so依赖于libbt-hci.so、libbt-utils.so、libbt-vendor.so等动态库,该库是蓝牙bluedroid协议栈的核心,该库的核心文件bluetooth.c实现了蓝牙的HAL层。
该硬件抽象层对应的接口定义如下(hardware/include/hardware/bluetooth.h):
/** NOTE: By default, no profiles are initialized at the time of init/enable.
* Whenever the application invokes the 'init' API of a profile, then one of
* the following shall occur:
*
* 1.) If Bluetooth is not enabled, then the Bluetooth core shall mark the
* profile as enabled. Subsequently, when the application invokes the
* Bluetooth 'enable', as part of the enable sequence the profile that were
* marked shall be enabled by calling appropriate stack APIs. The
* 'adapter_properties_cb' shall return the list of UUIDs of the
* enabled profiles.
*
* 2.) If Bluetooth is enabled, then the Bluetooth core shall invoke the stack
* profile API to initialize the profile and trigger a
* 'adapter_properties_cb' with the current list of UUIDs including the
* newly added profile's UUID.
*
* The reverse shall occur whenever the profile 'cleanup' APIs are invoked
*/
/** Represents the standard Bluetooth DM interface. */
typedefstruct{
/** set to sizeof(bt_interface_t) */
size_tsize;
/**
* Opens the interface and provides the callback routines
* to the implemenation of this interface.
*/
int(*init)(bt_callbacks_t* callbacks );
/** Enable Bluetooth. */
int(*enable)(void);
/** Disable Bluetooth. */
int(*disable)(void);
/** This ensures the chip is Powered ON to support other radios in the combo chip.
* If the chip is OFF it set the chip to ON, if it is already ON it just increases the radio ref count
* to keep track when to Power OFF */
int(*enableRadio)(void);
/** This decreases radio ref count and ensures that chip is Powered OFF
* when the radio ref count becomes zero. */
int(*disableRadio)(void);
/** Closes the interface. */
void(*cleanup)(void);
/** Get all Bluetooth Adapter properties at init */
int(*get_adapter_properties)(void);
/** Get Bluetooth Adapter property of 'type' */
int(*get_adapter_property)(bt_property_type_t type);
/** Set Bluetooth Adapter property of 'type' */
/* Based on the type, val shall be one of
* bt_bdaddr_t or bt_bdname_t or bt_scanmode_t etc
*/
int(*set_adapter_property)(constbt_property_t *property);
/** Get all Remote Device properties */
int(*get_remote_device_properties)(bt_bdaddr_t *remote_addr);
/** Get Remote Device property of 'type' */
int(*get_remote_device_property)(bt_bdaddr_t *r