From 40d8f1a61d98e6f3f954b0aedd56f9121b5659f7 Mon Sep 17 00:00:00 2001 From: Jooyung Han Date: Thu, 22 Feb 2024 13:30:57 +0900 Subject: Revert apex support from wpa_supplicant This is a revert of 1f2ba85e6d4117e16d5132a82c8d775e1c0704a7. This is a preparation for the follow up change to remove hard-coded vendor apex name: com.android.wifi.hal. Bug: 325392832 Test: m wpa_supplicant Change-Id: I16ec62b0f46b05cbc4e254f12a51a26320b9df30 --- wpa_supplicant/aidl/supplicant.cpp | 84 +++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 47 deletions(-) diff --git a/wpa_supplicant/aidl/supplicant.cpp b/wpa_supplicant/aidl/supplicant.cpp index 74602e44..d5dc8025 100644 --- a/wpa_supplicant/aidl/supplicant.cpp +++ b/wpa_supplicant/aidl/supplicant.cpp @@ -21,38 +21,27 @@ namespace { // Pre-populated interface params for interfaces controlled by wpa_supplicant. // Note: This may differ for other OEM's. So, modify this accordingly. constexpr char kIfaceDriverName[] = "nl80211"; + constexpr char kStaIfaceConfPath[] = "/data/vendor/wifi/wpa/wpa_supplicant.conf"; -static const char* kStaIfaceConfOverlayPaths[] = { - "/apex/com.android.wifi.hal/etc/wifi/wpa_supplicant_overlay.conf", - "/vendor/etc/wifi/wpa_supplicant_overlay.conf", -}; +constexpr char kStaIfaceConfOverlayPath[] = + "/vendor/etc/wifi/wpa_supplicant_overlay.conf"; + constexpr char kP2pIfaceConfPath[] = "/data/vendor/wifi/wpa/p2p_supplicant.conf"; -static const char* kP2pIfaceConfOverlayPaths[] = { - "/apex/com.android.wifi.hal/etc/wifi/p2p_supplicant_overlay.conf", - "/vendor/etc/wifi/p2p_supplicant_overlay.conf", -}; +constexpr char kP2pIfaceConfOverlayPath[] = + "/vendor/etc/wifi/p2p_supplicant_overlay.conf"; + // Migrate conf files for existing devices. -static const char* kTemplateConfPaths[] = { - "/apex/com.android.wifi.hal/etc/wifi/wpa_supplicant.conf", - "/vendor/etc/wifi/wpa_supplicant.conf", - "/system/etc/wifi/wpa_supplicant.conf", -}; +constexpr char kSystemTemplateConfPath[] = + "/system/etc/wifi/wpa_supplicant.conf"; +constexpr char kVendorTemplateConfPath[] = + "/vendor/etc/wifi/wpa_supplicant.conf"; + 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; -const char* resolvePath(const char* paths[], size_t size) -{ - for (int i = 0; i < size; ++i) { - if (access(paths[i], R_OK) == 0) { - return paths[i]; - } - } - return nullptr; -} - int copyFile( const std::string& src_file_path, const std::string& dest_file_path) { @@ -143,20 +132,25 @@ int ensureConfigFileExists( unlink(config_file_path.c_str()); return -1; } - const char* path = - resolvePath(kTemplateConfPaths, - sizeof(kTemplateConfPaths)/sizeof(kTemplateConfPaths[0])); - if (path != nullptr) { - ret = copyFileIfItExists(path, config_file_path); - if (ret == 0) { - wpa_printf( - MSG_INFO, "Copied template conf file from %s to %s", - path, config_file_path.c_str()); - return 0; - } else if (ret == -1) { - unlink(config_file_path.c_str()); - return -1; - } + ret = copyFileIfItExists(kVendorTemplateConfPath, config_file_path); + if (ret == 0) { + wpa_printf( + MSG_INFO, "Copied template conf file from %s to %s", + kVendorTemplateConfPath, config_file_path.c_str()); + return 0; + } else if (ret == -1) { + unlink(config_file_path.c_str()); + return -1; + } + ret = copyFileIfItExists(kSystemTemplateConfPath, config_file_path); + if (ret == 0) { + wpa_printf( + MSG_INFO, "Copied template conf file from %s to %s", + kSystemTemplateConfPath, config_file_path.c_str()); + return 0; + } else if (ret == -1) { + unlink(config_file_path.c_str()); + return -1; } // Did not create the conf file. return -1; @@ -382,11 +376,9 @@ Supplicant::addP2pInterfaceInternal(const std::string& name) SupplicantStatusCode::FAILURE_UNKNOWN, "Conf file does not exist")}; } iface_params.confname = kP2pIfaceConfPath; - const char* path = resolvePath( - kP2pIfaceConfOverlayPaths, - sizeof(kP2pIfaceConfOverlayPaths)/sizeof(kP2pIfaceConfOverlayPaths[0])); - if (path != nullptr) { - iface_params.confanother = path; + int ret = access(kP2pIfaceConfOverlayPath, R_OK); + if (ret == 0) { + iface_params.confanother = kP2pIfaceConfOverlayPath; } iface_params.ifname = name.c_str(); @@ -442,11 +434,9 @@ Supplicant::addStaInterfaceInternal(const std::string& name) SupplicantStatusCode::FAILURE_UNKNOWN, "Conf file does not exist")}; } iface_params.confname = kStaIfaceConfPath; - const char* path = resolvePath( - kStaIfaceConfOverlayPaths, - sizeof(kStaIfaceConfOverlayPaths)/sizeof(kStaIfaceConfOverlayPaths[0])); - if (path != nullptr) { - iface_params.confanother = path; + int ret = access(kStaIfaceConfOverlayPath, R_OK); + if (ret == 0) { + iface_params.confanother = kStaIfaceConfOverlayPath; } iface_params.ifname = name.c_str(); -- cgit v1.2.3 From bd916f819ff0cc1e76d36c54b59fd81f4ee76175 Mon Sep 17 00:00:00 2001 From: Jooyung Han Date: Thu, 22 Feb 2024 14:17:39 +0900 Subject: Support loading configs from APEX When wpa_supplicant is in its APEX, it loads configs (overlay/template) from the APEX. It gets the APEX path from the executable's path. Bug: 325392832 Test: atest CtsWifiTestCases Change-Id: Idabbe75cca1d6d9ec987053525ef3b81d2ca6bda --- wpa_supplicant/aidl/supplicant.cpp | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/wpa_supplicant/aidl/supplicant.cpp b/wpa_supplicant/aidl/supplicant.cpp index d5dc8025..1589dd25 100644 --- a/wpa_supplicant/aidl/supplicant.cpp +++ b/wpa_supplicant/aidl/supplicant.cpp @@ -20,28 +20,41 @@ namespace { // Pre-populated interface params for interfaces controlled by wpa_supplicant. // 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[] = - "/vendor/etc/wifi/wpa_supplicant_overlay.conf"; + "/etc/wifi/wpa_supplicant_overlay.conf"; constexpr char kP2pIfaceConfPath[] = "/data/vendor/wifi/wpa/p2p_supplicant.conf"; constexpr char kP2pIfaceConfOverlayPath[] = - "/vendor/etc/wifi/p2p_supplicant_overlay.conf"; + "/etc/wifi/p2p_supplicant_overlay.conf"; // Migrate conf files for existing devices. constexpr char kSystemTemplateConfPath[] = "/system/etc/wifi/wpa_supplicant.conf"; constexpr char kVendorTemplateConfPath[] = - "/vendor/etc/wifi/wpa_supplicant.conf"; + "/etc/wifi/wpa_supplicant.conf"; 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) +{ +#if defined(__ANDROID_APEX__) + // returns "/apex/" + conf_path + std::string path = android::base::GetExecutablePath(); + return path.substr(0, path.find_first_of('/', strlen("/apex/"))) + conf_path; +#else + return std::string("/vendor") + conf_path; +#endif +} + int copyFile( const std::string& src_file_path, const std::string& dest_file_path) { @@ -132,11 +145,12 @@ int ensureConfigFileExists( unlink(config_file_path.c_str()); return -1; } - ret = copyFileIfItExists(kVendorTemplateConfPath, config_file_path); + std::string vendor_template_conf_path = resolveVendorConfPath(kVendorTemplateConfPath); + ret = copyFileIfItExists(vendor_template_conf_path, config_file_path); if (ret == 0) { wpa_printf( MSG_INFO, "Copied template conf file from %s to %s", - kVendorTemplateConfPath, config_file_path.c_str()); + vendor_template_conf_path.c_str(), config_file_path.c_str()); return 0; } else if (ret == -1) { unlink(config_file_path.c_str()); @@ -376,9 +390,10 @@ Supplicant::addP2pInterfaceInternal(const std::string& name) SupplicantStatusCode::FAILURE_UNKNOWN, "Conf file does not exist")}; } iface_params.confname = kP2pIfaceConfPath; - int ret = access(kP2pIfaceConfOverlayPath, R_OK); + std::string overlay_path = resolveVendorConfPath(kP2pIfaceConfOverlayPath); + int ret = access(overlay_path.c_str(), R_OK); if (ret == 0) { - iface_params.confanother = kP2pIfaceConfOverlayPath; + iface_params.confanother = overlay_path.c_str(); } iface_params.ifname = name.c_str(); @@ -434,9 +449,10 @@ Supplicant::addStaInterfaceInternal(const std::string& name) SupplicantStatusCode::FAILURE_UNKNOWN, "Conf file does not exist")}; } iface_params.confname = kStaIfaceConfPath; - int ret = access(kStaIfaceConfOverlayPath, R_OK); + std::string overlay_path = resolveVendorConfPath(kStaIfaceConfOverlayPath); + int ret = access(overlay_path.c_str(), R_OK); if (ret == 0) { - iface_params.confanother = kStaIfaceConfOverlayPath; + iface_params.confanother = overlay_path.c_str(); } iface_params.ifname = name.c_str(); -- cgit v1.2.3