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