/[dynamips]/upstream/dynamips-0.2.7-RC1/dev_vtty.h
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /upstream/dynamips-0.2.7-RC1/dev_vtty.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 7 - (show annotations)
Sat Oct 6 16:23:47 2007 UTC (12 years, 1 month ago) by dpavlin
File MIME type: text/plain
File size: 2749 byte(s)
dynamips-0.2.7-RC1

1 /*
2 * Cisco router simulation platform.
3 * Copyright (c) 2005,2006 Christophe Fillot (cf@utc.fr)
4 *
5 * Virtual console TTY.
6 */
7
8 #ifndef __DEV_VTTY_H__
9 #define __DEV_VTTY_H__
10
11 #include <sys/types.h>
12 #include <pthread.h>
13
14 #include "vm.h"
15 #include <stdio.h>
16
17 /* 4 Kb should be enough for a keyboard buffer */
18 #define VTTY_BUFFER_SIZE 4096
19
20 /* VTTY connection types */
21 enum {
22 VTTY_TYPE_NONE = 0,
23 VTTY_TYPE_TERM,
24 VTTY_TYPE_TCP,
25 VTTY_TYPE_SERIAL,
26 };
27
28 /* VTTY connection states (for TCP) */
29 enum {
30 VTTY_STATE_TCP_INVALID, /* connection is not working */
31 VTTY_STATE_TCP_WAITING, /* waiting for incoming connection */
32 VTTY_STATE_TCP_RUNNING, /* character reading/writing ok */
33 };
34
35 /* VTTY input states */
36 enum {
37 VTTY_INPUT_TEXT,
38 VTTY_INPUT_VT1,
39 VTTY_INPUT_VT2,
40 VTTY_INPUT_REMOTE,
41 VTTY_INPUT_TELNET,
42 VTTY_INPUT_TELNET_IYOU,
43 VTTY_INPUT_TELNET_SB1,
44 VTTY_INPUT_TELNET_SB2,
45 VTTY_INPUT_TELNET_SB_TTYPE,
46 VTTY_INPUT_TELNET_NEXT
47 };
48
49
50 /* Commmand line support utility */
51 typedef struct vtty_serial_option vtty_serial_option_t;
52 struct vtty_serial_option {
53 char *device;
54 int baudrate, databits, parity, stopbits, hwflow;
55 };
56
57 int vtty_parse_serial_option(vtty_serial_option_t *params, char *optarg);
58
59 /* Virtual TTY structure */
60 typedef struct virtual_tty vtty_t;
61 struct virtual_tty {
62 vm_instance_t *vm;
63 char *name;
64 int type,state;
65 int tcp_port;
66 int terminal_support;
67 int input_state;
68 int input_pending;
69 int telnet_cmd, telnet_opt, telnet_qual;
70 int fd,accept_fd,*select_fd;
71 int managed_flush;
72 FILE *fstream;
73 u_char buffer[VTTY_BUFFER_SIZE];
74 u_int read_ptr,write_ptr;
75 pthread_mutex_t lock;
76 vtty_t *next,**pprev;
77 void *priv_data;
78
79 /* Read notification */
80 void (*read_notifier)(vtty_t *);
81 };
82
83 #define VTTY_LOCK(tty) pthread_mutex_lock(&(tty)->lock);
84 #define VTTY_UNLOCK(tty) pthread_mutex_unlock(&(tty)->lock);
85
86 /* create a virtual tty */
87 vtty_t *vtty_create(vm_instance_t *vm,char *name,int type,int tcp_port,
88 const vtty_serial_option_t *option);
89
90 /* delete a virtual tty */
91 void vtty_delete(vtty_t *vtty);
92
93 /* Store a string in the FIFO buffer */
94 int vtty_store_str(vtty_t *vtty,char *str);
95
96 /* read a character from the buffer (-1 if the buffer is empty) */
97 int vtty_get_char(vtty_t *vtty);
98
99 /* print a character to vtty */
100 void vtty_put_char(vtty_t *vtty, char ch);
101
102 /* Put a buffer to vtty */
103 void vtty_put_buffer(vtty_t *vtty,char *buf,size_t len);
104
105 /* Flush VTTY output */
106 void vtty_flush(vtty_t *vtty);
107
108 /* returns TRUE if a character is available in buffer */
109 int vtty_is_char_avail(vtty_t *vtty);
110
111 /* write CTRL+C to buffer */
112 int vtty_store_ctrlc(vtty_t *);
113
114 /* Initialize the VTTY thread */
115 int vtty_init(void);
116
117 #endif

  ViewVC Help
Powered by ViewVC 1.1.26