UPDATING: Mention that bt(4) is PCI only now.
[dragonfly.git] / usr.sbin / stallion / stlstty / stlstty.c
1 /*****************************************************************************/
2
3 /*
4  * stlstty.c  -- stallion intelligent multiport special options.
5  *
6  * Copyright (c) 1996-1998 Greg Ungerer (gerg@stallion.oz.au).
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 3. All advertising materials mentioning features or use of this software
18  *    must display the following acknowledgement:
19  *      This product includes software developed by Greg Ungerer.
20  * 4. Neither the name of the author nor the names of any co-contributors
21  *    may be used to endorse or promote products derived from this software
22  *    without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34  * SUCH DAMAGE.
35  *
36  * $FreeBSD: src/usr.sbin/stallion/stlstty/stlstty.c,v 1.1.2.1 2001/08/30 12:29:56 murray Exp $
37  * $DragonFly: src/usr.sbin/stallion/stlstty/stlstty.c,v 1.4 2007/11/25 01:28:24 swildner Exp $
38  */
39
40 /*****************************************************************************/
41
42 #include <err.h>
43 #include <fcntl.h>
44 #include <stdio.h>
45 #include <stdlib.h>
46 #include <string.h>
47 #include <unistd.h>
48 #include <sys/ioctl.h>
49
50 #include <machine/cdk.h>
51
52 /*****************************************************************************/
53
54 char    *version = "2.0.0";
55
56 /*
57  *      Define some marker flags (to append to pflag values).
58  */
59 #define PFLAG_ON        0x40000000
60 #define PFLAG_OFF       0x80000000
61
62 /*
63  *      List of all options used. Use the option structure even though we
64  *      don't use getopt!
65  */
66 struct stloption {
67         char    *name;
68         int     val;
69 };
70
71
72 /*
73  *      List of all options used. Use the option structure even though we
74  *      don't use getopt!
75  */
76 struct stloption longops[] = {
77         { "-V", 'V' },
78         { "--version", 'V' },
79         { "-?", 'h' },
80         { "-h", 'h' },
81         { "--help", 'h' },
82         { "maprts", (PFLAG_ON | P_MAPRTS) },
83         { "-maprts", (PFLAG_OFF | P_MAPRTS) },
84         { "mapcts", (PFLAG_ON | P_MAPCTS) },
85         { "-mapcts", (PFLAG_OFF | P_MAPCTS) },
86         { "rtslock", (PFLAG_ON | P_RTSLOCK) },
87         { "-rtslock", (PFLAG_OFF | P_RTSLOCK) },
88         { "ctslock", (PFLAG_ON | P_CTSLOCK) },
89         { "-ctslock", (PFLAG_OFF | P_CTSLOCK) },
90         { "loopback", (PFLAG_ON | P_LOOPBACK) },
91         { "-loopback", (PFLAG_OFF | P_LOOPBACK) },
92         { "fakedcd", (PFLAG_ON | P_FAKEDCD) },
93         { "-fakedcd", (PFLAG_OFF | P_FAKEDCD) },
94         { "dtrfollow", (PFLAG_ON | P_DTRFOLLOW) },
95         { "-dtrfollow", (PFLAG_OFF | P_DTRFOLLOW) },
96         { "rximin", (PFLAG_ON | P_RXIMIN) },
97         { "-rximin", (PFLAG_OFF | P_RXIMIN) },
98         { "rxitime", (PFLAG_ON | P_RXITIME) },
99         { "-rxitime", (PFLAG_OFF | P_RXITIME) },
100         { "rxthold", (PFLAG_ON | P_RXTHOLD) },
101         { "-rxthold", (PFLAG_OFF | P_RXTHOLD) },
102         { 0, 0 }
103 };
104
105 /* Function prototypes */
106 void getpflags(void);
107 void setpflags(unsigned long , unsigned long );
108
109 /*****************************************************************************/
110
111 /*
112  *      Declare internal function prototypes here.
113  */
114 static void     usage(void);
115
116 /*****************************************************************************/
117
118 static void
119 usage(void)
120 {
121         fprintf(stderr, "Usage: stlstty [OPTION] [ARGS]\n\n");
122         fprintf(stderr, "  -h, --help            print this information\n");
123         fprintf(stderr, "  -V, --version         show version information "
124                 "and exit\n");
125         fprintf(stderr, "  maprts, -maprts       set RTS mapping to DTR "
126                 "on or off\n");
127         fprintf(stderr, "  mapcts, -mapcts       set CTS mapping to DCD "
128                 "on or off\n");
129         fprintf(stderr, "  rtslock, -rtslock     set RTS hardware flow "
130                 "on or off\n");
131         fprintf(stderr, "  ctslock, -ctslock     set CTS hardware flow "
132                 "on or off\n");
133         fprintf(stderr, "  fakedcd, -fakedcd     set fake DCD on or off\n");
134         fprintf(stderr, "  dtrfollow, -dtrfollow set DTR data follow "
135                 "on or off\n");
136         fprintf(stderr, "  loopback, -loopback   set port internal loop back "
137                 "on or off\n");
138         fprintf(stderr, "  rximin, -rximin       set RX buffer minimum "
139                 "count on or off\n");
140         fprintf(stderr, "  rxitime, -rxitime     set RX buffer minimum "
141                 "time on or off\n");
142         fprintf(stderr, "  rxthold, -rxthold     set RX FIFO minimum "
143                 "count on or off\n");
144         exit(0);
145 }
146
147 /*****************************************************************************/
148
149 void
150 getpflags(void)
151 {
152         unsigned long   pflags;
153
154         if (ioctl(0, STL_GETPFLAG, &pflags) < 0)
155                 errx(1, "stdin not a Stallion serial port\n");
156
157         if (pflags & P_MAPRTS)
158                 printf("maprts ");
159         else
160                 printf("-maprts ");
161         if (pflags & P_MAPCTS)
162                 printf("mapcts ");
163         else
164                 printf("-mapcts ");
165
166         if (pflags & P_RTSLOCK)
167                 printf("rtslock ");
168         else
169                 printf("-rtslock ");
170         if (pflags & P_CTSLOCK)
171                 printf("ctslock ");
172         else
173                 printf("-ctslock ");
174
175         if (pflags & P_FAKEDCD)
176                 printf("fakedcd ");
177         else
178                 printf("-fakedcd ");
179         if (pflags & P_DTRFOLLOW)
180                 printf("dtrfollow ");
181         else
182                 printf("-dtrfollow ");
183         if (pflags & P_LOOPBACK)
184                 printf("loopback ");
185         else
186                 printf("-loopback ");
187         printf("\n");
188
189         if (pflags & P_RXIMIN)
190                 printf("rximin ");
191         else
192                 printf("-rximin ");
193         if (pflags & P_RXITIME)
194                 printf("rxitime ");
195         else
196                 printf("-rxitime ");
197         if (pflags & P_RXTHOLD)
198                 printf("rxthold ");
199         else
200                 printf("-rxthold ");
201         printf("\n");
202 }
203
204 /*****************************************************************************/
205
206 void
207 setpflags(unsigned long pflagin, unsigned long pflagout)
208 {
209         unsigned long   pflags;
210
211         if (ioctl(0, STL_GETPFLAG, &pflags) < 0)
212                 errx(1, "stdin not a Stallion serial port\n");
213         
214
215         pflags &= ~(pflagout & ~PFLAG_OFF);
216         pflags |= (pflagin & ~PFLAG_ON);
217
218         if (ioctl(0, STL_SETPFLAG, &pflags) < 0)
219                 err(1, "ioctl(SET_SETPFLAGS) failed");
220 }
221
222 /*****************************************************************************/
223
224 int
225 main(int argc, char *argv[])
226 {
227         unsigned long   pflagin, pflagout;
228         int             optind, optfound;
229         int             i, val;
230
231         pflagin = 0;
232         pflagout = 0;
233
234         for (optind = 1; (optind < argc); optind++) {
235                 optfound = 0;
236                 for (i = 0; (longops[i].name[0] != 0) ; i++) {
237                         if (strcmp(argv[optind], &(longops[i].name[0])) == 0) {
238                                 val = longops[i].val;
239                                 optfound++;
240                                 break;
241                         }
242                 }
243                 if (optfound == 0)
244                         errx(1, "invalid option '%s'\n", argv[optind]);
245
246                 switch (val) {
247                 case 'V':
248                         printf("stlstats version %s\n", version);
249                         exit(0);
250                         break;
251                 case 'h':
252                         usage();
253                         break;
254                 default:
255                         if (val & PFLAG_ON) {
256                                 pflagin |= val;
257                         } else if (val & PFLAG_OFF) {
258                                 pflagout |= val;
259                         } else {
260                                 errx(1, "unknown option found, val=%x!\n", val);
261                         }
262                 }
263         }
264
265         if (pflagin | pflagout)
266                 setpflags(pflagin, pflagout);
267         else
268                 getpflags();
269
270         exit(0);
271 }
272
273 /*****************************************************************************/