2 * Asterisk -- A telephony toolkit for Linux.
4 * App to flash a zap trunk
6 * Copyright (C) 1999, Mark Spencer
8 * Mark Spencer <markster@linux-support.net>
10 * This program is free software, distributed under the terms of
11 * the GNU General Public License
17 #include <sys/ioctl.h>
19 #include <linux/zaptel.h>
22 #endif /* __linux__ */
26 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
28 #include "asterisk/lock.h"
29 #include "asterisk/file.h"
30 #include "asterisk/logger.h"
31 #include "asterisk/channel.h"
32 #include "asterisk/pbx.h"
33 #include "asterisk/module.h"
34 #include "asterisk/translate.h"
35 #include "asterisk/image.h"
36 #include "asterisk/options.h"
38 static char *tdesc = "Flash zap trunk application";
40 static char *app = "Flash";
42 static char *synopsis = "Flashes a Zap Trunk";
44 static char *descrip =
45 " Flash(): Sends a flash on a zap trunk. This is only a hack for\n"
46 "people who want to perform transfers and such via AGI and is generally\n"
47 "quite useless otherwise. Returns 0 on success or -1 if this is not\n"
54 static inline int zt_wait_event(int fd)
56 /* Avoid the silly zt_waitevent which ignores a bunch of events */
58 i = ZT_IOMUX_SIGEVENT;
59 if (ioctl(fd, ZT_IOMUX, &i) == -1) return -1;
60 if (ioctl(fd, ZT_GETEVENT, &j) == -1) return -1;
64 static int flash_exec(struct ast_channel *chan, void *data)
71 if (!strcasecmp(chan->type, "Zap")) {
72 memset(&ztp, 0, sizeof(ztp));
73 res = ioctl(chan->fds[0], ZT_GET_PARAMS, &ztp);
75 if (ztp.sigtype & __ZT_SIG_FXS) {
77 res = ioctl(chan->fds[0], ZT_HOOK, &x);
78 if (!res || (errno == EINPROGRESS)) {
80 /* Wait for the event to finish */
81 zt_wait_event(chan->fds[0]);
83 res = ast_safe_sleep(chan, 1000);
84 if (option_verbose > 2)
85 ast_verbose(VERBOSE_PREFIX_3 "Flashed channel %s\n", chan->name);
87 ast_log(LOG_WARNING, "Unable to flash channel %s: %s\n", chan->name, strerror(errno));
89 ast_log(LOG_WARNING, "%s is not an FXO Channel\n", chan->name);
91 ast_log(LOG_WARNING, "Unable to get parameters of %s: %s\n", chan->name, strerror(errno));
93 ast_log(LOG_WARNING, "%s is not a Zap channel\n", chan->name);
98 int unload_module(void)
100 STANDARD_HANGUP_LOCALUSERS;
101 return ast_unregister_application(app);
104 int load_module(void)
106 return ast_register_application(app, flash_exec, synopsis, descrip);
109 char *description(void)
117 STANDARD_USECOUNT(res);
123 return ASTERISK_GPL_KEY;