blob: c39e3e5b8a3bceceb4f4187e3938dc6c56352c56 [file] [log] [blame]
Andre Eisenbach05f49542012-09-18 12:15:26 -07001/*
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
24#define BTHH_MAX_DSC_LEN 884
25
26/* HH connection states */
27typedef enum
28{
29 BTHH_CONN_STATE_CONNECTED = 0,
30 BTHH_CONN_STATE_CONNECTING,
31 BTHH_CONN_STATE_DISCONNECTED,
32 BTHH_CONN_STATE_DISCONNECTING,
33 BTHH_CONN_STATE_FAILED_MOUSE_FROM_HOST,
34 BTHH_CONN_STATE_FAILED_KBD_FROM_HOST,
35 BTHH_CONN_STATE_FAILED_TOO_MANY_DEVICES,
36 BTHH_CONN_STATE_FAILED_NO_BTHID_DRIVER,
37 BTHH_CONN_STATE_FAILED_GENERIC,
38 BTHH_CONN_STATE_UNKNOWN
39} bthh_connection_state_t;
40
41typedef enum
42{
43 BTHH_OK = 0,
44 BTHH_HS_HID_NOT_READY, /* handshake error : device not ready */
45 BTHH_HS_INVALID_RPT_ID, /* handshake error : invalid report ID */
46 BTHH_HS_TRANS_NOT_SPT, /* handshake error : transaction not spt */
47 BTHH_HS_INVALID_PARAM, /* handshake error : invalid paremter */
48 BTHH_HS_ERROR, /* handshake error : unspecified HS error */
49 BTHH_ERR, /* general BTA HH error */
50 BTHH_ERR_SDP, /* SDP error */
51 BTHH_ERR_PROTO, /* SET_Protocol error,
52 only used in BTA_HH_OPEN_EVT callback */
53 BTHH_ERR_DB_FULL, /* device database full error, used */
54 BTHH_ERR_TOD_UNSPT, /* type of device not supported */
55 BTHH_ERR_NO_RES, /* out of system resources */
56 BTHH_ERR_AUTH_FAILED, /* authentication fail */
57 BTHH_ERR_HDL
58}bthh_status_t;
59
60/* Protocol modes */
61typedef enum {
62 BTHH_REPORT_MODE = 0x00,
63 BTHH_BOOT_MODE = 0x01,
64 BTHH_UNSUPPORTED_MODE = 0xff
65}bthh_protocol_mode_t;
66
67/* Report types */
68typedef enum {
69 BTHH_INPUT_REPORT = 1,
70 BTHH_OUTPUT_REPORT,
71 BTHH_FEATURE_REPORT
72}bthh_report_type_t;
73
74typedef struct
75{
76 int attr_mask;
77 uint8_t sub_class;
78 uint8_t app_id;
79 int vendor_id;
80 int product_id;
81 int version;
82 uint8_t ctry_code;
83 int dl_len;
84 uint8_t dsc_list[BTHH_MAX_DSC_LEN];
85} bthh_hid_info_t;
86
87/** Callback for connection state change.
88 * state will have one of the values from bthh_connection_state_t
89 */
Jakub Pawlowskidb4c12a2017-06-24 17:33:20 -070090typedef void (* bthh_connection_state_callback)(RawAddress *bd_addr, bthh_connection_state_t state);
Andre Eisenbach05f49542012-09-18 12:15:26 -070091
92/** Callback for vitual unplug api.
93 * the status of the vitual unplug
94 */
Jakub Pawlowskidb4c12a2017-06-24 17:33:20 -070095typedef void (* bthh_virtual_unplug_callback)(RawAddress *bd_addr, bthh_status_t hh_status);
Andre Eisenbach05f49542012-09-18 12:15:26 -070096
97/** Callback for get hid info
98 * hid_info will contain attr_mask, sub_class, app_id, vendor_id, product_id, version, ctry_code, len
99 */
Jakub Pawlowskidb4c12a2017-06-24 17:33:20 -0700100typedef void (* bthh_hid_info_callback)(RawAddress *bd_addr, bthh_hid_info_t hid_info);
Andre Eisenbach05f49542012-09-18 12:15:26 -0700101
Mike J. Chen753c4422014-02-25 19:25:55 -0800102/** Callback for get protocol api.
Andre Eisenbach05f49542012-09-18 12:15:26 -0700103 * the protocol mode is one of the value from bthh_protocol_mode_t
104 */
Jakub Pawlowskidb4c12a2017-06-24 17:33:20 -0700105typedef void (* bthh_protocol_mode_callback)(RawAddress *bd_addr, bthh_status_t hh_status, bthh_protocol_mode_t mode);
Andre Eisenbach05f49542012-09-18 12:15:26 -0700106
107/** Callback for get/set_idle_time api.
108 */
Jakub Pawlowskidb4c12a2017-06-24 17:33:20 -0700109typedef void (* bthh_idle_time_callback)(RawAddress *bd_addr, bthh_status_t hh_status, int idle_rate);
Andre Eisenbach05f49542012-09-18 12:15:26 -0700110
111
112/** Callback for get report api.
113 * if staus is ok rpt_data contains the report data
114 */
Jakub Pawlowskidb4c12a2017-06-24 17:33:20 -0700115typedef void (* bthh_get_report_callback)(RawAddress *bd_addr, bthh_status_t hh_status, uint8_t* rpt_data, int rpt_size);
Andre Eisenbach05f49542012-09-18 12:15:26 -0700116
Mike J. Chen753c4422014-02-25 19:25:55 -0800117/** Callback for set_report/set_protocol api and if error
118 * occurs for get_report/get_protocol api.
119 */
Jakub Pawlowskidb4c12a2017-06-24 17:33:20 -0700120typedef void (* bthh_handshake_callback)(RawAddress *bd_addr, bthh_status_t hh_status);
Mike J. Chen753c4422014-02-25 19:25:55 -0800121
Andre Eisenbach05f49542012-09-18 12:15:26 -0700122
123/** BT-HH callback structure. */
124typedef struct {
125 /** set to sizeof(BtHfCallbacks) */
126 size_t size;
127 bthh_connection_state_callback connection_state_cb;
128 bthh_hid_info_callback hid_info_cb;
129 bthh_protocol_mode_callback protocol_mode_cb;
130 bthh_idle_time_callback idle_time_cb;
131 bthh_get_report_callback get_report_cb;
132 bthh_virtual_unplug_callback virtual_unplug_cb;
Mike J. Chen753c4422014-02-25 19:25:55 -0800133 bthh_handshake_callback handshake_cb;
Andre Eisenbach05f49542012-09-18 12:15:26 -0700134
135} bthh_callbacks_t;
136
137
138
139/** Represents the standard BT-HH interface. */
140typedef struct {
141
142 /** set to sizeof(BtHhInterface) */
143 size_t size;
144
145 /**
146 * Register the BtHh callbacks
147 */
148 bt_status_t (*init)( bthh_callbacks_t* callbacks );
149
150 /** connect to hid device */
Jakub Pawlowskidb4c12a2017-06-24 17:33:20 -0700151 bt_status_t (*connect)( RawAddress *bd_addr);
Andre Eisenbach05f49542012-09-18 12:15:26 -0700152
153 /** dis-connect from hid device */
Jakub Pawlowskidb4c12a2017-06-24 17:33:20 -0700154 bt_status_t (*disconnect)( RawAddress *bd_addr );
Andre Eisenbach05f49542012-09-18 12:15:26 -0700155
156 /** Virtual UnPlug (VUP) the specified HID device */
Jakub Pawlowskidb4c12a2017-06-24 17:33:20 -0700157 bt_status_t (*virtual_unplug)(RawAddress *bd_addr);
Andre Eisenbach05f49542012-09-18 12:15:26 -0700158
159 /** Set the HID device descriptor for the specified HID device. */
Jakub Pawlowskidb4c12a2017-06-24 17:33:20 -0700160 bt_status_t (*set_info)(RawAddress *bd_addr, bthh_hid_info_t hid_info );
Andre Eisenbach05f49542012-09-18 12:15:26 -0700161
162 /** Get the HID proto mode. */
Jakub Pawlowskidb4c12a2017-06-24 17:33:20 -0700163 bt_status_t (*get_protocol) (RawAddress *bd_addr, bthh_protocol_mode_t protocolMode);
Andre Eisenbach05f49542012-09-18 12:15:26 -0700164
165 /** Set the HID proto mode. */
Jakub Pawlowskidb4c12a2017-06-24 17:33:20 -0700166 bt_status_t (*set_protocol)(RawAddress *bd_addr, bthh_protocol_mode_t protocolMode);
Andre Eisenbach05f49542012-09-18 12:15:26 -0700167
Hemant Gupta9ec149f2013-07-30 16:13:46 +0530168 /** Get the HID Idle Time */
Jakub Pawlowskidb4c12a2017-06-24 17:33:20 -0700169 bt_status_t (*get_idle_time)(RawAddress *bd_addr);
Hemant Gupta9ec149f2013-07-30 16:13:46 +0530170
171 /** Set the HID Idle Time */
Jakub Pawlowskidb4c12a2017-06-24 17:33:20 -0700172 bt_status_t (*set_idle_time)(RawAddress *bd_addr, uint8_t idleTime);
Hemant Gupta9ec149f2013-07-30 16:13:46 +0530173
Andre Eisenbach05f49542012-09-18 12:15:26 -0700174 /** Send a GET_REPORT to HID device. */
Jakub Pawlowskidb4c12a2017-06-24 17:33:20 -0700175 bt_status_t (*get_report)(RawAddress *bd_addr, bthh_report_type_t reportType, uint8_t reportId, int bufferSize);
Andre Eisenbach05f49542012-09-18 12:15:26 -0700176
177 /** Send a SET_REPORT to HID device. */
Jakub Pawlowskidb4c12a2017-06-24 17:33:20 -0700178 bt_status_t (*set_report)(RawAddress *bd_addr, bthh_report_type_t reportType, char* report);
Andre Eisenbach05f49542012-09-18 12:15:26 -0700179
180 /** Send data to HID device. */
Jakub Pawlowskidb4c12a2017-06-24 17:33:20 -0700181 bt_status_t (*send_data)(RawAddress *bd_addr, char* data);
Andre Eisenbach05f49542012-09-18 12:15:26 -0700182
Hemant Gupta9ec149f2013-07-30 16:13:46 +0530183 /** Closes the interface. */
Andre Eisenbach05f49542012-09-18 12:15:26 -0700184 void (*cleanup)( void );
185
186} bthh_interface_t;
187__END_DECLS
188
189#endif /* ANDROID_INCLUDE_BT_HH_H */
190
191