1 /******************************************************************************
3 * Copyright (C) 2003-2012 Broadcom Corporation
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:
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 ******************************************************************************/
19 /******************************************************************************
21 * This file contains the GATT server main functions and state machine.
23 ******************************************************************************/
25 #include "bt_target.h"
27 #if defined(BTA_GATT_INCLUDED) && (BTA_GATT_INCLUDED == TRUE)
31 #include "bta_gatts_int.h"
32 #include "bt_common.h"
34 /* type for service building action functions */
35 typedef void (*tBTA_GATTS_SRVC_ACT)(tBTA_GATTS_SRVC_CB *p_rcb, tBTA_GATTS_DATA *p_data);
37 /* service building action function list */
38 const tBTA_GATTS_SRVC_ACT bta_gatts_srvc_build_act[] =
40 bta_gatts_add_include_srvc,
42 bta_gatts_add_char_descr,
43 bta_gatts_delete_service,
44 bta_gatts_start_service,
45 bta_gatts_stop_service,
48 /* GATTS control block */
49 #if BTA_DYNAMIC_MEMORY == FALSE
50 tBTA_GATTS_CB bta_gatts_cb;
53 /*******************************************************************************
55 ** Function bta_gatts_hdl_event
57 ** Description BTA GATT server main event handling function.
62 *******************************************************************************/
63 BOOLEAN bta_gatts_hdl_event(BT_HDR *p_msg)
65 tBTA_GATTS_CB *p_cb = &bta_gatts_cb;
66 tBTA_GATTS_SRVC_CB *p_srvc_cb = NULL;
70 case BTA_GATTS_API_DISABLE_EVT:
71 bta_gatts_api_disable(p_cb);
74 case BTA_GATTS_API_REG_EVT:
75 bta_gatts_register(p_cb, (tBTA_GATTS_DATA *) p_msg);
78 case BTA_GATTS_INT_START_IF_EVT:
79 bta_gatts_start_if(p_cb, (tBTA_GATTS_DATA *) p_msg);
82 case BTA_GATTS_API_DEREG_EVT:
83 bta_gatts_deregister(p_cb, (tBTA_GATTS_DATA *) p_msg);
86 case BTA_GATTS_API_CREATE_SRVC_EVT:
87 bta_gatts_create_srvc(p_cb, (tBTA_GATTS_DATA *) p_msg);
90 case BTA_GATTS_API_INDICATION_EVT:
91 bta_gatts_indicate_handle(p_cb,(tBTA_GATTS_DATA *) p_msg);
94 case BTA_GATTS_API_OPEN_EVT:
95 bta_gatts_open(p_cb,(tBTA_GATTS_DATA *) p_msg);
98 case BTA_GATTS_API_CANCEL_OPEN_EVT:
99 bta_gatts_cancel_open(p_cb,(tBTA_GATTS_DATA *) p_msg);
102 case BTA_GATTS_API_CLOSE_EVT:
103 bta_gatts_close(p_cb,(tBTA_GATTS_DATA *) p_msg);
106 case BTA_GATTS_API_RSP_EVT:
107 bta_gatts_send_rsp(p_cb,(tBTA_GATTS_DATA *) p_msg);
110 case BTA_GATTS_API_LISTEN_EVT:
111 bta_gatts_listen(p_cb,(tBTA_GATTS_DATA *) p_msg);
115 case BTA_GATTS_API_ADD_INCL_SRVC_EVT:
116 case BTA_GATTS_API_ADD_CHAR_EVT:
117 case BTA_GATTS_API_ADD_DESCR_EVT:
118 case BTA_GATTS_API_DEL_SRVC_EVT:
119 case BTA_GATTS_API_START_SRVC_EVT:
120 case BTA_GATTS_API_STOP_SRVC_EVT:
122 p_srvc_cb = bta_gatts_find_srvc_cb_by_srvc_id(p_cb,
123 ((tBTA_GATTS_DATA *)p_msg)->api_add_incl_srvc.hdr.layer_specific);
125 if (p_srvc_cb != NULL)
127 bta_gatts_srvc_build_act[p_msg->event - BTA_GATTS_API_ADD_INCL_SRVC_EVT](p_srvc_cb, (tBTA_GATTS_DATA *) p_msg);
131 APPL_TRACE_ERROR("service not created");
143 #endif /* BTA_GATT_INCLUDED */