From 36b16be3a4aebdd9e5d1a18dde984ccff0da8455 Mon Sep 17 00:00:00 2001 From: Zhanglong Xia Date: Fri, 15 Jan 2021 02:16:31 +0800 Subject: [PATCH] [build] add Android.bp support (#6039) Since Android 7.0, the Soong build system was introduced in Android to replace Make. This commit adds the Android.bp to support Soong build system. --- Android.bp | 707 ++++++++++++++++++ Android.mk | 12 + .../openthread-config-android-version.h.in | 35 + include/openthread-config-android.h | 4 + include/openthread/instance.h | 2 +- include/openthread/platform/toolchain.h | 19 + script/check-android-build | 4 +- script/config-android-version-gen.sh | 52 ++ src/core/api/instance_api.cpp | 28 + src/core/coap/coap.cpp | 5 +- src/core/mac/data_poll_handler.cpp | 2 +- src/core/mac/mac.cpp | 8 +- src/core/mac/sub_mac.cpp | 2 +- src/core/meshcop/dataset_manager.cpp | 2 +- src/core/meshcop/dataset_manager_ftd.cpp | 2 +- src/core/meshcop/joiner.cpp | 2 +- src/core/net/dhcp6_client.cpp | 2 +- src/core/net/dns_headers.cpp | 2 +- src/core/radio/trel_link.cpp | 2 +- src/core/thread/announce_sender.cpp | 2 +- src/core/thread/csl_tx_scheduler.cpp | 3 +- src/core/thread/discover_scanner.cpp | 2 +- src/core/thread/dua_manager.cpp | 3 +- src/core/thread/link_quality.cpp | 6 +- src/core/thread/lowpan.cpp | 4 +- src/core/thread/mesh_forwarder.cpp | 2 +- src/core/thread/mle.cpp | 6 +- src/core/thread/mle_router.cpp | 9 +- src/core/utils/channel_manager.cpp | 2 +- src/lib/spinel/spinel_buffer.cpp | 3 +- src/ncp/ncp_base_ftd.cpp | 8 +- src/ncp/ncp_base_mtd.cpp | 3 +- src/ncp/ncp_spi.cpp | 2 +- src/ncp/ncp_uart.cpp | 4 +- 34 files changed, 910 insertions(+), 41 deletions(-) create mode 100644 Android.bp create mode 100644 etc/android/openthread-config-android-version.h.in create mode 100755 script/config-android-version-gen.sh diff --git a/Android.bp b/Android.bp new file mode 100644 index 000000000..bcb812a03 --- /dev/null +++ b/Android.bp @@ -0,0 +1,707 @@ +// +// Copyright (c) 2021, The OpenThread Authors. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. Neither the name of the copyright holder nor the +// names of its contributors may be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// + +cc_defaults { + name : "ot_cflags_defaults", + cflags: [ + "-DOPENTHREAD_CONFIG_COMMISSIONER_ENABLE=1", + "-DOPENTHREAD_CONFIG_IP6_SLAAC_ENABLE=1", + "-DOPENTHREAD_CONFIG_LOG_LEVEL_DYNAMIC_ENABLE=1", + "-DOPENTHREAD_CONFIG_MAC_FILTER_ENABLE=1", + "-DOPENTHREAD_POSIX_CONFIG_RCP_PTY_ENABLE=1", + "-DOPENTHREAD_FTD=1", + "-DOPENTHREAD_POSIX=1", + "-DOPENTHREAD_SPINEL_CONFIG_OPENTHREAD_MESSAGE_ENABLE=1", + "-DOPENTHREAD_CONFIG_ANDROID_VERSION_HEADER_ENABLE=1", + "-DPACKAGE=\"openthread\"", + "-DPACKAGE_BUGREPORT=\"openthread-devel@googlegroups.com\"", + "-DPACKAGE_NAME=\"OPENTHREAD\"", + "-DPACKAGE_TARNAME=\"openthread\"", + "-DPACKAGE_URL=\"http://github.com/openthread/openthread\"", + "-DMBEDTLS_CONFIG_FILE=\"mbedtls-config.h\"", + "-DSPINEL_PLATFORM_HEADER=\"spinel_platform.h\"", + ], +} + +soong_config_module_type { + name: "ot_android_bp_cc_defaults", + module_type: "cc_defaults", + config_namespace: "openthread", + bool_variables: ["enable_android_bp", "disable_android_bp"], + properties: ["enabled"], +} + +ot_android_bp_cc_defaults { + name: "ot_android_bp_defaults", + soong_config_variables: { + enable_android_bp: { + enabled: true, + }, + disable_android_bp: { + enabled: false, + }, + }, +} + +genrule { + name: "ot_version_header", + cmd: "$(location script/config-android-version-gen.sh) $(location .default-version) < $(in) > $(out)", + srcs: ["etc/android/openthread-config-android-version.h.in"], + out: ["openthread-config-android-version.h"], + tool_files: [ + "script/config-android-version-gen.sh", + ".default-version", + ], +} + +soong_config_module_type { + name: "ot_config_cc_defaults", + module_type: "cc_defaults", + config_namespace: "openthread", + bool_variables: ["daemon", "diag", "default_config_file"], + value_variables: ["project_core_config_file", "config_file", "config_file_local_include_dir"], + variables: ["rcp_bus"], + properties: ["cflags", "local_include_dirs"], +} + +soong_config_string_variable { + name: "rcp_bus", + values: ["spi", "uart"], +} + +ot_config_cc_defaults { + name: "ot_config_defaults", + soong_config_variables: { + daemon: { + cflags: [ + "-DOPENTHREAD_CONFIG_PLATFORM_NETIF_ENABLE=1", + "-DOPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE=1", + "-DOPENTHREAD_CONFIG_UNSECURE_TRAFFIC_MANAGED_BY_STACK_ENABLE=1", + "-DOPENTHREAD_POSIX_CONFIG_DAEMON_ENABLE=1" + ], + }, + diag: { + cflags: ["-DOPENTHREAD_CONFIG_DIAG_ENABLE=1"], + }, + rcp_bus: { + spi: { + cflags: ["-DOPENTHREAD_POSIX_CONFIG_RCP_BUS=OT_POSIX_RCP_BUS_SPI"], + }, + uart: { + cflags: ["-DOPENTHREAD_POSIX_CONFIG_RCP_BUS=OT_POSIX_RCP_BUS_UART"], + }, + }, + project_core_config_file: { + cflags: ["-DOPENTHREAD_PROJECT_CORE_CONFIG_FILE=%s"], + }, + config_file: { + cflags: ["-DOPENTHREAD_CONFIG_FILE=%s"], + }, + config_file_local_include_dir: { + local_include_dirs: ["%s"], + }, + default_config_file: { + cflags: [ + "-DOPENTHREAD_PROJECT_CORE_CONFIG_FILE=\"openthread-core-posix-config.h\"", + "-DOPENTHREAD_CONFIG_FILE=\"openthread-config-android.h\"", + ], + }, + }, +} + +soong_config_module_type { + name: "ot_vendor_extension_cc_defaults", + module_type: "cc_defaults", + config_namespace: "openthread", + bool_variables: ["enable_vendor_extension"], + value_variables: ["vendor_extension_local_include_dir", "vendor_extension_src"], + properties: ["cflags", "srcs", "local_include_dirs"], +} + +ot_vendor_extension_cc_defaults { + name: "ot_vendor_extension_defaults", + soong_config_variables: { + enable_vendor_extension: { + cflags: ["-DOPENTHREAD_ENABLE_VENDOR_EXTENSION=1"], + }, + vendor_extension_local_include_dir: { + local_include_dirs: ["%s"], + }, + vendor_extension_src: { + srcs: ["%s"], + }, + }, +} + +cc_library_static { + name: "ot-core", + vendor_available: true, + host_supported: true, + defaults: ["ot_android_bp_defaults", "ot_cflags_defaults", "ot_config_defaults", "ot_vendor_extension_defaults"], + generated_headers: ["ot_version_header"], + + local_include_dirs: [ + "include", + "src", + "src/cli", + "src/core", + "src/ncp", + "src/posix/platform", + "src/posix/platform/include", + "third_party", + "third_party/mbedtls", + "third_party/mbedtls/repo/include", + ], + + export_include_dirs: [ + "include", + "src", + ], + + cppflags: [ + "-std=c++11", + "-pedantic-errors", + ], + + shared_libs: [ + "libcutils", + ], + + srcs: [ + "src/core/api/backbone_router_api.cpp", + "src/core/api/backbone_router_ftd_api.cpp", + "src/core/api/border_router_api.cpp", + "src/core/api/channel_manager_api.cpp", + "src/core/api/channel_monitor_api.cpp", + "src/core/api/child_supervision_api.cpp", + "src/core/api/coap_api.cpp", + "src/core/api/commissioner_api.cpp", + "src/core/api/crypto_api.cpp", + "src/core/api/dataset_api.cpp", + "src/core/api/dataset_ftd_api.cpp", + "src/core/api/dataset_updater_api.cpp", + "src/core/api/diags_api.cpp", + "src/core/api/dns_api.cpp", + "src/core/api/icmp6_api.cpp", + "src/core/api/instance_api.cpp", + "src/core/api/ip6_api.cpp", + "src/core/api/jam_detection_api.cpp", + "src/core/api/joiner_api.cpp", + "src/core/api/link_api.cpp", + "src/core/api/link_metrics_api.cpp", + "src/core/api/link_raw_api.cpp", + "src/core/api/logging_api.cpp", + "src/core/api/message_api.cpp", + "src/core/api/multi_radio_api.cpp", + "src/core/api/netdata_api.cpp", + "src/core/api/netdiag_api.cpp", + "src/core/api/random_crypto_api.cpp", + "src/core/api/random_noncrypto_api.cpp", + "src/core/api/server_api.cpp", + "src/core/api/tasklet_api.cpp", + "src/core/api/thread_api.cpp", + "src/core/api/thread_ftd_api.cpp", + "src/core/api/udp_api.cpp", + "src/core/backbone_router/backbone_tmf.cpp", + "src/core/backbone_router/bbr_leader.cpp", + "src/core/backbone_router/bbr_local.cpp", + "src/core/backbone_router/bbr_manager.cpp", + "src/core/backbone_router/multicast_listeners_table.cpp", + "src/core/backbone_router/ndproxy_table.cpp", + "src/core/border_router/infra_if_platform.cpp", + "src/core/border_router/router_advertisement.cpp", + "src/core/border_router/routing_manager.cpp", + "src/core/coap/coap.cpp", + "src/core/coap/coap_message.cpp", + "src/core/coap/coap_secure.cpp", + "src/core/common/crc16.cpp", + "src/core/common/instance.cpp", + "src/core/common/logging.cpp", + "src/core/common/message.cpp", + "src/core/common/notifier.cpp", + "src/core/common/random_manager.cpp", + "src/core/common/settings.cpp", + "src/core/common/string.cpp", + "src/core/common/tasklet.cpp", + "src/core/common/time_ticker.cpp", + "src/core/common/timer.cpp", + "src/core/common/tlvs.cpp", + "src/core/common/trickle_timer.cpp", + "src/core/crypto/aes_ccm.cpp", + "src/core/crypto/aes_ecb.cpp", + "src/core/crypto/ecdsa.cpp", + "src/core/crypto/hkdf_sha256.cpp", + "src/core/crypto/hmac_sha256.cpp", + "src/core/crypto/mbedtls.cpp", + "src/core/crypto/pbkdf2_cmac.cpp", + "src/core/crypto/sha256.cpp", + "src/core/diags/factory_diags.cpp", + "src/core/mac/channel_mask.cpp", + "src/core/mac/data_poll_handler.cpp", + "src/core/mac/data_poll_sender.cpp", + "src/core/mac/mac.cpp", + "src/core/mac/mac_filter.cpp", + "src/core/mac/mac_frame.cpp", + "src/core/mac/mac_links.cpp", + "src/core/mac/mac_types.cpp", + "src/core/mac/sub_mac.cpp", + "src/core/mac/sub_mac_callbacks.cpp", + "src/core/meshcop/announce_begin_client.cpp", + "src/core/meshcop/border_agent.cpp", + "src/core/meshcop/commissioner.cpp", + "src/core/meshcop/dataset.cpp", + "src/core/meshcop/dataset_local.cpp", + "src/core/meshcop/dataset_manager.cpp", + "src/core/meshcop/dataset_manager_ftd.cpp", + "src/core/meshcop/dtls.cpp", + "src/core/meshcop/energy_scan_client.cpp", + "src/core/meshcop/joiner.cpp", + "src/core/meshcop/joiner_router.cpp", + "src/core/meshcop/meshcop.cpp", + "src/core/meshcop/meshcop_leader.cpp", + "src/core/meshcop/meshcop_tlvs.cpp", + "src/core/meshcop/panid_query_client.cpp", + "src/core/meshcop/timestamp.cpp", + "src/core/net/checksum.cpp", + "src/core/net/dhcp6_client.cpp", + "src/core/net/dhcp6_server.cpp", + "src/core/net/dns_client.cpp", + "src/core/net/dns_headers.cpp", + "src/core/net/icmp6.cpp", + "src/core/net/ip6.cpp", + "src/core/net/ip6_address.cpp", + "src/core/net/ip6_filter.cpp", + "src/core/net/ip6_headers.cpp", + "src/core/net/ip6_mpl.cpp", + "src/core/net/netif.cpp", + "src/core/net/udp6.cpp", + "src/core/radio/radio.cpp", + "src/core/radio/radio_callbacks.cpp", + "src/core/radio/radio_platform.cpp", + "src/core/radio/trel_interface.cpp", + "src/core/radio/trel_link.cpp", + "src/core/radio/trel_packet.cpp", + "src/core/thread/address_resolver.cpp", + "src/core/thread/announce_begin_server.cpp", + "src/core/thread/announce_sender.cpp", + "src/core/thread/child_table.cpp", + "src/core/thread/csl_tx_scheduler.cpp", + "src/core/thread/discover_scanner.cpp", + "src/core/thread/dua_manager.cpp", + "src/core/thread/energy_scan_server.cpp", + "src/core/thread/indirect_sender.cpp", + "src/core/thread/key_manager.cpp", + "src/core/thread/link_metrics.cpp", + "src/core/thread/link_quality.cpp", + "src/core/thread/lowpan.cpp", + "src/core/thread/mesh_forwarder.cpp", + "src/core/thread/mesh_forwarder_ftd.cpp", + "src/core/thread/mesh_forwarder_mtd.cpp", + "src/core/thread/mle.cpp", + "src/core/thread/mle_router.cpp", + "src/core/thread/mle_types.cpp", + "src/core/thread/mlr_manager.cpp", + "src/core/thread/neighbor_table.cpp", + "src/core/thread/network_data.cpp", + "src/core/thread/network_data_leader.cpp", + "src/core/thread/network_data_leader_ftd.cpp", + "src/core/thread/network_data_local.cpp", + "src/core/thread/network_data_notifier.cpp", + "src/core/thread/network_diagnostic.cpp", + "src/core/thread/panid_query_server.cpp", + "src/core/thread/radio_selector.cpp", + "src/core/thread/router_table.cpp", + "src/core/thread/src_match_controller.cpp", + "src/core/thread/thread_netif.cpp", + "src/core/thread/tmf.cpp", + "src/core/thread/topology.cpp", + "src/core/thread/uri_paths.cpp", + "src/core/utils/channel_manager.cpp", + "src/core/utils/channel_monitor.cpp", + "src/core/utils/child_supervision.cpp", + "src/core/utils/dataset_updater.cpp", + "src/core/utils/heap.cpp", + "src/core/utils/jam_detector.cpp", + "src/core/utils/lookup_table.cpp", + "src/core/utils/parse_cmdline.cpp", + "src/core/utils/slaac_address.cpp", + "src/lib/hdlc/hdlc.cpp", + "src/lib/platform/exit_code.c", + "src/lib/spinel/spinel.c", + "src/lib/spinel/spinel_decoder.cpp", + "src/lib/spinel/spinel_encoder.cpp", + "src/lib/url/url.cpp", + "src/posix/platform/alarm.cpp", + "src/posix/platform/backbone.cpp", + "src/posix/platform/entropy.cpp", + "src/posix/platform/hdlc_interface.cpp", + "src/posix/platform/logging.cpp", + "src/posix/platform/misc.cpp", + "src/posix/platform/multicast_routing.cpp", + "src/posix/platform/netif.cpp", + "src/posix/platform/radio.cpp", + "src/posix/platform/radio_url.cpp", + "src/posix/platform/settings.cpp", + "src/posix/platform/spi_interface.cpp", + "src/posix/platform/system.cpp", + "src/posix/platform/uart.cpp", + "src/posix/platform/udp.cpp", + "third_party/mbedtls/repo/library/aes.c", + "third_party/mbedtls/repo/library/asn1parse.c", + "third_party/mbedtls/repo/library/asn1write.c", + "third_party/mbedtls/repo/library/base64.c", + "third_party/mbedtls/repo/library/bignum.c", + "third_party/mbedtls/repo/library/ccm.c", + "third_party/mbedtls/repo/library/cipher.c", + "third_party/mbedtls/repo/library/cipher_wrap.c", + "third_party/mbedtls/repo/library/cmac.c", + "third_party/mbedtls/repo/library/ctr_drbg.c", + "third_party/mbedtls/repo/library/debug.c", + "third_party/mbedtls/repo/library/ecdh.c", + "third_party/mbedtls/repo/library/ecdsa.c", + "third_party/mbedtls/repo/library/ecjpake.c", + "third_party/mbedtls/repo/library/ecp.c", + "third_party/mbedtls/repo/library/ecp_curves.c", + "third_party/mbedtls/repo/library/entropy.c", + "third_party/mbedtls/repo/library/entropy_poll.c", + "third_party/mbedtls/repo/library/hmac_drbg.c", + "third_party/mbedtls/repo/library/md.c", + "third_party/mbedtls/repo/library/md_wrap.c", + "third_party/mbedtls/repo/library/memory_buffer_alloc.c", + "third_party/mbedtls/repo/library/oid.c", + "third_party/mbedtls/repo/library/pem.c", + "third_party/mbedtls/repo/library/pk.c", + "third_party/mbedtls/repo/library/pk_wrap.c", + "third_party/mbedtls/repo/library/pkparse.c", + "third_party/mbedtls/repo/library/pkwrite.c", + "third_party/mbedtls/repo/library/platform.c", + "third_party/mbedtls/repo/library/platform_util.c", + "third_party/mbedtls/repo/library/sha256.c", + "third_party/mbedtls/repo/library/ssl_ciphersuites.c", + "third_party/mbedtls/repo/library/ssl_cli.c", + "third_party/mbedtls/repo/library/ssl_cookie.c", + "third_party/mbedtls/repo/library/ssl_srv.c", + "third_party/mbedtls/repo/library/ssl_ticket.c", + "third_party/mbedtls/repo/library/ssl_tls.c", + "third_party/mbedtls/repo/library/threading.c", + "third_party/mbedtls/repo/library/x509.c", + "third_party/mbedtls/repo/library/x509_crt.c", + ], +} + +cc_library_static { + name: "libopenthread-cli", + vendor_available: true, + host_supported: true, + + defaults: ["ot_android_bp_defaults", "ot_cflags_defaults", "ot_config_defaults"], + generated_headers: ["ot_version_header"], + + local_include_dirs: [ + "include", + "src", + "src/cli", + "src/core", + "src/posix/platform", + "src/posix/platform/include", + "third_party/mbedtls", + "third_party/mbedtls/repo/include", + ], + + cflags: ["-DOPENTHREAD_CONFIG_UART_CLI_RAW=1"], + + cppflags: [ + "-std=c++11", + "-pedantic-errors", + ], + + srcs: [ + "src/cli/cli.cpp", + "src/cli/cli_coap.cpp", + "src/cli/cli_coap_secure.cpp", + "src/cli/cli_commissioner.cpp", + "src/cli/cli_console.cpp", + "src/cli/cli_dataset.cpp", + "src/cli/cli_joiner.cpp", + "src/cli/cli_network_data.cpp", + "src/cli/cli_uart.cpp", + "src/cli/cli_udp.cpp", + ], +} + +cc_binary { + name: "ot-cli", + vendor: true, + + defaults: ["ot_android_bp_defaults", "ot_cflags_defaults", "ot_config_defaults"], + generated_headers: ["ot_version_header"], + + local_include_dirs: [ + "include", + "src", + "src/cli", + "src/core", + "src/posix/platform", + "src/posix/platform/include", + "third_party/mbedtls", + "third_party/mbedtls/repo/include", + ], + + cflags: ["-DOPENTHREAD_POSIX_APP_TYPE=OT_POSIX_APP_TYPE_CLI"], + + cppflags: [ + "-std=c++11", + "-pedantic-errors", + ], + + host_ldlibs: [ + "-lrt", + "-lutil", + ], + + srcs: ["src/posix/main.c"], + + static_libs: [ + "libopenthread-cli", + "ot-core", + ], +} + +cc_library_static { + name: "libopenthread-ncp", + vendor_available: true, + host_supported: true, + + defaults: ["ot_android_bp_defaults", "ot_cflags_defaults", "ot_config_defaults"], + generated_headers: ["ot_version_header"], + + local_include_dirs: [ + "include", + "src", + "src/core", + "src/ncp", + "src/posix/platform", + "src/posix/platform/include", + "third_party/mbedtls", + "third_party/mbedtls/repo/include", + ], + + cppflags: [ + "-std=c++11", + "-pedantic-errors", + ], + + srcs: [ + "src/lib/spinel/spinel_buffer.cpp", + "src/ncp/changed_props_set.cpp", + "src/ncp/ncp_base.cpp", + "src/ncp/ncp_base_mtd.cpp", + "src/ncp/ncp_base_ftd.cpp", + "src/ncp/ncp_base_dispatcher.cpp", + "src/ncp/ncp_uart.cpp", + ], +} + +cc_binary { + name: "ot-ncp", + vendor: true, + + defaults: ["ot_android_bp_defaults", "ot_cflags_defaults", "ot_config_defaults"], + generated_headers: ["ot_version_header"], + + local_include_dirs: [ + "include", + "src", + "src/core", + "src/ncp", + "src/posix/platform", + "src/posix/platform/include", + "third_party/mbedtls", + "third_party/mbedtls/repo/include", + ], + + cflags: ["-DOPENTHREAD_POSIX_APP_TYPE=OT_POSIX_APP_TYPE_NCP"], + + cppflags: [ + "-std=c++11", + "-pedantic-errors", + ], + + srcs: [ + "src/posix/main.c"], + + host_ldlibs: [ + "-lrt", + "-lutil", + ], + + static_libs: [ + "libopenthread-ncp", + "ot-core", + ], +} + +cc_binary { + name: "ot-ctl", + vendor: true, + + defaults: ["ot_android_bp_defaults", "ot_cflags_defaults", "ot_config_defaults"], + generated_headers: ["ot_version_header"], + + cppflags: [ + "-std=c++11", + "-pedantic-errors", + ], + + local_include_dirs: [ + "include", + "src/", + "src/core", + "src/posix/platform", + "src/posix/platform/include", + ], + + srcs: ["src/posix/client.cpp"], +} + +cc_binary { + name: "ot-rcp", + vendor: true, + + defaults: ["ot_android_bp_defaults"], + generated_headers: ["ot_version_header"], + + local_include_dirs: [ + "include", + "src", + "src/core", + "src/ncp", + "src/lib/hdlc", + "src/lib/platform", + "src/lib/spinel", + "examples/platforms", + "examples/platforms/simulation", + "third_party", + "third_party/mbedtls", + "third_party/mbedtls/repo/include", + ], + + cflags: [ + "-DOPENTHREAD_MTD=0", + "-DOPENTHREAD_FTD=0", + "-DOPENTHREAD_RADIO=1", + "-DOPENTHREAD_SPINEL_CONFIG_OPENTHREAD_MESSAGE_ENABLE=0", + "-DOPENTHREAD_EXAMPLES_SIMULATION=1", + "-D_GNU_SOURCE", + "-DSPINEL_PLATFORM_HEADER=\"spinel_platform.h\"", + "-DOPENTHREAD_PROJECT_CORE_CONFIG_FILE=\"openthread-core-simulation-config.h\"", + "-DOPENTHREAD_CONFIG_ANDROID_VERSION_HEADER_ENABLE=1", + "-DOPENTHREAD_CONFIG_FILE=", + "-DPACKAGE=\"openthread\"", + "-DPACKAGE_BUGREPORT=\"openthread-devel@googlegroups.com\"", + "-DPACKAGE_NAME=\"OPENTHREAD\"", + "-DPACKAGE_TARNAME=\"openthread\"", + "-DPACKAGE_URL=\"http://github.com/openthread/openthread\"", + ], + + cppflags: [ + "-std=c++11", + "-pedantic-errors", + ], + + host_ldlibs: [ + "-lrt", + "-lutil", + ], + + shared_libs: [ + "libcutils", + ], + + srcs: [ + "examples/apps/ncp/main.c", + "examples/platforms/utils/debug_uart.c", + "examples/platforms/utils/mac_frame.cpp", + "examples/platforms/utils/settings_ram.c", + "examples/platforms/utils/soft_source_match_table.c", + "examples/platforms/simulation/alarm.c", + "examples/platforms/simulation/diag.c", + "examples/platforms/simulation/entropy.c", + "examples/platforms/simulation/flash.c", + "examples/platforms/simulation/logging.c", + "examples/platforms/simulation/misc.c", + "examples/platforms/simulation/radio.c", + "examples/platforms/simulation/spi-stubs.c", + "examples/platforms/simulation/system.c", + "examples/platforms/simulation/uart.c", + "examples/platforms/simulation/virtual_time/alarm-sim.c", + "examples/platforms/simulation/virtual_time/platform-sim.c", + "src/core/api/diags_api.cpp", + "src/core/api/heap_api.cpp", + "src/core/api/instance_api.cpp", + "src/core/api/link_raw_api.cpp", + "src/core/api/logging_api.cpp", + "src/core/api/random_noncrypto_api.cpp", + "src/core/api/tasklet_api.cpp", + "src/core/common/instance.cpp", + "src/core/common/logging.cpp", + "src/core/common/random_manager.cpp", + "src/core/common/string.cpp", + "src/core/common/tasklet.cpp", + "src/core/common/timer.cpp", + "src/core/crypto/aes_ccm.cpp", + "src/core/crypto/aes_ecb.cpp", + "src/core/diags/factory_diags.cpp", + "src/core/mac/link_raw.cpp", + "src/core/mac/mac_frame.cpp", + "src/core/mac/mac_types.cpp", + "src/core/mac/sub_mac.cpp", + "src/core/mac/sub_mac_callbacks.cpp", + "src/core/radio/radio.cpp", + "src/core/radio/radio_callbacks.cpp", + "src/core/radio/radio_platform.cpp", + "src/core/thread/link_quality.cpp", + "src/core/utils/lookup_table.cpp", + "src/core/utils/parse_cmdline.cpp", + "src/lib/hdlc/hdlc.cpp", + "src/lib/platform/exit_code.c", + "src/lib/spinel/spinel.c", + "src/lib/spinel/spinel_buffer.cpp", + "src/lib/spinel/spinel_decoder.cpp", + "src/lib/spinel/spinel_encoder.cpp", + "src/ncp/changed_props_set.cpp", + "src/ncp/ncp_base.cpp", + "src/ncp/ncp_base_ftd.cpp", + "src/ncp/ncp_base_mtd.cpp", + "src/ncp/ncp_base_radio.cpp", + "src/ncp/ncp_base_dispatcher.cpp", + "src/ncp/ncp_spi.cpp", + "src/ncp/ncp_uart.cpp", + ], +} + diff --git a/Android.mk b/Android.mk index 5f21c5f32..d11dde674 100644 --- a/Android.mk +++ b/Android.mk @@ -28,6 +28,8 @@ LOCAL_PATH := $(call my-dir) +ifeq ($(OPENTHREAD_ENABLE_ANDROID_MK),1) + OPENTHREAD_DEFAULT_VERSION := $(shell cat $(LOCAL_PATH)/.default-version) OPENTHREAD_SOURCE_VERSION := $(shell git -C $(LOCAL_PATH) describe --always --match "[0-9].*" 2> /dev/null) @@ -145,6 +147,14 @@ LOCAL_CPPFLAGS := \ -pedantic-errors \ $(NULL) +ifeq ($(ANDROID_NDK),1) +LOCAL_SHARED_LIBRARIES := libcutils + +LOCAL_CFLAGS += \ + -DOPENTHREAD_ENABLE_ANDROID_NDK=1 \ + $(NULL) +endif + LOCAL_SRC_FILES := \ src/core/api/backbone_router_api.cpp \ src/core/api/backbone_router_ftd_api.cpp \ @@ -569,3 +579,5 @@ endif # ($(USE_OTBR_DAEMON), 1) ifneq ($(OPENTHREAD_PROJECT_ANDROID_MK),) include $(OPENTHREAD_PROJECT_ANDROID_MK) endif + +endif # ($(OPENTHREAD_ENABLE_ANDROID_MK),1) diff --git a/etc/android/openthread-config-android-version.h.in b/etc/android/openthread-config-android-version.h.in new file mode 100644 index 000000000..e96beddd5 --- /dev/null +++ b/etc/android/openthread-config-android-version.h.in @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2021, The OpenThread Authors. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @def PACKAGE_VERSION + * + * The source code version string to insert into the OpenThread version string. + * + */ +#define PACKAGE_VERSION "@OPENTHREAD_SOURCE_VERSION@" diff --git a/include/openthread-config-android.h b/include/openthread-config-android.h index c18df2358..10f7abf41 100644 --- a/include/openthread-config-android.h +++ b/include/openthread-config-android.h @@ -26,6 +26,10 @@ * POSSIBILITY OF SUCH DAMAGE. */ +#ifdef OPENTHREAD_CONFIG_ANDROID_VERSION_HEADER_ENABLE +#include +#endif + /* Define to 1 to enable the border agent feature. */ #define OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE 1 diff --git a/include/openthread/instance.h b/include/openthread/instance.h index 25a505876..22e887fdf 100644 --- a/include/openthread/instance.h +++ b/include/openthread/instance.h @@ -53,7 +53,7 @@ extern "C" { * @note This number versions both OpenThread platform and user APIs. * */ -#define OPENTHREAD_API_VERSION (60) +#define OPENTHREAD_API_VERSION (61) /** * @addtogroup api-instance diff --git a/include/openthread/platform/toolchain.h b/include/openthread/platform/toolchain.h index c1f3a003c..56109852d 100644 --- a/include/openthread/platform/toolchain.h +++ b/include/openthread/platform/toolchain.h @@ -257,6 +257,25 @@ extern "C" { #define OT_APPLE_IGNORE_GNU_FOLDING_CONSTANT(...) __VA_ARGS__ #endif +/** + * @def OT_FALL_THROUGH + * + * Suppress fall through warning in specific compiler. + * + */ +#if defined(__cplusplus) && (__cplusplus >= 201703L) +#define OT_FALL_THROUGH [[fallthrough]] +#elif defined(__clang__) +#define OT_FALL_THROUGH [[clang::fallthrough]] +#elif defined(__GNUC__) && (__GNUC__ >= 7) +#define OT_FALL_THROUGH __attribute__((fallthrough)) +#else +#define OT_FALL_THROUGH \ + do \ + { \ + } while (false) /* fallthrough */ +#endif + /** * @} * diff --git a/script/check-android-build b/script/check-android-build index 5acc0382b..790cbefa0 100755 --- a/script/check-android-build +++ b/script/check-android-build @@ -47,8 +47,8 @@ check_targets() main() { - USE_OTBR_DAEMON=1 check_targets ot-cli ot-ctl ot-ncp - check_targets ot-cli ot-ncp spi-hdlc-adapter + OPENTHREAD_ENABLE_ANDROID_MK=1 ANDROID_NDK=1 USE_OTBR_DAEMON=1 check_targets ot-cli ot-ctl ot-ncp + OPENTHREAD_ENABLE_ANDROID_MK=1 ANDROID_NDK=1 check_targets ot-cli ot-ncp spi-hdlc-adapter } main "$@" diff --git a/script/config-android-version-gen.sh b/script/config-android-version-gen.sh new file mode 100755 index 000000000..4d19459d7 --- /dev/null +++ b/script/config-android-version-gen.sh @@ -0,0 +1,52 @@ +#!/bin/bash +# +# Copyright (c) 2021, The OpenThread Authors. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. Neither the name of the copyright holder nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +# Description: +# This script generates the openthread version header file needed by Android.bp. +# + +set -euo pipefail + +main() +{ + if [[ $# -ne 1 ]]; then + echo >&2 "Usage: $0 .default-version " \ + "< etc/android/openthread-config-android-version.h.in > openthread-config-android-version.h" + exit 1 + fi + + OPENTHREAD_DEFAULT_VERSION_FILE="$1" + OPENTHREAD_SRC_PATH=$(dirname "${OPENTHREAD_DEFAULT_VERSION_FILE}") + OPENTHREAD_DEFAULT_VERSION=$(cat "${OPENTHREAD_DEFAULT_VERSION_FILE}") + OPENTHREAD_SOURCE_VERSION=$("${OPENTHREAD_SRC_PATH}"/third_party/nlbuild-autotools/repo/scripts/mkversion -b "${OPENTHREAD_DEFAULT_VERSION}" "${OPENTHREAD_SRC_PATH}") + + sed -e s/@OPENTHREAD_SOURCE_VERSION@/"${OPENTHREAD_SOURCE_VERSION}"/ +} + +main "$@" diff --git a/src/core/api/instance_api.cpp b/src/core/api/instance_api.cpp index 2ee10831d..e6482d581 100644 --- a/src/core/api/instance_api.cpp +++ b/src/core/api/instance_api.cpp @@ -42,6 +42,14 @@ #include "common/new.hpp" #include "radio/radio.hpp" +#ifdef __ANDROID__ +#ifdef OPENTHREAD_ENABLE_ANDROID_NDK +#include +#else +#include +#endif +#endif + using namespace ot; #if OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE @@ -134,6 +142,24 @@ const char *otGetVersionString(void) * image will be undefined and may change. */ +#ifdef __ANDROID__ + +#ifdef OPENTHREAD_ENABLE_ANDROID_NDK + static char sVersion[100 + PROP_VALUE_MAX]; + char dateTime[PROP_VALUE_MAX]; + + __system_property_get("ro.build.date", dateTime); +#else + static char sVersion[100 + PROPERTY_VALUE_MAX]; + char dateTime[PROPERTY_VALUE_MAX]; + + property_get("ro.build.date", dateTime, "Thu Jan 1 1970 UTC 00:00:00"); +#endif + + snprintf(sVersion, sizeof(sVersion), "%s/%s ;%s ; %s", PACKAGE_NAME, PACKAGE_VERSION, + OPENTHREAD_CONFIG_PLATFORM_INFO, dateTime); +#else + #ifdef PLATFORM_VERSION_ATTR_PREFIX PLATFORM_VERSION_ATTR_PREFIX #else @@ -148,6 +174,8 @@ const char *otGetVersionString(void) #endif ; // Trailing semicolon to end statement. +#endif + return sVersion; } diff --git a/src/core/coap/coap.cpp b/src/core/coap/coap.cpp index 48302ca64..9cce0523f 100644 --- a/src/core/coap/coap.cpp +++ b/src/core/coap/coap.cpp @@ -654,7 +654,8 @@ void CoapBase::ProcessReceivedResponse(Message &aMessage, const Ip6::MessageInfo case kTypeConfirmable: // Send empty ACK if it is a CON message. IgnoreError(SendAck(aMessage, aMessageInfo)); - // Fall through + + OT_FALL_THROUGH; // Handling of RFC7641 and multicast is below. case kTypeNonConfirmable: // Separate response or observation notification. If the request was to a multicast @@ -707,7 +708,7 @@ void CoapBase::ProcessReceivedRequest(Message &aMessage, const Ip6::MessageInfo cachedResponse->Finish(); error = Send(*cachedResponse, aMessageInfo); - // fall through + OT_FALL_THROUGH; case OT_ERROR_NO_BUFS: ExitNow(); diff --git a/src/core/mac/data_poll_handler.cpp b/src/core/mac/data_poll_handler.cpp index cc939b6b5..c4a4c9d9b 100644 --- a/src/core/mac/data_poll_handler.cpp +++ b/src/core/mac/data_poll_handler.cpp @@ -247,7 +247,7 @@ void DataPollHandler::HandleSentFrame(const Mac::TxFrame &aFrame, otError aError otLogInfoMac("Indirect tx to child %04x failed, attempt %d/%d", aChild.GetRloc16(), aChild.GetIndirectTxAttempts(), kMaxPollTriggeredTxAttempts); - // Fall through + OT_FALL_THROUGH; case OT_ERROR_CHANNEL_ACCESS_FAILURE: case OT_ERROR_ABORT: diff --git a/src/core/mac/mac.cpp b/src/core/mac/mac.cpp index de0a50a8b..9fffcde9a 100644 --- a/src/core/mac/mac.cpp +++ b/src/core/mac/mac.cpp @@ -1380,7 +1380,7 @@ void Mac::RecordFrameTransmitStatus(const TxFrame &aFrame, case OT_ERROR_NO_ACK: frameTxSuccess = false; - // Fall through + OT_FALL_THROUGH; case OT_ERROR_NONE: neighbor->GetLinkInfo().AddFrameTxStatus(frameTxSuccess); @@ -2024,7 +2024,7 @@ void Mac::HandleReceivedFrame(RxFrame *aFrame, otError aError) srcaddr.SetExtended(neighbor->GetExtAddress()); - // Fall through + OT_FALL_THROUGH; case Address::kTypeExtended: @@ -2084,7 +2084,7 @@ void Mac::HandleReceivedFrame(RxFrame *aFrame, otError aError) VerifyOrExit(mOperation == kOperationWaitingForData); - // Fall through + OT_FALL_THROUGH; case OT_ERROR_NONE: break; @@ -2160,7 +2160,7 @@ void Mac::HandleReceivedFrame(RxFrame *aFrame, otError aError) ExitNow(); } - // Fall through + OT_FALL_THROUGH; case kOperationEnergyScan: diff --git a/src/core/mac/sub_mac.cpp b/src/core/mac/sub_mac.cpp index dd27e7146..1facf3703 100644 --- a/src/core/mac/sub_mac.cpp +++ b/src/core/mac/sub_mac.cpp @@ -479,7 +479,7 @@ void SubMac::HandleTransmitDone(TxFrame &aFrame, RxFrame *aAckFrame, otError aEr case OT_ERROR_CHANNEL_ACCESS_FAILURE: ccaSuccess = false; - // fall through + OT_FALL_THROUGH; case OT_ERROR_NONE: case OT_ERROR_NO_ACK: diff --git a/src/core/meshcop/dataset_manager.cpp b/src/core/meshcop/dataset_manager.cpp index 5403cf2b3..820cd42b6 100644 --- a/src/core/meshcop/dataset_manager.cpp +++ b/src/core/meshcop/dataset_manager.cpp @@ -313,7 +313,7 @@ exit: case OT_ERROR_NO_BUFS: mTimer.Start(kDelayNoBufs); - // fall through + OT_FALL_THROUGH; default: LogError("send Dataset set to leader", error); diff --git a/src/core/meshcop/dataset_manager_ftd.cpp b/src/core/meshcop/dataset_manager_ftd.cpp index 02affdd23..b861fed99 100644 --- a/src/core/meshcop/dataset_manager_ftd.cpp +++ b/src/core/meshcop/dataset_manager_ftd.cpp @@ -223,7 +223,7 @@ otError DatasetManager::HandleSet(Coap::Message &aMessage, const Ip6::MessageInf } } - // fall through + OT_FALL_THROUGH; default: SuccessOrExit(dataset.SetTlv(datasetTlv)); diff --git a/src/core/meshcop/joiner.cpp b/src/core/meshcop/joiner.cpp index 349a4c68d..c67fee20d 100644 --- a/src/core/meshcop/joiner.cpp +++ b/src/core/meshcop/joiner.cpp @@ -217,7 +217,7 @@ void Joiner::Finish(otError aError) IgnoreError(Get().RemoveUnsecurePort(kJoinerUdpPort)); mTimer.Stop(); - // Fall through + OT_FALL_THROUGH; case kStateDiscover: Get().Stop(); diff --git a/src/core/net/dhcp6_client.cpp b/src/core/net/dhcp6_client.cpp index 6fe9c83d9..43e268c48 100644 --- a/src/core/net/dhcp6_client.cpp +++ b/src/core/net/dhcp6_client.cpp @@ -231,7 +231,7 @@ bool Client::HandleTrickleTimer(void) mStartTime = TimerMilli::GetNow(); mIdentityAssociationCurrent->mStatus = kIaStatusSoliciting; - // fall through + OT_FALL_THROUGH; case kIaStatusSoliciting: Solicit(mIdentityAssociationCurrent->mPrefixAgentRloc); diff --git a/src/core/net/dns_headers.cpp b/src/core/net/dns_headers.cpp index 83cd0fc02..7ecb0a90d 100644 --- a/src/core/net/dns_headers.cpp +++ b/src/core/net/dns_headers.cpp @@ -282,7 +282,7 @@ otError Name::ReadName(const Message &aMessage, aOffset = iterator.mNameEndOffset; error = OT_ERROR_NONE; - // Fall through + OT_FALL_THROUGH; default: ExitNow(); diff --git a/src/core/radio/trel_link.cpp b/src/core/radio/trel_link.cpp index 2d935f479..6349c13ea 100644 --- a/src/core/radio/trel_link.cpp +++ b/src/core/radio/trel_link.cpp @@ -284,7 +284,7 @@ void Link::HandleTimer(void) case Mle::kRoleChild: HandleTimer(Get().GetParent()); - // Fall through + OT_FALL_THROUGH; case Mle::kRoleRouter: case Mle::kRoleLeader: diff --git a/src/core/thread/announce_sender.cpp b/src/core/thread/announce_sender.cpp index f8b549577..10218ab18 100644 --- a/src/core/thread/announce_sender.cpp +++ b/src/core/thread/announce_sender.cpp @@ -142,7 +142,7 @@ void AnnounceSender::CheckState(void) } #endif - // fall through + OT_FALL_THROUGH; case Mle::kRoleDisabled: case Mle::kRoleDetached: diff --git a/src/core/thread/csl_tx_scheduler.cpp b/src/core/thread/csl_tx_scheduler.cpp index 613003e93..8b8f0e763 100644 --- a/src/core/thread/csl_tx_scheduler.cpp +++ b/src/core/thread/csl_tx_scheduler.cpp @@ -254,7 +254,8 @@ void CslTxScheduler::HandleSentFrame(const Mac::TxFrame &aFrame, otError aError, aChild.ResetCslTxAttempts(); } - // Fall through + OT_FALL_THROUGH; + case OT_ERROR_CHANNEL_ACCESS_FAILURE: case OT_ERROR_ABORT: diff --git a/src/core/thread/discover_scanner.cpp b/src/core/thread/discover_scanner.cpp index 3e5720ad4..1234558ae 100644 --- a/src/core/thread/discover_scanner.cpp +++ b/src/core/thread/discover_scanner.cpp @@ -234,7 +234,7 @@ void DiscoverScanner::HandleDiscoverComplete(void) mTimer.Stop(); Get().ResumeMessageTransmissions(); - // Fall through + OT_FALL_THROUGH; case kStateScanDone: Get().ClearTemporaryChannel(); diff --git a/src/core/thread/dua_manager.cpp b/src/core/thread/dua_manager.cpp index a9503a1c7..5ab918b4a 100644 --- a/src/core/thread/dua_manager.cpp +++ b/src/core/thread/dua_manager.cpp @@ -110,7 +110,8 @@ void DuaManager::HandleDomainPrefixUpdate(BackboneRouter::Leader::DomainPrefixSt // In case removed for some reason e.g. the kDuaInvalid response from PBBR forcely VerifyOrExit(!Get().HasUnicastAddress(GetDomainUnicastAddress())); - // fall through + OT_FALL_THROUGH; + case BackboneRouter::Leader::kDomainPrefixRefreshed: case BackboneRouter::Leader::kDomainPrefixAdded: { diff --git a/src/core/thread/link_quality.cpp b/src/core/thread/link_quality.cpp index e8a2ac1de..93b41934d 100644 --- a/src/core/thread/link_quality.cpp +++ b/src/core/thread/link_quality.cpp @@ -234,17 +234,17 @@ uint8_t LinkQualityInfo::CalculateLinkQuality(uint8_t aLinkMargin, uint8_t aLast case 0: threshold1 += kHysteresisThreshold; - // fall-through + OT_FALL_THROUGH; case 1: threshold2 += kHysteresisThreshold; - // fall-through + OT_FALL_THROUGH; case 2: threshold3 += kHysteresisThreshold; - // fall-through + OT_FALL_THROUGH; default: break; diff --git a/src/core/thread/lowpan.cpp b/src/core/thread/lowpan.cpp index 27e181dee..9194c3b70 100644 --- a/src/core/thread/lowpan.cpp +++ b/src/core/thread/lowpan.cpp @@ -350,7 +350,7 @@ otError Lowpan::Compress(Message & aMessage, hcCtl |= kHcNextHeader; break; } - // fall through + OT_FALL_THROUGH; default: SuccessOrExit(error = buf.Write(static_cast(ip6Header.GetNextHeader()))); @@ -439,7 +439,7 @@ otError Lowpan::Compress(Message & aMessage, error = Compress(aMessage, aMacSource, aMacDest, buf); - // fall through + OT_FALL_THROUGH; default: ExitNow(); diff --git a/src/core/thread/mesh_forwarder.cpp b/src/core/thread/mesh_forwarder.cpp index a1339feef..fed88d8bb 100644 --- a/src/core/thread/mesh_forwarder.cpp +++ b/src/core/thread/mesh_forwarder.cpp @@ -542,7 +542,7 @@ Mac::TxFrame *MeshForwarder::HandleFrameRequest(Mac::TxFrames &aTxFrames) // queue for it. The message would be then converted to a // direct tx. - // Fall through + OT_FALL_THROUGH; #endif default: diff --git a/src/core/thread/mle.cpp b/src/core/thread/mle.cpp index feaa4d6a6..47ed5171a 100644 --- a/src/core/thread/mle.cpp +++ b/src/core/thread/mle.cpp @@ -1726,7 +1726,7 @@ void Mle::HandleAttachTimer(void) break; } - // fall through + OT_FALL_THROUGH; case kAttachStateAnnounce: if (shouldAnnounce) @@ -1738,7 +1738,7 @@ void Mle::HandleAttachTimer(void) } } - // fall through + OT_FALL_THROUGH; case kAttachStateChildIdRequest: SetAttachState(kAttachStateIdle); @@ -3692,7 +3692,7 @@ void Mle::HandleChildUpdateResponse(const Message & aMessage, mRetrieveNewNetworkData = true; - // fall through + OT_FALL_THROUGH; case kRoleChild: // Source Address diff --git a/src/core/thread/mle_router.cpp b/src/core/thread/mle_router.cpp index ae1b03a80..1d4cff3fc 100644 --- a/src/core/thread/mle_router.cpp +++ b/src/core/thread/mle_router.cpp @@ -295,7 +295,8 @@ void MleRouter::HandleChildStart(AttachMode aMode) RemoveChildren(); } - // fall through + OT_FALL_THROUGH; + case kAttachBetter: if (HasChildren() && mPreviousPartitionIdRouter != mLeaderData.GetPartitionId()) { @@ -824,6 +825,8 @@ otError MleRouter::HandleLinkAccept(const Message & aMessage, case Neighbor::kStateInvalid: VerifyOrExit((mChallengeTimeout > 0) && (response == mChallenge), error = OT_ERROR_SECURITY); + OT_FALL_THROUGH; + case Neighbor::kStateValid: break; @@ -1360,7 +1363,7 @@ otError MleRouter::HandleAdvertisement(const Message & aMessage, mRouterSelectionJitterTimeout = 1 + Random::NonCrypto::GetUint8InRange(0, mRouterSelectionJitter); } - // fall through + OT_FALL_THROUGH; case kRoleLeader: router = mRouterTable.GetRouter(routerId); @@ -1737,7 +1740,7 @@ void MleRouter::HandleTimeTick(void) ExitNow(); } - // fall through + OT_FALL_THROUGH; case kRoleRouter: // verify path to leader diff --git a/src/core/utils/channel_manager.cpp b/src/core/utils/channel_manager.cpp index 888668271..9990090e1 100644 --- a/src/core/utils/channel_manager.cpp +++ b/src/core/utils/channel_manager.cpp @@ -121,7 +121,7 @@ void ChannelManager::StartDatasetUpdate(void) case OT_ERROR_INVALID_STATE: otLogInfoUtil("ChannelManager: Request to change to channel %d failed. Device is disabled", mChannel); - // Fall through + OT_FALL_THROUGH; default: mState = kStateIdle; diff --git a/src/lib/spinel/spinel_buffer.cpp b/src/lib/spinel/spinel_buffer.cpp index 93b198ba2..abaa2af93 100644 --- a/src/lib/spinel/spinel_buffer.cpp +++ b/src/lib/spinel/spinel_buffer.cpp @@ -717,8 +717,7 @@ uint8_t Buffer::OutFrameReadByte(void) switch (mReadState) { case kReadStateNotActive: - - // Fall through + OT_FALL_THROUGH; case kReadStateDone: diff --git a/src/ncp/ncp_base_ftd.cpp b/src/ncp/ncp_base_ftd.cpp index 72f6718e2..2d66b60d7 100644 --- a/src/ncp/ncp_base_ftd.cpp +++ b/src/ncp/ncp_base_ftd.cpp @@ -131,7 +131,9 @@ void NcpBase::HandleNeighborTableChanged(otNeighborTableEvent aEvent, const otNe { case OT_NEIGHBOR_TABLE_EVENT_CHILD_ADDED: command = SPINEL_CMD_PROP_VALUE_INSERTED; - // Fall through + + OT_FALL_THROUGH; + case OT_NEIGHBOR_TABLE_EVENT_CHILD_REMOVED: property = SPINEL_PROP_THREAD_CHILD_TABLE; VerifyOrExit(!aEntry.mInfo.mChild.mIsStateRestoring); @@ -139,7 +141,9 @@ void NcpBase::HandleNeighborTableChanged(otNeighborTableEvent aEvent, const otNe case OT_NEIGHBOR_TABLE_EVENT_ROUTER_ADDED: command = SPINEL_CMD_PROP_VALUE_INSERTED; - // Fall through + + OT_FALL_THROUGH; + case OT_NEIGHBOR_TABLE_EVENT_ROUTER_REMOVED: property = SPINEL_PROP_THREAD_NEIGHBOR_TABLE; break; diff --git a/src/ncp/ncp_base_mtd.cpp b/src/ncp/ncp_base_mtd.cpp index 77d0b0528..e4d0d3ccf 100644 --- a/src/ncp/ncp_base_mtd.cpp +++ b/src/ncp/ncp_base_mtd.cpp @@ -125,7 +125,8 @@ static uint8_t ExternalRoutePreferenceToFlagByte(int aPreference) break; case OT_ROUTE_PREFERENCE_MED: - // fall through + + OT_FALL_THROUGH; default: flags = SPINEL_ROUTE_PREFERENCE_MEDIUM; diff --git a/src/ncp/ncp_spi.cpp b/src/ncp/ncp_spi.cpp index aa044c58e..92009ea71 100644 --- a/src/ncp/ncp_spi.cpp +++ b/src/ncp/ncp_spi.cpp @@ -326,7 +326,7 @@ void NcpSpi::PrepareTxFrame(void) case kTxStateHandlingSendDone: mTxState = kTxStateIdle; - // Fall through + OT_FALL_THROUGH; // to next case to prepare the next frame (if any). case kTxStateIdle: diff --git a/src/ncp/ncp_uart.cpp b/src/ncp/ncp_uart.cpp index e5d0e1c03..4654efb68 100644 --- a/src/ncp/ncp_uart.cpp +++ b/src/ncp/ncp_uart.cpp @@ -158,6 +158,8 @@ void NcpUart::EncodeAndSendToUart(void) { mByte = txFrameBuffer.OutFrameReadByte(); + OT_FALL_THROUGH; + case kEncodingFrame: SuccessOrExit(mFrameEncoder.Encode(mByte)); @@ -181,7 +183,7 @@ void NcpUart::EncodeAndSendToUart(void) mState = kFinalizingFrame; - // fall through + OT_FALL_THROUGH; case kFinalizingFrame: