1 /* gap.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 /* GAP Service */ 14 /* commands */ 15 #define BTP_GAP_READ_SUPPORTED_COMMANDS 0x01 16 struct btp_gap_read_supported_commands_rp { 17 uint8_t data[0]; 18 } __packed; 19 20 #define BTP_GAP_READ_CONTROLLER_INDEX_LIST 0x02 21 struct btp_gap_read_controller_index_list_rp { 22 uint8_t num; 23 uint8_t index[]; 24 } __packed; 25 26 #define BTP_GAP_SETTINGS_POWERED 0 27 #define BTP_GAP_SETTINGS_CONNECTABLE 1 28 #define BTP_GAP_SETTINGS_FAST_CONNECTABLE 2 29 #define BTP_GAP_SETTINGS_DISCOVERABLE 3 30 #define BTP_GAP_SETTINGS_BONDABLE 4 31 #define BTP_GAP_SETTINGS_LINK_SEC_3 5 32 #define BTP_GAP_SETTINGS_SSP 6 33 #define BTP_GAP_SETTINGS_BREDR 7 34 #define BTP_GAP_SETTINGS_HS 8 35 #define BTP_GAP_SETTINGS_LE 9 36 #define BTP_GAP_SETTINGS_ADVERTISING 10 37 #define BTP_GAP_SETTINGS_SC 11 38 #define BTP_GAP_SETTINGS_DEBUG_KEYS 12 39 #define BTP_GAP_SETTINGS_PRIVACY 13 40 #define BTP_GAP_SETTINGS_CONTROLLER_CONFIG 14 41 #define BTP_GAP_SETTINGS_STATIC_ADDRESS 15 42 #define BTP_GAP_SETTINGS_SC_ONLY 16 43 #define BTP_GAP_SETTINGS_EXTENDED_ADVERTISING 17 44 45 #define BTP_GAP_READ_CONTROLLER_INFO 0x03 46 struct btp_gap_read_controller_info_rp { 47 bt_addr_t address; 48 uint32_t supported_settings; 49 uint32_t current_settings; 50 uint8_t cod[3]; 51 uint8_t name[249]; 52 uint8_t short_name[11]; 53 } __packed; 54 55 #define BTP_GAP_RESET 0x04 56 struct btp_gap_reset_rp { 57 uint32_t current_settings; 58 } __packed; 59 60 #define BTP_GAP_SET_POWERED 0x05 61 struct btp_gap_set_powered_cmd { 62 uint8_t powered; 63 } __packed; 64 struct btp_gap_set_powered_rp { 65 uint32_t current_settings; 66 } __packed; 67 68 #define BTP_GAP_SET_CONNECTABLE 0x06 69 struct btp_gap_set_connectable_cmd { 70 uint8_t connectable; 71 } __packed; 72 struct btp_gap_set_connectable_rp { 73 uint32_t current_settings; 74 } __packed; 75 76 #define BTP_GAP_SET_FAST_CONNECTABLE 0x07 77 struct btp_gap_set_fast_connectable_cmd { 78 uint8_t fast_connectable; 79 } __packed; 80 struct btp_gap_set_fast_connectable_rp { 81 uint32_t current_settings; 82 } __packed; 83 84 #define BTP_GAP_NON_DISCOVERABLE 0x00 85 #define BTP_GAP_GENERAL_DISCOVERABLE 0x01 86 #define BTP_GAP_LIMITED_DISCOVERABLE 0x02 87 88 #define BTP_GAP_SET_DISCOVERABLE 0x08 89 struct btp_gap_set_discoverable_cmd { 90 uint8_t discoverable; 91 } __packed; 92 struct btp_gap_set_discoverable_rp { 93 uint32_t current_settings; 94 } __packed; 95 96 #define BTP_GAP_SET_BONDABLE 0x09 97 struct btp_gap_set_bondable_cmd { 98 uint8_t bondable; 99 } __packed; 100 struct btp_gap_set_bondable_rp { 101 uint32_t current_settings; 102 } __packed; 103 104 #define BTP_GAP_ADDR_TYPE_IDENTITY 0 105 #define BTP_GAP_ADDR_TYPE_RESOLVABLE_PRIVATE 1 106 #define BTP_GAP_ADDR_TYPE_NON_RESOLVABLE_PRIVATE 2 107 108 #define BTP_GAP_START_ADVERTISING 0x0a 109 struct btp_gap_start_advertising_cmd { 110 uint8_t adv_data_len; 111 uint8_t scan_rsp_len; 112 uint8_t adv_sr_data[]; 113 /* 114 * This command is very unfortunate because it has two fields after variable 115 * data. Those needs to be handled explicitly by handler. 116 * uint32_t duration; 117 * uint8_t own_addr_type; 118 */ 119 } __packed; 120 struct btp_gap_start_advertising_rp { 121 uint32_t current_settings; 122 } __packed; 123 124 #define BTP_GAP_STOP_ADVERTISING 0x0b 125 struct btp_gap_stop_advertising_rp { 126 uint32_t current_settings; 127 } __packed; 128 129 #define BTP_GAP_DISCOVERY_FLAG_LE 0x01 130 #define BTP_GAP_DISCOVERY_FLAG_BREDR 0x02 131 #define BTP_GAP_DISCOVERY_FLAG_LIMITED 0x04 132 #define BTP_GAP_DISCOVERY_FLAG_LE_ACTIVE_SCAN 0x08 133 #define BTP_GAP_DISCOVERY_FLAG_LE_OBSERVE 0x10 134 #define BTP_GAP_DISCOVERY_FLAG_OWN_ID_ADDR 0x20 135 136 #define BTP_GAP_START_DISCOVERY 0x0c 137 struct btp_gap_start_discovery_cmd { 138 uint8_t flags; 139 } __packed; 140 141 #define BTP_GAP_STOP_DISCOVERY 0x0d 142 143 #define BTP_GAP_CONNECT 0x0e 144 struct btp_gap_connect_cmd { 145 bt_addr_le_t address; 146 uint8_t own_addr_type; 147 } __packed; 148 149 #define BTP_GAP_DISCONNECT 0x0f 150 struct btp_gap_disconnect_cmd { 151 bt_addr_le_t address; 152 } __packed; 153 154 #define BTP_GAP_IO_CAP_DISPLAY_ONLY 0 155 #define BTP_GAP_IO_CAP_DISPLAY_YESNO 1 156 #define BTP_GAP_IO_CAP_KEYBOARD_ONLY 2 157 #define BTP_GAP_IO_CAP_NO_INPUT_OUTPUT 3 158 #define BTP_GAP_IO_CAP_KEYBOARD_DISPLAY 4 159 160 #define BTP_GAP_SET_IO_CAP 0x10 161 struct btp_gap_set_io_cap_cmd { 162 uint8_t io_cap; 163 } __packed; 164 165 #define BTP_GAP_PAIR 0x11 166 struct btp_gap_pair_cmd { 167 bt_addr_le_t address; 168 } __packed; 169 170 #define BTP_GAP_UNPAIR 0x12 171 struct btp_gap_unpair_cmd { 172 bt_addr_le_t address; 173 } __packed; 174 175 #define BTP_GAP_PASSKEY_ENTRY 0x13 176 struct btp_gap_passkey_entry_cmd { 177 bt_addr_le_t address; 178 uint32_t passkey; 179 } __packed; 180 181 #define BTP_GAP_PASSKEY_CONFIRM 0x14 182 struct btp_gap_passkey_confirm_cmd { 183 bt_addr_le_t address; 184 uint8_t match; 185 } __packed; 186 187 #define BTP_GAP_START_DIRECTED_ADV_HD BIT(0) 188 #define BTP_GAP_START_DIRECTED_ADV_OWN_ID BIT(1) 189 #define BTP_GAP_START_DIRECTED_ADV_PEER_RPA BIT(2) 190 191 #define BTP_GAP_START_DIRECTED_ADV 0x15 192 struct btp_gap_start_directed_adv_cmd { 193 bt_addr_le_t address; 194 uint16_t options; 195 } __packed; 196 struct btp_gap_start_directed_adv_rp { 197 uint32_t current_settings; 198 } __packed; 199 200 #define BTP_GAP_CONN_PARAM_UPDATE 0x16 201 struct btp_gap_conn_param_update_cmd { 202 bt_addr_le_t address; 203 uint16_t interval_min; 204 uint16_t interval_max; 205 uint16_t latency; 206 uint16_t timeout; 207 } __packed; 208 209 #define BTP_GAP_PAIRING_CONSENT 0x17 210 struct btp_gap_pairing_consent_cmd { 211 bt_addr_le_t address; 212 uint8_t consent; 213 } __packed; 214 215 #define BTP_GAP_OOB_LEGACY_SET_DATA 0x18 216 struct btp_gap_oob_legacy_set_data_cmd { 217 uint8_t oob_data[16]; 218 } __packed; 219 220 #define BTP_GAP_OOB_SC_GET_LOCAL_DATA 0x19 221 struct btp_gap_oob_sc_get_local_data_rp { 222 uint8_t rand[16]; 223 uint8_t conf[16]; 224 } __packed; 225 226 #define BTP_GAP_OOB_SC_SET_REMOTE_DATA 0x1a 227 struct btp_gap_oob_sc_set_remote_data_cmd { 228 uint8_t rand[16]; 229 uint8_t conf[16]; 230 } __packed; 231 232 #define BTP_GAP_SET_MITM 0x1b 233 struct btp_gap_set_mitm { 234 uint8_t mitm; 235 } __packed; 236 237 #define BTP_GAP_SET_FILTER_LIST 0x1c 238 struct btp_gap_set_filter_list { 239 uint8_t cnt; 240 bt_addr_le_t addr[]; 241 } __packed; 242 243 #define BTP_GAP_SET_PRIVACY 0x1d 244 #define BTP_GAP_SET_SC_ONLY 0x1e 245 #define BTP_GAP_SET_SC 0x1f 246 #define BTP_GAP_SET_MIN_ENC_KEY_SIZE 0x20 247 248 #define BTP_GAP_SET_EXTENDED_ADVERTISING 0x21 249 struct btp_gap_set_extended_advertising_cmd { 250 uint8_t settings; 251 } __packed; 252 struct btp_gap_set_extended_advertising_rp { 253 uint32_t current_settings; 254 } __packed; 255 256 #define BTP_GAP_PADV_CONFIGURE 0x22 257 /* bitmap of flags*/ 258 #define BTP_GAP_PADV_INCLUDE_TX_POWER BIT(0) 259 struct btp_gap_padv_configure_cmd { 260 uint8_t flags; 261 uint16_t interval_min; 262 uint16_t interval_max; 263 } __packed; 264 struct btp_gap_padv_configure_rp { 265 uint32_t current_settings; 266 } __packed; 267 268 #define BTP_GAP_PADV_START 0x23 269 struct btp_gap_padv_start_cmd { 270 uint8_t flags; 271 } __packed; 272 struct btp_gap_padv_start_rp { 273 uint32_t current_settings; 274 } __packed; 275 276 #define BTP_GAP_PADV_STOP 0x24 277 struct btp_gap_padv_stop_cmd { 278 } __packed; 279 struct btp_gap_padv_stop_rp { 280 uint32_t current_settings; 281 } __packed; 282 283 #define BTP_GAP_PADV_SET_DATA 0x25 284 struct btp_gap_padv_set_data_cmd { 285 uint16_t data_len; 286 uint8_t data[]; 287 } __packed; 288 289 #define BTP_GAP_PADV_CREATE_SYNC_FLAG_REPORTS_DISABLED 0x01 290 #define BTP_GAP_PADV_CREATE_SYNC_FLAG_FILTER_DUPLICATES 0x02 291 292 #define BTP_GAP_PADV_CREATE_SYNC 0x26 293 struct btp_gap_padv_create_sync_cmd { 294 bt_addr_le_t address; 295 uint8_t advertiser_sid; 296 uint16_t skip; 297 uint16_t sync_timeout; 298 uint8_t flags; 299 } __packed; 300 301 #define BTP_GAP_PADV_SYNC_TRANSFER_SET_INFO 0x27 302 struct btp_gap_padv_sync_transfer_set_info_cmd { 303 bt_addr_le_t address; 304 uint16_t service_data; 305 } __packed; 306 307 #define BTP_GAP_PADV_SYNC_TRANSFER_START 0x28 308 struct btp_gap_padv_sync_transfer_start_cmd { 309 uint16_t sync_handle; 310 bt_addr_le_t address; 311 uint16_t service_data; 312 } __packed; 313 314 #define BTP_GAP_PADV_SYNC_TRANSFER_RECV 0x29 315 struct btp_gap_padv_sync_transfer_recv_cmd { 316 bt_addr_le_t address; 317 uint16_t skip; 318 uint16_t sync_timeout; 319 uint8_t flags; 320 } __packed; 321 322 /* events */ 323 #define BTP_GAP_EV_NEW_SETTINGS 0x80 324 struct btp_gap_new_settings_ev { 325 uint32_t current_settings; 326 } __packed; 327 328 #define BTP_GAP_DEVICE_FOUND_FLAG_RSSI 0x01 329 #define BTP_GAP_DEVICE_FOUND_FLAG_AD 0x02 330 #define BTP_GAP_DEVICE_FOUND_FLAG_SD 0x04 331 332 #define BTP_GAP_EV_DEVICE_FOUND 0x81 333 struct btp_gap_device_found_ev { 334 bt_addr_le_t address; 335 int8_t rssi; 336 uint8_t flags; 337 uint16_t eir_data_len; 338 uint8_t eir_data[]; 339 } __packed; 340 341 #define BTP_GAP_EV_DEVICE_CONNECTED 0x82 342 struct btp_gap_device_connected_ev { 343 bt_addr_le_t address; 344 uint16_t interval; 345 uint16_t latency; 346 uint16_t timeout; 347 } __packed; 348 349 #define BTP_GAP_EV_DEVICE_DISCONNECTED 0x83 350 struct btp_gap_device_disconnected_ev { 351 bt_addr_le_t address; 352 } __packed; 353 354 #define BTP_GAP_EV_PASSKEY_DISPLAY 0x84 355 struct btp_gap_passkey_display_ev { 356 bt_addr_le_t address; 357 uint32_t passkey; 358 } __packed; 359 360 #define BTP_GAP_EV_PASSKEY_ENTRY_REQ 0x85 361 struct btp_gap_passkey_entry_req_ev { 362 bt_addr_le_t address; 363 } __packed; 364 365 #define BTP_GAP_EV_PASSKEY_CONFIRM_REQ 0x86 366 struct btp_gap_passkey_confirm_req_ev { 367 bt_addr_le_t address; 368 uint32_t passkey; 369 } __packed; 370 371 #define BTP_GAP_EV_IDENTITY_RESOLVED 0x87 372 struct btp_gap_identity_resolved_ev { 373 bt_addr_le_t address; 374 bt_addr_le_t identity_address; 375 } __packed; 376 377 #define BTP_GAP_EV_CONN_PARAM_UPDATE 0x88 378 struct btp_gap_conn_param_update_ev { 379 bt_addr_le_t address; 380 uint16_t interval; 381 uint16_t latency; 382 uint16_t timeout; 383 } __packed; 384 385 #define BTP_GAP_SEC_LEVEL_UNAUTH_ENC 0x01 386 #define BTP_GAP_SEC_LEVEL_AUTH_ENC 0x02 387 #define BTP_GAP_SEC_LEVEL_AUTH_SC 0x03 388 389 #define BTP_GAP_EV_SEC_LEVEL_CHANGED 0x89 390 struct btp_gap_sec_level_changed_ev { 391 bt_addr_le_t address; 392 uint8_t sec_level; 393 } __packed; 394 395 #define BTP_GAP_EV_PAIRING_CONSENT_REQ 0x8a 396 struct btp_gap_pairing_consent_req_ev { 397 bt_addr_le_t address; 398 } __packed; 399 400 #define BTP_GAP_EV_BOND_LOST 0x8b 401 struct btp_gap_bond_lost_ev { 402 bt_addr_le_t address; 403 } __packed; 404 405 #define BTP_GAP_EV_PAIRING_FAILED 0x8c 406 struct btp_gap_bond_pairing_failed_ev { 407 bt_addr_le_t address; 408 uint8_t reason; 409 } __packed; 410 411 #define BTP_GAP_EV_PERIODIC_SYNC_ESTABLISHED 0x8d 412 struct btp_gap_ev_periodic_sync_established_ev { 413 bt_addr_le_t address; 414 uint16_t sync_handle; 415 uint8_t status; 416 } __packed; 417 418 #define BTP_GAP_EV_PERIODIC_SYNC_LOST 0x8e 419 struct btp_gap_ev_periodic_sync_lost_ev { 420 uint16_t sync_handle; 421 uint8_t reason; 422 } __packed; 423 424 #define BTP_GAP_EV_PERIODIC_REPORT 0x8f 425 struct btp_gap_ev_periodic_report_ev { 426 uint16_t sync_handle; 427 uint8_t tx_power; 428 uint8_t rssi; 429 uint8_t cte_type; 430 uint8_t data_status; 431 uint8_t data_len; 432 uint8_t data[]; 433 } __packed; 434 435 #define BTP_GAP_EV_PERIODIC_TRANSFER_RECEIVED 0x90 436 struct btp_gap_ev_periodic_transfer_received_ev { 437 uint16_t sync_handle; 438 uint8_t tx_power; 439 uint8_t rssi; 440 uint8_t cte_type; 441 uint8_t data_status; 442 uint8_t data_len; 443 uint8_t data[]; 444 } __packed; 445 446 #if defined(CONFIG_BT_EXT_ADV) 447 struct bt_le_per_adv_param; 448 struct bt_le_per_adv_sync_param; 449 struct bt_le_adv_param; 450 struct bt_data; 451 struct bt_le_ext_adv *tester_gap_ext_adv_get(void); 452 struct bt_le_per_adv_sync *tester_gap_padv_get(void); 453 int tester_gap_create_adv_instance(struct bt_le_adv_param *param, uint8_t own_addr_type, 454 const struct bt_data *ad, size_t ad_len, 455 const struct bt_data *sd, size_t sd_len, uint32_t *settings); 456 int tester_gap_stop_ext_adv(void); 457 int tester_gap_start_ext_adv(void); 458 int tester_gap_padv_configure(const struct bt_le_per_adv_param *param); 459 int tester_gap_padv_set_data(struct bt_data *per_ad, uint8_t ad_len); 460 int tester_gap_padv_start(void); 461 int tester_gap_padv_stop(void); 462 int tester_gap_padv_create_sync(struct bt_le_per_adv_sync_param *create_params); 463 int tester_gap_padv_stop_sync(void); 464 #endif /* defined(CONFIG_BT_EXT_ADV) */ 465