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 | cd566bd | 2016-10-10 08:03:42 -0700 | [diff] [blame] | 29 | WifiChip::WifiChip(ChipId chip_id, |
| 30 | const std::weak_ptr<WifiLegacyHal> legacy_hal) |
| 31 | : chip_id_(chip_id), legacy_hal_(legacy_hal) {} |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 32 | |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 33 | void WifiChip::invalidate() { |
| 34 | legacy_hal_.reset(); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 35 | callbacks_.clear(); |
| 36 | } |
| 37 | |
Roshan Pius | cd566bd | 2016-10-10 08:03:42 -0700 | [diff] [blame] | 38 | Return<ChipId> WifiChip::getId() { |
| 39 | return chip_id_; |
| 40 | } |
| 41 | |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 42 | Return<void> WifiChip::registerEventCallback( |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame] | 43 | const sp<IWifiChipEventCallback>& callback) { |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 44 | if (!legacy_hal_.lock()) |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame] | 45 | return Void(); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 46 | // TODO(b/31632518): remove the callback when the client is destroyed |
| 47 | callbacks_.insert(callback); |
| 48 | return Void(); |
| 49 | } |
| 50 | |
| 51 | Return<void> WifiChip::getAvailableModes(getAvailableModes_cb cb) { |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 52 | if (!legacy_hal_.lock()) { |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 53 | cb(hidl_vec<ChipMode>()); |
| 54 | return Void(); |
| 55 | } else { |
| 56 | // TODO add implementation |
| 57 | return Void(); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | Return<void> WifiChip::configureChip(uint32_t /*mode_id*/) { |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 62 | if (!legacy_hal_.lock()) |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame] | 63 | return Void(); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 64 | // TODO add implementation |
| 65 | return Void(); |
| 66 | } |
| 67 | |
| 68 | Return<uint32_t> WifiChip::getMode() { |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 69 | if (!legacy_hal_.lock()) |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame] | 70 | return 0; |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 71 | // TODO add implementation |
| 72 | return 0; |
| 73 | } |
| 74 | |
| 75 | Return<void> WifiChip::requestChipDebugInfo() { |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 76 | if (!legacy_hal_.lock()) |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame] | 77 | return Void(); |
Roshan Pius | 4b26c83 | 2016-10-03 12:49:58 -0700 | [diff] [blame] | 78 | |
| 79 | IWifiChipEventCallback::ChipDebugInfo result; |
| 80 | |
| 81 | std::pair<wifi_error, std::string> ret = |
Roshan Pius | ab5c471 | 2016-10-06 14:37:15 -0700 | [diff] [blame] | 82 | legacy_hal_.lock()->getDriverVersion(); |
Roshan Pius | 4b26c83 | 2016-10-03 12:49:58 -0700 | [diff] [blame] | 83 | 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 Pius | ab5c471 | 2016-10-06 14:37:15 -0700 | [diff] [blame] | 90 | ret = legacy_hal_.lock()->getFirmwareVersion(); |
Roshan Pius | 4b26c83 | 2016-10-03 12:49:58 -0700 | [diff] [blame] | 91 | 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 Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 101 | return Void(); |
| 102 | } |
| 103 | |
| 104 | Return<void> WifiChip::requestDriverDebugDump() { |
Roshan Pius | cdb77f3 | 2016-10-03 14:09:57 -0700 | [diff] [blame] | 105 | if (!legacy_hal_.lock()) |
| 106 | return Void(); |
| 107 | |
| 108 | std::pair<wifi_error, std::vector<char>> ret = |
Roshan Pius | ab5c471 | 2016-10-06 14:37:15 -0700 | [diff] [blame] | 109 | legacy_hal_.lock()->requestDriverMemoryDump(); |
Roshan Pius | cdb77f3 | 2016-10-03 14:09:57 -0700 | [diff] [blame] | 110 | 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 Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 123 | return Void(); |
| 124 | } |
| 125 | |
| 126 | Return<void> WifiChip::requestFirmwareDebugDump() { |
Roshan Pius | cdb77f3 | 2016-10-03 14:09:57 -0700 | [diff] [blame] | 127 | if (!legacy_hal_.lock()) |
| 128 | return Void(); |
| 129 | |
| 130 | std::pair<wifi_error, std::vector<char>> ret = |
Roshan Pius | ab5c471 | 2016-10-06 14:37:15 -0700 | [diff] [blame] | 131 | legacy_hal_.lock()->requestFirmwareMemoryDump(); |
Roshan Pius | cdb77f3 | 2016-10-03 14:09:57 -0700 | [diff] [blame] | 132 | 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 Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 145 | return Void(); |
| 146 | } |
| 147 | |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame] | 148 | } // namespace implementation |
| 149 | } // namespace V1_0 |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 150 | } // namespace wifi |
| 151 | } // namespace hardware |
| 152 | } // namespace android |