blob: 3089ee0a4ce5c1592ffc982a1f7676825f20c5df [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
17#include "wifi_hal/driver_tool.h"
18
Christopher Wileyf41e52f2016-09-09 13:28:03 -070019#include <android-base/logging.h>
20#include <private/android_filesystem_config.h>
21
Christopher Wiley00aa56e2016-06-24 14:25:38 -070022#include "hardware_legacy/wifi.h"
23
24namespace android {
25namespace wifi_hal {
26
27const int DriverTool::kFirmwareModeSta = WIFI_GET_FW_PATH_STA;
28const int DriverTool::kFirmwareModeAp = WIFI_GET_FW_PATH_AP;
29const int DriverTool::kFirmwareModeP2p = WIFI_GET_FW_PATH_P2P;
30
Christopher Wileyf41e52f2016-09-09 13:28:03 -070031bool DriverTool::TakeOwnershipOfFirmwareReload() {
32 if (!wifi_get_fw_path(kFirmwareModeSta) &&
33 !wifi_get_fw_path(kFirmwareModeAp) &&
34 !wifi_get_fw_path(kFirmwareModeP2p)) {
35 return true; // HAL doesn't think we need to load firmware for any mode.
36 }
37
38 if (chown(WIFI_DRIVER_FW_PATH_PARAM, AID_WIFI, AID_WIFI) != 0) {
39 PLOG(ERROR) << "Error changing ownership of '" << WIFI_DRIVER_FW_PATH_PARAM
40 << "' to wifi:wifi";
41 return false;
42 }
43
44 return true;
45}
Christopher Wiley1d3a41b2016-08-22 10:23:22 -070046
Christopher Wiley00aa56e2016-06-24 14:25:38 -070047bool DriverTool::LoadDriver() {
48 return ::wifi_load_driver() == 0;
49}
50
51bool DriverTool::UnloadDriver() {
52 return ::wifi_unload_driver() == 0;
53}
54
55bool DriverTool::IsDriverLoaded() {
56 return ::wifi_unload_driver() != 0;
57}
58
Roshan Pius6ce71732016-11-17 13:24:45 -080059bool DriverTool::IsFirmwareModeChangeNeeded(int mode) {
60 return (wifi_get_fw_path(mode) != nullptr);
61}
62
Christopher Wiley00aa56e2016-06-24 14:25:38 -070063bool DriverTool::ChangeFirmwareMode(int mode) {
64 const char* fwpath = wifi_get_fw_path(mode);
65 if (!fwpath) {
66 return true; // HAL doesn't think we need to load firmware for this mode.
67 }
68 if (wifi_change_fw_path(fwpath) != 0) {
69 // Not all devices actually require firmware reloads, but
70 // failure to change the firmware path when it is defined is an error.
71 return false;
72 }
73 return true;
74}
75
76} // namespace wifi_hal
77} // namespace android