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