1. packet中的jni,调用协议栈的过程
a.定义
在./hardware/libhardware/include/hardware/bluetooth.h中
-
#define BT_HARDWARE_MODULE_ID "bluetooth"
-
#define BT_STACK_MODULE_ID "bluetooth"
b.jni中
在./packages/apps/Bluetooth/jni/com_android_bluetooth_btservice_AdapterService.cp中
-
static void classInitNative(JNIEnv* env, jclass clazz) {
-
const char *id = (strcmp(value, "1")? BT_STACK_MODULE_ID : BT_STACK_TEST_MODULE_ID);
-
hw_get_module(id, (hw_module_t const**)&module); //获取动态库libbluedroid.so的入口
-
hw_device_t* abstraction;
-
module->methods->open(module, id, &abstraction); //调用libbluedroid.so的open函数
-
bluetooth_module_t* btStack = (bluetooth_module_t *)abstraction;
-
sBluetoothInterface = btStack->get_bluetooth_interface();
-
}
c. 协议栈中
在./external/bluetooth/bluedroid/btif/src/bluetooth.c中
-
static struct hw_module_methods_t bt_stack_module_methods = {
-
.open = open_bluetooth_stack,
-
};
-
-
struct hw_module_t HAL_MODULE_INFO_SYM = {
-
.tag = HARDWARE_MODULE_TAG,
-
.version_major = 1,
-
.version_minor = 0,
-
.id = BT_HARDWARE_MODULE_ID, //通过这个id找到对应的库
-
.name = "Bluetooth Stack",
-
.author = "The Android Open Source Project",
-
.methods = &bt_stack_module_methods
-
};
c.1 jni调用协议栈的open函数
module
->methods
->open
(module
, id
, &abstraction
); //调用
libbluedroid.so的open函数
-
static int open_bluetooth_stack (const struct hw_module_t* module, char const* name,
-
struct hw_device_t** abstraction)
-
{
-
bluetooth_device_t *stack = malloc(sizeof(bluetooth_device_t) );
-
memset(stack, 0, sizeof(bluetooth_device_t) );
-
stack->common.tag = HARDWARE_DEVICE_TAG;
-
stack->common.version = 0;
-
stack->common.module = (struct hw_module_t*)module;
-
stack->common.close = close_bluetooth_stack;
-
stack->get_bluetooth_interface = bluetooth__get_bluetooth_interface;
-
*abstraction = (struct hw_device_t*)stack;
-
return 0;
-
}
c.2 jni调用协议栈的
get_bluetooth_interface
函数
bluetooth_module_t
* btStack
= (bluetooth_module_t
*)abstraction
;
sBluetoothInterface = btStack->get_bluetooth_interface();
在./external/bluetooth/bluedroid/btif/src/bluetooth.c中
-
const bt_interface_t* bluetooth__get_bluetooth_interface ()
-
{
-
return &bluetoothInterface;
-
}
返回了 Bluetooth DM interface的结构体 这样jni就可以调用蓝牙的打开,关闭,discovery的接口了。
阅读(1152) | 评论(0) | 转发(0) |