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
28 #include <sys/ioctl.h>
30 #include <linux/zaptel.h>
33 #endif /* __linux__ */
37 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
39 #include "asterisk/lock.h"
40 #include "asterisk/file.h"
41 #include "asterisk/logger.h"
42 #include "asterisk/channel.h"
43 #include "asterisk/pbx.h"
44 #include "asterisk/module.h"
45 #include "asterisk/translate.h"
46 #include "asterisk/image.h"
47 #include "asterisk/options.h"
49 static char *tdesc = "Flash zap trunk application";
51 static char *app = "Flash";
53 static char *synopsis = "Flashes a Zap Trunk";
55 static char *descrip =
56 " Flash(): Sends a flash on a zap trunk. This is only a hack for\n"
57 "people who want to perform transfers and such via AGI and is generally\n"
58 "quite useless otherwise. Returns 0 on success or -1 if this is not\n"
65 static inline int zt_wait_event(int fd)
67 /* Avoid the silly zt_waitevent which ignores a bunch of events */
69 i = ZT_IOMUX_SIGEVENT;
70 if (ioctl(fd, ZT_IOMUX, &i) == -1) return -1;
71 if (ioctl(fd, ZT_GETEVENT, &j) == -1) return -1;
75 static int flash_exec(struct ast_channel *chan, void *data)
82 if (!strcasecmp(chan->type, "Zap")) {
83 memset(&ztp, 0, sizeof(ztp));
84 res = ioctl(chan->fds[0], ZT_GET_PARAMS, &ztp);
86 if (ztp.sigtype & __ZT_SIG_FXS) {
88 res = ioctl(chan->fds[0], ZT_HOOK, &x);
89 if (!res || (errno == EINPROGRESS)) {
91 /* Wait for the event to finish */
92 zt_wait_event(chan->fds[0]);
94 res = ast_safe_sleep(chan, 1000);
95 if (option_verbose > 2)
96 ast_verbose(VERBOSE_PREFIX_3 "Flashed channel %s\n", chan->name);
98 ast_log(LOG_WARNING, "Unable to flash channel %s: %s\n", chan->name, strerror(errno));
100 ast_log(LOG_WARNING, "%s is not an FXO Channel\n", chan->name);
102 ast_log(LOG_WARNING, "Unable to get parameters of %s: %s\n", chan->name, strerror(errno));
104 ast_log(LOG_WARNING, "%s is not a Zap channel\n", chan->name);
105 LOCAL_USER_REMOVE(u);
109 int unload_module(void)
113 res = ast_unregister_application(app);
115 STANDARD_HANGUP_LOCALUSERS;
120 int load_module(void)
122 return ast_register_application(app, flash_exec, synopsis, descrip);
125 char *description(void)
133 STANDARD_USECOUNT(res);
139 return ASTERISK_GPL_KEY;