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 #include "types/raw_address.h" 23 24 __BEGIN_DECLS 25 26 typedef enum { 27 BTHD_REPORT_TYPE_OTHER = 0, 28 BTHD_REPORT_TYPE_INPUT, 29 BTHD_REPORT_TYPE_OUTPUT, 30 BTHD_REPORT_TYPE_FEATURE, 31 // special value for reports to be sent on INTR(INPUT is assumed) 32 BTHD_REPORT_TYPE_INTRDATA 33 } bthd_report_type_t; 34 35 typedef enum { BTHD_APP_STATE_NOT_REGISTERED, BTHD_APP_STATE_REGISTERED } bthd_application_state_t; 36 37 typedef enum { 38 BTHD_CONN_STATE_CONNECTED, 39 BTHD_CONN_STATE_CONNECTING, 40 BTHD_CONN_STATE_DISCONNECTED, 41 BTHD_CONN_STATE_DISCONNECTING, 42 BTHD_CONN_STATE_UNKNOWN 43 } bthd_connection_state_t; 44 45 typedef struct { 46 const char* name; 47 const char* description; 48 const char* provider; 49 uint8_t subclass; 50 uint8_t* desc_list; 51 int desc_list_len; 52 } bthd_app_param_t; 53 54 typedef struct { 55 uint8_t service_type; 56 uint32_t token_rate; 57 uint32_t token_bucket_size; 58 uint32_t peak_bandwidth; 59 uint32_t access_latency; 60 uint32_t delay_variation; 61 } bthd_qos_param_t; 62 63 typedef void (*bthd_application_state_callback)(RawAddress* bd_addr, 64 bthd_application_state_t state); 65 typedef void (*bthd_connection_state_callback)(RawAddress* bd_addr, bthd_connection_state_t state); 66 typedef void (*bthd_get_report_callback)(uint8_t type, uint8_t id, uint16_t buffer_size); 67 typedef void (*bthd_set_report_callback)(uint8_t type, uint8_t id, uint16_t len, uint8_t* p_data); 68 typedef void (*bthd_set_protocol_callback)(uint8_t protocol); 69 typedef void (*bthd_intr_data_callback)(uint8_t report_id, uint16_t len, uint8_t* p_data); 70 typedef void (*bthd_vc_unplug_callback)(void); 71 72 /** BT-HD callbacks */ 73 typedef struct { 74 size_t size; 75 76 bthd_application_state_callback application_state_cb; 77 bthd_connection_state_callback connection_state_cb; 78 bthd_get_report_callback get_report_cb; 79 bthd_set_report_callback set_report_cb; 80 bthd_set_protocol_callback set_protocol_cb; 81 bthd_intr_data_callback intr_data_cb; 82 bthd_vc_unplug_callback vc_unplug_cb; 83 } bthd_callbacks_t; 84 85 /** BT-HD interface */ 86 typedef struct { 87 size_t size; 88 89 /** init interface and register callbacks */ 90 bt_status_t (*init)(bthd_callbacks_t* callbacks); 91 92 /** close interface */ 93 void (*cleanup)(void); 94 95 /** register application */ 96 bt_status_t (*register_app)(bthd_app_param_t* app_param, bthd_qos_param_t* in_qos, 97 bthd_qos_param_t* out_qos); 98 99 /** unregister application */ 100 bt_status_t (*unregister_app)(void); 101 102 /** connects to host with virtual cable */ 103 bt_status_t (*connect)(RawAddress* bd_addr); 104 105 /** disconnects from currently connected host */ 106 bt_status_t (*disconnect)(void); 107 108 /** send report */ 109 bt_status_t (*send_report)(bthd_report_type_t type, uint8_t id, uint16_t len, uint8_t* p_data); 110 111 /** notifies error for invalid SET_REPORT */ 112 bt_status_t (*report_error)(uint8_t error); 113 114 /** send Virtual Cable Unplug */ 115 bt_status_t (*virtual_cable_unplug)(void); 116 } bthd_interface_t; 117 118 __END_DECLS 119 120 #if __has_include(<bluetooth/log.h>) 121 #include <bluetooth/log.h> 122 123 namespace std { 124 template <> 125 struct formatter<bthd_report_type_t> : enum_formatter<bthd_report_type_t> {}; 126 } // namespace std 127 128 #endif // __has_include(<bluetooth/log.h>) 129 130 #endif /* ANDROID_INCLUDE_BT_HD_H */ 131