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