当前位置:   article > 正文

Android 源码分析 - 蓝牙 - HAL层_蓝牙 class hal

蓝牙 class hal

        Bluetooth模块接口定义在hardware/libhardware/include/hardware/bluetooth.h中。模块ID为“bluetooth”或者“bluetooth_test”。

接口定义

bluetooth.h

  1. bt_callbacks_t:

hardware/libhardware/include/hardware/bluetooth.h:

-------------------------------------------------------------------------

typedef struct {

    /** set to sizeof(bt_callbacks_t) */

    size_t size;

    adapter_state_changed_callback adapter_state_changed_cb;

    adapter_properties_callback adapter_properties_cb;

    remote_device_properties_callback remote_device_properties_cb;

    device_found_callback device_found_cb;

    discovery_state_changed_callback discovery_state_changed_cb;

    pin_request_callback pin_request_cb;

    ssp_request_callback ssp_request_cb;

    bond_state_changed_callback bond_state_changed_cb;

    acl_state_changed_callback acl_state_changed_cb;

    callback_thread_event thread_evt_cb;

    dut_mode_recv_callback dut_mode_recv_cb;

    le_test_mode_callback le_test_mode_cb;

} bt_callbacks_t;

  1. bt_interface_t

hardware/libhardware/include/hardware/bluetooth.h:

-------------------------------------------------------------------------

typedef struct {

    size_t size;

    int (*init)(bt_callbacks_t* callbacks );

    int (*enable)(void);

    int (*disable)(void);

    void (*cleanup)(void);

    int (*get_adapter_properties)(void);

    int (*get_adapter_property)(bt_property_type_t type);

    int (*set_adapter_property)(const bt_property_t *property);

    int (*get_remote_device_properties)(bt_bdaddr_t *remote_addr);

    int (*get_remote_device_property)(bt_bdaddr_t *remote_addr,

                                      bt_property_type_t type);

    int (*set_remote_device_property)(bt_bdaddr_t *remote_addr,

                                      const bt_property_t *property);

    int (*get_remote_service_record)(bt_bdaddr_t *remote_addr,

                                     bt_uuid_t *uuid);

    int (*get_remote_services)(bt_bdaddr_t *remote_addr);

    int (*start_discovery)(void);

    int (*cancel_discovery)(void);

    int (*create_bond)(const bt_bdaddr_t *bd_addr);

    int (*remove_bond)(const bt_bdaddr_t *bd_addr);

    int (*cancel_bond)(const bt_bdaddr_t *bd_addr);

    int (*pin_reply)(const bt_bdaddr_t *bd_addr, uint8_t accept,

                     uint8_t pin_len, bt_pin_code_t *pin_code);

    int (*ssp_reply)(const bt_bdaddr_t *bd_addr, bt_ssp_variant_t variant,

                     uint8_t accept, uint32_t passkey);

    const void* (*get_profile_interface) (const char *profile_id);

    int (*dut_mode_configure)(uint8_t enable);

    int (*dut_mode_send)(uint16_t opcode, uint8_t *buf, uint8_t len);

 

    int (*le_test_mode)(uint16_t opcode, uint8_t *buf, uint8_t len);

    int (*config_hci_snoop_log)(uint8_t enable);

} bt_interface_t;

  1. bluetooth_device_t

hardware/libhardware/include/hardware/bluetooth.h:

-------------------------------------------------------------------------

typedef struct {

    struct hw_device_t common;

    const bt_interface_t* (*get_bluetooth_interface)();

} bluetooth_device_t;

bt_av.h

  1. btav_callbacks_t

hardware/libhardware/include/hardware/bt_av.h:

-------------------------------------------------------------------------

typedef struct {

    /** set to sizeof(btav_callbacks_t) */

    size_t      size;

    btav_connection_state_callback  connection_state_cb;

    btav_audio_state_callback audio_state_cb;

} btav_callbacks_t;

  1. btav_interface_t

hardware/libhardware/include/hardware/bt_av.h:

-------------------------------------------------------------------------

typedef struct {

    size_t          size;

    bt_status_t (*init)( btav_callbacks_t* callbacks );

    bt_status_t (*connect)( bt_bdaddr_t *bd_addr );

    bt_status_t (*disconnect)( bt_bdaddr_t *bd_addr );

    void  (*cleanup)( void );

} btav_interface_t;

bt_gatt.h

  1. btgatt_callbacks_t

hardware/libhardware/include/hardware/bt_gatt.h:

