1/*-
2 * Copyright (c) 2010, Oracle America, Inc.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 *     * Redistributions of source code must retain the above copyright
9 *       notice, this list of conditions and the following disclaimer.
10 *     * Redistributions in binary form must reproduce the above
11 *       copyright notice, this list of conditions and the following
12 *       disclaimer in the documentation and/or other materials
13 *       provided with the distribution.
14 *     * Neither the name of the "Oracle America, Inc." nor the names of its
15 *       contributors may be used to endorse or promote products derived
16 *       from this software without specific prior written permission.
17 *
18 *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 *   FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22 *   COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23 *   INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 *   DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
25 *   GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 *   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27 *   WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 *   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32/*
33 * Remote execution (rex) protocol specification
34 */
35
36const STRINGSIZE = 1024;
37typedef string rexstring<1024>;
38
39/*
40 * values to pass to REXPROC_SIGNAL
41 */
42const SIGINT = 2;	/* interrupt */
43
44/*
45 * Values for rst_flags, below
46 */
47const REX_INTERACTIVE = 1;	/* interactive mode */
48
49struct rex_start {
50	rexstring rst_cmd<>;	/* list of command and args */
51	rexstring rst_host;	/* working directory host name */
52	rexstring rst_fsname;	/* working directory file system name */
53	rexstring rst_dirwithin;/* working directory within file system */
54	rexstring rst_env<>;	/* list of environment */
55	unsigned int rst_port0;	/* port for stdin */
56	unsigned int rst_port1;	/* port for stdout */
57	unsigned int rst_port2;	/* port for stderr */
58	unsigned int rst_flags;	/* options - see const above */
59};
60
61struct rex_result {
62   	int rlt_stat;		/* integer status code */
63	rexstring rlt_message;	/* string message for human consumption */
64};
65
66
67struct sgttyb {
68	unsigned four;	/* always equals 4 */
69	opaque chars[4];
70	/* chars[0] == input speed */
71	/* chars[1] == output speed */
72	/* chars[2] == kill character */
73	/* chars[3] == erase character */
74	unsigned flags;
75};
76/* values for speeds above (baud rates)  */
77const B0  = 0;
78const B50 = 1;
79const B75 = 2;
80const B110 = 3;
81const B134 = 4;
82const B150 = 5;
83const B200 = 6;
84const B300 = 7;
85const B600 = 8;
86const B1200 = 9;
87const B1800 = 10;
88const B2400 = 11;
89const B4800 = 12;
90const B9600 = 13;
91const B19200 = 14;
92const B38400 = 15;
93
94/* values for flags above */
95const TANDEM = 0x00000001; /* send stopc on out q full */
96const CBREAK = 0x00000002; /* half-cooked mode */
97const LCASE = 0x00000004; /* simulate lower case */
98const ECHO = 0x00000008; /* echo input */
99const CRMOD = 0x00000010; /* map \r to \r\n on output */
100const RAW = 0x00000020; /* no i/o processing */
101const ODDP = 0x00000040; /* get/send odd parity */
102const EVENP = 0x00000080; /* get/send even parity */
103const ANYP = 0x000000c0; /* get any parity/send none */
104const NLDELAY = 0x00000300; /* \n delay */
105const  NL0 = 0x00000000;
106const  NL1 = 0x00000100; /* tty 37 */
107const  NL2 = 0x00000200; /* vt05 */
108const  NL3 = 0x00000300;
109const TBDELAY = 0x00000c00; /* horizontal tab delay */
110const  TAB0 = 0x00000000;
111const  TAB1 = 0x00000400; /* tty 37 */
112const  TAB2 = 0x00000800;
113const XTABS = 0x00000c00; /* expand tabs on output */
114const CRDELAY = 0x00003000; /* \r delay */
115const  CR0 = 0x00000000;
116const  CR1 = 0x00001000; /* tn 300 */
117const  CR2 = 0x00002000; /* tty 37 */
118const  CR3 = 0x00003000; /* concept 100 */
119const VTDELAY = 0x00004000; /* vertical tab delay */
120const  FF0 = 0x00000000;
121const  FF1 = 0x00004000; /* tty 37 */
122const BSDELAY = 0x00008000; /* \b delay */
123const  BS0 = 0x00000000;
124const  BS1 = 0x00008000;
125const CRTBS = 0x00010000; /* do backspacing for crt */
126const PRTERA = 0x00020000; /* \ ... / erase */
127const CRTERA = 0x00040000; /* " \b " to wipe out char */
128const TILDE = 0x00080000; /* hazeltine tilde kludge */
129const MDMBUF = 0x00100000; /* start/stop output on carrier intr */
130const LITOUT = 0x00200000; /* literal output */
131const TOSTOP = 0x00400000; /* SIGTTOU on background output */
132const FLUSHO = 0x00800000; /* flush output to terminal */
133const NOHANG = 0x01000000; /* no SIGHUP on carrier drop */
134const L001000 = 0x02000000;
135const CRTKIL = 0x04000000; /* kill line with " \b " */
136const PASS8 = 0x08000000;
137const CTLECH = 0x10000000; /* echo control chars as ^X */
138const PENDIN = 0x20000000; /* tp->t_rawq needs reread */
139const DECCTQ = 0x40000000; /* only ^Q starts after ^S */
140const NOFLSH = 0x80000000; /* no output flush on signal */
141
142struct tchars {
143	unsigned six;	/* always equals 6 */
144	opaque chars[6];
145	/* chars[0] == interrupt char */
146	/* chars[1] == quit char */
147	/* chars[2] == start output char */
148	/* chars[3] == stop output char */
149	/* chars[4] == end-of-file char */
150	/* chars[5] == input delimeter (like nl) */
151};
152
153struct ltchars {
154	unsigned six;	/* always equals 6 */
155	opaque chars[6];
156	/* chars[0] == stop process signal */
157	/* chars[1] == delayed stop process signal */
158	/* chars[2] == reprint line */
159	/* chars[3] == flush output */
160	/* chars[4] == word erase */
161	/* chars[5] == literal next character */
162	unsigned mode;
163};
164
165struct rex_ttysize {
166	int ts_lines;
167	int ts_cols;
168};
169
170struct rex_ttymode {
171    sgttyb basic;    /* standard unix tty flags */
172    tchars more; /* interrupt, kill characters, etc. */
173    ltchars yetmore; /* special Berkeley characters */
174    unsigned andmore;     /* and Berkeley modes */
175};
176
177/* values for andmore above */
178const LCRTBS = 0x0001;	/* do backspacing for crt */
179const LPRTERA = 0x0002;	/* \ ... / erase */
180const LCRTERA = 0x0004;	/* " \b " to wipe out char */
181const LTILDE = 0x0008;	/* hazeltine tilde kludge */
182const LMDMBUF = 0x0010;	/* start/stop output on carrier intr */
183const LLITOUT = 0x0020;	/* literal output */
184const LTOSTOP = 0x0040;	/* SIGTTOU on background output */
185const LFLUSHO = 0x0080;	/* flush output to terminal */
186const LNOHANG = 0x0100;	/* no SIGHUP on carrier drop */
187const LL001000 = 0x0200;
188const LCRTKIL = 0x0400;	/* kill line with " \b " */
189const LPASS8 = 0x0800;
190const LCTLECH = 0x1000;	/* echo control chars as ^X */
191const LPENDIN = 0x2000;	/* needs reread */
192const LDECCTQ = 0x4000;	/* only ^Q starts after ^S */
193const LNOFLSH = 0x8000;	/* no output flush on signal */
194
195program REXPROG {
196	version REXVERS {
197
198		/*
199		 * Start remote execution
200		 */
201		rex_result
202		REXPROC_START(rex_start) = 1;
203
204		/*
205		 * Wait for remote execution to terminate
206		 */
207		rex_result
208		REXPROC_WAIT(void) = 2;
209
210		/*
211		 * Send tty modes
212		 */
213		void
214		REXPROC_MODES(rex_ttymode) = 3;
215
216		/*
217		 * Send window size change
218		 */
219		void
220		REXPROC_WINCH(rex_ttysize) = 4;
221
222		/*
223		 * Send other signal
224		 */
225		void
226		REXPROC_SIGNAL(int) = 5;
227	} = 1;
228} = 100017;
229