blob: 719a6b93c4ca83166a51bbca7ba9199cd643f726 [file] [log] [blame]
Roshan Pius3c4e8a32016-10-03 14:53:58 -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_chip.h"
18
19#include <android-base/logging.h>
20
21#include "failure_reason_util.h"
22
23namespace android {
24namespace hardware {
25namespace wifi {
Roshan Pius79a99752016-10-04 13:03:58 -070026namespace V1_0 {
27namespace implementation {
Roshan Pius3c4e8a32016-10-03 14:53:58 -070028
Roshan Piuscd566bd2016-10-10 08:03:42 -070029WifiChip::WifiChip(ChipId chip_id,
30 const std::weak_ptr<WifiLegacyHal> legacy_hal)
31 : chip_id_(chip_id), legacy_hal_(legacy_hal) {}
Roshan Pius3c4e8a32016-10-03 14:53:58 -070032
Roshan Piusaabe5752016-09-29 09:03:59 -070033void WifiChip::invalidate() {
34 legacy_hal_.reset();
Roshan Pius3c4e8a32016-10-03 14:53:58 -070035 callbacks_.clear();
36}
37
Roshan Piuscd566bd2016-10-10 08:03:42 -070038Return<ChipId> WifiChip::getId() {
39 return chip_id_;
40}
41
Roshan Pius3c4e8a32016-10-03 14:53:58 -070042Return<void> WifiChip::registerEventCallback(
Roshan Pius79a99752016-10-04 13:03:58 -070043 const sp<IWifiChipEventCallback>& callback) {
Roshan Piusaabe5752016-09-29 09:03:59 -070044 if (!legacy_hal_.lock())
Roshan Pius79a99752016-10-04 13:03:58 -070045 return Void();
Roshan Pius3c4e8a32016-10-03 14:53:58 -070046 // TODO(b/31632518): remove the callback when the client is destroyed
47 callbacks_.insert(callback);
48 return Void();
49}
50
51Return<void> WifiChip::getAvailableModes(getAvailableModes_cb cb) {
Roshan Piusaabe5752016-09-29 09:03:59 -070052 if (!legacy_hal_.lock()) {
Roshan Pius3c4e8a32016-10-03 14:53:58 -070053 cb(hidl_vec<ChipMode>());
54 return Void();
55 } else {
56 // TODO add implementation
57 return Void();
58 }
59}
60
61Return<void> WifiChip::configureChip(uint32_t /*mode_id*/) {
Roshan Piusaabe5752016-09-29 09:03:59 -070062 if (!legacy_hal_.lock())
Roshan Pius79a99752016-10-04 13:03:58 -070063 return Void();
Roshan Pius3c4e8a32016-10-03 14:53:58 -070064 // TODO add implementation
65 return Void();
66}
67
68Return<uint32_t> WifiChip::getMode() {
Roshan Piusaabe5752016-09-29 09:03:59 -070069 if (!legacy_hal_.lock())
Roshan Pius79a99752016-10-04 13:03:58 -070070 return 0;
Roshan Pius3c4e8a32016-10-03 14:53:58 -070071 // TODO add implementation
72 return 0;
73}
74
75Return<void> WifiChip::requestChipDebugInfo() {
Roshan Piusaabe5752016-09-29 09:03:59 -070076 if (!legacy_hal_.lock())
Roshan Pius79a99752016-10-04 13:03:58 -070077 return Void();
Roshan Pius4b26c832016-10-03 12:49:58 -070078
79 IWifiChipEventCallback::ChipDebugInfo result;
80
81 std::pair<wifi_error, std::string> ret =
Roshan Piusab5c4712016-10-06 14:37:15 -070082 legacy_hal_.lock()->getDriverVersion();
Roshan Pius4b26c832016-10-03 12:49:58 -070083 if (ret.first != WIFI_SUCCESS) {
84 LOG(ERROR) << "Failed to get driver version: "
85 << LegacyErrorToString(ret.first);
86 return Void();
87 }
88 result.driverDescription = ret.second.c_str();
89
Roshan Piusab5c4712016-10-06 14:37:15 -070090 ret = legacy_hal_.lock()->getFirmwareVersion();
Roshan Pius4b26c832016-10-03 12:49:58 -070091 if (ret.first != WIFI_SUCCESS) {
92 LOG(ERROR) << "Failed to get firmware version: "
93 << LegacyErrorToString(ret.first);
94 return Void();
95 }
96 result.firmwareDescription = ret.second.c_str();
97
98 for (const auto& callback : callbacks_) {
99 callback->onChipDebugInfoAvailable(result);
100 }
Roshan Pius3c4e8a32016-10-03 14:53:58 -0700101 return Void();
102}
103
104Return<void> WifiChip::requestDriverDebugDump() {
Roshan Piuscdb77f32016-10-03 14:09:57 -0700105 if (!legacy_hal_.lock())
106 return Void();
107
108 std::pair<wifi_error, std::vector<char>> ret =
Roshan Piusab5c4712016-10-06 14:37:15 -0700109 legacy_hal_.lock()->requestDriverMemoryDump();
Roshan Piuscdb77f32016-10-03 14:09:57 -0700110 if (ret.first != WIFI_SUCCESS) {
111 LOG(ERROR) << "Failed to get driver debug dump: "
112 << LegacyErrorToString(ret.first);
113 return Void();
114 }
115
116 auto& driver_dump = ret.second;
117 hidl_vec<uint8_t> hidl_data;
118 hidl_data.setToExternal(reinterpret_cast<uint8_t*>(driver_dump.data()),
119 driver_dump.size());
120 for (const auto& callback : callbacks_) {
121 callback->onDriverDebugDumpAvailable(hidl_data);
122 }
Roshan Pius3c4e8a32016-10-03 14:53:58 -0700123 return Void();
124}
125
126Return<void> WifiChip::requestFirmwareDebugDump() {
Roshan Piuscdb77f32016-10-03 14:09:57 -0700127 if (!legacy_hal_.lock())
128 return Void();
129
130 std::pair<wifi_error, std::vector<char>> ret =
Roshan Piusab5c4712016-10-06 14:37:15 -0700131 legacy_hal_.lock()->requestFirmwareMemoryDump();
Roshan Piuscdb77f32016-10-03 14:09:57 -0700132 if (ret.first != WIFI_SUCCESS) {
133 LOG(ERROR) << "Failed to get firmware debug dump: "
134 << LegacyErrorToString(ret.first);
135 return Void();
136 }
137
138 auto& firmware_dump = ret.second;
139 hidl_vec<uint8_t> hidl_data;
140 hidl_data.setToExternal(reinterpret_cast<uint8_t*>(firmware_dump.data()),
141 firmware_dump.size());
142 for (const auto& callback : callbacks_) {
143 callback->onFirmwareDebugDumpAvailable(hidl_data);
144 }
Roshan Pius3c4e8a32016-10-03 14:53:58 -0700145 return Void();
146}
147
Roshan Pius79a99752016-10-04 13:03:58 -0700148} // namespace implementation
149} // namespace V1_0
Roshan Pius3c4e8a32016-10-03 14:53:58 -0700150} // namespace wifi
151} // namespace hardware
152} // namespace android