1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include <grp.h> 18 #include <pwd.h> 19 #include <sys/types.h> 20 21 #include "wifi_hal/driver_tool.h" 22 23 #include <android-base/logging.h> 24 25 #include "hardware_legacy/wifi.h" 26 27 namespace android { 28 namespace wifi_hal { 29 30 const int DriverTool::kFirmwareModeSta = WIFI_GET_FW_PATH_STA; 31 const int DriverTool::kFirmwareModeAp = WIFI_GET_FW_PATH_AP; 32 const int DriverTool::kFirmwareModeP2p = WIFI_GET_FW_PATH_P2P; 33 LoadDriver()34bool DriverTool::LoadDriver() { 35 return ::wifi_load_driver() == 0; 36 } 37 UnloadDriver()38bool DriverTool::UnloadDriver() { 39 return ::wifi_unload_driver() == 0; 40 } 41 IsDriverLoaded()42bool DriverTool::IsDriverLoaded() { 43 return ::is_wifi_driver_loaded() != 0; 44 } 45 IsFirmwareModeChangeNeeded(int mode)46bool DriverTool::IsFirmwareModeChangeNeeded(int mode) { 47 return (wifi_get_fw_path(mode) != nullptr); 48 } 49 ChangeFirmwareMode(int mode)50bool DriverTool::ChangeFirmwareMode(int mode) { 51 const char* fwpath = wifi_get_fw_path(mode); 52 if (!fwpath) { 53 return true; // HAL doesn't think we need to load firmware for this mode. 54 } 55 if (wifi_change_fw_path(fwpath) != 0) { 56 // Not all devices actually require firmware reloads, but 57 // failure to change the firmware path when it is defined is an error. 58 return false; 59 } 60 return true; 61 } 62 63 } // namespace wifi_hal 64 } // namespace android 65