-------------------------------------------------------------------------

typedef struct {

    size_t size;

    const btgatt_client_callbacks_t* client;

    const btgatt_server_callbacks_t* server;

} btgatt_callbacks_t;

  1. btgatt_interface_t

hardware/libhardware/include/hardware/bt_gatt.h:

-------------------------------------------------------------------------

typedef struct {

    size_t          size;

    bt_status_t (*init)( const btgatt_callbacks_t* callbacks );

    void (*cleanup)( void );

    const btgatt_client_interface_t* client;

    const btgatt_server_interface_t* server;

} btgatt_interface_t;

  1. btgatt_client_callbacks_t

hardware/libhardware/include/hardware/bt_gatt_client.h:

-------------------------------------------------------------------------

typedef struct {

    register_client_callback            register_client_cb;

    scan_result_callback                scan_result_cb;

    connect_callback                    open_cb;

    disconnect_callback                 close_cb;

    search_complete_callback            search_complete_cb;

    search_result_callback              search_result_cb;

    get_characteristic_callback         get_characteristic_cb;

    get_descriptor_callback             get_descriptor_cb;

    get_included_service_callback       get_included_service_cb;

    register_for_notification_callback  register_for_notification_cb;

    notify_callback                     notify_cb;

    read_characteristic_callback        read_characteristic_cb;

    write_characteristic_callback       write_characteristic_cb;

    read_descriptor_callback            read_descriptor_cb;

    write_descriptor_callback           write_descriptor_cb;

    execute_write_callback              execute_write_cb;

    read_remote_rssi_callback           read_remote_rssi_cb;

    listen_callback                     listen_cb;

} btgatt_client_callbacks_t;

  1. btgatt_interface_client_t

hardware/libhardware/include/hardware/bt_gatt_client.h:

-------------------------------------------------------------------------

typedef struct {

    bt_status_t (*register_client)( bt_uuid_t *uuid );

    bt_status_t (*unregister_client)(int client_if );

    bt_status_t (*scan)( int client_if, bool start );

    bt_status_t (*connect)( int client_if, const bt_bdaddr_t *bd_addr,

                         bool is_direct );

    bt_status_t (*disconnect)( int client_if, const bt_bdaddr_t *bd_addr,

                    int conn_id);

    bt_status_t (*listen)(int client_if, bool start);

    bt_status_t (*refresh)( int client_if, const bt_bdaddr_t *bd_addr );

    bt_status_t (*search_service)(int conn_id, bt_uuid_t *filter_uuid );

    bt_status_t (*get_included_service)( int conn_id, btgatt_srvc_id_t *srvc_id,

                                         btgatt_srvc_id_t *start_incl_srvc_id);

    bt_status_t (*get_characteristic)( int conn_id,

                    btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *start_char_id);

    bt_status_t (*get_descriptor)( int conn_id,

                    btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id,

                    btgatt_gatt_id_t *start_descr_id);

    bt_status_t (*read_characteristic)( int conn_id,

                    btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id,

                    int auth_req );

    bt_status_t (*write_characteristic)(int conn_id,

                    btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id,

                    int write_type, int len, int auth_req,

                    char* p_value);

    bt_status_t (*read_descriptor)(int conn_id,

                    btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id,

                    btgatt_gatt_id_t *descr_id, int auth_req);

    bt_status_t (*write_descriptor)( int conn_id,

                    btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id,

                    btgatt_gatt_id_t *descr_id, int write_type, int len,

                    int auth_req, char* p_value);

    bt_status_t (*execute_write)(int conn_id, int execute);

hardware/libhardware/include/hardware/bt_gatt_client.h:

-------------------------------------------------------------------------

    bt_status_t (*register_for_notification)( int client_if,

                    const bt_bdaddr_t *bd_addr, btgatt_srvc_id_t *srvc_id,

                    btgatt_gatt_id_t *char_id);

    bt_status_t (*deregister_for_notification)( int client_if,

                    const bt_bdaddr_t *bd_addr, btgatt_srvc_id_t *srvc_id,

                    btgatt_gatt_id_t *char_id);

    bt_status_t (*read_remote_rssi)( int client_if,

                    const bt_bdaddr_t *bd_addr);

    int (*get_device_type)( const bt_bdaddr_t *bd_addr );

    bt_status_t (*set_adv_data)(int server_if, bool set_scan_rsp,

                    bool include_name, bool include_txpower,

                    int min_interval, int max_interval, int appearance,

                    uint16_t manufacturer_len, char* manufacturer_data);

    bt_status_t (*test_command)( int command,

                    btgatt_test_params_t* params);

} btgatt_client_interface_t;

  1. btgatt_server_callbacks_t

