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 "common/bt_target.h"
26
27 #if (GATTC_INCLUDED == 1 && BLE_INCLUDED == 1)
28
29 #include <string.h>
30
31 #include "bta_gattc_int.h"
32 #include "osi/allocator.h"
33
34
35 /*****************************************************************************
36 ** Constants and types
37 *****************************************************************************/
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
52 BTA_GATTC_Q_CMD,
53 BTA_GATTC_CLOSE,
54 BTA_GATTC_CLOSE_FAIL,
55 BTA_GATTC_READ,
56 BTA_GATTC_WRITE,
57
58 BTA_GATTC_OP_CMPL,
59 BTA_GATTC_SEARCH,
60 BTA_GATTC_FAIL,
61 BTA_GATTC_CONFIRM,
62 BTA_GATTC_EXEC,
63 BTA_GATTC_READ_MULTI,
64 BTA_GATTC_IGNORE_OP_CMPL,
65 BTA_GATTC_DISC_CLOSE,
66 BTA_GATTC_RESTART_DISCOVER,
67 BTA_GATTC_CFG_MTU,
68 BTA_GATTC_READ_BY_TYPE,
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 bta_gattc_open,
78 bta_gattc_open_fail,
79 bta_gattc_open_error,
80 bta_gattc_cancel_open,
81 bta_gattc_cancel_open_ok,
82 bta_gattc_cancel_open_error,
83 bta_gattc_conn,
84 bta_gattc_start_discover,
85 bta_gattc_disc_cmpl,
86
87 bta_gattc_q_cmd,
88 bta_gattc_close,
89 bta_gattc_close_fail,
90 bta_gattc_read,
91 bta_gattc_write,
92
93 bta_gattc_op_cmpl,
94 bta_gattc_search,
95 bta_gattc_fail,
96 bta_gattc_confirm,
97 bta_gattc_execute,
98 bta_gattc_read_multi,
99 bta_gattc_ignore_op_cmpl,
100 bta_gattc_disc_close,
101 bta_gattc_restart_discover,
102 bta_gattc_cfg_mtu,
103 bta_gattc_read_by_type
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 bta_gattc_st_idle[][BTA_GATTC_NUM_COLS] = {
114 /* Event Action 1 Next state */
115 /* BTA_GATTC_API_OPEN_EVT */ {BTA_GATTC_OPEN, BTA_GATTC_W4_CONN_ST},
116 /* BTA_GATTC_INT_OPEN_FAIL_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_IDLE_ST},
117 /* BTA_GATTC_API_CANCEL_OPEN_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_IDLE_ST},
118 /* BTA_GATTC_INT_CANCEL_OPEN_OK_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_IDLE_ST},
119
120 /* BTA_GATTC_API_READ_EVT */ {BTA_GATTC_FAIL, BTA_GATTC_IDLE_ST},
121 /* BTA_GATTC_API_WRITE_EVT */ {BTA_GATTC_FAIL, BTA_GATTC_IDLE_ST},
122 /* BTA_GATTC_API_EXEC_EVT */ {BTA_GATTC_FAIL, BTA_GATTC_IDLE_ST},
123 /* BTA_GATTC_API_CFG_MTU_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_IDLE_ST},
124
125 /* BTA_GATTC_API_CLOSE_EVT */ {BTA_GATTC_CLOSE_FAIL, BTA_GATTC_IDLE_ST},
126
127 /* BTA_GATTC_API_SEARCH_EVT */ {BTA_GATTC_FAIL, BTA_GATTC_IDLE_ST},
128 /* BTA_GATTC_API_CONFIRM_EVT */ {BTA_GATTC_FAIL, BTA_GATTC_IDLE_ST},
129 /* BTA_GATTC_API_READ_MULTI_EVT */ {BTA_GATTC_FAIL, BTA_GATTC_IDLE_ST},
130 /* BTA_GATTC_API_REFRESH_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_IDLE_ST},
131 /* BTA_GATTC_API_CACHE_CLEAN_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 /* BTA_GATTC_API_READ_BY_TYPE_EVT */ {BTA_GATTC_FAIL, BTA_GATTC_IDLE_ST},
140 };
141
142 /* state table for wait for open state */
143 static const UINT8 bta_gattc_st_w4_conn[][BTA_GATTC_NUM_COLS] = {
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 /* BTA_GATTC_API_CACHE_CLEAN_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_W4_CONN_ST},
162
163 /* BTA_GATTC_INT_CONN_EVT */ {BTA_GATTC_CONN, BTA_GATTC_CONN_ST},
164 /* BTA_GATTC_INT_DISCOVER_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_W4_CONN_ST},
165 /* BTA_GATTC_DISCOVER_CMPL_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_W4_CONN_ST},
166 /* BTA_GATTC_OP_CMPL_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_W4_CONN_ST},
167 /* BTA_GATTC_INT_DISCONN_EVT */ {BTA_GATTC_OPEN_FAIL, BTA_GATTC_IDLE_ST},
168
169 /* BTA_GATTC_API_READ_BY_TYPE_EVT */ {BTA_GATTC_FAIL, BTA_GATTC_W4_CONN_ST},
170 };
171
172 /* state table for open state */
173 static const UINT8 bta_gattc_st_connected[][BTA_GATTC_NUM_COLS] = {
174 /* Event Action 1 Next state */
175 /* BTA_GATTC_API_OPEN_EVT */ {BTA_GATTC_OPEN, BTA_GATTC_CONN_ST},
176 /* BTA_GATTC_INT_OPEN_FAIL_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_CONN_ST},
177 /* BTA_GATTC_API_CANCEL_OPEN_EVT */ {BTA_GATTC_CANCEL_OPEN_ERROR, BTA_GATTC_CONN_ST},
178 /* BTA_GATTC_INT_CANCEL_OPEN_OK_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_CONN_ST},
179
180 /* BTA_GATTC_API_READ_EVT */ {BTA_GATTC_READ, BTA_GATTC_CONN_ST},
181 /* BTA_GATTC_API_WRITE_EVT */ {BTA_GATTC_WRITE, BTA_GATTC_CONN_ST},
182 /* BTA_GATTC_API_EXEC_EVT */ {BTA_GATTC_EXEC, BTA_GATTC_CONN_ST},
183 /* BTA_GATTC_API_CFG_MTU_EVT */ {BTA_GATTC_CFG_MTU, BTA_GATTC_CONN_ST},
184
185 /* BTA_GATTC_API_CLOSE_EVT */ {BTA_GATTC_CLOSE, BTA_GATTC_IDLE_ST},
186
187 /* BTA_GATTC_API_SEARCH_EVT */ {BTA_GATTC_SEARCH, BTA_GATTC_CONN_ST},
188 /* BTA_GATTC_API_CONFIRM_EVT */ {BTA_GATTC_CONFIRM, BTA_GATTC_CONN_ST},
189 /* BTA_GATTC_API_READ_MULTI_EVT */ {BTA_GATTC_READ_MULTI, BTA_GATTC_CONN_ST},
190 /* BTA_GATTC_API_REFRESH_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_CONN_ST},
191 /* BTA_GATTC_API_CACHE_CLEAN_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_CONN_ST},
192
193 /* BTA_GATTC_INT_CONN_EVT */ {BTA_GATTC_CONN, BTA_GATTC_CONN_ST},
194 /* BTA_GATTC_INT_DISCOVER_EVT */ {BTA_GATTC_START_DISCOVER, BTA_GATTC_DISCOVER_ST},
195 /* BTA_GATTC_DISCOVER_CMPL_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_CONN_ST},
196 /* BTA_GATTC_OP_CMPL_EVT */ {BTA_GATTC_OP_CMPL, BTA_GATTC_CONN_ST},
197
198 /* BTA_GATTC_INT_DISCONN_EVT */ {BTA_GATTC_CLOSE, BTA_GATTC_IDLE_ST},
199
200 /* BTA_GATTC_API_READ_BY_TYPE_EVT */ {BTA_GATTC_READ_BY_TYPE, BTA_GATTC_CONN_ST},
201 };
202
203 /* state table for discover state */
204 static const UINT8 bta_gattc_st_discover[][BTA_GATTC_NUM_COLS] = {
205 /* Event Action 1 Next state */
206 /* BTA_GATTC_API_OPEN_EVT */ {BTA_GATTC_OPEN, BTA_GATTC_DISCOVER_ST},
207 /* BTA_GATTC_INT_OPEN_FAIL_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_DISCOVER_ST},
208 /* BTA_GATTC_API_CANCEL_OPEN_EVT */ {BTA_GATTC_CANCEL_OPEN_ERROR, BTA_GATTC_DISCOVER_ST},
209 /* BTA_GATTC_INT_CANCEL_OPEN_OK_EVT */ {BTA_GATTC_FAIL, BTA_GATTC_DISCOVER_ST},
210
211 /* BTA_GATTC_API_READ_EVT */ {BTA_GATTC_Q_CMD, BTA_GATTC_DISCOVER_ST},
212 /* BTA_GATTC_API_WRITE_EVT */ {BTA_GATTC_Q_CMD, BTA_GATTC_DISCOVER_ST},
213 /* BTA_GATTC_API_EXEC_EVT */ {BTA_GATTC_Q_CMD, BTA_GATTC_DISCOVER_ST},
214 /* BTA_GATTC_API_CFG_MTU_EVT */ {BTA_GATTC_Q_CMD, BTA_GATTC_DISCOVER_ST},
215
216 /* BTA_GATTC_API_CLOSE_EVT */ {BTA_GATTC_DISC_CLOSE, BTA_GATTC_DISCOVER_ST},
217
218 /* BTA_GATTC_API_SEARCH_EVT */ {BTA_GATTC_Q_CMD, BTA_GATTC_DISCOVER_ST},
219 /* BTA_GATTC_API_CONFIRM_EVT */ {BTA_GATTC_CONFIRM, BTA_GATTC_DISCOVER_ST},
220 /* BTA_GATTC_API_READ_MULTI_EVT */ {BTA_GATTC_Q_CMD, BTA_GATTC_DISCOVER_ST},
221 /* BTA_GATTC_API_REFRESH_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_DISCOVER_ST},
222 /* BTA_GATTC_API_CACHE_CLEAN_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_DISCOVER_ST},
223
224 /* BTA_GATTC_INT_CONN_EVT */ {BTA_GATTC_CONN, BTA_GATTC_DISCOVER_ST},
225 /* BTA_GATTC_INT_DISCOVER_EVT */ {BTA_GATTC_RESTART_DISCOVER, BTA_GATTC_DISCOVER_ST},
226 /* BTA_GATTC_DISCOVER_CMPL_EVT */ {BTA_GATTC_DISC_CMPL, BTA_GATTC_CONN_ST},
227 /* BTA_GATTC_OP_CMPL_EVT */ {BTA_GATTC_IGNORE_OP_CMPL, BTA_GATTC_DISCOVER_ST},
228 /* BTA_GATTC_INT_DISCONN_EVT */ {BTA_GATTC_CLOSE, BTA_GATTC_IDLE_ST},
229
230 /* BTA_GATTC_API_READ_BY_TYPE_EVT */ {BTA_GATTC_Q_CMD, BTA_GATTC_DISCOVER_ST},
231 };
232
233 /* type for state table */
234 typedef const UINT8 (*tBTA_GATTC_ST_TBL)[BTA_GATTC_NUM_COLS];
235
236 /* state table */
237 const tBTA_GATTC_ST_TBL bta_gattc_st_tbl[] = {
238 bta_gattc_st_idle,
239 bta_gattc_st_w4_conn,
240 bta_gattc_st_connected,
241 bta_gattc_st_discover
242 };
243
244 /*****************************************************************************
245 ** Global data
246 *****************************************************************************/
247
248 /* GATTC control block */
249 #if BTA_DYNAMIC_MEMORY == 0
250 tBTA_GATTC_CB bta_gattc_cb;
251 #else
252 tBTA_GATTC_CB *bta_gattc_cb_ptr;
253 #endif
254
255 #if BTA_GATT_DEBUG == 1
256 static char *gattc_evt_code(tBTA_GATTC_INT_EVT evt_code);
257 static char *gattc_state_code(tBTA_GATTC_STATE state_code);
258 #endif
259
260 /*******************************************************************************
261 **
262 ** Function bta_gattc_sm_execute
263 **
264 ** Description State machine event handling function for GATTC
265 **
266 **
267 ** Returns BOOLEAN : 1 if queued client request buffer can be immediately released
268 ** else 0
269 **
270 *******************************************************************************/
bta_gattc_sm_execute(tBTA_GATTC_CLCB * p_clcb,UINT16 event,tBTA_GATTC_DATA * p_data)271 BOOLEAN bta_gattc_sm_execute(tBTA_GATTC_CLCB *p_clcb, UINT16 event, tBTA_GATTC_DATA *p_data)
272 {
273 tBTA_GATTC_ST_TBL state_table;
274 UINT8 action;
275 int i;
276 BOOLEAN rt = 1;
277 #if BTA_GATT_DEBUG == 1
278 tBTA_GATTC_STATE in_state = p_clcb->state;
279 UINT16 in_event = event;
280 APPL_TRACE_DEBUG("bta_gattc_sm_execute: State 0x%02x [%s], Event 0x%x[%s]", in_state,
281 gattc_state_code(in_state),
282 in_event,
283 gattc_evt_code(in_event));
284 #endif
285
286
287 /* look up the state table for the current state */
288 state_table = bta_gattc_st_tbl[p_clcb->state];
289
290 event &= 0x00FF;
291
292 /* set next state */
293 p_clcb->state = state_table[event][BTA_GATTC_NEXT_STATE];
294
295 /* execute action functions */
296 for (i = 0; i < BTA_GATTC_ACTIONS; i++) {
297 if ((action = state_table[event][i]) != BTA_GATTC_IGNORE) {
298 (*bta_gattc_action[action])(p_clcb, p_data);
299 if (p_clcb->p_q_cmd == p_data) {
300 /* buffer is queued, don't free in the bta dispatcher.
301 * we free it ourselves when a completion event is received.
302 */
303 rt = 0;
304 }
305 } else {
306 break;
307 }
308 }
309
310 #if BTA_GATT_DEBUG == 1
311 if (in_state != p_clcb->state) {
312 APPL_TRACE_DEBUG("GATTC State Change: [%s] -> [%s] after Event [%s]",
313 gattc_state_code(in_state),
314 gattc_state_code(p_clcb->state),
315 gattc_evt_code(in_event));
316 }
317 #endif
318 return rt;
319 }
320
321 /*******************************************************************************
322 **
323 ** Function bta_gattc_hdl_event
324 **
325 ** Description GATT client main event handling function.
326 **
327 **
328 ** Returns BOOLEAN
329 **
330 *******************************************************************************/
bta_gattc_hdl_event(BT_HDR * p_msg)331 BOOLEAN bta_gattc_hdl_event(BT_HDR *p_msg)
332 {
333 tBTA_GATTC_CB *p_cb = &bta_gattc_cb;
334 tBTA_GATTC_CLCB *p_clcb = NULL;
335 tBTA_GATTC_RCB *p_clreg;
336 BOOLEAN rt = 1;
337 #if BTA_GATT_DEBUG == 1
338 APPL_TRACE_DEBUG("bta_gattc_hdl_event: Event [%s]\n", gattc_evt_code(p_msg->event));
339 #endif
340 switch (p_msg->event) {
341 case BTA_GATTC_API_DISABLE_EVT:
342 bta_gattc_disable(p_cb);
343 break;
344
345 case BTA_GATTC_API_REG_EVT:
346 bta_gattc_register(p_cb, (tBTA_GATTC_DATA *) p_msg);
347 break;
348
349 case BTA_GATTC_INT_START_IF_EVT:
350 bta_gattc_start_if(p_cb, (tBTA_GATTC_DATA *) p_msg);
351 break;
352
353 case BTA_GATTC_API_DEREG_EVT:
354 p_clreg = bta_gattc_cl_get_regcb(((tBTA_GATTC_DATA *)p_msg)->api_dereg.client_if);
355 bta_gattc_deregister(p_cb, p_clreg);
356 break;
357
358 case BTA_GATTC_API_OPEN_EVT:
359 bta_gattc_process_api_open(p_cb, (tBTA_GATTC_DATA *) p_msg);
360 break;
361
362 case BTA_GATTC_API_CANCEL_OPEN_EVT:
363 bta_gattc_process_api_open_cancel(p_cb, (tBTA_GATTC_DATA *) p_msg);
364 break;
365
366 case BTA_GATTC_API_REFRESH_EVT:
367 bta_gattc_process_api_refresh(p_cb, (tBTA_GATTC_DATA *) p_msg);
368 break;
369 case BTA_GATTC_API_CACHE_ASSOC_EVT:
370 bta_gattc_process_api_cache_assoc(p_cb, (tBTA_GATTC_DATA *)p_msg);
371 break;
372 case BTA_GATTC_API_CACHE_GET_ADDR_LIST_EVT:
373 bta_gattc_process_api_cache_get_addr_list(p_cb, (tBTA_GATTC_DATA *)p_msg);
374 break;
375 case BTA_GATTC_API_CACHE_CLEAN_EVT:
376 bta_gattc_process_api_cache_clean(p_cb, (tBTA_GATTC_DATA *) p_msg);
377 break;
378 #if BLE_INCLUDED == 1
379 case BTA_GATTC_API_LISTEN_EVT:
380 bta_gattc_listen(p_cb, (tBTA_GATTC_DATA *) p_msg);
381 break;
382 case BTA_GATTC_API_BROADCAST_EVT:
383 bta_gattc_broadcast(p_cb, (tBTA_GATTC_DATA *) p_msg);
384 break;
385 #endif
386
387 case BTA_GATTC_ENC_CMPL_EVT:
388 bta_gattc_process_enc_cmpl(p_cb, (tBTA_GATTC_DATA *) p_msg);
389 break;
390
391 default:
392 if (p_msg->event == BTA_GATTC_INT_CONN_EVT) {
393 p_clcb = bta_gattc_find_int_conn_clcb((tBTA_GATTC_DATA *) p_msg);
394 p_clreg = bta_gattc_cl_get_regcb(((tBTA_GATTC_DATA *)p_msg)->int_conn.client_if);
395 if (p_clreg != NULL){
396 bta_gattc_conncback(p_clreg, (tBTA_GATTC_DATA *) p_msg);
397 }
398
399 } else if (p_msg->event == BTA_GATTC_INT_DISCONN_EVT) {
400 p_clreg = bta_gattc_cl_get_regcb(((tBTA_GATTC_DATA *)p_msg)->int_conn.client_if);
401 if (p_clreg != NULL){
402 bta_gattc_disconncback(p_clreg, (tBTA_GATTC_DATA *) p_msg);
403 }
404 p_clcb = bta_gattc_find_int_disconn_clcb((tBTA_GATTC_DATA *) p_msg);
405 } else {
406 p_clcb = bta_gattc_find_clcb_by_conn_id(p_msg->layer_specific);
407 }
408
409 if (p_clcb != NULL) {
410 rt = bta_gattc_sm_execute(p_clcb, p_msg->event, (tBTA_GATTC_DATA *) p_msg);
411 } else {
412 APPL_TRACE_DEBUG("Ignore unknown conn ID: %d\n", p_msg->layer_specific);
413 }
414
415 break;
416 }
417
418
419 return rt;
420 }
421
422
423 /*****************************************************************************
424 ** Debug Functions
425 *****************************************************************************/
426 #if BTA_GATT_DEBUG == 1
427
428 /*******************************************************************************
429 **
430 ** Function gattc_evt_code
431 **
432 ** Description
433 **
434 ** Returns void
435 **
436 *******************************************************************************/
gattc_evt_code(tBTA_GATTC_INT_EVT evt_code)437 static char *gattc_evt_code(tBTA_GATTC_INT_EVT evt_code)
438 {
439 switch (evt_code) {
440 case BTA_GATTC_API_OPEN_EVT:
441 return "BTA_GATTC_API_OPEN_EVT";
442 case BTA_GATTC_INT_OPEN_FAIL_EVT:
443 return "BTA_GATTC_INT_OPEN_FAIL_EVT";
444 case BTA_GATTC_API_CANCEL_OPEN_EVT:
445 return "BTA_GATTC_API_CANCEL_OPEN_EVT";
446 case BTA_GATTC_INT_CANCEL_OPEN_OK_EVT:
447 return "BTA_GATTC_INT_CANCEL_OPEN_OK_EVT";
448 case BTA_GATTC_API_READ_EVT:
449 return "BTA_GATTC_API_READ_EVT";
450 case BTA_GATTC_API_WRITE_EVT:
451 return "BTA_GATTC_API_WRITE_EVT";
452 case BTA_GATTC_API_EXEC_EVT:
453 return "BTA_GATTC_API_EXEC_EVT";
454 case BTA_GATTC_API_CLOSE_EVT:
455 return "BTA_GATTC_API_CLOSE_EVT";
456 case BTA_GATTC_API_SEARCH_EVT:
457 return "BTA_GATTC_API_SEARCH_EVT";
458 case BTA_GATTC_API_CONFIRM_EVT:
459 return "BTA_GATTC_API_CONFIRM_EVT";
460 case BTA_GATTC_API_READ_MULTI_EVT:
461 return "BTA_GATTC_API_READ_MULTI_EVT";
462 case BTA_GATTC_INT_CONN_EVT:
463 return "BTA_GATTC_INT_CONN_EVT";
464 case BTA_GATTC_INT_DISCOVER_EVT:
465 return "BTA_GATTC_INT_DISCOVER_EVT";
466 case BTA_GATTC_DISCOVER_CMPL_EVT:
467 return "BTA_GATTC_DISCOVER_CMPL_EVT";
468 case BTA_GATTC_OP_CMPL_EVT:
469 return "BTA_GATTC_OP_CMPL_EVT";
470 case BTA_GATTC_INT_DISCONN_EVT:
471 return "BTA_GATTC_INT_DISCONN_EVT";
472 case BTA_GATTC_INT_START_IF_EVT:
473 return "BTA_GATTC_INT_START_IF_EVT";
474 case BTA_GATTC_API_REG_EVT:
475 return "BTA_GATTC_API_REG_EVT";
476 case BTA_GATTC_API_DEREG_EVT:
477 return "BTA_GATTC_API_DEREG_EVT";
478 case BTA_GATTC_API_REFRESH_EVT:
479 return "BTA_GATTC_API_REFRESH_EVT";
480 case BTA_GATTC_API_CACHE_CLEAN_EVT:
481 return "BTA_GATTC_API_CACHE_CLEAN_EVT";
482 case BTA_GATTC_API_LISTEN_EVT:
483 return "BTA_GATTC_API_LISTEN_EVT";
484 case BTA_GATTC_API_DISABLE_EVT:
485 return "BTA_GATTC_API_DISABLE_EVT";
486 case BTA_GATTC_API_CFG_MTU_EVT:
487 return "BTA_GATTC_API_CFG_MTU_EVT";
488 case BTA_GATTC_API_READ_BY_TYPE_EVT:
489 return "BTA_GATTC_API_READ_BY_TYPE_EVT";
490 default:
491 return "unknown GATTC event code";
492 }
493 }
494
495 /*******************************************************************************
496 **
497 ** Function gattc_state_code
498 **
499 ** Description
500 **
501 ** Returns void
502 **
503 *******************************************************************************/
gattc_state_code(tBTA_GATTC_STATE state_code)504 static char *gattc_state_code(tBTA_GATTC_STATE state_code)
505 {
506 switch (state_code) {
507 case BTA_GATTC_IDLE_ST:
508 return "GATTC_IDLE_ST";
509 case BTA_GATTC_W4_CONN_ST:
510 return "GATTC_W4_CONN_ST";
511 case BTA_GATTC_CONN_ST:
512 return "GATTC_CONN_ST";
513 case BTA_GATTC_DISCOVER_ST:
514 return "GATTC_DISCOVER_ST";
515 default:
516 return "unknown GATTC state code";
517 }
518 }
519
520 #endif /* Debug Functions */
521
bta_gattc_deinit(void)522 void bta_gattc_deinit(void)
523 {
524 #if BTA_DYNAMIC_MEMORY
525 memset(bta_gattc_cb_ptr, 0, sizeof(tBTA_GATTC_CB));
526 FREE_AND_RESET(bta_gattc_cb_ptr);
527 #endif /* #if BTA_DYNAMIC_MEMORY */
528 }
529 #endif /* GATTC_INCLUDED == 1 && BLE_INCLUDED == 1 */
530