Home | History | Annotate | Download | only in hardware
      1 /*
      2  * Copyright (C) 2016 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #ifndef ANDROID_INCLUDE_BT_HD_H
     18 #define ANDROID_INCLUDE_BT_HD_H
     19 
     20 #include <stdint.h>
     21 
     22 __BEGIN_DECLS
     23 
     24 typedef enum {
     25   BTHD_REPORT_TYPE_OTHER = 0,
     26   BTHD_REPORT_TYPE_INPUT,
     27   BTHD_REPORT_TYPE_OUTPUT,
     28   BTHD_REPORT_TYPE_FEATURE,
     29   // special value for reports to be sent on INTR(INPUT is assumed)
     30   BTHD_REPORT_TYPE_INTRDATA
     31 } bthd_report_type_t;
     32 
     33 typedef enum {
     34   BTHD_APP_STATE_NOT_REGISTERED,
     35   BTHD_APP_STATE_REGISTERED
     36 } bthd_application_state_t;
     37 
     38 typedef enum {
     39   BTHD_CONN_STATE_CONNECTED,
     40   BTHD_CONN_STATE_CONNECTING,
     41   BTHD_CONN_STATE_DISCONNECTED,
     42   BTHD_CONN_STATE_DISCONNECTING,
     43   BTHD_CONN_STATE_UNKNOWN
     44 } bthd_connection_state_t;
     45 
     46 typedef struct {
     47   const char* name;
     48   const char* description;
     49   const char* provider;
     50   uint8_t subclass;
     51   uint8_t* desc_list;
     52   int desc_list_len;
     53 } bthd_app_param_t;
     54 
     55 typedef struct {
     56   uint8_t service_type;
     57   uint32_t token_rate;
     58   uint32_t token_bucket_size;
     59   uint32_t peak_bandwidth;
     60   uint32_t access_latency;
     61   uint32_t delay_variation;
     62 } bthd_qos_param_t;
     63 
     64 typedef void (*bthd_application_state_callback)(RawAddress* bd_addr,
     65                                                 bthd_application_state_t state);
     66 typedef void (*bthd_connection_state_callback)(RawAddress* bd_addr,
     67                                                bthd_connection_state_t state);
     68 typedef void (*bthd_get_report_callback)(uint8_t type, uint8_t id,
     69                                          uint16_t buffer_size);
     70 typedef void (*bthd_set_report_callback)(uint8_t type, uint8_t id, uint16_t len,
     71                                          uint8_t* p_data);
     72 typedef void (*bthd_set_protocol_callback)(uint8_t protocol);
     73 typedef void (*bthd_intr_data_callback)(uint8_t report_id, uint16_t len,
     74                                         uint8_t* p_data);
     75 typedef void (*bthd_vc_unplug_callback)(void);
     76 
     77 /** BT-HD callbacks */
     78 typedef struct {
     79   size_t size;
     80 
     81   bthd_application_state_callback application_state_cb;
     82   bthd_connection_state_callback connection_state_cb;
     83   bthd_get_report_callback get_report_cb;
     84   bthd_set_report_callback set_report_cb;
     85   bthd_set_protocol_callback set_protocol_cb;
     86   bthd_intr_data_callback intr_data_cb;
     87   bthd_vc_unplug_callback vc_unplug_cb;
     88 } bthd_callbacks_t;
     89 
     90 /** BT-HD interface */
     91 typedef struct {
     92   size_t size;
     93 
     94   /** init interface and register callbacks */
     95   bt_status_t (*init)(bthd_callbacks_t* callbacks);
     96 
     97   /** close interface */
     98   void (*cleanup)(void);
     99 
    100   /** register application */
    101   bt_status_t (*register_app)(bthd_app_param_t* app_param,
    102                               bthd_qos_param_t* in_qos,
    103                               bthd_qos_param_t* out_qos);
    104 
    105   /** unregister application */
    106   bt_status_t (*unregister_app)(void);
    107 
    108   /** connects to host with virtual cable */
    109   bt_status_t (*connect)(RawAddress* bd_addr);
    110 
    111   /** disconnects from currently connected host */
    112   bt_status_t (*disconnect)(void);
    113 
    114   /** send report */
    115   bt_status_t (*send_report)(bthd_report_type_t type, uint8_t id, uint16_t len,
    116                              uint8_t* p_data);
    117 
    118   /** notifies error for invalid SET_REPORT */
    119   bt_status_t (*report_error)(uint8_t error);
    120 
    121   /** send Virtual Cable Unplug  */
    122   bt_status_t (*virtual_cable_unplug)(void);
    123 
    124 } bthd_interface_t;
    125 
    126 __END_DECLS
    127 
    128 #endif /* ANDROID_INCLUDE_BT_HD_H */
    129