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 zap trunk
23 * \author Mark Spencer <markster@digium.com>
25 * \ingroup applications
29 <depend>zaptel</depend>
34 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
40 #include "asterisk/zapata.h"
42 #include "asterisk/lock.h"
43 #include "asterisk/file.h"
44 #include "asterisk/logger.h"
45 #include "asterisk/channel.h"
46 #include "asterisk/pbx.h"
47 #include "asterisk/module.h"
48 #include "asterisk/translate.h"
49 #include "asterisk/image.h"
50 #include "asterisk/options.h"
52 static char *app = "Flash";
54 static char *synopsis = "Flashes a Zap Trunk";
56 static char *descrip =
57 " Flash(): Sends a flash on a zap trunk. This is only a hack for\n"
58 "people who want to perform transfers and such via AGI and is generally\n"
59 "quite useless oths application will only work on Zap trunks.\n";
62 static inline int zt_wait_event(int fd)
64 /* Avoid the silly zt_waitevent which ignores a bunch of events */
66 i = ZT_IOMUX_SIGEVENT;
67 if (ioctl(fd, ZT_IOMUX, &i) == -1) return -1;
68 if (ioctl(fd, ZT_GETEVENT, &j) == -1) return -1;
72 static int flash_exec(struct ast_channel *chan, void *data)
76 struct ast_module_user *u;
79 if (strcasecmp(chan->tech->type, "Zap")) {
80 ast_log(LOG_WARNING, "%s is not a Zap channel\n", chan->name);
84 u = ast_module_user_add(chan);
86 memset(&ztp, 0, sizeof(ztp));
87 res = ioctl(chan->fds[0], ZT_GET_PARAMS, &ztp);
89 if (ztp.sigtype & __ZT_SIG_FXS) {
91 res = ioctl(chan->fds[0], ZT_HOOK, &x);
92 if (!res || (errno == EINPROGRESS)) {
94 /* Wait for the event to finish */
95 zt_wait_event(chan->fds[0]);
97 res = ast_safe_sleep(chan, 1000);
98 if (option_verbose > 2)
99 ast_verbose(VERBOSE_PREFIX_3 "Flashed channel %s\n", chan->name);
101 ast_log(LOG_WARNING, "Unable to flash channel %s: %s\n", chan->name, strerror(errno));
103 ast_log(LOG_WARNING, "%s is not an FXO Channel\n", chan->name);
105 ast_log(LOG_WARNING, "Unable to get parameters of %s: %s\n", chan->name, strerror(errno));
107 ast_module_user_remove(u);
112 static int unload_module(void)
114 return ast_unregister_application(app);
117 static int load_module(void)
119 return ast_register_application(app, flash_exec, synopsis, descrip);
122 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Flash channel application");