00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include "asterisk.h"
00033
00034 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 182652 $")
00035
00036 #include <stdlib.h>
00037 #include <stdio.h>
00038 #include <string.h>
00039 #include <errno.h>
00040 #include <sys/ioctl.h>
00041
00042 #include "asterisk/lock.h"
00043 #include "asterisk/file.h"
00044 #include "asterisk/logger.h"
00045 #include "asterisk/channel.h"
00046 #include "asterisk/pbx.h"
00047 #include "asterisk/module.h"
00048 #include "asterisk/translate.h"
00049 #include "asterisk/image.h"
00050 #include "asterisk/options.h"
00051
00052 #include "asterisk/dahdi_compat.h"
00053
00054 static char *app = "Flash";
00055
00056 static char *dahdi_synopsis = "Flashes a DAHDI trunk";
00057
00058 static char *dahdi_descrip =
00059 "Performs a flash on a DAHDI trunk. This can be used\n"
00060 "to access features provided on an incoming analogue circuit\n"
00061 "such as conference and call waiting. Use with SendDTMF() to\n"
00062 "perform external transfers\n";
00063
00064 static char *zap_synopsis = "Flashes a Zap trunk";
00065
00066 static char *zap_descrip =
00067 "Performs a flash on a Zap trunk. This can be used\n"
00068 "to access features provided on an incoming analogue circuit\n"
00069 "such as conference and call waiting. Use with SendDTMF() to\n"
00070 "perform external transfers\n";
00071
00072 static inline int zt_wait_event(int fd)
00073 {
00074
00075 int i,j=0;
00076 i = DAHDI_IOMUX_SIGEVENT;
00077 if (ioctl(fd, DAHDI_IOMUX, &i) == -1) return -1;
00078 if (ioctl(fd, DAHDI_GETEVENT, &j) == -1) return -1;
00079 return j;
00080 }
00081
00082 static int flash_exec(struct ast_channel *chan, void *data)
00083 {
00084 int res = -1;
00085 int x;
00086 struct ast_module_user *u;
00087 struct dahdi_params ztp;
00088 u = ast_module_user_add(chan);
00089 if (!strcasecmp(chan->tech->type, dahdi_chan_name)) {
00090 memset(&ztp, 0, sizeof(ztp));
00091 res = ioctl(chan->fds[0], DAHDI_GET_PARAMS, &ztp);
00092 if (!res) {
00093 if (ztp.sigtype & __DAHDI_SIG_FXS) {
00094 x = DAHDI_FLASH;
00095 res = ioctl(chan->fds[0], DAHDI_HOOK, &x);
00096 if (!res || (errno == EINPROGRESS)) {
00097 if (res) {
00098
00099 zt_wait_event(chan->fds[0]);
00100 }
00101 res = ast_safe_sleep(chan, 1000);
00102 if (option_verbose > 2)
00103 ast_verbose(VERBOSE_PREFIX_3 "Flashed channel %s\n", chan->name);
00104 } else
00105 ast_log(LOG_WARNING, "Unable to flash channel %s: %s\n", chan->name, strerror(errno));
00106 } else
00107 ast_log(LOG_WARNING, "%s is not an FXO Channel\n", chan->name);
00108 } else
00109 ast_log(LOG_WARNING, "Unable to get parameters of %s: %s\n", chan->name, strerror(errno));
00110 } else
00111 ast_log(LOG_WARNING, "%s is not a DAHDI channel\n", chan->name);
00112 ast_module_user_remove(u);
00113 return res;
00114 }
00115
00116 static int unload_module(void)
00117 {
00118 int res;
00119
00120 res = ast_unregister_application(app);
00121
00122 ast_module_user_hangup_all();
00123
00124 return res;
00125 }
00126
00127 static int load_module(void)
00128 {
00129 if (*dahdi_chan_mode == CHAN_ZAP_MODE) {
00130 return ast_register_application(app, flash_exec, zap_synopsis, zap_descrip);
00131 } else {
00132 return ast_register_application(app, flash_exec, dahdi_synopsis, dahdi_descrip);
00133 }
00134 }
00135
00136 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Flash channel application");