// Copyright (C) 2022 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package {
    default_team: "trendy_team_fwk_wifi_hal",
    default_applicable_licenses: ["hardware_interfaces_license"],
}

soong_config_module_type {
    name: "wifi_hal_cc_defaults",
    module_type: "cc_defaults",
    config_namespace: "wifi",
    bool_variables: [
        "hidl_feature_aware", // WIFI_HIDL_FEATURE_AWARE
        "hidl_feature_dual_interface", // WIFI_HIDL_FEATURE_DUAL_INTERFACE
        "hidl_feature_disable_ap", // WIFI_HIDL_FEATURE_DISABLE_AP
        "hidl_feature_disable_ap_mac_randomization", // WIFI_HIDL_FEATURE_DISABLE_AP_MAC_RANDOMIZATION
        "avoid_iface_reset_mac_change", // WIFI_AVOID_IFACE_RESET_MAC_CHANGE
        "wifi_skip_state_toggle_off_on_for_nan", // WIFI_SKIP_STATE_TOGGLE_OFF_ON_FOR_NAN
    ],
    value_variables: [
        "hal_interface_combinations", // WIFI_HAL_INTERFACE_COMBINATIONS
    ],
    properties: [
        "cppflags",
    ],
}

wifi_hal_cc_defaults {
    name: "android.hardware.wifi-service-cppflags-defaults",
    soong_config_variables: {
        hidl_feature_aware: {
            cppflags: ["-DWIFI_HIDL_FEATURE_AWARE"],
        },
        hidl_feature_dual_interface: {
            cppflags: ["-DWIFI_HIDL_FEATURE_DUAL_INTERFACE"],
        },
        hidl_feature_disable_ap: {
            cppflags: ["-DWIFI_HIDL_FEATURE_DISABLE_AP"],
        },
        hidl_feature_disable_ap_mac_randomization: {
            cppflags: ["-DWIFI_HIDL_FEATURE_DISABLE_AP_MAC_RANDOMIZATION"],
        },
        avoid_iface_reset_mac_change: {
            cppflags: ["-DWIFI_AVOID_IFACE_RESET_MAC_CHANGE"],
        },
        wifi_skip_state_toggle_off_on_for_nan: {
            cppflags: ["-DWIFI_SKIP_STATE_TOGGLE_OFF_ON_FOR_NAN"],
        },
        hal_interface_combinations: {
            cppflags: ["-DWIFI_HAL_INTERFACE_COMBINATIONS=%s"],
        },
    },
}

cc_library_static {
    name: "android.hardware.wifi-service-lib",
    defaults: ["android.hardware.wifi-service-cppflags-defaults"],
    proprietary: true,
    compile_multilib: "first",
    cppflags: [
        "-Wall",
        "-Werror",
        "-Wextra",
    ],
    // Allow implicit fallthroughs in wifi_legacy_hal.cpp until they are fixed.
    cflags: ["-Wno-error=implicit-fallthrough"],
    srcs: [
        "aidl_struct_util.cpp",
        "aidl_sync_util.cpp",
        "ringbuffer.cpp",
        "wifi.cpp",
        "wifi_ap_iface.cpp",
        "wifi_chip.cpp",
        "wifi_feature_flags.cpp",
        "wifi_iface_util.cpp",
        "wifi_legacy_hal.cpp",
        "wifi_legacy_hal_factory.cpp",
        "wifi_legacy_hal_stubs.cpp",
        "wifi_mode_controller.cpp",
        "wifi_nan_iface.cpp",
        "wifi_p2p_iface.cpp",
        "wifi_rtt_controller.cpp",
        "wifi_sta_iface.cpp",
        "wifi_status_util.cpp",
    ],

    shared_libs: [
        "libbase",
        "libbinder_ndk",
        "libcutils",
        "liblog",
        "libnl",
        "libutils",
        "libwifi-hal",
        "libwifi-system-iface",
        "libxml2",
        "android.hardware.wifi-V2-ndk",
    ],

    export_include_dirs: ["."],
}

cc_binary {
    name: "android.hardware.wifi-service",
    vintf_fragments: ["android.hardware.wifi-service.xml"],
    relative_install_path: "hw",
    proprietary: true,
    cppflags: [
        "-Wall",
        "-Werror",
        "-Wextra",
    ],
    srcs: ["service.cpp"],
    shared_libs: [
        "libbase",
        "libbinder_ndk",
        "libcutils",
        "liblog",
        "libnl",
        "libutils",
        "libwifi-hal",
        "libwifi-system-iface",
        "libxml2",
        "android.hardware.wifi-V2-ndk",
    ],
    static_libs: ["android.hardware.wifi-service-lib"],
    init_rc: ["android.hardware.wifi-service.rc"],
}

cc_binary {
    name: "android.hardware.wifi-service-lazy",
    vintf_fragments: ["android.hardware.wifi-service.xml"],
    overrides: ["android.hardware.wifi-service"],
    cflags: ["-DLAZY_SERVICE"],
    relative_install_path: "hw",
    proprietary: true,
    cppflags: [
        "-Wall",
        "-Werror",
        "-Wextra",
    ],
    srcs: ["service.cpp"],
    shared_libs: [
        "libbase",
        "libbinder_ndk",
        "libcutils",
        "liblog",
        "libnl",
        "libutils",
        "libwifi-hal",
        "libwifi-system-iface",
        "libxml2",
        "android.hardware.wifi-V2-ndk",
    ],
    static_libs: ["android.hardware.wifi-service-lib"],
    init_rc: ["android.hardware.wifi-service-lazy.rc"],
}

cc_test {
    name: "android.hardware.wifi-service-tests",
    proprietary: true,
    compile_multilib: "first",
    cppflags: [
        "-Wall",
        "-Werror",
        "-Wextra",
    ],
    srcs: [
        "tests/aidl_struct_util_unit_tests.cpp",
        "tests/main.cpp",
        "tests/mock_interface_tool.cpp",
        "tests/mock_wifi_feature_flags.cpp",
        "tests/mock_wifi_iface_util.cpp",
        "tests/mock_wifi_legacy_hal.cpp",
        "tests/mock_wifi_mode_controller.cpp",
        "tests/ringbuffer_unit_tests.cpp",
        "tests/wifi_nan_iface_unit_tests.cpp",
        "tests/wifi_chip_unit_tests.cpp",
        "tests/wifi_iface_util_unit_tests.cpp",
    ],
    static_libs: [
        "libgmock",
        "libgtest",
        "android.hardware.wifi-V2-ndk",
        "android.hardware.wifi.common-V1-ndk",
        "android.hardware.wifi-service-lib",
    ],
    shared_libs: [
        "libbase",
        "libbinder_ndk",
        "libcutils",
        "liblog",
        "libnl",
        "libutils",
        "libwifi-hal",
        "libwifi-system-iface",
    ],
}

filegroup {
    name: "default-android.hardware.wifi-service.rc",
    srcs: ["android.hardware.wifi-service.rc"],
}

filegroup {
    name: "default-android.hardware.wifi-service.xml",
    srcs: ["android.hardware.wifi-service.xml"],
}
