2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 1999 - 2005, Digium, Inc.
6 * Mark Spencer <markster@digium.com>
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
21 * \brief App to flash a DAHDI trunk
23 * \author Mark Spencer <markster@digium.com>
25 * \ingroup applications
29 <depend>dahdi</depend>
30 <support_level>core</support_level>
35 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
37 #include <dahdi/user.h>
39 #include "asterisk/lock.h"
40 #include "asterisk/file.h"
41 #include "asterisk/channel.h"
42 #include "asterisk/pbx.h"
43 #include "asterisk/module.h"
44 #include "asterisk/translate.h"
45 #include "asterisk/image.h"
48 <application name="Flash" language="en_US">
50 Flashes a DAHDI Trunk.
54 <para>Performs a flash on a DAHDI trunk. This can be used to access features
55 provided on an incoming analogue circuit such as conference and call waiting.
56 Use with SendDTMF() to perform external transfers.</para>
59 <ref type="application">SendDTMF</ref>
64 static char *app = "Flash";
66 static inline int dahdi_wait_event(int fd)
68 /* Avoid the silly dahdi_waitevent which ignores a bunch of events */
70 i = DAHDI_IOMUX_SIGEVENT;
71 if (ioctl(fd, DAHDI_IOMUX, &i) == -1) return -1;
72 if (ioctl(fd, DAHDI_GETEVENT, &j) == -1) return -1;
76 static int flash_exec(struct ast_channel *chan, const char *data)
80 struct dahdi_params dahdip;
82 if (strcasecmp(ast_channel_tech(chan)->type, "DAHDI")) {
83 ast_log(LOG_WARNING, "%s is not a DAHDI channel\n", ast_channel_name(chan));
87 memset(&dahdip, 0, sizeof(dahdip));
88 res = ioctl(ast_channel_fd(chan, 0), DAHDI_GET_PARAMS, &dahdip);
90 if (dahdip.sigtype & __DAHDI_SIG_FXS) {
92 res = ioctl(ast_channel_fd(chan, 0), DAHDI_HOOK, &x);
93 if (!res || (errno == EINPROGRESS)) {
95 /* Wait for the event to finish */
96 dahdi_wait_event(ast_channel_fd(chan, 0));
98 res = ast_safe_sleep(chan, 1000);
99 ast_verb(3, "Flashed channel %s\n", ast_channel_name(chan));
101 ast_log(LOG_WARNING, "Unable to flash channel %s: %s\n", ast_channel_name(chan), strerror(errno));
103 ast_log(LOG_WARNING, "%s is not an FXO Channel\n", ast_channel_name(chan));
105 ast_log(LOG_WARNING, "Unable to get parameters of %s: %s\n", ast_channel_name(chan), strerror(errno));
110 static int unload_module(void)
112 return ast_unregister_application(app);
115 static int load_module(void)
117 return ast_register_application_xml(app, flash_exec);
120 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Flash channel application");