1 /****************************************************************************** 2 * 3 * Copyright 2016 The Android Open Source Project 4 * Copyright 2005-2012 Broadcom Corporation 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at: 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 * 18 ******************************************************************************/ 19 20 /****************************************************************************** 21 * 22 * This file contains BTA HID Device internal definitions 23 * 24 ******************************************************************************/ 25 26 #ifndef BTA_HD_INT_H 27 #define BTA_HD_INT_H 28 29 #include <cstdint> 30 31 #include "bta/include/bta_hd_api.h" 32 #include "bta/sys/bta_sys.h" 33 #include "stack/include/bt_types.h" 34 #include "stack/include/hiddefs.h" 35 #include "types/raw_address.h" 36 37 enum { 38 BTA_HD_API_REGISTER_APP_EVT = BTA_SYS_EVT_START(BTA_ID_HD), 39 BTA_HD_API_UNREGISTER_APP_EVT, 40 BTA_HD_API_CONNECT_EVT, 41 BTA_HD_API_DISCONNECT_EVT, 42 BTA_HD_API_ADD_DEVICE_EVT, 43 BTA_HD_API_REMOVE_DEVICE_EVT, 44 BTA_HD_API_SEND_REPORT_EVT, 45 BTA_HD_API_REPORT_ERROR_EVT, 46 BTA_HD_API_VC_UNPLUG_EVT, 47 BTA_HD_INT_OPEN_EVT, 48 BTA_HD_INT_CLOSE_EVT, 49 BTA_HD_INT_INTR_DATA_EVT, 50 BTA_HD_INT_GET_REPORT_EVT, 51 BTA_HD_INT_SET_REPORT_EVT, 52 BTA_HD_INT_SET_PROTOCOL_EVT, 53 BTA_HD_INT_VC_UNPLUG_EVT, 54 BTA_HD_INT_SUSPEND_EVT, 55 BTA_HD_INT_EXIT_SUSPEND_EVT, 56 57 /* handled outside state machine */ 58 BTA_HD_API_ENABLE_EVT, 59 BTA_HD_API_DISABLE_EVT 60 }; 61 typedef uint16_t tBTA_HD_INT_EVT; 62 63 #define BTA_HD_INVALID_EVT (BTA_HD_API_DISABLE_EVT + 1) 64 65 typedef struct { 66 BT_HDR_RIGID hdr; 67 tBTA_HD_CBACK* p_cback; 68 } tBTA_HD_API_ENABLE; 69 70 #define BTA_HD_APP_NAME_LEN 50 71 #define BTA_HD_APP_DESCRIPTION_LEN 50 72 #define BTA_HD_APP_PROVIDER_LEN 50 73 #define BTA_HD_APP_DESCRIPTOR_LEN HIDD_APP_DESCRIPTOR_LEN 74 75 #define BTA_HD_STATE_DISABLED 0x00 76 #define BTA_HD_STATE_ENABLED 0x01 77 #define BTA_HD_STATE_IDLE 0x02 78 #define BTA_HD_STATE_CONNECTED 0x03 79 #define BTA_HD_STATE_DISABLING 0x04 80 #define BTA_HD_STATE_REMOVING 0x05 81 82 typedef struct { 83 BT_HDR_RIGID hdr; 84 char name[BTA_HD_APP_NAME_LEN]; 85 char description[BTA_HD_APP_DESCRIPTION_LEN]; 86 char provider[BTA_HD_APP_PROVIDER_LEN]; 87 uint8_t subclass; 88 uint16_t d_len; 89 uint8_t d_data[BTA_HD_APP_DESCRIPTOR_LEN]; 90 91 tBTA_HD_QOS_INFO in_qos; 92 tBTA_HD_QOS_INFO out_qos; 93 } tBTA_HD_REGISTER_APP; 94 95 #define BTA_HD_REPORT_LEN HID_DEV_MTU_SIZE 96 97 typedef struct { 98 BT_HDR_RIGID hdr; 99 bool use_intr; 100 uint8_t type; 101 uint8_t id; 102 uint16_t len; 103 uint8_t data[BTA_HD_REPORT_LEN]; 104 } tBTA_HD_SEND_REPORT; 105 106 typedef struct { 107 BT_HDR_RIGID hdr; 108 RawAddress addr; 109 } tBTA_HD_DEVICE_CTRL; 110 111 typedef struct { 112 BT_HDR_RIGID hdr; 113 uint8_t error; 114 } tBTA_HD_REPORT_ERR; 115 116 /* union of all event data types */ 117 typedef union { 118 BT_HDR_RIGID hdr; 119 tBTA_HD_API_ENABLE api_enable; 120 tBTA_HD_REGISTER_APP register_app; 121 tBTA_HD_SEND_REPORT send_report; 122 tBTA_HD_DEVICE_CTRL device_ctrl; 123 tBTA_HD_REPORT_ERR report_err; 124 } tBTA_HD_DATA; 125 126 typedef struct { 127 BT_HDR_RIGID hdr; 128 RawAddress addr; 129 uint32_t data; 130 BT_HDR* p_data; 131 } tBTA_HD_CBACK_DATA; 132 133 /****************************************************************************** 134 * Main Control Block 135 ******************************************************************************/ 136 typedef struct { 137 tBTA_HD_CBACK* p_cback; 138 uint32_t sdp_handle; 139 uint8_t trace_level; 140 uint8_t state; 141 RawAddress bd_addr; 142 bool use_report_id; 143 bool boot_mode; 144 bool vc_unplug; 145 bool disable_w4_close; 146 } tBTA_HD_CB; 147 148 extern tBTA_HD_CB bta_hd_cb; 149 150 /***************************************************************************** 151 * Function prototypes 152 ****************************************************************************/ 153 extern bool bta_hd_hdl_event(BT_HDR_RIGID* p_msg); 154 155 extern void bta_hd_api_enable(tBTA_HD_DATA* p_data); 156 extern void bta_hd_api_disable(void); 157 158 extern void bta_hd_register_act(tBTA_HD_DATA* p_data); 159 extern void bta_hd_unregister_act(); 160 extern void bta_hd_unregister2_act(tBTA_HD_DATA* p_data); 161 extern void bta_hd_connect_act(tBTA_HD_DATA* p_data); 162 extern void bta_hd_disconnect_act(); 163 extern void bta_hd_add_device_act(tBTA_HD_DATA* p_data); 164 extern void bta_hd_remove_device_act(tBTA_HD_DATA* p_data); 165 extern void bta_hd_send_report_act(tBTA_HD_DATA* p_data); 166 extern void bta_hd_report_error_act(tBTA_HD_DATA* p_data); 167 extern void bta_hd_vc_unplug_act(); 168 169 extern void bta_hd_open_act(tBTA_HD_DATA* p_data); 170 extern void bta_hd_close_act(tBTA_HD_DATA* p_data); 171 extern void bta_hd_intr_data_act(tBTA_HD_DATA* p_data); 172 extern void bta_hd_get_report_act(tBTA_HD_DATA* p_data); 173 extern void bta_hd_set_report_act(tBTA_HD_DATA* p_data); 174 extern void bta_hd_set_protocol_act(tBTA_HD_DATA* p_data); 175 extern void bta_hd_vc_unplug_done_act(tBTA_HD_DATA* p_data); 176 extern void bta_hd_suspend_act(tBTA_HD_DATA* p_data); 177 extern void bta_hd_exit_suspend_act(tBTA_HD_DATA* p_data); 178 179 #endif 180