2 * Copyright (c) 1999, 2001 Hellmuth Michaelis. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 *---------------------------------------------------------------------------
27 * i4brunppp - run userland ppp for incoming call from rbch i/f
28 * ------------------------------------------------------------
30 * $FreeBSD: src/share/examples/isdn/i4brunppp/i4brunppp.c,v 1.2.2.1 2001/08/12 01:57:09 obrien Exp $
31 * $DragonFly: src/share/examples/isdn/i4brunppp/i4brunppp.c,v 1.2 2003/06/17 04:36:57 dillon Exp $
33 * last edit-date: [Sat Jul 21 13:38:10 2001]
35 *---------------------------------------------------------------------------
37 * BEWARE: HIGHLY EXPERIMENTAL!
38 * ---------------------------
40 * This program is used in conjunction with a isdnd.rc entry similar to
42 * regexpr = "ULPPP.*call active" # look for matches in log messages
43 * regprog = i4brunppp # execute program when match is found
45 * this one. It _must_ be put into /etc/isdn!
46 * When an active call is detected, isdnd fires off i4brunppp, which attaches
47 * the rbch device used to stdin/stdout and then runs ppp which is given the
48 * "-direct" command and the string "inc_rbchX" (where X is the i4brbch unit
49 * number) as arguments.
51 *---------------------------------------------------------------------------*/
63 #include <machine/i4b_ioctl.h>
64 #include <machine/i4b_rbch_ioctl.h>
66 #define I4BDEVICE "/dev/i4b"
68 #define PPPPROG "/usr/sbin/ppp"
70 #define PPPARG1 "-direct"
71 #define PPPLABEL "inc_"
73 #define VERIFYSTRING "call active"
74 #define DEVSTRING "rbch"
78 /*---------------------------------------------------------------------------*
80 *---------------------------------------------------------------------------*/
82 main(int argc, char **argv)
86 char *p = "DeadPointer";
93 register struct tm *tp;
98 (void)openlog("i4brunppp", LOG_PID|LOG_CONS|LOG_NDELAY, LOG_USER);
104 if((dfp = fopen("/tmp/i4brunppp-debug.log", "a")) == NULL)
106 syslog(LOG_INFO, "cannot open logfile: %s", strerror(errno));
111 tp = localtime(&tim);
112 strftime(buffer, 40, I4B_TIME_FORMAT, tp);
113 fprintf(dfp, "\n=================== %s ===================\n", buffer);
115 for(i=0; i < argc; i++)
116 fprintf(dfp, "\t%s\n", argv[i]);
119 /* check if this is the right message */
123 for(i=0; i < argc; i++)
125 if((strstr(argv[i], VERIFYSTRING)) != NULL)
135 fprintf(dfp, "did not found [%s], exit\n", VERIFYSTRING);
142 /* check if we got a good device name */
146 if((p = strstr(argv[i], DEVSTRING)) != NULL)
156 fprintf(dfp, "did not found [%s], exit\n", DEVSTRING);
161 /* everything ok, now prepare for running ppp */
163 /* close all file descriptors */
171 /* fiddle a terminating zero after the rbch unit number */
173 p += strlen(DEVSTRING);
175 if(isdigit(*p) && isdigit(*(p+1)))
180 /* construct /dev/i4brbchX device name */
182 sprintf(buffer, "%s%s%s", I4BDEVICE, DEVSTRING, p);
184 /* open the rbch device as fd 0 = stdin */
186 rbch_fd = open(buffer, O_RDWR);
191 syslog(LOG_INFO, "cannot open %s: %s", buffer, strerror(errno));
193 syslog(LOG_INFO, "cannot open %s as fd 0 (is %d): %s", buffer, rbch_fd, strerror(errno));
197 /* dup rbch device fd as fd 1 = stdout */
199 if((i = dup(rbch_fd)) != 1)
202 syslog(LOG_INFO, "cannot dup rbch_fd: %s", strerror(errno));
204 syslog(LOG_INFO, "cannot dup rbch as fd 1 (is %d): %s", i, strerror(errno));
208 /* construct the label for ppp's ppp.conf file */
210 sprintf(buffer, "%s%s%s", PPPLABEL, DEVSTRING, p);
212 syslog(LOG_INFO, "executing: %s %s %s %s", PPPPROG, PPPNAME, PPPARG1, buffer);
216 if((execl(PPPPROG, PPPNAME, PPPARG1, buffer, NULL)) == -1)
218 syslog(LOG_INFO, "cannot exec: %s", strerror(errno));
221 syslog(LOG_INFO, "finished: %s %s %s %s", PPPPROG, PPPNAME, PPPARG1, buffer);