1 /* 2 * Copyright (C) 2022 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 package com.android.server.wifi.hal; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.net.MacAddress; 22 import android.net.wifi.aware.AwarePairingConfig; 23 import android.net.wifi.aware.ConfigRequest; 24 import android.net.wifi.aware.PublishConfig; 25 import android.net.wifi.aware.SubscribeConfig; 26 import android.net.wifi.aware.WifiAwareChannelInfo; 27 import android.net.wifi.aware.WifiAwareDataPathSecurityConfig; 28 import android.util.Log; 29 30 import com.android.internal.annotations.VisibleForTesting; 31 import com.android.server.wifi.aware.Capabilities; 32 import com.android.server.wifi.aware.PairingConfigManager; 33 34 import java.util.ArrayList; 35 import java.util.List; 36 import java.util.function.Supplier; 37 38 /** 39 * Wrapper class for IWifiNanIface HAL calls. 40 */ 41 public class WifiNanIface implements WifiHal.WifiInterface { 42 private static final String TAG = "WifiNanIface"; 43 private IWifiNanIface mWifiNanIface; 44 45 @VisibleForTesting 46 static final String SERVICE_NAME_FOR_OOB_DATA_PATH = "Wi-Fi Aware Data Path"; 47 48 /** 49 * Event types for a cluster event indication. 50 */ 51 public static class NanClusterEventType { 52 public static final int DISCOVERY_MAC_ADDRESS_CHANGED = 0; 53 public static final int STARTED_CLUSTER = 1; 54 public static final int JOINED_CLUSTER = 2; 55 56 /** 57 * Convert NanClusterEventType from HIDL to framework. 58 */ fromHidl(int code)59 public static int fromHidl(int code) { 60 switch (code) { 61 case android.hardware.wifi.V1_0.NanClusterEventType.DISCOVERY_MAC_ADDRESS_CHANGED: 62 return DISCOVERY_MAC_ADDRESS_CHANGED; 63 case android.hardware.wifi.V1_0.NanClusterEventType.STARTED_CLUSTER: 64 return STARTED_CLUSTER; 65 case android.hardware.wifi.V1_0.NanClusterEventType.JOINED_CLUSTER: 66 return JOINED_CLUSTER; 67 default: 68 Log.e(TAG, "Unknown NanClusterEventType received from HIDL: " + code); 69 return -1; 70 } 71 } 72 73 /** 74 * Convert NanClusterEventType from AIDL to framework. 75 */ fromAidl(int code)76 public static int fromAidl(int code) { 77 switch (code) { 78 case android.hardware.wifi.NanClusterEventType.DISCOVERY_MAC_ADDRESS_CHANGED: 79 return DISCOVERY_MAC_ADDRESS_CHANGED; 80 case android.hardware.wifi.NanClusterEventType.STARTED_CLUSTER: 81 return STARTED_CLUSTER; 82 case android.hardware.wifi.NanClusterEventType.JOINED_CLUSTER: 83 return JOINED_CLUSTER; 84 default: 85 Log.e(TAG, "Unknown NanClusterEventType received from HIDL: " + code); 86 return -1; 87 } 88 } 89 } 90 91 /** 92 * NAN DP (data-path) channel config options. 93 */ 94 public static class NanDataPathChannelCfg { 95 public static final int CHANNEL_NOT_REQUESTED = 0; 96 public static final int REQUEST_CHANNEL_SETUP = 1; 97 public static final int FORCE_CHANNEL_SETUP = 2; 98 99 /** 100 * Convert NanDataPathChannelCfg from framework to HIDL. 101 */ toHidl(int code)102 public static int toHidl(int code) { 103 switch (code) { 104 case CHANNEL_NOT_REQUESTED: 105 return android.hardware.wifi.V1_0.NanDataPathChannelCfg.CHANNEL_NOT_REQUESTED; 106 case REQUEST_CHANNEL_SETUP: 107 return android.hardware.wifi.V1_0.NanDataPathChannelCfg.REQUEST_CHANNEL_SETUP; 108 case FORCE_CHANNEL_SETUP: 109 return android.hardware.wifi.V1_0.NanDataPathChannelCfg.FORCE_CHANNEL_SETUP; 110 default: 111 Log.e(TAG, "Unknown NanDataPathChannelCfg received from framework: " + code); 112 return -1; 113 } 114 } 115 116 /** 117 * Convert NanDataPathChannelCfg from framework to AIDL. 118 */ toAidl(int code)119 public static int toAidl(int code) { 120 switch (code) { 121 case CHANNEL_NOT_REQUESTED: 122 return android.hardware.wifi.NanDataPathChannelCfg.CHANNEL_NOT_REQUESTED; 123 case REQUEST_CHANNEL_SETUP: 124 return android.hardware.wifi.NanDataPathChannelCfg.REQUEST_CHANNEL_SETUP; 125 case FORCE_CHANNEL_SETUP: 126 return android.hardware.wifi.NanDataPathChannelCfg.FORCE_CHANNEL_SETUP; 127 default: 128 Log.e(TAG, "Unknown NanDataPathChannelCfg received from framework: " + code); 129 return -1; 130 } 131 } 132 } 133 134 /** 135 * Ranging in the context of discovery session indication controls. 136 */ 137 public static class NanRangingIndication { 138 public static final int CONTINUOUS_INDICATION_MASK = 1 << 0; 139 public static final int INGRESS_MET_MASK = 1 << 1; 140 public static final int EGRESS_MET_MASK = 1 << 2; 141 142 /** 143 * Convert NanRangingIndication from HIDL to framework. 144 */ fromHidl(int rangingInd)145 public static int fromHidl(int rangingInd) { 146 int frameworkRangingInd = 0; 147 if ((android.hardware.wifi.V1_0.NanRangingIndication.CONTINUOUS_INDICATION_MASK 148 & rangingInd) != 0) { 149 frameworkRangingInd |= CONTINUOUS_INDICATION_MASK; 150 } 151 if ((android.hardware.wifi.V1_0.NanRangingIndication.INGRESS_MET_MASK 152 & rangingInd) != 0) { 153 frameworkRangingInd |= INGRESS_MET_MASK; 154 } 155 if ((android.hardware.wifi.V1_0.NanRangingIndication.EGRESS_MET_MASK 156 & rangingInd) != 0) { 157 frameworkRangingInd |= EGRESS_MET_MASK; 158 } 159 return frameworkRangingInd; 160 } 161 162 /** 163 * Convert NanRangingIndication from AIDL to framework. 164 */ fromAidl(int rangingInd)165 public static int fromAidl(int rangingInd) { 166 int frameworkRangingInd = 0; 167 if ((android.hardware.wifi.NanRangingIndication.CONTINUOUS_INDICATION_MASK 168 & rangingInd) != 0) { 169 frameworkRangingInd |= CONTINUOUS_INDICATION_MASK; 170 } 171 if ((android.hardware.wifi.NanRangingIndication.INGRESS_MET_MASK 172 & rangingInd) != 0) { 173 frameworkRangingInd |= INGRESS_MET_MASK; 174 } 175 if ((android.hardware.wifi.NanRangingIndication.EGRESS_MET_MASK 176 & rangingInd) != 0) { 177 frameworkRangingInd |= EGRESS_MET_MASK; 178 } 179 return frameworkRangingInd; 180 } 181 } 182 183 /** 184 * NAN API response codes used in request notifications and events. 185 */ 186 public static class NanStatusCode { 187 public static final int SUCCESS = 0; 188 public static final int INTERNAL_FAILURE = 1; 189 public static final int PROTOCOL_FAILURE = 2; 190 public static final int INVALID_SESSION_ID = 3; 191 public static final int NO_RESOURCES_AVAILABLE = 4; 192 public static final int INVALID_ARGS = 5; 193 public static final int INVALID_PEER_ID = 6; 194 public static final int INVALID_NDP_ID = 7; 195 public static final int NAN_NOT_ALLOWED = 8; 196 public static final int NO_OTA_ACK = 9; 197 public static final int ALREADY_ENABLED = 10; 198 public static final int FOLLOWUP_TX_QUEUE_FULL = 11; 199 public static final int UNSUPPORTED_CONCURRENCY_NAN_DISABLED = 12; 200 public static final int INVALID_PAIRING_ID = 13; 201 public static final int INVALID_BOOTSTRAPPING_ID = 14; 202 203 204 /** 205 * Convert NanStatusCode from HIDL to framework. 206 */ fromHidl(int code)207 public static int fromHidl(int code) { 208 switch (code) { 209 case android.hardware.wifi.V1_0.NanStatusType.SUCCESS: 210 return SUCCESS; 211 case android.hardware.wifi.V1_0.NanStatusType.INTERNAL_FAILURE: 212 return INTERNAL_FAILURE; 213 case android.hardware.wifi.V1_0.NanStatusType.PROTOCOL_FAILURE: 214 return PROTOCOL_FAILURE; 215 case android.hardware.wifi.V1_0.NanStatusType.INVALID_SESSION_ID: 216 return INVALID_SESSION_ID; 217 case android.hardware.wifi.V1_0.NanStatusType.NO_RESOURCES_AVAILABLE: 218 return NO_RESOURCES_AVAILABLE; 219 case android.hardware.wifi.V1_0.NanStatusType.INVALID_ARGS: 220 return INVALID_ARGS; 221 case android.hardware.wifi.V1_0.NanStatusType.INVALID_PEER_ID: 222 return INVALID_PEER_ID; 223 case android.hardware.wifi.V1_0.NanStatusType.INVALID_NDP_ID: 224 return INVALID_NDP_ID; 225 case android.hardware.wifi.V1_0.NanStatusType.NAN_NOT_ALLOWED: 226 return NAN_NOT_ALLOWED; 227 case android.hardware.wifi.V1_0.NanStatusType.NO_OTA_ACK: 228 return NO_OTA_ACK; 229 case android.hardware.wifi.V1_0.NanStatusType.ALREADY_ENABLED: 230 return ALREADY_ENABLED; 231 case android.hardware.wifi.V1_0.NanStatusType.FOLLOWUP_TX_QUEUE_FULL: 232 return FOLLOWUP_TX_QUEUE_FULL; 233 case android.hardware.wifi.V1_0.NanStatusType.UNSUPPORTED_CONCURRENCY_NAN_DISABLED: 234 return UNSUPPORTED_CONCURRENCY_NAN_DISABLED; 235 default: 236 Log.e(TAG, "Unknown NanStatusType received from HIDL: " + code); 237 return -1; 238 } 239 } 240 241 /** 242 * Convert NanStatusCode from AIDL to framework. 243 */ fromAidl(int code)244 public static int fromAidl(int code) { 245 switch (code) { 246 case android.hardware.wifi.NanStatusCode.SUCCESS: 247 return SUCCESS; 248 case android.hardware.wifi.NanStatusCode.INTERNAL_FAILURE: 249 return INTERNAL_FAILURE; 250 case android.hardware.wifi.NanStatusCode.PROTOCOL_FAILURE: 251 return PROTOCOL_FAILURE; 252 case android.hardware.wifi.NanStatusCode.INVALID_SESSION_ID: 253 return INVALID_SESSION_ID; 254 case android.hardware.wifi.NanStatusCode.NO_RESOURCES_AVAILABLE: 255 return NO_RESOURCES_AVAILABLE; 256 case android.hardware.wifi.NanStatusCode.INVALID_ARGS: 257 return INVALID_ARGS; 258 case android.hardware.wifi.NanStatusCode.INVALID_PEER_ID: 259 return INVALID_PEER_ID; 260 case android.hardware.wifi.NanStatusCode.INVALID_NDP_ID: 261 return INVALID_NDP_ID; 262 case android.hardware.wifi.NanStatusCode.NAN_NOT_ALLOWED: 263 return NAN_NOT_ALLOWED; 264 case android.hardware.wifi.NanStatusCode.NO_OTA_ACK: 265 return NO_OTA_ACK; 266 case android.hardware.wifi.NanStatusCode.ALREADY_ENABLED: 267 return ALREADY_ENABLED; 268 case android.hardware.wifi.NanStatusCode.FOLLOWUP_TX_QUEUE_FULL: 269 return FOLLOWUP_TX_QUEUE_FULL; 270 case android.hardware.wifi.NanStatusCode.UNSUPPORTED_CONCURRENCY_NAN_DISABLED: 271 return UNSUPPORTED_CONCURRENCY_NAN_DISABLED; 272 case android.hardware.wifi.NanStatusCode.INVALID_PAIRING_ID: 273 return INVALID_PAIRING_ID; 274 case android.hardware.wifi.NanStatusCode.INVALID_BOOTSTRAPPING_ID: 275 return INVALID_BOOTSTRAPPING_ID; 276 default: 277 Log.e(TAG, "Unknown NanStatusType received from AIDL: " + code); 278 return -1; 279 } 280 } 281 } 282 283 /** 284 * Configuration parameters used in the call to enableAndConfigure. 285 */ 286 public static class PowerParameters { 287 public int discoveryWindow24Ghz; 288 public int discoveryWindow5Ghz; 289 public int discoveryWindow6Ghz; 290 public int discoveryBeaconIntervalMs; 291 public int numberOfSpatialStreamsInDiscovery; 292 public boolean enableDiscoveryWindowEarlyTermination; 293 } 294 WifiNanIface(@onNull android.hardware.wifi.V1_0.IWifiNanIface nanIface)295 public WifiNanIface(@NonNull android.hardware.wifi.V1_0.IWifiNanIface nanIface) { 296 Log.i(TAG, "Creating WifiNanIface using the HIDL implementation"); 297 mWifiNanIface = createWifiNanIfaceHidlImplMockable(nanIface); 298 } 299 WifiNanIface(@onNull android.hardware.wifi.IWifiNanIface nanIface)300 public WifiNanIface(@NonNull android.hardware.wifi.IWifiNanIface nanIface) { 301 mWifiNanIface = createWifiNanIfaceAidlImplMockable(nanIface); 302 } 303 createWifiNanIfaceHidlImplMockable( android.hardware.wifi.V1_0.IWifiNanIface nanIface)304 protected WifiNanIfaceHidlImpl createWifiNanIfaceHidlImplMockable( 305 android.hardware.wifi.V1_0.IWifiNanIface nanIface) { 306 return new WifiNanIfaceHidlImpl(nanIface); 307 } 308 createWifiNanIfaceAidlImplMockable( android.hardware.wifi.IWifiNanIface nanIface)309 protected WifiNanIfaceAidlImpl createWifiNanIfaceAidlImplMockable( 310 android.hardware.wifi.IWifiNanIface nanIface) { 311 return new WifiNanIfaceAidlImpl(nanIface); 312 } 313 validateAndCall(String methodStr, T defaultVal, @NonNull Supplier<T> supplier)314 private <T> T validateAndCall(String methodStr, T defaultVal, @NonNull Supplier<T> supplier) { 315 if (mWifiNanIface == null) { 316 Log.wtf(TAG, "Cannot call " + methodStr + " because mWifiNanIface is null"); 317 return defaultVal; 318 } 319 return supplier.get(); 320 } 321 322 /** 323 * Enable verbose logging. 324 */ enableVerboseLogging(boolean verbose)325 public void enableVerboseLogging(boolean verbose) { 326 if (mWifiNanIface != null) { 327 mWifiNanIface.enableVerboseLogging(verbose); 328 } 329 } 330 331 /** 332 * See comments for {@link IWifiNanIface#registerFrameworkCallback(Callback)} 333 */ registerFrameworkCallback(Callback cb)334 public boolean registerFrameworkCallback(Callback cb) { 335 return validateAndCall("registerFrameworkCallback", false, 336 () -> mWifiNanIface.registerFrameworkCallback(cb)); 337 } 338 339 /** 340 * See comments for {@link IWifiNanIface#getName()} 341 */ 342 @Override 343 @Nullable getName()344 public String getName() { 345 return validateAndCall("getName", null, 346 () -> mWifiNanIface.getName()); 347 } 348 349 /** 350 * See comments for {@link IWifiNanIface#getCapabilities(short)} 351 */ getCapabilities(short transactionId)352 public boolean getCapabilities(short transactionId) { 353 return validateAndCall("getCapabilities", false, 354 () -> mWifiNanIface.getCapabilities(transactionId)); 355 } 356 357 /** 358 * See comments for {@link IWifiNanIface#enableAndConfigure(short, ConfigRequest, boolean, 359 * boolean, boolean, boolean, int, int, PowerParameters)} 360 */ enableAndConfigure(short transactionId, ConfigRequest configRequest, boolean notifyIdentityChange, boolean initialConfiguration, boolean rangingEnabled, boolean isInstantCommunicationEnabled, int instantModeChannel, int clusterId, int macAddressRandomizationIntervalSec, PowerParameters powerParameters)361 public boolean enableAndConfigure(short transactionId, ConfigRequest configRequest, 362 boolean notifyIdentityChange, boolean initialConfiguration, boolean rangingEnabled, 363 boolean isInstantCommunicationEnabled, int instantModeChannel, int clusterId, 364 int macAddressRandomizationIntervalSec, PowerParameters powerParameters) { 365 return validateAndCall("enableAndConfigure", false, 366 () -> mWifiNanIface.enableAndConfigure(transactionId, configRequest, 367 notifyIdentityChange, initialConfiguration, rangingEnabled, 368 isInstantCommunicationEnabled, instantModeChannel, clusterId, 369 macAddressRandomizationIntervalSec, powerParameters)); 370 } 371 372 /** 373 * See comments for {@link IWifiNanIface#disable(short)} 374 */ disable(short transactionId)375 public boolean disable(short transactionId) { 376 return validateAndCall("disable", false, 377 () -> mWifiNanIface.disable(transactionId)); 378 } 379 380 /** 381 * See comments for {@link IWifiNanIface#publish(short, byte, PublishConfig, byte[])} 382 */ publish(short transactionId, byte publishId, PublishConfig publishConfig, byte[] nik)383 public boolean publish(short transactionId, byte publishId, PublishConfig publishConfig, 384 byte[] nik) { 385 return validateAndCall("publish", false, 386 () -> mWifiNanIface.publish(transactionId, publishId, publishConfig, nik)); 387 } 388 389 /** 390 * See comments for {@link IWifiNanIface#subscribe(short, byte, SubscribeConfig, byte[])} 391 */ subscribe(short transactionId, byte subscribeId, SubscribeConfig subscribeConfig, byte[] nik)392 public boolean subscribe(short transactionId, byte subscribeId, 393 SubscribeConfig subscribeConfig, byte[] nik) { 394 return validateAndCall("subscribe", false, 395 () -> mWifiNanIface.subscribe(transactionId, subscribeId, subscribeConfig, nik)); 396 } 397 398 /** 399 * See comments for {@link IWifiNanIface#sendMessage(short, byte, int, MacAddress, byte[])} 400 */ sendMessage(short transactionId, byte pubSubId, int requestorInstanceId, MacAddress dest, byte[] message)401 public boolean sendMessage(short transactionId, byte pubSubId, int requestorInstanceId, 402 MacAddress dest, byte[] message) { 403 return validateAndCall("sendMessage", false, 404 () -> mWifiNanIface.sendMessage(transactionId, pubSubId, requestorInstanceId, 405 dest, message)); 406 } 407 408 /** 409 * See comments for {@link IWifiNanIface#stopPublish(short, byte)} 410 */ stopPublish(short transactionId, byte pubSubId)411 public boolean stopPublish(short transactionId, byte pubSubId) { 412 return validateAndCall("stopPublish", false, 413 () -> mWifiNanIface.stopPublish(transactionId, pubSubId)); 414 } 415 416 /** 417 * See comments for {@link IWifiNanIface#stopSubscribe(short, byte)} 418 */ stopSubscribe(short transactionId, byte pubSubId)419 public boolean stopSubscribe(short transactionId, byte pubSubId) { 420 return validateAndCall("stopSubscribe", false, 421 () -> mWifiNanIface.stopSubscribe(transactionId, pubSubId)); 422 } 423 424 /** 425 * See comments for {@link IWifiNanIface#createAwareNetworkInterface(short, String)} 426 */ createAwareNetworkInterface(short transactionId, String interfaceName)427 public boolean createAwareNetworkInterface(short transactionId, String interfaceName) { 428 return validateAndCall("createAwareNetworkInterface", false, 429 () -> mWifiNanIface.createAwareNetworkInterface(transactionId, interfaceName)); 430 } 431 432 /** 433 * See comments for {@link IWifiNanIface#deleteAwareNetworkInterface(short, String)} 434 */ deleteAwareNetworkInterface(short transactionId, String interfaceName)435 public boolean deleteAwareNetworkInterface(short transactionId, String interfaceName) { 436 return validateAndCall("deleteAwareNetworkInterface", false, 437 () -> mWifiNanIface.deleteAwareNetworkInterface(transactionId, interfaceName)); 438 } 439 440 /** 441 * See comments for 442 * {@link IWifiNanIface#initiateDataPath(short, int, int, int, MacAddress, String, boolean, byte[], Capabilities, WifiAwareDataPathSecurityConfig, byte)} 443 */ initiateDataPath(short transactionId, int peerId, int channelRequestType, int channel, MacAddress peer, String interfaceName, boolean isOutOfBand, byte[] appInfo, Capabilities capabilities, WifiAwareDataPathSecurityConfig securityConfig, byte pubSubId)444 public boolean initiateDataPath(short transactionId, int peerId, int channelRequestType, 445 int channel, MacAddress peer, String interfaceName, 446 boolean isOutOfBand, byte[] appInfo, Capabilities capabilities, 447 WifiAwareDataPathSecurityConfig securityConfig, byte pubSubId) { 448 return validateAndCall("initiateDataPath", false, 449 () -> mWifiNanIface.initiateDataPath(transactionId, peerId, channelRequestType, 450 channel, peer, interfaceName, isOutOfBand, appInfo, capabilities, 451 securityConfig, pubSubId)); 452 } 453 454 /** 455 * See comments for 456 * {@link IWifiNanIface#respondToDataPathRequest(short, boolean, int, String, byte[], boolean, Capabilities, WifiAwareDataPathSecurityConfig, byte)} 457 */ respondToDataPathRequest(short transactionId, boolean accept, int ndpId, String interfaceName, byte[] appInfo, boolean isOutOfBand, Capabilities capabilities, WifiAwareDataPathSecurityConfig securityConfig, byte pubSubId)458 public boolean respondToDataPathRequest(short transactionId, boolean accept, int ndpId, 459 String interfaceName, byte[] appInfo, 460 boolean isOutOfBand, Capabilities capabilities, 461 WifiAwareDataPathSecurityConfig securityConfig, byte pubSubId) { 462 return validateAndCall("respondToDataPathRequest", false, 463 () -> mWifiNanIface.respondToDataPathRequest(transactionId, accept, ndpId, 464 interfaceName, appInfo, isOutOfBand, capabilities, securityConfig, 465 pubSubId)); 466 } 467 468 /** 469 * See comments for {@link IWifiNanIface#endDataPath(short, int)} 470 */ endDataPath(short transactionId, int ndpId)471 public boolean endDataPath(short transactionId, int ndpId) { 472 return validateAndCall("endDataPath", false, 473 () -> mWifiNanIface.endDataPath(transactionId, ndpId)); 474 } 475 476 /** 477 * {@link IWifiNanIface#initiateNanPairingRequest(short, int, MacAddress, byte[], boolean, int, byte[], String, int, int)} 478 */ initiatePairing(short transactionId, int peerId, MacAddress peer, byte[] pairingIdentityKey, boolean enablePairingCache, int requestType, byte[] pmk, String password, int akm, int cipherSuite)479 public boolean initiatePairing(short transactionId, int peerId, MacAddress peer, 480 byte[] pairingIdentityKey, boolean enablePairingCache, int requestType, byte[] pmk, 481 String password, int akm, int cipherSuite) { 482 return validateAndCall("initiatePairing", false, 483 () -> mWifiNanIface.initiateNanPairingRequest(transactionId, peerId, peer, 484 pairingIdentityKey, enablePairingCache, requestType, pmk, password, akm, 485 cipherSuite)); 486 } 487 488 /** 489 * {@link IWifiNanIface#endPairing(short, int)} 490 */ endPairing(short transactionId, int pairingId)491 public boolean endPairing(short transactionId, int pairingId) { 492 return validateAndCall("initiatePairing", false, 493 () -> mWifiNanIface.endPairing(transactionId, pairingId)); 494 } 495 496 /** 497 * {@link IWifiNanIface#respondToPairingRequest(short, int, boolean, byte[], boolean, int, byte[], String, int, int)} 498 */ respondToPairingRequest(short transactionId, int pairingId, boolean accept, byte[] pairingIdentityKey, boolean enablePairingCache, int requestType, byte[] pmk, String password, int akm, int cipherSuite)499 public boolean respondToPairingRequest(short transactionId, int pairingId, boolean accept, 500 byte[] pairingIdentityKey, boolean enablePairingCache, int requestType, byte[] pmk, 501 String password, int akm, int cipherSuite) { 502 return validateAndCall("respondToPairingRequest", false, 503 () -> mWifiNanIface.respondToPairingRequest(transactionId, pairingId, accept, 504 pairingIdentityKey, enablePairingCache, requestType, pmk, password, akm, 505 cipherSuite)); 506 } 507 /** 508 * {@link IWifiNanIface#initiateNanBootstrappingRequest(short, int, MacAddress, int, byte[])} 509 */ initiateBootstrapping(short transactionId, int peerId, MacAddress peer, int method, byte[] cookie)510 public boolean initiateBootstrapping(short transactionId, int peerId, MacAddress peer, 511 int method, byte[] cookie) { 512 return validateAndCall("initiateBootstrapping", false, 513 () -> mWifiNanIface.initiateNanBootstrappingRequest(transactionId, peerId, peer, 514 method, cookie)); 515 } 516 /** 517 * {@link IWifiNanIface#respondToNanBootstrappingRequest(short, int, boolean)} 518 */ respondToBootstrappingRequest(short transactionId, int bootstrappingId, boolean accept)519 public boolean respondToBootstrappingRequest(short transactionId, int bootstrappingId, 520 boolean accept) { 521 return validateAndCall("initiateBootstrapping", false, 522 () -> mWifiNanIface.respondToNanBootstrappingRequest(transactionId, bootstrappingId, 523 accept)); 524 } 525 526 /** 527 * See comments for {@link IWifiNanIface#suspend(short, byte)} 528 */ suspendRequest(short transactionId, byte pubSubId)529 public boolean suspendRequest(short transactionId, byte pubSubId) { 530 return validateAndCall("suspendRequest", false, 531 () -> mWifiNanIface.suspend(transactionId, pubSubId)); 532 } 533 534 /** 535 * See comments for {@link IWifiNanIface#resume(short, byte)} 536 */ resumeRequest(short transactionId, byte pubSubId)537 public boolean resumeRequest(short transactionId, byte pubSubId) { 538 return validateAndCall("resumeRequest", false, 539 () -> mWifiNanIface.resume(transactionId, pubSubId)); 540 } 541 542 /** 543 * Framework callback object. Will get called when the equivalent events are received 544 * from the HAL. 545 */ 546 public interface Callback { 547 /** 548 * Invoked in response to a capability request. 549 * @param id ID corresponding to the original request. 550 * @param capabilities Capability data. 551 */ notifyCapabilitiesResponse(short id, Capabilities capabilities)552 void notifyCapabilitiesResponse(short id, Capabilities capabilities); 553 554 /** 555 * Invoked in response to an enable request. 556 * @param id ID corresponding to the original request. 557 * @param status Status the operation (see {@link NanStatusCode}). 558 */ notifyEnableResponse(short id, int status)559 void notifyEnableResponse(short id, int status); 560 561 /** 562 * Invoked in response to a config request. 563 * @param id ID corresponding to the original request. 564 * @param status Status the operation (see {@link NanStatusCode}). 565 */ notifyConfigResponse(short id, int status)566 void notifyConfigResponse(short id, int status); 567 568 /** 569 * Invoked in response to a disable request. 570 * @param id ID corresponding to the original request. 571 * @param status Status the operation (see {@link NanStatusCode}). 572 */ notifyDisableResponse(short id, int status)573 void notifyDisableResponse(short id, int status); 574 575 /** 576 * Invoked to notify the status of the start publish request. 577 * @param id ID corresponding to the original request. 578 * @param status Status the operation (see {@link NanStatusCode}). 579 * @param publishId 580 */ notifyStartPublishResponse(short id, int status, byte publishId)581 void notifyStartPublishResponse(short id, int status, byte publishId); 582 583 /** 584 * Invoked to notify the status of the start subscribe request. 585 * @param id ID corresponding to the original request. 586 * @param status Status the operation (see {@link NanStatusCode}). 587 * @param subscribeId ID of the new subscribe session (if successfully created). 588 */ notifyStartSubscribeResponse(short id, int status, byte subscribeId)589 void notifyStartSubscribeResponse(short id, int status, byte subscribeId); 590 591 /** 592 * Invoked in response to a transmit followup request. 593 * @param id ID corresponding to the original request. 594 * @param status Status the operation (see {@link NanStatusCode}). 595 */ notifyTransmitFollowupResponse(short id, int status)596 void notifyTransmitFollowupResponse(short id, int status); 597 598 /** 599 * Invoked in response to a create data interface request. 600 * @param id ID corresponding to the original request. 601 * @param status Status the operation (see {@link NanStatusCode}). 602 */ notifyCreateDataInterfaceResponse(short id, int status)603 void notifyCreateDataInterfaceResponse(short id, int status); 604 605 /** 606 * Invoked in response to a delete data interface request. 607 * @param id ID corresponding to the original request. 608 * @param status Status the operation (see {@link NanStatusCode}). 609 */ notifyDeleteDataInterfaceResponse(short id, int status)610 void notifyDeleteDataInterfaceResponse(short id, int status); 611 612 /** 613 * Invoked in response to a delete data interface request. 614 * @param id ID corresponding to the original request. 615 * @param status Status the operation (see {@link NanStatusCode}). 616 * @param ndpInstanceId 617 */ notifyInitiateDataPathResponse(short id, int status, int ndpInstanceId)618 void notifyInitiateDataPathResponse(short id, int status, int ndpInstanceId); 619 620 /** 621 * Invoked in response to a respond to data path indication request. 622 * @param id ID corresponding to the original request. 623 * @param status Status the operation (see {@link NanStatusCode}). 624 */ notifyRespondToDataPathIndicationResponse(short id, int status)625 void notifyRespondToDataPathIndicationResponse(short id, int status); 626 627 /** 628 * Invoked in response to a terminate data path request. 629 * @param id ID corresponding to the original request. 630 * @param status Status the operation (see {@link NanStatusCode}). 631 */ notifyTerminateDataPathResponse(short id, int status)632 void notifyTerminateDataPathResponse(short id, int status); 633 634 /** 635 * Invoked in response to a initiate NAN pairing request. 636 * @param id ID corresponding to the original request. 637 * @param status Status the operation (see {@link NanStatusCode}). 638 */ notifyInitiatePairingResponse(short id, int status, int pairingInstanceId)639 void notifyInitiatePairingResponse(short id, int status, 640 int pairingInstanceId); 641 642 /** 643 * Invoked in response to a response NAN pairing request. 644 * @param id ID corresponding to the original request. 645 * @param status Status the operation (see {@link NanStatusCode}). 646 */ notifyRespondToPairingIndicationResponse(short id, int status)647 void notifyRespondToPairingIndicationResponse(short id, int status); 648 649 /** 650 * Invoked in response to a initiate NAN Bootstrapping request. 651 * @param id ID corresponding to the original request. 652 * @param status Status the operation (see {@link NanStatusCode}). 653 */ notifyInitiateBootstrappingResponse(short id, int status, int bootstrappingInstanceId)654 void notifyInitiateBootstrappingResponse(short id, int status, 655 int bootstrappingInstanceId); 656 657 /** 658 * Invoked in response to a response NAN Bootstrapping request. 659 * @param id ID corresponding to the original request. 660 * @param status Status the operation (see {@link NanStatusCode}). 661 */ notifyRespondToBootstrappingIndicationResponse(short id, int status)662 void notifyRespondToBootstrappingIndicationResponse(short id, int status); 663 664 /** 665 * Invoked in response to a connection suspension request. 666 * @param id ID corresponding to the original request. 667 * @param status Status the operation (see {@link NanStatusCode}). 668 */ notifySuspendResponse(short id, int status)669 void notifySuspendResponse(short id, int status); 670 671 /** 672 * Invoked in response to a connection resume request. 673 * @param id ID corresponding to the original request. 674 * @param status Status the operation (see {@link NanStatusCode}). 675 */ notifyResumeResponse(short id, int status)676 void notifyResumeResponse(short id, int status); 677 678 /** 679 * Invoked in response to a pairing termination request. 680 * @param id ID corresponding to the original request. 681 * @param status Status the operation (see {@link NanStatusCode}). 682 */ notifyTerminatePairingResponse(short id, int status)683 void notifyTerminatePairingResponse(short id, int status); 684 685 /** 686 * Indicates that a cluster event has been received. 687 * @param eventType Type of the cluster event (see {@link NanClusterEventType}). 688 * @param addr MAC Address associated with the corresponding event. 689 */ eventClusterEvent(int eventType, byte[] addr)690 void eventClusterEvent(int eventType, byte[] addr); 691 692 /** 693 * Indicates that a NAN has been disabled. 694 * @param status Status the operation (see {@link NanStatusCode}). 695 */ eventDisabled(int status)696 void eventDisabled(int status); 697 698 /** 699 * Indicates that an active publish session has terminated. 700 * @param sessionId Discovery session ID of the terminated session. 701 * @param status Status the operation (see {@link NanStatusCode}). 702 */ eventPublishTerminated(byte sessionId, int status)703 void eventPublishTerminated(byte sessionId, int status); 704 705 /** 706 * Indicates that an active subscribe session has terminated. 707 * @param sessionId Discovery session ID of the terminated session. 708 * @param status Status the operation (see {@link NanStatusCode}). 709 */ eventSubscribeTerminated(byte sessionId, int status)710 void eventSubscribeTerminated(byte sessionId, int status); 711 712 /** 713 * Indicates that a match has occurred - i.e. a service has been discovered. 714 * @param discoverySessionId Publish or subscribe discovery session ID of an existing 715 * discovery session. 716 * @param peerId Unique ID of the peer. Can be used subsequently in sendMessage() 717 * or to set up a data-path. 718 * @param addr NAN Discovery (management) MAC address of the peer. 719 * @param serviceSpecificInfo The arbitrary information contained in the 720 * |NanDiscoveryCommonConfig.serviceSpecificInfo| of 721 * the peer's discovery session configuration. 722 * @param matchFilter The match filter from the discovery packet (publish or subscribe) 723 * which caused service discovery. Matches the 724 * |NanDiscoveryCommonConfig.txMatchFilter| of the peer's unsolicited 725 * publish message or of the local device's Active subscribe message. 726 * @param rangingIndicationType The ranging event(s) which triggered the ranging. Ex. can 727 * indicate that continuous ranging was requested, or else that 728 * an ingress event occurred. See {@link NanRangingIndication}. 729 * @param rangingMeasurementInMm If ranging was required and executed, contains the 730 * distance to the peer in mm. 731 * @param scid Security Context Identifier identifies the Security Context. 732 * For NAN Shared Key Cipher Suite, this field contains the 16 octet PMKID 733 * identifying the PMK used for setting up the Secure Data Path. 734 * @param peerCipherType Cipher type for data-paths constructed in the context of this 735 * discovery session. 736 */ eventMatch(byte discoverySessionId, int peerId, byte[] addr, byte[] serviceSpecificInfo, byte[] matchFilter, int rangingIndicationType, int rangingMeasurementInMm, byte[] scid, int peerCipherType, byte[] nonce, byte[] tag, AwarePairingConfig pairingConfig)737 void eventMatch(byte discoverySessionId, int peerId, byte[] addr, 738 byte[] serviceSpecificInfo, byte[] matchFilter, int rangingIndicationType, 739 int rangingMeasurementInMm, byte[] scid, int peerCipherType, byte[] nonce, 740 byte[] tag, AwarePairingConfig pairingConfig); 741 742 /** 743 * Indicates that a previously discovered match (service) has expired. 744 * @param discoverySessionId Discovery session ID of the expired match. 745 * @param peerId Peer ID of the expired match. 746 */ eventMatchExpired(byte discoverySessionId, int peerId)747 void eventMatchExpired(byte discoverySessionId, int peerId); 748 749 /** 750 * Indicates that a followup message has been received from a peer. 751 * @param discoverySessionId Discovery session (publish or subscribe) ID of a previously 752 * created discovery session. 753 * @param peerId Unique ID of the peer. 754 * @param addr NAN Discovery (management) MAC address of the peer. 755 * @param serviceSpecificInfo Received message from the peer. There is no semantic 756 * meaning to these bytes. They are passed-through from sender 757 * to receiver as-is with no parsing. 758 */ eventFollowupReceived(byte discoverySessionId, int peerId, byte[] addr, byte[] serviceSpecificInfo)759 void eventFollowupReceived(byte discoverySessionId, int peerId, byte[] addr, 760 byte[] serviceSpecificInfo); 761 762 /** 763 * Provides status of a completed followup message transmit operation. 764 * @param id ID corresponding to the original request. 765 * @param status Status the operation (see {@link NanStatusCode}). 766 */ eventTransmitFollowup(short id, int status)767 void eventTransmitFollowup(short id, int status); 768 769 /** 770 * Indicates that a data-path (NDP) setup has been requested by an initiator peer 771 * (received by the intended responder). 772 * @param discoverySessionId ID of an active publish or subscribe discovery session. 773 * @param peerDiscMacAddr MAC address of the Initiator peer. This is the MAC address of 774 * the peer's management/discovery NAN interface. 775 * @param ndpInstanceId ID of the data-path. Used to identify the data-path in further 776 * negotiation/APIs. 777 * @param appInfo Arbitrary information communicated from the peer as part of the 778 * data-path setup process. There is no semantic meaning to these bytes. 779 * They are passed from sender to receiver as-is with no parsing. 780 */ eventDataPathRequest(byte discoverySessionId, byte[] peerDiscMacAddr, int ndpInstanceId, byte[] appInfo)781 void eventDataPathRequest(byte discoverySessionId, byte[] peerDiscMacAddr, 782 int ndpInstanceId, byte[] appInfo); 783 784 /** 785 * Indicates that a data-path (NDP) setup has been completed. Received by both the 786 * Initiator and Responder. 787 * @param status Status the operation (see {@link NanStatusCode}). 788 * @param ndpInstanceId ID of the data-path. 789 * @param dataPathSetupSuccess Indicates whether the data-path setup succeeded (true) 790 * or failed (false). 791 * @param peerNdiMacAddr MAC address of the peer's data-interface (not its 792 * management/discovery interface). 793 * @param appInfo Arbitrary information communicated from the peer as part of the 794 * data-path setup process. There is no semantic meaning to these bytes. 795 * They are passed from sender to receiver as-is with no parsing. 796 * @param channelInfos 797 */ eventDataPathConfirm(int status, int ndpInstanceId, boolean dataPathSetupSuccess, byte[] peerNdiMacAddr, byte[] appInfo, List<WifiAwareChannelInfo> channelInfos)798 void eventDataPathConfirm(int status, int ndpInstanceId, boolean dataPathSetupSuccess, 799 byte[] peerNdiMacAddr, byte[] appInfo, List<WifiAwareChannelInfo> channelInfos); 800 801 /** 802 * Indicates that a data-path (NDP) schedule has been updated (ex. channels 803 * have been changed). 804 * @param peerDiscoveryAddress Discovery address (NMI) of the peer to which the NDP 805 * is connected. 806 * @param ndpInstanceIds List of NDPs to which this update applies. 807 * @param channelInfo Updated channel(s) information. 808 */ eventDataPathScheduleUpdate(byte[] peerDiscoveryAddress, ArrayList<Integer> ndpInstanceIds, List<WifiAwareChannelInfo> channelInfo)809 void eventDataPathScheduleUpdate(byte[] peerDiscoveryAddress, 810 ArrayList<Integer> ndpInstanceIds, List<WifiAwareChannelInfo> channelInfo); 811 812 /** 813 * Indicates that a list of data-paths (NDP) have been terminated. Received by both the 814 * Initiator and Responder. 815 * @param ndpInstanceId Data-path ID of the terminated data-path. 816 */ eventDataPathTerminated(int ndpInstanceId)817 void eventDataPathTerminated(int ndpInstanceId); 818 819 /** 820 * Indicates that the pairing request is from the peer device. 821 */ eventPairingRequest(int discoverySessionId, int peerId, byte[] peerDiscMacAddr, int ndpInstanceId, int requestType, boolean enableCache, byte[] nonce, byte[] tag)822 void eventPairingRequest(int discoverySessionId, int peerId, byte[] peerDiscMacAddr, 823 int ndpInstanceId, int requestType, boolean enableCache, byte[] nonce, byte[] tag); 824 825 /** 826 * Indicates that the pairing is finished 827 */ eventPairingConfirm(int pairingId, boolean accept, int reason, int requestType, boolean enableCache, PairingConfigManager.PairingSecurityAssociationInfo npksa)828 void eventPairingConfirm(int pairingId, boolean accept, int reason, int requestType, 829 boolean enableCache, 830 PairingConfigManager.PairingSecurityAssociationInfo npksa); 831 832 /** 833 * Indicates that the bootstrapping request is from the peer device. 834 */ eventBootstrappingRequest(int discoverySessionId, int peerId, byte[] peerDiscMacAddr, int bootstrappingInstanceId, int method)835 void eventBootstrappingRequest(int discoverySessionId, int peerId, byte[] peerDiscMacAddr, 836 int bootstrappingInstanceId, int method); 837 838 /** 839 * Indicates that the bootstrapping is finished 840 */ eventBootstrappingConfirm(int pairingId, int responseCode, int reason, int comebackDelay, byte[] cookie)841 void eventBootstrappingConfirm(int pairingId, int responseCode, int reason, 842 int comebackDelay, byte[] cookie); 843 844 /** 845 * Indicates that the suspension mode has changed, i.e., the device has entered or exited 846 * the suspension mode 847 */ eventSuspensionModeChanged(boolean isSuspended)848 void eventSuspensionModeChanged(boolean isSuspended); 849 } 850 } 851