• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 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.p2p;
18 
19 import static com.android.server.wifi.HalDeviceManager.HDM_CREATE_IFACE_P2P;
20 import static com.android.server.wifi.WifiSettingsConfigStore.WIFI_P2P_SUPPORTED_FEATURES;
21 
22 import android.annotation.NonNull;
23 import android.annotation.Nullable;
24 import android.annotation.SuppressLint;
25 import android.net.wifi.CoexUnsafeChannel;
26 import android.net.wifi.ScanResult;
27 import android.net.wifi.nl80211.WifiNl80211Manager;
28 import android.net.wifi.p2p.WifiP2pConfig;
29 import android.net.wifi.p2p.WifiP2pDirInfo;
30 import android.net.wifi.p2p.WifiP2pDiscoveryConfig;
31 import android.net.wifi.p2p.WifiP2pExtListenParams;
32 import android.net.wifi.p2p.WifiP2pGroup;
33 import android.net.wifi.p2p.WifiP2pGroupList;
34 import android.net.wifi.p2p.WifiP2pManager;
35 import android.net.wifi.p2p.WifiP2pUsdBasedLocalServiceAdvertisementConfig;
36 import android.net.wifi.p2p.WifiP2pUsdBasedServiceDiscoveryConfig;
37 import android.net.wifi.p2p.nsd.WifiP2pServiceInfo;
38 import android.net.wifi.p2p.nsd.WifiP2pUsdBasedServiceConfig;
39 import android.net.wifi.util.Environment;
40 import android.os.Handler;
41 import android.os.WorkSource;
42 import android.text.TextUtils;
43 import android.util.Log;
44 
45 import androidx.annotation.Keep;
46 
47 import com.android.server.wifi.HalDeviceManager;
48 import com.android.server.wifi.PropertyService;
49 import com.android.server.wifi.WifiInjector;
50 import com.android.server.wifi.WifiMetrics;
51 import com.android.server.wifi.WifiNative;
52 import com.android.server.wifi.WifiSettingsConfigStore;
53 import com.android.server.wifi.WifiVendorHal;
54 import com.android.wifi.flags.FeatureFlags;
55 import com.android.wifi.flags.Flags;
56 
57 import java.util.HashSet;
58 import java.util.List;
59 import java.util.Set;
60 
61 /**
62  * Native calls for bring up/shut down of the supplicant daemon and for
63  * sending requests to the supplicant daemon
64  */
65 public class WifiP2pNative {
66     private static final String TAG = "WifiP2pNative";
67     private boolean mVerboseLoggingEnabled = false;
68     private final SupplicantP2pIfaceHal mSupplicantP2pIfaceHal;
69     private final WifiNative mWifiNative;
70     private final WifiMetrics mWifiMetrics;
71     private final WifiNl80211Manager mWifiNl80211Manager;
72     private final HalDeviceManager mHalDeviceManager;
73     private final PropertyService mPropertyService;
74     private final WifiVendorHal mWifiVendorHal;
75     private final WifiInjector mWifiInjector;
76     private final FeatureFlags mFeatureFlags;
77     private final Object mLock = new Object();
78     private WifiNative.Iface mP2pIface;
79     private String mP2pIfaceName;
80     private InterfaceDestroyedListenerInternal mInterfaceDestroyedListener;
81     private int mServiceVersion = -1;
82     private long mCachedFeatureSet = 0;
83 
84     /**
85      * Death handler for the supplicant daemon.
86      */
87     private class SupplicantDeathHandlerInternal implements WifiNative.SupplicantDeathEventHandler {
88         @Override
onDeath()89         public void onDeath() {
90             if (mP2pIface != null) {
91                 Log.i(TAG, "wpa_supplicant died. Cleaning up internal state.");
92                 mInterfaceDestroyedListener.teardownAndInvalidate(mP2pIface.name);
93                 mWifiMetrics.incrementNumSupplicantCrashes();
94             }
95         }
96     }
97 
98     // Internal callback registered to HalDeviceManager.
99     private class InterfaceDestroyedListenerInternal implements
100             HalDeviceManager.InterfaceDestroyedListener {
101         private final HalDeviceManager.InterfaceDestroyedListener mExternalListener;
102         private boolean mValid;
103 
InterfaceDestroyedListenerInternal( HalDeviceManager.InterfaceDestroyedListener externalListener)104         InterfaceDestroyedListenerInternal(
105                 HalDeviceManager.InterfaceDestroyedListener externalListener) {
106             mExternalListener = externalListener;
107             mValid = true;
108         }
109 
teardownAndInvalidate(@ullable String ifaceName)110         public void teardownAndInvalidate(@Nullable String ifaceName) {
111             synchronized (mLock) {
112                 if (!mSupplicantP2pIfaceHal.deregisterDeathHandler()) {
113                     Log.i(TAG, "Failed to deregister p2p supplicant death handler");
114                 }
115                 if (!TextUtils.isEmpty(ifaceName)) {
116                     mSupplicantP2pIfaceHal.teardownIface(ifaceName);
117                     if (mP2pIface != null) {
118                         mWifiNative.teardownP2pIface(mP2pIface.id);
119                     }
120                 }
121                 mP2pIfaceName = null;
122                 mP2pIface = null;
123                 mValid = false;
124                 Log.i(TAG, "teardownAndInvalidate is completed");
125             }
126         }
127 
128         @Override
onDestroyed(String ifaceName)129         public void onDestroyed(String ifaceName) {
130             synchronized (mLock) {
131                 Log.d(TAG, "P2P InterfaceDestroyedListener " + ifaceName);
132                 if (!mValid) {
133                     Log.d(TAG, "Ignoring stale interface destroyed listener");
134                     return;
135                 }
136                 teardownAndInvalidate(ifaceName);
137                 mExternalListener.onDestroyed(ifaceName);
138             }
139         }
140     }
141 
WifiP2pNative( WifiNl80211Manager wifiNl80211Manager, WifiNative wifiNative, WifiMetrics wifiMetrics, WifiVendorHal wifiVendorHal, SupplicantP2pIfaceHal p2pIfaceHal, HalDeviceManager halDeviceManager, PropertyService propertyService, WifiInjector wifiInjector)142     public WifiP2pNative(
143             WifiNl80211Manager wifiNl80211Manager,
144             WifiNative wifiNative,
145             WifiMetrics wifiMetrics,
146             WifiVendorHal wifiVendorHal,
147             SupplicantP2pIfaceHal p2pIfaceHal,
148             HalDeviceManager halDeviceManager,
149             PropertyService propertyService,
150             WifiInjector wifiInjector) {
151         mWifiNative = wifiNative;
152         mWifiMetrics = wifiMetrics;
153         mWifiNl80211Manager = wifiNl80211Manager;
154         mWifiVendorHal = wifiVendorHal;
155         mSupplicantP2pIfaceHal = p2pIfaceHal;
156         mHalDeviceManager = halDeviceManager;
157         mPropertyService = propertyService;
158         mWifiInjector = wifiInjector;
159         mFeatureFlags = wifiInjector.getDeviceConfigFacade().getFeatureFlags();
160     }
161 
162     /**
163      * Enable verbose logging for all sub modules.
164      */
enableVerboseLogging(boolean verboseEnabled, boolean halVerboseEnabled)165     public void enableVerboseLogging(boolean verboseEnabled, boolean halVerboseEnabled) {
166         mVerboseLoggingEnabled = verboseEnabled;
167         SupplicantP2pIfaceHal.enableVerboseLogging(verboseEnabled, halVerboseEnabled);
168     }
169 
170     private static final int CONNECT_TO_SUPPLICANT_SAMPLING_INTERVAL_MS = 100;
171     private static final int CONNECT_TO_SUPPLICANT_MAX_SAMPLES = 50;
172     /**
173      * This method is called to wait for establishing connection to wpa_supplicant.
174      *
175      * @return true if connection is established, false otherwise.
176      */
waitForSupplicantConnection()177     private boolean waitForSupplicantConnection() {
178         // Start initialization if not already started.
179         if (!mSupplicantP2pIfaceHal.isInitializationStarted()
180                 && !mSupplicantP2pIfaceHal.initialize()) {
181             return false;
182         }
183         int connectTries = 0;
184         while (connectTries++ < CONNECT_TO_SUPPLICANT_MAX_SAMPLES) {
185             // Check if the initialization is complete.
186             if (mSupplicantP2pIfaceHal.isInitializationComplete()) {
187                 return true;
188             }
189             try {
190                 Thread.sleep(CONNECT_TO_SUPPLICANT_SAMPLING_INTERVAL_MS);
191             } catch (InterruptedException ignore) {
192             }
193         }
194         return false;
195     }
196 
197     /**
198      * Close supplicant connection.
199      */
stopP2pSupplicantIfNecessary()200     public void stopP2pSupplicantIfNecessary() {
201         if (mSupplicantP2pIfaceHal.isInitializationStarted()) {
202             mSupplicantP2pIfaceHal.terminate();
203         }
204     }
205 
206     /**
207      * Returns whether HAL is supported on this device or not.
208      */
isHalInterfaceSupported()209     public boolean isHalInterfaceSupported() {
210         return mHalDeviceManager.isSupported();
211     }
212 
213     public static final String P2P_IFACE_NAME = "p2p0";
214     public static final String P2P_INTERFACE_PROPERTY = "wifi.direct.interface";
215 
216     /**
217      * Helper function to handle creation of P2P iface.
218      * For devices which do not the support the HAL, this will bypass HalDeviceManager &
219      * teardown any existing iface.
220      */
createP2pIface(Handler handler, WorkSource requestorWs)221     private String createP2pIface(Handler handler, WorkSource requestorWs) {
222         if (mHalDeviceManager.isSupported()) {
223             mP2pIfaceName = mHalDeviceManager.createP2pIface(
224                     mInterfaceDestroyedListener, handler, requestorWs);
225             if (mP2pIfaceName == null) {
226                 Log.e(TAG, "Failed to create P2p iface in HalDeviceManager");
227                 return null;
228             }
229             return mP2pIfaceName;
230         } else {
231             Log.i(TAG, "Vendor Hal is not supported, ignoring createP2pIface.");
232             return mPropertyService.getString(P2P_INTERFACE_PROPERTY, P2P_IFACE_NAME);
233         }
234     }
235 
236     /**
237      * Setup Interface for P2p mode.
238      *
239      * @param destroyedListener Listener to be invoked when the interface is destroyed.
240      * @param handler Handler to be used for invoking the destroyedListener.
241      * @param requestorWs Worksource to attribute the request to.
242      */
setupInterface( @ullable HalDeviceManager.InterfaceDestroyedListener destroyedListener, @NonNull Handler handler, @NonNull WorkSource requestorWs)243     public String setupInterface(
244             @Nullable HalDeviceManager.InterfaceDestroyedListener destroyedListener,
245             @NonNull Handler handler, @NonNull WorkSource requestorWs) {
246         synchronized (mLock) {
247             Log.d(TAG, "Setup P2P interface");
248             if (mP2pIfaceName == null) {
249                 mInterfaceDestroyedListener = (null == destroyedListener)
250                         ? null
251                         : new InterfaceDestroyedListenerInternal(destroyedListener);
252                 mP2pIface = mWifiNative.createP2pIface(mInterfaceDestroyedListener, handler,
253                     requestorWs);
254                 if (mP2pIface != null) {
255                     mP2pIfaceName = mP2pIface.name;
256                 }
257                 if (mP2pIfaceName == null) {
258                     Log.e(TAG, "Failed to create P2p iface");
259                     if (mHalDeviceManager.isItPossibleToCreateIface(HDM_CREATE_IFACE_P2P,
260                             requestorWs)) {
261                         mWifiMetrics.incrementNumSetupP2pInterfaceFailureDueToHal();
262                     }
263                     return null;
264                 }
265                 if (!waitForSupplicantConnection()) {
266                     Log.e(TAG, "Failed to connect to supplicant");
267                     teardownInterface();
268                     mWifiMetrics.incrementNumSetupP2pInterfaceFailureDueToSupplicant();
269                     return null;
270                 }
271                 if (!mSupplicantP2pIfaceHal.setupIface(mP2pIfaceName)) {
272                     Log.e(TAG, "Failed to setup P2p iface in supplicant");
273                     teardownInterface();
274                     mWifiMetrics.incrementNumSetupP2pInterfaceFailureDueToSupplicant();
275                     return null;
276                 }
277                 if (!mSupplicantP2pIfaceHal.registerDeathHandler(
278                                 new SupplicantDeathHandlerInternal())) {
279                     Log.e(TAG, "Failed to register supplicant death handler"
280                             + "(because hidl supplicant?)");
281                     teardownInterface();
282                     mWifiMetrics.incrementNumSetupP2pInterfaceFailureDueToSupplicant();
283                     return null;
284                 }
285                 long featureSet = mSupplicantP2pIfaceHal.getSupportedFeatures();
286                 mWifiInjector.getSettingsConfigStore()
287                         .put(WIFI_P2P_SUPPORTED_FEATURES, featureSet);
288                 mCachedFeatureSet = featureSet | getDriverIndependentFeatures();
289                 Log.i(TAG, "P2P Supported features: " + mCachedFeatureSet);
290                 Log.i(TAG, "P2P interface setup completed");
291                 return mP2pIfaceName;
292             } else {
293                 Log.i(TAG, "P2P interface already exists");
294                 return mHalDeviceManager.isSupported()
295                     ? mP2pIfaceName
296                     : mPropertyService.getString(P2P_INTERFACE_PROPERTY, P2P_IFACE_NAME);
297             }
298         }
299     }
300 
301     /**
302      * Teardown P2p interface.
303      */
teardownInterface()304     public void teardownInterface() {
305         synchronized (mLock) {
306             Log.d(TAG, "Teardown P2P interface:" + mP2pIfaceName);
307             if (mHalDeviceManager.isSupported()) {
308                 if (mP2pIfaceName != null) {
309                     mHalDeviceManager.removeP2pIface(mP2pIfaceName);
310                     Log.i(TAG, "P2P interface teardown completed");
311                 }
312             } else {
313                 Log.i(TAG, "HAL is not supported. Destroy listener for the interface.");
314                 String ifaceName = mPropertyService.getString(P2P_INTERFACE_PROPERTY,
315                         P2P_IFACE_NAME);
316                 if (null != mInterfaceDestroyedListener) {
317                     mInterfaceDestroyedListener.teardownAndInvalidate(ifaceName);
318                 }
319             }
320         }
321     }
322 
323     /**
324      * Replace requestorWs in-place when iface is already enabled.
325      */
replaceRequestorWs(WorkSource requestorWs)326     public boolean replaceRequestorWs(WorkSource requestorWs) {
327         synchronized (mLock) {
328             if (mHalDeviceManager.isSupported()) {
329                 if (mP2pIfaceName == null) return false;
330                 return mHalDeviceManager.replaceRequestorWsForP2pIface(mP2pIfaceName, requestorWs);
331             } else {
332                 Log.i(TAG, "HAL is not supported. Ignore replace requestorWs");
333                 return true;
334             }
335         }
336     }
337 
338     /**
339      * Get the supported features.
340      *
341      * The features can be retrieved regardless of whether the P2P interface is up.
342      *
343      * Note that the feature set may be incomplete if Supplicant has not been started
344      * on the device yet.
345      *
346      * @return bitmask defined by WifiP2pManager.FEATURE_*
347      */
getSupportedFeatures()348     public long getSupportedFeatures() {
349         if (mCachedFeatureSet == 0) {
350             mCachedFeatureSet = getDriverIndependentFeatures()
351                     | mWifiInjector.getSettingsConfigStore().get(
352                     WifiSettingsConfigStore.WIFI_P2P_SUPPORTED_FEATURES);
353         }
354         return mCachedFeatureSet;
355     }
356 
getDriverIndependentFeatures()357     private long getDriverIndependentFeatures() {
358         long features = 0;
359         // First AIDL version supports these three features.
360         if (getCachedServiceVersion() >= 1) {
361             features = WifiP2pManager.FEATURE_SET_VENDOR_ELEMENTS
362                     | WifiP2pManager.FEATURE_FLEXIBLE_DISCOVERY
363                     | WifiP2pManager.FEATURE_GROUP_CLIENT_REMOVAL;
364             if (mServiceVersion >= 2) {
365                 features |= WifiP2pManager.FEATURE_GROUP_OWNER_IPV6_LINK_LOCAL_ADDRESS_PROVIDED;
366             }
367         }
368         return features;
369     }
370 
getCachedServiceVersion()371     private int getCachedServiceVersion() {
372         if (mServiceVersion == -1) {
373             mServiceVersion = mWifiInjector.getSettingsConfigStore().get(
374                     WifiSettingsConfigStore.SUPPLICANT_HAL_AIDL_SERVICE_VERSION);
375         }
376         return mServiceVersion;
377     }
378 
379     /**
380      * Set WPS device name.
381      *
382      * @param name String to be set.
383      * @return true if request is sent successfully, false otherwise.
384      */
setDeviceName(String name)385     public boolean setDeviceName(String name) {
386         return mSupplicantP2pIfaceHal.setWpsDeviceName(name);
387     }
388 
389     /**
390      * Populate list of available networks or update existing list.
391      *
392      * @return true, if list has been modified.
393      */
p2pListNetworks(WifiP2pGroupList groups)394     public boolean p2pListNetworks(WifiP2pGroupList groups) {
395         return mSupplicantP2pIfaceHal.loadGroups(groups);
396     }
397 
398     /**
399      * Initiate WPS Push Button setup.
400      * The PBC operation requires that a button is also pressed at the
401      * AP/Registrar at about the same time (2 minute window).
402      *
403      * @param iface Group interface name to use.
404      * @param bssid BSSID of the AP. Use zero'ed bssid to indicate wildcard.
405      * @return true, if operation was successful.
406      */
startWpsPbc(String iface, String bssid)407     public boolean startWpsPbc(String iface, String bssid) {
408         return mSupplicantP2pIfaceHal.startWpsPbc(iface, bssid);
409     }
410 
411     /**
412      * Initiate WPS Pin Keypad setup.
413      *
414      * @param iface Group interface name to use.
415      * @param pin 8 digit pin to be used.
416      * @return true, if operation was successful.
417      */
startWpsPinKeypad(String iface, String pin)418     public boolean startWpsPinKeypad(String iface, String pin) {
419         return mSupplicantP2pIfaceHal.startWpsPinKeypad(iface, pin);
420     }
421 
422     /**
423      * Initiate WPS Pin Display setup.
424      *
425      * @param iface Group interface name to use.
426      * @param bssid BSSID of the AP. Use zero'ed bssid to indicate wildcard.
427      * @return generated pin if operation was successful, null otherwise.
428      */
startWpsPinDisplay(String iface, String bssid)429     public String startWpsPinDisplay(String iface, String bssid) {
430         return mSupplicantP2pIfaceHal.startWpsPinDisplay(iface, bssid);
431     }
432 
433     /**
434      * Remove network with provided id.
435      *
436      * @param netId Id of the network to lookup.
437      * @return true, if operation was successful.
438      */
removeP2pNetwork(int netId)439     public boolean removeP2pNetwork(int netId) {
440         return mSupplicantP2pIfaceHal.removeNetwork(netId);
441     }
442 
443     /**
444      * Set WPS device type.
445      *
446      * @param type Type specified as a string. Used format: <categ>-<OUI>-<subcateg>
447      * @return true if request is sent successfully, false otherwise.
448      */
setP2pDeviceType(String type)449     public boolean setP2pDeviceType(String type) {
450         return mSupplicantP2pIfaceHal.setWpsDeviceType(type);
451     }
452 
453     /**
454      * Set WPS config methods
455      *
456      * @param cfg List of config methods.
457      * @return true if request is sent successfully, false otherwise.
458      */
setConfigMethods(String cfg)459     public boolean setConfigMethods(String cfg) {
460         return mSupplicantP2pIfaceHal.setWpsConfigMethods(cfg);
461     }
462 
463     /**
464      * Set the postfix to be used for P2P SSID's.
465      *
466      * @param postfix String to be appended to SSID.
467      *
468      * @return boolean value indicating whether operation was successful.
469      */
setP2pSsidPostfix(String postfix)470     public boolean setP2pSsidPostfix(String postfix) {
471         return mSupplicantP2pIfaceHal.setSsidPostfix(postfix);
472     }
473 
474     /**
475      * Set the Maximum idle time in seconds for P2P groups.
476      * This value controls how long a P2P group is maintained after there
477      * is no other members in the group. As a group owner, this means no
478      * associated stations in the group. As a P2P client, this means no
479      * group owner seen in scan results.
480      *
481      * @param iface Group interface name to use.
482      * @param time Timeout value in seconds.
483      *
484      * @return boolean value indicating whether operation was successful.
485      */
setP2pGroupIdle(String iface, int time)486     public boolean setP2pGroupIdle(String iface, int time) {
487         return mSupplicantP2pIfaceHal.setGroupIdle(iface, time);
488     }
489 
490     /**
491      * Turn on/off power save mode for the interface.
492      *
493      * @param iface Group interface name to use.
494      * @param enabled Indicate if power save is to be turned on/off.
495      *
496      * @return boolean value indicating whether operation was successful.
497      */
498     @Keep
setP2pPowerSave(String iface, boolean enabled)499     public boolean setP2pPowerSave(String iface, boolean enabled) {
500         return mSupplicantP2pIfaceHal.setPowerSave(iface, enabled);
501     }
502 
503     /**
504      * Enable/Disable Wifi Display.
505      *
506      * @param enable true to enable, false to disable.
507      * @return true, if operation was successful.
508      */
setWfdEnable(boolean enable)509     public boolean setWfdEnable(boolean enable) {
510         return mSupplicantP2pIfaceHal.enableWfd(enable);
511     }
512 
513     /**
514      * Set Wifi Display device info.
515      *
516      * @param hex WFD device info as described in section 5.1.2 of WFD technical
517      *        specification v1.0.0.
518      * @return true, if operation was successful.
519      */
setWfdDeviceInfo(String hex)520     public boolean setWfdDeviceInfo(String hex) {
521         return mSupplicantP2pIfaceHal.setWfdDeviceInfo(hex);
522     }
523 
524     /**
525      * Initiate a P2P service discovery indefinitely.
526      * Will trigger {@link WifiP2pMonitor#P2P_DEVICE_FOUND_EVENT} on finding devices.
527      *
528      * @return boolean value indicating whether operation was successful.
529      */
p2pFind()530     public boolean p2pFind() {
531         return p2pFind(0);
532     }
533 
534     /**
535      * Initiate a P2P service discovery with a (optional) timeout.
536      *
537      * @param timeout The maximum amount of time to be spent in performing discovery.
538      *        Set to 0 to indefinitely continue discovery until an explicit
539      *        |stopFind| is sent.
540      * @return boolean value indicating whether operation was successful.
541      */
p2pFind(int timeout)542     public boolean p2pFind(int timeout) {
543         return mSupplicantP2pIfaceHal.find(timeout);
544     }
545 
546     /**
547      * Initiate a P2P device discovery with a scan type, a (optional) frequency, and a (optional)
548      * timeout.
549      *
550      * @param type indicates what channels to scan.
551      *        Valid values are {@link WifiP2pManager#WIFI_P2P_SCAN_FULL} for doing full P2P scan,
552      *        {@link WifiP2pManager#WIFI_P2P_SCAN_SOCIAL} for scanning social channels,
553      *        {@link WifiP2pManager#WIFI_P2P_SCAN_SINGLE_FREQ} for scanning a specified frequency.
554      * @param freq is the frequency to be scanned.
555      *        The possible values are:
556      *        <ul>
557      *        <li> A valid frequency for {@link WifiP2pManager#WIFI_P2P_SCAN_SINGLE_FREQ}</li>
558      *        <li> {@link WifiP2pManager#WIFI_P2P_SCAN_FREQ_UNSPECIFIED} for
559      *          {@link WifiP2pManager#WIFI_P2P_SCAN_FULL} and
560      *          {@link WifiP2pManager#WIFI_P2P_SCAN_SOCIAL}</li>
561      *        </ul>
562      * @param timeout The maximum amount of time to be spent in performing discovery.
563      *        Set to 0 to indefinitely continue discovery until an explicit
564      *        |stopFind| is sent.
565      * @return boolean value indicating whether operation was successful.
566      */
p2pFind(@ifiP2pManager.WifiP2pScanType int type, int freq, int timeout)567     public boolean p2pFind(@WifiP2pManager.WifiP2pScanType int type, int freq, int timeout) {
568         return mSupplicantP2pIfaceHal.find(type, freq, timeout);
569     }
570 
571     /**
572      * Initiate a P2P service discovery with config parameters.
573      *
574      * @param config The config parameters to initiate P2P discovery.
575      * @param timeout The maximum amount of time to be spent in performing discovery.
576      *        Set to 0 to indefinitely continue discovery until an explicit
577      *        |stopFind| is sent.
578      * @return boolean value indicating whether the operation was successful.
579      */
p2pFindWithParams(@onNull WifiP2pDiscoveryConfig config, int timeout)580     public boolean p2pFindWithParams(@NonNull WifiP2pDiscoveryConfig config, int timeout) {
581         return mSupplicantP2pIfaceHal.findWithParams(config, timeout);
582     }
583 
584     /**
585      * Stop an ongoing P2P service discovery.
586      *
587      * @return boolean value indicating whether operation was successful.
588      */
p2pStopFind()589     public boolean p2pStopFind() {
590         return mSupplicantP2pIfaceHal.stopFind();
591     }
592 
593     /**
594      * Configure Extended Listen Timing.
595      *
596      * If enabled, listen state must be entered every |intervalInMillis| for at
597      * least |periodInMillis|. Both values have acceptable range of 1-65535
598      * (with interval obviously having to be larger than or equal to duration).
599      * If the P2P module is not idle at the time the Extended Listen Timing
600      * timeout occurs, the Listen State operation must be skipped.
601      *
602      * @param enable Enables or disables listening.
603      * @param period Period in milliseconds.
604      * @param interval Interval in milliseconds.
605      * @param extListenParams Additional parameter struct for this request.
606      *
607      * @return true, if operation was successful.
608      */
p2pExtListen(boolean enable, int period, int interval, @Nullable WifiP2pExtListenParams extListenParams)609     public boolean p2pExtListen(boolean enable, int period, int interval,
610             @Nullable WifiP2pExtListenParams extListenParams) {
611         return mSupplicantP2pIfaceHal.configureExtListen(enable, period, interval, extListenParams);
612     }
613 
614     /**
615      * Set P2P Listen channel.
616      *
617      * When specifying a social channel on the 2.4 GHz band (1/6/11) there is no
618      * need to specify the operating class since it defaults to 81. When
619      * specifying a social channel on the 60 GHz band (2), specify the 60 GHz
620      * operating class (180).
621      *
622      * @param lc Wifi channel. eg, 1, 6, 11.
623      *
624      * @return true, if operation was successful.
625      */
p2pSetListenChannel(int lc)626     public boolean p2pSetListenChannel(int lc) {
627         return mSupplicantP2pIfaceHal.setListenChannel(lc);
628     }
629 
630     /**
631      * Set P2P operating channel.
632      *
633      * @param oc Wifi channel, eg, 1, 6, 11.
634      * @param unsafeChannels channels are not allowed.
635      * @return true if operation was successful.
636      */
p2pSetOperatingChannel(int oc, @NonNull List<CoexUnsafeChannel> unsafeChannels)637     public boolean p2pSetOperatingChannel(int oc, @NonNull List<CoexUnsafeChannel> unsafeChannels) {
638         if (null == unsafeChannels) {
639             Log.wtf(TAG, "unsafeChannels is null.");
640             return false;
641         }
642         return mSupplicantP2pIfaceHal.setOperatingChannel(oc, unsafeChannels);
643     }
644 
645     /**
646      * Flush P2P peer table and state.
647      *
648      * @return boolean value indicating whether operation was successful.
649      */
p2pFlush()650     public boolean p2pFlush() {
651         return mSupplicantP2pIfaceHal.flush();
652     }
653 
654     /**
655      * Start P2P group formation with a discovered P2P peer. This includes
656      * optional group owner negotiation, group interface setup, provisioning,
657      * and establishing data connection.
658      *
659      * @param config Configuration to use to connect to remote device.
660      * @param joinExistingGroup Indicates that this is a command to join an
661      *        existing group as a client. It skips the group owner negotiation
662      *        part. This must send a Provision Discovery Request message to the
663      *        target group owner before associating for WPS provisioning.
664      *
665      * @return String containing generated pin, if selected provision method
666      *        uses PIN.
667      */
p2pConnect(WifiP2pConfig config, boolean joinExistingGroup)668     public String p2pConnect(WifiP2pConfig config, boolean joinExistingGroup) {
669         return mSupplicantP2pIfaceHal.connect(config, joinExistingGroup);
670     }
671 
672     /**
673      * Cancel an ongoing P2P group formation and joining-a-group related
674      * operation. This operation unauthorizes the specific peer device (if any
675      * had been authorized to start group formation), stops P2P find (if in
676      * progress), stops pending operations for join-a-group, and removes the
677      * P2P group interface (if one was used) that is in the WPS provisioning
678      * step. If the WPS provisioning step has been completed, the group is not
679      * terminated.
680      *
681      * @return boolean value indicating whether operation was successful.
682      */
p2pCancelConnect()683     public boolean p2pCancelConnect() {
684         return mSupplicantP2pIfaceHal.cancelConnect();
685     }
686 
687     /**
688      * Send P2P provision discovery request to the specified peer. The
689      * parameters for this command are the P2P device address of the peer and the
690      * desired configuration method.
691      *
692      * @param config Config class describing peer setup.
693      *
694      * @return boolean value indicating whether operation was successful.
695      */
p2pProvisionDiscovery(WifiP2pConfig config)696     public boolean p2pProvisionDiscovery(WifiP2pConfig config) {
697         return mSupplicantP2pIfaceHal.provisionDiscovery(config);
698     }
699 
700     /**
701      * Set up a P2P group owner manually.
702      * This is a helper method that invokes groupAdd(networkId, isPersistent) internally.
703      *
704      * @param persistent Used to request a persistent group to be formed.
705      * @param isP2pV2 Used to start a Group Owner that support P2P2 IE.
706      *
707      * @return true, if operation was successful.
708      */
p2pGroupAdd(boolean persistent, boolean isP2pV2)709     public boolean p2pGroupAdd(boolean persistent, boolean isP2pV2) {
710         return mSupplicantP2pIfaceHal.groupAdd(persistent, isP2pV2);
711     }
712 
713     /**
714      * Set up a P2P group owner manually (i.e., without group owner
715      * negotiation with a specific peer). This is also known as autonomous
716      * group owner.
717      *
718      * @param netId Used to specify the restart of a persistent group.
719      * @param isP2pV2 Used to start a Group Owner that support P2P2 IE.
720      *
721      * @return true, if operation was successful.
722      */
p2pGroupAdd(int netId, boolean isP2pV2)723     public boolean p2pGroupAdd(int netId, boolean isP2pV2) {
724         return mSupplicantP2pIfaceHal.groupAdd(netId, true, isP2pV2);
725     }
726 
727     /**
728      * Set up a P2P group as Group Owner or join a group with a configuration.
729      *
730      * @param config Used to specify config for setting up a P2P group
731      *
732      * @return true, if operation was successful.
733      */
734     @SuppressLint("NewApi")
p2pGroupAdd(WifiP2pConfig config, boolean join)735     public boolean p2pGroupAdd(WifiP2pConfig config, boolean join) {
736         int freq = 0;
737         int connectionType = Environment.isSdkAtLeastB() && Flags.wifiDirectR2()
738                 ? config.getPccModeConnectionType()
739                 : WifiP2pConfig.PCC_MODE_DEFAULT_CONNECTION_TYPE_LEGACY_ONLY;
740 
741         switch (config.groupOwnerBand) {
742             case WifiP2pConfig.GROUP_OWNER_BAND_2GHZ:
743                 freq = 2;
744                 break;
745             case WifiP2pConfig.GROUP_OWNER_BAND_5GHZ:
746                 freq = 5;
747                 break;
748             case WifiP2pConfig.GROUP_OWNER_BAND_6GHZ:
749                 freq = 6;
750                 break;
751             // treat it as frequency.
752             default:
753                 freq = config.groupOwnerBand;
754         }
755         if (Environment.isSdkAtLeastB() && Flags.wifiDirectR2()) {
756             /* Check if the device supports Wi-Fi Direct R2 */
757             if ((WifiP2pConfig.GROUP_OWNER_BAND_6GHZ == config.groupOwnerBand
758                     || WifiP2pConfig.PCC_MODE_CONNECTION_TYPE_R2_ONLY == connectionType)
759                     && !isWiFiDirectR2Supported()) {
760                 Log.e(TAG, "Failed to add the group - Wi-Fi Direct R2 not supported");
761                 return false;
762             }
763 
764             /* Check if the device supports Wi-Fi Direct R1/R2 Compatibility Mode */
765             if (WifiP2pConfig.PCC_MODE_CONNECTION_TYPE_LEGACY_OR_R2 == connectionType
766                     && !isPccModeAllowLegacyAndR2ConnectionSupported()) {
767                 Log.e(TAG, "Failed to add the group - R1/R2 compatibility not supported");
768                 return false;
769             }
770 
771             /* Check if this is a valid configuration for 6GHz band */
772             if (WifiP2pConfig.GROUP_OWNER_BAND_6GHZ == config.groupOwnerBand
773                     && WifiP2pConfig.PCC_MODE_CONNECTION_TYPE_R2_ONLY != connectionType) {
774                 Log.e(TAG, "Failed to add the group in 6GHz band - ConnectionType: "
775                         + connectionType);
776                 return false;
777             }
778 
779             /* Check if we can upgrade LEGACY to R2 */
780             if (WifiP2pConfig.PCC_MODE_CONNECTION_TYPE_LEGACY_ONLY == connectionType
781                     && isPccModeAllowLegacyAndR2ConnectionSupported()) {
782                 Log.e(TAG, "Upgrade Legacy connection to R1/R2 compatibility");
783                 connectionType = WifiP2pConfig.PCC_MODE_CONNECTION_TYPE_LEGACY_OR_R2;
784             }
785         }
786 
787 
788         abortWifiRunningScanIfNeeded(join);
789         return mSupplicantP2pIfaceHal.groupAdd(
790                 config.networkName,
791                 config.passphrase,
792                 connectionType,
793                 (config.netId == WifiP2pGroup.NETWORK_ID_PERSISTENT),
794                 freq, config.deviceAddress, join);
795     }
796 
797     /**
798      * @return true if this device supports Wi-Fi Direct R2
799      */
isWiFiDirectR2Supported()800     private boolean isWiFiDirectR2Supported() {
801         return (mCachedFeatureSet & WifiP2pManager.FEATURE_WIFI_DIRECT_R2) != 0;
802     }
803 
804     /**
805      * @return true if this device supports R1/R2 Compatibility Mode.
806      */
isPccModeAllowLegacyAndR2ConnectionSupported()807     private boolean isPccModeAllowLegacyAndR2ConnectionSupported() {
808         return (mCachedFeatureSet
809                 & WifiP2pManager.FEATURE_PCC_MODE_ALLOW_LEGACY_AND_R2_CONNECTION) != 0;
810     }
811 
abortWifiRunningScanIfNeeded(boolean isJoin)812     private void abortWifiRunningScanIfNeeded(boolean isJoin) {
813         if (!isJoin) return;
814 
815         Set<String> wifiClientInterfaces = mWifiNative.getClientInterfaceNames();
816 
817         for (String interfaceName: wifiClientInterfaces) {
818             mWifiNl80211Manager.abortScan(interfaceName);
819         }
820     }
821 
822     /**
823      * Terminate a P2P group. If a new virtual network interface was used for
824      * the group, it must also be removed. The network interface name of the
825      * group interface is used as a parameter for this command.
826      *
827      * @param iface Group interface name to use.
828      * @return true, if operation was successful.
829      */
p2pGroupRemove(String iface)830     public boolean p2pGroupRemove(String iface) {
831         return mSupplicantP2pIfaceHal.groupRemove(iface);
832     }
833 
834     /**
835      * Reject connection attempt from a peer (specified with a device
836      * address). This is a mechanism to reject a pending group owner negotiation
837      * with a peer and request to automatically block any further connection or
838      * discovery of the peer.
839      *
840      * @param deviceAddress MAC address of the device to reject.
841      *
842      * @return boolean value indicating whether operation was successful.
843      */
p2pReject(String deviceAddress)844     public boolean p2pReject(String deviceAddress) {
845         return mSupplicantP2pIfaceHal.reject(deviceAddress);
846     }
847 
848     /**
849      * Invite a device to a persistent group.
850      * If the peer device is the group owner of the persistent group, the peer
851      * parameter is not needed. Otherwise it is used to specify which
852      * device to invite. |goDeviceAddress| parameter may be used to override
853      * the group owner device address for Invitation Request should it not be
854      * known for some reason (this should not be needed in most cases).
855      *
856      * @param group Group object to use.
857      * @param deviceAddress MAC address of the device to invite.
858      *
859      * @return boolean value indicating whether operation was successful.
860      */
p2pInvite(WifiP2pGroup group, String deviceAddress)861     public boolean p2pInvite(WifiP2pGroup group, String deviceAddress) {
862         return mSupplicantP2pIfaceHal.invite(group, deviceAddress);
863     }
864 
865     /**
866      * Reinvoke a device from a persistent group.
867      *
868      * @param netId Used to specify the persistent group (valid only for P2P V1 group).
869      * @param deviceAddress MAC address of the device to reinvoke.
870      * @param dikId The identifier of device identity key of the device to reinvoke.
871      *              (valid only for P2P V2 group).
872      *
873      * @return true, if operation was successful.
874      */
p2pReinvoke(int netId, String deviceAddress, int dikId)875     public boolean p2pReinvoke(int netId, String deviceAddress, int dikId) {
876         return mSupplicantP2pIfaceHal.reinvoke(netId, deviceAddress, dikId);
877     }
878 
879     /**
880      * Gets the operational SSID of the device.
881      *
882      * @param deviceAddress MAC address of the peer.
883      *
884      * @return SSID of the device.
885      */
p2pGetSsid(String deviceAddress)886     public String p2pGetSsid(String deviceAddress) {
887         return mSupplicantP2pIfaceHal.getSsid(deviceAddress);
888     }
889 
890     /**
891      * Gets the MAC address of the device.
892      *
893      * @return MAC address of the device.
894      */
p2pGetDeviceAddress()895     public String p2pGetDeviceAddress() {
896         return mSupplicantP2pIfaceHal.getDeviceAddress();
897     }
898 
899     /**
900      * Gets the capability of the group which the device is a
901      * member of.
902      *
903      * @param deviceAddress MAC address of the peer.
904      *
905      * @return combination of |GroupCapabilityMask| values.
906      */
getGroupCapability(String deviceAddress)907     public int getGroupCapability(String deviceAddress) {
908         return mSupplicantP2pIfaceHal.getGroupCapability(deviceAddress);
909     }
910 
911     /**
912      * This command can be used to add a upnp/bonjour service.
913      *
914      * @param servInfo List of service queries.
915      *
916      * @return true, if operation was successful.
917      */
p2pServiceAdd(WifiP2pServiceInfo servInfo)918     public boolean p2pServiceAdd(WifiP2pServiceInfo servInfo) {
919         return mSupplicantP2pIfaceHal.serviceAdd(servInfo);
920     }
921 
922     /**
923      * This command can be used to remove a upnp/bonjour service.
924      *
925      * @param servInfo List of service queries.
926      *
927      * @return true, if operation was successful.
928      */
p2pServiceDel(WifiP2pServiceInfo servInfo)929     public boolean p2pServiceDel(WifiP2pServiceInfo servInfo) {
930         return mSupplicantP2pIfaceHal.serviceRemove(servInfo);
931     }
932 
933     /**
934      * This command can be used to flush all services from the
935      * device.
936      *
937      * @return boolean value indicating whether operation was successful.
938      */
p2pServiceFlush()939     public boolean p2pServiceFlush() {
940         return mSupplicantP2pIfaceHal.serviceFlush();
941     }
942 
943     /**
944      * Schedule a P2P service discovery request. The parameters for this command
945      * are the device address of the peer device (or 00:00:00:00:00:00 for
946      * wildcard query that is sent to every discovered P2P peer that supports
947      * service discovery) and P2P Service Query TLV(s) as hexdump.
948      *
949      * @param addr MAC address of the device to discover.
950      * @param query Hex dump of the query data.
951      * @return identifier Identifier for the request. Can be used to cancel the
952      *         request.
953      */
p2pServDiscReq(String addr, String query)954     public String p2pServDiscReq(String addr, String query) {
955         return mSupplicantP2pIfaceHal.requestServiceDiscovery(addr, query);
956     }
957 
958     /**
959      * Cancel a previous service discovery request.
960      *
961      * @param id Identifier for the request to cancel.
962      * @return true, if operation was successful.
963      */
p2pServDiscCancelReq(String id)964     public boolean p2pServDiscCancelReq(String id) {
965         return mSupplicantP2pIfaceHal.cancelServiceDiscovery(id);
966     }
967 
968     /**
969      * Send driver command to set Miracast mode.
970      *
971      * @param mode Mode of Miracast.
972      *        0 = disabled
973      *        1 = operating as source
974      *        2 = operating as sink
975      */
setMiracastMode(int mode)976     public void setMiracastMode(int mode) {
977         mSupplicantP2pIfaceHal.setMiracastMode(mode);
978     }
979 
980     /**
981      * Get NFC handover request message.
982      *
983      * @return select message if created successfully, null otherwise.
984      */
getNfcHandoverRequest()985     public String getNfcHandoverRequest() {
986         return mSupplicantP2pIfaceHal.getNfcHandoverRequest();
987     }
988 
989     /**
990      * Get NFC handover select message.
991      *
992      * @return select message if created successfully, null otherwise.
993      */
getNfcHandoverSelect()994     public String getNfcHandoverSelect() {
995         return mSupplicantP2pIfaceHal.getNfcHandoverSelect();
996     }
997 
998     /**
999      * Report NFC handover select message.
1000      *
1001      * @return true if reported successfully, false otherwise.
1002      */
initiatorReportNfcHandover(String selectMessage)1003     public boolean initiatorReportNfcHandover(String selectMessage) {
1004         return mSupplicantP2pIfaceHal.initiatorReportNfcHandover(selectMessage);
1005     }
1006 
1007     /**
1008      * Report NFC handover request message.
1009      *
1010      * @return true if reported successfully, false otherwise.
1011      */
responderReportNfcHandover(String requestMessage)1012     public boolean responderReportNfcHandover(String requestMessage) {
1013         return mSupplicantP2pIfaceHal.responderReportNfcHandover(requestMessage);
1014     }
1015 
1016     /**
1017      * Set the client list for the provided network.
1018      *
1019      * @param netId Id of the network.
1020      * @return  Space separated list of clients if successfull, null otherwise.
1021      */
getP2pClientList(int netId)1022     public String getP2pClientList(int netId) {
1023         return mSupplicantP2pIfaceHal.getClientList(netId);
1024     }
1025 
1026     /**
1027      * Set the client list for the provided network.
1028      *
1029      * @param netId Id of the network.
1030      * @param list Space separated list of clients.
1031      * @return true, if operation was successful.
1032      */
setP2pClientList(int netId, String list)1033     public boolean setP2pClientList(int netId, String list) {
1034         return mSupplicantP2pIfaceHal.setClientList(netId, list);
1035     }
1036 
1037     /**
1038      * Save the current configuration to p2p_supplicant.conf.
1039      *
1040      * @return true on success, false otherwise.
1041      */
saveConfig()1042     public boolean saveConfig() {
1043         return mSupplicantP2pIfaceHal.saveConfig();
1044     }
1045 
1046     /**
1047      * Enable/Disable MAC randomization.
1048      *
1049      * @param enable true to enable, false to disable.
1050      * @return true, if operation was successful.
1051      */
setMacRandomization(boolean enable)1052     public boolean setMacRandomization(boolean enable) {
1053         return mSupplicantP2pIfaceHal.setMacRandomization(enable);
1054     }
1055 
1056     /**
1057      * Set Wifi Display R2 device info.
1058      *
1059      * @param hex WFD device info as described in section 5.1.12 of WFD technical
1060      *        specification v2.1.0.
1061      * @return true, if operation was successful.
1062      */
setWfdR2DeviceInfo(String hex)1063     public boolean setWfdR2DeviceInfo(String hex) {
1064         return mSupplicantP2pIfaceHal.setWfdR2DeviceInfo(hex);
1065     }
1066 
1067     /**
1068      * Remove the client with the MAC address from the group.
1069      *
1070      * @param peerAddress Mac address of the client.
1071      * @return true if success
1072      */
removeClient(String peerAddress)1073     public boolean removeClient(String peerAddress) {
1074         // The client is deemed as a P2P client, not a legacy client, hence the false.
1075         return mSupplicantP2pIfaceHal.removeClient(peerAddress, false);
1076     }
1077 
1078     /**
1079      * Set vendor-specific information elements to the native service.
1080      *
1081      * @param vendorElements the vendor opaque data.
1082      * @return true, if operation was successful.
1083      */
setVendorElements(Set<ScanResult.InformationElement> vendorElements)1084     public boolean setVendorElements(Set<ScanResult.InformationElement> vendorElements) {
1085         return mSupplicantP2pIfaceHal.setVendorElements(vendorElements);
1086     }
1087 
1088     /**
1089      * Remove vendor-specific information elements from the native service.
1090      */
removeVendorElements()1091     public boolean removeVendorElements() {
1092         return mSupplicantP2pIfaceHal.setVendorElements(
1093                 new HashSet<ScanResult.InformationElement>());
1094     }
1095 
1096     /** Indicate whether or not 5GHz/6GHz DBS is supported. */
is5g6gDbsSupported()1097     public boolean is5g6gDbsSupported() {
1098         synchronized (mLock) {
1099             if (mP2pIfaceName == null) return false;
1100             if (!mHalDeviceManager.isSupported()) return false;
1101             return mHalDeviceManager.is5g6gDbsSupportedOnP2pIface(mP2pIfaceName);
1102         }
1103     }
1104 
1105     /**
1106      * Configure the IP addresses in supplicant for P2P GO to provide the IP address to
1107      * client in EAPOL handshake. Refer Wi-Fi P2P Technical Specification v1.7 - Section  4.2.8
1108      * IP Address Allocation in EAPOL-Key Frames (4-Way Handshake) for more details.
1109      * The IP addresses are IPV4 addresses and higher-order address bytes are in the
1110      * lower-order int bytes (e.g. 1.2.3.4 is represented as 0x04030201)
1111      *
1112      * @param ipAddressGo The P2P Group Owner IP address.
1113      * @param ipAddressMask The P2P Group owner subnet mask.
1114      * @param ipAddressStart The starting address in the IP address pool.
1115      * @param ipAddressEnd The ending address in the IP address pool.
1116      * @return boolean value indicating whether operation was successful.
1117      */
configureEapolIpAddressAllocationParams(int ipAddressGo, int ipAddressMask, int ipAddressStart, int ipAddressEnd)1118     public boolean configureEapolIpAddressAllocationParams(int ipAddressGo, int ipAddressMask,
1119             int ipAddressStart, int ipAddressEnd) {
1120         return mSupplicantP2pIfaceHal.configureEapolIpAddressAllocationParams(ipAddressGo,
1121                 ipAddressMask, ipAddressStart, ipAddressEnd);
1122     }
1123 
1124     /**
1125      * Start an Un-synchronized Service Discovery (USD) based P2P service discovery.
1126      *
1127      * @param usdServiceConfig is the USD based service configuration.
1128      * @param discoveryConfig is the configuration for this service discovery request.
1129      * @param timeoutInSeconds is the maximum time to be spent for this service discovery request.
1130      */
startUsdBasedServiceDiscovery(WifiP2pUsdBasedServiceConfig usdServiceConfig, WifiP2pUsdBasedServiceDiscoveryConfig discoveryConfig, int timeoutInSeconds)1131     public int startUsdBasedServiceDiscovery(WifiP2pUsdBasedServiceConfig usdServiceConfig,
1132             WifiP2pUsdBasedServiceDiscoveryConfig discoveryConfig, int timeoutInSeconds) {
1133         return mSupplicantP2pIfaceHal.startUsdBasedServiceDiscovery(usdServiceConfig,
1134                 discoveryConfig, timeoutInSeconds);
1135     }
1136 
1137     /**
1138      * Stop an Un-synchronized Service Discovery (USD) based P2P service discovery.
1139      *
1140      * @param sessionId Identifier to cancel the service discovery instance.
1141      *        Use zero to cancel all the service discovery instances.
1142      */
stopUsdBasedServiceDiscovery(int sessionId)1143     public void stopUsdBasedServiceDiscovery(int sessionId) {
1144         mSupplicantP2pIfaceHal.stopUsdBasedServiceDiscovery(sessionId);
1145     }
1146 
1147     /**
1148      * Start an Un-synchronized Service Discovery (USD) based P2P service advertisement.
1149      *
1150      * @param usdServiceConfig is the USD based service configuration.
1151      * @param advertisementConfig is the configuration for this service advertisement.
1152      * @param timeoutInSeconds is the maximum time to be spent for this service advertisement.
1153      */
startUsdBasedServiceAdvertisement(WifiP2pUsdBasedServiceConfig usdServiceConfig, WifiP2pUsdBasedLocalServiceAdvertisementConfig advertisementConfig, int timeoutInSeconds)1154     public int startUsdBasedServiceAdvertisement(WifiP2pUsdBasedServiceConfig usdServiceConfig,
1155             WifiP2pUsdBasedLocalServiceAdvertisementConfig advertisementConfig,
1156             int timeoutInSeconds) {
1157         return mSupplicantP2pIfaceHal.startUsdBasedServiceAdvertisement(usdServiceConfig,
1158                 advertisementConfig, timeoutInSeconds);
1159     }
1160 
1161     /**
1162      * Stop an Un-synchronized Service Discovery (USD) based P2P service advertisement.
1163      *
1164      * @param sessionId Identifier to cancel the service advertisement.
1165      *        Use zero to cancel all the service advertisement instances.
1166      */
stopUsdBasedServiceAdvertisement(int sessionId)1167     public void stopUsdBasedServiceAdvertisement(int sessionId) {
1168         mSupplicantP2pIfaceHal.stopUsdBasedServiceAdvertisement(sessionId);
1169     }
1170 
1171     /**
1172      * Get the Device Identity Resolution (DIR) Information.
1173      * See {@link WifiP2pDirInfo} for details
1174      *
1175      * @return {@link WifiP2pDirInfo} instance on success, null on failure.
1176      */
getDirInfo()1177     public WifiP2pDirInfo getDirInfo() {
1178         return mSupplicantP2pIfaceHal.getDirInfo();
1179     }
1180 
1181     /**
1182      * Validate the Device Identity Resolution (DIR) Information of a P2P device.
1183      * See {@link WifiP2pDirInfo} for details.
1184      *
1185      * @param dirInfo {@link WifiP2pDirInfo} to validate.
1186      * @return The identifier of device identity key on success, -1 on failure.
1187      */
validateDirInfo(@onNull WifiP2pDirInfo dirInfo)1188     public int validateDirInfo(@NonNull WifiP2pDirInfo dirInfo) {
1189         return mSupplicantP2pIfaceHal.validateDirInfo(dirInfo);
1190     }
1191 
1192     /**
1193      * Used to authorize a connection request to an existing Group Owner
1194      * interface, to allow a peer device to connect.
1195      *
1196      * @param config Configuration to use for connection.
1197      * @param groupOwnerInterfaceName Group Owner interface name on which the request to connect
1198      *                           needs to be authorized.
1199      *
1200      * @return boolean value indicating whether operation was successful.
1201      */
authorizeConnectRequestOnGroupOwner( WifiP2pConfig config, String groupOwnerInterfaceName)1202     public boolean authorizeConnectRequestOnGroupOwner(
1203             WifiP2pConfig config, String groupOwnerInterfaceName) {
1204         return mSupplicantP2pIfaceHal.authorizeConnectRequestOnGroupOwner(config,
1205                 groupOwnerInterfaceName);
1206     }
1207 
1208 }
1209