当前位置:   article > 正文

Android 蓝牙模块框架分析_vendor.hid.enable

vendor.hid.enable

Android Bluedroid 框架图


蓝牙组件

Bluetooth core stack library

HCI library

Vendor Specific HCI library

UART, RFKILL,TUN/TAP and UHID device drivers


相关模块

bluetooth.apk :   packages\apps\Bluetooth目录下
libbluetooth_jni:  packages\apps\Bluetooth\jni目录下
libhardware: hardware\libhardware目录下  加载 module.{vendor}.so ,蓝牙模块就是bluetooth.{vendor}.so
bluetooth.default.so: external\bluetooth\bluedroid\main , external\bluetooth\bluedroid 打开各个厂商的动态库libbt-vendor_{vendor}.so, eg:libbt-vendor_rtk.so
                                      依赖libbt-hci.so、libbt-utils.so、libbt-vendor_xxx.so

libbt-vendor_xxx.so:  bluetooth.default.so 或者bluetooth.{vendor}.so会打开该库
audio.a2dp.default.so:高级音频传输库


主体调用流程

(1) BluetoothManagerService == mBluetooth(AdapterService)                                                       ==>
(2) AdapterService  == classInitNative, initNative, enableNative                                                     ==> 
(3) com_android_bluetooth_btservice_AdapterService == hw_get_module // libhardware.so ==> 
    classInitNative:
    1. ro.hardware.bluetooth= vendor 
    2. load(../../bluetooth. vendor.so)
    3. module->methods->open()
    initNative:
    1. sBluetoothInterface->init()   // bluetooth.default.so (external\bluetooth\bluedroid\btif\src\bluetooth.c)
       bt_utils_init , 
       btif_init_bluetooth() //btif_core.c  BTIF  main task prepares BT scheduler for startup
       --->btif_config_init
       --->bte_main_boot_entry
           --->GKI_init()
           --->bte_main_in_hw_init() //Internal helper function for chip hardware init
               ---> bt_hc_get_interface()  // libbt-hci.so 
           --->bte_load_conf()
           --->bte_load_ble_conf()
           --->....
       --->btif_fetch_local_bdaddr
       --->GKI_create_task(btif_task,...,..)
       
    2. sBluetoothInterface->set_os_callouts()
    3. sBluetoothInterface->get_profile_interface(BT_PROFILE_SOCKETS_ID)
    4. sBluetoothInterface->get_profile_interface(BT_PROFILE_MAP_CLIENT_ID)
    5. sBluetoothMceInterface->init()
    enableNative:
    1. enable() // bluetooth.default.so external\bluetooth\bluedroid\btif\src\bluetooth.c
    2. btif_enable_bluetooth()
    3. bte_main_enable()
       --->GKI_create_task(btu_task,...,..)
       --->bte_hci_enable()
           ---->bt_hc_if->init() // bt_hc_if为bt_hc_interface_t类型,也bt_hci_bdroid.c中init
                ---> vendor_open() // 打开libbt-vendor.so 可以配置成各个厂商的库,eg:bcm的libbt-vendor_bcm.so
                --->utils_init()
                --->userial_init()
                --->....

主干流程: Bluetooth.apk  --> libhardware.so  --> bluetooth.{vendor}.so --> libbt-hci.so   --> libbt-vendor_xxx.so  


hardware层移植任务

