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