blob: 5764d35ec48214c5b885a08f9321e13e6b09af5c [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 {
Ahmed ElArabawyf501a982019-07-23 15:02:22 -070027namespace V1_4 {
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(
Roshan Pius5ba0a902020-04-14 11:55:42 -070032 const std::string& ifname, bool is_dedicated_iface,
Roshan Pius356d5a62019-05-17 15:07:34 -070033 const std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal,
34 const std::weak_ptr<iface_util::WifiIfaceUtil> iface_util)
35 : ifname_(ifname),
Roshan Pius5ba0a902020-04-14 11:55:42 -070036 is_dedicated_iface_(is_dedicated_iface),
Roshan Pius356d5a62019-05-17 15:07:34 -070037 legacy_hal_(legacy_hal),
38 iface_util_(iface_util),
39 is_valid_(true) {
Roshan Pius5ba0a902020-04-14 11:55:42 -070040 if (is_dedicated_iface_) {
41 // If using a dedicated iface, set the iface up first.
42 if (!iface_util_.lock()->setUpState(ifname_, true)) {
43 // Fatal failure, invalidate the iface object.
44 invalidate();
45 return;
46 }
47 }
Roshan Piusabcf78f2017-10-06 16:30:38 -070048 // Register all the callbacks here. these should be valid for the lifetime
49 // of the object. Whenever the mode changes legacy HAL will remove
50 // all of these callbacks.
51 legacy_hal::NanCallbackHandlers callback_handlers;
52 android::wp<WifiNanIface> weak_ptr_this(this);
Roshan Piusf5f51fd2016-12-01 13:54:24 -080053
Roshan Piusabcf78f2017-10-06 16:30:38 -070054 // Callback for response.
55 callback_handlers
56 .on_notify_response = [weak_ptr_this](
57 legacy_hal::transaction_id id,
58 const legacy_hal::NanResponseMsg& msg) {
59 const auto shared_ptr_this = weak_ptr_this.promote();
60 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
61 LOG(ERROR) << "Callback invoked on an invalid object";
Etan Cohenf01bcaa2016-12-25 09:42:21 -080062 return;
63 }
Roshan Piusabcf78f2017-10-06 16:30:38 -070064 WifiNanStatus wifiNanStatus;
65 if (!hidl_struct_util::convertLegacyNanResponseHeaderToHidl(
66 msg, &wifiNanStatus)) {
67 LOG(ERROR) << "Failed to convert nan response header";
68 return;
Etan Cohenf01bcaa2016-12-25 09:42:21 -080069 }
Etan Cohenf01bcaa2016-12-25 09:42:21 -080070
Roshan Piusabcf78f2017-10-06 16:30:38 -070071 switch (msg.response_type) {
72 case legacy_hal::NAN_RESPONSE_ENABLED: {
73 for (const auto& callback :
74 shared_ptr_this->getEventCallbacks()) {
75 if (!callback->notifyEnableResponse(id, wifiNanStatus)
76 .isOk()) {
77 LOG(ERROR) << "Failed to invoke the callback";
78 }
79 }
80 break;
Etan Cohenf01bcaa2016-12-25 09:42:21 -080081 }
Roshan Piusabcf78f2017-10-06 16:30:38 -070082 case legacy_hal::NAN_RESPONSE_DISABLED: {
83 for (const auto& callback :
84 shared_ptr_this->getEventCallbacks()) {
85 if (!callback->notifyDisableResponse(id, wifiNanStatus)
86 .isOk()) {
87 LOG(ERROR) << "Failed to invoke the callback";
88 }
89 }
90 break;
91 }
92 case legacy_hal::NAN_RESPONSE_PUBLISH: {
93 for (const auto& callback :
94 shared_ptr_this->getEventCallbacks()) {
95 if (!callback
96 ->notifyStartPublishResponse(
97 id, wifiNanStatus,
98 msg.body.publish_response.publish_id)
99 .isOk()) {
100 LOG(ERROR) << "Failed to invoke the callback";
101 }
102 }
103 break;
104 }
105 case legacy_hal::NAN_RESPONSE_PUBLISH_CANCEL: {
106 for (const auto& callback :
107 shared_ptr_this->getEventCallbacks()) {
108 if (!callback->notifyStopPublishResponse(id, wifiNanStatus)
109 .isOk()) {
110 LOG(ERROR) << "Failed to invoke the callback";
111 }
112 }
113 break;
114 }
115 case legacy_hal::NAN_RESPONSE_TRANSMIT_FOLLOWUP: {
116 for (const auto& callback :
117 shared_ptr_this->getEventCallbacks()) {
118 if (!callback
119 ->notifyTransmitFollowupResponse(id, wifiNanStatus)
120 .isOk()) {
121 LOG(ERROR) << "Failed to invoke the callback";
122 }
123 }
124 break;
125 }
126 case legacy_hal::NAN_RESPONSE_SUBSCRIBE: {
127 for (const auto& callback :
128 shared_ptr_this->getEventCallbacks()) {
129 if (!callback
130 ->notifyStartSubscribeResponse(
131 id, wifiNanStatus,
132 msg.body.subscribe_response.subscribe_id)
133 .isOk()) {
134 LOG(ERROR) << "Failed to invoke the callback";
135 }
136 }
137 break;
138 }
139 case legacy_hal::NAN_RESPONSE_SUBSCRIBE_CANCEL: {
140 for (const auto& callback :
141 shared_ptr_this->getEventCallbacks()) {
142 if (!callback
143 ->notifyStopSubscribeResponse(id, wifiNanStatus)
144 .isOk()) {
145 LOG(ERROR) << "Failed to invoke the callback";
146 }
147 }
148 break;
149 }
150 case legacy_hal::NAN_RESPONSE_CONFIG: {
151 for (const auto& callback :
152 shared_ptr_this->getEventCallbacks()) {
153 if (!callback->notifyConfigResponse(id, wifiNanStatus)
154 .isOk()) {
155 LOG(ERROR) << "Failed to invoke the callback";
156 }
157 }
158 break;
159 }
160 case legacy_hal::NAN_GET_CAPABILITIES: {
161 NanCapabilities hidl_struct;
162 if (!hidl_struct_util::
163 convertLegacyNanCapabilitiesResponseToHidl(
164 msg.body.nan_capabilities, &hidl_struct)) {
165 LOG(ERROR) << "Failed to convert nan capabilities response";
166 return;
167 }
168 for (const auto& callback :
169 shared_ptr_this->getEventCallbacks()) {
170 if (!callback
171 ->notifyCapabilitiesResponse(id, wifiNanStatus,
172 hidl_struct)
173 .isOk()) {
174 LOG(ERROR) << "Failed to invoke the callback";
175 }
176 }
177 break;
178 }
179 case legacy_hal::NAN_DP_INTERFACE_CREATE: {
180 for (const auto& callback :
181 shared_ptr_this->getEventCallbacks()) {
182 if (!callback
183 ->notifyCreateDataInterfaceResponse(id,
184 wifiNanStatus)
185 .isOk()) {
186 LOG(ERROR) << "Failed to invoke the callback";
187 }
188 }
189 break;
190 }
191 case legacy_hal::NAN_DP_INTERFACE_DELETE: {
192 for (const auto& callback :
193 shared_ptr_this->getEventCallbacks()) {
194 if (!callback
195 ->notifyDeleteDataInterfaceResponse(id,
196 wifiNanStatus)
197 .isOk()) {
198 LOG(ERROR) << "Failed to invoke the callback";
199 }
200 }
201 break;
202 }
203 case legacy_hal::NAN_DP_INITIATOR_RESPONSE: {
204 for (const auto& callback :
205 shared_ptr_this->getEventCallbacks()) {
206 if (!callback
207 ->notifyInitiateDataPathResponse(
208 id, wifiNanStatus,
209 msg.body.data_request_response.ndp_instance_id)
210 .isOk()) {
211 LOG(ERROR) << "Failed to invoke the callback";
212 }
213 }
214 break;
215 }
216 case legacy_hal::NAN_DP_RESPONDER_RESPONSE: {
217 for (const auto& callback :
218 shared_ptr_this->getEventCallbacks()) {
219 if (!callback
220 ->notifyRespondToDataPathIndicationResponse(
221 id, wifiNanStatus)
222 .isOk()) {
223 LOG(ERROR) << "Failed to invoke the callback";
224 }
225 }
226 break;
227 }
228 case legacy_hal::NAN_DP_END: {
229 for (const auto& callback :
230 shared_ptr_this->getEventCallbacks()) {
231 if (!callback
232 ->notifyTerminateDataPathResponse(id,
233 wifiNanStatus)
234 .isOk()) {
235 LOG(ERROR) << "Failed to invoke the callback";
236 }
237 }
238 break;
239 }
240 case legacy_hal::NAN_RESPONSE_BEACON_SDF_PAYLOAD:
241 /* fall through */
242 case legacy_hal::NAN_RESPONSE_TCA:
243 /* fall through */
244 case legacy_hal::NAN_RESPONSE_STATS:
245 /* fall through */
246 case legacy_hal::NAN_RESPONSE_ERROR:
247 /* fall through */
248 default:
249 LOG(ERROR) << "Unknown or unhandled response type: "
250 << msg.response_type;
251 return;
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800252 }
Roshan Piusabcf78f2017-10-06 16:30:38 -0700253 };
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800254
Roshan Piusabcf78f2017-10-06 16:30:38 -0700255 callback_handlers.on_event_disc_eng_event =
256 [weak_ptr_this](const legacy_hal::NanDiscEngEventInd& msg) {
257 const auto shared_ptr_this = weak_ptr_this.promote();
258 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
259 LOG(ERROR) << "Callback invoked on an invalid object";
260 return;
261 }
262 NanClusterEventInd hidl_struct;
263 // event types defined identically - hence can be cast
264 hidl_struct.eventType = (NanClusterEventType)msg.event_type;
265 hidl_struct.addr = msg.data.mac_addr.addr;
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800266
Roshan Piusabcf78f2017-10-06 16:30:38 -0700267 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
268 if (!callback->eventClusterEvent(hidl_struct).isOk()) {
269 LOG(ERROR) << "Failed to invoke the callback";
270 }
271 }
272 };
Etan Cohenc190f932017-02-17 13:06:55 -0800273
Roshan Piusabcf78f2017-10-06 16:30:38 -0700274 callback_handlers.on_event_disabled =
275 [weak_ptr_this](const legacy_hal::NanDisabledInd& msg) {
276 const auto shared_ptr_this = weak_ptr_this.promote();
277 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
278 LOG(ERROR) << "Callback invoked on an invalid object";
279 return;
280 }
281 WifiNanStatus status;
282 hidl_struct_util::convertToWifiNanStatus(
283 msg.reason, msg.nan_reason, sizeof(msg.nan_reason), &status);
Etan Cohenc190f932017-02-17 13:06:55 -0800284
Roshan Piusabcf78f2017-10-06 16:30:38 -0700285 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
286 if (!callback->eventDisabled(status).isOk()) {
287 LOG(ERROR) << "Failed to invoke the callback";
288 }
289 }
290 };
291
292 callback_handlers.on_event_publish_terminated =
293 [weak_ptr_this](const legacy_hal::NanPublishTerminatedInd& msg) {
294 const auto shared_ptr_this = weak_ptr_this.promote();
295 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
296 LOG(ERROR) << "Callback invoked on an invalid object";
297 return;
298 }
299 WifiNanStatus status;
300 hidl_struct_util::convertToWifiNanStatus(
301 msg.reason, msg.nan_reason, sizeof(msg.nan_reason), &status);
302
303 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
304 if (!callback->eventPublishTerminated(msg.publish_id, status)
305 .isOk()) {
306 LOG(ERROR) << "Failed to invoke the callback";
307 }
308 }
309 };
310
311 callback_handlers.on_event_subscribe_terminated =
312 [weak_ptr_this](const legacy_hal::NanSubscribeTerminatedInd& msg) {
313 const auto shared_ptr_this = weak_ptr_this.promote();
314 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
315 LOG(ERROR) << "Callback invoked on an invalid object";
316 return;
317 }
318 WifiNanStatus status;
319 hidl_struct_util::convertToWifiNanStatus(
320 msg.reason, msg.nan_reason, sizeof(msg.nan_reason), &status);
321
322 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
323 if (!callback
324 ->eventSubscribeTerminated(msg.subscribe_id, status)
325 .isOk()) {
326 LOG(ERROR) << "Failed to invoke the callback";
327 }
328 }
329 };
330
331 callback_handlers.on_event_match =
332 [weak_ptr_this](const legacy_hal::NanMatchInd& msg) {
333 const auto shared_ptr_this = weak_ptr_this.promote();
334 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
335 LOG(ERROR) << "Callback invoked on an invalid object";
336 return;
337 }
338 NanMatchInd hidl_struct;
339 if (!hidl_struct_util::convertLegacyNanMatchIndToHidl(
340 msg, &hidl_struct)) {
341 LOG(ERROR) << "Failed to convert nan capabilities response";
342 return;
343 }
344
345 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
346 if (!callback->eventMatch(hidl_struct).isOk()) {
347 LOG(ERROR) << "Failed to invoke the callback";
348 }
349 }
350 };
351
352 callback_handlers.on_event_match_expired =
353 [weak_ptr_this](const legacy_hal::NanMatchExpiredInd& msg) {
354 const auto shared_ptr_this = weak_ptr_this.promote();
355 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
356 LOG(ERROR) << "Callback invoked on an invalid object";
357 return;
358 }
359 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
360 if (!callback
361 ->eventMatchExpired(msg.publish_subscribe_id,
362 msg.requestor_instance_id)
363 .isOk()) {
364 LOG(ERROR) << "Failed to invoke the callback";
365 }
366 }
367 };
368
369 callback_handlers.on_event_followup =
370 [weak_ptr_this](const legacy_hal::NanFollowupInd& msg) {
371 const auto shared_ptr_this = weak_ptr_this.promote();
372 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
373 LOG(ERROR) << "Callback invoked on an invalid object";
374 return;
375 }
376 NanFollowupReceivedInd hidl_struct;
377 if (!hidl_struct_util::convertLegacyNanFollowupIndToHidl(
378 msg, &hidl_struct)) {
379 LOG(ERROR) << "Failed to convert nan capabilities response";
380 return;
381 }
382
383 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
384 if (!callback->eventFollowupReceived(hidl_struct).isOk()) {
385 LOG(ERROR) << "Failed to invoke the callback";
386 }
387 }
388 };
389
390 callback_handlers.on_event_transmit_follow_up =
391 [weak_ptr_this](const legacy_hal::NanTransmitFollowupInd& msg) {
392 const auto shared_ptr_this = weak_ptr_this.promote();
393 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
394 LOG(ERROR) << "Callback invoked on an invalid object";
395 return;
396 }
397 WifiNanStatus status;
398 hidl_struct_util::convertToWifiNanStatus(
399 msg.reason, msg.nan_reason, sizeof(msg.nan_reason), &status);
400
401 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
402 if (!callback->eventTransmitFollowup(msg.id, status).isOk()) {
403 LOG(ERROR) << "Failed to invoke the callback";
404 }
405 }
406 };
407
408 callback_handlers.on_event_data_path_request =
409 [weak_ptr_this](const legacy_hal::NanDataPathRequestInd& msg) {
410 const auto shared_ptr_this = weak_ptr_this.promote();
411 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
412 LOG(ERROR) << "Callback invoked on an invalid object";
413 return;
414 }
415 NanDataPathRequestInd hidl_struct;
416 if (!hidl_struct_util::convertLegacyNanDataPathRequestIndToHidl(
417 msg, &hidl_struct)) {
418 LOG(ERROR) << "Failed to convert nan capabilities response";
419 return;
420 }
421
422 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
423 if (!callback->eventDataPathRequest(hidl_struct).isOk()) {
424 LOG(ERROR) << "Failed to invoke the callback";
425 }
426 }
427 };
428
429 callback_handlers.on_event_data_path_confirm =
430 [weak_ptr_this](const legacy_hal::NanDataPathConfirmInd& msg) {
431 const auto shared_ptr_this = weak_ptr_this.promote();
432 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
433 LOG(ERROR) << "Callback invoked on an invalid object";
434 return;
435 }
Jong Wook Kimda830c92018-07-23 15:29:38 -0700436 V1_2::NanDataPathConfirmInd hidl_struct;
Roshan Piusabcf78f2017-10-06 16:30:38 -0700437 if (!hidl_struct_util::convertLegacyNanDataPathConfirmIndToHidl(
438 msg, &hidl_struct)) {
439 LOG(ERROR) << "Failed to convert nan capabilities response";
440 return;
441 }
442
Etan Cohen44a8bf92018-04-09 13:32:40 -0700443 for (const auto& callback :
444 shared_ptr_this->getEventCallbacks_1_2()) {
Etan Cohenc7bd0f72017-12-26 11:52:44 -0800445 if (!callback->eventDataPathConfirm_1_2(hidl_struct).isOk()) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700446 LOG(ERROR) << "Failed to invoke the callback";
447 }
448 }
449 };
450
451 callback_handlers.on_event_data_path_end =
452 [weak_ptr_this](const legacy_hal::NanDataPathEndInd& msg) {
453 const auto shared_ptr_this = weak_ptr_this.promote();
454 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
455 LOG(ERROR) << "Callback invoked on an invalid object";
456 return;
457 }
458 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
459 for (int i = 0; i < msg.num_ndp_instances; ++i) {
460 if (!callback
461 ->eventDataPathTerminated(msg.ndp_instance_id[i])
462 .isOk()) {
463 LOG(ERROR) << "Failed to invoke the callback";
464 }
465 }
466 }
467 };
468
469 callback_handlers.on_event_beacon_sdf_payload =
470 [weak_ptr_this](const legacy_hal::NanBeaconSdfPayloadInd& /* msg */) {
471 LOG(ERROR) << "on_event_beacon_sdf_payload - should not be called";
472 };
473
474 callback_handlers.on_event_range_request =
475 [weak_ptr_this](const legacy_hal::NanRangeRequestInd& /* msg */) {
476 LOG(ERROR) << "on_event_range_request - should not be called";
477 };
478
479 callback_handlers.on_event_range_report =
480 [weak_ptr_this](const legacy_hal::NanRangeReportInd& /* msg */) {
481 LOG(ERROR) << "on_event_range_report - should not be called";
482 };
483
Etan Cohenc7bd0f72017-12-26 11:52:44 -0800484 callback_handlers
485 .on_event_schedule_update = [weak_ptr_this](
486 const legacy_hal::
487 NanDataPathScheduleUpdateInd& msg) {
488 const auto shared_ptr_this = weak_ptr_this.promote();
489 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
490 LOG(ERROR) << "Callback invoked on an invalid object";
491 return;
492 }
Jong Wook Kimda830c92018-07-23 15:29:38 -0700493 V1_2::NanDataPathScheduleUpdateInd hidl_struct;
Etan Cohenc7bd0f72017-12-26 11:52:44 -0800494 if (!hidl_struct_util::convertLegacyNanDataPathScheduleUpdateIndToHidl(
495 msg, &hidl_struct)) {
496 LOG(ERROR) << "Failed to convert nan capabilities response";
497 return;
498 }
499
Etan Cohen44a8bf92018-04-09 13:32:40 -0700500 for (const auto& callback : shared_ptr_this->getEventCallbacks_1_2()) {
Etan Cohenc7bd0f72017-12-26 11:52:44 -0800501 if (!callback->eventDataPathScheduleUpdate(hidl_struct).isOk()) {
502 LOG(ERROR) << "Failed to invoke the callback";
503 }
504 }
505 };
Etan Cohen1bf15f12017-12-12 16:15:16 -0800506
Roshan Piusabcf78f2017-10-06 16:30:38 -0700507 legacy_hal::wifi_error legacy_status =
508 legacy_hal_.lock()->nanRegisterCallbackHandlers(ifname_,
509 callback_handlers);
510 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
511 LOG(ERROR) << "Failed to register nan callbacks. Invalidating object";
512 invalidate();
513 }
Roshan Pius356d5a62019-05-17 15:07:34 -0700514
515 // Register for iface state toggle events.
516 iface_util::IfaceEventHandlers event_handlers = {};
517 event_handlers.on_state_toggle_off_on =
518 [weak_ptr_this](const std::string& /* iface_name */) {
519 const auto shared_ptr_this = weak_ptr_this.promote();
520 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
521 LOG(ERROR) << "Callback invoked on an invalid object";
522 return;
523 }
524 // Tell framework that NAN has been disabled.
525 WifiNanStatus status = {
526 NanStatusType::UNSUPPORTED_CONCURRENCY_NAN_DISABLED, ""};
527 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
528 if (!callback->eventDisabled(status).isOk()) {
529 LOG(ERROR) << "Failed to invoke the callback";
530 }
531 }
532 };
533 iface_util_.lock()->registerIfaceEventHandlers(ifname_, event_handlers);
Roshan Piusf5f51fd2016-12-01 13:54:24 -0800534}
Roshan Pius3e2d6712016-10-06 13:16:23 -0700535
536void WifiNanIface::invalidate() {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700537 // send commands to HAL to actually disable and destroy interfaces
538 legacy_hal_.lock()->nanDisableRequest(ifname_, 0xFFFF);
539 legacy_hal_.lock()->nanDataInterfaceDelete(ifname_, 0xFFFE, "aware_data0");
540 legacy_hal_.lock()->nanDataInterfaceDelete(ifname_, 0xFFFD, "aware_data1");
Roshan Pius356d5a62019-05-17 15:07:34 -0700541 iface_util_.lock()->unregisterIfaceEventHandlers(ifname_);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700542 legacy_hal_.reset();
543 event_cb_handler_.invalidate();
Etan Cohen44a8bf92018-04-09 13:32:40 -0700544 event_cb_handler_1_2_.invalidate();
Roshan Piusabcf78f2017-10-06 16:30:38 -0700545 is_valid_ = false;
Roshan Pius5ba0a902020-04-14 11:55:42 -0700546 if (is_dedicated_iface_) {
547 // If using a dedicated iface, set the iface down.
548 iface_util_.lock()->setUpState(ifname_, false);
549 }
Roshan Pius3e2d6712016-10-06 13:16:23 -0700550}
551
Roshan Piusabcf78f2017-10-06 16:30:38 -0700552bool WifiNanIface::isValid() { return is_valid_; }
Roshan Pius907d4a22016-10-27 12:48:12 -0700553
Roshan Pius675609b2017-10-31 14:24:58 -0700554std::string WifiNanIface::getName() { return ifname_; }
555
Etan Cohen44a8bf92018-04-09 13:32:40 -0700556std::set<sp<V1_0::IWifiNanIfaceEventCallback>>
557WifiNanIface::getEventCallbacks() {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700558 return event_cb_handler_.getCallbacks();
Roshan Piusd37341f2017-01-31 13:13:28 -0800559}
560
Etan Cohen44a8bf92018-04-09 13:32:40 -0700561std::set<sp<V1_2::IWifiNanIfaceEventCallback>>
562WifiNanIface::getEventCallbacks_1_2() {
563 return event_cb_handler_1_2_.getCallbacks();
564}
565
Roshan Pius734fea02016-10-11 08:30:28 -0700566Return<void> WifiNanIface::getName(getName_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700567 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
568 &WifiNanIface::getNameInternal, hidl_status_cb);
Roshan Pius3e2d6712016-10-06 13:16:23 -0700569}
570
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800571Return<void> WifiNanIface::getType(getType_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700572 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
573 &WifiNanIface::getTypeInternal, hidl_status_cb);
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800574}
575
Roshan Pius0c92d442016-10-27 17:38:53 -0700576Return<void> WifiNanIface::registerEventCallback(
Etan Cohenc7bd0f72017-12-26 11:52:44 -0800577 const sp<V1_0::IWifiNanIfaceEventCallback>& callback,
Roshan Pius0c92d442016-10-27 17:38:53 -0700578 registerEventCallback_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700579 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
580 &WifiNanIface::registerEventCallbackInternal,
581 hidl_status_cb, callback);
Roshan Pius0c92d442016-10-27 17:38:53 -0700582}
583
Roshan Piusabcf78f2017-10-06 16:30:38 -0700584Return<void> WifiNanIface::getCapabilitiesRequest(
585 uint16_t cmd_id, getCapabilitiesRequest_cb hidl_status_cb) {
586 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
587 &WifiNanIface::getCapabilitiesRequestInternal,
588 hidl_status_cb, cmd_id);
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800589}
590
591Return<void> WifiNanIface::enableRequest(uint16_t cmd_id,
Ahmed ElArabawy83baffd2019-11-15 19:20:41 -0800592 const V1_0::NanEnableRequest& msg,
Roshan Pius0c92d442016-10-27 17:38:53 -0700593 enableRequest_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700594 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
595 &WifiNanIface::enableRequestInternal, hidl_status_cb,
596 cmd_id, msg);
Roshan Pius0c92d442016-10-27 17:38:53 -0700597}
598
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800599Return<void> WifiNanIface::configRequest(uint16_t cmd_id,
Ahmed ElArabawy83baffd2019-11-15 19:20:41 -0800600 const V1_0::NanConfigRequest& msg,
Roshan Pius0c92d442016-10-27 17:38:53 -0700601 configRequest_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700602 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
603 &WifiNanIface::configRequestInternal, hidl_status_cb,
604 cmd_id, msg);
Roshan Pius0c92d442016-10-27 17:38:53 -0700605}
606
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800607Return<void> WifiNanIface::disableRequest(uint16_t cmd_id,
608 disableRequest_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700609 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
610 &WifiNanIface::disableRequestInternal,
611 hidl_status_cb, cmd_id);
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800612}
613
Roshan Piusabcf78f2017-10-06 16:30:38 -0700614Return<void> WifiNanIface::startPublishRequest(
615 uint16_t cmd_id, const NanPublishRequest& msg,
616 startPublishRequest_cb hidl_status_cb) {
617 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
618 &WifiNanIface::startPublishRequestInternal,
619 hidl_status_cb, cmd_id, msg);
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800620}
621
622Return<void> WifiNanIface::stopPublishRequest(
Roshan Piusabcf78f2017-10-06 16:30:38 -0700623 uint16_t cmd_id, uint8_t sessionId, stopPublishRequest_cb hidl_status_cb) {
624 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
625 &WifiNanIface::stopPublishRequestInternal,
626 hidl_status_cb, cmd_id, sessionId);
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800627}
628
629Return<void> WifiNanIface::startSubscribeRequest(
Roshan Piusabcf78f2017-10-06 16:30:38 -0700630 uint16_t cmd_id, const NanSubscribeRequest& msg,
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800631 startSubscribeRequest_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700632 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
633 &WifiNanIface::startSubscribeRequestInternal,
634 hidl_status_cb, cmd_id, msg);
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800635}
636
637Return<void> WifiNanIface::stopSubscribeRequest(
Roshan Piusabcf78f2017-10-06 16:30:38 -0700638 uint16_t cmd_id, uint8_t sessionId,
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800639 stopSubscribeRequest_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700640 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
641 &WifiNanIface::stopSubscribeRequestInternal,
642 hidl_status_cb, cmd_id, sessionId);
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800643}
644
645Return<void> WifiNanIface::transmitFollowupRequest(
Roshan Piusabcf78f2017-10-06 16:30:38 -0700646 uint16_t cmd_id, const NanTransmitFollowupRequest& msg,
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800647 transmitFollowupRequest_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700648 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
649 &WifiNanIface::transmitFollowupRequestInternal,
650 hidl_status_cb, cmd_id, msg);
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800651}
652
653Return<void> WifiNanIface::createDataInterfaceRequest(
Roshan Piusabcf78f2017-10-06 16:30:38 -0700654 uint16_t cmd_id, const hidl_string& iface_name,
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800655 createDataInterfaceRequest_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700656 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
657 &WifiNanIface::createDataInterfaceRequestInternal,
658 hidl_status_cb, cmd_id, iface_name);
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800659}
660
661Return<void> WifiNanIface::deleteDataInterfaceRequest(
Roshan Piusabcf78f2017-10-06 16:30:38 -0700662 uint16_t cmd_id, const hidl_string& iface_name,
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800663 deleteDataInterfaceRequest_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700664 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
665 &WifiNanIface::deleteDataInterfaceRequestInternal,
666 hidl_status_cb, cmd_id, iface_name);
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800667}
668
669Return<void> WifiNanIface::initiateDataPathRequest(
Roshan Piusabcf78f2017-10-06 16:30:38 -0700670 uint16_t cmd_id, const NanInitiateDataPathRequest& msg,
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800671 initiateDataPathRequest_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700672 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
673 &WifiNanIface::initiateDataPathRequestInternal,
674 hidl_status_cb, cmd_id, msg);
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800675}
676
677Return<void> WifiNanIface::respondToDataPathIndicationRequest(
Roshan Piusabcf78f2017-10-06 16:30:38 -0700678 uint16_t cmd_id, const NanRespondToDataPathIndicationRequest& msg,
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800679 respondToDataPathIndicationRequest_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700680 return validateAndCall(
681 this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
682 &WifiNanIface::respondToDataPathIndicationRequestInternal,
683 hidl_status_cb, cmd_id, msg);
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800684}
685
Roshan Piusabcf78f2017-10-06 16:30:38 -0700686Return<void> WifiNanIface::terminateDataPathRequest(
687 uint16_t cmd_id, uint32_t ndpInstanceId,
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800688 terminateDataPathRequest_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700689 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
690 &WifiNanIface::terminateDataPathRequestInternal,
691 hidl_status_cb, cmd_id, ndpInstanceId);
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800692}
693
Etan Cohenc7bd0f72017-12-26 11:52:44 -0800694Return<void> WifiNanIface::registerEventCallback_1_2(
Jong Wook Kimda830c92018-07-23 15:29:38 -0700695 const sp<V1_2::IWifiNanIfaceEventCallback>& callback,
Etan Cohenc7bd0f72017-12-26 11:52:44 -0800696 registerEventCallback_1_2_cb hidl_status_cb) {
697 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
698 &WifiNanIface::registerEventCallback_1_2Internal,
699 hidl_status_cb, callback);
700}
701
Etan Cohen9e7a4052017-12-21 13:45:26 -0800702Return<void> WifiNanIface::enableRequest_1_2(
Ahmed ElArabawy83baffd2019-11-15 19:20:41 -0800703 uint16_t cmd_id, const V1_0::NanEnableRequest& msg1,
Jong Wook Kimda830c92018-07-23 15:29:38 -0700704 const V1_2::NanConfigRequestSupplemental& msg2,
Etan Cohen9e7a4052017-12-21 13:45:26 -0800705 enableRequest_1_2_cb hidl_status_cb) {
706 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
707 &WifiNanIface::enableRequest_1_2Internal,
708 hidl_status_cb, cmd_id, msg1, msg2);
709}
710
711Return<void> WifiNanIface::configRequest_1_2(
Ahmed ElArabawy83baffd2019-11-15 19:20:41 -0800712 uint16_t cmd_id, const V1_0::NanConfigRequest& msg1,
Jong Wook Kimda830c92018-07-23 15:29:38 -0700713 const V1_2::NanConfigRequestSupplemental& msg2,
Etan Cohen9e7a4052017-12-21 13:45:26 -0800714 configRequest_1_2_cb hidl_status_cb) {
715 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
716 &WifiNanIface::configRequest_1_2Internal,
717 hidl_status_cb, cmd_id, msg1, msg2);
718}
719
Ahmed ElArabawy83baffd2019-11-15 19:20:41 -0800720Return<void> WifiNanIface::enableRequest_1_4(
721 uint16_t cmd_id, const NanEnableRequest& msg1,
722 const V1_2::NanConfigRequestSupplemental& msg2,
723 enableRequest_1_4_cb hidl_status_cb) {
724 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
725 &WifiNanIface::enableRequest_1_4Internal,
726 hidl_status_cb, cmd_id, msg1, msg2);
727}
728
729Return<void> WifiNanIface::configRequest_1_4(
730 uint16_t cmd_id, const NanConfigRequest& msg1,
731 const V1_2::NanConfigRequestSupplemental& msg2,
732 configRequest_1_4_cb hidl_status_cb) {
733 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
734 &WifiNanIface::configRequest_1_4Internal,
735 hidl_status_cb, cmd_id, msg1, msg2);
736}
737
Roshan Pius907d4a22016-10-27 12:48:12 -0700738std::pair<WifiStatus, std::string> WifiNanIface::getNameInternal() {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700739 return {createWifiStatus(WifiStatusCode::SUCCESS), ifname_};
Roshan Pius907d4a22016-10-27 12:48:12 -0700740}
741
742std::pair<WifiStatus, IfaceType> WifiNanIface::getTypeInternal() {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700743 return {createWifiStatus(WifiStatusCode::SUCCESS), IfaceType::NAN};
Roshan Pius3e2d6712016-10-06 13:16:23 -0700744}
745
Roshan Pius0c92d442016-10-27 17:38:53 -0700746WifiStatus WifiNanIface::registerEventCallbackInternal(
Etan Cohen44a8bf92018-04-09 13:32:40 -0700747 const sp<V1_0::IWifiNanIfaceEventCallback>& callback) {
748 if (!event_cb_handler_.addCallback(callback)) {
749 return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN);
750 }
751 return createWifiStatus(WifiStatusCode::SUCCESS);
Roshan Pius0c92d442016-10-27 17:38:53 -0700752}
753
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800754WifiStatus WifiNanIface::getCapabilitiesRequestInternal(uint16_t cmd_id) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700755 legacy_hal::wifi_error legacy_status =
Roshan Piusacededb2017-10-06 14:59:26 -0700756 legacy_hal_.lock()->nanGetCapabilities(ifname_, cmd_id);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700757 return createWifiStatusFromLegacyError(legacy_status);
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800758}
759
Etan Cohen9e7a4052017-12-21 13:45:26 -0800760WifiStatus WifiNanIface::enableRequestInternal(
Ahmed ElArabawy83baffd2019-11-15 19:20:41 -0800761 uint16_t /* cmd_id */, const V1_0::NanEnableRequest& /* msg */) {
Etan Cohen9e7a4052017-12-21 13:45:26 -0800762 return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED);
Roshan Pius0c92d442016-10-27 17:38:53 -0700763}
764
Etan Cohen9e7a4052017-12-21 13:45:26 -0800765WifiStatus WifiNanIface::configRequestInternal(
Ahmed ElArabawy83baffd2019-11-15 19:20:41 -0800766 uint16_t /* cmd_id */, const V1_0::NanConfigRequest& /* msg */) {
Etan Cohen9e7a4052017-12-21 13:45:26 -0800767 return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED);
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800768}
769
770WifiStatus WifiNanIface::disableRequestInternal(uint16_t cmd_id) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700771 legacy_hal::wifi_error legacy_status =
772 legacy_hal_.lock()->nanDisableRequest(ifname_, cmd_id);
773 return createWifiStatusFromLegacyError(legacy_status);
Roshan Pius0c92d442016-10-27 17:38:53 -0700774}
775
Roshan Piusacededb2017-10-06 14:59:26 -0700776WifiStatus WifiNanIface::startPublishRequestInternal(
777 uint16_t cmd_id, const NanPublishRequest& msg) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700778 legacy_hal::NanPublishRequest legacy_msg;
779 if (!hidl_struct_util::convertHidlNanPublishRequestToLegacy(msg,
780 &legacy_msg)) {
781 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
782 }
783 legacy_hal::wifi_error legacy_status =
784 legacy_hal_.lock()->nanPublishRequest(ifname_, cmd_id, legacy_msg);
785 return createWifiStatusFromLegacyError(legacy_status);
Roshan Pius0c92d442016-10-27 17:38:53 -0700786}
787
Roshan Piusabcf78f2017-10-06 16:30:38 -0700788WifiStatus WifiNanIface::stopPublishRequestInternal(uint16_t cmd_id,
789 uint8_t sessionId) {
790 legacy_hal::NanPublishCancelRequest legacy_msg;
791 legacy_msg.publish_id = sessionId;
792 legacy_hal::wifi_error legacy_status =
793 legacy_hal_.lock()->nanPublishCancelRequest(ifname_, cmd_id,
794 legacy_msg);
795 return createWifiStatusFromLegacyError(legacy_status);
Roshan Pius0c92d442016-10-27 17:38:53 -0700796}
Roshan Piusf5f51fd2016-12-01 13:54:24 -0800797
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800798WifiStatus WifiNanIface::startSubscribeRequestInternal(
799 uint16_t cmd_id, const NanSubscribeRequest& msg) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700800 legacy_hal::NanSubscribeRequest legacy_msg;
801 if (!hidl_struct_util::convertHidlNanSubscribeRequestToLegacy(
802 msg, &legacy_msg)) {
803 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
804 }
805 legacy_hal::wifi_error legacy_status =
806 legacy_hal_.lock()->nanSubscribeRequest(ifname_, cmd_id, legacy_msg);
807 return createWifiStatusFromLegacyError(legacy_status);
Roshan Pius0c92d442016-10-27 17:38:53 -0700808}
Roshan Piusf5f51fd2016-12-01 13:54:24 -0800809
Roshan Piusabcf78f2017-10-06 16:30:38 -0700810WifiStatus WifiNanIface::stopSubscribeRequestInternal(uint16_t cmd_id,
811 uint8_t sessionId) {
812 legacy_hal::NanSubscribeCancelRequest legacy_msg;
813 legacy_msg.subscribe_id = sessionId;
814 legacy_hal::wifi_error legacy_status =
815 legacy_hal_.lock()->nanSubscribeCancelRequest(ifname_, cmd_id,
816 legacy_msg);
817 return createWifiStatusFromLegacyError(legacy_status);
Roshan Pius0c92d442016-10-27 17:38:53 -0700818}
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800819
Roshan Pius0c92d442016-10-27 17:38:53 -0700820WifiStatus WifiNanIface::transmitFollowupRequestInternal(
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800821 uint16_t cmd_id, const NanTransmitFollowupRequest& msg) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700822 legacy_hal::NanTransmitFollowupRequest legacy_msg;
823 if (!hidl_struct_util::convertHidlNanTransmitFollowupRequestToLegacy(
824 msg, &legacy_msg)) {
825 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
826 }
827 legacy_hal::wifi_error legacy_status =
828 legacy_hal_.lock()->nanTransmitFollowupRequest(ifname_, cmd_id,
829 legacy_msg);
830 return createWifiStatusFromLegacyError(legacy_status);
Roshan Pius0c92d442016-10-27 17:38:53 -0700831}
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800832
833WifiStatus WifiNanIface::createDataInterfaceRequestInternal(
834 uint16_t cmd_id, const std::string& iface_name) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700835 legacy_hal::wifi_error legacy_status =
836 legacy_hal_.lock()->nanDataInterfaceCreate(ifname_, cmd_id, iface_name);
837 return createWifiStatusFromLegacyError(legacy_status);
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800838}
839WifiStatus WifiNanIface::deleteDataInterfaceRequestInternal(
840 uint16_t cmd_id, const std::string& iface_name) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700841 legacy_hal::wifi_error legacy_status =
842 legacy_hal_.lock()->nanDataInterfaceDelete(ifname_, cmd_id, iface_name);
843 return createWifiStatusFromLegacyError(legacy_status);
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800844}
845WifiStatus WifiNanIface::initiateDataPathRequestInternal(
846 uint16_t cmd_id, const NanInitiateDataPathRequest& msg) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700847 legacy_hal::NanDataPathInitiatorRequest legacy_msg;
848 if (!hidl_struct_util::convertHidlNanDataPathInitiatorRequestToLegacy(
849 msg, &legacy_msg)) {
850 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
851 }
852 legacy_hal::wifi_error legacy_status =
853 legacy_hal_.lock()->nanDataRequestInitiator(ifname_, cmd_id,
854 legacy_msg);
855 return createWifiStatusFromLegacyError(legacy_status);
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800856}
857WifiStatus WifiNanIface::respondToDataPathIndicationRequestInternal(
858 uint16_t cmd_id, const NanRespondToDataPathIndicationRequest& msg) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700859 legacy_hal::NanDataPathIndicationResponse legacy_msg;
860 if (!hidl_struct_util::convertHidlNanDataPathIndicationResponseToLegacy(
861 msg, &legacy_msg)) {
862 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
863 }
864 legacy_hal::wifi_error legacy_status =
865 legacy_hal_.lock()->nanDataIndicationResponse(ifname_, cmd_id,
866 legacy_msg);
867 return createWifiStatusFromLegacyError(legacy_status);
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800868}
869WifiStatus WifiNanIface::terminateDataPathRequestInternal(
870 uint16_t cmd_id, uint32_t ndpInstanceId) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700871 legacy_hal::wifi_error legacy_status =
872 legacy_hal_.lock()->nanDataEnd(ifname_, cmd_id, ndpInstanceId);
873 return createWifiStatusFromLegacyError(legacy_status);
Roshan Pius0c92d442016-10-27 17:38:53 -0700874}
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800875
Etan Cohenc7bd0f72017-12-26 11:52:44 -0800876WifiStatus WifiNanIface::registerEventCallback_1_2Internal(
Etan Cohen44a8bf92018-04-09 13:32:40 -0700877 const sp<V1_2::IWifiNanIfaceEventCallback>& callback) {
878 sp<V1_0::IWifiNanIfaceEventCallback> callback_1_0 = callback;
879 if (!event_cb_handler_.addCallback(callback_1_0)) {
880 return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN);
881 }
882 if (!event_cb_handler_1_2_.addCallback(callback)) {
Etan Cohenc7bd0f72017-12-26 11:52:44 -0800883 return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN);
884 }
885 return createWifiStatus(WifiStatusCode::SUCCESS);
886}
887
Etan Cohen9e7a4052017-12-21 13:45:26 -0800888WifiStatus WifiNanIface::enableRequest_1_2Internal(
Ahmed ElArabawy83baffd2019-11-15 19:20:41 -0800889 uint16_t /* cmd_id */, const V1_0::NanEnableRequest& /* msg1 */,
890 const V1_2::NanConfigRequestSupplemental& /*msg2 */) {
891 return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED);
892}
893
894WifiStatus WifiNanIface::configRequest_1_2Internal(
895 uint16_t /* cmd_id */, const V1_0::NanConfigRequest& /* msg1 */,
896 const V1_2::NanConfigRequestSupplemental& /* msg2 */) {
897 return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED);
898}
899
900WifiStatus WifiNanIface::enableRequest_1_4Internal(
Etan Cohen9e7a4052017-12-21 13:45:26 -0800901 uint16_t cmd_id, const NanEnableRequest& msg1,
Jong Wook Kimda830c92018-07-23 15:29:38 -0700902 const V1_2::NanConfigRequestSupplemental& msg2) {
Etan Cohen9e7a4052017-12-21 13:45:26 -0800903 legacy_hal::NanEnableRequest legacy_msg;
Ahmed ElArabawy83baffd2019-11-15 19:20:41 -0800904 if (!hidl_struct_util::convertHidlNanEnableRequest_1_4ToLegacy(
Etan Cohen9e7a4052017-12-21 13:45:26 -0800905 msg1, msg2, &legacy_msg)) {
906 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
907 }
908 legacy_hal::wifi_error legacy_status =
909 legacy_hal_.lock()->nanEnableRequest(ifname_, cmd_id, legacy_msg);
910 return createWifiStatusFromLegacyError(legacy_status);
911}
912
Ahmed ElArabawy83baffd2019-11-15 19:20:41 -0800913WifiStatus WifiNanIface::configRequest_1_4Internal(
Etan Cohen9e7a4052017-12-21 13:45:26 -0800914 uint16_t cmd_id, const NanConfigRequest& msg1,
Jong Wook Kimda830c92018-07-23 15:29:38 -0700915 const V1_2::NanConfigRequestSupplemental& msg2) {
Etan Cohen9e7a4052017-12-21 13:45:26 -0800916 legacy_hal::NanConfigRequest legacy_msg;
Ahmed ElArabawy83baffd2019-11-15 19:20:41 -0800917 if (!hidl_struct_util::convertHidlNanConfigRequest_1_4ToLegacy(
Etan Cohen9e7a4052017-12-21 13:45:26 -0800918 msg1, msg2, &legacy_msg)) {
919 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
920 }
921 legacy_hal::wifi_error legacy_status =
922 legacy_hal_.lock()->nanConfigRequest(ifname_, cmd_id, legacy_msg);
923 return createWifiStatusFromLegacyError(legacy_status);
924}
925
Roshan Pius3e2d6712016-10-06 13:16:23 -0700926} // namespace implementation
Ahmed ElArabawyf501a982019-07-23 15:02:22 -0700927} // namespace V1_4
Roshan Pius3e2d6712016-10-06 13:16:23 -0700928} // namespace wifi
929} // namespace hardware
930} // namespace android