mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-02 19:16:15 +00:00
app_meetme is deprecated in 19, to be removed in 21. app_osplookup is deprecated in 19, to be removed in 21. chan_alsa is deprecated in 19, to be removed in 21. chan_mgcp is deprecated in 19, to be removed in 21. chan_skinny is deprecated in 19, to be removed in 21. res_pktccops is deprecated in 19, to be removed in 21. cdr_mysql was deprecated in 1.8, to be removed in 19. app_mysql was deprecated in 1.8, to be removed in 19. app_ices was deprecated in 16, to be removed in 19. app_macro was deprecated in 16, to be removed in 21. app_fax was deprecated in 16, to be removed in 19. app_url was deprecated in 16, to be removed in 19. app_image was deprecated in 16, to be removed in 19. app_nbscat was deprecated in 16, to be removed in 19. app_dahdiras was deprecated in 16, to be removed in 19. cdr_syslog was deprecated in 16, to be removed in 19. chan_oss was deprecated in 16, to be removed in 19. chan_phone was deprecated in 16, to be removed in 19. chan_sip was deprecated in 17, to be removed in 21. chan_nbs was deprecated in 16, to be removed in 19. chan_misdn was deprecated in 16, to be removed in 19. chan_vpb was deprecated in 16, to be removed in 19. res_config_sqlite was deprecated in 16, to be removed in 19. res_monitor was deprecated in 16, to be removed in 21. conf2ael was deprecated in 16, to be removed in 19. muted was deprecated in 16, to be removed in 19. ASTERISK-29548 ASTERISK-29549 ASTERISK-29550 ASTERISK-29551 ASTERISK-29552 ASTERISK-29553 ASTERISK-29554 ASTERISK-29555 ASTERISK-29557 ASTERISK-29558 ASTERISK-29559 ASTERISK-29560 ASTERISK-29561 ASTERISK-29562 ASTERISK-29563 ASTERISK-29564 ASTERISK-29565 ASTERISK-29566 ASTERISK-29567 ASTERISK-29568 ASTERISK-29569 ASTERISK-29570 ASTERISK-29571 ASTERISK-29572 ASTERISK-29573 ASTERISK-29574 Change-Id: Ic3bee31a10d42c4b3bbc913d893f7b2a28a27131
234 lines
5.8 KiB
C
234 lines
5.8 KiB
C
/*
|
|
* Asterisk -- An open source telephony toolkit.
|
|
*
|
|
* Copyright (C) 1999 - 2005, Digium, Inc.
|
|
*
|
|
* Mark Spencer <markster@digium.com>
|
|
*
|
|
* See http://www.asterisk.org for more information about
|
|
* the Asterisk project. Please do not directly contact
|
|
* any of the maintainers of this project for assistance;
|
|
* the project provides a web site, mailing lists and IRC
|
|
* channels for your use.
|
|
*
|
|
* This program is free software, distributed under the terms of
|
|
* the GNU General Public License Version 2. See the LICENSE file
|
|
* at the top of the source tree.
|
|
*/
|
|
|
|
/*! \file
|
|
*
|
|
* \brief Execute an ISDN RAS
|
|
*
|
|
* \author Mark Spencer <markster@digium.com>
|
|
*
|
|
* \ingroup applications
|
|
*/
|
|
|
|
/*** MODULEINFO
|
|
<depend>dahdi</depend>
|
|
<support_level>deprecated</support_level>
|
|
<deprecated_in>16</deprecated_in>
|
|
<removed_in>19</removed_in>
|
|
***/
|
|
|
|
#include "asterisk.h"
|
|
|
|
#include <sys/ioctl.h>
|
|
#include <sys/wait.h>
|
|
#include <signal.h>
|
|
#include <fcntl.h>
|
|
|
|
#include <dahdi/user.h>
|
|
|
|
#include "asterisk/lock.h"
|
|
#include "asterisk/file.h"
|
|
#include "asterisk/channel.h"
|
|
#include "asterisk/pbx.h"
|
|
#include "asterisk/module.h"
|
|
#include "asterisk/app.h"
|
|
|
|
/*** DOCUMENTATION
|
|
<application name="DAHDIRAS" language="en_US">
|
|
<synopsis>
|
|
Executes DAHDI ISDN RAS application.
|
|
</synopsis>
|
|
<syntax>
|
|
<parameter name="args" required="true">
|
|
<para>A list of parameters to pass to the pppd daemon,
|
|
separated by <literal>,</literal> characters.</para>
|
|
</parameter>
|
|
</syntax>
|
|
<description>
|
|
<para>Executes a RAS server using pppd on the given channel.
|
|
The channel must be a clear channel (i.e. PRI source) and a DAHDI
|
|
channel to be able to use this function (No modem emulation is included).</para>
|
|
<para>Your pppd must be patched to be DAHDI aware.</para>
|
|
</description>
|
|
</application>
|
|
|
|
***/
|
|
|
|
static const char app[] = "DAHDIRAS";
|
|
|
|
#define PPP_MAX_ARGS 32
|
|
#define PPP_EXEC "/usr/sbin/pppd"
|
|
|
|
static pid_t spawn_ras(struct ast_channel *chan, char *args)
|
|
{
|
|
pid_t pid;
|
|
char *c;
|
|
|
|
char *argv[PPP_MAX_ARGS];
|
|
int argc = 0;
|
|
char *stringp=NULL;
|
|
|
|
/* Start by forking */
|
|
pid = ast_safe_fork(1);
|
|
if (pid) {
|
|
return pid;
|
|
}
|
|
|
|
/* Execute RAS on File handles */
|
|
dup2(ast_channel_fd(chan, 0), STDIN_FILENO);
|
|
|
|
/* Drop high priority */
|
|
if (ast_opt_high_priority)
|
|
ast_set_priority(0);
|
|
|
|
/* Close other file descriptors */
|
|
ast_close_fds_above_n(STDERR_FILENO);
|
|
|
|
/* Reset all arguments */
|
|
memset(argv, 0, sizeof(argv));
|
|
|
|
/* First argument is executable, followed by standard
|
|
arguments for DAHDI PPP */
|
|
argv[argc++] = PPP_EXEC;
|
|
argv[argc++] = "nodetach";
|
|
|
|
/* And all the other arguments */
|
|
stringp=args;
|
|
c = strsep(&stringp, ",");
|
|
while(c && strlen(c) && (argc < (PPP_MAX_ARGS - 4))) {
|
|
argv[argc++] = c;
|
|
c = strsep(&stringp, ",");
|
|
}
|
|
|
|
if (geteuid() == 0) {
|
|
argv[argc++] = "plugin";
|
|
argv[argc++] = "dahdi.so";
|
|
}
|
|
argv[argc++] = "stdin";
|
|
|
|
/* Finally launch PPP */
|
|
execv(PPP_EXEC, argv);
|
|
fprintf(stderr, "Failed to exec PPPD!\n");
|
|
exit(1);
|
|
}
|
|
|
|
static void run_ras(struct ast_channel *chan, char *args)
|
|
{
|
|
pid_t pid;
|
|
int status;
|
|
int res;
|
|
int signalled = 0;
|
|
struct dahdi_bufferinfo savebi;
|
|
int x;
|
|
|
|
res = ioctl(ast_channel_fd(chan, 0), DAHDI_GET_BUFINFO, &savebi);
|
|
if(res) {
|
|
ast_log(LOG_WARNING, "Unable to check buffer policy on channel %s\n", ast_channel_name(chan));
|
|
return;
|
|
}
|
|
|
|
pid = spawn_ras(chan, args);
|
|
if (pid < 0) {
|
|
ast_log(LOG_WARNING, "Failed to spawn RAS\n");
|
|
} else {
|
|
for (;;) {
|
|
res = waitpid(pid, &status, WNOHANG);
|
|
if (!res) {
|
|
/* Check for hangup */
|
|
if (ast_check_hangup(chan) && !signalled) {
|
|
ast_debug(1, "Channel '%s' hungup. Signalling RAS at %d to die...\n", ast_channel_name(chan), pid);
|
|
kill(pid, SIGTERM);
|
|
signalled=1;
|
|
}
|
|
/* Try again */
|
|
sleep(1);
|
|
continue;
|
|
}
|
|
if (res < 0) {
|
|
ast_log(LOG_WARNING, "waitpid returned %d: %s\n", res, strerror(errno));
|
|
}
|
|
if (WIFEXITED(status)) {
|
|
ast_verb(3, "RAS on %s terminated with status %d\n", ast_channel_name(chan), WEXITSTATUS(status));
|
|
} else if (WIFSIGNALED(status)) {
|
|
ast_verb(3, "RAS on %s terminated with signal %d\n",
|
|
ast_channel_name(chan), WTERMSIG(status));
|
|
} else {
|
|
ast_verb(3, "RAS on %s terminated weirdly.\n", ast_channel_name(chan));
|
|
}
|
|
/* Throw back into audio mode */
|
|
x = 1;
|
|
ioctl(ast_channel_fd(chan, 0), DAHDI_AUDIOMODE, &x);
|
|
|
|
/* Restore saved values */
|
|
res = ioctl(ast_channel_fd(chan, 0), DAHDI_SET_BUFINFO, &savebi);
|
|
if (res < 0) {
|
|
ast_log(LOG_WARNING, "Unable to set buffer policy on channel %s\n", ast_channel_name(chan));
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
ast_safe_fork_cleanup();
|
|
}
|
|
|
|
static int dahdiras_exec(struct ast_channel *chan, const char *data)
|
|
{
|
|
int res=-1;
|
|
char *args;
|
|
struct dahdi_params dahdip;
|
|
|
|
if (!data)
|
|
data = "";
|
|
|
|
args = ast_strdupa(data);
|
|
|
|
/* Answer the channel if it's not up */
|
|
if (ast_channel_state(chan) != AST_STATE_UP)
|
|
ast_answer(chan);
|
|
if (strcasecmp(ast_channel_tech(chan)->type, "DAHDI")) {
|
|
/* If it's not a DAHDI channel, we're done. Wait a couple of
|
|
seconds and then hangup... */
|
|
ast_verb(2, "Channel %s is not a DAHDI channel\n", ast_channel_name(chan));
|
|
sleep(2);
|
|
} else {
|
|
memset(&dahdip, 0, sizeof(dahdip));
|
|
if (ioctl(ast_channel_fd(chan, 0), DAHDI_GET_PARAMS, &dahdip)) {
|
|
ast_log(LOG_WARNING, "Unable to get DAHDI parameters\n");
|
|
} else if (dahdip.sigtype != DAHDI_SIG_CLEAR) {
|
|
ast_verb(2, "Channel %s is not a clear channel\n", ast_channel_name(chan));
|
|
} else {
|
|
/* Everything should be okay. Run PPP. */
|
|
ast_verb(3, "Starting RAS on %s\n", ast_channel_name(chan));
|
|
/* Execute RAS */
|
|
run_ras(chan, args);
|
|
}
|
|
}
|
|
return res;
|
|
}
|
|
|
|
static int unload_module(void)
|
|
{
|
|
return ast_unregister_application(app);
|
|
}
|
|
|
|
static int load_module(void)
|
|
{
|
|
return ((ast_register_application_xml(app, dahdiras_exec)) ? AST_MODULE_LOAD_DECLINE : AST_MODULE_LOAD_SUCCESS);
|
|
}
|
|
|
|
AST_MODULE_INFO_STANDARD_DEPRECATED(ASTERISK_GPL_KEY, "DAHDI ISDN Remote Access Server");
|