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 defined(BTA_GATT_INCLUDED) && (BTA_GATT_INCLUDED == TRUE) 28 29 #include <string.h> 30 31 #include "bta_gattc_int.h" 32 #include "gki.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_CI_OPEN, 66 BTA_GATTC_CI_LOAD, 67 BTA_GATTC_CI_SAVE, 68 BTA_GATTC_CACHE_OPEN, 69 BTA_GATTC_IGNORE_OP_CMPL, 70 BTA_GATTC_DISC_CLOSE, 71 BTA_GATTC_RESTART_DISCOVER, 72 73 BTA_GATTC_IGNORE 74 }; 75 /* type for action functions */ 76 typedef void (*tBTA_GATTC_ACTION)(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data); 77 78 /* action function list */ 79 const tBTA_GATTC_ACTION bta_gattc_action[] = 80 { 81 bta_gattc_open, 82 bta_gattc_open_fail, 83 bta_gattc_open_error, 84 bta_gattc_cancel_open, 85 bta_gattc_cancel_open_ok, 86 bta_gattc_cancel_open_error, 87 bta_gattc_conn, 88 bta_gattc_start_discover, 89 bta_gattc_disc_cmpl, 90 91 bta_gattc_q_cmd, 92 bta_gattc_close, 93 bta_gattc_close_fail, 94 bta_gattc_read, 95 bta_gattc_write, 96 97 bta_gattc_op_cmpl, 98 bta_gattc_search, 99 bta_gattc_fail, 100 bta_gattc_confirm, 101 bta_gattc_execute, 102 bta_gattc_read_multi, 103 bta_gattc_ci_open, 104 bta_gattc_ci_load, 105 bta_gattc_ci_save, 106 bta_gattc_cache_open, 107 bta_gattc_ignore_op_cmpl, 108 bta_gattc_disc_close, 109 bta_gattc_restart_discover 110 }; 111 112 113 /* state table information */ 114 #define BTA_GATTC_ACTIONS 1 /* number of actions */ 115 #define BTA_GATTC_NEXT_STATE 1 /* position of next state */ 116 #define BTA_GATTC_NUM_COLS 2 /* number of columns in state tables */ 117 118 /* state table for idle state */ 119 static const UINT8 bta_gattc_st_idle[][BTA_GATTC_NUM_COLS] = 120 { 121 /* Event Action 1 Next state */ 122 /* BTA_GATTC_API_OPEN_EVT */ {BTA_GATTC_OPEN, BTA_GATTC_W4_CONN_ST}, 123 /* BTA_GATTC_INT_OPEN_FAIL_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_IDLE_ST}, 124 /* BTA_GATTC_API_CANCEL_OPEN_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_IDLE_ST}, 125 /* BTA_GATTC_INT_CANCEL_OPEN_OK_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_IDLE_ST}, 126 127 /* BTA_GATTC_API_READ_EVT */ {BTA_GATTC_FAIL, BTA_GATTC_IDLE_ST}, 128 /* BTA_GATTC_API_WRITE_EVT */ {BTA_GATTC_FAIL, BTA_GATTC_IDLE_ST}, 129 /* BTA_GATTC_API_EXEC_EVT */ {BTA_GATTC_FAIL, BTA_GATTC_IDLE_ST}, 130 131 /* BTA_GATTC_API_CLOSE_EVT */ {BTA_GATTC_CLOSE_FAIL, BTA_GATTC_IDLE_ST}, 132 133 /* BTA_GATTC_API_SEARCH_EVT */ {BTA_GATTC_FAIL, BTA_GATTC_IDLE_ST}, 134 /* BTA_GATTC_API_CONFIRM_EVT */ {BTA_GATTC_FAIL, BTA_GATTC_IDLE_ST}, 135 /* BTA_GATTC_API_READ_MULTI_EVT */ {BTA_GATTC_FAIL, BTA_GATTC_IDLE_ST}, 136 /* BTA_GATTC_API_REFRESH_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_IDLE_ST}, 137 138 /* BTA_GATTC_INT_CONN_EVT */ {BTA_GATTC_CONN, BTA_GATTC_CONN_ST}, 139 /* BTA_GATTC_INT_DISCOVER_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_IDLE_ST}, 140 /* BTA_GATTC_DISCOVER_CMPL_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_IDLE_ST}, 141 /* BTA_GATTC_OP_CMPL_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_IDLE_ST}, 142 /* BTA_GATTC_INT_DISCONN_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_IDLE_ST}, 143 144 145 /* ===> for cache loading, saving */ 146 /* BTA_GATTC_START_CACHE_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_IDLE_ST}, 147 /* BTA_GATTC_CI_CACHE_OPEN_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_IDLE_ST}, 148 /* BTA_GATTC_CI_CACHE_LOAD_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_IDLE_ST}, 149 /* BTA_GATTC_CI_CACHE_SAVE_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_IDLE_ST} 150 }; 151 152 /* state table for wait for open state */ 153 static const UINT8 bta_gattc_st_w4_conn[][BTA_GATTC_NUM_COLS] = 154 { 155 /* Event Action 1 Next state */ 156 /* BTA_GATTC_API_OPEN_EVT */ {BTA_GATTC_OPEN, BTA_GATTC_W4_CONN_ST}, 157 /* BTA_GATTC_INT_OPEN_FAIL_EVT */ {BTA_GATTC_OPEN_FAIL, BTA_GATTC_IDLE_ST}, 158 /* BTA_GATTC_API_CANCEL_OPEN_EVT */ {BTA_GATTC_CANCEL_OPEN, BTA_GATTC_W4_CONN_ST}, 159 /* BTA_GATTC_INT_CANCEL_OPEN_OK_EVT */ {BTA_GATTC_CANCEL_OPEN_OK, BTA_GATTC_IDLE_ST}, 160 161 /* BTA_GATTC_API_READ_EVT */ {BTA_GATTC_FAIL, BTA_GATTC_W4_CONN_ST}, 162 /* BTA_GATTC_API_WRITE_EVT */ {BTA_GATTC_FAIL, BTA_GATTC_W4_CONN_ST}, 163 /* BTA_GATTC_API_EXEC_EVT */ {BTA_GATTC_FAIL, BTA_GATTC_W4_CONN_ST}, 164 165 /* BTA_GATTC_API_CLOSE_EVT */ {BTA_GATTC_CANCEL_OPEN, BTA_GATTC_W4_CONN_ST}, 166 167 /* BTA_GATTC_API_SEARCH_EVT */ {BTA_GATTC_FAIL, BTA_GATTC_W4_CONN_ST}, 168 /* BTA_GATTC_API_CONFIRM_EVT */ {BTA_GATTC_FAIL, BTA_GATTC_W4_CONN_ST}, 169 /* BTA_GATTC_API_READ_MULTI_EVT */ {BTA_GATTC_FAIL, BTA_GATTC_W4_CONN_ST}, 170 /* BTA_GATTC_API_REFRESH_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_W4_CONN_ST}, 171 172 /* BTA_GATTC_INT_CONN_EVT */ {BTA_GATTC_CONN, BTA_GATTC_CONN_ST}, 173 /* BTA_GATTC_INT_DISCOVER_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_W4_CONN_ST}, 174 /* BTA_GATTC_DISCOVER_CMPL_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_W4_CONN_ST}, 175 /* BTA_GATTC_OP_CMPL_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_W4_CONN_ST}, 176 /* BTA_GATTC_INT_DISCONN_EVT */ {BTA_GATTC_OPEN_FAIL, BTA_GATTC_IDLE_ST}, 177 178 /* ===> for cache loading, saving */ 179 /* BTA_GATTC_START_CACHE_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_W4_CONN_ST}, 180 /* BTA_GATTC_CI_CACHE_OPEN_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_W4_CONN_ST}, 181 /* BTA_GATTC_CI_CACHE_LOAD_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_W4_CONN_ST}, 182 /* BTA_GATTC_CI_CACHE_SAVE_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_W4_CONN_ST} 183 }; 184 185 /* state table for open state */ 186 static const UINT8 bta_gattc_st_connected[][BTA_GATTC_NUM_COLS] = 187 { 188 /* Event Action 1 Next state */ 189 /* BTA_GATTC_API_OPEN_EVT */ {BTA_GATTC_OPEN_ERROR, BTA_GATTC_CONN_ST}, 190 /* BTA_GATTC_INT_OPEN_FAIL_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_CONN_ST}, 191 /* BTA_GATTC_API_CANCEL_OPEN_EVT */ {BTA_GATTC_CANCEL_OPEN_ERROR, BTA_GATTC_CONN_ST}, 192 /* BTA_GATTC_INT_CANCEL_OPEN_OK_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_CONN_ST}, 193 194 /* BTA_GATTC_API_READ_EVT */ {BTA_GATTC_READ, BTA_GATTC_CONN_ST}, 195 /* BTA_GATTC_API_WRITE_EVT */ {BTA_GATTC_WRITE, BTA_GATTC_CONN_ST}, 196 /* BTA_GATTC_API_EXEC_EVT */ {BTA_GATTC_EXEC, BTA_GATTC_CONN_ST}, 197 198 /* BTA_GATTC_API_CLOSE_EVT */ {BTA_GATTC_CLOSE, BTA_GATTC_IDLE_ST}, 199 200 /* BTA_GATTC_API_SEARCH_EVT */ {BTA_GATTC_SEARCH, BTA_GATTC_CONN_ST}, 201 /* BTA_GATTC_API_CONFIRM_EVT */ {BTA_GATTC_CONFIRM, BTA_GATTC_CONN_ST}, 202 /* BTA_GATTC_API_READ_MULTI_EVT */ {BTA_GATTC_READ_MULTI, BTA_GATTC_CONN_ST}, 203 /* BTA_GATTC_API_REFRESH_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_CONN_ST}, 204 205 /* BTA_GATTC_INT_CONN_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_CONN_ST}, 206 /* BTA_GATTC_INT_DISCOVER_EVT */ {BTA_GATTC_START_DISCOVER, BTA_GATTC_DISCOVER_ST}, 207 /* BTA_GATTC_DISCOVER_CMPL_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_CONN_ST}, 208 /* BTA_GATTC_OP_CMPL_EVT */ {BTA_GATTC_OP_CMPL, BTA_GATTC_CONN_ST}, 209 210 /* BTA_GATTC_INT_DISCONN_EVT */ {BTA_GATTC_CLOSE, BTA_GATTC_IDLE_ST}, 211 212 /* ===> for cache loading, saving */ 213 /* BTA_GATTC_START_CACHE_EVT */ {BTA_GATTC_CACHE_OPEN, BTA_GATTC_DISCOVER_ST}, 214 /* BTA_GATTC_CI_CACHE_OPEN_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_CONN_ST}, 215 /* BTA_GATTC_CI_CACHE_LOAD_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_CONN_ST}, 216 /* BTA_GATTC_CI_CACHE_SAVE_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_CONN_ST} 217 }; 218 219 /* state table for discover state */ 220 static const UINT8 bta_gattc_st_discover[][BTA_GATTC_NUM_COLS] = 221 { 222 /* Event Action 1 Next state */ 223 /* BTA_GATTC_API_OPEN_EVT */ {BTA_GATTC_OPEN_ERROR, BTA_GATTC_DISCOVER_ST}, 224 /* BTA_GATTC_INT_OPEN_FAIL_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_DISCOVER_ST}, 225 /* BTA_GATTC_API_CANCEL_OPEN_EVT */ {BTA_GATTC_CANCEL_OPEN_ERROR, BTA_GATTC_DISCOVER_ST}, 226 /* BTA_GATTC_INT_CANCEL_OPEN_OK_EVT */ {BTA_GATTC_FAIL, BTA_GATTC_DISCOVER_ST}, 227 228 /* BTA_GATTC_API_READ_EVT */ {BTA_GATTC_Q_CMD, BTA_GATTC_DISCOVER_ST}, 229 /* BTA_GATTC_API_WRITE_EVT */ {BTA_GATTC_Q_CMD, BTA_GATTC_DISCOVER_ST}, 230 /* BTA_GATTC_API_EXEC_EVT */ {BTA_GATTC_Q_CMD, BTA_GATTC_DISCOVER_ST}, 231 232 /* BTA_GATTC_API_CLOSE_EVT */ {BTA_GATTC_DISC_CLOSE, BTA_GATTC_DISCOVER_ST}, 233 234 /* BTA_GATTC_API_SEARCH_EVT */ {BTA_GATTC_Q_CMD, BTA_GATTC_DISCOVER_ST}, 235 /* BTA_GATTC_API_CONFIRM_EVT */ {BTA_GATTC_CONFIRM, BTA_GATTC_DISCOVER_ST}, 236 /* BTA_GATTC_API_READ_MULTI_EVT */ {BTA_GATTC_Q_CMD, BTA_GATTC_DISCOVER_ST}, 237 /* BTA_GATTC_API_REFRESH_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_DISCOVER_ST}, 238 239 /* BTA_GATTC_INT_CONN_EVT */ {BTA_GATTC_CONN, BTA_GATTC_DISCOVER_ST}, 240 /* BTA_GATTC_INT_DISCOVER_EVT */ {BTA_GATTC_RESTART_DISCOVER, BTA_GATTC_DISCOVER_ST}, 241 /* BTA_GATTC_DISCOVER_CMPL_EVT */ {BTA_GATTC_DISC_CMPL, BTA_GATTC_CONN_ST}, 242 /* BTA_GATTC_OP_CMPL_EVT */ {BTA_GATTC_IGNORE_OP_CMPL, BTA_GATTC_DISCOVER_ST}, 243 /* BTA_GATTC_INT_DISCONN_EVT */ {BTA_GATTC_CLOSE, BTA_GATTC_IDLE_ST}, 244 245 /* ===> for cache loading, saving */ 246 /* BTA_GATTC_START_CACHE_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_DISCOVER_ST}, 247 /* BTA_GATTC_CI_CACHE_OPEN_EVT */ {BTA_GATTC_CI_OPEN, BTA_GATTC_DISCOVER_ST}, 248 /* BTA_GATTC_CI_CACHE_LOAD_EVT */ {BTA_GATTC_CI_LOAD, BTA_GATTC_DISCOVER_ST}, 249 /* BTA_GATTC_CI_CACHE_SAVE_EVT */ {BTA_GATTC_CI_SAVE, BTA_GATTC_DISCOVER_ST} 250 }; 251 252 /* type for state table */ 253 typedef const UINT8 (*tBTA_GATTC_ST_TBL)[BTA_GATTC_NUM_COLS]; 254 255 /* state table */ 256 const tBTA_GATTC_ST_TBL bta_gattc_st_tbl[] = 257 { 258 bta_gattc_st_idle, 259 bta_gattc_st_w4_conn, 260 bta_gattc_st_connected, 261 bta_gattc_st_discover 262 }; 263 264 /***************************************************************************** 265 ** Global data 266 *****************************************************************************/ 267 268 /* GATTC control block */ 269 #if BTA_DYNAMIC_MEMORY == FALSE 270 tBTA_GATTC_CB bta_gattc_cb; 271 #endif 272 273 #if BTA_GATT_DEBUG == TRUE 274 static char *gattc_evt_code(tBTA_GATTC_INT_EVT evt_code); 275 static char *gattc_state_code(tBTA_GATTC_STATE state_code); 276 #endif 277 278 /******************************************************************************* 279 ** 280 ** Function bta_gattc_sm_execute 281 ** 282 ** Description State machine event handling function for GATTC 283 ** 284 ** 285 ** Returns void 286 ** 287 *******************************************************************************/ 288 void bta_gattc_sm_execute(tBTA_GATTC_CLCB *p_clcb, UINT16 event, tBTA_GATTC_DATA *p_data) 289 { 290 tBTA_GATTC_ST_TBL state_table; 291 UINT8 action; 292 int i; 293 #if BTA_GATT_DEBUG == TRUE 294 tBTA_GATTC_STATE in_state = p_clcb->state; 295 UINT16 in_event = event; 296 APPL_TRACE_DEBUG4("bta_gattc_sm_execute: State 0x%02x [%s], Event 0x%x[%s]", in_state, 297 gattc_state_code(in_state), 298 in_event, 299 gattc_evt_code(in_event)); 300 #endif 301 302 303 /* look up the state table for the current state */ 304 state_table = bta_gattc_st_tbl[p_clcb->state]; 305 306 event &= 0x00FF; 307 308 /* set next state */ 309 p_clcb->state = state_table[event][BTA_GATTC_NEXT_STATE]; 310 311 /* execute action functions */ 312 for (i = 0; i < BTA_GATTC_ACTIONS; i++) 313 { 314 if ((action = state_table[event][i]) != BTA_GATTC_IGNORE) 315 { 316 (*bta_gattc_action[action])(p_clcb, p_data); 317 } 318 else 319 { 320 break; 321 } 322 } 323 324 #if BTA_GATT_DEBUG == TRUE 325 if (in_state != p_clcb->state) 326 { 327 APPL_TRACE_DEBUG3("GATTC State Change: [%s] -> [%s] after Event [%s]", 328 gattc_state_code(in_state), 329 gattc_state_code(p_clcb->state), 330 gattc_evt_code(in_event)); 331 } 332 #endif 333 } 334 335 /******************************************************************************* 336 ** 337 ** Function bta_gattc_hdl_event 338 ** 339 ** Description GATT client main event handling function. 340 ** 341 ** 342 ** Returns void 343 ** 344 *******************************************************************************/ 345 BOOLEAN bta_gattc_hdl_event(BT_HDR *p_msg) 346 { 347 tBTA_GATTC_CB *p_cb = &bta_gattc_cb; 348 tBTA_GATTC_CLCB *p_clcb = NULL; 349 tBTA_GATTC_RCB *p_clreg; 350 #if BTA_GATT_DEBUG == TRUE 351 APPL_TRACE_DEBUG1("bta_gattc_hdl_event: Event [%s]", gattc_evt_code(p_msg->event)); 352 #endif 353 switch (p_msg->event) 354 { 355 case BTA_GATTC_API_DISABLE_EVT: 356 bta_gattc_disable(p_cb); 357 break; 358 359 case BTA_GATTC_API_REG_EVT: 360 bta_gattc_register(p_cb, (tBTA_GATTC_DATA *) p_msg); 361 break; 362 363 case BTA_GATTC_INT_START_IF_EVT: 364 bta_gattc_start_if(p_cb, (tBTA_GATTC_DATA *) p_msg); 365 break; 366 367 case BTA_GATTC_API_DEREG_EVT: 368 p_clreg = bta_gattc_cl_get_regcb(((tBTA_GATTC_DATA *)p_msg)->api_dereg.client_if); 369 bta_gattc_deregister(p_cb, p_clreg); 370 break; 371 372 case BTA_GATTC_API_OPEN_EVT: 373 bta_gattc_process_api_open(p_cb, (tBTA_GATTC_DATA *) p_msg); 374 break; 375 376 case BTA_GATTC_API_CANCEL_OPEN_EVT: 377 bta_gattc_process_api_open_cancel(p_cb, (tBTA_GATTC_DATA *) p_msg); 378 break; 379 380 case BTA_GATTC_API_REFRESH_EVT: 381 bta_gattc_process_api_refresh(p_cb, (tBTA_GATTC_DATA *) p_msg); 382 break; 383 384 #if BLE_INCLUDED == TRUE 385 case BTA_GATTC_API_LISTEN_EVT: 386 bta_gattc_listen(p_cb, (tBTA_GATTC_DATA *) p_msg); 387 break; 388 case BTA_GATTC_API_BROADCAST_EVT: 389 bta_gattc_broadcast(p_cb, (tBTA_GATTC_DATA *) p_msg); 390 break; 391 #endif 392 393 case BTA_GATTC_ENC_CMPL_EVT: 394 bta_gattc_process_enc_cmpl(p_cb, (tBTA_GATTC_DATA *) p_msg); 395 break; 396 397 default: 398 if (p_msg->event == BTA_GATTC_INT_CONN_EVT) 399 p_clcb = bta_gattc_find_int_conn_clcb((tBTA_GATTC_DATA *) p_msg); 400 else if (p_msg->event == BTA_GATTC_INT_DISCONN_EVT) 401 p_clcb = bta_gattc_find_int_disconn_clcb((tBTA_GATTC_DATA *) p_msg); 402 else 403 p_clcb = bta_gattc_find_clcb_by_conn_id(p_msg->layer_specific); 404 405 if (p_clcb != NULL) 406 { 407 bta_gattc_sm_execute(p_clcb, p_msg->event, (tBTA_GATTC_DATA *) p_msg); 408 } 409 else 410 { 411 APPL_TRACE_DEBUG1("Ignore unknown conn ID: %d", p_msg->layer_specific); 412 } 413 414 break; 415 } 416 417 418 return(TRUE); 419 } 420 421 422 /***************************************************************************** 423 ** Debug Functions 424 *****************************************************************************/ 425 #if BTA_GATT_DEBUG == TRUE 426 427 /******************************************************************************* 428 ** 429 ** Function gattc_evt_code 430 ** 431 ** Description 432 ** 433 ** Returns void 434 ** 435 *******************************************************************************/ 436 static char *gattc_evt_code(tBTA_GATTC_INT_EVT evt_code) 437 { 438 switch (evt_code) 439 { 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_START_CACHE_EVT: 473 return "BTA_GATTC_START_CACHE_EVT"; 474 case BTA_GATTC_CI_CACHE_OPEN_EVT: 475 return "BTA_GATTC_CI_CACHE_OPEN_EVT"; 476 case BTA_GATTC_CI_CACHE_LOAD_EVT: 477 return "BTA_GATTC_CI_CACHE_LOAD_EVT"; 478 case BTA_GATTC_CI_CACHE_SAVE_EVT: 479 return "BTA_GATTC_CI_CACHE_SAVE_EVT"; 480 case BTA_GATTC_INT_START_IF_EVT: 481 return "BTA_GATTC_INT_START_IF_EVT"; 482 case BTA_GATTC_API_REG_EVT: 483 return "BTA_GATTC_API_REG_EVT"; 484 case BTA_GATTC_API_DEREG_EVT: 485 return "BTA_GATTC_API_DEREG_EVT"; 486 case BTA_GATTC_API_REFRESH_EVT: 487 return "BTA_GATTC_API_REFRESH_EVT"; 488 case BTA_GATTC_API_LISTEN_EVT: 489 return "BTA_GATTC_API_LISTEN_EVT"; 490 case BTA_GATTC_API_DISABLE_EVT: 491 return "BTA_GATTC_API_DISABLE_EVT"; 492 default: 493 return "unknown GATTC event code"; 494 } 495 } 496 497 /******************************************************************************* 498 ** 499 ** Function gattc_state_code 500 ** 501 ** Description 502 ** 503 ** Returns void 504 ** 505 *******************************************************************************/ 506 static char *gattc_state_code(tBTA_GATTC_STATE state_code) 507 { 508 switch (state_code) 509 { 510 case BTA_GATTC_IDLE_ST: 511 return "GATTC_IDLE_ST"; 512 case BTA_GATTC_W4_CONN_ST: 513 return "GATTC_W4_CONN_ST"; 514 case BTA_GATTC_CONN_ST: 515 return "GATTC_CONN_ST"; 516 case BTA_GATTC_DISCOVER_ST: 517 return "GATTC_DISCOVER_ST"; 518 default: 519 return "unknown GATTC state code"; 520 } 521 } 522 523 #endif /* Debug Functions */ 524 #endif /* BTA_GATT_INCLUDED */ 525