DO NOT MERGE - Merge Android 13

Bug: 242648940
Merged-In: Ib692084b9fb4984d380963d2156546bbb91b4b0d
Change-Id: I5bebe20fa42d98defd20cb8d76e698c50c204b8f
diff --git a/ipacm/inc/IPACM_Config.h b/ipacm/inc/IPACM_Config.h
index 1915fbc..a0a8bb8 100644
--- a/ipacm/inc/IPACM_Config.h
+++ b/ipacm/inc/IPACM_Config.h
@@ -261,6 +261,10 @@
 
 	enum ipa_hw_type GetIPAVer(bool get = false);
 
+#ifdef IPA_IOCTL_GET_HW_FEATURE_SUPPORT
+	int GetIPAFeatureSupport(bool get = false);
+#endif
+
 	bool isEthBridgingSupported();
 
 	bool isIPAv3Supported();
@@ -361,6 +365,9 @@
 
 private:
 	enum ipa_hw_type ver;
+#ifdef IPA_IOCTL_GET_HW_FEATURE_SUPPORT
+	uint32_t hw_feature;
+#endif
 	static IPACM_Config *pInstance;
 	static const char *DEVICE_NAME;
 	IPACM_Config(void);
diff --git a/ipacm/inc/IPACM_ConntrackClient.h b/ipacm/inc/IPACM_ConntrackClient.h
index 16d5b9c..4ceff43 100644
--- a/ipacm/inc/IPACM_ConntrackClient.h
+++ b/ipacm/inc/IPACM_ConntrackClient.h
@@ -33,6 +33,9 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#ifndef in_addr_t
+typedef uint32_t in_addr_t;
+#endif
 #include <arpa/inet.h>
 #include <netinet/in.h>
 #include <errno.h>
diff --git a/ipacm/inc/IPACM_ConntrackListener.h b/ipacm/inc/IPACM_ConntrackListener.h
index 2977af7..110fdcc 100644
--- a/ipacm/inc/IPACM_ConntrackListener.h
+++ b/ipacm/inc/IPACM_ConntrackListener.h
@@ -35,6 +35,9 @@
 #include <string.h>
 #include <fcntl.h>
 
+#ifndef in_addr_t
+typedef uint32_t in_addr_t;
+#endif
 #include <arpa/inet.h>
 #include <netinet/in.h>
 #include <errno.h>
diff --git a/ipacm/inc/IPACM_Xml.h b/ipacm/inc/IPACM_Xml.h
index 64c00ed..5954e1b 100644
--- a/ipacm/inc/IPACM_Xml.h
+++ b/ipacm/inc/IPACM_Xml.h
@@ -45,6 +45,9 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#ifndef in_addr_t
+typedef uint32_t in_addr_t;
+#endif
 #include <arpa/inet.h>
 #include <stdint.h>
 #include <libxml/parser.h>
diff --git a/ipacm/src/IPACM_Config.cpp b/ipacm/src/IPACM_Config.cpp
index d0c33e9..05fd07d 100644
--- a/ipacm/src/IPACM_Config.cpp
+++ b/ipacm/src/IPACM_Config.cpp
@@ -197,6 +197,9 @@
 		IPACMERR("Failed opening %s.\n", DEVICE_NAME);
 	}
 	ver = GetIPAVer(true);
+#ifdef IPA_IOCTL_GET_HW_FEATURE_SUPPORT
+	hw_feature = GetIPAFeatureSupport(true);
+#endif
 #ifdef FEATURE_IPACM_HAL
 	strlcpy(IPACM_config_file, "/vendor/etc/IPACM_cfg.xml", sizeof(IPACM_config_file));
 #else
@@ -911,11 +914,36 @@
 	return ver;
 }
 
