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 $
32 * last edit-date: [Sat Jul 21 13:38:10 2001]
34 *---------------------------------------------------------------------------
36 * BEWARE: HIGHLY EXPERIMENTAL!
37 * ---------------------------
39 * This program is used in conjunction with a isdnd.rc entry similar to
41 * regexpr = "ULPPP.*call active" # look for matches in log messages
42 * regprog = i4brunppp # execute program when match is found
44 * this one. It _must_ be put into /etc/isdn!
45 * When an active call is detected, isdnd fires off i4brunppp, which attaches
46 * the rbch device used to stdin/stdout and then runs ppp which is given the
47 * "-direct" command and the string "inc_rbchX" (where X is the i4brbch unit
48 * number) as arguments.
50 *---------------------------------------------------------------------------*/
62 #include <machine/i4b_ioctl.h>
63 #include <machine/i4b_rbch_ioctl.h>
65 #define I4BDEVICE "/dev/i4b"
67 #define PPPPROG "/usr/sbin/ppp"
69 #define PPPARG1 "-direct"
70 #define PPPLABEL "inc_"
72 #define VERIFYSTRING "call active"
73 #define DEVSTRING "rbch"
77 /*---------------------------------------------------------------------------*
79 *---------------------------------------------------------------------------*/
81 main(int argc, char **argv)
85 char *p = "DeadPointer";
92 register struct tm *tp;
97 (void)openlog("i4brunppp", LOG_PID|LOG_CONS|LOG_NDELAY, LOG_USER);
103 if((dfp = fopen("/tmp/i4brunppp-debug.log", "a")) == NULL)
105 syslog(LOG_INFO, "cannot open logfile: %s", strerror(errno));
110 tp = localtime(&tim);
111 strftime(buffer, 40, I4B_TIME_FORMAT, tp);
112 fprintf(dfp, "\n=================== %s ===================\n", buffer);
114 for(i=0; i < argc; i++)
115 fprintf(dfp, "\t%s\n", argv[i]);
118 /* check if this is the right message */
122 for(i=0; i < argc; i++)
124 if((strstr(argv[i], VERIFYSTRING)) != NULL)
134 fprintf(dfp, "did not found [%s], exit\n", VERIFYSTRING);
141 /* check if we got a good device name */
145 if((p = strstr(argv[i], DEVSTRING)) != NULL)
155 fprintf(dfp, "did not found [%s], exit\n", DEVSTRING);
160 /* everything ok, now prepare for running ppp */
162 /* close all file descriptors */
170 /* fiddle a terminating zero after the rbch unit number */
172 p += strlen(DEVSTRING);
174 if(isdigit(*p) && isdigit(*(p+1)))
179 /* construct /dev/i4brbchX device name */
181 sprintf(buffer, "%s%s%s", I4BDEVICE, DEVSTRING, p);
183 /* open the rbch device as fd 0 = stdin */
185 rbch_fd = open(buffer, O_RDWR);
190 syslog(LOG_INFO, "cannot open %s: %s", buffer, strerror(errno));
192 syslog(LOG_INFO, "cannot open %s as fd 0 (is %d): %s", buffer, rbch_fd, strerror(errno));
196 /* dup rbch device fd as fd 1 = stdout */
198 if((i = dup(rbch_fd)) != 1)
201 syslog(LOG_INFO, "cannot dup rbch_fd: %s", strerror(errno));
203 syslog(LOG_INFO, "cannot dup rbch as fd 1 (is %d): %s", i, strerror(errno));
207 /* construct the label for ppp's ppp.conf file */
209 sprintf(buffer, "%s%s%s", PPPLABEL, DEVSTRING, p);
211 syslog(LOG_INFO, "executing: %s %s %s %s", PPPPROG, PPPNAME, PPPARG1, buffer);
215 if((execl(PPPPROG, PPPNAME, PPPARG1, buffer, NULL)) == -1)
217 syslog(LOG_INFO, "cannot exec: %s", strerror(errno));
220 syslog(LOG_INFO, "finished: %s %s %s %s", PPPPROG, PPPNAME, PPPARG1, buffer);