hardware/libhardware/include/hardware/bt_gatt_server.h:

-------------------------------------------------------------------------

typedef struct {

    register_server_callback        register_server_cb;

    connection_callback             connection_cb;

    service_added_callback          service_added_cb;

    included_service_added_callback included_service_added_cb;

    characteristic_added_callback   characteristic_added_cb;

    descriptor_added_callback       descriptor_added_cb;

    service_started_callback        service_started_cb;

    service_stopped_callback        service_stopped_cb;

    service_deleted_callback        service_deleted_cb;

    request_read_callback           request_read_cb;

    request_write_callback          request_write_cb;

    request_exec_write_callback     request_exec_write_cb;

    response_confirmation_callback  response_confirmation_cb;

} btgatt_server_callbacks_t;

  1. btgatt_server_interface_t

hardware/libhardware/include/hardware/bt_gatt_server.h:

-------------------------------------------------------------------------

typedef struct {

    bt_status_t (*register_server)( bt_uuid_t *uuid );

    bt_status_t (*unregister_server)(int server_if );

    bt_status_t (*connect)(int server_if, const bt_bdaddr_t *bd_addr,

                                  bool is_direct );

    bt_status_t (*disconnect)(int server_if, const bt_bdaddr_t *bd_addr,

                    int conn_id );

    bt_status_t (*add_service)( int server_if, btgatt_srvc_id_t *srvc_id,

                                  int num_handles);

    bt_status_t (*add_included_service)( int server_if, int service_handle,

                                  int included_handle);

    bt_status_t (*add_characteristic)( int server_if,

                    int service_handle, bt_uuid_t *uuid,

                    int properties, int permissions);

    bt_status_t (*add_descriptor)(int server_if, int service_handle,

                                  bt_uuid_t *uuid, int permissions);

    bt_status_t (*start_service)(int server_if, int service_handle,

                                 int transport);

    bt_status_t (*stop_service)(int server_if, int service_handle);

    bt_status_t (*delete_service)(int server_if, int service_handle);

    bt_status_t (*send_indication)(int server_if, int attribute_handle,

                                   int conn_id, int len, int confirm,

                                   char* p_value);

    bt_status_t (*send_response)(int conn_id, int trans_id,

                                 int status, btgatt_response_t *response);

} btgatt_server_interface_t;

bt_hf.h

  1. bthf_callbacks_t

hardware/libhardware/include/hardware/bt_hf.h:

-------------------------------------------------------------------------

typedef struct {

    size_t      size;

    bthf_connection_state_callback  connection_state_cb;

    bthf_audio_state_callback       audio_state_cb;

    bthf_vr_cmd_callback            vr_cmd_cb;

    bthf_answer_call_cmd_callback   answer_call_cmd_cb;

    bthf_hangup_call_cmd_callback   hangup_call_cmd_cb;

    bthf_volume_cmd_callback        volume_cmd_cb;

    bthf_dial_call_cmd_callback     dial_call_cmd_cb;

    bthf_dtmf_cmd_callback          dtmf_cmd_cb;

    bthf_nrec_cmd_callback          nrec_cmd_cb;

    bthf_chld_cmd_callback          chld_cmd_cb;

    bthf_cnum_cmd_callback          cnum_cmd_cb;

    bthf_cind_cmd_callback          cind_cmd_cb;

    bthf_cops_cmd_callback          cops_cmd_cb;

    bthf_clcc_cmd_callback          clcc_cmd_cb;

    bthf_unknown_at_cmd_callback    unknown_at_cmd_cb;

    bthf_key_pressed_cmd_callback   key_pressed_cmd_cb;

} bthf_callbacks_t;

  1. bthf_interface_t

hardware/libhardware/include/hardware/bt_hf.h:

-------------------------------------------------------------------------

