1 /* 2 * Copyright (C) 2021 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.net.wifi.CoexUnsafeChannel; 22 import android.net.wifi.ScanResult; 23 import android.net.wifi.p2p.WifiP2pConfig; 24 import android.net.wifi.p2p.WifiP2pDiscoveryConfig; 25 import android.net.wifi.p2p.WifiP2pExtListenParams; 26 import android.net.wifi.p2p.WifiP2pGroup; 27 import android.net.wifi.p2p.WifiP2pGroupList; 28 import android.net.wifi.p2p.WifiP2pManager; 29 import android.net.wifi.p2p.nsd.WifiP2pServiceInfo; 30 31 import com.android.server.wifi.WifiNative; 32 33 import java.util.List; 34 import java.util.Set; 35 36 /** Abstraction of Supplicant P2P Iface HAL interface */ 37 interface ISupplicantP2pIfaceHal { 38 /** 39 * Begin initializing the ISupplicantP2pIfaceHal object. Specific initialization 40 * logic differs between the HIDL and AIDL implementations. 41 * 42 * @return true if the initialization routine was successful 43 */ initialize()44 boolean initialize(); 45 46 /** 47 * Set the debug log level for wpa_supplicant 48 * 49 * @param turnOnVerbose Whether to turn on verbose logging or not. 50 * @param globalShowKeys Whether show keys is true in WifiGlobals. 51 * @return true if request is sent successfully, false otherwise. 52 */ setLogLevel(boolean turnOnVerbose, boolean globalShowKeys)53 boolean setLogLevel(boolean turnOnVerbose, boolean globalShowKeys); 54 55 /** 56 * Setup the P2P iface. 57 * 58 * @param ifaceName Name of the interface. 59 * @return true on success, false otherwise. 60 */ setupIface(@onNull String ifaceName)61 boolean setupIface(@NonNull String ifaceName); 62 63 /** 64 * Teardown the P2P interface. 65 * 66 * @param ifaceName Name of the interface. 67 * @return true on success, false otherwise. 68 */ teardownIface(@onNull String ifaceName)69 boolean teardownIface(@NonNull String ifaceName); 70 71 /** 72 * Signals whether initialization started successfully. 73 */ isInitializationStarted()74 boolean isInitializationStarted(); 75 76 /** 77 * Signals whether Initialization completed successfully. Only necessary for testing, is not 78 * needed to guard calls etc. 79 */ isInitializationComplete()80 boolean isInitializationComplete(); 81 82 /** 83 * Initiate a P2P service discovery with a (optional) timeout. 84 * 85 * @param timeout Max time to be spent is performing discovery. 86 * Set to 0 to indefinitely continue discovery until an explicit 87 * |stopFind| is sent. 88 * @return boolean value indicating whether operation was successful. 89 */ find(int timeout)90 boolean find(int timeout); 91 92 /** 93 * Initiate a P2P device discovery with a scan type, a (optional) frequency, and a (optional) 94 * timeout. 95 * 96 * @param type indicates what channels to scan. 97 * Valid values are {@link WifiP2pManager#WIFI_P2P_SCAN_FULL} for doing full P2P scan, 98 * {@link WifiP2pManager#WIFI_P2P_SCAN_SOCIAL} for scanning social channels, 99 * {@link WifiP2pManager#WIFI_P2P_SCAN_SINGLE_FREQ} for scanning a specified frequency. 100 * @param freq is the frequency to be scanned. 101 * The possible values are: 102 * <ul> 103 * <li> A valid frequency for {@link WifiP2pManager#WIFI_P2P_SCAN_SINGLE_FREQ}</li> 104 * <li> {@link WifiP2pManager#WIFI_P2P_SCAN_FREQ_UNSPECIFIED} for 105 * {@link WifiP2pManager#WIFI_P2P_SCAN_FULL} and 106 * {@link WifiP2pManager#WIFI_P2P_SCAN_SOCIAL}</li> 107 * </ul> 108 * @param timeout Max time to be spent is performing discovery. 109 * Set to 0 to indefinitely continue discovery until an explicit 110 * |stopFind| is sent. 111 * @return boolean value indicating whether operation was successful. 112 */ find(@ifiP2pManager.WifiP2pScanType int type, int freq, int timeout)113 boolean find(@WifiP2pManager.WifiP2pScanType int type, int freq, int timeout); 114 115 /** 116 * Initiate P2P device discovery with config params. 117 * 118 * @param config The config parameters to initiate P2P discovery. 119 * @param timeout The maximum amount of time to be spent in performing discovery. 120 * Set to 0 to indefinitely continue discovery until an explicit 121 * |stopFind| is sent. 122 * @return boolean value indicating whether the operation was successful. 123 */ findWithParams(@onNull WifiP2pDiscoveryConfig config, int timeout)124 default boolean findWithParams(@NonNull WifiP2pDiscoveryConfig config, int timeout) { 125 return false; 126 } 127 128 /** 129 * Stop an ongoing P2P service discovery. 130 * 131 * @return boolean value indicating whether operation was successful. 132 */ stopFind()133 boolean stopFind(); 134 135 /** 136 * Flush P2P peer table and state. 137 * 138 * @return boolean value indicating whether operation was successful. 139 */ flush()140 boolean flush(); 141 142 /** 143 * This command can be used to flush all services from the 144 * device. 145 * 146 * @return boolean value indicating whether operation was successful. 147 */ serviceFlush()148 boolean serviceFlush(); 149 150 /** 151 * Turn on/off power save mode for the interface. 152 * 153 * @param groupIfName Group interface name to use. 154 * @param enable Indicate if power save is to be turned on/off. 155 * 156 * @return boolean value indicating whether operation was successful. 157 */ setPowerSave(String groupIfName, boolean enable)158 boolean setPowerSave(String groupIfName, boolean enable); 159 160 /** 161 * Set the Maximum idle time in seconds for P2P groups. 162 * This value controls how long a P2P group is maintained after there 163 * is no other members in the group. As a group owner, this means no 164 * associated stations in the group. As a P2P client, this means no 165 * group owner seen in scan results. 166 * 167 * @param groupIfName Group interface name to use. 168 * @param timeoutInSec Timeout value in seconds. 169 * 170 * @return boolean value indicating whether operation was successful. 171 */ setGroupIdle(String groupIfName, int timeoutInSec)172 boolean setGroupIdle(String groupIfName, int timeoutInSec); 173 174 /** 175 * Set the postfix to be used for P2P SSID's. 176 * 177 * @param postfix String to be appended to SSID. 178 * 179 * @return boolean value indicating whether operation was successful. 180 */ setSsidPostfix(String postfix)181 boolean setSsidPostfix(String postfix); 182 183 /** 184 * Start P2P group formation with a discovered P2P peer. This includes 185 * optional group owner negotiation, group interface setup, provisioning, 186 * and establishing data connection. 187 * 188 * @param config Configuration to use to connect to remote device. 189 * @param joinExistingGroup Indicates that this is a command to join an 190 * existing group as a client. It skips the group owner negotiation 191 * part. This must send a Provision Discovery Request message to the 192 * target group owner before associating for WPS provisioning. 193 * 194 * @return String containing generated pin, if selected provision method 195 * uses PIN. 196 */ connect(WifiP2pConfig config, boolean joinExistingGroup)197 String connect(WifiP2pConfig config, boolean joinExistingGroup); 198 199 /** 200 * Cancel an ongoing P2P group formation and joining-a-group related 201 * operation. This operation unauthorizes the specific peer device (if any 202 * had been authorized to start group formation), stops P2P find (if in 203 * progress), stops pending operations for join-a-group, and removes the 204 * P2P group interface (if one was used) that is in the WPS provisioning 205 * step. If the WPS provisioning step has been completed, the group is not 206 * terminated. 207 * 208 * @return boolean value indicating whether operation was successful. 209 */ cancelConnect()210 boolean cancelConnect(); 211 212 /** 213 * Send P2P provision discovery request to the specified peer. The 214 * parameters for this command are the P2P device address of the peer and the 215 * desired configuration method. 216 * 217 * @param config Config class describing peer setup. 218 * 219 * @return boolean value indicating whether operation was successful. 220 */ provisionDiscovery(WifiP2pConfig config)221 boolean provisionDiscovery(WifiP2pConfig config); 222 223 /** 224 * Invite a device to a persistent group. 225 * If the peer device is the group owner of the persistent group, the peer 226 * parameter is not needed. Otherwise it is used to specify which 227 * device to invite. |goDeviceAddress| parameter may be used to override 228 * the group owner device address for Invitation Request should it not be 229 * known for some reason (this should not be needed in most cases). 230 * 231 * @param group Group object to use. 232 * @param peerAddress MAC address of the device to invite. 233 * 234 * @return boolean value indicating whether operation was successful. 235 */ invite(WifiP2pGroup group, String peerAddress)236 boolean invite(WifiP2pGroup group, String peerAddress); 237 238 /** 239 * Reject connection attempt from a peer (specified with a device 240 * address). This is a mechanism to reject a pending group owner negotiation 241 * with a peer and request to automatically block any further connection or 242 * discovery of the peer. 243 * 244 * @param peerAddress MAC address of the device to reject. 245 * 246 * @return boolean value indicating whether operation was successful. 247 */ reject(String peerAddress)248 boolean reject(String peerAddress); 249 250 /** 251 * Gets the MAC address of the device. 252 * 253 * @return MAC address of the device. 254 */ getDeviceAddress()255 String getDeviceAddress(); 256 257 /** 258 * Gets the operational SSID of the device. 259 * 260 * @param address MAC address of the peer. 261 * 262 * @return SSID of the device. 263 */ getSsid(String address)264 String getSsid(String address); 265 266 /** 267 * Reinvoke a device from a persistent group. 268 * 269 * @param networkId Used to specify the persistent group. 270 * @param peerAddress MAC address of the device to reinvoke. 271 * 272 * @return true, if operation was successful. 273 */ reinvoke(int networkId, String peerAddress)274 boolean reinvoke(int networkId, String peerAddress); 275 276 /** 277 * Set up a P2P group owner manually (i.e., without group owner 278 * negotiation with a specific peer). This is also known as autonomous 279 * group owner. 280 * 281 * @param networkId Used to specify the restart of a persistent group. 282 * @param isPersistent Used to request a persistent group to be formed. 283 * 284 * @return true, if operation was successful. 285 */ groupAdd(int networkId, boolean isPersistent)286 boolean groupAdd(int networkId, boolean isPersistent); 287 288 /** 289 * Set up a P2P group as Group Owner or join a group with a configuration. 290 * 291 * @param networkName SSID of the group to be formed 292 * @param passphrase passphrase of the group to be formed 293 * @param isPersistent Used to request a persistent group to be formed. 294 * @param freq preferred frequency or band of the group to be formed 295 * @param peerAddress peerAddress Group Owner MAC address, only applied for Group Client. 296 * If the MAC is "00:00:00:00:00:00", the device will try to find a peer 297 * whose SSID matches ssid. 298 * @param join join a group or create a group 299 * 300 * @return true, if operation was successful. 301 */ groupAdd(String networkName, String passphrase, boolean isPersistent, int freq, String peerAddress, boolean join)302 boolean groupAdd(String networkName, String passphrase, 303 boolean isPersistent, int freq, String peerAddress, boolean join); 304 305 /** 306 * Terminate a P2P group. If a new virtual network interface was used for 307 * the group, it must also be removed. The network interface name of the 308 * group interface is used as a parameter for this command. 309 * 310 * @param groupName Group interface name to use. 311 * 312 * @return true, if operation was successful. 313 */ groupRemove(String groupName)314 boolean groupRemove(String groupName); 315 316 /** 317 * Gets the capability of the group which the device is a 318 * member of. 319 * 320 * @param peerAddress MAC address of the peer. 321 * 322 * @return combination of |GroupCapabilityMask| values. 323 */ getGroupCapability(String peerAddress)324 int getGroupCapability(String peerAddress); 325 326 /** 327 * Configure Extended Listen Timing. 328 * 329 * If enabled, listen state must be entered every |intervalInMillis| for at 330 * least |periodInMillis|. Both values have acceptable range of 1-65535 331 * (with interval obviously having to be larger than or equal to duration). 332 * If the P2P module is not idle at the time the Extended Listen Timing 333 * timeout occurs, the Listen State operation must be skipped. 334 * 335 * @param enable Enables or disables listening. 336 * @param periodInMillis Period in milliseconds. 337 * @param intervalInMillis Interval in milliseconds. 338 * @param extListenParams Additional parameter struct for this request. 339 * 340 * @return true, if operation was successful. 341 */ configureExtListen(boolean enable, int periodInMillis, int intervalInMillis, @Nullable WifiP2pExtListenParams extListenParams)342 boolean configureExtListen(boolean enable, int periodInMillis, int intervalInMillis, 343 @Nullable WifiP2pExtListenParams extListenParams); 344 345 /** 346 * Set P2P Listen channel. 347 * 348 * @param listenChannel Wifi channel. eg, 1, 6, 11. 349 * 350 * @return true, if operation was successful. 351 */ setListenChannel(int listenChannel)352 boolean setListenChannel(int listenChannel); 353 354 /** 355 * Set P2P operating channel. 356 * 357 * @param operatingChannel the desired operating channel. 358 * @param unsafeChannels channels which p2p cannot use. 359 * 360 * @return true, if operation was successful. 361 */ setOperatingChannel(int operatingChannel, @NonNull List<CoexUnsafeChannel> unsafeChannels)362 boolean setOperatingChannel(int operatingChannel, 363 @NonNull List<CoexUnsafeChannel> unsafeChannels); 364 365 /** 366 * This command can be used to add a upnp/bonjour service. 367 * 368 * @param servInfo List of service queries. 369 * 370 * @return true, if operation was successful. 371 */ serviceAdd(WifiP2pServiceInfo servInfo)372 boolean serviceAdd(WifiP2pServiceInfo servInfo); 373 374 /** 375 * This command can be used to remove a upnp/bonjour service. 376 * 377 * @param servInfo List of service queries. 378 * 379 * @return true, if operation was successful. 380 */ serviceRemove(WifiP2pServiceInfo servInfo)381 boolean serviceRemove(WifiP2pServiceInfo servInfo); 382 383 /** 384 * Schedule a P2P service discovery request. The parameters for this command 385 * are the device address of the peer device (or 00:00:00:00:00:00 for 386 * wildcard query that is sent to every discovered P2P peer that supports 387 * service discovery) and P2P Service Query TLV(s) as hexdump. 388 * 389 * @param peerAddress MAC address of the device to discover. 390 * @param query Hex dump of the query data. 391 * @return identifier Identifier for the request. Can be used to cancel the 392 * request. 393 */ requestServiceDiscovery(String peerAddress, String query)394 String requestServiceDiscovery(String peerAddress, String query); 395 396 /** 397 * Cancel a previous service discovery request. 398 * 399 * @param identifier Identifier for the request to cancel. 400 * @return true, if operation was successful. 401 */ cancelServiceDiscovery(String identifier)402 boolean cancelServiceDiscovery(String identifier); 403 404 /** 405 * Send driver command to set Miracast mode. 406 * 407 * @param mode Mode of Miracast. 408 * @return true, if operation was successful. 409 */ setMiracastMode(int mode)410 boolean setMiracastMode(int mode); 411 412 /** 413 * Initiate WPS Push Button setup. 414 * The PBC operation requires that a button is also pressed at the 415 * AP/Registrar at about the same time (2 minute window). 416 * 417 * @param groupIfName Group interface name to use. 418 * @param bssid BSSID of the AP. Use empty bssid to indicate wildcard. 419 * @return true, if operation was successful. 420 */ startWpsPbc(String groupIfName, String bssid)421 boolean startWpsPbc(String groupIfName, String bssid); 422 423 /** 424 * Initiate WPS Pin Keypad setup. 425 * 426 * @param groupIfName Group interface name to use. 427 * @param pin 8 digit pin to be used. 428 * @return true, if operation was successful. 429 */ startWpsPinKeypad(String groupIfName, String pin)430 boolean startWpsPinKeypad(String groupIfName, String pin); 431 432 /** 433 * Initiate WPS Pin Display setup. 434 * 435 * @param groupIfName Group interface name to use. 436 * @param bssid BSSID of the AP. Use empty bssid to indicate wildcard. 437 * @return generated pin if operation was successful, null otherwise. 438 */ startWpsPinDisplay(String groupIfName, String bssid)439 String startWpsPinDisplay(String groupIfName, String bssid); 440 441 /** 442 * Cancel any ongoing WPS operations. 443 * 444 * @param groupIfName Group interface name to use. 445 * @return true, if operation was successful. 446 */ cancelWps(String groupIfName)447 boolean cancelWps(String groupIfName); 448 449 /** 450 * Enable/Disable Wifi Display. 451 * 452 * @param enable true to enable, false to disable. 453 * @return true, if operation was successful. 454 */ enableWfd(boolean enable)455 boolean enableWfd(boolean enable); 456 457 /** 458 * Set Wifi Display device info. 459 * 460 * @param info WFD device info as described in section 5.1.2 of WFD technical 461 * specification v1.0.0. 462 * @return true, if operation was successful. 463 */ setWfdDeviceInfo(String info)464 boolean setWfdDeviceInfo(String info); 465 466 /** 467 * Remove network with provided id. 468 * 469 * @param networkId Id of the network to lookup. 470 * @return true, if operation was successful. 471 */ removeNetwork(int networkId)472 boolean removeNetwork(int networkId); 473 474 /** 475 * Get the persistent group list from wpa_supplicant's p2p mgmt interface 476 * 477 * @param groups WifiP2pGroupList to store persistent groups in 478 * @return true, if list has been modified. 479 */ loadGroups(WifiP2pGroupList groups)480 boolean loadGroups(WifiP2pGroupList groups); 481 482 /** 483 * Set WPS device name. 484 * 485 * @param name String to be set. 486 * @return true if request is sent successfully, false otherwise. 487 */ setWpsDeviceName(String name)488 boolean setWpsDeviceName(String name); 489 490 /** 491 * Set WPS device type. 492 * 493 * @param typeStr Type specified as a string. Used format: <categ>-<OUI>-<subcateg> 494 * @return true if request is sent successfully, false otherwise. 495 */ setWpsDeviceType(String typeStr)496 boolean setWpsDeviceType(String typeStr); 497 498 /** 499 * Set WPS config methods 500 * 501 * @param configMethodsStr List of config methods. 502 * @return true if request is sent successfully, false otherwise. 503 */ setWpsConfigMethods(String configMethodsStr)504 boolean setWpsConfigMethods(String configMethodsStr); 505 506 /** 507 * Get NFC handover request message. 508 * 509 * @return select message if created successfully, null otherwise. 510 */ getNfcHandoverRequest()511 String getNfcHandoverRequest(); 512 513 /** 514 * Get NFC handover select message. 515 * 516 * @return select message if created successfully, null otherwise. 517 */ getNfcHandoverSelect()518 String getNfcHandoverSelect(); 519 520 /** 521 * Report NFC handover select message. 522 * 523 * @return true if reported successfully, false otherwise. 524 */ initiatorReportNfcHandover(String selectMessage)525 boolean initiatorReportNfcHandover(String selectMessage); 526 527 /** 528 * Report NFC handover request message. 529 * 530 * @return true if reported successfully, false otherwise. 531 */ responderReportNfcHandover(String requestMessage)532 boolean responderReportNfcHandover(String requestMessage); 533 534 /** 535 * Set the client list for the provided network. 536 * 537 * @param networkId Id of the network. 538 * @param clientListStr Space separated list of clients. 539 * @return true, if operation was successful. 540 */ setClientList(int networkId, String clientListStr)541 boolean setClientList(int networkId, String clientListStr); 542 543 /** 544 * Set the client list for the provided network. 545 * 546 * @param networkId Id of the network. 547 * @return Space separated list of clients if successful, null otherwise. 548 */ getClientList(int networkId)549 String getClientList(int networkId); 550 551 /** 552 * Persist the current configurations to disk. 553 * 554 * @return true, if operation was successful. 555 */ saveConfig()556 boolean saveConfig(); 557 558 /** 559 * Enable/Disable P2P MAC randomization. 560 * 561 * @param enable true to enable, false to disable. 562 * @return true, if operation was successful. 563 */ setMacRandomization(boolean enable)564 boolean setMacRandomization(boolean enable); 565 566 /** 567 * Set Wifi Display R2 device info. 568 * 569 * @param info WFD R2 device info as described in section 5.1.12 of WFD technical 570 * specification v2.1. 571 * @return true, if operation was successful. 572 */ setWfdR2DeviceInfo(String info)573 boolean setWfdR2DeviceInfo(String info); 574 575 /** 576 * Remove the client with the MAC address from the group. 577 * 578 * @param peerAddress Mac address of the client. 579 * @param isLegacyClient Indicate if client is a legacy client or not. 580 * @return true if success 581 */ removeClient(String peerAddress, boolean isLegacyClient)582 boolean removeClient(String peerAddress, boolean isLegacyClient); 583 584 /** 585 * Set vendor-specific information elements to wpa_supplicant. 586 * 587 * @param vendorElements vendor-specific information elements. 588 * 589 * @return boolean value indicating whether operation was successful. 590 */ setVendorElements(Set<ScanResult.InformationElement> vendorElements)591 boolean setVendorElements(Set<ScanResult.InformationElement> vendorElements); 592 593 /** 594 * Configure the IP addresses in supplicant for P2P GO to provide the IP address to 595 * client in EAPOL handshake. Refer Wi-Fi P2P Technical Specification v1.7 - Section 4.2.8 596 * IP Address Allocation in EAPOL-Key Frames (4-Way Handshake) for more details. 597 * The IP addresses are IPV4 addresses and higher-order address bytes are in the 598 * lower-order int bytes (e.g. 1.2.3.4 is represented as 0x04030201) 599 * 600 * @param ipAddressGo The P2P Group Owner IP address. 601 * @param ipAddressMask The P2P Group owner subnet mask. 602 * @param ipAddressStart The starting address in the IP address pool. 603 * @param ipAddressEnd The ending address in the IP address pool. 604 * @return boolean value indicating whether operation was successful. 605 */ configureEapolIpAddressAllocationParams(int ipAddressGo, int ipAddressMask, int ipAddressStart, int ipAddressEnd)606 boolean configureEapolIpAddressAllocationParams(int ipAddressGo, int ipAddressMask, 607 int ipAddressStart, int ipAddressEnd); 608 609 /** 610 * Terminate the supplicant daemon & wait for its death. 611 * Note: Aidl only since it was added from HIDL 1.1 612 */ terminate()613 default void terminate() {}; 614 615 /** 616 * Registers a death notification for supplicant. 617 * @return Returns true on success. 618 * 619 * Note: Aidl only. 620 */ registerDeathHandler(@onNull WifiNative.SupplicantDeathEventHandler handler)621 default boolean registerDeathHandler(@NonNull WifiNative.SupplicantDeathEventHandler handler) { 622 return true; 623 }; 624 625 /** 626 * Deregisters a death notification for supplicant. 627 * @return Returns true on success. 628 * 629 * Note: Aidl only. 630 */ deregisterDeathHandler()631 default boolean deregisterDeathHandler() { 632 return true; 633 }; 634 } 635