blob: e7bbfaaae3d73c577e1b768f48cd8340e5de52cb [file] [log] [blame]
Roshan Pius3e2d6712016-10-06 13:16:23 -07001/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Roshan Pius3e2d6712016-10-06 13:16:23 -070017#include <android-base/logging.h>
18
Roshan Pius907d4a22016-10-27 12:48:12 -070019#include "hidl_return_util.h"
Roshan Piusf5f51fd2016-12-01 13:54:24 -080020#include "hidl_struct_util.h"
Roshan Pius907d4a22016-10-27 12:48:12 -070021#include "wifi_nan_iface.h"
Roshan Pius734fea02016-10-11 08:30:28 -070022#include "wifi_status_util.h"
Roshan Pius3e2d6712016-10-06 13:16:23 -070023
24namespace android {
25namespace hardware {
26namespace wifi {
Etan Cohen6ce50902017-09-14 07:30:57 -070027namespace V1_2 {
Roshan Pius3e2d6712016-10-06 13:16:23 -070028namespace implementation {
Roshan Pius907d4a22016-10-27 12:48:12 -070029using hidl_return_util::validateAndCall;
Roshan Pius3e2d6712016-10-06 13:16:23 -070030
Roshan Pius6cedc972016-10-28 10:11:17 -070031WifiNanIface::WifiNanIface(
32 const std::string& ifname,
33 const std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal)
Roshan Piusf5f51fd2016-12-01 13:54:24 -080034 : ifname_(ifname), legacy_hal_(legacy_hal), is_valid_(true) {
Roshan Piusabcf78f2017-10-06 16:30:38 -070035 // 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);
Roshan Piusf5f51fd2016-12-01 13:54:24 -080040
Roshan Piusabcf78f2017-10-06 16:30:38 -070041 // 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";
Etan Cohenf01bcaa2016-12-25 09:42:21 -080049 return;
50 }
Roshan Piusabcf78f2017-10-06 16:30:38 -070051 WifiNanStatus wifiNanStatus;
52 if (!hidl_struct_util::convertLegacyNanResponseHeaderToHidl(
53 msg, &wifiNanStatus)) {
54 LOG(ERROR) << "Failed to convert nan response header";
55 return;
Etan Cohenf01bcaa2016-12-25 09:42:21 -080056 }
Etan Cohenf01bcaa2016-12-25 09:42:21 -080057
Roshan Piusabcf78f2017-10-06 16:30:38 -070058 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;
Etan Cohenf01bcaa2016-12-25 09:42:21 -080068 }
Roshan Piusabcf78f2017-10-06 16:30:38 -070069 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;
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800239 }
Roshan Piusabcf78f2017-10-06 16:30:38 -0700240 };
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800241
Roshan Piusabcf78f2017-10-06 16:30:38 -0700242 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;
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800253
Roshan Piusabcf78f2017-10-06 16:30:38 -0700254 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 };
Etan Cohenc190f932017-02-17 13:06:55 -0800260
Roshan Piusabcf78f2017-10-06 16:30:38 -0700261 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);
Etan Cohenc190f932017-02-17 13:06:55 -0800271
Roshan Piusabcf78f2017-10-06 16:30:38 -0700272 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 : shared_ptr_this->getEventCallbacks()) {
431 if (!callback->eventDataPathConfirm(hidl_struct).isOk()) {
432 LOG(ERROR) << "Failed to invoke the callback";
433 }
434 }
435 };
436
437 callback_handlers.on_event_data_path_end =
438 [weak_ptr_this](const legacy_hal::NanDataPathEndInd& msg) {
439 const auto shared_ptr_this = weak_ptr_this.promote();
440 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
441 LOG(ERROR) << "Callback invoked on an invalid object";
442 return;
443 }
444 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
445 for (int i = 0; i < msg.num_ndp_instances; ++i) {
446 if (!callback
447 ->eventDataPathTerminated(msg.ndp_instance_id[i])
448 .isOk()) {
449 LOG(ERROR) << "Failed to invoke the callback";
450 }
451 }
452 }
453 };
454
455 callback_handlers.on_event_beacon_sdf_payload =
456 [weak_ptr_this](const legacy_hal::NanBeaconSdfPayloadInd& /* msg */) {
457 LOG(ERROR) << "on_event_beacon_sdf_payload - should not be called";
458 };
459
460 callback_handlers.on_event_range_request =
461 [weak_ptr_this](const legacy_hal::NanRangeRequestInd& /* msg */) {
462 LOG(ERROR) << "on_event_range_request - should not be called";
463 };
464
465 callback_handlers.on_event_range_report =
466 [weak_ptr_this](const legacy_hal::NanRangeReportInd& /* msg */) {
467 LOG(ERROR) << "on_event_range_report - should not be called";
468 };
469
Etan Cohen1bf15f12017-12-12 16:15:16 -0800470 callback_handlers.on_event_schedule_update =
471 [weak_ptr_this](const legacy_hal::NanDataPathScheduleUpdateInd& /* msg */) {
472 LOG(ERROR) << "on_event_schedule_update - should not be called";
473 };
474
Roshan Piusabcf78f2017-10-06 16:30:38 -0700475 legacy_hal::wifi_error legacy_status =
476 legacy_hal_.lock()->nanRegisterCallbackHandlers(ifname_,
477 callback_handlers);
478 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
479 LOG(ERROR) << "Failed to register nan callbacks. Invalidating object";
480 invalidate();
481 }
Roshan Piusf5f51fd2016-12-01 13:54:24 -0800482}
Roshan Pius3e2d6712016-10-06 13:16:23 -0700483
484void WifiNanIface::invalidate() {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700485 // send commands to HAL to actually disable and destroy interfaces
486 legacy_hal_.lock()->nanDisableRequest(ifname_, 0xFFFF);
487 legacy_hal_.lock()->nanDataInterfaceDelete(ifname_, 0xFFFE, "aware_data0");
488 legacy_hal_.lock()->nanDataInterfaceDelete(ifname_, 0xFFFD, "aware_data1");
Etan Cohenc4d9f872017-06-15 08:39:23 -0700489
Roshan Piusabcf78f2017-10-06 16:30:38 -0700490 legacy_hal_.reset();
491 event_cb_handler_.invalidate();
492 is_valid_ = false;
Roshan Pius3e2d6712016-10-06 13:16:23 -0700493}
494
Roshan Piusabcf78f2017-10-06 16:30:38 -0700495bool WifiNanIface::isValid() { return is_valid_; }
Roshan Pius907d4a22016-10-27 12:48:12 -0700496
Roshan Piusd37341f2017-01-31 13:13:28 -0800497std::set<sp<IWifiNanIfaceEventCallback>> WifiNanIface::getEventCallbacks() {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700498 return event_cb_handler_.getCallbacks();
Roshan Piusd37341f2017-01-31 13:13:28 -0800499}
500
Roshan Pius734fea02016-10-11 08:30:28 -0700501Return<void> WifiNanIface::getName(getName_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700502 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
503 &WifiNanIface::getNameInternal, hidl_status_cb);
Roshan Pius3e2d6712016-10-06 13:16:23 -0700504}
505
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800506Return<void> WifiNanIface::getType(getType_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700507 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
508 &WifiNanIface::getTypeInternal, hidl_status_cb);
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800509}
510
Roshan Pius0c92d442016-10-27 17:38:53 -0700511Return<void> WifiNanIface::registerEventCallback(
512 const sp<IWifiNanIfaceEventCallback>& callback,
513 registerEventCallback_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700514 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
515 &WifiNanIface::registerEventCallbackInternal,
516 hidl_status_cb, callback);
Roshan Pius0c92d442016-10-27 17:38:53 -0700517}
518
Roshan Piusabcf78f2017-10-06 16:30:38 -0700519Return<void> WifiNanIface::getCapabilitiesRequest(
520 uint16_t cmd_id, getCapabilitiesRequest_cb hidl_status_cb) {
521 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
522 &WifiNanIface::getCapabilitiesRequestInternal,
523 hidl_status_cb, cmd_id);
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800524}
525
526Return<void> WifiNanIface::enableRequest(uint16_t cmd_id,
Roshan Pius0c92d442016-10-27 17:38:53 -0700527 const NanEnableRequest& msg,
528 enableRequest_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700529 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
530 &WifiNanIface::enableRequestInternal, hidl_status_cb,
531 cmd_id, msg);
Roshan Pius0c92d442016-10-27 17:38:53 -0700532}
533
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800534Return<void> WifiNanIface::configRequest(uint16_t cmd_id,
Roshan Pius0c92d442016-10-27 17:38:53 -0700535 const NanConfigRequest& msg,
536 configRequest_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700537 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
538 &WifiNanIface::configRequestInternal, hidl_status_cb,
539 cmd_id, msg);
Roshan Pius0c92d442016-10-27 17:38:53 -0700540}
541
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800542Return<void> WifiNanIface::disableRequest(uint16_t cmd_id,
543 disableRequest_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700544 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
545 &WifiNanIface::disableRequestInternal,
546 hidl_status_cb, cmd_id);
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800547}
548
Roshan Piusabcf78f2017-10-06 16:30:38 -0700549Return<void> WifiNanIface::startPublishRequest(
550 uint16_t cmd_id, const NanPublishRequest& msg,
551 startPublishRequest_cb hidl_status_cb) {
552 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
553 &WifiNanIface::startPublishRequestInternal,
554 hidl_status_cb, cmd_id, msg);
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800555}
556
557Return<void> WifiNanIface::stopPublishRequest(
Roshan Piusabcf78f2017-10-06 16:30:38 -0700558 uint16_t cmd_id, uint8_t sessionId, stopPublishRequest_cb hidl_status_cb) {
559 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
560 &WifiNanIface::stopPublishRequestInternal,
561 hidl_status_cb, cmd_id, sessionId);
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800562}
563
564Return<void> WifiNanIface::startSubscribeRequest(
Roshan Piusabcf78f2017-10-06 16:30:38 -0700565 uint16_t cmd_id, const NanSubscribeRequest& msg,
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800566 startSubscribeRequest_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700567 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
568 &WifiNanIface::startSubscribeRequestInternal,
569 hidl_status_cb, cmd_id, msg);
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800570}
571
572Return<void> WifiNanIface::stopSubscribeRequest(
Roshan Piusabcf78f2017-10-06 16:30:38 -0700573 uint16_t cmd_id, uint8_t sessionId,
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800574 stopSubscribeRequest_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700575 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
576 &WifiNanIface::stopSubscribeRequestInternal,
577 hidl_status_cb, cmd_id, sessionId);
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800578}
579
580Return<void> WifiNanIface::transmitFollowupRequest(
Roshan Piusabcf78f2017-10-06 16:30:38 -0700581 uint16_t cmd_id, const NanTransmitFollowupRequest& msg,
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800582 transmitFollowupRequest_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700583 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
584 &WifiNanIface::transmitFollowupRequestInternal,
585 hidl_status_cb, cmd_id, msg);
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800586}
587
588Return<void> WifiNanIface::createDataInterfaceRequest(
Roshan Piusabcf78f2017-10-06 16:30:38 -0700589 uint16_t cmd_id, const hidl_string& iface_name,
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800590 createDataInterfaceRequest_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700591 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
592 &WifiNanIface::createDataInterfaceRequestInternal,
593 hidl_status_cb, cmd_id, iface_name);
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800594}
595
596Return<void> WifiNanIface::deleteDataInterfaceRequest(
Roshan Piusabcf78f2017-10-06 16:30:38 -0700597 uint16_t cmd_id, const hidl_string& iface_name,
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800598 deleteDataInterfaceRequest_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700599 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
600 &WifiNanIface::deleteDataInterfaceRequestInternal,
601 hidl_status_cb, cmd_id, iface_name);
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800602}
603
604Return<void> WifiNanIface::initiateDataPathRequest(
Roshan Piusabcf78f2017-10-06 16:30:38 -0700605 uint16_t cmd_id, const NanInitiateDataPathRequest& msg,
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800606 initiateDataPathRequest_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700607 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
608 &WifiNanIface::initiateDataPathRequestInternal,
609 hidl_status_cb, cmd_id, msg);
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800610}
611
612Return<void> WifiNanIface::respondToDataPathIndicationRequest(
Roshan Piusabcf78f2017-10-06 16:30:38 -0700613 uint16_t cmd_id, const NanRespondToDataPathIndicationRequest& msg,
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800614 respondToDataPathIndicationRequest_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700615 return validateAndCall(
616 this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
617 &WifiNanIface::respondToDataPathIndicationRequestInternal,
618 hidl_status_cb, cmd_id, msg);
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800619}
620
Roshan Piusabcf78f2017-10-06 16:30:38 -0700621Return<void> WifiNanIface::terminateDataPathRequest(
622 uint16_t cmd_id, uint32_t ndpInstanceId,
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800623 terminateDataPathRequest_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700624 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
625 &WifiNanIface::terminateDataPathRequestInternal,
626 hidl_status_cb, cmd_id, ndpInstanceId);
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800627}
628
Roshan Pius907d4a22016-10-27 12:48:12 -0700629std::pair<WifiStatus, std::string> WifiNanIface::getNameInternal() {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700630 return {createWifiStatus(WifiStatusCode::SUCCESS), ifname_};
Roshan Pius907d4a22016-10-27 12:48:12 -0700631}
632
633std::pair<WifiStatus, IfaceType> WifiNanIface::getTypeInternal() {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700634 return {createWifiStatus(WifiStatusCode::SUCCESS), IfaceType::NAN};
Roshan Pius3e2d6712016-10-06 13:16:23 -0700635}
636
Roshan Pius0c92d442016-10-27 17:38:53 -0700637WifiStatus WifiNanIface::registerEventCallbackInternal(
638 const sp<IWifiNanIfaceEventCallback>& callback) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700639 if (!event_cb_handler_.addCallback(callback)) {
640 return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN);
641 }
642 return createWifiStatus(WifiStatusCode::SUCCESS);
Roshan Pius0c92d442016-10-27 17:38:53 -0700643}
644
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800645WifiStatus WifiNanIface::getCapabilitiesRequestInternal(uint16_t cmd_id) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700646 legacy_hal::wifi_error legacy_status =
Roshan Piusacededb2017-10-06 14:59:26 -0700647 legacy_hal_.lock()->nanGetCapabilities(ifname_, cmd_id);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700648 return createWifiStatusFromLegacyError(legacy_status);
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800649}
650
651WifiStatus WifiNanIface::enableRequestInternal(uint16_t cmd_id,
Roshan Piusf5f51fd2016-12-01 13:54:24 -0800652 const NanEnableRequest& msg) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700653 legacy_hal::NanEnableRequest legacy_msg;
654 if (!hidl_struct_util::convertHidlNanEnableRequestToLegacy(msg,
655 &legacy_msg)) {
656 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
657 }
658 legacy_hal::wifi_error legacy_status =
659 legacy_hal_.lock()->nanEnableRequest(ifname_, cmd_id, legacy_msg);
660 return createWifiStatusFromLegacyError(legacy_status);
Roshan Pius0c92d442016-10-27 17:38:53 -0700661}
662
Roshan Piusabcf78f2017-10-06 16:30:38 -0700663WifiStatus WifiNanIface::configRequestInternal(uint16_t cmd_id,
664 const NanConfigRequest& msg) {
665 legacy_hal::NanConfigRequest legacy_msg;
666 if (!hidl_struct_util::convertHidlNanConfigRequestToLegacy(msg,
667 &legacy_msg)) {
668 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
669 }
670 legacy_hal::wifi_error legacy_status =
671 legacy_hal_.lock()->nanConfigRequest(ifname_, cmd_id, legacy_msg);
672 return createWifiStatusFromLegacyError(legacy_status);
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800673}
674
675WifiStatus WifiNanIface::disableRequestInternal(uint16_t cmd_id) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700676 legacy_hal::wifi_error legacy_status =
677 legacy_hal_.lock()->nanDisableRequest(ifname_, cmd_id);
678 return createWifiStatusFromLegacyError(legacy_status);
Roshan Pius0c92d442016-10-27 17:38:53 -0700679}
680
Roshan Piusacededb2017-10-06 14:59:26 -0700681WifiStatus WifiNanIface::startPublishRequestInternal(
682 uint16_t cmd_id, const NanPublishRequest& msg) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700683 legacy_hal::NanPublishRequest legacy_msg;
684 if (!hidl_struct_util::convertHidlNanPublishRequestToLegacy(msg,
685 &legacy_msg)) {
686 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
687 }
688 legacy_hal::wifi_error legacy_status =
689 legacy_hal_.lock()->nanPublishRequest(ifname_, cmd_id, legacy_msg);
690 return createWifiStatusFromLegacyError(legacy_status);
Roshan Pius0c92d442016-10-27 17:38:53 -0700691}
692
Roshan Piusabcf78f2017-10-06 16:30:38 -0700693WifiStatus WifiNanIface::stopPublishRequestInternal(uint16_t cmd_id,
694 uint8_t sessionId) {
695 legacy_hal::NanPublishCancelRequest legacy_msg;
696 legacy_msg.publish_id = sessionId;
697 legacy_hal::wifi_error legacy_status =
698 legacy_hal_.lock()->nanPublishCancelRequest(ifname_, cmd_id,
699 legacy_msg);
700 return createWifiStatusFromLegacyError(legacy_status);
Roshan Pius0c92d442016-10-27 17:38:53 -0700701}
Roshan Piusf5f51fd2016-12-01 13:54:24 -0800702
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800703WifiStatus WifiNanIface::startSubscribeRequestInternal(
704 uint16_t cmd_id, const NanSubscribeRequest& msg) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700705 legacy_hal::NanSubscribeRequest legacy_msg;
706 if (!hidl_struct_util::convertHidlNanSubscribeRequestToLegacy(
707 msg, &legacy_msg)) {
708 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
709 }
710 legacy_hal::wifi_error legacy_status =
711 legacy_hal_.lock()->nanSubscribeRequest(ifname_, cmd_id, legacy_msg);
712 return createWifiStatusFromLegacyError(legacy_status);
Roshan Pius0c92d442016-10-27 17:38:53 -0700713}
Roshan Piusf5f51fd2016-12-01 13:54:24 -0800714
Roshan Piusabcf78f2017-10-06 16:30:38 -0700715WifiStatus WifiNanIface::stopSubscribeRequestInternal(uint16_t cmd_id,
716 uint8_t sessionId) {
717 legacy_hal::NanSubscribeCancelRequest legacy_msg;
718 legacy_msg.subscribe_id = sessionId;
719 legacy_hal::wifi_error legacy_status =
720 legacy_hal_.lock()->nanSubscribeCancelRequest(ifname_, cmd_id,
721 legacy_msg);
722 return createWifiStatusFromLegacyError(legacy_status);
Roshan Pius0c92d442016-10-27 17:38:53 -0700723}
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800724
Roshan Pius0c92d442016-10-27 17:38:53 -0700725WifiStatus WifiNanIface::transmitFollowupRequestInternal(
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800726 uint16_t cmd_id, const NanTransmitFollowupRequest& msg) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700727 legacy_hal::NanTransmitFollowupRequest legacy_msg;
728 if (!hidl_struct_util::convertHidlNanTransmitFollowupRequestToLegacy(
729 msg, &legacy_msg)) {
730 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
731 }
732 legacy_hal::wifi_error legacy_status =
733 legacy_hal_.lock()->nanTransmitFollowupRequest(ifname_, cmd_id,
734 legacy_msg);
735 return createWifiStatusFromLegacyError(legacy_status);
Roshan Pius0c92d442016-10-27 17:38:53 -0700736}
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800737
738WifiStatus WifiNanIface::createDataInterfaceRequestInternal(
739 uint16_t cmd_id, const std::string& iface_name) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700740 legacy_hal::wifi_error legacy_status =
741 legacy_hal_.lock()->nanDataInterfaceCreate(ifname_, cmd_id, iface_name);
742 return createWifiStatusFromLegacyError(legacy_status);
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800743}
744WifiStatus WifiNanIface::deleteDataInterfaceRequestInternal(
745 uint16_t cmd_id, const std::string& iface_name) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700746 legacy_hal::wifi_error legacy_status =
747 legacy_hal_.lock()->nanDataInterfaceDelete(ifname_, cmd_id, iface_name);
748 return createWifiStatusFromLegacyError(legacy_status);
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800749}
750WifiStatus WifiNanIface::initiateDataPathRequestInternal(
751 uint16_t cmd_id, const NanInitiateDataPathRequest& msg) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700752 legacy_hal::NanDataPathInitiatorRequest legacy_msg;
753 if (!hidl_struct_util::convertHidlNanDataPathInitiatorRequestToLegacy(
754 msg, &legacy_msg)) {
755 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
756 }
757 legacy_hal::wifi_error legacy_status =
758 legacy_hal_.lock()->nanDataRequestInitiator(ifname_, cmd_id,
759 legacy_msg);
760 return createWifiStatusFromLegacyError(legacy_status);
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800761}
762WifiStatus WifiNanIface::respondToDataPathIndicationRequestInternal(
763 uint16_t cmd_id, const NanRespondToDataPathIndicationRequest& msg) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700764 legacy_hal::NanDataPathIndicationResponse legacy_msg;
765 if (!hidl_struct_util::convertHidlNanDataPathIndicationResponseToLegacy(
766 msg, &legacy_msg)) {
767 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
768 }
769 legacy_hal::wifi_error legacy_status =
770 legacy_hal_.lock()->nanDataIndicationResponse(ifname_, cmd_id,
771 legacy_msg);
772 return createWifiStatusFromLegacyError(legacy_status);
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800773}
774WifiStatus WifiNanIface::terminateDataPathRequestInternal(
775 uint16_t cmd_id, uint32_t ndpInstanceId) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700776 legacy_hal::wifi_error legacy_status =
777 legacy_hal_.lock()->nanDataEnd(ifname_, cmd_id, ndpInstanceId);
778 return createWifiStatusFromLegacyError(legacy_status);
Roshan Pius0c92d442016-10-27 17:38:53 -0700779}
Etan Cohenf01bcaa2016-12-25 09:42:21 -0800780
Roshan Pius3e2d6712016-10-06 13:16:23 -0700781} // namespace implementation
Etan Cohen6ce50902017-09-14 07:30:57 -0700782} // namespace V1_2
Roshan Pius3e2d6712016-10-06 13:16:23 -0700783} // namespace wifi
784} // namespace hardware
785} // namespace android