1 /* 2 * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef __ESP_GATT_DEFS_H__ 8 #define __ESP_GATT_DEFS_H__ 9 10 #include "esp_bt_defs.h" 11 12 #ifdef __cplusplus 13 extern "C" { 14 #endif 15 16 /// GATT INVALID UUID 17 #define ESP_GATT_ILLEGAL_UUID 0 18 /// GATT INVALID HANDLE 19 #define ESP_GATT_ILLEGAL_HANDLE 0 20 /// GATT attribute max handle 21 #define ESP_GATT_ATTR_HANDLE_MAX UC_CONFIG_BT_GATT_MAX_SR_ATTRIBUTES 22 #define ESP_GATT_MAX_READ_MULTI_HANDLES 10 /* Max attributes to read in one request */ 23 24 25 /**@{ 26 * All "ESP_GATT_UUID_xxx" is attribute types 27 */ 28 #define ESP_GATT_UUID_IMMEDIATE_ALERT_SVC 0x1802 /* Immediate alert Service*/ 29 #define ESP_GATT_UUID_LINK_LOSS_SVC 0x1803 /* Link Loss Service*/ 30 #define ESP_GATT_UUID_TX_POWER_SVC 0x1804 /* TX Power Service*/ 31 #define ESP_GATT_UUID_CURRENT_TIME_SVC 0x1805 /* Current Time Service Service*/ 32 #define ESP_GATT_UUID_REF_TIME_UPDATE_SVC 0x1806 /* Reference Time Update Service*/ 33 #define ESP_GATT_UUID_NEXT_DST_CHANGE_SVC 0x1807 /* Next DST Change Service*/ 34 #define ESP_GATT_UUID_GLUCOSE_SVC 0x1808 /* Glucose Service*/ 35 #define ESP_GATT_UUID_HEALTH_THERMOM_SVC 0x1809 /* Health Thermometer Service*/ 36 #define ESP_GATT_UUID_DEVICE_INFO_SVC 0x180A /* Device Information Service*/ 37 #define ESP_GATT_UUID_HEART_RATE_SVC 0x180D /* Heart Rate Service*/ 38 #define ESP_GATT_UUID_PHONE_ALERT_STATUS_SVC 0x180E /* Phone Alert Status Service*/ 39 #define ESP_GATT_UUID_BATTERY_SERVICE_SVC 0x180F /* Battery Service*/ 40 #define ESP_GATT_UUID_BLOOD_PRESSURE_SVC 0x1810 /* Blood Pressure Service*/ 41 #define ESP_GATT_UUID_ALERT_NTF_SVC 0x1811 /* Alert Notification Service*/ 42 #define ESP_GATT_UUID_HID_SVC 0x1812 /* HID Service*/ 43 #define ESP_GATT_UUID_SCAN_PARAMETERS_SVC 0x1813 /* Scan Parameters Service*/ 44 #define ESP_GATT_UUID_RUNNING_SPEED_CADENCE_SVC 0x1814 /* Running Speed and Cadence Service*/ 45 #define ESP_GATT_UUID_Automation_IO_SVC 0x1815 /* Automation IO Service*/ 46 #define ESP_GATT_UUID_CYCLING_SPEED_CADENCE_SVC 0x1816 /* Cycling Speed and Cadence Service*/ 47 #define ESP_GATT_UUID_CYCLING_POWER_SVC 0x1818 /* Cycling Power Service*/ 48 #define ESP_GATT_UUID_LOCATION_AND_NAVIGATION_SVC 0x1819 /* Location and Navigation Service*/ 49 #define ESP_GATT_UUID_ENVIRONMENTAL_SENSING_SVC 0x181A /* Environmental Sensing Service*/ 50 #define ESP_GATT_UUID_BODY_COMPOSITION 0x181B /* Body Composition Service*/ 51 #define ESP_GATT_UUID_USER_DATA_SVC 0x181C /* User Data Service*/ 52 #define ESP_GATT_UUID_WEIGHT_SCALE_SVC 0x181D /* Weight Scale Service*/ 53 #define ESP_GATT_UUID_BOND_MANAGEMENT_SVC 0x181E /* Bond Management Service*/ 54 #define ESP_GATT_UUID_CONT_GLUCOSE_MONITOR_SVC 0x181F /* Continuous Glucose Monitoring Service*/ 55 56 #define ESP_GATT_UUID_PRI_SERVICE 0x2800 57 #define ESP_GATT_UUID_SEC_SERVICE 0x2801 58 #define ESP_GATT_UUID_INCLUDE_SERVICE 0x2802 59 #define ESP_GATT_UUID_CHAR_DECLARE 0x2803 /* Characteristic Declaration*/ 60 61 #define ESP_GATT_UUID_CHAR_EXT_PROP 0x2900 /* Characteristic Extended Properties */ 62 #define ESP_GATT_UUID_CHAR_DESCRIPTION 0x2901 /* Characteristic User Description*/ 63 #define ESP_GATT_UUID_CHAR_CLIENT_CONFIG 0x2902 /* Client Characteristic Configuration */ 64 #define ESP_GATT_UUID_CHAR_SRVR_CONFIG 0x2903 /* Server Characteristic Configuration */ 65 #define ESP_GATT_UUID_CHAR_PRESENT_FORMAT 0x2904 /* Characteristic Presentation Format*/ 66 #define ESP_GATT_UUID_CHAR_AGG_FORMAT 0x2905 /* Characteristic Aggregate Format*/ 67 #define ESP_GATT_UUID_CHAR_VALID_RANGE 0x2906 /* Characteristic Valid Range */ 68 #define ESP_GATT_UUID_EXT_RPT_REF_DESCR 0x2907 /* External Report Reference */ 69 #define ESP_GATT_UUID_RPT_REF_DESCR 0x2908 /* Report Reference */ 70 #define ESP_GATT_UUID_NUM_DIGITALS_DESCR 0x2909 /* Number of Digitals */ 71 #define ESP_GATT_UUID_VALUE_TRIGGER_DESCR 0x290A /* Value Trigger Setting */ 72 #define ESP_GATT_UUID_ENV_SENSING_CONFIG_DESCR 0x290B /* Environmental Sensing Configuration */ 73 #define ESP_GATT_UUID_ENV_SENSING_MEASUREMENT_DESCR 0x290C /* Environmental Sensing Measurement */ 74 #define ESP_GATT_UUID_ENV_SENSING_TRIGGER_DESCR 0x290D /* Environmental Sensing Trigger Setting */ 75 #define ESP_GATT_UUID_TIME_TRIGGER_DESCR 0x290E /* Time Trigger Setting */ 76 77 /* GAP Profile Attributes */ 78 #define ESP_GATT_UUID_GAP_DEVICE_NAME 0x2A00 79 #define ESP_GATT_UUID_GAP_ICON 0x2A01 80 #define ESP_GATT_UUID_GAP_PREF_CONN_PARAM 0x2A04 81 #define ESP_GATT_UUID_GAP_CENTRAL_ADDR_RESOL 0x2AA6 82 83 /* Attribute Profile Attribute UUID */ 84 #define ESP_GATT_UUID_GATT_SRV_CHGD 0x2A05 85 86 /* Link ESP_Loss Service */ 87 #define ESP_GATT_UUID_ALERT_LEVEL 0x2A06 /* Alert Level */ 88 #define ESP_GATT_UUID_TX_POWER_LEVEL 0x2A07 /* TX power level */ 89 90 /* Current Time Service */ 91 #define ESP_GATT_UUID_CURRENT_TIME 0x2A2B /* Current Time */ 92 #define ESP_GATT_UUID_LOCAL_TIME_INFO 0x2A0F /* Local time info */ 93 #define ESP_GATT_UUID_REF_TIME_INFO 0x2A14 /* reference time information */ 94 95 /* Network availability Profile */ 96 #define ESP_GATT_UUID_NW_STATUS 0x2A18 /* network availability status */ 97 #define ESP_GATT_UUID_NW_TRIGGER 0x2A1A /* Network availability trigger */ 98 99 /* Phone alert */ 100 #define ESP_GATT_UUID_ALERT_STATUS 0x2A3F /* alert status */ 101 #define ESP_GATT_UUID_RINGER_CP 0x2A40 /* ringer control point */ 102 #define ESP_GATT_UUID_RINGER_SETTING 0x2A41 /* ringer setting */ 103 104 /* Glucose Service */ 105 #define ESP_GATT_UUID_GM_MEASUREMENT 0x2A18 106 #define ESP_GATT_UUID_GM_CONTEXT 0x2A34 107 #define ESP_GATT_UUID_GM_CONTROL_POINT 0x2A52 108 #define ESP_GATT_UUID_GM_FEATURE 0x2A51 109 110 /* device information characteristic */ 111 #define ESP_GATT_UUID_SYSTEM_ID 0x2A23 112 #define ESP_GATT_UUID_MODEL_NUMBER_STR 0x2A24 113 #define ESP_GATT_UUID_SERIAL_NUMBER_STR 0x2A25 114 #define ESP_GATT_UUID_FW_VERSION_STR 0x2A26 115 #define ESP_GATT_UUID_HW_VERSION_STR 0x2A27 116 #define ESP_GATT_UUID_SW_VERSION_STR 0x2A28 117 #define ESP_GATT_UUID_MANU_NAME 0x2A29 118 #define ESP_GATT_UUID_IEEE_DATA 0x2A2A 119 #define ESP_GATT_UUID_PNP_ID 0x2A50 120 121 /* HID characteristics */ 122 #define ESP_GATT_UUID_HID_INFORMATION 0x2A4A 123 #define ESP_GATT_UUID_HID_REPORT_MAP 0x2A4B 124 #define ESP_GATT_UUID_HID_CONTROL_POINT 0x2A4C 125 #define ESP_GATT_UUID_HID_REPORT 0x2A4D 126 #define ESP_GATT_UUID_HID_PROTO_MODE 0x2A4E 127 #define ESP_GATT_UUID_HID_BT_KB_INPUT 0x2A22 128 #define ESP_GATT_UUID_HID_BT_KB_OUTPUT 0x2A32 129 #define ESP_GATT_UUID_HID_BT_MOUSE_INPUT 0x2A33 130 131 /// Heart Rate Measurement 132 #define ESP_GATT_HEART_RATE_MEAS 0x2A37 133 /// Body Sensor Location 134 #define ESP_GATT_BODY_SENSOR_LOCATION 0x2A38 135 /// Heart Rate Control Point 136 #define ESP_GATT_HEART_RATE_CNTL_POINT 0x2A39 137 138 /* Battery Service characteristics */ 139 #define ESP_GATT_UUID_BATTERY_LEVEL 0x2A19 140 141 /* Sensor Service */ 142 #define ESP_GATT_UUID_SC_CONTROL_POINT 0x2A55 143 #define ESP_GATT_UUID_SENSOR_LOCATION 0x2A5D 144 145 /* Runners speed and cadence service */ 146 #define ESP_GATT_UUID_RSC_MEASUREMENT 0x2A53 147 #define ESP_GATT_UUID_RSC_FEATURE 0x2A54 148 149 /* Cycling speed and cadence service */ 150 #define ESP_GATT_UUID_CSC_MEASUREMENT 0x2A5B 151 #define ESP_GATT_UUID_CSC_FEATURE 0x2A5C 152 153 /* Scan ESP_Parameter characteristics */ 154 #define ESP_GATT_UUID_SCAN_INT_WINDOW 0x2A4F 155 #define ESP_GATT_UUID_SCAN_REFRESH 0x2A31 156 /** 157 * @} 158 */ 159 160 /* relate to BTA_GATT_PREP_WRITE_xxx in bta/bta_gatt_api.h */ 161 /// Attribute write data type from the client 162 typedef enum { 163 ESP_GATT_PREP_WRITE_CANCEL = 0x00, /*!< Prepare write cancel */ /* relate to BTA_GATT_PREP_WRITE_CANCEL in bta/bta_gatt_api.h */ 164 ESP_GATT_PREP_WRITE_EXEC = 0x01, /*!< Prepare write execute */ /* relate to BTA_GATT_PREP_WRITE_EXEC in bta/bta_gatt_api.h */ 165 } esp_gatt_prep_write_type; 166 167 /* relate to BTA_GATT_xxx in bta/bta_gatt_api.h */ 168 /** 169 * @brief GATT success code and error codes 170 */ 171 typedef enum { 172 ESP_GATT_OK = 0x0, /* relate to BTA_GATT_OK in bta/bta_gatt_api.h */ 173 ESP_GATT_INVALID_HANDLE = 0x01, /* 0x0001 */ /* relate to BTA_GATT_INVALID_HANDLE in bta/bta_gatt_api.h */ 174 ESP_GATT_READ_NOT_PERMIT = 0x02, /* 0x0002 */ /* relate to BTA_GATT_READ_NOT_PERMIT in bta/bta_gatt_api.h */ 175 ESP_GATT_WRITE_NOT_PERMIT = 0x03, /* 0x0003 */ /* relate to BTA_GATT_WRITE_NOT_PERMIT in bta/bta_gatt_api.h */ 176 ESP_GATT_INVALID_PDU = 0x04, /* 0x0004 */ /* relate to BTA_GATT_INVALID_PDU in bta/bta_gatt_api.h */ 177 ESP_GATT_INSUF_AUTHENTICATION = 0x05, /* 0x0005 */ /* relate to BTA_GATT_INSUF_AUTHENTICATION in bta/bta_gatt_api.h */ 178 ESP_GATT_REQ_NOT_SUPPORTED = 0x06, /* 0x0006 */ /* relate to BTA_GATT_REQ_NOT_SUPPORTED in bta/bta_gatt_api.h */ 179 ESP_GATT_INVALID_OFFSET = 0x07, /* 0x0007 */ /* relate to BTA_GATT_INVALID_OFFSET in bta/bta_gatt_api.h */ 180 ESP_GATT_INSUF_AUTHORIZATION = 0x08, /* 0x0008 */ /* relate to BTA_GATT_INSUF_AUTHORIZATION in bta/bta_gatt_api.h */ 181 ESP_GATT_PREPARE_Q_FULL = 0x09, /* 0x0009 */ /* relate to BTA_GATT_PREPARE_Q_FULL in bta/bta_gatt_api.h */ 182 ESP_GATT_NOT_FOUND = 0x0a, /* 0x000a */ /* relate to BTA_GATT_NOT_FOUND in bta/bta_gatt_api.h */ 183 ESP_GATT_NOT_LONG = 0x0b, /* 0x000b */ /* relate to BTA_GATT_NOT_LONG in bta/bta_gatt_api.h */ 184 ESP_GATT_INSUF_KEY_SIZE = 0x0c, /* 0x000c */ /* relate to BTA_GATT_INSUF_KEY_SIZE in bta/bta_gatt_api.h */ 185 ESP_GATT_INVALID_ATTR_LEN = 0x0d, /* 0x000d */ /* relate to BTA_GATT_INVALID_ATTR_LEN in bta/bta_gatt_api.h */ 186 ESP_GATT_ERR_UNLIKELY = 0x0e, /* 0x000e */ /* relate to BTA_GATT_ERR_UNLIKELY in bta/bta_gatt_api.h */ 187 ESP_GATT_INSUF_ENCRYPTION = 0x0f, /* 0x000f */ /* relate to BTA_GATT_INSUF_ENCRYPTION in bta/bta_gatt_api.h */ 188 ESP_GATT_UNSUPPORT_GRP_TYPE = 0x10, /* 0x0010 */ /* relate to BTA_GATT_UNSUPPORT_GRP_TYPE in bta/bta_gatt_api.h */ 189 ESP_GATT_INSUF_RESOURCE = 0x11, /* 0x0011 */ /* relate to BTA_GATT_INSUF_RESOURCE in bta/bta_gatt_api.h */ 190 191 ESP_GATT_NO_RESOURCES = 0x80, /* 0x80 */ /* relate to BTA_GATT_NO_RESOURCES in bta/bta_gatt_api.h */ 192 ESP_GATT_INTERNAL_ERROR = 0x81, /* 0x81 */ /* relate to BTA_GATT_INTERNAL_ERROR in bta/bta_gatt_api.h */ 193 ESP_GATT_WRONG_STATE = 0x82, /* 0x82 */ /* relate to BTA_GATT_WRONG_STATE in bta/bta_gatt_api.h */ 194 ESP_GATT_DB_FULL = 0x83, /* 0x83 */ /* relate to BTA_GATT_DB_FULL in bta/bta_gatt_api.h */ 195 ESP_GATT_BUSY = 0x84, /* 0x84 */ /* relate to BTA_GATT_BUSY in bta/bta_gatt_api.h */ 196 ESP_GATT_ERROR = 0x85, /* 0x85 */ /* relate to BTA_GATT_ERROR in bta/bta_gatt_api.h */ 197 ESP_GATT_CMD_STARTED = 0x86, /* 0x86 */ /* relate to BTA_GATT_CMD_STARTED in bta/bta_gatt_api.h */ 198 ESP_GATT_ILLEGAL_PARAMETER = 0x87, /* 0x87 */ /* relate to BTA_GATT_ILLEGAL_PARAMETER in bta/bta_gatt_api.h */ 199 ESP_GATT_PENDING = 0x88, /* 0x88 */ /* relate to BTA_GATT_PENDING in bta/bta_gatt_api.h */ 200 ESP_GATT_AUTH_FAIL = 0x89, /* 0x89 */ /* relate to BTA_GATT_AUTH_FAIL in bta/bta_gatt_api.h */ 201 ESP_GATT_MORE = 0x8a, /* 0x8a */ /* relate to BTA_GATT_MORE in bta/bta_gatt_api.h */ 202 ESP_GATT_INVALID_CFG = 0x8b, /* 0x8b */ /* relate to BTA_GATT_INVALID_CFG in bta/bta_gatt_api.h */ 203 ESP_GATT_SERVICE_STARTED = 0x8c, /* 0x8c */ /* relate to BTA_GATT_SERVICE_STARTED in bta/bta_gatt_api.h */ 204 ESP_GATT_ENCRYPTED_MITM = ESP_GATT_OK, /* relate to BTA_GATT_ENCRYPED_MITM in bta/bta_gatt_api.h */ 205 ESP_GATT_ENCRYPTED_NO_MITM = 0x8d, /* 0x8d */ /* relate to BTA_GATT_ENCRYPED_NO_MITM in bta/bta_gatt_api.h */ 206 ESP_GATT_NOT_ENCRYPTED = 0x8e, /* 0x8e */ /* relate to BTA_GATT_NOT_ENCRYPTED in bta/bta_gatt_api.h */ 207 ESP_GATT_CONGESTED = 0x8f, /* 0x8f */ /* relate to BTA_GATT_CONGESTED in bta/bta_gatt_api.h */ 208 ESP_GATT_DUP_REG = 0x90, /* 0x90 */ /* relate to BTA_GATT_DUP_REG in bta/bta_gatt_api.h */ 209 ESP_GATT_ALREADY_OPEN = 0x91, /* 0x91 */ /* relate to BTA_GATT_ALREADY_OPEN in bta/bta_gatt_api.h */ 210 ESP_GATT_CANCEL = 0x92, /* 0x92 */ /* relate to BTA_GATT_CANCEL in bta/bta_gatt_api.h */ 211 /* 0xE0 ~ 0xFC reserved for future use */ 212 ESP_GATT_STACK_RSP = 0xe0, /* 0xe0 */ /* relate to BTA_GATT_STACK_RSP in bta/bta_gatt_api.h */ 213 ESP_GATT_APP_RSP = 0xe1, /* 0xe1 */ /* relate to BTA_GATT_APP_RSP in bta/bta_gatt_api.h */ 214 //Error caused by customer application or stack bug 215 ESP_GATT_UNKNOWN_ERROR = 0xef, /* 0xef */ /* relate to BTA_GATT_UNKNOWN_ERROR in bta/bta_gatt_api.h */ 216 ESP_GATT_CCC_CFG_ERR = 0xfd, /* 0xFD Client Characteristic Configuration Descriptor Improperly Configured */ /* relate to BTA_GATT_CCC_CFG_ERR in bta/bta_gatt_api.h */ 217 ESP_GATT_PRC_IN_PROGRESS = 0xfe, /* 0xFE Procedure Already in progress */ /* relate to BTA_GATT_PRC_IN_PROGRESS in bta/bta_gatt_api.h */ 218 ESP_GATT_OUT_OF_RANGE = 0xff, /* 0xFF Attribute value out of range */ /* relate to BTA_GATT_OUT_OF_RANGE in bta/bta_gatt_api.h */ 219 } esp_gatt_status_t; 220 221 /* relate to BTA_GATT_CONN_xxx in bta/bta_gatt_api.h */ 222 /** 223 * @brief Gatt Connection reason enum 224 */ 225 typedef enum { 226 ESP_GATT_CONN_UNKNOWN = 0, /*!< Gatt connection unknown */ /* relate to BTA_GATT_CONN_UNKNOWN in bta/bta_gatt_api.h */ 227 ESP_GATT_CONN_L2C_FAILURE = 1, /*!< General L2cap failure */ /* relate to BTA_GATT_CONN_L2C_FAILURE in bta/bta_gatt_api.h */ 228 ESP_GATT_CONN_TIMEOUT = 0x08, /*!< Connection timeout */ /* relate to BTA_GATT_CONN_TIMEOUT in bta/bta_gatt_api.h */ 229 ESP_GATT_CONN_TERMINATE_PEER_USER = 0x13, /*!< Connection terminate by peer user */ /* relate to BTA_GATT_CONN_TERMINATE_PEER_USER in bta/bta_gatt_api.h */ 230 ESP_GATT_CONN_TERMINATE_LOCAL_HOST = 0x16, /*!< Connection terminated by local host */ /* relate to BTA_GATT_CONN_TERMINATE_LOCAL_HOST in bta/bta_gatt_api.h */ 231 ESP_GATT_CONN_FAIL_ESTABLISH = 0x3e, /*!< Connection fail to establish */ /* relate to BTA_GATT_CONN_FAIL_ESTABLISH in bta/bta_gatt_api.h */ 232 ESP_GATT_CONN_LMP_TIMEOUT = 0x22, /*!< Connection fail for LMP response tout */ /* relate to BTA_GATT_CONN_LMP_TIMEOUT in bta/bta_gatt_api.h */ 233 ESP_GATT_CONN_CONN_CANCEL = 0x0100, /*!< L2CAP connection cancelled */ /* relate to BTA_GATT_CONN_CONN_CANCEL in bta/bta_gatt_api.h */ 234 ESP_GATT_CONN_NONE = 0x0101 /*!< No connection to cancel */ /* relate to BTA_GATT_CONN_NONE in bta/bta_gatt_api.h */ 235 } esp_gatt_conn_reason_t; 236 237 /** 238 * @brief Gatt id, include uuid and instance id 239 */ 240 typedef struct { 241 esp_bt_uuid_t uuid; /*!< UUID */ 242 uint8_t inst_id; /*!< Instance id */ 243 } __attribute__((packed)) esp_gatt_id_t; 244 245 /** 246 * @brief Gatt service id, include id 247 * (uuid and instance id) and primary flag 248 */ 249 typedef struct { 250 esp_gatt_id_t id; /*!< Gatt id, include uuid and instance */ 251 bool is_primary; /*!< This service is primary or not */ 252 } __attribute__((packed)) esp_gatt_srvc_id_t; 253 254 /* relate to BTA_GATT_AUTH_REQ_xxx in bta/bta_gatt_api.h */ 255 /** 256 * @brief Gatt authentication request type 257 */ 258 typedef enum { 259 ESP_GATT_AUTH_REQ_NONE = 0, /* relate to BTA_GATT_AUTH_REQ_NONE in bta/bta_gatt_api.h */ 260 ESP_GATT_AUTH_REQ_NO_MITM = 1, /* unauthenticated encryption */ /* relate to BTA_GATT_AUTH_REQ_NO_MITM in bta/bta_gatt_api.h */ 261 ESP_GATT_AUTH_REQ_MITM = 2, /* authenticated encryption */ /* relate to BTA_GATT_AUTH_REQ_MITM in bta/bta_gatt_api.h */ 262 ESP_GATT_AUTH_REQ_SIGNED_NO_MITM = 3, /* relate to BTA_GATT_AUTH_REQ_SIGNED_NO_MITM in bta/bta_gatt_api.h */ 263 ESP_GATT_AUTH_REQ_SIGNED_MITM = 4, /* relate to BTA_GATT_AUTH_REQ_SIGNED_MITM in bta/bta_gatt_api.h */ 264 } esp_gatt_auth_req_t; 265 266 /* relate to BTA_GATT_PERM_xxx in bta/bta_gatt_api.h */ 267 /** 268 * @brief Attribute permissions 269 */ 270 #define ESP_GATT_PERM_READ (1 << 0) /* bit 0 - 0x0001 */ /* relate to BTA_GATT_PERM_READ in bta/bta_gatt_api.h */ 271 #define ESP_GATT_PERM_READ_ENCRYPTED (1 << 1) /* bit 1 - 0x0002 */ /* relate to BTA_GATT_PERM_READ_ENCRYPTED in bta/bta_gatt_api.h */ 272 #define ESP_GATT_PERM_READ_ENC_MITM (1 << 2) /* bit 2 - 0x0004 */ /* relate to BTA_GATT_PERM_READ_ENC_MITM in bta/bta_gatt_api.h */ 273 #define ESP_GATT_PERM_WRITE (1 << 4) /* bit 4 - 0x0010 */ /* relate to BTA_GATT_PERM_WRITE in bta/bta_gatt_api.h */ 274 #define ESP_GATT_PERM_WRITE_ENCRYPTED (1 << 5) /* bit 5 - 0x0020 */ /* relate to BTA_GATT_PERM_WRITE_ENCRYPTED in bta/bta_gatt_api.h */ 275 #define ESP_GATT_PERM_WRITE_ENC_MITM (1 << 6) /* bit 6 - 0x0040 */ /* relate to BTA_GATT_PERM_WRITE_ENC_MITM in bta/bta_gatt_api.h */ 276 #define ESP_GATT_PERM_WRITE_SIGNED (1 << 7) /* bit 7 - 0x0080 */ /* relate to BTA_GATT_PERM_WRITE_SIGNED in bta/bta_gatt_api.h */ 277 #define ESP_GATT_PERM_WRITE_SIGNED_MITM (1 << 8) /* bit 8 - 0x0100 */ /* relate to BTA_GATT_PERM_WRITE_SIGNED_MITM in bta/bta_gatt_api.h */ 278 #define ESP_GATT_PERM_READ_AUTHORIZATION (1 << 9) /* bit 9 - 0x0200 */ 279 #define ESP_GATT_PERM_WRITE_AUTHORIZATION (1 << 10) /* bit 10 - 0x0400 */ 280 #define ESP_GATT_PERM_ENCRYPT_KEY_SIZE(keysize) (((keysize - 6) & 0xF) << 12) /* bit 12:15 - 0xF000 */ 281 typedef uint16_t esp_gatt_perm_t; 282 283 /* relate to BTA_GATT_CHAR_PROP_BIT_xxx in bta/bta_gatt_api.h */ 284 /* definition of characteristic properties */ 285 #define ESP_GATT_CHAR_PROP_BIT_BROADCAST (1 << 0) /* 0x01 */ /* relate to BTA_GATT_CHAR_PROP_BIT_BROADCAST in bta/bta_gatt_api.h */ 286 #define ESP_GATT_CHAR_PROP_BIT_READ (1 << 1) /* 0x02 */ /* relate to BTA_GATT_CHAR_PROP_BIT_READ in bta/bta_gatt_api.h */ 287 #define ESP_GATT_CHAR_PROP_BIT_WRITE_NR (1 << 2) /* 0x04 */ /* relate to BTA_GATT_CHAR_PROP_BIT_WRITE_NR in bta/bta_gatt_api.h */ 288 #define ESP_GATT_CHAR_PROP_BIT_WRITE (1 << 3) /* 0x08 */ /* relate to BTA_GATT_CHAR_PROP_BIT_WRITE in bta/bta_gatt_api.h */ 289 #define ESP_GATT_CHAR_PROP_BIT_NOTIFY (1 << 4) /* 0x10 */ /* relate to BTA_GATT_CHAR_PROP_BIT_NOTIFY in bta/bta_gatt_api.h */ 290 #define ESP_GATT_CHAR_PROP_BIT_INDICATE (1 << 5) /* 0x20 */ /* relate to BTA_GATT_CHAR_PROP_BIT_INDICATE in bta/bta_gatt_api.h */ 291 #define ESP_GATT_CHAR_PROP_BIT_AUTH (1 << 6) /* 0x40 */ /* relate to BTA_GATT_CHAR_PROP_BIT_AUTH in bta/bta_gatt_api.h */ 292 #define ESP_GATT_CHAR_PROP_BIT_EXT_PROP (1 << 7) /* 0x80 */ /* relate to BTA_GATT_CHAR_PROP_BIT_EXT_PROP in bta/bta_gatt_api.h */ 293 typedef uint8_t esp_gatt_char_prop_t; 294 295 /// GATT maximum attribute length 296 #define ESP_GATT_MAX_ATTR_LEN 600 //as same as GATT_MAX_ATTR_LEN 297 298 typedef enum { 299 ESP_GATT_SERVICE_FROM_REMOTE_DEVICE = 0, /* relate to BTA_GATTC_SERVICE_INFO_FROM_REMOTE_DEVICE in bta_gattc_int.h */ 300 ESP_GATT_SERVICE_FROM_NVS_FLASH = 1, /* relate to BTA_GATTC_SERVICE_INFO_FROM_NVS_FLASH in bta_gattc_int.h */ 301 ESP_GATT_SERVICE_FROM_UNKNOWN = 2, /* relate to BTA_GATTC_SERVICE_INFO_FROM_UNKNOWN in bta_gattc_int.h */ 302 } esp_service_source_t; 303 304 /** 305 * @brief Attribute description (used to create database) 306 */ 307 typedef struct 308 { 309 uint16_t uuid_length; /*!< UUID length */ 310 uint8_t *uuid_p; /*!< UUID value */ 311 uint16_t perm; /*!< Attribute permission */ 312 uint16_t max_length; /*!< Maximum length of the element*/ 313 uint16_t length; /*!< Current length of the element*/ 314 uint8_t *value; /*!< Element value array*/ 315 } esp_attr_desc_t; 316 317 318 /** 319 * @brief attribute auto response flag 320 */ 321 typedef struct 322 { 323 #define ESP_GATT_RSP_BY_APP 0 324 #define ESP_GATT_AUTO_RSP 1 325 /** 326 * @brief if auto_rsp set to ESP_GATT_RSP_BY_APP, means the response of Write/Read operation will by replied by application. 327 if auto_rsp set to ESP_GATT_AUTO_RSP, means the response of Write/Read operation will be replied by GATT stack automatically. 328 */ 329 uint8_t auto_rsp; 330 } esp_attr_control_t; 331 332 333 /** 334 * @brief attribute type added to the gatt server database 335 */ 336 typedef struct 337 { 338 esp_attr_control_t attr_control; /*!< The attribute control type */ 339 esp_attr_desc_t att_desc; /*!< The attribute type */ 340 } esp_gatts_attr_db_t; 341 342 343 /** 344 * @brief set the attribute value type 345 */ 346 typedef struct 347 { 348 uint16_t attr_max_len; /*!< attribute max value length */ 349 uint16_t attr_len; /*!< attribute current value length */ 350 uint8_t *attr_value; /*!< the pointer to attribute value */ 351 } esp_attr_value_t; 352 353 354 /** 355 * @brief Gatt include service entry element 356 */ 357 typedef struct 358 { 359 uint16_t start_hdl; /*!< Gatt start handle value of included service */ 360 uint16_t end_hdl; /*!< Gatt end handle value of included service */ 361 uint16_t uuid; /*!< Gatt attribute value UUID of included service */ 362 } esp_gatts_incl_svc_desc_t; /*!< Gatt include service entry element */ 363 364 /** 365 * @brief Gatt include 128 bit service entry element 366 */ 367 typedef struct 368 { 369 uint16_t start_hdl; /*!< Gatt start handle value of included 128 bit service */ 370 uint16_t end_hdl; /*!< Gatt end handle value of included 128 bit service */ 371 } esp_gatts_incl128_svc_desc_t; /*!< Gatt include 128 bit service entry element */ 372 373 /// Gatt attribute value 374 typedef struct { 375 uint8_t value[ESP_GATT_MAX_ATTR_LEN]; /*!< Gatt attribute value */ 376 uint16_t handle; /*!< Gatt attribute handle */ 377 uint16_t offset; /*!< Gatt attribute value offset */ 378 uint16_t len; /*!< Gatt attribute value length */ 379 uint8_t auth_req; /*!< Gatt authentication request */ 380 } esp_gatt_value_t; 381 382 /// GATT remote read request response type 383 typedef union { 384 esp_gatt_value_t attr_value; /*!< Gatt attribute structure */ 385 uint16_t handle; /*!< Gatt attribute handle */ 386 } esp_gatt_rsp_t; 387 388 /** 389 * @brief Gatt write type 390 */ 391 typedef enum { 392 ESP_GATT_WRITE_TYPE_NO_RSP = 1, /*!< Gatt write attribute need no response */ 393 ESP_GATT_WRITE_TYPE_RSP, /*!< Gatt write attribute need remote response */ 394 } esp_gatt_write_type_t; 395 396 /** 397 * @brief Connection parameters information 398 */ 399 typedef struct { 400 uint16_t interval; /*!< connection interval */ 401 uint16_t latency; /*!< Slave latency for the connection in number of connection events. Range: 0x0000 to 0x01F3 */ 402 uint16_t timeout; /*!< Supervision timeout for the LE Link. Range: 0x000A to 0x0C80. 403 Mandatory Range: 0x000A to 0x0C80 Time = N * 10 msec 404 Time Range: 100 msec to 32 seconds */ 405 } esp_gatt_conn_params_t; 406 407 #define ESP_GATT_IF_NONE 0xff /*!< If callback report gattc_if/gatts_if as this macro, means this event is not correspond to any app */ 408 409 typedef uint8_t esp_gatt_if_t; /*!< Gatt interface type, different application on GATT client use different gatt_if */ 410 411 /** 412 * @brief the type of attribute element 413 */ 414 typedef enum { 415 ESP_GATT_DB_PRIMARY_SERVICE, /*!< Gattc primary service attribute type in the cache */ 416 ESP_GATT_DB_SECONDARY_SERVICE, /*!< Gattc secondary service attribute type in the cache */ 417 ESP_GATT_DB_CHARACTERISTIC, /*!< Gattc characteristic attribute type in the cache */ 418 ESP_GATT_DB_DESCRIPTOR, /*!< Gattc characteristic descriptor attribute type in the cache */ 419 ESP_GATT_DB_INCLUDED_SERVICE, /*!< Gattc include service attribute type in the cache */ 420 ESP_GATT_DB_ALL, /*!< Gattc all the attribute (primary service & secondary service & include service & char & descriptor) type in the cache */ 421 } esp_gatt_db_attr_type_t; /*!< Gattc attribute type element */ 422 423 /** 424 * @brief read multiple attribute 425 */ 426 typedef struct { 427 uint8_t num_attr; /*!< The number of the attribute */ 428 uint16_t handles[ESP_GATT_MAX_READ_MULTI_HANDLES]; /*!< The handles list */ 429 } esp_gattc_multi_t; /*!< The gattc multiple read element */ 430 431 /** 432 * @brief data base attribute element 433 */ 434 typedef struct { 435 esp_gatt_db_attr_type_t type; /*!< The attribute type */ 436 uint16_t attribute_handle; /*!< The attribute handle, it's valid for all of the type */ 437 uint16_t start_handle; /*!< The service start handle, it's valid only when the type = ESP_GATT_DB_PRIMARY_SERVICE or ESP_GATT_DB_SECONDARY_SERVICE */ 438 uint16_t end_handle; /*!< The service end handle, it's valid only when the type = ESP_GATT_DB_PRIMARY_SERVICE or ESP_GATT_DB_SECONDARY_SERVICE */ 439 esp_gatt_char_prop_t properties; /*!< The characteristic properties, it's valid only when the type = ESP_GATT_DB_CHARACTERISTIC */ 440 esp_bt_uuid_t uuid; /*!< The attribute uuid, it's valid for all of the type */ 441 } esp_gattc_db_elem_t; /*!< The gattc service data base element in the cache */ 442 443 /** 444 * @brief service element 445 */ 446 typedef struct { 447 bool is_primary; /*!< The service flag, true if the service is primary service, else is secondary service */ 448 uint16_t start_handle; /*!< The start handle of the service */ 449 uint16_t end_handle; /*!< The end handle of the service */ 450 esp_bt_uuid_t uuid; /*!< The uuid of the service */ 451 } esp_gattc_service_elem_t; /*!< The gattc service element */ 452 453 /** 454 * @brief characteristic element 455 */ 456 typedef struct { 457 uint16_t char_handle; /*!< The characteristic handle */ 458 esp_gatt_char_prop_t properties; /*!< The characteristic properties */ 459 esp_bt_uuid_t uuid; /*!< The characteristic uuid */ 460 } esp_gattc_char_elem_t; /*!< The gattc characteristic element */ 461 462 /** 463 * @brief descriptor element 464 */ 465 typedef struct { 466 uint16_t handle; /*!< The characteristic descriptor handle */ 467 esp_bt_uuid_t uuid; /*!< The characteristic descriptor uuid */ 468 } esp_gattc_descr_elem_t; /*!< The gattc descriptor type element */ 469 470 /** 471 * @brief include service element 472 */ 473 typedef struct { 474 uint16_t handle; /*!< The include service current attribute handle */ 475 uint16_t incl_srvc_s_handle; /*!< The start handle of the service which has been included */ 476 uint16_t incl_srvc_e_handle; /*!< The end handle of the service which has been included */ 477 esp_bt_uuid_t uuid; /*!< The include service uuid */ 478 } esp_gattc_incl_svc_elem_t; /*!< The gattc include service element */ 479 480 481 #ifdef __cplusplus 482 } 483 #endif 484 485 #endif /* __ESP_GATT_DEFS_H__ */ 486