1 /*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
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
24 namespace android {
25 namespace hardware {
26 namespace wifi {
27 namespace V1_4 {
28 namespace implementation {
29 using hidl_return_util::validateAndCall;
30
WifiNanIface(const std::string & ifname,bool is_dedicated_iface,const std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal,const std::weak_ptr<iface_util::WifiIfaceUtil> iface_util)31 WifiNanIface::WifiNanIface(
32 const std::string& ifname, bool is_dedicated_iface,
33 const std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal,
34 const std::weak_ptr<iface_util::WifiIfaceUtil> iface_util)
35 : ifname_(ifname),
36 is_dedicated_iface_(is_dedicated_iface),
37 legacy_hal_(legacy_hal),
38 iface_util_(iface_util),
39 is_valid_(true) {
40 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 }
48 // 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);
53
54 // 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";
62 return;
63 }
64 WifiNanStatus wifiNanStatus;
65 if (!hidl_struct_util::convertLegacyNanResponseHeaderToHidl(
66 msg, &wifiNanStatus)) {
67 LOG(ERROR) << "Failed to convert nan response header";
68 return;
69 }
70
71 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;
81 }
82 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;
252 }
253 };
254
255 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;
266
267 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 };
273
274 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);
284
285 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 }
436 V1_2::NanDataPathConfirmInd hidl_struct;
437 if (!hidl_struct_util::convertLegacyNanDataPathConfirmIndToHidl(
438 msg, &hidl_struct)) {
439 LOG(ERROR) << "Failed to convert nan capabilities response";
440 return;
441 }
442
443 for (const auto& callback :
444 shared_ptr_this->getEventCallbacks_1_2()) {
445 if (!callback->eventDataPathConfirm_1_2(hidl_struct).isOk()) {
446 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
484 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 }
493 V1_2::NanDataPathScheduleUpdateInd hidl_struct;
494 if (!hidl_struct_util::convertLegacyNanDataPathScheduleUpdateIndToHidl(
495 msg, &hidl_struct)) {
496 LOG(ERROR) << "Failed to convert nan capabilities response";
497 return;
498 }
499
500 for (const auto& callback : shared_ptr_this->getEventCallbacks_1_2()) {
501 if (!callback->eventDataPathScheduleUpdate(hidl_struct).isOk()) {
502 LOG(ERROR) << "Failed to invoke the callback";
503 }
504 }
505 };
506
507 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 }
514
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);
534 }
535
invalidate()536 void WifiNanIface::invalidate() {
537 // 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");
541 iface_util_.lock()->unregisterIfaceEventHandlers(ifname_);
542 legacy_hal_.reset();
543 event_cb_handler_.invalidate();
544 event_cb_handler_1_2_.invalidate();
545 is_valid_ = false;
546 if (is_dedicated_iface_) {
547 // If using a dedicated iface, set the iface down.
548 iface_util_.lock()->setUpState(ifname_, false);
549 }
550 }
551
isValid()552 bool WifiNanIface::isValid() { return is_valid_; }
553
getName()554 std::string WifiNanIface::getName() { return ifname_; }
555
556 std::set<sp<V1_0::IWifiNanIfaceEventCallback>>
getEventCallbacks()557 WifiNanIface::getEventCallbacks() {
558 return event_cb_handler_.getCallbacks();
559 }
560
561 std::set<sp<V1_2::IWifiNanIfaceEventCallback>>
getEventCallbacks_1_2()562 WifiNanIface::getEventCallbacks_1_2() {
563 return event_cb_handler_1_2_.getCallbacks();
564 }
565
getName(getName_cb hidl_status_cb)566 Return<void> WifiNanIface::getName(getName_cb hidl_status_cb) {
567 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
568 &WifiNanIface::getNameInternal, hidl_status_cb);
569 }
570
getType(getType_cb hidl_status_cb)571 Return<void> WifiNanIface::getType(getType_cb hidl_status_cb) {
572 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
573 &WifiNanIface::getTypeInternal, hidl_status_cb);
574 }
575
registerEventCallback(const sp<V1_0::IWifiNanIfaceEventCallback> & callback,registerEventCallback_cb hidl_status_cb)576 Return<void> WifiNanIface::registerEventCallback(
577 const sp<V1_0::IWifiNanIfaceEventCallback>& callback,
578 registerEventCallback_cb hidl_status_cb) {
579 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
580 &WifiNanIface::registerEventCallbackInternal,
581 hidl_status_cb, callback);
582 }
583
getCapabilitiesRequest(uint16_t cmd_id,getCapabilitiesRequest_cb hidl_status_cb)584 Return<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);
589 }
590
enableRequest(uint16_t cmd_id,const V1_0::NanEnableRequest & msg,enableRequest_cb hidl_status_cb)591 Return<void> WifiNanIface::enableRequest(uint16_t cmd_id,
592 const V1_0::NanEnableRequest& msg,
593 enableRequest_cb hidl_status_cb) {
594 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
595 &WifiNanIface::enableRequestInternal, hidl_status_cb,
596 cmd_id, msg);
597 }
598
configRequest(uint16_t cmd_id,const V1_0::NanConfigRequest & msg,configRequest_cb hidl_status_cb)599 Return<void> WifiNanIface::configRequest(uint16_t cmd_id,
600 const V1_0::NanConfigRequest& msg,
601 configRequest_cb hidl_status_cb) {
602 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
603 &WifiNanIface::configRequestInternal, hidl_status_cb,
604 cmd_id, msg);
605 }
606
disableRequest(uint16_t cmd_id,disableRequest_cb hidl_status_cb)607 Return<void> WifiNanIface::disableRequest(uint16_t cmd_id,
608 disableRequest_cb hidl_status_cb) {
609 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
610 &WifiNanIface::disableRequestInternal,
611 hidl_status_cb, cmd_id);
612 }
613
startPublishRequest(uint16_t cmd_id,const NanPublishRequest & msg,startPublishRequest_cb hidl_status_cb)614 Return<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);
620 }
621
stopPublishRequest(uint16_t cmd_id,uint8_t sessionId,stopPublishRequest_cb hidl_status_cb)622 Return<void> WifiNanIface::stopPublishRequest(
623 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);
627 }
628
startSubscribeRequest(uint16_t cmd_id,const NanSubscribeRequest & msg,startSubscribeRequest_cb hidl_status_cb)629 Return<void> WifiNanIface::startSubscribeRequest(
630 uint16_t cmd_id, const NanSubscribeRequest& msg,
631 startSubscribeRequest_cb hidl_status_cb) {
632 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
633 &WifiNanIface::startSubscribeRequestInternal,
634 hidl_status_cb, cmd_id, msg);
635 }
636
stopSubscribeRequest(uint16_t cmd_id,uint8_t sessionId,stopSubscribeRequest_cb hidl_status_cb)637 Return<void> WifiNanIface::stopSubscribeRequest(
638 uint16_t cmd_id, uint8_t sessionId,
639 stopSubscribeRequest_cb hidl_status_cb) {
640 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
641 &WifiNanIface::stopSubscribeRequestInternal,
642 hidl_status_cb, cmd_id, sessionId);
643 }
644
transmitFollowupRequest(uint16_t cmd_id,const NanTransmitFollowupRequest & msg,transmitFollowupRequest_cb hidl_status_cb)645 Return<void> WifiNanIface::transmitFollowupRequest(
646 uint16_t cmd_id, const NanTransmitFollowupRequest& msg,
647 transmitFollowupRequest_cb hidl_status_cb) {
648 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
649 &WifiNanIface::transmitFollowupRequestInternal,
650 hidl_status_cb, cmd_id, msg);
651 }
652
createDataInterfaceRequest(uint16_t cmd_id,const hidl_string & iface_name,createDataInterfaceRequest_cb hidl_status_cb)653 Return<void> WifiNanIface::createDataInterfaceRequest(
654 uint16_t cmd_id, const hidl_string& iface_name,
655 createDataInterfaceRequest_cb hidl_status_cb) {
656 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
657 &WifiNanIface::createDataInterfaceRequestInternal,
658 hidl_status_cb, cmd_id, iface_name);
659 }
660
deleteDataInterfaceRequest(uint16_t cmd_id,const hidl_string & iface_name,deleteDataInterfaceRequest_cb hidl_status_cb)661 Return<void> WifiNanIface::deleteDataInterfaceRequest(
662 uint16_t cmd_id, const hidl_string& iface_name,
663 deleteDataInterfaceRequest_cb hidl_status_cb) {
664 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
665 &WifiNanIface::deleteDataInterfaceRequestInternal,
666 hidl_status_cb, cmd_id, iface_name);
667 }
668
initiateDataPathRequest(uint16_t cmd_id,const NanInitiateDataPathRequest & msg,initiateDataPathRequest_cb hidl_status_cb)669 Return<void> WifiNanIface::initiateDataPathRequest(
670 uint16_t cmd_id, const NanInitiateDataPathRequest& msg,
671 initiateDataPathRequest_cb hidl_status_cb) {
672 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
673 &WifiNanIface::initiateDataPathRequestInternal,
674 hidl_status_cb, cmd_id, msg);
675 }
676
respondToDataPathIndicationRequest(uint16_t cmd_id,const NanRespondToDataPathIndicationRequest & msg,respondToDataPathIndicationRequest_cb hidl_status_cb)677 Return<void> WifiNanIface::respondToDataPathIndicationRequest(
678 uint16_t cmd_id, const NanRespondToDataPathIndicationRequest& msg,
679 respondToDataPathIndicationRequest_cb hidl_status_cb) {
680 return validateAndCall(
681 this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
682 &WifiNanIface::respondToDataPathIndicationRequestInternal,
683 hidl_status_cb, cmd_id, msg);
684 }
685
terminateDataPathRequest(uint16_t cmd_id,uint32_t ndpInstanceId,terminateDataPathRequest_cb hidl_status_cb)686 Return<void> WifiNanIface::terminateDataPathRequest(
687 uint16_t cmd_id, uint32_t ndpInstanceId,
688 terminateDataPathRequest_cb hidl_status_cb) {
689 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
690 &WifiNanIface::terminateDataPathRequestInternal,
691 hidl_status_cb, cmd_id, ndpInstanceId);
692 }
693
registerEventCallback_1_2(const sp<V1_2::IWifiNanIfaceEventCallback> & callback,registerEventCallback_1_2_cb hidl_status_cb)694 Return<void> WifiNanIface::registerEventCallback_1_2(
695 const sp<V1_2::IWifiNanIfaceEventCallback>& callback,
696 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
enableRequest_1_2(uint16_t cmd_id,const V1_0::NanEnableRequest & msg1,const V1_2::NanConfigRequestSupplemental & msg2,enableRequest_1_2_cb hidl_status_cb)702 Return<void> WifiNanIface::enableRequest_1_2(
703 uint16_t cmd_id, const V1_0::NanEnableRequest& msg1,
704 const V1_2::NanConfigRequestSupplemental& msg2,
705 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
configRequest_1_2(uint16_t cmd_id,const V1_0::NanConfigRequest & msg1,const V1_2::NanConfigRequestSupplemental & msg2,configRequest_1_2_cb hidl_status_cb)711 Return<void> WifiNanIface::configRequest_1_2(
712 uint16_t cmd_id, const V1_0::NanConfigRequest& msg1,
713 const V1_2::NanConfigRequestSupplemental& msg2,
714 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
enableRequest_1_4(uint16_t cmd_id,const NanEnableRequest & msg1,const V1_2::NanConfigRequestSupplemental & msg2,enableRequest_1_4_cb hidl_status_cb)720 Return<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
configRequest_1_4(uint16_t cmd_id,const NanConfigRequest & msg1,const V1_2::NanConfigRequestSupplemental & msg2,configRequest_1_4_cb hidl_status_cb)729 Return<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
getNameInternal()738 std::pair<WifiStatus, std::string> WifiNanIface::getNameInternal() {
739 return {createWifiStatus(WifiStatusCode::SUCCESS), ifname_};
740 }
741
getTypeInternal()742 std::pair<WifiStatus, IfaceType> WifiNanIface::getTypeInternal() {
743 return {createWifiStatus(WifiStatusCode::SUCCESS), IfaceType::NAN};
744 }
745
registerEventCallbackInternal(const sp<V1_0::IWifiNanIfaceEventCallback> & callback)746 WifiStatus WifiNanIface::registerEventCallbackInternal(
747 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);
752 }
753
getCapabilitiesRequestInternal(uint16_t cmd_id)754 WifiStatus WifiNanIface::getCapabilitiesRequestInternal(uint16_t cmd_id) {
755 legacy_hal::wifi_error legacy_status =
756 legacy_hal_.lock()->nanGetCapabilities(ifname_, cmd_id);
757 return createWifiStatusFromLegacyError(legacy_status);
758 }
759
enableRequestInternal(uint16_t,const V1_0::NanEnableRequest &)760 WifiStatus WifiNanIface::enableRequestInternal(
761 uint16_t /* cmd_id */, const V1_0::NanEnableRequest& /* msg */) {
762 return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED);
763 }
764
configRequestInternal(uint16_t,const V1_0::NanConfigRequest &)765 WifiStatus WifiNanIface::configRequestInternal(
766 uint16_t /* cmd_id */, const V1_0::NanConfigRequest& /* msg */) {
767 return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED);
768 }
769
disableRequestInternal(uint16_t cmd_id)770 WifiStatus WifiNanIface::disableRequestInternal(uint16_t cmd_id) {
771 legacy_hal::wifi_error legacy_status =
772 legacy_hal_.lock()->nanDisableRequest(ifname_, cmd_id);
773 return createWifiStatusFromLegacyError(legacy_status);
774 }
775
startPublishRequestInternal(uint16_t cmd_id,const NanPublishRequest & msg)776 WifiStatus WifiNanIface::startPublishRequestInternal(
777 uint16_t cmd_id, const NanPublishRequest& msg) {
778 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);
786 }
787
stopPublishRequestInternal(uint16_t cmd_id,uint8_t sessionId)788 WifiStatus 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);
796 }
797
startSubscribeRequestInternal(uint16_t cmd_id,const NanSubscribeRequest & msg)798 WifiStatus WifiNanIface::startSubscribeRequestInternal(
799 uint16_t cmd_id, const NanSubscribeRequest& msg) {
800 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);
808 }
809
stopSubscribeRequestInternal(uint16_t cmd_id,uint8_t sessionId)810 WifiStatus 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);
818 }
819
transmitFollowupRequestInternal(uint16_t cmd_id,const NanTransmitFollowupRequest & msg)820 WifiStatus WifiNanIface::transmitFollowupRequestInternal(
821 uint16_t cmd_id, const NanTransmitFollowupRequest& msg) {
822 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);
831 }
832
createDataInterfaceRequestInternal(uint16_t cmd_id,const std::string & iface_name)833 WifiStatus WifiNanIface::createDataInterfaceRequestInternal(
834 uint16_t cmd_id, const std::string& iface_name) {
835 legacy_hal::wifi_error legacy_status =
836 legacy_hal_.lock()->nanDataInterfaceCreate(ifname_, cmd_id, iface_name);
837 return createWifiStatusFromLegacyError(legacy_status);
838 }
deleteDataInterfaceRequestInternal(uint16_t cmd_id,const std::string & iface_name)839 WifiStatus WifiNanIface::deleteDataInterfaceRequestInternal(
840 uint16_t cmd_id, const std::string& iface_name) {
841 legacy_hal::wifi_error legacy_status =
842 legacy_hal_.lock()->nanDataInterfaceDelete(ifname_, cmd_id, iface_name);
843 return createWifiStatusFromLegacyError(legacy_status);
844 }
initiateDataPathRequestInternal(uint16_t cmd_id,const NanInitiateDataPathRequest & msg)845 WifiStatus WifiNanIface::initiateDataPathRequestInternal(
846 uint16_t cmd_id, const NanInitiateDataPathRequest& msg) {
847 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);
856 }
respondToDataPathIndicationRequestInternal(uint16_t cmd_id,const NanRespondToDataPathIndicationRequest & msg)857 WifiStatus WifiNanIface::respondToDataPathIndicationRequestInternal(
858 uint16_t cmd_id, const NanRespondToDataPathIndicationRequest& msg) {
859 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);
868 }
terminateDataPathRequestInternal(uint16_t cmd_id,uint32_t ndpInstanceId)869 WifiStatus WifiNanIface::terminateDataPathRequestInternal(
870 uint16_t cmd_id, uint32_t ndpInstanceId) {
871 legacy_hal::wifi_error legacy_status =
872 legacy_hal_.lock()->nanDataEnd(ifname_, cmd_id, ndpInstanceId);
873 return createWifiStatusFromLegacyError(legacy_status);
874 }
875
registerEventCallback_1_2Internal(const sp<V1_2::IWifiNanIfaceEventCallback> & callback)876 WifiStatus WifiNanIface::registerEventCallback_1_2Internal(
877 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)) {
883 return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN);
884 }
885 return createWifiStatus(WifiStatusCode::SUCCESS);
886 }
887
enableRequest_1_2Internal(uint16_t,const V1_0::NanEnableRequest &,const V1_2::NanConfigRequestSupplemental &)888 WifiStatus WifiNanIface::enableRequest_1_2Internal(
889 uint16_t /* cmd_id */, const V1_0::NanEnableRequest& /* msg1 */,
890 const V1_2::NanConfigRequestSupplemental& /*msg2 */) {
891 return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED);
892 }
893
configRequest_1_2Internal(uint16_t,const V1_0::NanConfigRequest &,const V1_2::NanConfigRequestSupplemental &)894 WifiStatus 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
enableRequest_1_4Internal(uint16_t cmd_id,const NanEnableRequest & msg1,const V1_2::NanConfigRequestSupplemental & msg2)900 WifiStatus WifiNanIface::enableRequest_1_4Internal(
901 uint16_t cmd_id, const NanEnableRequest& msg1,
902 const V1_2::NanConfigRequestSupplemental& msg2) {
903 legacy_hal::NanEnableRequest legacy_msg;
904 if (!hidl_struct_util::convertHidlNanEnableRequest_1_4ToLegacy(
905 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
configRequest_1_4Internal(uint16_t cmd_id,const NanConfigRequest & msg1,const V1_2::NanConfigRequestSupplemental & msg2)913 WifiStatus WifiNanIface::configRequest_1_4Internal(
914 uint16_t cmd_id, const NanConfigRequest& msg1,
915 const V1_2::NanConfigRequestSupplemental& msg2) {
916 legacy_hal::NanConfigRequest legacy_msg;
917 if (!hidl_struct_util::convertHidlNanConfigRequest_1_4ToLegacy(
918 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
926 } // namespace implementation
927 } // namespace V1_4
928 } // namespace wifi
929 } // namespace hardware
930 } // namespace android
931