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() { |
| 100 | // TODO implement |
| 101 | return Void(); |
| 102 | } |
| 103 | |
| 104 | Return<void> WifiChip::requestFirmwareDebugDump() { |
| 105 | // TODO implement |
| 106 | return Void(); |
| 107 | } |
| 108 | |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame] | 109 | } // namespace implementation |
| 110 | } // namespace V1_0 |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 111 | } // namespace wifi |
| 112 | } // namespace hardware |
| 113 | } // namespace android |