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