blob: 0cc6cd5fce1c1463437b9b393490f6cf6b15c509 [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 {
Jimmy Chend460df32019-11-29 17:31:22 +020027namespace V1_5 {
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 :
Nate Jiang3ec67812020-08-24 11:04:31 -0700169 shared_ptr_this->getEventCallbacks_1_5()) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700170 if (!callback
Nate Jiang3ec67812020-08-24 11:04:31 -0700171 ->notifyCapabilitiesResponse_1_5(id, wifiNanStatus,
172 hidl_struct)
Roshan Piusabcf78f2017-10-06 16:30:38 -0700173 .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() {
Nate Jiang674b27a2020-08-26 16:38:19 -0700537 if (!isValid()) {
538 return;
539 }
Roshan Piusabcf78f2017-10-06 16:30:38 -0700540 // send commands to HAL to actually disable and destroy interfaces
541 legacy_hal_.lock()->nanDisableRequest(ifname_, 0xFFFF);
542 legacy_hal_.lock()->nanDataInterfaceDelete(ifname_, 0xFFFE, "aware_data0");
543 legacy_hal_.lock()->nanDataInterfaceDelete(ifname_, 0xFFFD, "aware_data1");
Roshan Pius356d5a62019-05-17 15:07:34 -0700544 iface_util_.lock()->unregisterIfaceEventHandlers(ifname_);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700545 legacy_hal_.reset();
546 event_cb_handler_.invalidate();
Etan Cohen44a8bf92018-04-09 13:32:40 -0700547 event_cb_handler_1_2_.invalidate();
Nate Jiang3ec67812020-08-24 11:04:31 -0700548 event_cb_handler_1_5_.invalidate();
Roshan Piusabcf78f2017-10-06 16:30:38 -0700549 is_valid_ = false;
Roshan Pius5ba0a902020-04-14 11:55:42 -0700550 if (is_dedicated_iface_) {
551 // If using a dedicated iface, set the iface down.
552 iface_util_.lock()->setUpState(ifname_, false);
553 }
Roshan Pius3e2d6712016-10-06 13:16:23 -0700554}
555
Roshan Piusabcf78f2017-10-06 16:30:38 -0700556bool WifiNanIface::isValid() { return is_valid_; }
Roshan Pius907d4a22016-10-27 12:48:12 -0700557
Roshan Pius675609b2017-10-31 14:24:58 -0700558std::string WifiNanIface::getName() { return ifname_; }
559
Etan Cohen44a8bf92018-04-09 13:32:40 -0700560std::set<sp<V1_0::IWifiNanIfaceEventCallback>>
561WifiNanIface::getEventCallbacks() {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700562 return event_cb_handler_.getCallbacks();
Roshan Piusd37341f2017-01-31 13:13:28 -0800563}
564
Etan Cohen44a8bf92018-04-09 13:32:40 -0700565std::set<sp<V1_2::IWifiNanIfaceEventCallback>>
566WifiNanIface::getEventCallbacks_1_2() {
567 return event_cb_handler_1_2_.getCallbacks();
568}
569
Nate Jiang3ec67812020-08-24 11:04:31 -0700570std::set<sp<IWifiNanIfaceEventCallback>> WifiNanIface::getEventCallbacks_1_5() {
571 return event_cb_handler_1_5_.getCallbacks();
572}
573
Roshan Pius734fea02016-10-11 08:30:28 -0700574Return<void> WifiNanIface::getName(getName_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700575 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
576 &WifiNanIface::getNameInternal, hidl_status_cb);
Roshan Pius3e2d6712016-10-06 13:16:23 -0700577}
578
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800579Return<void> WifiNanIface::getType(getType_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700580 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
581 &WifiNanIface::getTypeInternal, hidl_status_cb);
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800582}
583
Roshan Pius0c92d442016-10-27 17:38:53 -0700584Return<void> WifiNanIface::registerEventCallback(
Etan Cohenc7bd0f72017-12-26 11:52:44 -0800585 const sp<V1_0::IWifiNanIfaceEventCallback>& callback,
Roshan Pius0c92d442016-10-27 17:38:53 -0700586 registerEventCallback_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700587 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
588 &WifiNanIface::registerEventCallbackInternal,
589 hidl_status_cb, callback);
Roshan Pius0c92d442016-10-27 17:38:53 -0700590}
591
Roshan Piusabcf78f2017-10-06 16:30:38 -0700592Return<void> WifiNanIface::getCapabilitiesRequest(
593 uint16_t cmd_id, getCapabilitiesRequest_cb hidl_status_cb) {
594 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
595 &WifiNanIface::getCapabilitiesRequestInternal,
596 hidl_status_cb, cmd_id);
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800597}
598
599Return<void> WifiNanIface::enableRequest(uint16_t cmd_id,
Ahmed ElArabawy83baffd2019-11-15 19:20:41 -0800600 const V1_0::NanEnableRequest& msg,
Roshan Pius0c92d442016-10-27 17:38:53 -0700601 enableRequest_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700602 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
603 &WifiNanIface::enableRequestInternal, 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::configRequest(uint16_t cmd_id,
Ahmed ElArabawy83baffd2019-11-15 19:20:41 -0800608 const V1_0::NanConfigRequest& msg,
Roshan Pius0c92d442016-10-27 17:38:53 -0700609 configRequest_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700610 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
611 &WifiNanIface::configRequestInternal, hidl_status_cb,
612 cmd_id, msg);
Roshan Pius0c92d442016-10-27 17:38:53 -0700613}
614
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800615Return<void> WifiNanIface::disableRequest(uint16_t cmd_id,
616 disableRequest_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700617 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
618 &WifiNanIface::disableRequestInternal,
619 hidl_status_cb, cmd_id);
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800620}
621
Roshan Piusabcf78f2017-10-06 16:30:38 -0700622Return<void> WifiNanIface::startPublishRequest(
623 uint16_t cmd_id, const NanPublishRequest& msg,
624 startPublishRequest_cb hidl_status_cb) {
625 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
626 &WifiNanIface::startPublishRequestInternal,
627 hidl_status_cb, cmd_id, msg);
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800628}
629
630Return<void> WifiNanIface::stopPublishRequest(
Roshan Piusabcf78f2017-10-06 16:30:38 -0700631 uint16_t cmd_id, uint8_t sessionId, stopPublishRequest_cb hidl_status_cb) {
632 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
633 &WifiNanIface::stopPublishRequestInternal,
634 hidl_status_cb, cmd_id, sessionId);
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800635}
636
637Return<void> WifiNanIface::startSubscribeRequest(
Roshan Piusabcf78f2017-10-06 16:30:38 -0700638 uint16_t cmd_id, const NanSubscribeRequest& msg,
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800639 startSubscribeRequest_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700640 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
641 &WifiNanIface::startSubscribeRequestInternal,
642 hidl_status_cb, cmd_id, msg);
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800643}
644
645Return<void> WifiNanIface::stopSubscribeRequest(
Roshan Piusabcf78f2017-10-06 16:30:38 -0700646 uint16_t cmd_id, uint8_t sessionId,
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800647 stopSubscribeRequest_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700648 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
649 &WifiNanIface::stopSubscribeRequestInternal,
650 hidl_status_cb, cmd_id, sessionId);
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800651}
652
653Return<void> WifiNanIface::transmitFollowupRequest(
Roshan Piusabcf78f2017-10-06 16:30:38 -0700654 uint16_t cmd_id, const NanTransmitFollowupRequest& msg,
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800655 transmitFollowupRequest_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700656 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
657 &WifiNanIface::transmitFollowupRequestInternal,
658 hidl_status_cb, cmd_id, msg);
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800659}
660
661Return<void> WifiNanIface::createDataInterfaceRequest(
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 createDataInterfaceRequest_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700664 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
665 &WifiNanIface::createDataInterfaceRequestInternal,
666 hidl_status_cb, cmd_id, iface_name);
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800667}
668
669Return<void> WifiNanIface::deleteDataInterfaceRequest(
Roshan Piusabcf78f2017-10-06 16:30:38 -0700670 uint16_t cmd_id, const hidl_string& iface_name,
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800671 deleteDataInterfaceRequest_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700672 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
673 &WifiNanIface::deleteDataInterfaceRequestInternal,
674 hidl_status_cb, cmd_id, iface_name);
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800675}
676
677Return<void> WifiNanIface::initiateDataPathRequest(
Roshan Piusabcf78f2017-10-06 16:30:38 -0700678 uint16_t cmd_id, const NanInitiateDataPathRequest& msg,
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800679 initiateDataPathRequest_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700680 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
681 &WifiNanIface::initiateDataPathRequestInternal,
682 hidl_status_cb, cmd_id, msg);
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800683}
684
685Return<void> WifiNanIface::respondToDataPathIndicationRequest(
Roshan Piusabcf78f2017-10-06 16:30:38 -0700686 uint16_t cmd_id, const NanRespondToDataPathIndicationRequest& msg,
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800687 respondToDataPathIndicationRequest_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700688 return validateAndCall(
689 this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
690 &WifiNanIface::respondToDataPathIndicationRequestInternal,
691 hidl_status_cb, cmd_id, msg);
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800692}
693
Roshan Piusabcf78f2017-10-06 16:30:38 -0700694Return<void> WifiNanIface::terminateDataPathRequest(
695 uint16_t cmd_id, uint32_t ndpInstanceId,
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800696 terminateDataPathRequest_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700697 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
698 &WifiNanIface::terminateDataPathRequestInternal,
699 hidl_status_cb, cmd_id, ndpInstanceId);
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800700}
701
Etan Cohenc7bd0f72017-12-26 11:52:44 -0800702Return<void> WifiNanIface::registerEventCallback_1_2(
Jong Wook Kimda830c92018-07-23 15:29:38 -0700703 const sp<V1_2::IWifiNanIfaceEventCallback>& callback,
Etan Cohenc7bd0f72017-12-26 11:52:44 -0800704 registerEventCallback_1_2_cb hidl_status_cb) {
705 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
706 &WifiNanIface::registerEventCallback_1_2Internal,
707 hidl_status_cb, callback);
708}
709
Etan Cohen9e7a4052017-12-21 13:45:26 -0800710Return<void> WifiNanIface::enableRequest_1_2(
Ahmed ElArabawy83baffd2019-11-15 19:20:41 -0800711 uint16_t cmd_id, const V1_0::NanEnableRequest& msg1,
Jong Wook Kimda830c92018-07-23 15:29:38 -0700712 const V1_2::NanConfigRequestSupplemental& msg2,
Etan Cohen9e7a4052017-12-21 13:45:26 -0800713 enableRequest_1_2_cb hidl_status_cb) {
714 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
715 &WifiNanIface::enableRequest_1_2Internal,
716 hidl_status_cb, cmd_id, msg1, msg2);
717}
718
719Return<void> WifiNanIface::configRequest_1_2(
Ahmed ElArabawy83baffd2019-11-15 19:20:41 -0800720 uint16_t cmd_id, const V1_0::NanConfigRequest& msg1,
Jong Wook Kimda830c92018-07-23 15:29:38 -0700721 const V1_2::NanConfigRequestSupplemental& msg2,
Etan Cohen9e7a4052017-12-21 13:45:26 -0800722 configRequest_1_2_cb hidl_status_cb) {
723 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
724 &WifiNanIface::configRequest_1_2Internal,
725 hidl_status_cb, cmd_id, msg1, msg2);
726}
727
Ahmed ElArabawy83baffd2019-11-15 19:20:41 -0800728Return<void> WifiNanIface::enableRequest_1_4(
Jimmy Chend460df32019-11-29 17:31:22 +0200729 uint16_t cmd_id, const V1_4::NanEnableRequest& msg1,
Ahmed ElArabawy83baffd2019-11-15 19:20:41 -0800730 const V1_2::NanConfigRequestSupplemental& msg2,
731 enableRequest_1_4_cb hidl_status_cb) {
732 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
733 &WifiNanIface::enableRequest_1_4Internal,
734 hidl_status_cb, cmd_id, msg1, msg2);
735}
736
737Return<void> WifiNanIface::configRequest_1_4(
Jimmy Chend460df32019-11-29 17:31:22 +0200738 uint16_t cmd_id, const V1_4::NanConfigRequest& msg1,
Ahmed ElArabawy83baffd2019-11-15 19:20:41 -0800739 const V1_2::NanConfigRequestSupplemental& msg2,
740 configRequest_1_4_cb hidl_status_cb) {
741 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
742 &WifiNanIface::configRequest_1_4Internal,
743 hidl_status_cb, cmd_id, msg1, msg2);
744}
745
Nate Jiang3ec67812020-08-24 11:04:31 -0700746Return<void> WifiNanIface::registerEventCallback_1_5(
747 const sp<IWifiNanIfaceEventCallback>& callback,
748 registerEventCallback_1_5_cb hidl_status_cb) {
749 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
750 &WifiNanIface::registerEventCallback_1_5Internal,
751 hidl_status_cb, callback);
752}
753
754Return<void> WifiNanIface::enableRequest_1_5(
755 uint16_t cmd_id, const V1_4::NanEnableRequest& msg1,
756 const NanConfigRequestSupplemental& msg2,
757 enableRequest_1_5_cb hidl_status_cb) {
758 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
759 &WifiNanIface::enableRequest_1_5Internal,
760 hidl_status_cb, cmd_id, msg1, msg2);
761}
762
763Return<void> WifiNanIface::configRequest_1_5(
764 uint16_t cmd_id, const V1_4::NanConfigRequest& msg1,
765 const NanConfigRequestSupplemental& msg2,
766 configRequest_1_5_cb hidl_status_cb) {
767 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
768 &WifiNanIface::configRequest_1_5Internal,
769 hidl_status_cb, cmd_id, msg1, msg2);
770}
771
772Return<void> WifiNanIface::getCapabilitiesRequest_1_5(
773 uint16_t cmd_id, getCapabilitiesRequest_1_5_cb hidl_status_cb) {
774 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
775 &WifiNanIface::getCapabilitiesRequest_1_5Internal,
776 hidl_status_cb, cmd_id);
777}
778
Roshan Pius907d4a22016-10-27 12:48:12 -0700779std::pair<WifiStatus, std::string> WifiNanIface::getNameInternal() {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700780 return {createWifiStatus(WifiStatusCode::SUCCESS), ifname_};
Roshan Pius907d4a22016-10-27 12:48:12 -0700781}
782
783std::pair<WifiStatus, IfaceType> WifiNanIface::getTypeInternal() {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700784 return {createWifiStatus(WifiStatusCode::SUCCESS), IfaceType::NAN};
Roshan Pius3e2d6712016-10-06 13:16:23 -0700785}
786
Roshan Pius0c92d442016-10-27 17:38:53 -0700787WifiStatus WifiNanIface::registerEventCallbackInternal(
Etan Cohen44a8bf92018-04-09 13:32:40 -0700788 const sp<V1_0::IWifiNanIfaceEventCallback>& callback) {
789 if (!event_cb_handler_.addCallback(callback)) {
790 return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN);
791 }
792 return createWifiStatus(WifiStatusCode::SUCCESS);
Roshan Pius0c92d442016-10-27 17:38:53 -0700793}
794
Nate Jiang3ec67812020-08-24 11:04:31 -0700795WifiStatus WifiNanIface::getCapabilitiesRequestInternal(uint16_t /* cmd_id */) {
796 return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED);
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800797}
798
Etan Cohen9e7a4052017-12-21 13:45:26 -0800799WifiStatus WifiNanIface::enableRequestInternal(
Ahmed ElArabawy83baffd2019-11-15 19:20:41 -0800800 uint16_t /* cmd_id */, const V1_0::NanEnableRequest& /* msg */) {
Etan Cohen9e7a4052017-12-21 13:45:26 -0800801 return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED);
Roshan Pius0c92d442016-10-27 17:38:53 -0700802}
803
Etan Cohen9e7a4052017-12-21 13:45:26 -0800804WifiStatus WifiNanIface::configRequestInternal(
Ahmed ElArabawy83baffd2019-11-15 19:20:41 -0800805 uint16_t /* cmd_id */, const V1_0::NanConfigRequest& /* msg */) {
Etan Cohen9e7a4052017-12-21 13:45:26 -0800806 return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED);
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800807}
808
809WifiStatus WifiNanIface::disableRequestInternal(uint16_t cmd_id) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700810 legacy_hal::wifi_error legacy_status =
811 legacy_hal_.lock()->nanDisableRequest(ifname_, cmd_id);
812 return createWifiStatusFromLegacyError(legacy_status);
Roshan Pius0c92d442016-10-27 17:38:53 -0700813}
814
Roshan Piusacededb2017-10-06 14:59:26 -0700815WifiStatus WifiNanIface::startPublishRequestInternal(
816 uint16_t cmd_id, const NanPublishRequest& msg) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700817 legacy_hal::NanPublishRequest legacy_msg;
818 if (!hidl_struct_util::convertHidlNanPublishRequestToLegacy(msg,
819 &legacy_msg)) {
820 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
821 }
822 legacy_hal::wifi_error legacy_status =
823 legacy_hal_.lock()->nanPublishRequest(ifname_, cmd_id, legacy_msg);
824 return createWifiStatusFromLegacyError(legacy_status);
Roshan Pius0c92d442016-10-27 17:38:53 -0700825}
826
Roshan Piusabcf78f2017-10-06 16:30:38 -0700827WifiStatus WifiNanIface::stopPublishRequestInternal(uint16_t cmd_id,
828 uint8_t sessionId) {
829 legacy_hal::NanPublishCancelRequest legacy_msg;
830 legacy_msg.publish_id = sessionId;
831 legacy_hal::wifi_error legacy_status =
832 legacy_hal_.lock()->nanPublishCancelRequest(ifname_, cmd_id,
833 legacy_msg);
834 return createWifiStatusFromLegacyError(legacy_status);
Roshan Pius0c92d442016-10-27 17:38:53 -0700835}
Roshan Piusf5f51fd2016-12-01 13:54:24 -0800836
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800837WifiStatus WifiNanIface::startSubscribeRequestInternal(
838 uint16_t cmd_id, const NanSubscribeRequest& msg) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700839 legacy_hal::NanSubscribeRequest legacy_msg;
840 if (!hidl_struct_util::convertHidlNanSubscribeRequestToLegacy(
841 msg, &legacy_msg)) {
842 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
843 }
844 legacy_hal::wifi_error legacy_status =
845 legacy_hal_.lock()->nanSubscribeRequest(ifname_, cmd_id, legacy_msg);
846 return createWifiStatusFromLegacyError(legacy_status);
Roshan Pius0c92d442016-10-27 17:38:53 -0700847}
Roshan Piusf5f51fd2016-12-01 13:54:24 -0800848
Roshan Piusabcf78f2017-10-06 16:30:38 -0700849WifiStatus WifiNanIface::stopSubscribeRequestInternal(uint16_t cmd_id,
850 uint8_t sessionId) {
851 legacy_hal::NanSubscribeCancelRequest legacy_msg;
852 legacy_msg.subscribe_id = sessionId;
853 legacy_hal::wifi_error legacy_status =
854 legacy_hal_.lock()->nanSubscribeCancelRequest(ifname_, cmd_id,
855 legacy_msg);
856 return createWifiStatusFromLegacyError(legacy_status);
Roshan Pius0c92d442016-10-27 17:38:53 -0700857}
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800858
Roshan Pius0c92d442016-10-27 17:38:53 -0700859WifiStatus WifiNanIface::transmitFollowupRequestInternal(
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800860 uint16_t cmd_id, const NanTransmitFollowupRequest& msg) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700861 legacy_hal::NanTransmitFollowupRequest legacy_msg;
862 if (!hidl_struct_util::convertHidlNanTransmitFollowupRequestToLegacy(
863 msg, &legacy_msg)) {
864 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
865 }
866 legacy_hal::wifi_error legacy_status =
867 legacy_hal_.lock()->nanTransmitFollowupRequest(ifname_, cmd_id,
868 legacy_msg);
869 return createWifiStatusFromLegacyError(legacy_status);
Roshan Pius0c92d442016-10-27 17:38:53 -0700870}
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800871
872WifiStatus WifiNanIface::createDataInterfaceRequestInternal(
873 uint16_t cmd_id, const std::string& iface_name) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700874 legacy_hal::wifi_error legacy_status =
875 legacy_hal_.lock()->nanDataInterfaceCreate(ifname_, cmd_id, iface_name);
876 return createWifiStatusFromLegacyError(legacy_status);
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800877}
878WifiStatus WifiNanIface::deleteDataInterfaceRequestInternal(
879 uint16_t cmd_id, const std::string& iface_name) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700880 legacy_hal::wifi_error legacy_status =
881 legacy_hal_.lock()->nanDataInterfaceDelete(ifname_, cmd_id, iface_name);
882 return createWifiStatusFromLegacyError(legacy_status);
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800883}
884WifiStatus WifiNanIface::initiateDataPathRequestInternal(
885 uint16_t cmd_id, const NanInitiateDataPathRequest& msg) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700886 legacy_hal::NanDataPathInitiatorRequest legacy_msg;
887 if (!hidl_struct_util::convertHidlNanDataPathInitiatorRequestToLegacy(
888 msg, &legacy_msg)) {
889 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
890 }
891 legacy_hal::wifi_error legacy_status =
892 legacy_hal_.lock()->nanDataRequestInitiator(ifname_, cmd_id,
893 legacy_msg);
894 return createWifiStatusFromLegacyError(legacy_status);
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800895}
896WifiStatus WifiNanIface::respondToDataPathIndicationRequestInternal(
897 uint16_t cmd_id, const NanRespondToDataPathIndicationRequest& msg) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700898 legacy_hal::NanDataPathIndicationResponse legacy_msg;
899 if (!hidl_struct_util::convertHidlNanDataPathIndicationResponseToLegacy(
900 msg, &legacy_msg)) {
901 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
902 }
903 legacy_hal::wifi_error legacy_status =
904 legacy_hal_.lock()->nanDataIndicationResponse(ifname_, cmd_id,
905 legacy_msg);
906 return createWifiStatusFromLegacyError(legacy_status);
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800907}
908WifiStatus WifiNanIface::terminateDataPathRequestInternal(
909 uint16_t cmd_id, uint32_t ndpInstanceId) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700910 legacy_hal::wifi_error legacy_status =
911 legacy_hal_.lock()->nanDataEnd(ifname_, cmd_id, ndpInstanceId);
912 return createWifiStatusFromLegacyError(legacy_status);
Roshan Pius0c92d442016-10-27 17:38:53 -0700913}
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800914
Etan Cohenc7bd0f72017-12-26 11:52:44 -0800915WifiStatus WifiNanIface::registerEventCallback_1_2Internal(
Etan Cohen44a8bf92018-04-09 13:32:40 -0700916 const sp<V1_2::IWifiNanIfaceEventCallback>& callback) {
917 sp<V1_0::IWifiNanIfaceEventCallback> callback_1_0 = callback;
918 if (!event_cb_handler_.addCallback(callback_1_0)) {
919 return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN);
920 }
921 if (!event_cb_handler_1_2_.addCallback(callback)) {
Etan Cohenc7bd0f72017-12-26 11:52:44 -0800922 return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN);
923 }
924 return createWifiStatus(WifiStatusCode::SUCCESS);
925}
926
Etan Cohen9e7a4052017-12-21 13:45:26 -0800927WifiStatus WifiNanIface::enableRequest_1_2Internal(
Ahmed ElArabawy83baffd2019-11-15 19:20:41 -0800928 uint16_t /* cmd_id */, const V1_0::NanEnableRequest& /* msg1 */,
Nate Jiang3ec67812020-08-24 11:04:31 -0700929 const V1_2::NanConfigRequestSupplemental& /* msg2 */) {
Ahmed ElArabawy83baffd2019-11-15 19:20:41 -0800930 return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED);
931}
932
933WifiStatus WifiNanIface::configRequest_1_2Internal(
934 uint16_t /* cmd_id */, const V1_0::NanConfigRequest& /* msg1 */,
935 const V1_2::NanConfigRequestSupplemental& /* msg2 */) {
936 return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED);
937}
938
939WifiStatus WifiNanIface::enableRequest_1_4Internal(
Nate Jiang3ec67812020-08-24 11:04:31 -0700940 uint16_t /* cmd_id */, const V1_4::NanEnableRequest& /* msg1 */,
941 const V1_2::NanConfigRequestSupplemental& /* msg2 */) {
942 return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED);
943}
944
945WifiStatus WifiNanIface::configRequest_1_4Internal(
946 uint16_t /* cmd_id */, const V1_4::NanConfigRequest& /* msg1 */,
947 const V1_2::NanConfigRequestSupplemental& /* msg2 */) {
948 return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED);
949}
950
951WifiStatus WifiNanIface::registerEventCallback_1_5Internal(
952 const sp<IWifiNanIfaceEventCallback>& callback) {
953 sp<V1_0::IWifiNanIfaceEventCallback> callback_1_0 = callback;
954 if (!event_cb_handler_.addCallback(callback_1_0)) {
955 return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN);
956 }
957 sp<V1_2::IWifiNanIfaceEventCallback> callback_1_2 = callback;
958 if (!event_cb_handler_1_2_.addCallback(callback_1_2)) {
959 return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN);
960 }
961 if (!event_cb_handler_1_5_.addCallback(callback)) {
962 return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN);
963 }
964 return createWifiStatus(WifiStatusCode::SUCCESS);
965}
966
967WifiStatus WifiNanIface::getCapabilitiesRequest_1_5Internal(uint16_t cmd_id) {
968 legacy_hal::wifi_error legacy_status =
969 legacy_hal_.lock()->nanGetCapabilities(ifname_, cmd_id);
970 return createWifiStatusFromLegacyError(legacy_status);
971}
972
973WifiStatus WifiNanIface::enableRequest_1_5Internal(
Jimmy Chend460df32019-11-29 17:31:22 +0200974 uint16_t cmd_id, const V1_4::NanEnableRequest& msg1,
Nate Jiang3ec67812020-08-24 11:04:31 -0700975 const NanConfigRequestSupplemental& msg2) {
Etan Cohen9e7a4052017-12-21 13:45:26 -0800976 legacy_hal::NanEnableRequest legacy_msg;
Nate Jiang3ec67812020-08-24 11:04:31 -0700977 if (!hidl_struct_util::convertHidlNanEnableRequest_1_5ToLegacy(
Etan Cohen9e7a4052017-12-21 13:45:26 -0800978 msg1, msg2, &legacy_msg)) {
979 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
980 }
981 legacy_hal::wifi_error legacy_status =
982 legacy_hal_.lock()->nanEnableRequest(ifname_, cmd_id, legacy_msg);
983 return createWifiStatusFromLegacyError(legacy_status);
984}
985
Nate Jiang3ec67812020-08-24 11:04:31 -0700986WifiStatus WifiNanIface::configRequest_1_5Internal(
Jimmy Chend460df32019-11-29 17:31:22 +0200987 uint16_t cmd_id, const V1_4::NanConfigRequest& msg1,
Nate Jiang3ec67812020-08-24 11:04:31 -0700988 const NanConfigRequestSupplemental& msg2) {
Etan Cohen9e7a4052017-12-21 13:45:26 -0800989 legacy_hal::NanConfigRequest legacy_msg;
Nate Jiang3ec67812020-08-24 11:04:31 -0700990 if (!hidl_struct_util::convertHidlNanConfigRequest_1_5ToLegacy(
Etan Cohen9e7a4052017-12-21 13:45:26 -0800991 msg1, msg2, &legacy_msg)) {
992 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
993 }
994 legacy_hal::wifi_error legacy_status =
995 legacy_hal_.lock()->nanConfigRequest(ifname_, cmd_id, legacy_msg);
996 return createWifiStatusFromLegacyError(legacy_status);
997}
998
Roshan Pius3e2d6712016-10-06 13:16:23 -0700999} // namespace implementation
Jimmy Chend460df32019-11-29 17:31:22 +02001000} // namespace V1_5
Roshan Pius3e2d6712016-10-06 13:16:23 -07001001} // namespace wifi
1002} // namespace hardware
1003} // namespace android