Tools for working with Cidco Mailstations
1/*
2 * tribble_getty
3 *
4 * must be run as root to set iopl and use inb/outb
5 *
6 * interfaces getty(8) to the parallel port tribble routines for sending and
7 * receiving bytes
8 *
9 */
10
11#include <stdio.h>
12#include <stdlib.h>
13#include <string.h>
14#include <signal.h>
15#include <err.h>
16#include <errno.h>
17#include <unistd.h>
18#include <termios.h>
19#include <util.h>
20#include <sys/types.h>
21#include <sys/stat.h>
22
23#include "tribble.h"
24
25void
26usage(void)
27{
28 printf("usage: %s [-d] [-p port address]\n", getprogname());
29 exit(1);
30}
31
32int
33main(int argc, char *argv[])
34{
35 struct timeval tv = { 0 };
36 unsigned char obuf[2];
37 size_t cc = 0;
38 fd_set rfds;
39 pid_t child;
40 int master, slave, ch, b;
41
42 while ((ch = getopt(argc, argv, "dp:")) != -1) {
43 switch (ch) {
44 case 'd':
45 tribble_debug = 1;
46 break;
47 case 'p':
48 tribble_port = (unsigned)strtol(optarg, NULL, 0);
49 if (errno)
50 err(1, "invalid port value");
51 break;
52 default:
53 usage();
54 }
55 }
56 argc -= optind;
57 argv += optind;
58
59 if (argc != 0)
60 usage();
61
62 checkio();
63
64 printf("[port 0x%x]\n", tribble_port);
65
66 if (openpty(&master, &slave, NULL, NULL, NULL) == -1)
67 errx(1, "openpty");
68
69 child = fork();
70 if (child == 0) {
71 char *argp[] = { "sh", "-c", "/usr/libexec/getty", NULL };
72
73 close(master);
74 login_tty(slave);
75
76 setenv("TERM", "vt100", 1);
77 setenv("LINES", "15", 1);
78 setenv("COLUMNS", "64", 1);
79
80 execv("/bin/sh", argp);
81 }
82
83 close(STDIN_FILENO);
84
85 for (;;) {
86 FD_ZERO(&rfds);
87 FD_SET(master, &rfds);
88 tv.tv_usec = 10;
89
90 if (cc == 0 && select(master + 1, &rfds, NULL, NULL, &tv)) {
91 cc = read(master, obuf, 1);
92 if (cc == -1 && errno == EINTR)
93 continue;
94 if (cc <= 0)
95 break;
96 }
97
98 if (cc > 0 && (sendbyte(obuf[0]) == 0)) {
99 cc--;
100#if 0
101 printf("sendbyte(0x%x): %c\n", obuf[0],
102 (obuf[0] >= 32 && obuf[0] <= 126 ?
103 obuf[0] : ' '));
104#endif
105 }
106
107 if (havetribble()) {
108 b = recvbyte();
109 if (b < 0) {
110 printf("recvbyte() failed\n");
111 continue;
112 }
113#if 0
114 printf("recvbyte() = 0x%x: %c\n", b,
115 (b >= 32 && b <= 126 ? b : ' '));
116#endif
117 write(master, &b, 1);
118 }
119 }
120
121 close(master);
122 close(slave);
123
124 return 0;
125}