1 /* 2 Copyright (c) 2013, 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_Xml.h 32 33 @brief 34 This file implements the XML specific parsing functionality. 35 36 @Author 37 Skylar Chang/Shihuan Liu 38 39 */ 40 #ifndef IPACM_XML_H 41 #define IPACM_XML_H 42 43 #include <linux/msm_ipa.h> 44 #include "IPACM_Defs.h" 45 #include <stdio.h> 46 #include <stdlib.h> 47 #include <string.h> 48 #ifndef in_addr_t 49 typedef uint32_t in_addr_t; 50 #endif 51 #include <arpa/inet.h> 52 #include <stdint.h> 53 #include <libxml/parser.h> 54 #include <libxml/tree.h> 55 #ifdef __cplusplus 56 extern "C" { 57 #endif 58 59 60 #define IPACM_ASSERT(a) \ 61 if (!(a)) { \ 62 fprintf(stderr, "%s, %d: assertion (a) failed!", \ 63 __FILE__, \ 64 __LINE__); \ 65 abort(); \ 66 } 67 68 /* Max allowed size of the XML file (2 MB) */ 69 #define IPACM_XML_MAX_FILESIZE (2 << 20) 70 #define IPACM_MAX_FIREWALL_ENTRIES 50 71 #define IPACM_IPV6_ADDR_LEN 16 72 73 /* Defines for clipping space or space & quotes (single, double) */ 74 #define IPACM_XML_CLIP_SPACE " " 75 #define IPACM_XML_CLIP_SPACE_QUOTES " '\"" 76 77 #define MAX_XML_STR_LEN 120 78 79 /* IPA Config Entries */ 80 #define system_TAG "system" 81 #define ODU_TAG "ODUCFG" 82 #define ODUMODE_TAG "OduMode" 83 #define ODUEMBMS_OFFLOAD_TAG "eMBMS_offload" 84 #define ODU_ROUTER_TAG "router" 85 #define ODU_BRIDGE_TAG "bridge" 86 #define IPACMCFG_TAG "IPACM" 87 #define IPACMIFACECFG_TAG "IPACMIface" 88 #define IFACE_TAG "Iface" 89 #define NAME_TAG "Name" 90 #define CATEGORY_TAG "Category" 91 #define MODE_TAG "Mode" 92 #define IPACMPRIVATESUBNETCFG_TAG "IPACMPrivateSubnet" 93 #define SUBNET_TAG "Subnet" 94 #define SUBNETADDRESS_TAG "SubnetAddress" 95 #define SUBNETMASK_TAG "SubnetMask" 96 #define WANIF_TAG "WAN" 97 #define LANIF_TAG "LAN" 98 #define WLANIF_TAG "WLAN" 99 #define WLAN_FULL_MODE_TAG "full" 100 #define WLAN_INTERNET_MODE_TAG "internet" 101 #define WLAN_MODE_TAG "WlanMode" 102 #define VIRTUALIF_TAG "VIRTUAL" 103 #define UNKNOWNIF_TAG "UNKNOWN" 104 #define ODUIF_TAG "ODU" 105 #define EMBMSIF_TAG "EMBMS" 106 #define ETHIF_TAG "ETH" 107 #define IFACE_ROUTER_MODE_TAG "ROUTER" 108 #define IFACE_BRIDGE_MODE_TAG "BRIDGE" 109 #define IPACMALG_TAG "IPACMALG" 110 #define ALG_TAG "ALG" 111 #define Protocol_TAG "Protocol" 112 #define Port_TAG "Port" 113 #define TCP_PROTOCOL_TAG "TCP" 114 #define UDP_PROTOCOL_TAG "UDP" 115 116 /* FIREWALL Config Entries */ 117 #define Firewall_TAG "Firewall" 118 #define MobileAPFirewallCfg_TAG "MobileAPFirewallCfg" 119 #define FirewallEnabled_TAG "FirewallEnabled" 120 #define FirewallPktsAllowed_TAG "FirewallPktsAllowed" 121 122 #define IPFamily_TAG "IPFamily" 123 #define IPV4SourceAddress_TAG "IPV4SourceAddress" 124 #define IPV4SourceIPAddress_TAG "IPV4SourceIPAddress" 125 #define IPV4SourceSubnetMask_TAG "IPV4SourceSubnetMask" 126 127 #define IPV4DestinationAddress_TAG "IPV4DestinationAddress" 128 #define IPV4DestinationIPAddress_TAG "IPV4DestinationIPAddress" 129 #define IPV4DestinationSubnetMask_TAG "IPV4DestinationSubnetMask" 130 131 #define IPV4TypeOfService_TAG "IPV4TypeOfService" 132 #define TOSValue_TAG "TOSValue" 133 #define TOSMask_TAG "TOSMask" 134 135 #define IPV4NextHeaderProtocol_TAG "IPV4NextHeaderProtocol" 136 137 #define IPV6SourceAddress_TAG "IPV6SourceAddress" 138 #define IPV6SourceIPAddress_TAG "IPV6SourceIPAddress" 139 #define IPV6SourcePrefix_TAG "IPV6SourcePrefix" 140 141 #define IPV6DestinationAddress_TAG "IPV6DestinationAddress" 142 #define IPV6DestinationIPAddress_TAG "IPV6DestinationIPAddress" 143 #define IPV6DestinationPrefix_TAG "IPV6DestinationPrefix" 144 145 #define IPV6TrafficClass_TAG "IPV6TrafficClass" 146 #define TrfClsValue_TAG "TrfClsValue" 147 #define TrfClsMask_TAG "TrfClsMask" 148 149 #define IPV6NextHeaderProtocol_TAG "IPV6NextHeaderProtocol" 150 151 #define TCPSource_TAG "TCPSource" 152 #define TCPSourcePort_TAG "TCPSourcePort" 153 #define TCPSourceRange_TAG "TCPSourceRange" 154 155 #define TCPDestination_TAG "TCPDestination" 156 #define TCPDestinationPort_TAG "TCPDestinationPort" 157 #define TCPDestinationRange_TAG "TCPDestinationRange" 158 159 #define UDPSource_TAG "UDPSource" 160 #define UDPSourcePort_TAG "UDPSourcePort" 161 #define UDPSourceRange_TAG "UDPSourceRange" 162 163 #define UDPDestination_TAG "UDPDestination" 164 #define UDPDestinationPort_TAG "UDPDestinationPort" 165 #define UDPDestinationRange_TAG "UDPDestinationRange" 166 167 #define ICMPType_TAG "ICMPType" 168 #define ICMPCode_TAG "ICMPCode" 169 170 #define ESP_TAG "ESP" 171 #define ESPSPI_TAG "ESPSPI" 172 173 #define TCP_UDPSource_TAG "TCP_UDPSource" 174 #define TCP_UDPSourcePort_TAG "TCP_UDPSourcePort" 175 #define TCP_UDPSourceRange_TAG "TCP_UDPSourceRange" 176 177 #define TCP_UDPDestination_TAG "TCP_UDPDestination" 178 #define TCP_UDPDestinationPort_TAG "TCP_UDPDestinationPort" 179 #define TCP_UDPDestinationRange_TAG "TCP_UDPDestinationRange" 180 181 #define IPACMNat_TAG "IPACMNAT" 182 #define NAT_MaxEntries_TAG "MaxNatEntries" 183 184 #define IP_PassthroughFlag_TAG "IPPassthroughFlag" 185 #define IP_PassthroughMode_TAG "IPPassthroughMode" 186 187 /*--------------------------------------------------------------------------- 188 IP protocol numbers - use in dss_socket() to identify protocols. 189 Also contains the extension header types for IPv6. 190 ---------------------------------------------------------------------------*/ 191 typedef enum 192 { 193 IPACM_FIREWALL_IPV6_BASE_HDR = 4, /* IPv6 Base Header */ 194 IPACM_FIREWALL_IPPROTO_HOP_BY_HOP_OPT_HDR = 0, /* Hop-by-hop Option Header */ 195 IPACM_FIREWALL_IPPROTO_ICMP = 1, /* ICMP protocol */ 196 IPACM_FIREWALL_IPPROTO_IGMP = 2, /* IGMP protocol */ 197 IPACM_FIREWALL_IPPROTO_IP = IPACM_FIREWALL_IPV6_BASE_HDR, /* IPv4 */ 198 IPACM_FIREWALL_IPPROTO_TCP = 6, /* TCP Protocol */ 199 IPACM_FIREWALL_IPPROTO_UDP = 17, /* UDP Protocol */ 200 IPACM_FIREWALL_IPPROTO_IPV6 = 41, /* IPv6 */ 201 IPACM_FIREWALL_IPPROTO_ROUTING_HDR = 43, /* Routing Header */ 202 IPACM_FIREWALL_IPPROTO_FRAG_HDR = 44, /* Fragmentation Header */ 203 IPACM_FIREWALL_IPPROTO_GRE = 47, /* GRE Protocol */ 204 IPACM_FIREWALL_IPPROTO_ESP = 50, /* ESP Protocol */ 205 IPACM_FIREWALL_IPPROTO_AH = 51, /* Authentication Header */ 206 IPACM_FIREWALL_IPPROTO_ICMP6 = 58, /* ICMPv6 */ 207 IPACM_FIREWALL_NO_NEXT_HDR = 59, /* No Next Header for IPv6 */ 208 IPACM_FIREWALL_IPPROTO_DEST_OPT_HDR = 60, /* Destination Options Header */ 209 IPACM_FIREWALL_IPPROTO_MOBILITY_HDR = 135, /* Mobility Header */ 210 IPACM_FIREWALL_IPPROTO_TCP_UDP = 253 /* Unspecified protocol used for IPACM */ 211 } ipacm_firewall_ip_protocol_enum_type; 212 213 /* define as mobileap firewall rule format*/ 214 typedef enum 215 { 216 IP_V4 = 4, 217 IP_V6 = 6 218 } firewall_ip_version_enum; 219 220 /*--------------------------------------------------------------------------- 221 Extended FireWall Entry Configuration. 222 ---------------------------------------------------------------------------*/ 223 typedef struct 224 { 225 struct ipa_rule_attrib attrib; 226 firewall_ip_version_enum ip_vsn; 227 } IPACM_extd_firewall_entry_conf_t; 228 229 230 /*--------------------------------------------------------------------------- 231 Extended FireWall configuration. 232 ---------------------------------------------------------------------------*/ 233 typedef union 234 { 235 IPACM_extd_firewall_entry_conf_t extd_firewall_entry; 236 } IPACM_extd_firewall_conf_t; 237 238 239 typedef struct 240 { 241 char firewall_config_file[IPA_MAX_FILE_LEN]; 242 uint8_t num_extd_firewall_entries; 243 IPACM_extd_firewall_entry_conf_t extd_firewall_entries[IPACM_MAX_FIREWALL_ENTRIES]; 244 bool rule_action_accept; 245 bool firewall_enable; 246 } IPACM_firewall_conf_t; 247 248 249 250 typedef struct 251 { 252 uint8_t num_iface_entries; 253 ipa_ifi_dev_name_t iface_entries[IPA_MAX_IFACE_ENTRIES]; 254 } ipacm_iface_conf_t; 255 256 typedef struct 257 { 258 uint8_t num_subnet_entries; 259 ipa_private_subnet private_subnet_entries[IPA_MAX_PRIVATE_SUBNET_ENTRIES]; 260 } ipacm_private_subnet_conf_t; 261 262 typedef struct 263 { 264 uint8_t protocol; 265 uint16_t port; 266 } ipacm_alg; 267 268 typedef struct 269 { 270 uint8_t num_alg_entries; 271 ipacm_alg alg_entries[IPA_MAX_ALG_ENTRIES]; 272 } ipacm_alg_conf_t; 273 274 275 typedef struct _IPACM_conf_t 276 { 277 ipacm_iface_conf_t iface_config; 278 ipacm_private_subnet_conf_t private_subnet_config; 279 ipacm_alg_conf_t alg_config; 280 int nat_max_entries; 281 bool odu_enable; 282 bool router_mode_enable; 283 bool odu_embms_enable; 284 int num_wlan_guest_ap; 285 bool ip_passthrough_mode; 286 } IPACM_conf_t; 287 288 /* This function read IPACM XML configuration*/ 289 int ipacm_read_cfg_xml 290 ( 291 char *xml_file, /* Filename and path */ 292 IPACM_conf_t *config /* Mobile AP config data */ 293 ); 294 295 /* This function reads QCMAP Firewall XML and store in IPACM Firewall stucture */ 296 int IPACM_read_firewall_xml 297 ( 298 char *xml_file, /* Filename and path */ 299 IPACM_firewall_conf_t *config /* Mobile AP config data */ 300 ); 301 302 #ifdef __cplusplus 303 } 304 #endif 305 306 #endif //IPACM_XML 307