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