M7350v1_en_gpl

This commit is contained in:
T
2024-09-09 08:52:07 +00:00
commit f9cc65cfda
65988 changed files with 26357421 additions and 0 deletions
+108
View File
@@ -0,0 +1,108 @@
/*
Copyright (c) 2013, The Linux Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of The Linux Foundation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*!
@file
IPACM_CmdQueue.h
@brief
This file implements the IPAM Comment Queue definitions
@Author
*/
#ifndef IPA_CONNTRACK_MESSAGE_H
#define IPA_CONNTRACK_MESSAGE_H
#include <iostream>
#include <pthread.h>
#include "IPACM_Defs.h"
/*---------------------------------------------------------------------------
Event data required by IPA_CM
---------------------------------------------------------------------------*/
typedef struct _ipacm_cmd_q_data {
ipa_cm_event_id event;
void *evt_data;
}ipacm_cmd_q_data;
typedef struct cmd_s
{
void (*callback_ptr)(ipacm_cmd_q_data *);
ipacm_cmd_q_data data;
}cmd_t;
class Message
{
private:
Message *m_next;
public:
cmd_t evt;
Message()
{
m_next = NULL;
evt.callback_ptr = NULL;
}
~Message() { }
void setnext(Message *item) { m_next = item; }
Message* getnext() { return m_next; }
};
class MessageQueue
{
private:
Message *Head;
Message *Tail;
Message* dequeue(void);
static MessageQueue *inst;
MessageQueue()
{
Head = NULL;
Tail = NULL;
}
public:
~MessageQueue() { }
void enqueue(Message *item);
static void* Process(void *);
static MessageQueue* getInstance();
};
#endif /* IPA_CONNTRACK_MESSAGE_H */
+144
View File
@@ -0,0 +1,144 @@
/*
Copyright (c) 2013, The Linux Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of The Linux Foundation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*!
@file
IPACM_Config.h
@brief
This file implements the IPACM Configuration from XML file
@Author
Skylar Chang
*/
#ifndef IPACM_CONFIG_H
#define IPACM_CONFIG_H
#include "IPACM_Defs.h"
#include "IPACM_Xml.h"
typedef struct
{
char iface_name[IPA_IFACE_NAME_LEN];
}NatIfaces;
/* for IPACM rm dependency use*/
typedef struct _ipa_rm_client
{
ipa_rm_resource_name producer_rm1;
ipa_rm_resource_name consumer_rm1;
ipa_rm_resource_name producer_rm2;
ipa_rm_resource_name consumer_rm2;
bool producer1_up; /* only monitor producer_rm1, not monitor producer_rm2 */
bool consumer1_up; /* only monitor consumer_rm1, not monitor consumer_rm2 */
bool rm_set; /* once producer1_up and consumer1_up, will add bi-directional dependency */
bool rx_bypass_ipa; /* support WLAN may not register RX-property, should not add dependency */
}ipa_rm_client;
/* iface */
class IPACM_Config
{
public:
/* IPACM ipa_client map to rm_resource*/
ipa_rm_resource_name ipa_client_rm_map_tbl[IPA_CLIENT_MAX];
/* IPACM monitored rm_depency table */
ipa_rm_client ipa_rm_tbl[IPA_MAX_RM_ENTRY];
/* IPACM rm_depency a2 endpoint check*/
int ipa_rm_a2_check;
/* Store interested interface and their configuration from XML file */
ipa_ifi_dev_name_t *iface_table;
/* Store interested ALG port from XML file */
ipacm_alg *alg_table;
/* Store private subnet configuration from XML file */
ipa_private_subnet private_subnet_table[IPA_MAX_PRIVATE_SUBNET_ENTRIES];
/* Store the non nat iface names */
NatIfaces *pNatIfaces;
/* Store the number of interface IPACM read from XML file */
int ipa_num_ipa_interfaces;
int ipa_num_private_subnet;
int ipa_num_alg_ports;
int ipa_nat_max_entries;
int ipa_nat_iface_entries;
/* IPACM routing table name for v4/v6 */
struct ipa_ioc_get_rt_tbl rt_tbl_lan_v4, rt_tbl_wan_v4, rt_tbl_default_v4, rt_tbl_v6, rt_tbl_wan_v6;
/* To return the instance */
static IPACM_Config* GetInstance();
inline int GetAlgPortCnt()
{
return ipa_num_alg_ports;
}
int GetAlgPorts(int nPorts, ipacm_alg *pAlgPorts);
inline int GetNatMaxEntries(void)
{
return ipa_nat_max_entries;
}
inline int GetNatIfacesCnt()
{
return ipa_nat_iface_entries;
}
int GetNatIfaces(int nPorts, NatIfaces *ifaces);
/* for IPACM resource manager dependency usage */
void AddRmDepend(ipa_rm_resource_name rm1,bool rx_bypass_ipa);
void DelRmDepend(ipa_rm_resource_name rm1);
int AddNatIfaces(char *dev_name);
int DelNatIfaces(char *dev_name);
private:
static IPACM_Config *pInstance;
static const char *DEVICE_NAME;
IPACM_Config(void);
int Init(void);
int m_fd; /* File descriptor of the IPA device node /dev/ipa */
};
#endif /* IPACM_CONFIG */
@@ -0,0 +1,113 @@
/*
Copyright (c) 2013, The Linux Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of The Linux Foundation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef IPACM_CONNTRACK_FILTER_H
#define IPACM_CONNTRACK_FILTER_H
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <errno.h>
#include "IPACM_ConntrackClient.h"
#include "IPACM_CmdQueue.h"
#include "IPACM_Conntrack_NATApp.h"
#include "IPACM_EvtDispatcher.h"
#include "IPACM_Defs.h"
#ifndef IPACM_DEBUG
#define IPACM_DEBUG
#endif
extern "C"
{
#include <libnetfilter_conntrack/libnetfilter_conntrack.h>
#include <libnetfilter_conntrack/libnetfilter_conntrack_tcp.h>
#include <sys/inotify.h>
}
using namespace std;
#define UDP_TIMEOUT_UPDATE 20
#define BROADCAST_IPV4_ADDR 0xFFFFFFFF
#define IPACM_DIR_NAME "/proc/sys/net/ipv4/netfilter"
#define IPACM_TCP_FILE_NAME "ip_conntrack_tcp_timeout_established"
#define IPACM_UDP_FILE_NAME "ip_conntrack_udp_timeout_stream"
#define IPACM_TCP_FULL_FILE_NAME "/proc/sys/net/ipv4/netfilter/ip_conntrack_tcp_timeout_established"
#define IPACM_UDP_FULL_FILE_NAME "/proc/sys/net/ipv4/netfilter/ip_conntrack_udp_timeout_stream"
#define INOTIFY_EVENT_SIZE (sizeof(struct inotify_event))
#define INOTIFY_BUF_LEN (INOTIFY_EVENT_SIZE + 2*sizeof(IPACM_TCP_FILE_NAME))
class IPACM_ConntrackClient
{
private:
static IPACM_ConntrackClient *pInstance;
struct nfct_handle *tcp_hdl;
struct nfct_handle *udp_hdl;
struct nfct_filter *tcp_filter;
struct nfct_filter *udp_filter;
static int IPA_Conntrack_Filters_Ignore_Local_Addrs(struct nfct_filter *filter);
static int IPA_Conntrack_Filters_Ignore_Bridge_Addrs(struct nfct_filter *filter);
IPACM_ConntrackClient();
public:
static int IPAConntrackEventCB(enum nf_conntrack_msg_type type,
struct nf_conntrack *ct,
void *data);
static int IPA_Conntrack_UDP_Filter_Init(void);
static int IPA_Conntrack_TCP_Filter_Init(void);
static void* TCPRegisterWithConnTrack(void *);
static void* UDPRegisterWithConnTrack(void *);
static void* UDPConnTimeoutUpdate(void *);
static void* TCPUDP_Timeout_monitor(void *);
static void UpdateUDPFilters(void *);
static void UpdateTCPFilters(void *);
static void Read_TcpUdp_Timeout(char *in, int len);
static IPACM_ConntrackClient* GetInstance();
#ifdef IPACM_DEBUG
static void iptodot(const char *type, uint32_t ipAddr);
#endif
};
#endif /* IPACM_CONNTRACK_FILTER_H */
@@ -0,0 +1,78 @@
/*
Copyright (c) 2013, The Linux Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of The Linux Foundation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef IPACM_CONNTRACK_LISTENER
#define IPACM_CONNTRACK_LISTENER
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <errno.h>
#include "IPACM_CmdQueue.h"
#include "IPACM_Conntrack_NATApp.h"
#include "IPACM_Listener.h"
#define MAX_NAT_IFACES 50
using namespace std;
class IPACM_ConntrackListener : public IPACM_Listener
{
private:
bool isCTReg;
bool isWanUp;
int NatIfaceCnt;
NatIfaces *pNatIfaces;
uint32_t nat_iface_ipv4_addr[MAX_NAT_IFACES];
IPACM_Config *pConfig;
void ProcessCTMessage(void *data);
void ProcessTCPorUDPMsg(struct nf_conntrack *ct, enum nf_conntrack_msg_type, u_int8_t);
void TriggerWANUp(void *);
void TriggerWANDown(uint32_t wan_addr);
int CreateNatThreads(void);
void HandleNeighIpAddrEvt(void *data, bool);
public:
char wan_ifname[IPA_IFACE_NAME_LEN];
uint32_t wan_ipaddr;
IPACM_ConntrackListener();
void event_callback(ipa_cm_event_id, void *data);
};
#endif /* IPACM_CONNTRACK_LISTENER */
@@ -0,0 +1,118 @@
/*
Copyright (c) 2013, The Linux Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of The Linux Foundation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef IPACM_CONNTRACK_NATAPP_H
#define IPACM_CONNTRACK_NATAPP_H
#include <string.h> /* for stderror */
#include <stdlib.h>
#include <cstdio> /* for perror */
#include "IPACM_Config.h"
#include "IPACM_Xml.h"
extern "C"
{
#include <libnetfilter_conntrack/libnetfilter_conntrack.h>
#include <ipa_nat_drv.h>
}
typedef struct _nat_table_entry
{
uint32_t private_ip;
uint16_t private_port;
uint32_t target_ip;
uint16_t target_port;
uint16_t public_port;
u_int8_t protocol;
uint32_t timestamp;
bool dst_nat;
bool enabled;
uint32_t rule_hdl;
}nat_table_entry;
#define CHK_TBL_HDL() if(nat_table_hdl == 0){ return -1; }
class NatApp
{
private:
static NatApp *pInstance;
nat_table_entry *cache;
uint32_t pub_ip_addr;
uint32_t nat_table_hdl;
int curCnt, max_entries;
ipacm_alg *pALGPorts;
uint16_t nALGPort;
uint32_t tcp_timeout;
uint32_t udp_timeout;
uint32_t PwrSaveIfs[IPA_MAX_NUM_WIFI_CLIENTS];
struct nf_conntrack *ct;
struct nfct_handle *ct_hdl;
NatApp();
int Init();
void UpdateCTUdpTs(nat_table_entry *, uint32_t);
bool ChkForDup(const nat_table_entry *);
bool isAlgPort(uint8_t, uint16_t);
void Reset();
bool isPwrSaveIf(uint32_t);
public:
static NatApp* GetInstance();
int AddTable(uint32_t);
uint32_t GetTableHdl(uint32_t);
int DeleteTable(uint32_t);
int AddEntry(const nat_table_entry *);
int DeleteEntry(const nat_table_entry *);
void UpdateUDPTimeStamp();
int UpdatePwrSaveIf(uint32_t);
int ResetPwrSaveIf(uint32_t);
void UpdateTcpUdpTo(uint32_t, int proto);
};
#endif /* IPACM_CONNTRACK_NATAPP_H */
+187
View File
@@ -0,0 +1,187 @@
/*
Copyright (c) 2013, The Linux Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of The Linux Foundation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*!
@file
IPACM_Defs.h
@brief
This file implements the common definitions amon all ifaces.
@Author
Skylar Chang
*/
#ifndef IPA_CM_DEFS_H
#define IPA_CM_DEFS_H
#include <linux/msm_ipa.h>
#include "IPACM_Log.h"
extern "C"
{
#include <libnetfilter_conntrack/libnetfilter_conntrack.h>
#include <libnetfilter_conntrack/libnetfilter_conntrack_tcp.h>
}
#define IPA_MAX_FILE_LEN 64
#define IPA_IFACE_NAME_LEN 16
#define IPA_ALG_PROTOCOL_NAME_LEN 10
#define IPA_WLAN_PARTIAL_HDR_OFFSET 12 // dst mac first then src mac
#define IPA_VIRTUAL_IFACE_NAME "bridge0"
#define IPA_WLAN_PARTIAL_HDR_NAME_v4 "IEEE802_3_v4"
#define IPA_WLAN_PARTIAL_HDR_NAME_v6 "IEEE802_3_v6"
#define IPA_WAN_PARTIAL_HDR_NAME_v4 "IEEE802_3_STA_v4"
#define IPA_WAN_PARTIAL_HDR_NAME_v6 "IEEE802_3_STA_v6"
#define IPA_MAX_IFACE_ENTRIES 15
#define IPA_MAX_PRIVATE_SUBNET_ENTRIES 3
#define IPA_MAX_ALG_ENTRIES 10
#define IPA_MAX_RM_ENTRY 6
#define V4_DEFAULT_ROUTE_TABLE_NAME "ipa_dflt_rt"
#define V4_LAN_ROUTE_TABLE_NAME "COMRTBLLANv4"
#define V4_WAN_ROUTE_TABLE_NAME "WANRTBLv4"
#define V6_COMMON_ROUTE_TABLE_NAME "COMRTBLv6"
#define V6_WAN_ROUTE_TABLE_NAME "WANRTBLv6"
/*---------------------------------------------------------------------------
Return values indicating error status
---------------------------------------------------------------------------*/
#define IPACM_SUCCESS 0 /* Successful operation */
#define IPACM_FAILURE -1 /* Unsuccessful operation */
#define IPACM_IP_NULL (ipa_ip_type)0xFF
#define IPACM_INVALID_INDEX (ipa_ip_type)0xFF
#define IPA_MAX_NUM_WIFI_CLIENTS 15
#define IPA_MAX_NUM_AMPDU_RULE 15
#define IPA_MAC_ADDR_SIZE 6
/*===========================================================================
GLOBAL DEFINITIONS AND DECLARATIONS
===========================================================================*/
typedef enum
{
IPA_LINK_UP_EVENT = 1, /* 1 ipacm_event_data_fid */
IPA_LINK_DOWN_EVENT, /* 2 ipacm_event_data_fid */
IPA_ADDR_ADD_EVENT, /* 3 ipacm_event_data_addr */
IPA_ADDR_DEL_EVENT, /* 4 no use */
IPA_ROUTE_ADD_EVENT, /* 5 ipacm_event_data_addr */
IPA_ROUTE_DEL_EVENT, /* 6 ipacm_event_data_addr */
IPA_FIREWALL_CHANGE_EVENT, /* 7 NULL */
IPA_WLAN_AP_LINK_UP_EVENT, /* 8 ipacm_event_data_mac */
IPA_WLAN_STA_LINK_UP_EVENT, /* 9 ipacm_event_data_mac */
IPA_WLAN_CLIENT_ADD_EVENT, /* 10 ipacm_event_data_mac */
IPA_WLAN_CLIENT_DEL_EVENT, /* 11 ipacm_event_data_mac */
IPA_WLAN_CLIENT_POWER_SAVE_EVENT, /* 12 ipacm_event_data_mac */
IPA_WLAN_CLIENT_RECOVER_EVENT, /* 13 ipacm_event_data_mac */
IPA_NEW_NEIGH_EVENT, /* 14 ipacm_event_data_all */
IPA_DEL_NEIGH_EVENT, /* 15 ipacm_event_data_all */
IPA_NEIGH_CLIENT_IP_ADDR_ADD_EVENT, /* 16 ipacm_event_data_all */
IPA_NEIGH_CLIENT_IP_ADDR_DEL_EVENT, /* 17 ipacm_event_data_all */
IPA_SW_ROUTING_ENABLE, /* 18 NULL */
IPA_SW_ROUTING_DISABLE, /* 19 NULL */
IPA_PROCESS_CT_MESSAGE, /* 20 ipacm_ct_evt_data */
IPA_HANDLE_WAN_UP, /* 21 ipacm_event_iface_up */
IPA_HANDLE_WAN_DOWN, /* 22 unsigned long */
IPA_HANDLE_WLAN_UP, /* 23 ipacm_event_iface_up */
IPA_HANDLE_LAN_UP /* 24 ipacm_event_iface_up */
} ipa_cm_event_id;
typedef enum
{
LAN_IF = 0,
WLAN_IF,
WAN_IF,
VIRTUAL_IF,
UNKNOWN_IF
} ipacm_iface_type;
typedef struct
{
struct nf_conntrack *ct;
enum nf_conntrack_msg_type type;
}ipacm_ct_evt_data;
typedef struct
{
char iface_name[IPA_IFACE_NAME_LEN];
ipacm_iface_type if_cat;
int netlink_interface_index;
} ipa_ifi_dev_name_t;
typedef struct
{
uint32_t subnet_addr;
uint32_t subnet_mask;
} ipa_private_subnet;
typedef struct _ipacm_event_data_all
{
enum ipa_ip_type iptype;
int if_index;
uint32_t ipv4_addr;
uint32_t ipv6_addr[4];
uint8_t mac_addr[6];
} ipacm_event_data_all;
typedef struct _ipacm_event_data_fid
{
int if_index;
} ipacm_event_data_fid;
typedef struct _ipacm_event_data_addr
{
enum ipa_ip_type iptype;
int if_index;
uint32_t ipv4_addr;
uint32_t ipv4_addr_mask;
uint32_t ipv6_addr[4];
uint32_t ipv6_addr_mask[4];
} ipacm_event_data_addr;
typedef struct _ipacm_event_data_mac
{
int if_index;
uint8_t mac_addr[6];
} ipacm_event_data_mac;
typedef struct _ipacm_event_iface_up
{
char ifname[IPA_IFACE_NAME_LEN];
uint32_t ipv4_addr;
uint32_t addr_mask;
}ipacm_event_iface_up;
#endif /* IPA_CM_DEFS_H */
@@ -0,0 +1,76 @@
/*
Copyright (c) 2013, The Linux Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of The Linux Foundation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*!
@file
IPACM_EvtDispatcher.h
@brief
This file implements the IPAM event dispatcher definitions
@Author
*/
#ifndef IPACM_EvtDispatcher_H
#define IPACM_EvtDispatcher_H
#include <stdio.h>
#include <IPACM_CmdQueue.h>
#include "IPACM_Defs.h"
#include "IPACM_Listener.h"
/* queue */
typedef struct _cmd_evts
{
ipa_cm_event_id event;
IPACM_Listener *obj;
//int ipa_interface_index;
_cmd_evts *next;
} cmd_evts;
class IPACM_EvtDispatcher
{
public:
/* api for all iface instances to register events */
static int registr(ipa_cm_event_id event, IPACM_Listener *obj);
/* api for all iface instances to de-register events */
static int deregistr(IPACM_Listener *obj);
static int PostEvt(ipacm_cmd_q_data *);
static void ProcessEvt(ipacm_cmd_q_data *);
private:
static cmd_evts *head;
};
#endif /* IPACM_EvtDispatcher_H */
@@ -0,0 +1,69 @@
/*
Copyright (c) 2013, The Linux Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of The Linux Foundation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*!
@file
IPACM_Filtering.h
@brief
This file implements the IPACM filtering definitions
@Author
Skylar Chang
*/
#ifndef IPACM_FILTERING_H
#define IPACM_FILTERING_H
#include <stdint.h>
#include <linux/msm_ipa.h>
#include <IPACM_Defs.h>
class IPACM_Filtering
{
public:
IPACM_Filtering();
~IPACM_Filtering();
bool AddFilteringRule(struct ipa_ioc_add_flt_rule const *ruleTable);
bool DeleteFilteringRule(struct ipa_ioc_del_flt_rule *ruleTable);
bool Commit(enum ipa_ip_type ip);
bool Reset(enum ipa_ip_type ip);
bool DeviceNodeIsOpened();
bool DeleteFilteringHdls(uint32_t *flt_rule_hdls,
ipa_ip_type ip,
uint8_t num_rules);
private:
static const char *DEVICE_NAME;
int fd; /* File descriptor of the IPA device node /dev/ipa */
};
#endif //IPACM_FILTERING_H
+68
View File
@@ -0,0 +1,68 @@
/*
Copyright (c) 2013, The Linux Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of The Linux Foundation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* IPACM_Header.h
*
* Created on: Jun 20, 2012
* Author: tatias
*/
//////////////////////////////////////////////////////////////////////////////////
#ifndef IPACM_HEADER_H
#define IPACM_HEADER_H
#include <stdint.h>
#include "linux/msm_ipa.h"
//////////////////////////////////////////////////////////////////////////////////
class IPACM_Header
{
private:
int m_fd;
public:
bool AddHeader(struct ipa_ioc_add_hdr *pHeaderTable);
bool DeleteHeader(struct ipa_ioc_del_hdr *pHeaderTable);
bool GetHeaderHandle(struct ipa_ioc_get_hdr *pHeaderStruct);
bool CopyHeader(struct ipa_ioc_copy_hdr *pCopyHeaderStruct);
bool Commit();
bool Reset();
bool DeleteHeaderHdl(uint32_t hdr_hdl);
IPACM_Header();
~IPACM_Header();
bool DeviceNodeIsOpened();
};
#endif
+142
View File
@@ -0,0 +1,142 @@
/*
Copyright (c) 2013, The Linux Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of The Linux Foundation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*!
@file
IPACM_iface.h
@brief
This file implements the basis Iface definitions.
@Author
Skylar Chang
*/
#ifndef IPACM_IFACE_H
#define IPACM_IFACE_H
#include <stdio.h>
#include <IPACM_CmdQueue.h>
#include <linux/msm_ipa.h>
#include "IPACM_Routing.h"
#include "IPACM_Filtering.h"
#include "IPACM_Header.h"
#include "IPACM_EvtDispatcher.h"
#include "IPACM_Xml.h"
#include "IPACM_Log.h"
#include "IPACM_Netlink.h"
#include "IPACM_Config.h"
#include "IPACM_Defs.h"
/* current support 2 ipv6-address*/
#define MAX_DEFAULT_v4_ROUTE_RULES 1
#define MAX_DEFAULT_v6_ROUTE_RULES 2
#define IPV4_DEFAULT_FILTERTING_RULES 3
#define IPV6_DEFAULT_FILTERTING_RULES 3
#define IPV6_DEFAULT_LAN_FILTERTING_RULES 1
#define IPV6_NUM_ADDR 3
#define MAX_SOFTWAREROUTING_FILTERTING_RULES 2
#define INVALID_IFACE -1
/* iface */
class IPACM_Iface : public IPACM_Listener
{
public:
/* Static class for reading IPACM configuration from XML file*/
static IPACM_Config *ipacmcfg;
/* IPACM interface id */
int ipa_if_num;
/* IPACM interface name */
char dev_name[IF_NAME_LEN];
/* IPACM interface iptype v4, v6 or both */
ipa_ip_type ip_type;
/* IPACM interface v6 ip-address*/
uint32_t ipv6_addr[MAX_DEFAULT_v6_ROUTE_RULES][4];
uint32_t header_hdl;
uint32_t software_routing_fl_rule_hdl[MAX_SOFTWAREROUTING_FILTERTING_RULES];
bool softwarerouting_act;
/* IPACM number of default route rules for ipv6*/
int num_dft_rt_v6;
uint32_t dft_v4fl_rule_hdl[IPV4_DEFAULT_FILTERTING_RULES];
uint32_t dft_v6fl_rule_hdl[IPV6_DEFAULT_FILTERTING_RULES + IPV6_DEFAULT_LAN_FILTERTING_RULES];
/* create additional set of v6 RT-rules in Wanv6RT table*/
uint32_t dft_rt_rule_hdl[MAX_DEFAULT_v4_ROUTE_RULES+2*MAX_DEFAULT_v6_ROUTE_RULES];
ipa_ioc_query_intf *iface_query;
ipa_ioc_query_intf_tx_props *tx_prop;
ipa_ioc_query_intf_rx_props *rx_prop;
virtual int handle_down_evt() = 0;
virtual int handle_addr_evt(ipacm_event_data_addr *data) = 0;
IPACM_Iface(int iface_index);
virtual void event_callback(ipa_cm_event_id event,
void *data) = 0;
/* Query ipa_interface_index by given linux interface_index */
static int iface_ipa_index_query(int interface_index);
/* Query ipa_interface ipv4_addr by given linux interface_index */
static void iface_addr_query(int interface_index);
/*Query the IPA endpoint property */
int query_iface_property(void);
/*Configure the initial filter rules */
virtual int init_fl_rule(ipa_ip_type iptype);
static IPACM_Routing m_routing;
static IPACM_Filtering m_filtering;
static IPACM_Header m_header;
/* software routing enable */
virtual int handle_software_routing_enable(void);
/* software routing disable */
virtual int handle_software_routing_disable(void);
private:
static const char *DEVICE_NAME;
};
#endif /* IPACM_IFACE_H */
@@ -0,0 +1,91 @@
/*
Copyright (c) 2013, The Linux Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of The Linux Foundation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*!
@file
IPACM_IfaceManager.h
@brief
This file implements the IPAM iface_manager definitions
@Author
Skylar Chang
*/
#ifndef IPACM_IFACEMANAGER_H
#define IPACM_IFACEMANAGER_H
#include <stdio.h>
#include <IPACM_CmdQueue.h>
#include "IPACM_Routing.h"
#include "IPACM_Filtering.h"
#include "IPACM_Listener.h"
#include "IPACM_Iface.h"
#define IPA_MAX_NUM_NEIGHBOR_CLIENTS 17
#define IPA_INSTANCE_NOT_FOUND 0
#define IPA_INSTANCE_FOUND 1
/* queue */
typedef struct _iface_instances
{
/* Linux interface id */
int ipa_if_index;
IPACM_Listener *obj;
_iface_instances *next;
} iface_instances;
class IPACM_IfaceManager : public IPACM_Listener
{
public:
IPACM_IfaceManager();
void event_callback(ipa_cm_event_id event,
void *data);
/* api for all iface instances to de-register instances */
static int deregistr(IPACM_Listener *param);
private:
int create_iface_instance(int if_index);
/* api to register instances */
int registr(int ipa_if_index, IPACM_Listener *obj);
int SearchInstance(int ipa_if_index);
static iface_instances *head;
};
#endif /* IPACM_IFACEMANAGER_H */
+132
View File
@@ -0,0 +1,132 @@
/*
Copyright (c) 2013, The Linux Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of The Linux Foundation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*!
@file
IPACM_Lan.h
@brief
This file implements the LAN iface definitions
@Author
Skylar Chang
*/
#ifndef IPACM_LAN_H
#define IPACM_LAN_H
#include <stdio.h>
#include <linux/msm_ipa.h>
#include "IPACM_CmdQueue.h"
#include "IPACM_Iface.h"
#include "IPACM_Routing.h"
#include "IPACM_Filtering.h"
#define IPA_MAX_NUM_UNICAST_ROUTE_RULES 6
#define IPA_WAN_DEFAULT_FILTER_RULE_HANDLES 1
#define IPA_PRIV_SUBNET_FILTER_RULE_HANDLES 3
/* store each lan-iface unicast routing rule and its handler*/
struct ipa_lan_rt_rule
{
ipa_ip_type ip;
uint32_t v4_addr;
uint32_t v4_addr_mask;
uint32_t v6_addr[4];
uint32_t rt_rule_hdl[0];
};
/* lan iface */
class IPACM_Lan : public IPACM_Iface
{
public:
IPACM_Lan(int iface_index);
~IPACM_Lan();
/* store lan's wan-up filter rule handlers */
uint32_t lan_wan_fl_rule_hdl[IPA_WAN_DEFAULT_FILTER_RULE_HANDLES];
/* store private-subnet filter rule handlers */
uint32_t private_fl_rule_hdl[IPA_PRIV_SUBNET_FILTER_RULE_HANDLES];
/* LAN-iface's callback function */
void event_callback(ipa_cm_event_id event,
void *data);
/* configure filter rule for wan_up event*/
virtual int handle_wan_up(void);
/* delete filter rule for wan_down event*/
virtual int handle_wan_down(void);
/* configure private subnet filter rules*/
virtual int handle_private_subnet(ipa_ip_type iptype);
/* handle new_address event*/
int handle_addr_evt(ipacm_event_data_addr *data);
private:
/* dynamically allocate lan iface's unicast routing rule structure */
int rt_rule_len;
ipa_lan_rt_rule *route_rule;
uint32_t v6_addr[IPV6_NUM_ADDR][4];
int ipv6_set;
/* store the number of lan-iface's unicast routing rule */
int num_uni_rt;
inline ipa_lan_rt_rule* get_rt_ruleptr(ipa_lan_rt_rule *param, int cnt)
{
char *ret = ((char *)param) + (rt_rule_len * cnt);
return (ipa_lan_rt_rule *)ret;
}
/* handle unicast routing rule add event for ipv4 */
int handle_route_add_evt(ipacm_event_data_addr *data);
/* handle unicast routing rule add event for ipv6 */
int handle_route_add_evt_v6(ipacm_event_data_all *data);
/* handle unicast routing rule del event for ipv4 */
int handle_route_del_evt(ipacm_event_data_addr *data);
/* handle unicast routing rule del event for ipv6 */
int handle_route_del_evt_v6(ipacm_event_data_all *data);
/*handle wlan iface down event*/
int handle_down_evt();
};
#endif /* IPACM_LAN_H */
@@ -0,0 +1,55 @@
/*
Copyright (c) 2013, The Linux Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of The Linux Foundation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*!
@file
IPACM_Listener.h
@brief
This file implements the abstract class notifier.
@Author
Skylar Chang
*/
#ifndef IPACM_LISTENER_H
#define IPACM_LISTENER_H
#include "IPACM_Defs.h"
#include "IPACM_CmdQueue.h"
/* abstract class notifier */
class IPACM_Listener
{
public:
virtual void event_callback(ipa_cm_event_id event,
void *data) = 0;
};
#endif /* IPACM_LISTENER_H */
+71
View File
@@ -0,0 +1,71 @@
/*
Copyright (c) 2013, The Linux Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of The Linux Foundation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*!
@file
IPACM_log.h
@brief
This file implements the IPAM log functionality.
@Author
Skylar Chang
*/
#ifndef IPACM_LOG_H
#define IPACM_LOG_H
#ifdef __cplusplus
extern "C"
{
#endif
#include <stdio.h>
#include <string.h>
#include <syslog.h>
#define PERROR(fmt) printf("%s:%d %s()", __FILE__, __LINE__, __FUNCTION__);\
perror(fmt);
#define IPACMERR(fmt, ...) syslog(LOG_ERR, "ERROR: %s:%d %s() " fmt, __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__);\
printf("ERR: %s:%d %s() " fmt, __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__);
#ifdef DEBUG
#define IPACMDBG(fmt, ...) syslog(LOG_DEBUG, "%s:%d %s() " fmt, __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__);\
printf("%s:%d %s() " fmt, __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__);
#else
#define IPACMDBG(fmt, ...)
#endif
#ifdef __cplusplus
}
#endif
#endif /* IPACM_LOG_H */
@@ -0,0 +1,78 @@
/*
Copyright (c) 2013, The Linux Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of The Linux Foundation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*!
@file
IPACM_Neighbor.h
@brief
This file implements the functionality of handling IPACM Neighbor events.
@Author
Skylar Chang
*/
#ifndef IPACM_NEIGHBOR_H
#define IPACM_NEIGHBOR_H
#include <stdio.h>
#include <IPACM_CmdQueue.h>
#include <linux/msm_ipa.h>
#include "IPACM_Routing.h"
#include "IPACM_Filtering.h"
#include "IPACM_Listener.h"
#include "IPACM_Iface.h"
#define IPA_MAX_NUM_NEIGHBOR_CLIENTS 17
struct ipa_neighbor_client
{
uint8_t mac_addr[6];
int iface_index;
};
class IPACM_Neighbor : public IPACM_Listener
{
public:
IPACM_Neighbor();
void event_callback(ipa_cm_event_id event,
void *data);
private:
int num_neighbor_client;
ipa_neighbor_client neighbor_client[IPA_MAX_NUM_NEIGHBOR_CLIENTS];
};
#endif /* IPACM_NEIGHBOR_H */
+221
View File
@@ -0,0 +1,221 @@
/*
Copyright (c) 2013, The Linux Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of The Linux Foundation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*!
@file
IPA_Netlink.h
@brief
IPACM Netlink Messaging Implementation File
@Author
Skylar Chang
*/
#ifndef IPACM_NETLINK_H
#define IPACM_NETLINK_H
#ifdef __cplusplus
extern "C"
{
#endif
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <pthread.h>
#include <sys/select.h>
#include <sys/socket.h>
#include <linux/if.h>
#include <linux/if_addr.h>
#include <linux/rtnetlink.h>
#include <linux/netlink.h>
#include <netinet/in.h>
#include "IPACM_Defs.h"
#define MAX_NUM_OF_FD 10
#define IPA_NL_MSG_MAX_LEN (1024)
#define IF_NAME_LEN 16
/*---------------------------------------------------------------------------
Type representing enumeration of NetLink event indication messages
---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------
Types representing parsed NetLink message
---------------------------------------------------------------------------*/
#define IPA_NLA_PARAM_NONE (0x0000)
#define IPA_NLA_PARAM_PREFIXADDR (0x0001)
#define IPA_NLA_PARAM_LOCALADDR (0x0002)
#define IPA_NLA_PARAM_LABELNAME (0x0004)
#define IPA_NLA_PARAM_BCASTADDR (0x0008)
#define IPA_NLA_PARAM_ACASTADDR (0x0010)
#define IPA_NLA_PARAM_MCASTADDR (0x0020)
#define IPA_NLA_PARAM_CACHEINFO (0x0080)
#define IPA_NLA_PARAM_PROTOINFO (0x0100)
#define IPA_NLA_PARAM_FLAGS (0x0200)
#define IPA_RTA_PARAM_NONE (0x0000)
#define IPA_RTA_PARAM_DST (0x0001)
#define IPA_RTA_PARAM_SRC (0x0002)
#define IPA_RTA_PARAM_GATEWAY (0x0004)
#define IPA_RTA_PARAM_IIF (0x0008)
#define IPA_RTA_PARAM_OIF (0x0010)
#define IPA_RTA_PARAM_CACHEINFO (0x0020)
#define IPA_RTA_PARAM_PRIORITY (0x0080)
#define IPA_RTA_PARAM_METRICS (0x0100)
/*---------------------------------------------------------------------------
Type representing function callback registered with a socket listener
thread for reading from a socket on receipt of an incoming message
---------------------------------------------------------------------------*/
typedef int (*ipa_sock_thrd_fd_read_f)(int fd);
typedef enum
{
IPA_INIT = 0,
IPA_LINK_UP_WAIT,
IPA_LINK_UP,
IPA_LINK_DOWN_WAIT,
IPA_LINK_DOWN
} ipa_nl_state_e;
typedef struct
{
int sk_fd;
ipa_sock_thrd_fd_read_f read_func;
} ipa_nl_sk_fd_map_info_t;
typedef struct
{
ipa_nl_sk_fd_map_info_t sk_fds[MAX_NUM_OF_FD];
fd_set fdset;
int num_fd;
int max_fd;
} ipa_nl_sk_fd_set_info_t;
typedef struct
{
int sk_fd; /* socket descriptor */
struct sockaddr_nl sk_addr_loc; /* local address of socket */
} ipa_nl_sk_info_t;
typedef struct ipa_nl_addr_s {
struct sockaddr_storage ip_addr;
unsigned int mask;
} ipa_nl_addr_t;
typedef struct ipa_nl_proto_info_s {
unsigned int param_mask;
unsigned int flags;
struct ifla_cacheinfo cache_info;
} ipa_nl_proto_info_t;
typedef struct
{
struct ifinfomsg metainfo; /* from header */
} ipa_nl_link_info_t;
typedef struct ipa_nl_addr_info_s {
struct ifaddrmsg metainfo; /* from header */
struct /* attributes */
{
unsigned int param_mask;
unsigned char label_name[IF_NAME_LEN];
struct sockaddr_storage prefix_addr;
} attr_info;
} ipa_nl_addr_info_t;
typedef struct ipa_nl_neigh_info_s {
struct ndmsg metainfo; /* from header */
struct /* attributes */
{
unsigned int param_mask;
struct sockaddr_storage local_addr;
struct sockaddr lladdr_hwaddr;
} attr_info;
} ipa_nl_neigh_info_t;
typedef struct ipa_nl_route_info_s {
struct rtmsg metainfo; /* from header */
struct /* attributes */
{
unsigned int param_mask;
struct sockaddr_storage dst_addr;
struct sockaddr_storage src_addr;
struct sockaddr_storage gateway_addr;
struct sockaddr_storage mark_addr;
struct rta_cacheinfo cache_info;
__u32 iif_index; /* Link index */
__u32 oif_index; /* Link index */
__u32 priority;
__u32 metrics;
ipa_nl_proto_info_t proto_info;
} attr_info;
} ipa_nl_route_info_t;
#define IPA_FLOW_TYPE_INVALID (-1)
typedef struct
{
unsigned int type;
bool link_event;
/* Optional parameters */
ipa_nl_link_info_t nl_link_info;
ipa_nl_addr_info_t nl_addr_info;
ipa_nl_neigh_info_t nl_neigh_info;
ipa_nl_route_info_t nl_route_info;
} ipa_nl_msg_t;
/* Initialization routine for listener on NetLink sockets interface */
int ipa_nl_listener_init
(
unsigned int nl_type,
unsigned int nl_groups,
ipa_nl_sk_fd_set_info_t *sk_fdset,
ipa_sock_thrd_fd_read_f read_f
);
/* Virtual function registered to receive incoming messages over the NETLINK routing socket*/
int ipa_nl_recv_msg(int fd);
/* map mask value for ipv6 */
int mask_v6(int index, uint32_t *mask);
#ifdef __cplusplus
}
#endif
#endif /* IPACM_NETLINK_H */
@@ -0,0 +1,75 @@
/*
Copyright (c) 2013, The Linux Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of The Linux Foundation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*!
@file
IPACM_Routing.cpp
@brief
This file implements the IPACM routing functionality.
@Author
Skylar Chang
*/
#ifndef IPACM_ROUTING_H
#define IPACM_ROUTING_H
#include <stdint.h>
#include <linux/msm_ipa.h>
#include <IPACM_Defs.h>
using namespace std;
class IPACM_Routing
{
public:
IPACM_Routing();
~IPACM_Routing();
bool AddRoutingRule(struct ipa_ioc_add_rt_rule *ruleTable);
bool DeleteRoutingRule(struct ipa_ioc_del_rt_rule *ruleTable);
bool Commit(enum ipa_ip_type ip);
bool Reset(enum ipa_ip_type ip);
bool GetRoutingTable(struct ipa_ioc_get_rt_tbl *routingTable);
bool PutRoutingTable(uint32_t routingTableHandle);
bool DeviceNodeIsOpened();
bool DeleteRoutingHdl(uint32_t rt_rule_hdl, ipa_ip_type ip);
private:
static const char *DEVICE_NAME;
int m_fd; /* File descriptor of the IPA device node /dev/ipa */
};
#endif //IPACM_ROUTING_H
+117
View File
@@ -0,0 +1,117 @@
/*
Copyright (c) 2013, The Linux Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of The Linux Foundation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*!
@file
IPACM_Wan.cpp
@brief
This file implements the WAN iface functionality.
@Author
Skylar Chang
*/
#ifndef IPACM_WAN_H
#define IPACM_WAN_H
#include <stdio.h>
#include <IPACM_CmdQueue.h>
#include <linux/msm_ipa.h>
#include "IPACM_Routing.h"
#include "IPACM_Filtering.h"
#include <IPACM_Iface.h>
#include <IPACM_Defs.h>
#include <IPACM_Xml.h>
#define IPA_NUM_DEFAULT_WAN_FILTER_RULES 2
/* wan iface */
class IPACM_Wan : public IPACM_Iface
{
public:
static bool wan_up;
IPACM_Wan(int iface_index);
~IPACM_Wan();
static bool isWanUP()
{
return wan_up;
}
void event_callback(ipa_cm_event_id event,
void *data);
private:
uint32_t *wan_route_rule_v4_hdl;
uint32_t *wan_route_rule_v6_hdl;
uint32_t *wan_route_rule_v6_hdl_a5;
uint32_t hdr_hdl_sta_v4;
uint32_t hdr_hdl_sta_v6;
uint32_t firewall_hdl_v4[IPACM_MAX_FIREWALL_ENTRIES];
uint32_t firewall_hdl_v6[IPACM_MAX_FIREWALL_ENTRIES];
uint32_t dft_wan_fl_hdl[IPA_NUM_DEFAULT_WAN_FILTER_RULES];
int num_firewall_v4,num_firewall_v6;
uint32_t wan_v4_addr;
bool active_v4;
bool active_v6;
bool header_set_v4;
bool header_set_v6;
bool header_partial_default_wan_v4;
bool header_partial_default_wan_v6;
/* IPACM firewall Configuration file*/
IPACM_firewall_conf_t firewall_config;
/* handle new_address event */
int handle_addr_evt(ipacm_event_data_addr *data);
/* wan default route/filter rule configuration */
int handle_route_add_evt(ipa_ip_type iptype);
/* wan default route/filter rule delete */
int handle_route_del_evt(ipa_ip_type iptype);
/* construct complete ethernet header */
int handle_header_add_evt(uint8_t mac_addr[6]);
/* configure the initial firewall filter rules */
int config_dft_firewall_rules(ipa_ip_type iptype);
/*clean firewall filter rules */
int del_dft_firewall_rules(ipa_ip_type iptype);
/*handle wan-iface down event */
int handle_down_evt();
};
#endif /* IPACM_WAN_H */
+252
View File
@@ -0,0 +1,252 @@
/*
Copyright (c) 2013, The Linux Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of The Linux Foundation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*!
@file
IPACM_Wlan.h
@brief
This file implements the WLAN iface functionality.
@Author
Skylar Chang
*/
#ifndef IPACM_WLAN_H
#define IPACM_WLAN_H
#include <stdio.h>
#include <IPACM_CmdQueue.h>
#include <linux/msm_ipa.h>
#include "IPACM_Routing.h"
#include "IPACM_Filtering.h"
#include "IPACM_Lan.h"
#include "IPACM_Iface.h"
#include "IPACM_Conntrack_NATApp.h"
typedef struct _wlan_client_rt_hdl
{
uint32_t wifi_rt_rule_hdl_v4;
uint32_t wifi_rt_rule_hdl_v6[IPV6_NUM_ADDR];
uint32_t wifi_rt_rule_hdl_v6_wan[IPV6_NUM_ADDR];
}wlan_client_rt_hdl;
typedef struct _ipa_wlan_client
{
uint8_t mac[IPA_MAC_ADDR_SIZE];
uint32_t v4_addr;
uint32_t v6_addr[IPV6_NUM_ADDR][4];
uint32_t hdr_hdl_v4;
uint32_t hdr_hdl_v6;
bool route_rule_set_v4;
int route_rule_set_v6;
bool ipv4_set;
int ipv6_set;
bool ipv4_header_set;
bool ipv6_header_set;
bool power_save_set;
wlan_client_rt_hdl wifi_rt_hdl[0]; /* depends on number of tx properties */
}ipa_wlan_client;
typedef struct _wlan_ampdu_flt_rules
{
uint32_t hdl[IPA_MAX_NUM_AMPDU_RULE];
ipa_ip_type ip[IPA_MAX_NUM_AMPDU_RULE];
int num_rules;
}wlan_ampdu_flt_rules;
/* wlan iface */
class IPACM_Wlan : public IPACM_Lan
{
public:
IPACM_Wlan(int iface_index);
~IPACM_Wlan(void);
static int total_num_wifi_clients;
void event_callback(ipa_cm_event_id event,
void *data);
private:
int wlan_client_len;
ipa_wlan_client *wlan_client;
int header_name_count;
int num_wifi_client;
wlan_ampdu_flt_rules wlan_ampdu_flt_rule;
NatApp *Nat_App;
inline ipa_wlan_client* get_client_memptr(ipa_wlan_client *param, int cnt)
{
char *ret = ((char *)param) + (wlan_client_len * cnt);
return (ipa_wlan_client *)ret;
}
inline int get_wlan_client_index(uint8_t *mac_addr)
{
int cnt;
int num_wifi_client_tmp = num_wifi_client;
IPACMDBG("Passed MAC %02x:%02x:%02x:%02x:%02x:%02x\n",
mac_addr[0], mac_addr[1], mac_addr[2],
mac_addr[3], mac_addr[4], mac_addr[5]);
for(cnt = 0; cnt < num_wifi_client_tmp; cnt++)
{
IPACMDBG("stored MAC %02x:%02x:%02x:%02x:%02x:%02x\n",
get_client_memptr(wlan_client, cnt)->mac[0],
get_client_memptr(wlan_client, cnt)->mac[1],
get_client_memptr(wlan_client, cnt)->mac[2],
get_client_memptr(wlan_client, cnt)->mac[3],
get_client_memptr(wlan_client, cnt)->mac[4],
get_client_memptr(wlan_client, cnt)->mac[5]);
if(memcmp(get_client_memptr(wlan_client, cnt)->mac,
mac_addr,
sizeof(get_client_memptr(wlan_client, cnt)->mac)) == 0)
{
IPACMDBG("Matched client index: %d\n", cnt);
return cnt;
}
}
return IPACM_INVALID_INDEX;
}
inline int delete_default_qos_rtrules(int clt_indx, ipa_ip_type iptype)
{
uint32_t tx_index;
uint32_t rt_hdl;
int num_v6;
if(iptype == IPA_IP_v4)
{
for(tx_index = 0; tx_index < iface_query->num_tx_props; tx_index++)
{
if((tx_prop->tx[tx_index].ip == IPA_IP_v4) && (get_client_memptr(wlan_client, clt_indx)->route_rule_set_v4==true)) /* for ipv4 */
{
IPACMDBG("Delete client index %d ipv4 Qos rules for tx:%d \n", clt_indx,tx_index);
rt_hdl = get_client_memptr(wlan_client, clt_indx)->wifi_rt_hdl[tx_index].wifi_rt_rule_hdl_v4;
if(m_routing.DeleteRoutingHdl(rt_hdl, IPA_IP_v4) == false)
{
return IPACM_FAILURE;
}
}
} /* end of for loop */
/* clean the 4 Qos ipv4 RT rules for client:clt_indx */
if(get_client_memptr(wlan_client, clt_indx)->route_rule_set_v4==true) /* for ipv4 */
{
get_client_memptr(wlan_client, clt_indx)->route_rule_set_v4 = false;
}
}
if(iptype == IPA_IP_v6)
{
for(tx_index = 0; tx_index < iface_query->num_tx_props; tx_index++)
{
if((tx_prop->tx[tx_index].ip == IPA_IP_v6) && (get_client_memptr(wlan_client, clt_indx)->route_rule_set_v6 != 0)) /* for ipv6 */
{
for(num_v6 =0;num_v6 < get_client_memptr(wlan_client, clt_indx)->route_rule_set_v6;num_v6++)
{
IPACMDBG("Delete client index %d ipv6 Qos rules for %d-st ipv6 for tx:%d\n", clt_indx,num_v6,tx_index);
rt_hdl = get_client_memptr(wlan_client, clt_indx)->wifi_rt_hdl[tx_index].wifi_rt_rule_hdl_v6[num_v6];
if(m_routing.DeleteRoutingHdl(rt_hdl, IPA_IP_v6) == false)
{
return IPACM_FAILURE;
}
rt_hdl = get_client_memptr(wlan_client, clt_indx)->wifi_rt_hdl[tx_index].wifi_rt_rule_hdl_v6_wan[num_v6];
if(m_routing.DeleteRoutingHdl(rt_hdl, IPA_IP_v6) == false)
{
return IPACM_FAILURE;
}
}
}
} /* end of for loop */
/* clean the 4 Qos ipv6 RT rules for client:clt_indx */
if(get_client_memptr(wlan_client, clt_indx)->route_rule_set_v6 != 0) /* for ipv6 */
{
get_client_memptr(wlan_client, clt_indx)->route_rule_set_v6 = 0;
}
}
return IPACM_SUCCESS;
}
/* handle wifi client initial,copy all partial headers (tx property) */
int handle_wlan_client_init(uint8_t *mac_addr);
/*handle wifi client */
int handle_wlan_client_ipaddr(ipacm_event_data_all *data);
/*handle wifi client routing rule*/
int handle_wlan_client_route_rule(uint8_t *mac_addr, ipa_ip_type iptype);
/*handle wifi client power-save mode*/
int handle_wlan_client_pwrsave(uint8_t *mac_addr);
/*handle wifi client del mode*/
int handle_wlan_client_down_evt(uint8_t *mac_addr);
/*duplicate ampdu filter rules for private subnet configuration*/
int handle_private_subnet(ipa_ip_type iptype);
/*duplicate ampdu filter rules for initial iface configuration*/
int init_fl_rule(ipa_ip_type iptype);
/*duplicate ampdu filter rules for new_address event*/
int handle_addr_evt(ipacm_event_data_addr *data);
/*duplicate ampdu filter rules for wan_up event*/
int handle_wan_up(void);
/*delete ampdu filter rules for wan_down event*/
int handle_wan_down(void);
/*duplicate ampdu filter rules for software_routing event*/
int handle_software_routing_enable(void);
/*delete ampdu filter rules for disabling software_routing event*/
int handle_software_routing_disable(void);
/*handle wlan iface down event*/
int handle_down_evt();
};
#endif /* IPACM_WLAN_H */
+282
View File
@@ -0,0 +1,282 @@
/*
Copyright (c) 2013, The Linux Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of The Linux Foundation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*!
@file
IPACM_Xml.h
@brief
This file implements the XML specific parsing functionality.
@Author
Skylar Chang/Shihuan Liu
*/
#ifndef IPACM_XML_H
#define IPACM_XML_H
#ifdef __cplusplus
extern "C" {
#endif
#include <linux/msm_ipa.h>
#include "IPACM_Defs.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <arpa/inet.h>
#include <stdint.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
#define IPACM_ASSERT(a) \
if (!(a)) { \
fprintf(stderr, "%s, %d: assertion (a) failed!", \
__FILE__, \
__LINE__); \
abort(); \
}
/* Max allowed size of the XML file (2 MB) */
#define IPACM_XML_MAX_FILESIZE (2 << 20)
#define IPACM_MAX_FIREWALL_ENTRIES 50
#define IPACM_IPV6_ADDR_LEN 16
/* Defines for clipping space or space & quotes (single, double) */
#define IPACM_XML_CLIP_SPACE " "
#define IPACM_XML_CLIP_SPACE_QUOTES " '\""
#define MAX_XML_STR_LEN 120
/* IPA Config Entries */
#define system_TAG "system"
#define IPACMCFG_TAG "IPACM"
#define IPACMIFACECFG_TAG "IPACMIface"
#define IFACE_TAG "Iface"
#define NAME_TAG "Name"
#define CATEGORY_TAG "Category"
#define IPACMPRIVATESUBNETCFG_TAG "IPACMPrivateSubnet"
#define SUBNET_TAG "Subnet"
#define SUBNETADDRESS_TAG "SubnetAddress"
#define SUBNETMASK_TAG "SubnetMask"
#define WANIF_TAG "WAN"
#define LANIF_TAG "LAN"
#define WLANIF_TAG "WLAN"
#define VIRTUALIF_TAG "VIRTUAL"
#define UNKNOWNIF_TAG "UNKNOWN"
#define IPACMALG_TAG "IPACMALG"
#define ALG_TAG "ALG"
#define Protocol_TAG "Protocol"
#define Port_TAG "Port"
#define TCP_PROTOCOL_TAG "TCP"
#define UDP_PROTOCOL_TAG "UDP"
/* FIREWALL Config Entries */
#define Firewall_TAG "Firewall"
#define MobileAPFirewallCfg_TAG "MobileAPFirewallCfg"
#define FirewallEnabled_TAG "FirewallEnabled"
#define FirewallPktsAllowed_TAG "FirewallPktsAllowed"
#define IPFamily_TAG "IPFamily"
#define IPV4SourceAddress_TAG "IPV4SourceAddress"
#define IPV4SourceIPAddress_TAG "IPV4SourceIPAddress"
#define IPV4SourceSubnetMask_TAG "IPV4SourceSubnetMask"
#define IPV4DestinationAddress_TAG "IPV4DestinationAddress"
#define IPV4DestinationIPAddress_TAG "IPV4DestinationIPAddress"
#define IPV4DestinationSubnetMask_TAG "IPV4DestinationSubnetMask"
#define IPV4TypeOfService_TAG "IPV4TypeOfService"
#define TOSValue_TAG "TOSValue"
#define TOSMask_TAG "TOSMask"
#define IPV4NextHeaderProtocol_TAG "IPV4NextHeaderProtocol"
#define IPV6SourceAddress_TAG "IPV6SourceAddress"
#define IPV6SourceIPAddress_TAG "IPV6SourceIPAddress"
#define IPV6SourcePrefix_TAG "IPV6SourcePrefix"
#define IPV6DestinationAddress_TAG "IPV6DestinationAddress"
#define IPV6DestinationIPAddress_TAG "IPV6DestinationIPAddress"
#define IPV6DestinationPrefix_TAG "IPV6DestinationPrefix"
#define IPV6TrafficClass_TAG "IPV6TrafficClass"
#define TrfClsValue_TAG "TrfClsValue"
#define TrfClsMask_TAG "TrfClsMask"
#define IPV6NextHeaderProtocol_TAG "IPV6NextHeaderProtocol"
#define TCPSource_TAG "TCPSource"
#define TCPSourcePort_TAG "TCPSourcePort"
#define TCPSourceRange_TAG "TCPSourceRange"
#define TCPDestination_TAG "TCPDestination"
#define TCPDestinationPort_TAG "TCPDestinationPort"
#define TCPDestinationRange_TAG "TCPDestinationRange"
#define UDPSource_TAG "UDPSource"
#define UDPSourcePort_TAG "UDPSourcePort"
#define UDPSourceRange_TAG "UDPSourceRange"
#define UDPDestination_TAG "UDPDestination"
#define UDPDestinationPort_TAG "UDPDestinationPort"
#define UDPDestinationRange_TAG "UDPDestinationRange"
#define ICMPType_TAG "ICMPType"
#define ICMPCode_TAG "ICMPCode"
#define ESP_TAG "ESP"
#define ESPSPI_TAG "ESPSPI"
#define TCP_UDPSource_TAG "TCP_UDPSource"
#define TCP_UDPSourcePort_TAG "TCP_UDPSourcePort"
#define TCP_UDPSourceRange_TAG "TCP_UDPSourceRange"
#define TCP_UDPDestination_TAG "TCP_UDPDestination"
#define TCP_UDPDestinationPort_TAG "TCP_UDPDestinationPort"
#define TCP_UDPDestinationRange_TAG "TCP_UDPDestinationRange"
#define IPACMNat_TAG "IPACMNAT"
#define NAT_MaxEntries_TAG "MaxNatEntries"
/*---------------------------------------------------------------------------
IP protocol numbers - use in dss_socket() to identify protocols.
Also contains the extension header types for IPv6.
---------------------------------------------------------------------------*/
typedef enum
{
IPACM_FIREWALL_IPV6_BASE_HDR = 4, /* IPv6 Base Header */
IPACM_FIREWALL_IPPROTO_HOP_BY_HOP_OPT_HDR = 0, /* Hop-by-hop Option Header */
IPACM_FIREWALL_IPPROTO_ICMP = 1, /* ICMP protocol */
IPACM_FIREWALL_IPPROTO_IGMP = 2, /* IGMP protocol */
IPACM_FIREWALL_IPPROTO_IP = IPACM_FIREWALL_IPV6_BASE_HDR, /* IPv4 */
IPACM_FIREWALL_IPPROTO_TCP = 6, /* TCP Protocol */
IPACM_FIREWALL_IPPROTO_UDP = 17, /* UDP Protocol */
IPACM_FIREWALL_IPPROTO_IPV6 = 41, /* IPv6 */
IPACM_FIREWALL_IPPROTO_ROUTING_HDR = 43, /* Routing Header */
IPACM_FIREWALL_IPPROTO_FRAG_HDR = 44, /* Fragmentation Header */
IPACM_FIREWALL_IPPROTO_GRE = 47, /* GRE Protocol */
IPACM_FIREWALL_IPPROTO_ESP = 50, /* ESP Protocol */
IPACM_FIREWALL_IPPROTO_AH = 51, /* Authentication Header */
IPACM_FIREWALL_IPPROTO_ICMP6 = 58, /* ICMPv6 */
IPACM_FIREWALL_NO_NEXT_HDR = 59, /* No Next Header for IPv6 */
IPACM_FIREWALL_IPPROTO_DEST_OPT_HDR = 60, /* Destination Options Header */
IPACM_FIREWALL_IPPROTO_MOBILITY_HDR = 135, /* Mobility Header */
IPACM_FIREWALL_IPPROTO_TCP_UDP = 253 /* Unspecified protocol used for IPACM */
} ipacm_firewall_ip_protocol_enum_type;
/* define as mobileap firewall rule format*/
typedef enum
{
IP_V4 = 4,
IP_V6 = 6
} firewall_ip_version_enum;
/*---------------------------------------------------------------------------
Extended FireWall Entry Configuration.
---------------------------------------------------------------------------*/
typedef struct
{
struct ipa_rule_attrib attrib;
firewall_ip_version_enum ip_vsn;
} IPACM_extd_firewall_entry_conf_t;
/*---------------------------------------------------------------------------
Extended FireWall configuration.
---------------------------------------------------------------------------*/
typedef union
{
IPACM_extd_firewall_entry_conf_t extd_firewall_entry;
} IPACM_extd_firewall_conf_t;
typedef struct
{
char firewall_config_file[IPA_MAX_FILE_LEN];
uint8_t num_extd_firewall_entries;
IPACM_extd_firewall_entry_conf_t extd_firewall_entries[IPACM_MAX_FIREWALL_ENTRIES];
bool rule_action_accept;
bool firewall_enable;
} IPACM_firewall_conf_t;
typedef struct
{
uint8_t num_iface_entries;
ipa_ifi_dev_name_t iface_entries[IPA_MAX_IFACE_ENTRIES];
} ipacm_iface_conf_t;
typedef struct
{
uint8_t num_subnet_entries;
ipa_private_subnet private_subnet_entries[IPA_MAX_PRIVATE_SUBNET_ENTRIES];
} ipacm_private_subnet_conf_t;
typedef struct
{
uint8_t protocol;
uint16_t port;
} ipacm_alg;
typedef struct
{
uint8_t num_alg_entries;
ipacm_alg alg_entries[IPA_MAX_ALG_ENTRIES];
} ipacm_alg_conf_t;
typedef struct _IPACM_conf_t
{
ipacm_iface_conf_t iface_config;
ipacm_private_subnet_conf_t private_subnet_config;
ipacm_alg_conf_t alg_config;
int nat_max_entries;
} IPACM_conf_t;
/* This function read IPACM XML configuration*/
int ipacm_read_cfg_xml
(
char *xml_file, /* Filename and path */
IPACM_conf_t *config /* Mobile AP config data */
);
/* This function reads QCMAP Firewall XML and store in IPACM Firewall stucture */
int IPACM_read_firewall_xml
(
char *xml_file, /* Filename and path */
IPACM_firewall_conf_t *config /* Mobile AP config data */
);
#ifdef __cplusplus
}
#endif
#endif //IPACM_XML