1 /*
2 Copyright (c) 2013-2016, 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,                     /* NULL */
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_LAN_DELETE_SELF,                      /* ipacm_event_data_fid */
190 	IPACM_EVENT_MAX
191 } ipa_cm_event_id;
192 
193 typedef struct
194 {
195 	uint8_t num_rule;
196 	uint32_t rule_hdl[MAX_NUM_PROP];
197 } lan_to_lan_rt_rule_hdl;
198 
199 typedef enum
200 {
201 	LAN_IF = 0,
202 	WLAN_IF,
203 	WAN_IF,
204 	VIRTUAL_IF,
205 	ETH_IF,
206 	EMBMS_IF,
207 	ODU_IF,
208 	UNKNOWN_IF
209 } ipacm_iface_type;
210 
211 typedef enum
212 {
213 	ROUTER = 0,
214 	BRIDGE
215 } ipacm_cradle_iface_mode;
216 
217 typedef enum
218 {
219 	FULL,
220 	INTERNET
221 } ipacm_wlan_access_mode;
222 
223 typedef struct
224 {
225 	struct nf_conntrack *ct;
226 	enum nf_conntrack_msg_type type;
227 }ipacm_ct_evt_data;
228 
229 typedef struct
230 {
231 	char iface_name[IPA_IFACE_NAME_LEN];
232 	ipacm_iface_type if_cat;
233 	ipacm_cradle_iface_mode if_mode;
234 	ipacm_wlan_access_mode wlan_mode;
235 	int netlink_interface_index;
236 } ipa_ifi_dev_name_t;
237 
238 typedef struct
239 {
240 	uint32_t subnet_addr;
241 	uint32_t subnet_mask;
242 } ipa_private_subnet;
243 
244 
245 typedef struct _ipacm_event_data_all
246 {
247 	enum ipa_ip_type iptype;
248 	int if_index;
249 	uint32_t  ipv4_addr;
250 	uint32_t  ipv6_addr[4];
251 	uint8_t mac_addr[IPA_MAC_ADDR_SIZE];
252 } ipacm_event_data_all;
253 
254 class IPACM_Lan;
255 
256 typedef struct
257 {
258 	ipacm_cradle_iface_mode cradle_wan_mode;
259 } ipacm_event_cradle_wan_mode;
260 
261 typedef struct
262 {
263 	IPACM_Lan *p_iface;
264 	ipa_ip_type iptype;
265 	uint8_t mac_addr[6];
266 } ipacm_event_eth_bridge;
267 
268 typedef struct
269 {
270 	enum ipa_ip_type iptype;
271 	uint32_t src_ipv4_addr;
272 	uint32_t dst_ipv4_addr;
273 	uint32_t src_ipv6_addr[4];
274 	uint32_t dst_ipv6_addr[4];
275 } ipacm_event_connection;
276 
277 typedef struct _ipacm_event_data_fid
278 {
279 	int if_index;
280 } ipacm_event_data_fid;
281 
282 typedef struct
283 {
284 	ipacm_iface_type if_cat;
285 } ipacm_event_data_if_cat;
286 
287 typedef struct _ipacm_event_data_iptype
288 {
289 	int if_index;
290 	int if_index_tether;
291 	enum ipa_ip_type iptype;
292 #ifdef IPA_WAN_MSG_IPv6_ADDR_GW_LEN
293 	uint32_t  ipv4_addr_gw;
294 	uint32_t  ipv6_addr_gw[4];
295 #endif
296 } ipacm_event_data_iptype;
297 
298 
299 typedef struct _ipacm_event_data_addr
300 {
301 	enum ipa_ip_type iptype;
302 	int if_index;
303 	uint32_t  ipv4_addr_gw;
304 	uint32_t  ipv4_addr;
305 	uint32_t  ipv4_addr_mask;
306 	uint32_t  ipv6_addr[4];
307 	uint32_t  ipv6_addr_mask[4];
308 	uint32_t  ipv6_addr_gw[4];
309 } ipacm_event_data_addr;
310 
311 typedef struct _ipacm_event_data_mac
312 {
313 	int if_index;
314 	int ipa_if_cate;
315 	uint8_t mac_addr[IPA_MAC_ADDR_SIZE];
316 } ipacm_event_data_mac;
317 
318 typedef struct
319 {
320 	int if_index;
321 	uint8_t num_of_attribs;
322 	struct ipa_wlan_hdr_attrib_val attribs[0];
323 } ipacm_event_data_wlan_ex;
324 
325 typedef struct _ipacm_event_iface_up
326 {
327 	char ifname[IPA_IFACE_NAME_LEN];
328 	uint32_t ipv4_addr;
329 	uint32_t addr_mask;
330 	uint32_t ipv6_prefix[2];
331 	bool is_sta;
332 	uint8_t xlat_mux_id;
333 }ipacm_event_iface_up;
334 
335 typedef struct _ipacm_event_iface_up_tether
336 {
337 	uint32_t if_index_tether;
338 	uint32_t ipv6_prefix[2];
339 	bool is_sta;
340 }ipacm_event_iface_up_tehter;
341 
342 typedef enum
343 {
344 	Q6_WAN = 0,
345 	WLAN_WAN,
346 	ECM_WAN
347 } ipacm_wan_iface_type;
348 
349 typedef struct _ipacm_ifacemgr_data
350 {
351 	int if_index;
352 	ipacm_wan_iface_type if_type;
353 	uint8_t mac_addr[IPA_MAC_ADDR_SIZE];
354 }ipacm_ifacemgr_data;
355 
356 typedef struct _ipacm_offload_prefix {
357 	enum ipa_ip_type iptype;
358 	uint32_t v4Addr;
359 	uint32_t v4Mask;
360 	uint32_t v6Addr[4];
361 	uint32_t v6Mask[4];
362 } ipacm_offload_prefix;
363 
364 typedef struct {
365 	int if_index;
366 	_ipacm_offload_prefix prefix;
367 } ipacm_event_ipahal_stream;
368 
369 #endif /* IPA_CM_DEFS_H */
370