Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2116201
  • 博文数量: 438
  • 博客积分: 3871
  • 博客等级: 中校
  • 技术积分: 6075
  • 用 户 组: 普通用户
  • 注册时间: 2011-09-10 00:11
个人简介

邮箱: wangcong02345@163.com

文章分类

全部博文(438)

文章存档

2017年(15)

2016年(119)

2015年(91)

2014年(62)

2013年(56)

2012年(79)

2011年(16)

分类: Android平台

2014-08-29 17:53:05

1. packet中的jni,调用协议栈的过程
a.定义
在./hardware/libhardware/include/hardware/bluetooth.h中
  1. #define BT_HARDWARE_MODULE_ID "bluetooth"
  2. #define BT_STACK_MODULE_ID "bluetooth"
b.jni中
在./packages/apps/Bluetooth/jni/com_android_bluetooth_btservice_AdapterService.cp中
  1. static void classInitNative(JNIEnv* env, jclass clazz) {
  2.     const char *id = (strcmp(value, "1")? BT_STACK_MODULE_ID : BT_STACK_TEST_MODULE_ID);
  3.     hw_get_module(id, (hw_module_t const**)&module);   //获取动态库libbluedroid.so的入口
  4.     hw_device_t* abstraction;
  5.     module->methods->open(module, id, &abstraction);    //调用libbluedroid.so的open函数
  6.     bluetooth_module_t* btStack = (bluetooth_module_t *)abstraction;
  7.     sBluetoothInterface = btStack->get_bluetooth_interface();
  8. }
c. 协议栈中
在./external/bluetooth/bluedroid/btif/src/bluetooth.c中
  1. static struct hw_module_methods_t bt_stack_module_methods = {
  2.     .open = open_bluetooth_stack,
  3. };

  4. struct hw_module_t HAL_MODULE_INFO_SYM = {
  5.     .tag = HARDWARE_MODULE_TAG,
  6.     .version_major = 1,
  7.     .version_minor = 0,
  8.     .id = BT_HARDWARE_MODULE_ID,    //通过这个id找到对应的库
  9.     .name = "Bluetooth Stack",
  10.     .author = "The Android Open Source Project",
  11.     .methods = &bt_stack_module_methods
  12. };
c.1 jni调用协议栈的open函数
module->methods->open(module, id, &abstraction);    //调用libbluedroid.so的open函数
  1. static int open_bluetooth_stack (const struct hw_module_t* module, char const* name,
  2. struct hw_device_t** abstraction)
  3. {
  4.     bluetooth_device_t *stack = malloc(sizeof(bluetooth_device_t) );
  5.     memset(stack, 0, sizeof(bluetooth_device_t) );
  6.     stack->common.tag = HARDWARE_DEVICE_TAG;
  7.     stack->common.version = 0;
  8.     stack->common.module = (struct hw_module_t*)module;
  9.     stack->common.close = close_bluetooth_stack;
  10.     stack->get_bluetooth_interface = bluetooth__get_bluetooth_interface;
  11.     *abstraction = (struct hw_device_t*)stack;
  12.     return 0;
  13. }
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中
  1. const bt_interface_t* bluetooth__get_bluetooth_interface ()
  2. {
  3.     return &bluetoothInterface;
  4. }
返回了 Bluetooth DM interface的结构体 这样jni就可以调用蓝牙的打开,关闭,discovery的接口了。





阅读(1102) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~