gatt_attr.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  1. /******************************************************************************
  2. *
  3. * Copyright (C) 2008-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. * this file contains the main GATT server attributes access request
  21. * handling functions.
  22. *
  23. ******************************************************************************/
  24. #include "common/bt_target.h"
  25. //#include "bt_utils.h"
  26. #include "stack/gatt_api.h"
  27. #include "gatt_int.h"
  28. #include "stack/sdpdefs.h"
  29. #if (BLE_INCLUDED == TRUE && GATTS_INCLUDED == TRUE)
  30. #define GATTP_MAX_NUM_INC_SVR 0
  31. #define GATTP_MAX_CHAR_NUM 2
  32. #define GATTP_MAX_ATTR_NUM (GATTP_MAX_CHAR_NUM * 2 + GATTP_MAX_NUM_INC_SVR + 1)
  33. #define GATTP_MAX_CHAR_VALUE_SIZE 50
  34. #ifndef GATTP_ATTR_DB_SIZE
  35. #define GATTP_ATTR_DB_SIZE GATT_DB_MEM_SIZE(GATTP_MAX_NUM_INC_SVR, GATTP_MAX_CHAR_NUM, GATTP_MAX_CHAR_VALUE_SIZE)
  36. #endif
  37. static void gatt_request_cback(UINT16 conn_id, UINT32 trans_id, UINT8 op_code, tGATTS_DATA *p_data);
  38. static void gatt_connect_cback(tGATT_IF gatt_if, BD_ADDR bda, UINT16 conn_id, BOOLEAN connected,
  39. tGATT_DISCONN_REASON reason, tBT_TRANSPORT transport);
  40. static void gatt_disc_res_cback(UINT16 conn_id, tGATT_DISC_TYPE disc_type, tGATT_DISC_RES *p_data);
  41. static void gatt_disc_cmpl_cback(UINT16 conn_id, tGATT_DISC_TYPE disc_type, tGATT_STATUS status);
  42. static void gatt_cl_op_cmpl_cback(UINT16 conn_id, tGATTC_OPTYPE op, tGATT_STATUS status,
  43. tGATT_CL_COMPLETE *p_data);
  44. static void gatt_cl_start_config_ccc(tGATT_PROFILE_CLCB *p_clcb);
  45. static const tGATT_CBACK gatt_profile_cback = {
  46. gatt_connect_cback,
  47. gatt_cl_op_cmpl_cback,
  48. gatt_disc_res_cback,
  49. gatt_disc_cmpl_cback,
  50. gatt_request_cback,
  51. NULL,
  52. NULL
  53. } ;
  54. /*******************************************************************************
  55. **
  56. ** Function gatt_profile_find_conn_id_by_bd_addr
  57. **
  58. ** Description Find the connection ID by remote address
  59. **
  60. ** Returns Connection ID
  61. **
  62. *******************************************************************************/
  63. #if (GATTS_INCLUDED == TRUE)
  64. UINT16 gatt_profile_find_conn_id_by_bd_addr(BD_ADDR remote_bda)
  65. {
  66. UINT16 conn_id = GATT_INVALID_CONN_ID;
  67. GATT_GetConnIdIfConnected (gatt_cb.gatt_if, remote_bda, &conn_id, BT_TRANSPORT_LE);
  68. return conn_id;
  69. }
  70. #endif ///GATTS_INCLUDED == TRUE
  71. /*******************************************************************************
  72. **
  73. ** Function gatt_profile_find_clcb_by_conn_id
  74. **
  75. ** Description find clcb by Connection ID
  76. **
  77. ** Returns Pointer to the found link conenction control block.
  78. **
  79. *******************************************************************************/
  80. static tGATT_PROFILE_CLCB *gatt_profile_find_clcb_by_conn_id(UINT16 conn_id)
  81. {
  82. UINT8 i_clcb;
  83. tGATT_PROFILE_CLCB *p_clcb = NULL;
  84. for (i_clcb = 0, p_clcb = gatt_cb.profile_clcb; i_clcb < GATT_MAX_APPS; i_clcb++, p_clcb++) {
  85. if (p_clcb->in_use && p_clcb->conn_id == conn_id) {
  86. return p_clcb;
  87. }
  88. }
  89. return NULL;
  90. }
  91. /*******************************************************************************
  92. **
  93. ** Function gatt_profile_find_clcb_by_bd_addr
  94. **
  95. ** Description The function searches all LCBs with macthing bd address.
  96. **
  97. ** Returns Pointer to the found link conenction control block.
  98. **
  99. *******************************************************************************/
  100. static tGATT_PROFILE_CLCB *gatt_profile_find_clcb_by_bd_addr(BD_ADDR bda, tBT_TRANSPORT transport)
  101. {
  102. UINT8 i_clcb;
  103. tGATT_PROFILE_CLCB *p_clcb = NULL;
  104. for (i_clcb = 0, p_clcb = gatt_cb.profile_clcb; i_clcb < GATT_MAX_APPS; i_clcb++, p_clcb++) {
  105. if (p_clcb->in_use && p_clcb->transport == transport &&
  106. p_clcb->connected && !memcmp(p_clcb->bda, bda, BD_ADDR_LEN)) {
  107. return p_clcb;
  108. }
  109. }
  110. return NULL;
  111. }
  112. /*******************************************************************************
  113. **
  114. ** Function gatt_profile_clcb_alloc
  115. **
  116. ** Description The function allocates a GATT profile connection link control block
  117. **
  118. ** Returns NULL if not found. Otherwise pointer to the connection link block.
  119. **
  120. *******************************************************************************/
  121. tGATT_PROFILE_CLCB *gatt_profile_clcb_alloc (UINT16 conn_id, BD_ADDR bda, tBT_TRANSPORT tranport)
  122. {
  123. UINT8 i_clcb = 0;
  124. tGATT_PROFILE_CLCB *p_clcb = NULL;
  125. for (i_clcb = 0, p_clcb = gatt_cb.profile_clcb; i_clcb < GATT_MAX_APPS; i_clcb++, p_clcb++) {
  126. if (!p_clcb->in_use) {
  127. p_clcb->in_use = TRUE;
  128. p_clcb->conn_id = conn_id;
  129. p_clcb->connected = TRUE;
  130. p_clcb->transport = tranport;
  131. memcpy (p_clcb->bda, bda, BD_ADDR_LEN);
  132. break;
  133. }
  134. }
  135. if (i_clcb < GATT_MAX_APPS) {
  136. return p_clcb;
  137. }
  138. return NULL;
  139. }
  140. /*******************************************************************************
  141. **
  142. ** Function gatt_profile_clcb_dealloc
  143. **
  144. ** Description The function deallocates a GATT profile connection link control block
  145. **
  146. ** Returns void
  147. **
  148. *******************************************************************************/
  149. void gatt_profile_clcb_dealloc (tGATT_PROFILE_CLCB *p_clcb)
  150. {
  151. memset(p_clcb, 0, sizeof(tGATT_PROFILE_CLCB));
  152. }
  153. /*******************************************************************************
  154. **
  155. ** Function gatt_proc_read
  156. **
  157. ** Description GATT Attributes Database Read/Read Blob Request process
  158. **
  159. ** Returns GATT_SUCCESS if successfully sent; otherwise error code.
  160. **
  161. *******************************************************************************/
  162. tGATT_STATUS gatt_proc_read (tGATTS_REQ_TYPE type, tGATT_READ_REQ *p_data, tGATTS_RSP *p_rsp)
  163. {
  164. tGATT_STATUS status = GATT_NO_RESOURCES;
  165. UNUSED(type);
  166. if (p_data->is_long) {
  167. p_rsp->attr_value.offset = p_data->offset;
  168. }
  169. p_rsp->attr_value.handle = p_data->handle;
  170. UINT16 len = 0;
  171. uint8_t *value;
  172. status = GATTS_GetAttributeValue(p_data->handle, &len, &value);
  173. if(status == GATT_SUCCESS && len > 0 && value) {
  174. if(len > GATT_MAX_ATTR_LEN) {
  175. len = GATT_MAX_ATTR_LEN;
  176. }
  177. p_rsp->attr_value.len = len;
  178. memcpy(p_rsp->attr_value.value, value, len);
  179. }
  180. return status;
  181. }
  182. /******************************************************************************
  183. **
  184. ** Function gatt_proc_write_req
  185. **
  186. ** Description GATT server process a write request.
  187. **
  188. ** Returns GATT_SUCCESS if successfully sent; otherwise error code.
  189. **
  190. *******************************************************************************/
  191. tGATT_STATUS gatt_proc_write_req( tGATTS_REQ_TYPE type, tGATT_WRITE_REQ *p_data)
  192. {
  193. if(p_data->len > GATT_MAX_ATTR_LEN) {
  194. p_data->len = GATT_MAX_ATTR_LEN;
  195. }
  196. return GATTS_SetAttributeValue(p_data->handle,
  197. p_data->len,
  198. p_data->value);
  199. }
  200. /*******************************************************************************
  201. **
  202. ** Function gatt_request_cback
  203. **
  204. ** Description GATT profile attribute access request callback.
  205. **
  206. ** Returns void.
  207. **
  208. *******************************************************************************/
  209. static void gatt_request_cback (UINT16 conn_id, UINT32 trans_id, tGATTS_REQ_TYPE type,
  210. tGATTS_DATA *p_data)
  211. {
  212. UINT8 status = GATT_INVALID_PDU;
  213. tGATTS_RSP rsp_msg ;
  214. BOOLEAN ignore = FALSE;
  215. GATT_TRACE_DEBUG("%s",__func__);
  216. memset(&rsp_msg, 0, sizeof(tGATTS_RSP));
  217. switch (type) {
  218. case GATTS_REQ_TYPE_READ:
  219. status = gatt_proc_read(type, &p_data->read_req, &rsp_msg);
  220. break;
  221. case GATTS_REQ_TYPE_WRITE:
  222. if (!p_data->write_req.need_rsp) {
  223. ignore = TRUE;
  224. }
  225. status = gatt_proc_write_req(type, &p_data->write_req);
  226. break;
  227. case GATTS_REQ_TYPE_WRITE_EXEC:
  228. case GATT_CMD_WRITE:
  229. ignore = TRUE;
  230. GATT_TRACE_EVENT("Ignore GATT_REQ_EXEC_WRITE/WRITE_CMD" );
  231. break;
  232. case GATTS_REQ_TYPE_MTU:
  233. GATT_TRACE_EVENT("Get MTU exchange new mtu size: %d", p_data->mtu);
  234. ignore = TRUE;
  235. break;
  236. default:
  237. GATT_TRACE_EVENT("Unknown/unexpected LE GAP ATT request: 0x%02x", type);
  238. break;
  239. }
  240. if (!ignore) {
  241. GATTS_SendRsp (conn_id, trans_id, status, &rsp_msg);
  242. }
  243. }
  244. /*******************************************************************************
  245. **
  246. ** Function gatt_connect_cback
  247. **
  248. ** Description Gatt profile connection callback.
  249. **
  250. ** Returns void
  251. **
  252. *******************************************************************************/
  253. static void gatt_connect_cback (tGATT_IF gatt_if, BD_ADDR bda, UINT16 conn_id,
  254. BOOLEAN connected, tGATT_DISCONN_REASON reason,
  255. tBT_TRANSPORT transport)
  256. {
  257. UNUSED(gatt_if);
  258. GATT_TRACE_DEBUG ("%s: from %08x%04x connected:%d conn_id=%d reason = 0x%04x", __FUNCTION__,
  259. (bda[0] << 24) + (bda[1] << 16) + (bda[2] << 8) + bda[3],
  260. (bda[4] << 8) + bda[5], connected, conn_id, reason);
  261. tGATT_PROFILE_CLCB *p_clcb = gatt_profile_find_clcb_by_bd_addr(bda, transport);
  262. if (p_clcb == NULL) {
  263. p_clcb = gatt_profile_clcb_alloc (conn_id, bda, transport);
  264. }
  265. if (p_clcb == NULL) {
  266. return;
  267. }
  268. if (GATT_GetConnIdIfConnected (gatt_cb.gatt_if, bda, &p_clcb->conn_id, transport)) {
  269. p_clcb->connected = TRUE;
  270. p_clcb->conn_id = conn_id;
  271. }
  272. if (!p_clcb->connected) {
  273. /* wait for connection */
  274. return;
  275. }
  276. if (connected) {
  277. p_clcb->conn_id = conn_id;
  278. p_clcb->connected = TRUE;
  279. } else {
  280. gatt_profile_clcb_dealloc(p_clcb);
  281. }
  282. }
  283. /*******************************************************************************
  284. **
  285. ** Function gatt_profile_db_init
  286. **
  287. ** Description Initializa the GATT profile attribute database.
  288. **
  289. *******************************************************************************/
  290. void gatt_profile_db_init (void)
  291. {
  292. tBT_UUID app_uuid = {LEN_UUID_128, {0}};
  293. tBT_UUID uuid = {LEN_UUID_16, {UUID_SERVCLASS_GATT_SERVER}};
  294. UINT16 service_handle = 0;
  295. tGATT_STATUS status;
  296. /* Fill our internal UUID with a fixed pattern 0x81 */
  297. memset (&app_uuid.uu.uuid128, 0x81, LEN_UUID_128);
  298. /* Create a GATT profile service */
  299. gatt_cb.gatt_if = GATT_Register(&app_uuid, &gatt_profile_cback);
  300. GATT_StartIf(gatt_cb.gatt_if);
  301. service_handle = GATTS_CreateService (gatt_cb.gatt_if , &uuid, 0, GATTP_MAX_ATTR_NUM, TRUE);
  302. GATT_TRACE_DEBUG ("GATTS_CreateService: handle of service handle%x", service_handle);
  303. /* add Service Changed characteristic
  304. */
  305. uuid.uu.uuid16 = gatt_cb.gattp_attr.uuid = GATT_UUID_GATT_SRV_CHGD;
  306. gatt_cb.gattp_attr.service_change = 0;
  307. gatt_cb.gattp_attr.handle =
  308. gatt_cb.handle_of_h_r = GATTS_AddCharacteristic(service_handle, &uuid, 0, GATT_CHAR_PROP_BIT_INDICATE,
  309. NULL, NULL);
  310. GATT_TRACE_DEBUG ("gatt_profile_db_init: handle of service changed%d\n",
  311. gatt_cb.handle_of_h_r);
  312. tBT_UUID descr_uuid = {LEN_UUID_16, {GATT_UUID_CHAR_CLIENT_CONFIG}};
  313. uint8_t ccc_value[2] ={ 0x00, 0x00};
  314. tGATT_ATTR_VAL attr_val = {
  315. .attr_max_len = sizeof(UINT16),
  316. .attr_len = sizeof(UINT16),
  317. .attr_val = ccc_value,
  318. };
  319. GATTS_AddCharDescriptor (service_handle, GATT_PERM_READ | GATT_PERM_WRITE , &descr_uuid, &attr_val, NULL);
  320. /* start service
  321. */
  322. status = GATTS_StartService (gatt_cb.gatt_if, service_handle, GATTP_TRANSPORT_SUPPORTED );
  323. #if (CONFIG_BT_STACK_NO_LOG)
  324. (void) status;
  325. #endif
  326. GATT_TRACE_DEBUG ("gatt_profile_db_init: gatt_if=%d start status%d\n",
  327. gatt_cb.gatt_if, status);
  328. }
  329. /*******************************************************************************
  330. **
  331. ** Function gatt_disc_res_cback
  332. **
  333. ** Description Gatt profile discovery result callback
  334. **
  335. ** Returns void
  336. **
  337. *******************************************************************************/
  338. static void gatt_disc_res_cback (UINT16 conn_id, tGATT_DISC_TYPE disc_type, tGATT_DISC_RES *p_data)
  339. {
  340. GATT_TRACE_DEBUG("%s, disc_type = %d",__func__, disc_type);
  341. tGATT_PROFILE_CLCB *p_clcb = gatt_profile_find_clcb_by_conn_id(conn_id);
  342. if (p_clcb == NULL) {
  343. return;
  344. }
  345. switch (disc_type) {
  346. case GATT_DISC_SRVC_BY_UUID:/* stage 1 */
  347. p_clcb->e_handle = p_data->value.group_value.e_handle;
  348. p_clcb->ccc_result ++;
  349. break;
  350. case GATT_DISC_CHAR:/* stage 2 */
  351. p_clcb->s_handle = p_data->value.dclr_value.val_handle;
  352. p_clcb->ccc_result ++;
  353. break;
  354. case GATT_DISC_CHAR_DSCPT: /* stage 3 */
  355. if (p_data->type.uu.uuid16 == GATT_UUID_CHAR_CLIENT_CONFIG) {
  356. p_clcb->s_handle = p_data->handle;
  357. p_clcb->ccc_result ++;
  358. }
  359. break;
  360. }
  361. }
  362. /*******************************************************************************
  363. **
  364. ** Function gatt_disc_cmpl_cback
  365. **
  366. ** Description Gatt profile discovery complete callback
  367. **
  368. ** Returns void
  369. **
  370. *******************************************************************************/
  371. static void gatt_disc_cmpl_cback (UINT16 conn_id, tGATT_DISC_TYPE disc_type, tGATT_STATUS status)
  372. {
  373. GATT_TRACE_DEBUG("%s",__func__);
  374. tGATT_PROFILE_CLCB *p_clcb = gatt_profile_find_clcb_by_conn_id(conn_id);
  375. if (p_clcb == NULL) {
  376. return;
  377. }
  378. if (status == GATT_SUCCESS && p_clcb->ccc_result > 0) {
  379. p_clcb->ccc_result = 0;
  380. p_clcb->ccc_stage ++;
  381. gatt_cl_start_config_ccc(p_clcb);
  382. } else {
  383. GATT_TRACE_ERROR("%s() - Register for service changed indication failure", __FUNCTION__);
  384. }
  385. }
  386. /*******************************************************************************
  387. **
  388. ** Function gatt_cl_op_cmpl_cback
  389. **
  390. ** Description Gatt profile client operation complete callback
  391. **
  392. ** Returns void
  393. **
  394. *******************************************************************************/
  395. static void gatt_cl_op_cmpl_cback (UINT16 conn_id, tGATTC_OPTYPE op,
  396. tGATT_STATUS status, tGATT_CL_COMPLETE *p_data)
  397. {
  398. GATT_TRACE_DEBUG("%s",__func__);
  399. tGATT_PROFILE_CLCB *p_clcb = gatt_profile_find_clcb_by_conn_id(conn_id);
  400. if (p_clcb == NULL) {
  401. return;
  402. }
  403. if (op == GATTC_OPTYPE_WRITE) {
  404. GATT_TRACE_DEBUG("%s() - ccc write status : %d", __FUNCTION__, status);
  405. }
  406. }
  407. /*******************************************************************************
  408. **
  409. ** Function gatt_cl_start_config_ccc
  410. **
  411. ** Description Gatt profile start configure service change CCC
  412. **
  413. ** Returns void
  414. **
  415. *******************************************************************************/
  416. static void gatt_cl_start_config_ccc(tGATT_PROFILE_CLCB *p_clcb)
  417. {
  418. tGATT_DISC_PARAM srvc_disc_param;
  419. tGATT_VALUE ccc_value;
  420. GATT_TRACE_DEBUG("%s() - stage: %d", __FUNCTION__, p_clcb->ccc_stage);
  421. memset (&srvc_disc_param, 0 , sizeof(tGATT_DISC_PARAM));
  422. memset (&ccc_value, 0 , sizeof(tGATT_VALUE));
  423. switch (p_clcb->ccc_stage) {
  424. case GATT_SVC_CHANGED_SERVICE: /* discover GATT service */
  425. srvc_disc_param.s_handle = 1;
  426. srvc_disc_param.e_handle = 0xffff;
  427. srvc_disc_param.service.len = 2;
  428. srvc_disc_param.service.uu.uuid16 = UUID_SERVCLASS_GATT_SERVER;
  429. #if (GATTC_INCLUDED == TRUE)
  430. if (GATTC_Discover (p_clcb->conn_id, GATT_DISC_SRVC_BY_UUID, &srvc_disc_param) != GATT_SUCCESS) {
  431. GATT_TRACE_ERROR("%s() - ccc service error", __FUNCTION__);
  432. }
  433. #endif ///GATTC_INCLUDED == TRUE
  434. break;
  435. case GATT_SVC_CHANGED_CHARACTERISTIC: /* discover service change char */
  436. srvc_disc_param.s_handle = 1;
  437. srvc_disc_param.e_handle = p_clcb->e_handle;
  438. srvc_disc_param.service.len = 2;
  439. srvc_disc_param.service.uu.uuid16 = GATT_UUID_GATT_SRV_CHGD;
  440. #if (GATTC_INCLUDED == TRUE)
  441. if (GATTC_Discover (p_clcb->conn_id, GATT_DISC_CHAR, &srvc_disc_param) != GATT_SUCCESS) {
  442. GATT_TRACE_ERROR("%s() - ccc char error", __FUNCTION__);
  443. }
  444. #endif ///GATTC_INCLUDED == TRUE
  445. break;
  446. case GATT_SVC_CHANGED_DESCRIPTOR: /* discover service change ccc */
  447. srvc_disc_param.s_handle = p_clcb->s_handle;
  448. srvc_disc_param.e_handle = p_clcb->e_handle;
  449. #if (GATTC_INCLUDED == TRUE)
  450. if (GATTC_Discover (p_clcb->conn_id, GATT_DISC_CHAR_DSCPT, &srvc_disc_param) != GATT_SUCCESS) {
  451. GATT_TRACE_ERROR("%s() - ccc char descriptor error", __FUNCTION__);
  452. }
  453. #endif ///GATTC_INCLUDED == TRUE
  454. break;
  455. case GATT_SVC_CHANGED_CONFIGURE_CCCD: /* write ccc */
  456. ccc_value.handle = p_clcb->s_handle;
  457. ccc_value.len = 2;
  458. ccc_value.value[0] = GATT_CLT_CONFIG_INDICATION;
  459. #if (GATTC_INCLUDED == TRUE)
  460. if (GATTC_Write (p_clcb->conn_id, GATT_WRITE, &ccc_value) != GATT_SUCCESS) {
  461. GATT_TRACE_ERROR("%s() - write ccc error", __FUNCTION__);
  462. }
  463. #endif ///GATTC_INCLUDED == TRUE
  464. break;
  465. }
  466. }
  467. /*******************************************************************************
  468. **
  469. ** Function GATT_ConfigServiceChangeCCC
  470. **
  471. ** Description Configure service change indication on remote device
  472. **
  473. ** Returns none
  474. **
  475. *******************************************************************************/
  476. void GATT_ConfigServiceChangeCCC (BD_ADDR remote_bda, BOOLEAN enable, tBT_TRANSPORT transport)
  477. {
  478. tGATT_PROFILE_CLCB *p_clcb = gatt_profile_find_clcb_by_bd_addr (remote_bda, transport);
  479. if (p_clcb == NULL) {
  480. p_clcb = gatt_profile_clcb_alloc (0, remote_bda, transport);
  481. }
  482. if (p_clcb == NULL) {
  483. return;
  484. }
  485. if (GATT_GetConnIdIfConnected (gatt_cb.gatt_if, remote_bda, &p_clcb->conn_id, transport)) {
  486. p_clcb->connected = TRUE;
  487. }
  488. /* hold the link here */
  489. GATT_Connect(gatt_cb.gatt_if, remote_bda, BLE_ADDR_UNKNOWN_TYPE, TRUE, transport);
  490. p_clcb->ccc_stage = GATT_SVC_CHANGED_CONNECTING;
  491. if (!p_clcb->connected) {
  492. /* wait for connection */
  493. return;
  494. }
  495. p_clcb->ccc_stage ++;
  496. gatt_cl_start_config_ccc(p_clcb);
  497. }
  498. #endif /* BLE_INCLUDED == TRUE && GATTS_INCLUDED == TRUE */