1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
|
/*
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
{
ipacm_event_data_wlan_ex* p_hdr_info;
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;
/* wlan iface */
class IPACM_Wlan : public IPACM_Lan
{
public:
IPACM_Wlan(int iface_index);
virtual ~IPACM_Wlan(void);
static int total_num_wifi_clients;
void event_callback(ipa_cm_event_id event,
void *data);
virtual int add_lan2lan_hdr(ipa_ip_type iptype, uint8_t* src_mac, uint8_t* dst_mac, uint32_t* hdr_hdl);
private:
eth_bridge_client_flt_info eth_bridge_lan_client_flt_info[IPA_LAN_TO_LAN_MAX_LAN_CLIENT];
int lan_client_flt_info_count;
static lan2lan_flt_rule_hdl self_client_flt_rule_hdl_v4[IPA_LAN_TO_LAN_MAX_WLAN_CLIENT];
static lan2lan_flt_rule_hdl self_client_flt_rule_hdl_v6[IPA_LAN_TO_LAN_MAX_WLAN_CLIENT];
static lan2lan_flt_rule_hdl lan_client_flt_rule_hdl_v4[IPA_LAN_TO_LAN_MAX_LAN_CLIENT];
static lan2lan_flt_rule_hdl lan_client_flt_rule_hdl_v6[IPA_LAN_TO_LAN_MAX_LAN_CLIENT];
bool is_guest_ap;
eth_bridge_client_rt_info* eth_bridge_wlan_client_rt_from_lan_info_v4;
int wlan_client_rt_from_lan_info_count_v4;
eth_bridge_client_rt_info* eth_bridge_wlan_client_rt_from_lan_info_v6;
int wlan_client_rt_from_lan_info_count_v6;
eth_bridge_client_rt_info* eth_bridge_wlan_client_rt_from_wlan_info_v4;
int wlan_client_rt_from_wlan_info_count_v4;
eth_bridge_client_rt_info* eth_bridge_wlan_client_rt_from_wlan_info_v6;
int wlan_client_rt_from_wlan_info_count_v6;
int eth_bridge_install_wlan_guest_ap_ipv6_flt_rule();
virtual int eth_bridge_handle_dummy_wlan_client_flt_rule(ipa_ip_type iptype);
virtual int eth_bridge_handle_dummy_lan_client_flt_rule(ipa_ip_type iptype);
int eth_bridge_add_lan_client_flt_rule(uint8_t* mac, ipa_ip_type iptype);
int eth_bridge_del_lan_client_flt_rule(uint8_t* mac);
int eth_bridge_add_self_client_flt_rule(uint8_t* mac, ipa_ip_type iptype);
int eth_bridge_del_self_client_flt_rule(uint8_t* mac);
virtual int eth_bridge_install_cache_wlan_client_flt_rule(ipa_ip_type iptype);
virtual int eth_bridge_install_cache_lan_client_flt_rule(ipa_ip_type iptype);
int eth_bridge_add_wlan_client_rt_rule(uint8_t* mac, eth_bridge_src_iface src, ipa_ip_type iptype);
int eth_bridge_del_wlan_client_rt_rule(uint8_t* mac, eth_bridge_src_iface src);
eth_bridge_client_rt_info* eth_bridge_get_client_rt_info_ptr(uint8_t index, eth_bridge_src_iface src, ipa_ip_type iptype);
void eth_bridge_add_wlan_client(uint8_t* mac, int if_num);
void eth_bridge_del_wlan_client(uint8_t* mac);
int wlan_client_len;
ipa_wlan_client *wlan_client;
int header_name_count;
int num_wifi_client;
int wlan_ap_index;
static uint32_t* dummy_flt_rule_hdl_v4;
static uint32_t* dummy_flt_rule_hdl_v6;
static int num_wlan_ap_iface;
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_H("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_H("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_H("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_H("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_H("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;
}
/* for handle wifi client initial,copy all partial headers (tx property) */
int handle_wlan_client_init_ex(ipacm_event_data_wlan_ex *data);
/*handle lan2lan internal mesg posting*/
int handle_lan2lan_msg_post(uint8_t *mac_addr, ipa_cm_event_id event, ipa_ip_type iptype);
/*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);
/*handle wlan iface down event*/
int handle_down_evt();
/* add dummy filtering rules for WLAN AP-AP mode support */
void add_dummy_flt_rule();
/* install dummy filtering rules for WLAN AP-AP mode support */
int install_dummy_flt_rule(ipa_ip_type iptype, int num_rule);
/* delete dummy flt rule for WLAN AP-AP mode support*/
void del_dummy_flt_rule();
/*Configure the initial filter rules */
virtual int init_fl_rule(ipa_ip_type iptype);
virtual int add_dummy_lan2lan_flt_rule(ipa_ip_type iptype);
virtual int add_dummy_private_subnet_flt_rule(ipa_ip_type iptype);
/*configure private subnet filter rules*/
virtual int handle_private_subnet(ipa_ip_type iptype);
/* install UL filter rule from Q6 */
virtual int handle_uplink_filter_rule(ipacm_ext_prop* prop, ipa_ip_type iptype, uint8_t xlat_mux_id);
/* install TCP control filter rules */
virtual void install_tcp_ctl_flt_rule(ipa_ip_type iptype);
/*handle reset wifi-client rt-rules */
int handle_wlan_client_reset_rt(ipa_ip_type iptype);
void handle_SCC_MCC_switch(ipa_ip_type);
void eth_bridge_handle_wlan_SCC_MCC_switch(ipa_ip_type iptype);
int eth_bridge_modify_wlan_client_flt_rule(uint8_t* mac, eth_bridge_dst_iface dst_iface, ipa_ip_type iptype);
int eth_bridge_modify_wlan_rt_rule(uint8_t* mac, eth_bridge_src_iface src_iface, ipa_ip_type iptyp);
/*handle wlan access mode switch */
void eth_bridge_handle_wlan_mode_switch();
virtual int install_ipv6_prefix_flt_rule(uint32_t* prefix);
virtual void delete_ipv6_prefix_flt_rule();
};
#endif /* IPACM_WLAN_H */
|