Merge "Update setAfcChannelAllowance" into udc-dev
diff --git a/wifi/aidl/aidl_api/android.hardware.wifi/current/android/hardware/wifi/AfcChannelAllowance.aidl b/wifi/aidl/aidl_api/android.hardware.wifi/current/android/hardware/wifi/AfcChannelAllowance.aidl
new file mode 100644
index 0000000..4d3cd6e
--- /dev/null
+++ b/wifi/aidl/aidl_api/android.hardware.wifi/current/android/hardware/wifi/AfcChannelAllowance.aidl
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2023 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;
+@VintfStability
+parcelable AfcChannelAllowance {
+  android.hardware.wifi.AvailableAfcFrequencyInfo[] availableAfcFrequencyInfos;
+  android.hardware.wifi.AvailableAfcChannelInfo[] availableAfcChannelInfos;
+  long availabilityExpireTimeMs;
+}
diff --git a/wifi/aidl/aidl_api/android.hardware.wifi/current/android/hardware/wifi/AvailableAfcChannelInfo.aidl b/wifi/aidl/aidl_api/android.hardware.wifi/current/android/hardware/wifi/AvailableAfcChannelInfo.aidl
new file mode 100644
index 0000000..d238640
--- /dev/null
+++ b/wifi/aidl/aidl_api/android.hardware.wifi/current/android/hardware/wifi/AvailableAfcChannelInfo.aidl
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2023 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;
+@VintfStability
+parcelable AvailableAfcChannelInfo {
+  int globalOperatingClass;
+  int channelCfi;
+  int maxEirpDbm;
+}
diff --git a/wifi/aidl/aidl_api/android.hardware.wifi/current/android/hardware/wifi/IWifiChip.aidl b/wifi/aidl/aidl_api/android.hardware.wifi/current/android/hardware/wifi/IWifiChip.aidl
index 502e7ac..4ea2081 100644
--- a/wifi/aidl/aidl_api/android.hardware.wifi/current/android/hardware/wifi/IWifiChip.aidl
+++ b/wifi/aidl/aidl_api/android.hardware.wifi/current/android/hardware/wifi/IWifiChip.aidl
@@ -61,7 +61,7 @@
   android.hardware.wifi.WifiRadioCombination[] getSupportedRadioCombinations();
   android.hardware.wifi.WifiChipCapabilities getWifiChipCapabilities();
   android.hardware.wifi.WifiUsableChannel[] getUsableChannels(in android.hardware.wifi.WifiBand band, in int ifaceModeMask, in int filterMask);
-  void setAfcChannelAllowance(in android.hardware.wifi.AvailableAfcFrequencyInfo[] availableAfcFrequencyInfo);
+  void setAfcChannelAllowance(in android.hardware.wifi.AfcChannelAllowance afcChannelAllowance);
   void registerEventCallback(in android.hardware.wifi.IWifiChipEventCallback callback);
   void removeApIface(in String ifname);
   void removeIfaceInstanceFromBridgedApIface(in String brIfaceName, in String ifaceInstanceName);
diff --git a/wifi/aidl/android/hardware/wifi/AfcChannelAllowance.aidl b/wifi/aidl/android/hardware/wifi/AfcChannelAllowance.aidl
new file mode 100644
index 0000000..289383c
--- /dev/null
+++ b/wifi/aidl/android/hardware/wifi/AfcChannelAllowance.aidl
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2023 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;
+
+import android.hardware.wifi.AvailableAfcChannelInfo;
+import android.hardware.wifi.AvailableAfcFrequencyInfo;
+
+/**
+ * Defines the maximum permissible power spectral density to support 6Ghz with standard power for
+ * AFC. The maximum power can be either defined based on frequencies or channel number.
+ *
+ * Note, based on AFC server support, either availableAfcFrequencyInfos or availableAfcChannelInfos
+ * may be empty. If one of them is empty while the other is not, use the non-empty one and ignore
+ * the empty one. If both are empty then it means 6Ghz standard power should not be supported at
+ * all.
+ *
+ * If availableAfcFrequencyInfos is non-empty, set the max permissible power according to the maxPsd
+ * per frequency range, and disallow emmision on 6Ghz frequencies not included in the structure.
+ *
+ * If availableAfcChannelInfos is non-empty, set the max permissible power according to the
+ * maxEirpDbm per channel, and disallow emmision on 6Ghz channels not included in the structure.
+ */
+@VintfStability
+parcelable AfcChannelAllowance {
+    /**
+     * AFC max permissible information queried from AFC server based on frequency.
+     */
+    AvailableAfcFrequencyInfo[] availableAfcFrequencyInfos;
+    /**
+     * AFC max permissible information queried from AFC server on channel number.
+     */
+    AvailableAfcChannelInfo[] availableAfcChannelInfos;
+    /**
+     * The time in UTC at which this information expires, as the difference, measured in
+     * milliseconds between the expiration time and midnight, January 1, 1970 UTC.
+     */
+    long availabilityExpireTimeMs;
+}
diff --git a/wifi/aidl/android/hardware/wifi/AvailableAfcChannelInfo.aidl b/wifi/aidl/android/hardware/wifi/AvailableAfcChannelInfo.aidl
new file mode 100644
index 0000000..398cd12
--- /dev/null
+++ b/wifi/aidl/android/hardware/wifi/AvailableAfcChannelInfo.aidl
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2023 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;
+
+/**
+ * Defines the maximum EIRP per channel for supporting 6Ghz standard power for AFC. The format of
+ * the data structure is derived from the Wi-Fi Alliance AFC System to AFC Device Interface
+ * Specification: AvailableChannelInfo object.
+ */
+@VintfStability
+parcelable AvailableAfcChannelInfo {
+    /**
+     * The global operating class used to define the channel center frequency indices
+     * and operating bandwidth.
+     */
+    int globalOperatingClass;
+
+    /**
+     * The channel center frequency index.
+     */
+    int channelCfi;
+
+    /**
+     * The maximum permissible EIRP in units of dBm available for the channel
+     * specified by channelCfi. In addition, in any portion of the channel, the conducted PSD plus
+     * the maximum antenna gain cannot exceed the maxEirp divided by the channel width defined by
+     * the globalOperatingClass.
+     */
+    int maxEirpDbm;
+}
diff --git a/wifi/aidl/android/hardware/wifi/IWifiChip.aidl b/wifi/aidl/android/hardware/wifi/IWifiChip.aidl
index 9322d7a..c1caa7e 100644
--- a/wifi/aidl/android/hardware/wifi/IWifiChip.aidl
+++ b/wifi/aidl/android/hardware/wifi/IWifiChip.aidl
@@ -16,7 +16,7 @@
 
 package android.hardware.wifi;
 
