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