p2p: add new HAL API to pass vendor-specific data

Bug: 197695047
Test: atest VtsHalWifiSupplicantStaIfaceTargetTest \
            VtsHalWifiSupplicantStaNetworkTargetTest \
            VtsHalWifiSupplicantP2pIfaceTargetTest
Change-Id: Ie746deb74c08307b70bd7959e5950c5f3c1679c5
diff --git a/wifi/supplicant/aidl/aidl_api/android.hardware.wifi.supplicant/current/android/hardware/wifi/supplicant/ISupplicantP2pIface.aidl b/wifi/supplicant/aidl/aidl_api/android.hardware.wifi.supplicant/current/android/hardware/wifi/supplicant/ISupplicantP2pIface.aidl
index f709aef..d7eff76 100644
--- a/wifi/supplicant/aidl/aidl_api/android.hardware.wifi.supplicant/current/android/hardware/wifi/supplicant/ISupplicantP2pIface.aidl
+++ b/wifi/supplicant/aidl/aidl_api/android.hardware.wifi.supplicant/current/android/hardware/wifi/supplicant/ISupplicantP2pIface.aidl
@@ -95,4 +95,5 @@
   void stopFind();
   void findOnSocialChannels(in int timeoutInSec);
   void findOnSpecificFrequency(in int freqInHz, in int timeoutInSec);
+  void setVendorElements(in android.hardware.wifi.supplicant.P2pFrameTypeMask frameTypeMask, in byte[] vendorElemBytes);
 }
diff --git a/wifi/supplicant/aidl/aidl_api/android.hardware.wifi.supplicant/current/android/hardware/wifi/supplicant/ISupplicantP2pIfaceCallback.aidl b/wifi/supplicant/aidl/aidl_api/android.hardware.wifi.supplicant/current/android/hardware/wifi/supplicant/ISupplicantP2pIfaceCallback.aidl
index 826d916..8d9f498 100644
--- a/wifi/supplicant/aidl/aidl_api/android.hardware.wifi.supplicant/current/android/hardware/wifi/supplicant/ISupplicantP2pIfaceCallback.aidl
+++ b/wifi/supplicant/aidl/aidl_api/android.hardware.wifi.supplicant/current/android/hardware/wifi/supplicant/ISupplicantP2pIfaceCallback.aidl
@@ -51,4 +51,5 @@
   oneway void onStaAuthorized(in byte[] srcAddress, in byte[] p2pDeviceAddress);
   oneway void onStaDeauthorized(in byte[] srcAddress, in byte[] p2pDeviceAddress);
   oneway void onGroupFrequencyChanged(in String groupIfname, in int frequency);
+  oneway void onDeviceFoundWithVendorElements(in byte[] srcAddress, in byte[] p2pDeviceAddress, in byte[] primaryDeviceType, in String deviceName, in android.hardware.wifi.supplicant.WpsConfigMethods configMethods, in byte deviceCapabilities, in android.hardware.wifi.supplicant.P2pGroupCapabilityMask groupCapabilities, in byte[] wfdDeviceInfo, in byte[] wfdR2DeviceInfo, in byte[] vendorElemBytes);
 }
