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