OSDN Git Service

Avoid more annoying crashing
[android-x86/system-bt.git] / bta / hh / bta_hh_act.c
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 <log/log.h>
30 #include <string.h>
31
32 #include "bta_sys.h"
33 #include "btm_api.h"
34 #include "l2c_api.h"
35 #include "bta_hh_int.h"
36 #include "bta_hh_co.h"
37 #include "utl.h"
38
39 /*****************************************************************************
40 **  Constants
41 *****************************************************************************/
42
43
44 /*****************************************************************************
45 **  Local Function prototypes
46 *****************************************************************************/
47 static void bta_hh_cback (UINT8 dev_handle, BD_ADDR addr, UINT8 event,
48                             UINT32 data, BT_HDR *pdata);
49 static tBTA_HH_STATUS bta_hh_get_trans_status(UINT32 result);
50
51 #if BTA_HH_DEBUG
52 static char* bta_hh_get_w4_event(UINT16 event);
53 static char * bta_hh_hid_event_name(UINT16 event);
54 #endif
55
56 /*****************************************************************************
57 **  Action Functions
58 *****************************************************************************/
59 /*******************************************************************************
60 **
61 ** Function         bta_hh_api_enable
62 **
63 ** Description      Perform necessary operations to enable HID host.
64 **
65 **
66 ** Returns          void
67 **
68 *******************************************************************************/
69 void bta_hh_api_enable(tBTA_HH_DATA *p_data)
70 {
71     tBTA_HH_STATUS      status = BTA_HH_ERR;
72     UINT8               xx;
73
74     /* initialize BTE HID */
75     HID_HostInit();
76
77     memset(&bta_hh_cb, 0, sizeof(tBTA_HH_CB));
78
79     HID_HostSetSecurityLevel("", p_data->api_enable.sec_mask);
80
81     /* Register with L2CAP */
82     if ( HID_HostRegister (bta_hh_cback) == HID_SUCCESS)
83     {
84         /* store parameters */
85         bta_hh_cb.p_cback = p_data->api_enable.p_cback;
86
87         status = BTA_HH_OK;
88         /* initialize device CB */
89         for (xx = 0; xx < BTA_HH_MAX_DEVICE; xx ++)
90         {
91             bta_hh_cb.kdev[xx].state        = BTA_HH_IDLE_ST;
92             bta_hh_cb.kdev[xx].hid_handle   = BTA_HH_INVALID_HANDLE;
93             bta_hh_cb.kdev[xx].index        = xx;
94         }
95
96         /* initialize control block map */
97         for (xx = 0; xx < BTA_HH_MAX_KNOWN; xx ++)
98             bta_hh_cb.cb_index[xx]          = BTA_HH_IDX_INVALID;
99     }
100
101 #if (BTA_HH_LE_INCLUDED == TRUE)
102     if (status == BTA_HH_OK)
103     {
104         bta_hh_le_enable();
105     }
106     else
107 #endif
108         /* signal BTA call back event */
109         (* bta_hh_cb.p_cback)(BTA_HH_ENABLE_EVT, (tBTA_HH *)&status);
110 }
111 /*******************************************************************************
112 **
113 ** Function         bta_hh_api_disable
114 **
115 ** Description      Perform necessary operations to disable HID host.
116 **
117 **
118 ** Returns          void
119 **
120 *******************************************************************************/
121 void bta_hh_api_disable(void)
122 {
123     UINT8 xx;
124
125     /* service is not enabled */
126     if (bta_hh_cb.p_cback == NULL)
127         return;
128
129     /* no live connection, signal DISC_CMPL_EVT directly */
130     if (!bta_hh_cb.cnt_num)
131     {
132         bta_hh_disc_cmpl();
133     }
134     else /* otherwise, disconnect all live connections */
135     {
136         bta_hh_cb.w4_disable = TRUE;
137
138         for(xx = 0; xx < BTA_HH_MAX_DEVICE; xx ++)
139         {
140             /* send API_CLOSE event to every connected device */
141             if ( bta_hh_cb.kdev[xx].state == BTA_HH_CONN_ST )
142             {
143                 /* disconnect all connected devices */
144                 bta_hh_sm_execute(&bta_hh_cb.kdev[xx],
145                                 BTA_HH_API_CLOSE_EVT,
146                                 NULL);
147             }
148         }
149     }
150
151     return;
152 }
153
154 /*******************************************************************************
155 **
156 ** Function         bta_hh_disc_cmpl
157 **
158 ** Description      All connections have been closed, disable service.
159 **
160 **
161 ** Returns          void
162 **
163 *******************************************************************************/
164 void bta_hh_disc_cmpl(void)
165 {
166     tBTA_HH_STATUS  status = BTA_HH_OK;
167
168     /* Deregister with lower layer */
169     if (HID_HostDeregister() != HID_SUCCESS)
170         status = BTA_HH_ERR;
171
172 #if (BTA_HH_LE_INCLUDED == TRUE)
173     bta_hh_le_deregister();
174     UNUSED(status);
175 #else
176     bta_hh_cleanup_disable(status);
177 #endif
178 }
179
180 /*******************************************************************************
181 **
182 ** Function         bta_hh_sdp_cback
183 **
184 ** Description      SDP callback function.
185 **
186 ** Returns          void
187 **
188 *******************************************************************************/
189 static void bta_hh_sdp_cback(UINT16 result, UINT16 attr_mask,
190                                   tHID_DEV_SDP_INFO *sdp_rec )
191 {
192     tBTA_HH_DEV_CB     *p_cb = bta_hh_cb.p_cur;
193     UINT8              hdl = 0;
194     tBTA_HH_STATUS    status = BTA_HH_ERR_SDP;
195
196     /* make sure sdp succeeded and hh has not been disabled */
197     if ((result == SDP_SUCCESS) && (p_cb != NULL))
198     {
199         /* security is required for the connection, add attr_mask bit*/
200         if (p_cb->sec_mask)
201             attr_mask |= HID_SEC_REQUIRED;
202
203 #if BTA_HH_DEBUG
204         APPL_TRACE_EVENT("bta_hh_sdp_cback: p_cb: %d result 0x%02x, \
205                             attr_mask 0x%02x, handle %x", \
206                             p_cb, result, attr_mask,p_cb->hid_handle);
207 #endif
208
209         /* check to see type of device is supported , and should not been added before */
210         if (bta_hh_tod_spt(p_cb, sdp_rec->sub_class))
211         {
212             /* if not added before */
213             if (p_cb->hid_handle == BTA_HH_INVALID_HANDLE)
214             {
215                 /*  add device/update attr_mask information */
216                 if(HID_HostAddDev (p_cb->addr, attr_mask, &hdl) == HID_SUCCESS)
217                 {
218                     status = BTA_HH_OK;
219                     /* update cb_index[] map */
220                     bta_hh_cb.cb_index[hdl] = p_cb->index;
221                 }
222                 else
223                 {
224                     p_cb->app_id = 0;
225                 }
226             }
227             else
228             {
229                 hdl = p_cb->hid_handle;
230             }
231             /* else : incoming connection after SDP should update the SDP information as well */
232
233             if (p_cb->app_id != 0)
234             {
235                 /* update cb information with attr_mask, dscp_info etc. */
236                 bta_hh_add_device_to_list(p_cb,  hdl, attr_mask,
237                                             &sdp_rec->dscp_info,
238                                             sdp_rec->sub_class,
239                                             sdp_rec->ssr_max_latency,
240                                             sdp_rec->ssr_min_tout,
241                                             p_cb->app_id);
242
243                 p_cb->dscp_info.ctry_code = sdp_rec->ctry_code;
244
245                 status = BTA_HH_OK;
246             }
247
248         }
249         else /* type of device is not supported */
250             status = BTA_HH_ERR_TOD_UNSPT;
251     }
252
253     /* free disc_db when SDP is completed */
254     osi_free_and_reset((void **)&bta_hh_cb.p_disc_db);
255
256     /* send SDP_CMPL_EVT into state machine */
257     bta_hh_sm_execute(p_cb, BTA_HH_SDP_CMPL_EVT, (tBTA_HH_DATA *)&status);
258
259     return;
260 }
261 /*******************************************************************************
262 **
263 ** Function         bta_hh_di_sdp_cback
264 **
265 ** Description      SDP DI callback function.
266 **
267 ** Returns          void
268 **
269 *******************************************************************************/
270 static void bta_hh_di_sdp_cback(UINT16 result)
271 {
272     tBTA_HH_DEV_CB     *p_cb = bta_hh_cb.p_cur;
273     tBTA_HH_STATUS         status = BTA_HH_ERR_SDP;
274     tSDP_DI_GET_RECORD  di_rec;
275     tHID_STATUS ret;
276 #if BTA_HH_DEBUG
277     APPL_TRACE_EVENT("bta_hh_di_sdp_cback: p_cb: %d result 0x%02x", p_cb, result);
278 #endif
279
280     /* if DI record does not exist on remote device, vendor_id in tBTA_HH_DEV_DSCP_INFO will be
281          * set to 0xffff and we will allow the connection to go through. Spec mandates that DI
282          * record be set, but many HID devices do not set this. So for IOP purposes, we allow the
283          * connection to go through and update the DI record to invalid DI entry.*/
284     if (((result == SDP_SUCCESS) || (result == SDP_NO_RECS_MATCH)) && (p_cb != NULL))
285     {
286         if(result == SDP_SUCCESS && SDP_GetNumDiRecords(bta_hh_cb.p_disc_db) != 0)
287         {
288             /* always update information with primary DI record */
289             if (SDP_GetDiRecord(1, &di_rec, bta_hh_cb.p_disc_db) == SDP_SUCCESS)
290             {
291                 bta_hh_update_di_info(p_cb, di_rec.rec.vendor, di_rec.rec.product, di_rec.rec.version, 0);
292             }
293
294         }
295         else /* no DI recrod available */
296         {
297             bta_hh_update_di_info(p_cb, BTA_HH_VENDOR_ID_INVALID, 0, 0, 0);
298         }
299
300         if ((ret = HID_HostGetSDPRecord(p_cb->addr,
301                                  bta_hh_cb.p_disc_db,
302                                  p_bta_hh_cfg->sdp_db_size,
303                                  bta_hh_sdp_cback)) == HID_SUCCESS)
304         {
305             status = BTA_HH_OK;
306         }
307         else
308         {
309 #if BTA_HH_DEBUG
310             APPL_TRACE_DEBUG ("bta_hh_di_sdp_cback:  HID_HostGetSDPRecord failed: Status 0x%2x",
311                                ret);
312 #endif
313         }
314     }
315
316
317     if (status != BTA_HH_OK) {
318         osi_free_and_reset((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 *******************************************************************************/
339 void 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 *)osi_malloc(p_bta_hh_cfg->sdp_db_size);
388         bta_hh_cb.p_cur = p_cb;
389         /* do DI discovery first */
390         if (SDP_DiDiscover(p_data->api_conn.bd_addr,
391                            bta_hh_cb.p_disc_db,
392                            p_bta_hh_cfg->sdp_db_size,
393                            bta_hh_di_sdp_cback) != SDP_SUCCESS) {
394 #if BTA_HH_DEBUG
395             APPL_TRACE_DEBUG("bta_hh_start_sdp:  SDP_DiDiscover failed: \
396                     Status 0x%2X",status);
397 #endif
398             status = BTA_HH_ERR_SDP;
399             osi_free_and_reset((void **)&bta_hh_cb.p_disc_db);
400         } else {
401             status = BTA_HH_OK;
402         }
403     }
404
405     if (status != BTA_HH_OK)
406         bta_hh_sm_execute(p_cb, BTA_HH_SDP_CMPL_EVT, (tBTA_HH_DATA *)&status);
407
408     return;
409
410 }
411 /*******************************************************************************
412 **
413 ** Function         bta_hh_sdp_cmpl
414 **
415 ** Description      When SDP completed, initiate a connection or report error depend
416 **                  on SDP result.
417 **
418 **
419 ** Returns          void
420 **
421 *******************************************************************************/
422 void bta_hh_sdp_cmpl(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data)
423 {
424     tBTA_HH_CONN            conn_dat;
425     tBTA_HH_STATUS          status = p_data->status;
426
427 #if BTA_HH_DEBUG
428     APPL_TRACE_DEBUG ("bta_hh_sdp_cmpl:  status 0x%2X",p_data->status);
429 #endif
430
431     /* initialize call back data */
432     memset((void *)&conn_dat, 0, sizeof(tBTA_HH_CONN));
433     conn_dat.handle = p_cb->hid_handle;
434     bdcpy(conn_dat.bda, p_cb->addr);
435
436     /* if SDP compl success */
437     if ( status == BTA_HH_OK)
438     {
439         /* not incoming connection doing SDP, initiate a HID connection */
440         if (!p_cb->incoming_conn)
441         {
442             tHID_STATUS ret;
443             /* set security level */
444             HID_HostSetSecurityLevel("", p_cb->sec_mask);
445
446             /* open HID connection */
447             ret = HID_HostOpenDev (p_cb->hid_handle);
448             APPL_TRACE_DEBUG ("%s: HID_HostOpenDev returned=%d", __func__, ret);
449             if (ret == HID_SUCCESS || ret == HID_ERR_ALREADY_CONN)
450             {
451                 status = BTA_HH_OK;
452             }
453             else if (ret == HID_ERR_CONN_IN_PROCESS)
454             {
455                 /* Connection already in progress, return from here, SDP
456                  * will be performed after connection is completed.
457                  */
458                 APPL_TRACE_DEBUG ("%s: connection already in progress", __func__);
459                 return;
460             }
461             else
462             {
463 #if BTA_HH_DEBUG
464                 APPL_TRACE_DEBUG ("%s: HID_HostOpenDev failed: Status 0x%2X", __func__, ret);
465 #endif
466                 /* open fail, remove device from management device list */
467                 HID_HostRemoveDev( p_cb->hid_handle);
468                 status = BTA_HH_ERR;
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 *******************************************************************************/
519 void 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 *******************************************************************************/
553 void 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 *******************************************************************************/
620 void 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 *******************************************************************************/
663 void 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     osi_free_and_reset((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 *******************************************************************************/
685 void 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 *******************************************************************************/
758 void 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     if (pdata->len == 0) {
769         android_errorWriteLog(0x534e4554, "116108738");
770         p_cb->w4_evt = 0;
771         osi_free_and_reset((void**)&pdata);
772         return;
773     }
774     hs_data.status  = BTA_HH_OK;
775     hs_data.handle  = p_cb->hid_handle;
776
777     switch (p_cb->w4_evt)
778     {
779     case BTA_HH_GET_IDLE_EVT:
780         hs_data.rsp_data.idle_rate = *data;
781         break;
782     case BTA_HH_GET_RPT_EVT:
783         hs_data.rsp_data.p_rpt_data = pdata;
784         break;
785     case BTA_HH_GET_PROTO_EVT:
786         /* match up BTE/BTA report/boot mode def*/
787         hs_data.rsp_data.proto_mode = ((*data) == HID_PAR_PROTOCOL_REPORT)? \
788                     BTA_HH_PROTO_RPT_MODE : BTA_HH_PROTO_BOOT_MODE;
789 #if BTA_HH_DEBUG
790         APPL_TRACE_DEBUG("GET_PROTOCOL Mode = [%s]",
791             (hs_data.rsp_data.proto_mode == BTA_HH_PROTO_RPT_MODE)? "Report" : "Boot");
792 #endif
793         break;
794     /* should not expect control DATA for SET_ transaction */
795     case BTA_HH_SET_PROTO_EVT:
796         /* fall through */
797     case BTA_HH_SET_RPT_EVT:
798         /* fall through */
799     case BTA_HH_SET_IDLE_EVT :
800         /* fall through */
801     default:
802 #if BTA_HH_DEBUG
803         APPL_TRACE_DEBUG("invalid  transaction type for DATA payload: 4_evt[%s]",
804                         bta_hh_get_w4_event(p_cb->w4_evt));
805 #endif
806         break;
807     }
808
809     /* inform PM for mode change */
810     bta_sys_busy(BTA_ID_HH, p_cb->app_id, p_cb->addr);
811     bta_sys_idle(BTA_ID_HH, p_cb->app_id, p_cb->addr);
812
813     (* bta_hh_cb.p_cback)(p_cb->w4_evt, (tBTA_HH *)&hs_data);
814
815     p_cb->w4_evt = 0;
816     osi_free_and_reset((void **)&pdata);
817
818 }
819
820 /*******************************************************************************
821 **
822 ** Function         bta_hh_open_failure
823 **
824 ** Description      report HID open failure when at wait for connection state and receive
825 **                  device close event.
826 **
827 **
828 ** Returns          void
829 **
830 *******************************************************************************/
831 void bta_hh_open_failure(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data)
832 {
833     tBTA_HH_CONN            conn_dat ;
834     UINT32                  reason = p_data->hid_cback.data;    /* Reason for closing (32-bit) */
835
836     memset(&conn_dat, 0, sizeof(tBTA_HH_CONN));
837      conn_dat.handle = p_cb->hid_handle;
838      conn_dat.status = (reason == HID_ERR_AUTH_FAILED) ?
839                                     BTA_HH_ERR_AUTH_FAILED : BTA_HH_ERR;
840      bdcpy(conn_dat.bda, p_cb->addr);
841      HID_HostCloseDev(p_cb->hid_handle);
842
843      /* Report OPEN fail event */
844      (*bta_hh_cb.p_cback)(BTA_HH_OPEN_EVT, (tBTA_HH *)&conn_dat);
845
846 #if BTA_HH_DEBUG
847     bta_hh_trace_dev_db();
848 #endif
849     /* clean up control block, but retain SDP info and device handle */
850     p_cb->vp            = FALSE;
851     p_cb->w4_evt        = 0;
852
853     /* if no connection is active and HH disable is signaled, disable service */
854     if (bta_hh_cb.cnt_num == 0 && bta_hh_cb.w4_disable)
855     {
856         bta_hh_disc_cmpl();
857     }
858
859     /* Error in opening hid connection, reset flags */
860     p_cb->incoming_conn = FALSE;
861     p_cb->incoming_hid_handle = BTA_HH_INVALID_HANDLE;
862 }
863
864 /*******************************************************************************
865 **
866 ** Function         bta_hh_close_act
867 **
868 ** Description      HID Host process a close event
869 **
870 **
871 ** Returns          void
872 **
873 *******************************************************************************/
874 void bta_hh_close_act (tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data)
875 {
876     tBTA_HH_CONN            conn_dat ;
877     tBTA_HH_CBDATA          disc_dat = {BTA_HH_OK, 0};
878     UINT32                  reason = p_data->hid_cback.data;    /* Reason for closing (32-bit) */
879
880     /* if HID_HDEV_EVT_VC_UNPLUG was received, report BTA_HH_VC_UNPLUG_EVT */
881     UINT16     event = p_cb->vp ? BTA_HH_VC_UNPLUG_EVT : BTA_HH_CLOSE_EVT;
882
883     disc_dat.handle = p_cb->hid_handle;
884     disc_dat.status = p_data->hid_cback.data;
885
886     /* Check reason for closing */
887     if ((reason & (HID_L2CAP_CONN_FAIL|HID_L2CAP_REQ_FAIL)) ||  /* Failure to initialize connection (page timeout or l2cap error) */
888         (reason == HID_ERR_AUTH_FAILED) ||                      /* Authenication error (while initiating) */
889         (reason == HID_ERR_L2CAP_FAILED))                       /* Failure creating l2cap connection */
890     {
891         /* Failure in opening connection */
892         conn_dat.handle = p_cb->hid_handle;
893         conn_dat.status = (reason == HID_ERR_AUTH_FAILED) ? BTA_HH_ERR_AUTH_FAILED : BTA_HH_ERR;
894         bdcpy(conn_dat.bda, p_cb->addr);
895         HID_HostCloseDev(p_cb->hid_handle);
896
897         /* Report OPEN fail event */
898         (*bta_hh_cb.p_cback)(BTA_HH_OPEN_EVT, (tBTA_HH *)&conn_dat);
899
900 #if BTA_HH_DEBUG
901         bta_hh_trace_dev_db();
902 #endif
903         return;
904     }
905     /* otherwise report CLOSE/VC_UNPLUG event */
906     else
907     {
908         /* finaliza device driver */
909         bta_hh_co_close(p_cb->hid_handle, p_cb->app_id);
910         /* inform role manager */
911         bta_sys_conn_close( BTA_ID_HH ,p_cb->app_id, p_cb->addr);
912         /* update total conn number */
913         bta_hh_cb.cnt_num --;
914
915         if (disc_dat.status)
916             disc_dat.status = BTA_HH_ERR;
917
918         (*bta_hh_cb.p_cback)(event, (tBTA_HH *)&disc_dat);
919
920         /* if virtually unplug, remove device */
921         if (p_cb->vp )
922         {
923             HID_HostRemoveDev( p_cb->hid_handle);
924             bta_hh_clean_up_kdev(p_cb);
925         }
926
927 #if BTA_HH_DEBUG
928         bta_hh_trace_dev_db();
929 #endif
930     }
931
932     /* clean up control block, but retain SDP info and device handle */
933     p_cb->vp            = FALSE;
934     p_cb->w4_evt        = 0;
935
936     /* if no connection is active and HH disable is signaled, disable service */
937     if (bta_hh_cb.cnt_num == 0 && bta_hh_cb.w4_disable)
938     {
939         bta_hh_disc_cmpl();
940     }
941
942     return;
943 }
944
945 /*******************************************************************************
946 **
947 ** Function         bta_hh_get_dscp_act
948 **
949 ** Description      Get device report descriptor
950 **
951 **
952 ** Returns          void
953 **
954 *******************************************************************************/
955 void bta_hh_get_dscp_act(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data)
956 {
957     UNUSED(p_data);
958
959 #if (BTA_HH_LE_INCLUDED == TRUE)
960     if (p_cb->is_le_device)
961     {
962         bta_hh_le_get_dscp_act(p_cb);
963     }
964     else
965 #endif
966     (*bta_hh_cb.p_cback)(BTA_HH_GET_DSCP_EVT, (tBTA_HH *)&p_cb->dscp_info);
967 }
968
969 /*******************************************************************************
970 **
971 ** Function         bta_hh_maint_dev_act
972 **
973 ** Description      HID Host maintain device list.
974 **
975 **
976 ** Returns          void
977 **
978 *******************************************************************************/
979 void bta_hh_maint_dev_act(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data)
980 {
981     tBTA_HH_MAINT_DEV       *p_dev_info = &p_data->api_maintdev;
982     tBTA_HH_DEV_INFO        dev_info ;
983     UINT8                   dev_handle;
984
985     dev_info.status = BTA_HH_ERR;
986     dev_info.handle = BTA_HH_INVALID_HANDLE;
987
988     switch (p_dev_info->sub_event)
989     {
990     case BTA_HH_ADD_DEV_EVT:    /* add a device */
991         bdcpy(dev_info.bda, p_dev_info->bda);
992         /* initialize callback data */
993         if (p_cb->hid_handle == BTA_HH_INVALID_HANDLE)
994         {
995 #if (BTA_HH_LE_INCLUDED == TRUE)
996             if (bta_hh_is_le_device(p_cb, p_data->api_conn.bd_addr))
997             {
998                 dev_info.handle   = bta_hh_le_add_device(p_cb, p_dev_info);
999                 dev_info.status   = BTA_HH_OK;
1000             }
1001             else
1002 #endif
1003
1004             if (HID_HostAddDev(p_dev_info->bda, p_dev_info->attr_mask, &dev_handle)\
1005                             == HID_SUCCESS)
1006             {
1007                 dev_info.handle   = dev_handle;
1008                 dev_info.status   = BTA_HH_OK;
1009
1010 #if (defined BTA_HH_LE_INCLUDED && BTA_HH_LE_INCLUDED == TRUE)
1011                 /* update DI information */
1012                 bta_hh_update_di_info(p_cb,
1013                                       p_dev_info->dscp_info.vendor_id,
1014                                       p_dev_info->dscp_info.product_id,
1015                                       p_dev_info->dscp_info.version,
1016                                       p_dev_info->dscp_info.flag);
1017 #else
1018                 bta_hh_update_di_info(p_cb,
1019                                       p_dev_info->dscp_info.vendor_id,
1020                                       p_dev_info->dscp_info.product_id,
1021                                       p_dev_info->dscp_info.version,
1022                                       0);
1023
1024 #endif
1025                 /* add to BTA device list */
1026                 bta_hh_add_device_to_list(p_cb, dev_handle,
1027                                           p_dev_info->attr_mask,
1028                                           &p_dev_info->dscp_info.descriptor,
1029                                           p_dev_info->sub_class,
1030                                           p_dev_info->dscp_info.ssr_max_latency,
1031                                           p_dev_info->dscp_info.ssr_min_tout,
1032                                           p_dev_info->app_id);
1033                 /* update cb_index[] map */
1034                 bta_hh_cb.cb_index[dev_handle] = p_cb->index;
1035             }
1036         }
1037         else    /* device already been added */
1038         {
1039             dev_info.handle = p_cb->hid_handle;
1040             dev_info.status = BTA_HH_OK;
1041         }
1042 #if BTA_HH_DEBUG
1043         bta_hh_trace_dev_db();
1044 #endif
1045
1046         break;
1047     case BTA_HH_RMV_DEV_EVT:    /* remove device */
1048         dev_info.handle = (UINT8)p_dev_info->hdr.layer_specific;
1049         bdcpy(dev_info.bda, p_cb->addr);
1050
1051 #if BTA_HH_LE_INCLUDED == TRUE
1052         if (p_cb->is_le_device)
1053         {
1054             bta_hh_le_remove_dev_bg_conn(p_cb);
1055             bta_hh_sm_execute(p_cb, BTA_HH_API_CLOSE_EVT, NULL);
1056             bta_hh_clean_up_kdev(p_cb);
1057         }
1058         else
1059 #endif
1060         {
1061             if(HID_HostRemoveDev( dev_info.handle ) == HID_SUCCESS)
1062             {
1063                 dev_info.status  = BTA_HH_OK;
1064
1065                 /* remove from known device list in BTA */
1066                 bta_hh_clean_up_kdev(p_cb);
1067             }
1068         }
1069         break;
1070
1071     default:
1072         APPL_TRACE_DEBUG("invalid command");
1073         break;
1074     }
1075
1076     (* bta_hh_cb.p_cback)(p_dev_info->sub_event, (tBTA_HH *)&dev_info);
1077 }
1078 /*******************************************************************************
1079 **
1080 ** Function         bta_hh_write_dev_act
1081 **
1082 ** Description      Write device action. can be SET/GET/DATA transaction.
1083 **
1084 ** Returns          void
1085 **
1086 *******************************************************************************/
1087 void bta_hh_write_dev_act(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data)
1088 {
1089     tBTA_HH_CBDATA     cbdata = {BTA_HH_OK, 0};
1090     UINT16  event = (p_data->api_sndcmd.t_type - BTA_HH_FST_BTE_TRANS_EVT) +
1091                         BTA_HH_FST_TRANS_CB_EVT;
1092
1093 #if BTA_HH_LE_INCLUDED == TRUE
1094     if (p_cb->is_le_device)
1095         bta_hh_le_write_dev_act(p_cb, p_data);
1096     else
1097 #endif
1098     {
1099
1100     cbdata.handle = p_cb->hid_handle;
1101
1102     /* match up BTE/BTA report/boot mode def */
1103     if (p_data->api_sndcmd.t_type == HID_TRANS_SET_PROTOCOL)
1104     {
1105         p_data->api_sndcmd.param = ( p_data->api_sndcmd.param == BTA_HH_PROTO_RPT_MODE) ?\
1106                         HID_PAR_PROTOCOL_REPORT :HID_PAR_PROTOCOL_BOOT_MODE;
1107     }
1108
1109     if (HID_HostWriteDev (p_cb->hid_handle,
1110                        p_data->api_sndcmd.t_type,
1111                        p_data->api_sndcmd.param,
1112                        p_data->api_sndcmd.data,
1113                        p_data->api_sndcmd.rpt_id,
1114                        p_data->api_sndcmd.p_data) != HID_SUCCESS)
1115     {
1116         APPL_TRACE_ERROR("HID_HostWriteDev Error ");
1117         cbdata.status = BTA_HH_ERR;
1118
1119         if (p_data->api_sndcmd.t_type != HID_TRANS_CONTROL &&
1120             p_data->api_sndcmd.t_type != HID_TRANS_DATA)
1121             (* bta_hh_cb.p_cback)(event, (tBTA_HH *)&cbdata);
1122         else if (p_data->api_sndcmd.param == BTA_HH_CTRL_VIRTUAL_CABLE_UNPLUG)
1123             (* bta_hh_cb.p_cback)(BTA_HH_VC_UNPLUG_EVT, (tBTA_HH *)&cbdata);
1124     }
1125     else
1126     {
1127
1128         switch(p_data->api_sndcmd.t_type)
1129         {
1130         case HID_TRANS_SET_PROTOCOL:
1131             /* fall through */
1132         case HID_TRANS_GET_REPORT:
1133             /* fall through */
1134         case HID_TRANS_SET_REPORT:
1135             /* fall through */
1136         case HID_TRANS_GET_PROTOCOL:
1137             /* fall through */
1138         case HID_TRANS_GET_IDLE:
1139             /* fall through */
1140         case HID_TRANS_SET_IDLE:/* set w4_handsk event name for callback function use */
1141             p_cb->w4_evt = event;
1142             break;
1143         case HID_TRANS_DATA:  /* output report */
1144             /* fall through */
1145         case HID_TRANS_CONTROL:
1146             /* no handshake event will be generated */
1147             /* if VC_UNPLUG is issued, set flag */
1148             if (p_data->api_sndcmd.param == BTA_HH_CTRL_VIRTUAL_CABLE_UNPLUG)
1149                 p_cb->vp = TRUE;
1150
1151             break;
1152         /* currently not expected */
1153         case HID_TRANS_DATAC:
1154         default:
1155             APPL_TRACE_DEBUG("bta_hh_write_dev_act:: cmd type = %d",
1156                             p_data->api_sndcmd.t_type);
1157             break;
1158         }
1159
1160         /* if not control type transaction, notify PM for energy control */
1161         if (p_data->api_sndcmd.t_type != HID_TRANS_CONTROL)
1162         {
1163             /* inform PM for mode change */
1164             bta_sys_busy(BTA_ID_HH, p_cb->app_id, p_cb->addr);
1165             bta_sys_idle(BTA_ID_HH, p_cb->app_id, p_cb->addr);
1166         }
1167         else if (p_data->api_sndcmd.param == BTA_HH_CTRL_SUSPEND)
1168         {
1169                         bta_sys_sco_close(BTA_ID_HH, p_cb->app_id, p_cb->addr);
1170         }
1171         else if (p_data->api_sndcmd.param == BTA_HH_CTRL_EXIT_SUSPEND)
1172         {
1173             bta_sys_busy(BTA_ID_HH, p_cb->app_id, p_cb->addr);
1174         }
1175     }
1176
1177     }
1178     return;
1179 }
1180
1181 /*****************************************************************************
1182 **  Static Function
1183 *****************************************************************************/
1184 /*******************************************************************************
1185 **
1186 ** Function         bta_hh_cback
1187 **
1188 ** Description      BTA HH callback function.
1189 **
1190 **
1191 ** Returns          void
1192 **
1193 *******************************************************************************/
1194 static void bta_hh_cback (UINT8 dev_handle, BD_ADDR addr, UINT8 event,
1195                         UINT32 data, BT_HDR *pdata)
1196 {
1197     UINT16  sm_event = BTA_HH_INVALID_EVT;
1198     UINT8   xx = 0;
1199
1200 #if BTA_HH_DEBUG
1201     APPL_TRACE_DEBUG("bta_hh_cback::HID_event [%s]", bta_hh_hid_event_name(event));
1202 #endif
1203
1204     switch (event)
1205     {
1206     case HID_HDEV_EVT_OPEN:
1207         sm_event = BTA_HH_INT_OPEN_EVT;
1208         break;
1209     case HID_HDEV_EVT_CLOSE:
1210         sm_event = BTA_HH_INT_CLOSE_EVT;
1211         break;
1212     case HID_HDEV_EVT_INTR_DATA:
1213         sm_event = BTA_HH_INT_DATA_EVT;
1214         break;
1215     case HID_HDEV_EVT_HANDSHAKE:
1216         sm_event = BTA_HH_INT_HANDSK_EVT;
1217         break;
1218     case HID_HDEV_EVT_CTRL_DATA:
1219         sm_event = BTA_HH_INT_CTRL_DATA;
1220         break;
1221     case HID_HDEV_EVT_RETRYING:
1222         break;
1223     case HID_HDEV_EVT_INTR_DATC:
1224     case HID_HDEV_EVT_CTRL_DATC:
1225         /* Unhandled events: Free buffer for DATAC */
1226         osi_free_and_reset((void **)&pdata);
1227         break;
1228     case HID_HDEV_EVT_VC_UNPLUG:
1229         for (xx = 0; xx < BTA_HH_MAX_DEVICE; xx++)
1230         {
1231             if (bta_hh_cb.kdev[xx].hid_handle == dev_handle)
1232             {
1233                bta_hh_cb.kdev[xx].vp = TRUE;
1234                break;
1235             }
1236         }
1237         break;
1238     }
1239
1240     if (sm_event != BTA_HH_INVALID_EVT) {
1241         tBTA_HH_CBACK_DATA *p_buf =
1242             (tBTA_HH_CBACK_DATA *)osi_malloc(sizeof(tBTA_HH_CBACK_DATA) +
1243                                              sizeof(BT_HDR));
1244         p_buf->hdr.event = sm_event;
1245         p_buf->hdr.layer_specific = (UINT16)dev_handle;
1246         p_buf->data = data;
1247         bdcpy(p_buf->addr, addr);
1248         p_buf->p_data = pdata;
1249
1250         bta_sys_sendmsg(p_buf);
1251     }
1252 }
1253
1254 /*******************************************************************************
1255 **
1256 ** Function         bta_hh_get_trans_status
1257 **
1258 ** Description      translate a handshake result code into BTA HH
1259 **                  status code
1260 **
1261 *******************************************************************************/
1262 static tBTA_HH_STATUS bta_hh_get_trans_status(UINT32 result)
1263 {
1264     switch(result)
1265     {
1266     case HID_PAR_HANDSHAKE_RSP_SUCCESS :                /*   (0) */
1267         return BTA_HH_OK;
1268     case HID_PAR_HANDSHAKE_RSP_NOT_READY :              /*   (1) */
1269     case HID_PAR_HANDSHAKE_RSP_ERR_INVALID_REP_ID:      /*   (2) */
1270     case HID_PAR_HANDSHAKE_RSP_ERR_UNSUPPORTED_REQ :    /*   (3) */
1271     case HID_PAR_HANDSHAKE_RSP_ERR_INVALID_PARAM :      /*   (4) */
1272         return (tBTA_HH_STATUS)result;
1273     case HID_PAR_HANDSHAKE_RSP_ERR_UNKNOWN :            /*   (14) */
1274     case HID_PAR_HANDSHAKE_RSP_ERR_FATAL  :             /*   (15) */
1275     default:
1276         return BTA_HH_HS_ERROR;
1277         break;
1278     }
1279 }
1280 /*****************************************************************************
1281 **  Debug Functions
1282 *****************************************************************************/
1283
1284 #if (defined BTA_HH_DEBUG && BTA_HH_DEBUG == TRUE)
1285 static char* bta_hh_get_w4_event(UINT16 event)
1286 {
1287     switch (event)
1288     {
1289     case BTA_HH_GET_RPT_EVT:
1290         return "BTA_HH_GET_RPT_EVT";
1291     case BTA_HH_SET_RPT_EVT:
1292         return "BTA_HH_SET_RPT_EVT";
1293     case BTA_HH_GET_PROTO_EVT:
1294         return "BTA_HH_GET_PROTO_EVT";
1295     case BTA_HH_SET_PROTO_EVT:
1296         return "BTA_HH_SET_PROTO_EVT";
1297     case BTA_HH_GET_IDLE_EVT:
1298         return "BTA_HH_GET_IDLE_EVT";
1299     case BTA_HH_SET_IDLE_EVT:
1300         return "BTA_HH_SET_IDLE_EVT";
1301     case BTA_HH_OPEN_EVT:
1302         return "BTA_HH_OPEN_EVT";
1303     default:
1304         return "Unknown event";
1305     }
1306
1307 }
1308
1309 static char * bta_hh_hid_event_name(UINT16 event)
1310 {
1311     switch (event)
1312     {
1313     case HID_HDEV_EVT_OPEN:
1314         return "HID_HDEV_EVT_OPEN";
1315     case HID_HDEV_EVT_CLOSE:
1316         return "HID_HDEV_EVT_CLOSE";
1317     case HID_HDEV_EVT_RETRYING:
1318         return "HID_HDEV_EVT_RETRYING";
1319     case HID_HDEV_EVT_INTR_DATA:
1320         return "HID_HDEV_EVT_INTR_DATA";
1321     case HID_HDEV_EVT_INTR_DATC:
1322         return "HID_HDEV_EVT_INTR_DATC";
1323     case HID_HDEV_EVT_CTRL_DATA:
1324         return "HID_HDEV_EVT_CTRL_DATA";
1325     case HID_HDEV_EVT_CTRL_DATC:
1326         return "HID_HDEV_EVT_CTRL_DATC";
1327     case HID_HDEV_EVT_HANDSHAKE:
1328         return "HID_HDEV_EVT_HANDSHAKE";
1329     case HID_HDEV_EVT_VC_UNPLUG:
1330         return "HID_HDEV_EVT_VC_UNPLUG";
1331     default:
1332         return "Unknown HID event";
1333     }
1334 }
1335 #endif
1336 #endif /* BTA_HH_INCLUDED */
1337