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 <android-base/logging.h> 18 #include <android-base/macros.h> 19 #include <private/android_filesystem_config.h> 20 21 #include "wifi_mode_controller.h" 22 23 using android::hardware::wifi::V1_0::IfaceType; 24 using android::wifi_hal::DriverTool; 25 26 namespace { convertIfaceTypeToFirmwareMode(IfaceType type)27int convertIfaceTypeToFirmwareMode(IfaceType type) { 28 int mode; 29 switch (type) { 30 case IfaceType::AP: 31 mode = DriverTool::kFirmwareModeAp; 32 break; 33 case IfaceType::P2P: 34 mode = DriverTool::kFirmwareModeP2p; 35 break; 36 case IfaceType::NAN: 37 // NAN is exposed in STA mode currently. 38 mode = DriverTool::kFirmwareModeSta; 39 break; 40 case IfaceType::STA: 41 mode = DriverTool::kFirmwareModeSta; 42 break; 43 } 44 return mode; 45 } 46 } // namespace 47 48 namespace android { 49 namespace hardware { 50 namespace wifi { 51 namespace V1_4 { 52 namespace implementation { 53 namespace mode_controller { 54 WifiModeController()55WifiModeController::WifiModeController() : driver_tool_(new DriverTool) {} 56 isFirmwareModeChangeNeeded(IfaceType type)57bool WifiModeController::isFirmwareModeChangeNeeded(IfaceType type) { 58 return driver_tool_->IsFirmwareModeChangeNeeded( 59 convertIfaceTypeToFirmwareMode(type)); 60 } 61 initialize()62bool WifiModeController::initialize() { 63 if (!driver_tool_->LoadDriver()) { 64 LOG(ERROR) << "Failed to load WiFi driver"; 65 return false; 66 } 67 return true; 68 } 69 changeFirmwareMode(IfaceType type)70bool WifiModeController::changeFirmwareMode(IfaceType type) { 71 if (!driver_tool_->ChangeFirmwareMode( 72 convertIfaceTypeToFirmwareMode(type))) { 73 LOG(ERROR) << "Failed to change firmware mode"; 74 return false; 75 } 76 return true; 77 } 78 deinitialize()79bool WifiModeController::deinitialize() { 80 if (!driver_tool_->UnloadDriver()) { 81 LOG(ERROR) << "Failed to unload WiFi driver"; 82 return false; 83 } 84 return true; 85 } 86 } // namespace mode_controller 87 } // namespace implementation 88 } // namespace V1_4 89 } // namespace wifi 90 } // namespace hardware 91 } // namespace android 92