blob: 1add6dce5c3701bb33f4d586fe1ea2e387a84df0 [file] [log] [blame]
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001/*
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 <android-base/logging.h>
18
19#include "hidl_return_util.h"
20#include "hidl_struct_util.h"
21#include "wifi_nan_iface.h"
22#include "wifi_status_util.h"
23
24namespace android {
25namespace hardware {
26namespace wifi {
27namespace V1_6 {
28namespace implementation {
29using hidl_return_util::validateAndCall;
30
31WifiNanIface::WifiNanIface(const std::string& ifname, bool is_dedicated_iface,
32 const std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal,
33 const std::weak_ptr<iface_util::WifiIfaceUtil> iface_util)
34 : ifname_(ifname),
35 is_dedicated_iface_(is_dedicated_iface),
36 legacy_hal_(legacy_hal),
37 iface_util_(iface_util),
38 is_valid_(true) {
39 if (is_dedicated_iface_) {
40 // If using a dedicated iface, set the iface up first.
41 if (!iface_util_.lock()->setUpState(ifname_, true)) {
42 // Fatal failure, invalidate the iface object.
43 invalidate();
44 return;
45 }
46 }
47 // Register all the callbacks here. these should be valid for the lifetime
48 // of the object. Whenever the mode changes legacy HAL will remove
49 // all of these callbacks.
50 legacy_hal::NanCallbackHandlers callback_handlers;
51 android::wp<WifiNanIface> weak_ptr_this(this);
52
53 // Callback for response.
54 callback_handlers.on_notify_response = [weak_ptr_this](legacy_hal::transaction_id id,
55 const legacy_hal::NanResponseMsg& msg) {
56 const auto shared_ptr_this = weak_ptr_this.promote();
57 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
58 LOG(ERROR) << "Callback invoked on an invalid object";
59 return;
60 }
61 WifiNanStatus wifiNanStatus;
62 if (!hidl_struct_util::convertLegacyNanResponseHeaderToHidl(msg, &wifiNanStatus)) {
63 LOG(ERROR) << "Failed to convert nan response header";
64 return;
65 }
66
67 switch (msg.response_type) {
68 case legacy_hal::NAN_RESPONSE_ENABLED: {
69 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
70 if (!callback->notifyEnableResponse(id, wifiNanStatus).isOk()) {
71 LOG(ERROR) << "Failed to invoke the callback";
72 }
73 }
74 break;
75 }
76 case legacy_hal::NAN_RESPONSE_DISABLED: {
77 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
78 if (!callback->notifyDisableResponse(id, wifiNanStatus).isOk()) {
79 LOG(ERROR) << "Failed to invoke the callback";
80 }
81 }
82 break;
83 }
84 case legacy_hal::NAN_RESPONSE_PUBLISH: {
85 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
86 if (!callback->notifyStartPublishResponse(id, wifiNanStatus,
87 msg.body.publish_response.publish_id)
88 .isOk()) {
89 LOG(ERROR) << "Failed to invoke the callback";
90 }
91 }
92 break;
93 }
94 case legacy_hal::NAN_RESPONSE_PUBLISH_CANCEL: {
95 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
96 if (!callback->notifyStopPublishResponse(id, wifiNanStatus).isOk()) {
97 LOG(ERROR) << "Failed to invoke the callback";
98 }
99 }
100 break;
101 }
102 case legacy_hal::NAN_RESPONSE_TRANSMIT_FOLLOWUP: {
103 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
104 if (!callback->notifyTransmitFollowupResponse(id, wifiNanStatus).isOk()) {
105 LOG(ERROR) << "Failed to invoke the callback";
106 }
107 }
108 break;
109 }
110 case legacy_hal::NAN_RESPONSE_SUBSCRIBE: {
111 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
112 if (!callback->notifyStartSubscribeResponse(
113 id, wifiNanStatus,
114 msg.body.subscribe_response.subscribe_id)
115 .isOk()) {
116 LOG(ERROR) << "Failed to invoke the callback";
117 }
118 }
119 break;
120 }
121 case legacy_hal::NAN_RESPONSE_SUBSCRIBE_CANCEL: {
122 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
123 if (!callback->notifyStopSubscribeResponse(id, wifiNanStatus).isOk()) {
124 LOG(ERROR) << "Failed to invoke the callback";
125 }
126 }
127 break;
128 }
129 case legacy_hal::NAN_RESPONSE_CONFIG: {
130 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
131 if (!callback->notifyConfigResponse(id, wifiNanStatus).isOk()) {
132 LOG(ERROR) << "Failed to invoke the callback";
133 }
134 }
135 break;
136 }
137 case legacy_hal::NAN_GET_CAPABILITIES: {
138 V1_5::NanCapabilities hidl_struct;
139 if (!hidl_struct_util::convertLegacyNanCapabilitiesResponseToHidl(
140 msg.body.nan_capabilities, &hidl_struct)) {
141 LOG(ERROR) << "Failed to convert nan capabilities response";
142 return;
143 }
144 for (const auto& callback : shared_ptr_this->getEventCallbacks_1_5()) {
145 if (!callback->notifyCapabilitiesResponse_1_5(id, wifiNanStatus, hidl_struct)
146 .isOk()) {
147 LOG(ERROR) << "Failed to invoke the callback";
148 }
149 }
150 break;
151 }
152 case legacy_hal::NAN_DP_INTERFACE_CREATE: {
153 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
154 if (!callback->notifyCreateDataInterfaceResponse(id, wifiNanStatus).isOk()) {
155 LOG(ERROR) << "Failed to invoke the callback";
156 }
157 }
158 break;
159 }
160 case legacy_hal::NAN_DP_INTERFACE_DELETE: {
161 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
162 if (!callback->notifyDeleteDataInterfaceResponse(id, wifiNanStatus).isOk()) {
163 LOG(ERROR) << "Failed to invoke the callback";
164 }
165 }
166 break;
167 }
168 case legacy_hal::NAN_DP_INITIATOR_RESPONSE: {
169 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
170 if (!callback->notifyInitiateDataPathResponse(
171 id, wifiNanStatus,
172 msg.body.data_request_response.ndp_instance_id)
173 .isOk()) {
174 LOG(ERROR) << "Failed to invoke the callback";
175 }
176 }
177 break;
178 }
179 case legacy_hal::NAN_DP_RESPONDER_RESPONSE: {
180 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
181 if (!callback->notifyRespondToDataPathIndicationResponse(id, wifiNanStatus)
182 .isOk()) {
183 LOG(ERROR) << "Failed to invoke the callback";
184 }
185 }
186 break;
187 }
188 case legacy_hal::NAN_DP_END: {
189 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
190 if (!callback->notifyTerminateDataPathResponse(id, wifiNanStatus).isOk()) {
191 LOG(ERROR) << "Failed to invoke the callback";
192 }
193 }
194 break;
195 }
196 case legacy_hal::NAN_RESPONSE_BEACON_SDF_PAYLOAD:
197 /* fall through */
198 case legacy_hal::NAN_RESPONSE_TCA:
199 /* fall through */
200 case legacy_hal::NAN_RESPONSE_STATS:
201 /* fall through */
202 case legacy_hal::NAN_RESPONSE_ERROR:
203 /* fall through */
204 default:
205 LOG(ERROR) << "Unknown or unhandled response type: " << msg.response_type;
206 return;
207 }
208 };
209
210 callback_handlers.on_event_disc_eng_event =
211 [weak_ptr_this](const legacy_hal::NanDiscEngEventInd& msg) {
212 const auto shared_ptr_this = weak_ptr_this.promote();
213 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
214 LOG(ERROR) << "Callback invoked on an invalid object";
215 return;
216 }
217 NanClusterEventInd hidl_struct;
218 // event types defined identically - hence can be cast
219 hidl_struct.eventType = (NanClusterEventType)msg.event_type;
220 hidl_struct.addr = msg.data.mac_addr.addr;
221
222 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
223 if (!callback->eventClusterEvent(hidl_struct).isOk()) {
224 LOG(ERROR) << "Failed to invoke the callback";
225 }
226 }
227 };
228
229 callback_handlers.on_event_disabled = [weak_ptr_this](const legacy_hal::NanDisabledInd& msg) {
230 const auto shared_ptr_this = weak_ptr_this.promote();
231 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
232 LOG(ERROR) << "Callback invoked on an invalid object";
233 return;
234 }
235 WifiNanStatus status;
236 hidl_struct_util::convertToWifiNanStatus(msg.reason, msg.nan_reason, sizeof(msg.nan_reason),
237 &status);
238
239 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
240 if (!callback->eventDisabled(status).isOk()) {
241 LOG(ERROR) << "Failed to invoke the callback";
242 }
243 }
244 };
245
246 callback_handlers.on_event_publish_terminated =
247 [weak_ptr_this](const legacy_hal::NanPublishTerminatedInd& msg) {
248 const auto shared_ptr_this = weak_ptr_this.promote();
249 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
250 LOG(ERROR) << "Callback invoked on an invalid object";
251 return;
252 }
253 WifiNanStatus status;
254 hidl_struct_util::convertToWifiNanStatus(msg.reason, msg.nan_reason,
255 sizeof(msg.nan_reason), &status);
256
257 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
258 if (!callback->eventPublishTerminated(msg.publish_id, status).isOk()) {
259 LOG(ERROR) << "Failed to invoke the callback";
260 }
261 }
262 };
263
264 callback_handlers.on_event_subscribe_terminated =
265 [weak_ptr_this](const legacy_hal::NanSubscribeTerminatedInd& msg) {
266 const auto shared_ptr_this = weak_ptr_this.promote();
267 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
268 LOG(ERROR) << "Callback invoked on an invalid object";
269 return;
270 }
271 WifiNanStatus status;
272 hidl_struct_util::convertToWifiNanStatus(msg.reason, msg.nan_reason,
273 sizeof(msg.nan_reason), &status);
274
275 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
276 if (!callback->eventSubscribeTerminated(msg.subscribe_id, status).isOk()) {
277 LOG(ERROR) << "Failed to invoke the callback";
278 }
279 }
280 };
281
282 callback_handlers.on_event_match = [weak_ptr_this](const legacy_hal::NanMatchInd& msg) {
283 const auto shared_ptr_this = weak_ptr_this.promote();
284 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
285 LOG(ERROR) << "Callback invoked on an invalid object";
286 return;
287 }
288 NanMatchInd hidl_struct;
289 if (!hidl_struct_util::convertLegacyNanMatchIndToHidl(msg, &hidl_struct)) {
290 LOG(ERROR) << "Failed to convert nan capabilities response";
291 return;
292 }
293
294 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
295 if (!callback->eventMatch(hidl_struct).isOk()) {
296 LOG(ERROR) << "Failed to invoke the callback";
297 }
298 }
299 };
300
301 callback_handlers.on_event_match_expired = [weak_ptr_this](
302 const legacy_hal::NanMatchExpiredInd& msg) {
303 const auto shared_ptr_this = weak_ptr_this.promote();
304 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
305 LOG(ERROR) << "Callback invoked on an invalid object";
306 return;
307 }
308 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
309 if (!callback->eventMatchExpired(msg.publish_subscribe_id, msg.requestor_instance_id)
310 .isOk()) {
311 LOG(ERROR) << "Failed to invoke the callback";
312 }
313 }
314 };
315
316 callback_handlers.on_event_followup = [weak_ptr_this](const legacy_hal::NanFollowupInd& msg) {
317 const auto shared_ptr_this = weak_ptr_this.promote();
318 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
319 LOG(ERROR) << "Callback invoked on an invalid object";
320 return;
321 }
322 NanFollowupReceivedInd hidl_struct;
323 if (!hidl_struct_util::convertLegacyNanFollowupIndToHidl(msg, &hidl_struct)) {
324 LOG(ERROR) << "Failed to convert nan capabilities response";
325 return;
326 }
327
328 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
329 if (!callback->eventFollowupReceived(hidl_struct).isOk()) {
330 LOG(ERROR) << "Failed to invoke the callback";
331 }
332 }
333 };
334
335 callback_handlers.on_event_transmit_follow_up =
336 [weak_ptr_this](const legacy_hal::NanTransmitFollowupInd& msg) {
337 const auto shared_ptr_this = weak_ptr_this.promote();
338 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
339 LOG(ERROR) << "Callback invoked on an invalid object";
340 return;
341 }
342 WifiNanStatus status;
343 hidl_struct_util::convertToWifiNanStatus(msg.reason, msg.nan_reason,
344 sizeof(msg.nan_reason), &status);
345
346 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
347 if (!callback->eventTransmitFollowup(msg.id, status).isOk()) {
348 LOG(ERROR) << "Failed to invoke the callback";
349 }
350 }
351 };
352
353 callback_handlers.on_event_data_path_request =
354 [weak_ptr_this](const legacy_hal::NanDataPathRequestInd& msg) {
355 const auto shared_ptr_this = weak_ptr_this.promote();
356 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
357 LOG(ERROR) << "Callback invoked on an invalid object";
358 return;
359 }
360 NanDataPathRequestInd hidl_struct;
361 if (!hidl_struct_util::convertLegacyNanDataPathRequestIndToHidl(msg,
362 &hidl_struct)) {
363 LOG(ERROR) << "Failed to convert nan capabilities response";
364 return;
365 }
366
367 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
368 if (!callback->eventDataPathRequest(hidl_struct).isOk()) {
369 LOG(ERROR) << "Failed to invoke the callback";
370 }
371 }
372 };
373
374 callback_handlers.on_event_data_path_confirm =
375 [weak_ptr_this](const legacy_hal::NanDataPathConfirmInd& msg) {
376 const auto shared_ptr_this = weak_ptr_this.promote();
377 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
378 LOG(ERROR) << "Callback invoked on an invalid object";
379 return;
380 }
Ahmed ElArabawy05571e42022-01-19 11:54:11 -0800381 V1_6::NanDataPathConfirmInd hidl_struct;
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800382 if (!hidl_struct_util::convertLegacyNanDataPathConfirmIndToHidl(msg,
383 &hidl_struct)) {
384 LOG(ERROR) << "Failed to convert nan capabilities response";
385 return;
386 }
387
Ahmed ElArabawy05571e42022-01-19 11:54:11 -0800388 for (const auto& callback : shared_ptr_this->getEventCallbacks_1_6()) {
389 if (!callback->eventDataPathConfirm_1_6(hidl_struct).isOk()) {
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800390 LOG(ERROR) << "Failed to invoke the callback";
391 }
392 }
393 };
394
395 callback_handlers.on_event_data_path_end =
396 [weak_ptr_this](const legacy_hal::NanDataPathEndInd& msg) {
397 const auto shared_ptr_this = weak_ptr_this.promote();
398 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
399 LOG(ERROR) << "Callback invoked on an invalid object";
400 return;
401 }
402 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
403 for (int i = 0; i < msg.num_ndp_instances; ++i) {
404 if (!callback->eventDataPathTerminated(msg.ndp_instance_id[i]).isOk()) {
405 LOG(ERROR) << "Failed to invoke the callback";
406 }
407 }
408 }
409 };
410
411 callback_handlers.on_event_beacon_sdf_payload =
412 [weak_ptr_this](const legacy_hal::NanBeaconSdfPayloadInd& /* msg */) {
413 LOG(ERROR) << "on_event_beacon_sdf_payload - should not be called";
414 };
415
416 callback_handlers.on_event_range_request =
417 [weak_ptr_this](const legacy_hal::NanRangeRequestInd& /* msg */) {
418 LOG(ERROR) << "on_event_range_request - should not be called";
419 };
420
421 callback_handlers.on_event_range_report =
422 [weak_ptr_this](const legacy_hal::NanRangeReportInd& /* msg */) {
423 LOG(ERROR) << "on_event_range_report - should not be called";
424 };
425
426 callback_handlers.on_event_schedule_update =
427 [weak_ptr_this](const legacy_hal::NanDataPathScheduleUpdateInd& msg) {
428 const auto shared_ptr_this = weak_ptr_this.promote();
429 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
430 LOG(ERROR) << "Callback invoked on an invalid object";
431 return;
432 }
Ahmed ElArabawy05571e42022-01-19 11:54:11 -0800433 V1_6::NanDataPathScheduleUpdateInd hidl_struct;
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800434 if (!hidl_struct_util::convertLegacyNanDataPathScheduleUpdateIndToHidl(
435 msg, &hidl_struct)) {
436 LOG(ERROR) << "Failed to convert nan capabilities response";
437 return;
438 }
439
Ahmed ElArabawy05571e42022-01-19 11:54:11 -0800440 for (const auto& callback : shared_ptr_this->getEventCallbacks_1_6()) {
441 if (!callback->eventDataPathScheduleUpdate_1_6(hidl_struct).isOk()) {
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800442 LOG(ERROR) << "Failed to invoke the callback";
443 }
444 }
445 };
446
447 legacy_hal::wifi_error legacy_status =
448 legacy_hal_.lock()->nanRegisterCallbackHandlers(ifname_, callback_handlers);
449 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
450 LOG(ERROR) << "Failed to register nan callbacks. Invalidating object";
451 invalidate();
452 }
453
454 // Register for iface state toggle events.
455 iface_util::IfaceEventHandlers event_handlers = {};
456 event_handlers.on_state_toggle_off_on = [weak_ptr_this](const std::string& /* iface_name */) {
457 const auto shared_ptr_this = weak_ptr_this.promote();
458 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
459 LOG(ERROR) << "Callback invoked on an invalid object";
460 return;
461 }
462 // Tell framework that NAN has been disabled.
463 WifiNanStatus status = {NanStatusType::UNSUPPORTED_CONCURRENCY_NAN_DISABLED, ""};
464 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
465 if (!callback->eventDisabled(status).isOk()) {
466 LOG(ERROR) << "Failed to invoke the callback";
467 }
468 }
469 };
470 iface_util_.lock()->registerIfaceEventHandlers(ifname_, event_handlers);
471}
472
473void WifiNanIface::invalidate() {
474 if (!isValid()) {
475 return;
476 }
477 // send commands to HAL to actually disable and destroy interfaces
478 legacy_hal_.lock()->nanDisableRequest(ifname_, 0xFFFF);
479 legacy_hal_.lock()->nanDataInterfaceDelete(ifname_, 0xFFFE, "aware_data0");
480 legacy_hal_.lock()->nanDataInterfaceDelete(ifname_, 0xFFFD, "aware_data1");
481 iface_util_.lock()->unregisterIfaceEventHandlers(ifname_);
482 legacy_hal_.reset();
483 event_cb_handler_.invalidate();
484 event_cb_handler_1_2_.invalidate();
485 event_cb_handler_1_5_.invalidate();
486 is_valid_ = false;
487 if (is_dedicated_iface_) {
488 // If using a dedicated iface, set the iface down.
489 iface_util_.lock()->setUpState(ifname_, false);
490 }
491}
492
493bool WifiNanIface::isValid() {
494 return is_valid_;
495}
496
497std::string WifiNanIface::getName() {
498 return ifname_;
499}
500
501std::set<sp<V1_0::IWifiNanIfaceEventCallback>> WifiNanIface::getEventCallbacks() {
502 return event_cb_handler_.getCallbacks();
503}
504
505std::set<sp<V1_2::IWifiNanIfaceEventCallback>> WifiNanIface::getEventCallbacks_1_2() {
506 return event_cb_handler_1_2_.getCallbacks();
507}
508
509std::set<sp<V1_5::IWifiNanIfaceEventCallback>> WifiNanIface::getEventCallbacks_1_5() {
510 return event_cb_handler_1_5_.getCallbacks();
511}
512
Ahmed ElArabawy05571e42022-01-19 11:54:11 -0800513std::set<sp<V1_6::IWifiNanIfaceEventCallback>> WifiNanIface::getEventCallbacks_1_6() {
514 return event_cb_handler_1_6_.getCallbacks();
515}
516
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800517Return<void> WifiNanIface::getName(getName_cb hidl_status_cb) {
518 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
519 &WifiNanIface::getNameInternal, hidl_status_cb);
520}
521
522Return<void> WifiNanIface::getType(getType_cb hidl_status_cb) {
523 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
524 &WifiNanIface::getTypeInternal, hidl_status_cb);
525}
526
527Return<void> WifiNanIface::registerEventCallback(
528 const sp<V1_0::IWifiNanIfaceEventCallback>& callback,
529 registerEventCallback_cb hidl_status_cb) {
530 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
531 &WifiNanIface::registerEventCallbackInternal, hidl_status_cb, callback);
532}
533
534Return<void> WifiNanIface::getCapabilitiesRequest(uint16_t cmd_id,
535 getCapabilitiesRequest_cb hidl_status_cb) {
536 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
537 &WifiNanIface::getCapabilitiesRequestInternal, hidl_status_cb, cmd_id);
538}
539
540Return<void> WifiNanIface::enableRequest(uint16_t cmd_id, const V1_0::NanEnableRequest& msg,
541 enableRequest_cb hidl_status_cb) {
542 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
543 &WifiNanIface::enableRequestInternal, hidl_status_cb, cmd_id, msg);
544}
545
546Return<void> WifiNanIface::configRequest(uint16_t cmd_id, const V1_0::NanConfigRequest& msg,
547 configRequest_cb hidl_status_cb) {
548 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
549 &WifiNanIface::configRequestInternal, hidl_status_cb, cmd_id, msg);
550}
551
552Return<void> WifiNanIface::disableRequest(uint16_t cmd_id, disableRequest_cb hidl_status_cb) {
553 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
554 &WifiNanIface::disableRequestInternal, hidl_status_cb, cmd_id);
555}
556
557Return<void> WifiNanIface::startPublishRequest(uint16_t cmd_id, const NanPublishRequest& msg,
558 startPublishRequest_cb hidl_status_cb) {
559 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
560 &WifiNanIface::startPublishRequestInternal, hidl_status_cb, cmd_id, msg);
561}
562
563Return<void> WifiNanIface::stopPublishRequest(uint16_t cmd_id, uint8_t sessionId,
564 stopPublishRequest_cb hidl_status_cb) {
565 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
566 &WifiNanIface::stopPublishRequestInternal, hidl_status_cb, cmd_id,
567 sessionId);
568}
569
570Return<void> WifiNanIface::startSubscribeRequest(uint16_t cmd_id, const NanSubscribeRequest& msg,
571 startSubscribeRequest_cb hidl_status_cb) {
572 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
573 &WifiNanIface::startSubscribeRequestInternal, hidl_status_cb, cmd_id,
574 msg);
575}
576
577Return<void> WifiNanIface::stopSubscribeRequest(uint16_t cmd_id, uint8_t sessionId,
578 stopSubscribeRequest_cb hidl_status_cb) {
579 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
580 &WifiNanIface::stopSubscribeRequestInternal, hidl_status_cb, cmd_id,
581 sessionId);
582}
583
584Return<void> WifiNanIface::transmitFollowupRequest(uint16_t cmd_id,
585 const NanTransmitFollowupRequest& msg,
586 transmitFollowupRequest_cb hidl_status_cb) {
587 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
588 &WifiNanIface::transmitFollowupRequestInternal, hidl_status_cb, cmd_id,
589 msg);
590}
591
592Return<void> WifiNanIface::createDataInterfaceRequest(
593 uint16_t cmd_id, const hidl_string& iface_name,
594 createDataInterfaceRequest_cb hidl_status_cb) {
595 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
596 &WifiNanIface::createDataInterfaceRequestInternal, hidl_status_cb,
597 cmd_id, iface_name);
598}
599
600Return<void> WifiNanIface::deleteDataInterfaceRequest(
601 uint16_t cmd_id, const hidl_string& iface_name,
602 deleteDataInterfaceRequest_cb hidl_status_cb) {
603 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
604 &WifiNanIface::deleteDataInterfaceRequestInternal, hidl_status_cb,
605 cmd_id, iface_name);
606}
607
608Return<void> WifiNanIface::initiateDataPathRequest(uint16_t cmd_id,
609 const NanInitiateDataPathRequest& msg,
610 initiateDataPathRequest_cb hidl_status_cb) {
611 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
612 &WifiNanIface::initiateDataPathRequestInternal, hidl_status_cb, cmd_id,
613 msg);
614}
615
616Return<void> WifiNanIface::respondToDataPathIndicationRequest(
617 uint16_t cmd_id, const NanRespondToDataPathIndicationRequest& msg,
618 respondToDataPathIndicationRequest_cb hidl_status_cb) {
619 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
620 &WifiNanIface::respondToDataPathIndicationRequestInternal,
621 hidl_status_cb, cmd_id, msg);
622}
623
624Return<void> WifiNanIface::terminateDataPathRequest(uint16_t cmd_id, uint32_t ndpInstanceId,
625 terminateDataPathRequest_cb hidl_status_cb) {
626 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
627 &WifiNanIface::terminateDataPathRequestInternal, hidl_status_cb, cmd_id,
628 ndpInstanceId);
629}
630
631Return<void> WifiNanIface::registerEventCallback_1_2(
632 const sp<V1_2::IWifiNanIfaceEventCallback>& callback,
633 registerEventCallback_1_2_cb hidl_status_cb) {
634 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
635 &WifiNanIface::registerEventCallback_1_2Internal, hidl_status_cb,
636 callback);
637}
638
639Return<void> WifiNanIface::enableRequest_1_2(uint16_t cmd_id, const V1_0::NanEnableRequest& msg1,
640 const V1_2::NanConfigRequestSupplemental& msg2,
641 enableRequest_1_2_cb hidl_status_cb) {
642 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
643 &WifiNanIface::enableRequest_1_2Internal, hidl_status_cb, cmd_id, msg1,
644 msg2);
645}
646
647Return<void> WifiNanIface::configRequest_1_2(uint16_t cmd_id, const V1_0::NanConfigRequest& msg1,
648 const V1_2::NanConfigRequestSupplemental& msg2,
649 configRequest_1_2_cb hidl_status_cb) {
650 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
651 &WifiNanIface::configRequest_1_2Internal, hidl_status_cb, cmd_id, msg1,
652 msg2);
653}
654
655Return<void> WifiNanIface::enableRequest_1_4(uint16_t cmd_id, const V1_4::NanEnableRequest& msg1,
656 const V1_2::NanConfigRequestSupplemental& msg2,
657 enableRequest_1_4_cb hidl_status_cb) {
658 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
659 &WifiNanIface::enableRequest_1_4Internal, hidl_status_cb, cmd_id, msg1,
660 msg2);
661}
662
663Return<void> WifiNanIface::configRequest_1_4(uint16_t cmd_id, const V1_4::NanConfigRequest& msg1,
664 const V1_2::NanConfigRequestSupplemental& msg2,
665 configRequest_1_4_cb hidl_status_cb) {
666 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
667 &WifiNanIface::configRequest_1_4Internal, hidl_status_cb, cmd_id, msg1,
668 msg2);
669}
670
671Return<void> WifiNanIface::registerEventCallback_1_5(
672 const sp<V1_5::IWifiNanIfaceEventCallback>& callback,
673 registerEventCallback_1_5_cb hidl_status_cb) {
674 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
675 &WifiNanIface::registerEventCallback_1_5Internal, hidl_status_cb,
676 callback);
677}
678
679Return<void> WifiNanIface::enableRequest_1_5(uint16_t cmd_id, const V1_4::NanEnableRequest& msg1,
680 const V1_5::NanConfigRequestSupplemental& msg2,
681 enableRequest_1_5_cb hidl_status_cb) {
682 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
683 &WifiNanIface::enableRequest_1_5Internal, hidl_status_cb, cmd_id, msg1,
684 msg2);
685}
686
687Return<void> WifiNanIface::configRequest_1_5(uint16_t cmd_id, const V1_4::NanConfigRequest& msg1,
688 const V1_5::NanConfigRequestSupplemental& msg2,
689 configRequest_1_5_cb hidl_status_cb) {
690 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
691 &WifiNanIface::configRequest_1_5Internal, hidl_status_cb, cmd_id, msg1,
692 msg2);
693}
694
695Return<void> WifiNanIface::getCapabilitiesRequest_1_5(
696 uint16_t cmd_id, getCapabilitiesRequest_1_5_cb hidl_status_cb) {
697 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
698 &WifiNanIface::getCapabilitiesRequest_1_5Internal, hidl_status_cb,
699 cmd_id);
700}
701
702std::pair<WifiStatus, std::string> WifiNanIface::getNameInternal() {
703 return {createWifiStatus(WifiStatusCode::SUCCESS), ifname_};
704}
705
706std::pair<WifiStatus, IfaceType> WifiNanIface::getTypeInternal() {
707 return {createWifiStatus(WifiStatusCode::SUCCESS), IfaceType::NAN};
708}
709
Ahmed ElArabawy05571e42022-01-19 11:54:11 -0800710Return<void> WifiNanIface::registerEventCallback_1_6(
711 const sp<V1_6::IWifiNanIfaceEventCallback>& callback,
712 registerEventCallback_1_6_cb hidl_status_cb) {
713 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
714 &WifiNanIface::registerEventCallback_1_6Internal, hidl_status_cb,
715 callback);
716}
717
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800718WifiStatus WifiNanIface::registerEventCallbackInternal(
719 const sp<V1_0::IWifiNanIfaceEventCallback>& callback) {
720 if (!event_cb_handler_.addCallback(callback)) {
721 return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN);
722 }
723 return createWifiStatus(WifiStatusCode::SUCCESS);
724}
725
726WifiStatus WifiNanIface::getCapabilitiesRequestInternal(uint16_t /* cmd_id */) {
727 return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED);
728}
729
730WifiStatus WifiNanIface::enableRequestInternal(uint16_t /* cmd_id */,
731 const V1_0::NanEnableRequest& /* msg */) {
732 return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED);
733}
734
735WifiStatus WifiNanIface::configRequestInternal(uint16_t /* cmd_id */,
736 const V1_0::NanConfigRequest& /* msg */) {
737 return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED);
738}
739
740WifiStatus WifiNanIface::disableRequestInternal(uint16_t cmd_id) {
741 legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->nanDisableRequest(ifname_, cmd_id);
742 return createWifiStatusFromLegacyError(legacy_status);
743}
744
745WifiStatus WifiNanIface::startPublishRequestInternal(uint16_t cmd_id,
746 const NanPublishRequest& msg) {
747 legacy_hal::NanPublishRequest legacy_msg;
748 if (!hidl_struct_util::convertHidlNanPublishRequestToLegacy(msg, &legacy_msg)) {
749 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
750 }
751 legacy_hal::wifi_error legacy_status =
752 legacy_hal_.lock()->nanPublishRequest(ifname_, cmd_id, legacy_msg);
753 return createWifiStatusFromLegacyError(legacy_status);
754}
755
756WifiStatus WifiNanIface::stopPublishRequestInternal(uint16_t cmd_id, uint8_t sessionId) {
757 legacy_hal::NanPublishCancelRequest legacy_msg;
758 legacy_msg.publish_id = sessionId;
759 legacy_hal::wifi_error legacy_status =
760 legacy_hal_.lock()->nanPublishCancelRequest(ifname_, cmd_id, legacy_msg);
761 return createWifiStatusFromLegacyError(legacy_status);
762}
763
764WifiStatus WifiNanIface::startSubscribeRequestInternal(uint16_t cmd_id,
765 const NanSubscribeRequest& msg) {
766 legacy_hal::NanSubscribeRequest legacy_msg;
767 if (!hidl_struct_util::convertHidlNanSubscribeRequestToLegacy(msg, &legacy_msg)) {
768 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
769 }
770 legacy_hal::wifi_error legacy_status =
771 legacy_hal_.lock()->nanSubscribeRequest(ifname_, cmd_id, legacy_msg);
772 return createWifiStatusFromLegacyError(legacy_status);
773}
774
775WifiStatus WifiNanIface::stopSubscribeRequestInternal(uint16_t cmd_id, uint8_t sessionId) {
776 legacy_hal::NanSubscribeCancelRequest legacy_msg;
777 legacy_msg.subscribe_id = sessionId;
778 legacy_hal::wifi_error legacy_status =
779 legacy_hal_.lock()->nanSubscribeCancelRequest(ifname_, cmd_id, legacy_msg);
780 return createWifiStatusFromLegacyError(legacy_status);
781}
782
783WifiStatus WifiNanIface::transmitFollowupRequestInternal(uint16_t cmd_id,
784 const NanTransmitFollowupRequest& msg) {
785 legacy_hal::NanTransmitFollowupRequest legacy_msg;
786 if (!hidl_struct_util::convertHidlNanTransmitFollowupRequestToLegacy(msg, &legacy_msg)) {
787 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
788 }
789 legacy_hal::wifi_error legacy_status =
790 legacy_hal_.lock()->nanTransmitFollowupRequest(ifname_, cmd_id, legacy_msg);
791 return createWifiStatusFromLegacyError(legacy_status);
792}
793
794WifiStatus WifiNanIface::createDataInterfaceRequestInternal(uint16_t cmd_id,
795 const std::string& iface_name) {
796 legacy_hal::wifi_error legacy_status =
797 legacy_hal_.lock()->nanDataInterfaceCreate(ifname_, cmd_id, iface_name);
798 return createWifiStatusFromLegacyError(legacy_status);
799}
800WifiStatus WifiNanIface::deleteDataInterfaceRequestInternal(uint16_t cmd_id,
801 const std::string& iface_name) {
802 legacy_hal::wifi_error legacy_status =
803 legacy_hal_.lock()->nanDataInterfaceDelete(ifname_, cmd_id, iface_name);
804 return createWifiStatusFromLegacyError(legacy_status);
805}
806WifiStatus WifiNanIface::initiateDataPathRequestInternal(uint16_t cmd_id,
807 const NanInitiateDataPathRequest& msg) {
808 legacy_hal::NanDataPathInitiatorRequest legacy_msg;
809 if (!hidl_struct_util::convertHidlNanDataPathInitiatorRequestToLegacy(msg, &legacy_msg)) {
810 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
811 }
812 legacy_hal::wifi_error legacy_status =
813 legacy_hal_.lock()->nanDataRequestInitiator(ifname_, cmd_id, legacy_msg);
814 return createWifiStatusFromLegacyError(legacy_status);
815}
816WifiStatus WifiNanIface::respondToDataPathIndicationRequestInternal(
817 uint16_t cmd_id, const NanRespondToDataPathIndicationRequest& msg) {
818 legacy_hal::NanDataPathIndicationResponse legacy_msg;
819 if (!hidl_struct_util::convertHidlNanDataPathIndicationResponseToLegacy(msg, &legacy_msg)) {
820 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
821 }
822 legacy_hal::wifi_error legacy_status =
823 legacy_hal_.lock()->nanDataIndicationResponse(ifname_, cmd_id, legacy_msg);
824 return createWifiStatusFromLegacyError(legacy_status);
825}
826WifiStatus WifiNanIface::terminateDataPathRequestInternal(uint16_t cmd_id, uint32_t ndpInstanceId) {
827 legacy_hal::wifi_error legacy_status =
828 legacy_hal_.lock()->nanDataEnd(ifname_, cmd_id, ndpInstanceId);
829 return createWifiStatusFromLegacyError(legacy_status);
830}
831
832WifiStatus WifiNanIface::registerEventCallback_1_2Internal(
833 const sp<V1_2::IWifiNanIfaceEventCallback>& callback) {
834 sp<V1_0::IWifiNanIfaceEventCallback> callback_1_0 = callback;
835 if (!event_cb_handler_.addCallback(callback_1_0)) {
836 return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN);
837 }
838 if (!event_cb_handler_1_2_.addCallback(callback)) {
839 return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN);
840 }
841 return createWifiStatus(WifiStatusCode::SUCCESS);
842}
843
844WifiStatus WifiNanIface::enableRequest_1_2Internal(
845 uint16_t /* cmd_id */, const V1_0::NanEnableRequest& /* msg1 */,
846 const V1_2::NanConfigRequestSupplemental& /* msg2 */) {
847 return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED);
848}
849
850WifiStatus WifiNanIface::configRequest_1_2Internal(
851 uint16_t /* cmd_id */, const V1_0::NanConfigRequest& /* msg1 */,
852 const V1_2::NanConfigRequestSupplemental& /* msg2 */) {
853 return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED);
854}
855
856WifiStatus WifiNanIface::enableRequest_1_4Internal(
857 uint16_t /* cmd_id */, const V1_4::NanEnableRequest& /* msg1 */,
858 const V1_2::NanConfigRequestSupplemental& /* msg2 */) {
859 return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED);
860}
861
862WifiStatus WifiNanIface::configRequest_1_4Internal(
863 uint16_t /* cmd_id */, const V1_4::NanConfigRequest& /* msg1 */,
864 const V1_2::NanConfigRequestSupplemental& /* msg2 */) {
865 return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED);
866}
867
868WifiStatus WifiNanIface::registerEventCallback_1_5Internal(
869 const sp<V1_5::IWifiNanIfaceEventCallback>& callback) {
870 sp<V1_0::IWifiNanIfaceEventCallback> callback_1_0 = callback;
871 if (!event_cb_handler_.addCallback(callback_1_0)) {
872 return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN);
873 }
874 sp<V1_2::IWifiNanIfaceEventCallback> callback_1_2 = callback;
875 if (!event_cb_handler_1_2_.addCallback(callback_1_2)) {
876 return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN);
877 }
878 if (!event_cb_handler_1_5_.addCallback(callback)) {
879 return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN);
880 }
881 return createWifiStatus(WifiStatusCode::SUCCESS);
882}
883
884WifiStatus WifiNanIface::getCapabilitiesRequest_1_5Internal(uint16_t cmd_id) {
885 legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->nanGetCapabilities(ifname_, cmd_id);
886 return createWifiStatusFromLegacyError(legacy_status);
887}
888
889WifiStatus WifiNanIface::enableRequest_1_5Internal(uint16_t cmd_id,
890 const V1_4::NanEnableRequest& msg1,
891 const V1_5::NanConfigRequestSupplemental& msg2) {
892 legacy_hal::NanEnableRequest legacy_msg;
893 if (!hidl_struct_util::convertHidlNanEnableRequest_1_5ToLegacy(msg1, msg2, &legacy_msg)) {
894 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
895 }
896 legacy_hal::wifi_error legacy_status =
897 legacy_hal_.lock()->nanEnableRequest(ifname_, cmd_id, legacy_msg);
898 return createWifiStatusFromLegacyError(legacy_status);
899}
900
901WifiStatus WifiNanIface::configRequest_1_5Internal(uint16_t cmd_id,
902 const V1_4::NanConfigRequest& msg1,
903 const V1_5::NanConfigRequestSupplemental& msg2) {
904 legacy_hal::NanConfigRequest legacy_msg;
905 if (!hidl_struct_util::convertHidlNanConfigRequest_1_5ToLegacy(msg1, msg2, &legacy_msg)) {
906 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
907 }
908 legacy_hal::wifi_error legacy_status =
909 legacy_hal_.lock()->nanConfigRequest(ifname_, cmd_id, legacy_msg);
910 return createWifiStatusFromLegacyError(legacy_status);
911}
912
Ahmed ElArabawy05571e42022-01-19 11:54:11 -0800913WifiStatus WifiNanIface::registerEventCallback_1_6Internal(
914 const sp<V1_6::IWifiNanIfaceEventCallback>& callback) {
915 sp<V1_0::IWifiNanIfaceEventCallback> callback_1_0 = callback;
916 if (!event_cb_handler_.addCallback(callback_1_0)) {
917 return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN);
918 }
919 sp<V1_2::IWifiNanIfaceEventCallback> callback_1_2 = callback;
920 if (!event_cb_handler_1_2_.addCallback(callback_1_2)) {
921 return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN);
922 }
923 sp<V1_5::IWifiNanIfaceEventCallback> callback_1_5 = callback;
924 if (!event_cb_handler_1_5_.addCallback(callback_1_5)) {
925 return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN);
926 }
927 if (!event_cb_handler_1_6_.addCallback(callback)) {
928 return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN);
929 }
930 return createWifiStatus(WifiStatusCode::SUCCESS);
931}
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800932} // namespace implementation
933} // namespace V1_6
934} // namespace wifi
935} // namespace hardware
936} // namespace android