/****************************************************************************** R M N E T C L I . C Copyright (c) 2013-2015, 2017-2020 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 rmnetcli.c @brief command line interface to expose rmnet control API's DESCRIPTION File containing implementation of the command line interface to expose the rmnet control configuration . ******************************************************************************/ /*=========================================================================== INCLUDE FILES ===========================================================================*/ #include #include #include #include #include #include #include #include "rmnetcli.h" #include "librmnetctl.h" #define RMNET_MAX_STR_LEN 16 #define _RMNETCLI_CHECKNULL(X) do { if (!X) { \ print_rmnet_api_status(RMNETCTL_INVALID_ARG, RMNETCTL_CFG_FAILURE_NO_COMMAND); \ rmnetctl_cleanup(handle); \ return RMNETCTL_INVALID_ARG; \ } } while (0); #define _STRTOUI32(X) (uint32_t)strtoul(X, NULL, 0) #define _STRTOUI16(X) (uint16_t)strtoul(X, NULL, 0) #define _STRTOUI8(X) (uint8_t)strtoul(X, NULL, 0) #define _STRTOI32(X) (int32_t)strtol(X, NULL, 0) #define _5TABS "\n\t\t\t\t\t" #define _2TABS "\n\t\t" /*! * @brief Contains a list of error message from CLI */ char rmnetcfg_error_code_text [RMNETCFG_TOTAL_ERR_MSGS][RMNETCTL_ERR_MSG_SIZE] = { "Help option Specified", "ERROR: No\\Invalid command was specified\n", "ERROR: Could not allocate buffer for Egress device\n" }; /*! * @brief Method to display the syntax for the commands * @details Displays the syntax and usage for the commands * @param void * @return void */ static void rmnet_api_usage(void) { printf("RmNet API Usage:\n\n"); printf("rmnetcli help Displays this help\n"); printf("\n"); printf("rmnetcli assocnetdev Registers the RmNet"); printf(_5TABS" data driver on a particular"); printf(_5TABS" device.dev_name cannot"); printf(_5TABS" be larger than 15"); printf(_5TABS" characters. Returns"); printf(_5TABS" the status code.\n\n"); printf("rmnetcli unassocnetdev Unregisters the"); printf(_5TABS" RmNet data driver on a particular"); printf(_5TABS" device. dev_name cannot"); printf(_5TABS" be larger than 15"); printf(_5TABS" characters. Returns"); printf(_5TABS" the status code.\n\n"); printf("rmnetcli getnetdevassoc Get if the RmNet"); printf(_5TABS" data driver is registered on"); printf(_5TABS" a particular device."); printf(_5TABS" dev_name cannot be"); printf(_5TABS" larger than 15"); printf(_5TABS" characters. Returns 1"); printf(_5TABS" if is registered and"); printf(_5TABS" 0 if it is not"); printf(_5TABS" registered\n\n"); printf("rmnetcli setledf Sets the egress data"); printf(_2TABS" format for a particular link."); printf(_2TABS" dev_name cannot be larger"); printf(_2TABS" than 15 characters."); printf(_5TABS" Returns the status code\n\n"); printf("rmnetcli getledf Gets the egress data"); printf(_5TABS" format for a particular link."); printf(_5TABS" dev_name cannot be larger"); printf(_5TABS" than 15. Returns the 4"); printf(_5TABS" byte unsigned integer"); printf(_5TABS" egress_flags\n\n"); printf("rmnetcli setlidf Sets the ingress"); printf(_2TABS" data format for a particular"); printf(_2TABS" link. ingress_flags is 4"); printf(_5TABS" byte unsigned integer."); printf(_5TABS" tail_spacing is a one."); printf(_5TABS" byte unsigned integer."); printf(_5TABS" dev_name cannot be"); printf(_5TABS" larger than 15."); printf(_5TABS" characters. Returns"); printf(_5TABS" the status code\n\n"); printf("rmnetcli getlidf Gets the ingress"); printf(_5TABS" data format for a particular"); printf(_5TABS" link. dev_name cannot be"); printf(_5TABS" larger than 15. Returns"); printf(_5TABS" the 4 byte unsigned"); printf(_5TABS" integer ingress_flags\n\n"); printf("rmnetcli setlepc Sets the logical"); printf(_2TABS" endpoint configuration for"); printf(_2TABS" a particular link."); printf(_2TABS" logical_ep_id are 32bit"); printf(_5TABS" integers from -1 to 31."); printf(_5TABS" rmnet_mode is a 1 byte"); printf(_5TABS" unsigned integer of"); printf(_5TABS" value none, vnd or"); printf(_5TABS" bridged. dev_name"); printf(_5TABS" and egress_dev_name"); printf(_5TABS" cannot be larger"); printf(_5TABS" than 15 characters"); printf(_5TABS" Returns the status code\n\n"); printf("rmnetcli unsetlepc Un-sets the logical"); printf(_2TABS" endpoint configuration for"); printf(_5TABS" a particular link."); printf(_5TABS" integers from -1 to 31."); printf(_5TABS" dev_name cannot be larger"); printf(_5TABS" than 15 characters"); printf(_5TABS" Returns the status code\n\n"); printf("rmnetcli getlepc Sets the logical"); printf(_2TABS" endpoint configuration for a"); printf(_5TABS" particular link."); printf(_5TABS" logical_ep_id are 32bit"); printf(_5TABS" integers from -1 to 31."); printf(_5TABS" Returns the rmnet_mode"); printf(_5TABS" and egress_dev_name."); printf(_5TABS" rmnet_mode is a 1"); printf(_5TABS" byte unsigned integer"); printf(_5TABS" of value none, vnd or"); printf(_5TABS" bridged. dev_name and"); printf(_5TABS" egress_dev_name cannot be"); printf(_5TABS" larger than 15 "); printf(_5TABS" characters. Returns the"); printf(_5TABS" status code\n\n"); printf("rmnetcli newvnd Creates a new"); printf(_5TABS" virtual network device node."); printf(_5TABS" dev_id is an int"); printf(_5TABS" less than 32. Returns"); printf(_5TABS" the status code\n\n"); printf("rmnetcli newvndprefix Creates"); printf(_5TABS" virtual network device node."); printf(_5TABS" dev_id is an int"); printf(_5TABS" less than 32. Prefix"); printf(_5TABS" must be less than"); printf(_5TABS" 15 chars. Returns"); printf(_5TABS" the status code\n\n"); printf("rmnetcli newvndname Creates"); printf(_5TABS" virtual network device node."); printf(_5TABS" dev_id is an int"); printf(_5TABS" less than 32. Name"); printf(_5TABS" must be less than"); printf(_5TABS" 15 chars. Returns"); printf(_5TABS" the status code\n\n"); printf("rmnetcli getvndname Get name of"); printf(_5TABS" network device node from id\n\n"); printf("rmnetcli freevnd Removes virtual"); printf(_5TABS" network device node. dev_name"); printf(_5TABS" cannot be larger than 15."); printf(_5TABS" Returns the status code\n\n"); printf("rmnetcli addvnctcflow Add a modem flow"); printf(_2TABS" handle - tc flow handle"); printf(_2TABS" mapping for a virtual network"); printf(_2TABS" device node\n\n"); printf("rmnetcli delvnctcflow Delete a modem flow"); printf(_2TABS" handle - tc flow handle"); printf(_2TABS" mapping for a virtual network"); printf(_2TABS" device node\n\n"); printf("**************************\n"); printf("RmNet RTM_NETLINK API Usage:\n\n"); printf("rmnetcli -n newlink Add a vnd w/ newlink"); printf(_2TABS" string - vnd device_name"); printf(_2TABS" int - new vnd id"); printf(_2TABS" [flags] int - starting flag config\n\n"); printf("rmnetcli -n changelink Change a vnd's flags"); printf(_2TABS" string - vnd device_name"); printf(_2TABS" int - new vnd id"); printf(_2TABS" int - new flag config\n\n"); printf("rmnetcli -n getlink Get device config\n\n"); printf("rmnetcli -n dellink Delete a vnd"); printf(_2TABS" by inputting dev name\n\n"); printf("rmnetcli -n bridgelink Bridge a vnd and a dev"); printf(_2TABS" by specifying dev id and vnd id\n\n"); printf("rmnetcli -n uplinkparam set uplink aggregation parameters"); printf(_2TABS" string - vnd device_name"); printf(_2TABS" int - maximum packet count"); printf(_2TABS" int - maximum byte count"); printf(_2TABS"