annotate src/hftctl.c @ 380:8626e4521993 r21-2-5

Import from CVS: tag r21-2-5
author cvs
date Mon, 13 Aug 2007 11:07:10 +0200
parents 376386a54a3c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 /* IBM has disclaimed copyright on this module. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 /* Synched up with: FSF 19.30. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 /***************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 /* */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 /* Function: hftctl */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 /* */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 /* Syntax: */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 /* #include <sys/ioctl.h> */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 /* #include <sys/hft.h> */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 /* */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 /* int hftctl(fildes, request, arg ) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 /* int fildes, request; */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 /* char *arg; */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 /* */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 /* Description: */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 /* */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 /* Does the following: */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 /* 1. determines if fildes is pty */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 /* does normal ioctl it is not */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 /* 2. places fildes into raw mode */
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 0
diff changeset
23 /* 3. converts ioctl arguments to data stream */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 /* 4. waits for 2 secs for acknowledgement before */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 /* timing out. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 /* 5. places response in callers buffer ( just like */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 /* ioctl. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 /* 6. returns fildes to its original mode */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 /* */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 /* User of this program should review steps 1,4, and 3. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 /* hftctl makes no check on the request type. It must be */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 /* a HFT ioctl that is supported remotely. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 /* This program will use the SIGALRM and alarm(2). Any */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 /* Previous alarms are lost. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 /* */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 /* Users of this program are free to modify it any way */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 /* they want. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 /* */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 /* Return Value: */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 /* */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 /* If ioctl fails, a value of -1 is returned and errno */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 /* is set to indicate the error. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 /* */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 /***************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 #include <config.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 #include "lisp.h" /* encapsulated open, close, read, write */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 #include <sys/signal.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 #include <errno.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 #include <stdio.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 #include <fcntl.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 #include <setjmp.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 #include <sys/ioctl.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 #include <sys/devinfo.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 #include <termios.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 #include <termio.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 #include <sys/hft.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 #include <sys/uio.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 #include <sys/tty.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 /* #include <sys/pty.h> */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 #define REMOTE 0x01
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 #undef ioctl
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 static char SCCSid[] = "com/gnuemacs/src,3.1,9021-90/05/03-5/3/90";
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 /*************** LOCAL DEFINES **********************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 #define QDEV ((HFQPDEVCH<<8)|HFQPDEVCL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 #define QLOC ((HFQLOCCH<<8)|HFQLOCCL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 #define QPS ((HFQPRESCH<<8)|HFQPRESCL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 #ifndef TCGETS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 #define TCGETS TCGETA
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 #ifndef TCSETS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 #define TCSETS TCSETA
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 /*************** EXTERNAL / GLOBAL DATA AREA ********************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 static int hfqry();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 static int hfskbd();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 extern int errno;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 static JMP_BUF hftenv;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 static int is_ack_vtd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 static SIGTYPE (*sav_alrm) ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 static struct hfctlreq req =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 { 0x1b,'[','x',0,0,0,21,HFCTLREQCH,HFCTLREQCL};
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 static struct hfctlack ACK =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 { 0x1b,'[','x',0,0,0,21,HFCTLACKCH,HFCTLACKCL};
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 /* FUNC signal(); */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 /*************** LOCAL MACROS ***********************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 #define HFTYPE(p) ((p->hf_typehi<<8)|(p->hf_typelo))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 #define BYTE4(p) ((p)[0]<<24 | (p)[1]<<16 | (p)[2]<<8 | (p)[3])
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 /* read a buffer */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 #define RD_BUF(f,p,l) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 while ((l)) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 if ((j = read((f),(p),(l))) < 0) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 if (errno != EINTR) return (-1); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 else continue; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 else { (l) -= j; (p) += j; }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 /*************** function prototypes ***************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 #ifdef __STDC__
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 static GT_ACK (int fd, int req, char *buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 static WR_REQ (int fd, int request, int cmdlen, char *cmd, int resplen);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 static void hft_alrm(int sig);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 static GT_ACK ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 static WR_REQ ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 static void hft_alrm ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 /*************** HFTCTL FUNCTION *******************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 hftctl (fd, request, arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 int fd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 int request;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 union {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 struct hfintro *intro;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 struct hfquery *query;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 char *c;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 } arg;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 int fd_flag; /* fcntl flags */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 union {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 struct hfintro *cmd; /* p.cmd - intro des. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 struct hfqphdevc *ph; /* p.ph - physical dev.*/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 char *c; /* p.c - char ptr */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 } p; /* general pointer */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 int pty_new; /* pty modes */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 int pty_old;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 int retcode;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 struct termios term_new; /* terminal attributes */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 struct termios term_old;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 struct devinfo devInfo; /* defined in sys/devinfo.h */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 if (ioctl (fd, IOCINFO, &devInfo) == -1) return(-1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 if (devInfo.devtype != DD_PSEU) /* is it a pty? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 return (ioctl(fd, request, arg)); /* no, do IOCTL */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 /******* START PTY **************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 /** Pty found, possible HFT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 /** set new file des as raw */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 /** as you can. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 /********************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 /* Get current state of file */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 /* descriptor & save */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 if ((fd_flag = fcntl (fd, F_GETFL, 0)) == -1) return (-1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 if (ioctl (fd, TCGETS, &term_old) == -1) return (-1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 /* set terminal attr to raw */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 /* and to delay on read */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 pty_new = pty_old | REMOTE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 memcpy (&term_new, &term_old, sizeof (term_new));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 term_new.c_iflag = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 term_new.c_oflag = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 term_new.c_lflag = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 /* term_new.c_line = 0; */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 for (i = 1; i <= 5; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 term_new.c_cc[i] = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 term_new.c_cc[0] = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 ioctl (fd, TCSETS, &term_new);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 if (fcntl (fd, F_SETFL, fd_flag & ~O_NDELAY) == -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 return(-1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 /* call spacific function */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 if (request == HFSKBD)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 retcode = hfskbd (fd, request, arg.c);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 else /* assume HFQUERY */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 retcode = hfqry (fd, request, arg.c);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 fcntl (fd, F_SETFL, fd_flag); /* reset terminal to original */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 ioctl (fd, TCSETS, &term_old);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 return (retcode); /* return error */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 /*************** HFSKBD FUNCTION ******************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 hfskbd (fd, request, arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 int fd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 int request;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 struct hfbuf *arg;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 WR_REQ(fd, request, arg->hf_buflen, arg->hf_bufp,0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 return (GT_ACK(fd, request, arg->hf_bufp));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 /*************** HFQUERY FUNCTION ******************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 hfqry (fd, request, arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 int fd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 int request;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 struct hfquery *arg;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 WR_REQ(fd, request, arg->hf_cmdlen, arg->hf_cmd, arg->hf_resplen);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 return (GT_ACK(fd, request, arg->hf_resp));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 /*************** GT_ACK FUNCTION ******************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 GT_ACK (fd, req, buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 int fd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 int req;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 char *buf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 struct hfctlack ack;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 int i = sizeof (ack);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 int j = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 union {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 char *c;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 struct hfctlack *ack;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 } p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 is_ack_vtd = 0; /* flag no ACT VTD yet */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 if (SETJMP (hftenv)) /* set environment in case */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 { /* of time out */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 errno = ENODEV; /* if time out, set errno */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 return (-1); /* flag error */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 alarm(3); /* time out in 3 secs */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 sav_alrm = signal (SIGALRM, hft_alrm); /* prepare to catch time out */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 p.ack = &ack;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 while (! is_ack_vtd) /* do until valid ACK VTD */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 RD_BUF(fd, p.c, i); /* read until a ACK VTD is fill*/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 if (! memcmp (&ack, &ACK, sizeof (HFINTROSZ)) /* the ACK intro & */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 && (ack.hf_request == req)) /* is it the response we want ?*/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 { /* yes, ACK VTD found */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 is_ack_vtd = 1; /* quickly, flag it */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 break; /* get the %$%#@ out of here */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 p.ack = &ack; /* no, then skip 1st */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 ++p.c; /* char and start over */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 i = sizeof (ack) - 1; /* one less ESC to cry over */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 while ((*p.c != 0x1b) && i) /* scan for next ESC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 { ++p.c; --i; } /* if any */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 (i ? memcpy (&ack, p.c, i) : 0); /* if any left over, then move */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 p.ack = &ack; /* ESC to front of ack struct */
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 0
diff changeset
262 p.c += i; /* skip over what's been read */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 0
diff changeset
263 i = sizeof (ack) - i; /* set what's left to be read */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 } /***** TRY AGAIN */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 alarm(0); /* ACK VTD received, reset alrm*/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 signal (SIGALRM, sav_alrm); /* reset signal */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 if (i = ack.hf_arg_len) /* any data following ? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 { /* yes, */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 RD_BUF(fd,buf,i); /* read until it is received */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 if (errno = ack.hf_retcode) /* set errno based on returned */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 return (-1); /* code, if 0, then no error */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 return (0); /* if set, then error returned */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 /*************** HFT_ALRM FUNCTION ******************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 hft_alrm (sig) /* Function hft_alrm - handle */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 int sig; /* alarm signal */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 signal (SIGALRM, sav_alrm); /* reset to previous */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 if (is_ack_vtd) /* has ack vtd arrived ? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 return; /* yes, then continue */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 else /* no, then return with error */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 LONGJMP (hftenv, -1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 /*********************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 /*** ***/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 /*** NOTE: Both the HFCTLREQ and the arg structure should be ***/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 /*** sent in one io write operation. If terminal ***/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 /*** emulators are in NODELAY mode then multiple writes ***/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 /*** may cause bogus information to be read by the emulator ***/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 /*** depending on the timing. ***/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 /*** ***/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 /*********************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 WR_REQ (fd, request, cmdlen, cmd, resplen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 int fd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 int request;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 int cmdlen;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 char *cmd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 int resplen;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 struct {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 char *c;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 struct hfctlreq *req;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 } p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 int size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 req.hf_request = request;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 req.hf_arg_len = cmdlen;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 req.hf_rsp_len = resplen;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 if (cmdlen) /* if arg structure to pass */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 size = sizeof (struct hfctlreq) + cmdlen;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 if ((p.c = xmalloc(size)) == NULL) /* malloc one area */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 return (-1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 memcpy (p.c, &req, sizeof (req)); /* copy CTL REQ struct */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 memcpy (p.c + sizeof (req), cmd, cmdlen); /* copy arg struct */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 p.req = &req; /* otherwise use only CTL REQ */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 size = sizeof (req);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 /* write request to terminal */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 if (write(fd,p.c,size) == -1) return (-1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 if (p.req != &req) /* free if allocated */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 xfree (p.c);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 return (0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 }