版权声明:本文为博主原创文章,未经博主允许不得转载。
=========================蓝牙驱动层===========================
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>
bt_wake = port:PA12<1>
bt_host_wake = port:PL06<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");
}
---------------------------------------------------------------------
}