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