Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[COMMANDS] Add vstelnet command for command line access to vstelnet l…

…ibrary

Signed-off-by: Anup Patel <anup@brainfault.org>
  • Loading branch information...
commit 4e6486069530cbd291864689afdb5b681fed7dc8 1 parent 5ec1b8a
Anup Patel avpatel authored
152 commands/cmd_vstelnet.c
... ... @@ -0,0 +1,152 @@
  1 +/**
  2 + * Copyright (c) 2013 Anup Patel.
  3 + * All rights reserved.
  4 + *
  5 + * This program is free software; you can redistribute it and/or modify
  6 + * it under the terms of the GNU General Public License as published by
  7 + * the Free Software Foundation; either version 2, or (at your option)
  8 + * any later version.
  9 + *
  10 + * This program is distributed in the hope that it will be useful,
  11 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13 + * GNU General Public License for more details.
  14 + *
  15 + * You should have received a copy of the GNU General Public License
  16 + * along with this program; if not, write to the Free Software
  17 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18 + *
  19 + * @file cmd_vstelnet.c
  20 + * @author Anup Patel (anup@brainfault.org)
  21 + * @brief Implementation of vstelnet command
  22 + */
  23 +
  24 +#include <vmm_error.h>
  25 +#include <vmm_stdio.h>
  26 +#include <vmm_modules.h>
  27 +#include <vmm_cmdmgr.h>
  28 +#include <libs/stringlib.h>
  29 +#include <libs/vstelnet.h>
  30 +
  31 +#define MODULE_DESC "Command vstelnet"
  32 +#define MODULE_AUTHOR "Anup Patel"
  33 +#define MODULE_LICENSE "GPL"
  34 +#define MODULE_IPRIORITY 0
  35 +#define MODULE_INIT cmd_vstelnet_init
  36 +#define MODULE_EXIT cmd_vstelnet_exit
  37 +
  38 +static void cmd_vstelnet_usage(struct vmm_chardev *cdev)
  39 +{
  40 + vmm_cprintf(cdev, "Usage:\n");
  41 + vmm_cprintf(cdev, " vstelnet help\n");
  42 + vmm_cprintf(cdev, " vstelnet list\n");
  43 + vmm_cprintf(cdev, " vstelnet create <port_num> <vserial_name>\n");
  44 + vmm_cprintf(cdev, " vstelnet destroy <port_num>\n");
  45 +}
  46 +
  47 +static void cmd_vstelnet_list(struct vmm_chardev *cdev)
  48 +{
  49 + int i, count;
  50 + struct vstelnet *vst;
  51 +
  52 + vmm_cprintf(cdev, "----------------------------------------"
  53 + "----------------------------------------\n");
  54 + vmm_cprintf(cdev, " %-9s %-69s\n",
  55 + "Port", "Vserial Name");
  56 + vmm_cprintf(cdev, "----------------------------------------"
  57 + "----------------------------------------\n");
  58 +
  59 + count = vstelnet_count();
  60 + for (i = 0; i < count; i++) {
  61 + if (!(vst = vstelnet_get(i))) {
  62 + continue;
  63 + }
  64 + vmm_cprintf(cdev, " %-9d %-69s\n", vst->port, vst->vser->name);
  65 + }
  66 +
  67 + vmm_cprintf(cdev, "----------------------------------------"
  68 + "----------------------------------------\n");
  69 +}
  70 +
  71 +static int cmd_vstelnet_create(struct vmm_chardev *cdev,
  72 + u32 port, const char *vser)
  73 +{
  74 + struct vstelnet *vst = NULL;
  75 +
  76 + vst = vstelnet_create(port, vser);
  77 + if (!vst) {
  78 + vmm_cprintf(cdev, "Error: failed to create "
  79 + "vstelnet for %s\n", vser);
  80 + return VMM_EFAIL;
  81 + }
  82 +
  83 + vmm_cprintf(cdev, "Created vstelnet for %s @ %d\n", vser, port);
  84 +
  85 + return VMM_OK;
  86 +}
  87 +
  88 +static int cmd_vstelnet_destroy(struct vmm_chardev *cdev, u32 port)
  89 +{
  90 + int ret = VMM_EFAIL;
  91 + struct vstelnet *vst = vstelnet_find(port);
  92 +
  93 + if (vst) {
  94 + if ((ret = vstelnet_destroy(vst))) {
  95 + vmm_cprintf(cdev, "Failed to destroy vstelnet "
  96 + "at port %d\n", port);
  97 + } else {
  98 + vmm_cprintf(cdev, "Destroyed vstelnet at port %d\n", port);
  99 + }
  100 + } else {
  101 + vmm_cprintf(cdev, "Failed to find vstelnet at port %d\n", port);
  102 + }
  103 +
  104 + return ret;
  105 +}
  106 +
  107 +static int cmd_vstelnet_exec(struct vmm_chardev *cdev, int argc, char **argv)
  108 +{
  109 + u32 port;
  110 + if (argc == 2) {
  111 + if (strcmp(argv[1], "help") == 0) {
  112 + cmd_vstelnet_usage(cdev);
  113 + return VMM_OK;
  114 + } else if (strcmp(argv[1], "list") == 0) {
  115 + cmd_vstelnet_list(cdev);
  116 + return VMM_OK;
  117 + }
  118 + }
  119 + if ((strcmp(argv[1], "create") == 0) && (argc == 4)) {
  120 + port = str2uint(argv[2], 10);
  121 + return cmd_vstelnet_create(cdev, port, argv[3]);
  122 + } else if ((strcmp(argv[1], "destroy") == 0) && (argc == 3)) {
  123 + port = str2uint(argv[2], 10);
  124 + return cmd_vstelnet_destroy(cdev, port);
  125 + }
  126 + cmd_vstelnet_usage(cdev);
  127 + return VMM_EFAIL;
  128 +}
  129 +
  130 +static struct vmm_cmd cmd_vstelnet = {
  131 + .name = "vstelnet",
  132 + .desc = "commands for vserial telnet access",
  133 + .usage = cmd_vstelnet_usage,
  134 + .exec = cmd_vstelnet_exec,
  135 +};
  136 +
  137 +static int __init cmd_vstelnet_init(void)
  138 +{
  139 + return vmm_cmdmgr_register_cmd(&cmd_vstelnet);
  140 +}
  141 +
  142 +static void __exit cmd_vstelnet_exit(void)
  143 +{
  144 + vmm_cmdmgr_unregister_cmd(&cmd_vstelnet);
  145 +}
  146 +
  147 +VMM_DECLARE_MODULE(MODULE_DESC,
  148 + MODULE_AUTHOR,
  149 + MODULE_LICENSE,
  150 + MODULE_IPRIORITY,
  151 + MODULE_INIT,
  152 + MODULE_EXIT);
