Merge "wifi: Supports Soft AP client isolation configuration" into main
diff --git a/Android.bp b/Android.bp
index 068630b..a083f89 100644
--- a/Android.bp
+++ b/Android.bp
@@ -64,3 +64,40 @@
         "src/wps/http_server.c",
     ],
 }
+
+filegroup {
+    name: "wpa_supplicant_macsec_extra_driver_srcs",
+    srcs: [
+        "src/drivers/driver_macsec_linux.c",
+        "src/drivers/driver_wired_common.c",
+    ],
+}
+
+filegroup {
+    name: "hs20_client_srcs",
+    srcs: [
+        "hs20/client/est.c",
+        "hs20/client/oma_dm_client.c",
+        "hs20/client/osu_client.c",
+        "hs20/client/spp_client.c",
+        "src/common/wpa_ctrl.c",
+        "src/common/wpa_helpers.c",
+        "src/crypto/crypto_internal.c",
+        "src/crypto/md5-internal.c",
+        "src/crypto/sha1-internal.c",
+        "src/crypto/sha256-internal.c",
+        "src/crypto/tls_openssl_ocsp.c",
+        "src/utils/base64.c",
+        "src/utils/browser-wpadebug.c",
+        "src/utils/common.c",
+        "src/utils/eloop.c",
+        "src/utils/http_curl.c",
+        "src/utils/os_unix.c",
+        "src/utils/wpa_debug.c",
+        "src/utils/wpabuf.c",
+        "src/utils/xml-utils.c",
+        "src/utils/xml_libxml2.c",
+        "src/wps/http_server.c",
+        "src/wps/httpread.c",
+    ],
+}
diff --git a/Android.mk b/Android.mk
index bb8326c..ca7a620 100644
--- a/Android.mk
+++ b/Android.mk
@@ -1,5 +1,6 @@
 S_LOCAL_PATH := $(call my-dir)
 
+ifdef FORCE_USE_ANDROIDMK_FOR_WPA
 ifneq ($(filter VER_0_8_X VER_2_1_DEVEL,$(WPA_SUPPLICANT_VERSION)),)
 # The order of the 2 Android.mks does matter!
 # TODO: Clean up the Android.mks, reset all the temporary variables at the
@@ -13,3 +14,4 @@
 endif #End of Check for platform version
 endif #End of Check for target build variant
 endif
+endif
diff --git a/PREUPLOAD.cfg b/PREUPLOAD.cfg
new file mode 100644
index 0000000..321bab6
--- /dev/null
+++ b/PREUPLOAD.cfg
@@ -0,0 +1,2 @@
+[Builtin Hooks]
+bpfmt = true
diff --git a/hostapd/Android.bp b/hostapd/Android.bp
index fb414d0..4f76a30 100644
--- a/hostapd/Android.bp
+++ b/hostapd/Android.bp
@@ -362,3 +362,345 @@
     relative_install_path: "vintf",
     installable: false,
 }
+
+// For converting the default to soong
+cc_defaults {
+    name: "hostapd_driver_srcs_default",
+    srcs: [
+        "src/drivers/driver_nl80211.c",
+        "src/drivers/driver_nl80211_android.c",
+        "src/drivers/driver_nl80211_capa.c",
+        "src/drivers/driver_nl80211_event.c",
+        "src/drivers/driver_nl80211_monitor.c",
+        "src/drivers/driver_nl80211_scan.c",
+        "src/drivers/linux_ioctl.c",
+        "src/drivers/netlink.c",
+        "src/drivers/rfkill.c",
+        "src/utils/radiotap.c",
+    ],
+}
+
+cc_defaults {
+    name: "hostapd_driver_cflags_default",
+    cflags: [
+        "-DCONFIG_DRIVER_NL80211",
+    ] + select(soong_config_variable("wpa_supplicant_8", "board_wlan_device"), {
+        "bcmdhd": ["-DCONFIG_DRIVER_NL80211_BRCM"],
+        "synadhd": ["-DCONFIG_DRIVER_NL80211_SYNA"],
+        default: ["-DCONFIG_DRIVER_NL80211_QCA"],
+    }),
+}
+
+soong_config_module_type {
+    name: "hostapd_cc_defaults_type",
+    module_type: "cc_defaults",
+    config_namespace: "wpa_supplicant_8",
+    value_variables: [
+        "platform_version",
+    ],
+    properties: ["cflags"],
+}
+
+// Hostap related module share the same CFLAGS
+hostapd_cc_defaults_type {
+    name: "hostapd_cflags_default",
+    cflags: [
+        "-DWPA_IGNORE_CONFIG_ERRORS",
+        "-DANDROID_LOG_NAME=\"hostapd\"",
+        "-Wall",
+        "-Werror",
+        "-Wno-unused-parameter",
+        "-Wno-unused-variable",
+        "-Wno-macro-redefined",
+        "-DANDROID_P2P",
+        "-DCONFIG_CTRL_IFACE_CLIENT_DIR=\"/data/vendor/wifi/hostapd/sockets\"",
+        "-DCONFIG_CTRL_IFACE_DIR=\"/data/vendor/wifi/hostapd/ctrl\"",
+        "-DCONFIG_HOSTAPD_CLI_HISTORY_DIR=\"/data/vendor/wifi/hostapd\"",
+        "-DHOSTAPD",
+        "-DHOSTAPD_DUMP_STATE",
+        "-DCONFIG_NO_RADIUS",
+        "-DCONFIG_NO_ACCOUNTING",
+        "-DCONFIG_CTRL_IFACE",
+        "-DCONFIG_CTRL_IFACE_UNIX",
+        "-DCONFIG_SAE",
+        "-DCONFIG_IEEE80211AC",
+        "-DCONFIG_WEP",
+        "-DCONFIG_WPS",
+        "-DEAP_SERVER_WSC",
+        "-DCONFIG_DPP",
+        "-DEAP_SERVER_IDENTITY",
+        "-DEAP_SERVER",
+        "-DPKCS12_FUNCS",
+        "-DCRYPTO_RSA_OAEP_SHA256",
+        "-DTLS_DEFAULT_CIPHERS=\"DEFAULT:!EXP:!LOW\"",
+        "-DCONFIG_SHA256",
+        "-DCONFIG_SHA384",
+        "-DCONFIG_SHA512",
+        "-DCONFIG_ECC",
+        "-DCONFIG_NO_RANDOM_POOL",
+        "-DCONFIG_IPV6",
+        "-DCONFIG_JSON",
+        "-DNEED_AP_MLME",
+        "-DCONFIG_INTERWORKING",
+        "-DCONFIG_ACS",
+        "-DCONFIG_ANDROID_LOG",
+        "-DCONFIG_CTRL_IFACE_AIDL",
+    ] + select(soong_config_variable("wpa_supplicant_8", "hostapd_use_stub_lib"), {
+        true: ["-DANDROID_LIB_STUB"],
+        default: [],
+    }) + select(soong_config_variable("wpa_supplicant_8", "hostapd_11ax"), {
+        true: ["-DCONFIG_IEEE80211AX"],
+        default: [],
+    }) + select(soong_config_variable("wpa_supplicant_8", "board_hostapd_config_80211w_mfp_optional"), {
+        true: ["-DENABLE_HOSTAPD_CONFIG_80211W_MFP_OPTIONAL"],
+        default: [],
+    }) + select(soong_config_variable("wpa_supplicant_8", "board_hostapd_private_lib_event"), {
+        true: ["-DANDROID_LIB_EVENT"],
+        default: [],
+    }),
+    arch: {
+        arm: {
+            cflags: [
+                "-mabi=aapcs-linux",
+            ],
+        },
+    },
+    defaults: [
+        "hostapd_driver_cflags_default",
+    ],
+    soong_config_variables: {
+        platform_version: {
+            cflags: ["-DVERSION_STR_POSTFIX=\"-%s\""],
+        },
+    },
+    enabled: select(soong_config_variable("wpa_supplicant_8", "wpa_build_hostapd"), {
+        true: true,
+        default: false,
+    }),
+}
+
+cc_defaults {
+    name: "hostapd_includes_default",
+    local_include_dirs: [
+        ".",
+        "src",
+        "src/utils",
+    ],
+    include_dirs: [
+        // There's an if condition for external/libnl but current code base should always have this.
+        "external/libnl/include",
+        "system/security/keystore/include",
+    ],
+}
+
+cc_defaults {
+    name: "hostapd_srcs_default",
+    srcs: [
+        "main.c",
+        "config_file.c",
+        "src/ap/hostapd.c",
+        "src/ap/wpa_auth_glue.c",
+        "src/ap/drv_callbacks.c",
+        "src/ap/ap_drv_ops.c",
+        "src/ap/utils.c",
+        "src/ap/authsrv.c",
+        "src/ap/ieee802_1x.c",
+        "src/ap/ap_config.c",
+        "src/ap/eap_user_db.c",
+        "src/ap/ieee802_11_auth.c",
+        "src/ap/sta_info.c",
+        "src/ap/wpa_auth.c",
+        "src/ap/tkip_countermeasures.c",
+        "src/ap/ap_mlme.c",
+        "src/ap/wpa_auth_ie.c",
+        "src/ap/preauth_auth.c",
+        "src/ap/pmksa_cache_auth.c",
+        "src/ap/ieee802_11_shared.c",
+        "src/ap/beacon.c",
+        "src/ap/bss_load.c",
+        "src/ap/neighbor_db.c",
+        "src/ap/rrm.c",
+        "src/drivers/drivers.c",
+        "src/utils/eloop.c",
+        "src/utils/common.c",
+        "src/utils/wpa_debug.c",
+        "src/utils/wpabuf.c",
+        "src/utils/os_unix.c",
+        "src/utils/ip_addr.c",
+        "src/utils/crc32.c",
+        "src/common/ieee802_11_common.c",
+        "src/common/wpa_common.c",
+        "src/common/hw_features_common.c",
+        "src/common/ptksa_cache.c",
+        "src/eapol_auth/eapol_auth_sm.c",
+        "src/eapol_auth/eapol_auth_dump.c",
+        "src/ap/vlan_init.c",
+        "src/ap/vlan_ifconfig.c",
+        "src/ap/vlan.c",
+        "src/common/ctrl_iface_common.c",
+        "ctrl_iface.c",
+        "src/ap/ctrl_iface_ap.c",
+        "src/common/sae.c",
+        "src/l2_packet/l2_packet_none.c",
+        "src/utils/uuid.c",
+        "src/ap/wps_hostapd.c",
+        "src/eap_server/eap_server_wsc.c",
+        "src/eap_common/eap_wsc_common.c",
+        "src/wps/wps.c",
+        "src/wps/wps_common.c",
+        "src/wps/wps_attr_parse.c",
+        "src/wps/wps_attr_build.c",
+        "src/wps/wps_attr_process.c",
+        "src/wps/wps_dev_attr.c",
+        "src/wps/wps_enrollee.c",
+        "src/wps/wps_registrar.c",
+        "src/common/dpp.c",
+        "src/common/dpp_auth.c",
+        "src/common/dpp_backup.c",
+        "src/common/dpp_crypto.c",
+        "src/common/dpp_pkex.c",
+        "src/common/dpp_reconfig.c",
+        "src/common/dpp_tcp.c",
+        "src/ap/dpp_hostapd.c",
+        "src/ap/gas_query_ap.c",
+        "eap_register.c",
+        "src/eap_server/eap_server.c",
+        "src/eap_common/eap_common.c",
+        "src/eap_server/eap_server_methods.c",
+        "src/eap_server/eap_server_identity.c",
+        "src/common/dragonfly.c",
+        "src/crypto/crypto_openssl.c",
+        "src/crypto/tls_none.c",
+        "src/crypto/aes-siv.c",
+        "src/crypto/aes-ctr.c",
+        "src/crypto/sha1-prf.c",
+        "src/crypto/sha256-prf.c",
+        "src/crypto/sha256-tlsprf.c",
+        "src/crypto/sha256-kdf.c",
+        "src/crypto/sha384-kdf.c",
+        "src/crypto/sha512-kdf.c",
+        "src/crypto/sha384-prf.c",
+        "src/crypto/sha512-prf.c",
+        "src/tls/asn1.c",
+        "src/crypto/dh_groups.c",
+        "src/utils/base64.c",
+        "src/utils/json.c",
+        "src/ap/wmm.c",
+        "src/ap/ap_list.c",
+        "src/ap/comeback_token.c",
+        "src/pasn/pasn_common.c",
+        "src/pasn/pasn_responder.c",
+        "src/ap/ieee802_11.c",
+        "src/ap/hw_features.c",
+        "src/ap/dfs.c",
+        "src/ap/ieee802_11_ht.c",
+        "src/ap/ieee802_11_vht.c",
+        "src/common/gas.c",
+        "src/ap/gas_serv.c",
+        "src/drivers/driver_common.c",
+        "src/ap/acs.c",
+    ] + select(soong_config_variable("wpa_supplicant_8", "hostapd_11ax"), {
+        true: ["src/ap/ieee802_11_he.c"],
+        default: [],
+    }),
+    defaults: [
+        "hostapd_driver_srcs_default",
+    ],
+}
+
+cc_binary {
+    name: "hostapd_cli",
+    proprietary: true,
+    srcs: [
+        "hostapd_cli.c",
+        "src/common/cli.c",
+        "src/common/wpa_ctrl.c",
+        "src/utils/common.c",
+        "src/utils/edit.c",
+        "src/utils/eloop.c",
+        "src/utils/os_unix.c",
+        "src/utils/wpa_debug.c",
+    ],
+    shared_libs: [
+        "libc",
+        "libcutils",
+        "liblog",
+    ],
+    defaults: [
+        "hostapd_cflags_default",
+        "hostapd_includes_default",
+    ],
+}
+
+soong_config_module_type {
+    name: "hostapd_cc_binary",
+    module_type: "cc_binary",
+    config_namespace: "wpa_supplicant_8",
+    value_variables: [
+        "board_hostapd_private_lib",
+    ],
+    properties: ["static_libs"],
+}
+
+hostapd_cc_binary {
+    name: "hostapd",
+    proprietary: true,
+    relative_install_path: "hw",
+    //vintf_fragments: ["android.hardware.wifi.hostapd.xml"],
+    required: [
+        "android.hardware.wifi.hostapd.xml",
+    ],
+    static_libs: [
+        "libhostapd_aidl",
+    ],
+    shared_libs: [
+        "libc",
+        "libcutils",
+        "liblog",
+        "libcrypto",
+        "libssl",
+        "libnl",
+        "android.hardware.wifi.hostapd-V3-ndk",
+        "android.hardware.wifi.common-V2-ndk",
+        "libbase",
+        "libutils",
+        "libbinder_ndk",
+    ],
+    init_rc: ["hostapd.android.rc"],
+    defaults: [
+        "hostapd_srcs_default",
+        "hostapd_cflags_default",
+        "hostapd_includes_default",
+    ],
+    soong_config_variables: {
+        board_hostapd_private_lib: {
+            static_libs: ["%s"],
+        },
+    },
+}
+
+cc_library_static {
+    name: "libhostapd_aidl",
+    soc_specific: true,
+    srcs: [
+        "aidl/aidl.cpp",
+        "aidl/hostapd.cpp",
+    ],
+    shared_libs: [
+        "android.hardware.wifi.hostapd-V3-ndk",
+        "android.hardware.wifi.common-V2-ndk",
+        "libbinder_ndk",
+        "libbase",
+        "libutils",
+        "liblog",
+    ],
+    export_include_dirs: ["aidl"],
+    cppflags: [
+        "-Wall",
+        "-Werror",
+    ],
+    defaults: [
+        "hostapd_cflags_default",
+        "hostapd_includes_default",
+    ],
+}
diff --git a/hs20/client/Android.bp b/hs20/client/Android.bp
new file mode 100644
index 0000000..3c8383c
--- /dev/null
+++ b/hs20/client/Android.bp
@@ -0,0 +1,61 @@
+//
+// Copyright (C) 2024 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 {
+    // See: http://go/android-license-faq
+    default_applicable_licenses: [
+        "external_wpa_supplicant_8_license",
+    ],
+}
+
+cc_binary {
+    name: "hs20-osu-client",
+    vendor: true,
+    srcs: [
+        ":hs20_client_srcs",
+    ],
+    shared_libs: [
+        "libc",
+        "libcrypto",
+        "libcurl",
+        "libcutils",
+        "liblog",
+        "libssl",
+        "libxml2",
+    ],
+    cflags: [
+        "-DCONFIG_CTRL_IFACE",
+        "-DCONFIG_CTRL_IFACE_UNIX",
+        "-DCONFIG_CTRL_IFACE_CLIENT_DIR=\"/data/misc/wifi/sockets\"",
+        "-DCONFIG_DEBUG_FILE",
+        "-DEAP_TLS_OPENSSL",
+        "-Wno-unused-parameter",
+        "-DCONFIG_ANDROID_LOG",
+        "-DANDROID_LOG_NAME=\"hs20-osu-client\"",
+    ],
+    local_include_dirs: [
+        ".",
+    ],
+    include_dirs: [
+        "external/curl/include",
+        "external/libxml2/include",
+        "external/wpa_supplicant_8/src",
+        "external/wpa_supplicant_8/src/common",
+        "external/wpa_supplicant_8/src/utils",
+    ],
+    defaults: [
+        "wpa_supplicant_cflags_default",
+    ],
+}
diff --git a/src/crypto/tls_openssl.c b/src/crypto/tls_openssl.c
index f5d734d..d849933 100644
--- a/src/crypto/tls_openssl.c
+++ b/src/crypto/tls_openssl.c
@@ -1290,8 +1290,9 @@
 #endif /* OPENSSL_NO_ENGINE */
 
 
