1 /* Copyright (c) 2013-2019, The Linux Foundation. All rights reserved.
2  *
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License version 2 and
5  * only version 2 as published by the Free Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  */
12 
13 #ifndef _RMNET_IPA_FD_IOCTL_H
14 #define _RMNET_IPA_FD_IOCTL_H
15 
16 #include <linux/ioctl.h>
17 #include <linux/ipa_qmi_service_v01.h>
18 #include <linux/msm_ipa.h>
19 
20 /**
21  * unique magic number of the IPA_WAN device
22  */
23 #define WAN_IOC_MAGIC 0x69
24 
25 #define WAN_IOCTL_ADD_FLT_RULE		0
26 #define WAN_IOCTL_ADD_FLT_INDEX		1
27 #define WAN_IOCTL_VOTE_FOR_BW_MBPS	2
28 #define WAN_IOCTL_POLL_TETHERING_STATS  3
29 #define WAN_IOCTL_SET_DATA_QUOTA        4
30 #define WAN_IOCTL_SET_TETHER_CLIENT_PIPE 5
31 #define WAN_IOCTL_QUERY_TETHER_STATS     6
32 #define WAN_IOCTL_RESET_TETHER_STATS     7
33 #define WAN_IOCTL_QUERY_DL_FILTER_STATS  8
34 #define WAN_IOCTL_ADD_FLT_RULE_EX        9
35 #define WAN_IOCTL_QUERY_TETHER_STATS_ALL  10
36 #define WAN_IOCTL_NOTIFY_WAN_STATE  11
37 #define WAN_IOCTL_ADD_UL_FLT_RULE          12
38 #define WAN_IOCTL_ENABLE_PER_CLIENT_STATS    13
39 #define WAN_IOCTL_QUERY_PER_CLIENT_STATS     14
40 #define WAN_IOCTL_SET_LAN_CLIENT_INFO        15
41 #define WAN_IOCTL_CLEAR_LAN_CLIENT_INFO      16
42 #define WAN_IOCTL_SEND_LAN_CLIENT_MSG        17
43 #define WAN_IOCTL_ADD_OFFLOAD_CONNECTION     18
44 #define WAN_IOCTL_RMV_OFFLOAD_CONNECTION     19
45 
46 /* User space may not have this defined. */
47 #ifndef IFNAMSIZ
48 #define IFNAMSIZ 16
49 #endif
50 
51 /**
52  * struct wan_ioctl_poll_tethering_stats - structure used for
53  *                                         WAN_IOCTL_POLL_TETHERING_STATS IOCTL.
54  *
55  * @polling_interval_secs: Polling interval in seconds.
56  * @reset_stats:           Indicate whether to reset the stats (use 1) or not.
57  *
58  * The structure to be used by the user space in order to request for the
59  * tethering stats to be polled. Setting the interval to 0 indicates to stop
60  * the polling process.
61  */
62 struct wan_ioctl_poll_tethering_stats {
63 	uint64_t polling_interval_secs;
64 	uint8_t  reset_stats;
65 };
66 
67 /**
68  * struct wan_ioctl_set_data_quota - structure used for
69  *                                   WAN_IOCTL_SET_DATA_QUOTA IOCTL.
70  *
71  * @interface_name:  Name of the interface on which to set the quota.
72  * @quota_mbytes:    Quota (in Mbytes) for the above interface.
73  * @set_quota:       Indicate whether to set the quota (use 1) or
74  *                   unset the quota.
75  *
76  * The structure to be used by the user space in order to request
77  * a quota to be set on a specific interface (by specifying its name).
78  */
79 struct wan_ioctl_set_data_quota {
80 	char     interface_name[IFNAMSIZ];
81 	uint64_t quota_mbytes;
82 	uint8_t  set_quota;
83 };
84 
85 struct wan_ioctl_set_tether_client_pipe {
86 	/* enum of tether interface */
87 	enum ipacm_client_enum ipa_client;
88 	uint8_t reset_client;
89 	uint32_t ul_src_pipe_len;
90 	uint32_t ul_src_pipe_list[QMI_IPA_MAX_PIPES_V01];
91 	uint32_t dl_dst_pipe_len;
92 	uint32_t dl_dst_pipe_list[QMI_IPA_MAX_PIPES_V01];
93 };
94 
95 struct wan_ioctl_query_tether_stats {
96 	/* Name of the upstream interface */
97 	char upstreamIface[IFNAMSIZ];
98 	/* Name of the tethered interface */
99 	char tetherIface[IFNAMSIZ];
100 	/* enum of tether interface */
101 	enum ipacm_client_enum ipa_client;
102 	uint64_t ipv4_tx_packets;
103 	uint64_t ipv4_tx_bytes;
104 	uint64_t ipv4_rx_packets;
105 	uint64_t ipv4_rx_bytes;
106 	uint64_t ipv6_tx_packets;
107 	uint64_t ipv6_tx_bytes;
108 	uint64_t ipv6_rx_packets;
109 	uint64_t ipv6_rx_bytes;
110 };
111 
112 struct wan_ioctl_query_tether_stats_all {
113 	/* Name of the upstream interface */
114 	char upstreamIface[IFNAMSIZ];
115 	/* enum of tether interface */
116 	enum ipacm_client_enum ipa_client;
117 	uint8_t reset_stats;
118 	uint64_t tx_bytes;
119 	uint64_t rx_bytes;
120 };
121 
122 struct wan_ioctl_reset_tether_stats {
123 	/* Name of the upstream interface, not support now */
124 	char upstreamIface[IFNAMSIZ];
125 	/* Indicate whether to reset the stats (use 1) or not */
126 	uint8_t reset_stats;
127 };
128 
129 struct wan_ioctl_query_dl_filter_stats {
130 	/* Indicate whether to reset the filter stats (use 1) or not*/
131 	uint8_t reset_stats;
132 	/* Modem response QMI */
133 	struct ipa_get_data_stats_resp_msg_v01 stats_resp;
134 	/* provide right index to 1st firewall rule */
135 	uint32_t index;
136 };
137 
138 struct wan_ioctl_notify_wan_state {
139 	uint8_t up;
140 };
141 struct wan_ioctl_send_lan_client_msg {
142 	/* Lan client info. */
143 	struct ipa_lan_client_msg lan_client;
144 	/* Event to indicate whether client is
145 	 * connected or disconnected.
146 	 */
147 	enum ipa_per_client_stats_event client_event;
148 };
149 
150 struct wan_ioctl_lan_client_info {
151 	/* Device type of the client. */
152 	enum ipacm_per_client_device_type device_type;
153 	/* MAC Address of the client. */
154 	uint8_t mac[IPA_MAC_ADDR_SIZE];
155 	/* Init client. */
156 	uint8_t client_init;
157 	/* Client Index */
158 	int8_t client_idx;
159 	/* Header length of the client. */
160 	uint8_t hdr_len;
161 	/* Source pipe of the lan client. */
162 	enum ipa_client_type ul_src_pipe;
163 	/* Counter indices for h/w fnr stats */
164 #define IPA_HW_FNR_STATS
165 	uint8_t ul_cnt_idx;
166 	uint8_t dl_cnt_idx;
167 };
168 
169 struct wan_ioctl_per_client_info {
170 	/* MAC Address of the client. */
171 	uint8_t mac[IPA_MAC_ADDR_SIZE];
172 	/* Ipv4 UL traffic bytes. */
173 	uint64_t ipv4_tx_bytes;
174 	/* Ipv4 DL traffic bytes. */
175 	uint64_t ipv4_rx_bytes;
176 	/* Ipv6 UL traffic bytes. */
177 	uint64_t ipv6_tx_bytes;
178 	/* Ipv6 DL traffic bytes. */
179 	uint64_t ipv6_rx_bytes;
180 };
181 
182 struct wan_ioctl_query_per_client_stats {
183 	/* Device type of the client. */
184 	enum ipacm_per_client_device_type device_type;
185 	/* Indicate whether to reset the stats (use 1) or not */
186 	uint8_t reset_stats;
187 	/* Indicates whether client is disconnected. */
188 	uint8_t disconnect_clnt;
189 	/* Number of clients. */
190 	uint8_t num_clients;
191 	/* Client information. */
192 	struct wan_ioctl_per_client_info
193 		client_info[IPA_MAX_NUM_HW_PATH_CLIENTS];
194 };
195 
196 #define WAN_IOC_ADD_FLT_RULE _IOWR(WAN_IOC_MAGIC, \
197 		WAN_IOCTL_ADD_FLT_RULE, \
198 		struct ipa_install_fltr_rule_req_msg_v01 *)
199 
200 #define WAN_IOC_ADD_FLT_RULE_INDEX _IOWR(WAN_IOC_MAGIC, \
201 		WAN_IOCTL_ADD_FLT_INDEX, \
202 		struct ipa_fltr_installed_notif_req_msg_v01 *)
203 
204 #define WAN_IOC_VOTE_FOR_BW_MBPS _IOWR(WAN_IOC_MAGIC, \
205 		WAN_IOCTL_VOTE_FOR_BW_MBPS, \
206 		uint32_t *)
207 
208 #define WAN_IOC_POLL_TETHERING_STATS _IOWR(WAN_IOC_MAGIC, \
209 		WAN_IOCTL_POLL_TETHERING_STATS, \
210 		struct wan_ioctl_poll_tethering_stats *)
211 
212 #define WAN_IOC_SET_DATA_QUOTA _IOWR(WAN_IOC_MAGIC, \
213 		WAN_IOCTL_SET_DATA_QUOTA, \
214 		struct wan_ioctl_set_data_quota *)
215 
216 #define WAN_IOC_SET_TETHER_CLIENT_PIPE _IOWR(WAN_IOC_MAGIC, \
217 		WAN_IOCTL_SET_TETHER_CLIENT_PIPE, \
218 		struct wan_ioctl_set_tether_client_pipe *)
219 
220 #define WAN_IOC_QUERY_TETHER_STATS _IOWR(WAN_IOC_MAGIC, \
221 		WAN_IOCTL_QUERY_TETHER_STATS, \
222 		struct wan_ioctl_query_tether_stats *)
223 
224 #define WAN_IOC_RESET_TETHER_STATS _IOWR(WAN_IOC_MAGIC, \
225 		WAN_IOCTL_RESET_TETHER_STATS, \
226 		struct wan_ioctl_reset_tether_stats *)
227 
228 #define WAN_IOC_QUERY_DL_FILTER_STATS _IOWR(WAN_IOC_MAGIC, \
229 		WAN_IOCTL_QUERY_DL_FILTER_STATS, \
230 		struct wan_ioctl_query_dl_filter_stats *)
231 
232 #define WAN_IOC_ADD_FLT_RULE_EX _IOWR(WAN_IOC_MAGIC, \
233 		WAN_IOCTL_ADD_FLT_RULE_EX, \
234 		struct ipa_install_fltr_rule_req_ex_msg_v01 *)
235 
236 #define WAN_IOC_QUERY_TETHER_STATS_ALL _IOWR(WAN_IOC_MAGIC, \
237 		WAN_IOCTL_QUERY_TETHER_STATS_ALL, \
238 		struct wan_ioctl_query_tether_stats_all *)
239 
240 #define WAN_IOC_NOTIFY_WAN_STATE _IOWR(WAN_IOC_MAGIC, \
241 		WAN_IOCTL_NOTIFY_WAN_STATE, \
242 		struct wan_ioctl_notify_wan_state *)
243 
244 #define WAN_IOC_ADD_UL_FLT_RULE _IOWR(WAN_IOC_MAGIC, \
245 		WAN_IOCTL_ADD_UL_FLT_RULE, \
246 		struct ipa_configure_ul_firewall_rules_req_msg_v01 *)
247 
248 #define WAN_IOC_ENABLE_PER_CLIENT_STATS _IOWR(WAN_IOC_MAGIC, \
249 		WAN_IOCTL_ENABLE_PER_CLIENT_STATS, \
250 		bool *)
251 
252 #define WAN_IOC_QUERY_PER_CLIENT_STATS _IOWR(WAN_IOC_MAGIC, \
253 		WAN_IOCTL_QUERY_PER_CLIENT_STATS, \
254 		struct wan_ioctl_query_per_client_stats *)
255 
256 #define WAN_IOC_SET_LAN_CLIENT_INFO _IOWR(WAN_IOC_MAGIC, \
257 			WAN_IOCTL_SET_LAN_CLIENT_INFO, \
258 			struct wan_ioctl_lan_client_info *)
259 
260 #define WAN_IOC_SEND_LAN_CLIENT_MSG _IOWR(WAN_IOC_MAGIC, \
261 				WAN_IOCTL_SEND_LAN_CLIENT_MSG, \
262 				struct wan_ioctl_send_lan_client_msg *)
263 
264 #define WAN_IOC_CLEAR_LAN_CLIENT_INFO _IOWR(WAN_IOC_MAGIC, \
265 			WAN_IOCTL_CLEAR_LAN_CLIENT_INFO, \
266 			struct wan_ioctl_lan_client_info *)
267 
268 #define WAN_IOC_ADD_OFFLOAD_CONNECTION _IOWR(WAN_IOC_MAGIC, \
269 		WAN_IOCTL_ADD_OFFLOAD_CONNECTION, \
270 		struct ipa_add_offload_connection_req_msg_v01 *)
271 
272 #define WAN_IOC_RMV_OFFLOAD_CONNECTION _IOWR(WAN_IOC_MAGIC, \
273 		WAN_IOCTL_RMV_OFFLOAD_CONNECTION, \
274 		struct ipa_remove_offload_connection_req_msg_v01 *)
275 #endif /* _RMNET_IPA_FD_IOCTL_H */
276