diff --git a/wifi/supplicant/aidl/aidl_api/android.hardware.wifi.supplicant/current/android/hardware/wifi/supplicant/P2pFrameTypeMask.aidl b/wifi/supplicant/aidl/aidl_api/android.hardware.wifi.supplicant/current/android/hardware/wifi/supplicant/P2pFrameTypeMask.aidl
new file mode 100644
index 0000000..6e1b957
--- /dev/null
+++ b/wifi/supplicant/aidl/aidl_api/android.hardware.wifi.supplicant/current/android/hardware/wifi/supplicant/P2pFrameTypeMask.aidl
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+///////////////////////////////////////////////////////////////////////////////
+// THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE.                          //
+///////////////////////////////////////////////////////////////////////////////
+
+// This file is a snapshot of an AIDL file. Do not edit it manually. There are
+// two cases:
+// 1). this is a frozen version file - do not edit this in any case.
+// 2). this is a 'current' file. If you make a backwards compatible change to
+//     the interface (from the latest frozen version), the build system will
+//     prompt you to update this file with `m <name>-update-api`.
+//
+// You must not make a backward incompatible change to any AIDL file built
+// with the aidl_interface module type with versions property set. The module
+// type is used to build AIDL files in a way that they can be used across
+// independently updatable components of the system. If a device is shipped
+// with such a backward incompatible change, it has a high risk of breaking
+// later when a module using the interface is updated, e.g., Mainline modules.
+
+package android.hardware.wifi.supplicant;
+@Backing(type="int") @VintfStability
+enum P2pFrameTypeMask {
+  P2P_FRAME_PROBE_REQ_P2P = 1,
+  P2P_FRAME_PROBE_RESP_P2P = 2,
+  P2P_FRAME_PROBE_RESP_P2P_GO = 4,
+  P2P_FRAME_BEACON_P2P_GO = 8,
+  P2P_FRAME_P2P_PD_REQ = 16,
+  P2P_FRAME_P2P_PD_RESP = 32,
+  P2P_FRAME_P2P_GO_NEG_REQ = 64,
+  P2P_FRAME_P2P_GO_NEG_RESP = 128,
+  P2P_FRAME_P2P_GO_NEG_CONF = 256,
+  P2P_FRAME_P2P_INV_REQ = 512,
+  P2P_FRAME_P2P_INV_RESP = 1024,
+  P2P_FRAME_P2P_ASSOC_REQ = 2048,
+  P2P_FRAME_P2P_ASSOC_RESP = 4096,
+}
diff --git a/wifi/supplicant/aidl/android/hardware/wifi/supplicant/ISupplicantP2pIface.aidl b/wifi/supplicant/aidl/android/hardware/wifi/supplicant/ISupplicantP2pIface.aidl
index 7588c74..9021bf5 100644
--- a/wifi/supplicant/aidl/android/hardware/wifi/supplicant/ISupplicantP2pIface.aidl
+++ b/wifi/supplicant/aidl/android/hardware/wifi/supplicant/ISupplicantP2pIface.aidl
@@ -21,6 +21,7 @@
 import android.hardware.wifi.supplicant.ISupplicantP2pNetwork;
 import android.hardware.wifi.supplicant.IfaceType;
 import android.hardware.wifi.supplicant.MiracastMode;
+import android.hardware.wifi.supplicant.P2pFrameTypeMask;
 import android.hardware.wifi.supplicant.P2pGroupCapabilityMask;
 import android.hardware.wifi.supplicant.WpsConfigMethods;
 import android.hardware.wifi.supplicant.WpsProvisionMethod;
@@ -810,4 +811,20 @@
      *         |SupplicantStatusCode.FAILURE_IFACE_DISABLED|
      */
     void findOnSpecificFrequency(in int freqInHz, in int timeoutInSec);
+
+    /**
+     * Set vendor-specific information elements to P2P frames.
+     *
+     * @param frameTypeMask The bit mask of P2P frame type represented by
+     *         P2pFrameTypeMask.
+     * @param vendorElemBytes Vendor-specific information element bytes. The format of an
+     *         information element is EID (1 byte) + Length (1 Byte) + Payload which is
+     *         defined in Section 9.4.4 TLV encodings of 802.11-2016 IEEE Standard for
+     *         Information technology. The length indicates the size of the payload.
+     *         Multiple information elements may be appended within the byte array.
+     * @throws ServiceSpecificException with one of the following values:
+     *         |SupplicantStatusCode.FAILURE_UNKNOWN|,
+     *         |SupplicantStatusCode.FAILURE_IFACE_INVALID|
+     */
+    void setVendorElements(in P2pFrameTypeMask frameTypeMask, in byte[] vendorElemBytes);
 }