+#ifdef IPA_IOCTL_GET_HW_FEATURE_SUPPORT
+int IPACM_Config::GetIPAFeatureSupport(bool get)
+{
+	int ret;
+
+	if(!get)
+		return hw_feature;
+
+	ret = ioctl(m_fd, IPA_IOC_GET_HW_FEATURE_SUPPORT, &hw_feature);
+	if(ret != 0)
+	{
+		IPACMERR("Failed to get IPA HW feature support %d.\n", ret);
+		hw_feature = 0;
+		return hw_feature;
+	}
+	IPACMDBG_H("IPA HW supported feature %d.\n", hw_feature);
+	return hw_feature;
+}
+#endif
+
 bool IPACM_Config::isEthBridgingSupported()
 {
 	enum ipa_hw_type hw_type;
 
 	hw_type = GetIPAVer();
+#ifdef IPA_IOCTL_GET_HW_FEATURE_SUPPORT
+	if (hw_type >= IPA_HW_v4_11) {
+		return ((hw_feature & IPA_HW_ETH_BRIDGING_SUPPORT_BMSK) != 0);
+	}
+#endif
 
 #ifdef IPA_HW_v4_7
 	return ((hw_type >= IPA_HW_v4_5) &&
diff --git a/ipacm/src/IPACM_ConntrackClient.cpp b/ipacm/src/IPACM_ConntrackClient.cpp
index 29afd50..a953626 100644
--- a/ipacm/src/IPACM_ConntrackClient.cpp
+++ b/ipacm/src/IPACM_ConntrackClient.cpp
@@ -31,6 +31,9 @@
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
+#ifndef in_addr_t
+typedef uint32_t in_addr_t;
+#endif
 #include <arpa/inet.h>
 #include <netinet/in.h>
 #include <sys/ioctl.h>
diff --git a/ipacm/src/IPACM_Lan.cpp b/ipacm/src/IPACM_Lan.cpp
index c83a729..9bcbac4 100644
--- a/ipacm/src/IPACM_Lan.cpp
+++ b/ipacm/src/IPACM_Lan.cpp
@@ -3335,7 +3335,7 @@
 /* install UL filter rule from Q6 */
 int IPACM_Lan::handle_uplink_filter_rule(ipacm_ext_prop *prop, ipa_ip_type iptype, uint8_t xlat_mux_id)
 {
-	ipa_flt_rule_add flt_rule_entry;
+	static ipa_flt_rule_add flt_rule_entry;
 	int len = 0, cnt, ret = IPACM_SUCCESS;
 	ipa_ioc_add_flt_rule *pFilteringTable;
 	ipa_fltr_installed_notif_req_msg_v01 flt_index;
@@ -6632,11 +6632,11 @@
 		&flt_eq.eq_attrib, sizeof(rule->eq_attrib));
 
 	//add IHL offsets
-#ifdef FEATURE_IPA_V3
+	if(IPACM_Iface::ipacmcfg->GetIPAVer() >= IPA_HW_v3_0)
 		rule->eq_attrib.rule_eq_bitmap |= (1<<10);
-#else
+	else
 		rule->eq_attrib.rule_eq_bitmap |= (1<<4);
-#endif
+
 	rule->eq_attrib.num_ihl_offset_range_16 = 1;
 	if (iptype == IPA_IP_v4)
 		rule->eq_attrib.ihl_offset_range_16[0].offset = 0x82;
diff --git a/ipacm/src/IPACM_Wan.cpp b/ipacm/src/IPACM_Wan.cpp
index f17eb03..a36fa4a 100644
--- a/ipacm/src/IPACM_Wan.cpp
+++ b/ipacm/src/IPACM_Wan.cpp
@@ -134,6 +134,10 @@
 	is_ipv6_frag_firewall_flt_rule_installed = false;
 	ipv6_frag_firewall_flt_rule_hdl = 0;
 
+	icmpv6_exception_hdl = 0;
+	tcp_fin_hdl = 0;
+	tcp_rst_hdl = 0;
+
 	mtu_v4 = DEFAULT_MTU_SIZE;
 	mtu_v4_set = false;
 	mtu_v6 = DEFAULT_MTU_SIZE;
@@ -7580,6 +7584,13 @@
 	uint8_t mux_id;
 	ipa_ioc_add_flt_rule *pFilteringTable = NULL;
 
+	/* Return if rules are there */
+	if (mhi_dl_v4_frag_hdl)
+	{
+		IPACMERR("frag rule have not been deleted. Don't install again\n");
+		return IPACM_FAILURE;
+	}
+
 	mux_id = ext_prop->ext[0].mux_id;
 	/* contruct filter rules to pcie modem */
 	struct ipa_flt_rule_add flt_rule_entry;
@@ -7721,6 +7732,13 @@
 	uint8_t mux_id;
 	ipa_ioc_add_flt_rule *pFilteringTable = NULL;
 
+	/* Return if rules are there */
+	if (icmpv6_exception_hdl)
+	{
+		IPACMERR("icmpv6 rule have not been deleted. Don't install again\n");
+		return IPACM_FAILURE;
+	}
+
 	mux_id = ext_prop->ext[0].mux_id;
 	/* contruct filter rules to pcie modem */
 	struct ipa_flt_rule_add flt_rule_entry;
@@ -7858,6 +7876,13 @@
 	uint8_t mux_id;
 	ipa_ioc_add_flt_rule *pFilteringTable = NULL;
 
+	/* Return if rules are there */
+	if (tcp_fin_hdl || tcp_rst_hdl)
+	{
+		IPACMERR("tcp RST/FIN rules have not been deleted. Don't install again\n");
+		return IPACM_FAILURE;
+	}
+
 	mux_id = ext_prop->ext[0].mux_id;
 	/* contruct filter rules to pcie modem */
 	struct ipa_flt_rule_add flt_rule_entry;
diff --git a/ipacm/src/IPACM_Xml.cpp b/ipacm/src/IPACM_Xml.cpp
index d59bbb0..9c4af41 100644
--- a/ipacm/src/IPACM_Xml.cpp
+++ b/ipacm/src/IPACM_Xml.cpp
@@ -39,6 +39,9 @@
 
 #include <sys/socket.h>
 #include <netinet/in.h>
+#ifndef in_addr_t
+typedef uint32_t in_addr_t;
+#endif
 #include <arpa/inet.h>
 
 #include "IPACM_Xml.h"
diff --git a/ipacm_vendor_product.mk b/ipacm_vendor_product.mk
index 88cc483..e18d519 100644
--- a/ipacm_vendor_product.mk
+++ b/ipacm_vendor_product.mk
@@ -1,9 +1,11 @@
 TARGET_DISABLE_IPACM := false
 
+ifneq ($(TARGET_BOARD_SUFFIX),_au)
 #IPACM_DATA
 IPACM_DATA += IPACM_cfg.xml
 IPACM_DATA += ipacm
 IPACM_DATA += ipacm.rc
+endif
 
 ifeq ($(TARGET_USES_QMAA),true)
 ifneq ($(TARGET_USES_QMAA_OVERRIDE_DATA),true)
@@ -12,6 +14,7 @@
 endif #TARGET_USES_QMAA
 
 BOARD_IPA_LOW_RAM_EXCP_LIST := bengal
+BOARD_IPA_LOW_RAM_EXCP_LIST += monaco
 
 ifeq ($(TARGET_HAS_LOW_RAM),true)
 ifeq (,$(call is-board-platform-in-list2,$(BOARD_IPA_LOW_RAM_EXCP_LIST)))
@@ -25,6 +28,9 @@
 BOARD_PLATFORM_LIST += msm8917
 BOARD_PLATFORM_LIST += qm215
 BOARD_PLATFORM_LIST += msm8937
+ifeq ($(TARGET_BOARD_SUFFIX),_au)
+BOARD_PLATFORM_LIST += msmnile
+endif
 BOARD_IPAv3_LIST := msm8998
 BOARD_IPAv3_LIST += sdm845
 BOARD_IPAv3_LIST += sdm710