Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 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 "wifi_chip.h" |
| 18 | |
| 19 | #include <android-base/logging.h> |
| 20 | |
| 21 | #include "failure_reason_util.h" |
| 22 | |
| 23 | namespace android { |
| 24 | namespace hardware { |
| 25 | namespace wifi { |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame] | 26 | namespace V1_0 { |
| 27 | namespace implementation { |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 28 | |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 29 | WifiChip::WifiChip(std::weak_ptr<WifiLegacyHal> legacy_hal) |
| 30 | : legacy_hal_(legacy_hal) {} |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 31 | |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 32 | void WifiChip::invalidate() { |
| 33 | legacy_hal_.reset(); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 34 | callbacks_.clear(); |
| 35 | } |
| 36 | |
| 37 | Return<void> WifiChip::registerEventCallback( |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame] | 38 | const sp<IWifiChipEventCallback>& callback) { |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 39 | if (!legacy_hal_.lock()) |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame] | 40 | return Void(); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 41 | // TODO(b/31632518): remove the callback when the client is destroyed |
| 42 | callbacks_.insert(callback); |
| 43 | return Void(); |
| 44 | } |
| 45 | |
| 46 | Return<void> WifiChip::getAvailableModes(getAvailableModes_cb cb) { |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 47 | if (!legacy_hal_.lock()) { |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 48 | cb(hidl_vec<ChipMode>()); |
| 49 | return Void(); |
| 50 | } else { |
| 51 | // TODO add implementation |
| 52 | return Void(); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | Return<void> WifiChip::configureChip(uint32_t /*mode_id*/) { |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 57 | if (!legacy_hal_.lock()) |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame] | 58 | return Void(); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 59 | // TODO add implementation |
| 60 | return Void(); |
| 61 | } |
| 62 | |
| 63 | Return<uint32_t> WifiChip::getMode() { |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 64 | if (!legacy_hal_.lock()) |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame] | 65 | return 0; |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 66 | // TODO add implementation |
| 67 | return 0; |
| 68 | } |
| 69 | |
| 70 | Return<void> WifiChip::requestChipDebugInfo() { |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 71 | if (!legacy_hal_.lock()) |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame] | 72 | return Void(); |
Roshan Pius | 4b26c83 | 2016-10-03 12:49:58 -0700 | [diff] [blame] | 73 | |
| 74 | IWifiChipEventCallback::ChipDebugInfo result; |
| 75 | |
| 76 | std::pair<wifi_error, std::string> ret = |
| 77 | legacy_hal_.lock()->getWlanDriverVersion(); |
| 78 | if (ret.first != WIFI_SUCCESS) { |
| 79 | LOG(ERROR) << "Failed to get driver version: " |
| 80 | << LegacyErrorToString(ret.first); |
| 81 | return Void(); |
| 82 | } |
| 83 | result.driverDescription = ret.second.c_str(); |
| 84 | |
| 85 | ret = legacy_hal_.lock()->getWlanFirmwareVersion(); |
| 86 | if (ret.first != WIFI_SUCCESS) { |
| 87 | LOG(ERROR) << "Failed to get firmware version: " |
| 88 | << LegacyErrorToString(ret.first); |
| 89 | return Void(); |
| 90 | } |
| 91 | result.firmwareDescription = ret.second.c_str(); |
| 92 | |
| 93 | for (const auto& callback : callbacks_) { |
| 94 | callback->onChipDebugInfoAvailable(result); |
| 95 | } |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 96 | return Void(); |
| 97 | } |
| 98 | |
| 99 | Return<void> WifiChip::requestDriverDebugDump() { |
Roshan Pius | cdb77f3 | 2016-10-03 14:09:57 -0700 | [diff] [blame] | 100 | if (!legacy_hal_.lock()) |
| 101 | return Void(); |
| 102 | |
| 103 | std::pair<wifi_error, std::vector<char>> ret = |
| 104 | legacy_hal_.lock()->requestWlanDriverMemoryDump(); |
| 105 | if (ret.first != WIFI_SUCCESS) { |
| 106 | LOG(ERROR) << "Failed to get driver debug dump: " |
| 107 | << LegacyErrorToString(ret.first); |
| 108 | return Void(); |
| 109 | } |
| 110 | |
| 111 | auto& driver_dump = ret.second; |
| 112 | hidl_vec<uint8_t> hidl_data; |
| 113 | hidl_data.setToExternal(reinterpret_cast<uint8_t*>(driver_dump.data()), |
| 114 | driver_dump.size()); |
| 115 | for (const auto& callback : callbacks_) { |
| 116 | callback->onDriverDebugDumpAvailable(hidl_data); |
| 117 | } |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 118 | return Void(); |
| 119 | } |
| 120 | |
| 121 | Return<void> WifiChip::requestFirmwareDebugDump() { |
Roshan Pius | cdb77f3 | 2016-10-03 14:09:57 -0700 | [diff] [blame] | 122 | if (!legacy_hal_.lock()) |
| 123 | return Void(); |
| 124 | |
| 125 | std::pair<wifi_error, std::vector<char>> ret = |
| 126 | legacy_hal_.lock()->requestWlanFirmwareMemoryDump(); |
| 127 | if (ret.first != WIFI_SUCCESS) { |
| 128 | LOG(ERROR) << "Failed to get firmware debug dump: " |
| 129 | << LegacyErrorToString(ret.first); |
| 130 | return Void(); |
| 131 | } |
| 132 | |
| 133 | auto& firmware_dump = ret.second; |
| 134 | hidl_vec<uint8_t> hidl_data; |
| 135 | hidl_data.setToExternal(reinterpret_cast<uint8_t*>(firmware_dump.data()), |
| 136 | firmware_dump.size()); |
| 137 | for (const auto& callback : callbacks_) { |
| 138 | callback->onFirmwareDebugDumpAvailable(hidl_data); |
| 139 | } |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 140 | return Void(); |
| 141 | } |
| 142 | |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame] | 143 | } // namespace implementation |
| 144 | } // namespace V1_0 |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 145 | } // namespace wifi |
| 146 | } // namespace hardware |
| 147 | } // namespace android |