diff --git a/wifi/supplicant/aidl/android/hardware/wifi/supplicant/ISupplicantP2pIfaceCallback.aidl b/wifi/supplicant/aidl/android/hardware/wifi/supplicant/ISupplicantP2pIfaceCallback.aidl
index 2b58cc2..da17c7b 100644
--- a/wifi/supplicant/aidl/android/hardware/wifi/supplicant/ISupplicantP2pIfaceCallback.aidl
+++ b/wifi/supplicant/aidl/android/hardware/wifi/supplicant/ISupplicantP2pIfaceCallback.aidl
@@ -213,4 +213,35 @@
      * @param frequency New operating frequency in MHz.
      */
     oneway void onGroupFrequencyChanged(in String groupIfname, in int frequency);
+
+    /**
+     * Used to indicate that a P2P device has been found.
+     *
+     * @param srcAddress MAC address of the device found. This must either
+     *        be the P2P device address for a peer which is not in a group,
+     *        or the P2P interface address for a peer which is a Group Owner.
+     * @param p2pDeviceAddress P2P device address.
+     * @param primaryDeviceType Type of device. Refer to section B.1 of Wifi P2P
+     *        Technical specification v1.2.
+     * @param deviceName Name of the device.
+     * @param configMethods Mask of WPS configuration methods supported by the
+     *        device.
+     * @param deviceCapabilities Refer to section 4.1.4 of Wifi P2P Technical
+     *        specification v1.2.
+     * @param groupCapabilites Refer to section 4.1.4 of Wifi P2P Technical
+     *        specification v1.2.
+     * @param wfdDeviceInfo WFD device info as described in section 5.1.2 of WFD
+     *        technical specification v1.0.0.
+     * @param wfdR2DeviceInfo WFD R2 device info as described in section 5.1.12 of WFD
+     *        technical specification v2.1.
+     * @param vendorElemBytes Vendor-specific information element bytes. The format of an
+     *         information element is EID (1 byte) + Length (1 Byte) + Payload which is
+     *         defined in Section 9.4.4 TLV encodings of 802.11-2016 IEEE Standard for
+     *         Information technology. The length indicates the size of the payload.
+     *         Multiple information elements may be appended within the byte array.
+     */
+    oneway void onDeviceFoundWithVendorElements(in byte[] srcAddress, in byte[] p2pDeviceAddress,
+            in byte[] primaryDeviceType, in String deviceName, in WpsConfigMethods configMethods,
+            in byte deviceCapabilities, in P2pGroupCapabilityMask groupCapabilities,
+            in byte[] wfdDeviceInfo, in byte[] wfdR2DeviceInfo, in byte[] vendorElemBytes);
 }