1  commands/objects.mk
@@ -44,5 +44,6 @@ commands-objs-$(CONFIG_CMD_BLOCKDEV)+= cmd_blockdev.o
44 44 commands-objs-$(CONFIG_CMD_NET)+= cmd_net.o
45 45 commands-objs-$(CONFIG_CMD_IPCONFIG)+= cmd_ipconfig.o
46 46 commands-objs-$(CONFIG_CMD_PING)+= cmd_ping.o
  47 +commands-objs-$(CONFIG_CMD_VSTELNET)+= cmd_vstelnet.o
47 48 commands-objs-$(CONFIG_CMD_VFS)+= cmd_vfs.o
48 49
7 commands/openconf.cfg
@@ -169,6 +169,13 @@ config CONFIG_CMD_PING
169 169 help
170 170 Enable/Disable ping command.
171 171
  172 +config CONFIG_CMD_VSTELNET
  173 + tristate "vstelnet"
  174 + depends on CONFIG_VSTELNET
  175 + default y
  176 + help
  177 + Enable/Disable vstelnet command.
  178 +
172 179 config CONFIG_CMD_VFS
173 180 tristate "vfs"
174 181 depends on CONFIG_VFS

0 comments on commit 4e64860

Please sign in to comment.
Something went wrong with that request. Please try again.