-#ifdef ANDROID
-/* EVP_PKEY_from_keystore comes from system/security/keystore-engine. */
+// Imported from system/security/keystore-engine. This method
+// is not used by the mainline supplicant.
+#if defined(ANDROID) && !defined(MAINLINE_SUPPLICANT)
 EVP_PKEY * EVP_PKEY_from_keystore(const char *key_id);
 #endif /* ANDROID */
 
@@ -1299,7 +1300,7 @@
 			   const char *pin, const char *key_id,
 			   const char *cert_id, const char *ca_cert_id)
 {
-#if defined(ANDROID) && defined(OPENSSL_IS_BORINGSSL)
+#if defined(ANDROID) && !defined(MAINLINE_SUPPLICANT) && defined(OPENSSL_IS_BORINGSSL)
 #if !defined(OPENSSL_NO_ENGINE)
 #error "This code depends on OPENSSL_NO_ENGINE being defined by BoringSSL."
 #endif
@@ -1307,6 +1308,7 @@
 		return TLS_SET_PARAMS_ENGINE_PRV_INIT_FAILED;
 	conn->engine = NULL;
 	conn->private_key = EVP_PKEY_from_keystore(key_id);
+
 	if (!conn->private_key) {
 		wpa_printf(MSG_ERROR,
 			   "ENGINE: cannot load private key with id '%s' [%s]",
diff --git a/wpa_supplicant/Android.bp b/wpa_supplicant/Android.bp
index 619e35a..210325b 100644
--- a/wpa_supplicant/Android.bp
+++ b/wpa_supplicant/Android.bp
@@ -57,6 +57,31 @@
     soc_specific: true,
 }
 
+cc_library_headers {
+    name: "wpa_supplicant_headers_mainline",
+    export_include_dirs: [
+        ".",
+        "src",
+        "src/common",
+        "src/drivers",
+        "src/eap_common",
+        "src/eapol_supp",
+        "src/eap_peer",
+        "src/eap_server",
+        "src/l2_packet",
+        "src/radius",
+        "src/rsn_supp",
+        "src/tls",
+        "src/utils",
+        "src/wps",
+    ],
+    apex_available: [
+        "//apex_available:platform",
+        "com.android.wifi",
+    ],
+    min_sdk_version: "30",
+}
+
 filegroup {
     name: "wpa_supplicant_template.conf",
     srcs: ["wpa_supplicant_template.conf"],
@@ -676,3 +701,762 @@
         cfi: true,
     },
 }
+
+// For converting the default to soong
+cc_defaults {
+    name: "wpa_supplicant_driver_srcs_default",
+    srcs: [
+        "src/drivers/driver_nl80211.c",
+        "src/drivers/driver_nl80211_android.c",
+        "src/drivers/driver_nl80211_capa.c",
+        "src/drivers/driver_nl80211_event.c",
+        "src/drivers/driver_nl80211_monitor.c",
+        "src/drivers/driver_nl80211_scan.c",
+        "src/drivers/linux_ioctl.c",
+        "src/drivers/netlink.c",
+        "src/drivers/rfkill.c",
+        "src/utils/radiotap.c",
+    ],
+}
+
+cc_defaults {
+    name: "wpa_supplicant_driver_cflags_default",
+    cflags: [
+        "-DCONFIG_DRIVER_NL80211",
+        // Because the original Android.mk will call hostapd's Android.mk first and it
+        // will make the flag share with wpa_supplicant, keep the original logic in hostapd.
+    ] + select(soong_config_variable("wpa_supplicant_8", "board_wlan_device"), {
+        "bcmdhd": ["-DCONFIG_DRIVER_NL80211_BRCM"],
+        "synadhd": ["-DCONFIG_DRIVER_NL80211_SYNA"],
+        "qcwcn": ["-DCONFIG_DRIVER_NL80211_QCA"],
+        default: ["-DCONFIG_DRIVER_NL80211_QCA"],
+    }),
+}
+
+cc_defaults {
+    name: "wpa_supplicant_includes_default",
+    local_include_dirs: [
+        ".",
+        "src",
+        "src/common",
+        "src/drivers",
+        "src/eap_common",
+        "src/eap_peer",
+        "src/eap_server",
+        "src/eapol_supp",
+        "src/l2_packet",
+        "src/pasn",
+        "src/radius",
+        "src/rsn_supp",
+        "src/tls",
+        "src/utils",
+        "src/wps",
+    ],
+    include_dirs: [
+        // There's an if condition for external/libnl but current code base should always have this.
+        "external/libnl/include",
+        "system/security/keystore/include",
+    ],
+}
+
+soong_config_module_type {
+    name: "wpa_supplicant_cc_defaults_type",
+    module_type: "cc_defaults",
+    config_namespace: "wpa_supplicant_8",
+    value_variables: [
+        "platform_version",
+    ],
+    properties: ["cflags"],
+}
+
+// Hostap related module share the same CFLAGS
+wpa_supplicant_cc_defaults_type {
+    name: "wpa_supplicant_no_aidl_cflags_default",
+    cflags: [
+        "-DANDROID_LOG_NAME=\"wpa_supplicant\"",
+        "-DANDROID_P2P",
+        "-DCONFIG_ACS",
+        "-DCONFIG_ANDROID_LOG",
+        "-DCONFIG_AP",
+        "-DCONFIG_BACKEND_FILE",
+        "-DCONFIG_CTRL_IFACE",
+        "-DCONFIG_CTRL_IFACE_CLIENT_DIR=\"/data/vendor/wifi/wpa/sockets\"",
+        "-DCONFIG_CTRL_IFACE_DIR=\"/data/vendor/wifi/wpa/sockets\"",
+        "-DCONFIG_CTRL_IFACE_UNIX",
+        "-DCONFIG_DPP",
+        "-DCONFIG_DPP2",
+        "-DCONFIG_DRIVER_NL80211",
+        "-DCONFIG_DRIVER_NL80211_QCA",
+        "-DCONFIG_ECC",
+        "-DCONFIG_ERP",
+        "-DCONFIG_FILS",
+        "-DCONFIG_GAS",
+        "-DCONFIG_GAS_SERVER",
+        "-DCONFIG_HMAC_SHA256_KDF",
+        "-DCONFIG_HMAC_SHA384_KDF",
+        "-DCONFIG_HMAC_SHA512_KDF",
+        "-DCONFIG_HS20",
+        "-DCONFIG_IEEE80211AC",
+        "-DCONFIG_IEEE80211R",
+        "-DCONFIG_INTERWORKING",
+        "-DCONFIG_IPV6",
+        "-DCONFIG_JSON",
+        "-DCONFIG_MBO",
+        "-DCONFIG_NO_ACCOUNTING",
+        "-DCONFIG_NO_RADIUS",
+        "-DCONFIG_NO_RADIUS",
+        "-DCONFIG_NO_RANDOM_POOL",
+        "-DCONFIG_NO_ROAMING",
+        "-DCONFIG_NO_VLAN",
+        "-DCONFIG_OFFCHANNEL",
+        "-DCONFIG_OWE",
+        "-DCONFIG_P2P",
+        "-DCONFIG_PASN",
+        "-DCONFIG_PTKSA_CACHE",
+        "-DCONFIG_SAE",
+        "-DCONFIG_SAE_PK",
+        "-DCONFIG_SHA256",
+        "-DCONFIG_SHA384",
+        "-DCONFIG_SHA512",
+        "-DCONFIG_SMARTCARD",
+        "-DCONFIG_SME",
+        "-DCONFIG_SUITEB",
+        "-DCONFIG_SUITEB192",
+        "-DCONFIG_TDLS",
+        "-DCONFIG_WEP",
+        "-DCONFIG_WIFI_DISPLAY",
+        "-DCONFIG_WNM",
+        "-DCONFIG_WPA_CLI_HISTORY_DIR=\"/data/vendor/wifi/wpa\"",
+        "-DCONFIG_WPS",
+        "-DCONFIG_WPS_ER",
+        "-DCONFIG_WPS_NFC",
+        "-DCONFIG_WPS_OOB",
+        "-DCONFIG_WPS_UPNP",
+        "-DCRYPTO_RSA_OAEP_SHA256",
+        "-DEAP_AKA",
+        "-DEAP_AKA_PRIME",
+        "-DEAP_GTC",
+        "-DEAP_LEAP",
+        "-DEAP_MD5",
+        "-DEAP_MSCHAPv2",
+        "-DEAP_OTP",
+        "-DEAP_PEAP",
+        "-DEAP_PWD",
+        "-DEAP_SERVER",
+        "-DEAP_SERVER_IDENTITY",
+        "-DEAP_SERVER_WSC",
+        "-DEAP_SIM",
+        "-DEAP_TLS",
+        "-DEAP_TLSV1_3",
+        "-DEAP_TLS_OPENSSL",
+        "-DEAP_TTLS",
+        "-DEAP_WSC",
+        "-DIEEE8021X_EAPOL",
+        "-DNEED_AP_MLME",
+        "-DPKCS12_FUNCS",
+        "-DTLS_DEFAULT_CIPHERS=\"DEFAULT:!EXP:!LOW\"",
+        "-DWPA_IGNORE_CONFIG_ERRORS",
+        "-Wall",
+        "-Werror",
+        "-Wno-error=sometimes-uninitialized",
+        "-Wno-incompatible-pointer-types",
+        "-Wno-incompatible-pointer-types-discards-qualifiers",
+        "-Wno-macro-redefined",
+        "-Wno-parentheses-equality",
+        "-Wno-sign-compare",
+        "-Wno-unused-function",
+        "-Wno-unused-parameter",
+        "-Wno-unused-variable",
+    ] + select(soong_config_variable("wpa_supplicant_8", "wpa_supplicant_use_stub_lib"), {
+        true: ["-DANDROID_LIB_STUB"],
+        default: [],
+    }) + select(soong_config_variable("wpa_supplicant_8", "board_hostapd_config_80211w_mfp_optional"), {
+        true: ["-DENABLE_HOSTAPD_CONFIG_80211W_MFP_OPTIONAL"],
+        default: [],
+    }) + select(soong_config_variable("wpa_supplicant_8", "board_wpa_supplicant_private_lib_event"), {
+        true: ["-DANDROID_LIB_EVENT"],
+        default: [],
+    }) + select(soong_config_variable("wpa_supplicant_8", "wifi_priv_cmd_update_mbo_cell_status"), {
+        true: ["-DENABLE_PRIV_CMD_UPDATE_MBO_CELL_STATUS"],
+        default: [],
+    }) + select(soong_config_variable("wpa_supplicant_8", "hostapd_11ax"), {
+        true: ["-DCONFIG_IEEE80211AX"],
+        default: [],
+    }) + select(soong_config_variable("wpa_supplicant_8", "wifi_brcm_open_source_multi_akm"), {
+        true: ["-DWIFI_BRCM_OPEN_SOURCE_MULTI_AKM"],
+        default: [],
+    }),
+    arch: {
+        arm: {
+            cflags: [
+                "-mabi=aapcs-linux",
+            ],
+        },
+    },
+    defaults: [
+        "wpa_supplicant_driver_cflags_default",
+    ],
+    soong_config_variables: {
+        platform_version: {
+            cflags: ["-DVERSION_STR_POSTFIX=\"-%s\""],
+        },
+    },
+}
+
+cc_defaults {
+    name: "wpa_supplicant_cflags_default",
+    cflags: [
+        "-DCONFIG_AIDL",
+        "-DCONFIG_CTRL_IFACE_AIDL",
+    ],
+    defaults: [
+        "wpa_supplicant_no_aidl_cflags_default",
+    ],
+}
+
+wpa_supplicant_cc_defaults_type {
+    name: "wpa_supplicant_mainline_cflags_default",
+    cflags: [
+        "-DANDROID_LIB_STUB",
+        "-DANDROID_LOG_NAME=\"mainline_supplicant\"",
+        "-DCONFIG_ACS",
+        "-DCONFIG_ANDROID_LOG",
+        "-DCONFIG_AP",
+        "-DCONFIG_BACKEND_FILE",
+        "-DCONFIG_CTRL_IFACE",
+        "-DCONFIG_CTRL_IFACE_UNIX",
+        "-DCONFIG_DPP",
+        "-DCONFIG_DPP2",
+        "-DCONFIG_DRIVER_NL80211",
+        "-DCONFIG_DRIVER_NL80211_QCA",
+        "-DCONFIG_ECC",
+        "-DCONFIG_ERP",
+        "-DCONFIG_FILS",
+        "-DCONFIG_GAS",
+        "-DCONFIG_GAS_SERVER",
+        "-DCONFIG_HMAC_SHA256_KDF",
+        "-DCONFIG_HMAC_SHA384_KDF",
+        "-DCONFIG_HMAC_SHA512_KDF",
+        "-DCONFIG_HS20",
+        "-DCONFIG_IEEE80211AC",
+        "-DCONFIG_IEEE80211R",
+        "-DCONFIG_INTERWORKING",
+        "-DCONFIG_IPV6",
+        "-DCONFIG_JSON",
+        "-DCONFIG_MBO",
+        "-DCONFIG_NO_ACCOUNTING",
+        "-DCONFIG_NO_RADIUS",
+        "-DCONFIG_NO_RADIUS",
+        "-DCONFIG_NO_RANDOM_POOL",
+        "-DCONFIG_NO_ROAMING",
+        "-DCONFIG_NO_VLAN",
+        "-DCONFIG_OFFCHANNEL",
+        "-DCONFIG_OWE",
+        "-DCONFIG_P2P",
+        "-DCONFIG_PASN",
+        "-DCONFIG_PTKSA_CACHE",
+        "-DCONFIG_SAE",
+        "-DCONFIG_SAE_PK",
+        "-DCONFIG_SHA256",
+        "-DCONFIG_SHA384",
+        "-DCONFIG_SHA512",
+        "-DCONFIG_SMARTCARD",
+        "-DCONFIG_SME",
+        "-DCONFIG_SUITEB",
+        "-DCONFIG_SUITEB192",
+        "-DCONFIG_TDLS",
+        "-DCONFIG_WEP",
+        "-DCONFIG_WIFI_DISPLAY",
+        "-DCONFIG_WNM",
+        "-DCONFIG_WPS",
+        "-DCONFIG_WPS_ER",
+        "-DCONFIG_WPS_NFC",
+        "-DCONFIG_WPS_OOB",
+        "-DCONFIG_WPS_UPNP",
+        "-DCRYPTO_RSA_OAEP_SHA256",
+        "-DEAP_AKA",
+        "-DEAP_AKA_PRIME",
+        "-DEAP_GTC",
+        "-DEAP_LEAP",
+        "-DEAP_MD5",
+        "-DEAP_MSCHAPv2",
+        "-DEAP_OTP",
+        "-DEAP_PEAP",
+        "-DEAP_PWD",
+        "-DEAP_SERVER",
+        "-DEAP_SERVER_IDENTITY",
+        "-DEAP_SERVER_WSC",
+        "-DEAP_SIM",
+        "-DEAP_TLS",
+        "-DEAP_TLSV1_3",
+        "-DEAP_TLS_OPENSSL",
+        "-DEAP_TTLS",
+        "-DEAP_WSC",
+        "-DIEEE8021X_EAPOL",
+        "-DMAINLINE_SUPPLICANT",
+        "-DNEED_AP_MLME",
+        "-DOPENSSL_NO_ENGINE",
+        "-DPKCS12_FUNCS",
+        "-DTLS_DEFAULT_CIPHERS=\"DEFAULT:!EXP:!LOW\"",
+        "-DWPA_IGNORE_CONFIG_ERRORS",
+        "-Wall",
+        "-Werror",
+        "-Wno-error=sometimes-uninitialized",
+        "-Wno-incompatible-pointer-types",
+        "-Wno-incompatible-pointer-types-discards-qualifiers",
+        "-Wno-macro-redefined",
+        "-Wno-parentheses-equality",
+        "-Wno-sign-compare",
+        "-Wno-unused-function",
+        "-Wno-unused-parameter",
+        "-Wno-unused-variable",
+    ] + select(soong_config_variable("wpa_supplicant_8", "wpa_supplicant_use_stub_lib"), {
+        true: ["-DANDROID_LIB_STUB"],
+        default: [],
+    }) + select(soong_config_variable("wpa_supplicant_8", "board_hostapd_config_80211w_mfp_optional"), {
+        true: ["-DENABLE_HOSTAPD_CONFIG_80211W_MFP_OPTIONAL"],
+        default: [],
+    }) + select(soong_config_variable("wpa_supplicant_8", "board_wpa_supplicant_private_lib_event"), {
+        true: ["-DANDROID_LIB_EVENT"],
+        default: [],
+    }) + select(soong_config_variable("wpa_supplicant_8", "wifi_priv_cmd_update_mbo_cell_status"), {
+        true: ["-DENABLE_PRIV_CMD_UPDATE_MBO_CELL_STATUS"],
+        default: [],
+    }) + select(soong_config_variable("wpa_supplicant_8", "hostapd_11ax"), {
+        true: ["-DCONFIG_IEEE80211AX"],
+        default: [],
+    }) + select(soong_config_variable("wpa_supplicant_8", "wifi_brcm_open_source_multi_akm"), {
+        true: ["-DWIFI_BRCM_OPEN_SOURCE_MULTI_AKM"],
+        default: [],
+    }),
+}
+
+cc_defaults {
+    name: "wpa_supplicant_srcs_default",
+    srcs: [
+        "ap.c",
+        "bss.c",
+        "bssid_ignore.c",
+        "config.c",
+        "config_file.c",
+        "ctrl_iface.c",
+        "ctrl_iface_unix.c",
+        "dpp_supplicant.c",
+        "eap_register.c",
+        "events.c",
+        "gas_query.c",
+        "hs20_supplicant.c",
+        "interworking.c",
+        "main.c",
+        "mbo.c",
+        "notify.c",
+        "offchannel.c",
+        "op_classes.c",
+        "p2p_supplicant.c",
+        "p2p_supplicant_sd.c",
+        "pasn_supplicant.c",
+        "robust_av.c",
+        "rrm.c",
+        "scan.c",
+        "sme.c",
+        "twt.c",
+        "wifi_display.c",
+        "wmm_ac.c",
+        "wnm_sta.c",
+        "wpa_supplicant.c",
+        "wpas_glue.c",
+        "wps_supplicant.c",
+        "src/ap/acs.c",
+        "src/ap/ap_config.c",
+        "src/ap/ap_drv_ops.c",
+        "src/ap/ap_list.c",
+        "src/ap/ap_mlme.c",
+        "src/ap/authsrv.c",
+        "src/ap/beacon.c",
+        "src/ap/bss_load.c",
+        "src/ap/comeback_token.c",
+        "src/ap/ctrl_iface_ap.c",
+        "src/ap/dfs.c",
+        "src/ap/dpp_hostapd.c",
+        "src/ap/drv_callbacks.c",
+        "src/ap/eap_user_db.c",
+        "src/ap/fils_hlp.c",
+        "src/ap/gas_query_ap.c",
+        "src/ap/gas_serv.c",
+        "src/ap/hostapd.c",
+        "src/ap/hs20.c",
+        "src/ap/hw_features.c",
+        "src/ap/ieee802_11.c",
+        "src/ap/ieee802_11_auth.c",
+        "src/ap/ieee802_11_ht.c",
+        "src/ap/ieee802_11_shared.c",
+        "src/ap/ieee802_11_vht.c",
+        "src/ap/ieee802_1x.c",
+        "src/ap/mbo_ap.c",
+        "src/ap/neighbor_db.c",
+        "src/ap/p2p_hostapd.c",
+        "src/ap/pmksa_cache_auth.c",
+        "src/ap/rrm.c",
+        "src/ap/sta_info.c",
+        "src/ap/tkip_countermeasures.c",
+        "src/ap/utils.c",
+        "src/ap/wmm.c",
+        "src/ap/wpa_auth.c",
+        "src/ap/wpa_auth_glue.c",
+        "src/ap/wpa_auth_ie.c",
+        "src/ap/wps_hostapd.c",
+        "src/common/ctrl_iface_common.c",
+        "src/common/dpp.c",
+        "src/common/dpp_auth.c",
+        "src/common/dpp_backup.c",
+        "src/common/dpp_crypto.c",
+        "src/common/dpp_pkex.c",
+        "src/common/dpp_reconfig.c",
+        "src/common/dpp_tcp.c",
+        "src/common/dragonfly.c",
+        "src/common/gas.c",
+        "src/common/gas_server.c",
+        "src/common/hw_features_common.c",
+        "src/common/ieee802_11_common.c",
+        "src/common/ptksa_cache.c",
+        "src/common/sae.c",
+        "src/common/sae_pk.c",
+        "src/common/wpa_common.c",
+        "src/crypto/aes-ctr.c",
+        "src/crypto/aes-siv.c",
+        "src/crypto/crypto_openssl.c",
+        "src/crypto/dh_groups.c",
+        "src/crypto/fips_prf_openssl.c",
+        "src/crypto/ms_funcs.c",
+        "src/crypto/sha1-prf.c",
+        "src/crypto/sha1-tlsprf.c",
+        "src/crypto/sha256-kdf.c",
+        "src/crypto/sha256-prf.c",
+        "src/crypto/sha256-tlsprf.c",
+        "src/crypto/sha384-kdf.c",
+        "src/crypto/sha384-prf.c",
+        "src/crypto/sha512-kdf.c",
+        "src/crypto/sha512-prf.c",
+        "src/crypto/tls_openssl.c",
+        "src/crypto/tls_openssl_ocsp.c",
+        "src/drivers/driver_common.c",
+        "src/drivers/driver_nl80211.c",
+        "src/drivers/driver_nl80211_android.c",
+        "src/drivers/driver_nl80211_capa.c",
+        "src/drivers/driver_nl80211_event.c",
+        "src/drivers/driver_nl80211_monitor.c",
+        "src/drivers/driver_nl80211_scan.c",
+        "src/drivers/drivers.c",
+        "src/drivers/linux_ioctl.c",
+        "src/drivers/netlink.c",
+        "src/drivers/rfkill.c",
+        "src/eap_common/chap.c",
+        "src/eap_common/eap_common.c",
+        "src/eap_common/eap_peap_common.c",
+        "src/eap_common/eap_pwd_common.c",
+        "src/eap_common/eap_sim_common.c",
+        "src/eap_common/eap_wsc_common.c",
+        "src/eap_peer/eap.c",
+        "src/eap_peer/eap_aka.c",
+        "src/eap_peer/eap_gtc.c",
+        "src/eap_peer/eap_leap.c",
+        "src/eap_peer/eap_md5.c",
+        "src/eap_peer/eap_methods.c",
+        "src/eap_peer/eap_mschapv2.c",
+        "src/eap_peer/eap_otp.c",
+        "src/eap_peer/eap_peap.c",
+        "src/eap_peer/eap_pwd.c",
+        "src/eap_peer/eap_sim.c",
+        "src/eap_peer/eap_tls.c",
+        "src/eap_peer/eap_tls_common.c",
+        "src/eap_peer/eap_ttls.c",
+        "src/eap_peer/eap_wsc.c",
+        "src/eap_peer/mschapv2.c",
+        "src/eap_server/eap_server.c",
+        "src/eap_server/eap_server_identity.c",
+        "src/eap_server/eap_server_methods.c",
+        "src/eap_server/eap_server_wsc.c",
+        "src/eapol_auth/eapol_auth_sm.c",
+        "src/eapol_supp/eapol_supp_sm.c",
+        "src/l2_packet/l2_packet_linux.c",
+        "src/p2p/p2p.c",
+        "src/p2p/p2p_build.c",
+        "src/p2p/p2p_dev_disc.c",
+        "src/p2p/p2p_go_neg.c",
+        "src/p2p/p2p_group.c",
+        "src/p2p/p2p_invitation.c",
+        "src/p2p/p2p_parse.c",
+        "src/p2p/p2p_pd.c",
+        "src/p2p/p2p_sd.c",
+        "src/p2p/p2p_utils.c",
+        "src/pasn/pasn_common.c",
+        "src/pasn/pasn_initiator.c",
+        "src/pasn/pasn_responder.c",
+        "src/rsn_supp/pmksa_cache.c",
+        "src/rsn_supp/preauth.c",
+        "src/rsn_supp/tdls.c",
+        "src/rsn_supp/wpa.c",
+        "src/rsn_supp/wpa_ft.c",
+        "src/rsn_supp/wpa_ie.c",
+        "src/tls/asn1.c",
+        "src/utils/base64.c",
+        "src/utils/bitfield.c",
+        "src/utils/common.c",
+        "src/utils/config.c",
+        "src/utils/crc32.c",
+        "src/utils/eloop.c",
+        "src/utils/ip_addr.c",
+        "src/utils/json.c",
+        "src/utils/os_unix.c",
+        "src/utils/radiotap.c",
+        "src/utils/uuid.c",
+        "src/utils/wpa_debug.c",
+        "src/utils/wpabuf.c",
+        "src/wps/http_client.c",
+        "src/wps/http_server.c",
+        "src/wps/httpread.c",
+        "src/wps/ndef.c",
+        "src/wps/upnp_xml.c",
+        "src/wps/wps.c",
+        "src/wps/wps_attr_build.c",
+        "src/wps/wps_attr_parse.c",
+        "src/wps/wps_attr_process.c",
+        "src/wps/wps_common.c",
+        "src/wps/wps_dev_attr.c",
+        "src/wps/wps_enrollee.c",
+        "src/wps/wps_er.c",
+        "src/wps/wps_er_ssdp.c",
+        "src/wps/wps_registrar.c",
+        "src/wps/wps_upnp.c",
+        "src/wps/wps_upnp_ap.c",
+        "src/wps/wps_upnp_event.c",
+        "src/wps/wps_upnp_ssdp.c",
+        "src/wps/wps_upnp_web.c",
+    ] + select(soong_config_variable("wpa_supplicant_8", "hostapd_11ax"), {
+        true: ["src/ap/ieee802_11_he.c"],
+        default: [],
+    }),
+    defaults: [
+        "wpa_supplicant_driver_srcs_default",
+    ],
+}
+
+cc_binary {
+    name: "wpa_cli",
+    proprietary: true,
+    srcs: [
+        "wpa_cli.c",
+        "src/common/cli.c",
+        "src/common/wpa_ctrl.c",
+        "src/utils/common.c",
+        "src/utils/edit.c",
+        "src/utils/eloop.c",
+        "src/utils/os_unix.c",
+        "src/utils/wpa_debug.c",
+    ],
+    shared_libs: [
+        "libcutils",
+        "liblog",
+    ],
+    defaults: [
+        "wpa_supplicant_cflags_default",
+        "wpa_supplicant_includes_default",
+    ],
+}
+
+soong_config_module_type {
+    name: "wpa_supplicant_cc_binary",
+    module_type: "cc_binary",
+    config_namespace: "wpa_supplicant_8",
+    value_variables: [
+        "board_wpa_supplicant_private_lib",
+    ],
+    bool_variables: [
+        "wifi_hidl_unified_supplicant_service_rc_entry",
+    ],
+    properties: [
+        "init_rc",
+        "static_libs",
+    ],
+}
+
+wpa_supplicant_cc_binary {
+    name: "wpa_supplicant",
+    proprietary: true,
+    relative_install_path: "hw",
+    // vintf_fragments: wpa_supplicant only
+    // vintf_fragments: ["aidl/android.hardware.wifi.supplicant.xml"],
+    required: [
+        "android.hardware.wifi.supplicant.xml",
+    ],
+    // wpa_supplicant only
+    static_libs: [
+        "libwpa_aidl",
+    ],
+    shared_libs: [
+        // Share between wpa_supplicant and wpa_supplicant_macsec
+        "libc",
+        "libcrypto",
+        "libcutils",
+        "libkeystore-engine-wifi-hidl",
+        "liblog",
+        "libnl",
+        "libssl",
+    ] + [
+        // wpa_supplicant only
+        "android.hardware.wifi.supplicant-V4-ndk",
+        "android.system.keystore2-V1-ndk",
+        "libbase",
+        "libbinder_ndk",
+        "libutils",
+    ],
+    defaults: [
+        "wpa_supplicant_srcs_default",
+        "wpa_supplicant_cflags_default",
+        "wpa_supplicant_includes_default",
+    ],
+    soong_config_variables: {
+        board_wpa_supplicant_private_lib: {
+            static_libs: ["%s"],
+        },
+        // init_rc: wpa_supplicant only
+        wifi_hidl_unified_supplicant_service_rc_entry: {
+            init_rc: ["aidl/vendor/android.hardware.wifi.supplicant-service.rc"],
+        },
+    },
+}
+
+wpa_supplicant_cc_binary {
+    name: "wpa_supplicant_macsec",
+    proprietary: true,
+    relative_install_path: "hw",
+    srcs: [
+        // wpa_supplicant_macsec only
+        ":wpa_supplicant_macsec_extra_driver_srcs",
+        "wpas_kay.c",
+        "src/ap/wpa_auth_kay.c",
+        "src/pae/ieee802_1x_cp.c",
+        "src/pae/ieee802_1x_kay.c",
+        "src/pae/ieee802_1x_key.c",
+        "src/pae/ieee802_1x_secy_ops.c",
+        "src/pae/aidl/aidl_psk.cpp",
+    ],
+    shared_libs: [
+        // Share between wpa_supplicant and wpa_supplicant_macsec
+        "libc",
+        "libcrypto",
+        "libcutils",
+        "libkeystore-engine-wifi-hidl",
+        "liblog",
+        "libnl",
+        "libssl",
+    ] + [
+        // wpa_supplicant_macsec only
+        "android.hardware.macsec-V1-ndk",
+        "libbinder_ndk",
+    ],
+    cflags: [
+        "-DCONFIG_AIDL_MACSEC_PSK_METHODS",
+        "-DCONFIG_DRIVER_MACSEC_LINUX",
+        "-DCONFIG_MACSEC",
+    ],
+    local_include_dirs: [
+        // wpa_supplicant_macsec only
+        "aidl",
+    ],
+    defaults: [
+        "wpa_supplicant_srcs_default",
+        "wpa_supplicant_includes_default",
+        "wpa_supplicant_no_aidl_cflags_default",
+    ],
+    soong_config_variables: {
+        board_wpa_supplicant_private_lib: {
+            static_libs: ["%s"],
+        },
+    },
+}
+
+wpa_supplicant_cc_binary {
+    name: "wpa_supplicant_mainline",
+    shared_libs: [
+        "android.system.wifi.mainline_supplicant-ndk",
+        "libbase",
+        "libbinder_ndk",
+        "libc",
+        "libcrypto",
+        "libcutils_sockets",
+        "liblog",
+        "libnl",
+        "libssl",
+    ],
+    static_libs: [
+        "mainline_supplicant_aidl_bp",
+    ],
+    defaults: [
+        "wpa_supplicant_srcs_default",
+        "wpa_supplicant_includes_default",
+        "wpa_supplicant_mainline_cflags_default",
+    ],
+    apex_available: [
+        "//apex_available:platform",
+        "com.android.wifi",
+    ],
+    min_sdk_version: "30",
+}
+
+cc_library_shared {
+    name: "libwpa_client",
+    proprietary: true,
+    srcs: [
+        "src/common/wpa_ctrl.c",
+        "src/utils/os_unix.c",
+    ],
+    shared_libs: [
+        "libc",
+        "libcutils",
+        "liblog",
+    ],
+    defaults: [
+        "wpa_supplicant_cflags_default",
+        "wpa_supplicant_includes_default",
+    ],
+}
+
+//## Aidl service library ###
+//#######################
+cc_library_static {
+    name: "libwpa_aidl",
+    vendor: true,
+    cppflags: [
+        "-Wall",
+        "-Werror",
+        "-Wno-unused-parameter",
+        "-Wno-unused-private-field",
+        "-Wno-unused-variable",
+    ],
+    srcs: [
+        "aidl/vendor/aidl.cpp",
+        "aidl/vendor/aidl_manager.cpp",
+        "aidl/vendor/certificate_utils.cpp",
+        "aidl/vendor/iface_config_utils.cpp",
+        "aidl/vendor/p2p_iface.cpp",
+        "aidl/vendor/p2p_network.cpp",
+        "aidl/vendor/sta_iface.cpp",
+        "aidl/vendor/sta_network.cpp",
+        "aidl/vendor/supplicant.cpp",
+    ],
+    shared_libs: [
+        "android.hardware.wifi.supplicant-V4-ndk",
+        "android.system.keystore2-V1-ndk",
+        "libbinder_ndk",
+        "libbase",
+        "libutils",
+        "liblog",
+        "libssl",
+    ],
+    export_include_dirs: ["aidl"],
+    defaults: [
+        "wpa_supplicant_cflags_default",
+        "wpa_supplicant_includes_default",
+    ],
+}
diff --git a/wpa_supplicant/aidl/mainline/Android.bp b/wpa_supplicant/aidl/mainline/Android.bp
new file mode 100644
index 0000000..a2f5370
--- /dev/null
+++ b/wpa_supplicant/aidl/mainline/Android.bp
@@ -0,0 +1,67 @@
+// Copyright (C) 2024 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.
+
+cc_library_headers {
+    name: "mainline_supplicant_aidl_headers",
+    export_include_dirs: ["."],
+    apex_available: [
+        "//apex_available:platform",
+        "com.android.wifi",
+    ],
+    min_sdk_version: "30",
+}
+
+cc_library_static {
+    name: "mainline_supplicant_aidl_bp",
+    srcs: ["*.cpp"],
+    shared_libs: [
+        "android.system.wifi.mainline_supplicant-ndk",
+        "libbase",
+        "libbinder_ndk",
+    ],
+    cppflags: [
+        "-Wall",
+        "-Werror",
+        "-Wno-unused-parameter",
+        "-Wno-unused-private-field",
+        "-Wno-unused-variable",
+    ],
+    header_libs: [
+        // Shared headers with vendor supplicant
+        "libwpa_shared_aidl_headers_mainline",
+        // Mainline supplicant headers
+        "mainline_supplicant_aidl_headers",
+        // Core supplicant headers
+        "wpa_supplicant_headers_mainline",
+    ],
+    apex_available: [
+        "//apex_available:platform",
+        "com.android.wifi",
+    ],
+    min_sdk_version: "30",
+}
+
+prebuilt_etc {
+    name: "mainline_supplicant_rc",
+    src: "config/mainline_supplicant.rc",
+    filename: "mainline_supplicant.rc",
+    installable: false,
+}
+
+prebuilt_etc {
+    name: "mainline_supplicant_conf",
+    src: "config/mainline_supplicant.conf",
+    filename: "mainline_supplicant.conf",
+    installable: false,
+}
diff --git a/wpa_supplicant/aidl/mainline/config/mainline_supplicant.conf b/wpa_supplicant/aidl/mainline/config/mainline_supplicant.conf
new file mode 100644
index 0000000..57eb059
--- /dev/null
+++ b/wpa_supplicant/aidl/mainline/config/mainline_supplicant.conf
@@ -0,0 +1,2 @@
+ctrl_interface=/data/misc/wifi/mainline_supplicant/sockets
+p2p_disabled=1
diff --git a/wpa_supplicant/aidl/mainline/config/mainline_supplicant.rc b/wpa_supplicant/aidl/mainline/config/mainline_supplicant.rc
new file mode 100644
index 0000000..8c436c6
--- /dev/null
+++ b/wpa_supplicant/aidl/mainline/config/mainline_supplicant.rc
@@ -0,0 +1,9 @@
+service wpa_supplicant_mainline /apex/com.android.wifi/bin/wpa_supplicant_mainline \
+    -O/data/misc/wifi/mainline_supplicant/sockets -dd \
+    -g@android:wpa_wlan0
+    interface aidl wifi_mainline_supplicant
+    class main
+    user root
+    socket wpa_wlan0 dgram 660 wifi wifi
+    disabled
+    oneshot
diff --git a/wpa_supplicant/aidl/mainline/mainline_supplicant.cpp b/wpa_supplicant/aidl/mainline/mainline_supplicant.cpp
new file mode 100644
index 0000000..dd2babe
--- /dev/null
+++ b/wpa_supplicant/aidl/mainline/mainline_supplicant.cpp
@@ -0,0 +1,85 @@
+/*
+ * WPA Supplicant - Mainline supplicant AIDL implementation
+ * Copyright (c) 2024, Google Inc. All rights reserved.
+ *
+ * This software may be distributed under the terms of the BSD license.
+ * See README for more details.
+ */
+
+#include "aidl/shared/shared_utils.h"
+#include "mainline_supplicant.h"
+#include "utils.h"
+
+using ::ndk::ScopedAStatus;
+
+const std::string kConfigFilePath = "/apex/com.android.wifi/etc/mainline_supplicant.conf";
+
+MainlineSupplicant::MainlineSupplicant(struct wpa_global* global) {
+    wpa_global_ = global;
+}
+
+ndk::ScopedAStatus MainlineSupplicant::addUsdInterface(const std::string& ifaceName) {
+    if (ifaceName.empty()) {
+        wpa_printf(MSG_ERROR, "Empty iface name provided");
+        return createStatus(SupplicantStatusCode::FAILURE_ARGS_INVALID);
+    }
+
+    if (active_usd_ifaces_.find(ifaceName) != active_usd_ifaces_.end()) {
+        wpa_printf(MSG_INFO, "Interface %s already exists", ifaceName.c_str());
+        return ndk::ScopedAStatus::ok();
+    }
+
+    if (ensureConfigFileExistsAtPath(kConfigFilePath) != 0) {
+        wpa_printf(MSG_ERROR, "Unable to find config file at %s", kConfigFilePath.c_str());
+        return createStatusWithMsg(
+            SupplicantStatusCode::FAILURE_UNKNOWN, "Config file does not exist");
+    }
+
+    struct wpa_interface iface_params = {};
+    iface_params.driver = kIfaceDriverName;
+    iface_params.ifname = ifaceName.c_str();
+    iface_params.confname = kConfigFilePath.c_str();
+
+    struct wpa_supplicant* wpa_s = wpa_supplicant_add_iface(wpa_global_, &iface_params, NULL);
+    if (!wpa_s) {
+        wpa_printf(MSG_ERROR, "Unable to add interface %s", ifaceName.c_str());
+        return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
+    }
+
+    wpa_printf(MSG_INFO, "Interface %s was added successfully", ifaceName.c_str());
+    active_usd_ifaces_.insert(ifaceName);
+    return ndk::ScopedAStatus::ok();
+}
+
+ndk::ScopedAStatus MainlineSupplicant::removeUsdInterface(const std::string& ifaceName) {
+    if (ifaceName.empty()) {
+        wpa_printf(MSG_ERROR, "Empty iface name provided");
+        return createStatus(SupplicantStatusCode::FAILURE_ARGS_INVALID);
+    }
+
+    if (active_usd_ifaces_.find(ifaceName) == active_usd_ifaces_.end()) {
+        wpa_printf(MSG_ERROR, "Interface %s does not exist", ifaceName.c_str());
+        return createStatus(SupplicantStatusCode::FAILURE_IFACE_UNKNOWN);
+    }
+
+    struct wpa_supplicant* wpa_s =
+        wpa_supplicant_get_iface(wpa_global_, ifaceName.c_str());
+    if (!wpa_s) {
+        wpa_printf(MSG_ERROR, "Interface %s does not exist", ifaceName.c_str());
+        return createStatus(SupplicantStatusCode::FAILURE_IFACE_UNKNOWN);
+    }
+    if (wpa_supplicant_remove_iface(wpa_global_, wpa_s, 0)) {
+        wpa_printf(MSG_ERROR, "Unable to remove interface %s", ifaceName.c_str());
+        return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
+    }
+
+    wpa_printf(MSG_INFO, "Interface %s was removed successfully", ifaceName.c_str());
+    active_usd_ifaces_.erase(ifaceName);
+    return ndk::ScopedAStatus::ok();
+}
+
+ndk::ScopedAStatus MainlineSupplicant::terminate() {
+    wpa_printf(MSG_INFO, "Terminating...");
+    wpa_supplicant_terminate_proc(wpa_global_);
+    return ndk::ScopedAStatus::ok();
+}
diff --git a/wpa_supplicant/aidl/mainline/mainline_supplicant.h b/wpa_supplicant/aidl/mainline/mainline_supplicant.h
new file mode 100644
index 0000000..38a355f
--- /dev/null
+++ b/wpa_supplicant/aidl/mainline/mainline_supplicant.h
@@ -0,0 +1,43 @@
+/*
+ * WPA Supplicant - Mainline supplicant AIDL implementation
+ * Copyright (c) 2024, Google Inc. All rights reserved.
+ *
+ * This software may be distributed under the terms of the BSD license.
+ * See README for more details.
+ */
+
+#ifndef MAINLINE_SUPPLICANT_IMPL_H
+#define MAINLINE_SUPPLICANT_IMPL_H
+
+#include <set>
+
+#include <aidl/android/system/wifi/mainline_supplicant/BnMainlineSupplicant.h>
+#include <aidl/android/system/wifi/mainline_supplicant/SupplicantStatusCode.h>
+
+extern "C"
+{
+#include "utils/common.h"
+#include "utils/includes.h"
+#include "utils/wpa_debug.h"
+#include "wpa_supplicant_i.h"
+#include "scan.h"
+}
+
+using ::aidl::android::system::wifi::mainline_supplicant::BnMainlineSupplicant;
+using ::aidl::android::system::wifi::mainline_supplicant::SupplicantStatusCode;
+
+class MainlineSupplicant : public BnMainlineSupplicant {
+    public:
+        MainlineSupplicant(struct wpa_global* global);
+        ndk::ScopedAStatus addUsdInterface(const std::string& ifaceName);
+        ndk::ScopedAStatus removeUsdInterface(const std::string& ifaceName);
+        ndk::ScopedAStatus terminate();
+
+    private:
+        // Raw pointer to the global structure maintained by the core
+        struct wpa_global* wpa_global_;
+        // Names of all active USD interfaces
+        std::set<std::string> active_usd_ifaces_;
+};
+
+#endif  // MAINLINE_SUPPLICANT_IMPL_H
diff --git a/wpa_supplicant/aidl/mainline/service.cpp b/wpa_supplicant/aidl/mainline/service.cpp
new file mode 100644
index 0000000..da343ea
--- /dev/null
+++ b/wpa_supplicant/aidl/mainline/service.cpp
@@ -0,0 +1,91 @@
+/*
+ * WPA Supplicant - Mainline supplicant service
+ * Copyright (c) 2024, Google Inc. All rights reserved.
+ *
+ * This software may be distributed under the terms of the BSD license.
+ * See README for more details.
+ */
+
+#include <android/binder_manager.h>
+#include <android/binder_process.h>
+
+#include "mainline_supplicant.h"
+
+extern "C"
+{
+#include "aidl_i.h"
+#include "service.h"
+#include "utils/common.h"
+#include "utils/eloop.h"
+#include "utils/includes.h"
+#include "utils/wpa_debug.h"
+}
+
+using ::ndk::SharedRefBase;
+
+/* Handler for requests to the service */
+void aidl_sock_handler(int /* sock */, void * /* eloop_ctx */, void * /* sock_ctx */) {
+    // Suppress warning, since this service is only available after Android V
+    if (__builtin_available(android __ANDROID_API_V__, *)) {
+        ABinderProcess_handlePolledCommands();
+    }
+}
+
+bool register_service(struct wpa_global *global) {
+    wpa_printf(MSG_INFO, "Registering as a lazy service");
+    std::string service_name = "wifi_mainline_supplicant";
+    std::shared_ptr<MainlineSupplicant> service = SharedRefBase::make<MainlineSupplicant>(global);
+
+    // Suppress warning, since this service is only available after Android V
+    if (__builtin_available(android __ANDROID_API_V__, *)) {
+        int status =
+            AServiceManager_registerLazyService(service->asBinder().get(), service_name.c_str());
+        if (status != EX_NONE) {
+            wpa_printf(MSG_ERROR, "Registration failed with status %d", status);
+        }
+        return status == EX_NONE;
+    }
+    return false;
+}
+
+struct wpas_aidl_priv *mainline_aidl_init(struct wpa_global *global) {
+    wpa_printf(MSG_INFO, "Initializing the mainline supplicant service");
+    struct wpas_aidl_priv *priv = (wpas_aidl_priv *)os_zalloc(sizeof(*priv));
+    if (!priv) {
+        wpa_printf(MSG_ERROR, "Unable to allocate the global AIDL object");
+        return NULL;
+    }
+    priv->global = global;
+
+    // Suppress warning, since this service is only available after Android V
+    if (__builtin_available(android __ANDROID_API_V__, *)) {
+        ABinderProcess_setupPolling(&priv->aidl_fd);
+    }
+    if (priv->aidl_fd < 0) {
+        wpa_printf(MSG_ERROR, "Unable to set up polling");
+        mainline_aidl_deinit(priv);
+        return NULL;
+    }
+
+    if (eloop_register_read_sock(priv->aidl_fd, aidl_sock_handler, global, priv) < 0) {
+        wpa_printf(MSG_ERROR, "Unable to register eloop read socket");
+        mainline_aidl_deinit(priv);
+        return NULL;
+    }
+
+    if (!register_service(global)) {
+        wpa_printf(MSG_ERROR, "Unable to register service");
+        mainline_aidl_deinit(priv);
+        return NULL;
+    }
+
+    wpa_printf(MSG_INFO, "AIDL setup is complete");
+    return priv;
+}
+
+void mainline_aidl_deinit(struct wpas_aidl_priv *priv) {
+    if (!priv) return;
+    wpa_printf(MSG_INFO, "Deiniting the mainline supplicant service");
+    eloop_unregister_read_sock(priv->aidl_fd);
+    os_free(priv);
+}
diff --git a/wpa_supplicant/aidl/mainline/service.h b/wpa_supplicant/aidl/mainline/service.h
new file mode 100644
index 0000000..6d213e7
--- /dev/null
+++ b/wpa_supplicant/aidl/mainline/service.h
@@ -0,0 +1,27 @@
+/*
+ * WPA Supplicant - Mainline supplicant service
+ * Copyright (c) 2024, Google Inc. All rights reserved.
+ *
+ * This software may be distributed under the terms of the BSD license.
+ * See README for more details.
+ */
+
+#ifndef MAINLINE_SUPPLICANT_SERVICE_H
+#define MAINLINE_SUPPLICANT_SERVICE_H
+
+#ifdef _cplusplus
+extern "C"
+{
+#endif  // _cplusplus
+
+struct wpas_aidl_priv;
+struct wpa_global;
+
+struct wpas_aidl_priv *mainline_aidl_init(struct wpa_global *global);
+void mainline_aidl_deinit(struct wpas_aidl_priv *priv);
+
+#ifdef _cplusplus
+}
+#endif  // _cplusplus
+
+#endif  // MAINLINE_SUPPLICANT_SERVICE_H
diff --git a/wpa_supplicant/aidl/mainline/utils.h b/wpa_supplicant/aidl/mainline/utils.h
new file mode 100644
index 0000000..703b9ee
--- /dev/null
+++ b/wpa_supplicant/aidl/mainline/utils.h
@@ -0,0 +1,25 @@
+/*
+ * WPA Supplicant - Utilities for the mainline supplicant
+ * Copyright (c) 2024, Google Inc. All rights reserved.
+ *
+ * This software may be distributed under the terms of the BSD license.
+ * See README for more details.
+ */
+
+#ifndef MAINLINE_SUPPLICANT_UTILS_H
+#define MAINLINE_SUPPLICANT_UTILS_H
+
+#include <aidl/android/system/wifi/mainline_supplicant/SupplicantStatusCode.h>
+
+inline ndk::ScopedAStatus createStatus(SupplicantStatusCode statusCode) {
+	return ndk::ScopedAStatus::fromServiceSpecificError(
+		static_cast<int32_t>(statusCode));
+}
+
+inline ndk::ScopedAStatus createStatusWithMsg(
+	    SupplicantStatusCode statusCode, std::string msg) {
+	return ndk::ScopedAStatus::fromServiceSpecificErrorWithMessage(
+		static_cast<int32_t>(statusCode), msg.c_str());
+}
+
+#endif // MAINLINE_SUPPLICANT_UTILS_H
diff --git a/wpa_supplicant/aidl/shared/Android.bp b/wpa_supplicant/aidl/shared/Android.bp
new file mode 100644
index 0000000..25cb5fa
--- /dev/null
+++ b/wpa_supplicant/aidl/shared/Android.bp
@@ -0,0 +1,29 @@
+// Copyright (C) 2024 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.
+
+cc_library_headers {
+    name: "libwpa_shared_aidl_headers_vendor",
+    export_include_dirs: ["."],
+    soc_specific: true,
+}
+
+cc_library_headers {
+    name: "libwpa_shared_aidl_headers_mainline",
+    export_include_dirs: ["."],
+    apex_available: [
+        "//apex_available:platform",
+        "com.android.wifi",
+    ],
+    min_sdk_version: "30",
+}
diff --git a/wpa_supplicant/aidl/aidl_i.h b/wpa_supplicant/aidl/shared/aidl_i.h
similarity index 100%
rename from wpa_supplicant/aidl/aidl_i.h
rename to wpa_supplicant/aidl/shared/aidl_i.h
diff --git a/wpa_supplicant/aidl/shared/shared_utils.h b/wpa_supplicant/aidl/shared/shared_utils.h
new file mode 100644
index 0000000..97676f4
--- /dev/null
+++ b/wpa_supplicant/aidl/shared/shared_utils.h
@@ -0,0 +1,49 @@
+/*
+ * WPA Supplicant - Shared utility functions and constants
+ * Copyright (c) 2024, Google Inc. All rights reserved.
+ *
+ * This software may be distributed under the terms of the BSD license.
+ * See README for more details.
+ */
+
+#ifndef SHARED_UTILS_H
+#define SHARED_UTILS_H
+
+#include <android-base/file.h>
+#include <fcntl.h>
+
+extern "C"
+{
+#include "utils/common.h"
+}
+
+constexpr char kIfaceDriverName[] = "nl80211";
+constexpr mode_t kConfigFileMode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP;
+
+/**
+ * Ensure that the config file at |config_file_path| exists.
+ * Returns 0 on success, or errno otherwise.
+ */
+int ensureConfigFileExistsAtPath(const std::string& config_file_path) {
+    int ret = access(config_file_path.c_str(), R_OK);
+    if (ret == 0) {
+        return 0;
+    }
+    if (errno == EACCES) {
+        ret = chmod(config_file_path.c_str(), kConfigFileMode);
+        if (ret == 0) {
+            return 0;
+        } else {
+            wpa_printf(
+                MSG_ERROR, "Cannot set RW to %s. Errno: %s",
+                config_file_path.c_str(), strerror(errno));
+        }
+    } else if (errno != ENOENT) {
+        wpa_printf(
+            MSG_ERROR, "Cannot access %s. Errno: %s",
+            config_file_path.c_str(), strerror(errno));
+    }
+    return errno;
+}
+
+#endif // SHARED_UTILS_H
diff --git a/wpa_supplicant/aidl/.clang-format b/wpa_supplicant/aidl/vendor/.clang-format
similarity index 100%
rename from wpa_supplicant/aidl/.clang-format
rename to wpa_supplicant/aidl/vendor/.clang-format
diff --git a/wpa_supplicant/aidl/Android.bp b/wpa_supplicant/aidl/vendor/Android.bp
similarity index 97%
rename from wpa_supplicant/aidl/Android.bp
rename to wpa_supplicant/aidl/vendor/Android.bp
index 5976ff9..a972dd6 100644
--- a/wpa_supplicant/aidl/Android.bp
+++ b/wpa_supplicant/aidl/vendor/Android.bp
@@ -56,6 +56,7 @@
     header_libs: [
         "wpa_supplicant_headers",
         "libwpa_aidl_headers",
+        "libwpa_shared_aidl_headers_vendor",
     ],
 }
 
