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 /*--------------------------------------------------------------------------- 109 Return values indicating error status 110 ---------------------------------------------------------------------------*/ 111 112 #define IPACM_SUCCESS 0 /* Successful operation */ 113 #define IPACM_FAILURE -1 /* Unsuccessful operation */ 114 115 #define IPACM_IP_NULL (ipa_ip_type)0xFF 116 #define IPACM_INVALID_INDEX (ipa_ip_type)0xFF 117 118 #define IPA_MAX_NUM_WIFI_CLIENTS 32 119 #define IPA_MAX_NUM_WAN_CLIENTS 10 120 #define IPA_MAX_NUM_ETH_CLIENTS 15 121 #define IPA_MAX_NUM_AMPDU_RULE 15 122 #define IPA_MAC_ADDR_SIZE 6 123 #define IPA_MAX_NUM_SW_PDNS 15 124 125 #define DEFAULT_MTU_SIZE 1500 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 IPA_COALESCE_NOTICE, /* NULL*/ 191 #ifdef FEATURE_L2TP 192 IPA_ADD_VLAN_IFACE, /* ipa_ioc_vlan_iface_info */ 193 IPA_DEL_VLAN_IFACE, /* ipa_ioc_vlan_iface_info */ 194 IPA_ADD_L2TP_VLAN_MAPPING, /* ipa_ioc_l2tp_vlan_mapping_info */ 195 IPA_DEL_L2TP_VLAN_MAPPING, /* ipa_ioc_l2tp_vlan_mapping_info */ 196 IPA_HANDLE_VLAN_CLIENT_INFO, /* ipacm_event_data_all */ 197 IPA_HANDLE_VLAN_IFACE_INFO, /* ipacm_event_data_all */ 198 #endif 199 IPA_WLAN_FWR_SSR_BEFORE_SHUTDOWN_NOTICE, 200 IPA_LAN_DELETE_SELF, /* ipacm_event_data_fid */ 201 IPA_WIGIG_CLIENT_ADD_EVENT, /* ipacm_event_data_mac_ep */ 202 IPA_WIGIG_FST_SWITCH, /* ipacm_event_data_fst */ 203 IPACM_EVENT_MAX 204 } ipa_cm_event_id; 205 206 typedef struct 207 { 208 uint8_t num_rule; 209 uint32_t rule_hdl[MAX_NUM_PROP]; 210 } lan_to_lan_rt_rule_hdl; 211 212 typedef enum 213 { 214 LAN_IF = 0, 215 WLAN_IF, 216 WAN_IF, 217 VIRTUAL_IF, 218 ETH_IF, 219 EMBMS_IF, 220 ODU_IF, 221 UNKNOWN_IF 222 } ipacm_iface_type; 223 224 typedef enum 225 { 226 ROUTER = 0, 227 BRIDGE 228 } ipacm_cradle_iface_mode; 229 230 typedef enum 231 { 232 FULL, 233 INTERNET 234 } ipacm_wlan_access_mode; 235 236 typedef struct 237 { 238 struct nf_conntrack *ct; 239 enum nf_conntrack_msg_type type; 240 }ipacm_ct_evt_data; 241 242 typedef struct 243 { 244 char iface_name[IPA_IFACE_NAME_LEN]; 245 ipacm_iface_type if_cat; 246 ipacm_cradle_iface_mode if_mode; 247 ipacm_wlan_access_mode wlan_mode; 248 int netlink_interface_index; 249 } ipa_ifi_dev_name_t; 250 251 typedef struct 252 { 253 uint32_t subnet_addr; 254 uint32_t subnet_mask; 255 } ipa_private_subnet; 256 257 258 typedef struct _ipacm_event_data_all 259 { 260 enum ipa_ip_type iptype; 261 int if_index; 262 uint32_t ipv4_addr; 263 uint32_t ipv6_addr[4]; 264 uint8_t mac_addr[IPA_MAC_ADDR_SIZE]; 265 char iface_name[IPA_IFACE_NAME_LEN]; 266 } ipacm_event_data_all; 267 268 class IPACM_Lan; 269 270 typedef struct 271 { 272 ipacm_cradle_iface_mode cradle_wan_mode; 273 } ipacm_event_cradle_wan_mode; 274 275 typedef struct 276 { 277 IPACM_Lan *p_iface; 278 ipa_ip_type iptype; 279 uint8_t mac_addr[6]; 280 char iface_name[IPA_IFACE_NAME_LEN]; 281 int ep; 282 } ipacm_event_eth_bridge; 283 284 typedef struct 285 { 286 enum ipa_ip_type iptype; 287 uint32_t src_ipv4_addr; 288 uint32_t dst_ipv4_addr; 289 uint32_t src_ipv6_addr[4]; 290 uint32_t dst_ipv6_addr[4]; 291 } ipacm_event_connection; 292 293 typedef struct _ipacm_event_data_fid 294 { 295 int if_index; 296 } ipacm_event_data_fid; 297 298 typedef struct 299 { 300 ipacm_iface_type if_cat; 301 } ipacm_event_data_if_cat; 302 303 typedef struct _ipacm_event_data_iptype 304 { 305 int if_index; 306 int if_index_tether; 307 enum ipa_ip_type iptype; 308 #ifdef IPA_WAN_MSG_IPv6_ADDR_GW_LEN 309 uint32_t ipv4_addr_gw; 310 uint32_t ipv6_addr_gw[4]; 311 #endif 312 } ipacm_event_data_iptype; 313 314 315 typedef struct _ipacm_event_data_addr 316 { 317 enum ipa_ip_type iptype; 318 char iface_name[IPA_IFACE_NAME_LEN]; 319 int if_index; 320 uint32_t ipv4_addr_gw; 321 uint32_t ipv4_addr; 322 uint32_t ipv4_addr_mask; 323 uint32_t ipv6_addr[4]; 324 uint32_t ipv6_addr_mask[4]; 325 uint32_t ipv6_addr_gw[4]; 326 } ipacm_event_data_addr; 327 328 typedef struct _ipacm_event_data_mac 329 { 330 int if_index; 331 int ipa_if_cate; 332 uint8_t mac_addr[IPA_MAC_ADDR_SIZE]; 333 } ipacm_event_data_mac; 334 335 typedef struct _ipacm_event_data_mac_ep 336 { 337 int if_index; 338 enum ipa_client_type client; 339 uint8_t mac_addr[IPA_MAC_ADDR_SIZE]; 340 } ipacm_event_data_mac_ep; 341 342 typedef struct _ipacm_event_data_fst 343 { 344 int if_index; 345 bool to_wigig; 346 uint8_t mac_addr[IPA_MAC_ADDR_SIZE]; 347 } ipacm_event_data_fst; 348 349 typedef struct 350 { 351 int if_index; 352 uint8_t num_of_attribs; 353 struct ipa_wlan_hdr_attrib_val attribs[0]; 354 } ipacm_event_data_wlan_ex; 355 356 typedef enum 357 { 358 Q6_WAN = 0, 359 WLAN_WAN, 360 ECM_WAN, 361 Q6_MHI_WAN 362 } ipacm_wan_iface_type; 363 364 typedef struct _ipacm_event_iface_up 365 { 366 ipacm_wan_iface_type backhaul_type; 367 char ifname[IPA_IFACE_NAME_LEN]; 368 uint32_t ipv4_addr; 369 uint32_t addr_mask; 370 uint32_t ipv6_prefix[2]; 371 uint8_t xlat_mux_id; 372 uint8_t mux_id; 373 }ipacm_event_iface_up; 374 375 typedef struct _ipacm_event_iface_up_tether 376 { 377 ipacm_wan_iface_type backhaul_type; 378 uint32_t if_index_tether; 379 uint32_t ipv6_prefix[2]; 380 bool is_sta; 381 uint8_t xlat_mux_id; 382 }ipacm_event_iface_up_tehter; 383 384 385 typedef struct _ipacm_ifacemgr_data 386 { 387 int if_index; 388 ipacm_wan_iface_type if_type; 389 uint8_t mac_addr[IPA_MAC_ADDR_SIZE]; 390 }ipacm_ifacemgr_data; 391 392 typedef struct _ipacm_offload_prefix { 393 enum ipa_ip_type iptype; 394 uint32_t v4Addr; 395 uint32_t v4Mask; 396 uint32_t v6Addr[4]; 397 uint32_t v6Mask[4]; 398 } ipacm_offload_prefix; 399 400 typedef struct { 401 int if_index; 402 _ipacm_offload_prefix prefix; 403 } ipacm_event_ipahal_stream; 404 405 #endif /* IPA_CM_DEFS_H */ 406