1 /* 2 Copyright (c) 2014, 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 /* 31 * IPACM_LanToLan.h 32 * 33 * Created on: Mar 4th, 2014 34 * Author: Shihuan Liu 35 */ 36 37 #ifndef IPACM_LANTOLAN_H 38 #define IPACM_LANTOLAN_H 39 40 #include <stdint.h> 41 #include "linux/msm_ipa.h" 42 #include "IPACM_Iface.h" 43 #include "IPACM_Defs.h" 44 #include "IPACM_Lan.h" 45 46 #ifdef FEATURE_IPA_ANDROID 47 #include <libxml/list.h> 48 #else/* defined(FEATURE_IPA_ANDROID) */ 49 #include <list> 50 #endif /* ndefined(FEATURE_IPA_ANDROID)*/ 51 52 #define MAX_NUM_CACHED_CLIENT_ADD_EVENT 10 53 #define MAX_NUM_IFACE 10 54 #define MAX_NUM_CLIENT 16 55 56 struct rt_rule_info 57 { 58 int num_hdl[IPA_IP_MAX]; /* one client may need more than one routing rules on the same routing table depending on tx_prop */ 59 uint32_t rule_hdl[IPA_IP_MAX][MAX_NUM_PROP]; 60 }; 61 62 struct client_info 63 { 64 uint8_t mac_addr[6]; 65 rt_rule_info inter_iface_rt_rule_hdl[IPA_HDR_L2_MAX]; /* routing rule handles of inter interface communication based on source l2 header type */ 66 rt_rule_info intra_iface_rt_rule_hdl; /* routing rule handles of inter interface communication */ 67 }; 68 69 struct flt_rule_info 70 { 71 client_info *p_client; 72 uint32_t flt_rule_hdl[IPA_IP_MAX]; 73 }; 74 75 struct peer_iface_info 76 { 77 class IPACM_LanToLan_Iface *peer; 78 char rt_tbl_name_for_rt[IPA_IP_MAX][IPA_RESOURCE_NAME_MAX]; 79 char rt_tbl_name_for_flt[IPA_IP_MAX][IPA_RESOURCE_NAME_MAX]; 80 list<flt_rule_info> flt_rule; 81 }; 82 83 class IPACM_LanToLan_Iface 84 { 85 public: 86 IPACM_LanToLan_Iface(IPACM_Lan *p_iface); 87 ~IPACM_LanToLan_Iface(); 88 89 void add_client_rt_rule_for_new_iface(); 90 91 void add_all_inter_interface_client_flt_rule(ipa_ip_type iptype); 92 93 void add_all_intra_interface_client_flt_rule(ipa_ip_type iptype); 94 95 void handle_down_event(); 96 97 void handle_wlan_scc_mcc_switch(); 98 99 void handle_intra_interface_info(); 100 101 void handle_new_iface_up(char rt_tbl_name_for_flt[][IPA_RESOURCE_NAME_MAX], char rt_tbl_name_for_rt[][IPA_RESOURCE_NAME_MAX], 102 IPACM_LanToLan_Iface *peer_iface); 103 104 void handle_client_add(uint8_t *mac); 105 106 void handle_client_del(uint8_t *mac); 107 108 void print_data_structure_info(); 109 110 IPACM_Lan* get_iface_pointer(); 111 112 bool get_m_is_ip_addr_assigned(ipa_ip_type iptype); 113 114 void set_m_is_ip_addr_assigned(ipa_ip_type iptype, bool value); 115 116 bool get_m_support_inter_iface_offload(); 117 118 bool get_m_support_intra_iface_offload(); 119 120 void increment_ref_cnt_peer_l2_hdr_type(ipa_hdr_l2_type peer_l2_type); 121 122 void decrement_ref_cnt_peer_l2_hdr_type(ipa_hdr_l2_type peer_l2_type); 123 124 private: 125 126 IPACM_Lan *m_p_iface; 127 bool m_is_ip_addr_assigned[IPA_IP_MAX]; 128 bool m_support_inter_iface_offload; 129 bool m_support_intra_iface_offload; 130 131 int ref_cnt_peer_l2_hdr_type[IPA_HDR_L2_MAX]; /* reference count of l2 header type of peer interfaces */ 132 uint32_t hdr_proc_ctx_for_inter_interface[IPA_HDR_L2_MAX]; 133 uint32_t hdr_proc_ctx_for_intra_interface; 134 135 list<client_info> m_client_info; /* client list */ 136 list<peer_iface_info> m_peer_iface_info; /* peer information list */ 137 138 /* The following members are for intra-interface communication*/ 139 peer_iface_info m_intra_interface_info; 140 141 void add_one_client_flt_rule(IPACM_LanToLan_Iface *peer_iface, client_info *client); 142 143 void add_client_flt_rule(peer_iface_info *peer, client_info *client, ipa_ip_type iptype); 144 145 void del_one_client_flt_rule(IPACM_LanToLan_Iface *peer_iface, client_info *client); 146 147 void del_client_flt_rule(peer_iface_info *peer, client_info *client); 148 149 void add_client_rt_rule(peer_iface_info *peer, client_info *client); 150 151 void del_client_rt_rule(peer_iface_info *peer, client_info *client); 152 153 void clear_all_flt_rule_for_one_peer_iface(peer_iface_info *peer); 154 155 void clear_all_rt_rule_for_one_peer_iface(peer_iface_info *peer); 156 157 void add_hdr_proc_ctx(ipa_hdr_l2_type peer_l2_type); 158 159 void del_hdr_proc_ctx(ipa_hdr_l2_type peer_l2_type); 160 161 void print_peer_info(peer_iface_info *peer_info); 162 163 }; 164 165 class IPACM_LanToLan : public IPACM_Listener 166 { 167 168 public: 169 170 IPACM_LanToLan(); 171 172 private: 173 174 ~IPACM_LanToLan(); 175 176 list<class IPACM_LanToLan_Iface> m_iface; 177 178 list<ipacm_event_eth_bridge> m_cached_client_add_event; 179 180 void handle_iface_up(ipacm_event_eth_bridge *data); 181 182 void handle_iface_down(ipacm_event_eth_bridge *data); 183 184 void handle_client_add(ipacm_event_eth_bridge *data); 185 186 void handle_client_del(ipacm_event_eth_bridge *data); 187 188 void handle_wlan_scc_mcc_switch(ipacm_event_eth_bridge *data); 189 190 void handle_new_iface_up(IPACM_LanToLan_Iface *new_iface, IPACM_LanToLan_Iface *exist_iface); 191 192 void event_callback(ipa_cm_event_id event, void* param); 193 194 void handle_cached_client_add_event(IPACM_Lan *p_iface); 195 196 void clear_cached_client_add_event(IPACM_Lan *p_iface); 197 198 void print_data_structure_info(); 199 200 }; 201 202 #endif 203