1 /*
2 Copyright (c) 2013-2020, The Linux Foundation. All rights reserved.
3 
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions are
6 met:
7     * Redistributions of source code must retain the above copyright
8       notice, this list of conditions and the following disclaimer.
9     * Redistributions in binary form must reproduce the above
10       copyright notice, this list of conditions and the following
11       disclaimer in the documentation and/or other materials provided
12       with the distribution.
13     * Neither the name of The Linux Foundation nor the names of its
14       contributors may be used to endorse or promote products derived
15       from this software without specific prior written permission.
16 
17 THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20 ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29 /*!
30 	@file
31 	IPACM_Wan.cpp
32 
33 	@brief
34 	This file implements the WAN iface functionality.
35 
36 	@Author
37 	Skylar Chang
38 
39 */
40 #ifndef IPACM_WAN_H
41 #define IPACM_WAN_H
42 
43 #include <stdio.h>
44 #include <IPACM_CmdQueue.h>
45 #include <linux/msm_ipa.h>
46 #include "IPACM_Routing.h"
47 #include "IPACM_Filtering.h"
48 #include <IPACM_Iface.h>
49 #include <IPACM_Defs.h>
50 #include <IPACM_Xml.h>
51 
52 #define IPA_NUM_DEFAULT_WAN_FILTER_RULES 3 /*1 for v4, 2 for v6*/
53 #define IPA_V2_NUM_DEFAULT_WAN_FILTER_RULE_IPV4 2
54 
55 #ifdef FEATURE_IPA_ANDROID
56 #define IPA_V2_NUM_DEFAULT_WAN_FILTER_RULE_IPV6 4
57 #define IPA_V2_NUM_TCP_WAN_FILTER_RULE_IPV6 3
58 #define IPA_V2_NUM_MULTICAST_WAN_FILTER_RULE_IPV6 3
59 #define IPA_V2_NUM_FRAG_WAN_FILTER_RULE_IPV6 1
60 #else
61 #define IPA_V2_NUM_DEFAULT_WAN_FILTER_RULE_IPV6 3
62 #endif
63 
64 #define NETWORK_STATS "%s %llu %llu %llu %llu"
65 #define IPA_NETWORK_STATS_FILE_NAME "/data/misc/ipa/network_stats"
66 #define IPA_OFFLOAD_TETHER_STATE_FILE_NAME "/data/vendor/ipa/offload_state"
67 
68 typedef struct _wan_client_rt_hdl
69 {
70 	uint32_t wan_rt_rule_hdl_v4;
71 	uint32_t wan_rt_rule_hdl_v6[IPV6_NUM_ADDR];
72 	uint32_t wan_rt_rule_hdl_v6_wan[IPV6_NUM_ADDR];
73 }wan_client_rt_hdl;
74 
75 typedef struct _ipa_wan_client
76 {
77 	ipacm_event_data_wlan_ex* p_hdr_info;
78 	uint8_t mac[IPA_MAC_ADDR_SIZE];
79 	uint32_t v4_addr;
80 	uint32_t v6_addr[IPV6_NUM_ADDR][4];
81 	uint32_t hdr_hdl_v4;
82 	uint32_t hdr_hdl_v6;
83 	bool route_rule_set_v4;
84 	int route_rule_set_v6;
85 	bool ipv4_set;
86 	int ipv6_set;
87 	bool ipv4_header_set;
88 	bool ipv6_header_set;
89 	bool power_save_set;
90 	wan_client_rt_hdl wan_rt_hdl[0]; /* depends on number of tx properties */
91 }ipa_wan_client;
92 
93 typedef struct
94 {
95 	bool coalesce_tcp_enable;
96 	bool coalesce_udp_enable;
97 }ipacm_coalesce;
98 
99 /* wan iface */
100 class IPACM_Wan : public IPACM_Iface
101 {
102 
103 public:
104 	/* IPACM pm_depency q6 check*/
105 	static int ipa_pm_q6_check;
106 	static bool wan_up;
107 	static bool wan_up_v6;
108 	static uint8_t xlat_mux_id;
109 
110 	static uint16_t mtu_default_wan_v4;
111 	static uint16_t mtu_default_wan_v6;
112 
113 	/* IPACM interface name */
114 	static char wan_up_dev_name[IF_NAME_LEN];
115 	static uint32_t curr_wan_ip;
116 	IPACM_Wan(int, ipacm_wan_iface_type, uint8_t *);
117 	virtual ~IPACM_Wan();
118 
isWanUP(int ipa_if_num_tether)119 	static bool isWanUP(int ipa_if_num_tether)
120 	{
121 #ifdef FEATURE_IPA_ANDROID
122 #ifdef FEATURE_IPACM_HAL
123 		/*To avoid -Wall -Werror error */
124 		IPACMDBG_H("ipa_if_num_tether: %d\n",ipa_if_num_tether);
125 		return wan_up;
126 #else
127 		uint32_t i;
128 		for (i=0; i < ipa_if_num_tether_v4_total;i++)
129 		{
130 			if (ipa_if_num_tether_v4[i] == ipa_if_num_tether)
131 			{
132 				IPACMDBG_H("support ipv4 tether_iface(%s)\n",
133 					IPACM_Iface::ipacmcfg->iface_table[ipa_if_num_tether].iface_name);
134 				return wan_up;
135 				break;
136 			}
137 		}
138 		return false;
139 #endif
140 #else
141 		return wan_up;
142 #endif
143 	}
144 
queryMTU(int ipa_if_num_tether,enum ipa_ip_type iptype)145 	static uint16_t queryMTU(int ipa_if_num_tether, enum ipa_ip_type iptype)
146 	{
147 		if (iptype == IPA_IP_v4)
148 		{
149 			if (isWanUP(ipa_if_num_tether))
150 			{
151 				return mtu_default_wan_v4;
152 			}
153 		}
154 		else if (iptype == IPA_IP_v6)
155 		{
156 			if (isWanUP_V6(ipa_if_num_tether))
157 			{
158 				return mtu_default_wan_v6;
159 			}
160 		}
161 		return DEFAULT_MTU_SIZE;
162 	}
163 
isWanUP_V6(int ipa_if_num_tether)164 	static bool isWanUP_V6(int ipa_if_num_tether)
165 	{
166 #ifdef FEATURE_IPA_ANDROID
167 #ifdef FEATURE_IPACM_HAL
168 		/*To avoid -Wall -Werror error */
169 		IPACMDBG_H("ipa_if_num_tether: %d\n",ipa_if_num_tether);
170 		return wan_up_v6;
171 #else
172 		uint32_t i;
173 		for (i=0; i < ipa_if_num_tether_v6_total;i++)
174 		{
175 			if (ipa_if_num_tether_v6[i] == ipa_if_num_tether)
176 			{
177 				IPACMDBG_H("support ipv6 tether_iface(%s)\n",
178 					IPACM_Iface::ipacmcfg->iface_table[ipa_if_num_tether].iface_name);
179 				return wan_up_v6;
180 				break;
181 			}
182 		}
183 		return false;
184 #endif
185 #else
186 		return wan_up_v6;
187 #endif
188 	}
189 
190 #ifdef FEATURE_IPA_ANDROID
delete_tether_iface(ipa_ip_type iptype,int ipa_if_num_tether)191 	static int delete_tether_iface(ipa_ip_type iptype, int ipa_if_num_tether)
192 	{
193 		uint32_t i, j;
194 
195 		if (iptype == IPA_IP_v4)
196 		{
197 			/* delete support tether ifaces to its array*/
198 			for (i=0; i < IPACM_Wan::ipa_if_num_tether_v4_total; i++)
199 			{
200 				if(IPACM_Wan::ipa_if_num_tether_v4[i] == ipa_if_num_tether)
201 				{
202 					IPACMDBG_H("Found tether client at position %d name(%s)\n", i,
203 					IPACM_Iface::ipacmcfg->iface_table[ipa_if_num_tether].iface_name);
204 					break;
205 				}
206 			}
207 			if(i == IPACM_Wan::ipa_if_num_tether_v4_total)
208 			{
209 				IPACMDBG_H("Not finding the tethered ipv4 client.\n");
210 				return IPACM_FAILURE;
211 			}
212 			for(j = i+1; j < IPACM_Wan::ipa_if_num_tether_v4_total; j++)
213 			{
214 				IPACM_Wan::ipa_if_num_tether_v4[j-1] = IPACM_Wan::ipa_if_num_tether_v4[j];
215 			}
216 			IPACM_Wan::ipa_if_num_tether_v4_total--;
217 			IPACMDBG_H("Now the total num of ipa_if_num_tether_v4_total is %d\n",
218 				IPACM_Wan::ipa_if_num_tether_v4_total);
219 		}
220 		else
221 		{
222 			/* delete support tether ifaces to its array*/
223 			for (i=0; i < IPACM_Wan::ipa_if_num_tether_v6_total; i++)
224 			{
225 				if(IPACM_Wan::ipa_if_num_tether_v6[i] == ipa_if_num_tether)
226 				{
227 					IPACMDBG_H("Found tether client at position %d name(%s)\n", i,
228 					IPACM_Iface::ipacmcfg->iface_table[ipa_if_num_tether].iface_name);
229 					break;
230 				}
231 			}
232 			if(i == IPACM_Wan::ipa_if_num_tether_v6_total)
233 			{
234 				IPACMDBG_H("Not finding the tethered ipv6 client.\n");
235 				return IPACM_FAILURE;
236 			}
237 			for(j = i+1; j < IPACM_Wan::ipa_if_num_tether_v6_total; j++)
238 			{
239 				IPACM_Wan::ipa_if_num_tether_v6[j-1] = IPACM_Wan::ipa_if_num_tether_v6[j];
240 			}
241 			IPACM_Wan::ipa_if_num_tether_v6_total--;
242 			IPACMDBG_H("Now the total num of ipa_if_num_tether_v6_total is %d\n",
243 				IPACM_Wan::ipa_if_num_tether_v6_total);
244 		}
245 		return IPACM_SUCCESS;
246 	}
247 #endif
coalesce_config(uint8_t qmap_id,bool tcp_enable,bool udp_enable)248 	static void coalesce_config(uint8_t qmap_id, bool tcp_enable, bool udp_enable)
249 	{
250 		if (qmap_id >= IPA_MAX_NUM_SW_PDNS)
251 		{
252 			IPACMERR("qmap_id (%d) beyond the Max range (%d), abort\n",
253 				qmap_id, IPA_MAX_NUM_SW_PDNS);
254 			return ;
255 		}
256 
257 		IPACM_Wan::coalesce_enable_info[qmap_id].coalesce_tcp_enable = tcp_enable;
258 		IPACM_Wan::coalesce_enable_info[qmap_id].coalesce_udp_enable = udp_enable;
259 		IPACMDBG_H(" Updated qmap(%d) coalesce enable TCP:%d UDP:%d\n",
260 				qmap_id,
261 				IPACM_Wan::coalesce_enable_info[qmap_id].coalesce_tcp_enable,
262 				IPACM_Wan::coalesce_enable_info[qmap_id].coalesce_udp_enable);
263 		return ;
264 	}
265 
coalesce_config_reset()266 	static void coalesce_config_reset()
267 	{
268 		int i;
269 		/* reset coalesce settings on all modem interfaces */
270 		for (i = 0; i < IPA_MAX_NUM_SW_PDNS; i++)
271 			IPACM_Wan::coalesce_config(i, false, false);
272 		return ;
273 	}
274 
getWANIP()275 	static uint32_t getWANIP()
276 	{
277 		return curr_wan_ip;
278 	}
279 
getXlat_Mux_Id()280 	static int getXlat_Mux_Id()
281 	{
282 		if (is_xlat)
283 		{
284 			IPACMDBG_H("xlat_mux_id: %d\n", xlat_mux_id);
285 			return xlat_mux_id;
286 		} else {
287 			IPACMDBG_H("no xlat return invalid mux-id: 0\n");
288 			return 0;
289 		}
290 	}
291 
clearExtProp()292 	static void clearExtProp()
293 	{
294 		IPACM_Wan::is_ext_prop_set = false;
295 		IPACM_Iface::ipacmcfg->DelExtProp(IPA_IP_v4);
296 		IPACM_Iface::ipacmcfg->DelExtProp(IPA_IP_v6);
297 	}
298 
299 	void event_callback(ipa_cm_event_id event,
300 											void *data);
301 
302 	static struct ipa_flt_rule_add flt_rule_v4[IPA_MAX_FLT_RULE];
303 	static struct ipa_flt_rule_add flt_rule_v6[IPA_MAX_FLT_RULE];
304 
305 	static int num_v4_flt_rule;
306 	static int num_v6_flt_rule;
307 
308 	ipacm_wan_iface_type m_is_sta_mode;
309 	static ipacm_wan_iface_type backhaul_mode;
310 	static bool is_ext_prop_set;
311 	static uint32_t backhaul_ipv6_prefix[2];
312 
313 	static bool embms_is_on;
314 	static bool backhaul_is_wan_bridge;
315 	static bool is_xlat;
316 
isWan_Bridge_Mode()317 	static bool isWan_Bridge_Mode()
318 	{
319 		return backhaul_is_wan_bridge;
320 	}
321 #ifdef FEATURE_IPA_ANDROID
322 	/* IPACM interface id */
323 	static uint32_t ipa_if_num_tether_v4_total;
324 	static int ipa_if_num_tether_v4[IPA_MAX_IFACE_ENTRIES];
325 	static uint32_t ipa_if_num_tether_v6_total;
326 	static int ipa_if_num_tether_v6[IPA_MAX_IFACE_ENTRIES];
327 
isXlat()328 	static bool isXlat()
329 	{
330 		return is_xlat;
331 	}
332 #endif
333 
334 	/* indicate coalesce support on tcp or udp*/
335 	static ipacm_coalesce coalesce_enable_info[IPA_MAX_NUM_SW_PDNS];
336 
337 private:
338 
339 	bool is_ipv6_frag_firewall_flt_rule_installed;
340 	uint32_t ipv6_frag_firewall_flt_rule_hdl;
341 	uint32_t *wan_route_rule_v4_hdl;
342 	uint32_t *wan_route_rule_v6_hdl;
343 	uint32_t *wan_route_rule_v6_hdl_a5;
344 	uint32_t hdr_hdl_sta_v4;
345 	uint32_t hdr_hdl_sta_v6;
346 	uint32_t firewall_hdl_v4[IPACM_MAX_FIREWALL_ENTRIES];
347 	uint32_t firewall_hdl_v6[IPACM_MAX_FIREWALL_ENTRIES];
348 	uint32_t dft_wan_fl_hdl[IPA_NUM_DEFAULT_WAN_FILTER_RULES];
349 	uint32_t ipv6_dest_flt_rule_hdl[MAX_DEFAULT_v6_ROUTE_RULES];
350 	int num_ipv6_dest_flt_rule;
351 	uint32_t ODU_fl_hdl[IPA_NUM_DEFAULT_WAN_FILTER_RULES];
352 	int num_firewall_v4,num_firewall_v6;
353 	uint32_t wan_v4_addr;
354 	uint32_t wan_v4_addr_gw;
355 	uint32_t wan_v6_addr_gw[4];
356 	bool wan_v4_addr_set;
357 	bool wan_v4_addr_gw_set;
358 	bool wan_v6_addr_gw_set;
359 	bool active_v4;
360 	bool active_v6;
361 	bool header_set_v4;
362 	bool header_set_v6;
363 	bool header_partial_default_wan_v4;
364 	bool header_partial_default_wan_v6;
365 	uint8_t ext_router_mac_addr[IPA_MAC_ADDR_SIZE];
366 	uint8_t netdev_mac[IPA_MAC_ADDR_SIZE];
367 	/* create additional set of v4 Coalesce RT-rules: tcp udp */
368 	uint32_t dft_coalesce_rt_rule_hdl[2*MAX_DEFAULT_v4_ROUTE_RULES+ 2*MAX_DEFAULT_v6_ROUTE_RULES];
369 
370 	static int num_ipv4_modem_pdn;
371 
372 	static int num_ipv6_modem_pdn;
373 
374 	int modem_ipv4_pdn_index;
375 
376 	int modem_ipv6_pdn_index;
377 
378 	bool is_default_gateway;
379 
380 	uint32_t ipv6_prefix[2];
381 
382 	/* IPACM firewall Configuration file*/
383 	IPACM_firewall_conf_t firewall_config;
384 
385 	/* STA mode wan-client*/
386 	int wan_client_len;
387 	ipa_wan_client *wan_client;
388 	int header_name_count;
389 	uint32_t num_wan_client;
390 	uint8_t invalid_mac[IPA_MAC_ADDR_SIZE];
391 	bool is_xlat_local;
392 
393 	/* update network stats for CNE */
394 	int ipa_network_stats_fd;
395 	uint32_t hdr_hdl_dummy_v6;
396 	uint32_t hdr_proc_hdl_dummy_v6;
397 
398 	/* handle for UDP mhi frag rule */
399 	uint32_t mhi_dl_v4_frag_hdl;
400 
401 	/* handle for icmpv6 exception rule */
402 	uint32_t icmpv6_exception_hdl;
403 
404 	/* handle for TCP FIN rule */
405 	uint32_t tcp_fin_hdl;
406 
407 	/* handle for TCP RST rule */
408 	uint32_t tcp_rst_hdl;
409 
410 	/* V4 MTU value. */
411 	uint16_t mtu_v4;
412 	bool mtu_v4_set;
413 
414 	/* V6 MTU value. */
415 	uint16_t mtu_v6;
416 	bool mtu_v6_set;
417 
get_client_memptr(ipa_wan_client * param,int cnt)418 	inline ipa_wan_client* get_client_memptr(ipa_wan_client *param, int cnt)
419 	{
420 	    char *ret = ((char *)param) + (wan_client_len * cnt);
421 		return (ipa_wan_client *)ret;
422 	}
423 
get_wan_client_index(uint8_t * mac_addr)424 	inline int get_wan_client_index(uint8_t *mac_addr)
425 	{
426 		int cnt;
427 		int num_wan_client_tmp = num_wan_client;
428 
429 		IPACMDBG_H("Passed MAC %02x:%02x:%02x:%02x:%02x:%02x\n",
430 						 mac_addr[0], mac_addr[1], mac_addr[2],
431 						 mac_addr[3], mac_addr[4], mac_addr[5]);
432 
433 		for(cnt = 0; cnt < num_wan_client_tmp; cnt++)
434 		{
435 			IPACMDBG_H("stored MAC %02x:%02x:%02x:%02x:%02x:%02x\n",
436 							 get_client_memptr(wan_client, cnt)->mac[0],
437 							 get_client_memptr(wan_client, cnt)->mac[1],
438 							 get_client_memptr(wan_client, cnt)->mac[2],
439 							 get_client_memptr(wan_client, cnt)->mac[3],
440 							 get_client_memptr(wan_client, cnt)->mac[4],
441 							 get_client_memptr(wan_client, cnt)->mac[5]);
442 
443 			if(memcmp(get_client_memptr(wan_client, cnt)->mac,
444 								mac_addr,
445 								sizeof(get_client_memptr(wan_client, cnt)->mac)) == 0)
446 			{
447 				IPACMDBG_H("Matched client index: %d\n", cnt);
448 				return cnt;
449 			}
450 		}
451 
452 		return IPACM_INVALID_INDEX;
453 	}
454 
get_wan_client_index_ipv4(uint32_t ipv4_addr)455 	inline int get_wan_client_index_ipv4(uint32_t ipv4_addr)
456 	{
457 		int cnt;
458 		int num_wan_client_tmp = num_wan_client;
459 
460 		IPACMDBG_H("Passed IPv4 %x\n", ipv4_addr);
461 
462 		for(cnt = 0; cnt < num_wan_client_tmp; cnt++)
463 		{
464 			if (get_client_memptr(wan_client, cnt)->ipv4_set)
465 			{
466 				IPACMDBG_H("stored IPv4 %x\n", get_client_memptr(wan_client, cnt)->v4_addr);
467 
468 				if(ipv4_addr == get_client_memptr(wan_client, cnt)->v4_addr)
469 				{
470 					IPACMDBG_H("Matched client index: %d\n", cnt);
471 					IPACMDBG_H("The MAC is %02x:%02x:%02x:%02x:%02x:%02x\n",
472 							get_client_memptr(wan_client, cnt)->mac[0],
473 							get_client_memptr(wan_client, cnt)->mac[1],
474 							get_client_memptr(wan_client, cnt)->mac[2],
475 							get_client_memptr(wan_client, cnt)->mac[3],
476 							get_client_memptr(wan_client, cnt)->mac[4],
477 							get_client_memptr(wan_client, cnt)->mac[5]);
478 					IPACMDBG_H("header set ipv4(%d) ipv6(%d)\n",
479 							get_client_memptr(wan_client, cnt)->ipv4_header_set,
480 							get_client_memptr(wan_client, cnt)->ipv6_header_set);
481 					return cnt;
482 				}
483 			}
484 		}
485 		return IPACM_INVALID_INDEX;
486 	}
487 
get_wan_client_index_ipv6(uint32_t * ipv6_addr)488 	inline int get_wan_client_index_ipv6(uint32_t* ipv6_addr)
489 	{
490 		int cnt, v6_num;
491 		int num_wan_client_tmp = num_wan_client;
492 
493 		IPACMDBG_H("Get ipv6 address 0x%08x.0x%08x.0x%08x.0x%08x\n", ipv6_addr[0], ipv6_addr[1], ipv6_addr[2], ipv6_addr[3]);
494 
495 		for(cnt = 0; cnt < num_wan_client_tmp; cnt++)
496 		{
497 			if (get_client_memptr(wan_client, cnt)->ipv6_set)
498 			{
499 			    for(v6_num=0;v6_num < get_client_memptr(wan_client, cnt)->ipv6_set;v6_num++)
500 	            {
501 
502 					IPACMDBG_H("stored IPv6 0x%08x.0x%08x.0x%08x.0x%08x\n", get_client_memptr(wan_client, cnt)->v6_addr[v6_num][0],
503 						get_client_memptr(wan_client, cnt)->v6_addr[v6_num][1],
504 						get_client_memptr(wan_client, cnt)->v6_addr[v6_num][2],
505 						get_client_memptr(wan_client, cnt)->v6_addr[v6_num][3]);
506 
507 					if(ipv6_addr[0] == get_client_memptr(wan_client, cnt)->v6_addr[v6_num][0] &&
508 					   ipv6_addr[1] == get_client_memptr(wan_client, cnt)->v6_addr[v6_num][1] &&
509 					   ipv6_addr[2]== get_client_memptr(wan_client, cnt)->v6_addr[v6_num][2] &&
510 					   ipv6_addr[3] == get_client_memptr(wan_client, cnt)->v6_addr[v6_num][3])
511 					{
512 						IPACMDBG_H("Matched client index: %d\n", cnt);
513 						IPACMDBG_H("The MAC is %02x:%02x:%02x:%02x:%02x:%02x\n",
514 								get_client_memptr(wan_client, cnt)->mac[0],
515 								get_client_memptr(wan_client, cnt)->mac[1],
516 								get_client_memptr(wan_client, cnt)->mac[2],
517 								get_client_memptr(wan_client, cnt)->mac[3],
518 								get_client_memptr(wan_client, cnt)->mac[4],
519 								get_client_memptr(wan_client, cnt)->mac[5]);
520 						IPACMDBG_H("header set ipv4(%d) ipv6(%d)\n",
521 								get_client_memptr(wan_client, cnt)->ipv4_header_set,
522 								get_client_memptr(wan_client, cnt)->ipv6_header_set);
523 						return cnt;
524 					}
525 				}
526 			}
527 		}
528 		return IPACM_INVALID_INDEX;
529 	}
530 
delete_wan_rtrules(int clt_indx,ipa_ip_type iptype)531 	inline int delete_wan_rtrules(int clt_indx, ipa_ip_type iptype)
532 	{
533 		uint32_t tx_index;
534 		uint32_t rt_hdl;
535 		int num_v6;
536 
537 		if(iptype == IPA_IP_v4)
538 		{
539 		     for(tx_index = 0; tx_index < iface_query->num_tx_props; tx_index++)
540 		     {
541 		        if((tx_prop->tx[tx_index].ip == IPA_IP_v4) && (get_client_memptr(wan_client, clt_indx)->route_rule_set_v4==true)) /* for ipv4 */
542 			{
543 				IPACMDBG_H("Delete client index %d ipv4 Qos rules for tx:%d \n",clt_indx,tx_index);
544 				rt_hdl = get_client_memptr(wan_client, clt_indx)->wan_rt_hdl[tx_index].wan_rt_rule_hdl_v4;
545 
546 				if(m_routing.DeleteRoutingHdl(rt_hdl, IPA_IP_v4) == false)
547 				{
548 					return IPACM_FAILURE;
549 				}
550 			}
551 		     } /* end of for loop */
552 
553 		     /* clean the 4 Qos ipv4 RT rules for client:clt_indx */
554 		     if(get_client_memptr(wan_client, clt_indx)->route_rule_set_v4==true) /* for ipv4 */
555 		     {
556 				get_client_memptr(wan_client, clt_indx)->route_rule_set_v4 = false;
557 		     }
558 		}
559 
560 		if(iptype == IPA_IP_v6)
561 		{
562 		    for(tx_index = 0; tx_index < iface_query->num_tx_props; tx_index++)
563 		    {
564 
565 				if((tx_prop->tx[tx_index].ip == IPA_IP_v6) && (get_client_memptr(wan_client, clt_indx)->route_rule_set_v6 != 0)) /* for ipv6 */
566 				{
567 					for(num_v6 =0;num_v6 < get_client_memptr(wan_client, clt_indx)->route_rule_set_v6;num_v6++)
568 					{
569 						IPACMDBG_H("Delete client index %d ipv6 Qos rules for %d-st ipv6 for tx:%d\n", clt_indx,num_v6,tx_index);
570 						rt_hdl = get_client_memptr(wan_client, clt_indx)->wan_rt_hdl[tx_index].wan_rt_rule_hdl_v6[num_v6];
571 						if(m_routing.DeleteRoutingHdl(rt_hdl, IPA_IP_v6) == false)
572 						{
573 							return IPACM_FAILURE;
574 						}
575 
576 						rt_hdl = get_client_memptr(wan_client, clt_indx)->wan_rt_hdl[tx_index].wan_rt_rule_hdl_v6_wan[num_v6];
577 						if(m_routing.DeleteRoutingHdl(rt_hdl, IPA_IP_v6) == false)
578 						{
579 							return IPACM_FAILURE;
580 						}
581 					}
582 
583 				}
584 			} /* end of for loop */
585 
586 		    /* clean the 4 Qos ipv6 RT rules for client:clt_indx */
587 		    if(get_client_memptr(wan_client, clt_indx)->route_rule_set_v6 != 0) /* for ipv6 */
588 		    {
589 		                 get_client_memptr(wan_client, clt_indx)->route_rule_set_v6 = 0;
590                     }
591 		}
592 
593 		return IPACM_SUCCESS;
594 	}
595 
596 	int handle_wan_hdr_init(uint8_t *mac_addr, bool replaced = false, int entry = 0);
597 	int handle_wan_client_ipaddr(ipacm_event_data_all *data);
598 	int handle_wan_client_route_rule(uint8_t *mac_addr, ipa_ip_type iptype);
599 
600 	/* handle_gw_mac_renew, index_client valiud is success */
601 	int handle_gw_mac_renew(ipacm_event_data_all *data, int index_client);
602 
603 	/* handle new_address event */
604 	int handle_addr_evt(ipacm_event_data_addr *data);
605 
606 	/* handle new_address event for q6_mhi */
607 	int handle_addr_evt_mhi_q6(ipacm_event_data_addr *data);
608 
609 	/* wan default route/filter rule configuration */
610 	int handle_route_add_evt(ipa_ip_type iptype, bool add_only = false);
611 
612 	/* construct complete STA ethernet header */
613 	int handle_sta_header_add_evt(bool renew = false);
614 
615 	bool check_dft_firewall_rules_attr_mask(IPACM_firewall_conf_t *firewall_config);
616 
617 #ifdef FEATURE_IPA_ANDROID
618 	/* wan posting supported tether_iface */
619 	int post_wan_up_tether_evt(ipa_ip_type iptype, int ipa_if_num_tether);
620 
621 	int post_wan_down_tether_evt(ipa_ip_type iptype, int ipa_if_num_tether);
622 #endif
623 	int config_dft_firewall_rules(ipa_ip_type iptype);
624 
625 	/* configure the initial firewall filter rules */
626 	int config_dft_embms_rules(ipa_ioc_add_flt_rule *pFilteringTable_v4, ipa_ioc_add_flt_rule *pFilteringTable_v6);
627 
628 	int handle_route_del_evt(ipa_ip_type iptype, bool delete_only = false);
629 
630 	int del_dft_firewall_rules(ipa_ip_type iptype);
631 
632 	int handle_down_evt();
633 
634 	/*handle wan-iface down event */
635 	int handle_down_evt_ex();
636 
637 	/* wan default route/filter rule delete */
638 	int handle_route_del_evt_ex(ipa_ip_type iptype);
639 
640 	/* configure the initial firewall filter rules */
641 	int config_dft_firewall_rules_ex(struct ipa_flt_rule_add* rules, int rule_offset,
642 		ipa_ip_type iptype);
643 
644 	/* init filtering rule in wan dl filtering table */
645 	int init_fl_rule_ex(ipa_ip_type iptype);
646 
647 	/* add ICMP and ALG rules in wan dl filtering table */
648 	int add_icmp_alg_rules(struct ipa_flt_rule_add* rules, int rule_offset, ipa_ip_type iptype);
649 
650 	/* query extended property */
651 	int query_ext_prop();
652 
653 	ipa_ioc_query_intf_ext_props *ext_prop;
654 
655 	int config_wan_firewall_rule(ipa_ip_type iptype);
656 
657 	int del_wan_firewall_rule(ipa_ip_type iptype);
658 
659 	int add_dft_filtering_rule(struct ipa_flt_rule_add* rules, int rule_offset, ipa_ip_type iptype);
660 
661 	int install_wan_filtering_rule(bool is_sw_routing);
662 
663 	void handle_wlan_SCC_MCC_switch(bool, ipa_ip_type);
664 
665 	void handle_wan_client_SCC_MCC_switch(bool, ipa_ip_type);
666 
667 	int handle_network_stats_evt();
668 
669 	int m_fd_ipa;
670 
671 	int handle_network_stats_update(ipa_get_apn_data_stats_resp_msg_v01 *data);
672 
673 	/* construct dummy ethernet header */
674 	int add_dummy_rx_hdr();
675 
676 	int handle_coalesce_evt();
677 
678 	int add_offload_frag_rule();
679 
680 	int delete_offload_frag_rule();
681 
682 	int add_icmpv6_exception_rule();
683 
684 	int delete_icmpv6_exception_rule();
685 
686 	int add_tcp_fin_rst_exception_rule();
687 
688 	int delete_tcp_fin_rst_exception_rule();
689 
690 	/* MTU helper functions */
691 	int query_mtu_size();
692 };
693 
694 #endif /* IPACM_WAN_H */
695