1 /* 2 * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #pragma once 8 #include "esp_bt_defs.h" 9 10 #ifdef __cplusplus 11 extern "C" { 12 #endif 13 14 /** @brief GATT INVALID UUID. */ 15 #define ESP_GATT_ILLEGAL_UUID 0 16 17 /** @brief GATT INVALID HANDLE. */ 18 #define ESP_GATT_ILLEGAL_HANDLE 0 19 20 /** @brief GATT attribute max handle. */ 21 #define ESP_GATT_ATTR_HANDLE_MAX UC_CONFIG_BT_GATT_MAX_SR_ATTRIBUTES 22 23 /** @brief Maximum number of attributes to read in one request. */ 24 #define ESP_GATT_MAX_READ_MULTI_HANDLES 10 25 26 27 /** 28 * @defgroup GATT_UUIDs GATT Service UUIDs 29 * @brief Definitions of GATT Service UUIDs. 30 * 31 * This module contains the definitions of standard GATT service UUIDs. These UUIDs 32 * identify the type of GATT service. 33 * @{ 34 */ 35 36 /** @brief Immediate Alert Service UUID. */ 37 #define ESP_GATT_UUID_IMMEDIATE_ALERT_SVC 0x1802 38 /** @brief Link Loss Service UUID. */ 39 #define ESP_GATT_UUID_LINK_LOSS_SVC 0x1803 40 /** @brief TX Power Service UUID. */ 41 #define ESP_GATT_UUID_TX_POWER_SVC 0x1804 42 /** @brief Current Time Service UUID. */ 43 #define ESP_GATT_UUID_CURRENT_TIME_SVC 0x1805 44 /** @brief Reference Time Update Service UUID. */ 45 #define ESP_GATT_UUID_REF_TIME_UPDATE_SVC 0x1806 46 /** @brief Next DST Change Service UUID. */ 47 #define ESP_GATT_UUID_NEXT_DST_CHANGE_SVC 0x1807 48 /** @brief Glucose Service UUID. */ 49 #define ESP_GATT_UUID_GLUCOSE_SVC 0x1808 50 /** @brief Health Thermometer Service UUID. */ 51 #define ESP_GATT_UUID_HEALTH_THERMOM_SVC 0x1809 52 /** @brief Device Information Service UUID. */ 53 #define ESP_GATT_UUID_DEVICE_INFO_SVC 0x180A 54 /** @brief Heart Rate Service UUID. */ 55 #define ESP_GATT_UUID_HEART_RATE_SVC 0x180D 56 /** @brief Phone Alert Status Service UUID. */ 57 #define ESP_GATT_UUID_PHONE_ALERT_STATUS_SVC 0x180E 58 /** @brief Battery Service UUID. */ 59 #define ESP_GATT_UUID_BATTERY_SERVICE_SVC 0x180F 60 /** @brief Blood Pressure Service UUID. */ 61 #define ESP_GATT_UUID_BLOOD_PRESSURE_SVC 0x1810 62 /** @brief Alert Notification Service UUID. */ 63 #define ESP_GATT_UUID_ALERT_NTF_SVC 0x1811 64 /** @brief HID Service UUID. */ 65 #define ESP_GATT_UUID_HID_SVC 0x1812 66 /** @brief Scan Parameters Service UUID. */ 67 #define ESP_GATT_UUID_SCAN_PARAMETERS_SVC 0x1813 68 /** @brief Running Speed and Cadence Service UUID. */ 69 #define ESP_GATT_UUID_RUNNING_SPEED_CADENCE_SVC 0x1814 70 /** @brief Automation IO Service UUID. */ 71 #define ESP_GATT_UUID_Automation_IO_SVC 0x1815 72 /** @brief Cycling Speed and Cadence Service UUID. */ 73 #define ESP_GATT_UUID_CYCLING_SPEED_CADENCE_SVC 0x1816 74 /** @brief Cycling Power Service UUID. */ 75 #define ESP_GATT_UUID_CYCLING_POWER_SVC 0x1818 76 /** @brief Location and Navigation Service UUID. */ 77 #define ESP_GATT_UUID_LOCATION_AND_NAVIGATION_SVC 0x1819 78 /** @brief Environmental Sensing Service UUID. */ 79 #define ESP_GATT_UUID_ENVIRONMENTAL_SENSING_SVC 0x181A 80 /** @brief Body Composition Service UUID. */ 81 #define ESP_GATT_UUID_BODY_COMPOSITION 0x181B 82 /** @brief User Data Service UUID. */ 83 #define ESP_GATT_UUID_USER_DATA_SVC 0x181C 84 /** @brief Weight Scale Service UUID. */ 85 #define ESP_GATT_UUID_WEIGHT_SCALE_SVC 0x181D 86 /** @brief Bond Management Service UUID. */ 87 #define ESP_GATT_UUID_BOND_MANAGEMENT_SVC 0x181E 88 /** @brief Continuous Glucose Monitoring Service UUID. */ 89 #define ESP_GATT_UUID_CONT_GLUCOSE_MONITOR_SVC 0x181F 90 /** @brief Primary Service UUID. */ 91 #define ESP_GATT_UUID_PRI_SERVICE 0x2800 92 /** @brief Secondary Service UUID. */ 93 #define ESP_GATT_UUID_SEC_SERVICE 0x2801 94 /** @brief Include Service UUID. */ 95 #define ESP_GATT_UUID_INCLUDE_SERVICE 0x2802 96 /** @brief Characteristic Declaration UUID. */ 97 #define ESP_GATT_UUID_CHAR_DECLARE 0x2803 98 /** @brief Characteristic Extended Properties UUID. */ 99 #define ESP_GATT_UUID_CHAR_EXT_PROP 0x2900 100 /** @brief Characteristic User Description UUID. */ 101 #define ESP_GATT_UUID_CHAR_DESCRIPTION 0x2901 102 /** @brief Client Characteristic Configuration UUID. */ 103 #define ESP_GATT_UUID_CHAR_CLIENT_CONFIG 0x2902 104 /** @brief Server Characteristic Configuration UUID. */ 105 #define ESP_GATT_UUID_CHAR_SRVR_CONFIG 0x2903 106 /** @brief Characteristic Presentation Format UUID. */ 107 #define ESP_GATT_UUID_CHAR_PRESENT_FORMAT 0x2904 108 /** @brief Characteristic Aggregate Format UUID. */ 109 #define ESP_GATT_UUID_CHAR_AGG_FORMAT 0x2905 110 /** @brief Characteristic Valid Range UUID. */ 111 #define ESP_GATT_UUID_CHAR_VALID_RANGE 0x2906 112 /** @brief External Report Reference Descriptor UUID. */ 113 #define ESP_GATT_UUID_EXT_RPT_REF_DESCR 0x2907 114 /** @brief Report Reference Descriptor UUID. */ 115 #define ESP_GATT_UUID_RPT_REF_DESCR 0x2908 116 /** @brief Number of Digitals Descriptor UUID. */ 117 #define ESP_GATT_UUID_NUM_DIGITALS_DESCR 0x2909 118 /** @brief Value Trigger Setting Descriptor UUID. */ 119 #define ESP_GATT_UUID_VALUE_TRIGGER_DESCR 0x290A 120 /** @brief Environmental Sensing Configuration Descriptor UUID. */ 121 #define ESP_GATT_UUID_ENV_SENSING_CONFIG_DESCR 0x290B 122 /** @brief Environmental Sensing Measurement Descriptor UUID. */ 123 #define ESP_GATT_UUID_ENV_SENSING_MEASUREMENT_DESCR 0x290C 124 /** @brief Environmental Sensing Trigger Setting Descriptor UUID. */ 125 #define ESP_GATT_UUID_ENV_SENSING_TRIGGER_DESCR 0x290D 126 /** @brief Time Trigger Setting Descriptor UUID. */ 127 #define ESP_GATT_UUID_TIME_TRIGGER_DESCR 0x290E 128 129 /* GAP Profile Attributes */ 130 /** @brief GAP Device Name UUID. */ 131 #define ESP_GATT_UUID_GAP_DEVICE_NAME 0x2A00 132 /** @brief GAP Icon UUID. */ 133 #define ESP_GATT_UUID_GAP_ICON 0x2A01 134 /** @brief GAP Preferred Connection Parameters UUID. */ 135 #define ESP_GATT_UUID_GAP_PREF_CONN_PARAM 0x2A04 136 /** @brief GAP Central Address Resolution UUID. */ 137 #define ESP_GATT_UUID_GAP_CENTRAL_ADDR_RESOL 0x2AA6 138 139 /* Attribute Profile Attribute UUID */ 140 /** @brief GATT Service Changed UUID. */ 141 #define ESP_GATT_UUID_GATT_SRV_CHGD 0x2A05 142 143 /* Link Loss Service */ 144 /** @brief Alert Level UUID. */ 145 #define ESP_GATT_UUID_ALERT_LEVEL 0x2A06 146 /** @brief TX Power Level UUID. */ 147 #define ESP_GATT_UUID_TX_POWER_LEVEL 0x2A07 148 149 /* Current Time Service */ 150 /** @brief Current Time UUID. */ 151 #define ESP_GATT_UUID_CURRENT_TIME 0x2A2B 152 /** @brief Local Time Info UUID. */ 153 #define ESP_GATT_UUID_LOCAL_TIME_INFO 0x2A0F 154 /** @brief Reference Time Information UUID. */ 155 #define ESP_GATT_UUID_REF_TIME_INFO 0x2A14 156 157 /* Network Availability Service */ 158 /** @brief Network Availability Status UUID. */ 159 #define ESP_GATT_UUID_NW_STATUS 0x2A18 160 /** @brief Network Availability Trigger UUID. */ 161 #define ESP_GATT_UUID_NW_TRIGGER 0x2A1A 162 163 /* Phone Alert Status Service */ 164 /** @brief Alert Status UUID. */ 165 #define ESP_GATT_UUID_ALERT_STATUS 0x2A3F 166 /** @brief Ringer Control Point UUID. */ 167 #define ESP_GATT_UUID_RINGER_CP 0x2A40 168 /** @brief Ringer Setting UUID. */ 169 #define ESP_GATT_UUID_RINGER_SETTING 0x2A41 170 171 /* Glucose Service */ 172 /** @brief Glucose Measurement Characteristic UUID. */ 173 #define ESP_GATT_UUID_GM_MEASUREMENT 0x2A18 174 /** @brief Glucose Measurement Context Characteristic UUID. */ 175 #define ESP_GATT_UUID_GM_CONTEXT 0x2A34 176 /** @brief Glucose Control Point Characteristic UUID. */ 177 #define ESP_GATT_UUID_GM_CONTROL_POINT 0x2A52 178 /** @brief Glucose Feature Characteristic UUID. */ 179 #define ESP_GATT_UUID_GM_FEATURE 0x2A51 180 181 /* Device Information Service Characteristics */ 182 /** @brief System ID Characteristic UUID. */ 183 #define ESP_GATT_UUID_SYSTEM_ID 0x2A23 184 /** @brief Model Number String Characteristic UUID. */ 185 #define ESP_GATT_UUID_MODEL_NUMBER_STR 0x2A24 186 /** @brief Serial Number String Characteristic UUID. */ 187 #define ESP_GATT_UUID_SERIAL_NUMBER_STR 0x2A25 188 /** @brief Firmware Revision String Characteristic UUID. */ 189 #define ESP_GATT_UUID_FW_VERSION_STR 0x2A26 190 /** @brief Hardware Revision String Characteristic UUID. */ 191 #define ESP_GATT_UUID_HW_VERSION_STR 0x2A27 192 /** @brief Software Revision String Characteristic UUID. */ 193 #define ESP_GATT_UUID_SW_VERSION_STR 0x2A28 194 /** @brief Manufacturer Name String Characteristic UUID. */ 195 #define ESP_GATT_UUID_MANU_NAME 0x2A29 196 /** @brief IEEE 11073-20601 Regulatory Certification Data List Characteristic UUID. */ 197 #define ESP_GATT_UUID_IEEE_DATA 0x2A2A 198 /** @brief PnP ID Characteristic UUID. */ 199 #define ESP_GATT_UUID_PNP_ID 0x2A50 200 201 /* HID Service Characteristics */ 202 /** @brief HID Information Characteristic UUID. */ 203 #define ESP_GATT_UUID_HID_INFORMATION 0x2A4A 204 /** @brief HID Report Map Characteristic UUID. */ 205 #define ESP_GATT_UUID_HID_REPORT_MAP 0x2A4B 206 /** @brief HID Control Point Characteristic UUID. */ 207 #define ESP_GATT_UUID_HID_CONTROL_POINT 0x2A4C 208 /** @brief HID Report Characteristic UUID. */ 209 #define ESP_GATT_UUID_HID_REPORT 0x2A4D 210 /** @brief HID Protocol Mode Characteristic UUID. */ 211 #define ESP_GATT_UUID_HID_PROTO_MODE 0x2A4E 212 /** @brief HID Bluetooth Keyboard Input Characteristic UUID. */ 213 #define ESP_GATT_UUID_HID_BT_KB_INPUT 0x2A22 214 /** @brief HID Bluetooth Keyboard Output Characteristic UUID. */ 215 #define ESP_GATT_UUID_HID_BT_KB_OUTPUT 0x2A32 216 /** @brief HID Bluetooth Mouse Input Characteristic UUID. */ 217 #define ESP_GATT_UUID_HID_BT_MOUSE_INPUT 0x2A33 218 219 /* Heart Rate Service Characteristics */ 220 /** @brief Heart Rate Measurement Characteristic UUID. */ 221 #define ESP_GATT_HEART_RATE_MEAS 0x2A37 222 /** @brief Body Sensor Location Characteristic UUID. */ 223 #define ESP_GATT_BODY_SENSOR_LOCATION 0x2A38 224 /** @brief Heart Rate Control Point Characteristic UUID. */ 225 #define ESP_GATT_HEART_RATE_CNTL_POINT 0x2A39 226 227 /* Battery Service Characteristics */ 228 /** @brief Battery Level Characteristic UUID. */ 229 #define ESP_GATT_UUID_BATTERY_LEVEL 0x2A19 230 231 /* Sensor Service Characteristics */ 232 /** @brief Sensor Control Point Characteristic UUID. */ 233 #define ESP_GATT_UUID_SC_CONTROL_POINT 0x2A55 234 /** @brief Sensor Location Characteristic UUID. */ 235 #define ESP_GATT_UUID_SENSOR_LOCATION 0x2A5D 236 237 /* Running Speed and Cadence Service Characteristics */ 238 /** @brief RSC Measurement Characteristic UUID. */ 239 #define ESP_GATT_UUID_RSC_MEASUREMENT 0x2A53 240 /** @brief RSC Feature Characteristic UUID. */ 241 #define ESP_GATT_UUID_RSC_FEATURE 0x2A54 242 243 /* Cycling Speed and Cadence Service Characteristics */ 244 /** @brief CSC Measurement Characteristic UUID. */ 245 #define ESP_GATT_UUID_CSC_MEASUREMENT 0x2A5B 246 /** @brief CSC Feature Characteristic UUID. */ 247 #define ESP_GATT_UUID_CSC_FEATURE 0x2A5C 248 249 /* Scan Parameters Service Characteristics */ 250 /** @brief Scan Interval Window Characteristic UUID. */ 251 #define ESP_GATT_UUID_SCAN_INT_WINDOW 0x2A4F 252 /** @brief Scan Refresh UUID. */ 253 #define ESP_GATT_UUID_SCAN_REFRESH 0x2A31 254 /* Additional GATT Services not covered yet */ 255 /** @} */ // End of group GATT_UUIDs 256 257 258 /** 259 * @brief Defines the attribute write operation types from the client. 260 * 261 * These values are used to specify the type of write operation in a prepare write sequence. 262 * relate to BTA_GATT_PREP_WRITE_xxx in bta/bta_gatt_api.h. 263 */ 264 typedef enum { 265 ESP_GATT_PREP_WRITE_CANCEL = 0x00, /*!< Prepare write cancel. Corresponds to BTA_GATT_PREP_WRITE_CANCEL. */ 266 ESP_GATT_PREP_WRITE_EXEC = 0x01, /*!< Prepare write execute. Corresponds to BTA_GATT_PREP_WRITE_EXEC. */ 267 } esp_gatt_prep_write_type; 268 269 270 /** 271 * @brief GATT operation status codes. 272 * 273 * These status codes are used to indicate the result of various GATT operations. 274 * relate to BTA_GATT_xxx in bta/bta_gatt_api.h . 275 */ 276 typedef enum { 277 ESP_GATT_OK = 0x0, /*!< 0x0, Operation successful. Corresponds to BTA_GATT_OK. */ 278 ESP_GATT_INVALID_HANDLE = 0x01, /*!< 0x01, Invalid handle. Corresponds to BTA_GATT_INVALID_HANDLE. */ 279 ESP_GATT_READ_NOT_PERMIT = 0x02, /*!< 0x02, Read operation not permitted. Corresponds to BTA_GATT_READ_NOT_PERMIT. */ 280 ESP_GATT_WRITE_NOT_PERMIT = 0x03, /*!< 0x03, Write operation not permitted. Corresponds to BTA_GATT_WRITE_NOT_PERMIT. */ 281 ESP_GATT_INVALID_PDU = 0x04, /*!< 0x04, Invalid PDU. Corresponds to BTA_GATT_INVALID_PDU. */ 282 ESP_GATT_INSUF_AUTHENTICATION = 0x05, /*!< 0x05, Insufficient authentication. Corresponds to BTA_GATT_INSUF_AUTHENTICATION. */ 283 ESP_GATT_REQ_NOT_SUPPORTED = 0x06, /*!< 0x06, Request not supported. Corresponds to BTA_GATT_REQ_NOT_SUPPORTED. */ 284 ESP_GATT_INVALID_OFFSET = 0x07, /*!< 0x07, Invalid offset. Corresponds to BTA_GATT_INVALID_OFFSET. */ 285 ESP_GATT_INSUF_AUTHORIZATION = 0x08, /*!< 0x08, Insufficient authorization. Corresponds to BTA_GATT_INSUF_AUTHORIZATION. */ 286 ESP_GATT_PREPARE_Q_FULL = 0x09, /*!< 0x09, Prepare queue full. Corresponds to BTA_GATT_PREPARE_Q_FULL. */ 287 ESP_GATT_NOT_FOUND = 0x0a, /*!< 0x0a, Not found. Corresponds to BTA_GATT_NOT_FOUND. */ 288 ESP_GATT_NOT_LONG = 0x0b, /*!< 0x0b, Not long. Corresponds to BTA_GATT_NOT_LONG. */ 289 ESP_GATT_INSUF_KEY_SIZE = 0x0c, /*!< 0x0c, Insufficient key size. Corresponds to BTA_GATT_INSUF_KEY_SIZE. */ 290 ESP_GATT_INVALID_ATTR_LEN = 0x0d, /*!< 0x0d, Invalid attribute length. Corresponds to BTA_GATT_INVALID_ATTR_LEN. */ 291 ESP_GATT_ERR_UNLIKELY = 0x0e, /*!< 0x0e, Unlikely error. Corresponds to BTA_GATT_ERR_UNLIKELY. */ 292 ESP_GATT_INSUF_ENCRYPTION = 0x0f, /*!< 0x0f, Insufficient encryption. Corresponds to BTA_GATT_INSUF_ENCRYPTION. */ 293 ESP_GATT_UNSUPPORT_GRP_TYPE = 0x10, /*!< 0x10, Unsupported group type. Corresponds to BTA_GATT_UNSUPPORT_GRP_TYPE. */ 294 ESP_GATT_INSUF_RESOURCE = 0x11, /*!< 0x11, Insufficient resource. Corresponds to BTA_GATT_INSUF_RESOURCE. */ 295 296 /* Additional error codes specific to implementation or future use */ 297 ESP_GATT_NO_RESOURCES = 0x80, /*!< 0x80, No resources. Corresponds to BTA_GATT_NO_RESOURCES. */ 298 ESP_GATT_INTERNAL_ERROR = 0x81, /*!< 0x81, Internal error. Corresponds to BTA_GATT_INTERNAL_ERROR. */ 299 ESP_GATT_WRONG_STATE = 0x82, /*!< 0x82, Wrong state. Corresponds to BTA_GATT_WRONG_STATE. */ 300 ESP_GATT_DB_FULL = 0x83, /*!< 0x83, Database full. Corresponds to BTA_GATT_DB_FULL. */ 301 ESP_GATT_BUSY = 0x84, /*!< 0x84, Busy. Corresponds to BTA_GATT_BUSY. */ 302 ESP_GATT_ERROR = 0x85, /*!< 0x85, Generic error. Corresponds to BTA_GATT_ERROR. */ 303 ESP_GATT_CMD_STARTED = 0x86, /*!< 0x86, Command started. Corresponds to BTA_GATT_CMD_STARTED. */ 304 ESP_GATT_ILLEGAL_PARAMETER = 0x87, /*!< 0x87, Illegal parameter. Corresponds to BTA_GATT_ILLEGAL_PARAMETER. */ 305 ESP_GATT_PENDING = 0x88, /*!< 0x88, Operation pending. Corresponds to BTA_GATT_PENDING. */ 306 ESP_GATT_AUTH_FAIL = 0x89, /*!< 0x89, Authentication failed. Corresponds to BTA_GATT_AUTH_FAIL. */ 307 ESP_GATT_MORE = 0x8a, /*!< 0x8a, More data available. Corresponds to BTA_GATT_MORE. */ 308 ESP_GATT_INVALID_CFG = 0x8b, /*!< 0x8b, Invalid configuration. Corresponds to BTA_GATT_INVALID_CFG. */ 309 ESP_GATT_SERVICE_STARTED = 0x8c, /*!< 0x8c, Service started. Corresponds to BTA_GATT_SERVICE_STARTED. */ 310 ESP_GATT_ENCRYPTED_MITM = ESP_GATT_OK, /*!< 0x0, Encrypted, with MITM protection. Corresponds to BTA_GATT_ENCRYPTED_MITM. */ 311 ESP_GATT_ENCRYPTED_NO_MITM = 0x8d, /*!< 0x8d, Encrypted, without MITM protection. Corresponds to BTA_GATT_ENCRYPTED_NO_MITM. */ 312 ESP_GATT_NOT_ENCRYPTED = 0x8e, /*!< 0x8e, Not encrypted. Corresponds to BTA_GATT_NOT_ENCRYPTED. */ 313 ESP_GATT_CONGESTED = 0x8f, /*!< 0x8f, Congested. Corresponds to BTA_GATT_CONGESTED. */ 314 ESP_GATT_DUP_REG = 0x90, /*!< 0x90, Duplicate registration. Corresponds to BTA_GATT_DUP_REG. */ 315 ESP_GATT_ALREADY_OPEN = 0x91, /*!< 0x91, Already open. Corresponds to BTA_GATT_ALREADY_OPEN. */ 316 ESP_GATT_CANCEL = 0x92, /*!< 0x92, Operation cancelled. Corresponds to BTA_GATT_CANCEL. */ 317 /* 0xE0 ~ 0xFC reserved for future use */ 318 ESP_GATT_STACK_RSP = 0xe0, /*!< 0xe0, Stack response. Corresponds to BTA_GATT_STACK_RSP. */ 319 ESP_GATT_APP_RSP = 0xe1, /*!< 0xe1, Application response. Corresponds to BTA_GATT_APP_RSP. */ 320 /* Error caused by customer application or stack bug */ 321 ESP_GATT_UNKNOWN_ERROR = 0xef, /*!< 0xef, Unknown error. Corresponds to BTA_GATT_UNKNOWN_ERROR. */ 322 ESP_GATT_CCC_CFG_ERR = 0xfd, /*!< 0xfd, Client Characteristic Configuration Descriptor improperly configured. Corresponds to BTA_GATT_CCC_CFG_ERR. */ 323 ESP_GATT_PRC_IN_PROGRESS = 0xfe, /*!< 0xfe, Procedure already in progress. Corresponds to BTA_GATT_PRC_IN_PROGRESS. */ 324 ESP_GATT_OUT_OF_RANGE = 0xff /*!< 0xff, Attribute value out of range. Corresponds to BTA_GATT_OUT_OF_RANGE. */ 325 } esp_gatt_status_t; 326 327 328 /** 329 * @brief Enumerates reasons for GATT connection. 330 */ 331 typedef enum { 332 ESP_GATT_CONN_UNKNOWN = 0, /*!< Unknown connection reason. Corresponds to BTA_GATT_CONN_UNKNOWN in bta/bta_gatt_api.h */ 333 ESP_GATT_CONN_L2C_FAILURE = 1, /*!< General L2CAP failure. Corresponds to BTA_GATT_CONN_L2C_FAILURE in bta/bta_gatt_api.h */ 334 ESP_GATT_CONN_TIMEOUT = 0x08, /*!< Connection timeout. Corresponds to BTA_GATT_CONN_TIMEOUT in bta/bta_gatt_api.h */ 335 ESP_GATT_CONN_TERMINATE_PEER_USER = 0x13, /*!< Connection terminated by peer user. Corresponds to BTA_GATT_CONN_TERMINATE_PEER_USER in bta/bta_gatt_api.h */ 336 ESP_GATT_CONN_TERMINATE_LOCAL_HOST = 0x16, /*!< Connection terminated by local host. Corresponds to BTA_GATT_CONN_TERMINATE_LOCAL_HOST in bta/bta_gatt_api.h */ 337 ESP_GATT_CONN_FAIL_ESTABLISH = 0x3e, /*!< Failure to establish connection. Corresponds to BTA_GATT_CONN_FAIL_ESTABLISH in bta/bta_gatt_api.h */ 338 ESP_GATT_CONN_LMP_TIMEOUT = 0x22, /*!< Connection failed due to LMP response timeout. Corresponds to BTA_GATT_CONN_LMP_TIMEOUT in bta/bta_gatt_api.h */ 339 ESP_GATT_CONN_CONN_CANCEL = 0x0100, /*!< L2CAP connection cancelled. Corresponds to BTA_GATT_CONN_CONN_CANCEL in bta/bta_gatt_api.h */ 340 ESP_GATT_CONN_NONE = 0x0101 /*!< No connection to cancel. Corresponds to BTA_GATT_CONN_NONE in bta/bta_gatt_api.h */ 341 } esp_gatt_conn_reason_t; 342 343 344 /** 345 * @brief Represents a GATT identifier. 346 */ 347 typedef struct { 348 esp_bt_uuid_t uuid; /*!< @brief The UUID component of the GATT ID. */ 349 uint8_t inst_id; /*!< @brief The instance ID component of the GATT ID, providing further differentiation of the GATT ID. */ 350 } __attribute__((packed)) esp_gatt_id_t; 351 352 353 /** 354 * @brief Represents a GATT service identifier. 355 */ 356 typedef struct { 357 esp_gatt_id_t id; /*!< @brief Encapsulates the UUID and instance ID of the GATT service. */ 358 bool is_primary; /*!< @brief Indicates if the service is primary. A value of true means it is a primary service, false indicates a secondary service. */ 359 } __attribute__((packed)) esp_gatt_srvc_id_t; 360 361 /** 362 * @brief Defines the GATT authentication request types. 363 * 364 * This enumeration lists the types of authentication requests that can be made. 365 * It corresponds to the `BTA_GATT_AUTH_REQ_xxx` values defined in `bta/bta_gatt_api.h`. 366 * The types include options for no authentication, unauthenticated encryption, authenticated encryption, 367 * and both signed versions with and without MITM (Man-In-The-Middle) protection. 368 */ 369 typedef enum { 370 ESP_GATT_AUTH_REQ_NONE = 0, /*!< No authentication required. Corresponds to BTA_GATT_AUTH_REQ_NONE. */ 371 ESP_GATT_AUTH_REQ_NO_MITM = 1, /*!< Unauthenticated encryption. Corresponds to BTA_GATT_AUTH_REQ_NO_MITM. */ 372 ESP_GATT_AUTH_REQ_MITM = 2, /*!< Authenticated encryption (MITM protection). Corresponds to BTA_GATT_AUTH_REQ_MITM. */ 373 ESP_GATT_AUTH_REQ_SIGNED_NO_MITM = 3, /*!< Signed data, no MITM protection. Corresponds to BTA_GATT_AUTH_REQ_SIGNED_NO_MITM. */ 374 ESP_GATT_AUTH_REQ_SIGNED_MITM = 4, /*!< Signed data with MITM protection. Corresponds to BTA_GATT_AUTH_REQ_SIGNED_MITM. */ 375 } esp_gatt_auth_req_t; 376 377 378 /** 379 * @brief Defines GATT attribute permission flags. 380 * 381 * These permission flags are used to specify the security requirements for GATT attributes. 382 * They correlate directly with the BTA_GATT_PERM_xxx definitions found in bta/bta_gatt_api.h. 383 */ 384 385 /** @defgroup GATT_PERMS GATT Attribute Permissions 386 * @brief Definitions of permission flags for GATT attributes. 387 * @{ 388 */ 389 390 /** @brief Permission to read the attribute. Corresponds to BTA_GATT_PERM_READ. */ 391 #define ESP_GATT_PERM_READ (1 << 0) 392 393 /** @brief Permission to read the attribute with encryption. Corresponds to BTA_GATT_PERM_READ_ENCRYPTED. */ 394 #define ESP_GATT_PERM_READ_ENCRYPTED (1 << 1) 395 396 /** @brief Permission to read the attribute with encrypted MITM (Man In The Middle) protection. Corresponds to BTA_GATT_PERM_READ_ENC_MITM.*/ 397 #define ESP_GATT_PERM_READ_ENC_MITM (1 << 2) 398 399 /** @brief Permission to write to the attribute. Corresponds to BTA_GATT_PERM_WRITE. */ 400 #define ESP_GATT_PERM_WRITE (1 << 4) 401 402 /** @brief Permission to write to the attribute with encryption. Corresponds to BTA_GATT_PERM_WRITE_ENCRYPTED. */ 403 #define ESP_GATT_PERM_WRITE_ENCRYPTED (1 << 5) 404 405 /** @brief Permission to write to the attribute with encrypted MITM protection. Corresponds to BTA_GATT_PERM_WRITE_ENC_MITM. */ 406 #define ESP_GATT_PERM_WRITE_ENC_MITM (1 << 6) 407 408 /** @brief Permission for signed writes to the attribute. Corresponds to BTA_GATT_PERM_WRITE_SIGNED. */ 409 #define ESP_GATT_PERM_WRITE_SIGNED (1 << 7) 410 411 /** @brief Permission for signed writes to the attribute with MITM protection. Corresponds to BTA_GATT_PERM_WRITE_SIGNED_MITM. */ 412 #define ESP_GATT_PERM_WRITE_SIGNED_MITM (1 << 8) 413 414 /** @brief Permission to read the attribute with authorization. */ 415 #define ESP_GATT_PERM_READ_AUTHORIZATION (1 << 9) 416 417 /** @brief Permission to write to the attribute with authorization. */ 418 #define ESP_GATT_PERM_WRITE_AUTHORIZATION (1 << 10) 419 420 /** 421 * @brief Macro to specify minimum encryption key size. 422 * 423 * @param keysize The minimum size of the encryption key, in bytes. 424 */ 425 #define ESP_GATT_PERM_ENCRYPT_KEY_SIZE(keysize) (((keysize - 6) & 0xF) << 12) 426 427 /** @} */ // End of GATT_PERMS group 428 429 typedef uint16_t esp_gatt_perm_t; ///< Type to represent GATT attribute permissions. 430 431 432 433 /** 434 * @brief Defines GATT characteristic properties. 435 * 436 * These properties are related to `BTA_GATT_CHAR_PROP_BIT_xxx` in `bta/bta_gatt_api.h`. 437 */ 438 439 /** @defgroup GATT_CHAR_PROPERTIES GATT Characteristic Properties 440 * These properties define various capabilities of a GATT characteristic. 441 * @{ 442 */ 443 /** @brief Ability to broadcast.Corresponds to BTA_GATT_CHAR_PROP_BIT_BROADCAST. */ 444 #define ESP_GATT_CHAR_PROP_BIT_BROADCAST (1 << 0) 445 446 /** @brief Ability to read.Corresponds to BTA_GATT_CHAR_PROP_BIT_READ. */ 447 #define ESP_GATT_CHAR_PROP_BIT_READ (1 << 1) 448 449 /** @brief Ability to write without response.Corresponds to BTA_GATT_CHAR_PROP_BIT_WRITE_NR. */ 450 #define ESP_GATT_CHAR_PROP_BIT_WRITE_NR (1 << 2) 451 452 /** @brief Ability to write.Corresponds to BTA_GATT_CHAR_PROP_BIT_WRITE. */ 453 #define ESP_GATT_CHAR_PROP_BIT_WRITE (1 << 3) 454 455 /** @brief Ability to notify.Corresponds to BTA_GATT_CHAR_PROP_BIT_NOTIFY. */ 456 #define ESP_GATT_CHAR_PROP_BIT_NOTIFY (1 << 4) 457 458 /** @brief Ability to indicate.Corresponds to BTA_GATT_CHAR_PROP_BIT_INDICATE. */ 459 #define ESP_GATT_CHAR_PROP_BIT_INDICATE (1 << 5) 460 461 /** @brief Ability to authenticate.Corresponds to BTA_GATT_CHAR_PROP_BIT_AUTH. */ 462 #define ESP_GATT_CHAR_PROP_BIT_AUTH (1 << 6) 463 464 /** @brief Has extended properties.Corresponds to BTA_GATT_CHAR_PROP_BIT_EXT_PROP. */ 465 #define ESP_GATT_CHAR_PROP_BIT_EXT_PROP (1 << 7) 466 467 /** @} */ // end of GATT_CHAR_PROPERTIES 468 469 /** 470 * @typedef esp_gatt_char_prop_t 471 * @brief Type for characteristic properties bitmask. 472 */ 473 typedef uint8_t esp_gatt_char_prop_t; 474 475 476 /** 477 * @brief Defines the maximum length of a GATT attribute. 478 * 479 * This definition specifies the maximum number of bytes that a GATT attribute can hold. 480 */ 481 #define ESP_GATT_MAX_ATTR_LEN 512 /*!< As same as GATT_MAX_ATTR_LEN. */ 482 483 /** 484 * @brief Enumerates the possible sources of a GATT service discovery. 485 * 486 * This enumeration identifies the source of a GATT service discovery process, 487 * indicating whether the service information was obtained from a remote device, 488 * from NVS (Non-Volatile Storage) flash, or the source is unknown. 489 */ 490 typedef enum { 491 ESP_GATT_SERVICE_FROM_REMOTE_DEVICE = 0, /*!< Service information from a remote device. Relates to BTA_GATTC_SERVICE_INFO_FROM_REMOTE_DEVICE. */ 492 ESP_GATT_SERVICE_FROM_NVS_FLASH = 1, /*!< Service information from NVS flash. Relates to BTA_GATTC_SERVICE_INFO_FROM_NVS_FLASH. */ 493 ESP_GATT_SERVICE_FROM_UNKNOWN = 2, /*!< Service source is unknown. Relates to BTA_GATTC_SERVICE_INFO_FROM_UNKNOWN. */ 494 } esp_service_source_t; 495 496 497 /** 498 * @brief Defines an attribute's description. 499 * 500 * This structure is used to describe an attribute in the GATT database. It includes 501 * details such as the UUID of the attribute, its permissions, and its value. 502 */ 503 typedef struct 504 { 505 uint16_t uuid_length; /*!< Length of the UUID in bytes. */ 506 uint8_t *uuid_p; /*!< Pointer to the UUID value. */ 507 uint16_t perm; /*!< Attribute permissions, defined by esp_gatt_perm_t. */ 508 uint16_t max_length; /*!< Maximum length of the attribute's value. */ 509 uint16_t length; /*!< Current length of the attribute's value. */ 510 uint8_t *value; /*!< Pointer to the attribute's value array. */ 511 } esp_attr_desc_t; 512 513 514 /** 515 * @brief Defines attribute control for GATT operations. 516 * 517 * This module provides definitions for controlling attribute auto responses 518 * in GATT operations. 519 */ 520 521 /** @brief Response to Write/Read operations should be handled by the application. */ 522 #define ESP_GATT_RSP_BY_APP 0 523 524 /** @brief Response to Write/Read operations should be automatically handled by the GATT stack. */ 525 #define ESP_GATT_AUTO_RSP 1 526 527 /** 528 * @brief Defines the auto response setting for attribute operations. 529 * 530 * This structure is used to control whether the GATT stack or the application 531 * will handle responses to Read/Write operations. 532 */ 533 typedef struct 534 { 535 /** 536 * @brief Controls who handles the response to Read/Write operations. 537 * 538 * - If set to @c ESP_GATT_RSP_BY_APP, the application is responsible for 539 * generating the response. 540 * - If set to @c ESP_GATT_AUTO_RSP, the GATT stack will automatically generate 541 * the response. 542 */ 543 uint8_t auto_rsp; 544 } esp_attr_control_t; 545 546 547 548 /** 549 * @brief attribute type added to the GATT server database 550 */ 551 typedef struct 552 { 553 esp_attr_control_t attr_control; /*!< The attribute control type */ 554 esp_attr_desc_t att_desc; /*!< The attribute type */ 555 } esp_gatts_attr_db_t; 556 557 558 /** 559 * @brief set the attribute value type 560 */ 561 typedef struct 562 { 563 uint16_t attr_max_len; /*!< attribute max value length */ 564 uint16_t attr_len; /*!< attribute current value length */ 565 uint8_t *attr_value; /*!< the pointer to attribute value */ 566 } esp_attr_value_t; 567 568 569 /** 570 * @brief Gatt include service entry element 571 */ 572 typedef struct 573 { 574 uint16_t start_hdl; /*!< Gatt start handle value of included service */ 575 uint16_t end_hdl; /*!< Gatt end handle value of included service */ 576 uint16_t uuid; /*!< Gatt attribute value UUID of included service */ 577 } esp_gatts_incl_svc_desc_t; /*!< Gatt include service entry element */ 578 579 /** 580 * @brief Gatt include 128 bit service entry element 581 */ 582 typedef struct 583 { 584 uint16_t start_hdl; /*!< Gatt start handle value of included 128 bit service */ 585 uint16_t end_hdl; /*!< Gatt end handle value of included 128 bit service */ 586 } esp_gatts_incl128_svc_desc_t; /*!< Gatt include 128 bit service entry element */ 587 588 /** 589 * @brief Represents a GATT attribute's value. 590 */ 591 typedef struct { 592 uint8_t value[ESP_GATT_MAX_ATTR_LEN]; /*!< Array holding the value of the GATT attribute. */ 593 uint16_t handle; /*!< Unique identifier (handle) of the GATT attribute. */ 594 uint16_t offset; /*!< Offset within the attribute's value, for partial updates. */ 595 uint16_t len; /*!< Current length of the data in the value array. */ 596 uint8_t auth_req; /*!< Authentication requirements for accessing this attribute. */ 597 } esp_gatt_value_t; 598 599 /** 600 * @brief Represents the response type for a GATT remote read request. 601 */ 602 typedef union { 603 esp_gatt_value_t attr_value; /*!< The GATT attribute value, including its data, handle, and metadata. */ 604 uint16_t handle; /*!< Only the handle of the GATT attribute, when that's the only required information. */ 605 } esp_gatt_rsp_t; 606 607 608 /** 609 * @brief Defines the types of GATT write operations. 610 */ 611 typedef enum { 612 ESP_GATT_WRITE_TYPE_NO_RSP = 1, /*!< Write operation where no response is needed. */ 613 ESP_GATT_WRITE_TYPE_RSP = 2, /*!< Write operation that requires a remote response. */ 614 } esp_gatt_write_type_t; 615 616 617 /** @brief Connection parameters for GATT. */ 618 typedef struct { 619 uint16_t interval; /*!< Connection interval. */ 620 uint16_t latency; /*!< Slave latency for the connection in number of connection events. */ 621 uint16_t timeout; /*!< Supervision timeout for the LE Link. */ 622 } esp_gatt_conn_params_t; 623 624 /** @brief Macro indicating no specific GATT interface. */ 625 #define ESP_GATT_IF_NONE 0xff /*!< No specific application GATT interface. */ 626 627 /** @brief GATT interface type for client applications. */ 628 typedef uint8_t esp_gatt_if_t; 629 630 /** @brief Enumerates types of GATT database attributes. */ 631 typedef enum { 632 ESP_GATT_DB_PRIMARY_SERVICE, /*!< Primary service attribute. */ 633 ESP_GATT_DB_SECONDARY_SERVICE, /*!< Secondary service attribute. */ 634 ESP_GATT_DB_CHARACTERISTIC, /*!< Characteristic attribute. */ 635 ESP_GATT_DB_DESCRIPTOR, /*!< Descriptor attribute. */ 636 ESP_GATT_DB_INCLUDED_SERVICE, /*!< Included service attribute. */ 637 ESP_GATT_DB_ALL, /*!< All attribute types. */ 638 } esp_gatt_db_attr_type_t; 639 640 /** @brief Represents multiple attributes for reading. */ 641 typedef struct { 642 uint8_t num_attr; /*!< Number of attributes. */ 643 uint16_t handles[ESP_GATT_MAX_READ_MULTI_HANDLES]; /*!< List of attribute handles. */ 644 } esp_gattc_multi_t; 645 646 /** @brief GATT database attribute element. */ 647 typedef struct { 648 esp_gatt_db_attr_type_t type; /*!< Attribute type. */ 649 uint16_t attribute_handle; /*!< Attribute handle. */ 650 uint16_t start_handle; /*!< Service start handle. */ 651 uint16_t end_handle; /*!< Service end handle. */ 652 esp_gatt_char_prop_t properties; /*!< Characteristic properties. */ 653 esp_bt_uuid_t uuid; /*!< Attribute UUID. */ 654 } esp_gattc_db_elem_t; 655 656 /** @brief Represents a GATT service element. */ 657 typedef struct { 658 bool is_primary; /*!< Indicates if the service is primary. */ 659 uint16_t start_handle; /*!< Service start handle. */ 660 uint16_t end_handle; /*!< Service end handle. */ 661 esp_bt_uuid_t uuid; /*!< Service UUID. */ 662 } esp_gattc_service_elem_t; 663 664 /** @brief Represents a GATT characteristic element. */ 665 typedef struct { 666 uint16_t char_handle; /*!< Characteristic handle. */ 667 esp_gatt_char_prop_t properties; /*!< Characteristic properties. */ 668 esp_bt_uuid_t uuid; /*!< Characteristic UUID. */ 669 } esp_gattc_char_elem_t; 670 671 /** @brief Represents a GATT descriptor element. */ 672 typedef struct { 673 uint16_t handle; /*!< Descriptor handle. */ 674 esp_bt_uuid_t uuid; /*!< Descriptor UUID. */ 675 } esp_gattc_descr_elem_t; 676 677 /** @brief Represents an included GATT service element. */ 678 typedef struct { 679 uint16_t handle; /*!< Current attribute handle of the included service. */ 680 uint16_t incl_srvc_s_handle; /*!< Start handle of the included service. */ 681 uint16_t incl_srvc_e_handle; /*!< End handle of the included service. */ 682 esp_bt_uuid_t uuid; /*!< Included service UUID. */ 683 } esp_gattc_incl_svc_elem_t; 684 685 /** @brief Represents a creat connection element. */ 686 typedef struct { 687 esp_bd_addr_t remote_bda; /*!< The Bluetooth address of the remote device */ 688 esp_ble_addr_type_t remote_addr_type; /*!< Address type of the remote device */ 689 bool is_direct; /*!< Direct connection or background auto connection(by now, background auto connection is not supported */ 690 bool is_aux; /*!< Set to true for BLE 5.0 or higher to enable auxiliary connections; set to false for BLE 4.2 or lower. */ 691 esp_ble_addr_type_t own_addr_type; /*!< Specifies the address type used in the connection request. Set to 0xFF if the address type is unknown. */ 692 esp_ble_phy_mask_t phy_mask; /*!< Indicates which PHY connection parameters will be used. When is_aux is false, only the connection params for 1M PHY can be specified */ 693 const esp_ble_conn_params_t *phy_1m_conn_params; /*!< Connection parameters for the LE 1M PHY */ 694 const esp_ble_conn_params_t *phy_2m_conn_params; /*!< Connection parameters for the LE 2M PHY */ 695 const esp_ble_conn_params_t *phy_coded_conn_params; /*!< Connection parameters for the LE Coded PHY */ 696 } esp_ble_gatt_creat_conn_params_t; 697 698 #ifdef __cplusplus 699 } 700 #endif 701