• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 Copyright (c) 2014-2017, 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 /*
31  * IPACM_LanToLan.h
32  *
33  *  Created on: Mar 4th, 2014
34  *      Author: Shihuan Liu
35  */
36 
37 #ifndef IPACM_LANTOLAN_H
38 #define IPACM_LANTOLAN_H
39 
40 #include <stdint.h>
41 #include "linux/msm_ipa.h"
42 #include "IPACM_Iface.h"
43 #include "IPACM_Defs.h"
44 #include "IPACM_Lan.h"
45 
46 #ifdef FEATURE_IPA_ANDROID
47 #include <libxml/list.h>
48 #else/* defined(FEATURE_IPA_ANDROID) */
49 #include <list>
50 #endif /* ndefined(FEATURE_IPA_ANDROID)*/
51 
52 #define MAX_NUM_CACHED_CLIENT_ADD_EVENT 10
53 #define MAX_NUM_IFACE 10
54 #define MAX_NUM_CLIENT 16
55 
56 struct vlan_iface_info
57 {
58 	char vlan_iface_name[IPA_RESOURCE_NAME_MAX];
59 	uint8_t vlan_id;
60 	uint32_t vlan_iface_ipv6_addr[4];
61 	uint8_t vlan_client_mac[6];
62 	uint32_t vlan_client_ipv6_addr[4];
63 };
64 
65 struct l2tp_vlan_mapping_info
66 {
67 	/* the following are l2tp iface info (name, session id) */
68 	char l2tp_iface_name[IPA_RESOURCE_NAME_MAX];
69 	uint8_t l2tp_session_id;
70 	/* the following are mdm vlan iface info (name, vlan id, ipv6 addr) */
71 	char vlan_iface_name[IPA_RESOURCE_NAME_MAX];
72 	uint8_t vlan_id;
73 	uint32_t vlan_iface_ipv6_addr[4];
74 	/* the following are MIB3 vlan client info (mac, ipv6 addr) */
75 	uint8_t vlan_client_mac[6];
76 	uint32_t vlan_client_ipv6_addr[4];
77 	/* the following is MIB3 l2tp client info (mac) */
78 	uint8_t l2tp_client_mac[6];
79 };
80 
81 struct rt_rule_info
82 {
83 	int num_hdl[IPA_IP_MAX];	/* one client may need more than one routing rules on the same routing table depending on tx_prop */
84 	uint32_t  rule_hdl[IPA_IP_MAX][MAX_NUM_PROP];
85 };
86 
87 struct l2tp_rt_rule_info
88 {
89 	uint32_t first_pass_hdr_hdl;	/* first pass hdr template (IPv4 and IPv6 use the same hdr template) */
90 	uint32_t first_pass_hdr_proc_ctx_hdl[IPA_IP_MAX]; /* first pass hdr proc ctx */
91 	uint32_t second_pass_hdr_hdl;	/* second pass hdr template (IPv4 and IPv6 use the same hdr template) */
92 	int num_rt_hdl[IPA_IP_MAX];		/* number of TX properties for IPv4 and IPv6 respectively */
93 	uint32_t  first_pass_rt_rule_hdl[IPA_IP_MAX][MAX_NUM_PROP];	/* first pass routing rule */
94 	uint32_t  second_pass_rt_rule_hdl[MAX_NUM_PROP];	/*second pass routing rule (only ipv6 rt rule is needed) */
95 };
96 
97 struct client_info
98 {
99 	uint8_t mac_addr[6];
100 	rt_rule_info inter_iface_rt_rule_hdl[IPA_HDR_L2_MAX];	/* routing rule handles of inter interface communication based on source l2 header type */
101 	rt_rule_info intra_iface_rt_rule_hdl;	/* routing rule handles of inter interface communication */
102 	bool is_l2tp_client;
103 	l2tp_vlan_mapping_info *mapping_info;
104 	l2tp_rt_rule_info l2tp_rt_rule_hdl[IPA_HDR_L2_MAX];
105 };
106 
107 struct flt_rule_info
108 {
109 	client_info *p_client;
110 	uint32_t flt_rule_hdl[IPA_IP_MAX];
111 	uint32_t l2tp_first_pass_flt_rule_hdl[IPA_IP_MAX];	/* L2TP filtering rules are destination MAC based */
112 	uint32_t l2tp_second_pass_flt_rule_hdl;
113 };
114 
115 struct peer_iface_info
116 {
117 	class IPACM_LanToLan_Iface *peer;
118 	char rt_tbl_name_for_rt[IPA_IP_MAX][IPA_RESOURCE_NAME_MAX];
119 	char rt_tbl_name_for_flt[IPA_IP_MAX][IPA_RESOURCE_NAME_MAX];
120 	list<flt_rule_info> flt_rule;
121 };
122 
123 class IPACM_LanToLan_Iface
124 {
125 public:
126 	IPACM_LanToLan_Iface(IPACM_Lan *p_iface);
127 	~IPACM_LanToLan_Iface();
128 
129 	void add_client_rt_rule_for_new_iface();
130 
131 	void add_all_inter_interface_client_flt_rule(ipa_ip_type iptype);
132 
133 	void add_all_intra_interface_client_flt_rule(ipa_ip_type iptype);
134 
135 	void handle_down_event();
136 
137 	void handle_wlan_scc_mcc_switch();
138 
139 	void handle_intra_interface_info();
140 
141 	void handle_new_iface_up(char rt_tbl_name_for_flt[][IPA_RESOURCE_NAME_MAX], char rt_tbl_name_for_rt[][IPA_RESOURCE_NAME_MAX],
142 		IPACM_LanToLan_Iface *peer_iface);
143 
144 	void handle_client_add(uint8_t *mac, bool is_l2tp_client, l2tp_vlan_mapping_info *mapping_info);
145 
146 	void handle_client_del(uint8_t *mac);
147 
148 	void print_data_structure_info();
149 
150 	IPACM_Lan* get_iface_pointer();
151 
152 	bool get_m_is_ip_addr_assigned(ipa_ip_type iptype);
153 
154 	void set_m_is_ip_addr_assigned(ipa_ip_type iptype, bool value);
155 
156 	bool get_m_support_inter_iface_offload();
157 
158 	bool get_m_support_intra_iface_offload();
159 
160 	void increment_ref_cnt_peer_l2_hdr_type(ipa_hdr_l2_type peer_l2_type);
161 
162 	void decrement_ref_cnt_peer_l2_hdr_type(ipa_hdr_l2_type peer_l2_type);
163 #ifdef FEATURE_L2TP
164 	void switch_to_l2tp_iface();
165 
166 	bool set_l2tp_iface(char *vlan_iface_name);
167 
168 	bool is_l2tp_iface();
169 
170 	void handle_l2tp_enable();
171 
172 	void handle_l2tp_disable();
173 #endif
174 private:
175 
176 	IPACM_Lan *m_p_iface;
177 	bool m_is_ip_addr_assigned[IPA_IP_MAX];
178 	bool m_support_inter_iface_offload;
179 	bool m_support_intra_iface_offload;
180 	bool m_is_l2tp_iface;
181 
182 	int ref_cnt_peer_l2_hdr_type[IPA_HDR_L2_MAX];	/* reference count of l2 header type of peer interfaces */
183 	uint32_t hdr_proc_ctx_for_inter_interface[IPA_HDR_L2_MAX];
184 	uint32_t hdr_proc_ctx_for_intra_interface;
185 	uint32_t hdr_proc_ctx_for_l2tp;		/* uc needs to remove 62 bytes IPv6 + L2TP + inner Ethernet header */
186 
187 	list<client_info> m_client_info;	/* client list */
188 	list<peer_iface_info> m_peer_iface_info;	/* peer information list */
189 
190 	/* The following members are for intra-interface communication*/
191 	peer_iface_info m_intra_interface_info;
192 
193 	void add_one_client_flt_rule(IPACM_LanToLan_Iface *peer_iface, client_info *client);
194 
195 	void add_client_flt_rule(peer_iface_info *peer, client_info *client, ipa_ip_type iptype);
196 
197 	void del_one_client_flt_rule(IPACM_LanToLan_Iface *peer_iface, client_info *client);
198 
199 	void del_client_flt_rule(peer_iface_info *peer, client_info *client);
200 
201 	void add_client_rt_rule(peer_iface_info *peer, client_info *client);
202 
203 	void del_client_rt_rule(peer_iface_info *peer, client_info *client);
204 
205 	void add_l2tp_client_rt_rule(peer_iface_info *peer, client_info *client);
206 
207 	void clear_all_flt_rule_for_one_peer_iface(peer_iface_info *peer);
208 
209 	void clear_all_rt_rule_for_one_peer_iface(peer_iface_info *peer);
210 
211 	void add_hdr_proc_ctx(ipa_hdr_l2_type peer_l2_type);
212 
213 	void del_hdr_proc_ctx(ipa_hdr_l2_type peer_l2_type);
214 
215 	void print_peer_info(peer_iface_info *peer_info);
216 
217 };
218 
219 class IPACM_LanToLan : public IPACM_Listener
220 {
221 
222 public:
223 
224 	static IPACM_LanToLan* p_instance;
225 	static IPACM_LanToLan* get_instance();
226 #ifdef FEATURE_L2TP
227 	bool has_l2tp_iface();
228 #endif
229 
230 private:
231 
232 	IPACM_LanToLan();
233 
234 	~IPACM_LanToLan();
235 
236 	bool m_has_l2tp_iface;
237 
238 	list<class IPACM_LanToLan_Iface> m_iface;
239 
240 	list<ipacm_event_eth_bridge> m_cached_client_add_event;
241 
242 	list<vlan_iface_info> m_vlan_iface;
243 
244 	list<l2tp_vlan_mapping_info> m_l2tp_vlan_mapping;
245 
246 	void handle_iface_up(ipacm_event_eth_bridge *data);
247 
248 	void handle_iface_down(ipacm_event_eth_bridge *data);
249 
250 	void handle_client_add(ipacm_event_eth_bridge *data);
251 
252 	void handle_client_del(ipacm_event_eth_bridge *data);
253 
254 	void handle_wlan_scc_mcc_switch(ipacm_event_eth_bridge *data);
255 
256 #ifdef FEATURE_L2TP
257 	void handle_add_vlan_iface(ipa_ioc_vlan_iface_info *data);
258 
259 	void handle_del_vlan_iface(ipa_ioc_vlan_iface_info *data);
260 
261 	void handle_add_l2tp_vlan_mapping(ipa_ioc_l2tp_vlan_mapping_info *data);
262 
263 	void handle_del_l2tp_vlan_mapping(ipa_ioc_l2tp_vlan_mapping_info *data);
264 
265 	void handle_vlan_client_info(ipacm_event_data_all *data);
266 
267 	void handle_vlan_iface_info(ipacm_event_data_all *data);
268 #endif
269 
270 	void handle_new_iface_up(IPACM_LanToLan_Iface *new_iface, IPACM_LanToLan_Iface *exist_iface);
271 
272 	void event_callback(ipa_cm_event_id event, void* param);
273 
274 	void handle_cached_client_add_event(IPACM_Lan *p_iface);
275 
276 	void clear_cached_client_add_event(IPACM_Lan *p_iface);
277 
278 	void print_data_structure_info();
279 
280 };
281 
282 #endif
283