(1)对应厂商的bluetooth.{vendor}.so库的实现  // 参考bluetooth.default.so
           完成hw_module_t  结构体HAL_MODULE_INFO_SYM的填充,相关结构体hw_module_methods_t,bt_interface_t方法的实现
  1. typedef struct {
  2. /** set to sizeof(bt_interface_t) */
  3. size_t size;
  4. /**
  5. * Opens the interface and provides the callback routines
  6. * to the implemenation of this interface.
  7. */
  8. int (*init)(bt_callbacks_t* callbacks );
  9. /** Enable Bluetooth. */
  10. int (*enable)(void);
  11. /** Disable Bluetooth. */
  12. int (*disable)(void);
  13. /** Closes the interface. */
  14. void (*cleanup)(void);
  15. /** Get all Bluetooth Adapter properties at init */
  16. int (*get_adapter_properties)(void);
  17. /** Get Bluetooth Adapter property of 'type' */
  18. int (*get_adapter_property)(bt_property_type_t type);
  19. /** Set Bluetooth Adapter property of 'type' */
  20. /* Based on the type, val shall be one of
  21. * bt_bdaddr_t or bt_bdname_t or bt_scanmode_t etc
  22. */
  23. int (*set_adapter_property)(const bt_property_t *property);
  24. /** Get all Remote Device properties */
  25. int (*get_remote_device_properties)(bt_bdaddr_t *remote_addr);
  26. /** Get Remote Device property of 'type' */
  27. int (*get_remote_device_property)(bt_bdaddr_t *remote_addr,
  28. bt_property_type_t type);
  29. /** Set Remote Device property of 'type' */
  30. int (*set_remote_device_property)(bt_bdaddr_t *remote_addr,
  31. const bt_property_t *property);
  32. /** Get Remote Device's service record for the given UUID */
  33. int (*get_remote_service_record)(bt_bdaddr_t *remote_addr,
  34. bt_uuid_t *uuid);
  35. /** Start SDP to get remote services */
  36. int (*get_remote_services)(bt_bdaddr_t *remote_addr);
  37. /** Start Discovery */
  38. int (*start_discovery)(void);
  39. /** Cancel Discovery */
  40. int (*cancel_discovery)(void);
  41. /** Create Bluetooth Bonding */
  42. int (*create_bond)(const bt_bdaddr_t *bd_addr, int transport);
  43. /** Remove Bond */
  44. int (*remove_bond)(const bt_bdaddr_t *bd_addr);
  45. /** Cancel Bond */
  46. int (*cancel_bond)(const bt_bdaddr_t *bd_addr);
  47. /**
  48. * Get the connection status for a given remote device.
  49. * return value of 0 means the device is not connected,
  50. * non-zero return status indicates an active connection.
  51. */
  52. int (*get_connection_state)(const bt_bdaddr_t *bd_addr);
  53. /** BT Legacy PinKey Reply */
  54. /** If accept==FALSE, then pin_len and pin_code shall be 0x0 */
  55. int (*pin_reply)(const bt_bdaddr_t *bd_addr, uint8_t accept,
  56. uint8_t pin_len, bt_pin_code_t *pin_code);
  57. /** BT SSP Reply - Just Works, Numeric Comparison and Passkey
  58. * passkey shall be zero for BT_SSP_VARIANT_PASSKEY_COMPARISON &
  59. * BT_SSP_VARIANT_CONSENT
  60. * For BT_SSP_VARIANT_PASSKEY_ENTRY, if accept==FALSE, then passkey
  61. * shall be zero */
  62. int (*ssp_reply)(const bt_bdaddr_t *bd_addr, bt_ssp_variant_t variant,
  63. uint8_t accept, uint32_t passkey);
  64. /** Get Bluetooth profile interface */
  65. const void* (*get_profile_interface) (const char *profile_id);
  66. /** Bluetooth Test Mode APIs - Bluetooth must be enabled for these APIs */
  67. /* Configure DUT Mode - Use this mode to enter/exit DUT mode */
  68. int (*dut_mode_configure)(uint8_t enable);
  69. /* Send any test HCI (vendor-specific) command to the controller. Must be in DUT Mode */
  70. int (*dut_mode_send)(uint16_t opcode, uint8_t *buf, uint8_t len);
  71. /** BLE Test Mode APIs */
  72. /* opcode MUST be one of: LE_Receiver_Test, LE_Transmitter_Test, LE_Test_End */
  73. int (*le_test_mode)(uint16_t opcode, uint8_t *buf, uint8_t len);
  74. /* enable or disable bluetooth HCI snoop log */
  75. int (*config_hci_snoop_log)(uint8_t enable);
  76. /** Sets the OS call-out functions that bluedroid needs for alarms and wake locks.
  77. * This should be called immediately after a successful |init|.
  78. */
  79. int (*set_os_callouts)(bt_os_callouts_t *callouts);
  80. /** Read Energy info details - return value indicates BT_STATUS_SUCCESS or BT_STATUS_NOT_READY
  81. * Success indicates that the VSC command was sent to controller
  82. */
  83. int (*read_energy_info)();
  84. // MStar Android Patch Begin
  85. /** This ensures the chip is Powered ON to support other radios in the combo chip.
  86. * If the chip is OFF it set the chip to ON, if it is already ON it just increases the radio ref count
  87. * to keep track when to Power OFF */
  88. int (*enableRadio)(void);
  89. /** This decreases radio ref count and ensures that chip is Powered OFF
  90. * when the radio ref count becomes zero. */
  91. int (*disableRadio)(void);
  92. /* Send any test HCI (vendor-specific) command */
  93. int (*send_vsc)(uint16_t opcode, uint8_t *buf, uint8_t len);
  94. /**Set secure mode configurations*/
  95. int (*secure_mode_configure)(uint8_t secure_mode, uint8_t scans_disabled,
  96. uint8_t insec_pair_disabled);
  97. /**Force disable bluetooth*/
  98. void (*force_disable) ();
  99. /** Add/remove SDP record */
  100. int (*set_sdp_record)(uint8_t enable, uint16_t uuid);
  101. // MStar Android Patch End
  102. } bt_interface_t;


           详参external\bluetooth\bluedroid\btif\src\bluetooth.c

(2)完成libbt-vendor_{vendor}.so模块的实现 
           主要bt_vendor_interface_t结构体中init,op,cleanup方法的实现           
  1. typedef struct {
  2. /** Set to sizeof(bt_vndor_interface_t) */
  3. size_t size;
  4. /*
  5. * Functions need to be implemented in Vendor libray (libbt-vendor.so).
  6. */
  7. /**
  8. * Caller will open the interface and pass in the callback routines
  9. * to the implemenation of this interface.
  10. */
  11. int (*init)(const bt_vendor_callbacks_t* p_cb, unsigned char *local_bdaddr);
  12. /** Vendor specific operations */
  13. int (*op)(bt_vendor_opcode_t opcode, void *param);
  14. /** Closes the interface */
  15. void (*cleanup)(void);
  16. } bt_vendor_interface_t;

动态加载节点

(1) hardware层 bluetooth.{vendor}.so  加载
           hardware.c文件中可以看到, load 加载的库在/system/lib64/hw,/system/lib/hw,/vendor/lib64/hw,/vendor/lib/hw之中,但是加载的库名称根据
           定义的ro.hardware.bluetooth的值来确定

(2)bluetooth.{vendor}.so加载 libbt-hci.so

(3)libbt-hci.so加载libbt-vendor_xxx.so
          external\bluetooth\bluedroid\hci\src\vendor.c 文件会根据VENDOR_LIBRARY_NAME定义的值来加载动态库,默认是libbt-vendor.so


相关链接:
移植:http://blog.csdn.net/xiaojsj111/article/details/12647923#t2
蓝牙简介:http://blog.chinaunix.net/uid-24227137-id-3359410.html
Hiconfig:http://blog.csdn.net/xubin341719/article/details/38640533


声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/326563
推荐阅读
相关标签
  

闽ICP备14008679号