blob: 25a1477ce2cd9fd0c686130060507394dc491fef [file] [log] [blame]
Harout Hedeshianb2fc5b12013-09-03 13:49:00 -06001/******************************************************************************
2
3 L I B R M N E T C T L . H
4
Harout Hedeshiana9731652014-01-06 18:00:23 +02005Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
Harout Hedeshianb2fc5b12013-09-03 13:49:00 -06006
7Redistribution and use in source and binary forms, with or without
8modification, are permitted provided that the following conditions are
9met:
10 * Redistributions of source code must retain the above copyright
11 notice, this list of conditions and the following disclaimer.
12 * Redistributions in binary form must reproduce the above
13 copyright notice, this list of conditions and the following
14 disclaimer in the documentation and/or other materials provided
15 with the distribution.
16 * Neither the name of The Linux Foundation nor the names of its
17 contributors may be used to endorse or promote products derived
18 from this software without specific prior written permission.
19
20THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
21WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
23ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
24BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
27BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
29OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
30IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
32******************************************************************************/
33
34/*!
35* @file librmnetctl.h
36* @brief rmnet control API's header file
37*/
38
39#ifndef LIBRMNETCTL_H
40#define LIBRMNETCTL_H
41
42/* RMNET API succeeded */
43#define RMNETCTL_SUCCESS 0
44/* RMNET API encountered an error while executing within the library. Check the
45* error code in this case */
46#define RMNETCTL_LIB_ERR 1
47/* RMNET API encountered an error while executing in the kernel. Check the
48* error code in this case */
49#define RMNETCTL_KERNEL_ERR 2
50/* RMNET API encountered an error because of invalid arguments*/
51#define RMNETCTL_INVALID_ARG 3
52
53/* Flag to associate a network device*/
54#define RMNETCTL_DEVICE_ASSOCIATE 1
55/* Flag to unassociate a network device*/
56#define RMNETCTL_DEVICE_UNASSOCIATE 0
57/* Flag to create a new virtual network device*/
58#define RMNETCTL_NEW_VND 1
59/* Flag to free a new virtual network device*/
60#define RMNETCTL_FREE_VND 0
Harout Hedeshian97a1e982013-11-08 09:28:53 -070061/* Flag to add a new flow*/
62#define RMNETCTL_ADD_FLOW 1
63/* Flag to delete an existing flow*/
64#define RMNETCTL_DEL_FLOW 0
Harout Hedeshianb2fc5b12013-09-03 13:49:00 -060065
66enum rmnetctl_error_codes_e {
67 /* API succeeded. This should always be the first element. */
68 RMNETCTL_API_SUCCESS,
69 /* API failed because not enough memory to create buffer to send
70 * message */
71 RMNETCTL_API_ERR_REQUEST_INVALID,
72 /* API failed because not enough memory to create buffer for the
73 * response message */
74 RMNETCTL_API_ERR_RESPONSE_INVALID,
75 /* API failed because could not send the message to kernel */
76 RMNETCTL_API_ERR_MESSAGE_SEND,
77 /* API failed because could not receive message from the kernel */
78 RMNETCTL_API_ERR_MESSAGE_RECEIVE,
79 /* Invalid process id. So return an error. */
80 RMNETCTL_INIT_ERR_PROCESS_ID,
81 /* Invalid socket descriptor id. So return an error. */
82 RMNETCTL_INIT_ERR_NETLINK_FD,
83 /* Could not bind the socket to the Netlink file descriptor */
84 RMNETCTL_INIT_ERR_BIND,
85 /* Invalid user id. Only root has access to this function. (NA) */
86 RMNETCTL_INIT_ERR_INVALID_USER,
87 /* API failed because the RmNet handle for the transaction was NULL */
88 RMNETCTL_API_ERR_HNDL_INVALID,
89 /* API failed because the request buffer for the transaction was NULL */
90 RMNETCTL_API_ERR_REQUEST_NULL,
91 /* API failed because the response buffer for the transaction was NULL*/
92 RMNETCTL_API_ERR_RESPONSE_NULL,
93 /* API failed because the request and response type do not match*/
94 RMNETCTL_API_ERR_MESSAGE_TYPE,
95 /* API failed because the return type is invalid */
96 RMNETCTL_API_ERR_RETURN_TYPE,
97 /* API failed because the string was truncated */
98 RMNETCTL_API_ERR_STRING_TRUNCATION,
99 /* This should always be the last element */
100 RMNETCTL_API_ERR_ENUM_LENGTH
101};
102
103#define RMNETCTL_ERR_MSG_SIZE 100
104
105/*!
106* @brief Contains a list of error message from API
107*/
108char rmnetctl_error_code_text
109[RMNETCTL_API_ERR_ENUM_LENGTH][RMNETCTL_ERR_MSG_SIZE] = {
110 "ERROR: API succeeded\n",
111 "ERROR: Unable to allocate the buffer to send message\n",
112 "ERROR: Unable to allocate the buffer to receive message\n",
113 "ERROR: Could not send the message to kernel\n",
114 "ERROR: Unable to receive message from the kernel\n",
115 "ERROR: Invalid process id\n",
116 "ERROR: Invalid socket descriptor id\n",
117 "ERROR: Could not bind to netlink socket\n",
118 "ERROR: Only root can access this API\n",
119 "ERROR: RmNet handle for the transaction was NULL\n",
120 "ERROR: Request buffer for the transaction was NULL\n",
121 "ERROR: Response buffer for the transaction was NULL\n",
122 "ERROR: Request and response type do not match\n",
123 "ERROR: Return type is invalid\n",
124 "ERROR: String was truncated\n"
125};
126
127/*===========================================================================
128 DEFINITIONS AND DECLARATIONS
129===========================================================================*/
130typedef struct rmnetctl_hndl_s rmnetctl_hndl_t;
131
132/*!
133* @brief Public API to initialize the RMNET control driver
134* @details Allocates memory for the RmNet handle. Creates and binds to a and
135* netlink socket if successful
136* @param **rmnetctl_hndl_t_val RmNet handle to be initialized
137* @return RMNETCTL_SUCCESS if successful
138* @return RMNETCTL_LIB_ERR if there was a library error. Check error_code
139* @return RMNETCTL_KERNEL_ERR if there was an error in the kernel.
140* Check error_code
141* @return RMNETCTL_INVALID_ARG if invalid arguments were passed to the API
142*/
143int rmnetctl_init(rmnetctl_hndl_t **hndl, uint16_t *error_code);
144
145/*!
146* @brief Public API to clean up the RmNeT control handle
147* @details Close the socket and free the RmNet handle
148* @param *rmnetctl_hndl_t_val RmNet handle to be initialized
149* @return void
150*/
151void rmnetctl_cleanup(rmnetctl_hndl_t *hndl);
152
153/*!
154* @brief Public API to register/unregister a RMNET driver on a particular device
155* @details Message type is RMNET_NETLINK_ASSOCIATE_NETWORK_DEVICE or
156* RMNET_NETLINK_UNASSOCIATE_NETWORK_DEVICE based on the flag for assoc_dev
157* @param *rmnetctl_hndl_t_val RmNet handle for the Netlink message
158* @param dev_name Device on which to register the RmNet driver
159* @param error_code Status code of this operation
160* @param assoc_dev registers the device if RMNETCTL_DEVICE_ASSOCIATE or
161* unregisters the device if RMNETCTL_DEVICE_UNASSOCIATE
162* @return RMNETCTL_SUCCESS if successful
163* @return RMNETCTL_LIB_ERR if there was a library error. Check error_code
164* @return RMNETCTL_KERNEL_ERR if there was an error in the kernel.
165* Check error_code
166* @return RMNETCTL_INVALID_ARG if invalid arguments were passed to the API
167*/
168int rmnet_associate_network_device(rmnetctl_hndl_t *hndl,
169 const char *dev_name,
170 uint16_t *error_code,
171 uint8_t assoc_dev);
172
173/*!
174* @brief Public API to get if a RMNET driver is registered on a particular
175* device
176* @details Message type is RMNET_NETLINK_GET_NETWORK_DEVICE_ASSOCIATED.
177* @param *rmnetctl_hndl_t_val RmNet handle for the Netlink message
178* @param dev_name Device on which to check if the RmNet driver is registered
179* @param register_status 1 if RmNet data driver is registered on a particular
180* device, 0 if not
181* @param error_code Status code of this operation
182* @return RMNETCTL_SUCCESS if successful
183* @return RMNETCTL_LIB_ERR if there was a library error. Check error_code
184* @return RMNETCTL_KERNEL_ERR if there was an error in the kernel.
185* Check error_code
186* @return RMNETCTL_INVALID_ARG if invalid arguments were passed to the API
187*/
188int rmnet_get_network_device_associated(rmnetctl_hndl_t *hndl,
189 const char *dev_name,
190 int *register_status,
191 uint16_t *error_code);
192
193/*!
194* @brief Public API to set the egress data format for a particular link.
195* @details Message type is RMNET_NETLINK_SET_LINK_EGRESS_DATA_FORMAT.
196* @param *rmnetctl_hndl_t_val RmNet handle for the Netlink message
197* @param egress_flags Egress flags to be set on the device
198* @param agg_size Max size of aggregated packets
199* @param agg_count Number of packets to be aggregated
200* @param dev_name Device on which to set the egress data format
201* @param error_code Status code of this operation returned from the kernel
202* @return RMNETCTL_SUCCESS if successful
203* @return RMNETCTL_LIB_ERR if there was a library error. Check error_code
204* @return RMNETCTL_KERNEL_ERR if there was an error in the kernel.
205* Check error_code
206* @return RMNETCTL_INVALID_ARG if invalid arguments were passed to the API
207*/
208int rmnet_set_link_egress_data_format(rmnetctl_hndl_t *hndl,
209 uint32_t egress_flags,
210 uint16_t agg_size,
211 uint16_t agg_count,
212 const char *dev_name,
213 uint16_t *error_code);
214
215/*!
216* @brief Public API to get the egress data format for a particular link.
217* @details Message type is RMNET_NETLINK_GET_LINK_EGRESS_DATA_FORMAT.
218* @param *rmnetctl_hndl_t_val RmNet handle for the Netlink message
219* @param dev_name Device on which to get the egress data format
220* @param egress_flags Egress flags from the device
221* @param agg_count Number of packets to be aggregated
222* @param error_code Status code of this operation returned from the kernel
223* @return RMNETCTL_SUCCESS if successful
224* @return RMNETCTL_LIB_ERR if there was a library error. Check error_code
225* @return RMNETCTL_KERNEL_ERR if there was an error in the kernel.
226* Check error_code
227* @return RMNETCTL_INVALID_ARG if invalid arguments were passed to the API
228*/
229int rmnet_get_link_egress_data_format(rmnetctl_hndl_t *hndl,
230 const char *dev_name,
231 uint32_t *egress_flags,
232 uint16_t *agg_size,
233 uint16_t *agg_count,
234 uint16_t *error_code);
235
236/*!
237* @brief Public API to set the ingress data format for a particular link.
238* @details Message type is RMNET_NETLINK_SET_LINK_INGRESS_DATA_FORMAT.
239* @param *rmnetctl_hndl_t_val RmNet handle for the Netlink message
240* @param ingress_flags Ingress flags from the device
241* @param dev_name Device on which to set the ingress data format
242* @param error_code Status code of this operation returned from the kernel
243* @return RMNETCTL_SUCCESS if successful
244* @return RMNETCTL_LIB_ERR if there was a library error. Check error_code
245* @return RMNETCTL_KERNEL_ERR if there was an error in the kernel.
246* Check error_code
247* @return RMNETCTL_INVALID_ARG if invalid arguments were passed to the API
248*/
249int rmnet_set_link_ingress_data_format(rmnetctl_hndl_t *hndl,
250 uint32_t ingress_flags,
251 const char *dev_name,
252 uint16_t *error_code);
253
254/*!
255* @brief Public API to get the ingress data format for a particular link.
256* @details Message type is RMNET_NETLINK_GET_LINK_INGRESS_DATA_FORMAT.
257* @param *rmnetctl_hndl_t_val RmNet handle for the Netlink message
258* @param dev_name Device on which to get the ingress data format
259* @param ingress_flags Ingress flags from the device
260* @param error_code Status code of this operation returned from the kernel
261* @return RMNETCTL_SUCCESS if successful
262* @return RMNETCTL_LIB_ERR if there was a library error. Check error_code
263* @return RMNETCTL_KERNEL_ERR if there was an error in the kernel.
264* Check error_code
265* @return RMNETCTL_INVALID_ARG if invalid arguments were passed to the API
266*/
267int rmnet_get_link_ingress_data_format(rmnetctl_hndl_t *hndl,
268 const char *dev_name,
269 uint32_t *ingress_flags,
270 uint16_t *error_code);
271
272/*!
273* @brief Public API to set the logical endpoint configuration for a
274* particular link.
275* @details Message type is RMNET_NETLINK_SET_LOGICAL_EP_CONFIG.
276* @param *rmnetctl_hndl_t_val RmNet handle for the Netlink message
277* @param logical_ep_id Logical end point id on which the configuration is to be
278* set
279* @param rmnet_mode RmNet mode to be set on the device
280* @param dev_name Device on which to set the logical end point configuration
281* @param egress_dev_name Egress Device if operating in bridge mode
282* @param error_code Status code of this operation returned from the kernel
283* @return RMNETCTL_SUCCESS if successful
284* @return RMNETCTL_LIB_ERR if there was a library error. Check error_code
285* @return RMNETCTL_KERNEL_ERR if there was an error in the kernel.
286* Check error_code
287* @return RMNETCTL_INVALID_ARG if invalid arguments were passed to the API
288*/
289int rmnet_set_logical_ep_config(rmnetctl_hndl_t *hndl,
290 int32_t ep_id,
291 uint8_t operating_mode,
292 const char *dev_name,
293 const char *next_dev,
294 uint16_t *error_code);
295
296/*!
Harout Hedeshiana9731652014-01-06 18:00:23 +0200297* @brief Public API to un-set the logical endpoint configuration for a
298* particular link.
299* @details Message type is RMNET_NETLINK_UNSET_LOGICAL_EP_CONFIG.
300* @param *rmnetctl_hndl_t_val RmNet handle for the Netlink message
301* @param logical_ep_id Logical end point id on which the configuration is to be
302* un-set
303* @param dev_name Device on which to un-set the logical end point configuration
304* @param error_code Status code of this operation returned from the kernel
305* @return RMNETCTL_SUCCESS if successful
306* @return RMNETCTL_LIB_ERR if there was a library error. Check error_code
307* @return RMNETCTL_KERNEL_ERR if there was an error in the kernel.
308* Check error_code
309* @return RMNETCTL_INVALID_ARG if invalid arguments were passed to the API
310*/
311int rmnet_unset_logical_ep_config(rmnetctl_hndl_t *hndl,
312 int32_t ep_id,
313 const char *dev_name,
314 uint16_t *error_code);
315/*!
Harout Hedeshianb2fc5b12013-09-03 13:49:00 -0600316* @brief Public API to get the logical endpoint configuration for a
317* particular link.
318* @details Message type is RMNET_NETLINK_GET_LOGICAL_EP_CONFIG.
319* @param *rmnetctl_hndl_t_val RmNet handle for the Netlink message
320* @param logical_ep_id Logical end point id from which to get the configuration
321* @param dev_name Device on which to get the logical end point configuration
322* @param rmnet_mode RmNet mode from the device
323* @param egress_dev_name Egress Device if operating in bridge mode
324* @param error_code Status code of this operation returned from the kernel
325* @return RMNETCTL_SUCCESS if successful
326* @return RMNETCTL_LIB_ERR if there was a library error. Check error_code
327* @return RMNETCTL_KERNEL_ERR if there was an error in the kernel.
328* Check error_code
329* @return RMNETCTL_INVALID_ARG if invalid arguments were passed to the API
330*/
331int rmnet_get_logical_ep_config(rmnetctl_hndl_t *hndl,
332 int32_t ep_id,
333 const char *dev_name,
334 uint8_t *operating_mode,
335 char **next_dev,
336 uint16_t *error_code);
337
338/*!
339* @brief Public API to create a new virtual device node
340* @details Message type is RMNET_NETLINK_NEW_VND or
341* RMNETCTL_FREE_VND based on the flag for new_vnd
Harout Hedeshian89a91e22013-10-09 08:59:47 -0600342* @param hndl RmNet handle for the Netlink message
343* @param id Node number to create the virtual network device node
Harout Hedeshianb2fc5b12013-09-03 13:49:00 -0600344* @param error_code Status code of this operation returned from the kernel
345* @param new_vnd creates a new virtual network device if RMNETCTL_NEW_VND or
346* frees the device if RMNETCTL_FREE_VND
347* @return RMNETCTL_SUCCESS if successful
348* @return RMNETCTL_LIB_ERR if there was a library error. Check error_code
349* @return RMNETCTL_KERNEL_ERR if there was an error in the kernel.
350* Check error_code
351* @return RMNETCTL_INVALID_ARG if invalid arguments were passed to the API
352*/
353int rmnet_new_vnd(rmnetctl_hndl_t *hndl,
354 uint32_t id,
355 uint16_t *error_code,
356 uint8_t new_vnd);
357
Harout Hedeshian89a91e22013-10-09 08:59:47 -0600358/*!
359 * @brief Public API to create a new virtual device node with a custom prefix
360 * @details Message type is RMNET_NETLINK_NEW_VND or
361 * RMNETCTL_FREE_VND based on the flag for new_vnd
362 * @param hndl RmNet handle for the Netlink message
363 * @param id Node number to create the virtual network device node
364 * @param error_code Status code of this operation returned from the kernel
365 * @param new_vnd creates a new virtual network device if RMNETCTL_NEW_VND or
366 * frees the device if RMNETCTL_FREE_VND
367 * @param prefix Prefix to be used when naming the network interface
368 * @return RMNETCTL_SUCCESS if successful
369 * @return RMNETCTL_LIB_ERR if there was a library error. Check error_code
370 * @return RMNETCTL_KERNEL_ERR if there was an error in the kernel.
371 * Check error_code
372 * @return RMNETCTL_INVALID_ARG if invalid arguments were passed to the API
373 */
374int rmnet_new_vnd_prefix(rmnetctl_hndl_t *hndl,
375 uint32_t id,
376 uint16_t *error_code,
377 uint8_t new_vnd,
378 const char *prefix);
379/*!
380 * @brief API to get the ASCII name of a virtual network device from its ID
381 * @param hndl RmNet handle for the Netlink message
382 * @param id Node number to create the virtual network device node
383 * @param error_code Status code of this operation returned from the kernel
384 * @param buf Buffer to store ASCII representation of device name
385 * @param buflen Length of the buffer
386 * @param prefix Prefix to be used when naming the network interface
387 * @return RMNETCTL_SUCCESS if successful
388 * @return RMNETCTL_LIB_ERR if there was a library error. Check error_code
389 * @return RMNETCTL_KERNEL_ERR if there was an error in the kernel.
390 * Check error_code
391 * @return RMNETCTL_INVALID_ARG if invalid arguments were passed to the API
392 */
393
394int rmnet_get_vnd_name(rmnetctl_hndl_t *hndl,
395 uint32_t id,
396 uint16_t *error_code,
397 char *buf,
398 uint32_t buflen);
399
Harout Hedeshian97a1e982013-11-08 09:28:53 -0700400/*!
401* @brief Public API to set or clear a flow
402* @details Message type is RMNET_NETLINK_ADD_VND_TC_FLOW or
403* RMNET_NETLINK_DEL_VND_TC_FLOW based on the flag for set_flow
404* @param *rmnetctl_hndl_t_val RmNet handle for the Netlink message
405* @param id Node number to set or clear the flow on the virtual network
406* device node
407* @param map_flow_id Flow handle of the modem
408* @param tc_flow_id Software flow handle
409* @param set_flow sets the flow if RMNET_NETLINK_SET_FLOW or
410* clears the flow if RMNET_NETLINK_CLEAR_FLOW
411* @return RMNETCTL_SUCCESS if successful
412* @return RMNETCTL_LIB_ERR if there was a library error. Check error_code
413* @return RMNETCTL_KERNEL_ERR if there was an error in the kernel.
414* Check error_code
415* @return RMNETCTL_INVALID_ARG if invalid arguments were passed to the API
416*/
417int rmnet_add_del_vnd_tc_flow(rmnetctl_hndl_t *hndl,
418 uint32_t id,
419 uint32_t map_flow_id,
420 uint32_t tc_flow_id,
421 uint8_t set_flow,
422 uint16_t *error_code);
423
Harout Hedeshianb2fc5b12013-09-03 13:49:00 -0600424#endif /* not defined LIBRMNETCTL_H */
425