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