/* * Copyright (c) 2011-2015, Emulex * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * 2. 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. * * 3. Neither the name of the copyright holder 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 BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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 * TBD */ /** * @defgroup cmd_line_parsing Command Line Parsing and Command Execution * @defgroup dev_enum Device Enumeration (Using "list") * @defgroup flash_parsing Flash File Parsing (Using "file-info") * @defgroup flash_access Flash Access * @defgroup mbox_cmd Mailbox Command Construction * @defgroup dev_mgmt Device Management API */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "elxu_common.h" #include "elxu_commands.h" #include #include "version.h" /** * @brief main elxsdkutil CLI functionality * * This function processes CLI parameters and initiates appropriate functional * calls. * * @param argc number of entered cli words * @param *argv[] pointer to array of entered words */ int main(int argc, char *argv[]) { elxu_device_t *device; int i; int result; if (getuid() != 0) { printf("==[ you may need root to run the command ]==\n"); } /* Special case - if no arguments given print usage and exit */ if (argc == 1) { fprintf(stderr, "Type 'elxsdkutil help' for usage\n"); exit(0); } elxu_build_device_list(argc, argv); device = elxu_device_from_args(argc, argv); for (i = 0; i < ARRAY_SIZE(cmd_table); i++) { if (strcmp(argv[1],cmd_table[i].name) == 0) { if (device == NULL) { if (cmd_table[i].nodev_handler != NULL) { result = cmd_table[i].nodev_handler(argc, argv); } else { fprintf(stderr, "The %s command requires a device\n", argv[1]); result = -1; } } else { switch (device->driver) { case DEVICE_DRIVER_OCS: case DEVICE_DRIVER_USPACE: if (cmd_table[i].ocs_handler != NULL) { result = cmd_table[i].ocs_handler(argc, argv); } else { fprintf(stderr, "The %s command is not supported with the OCS SDK drivers\n", argv[1]); result = -1; } break; case DEVICE_DRIVER_PT: if (cmd_table[i].pt_handler != NULL) { result = cmd_table[i].pt_handler(argc, argv); } else { fprintf(stderr, "The %s command is not supported with the elx_pt driver\n", argv[1]); result = -1; } break; case DEVICE_DRIVER_NONE: if (cmd_table[i].nodriver_handler != NULL) { result = cmd_table[i].nodriver_handler(argc, argv); } else { fprintf(stderr, "The %s command is not supported with the OCS SDK drivers\n", argv[1]); result = -1; } break; case DEVICE_DRIVER_BE2NET: /* See if there's a nodev handler that will work */ if (cmd_table[i].nodev_handler != NULL) { result = cmd_table[i].nodev_handler(argc, argv); } else { fprintf(stderr, "Device %d is controlled by the be2net driver, \ which is unsupported by %s\n", device->deviceIndex, argv[0]); result = -1; } break; case DEVICE_DRIVER_UNKNOWN: /* See if there's a nodev handler that will work */ if (cmd_table[i].nodev_handler != NULL) { result = cmd_table[i].nodev_handler(argc, argv); } else { fprintf(stderr, "Unknown driver handling device %d\n", device->deviceIndex); result = -1; } break; } } elxu_delete_device_list(); return result; } } fprintf(stderr, "Unknown command: %s\n", argv[1]); fprintf(stderr, "Type 'elxsdkutil help' for usage\n"); elxu_delete_device_list(); return -1; } /** * @page elxsdkutil_components.html Design and Main Components * - @ref cmd_line_parsing * - @ref dev_enum * - @ref flash_parsing * - @ref flash_access * - @ref mbox_cmd * - @ref dev_mgmt * * @n @section util_main_components Main Components of the elxsdkutil Structure * */