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