Roshan Pius | 5926828 | 2016-10-06 20:23:47 -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 | 5926828 | 2016-10-06 20:23:47 -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 | e3f72ff | 2016-12-05 16:18:43 -0800 | [diff] [blame] | 20 | #include "hidl_struct_util.h" |
Roshan Pius | 907d4a2 | 2016-10-27 12:48:12 -0700 | [diff] [blame] | 21 | #include "wifi_rtt_controller.h" |
Roshan Pius | 734fea0 | 2016-10-11 08:30:28 -0700 | [diff] [blame] | 22 | #include "wifi_status_util.h" |
Roshan Pius | 5926828 | 2016-10-06 20:23:47 -0700 | [diff] [blame] | 23 | |
| 24 | namespace android { |
| 25 | namespace hardware { |
| 26 | namespace wifi { |
Jong Wook Kim | da830c9 | 2018-07-23 15:29:38 -0700 | [diff] [blame] | 27 | namespace V1_3 { |
Roshan Pius | 5926828 | 2016-10-06 20:23:47 -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 | 5926828 | 2016-10-06 20:23:47 -0700 | [diff] [blame] | 30 | |
| 31 | WifiRttController::WifiRttController( |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 32 | const std::string& iface_name, const sp<IWifiIface>& bound_iface, |
Roshan Pius | 6cedc97 | 2016-10-28 10:11:17 -0700 | [diff] [blame] | 33 | const std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal) |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 34 | : ifname_(iface_name), |
| 35 | bound_iface_(bound_iface), |
| 36 | legacy_hal_(legacy_hal), |
Roshan Pius | 9377a0d | 2017-10-06 13:18:54 -0700 | [diff] [blame] | 37 | is_valid_(true) {} |
Roshan Pius | 5926828 | 2016-10-06 20:23:47 -0700 | [diff] [blame] | 38 | |
| 39 | void WifiRttController::invalidate() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 40 | legacy_hal_.reset(); |
| 41 | event_callbacks_.clear(); |
| 42 | is_valid_ = false; |
Roshan Pius | 5926828 | 2016-10-06 20:23:47 -0700 | [diff] [blame] | 43 | } |
| 44 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 45 | bool WifiRttController::isValid() { return is_valid_; } |
Roshan Pius | 907d4a2 | 2016-10-27 12:48:12 -0700 | [diff] [blame] | 46 | |
Roshan Pius | e3f72ff | 2016-12-05 16:18:43 -0800 | [diff] [blame] | 47 | std::vector<sp<IWifiRttControllerEventCallback>> |
| 48 | WifiRttController::getEventCallbacks() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 49 | return event_callbacks_; |
Roshan Pius | e3f72ff | 2016-12-05 16:18:43 -0800 | [diff] [blame] | 50 | } |
| 51 | |
Roshan Pius | 8236850 | 2019-05-16 12:53:02 -0700 | [diff] [blame^] | 52 | std::string WifiRttController::getIfaceName() { return ifname_; } |
| 53 | |
Roshan Pius | 734fea0 | 2016-10-11 08:30:28 -0700 | [diff] [blame] | 54 | Return<void> WifiRttController::getBoundIface(getBoundIface_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 55 | return validateAndCall( |
| 56 | this, WifiStatusCode::ERROR_WIFI_RTT_CONTROLLER_INVALID, |
| 57 | &WifiRttController::getBoundIfaceInternal, hidl_status_cb); |
Roshan Pius | 907d4a2 | 2016-10-27 12:48:12 -0700 | [diff] [blame] | 58 | } |
| 59 | |
Roshan Pius | 7913f5e | 2016-10-27 17:09:30 -0700 | [diff] [blame] | 60 | Return<void> WifiRttController::registerEventCallback( |
| 61 | const sp<IWifiRttControllerEventCallback>& callback, |
| 62 | registerEventCallback_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 63 | return validateAndCall(this, |
| 64 | WifiStatusCode::ERROR_WIFI_RTT_CONTROLLER_INVALID, |
| 65 | &WifiRttController::registerEventCallbackInternal, |
| 66 | hidl_status_cb, callback); |
Roshan Pius | 7913f5e | 2016-10-27 17:09:30 -0700 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | Return<void> WifiRttController::rangeRequest( |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 70 | uint32_t cmd_id, const hidl_vec<RttConfig>& rtt_configs, |
Roshan Pius | 7913f5e | 2016-10-27 17:09:30 -0700 | [diff] [blame] | 71 | rangeRequest_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 72 | return validateAndCall(this, |
| 73 | WifiStatusCode::ERROR_WIFI_RTT_CONTROLLER_INVALID, |
| 74 | &WifiRttController::rangeRequestInternal, |
| 75 | hidl_status_cb, cmd_id, rtt_configs); |
Roshan Pius | 7913f5e | 2016-10-27 17:09:30 -0700 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | Return<void> WifiRttController::rangeCancel( |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 79 | uint32_t cmd_id, const hidl_vec<hidl_array<uint8_t, 6>>& addrs, |
Roshan Pius | 7913f5e | 2016-10-27 17:09:30 -0700 | [diff] [blame] | 80 | rangeCancel_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 81 | return validateAndCall( |
| 82 | this, WifiStatusCode::ERROR_WIFI_RTT_CONTROLLER_INVALID, |
| 83 | &WifiRttController::rangeCancelInternal, hidl_status_cb, cmd_id, addrs); |
Roshan Pius | 7913f5e | 2016-10-27 17:09:30 -0700 | [diff] [blame] | 84 | } |
| 85 | |
Roshan Pius | 7913f5e | 2016-10-27 17:09:30 -0700 | [diff] [blame] | 86 | Return<void> WifiRttController::getCapabilities( |
| 87 | getCapabilities_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 88 | return validateAndCall( |
| 89 | this, WifiStatusCode::ERROR_WIFI_RTT_CONTROLLER_INVALID, |
| 90 | &WifiRttController::getCapabilitiesInternal, hidl_status_cb); |
Roshan Pius | 7913f5e | 2016-10-27 17:09:30 -0700 | [diff] [blame] | 91 | } |
| 92 | |
Roshan Pius | 7913f5e | 2016-10-27 17:09:30 -0700 | [diff] [blame] | 93 | Return<void> WifiRttController::setLci(uint32_t cmd_id, |
| 94 | const RttLciInformation& lci, |
| 95 | setLci_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 96 | return validateAndCall( |
| 97 | this, WifiStatusCode::ERROR_WIFI_RTT_CONTROLLER_INVALID, |
| 98 | &WifiRttController::setLciInternal, hidl_status_cb, cmd_id, lci); |
Roshan Pius | 7913f5e | 2016-10-27 17:09:30 -0700 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | Return<void> WifiRttController::setLcr(uint32_t cmd_id, |
| 102 | const RttLcrInformation& lcr, |
| 103 | setLcr_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 104 | return validateAndCall( |
| 105 | this, WifiStatusCode::ERROR_WIFI_RTT_CONTROLLER_INVALID, |
| 106 | &WifiRttController::setLcrInternal, hidl_status_cb, cmd_id, lcr); |
Roshan Pius | 7913f5e | 2016-10-27 17:09:30 -0700 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | Return<void> WifiRttController::getResponderInfo( |
| 110 | getResponderInfo_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 111 | return validateAndCall( |
| 112 | this, WifiStatusCode::ERROR_WIFI_RTT_CONTROLLER_INVALID, |
| 113 | &WifiRttController::getResponderInfoInternal, hidl_status_cb); |
Roshan Pius | 7913f5e | 2016-10-27 17:09:30 -0700 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | Return<void> WifiRttController::enableResponder( |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 117 | uint32_t cmd_id, const WifiChannelInfo& channel_hint, |
| 118 | uint32_t max_duration_seconds, const RttResponder& info, |
Roshan Pius | 7913f5e | 2016-10-27 17:09:30 -0700 | [diff] [blame] | 119 | enableResponder_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 120 | return validateAndCall( |
| 121 | this, WifiStatusCode::ERROR_WIFI_RTT_CONTROLLER_INVALID, |
| 122 | &WifiRttController::enableResponderInternal, hidl_status_cb, cmd_id, |
| 123 | channel_hint, max_duration_seconds, info); |
Roshan Pius | 7913f5e | 2016-10-27 17:09:30 -0700 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | Return<void> WifiRttController::disableResponder( |
| 127 | uint32_t cmd_id, disableResponder_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 128 | return validateAndCall( |
| 129 | this, WifiStatusCode::ERROR_WIFI_RTT_CONTROLLER_INVALID, |
| 130 | &WifiRttController::disableResponderInternal, hidl_status_cb, cmd_id); |
Roshan Pius | 7913f5e | 2016-10-27 17:09:30 -0700 | [diff] [blame] | 131 | } |
| 132 | |
Roshan Pius | 907d4a2 | 2016-10-27 12:48:12 -0700 | [diff] [blame] | 133 | std::pair<WifiStatus, sp<IWifiIface>> |
| 134 | WifiRttController::getBoundIfaceInternal() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 135 | return {createWifiStatus(WifiStatusCode::SUCCESS), bound_iface_}; |
Roshan Pius | 5926828 | 2016-10-06 20:23:47 -0700 | [diff] [blame] | 136 | } |
| 137 | |
Roshan Pius | 7913f5e | 2016-10-27 17:09:30 -0700 | [diff] [blame] | 138 | WifiStatus WifiRttController::registerEventCallbackInternal( |
| 139 | const sp<IWifiRttControllerEventCallback>& callback) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 140 | // TODO(b/31632518): remove the callback when the client is destroyed |
| 141 | event_callbacks_.emplace_back(callback); |
| 142 | return createWifiStatus(WifiStatusCode::SUCCESS); |
Roshan Pius | 7913f5e | 2016-10-27 17:09:30 -0700 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | WifiStatus WifiRttController::rangeRequestInternal( |
Roshan Pius | e3f72ff | 2016-12-05 16:18:43 -0800 | [diff] [blame] | 146 | uint32_t cmd_id, const std::vector<RttConfig>& rtt_configs) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 147 | std::vector<legacy_hal::wifi_rtt_config> legacy_configs; |
| 148 | if (!hidl_struct_util::convertHidlVectorOfRttConfigToLegacy( |
| 149 | rtt_configs, &legacy_configs)) { |
| 150 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); |
Roshan Pius | e3f72ff | 2016-12-05 16:18:43 -0800 | [diff] [blame] | 151 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 152 | android::wp<WifiRttController> weak_ptr_this(this); |
| 153 | const auto& on_results_callback = |
| 154 | [weak_ptr_this]( |
| 155 | legacy_hal::wifi_request_id id, |
| 156 | const std::vector<const legacy_hal::wifi_rtt_result*>& results) { |
| 157 | const auto shared_ptr_this = weak_ptr_this.promote(); |
| 158 | if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { |
| 159 | LOG(ERROR) << "Callback invoked on an invalid object"; |
| 160 | return; |
| 161 | } |
| 162 | std::vector<RttResult> hidl_results; |
| 163 | if (!hidl_struct_util::convertLegacyVectorOfRttResultToHidl( |
| 164 | results, &hidl_results)) { |
| 165 | LOG(ERROR) << "Failed to convert rtt results to HIDL structs"; |
| 166 | return; |
| 167 | } |
| 168 | for (const auto& callback : shared_ptr_this->getEventCallbacks()) { |
| 169 | callback->onResults(id, hidl_results); |
| 170 | } |
| 171 | }; |
| 172 | legacy_hal::wifi_error legacy_status = |
| 173 | legacy_hal_.lock()->startRttRangeRequest( |
| 174 | ifname_, cmd_id, legacy_configs, on_results_callback); |
| 175 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | 7913f5e | 2016-10-27 17:09:30 -0700 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | WifiStatus WifiRttController::rangeCancelInternal( |
Roshan Pius | e3f72ff | 2016-12-05 16:18:43 -0800 | [diff] [blame] | 179 | uint32_t cmd_id, const std::vector<hidl_array<uint8_t, 6>>& addrs) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 180 | std::vector<std::array<uint8_t, 6>> legacy_addrs; |
| 181 | for (const auto& addr : addrs) { |
| 182 | legacy_addrs.push_back(addr); |
| 183 | } |
| 184 | legacy_hal::wifi_error legacy_status = |
| 185 | legacy_hal_.lock()->cancelRttRangeRequest(ifname_, cmd_id, |
| 186 | legacy_addrs); |
| 187 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | 7913f5e | 2016-10-27 17:09:30 -0700 | [diff] [blame] | 188 | } |
| 189 | |
Roshan Pius | 7913f5e | 2016-10-27 17:09:30 -0700 | [diff] [blame] | 190 | std::pair<WifiStatus, RttCapabilities> |
| 191 | WifiRttController::getCapabilitiesInternal() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 192 | legacy_hal::wifi_error legacy_status; |
| 193 | legacy_hal::wifi_rtt_capabilities legacy_caps; |
| 194 | std::tie(legacy_status, legacy_caps) = |
| 195 | legacy_hal_.lock()->getRttCapabilities(ifname_); |
| 196 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 197 | return {createWifiStatusFromLegacyError(legacy_status), {}}; |
| 198 | } |
| 199 | RttCapabilities hidl_caps; |
| 200 | if (!hidl_struct_util::convertLegacyRttCapabilitiesToHidl(legacy_caps, |
| 201 | &hidl_caps)) { |
| 202 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; |
| 203 | } |
| 204 | return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_caps}; |
Roshan Pius | 7913f5e | 2016-10-27 17:09:30 -0700 | [diff] [blame] | 205 | } |
| 206 | |
Roshan Pius | e3f72ff | 2016-12-05 16:18:43 -0800 | [diff] [blame] | 207 | WifiStatus WifiRttController::setLciInternal(uint32_t cmd_id, |
| 208 | const RttLciInformation& lci) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 209 | legacy_hal::wifi_lci_information legacy_lci; |
| 210 | if (!hidl_struct_util::convertHidlRttLciInformationToLegacy(lci, |
| 211 | &legacy_lci)) { |
| 212 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); |
| 213 | } |
| 214 | legacy_hal::wifi_error legacy_status = |
| 215 | legacy_hal_.lock()->setRttLci(ifname_, cmd_id, legacy_lci); |
| 216 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | 7913f5e | 2016-10-27 17:09:30 -0700 | [diff] [blame] | 217 | } |
| 218 | |
Roshan Pius | e3f72ff | 2016-12-05 16:18:43 -0800 | [diff] [blame] | 219 | WifiStatus WifiRttController::setLcrInternal(uint32_t cmd_id, |
| 220 | const RttLcrInformation& lcr) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 221 | legacy_hal::wifi_lcr_information legacy_lcr; |
| 222 | if (!hidl_struct_util::convertHidlRttLcrInformationToLegacy(lcr, |
| 223 | &legacy_lcr)) { |
| 224 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); |
| 225 | } |
| 226 | legacy_hal::wifi_error legacy_status = |
| 227 | legacy_hal_.lock()->setRttLcr(ifname_, cmd_id, legacy_lcr); |
| 228 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | 7913f5e | 2016-10-27 17:09:30 -0700 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | std::pair<WifiStatus, RttResponder> |
| 232 | WifiRttController::getResponderInfoInternal() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 233 | legacy_hal::wifi_error legacy_status; |
| 234 | legacy_hal::wifi_rtt_responder legacy_responder; |
| 235 | std::tie(legacy_status, legacy_responder) = |
| 236 | legacy_hal_.lock()->getRttResponderInfo(ifname_); |
| 237 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 238 | return {createWifiStatusFromLegacyError(legacy_status), {}}; |
| 239 | } |
| 240 | RttResponder hidl_responder; |
| 241 | if (!hidl_struct_util::convertLegacyRttResponderToHidl(legacy_responder, |
| 242 | &hidl_responder)) { |
| 243 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; |
| 244 | } |
| 245 | return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_responder}; |
Roshan Pius | 7913f5e | 2016-10-27 17:09:30 -0700 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | WifiStatus WifiRttController::enableResponderInternal( |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 249 | uint32_t cmd_id, const WifiChannelInfo& channel_hint, |
| 250 | uint32_t max_duration_seconds, const RttResponder& info) { |
| 251 | legacy_hal::wifi_channel_info legacy_channel_info; |
| 252 | if (!hidl_struct_util::convertHidlWifiChannelInfoToLegacy( |
| 253 | channel_hint, &legacy_channel_info)) { |
| 254 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); |
| 255 | } |
| 256 | legacy_hal::wifi_rtt_responder legacy_responder; |
| 257 | if (!hidl_struct_util::convertHidlRttResponderToLegacy(info, |
| 258 | &legacy_responder)) { |
| 259 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); |
| 260 | } |
| 261 | legacy_hal::wifi_error legacy_status = |
| 262 | legacy_hal_.lock()->enableRttResponder( |
| 263 | ifname_, cmd_id, legacy_channel_info, max_duration_seconds, |
| 264 | legacy_responder); |
| 265 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | 7913f5e | 2016-10-27 17:09:30 -0700 | [diff] [blame] | 266 | } |
| 267 | |
Roshan Pius | e3f72ff | 2016-12-05 16:18:43 -0800 | [diff] [blame] | 268 | WifiStatus WifiRttController::disableResponderInternal(uint32_t cmd_id) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 269 | legacy_hal::wifi_error legacy_status = |
| 270 | legacy_hal_.lock()->disableRttResponder(ifname_, cmd_id); |
| 271 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | 7913f5e | 2016-10-27 17:09:30 -0700 | [diff] [blame] | 272 | } |
Roshan Pius | 5926828 | 2016-10-06 20:23:47 -0700 | [diff] [blame] | 273 | } // namespace implementation |
Jong Wook Kim | da830c9 | 2018-07-23 15:29:38 -0700 | [diff] [blame] | 274 | } // namespace V1_3 |
Roshan Pius | 5926828 | 2016-10-06 20:23:47 -0700 | [diff] [blame] | 275 | } // namespace wifi |
| 276 | } // namespace hardware |
| 277 | } // namespace android |