blob: b9bca192959bcdc4d3d447b4fa57a6097026fcc2 [file] [log] [blame]
Christopher Wiley00aa56e2016-06-24 14:25:38 -07001/*
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
Colin Crossbddd3ef2018-09-06 11:53:17 -070017#include <grp.h>
18#include <pwd.h>
19#include <sys/types.h>
20
Christopher Wiley00aa56e2016-06-24 14:25:38 -070021#include "wifi_hal/driver_tool.h"
22
Christopher Wileyf41e52f2016-09-09 13:28:03 -070023#include <android-base/logging.h>
Christopher Wileyf41e52f2016-09-09 13:28:03 -070024
Christopher Wiley00aa56e2016-06-24 14:25:38 -070025#include "hardware_legacy/wifi.h"
26
27namespace android {
28namespace wifi_hal {
29
30const int DriverTool::kFirmwareModeSta = WIFI_GET_FW_PATH_STA;
31const int DriverTool::kFirmwareModeAp = WIFI_GET_FW_PATH_AP;
32const int DriverTool::kFirmwareModeP2p = WIFI_GET_FW_PATH_P2P;
33
Christopher Wiley00aa56e2016-06-24 14:25:38 -070034bool DriverTool::LoadDriver() {
35 return ::wifi_load_driver() == 0;
36}
37
38bool DriverTool::UnloadDriver() {
39 return ::wifi_unload_driver() == 0;
40}
41
42bool DriverTool::IsDriverLoaded() {
Ahmed ElArabawy50b3b9b2018-08-09 11:27:38 -070043 return ::is_wifi_driver_loaded() != 0;
Christopher Wiley00aa56e2016-06-24 14:25:38 -070044}
45
Roshan Pius6ce71732016-11-17 13:24:45 -080046bool DriverTool::IsFirmwareModeChangeNeeded(int mode) {
47 return (wifi_get_fw_path(mode) != nullptr);
48}
49
Christopher Wiley00aa56e2016-06-24 14:25:38 -070050bool 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