Permalink
Browse files

[LIBS] Introduce vstelnet library for spawing and managing telnet dae…

…mon for vserial ports

Signed-off-by: Anup Patel <anup@brainfault.org>
  • Loading branch information...
avpatel committed Jan 25, 2013
1 parent 0d0a685 commit 5ec1b8a2532c531952cac17ee9a26ece9a76055f
Showing with 570 additions and 1 deletion.
  1. +95 −0 libs/include/libs/vstelnet.h
  2. +8 −1 libs/openconf.cfg
  3. +25 −0 libs/vstelnet/objects.mk
  4. +442 −0 libs/vstelnet/vstelnet.c
@@ -0,0 +1,95 @@
+/**
+ * Copyright (c) 2013 Anup Patel.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * @file vstelnet.h
+ * @author Anup Patel (anup@brainfault.org)
+ * @brief vserial telnet library interface
+ */
+
+#ifndef __VSTELNET_H_
+#define __VSTELNET_H_
+
+#include <vmm_types.h>
+#include <vmm_threads.h>
+#include <vmm_vserial.h>
+#include <libs/list.h>
+#include <libs/netstack.h>
+
+#define VSTELNET_IPRIORITY (NETSTACK_IPRIORITY + 1)
+#define VSTELNET_TXBUF_SIZE 4096
+#define VSTELNET_RXTIMEOUT_MS 400
+
+struct vstelnet {
+ /* tcp port number */
+ u32 port;
+
+ /* socket pointers */
+ struct netstack_socket *sk;
+
+ /* active connection */
+ struct netstack_socket *active_sk;
+
+ /* tx buffer */
+ u8 tx_buf[VSTELNET_TXBUF_SIZE];
+ u32 tx_buf_head;
+ u32 tx_buf_tail;
+ u32 tx_buf_count;
+ vmm_spinlock_t tx_buf_lock;
+
+ /* vserial port */
+ struct vmm_vserial *vser;
+
+ /* underlying thread */
+ struct vmm_thread *thread;
+
+ /* list head */
+ struct dlist head;
+};
+
+/** Valid vstelnet port numbers */
+static inline bool vstelnet_valid_port(u32 port)
+{
+ if (port < 1024) {
+ /* Well-known port number not allowed */
+ return FALSE;
+ }
+
+ if (65535 < port) {
+ /* Maximum port number is 65535 */
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/** Create vstelnet instance */
+struct vstelnet *vstelnet_create(u32 port, const char *vser_name);
+
+/** Destroy vstelnet instance */
+int vstelnet_destroy(struct vstelnet *vst);
+
+/** Find vstelnet based on port number */
+struct vstelnet *vstelnet_find(u32 port);
+
+/** Get vstelnet based on index */
+struct vstelnet *vstelnet_get(int index);
+
+/** Count vstelnet instances */
+u32 vstelnet_count(void);
+
+#endif /* __VSTELNET_H_ */
View
@@ -27,10 +27,17 @@ config CONFIG_LIBFDT
bool "Flattened device tree library"
default n
help
- Enable/Disable FDT Library.
+ Enable/Disable FDT library.
source libs/netstack/openconf.cfg
+config CONFIG_VSTELNET
+ tristate "Vserial telnet library"
+ depends on CONFIG_NET_STACK
+ default n
+ help
+ Enable/Disable vstelnet library.
+
source libs/vtemu/openconf.cfg
source libs/vfs/openconf.cfg
View
@@ -0,0 +1,25 @@
+#/**
+# Copyright (c) 2013 Anup Patel.
+# All rights reserved.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+# @file vstelnet.mk
+# @author Anup Patel (anup@brainfault.org)
+# @brief list of vstelnet objects to be build
+# */
+
+libs-objs-$(CONFIG_VSTELNET)+= vstelnet/vstelnet.o
+
Oops, something went wrong.

0 comments on commit 5ec1b8a

Please sign in to comment.