]> git.ipfire.org Git - thirdparty/cups.git/blame - backend/serial.c
Merge changes from 1.1.x into 1.2 devel.
[thirdparty/cups.git] / backend / serial.c
CommitLineData
43e2fc22 1/*
753453e4 2 * "$Id: serial.c,v 1.32.2.1 2001/12/26 16:52:07 mike Exp $"
43e2fc22 3 *
e73c6c0a 4 * Serial port backend for the Common UNIX Printing System (CUPS).
43e2fc22 5 *
d2935a0f 6 * Copyright 1997-2001 by Easy Software Products, all rights reserved.
43e2fc22 7 *
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
13 * at:
14 *
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
8784b6a6 17 * 44141 Airport View Drive, Suite 204
43e2fc22 18 * Hollywood, Maryland 20636-3111 USA
19 *
20 * Voice: (301) 373-9603
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
23 *
24 * Contents:
25 *
a3e17a89 26 * main() - Send a file to the printer or server.
27 * list_devices() - List all serial devices.
43e2fc22 28 */
29
30/*
31 * Include necessary headers.
32 */
33
e73c6c0a 34#include <cups/cups.h>
35#include <stdio.h>
36#include <stdlib.h>
a3e17a89 37#include <errno.h>
e73c6c0a 38#include <cups/string.h>
4ff40357 39#include <signal.h>
e73c6c0a 40
8c8c32b0 41#ifdef __hpux
42# include <sys/modem.h>
43#endif /* __hpux */
44
7c88bf41 45#if defined(WIN32) || defined(__EMX__)
46# include <io.h>
47#else
48# include <unistd.h>
49# include <fcntl.h>
50# include <termios.h>
957d43b0 51# ifdef HAVE_SYS_IOCTL_H
c3258d2d 52# include <sys/ioctl.h>
f30537c6 53# endif /* HAVE_SYS_IOCTL_H */
7c88bf41 54#endif /* WIN32 || __EMX__ */
55
92a63e4c 56#ifdef __sgi
57# include <invent.h>
58# ifndef INV_EPP_ECP_PLP
59# define INV_EPP_ECP_PLP 6 /* From 6.3/6.4/6.5 sys/invent.h */
60# define INV_ASO_SERIAL 14 /* serial portion of SGI ASO board */
61# define INV_IOC3_DMA 16 /* DMA mode IOC3 serial */
62# define INV_IOC3_PIO 17 /* PIO mode IOC3 serial */
63# define INV_ISA_DMA 19 /* DMA mode ISA serial -- O2 */
64# endif /* !INV_EPP_ECP_PLP */
65#endif /* __sgi */
66
14aa7027 67#ifndef CRTSCTS
68# ifdef CNEW_RTSCTS
69# define CRTSCTS CNEW_RTSCTS
70# else
71# define CRTSCTS 0
72# endif /* CNEW_RTSCTS */
73#endif /* !CRTSCTS */
74
e73c6c0a 75
68edc300 76/*
77 * Local functions...
78 */
79
80void list_devices(void);
81
82
e73c6c0a 83/*
84 * 'main()' - Send a file to the printer or server.
85 *
86 * Usage:
87 *
88 * printer-uri job-id user title copies options [file]
89 */
90
91int /* O - Exit status */
92main(int argc, /* I - Number of command-line arguments (6 or 7) */
93 char *argv[]) /* I - Command-line arguments */
94{
7c88bf41 95 char method[255], /* Method in URI */
96 hostname[1024], /* Hostname */
97 username[255], /* Username info (not used) */
98 resource[1024], /* Resource info (device and options) */
99 *options, /* Pointer to options */
100 name[255], /* Name of option */
101 value[255], /* Value of option */
102 *ptr; /* Pointer into name or value */
103 int port; /* Port number (not used) */
104 FILE *fp; /* Print file */
3f9cb6c6 105 int copies; /* Number of copies to print */
7c88bf41 106 int fd; /* Parallel device */
1c33ff6a 107 int wbytes; /* Number of bytes written */
108 size_t nbytes, /* Number of bytes read */
7c88bf41 109 tbytes; /* Total number of bytes written */
14aa7027 110 int dtrdsr; /* Do dtr/dsr flow control? */
111 int bufsize; /* Size of output buffer for writes */
1c33ff6a 112 char buffer[8192], /* Output buffer */
113 *bufptr; /* Pointer into buffer */
7c88bf41 114 struct termios opts; /* Parallel port options */
4ff40357 115#if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
116 struct sigaction action; /* Actions for POSIX signals */
117#endif /* HAVE_SIGACTION && !HAVE_SIGSET */
7c88bf41 118
119
4b23f3b3 120 /*
121 * Make sure status messages are not buffered...
122 */
123
124 setbuf(stderr, NULL);
125
126 /*
127 * Check command-line...
128 */
129
68edc300 130 if (argc == 1)
131 {
132 list_devices();
133 return (0);
134 }
135 else if (argc < 6 || argc > 7)
e73c6c0a 136 {
7c88bf41 137 fputs("Usage: serial job-id user title copies options [file]\n", stderr);
e73c6c0a 138 return (1);
139 }
140
7c88bf41 141 /*
142 * If we have 7 arguments, print the file named on the command-line.
143 * Otherwise, send stdin instead...
144 */
145
146 if (argc == 6)
3f9cb6c6 147 {
148 fp = stdin;
149 copies = 1;
150 }
7c88bf41 151 else
152 {
153 /*
154 * Try to open the print file...
155 */
156
157 if ((fp = fopen(argv[6], "rb")) == NULL)
158 {
decc1f36 159 perror("ERROR: unable to open print file");
7c88bf41 160 return (1);
161 }
3f9cb6c6 162
163 copies = atoi(argv[4]);
7c88bf41 164 }
165
166 /*
167 * Extract the device name and options from the URI...
168 */
169
170 httpSeparate(argv[0], method, username, hostname, &port, resource);
171
172 /*
173 * See if there are any options...
174 */
175
176 if ((options = strchr(resource, '?')) != NULL)
177 {
178 /*
179 * Yup, terminate the device name string and move to the first
180 * character of the options...
181 */
182
183 *options++ = '\0';
184 }
185
186 /*
8ec4b03f 187 * Open the serial port device...
7c88bf41 188 */
189
a3e17a89 190 do
7c88bf41 191 {
753453e4 192 if ((fd = open(resource, O_WRONLY | O_NOCTTY | O_EXCL | O_NDELAY)) == -1)
a3e17a89 193 {
194 if (errno == EBUSY)
195 {
196 fputs("INFO: Serial port busy; will retry in 30 seconds...\n", stderr);
197 sleep(30);
198 }
199 else
200 {
201 perror("ERROR: Unable to open serial port device file");
202 return (1);
203 }
204 }
7c88bf41 205 }
a3e17a89 206 while (fd < 0);
7c88bf41 207
208 /*
209 * Set any options provided...
210 */
211
212 tcgetattr(fd, &opts);
213
214 opts.c_lflag &= ~(ICANON | ECHO | ISIG); /* Raw mode */
753453e4 215 opts.c_oflag &= ~OPOST; /* Don't post-process */
7c88bf41 216
753453e4 217 bufsize = 96; /* 9600 baud / 10 bits/char / 10Hz */
14aa7027 218 dtrdsr = 0; /* No dtr/dsr flow control */
219
7c88bf41 220 if (options != NULL)
221 while (*options)
222 {
223 /*
224 * Get the name...
225 */
226
227 for (ptr = name; *options && *options != '=';)
228 *ptr++ = *options++;
229 *ptr = '\0';
230
231 if (*options == '=')
232 {
233 /*
234 * Get the value...
235 */
236
237 options ++;
238
239 for (ptr = value; *options && *options != '+';)
240 *ptr++ = *options++;
241 *ptr = '\0';
242
243 if (*options == '+')
244 options ++;
245 }
246 else
247 value[0] = '\0';
248
249 /*
250 * Process the option...
251 */
252
253 if (strcasecmp(name, "baud") == 0)
254 {
255 /*
256 * Set the baud rate...
257 */
258
753453e4 259 bufsize = atoi(value) / 100;
14aa7027 260
7c88bf41 261#if B19200 == 19200
262 cfsetispeed(&opts, atoi(value));
263 cfsetospeed(&opts, atoi(value));
264#else
265 switch (atoi(value))
266 {
267 case 1200 :
268 cfsetispeed(&opts, B1200);
269 cfsetospeed(&opts, B1200);
270 break;
271 case 2400 :
272 cfsetispeed(&opts, B2400);
273 cfsetospeed(&opts, B2400);
274 break;
275 case 4800 :
276 cfsetispeed(&opts, B4800);
277 cfsetospeed(&opts, B4800);
278 break;
279 case 9600 :
280 cfsetispeed(&opts, B9600);
281 cfsetospeed(&opts, B9600);
282 break;
283 case 19200 :
284 cfsetispeed(&opts, B19200);
285 cfsetospeed(&opts, B19200);
286 break;
287 case 38400 :
288 cfsetispeed(&opts, B38400);
289 cfsetospeed(&opts, B38400);
290 break;
14aa7027 291#ifdef B57600
292 case 57600 :
293 cfsetispeed(&opts, B57600);
294 cfsetospeed(&opts, B57600);
295 break;
296#endif /* B57600 */
297#ifdef B115200
298 case 115200 :
299 cfsetispeed(&opts, B115200);
300 cfsetospeed(&opts, B115200);
301 break;
302#endif /* B115200 */
7c88bf41 303 default :
304 fprintf(stderr, "WARNING: Unsupported baud rate %s!\n", value);
305 break;
306 }
307#endif /* B19200 == 19200 */
308 }
309 else if (strcasecmp(name, "bits") == 0)
310 {
311 /*
312 * Set number of data bits...
313 */
314
315 switch (atoi(value))
316 {
317 case 7 :
318 opts.c_cflag &= ~CSIZE;
319 opts.c_cflag |= CS7;
320 opts.c_cflag |= PARENB;
321 opts.c_cflag &= ~PARODD;
322 break;
323 case 8 :
324 opts.c_cflag &= ~CSIZE;
325 opts.c_cflag |= CS8;
326 opts.c_cflag &= ~PARENB;
327 break;
328 }
329 }
330 else if (strcasecmp(name, "parity") == 0)
331 {
332 /*
333 * Set parity checking...
334 */
335
336 if (strcasecmp(value, "even") == 0)
337 {
338 opts.c_cflag |= PARENB;
339 opts.c_cflag &= ~PARODD;
340 }
341 else if (strcasecmp(value, "odd") == 0)
342 {
343 opts.c_cflag |= PARENB;
344 opts.c_cflag |= PARODD;
345 }
346 else if (strcasecmp(value, "none") == 0)
347 opts.c_cflag &= ~PARENB;
348 }
14aa7027 349 else if (strcasecmp(name, "flow") == 0)
350 {
351 /*
352 * Set flow control...
353 */
354
355 if (strcasecmp(value, "none") == 0)
356 {
357 opts.c_iflag &= ~(IXON | IXOFF | IXANY);
358 opts.c_cflag &= ~CRTSCTS;
359 }
360 else if (strcasecmp(value, "soft") == 0)
361 {
362 opts.c_iflag |= IXON | IXOFF | IXANY;
363 opts.c_cflag &= ~CRTSCTS;
364 }
365 else if (strcasecmp(value, "hard") == 0 ||
366 strcasecmp(value, "rtscts") == 0)
367 {
368 opts.c_iflag &= ~(IXON | IXOFF | IXANY);
369 opts.c_cflag |= CRTSCTS;
370 }
371 else if (strcasecmp(value, "dtrdsr") == 0)
372 {
373 opts.c_iflag &= ~(IXON | IXOFF | IXANY);
374 opts.c_cflag &= ~CRTSCTS;
375
376 dtrdsr = 1;
377 }
378 }
7c88bf41 379 }
380
381 tcsetattr(fd, TCSANOW, &opts);
753453e4 382 fcntl(fd, F_SETFL, 0);
7c88bf41 383
4ff40357 384 /*
385 * Now that we are "connected" to the port, ignore SIGTERM so that we
386 * can finish out any page data the driver sends (e.g. to eject the
387 * current page...
388 */
389
390#ifdef HAVE_SIGSET /* Use System V signals over POSIX to avoid bugs */
391 sigset(SIGTERM, SIG_IGN);
392#elif defined(HAVE_SIGACTION)
393 memset(&action, 0, sizeof(action));
394
395 sigemptyset(&action.sa_mask);
396 action.sa_handler = SIG_IGN;
397 sigaction(SIGTERM, &action, NULL);
398#else
399 signal(SIGTERM, SIG_IGN);
400#endif /* HAVE_SIGSET */
401
7c88bf41 402 /*
403 * Finally, send the print file...
404 */
405
14aa7027 406 if (bufsize > sizeof(buffer))
407 bufsize = sizeof(buffer);
408
3f9cb6c6 409 while (copies > 0)
7c88bf41 410 {
3f9cb6c6 411 copies --;
7c88bf41 412
3f9cb6c6 413 if (fp != stdin)
7c88bf41 414 {
3f9cb6c6 415 fputs("PAGE: 1 1\n", stderr);
416 rewind(fp);
7c88bf41 417 }
7c88bf41 418
14aa7027 419 if (dtrdsr)
420 {
421 /*
422 * Check the port and sleep until DSR is set...
423 */
424
425 int status;
426
427
428 if (!ioctl(fd, TIOCMGET, &status))
429 if (!(status & TIOCM_DSR))
430 {
431 /*
432 * Wait for DSR to go high...
433 */
434
435 fputs("DEBUG: DSR is low; waiting for device...\n", stderr);
436
437 do
438 {
439 sleep(1);
440 if (ioctl(fd, TIOCMGET, &status))
441 break;
442 }
443 while (!(status & TIOCM_DSR));
444
445 fputs("DEBUG: DSR is high; writing to device...\n", stderr);
446 }
447 }
448
3f9cb6c6 449 tbytes = 0;
14aa7027 450 while ((nbytes = fread(buffer, 1, bufsize, fp)) > 0)
3f9cb6c6 451 {
452 /*
453 * Write the print data to the printer...
454 */
455
1c33ff6a 456 tbytes += nbytes;
457 bufptr = buffer;
458
459 while (nbytes > 0)
3f9cb6c6 460 {
1c33ff6a 461 if ((wbytes = write(fd, bufptr, nbytes)) < 0)
462 if (errno == ENOTTY)
463 wbytes = write(fd, bufptr, nbytes);
464
465 if (wbytes < 0)
466 {
467 perror("ERROR: Unable to send print file to printer");
468 break;
469 }
470
471 nbytes -= wbytes;
472 bufptr += wbytes;
3f9cb6c6 473 }
3f9cb6c6 474
475 if (argc > 6)
476 fprintf(stderr, "INFO: Sending print file, %u bytes...\n", tbytes);
477 }
7c88bf41 478 }
479
480 /*
753453e4 481 * Close the serial port and input file and return...
7c88bf41 482 */
483
484 close(fd);
485 if (fp != stdin)
486 fclose(fp);
e73c6c0a 487
7c88bf41 488 return (0);
e73c6c0a 489}
43e2fc22 490
491
492/*
68edc300 493 * 'list_devices()' - List all serial devices.
494 */
495
496void
497list_devices(void)
498{
91b3b672 499#if defined(__hpux) || defined(__sgi) || defined(__sun) || defined(__FreeBSD__) || defined(__OpenBSD__)
92a63e4c 500 static char *funky_hex = "0123456789abcdefghijklmnopqrstuvwxyz";
501 /* Funky hex numbering used for some devices */
91b3b672 502#endif /* __hpux || __sgi || __sun || __FreeBSD__ || __OpenBSD__ */
92a63e4c 503
68edc300 504#ifdef __linux
505 int i; /* Looping var */
8ec4b03f 506 int fd; /* File descriptor */
68edc300 507 char device[255]; /* Device filename */
508
509
39dabc6c 510 for (i = 0; i < 100; i ++)
68edc300 511 {
512 sprintf(device, "/dev/ttyS%d", i);
a3e17a89 513 if ((fd = open(device, O_WRONLY | O_NOCTTY | O_NDELAY)) >= 0)
8ec4b03f 514 {
515 close(fd);
d4c438d4 516 printf("serial serial:%s?baud=115200 \"Unknown\" \"Serial Port #%d\"\n",
517 device, i + 1);
8ec4b03f 518 }
68edc300 519 }
520#elif defined(__sgi)
92a63e4c 521 int i, j, n; /* Looping vars */
522 char device[255]; /* Device filename */
523 inventory_t *inv; /* Hardware inventory info */
524
525
526 /*
527 * IRIX maintains a hardware inventory of most devices...
528 */
529
530 setinvent();
531
532 while ((inv = getinvent()) != NULL)
533 {
534 if (inv->inv_class == INV_SERIAL)
535 {
536 /*
537 * Some sort of serial port...
538 */
539
540 if (inv->inv_type == INV_CDSIO || inv->inv_type == INV_CDSIO_E)
541 {
542 /*
543 * CDSIO port...
544 */
545
546 for (n = 0; n < 6; n ++)
7c935cd3 547 printf("serial serial:/dev/ttyd%d?baud=38400 \"Unknown\" \"CDSIO Board %d Serial Port #%d\"\n",
92a63e4c 548 n + 5 + 8 * inv->inv_controller, inv->inv_controller, n + 1);
549 }
550 else if (inv->inv_type == INV_EPC_SERIAL)
551 {
552 /*
553 * Everest serial port...
554 */
555
556 if (inv->inv_unit == 0)
557 i = 1;
558 else
8a2c2126 559 i = 41 + 4 * (int)inv->inv_controller;
92a63e4c 560
8a2c2126 561 for (n = 0; n < (int)inv->inv_state; n ++)
7c935cd3 562 printf("serial serial:/dev/ttyd%d?baud=38400 \"Unknown\" \"EPC Serial Port %d, Ebus slot %d\"\n",
8a2c2126 563 n + i, n + 1, (int)inv->inv_controller);
92a63e4c 564 }
565 else if (inv->inv_state > 1)
566 {
567 /*
568 * Standard serial port under IRIX 6.4 and earlier...
569 */
570
8a2c2126 571 for (n = 0; n < (int)inv->inv_state; n ++)
7c935cd3 572 printf("serial serial:/dev/ttyd%d?baud=38400 \"Unknown\" \"Onboard Serial Port %d\"\n",
8a2c2126 573 n + (int)inv->inv_unit + 1, n + (int)inv->inv_unit + 1);
92a63e4c 574 }
575 else
576 {
577 /*
578 * Standard serial port under IRIX 6.5 and beyond...
579 */
580
581 printf("serial serial:/dev/ttyd%d?baud=115200 \"Unknown\" \"Onboard Serial Port %d\"\n",
8a2c2126 582 (int)inv->inv_controller, (int)inv->inv_controller);
92a63e4c 583 }
584 }
585 }
586
587 endinvent();
588
589 /*
590 * Central Data makes serial and parallel "servers" that can be
591 * connected in a number of ways. Look for ports...
592 */
593
594 for (i = 0; i < 10; i ++)
595 for (j = 0; j < 8; j ++)
596 for (n = 0; n < 32; n ++)
597 {
598 if (i == 8) /* EtherLite */
599 sprintf(device, "/dev/ttydn%d%c", j, funky_hex[n]);
600 else if (i == 9) /* PCI */
601 sprintf(device, "/dev/ttydp%d%c", j, funky_hex[n]);
602 else /* SCSI */
603 sprintf(device, "/dev/ttyd%d%d%c", i, j, funky_hex[n]);
604
605 if (access(device, 0) == 0)
606 {
607 if (i == 8)
608 printf("serial serial:%s?baud=38400 \"Unknown\" \"Central Data EtherLite Serial Port, ID %d, port %d\"\n",
609 device, j, n);
610 else if (i == 9)
611 printf("serial serial:%s?baud=38400 \"Unknown\" \"Central Data PCI Serial Port, ID %d, port %d\"\n",
612 device, j, n);
613 else
614 printf("serial serial:%s?baud=38400 \"Unknown\" \"Central Data SCSI Serial Port, logical bus %d, ID %d, port %d\"\n",
615 device, i, j, n);
616 }
617 }
68edc300 618#elif defined(__sun)
92a63e4c 619 int i, j, n; /* Looping vars */
620 char device[255]; /* Device filename */
621
622
623 /*
624 * Standard serial ports...
625 */
626
627 for (i = 0; i < 26; i ++)
628 {
629 sprintf(device, "/dev/cua/%c", 'a' + i);
630 if (access(device, 0) == 0)
c71a2ea0 631#ifdef B115200
632 printf("serial serial:%s?baud=115200 \"Unknown\" \"Serial Port #%d\"\n",
633 device, i + 1);
634#else
92a63e4c 635 printf("serial serial:%s?baud=38400 \"Unknown\" \"Serial Port #%d\"\n",
636 device, i + 1);
c71a2ea0 637#endif /* B115200 */
92a63e4c 638 }
639
640 /*
641 * MAGMA serial ports...
642 */
643
644 for (i = 0; i < 40; i ++)
645 {
646 sprintf(device, "/dev/term/%02d", i);
647 if (access(device, 0) == 0)
648 printf("serial serial:%s?baud=38400 \"Unknown\" \"MAGMA Serial Board #%d Port #%d\"\n",
649 device, (i / 10) + 1, (i % 10) + 1);
650 }
651
652 /*
653 * Central Data serial ports...
654 */
655
656 for (i = 0; i < 9; i ++)
657 for (j = 0; j < 8; j ++)
658 for (n = 0; n < 32; n ++)
659 {
660 if (i == 8) /* EtherLite */
661 sprintf(device, "/dev/sts/ttyN%d%c", j, funky_hex[n]);
662 else
663 sprintf(device, "/dev/sts/tty%c%d%c", i + 'C', j,
664 funky_hex[n]);
665
666 if (access(device, 0) == 0)
667 {
668 if (i == 8)
669 printf("serial serial:%s?baud=38400 \"Unknown\" \"Central Data EtherLite Serial Port, ID %d, port %d\"\n",
670 device, j, n);
671 else
672 printf("serial serial:%s?baud=38400 \"Unknown\" \"Central Data SCSI Serial Port, logical bus %d, ID %d, port %d\"\n",
673 device, i, j, n);
674 }
675 }
68edc300 676#elif defined(__hpux)
92a63e4c 677 int i, j, n; /* Looping vars */
678 char device[255]; /* Device filename */
679
680
681 /*
682 * Standard serial ports...
683 */
684
685 for (i = 0; i < 10; i ++)
686 {
687 sprintf(device, "/dev/tty%dp0", i);
688 if (access(device, 0) == 0)
689 printf("serial serial:%s?baud=38400 \"Unknown\" \"Serial Port #%d\"\n",
690 device, i + 1);
691 }
692
693 /*
694 * Central Data serial ports...
695 */
696
697 for (i = 0; i < 9; i ++)
698 for (j = 0; j < 8; j ++)
699 for (n = 0; n < 32; n ++)
700 {
701 if (i == 8) /* EtherLite */
702 sprintf(device, "/dev/ttyN%d%c", j, funky_hex[n]);
703 else
704 sprintf(device, "/dev/tty%c%d%c", i + 'C', j,
705 funky_hex[n]);
706
707 if (access(device, 0) == 0)
708 {
709 if (i == 8)
710 printf("serial serial:%s?baud=38400 \"Unknown\" \"Central Data EtherLite Serial Port, ID %d, port %d\"\n",
711 device, j, n);
712 else
713 printf("serial serial:%s?baud=38400 \"Unknown\" \"Central Data SCSI Serial Port, logical bus %d, ID %d, port %d\"\n",
714 device, i, j, n);
715 }
716 }
717#elif defined(__osf__)
718 int i; /* Looping var */
719 char device[255]; /* Device filename */
720
721
722 /*
723 * Standard serial ports...
724 */
725
726 for (i = 0; i < 100; i ++)
727 {
728 sprintf(device, "/dev/tty%02d", i);
729 if (access(device, 0) == 0)
730 printf("serial serial:%s?baud=38400 \"Unknown\" \"Serial Port #%d\"\n",
731 device, i + 1);
732 }
91b3b672 733#elif defined(__FreeBSD__) || defined(__OpenBSD__)
92a63e4c 734 int i, j; /* Looping vars */
735 int fd; /* File descriptor */
736 char device[255]; /* Device filename */
737
738
739 /*
740 * SIO ports...
741 */
742
743 for (i = 0; i < 32; i ++)
744 {
745 sprintf(device, "/dev/ttyd%c", funky_hex[i]);
a3e17a89 746 if ((fd = open(device, O_WRONLY | O_NOCTTY | O_NDELAY)) >= 0)
92a63e4c 747 {
748 close(fd);
749 printf("serial serial:%s?baud=115200 \"Unknown\" \"Standard Serial Port #%d\"\n",
750 device, i + 1);
751 }
752 }
753
754 /*
755 * Cyclades ports...
756 */
757
758 for (i = 0; i < 16; i ++) /* Should be up to 65536 boards... */
759 for (j = 0; j < 32; j ++)
760 {
761 sprintf(device, "/dev/ttyc%d%c", i, funky_hex[j]);
a3e17a89 762 if ((fd = open(device, O_WRONLY | O_NOCTTY | O_NDELAY)) >= 0)
92a63e4c 763 {
764 close(fd);
765 printf("serial serial:%s?baud=115200 \"Unknown\" \"Cyclades #%d Serial Port #%d\"\n",
766 device, i, j + 1);
767 }
768 }
769
770 /*
771 * Digiboard ports...
772 */
773
774 for (i = 0; i < 16; i ++) /* Should be up to 65536 boards... */
775 for (j = 0; j < 32; j ++)
776 {
777 sprintf(device, "/dev/ttyD%d%c", i, funky_hex[j]);
a3e17a89 778 if ((fd = open(device, O_WRONLY | O_NOCTTY | O_NDELAY)) >= 0)
92a63e4c 779 {
780 close(fd);
781 printf("serial serial:%s?baud=115200 \"Unknown\" \"Digiboard #%d Serial Port #%d\"\n",
782 device, i, j + 1);
783 }
784 }
785
786 /*
787 * Stallion ports...
788 */
789
790 for (i = 0; i < 32; i ++)
791 {
792 sprintf(device, "/dev/ttyE%c", funky_hex[i]);
a3e17a89 793 if ((fd = open(device, O_WRONLY | O_NOCTTY | O_NDELAY)) >= 0)
92a63e4c 794 {
795 close(fd);
796 printf("serial serial:%s?baud=115200 \"Unknown\" \"Stallion Serial Port #%d\"\n",
797 device, i + 1);
798 }
799 }
800
801 /*
802 * SX ports...
803 */
804
805 for (i = 0; i < 128; i ++)
806 {
807 sprintf(device, "/dev/ttyA%d", i + 1);
a3e17a89 808 if ((fd = open(device, O_WRONLY | O_NOCTTY | O_NDELAY)) >= 0)
92a63e4c 809 {
810 close(fd);
811 printf("serial serial:%s?baud=115200 \"Unknown\" \"SX Serial Port #%d\"\n",
812 device, i + 1);
813 }
814 }
5eaf1bc1 815#elif defined(__NetBSD__)
91b3b672 816 int i, j; /* Looping vars */
817 int fd; /* File descriptor */
818 char device[255]; /* Device filename */
819
820
821 /*
822 * Standard serial ports...
823 */
824
825 for (i = 0; i < 4; i ++)
826 {
827 sprintf(device, "/dev/tty%02d", i);
828 if ((fd = open(device, O_WRONLY | O_NOCTTY | O_NDELAY)) >= 0)
829 {
830 close(fd);
831 printf("serial serial:%s?baud=115200 \"Unknown\" \"Serial Port #%d\"\n",
832 device, i + 1);
833 }
834 }
835
836 /*
837 * Cyclades-Z ports...
838 */
839
840 for (i = 0; i < 16; i ++) /* Should be up to 65536 boards... */
841 for (j = 0; j < 64; j ++)
842 {
843 sprintf(device, "/dev/ttyCZ%02d%02d", i, j);
844 if ((fd = open(device, O_WRONLY | O_NOCTTY | O_NDELAY)) >= 0)
845 {
846 close(fd);
847 printf("serial serial:%s?baud=115200 \"Unknown\" \"Cyclades #%d Serial Prt #%d\"\n",
848 device, i, j + 1);
849 }
850 }
851
68edc300 852#endif
853}
854
855
856/*
753453e4 857 * End of "$Id: serial.c,v 1.32.2.1 2001/12/26 16:52:07 mike Exp $".
43e2fc22 858 */