Jakub Pawlowski | f2f207a | 2017-09-23 14:47:20 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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_HH_H |
| 18 | #define ANDROID_INCLUDE_BT_HH_H |
| 19 | |
| 20 | #include <stdint.h> |
| 21 | |
| 22 | __BEGIN_DECLS |
| 23 | |
Jakub Pawlowski | 3a3b82c | 2017-10-18 20:49:54 -0700 | [diff] [blame] | 24 | #define BTHH_MAX_DSC_LEN 884 |
Jakub Pawlowski | f2f207a | 2017-09-23 14:47:20 -0700 | [diff] [blame] | 25 | |
| 26 | /* HH connection states */ |
Jakub Pawlowski | 3a3b82c | 2017-10-18 20:49:54 -0700 | [diff] [blame] | 27 | typedef enum { |
| 28 | BTHH_CONN_STATE_CONNECTED = 0, |
| 29 | BTHH_CONN_STATE_CONNECTING, |
| 30 | BTHH_CONN_STATE_DISCONNECTED, |
| 31 | BTHH_CONN_STATE_DISCONNECTING, |
| 32 | BTHH_CONN_STATE_FAILED_MOUSE_FROM_HOST, |
| 33 | BTHH_CONN_STATE_FAILED_KBD_FROM_HOST, |
| 34 | BTHH_CONN_STATE_FAILED_TOO_MANY_DEVICES, |
| 35 | BTHH_CONN_STATE_FAILED_NO_BTHID_DRIVER, |
| 36 | BTHH_CONN_STATE_FAILED_GENERIC, |
| 37 | BTHH_CONN_STATE_UNKNOWN |
Jakub Pawlowski | f2f207a | 2017-09-23 14:47:20 -0700 | [diff] [blame] | 38 | } bthh_connection_state_t; |
| 39 | |
Jakub Pawlowski | 3a3b82c | 2017-10-18 20:49:54 -0700 | [diff] [blame] | 40 | typedef enum { |
| 41 | BTHH_OK = 0, |
| 42 | BTHH_HS_HID_NOT_READY, /* handshake error : device not ready */ |
| 43 | BTHH_HS_INVALID_RPT_ID, /* handshake error : invalid report ID */ |
| 44 | BTHH_HS_TRANS_NOT_SPT, /* handshake error : transaction not spt */ |
| 45 | BTHH_HS_INVALID_PARAM, /* handshake error : invalid paremter */ |
| 46 | BTHH_HS_ERROR, /* handshake error : unspecified HS error */ |
| 47 | BTHH_ERR, /* general BTA HH error */ |
| 48 | BTHH_ERR_SDP, /* SDP error */ |
| 49 | BTHH_ERR_PROTO, /* SET_Protocol error, |
| 50 | only used in BTA_HH_OPEN_EVT |
| 51 | callback */ |
| 52 | BTHH_ERR_DB_FULL, /* device database full error, used */ |
| 53 | BTHH_ERR_TOD_UNSPT, /* type of device not supported */ |
| 54 | BTHH_ERR_NO_RES, /* out of system resources */ |
| 55 | BTHH_ERR_AUTH_FAILED, /* authentication fail */ |
| 56 | BTHH_ERR_HDL |
| 57 | } bthh_status_t; |
Jakub Pawlowski | f2f207a | 2017-09-23 14:47:20 -0700 | [diff] [blame] | 58 | |
| 59 | /* Protocol modes */ |
| 60 | typedef enum { |
Jakub Pawlowski | 3a3b82c | 2017-10-18 20:49:54 -0700 | [diff] [blame] | 61 | BTHH_REPORT_MODE = 0x00, |
| 62 | BTHH_BOOT_MODE = 0x01, |
| 63 | BTHH_UNSUPPORTED_MODE = 0xff |
| 64 | } bthh_protocol_mode_t; |
Jakub Pawlowski | f2f207a | 2017-09-23 14:47:20 -0700 | [diff] [blame] | 65 | |
| 66 | /* Report types */ |
| 67 | typedef enum { |
Jakub Pawlowski | 3a3b82c | 2017-10-18 20:49:54 -0700 | [diff] [blame] | 68 | BTHH_INPUT_REPORT = 1, |
| 69 | BTHH_OUTPUT_REPORT, |
| 70 | BTHH_FEATURE_REPORT |
| 71 | } bthh_report_type_t; |
Jakub Pawlowski | f2f207a | 2017-09-23 14:47:20 -0700 | [diff] [blame] | 72 | |
Jakub Pawlowski | 3a3b82c | 2017-10-18 20:49:54 -0700 | [diff] [blame] | 73 | typedef struct { |
| 74 | int attr_mask; |
| 75 | uint8_t sub_class; |
| 76 | uint8_t app_id; |
| 77 | int vendor_id; |
| 78 | int product_id; |
| 79 | int version; |
| 80 | uint8_t ctry_code; |
| 81 | int dl_len; |
| 82 | uint8_t dsc_list[BTHH_MAX_DSC_LEN]; |
Jakub Pawlowski | f2f207a | 2017-09-23 14:47:20 -0700 | [diff] [blame] | 83 | } bthh_hid_info_t; |
| 84 | |
| 85 | /** Callback for connection state change. |
| 86 | * state will have one of the values from bthh_connection_state_t |
| 87 | */ |
Jakub Pawlowski | 3a3b82c | 2017-10-18 20:49:54 -0700 | [diff] [blame] | 88 | typedef void (*bthh_connection_state_callback)(RawAddress* bd_addr, |
| 89 | bthh_connection_state_t state); |
Jakub Pawlowski | f2f207a | 2017-09-23 14:47:20 -0700 | [diff] [blame] | 90 | |
| 91 | /** Callback for vitual unplug api. |
| 92 | * the status of the vitual unplug |
| 93 | */ |
Jakub Pawlowski | 3a3b82c | 2017-10-18 20:49:54 -0700 | [diff] [blame] | 94 | typedef void (*bthh_virtual_unplug_callback)(RawAddress* bd_addr, |
| 95 | bthh_status_t hh_status); |
Jakub Pawlowski | f2f207a | 2017-09-23 14:47:20 -0700 | [diff] [blame] | 96 | |
| 97 | /** Callback for get hid info |
Jakub Pawlowski | 3a3b82c | 2017-10-18 20:49:54 -0700 | [diff] [blame] | 98 | * hid_info will contain attr_mask, sub_class, app_id, vendor_id, product_id, |
| 99 | * version, ctry_code, len |
Jakub Pawlowski | f2f207a | 2017-09-23 14:47:20 -0700 | [diff] [blame] | 100 | */ |
Jakub Pawlowski | 3a3b82c | 2017-10-18 20:49:54 -0700 | [diff] [blame] | 101 | typedef void (*bthh_hid_info_callback)(RawAddress* bd_addr, |
| 102 | bthh_hid_info_t hid_info); |
Jakub Pawlowski | f2f207a | 2017-09-23 14:47:20 -0700 | [diff] [blame] | 103 | |
| 104 | /** Callback for get protocol api. |
| 105 | * the protocol mode is one of the value from bthh_protocol_mode_t |
| 106 | */ |
Jakub Pawlowski | 3a3b82c | 2017-10-18 20:49:54 -0700 | [diff] [blame] | 107 | typedef void (*bthh_protocol_mode_callback)(RawAddress* bd_addr, |
| 108 | bthh_status_t hh_status, |
| 109 | bthh_protocol_mode_t mode); |
Jakub Pawlowski | f2f207a | 2017-09-23 14:47:20 -0700 | [diff] [blame] | 110 | |
| 111 | /** Callback for get/set_idle_time api. |
| 112 | */ |
Jakub Pawlowski | 3a3b82c | 2017-10-18 20:49:54 -0700 | [diff] [blame] | 113 | typedef void (*bthh_idle_time_callback)(RawAddress* bd_addr, |
| 114 | bthh_status_t hh_status, int idle_rate); |
Jakub Pawlowski | f2f207a | 2017-09-23 14:47:20 -0700 | [diff] [blame] | 115 | |
| 116 | /** Callback for get report api. |
| 117 | * if staus is ok rpt_data contains the report data |
| 118 | */ |
Jakub Pawlowski | 3a3b82c | 2017-10-18 20:49:54 -0700 | [diff] [blame] | 119 | typedef void (*bthh_get_report_callback)(RawAddress* bd_addr, |
| 120 | bthh_status_t hh_status, |
| 121 | uint8_t* rpt_data, int rpt_size); |
Jakub Pawlowski | f2f207a | 2017-09-23 14:47:20 -0700 | [diff] [blame] | 122 | |
| 123 | /** Callback for set_report/set_protocol api and if error |
| 124 | * occurs for get_report/get_protocol api. |
| 125 | */ |
Jakub Pawlowski | 3a3b82c | 2017-10-18 20:49:54 -0700 | [diff] [blame] | 126 | typedef void (*bthh_handshake_callback)(RawAddress* bd_addr, |
| 127 | bthh_status_t hh_status); |
Jakub Pawlowski | f2f207a | 2017-09-23 14:47:20 -0700 | [diff] [blame] | 128 | |
| 129 | /** BT-HH callback structure. */ |
| 130 | typedef struct { |
Jakub Pawlowski | 3a3b82c | 2017-10-18 20:49:54 -0700 | [diff] [blame] | 131 | /** set to sizeof(BtHfCallbacks) */ |
| 132 | size_t size; |
| 133 | bthh_connection_state_callback connection_state_cb; |
| 134 | bthh_hid_info_callback hid_info_cb; |
| 135 | bthh_protocol_mode_callback protocol_mode_cb; |
| 136 | bthh_idle_time_callback idle_time_cb; |
| 137 | bthh_get_report_callback get_report_cb; |
| 138 | bthh_virtual_unplug_callback virtual_unplug_cb; |
| 139 | bthh_handshake_callback handshake_cb; |
Jakub Pawlowski | f2f207a | 2017-09-23 14:47:20 -0700 | [diff] [blame] | 140 | |
| 141 | } bthh_callbacks_t; |
| 142 | |
Jakub Pawlowski | f2f207a | 2017-09-23 14:47:20 -0700 | [diff] [blame] | 143 | /** Represents the standard BT-HH interface. */ |
| 144 | typedef struct { |
Jakub Pawlowski | 3a3b82c | 2017-10-18 20:49:54 -0700 | [diff] [blame] | 145 | /** set to sizeof(BtHhInterface) */ |
| 146 | size_t size; |
Jakub Pawlowski | f2f207a | 2017-09-23 14:47:20 -0700 | [diff] [blame] | 147 | |
Jakub Pawlowski | 3a3b82c | 2017-10-18 20:49:54 -0700 | [diff] [blame] | 148 | /** |
| 149 | * Register the BtHh callbacks |
| 150 | */ |
| 151 | bt_status_t (*init)(bthh_callbacks_t* callbacks); |
Jakub Pawlowski | f2f207a | 2017-09-23 14:47:20 -0700 | [diff] [blame] | 152 | |
Jakub Pawlowski | 3a3b82c | 2017-10-18 20:49:54 -0700 | [diff] [blame] | 153 | /** connect to hid device */ |
| 154 | bt_status_t (*connect)(RawAddress* bd_addr); |
Jakub Pawlowski | f2f207a | 2017-09-23 14:47:20 -0700 | [diff] [blame] | 155 | |
Jakub Pawlowski | 3a3b82c | 2017-10-18 20:49:54 -0700 | [diff] [blame] | 156 | /** dis-connect from hid device */ |
| 157 | bt_status_t (*disconnect)(RawAddress* bd_addr); |
Jakub Pawlowski | f2f207a | 2017-09-23 14:47:20 -0700 | [diff] [blame] | 158 | |
Jakub Pawlowski | 3a3b82c | 2017-10-18 20:49:54 -0700 | [diff] [blame] | 159 | /** Virtual UnPlug (VUP) the specified HID device */ |
| 160 | bt_status_t (*virtual_unplug)(RawAddress* bd_addr); |
Jakub Pawlowski | f2f207a | 2017-09-23 14:47:20 -0700 | [diff] [blame] | 161 | |
Jakub Pawlowski | 3a3b82c | 2017-10-18 20:49:54 -0700 | [diff] [blame] | 162 | /** Set the HID device descriptor for the specified HID device. */ |
| 163 | bt_status_t (*set_info)(RawAddress* bd_addr, bthh_hid_info_t hid_info); |
Jakub Pawlowski | f2f207a | 2017-09-23 14:47:20 -0700 | [diff] [blame] | 164 | |
Jakub Pawlowski | 3a3b82c | 2017-10-18 20:49:54 -0700 | [diff] [blame] | 165 | /** Get the HID proto mode. */ |
| 166 | bt_status_t (*get_protocol)(RawAddress* bd_addr, |
| 167 | bthh_protocol_mode_t protocolMode); |
Jakub Pawlowski | f2f207a | 2017-09-23 14:47:20 -0700 | [diff] [blame] | 168 | |
Jakub Pawlowski | 3a3b82c | 2017-10-18 20:49:54 -0700 | [diff] [blame] | 169 | /** Set the HID proto mode. */ |
| 170 | bt_status_t (*set_protocol)(RawAddress* bd_addr, |
| 171 | bthh_protocol_mode_t protocolMode); |
Jakub Pawlowski | f2f207a | 2017-09-23 14:47:20 -0700 | [diff] [blame] | 172 | |
Jakub Pawlowski | 3a3b82c | 2017-10-18 20:49:54 -0700 | [diff] [blame] | 173 | /** Get the HID Idle Time */ |
| 174 | bt_status_t (*get_idle_time)(RawAddress* bd_addr); |
Jakub Pawlowski | f2f207a | 2017-09-23 14:47:20 -0700 | [diff] [blame] | 175 | |
Jakub Pawlowski | 3a3b82c | 2017-10-18 20:49:54 -0700 | [diff] [blame] | 176 | /** Set the HID Idle Time */ |
| 177 | bt_status_t (*set_idle_time)(RawAddress* bd_addr, uint8_t idleTime); |
Jakub Pawlowski | f2f207a | 2017-09-23 14:47:20 -0700 | [diff] [blame] | 178 | |
Jakub Pawlowski | 3a3b82c | 2017-10-18 20:49:54 -0700 | [diff] [blame] | 179 | /** Send a GET_REPORT to HID device. */ |
| 180 | bt_status_t (*get_report)(RawAddress* bd_addr, bthh_report_type_t reportType, |
| 181 | uint8_t reportId, int bufferSize); |
Jakub Pawlowski | f2f207a | 2017-09-23 14:47:20 -0700 | [diff] [blame] | 182 | |
Jakub Pawlowski | 3a3b82c | 2017-10-18 20:49:54 -0700 | [diff] [blame] | 183 | /** Send a SET_REPORT to HID device. */ |
| 184 | bt_status_t (*set_report)(RawAddress* bd_addr, bthh_report_type_t reportType, |
| 185 | char* report); |
Jakub Pawlowski | f2f207a | 2017-09-23 14:47:20 -0700 | [diff] [blame] | 186 | |
Jakub Pawlowski | 3a3b82c | 2017-10-18 20:49:54 -0700 | [diff] [blame] | 187 | /** Send data to HID device. */ |
| 188 | bt_status_t (*send_data)(RawAddress* bd_addr, char* data); |
Jakub Pawlowski | f2f207a | 2017-09-23 14:47:20 -0700 | [diff] [blame] | 189 | |
Jakub Pawlowski | 3a3b82c | 2017-10-18 20:49:54 -0700 | [diff] [blame] | 190 | /** Closes the interface. */ |
| 191 | void (*cleanup)(void); |
Jakub Pawlowski | f2f207a | 2017-09-23 14:47:20 -0700 | [diff] [blame] | 192 | |
| 193 | } bthh_interface_t; |
| 194 | __END_DECLS |
| 195 | |
| 196 | #endif /* ANDROID_INCLUDE_BT_HH_H */ |