Roshan Pius | 3e2d671 | 2016-10-06 13:16:23 -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 | |
Roshan Pius | 3e2d671 | 2016-10-06 13:16:23 -0700 | [diff] [blame] | 17 | #include <android-base/logging.h> |
| 18 | |
Roshan Pius | 907d4a2 | 2016-10-27 12:48:12 -0700 | [diff] [blame] | 19 | #include "hidl_return_util.h" |
Roshan Pius | 7f4574d | 2017-02-22 09:48:03 -0800 | [diff] [blame] | 20 | #include "hidl_struct_util.h" |
Roshan Pius | 907d4a2 | 2016-10-27 12:48:12 -0700 | [diff] [blame] | 21 | #include "wifi_ap_iface.h" |
Roshan Pius | 734fea0 | 2016-10-11 08:30:28 -0700 | [diff] [blame] | 22 | #include "wifi_status_util.h" |
Roshan Pius | 3e2d671 | 2016-10-06 13:16:23 -0700 | [diff] [blame] | 23 | |
| 24 | namespace android { |
| 25 | namespace hardware { |
| 26 | namespace wifi { |
Ahmed ElArabawy | f501a98 | 2019-07-23 15:02:22 -0700 | [diff] [blame] | 27 | namespace V1_4 { |
Roshan Pius | 3e2d671 | 2016-10-06 13:16:23 -0700 | [diff] [blame] | 28 | namespace implementation { |
Roshan Pius | 907d4a2 | 2016-10-27 12:48:12 -0700 | [diff] [blame] | 29 | using hidl_return_util::validateAndCall; |
Roshan Pius | 3e2d671 | 2016-10-06 13:16:23 -0700 | [diff] [blame] | 30 | |
Roshan Pius | 6cedc97 | 2016-10-28 10:11:17 -0700 | [diff] [blame] | 31 | WifiApIface::WifiApIface( |
| 32 | const std::string& ifname, |
Roshan Pius | 99dab38 | 2019-02-14 07:57:10 -0800 | [diff] [blame] | 33 | const std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal, |
Roshan Pius | 3b6705f | 2019-02-14 09:43:43 -0800 | [diff] [blame] | 34 | const std::weak_ptr<iface_util::WifiIfaceUtil> iface_util, |
| 35 | const std::weak_ptr<feature_flags::WifiFeatureFlags> feature_flags) |
Roshan Pius | 99dab38 | 2019-02-14 07:57:10 -0800 | [diff] [blame] | 36 | : ifname_(ifname), |
| 37 | legacy_hal_(legacy_hal), |
| 38 | iface_util_(iface_util), |
Roshan Pius | 3b6705f | 2019-02-14 09:43:43 -0800 | [diff] [blame] | 39 | feature_flags_(feature_flags), |
| 40 | is_valid_(true) { |
| 41 | if (feature_flags_.lock()->isApMacRandomizationDisabled()) { |
| 42 | LOG(INFO) << "AP MAC randomization disabled"; |
| 43 | return; |
| 44 | } |
| 45 | LOG(INFO) << "AP MAC randomization enabled"; |
| 46 | // Set random MAC address |
| 47 | std::array<uint8_t, 6> randomized_mac = |
| 48 | iface_util_.lock()->getOrCreateRandomMacAddress(); |
| 49 | bool status = iface_util_.lock()->setMacAddress(ifname_, randomized_mac); |
| 50 | if (!status) { |
| 51 | LOG(ERROR) << "Failed to set random mac address"; |
| 52 | } |
| 53 | } |
Roshan Pius | 3e2d671 | 2016-10-06 13:16:23 -0700 | [diff] [blame] | 54 | |
| 55 | void WifiApIface::invalidate() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 56 | legacy_hal_.reset(); |
| 57 | is_valid_ = false; |
Roshan Pius | 3e2d671 | 2016-10-06 13:16:23 -0700 | [diff] [blame] | 58 | } |
| 59 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 60 | bool WifiApIface::isValid() { return is_valid_; } |
Roshan Pius | 907d4a2 | 2016-10-27 12:48:12 -0700 | [diff] [blame] | 61 | |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 62 | std::string WifiApIface::getName() { return ifname_; } |
| 63 | |
Roshan Pius | 734fea0 | 2016-10-11 08:30:28 -0700 | [diff] [blame] | 64 | Return<void> WifiApIface::getName(getName_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 65 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 66 | &WifiApIface::getNameInternal, hidl_status_cb); |
Roshan Pius | 3e2d671 | 2016-10-06 13:16:23 -0700 | [diff] [blame] | 67 | } |
| 68 | |
Roshan Pius | 734fea0 | 2016-10-11 08:30:28 -0700 | [diff] [blame] | 69 | Return<void> WifiApIface::getType(getType_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 70 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 71 | &WifiApIface::getTypeInternal, hidl_status_cb); |
Roshan Pius | 907d4a2 | 2016-10-27 12:48:12 -0700 | [diff] [blame] | 72 | } |
| 73 | |
Roshan Pius | 32fc12e | 2017-01-25 17:44:42 -0800 | [diff] [blame] | 74 | Return<void> WifiApIface::setCountryCode(const hidl_array<int8_t, 2>& code, |
| 75 | setCountryCode_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 76 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 77 | &WifiApIface::setCountryCodeInternal, hidl_status_cb, |
| 78 | code); |
Roshan Pius | 32fc12e | 2017-01-25 17:44:42 -0800 | [diff] [blame] | 79 | } |
| 80 | |
Roshan Pius | 7f4574d | 2017-02-22 09:48:03 -0800 | [diff] [blame] | 81 | Return<void> WifiApIface::getValidFrequenciesForBand( |
| 82 | WifiBand band, getValidFrequenciesForBand_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 83 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 84 | &WifiApIface::getValidFrequenciesForBandInternal, |
| 85 | hidl_status_cb, band); |
Roshan Pius | 7f4574d | 2017-02-22 09:48:03 -0800 | [diff] [blame] | 86 | } |
| 87 | |
Patrik Fimml | c919f96 | 2019-09-11 14:31:56 +0200 | [diff] [blame] | 88 | Return<void> WifiApIface::setMacAddress(const hidl_array<uint8_t, 6>& mac, |
| 89 | setMacAddress_cb hidl_status_cb) { |
| 90 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 91 | &WifiApIface::setMacAddressInternal, hidl_status_cb, |
| 92 | mac); |
| 93 | } |
| 94 | |
| 95 | Return<void> WifiApIface::getFactoryMacAddress( |
| 96 | getFactoryMacAddress_cb hidl_status_cb) { |
| 97 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 98 | &WifiApIface::getFactoryMacAddressInternal, |
| 99 | hidl_status_cb); |
| 100 | } |
| 101 | |
Roshan Pius | 907d4a2 | 2016-10-27 12:48:12 -0700 | [diff] [blame] | 102 | std::pair<WifiStatus, std::string> WifiApIface::getNameInternal() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 103 | return {createWifiStatus(WifiStatusCode::SUCCESS), ifname_}; |
Roshan Pius | 907d4a2 | 2016-10-27 12:48:12 -0700 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | std::pair<WifiStatus, IfaceType> WifiApIface::getTypeInternal() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 107 | return {createWifiStatus(WifiStatusCode::SUCCESS), IfaceType::AP}; |
Roshan Pius | 3e2d671 | 2016-10-06 13:16:23 -0700 | [diff] [blame] | 108 | } |
| 109 | |
Roshan Pius | 32fc12e | 2017-01-25 17:44:42 -0800 | [diff] [blame] | 110 | WifiStatus WifiApIface::setCountryCodeInternal( |
| 111 | const std::array<int8_t, 2>& code) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 112 | legacy_hal::wifi_error legacy_status = |
| 113 | legacy_hal_.lock()->setCountryCode(ifname_, code); |
| 114 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | 32fc12e | 2017-01-25 17:44:42 -0800 | [diff] [blame] | 115 | } |
| 116 | |
Roshan Pius | 7f4574d | 2017-02-22 09:48:03 -0800 | [diff] [blame] | 117 | std::pair<WifiStatus, std::vector<WifiChannelInMhz>> |
| 118 | WifiApIface::getValidFrequenciesForBandInternal(WifiBand band) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 119 | static_assert(sizeof(WifiChannelInMhz) == sizeof(uint32_t), |
| 120 | "Size mismatch"); |
| 121 | legacy_hal::wifi_error legacy_status; |
| 122 | std::vector<uint32_t> valid_frequencies; |
| 123 | std::tie(legacy_status, valid_frequencies) = |
| 124 | legacy_hal_.lock()->getValidFrequenciesForBand( |
| 125 | ifname_, hidl_struct_util::convertHidlWifiBandToLegacy(band)); |
| 126 | return {createWifiStatusFromLegacyError(legacy_status), valid_frequencies}; |
Roshan Pius | 7f4574d | 2017-02-22 09:48:03 -0800 | [diff] [blame] | 127 | } |
Patrik Fimml | c919f96 | 2019-09-11 14:31:56 +0200 | [diff] [blame] | 128 | |
| 129 | WifiStatus WifiApIface::setMacAddressInternal( |
| 130 | const std::array<uint8_t, 6>& mac) { |
| 131 | bool status = iface_util_.lock()->setMacAddress(ifname_, mac); |
| 132 | if (!status) { |
| 133 | return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN); |
| 134 | } |
| 135 | return createWifiStatus(WifiStatusCode::SUCCESS); |
| 136 | } |
| 137 | |
| 138 | std::pair<WifiStatus, std::array<uint8_t, 6>> |
| 139 | WifiApIface::getFactoryMacAddressInternal() { |
| 140 | std::array<uint8_t, 6> mac = |
| 141 | iface_util_.lock()->getFactoryMacAddress(ifname_); |
| 142 | if (mac[0] == 0 && mac[1] == 0 && mac[2] == 0 && mac[3] == 0 && |
| 143 | mac[4] == 0 && mac[5] == 0) { |
| 144 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), mac}; |
| 145 | } |
| 146 | return {createWifiStatus(WifiStatusCode::SUCCESS), mac}; |
| 147 | } |
Roshan Pius | 3e2d671 | 2016-10-06 13:16:23 -0700 | [diff] [blame] | 148 | } // namespace implementation |
Ahmed ElArabawy | f501a98 | 2019-07-23 15:02:22 -0700 | [diff] [blame] | 149 | } // namespace V1_4 |
Roshan Pius | 3e2d671 | 2016-10-06 13:16:23 -0700 | [diff] [blame] | 150 | } // namespace wifi |
| 151 | } // namespace hardware |
| 152 | } // namespace android |