1  /*
2  * Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 and
6  * only version 2 as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  *
13  * RMNET Data configuration specification
14  */
15 
16 #ifndef _RMNET_DATA_H_
17 #define _RMNET_DATA_H_
18 
19 /* ***************** Constants ********************************************** */
20 #define RMNET_LOCAL_LOGICAL_ENDPOINT -1
21 
22 #define RMNET_EGRESS_FORMAT__RESERVED__         (1<<0)
23 #define RMNET_EGRESS_FORMAT_MAP                 (1<<1)
24 #define RMNET_EGRESS_FORMAT_AGGREGATION         (1<<2)
25 #define RMNET_EGRESS_FORMAT_MUXING              (1<<3)
26 #define RMNET_EGRESS_FORMAT_MAP_CKSUMV3         (1<<4)
27 
28 #define RMNET_INGRESS_FIX_ETHERNET              (1<<0)
29 #define RMNET_INGRESS_FORMAT_MAP                (1<<1)
30 #define RMNET_INGRESS_FORMAT_DEAGGREGATION      (1<<2)
31 #define RMNET_INGRESS_FORMAT_DEMUXING           (1<<3)
32 #define RMNET_INGRESS_FORMAT_MAP_COMMANDS       (1<<4)
33 #define RMNET_INGRESS_FORMAT_MAP_CKSUMV3        (1<<5)
34 
35 /* ***************** Netlink API ******************************************** */
36 #define RMNET_NETLINK_PROTO 31
37 #define RMNET_MAX_STR_LEN  16
38 #define RMNET_NL_DATA_MAX_LEN 64
39 
40 #define RMNET_NETLINK_MSG_COMMAND    0
41 #define RMNET_NETLINK_MSG_RETURNCODE 1
42 #define RMNET_NETLINK_MSG_RETURNDATA 2
43 
44 struct rmnet_nl_msg_s {
45 	uint16_t reserved;
46 	uint16_t message_type;
47 	uint16_t reserved2:14;
48 	uint16_t crd:2;
49 	union {
50 		uint16_t arg_length;
51 		uint16_t return_code;
52 	};
53 	union {
54 		uint8_t data[RMNET_NL_DATA_MAX_LEN];
55 		struct {
56 			uint8_t  dev[RMNET_MAX_STR_LEN];
57 			uint32_t flags;
58 			uint16_t agg_size;
59 			uint16_t agg_count;
60 			uint8_t  tail_spacing;
61 		} data_format;
62 		struct {
63 			uint8_t dev[RMNET_MAX_STR_LEN];
64 			int32_t ep_id;
65 			uint8_t operating_mode;
66 			uint8_t next_dev[RMNET_MAX_STR_LEN];
67 		} local_ep_config;
68 		struct {
69 			uint32_t id;
70 			uint8_t  vnd_name[RMNET_MAX_STR_LEN];
71 		} vnd;
72 		struct {
73 			uint32_t id;
74 			uint32_t map_flow_id;
75 			uint32_t tc_flow_id;
76 		} flow_control;
77 	};
78 };
79 
80 enum rmnet_netlink_message_types_e {
81 	/*
82 	 * RMNET_NETLINK_ASSOCIATE_NETWORK_DEVICE - Register RMNET data driver
83 	 *                                          on a particular device.
84 	 * Args: char[] dev_name: Null terminated ASCII string, max length: 15
85 	 * Returns: status code
86 	 */
87 	RMNET_NETLINK_ASSOCIATE_NETWORK_DEVICE,
88 
89 	/*
90 	 * RMNET_NETLINK_UNASSOCIATE_NETWORK_DEVICE - Unregister RMNET data
91 	 *                                            driver on a particular
92 	 *                                            device.
93 	 * Args: char[] dev_name: Null terminated ASCII string, max length: 15
94 	 * Returns: status code
95 	 */
96 	RMNET_NETLINK_UNASSOCIATE_NETWORK_DEVICE,
97 
98 	/*
99 	 * RMNET_NETLINK_GET_NETWORK_DEVICE_ASSOCIATED - Get if RMNET data
100 	 *                                            driver is registered on a
101 	 *                                            particular device.
102 	 * Args: char[] dev_name: Null terminated ASCII string, max length: 15
103 	 * Returns: 1 if registered, 0 if not
104 	 */
105 	RMNET_NETLINK_GET_NETWORK_DEVICE_ASSOCIATED,
106 
107 	/*
108 	 * RMNET_NETLINK_SET_LINK_EGRESS_DATA_FORMAT - Sets the egress data
109 	 *                                             format for a particular
110 	 *                                             link.
111 	 * Args: uint32_t egress_flags
112 	 *       char[] dev_name: Null terminated ASCII string, max length: 15
113 	 * Returns: status code
114 	 */
115 	RMNET_NETLINK_SET_LINK_EGRESS_DATA_FORMAT,
116 
117 	/*
118 	 * RMNET_NETLINK_GET_LINK_EGRESS_DATA_FORMAT - Gets the egress data
119 	 *                                             format for a particular
120 	 *                                             link.
121 	 * Args: char[] dev_name: Null terminated ASCII string, max length: 15
122 	 * Returns: 4-bytes data: uint32_t egress_flags
123 	 */
124 	RMNET_NETLINK_GET_LINK_EGRESS_DATA_FORMAT,
125 
126 	/*
127 	 * RMNET_NETLINK_SET_LINK_INGRESS_DATA_FORMAT - Sets the ingress data
128 	 *                                              format for a particular
129 	 *                                              link.
130 	 * Args: uint32_t ingress_flags
131 	 *       char[] dev_name: Null terminated ASCII string, max length: 15
132 	 * Returns: status code
133 	 */
134 	RMNET_NETLINK_SET_LINK_INGRESS_DATA_FORMAT,
135 
136 	/*
137 	 * RMNET_NETLINK_GET_LINK_INGRESS_DATA_FORMAT - Gets the ingress data
138 	 *                                              format for a particular
139 	 *                                              link.
140 	 * Args: char[] dev_name: Null terminated ASCII string, max length: 15
141 	 * Returns: 4-bytes data: uint32_t ingress_flags
142 	 */
143 	RMNET_NETLINK_GET_LINK_INGRESS_DATA_FORMAT,
144 
145 	/*
146 	 * RMNET_NETLINK_SET_LOGICAL_EP_CONFIG - Sets the logical endpoint
147 	 *                                       configuration for a particular
148 	 *                                       link.
149 	 * Args: char[] dev_name: Null terminated ASCII string, max length: 15
150 	 *     int32_t logical_ep_id, valid values are -1 through 31
151 	 *     uint8_t rmnet_mode: one of none, vnd, bridged
152 	 *     char[] egress_dev_name: Egress device if operating in bridge mode
153 	 * Returns: status code
154 	 */
155 	RMNET_NETLINK_SET_LOGICAL_EP_CONFIG,
156 
157 	/*
158 	 * RMNET_NETLINK_UNSET_LOGICAL_EP_CONFIG - Un-sets the logical endpoint
159 	 *                                       configuration for a particular
160 	 *                                       link.
161 	 * Args: char[] dev_name: Null terminated ASCII string, max length: 15
162 	 *       int32_t logical_ep_id, valid values are -1 through 31
163 	 * Returns: status code
164 	 */
165 	RMNET_NETLINK_UNSET_LOGICAL_EP_CONFIG,
166 
167 	/*
168 	 * RMNET_NETLINK_GET_LOGICAL_EP_CONFIG - Gets the logical endpoint
169 	 *                                       configuration for a particular
170 	 *                                       link.
171 	 * Args: char[] dev_name: Null terminated ASCII string, max length: 15
172 	 *        int32_t logical_ep_id, valid values are -1 through 31
173 	 * Returns: uint8_t rmnet_mode: one of none, vnd, bridged
174 	 * char[] egress_dev_name: Egress device
175 	 */
176 	RMNET_NETLINK_GET_LOGICAL_EP_CONFIG,
177 
178 	/*
179 	 * RMNET_NETLINK_NEW_VND - Creates a new virtual network device node
180 	 * Args: int32_t node number
181 	 * Returns: status code
182 	 */
183 	RMNET_NETLINK_NEW_VND,
184 
185 	/*
186 	 * RMNET_NETLINK_NEW_VND_WITH_PREFIX - Creates a new virtual network
187 	 *                                     device node with the specified
188 	 *                                     prefix for the device name
189 	 * Args: int32_t node number
190 	 *       char[] vnd_name - Use as prefix
191 	 * Returns: status code
192 	 */
193 	RMNET_NETLINK_NEW_VND_WITH_PREFIX,
194 
195 	/*
196 	 * RMNET_NETLINK_GET_VND_NAME - Gets the string name of a VND from ID
197 	 * Args: int32_t node number
198 	 * Returns: char[] vnd_name
199 	 */
200 	RMNET_NETLINK_GET_VND_NAME,
201 
202 	/*
203 	 * RMNET_NETLINK_FREE_VND - Removes virtual network device node
204 	 * Args: int32_t node number
205 	 * Returns: status code
206 	 */
207 	RMNET_NETLINK_FREE_VND,
208 
209 	/*
210 	 * RMNET_NETLINK_ADD_VND_TC_FLOW - Add flow control handle on VND
211 	 * Args: int32_t node number
212 	 *       uint32_t MAP Flow Handle
213 	 *       uint32_t TC Flow Handle
214 	 * Returns: status code
215 	 */
216 	RMNET_NETLINK_ADD_VND_TC_FLOW,
217 
218 	/*
219 	 * RMNET_NETLINK_DEL_VND_TC_FLOW - Removes flow control handle on VND
220 	 * Args: int32_t node number
221 	 *       uint32_t MAP Flow Handle
222 	 * Returns: status code
223 	 */
224 	RMNET_NETLINK_DEL_VND_TC_FLOW
225 };
226 
227 enum rmnet_config_endpoint_modes_e {
228 	/* Pass the frame up the stack with no modifications to skb->dev      */
229 	RMNET_EPMODE_NONE,
230 	/* Replace skb->dev to a virtual rmnet device and pass up the stack   */
231 	RMNET_EPMODE_VND,
232 	/* Pass the frame directly to another device with dev_queue_xmit().   */
233 	RMNET_EPMODE_BRIDGE,
234 	/* Must be the last item in the list                                  */
235 	RMNET_EPMODE_LENGTH
236 };
237 
238 enum rmnet_config_return_codes_e {
239 	RMNET_CONFIG_OK,
240 	RMNET_CONFIG_UNKNOWN_MESSAGE,
241 	RMNET_CONFIG_UNKNOWN_ERROR,
242 	RMNET_CONFIG_NOMEM,
243 	RMNET_CONFIG_DEVICE_IN_USE,
244 	RMNET_CONFIG_INVALID_REQUEST,
245 	RMNET_CONFIG_NO_SUCH_DEVICE,
246 	RMNET_CONFIG_BAD_ARGUMENTS,
247 	RMNET_CONFIG_BAD_EGRESS_DEVICE,
248 	RMNET_CONFIG_TC_HANDLE_FULL
249 };
250 
251 #endif /* _RMNET_DATA_H_ */
252