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