diff --git a/wpa_supplicant/aidl/aidl.cpp b/wpa_supplicant/aidl/vendor/aidl.cpp
similarity index 99%
rename from wpa_supplicant/aidl/aidl.cpp
rename to wpa_supplicant/aidl/vendor/aidl.cpp
index d1cf891..a0446fe 100644
--- a/wpa_supplicant/aidl/aidl.cpp
+++ b/wpa_supplicant/aidl/vendor/aidl.cpp
@@ -14,7 +14,7 @@
 extern "C"
 {
 #include "aidl.h"
-#include "aidl_i.h"
+#include "aidl/shared/aidl_i.h"
 #include "utils/common.h"
 #include "utils/eloop.h"
 #include "utils/includes.h"
diff --git a/wpa_supplicant/aidl/aidl.h b/wpa_supplicant/aidl/vendor/aidl.h
similarity index 100%
rename from wpa_supplicant/aidl/aidl.h
rename to wpa_supplicant/aidl/vendor/aidl.h
diff --git a/wpa_supplicant/aidl/aidl_manager.cpp b/wpa_supplicant/aidl/vendor/aidl_manager.cpp
similarity index 100%
rename from wpa_supplicant/aidl/aidl_manager.cpp
rename to wpa_supplicant/aidl/vendor/aidl_manager.cpp
diff --git a/wpa_supplicant/aidl/aidl_manager.h b/wpa_supplicant/aidl/vendor/aidl_manager.h
similarity index 100%
rename from wpa_supplicant/aidl/aidl_manager.h
rename to wpa_supplicant/aidl/vendor/aidl_manager.h
diff --git a/wpa_supplicant/aidl/aidl_return_util.h b/wpa_supplicant/aidl/vendor/aidl_return_util.h
similarity index 100%
rename from wpa_supplicant/aidl/aidl_return_util.h
rename to wpa_supplicant/aidl/vendor/aidl_return_util.h
diff --git a/wpa_supplicant/aidl/android.hardware.wifi.supplicant-service.rc b/wpa_supplicant/aidl/vendor/android.hardware.wifi.supplicant-service.rc
similarity index 100%
rename from wpa_supplicant/aidl/android.hardware.wifi.supplicant-service.rc
rename to wpa_supplicant/aidl/vendor/android.hardware.wifi.supplicant-service.rc
diff --git a/wpa_supplicant/aidl/android.hardware.wifi.supplicant.xml b/wpa_supplicant/aidl/vendor/android.hardware.wifi.supplicant.xml
similarity index 100%
rename from wpa_supplicant/aidl/android.hardware.wifi.supplicant.xml
rename to wpa_supplicant/aidl/vendor/android.hardware.wifi.supplicant.xml
diff --git a/wpa_supplicant/aidl/certificate_utils.cpp b/wpa_supplicant/aidl/vendor/certificate_utils.cpp
similarity index 100%
rename from wpa_supplicant/aidl/certificate_utils.cpp
rename to wpa_supplicant/aidl/vendor/certificate_utils.cpp
diff --git a/wpa_supplicant/aidl/certificate_utils.h b/wpa_supplicant/aidl/vendor/certificate_utils.h
similarity index 100%
rename from wpa_supplicant/aidl/certificate_utils.h
rename to wpa_supplicant/aidl/vendor/certificate_utils.h
diff --git a/wpa_supplicant/aidl/iface_config_utils.cpp b/wpa_supplicant/aidl/vendor/iface_config_utils.cpp
similarity index 100%
rename from wpa_supplicant/aidl/iface_config_utils.cpp
rename to wpa_supplicant/aidl/vendor/iface_config_utils.cpp
diff --git a/wpa_supplicant/aidl/iface_config_utils.h b/wpa_supplicant/aidl/vendor/iface_config_utils.h
similarity index 100%
rename from wpa_supplicant/aidl/iface_config_utils.h
rename to wpa_supplicant/aidl/vendor/iface_config_utils.h
diff --git a/wpa_supplicant/aidl/misc_utils.h b/wpa_supplicant/aidl/vendor/misc_utils.h
similarity index 100%
rename from wpa_supplicant/aidl/misc_utils.h
rename to wpa_supplicant/aidl/vendor/misc_utils.h
diff --git a/wpa_supplicant/aidl/p2p_iface.cpp b/wpa_supplicant/aidl/vendor/p2p_iface.cpp
similarity index 100%
rename from wpa_supplicant/aidl/p2p_iface.cpp
rename to wpa_supplicant/aidl/vendor/p2p_iface.cpp
diff --git a/wpa_supplicant/aidl/p2p_iface.h b/wpa_supplicant/aidl/vendor/p2p_iface.h
similarity index 100%
rename from wpa_supplicant/aidl/p2p_iface.h
rename to wpa_supplicant/aidl/vendor/p2p_iface.h
diff --git a/wpa_supplicant/aidl/p2p_network.cpp b/wpa_supplicant/aidl/vendor/p2p_network.cpp
similarity index 100%
rename from wpa_supplicant/aidl/p2p_network.cpp
rename to wpa_supplicant/aidl/vendor/p2p_network.cpp
diff --git a/wpa_supplicant/aidl/p2p_network.h b/wpa_supplicant/aidl/vendor/p2p_network.h
similarity index 100%
rename from wpa_supplicant/aidl/p2p_network.h
rename to wpa_supplicant/aidl/vendor/p2p_network.h
diff --git a/wpa_supplicant/aidl/sta_iface.cpp b/wpa_supplicant/aidl/vendor/sta_iface.cpp
similarity index 100%
rename from wpa_supplicant/aidl/sta_iface.cpp
rename to wpa_supplicant/aidl/vendor/sta_iface.cpp
diff --git a/wpa_supplicant/aidl/sta_iface.h b/wpa_supplicant/aidl/vendor/sta_iface.h
similarity index 100%
rename from wpa_supplicant/aidl/sta_iface.h
rename to wpa_supplicant/aidl/vendor/sta_iface.h
diff --git a/wpa_supplicant/aidl/sta_network.cpp b/wpa_supplicant/aidl/vendor/sta_network.cpp
similarity index 100%
rename from wpa_supplicant/aidl/sta_network.cpp
rename to wpa_supplicant/aidl/vendor/sta_network.cpp
diff --git a/wpa_supplicant/aidl/sta_network.h b/wpa_supplicant/aidl/vendor/sta_network.h
similarity index 100%
rename from wpa_supplicant/aidl/sta_network.h
rename to wpa_supplicant/aidl/vendor/sta_network.h
diff --git a/wpa_supplicant/aidl/supplicant.cpp b/wpa_supplicant/aidl/vendor/supplicant.cpp
similarity index 96%
rename from wpa_supplicant/aidl/supplicant.cpp
rename to wpa_supplicant/aidl/vendor/supplicant.cpp
index ae1943f..0cb2342 100644
--- a/wpa_supplicant/aidl/supplicant.cpp
+++ b/wpa_supplicant/aidl/vendor/supplicant.cpp
@@ -12,6 +12,8 @@
 #include "supplicant.h"
 #include "p2p_iface.h"
 
+#include "aidl/shared/shared_utils.h"
+
 #include <android-base/file.h>
 #include <fcntl.h>
 #include <sys/stat.h>
@@ -22,8 +24,6 @@
 // Note: This may differ for other OEM's. So, modify this accordingly.
 // When wpa_supplicant is in its APEX, overlay/template configurations should be
 // loaded from the same APEX.
-constexpr char kIfaceDriverName[] = "nl80211";
-
 constexpr char kStaIfaceConfPath[] =
 	"/data/vendor/wifi/wpa/wpa_supplicant.conf";
 constexpr char kStaIfaceConfOverlayPath[] =
@@ -42,7 +42,6 @@
 
 constexpr char kOldStaIfaceConfPath[] = "/data/misc/wifi/wpa_supplicant.conf";
 constexpr char kOldP2pIfaceConfPath[] = "/data/misc/wifi/p2p_supplicant.conf";
-constexpr mode_t kConfigFileMode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP;
 
 std::string resolveVendorConfPath(const std::string& conf_path)
 {
@@ -114,26 +113,15 @@
 	const std::string& config_file_path,
 	const std::string& old_config_file_path)
 {
-	int ret = access(config_file_path.c_str(), R_OK | W_OK);
+	// Check if config file already exists at |config_file_path|
+	int ret = ensureConfigFileExistsAtPath(config_file_path);
 	if (ret == 0) {
+		wpa_printf(MSG_INFO, "Config file already exists at %s", config_file_path.c_str());
 		return 0;
-	}
-	if (errno == EACCES) {
-		ret = chmod(config_file_path.c_str(), kConfigFileMode);
-		if (ret == 0) {
-			return 0;
-		} else {
-			wpa_printf(
-				MSG_ERROR, "Cannot set RW to %s. Errno: %s",
-				config_file_path.c_str(), strerror(errno));
-			return -1;
-		}
-	} else if (errno != ENOENT) {
-		wpa_printf(
-			MSG_ERROR, "Cannot acces %s. Errno: %s",
-			config_file_path.c_str(), strerror(errno));
+	} else if (ret != ENOENT) {
 		return -1;
 	}
+
 	ret = copyFileIfItExists(old_config_file_path, config_file_path);
 	if (ret == 0) {
 		wpa_printf(
@@ -145,6 +133,7 @@
 		unlink(config_file_path.c_str());
 		return -1;
 	}
+
 	std::string vendor_template_conf_path = resolveVendorConfPath(kVendorTemplateConfPath);
 	ret = copyFileIfItExists(vendor_template_conf_path, config_file_path);
 	if (ret == 0) {
@@ -156,6 +145,7 @@
 		unlink(config_file_path.c_str());
 		return -1;
 	}
+
 	ret = copyFileIfItExists(kSystemTemplateConfPath, config_file_path);
 	if (ret == 0) {
 		wpa_printf(
@@ -166,6 +156,7 @@
 		unlink(config_file_path.c_str());
 		return -1;
 	}
+
 	// Did not create the conf file.
 	return -1;
 }
diff --git a/wpa_supplicant/aidl/supplicant.h b/wpa_supplicant/aidl/vendor/supplicant.h
similarity index 100%
rename from wpa_supplicant/aidl/supplicant.h
rename to wpa_supplicant/aidl/vendor/supplicant.h
diff --git a/wpa_supplicant/dpp_supplicant.c b/wpa_supplicant/dpp_supplicant.c
index 75a3d78..1b2c756 100644
--- a/wpa_supplicant/dpp_supplicant.c
+++ b/wpa_supplicant/dpp_supplicant.c
@@ -29,7 +29,7 @@
 #include "scan.h"
 #include "notify.h"
 #include "dpp_supplicant.h"
-#include "aidl/aidl.h"
+#include "aidl/vendor/aidl.h"
 
 
 static int wpas_dpp_listen_start(struct wpa_supplicant *wpa_s,
diff --git a/wpa_supplicant/notify.c b/wpa_supplicant/notify.c
index b8fdf29..1fb2628 100644
--- a/wpa_supplicant/notify.c
+++ b/wpa_supplicant/notify.c
@@ -26,7 +26,11 @@
 #include "p2p_supplicant.h"
 #include "sme.h"
 #include "notify.h"
-#include "aidl/aidl.h"
+#include "aidl/vendor/aidl.h"
+
+#ifdef MAINLINE_SUPPLICANT
+#include "aidl/mainline/service.h"
+#endif
 
 int wpas_notify_supplicant_initialized(struct wpa_global *global)
 {
@@ -48,6 +52,12 @@
 	}
 #endif /* CONFIG_AIDL */
 
+#ifdef MAINLINE_SUPPLICANT
+	global->aidl = mainline_aidl_init(global);
+	if (!global->aidl)
+		return -1;
+#endif /* MAINLINE_SUPPLICANT */
+
 	return 0;
 }
 
@@ -63,6 +73,12 @@
 	if (global->aidl)
 		wpas_aidl_deinit(global->aidl);
 #endif /* CONFIG_AIDL */
+
+#ifdef MAINLINE_SUPPLICANT
+	if (global->aidl)
+		mainline_aidl_deinit(global->aidl);
+#endif /* MAINLINE_SUPPLICANT */
+
 }
 
 
diff --git a/wpa_supplicant/wpa_supplicant.c b/wpa_supplicant/wpa_supplicant.c
index 6df886f..982ff6c 100644
--- a/wpa_supplicant/wpa_supplicant.c
+++ b/wpa_supplicant/wpa_supplicant.c
@@ -70,7 +70,7 @@
 #include "ap/ap_config.h"
 #include "ap/hostapd.h"
 #endif /* CONFIG_MESH */
-#include "aidl/aidl.h"
+#include "aidl/vendor/aidl.h"
 
 const char *const wpa_supplicant_version =
 "wpa_supplicant v" VERSION_STR "\n"
diff --git a/wpa_supplicant/wpa_supplicant_template.conf b/wpa_supplicant/wpa_supplicant_template.conf
index 6a2fbd3..cec26c4 100644
--- a/wpa_supplicant/wpa_supplicant_template.conf
+++ b/wpa_supplicant/wpa_supplicant_template.conf
@@ -9,4 +9,3 @@
 sae_pwe=2
 p2p_optimize_listen_chan=1
 wowlan_disconnect_on_deinit=1
-sae_pmkid_in_assoc=1