1// simulation library for testing virtual devices 2package { 3 // See: http://go/android-license-faq 4 // A large-scale-change added 'default_applicable_licenses' to import 5 // all of the 'license_kinds' from "system_bt_license" 6 // to get the below license kinds: 7 // SPDX-license-identifier-Apache-2.0 8 default_applicable_licenses: ["system_bt_license"], 9 default_visibility: [ 10 "//device:__subpackages__", 11 "//packages/modules/Bluetooth:__subpackages__", 12 "//platform_testing:__subpackages__", 13 "//tools/netsim:__subpackages__", 14 ], 15} 16 17cc_defaults { 18 name: "rootcanal_defaults", 19 tidy: true, 20 tidy_checks: [ 21 "-*", 22 "readability-*", 23 24 "-readability-function-size", 25 "-readability-identifier-length", 26 "-readability-implicit-bool-conversion", 27 "-readability-magic-numbers", 28 "-readability-use-anyofallof", 29 ], 30 tidy_checks_as_errors: [ 31 "readability-*", 32 ], 33 tidy_flags: [ 34 "--header-filter=^.*tools\\/rootcanal\\/(model|include|net|desktop)\\/(.(?!\\.pb\\.h))*$", 35 ], 36 sanitize: { 37 address: true, 38 all_undefined: true, 39 misc_undefined: ["bounds"], 40 }, 41 c_std: "c99", 42 cpp_std: "c++20", 43 cflags: [ 44 "-DGOOGLE_PROTOBUF_NO_RTTI", 45 "-Wall", 46 "-Werror", 47 "-Wextra", 48 "-fvisibility=hidden", 49 ], 50 include_dirs: [ 51 "packages/modules/Bluetooth/tools/rootcanal/include", 52 ], 53 header_libs: [ 54 "libbase_headers", 55 "pdl_cxx_packet_runtime", 56 ], 57 generated_headers: [ 58 "rootcanal_bredr_bb_packets_cxx_gen", 59 "rootcanal_hci_packets_cxx_gen", 60 "rootcanal_link_layer_packets_cxx_gen", 61 ], 62} 63 64filegroup { 65 name: "lib_sources", 66 srcs: [ 67 "lib/crypto/crypto.cc", 68 "lib/hci/address.cc", 69 "lib/hci/pcap_filter.cc", 70 "lib/log.cc", 71 ], 72} 73 74// This library should be added as `whole_static_libs` 75// as it uses static registration and all object 76// files needs to be linked 77cc_library_static { 78 name: "libbt-rootcanal", 79 defaults: ["rootcanal_defaults"], 80 host_supported: true, 81 proprietary: true, 82 srcs: [ 83 ":lib_sources", 84 "model/controller/acl_connection.cc", 85 "model/controller/acl_connection_handler.cc", 86 "model/controller/controller_properties.cc", 87 "model/controller/dual_mode_controller.cc", 88 "model/controller/le_advertiser.cc", 89 "model/controller/link_layer_controller.cc", 90 "model/controller/sco_connection.cc", 91 "model/controller/vendor_commands/le_apcf.cc", 92 "model/devices/baseband_sniffer.cc", 93 "model/devices/beacon.cc", 94 "model/devices/device.cc", 95 "model/devices/hci_device.cc", 96 "model/devices/link_layer_socket_device.cc", 97 "model/devices/sniffer.cc", 98 "model/hci/h4_data_channel_packetizer.cc", 99 "model/hci/h4_parser.cc", 100 "model/hci/hci_sniffer.cc", 101 "model/hci/hci_socket_transport.cc", 102 "model/setup/async_manager.cc", 103 "model/setup/device_boutique.cc", 104 "model/setup/phy_device.cc", 105 "model/setup/phy_layer.cc", 106 "model/setup/test_channel_transport.cc", 107 "model/setup/test_command_handler.cc", 108 "model/setup/test_model.cc", 109 "net/posix/posix_async_socket.cc", 110 "net/posix/posix_async_socket_connector.cc", 111 "net/posix/posix_async_socket_server.cc", 112 ], 113 export_header_lib_headers: [ 114 "pdl_cxx_packet_runtime", 115 ], 116 export_include_dirs: [ 117 ".", 118 "include", 119 ], 120 export_generated_headers: [ 121 "rootcanal_hci_packets_cxx_gen", 122 "rootcanal_link_layer_packets_cxx_gen", 123 ], 124 export_static_lib_headers: [ 125 "librootcanal_config", 126 ], 127 whole_static_libs: [ 128 "librootcanal_config", 129 "librootcanal_rs", 130 ], 131 shared_libs: [ 132 "libbase", 133 "libcrypto", 134 "libprotobuf-cpp-full", 135 ], 136} 137 138// This library implements a foreigh function interface over DualModeController 139// compatible with Python or Rust. 140cc_library_host_shared { 141 name: "lib_rootcanal_ffi", 142 defaults: [ 143 "rootcanal_defaults", 144 ], 145 sanitize: { 146 address: false, 147 }, 148 srcs: [ 149 ":lib_sources", 150 "model/controller/acl_connection.cc", 151 "model/controller/acl_connection_handler.cc", 152 "model/controller/controller_properties.cc", 153 "model/controller/dual_mode_controller.cc", 154 "model/controller/ffi.cc", 155 "model/controller/le_advertiser.cc", 156 "model/controller/link_layer_controller.cc", 157 "model/controller/sco_connection.cc", 158 "model/controller/vendor_commands/le_apcf.cc", 159 "model/devices/device.cc", 160 "model/setup/async_manager.cc", 161 ], 162 export_include_dirs: [ 163 ".", 164 "include", 165 ], 166 stl: "libc++_static", 167 static_libs: [ 168 "libcrypto", 169 "libprotobuf-cpp-full", 170 "librootcanal_config", 171 ], 172 whole_static_libs: [ 173 "libbase", 174 "liblog", 175 "librootcanal_rs", 176 ], 177 cflags: [ 178 "-fexceptions", 179 ], 180} 181 182// Generate the python parser+serializer backend for 183// packets/link_layer_packets.pdl. 184genrule { 185 name: "link_layer_packets_python3_gen", 186 defaults: ["pdl_python_generator_defaults"], 187 cmd: "$(location :pdlc) $(in) |" + 188 " $(location :pdl_python_generator)" + 189 " --output $(out) --custom-type-location py.bluetooth", 190 srcs: [ 191 "packets/link_layer_packets.pdl", 192 ], 193 out: [ 194 "link_layer_packets.py", 195 ], 196} 197 198// Generate the python parser+serializer backend for 199// rust/llcp_packets.pdl. 200genrule { 201 name: "llcp_packets_python3_gen", 202 defaults: ["pdl_python_generator_defaults"], 203 cmd: "$(location :pdlc) $(in) |" + 204 " $(location :pdl_python_generator)" + 205 " --output $(out) --custom-type-location py.bluetooth", 206 srcs: [ 207 "rust/llcp_packets.pdl", 208 ], 209 out: [ 210 "llcp_packets.py", 211 ], 212} 213 214// Generate the python parser+serializer backend for 215// hci_packets.pdl. 216genrule { 217 name: "hci_packets_python3_gen", 218 defaults: ["pdl_python_generator_defaults"], 219 cmd: "$(location :pdlc) $(in) |" + 220 " $(location :pdl_python_generator)" + 221 " --output $(out) --custom-type-location py.bluetooth", 222 srcs: [ 223 "packets/hci_packets.pdl", 224 ], 225 out: [ 226 "hci_packets.py", 227 ], 228} 229 230cc_test_host { 231 name: "rootcanal_hci_test", 232 defaults: [ 233 "rootcanal_defaults", 234 ], 235 srcs: [ 236 "test/controller/le/le_add_device_to_filter_accept_list_test.cc", 237 "test/controller/le/le_add_device_to_periodic_advertiser_list_test.cc", 238 "test/controller/le/le_add_device_to_resolving_list_test.cc", 239 "test/controller/le/le_clear_filter_accept_list_test.cc", 240 "test/controller/le/le_clear_periodic_advertiser_list_test.cc", 241 "test/controller/le/le_clear_resolving_list_test.cc", 242 "test/controller/le/le_create_connection_cancel_test.cc", 243 "test/controller/le/le_create_connection_test.cc", 244 "test/controller/le/le_extended_create_connection_test.cc", 245 "test/controller/le/le_periodic_advertising_create_sync_cancel_test.cc", 246 "test/controller/le/le_periodic_advertising_create_sync_test.cc", 247 "test/controller/le/le_remove_device_from_filter_accept_list_test.cc", 248 "test/controller/le/le_remove_device_from_periodic_advertiser_list_test.cc", 249 "test/controller/le/le_remove_device_from_resolving_list_test.cc", 250 "test/controller/le/le_scanning_filter_duplicates_test.cc", 251 "test/controller/le/le_set_address_resolution_enable_test.cc", 252 "test/controller/le/le_set_advertising_enable_test.cc", 253 "test/controller/le/le_set_advertising_parameters_test.cc", 254 "test/controller/le/le_set_extended_advertising_data_test.cc", 255 "test/controller/le/le_set_extended_advertising_enable_test.cc", 256 "test/controller/le/le_set_extended_advertising_parameters_test.cc", 257 "test/controller/le/le_set_extended_scan_enable_test.cc", 258 "test/controller/le/le_set_extended_scan_parameters_test.cc", 259 "test/controller/le/le_set_extended_scan_response_data_test.cc", 260 "test/controller/le/le_set_periodic_advertising_data_test.cc", 261 "test/controller/le/le_set_periodic_advertising_enable_test.cc", 262 "test/controller/le/le_set_periodic_advertising_parameters_test.cc", 263 "test/controller/le/le_set_random_address_test.cc", 264 "test/controller/le/le_set_scan_enable_test.cc", 265 "test/controller/le/le_set_scan_parameters_test.cc", 266 "test/controller/le/rpa_generation_test.cc", 267 ], 268 header_libs: [ 269 "libbluetooth_headers", 270 ], 271 local_include_dirs: [ 272 ".", 273 ], 274 shared_libs: [ 275 "libbase", 276 "libcrypto", 277 "libprotobuf-cpp-full", 278 ], 279 static_libs: [ 280 "libbt-rootcanal", 281 ], 282} 283 284// Implement the Bluetooth official LL test suite for root-canal. 285python_test_host { 286 name: "rootcanal_ll_test", 287 main: "test/main.py", 288 srcs: [ 289 ":hci_packets_python3_gen", 290 ":link_layer_packets_python3_gen", 291 ":llcp_packets_python3_gen", 292 "py/bluetooth.py", 293 "py/controller.py", 294 "test/HCI/AEN/*.py", 295 "test/LL/*.py", 296 "test/LL/CIS/CEN/*.py", 297 "test/LL/CIS/PER/*.py", 298 "test/LL/CON_/CEN/*.py", 299 "test/LL/CON_/INI/*.py", 300 "test/LL/CON_/PER/*.py", 301 "test/LL/DDI/ADV/*.py", 302 "test/LL/DDI/SCN/*.py", 303 "test/LL/SEC/ADV/*.py", 304 "test/LMP/*.py", 305 "test/LMP/LIH/*.py", 306 "test/main.py", 307 ], 308 data: [ 309 ":lib_rootcanal_ffi", 310 ], 311 libs: [ 312 "typing_extensions", 313 ], 314 test_options: { 315 unit_test: true, 316 }, 317} 318 319// test-vendor unit tests for host 320cc_test_host { 321 name: "rootcanal_test_host", 322 defaults: [ 323 "bluetooth_cflags", 324 ], 325 // TODO(b/231993739): Reenable isolated:true by deleting the explicit disable below 326 isolated: false, 327 srcs: [ 328 "test/async_manager_unittest.cc", 329 "test/h4_parser_unittest.cc", 330 "test/invalid_packet_handler_unittest.cc", 331 "test/pcap_filter_unittest.cc", 332 "test/posix_socket_unittest.cc", 333 ], 334 header_libs: [ 335 "libbluetooth_headers", 336 ], 337 local_include_dirs: [ 338 "include", 339 ], 340 shared_libs: [ 341 "libbase", 342 "libcrypto", 343 "libprotobuf-cpp-full", 344 ], 345 static_libs: [ 346 "libbt-rootcanal", 347 ], 348 cflags: [ 349 "-fvisibility=hidden", 350 ], 351 target: { 352 darwin: { 353 enabled: false, 354 }, 355 }, 356} 357 358// Linux RootCanal Executable 359cc_binary_host { 360 name: "root-canal", 361 defaults: ["rootcanal_defaults"], 362 srcs: [ 363 "desktop/root_canal_main.cc", 364 "desktop/test_environment.cc", 365 ], 366 header_libs: [ 367 "libbluetooth_headers", 368 ], 369 shared_libs: [ 370 "libbase", 371 "libunwindstack", 372 ], 373 whole_static_libs: [ 374 "libbt-rootcanal", 375 ], 376 static_libs: [ 377 "breakpad_client", 378 "libcrypto", 379 "libgflags", 380 "libprotobuf-cpp-full", 381 ], 382 target: { 383 // TODO(b/181290178) remove it when sanitize option is supported by linux_bionic as well 384 linux_bionic: { 385 sanitize: { 386 address: false, 387 cfi: false, 388 all_undefined: false, 389 }, 390 }, 391 darwin: { 392 enabled: false, 393 }, 394 }, 395} 396 397genrule { 398 name: "rootcanal_hci_packets_cxx_gen", 399 tools: [ 400 ":pdl_cxx_generator", 401 ":pdlc", 402 ], 403 cmd: "set -o pipefail;" + 404 " $(location :pdlc) $(in) |" + 405 " $(location :pdl_cxx_generator)" + 406 " --namespace bluetooth::hci" + 407 " --include-header hci/address.h" + 408 " --output $(out)", 409 srcs: [ 410 "packets/hci_packets.pdl", 411 ], 412 out: [ 413 "packets/hci_packets.h", 414 ], 415} 416 417genrule { 418 name: "rootcanal_link_layer_packets_cxx_gen", 419 tools: [ 420 ":pdl_cxx_generator", 421 ":pdlc", 422 ], 423 cmd: "set -o pipefail;" + 424 " $(location :pdlc) $(in) |" + 425 " $(location :pdl_cxx_generator)" + 426 " --namespace model::packets" + 427 " --include-header hci/address.h" + 428 " --using-namespace bluetooth::hci" + 429 " --output $(out)", 430 srcs: [ 431 "packets/link_layer_packets.pdl", 432 ], 433 out: [ 434 "packets/link_layer_packets.h", 435 ], 436} 437 438genrule { 439 name: "rootcanal_link_layer_packets_rust_gen", 440 defaults: ["pdl_rust_legacy_generator_defaults"], 441 srcs: ["packets/link_layer_packets.pdl"], 442 out: ["link_layer_packets.rs"], 443} 444 445genrule { 446 name: "rootcanal_bredr_bb_packets_cxx_gen", 447 tools: [ 448 ":pdl_cxx_generator", 449 ":pdlc", 450 ], 451 cmd: "set -o pipefail;" + 452 " $(location :pdlc) $(in) |" + 453 " $(location :pdl_cxx_generator)" + 454 " --namespace bredr_bb" + 455 " --include-header hci/address.h" + 456 " --using-namespace bluetooth::hci" + 457 " --output $(out)", 458 srcs: [ 459 "packets/bredr_bb.pdl", 460 ], 461 out: [ 462 "bredr_bb.h", 463 ], 464} 465 466genrule { 467 name: "rootcanal_hci_packets_rust_gen", 468 defaults: ["pdl_rust_legacy_generator_defaults"], 469 srcs: ["packets/hci_packets.pdl"], 470 out: ["hci_packets.rs"], 471} 472