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 android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.hardware.wifi.V1_0.IWifiP2pIface; 22 import android.net.wifi.CoexUnsafeChannel; 23 import android.net.wifi.nl80211.WifiNl80211Manager; 24 import android.net.wifi.p2p.WifiP2pConfig; 25 import android.net.wifi.p2p.WifiP2pGroup; 26 import android.net.wifi.p2p.WifiP2pGroupList; 27 import android.net.wifi.p2p.nsd.WifiP2pServiceInfo; 28 import android.os.Handler; 29 import android.os.WorkSource; 30 import android.text.TextUtils; 31 import android.util.Log; 32 33 import com.android.server.wifi.HalDeviceManager; 34 import com.android.server.wifi.PropertyService; 35 import com.android.server.wifi.WifiNative; 36 import com.android.server.wifi.WifiVendorHal; 37 38 import java.util.List; 39 import java.util.Set; 40 41 /** 42 * Native calls for bring up/shut down of the supplicant daemon and for 43 * sending requests to the supplicant daemon 44 */ 45 public class WifiP2pNative { 46 private static final String TAG = "WifiP2pNative"; 47 private boolean mVerboseLoggingEnabled = false; 48 private final SupplicantP2pIfaceHal mSupplicantP2pIfaceHal; 49 private final WifiNative mWifiNative; 50 private final WifiNl80211Manager mWifiNl80211Manager; 51 private final HalDeviceManager mHalDeviceManager; 52 private final PropertyService mPropertyService; 53 private final WifiVendorHal mWifiVendorHal; 54 private IWifiP2pIface mIWifiP2pIface; 55 private InterfaceDestroyedListenerInternal mInterfaceDestroyedListener; 56 57 // Internal callback registered to HalDeviceManager. 58 private class InterfaceDestroyedListenerInternal implements 59 HalDeviceManager.InterfaceDestroyedListener { 60 private final HalDeviceManager.InterfaceDestroyedListener mExternalListener; 61 private boolean mValid; 62 InterfaceDestroyedListenerInternal( HalDeviceManager.InterfaceDestroyedListener externalListener)63 InterfaceDestroyedListenerInternal( 64 HalDeviceManager.InterfaceDestroyedListener externalListener) { 65 mExternalListener = externalListener; 66 mValid = true; 67 } 68 teardownAndInvalidate(@ullable String ifaceName)69 public void teardownAndInvalidate(@Nullable String ifaceName) { 70 if (!TextUtils.isEmpty(ifaceName)) { 71 mSupplicantP2pIfaceHal.teardownIface(ifaceName); 72 } 73 mIWifiP2pIface = null; 74 mValid = false; 75 } 76 77 @Override onDestroyed(String ifaceName)78 public void onDestroyed(String ifaceName) { 79 Log.d(TAG, "P2P InterfaceDestroyedListener " + ifaceName); 80 if (!mValid) { 81 Log.d(TAG, "Ignoring stale interface destroyed listener"); 82 return; 83 } 84 teardownAndInvalidate(ifaceName); 85 mExternalListener.onDestroyed(ifaceName); 86 } 87 } 88 WifiP2pNative( WifiNl80211Manager wifiNl80211Manager, WifiNative wifiNative, WifiVendorHal wifiVendorHal, SupplicantP2pIfaceHal p2pIfaceHal, HalDeviceManager halDeviceManager, PropertyService propertyService)89 public WifiP2pNative( 90 WifiNl80211Manager wifiNl80211Manager, 91 WifiNative wifiNative, 92 WifiVendorHal wifiVendorHal, 93 SupplicantP2pIfaceHal p2pIfaceHal, 94 HalDeviceManager halDeviceManager, 95 PropertyService propertyService) { 96 mWifiNative = wifiNative; 97 mWifiNl80211Manager = wifiNl80211Manager; 98 mWifiVendorHal = wifiVendorHal; 99 mSupplicantP2pIfaceHal = p2pIfaceHal; 100 mHalDeviceManager = halDeviceManager; 101 mPropertyService = propertyService; 102 } 103 104 /** 105 * Enable verbose logging for all sub modules. 106 */ enableVerboseLogging(int verbose)107 public void enableVerboseLogging(int verbose) { 108 mVerboseLoggingEnabled = verbose > 0; 109 SupplicantP2pIfaceHal.enableVerboseLogging(verbose); 110 } 111 112 private static final int CONNECT_TO_SUPPLICANT_SAMPLING_INTERVAL_MS = 100; 113 private static final int CONNECT_TO_SUPPLICANT_MAX_SAMPLES = 50; 114 /** 115 * This method is called to wait for establishing connection to wpa_supplicant. 116 * 117 * @return true if connection is established, false otherwise. 118 */ waitForSupplicantConnection()119 private boolean waitForSupplicantConnection() { 120 // Start initialization if not already started. 121 if (!mSupplicantP2pIfaceHal.isInitializationStarted() 122 && !mSupplicantP2pIfaceHal.initialize()) { 123 return false; 124 } 125 int connectTries = 0; 126 while (connectTries++ < CONNECT_TO_SUPPLICANT_MAX_SAMPLES) { 127 // Check if the initialization is complete. 128 if (mSupplicantP2pIfaceHal.isInitializationComplete()) { 129 return true; 130 } 131 try { 132 Thread.sleep(CONNECT_TO_SUPPLICANT_SAMPLING_INTERVAL_MS); 133 } catch (InterruptedException ignore) { 134 } 135 } 136 return false; 137 } 138 139 /** 140 * Close supplicant connection. 141 */ closeSupplicantConnection()142 public void closeSupplicantConnection() { 143 // Nothing to do for HIDL. 144 } 145 146 /** 147 * Returns whether HAL (HIDL) is supported on this device or not. 148 */ isHalInterfaceSupported()149 public boolean isHalInterfaceSupported() { 150 return mHalDeviceManager.isSupported(); 151 } 152 153 private static final String P2P_IFACE_NAME = "p2p0"; 154 private static final String P2P_INTERFACE_PROPERTY = "wifi.direct.interface"; 155 /** 156 * Helper function to handle creation of P2P iface. 157 * For devices which do not the support the HAL, this will bypass HalDeviceManager & 158 * teardown any existing iface. 159 */ createP2pIface(Handler handler, WorkSource requestorWs)160 private String createP2pIface(Handler handler, WorkSource requestorWs) { 161 if (mHalDeviceManager.isSupported()) { 162 mIWifiP2pIface = mHalDeviceManager 163 .createP2pIface(mInterfaceDestroyedListener, handler, requestorWs); 164 if (mIWifiP2pIface == null) { 165 Log.e(TAG, "Failed to create P2p iface in HalDeviceManager"); 166 return null; 167 } 168 String ifaceName = HalDeviceManager.getName(mIWifiP2pIface); 169 if (TextUtils.isEmpty(ifaceName)) { 170 Log.e(TAG, "Failed to get p2p iface name"); 171 teardownInterface(); 172 return null; 173 } 174 return ifaceName; 175 } else { 176 Log.i(TAG, "Vendor Hal is not supported, ignoring createP2pIface."); 177 return mPropertyService.getString(P2P_INTERFACE_PROPERTY, P2P_IFACE_NAME); 178 } 179 } 180 181 /** 182 * Setup Interface for P2p mode. 183 * 184 * @param destroyedListener Listener to be invoked when the interface is destroyed. 185 * @param handler Handler to be used for invoking the destroyedListener. 186 * @param requestorWs Worksource to attribute the request to. 187 */ setupInterface( @onNull HalDeviceManager.InterfaceDestroyedListener destroyedListener, @NonNull Handler handler, @NonNull WorkSource requestorWs)188 public String setupInterface( 189 @NonNull HalDeviceManager.InterfaceDestroyedListener destroyedListener, 190 @NonNull Handler handler, @NonNull WorkSource requestorWs) { 191 Log.d(TAG, "Setup P2P interface"); 192 if (mIWifiP2pIface == null) { 193 mInterfaceDestroyedListener = 194 new InterfaceDestroyedListenerInternal(destroyedListener); 195 String ifaceName = createP2pIface(handler, requestorWs); 196 if (ifaceName == null) { 197 Log.e(TAG, "Failed to create P2p iface"); 198 return null; 199 } 200 if (!waitForSupplicantConnection()) { 201 Log.e(TAG, "Failed to connect to supplicant"); 202 teardownInterface(); 203 return null; 204 } 205 if (!mSupplicantP2pIfaceHal.setupIface(ifaceName)) { 206 Log.e(TAG, "Failed to setup P2p iface in supplicant"); 207 teardownInterface(); 208 return null; 209 } 210 Log.i(TAG, "P2P interface setup completed"); 211 return ifaceName; 212 } else { 213 Log.i(TAG, "P2P interface is already existed"); 214 return mHalDeviceManager.isSupported() 215 ? HalDeviceManager.getName(mIWifiP2pIface) 216 : mPropertyService.getString(P2P_INTERFACE_PROPERTY, P2P_IFACE_NAME); 217 } 218 } 219 220 /** 221 * Teardown P2p interface. 222 */ teardownInterface()223 public void teardownInterface() { 224 Log.d(TAG, "Teardown P2P interface"); 225 if (mHalDeviceManager.isSupported()) { 226 if (mIWifiP2pIface != null) { 227 String ifaceName = HalDeviceManager.getName(mIWifiP2pIface); 228 mHalDeviceManager.removeIface(mIWifiP2pIface); 229 mInterfaceDestroyedListener.teardownAndInvalidate(ifaceName); 230 Log.i(TAG, "P2P interface teardown completed"); 231 } 232 } else { 233 Log.i(TAG, "HAL (HIDL) is not supported. Destroy listener for the interface."); 234 String ifaceName = mPropertyService.getString(P2P_INTERFACE_PROPERTY, P2P_IFACE_NAME); 235 mInterfaceDestroyedListener.teardownAndInvalidate(ifaceName); 236 } 237 } 238 239 /** 240 * Replace requestorWs in-place when iface is already enabled. 241 */ replaceRequestorWs(WorkSource requestorWs)242 public boolean replaceRequestorWs(WorkSource requestorWs) { 243 if (mHalDeviceManager.isSupported()) { 244 if (mIWifiP2pIface == null) return false; 245 return mHalDeviceManager.replaceRequestorWs(mIWifiP2pIface, requestorWs); 246 } else { 247 Log.i(TAG, "HAL (HIDL) is not supported. Ignore replace requestorWs"); 248 return true; 249 } 250 } 251 252 /** 253 * Set WPS device name. 254 * 255 * @param name String to be set. 256 * @return true if request is sent successfully, false otherwise. 257 */ setDeviceName(String name)258 public boolean setDeviceName(String name) { 259 return mSupplicantP2pIfaceHal.setWpsDeviceName(name); 260 } 261 262 /** 263 * Populate list of available networks or update existing list. 264 * 265 * @return true, if list has been modified. 266 */ p2pListNetworks(WifiP2pGroupList groups)267 public boolean p2pListNetworks(WifiP2pGroupList groups) { 268 return mSupplicantP2pIfaceHal.loadGroups(groups); 269 } 270 271 /** 272 * Initiate WPS Push Button setup. 273 * The PBC operation requires that a button is also pressed at the 274 * AP/Registrar at about the same time (2 minute window). 275 * 276 * @param iface Group interface name to use. 277 * @param bssid BSSID of the AP. Use zero'ed bssid to indicate wildcard. 278 * @return true, if operation was successful. 279 */ startWpsPbc(String iface, String bssid)280 public boolean startWpsPbc(String iface, String bssid) { 281 return mSupplicantP2pIfaceHal.startWpsPbc(iface, bssid); 282 } 283 284 /** 285 * Initiate WPS Pin Keypad setup. 286 * 287 * @param iface Group interface name to use. 288 * @param pin 8 digit pin to be used. 289 * @return true, if operation was successful. 290 */ startWpsPinKeypad(String iface, String pin)291 public boolean startWpsPinKeypad(String iface, String pin) { 292 return mSupplicantP2pIfaceHal.startWpsPinKeypad(iface, pin); 293 } 294 295 /** 296 * Initiate WPS Pin Display setup. 297 * 298 * @param iface Group interface name to use. 299 * @param bssid BSSID of the AP. Use zero'ed bssid to indicate wildcard. 300 * @return generated pin if operation was successful, null otherwise. 301 */ startWpsPinDisplay(String iface, String bssid)302 public String startWpsPinDisplay(String iface, String bssid) { 303 return mSupplicantP2pIfaceHal.startWpsPinDisplay(iface, bssid); 304 } 305 306 /** 307 * Remove network with provided id. 308 * 309 * @param netId Id of the network to lookup. 310 * @return true, if operation was successful. 311 */ removeP2pNetwork(int netId)312 public boolean removeP2pNetwork(int netId) { 313 return mSupplicantP2pIfaceHal.removeNetwork(netId); 314 } 315 316 /** 317 * Set WPS device name. 318 * 319 * @param name String to be set. 320 * @return true if request is sent successfully, false otherwise. 321 */ setP2pDeviceName(String name)322 public boolean setP2pDeviceName(String name) { 323 return mSupplicantP2pIfaceHal.setWpsDeviceName(name); 324 } 325 326 /** 327 * Set WPS device type. 328 * 329 * @param type Type specified as a string. Used format: <categ>-<OUI>-<subcateg> 330 * @return true if request is sent successfully, false otherwise. 331 */ setP2pDeviceType(String type)332 public boolean setP2pDeviceType(String type) { 333 return mSupplicantP2pIfaceHal.setWpsDeviceType(type); 334 } 335 336 /** 337 * Set WPS config methods 338 * 339 * @param cfg List of config methods. 340 * @return true if request is sent successfully, false otherwise. 341 */ setConfigMethods(String cfg)342 public boolean setConfigMethods(String cfg) { 343 return mSupplicantP2pIfaceHal.setWpsConfigMethods(cfg); 344 } 345 346 /** 347 * Set the postfix to be used for P2P SSID's. 348 * 349 * @param postfix String to be appended to SSID. 350 * 351 * @return boolean value indicating whether operation was successful. 352 */ setP2pSsidPostfix(String postfix)353 public boolean setP2pSsidPostfix(String postfix) { 354 return mSupplicantP2pIfaceHal.setSsidPostfix(postfix); 355 } 356 357 /** 358 * Set the Maximum idle time in seconds for P2P groups. 359 * This value controls how long a P2P group is maintained after there 360 * is no other members in the group. As a group owner, this means no 361 * associated stations in the group. As a P2P client, this means no 362 * group owner seen in scan results. 363 * 364 * @param iface Group interface name to use. 365 * @param time Timeout value in seconds. 366 * 367 * @return boolean value indicating whether operation was successful. 368 */ setP2pGroupIdle(String iface, int time)369 public boolean setP2pGroupIdle(String iface, int time) { 370 return mSupplicantP2pIfaceHal.setGroupIdle(iface, time); 371 } 372 373 /** 374 * Turn on/off power save mode for the interface. 375 * 376 * @param iface Group interface name to use. 377 * @param enabled Indicate if power save is to be turned on/off. 378 * 379 * @return boolean value indicating whether operation was successful. 380 */ setP2pPowerSave(String iface, boolean enabled)381 public boolean setP2pPowerSave(String iface, boolean enabled) { 382 return mSupplicantP2pIfaceHal.setPowerSave(iface, enabled); 383 } 384 385 /** 386 * Enable/Disable Wifi Display. 387 * 388 * @param enable true to enable, false to disable. 389 * @return true, if operation was successful. 390 */ setWfdEnable(boolean enable)391 public boolean setWfdEnable(boolean enable) { 392 return mSupplicantP2pIfaceHal.enableWfd(enable); 393 } 394 395 /** 396 * Set Wifi Display device info. 397 * 398 * @param hex WFD device info as described in section 5.1.2 of WFD technical 399 * specification v1.0.0. 400 * @return true, if operation was successful. 401 */ setWfdDeviceInfo(String hex)402 public boolean setWfdDeviceInfo(String hex) { 403 return mSupplicantP2pIfaceHal.setWfdDeviceInfo(hex); 404 } 405 406 /** 407 * Initiate a P2P service discovery indefinitely. 408 * Will trigger {@link WifiP2pMonitor#P2P_DEVICE_FOUND_EVENT} on finding devices. 409 * 410 * @return boolean value indicating whether operation was successful. 411 */ p2pFind()412 public boolean p2pFind() { 413 return p2pFind(0); 414 } 415 416 /** 417 * Initiate a P2P service discovery with a (optional) timeout. 418 * 419 * @param timeout Max time to be spent is peforming discovery. 420 * Set to 0 to indefinely continue discovery untill and explicit 421 * |stopFind| is sent. 422 * @return boolean value indicating whether operation was successful. 423 */ p2pFind(int timeout)424 public boolean p2pFind(int timeout) { 425 return mSupplicantP2pIfaceHal.find(timeout); 426 } 427 428 /** 429 * Stop an ongoing P2P service discovery. 430 * 431 * @return boolean value indicating whether operation was successful. 432 */ p2pStopFind()433 public boolean p2pStopFind() { 434 return mSupplicantP2pIfaceHal.stopFind(); 435 } 436 437 /** 438 * Configure Extended Listen Timing. 439 * 440 * If enabled, listen state must be entered every |intervalInMillis| for at 441 * least |periodInMillis|. Both values have acceptable range of 1-65535 442 * (with interval obviously having to be larger than or equal to duration). 443 * If the P2P module is not idle at the time the Extended Listen Timing 444 * timeout occurs, the Listen State operation must be skipped. 445 * 446 * @param enable Enables or disables listening. 447 * @param period Period in milliseconds. 448 * @param interval Interval in milliseconds. 449 * 450 * @return true, if operation was successful. 451 */ p2pExtListen(boolean enable, int period, int interval)452 public boolean p2pExtListen(boolean enable, int period, int interval) { 453 return mSupplicantP2pIfaceHal.configureExtListen(enable, period, interval); 454 } 455 456 /** 457 * Set P2P Listen channel. 458 * 459 * When specifying a social channel on the 2.4 GHz band (1/6/11) there is no 460 * need to specify the operating class since it defaults to 81. When 461 * specifying a social channel on the 60 GHz band (2), specify the 60 GHz 462 * operating class (180). 463 * 464 * @param lc Wifi channel. eg, 1, 6, 11. 465 * 466 * @return true, if operation was successful. 467 */ p2pSetListenChannel(int lc)468 public boolean p2pSetListenChannel(int lc) { 469 return mSupplicantP2pIfaceHal.setListenChannel(lc); 470 } 471 472 /** 473 * Set P2P operating channel. 474 * 475 * @param oc Wifi channel, eg, 1, 6, 11. 476 * @param unsafeChannels channels are not allowed. 477 * @return true if operation was successful. 478 */ p2pSetOperatingChannel(int oc, @NonNull List<CoexUnsafeChannel> unsafeChannels)479 public boolean p2pSetOperatingChannel(int oc, @NonNull List<CoexUnsafeChannel> unsafeChannels) { 480 if (null == unsafeChannels) { 481 Log.wtf(TAG, "unsafeChannels is null."); 482 return false; 483 } 484 return mSupplicantP2pIfaceHal.setOperatingChannel(oc, unsafeChannels); 485 } 486 487 /** 488 * Flush P2P peer table and state. 489 * 490 * @return boolean value indicating whether operation was successful. 491 */ p2pFlush()492 public boolean p2pFlush() { 493 return mSupplicantP2pIfaceHal.flush(); 494 } 495 496 /** 497 * Start P2P group formation with a discovered P2P peer. This includes 498 * optional group owner negotiation, group interface setup, provisioning, 499 * and establishing data connection. 500 * 501 * @param config Configuration to use to connect to remote device. 502 * @param joinExistingGroup Indicates that this is a command to join an 503 * existing group as a client. It skips the group owner negotiation 504 * part. This must send a Provision Discovery Request message to the 505 * target group owner before associating for WPS provisioning. 506 * 507 * @return String containing generated pin, if selected provision method 508 * uses PIN. 509 */ p2pConnect(WifiP2pConfig config, boolean joinExistingGroup)510 public String p2pConnect(WifiP2pConfig config, boolean joinExistingGroup) { 511 return mSupplicantP2pIfaceHal.connect(config, joinExistingGroup); 512 } 513 514 /** 515 * Cancel an ongoing P2P group formation and joining-a-group related 516 * operation. This operation unauthorizes the specific peer device (if any 517 * had been authorized to start group formation), stops P2P find (if in 518 * progress), stops pending operations for join-a-group, and removes the 519 * P2P group interface (if one was used) that is in the WPS provisioning 520 * step. If the WPS provisioning step has been completed, the group is not 521 * terminated. 522 * 523 * @return boolean value indicating whether operation was successful. 524 */ p2pCancelConnect()525 public boolean p2pCancelConnect() { 526 return mSupplicantP2pIfaceHal.cancelConnect(); 527 } 528 529 /** 530 * Send P2P provision discovery request to the specified peer. The 531 * parameters for this command are the P2P device address of the peer and the 532 * desired configuration method. 533 * 534 * @param config Config class describing peer setup. 535 * 536 * @return boolean value indicating whether operation was successful. 537 */ p2pProvisionDiscovery(WifiP2pConfig config)538 public boolean p2pProvisionDiscovery(WifiP2pConfig config) { 539 return mSupplicantP2pIfaceHal.provisionDiscovery(config); 540 } 541 542 /** 543 * Set up a P2P group owner manually. 544 * This is a helper method that invokes groupAdd(networkId, isPersistent) internally. 545 * 546 * @param persistent Used to request a persistent group to be formed. 547 * 548 * @return true, if operation was successful. 549 */ p2pGroupAdd(boolean persistent)550 public boolean p2pGroupAdd(boolean persistent) { 551 return mSupplicantP2pIfaceHal.groupAdd(persistent); 552 } 553 554 /** 555 * Set up a P2P group owner manually (i.e., without group owner 556 * negotiation with a specific peer). This is also known as autonomous 557 * group owner. 558 * 559 * @param netId Used to specify the restart of a persistent group. 560 * 561 * @return true, if operation was successful. 562 */ p2pGroupAdd(int netId)563 public boolean p2pGroupAdd(int netId) { 564 return mSupplicantP2pIfaceHal.groupAdd(netId, true); 565 } 566 567 /** 568 * Set up a P2P group as Group Owner or join a group with a configuration. 569 * 570 * @param config Used to specify config for setting up a P2P group 571 * 572 * @return true, if operation was successful. 573 */ p2pGroupAdd(WifiP2pConfig config, boolean join)574 public boolean p2pGroupAdd(WifiP2pConfig config, boolean join) { 575 int freq = 0; 576 switch (config.groupOwnerBand) { 577 case WifiP2pConfig.GROUP_OWNER_BAND_2GHZ: 578 freq = 2; 579 break; 580 case WifiP2pConfig.GROUP_OWNER_BAND_5GHZ: 581 freq = 5; 582 break; 583 // treat it as frequency. 584 default: 585 freq = config.groupOwnerBand; 586 } 587 abortWifiRunningScanIfNeeded(join); 588 return mSupplicantP2pIfaceHal.groupAdd( 589 config.networkName, 590 config.passphrase, 591 (config.netId == WifiP2pGroup.NETWORK_ID_PERSISTENT), 592 freq, config.deviceAddress, join); 593 } 594 abortWifiRunningScanIfNeeded(boolean isJoin)595 private void abortWifiRunningScanIfNeeded(boolean isJoin) { 596 if (!isJoin) return; 597 598 Set<String> wifiClientInterfaces = mWifiNative.getClientInterfaceNames(); 599 600 for (String interfaceName: wifiClientInterfaces) { 601 mWifiNl80211Manager.abortScan(interfaceName); 602 } 603 } 604 605 /** 606 * Terminate a P2P group. If a new virtual network interface was used for 607 * the group, it must also be removed. The network interface name of the 608 * group interface is used as a parameter for this command. 609 * 610 * @param iface Group interface name to use. 611 * @return true, if operation was successful. 612 */ p2pGroupRemove(String iface)613 public boolean p2pGroupRemove(String iface) { 614 return mSupplicantP2pIfaceHal.groupRemove(iface); 615 } 616 617 /** 618 * Reject connection attempt from a peer (specified with a device 619 * address). This is a mechanism to reject a pending group owner negotiation 620 * with a peer and request to automatically block any further connection or 621 * discovery of the peer. 622 * 623 * @param deviceAddress MAC address of the device to reject. 624 * 625 * @return boolean value indicating whether operation was successful. 626 */ p2pReject(String deviceAddress)627 public boolean p2pReject(String deviceAddress) { 628 return mSupplicantP2pIfaceHal.reject(deviceAddress); 629 } 630 631 /** 632 * Invite a device to a persistent group. 633 * If the peer device is the group owner of the persistent group, the peer 634 * parameter is not needed. Otherwise it is used to specify which 635 * device to invite. |goDeviceAddress| parameter may be used to override 636 * the group owner device address for Invitation Request should it not be 637 * known for some reason (this should not be needed in most cases). 638 * 639 * @param group Group object to use. 640 * @param deviceAddress MAC address of the device to invite. 641 * 642 * @return boolean value indicating whether operation was successful. 643 */ p2pInvite(WifiP2pGroup group, String deviceAddress)644 public boolean p2pInvite(WifiP2pGroup group, String deviceAddress) { 645 return mSupplicantP2pIfaceHal.invite(group, deviceAddress); 646 } 647 648 /** 649 * Reinvoke a device from a persistent group. 650 * 651 * @param netId Used to specify the persistent group. 652 * @param deviceAddress MAC address of the device to reinvoke. 653 * 654 * @return true, if operation was successful. 655 */ p2pReinvoke(int netId, String deviceAddress)656 public boolean p2pReinvoke(int netId, String deviceAddress) { 657 return mSupplicantP2pIfaceHal.reinvoke(netId, deviceAddress); 658 } 659 660 /** 661 * Gets the operational SSID of the device. 662 * 663 * @param deviceAddress MAC address of the peer. 664 * 665 * @return SSID of the device. 666 */ p2pGetSsid(String deviceAddress)667 public String p2pGetSsid(String deviceAddress) { 668 return mSupplicantP2pIfaceHal.getSsid(deviceAddress); 669 } 670 671 /** 672 * Gets the MAC address of the device. 673 * 674 * @return MAC address of the device. 675 */ p2pGetDeviceAddress()676 public String p2pGetDeviceAddress() { 677 return mSupplicantP2pIfaceHal.getDeviceAddress(); 678 } 679 680 /** 681 * Gets the capability of the group which the device is a 682 * member of. 683 * 684 * @param deviceAddress MAC address of the peer. 685 * 686 * @return combination of |GroupCapabilityMask| values. 687 */ getGroupCapability(String deviceAddress)688 public int getGroupCapability(String deviceAddress) { 689 return mSupplicantP2pIfaceHal.getGroupCapability(deviceAddress); 690 } 691 692 /** 693 * This command can be used to add a upnp/bonjour service. 694 * 695 * @param servInfo List of service queries. 696 * 697 * @return true, if operation was successful. 698 */ p2pServiceAdd(WifiP2pServiceInfo servInfo)699 public boolean p2pServiceAdd(WifiP2pServiceInfo servInfo) { 700 return mSupplicantP2pIfaceHal.serviceAdd(servInfo); 701 } 702 703 /** 704 * This command can be used to remove a upnp/bonjour service. 705 * 706 * @param servInfo List of service queries. 707 * 708 * @return true, if operation was successful. 709 */ p2pServiceDel(WifiP2pServiceInfo servInfo)710 public boolean p2pServiceDel(WifiP2pServiceInfo servInfo) { 711 return mSupplicantP2pIfaceHal.serviceRemove(servInfo); 712 } 713 714 /** 715 * This command can be used to flush all services from the 716 * device. 717 * 718 * @return boolean value indicating whether operation was successful. 719 */ p2pServiceFlush()720 public boolean p2pServiceFlush() { 721 return mSupplicantP2pIfaceHal.serviceFlush(); 722 } 723 724 /** 725 * Schedule a P2P service discovery request. The parameters for this command 726 * are the device address of the peer device (or 00:00:00:00:00:00 for 727 * wildcard query that is sent to every discovered P2P peer that supports 728 * service discovery) and P2P Service Query TLV(s) as hexdump. 729 * 730 * @param addr MAC address of the device to discover. 731 * @param query Hex dump of the query data. 732 * @return identifier Identifier for the request. Can be used to cancel the 733 * request. 734 */ p2pServDiscReq(String addr, String query)735 public String p2pServDiscReq(String addr, String query) { 736 return mSupplicantP2pIfaceHal.requestServiceDiscovery(addr, query); 737 } 738 739 /** 740 * Cancel a previous service discovery request. 741 * 742 * @param id Identifier for the request to cancel. 743 * @return true, if operation was successful. 744 */ p2pServDiscCancelReq(String id)745 public boolean p2pServDiscCancelReq(String id) { 746 return mSupplicantP2pIfaceHal.cancelServiceDiscovery(id); 747 } 748 749 /** 750 * Send driver command to set Miracast mode. 751 * 752 * @param mode Mode of Miracast. 753 * 0 = disabled 754 * 1 = operating as source 755 * 2 = operating as sink 756 */ setMiracastMode(int mode)757 public void setMiracastMode(int mode) { 758 mSupplicantP2pIfaceHal.setMiracastMode(mode); 759 } 760 761 /** 762 * Get NFC handover request message. 763 * 764 * @return select message if created successfully, null otherwise. 765 */ getNfcHandoverRequest()766 public String getNfcHandoverRequest() { 767 return mSupplicantP2pIfaceHal.getNfcHandoverRequest(); 768 } 769 770 /** 771 * Get NFC handover select message. 772 * 773 * @return select message if created successfully, null otherwise. 774 */ getNfcHandoverSelect()775 public String getNfcHandoverSelect() { 776 return mSupplicantP2pIfaceHal.getNfcHandoverSelect(); 777 } 778 779 /** 780 * Report NFC handover select message. 781 * 782 * @return true if reported successfully, false otherwise. 783 */ initiatorReportNfcHandover(String selectMessage)784 public boolean initiatorReportNfcHandover(String selectMessage) { 785 return mSupplicantP2pIfaceHal.initiatorReportNfcHandover(selectMessage); 786 } 787 788 /** 789 * Report NFC handover request message. 790 * 791 * @return true if reported successfully, false otherwise. 792 */ responderReportNfcHandover(String requestMessage)793 public boolean responderReportNfcHandover(String requestMessage) { 794 return mSupplicantP2pIfaceHal.responderReportNfcHandover(requestMessage); 795 } 796 797 /** 798 * Set the client list for the provided network. 799 * 800 * @param netId Id of the network. 801 * @return Space separated list of clients if successfull, null otherwise. 802 */ getP2pClientList(int netId)803 public String getP2pClientList(int netId) { 804 return mSupplicantP2pIfaceHal.getClientList(netId); 805 } 806 807 /** 808 * Set the client list for the provided network. 809 * 810 * @param netId Id of the network. 811 * @param list Space separated list of clients. 812 * @return true, if operation was successful. 813 */ setP2pClientList(int netId, String list)814 public boolean setP2pClientList(int netId, String list) { 815 return mSupplicantP2pIfaceHal.setClientList(netId, list); 816 } 817 818 /** 819 * Save the current configuration to p2p_supplicant.conf. 820 * 821 * @return true on success, false otherwise. 822 */ saveConfig()823 public boolean saveConfig() { 824 return mSupplicantP2pIfaceHal.saveConfig(); 825 } 826 827 /** 828 * Enable/Disable MAC randomization. 829 * 830 * @param enable true to enable, false to disable. 831 * @return true, if operation was successful. 832 */ setMacRandomization(boolean enable)833 public boolean setMacRandomization(boolean enable) { 834 return mSupplicantP2pIfaceHal.setMacRandomization(enable); 835 } 836 837 /** 838 * Get the supported features 839 * 840 * @param ifaceName Name of the interface. 841 * @return bitmask defined by WifiManager.WIFI_FEATURE_* 842 */ getSupportedFeatureSet(@onNull String ifaceName)843 public long getSupportedFeatureSet(@NonNull String ifaceName) { 844 return mWifiVendorHal.getSupportedFeatureSet(ifaceName); 845 } 846 847 /** 848 * Set Wifi Display R2 device info. 849 * 850 * @param hex WFD device info as described in section 5.1.12 of WFD technical 851 * specification v2.1.0. 852 * @return true, if operation was successful. 853 */ setWfdR2DeviceInfo(String hex)854 public boolean setWfdR2DeviceInfo(String hex) { 855 return mSupplicantP2pIfaceHal.setWfdR2DeviceInfo(hex); 856 } 857 } 858