OSDN Git Service

Simplify BTA_GATTC_Listen
[android-x86/system-bt.git] / bta / gatt / bta_gattc_main.cc
1 /******************************************************************************
2  *
3  *  Copyright (C) 2003-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 GATT client main functions and state machine.
22  *
23  ******************************************************************************/
24
25 #include "bt_target.h"
26
27 #if (BTA_GATT_INCLUDED == TRUE)
28
29 #include <string.h>
30
31 #include "bta_gattc_int.h"
32 #include "bt_common.h"
33
34
35 /*****************************************************************************
36 ** Constants and types
37 *****************************************************************************/
38
39
40 /* state machine action enumeration list */
41 enum
42 {
43     BTA_GATTC_OPEN,
44     BTA_GATTC_OPEN_FAIL,
45     BTA_GATTC_OPEN_ERROR,
46     BTA_GATTC_CANCEL_OPEN,
47     BTA_GATTC_CANCEL_OPEN_OK,
48     BTA_GATTC_CANCEL_OPEN_ERROR,
49     BTA_GATTC_CONN,
50     BTA_GATTC_START_DISCOVER,
51     BTA_GATTC_DISC_CMPL,
52
53     BTA_GATTC_Q_CMD,
54     BTA_GATTC_CLOSE,
55     BTA_GATTC_CLOSE_FAIL,
56     BTA_GATTC_READ,
57     BTA_GATTC_WRITE,
58
59     BTA_GATTC_OP_CMPL,
60     BTA_GATTC_SEARCH,
61     BTA_GATTC_FAIL,
62     BTA_GATTC_CONFIRM,
63     BTA_GATTC_EXEC,
64     BTA_GATTC_READ_MULTI,
65     BTA_GATTC_IGNORE_OP_CMPL,
66     BTA_GATTC_DISC_CLOSE,
67     BTA_GATTC_RESTART_DISCOVER,
68     BTA_GATTC_CFG_MTU,
69
70     BTA_GATTC_IGNORE
71 };
72 /* type for action functions */
73 typedef void (*tBTA_GATTC_ACTION)(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data);
74
75 /* action function list */
76 const tBTA_GATTC_ACTION bta_gattc_action[] =
77 {
78     bta_gattc_open,
79     bta_gattc_open_fail,
80     bta_gattc_open_error,
81     bta_gattc_cancel_open,
82     bta_gattc_cancel_open_ok,
83     bta_gattc_cancel_open_error,
84     bta_gattc_conn,
85     bta_gattc_start_discover,
86     bta_gattc_disc_cmpl,
87
88     bta_gattc_q_cmd,
89     bta_gattc_close,
90     bta_gattc_close_fail,
91     bta_gattc_read,
92     bta_gattc_write,
93
94     bta_gattc_op_cmpl,
95     bta_gattc_search,
96     bta_gattc_fail,
97     bta_gattc_confirm,
98     bta_gattc_execute,
99     bta_gattc_read_multi,
100     bta_gattc_ignore_op_cmpl,
101     bta_gattc_disc_close,
102     bta_gattc_restart_discover,
103     bta_gattc_cfg_mtu
104 };
105
106
107 /* state table information */
108 #define BTA_GATTC_ACTIONS           1       /* number of actions */
109 #define BTA_GATTC_NEXT_STATE          1       /* position of next state */
110 #define BTA_GATTC_NUM_COLS            2       /* number of columns in state tables */
111
112 /* state table for idle state */
113 static const uint8_t bta_gattc_st_idle[][BTA_GATTC_NUM_COLS] =
114 {
115 /* Event                            Action 1                  Next state */
116 /* BTA_GATTC_API_OPEN_EVT           */   {BTA_GATTC_OPEN,              BTA_GATTC_W4_CONN_ST},
117 /* BTA_GATTC_INT_OPEN_FAIL_EVT      */   {BTA_GATTC_IGNORE,            BTA_GATTC_IDLE_ST},
118 /* BTA_GATTC_API_CANCEL_OPEN_EVT    */   {BTA_GATTC_IGNORE,            BTA_GATTC_IDLE_ST},
119 /* BTA_GATTC_INT_CANCEL_OPEN_OK_EVT */   {BTA_GATTC_IGNORE,            BTA_GATTC_IDLE_ST},
120
121 /* BTA_GATTC_API_READ_EVT           */   {BTA_GATTC_FAIL,              BTA_GATTC_IDLE_ST},
122 /* BTA_GATTC_API_WRITE_EVT          */   {BTA_GATTC_FAIL,              BTA_GATTC_IDLE_ST},
123 /* BTA_GATTC_API_EXEC_EVT           */   {BTA_GATTC_FAIL,              BTA_GATTC_IDLE_ST},
124 /* BTA_GATTC_API_CFG_MTU_EVT        */   {BTA_GATTC_IGNORE,            BTA_GATTC_IDLE_ST},
125
126 /* BTA_GATTC_API_CLOSE_EVT          */   {BTA_GATTC_CLOSE_FAIL,        BTA_GATTC_IDLE_ST},
127
128 /* BTA_GATTC_API_SEARCH_EVT         */   {BTA_GATTC_FAIL,              BTA_GATTC_IDLE_ST},
129 /* BTA_GATTC_API_CONFIRM_EVT        */   {BTA_GATTC_FAIL,              BTA_GATTC_IDLE_ST},
130 /* BTA_GATTC_API_READ_MULTI_EVT     */   {BTA_GATTC_FAIL,              BTA_GATTC_IDLE_ST},
131 /* BTA_GATTC_API_REFRESH_EVT        */   {BTA_GATTC_IGNORE,            BTA_GATTC_IDLE_ST},
132
133 /* BTA_GATTC_INT_CONN_EVT           */   {BTA_GATTC_CONN,              BTA_GATTC_CONN_ST},
134 /* BTA_GATTC_INT_DISCOVER_EVT       */   {BTA_GATTC_IGNORE,            BTA_GATTC_IDLE_ST},
135 /* BTA_GATTC_DISCOVER_CMPL_EVT      */   {BTA_GATTC_IGNORE,            BTA_GATTC_IDLE_ST},
136 /* BTA_GATTC_OP_CMPL_EVT            */   {BTA_GATTC_IGNORE,            BTA_GATTC_IDLE_ST},
137 /* BTA_GATTC_INT_DISCONN_EVT       */    {BTA_GATTC_IGNORE,            BTA_GATTC_IDLE_ST},
138
139 };
140
141 /* state table for wait for open state */
142 static const uint8_t bta_gattc_st_w4_conn[][BTA_GATTC_NUM_COLS] =
143 {
144 /* Event                            Action 1                             Next state */
145 /* BTA_GATTC_API_OPEN_EVT           */   {BTA_GATTC_OPEN,              BTA_GATTC_W4_CONN_ST},
146 /* BTA_GATTC_INT_OPEN_FAIL_EVT      */   {BTA_GATTC_OPEN_FAIL,         BTA_GATTC_IDLE_ST},
147 /* BTA_GATTC_API_CANCEL_OPEN_EVT    */   {BTA_GATTC_CANCEL_OPEN,       BTA_GATTC_W4_CONN_ST},
148 /* BTA_GATTC_INT_CANCEL_OPEN_OK_EVT */   {BTA_GATTC_CANCEL_OPEN_OK,    BTA_GATTC_IDLE_ST},
149
150 /* BTA_GATTC_API_READ_EVT           */   {BTA_GATTC_FAIL,               BTA_GATTC_W4_CONN_ST},
151 /* BTA_GATTC_API_WRITE_EVT          */   {BTA_GATTC_FAIL,               BTA_GATTC_W4_CONN_ST},
152 /* BTA_GATTC_API_EXEC_EVT           */   {BTA_GATTC_FAIL,               BTA_GATTC_W4_CONN_ST},
153 /* BTA_GATTC_API_CFG_MTU_EVT        */   {BTA_GATTC_IGNORE,             BTA_GATTC_W4_CONN_ST},
154
155 /* BTA_GATTC_API_CLOSE_EVT          */   {BTA_GATTC_CANCEL_OPEN,         BTA_GATTC_W4_CONN_ST},
156
157 /* BTA_GATTC_API_SEARCH_EVT         */   {BTA_GATTC_FAIL,               BTA_GATTC_W4_CONN_ST},
158 /* BTA_GATTC_API_CONFIRM_EVT        */   {BTA_GATTC_FAIL,               BTA_GATTC_W4_CONN_ST},
159 /* BTA_GATTC_API_READ_MULTI_EVT     */   {BTA_GATTC_FAIL,               BTA_GATTC_W4_CONN_ST},
160 /* BTA_GATTC_API_REFRESH_EVT        */   {BTA_GATTC_IGNORE,             BTA_GATTC_W4_CONN_ST},
161
162 /* BTA_GATTC_INT_CONN_EVT           */   {BTA_GATTC_CONN,               BTA_GATTC_CONN_ST},
163 /* BTA_GATTC_INT_DISCOVER_EVT       */   {BTA_GATTC_IGNORE,             BTA_GATTC_W4_CONN_ST},
164 /* BTA_GATTC_DISCOVER_CMPL_EVT       */  {BTA_GATTC_IGNORE,             BTA_GATTC_W4_CONN_ST},
165 /* BTA_GATTC_OP_CMPL_EVT            */   {BTA_GATTC_IGNORE,             BTA_GATTC_W4_CONN_ST},
166 /* BTA_GATTC_INT_DISCONN_EVT      */     {BTA_GATTC_OPEN_FAIL,          BTA_GATTC_IDLE_ST},
167
168 };
169
170 /* state table for open state */
171 static const uint8_t bta_gattc_st_connected[][BTA_GATTC_NUM_COLS] =
172 {
173 /* Event                            Action 1                            Next state */
174 /* BTA_GATTC_API_OPEN_EVT           */   {BTA_GATTC_OPEN,               BTA_GATTC_CONN_ST},
175 /* BTA_GATTC_INT_OPEN_FAIL_EVT      */   {BTA_GATTC_IGNORE,             BTA_GATTC_CONN_ST},
176 /* BTA_GATTC_API_CANCEL_OPEN_EVT    */   {BTA_GATTC_CANCEL_OPEN_ERROR, BTA_GATTC_CONN_ST},
177 /* BTA_GATTC_INT_CANCEL_OPEN_OK_EVT */   {BTA_GATTC_IGNORE,            BTA_GATTC_CONN_ST},
178
179 /* BTA_GATTC_API_READ_EVT           */   {BTA_GATTC_READ,               BTA_GATTC_CONN_ST},
180 /* BTA_GATTC_API_WRITE_EVT          */   {BTA_GATTC_WRITE,              BTA_GATTC_CONN_ST},
181 /* BTA_GATTC_API_EXEC_EVT           */   {BTA_GATTC_EXEC,               BTA_GATTC_CONN_ST},
182 /* BTA_GATTC_API_CFG_MTU_EVT        */   {BTA_GATTC_CFG_MTU,            BTA_GATTC_CONN_ST},
183
184 /* BTA_GATTC_API_CLOSE_EVT          */   {BTA_GATTC_CLOSE,              BTA_GATTC_IDLE_ST},
185
186 /* BTA_GATTC_API_SEARCH_EVT         */   {BTA_GATTC_SEARCH,             BTA_GATTC_CONN_ST},
187 /* BTA_GATTC_API_CONFIRM_EVT        */   {BTA_GATTC_CONFIRM,            BTA_GATTC_CONN_ST},
188 /* BTA_GATTC_API_READ_MULTI_EVT     */   {BTA_GATTC_READ_MULTI,         BTA_GATTC_CONN_ST},
189 /* BTA_GATTC_API_REFRESH_EVT        */   {BTA_GATTC_IGNORE,             BTA_GATTC_CONN_ST},
190
191 /* BTA_GATTC_INT_CONN_EVT           */   {BTA_GATTC_IGNORE,             BTA_GATTC_CONN_ST},
192 /* BTA_GATTC_INT_DISCOVER_EVT       */   {BTA_GATTC_START_DISCOVER,     BTA_GATTC_DISCOVER_ST},
193 /* BTA_GATTC_DISCOVER_CMPL_EVT       */  {BTA_GATTC_IGNORE,             BTA_GATTC_CONN_ST},
194 /* BTA_GATTC_OP_CMPL_EVT            */   {BTA_GATTC_OP_CMPL,            BTA_GATTC_CONN_ST},
195
196 /* BTA_GATTC_INT_DISCONN_EVT        */   {BTA_GATTC_CLOSE,              BTA_GATTC_IDLE_ST},
197
198 };
199
200 /* state table for discover state */
201 static const uint8_t bta_gattc_st_discover[][BTA_GATTC_NUM_COLS] =
202 {
203 /* Event                            Action 1                            Next state */
204 /* BTA_GATTC_API_OPEN_EVT           */   {BTA_GATTC_OPEN,               BTA_GATTC_DISCOVER_ST},
205 /* BTA_GATTC_INT_OPEN_FAIL_EVT      */   {BTA_GATTC_IGNORE,             BTA_GATTC_DISCOVER_ST},
206 /* BTA_GATTC_API_CANCEL_OPEN_EVT    */   {BTA_GATTC_CANCEL_OPEN_ERROR,  BTA_GATTC_DISCOVER_ST},
207 /* BTA_GATTC_INT_CANCEL_OPEN_OK_EVT */   {BTA_GATTC_FAIL,               BTA_GATTC_DISCOVER_ST},
208
209 /* BTA_GATTC_API_READ_EVT           */   {BTA_GATTC_Q_CMD,              BTA_GATTC_DISCOVER_ST},
210 /* BTA_GATTC_API_WRITE_EVT          */   {BTA_GATTC_Q_CMD,              BTA_GATTC_DISCOVER_ST},
211 /* BTA_GATTC_API_EXEC_EVT           */   {BTA_GATTC_Q_CMD,              BTA_GATTC_DISCOVER_ST},
212 /* BTA_GATTC_API_CFG_MTU_EVT        */   {BTA_GATTC_Q_CMD,              BTA_GATTC_DISCOVER_ST},
213
214 /* BTA_GATTC_API_CLOSE_EVT          */   {BTA_GATTC_DISC_CLOSE,         BTA_GATTC_DISCOVER_ST},
215
216 /* BTA_GATTC_API_SEARCH_EVT         */   {BTA_GATTC_Q_CMD,              BTA_GATTC_DISCOVER_ST},
217 /* BTA_GATTC_API_CONFIRM_EVT        */   {BTA_GATTC_CONFIRM,            BTA_GATTC_DISCOVER_ST},
218 /* BTA_GATTC_API_READ_MULTI_EVT     */   {BTA_GATTC_Q_CMD,              BTA_GATTC_DISCOVER_ST},
219 /* BTA_GATTC_API_REFRESH_EVT        */   {BTA_GATTC_IGNORE,             BTA_GATTC_DISCOVER_ST},
220
221 /* BTA_GATTC_INT_CONN_EVT           */   {BTA_GATTC_CONN,               BTA_GATTC_DISCOVER_ST},
222 /* BTA_GATTC_INT_DISCOVER_EVT       */   {BTA_GATTC_RESTART_DISCOVER,   BTA_GATTC_DISCOVER_ST},
223 /* BTA_GATTC_DISCOVER_CMPL_EVT      */   {BTA_GATTC_DISC_CMPL,          BTA_GATTC_CONN_ST},
224 /* BTA_GATTC_OP_CMPL_EVT            */   {BTA_GATTC_IGNORE_OP_CMPL,     BTA_GATTC_DISCOVER_ST},
225 /* BTA_GATTC_INT_DISCONN_EVT        */   {BTA_GATTC_CLOSE,              BTA_GATTC_IDLE_ST},
226
227 };
228
229 /* type for state table */
230 typedef const uint8_t (*tBTA_GATTC_ST_TBL)[BTA_GATTC_NUM_COLS];
231
232 /* state table */
233 const tBTA_GATTC_ST_TBL bta_gattc_st_tbl[] =
234 {
235     bta_gattc_st_idle,
236     bta_gattc_st_w4_conn,
237     bta_gattc_st_connected,
238     bta_gattc_st_discover
239 };
240
241 /*****************************************************************************
242 ** Global data
243 *****************************************************************************/
244
245 /* GATTC control block */
246 tBTA_GATTC_CB  bta_gattc_cb;
247
248 #if (BTA_GATT_DEBUG == TRUE)
249 static char *gattc_evt_code(tBTA_GATTC_INT_EVT evt_code);
250 static char *gattc_state_code(tBTA_GATTC_STATE state_code);
251 #endif
252
253 /*******************************************************************************
254 **
255 ** Function         bta_gattc_sm_execute
256 **
257 ** Description      State machine event handling function for GATTC
258 **
259 **
260 ** Returns          bool  : true if queued client request buffer can be immediately released
261 **                                        else false
262 **
263 *******************************************************************************/
264 bool bta_gattc_sm_execute(tBTA_GATTC_CLCB *p_clcb, uint16_t event, tBTA_GATTC_DATA *p_data)
265 {
266     tBTA_GATTC_ST_TBL     state_table;
267     uint8_t               action;
268     int                 i;
269     bool             rt = true;
270 #if (BTA_GATT_DEBUG == TRUE)
271     tBTA_GATTC_STATE in_state = p_clcb->state;
272     uint16_t         in_event = event;
273     APPL_TRACE_DEBUG("bta_gattc_sm_execute: State 0x%02x [%s], Event 0x%x[%s]", in_state,
274                       gattc_state_code(in_state),
275                       in_event,
276                       gattc_evt_code(in_event));
277 #endif
278
279
280     /* look up the state table for the current state */
281     state_table = bta_gattc_st_tbl[p_clcb->state];
282
283     event &= 0x00FF;
284
285     /* set next state */
286     p_clcb->state = state_table[event][BTA_GATTC_NEXT_STATE];
287
288     /* execute action functions */
289     for (i = 0; i < BTA_GATTC_ACTIONS; i++)
290     {
291         if ((action = state_table[event][i]) != BTA_GATTC_IGNORE)
292         {
293             (*bta_gattc_action[action])(p_clcb, p_data);
294             if (p_clcb->p_q_cmd == p_data) {
295                 /* buffer is queued, don't free in the bta dispatcher.
296                  * we free it ourselves when a completion event is received.
297                  */
298                 rt = false;
299             }
300         }
301         else
302         {
303             break;
304         }
305     }
306
307 #if (BTA_GATT_DEBUG == TRUE)
308     if (in_state != p_clcb->state)
309     {
310         APPL_TRACE_DEBUG("GATTC State Change: [%s] -> [%s] after Event [%s]",
311                           gattc_state_code(in_state),
312                           gattc_state_code(p_clcb->state),
313                           gattc_evt_code(in_event));
314     }
315 #endif
316     return rt;
317 }
318
319 /*******************************************************************************
320 **
321 ** Function         bta_gattc_hdl_event
322 **
323 ** Description      GATT client main event handling function.
324 **
325 **
326 ** Returns          bool
327 **
328 *******************************************************************************/
329 bool bta_gattc_hdl_event(BT_HDR *p_msg)
330 {
331     tBTA_GATTC_CLCB *p_clcb = NULL;
332     tBTA_GATTC_RCB      *p_clreg;
333     bool             rt = true;
334 #if (BTA_GATT_DEBUG == TRUE)
335     APPL_TRACE_DEBUG("bta_gattc_hdl_event: Event [%s]", gattc_evt_code(p_msg->event));
336 #endif
337     switch (p_msg->event)
338     {
339         case BTA_GATTC_API_DISABLE_EVT:
340             bta_gattc_disable();
341             break;
342
343         case BTA_GATTC_API_REG_EVT:
344             bta_gattc_register((tBTA_GATTC_DATA *) p_msg);
345             break;
346
347         case BTA_GATTC_INT_START_IF_EVT:
348             bta_gattc_start_if((tBTA_GATTC_DATA *) p_msg);
349             break;
350
351         case BTA_GATTC_API_DEREG_EVT:
352             p_clreg = bta_gattc_cl_get_regcb(((tBTA_GATTC_DATA *)p_msg)->api_dereg.client_if);
353             bta_gattc_deregister(p_clreg);
354             break;
355
356         case BTA_GATTC_API_OPEN_EVT:
357             bta_gattc_process_api_open((tBTA_GATTC_DATA *) p_msg);
358             break;
359
360         case BTA_GATTC_API_CANCEL_OPEN_EVT:
361             bta_gattc_process_api_open_cancel((tBTA_GATTC_DATA *) p_msg);
362             break;
363
364         case BTA_GATTC_API_REFRESH_EVT:
365             bta_gattc_process_api_refresh((tBTA_GATTC_DATA *) p_msg);
366             break;
367
368         case BTA_GATTC_ENC_CMPL_EVT:
369             bta_gattc_process_enc_cmpl((tBTA_GATTC_DATA *) p_msg);
370             break;
371
372         default:
373             if (p_msg->event == BTA_GATTC_INT_CONN_EVT)
374                 p_clcb = bta_gattc_find_int_conn_clcb((tBTA_GATTC_DATA *) p_msg);
375             else if (p_msg->event == BTA_GATTC_INT_DISCONN_EVT)
376                 p_clcb = bta_gattc_find_int_disconn_clcb((tBTA_GATTC_DATA *) p_msg);
377             else
378                 p_clcb = bta_gattc_find_clcb_by_conn_id(p_msg->layer_specific);
379
380             if (p_clcb != NULL)
381             {
382                 rt = bta_gattc_sm_execute(p_clcb, p_msg->event, (tBTA_GATTC_DATA *) p_msg);
383             }
384             else
385             {
386                 APPL_TRACE_DEBUG("Ignore unknown conn ID: %d", p_msg->layer_specific);
387             }
388
389             break;
390     }
391
392
393     return rt;
394 }
395
396
397 /*****************************************************************************
398 **  Debug Functions
399 *****************************************************************************/
400 #if (BTA_GATT_DEBUG == TRUE)
401
402 /*******************************************************************************
403 **
404 ** Function         gattc_evt_code
405 **
406 ** Description
407 **
408 ** Returns          void
409 **
410 *******************************************************************************/
411 static char *gattc_evt_code(tBTA_GATTC_INT_EVT evt_code)
412 {
413     switch (evt_code)
414     {
415         case BTA_GATTC_API_OPEN_EVT:
416             return "BTA_GATTC_API_OPEN_EVT";
417         case BTA_GATTC_INT_OPEN_FAIL_EVT:
418             return "BTA_GATTC_INT_OPEN_FAIL_EVT";
419         case BTA_GATTC_API_CANCEL_OPEN_EVT:
420             return "BTA_GATTC_API_CANCEL_OPEN_EVT";
421         case BTA_GATTC_INT_CANCEL_OPEN_OK_EVT:
422             return "BTA_GATTC_INT_CANCEL_OPEN_OK_EVT";
423         case BTA_GATTC_API_READ_EVT:
424             return "BTA_GATTC_API_READ_EVT";
425         case BTA_GATTC_API_WRITE_EVT:
426             return "BTA_GATTC_API_WRITE_EVT";
427         case BTA_GATTC_API_EXEC_EVT:
428             return "BTA_GATTC_API_EXEC_EVT";
429         case BTA_GATTC_API_CLOSE_EVT:
430             return "BTA_GATTC_API_CLOSE_EVT";
431         case BTA_GATTC_API_SEARCH_EVT:
432             return "BTA_GATTC_API_SEARCH_EVT";
433         case BTA_GATTC_API_CONFIRM_EVT:
434             return "BTA_GATTC_API_CONFIRM_EVT";
435         case BTA_GATTC_API_READ_MULTI_EVT:
436             return "BTA_GATTC_API_READ_MULTI_EVT";
437         case BTA_GATTC_INT_CONN_EVT:
438             return "BTA_GATTC_INT_CONN_EVT";
439         case BTA_GATTC_INT_DISCOVER_EVT:
440             return "BTA_GATTC_INT_DISCOVER_EVT";
441         case BTA_GATTC_DISCOVER_CMPL_EVT:
442             return "BTA_GATTC_DISCOVER_CMPL_EVT";
443         case BTA_GATTC_OP_CMPL_EVT:
444             return "BTA_GATTC_OP_CMPL_EVT";
445         case BTA_GATTC_INT_DISCONN_EVT:
446             return "BTA_GATTC_INT_DISCONN_EVT";
447         case BTA_GATTC_INT_START_IF_EVT:
448             return "BTA_GATTC_INT_START_IF_EVT";
449         case BTA_GATTC_API_REG_EVT:
450             return "BTA_GATTC_API_REG_EVT";
451         case BTA_GATTC_API_DEREG_EVT:
452             return "BTA_GATTC_API_DEREG_EVT";
453         case BTA_GATTC_API_REFRESH_EVT:
454             return "BTA_GATTC_API_REFRESH_EVT";
455         case BTA_GATTC_API_DISABLE_EVT:
456             return "BTA_GATTC_API_DISABLE_EVT";
457         case BTA_GATTC_API_CFG_MTU_EVT:
458             return "BTA_GATTC_API_CFG_MTU_EVT";
459         default:
460             return "unknown GATTC event code";
461     }
462 }
463
464 /*******************************************************************************
465 **
466 ** Function         gattc_state_code
467 **
468 ** Description
469 **
470 ** Returns          void
471 **
472 *******************************************************************************/
473 static char *gattc_state_code(tBTA_GATTC_STATE state_code)
474 {
475     switch (state_code)
476     {
477         case BTA_GATTC_IDLE_ST:
478             return "GATTC_IDLE_ST";
479         case BTA_GATTC_W4_CONN_ST:
480             return "GATTC_W4_CONN_ST";
481         case BTA_GATTC_CONN_ST:
482             return "GATTC_CONN_ST";
483         case BTA_GATTC_DISCOVER_ST:
484             return "GATTC_DISCOVER_ST";
485         default:
486             return "unknown GATTC state code";
487     }
488 }
489
490 #endif  /* Debug Functions */
491 #endif /* BTA_GATT_INCLUDED */