external/bluetooth/bluedroid
Revision | e1202caae4920139ea0cfed5c51f5f76b2dc8bc4 (tree) |
---|---|
Zeit | 2013-08-14 09:40:44 |
Autor | Andre Eisenbach <andre@broa...> |
Commiter | Matthew Xie |
LE: Add GATT disable functions
This patch adds required disable functions to the GATT sub-system to
properly unregister with the stack. Without the disable functions in
place, turning Bluetooth off with a GATT device connected may lead to
unexpected behaviour and cause GATT to fail on sub-sequent stack
restarts.
Change-Id: I7cb80e96109e2c09882991298d0487b506f5ffdd
@@ -102,6 +102,7 @@ static UINT8 bta_dm_ble_smp_cback (tBTM_LE_EVT event, BD_ADDR bda, tBTM_LE_EVT_D | ||
102 | 102 | #endif |
103 | 103 | static void bta_dm_ble_id_key_cback (UINT8 key_type, tBTM_BLE_LOCAL_KEYS *p_key); |
104 | 104 | #if ((defined BTA_GATT_INCLUDED) && (BTA_GATT_INCLUDED == TRUE)) |
105 | +static void bta_dm_gattc_register(void); | |
105 | 106 | static void btm_dm_start_gatt_discovery ( BD_ADDR bd_addr); |
106 | 107 | static void bta_dm_cancel_gatt_discovery(BD_ADDR bd_addr); |
107 | 108 | static void bta_dm_gattc_callback(tBTA_GATTC_EVT event, tBTA_GATTC *p_data); |
@@ -381,10 +382,6 @@ static void bta_dm_sys_hw_cback( tBTA_SYS_HW_EVT status ) | ||
381 | 382 | { |
382 | 383 | BTM_BleLoadLocalKeys(BTA_BLE_LOCAL_KEY_TYPE_ID, (tBTM_BLE_LOCAL_KEYS *)&id_key); |
383 | 384 | } |
384 | -#if ((defined BTA_GATT_INCLUDED) && (BTA_GATT_INCLUDED == TRUE)) | |
385 | - memset (&app_uuid.uu.uuid128, 0x87, LEN_UUID_128); | |
386 | - BTA_GATTC_AppRegister(&app_uuid, bta_dm_gattc_callback); | |
387 | -#endif | |
388 | 385 | #endif |
389 | 386 | |
390 | 387 | BTM_SecRegister((tBTM_APPL_INFO*)&bta_security); |
@@ -433,6 +430,11 @@ static void bta_dm_sys_hw_cback( tBTA_SYS_HW_EVT status ) | ||
433 | 430 | WBT_ExtAddPinCode(); |
434 | 431 | #endif |
435 | 432 | #endif |
433 | +#if (BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE) | |
434 | + memset (&app_uuid.uu.uuid128, 0x87, LEN_UUID_128); | |
435 | + bta_dm_gattc_register(); | |
436 | +#endif | |
437 | + | |
436 | 438 | } |
437 | 439 | else |
438 | 440 | APPL_TRACE_DEBUG0(" --- ignored event"); |
@@ -1178,7 +1180,7 @@ void bta_dm_search_start (tBTA_DM_MSG *p_data) | ||
1178 | 1180 | { |
1179 | 1181 | tBTM_INQUIRY_CMPL result; |
1180 | 1182 | |
1181 | -#if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE | |
1183 | +#if (BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE) | |
1182 | 1184 | UINT16 len = (UINT16)(sizeof(tBT_UUID) * p_data->search.num_uuid); |
1183 | 1185 | #endif |
1184 | 1186 |
@@ -4950,6 +4952,27 @@ void bta_dm_ble_observe (tBTA_DM_MSG *p_data) | ||
4950 | 4952 | |
4951 | 4953 | /******************************************************************************* |
4952 | 4954 | ** |
4955 | +** Function bta_dm_gattc_register | |
4956 | +** | |
4957 | +** Description Register with GATTC in DM if BLE is needed. | |
4958 | +** | |
4959 | +** | |
4960 | +** Returns void | |
4961 | +** | |
4962 | +*******************************************************************************/ | |
4963 | +static void bta_dm_gattc_register(void) | |
4964 | +{ | |
4965 | + tBT_UUID app_uuid = {LEN_UUID_128,{0}}; | |
4966 | + | |
4967 | + if (bta_dm_search_cb.client_if == BTA_GATTS_INVALID_IF) | |
4968 | + { | |
4969 | + memset (&app_uuid.uu.uuid128, 0x87, LEN_UUID_128); | |
4970 | + BTA_GATTC_AppRegister(&app_uuid, bta_dm_gattc_callback); | |
4971 | + } | |
4972 | +} | |
4973 | + | |
4974 | +/******************************************************************************* | |
4975 | +** | |
4953 | 4976 | ** Function btm_dm_start_disc_gatt_services |
4954 | 4977 | ** |
4955 | 4978 | ** Description This function starts a GATT service search request. |
@@ -25,9 +25,6 @@ | ||
25 | 25 | |
26 | 26 | #include "bt_target.h" |
27 | 27 | |
28 | -#if defined(BTA_GATT_INCLUDED) && (BTA_GATT_INCLUDED == TRUE) | |
29 | - | |
30 | - | |
31 | 28 | #include "utl.h" |
32 | 29 | #include "gki.h" |
33 | 30 | #include "bd.h" |
@@ -39,6 +36,8 @@ | ||
39 | 36 | |
40 | 37 | #include <string.h> |
41 | 38 | |
39 | +#if BTA_GATT_INCLUDED && BLE_INCLUDED == TRUE | |
40 | + | |
42 | 41 | /***************************************************************************** |
43 | 42 | ** Constants |
44 | 43 | *****************************************************************************/ |
@@ -48,6 +47,8 @@ static void bta_gattc_conn_cback(tGATT_IF gattc_if, BD_ADDR bda, UINT16 conn_id, | ||
48 | 47 | static void bta_gattc_cmpl_cback(UINT16 conn_id, tGATTC_OPTYPE op, tGATT_STATUS status, |
49 | 48 | tGATT_CL_COMPLETE *p_data); |
50 | 49 | |
50 | +static void bta_gattc_deregister_cmpl(tBTA_GATTC_RCB *p_clreg); | |
51 | + | |
51 | 52 | static tGATT_CBACK bta_gattc_cl_cback = |
52 | 53 | { |
53 | 54 | bta_gattc_conn_cback, |
@@ -84,6 +85,72 @@ static const char *bta_gattc_op_code_name[] = | ||
84 | 85 | |
85 | 86 | /******************************************************************************* |
86 | 87 | ** |
88 | +** Function bta_gattc_enable | |
89 | +** | |
90 | +** Description Enables GATTC module | |
91 | +** | |
92 | +** | |
93 | +** Returns void | |
94 | +** | |
95 | +*******************************************************************************/ | |
96 | +static void bta_gattc_enable(tBTA_GATTC_CB *p_cb) | |
97 | +{ | |
98 | + APPL_TRACE_DEBUG0("bta_gattc_enable"); | |
99 | + | |
100 | + if (p_cb->state == BTA_GATTC_STATE_DISABLED) | |
101 | + { | |
102 | + /* initialize control block */ | |
103 | + memset(&bta_gattc_cb, 0, sizeof(tBTA_GATTC_CB)); | |
104 | + p_cb->state = BTA_GATTC_STATE_ENABLED; | |
105 | + } | |
106 | + else | |
107 | + { | |
108 | + APPL_TRACE_DEBUG0("GATTC is arelady enabled"); | |
109 | + } | |
110 | +} | |
111 | + | |
112 | + | |
113 | +/******************************************************************************* | |
114 | +** | |
115 | +** Function bta_gattc_disable | |
116 | +** | |
117 | +** Description Disable GATTC module by cleaning up all active connections | |
118 | +** and deregister all application. | |
119 | +** | |
120 | +** Returns void | |
121 | +** | |
122 | +*******************************************************************************/ | |
123 | +void bta_gattc_disable(tBTA_GATTC_CB *p_cb) | |
124 | +{ | |
125 | + UINT8 i; | |
126 | + | |
127 | + APPL_TRACE_DEBUG0("bta_gattc_disable"); | |
128 | + | |
129 | + if (p_cb->state != BTA_GATTC_STATE_ENABLED) | |
130 | + { | |
131 | + APPL_TRACE_ERROR0("not enabled or disable in pogress"); | |
132 | + return; | |
133 | + } | |
134 | + | |
135 | + for (i = 0; i <BTA_GATTC_CL_MAX; i ++) | |
136 | + { | |
137 | + if (p_cb->cl_rcb[i].in_use) | |
138 | + { | |
139 | + p_cb->state = BTA_GATTC_STATE_DISABLING; | |
140 | + bta_gattc_deregister(p_cb, &p_cb->cl_rcb[i]); | |
141 | + } | |
142 | + } | |
143 | + | |
144 | + /* no registered apps, indicate disable completed */ | |
145 | + if (p_cb->state != BTA_GATTC_STATE_DISABLING) | |
146 | + { | |
147 | + p_cb->state = BTA_GATTC_STATE_DISABLED; | |
148 | + memset(p_cb, 0, sizeof(tBTA_GATTC_CB)); | |
149 | + } | |
150 | +} | |
151 | + | |
152 | +/******************************************************************************* | |
153 | +** | |
87 | 154 | ** Function bta_gattc_register |
88 | 155 | ** |
89 | 156 | ** Description Register a GATT client application with BTA. |
@@ -99,6 +166,13 @@ void bta_gattc_register(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_data) | ||
99 | 166 | tBTA_GATTC_INT_START_IF *p_buf; |
100 | 167 | tBTA_GATT_STATUS status = BTA_GATT_NO_RESOURCES; |
101 | 168 | |
169 | + APPL_TRACE_DEBUG1("bta_gattc_register state %d",p_cb->state); | |
170 | + | |
171 | + /* check if GATTC module is already enabled . Else enable */ | |
172 | + if (p_cb->state == BTA_GATTC_STATE_DISABLED) | |
173 | + { | |
174 | + bta_gattc_enable (p_cb); | |
175 | + } | |
102 | 176 | /* todo need to check duplicate uuid */ |
103 | 177 | for (i = 0; i < BTA_GATTC_CL_MAX; i ++) |
104 | 178 | { |
@@ -128,6 +202,9 @@ void bta_gattc_register(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_data) | ||
128 | 202 | } |
129 | 203 | else |
130 | 204 | { |
205 | + GATT_Deregister(p_cb->cl_rcb[i].client_if); | |
206 | + | |
207 | + status = BTA_GATT_NO_RESOURCES; | |
131 | 208 | memset( &p_cb->cl_rcb[i], 0 , sizeof(tBTA_GATTC_RCB)); |
132 | 209 | } |
133 | 210 | break; |
@@ -167,99 +244,6 @@ void bta_gattc_start_if(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_msg) | ||
167 | 244 | } |
168 | 245 | /******************************************************************************* |
169 | 246 | ** |
170 | -** Function bta_gattc_deregister_cmpl | |
171 | -** | |
172 | -** Description De-Register a GATT client application with BTA completed. | |
173 | -** | |
174 | -** Returns void | |
175 | -** | |
176 | -*******************************************************************************/ | |
177 | -void bta_gattc_int_deregister_cmpl(tBTA_GATTC_RCB *p_clreg, tBTA_GATTC_IF client_if) | |
178 | -{ | |
179 | - tBTA_GATTC_CBACK *p_cback = p_clreg->p_cback; | |
180 | - tBTA_GATTC cb_data; | |
181 | - | |
182 | - | |
183 | - APPL_TRACE_DEBUG1("bta_gattc_int_deregister_cmpl client_if=%d", client_if ); | |
184 | - | |
185 | - GATT_Deregister(p_clreg->client_if); | |
186 | - memset(p_clreg, 0, sizeof(tBTA_GATTC_RCB)); | |
187 | - | |
188 | - cb_data.reg_oper.client_if = client_if; | |
189 | - cb_data.reg_oper.status = BTA_GATT_OK; | |
190 | - | |
191 | - if (p_cback) | |
192 | - /* callback with de-register event */ | |
193 | - (*p_cback)(BTA_GATTC_DEREG_EVT, (tBTA_GATTC *)&cb_data); | |
194 | -} | |
195 | - | |
196 | - | |
197 | -/******************************************************************************* | |
198 | -** | |
199 | -** Function bta_gattc_deregister_cmpl | |
200 | -** | |
201 | -** Description De-Register a GATT client application with BTA completed. | |
202 | -** | |
203 | -** Returns void | |
204 | -** | |
205 | -*******************************************************************************/ | |
206 | -void bta_gattc_deregister_cmpl(tBTA_GATTC_RCB *p_clreg, tBTA_GATTC_IF client_if) | |
207 | -{ | |
208 | - tBTA_GATTC_INT_DEREG *p_buf; | |
209 | - | |
210 | - APPL_TRACE_DEBUG1("bta_gattc_deregister_cmpl client_if=%d", client_if ); | |
211 | - | |
212 | - if ((p_buf = (tBTA_GATTC_INT_DEREG *) GKI_getbuf(sizeof(tBTA_GATTC_INT_DEREG))) != NULL) | |
213 | - { | |
214 | - p_buf->hdr.event = BTA_GATTC_INT_DEREG_EVT; | |
215 | - p_buf->client_if = client_if; | |
216 | - bta_sys_sendmsg(p_buf); | |
217 | - } | |
218 | - else | |
219 | - { | |
220 | - APPL_TRACE_ERROR1("bta_gattc_deregister_cmpl unable to allocate buffer to complete dereg=%d", client_if); | |
221 | - } | |
222 | - | |
223 | -} | |
224 | -/******************************************************************************* | |
225 | -** | |
226 | -** Function bta_gattc_deregister | |
227 | -** | |
228 | -** Description De-Register a GATT client application with BTA. | |
229 | -** | |
230 | -** Returns void | |
231 | -** | |
232 | -*******************************************************************************/ | |
233 | -void bta_gattc_int_deregister(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_data) | |
234 | -{ | |
235 | - | |
236 | - tBTA_GATTC_IF client_if = p_data->int_dereg.client_if; | |
237 | - tBTA_GATTC_CBACK *p_cback; | |
238 | - tBTA_GATTC cb_data; | |
239 | - tBTA_GATTC_RCB *p_clreg; | |
240 | - | |
241 | - | |
242 | - APPL_TRACE_DEBUG1("bta_gattc_int_deregister_cmpl client_if=%d", client_if ); | |
243 | - | |
244 | - if ((p_clreg = bta_gattc_cl_get_regcb(client_if)) != NULL) | |
245 | - { | |
246 | - p_cback = p_clreg->p_cback; | |
247 | - GATT_Deregister(client_if); | |
248 | - memset(p_clreg, 0, sizeof(tBTA_GATTC_RCB)); | |
249 | - cb_data.reg_oper.client_if = client_if; | |
250 | - cb_data.reg_oper.status = BTA_GATT_OK; | |
251 | - | |
252 | - if (p_cback) | |
253 | - /* callback with de-register event */ | |
254 | - (*p_cback)(BTA_GATTC_DEREG_EVT, (tBTA_GATTC *)&cb_data); | |
255 | - } | |
256 | - else | |
257 | - { | |
258 | - APPL_TRACE_ERROR1("bta_gattc_int_deregister Deregister Failed, unknown client_if: %d", p_data->int_dereg.client_if); | |
259 | - } | |
260 | -} | |
261 | -/******************************************************************************* | |
262 | -** | |
263 | 247 | ** Function bta_gattc_deregister |
264 | 248 | ** |
265 | 249 | ** Description De-Register a GATT client application with BTA. |
@@ -267,14 +251,30 @@ void bta_gattc_int_deregister(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_data) | ||
267 | 251 | ** Returns void |
268 | 252 | ** |
269 | 253 | *******************************************************************************/ |
270 | -void bta_gattc_deregister(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_data) | |
254 | +void bta_gattc_deregister(tBTA_GATTC_CB *p_cb, tBTA_GATTC_RCB *p_clreg) | |
271 | 255 | { |
272 | - tBTA_GATTC_RCB *p_clreg; | |
273 | 256 | UINT8 i; |
274 | 257 | BT_HDR buf; |
275 | 258 | |
276 | - if ((p_clreg = bta_gattc_cl_get_regcb(p_data->api_dereg.client_if)) != NULL) | |
259 | + if (p_clreg != NULL) | |
277 | 260 | { |
261 | + /* remove bg connection associated with this rcb */ | |
262 | + for (i = 0; i < BTA_GATTC_KNOWN_SR_MAX; i ++) | |
263 | + { | |
264 | + if (p_cb->bg_track[i].in_use) | |
265 | + { | |
266 | + if (p_cb->bg_track[i].cif_mask & (1 <<(p_clreg->client_if - 1))) | |
267 | + { | |
268 | + bta_gattc_mark_bg_conn(p_clreg->client_if, p_cb->bg_track[i].remote_bda, FALSE, FALSE); | |
269 | + GATT_CancelConnect(p_clreg->client_if, p_cb->bg_track[i].remote_bda, FALSE); | |
270 | + } | |
271 | + if (p_cb->bg_track[i].cif_adv_mask & (1 <<(p_clreg->client_if - 1))) | |
272 | + { | |
273 | + bta_gattc_mark_bg_conn(p_clreg->client_if, p_cb->bg_track[i].remote_bda, FALSE, TRUE); | |
274 | + } | |
275 | + } | |
276 | + } | |
277 | + | |
278 | 278 | if (p_clreg->num_clcb > 0) |
279 | 279 | { |
280 | 280 | /* close all CLCB related to this app */ |
@@ -291,11 +291,11 @@ void bta_gattc_deregister(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_data) | ||
291 | 291 | } |
292 | 292 | } |
293 | 293 | else |
294 | - bta_gattc_deregister_cmpl(p_clreg, p_clreg->client_if); | |
294 | + bta_gattc_deregister_cmpl(p_clreg); | |
295 | 295 | } |
296 | 296 | else |
297 | 297 | { |
298 | - APPL_TRACE_ERROR1("bta_gattc_deregister Deregister Failed, unknown client_if: %d", p_data->api_dereg.client_if); | |
298 | + APPL_TRACE_ERROR0("bta_gattc_deregister Deregister Failedm unknown client cif"); | |
299 | 299 | } |
300 | 300 | } |
301 | 301 | /******************************************************************************* |
@@ -417,7 +417,7 @@ void bta_gattc_open_error(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data) | ||
417 | 417 | APPL_TRACE_ERROR0("Connection already opened. wrong state"); |
418 | 418 | |
419 | 419 | bta_gattc_send_open_cback(p_clcb->p_rcb, |
420 | - BTA_GATT_ALREADY_OPEN, | |
420 | + BTA_GATT_OK, | |
421 | 421 | p_clcb->bda, |
422 | 422 | p_clcb->bta_conn_id); |
423 | 423 | } |
@@ -432,7 +432,11 @@ void bta_gattc_open_error(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data) | ||
432 | 432 | *******************************************************************************/ |
433 | 433 | void bta_gattc_open_fail(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data) |
434 | 434 | { |
435 | - bta_gattc_open_error(p_clcb, p_data); | |
435 | + bta_gattc_send_open_cback(p_clcb->p_rcb, | |
436 | + BTA_GATT_ERROR, | |
437 | + p_clcb->bda, | |
438 | + p_clcb->bta_conn_id); | |
439 | + | |
436 | 440 | /* open failure, remove clcb */ |
437 | 441 | bta_gattc_clcb_dealloc(p_clcb); |
438 | 442 | } |
@@ -702,22 +706,22 @@ void bta_gattc_close(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data) | ||
702 | 706 | |
703 | 707 | APPL_TRACE_DEBUG1("bta_gattc_close conn_id=%d",p_clcb->bta_conn_id); |
704 | 708 | |
705 | - if (p_data->hdr.event == BTA_GATTC_API_CLOSE_EVT) | |
706 | - p_clcb->status = GATT_Disconnect(p_clcb->bta_conn_id); | |
707 | - | |
708 | 709 | cb_data.close.client_if = p_clcb->p_rcb->client_if; |
709 | 710 | cb_data.close.conn_id = p_clcb->bta_conn_id; |
710 | - cb_data.close.status = p_clcb->status; | |
711 | 711 | cb_data.close.reason = p_clcb->reason; |
712 | + cb_data.close.status = p_clcb->status; | |
712 | 713 | bdcpy(cb_data.close.remote_bda, p_clcb->bda); |
713 | 714 | |
714 | 715 | bta_gattc_clcb_dealloc(p_clcb); |
715 | 716 | |
717 | + if (p_data->hdr.event == BTA_GATTC_API_CLOSE_EVT) | |
718 | + cb_data.close.status = GATT_Disconnect(p_data->hdr.layer_specific); | |
719 | + | |
716 | 720 | ( * p_cback)(BTA_GATTC_CLOSE_EVT, (tBTA_GATTC *)&cb_data); |
717 | 721 | |
718 | 722 | if (p_clreg->num_clcb == 0 && p_clreg->dereg_pending) |
719 | 723 | { |
720 | - bta_gattc_deregister_cmpl(p_clreg, p_clreg->client_if); | |
724 | + bta_gattc_deregister_cmpl(p_clreg); | |
721 | 725 | } |
722 | 726 | } |
723 | 727 | /******************************************************************************* |
@@ -1494,7 +1498,7 @@ void bta_gattc_ci_load(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data) | ||
1494 | 1498 | { |
1495 | 1499 | p_clcb->p_srcb->state = BTA_GATTC_SERV_DISC; |
1496 | 1500 | p_clcb->p_srcb->attr_index = 0; |
1497 | - /* cache open failure, start discovery */ | |
1501 | + /* cache load failure, start discovery */ | |
1498 | 1502 | bta_gattc_start_discover(p_clcb, NULL); |
1499 | 1503 | } |
1500 | 1504 | } |
@@ -1535,6 +1539,40 @@ void bta_gattc_fail(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data) | ||
1535 | 1539 | APPL_TRACE_ERROR1("operation not supported at current state [%d]", p_clcb->state); |
1536 | 1540 | } |
1537 | 1541 | } |
1542 | + | |
1543 | +/******************************************************************************* | |
1544 | +** | |
1545 | +** Function bta_gattc_deregister_cmpl | |
1546 | +** | |
1547 | +** Description De-Register a GATT client application with BTA completed. | |
1548 | +** | |
1549 | +** Returns void | |
1550 | +** | |
1551 | +*******************************************************************************/ | |
1552 | +static void bta_gattc_deregister_cmpl(tBTA_GATTC_RCB *p_clreg) | |
1553 | +{ | |
1554 | + tBTA_GATTC_CB *p_cb = &bta_gattc_cb; | |
1555 | + tBTA_GATTC_IF client_if = p_clreg->client_if; | |
1556 | + tBTA_GATTC cb_data; | |
1557 | + tBTA_GATTC_CBACK *p_cback = p_clreg->p_cback; | |
1558 | + | |
1559 | + memset(&cb_data, 0, sizeof(tBTA_GATTC)); | |
1560 | + | |
1561 | + GATT_Deregister(p_clreg->client_if); | |
1562 | + memset(p_clreg, 0, sizeof(tBTA_GATTC_RCB)); | |
1563 | + | |
1564 | + cb_data.reg_oper.client_if = client_if; | |
1565 | + cb_data.reg_oper.status = BTA_GATT_OK; | |
1566 | + | |
1567 | + if (p_cback) | |
1568 | + /* callback with de-register event */ | |
1569 | + (*p_cback)(BTA_GATTC_DEREG_EVT, (tBTA_GATTC *)&cb_data); | |
1570 | + | |
1571 | + if (bta_gattc_num_reg_app() == 0 && p_cb->state == BTA_GATTC_STATE_DISABLING) | |
1572 | + { | |
1573 | + p_cb->state = BTA_GATTC_STATE_DISABLED; | |
1574 | + } | |
1575 | +} | |
1538 | 1576 | /******************************************************************************* |
1539 | 1577 | ** |
1540 | 1578 | ** Function bta_gattc_conn_cback |
@@ -1550,25 +1588,21 @@ static void bta_gattc_conn_cback(tGATT_IF gattc_if, BD_ADDR bda, UINT16 conn_id, | ||
1550 | 1588 | { |
1551 | 1589 | BT_HDR *p_buf; |
1552 | 1590 | tBTA_GATTC_CLCB *p_clcb = NULL; |
1553 | -#if BLE_INCLUDED == TRUE | |
1554 | 1591 | UINT8 role ; |
1555 | -#endif | |
1592 | + | |
1556 | 1593 | APPL_TRACE_DEBUG4("bta_gattc_conn_cback: cif = %d connected = %d conn_id = %d reaosn = 0x%04x", |
1557 | 1594 | gattc_if, connected, conn_id, reason); |
1558 | 1595 | |
1559 | 1596 | if (connected) |
1560 | 1597 | { |
1561 | -#if BLE_INCLUDED == TRUE | |
1562 | 1598 | role = L2CA_GetBleConnRole(bda); |
1563 | 1599 | |
1564 | 1600 | if (role == HCI_ROLE_SLAVE) |
1565 | 1601 | bta_gattc_conn_find_alloc(bda); |
1566 | -#endif | |
1567 | 1602 | |
1568 | 1603 | /* outgoing connection : locate a logic channel */ |
1569 | 1604 | if ((p_clcb = bta_gattc_find_clcb_by_cif(gattc_if, bda)) == NULL) |
1570 | 1605 | { |
1571 | -#if BLE_INCLUDED == TRUE | |
1572 | 1606 | /* for a background connection or listening connection */ |
1573 | 1607 | if (/* L2CA_GetBleConnRole(bda)== HCI_ROLE_MASTER && */ |
1574 | 1608 | bta_gattc_check_bg_conn(gattc_if, bda, role)) |
@@ -1576,7 +1610,6 @@ static void bta_gattc_conn_cback(tGATT_IF gattc_if, BD_ADDR bda, UINT16 conn_id, | ||
1576 | 1610 | /* allocate a new channel */ |
1577 | 1611 | p_clcb = bta_gattc_clcb_alloc(gattc_if, bda); |
1578 | 1612 | } |
1579 | -#endif | |
1580 | 1613 | } |
1581 | 1614 | if (p_clcb != NULL) |
1582 | 1615 | { |
@@ -1883,7 +1916,6 @@ static void bta_gattc_cmpl_cback(UINT16 conn_id, tGATTC_OPTYPE op, tGATT_STATUS | ||
1883 | 1916 | return; |
1884 | 1917 | } |
1885 | 1918 | |
1886 | - | |
1887 | 1919 | if ((p_buf = (tBTA_GATTC_OP_CMPL *) GKI_getbuf(len)) != NULL) |
1888 | 1920 | { |
1889 | 1921 | memset(p_buf, 0, len); |
@@ -32,38 +32,44 @@ | ||
32 | 32 | #include "bta_gatt_api.h" |
33 | 33 | #include "bta_gattc_int.h" |
34 | 34 | |
35 | - | |
36 | -/***************************************************************************** | |
37 | -** Externs | |
38 | -*****************************************************************************/ | |
39 | -#if BTA_DYNAMIC_MEMORY == FALSE | |
40 | -extern tBTA_GATTC_CB bta_gattc_cb; | |
41 | -#endif | |
42 | - | |
43 | 35 | /***************************************************************************** |
44 | 36 | ** Constants |
45 | 37 | *****************************************************************************/ |
46 | 38 | |
47 | -static const tBTA_SYS_REG bta_gatt_reg = | |
39 | +static const tBTA_SYS_REG bta_gattc_reg = | |
48 | 40 | { |
49 | 41 | bta_gattc_hdl_event, |
50 | - NULL /* need a disable functino to be called when BT is disabled */ | |
42 | + BTA_GATTC_Disable | |
51 | 43 | }; |
52 | 44 | |
45 | + | |
53 | 46 | /******************************************************************************* |
54 | 47 | ** |
55 | -** Function BTA_GATTC_Init | |
48 | +** Function BTA_GATTC_Disable | |
56 | 49 | ** |
57 | -** Description This function is called to initalize GATTC module | |
50 | +** Description This function is called to disable GATTC module | |
58 | 51 | ** |
59 | -** Parameters None | |
52 | +** Parameters None. | |
60 | 53 | ** |
61 | 54 | ** Returns None |
62 | 55 | ** |
63 | 56 | *******************************************************************************/ |
64 | -void BTA_GATTC_Init() | |
57 | +void BTA_GATTC_Disable(void) | |
65 | 58 | { |
66 | - memset(&bta_gattc_cb, 0, sizeof(tBTA_GATTC_CB)); | |
59 | + BT_HDR *p_buf; | |
60 | + | |
61 | + if (bta_sys_is_register(BTA_ID_GATTC) == FALSE) | |
62 | + { | |
63 | + APPL_TRACE_WARNING0("GATTC Module not enabled/already disabled"); | |
64 | + return; | |
65 | + } | |
66 | + if ((p_buf = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL) | |
67 | + { | |
68 | + p_buf->event = BTA_GATTC_API_DISABLE_EVT; | |
69 | + bta_sys_sendmsg(p_buf); | |
70 | + } | |
71 | + bta_sys_deregister(BTA_ID_GATTC); | |
72 | + | |
67 | 73 | } |
68 | 74 | |
69 | 75 | /******************************************************************************* |
@@ -83,10 +89,12 @@ void BTA_GATTC_AppRegister(tBT_UUID *p_app_uuid, tBTA_GATTC_CBACK *p_client_cb) | ||
83 | 89 | { |
84 | 90 | tBTA_GATTC_API_REG *p_buf; |
85 | 91 | |
86 | - /* register with BTA system manager */ | |
87 | - GKI_sched_lock(); | |
88 | - bta_sys_register(BTA_ID_GATTC, &bta_gatt_reg); | |
89 | - GKI_sched_unlock(); | |
92 | + if (bta_sys_is_register(BTA_ID_GATTC) == FALSE) | |
93 | + { | |
94 | + GKI_sched_lock(); | |
95 | + bta_sys_register(BTA_ID_GATTC, &bta_gattc_reg); | |
96 | + GKI_sched_unlock(); | |
97 | + } | |
90 | 98 | |
91 | 99 | if ((p_buf = (tBTA_GATTC_API_REG *) GKI_getbuf(sizeof(tBTA_GATTC_API_REG))) != NULL) |
92 | 100 | { |
@@ -68,7 +68,7 @@ enum | ||
68 | 68 | BTA_GATTC_INT_START_IF_EVT, |
69 | 69 | BTA_GATTC_API_REG_EVT, |
70 | 70 | BTA_GATTC_API_DEREG_EVT, |
71 | - BTA_GATTC_INT_DEREG_EVT | |
71 | + BTA_GATTC_API_DISABLE_EVT | |
72 | 72 | |
73 | 73 | }; |
74 | 74 | typedef UINT16 tBTA_GATTC_INT_EVT; |
@@ -91,6 +91,7 @@ typedef UINT16 tBTA_GATTC_INT_EVT; | ||
91 | 91 | |
92 | 92 | #define BTA_GATTC_WRITE_PREPARE GATT_WRITE_PREPARE |
93 | 93 | |
94 | + | |
94 | 95 | /* internal strucutre for GATTC register API */ |
95 | 96 | typedef struct |
96 | 97 | { |
@@ -363,8 +364,18 @@ typedef struct | ||
363 | 364 | BD_ADDR remote_bda; |
364 | 365 | }tBTA_GATTC_CONN; |
365 | 366 | |
367 | +enum | |
368 | +{ | |
369 | + BTA_GATTC_STATE_DISABLED, | |
370 | + BTA_GATTC_STATE_ENABLING, | |
371 | + BTA_GATTC_STATE_ENABLED, | |
372 | + BTA_GATTC_STATE_DISABLING | |
373 | +}; | |
374 | + | |
366 | 375 | typedef struct |
367 | 376 | { |
377 | + UINT8 state; | |
378 | + | |
368 | 379 | tBTA_GATTC_CONN conn_track[BTA_GATTC_CONN_MAX]; |
369 | 380 | tBTA_GATTC_BG_TCK bg_track[BTA_GATTC_KNOWN_SR_MAX]; |
370 | 381 | tBTA_GATTC_RCB cl_rcb[BTA_GATTC_CL_MAX]; |
@@ -395,12 +406,12 @@ extern BOOLEAN bta_gattc_hdl_event(BT_HDR *p_msg); | ||
395 | 406 | extern void bta_gattc_sm_execute(tBTA_GATTC_CLCB *p_clcb, UINT16 event, tBTA_GATTC_DATA *p_data); |
396 | 407 | |
397 | 408 | /* function processed outside SM */ |
409 | +extern void bta_gattc_disable(tBTA_GATTC_CB *p_cb); | |
398 | 410 | extern void bta_gattc_register(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_data); |
399 | 411 | extern void bta_gattc_start_if(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_data); |
400 | 412 | extern void bta_gattc_process_api_open (tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA * p_msg); |
401 | 413 | extern void bta_gattc_process_api_open_cancel (tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA * p_msg); |
402 | -extern void bta_gattc_deregister(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_data); | |
403 | -extern void bta_gattc_int_deregister(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_data); | |
414 | +extern void bta_gattc_deregister(tBTA_GATTC_CB *p_cb, tBTA_GATTC_RCB *p_clreg); | |
404 | 415 | |
405 | 416 | /* function within state machine */ |
406 | 417 | extern void bta_gattc_open(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data); |
@@ -346,12 +346,16 @@ BOOLEAN bta_gattc_hdl_event(BT_HDR *p_msg) | ||
346 | 346 | { |
347 | 347 | tBTA_GATTC_CB *p_cb = &bta_gattc_cb; |
348 | 348 | tBTA_GATTC_CLCB *p_clcb = NULL; |
349 | - | |
349 | + tBTA_GATTC_RCB *p_clreg; | |
350 | 350 | #if BTA_GATT_DEBUG == TRUE |
351 | 351 | APPL_TRACE_DEBUG1("bta_gattc_hdl_event: Event [%s]", gattc_evt_code(p_msg->event)); |
352 | 352 | #endif |
353 | 353 | switch (p_msg->event) |
354 | 354 | { |
355 | + case BTA_GATTC_API_DISABLE_EVT: | |
356 | + bta_gattc_disable(p_cb); | |
357 | + break; | |
358 | + | |
355 | 359 | case BTA_GATTC_API_REG_EVT: |
356 | 360 | bta_gattc_register(p_cb, (tBTA_GATTC_DATA *) p_msg); |
357 | 361 | break; |
@@ -361,11 +365,8 @@ BOOLEAN bta_gattc_hdl_event(BT_HDR *p_msg) | ||
361 | 365 | break; |
362 | 366 | |
363 | 367 | case BTA_GATTC_API_DEREG_EVT: |
364 | - bta_gattc_deregister(p_cb, (tBTA_GATTC_DATA *) p_msg); | |
365 | - break; | |
366 | - | |
367 | - case BTA_GATTC_INT_DEREG_EVT: | |
368 | - bta_gattc_int_deregister(p_cb, (tBTA_GATTC_DATA *) p_msg); | |
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); | |
369 | 370 | break; |
370 | 371 | |
371 | 372 | case BTA_GATTC_API_OPEN_EVT: |
@@ -465,6 +466,10 @@ static char *gattc_evt_code(tBTA_GATTC_INT_EVT evt_code) | ||
465 | 466 | return "BTA_GATTC_API_DEREG_EVT"; |
466 | 467 | case BTA_GATTC_API_REFRESH_EVT: |
467 | 468 | return "BTA_GATTC_API_REFRESH_EVT"; |
469 | + case BTA_GATTC_API_DISABLE_EVT: | |
470 | + return "BTA_GATTC_API_DISABLE_EVT"; | |
471 | + case BTA_GATTC_API_ENABLE_EVT: | |
472 | + return "BTA_GATTC_API_ENABLE_EVT"; | |
468 | 473 | default: |
469 | 474 | return "unknown GATTC event code"; |
470 | 475 | } |
@@ -105,24 +105,66 @@ void bta_gatts_enable(tBTA_GATTS_CB *p_cb) | ||
105 | 105 | { |
106 | 106 | UINT8 index=0; |
107 | 107 | tBTA_GATTS_HNDL_RANGE handle_range; |
108 | + tBTA_GATT_STATUS status = BTA_GATT_OK; | |
108 | 109 | |
109 | - p_cb->enabled = TRUE; | |
110 | - | |
111 | - APPL_TRACE_DEBUG0("bta_gatts_enable"); | |
112 | - while ( bta_gatts_co_load_handle_range(index, &handle_range)) | |
110 | + if (p_cb->enabled) | |
113 | 111 | { |
114 | - GATTS_AddHandleRange((tGATTS_HNDL_RANGE *)&handle_range); | |
115 | - memset(&handle_range, 0, sizeof(tGATTS_HNDL_RANGE)); | |
116 | - index++; | |
112 | + APPL_TRACE_DEBUG0("GATTS already enabled."); | |
117 | 113 | } |
114 | + else | |
115 | + { | |
116 | + memset(p_cb, 0, sizeof(tBTA_GATTS_CB)); | |
118 | 117 | |
119 | - APPL_TRACE_DEBUG1("bta_gatts_enable: num of handle range added=%d", index); | |
118 | + p_cb->enabled = TRUE; | |
120 | 119 | |
121 | - if (!GATTS_NVRegister(&bta_gatts_nv_cback)) | |
120 | + while ( bta_gatts_co_load_handle_range(index, &handle_range)) | |
121 | + { | |
122 | + GATTS_AddHandleRange((tGATTS_HNDL_RANGE *)&handle_range); | |
123 | + memset(&handle_range, 0, sizeof(tGATTS_HNDL_RANGE)); | |
124 | + index++; | |
125 | + } | |
126 | + | |
127 | + APPL_TRACE_DEBUG1("bta_gatts_enable: num of handle range added=%d", index); | |
128 | + | |
129 | + if (!GATTS_NVRegister(&bta_gatts_nv_cback)) | |
130 | + { | |
131 | + APPL_TRACE_ERROR0("BTA GATTS NV register failed."); | |
132 | + status = BTA_GATT_ERROR; | |
133 | + } | |
134 | + } | |
135 | +} | |
136 | + | |
137 | +/******************************************************************************* | |
138 | +** | |
139 | +** Function bta_gatts_api_disable | |
140 | +** | |
141 | +** Description disable BTA GATTS module. | |
142 | +** | |
143 | +** Returns none. | |
144 | +** | |
145 | +*******************************************************************************/ | |
146 | +void bta_gatts_api_disable(tBTA_GATTS_CB *p_cb) | |
147 | +{ | |
148 | + UINT8 i; | |
149 | + tBTA_GATT_STATUS status = BTA_GATT_OK; | |
150 | + | |
151 | + if (p_cb->enabled) | |
152 | + { | |
153 | + for (i = 0; i < BTA_GATTS_MAX_APP_NUM; i ++) | |
154 | + { | |
155 | + if (p_cb->rcb[i].in_use) | |
156 | + { | |
157 | + GATT_Deregister(p_cb->rcb[i].gatt_if); | |
158 | + } | |
159 | + } | |
160 | + memset(p_cb, 0, sizeof(tBTA_GATTS_CB)); | |
161 | + } | |
162 | + else | |
122 | 163 | { |
123 | - APPL_TRACE_ERROR0("BTA GATTS NV register failed."); | |
164 | + APPL_TRACE_ERROR0("GATTS not enabled"); | |
124 | 165 | } |
125 | 166 | } |
167 | + | |
126 | 168 | /******************************************************************************* |
127 | 169 | ** |
128 | 170 | ** Function bta_gatts_register |
@@ -139,9 +181,10 @@ void bta_gatts_register(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg) | ||
139 | 181 | tBTA_GATT_STATUS status = BTA_GATT_OK; |
140 | 182 | UINT8 i, first_unuse = 0xff; |
141 | 183 | |
142 | - if (!p_cb->enabled) | |
184 | + if (p_cb->enabled == FALSE) | |
185 | + { | |
143 | 186 | bta_gatts_enable(p_cb); |
144 | - | |
187 | + } | |
145 | 188 | |
146 | 189 | for (i = 0; i < BTA_GATTS_MAX_APP_NUM; i ++) |
147 | 190 | { |
@@ -33,36 +33,43 @@ | ||
33 | 33 | #include "bta_gatts_int.h" |
34 | 34 | |
35 | 35 | /***************************************************************************** |
36 | -** Externs | |
37 | -*****************************************************************************/ | |
38 | -#if BTA_DYNAMIC_MEMORY == FALSE | |
39 | -extern tBTA_GATTS_CB bta_gatts_cb; | |
40 | -#endif | |
41 | - | |
42 | -/***************************************************************************** | |
43 | 36 | ** Constants |
44 | 37 | *****************************************************************************/ |
45 | 38 | |
46 | 39 | static const tBTA_SYS_REG bta_gatts_reg = |
47 | 40 | { |
48 | 41 | bta_gatts_hdl_event, |
49 | - NULL /* need a disable functino to be called when BT is disabled */ | |
42 | + BTA_GATTS_Disable | |
50 | 43 | }; |
51 | 44 | |
52 | 45 | /******************************************************************************* |
53 | 46 | ** |
54 | -** Function BTA_GATTS_Init | |
47 | +** Function BTA_GATTS_Disable | |
55 | 48 | ** |
56 | -** Description This function is called to initalize GATTS module | |
49 | +** Description This function is called to disable GATTS module | |
57 | 50 | ** |
58 | -** Parameters None | |
51 | +** Parameters None. | |
59 | 52 | ** |
60 | 53 | ** Returns None |
61 | 54 | ** |
62 | 55 | *******************************************************************************/ |
63 | -void BTA_GATTS_Init() | |
56 | +void BTA_GATTS_Disable(void) | |
64 | 57 | { |
65 | - memset(&bta_gatts_cb, 0, sizeof(tBTA_GATTS_CB)); | |
58 | + BT_HDR *p_buf; | |
59 | + | |
60 | + if (bta_sys_is_register(BTA_ID_GATTS) == FALSE) | |
61 | + { | |
62 | + APPL_TRACE_WARNING0("GATTS Module not enabled/already disabled"); | |
63 | + return; | |
64 | + } | |
65 | + | |
66 | + if ((p_buf = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL) | |
67 | + { | |
68 | + p_buf->event = BTA_GATTS_API_DISABLE_EVT; | |
69 | + bta_sys_sendmsg(p_buf); | |
70 | + } | |
71 | + bta_sys_deregister(BTA_ID_GATTS); | |
72 | + | |
66 | 73 | } |
67 | 74 | |
68 | 75 | /******************************************************************************* |
@@ -83,12 +90,12 @@ void BTA_GATTS_AppRegister(tBT_UUID *p_app_uuid, tBTA_GATTS_CBACK *p_cback) | ||
83 | 90 | tBTA_GATTS_API_REG *p_buf; |
84 | 91 | |
85 | 92 | /* register with BTA system manager */ |
86 | - GKI_sched_lock(); | |
87 | - if (!bta_gatts_cb.enabled) | |
88 | - { | |
93 | + if (bta_sys_is_register(BTA_ID_GATTS) == FALSE) | |
94 | + { | |
95 | + GKI_sched_lock(); | |
89 | 96 | bta_sys_register(BTA_ID_GATTS, &bta_gatts_reg); |
97 | + GKI_sched_unlock(); | |
90 | 98 | } |
91 | - GKI_sched_unlock(); | |
92 | 99 | |
93 | 100 | if ((p_buf = (tBTA_GATTS_API_REG *) GKI_getbuf(sizeof(tBTA_GATTS_API_REG))) != NULL) |
94 | 101 | { |
@@ -52,8 +52,8 @@ enum | ||
52 | 52 | BTA_GATTS_API_OPEN_EVT, |
53 | 53 | BTA_GATTS_API_CANCEL_OPEN_EVT, |
54 | 54 | BTA_GATTS_API_CLOSE_EVT, |
55 | - BTA_GATTS_API_LISTEN_EVT | |
56 | - | |
55 | + BTA_GATTS_API_LISTEN_EVT, | |
56 | + BTA_GATTS_API_DISABLE_EVT | |
57 | 57 | }; |
58 | 58 | typedef UINT16 tBTA_GATTS_INT_EVT; |
59 | 59 |
@@ -224,6 +224,8 @@ extern tBTA_GATTS_CB *bta_gatts_cb_ptr; | ||
224 | 224 | *****************************************************************************/ |
225 | 225 | extern BOOLEAN bta_gatts_hdl_event(BT_HDR *p_msg); |
226 | 226 | |
227 | +extern void bta_gatts_api_disable(tBTA_GATTS_CB *p_cb); | |
228 | +extern void bta_gatts_api_enable(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_data); | |
227 | 229 | extern void bta_gatts_register(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg); |
228 | 230 | extern void bta_gatts_start_if(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg); |
229 | 231 | extern void bta_gatts_deregister(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg); |
@@ -67,6 +67,10 @@ BOOLEAN bta_gatts_hdl_event(BT_HDR *p_msg) | ||
67 | 67 | |
68 | 68 | switch (p_msg->event) |
69 | 69 | { |
70 | + case BTA_GATTS_API_DISABLE_EVT: | |
71 | + bta_gatts_api_disable(p_cb); | |
72 | + break; | |
73 | + | |
70 | 74 | case BTA_GATTS_API_REG_EVT: |
71 | 75 | bta_gatts_register(p_cb, (tBTA_GATTS_DATA *) p_msg); |
72 | 76 | break; |
@@ -364,6 +364,9 @@ typedef union | ||
364 | 364 | BD_ADDR remote_bda; /* service change event */ |
365 | 365 | } tBTA_GATTC; |
366 | 366 | |
367 | +/* GATTC enable callback function */ | |
368 | +typedef void (tBTA_GATTC_ENB_CBACK)(tBTA_GATT_STATUS status); | |
369 | + | |
367 | 370 | /* Client callback function */ |
368 | 371 | typedef void (tBTA_GATTC_CBACK)(tBTA_GATTC_EVT event, tBTA_GATTC *p_data); |
369 | 372 |
@@ -547,9 +550,12 @@ typedef union | ||
547 | 550 | |
548 | 551 | }tBTA_GATTS; |
549 | 552 | |
553 | +/* GATTS enable callback function */ | |
554 | +typedef void (tBTA_GATTS_ENB_CBACK)(tBTA_GATT_STATUS status); | |
550 | 555 | |
551 | 556 | /* Server callback function */ |
552 | 557 | typedef void (tBTA_GATTS_CBACK)(tBTA_GATTS_EVT event, tBTA_GATTS *p_data); |
558 | + | |
553 | 559 | /***************************************************************************** |
554 | 560 | ** External Function Declarations |
555 | 561 | *****************************************************************************/ |
@@ -565,16 +571,16 @@ extern "C" | ||
565 | 571 | |
566 | 572 | /******************************************************************************* |
567 | 573 | ** |
568 | -** Function BTA_GATTC_Init | |
574 | +** Function BTA_GATTC_Disable | |
569 | 575 | ** |
570 | -** Description This function is called to initalize GATTC module | |
576 | +** Description This function is called to disable the GATTC module | |
571 | 577 | ** |
572 | -** Parameters None | |
578 | +** Parameters None. | |
573 | 579 | ** |
574 | 580 | ** Returns None |
575 | 581 | ** |
576 | 582 | *******************************************************************************/ |
577 | -BTA_API extern void BTA_GATTC_Init(); | |
583 | +BTA_API extern void BTA_GATTC_Disable(void); | |
578 | 584 | |
579 | 585 | /******************************************************************************* |
580 | 586 | ** |
@@ -1017,6 +1023,19 @@ BTA_API extern void BTA_GATTC_Refresh(BD_ADDR remote_bda); | ||
1017 | 1023 | |
1018 | 1024 | /******************************************************************************* |
1019 | 1025 | ** |
1026 | +** Function BTA_GATTS_Disable | |
1027 | +** | |
1028 | +** Description This function is called to disable GATTS module | |
1029 | +** | |
1030 | +** Parameters None. | |
1031 | +** | |
1032 | +** Returns None | |
1033 | +** | |
1034 | +*******************************************************************************/ | |
1035 | + BTA_API extern void BTA_GATTS_Disable(void); | |
1036 | + | |
1037 | +/******************************************************************************* | |
1038 | +** | |
1020 | 1039 | ** Function BTA_GATTS_AppRegister |
1021 | 1040 | ** |
1022 | 1041 | ** Description This function is called to register application callbacks |
@@ -1417,7 +1417,7 @@ bt_status_t btif_enable_service(tBTA_SERVICE_ID service_id) | ||
1417 | 1417 | |
1418 | 1418 | btif_enabled_services |= (1 << service_id); |
1419 | 1419 | |
1420 | - BTIF_TRACE_ERROR2("%s: current services:0x%x", __FUNCTION__, btif_enabled_services); | |
1420 | + BTIF_TRACE_DEBUG2("%s: current services:0x%x", __FUNCTION__, btif_enabled_services); | |
1421 | 1421 | |
1422 | 1422 | if (btif_is_enabled()) |
1423 | 1423 | { |
@@ -1450,7 +1450,7 @@ bt_status_t btif_disable_service(tBTA_SERVICE_ID service_id) | ||
1450 | 1450 | |
1451 | 1451 | btif_enabled_services &= (tBTA_SERVICE_MASK)(~(1<<service_id)); |
1452 | 1452 | |
1453 | - BTIF_TRACE_ERROR2("%s: Current Services:0x%x", __FUNCTION__, btif_enabled_services); | |
1453 | + BTIF_TRACE_DEBUG2("%s: Current Services:0x%x", __FUNCTION__, btif_enabled_services); | |
1454 | 1454 | |
1455 | 1455 | if (btif_is_enabled()) |
1456 | 1456 | { |
@@ -58,16 +58,13 @@ extern btgatt_server_interface_t btgattServerInterface; | ||
58 | 58 | ** |
59 | 59 | ** Description Initializes the GATT interface |
60 | 60 | ** |
61 | -** Returns s bt_status_t | |
61 | +** Returns bt_status_t | |
62 | 62 | ** |
63 | 63 | *******************************************************************************/ |
64 | 64 | static bt_status_t btif_gatt_init( const btgatt_callbacks_t* callbacks ) |
65 | 65 | { |
66 | 66 | bt_gatt_callbacks = callbacks; |
67 | 67 | |
68 | - BTA_GATTC_Init(); | |
69 | - BTA_GATTS_Init(); | |
70 | - | |
71 | 68 | return BT_STATUS_SUCCESS; |
72 | 69 | } |
73 | 70 |
@@ -84,6 +81,9 @@ static void btif_gatt_cleanup( void ) | ||
84 | 81 | { |
85 | 82 | if (bt_gatt_callbacks) |
86 | 83 | bt_gatt_callbacks = NULL; |
84 | + | |
85 | + BTA_GATTC_Disable(); | |
86 | + BTA_GATTS_Disable(); | |
87 | 87 | } |
88 | 88 | |
89 | 89 | static const btgatt_interface_t btgattInterface = { |
@@ -1293,6 +1293,9 @@ void GATT_Deregister (tGATT_IF gatt_if) | ||
1293 | 1293 | } |
1294 | 1294 | |
1295 | 1295 | gatt_deregister_bgdev_list(gatt_if); |
1296 | + /* update the listen mode */ | |
1297 | + GATT_Listen(gatt_if, FALSE, NULL); | |
1298 | + | |
1296 | 1299 | memset (p_reg, 0, sizeof(tGATT_REG)); |
1297 | 1300 | } |
1298 | 1301 |
@@ -1564,7 +1567,7 @@ BOOLEAN GATT_GetConnIdIfConnected(tGATT_IF gatt_if, BD_ADDR bd_addr, UINT16 *p_c | ||
1564 | 1567 | ** Parameters gatt_if: applicaiton interface |
1565 | 1568 | ** p_bd_addr: listen for specific address connection, or NULL for |
1566 | 1569 | ** listen to all device connection. |
1567 | -** start: is a direct conenection or a background auto connection | |
1570 | +** start: start or stop listening. | |
1568 | 1571 | ** |
1569 | 1572 | ** Returns TRUE if advertisement is started; FALSE if adv start failure. |
1570 | 1573 | ** |
@@ -2322,6 +2322,8 @@ BOOLEAN gatt_add_bg_dev_list(tGATT_REG *p_reg, BD_ADDR bd_addr, BOOLEAN is_init | ||
2322 | 2322 | p_dev->gatt_if[i] = gatt_if; |
2323 | 2323 | if (i == 0) |
2324 | 2324 | ret = BTM_BleUpdateBgConnDev(TRUE, bd_addr); |
2325 | + else | |
2326 | + ret = TRUE; | |
2325 | 2327 | break; |
2326 | 2328 | } |
2327 | 2329 | } |
@@ -2342,6 +2344,8 @@ BOOLEAN gatt_add_bg_dev_list(tGATT_REG *p_reg, BD_ADDR bd_addr, BOOLEAN is_init | ||
2342 | 2344 | |
2343 | 2345 | if (i == 0) |
2344 | 2346 | ret = BTM_BleUpdateAdvWhitelist(TRUE, bd_addr); |
2347 | + else | |
2348 | + ret = TRUE; | |
2345 | 2349 | break; |
2346 | 2350 | } |
2347 | 2351 | } |
@@ -2515,26 +2519,38 @@ void gatt_deregister_bgdev_list(tGATT_IF gatt_if) | ||
2515 | 2519 | { |
2516 | 2520 | tGATT_BG_CONN_DEV *p_dev_list = &gatt_cb.bgconn_dev[0]; |
2517 | 2521 | UINT8 i , j, k; |
2522 | + tGATT_REG *p_reg = gatt_get_regcb(gatt_if); | |
2518 | 2523 | |
2524 | + /* update the BG conn device list */ | |
2519 | 2525 | for (i = 0 ; i <GATT_MAX_BG_CONN_DEV; i ++, p_dev_list ++ ) |
2520 | 2526 | { |
2521 | 2527 | if (p_dev_list->in_use) |
2522 | 2528 | { |
2523 | 2529 | for (j = 0; j < GATT_MAX_APPS; j ++) |
2524 | 2530 | { |
2525 | - if (p_dev_list->gatt_if[j] == 0) | |
2531 | + if (p_dev_list->gatt_if[j] == 0 && p_dev_list->listen_gif[j] == 0) | |
2526 | 2532 | break; |
2527 | - else if (p_dev_list->gatt_if[j] == gatt_if) | |
2533 | + | |
2534 | + if (p_dev_list->gatt_if[j] == gatt_if) | |
2528 | 2535 | { |
2529 | 2536 | for (k = j + 1; k < GATT_MAX_APPS; k ++) |
2530 | 2537 | p_dev_list->gatt_if[k - 1] = p_dev_list->gatt_if[k]; |
2531 | 2538 | |
2532 | 2539 | if (p_dev_list->gatt_if[0] == 0) |
2533 | - { | |
2534 | 2540 | BTM_BleUpdateBgConnDev(FALSE, p_dev_list->remote_bda); |
2535 | - memset(p_dev_list, 0, sizeof(tGATT_BG_CONN_DEV)); | |
2536 | - break; | |
2537 | - } | |
2541 | + } | |
2542 | + | |
2543 | + if (p_dev_list->listen_gif[j] == gatt_if) | |
2544 | + { | |
2545 | + p_dev_list->listen_gif[j] = 0; | |
2546 | + p_reg->listening --; | |
2547 | + | |
2548 | + /* move all element behind one forward */ | |
2549 | + for (k = j + 1; k < GATT_MAX_APPS; k ++) | |
2550 | + p_dev_list->listen_gif[k - 1] = p_dev_list->listen_gif[k]; | |
2551 | + | |
2552 | + if (p_dev_list->listen_gif[0] == 0) | |
2553 | + BTM_BleUpdateAdvWhitelist(FALSE, p_dev_list->remote_bda); | |
2538 | 2554 | } |
2539 | 2555 | } |
2540 | 2556 | } |