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: 82992 $")
00035
00036 #include <stdlib.h>
00037 #include <stdio.h>
00038 #include <string.h>
00039 #include <errno.h>
00040 #include <sys/ioctl.h>
00041 #include <zaptel/zaptel.h>
00042
00043 #include "asterisk/lock.h"
00044 #include "asterisk/file.h"
00045 #include "asterisk/logger.h"
00046 #include "asterisk/channel.h"
00047 #include "asterisk/pbx.h"
00048 #include "asterisk/module.h"
00049 #include "asterisk/translate.h"
00050 #include "asterisk/image.h"
00051 #include "asterisk/options.h"
00052
00053 static char *app = "Flash";
00054
00055 static char *synopsis = "Flashes a Zap Trunk";
00056
00057 static char *descrip =
00058 "Performs a flash on a zap trunk. This can be used\n"
00059 "to access features provided on an incoming analogue circuit\n"
00060 "such as conference and call waiting. Use with SendDTMF() to\n"
00061 "perform external transfers\n";
00062
00063
00064 static inline int zt_wait_event(int fd)
00065 {
00066
00067 int i,j=0;
00068 i = ZT_IOMUX_SIGEVENT;
00069 if (ioctl(fd, ZT_IOMUX, &i) == -1) return -1;
00070 if (ioctl(fd, ZT_GETEVENT, &j) == -1) return -1;
00071 return j;
00072 }
00073
00074 static int flash_exec(struct ast_channel *chan, void *data)
00075 {
00076 int res = -1;
00077 int x;
00078 struct ast_module_user *u;
00079 struct zt_params ztp;
00080 u = ast_module_user_add(chan);
00081 if (!strcasecmp(chan->tech->type, "Zap")) {
00082 memset(&ztp, 0, sizeof(ztp));
00083 res = ioctl(chan->fds[0], ZT_GET_PARAMS, &ztp);
00084 if (!res) {
00085 if (ztp.sigtype & __ZT_SIG_FXS) {
00086 x = ZT_FLASH;
00087 res = ioctl(chan->fds[0], ZT_HOOK, &x);
00088 if (!res || (errno == EINPROGRESS)) {
00089 if (res) {
00090
00091 zt_wait_event(chan->fds[0]);
00092 }
00093 res = ast_safe_sleep(chan, 1000);
00094 if (option_verbose > 2)
00095 ast_verbose(VERBOSE_PREFIX_3 "Flashed channel %s\n", chan->name);
00096 } else
00097 ast_log(LOG_WARNING, "Unable to flash channel %s: %s\n", chan->name, strerror(errno));
00098 } else
00099 ast_log(LOG_WARNING, "%s is not an FXO Channel\n", chan->name);
00100 } else
00101 ast_log(LOG_WARNING, "Unable to get parameters of %s: %s\n", chan->name, strerror(errno));
00102 } else
00103 ast_log(LOG_WARNING, "%s is not a Zap channel\n", chan->name);
00104 ast_module_user_remove(u);
00105 return res;
00106 }
00107
00108 static int unload_module(void)
00109 {
00110 int res;
00111
00112 res = ast_unregister_application(app);
00113
00114 ast_module_user_hangup_all();
00115
00116 return res;
00117 }
00118
00119 static int load_module(void)
00120 {
00121 return ast_register_application(app, flash_exec, synopsis, descrip);
00122 }
00123
00124 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Flash channel application");
00125