1 /*
2  * Copyright 1996, 1997, 1998, 1999 by Daniel B. Suthers,
3  * Pleasanton Ca. 94588 USA
4  * E-MAIL dbs@tanj.com
5  *
6  */
7 
8 /*
9  *   This program is free software: you can redistribute it and/or modify
10  *   it under the terms of the GNU General Public License as published by
11  *   the Free Software Foundation, either version 3 of the License, or
12  *   (at your option) any later version.
13  *
14  *   This program is distributed in the hope that it will be useful,
15  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *   GNU General Public License for more details.
18  *
19  *   You should have received a copy of the GNU General Public License
20  *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  */
23 
24 
25 #include <stdio.h>
26 #include <ctype.h>
27 
28 #ifdef        SCO
29 #define _SVID3 /* required for correct termio handling */
30 #undef  _IBCS2 /* conflicts with SVID3  */
31 #endif
32 
33 #include <time.h>
34 #include <unistd.h>
35 
36 #ifdef LINUX
37 #include <asm/ioctls.h>
38 #   ifdef OLDLINUX
39 #include <linux/serial_reg.h>
40 #   endif
41 #include <linux/serial.h>
42 #include <sys/ioctl.h>
43 #include <unistd.h>
44 #include <syslog.h>
45 #else
46 #    if (defined(POSIX) || defined(FREEBSD) || defined(OPENBSD))
47 #include <sys/ttycom.h>
48 #    else
49 #         ifdef SCO
50 #include <sys/ttycom.h>
51 #         else
52 #              ifdef DARWIN
53 #include <sys/ttycom.h>
54 #              else
55 #include <sys/ttycom.h>
56 #              endif
57 #         endif
58 #    endif
59 #endif
60 
61 #if (defined(OSF) || defined(DARWIN))
62 #include <sys/ioctl.h>
63 #endif
64 
65 #include <string.h>
66 
67 #include "x10.h"
68 #include "process.h"
69 
70 extern int verbose;
71 extern int sptty;
72 extern int ttylock(), munlock();
73 extern int i_am_relay;
74 
75 
76 /* This process echoes all strings to the spool file as well as
77  * sending them to the CM11A's tty port
78  */
xwrite(int tty,char * buf,int size)79 int xwrite( int tty, char *buf, int size)
80 {
81     static unsigned char template[4] = {0xff, 0xff, 0xff, 0x00};
82     unsigned char        outbuf[160];
83     int                  max = 0;
84 
85     int ignoret;
86 
87     template[3] = size;
88     memcpy(outbuf, template, 4);
89     memcpy(outbuf + 4, buf, size);
90 
91     ignoret = write(sptty, (char *)outbuf, size + 4);
92 
93     /* Command to state engine is written to sptty only */
94     if ( buf[0] == ST_COMMAND && size == 3 )
95        return 3;
96 
97     if ( verbose && !i_am_relay )
98        fprintf(stdout, "xwrite() called, count=%d\n", size );
99 
100     max = write( tty, buf, size);
101 
102     return(max);
103 }
104 
105 
106 
107