-import android.hardware.wifi.AvailableAfcFrequencyInfo;
+import android.hardware.wifi.AfcChannelAllowance;
 import android.hardware.wifi.IWifiApIface;
 import android.hardware.wifi.IWifiChipEventCallback;
 import android.hardware.wifi.IWifiNanIface;
@@ -811,16 +811,12 @@
             in WifiBand band, in int ifaceModeMask, in int filterMask);
 
     /*
-     * Set the max power level the chip is allowed to transmit on for 6Ghz AFC
-     * using an array of AvailableAfcFrequencyInfo. The max power for
-     * frequencies not included in the input frequency ranges will be reset to
-     * their respective default values.
-     * @param availableAfcFrequencyInfo The list of frequency ranges and
-     * corresponding max allowed power.
+     * Set the max power level the chip is allowed to transmit on for 6Ghz AFC.
+     * @param afcChannelAllowance Specifies the power limitations for 6Ghz AFC.
      * @throws ServiceSpecificException with one of the following values:
      *         |WifiStatusCode.ERROR_NOT_SUPPORTED|
      */
-    void setAfcChannelAllowance(in AvailableAfcFrequencyInfo[] availableAfcFrequencyInfo);
+    void setAfcChannelAllowance(in AfcChannelAllowance afcChannelAllowance);
 
     /**
      * Requests notifications of significant events on this chip. Multiple calls
diff --git a/wifi/aidl/default/wifi_chip.cpp b/wifi/aidl/default/wifi_chip.cpp
index 3b2dba2..f9f5528 100644
--- a/wifi/aidl/default/wifi_chip.cpp
+++ b/wifi/aidl/default/wifi_chip.cpp
@@ -701,9 +701,9 @@
 }
 
 ndk::ScopedAStatus WifiChip::setAfcChannelAllowance(
-        const std::vector<AvailableAfcFrequencyInfo>& availableAfcFrequencyInfo) {
+        const AfcChannelAllowance& afcChannelAllowance) {
     return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
-                           &WifiChip::setAfcChannelAllowanceInternal, availableAfcFrequencyInfo);
+                           &WifiChip::setAfcChannelAllowanceInternal, afcChannelAllowance);
 }
 
 ndk::ScopedAStatus WifiChip::triggerSubsystemRestart() {
@@ -1430,8 +1430,12 @@
 }
 
 ndk::ScopedAStatus WifiChip::setAfcChannelAllowanceInternal(
-        const std::vector<AvailableAfcFrequencyInfo>& availableAfcFrequencyInfo) {
-    LOG(INFO) << "setAfcChannelAllowance is not yet supported " << availableAfcFrequencyInfo.size();
+        const AfcChannelAllowance& afcChannelAllowance) {
+    LOG(INFO) << "setAfcChannelAllowance is not yet supported. availableAfcFrequencyInfos size="
+              << afcChannelAllowance.availableAfcFrequencyInfos.size()
+              << " availableAfcChannelInfos size="
+              << afcChannelAllowance.availableAfcChannelInfos.size()
+              << " availabilityExpireTimeMs=" << afcChannelAllowance.availabilityExpireTimeMs;
     return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED);
 }
 
diff --git a/wifi/aidl/default/wifi_chip.h b/wifi/aidl/default/wifi_chip.h
index 6d2a59e..4ddee92 100644
--- a/wifi/aidl/default/wifi_chip.h
+++ b/wifi/aidl/default/wifi_chip.h
@@ -142,7 +142,7 @@
                                          int32_t in_filterMask,
                                          std::vector<WifiUsableChannel>* _aidl_return) override;
     ndk::ScopedAStatus setAfcChannelAllowance(
-            const std::vector<AvailableAfcFrequencyInfo>& availableAfcFrequencyInfo) override;
+            const AfcChannelAllowance& afcChannelAllowance) override;
     ndk::ScopedAStatus triggerSubsystemRestart() override;
     ndk::ScopedAStatus getSupportedRadioCombinations(
             std::vector<WifiRadioCombination>* _aidl_return) override;
@@ -220,7 +220,7 @@
             WifiBand band, int32_t ifaceModeMask, int32_t filterMask);
     ndk::ScopedAStatus enableStaChannelForPeerNetworkInternal(int32_t channelCategoryEnableFlag);
     ndk::ScopedAStatus setAfcChannelAllowanceInternal(
-            const std::vector<AvailableAfcFrequencyInfo>& availableAfcFrequencyInfo);
+            const AfcChannelAllowance& afcChannelAllowance);
     ndk::ScopedAStatus handleChipConfiguration(std::unique_lock<std::recursive_mutex>* lock,
                                                int32_t mode_id);
     ndk::ScopedAStatus registerDebugRingBufferCallback();