1/******************************************************************************
2 *
3 *  Copyright (C) 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 action functions.
22 *
23 ******************************************************************************/
24
25#include "bt_target.h"
26
27#if defined(BTA_HH_INCLUDED) && (BTA_HH_INCLUDED == TRUE)
28
29#include <string.h>
30
31#include "bta_sys.h"
32#include "btm_api.h"
33#include "l2c_api.h"
34#include "bta_hh_int.h"
35#include "bta_hh_co.h"
36#include "utl.h"
37
38/*****************************************************************************
39**  Constants
40*****************************************************************************/
41
42
43/*****************************************************************************
44**  Local Function prototypes
45*****************************************************************************/
46static void bta_hh_cback (UINT8 dev_handle, BD_ADDR addr, UINT8 event,
47                            UINT32 data, BT_HDR *pdata);
48static tBTA_HH_STATUS bta_hh_get_trans_status(UINT32 result);
49
50#if BTA_HH_DEBUG
51static char* bta_hh_get_w4_event(UINT16 event);
52static char * bta_hh_hid_event_name(UINT16 event);
53#endif
54
55/*****************************************************************************
56**  Action Functions
57*****************************************************************************/
58/*******************************************************************************
59**
60** Function         bta_hh_api_enable
61**
62** Description      Perform necessary operations to enable HID host.
63**
64**
65** Returns          void
66**
67*******************************************************************************/
68void bta_hh_api_enable(tBTA_HH_DATA *p_data)
69{
70    tBTA_HH_STATUS      status = BTA_HH_ERR;
71    UINT8               xx;
72
73    /* initialize BTE HID */
74    HID_HostInit();
75
76    memset(&bta_hh_cb, 0, sizeof(tBTA_HH_CB));
77
78    HID_HostSetSecurityLevel("", p_data->api_enable.sec_mask);
79
80    /* Register with L2CAP */
81    if ( HID_HostRegister (bta_hh_cback) == HID_SUCCESS)
82    {
83        /* store parameters */
84        bta_hh_cb.p_cback = p_data->api_enable.p_cback;
85
86        status = BTA_HH_OK;
87        /* initialize device CB */
88        for (xx = 0; xx < BTA_HH_MAX_DEVICE; xx ++)
89        {
90            bta_hh_cb.kdev[xx].state        = BTA_HH_IDLE_ST;
91            bta_hh_cb.kdev[xx].hid_handle   = BTA_HH_INVALID_HANDLE;
92            bta_hh_cb.kdev[xx].index        = xx;
93        }
94
95        /* initialize control block map */
96        for (xx = 0; xx < BTA_HH_MAX_KNOWN; xx ++)
97            bta_hh_cb.cb_index[xx]          = BTA_HH_IDX_INVALID;
98    }
99
100#if (BTA_HH_LE_INCLUDED == TRUE)
101    if (status == BTA_HH_OK)
102    {
103        bta_hh_le_enable();
104    }
105    else
106#endif
107        /* signal BTA call back event */
108        (* bta_hh_cb.p_cback)(BTA_HH_ENABLE_EVT, (tBTA_HH *)&status);
109}
110/*******************************************************************************
111**
112** Function         bta_hh_api_disable
113**
114** Description      Perform necessary operations to disable HID host.
115**
116**
117** Returns          void
118**
119*******************************************************************************/
120void bta_hh_api_disable(void)
121{
122    UINT8 xx;
123
124    /* service is not enabled */
125    if (bta_hh_cb.p_cback == NULL)
126        return;
127
128    /* no live connection, signal DISC_CMPL_EVT directly */
129    if (!bta_hh_cb.cnt_num)
130    {
131        bta_hh_disc_cmpl();
132    }
133    else /* otherwise, disconnect all live connections */
134    {
135        bta_hh_cb.w4_disable = TRUE;
136
137        for(xx = 0; xx < BTA_HH_MAX_DEVICE; xx ++)
138        {
139            /* send API_CLOSE event to every connected device */
140            if ( bta_hh_cb.kdev[xx].state == BTA_HH_CONN_ST )
141            {
142                /* disconnect all connected devices */
143                bta_hh_sm_execute(&bta_hh_cb.kdev[xx],
144                                BTA_HH_API_CLOSE_EVT,
145                                NULL);
146            }
147        }
148    }
149
150    return;
151}
152
153/*******************************************************************************
154**
155** Function         bta_hh_disc_cmpl
156**
157** Description      All connections have been closed, disable service.
158**
159**
160** Returns          void
161**
162*******************************************************************************/
163void bta_hh_disc_cmpl(void)
164{
165    tBTA_HH_STATUS  status = BTA_HH_OK;
166
167    /* Deregister with lower layer */
168    if (HID_HostDeregister() != HID_SUCCESS)
169        status = BTA_HH_ERR;
170
171#if (BTA_HH_LE_INCLUDED == TRUE)
172    bta_hh_le_deregister();
173    UNUSED(status);
174#else
175    bta_hh_cleanup_disable(status);
176#endif
177}
178
179/*******************************************************************************
180**
181** Function         bta_hh_sdp_cback
182**
183** Description      SDP callback function.
184**
185** Returns          void
186**
187*******************************************************************************/
188static void bta_hh_sdp_cback(UINT16 result, UINT16 attr_mask,
189                                  tHID_DEV_SDP_INFO *sdp_rec )
190{
191    tBTA_HH_DEV_CB     *p_cb = bta_hh_cb.p_cur;
192    UINT8              hdl = 0;
193    tBTA_HH_STATUS    status = BTA_HH_ERR_SDP;
194
195    /* make sure sdp succeeded and hh has not been disabled */
196    if ((result == SDP_SUCCESS) && (p_cb != NULL))
197    {
198        /* security is required for the connection, add attr_mask bit*/
199        if (p_cb->sec_mask)
200            attr_mask |= HID_SEC_REQUIRED;
201
202#if BTA_HH_DEBUG
203        APPL_TRACE_EVENT("bta_hh_sdp_cback: p_cb: %d result 0x%02x, \
204                            attr_mask 0x%02x, handle %x", \
205                            p_cb, result, attr_mask,p_cb->hid_handle);
206#endif
207
208        /* check to see type of device is supported , and should not been added before */
209        if (bta_hh_tod_spt(p_cb, sdp_rec->sub_class))
210        {
211            /* if not added before */
212            if (p_cb->hid_handle == BTA_HH_INVALID_HANDLE)
213            {
214                /*  add device/update attr_mask information */
215                if(HID_HostAddDev (p_cb->addr, attr_mask, &hdl) == HID_SUCCESS)
216                {
217                    status = BTA_HH_OK;
218                    /* update cb_index[] map */
219                    bta_hh_cb.cb_index[hdl] = p_cb->index;
220                }
221                else
222                {
223                    p_cb->app_id = 0;
224                }
225            }
226            else
227            {
228                hdl = p_cb->hid_handle;
229            }
230            /* else : incoming connection after SDP should update the SDP information as well */
231
232            if (p_cb->app_id != 0)
233            {
234                /* update cb information with attr_mask, dscp_info etc. */
235                bta_hh_add_device_to_list(p_cb,  hdl, attr_mask,
236                                            &sdp_rec->dscp_info,
237                                            sdp_rec->sub_class,
238                                            sdp_rec->ssr_max_latency,
239                                            sdp_rec->ssr_min_tout,
240                                            p_cb->app_id);
241
242                p_cb->dscp_info.ctry_code = sdp_rec->ctry_code;
243
244                status = BTA_HH_OK;
245            }
246
247        }
248        else /* type of device is not supported */
249            status = BTA_HH_ERR_TOD_UNSPT;
250    }
251
252    /* free disc_db when SDP is completed */
253    utl_freebuf((void **)&bta_hh_cb.p_disc_db);
254
255    /* send SDP_CMPL_EVT into state machine */
256    bta_hh_sm_execute(p_cb, BTA_HH_SDP_CMPL_EVT, (tBTA_HH_DATA *)&status);
257
258    return;
259}
260/*******************************************************************************
261**
262** Function         bta_hh_di_sdp_cback
263**
264** Description      SDP DI callback function.
265**
266** Returns          void
267**
268*******************************************************************************/
269static void bta_hh_di_sdp_cback(UINT16 result)
270{
271    tBTA_HH_DEV_CB     *p_cb = bta_hh_cb.p_cur;
272    tBTA_HH_STATUS         status = BTA_HH_ERR_SDP;
273    tSDP_DI_GET_RECORD  di_rec;
274    tHID_STATUS ret;
275#if BTA_HH_DEBUG
276    APPL_TRACE_EVENT("bta_hh_di_sdp_cback: p_cb: %d result 0x%02x", p_cb, result);
277#endif
278
279    /* if DI record does not exist on remote device, vendor_id in tBTA_HH_DEV_DSCP_INFO will be
280         * set to 0xffff and we will allow the connection to go through. Spec mandates that DI
281         * record be set, but many HID devices do not set this. So for IOP purposes, we allow the
282         * connection to go through and update the DI record to invalid DI entry.*/
283    if (((result == SDP_SUCCESS) || (result == SDP_NO_RECS_MATCH)) && (p_cb != NULL))
284    {
285        if(result == SDP_SUCCESS && SDP_GetNumDiRecords(bta_hh_cb.p_disc_db) != 0)
286        {
287            /* always update information with primary DI record */
288            if (SDP_GetDiRecord(1, &di_rec, bta_hh_cb.p_disc_db) == SDP_SUCCESS)
289            {
290                bta_hh_update_di_info(p_cb, di_rec.rec.vendor, di_rec.rec.product, di_rec.rec.version, 0);
291            }
292
293        }
294        else /* no DI recrod available */
295        {
296            bta_hh_update_di_info(p_cb, BTA_HH_VENDOR_ID_INVALID, 0, 0, 0);
297        }
298
299        if ((ret = HID_HostGetSDPRecord(p_cb->addr,
300                                 bta_hh_cb.p_disc_db,
301                                 p_bta_hh_cfg->sdp_db_size,
302                                 bta_hh_sdp_cback)) == HID_SUCCESS)
303        {
304            status = BTA_HH_OK;
305        }
306        else
307        {
308#if BTA_HH_DEBUG
309            APPL_TRACE_DEBUG ("bta_hh_di_sdp_cback:  HID_HostGetSDPRecord failed: Status 0x%2x",
310                               ret);
311#endif
312        }
313    }
314
315
316    if (status != BTA_HH_OK)
317    {
318        utl_freebuf((void **)&bta_hh_cb.p_disc_db);
319        /* send SDP_CMPL_EVT into state machine */
320        bta_hh_sm_execute(p_cb, BTA_HH_SDP_CMPL_EVT, (tBTA_HH_DATA *)&status);
321    }
322    return;
323
324}
325
326
327/*******************************************************************************
328**
329** Function         bta_hh_start_sdp
330**
331** Description      Start SDP service search, and obtain necessary SDP records.
332**                  Only one SDP service search request is allowed at the same
333**                  time. For every BTA_HhOpen API call, do SDP first unless SDP
334**                  has been done previously.
335**
336** Returns          void
337**
338*******************************************************************************/
339void bta_hh_start_sdp(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data)
340{
341    tBTA_HH_STATUS          status = BTA_HH_ERR_SDP;
342    UINT8                   hdl;
343
344    p_cb->sec_mask  = p_data->api_conn.sec_mask;
345    p_cb->mode      = p_data->api_conn.mode;
346    bta_hh_cb.p_cur = p_cb;
347
348#if (BTA_HH_LE_INCLUDED == TRUE)
349    if (bta_hh_is_le_device(p_cb, p_data->api_conn.bd_addr))
350    {
351        bta_hh_le_open_conn(p_cb, p_data->api_conn.bd_addr);
352        return;
353    }
354#endif
355
356    /* if previously virtually cabled device, skip SDP */
357    if (p_cb->app_id)
358    {
359        status = BTA_HH_OK;
360#if BTA_HH_DEBUG
361        APPL_TRACE_DEBUG("bta_hh_start_sdp:: skip SDP for known devices");
362#endif
363        if (p_cb->hid_handle == BTA_HH_INVALID_HANDLE)
364        {
365            if (HID_HostAddDev (p_cb->addr, p_cb->attr_mask, &hdl) \
366                == HID_SUCCESS)
367            {
368                /* update device CB with newly register device handle */
369                bta_hh_add_device_to_list(p_cb,  hdl, p_cb->attr_mask, NULL,
370                                          p_cb->sub_class,
371                                          p_cb->dscp_info.ssr_max_latency,
372                                          p_cb->dscp_info.ssr_min_tout,
373                                          p_cb->app_id);
374                /* update cb_index[] map */
375                bta_hh_cb.cb_index[hdl] = p_cb->index;
376            }
377            else
378                status = BTA_HH_ERR_NO_RES;
379        }
380        bta_hh_sm_execute(p_cb, BTA_HH_SDP_CMPL_EVT, (tBTA_HH_DATA *)&status);
381
382        return;
383    }
384    /* GetSDPRecord. at one time only one SDP precedure can be active */
385    else if (!bta_hh_cb.p_disc_db)
386    {
387        bta_hh_cb.p_disc_db = (tSDP_DISCOVERY_DB *) GKI_getbuf(p_bta_hh_cfg->sdp_db_size);
388
389        if (bta_hh_cb.p_disc_db == NULL)
390        {
391            status = BTA_HH_ERR_NO_RES;
392        }
393        else
394        {
395            bta_hh_cb.p_cur = p_cb;
396            /* do DI discovery first */
397            if (SDP_DiDiscover(p_data->api_conn.bd_addr,
398                                         bta_hh_cb.p_disc_db,
399                                         p_bta_hh_cfg->sdp_db_size,
400                                         bta_hh_di_sdp_cback) != SDP_SUCCESS)
401            {
402#if BTA_HH_DEBUG
403                APPL_TRACE_DEBUG ("bta_hh_start_sdp:  SDP_DiDiscover failed: \
404                    Status 0x%2X",status);
405#endif
406                status = BTA_HH_ERR_SDP;
407                utl_freebuf((void **)&bta_hh_cb.p_disc_db);
408            }
409            else
410                status = BTA_HH_OK;
411        }
412    }
413
414    if (status != BTA_HH_OK)
415        bta_hh_sm_execute(p_cb, BTA_HH_SDP_CMPL_EVT, (tBTA_HH_DATA *)&status);
416
417    return;
418
419}
420/*******************************************************************************
421**
422** Function         bta_hh_sdp_cmpl
423**
424** Description      When SDP completed, initiate a connection or report error depend
425**                  on SDP result.
426**
427**
428** Returns          void
429**
430*******************************************************************************/
431void bta_hh_sdp_cmpl(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data)
432{
433    tBTA_HH_CONN            conn_dat;
434    tBTA_HH_STATUS          status = p_data->status;
435
436#if BTA_HH_DEBUG
437    APPL_TRACE_DEBUG ("bta_hh_sdp_cmpl:  status 0x%2X",p_data->status);
438#endif
439
440    /* initialize call back data */
441    memset((void *)&conn_dat, 0, sizeof(tBTA_HH_CONN));
442    conn_dat.handle = p_cb->hid_handle;
443    bdcpy(conn_dat.bda, p_cb->addr);
444
445    /* if SDP compl success */
446    if ( status == BTA_HH_OK)
447    {
448        /* not incoming connection doing SDP, initiate a HID connection */
449        if (!p_cb->incoming_conn)
450        {
451            tHID_STATUS ret;
452            /* set security level */
453            HID_HostSetSecurityLevel("", p_cb->sec_mask);
454
455            /* open HID connection */
456            if ((ret = HID_HostOpenDev (p_cb->hid_handle)) != HID_SUCCESS)
457            {
458#if BTA_HH_DEBUG
459                APPL_TRACE_DEBUG ("bta_hh_sdp_cmpl:  HID_HostOpenDev failed: \
460                    Status 0x%2X",ret);
461#endif
462                /* open fail, remove device from management device list */
463                HID_HostRemoveDev( p_cb->hid_handle);
464                status = BTA_HH_ERR;
465            }
466            else
467            {
468                status = BTA_HH_OK;
469            }
470        }
471        else /* incoming connection SDP finish */
472        {
473            bta_hh_sm_execute(p_cb, BTA_HH_OPEN_CMPL_EVT, NULL);
474        }
475    }
476
477    if (status != BTA_HH_OK)
478    {
479        /* Check if this was incoming connection request  from an unknown device
480           **and connection failed due to missing HID Device SDP UUID
481           **In above condition, disconnect the link as well as remove the
482           **device from list of HID devices*/
483        if ((status == BTA_HH_ERR_SDP) &&
484           (p_cb->incoming_conn) &&(p_cb->app_id == 0))
485        {
486            APPL_TRACE_DEBUG ("bta_hh_sdp_cmpl:SDP failed for  incoming conn :hndl %d",
487                                p_cb->incoming_hid_handle);
488            HID_HostRemoveDev( p_cb->incoming_hid_handle);
489        }
490        conn_dat.status = status;
491        (* bta_hh_cb.p_cback)(BTA_HH_OPEN_EVT, (tBTA_HH *)&conn_dat);
492
493        /* move state machine W4_CONN ->IDLE */
494        bta_hh_sm_execute(p_cb, BTA_HH_API_CLOSE_EVT, NULL);
495
496        /* if this is an outgoing connection to an unknown device, clean up cb */
497        if (p_cb->app_id == 0 && !p_cb->incoming_conn)
498        {
499            /* clean up device control block */
500            bta_hh_clean_up_kdev(p_cb);
501        }
502#if BTA_HH_DEBUG
503        bta_hh_trace_dev_db();
504#endif
505    }
506    return;
507}
508
509/*******************************************************************************
510**
511** Function         bta_hh_api_disc_act
512**
513** Description      HID Host initiate a disconnection.
514**
515**
516** Returns          void
517**
518*******************************************************************************/
519void bta_hh_api_disc_act(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data)
520{
521    tBTA_HH_CBDATA    disc_dat;
522    tHID_STATUS     status;
523
524#if BTA_HH_LE_INCLUDED == TRUE
525    if (p_cb->is_le_device)
526        bta_hh_le_api_disc_act(p_cb);
527    else
528#endif
529    {
530        /* found an active connection */
531        disc_dat.handle = p_data ?(UINT8)p_data->hdr.layer_specific :p_cb->hid_handle;
532        disc_dat.status = BTA_HH_ERR;
533
534        status = HID_HostCloseDev(disc_dat.handle);
535
536        if (status)
537            (* bta_hh_cb.p_cback)(BTA_HH_CLOSE_EVT, (tBTA_HH *)&disc_dat);
538    }
539
540    return;
541
542}
543/*******************************************************************************
544**
545** Function         bta_hh_open_cmpl_act
546**
547** Description      HID host connection completed
548**
549**
550** Returns          void
551**
552*******************************************************************************/
553void bta_hh_open_cmpl_act(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data)
554{
555    tBTA_HH_CONN        conn ;
556    UINT8   dev_handle = p_data ? (UINT8)p_data->hid_cback.hdr.layer_specific : \
557                        p_cb->hid_handle;
558
559    memset((void *)&conn, 0, sizeof (tBTA_HH_CONN));
560    conn.handle = dev_handle;
561    bdcpy(conn.bda, p_cb->addr);
562
563    /* increase connection number */
564    bta_hh_cb.cnt_num ++;
565
566    /* initialize device driver */
567    bta_hh_co_open(p_cb->hid_handle, p_cb->sub_class,
568                       p_cb->attr_mask,  p_cb->app_id);
569
570#if (BTA_HH_LE_INCLUDED == TRUE)
571    conn.status = p_cb->status;
572    conn.le_hid = p_cb->is_le_device;
573    conn.scps_supported = p_cb->scps_supported;
574
575    if (!p_cb->is_le_device)
576#endif
577    {
578        /* inform role manager */
579        bta_sys_conn_open( BTA_ID_HH ,p_cb->app_id, p_cb->addr);
580    }
581    /* set protocol mode when not default report mode */
582    if ( p_cb->mode != BTA_HH_PROTO_RPT_MODE
583#if (BTA_HH_LE_INCLUDED == TRUE)
584         && !p_cb->is_le_device
585#endif
586        )
587    {
588        if ((HID_HostWriteDev(dev_handle,
589                              HID_TRANS_SET_PROTOCOL, HID_PAR_PROTOCOL_BOOT_MODE,
590                              0,
591                              0, NULL)) != HID_SUCCESS)
592        {
593            /* HID connection is up, while SET_PROTO fail */
594            conn.status = BTA_HH_ERR_PROTO;
595            (* bta_hh_cb.p_cback)(BTA_HH_OPEN_EVT, (tBTA_HH *)&conn);
596        }
597        else
598        {
599            conn.status = BTA_HH_OK;
600            p_cb->w4_evt = BTA_HH_OPEN_EVT;
601        }
602    }
603    else
604        (* bta_hh_cb.p_cback)(BTA_HH_OPEN_EVT, (tBTA_HH *)&conn);
605
606    p_cb->incoming_conn = FALSE;
607    p_cb->incoming_hid_handle = BTA_HH_INVALID_HANDLE;
608
609}
610/*******************************************************************************
611**
612** Function         bta_hh_open_act
613**
614** Description      HID host receive HID_OPEN_EVT .
615**
616**
617** Returns          void
618**
619*******************************************************************************/
620void bta_hh_open_act(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data)
621{
622    tBTA_HH_API_CONN    conn_data;
623
624    UINT8   dev_handle = p_data ? (UINT8)p_data->hid_cback.hdr.layer_specific : \
625                        p_cb->hid_handle;
626
627#if BTA_HH_DEBUG
628    APPL_TRACE_EVENT ("bta_hh_open_act:  Device[%d] connected", dev_handle);
629#endif
630
631    /* SDP has been done */
632    if (p_cb->app_id != 0)
633    {
634        bta_hh_sm_execute(p_cb, BTA_HH_OPEN_CMPL_EVT, p_data);
635    }
636    else
637    /*  app_id == 0 indicates an incoming conenction request arrives without SDP
638        performed, do it first */
639    {
640        p_cb->incoming_conn = TRUE;
641        /* store the handle here in case sdp fails - need to disconnect */
642        p_cb->incoming_hid_handle = dev_handle;
643
644        memset(&conn_data, 0, sizeof(tBTA_HH_API_CONN));
645        bdcpy(conn_data.bd_addr, p_cb->addr);
646        bta_hh_start_sdp(p_cb, (tBTA_HH_DATA *)&conn_data);
647    }
648
649    return;
650}
651
652
653/*******************************************************************************
654**
655** Function         bta_hh_data_act
656**
657** Description      HID Host process a data report
658**
659**
660** Returns          void
661**
662*******************************************************************************/
663void bta_hh_data_act(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA * p_data)
664{
665    BT_HDR  *pdata = p_data->hid_cback.p_data;
666    UINT8   *p_rpt = (UINT8 *)(pdata + 1) + pdata->offset;
667
668    bta_hh_co_data((UINT8)p_data->hid_cback.hdr.layer_specific, p_rpt, pdata->len,
669                    p_cb->mode, p_cb->sub_class, p_cb->dscp_info.ctry_code, p_cb->addr, p_cb->app_id);
670
671    utl_freebuf((void **)&pdata);
672}
673
674
675/*******************************************************************************
676**
677** Function         bta_hh_handsk_act
678**
679** Description      HID Host process a handshake acknoledgement.
680**
681**
682** Returns          void
683**
684*******************************************************************************/
685void bta_hh_handsk_act(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA * p_data)
686{
687    tBTA_HH_CBDATA  cback_data ;
688    tBTA_HH_HSDATA  hs_data;
689    tBTA_HH_CONN    conn ;
690
691#if BTA_HH_DEBUG
692    APPL_TRACE_DEBUG("HANDSHAKE received for: event = %s data= %d",
693        bta_hh_get_w4_event(p_cb->w4_evt), p_data->hid_cback.data);
694#endif
695
696    memset(&hs_data, 0, sizeof(tBTA_HH_HSDATA));
697    memset(&cback_data, 0, sizeof(tBTA_HH_CBDATA));
698
699    switch (p_cb->w4_evt)
700    {
701        /* GET_ transsaction, handshake indicate unsupported request */
702        case BTA_HH_GET_PROTO_EVT:
703            hs_data.rsp_data.proto_mode = BTA_HH_PROTO_UNKNOWN;
704            /* fall through */
705        case BTA_HH_GET_RPT_EVT:
706        case BTA_HH_GET_IDLE_EVT :
707            hs_data.handle = p_cb->hid_handle;
708            /* if handshake gives an OK code for these transaction, fill in UNSUPT */
709            if ((hs_data.status = bta_hh_get_trans_status(p_data->hid_cback.data)) == BTA_HH_OK)
710                 hs_data.status = BTA_HH_HS_TRANS_NOT_SPT;
711
712            (* bta_hh_cb.p_cback)(p_cb->w4_evt, (tBTA_HH *)&hs_data);
713            p_cb->w4_evt = 0;
714            break;
715
716        /* acknoledgement from HID device for SET_ transaction */
717        case BTA_HH_SET_RPT_EVT:
718        case BTA_HH_SET_PROTO_EVT:
719        case BTA_HH_SET_IDLE_EVT :
720            cback_data.handle  = p_cb->hid_handle;
721            cback_data.status = bta_hh_get_trans_status(p_data->hid_cback.data);
722            (* bta_hh_cb.p_cback)(p_cb->w4_evt, (tBTA_HH *)&cback_data);
723            p_cb->w4_evt = 0;
724            break;
725
726        /* SET_PROTOCOL when open connection */
727        case BTA_HH_OPEN_EVT:
728            conn.status =p_data->hid_cback.data ? BTA_HH_ERR_PROTO: BTA_HH_OK;
729            conn.handle = p_cb->hid_handle;
730            bdcpy(conn.bda, p_cb->addr);
731            (* bta_hh_cb.p_cback)(p_cb->w4_evt, (tBTA_HH *)&conn);
732#if BTA_HH_DEBUG
733            bta_hh_trace_dev_db();
734#endif
735            p_cb->w4_evt = 0;
736            break;
737
738        default:
739            /* unknow transaction handshake response */
740            APPL_TRACE_DEBUG("unknown transaction type");
741            break;
742    }
743
744    /* transaction achknoledgement received, inform PM for mode change */
745    bta_sys_idle(BTA_ID_HH, p_cb->app_id, p_cb->addr);
746    return;
747}
748/*******************************************************************************
749**
750** Function         bta_hh_ctrl_dat_act
751**
752** Description      HID Host process a data report from control channel.
753**
754**
755** Returns          void
756**
757*******************************************************************************/
758void bta_hh_ctrl_dat_act(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA * p_data)
759{
760    BT_HDR          *pdata = p_data->hid_cback.p_data;
761    UINT8           *data = (UINT8 *)(pdata + 1) + pdata->offset;
762    tBTA_HH_HSDATA    hs_data;
763
764#if BTA_HH_DEBUG
765    APPL_TRACE_DEBUG("Ctrl DATA received w4: event[%s]",
766                        bta_hh_get_w4_event(p_cb->w4_evt));
767#endif
768    hs_data.status  = BTA_HH_OK;
769    hs_data.handle  = p_cb->hid_handle;
770
771    switch (p_cb->w4_evt)
772    {
773    case BTA_HH_GET_IDLE_EVT:
774        hs_data.rsp_data.idle_rate = *data;
775        break;
776    case BTA_HH_GET_RPT_EVT:
777        hs_data.rsp_data.p_rpt_data = pdata;
778        break;
779    case BTA_HH_GET_PROTO_EVT:
780        /* match up BTE/BTA report/boot mode def*/
781        hs_data.rsp_data.proto_mode = ((*data) == HID_PAR_PROTOCOL_REPORT)? \
782                    BTA_HH_PROTO_RPT_MODE : BTA_HH_PROTO_BOOT_MODE;
783#if BTA_HH_DEBUG
784        APPL_TRACE_DEBUG("GET_PROTOCOL Mode = [%s]",
785            (hs_data.rsp_data.proto_mode == BTA_HH_PROTO_RPT_MODE)? "Report" : "Boot");
786#endif
787        break;
788    /* should not expect control DATA for SET_ transaction */
789    case BTA_HH_SET_PROTO_EVT:
790        /* fall through */
791    case BTA_HH_SET_RPT_EVT:
792        /* fall through */
793    case BTA_HH_SET_IDLE_EVT :
794        /* fall through */
795    default:
796#if BTA_HH_DEBUG
797        APPL_TRACE_DEBUG("invalid  transaction type for DATA payload: 4_evt[%s]",
798                        bta_hh_get_w4_event(p_cb->w4_evt));
799#endif
800        break;
801    }
802
803    /* inform PM for mode change */
804    bta_sys_busy(BTA_ID_HH, p_cb->app_id, p_cb->addr);
805    bta_sys_idle(BTA_ID_HH, p_cb->app_id, p_cb->addr);
806
807    (* bta_hh_cb.p_cback)(p_cb->w4_evt, (tBTA_HH *)&hs_data);
808
809    p_cb->w4_evt = 0;
810    utl_freebuf((void **)&pdata);
811
812}
813
814/*******************************************************************************
815**
816** Function         bta_hh_open_failure
817**
818** Description      report HID open failure when at wait for connection state and receive
819**                  device close event.
820**
821**
822** Returns          void
823**
824*******************************************************************************/
825void bta_hh_open_failure(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data)
826{
827    tBTA_HH_CONN            conn_dat ;
828    UINT32                  reason = p_data->hid_cback.data;    /* Reason for closing (32-bit) */
829
830    memset(&conn_dat, 0, sizeof(tBTA_HH_CONN));
831     conn_dat.handle = p_cb->hid_handle;
832     conn_dat.status = (reason == HID_ERR_AUTH_FAILED) ?
833                                    BTA_HH_ERR_AUTH_FAILED : BTA_HH_ERR;
834     bdcpy(conn_dat.bda, p_cb->addr);
835     HID_HostCloseDev(p_cb->hid_handle);
836
837     /* Report OPEN fail event */
838     (*bta_hh_cb.p_cback)(BTA_HH_OPEN_EVT, (tBTA_HH *)&conn_dat);
839
840#if BTA_HH_DEBUG
841    bta_hh_trace_dev_db();
842#endif
843    /* clean up control block, but retain SDP info and device handle */
844    p_cb->vp            = FALSE;
845    p_cb->w4_evt        = 0;
846
847    /* if no connection is active and HH disable is signaled, disable service */
848    if (bta_hh_cb.cnt_num == 0 && bta_hh_cb.w4_disable)
849    {
850        bta_hh_disc_cmpl();
851    }
852
853}
854
855/*******************************************************************************
856**
857** Function         bta_hh_close_act
858**
859** Description      HID Host process a close event
860**
861**
862** Returns          void
863**
864*******************************************************************************/
865void bta_hh_close_act (tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data)
866{
867    tBTA_HH_CONN            conn_dat ;
868    tBTA_HH_CBDATA          disc_dat = {BTA_HH_OK, 0};
869    UINT32                  reason = p_data->hid_cback.data;    /* Reason for closing (32-bit) */
870
871    /* if HID_HDEV_EVT_VC_UNPLUG was received, report BTA_HH_VC_UNPLUG_EVT */
872    UINT16     event = p_cb->vp ? BTA_HH_VC_UNPLUG_EVT : BTA_HH_CLOSE_EVT;
873
874    disc_dat.handle = p_cb->hid_handle;
875    disc_dat.status = p_data->hid_cback.data;
876
877    /* Check reason for closing */
878    if ((reason & (HID_L2CAP_CONN_FAIL|HID_L2CAP_REQ_FAIL)) ||  /* Failure to initialize connection (page timeout or l2cap error) */
879        (reason == HID_ERR_AUTH_FAILED) ||                      /* Authenication error (while initiating) */
880        (reason == HID_ERR_L2CAP_FAILED))                       /* Failure creating l2cap connection */
881    {
882        /* Failure in opening connection */
883        conn_dat.handle = p_cb->hid_handle;
884        conn_dat.status = (reason == HID_ERR_AUTH_FAILED) ? BTA_HH_ERR_AUTH_FAILED : BTA_HH_ERR;
885        bdcpy(conn_dat.bda, p_cb->addr);
886        HID_HostCloseDev(p_cb->hid_handle);
887
888        /* Report OPEN fail event */
889        (*bta_hh_cb.p_cback)(BTA_HH_OPEN_EVT, (tBTA_HH *)&conn_dat);
890
891#if BTA_HH_DEBUG
892        bta_hh_trace_dev_db();
893#endif
894        return;
895    }
896    /* otherwise report CLOSE/VC_UNPLUG event */
897    else
898    {
899        /* finaliza device driver */
900        bta_hh_co_close(p_cb->hid_handle, p_cb->app_id);
901        /* inform role manager */
902        bta_sys_conn_close( BTA_ID_HH ,p_cb->app_id, p_cb->addr);
903        /* update total conn number */
904        bta_hh_cb.cnt_num --;
905
906        if (disc_dat.status)
907            disc_dat.status = BTA_HH_ERR;
908
909        (*bta_hh_cb.p_cback)(event, (tBTA_HH *)&disc_dat);
910
911        /* if virtually unplug, remove device */
912        if (p_cb->vp )
913        {
914            HID_HostRemoveDev( p_cb->hid_handle);
915            bta_hh_clean_up_kdev(p_cb);
916        }
917
918#if BTA_HH_DEBUG
919        bta_hh_trace_dev_db();
920#endif
921    }
922
923    /* clean up control block, but retain SDP info and device handle */
924    p_cb->vp            = FALSE;
925    p_cb->w4_evt        = 0;
926
927    /* if no connection is active and HH disable is signaled, disable service */
928    if (bta_hh_cb.cnt_num == 0 && bta_hh_cb.w4_disable)
929    {
930        bta_hh_disc_cmpl();
931    }
932
933    return;
934}
935
936/*******************************************************************************
937**
938** Function         bta_hh_get_dscp_act
939**
940** Description      Get device report descriptor
941**
942**
943** Returns          void
944**
945*******************************************************************************/
946void bta_hh_get_dscp_act(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data)
947{
948    UNUSED(p_data);
949
950#if (BTA_HH_LE_INCLUDED == TRUE)
951    if (p_cb->is_le_device)
952    {
953        bta_hh_le_get_dscp_act(p_cb);
954    }
955    else
956#endif
957    (*bta_hh_cb.p_cback)(BTA_HH_GET_DSCP_EVT, (tBTA_HH *)&p_cb->dscp_info);
958}
959
960/*******************************************************************************
961**
962** Function         bta_hh_maint_dev_act
963**
964** Description      HID Host maintain device list.
965**
966**
967** Returns          void
968**
969*******************************************************************************/
970void bta_hh_maint_dev_act(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data)
971{
972    tBTA_HH_MAINT_DEV       *p_dev_info = &p_data->api_maintdev;
973    tBTA_HH_DEV_INFO        dev_info ;
974    UINT8                   dev_handle;
975
976    dev_info.status = BTA_HH_ERR;
977    dev_info.handle = BTA_HH_INVALID_HANDLE;
978
979    switch (p_dev_info->sub_event)
980    {
981    case BTA_HH_ADD_DEV_EVT:    /* add a device */
982        bdcpy(dev_info.bda, p_dev_info->bda);
983        /* initialize callback data */
984        if (p_cb->hid_handle == BTA_HH_INVALID_HANDLE)
985        {
986#if (BTA_HH_LE_INCLUDED == TRUE)
987            if (bta_hh_is_le_device(p_cb, p_data->api_conn.bd_addr))
988            {
989                dev_info.handle   = bta_hh_le_add_device(p_cb, p_dev_info);
990                dev_info.status   = BTA_HH_OK;
991            }
992            else
993#endif
994
995            if (HID_HostAddDev(p_dev_info->bda, p_dev_info->attr_mask, &dev_handle)\
996                            == HID_SUCCESS)
997            {
998                dev_info.handle   = dev_handle;
999                dev_info.status   = BTA_HH_OK;
1000
1001#if (defined BTA_HH_LE_INCLUDED && BTA_HH_LE_INCLUDED == TRUE)
1002                /* update DI information */
1003                bta_hh_update_di_info(p_cb,
1004                                      p_dev_info->dscp_info.vendor_id,
1005                                      p_dev_info->dscp_info.product_id,
1006                                      p_dev_info->dscp_info.version,
1007                                      p_dev_info->dscp_info.flag);
1008#else
1009                bta_hh_update_di_info(p_cb,
1010                                      p_dev_info->dscp_info.vendor_id,
1011                                      p_dev_info->dscp_info.product_id,
1012                                      p_dev_info->dscp_info.version,
1013                                      0);
1014
1015#endif
1016                /* add to BTA device list */
1017                bta_hh_add_device_to_list(p_cb, dev_handle,
1018                                          p_dev_info->attr_mask,
1019                                          &p_dev_info->dscp_info.descriptor,
1020                                          p_dev_info->sub_class,
1021                                          p_dev_info->dscp_info.ssr_max_latency,
1022                                          p_dev_info->dscp_info.ssr_min_tout,
1023                                          p_dev_info->app_id);
1024                /* update cb_index[] map */
1025                bta_hh_cb.cb_index[dev_handle] = p_cb->index;
1026            }
1027        }
1028        else    /* device already been added */
1029        {
1030            dev_info.handle = p_cb->hid_handle;
1031            dev_info.status = BTA_HH_OK;
1032        }
1033#if BTA_HH_DEBUG
1034        bta_hh_trace_dev_db();
1035#endif
1036
1037        break;
1038    case BTA_HH_RMV_DEV_EVT:    /* remove device */
1039        dev_info.handle = (UINT8)p_dev_info->hdr.layer_specific;
1040        bdcpy(dev_info.bda, p_cb->addr);
1041
1042#if BTA_HH_LE_INCLUDED == TRUE
1043        if (p_cb->is_le_device)
1044        {
1045            bta_hh_le_remove_dev_bg_conn(p_cb);
1046            bta_hh_sm_execute(p_cb, BTA_HH_API_CLOSE_EVT, NULL);
1047            bta_hh_clean_up_kdev(p_cb);
1048        }
1049        else
1050#endif
1051        {
1052            if(HID_HostRemoveDev( dev_info.handle ) == HID_SUCCESS)
1053            {
1054                dev_info.status  = BTA_HH_OK;
1055
1056                /* remove from known device list in BTA */
1057                bta_hh_clean_up_kdev(p_cb);
1058            }
1059        }
1060        break;
1061
1062    default:
1063        APPL_TRACE_DEBUG("invalid command");
1064        break;
1065    }
1066
1067    (* bta_hh_cb.p_cback)(p_dev_info->sub_event, (tBTA_HH *)&dev_info);
1068}
1069/*******************************************************************************
1070**
1071** Function         bta_hh_write_dev_act
1072**
1073** Description      Write device action. can be SET/GET/DATA transaction.
1074**
1075** Returns          void
1076**
1077*******************************************************************************/
1078void bta_hh_write_dev_act(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data)
1079{
1080    tBTA_HH_CBDATA     cbdata = {BTA_HH_OK, 0};
1081    UINT16  event = (p_data->api_sndcmd.t_type - BTA_HH_FST_BTE_TRANS_EVT) +
1082                        BTA_HH_FST_TRANS_CB_EVT;
1083
1084#if BTA_HH_LE_INCLUDED == TRUE
1085    if (p_cb->is_le_device)
1086        bta_hh_le_write_dev_act(p_cb, p_data);
1087    else
1088#endif
1089    {
1090
1091    cbdata.handle = p_cb->hid_handle;
1092
1093    /* match up BTE/BTA report/boot mode def */
1094    if (p_data->api_sndcmd.t_type == HID_TRANS_SET_PROTOCOL)
1095    {
1096        p_data->api_sndcmd.param = ( p_data->api_sndcmd.param == BTA_HH_PROTO_RPT_MODE) ?\
1097                        HID_PAR_PROTOCOL_REPORT :HID_PAR_PROTOCOL_BOOT_MODE;
1098    }
1099
1100    if (HID_HostWriteDev (p_cb->hid_handle,
1101                       p_data->api_sndcmd.t_type,
1102                       p_data->api_sndcmd.param,
1103                       p_data->api_sndcmd.data,
1104                       p_data->api_sndcmd.rpt_id,
1105                       p_data->api_sndcmd.p_data) != HID_SUCCESS)
1106    {
1107        APPL_TRACE_ERROR("HID_HostWriteDev Error ");
1108        cbdata.status = BTA_HH_ERR;
1109
1110        if (p_data->api_sndcmd.t_type != HID_TRANS_CONTROL &&
1111            p_data->api_sndcmd.t_type != HID_TRANS_DATA)
1112            (* bta_hh_cb.p_cback)(event, (tBTA_HH *)&cbdata);
1113        else if (p_data->api_sndcmd.param == BTA_HH_CTRL_VIRTUAL_CABLE_UNPLUG)
1114            (* bta_hh_cb.p_cback)(BTA_HH_VC_UNPLUG_EVT, (tBTA_HH *)&cbdata);
1115    }
1116    else
1117    {
1118
1119        switch(p_data->api_sndcmd.t_type)
1120        {
1121        case HID_TRANS_SET_PROTOCOL:
1122            /* fall through */
1123        case HID_TRANS_GET_REPORT:
1124            /* fall through */
1125        case HID_TRANS_SET_REPORT:
1126            /* fall through */
1127        case HID_TRANS_GET_PROTOCOL:
1128            /* fall through */
1129        case HID_TRANS_GET_IDLE:
1130            /* fall through */
1131        case HID_TRANS_SET_IDLE:/* set w4_handsk event name for callback function use */
1132            p_cb->w4_evt = event;
1133            break;
1134        case HID_TRANS_DATA:  /* output report */
1135            /* fall through */
1136        case HID_TRANS_CONTROL:
1137            /* no handshake event will be generated */
1138            /* if VC_UNPLUG is issued, set flag */
1139            if (p_data->api_sndcmd.param == BTA_HH_CTRL_VIRTUAL_CABLE_UNPLUG)
1140                p_cb->vp = TRUE;
1141
1142            break;
1143        /* currently not expected */
1144        case HID_TRANS_DATAC:
1145        default:
1146            APPL_TRACE_DEBUG("bta_hh_write_dev_act:: cmd type = %d",
1147                            p_data->api_sndcmd.t_type);
1148            break;
1149        }
1150
1151        /* if not control type transaction, notify PM for energy control */
1152        if (p_data->api_sndcmd.t_type != HID_TRANS_CONTROL)
1153        {
1154            /* inform PM for mode change */
1155            bta_sys_busy(BTA_ID_HH, p_cb->app_id, p_cb->addr);
1156            bta_sys_idle(BTA_ID_HH, p_cb->app_id, p_cb->addr);
1157        }
1158        else if (p_data->api_sndcmd.param == BTA_HH_CTRL_SUSPEND)
1159        {
1160			bta_sys_sco_close(BTA_ID_HH, p_cb->app_id, p_cb->addr);
1161        }
1162        else if (p_data->api_sndcmd.param == BTA_HH_CTRL_EXIT_SUSPEND)
1163        {
1164            bta_sys_busy(BTA_ID_HH, p_cb->app_id, p_cb->addr);
1165        }
1166    }
1167
1168    }
1169    return;
1170}
1171
1172/*****************************************************************************
1173**  Static Function
1174*****************************************************************************/
1175/*******************************************************************************
1176**
1177** Function         bta_hh_cback
1178**
1179** Description      BTA HH callback function.
1180**
1181**
1182** Returns          void
1183**
1184*******************************************************************************/
1185static void bta_hh_cback (UINT8 dev_handle, BD_ADDR addr, UINT8 event,
1186                        UINT32 data, BT_HDR *pdata)
1187{
1188    tBTA_HH_CBACK_DATA    *p_buf = NULL;
1189    UINT16  sm_event = BTA_HH_INVALID_EVT;
1190    UINT8   xx = 0;
1191
1192#if BTA_HH_DEBUG
1193    APPL_TRACE_DEBUG("bta_hh_cback::HID_event [%s]", bta_hh_hid_event_name(event));
1194#endif
1195
1196    switch (event)
1197    {
1198    case HID_HDEV_EVT_OPEN:
1199        sm_event = BTA_HH_INT_OPEN_EVT;
1200        break;
1201    case HID_HDEV_EVT_CLOSE:
1202        sm_event = BTA_HH_INT_CLOSE_EVT;
1203        break;
1204    case HID_HDEV_EVT_INTR_DATA:
1205        sm_event = BTA_HH_INT_DATA_EVT;
1206        break;
1207    case HID_HDEV_EVT_HANDSHAKE:
1208        sm_event = BTA_HH_INT_HANDSK_EVT;
1209        break;
1210    case HID_HDEV_EVT_CTRL_DATA:
1211        sm_event = BTA_HH_INT_CTRL_DATA;
1212        break;
1213    case HID_HDEV_EVT_RETRYING:
1214        break;
1215    case HID_HDEV_EVT_INTR_DATC:
1216    case HID_HDEV_EVT_CTRL_DATC:
1217        /* Unhandled events: Free buffer for DATAC */
1218        utl_freebuf((void **)&pdata);
1219        break;
1220    case HID_HDEV_EVT_VC_UNPLUG:
1221        for (xx = 0; xx < BTA_HH_MAX_DEVICE; xx++)
1222        {
1223            if (bta_hh_cb.kdev[xx].hid_handle == dev_handle)
1224            {
1225               bta_hh_cb.kdev[xx].vp = TRUE;
1226               break;
1227            }
1228        }
1229        break;
1230    }
1231
1232    if (sm_event != BTA_HH_INVALID_EVT &&
1233        (p_buf = (tBTA_HH_CBACK_DATA *)GKI_getbuf(sizeof(tBTA_HH_CBACK_DATA) +
1234                    sizeof(BT_HDR))) != NULL)
1235    {
1236        p_buf->hdr.event  = sm_event;
1237        p_buf->hdr.layer_specific = (UINT16)dev_handle;
1238        p_buf->data       = data;
1239        bdcpy(p_buf->addr, addr);
1240        p_buf->p_data     = pdata;
1241
1242        bta_sys_sendmsg(p_buf);
1243    }
1244
1245}
1246/*******************************************************************************
1247**
1248** Function         bta_hh_get_trans_status
1249**
1250** Description      translate a handshake result code into BTA HH
1251**                  status code
1252**
1253*******************************************************************************/
1254static tBTA_HH_STATUS bta_hh_get_trans_status(UINT32 result)
1255{
1256    switch(result)
1257    {
1258    case HID_PAR_HANDSHAKE_RSP_SUCCESS :                /*   (0) */
1259        return BTA_HH_OK;
1260    case HID_PAR_HANDSHAKE_RSP_NOT_READY :              /*   (1) */
1261    case HID_PAR_HANDSHAKE_RSP_ERR_INVALID_REP_ID:      /*   (2) */
1262    case HID_PAR_HANDSHAKE_RSP_ERR_UNSUPPORTED_REQ :    /*   (3) */
1263    case HID_PAR_HANDSHAKE_RSP_ERR_INVALID_PARAM :      /*   (4) */
1264        return (tBTA_HH_STATUS)result;
1265    case HID_PAR_HANDSHAKE_RSP_ERR_UNKNOWN :            /*   (14) */
1266    case HID_PAR_HANDSHAKE_RSP_ERR_FATAL  :             /*   (15) */
1267    default:
1268        return BTA_HH_HS_ERROR;
1269        break;
1270    }
1271}
1272/*****************************************************************************
1273**  Debug Functions
1274*****************************************************************************/
1275
1276#if (defined BTA_HH_DEBUG && BTA_HH_DEBUG == TRUE)
1277static char* bta_hh_get_w4_event(UINT16 event)
1278{
1279    switch (event)
1280    {
1281    case BTA_HH_GET_RPT_EVT:
1282        return "BTA_HH_GET_RPT_EVT";
1283    case BTA_HH_SET_RPT_EVT:
1284        return "BTA_HH_SET_RPT_EVT";
1285    case BTA_HH_GET_PROTO_EVT:
1286        return "BTA_HH_GET_PROTO_EVT";
1287    case BTA_HH_SET_PROTO_EVT:
1288        return "BTA_HH_SET_PROTO_EVT";
1289    case BTA_HH_GET_IDLE_EVT:
1290        return "BTA_HH_GET_IDLE_EVT";
1291    case BTA_HH_SET_IDLE_EVT:
1292        return "BTA_HH_SET_IDLE_EVT";
1293    case BTA_HH_OPEN_EVT:
1294        return "BTA_HH_OPEN_EVT";
1295    default:
1296        return "Unknown event";
1297    }
1298
1299}
1300
1301static char * bta_hh_hid_event_name(UINT16 event)
1302{
1303    switch (event)
1304    {
1305    case HID_HDEV_EVT_OPEN:
1306        return "HID_HDEV_EVT_OPEN";
1307    case HID_HDEV_EVT_CLOSE:
1308        return "HID_HDEV_EVT_CLOSE";
1309    case HID_HDEV_EVT_RETRYING:
1310        return "HID_HDEV_EVT_RETRYING";
1311    case HID_HDEV_EVT_INTR_DATA:
1312        return "HID_HDEV_EVT_INTR_DATA";
1313    case HID_HDEV_EVT_INTR_DATC:
1314        return "HID_HDEV_EVT_INTR_DATC";
1315    case HID_HDEV_EVT_CTRL_DATA:
1316        return "HID_HDEV_EVT_CTRL_DATA";
1317    case HID_HDEV_EVT_CTRL_DATC:
1318        return "HID_HDEV_EVT_CTRL_DATC";
1319    case HID_HDEV_EVT_HANDSHAKE:
1320        return "HID_HDEV_EVT_HANDSHAKE";
1321    case HID_HDEV_EVT_VC_UNPLUG:
1322        return "HID_HDEV_EVT_VC_UNPLUG";
1323    default:
1324        return "Unknown HID event";
1325    }
1326}
1327#endif
1328#endif /* BTA_HH_INCLUDED */
1329
1330