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