1 /******************************************************************************
2 *
3 * Copyright (C) 2010-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 is the implementation of the API for GATT server of BTA.
22 *
23 ******************************************************************************/
24
25 #include "common/bt_target.h"
26
27 #if defined(GATTS_INCLUDED) && (GATTS_INCLUDED == TRUE)
28
29 #include <string.h>
30 #include "bta/bta_sys.h"
31 #include "bta/bta_gatt_api.h"
32 #include "bta_gatts_int.h"
33 #include "osi/allocator.h"
34 #include "stack/l2c_api.h"
35
36 /*****************************************************************************
37 ** Constants
38 *****************************************************************************/
39
40 static const tBTA_SYS_REG bta_gatts_reg = {
41 bta_gatts_hdl_event,
42 BTA_GATTS_Disable
43 };
44
45 /*******************************************************************************
46 **
47 ** Function BTA_GATTS_Disable
48 **
49 ** Description This function is called to disable GATTS module
50 **
51 ** Parameters None.
52 **
53 ** Returns None
54 **
55 *******************************************************************************/
BTA_GATTS_Disable(void)56 void BTA_GATTS_Disable(void)
57 {
58 BT_HDR *p_buf;
59
60 if (bta_sys_is_register(BTA_ID_GATTS) == FALSE) {
61 APPL_TRACE_WARNING("GATTS Module not enabled/already disabled");
62 return;
63 }
64
65 if ((p_buf = (BT_HDR *) osi_malloc(sizeof(BT_HDR))) != NULL) {
66 p_buf->event = BTA_GATTS_API_DISABLE_EVT;
67 bta_sys_sendmsg(p_buf);
68 }
69 bta_sys_deregister(BTA_ID_GATTS);
70
71 }
72
73 /*******************************************************************************
74 **
75 ** Function BTA_GATTS_AppRegister
76 **
77 ** Description This function is called to register application callbacks
78 ** with BTA GATTS module.
79 **
80 ** Parameters p_app_uuid - application UUID
81 ** p_cback - pointer to the application callback function.
82 **
83 ** Returns None
84 **
85 *******************************************************************************/
BTA_GATTS_AppRegister(const tBT_UUID * p_app_uuid,tBTA_GATTS_CBACK * p_cback)86 void BTA_GATTS_AppRegister(const tBT_UUID * p_app_uuid, tBTA_GATTS_CBACK *p_cback)
87 {
88 tBTA_GATTS_API_REG *p_buf;
89
90 /* register with BTA system manager */
91 if (bta_sys_is_register(BTA_ID_GATTS) == FALSE) {
92 bta_sys_register(BTA_ID_GATTS, &bta_gatts_reg);
93 }
94
95 if ((p_buf = (tBTA_GATTS_API_REG *) osi_malloc(sizeof(tBTA_GATTS_API_REG))) != NULL) {
96 p_buf->hdr.event = BTA_GATTS_API_REG_EVT;
97
98 if (p_app_uuid != NULL) {
99 memcpy(&p_buf->app_uuid, p_app_uuid, sizeof(tBT_UUID));
100 }
101 p_buf->p_cback = p_cback;
102
103 bta_sys_sendmsg(p_buf);
104 }
105 return;
106 }
107
108
109
110 /*******************************************************************************
111 **
112 ** Function BTA_GATTS_AppDeregister
113 **
114 ** Description De-register with GATT Server.
115 **
116 ** Parameters app_id: applicatino ID.
117 **
118 ** Returns void
119 **
120 *******************************************************************************/
BTA_GATTS_AppDeregister(tBTA_GATTS_IF server_if)121 void BTA_GATTS_AppDeregister(tBTA_GATTS_IF server_if)
122 {
123 tBTA_GATTS_API_DEREG *p_buf;
124
125 if ((p_buf = (tBTA_GATTS_API_DEREG *) osi_malloc(sizeof(tBTA_GATTS_API_DEREG))) != NULL) {
126 p_buf->hdr.event = BTA_GATTS_API_DEREG_EVT;
127 p_buf->server_if = server_if;
128
129 bta_sys_sendmsg(p_buf);
130 }
131 return;
132 }
133
134 /*******************************************************************************
135 **
136 ** Function BTA_GATTS_CreateService
137 **
138 ** Description Create a service. When service creation is done, a callback
139 ** event BTA_GATTS_CREATE_EVT is called to report status
140 ** and service ID to the profile. The service ID obtained in
141 ** the callback function needs to be used when adding included
142 ** service and characteristics/descriptors into the service.
143 **
144 ** Parameters app_id: Profile ID this service is belonged to.
145 ** p_service_uuid: service UUID.
146 ** inst: instance ID number of this service.
147 ** num_handle: numble of handle requessted for this service.
148 ** is_primary: is this service a primary one or not.
149 **
150 ** Returns void
151 **
152 *******************************************************************************/
BTA_GATTS_CreateService(tBTA_GATTS_IF server_if,const tBT_UUID * p_service_uuid,UINT8 inst,UINT16 num_handle,BOOLEAN is_primary)153 void BTA_GATTS_CreateService(tBTA_GATTS_IF server_if, const tBT_UUID * p_service_uuid, UINT8 inst,
154 UINT16 num_handle, BOOLEAN is_primary)
155 {
156 tBTA_GATTS_API_CREATE_SRVC *p_buf;
157
158 if ((p_buf = (tBTA_GATTS_API_CREATE_SRVC *) osi_malloc(sizeof(tBTA_GATTS_API_CREATE_SRVC))) != NULL) {
159 p_buf->hdr.event = BTA_GATTS_API_CREATE_SRVC_EVT;
160
161 p_buf->server_if = server_if;
162 p_buf->inst = inst;
163 memcpy(&p_buf->service_uuid, p_service_uuid, sizeof(tBT_UUID));
164 p_buf->num_handle = num_handle;
165 p_buf->is_pri = is_primary;
166
167 bta_sys_sendmsg(p_buf);
168 }
169 return;
170 }
171 /*******************************************************************************
172 **
173 ** Function BTA_GATTS_AddIncludeService
174 **
175 ** Description This function is called to add an included service. After included
176 ** service is included, a callback event BTA_GATTS_ADD_INCL_SRVC_EVT
177 ** is reported the included service ID.
178 **
179 ** Parameters service_id: service ID to which this included service is to
180 ** be added.
181 ** included_service_id: the service ID to be included.
182 **
183 ** Returns void
184 **
185 *******************************************************************************/
BTA_GATTS_AddIncludeService(UINT16 service_id,UINT16 included_service_id)186 void BTA_GATTS_AddIncludeService(UINT16 service_id, UINT16 included_service_id)
187 {
188 tBTA_GATTS_API_ADD_INCL_SRVC *p_buf;
189
190 if ((p_buf =
191 (tBTA_GATTS_API_ADD_INCL_SRVC *) osi_malloc(sizeof(tBTA_GATTS_API_ADD_INCL_SRVC)))
192 != NULL) {
193 p_buf->hdr.event = BTA_GATTS_API_ADD_INCL_SRVC_EVT;
194
195 p_buf->hdr.layer_specific = service_id;
196 p_buf->included_service_id = included_service_id;
197
198 bta_sys_sendmsg(p_buf);
199 }
200 return;
201
202 }
203 /*******************************************************************************
204 **
205 ** Function BTA_GATTS_AddCharacteristic
206 **
207 ** Description This function is called to add a characteristic into a service.
208 **
209 ** Parameters service_id: service ID to which this included service is to
210 ** be added.
211 ** p_char_uuid : Characteristic UUID.
212 ** perm : Characteristic value declaration attribute permission.
213 ** property : Characteristic Properties
214 **
215 ** Returns None
216 **
217 *******************************************************************************/
BTA_GATTS_AddCharacteristic(UINT16 service_id,const tBT_UUID * p_char_uuid,tBTA_GATT_PERM perm,tBTA_GATT_CHAR_PROP property,tGATT_ATTR_VAL * attr_val,tBTA_GATTS_ATTR_CONTROL * control)218 void BTA_GATTS_AddCharacteristic (UINT16 service_id, const tBT_UUID * p_char_uuid,
219 tBTA_GATT_PERM perm, tBTA_GATT_CHAR_PROP property, tGATT_ATTR_VAL *attr_val,
220 tBTA_GATTS_ATTR_CONTROL *control)
221 {
222 tBTA_GATTS_API_ADD_CHAR *p_buf;
223 UINT16 len = 0;
224 if(attr_val != NULL){
225 len = attr_val->attr_len;
226 }
227 if ((p_buf = (tBTA_GATTS_API_ADD_CHAR *) osi_malloc(sizeof(tBTA_GATTS_API_ADD_CHAR))) != NULL) {
228 memset(p_buf, 0, sizeof(tBTA_GATTS_API_ADD_CHAR));
229
230 p_buf->hdr.event = BTA_GATTS_API_ADD_CHAR_EVT;
231 p_buf->hdr.layer_specific = service_id;
232 p_buf->perm = perm;
233 p_buf->property = property;
234 if(control !=NULL){
235 p_buf->control.auto_rsp = control->auto_rsp;
236 }
237 if(attr_val != NULL){
238 APPL_TRACE_DEBUG("!!!!!!attr_val->attr_len = %x\n",attr_val->attr_len);
239 APPL_TRACE_DEBUG("!!!!!!!attr_val->attr_max_len = %x\n",attr_val->attr_max_len);
240 p_buf->attr_val.attr_len = attr_val->attr_len;
241 p_buf->attr_val.attr_max_len = attr_val->attr_max_len;
242 p_buf->attr_val.attr_val = (uint8_t *)osi_malloc(len);
243 if(p_buf->attr_val.attr_val != NULL){
244 memcpy(p_buf->attr_val.attr_val, attr_val->attr_val, attr_val->attr_len);
245 }
246 }
247
248 if (p_char_uuid) {
249 memcpy(&p_buf->char_uuid, p_char_uuid, sizeof(tBT_UUID));
250 }
251 bta_sys_sendmsg(p_buf);
252 }
253 return;
254 }
255
256 /*******************************************************************************
257 **
258 ** Function BTA_GATTS_AddCharDescriptor
259 **
260 ** Description This function is called to add characteristic descriptor. When
261 ** it's done, a callback event BTA_GATTS_ADD_DESCR_EVT is called
262 ** to report the status and an ID number for this descriptor.
263 **
264 ** Parameters service_id: service ID to which this charatceristic descriptor is to
265 ** be added.
266 ** perm: descriptor access permission.
267 ** p_descr_uuid: descriptor UUID.
268 **
269 ** Returns returns status.
270 **
271 *******************************************************************************/
BTA_GATTS_AddCharDescriptor(UINT16 service_id,tBTA_GATT_PERM perm,const tBT_UUID * p_descr_uuid,tBTA_GATT_ATTR_VAL * attr_val,tBTA_GATTS_ATTR_CONTROL * control)272 void BTA_GATTS_AddCharDescriptor (UINT16 service_id,
273 tBTA_GATT_PERM perm,
274 const tBT_UUID * p_descr_uuid, tBTA_GATT_ATTR_VAL *attr_val,
275 tBTA_GATTS_ATTR_CONTROL *control)
276 {
277 tBTA_GATTS_API_ADD_DESCR *p_buf;
278 UINT16 value_len = 0;
279
280 if ((p_buf = (tBTA_GATTS_API_ADD_DESCR *) osi_malloc(sizeof(tBTA_GATTS_API_ADD_DESCR))) != NULL) {
281 memset(p_buf, 0, sizeof(tBTA_GATTS_API_ADD_DESCR));
282
283 p_buf->hdr.event = BTA_GATTS_API_ADD_DESCR_EVT;
284 p_buf->hdr.layer_specific = service_id;
285 p_buf->perm = perm;
286
287 if(control != NULL){
288 p_buf->control.auto_rsp = control->auto_rsp;
289 }
290
291 if (p_descr_uuid) {
292 memcpy(&p_buf->descr_uuid, p_descr_uuid, sizeof(tBT_UUID));
293 }
294
295 if(attr_val != NULL){
296 p_buf->attr_val.attr_len = attr_val->attr_len;
297 p_buf->attr_val.attr_max_len = attr_val->attr_max_len;
298 value_len = attr_val->attr_len;
299 if (value_len != 0){
300 p_buf->attr_val.attr_val = (uint8_t*)osi_malloc(value_len);
301 if(p_buf->attr_val.attr_val != NULL){
302 memcpy(p_buf->attr_val.attr_val, attr_val->attr_val, value_len);
303 }
304 else{
305 APPL_TRACE_ERROR("Allocate fail for %s\n", __func__);
306
307 }
308 }
309 }
310
311 bta_sys_sendmsg(p_buf);
312 }
313 return;
314
315 }
316
317 /*******************************************************************************
318 **
319 ** Function BTA_GATTS_DeleteService
320 **
321 ** Description This function is called to delete a service. When this is done,
322 ** a callback event BTA_GATTS_DELETE_EVT is report with the status.
323 **
324 ** Parameters service_id: service_id to be deleted.
325 **
326 ** Returns returns none.
327 **
328 *******************************************************************************/
BTA_GATTS_DeleteService(UINT16 service_id)329 void BTA_GATTS_DeleteService(UINT16 service_id)
330 {
331 BT_HDR *p_buf;
332
333 if ((p_buf = (BT_HDR *) osi_malloc(sizeof(BT_HDR))) != NULL) {
334 p_buf->event = BTA_GATTS_API_DEL_SRVC_EVT;
335
336 p_buf->layer_specific = service_id;
337
338 bta_sys_sendmsg(p_buf);
339 }
340 return;
341
342 }
343
344 /*******************************************************************************
345 **
346 ** Function BTA_GATTS_StartService
347 **
348 ** Description This function is called to start a service.
349 **
350 ** Parameters service_id: the service ID to be started.
351 ** sup_transport: supported transport.
352 **
353 ** Returns None.
354 **
355 *******************************************************************************/
BTA_GATTS_StartService(UINT16 service_id,tBTA_GATT_TRANSPORT sup_transport)356 void BTA_GATTS_StartService(UINT16 service_id, tBTA_GATT_TRANSPORT sup_transport)
357 {
358 tBTA_GATTS_API_START *p_buf;
359
360 if ((p_buf = (tBTA_GATTS_API_START *) osi_malloc(sizeof(tBTA_GATTS_API_START))) != NULL) {
361 p_buf->hdr.event = BTA_GATTS_API_START_SRVC_EVT;
362
363 p_buf->hdr.layer_specific = service_id;
364 p_buf->transport = sup_transport;
365
366 bta_sys_sendmsg(p_buf);
367 }
368 return;
369 }
370
371 /*******************************************************************************
372 **
373 ** Function BTA_GATTS_StopService
374 **
375 ** Description This function is called to stop a service.
376 **
377 ** Parameters service_id - service to be topped.
378 **
379 ** Returns None
380 **
381 *******************************************************************************/
BTA_GATTS_StopService(UINT16 service_id)382 void BTA_GATTS_StopService(UINT16 service_id)
383 {
384 BT_HDR *p_buf;
385
386 if ((p_buf = (BT_HDR *) osi_malloc(sizeof(BT_HDR))) != NULL) {
387 p_buf->event = BTA_GATTS_API_STOP_SRVC_EVT;
388
389 p_buf->layer_specific = service_id;
390
391 bta_sys_sendmsg(p_buf);
392 }
393 return;
394 }
395
396 /*******************************************************************************
397 **
398 ** Function BTA_GATTS_HandleValueIndication
399 **
400 ** Description This function is called to read a characteristics descriptor.
401 **
402 ** Parameters bda - remote device bd address to indicate.
403 ** attr_id - attribute ID to indicate.
404 ** data_len - indicate data length.
405 ** p_data: data to indicate.
406 ** need_confirm - if this indication expects a confirmation or not.
407 **
408 ** Returns None
409 **
410 *******************************************************************************/
BTA_GATTS_HandleValueIndication(UINT16 conn_id,UINT16 attr_id,UINT16 data_len,UINT8 * p_data,BOOLEAN need_confirm)411 void BTA_GATTS_HandleValueIndication (UINT16 conn_id, UINT16 attr_id, UINT16 data_len,
412 UINT8 *p_data, BOOLEAN need_confirm)
413 {
414 tBTA_GATTS_API_INDICATION *p_buf;
415 UINT16 len = sizeof(tBTA_GATTS_API_INDICATION);
416
417 if ((p_buf = (tBTA_GATTS_API_INDICATION *) osi_malloc(len)) != NULL) {
418 memset(p_buf, 0, len);
419
420 p_buf->hdr.event = BTA_GATTS_API_INDICATION_EVT;
421 p_buf->hdr.layer_specific = conn_id;
422 p_buf->attr_id = attr_id;
423 p_buf->need_confirm = need_confirm;
424
425 if (data_len > 0 && p_data != NULL) {
426 p_buf->len = data_len;
427 memcpy(p_buf->value, p_data, data_len);
428
429 }
430 if(need_confirm == false){
431 l2ble_update_att_acl_pkt_num(L2CA_DECREASE_BTC_NUM, NULL);
432 l2ble_update_att_acl_pkt_num(L2CA_ADD_BTU_NUM, NULL);
433 }
434 bta_sys_sendmsg(p_buf);
435 }
436 return;
437
438 }
439 /*******************************************************************************
440 **
441 ** Function BTA_GATTS_SendRsp
442 **
443 ** Description This function is called to send a response to a request.
444 **
445 ** Parameters conn_id - connection identifier.
446 ** trans_id - transaction ID.
447 ** status - response status
448 ** p_msg - response data.
449 **
450 ** Returns None
451 **
452 *******************************************************************************/
BTA_GATTS_SendRsp(UINT16 conn_id,UINT32 trans_id,tBTA_GATT_STATUS status,tBTA_GATTS_RSP * p_msg)453 void BTA_GATTS_SendRsp (UINT16 conn_id, UINT32 trans_id,
454 tBTA_GATT_STATUS status, tBTA_GATTS_RSP *p_msg)
455 {
456 tBTA_GATTS_API_RSP *p_buf;
457 UINT16 len = sizeof(tBTA_GATTS_API_RSP) + sizeof(tBTA_GATTS_RSP);
458
459 if ((p_buf = (tBTA_GATTS_API_RSP *) osi_malloc(len)) != NULL) {
460 memset(p_buf, 0, len);
461
462 p_buf->hdr.event = BTA_GATTS_API_RSP_EVT;
463 p_buf->hdr.layer_specific = conn_id;
464 p_buf->trans_id = trans_id;
465 p_buf->status = status;
466
467 if (p_msg != NULL) {
468 p_buf->p_rsp = (tBTA_GATTS_RSP *)(p_buf + 1);
469 memcpy(p_buf->p_rsp, p_msg, sizeof(tBTA_GATTS_RSP));
470 }
471
472 bta_sys_sendmsg(p_buf);
473 }
474 return;
475
476 }
477
478
BTA_SetAttributeValue(UINT16 attr_handle,UINT16 length,UINT8 * value)479 void BTA_SetAttributeValue(UINT16 attr_handle, UINT16 length, UINT8 *value)
480 {
481 tBTA_GATTS_API_SET_ATTR_VAL *p_buf;
482 UINT16 len = sizeof(tBTA_GATTS_API_SET_ATTR_VAL);
483 if((p_buf = (tBTA_GATTS_API_SET_ATTR_VAL *)osi_malloc(
484 sizeof(tBTA_GATTS_API_SET_ATTR_VAL))) != NULL){
485 memset(p_buf, 0, len);
486 p_buf->hdr.event = BTA_GATTS_API_SET_ATTR_VAL_EVT;
487 p_buf->hdr.layer_specific = attr_handle;
488 p_buf->length = length;
489 if(value != NULL){
490 if((p_buf->value = (UINT8 *)osi_malloc(length)) != NULL){
491 memcpy(p_buf->value, value, length);
492 }
493 }
494
495 bta_sys_sendmsg(p_buf);
496 }
497
498 }
499
BTA_GetAttributeValue(UINT16 attr_handle,UINT16 * length,UINT8 ** value)500 tBTA_GATT_STATUS BTA_GetAttributeValue(UINT16 attr_handle, UINT16 *length, UINT8 **value)
501 {
502 return bta_gatts_get_attr_value(attr_handle, length, value);
503 }
504
505 /*******************************************************************************
506 **
507 ** Function BTA_GATTS_Open
508 **
509 ** Description Open a direct open connection or add a background auto connection
510 ** bd address
511 **
512 ** Parameters server_if: server interface.
513 ** remote_bda: remote device BD address.
514 ** is_direct: direct connection or background auto connection
515 ** transport : Transport on which GATT connection to be opened (BR/EDR or LE)
516 **
517 ** Returns void
518 **
519 *******************************************************************************/
BTA_GATTS_Open(tBTA_GATTS_IF server_if,BD_ADDR remote_bda,BOOLEAN is_direct,tBTA_GATT_TRANSPORT transport)520 void BTA_GATTS_Open(tBTA_GATTS_IF server_if, BD_ADDR remote_bda, BOOLEAN is_direct,
521 tBTA_GATT_TRANSPORT transport)
522 {
523 tBTA_GATTS_API_OPEN *p_buf;
524
525 if ((p_buf = (tBTA_GATTS_API_OPEN *) osi_malloc(sizeof(tBTA_GATTS_API_OPEN))) != NULL) {
526 p_buf->hdr.event = BTA_GATTS_API_OPEN_EVT;
527 p_buf->server_if = server_if;
528 p_buf->is_direct = is_direct;
529 p_buf->transport = transport;
530 memcpy(p_buf->remote_bda, remote_bda, BD_ADDR_LEN);
531
532 bta_sys_sendmsg(p_buf);
533 }
534 return;
535 }
536
537
538 /*******************************************************************************
539 **
540 ** Function BTA_GATTS_CancelOpen
541 **
542 ** Description Cancel a direct open connection or remove a background auto connection
543 ** bd address
544 **
545 ** Parameters server_if: server interface.
546 ** remote_bda: remote device BD address.
547 ** is_direct: direct connection or background auto connection
548 **
549 ** Returns void
550 **
551 *******************************************************************************/
BTA_GATTS_CancelOpen(tBTA_GATTS_IF server_if,BD_ADDR remote_bda,BOOLEAN is_direct)552 void BTA_GATTS_CancelOpen(tBTA_GATTS_IF server_if, BD_ADDR remote_bda, BOOLEAN is_direct)
553 {
554 tBTA_GATTS_API_CANCEL_OPEN *p_buf;
555
556 if ((p_buf = (tBTA_GATTS_API_CANCEL_OPEN *) osi_malloc(sizeof(tBTA_GATTS_API_CANCEL_OPEN))) != NULL) {
557 p_buf->hdr.event = BTA_GATTS_API_CANCEL_OPEN_EVT;
558 p_buf->server_if = server_if;
559 p_buf->is_direct = is_direct;
560 memcpy(p_buf->remote_bda, remote_bda, BD_ADDR_LEN);
561 bta_sys_sendmsg(p_buf);
562 }
563 return;
564 }
565
566 /*******************************************************************************
567 **
568 ** Function BTA_GATTS_Close
569 **
570 ** Description Close a connection a remote device.
571 **
572 ** Parameters conn_id: connection ID to be closed.
573 **
574 ** Returns void
575 **
576 *******************************************************************************/
BTA_GATTS_Close(UINT16 conn_id)577 void BTA_GATTS_Close(UINT16 conn_id)
578 {
579 BT_HDR *p_buf;
580
581 if ((p_buf = (BT_HDR *) osi_malloc(sizeof(BT_HDR))) != NULL) {
582 p_buf->event = BTA_GATTS_API_CLOSE_EVT;
583 p_buf->layer_specific = conn_id;
584 bta_sys_sendmsg(p_buf);
585 }
586 return;
587
588 }
589
BTA_GATTS_SendServiceChangeIndication(tBTA_GATTS_IF server_if,BD_ADDR remote_bda)590 void BTA_GATTS_SendServiceChangeIndication(tBTA_GATTS_IF server_if, BD_ADDR remote_bda)
591 {
592 tBTA_GATTS_API_SEND_SERVICE_CHANGE *p_buf;
593
594 if ((p_buf = (tBTA_GATTS_API_SEND_SERVICE_CHANGE *) osi_malloc(sizeof(tBTA_GATTS_API_SEND_SERVICE_CHANGE))) != NULL) {
595 memset(p_buf, 0, sizeof(tBTA_GATTS_API_SEND_SERVICE_CHANGE));
596 p_buf->hdr.event = BTA_GATTS_API_SEND_SERVICE_CHANGE_EVT;
597 p_buf->server_if = server_if;
598 memcpy(p_buf->remote_bda, remote_bda, BD_ADDR_LEN);
599
600 bta_sys_sendmsg(p_buf);
601 }
602 return;
603
604 }
605
606 /*******************************************************************************
607 **
608 ** Function BTA_GATTS_Listen
609 **
610 ** Description Start advertisement to listen for connection request for a
611 ** GATT server
612 **
613 ** Parameters server_if: server interface.
614 ** start: to start or stop listening for connection
615 ** remote_bda: remote device BD address, if listen to all device
616 ** use NULL.
617 **
618 ** Returns void
619 **
620 *******************************************************************************/
BTA_GATTS_Listen(tBTA_GATTS_IF server_if,BOOLEAN start,BD_ADDR_PTR target_bda)621 void BTA_GATTS_Listen(tBTA_GATTS_IF server_if, BOOLEAN start, BD_ADDR_PTR target_bda)
622 {
623 tBTA_GATTS_API_LISTEN *p_buf;
624
625 if ((p_buf = (tBTA_GATTS_API_LISTEN *) osi_malloc((UINT16)(sizeof(tBTA_GATTS_API_LISTEN) + BD_ADDR_LEN))) != NULL) {
626 p_buf->hdr.event = BTA_GATTS_API_LISTEN_EVT;
627
628 p_buf->server_if = server_if;
629 p_buf->start = start;
630
631 if (target_bda) {
632 p_buf->remote_bda = (UINT8 *)(p_buf + 1);
633 memcpy(p_buf->remote_bda, target_bda, BD_ADDR_LEN);
634 } else {
635 p_buf->remote_bda = NULL;
636 }
637
638 bta_sys_sendmsg(p_buf);
639 }
640 return;
641 }
642
643 #endif /* BTA_GATT_INCLUDED */
644