blob: 93b8902418c5798f4c35c8aa9ffdf281f797e958 [file] [log] [blame]
Roshan Pius3e2d6712016-10-06 13:16:23 -07001/*
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 Pius3e2d6712016-10-06 13:16:23 -070017#include <android-base/logging.h>
18
Roshan Pius907d4a22016-10-27 12:48:12 -070019#include "hidl_return_util.h"
Roshan Piusf5f51fd2016-12-01 13:54:24 -080020#include "hidl_struct_util.h"
Roshan Pius907d4a22016-10-27 12:48:12 -070021#include "wifi_nan_iface.h"
Roshan Pius734fea02016-10-11 08:30:28 -070022#include "wifi_status_util.h"
Roshan Pius3e2d6712016-10-06 13:16:23 -070023
24namespace android {
25namespace hardware {
26namespace wifi {
Etan Cohen6ce50902017-09-14 07:30:57 -070027namespace V1_2 {
Roshan Pius3e2d6712016-10-06 13:16:23 -070028namespace implementation {
Roshan Pius907d4a22016-10-27 12:48:12 -070029using hidl_return_util::validateAndCall;
Roshan Pius3e2d6712016-10-06 13:16:23 -070030
Roshan Pius6cedc972016-10-28 10:11:17 -070031WifiNanIface::WifiNanIface(
32 const std::string& ifname,
33 const std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal)
Roshan Piusf5f51fd2016-12-01 13:54:24 -080034 : 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 Cohenf01bcaa2016-12-25 09:42:21 -080039 android::wp<WifiNanIface> weak_ptr_this(this);
Roshan Piusf5f51fd2016-12-01 13:54:24 -080040
41 // Callback for response.
Etan Cohenf01bcaa2016-12-25 09:42:21 -080042 callback_handlers.on_notify_response = [weak_ptr_this](
Roshan Piusf5f51fd2016-12-01 13:54:24 -080043 legacy_hal::transaction_id id, const legacy_hal::NanResponseMsg& msg) {
Etan Cohenf01bcaa2016-12-25 09:42:21 -080044 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 Piusf5f51fd2016-12-01 13:54:24 -080050 if (!hidl_struct_util::convertLegacyNanResponseHeaderToHidl(msg,
Etan Cohenf01bcaa2016-12-25 09:42:21 -080051 &wifiNanStatus)) {
Roshan Piusf5f51fd2016-12-01 13:54:24 -080052 LOG(ERROR) << "Failed to convert nan response header";
53 return;
54 }
Etan Cohenf01bcaa2016-12-25 09:42:21 -080055
56 switch (msg.response_type) {
57 case legacy_hal::NAN_RESPONSE_ENABLED: {
Roshan Piusd37341f2017-01-31 13:13:28 -080058 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
Etan Cohenf01bcaa2016-12-25 09:42:21 -080059 if (!callback->notifyEnableResponse(id, wifiNanStatus).isOk()) {
60 LOG(ERROR) << "Failed to invoke the callback";
61 }
62 }
Etan Cohen4bbc2092017-01-30 13:28:37 -080063 break;
Roshan Piusf5f51fd2016-12-01 13:54:24 -080064 }
Etan Cohenf01bcaa2016-12-25 09:42:21 -080065 case legacy_hal::NAN_RESPONSE_DISABLED: {
Roshan Piusd37341f2017-01-31 13:13:28 -080066 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
Etan Cohenf01bcaa2016-12-25 09:42:21 -080067 if (!callback->notifyDisableResponse(id, wifiNanStatus).isOk()) {
68 LOG(ERROR) << "Failed to invoke the callback";
69 }
70 }
Etan Cohen4bbc2092017-01-30 13:28:37 -080071 break;
Etan Cohenf01bcaa2016-12-25 09:42:21 -080072 }
73 case legacy_hal::NAN_RESPONSE_PUBLISH: {
Roshan Piusd37341f2017-01-31 13:13:28 -080074 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
Etan Cohenf01bcaa2016-12-25 09:42:21 -080075 if (!callback->notifyStartPublishResponse(id, wifiNanStatus,
76 msg.body.publish_response.publish_id).isOk()) {
77 LOG(ERROR) << "Failed to invoke the callback";
78 }
79 }
Etan Cohen4bbc2092017-01-30 13:28:37 -080080 break;
Etan Cohenf01bcaa2016-12-25 09:42:21 -080081 }
82 case legacy_hal::NAN_RESPONSE_PUBLISH_CANCEL: {
Roshan Piusd37341f2017-01-31 13:13:28 -080083 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
Etan Cohenf01bcaa2016-12-25 09:42:21 -080084 if (!callback->notifyStopPublishResponse(id, wifiNanStatus).isOk()) {
85 LOG(ERROR) << "Failed to invoke the callback";
86 }
87 }
Etan Cohen4bbc2092017-01-30 13:28:37 -080088 break;
Etan Cohenf01bcaa2016-12-25 09:42:21 -080089 }
90 case legacy_hal::NAN_RESPONSE_TRANSMIT_FOLLOWUP: {
Roshan Piusd37341f2017-01-31 13:13:28 -080091 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
Etan Cohenf01bcaa2016-12-25 09:42:21 -080092 if (!callback->notifyTransmitFollowupResponse(id, wifiNanStatus).isOk()) {
93 LOG(ERROR) << "Failed to invoke the callback";
94 }
95 }
Etan Cohen4bbc2092017-01-30 13:28:37 -080096 break;
Etan Cohenf01bcaa2016-12-25 09:42:21 -080097 }
98 case legacy_hal::NAN_RESPONSE_SUBSCRIBE: {
Roshan Piusd37341f2017-01-31 13:13:28 -080099 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800100 if (!callback->notifyStartSubscribeResponse(id, wifiNanStatus,
101 msg.body.subscribe_response.subscribe_id).isOk()) {
102 LOG(ERROR) << "Failed to invoke the callback";
103 }
104 }
Etan Cohen4bbc2092017-01-30 13:28:37 -0800105 break;
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800106 }
107 case legacy_hal::NAN_RESPONSE_SUBSCRIBE_CANCEL: {
Roshan Piusd37341f2017-01-31 13:13:28 -0800108 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800109 if (!callback->notifyStopSubscribeResponse(id, wifiNanStatus).isOk()) {
110 LOG(ERROR) << "Failed to invoke the callback";
111 }
112 }
Etan Cohen4bbc2092017-01-30 13:28:37 -0800113 break;
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800114 }
115 case legacy_hal::NAN_RESPONSE_CONFIG: {
Roshan Piusd37341f2017-01-31 13:13:28 -0800116 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800117 if (!callback->notifyConfigResponse(id, wifiNanStatus).isOk()) {
118 LOG(ERROR) << "Failed to invoke the callback";
119 }
120 }
Etan Cohen4bbc2092017-01-30 13:28:37 -0800121 break;
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800122 }
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800123 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 Piusd37341f2017-01-31 13:13:28 -0800130 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800131 if (!callback->notifyCapabilitiesResponse(id, wifiNanStatus,
132 hidl_struct).isOk()) {
133 LOG(ERROR) << "Failed to invoke the callback";
134 }
135 }
Etan Cohen4bbc2092017-01-30 13:28:37 -0800136 break;
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800137 }
138 case legacy_hal::NAN_DP_INTERFACE_CREATE: {
Roshan Piusd37341f2017-01-31 13:13:28 -0800139 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800140 if (!callback->notifyCreateDataInterfaceResponse(id, wifiNanStatus).isOk()) {
141 LOG(ERROR) << "Failed to invoke the callback";
142 }
143 }
Etan Cohen4bbc2092017-01-30 13:28:37 -0800144 break;
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800145 }
146 case legacy_hal::NAN_DP_INTERFACE_DELETE: {
Roshan Piusd37341f2017-01-31 13:13:28 -0800147 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800148 if (!callback->notifyDeleteDataInterfaceResponse(id, wifiNanStatus).isOk()) {
149 LOG(ERROR) << "Failed to invoke the callback";
150 }
151 }
Etan Cohen4bbc2092017-01-30 13:28:37 -0800152 break;
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800153 }
154 case legacy_hal::NAN_DP_INITIATOR_RESPONSE: {
Roshan Piusd37341f2017-01-31 13:13:28 -0800155 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
Etan Cohen4bbc2092017-01-30 13:28:37 -0800156 if (!callback->notifyInitiateDataPathResponse(id, wifiNanStatus,
157 msg.body.data_request_response.ndp_instance_id).isOk()) {
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800158 LOG(ERROR) << "Failed to invoke the callback";
159 }
160 }
Etan Cohen4bbc2092017-01-30 13:28:37 -0800161 break;
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800162 }
163 case legacy_hal::NAN_DP_RESPONDER_RESPONSE: {
Roshan Piusd37341f2017-01-31 13:13:28 -0800164 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
Etan Cohen4bbc2092017-01-30 13:28:37 -0800165 if (!callback->notifyRespondToDataPathIndicationResponse(id, wifiNanStatus).isOk()) {
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800166 LOG(ERROR) << "Failed to invoke the callback";
167 }
168 }
Etan Cohen3c5d8ae2017-02-22 12:54:20 -0800169 break;
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800170 }
171 case legacy_hal::NAN_DP_END: {
Roshan Piusd37341f2017-01-31 13:13:28 -0800172 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800173 if (!callback->notifyTerminateDataPathResponse(id, wifiNanStatus).isOk()) {
174 LOG(ERROR) << "Failed to invoke the callback";
175 }
176 }
Etan Cohen4bbc2092017-01-30 13:28:37 -0800177 break;
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800178 }
Etan Cohenccb15622017-02-09 09:35:35 -0800179 case legacy_hal::NAN_RESPONSE_BEACON_SDF_PAYLOAD:
180 /* fall through */
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800181 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 Piusf5f51fd2016-12-01 13:54:24 -0800190 }
191 };
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800192
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 Piusd37341f2017-01-31 13:13:28 -0800205 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800206 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 Cohenbbc0f092017-04-26 16:52:34 -0700220 hidl_struct_util::convertToWifiNanStatus(msg.reason, msg.nan_reason, sizeof(msg.nan_reason),
221 &status);
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800222
Roshan Piusd37341f2017-01-31 13:13:28 -0800223 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800224 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 Cohenbbc0f092017-04-26 16:52:34 -0700238 hidl_struct_util::convertToWifiNanStatus(msg.reason, msg.nan_reason, sizeof(msg.nan_reason),
239 &status);
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800240
Roshan Piusd37341f2017-01-31 13:13:28 -0800241 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800242 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 Cohenbbc0f092017-04-26 16:52:34 -0700256 hidl_struct_util::convertToWifiNanStatus(msg.reason, msg.nan_reason, sizeof(msg.nan_reason),
257 &status);
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800258
Roshan Piusd37341f2017-01-31 13:13:28 -0800259 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800260 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 Piusd37341f2017-01-31 13:13:28 -0800280 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800281 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 Piusd37341f2017-01-31 13:13:28 -0800294 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800295 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 Piusd37341f2017-01-31 13:13:28 -0800316 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800317 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 Cohenbbc0f092017-04-26 16:52:34 -0700331 hidl_struct_util::convertToWifiNanStatus(msg.reason, msg.nan_reason, sizeof(msg.nan_reason),
332 &status);
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800333
Roshan Piusd37341f2017-01-31 13:13:28 -0800334 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800335 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 Piusd37341f2017-01-31 13:13:28 -0800355 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800356 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 Piusd37341f2017-01-31 13:13:28 -0800376 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800377 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 Piusd37341f2017-01-31 13:13:28 -0800390 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800391 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 Cohenccb15622017-02-09 09:35:35 -0800400 const legacy_hal::NanBeaconSdfPayloadInd& /* msg */) {
401 LOG(ERROR) << "on_event_beacon_sdf_payload - should not be called";
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800402 };
403
Etan Cohenc190f932017-02-17 13:06:55 -0800404 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 Piusf5f51fd2016-12-01 13:54:24 -0800414 legacy_hal::wifi_error legacy_status =
415 legacy_hal_.lock()->nanRegisterCallbackHandlers(callback_handlers);
416 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
417 LOG(ERROR) << "Failed to register nan callbacks. Invalidating object";
418 invalidate();
419 }
420}
Roshan Pius3e2d6712016-10-06 13:16:23 -0700421
422void WifiNanIface::invalidate() {
Etan Cohenc4d9f872017-06-15 08:39:23 -0700423 // send commands to HAL to actually disable and destroy interfaces
424 legacy_hal_.lock()->nanDisableRequest(0xFFFF);
425 legacy_hal_.lock()->nanDataInterfaceDelete(0xFFFE, "aware_data0");
426 legacy_hal_.lock()->nanDataInterfaceDelete(0xFFFD, "aware_data1");
427
Roshan Pius3e2d6712016-10-06 13:16:23 -0700428 legacy_hal_.reset();
Roshan Piusd37341f2017-01-31 13:13:28 -0800429 event_cb_handler_.invalidate();
Roshan Pius3e2d6712016-10-06 13:16:23 -0700430 is_valid_ = false;
431}
432
Roshan Pius907d4a22016-10-27 12:48:12 -0700433bool WifiNanIface::isValid() {
434 return is_valid_;
435}
436
Roshan Piusd37341f2017-01-31 13:13:28 -0800437std::set<sp<IWifiNanIfaceEventCallback>> WifiNanIface::getEventCallbacks() {
438 return event_cb_handler_.getCallbacks();
439}
440
Roshan Pius734fea02016-10-11 08:30:28 -0700441Return<void> WifiNanIface::getName(getName_cb hidl_status_cb) {
Roshan Pius907d4a22016-10-27 12:48:12 -0700442 return validateAndCall(this,
443 WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
444 &WifiNanIface::getNameInternal,
445 hidl_status_cb);
Roshan Pius3e2d6712016-10-06 13:16:23 -0700446}
447
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800448Return<void> WifiNanIface::getType(getType_cb hidl_status_cb) {
449 return validateAndCall(this,
450 WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
451 &WifiNanIface::getTypeInternal,
452 hidl_status_cb);
453}
454
Roshan Pius0c92d442016-10-27 17:38:53 -0700455Return<void> WifiNanIface::registerEventCallback(
456 const sp<IWifiNanIfaceEventCallback>& callback,
457 registerEventCallback_cb hidl_status_cb) {
458 return validateAndCall(this,
459 WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
460 &WifiNanIface::registerEventCallbackInternal,
461 hidl_status_cb,
462 callback);
463}
464
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800465Return<void> WifiNanIface::getCapabilitiesRequest(uint16_t cmd_id,
466 getCapabilitiesRequest_cb hidl_status_cb) {
467 return validateAndCall(this,
468 WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
469 &WifiNanIface::getCapabilitiesRequestInternal,
470 hidl_status_cb,
471 cmd_id);
472}
473
474Return<void> WifiNanIface::enableRequest(uint16_t cmd_id,
Roshan Pius0c92d442016-10-27 17:38:53 -0700475 const NanEnableRequest& msg,
476 enableRequest_cb hidl_status_cb) {
477 return validateAndCall(this,
478 WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
479 &WifiNanIface::enableRequestInternal,
480 hidl_status_cb,
481 cmd_id,
482 msg);
483}
484
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800485Return<void> WifiNanIface::configRequest(uint16_t cmd_id,
Roshan Pius0c92d442016-10-27 17:38:53 -0700486 const NanConfigRequest& msg,
487 configRequest_cb hidl_status_cb) {
488 return validateAndCall(this,
489 WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
490 &WifiNanIface::configRequestInternal,
491 hidl_status_cb,
492 cmd_id,
493 msg);
494}
495
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800496Return<void> WifiNanIface::disableRequest(uint16_t cmd_id,
497 disableRequest_cb hidl_status_cb) {
498 return validateAndCall(this,
499 WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
500 &WifiNanIface::disableRequestInternal,
501 hidl_status_cb,
502 cmd_id);
503}
504
505Return<void> WifiNanIface::startPublishRequest(uint16_t cmd_id,
506 const NanPublishRequest& msg,
507 startPublishRequest_cb hidl_status_cb) {
508 return validateAndCall(this,
509 WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
510 &WifiNanIface::startPublishRequestInternal,
511 hidl_status_cb,
512 cmd_id,
513 msg);
514}
515
516Return<void> WifiNanIface::stopPublishRequest(
517 uint16_t cmd_id,
Etan Cohen073bb992017-02-09 10:05:59 -0800518 uint8_t sessionId,
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800519 stopPublishRequest_cb hidl_status_cb) {
520 return validateAndCall(this,
521 WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
522 &WifiNanIface::stopPublishRequestInternal,
523 hidl_status_cb,
524 cmd_id,
525 sessionId);
526}
527
528Return<void> WifiNanIface::startSubscribeRequest(
529 uint16_t cmd_id,
530 const NanSubscribeRequest& msg,
531 startSubscribeRequest_cb hidl_status_cb) {
532 return validateAndCall(this,
533 WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
534 &WifiNanIface::startSubscribeRequestInternal,
535 hidl_status_cb,
536 cmd_id,
537 msg);
538}
539
540Return<void> WifiNanIface::stopSubscribeRequest(
541 uint16_t cmd_id,
Etan Cohen073bb992017-02-09 10:05:59 -0800542 uint8_t sessionId,
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800543 stopSubscribeRequest_cb hidl_status_cb) {
544 return validateAndCall(this,
545 WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
546 &WifiNanIface::stopSubscribeRequestInternal,
547 hidl_status_cb,
548 cmd_id,
549 sessionId);
550}
551
552Return<void> WifiNanIface::transmitFollowupRequest(
553 uint16_t cmd_id,
554 const NanTransmitFollowupRequest& msg,
555 transmitFollowupRequest_cb hidl_status_cb) {
556 return validateAndCall(this,
557 WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
558 &WifiNanIface::transmitFollowupRequestInternal,
559 hidl_status_cb,
560 cmd_id,
561 msg);
562}
563
564Return<void> WifiNanIface::createDataInterfaceRequest(
565 uint16_t cmd_id,
566 const hidl_string& iface_name,
567 createDataInterfaceRequest_cb hidl_status_cb) {
568 return validateAndCall(this,
569 WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
570 &WifiNanIface::createDataInterfaceRequestInternal,
571 hidl_status_cb,
572 cmd_id,
573 iface_name);
574}
575
576Return<void> WifiNanIface::deleteDataInterfaceRequest(
577 uint16_t cmd_id,
578 const hidl_string& iface_name,
579 deleteDataInterfaceRequest_cb hidl_status_cb) {
580 return validateAndCall(this,
581 WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
582 &WifiNanIface::deleteDataInterfaceRequestInternal,
583 hidl_status_cb,
584 cmd_id,
585 iface_name);
586}
587
588Return<void> WifiNanIface::initiateDataPathRequest(
589 uint16_t cmd_id,
590 const NanInitiateDataPathRequest& msg,
591 initiateDataPathRequest_cb hidl_status_cb) {
592 return validateAndCall(this,
593 WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
594 &WifiNanIface::initiateDataPathRequestInternal,
595 hidl_status_cb,
596 cmd_id,
597 msg);
598}
599
600Return<void> WifiNanIface::respondToDataPathIndicationRequest(
601 uint16_t cmd_id,
602 const NanRespondToDataPathIndicationRequest& msg,
603 respondToDataPathIndicationRequest_cb hidl_status_cb) {
604 return validateAndCall(this,
605 WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
606 &WifiNanIface::respondToDataPathIndicationRequestInternal,
607 hidl_status_cb,
608 cmd_id,
609 msg);
610}
611
612Return<void> WifiNanIface::terminateDataPathRequest(uint16_t cmd_id, uint32_t ndpInstanceId,
613 terminateDataPathRequest_cb hidl_status_cb) {
614 return validateAndCall(this,
615 WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
616 &WifiNanIface::terminateDataPathRequestInternal,
617 hidl_status_cb,
618 cmd_id,
619 ndpInstanceId);
620}
621
Roshan Pius907d4a22016-10-27 12:48:12 -0700622std::pair<WifiStatus, std::string> WifiNanIface::getNameInternal() {
623 return {createWifiStatus(WifiStatusCode::SUCCESS), ifname_};
624}
625
626std::pair<WifiStatus, IfaceType> WifiNanIface::getTypeInternal() {
627 return {createWifiStatus(WifiStatusCode::SUCCESS), IfaceType::NAN};
Roshan Pius3e2d6712016-10-06 13:16:23 -0700628}
629
Roshan Pius0c92d442016-10-27 17:38:53 -0700630WifiStatus WifiNanIface::registerEventCallbackInternal(
631 const sp<IWifiNanIfaceEventCallback>& callback) {
Roshan Piusd37341f2017-01-31 13:13:28 -0800632 if (!event_cb_handler_.addCallback(callback)) {
633 return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN);
634 }
Roshan Pius0c92d442016-10-27 17:38:53 -0700635 return createWifiStatus(WifiStatusCode::SUCCESS);
636}
637
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800638WifiStatus WifiNanIface::getCapabilitiesRequestInternal(uint16_t cmd_id) {
639 legacy_hal::wifi_error legacy_status =
640 legacy_hal_.lock()->nanGetCapabilities(cmd_id);
641 return createWifiStatusFromLegacyError(legacy_status);
642}
643
644WifiStatus WifiNanIface::enableRequestInternal(uint16_t cmd_id,
Roshan Piusf5f51fd2016-12-01 13:54:24 -0800645 const NanEnableRequest& msg) {
646 legacy_hal::NanEnableRequest legacy_msg;
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800647 if (!hidl_struct_util::convertHidlNanEnableRequestToLegacy(msg, &legacy_msg)) {
Roshan Piusf5f51fd2016-12-01 13:54:24 -0800648 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
649 }
650 legacy_hal::wifi_error legacy_status =
651 legacy_hal_.lock()->nanEnableRequest(cmd_id, legacy_msg);
652 return createWifiStatusFromLegacyError(legacy_status);
Roshan Pius0c92d442016-10-27 17:38:53 -0700653}
654
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800655WifiStatus WifiNanIface::configRequestInternal(
656 uint16_t cmd_id, const NanConfigRequest& msg) {
657 legacy_hal::NanConfigRequest legacy_msg;
658 if (!hidl_struct_util::convertHidlNanConfigRequestToLegacy(msg,
659 &legacy_msg)) {
660 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
661 }
662 legacy_hal::wifi_error legacy_status =
663 legacy_hal_.lock()->nanConfigRequest(cmd_id, legacy_msg);
664 return createWifiStatusFromLegacyError(legacy_status);
665}
666
667WifiStatus WifiNanIface::disableRequestInternal(uint16_t cmd_id) {
Roshan Piusf5f51fd2016-12-01 13:54:24 -0800668 legacy_hal::wifi_error legacy_status =
669 legacy_hal_.lock()->nanDisableRequest(cmd_id);
670 return createWifiStatusFromLegacyError(legacy_status);
Roshan Pius0c92d442016-10-27 17:38:53 -0700671}
672
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800673WifiStatus WifiNanIface::startPublishRequestInternal(uint16_t cmd_id,
674 const NanPublishRequest& msg) {
Roshan Piusf5f51fd2016-12-01 13:54:24 -0800675 legacy_hal::NanPublishRequest legacy_msg;
676 if (!hidl_struct_util::convertHidlNanPublishRequestToLegacy(msg,
677 &legacy_msg)) {
678 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
679 }
680 legacy_hal::wifi_error legacy_status =
681 legacy_hal_.lock()->nanPublishRequest(cmd_id, legacy_msg);
682 return createWifiStatusFromLegacyError(legacy_status);
Roshan Pius0c92d442016-10-27 17:38:53 -0700683}
684
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800685WifiStatus WifiNanIface::stopPublishRequestInternal(
Etan Cohen073bb992017-02-09 10:05:59 -0800686 uint16_t cmd_id, uint8_t sessionId) {
Roshan Piusf5f51fd2016-12-01 13:54:24 -0800687 legacy_hal::NanPublishCancelRequest legacy_msg;
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800688 legacy_msg.publish_id = sessionId;
Roshan Piusf5f51fd2016-12-01 13:54:24 -0800689 legacy_hal::wifi_error legacy_status =
690 legacy_hal_.lock()->nanPublishCancelRequest(cmd_id, legacy_msg);
691 return createWifiStatusFromLegacyError(legacy_status);
Roshan Pius0c92d442016-10-27 17:38:53 -0700692}
Roshan Piusf5f51fd2016-12-01 13:54:24 -0800693
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800694WifiStatus WifiNanIface::startSubscribeRequestInternal(
695 uint16_t cmd_id, const NanSubscribeRequest& msg) {
Roshan Piusf5f51fd2016-12-01 13:54:24 -0800696 legacy_hal::NanSubscribeRequest legacy_msg;
697 if (!hidl_struct_util::convertHidlNanSubscribeRequestToLegacy(msg,
698 &legacy_msg)) {
699 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
700 }
701 legacy_hal::wifi_error legacy_status =
702 legacy_hal_.lock()->nanSubscribeRequest(cmd_id, legacy_msg);
703 return createWifiStatusFromLegacyError(legacy_status);
Roshan Pius0c92d442016-10-27 17:38:53 -0700704}
Roshan Piusf5f51fd2016-12-01 13:54:24 -0800705
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800706WifiStatus WifiNanIface::stopSubscribeRequestInternal(
Etan Cohen073bb992017-02-09 10:05:59 -0800707 uint16_t cmd_id, uint8_t sessionId) {
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800708 legacy_hal::NanSubscribeCancelRequest legacy_msg;
709 legacy_msg.subscribe_id = sessionId;
710 legacy_hal::wifi_error legacy_status =
711 legacy_hal_.lock()->nanSubscribeCancelRequest(cmd_id, legacy_msg);
712 return createWifiStatusFromLegacyError(legacy_status);
Roshan Pius0c92d442016-10-27 17:38:53 -0700713}
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800714
Roshan Pius0c92d442016-10-27 17:38:53 -0700715WifiStatus WifiNanIface::transmitFollowupRequestInternal(
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800716 uint16_t cmd_id, const NanTransmitFollowupRequest& msg) {
717 legacy_hal::NanTransmitFollowupRequest legacy_msg;
718 if (!hidl_struct_util::convertHidlNanTransmitFollowupRequestToLegacy(msg, &legacy_msg)) {
719 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
720 }
721 legacy_hal::wifi_error legacy_status =
722 legacy_hal_.lock()->nanTransmitFollowupRequest(cmd_id, legacy_msg);
723 return createWifiStatusFromLegacyError(legacy_status);
Roshan Pius0c92d442016-10-27 17:38:53 -0700724}
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800725
726WifiStatus WifiNanIface::createDataInterfaceRequestInternal(
727 uint16_t cmd_id, const std::string& iface_name) {
728 legacy_hal::wifi_error legacy_status =
729 legacy_hal_.lock()->nanDataInterfaceCreate(cmd_id, iface_name);
730 return createWifiStatusFromLegacyError(legacy_status);
731}
732WifiStatus WifiNanIface::deleteDataInterfaceRequestInternal(
733 uint16_t cmd_id, const std::string& iface_name) {
734 legacy_hal::wifi_error legacy_status =
735 legacy_hal_.lock()->nanDataInterfaceDelete(cmd_id, iface_name);
736 return createWifiStatusFromLegacyError(legacy_status);
737}
738WifiStatus WifiNanIface::initiateDataPathRequestInternal(
739 uint16_t cmd_id, const NanInitiateDataPathRequest& msg) {
740 legacy_hal::NanDataPathInitiatorRequest legacy_msg;
741 if (!hidl_struct_util::convertHidlNanDataPathInitiatorRequestToLegacy(msg, &legacy_msg)) {
742 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
743 }
744 legacy_hal::wifi_error legacy_status =
745 legacy_hal_.lock()->nanDataRequestInitiator(cmd_id, legacy_msg);
746 return createWifiStatusFromLegacyError(legacy_status);
747}
748WifiStatus WifiNanIface::respondToDataPathIndicationRequestInternal(
749 uint16_t cmd_id, const NanRespondToDataPathIndicationRequest& msg) {
750 legacy_hal::NanDataPathIndicationResponse legacy_msg;
751 if (!hidl_struct_util::convertHidlNanDataPathIndicationResponseToLegacy(msg, &legacy_msg)) {
752 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
753 }
754 legacy_hal::wifi_error legacy_status =
755 legacy_hal_.lock()->nanDataIndicationResponse(cmd_id, legacy_msg);
756 return createWifiStatusFromLegacyError(legacy_status);
757}
758WifiStatus WifiNanIface::terminateDataPathRequestInternal(
759 uint16_t cmd_id, uint32_t ndpInstanceId) {
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800760 legacy_hal::wifi_error legacy_status =
Etan Cohenc9836f92017-06-30 13:55:21 -0700761 legacy_hal_.lock()->nanDataEnd(cmd_id, ndpInstanceId);
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800762 return createWifiStatusFromLegacyError(legacy_status);
Roshan Pius0c92d442016-10-27 17:38:53 -0700763}
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800764
Roshan Pius3e2d6712016-10-06 13:16:23 -0700765} // namespace implementation
Etan Cohen6ce50902017-09-14 07:30:57 -0700766} // namespace V1_2
Roshan Pius3e2d6712016-10-06 13:16:23 -0700767} // namespace wifi
768} // namespace hardware
769} // namespace android