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>
34 ASTERISK_FILE_VERSION(__FILE__
, "$Revision$")
40 #include <sys/ioctl.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 #include "asterisk/dahdi_compat.h"
54 static char *app
= "Flash";
56 static char *dahdi_synopsis
= "Flashes a DAHDI trunk";
58 static char *dahdi_descrip
=
59 "Performs a flash on a DAHDI trunk. This can be used\n"
60 "to access features provided on an incoming analogue circuit\n"
61 "such as conference and call waiting. Use with SendDTMF() to\n"
62 "perform external transfers\n";
64 static char *zap_synopsis
= "Flashes a Zap trunk";
66 static char *zap_descrip
=
67 "Performs a flash on a Zap trunk. This can be used\n"
68 "to access features provided on an incoming analogue circuit\n"
69 "such as conference and call waiting. Use with SendDTMF() to\n"
70 "perform external transfers\n";
72 static inline int zt_wait_event(int fd
)
74 /* Avoid the silly zt_waitevent which ignores a bunch of events */
76 i
= DAHDI_IOMUX_SIGEVENT
;
77 if (ioctl(fd
, DAHDI_IOMUX
, &i
) == -1) return -1;
78 if (ioctl(fd
, DAHDI_GETEVENT
, &j
) == -1) return -1;
82 static int flash_exec(struct ast_channel
*chan
, void *data
)
86 struct ast_module_user
*u
;
87 struct dahdi_params ztp
;
88 u
= ast_module_user_add(chan
);
89 if (!strcasecmp(chan
->tech
->type
, dahdi_chan_name
)) {
90 memset(&ztp
, 0, sizeof(ztp
));
91 res
= ioctl(chan
->fds
[0], DAHDI_GET_PARAMS
, &ztp
);
93 if (ztp
.sigtype
& __DAHDI_SIG_FXS
) {
95 res
= ioctl(chan
->fds
[0], DAHDI_HOOK
, &x
);
96 if (!res
|| (errno
== EINPROGRESS
)) {
98 /* Wait for the event to finish */
99 zt_wait_event(chan
->fds
[0]);
101 res
= ast_safe_sleep(chan
, 1000);
102 if (option_verbose
> 2)
103 ast_verbose(VERBOSE_PREFIX_3
"Flashed channel %s\n", chan
->name
);
105 ast_log(LOG_WARNING
, "Unable to flash channel %s: %s\n", chan
->name
, strerror(errno
));
107 ast_log(LOG_WARNING
, "%s is not an FXO Channel\n", chan
->name
);
109 ast_log(LOG_WARNING
, "Unable to get parameters of %s: %s\n", chan
->name
, strerror(errno
));
111 ast_log(LOG_WARNING
, "%s is not a DAHDI channel\n", chan
->name
);
112 ast_module_user_remove(u
);
116 static int unload_module(void)
120 res
= ast_unregister_application(app
);
122 ast_module_user_hangup_all();
127 static int load_module(void)
129 if (dahdi_chan_mode
== CHAN_ZAP_MODE
) {
130 return ast_register_application(app
, flash_exec
, zap_synopsis
, zap_descrip
);
132 return ast_register_application(app
, flash_exec
, dahdi_synopsis
, dahdi_descrip
);
136 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY
, "Flash channel application");