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