typedef struct {

    size_t          size;

    bt_status_t (*init)( bthf_callbacks_t* callbacks );

    bt_status_t (*connect)( bt_bdaddr_t *bd_addr );

    bt_status_t (*disconnect)( bt_bdaddr_t *bd_addr );

    bt_status_t (*connect_audio)( bt_bdaddr_t *bd_addr );

    bt_status_t (*disconnect_audio)( bt_bdaddr_t *bd_addr );

    bt_status_t (*start_voice_recognition)();

    bt_status_t (*stop_voice_recognition)();

    bt_status_t (*volume_control) (bthf_volume_type_t type, int volume);

    bt_status_t (*device_status_notification)(

                           bthf_network_state_t ntk_state,

                           bthf_service_type_t svc_type, int signal,

                           int batt_chg);

    bt_status_t (*cops_response)(const char *cops);

    bt_status_t (*cind_response)(int svc, int num_active, int num_held,

                                 bthf_call_state_t call_setup_state,

                                 int signal, int roam, int batt_chg);

    bt_status_t (*formatted_at_response)(const char *rsp);

    bt_status_t (*at_response) (bthf_at_response_t response_code, int error_code);

    bt_status_t (*clcc_response) (int index, bthf_call_direction_t dir,

                                bthf_call_state_t state, bthf_call_mode_t mode,

                                bthf_call_mpty_type_t mpty, const char *number,

                                bthf_call_addrtype_t type);

    bt_status_t (*phone_state_change) (int num_active, int num_held,

                           bthf_call_state_t call_setup_state,

                           const char *number, bthf_call_addrtype_t type);

    void  (*cleanup)( void );

} bthf_interface_t;

bt_hh.h

  1. bthh_callbacks_t

hardware/libhardware/include/hardware/bt_hh.h:

-------------------------------------------------------------------------

typedef struct {

    size_t      size;

    bthh_connection_state_callback  connection_state_cb;

    bthh_hid_info_callback          hid_info_cb;

    bthh_protocol_mode_callback     protocol_mode_cb;

    bthh_idle_time_callback         idle_time_cb;

    bthh_get_report_callback        get_report_cb;

    bthh_virtual_unplug_callback    virtual_unplug_cb;

} bthh_callbacks_t;

  1. bthh_interface_t

hardware/libhardware/include/hardware/bt_hh.h:

-------------------------------------------------------------------------

typedef struct {

    size_t          size;

    bt_status_t (*init)( bthh_callbacks_t* callbacks );

    bt_status_t (*connect)( bt_bdaddr_t *bd_addr);

    bt_status_t (*disconnect)( bt_bdaddr_t *bd_addr );

    bt_status_t (*virtual_unplug)(bt_bdaddr_t *bd_addr);

    bt_status_t (*set_info)(bt_bdaddr_t *bd_addr,

           bthh_hid_info_t hid_info );

    bt_status_t (*get_protocol) (bt_bdaddr_t *bd_addr,

           bthh_protocol_mode_t protocolMode);

    bt_status_t (*set_protocol)(bt_bdaddr_t *bd_addr,

           bthh_protocol_mode_t protocolMode);

    bt_status_t (*get_report)(bt_bdaddr_t *bd_addr,

           bthh_report_type_t reportType, uint8_t reportId, int bufferSize);

    bt_status_t (*set_report)(bt_bdaddr_t *bd_addr,

           bthh_report_type_t reportType, char* report);

    bt_status_t (*send_data)(bt_bdaddr_t *bd_addr, char* data);

    void  (*cleanup)( void );

} bthh_interface_t;

bt_hl.h

  1. bthl_callbacks_t

hardware/libhardware/include/hardware/bt_hl.h:

-------------------------------------------------------------------------

typedef struct {

    size_t      size;

    bthl_app_reg_state_callback     app_reg_state_cb;

    bthl_channel_state_callback     channel_state_cb;

} bthl_callbacks_t;

  1. bthl_interface_t

hardware/libhardware/include/hardware/bt_hl.h:

-------------------------------------------------------------------------

typedef struct {

    size_t          size;

    bt_status_t (*init)( bthl_callbacks_t* callbacks );

    bt_status_t (*register_application) ( bthl_reg_param_t *p_reg_param, int *app_id);

    bt_status_t (*unregister_application) (int app_id);

    bt_status_t (*connect_channel)(int app_id, bt_bdaddr_t *bd_addr, int mdep_cfg_index, int *channel_id);

    bt_status_t (*destroy_channel)(int channel_id);

    void (*cleanup)(void);

} bthl_interface_t;

bt_pan.h

  1. btpan_callbacks_t

hardware/libhardware/include/hardware/bt_pan.h:

-------------------------------------------------------------------------

