1 /* gatt.h - Bluetooth tester headers */ 2 3 /* 4 * Copyright (c) 2015-2016 Intel Corporation 5 * Copyright (c) 2022 Codecoup 6 * 7 * SPDX-License-Identifier: Apache-2.0 8 */ 9 10 #include <stdint.h> 11 12 #include <zephyr/bluetooth/addr.h> 13 14 /* GATT Service */ 15 /* commands */ 16 #define BTP_GATT_READ_SUPPORTED_COMMANDS 0x01 17 struct btp_gatt_read_supported_commands_rp { 18 uint8_t data[0]; 19 } __packed; 20 21 #define BTP_GATT_SERVICE_PRIMARY 0x00 22 #define BTP_GATT_SERVICE_SECONDARY 0x01 23 24 #define BTP_GATT_ADD_SERVICE 0x02 25 struct btp_gatt_add_service_cmd { 26 uint8_t type; 27 uint8_t uuid_length; 28 uint8_t uuid[]; 29 } __packed; 30 struct btp_gatt_add_service_rp { 31 uint16_t svc_id; 32 } __packed; 33 34 #define BTP_GATT_ADD_CHARACTERISTIC 0x03 35 struct btp_gatt_add_characteristic_cmd { 36 uint16_t svc_id; 37 uint8_t properties; 38 uint8_t permissions; 39 uint8_t uuid_length; 40 uint8_t uuid[]; 41 } __packed; 42 struct btp_gatt_add_characteristic_rp { 43 uint16_t char_id; 44 } __packed; 45 46 #define BTP_GATT_ADD_DESCRIPTOR 0x04 47 struct btp_gatt_add_descriptor_cmd { 48 uint16_t char_id; 49 uint8_t permissions; 50 uint8_t uuid_length; 51 uint8_t uuid[]; 52 } __packed; 53 struct btp_gatt_add_descriptor_rp { 54 uint16_t desc_id; 55 } __packed; 56 57 #define BTP_GATT_ADD_INCLUDED_SERVICE 0x05 58 struct btp_gatt_add_included_service_cmd { 59 uint16_t svc_id; 60 } __packed; 61 struct btp_gatt_add_included_service_rp { 62 uint16_t included_service_id; 63 } __packed; 64 65 #define BTP_GATT_SET_VALUE 0x06 66 struct btp_gatt_set_value_cmd { 67 uint16_t attr_id; 68 uint16_t len; 69 uint8_t value[]; 70 } __packed; 71 72 #define BTP_GATT_START_SERVER 0x07 73 struct btp_gatt_start_server_rp { 74 uint16_t db_attr_off; 75 uint8_t db_attr_cnt; 76 } __packed; 77 78 #define BTP_GATT_RESET_SERVER 0x08 79 80 #define BTP_GATT_SET_ENC_KEY_SIZE 0x09 81 struct btp_gatt_set_enc_key_size_cmd { 82 uint16_t attr_id; 83 uint8_t key_size; 84 } __packed; 85 86 /* Gatt Client */ 87 struct btp_gatt_service { 88 uint16_t start_handle; 89 uint16_t end_handle; 90 uint8_t uuid_length; 91 uint8_t uuid[]; 92 } __packed; 93 94 struct btp_gatt_included { 95 uint16_t included_handle; 96 struct btp_gatt_service service; 97 } __packed; 98 99 struct btp_gatt_characteristic { 100 uint16_t characteristic_handle; 101 uint16_t value_handle; 102 uint8_t properties; 103 uint8_t uuid_length; 104 uint8_t uuid[]; 105 } __packed; 106 107 struct btp_gatt_descriptor { 108 uint16_t descriptor_handle; 109 uint8_t uuid_length; 110 uint8_t uuid[]; 111 } __packed; 112 113 #define BTP_GATT_EXCHANGE_MTU 0x0a 114 struct btp_gatt_exchange_mtu_cmd { 115 bt_addr_le_t address; 116 } __packed; 117 118 #define BTP_GATT_DISC_ALL_PRIM 0x0b 119 struct btp_gatt_disc_all_prim_cmd { 120 bt_addr_le_t address; 121 } __packed; 122 struct btp_gatt_disc_all_prim_rp { 123 uint8_t services_count; 124 struct btp_gatt_service services[]; 125 } __packed; 126 127 #define BTP_GATT_DISC_PRIM_UUID 0x0c 128 struct btp_gatt_disc_prim_uuid_cmd { 129 bt_addr_le_t address; 130 uint8_t uuid_length; 131 uint8_t uuid[]; 132 } __packed; 133 struct btp_gatt_disc_prim_rp { 134 uint8_t services_count; 135 struct btp_gatt_service services[]; 136 } __packed; 137 138 #define BTP_GATT_FIND_INCLUDED 0x0d 139 struct btp_gatt_find_included_cmd { 140 bt_addr_le_t address; 141 uint16_t start_handle; 142 uint16_t end_handle; 143 } __packed; 144 struct btp_gatt_find_included_rp { 145 uint8_t services_count; 146 struct btp_gatt_included included[]; 147 } __packed; 148 149 #define BTP_GATT_DISC_ALL_CHRC 0x0e 150 struct btp_gatt_disc_all_chrc_cmd { 151 bt_addr_le_t address; 152 uint16_t start_handle; 153 uint16_t end_handle; 154 } __packed; 155 struct btp_gatt_disc_chrc_rp { 156 uint8_t characteristics_count; 157 struct btp_gatt_characteristic characteristics[]; 158 } __packed; 159 160 #define BTP_GATT_DISC_CHRC_UUID 0x0f 161 struct btp_gatt_disc_chrc_uuid_cmd { 162 bt_addr_le_t address; 163 uint16_t start_handle; 164 uint16_t end_handle; 165 uint8_t uuid_length; 166 uint8_t uuid[]; 167 } __packed; 168 169 #define BTP_GATT_DISC_ALL_DESC 0x10 170 struct btp_gatt_disc_all_desc_cmd { 171 bt_addr_le_t address; 172 uint16_t start_handle; 173 uint16_t end_handle; 174 } __packed; 175 struct btp_gatt_disc_all_desc_rp { 176 uint8_t descriptors_count; 177 struct btp_gatt_descriptor descriptors[]; 178 } __packed; 179 180 #define BTP_GATT_READ 0x11 181 struct btp_gatt_read_cmd { 182 bt_addr_le_t address; 183 uint16_t handle; 184 } __packed; 185 struct btp_gatt_read_rp { 186 uint8_t att_response; 187 uint16_t data_length; 188 uint8_t data[]; 189 } __packed; 190 191 struct btp_gatt_char_value { 192 uint16_t handle; 193 uint8_t data_len; 194 uint8_t data[0]; 195 } __packed; 196 197 #define BTP_GATT_READ_UUID 0x12 198 struct btp_gatt_read_uuid_cmd { 199 bt_addr_le_t address; 200 uint16_t start_handle; 201 uint16_t end_handle; 202 uint8_t uuid_length; 203 uint8_t uuid[]; 204 } __packed; 205 struct btp_gatt_read_uuid_rp { 206 uint8_t att_response; 207 uint8_t values_count; 208 struct btp_gatt_char_value values[0]; 209 } __packed; 210 211 #define BTP_GATT_READ_LONG 0x13 212 struct btp_gatt_read_long_cmd { 213 bt_addr_le_t address; 214 uint16_t handle; 215 uint16_t offset; 216 } __packed; 217 struct btp_gatt_read_long_rp { 218 uint8_t att_response; 219 uint16_t data_length; 220 uint8_t data[]; 221 } __packed; 222 223 #define BTP_GATT_READ_MULTIPLE 0x14 224 struct btp_gatt_read_multiple_cmd { 225 bt_addr_le_t address; 226 uint8_t handles_count; 227 uint16_t handles[]; 228 } __packed; 229 struct btp_gatt_read_multiple_rp { 230 uint8_t att_response; 231 uint16_t data_length; 232 uint8_t data[]; 233 } __packed; 234 235 #define BTP_GATT_WRITE_WITHOUT_RSP 0x15 236 struct btp_gatt_write_without_rsp_cmd { 237 bt_addr_le_t address; 238 uint16_t handle; 239 uint16_t data_length; 240 uint8_t data[]; 241 } __packed; 242 243 #define BTP_GATT_SIGNED_WRITE_WITHOUT_RSP 0x16 244 struct btp_gatt_signed_write_without_rsp_cmd { 245 bt_addr_le_t address; 246 uint16_t handle; 247 uint16_t data_length; 248 uint8_t data[]; 249 } __packed; 250 251 #define BTP_GATT_WRITE 0x17 252 struct btp_gatt_write_cmd { 253 bt_addr_le_t address; 254 uint16_t handle; 255 uint16_t data_length; 256 uint8_t data[]; 257 } __packed; 258 struct btp_gatt_write_rp { 259 uint8_t att_response; 260 } __packed; 261 262 #define BTP_GATT_WRITE_LONG 0x18 263 struct btp_gatt_write_long_cmd { 264 bt_addr_le_t address; 265 uint16_t handle; 266 uint16_t offset; 267 uint16_t data_length; 268 uint8_t data[]; 269 } __packed; 270 struct btp_gatt_write_long_rp { 271 uint8_t att_response; 272 } __packed; 273 274 #define BTP_GATT_RELIABLE_WRITE 0x19 275 struct btp_gatt_reliable_write_cmd { 276 bt_addr_le_t address; 277 uint16_t handle; 278 uint16_t offset; 279 uint16_t data_length; 280 uint8_t data[]; 281 } __packed; 282 struct btp_gatt_reliable_write_rp { 283 uint8_t att_response; 284 } __packed; 285 286 #define BTP_GATT_CFG_NOTIFY 0x1a 287 #define BTP_GATT_CFG_INDICATE 0x1b 288 struct btp_gatt_cfg_notify_cmd { 289 bt_addr_le_t address; 290 uint8_t enable; 291 uint16_t ccc_handle; 292 } __packed; 293 294 #define BTP_GATT_GET_ATTRIBUTES 0x1c 295 struct btp_gatt_get_attributes_cmd { 296 uint16_t start_handle; 297 uint16_t end_handle; 298 uint8_t type_length; 299 uint8_t type[]; 300 } __packed; 301 struct btp_gatt_get_attributes_rp { 302 uint8_t attrs_count; 303 uint8_t attrs[]; 304 } __packed; 305 struct btp_gatt_attr { 306 uint16_t handle; 307 uint8_t permission; 308 uint8_t type_length; 309 uint8_t type[]; 310 } __packed; 311 312 #define BTP_GATT_GET_ATTRIBUTE_VALUE 0x1d 313 struct btp_gatt_get_attribute_value_cmd { 314 bt_addr_le_t address; 315 uint16_t handle; 316 } __packed; 317 struct btp_gatt_get_attribute_value_rp { 318 uint8_t att_response; 319 uint16_t value_length; 320 uint8_t value[]; 321 } __packed; 322 323 #define BTP_GATT_CHANGE_DB_REMOVE 0x00 324 #define BTP_GATT_CHANGE_DB_ADD 0x01 325 #define BTP_GATT_CHANGE_DB_ANY 0x02 326 327 #define BTP_GATT_CHANGE_DB 0x1e 328 struct btp_gatt_change_db_cmd { 329 uint16_t start_handle; 330 uint16_t end_handle; 331 uint8_t operation; 332 } __packed; 333 334 #define BTP_GATT_EATT_CONNECT 0x1f 335 struct btp_gatt_eatt_connect_cmd { 336 bt_addr_le_t address; 337 uint8_t num_channels; 338 } __packed; 339 340 #define BTP_GATT_READ_MULTIPLE_VAR 0x20 341 struct btp_gatt_read_multiple_var_cmd { 342 bt_addr_le_t address; 343 uint8_t handles_count; 344 uint16_t handles[]; 345 } __packed; 346 struct btp_gatt_read_multiple_var_rp { 347 uint8_t att_response; 348 uint16_t data_length; 349 uint8_t data[]; 350 } __packed; 351 352 #define BTP_GATT_NOTIFY_MULTIPLE 0x21 353 struct btp_gatt_cfg_notify_mult_cmd { 354 bt_addr_le_t address; 355 uint16_t cnt; 356 uint16_t attr_id[]; 357 } __packed; 358 /* GATT events */ 359 #define BTP_GATT_EV_NOTIFICATION 0x80 360 struct btp_gatt_notification_ev { 361 bt_addr_le_t address; 362 uint8_t type; 363 uint16_t handle; 364 uint16_t data_length; 365 uint8_t data[]; 366 } __packed; 367 368 #define BTP_GATT_EV_ATTR_VALUE_CHANGED 0x81 369 struct btp_gatt_attr_value_changed_ev { 370 uint16_t handle; 371 uint16_t data_length; 372 uint8_t data[]; 373 } __packed; 374