1 /*
2 * Copyright (C) 2022 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_nan_iface.h"
18
19 #include <android-base/logging.h>
20
21 #include "aidl_return_util.h"
22 #include "aidl_struct_util.h"
23 #include "wifi_status_util.h"
24
25 namespace aidl {
26 namespace android {
27 namespace hardware {
28 namespace wifi {
29 using aidl_return_util::validateAndCall;
30
WifiNanIface(const std::string & ifname,bool is_dedicated_iface,const std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal,const std::weak_ptr<iface_util::WifiIfaceUtil> iface_util)31 WifiNanIface::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
create(const std::string & ifname,bool is_dedicated_iface,const std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal,const std::weak_ptr<iface_util::WifiIfaceUtil> iface_util)40 std::shared_ptr<WifiNanIface> WifiNanIface::create(
41 const std::string& ifname, bool is_dedicated_iface,
42 const std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal,
43 const std::weak_ptr<iface_util::WifiIfaceUtil> iface_util) {
44 std::shared_ptr<WifiNanIface> ptr = ndk::SharedRefBase::make<WifiNanIface>(
45 ifname, is_dedicated_iface, legacy_hal, iface_util);
46 if (is_dedicated_iface) {
47 // If using a dedicated iface, set the iface up first.
48 if (!iface_util.lock()->setUpState(ifname, true)) {
49 // Fatal failure, invalidate the iface object.
50 ptr->invalidate();
51 return nullptr;
52 }
53 }
54 std::weak_ptr<WifiNanIface> weak_ptr_this(ptr);
55 ptr->setWeakPtr(weak_ptr_this);
56 ptr->registerCallbackHandlers();
57 return ptr;
58 }
59
registerCallbackHandlers()60 void WifiNanIface::registerCallbackHandlers() {
61 // Register all the callbacks here. These should be valid for the lifetime
62 // of the object. Whenever the mode changes legacy HAL will remove
63 // all of these callbacks.
64 legacy_hal::NanCallbackHandlers callback_handlers;
65 std::weak_ptr<WifiNanIface> weak_ptr_this = weak_ptr_this_;
66
67 // Callback for response.
68 callback_handlers.on_notify_response = [weak_ptr_this](legacy_hal::transaction_id id,
69 const legacy_hal::NanResponseMsg& msg) {
70 const auto shared_ptr_this = weak_ptr_this.lock();
71 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
72 LOG(ERROR) << "Callback invoked on an invalid object";
73 return;
74 }
75 NanStatus nanStatus;
76 if (!aidl_struct_util::convertLegacyNanResponseHeaderToAidl(msg, &nanStatus)) {
77 LOG(ERROR) << "Failed to convert nan response header";
78 return;
79 }
80
81 switch (msg.response_type) {
82 case legacy_hal::NAN_RESPONSE_ENABLED: {
83 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
84 if (!callback->notifyEnableResponse(id, nanStatus).isOk()) {
85 LOG(ERROR) << "Failed to invoke the callback";
86 }
87 }
88 break;
89 }
90 case legacy_hal::NAN_RESPONSE_DISABLED: {
91 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
92 if (!callback->notifyDisableResponse(id, nanStatus).isOk()) {
93 LOG(ERROR) << "Failed to invoke the callback";
94 }
95 }
96 break;
97 }
98 case legacy_hal::NAN_RESPONSE_PUBLISH: {
99 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
100 if (!callback->notifyStartPublishResponse(id, nanStatus,
101 msg.body.publish_response.publish_id)
102 .isOk()) {
103 LOG(ERROR) << "Failed to invoke the callback";
104 }
105 }
106 break;
107 }
108 case legacy_hal::NAN_RESPONSE_PUBLISH_CANCEL: {
109 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
110 if (!callback->notifyStopPublishResponse(id, nanStatus).isOk()) {
111 LOG(ERROR) << "Failed to invoke the callback";
112 }
113 }
114 break;
115 }
116 case legacy_hal::NAN_RESPONSE_TRANSMIT_FOLLOWUP: {
117 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
118 if (!callback->notifyTransmitFollowupResponse(id, nanStatus).isOk()) {
119 LOG(ERROR) << "Failed to invoke the callback";
120 }
121 }
122 break;
123 }
124 case legacy_hal::NAN_RESPONSE_SUBSCRIBE: {
125 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
126 if (!callback->notifyStartSubscribeResponse(
127 id, nanStatus, msg.body.subscribe_response.subscribe_id)
128 .isOk()) {
129 LOG(ERROR) << "Failed to invoke the callback";
130 }
131 }
132 break;
133 }
134 case legacy_hal::NAN_RESPONSE_SUBSCRIBE_CANCEL: {
135 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
136 if (!callback->notifyStopSubscribeResponse(id, nanStatus).isOk()) {
137 LOG(ERROR) << "Failed to invoke the callback";
138 }
139 }
140 break;
141 }
142 case legacy_hal::NAN_RESPONSE_CONFIG: {
143 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
144 if (!callback->notifyConfigResponse(id, nanStatus).isOk()) {
145 LOG(ERROR) << "Failed to invoke the callback";
146 }
147 }
148 break;
149 }
150 case legacy_hal::NAN_GET_CAPABILITIES: {
151 NanCapabilities aidl_struct;
152 if (!aidl_struct_util::convertLegacyNanCapabilitiesResponseToAidl(
153 msg.body.nan_capabilities, &aidl_struct)) {
154 LOG(ERROR) << "Failed to convert nan capabilities response";
155 return;
156 }
157 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
158 if (!callback->notifyCapabilitiesResponse(id, nanStatus, aidl_struct).isOk()) {
159 LOG(ERROR) << "Failed to invoke the callback";
160 }
161 }
162 break;
163 }
164 case legacy_hal::NAN_DP_INTERFACE_CREATE: {
165 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
166 if (!callback->notifyCreateDataInterfaceResponse(id, nanStatus).isOk()) {
167 LOG(ERROR) << "Failed to invoke the callback";
168 }
169 }
170 break;
171 }
172 case legacy_hal::NAN_DP_INTERFACE_DELETE: {
173 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
174 if (!callback->notifyDeleteDataInterfaceResponse(id, nanStatus).isOk()) {
175 LOG(ERROR) << "Failed to invoke the callback";
176 }
177 }
178 break;
179 }
180 case legacy_hal::NAN_DP_INITIATOR_RESPONSE: {
181 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
182 if (!callback->notifyInitiateDataPathResponse(
183 id, nanStatus,
184 msg.body.data_request_response.ndp_instance_id)
185 .isOk()) {
186 LOG(ERROR) << "Failed to invoke the callback";
187 }
188 }
189 break;
190 }
191 case legacy_hal::NAN_DP_RESPONDER_RESPONSE: {
192 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
193 if (!callback->notifyRespondToDataPathIndicationResponse(id, nanStatus)
194 .isOk()) {
195 LOG(ERROR) << "Failed to invoke the callback";
196 }
197 }
198 break;
199 }
200 case legacy_hal::NAN_DP_END: {
201 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
202 if (!callback->notifyTerminateDataPathResponse(id, nanStatus).isOk()) {
203 LOG(ERROR) << "Failed to invoke the callback";
204 }
205 }
206 break;
207 }
208 case legacy_hal::NAN_PAIRING_INITIATOR_RESPONSE: {
209 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
210 if (!callback->notifyInitiatePairingResponse(
211 id, nanStatus,
212 msg.body.pairing_request_response.paring_instance_id)
213 .isOk()) {
214 LOG(ERROR) << "Failed to invoke the callback";
215 }
216 }
217 break;
218 }
219 case legacy_hal::NAN_PAIRING_RESPONDER_RESPONSE: {
220 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
221 if (!callback->notifyRespondToPairingIndicationResponse(id, nanStatus).isOk()) {
222 LOG(ERROR) << "Failed to invoke the callback";
223 }
224 }
225 break;
226 }
227 case legacy_hal::NAN_PAIRING_END: {
228 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
229 if (!callback->notifyTerminatePairingResponse(id, nanStatus).isOk()) {
230 LOG(ERROR) << "Failed to invoke the callback";
231 }
232 }
233 break;
234 }
235 case legacy_hal::NAN_BOOTSTRAPPING_INITIATOR_RESPONSE: {
236 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
237 if (!callback->notifyInitiateBootstrappingResponse(
238 id, nanStatus,
239 msg.body.bootstrapping_request_response
240 .bootstrapping_instance_id)
241 .isOk()) {
242 LOG(ERROR) << "Failed to invoke the callback";
243 }
244 }
245 break;
246 }
247 case legacy_hal::NAN_BOOTSTRAPPING_RESPONDER_RESPONSE: {
248 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
249 if (!callback->notifyRespondToBootstrappingIndicationResponse(id, nanStatus)
250 .isOk()) {
251 LOG(ERROR) << "Failed to invoke the callback";
252 }
253 }
254 break;
255 }
256 case legacy_hal::NAN_SUSPEND_REQUEST_RESPONSE: {
257 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
258 if (!callback->notifySuspendResponse(id, nanStatus).isOk()) {
259 LOG(ERROR) << "Failed to invoke the callback";
260 }
261 }
262 break;
263 }
264 case legacy_hal::NAN_RESUME_REQUEST_RESPONSE: {
265 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
266 if (!callback->notifyResumeResponse(id, nanStatus).isOk()) {
267 LOG(ERROR) << "Failed to invoke the callback";
268 }
269 }
270 break;
271 }
272 case legacy_hal::NAN_RESPONSE_BEACON_SDF_PAYLOAD:
273 /* fall through */
274 case legacy_hal::NAN_RESPONSE_TCA:
275 /* fall through */
276 case legacy_hal::NAN_RESPONSE_STATS:
277 /* fall through */
278 case legacy_hal::NAN_RESPONSE_ERROR:
279 /* fall through */
280 default:
281 LOG(ERROR) << "Unknown or unhandled response type: " << msg.response_type;
282 return;
283 }
284 };
285
286 callback_handlers.on_event_disc_eng_event = [weak_ptr_this](
287 const legacy_hal::NanDiscEngEventInd& msg) {
288 const auto shared_ptr_this = weak_ptr_this.lock();
289 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
290 LOG(ERROR) << "Callback invoked on an invalid object";
291 return;
292 }
293 NanClusterEventInd aidl_struct;
294 // event types defined identically - hence can be cast
295 aidl_struct.eventType = (NanClusterEventType)msg.event_type;
296 aidl_struct.addr = std::array<uint8_t, 6>();
297 std::copy(msg.data.mac_addr.addr, msg.data.mac_addr.addr + 6, std::begin(aidl_struct.addr));
298
299 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
300 if (!callback->eventClusterEvent(aidl_struct).isOk()) {
301 LOG(ERROR) << "Failed to invoke the callback";
302 }
303 }
304 };
305
306 callback_handlers.on_event_disabled = [weak_ptr_this](const legacy_hal::NanDisabledInd& msg) {
307 const auto shared_ptr_this = weak_ptr_this.lock();
308 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
309 LOG(ERROR) << "Callback invoked on an invalid object";
310 return;
311 }
312 NanStatus status;
313 aidl_struct_util::convertToNanStatus(msg.reason, msg.nan_reason, sizeof(msg.nan_reason),
314 &status);
315
316 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
317 if (!callback->eventDisabled(status).isOk()) {
318 LOG(ERROR) << "Failed to invoke the callback";
319 }
320 }
321 };
322
323 callback_handlers.on_event_publish_terminated =
324 [weak_ptr_this](const legacy_hal::NanPublishTerminatedInd& msg) {
325 const auto shared_ptr_this = weak_ptr_this.lock();
326 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
327 LOG(ERROR) << "Callback invoked on an invalid object";
328 return;
329 }
330 NanStatus status;
331 aidl_struct_util::convertToNanStatus(msg.reason, msg.nan_reason,
332 sizeof(msg.nan_reason), &status);
333
334 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
335 if (!callback->eventPublishTerminated(msg.publish_id, status).isOk()) {
336 LOG(ERROR) << "Failed to invoke the callback";
337 }
338 }
339 };
340
341 callback_handlers.on_event_subscribe_terminated =
342 [weak_ptr_this](const legacy_hal::NanSubscribeTerminatedInd& msg) {
343 const auto shared_ptr_this = weak_ptr_this.lock();
344 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
345 LOG(ERROR) << "Callback invoked on an invalid object";
346 return;
347 }
348 NanStatus status;
349 aidl_struct_util::convertToNanStatus(msg.reason, msg.nan_reason,
350 sizeof(msg.nan_reason), &status);
351
352 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
353 if (!callback->eventSubscribeTerminated(msg.subscribe_id, status).isOk()) {
354 LOG(ERROR) << "Failed to invoke the callback";
355 }
356 }
357 };
358
359 callback_handlers.on_event_match = [weak_ptr_this](const legacy_hal::NanMatchInd& msg) {
360 const auto shared_ptr_this = weak_ptr_this.lock();
361 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
362 LOG(ERROR) << "Callback invoked on an invalid object";
363 return;
364 }
365 NanMatchInd aidl_struct;
366 if (!aidl_struct_util::convertLegacyNanMatchIndToAidl(msg, &aidl_struct)) {
367 LOG(ERROR) << "Failed to convert nan capabilities response";
368 return;
369 }
370
371 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
372 if (!callback->eventMatch(aidl_struct).isOk()) {
373 LOG(ERROR) << "Failed to invoke the callback";
374 }
375 }
376 };
377
378 callback_handlers.on_event_match_expired = [weak_ptr_this](
379 const legacy_hal::NanMatchExpiredInd& msg) {
380 const auto shared_ptr_this = weak_ptr_this.lock();
381 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
382 LOG(ERROR) << "Callback invoked on an invalid object";
383 return;
384 }
385 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
386 if (!callback->eventMatchExpired(msg.publish_subscribe_id, msg.requestor_instance_id)
387 .isOk()) {
388 LOG(ERROR) << "Failed to invoke the callback";
389 }
390 }
391 };
392
393 callback_handlers.on_event_followup = [weak_ptr_this](const legacy_hal::NanFollowupInd& msg) {
394 const auto shared_ptr_this = weak_ptr_this.lock();
395 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
396 LOG(ERROR) << "Callback invoked on an invalid object";
397 return;
398 }
399 NanFollowupReceivedInd aidl_struct;
400 if (!aidl_struct_util::convertLegacyNanFollowupIndToAidl(msg, &aidl_struct)) {
401 LOG(ERROR) << "Failed to convert nan capabilities response";
402 return;
403 }
404
405 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
406 if (!callback->eventFollowupReceived(aidl_struct).isOk()) {
407 LOG(ERROR) << "Failed to invoke the callback";
408 }
409 }
410 };
411
412 callback_handlers.on_event_transmit_follow_up =
413 [weak_ptr_this](const legacy_hal::NanTransmitFollowupInd& msg) {
414 const auto shared_ptr_this = weak_ptr_this.lock();
415 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
416 LOG(ERROR) << "Callback invoked on an invalid object";
417 return;
418 }
419 NanStatus status;
420 aidl_struct_util::convertToNanStatus(msg.reason, msg.nan_reason,
421 sizeof(msg.nan_reason), &status);
422
423 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
424 if (!callback->eventTransmitFollowup(msg.id, status).isOk()) {
425 LOG(ERROR) << "Failed to invoke the callback";
426 }
427 }
428 };
429
430 callback_handlers.on_event_data_path_request =
431 [weak_ptr_this](const legacy_hal::NanDataPathRequestInd& msg) {
432 const auto shared_ptr_this = weak_ptr_this.lock();
433 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
434 LOG(ERROR) << "Callback invoked on an invalid object";
435 return;
436 }
437 NanDataPathRequestInd aidl_struct;
438 if (!aidl_struct_util::convertLegacyNanDataPathRequestIndToAidl(msg,
439 &aidl_struct)) {
440 LOG(ERROR) << "Failed to convert nan capabilities response";
441 return;
442 }
443
444 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
445 if (!callback->eventDataPathRequest(aidl_struct).isOk()) {
446 LOG(ERROR) << "Failed to invoke the callback";
447 }
448 }
449 };
450
451 callback_handlers.on_event_data_path_confirm =
452 [weak_ptr_this](const legacy_hal::NanDataPathConfirmInd& msg) {
453 const auto shared_ptr_this = weak_ptr_this.lock();
454 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
455 LOG(ERROR) << "Callback invoked on an invalid object";
456 return;
457 }
458 NanDataPathConfirmInd aidl_struct;
459 if (!aidl_struct_util::convertLegacyNanDataPathConfirmIndToAidl(msg,
460 &aidl_struct)) {
461 LOG(ERROR) << "Failed to convert nan capabilities response";
462 return;
463 }
464
465 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
466 if (!callback->eventDataPathConfirm(aidl_struct).isOk()) {
467 LOG(ERROR) << "Failed to invoke the callback";
468 }
469 }
470 };
471
472 callback_handlers.on_event_data_path_end =
473 [weak_ptr_this](const legacy_hal::NanDataPathEndInd& msg) {
474 const auto shared_ptr_this = weak_ptr_this.lock();
475 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
476 LOG(ERROR) << "Callback invoked on an invalid object";
477 return;
478 }
479 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
480 for (int i = 0; i < msg.num_ndp_instances; ++i) {
481 if (!callback->eventDataPathTerminated(msg.ndp_instance_id[i]).isOk()) {
482 LOG(ERROR) << "Failed to invoke the callback";
483 }
484 }
485 }
486 };
487
488 callback_handlers.on_event_pairing_request =
489 [weak_ptr_this](const legacy_hal::NanPairingRequestInd& msg) {
490 const auto shared_ptr_this = weak_ptr_this.lock();
491 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
492 LOG(ERROR) << "Callback invoked on an invalid object";
493 return;
494 }
495 NanPairingRequestInd aidl_struct;
496 if (!aidl_struct_util::convertLegacyNanPairingRequestIndToAidl(msg, &aidl_struct)) {
497 LOG(ERROR) << "Failed to convert nan capabilities response";
498 return;
499 }
500
501 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
502 if (!callback->eventPairingRequest(aidl_struct).isOk()) {
503 LOG(ERROR) << "Failed to invoke the callback";
504 }
505 }
506 };
507 callback_handlers.on_event_pairing_confirm =
508 [weak_ptr_this](const legacy_hal::NanPairingConfirmInd& msg) {
509 const auto shared_ptr_this = weak_ptr_this.lock();
510 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
511 LOG(ERROR) << "Callback invoked on an invalid object";
512 return;
513 }
514 NanPairingConfirmInd aidl_struct;
515 if (!aidl_struct_util::convertLegacyNanPairingConfirmIndToAidl(msg, &aidl_struct)) {
516 LOG(ERROR) << "Failed to convert nan capabilities response";
517 return;
518 }
519
520 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
521 if (!callback->eventPairingConfirm(aidl_struct).isOk()) {
522 LOG(ERROR) << "Failed to invoke the callback";
523 }
524 }
525 };
526 callback_handlers.on_event_bootstrapping_request =
527 [weak_ptr_this](const legacy_hal::NanBootstrappingRequestInd& msg) {
528 const auto shared_ptr_this = weak_ptr_this.lock();
529 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
530 LOG(ERROR) << "Callback invoked on an invalid object";
531 return;
532 }
533 NanBootstrappingRequestInd aidl_struct;
534 if (!aidl_struct_util::convertLegacyNanBootstrappingRequestIndToAidl(
535 msg, &aidl_struct)) {
536 LOG(ERROR) << "Failed to convert nan capabilities response";
537 return;
538 }
539
540 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
541 if (!callback->eventBootstrappingRequest(aidl_struct).isOk()) {
542 LOG(ERROR) << "Failed to invoke the callback";
543 }
544 }
545 };
546 callback_handlers.on_event_bootstrapping_confirm =
547 [weak_ptr_this](const legacy_hal::NanBootstrappingConfirmInd& msg) {
548 const auto shared_ptr_this = weak_ptr_this.lock();
549 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
550 LOG(ERROR) << "Callback invoked on an invalid object";
551 return;
552 }
553 NanBootstrappingConfirmInd aidl_struct;
554 if (!aidl_struct_util::convertLegacyNanBootstrappingConfirmIndToAidl(
555 msg, &aidl_struct)) {
556 LOG(ERROR) << "Failed to convert nan capabilities response";
557 return;
558 }
559
560 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
561 if (!callback->eventBootstrappingConfirm(aidl_struct).isOk()) {
562 LOG(ERROR) << "Failed to invoke the callback";
563 }
564 }
565 };
566
567 callback_handlers.on_event_beacon_sdf_payload =
568 [](const legacy_hal::NanBeaconSdfPayloadInd& /* msg */) {
569 LOG(ERROR) << "on_event_beacon_sdf_payload - should not be called";
570 };
571
572 callback_handlers.on_event_range_request = [](const legacy_hal::NanRangeRequestInd& /* msg */) {
573 LOG(ERROR) << "on_event_range_request - should not be called";
574 };
575
576 callback_handlers.on_event_range_report = [](const legacy_hal::NanRangeReportInd& /* msg */) {
577 LOG(ERROR) << "on_event_range_report - should not be called";
578 };
579
580 callback_handlers.on_event_schedule_update =
581 [weak_ptr_this](const legacy_hal::NanDataPathScheduleUpdateInd& msg) {
582 const auto shared_ptr_this = weak_ptr_this.lock();
583 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
584 LOG(ERROR) << "Callback invoked on an invalid object";
585 return;
586 }
587 NanDataPathScheduleUpdateInd aidl_struct;
588 if (!aidl_struct_util::convertLegacyNanDataPathScheduleUpdateIndToAidl(
589 msg, &aidl_struct)) {
590 LOG(ERROR) << "Failed to convert nan capabilities response";
591 return;
592 }
593
594 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
595 if (!callback->eventDataPathScheduleUpdate(aidl_struct).isOk()) {
596 LOG(ERROR) << "Failed to invoke the callback";
597 }
598 }
599 };
600 callback_handlers.on_event_suspension_mode_change =
601 [weak_ptr_this](const legacy_hal::NanSuspensionModeChangeInd& msg) {
602 const auto shared_ptr_this = weak_ptr_this.lock();
603 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
604 LOG(ERROR) << "Callback invoked on an invalid object";
605 return;
606 }
607 NanSuspensionModeChangeInd aidl_struct;
608 aidl_struct.isSuspended = msg.is_suspended;
609
610 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
611 if (!callback->eventSuspensionModeChanged(aidl_struct).isOk()) {
612 LOG(ERROR) << "Failed to invoke the callback";
613 }
614 }
615 };
616
617 legacy_hal::wifi_error legacy_status =
618 legacy_hal_.lock()->nanRegisterCallbackHandlers(ifname_, callback_handlers);
619 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
620 LOG(ERROR) << "Failed to register nan callbacks. Invalidating object";
621 invalidate();
622 }
623
624 // Register for iface state toggle events.
625 iface_util::IfaceEventHandlers event_handlers = {};
626 #ifndef WIFI_SKIP_STATE_TOGGLE_OFF_ON_FOR_NAN
627 event_handlers.on_state_toggle_off_on = [weak_ptr_this](const std::string& /* iface_name */) {
628 const auto shared_ptr_this = weak_ptr_this.lock();
629 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
630 LOG(ERROR) << "Callback invoked on an invalid object";
631 return;
632 }
633 // Tell framework that NAN has been disabled.
634 NanStatus status = {NanStatusCode::UNSUPPORTED_CONCURRENCY_NAN_DISABLED, ""};
635 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
636 if (!callback->eventDisabled(status).isOk()) {
637 LOG(ERROR) << "Failed to invoke the callback";
638 }
639 }
640 };
641 #endif
642 iface_util_.lock()->registerIfaceEventHandlers(ifname_, event_handlers);
643 }
644
setWeakPtr(std::weak_ptr<WifiNanIface> ptr)645 void WifiNanIface::setWeakPtr(std::weak_ptr<WifiNanIface> ptr) {
646 weak_ptr_this_ = ptr;
647 }
648
invalidate()649 void WifiNanIface::invalidate() {
650 if (!isValid()) {
651 return;
652 }
653 // send commands to HAL to actually disable and destroy interfaces
654 legacy_hal_.lock()->nanDisableRequest(ifname_, 0xFFFF);
655 legacy_hal_.lock()->nanDataInterfaceDelete(ifname_, 0xFFFE, "aware_data0");
656 legacy_hal_.lock()->nanDataInterfaceDelete(ifname_, 0xFFFD, "aware_data1");
657 iface_util_.lock()->unregisterIfaceEventHandlers(ifname_);
658 legacy_hal_.reset();
659 event_cb_handler_.invalidate();
660 is_valid_ = false;
661 if (is_dedicated_iface_) {
662 // If using a dedicated iface, set the iface down.
663 iface_util_.lock()->setUpState(ifname_, false);
664 }
665 }
666
isValid()667 bool WifiNanIface::isValid() {
668 return is_valid_;
669 }
670
getName()671 std::string WifiNanIface::getName() {
672 return ifname_;
673 }
674
getEventCallbacks()675 std::set<std::shared_ptr<IWifiNanIfaceEventCallback>> WifiNanIface::getEventCallbacks() {
676 LOG(ERROR) << "Using original getEventCallbacks";
677 return event_cb_handler_.getCallbacks();
678 }
679
getName(std::string * _aidl_return)680 ndk::ScopedAStatus WifiNanIface::getName(std::string* _aidl_return) {
681 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
682 &WifiNanIface::getNameInternal, _aidl_return);
683 }
684
registerEventCallback(const std::shared_ptr<IWifiNanIfaceEventCallback> & callback)685 ndk::ScopedAStatus WifiNanIface::registerEventCallback(
686 const std::shared_ptr<IWifiNanIfaceEventCallback>& callback) {
687 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
688 &WifiNanIface::registerEventCallbackInternal, callback);
689 }
690
getCapabilitiesRequest(char16_t in_cmdId)691 ndk::ScopedAStatus WifiNanIface::getCapabilitiesRequest(char16_t in_cmdId) {
692 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
693 &WifiNanIface::getCapabilitiesRequestInternal, in_cmdId);
694 }
695
enableRequest(char16_t in_cmdId,const NanEnableRequest & in_msg1,const NanConfigRequestSupplemental & in_msg2)696 ndk::ScopedAStatus WifiNanIface::enableRequest(char16_t in_cmdId, const NanEnableRequest& in_msg1,
697 const NanConfigRequestSupplemental& in_msg2) {
698 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
699 &WifiNanIface::enableRequestInternal, in_cmdId, in_msg1, in_msg2);
700 }
701
configRequest(char16_t in_cmdId,const NanConfigRequest & in_msg1,const NanConfigRequestSupplemental & in_msg2)702 ndk::ScopedAStatus WifiNanIface::configRequest(char16_t in_cmdId, const NanConfigRequest& in_msg1,
703 const NanConfigRequestSupplemental& in_msg2) {
704 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
705 &WifiNanIface::configRequestInternal, in_cmdId, in_msg1, in_msg2);
706 }
707
disableRequest(char16_t in_cmdId)708 ndk::ScopedAStatus WifiNanIface::disableRequest(char16_t in_cmdId) {
709 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
710 &WifiNanIface::disableRequestInternal, in_cmdId);
711 }
712
startPublishRequest(char16_t in_cmdId,const NanPublishRequest & in_msg)713 ndk::ScopedAStatus WifiNanIface::startPublishRequest(char16_t in_cmdId,
714 const NanPublishRequest& in_msg) {
715 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
716 &WifiNanIface::startPublishRequestInternal, in_cmdId, in_msg);
717 }
718
stopPublishRequest(char16_t in_cmdId,int8_t in_sessionId)719 ndk::ScopedAStatus WifiNanIface::stopPublishRequest(char16_t in_cmdId, int8_t in_sessionId) {
720 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
721 &WifiNanIface::stopPublishRequestInternal, in_cmdId, in_sessionId);
722 }
723
startSubscribeRequest(char16_t in_cmdId,const NanSubscribeRequest & in_msg)724 ndk::ScopedAStatus WifiNanIface::startSubscribeRequest(char16_t in_cmdId,
725 const NanSubscribeRequest& in_msg) {
726 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
727 &WifiNanIface::startSubscribeRequestInternal, in_cmdId, in_msg);
728 }
729
stopSubscribeRequest(char16_t in_cmdId,int8_t in_sessionId)730 ndk::ScopedAStatus WifiNanIface::stopSubscribeRequest(char16_t in_cmdId, int8_t in_sessionId) {
731 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
732 &WifiNanIface::stopSubscribeRequestInternal, in_cmdId, in_sessionId);
733 }
734
transmitFollowupRequest(char16_t in_cmdId,const NanTransmitFollowupRequest & in_msg)735 ndk::ScopedAStatus WifiNanIface::transmitFollowupRequest(char16_t in_cmdId,
736 const NanTransmitFollowupRequest& in_msg) {
737 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
738 &WifiNanIface::transmitFollowupRequestInternal, in_cmdId, in_msg);
739 }
740
createDataInterfaceRequest(char16_t in_cmdId,const std::string & in_ifaceName)741 ndk::ScopedAStatus WifiNanIface::createDataInterfaceRequest(char16_t in_cmdId,
742 const std::string& in_ifaceName) {
743 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
744 &WifiNanIface::createDataInterfaceRequestInternal, in_cmdId,
745 in_ifaceName);
746 }
747
deleteDataInterfaceRequest(char16_t in_cmdId,const std::string & in_ifaceName)748 ndk::ScopedAStatus WifiNanIface::deleteDataInterfaceRequest(char16_t in_cmdId,
749 const std::string& in_ifaceName) {
750 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
751 &WifiNanIface::deleteDataInterfaceRequestInternal, in_cmdId,
752 in_ifaceName);
753 }
754
initiateDataPathRequest(char16_t in_cmdId,const NanInitiateDataPathRequest & in_msg)755 ndk::ScopedAStatus WifiNanIface::initiateDataPathRequest(char16_t in_cmdId,
756 const NanInitiateDataPathRequest& in_msg) {
757 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
758 &WifiNanIface::initiateDataPathRequestInternal, in_cmdId, in_msg);
759 }
760
respondToDataPathIndicationRequest(char16_t in_cmdId,const NanRespondToDataPathIndicationRequest & in_msg)761 ndk::ScopedAStatus WifiNanIface::respondToDataPathIndicationRequest(
762 char16_t in_cmdId, const NanRespondToDataPathIndicationRequest& in_msg) {
763 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
764 &WifiNanIface::respondToDataPathIndicationRequestInternal, in_cmdId,
765 in_msg);
766 }
767
terminateDataPathRequest(char16_t in_cmdId,int32_t in_ndpInstanceId)768 ndk::ScopedAStatus WifiNanIface::terminateDataPathRequest(char16_t in_cmdId,
769 int32_t in_ndpInstanceId) {
770 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
771 &WifiNanIface::terminateDataPathRequestInternal, in_cmdId,
772 in_ndpInstanceId);
773 }
774
initiatePairingRequest(char16_t in_cmdId,const NanPairingRequest & in_msg)775 ndk::ScopedAStatus WifiNanIface::initiatePairingRequest(char16_t in_cmdId,
776 const NanPairingRequest& in_msg) {
777 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
778 &WifiNanIface::initiatePairingRequestInternal, in_cmdId, in_msg);
779 }
780
respondToPairingIndicationRequest(char16_t in_cmdId,const NanRespondToPairingIndicationRequest & in_msg)781 ndk::ScopedAStatus WifiNanIface::respondToPairingIndicationRequest(
782 char16_t in_cmdId, const NanRespondToPairingIndicationRequest& in_msg) {
783 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
784 &WifiNanIface::respondToPairingIndicationRequestInternal, in_cmdId,
785 in_msg);
786 }
787
terminatePairingRequest(char16_t in_cmdId,int32_t in_ndpInstanceId)788 ndk::ScopedAStatus WifiNanIface::terminatePairingRequest(char16_t in_cmdId,
789 int32_t in_ndpInstanceId) {
790 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
791 &WifiNanIface::terminatePairingRequestInternal, in_cmdId,
792 in_ndpInstanceId);
793 }
794
initiateBootstrappingRequest(char16_t in_cmdId,const NanBootstrappingRequest & in_msg)795 ndk::ScopedAStatus WifiNanIface::initiateBootstrappingRequest(
796 char16_t in_cmdId, const NanBootstrappingRequest& in_msg) {
797 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
798 &WifiNanIface::initiateBootstrappingRequestInternal, in_cmdId, in_msg);
799 }
800
respondToBootstrappingIndicationRequest(char16_t in_cmdId,const NanBootstrappingResponse & in_msg)801 ndk::ScopedAStatus WifiNanIface::respondToBootstrappingIndicationRequest(
802 char16_t in_cmdId, const NanBootstrappingResponse& in_msg) {
803 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
804 &WifiNanIface::respondToBootstrappingIndicationRequestInternal, in_cmdId,
805 in_msg);
806 }
807
suspendRequest(char16_t in_cmdId,int8_t in_sessionId)808 ndk::ScopedAStatus WifiNanIface::suspendRequest(char16_t in_cmdId, int8_t in_sessionId) {
809 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
810 &WifiNanIface::suspendRequestInternal, in_cmdId, in_sessionId);
811 }
812
resumeRequest(char16_t in_cmdId,int8_t in_sessionId)813 ndk::ScopedAStatus WifiNanIface::resumeRequest(char16_t in_cmdId, int8_t in_sessionId) {
814 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
815 &WifiNanIface::resumeRequestInternal, in_cmdId, in_sessionId);
816 }
817
getNameInternal()818 std::pair<std::string, ndk::ScopedAStatus> WifiNanIface::getNameInternal() {
819 return {ifname_, ndk::ScopedAStatus::ok()};
820 }
821
registerEventCallbackInternal(const std::shared_ptr<IWifiNanIfaceEventCallback> & callback)822 ndk::ScopedAStatus WifiNanIface::registerEventCallbackInternal(
823 const std::shared_ptr<IWifiNanIfaceEventCallback>& callback) {
824 if (!event_cb_handler_.addCallback(callback)) {
825 return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN);
826 }
827 return ndk::ScopedAStatus::ok();
828 }
829
getCapabilitiesRequestInternal(char16_t cmd_id)830 ndk::ScopedAStatus WifiNanIface::getCapabilitiesRequestInternal(char16_t cmd_id) {
831 legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->nanGetCapabilities(ifname_, cmd_id);
832 return createWifiStatusFromLegacyError(legacy_status);
833 }
834
enableRequestInternal(char16_t cmd_id,const NanEnableRequest & msg1,const NanConfigRequestSupplemental & msg2)835 ndk::ScopedAStatus WifiNanIface::enableRequestInternal(char16_t cmd_id,
836 const NanEnableRequest& msg1,
837 const NanConfigRequestSupplemental& msg2) {
838 legacy_hal::NanEnableRequest legacy_msg;
839 if (!aidl_struct_util::convertAidlNanEnableRequestToLegacy(msg1, msg2, &legacy_msg)) {
840 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
841 }
842 legacy_hal::wifi_error legacy_status =
843 legacy_hal_.lock()->nanEnableRequest(ifname_, cmd_id, legacy_msg);
844 return createWifiStatusFromLegacyError(legacy_status);
845 }
846
configRequestInternal(char16_t cmd_id,const NanConfigRequest & msg1,const NanConfigRequestSupplemental & msg2)847 ndk::ScopedAStatus WifiNanIface::configRequestInternal(char16_t cmd_id,
848 const NanConfigRequest& msg1,
849 const NanConfigRequestSupplemental& msg2) {
850 legacy_hal::NanConfigRequest legacy_msg;
851 if (!aidl_struct_util::convertAidlNanConfigRequestToLegacy(msg1, msg2, &legacy_msg)) {
852 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
853 }
854 legacy_hal::wifi_error legacy_status =
855 legacy_hal_.lock()->nanConfigRequest(ifname_, cmd_id, legacy_msg);
856 return createWifiStatusFromLegacyError(legacy_status);
857 }
858
disableRequestInternal(char16_t cmd_id)859 ndk::ScopedAStatus WifiNanIface::disableRequestInternal(char16_t cmd_id) {
860 legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->nanDisableRequest(ifname_, cmd_id);
861 return createWifiStatusFromLegacyError(legacy_status);
862 }
863
startPublishRequestInternal(char16_t cmd_id,const NanPublishRequest & msg)864 ndk::ScopedAStatus WifiNanIface::startPublishRequestInternal(char16_t cmd_id,
865 const NanPublishRequest& msg) {
866 legacy_hal::NanPublishRequest legacy_msg;
867 if (!aidl_struct_util::convertAidlNanPublishRequestToLegacy(msg, &legacy_msg)) {
868 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
869 }
870 legacy_hal::wifi_error legacy_status =
871 legacy_hal_.lock()->nanPublishRequest(ifname_, cmd_id, legacy_msg);
872 return createWifiStatusFromLegacyError(legacy_status);
873 }
874
stopPublishRequestInternal(char16_t cmd_id,int8_t sessionId)875 ndk::ScopedAStatus WifiNanIface::stopPublishRequestInternal(char16_t cmd_id, int8_t sessionId) {
876 legacy_hal::NanPublishCancelRequest legacy_msg;
877 legacy_msg.publish_id = sessionId;
878 legacy_hal::wifi_error legacy_status =
879 legacy_hal_.lock()->nanPublishCancelRequest(ifname_, cmd_id, legacy_msg);
880 return createWifiStatusFromLegacyError(legacy_status);
881 }
882
startSubscribeRequestInternal(char16_t cmd_id,const NanSubscribeRequest & msg)883 ndk::ScopedAStatus WifiNanIface::startSubscribeRequestInternal(char16_t cmd_id,
884 const NanSubscribeRequest& msg) {
885 legacy_hal::NanSubscribeRequest legacy_msg;
886 if (!aidl_struct_util::convertAidlNanSubscribeRequestToLegacy(msg, &legacy_msg)) {
887 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
888 }
889 legacy_hal::wifi_error legacy_status =
890 legacy_hal_.lock()->nanSubscribeRequest(ifname_, cmd_id, legacy_msg);
891 return createWifiStatusFromLegacyError(legacy_status);
892 }
893
stopSubscribeRequestInternal(char16_t cmd_id,int8_t sessionId)894 ndk::ScopedAStatus WifiNanIface::stopSubscribeRequestInternal(char16_t cmd_id, int8_t sessionId) {
895 legacy_hal::NanSubscribeCancelRequest legacy_msg;
896 legacy_msg.subscribe_id = sessionId;
897 legacy_hal::wifi_error legacy_status =
898 legacy_hal_.lock()->nanSubscribeCancelRequest(ifname_, cmd_id, legacy_msg);
899 return createWifiStatusFromLegacyError(legacy_status);
900 }
901
transmitFollowupRequestInternal(char16_t cmd_id,const NanTransmitFollowupRequest & msg)902 ndk::ScopedAStatus WifiNanIface::transmitFollowupRequestInternal(
903 char16_t cmd_id, const NanTransmitFollowupRequest& msg) {
904 legacy_hal::NanTransmitFollowupRequest legacy_msg;
905 if (!aidl_struct_util::convertAidlNanTransmitFollowupRequestToLegacy(msg, &legacy_msg)) {
906 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
907 }
908 legacy_hal::wifi_error legacy_status =
909 legacy_hal_.lock()->nanTransmitFollowupRequest(ifname_, cmd_id, legacy_msg);
910 return createWifiStatusFromLegacyError(legacy_status);
911 }
912
createDataInterfaceRequestInternal(char16_t cmd_id,const std::string & iface_name)913 ndk::ScopedAStatus WifiNanIface::createDataInterfaceRequestInternal(char16_t cmd_id,
914 const std::string& iface_name) {
915 legacy_hal::wifi_error legacy_status =
916 legacy_hal_.lock()->nanDataInterfaceCreate(ifname_, cmd_id, iface_name);
917 return createWifiStatusFromLegacyError(legacy_status);
918 }
deleteDataInterfaceRequestInternal(char16_t cmd_id,const std::string & iface_name)919 ndk::ScopedAStatus WifiNanIface::deleteDataInterfaceRequestInternal(char16_t cmd_id,
920 const std::string& iface_name) {
921 legacy_hal::wifi_error legacy_status =
922 legacy_hal_.lock()->nanDataInterfaceDelete(ifname_, cmd_id, iface_name);
923 return createWifiStatusFromLegacyError(legacy_status);
924 }
initiateDataPathRequestInternal(char16_t cmd_id,const NanInitiateDataPathRequest & msg)925 ndk::ScopedAStatus WifiNanIface::initiateDataPathRequestInternal(
926 char16_t cmd_id, const NanInitiateDataPathRequest& msg) {
927 legacy_hal::NanDataPathInitiatorRequest legacy_msg;
928 if (!aidl_struct_util::convertAidlNanDataPathInitiatorRequestToLegacy(msg, &legacy_msg)) {
929 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
930 }
931 legacy_hal::wifi_error legacy_status =
932 legacy_hal_.lock()->nanDataRequestInitiator(ifname_, cmd_id, legacy_msg);
933 return createWifiStatusFromLegacyError(legacy_status);
934 }
respondToDataPathIndicationRequestInternal(char16_t cmd_id,const NanRespondToDataPathIndicationRequest & msg)935 ndk::ScopedAStatus WifiNanIface::respondToDataPathIndicationRequestInternal(
936 char16_t cmd_id, const NanRespondToDataPathIndicationRequest& msg) {
937 legacy_hal::NanDataPathIndicationResponse legacy_msg;
938 if (!aidl_struct_util::convertAidlNanDataPathIndicationResponseToLegacy(msg, &legacy_msg)) {
939 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
940 }
941 legacy_hal::wifi_error legacy_status =
942 legacy_hal_.lock()->nanDataIndicationResponse(ifname_, cmd_id, legacy_msg);
943 return createWifiStatusFromLegacyError(legacy_status);
944 }
terminateDataPathRequestInternal(char16_t cmd_id,int32_t ndpInstanceId)945 ndk::ScopedAStatus WifiNanIface::terminateDataPathRequestInternal(char16_t cmd_id,
946 int32_t ndpInstanceId) {
947 legacy_hal::wifi_error legacy_status =
948 legacy_hal_.lock()->nanDataEnd(ifname_, cmd_id, ndpInstanceId);
949 return createWifiStatusFromLegacyError(legacy_status);
950 }
initiatePairingRequestInternal(char16_t cmd_id,const NanPairingRequest & msg)951 ndk::ScopedAStatus WifiNanIface::initiatePairingRequestInternal(char16_t cmd_id,
952 const NanPairingRequest& msg) {
953 legacy_hal::NanPairingRequest legacy_msg;
954 if (!aidl_struct_util::convertAidlNanPairingInitiatorRequestToLegacy(msg, &legacy_msg)) {
955 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
956 }
957 legacy_hal::wifi_error legacy_status =
958 legacy_hal_.lock()->nanPairingRequest(ifname_, cmd_id, legacy_msg);
959 return createWifiStatusFromLegacyError(legacy_status);
960 }
respondToPairingIndicationRequestInternal(char16_t cmd_id,const NanRespondToPairingIndicationRequest & msg)961 ndk::ScopedAStatus WifiNanIface::respondToPairingIndicationRequestInternal(
962 char16_t cmd_id, const NanRespondToPairingIndicationRequest& msg) {
963 legacy_hal::NanPairingIndicationResponse legacy_msg;
964 if (!aidl_struct_util::convertAidlNanPairingIndicationResponseToLegacy(msg, &legacy_msg)) {
965 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
966 }
967 legacy_hal::wifi_error legacy_status =
968 legacy_hal_.lock()->nanPairingIndicationResponse(ifname_, cmd_id, legacy_msg);
969 return createWifiStatusFromLegacyError(legacy_status);
970 }
terminatePairingRequestInternal(char16_t cmd_id,int32_t ndpInstanceId)971 ndk::ScopedAStatus WifiNanIface::terminatePairingRequestInternal(char16_t cmd_id,
972 int32_t ndpInstanceId) {
973 legacy_hal::wifi_error legacy_status =
974 legacy_hal_.lock()->nanPairingEnd(ifname_, cmd_id, ndpInstanceId);
975 return createWifiStatusFromLegacyError(legacy_status);
976 }
initiateBootstrappingRequestInternal(char16_t cmd_id,const NanBootstrappingRequest & msg)977 ndk::ScopedAStatus WifiNanIface::initiateBootstrappingRequestInternal(
978 char16_t cmd_id, const NanBootstrappingRequest& msg) {
979 legacy_hal::NanBootstrappingRequest legacy_msg;
980 if (!aidl_struct_util::convertAidlNanBootstrappingInitiatorRequestToLegacy(msg, &legacy_msg)) {
981 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
982 }
983 legacy_hal::wifi_error legacy_status =
984 legacy_hal_.lock()->nanBootstrappingRequest(ifname_, cmd_id, legacy_msg);
985 return createWifiStatusFromLegacyError(legacy_status);
986 }
respondToBootstrappingIndicationRequestInternal(char16_t cmd_id,const NanBootstrappingResponse & msg)987 ndk::ScopedAStatus WifiNanIface::respondToBootstrappingIndicationRequestInternal(
988 char16_t cmd_id, const NanBootstrappingResponse& msg) {
989 legacy_hal::NanBootstrappingIndicationResponse legacy_msg;
990 if (!aidl_struct_util::convertAidlNanBootstrappingIndicationResponseToLegacy(msg,
991 &legacy_msg)) {
992 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
993 }
994 legacy_hal::wifi_error legacy_status =
995 legacy_hal_.lock()->nanBootstrappingIndicationResponse(ifname_, cmd_id, legacy_msg);
996 return createWifiStatusFromLegacyError(legacy_status);
997 }
suspendRequestInternal(char16_t cmd_id,int8_t sessionId)998 ndk::ScopedAStatus WifiNanIface::suspendRequestInternal(char16_t cmd_id, int8_t sessionId) {
999 legacy_hal::NanSuspendRequest legacy_msg;
1000 legacy_msg.publish_subscribe_id = sessionId;
1001 legacy_hal::wifi_error legacy_status =
1002 legacy_hal_.lock()->nanSuspendRequest(ifname_, cmd_id, legacy_msg);
1003 return createWifiStatusFromLegacyError(legacy_status);
1004 }
resumeRequestInternal(char16_t cmd_id,int8_t sessionId)1005 ndk::ScopedAStatus WifiNanIface::resumeRequestInternal(char16_t cmd_id, int8_t sessionId) {
1006 legacy_hal::NanResumeRequest legacy_msg;
1007 legacy_msg.publish_subscribe_id = sessionId;
1008 legacy_hal::wifi_error legacy_status =
1009 legacy_hal_.lock()->nanResumeRequest(ifname_, cmd_id, legacy_msg);
1010 return createWifiStatusFromLegacyError(legacy_status);
1011 }
1012 } // namespace wifi
1013 } // namespace hardware
1014 } // namespace android
1015 } // namespace aidl
1016