1 /******************************************************************************
2  *
3  *  Copyright (C) 2016 The Android Open Source Project
4  *  Copyright (C) 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  *  This file contains BTA HID Device internal definitions
22  *
23  ******************************************************************************/
24 #ifndef BTA_HD_INT_H
25 #define BTA_HD_INT_H
26 
27 #include "bta/bta_hd_api.h"
28 #include "bta/bta_sys.h"
29 #include "stack/hiddefs.h"
30 
31 enum {
32     BTA_HD_API_REGISTER_APP_EVT = BTA_SYS_EVT_START(BTA_ID_HD),
33     BTA_HD_API_UNREGISTER_APP_EVT,
34     BTA_HD_API_CONNECT_EVT,
35     BTA_HD_API_DISCONNECT_EVT,
36     BTA_HD_API_ADD_DEVICE_EVT,
37     BTA_HD_API_REMOVE_DEVICE_EVT,
38     BTA_HD_API_SEND_REPORT_EVT,
39     BTA_HD_API_REPORT_ERROR_EVT,
40     BTA_HD_API_VC_UNPLUG_EVT,
41     BTA_HD_INT_OPEN_EVT,
42     BTA_HD_INT_CLOSE_EVT,
43     BTA_HD_INT_INTR_DATA_EVT,
44     BTA_HD_INT_GET_REPORT_EVT,
45     BTA_HD_INT_SET_REPORT_EVT,
46     BTA_HD_INT_SET_PROTOCOL_EVT,
47     BTA_HD_INT_VC_UNPLUG_EVT,
48     BTA_HD_INT_SUSPEND_EVT,
49     BTA_HD_INT_EXIT_SUSPEND_EVT,
50     /* handled outside state machine */
51     BTA_HD_API_ENABLE_EVT,
52     BTA_HD_API_DISABLE_EVT
53 };
54 typedef uint16_t tBTA_HD_INT_EVT;
55 #define BTA_HD_INVALID_EVT (BTA_HD_API_DISABLE_EVT + 1)
56 typedef struct {
57     BT_HDR hdr;
58     tBTA_HD_CBACK *p_cback;
59 } tBTA_HD_API_ENABLE;
60 #define BTA_HD_APP_NAME_LEN 50
61 #define BTA_HD_APP_DESCRIPTION_LEN 50
62 #define BTA_HD_APP_PROVIDER_LEN 50
63 #define BTA_HD_APP_DESCRIPTOR_LEN 2048
64 #define BTA_HD_STATE_DISABLED 0x00
65 #define BTA_HD_STATE_ENABLED 0x01
66 #define BTA_HD_STATE_IDLE 0x02
67 #define BTA_HD_STATE_CONNECTED 0x03
68 #define BTA_HD_STATE_DISABLING 0x04
69 #define BTA_HD_STATE_REMOVING 0x05
70 typedef struct {
71     BT_HDR hdr;
72     char name[BTA_HD_APP_NAME_LEN + 1];
73     char description[BTA_HD_APP_DESCRIPTION_LEN + 1];
74     char provider[BTA_HD_APP_PROVIDER_LEN + 1];
75     uint8_t subclass;
76     uint16_t d_len;
77     uint8_t d_data[BTA_HD_APP_DESCRIPTOR_LEN];
78     tBTA_HD_QOS_INFO in_qos;
79     tBTA_HD_QOS_INFO out_qos;
80 } tBTA_HD_REGISTER_APP;
81 
82 #define BTA_HD_REPORT_LEN HID_DEV_MTU_SIZE
83 
84 typedef struct {
85     BT_HDR hdr;
86     bool use_intr;
87     uint8_t type;
88     uint8_t id;
89     uint16_t len;
90     uint8_t data[BTA_HD_REPORT_LEN];
91 } tBTA_HD_SEND_REPORT;
92 
93 typedef struct {
94     BT_HDR hdr;
95     BD_ADDR addr;
96 } tBTA_HD_DEVICE_CTRL;
97 
98 typedef struct {
99     BT_HDR hdr;
100     uint8_t error;
101 } tBTA_HD_REPORT_ERR;
102 
103 /* union of all event data types */
104 typedef union {
105     BT_HDR hdr;
106     tBTA_HD_API_ENABLE api_enable;
107     tBTA_HD_REGISTER_APP register_app;
108     tBTA_HD_SEND_REPORT send_report;
109     tBTA_HD_DEVICE_CTRL device_ctrl;
110     tBTA_HD_REPORT_ERR report_err;
111 } tBTA_HD_DATA;
112 
113 typedef struct {
114     BT_HDR hdr;
115     BD_ADDR addr;
116     uint32_t data;
117     BT_HDR *p_data;
118 } tBTA_HD_CBACK_DATA;
119 
120 /******************************************************************************
121  * Main Control Block
122  ******************************************************************************/
123 typedef struct {
124     tBTA_HD_CBACK *p_cback;
125     uint32_t sdp_handle;
126     uint8_t trace_level;
127     uint8_t state;
128     BD_ADDR bd_addr;
129     bool use_report_id;
130     bool boot_mode;
131     bool vc_unplug;
132     bool disable_w4_close;
133 } tBTA_HD_CB;
134 
135 #if BTA_DYNAMIC_MEMORY == FALSE
136 extern tBTA_HD_CB bta_hd_cb;
137 #else
138 extern tBTA_HD_CB *bta_hd_cb_ptr;
139 #define bta_hd_cb (*bta_hd_cb_ptr)
140 #endif
141 
142 /*****************************************************************************
143  *  Function prototypes
144  ****************************************************************************/
145 extern bool bta_hd_hdl_event(BT_HDR *p_msg);
146 extern void bta_hd_api_enable(tBTA_HD_DATA *p_data);
147 extern void bta_hd_api_disable(void);
148 extern void bta_hd_register_act(tBTA_HD_DATA *p_data);
149 extern void bta_hd_unregister_act(tBTA_HD_DATA *p_data);
150 extern void bta_hd_unregister2_act(tBTA_HD_DATA *p_data);
151 extern void bta_hd_connect_act(tBTA_HD_DATA *p_data);
152 extern void bta_hd_disconnect_act(tBTA_HD_DATA *p_data);
153 extern void bta_hd_add_device_act(tBTA_HD_DATA *p_data);
154 extern void bta_hd_remove_device_act(tBTA_HD_DATA *p_data);
155 extern void bta_hd_send_report_act(tBTA_HD_DATA *p_data);
156 extern void bta_hd_report_error_act(tBTA_HD_DATA *p_data);
157 extern void bta_hd_vc_unplug_act(tBTA_HD_DATA *p_data);
158 extern void bta_hd_open_act(tBTA_HD_DATA *p_data);
159 extern void bta_hd_close_act(tBTA_HD_DATA *p_data);
160 extern void bta_hd_intr_data_act(tBTA_HD_DATA *p_data);
161 extern void bta_hd_get_report_act(tBTA_HD_DATA *p_data);
162 extern void bta_hd_set_report_act(tBTA_HD_DATA *p_data);
163 extern void bta_hd_set_protocol_act(tBTA_HD_DATA *p_data);
164 extern void bta_hd_vc_unplug_done_act(tBTA_HD_DATA *p_data);
165 extern void bta_hd_suspend_act(tBTA_HD_DATA *p_data);
166 extern void bta_hd_exit_suspend_act(tBTA_HD_DATA *p_data);
167 
168 #endif
169