Initial code for libbt-oal
[platform/core/connectivity/bluetooth-frwk.git] / hardware / bt_hh.h
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
24 #define BTHH_MAX_DSC_LEN   884
25
26 /* HH connection states */
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
38 } bthh_connection_state_t;
39
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 callback */
51         BTHH_ERR_DB_FULL,             /* device database full error, used  */
52         BTHH_ERR_TOD_UNSPT,           /* type of device not supported */
53         BTHH_ERR_NO_RES,              /* out of system resources */
54         BTHH_ERR_AUTH_FAILED,         /* authentication fail */
55         BTHH_ERR_HDL
56 } bthh_status_t;
57
58 /* Protocol modes */
59 typedef enum {
60         BTHH_REPORT_MODE       = 0x00,
61         BTHH_BOOT_MODE         = 0x01,
62         BTHH_UNSUPPORTED_MODE  = 0xff
63 } bthh_protocol_mode_t;
64
65 /* Report types */
66 typedef enum {
67         BTHH_INPUT_REPORT      = 1,
68         BTHH_OUTPUT_REPORT,
69         BTHH_FEATURE_REPORT
70 } bthh_report_type_t;
71
72 typedef struct {
73         int         attr_mask;
74         uint8_t     sub_class;
75         uint8_t     app_id;
76         int         vendor_id;
77         int         product_id;
78         int         version;
79         uint8_t     ctry_code;
80         int         dl_len;
81         uint8_t     dsc_list[BTHH_MAX_DSC_LEN];
82 } bthh_hid_info_t;
83
84 /** Callback for connection state change.
85  *  state will have one of the values from bthh_connection_state_t
86  */
87 typedef void (*bthh_connection_state_callback)(bt_bdaddr_t *bd_addr, bthh_connection_state_t state);
88
89 /** Callback for vitual unplug api.
90  *  the status of the vitual unplug
91  */
92 typedef void (*bthh_virtual_unplug_callback)(bt_bdaddr_t *bd_addr, bthh_status_t hh_status);
93
94 /** Callback for get hid info
95  *  hid_info will contain attr_mask, sub_class, app_id, vendor_id, product_id, version, ctry_code, len
96  */
97 typedef void (*bthh_hid_info_callback)(bt_bdaddr_t *bd_addr, bthh_hid_info_t *hid_info);
98
99 /** Callback for get protocol api.
100  *  the protocol mode is one of the value from bthh_protocol_mode_t
101  */
102 typedef void (*bthh_protocol_mode_callback)(bt_bdaddr_t *bd_addr, bthh_status_t hh_status, bthh_protocol_mode_t mode);
103
104 /** Callback for get/set_idle_time api.
105  */
106 typedef void (*bthh_idle_time_callback)(bt_bdaddr_t *bd_addr, bthh_status_t hh_status, int idle_rate);
107
108 /** Callback for get report api.
109  *  if staus is ok rpt_data contains the report data
110  */
111 typedef void (*bthh_get_report_callback)(bt_bdaddr_t *bd_addr, bthh_status_t hh_status, uint8_t* rpt_data, int rpt_size);
112
113 /** Callback for set_report/set_protocol api and if error
114  *  occurs for get_report/get_protocol api.
115  */
116 typedef void (*bthh_handshake_callback)(bt_bdaddr_t *bd_addr, bthh_status_t hh_status);
117
118 /** BT-HH callback structure. */
119 typedef struct {
120         /** set to sizeof(BtHfCallbacks) */
121         size_t      size;
122         bthh_connection_state_callback  connection_state_cb;
123         bthh_hid_info_callback          hid_info_cb;
124         bthh_protocol_mode_callback     protocol_mode_cb;
125         bthh_idle_time_callback         idle_time_cb;
126         bthh_get_report_callback        get_report_cb;
127         bthh_virtual_unplug_callback    virtual_unplug_cb;
128         bthh_handshake_callback         handshake_cb;
129 } bthh_callbacks_t;
130
131 /** Represents the standard BT-HH interface. */
132 typedef struct {
133
134         /** set to sizeof(BtHhInterface) */
135         size_t          size;
136
137         /**
138          * Register the BtHh callbacks
139          */
140         bt_status_t (*init)(bthh_callbacks_t* callbacks);
141
142         /** connect to hid device */
143         bt_status_t (*connect)(bt_bdaddr_t *bd_addr);
144
145         /** dis-connect from hid device */
146         bt_status_t (*disconnect)(bt_bdaddr_t *bd_addr);
147
148         /** Virtual UnPlug (VUP) the specified HID device */
149         bt_status_t (*virtual_unplug)(bt_bdaddr_t *bd_addr);
150
151         /** Set the HID device descriptor for the specified HID device. */
152         bt_status_t (*set_info)(bt_bdaddr_t *bd_addr, bthh_hid_info_t *hid_info);
153
154         /** Get the HID proto mode. */
155         bt_status_t (*get_protocol) (bt_bdaddr_t *bd_addr, bthh_protocol_mode_t protocolMode);
156
157         /** Set the HID proto mode. */
158         bt_status_t (*set_protocol)(bt_bdaddr_t *bd_addr, bthh_protocol_mode_t protocolMode);
159
160         /** Send a GET_REPORT to HID device. */
161         bt_status_t (*get_report)(bt_bdaddr_t *bd_addr, bthh_report_type_t reportType, uint8_t reportId, int bufferSize);
162
163         /** Send a SET_REPORT to HID device. */
164         bt_status_t (*set_report)(bt_bdaddr_t *bd_addr, bthh_report_type_t reportType, char* report);
165
166         /** Send data to HID device. */
167         bt_status_t (*send_data)(bt_bdaddr_t *bd_addr, char* data);
168
169         /** Closes the interface. */
170         void (*cleanup)(void);
171
172 } bthh_interface_t;
173 __END_DECLS
174
175 #endif /* ANDROID_INCLUDE_BT_HH_H */