1 /******************************************************************************
2  *
3  *  Copyright 2005-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 the HID host main functions and state machine.
22  *
23  ******************************************************************************/
24 
25 #include "bt_target.h"
26 
27 #if (BTA_HH_INCLUDED == TRUE)
28 
29 #include <string.h>
30 
31 #include "bt_common.h"
32 #include "bta_hh_api.h"
33 #include "bta_hh_int.h"
34 
35 /*****************************************************************************
36  * Constants and types
37  ****************************************************************************/
38 
39 /* state machine action enumeration list */
40 enum {
41   BTA_HH_API_DISC_ACT, /* HID host process API close action    */
42   BTA_HH_OPEN_ACT,     /* HID host process BTA_HH_EVT_OPEN     */
43   BTA_HH_CLOSE_ACT,    /* HID host process BTA_HH_EVT_CLOSE    */
44   BTA_HH_DATA_ACT,     /* HID host receive data report         */
45   BTA_HH_CTRL_DAT_ACT,
46   BTA_HH_HANDSK_ACT,
47   BTA_HH_START_SDP, /* HID host inquery                     */
48   BTA_HH_SDP_CMPL,
49   BTA_HH_WRITE_DEV_ACT,
50   BTA_HH_GET_DSCP_ACT,
51   BTA_HH_MAINT_DEV_ACT,
52   BTA_HH_OPEN_CMPL_ACT,
53   BTA_HH_OPEN_FAILURE,
54 #if (BTA_HH_LE_INCLUDED == TRUE)
55   BTA_HH_GATT_CLOSE,
56   BTA_HH_LE_OPEN_FAIL,
57   BTA_HH_GATT_OPEN,
58   BTA_HH_START_SEC,
59   BTA_HH_SEC_CMPL,
60   BTA_HH_GATT_ENC_CMPL,
61 #endif
62   BTA_HH_NUM_ACTIONS
63 };
64 
65 #define BTA_HH_IGNORE BTA_HH_NUM_ACTIONS
66 
67 /* type for action functions */
68 typedef void (*tBTA_HH_ACTION)(tBTA_HH_DEV_CB* p_cb, tBTA_HH_DATA* p_data);
69 
70 /* action functions */
71 const tBTA_HH_ACTION bta_hh_action[] = {
72     bta_hh_api_disc_act, bta_hh_open_act, bta_hh_close_act, bta_hh_data_act,
73     bta_hh_ctrl_dat_act, bta_hh_handsk_act, bta_hh_start_sdp, bta_hh_sdp_cmpl,
74     bta_hh_write_dev_act, bta_hh_get_dscp_act, bta_hh_maint_dev_act,
75     bta_hh_open_cmpl_act, bta_hh_open_failure
76 #if (BTA_HH_LE_INCLUDED == TRUE)
77     ,
78     bta_hh_gatt_close, bta_hh_le_open_fail, bta_hh_gatt_open,
79     bta_hh_start_security, bta_hh_security_cmpl, bta_hh_le_notify_enc_cmpl
80 #endif
81 };
82 
83 /* state table information */
84 #define BTA_HH_ACTION 0     /* position of action */
85 #define BTA_HH_NEXT_STATE 1 /* position of next state */
86 #define BTA_HH_NUM_COLS 2   /* number of columns */
87 
88 /* state table for idle state */
89 const uint8_t bta_hh_st_idle[][BTA_HH_NUM_COLS] = {
90     /* Event                          Action                    Next state */
91     /* BTA_HH_API_OPEN_EVT      */ {BTA_HH_START_SDP, BTA_HH_W4_CONN_ST},
92     /* BTA_HH_API_CLOSE_EVT     */ {BTA_HH_IGNORE, BTA_HH_IDLE_ST},
93     /* BTA_HH_INT_OPEN_EVT      */ {BTA_HH_OPEN_ACT, BTA_HH_W4_CONN_ST},
94     /* BTA_HH_INT_CLOSE_EVT     */ {BTA_HH_CLOSE_ACT, BTA_HH_IDLE_ST},
95     /* BTA_HH_INT_DATA_EVT      */ {BTA_HH_IGNORE, BTA_HH_IDLE_ST},
96     /* BTA_HH_INT_CTRL_DATA     */ {BTA_HH_IGNORE, BTA_HH_IDLE_ST},
97     /* BTA_HH_INT_HANDSK_EVT    */ {BTA_HH_IGNORE, BTA_HH_IDLE_ST},
98     /* BTA_HH_SDP_CMPL_EVT      */ {BTA_HH_IGNORE, BTA_HH_IDLE_ST},
99     /* BTA_HH_API_WRITE_DEV_EVT */ {BTA_HH_IGNORE, BTA_HH_IDLE_ST},
100     /* BTA_HH_API_GET_DSCP_EVT  */ {BTA_HH_IGNORE, BTA_HH_IDLE_ST},
101     /* BTA_HH_API_MAINT_DEV_EVT */ {BTA_HH_MAINT_DEV_ACT, BTA_HH_IDLE_ST},
102     /* BTA_HH_OPEN_CMPL_EVT        */ {BTA_HH_OPEN_CMPL_ACT, BTA_HH_CONN_ST}
103 #if (BTA_HH_LE_INCLUDED == TRUE)
104     /* BTA_HH_GATT_CLOSE_EVT    */,
105     {BTA_HH_IGNORE, BTA_HH_IDLE_ST}
106     /* BTA_HH_GATT_OPEN_EVT    */,
107     {BTA_HH_GATT_OPEN, BTA_HH_W4_CONN_ST}
108     /* BTA_HH_START_ENC_EVT    */,
109     {BTA_HH_IGNORE, BTA_HH_IDLE_ST}
110     /* BTA_HH_ENC_CMPL_EVT     */,
111     {BTA_HH_IGNORE, BTA_HH_IDLE_ST}
112     /* BTA_HH_GATT_ENC_CMPL_EVT */,
113     {BTA_HH_IGNORE, BTA_HH_IDLE_ST}
114 #endif
115 
116 };
117 
118 const uint8_t bta_hh_st_w4_conn[][BTA_HH_NUM_COLS] = {
119     /* Event                          Action                 Next state */
120     /* BTA_HH_API_OPEN_EVT      */ {BTA_HH_IGNORE, BTA_HH_W4_CONN_ST},
121     /* BTA_HH_API_CLOSE_EVT     */ {BTA_HH_IGNORE, BTA_HH_IDLE_ST},
122     /* BTA_HH_INT_OPEN_EVT      */ {BTA_HH_OPEN_ACT, BTA_HH_W4_CONN_ST},
123     /* BTA_HH_INT_CLOSE_EVT     */ {BTA_HH_OPEN_FAILURE, BTA_HH_IDLE_ST},
124     /* BTA_HH_INT_DATA_EVT      */ {BTA_HH_IGNORE, BTA_HH_W4_CONN_ST},
125     /* BTA_HH_INT_CTRL_DATA     */ {BTA_HH_IGNORE, BTA_HH_W4_CONN_ST},
126     /* BTA_HH_INT_HANDSK_EVT    */ {BTA_HH_IGNORE, BTA_HH_W4_CONN_ST},
127     /* BTA_HH_SDP_CMPL_EVT      */ {BTA_HH_SDP_CMPL, BTA_HH_W4_CONN_ST},
128     /* BTA_HH_API_WRITE_DEV_EVT */ {BTA_HH_WRITE_DEV_ACT, BTA_HH_W4_CONN_ST},
129     /* BTA_HH_API_GET_DSCP_EVT  */ {BTA_HH_IGNORE, BTA_HH_W4_CONN_ST},
130     /* BTA_HH_API_MAINT_DEV_EVT */ {BTA_HH_MAINT_DEV_ACT, BTA_HH_IDLE_ST},
131     /* BTA_HH_OPEN_CMPL_EVT     */ {BTA_HH_OPEN_CMPL_ACT, BTA_HH_CONN_ST}
132 #if (BTA_HH_LE_INCLUDED == TRUE)
133     /* BTA_HH_GATT_CLOSE_EVT    */,
134     {BTA_HH_LE_OPEN_FAIL, BTA_HH_IDLE_ST}
135     /* BTA_HH_GATT_OPEN_EVT    */,
136     {BTA_HH_GATT_OPEN, BTA_HH_W4_CONN_ST}
137     /* BTA_HH_START_ENC_EVT    */,
138     {BTA_HH_START_SEC, BTA_HH_W4_SEC}
139     /* BTA_HH_ENC_CMPL_EVT     */,
140     {BTA_HH_IGNORE, BTA_HH_W4_CONN_ST}
141     /* BTA_HH_GATT_ENC_CMPL_EVT */,
142     {BTA_HH_IGNORE, BTA_HH_W4_CONN_ST}
143 #endif
144 };
145 
146 const uint8_t bta_hh_st_connected[][BTA_HH_NUM_COLS] = {
147     /* Event                          Action                 Next state */
148     /* BTA_HH_API_OPEN_EVT      */ {BTA_HH_IGNORE, BTA_HH_CONN_ST},
149     /* BTA_HH_API_CLOSE_EVT     */ {BTA_HH_API_DISC_ACT, BTA_HH_CONN_ST},
150     /* BTA_HH_INT_OPEN_EVT      */ {BTA_HH_OPEN_ACT, BTA_HH_CONN_ST},
151     /* BTA_HH_INT_CLOSE_EVT     */ {BTA_HH_CLOSE_ACT, BTA_HH_IDLE_ST},
152     /* BTA_HH_INT_DATA_EVT      */ {BTA_HH_DATA_ACT, BTA_HH_CONN_ST},
153     /* BTA_HH_INT_CTRL_DATA     */ {BTA_HH_CTRL_DAT_ACT, BTA_HH_CONN_ST},
154     /* BTA_HH_INT_HANDSK_EVT    */ {BTA_HH_HANDSK_ACT, BTA_HH_CONN_ST},
155     /* BTA_HH_SDP_CMPL_EVT      */ {BTA_HH_IGNORE, BTA_HH_CONN_ST},
156     /* BTA_HH_API_WRITE_DEV_EVT */ {BTA_HH_WRITE_DEV_ACT, BTA_HH_CONN_ST},
157     /* BTA_HH_API_GET_DSCP_EVT  */ {BTA_HH_GET_DSCP_ACT, BTA_HH_CONN_ST},
158     /* BTA_HH_API_MAINT_DEV_EVT */ {BTA_HH_MAINT_DEV_ACT, BTA_HH_CONN_ST},
159     /* BTA_HH_OPEN_CMPL_EVT        */ {BTA_HH_IGNORE, BTA_HH_CONN_ST}
160 #if (BTA_HH_LE_INCLUDED == TRUE)
161     /* BTA_HH_GATT_CLOSE_EVT    */,
162     {BTA_HH_GATT_CLOSE, BTA_HH_IDLE_ST}
163     /* BTA_HH_GATT_OPEN_EVT    */,
164     {BTA_HH_IGNORE, BTA_HH_CONN_ST}
165     /* BTA_HH_START_ENC_EVT    */,
166     {BTA_HH_IGNORE, BTA_HH_CONN_ST}
167     /* BTA_HH_ENC_CMPL_EVT     */,
168     {BTA_HH_IGNORE, BTA_HH_CONN_ST}
169     /* BTA_HH_GATT_ENC_CMPL_EVT */,
170     {BTA_HH_IGNORE, BTA_HH_CONN_ST}
171 #endif
172 };
173 #if (BTA_HH_LE_INCLUDED == TRUE)
174 const uint8_t bta_hh_st_w4_sec[][BTA_HH_NUM_COLS] = {
175     /* Event                          Action                 Next state */
176     /* BTA_HH_API_OPEN_EVT      */ {BTA_HH_IGNORE, BTA_HH_W4_SEC},
177     /* BTA_HH_API_CLOSE_EVT     */ {BTA_HH_API_DISC_ACT, BTA_HH_W4_SEC},
178     /* BTA_HH_INT_OPEN_EVT      */ {BTA_HH_IGNORE, BTA_HH_W4_SEC},
179     /* BTA_HH_INT_CLOSE_EVT     */ {BTA_HH_OPEN_FAILURE, BTA_HH_IDLE_ST},
180     /* BTA_HH_INT_DATA_EVT      */ {BTA_HH_IGNORE, BTA_HH_W4_SEC},
181     /* BTA_HH_INT_CTRL_DATA     */ {BTA_HH_IGNORE, BTA_HH_W4_SEC},
182     /* BTA_HH_INT_HANDSK_EVT    */ {BTA_HH_IGNORE, BTA_HH_W4_SEC},
183     /* BTA_HH_SDP_CMPL_EVT      */ {BTA_HH_IGNORE, BTA_HH_W4_SEC},
184     /* BTA_HH_API_WRITE_DEV_EVT */ {BTA_HH_IGNORE, BTA_HH_W4_SEC},
185     /* BTA_HH_API_GET_DSCP_EVT  */ {BTA_HH_IGNORE, BTA_HH_W4_SEC},
186     /* BTA_HH_API_MAINT_DEV_EVT */ {BTA_HH_MAINT_DEV_ACT, BTA_HH_W4_SEC},
187     /* BTA_HH_OPEN_CMPL_EVT     */ {BTA_HH_IGNORE, BTA_HH_W4_SEC},
188     /* BTA_HH_GATT_CLOSE_EVT    */ {BTA_HH_LE_OPEN_FAIL, BTA_HH_IDLE_ST},
189     /* BTA_HH_GATT_OPEN_EVT    */ {BTA_HH_IGNORE, BTA_HH_W4_SEC},
190     /* BTA_HH_START_ENC_EVT    */ {BTA_HH_IGNORE, BTA_HH_W4_SEC},
191     /* BTA_HH_ENC_CMPL_EVT     */ {BTA_HH_SEC_CMPL, BTA_HH_W4_CONN_ST},
192     /* BTA_HH_GATT_ENC_CMPL_EVT */ {BTA_HH_GATT_ENC_CMPL, BTA_HH_W4_SEC}};
193 #endif
194 
195 /* type for state table */
196 typedef const uint8_t (*tBTA_HH_ST_TBL)[BTA_HH_NUM_COLS];
197 
198 /* state table */
199 const tBTA_HH_ST_TBL bta_hh_st_tbl[] = {bta_hh_st_idle, bta_hh_st_w4_conn,
200                                         bta_hh_st_connected
201 #if (BTA_HH_LE_INCLUDED == TRUE)
202                                         ,
203                                         bta_hh_st_w4_sec
204 #endif
205 };
206 
207 /*****************************************************************************
208  * Global data
209  ****************************************************************************/
210 tBTA_HH_CB bta_hh_cb;
211 
212 /*****************************************************************************
213  * Static functions
214  ****************************************************************************/
215 #if (BTA_HH_DEBUG == TRUE)
216 static const char* bta_hh_evt_code(tBTA_HH_INT_EVT evt_code);
217 static const char* bta_hh_state_code(tBTA_HH_STATE state_code);
218 #endif
219 
220 /*******************************************************************************
221  *
222  * Function         bta_hh_sm_execute
223  *
224  * Description      State machine event handling function for HID Host
225  *
226  *
227  * Returns          void
228  *
229  ******************************************************************************/
bta_hh_sm_execute(tBTA_HH_DEV_CB * p_cb,uint16_t event,tBTA_HH_DATA * p_data)230 void bta_hh_sm_execute(tBTA_HH_DEV_CB* p_cb, uint16_t event,
231                        tBTA_HH_DATA* p_data) {
232   tBTA_HH_ST_TBL state_table;
233   uint8_t action;
234   tBTA_HH cback_data;
235   tBTA_HH_EVT cback_event = 0;
236 #if (BTA_HH_DEBUG == TRUE)
237   tBTA_HH_STATE in_state;
238   uint16_t debug_event = event;
239 #endif
240 
241   memset(&cback_data, 0, sizeof(tBTA_HH));
242 
243   /* handle exception, no valid control block was found */
244   if (!p_cb) {
245     /* BTA HH enabled already? otherwise ignore the event although it's bad*/
246     if (bta_hh_cb.p_cback != NULL) {
247       switch (event) {
248         /* no control block available for new connection */
249         case BTA_HH_API_OPEN_EVT:
250           cback_event = BTA_HH_OPEN_EVT;
251           /* build cback data */
252           cback_data.conn.bda = ((tBTA_HH_API_CONN*)p_data)->bd_addr;
253           cback_data.conn.status = BTA_HH_ERR_DB_FULL;
254           cback_data.conn.handle = BTA_HH_INVALID_HANDLE;
255           break;
256         /* DB full, BTA_HhAddDev */
257         case BTA_HH_API_MAINT_DEV_EVT:
258           cback_event = p_data->api_maintdev.sub_event;
259 
260           if (p_data->api_maintdev.sub_event == BTA_HH_ADD_DEV_EVT) {
261             cback_data.dev_info.bda = p_data->api_maintdev.bda;
262             cback_data.dev_info.status = BTA_HH_ERR_DB_FULL;
263             cback_data.dev_info.handle = BTA_HH_INVALID_HANDLE;
264           } else {
265             cback_data.dev_info.status = BTA_HH_ERR_HDL;
266             cback_data.dev_info.handle =
267                 (uint8_t)p_data->api_maintdev.hdr.layer_specific;
268           }
269           break;
270         case BTA_HH_API_WRITE_DEV_EVT:
271           cback_event = (p_data->api_sndcmd.t_type - BTA_HH_FST_BTE_TRANS_EVT) +
272                         BTA_HH_FST_TRANS_CB_EVT;
273           osi_free_and_reset((void**)&p_data->api_sndcmd.p_data);
274           if (p_data->api_sndcmd.t_type == HID_TRANS_SET_PROTOCOL ||
275               p_data->api_sndcmd.t_type == HID_TRANS_SET_REPORT ||
276               p_data->api_sndcmd.t_type == HID_TRANS_SET_IDLE) {
277             cback_data.dev_status.status = BTA_HH_ERR_HDL;
278             cback_data.dev_status.handle =
279                 (uint8_t)p_data->api_sndcmd.hdr.layer_specific;
280           } else if (p_data->api_sndcmd.t_type != HID_TRANS_DATA &&
281                      p_data->api_sndcmd.t_type != HID_TRANS_CONTROL) {
282             cback_data.hs_data.handle =
283                 (uint8_t)p_data->api_sndcmd.hdr.layer_specific;
284             cback_data.hs_data.status = BTA_HH_ERR_HDL;
285             /* hs_data.rsp_data will be all zero, which is not valid value */
286           } else if (p_data->api_sndcmd.t_type == HID_TRANS_CONTROL &&
287                      p_data->api_sndcmd.param ==
288                          BTA_HH_CTRL_VIRTUAL_CABLE_UNPLUG) {
289             cback_data.status = BTA_HH_ERR_HDL;
290             cback_event = BTA_HH_VC_UNPLUG_EVT;
291           } else
292             cback_event = 0;
293           break;
294 
295         case BTA_HH_API_CLOSE_EVT:
296           cback_event = BTA_HH_CLOSE_EVT;
297 
298           cback_data.dev_status.status = BTA_HH_ERR_HDL;
299           cback_data.dev_status.handle =
300               (uint8_t)p_data->api_sndcmd.hdr.layer_specific;
301           break;
302 
303         default:
304           /* invalid handle, call bad API event */
305           APPL_TRACE_ERROR("wrong device handle: [%d]",
306                            p_data->hdr.layer_specific);
307           /* Free the callback buffer now */
308           if (p_data != NULL)
309             osi_free_and_reset((void**)&p_data->hid_cback.p_data);
310           break;
311       }
312       if (cback_event) (*bta_hh_cb.p_cback)(cback_event, &cback_data);
313     }
314   }
315   /* corresponding CB is found, go to state machine */
316   else {
317 #if (BTA_HH_DEBUG == TRUE)
318     in_state = p_cb->state;
319     APPL_TRACE_EVENT("bta_hh_sm_execute: State 0x%02x [%s], Event [%s]",
320                      in_state, bta_hh_state_code(in_state),
321                      bta_hh_evt_code(debug_event));
322 #endif
323 
324     if ((p_cb->state == BTA_HH_NULL_ST) || (p_cb->state >= BTA_HH_INVALID_ST)) {
325       APPL_TRACE_ERROR(
326           "bta_hh_sm_execute: Invalid state State = 0x%x, Event = %d",
327           p_cb->state, event);
328       return;
329     }
330     state_table = bta_hh_st_tbl[p_cb->state - 1];
331 
332     event &= 0xff;
333 
334     p_cb->state = state_table[event][BTA_HH_NEXT_STATE];
335 
336     action = state_table[event][BTA_HH_ACTION];
337     if (action != BTA_HH_IGNORE) {
338       (*bta_hh_action[action])(p_cb, p_data);
339     }
340 
341 #if (BTA_HH_DEBUG == TRUE)
342     if (in_state != p_cb->state) {
343       APPL_TRACE_DEBUG("HH State Change: [%s] -> [%s] after Event [%s]",
344                        bta_hh_state_code(in_state),
345                        bta_hh_state_code(p_cb->state),
346                        bta_hh_evt_code(debug_event));
347     }
348 #endif
349   }
350 
351   return;
352 }
353 /*******************************************************************************
354  *
355  * Function         bta_hh_hdl_event
356  *
357  * Description      HID host main event handling function.
358  *
359  *
360  * Returns          void
361  *
362  ******************************************************************************/
bta_hh_hdl_event(BT_HDR * p_msg)363 bool bta_hh_hdl_event(BT_HDR* p_msg) {
364   uint8_t index = BTA_HH_IDX_INVALID;
365   tBTA_HH_DEV_CB* p_cb = NULL;
366 
367   switch (p_msg->event) {
368     case BTA_HH_API_ENABLE_EVT:
369       bta_hh_api_enable((tBTA_HH_DATA*)p_msg);
370       break;
371 
372     case BTA_HH_API_DISABLE_EVT:
373       bta_hh_api_disable();
374       break;
375 
376     case BTA_HH_DISC_CMPL_EVT: /* disable complete */
377       bta_hh_disc_cmpl();
378       break;
379 
380     default:
381       /* all events processed in state machine need to find corresponding
382           CB before proceed */
383       if (p_msg->event == BTA_HH_API_OPEN_EVT) {
384         index = bta_hh_find_cb(((tBTA_HH_API_CONN*)p_msg)->bd_addr);
385       } else if (p_msg->event == BTA_HH_API_MAINT_DEV_EVT) {
386         /* if add device */
387         if (((tBTA_HH_MAINT_DEV*)p_msg)->sub_event == BTA_HH_ADD_DEV_EVT) {
388           index = bta_hh_find_cb(((tBTA_HH_MAINT_DEV*)p_msg)->bda);
389         } else /* else remove device by handle */
390         {
391           index = bta_hh_dev_handle_to_cb_idx((uint8_t)p_msg->layer_specific);
392           /* If BT disable is done while the HID device is connected and
393            * Link_Key uses unauthenticated combination
394             * then we can get into a situation where remove_bonding is called
395            * with the index set to 0 (without getting
396             * cleaned up). Only when VIRTUAL_UNPLUG is called do we cleanup the
397            * index and make it MAX_KNOWN.
398             * So if REMOVE_DEVICE is called and in_use is false then we should
399            * treat this as a NULL p_cb. Hence we
400             * force the index to be IDX_INVALID
401             */
402           if ((index != BTA_HH_IDX_INVALID) &&
403               (!bta_hh_cb.kdev[index].in_use)) {
404             index = BTA_HH_IDX_INVALID;
405           }
406         }
407       } else if (p_msg->event == BTA_HH_INT_OPEN_EVT) {
408         index = bta_hh_find_cb(((tBTA_HH_CBACK_DATA*)p_msg)->addr);
409       } else
410         index = bta_hh_dev_handle_to_cb_idx((uint8_t)p_msg->layer_specific);
411 
412       if (index != BTA_HH_IDX_INVALID) p_cb = &bta_hh_cb.kdev[index];
413 
414 #if (BTA_HH_DEBUG == TRUE)
415       APPL_TRACE_DEBUG("bta_hh_hdl_event:: handle = %d dev_cb[%d] ",
416                        p_msg->layer_specific, index);
417 #endif
418       bta_hh_sm_execute(p_cb, p_msg->event, (tBTA_HH_DATA*)p_msg);
419   }
420   return (true);
421 }
422 
423 /*****************************************************************************
424  *  Debug Functions
425  ****************************************************************************/
426 #if (BTA_HH_DEBUG == TRUE)
427 /*******************************************************************************
428  *
429  * Function         bta_hh_evt_code
430  *
431  * Description
432  *
433  * Returns          void
434  *
435  ******************************************************************************/
bta_hh_evt_code(tBTA_HH_INT_EVT evt_code)436 static const char* bta_hh_evt_code(tBTA_HH_INT_EVT evt_code) {
437   switch (evt_code) {
438     case BTA_HH_API_DISABLE_EVT:
439       return "BTA_HH_API_DISABLE_EVT";
440     case BTA_HH_API_ENABLE_EVT:
441       return "BTA_HH_API_ENABLE_EVT";
442     case BTA_HH_API_OPEN_EVT:
443       return "BTA_HH_API_OPEN_EVT";
444     case BTA_HH_API_CLOSE_EVT:
445       return "BTA_HH_API_CLOSE_EVT";
446     case BTA_HH_INT_OPEN_EVT:
447       return "BTA_HH_INT_OPEN_EVT";
448     case BTA_HH_INT_CLOSE_EVT:
449       return "BTA_HH_INT_CLOSE_EVT";
450     case BTA_HH_INT_HANDSK_EVT:
451       return "BTA_HH_INT_HANDSK_EVT";
452     case BTA_HH_INT_DATA_EVT:
453       return "BTA_HH_INT_DATA_EVT";
454     case BTA_HH_INT_CTRL_DATA:
455       return "BTA_HH_INT_CTRL_DATA";
456     case BTA_HH_API_WRITE_DEV_EVT:
457       return "BTA_HH_API_WRITE_DEV_EVT";
458     case BTA_HH_SDP_CMPL_EVT:
459       return "BTA_HH_SDP_CMPL_EVT";
460     case BTA_HH_DISC_CMPL_EVT:
461       return "BTA_HH_DISC_CMPL_EVT";
462     case BTA_HH_API_MAINT_DEV_EVT:
463       return "BTA_HH_API_MAINT_DEV_EVT";
464     case BTA_HH_API_GET_DSCP_EVT:
465       return "BTA_HH_API_GET_DSCP_EVT";
466     case BTA_HH_OPEN_CMPL_EVT:
467       return "BTA_HH_OPEN_CMPL_EVT";
468 #if (BTA_HH_LE_INCLUDED == TRUE)
469     case BTA_HH_GATT_CLOSE_EVT:
470       return "BTA_HH_GATT_CLOSE_EVT";
471     case BTA_HH_GATT_OPEN_EVT:
472       return "BTA_HH_GATT_OPEN_EVT";
473     case BTA_HH_START_ENC_EVT:
474       return "BTA_HH_START_ENC_EVT";
475     case BTA_HH_ENC_CMPL_EVT:
476       return "BTA_HH_ENC_CMPL_EVT";
477 #endif
478     default:
479       return "unknown HID Host event code";
480   }
481 }
482 
483 /*******************************************************************************
484  *
485  * Function         bta_hh_state_code
486  *
487  * Description      get string representation of HID host state code.
488  *
489  * Returns          void
490  *
491  ******************************************************************************/
bta_hh_state_code(tBTA_HH_STATE state_code)492 static const char* bta_hh_state_code(tBTA_HH_STATE state_code) {
493   switch (state_code) {
494     case BTA_HH_NULL_ST:
495       return "BTA_HH_NULL_ST";
496     case BTA_HH_IDLE_ST:
497       return "BTA_HH_IDLE_ST";
498     case BTA_HH_W4_CONN_ST:
499       return "BTA_HH_W4_CONN_ST";
500     case BTA_HH_CONN_ST:
501       return "BTA_HH_CONN_ST";
502 #if (BTA_HH_LE_INCLUDED == TRUE)
503     case BTA_HH_W4_SEC:
504       return "BTA_HH_W4_SEC";
505 #endif
506     default:
507       return "unknown HID Host state";
508   }
509 }
510 
511 #endif /* Debug Functions */
512 
513 #endif /* BTA_HH_INCLUDED */
514