• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  *  Copyright 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 is the private file for the BTA GATT server.
22  *
23  ******************************************************************************/
24 #ifndef BTA_GATTS_INT_H
25 #define BTA_GATTS_INT_H
26 
27 #include <cstdint>
28 
29 #include "bt_target.h"  // Must be first to define build configuration
30 #include "bta/include/bta_gatt_api.h"
31 #include "bta/sys/bta_sys.h"
32 #include "stack/include/bt_hdr.h"
33 #include "stack/include/bt_types.h"
34 #include "stack/include/btm_ble_api_types.h"
35 #include "stack/include/gatt_api.h"
36 #include "types/bluetooth/uuid.h"
37 #include "types/raw_address.h"
38 
39 /*****************************************************************************
40  *  Constants and data types
41  ****************************************************************************/
42 enum {
43   BTA_GATTS_API_REG_EVT = BTA_SYS_EVT_START(BTA_ID_GATTS),
44   BTA_GATTS_INT_START_IF_EVT,
45   BTA_GATTS_API_DEREG_EVT,
46   BTA_GATTS_API_INDICATION_EVT,
47 
48   BTA_GATTS_API_DEL_SRVC_EVT,
49   BTA_GATTS_API_STOP_SRVC_EVT,
50   BTA_GATTS_API_RSP_EVT,
51   BTA_GATTS_API_OPEN_EVT,
52   BTA_GATTS_API_CANCEL_OPEN_EVT,
53   BTA_GATTS_API_CLOSE_EVT,
54   BTA_GATTS_API_DISABLE_EVT,
55 
56   BTA_GATTS_API_INIT_BONDED_EVT,
57 };
58 typedef uint16_t tBTA_GATTS_INT_EVT;
59 
60 /* max number of application allowed on device */
61 #define BTA_GATTS_MAX_APP_NUM GATT_MAX_SR_PROFILES
62 
63 /* max number of services allowed in the device */
64 #define BTA_GATTS_MAX_SRVC_NUM GATT_MAX_SR_PROFILES
65 
66 /* internal strucutre for GATTC register API  */
67 typedef struct {
68   BT_HDR_RIGID hdr;
69   bluetooth::Uuid app_uuid;
70   tBTA_GATTS_CBACK* p_cback;
71   bool eatt_support;
72 } tBTA_GATTS_API_REG;
73 
74 typedef struct {
75   BT_HDR_RIGID hdr;
76   tGATT_IF server_if;
77 } tBTA_GATTS_INT_START_IF;
78 
79 typedef tBTA_GATTS_INT_START_IF tBTA_GATTS_API_DEREG;
80 
81 typedef struct {
82   BT_HDR_RIGID hdr;
83   tGATT_IF server_if;
84   btgatt_db_element_t* service;
85   uint16_t count;
86 } tBTA_GATTS_API_ADD_SERVICE;
87 
88 typedef struct {
89   BT_HDR_RIGID hdr;
90   uint16_t attr_id;
91   uint16_t len;
92   bool need_confirm;
93   uint8_t value[GATT_MAX_ATTR_LEN];
94 } tBTA_GATTS_API_INDICATION;
95 
96 typedef struct {
97   BT_HDR_RIGID hdr;
98   uint32_t trans_id;
99   tGATT_STATUS status;
100   tGATTS_RSP* p_rsp;
101 } tBTA_GATTS_API_RSP;
102 
103 typedef struct {
104   BT_HDR_RIGID hdr;
105   tBT_TRANSPORT transport;
106 } tBTA_GATTS_API_START;
107 
108 typedef struct {
109   BT_HDR_RIGID hdr;
110   RawAddress remote_bda;
111   tGATT_IF server_if;
112   tBTM_BLE_CONN_TYPE connection_type;
113   tBT_TRANSPORT transport;
114 } tBTA_GATTS_API_OPEN;
115 
116 typedef struct {
117   BT_HDR_RIGID hdr;
118   RawAddress remote_bda;
119   tGATT_IF server_if;
120   bool is_direct;
121   tBT_TRANSPORT transport;
122 } tBTA_GATTS_API_CANCEL_OPEN;
123 
124 typedef union {
125   BT_HDR_RIGID hdr;
126   tBTA_GATTS_API_REG api_reg;
127   tBTA_GATTS_API_DEREG api_dereg;
128   tBTA_GATTS_API_ADD_SERVICE api_add_service;
129   tBTA_GATTS_API_INDICATION api_indicate;
130   tBTA_GATTS_API_RSP api_rsp;
131   tBTA_GATTS_API_OPEN api_open;
132   tBTA_GATTS_API_CANCEL_OPEN api_cancel_open;
133 
134   tBTA_GATTS_INT_START_IF int_start_if;
135 } tBTA_GATTS_DATA;
136 
137 /* application registration control block */
138 typedef struct {
139   bool in_use;
140   bluetooth::Uuid app_uuid;
141   tBTA_GATTS_CBACK* p_cback;
142   tGATT_IF gatt_if;
143 } tBTA_GATTS_RCB;
144 
145 /* service registration control block */
146 typedef struct {
147   bluetooth::Uuid service_uuid; /* service UUID */
148   uint16_t service_id;   /* service start handle */
149   uint8_t rcb_idx;
150   uint8_t idx; /* self index of serviec CB */
151   bool in_use;
152 } tBTA_GATTS_SRVC_CB;
153 
154 /* GATT server control block */
155 typedef struct {
156   bool enabled;
157   tBTA_GATTS_RCB rcb[BTA_GATTS_MAX_APP_NUM];
158   tBTA_GATTS_SRVC_CB srvc_cb[BTA_GATTS_MAX_SRVC_NUM];
159 } tBTA_GATTS_CB;
160 
161 /*****************************************************************************
162  *  Global data
163  ****************************************************************************/
164 
165 /* GATTC control block */
166 extern tBTA_GATTS_CB bta_gatts_cb;
167 
168 /*****************************************************************************
169  *  Function prototypes
170  ****************************************************************************/
171 extern bool bta_gatts_hdl_event(BT_HDR_RIGID* p_msg);
172 
173 extern void bta_gatts_api_disable(tBTA_GATTS_CB* p_cb);
174 extern void bta_gatts_api_enable(tBTA_GATTS_CB* p_cb, tBTA_GATTS_DATA* p_data);
175 extern void bta_gatts_register(tBTA_GATTS_CB* p_cb, tBTA_GATTS_DATA* p_msg);
176 extern void bta_gatts_start_if(tBTA_GATTS_CB* p_cb, tBTA_GATTS_DATA* p_msg);
177 extern void bta_gatts_deregister(tBTA_GATTS_CB* p_cb, tBTA_GATTS_DATA* p_msg);
178 extern void bta_gatts_delete_service(tBTA_GATTS_SRVC_CB* p_srvc_cb,
179                                      tBTA_GATTS_DATA* p_msg);
180 extern void bta_gatts_stop_service(tBTA_GATTS_SRVC_CB* p_srvc_cb,
181                                    tBTA_GATTS_DATA* p_msg);
182 
183 extern void bta_gatts_send_rsp(tBTA_GATTS_CB* p_cb, tBTA_GATTS_DATA* p_msg);
184 extern void bta_gatts_indicate_handle(tBTA_GATTS_CB* p_cb,
185                                       tBTA_GATTS_DATA* p_msg);
186 
187 extern void bta_gatts_open(tBTA_GATTS_CB* p_cb, tBTA_GATTS_DATA* p_msg);
188 extern void bta_gatts_cancel_open(tBTA_GATTS_CB* p_cb, tBTA_GATTS_DATA* p_msg);
189 extern void bta_gatts_close(tBTA_GATTS_CB* p_cb, tBTA_GATTS_DATA* p_msg);
190 
191 extern tBTA_GATTS_RCB* bta_gatts_find_app_rcb_by_app_if(tGATT_IF server_if);
192 extern uint8_t bta_gatts_find_app_rcb_idx_by_app_if(tBTA_GATTS_CB* p_cb,
193                                                     tGATT_IF server_if);
194 extern uint8_t bta_gatts_alloc_srvc_cb(tBTA_GATTS_CB* p_cb, uint8_t rcb_idx);
195 extern tBTA_GATTS_SRVC_CB* bta_gatts_find_srvc_cb_by_srvc_id(
196     tBTA_GATTS_CB* p_cb, uint16_t service_id);
197 extern tBTA_GATTS_SRVC_CB* bta_gatts_find_srvc_cb_by_attr_id(
198     tBTA_GATTS_CB* p_cb, uint16_t attr_id);
199 
200 #endif /* BTA_GATTS_INT_H */
201