/****************************************************************************** R M N E T C L I . C Copyright (c) 2013-2015, 2017-2021 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 #ifdef USE_OLD_RMNET_DATA #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); #else #define _RMNETCLI_CHECKNULL(X) do { if (!X) { \ print_rmnet_api_status(RMNETCTL_INVALID_ARG, RMNETCTL_CFG_FAILURE_NO_COMMAND); \ rtrmnet_ctl_deinit(handle); \ return RMNETCTL_INVALID_ARG; \ } } while (0); #endif #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("**************************\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"