diff --git a/wifi/supplicant/aidl/android/hardware/wifi/supplicant/P2pFrameTypeMask.aidl b/wifi/supplicant/aidl/android/hardware/wifi/supplicant/P2pFrameTypeMask.aidl
new file mode 100644
index 0000000..06e834b
--- /dev/null
+++ b/wifi/supplicant/aidl/android/hardware/wifi/supplicant/P2pFrameTypeMask.aidl
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.hardware.wifi.supplicant;
+
+/**
+ * Bitmask of P2P frame types.
+ */
+@VintfStability
+@Backing(type="int")
+enum P2pFrameTypeMask {
+    /** P2P probe request frame */
+    P2P_FRAME_PROBE_REQ_P2P = 1 << 0,
+    /** P2P probe response frame */
+    P2P_FRAME_PROBE_RESP_P2P = 1 << 1,
+    /** P2P probe response frame from the group owner */
+    P2P_FRAME_PROBE_RESP_P2P_GO = 1 << 2,
+    /** Beacon frame from the group owner */
+    P2P_FRAME_BEACON_P2P_GO = 1 << 3,
+    /** Provision discovery request frame */
+    P2P_FRAME_P2P_PD_REQ = 1 << 4,
+    /** Provision discovery response frame */
+    P2P_FRAME_P2P_PD_RESP = 1 << 5,
+    /** Group negotiation request frame */
+    P2P_FRAME_P2P_GO_NEG_REQ = 1 << 6,
+    /** Group negotiation response frame */
+    P2P_FRAME_P2P_GO_NEG_RESP = 1 << 7,
+    /** Group negotiation confirm frame */
+    P2P_FRAME_P2P_GO_NEG_CONF = 1 << 8,
+    /** Invitation request frame */
+    P2P_FRAME_P2P_INV_REQ = 1 << 9,
+    /** Invitation response frame */
+    P2P_FRAME_P2P_INV_RESP = 1 << 10,
+    /** P2P Association request frame */
+    P2P_FRAME_P2P_ASSOC_REQ = 1 << 11,
+    /** P2P Association response frame */
+    P2P_FRAME_P2P_ASSOC_RESP = 1 << 12,
+}
diff --git a/wifi/supplicant/aidl/vts/functional/supplicant_p2p_iface_aidl_test.cpp b/wifi/supplicant/aidl/vts/functional/supplicant_p2p_iface_aidl_test.cpp
index 470a9b0..8c7018d 100644
--- a/wifi/supplicant/aidl/vts/functional/supplicant_p2p_iface_aidl_test.cpp
+++ b/wifi/supplicant/aidl/vts/functional/supplicant_p2p_iface_aidl_test.cpp
@@ -34,6 +34,7 @@
 using aidl::android::hardware::wifi::supplicant::ISupplicant;
 using aidl::android::hardware::wifi::supplicant::ISupplicantP2pIface;
 using aidl::android::hardware::wifi::supplicant::MiracastMode;
+using aidl::android::hardware::wifi::supplicant::P2pFrameTypeMask;
 using aidl::android::hardware::wifi::supplicant::P2pGroupCapabilityMask;
 using aidl::android::hardware::wifi::supplicant::P2pProvDiscStatusCode;
 using aidl::android::hardware::wifi::supplicant::P2pStatusCode;
@@ -163,6 +164,17 @@
                                                  int32_t /* frequency */) override {
         return ndk::ScopedAStatus::ok();
     }
+    ::ndk::ScopedAStatus onDeviceFoundWithVendorElements(
+            const std::vector<uint8_t>& /* srcAddress */,
+            const std::vector<uint8_t>& /* p2pDeviceAddress */,
+            const std::vector<uint8_t>& /* primaryDeviceType */,
+            const std::string& /* deviceName */, WpsConfigMethods /* configMethods */,
+            int8_t /* deviceCapabilities */, P2pGroupCapabilityMask /* groupCapabilities */,
+            const std::vector<uint8_t>& /* wfdDeviceInfo */,
+            const std::vector<uint8_t>& /* wfdR2DeviceInfo */,
+            const std::vector<uint8_t>& /* vendorElemBytes */) override {
+        return ndk::ScopedAStatus::ok();
+    }
 };
 
 class SupplicantP2pIfaceAidlTest : public testing::TestWithParam<std::string> {
@@ -638,6 +650,21 @@
         p2p_iface_->removeUpnpService(0 /* version */, upnpServiceName).isOk());
 }
 
+/*
+ * SetVendorElements
+ */
+TEST_P(SupplicantP2pIfaceAidlTest, SetVendorElements) {
+    LOG(INFO) << "SupplicantP2pIfaceAidlTest::SetVendorElements start";
+
+    std::vector<uint8_t> vendorElemBytes;
+    EXPECT_TRUE(
+            p2p_iface_
+                    ->setVendorElements(P2pFrameTypeMask::P2P_FRAME_PROBE_RESP_P2P, vendorElemBytes)
+                    .isOk());
+
+    LOG(INFO) << "SupplicantP2pIfaceAidlTest::SetVendorElements end";
+}
+
 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(SupplicantP2pIfaceAidlTest);
 INSTANTIATE_TEST_SUITE_P(Supplicant, SupplicantP2pIfaceAidlTest,
                          testing::ValuesIn(android::getAidlHalInstanceNames(