1 /*
2 Copyright (c) 2013-2019, 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_MTU_ENTRIES 3
81 #define IPA_MAX_ALG_ENTRIES 20
82 #define IPA_MAX_RM_ENTRY 6
83 
84 #define IPV4_ADDR_LINKLOCAL 0xA9FE0000
85 #define IPV4_ADDR_LINKLOCAL_MASK 0xFFFF0000
86 
87 #define V4_DEFAULT_ROUTE_TABLE_NAME  "ipa_dflt_rt"
88 #define V4_LAN_ROUTE_TABLE_NAME  "COMRTBLLANv4"
89 #define V4_WAN_ROUTE_TABLE_NAME  "WANRTBLv4"
90 #define WAN_DL_ROUTE_TABLE_NAME "ipa_dflt_wan_rt"
91 #define V6_COMMON_ROUTE_TABLE_NAME  "COMRTBLv6"
92 #define V6_WAN_ROUTE_TABLE_NAME  "WANRTBLv6"
93 #define V4_ODU_ROUTE_TABLE_NAME  "ODURTBLv4"
94 #define V6_ODU_ROUTE_TABLE_NAME  "ODURTBLv6"
95 
96 #define WWAN_QMI_IOCTL_DEVICE_NAME "/dev/wwan_ioctl"
97 #define IPA_DEVICE_NAME "/dev/ipa"
98 #define MAX_NUM_PROP 2
99 
100 #define IPA_MAX_FLT_RULE 100
101 
102 #define TCP_FIN_SHIFT 16
103 #define TCP_SYN_SHIFT 17
104 #define TCP_RST_SHIFT 18
105 #define NUM_IPV6_PREFIX_FLT_RULE 1
106 #define NUM_IPV6_PREFIX_MTU_RULE 1
107 
108 #define MAX_CONNTRACK_ENTRIES 100
109 #define CT_ENTRIES_BUFFER_SIZE 8096
110 #define LOOPBACK_MASK 0xFF000000
111 #define LOOPBACK_ADDR 0x7F000000
112 
113 /*---------------------------------------------------------------------------
114 										Return values indicating error status
115 ---------------------------------------------------------------------------*/
116 
117 #define IPACM_SUCCESS                0         /* Successful operation   */
118 #define IPACM_FAILURE               -1         /* Unsuccessful operation */
119 
120 #define IPACM_IP_NULL (ipa_ip_type)0xFF
121 #define IPACM_INVALID_INDEX (ipa_ip_type)0xFF
122 
123 #define IPA_MAX_NUM_WIFI_CLIENTS  32
124 #define IPA_MAX_NUM_WAN_CLIENTS  10
125 #define IPA_MAX_NUM_ETH_CLIENTS  15
126 #define IPA_MAX_NUM_AMPDU_RULE  15
127 #define IPA_MAC_ADDR_SIZE  6
128 #define IPA_MAX_NUM_SW_PDNS 15
129 
130 #define DEFAULT_MTU_SIZE 1500
131 /*===========================================================================
132 										 GLOBAL DEFINITIONS AND DECLARATIONS
133 ===========================================================================*/
134 typedef enum
135 {
136 	IPA_CFG_CHANGE_EVENT,                 /* NULL */
137 	IPA_PRIVATE_SUBNET_CHANGE_EVENT,          /* ipacm_event_data_fid */
138 	IPA_FIREWALL_CHANGE_EVENT,                /* NULL */
139 	IPA_LINK_UP_EVENT,                        /* ipacm_event_data_fid */
140 	IPA_LINK_DOWN_EVENT,                      /* ipacm_event_data_fid */
141 	IPA_USB_LINK_UP_EVENT,                    /* ipacm_event_data_fid */
142 	IPA_BRIDGE_LINK_UP_EVENT,                 /* ipacm_event_data_all */
143 	IPA_WAN_EMBMS_LINK_UP_EVENT,              /* ipacm_event_data_mac */
144 	IPA_ADDR_ADD_EVENT,                       /* ipacm_event_data_addr */
145 	IPA_ADDR_DEL_EVENT,                       /* no use */
146 	IPA_ROUTE_ADD_EVENT,                      /* ipacm_event_data_addr */
147 	IPA_ROUTE_DEL_EVENT,                      /* ipacm_event_data_addr */
148 	IPA_WAN_UPSTREAM_ROUTE_ADD_EVENT,         /* ipacm_event_data_fid */
149 	IPA_WAN_UPSTREAM_ROUTE_DEL_EVENT,         /* ipacm_event_data_fid */
150 	IPA_WLAN_AP_LINK_UP_EVENT,                /* ipacm_event_data_mac */
151 	IPA_WLAN_STA_LINK_UP_EVENT,               /* ipacm_event_data_mac */
152 	IPA_WLAN_LINK_DOWN_EVENT,                 /* ipacm_event_data_mac */
153 	IPA_WLAN_CLIENT_ADD_EVENT,                /* ipacm_event_data_mac */
154 	IPA_WLAN_CLIENT_ADD_EVENT_EX,             /* ipacm_event_data_wlan_ex */
155 	IPA_WLAN_CLIENT_DEL_EVENT,                /* ipacm_event_data_mac */
156 	IPA_WLAN_CLIENT_POWER_SAVE_EVENT,         /* ipacm_event_data_mac */
157 	IPA_WLAN_CLIENT_RECOVER_EVENT,            /* ipacm_event_data_mac */
158 	IPA_NEW_NEIGH_EVENT,                      /* ipacm_event_data_all */
159 	IPA_DEL_NEIGH_EVENT,                      /* ipacm_event_data_all */
160 	IPA_NEIGH_CLIENT_IP_ADDR_ADD_EVENT,       /* ipacm_event_data_all */
161 	IPA_NEIGH_CLIENT_IP_ADDR_DEL_EVENT,       /* ipacm_event_data_all */
162 	IPA_SW_ROUTING_ENABLE,                    /* NULL */
163 	IPA_SW_ROUTING_DISABLE,                   /* NULL */
164 	IPA_PROCESS_CT_MESSAGE,                   /* ipacm_ct_evt_data */
165 	IPA_PROCESS_CT_MESSAGE_V6,                /* ipacm_ct_evt_data */
166 	IPA_LAN_TO_LAN_NEW_CONNECTION,            /* ipacm_event_connection */
167 	IPA_LAN_TO_LAN_DEL_CONNECTION,            /* ipacm_event_connection */
168 	IPA_WLAN_SWITCH_TO_SCC,                   /* No Data */
169 	IPA_WLAN_SWITCH_TO_MCC,                   /* No Data */
170 	IPA_CRADLE_WAN_MODE_SWITCH,               /* ipacm_event_cradle_wan_mode */
171 	IPA_WAN_XLAT_CONNECT_EVENT,               /* ipacm_event_data_fid */
172 	IPA_TETHERING_STATS_UPDATE_EVENT,         /* ipacm_event_data_fid */
173 	IPA_NETWORK_STATS_UPDATE_EVENT,           /* ipacm_event_data_fid */
174 	IPA_DOWNSTREAM_ADD,                       /* ipacm_event_ipahal_stream */
175 	IPA_DOWNSTREAM_DEL,                       /* ipacm_event_ipahal_stream */
176 
177 	IPA_EXTERNAL_EVENT_MAX,
178 
179 	IPA_HANDLE_WAN_UP,                        /* ipacm_event_iface_up  */
180 	IPA_HANDLE_WAN_DOWN,                      /* ipacm_event_iface_up  */
181 	IPA_HANDLE_WAN_UP_V6,                     /* ipacm_event_iface_up */
182 	IPA_HANDLE_WAN_DOWN_V6,                   /* NULL */
183 	IPA_HANDLE_WAN_UP_TETHER,                 /* ipacm_event_iface_up_tehter */
184 	IPA_HANDLE_WAN_DOWN_TETHER,               /* ipacm_event_iface_up_tehter */
185 	IPA_HANDLE_WAN_UP_V6_TETHER,              /* ipacm_event_iface_up_tehter */
186 	IPA_HANDLE_WAN_DOWN_V6_TETHER,            /* ipacm_event_iface_up_tehter */
187 	IPA_HANDLE_WLAN_UP,                       /* ipacm_event_iface_up */
188 	IPA_HANDLE_LAN_UP,                        /* ipacm_event_iface_up */
189 	IPA_ETH_BRIDGE_IFACE_UP,                  /* ipacm_event_eth_bridge*/
190 	IPA_ETH_BRIDGE_IFACE_DOWN,                /* ipacm_event_eth_bridge*/
191 	IPA_ETH_BRIDGE_CLIENT_ADD,                /* ipacm_event_eth_bridge */
192 	IPA_ETH_BRIDGE_CLIENT_DEL,                /* ipacm_event_eth_bridge*/
193 	IPA_ETH_BRIDGE_WLAN_SCC_MCC_SWITCH,       /* ipacm_event_eth_bridge*/
194 	IPA_SSR_NOTICE,                           /* NULL*/
195 	IPA_COALESCE_NOTICE,                      /* NULL*/
196 #ifdef IPA_MTU_EVENT_MAX
197 	IPA_MTU_SET,                              /* ipa_mtu_info */
198 	IPA_MTU_UPDATE,                           /* ipacm_event_mtu_info */
199 #endif
200 #ifdef FEATURE_L2TP
201 	IPA_ADD_VLAN_IFACE,                       /* ipa_ioc_vlan_iface_info */
202 	IPA_DEL_VLAN_IFACE,                       /* ipa_ioc_vlan_iface_info */
203 	IPA_ADD_L2TP_VLAN_MAPPING,                /* ipa_ioc_l2tp_vlan_mapping_info */
204 	IPA_DEL_L2TP_VLAN_MAPPING,                /* ipa_ioc_l2tp_vlan_mapping_info */
205 	IPA_HANDLE_VLAN_CLIENT_INFO,              /* ipacm_event_data_all */
206 	IPA_HANDLE_VLAN_IFACE_INFO,               /* ipacm_event_data_all */
207 #endif
208 	IPA_WLAN_FWR_SSR_BEFORE_SHUTDOWN_NOTICE,
209 	IPA_LAN_DELETE_SELF,                      /* ipacm_event_data_fid */
210 	IPA_WIGIG_CLIENT_ADD_EVENT,               /* ipacm_event_data_mac_ep */
211 	IPA_WIGIG_FST_SWITCH,                     /* ipacm_event_data_fst */
212 	IPACM_EVENT_MAX
213 } ipa_cm_event_id;
214 
215 typedef struct
216 {
217 	uint8_t num_rule;
218 	uint32_t rule_hdl[MAX_NUM_PROP];
219 } lan_to_lan_rt_rule_hdl;
220 
221 typedef enum
222 {
223 	LAN_IF = 0,
224 	WLAN_IF,
225 	WAN_IF,
226 	VIRTUAL_IF,
227 	ETH_IF,
228 	EMBMS_IF,
229 	ODU_IF,
230 	UNKNOWN_IF
231 } ipacm_iface_type;
232 
233 typedef enum
234 {
235 	ROUTER = 0,
236 	BRIDGE
237 } ipacm_cradle_iface_mode;
238 
239 typedef enum
240 {
241 	FULL,
242 	INTERNET
243 } ipacm_wlan_access_mode;
244 
245 typedef struct
246 {
247 	struct nf_conntrack *ct;
248 	enum nf_conntrack_msg_type type;
249 }ipacm_ct_evt_data;
250 
251 typedef struct
252 {
253 	char iface_name[IPA_IFACE_NAME_LEN];
254 	ipacm_iface_type if_cat;
255 	ipacm_cradle_iface_mode if_mode;
256 	ipacm_wlan_access_mode wlan_mode;
257 	int netlink_interface_index;
258 } ipa_ifi_dev_name_t;
259 
260 typedef struct
261 {
262 	uint32_t subnet_addr;
263 	uint32_t subnet_mask;
264 } ipa_private_subnet;
265 
266 
267 typedef struct _ipacm_event_data_all
268 {
269 	enum ipa_ip_type iptype;
270 	int if_index;
271 	uint32_t  ipv4_addr;
272 	uint32_t  ipv6_addr[4];
273 	uint8_t mac_addr[IPA_MAC_ADDR_SIZE];
274 	char iface_name[IPA_IFACE_NAME_LEN];
275 } ipacm_event_data_all;
276 
277 class IPACM_Lan;
278 
279 typedef struct
280 {
281 	ipacm_cradle_iface_mode cradle_wan_mode;
282 } ipacm_event_cradle_wan_mode;
283 
284 typedef struct
285 {
286 	IPACM_Lan *p_iface;
287 	ipa_ip_type iptype;
288 	uint8_t mac_addr[6];
289 	char iface_name[IPA_IFACE_NAME_LEN];
290 	int ep;
291 } ipacm_event_eth_bridge;
292 
293 typedef struct
294 {
295 	enum ipa_ip_type iptype;
296 	uint32_t src_ipv4_addr;
297 	uint32_t dst_ipv4_addr;
298 	uint32_t src_ipv6_addr[4];
299 	uint32_t dst_ipv6_addr[4];
300 } ipacm_event_connection;
301 
302 typedef struct _ipacm_event_data_fid
303 {
304 	int if_index;
305 } ipacm_event_data_fid;
306 
307 typedef struct
308 {
309 	ipacm_iface_type if_cat;
310 } ipacm_event_data_if_cat;
311 
312 typedef struct _ipacm_event_data_iptype
313 {
314 	int if_index;
315 	int if_index_tether;
316 	enum ipa_ip_type iptype;
317 #ifdef IPA_WAN_MSG_IPv6_ADDR_GW_LEN
318 	uint32_t  ipv4_addr_gw;
319 	uint32_t  ipv6_addr_gw[4];
320 #endif
321 } ipacm_event_data_iptype;
322 
323 
324 typedef struct _ipacm_event_data_addr
325 {
326 	enum ipa_ip_type iptype;
327 	char iface_name[IPA_IFACE_NAME_LEN];
328 	int if_index;
329 	uint32_t  ipv4_addr_gw;
330 	uint32_t  ipv4_addr;
331 	uint32_t  ipv4_addr_mask;
332 	uint32_t  ipv6_addr[4];
333 	uint32_t  ipv6_addr_mask[4];
334 	uint32_t  ipv6_addr_gw[4];
335 } ipacm_event_data_addr;
336 
337 typedef struct _ipacm_event_data_mac
338 {
339 	int if_index;
340 	int ipa_if_cate;
341 	uint8_t mac_addr[IPA_MAC_ADDR_SIZE];
342 } ipacm_event_data_mac;
343 
344 typedef struct _ipacm_event_data_mac_ep
345 {
346 	int if_index;
347 	enum ipa_client_type client;
348 	uint8_t mac_addr[IPA_MAC_ADDR_SIZE];
349 } ipacm_event_data_mac_ep;
350 
351 typedef struct _ipacm_event_data_fst
352 {
353 	int if_index;
354 	bool to_wigig;
355 	uint8_t mac_addr[IPA_MAC_ADDR_SIZE];
356 } ipacm_event_data_fst;
357 
358 typedef struct
359 {
360 	int if_index;
361 	uint8_t num_of_attribs;
362 	struct ipa_wlan_hdr_attrib_val attribs[0];
363 } ipacm_event_data_wlan_ex;
364 
365 typedef enum
366 {
367 	Q6_WAN = 0,
368 	WLAN_WAN,
369 	ECM_WAN,
370 	Q6_MHI_WAN
371 } ipacm_wan_iface_type;
372 
373 typedef struct _ipacm_event_iface_up
374 {
375 	ipacm_wan_iface_type backhaul_type;
376 	char ifname[IPA_IFACE_NAME_LEN];
377 	uint32_t ipv4_addr;
378 	uint32_t addr_mask;
379 	uint32_t ipv6_prefix[2];
380 	uint8_t xlat_mux_id;
381 	uint8_t mux_id;
382 }ipacm_event_iface_up;
383 
384 typedef struct _ipacm_event_iface_up_tether
385 {
386 	ipacm_wan_iface_type backhaul_type;
387 	uint32_t if_index_tether;
388 	uint32_t ipv6_prefix[2];
389 	bool is_sta;
390 	uint8_t xlat_mux_id;
391 }ipacm_event_iface_up_tehter;
392 
393 
394 typedef struct _ipacm_ifacemgr_data
395 {
396 	int if_index;
397 	ipacm_wan_iface_type if_type;
398 	uint8_t mac_addr[IPA_MAC_ADDR_SIZE];
399 }ipacm_ifacemgr_data;
400 
401 typedef struct _ipacm_offload_prefix {
402 	enum ipa_ip_type iptype;
403 	uint32_t v4Addr;
404 	uint32_t v4Mask;
405 	uint32_t v6Addr[4];
406 	uint32_t v6Mask[4];
407 } ipacm_offload_prefix;
408 
409 typedef struct {
410 	int if_index;
411 	_ipacm_offload_prefix prefix;
412 } ipacm_event_ipahal_stream;
413 
414 #ifdef IPA_MTU_EVENT_MAX
415 typedef struct _ipacm_event_mtu_info
416 {
417 	int if_index;
418 	ipa_mtu_info mtu_info;
419 } ipacm_event_mtu_info;
420 #endif
421 #endif /* IPA_CM_DEFS_H */
422