blob: a0f9969033addc30668284d4d3b361db4249935c [file] [log] [blame]
Roshan Pius59268282016-10-06 20:23:47 -07001/*
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 Pius59268282016-10-06 20:23:47 -070017#include <android-base/logging.h>
18
Roshan Pius907d4a22016-10-27 12:48:12 -070019#include "hidl_return_util.h"
Roshan Piuse3f72ff2016-12-05 16:18:43 -080020#include "hidl_struct_util.h"
Roshan Pius907d4a22016-10-27 12:48:12 -070021#include "wifi_rtt_controller.h"
Roshan Pius734fea02016-10-11 08:30:28 -070022#include "wifi_status_util.h"
Roshan Pius59268282016-10-06 20:23:47 -070023
24namespace android {
25namespace hardware {
26namespace wifi {
Jimmy Chend460df32019-11-29 17:31:22 +020027namespace V1_5 {
Roshan Pius59268282016-10-06 20:23:47 -070028namespace implementation {
Roshan Pius907d4a22016-10-27 12:48:12 -070029using hidl_return_util::validateAndCall;
Roshan Pius59268282016-10-06 20:23:47 -070030
31WifiRttController::WifiRttController(
Roshan Piusabcf78f2017-10-06 16:30:38 -070032 const std::string& iface_name, const sp<IWifiIface>& bound_iface,
Roshan Pius6cedc972016-10-28 10:11:17 -070033 const std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal)
Roshan Piusabcf78f2017-10-06 16:30:38 -070034 : ifname_(iface_name),
35 bound_iface_(bound_iface),
36 legacy_hal_(legacy_hal),
Roshan Pius9377a0d2017-10-06 13:18:54 -070037 is_valid_(true) {}
Roshan Pius59268282016-10-06 20:23:47 -070038
39void WifiRttController::invalidate() {
Roshan Piusabcf78f2017-10-06 16:30:38 -070040 legacy_hal_.reset();
41 event_callbacks_.clear();
42 is_valid_ = false;
Roshan Pius59268282016-10-06 20:23:47 -070043}
44
Roshan Piusabcf78f2017-10-06 16:30:38 -070045bool WifiRttController::isValid() { return is_valid_; }
Roshan Pius907d4a22016-10-27 12:48:12 -070046
Jimmy Chend460df32019-11-29 17:31:22 +020047std::vector<sp<V1_4::IWifiRttControllerEventCallback>>
Roshan Piuse3f72ff2016-12-05 16:18:43 -080048WifiRttController::getEventCallbacks() {
Roshan Piusabcf78f2017-10-06 16:30:38 -070049 return event_callbacks_;
Roshan Piuse3f72ff2016-12-05 16:18:43 -080050}
51
Roshan Pius82368502019-05-16 12:53:02 -070052std::string WifiRttController::getIfaceName() { return ifname_; }
53
Roshan Pius734fea02016-10-11 08:30:28 -070054Return<void> WifiRttController::getBoundIface(getBoundIface_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -070055 return validateAndCall(
56 this, WifiStatusCode::ERROR_WIFI_RTT_CONTROLLER_INVALID,
57 &WifiRttController::getBoundIfaceInternal, hidl_status_cb);
Roshan Pius907d4a22016-10-27 12:48:12 -070058}
59
Roshan Pius7913f5e2016-10-27 17:09:30 -070060Return<void> WifiRttController::registerEventCallback(
Ahmed ElArabawyeeb53382019-10-10 20:18:31 -070061 const sp<V1_0::IWifiRttControllerEventCallback>& callback,
Roshan Pius7913f5e2016-10-27 17:09:30 -070062 registerEventCallback_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -070063 return validateAndCall(this,
64 WifiStatusCode::ERROR_WIFI_RTT_CONTROLLER_INVALID,
65 &WifiRttController::registerEventCallbackInternal,
66 hidl_status_cb, callback);
Roshan Pius7913f5e2016-10-27 17:09:30 -070067}
68
69Return<void> WifiRttController::rangeRequest(
Ahmed ElArabawyeeb53382019-10-10 20:18:31 -070070 uint32_t cmd_id, const hidl_vec<V1_0::RttConfig>& rtt_configs,
Roshan Pius7913f5e2016-10-27 17:09:30 -070071 rangeRequest_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -070072 return validateAndCall(this,
73 WifiStatusCode::ERROR_WIFI_RTT_CONTROLLER_INVALID,
74 &WifiRttController::rangeRequestInternal,
75 hidl_status_cb, cmd_id, rtt_configs);
Roshan Pius7913f5e2016-10-27 17:09:30 -070076}
77
78Return<void> WifiRttController::rangeCancel(
Roshan Piusabcf78f2017-10-06 16:30:38 -070079 uint32_t cmd_id, const hidl_vec<hidl_array<uint8_t, 6>>& addrs,
Roshan Pius7913f5e2016-10-27 17:09:30 -070080 rangeCancel_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -070081 return validateAndCall(
82 this, WifiStatusCode::ERROR_WIFI_RTT_CONTROLLER_INVALID,
83 &WifiRttController::rangeCancelInternal, hidl_status_cb, cmd_id, addrs);
Roshan Pius7913f5e2016-10-27 17:09:30 -070084}
85
Roshan Pius7913f5e2016-10-27 17:09:30 -070086Return<void> WifiRttController::getCapabilities(
87 getCapabilities_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -070088 return validateAndCall(
89 this, WifiStatusCode::ERROR_WIFI_RTT_CONTROLLER_INVALID,
90 &WifiRttController::getCapabilitiesInternal, hidl_status_cb);
Roshan Pius7913f5e2016-10-27 17:09:30 -070091}
92
Roshan Pius7913f5e2016-10-27 17:09:30 -070093Return<void> WifiRttController::setLci(uint32_t cmd_id,
94 const RttLciInformation& lci,
95 setLci_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -070096 return validateAndCall(
97 this, WifiStatusCode::ERROR_WIFI_RTT_CONTROLLER_INVALID,
98 &WifiRttController::setLciInternal, hidl_status_cb, cmd_id, lci);
Roshan Pius7913f5e2016-10-27 17:09:30 -070099}
100
101Return<void> WifiRttController::setLcr(uint32_t cmd_id,
102 const RttLcrInformation& lcr,
103 setLcr_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700104 return validateAndCall(
105 this, WifiStatusCode::ERROR_WIFI_RTT_CONTROLLER_INVALID,
106 &WifiRttController::setLcrInternal, hidl_status_cb, cmd_id, lcr);
Roshan Pius7913f5e2016-10-27 17:09:30 -0700107}
108
109Return<void> WifiRttController::getResponderInfo(
110 getResponderInfo_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700111 return validateAndCall(
112 this, WifiStatusCode::ERROR_WIFI_RTT_CONTROLLER_INVALID,
113 &WifiRttController::getResponderInfoInternal, hidl_status_cb);
Roshan Pius7913f5e2016-10-27 17:09:30 -0700114}
115
116Return<void> WifiRttController::enableResponder(
Roshan Piusabcf78f2017-10-06 16:30:38 -0700117 uint32_t cmd_id, const WifiChannelInfo& channel_hint,
Ahmed ElArabawyeeb53382019-10-10 20:18:31 -0700118 uint32_t max_duration_seconds, const V1_0::RttResponder& info,
Roshan Pius7913f5e2016-10-27 17:09:30 -0700119 enableResponder_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700120 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 Pius7913f5e2016-10-27 17:09:30 -0700124}
125
126Return<void> WifiRttController::disableResponder(
127 uint32_t cmd_id, disableResponder_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700128 return validateAndCall(
129 this, WifiStatusCode::ERROR_WIFI_RTT_CONTROLLER_INVALID,
130 &WifiRttController::disableResponderInternal, hidl_status_cb, cmd_id);
Roshan Pius7913f5e2016-10-27 17:09:30 -0700131}
132
Ahmed ElArabawyeeb53382019-10-10 20:18:31 -0700133Return<void> WifiRttController::registerEventCallback_1_4(
Jimmy Chend460df32019-11-29 17:31:22 +0200134 const sp<V1_4::IWifiRttControllerEventCallback>& callback,
Ahmed ElArabawyeeb53382019-10-10 20:18:31 -0700135 registerEventCallback_1_4_cb hidl_status_cb) {
136 return validateAndCall(
137 this, WifiStatusCode::ERROR_WIFI_RTT_CONTROLLER_INVALID,
138 &WifiRttController::registerEventCallbackInternal_1_4, hidl_status_cb,
139 callback);
140}
141
142Return<void> WifiRttController::rangeRequest_1_4(
Jimmy Chend460df32019-11-29 17:31:22 +0200143 uint32_t cmd_id, const hidl_vec<V1_4::RttConfig>& rtt_configs,
Ahmed ElArabawyeeb53382019-10-10 20:18:31 -0700144 rangeRequest_1_4_cb hidl_status_cb) {
145 return validateAndCall(this,
146 WifiStatusCode::ERROR_WIFI_RTT_CONTROLLER_INVALID,
147 &WifiRttController::rangeRequestInternal_1_4,
148 hidl_status_cb, cmd_id, rtt_configs);
149}
150
151Return<void> WifiRttController::getCapabilities_1_4(
152 getCapabilities_1_4_cb hidl_status_cb) {
153 return validateAndCall(
154 this, WifiStatusCode::ERROR_WIFI_RTT_CONTROLLER_INVALID,
155 &WifiRttController::getCapabilitiesInternal_1_4, hidl_status_cb);
156}
157
158Return<void> WifiRttController::getResponderInfo_1_4(
159 getResponderInfo_1_4_cb hidl_status_cb) {
160 return validateAndCall(
161 this, WifiStatusCode::ERROR_WIFI_RTT_CONTROLLER_INVALID,
162 &WifiRttController::getResponderInfoInternal_1_4, hidl_status_cb);
163}
164
165Return<void> WifiRttController::enableResponder_1_4(
166 uint32_t cmd_id, const WifiChannelInfo& channel_hint,
Jimmy Chend460df32019-11-29 17:31:22 +0200167 uint32_t max_duration_seconds, const V1_4::RttResponder& info,
Ahmed ElArabawyeeb53382019-10-10 20:18:31 -0700168 enableResponder_1_4_cb hidl_status_cb) {
169 return validateAndCall(
170 this, WifiStatusCode::ERROR_WIFI_RTT_CONTROLLER_INVALID,
171 &WifiRttController::enableResponderInternal_1_4, hidl_status_cb, cmd_id,
172 channel_hint, max_duration_seconds, info);
173}
174
Roshan Pius907d4a22016-10-27 12:48:12 -0700175std::pair<WifiStatus, sp<IWifiIface>>
176WifiRttController::getBoundIfaceInternal() {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700177 return {createWifiStatus(WifiStatusCode::SUCCESS), bound_iface_};
Roshan Pius59268282016-10-06 20:23:47 -0700178}
179
Roshan Pius7913f5e2016-10-27 17:09:30 -0700180WifiStatus WifiRttController::registerEventCallbackInternal(
Ahmed ElArabawyeeb53382019-10-10 20:18:31 -0700181 const sp<V1_0::IWifiRttControllerEventCallback>& /* callback */) {
182 // Deprecated support for this api
183 return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED);
Roshan Pius7913f5e2016-10-27 17:09:30 -0700184}
185
186WifiStatus WifiRttController::rangeRequestInternal(
Ahmed ElArabawyeeb53382019-10-10 20:18:31 -0700187 uint32_t /* cmd_id */,
188 const std::vector<V1_0::RttConfig>& /* rtt_configs */) {
189 // Deprecated support for this api
190 return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED);
Roshan Pius7913f5e2016-10-27 17:09:30 -0700191}
192
193WifiStatus WifiRttController::rangeCancelInternal(
Roshan Piuse3f72ff2016-12-05 16:18:43 -0800194 uint32_t cmd_id, const std::vector<hidl_array<uint8_t, 6>>& addrs) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700195 std::vector<std::array<uint8_t, 6>> legacy_addrs;
196 for (const auto& addr : addrs) {
197 legacy_addrs.push_back(addr);
198 }
199 legacy_hal::wifi_error legacy_status =
200 legacy_hal_.lock()->cancelRttRangeRequest(ifname_, cmd_id,
201 legacy_addrs);
202 return createWifiStatusFromLegacyError(legacy_status);
Roshan Pius7913f5e2016-10-27 17:09:30 -0700203}
204
Ahmed ElArabawyeeb53382019-10-10 20:18:31 -0700205std::pair<WifiStatus, V1_0::RttCapabilities>
Roshan Pius7913f5e2016-10-27 17:09:30 -0700206WifiRttController::getCapabilitiesInternal() {
Ahmed ElArabawyeeb53382019-10-10 20:18:31 -0700207 // Deprecated support for this api
208 return {createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED), {}};
Roshan Pius7913f5e2016-10-27 17:09:30 -0700209}
210
Roshan Piuse3f72ff2016-12-05 16:18:43 -0800211WifiStatus WifiRttController::setLciInternal(uint32_t cmd_id,
212 const RttLciInformation& lci) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700213 legacy_hal::wifi_lci_information legacy_lci;
214 if (!hidl_struct_util::convertHidlRttLciInformationToLegacy(lci,
215 &legacy_lci)) {
216 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
217 }
218 legacy_hal::wifi_error legacy_status =
219 legacy_hal_.lock()->setRttLci(ifname_, cmd_id, legacy_lci);
220 return createWifiStatusFromLegacyError(legacy_status);
Roshan Pius7913f5e2016-10-27 17:09:30 -0700221}
222
Roshan Piuse3f72ff2016-12-05 16:18:43 -0800223WifiStatus WifiRttController::setLcrInternal(uint32_t cmd_id,
224 const RttLcrInformation& lcr) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700225 legacy_hal::wifi_lcr_information legacy_lcr;
226 if (!hidl_struct_util::convertHidlRttLcrInformationToLegacy(lcr,
227 &legacy_lcr)) {
228 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
229 }
230 legacy_hal::wifi_error legacy_status =
231 legacy_hal_.lock()->setRttLcr(ifname_, cmd_id, legacy_lcr);
232 return createWifiStatusFromLegacyError(legacy_status);
Roshan Pius7913f5e2016-10-27 17:09:30 -0700233}
234
Ahmed ElArabawyeeb53382019-10-10 20:18:31 -0700235std::pair<WifiStatus, V1_0::RttResponder>
Roshan Pius7913f5e2016-10-27 17:09:30 -0700236WifiRttController::getResponderInfoInternal() {
Ahmed ElArabawyeeb53382019-10-10 20:18:31 -0700237 // Deprecated support for this api
238 return {createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED), {}};
239}
240
241WifiStatus WifiRttController::enableResponderInternal(
242 uint32_t /* cmd_id */, const WifiChannelInfo& /* channel_hint */,
243 uint32_t /* max_duration_seconds */, const V1_0::RttResponder& /* info */) {
244 // Deprecated support for this api
245 return {createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED)};
246}
247
248WifiStatus WifiRttController::disableResponderInternal(uint32_t cmd_id) {
249 legacy_hal::wifi_error legacy_status =
250 legacy_hal_.lock()->disableRttResponder(ifname_, cmd_id);
251 return createWifiStatusFromLegacyError(legacy_status);
252}
253
254WifiStatus WifiRttController::registerEventCallbackInternal_1_4(
Jimmy Chend460df32019-11-29 17:31:22 +0200255 const sp<V1_4::IWifiRttControllerEventCallback>& callback) {
Ahmed ElArabawyeeb53382019-10-10 20:18:31 -0700256 // TODO(b/31632518): remove the callback when the client is destroyed
257 event_callbacks_.emplace_back(callback);
258 return createWifiStatus(WifiStatusCode::SUCCESS);
259}
260
261WifiStatus WifiRttController::rangeRequestInternal_1_4(
Jimmy Chend460df32019-11-29 17:31:22 +0200262 uint32_t cmd_id, const std::vector<V1_4::RttConfig>& rtt_configs) {
Ahmed ElArabawyeeb53382019-10-10 20:18:31 -0700263 std::vector<legacy_hal::wifi_rtt_config> legacy_configs;
264 if (!hidl_struct_util::convertHidlVectorOfRttConfigToLegacy(
265 rtt_configs, &legacy_configs)) {
266 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
267 }
268 android::wp<WifiRttController> weak_ptr_this(this);
269 const auto& on_results_callback =
270 [weak_ptr_this](
271 legacy_hal::wifi_request_id id,
272 const std::vector<const legacy_hal::wifi_rtt_result*>& results) {
273 const auto shared_ptr_this = weak_ptr_this.promote();
274 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
275 LOG(ERROR) << "Callback invoked on an invalid object";
276 return;
277 }
Jimmy Chend460df32019-11-29 17:31:22 +0200278 std::vector<V1_4::RttResult> hidl_results;
Ahmed ElArabawyeeb53382019-10-10 20:18:31 -0700279 if (!hidl_struct_util::convertLegacyVectorOfRttResultToHidl(
280 results, &hidl_results)) {
281 LOG(ERROR) << "Failed to convert rtt results to HIDL structs";
282 return;
283 }
284 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
285 callback->onResults_1_4(id, hidl_results);
286 }
287 };
288 legacy_hal::wifi_error legacy_status =
289 legacy_hal_.lock()->startRttRangeRequest(
290 ifname_, cmd_id, legacy_configs, on_results_callback);
291 return createWifiStatusFromLegacyError(legacy_status);
292}
293
Jimmy Chend460df32019-11-29 17:31:22 +0200294std::pair<WifiStatus, V1_4::RttCapabilities>
Ahmed ElArabawyeeb53382019-10-10 20:18:31 -0700295WifiRttController::getCapabilitiesInternal_1_4() {
296 legacy_hal::wifi_error legacy_status;
297 legacy_hal::wifi_rtt_capabilities legacy_caps;
298 std::tie(legacy_status, legacy_caps) =
299 legacy_hal_.lock()->getRttCapabilities(ifname_);
300 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
301 return {createWifiStatusFromLegacyError(legacy_status), {}};
302 }
Jimmy Chend460df32019-11-29 17:31:22 +0200303 V1_4::RttCapabilities hidl_caps;
Ahmed ElArabawyeeb53382019-10-10 20:18:31 -0700304 if (!hidl_struct_util::convertLegacyRttCapabilitiesToHidl(legacy_caps,
305 &hidl_caps)) {
306 return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}};
307 }
308 return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_caps};
309}
310
Jimmy Chend460df32019-11-29 17:31:22 +0200311std::pair<WifiStatus, V1_4::RttResponder>
Ahmed ElArabawyeeb53382019-10-10 20:18:31 -0700312WifiRttController::getResponderInfoInternal_1_4() {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700313 legacy_hal::wifi_error legacy_status;
314 legacy_hal::wifi_rtt_responder legacy_responder;
315 std::tie(legacy_status, legacy_responder) =
316 legacy_hal_.lock()->getRttResponderInfo(ifname_);
317 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
318 return {createWifiStatusFromLegacyError(legacy_status), {}};
319 }
Jimmy Chend460df32019-11-29 17:31:22 +0200320 V1_4::RttResponder hidl_responder;
Roshan Piusabcf78f2017-10-06 16:30:38 -0700321 if (!hidl_struct_util::convertLegacyRttResponderToHidl(legacy_responder,
322 &hidl_responder)) {
323 return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}};
324 }
325 return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_responder};
Roshan Pius7913f5e2016-10-27 17:09:30 -0700326}
327
Ahmed ElArabawyeeb53382019-10-10 20:18:31 -0700328WifiStatus WifiRttController::enableResponderInternal_1_4(
Roshan Piusabcf78f2017-10-06 16:30:38 -0700329 uint32_t cmd_id, const WifiChannelInfo& channel_hint,
Jimmy Chend460df32019-11-29 17:31:22 +0200330 uint32_t max_duration_seconds, const V1_4::RttResponder& info) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700331 legacy_hal::wifi_channel_info legacy_channel_info;
332 if (!hidl_struct_util::convertHidlWifiChannelInfoToLegacy(
333 channel_hint, &legacy_channel_info)) {
334 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
335 }
336 legacy_hal::wifi_rtt_responder legacy_responder;
337 if (!hidl_struct_util::convertHidlRttResponderToLegacy(info,
338 &legacy_responder)) {
339 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
340 }
341 legacy_hal::wifi_error legacy_status =
342 legacy_hal_.lock()->enableRttResponder(
343 ifname_, cmd_id, legacy_channel_info, max_duration_seconds,
344 legacy_responder);
345 return createWifiStatusFromLegacyError(legacy_status);
Roshan Pius7913f5e2016-10-27 17:09:30 -0700346}
Roshan Pius59268282016-10-06 20:23:47 -0700347} // namespace implementation
Jimmy Chend460df32019-11-29 17:31:22 +0200348} // namespace V1_5
Roshan Pius59268282016-10-06 20:23:47 -0700349} // namespace wifi
350} // namespace hardware
351} // namespace android