1 /****************************************************************************** 2 * 3 * Copyright (C) 1999-2013 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 ** Header file for profile folder. 22 ** 23 ********************************************************************************/ 24 25 #ifndef SRVC_DIS_API_H 26 #define SRVC_DIS_API_H 27 28 #include "common/bt_target.h" 29 #include "stack/gatt_api.h" 30 #include "stack/gattdefs.h" 31 #include "esp_gatts_api.h" 32 33 #define DIS_SUCCESS GATT_SUCCESS 34 #define DIS_ILLEGAL_PARAM GATT_ILLEGAL_PARAMETER 35 #define DIS_NO_RESOURCES GATT_NO_RESOURCES 36 typedef UINT8 tDIS_STATUS; 37 38 39 /***************************************************************************** 40 ** Data structure for DIS 41 *****************************************************************************/ 42 43 #define DIS_ATTR_SYS_ID_BIT 0x0001 44 #define DIS_ATTR_MODEL_NUM_BIT 0x0002 45 #define DIS_ATTR_SERIAL_NUM_BIT 0x0004 46 #define DIS_ATTR_FW_NUM_BIT 0x0008 47 #define DIS_ATTR_HW_NUM_BIT 0x0010 48 #define DIS_ATTR_SW_NUM_BIT 0x0020 49 #define DIS_ATTR_MANU_NAME_BIT 0x0040 50 #define DIS_ATTR_IEEE_DATA_BIT 0x0080 51 #define DIS_ATTR_PNP_ID_BIT 0x0100 52 typedef UINT16 tDIS_ATTR_MASK; 53 54 #define DIS_ATTR_ALL_MASK 0xffff 55 56 typedef tDIS_ATTR_MASK tDIS_ATTR_BIT ; 57 58 #define DIS_MAX_NUM_INC_SVR 0 59 #define DIS_MAX_CHAR_NUM 9 60 #define DIS_MAX_ATTR_NUM (DIS_MAX_CHAR_NUM * 2 + DIS_MAX_NUM_INC_SVR + 1) 61 62 #ifndef DIS_ATTR_DB_SIZE 63 #define DIS_ATTR_DB_SIZE GATT_DB_MEM_SIZE(DIS_MAX_NUM_INC_SVR, DIS_MAX_CHAR_NUM, 0) 64 #endif 65 66 #define DIS_SYSTEM_ID_SIZE 8 67 #define DIS_PNP_ID_SIZE 7 68 69 70 typedef struct { 71 UINT16 uuid; 72 UINT16 handle; 73 } tDIS_DB_ENTRY; 74 75 typedef struct { 76 UINT16 len; 77 UINT8 *p_data; 78 } tDIS_STRING; 79 80 typedef struct { 81 UINT16 vendor_id; 82 UINT16 product_id; 83 UINT16 product_version; 84 UINT8 vendor_id_src; 85 86 } tDIS_PNP_ID; 87 88 typedef union { 89 UINT64 system_id; 90 tDIS_PNP_ID pnp_id; 91 tDIS_STRING data_str; 92 } tDIS_ATTR; 93 94 #define DIS_MAX_STRING_DATA 7 95 96 typedef struct { 97 UINT16 attr_mask; 98 UINT64 system_id; 99 tDIS_PNP_ID pnp_id; 100 UINT8 *data_string[DIS_MAX_STRING_DATA]; 101 } tDIS_VALUE; 102 103 //typedef void (tDIS_READ_CBACK)(BD_ADDR addr, tDIS_VALUE *p_dis_value); 104 105 typedef struct { 106 tDIS_DB_ENTRY dis_attr[DIS_MAX_CHAR_NUM]; 107 tDIS_VALUE dis_value; 108 109 // tDIS_READ_CBACK *p_read_dis_cback; 110 111 UINT16 service_handle; 112 UINT16 max_handle; 113 114 bool enabled; 115 116 // UINT8 dis_read_uuid_idx; 117 // tDIS_ATTR_MASK request_mask; 118 } tDIS_CB; 119 120 /***************************************************************************** 121 ** Data structure used by Battery Service 122 *****************************************************************************/ 123 124 #ifndef BA_MAX_INT_NUM 125 #define BA_MAX_INT_NUM 4 126 #endif 127 128 #define BATTERY_LEVEL_SIZE 1 129 130 typedef struct { 131 BD_ADDR remote_bda; 132 BOOLEAN need_rsp; 133 UINT16 clt_cfg; 134 } tBA_WRITE_DATA; 135 136 #define BA_READ_CLT_CFG_REQ 1 137 #define BA_READ_PRE_FMT_REQ 2 138 #define BA_READ_RPT_REF_REQ 3 139 #define BA_READ_LEVEL_REQ 4 140 #define BA_WRITE_CLT_CFG_REQ 5 141 142 typedef void (tBA_CBACK)(UINT32 trans_id, UINT16 conn_id, UINT8 app_id, UINT8 event, tBA_WRITE_DATA *p_data); 143 144 #define BA_LEVEL_NOTIFY 0x01 145 #define BA_LEVEL_PRE_FMT 0x02 146 #define BA_LEVEL_RPT_REF 0x04 147 typedef UINT8 tBA_LEVEL_DESCR; 148 149 typedef struct { 150 BOOLEAN is_pri; 151 tBA_LEVEL_DESCR ba_level_descr; 152 tGATT_TRANSPORT transport; 153 tBA_CBACK *p_cback; 154 155 } tBA_REG_INFO; 156 157 typedef union { 158 UINT8 ba_level; 159 UINT16 clt_cfg; 160 tGATT_CHAR_RPT_REF rpt_ref; 161 tGATT_CHAR_PRES pres_fmt; 162 } tBA_RSP_DATA; 163 164 typedef struct { 165 UINT8 app_id; 166 UINT16 ba_level_hdl; 167 UINT16 clt_cfg_hdl; 168 UINT16 rpt_ref_hdl; 169 UINT16 pres_fmt_hdl; 170 171 tBA_CBACK *p_cback; 172 173 UINT16 pending_handle; 174 //UINT8 pending_clcb_idx; 175 UINT8 pending_evt; 176 } tBA_INST; 177 178 typedef struct { 179 tBA_INST battery_inst[BA_MAX_INT_NUM]; 180 UINT8 inst_id; 181 bool enabled; 182 } tBATTERY_CB; 183 /***************************************************************************** 184 ** External Function Declarations 185 *****************************************************************************/ 186 #ifdef __cplusplus 187 extern "C" 188 { 189 #endif 190 /***************************************************************************** 191 ** Service Engine API 192 *****************************************************************************/ 193 /******************************************************************************* 194 ** 195 ** Function srvc_eng_init 196 ** 197 ** Description Initializa the GATT Service engine, register a GATT application 198 ** as for a central service management. 199 ** 200 *******************************************************************************/ 201 //extern tGATT_STATUS srvc_eng_init (void); 202 203 204 /***************************************************************************** 205 ** DIS Server Function 206 *****************************************************************************/ 207 208 extern bool dis_valid_handle_range(UINT16 handle); 209 /******************************************************************************* 210 ** 211 ** Function DIS_Init 212 ** 213 ** Description Initializa the Device Information Service Server. 214 ** 215 *******************************************************************************/ 216 extern void DIS_Init (tBTA_GATTS_IF gatt_if, tDIS_ATTR_MASK dis_attr_mask); 217 /******************************************************************************* 218 ** 219 ** Function DIS_SrUpdate 220 ** 221 ** Description Update the DIS server attribute values 222 ** 223 *******************************************************************************/ 224 extern tDIS_STATUS DIS_SrUpdate(tDIS_ATTR_BIT dis_attr_bit, tDIS_ATTR *p_info); 225 /******************************************************************************* 226 ** 227 ** Function dis_AddChar 228 ** 229 ** Description add characteristic for dis 230 ** 231 *******************************************************************************/ 232 extern void dis_AddChar(UINT16 service_id); 233 /******************************************************************************* 234 ** dis_s_read_attr_value 235 ** 236 ** Process read DIS attribute request. 237 *******************************************************************************/ 238 239 extern void dis_s_read_attr_value (tGATTS_DATA *p_data, tGATT_VALUE *p_value, 240 UINT32 trans_id, UINT16 conn_id); 241 /***************************************************************************** 242 ** DIS Client Function 243 *****************************************************************************/ 244 /******************************************************************************* 245 ** 246 ** Function DIS_ReadDISInfo 247 ** 248 ** Description Read remote device DIS information. 249 ** 250 ** Returns void 251 ** 252 *******************************************************************************/ 253 //extern BOOLEAN DIS_ReadDISInfo(BD_ADDR peer_bda, tDIS_READ_CBACK *p_cback, 254 // tDIS_ATTR_MASK mask); 255 256 /******************************************************************************* 257 ** BATTERY SERVICE API 258 *******************************************************************************/ 259 /*************************************************************** 260 ** 261 ** Function bas_register 262 ** 263 ** Description register app for battery service 264 ** 265 ****************************************************************/ 266 extern void bas_register(void); 267 /*************************************************************** 268 ** 269 ** Function bas_init 270 ** 271 ** Description register battery service 272 ** 273 ****************************************************************/ 274 extern void bas_init(tBTA_GATTS_IF gatt_if, UINT16 app_id); 275 276 /*************************************************************** 277 ** 278 ** Function bas_AddChar 279 ** 280 ** Description add characteristic for battery service 281 ** 282 ****************************************************************/ 283 extern void bas_AddChar(UINT16 service_id, tBT_UUID *char_uuid); 284 /*************************************************************** 285 ** 286 ** Function bas_AddCharDescr 287 ** 288 ** Description add descriptor for battery service if needed 289 ** 290 ****************************************************************/ 291 extern void bas_AddCharDescr(UINT16 service_id, UINT16 attr_id); 292 /*************************************************************** 293 ** 294 ** Function bas_service_cmpl 295 ** 296 ** Description create battery service complete 297 ** 298 ****************************************************************/ 299 extern void bas_service_cmpl(UINT16 service_id, tBTA_GATT_STATUS status); 300 /******************************************************************************* 301 ** 302 ** Function Battery_Rsp 303 ** 304 ** Description Respond to a battery service request 305 ** 306 *******************************************************************************/ 307 extern void Battery_Rsp (UINT32 trans_id, UINT16 conn_id, UINT8 app_id, 308 tGATT_STATUS st, UINT8 event, tBA_RSP_DATA *p_rsp); 309 /******************************************************************************* 310 ** 311 ** Function Battery_Notify 312 ** 313 ** Description Send battery level notification 314 ** 315 *******************************************************************************/ 316 extern void Battery_Notify (UINT16 conn_id, UINT8 app_id, BD_ADDR remote_bda, UINT8 battery_level); 317 318 /***************************************************************************** 319 ** Function bas_s_read_attr_value 320 ** 321 ** Description it will be called when client send a read request 322 ******************************************************************************/ 323 extern void bas_s_read_attr_value(tGATTS_DATA *p_data, UINT32 trans_id, UINT16 conn_id); 324 /***************************************************************************** 325 ** Function bas_s_write_attr_value 326 ** 327 ** Description it will be called when client send a write request 328 ******************************************************************************/ 329 extern void bas_s_write_attr_value(tGATTS_DATA *p_data, UINT32 trans_id, 330 UINT16 conn_id, BD_ADDR bd_addr); 331 332 extern void gatts_server_test(void); 333 #ifdef __cplusplus 334 335 } 336 #endif 337 338 #endif 339