• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/LL/*.py",
309        "test/LL/CIS/CEN/*.py",
310        "test/LL/CIS/PER/*.py",
311        "test/LL/CON_/CEN/*.py",
312        "test/LL/CON_/INI/*.py",
313        "test/LL/CON_/PER/*.py",
314        "test/LL/DDI/ADV/*.py",
315        "test/LL/DDI/SCN/*.py",
316        "test/LL/SEC/ADV/*.py",
317        "test/LMP/*.py",
318        "test/LMP/LIH/*.py",
319        "test/main.py",
320    ],
321    data: [
322        ":lib_rootcanal_ffi",
323    ],
324    libs: [
325        "typing_extensions",
326    ],
327    test_options: {
328        unit_test: true,
329    },
330    version: {
331        py3: {
332            embedded_launcher: true,
333        },
334    },
335}
336
337// test-vendor unit tests for host
338cc_test_host {
339    name: "rootcanal_test_host",
340    defaults: [
341        "bluetooth_cflags",
342    ],
343    // TODO(b/231993739): Reenable isolated:true by deleting the explicit disable below
344    isolated: false,
345    srcs: [
346        "test/async_manager_unittest.cc",
347        "test/h4_parser_unittest.cc",
348        "test/invalid_packet_handler_unittest.cc",
349        "test/pcap_filter_unittest.cc",
350        "test/posix_socket_unittest.cc",
351    ],
352    header_libs: [
353        "libbluetooth_headers",
354    ],
355    local_include_dirs: [
356        "include",
357    ],
358    shared_libs: [
359        "libbase",
360        "libcrypto",
361        "libprotobuf-cpp-full",
362    ],
363    static_libs: [
364        "libbt-rootcanal",
365    ],
366    cflags: [
367        "-fvisibility=hidden",
368    ],
369    target: {
370        darwin: {
371            enabled: false,
372        },
373    },
374}
375
376// Linux RootCanal Executable
377cc_binary_host {
378    name: "root-canal",
379    defaults: ["rootcanal_defaults"],
380    srcs: [
381        "desktop/root_canal_main.cc",
382        "desktop/test_environment.cc",
383    ],
384    header_libs: [
385        "libbluetooth_headers",
386    ],
387    shared_libs: [
388        "libbase",
389        "libunwindstack",
390    ],
391    whole_static_libs: [
392        "libbt-rootcanal",
393    ],
394    static_libs: [
395        "breakpad_client",
396        "libcrypto",
397        "libgflags",
398        "libprotobuf-cpp-full",
399        "libscriptedbeaconpayload-protos-lite",
400    ],
401    target: {
402        // TODO(b/181290178) remove it when sanitize option is supported by linux_bionic as well
403        linux_bionic: {
404            sanitize: {
405                address: false,
406                cfi: false,
407                all_undefined: false,
408            },
409        },
410        darwin: {
411            enabled: false,
412        },
413    },
414}
415
416genrule {
417    name: "rootcanal_hci_packets_cxx_gen",
418    tools: [
419        ":pdl_cxx_generator",
420        ":pdlc",
421    ],
422    cmd: "set -o pipefail;" +
423        " $(location :pdlc) $(in) |" +
424        " $(location :pdl_cxx_generator)" +
425        " --namespace bluetooth::hci" +
426        " --include-header hci/address.h" +
427        " --output $(out)",
428    srcs: [
429        "packets/hci_packets.pdl",
430    ],
431    out: [
432        "packets/hci_packets.h",
433    ],
434}
435
436genrule {
437    name: "rootcanal_link_layer_packets_cxx_gen",
438    tools: [
439        ":pdl_cxx_generator",
440        ":pdlc",
441    ],
442    cmd: "set -o pipefail;" +
443        " $(location :pdlc) $(in) |" +
444        " $(location :pdl_cxx_generator)" +
445        " --namespace model::packets" +
446        " --include-header hci/address.h" +
447        " --using-namespace bluetooth::hci" +
448        " --output $(out)",
449    srcs: [
450        "packets/link_layer_packets.pdl",
451    ],
452    out: [
453        "packets/link_layer_packets.h",
454    ],
455}
456
457genrule {
458    name: "rootcanal_link_layer_packets_rust_gen",
459    defaults: ["pdl_rust_legacy_generator_defaults"],
460    srcs: ["packets/link_layer_packets.pdl"],
461    out: ["link_layer_packets.rs"],
462}
463
464genrule {
465    name: "rootcanal_bredr_bb_packets_cxx_gen",
466    tools: [
467        ":pdl_cxx_generator",
468        ":pdlc",
469    ],
470    cmd: "set -o pipefail;" +
471        " $(location :pdlc) $(in) |" +
472        " $(location :pdl_cxx_generator)" +
473        " --namespace bredr_bb" +
474        " --include-header hci/address.h" +
475        " --using-namespace bluetooth::hci" +
476        " --output $(out)",
477    srcs: [
478        "packets/bredr_bb.pdl",
479    ],
480    out: [
481        "bredr_bb.h",
482    ],
483}
484
485genrule {
486    name: "rootcanal_hci_packets_rust_gen",
487    defaults: ["pdl_rust_legacy_generator_defaults"],
488    srcs: ["packets/hci_packets.pdl"],
489    out: ["hci_packets.rs"],
490}
491