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