• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  *  Copyright 2002-2012 Broadcom Corporation
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at:
8  *
9  *  http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  ******************************************************************************/
18 
19 /******************************************************************************
20  *
21  *  This file contains HID protocol definitions
22  *
23  ******************************************************************************/
24 
25 #ifndef HIDDEFS_H
26 #define HIDDEFS_H
27 
28 #include <base/strings/stringprintf.h>
29 
30 #include <cstring>
31 
32 #include "stack/include/sdp_api.h"
33 /*
34  * tHID_STATUS: HID result codes, returned by HID and device and host functions.
35 */
36 typedef enum : uint8_t {
37   HID_SUCCESS = 0,
38   HID_ERR_NOT_REGISTERED,
39   HID_ERR_ALREADY_REGISTERED,
40   HID_ERR_NO_RESOURCES,
41   HID_ERR_NO_CONNECTION,
42   HID_ERR_INVALID_PARAM,
43   HID_ERR_UNSUPPORTED,
44   HID_ERR_UNKNOWN_COMMAND,
45   HID_ERR_CONGESTED,
46   HID_ERR_CONN_IN_PROCESS,
47   HID_ERR_ALREADY_CONN,
48   HID_ERR_DISCONNECTING,
49   HID_ERR_SET_CONNABLE_FAIL,
50   /* Device specific error codes */
51   HID_ERR_HOST_UNKNOWN,
52   HID_ERR_L2CAP_FAILED,
53   HID_ERR_AUTH_FAILED,
54   HID_ERR_SDP_BUSY,
55   HID_ERR_GATT,
56 
57   HID_ERR_INVALID = 0xFF
58 } tHID_STATUS;
59 
60 #define CASE_RETURN_TEXT(code) \
61   case code:                   \
62     return #code
63 
hid_status_text(const tHID_STATUS & status)64 inline std::string hid_status_text(const tHID_STATUS& status) {
65   switch (status) {
66     CASE_RETURN_TEXT(HID_SUCCESS);
67     CASE_RETURN_TEXT(HID_ERR_NOT_REGISTERED);
68     CASE_RETURN_TEXT(HID_ERR_ALREADY_REGISTERED);
69     CASE_RETURN_TEXT(HID_ERR_NO_RESOURCES);
70     CASE_RETURN_TEXT(HID_ERR_NO_CONNECTION);
71     CASE_RETURN_TEXT(HID_ERR_INVALID_PARAM);
72     CASE_RETURN_TEXT(HID_ERR_UNSUPPORTED);
73     CASE_RETURN_TEXT(HID_ERR_UNKNOWN_COMMAND);
74     CASE_RETURN_TEXT(HID_ERR_CONGESTED);
75     CASE_RETURN_TEXT(HID_ERR_CONN_IN_PROCESS);
76     CASE_RETURN_TEXT(HID_ERR_ALREADY_CONN);
77     CASE_RETURN_TEXT(HID_ERR_DISCONNECTING);
78     CASE_RETURN_TEXT(HID_ERR_SET_CONNABLE_FAIL);
79     CASE_RETURN_TEXT(HID_ERR_HOST_UNKNOWN);
80     CASE_RETURN_TEXT(HID_ERR_L2CAP_FAILED);
81     CASE_RETURN_TEXT(HID_ERR_AUTH_FAILED);
82     CASE_RETURN_TEXT(HID_ERR_SDP_BUSY);
83     CASE_RETURN_TEXT(HID_ERR_GATT);
84     CASE_RETURN_TEXT(HID_ERR_INVALID);
85     default:
86       return base::StringPrintf("UNKNOWN[%hhu]", status);
87   }
88 }
89 #undef CASE_RETURN_TEXT
90 
91 #define HID_L2CAP_CONN_FAIL \
92   (0x0100)                          /* Connection Attempt was made but failed */
93 #define HID_L2CAP_REQ_FAIL (0x0200) /* L2CAP_ConnectReq API failed */
94 #define HID_L2CAP_CFG_FAIL \
95   (0x0400) /* L2CAP Configuration was rejected by peer */
96 
97 /* Define the HID transaction types
98 */
99 #define HID_TRANS_HANDSHAKE (0)
100 #define HID_TRANS_CONTROL (1)
101 #define HID_TRANS_GET_REPORT (4)
102 #define HID_TRANS_SET_REPORT (5)
103 #define HID_TRANS_GET_PROTOCOL (6)
104 #define HID_TRANS_SET_PROTOCOL (7)
105 #define HID_TRANS_GET_IDLE (8)
106 #define HID_TRANS_SET_IDLE (9)
107 #define HID_TRANS_DATA (10)
108 #define HID_TRANS_DATAC (11)
109 
110 #define HID_GET_TRANS_FROM_HDR(x) (((x) >> 4) & 0x0f)
111 #define HID_GET_PARAM_FROM_HDR(x) ((x)&0x0f)
112 #define HID_BUILD_HDR(t, p) (uint8_t)(((t) << 4) | ((p)&0x0f))
113 
114 /* Parameters for Handshake
115 */
116 #define HID_PAR_HANDSHAKE_RSP_SUCCESS (0)
117 #define HID_PAR_HANDSHAKE_RSP_NOT_READY (1)
118 #define HID_PAR_HANDSHAKE_RSP_ERR_INVALID_REP_ID (2)
119 #define HID_PAR_HANDSHAKE_RSP_ERR_UNSUPPORTED_REQ (3)
120 #define HID_PAR_HANDSHAKE_RSP_ERR_INVALID_PARAM (4)
121 #define HID_PAR_HANDSHAKE_RSP_ERR_UNKNOWN (14)
122 #define HID_PAR_HANDSHAKE_RSP_ERR_FATAL (15)
123 
124 /* Parameters for Control
125 */
126 #define HID_PAR_CONTROL_NOP (0)
127 #define HID_PAR_CONTROL_HARD_RESET (1)
128 #define HID_PAR_CONTROL_SOFT_RESET (2)
129 #define HID_PAR_CONTROL_SUSPEND (3)
130 #define HID_PAR_CONTROL_EXIT_SUSPEND (4)
131 #define HID_PAR_CONTROL_VIRTUAL_CABLE_UNPLUG (5)
132 
133 /* Different report types in get, set, data
134 */
135 #define HID_PAR_REP_TYPE_MASK (0x03)
136 #define HID_PAR_REP_TYPE_OTHER (0x00)
137 #define HID_PAR_REP_TYPE_INPUT (0x01)
138 #define HID_PAR_REP_TYPE_OUTPUT (0x02)
139 #define HID_PAR_REP_TYPE_FEATURE (0x03)
140 
141 /* Parameters for Get Report
142 */
143 
144 /* Buffer size in two bytes after Report ID */
145 #define HID_PAR_GET_REP_BUFSIZE_FOLLOWS (0x08)
146 
147 /* Parameters for Protocol Type
148 */
149 #define HID_PAR_PROTOCOL_MASK (0x01)
150 #define HID_PAR_PROTOCOL_REPORT (0x01)
151 #define HID_PAR_PROTOCOL_BOOT_MODE (0x00)
152 
153 #define HID_PAR_REP_TYPE_MASK (0x03)
154 
155 /* Descriptor types in the SDP record
156 */
157 #define HID_SDP_DESCRIPTOR_REPORT (0x22)
158 #define HID_SDP_DESCRIPTOR_PHYSICAL (0x23)
159 
160 typedef struct desc_info {
161   uint16_t dl_len;
162   uint8_t* dsc_list;
163 } tHID_DEV_DSCP_INFO;
164 
165 #define HID_SSR_PARAM_INVALID 0xffff
166 
167 #define HIDD_APP_DESCRIPTOR_LEN 2048
168 
169 typedef struct sdp_info {
170   char svc_name[HID_MAX_SVC_NAME_LEN];   /*Service Name */
171   char svc_descr[HID_MAX_SVC_DESCR_LEN]; /*Service Description*/
172   char prov_name[HID_MAX_PROV_NAME_LEN]; /*Provider Name.*/
173   uint16_t rel_num;                      /*Release Number */
174   uint16_t hpars_ver;                    /*HID Parser Version.*/
175   uint16_t ssr_max_latency;              /* HIDSSRHostMaxLatency value, if
176                                             HID_SSR_PARAM_INVALID not used*/
177   uint16_t
178       ssr_min_tout;  /* HIDSSRHostMinTimeout value, if HID_SSR_PARAM_INVALID not
179                         used* */
180   uint8_t sub_class; /*Device Subclass.*/
181   uint8_t ctry_code; /*Country Code.*/
182   uint16_t sup_timeout; /* Supervisory Timeout */
183 
184   tHID_DEV_DSCP_INFO dscp_info; /* Descriptor list and Report list to be set in
185                                   the SDP record.
186                                   This parameter is used if
187                                   HID_DEV_USE_GLB_SDP_REC is set to false.*/
188   tSDP_DISC_REC* p_sdp_layer_rec;
189 } tHID_DEV_SDP_INFO;
190 
191 #endif
192