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