OSDN Git Service

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