Home | History | Annotate | Download | only in inc
      1 /*
      2 Copyright (c) 2013-2016, 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_Wlan.h
     32 
     33 		@brief
     34 		This file implements the WLAN iface functionality.
     35 
     36 		@Author
     37 		Skylar Chang
     38 
     39 */
     40 #ifndef IPACM_WLAN_H
     41 #define IPACM_WLAN_H
     42 
     43 #include <stdio.h>
     44 #include <IPACM_CmdQueue.h>
     45 #include <linux/msm_ipa.h>
     46 #include "IPACM_Routing.h"
     47 #include "IPACM_Filtering.h"
     48 #include "IPACM_Lan.h"
     49 #include "IPACM_Iface.h"
     50 #include "IPACM_Conntrack_NATApp.h"
     51 
     52 typedef struct _wlan_client_rt_hdl
     53 {
     54 	uint32_t wifi_rt_rule_hdl_v4;
     55 	uint32_t wifi_rt_rule_hdl_v6[IPV6_NUM_ADDR];
     56 	uint32_t wifi_rt_rule_hdl_v6_wan[IPV6_NUM_ADDR];
     57 }wlan_client_rt_hdl;
     58 
     59 typedef struct _ipa_wlan_client
     60 {
     61 	ipacm_event_data_wlan_ex* p_hdr_info;
     62 	uint8_t mac[IPA_MAC_ADDR_SIZE];
     63 	uint32_t v4_addr;
     64 	uint32_t v6_addr[IPV6_NUM_ADDR][4];
     65 	uint32_t hdr_hdl_v4;
     66 	uint32_t hdr_hdl_v6;
     67 	bool route_rule_set_v4;
     68 	int route_rule_set_v6;
     69 	bool ipv4_set;
     70 	int ipv6_set;
     71 	bool ipv4_header_set;
     72 	bool ipv6_header_set;
     73 	bool power_save_set;
     74 	wlan_client_rt_hdl wifi_rt_hdl[0]; /* depends on number of tx properties */
     75 }ipa_wlan_client;
     76 
     77 /* wlan iface */
     78 class IPACM_Wlan : public IPACM_Lan
     79 {
     80 
     81 public:
     82 
     83 	IPACM_Wlan(int iface_index);
     84 	virtual ~IPACM_Wlan(void);
     85 
     86 	static int total_num_wifi_clients;
     87 
     88 	void event_callback(ipa_cm_event_id event, void *data);
     89 
     90 	bool is_guest_ap();
     91 
     92 private:
     93 
     94 	bool m_is_guest_ap;
     95 
     96 	/* handle wlan access mode switch in ethernet bridging*/
     97 	void eth_bridge_handle_wlan_mode_switch();
     98 
     99 
    100 	int wlan_client_len;
    101 	ipa_wlan_client *wlan_client;
    102 
    103 	int header_name_count;
    104 	uint32_t num_wifi_client;
    105 
    106 	int wlan_ap_index;
    107 
    108 	static int num_wlan_ap_iface;
    109 
    110 	NatApp *Nat_App;
    111 
    112 	inline ipa_wlan_client* get_client_memptr(ipa_wlan_client *param, int cnt)
    113 	{
    114 	    char *ret = ((char *)param) + (wlan_client_len * cnt);
    115 		return (ipa_wlan_client *)ret;
    116 	}
    117 
    118 	inline int get_wlan_client_index(uint8_t *mac_addr)
    119 	{
    120 		int cnt;
    121 		int num_wifi_client_tmp = num_wifi_client;
    122 
    123 		IPACMDBG_H("Passed MAC %02x:%02x:%02x:%02x:%02x:%02x\n",
    124 						 mac_addr[0], mac_addr[1], mac_addr[2],
    125 						 mac_addr[3], mac_addr[4], mac_addr[5]);
    126 
    127 		for(cnt = 0; cnt < num_wifi_client_tmp; cnt++)
    128 		{
    129 			IPACMDBG_H("stored MAC %02x:%02x:%02x:%02x:%02x:%02x\n",
    130 							 get_client_memptr(wlan_client, cnt)->mac[0],
    131 							 get_client_memptr(wlan_client, cnt)->mac[1],
    132 							 get_client_memptr(wlan_client, cnt)->mac[2],
    133 							 get_client_memptr(wlan_client, cnt)->mac[3],
    134 							 get_client_memptr(wlan_client, cnt)->mac[4],
    135 							 get_client_memptr(wlan_client, cnt)->mac[5]);
    136 
    137 			if(memcmp(get_client_memptr(wlan_client, cnt)->mac,
    138 								mac_addr,
    139 								sizeof(get_client_memptr(wlan_client, cnt)->mac)) == 0)
    140 			{
    141 				IPACMDBG_H("Matched client index: %d\n", cnt);
    142 				return cnt;
    143 			}
    144 		}
    145 
    146 		return IPACM_INVALID_INDEX;
    147 	}
    148 
    149 	inline int delete_default_qos_rtrules(int clt_indx, ipa_ip_type iptype)
    150 	{
    151 		uint32_t tx_index;
    152 		uint32_t rt_hdl;
    153 		int num_v6;
    154 
    155 		if(iptype == IPA_IP_v4)
    156 		{
    157 		     for(tx_index = 0; tx_index < iface_query->num_tx_props; tx_index++)
    158 		     {
    159 		        if((tx_prop->tx[tx_index].ip == IPA_IP_v4) && (get_client_memptr(wlan_client, clt_indx)->route_rule_set_v4==true)) /* for ipv4 */
    160 			{
    161 				IPACMDBG_H("Delete client index %d ipv4 Qos rules for tx:%d \n",clt_indx,tx_index);
    162 				rt_hdl = get_client_memptr(wlan_client, clt_indx)->wifi_rt_hdl[tx_index].wifi_rt_rule_hdl_v4;
    163 
    164 				if(m_routing.DeleteRoutingHdl(rt_hdl, IPA_IP_v4) == false)
    165 				{
    166 					return IPACM_FAILURE;
    167 				}
    168 			}
    169 		     } /* end of for loop */
    170 
    171 		     /* clean the 4 Qos ipv4 RT rules for client:clt_indx */
    172 		     if(get_client_memptr(wlan_client, clt_indx)->route_rule_set_v4==true) /* for ipv4 */
    173 		     {
    174 				get_client_memptr(wlan_client, clt_indx)->route_rule_set_v4 = false;
    175 		     }
    176 		}
    177 
    178 		if(iptype == IPA_IP_v6)
    179 		{
    180 		    for(tx_index = 0; tx_index < iface_query->num_tx_props; tx_index++)
    181 		    {
    182 
    183 				if((tx_prop->tx[tx_index].ip == IPA_IP_v6) && (get_client_memptr(wlan_client, clt_indx)->route_rule_set_v6 != 0)) /* for ipv6 */
    184 				{
    185 					for(num_v6 =0;num_v6 < get_client_memptr(wlan_client, clt_indx)->route_rule_set_v6;num_v6++)
    186 					{
    187 						IPACMDBG_H("Delete client index %d ipv6 Qos rules for %d-st ipv6 for tx:%d\n", clt_indx,num_v6,tx_index);
    188 						rt_hdl = get_client_memptr(wlan_client, clt_indx)->wifi_rt_hdl[tx_index].wifi_rt_rule_hdl_v6[num_v6];
    189 						if(m_routing.DeleteRoutingHdl(rt_hdl, IPA_IP_v6) == false)
    190 						{
    191 							return IPACM_FAILURE;
    192 						}
    193 
    194 						rt_hdl = get_client_memptr(wlan_client, clt_indx)->wifi_rt_hdl[tx_index].wifi_rt_rule_hdl_v6_wan[num_v6];
    195 						if(m_routing.DeleteRoutingHdl(rt_hdl, IPA_IP_v6) == false)
    196 						{
    197 							return IPACM_FAILURE;
    198 						}
    199 					}
    200 
    201 				}
    202 			} /* end of for loop */
    203 
    204 		    /* clean the 4 Qos ipv6 RT rules for client:clt_indx */
    205 		    if(get_client_memptr(wlan_client, clt_indx)->route_rule_set_v6 != 0) /* for ipv6 */
    206 		    {
    207 		                 get_client_memptr(wlan_client, clt_indx)->route_rule_set_v6 = 0;
    208                     }
    209 		}
    210 
    211 		return IPACM_SUCCESS;
    212 	}
    213 
    214 	/* for handle wifi client initial,copy all partial headers (tx property) */
    215 	int handle_wlan_client_init_ex(ipacm_event_data_wlan_ex *data);
    216 
    217 	/*handle wifi client */
    218 	int handle_wlan_client_ipaddr(ipacm_event_data_all *data);
    219 
    220 	/*handle wifi client routing rule*/
    221 	int handle_wlan_client_route_rule(uint8_t *mac_addr, ipa_ip_type iptype);
    222 
    223 	/*handle wifi client power-save mode*/
    224 	int handle_wlan_client_pwrsave(uint8_t *mac_addr);
    225 
    226 	/*handle wifi client del mode*/
    227 	int handle_wlan_client_down_evt(uint8_t *mac_addr);
    228 
    229 	/*handle wlan iface down event*/
    230 	int handle_down_evt();
    231 
    232 	/*handle reset wifi-client rt-rules */
    233 	int handle_wlan_client_reset_rt(ipa_ip_type iptype);
    234 
    235 	void handle_SCC_MCC_switch(ipa_ip_type);
    236 
    237 };
    238 
    239 
    240 #endif /* IPACM_WLAN_H */
    241