From f41e52f5ad89310d867a00c12f2cf146703ad574 Mon Sep 17 00:00:00 2001 From: Christopher Wiley Date: Fri, 9 Sep 2016 13:28:03 -0700 Subject: Expose a method to take control of firmware path Rather than exposing the firmware path directly, expose a helper method. This method can be static, since we call it once from wificond's main() and cannot effectively unittest changing filesystem permissions. Hide the firmware path again after this change. Bug: 31225859 Test: Can connect to networks on bullhead with this change. Change-Id: I1b1640f552f78ede2adb7e1273d69cc606543c7b --- libwifi_hal/Android.mk | 1 + libwifi_hal/driver_tool.cpp | 19 ++++++++++++++++++- libwifi_hal/include/wifi_hal/driver_tool.h | 4 +++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/libwifi_hal/Android.mk b/libwifi_hal/Android.mk index f93015902..1ed59882f 100644 --- a/libwifi_hal/Android.mk +++ b/libwifi_hal/Android.mk @@ -106,6 +106,7 @@ LOCAL_EXPORT_C_INCLUDE_DIRS := \ $(LOCAL_PATH)/include \ $(call include-path-for, libhardware_legacy) LOCAL_SHARED_LIBRARIES := \ + libbase \ libcutils \ liblog \ libnl \ diff --git a/libwifi_hal/driver_tool.cpp b/libwifi_hal/driver_tool.cpp index 6b0b7522b..c05c00080 100644 --- a/libwifi_hal/driver_tool.cpp +++ b/libwifi_hal/driver_tool.cpp @@ -16,6 +16,9 @@ #include "wifi_hal/driver_tool.h" +#include +#include + #include "hardware_legacy/wifi.h" namespace android { @@ -25,7 +28,21 @@ const int DriverTool::kFirmwareModeSta = WIFI_GET_FW_PATH_STA; const int DriverTool::kFirmwareModeAp = WIFI_GET_FW_PATH_AP; const int DriverTool::kFirmwareModeP2p = WIFI_GET_FW_PATH_P2P; -const char DriverTool::kFirmwareReloadPath[] = WIFI_DRIVER_FW_PATH_PARAM; +bool DriverTool::TakeOwnershipOfFirmwareReload() { + if (!wifi_get_fw_path(kFirmwareModeSta) && + !wifi_get_fw_path(kFirmwareModeAp) && + !wifi_get_fw_path(kFirmwareModeP2p)) { + return true; // HAL doesn't think we need to load firmware for any mode. + } + + if (chown(WIFI_DRIVER_FW_PATH_PARAM, AID_WIFI, AID_WIFI) != 0) { + PLOG(ERROR) << "Error changing ownership of '" << WIFI_DRIVER_FW_PATH_PARAM + << "' to wifi:wifi"; + return false; + } + + return true; +} bool DriverTool::LoadDriver() { return ::wifi_load_driver() == 0; diff --git a/libwifi_hal/include/wifi_hal/driver_tool.h b/libwifi_hal/include/wifi_hal/driver_tool.h index 376d17d93..e0941c0f9 100644 --- a/libwifi_hal/include/wifi_hal/driver_tool.h +++ b/libwifi_hal/include/wifi_hal/driver_tool.h @@ -27,7 +27,9 @@ class DriverTool { static const int kFirmwareModeAp; static const int kFirmwareModeP2p; - static const char kFirmwareReloadPath[]; + // Change the owner of the firmware reload path to wifi:wifi if + // firmware reload is supported. + static bool TakeOwnershipOfFirmwareReload(); DriverTool() = default; virtual ~DriverTool() = default; -- cgit v1.2.3