xref: /aosp_15_r20/hardware/interfaces/wifi/aidl/default/wifi_nan_iface.cpp (revision 4d7e907c777eeecc4c5bd7cf640a754fac206ff7)
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     callback_handlers.on_ranging_results = [weak_ptr_this](
617                                                    legacy_hal::wifi_rtt_result* rtt_results[],
618                                                    uint32_t num_results, uint16_t session_id) {
619         const auto shared_ptr_this = weak_ptr_this.lock();
620         if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
621             LOG(ERROR) << "Callback invoked on an invalid object";
622             return;
623         }
624         if (shared_ptr_this->getMinCallbackVersion() < 3) {
625             LOG(INFO) << "notifyRangingResults requires callback version 3";
626             return;
627         }
628 
629         std::vector<const wifi_rtt_result*> legacy_results;
630         std::copy_if(rtt_results, rtt_results + num_results, back_inserter(legacy_results),
631                      [](wifi_rtt_result* rtt_result) { return rtt_result != nullptr; });
632 
633         std::vector<RttResult> aidl_results;
634         if (!aidl_struct_util::convertLegacyVectorOfRttResultToAidl(legacy_results,
635                                                                     &aidl_results)) {
636             LOG(ERROR) << "Failed to convert RTT results to AIDL structs";
637             return;
638         }
639 
640         for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
641             if (!callback->notifyRangingResults(aidl_results, session_id).isOk()) {
642                 LOG(ERROR) << "Failed to invoke the callback";
643             }
644         }
645     };
646     legacy_hal::wifi_error legacy_status =
647             legacy_hal_.lock()->nanRegisterCallbackHandlers(ifname_, callback_handlers);
648     if (legacy_status != legacy_hal::WIFI_SUCCESS) {
649         LOG(ERROR) << "Failed to register nan callbacks. Invalidating object";
650         invalidate();
651     }
652 
653     // Register for iface state toggle events.
654     iface_util::IfaceEventHandlers event_handlers = {};
655 #ifndef WIFI_SKIP_STATE_TOGGLE_OFF_ON_FOR_NAN
656     event_handlers.on_state_toggle_off_on = [weak_ptr_this](const std::string& /* iface_name */) {
657         const auto shared_ptr_this = weak_ptr_this.lock();
658         if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
659             LOG(ERROR) << "Callback invoked on an invalid object";
660             return;
661         }
662         // Tell framework that NAN has been disabled.
663         NanStatus status = {NanStatusCode::UNSUPPORTED_CONCURRENCY_NAN_DISABLED, ""};
664         for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
665             if (!callback->eventDisabled(status).isOk()) {
666                 LOG(ERROR) << "Failed to invoke the callback";
667             }
668         }
669     };
670 #endif
671     iface_util_.lock()->registerIfaceEventHandlers(ifname_, event_handlers);
672 }
673 
setWeakPtr(std::weak_ptr<WifiNanIface> ptr)674 void WifiNanIface::setWeakPtr(std::weak_ptr<WifiNanIface> ptr) {
675     weak_ptr_this_ = ptr;
676 }
677 
invalidate()678 void WifiNanIface::invalidate() {
679     if (!isValid()) {
680         return;
681     }
682     // send commands to HAL to actually disable and destroy interfaces
683     legacy_hal_.lock()->nanDisableRequest(ifname_, 0xFFFF);
684     legacy_hal_.lock()->nanDataInterfaceDelete(ifname_, 0xFFFE, "aware_data0");
685     legacy_hal_.lock()->nanDataInterfaceDelete(ifname_, 0xFFFD, "aware_data1");
686     iface_util_.lock()->unregisterIfaceEventHandlers(ifname_);
687     legacy_hal_.reset();
688     event_cb_handler_.invalidate();
689     is_valid_ = false;
690     if (is_dedicated_iface_) {
691         // If using a dedicated iface, set the iface down.
692         iface_util_.lock()->setUpState(ifname_, false);
693     }
694 }
695 
isValid()696 bool WifiNanIface::isValid() {
697     return is_valid_;
698 }
699 
getName()700 std::string WifiNanIface::getName() {
701     return ifname_;
702 }
703 
getMinCallbackVersion()704 int32_t WifiNanIface::getMinCallbackVersion() {
705     return event_cb_handler_.getMinCallbackVersion();
706 }
707 
getEventCallbacks()708 std::set<std::shared_ptr<IWifiNanIfaceEventCallback>> WifiNanIface::getEventCallbacks() {
709     LOG(ERROR) << "Using original getEventCallbacks";
710     return event_cb_handler_.getCallbacks();
711 }
712 
getName(std::string * _aidl_return)713 ndk::ScopedAStatus WifiNanIface::getName(std::string* _aidl_return) {
714     return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
715                            &WifiNanIface::getNameInternal, _aidl_return);
716 }
717 
registerEventCallback(const std::shared_ptr<IWifiNanIfaceEventCallback> & callback)718 ndk::ScopedAStatus WifiNanIface::registerEventCallback(
719         const std::shared_ptr<IWifiNanIfaceEventCallback>& callback) {
720     return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
721                            &WifiNanIface::registerEventCallbackInternal, callback);
722 }
723 
getCapabilitiesRequest(char16_t in_cmdId)724 ndk::ScopedAStatus WifiNanIface::getCapabilitiesRequest(char16_t in_cmdId) {
725     return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
726                            &WifiNanIface::getCapabilitiesRequestInternal, in_cmdId);
727 }
728 
enableRequest(char16_t in_cmdId,const NanEnableRequest & in_msg1,const NanConfigRequestSupplemental & in_msg2)729 ndk::ScopedAStatus WifiNanIface::enableRequest(char16_t in_cmdId, const NanEnableRequest& in_msg1,
730                                                const NanConfigRequestSupplemental& in_msg2) {
731     return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
732                            &WifiNanIface::enableRequestInternal, in_cmdId, in_msg1, in_msg2);
733 }
734 
configRequest(char16_t in_cmdId,const NanConfigRequest & in_msg1,const NanConfigRequestSupplemental & in_msg2)735 ndk::ScopedAStatus WifiNanIface::configRequest(char16_t in_cmdId, const NanConfigRequest& in_msg1,
736                                                const NanConfigRequestSupplemental& in_msg2) {
737     return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
738                            &WifiNanIface::configRequestInternal, in_cmdId, in_msg1, in_msg2);
739 }
740 
disableRequest(char16_t in_cmdId)741 ndk::ScopedAStatus WifiNanIface::disableRequest(char16_t in_cmdId) {
742     return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
743                            &WifiNanIface::disableRequestInternal, in_cmdId);
744 }
745 
startPublishRequest(char16_t in_cmdId,const NanPublishRequest & in_msg)746 ndk::ScopedAStatus WifiNanIface::startPublishRequest(char16_t in_cmdId,
747                                                      const NanPublishRequest& in_msg) {
748     return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
749                            &WifiNanIface::startPublishRequestInternal, in_cmdId, in_msg);
750 }
751 
stopPublishRequest(char16_t in_cmdId,int8_t in_sessionId)752 ndk::ScopedAStatus WifiNanIface::stopPublishRequest(char16_t in_cmdId, int8_t in_sessionId) {
753     return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
754                            &WifiNanIface::stopPublishRequestInternal, in_cmdId, in_sessionId);
755 }
756 
startSubscribeRequest(char16_t in_cmdId,const NanSubscribeRequest & in_msg)757 ndk::ScopedAStatus WifiNanIface::startSubscribeRequest(char16_t in_cmdId,
758                                                        const NanSubscribeRequest& in_msg) {
759     return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
760                            &WifiNanIface::startSubscribeRequestInternal, in_cmdId, in_msg);
761 }
762 
stopSubscribeRequest(char16_t in_cmdId,int8_t in_sessionId)763 ndk::ScopedAStatus WifiNanIface::stopSubscribeRequest(char16_t in_cmdId, int8_t in_sessionId) {
764     return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
765                            &WifiNanIface::stopSubscribeRequestInternal, in_cmdId, in_sessionId);
766 }
767 
transmitFollowupRequest(char16_t in_cmdId,const NanTransmitFollowupRequest & in_msg)768 ndk::ScopedAStatus WifiNanIface::transmitFollowupRequest(char16_t in_cmdId,
769                                                          const NanTransmitFollowupRequest& in_msg) {
770     return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
771                            &WifiNanIface::transmitFollowupRequestInternal, in_cmdId, in_msg);
772 }
773 
createDataInterfaceRequest(char16_t in_cmdId,const std::string & in_ifaceName)774 ndk::ScopedAStatus WifiNanIface::createDataInterfaceRequest(char16_t in_cmdId,
775                                                             const std::string& in_ifaceName) {
776     return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
777                            &WifiNanIface::createDataInterfaceRequestInternal, in_cmdId,
778                            in_ifaceName);
779 }
780 
deleteDataInterfaceRequest(char16_t in_cmdId,const std::string & in_ifaceName)781 ndk::ScopedAStatus WifiNanIface::deleteDataInterfaceRequest(char16_t in_cmdId,
782                                                             const std::string& in_ifaceName) {
783     return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
784                            &WifiNanIface::deleteDataInterfaceRequestInternal, in_cmdId,
785                            in_ifaceName);
786 }
787 
initiateDataPathRequest(char16_t in_cmdId,const NanInitiateDataPathRequest & in_msg)788 ndk::ScopedAStatus WifiNanIface::initiateDataPathRequest(char16_t in_cmdId,
789                                                          const NanInitiateDataPathRequest& in_msg) {
790     return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
791                            &WifiNanIface::initiateDataPathRequestInternal, in_cmdId, in_msg);
792 }
793 
respondToDataPathIndicationRequest(char16_t in_cmdId,const NanRespondToDataPathIndicationRequest & in_msg)794 ndk::ScopedAStatus WifiNanIface::respondToDataPathIndicationRequest(
795         char16_t in_cmdId, const NanRespondToDataPathIndicationRequest& in_msg) {
796     return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
797                            &WifiNanIface::respondToDataPathIndicationRequestInternal, in_cmdId,
798                            in_msg);
799 }
800 
terminateDataPathRequest(char16_t in_cmdId,int32_t in_ndpInstanceId)801 ndk::ScopedAStatus WifiNanIface::terminateDataPathRequest(char16_t in_cmdId,
802                                                           int32_t in_ndpInstanceId) {
803     return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
804                            &WifiNanIface::terminateDataPathRequestInternal, in_cmdId,
805                            in_ndpInstanceId);
806 }
807 
initiatePairingRequest(char16_t in_cmdId,const NanPairingRequest & in_msg)808 ndk::ScopedAStatus WifiNanIface::initiatePairingRequest(char16_t in_cmdId,
809                                                         const NanPairingRequest& in_msg) {
810     return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
811                            &WifiNanIface::initiatePairingRequestInternal, in_cmdId, in_msg);
812 }
813 
respondToPairingIndicationRequest(char16_t in_cmdId,const NanRespondToPairingIndicationRequest & in_msg)814 ndk::ScopedAStatus WifiNanIface::respondToPairingIndicationRequest(
815         char16_t in_cmdId, const NanRespondToPairingIndicationRequest& in_msg) {
816     return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
817                            &WifiNanIface::respondToPairingIndicationRequestInternal, in_cmdId,
818                            in_msg);
819 }
820 
terminatePairingRequest(char16_t in_cmdId,int32_t in_ndpInstanceId)821 ndk::ScopedAStatus WifiNanIface::terminatePairingRequest(char16_t in_cmdId,
822                                                          int32_t in_ndpInstanceId) {
823     return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
824                            &WifiNanIface::terminatePairingRequestInternal, in_cmdId,
825                            in_ndpInstanceId);
826 }
827 
initiateBootstrappingRequest(char16_t in_cmdId,const NanBootstrappingRequest & in_msg)828 ndk::ScopedAStatus WifiNanIface::initiateBootstrappingRequest(
829         char16_t in_cmdId, const NanBootstrappingRequest& in_msg) {
830     return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
831                            &WifiNanIface::initiateBootstrappingRequestInternal, in_cmdId, in_msg);
832 }
833 
respondToBootstrappingIndicationRequest(char16_t in_cmdId,const NanBootstrappingResponse & in_msg)834 ndk::ScopedAStatus WifiNanIface::respondToBootstrappingIndicationRequest(
835         char16_t in_cmdId, const NanBootstrappingResponse& in_msg) {
836     return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
837                            &WifiNanIface::respondToBootstrappingIndicationRequestInternal, in_cmdId,
838                            in_msg);
839 }
840 
suspendRequest(char16_t in_cmdId,int8_t in_sessionId)841 ndk::ScopedAStatus WifiNanIface::suspendRequest(char16_t in_cmdId, int8_t in_sessionId) {
842     return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
843                            &WifiNanIface::suspendRequestInternal, in_cmdId, in_sessionId);
844 }
845 
resumeRequest(char16_t in_cmdId,int8_t in_sessionId)846 ndk::ScopedAStatus WifiNanIface::resumeRequest(char16_t in_cmdId, int8_t in_sessionId) {
847     return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
848                            &WifiNanIface::resumeRequestInternal, in_cmdId, in_sessionId);
849 }
850 
getNameInternal()851 std::pair<std::string, ndk::ScopedAStatus> WifiNanIface::getNameInternal() {
852     return {ifname_, ndk::ScopedAStatus::ok()};
853 }
854 
registerEventCallbackInternal(const std::shared_ptr<IWifiNanIfaceEventCallback> & callback)855 ndk::ScopedAStatus WifiNanIface::registerEventCallbackInternal(
856         const std::shared_ptr<IWifiNanIfaceEventCallback>& callback) {
857     if (!event_cb_handler_.addCallback(callback)) {
858         return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN);
859     }
860     return ndk::ScopedAStatus::ok();
861 }
862 
getCapabilitiesRequestInternal(char16_t cmd_id)863 ndk::ScopedAStatus WifiNanIface::getCapabilitiesRequestInternal(char16_t cmd_id) {
864     legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->nanGetCapabilities(ifname_, cmd_id);
865     return createWifiStatusFromLegacyError(legacy_status);
866 }
867 
enableRequestInternal(char16_t cmd_id,const NanEnableRequest & msg1,const NanConfigRequestSupplemental & msg2)868 ndk::ScopedAStatus WifiNanIface::enableRequestInternal(char16_t cmd_id,
869                                                        const NanEnableRequest& msg1,
870                                                        const NanConfigRequestSupplemental& msg2) {
871     legacy_hal::NanEnableRequest legacy_msg;
872     if (!aidl_struct_util::convertAidlNanEnableRequestToLegacy(msg1, msg2, &legacy_msg)) {
873         return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
874     }
875     legacy_hal::wifi_error legacy_status =
876             legacy_hal_.lock()->nanEnableRequest(ifname_, cmd_id, legacy_msg);
877     return createWifiStatusFromLegacyError(legacy_status);
878 }
879 
configRequestInternal(char16_t cmd_id,const NanConfigRequest & msg1,const NanConfigRequestSupplemental & msg2)880 ndk::ScopedAStatus WifiNanIface::configRequestInternal(char16_t cmd_id,
881                                                        const NanConfigRequest& msg1,
882                                                        const NanConfigRequestSupplemental& msg2) {
883     legacy_hal::NanConfigRequest legacy_msg;
884     if (!aidl_struct_util::convertAidlNanConfigRequestToLegacy(msg1, msg2, &legacy_msg)) {
885         return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
886     }
887     legacy_hal::wifi_error legacy_status =
888             legacy_hal_.lock()->nanConfigRequest(ifname_, cmd_id, legacy_msg);
889     return createWifiStatusFromLegacyError(legacy_status);
890 }
891 
disableRequestInternal(char16_t cmd_id)892 ndk::ScopedAStatus WifiNanIface::disableRequestInternal(char16_t cmd_id) {
893     legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->nanDisableRequest(ifname_, cmd_id);
894     return createWifiStatusFromLegacyError(legacy_status);
895 }
896 
startPublishRequestInternal(char16_t cmd_id,const NanPublishRequest & msg)897 ndk::ScopedAStatus WifiNanIface::startPublishRequestInternal(char16_t cmd_id,
898                                                              const NanPublishRequest& msg) {
899     legacy_hal::NanPublishRequest legacy_msg;
900     if (!aidl_struct_util::convertAidlNanPublishRequestToLegacy(msg, &legacy_msg)) {
901         return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
902     }
903     legacy_hal::wifi_error legacy_status =
904             legacy_hal_.lock()->nanPublishRequest(ifname_, cmd_id, legacy_msg);
905     return createWifiStatusFromLegacyError(legacy_status);
906 }
907 
stopPublishRequestInternal(char16_t cmd_id,int8_t sessionId)908 ndk::ScopedAStatus WifiNanIface::stopPublishRequestInternal(char16_t cmd_id, int8_t sessionId) {
909     legacy_hal::NanPublishCancelRequest legacy_msg;
910     legacy_msg.publish_id = sessionId;
911     legacy_hal::wifi_error legacy_status =
912             legacy_hal_.lock()->nanPublishCancelRequest(ifname_, cmd_id, legacy_msg);
913     return createWifiStatusFromLegacyError(legacy_status);
914 }
915 
startSubscribeRequestInternal(char16_t cmd_id,const NanSubscribeRequest & msg)916 ndk::ScopedAStatus WifiNanIface::startSubscribeRequestInternal(char16_t cmd_id,
917                                                                const NanSubscribeRequest& msg) {
918     legacy_hal::NanSubscribeRequest legacy_msg;
919     if (!aidl_struct_util::convertAidlNanSubscribeRequestToLegacy(msg, &legacy_msg)) {
920         return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
921     }
922     legacy_hal::wifi_error legacy_status =
923             legacy_hal_.lock()->nanSubscribeRequest(ifname_, cmd_id, legacy_msg);
924     return createWifiStatusFromLegacyError(legacy_status);
925 }
926 
stopSubscribeRequestInternal(char16_t cmd_id,int8_t sessionId)927 ndk::ScopedAStatus WifiNanIface::stopSubscribeRequestInternal(char16_t cmd_id, int8_t sessionId) {
928     legacy_hal::NanSubscribeCancelRequest legacy_msg;
929     legacy_msg.subscribe_id = sessionId;
930     legacy_hal::wifi_error legacy_status =
931             legacy_hal_.lock()->nanSubscribeCancelRequest(ifname_, cmd_id, legacy_msg);
932     return createWifiStatusFromLegacyError(legacy_status);
933 }
934 
transmitFollowupRequestInternal(char16_t cmd_id,const NanTransmitFollowupRequest & msg)935 ndk::ScopedAStatus WifiNanIface::transmitFollowupRequestInternal(
936         char16_t cmd_id, const NanTransmitFollowupRequest& msg) {
937     legacy_hal::NanTransmitFollowupRequest legacy_msg;
938     if (!aidl_struct_util::convertAidlNanTransmitFollowupRequestToLegacy(msg, &legacy_msg)) {
939         return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
940     }
941     legacy_hal::wifi_error legacy_status =
942             legacy_hal_.lock()->nanTransmitFollowupRequest(ifname_, cmd_id, legacy_msg);
943     return createWifiStatusFromLegacyError(legacy_status);
944 }
945 
createDataInterfaceRequestInternal(char16_t cmd_id,const std::string & iface_name)946 ndk::ScopedAStatus WifiNanIface::createDataInterfaceRequestInternal(char16_t cmd_id,
947                                                                     const std::string& iface_name) {
948     legacy_hal::wifi_error legacy_status =
949             legacy_hal_.lock()->nanDataInterfaceCreate(ifname_, cmd_id, iface_name);
950     return createWifiStatusFromLegacyError(legacy_status);
951 }
deleteDataInterfaceRequestInternal(char16_t cmd_id,const std::string & iface_name)952 ndk::ScopedAStatus WifiNanIface::deleteDataInterfaceRequestInternal(char16_t cmd_id,
953                                                                     const std::string& iface_name) {
954     legacy_hal::wifi_error legacy_status =
955             legacy_hal_.lock()->nanDataInterfaceDelete(ifname_, cmd_id, iface_name);
956     return createWifiStatusFromLegacyError(legacy_status);
957 }
initiateDataPathRequestInternal(char16_t cmd_id,const NanInitiateDataPathRequest & msg)958 ndk::ScopedAStatus WifiNanIface::initiateDataPathRequestInternal(
959         char16_t cmd_id, const NanInitiateDataPathRequest& msg) {
960     legacy_hal::NanDataPathInitiatorRequest legacy_msg;
961     if (!aidl_struct_util::convertAidlNanDataPathInitiatorRequestToLegacy(msg, &legacy_msg)) {
962         return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
963     }
964     legacy_hal::wifi_error legacy_status =
965             legacy_hal_.lock()->nanDataRequestInitiator(ifname_, cmd_id, legacy_msg);
966     return createWifiStatusFromLegacyError(legacy_status);
967 }
respondToDataPathIndicationRequestInternal(char16_t cmd_id,const NanRespondToDataPathIndicationRequest & msg)968 ndk::ScopedAStatus WifiNanIface::respondToDataPathIndicationRequestInternal(
969         char16_t cmd_id, const NanRespondToDataPathIndicationRequest& msg) {
970     legacy_hal::NanDataPathIndicationResponse legacy_msg;
971     if (!aidl_struct_util::convertAidlNanDataPathIndicationResponseToLegacy(msg, &legacy_msg)) {
972         return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
973     }
974     legacy_hal::wifi_error legacy_status =
975             legacy_hal_.lock()->nanDataIndicationResponse(ifname_, cmd_id, legacy_msg);
976     return createWifiStatusFromLegacyError(legacy_status);
977 }
terminateDataPathRequestInternal(char16_t cmd_id,int32_t ndpInstanceId)978 ndk::ScopedAStatus WifiNanIface::terminateDataPathRequestInternal(char16_t cmd_id,
979                                                                   int32_t ndpInstanceId) {
980     legacy_hal::wifi_error legacy_status =
981             legacy_hal_.lock()->nanDataEnd(ifname_, cmd_id, ndpInstanceId);
982     return createWifiStatusFromLegacyError(legacy_status);
983 }
initiatePairingRequestInternal(char16_t cmd_id,const NanPairingRequest & msg)984 ndk::ScopedAStatus WifiNanIface::initiatePairingRequestInternal(char16_t cmd_id,
985                                                                 const NanPairingRequest& msg) {
986     legacy_hal::NanPairingRequest legacy_msg;
987     if (!aidl_struct_util::convertAidlNanPairingInitiatorRequestToLegacy(msg, &legacy_msg)) {
988         return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
989     }
990     legacy_hal::wifi_error legacy_status =
991             legacy_hal_.lock()->nanPairingRequest(ifname_, cmd_id, legacy_msg);
992     return createWifiStatusFromLegacyError(legacy_status);
993 }
respondToPairingIndicationRequestInternal(char16_t cmd_id,const NanRespondToPairingIndicationRequest & msg)994 ndk::ScopedAStatus WifiNanIface::respondToPairingIndicationRequestInternal(
995         char16_t cmd_id, const NanRespondToPairingIndicationRequest& msg) {
996     legacy_hal::NanPairingIndicationResponse legacy_msg;
997     if (!aidl_struct_util::convertAidlNanPairingIndicationResponseToLegacy(msg, &legacy_msg)) {
998         return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
999     }
1000     legacy_hal::wifi_error legacy_status =
1001             legacy_hal_.lock()->nanPairingIndicationResponse(ifname_, cmd_id, legacy_msg);
1002     return createWifiStatusFromLegacyError(legacy_status);
1003 }
terminatePairingRequestInternal(char16_t cmd_id,int32_t ndpInstanceId)1004 ndk::ScopedAStatus WifiNanIface::terminatePairingRequestInternal(char16_t cmd_id,
1005                                                                  int32_t ndpInstanceId) {
1006     legacy_hal::wifi_error legacy_status =
1007             legacy_hal_.lock()->nanPairingEnd(ifname_, cmd_id, ndpInstanceId);
1008     return createWifiStatusFromLegacyError(legacy_status);
1009 }
initiateBootstrappingRequestInternal(char16_t cmd_id,const NanBootstrappingRequest & msg)1010 ndk::ScopedAStatus WifiNanIface::initiateBootstrappingRequestInternal(
1011         char16_t cmd_id, const NanBootstrappingRequest& msg) {
1012     legacy_hal::NanBootstrappingRequest legacy_msg;
1013     if (!aidl_struct_util::convertAidlNanBootstrappingInitiatorRequestToLegacy(msg, &legacy_msg)) {
1014         return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
1015     }
1016     legacy_hal::wifi_error legacy_status =
1017             legacy_hal_.lock()->nanBootstrappingRequest(ifname_, cmd_id, legacy_msg);
1018     return createWifiStatusFromLegacyError(legacy_status);
1019 }
respondToBootstrappingIndicationRequestInternal(char16_t cmd_id,const NanBootstrappingResponse & msg)1020 ndk::ScopedAStatus WifiNanIface::respondToBootstrappingIndicationRequestInternal(
1021         char16_t cmd_id, const NanBootstrappingResponse& msg) {
1022     legacy_hal::NanBootstrappingIndicationResponse legacy_msg;
1023     if (!aidl_struct_util::convertAidlNanBootstrappingIndicationResponseToLegacy(msg,
1024                                                                                  &legacy_msg)) {
1025         return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
1026     }
1027     legacy_hal::wifi_error legacy_status =
1028             legacy_hal_.lock()->nanBootstrappingIndicationResponse(ifname_, cmd_id, legacy_msg);
1029     return createWifiStatusFromLegacyError(legacy_status);
1030 }
suspendRequestInternal(char16_t cmd_id,int8_t sessionId)1031 ndk::ScopedAStatus WifiNanIface::suspendRequestInternal(char16_t cmd_id, int8_t sessionId) {
1032     legacy_hal::NanSuspendRequest legacy_msg;
1033     legacy_msg.publish_subscribe_id = sessionId;
1034     legacy_hal::wifi_error legacy_status =
1035             legacy_hal_.lock()->nanSuspendRequest(ifname_, cmd_id, legacy_msg);
1036     return createWifiStatusFromLegacyError(legacy_status);
1037 }
resumeRequestInternal(char16_t cmd_id,int8_t sessionId)1038 ndk::ScopedAStatus WifiNanIface::resumeRequestInternal(char16_t cmd_id, int8_t sessionId) {
1039     legacy_hal::NanResumeRequest legacy_msg;
1040     legacy_msg.publish_subscribe_id = sessionId;
1041     legacy_hal::wifi_error legacy_status =
1042             legacy_hal_.lock()->nanResumeRequest(ifname_, cmd_id, legacy_msg);
1043     return createWifiStatusFromLegacyError(legacy_status);
1044 }
1045 }  // namespace wifi
1046 }  // namespace hardware
1047 }  // namespace android
1048 }  // namespace aidl
1049