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