typedef struct {

    size_t size;

    btpan_control_state_callback control_state_cb;

    btpan_connection_state_callback connection_state_cb;

} btpan_callbacks_t;

  1. btpan_interface_t

hardware/libhardware/include/hardware/bt_pan.h:

-------------------------------------------------------------------------

typedef struct {

    size_t          size;

    bt_status_t (*init)(const btpan_callbacks_t* callbacks);

    bt_status_t (*enable)(int local_role);

    int (*get_local_role)(void);

    bt_status_t (*connect)(const bt_bdaddr_t *bd_addr, int local_role, int remote_role);

    bt_status_t (*disconnect)(const bt_bdaddr_t *bd_addr);

    void (*cleanup)(void);

} btpan_interface_t;

bt_rc.h

  1. btrc_callbacks_t

hardware/libhardware/include/hardware/bt_rc.h:

-------------------------------------------------------------------------

typedef struct {

    size_t      size;

    btrc_remote_features_callback               remote_features_cb;

    btrc_get_play_status_callback               get_play_status_cb;

    btrc_list_player_app_attr_callback          list_player_app_attr_cb;

    btrc_list_player_app_values_callback        list_player_app_values_cb;

    btrc_get_player_app_value_callback          get_player_app_value_cb;

    btrc_get_player_app_attrs_text_callback    

        get_player_app_attrs_text_cb;

    btrc_get_player_app_values_text_callback   

        get_player_app_values_text_cb;

    btrc_set_player_app_value_callback          set_player_app_value_cb;

    btrc_get_element_attr_callback              get_element_attr_cb;

    btrc_register_notification_callback         register_notification_cb;

    btrc_volume_change_callback                 volume_change_cb;

    btrc_passthrough_cmd_callback               passthrough_cmd_cb;

} btrc_callbacks_t;

  1. btrc_interface_t

hardware/libhardware/include/hardware/bt_rc.h:

-------------------------------------------------------------------------

typedef struct {

    size_t          size;

    bt_status_t (*init)( btrc_callbacks_t* callbacks );

    bt_status_t (*get_play_status_rsp)( btrc_play_status_t play_status, uint32_t song_len, uint32_t song_pos);

    bt_status_t (*list_player_app_attr_rsp)( int num_attr, btrc_player_attr_t *p_attrs);

    bt_status_t (*list_player_app_value_rsp)( int num_val, uint8_t *p_vals);

    bt_status_t (*get_player_app_value_rsp)( btrc_player_settings_t *p_vals);

    bt_status_t (*get_player_app_attr_text_rsp)( int num_attr, btrc_player_setting_text_t *p_attrs);

    bt_status_t (*get_player_app_value_text_rsp)( int num_val, btrc_player_setting_text_t *p_vals);

    bt_status_t (*get_element_attr_rsp)( uint8_t num_attr, btrc_element_attr_val_t *p_attrs);

    bt_status_t (*set_player_app_value_rsp)(btrc_status_t rsp_status);

    bt_status_t (*register_notification_rsp)(btrc_event_id_t event_id,

                                             btrc_notification_type_t type,

                                             btrc_register_notification_t *p_param);

    bt_status_t (*set_volume)(uint8_t volume);

    void  (*cleanup)( void );

} btrc_interface_t;

bt_sock.h

  1. btsock_interface_t

hardware/libhardware/include/hardware/bt_sock.h:

-------------------------------------------------------------------------

typedef struct {

    size_t          size;

    bt_status_t (*listen)(btsock_type_t type, const char* service_name, const uint8_t* service_uuid, int channel, int* sock_fd, int flags);

    bt_status_t (*connect)(const bt_bdaddr_t *bd_addr, btsock_type_t type, const uint8_t* uuid, int channel, int* sock_fd, int flags);

} btsock_interface_t;

bluetooth.default

        源码位于:external/bluetooth/bluedroid。

  1. main/
  2. btif/
  3. btif/co/
  4. embdrv/sbc/encoder/
  5. udrv/
  6. libbt-brcm_bta(static)
    1. bta/
  7. libbt-brcm_gki(static)
    1. gki/
  8. libbt-brcm_stack(static)
    1. stack/

libbt-utils

  1. utils/

libbt-hci

  1. hci/

        厂商定制方式:

  1. 提供libbt-hci,覆盖默认库
  2. 提供libbt-vendor库,实现bt_vendor_interface_t、bt_vendor_callbacks_t。

audio.a2dp.default

  1. audio_a2dp_hw

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

闽ICP备14008679号