Android 4.4 蓝牙解析(一)

2019-04-14 16:54发布

首先我们都知道蓝牙第一步是上电,但是android4.4蓝牙上电部分的代码实际已经和android4.3不一样了。 android4.3蓝牙os是走system/bluetooth,但是android4.4走的是hardware/libhardware和external/bluetooth/,具体请看下面: Bluetooth.h(hardware/libhardware/include/hardware/)----这是结构体,主要是看enable函数。 [cpp] view plaincopy在CODE上查看代码片派生到我的代码片
  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.   
  10.     /** Enable Bluetooth. */  
  11.     int (*"color:#ff0000;">enable)(void);  
  12.   
  13.     /** Disable Bluetooth. */  
  14.     int (*disable)(void);  
  15.   
  16.     /** Closes the interface. */  
  17.     void (*cleanup)(void);  
  18.   
  19.     /** Get all Bluetooth Adapter properties at init */  
  20.     int (*get_adapter_properties)(void);  
  21.   
  22.     /** Get Bluetooth Adapter property of 'type' */  
  23.     int (*get_adapter_property)(bt_property_type_t type);  
  24.   
  25.     /** Set Bluetooth Adapter property of 'type' */  
  26.     /* Based on the type, val shall be one of 
  27.      * bt_bdaddr_t or bt_bdname_t or bt_scanmode_t etc 
  28.      */  
  29.     int (*set_adapter_property)(const bt_property_t *property);  
  30.   
  31.     /** Get all Remote Device properties */  
  32.     int (*get_remote_device_properties)(bt_bdaddr_t *remote_addr);  
  33.   
  34.     /** Get Remote Device property of 'type' */  
  35.     int (*get_remote_device_property)(bt_bdaddr_t *remote_addr,  
  36.                                       bt_property_type_t type);  
  37.   
  38.     /** Set Remote Device property of 'type' */  
  39.     int (*set_remote_device_property)(bt_bdaddr_t *remote_addr,  
  40.                                       const bt_property_t *property);  
  41.   
  42.     /** Get Remote Device's service record  for the given UUID */  
  43.     int (*get_remote_service_record)(bt_bdaddr_t *remote_addr,  
  44.                                      bt_uuid_t *uuid);  
  45.   
  46.     /** Start SDP to get remote services */  
  47.     int (*get_remote_services)(bt_bdaddr_t *remote_addr);  
  48.   
  49.     /** Start Discovery */  
  50.     int (*start_discovery)(void);  
  51.   
  52.     /** Cancel Discovery */  
  53.     int (*cancel_discovery)(void);  
  54.   
  55.     /** Create Bluetooth Bonding */  
  56.     int (*create_bond)(const bt_bdaddr_t *bd_addr);  
  57.   
  58.     /** Remove Bond */  
  59.     int (*remove_bond)(const bt_bdaddr_t *bd_addr);  
  60.   
  61.     /** Cancel Bond */  
  62.     int (*cancel_bond)(const bt_bdaddr_t *bd_addr);  
  63.   
  64.     /** BT Legacy PinKey Reply */  
  65.     /** If accept==FALSE, then pin_len and pin_code shall be 0x0 */  
  66.     int (*pin_reply)(const bt_bdaddr_t *bd_addr, uint8_t accept,  
  67.                      uint8_t pin_len, bt_pin_code_t *pin_code);  
  68.   
  69.     /** BT SSP Reply - Just Works, Numeric Comparison and Passkey 
  70.      * passkey shall be zero for BT_SSP_VARIANT_PASSKEY_COMPARISON & 
  71.      * BT_SSP_VARIANT_CONSENT 
  72.      * For BT_SSP_VARIANT_PASSKEY_ENTRY, if accept==FALSE, then passkey 
  73.      * shall be zero */  
  74.     int (*ssp_reply)(const bt_bdaddr_t *bd_addr, bt_ssp_variant_t variant,  
  75.                      uint8_t accept, uint32_t passkey);  
  76.   
  77.     /** Get Bluetooth profile interface */  
  78.     const void* (*get_profile_interface) (const char *profile_id);  
  79.   
  80.     /** Bluetooth Test Mode APIs - Bluetooth must be enabled for these APIs */  
  81.     /* Configure DUT Mode - Use this mode to enter/exit DUT mode */  
  82.     int (*dut_mode_configure)(uint8_t enable);  
  83.   
  84.     /* Send any test HCI (vendor-specific) command to the controller. Must be in DUT Mode */  
  85.     int (*dut_mode_send)(uint16_t opcode, uint8_t *buf, uint8_t len);  
  86.     /** BLE Test Mode APIs */  
  87.     /* opcode MUST be one of: LE_Receiver_Test, LE_Transmitter_Test, LE_Test_End */  
  88.     int (*le_test_mode)(uint16_t opcode, uint8_t *buf, uint8_t len);  
  89.   
  90.     /* enable or disable bluetooth HCI snoop log */  
  91.     int (*config_hci_snoop_log)(uint8_t enable);  
  92. } bt_interface_t;  
有结构体就会要找结构体对照的函数实现: Bluetooth.c (externalluetoothluedroidtifsrc) [cpp] view plaincopy在CODE上查看代码片派生到我的代码片
  1. const bt_interface_t* bluetooth__get_bluetooth_interface ()  
  2. {  
  3.     /* fixme -- add property to disable bt interface ? */  
  4.   
  5.     return &bluetoothInterface;  
  6. }