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 server 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_gatts_int.h"
32 #include "gki.h"
33
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);
36
37 /* service building action function list */
38 const tBTA_GATTS_SRVC_ACT bta_gatts_srvc_build_act[] =
39 {
40 bta_gatts_add_include_srvc,
41 bta_gatts_add_char,
42 bta_gatts_add_char_descr,
43 bta_gatts_delete_service,
44 bta_gatts_start_service,
45 bta_gatts_stop_service,
46 };
47
48 /* GATTS control block */
49 #if BTA_DYNAMIC_MEMORY == FALSE
50 tBTA_GATTS_CB bta_gatts_cb;
51 #endif
52
53 /*******************************************************************************
54 **
55 ** Function bta_gatts_hdl_event
56 **
57 ** Description BTA GATT server main event handling function.
58 **
59 **
60 ** Returns void
61 **
62 *******************************************************************************/
bta_gatts_hdl_event(BT_HDR * p_msg)63 BOOLEAN bta_gatts_hdl_event(BT_HDR *p_msg)
64 {
65 tBTA_GATTS_CB *p_cb = &bta_gatts_cb;
66 tBTA_GATTS_SRVC_CB *p_srvc_cb = NULL;
67
68 switch (p_msg->event)
69 {
70 case BTA_GATTS_API_DISABLE_EVT:
71 bta_gatts_api_disable(p_cb);
72 break;
73
74 case BTA_GATTS_API_REG_EVT:
75 bta_gatts_register(p_cb, (tBTA_GATTS_DATA *) p_msg);
76 break;
77
78 case BTA_GATTS_INT_START_IF_EVT:
79 bta_gatts_start_if(p_cb, (tBTA_GATTS_DATA *) p_msg);
80 break;
81
82 case BTA_GATTS_API_DEREG_EVT:
83 bta_gatts_deregister(p_cb, (tBTA_GATTS_DATA *) p_msg);
84 break;
85
86 case BTA_GATTS_API_CREATE_SRVC_EVT:
87 bta_gatts_create_srvc(p_cb, (tBTA_GATTS_DATA *) p_msg);
88 break;
89
90 case BTA_GATTS_API_INDICATION_EVT:
91 bta_gatts_indicate_handle(p_cb,(tBTA_GATTS_DATA *) p_msg);
92 break;
93
94 case BTA_GATTS_API_OPEN_EVT:
95 bta_gatts_open(p_cb,(tBTA_GATTS_DATA *) p_msg);
96 break;
97
98 case BTA_GATTS_API_CANCEL_OPEN_EVT:
99 bta_gatts_cancel_open(p_cb,(tBTA_GATTS_DATA *) p_msg);
100 break;
101
102 case BTA_GATTS_API_CLOSE_EVT:
103 bta_gatts_close(p_cb,(tBTA_GATTS_DATA *) p_msg);
104 break;
105
106 case BTA_GATTS_API_RSP_EVT:
107 bta_gatts_send_rsp(p_cb,(tBTA_GATTS_DATA *) p_msg);
108 break;
109
110 case BTA_GATTS_API_LISTEN_EVT:
111 bta_gatts_listen(p_cb,(tBTA_GATTS_DATA *) p_msg);
112 break;
113
114
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:
121
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);
124
125 if (p_srvc_cb != NULL)
126 {
127 bta_gatts_srvc_build_act[p_msg->event - BTA_GATTS_API_ADD_INCL_SRVC_EVT](p_srvc_cb, (tBTA_GATTS_DATA *) p_msg);
128 }
129 else
130 {
131 APPL_TRACE_ERROR("service not created");
132 }
133 break;
134
135 default:
136 break;
137 }
138
139
140 return (TRUE);
141 }
142
143 #endif /* BTA_GATT_INCLUDED */
144