• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 Copyright (c) 2013-2018, 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_Defs.h
32 
33 	@brief
34 	This file implements the common definitions amon all ifaces.
35 
36 	@Author
37 	Skylar Chang
38 
39 */
40 #ifndef IPA_CM_DEFS_H
41 #define IPA_CM_DEFS_H
42 
43 #include <unistd.h>
44 #include <fcntl.h>
45 #include <linux/msm_ipa.h>
46 #include "IPACM_Log.h"
47 
48 #ifdef USE_GLIB
49 #include <glib.h>
50 #define strlcpy g_strlcpy
51 #define strlcat g_strlcat
52 #endif
53 
54 extern "C"
55 {
56 #include <libnetfilter_conntrack/libnetfilter_conntrack.h>
57 #include <libnetfilter_conntrack/libnetfilter_conntrack_tcp.h>
58 }
59 
60 #define IF_NAME_LEN 16
61 #define IPA_MAX_FILE_LEN  64
62 #define IPA_IFACE_NAME_LEN 16
63 #define IPA_ALG_PROTOCOL_NAME_LEN  10
64 
65 #define IPA_WLAN_PARTIAL_HDR_OFFSET  0 // dst mac first then src mac
66 #define IPA_ODU_PARTIAL_HDR_OFFSET  8 // dst mac first then src mac
67 #define IPA_WLAN_PARTIAL_HDR_NAME_v4  "IEEE802_3_v4"
68 #define IPA_WLAN_PARTIAL_HDR_NAME_v6  "IEEE802_3_v6"
69 #define IPA_DUMMY_ETH_HDR_NAME_v6     "ETH_dummy_v6"
70 #define IPA_WAN_PARTIAL_HDR_NAME_v4  "IEEE802_3_STA_v4"
71 #define IPA_WAN_PARTIAL_HDR_NAME_v6  "IEEE802_3_STA_v6"
72 #define IPA_ETH_HDR_NAME_v4  "IPACM_ETH_v4"
73 #define IPA_ETH_HDR_NAME_v6  "IPACM_ETH_v6"
74 #define IPA_ODU_HDR_NAME_v4  "IPACM_ODU_v4"
75 #define IPA_ODU_HDR_NAME_v6  "IPACM_ODU_v6"
76 
77 
78 #define IPA_MAX_IFACE_ENTRIES 20
79 #define IPA_MAX_PRIVATE_SUBNET_ENTRIES 3
80 #define IPA_MAX_ALG_ENTRIES 20
81 #define IPA_MAX_RM_ENTRY 6
82 
83 #define IPV4_ADDR_LINKLOCAL 0xA9FE0000
84 #define IPV4_ADDR_LINKLOCAL_MASK 0xFFFF0000
85 
86 #define V4_DEFAULT_ROUTE_TABLE_NAME  "ipa_dflt_rt"
87 #define V4_LAN_ROUTE_TABLE_NAME  "COMRTBLLANv4"
88 #define V4_WAN_ROUTE_TABLE_NAME  "WANRTBLv4"
89 #define WAN_DL_ROUTE_TABLE_NAME "ipa_dflt_wan_rt"
90 #define V6_COMMON_ROUTE_TABLE_NAME  "COMRTBLv6"
91 #define V6_WAN_ROUTE_TABLE_NAME  "WANRTBLv6"
92 #define V4_ODU_ROUTE_TABLE_NAME  "ODURTBLv4"
93 #define V6_ODU_ROUTE_TABLE_NAME  "ODURTBLv6"
94 
95 #define WWAN_QMI_IOCTL_DEVICE_NAME "/dev/wwan_ioctl"
96 #define IPA_DEVICE_NAME "/dev/ipa"
97 #define MAX_NUM_PROP 2
98 
99 #ifndef FEATURE_IPA_V3
100 #define IPA_MAX_FLT_RULE 50
101 #else
102 #define IPA_MAX_FLT_RULE 100
103 #endif
104 
105 #define TCP_FIN_SHIFT 16
106 #define TCP_SYN_SHIFT 17
107 #define TCP_RST_SHIFT 18
108 #define NUM_IPV6_PREFIX_FLT_RULE 1
109 
110 /*---------------------------------------------------------------------------
111 										Return values indicating error status
112 ---------------------------------------------------------------------------*/
113 
114 #define IPACM_SUCCESS                0         /* Successful operation   */
115 #define IPACM_FAILURE               -1         /* Unsuccessful operation */
116 
117 #define IPACM_IP_NULL (ipa_ip_type)0xFF
118 #define IPACM_INVALID_INDEX (ipa_ip_type)0xFF
119 
120 #define IPA_MAX_NUM_WIFI_CLIENTS  32
121 #define IPA_MAX_NUM_WAN_CLIENTS  10
122 #define IPA_MAX_NUM_ETH_CLIENTS  15
123 #define IPA_MAX_NUM_AMPDU_RULE  15
124 #define IPA_MAC_ADDR_SIZE  6
125 
126 /*===========================================================================
127 										 GLOBAL DEFINITIONS AND DECLARATIONS
128 ===========================================================================*/
129 typedef enum
130 {
131 	IPA_CFG_CHANGE_EVENT,                 /* NULL */
132 	IPA_PRIVATE_SUBNET_CHANGE_EVENT,          /* ipacm_event_data_fid */
133 	IPA_FIREWALL_CHANGE_EVENT,                /* NULL */
134 	IPA_LINK_UP_EVENT,                        /* ipacm_event_data_fid */
135 	IPA_LINK_DOWN_EVENT,                      /* ipacm_event_data_fid */
136 	IPA_USB_LINK_UP_EVENT,                    /* ipacm_event_data_fid */
137 	IPA_BRIDGE_LINK_UP_EVENT,                 /* ipacm_event_data_all */
138 	IPA_WAN_EMBMS_LINK_UP_EVENT,              /* ipacm_event_data_mac */
139 	IPA_ADDR_ADD_EVENT,                       /* ipacm_event_data_addr */
140 	IPA_ADDR_DEL_EVENT,                       /* no use */
141 	IPA_ROUTE_ADD_EVENT,                      /* ipacm_event_data_addr */
142 	IPA_ROUTE_DEL_EVENT,                      /* ipacm_event_data_addr */
143 	IPA_WAN_UPSTREAM_ROUTE_ADD_EVENT,         /* ipacm_event_data_fid */
144 	IPA_WAN_UPSTREAM_ROUTE_DEL_EVENT,         /* ipacm_event_data_fid */
145 	IPA_WLAN_AP_LINK_UP_EVENT,                /* ipacm_event_data_mac */
146 	IPA_WLAN_STA_LINK_UP_EVENT,               /* ipacm_event_data_mac */
147 	IPA_WLAN_LINK_DOWN_EVENT,                 /* ipacm_event_data_mac */
148 	IPA_WLAN_CLIENT_ADD_EVENT,                /* ipacm_event_data_mac */
149 	IPA_WLAN_CLIENT_ADD_EVENT_EX,             /* ipacm_event_data_wlan_ex */
150 	IPA_WLAN_CLIENT_DEL_EVENT,                /* ipacm_event_data_mac */
151 	IPA_WLAN_CLIENT_POWER_SAVE_EVENT,         /* ipacm_event_data_mac */
152 	IPA_WLAN_CLIENT_RECOVER_EVENT,            /* ipacm_event_data_mac */
153 	IPA_NEW_NEIGH_EVENT,                      /* ipacm_event_data_all */
154 	IPA_DEL_NEIGH_EVENT,                      /* ipacm_event_data_all */
155 	IPA_NEIGH_CLIENT_IP_ADDR_ADD_EVENT,       /* ipacm_event_data_all */
156 	IPA_NEIGH_CLIENT_IP_ADDR_DEL_EVENT,       /* ipacm_event_data_all */
157 	IPA_SW_ROUTING_ENABLE,                    /* NULL */
158 	IPA_SW_ROUTING_DISABLE,                   /* NULL */
159 	IPA_PROCESS_CT_MESSAGE,                   /* ipacm_ct_evt_data */
160 	IPA_PROCESS_CT_MESSAGE_V6,                /* ipacm_ct_evt_data */
161 	IPA_LAN_TO_LAN_NEW_CONNECTION,            /* ipacm_event_connection */
162 	IPA_LAN_TO_LAN_DEL_CONNECTION,            /* ipacm_event_connection */
163 	IPA_WLAN_SWITCH_TO_SCC,                   /* No Data */
164 	IPA_WLAN_SWITCH_TO_MCC,                   /* No Data */
165 	IPA_CRADLE_WAN_MODE_SWITCH,               /* ipacm_event_cradle_wan_mode */
166 	IPA_WAN_XLAT_CONNECT_EVENT,               /* ipacm_event_data_fid */
167 	IPA_TETHERING_STATS_UPDATE_EVENT,         /* ipacm_event_data_fid */
168 	IPA_NETWORK_STATS_UPDATE_EVENT,           /* ipacm_event_data_fid */
169 	IPA_DOWNSTREAM_ADD,                       /* ipacm_event_ipahal_stream */
170 	IPA_DOWNSTREAM_DEL,                       /* ipacm_event_ipahal_stream */
171 
172 	IPA_EXTERNAL_EVENT_MAX,
173 
174 	IPA_HANDLE_WAN_UP,                        /* ipacm_event_iface_up  */
175 	IPA_HANDLE_WAN_DOWN,                      /* ipacm_event_iface_up  */
176 	IPA_HANDLE_WAN_UP_V6,                     /* ipacm_event_iface_up */
177 	IPA_HANDLE_WAN_DOWN_V6,                   /* NULL */
178 	IPA_HANDLE_WAN_UP_TETHER,                 /* ipacm_event_iface_up_tehter */
179 	IPA_HANDLE_WAN_DOWN_TETHER,               /* ipacm_event_iface_up_tehter */
180 	IPA_HANDLE_WAN_UP_V6_TETHER,              /* ipacm_event_iface_up_tehter */
181 	IPA_HANDLE_WAN_DOWN_V6_TETHER,            /* ipacm_event_iface_up_tehter */
182 	IPA_HANDLE_WLAN_UP,                       /* ipacm_event_iface_up */
183 	IPA_HANDLE_LAN_UP,                        /* ipacm_event_iface_up */
184 	IPA_ETH_BRIDGE_IFACE_UP,                  /* ipacm_event_eth_bridge*/
185 	IPA_ETH_BRIDGE_IFACE_DOWN,                /* ipacm_event_eth_bridge*/
186 	IPA_ETH_BRIDGE_CLIENT_ADD,                /* ipacm_event_eth_bridge */
187 	IPA_ETH_BRIDGE_CLIENT_DEL,                /* ipacm_event_eth_bridge*/
188 	IPA_ETH_BRIDGE_WLAN_SCC_MCC_SWITCH,       /* ipacm_event_eth_bridge*/
189 	IPA_SSR_NOTICE,						      /* NULL*/
190 #ifdef FEATURE_L2TP
191 	IPA_ADD_VLAN_IFACE,                       /* ipa_ioc_vlan_iface_info */
192 	IPA_DEL_VLAN_IFACE,                       /* ipa_ioc_vlan_iface_info */
193 	IPA_ADD_L2TP_VLAN_MAPPING,                /* ipa_ioc_l2tp_vlan_mapping_info */
194 	IPA_DEL_L2TP_VLAN_MAPPING,                /* ipa_ioc_l2tp_vlan_mapping_info */
195 	IPA_HANDLE_VLAN_CLIENT_INFO,              /* ipacm_event_data_all */
196 	IPA_HANDLE_VLAN_IFACE_INFO,               /* ipacm_event_data_all */
197 #endif
198 	IPA_WLAN_FWR_SSR_BEFORE_SHUTDOWN_NOTICE,
199 	IPA_LAN_DELETE_SELF,                      /* ipacm_event_data_fid */
200 	IPACM_EVENT_MAX
201 } ipa_cm_event_id;
202 
203 typedef struct
204 {
205 	uint8_t num_rule;
206 	uint32_t rule_hdl[MAX_NUM_PROP];
207 } lan_to_lan_rt_rule_hdl;
208 
209 typedef enum
210 {
211 	LAN_IF = 0,
212 	WLAN_IF,
213 	WAN_IF,
214 	VIRTUAL_IF,
215 	ETH_IF,
216 	EMBMS_IF,
217 	ODU_IF,
218 	UNKNOWN_IF
219 } ipacm_iface_type;
220 
221 typedef enum
222 {
223 	ROUTER = 0,
224 	BRIDGE
225 } ipacm_cradle_iface_mode;
226 
227 typedef enum
228 {
229 	FULL,
230 	INTERNET
231 } ipacm_wlan_access_mode;
232 
233 typedef struct
234 {
235 	struct nf_conntrack *ct;
236 	enum nf_conntrack_msg_type type;
237 }ipacm_ct_evt_data;
238 
239 typedef struct
240 {
241 	char iface_name[IPA_IFACE_NAME_LEN];
242 	ipacm_iface_type if_cat;
243 	ipacm_cradle_iface_mode if_mode;
244 	ipacm_wlan_access_mode wlan_mode;
245 	int netlink_interface_index;
246 } ipa_ifi_dev_name_t;
247 
248 typedef struct
249 {
250 	uint32_t subnet_addr;
251 	uint32_t subnet_mask;
252 } ipa_private_subnet;
253 
254 
255 typedef struct _ipacm_event_data_all
256 {
257 	enum ipa_ip_type iptype;
258 	int if_index;
259 	uint32_t  ipv4_addr;
260 	uint32_t  ipv6_addr[4];
261 	uint8_t mac_addr[IPA_MAC_ADDR_SIZE];
262 	char iface_name[IPA_IFACE_NAME_LEN];
263 } ipacm_event_data_all;
264 
265 class IPACM_Lan;
266 
267 typedef struct
268 {
269 	ipacm_cradle_iface_mode cradle_wan_mode;
270 } ipacm_event_cradle_wan_mode;
271 
272 typedef struct
273 {
274 	IPACM_Lan *p_iface;
275 	ipa_ip_type iptype;
276 	uint8_t mac_addr[6];
277 	char iface_name[IPA_IFACE_NAME_LEN];
278 } ipacm_event_eth_bridge;
279 
280 typedef struct
281 {
282 	enum ipa_ip_type iptype;
283 	uint32_t src_ipv4_addr;
284 	uint32_t dst_ipv4_addr;
285 	uint32_t src_ipv6_addr[4];
286 	uint32_t dst_ipv6_addr[4];
287 } ipacm_event_connection;
288 
289 typedef struct _ipacm_event_data_fid
290 {
291 	int if_index;
292 } ipacm_event_data_fid;
293 
294 typedef struct
295 {
296 	ipacm_iface_type if_cat;
297 } ipacm_event_data_if_cat;
298 
299 typedef struct _ipacm_event_data_iptype
300 {
301 	int if_index;
302 	int if_index_tether;
303 	enum ipa_ip_type iptype;
304 #ifdef IPA_WAN_MSG_IPv6_ADDR_GW_LEN
305 	uint32_t  ipv4_addr_gw;
306 	uint32_t  ipv6_addr_gw[4];
307 #endif
308 } ipacm_event_data_iptype;
309 
310 
311 typedef struct _ipacm_event_data_addr
312 {
313 	enum ipa_ip_type iptype;
314 	char iface_name[IPA_IFACE_NAME_LEN];
315 	int if_index;
316 	uint32_t  ipv4_addr_gw;
317 	uint32_t  ipv4_addr;
318 	uint32_t  ipv4_addr_mask;
319 	uint32_t  ipv6_addr[4];
320 	uint32_t  ipv6_addr_mask[4];
321 	uint32_t  ipv6_addr_gw[4];
322 } ipacm_event_data_addr;
323 
324 typedef struct _ipacm_event_data_mac
325 {
326 	int if_index;
327 	int ipa_if_cate;
328 	uint8_t mac_addr[IPA_MAC_ADDR_SIZE];
329 } ipacm_event_data_mac;
330 
331 typedef struct
332 {
333 	int if_index;
334 	uint8_t num_of_attribs;
335 	struct ipa_wlan_hdr_attrib_val attribs[0];
336 } ipacm_event_data_wlan_ex;
337 
338 typedef struct _ipacm_event_iface_up
339 {
340 	char ifname[IPA_IFACE_NAME_LEN];
341 	uint32_t ipv4_addr;
342 	uint32_t addr_mask;
343 	uint32_t ipv6_prefix[2];
344 	bool is_sta;
345 	uint8_t xlat_mux_id;
346 	uint8_t mux_id;
347 }ipacm_event_iface_up;
348 
349 typedef struct _ipacm_event_iface_up_tether
350 {
351 	uint32_t if_index_tether;
352 	uint32_t ipv6_prefix[2];
353 	bool is_sta;
354 }ipacm_event_iface_up_tehter;
355 
356 typedef enum
357 {
358 	Q6_WAN = 0,
359 	WLAN_WAN,
360 	ECM_WAN
361 } ipacm_wan_iface_type;
362 
363 typedef struct _ipacm_ifacemgr_data
364 {
365 	int if_index;
366 	ipacm_wan_iface_type if_type;
367 	uint8_t mac_addr[IPA_MAC_ADDR_SIZE];
368 }ipacm_ifacemgr_data;
369 
370 typedef struct _ipacm_offload_prefix {
371 	enum ipa_ip_type iptype;
372 	uint32_t v4Addr;
373 	uint32_t v4Mask;
374 	uint32_t v6Addr[4];
375 	uint32_t v6Mask[4];
376 } ipacm_offload_prefix;
377 
378 typedef struct {
379 	int if_index;
380 	_ipacm_offload_prefix prefix;
381 } ipacm_event_ipahal_stream;
382 
383 #endif /* IPA_CM_DEFS_H */
384