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