blob: c02850bee2de879766667be9384da233c59d1c86 [file] [log] [blame]
Harout Hedeshianb2fc5b12013-09-03 13:49:00 -06001/******************************************************************************
2
3 R M N E T C L I . C
4
Subash Abhinov Kasiviswanathan5b903dd2017-12-20 19:11:40 -07005Copyright (c) 2013-2015, 2017-2018 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
36 @file rmnetcli.c
37 @brief command line interface to expose rmnet control API's
38
39 DESCRIPTION
40 File containing implementation of the command line interface to expose the
41 rmnet control configuration .
42
43******************************************************************************/
44
45/*===========================================================================
46 INCLUDE FILES
47===========================================================================*/
48
49#include <sys/socket.h>
50#include <stdint.h>
51#include <linux/netlink.h>
52#include <string.h>
53#include <stdio.h>
54#include <unistd.h>
55#include <stdlib.h>
56#include "rmnetcli.h"
57#include "librmnetctl.h"
58
59#define RMNET_MAX_STR_LEN 16
60
61#define _RMNETCLI_CHECKNULL(X) do { if (!X) { \
62print_rmnet_api_status(RMNETCTL_INVALID_ARG, RMNETCTL_CFG_FAILURE_NO_COMMAND); \
63 rmnetctl_cleanup(handle); \
64 return RMNETCTL_INVALID_ARG; \
65 } } while (0);
66#define _STRTOUI32(X) (uint32_t)strtoul(X, NULL, 0)
67#define _STRTOUI16(X) (uint16_t)strtoul(X, NULL, 0)
68#define _STRTOUI8(X) (uint8_t)strtoul(X, NULL, 0)
69#define _STRTOI32(X) (int32_t)strtol(X, NULL, 0)
70
71#define _5TABS "\n\t\t\t\t\t"
72#define _2TABS "\n\t\t"
73
74/*!
75* @brief Contains a list of error message from CLI
76*/
77char rmnetcfg_error_code_text
78[RMNETCFG_TOTAL_ERR_MSGS][RMNETCTL_ERR_MSG_SIZE] = {
79 "Help option Specified",
80 "ERROR: No\\Invalid command was specified\n",
81 "ERROR: Could not allocate buffer for Egress device\n"
82};
83
84/*!
85* @brief Method to display the syntax for the commands
86* @details Displays the syntax and usage for the commands
87* @param void
88* @return void
89*/
Harout Hedeshian04d69732013-10-02 09:29:11 -060090static void rmnet_api_usage(void)
Harout Hedeshianb2fc5b12013-09-03 13:49:00 -060091{
92 printf("RmNet API Usage:\n\n");
93 printf("rmnetcli help Displays this help\n");
94 printf("\n");
95 printf("rmnetcli assocnetdev <dev_name> Registers the RmNet");
96 printf(_5TABS" data driver on a particular");
97 printf(_5TABS" device.dev_name cannot");
98 printf(_5TABS" be larger than 15");
99 printf(_5TABS" characters. Returns");
100 printf(_5TABS" the status code.\n\n");
101 printf("rmnetcli unassocnetdev <dev_name> Unregisters the");
102 printf(_5TABS" RmNet data driver on a particular");
103 printf(_5TABS" device. dev_name cannot");
104 printf(_5TABS" be larger than 15");
105 printf(_5TABS" characters. Returns");
106 printf(_5TABS" the status code.\n\n");
107 printf("rmnetcli getnetdevassoc <dev_name> Get if the RmNet");
108 printf(_5TABS" data driver is registered on");
109 printf(_5TABS" a particular device.");
110 printf(_5TABS" dev_name cannot be");
111 printf(_5TABS" larger than 15");
112 printf(_5TABS" characters. Returns 1");
113 printf(_5TABS" if is registered and");
114 printf(_5TABS" 0 if it is not");
115 printf(_5TABS" registered\n\n");
116 printf("rmnetcli setledf <egress_flags> Sets the egress data");
117 printf(_2TABS" <agg_size> format for a particular link.");
118 printf(_2TABS" <agg_count> dev_name cannot be larger");
119 printf(_2TABS" <dev_name> than 15 characters.");
120 printf(_5TABS" Returns the status code\n\n");
121 printf("rmnetcli getledf <dev_name> Gets the egress data");
122 printf(_5TABS" format for a particular link.");
123 printf(_5TABS" dev_name cannot be larger");
124 printf(_5TABS" than 15. Returns the 4");
125 printf(_5TABS" byte unsigned integer");
126 printf(_5TABS" egress_flags\n\n");
127 printf("rmnetcli setlidf <ingress_flags> Sets the ingress");
Subash Abhinov Kasiviswanathan22fa3882014-01-16 12:55:45 -0700128 printf(_2TABS" <tail_spacing> data format for a particular");
129 printf(_2TABS" <dev_name> link. ingress_flags is 4");
130 printf(_5TABS" byte unsigned integer.");
131 printf(_5TABS" tail_spacing is a one.");
Harout Hedeshianb2fc5b12013-09-03 13:49:00 -0600132 printf(_5TABS" byte unsigned integer.");
133 printf(_5TABS" dev_name cannot be");
134 printf(_5TABS" larger than 15.");
135 printf(_5TABS" characters. Returns");
136 printf(_5TABS" the status code\n\n");
137 printf("rmnetcli getlidf <dev_name> Gets the ingress");
138 printf(_5TABS" data format for a particular");
139 printf(_5TABS" link. dev_name cannot be");
140 printf(_5TABS" larger than 15. Returns");
141 printf(_5TABS" the 4 byte unsigned");
142 printf(_5TABS" integer ingress_flags\n\n");
143 printf("rmnetcli setlepc <logical_ep_id> Sets the logical");
144 printf(_2TABS" <rmnet_mode> endpoint configuration for");
145 printf(_2TABS" <dev_name> a particular link.");
146 printf(_2TABS" <egress_dev_name> logical_ep_id are 32bit");
147 printf(_5TABS" integers from -1 to 31.");
148 printf(_5TABS" rmnet_mode is a 1 byte");
149 printf(_5TABS" unsigned integer of");
150 printf(_5TABS" value none, vnd or");
151 printf(_5TABS" bridged. dev_name");
152 printf(_5TABS" and egress_dev_name");
153 printf(_5TABS" cannot be larger");
Subash Abhinov Kasiviswanathancf715082015-04-14 13:51:59 -0600154 printf(_5TABS" than 15 characters");
Harout Hedeshianb2fc5b12013-09-03 13:49:00 -0600155 printf(_5TABS" Returns the status code\n\n");
Harout Hedeshiana9731652014-01-06 18:00:23 +0200156 printf("rmnetcli unsetlepc <logical_ep_id> Un-sets the logical");
157 printf(_2TABS" <dev_name> endpoint configuration for");
158 printf(_5TABS" a particular link.");
159 printf(_5TABS" integers from -1 to 31.");
160 printf(_5TABS" dev_name cannot be larger");
Subash Abhinov Kasiviswanathancf715082015-04-14 13:51:59 -0600161 printf(_5TABS" than 15 characters");
Harout Hedeshiana9731652014-01-06 18:00:23 +0200162 printf(_5TABS" Returns the status code\n\n");
Harout Hedeshianb2fc5b12013-09-03 13:49:00 -0600163 printf("rmnetcli getlepc <logical_ep_id> Sets the logical");
Subash Abhinov Kasiviswanathancf715082015-04-14 13:51:59 -0600164 printf(_2TABS" <dev_name> endpoint configuration for a");
Harout Hedeshianb2fc5b12013-09-03 13:49:00 -0600165 printf(_5TABS" particular link.");
166 printf(_5TABS" logical_ep_id are 32bit");
167 printf(_5TABS" integers from -1 to 31.");
168 printf(_5TABS" Returns the rmnet_mode");
169 printf(_5TABS" and egress_dev_name.");
170 printf(_5TABS" rmnet_mode is a 1");
171 printf(_5TABS" byte unsigned integer");
172 printf(_5TABS" of value none, vnd or");
173 printf(_5TABS" bridged. dev_name and");
174 printf(_5TABS" egress_dev_name cannot be");
175 printf(_5TABS" larger than 15 ");
176 printf(_5TABS" characters. Returns the");
177 printf(_5TABS" status code\n\n");
Harout Hedeshian89a91e22013-10-09 08:59:47 -0600178 printf("rmnetcli newvnd <dev_id> Creates a new");
Harout Hedeshianb2fc5b12013-09-03 13:49:00 -0600179 printf(_5TABS" virtual network device node.");
Harout Hedeshian89a91e22013-10-09 08:59:47 -0600180 printf(_5TABS" dev_id is an int");
181 printf(_5TABS" less than 32. Returns");
Harout Hedeshianb2fc5b12013-09-03 13:49:00 -0600182 printf(_5TABS" the status code\n\n");
Harout Hedeshian89a91e22013-10-09 08:59:47 -0600183 printf("rmnetcli newvndprefix <dev_id> <name_prefix> Creates");
184 printf(_5TABS" virtual network device node.");
185 printf(_5TABS" dev_id is an int");
186 printf(_5TABS" less than 32. Prefix");
187 printf(_5TABS" must be less than");
188 printf(_5TABS" 15 chars. Returns");
189 printf(_5TABS" the status code\n\n");
Subash Abhinov Kasiviswanathandba447c2017-02-23 17:58:09 -0700190 printf("rmnetcli newvndname <dev_id> <name_prefix> Creates");
191 printf(_5TABS" virtual network device node.");
192 printf(_5TABS" dev_id is an int");
193 printf(_5TABS" less than 32. Name");
194 printf(_5TABS" must be less than");
195 printf(_5TABS" 15 chars. Returns");
196 printf(_5TABS" the status code\n\n");
Harout Hedeshian89a91e22013-10-09 08:59:47 -0600197 printf("rmnetcli getvndname <dev_id> Get name of");
Harout Hedeshiana9731652014-01-06 18:00:23 +0200198 printf(_5TABS" network device node from id\n\n");
Harout Hedeshian89a91e22013-10-09 08:59:47 -0600199 printf("rmnetcli freevnd <dev_id> Removes virtual");
Harout Hedeshianb2fc5b12013-09-03 13:49:00 -0600200 printf(_5TABS" network device node. dev_name");
201 printf(_5TABS" cannot be larger than 15.");
202 printf(_5TABS" Returns the status code\n\n");
Harout Hedeshian97a1e982013-11-08 09:28:53 -0700203 printf("rmnetcli addvnctcflow <dev_id> Add a modem flow");
204 printf(_2TABS" <mdm_flow_hndl> handle - tc flow handle");
205 printf(_2TABS" <tc_flow_hndl> mapping for a virtual network");
206 printf(_2TABS" device node\n\n");
207 printf("rmnetcli delvnctcflow <dev_id> Delete a modem flow");
208 printf(_2TABS" <mdm_flow_hndl> handle - tc flow handle");
209 printf(_2TABS" <tc_flow_hndl> mapping for a virtual network");
210 printf(_2TABS" device node\n\n");
Subash Abhinov Kasiviswanathan5b903dd2017-12-20 19:11:40 -0700211 printf("**************************\n");
212 printf("RmNet RTM_NETLINK API Usage:\n\n");
213 printf("rmnetcli -n newlink <dev_id> Add a vnd w/ newlink");
214 printf(_2TABS" <vnd> string - vnd device_name");
215 printf(_2TABS" <vnd id> int - new vnd id");
216 printf(_2TABS" [flags] int - starting flag config\n\n");
217 printf("rmnetcli -n changelink <dev_id> Change a vnd's flags");
218 printf(_2TABS" <vnd> string - vnd device_name");
219 printf(_2TABS" <vnd id> int - new vnd id");
220 printf(_2TABS" <flags> int - new flag config\n\n");
221 printf("rmnetcli -n dellink <dev_name> Delete a vnd");
222 printf(_2TABS" by inputting dev name\n\n");
223 printf("rmnetcli -n bridgelink <dev_name> Bridge a vnd and a dev");
224 printf(_2TABS" <vnd id> by specifying dev id and vnd id\n\n");
225
Harout Hedeshianb2fc5b12013-09-03 13:49:00 -0600226}
227
Harout Hedeshian77825572014-02-17 10:47:14 +0200228static void print_rmnetctl_lib_errors(uint16_t error_number)
229{
Harout Hedeshianb2fc5b12013-09-03 13:49:00 -0600230 if ((error_number > RMNETCTL_API_SUCCESS) &&
231 (error_number < RMNETCTL_API_ERR_ENUM_LENGTH)) {
232 printf("%s", rmnetctl_error_code_text[error_number]);
233 }
234 if ((error_number >= RMNETCFG_ERR_NUM_START) &&
235 (error_number < RMNETCFG_ERR_NUM_START + RMNETCFG_TOTAL_ERR_MSGS)) {
236 printf("%s", rmnetcfg_error_code_text
237 [error_number - RMNETCFG_ERR_NUM_START]);
238 if ((error_number == RMNETCTL_CFG_SUCCESS_HELP_COMMAND) ||
239 (error_number == RMNETCTL_CFG_FAILURE_NO_COMMAND))
240 rmnet_api_usage();
241 }
242}
243
244/*!
245* @brief Method to check the error numbers generated from API calls
246* @details Displays the error messages based on each error code
247* @param error_number Error number returned from the API and the CLI
248* @return void
249*/
250static void print_rmnet_api_status(int return_code, uint16_t error_number)
251{
252 if (return_code == RMNETCTL_SUCCESS)
253 printf("SUCCESS\n");
Harout Hedeshian77825572014-02-17 10:47:14 +0200254 else if (return_code == RMNETCTL_LIB_ERR) {
Harout Hedeshianb2fc5b12013-09-03 13:49:00 -0600255 printf("LIBRARY ");
Harout Hedeshian77825572014-02-17 10:47:14 +0200256 print_rmnetctl_lib_errors(error_number);
Subash Abhinov Kasiviswanathan5b903dd2017-12-20 19:11:40 -0700257 } else if (return_code == RMNETCTL_KERNEL_ERR) {
258 if (error_number < RMNETCTL_API_ERR_ENUM_LENGTH)
259 printf("KERNEL ERROR: System or rmnet error %d\n",
260 error_number);
261 }
Harout Hedeshianb2fc5b12013-09-03 13:49:00 -0600262 else if (return_code == RMNETCTL_INVALID_ARG)
263 printf("INVALID_ARG\n");
Harout Hedeshianb2fc5b12013-09-03 13:49:00 -0600264}
265
266/*!
267* @brief Method to make the API calls
268* @details Checks for each type of parameter and calls the appropriate
Subash Abhinov Kasiviswanathancf715082015-04-14 13:51:59 -0600269* function based on the number of parameters and parameter type
Harout Hedeshianb2fc5b12013-09-03 13:49:00 -0600270* @param argc Number of arguments which vary based on the commands
271* @param argv Value of the arguments which vary based on the commands
272* @return RMNETCTL_SUCCESS if successful. Relevant data might be printed
273* based on the message type
274* @return RMNETCTL_LIB_ERR if there was a library error. Error code will be
275* printed
276* @return RMNETCTL_KERNEL_ERR if there was a error in the kernel. Error code will be
277* printed
278* @return RMNETCTL_INVALID_ARG if invalid arguments were passed to the API
279*/
280
281static int rmnet_api_call(int argc, char *argv[])
282{
283 struct rmnetctl_hndl_s *handle = NULL;
284 uint16_t error_number = RMNETCTL_CFG_FAILURE_NO_COMMAND;
285 int return_code = RMNETCTL_LIB_ERR;
286 if ((!argc) || (!*argv)) {
287 print_rmnet_api_status(RMNETCTL_LIB_ERR,
288 RMNETCTL_CFG_FAILURE_NO_COMMAND);
289 return RMNETCTL_LIB_ERR;
290 }
291 if (!strcmp(*argv, "help")) {
292 print_rmnet_api_status(RMNETCTL_LIB_ERR,
293 RMNETCTL_CFG_SUCCESS_HELP_COMMAND);
294 return RMNETCTL_LIB_ERR;
295 }
Subash Abhinov Kasiviswanathan5b903dd2017-12-20 19:11:40 -0700296
297 if (!strcmp(*argv, "-n")) {
298 return_code = rtrmnet_ctl_init(&handle, &error_number);
299 if (return_code != RMNETCTL_SUCCESS) {
300 print_rmnet_api_status(return_code, error_number);
301 return RMNETCTL_LIB_ERR;
302 }
303 error_number = RMNETCTL_CFG_FAILURE_NO_COMMAND;
304 return_code = RMNETCTL_LIB_ERR;
305 argv++;
306 argc--;
307 if ((!argc) || (!*argv)) {
308 print_rmnet_api_status(RMNETCTL_LIB_ERR,
309 RMNETCTL_CFG_FAILURE_NO_COMMAND);
310 return RMNETCTL_LIB_ERR;
311 }
312 if (!strcmp(*argv, "newlink")) {
313 _RMNETCLI_CHECKNULL(argv[1]);
314 _RMNETCLI_CHECKNULL(argv[2]);
315 _RMNETCLI_CHECKNULL(argv[3]);
316 uint32_t flags = 0;
317 /* If optional flag was used pass it on*/
318 if (argv[4])
319 flags = _STRTOI32(argv[4]);
320
321 return_code = rtrmnet_ctl_newvnd(handle, argv[1],
322 argv[2],
323 &error_number,
324 _STRTOI32(argv[3]),
325 flags);
326 } else if (!strcmp(*argv, "changelink")) {
327 _RMNETCLI_CHECKNULL(argv[1]);
328 _RMNETCLI_CHECKNULL(argv[2]);
329 _RMNETCLI_CHECKNULL(argv[3]);
330 _RMNETCLI_CHECKNULL(argv[4]);
331
332 return_code = rtrmnet_ctl_changevnd(handle, argv[1],
333 argv[2],
334 &error_number,
335 _STRTOI32(argv[3]),
336 _STRTOI32(argv[4]));
337 } else if (!strcmp(*argv, "dellink")) {
338 _RMNETCLI_CHECKNULL(argv[1]);
339 return_code = rtrmnet_ctl_delvnd(handle, argv[1],
340 &error_number);
341 } else if (!strcmp(*argv, "bridge")) {
342 _RMNETCLI_CHECKNULL(argv[1]);
343 _RMNETCLI_CHECKNULL(argv[2]);
344 return_code = rtrmnet_ctl_bridgevnd(handle, argv[1],
345 argv[2],
346 &error_number);
347 }
348 goto end;
349 } else {
350 return_code = rmnetctl_init(&handle, &error_number);
351 if (return_code != RMNETCTL_SUCCESS) {
352 print_rmnet_api_status(return_code, error_number);
353 return RMNETCTL_LIB_ERR;
354 }
355
Harout Hedeshianb2fc5b12013-09-03 13:49:00 -0600356 }
357 error_number = RMNETCTL_CFG_FAILURE_NO_COMMAND;
358 return_code = RMNETCTL_LIB_ERR;
359 if (!strcmp(*argv, "assocnetdev")) {
360 return_code = rmnet_associate_network_device(handle,
361 argv[1], &error_number, RMNETCTL_DEVICE_ASSOCIATE);
362 } else if (!strcmp(*argv, "unassocnetdev")) {
363 return_code = rmnet_associate_network_device(handle,
364 argv[1], &error_number, RMNETCTL_DEVICE_UNASSOCIATE);
365 } else if (!strcmp(*argv, "getnetdevassoc")) {
366 int register_status;
367 return_code = rmnet_get_network_device_associated(handle,
368 argv[1], &register_status, &error_number);
369 if (return_code == RMNETCTL_SUCCESS)
370 printf("register_status is %d\n", register_status);
371 } else if (!strcmp(*argv, "getledf")) {
372 uint32_t egress_flags;
373 uint16_t agg_size, agg_count;
374 return_code = rmnet_get_link_egress_data_format(handle,
375 argv[1], &egress_flags, &agg_size, &agg_count, &error_number);
376 if (return_code == RMNETCTL_SUCCESS) {
377 printf("egress_flags is %u\n", egress_flags);
378 printf("agg_size is %u\n", agg_size);
379 printf("agg_count is %u\n", agg_count);
380 }
381 } else if (!strcmp(*argv, "getlidf")) {
382 uint32_t ingress_flags;
Subash Abhinov Kasiviswanathan22fa3882014-01-16 12:55:45 -0700383 uint8_t tail_spacing;
384 return_code = rmnet_get_link_ingress_data_format_tailspace(
385 handle, argv[1], &ingress_flags, &tail_spacing, &error_number);
Harout Hedeshianb2fc5b12013-09-03 13:49:00 -0600386 if (return_code == RMNETCTL_SUCCESS) {
387 printf("ingress_flags is %u\n", ingress_flags);
Subash Abhinov Kasiviswanathan22fa3882014-01-16 12:55:45 -0700388 printf("tail_spacing is %u\n", tail_spacing);
Harout Hedeshianb2fc5b12013-09-03 13:49:00 -0600389 }
Harout Hedeshian89a91e22013-10-09 08:59:47 -0600390 } else if (!strcmp(*argv, "newvndprefix")) {
391 _RMNETCLI_CHECKNULL(argv[1]);
392 _RMNETCLI_CHECKNULL(argv[2]);
393 return_code = rmnet_new_vnd_prefix(handle,
394 _STRTOUI32(argv[1]), &error_number, RMNETCTL_NEW_VND, argv[2]);
Subash Abhinov Kasiviswanathandba447c2017-02-23 17:58:09 -0700395 } else if (!strcmp(*argv, "newvndname")) {
396 _RMNETCLI_CHECKNULL(argv[1]);
397 _RMNETCLI_CHECKNULL(argv[2]);
398 return_code = rmnet_new_vnd_name(handle,
399 _STRTOUI32(argv[1]), &error_number, argv[2]);
Harout Hedeshianb2fc5b12013-09-03 13:49:00 -0600400 } else if (!strcmp(*argv, "newvnd")) {
401 _RMNETCLI_CHECKNULL(argv[1]);
402 return_code = rmnet_new_vnd(handle,
403 _STRTOUI32(argv[1]), &error_number, RMNETCTL_NEW_VND);
Harout Hedeshian89a91e22013-10-09 08:59:47 -0600404 } else if (!strcmp(*argv, "getvndname")) {
405 char buffer[32];
406 memset(buffer, 0, 32);
407 _RMNETCLI_CHECKNULL(argv[1]);
408 return_code = rmnet_get_vnd_name(handle, _STRTOUI32(argv[1]),
409 &error_number, buffer, 32);
410 if (return_code == RMNETCTL_SUCCESS) {
411 printf("VND name: %s\n", buffer);
412 }
Harout Hedeshianb2fc5b12013-09-03 13:49:00 -0600413 } else if (!strcmp(*argv, "freevnd")) {
414 _RMNETCLI_CHECKNULL(argv[1]);
415 return_code = rmnet_new_vnd(handle,
416 _STRTOUI32(argv[1]), &error_number, RMNETCTL_FREE_VND);
417 } else if (!strcmp(*argv, "setlidf")) {
418 _RMNETCLI_CHECKNULL(argv[1]);
Subash Abhinov Kasiviswanathan22fa3882014-01-16 12:55:45 -0700419 _RMNETCLI_CHECKNULL(argv[2]);
420 _RMNETCLI_CHECKNULL(argv[3]);
421 return_code = rmnet_set_link_ingress_data_format_tailspace(
422 handle, _STRTOUI32(argv[1]), _STRTOUI8(argv[2]), argv[3],
423 &error_number);
Harout Hedeshian97a1e982013-11-08 09:28:53 -0700424 } else if (!strcmp(*argv, "delvnctcflow")) {
425 _RMNETCLI_CHECKNULL(argv[1]);
426 _RMNETCLI_CHECKNULL(argv[2]);
427 _RMNETCLI_CHECKNULL(argv[3]);
428 return_code = rmnet_add_del_vnd_tc_flow(handle,
429 _STRTOUI32(argv[1]), _STRTOUI32(argv[2]), _STRTOUI32(argv[3]),
430 RMNETCTL_DEL_FLOW, &error_number);
Harout Hedeshianb2fc5b12013-09-03 13:49:00 -0600431 } else if (!strcmp(*argv, "getlepc")) {
432 _RMNETCLI_CHECKNULL(argv[1]);
433 uint8_t rmnet_mode;
434 char *egress_dev_name;
435 egress_dev_name = NULL;
436 egress_dev_name = (char *)malloc(RMNET_MAX_STR_LEN
437 * sizeof(char));
438 if (!egress_dev_name) {
439 print_rmnet_api_status(RMNETCTL_LIB_ERR,
440 RMNETCTL_CFG_FAILURE_EGRESS_DEV_NAME_NULL);
Harout Hedeshian0bf0a172014-02-19 23:52:05 -0700441 rmnetctl_cleanup(handle);
Harout Hedeshianb2fc5b12013-09-03 13:49:00 -0600442 return RMNETCTL_LIB_ERR;
443 }
444 return_code = rmnet_get_logical_ep_config(handle,
445 _STRTOI32(argv[1]), argv[2], &rmnet_mode,
Harout Hedeshian77825572014-02-17 10:47:14 +0200446 &egress_dev_name, RMNET_MAX_STR_LEN, &error_number);
Harout Hedeshianb2fc5b12013-09-03 13:49:00 -0600447 if (return_code == RMNETCTL_SUCCESS) {
448 printf("rmnet_mode is %u\n", rmnet_mode);
449 printf("egress_dev_name is %s\n", egress_dev_name);
450 }
Harout Hedeshian0bf0a172014-02-19 23:52:05 -0700451 free(egress_dev_name);
Harout Hedeshian97a1e982013-11-08 09:28:53 -0700452 } else if (!strcmp(*argv, "addvnctcflow")) {
453 _RMNETCLI_CHECKNULL(argv[1]);
454 _RMNETCLI_CHECKNULL(argv[2]);
455 _RMNETCLI_CHECKNULL(argv[3]);
456 return_code = rmnet_add_del_vnd_tc_flow(handle,
457 _STRTOUI32(argv[1]), _STRTOUI32(argv[2]), _STRTOUI32(argv[3]),
458 RMNETCTL_ADD_FLOW, &error_number);
Harout Hedeshianb2fc5b12013-09-03 13:49:00 -0600459 } else if (!strcmp(*argv, "setledf")) {
460 _RMNETCLI_CHECKNULL(argv[1]);
461 _RMNETCLI_CHECKNULL(argv[2]);
462 _RMNETCLI_CHECKNULL(argv[3]);
463 return_code = rmnet_set_link_egress_data_format(handle,
464 _STRTOUI32(argv[1]), _STRTOUI16(argv[2]), _STRTOUI16(argv[3]),
465 argv[4], &error_number);
466 } else if (!strcmp(*argv, "setlepc")) {
467 _RMNETCLI_CHECKNULL(argv[1]);
468 _RMNETCLI_CHECKNULL(argv[2]);
469 return_code = rmnet_set_logical_ep_config(handle,
470 _STRTOI32(argv[1]), _STRTOUI8(argv[2]), argv[3], argv[4],
471 &error_number);
Harout Hedeshiana9731652014-01-06 18:00:23 +0200472 } else if (!strcmp(*argv, "unsetlepc")) {
473 _RMNETCLI_CHECKNULL(argv[1]);
474 return_code = rmnet_unset_logical_ep_config(handle,
475 _STRTOI32(argv[1]), argv[2], &error_number);
Harout Hedeshianb2fc5b12013-09-03 13:49:00 -0600476 }
Subash Abhinov Kasiviswanathan5b903dd2017-12-20 19:11:40 -0700477end:
Harout Hedeshianb2fc5b12013-09-03 13:49:00 -0600478 print_rmnet_api_status(return_code, error_number);
479 rmnetctl_cleanup(handle);
Subash Abhinov Kasiviswanathan5b903dd2017-12-20 19:11:40 -0700480 rtrmnet_ctl_deinit(handle);
Harout Hedeshianb2fc5b12013-09-03 13:49:00 -0600481 return return_code;
482}
483
484/*!
485* @brief Method which serves as en entry point to the rmnetcli function
486* @details Entry point for the RmNet Netlink API. This is the command line
487* interface for the RmNet API
488* @param argc Number of arguments which vary based on the commands
489* @param argv Value of the arguments which vary based on the commands
490* @return RMNETCTL_SUCCESS if successful. Relevant data might be printed
491* based on the message type
492* @return RMNETCTL_LIB_ERR if there was a library error. Error code will be
493* printed
494* @return RMNETCTL_KERNEL_ERR if there was a error in the kernel. Error code will be
495* printed
496* @return RMNETCTL_INVALID_ARG if invalid arguments were passed to the API
497*/
498int main(int argc, char *argv[])
499{
500 argc--;
501 argv++;
502 return rmnet_api_call(argc, argv);
503}