版權聲明:本文爲博主原創文章,未經博主允許不得轉載。
=========================藍牙驅動層===========================
1、這個是在驅動裏添加的
add device 1: /dev/input/event6
name: "Broadcom Bluetooth HID"
驅動目錄:
調用hidp_sock_ioctl--Sock.c (x:\q2442g_v1.0_d\lichee\linux-3.4\net\bluetooth\hidp) 7080 2015-7-20
hidp_add_connection--------Core.c (x:\q2442g_v1.0_d\lichee\linux-3.4\net\bluetooth\hidp) 30491 2015-7-20
hidp_setup_input---產生evnvt6設備文件
在linux-3.4\net\bluetooth裏面內核封裝對藍牙的協議處理
2、sys_config.fex文件串口配置文件
[bt_para]
bt_used = 1
bt_uart_id = 1
bt_uart_baud = 1500000
bt_rst_n = port:PL01<1><default><default><0>
bt_wake = port:PA12<1><default><default><0>
bt_host_wake = port:PL06<0><default><default><0>
bt_host_wake_invert = 0
這些配置是給Bt_sleep.c (x:\q2442g_v1.0_d\lichee\linux-3.4\drivers\bluetooth) 26423 2015-7-20
驅動文件用的,這個驅動通過在 proc/bluetooth產生文件提供應用程序來讀取配置
baud_rate----串口波特率
sleep----休眠文件夾
uart_id---串口id使用哪個串口
vendor_id---驅動版本號
疑問:
1、藍牙驅動協議層怎把數據安裝藍牙協議封裝好傳送給串口
=======================================藍牙應用層===============================
=============================廠家硬件相關代碼 start==============================
3、串口讀寫操作
Bt_vendor_rtk.c (x:\q2442g_v1.0_d\android\device\softwinner\common\hardware\realtek\bluetooth\rtl8723bs\libbt-vendor\src) 7003 2015-7-20
這些定義通過Bt_sleep.c產生的數據
#define PROC_BLUETOOTH_VENDOR_ID "/proc/bluetooth/vendor_id"
#define PROC_BLUETOOTH_UART_ID_PATH "/proc/bluetooth/uart_id"
#define PROC_BLUETOOTH_BAUD_RATE_PATH "/proc/bluetooth/baud_rate"
通過對封裝串口操作:
const bt_vendor_interface_t BLUETOOTH_VENDOR_LIB_INTERFACE = {
sizeof(bt_vendor_interface_t),
init,---初始化工作--在全志平臺的8723bs模塊上面其實對串口設置--property:persist.service.bdroid.uart設置系統數據、
比如我設置的/dev/ttys1
op,---次函數對藍牙電源開關,設置藍牙讀取廠家給的rtl8723b_fw、rtl8723b_config配置文件
cleanup
};
/a/0ps/q2442g_v1.0_d/android/hardware/broadcom/libbt $ mm -b
產生動態庫 out/target/product/dolphin-fvd-p1/system/vendor/lib/libbt-vendor-rtl.so
重點:
啓動串口服務
service btuartservice /system/bin/btuartservice
class core
user root
group root
disabled
oneshot
判斷property:persist.service.bdroid.uart等於任意值就啓動btuartservice串口服務
on property:persist.service.bdroid.uart=*
start btuartservice
這個服務是在系統init進程裏判斷是否啓動的-------------這裏面還爲研究帶下次研究
4、串口服務
/device/softwinner/common/hardware/btuartservice/btuartservice.c
這裏做的就改串口設備的所屬組、擁有者、權限
把串口權限設置爲 {"chmod", "660"};
{"chown", "bluetooth", "net_bt_stack"};
獲取系統屬性值:
property_get(BT_UART_PROPERTY, pval, NULL) ;--參數1---屬性的名稱,參數2--保存屬性的值
設置系統屬性值:
property_set(BT_UART_PROPERTY, dev);-----參數1---屬性的名稱,參數2--保存屬性的值
=============================廠家硬件相關代碼 end==============================
==============================android系統代碼=================================
5、動態庫加載:
5.1 Bt_hw.c (x:\q2442g_v1.0_d\android\external\bluetooth\bluedroid\hci\src) 7616 2015-7-20
init_vnd_if----------------函數里加載動態庫
dlhandle = dlopen("libbt-vendor-rtl.so", RTLD_NOW);
從動態庫裏找到const bt_vendor_interface_t BLUETOOTH_VENDOR_LIB_INTERFACE 變量位置並且賦值
bt_vnd_if = (bt_vendor_interface_t *) dlsym(dlhandle, "BLUETOOTH_VENDOR_LIB_INTERFACE");
5.2 Bt_hci_bdroid.c (x:\q2442g_v1.0_d\android\external\bluetooth\bluedroid\hci\src) 17902 2015-7-20
static int init(const bt_hc_callbacks_t* p_cb, unsigned char *local_bdaddr)調用 init_vnd_if()函數
static const bt_hc_interface_t bluetoothHCLibInterface = {
sizeof(bt_hc_interface_t),
init,
set_power,
lpm,
preload,
postload,
transmit_buf,
set_rxflow,
logging,
cleanup
};
定義方法獲取bluetoothHCLibInterface結構體
const bt_hc_interface_t *bt_hc_get_interface(void)
{
return &bluetoothHCLibInterface;
}
5.3 Bte_main.c (x:\q2442g_v1.0_d\android\external\bluetooth\bluedroid\main) 24138 2015-7-20
void bte_main_boot_entry(void)
static void bte_main_in_hw_init(void)--調用bt_hc_get_interface方法
5.4 Btif_core.c (x:\q2442g_v1.0_d\android\external\bluetooth\bluedroid\btif\src) 50017 2015-7-20
bt_status_t btif_init_bluetooth()----調用bte_main_boot_entry
5.5 Bluetooth.c (x:\q2442g_v1.0_d\android\external\bluetooth\bluedroid\btif\src) 11906 2015-7-20
static int init(bt_callbacks_t* callbacks )---調用btif_init_bluetooth
static const bt_interface_t bluetoothInterface = {
sizeof(bluetoothInterface),
init,
enable,
disable,
cleanup,
get_adapter_properties,
get_adapter_property,
set_adapter_property,
get_remote_device_properties,
get_remote_device_property,
set_remote_device_property,
get_remote_service_record,
get_remote_services,
start_discovery,
cancel_discovery,
create_bond,
remove_bond,
cancel_bond,
pin_reply,
ssp_reply,
get_profile_interface,
dut_mode_configure,
dut_mode_send,
#if BLE_INCLUDED == TRUE
le_test_mode,
#else
NULL,
#endif
config_hci_snoop_log
};
獲取藍牙結構體bluetoothInterface
const bt_interface_t* bluetooth__get_bluetooth_interface ()
{
/* fixme -- add property to disable bt interface ? */
return &bluetoothInterface;
}
調用open_bluetooth_stack
static struct hw_module_methods_t bt_stack_module_methods = {
.open = open_bluetooth_stack,
};
總之在最後Bluetooth.c 文件最後剩下這個結構體
struct hw_module_t HAL_MODULE_INFO_SYM = {
.tag = HARDWARE_MODULE_TAG,
.version_major = 1,
.version_minor = 0,
.id = BT_HARDWARE_MODULE_ID,
.name = "Bluetooth Stack",
.author = "The Android Open Source Project",
.methods = &bt_stack_module_methods
};
在這個目錄下編譯可以得到bluetooth.default.so動態庫
android/external/bluetooth/bluedroid/btif/src $ mm -b
out/target/product/dolphin-fvd-p1/system/lib/hw/bluetooth.default.so
5.5最終目標在android\packages\apps\bluetooth這個apk通過jni裏調用底層通過 hw_get_module()函數調用 找到
藍牙動態庫bluetooth.default.so
com_android_bluetooth_btservice_AdapterService.cpp (x:\q2442g_v1.0_d\android\packages\apps\bluetooth\jni) 33993 2015-7-20
static void classInitNative(JNIEnv* env, jclass clazz) {
----------------------------------------------------------------
err = hw_get_module(id, (hw_module_t const**)&module);//找到HAL_MODULE_INFO_SYM 定義的藍牙結構體
if (err == 0) {
hw_device_t* abstraction;
err = module->methods->open(module, id, &abstraction);//調用open打開設備
if (err == 0) {
bluetooth_module_t* btStack = (bluetooth_module_t *)abstraction;
sBluetoothInterface = btStack->get_bluetooth_interface();//獲取藍牙接口結構體bt_stack_module_methods
} else {
ALOGE("Error while opening Bluetooth library");
}
} else {
ALOGE("No Bluetooth Library found");
}
---------------------------------------------------------------------
}