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: 125146 $")
00035
00036 #include <sys/ioctl.h>
00037 #include <dahdi/user.h>
00038
00039 #include "asterisk/lock.h"
00040 #include "asterisk/file.h"
00041 #include "asterisk/channel.h"
00042 #include "asterisk/pbx.h"
00043 #include "asterisk/module.h"
00044 #include "asterisk/translate.h"
00045 #include "asterisk/image.h"
00046
00047 static char *app = "Flash";
00048
00049 static char *synopsis = "Flashes a DAHDI Trunk";
00050
00051 static char *descrip =
00052 "Performs a flash on a DAHDI trunk. This can be used\n"
00053 "to access features provided on an incoming analogue circuit\n"
00054 "such as conference and call waiting. Use with SendDTMF() to\n"
00055 "perform external transfers\n";
00056
00057
00058 static inline int dahdi_wait_event(int fd)
00059 {
00060
00061 int i,j=0;
00062 i = DAHDI_IOMUX_SIGEVENT;
00063 if (ioctl(fd, DAHDI_IOMUX, &i) == -1) return -1;
00064 if (ioctl(fd, DAHDI_GETEVENT, &j) == -1) return -1;
00065 return j;
00066 }
00067
00068 static int flash_exec(struct ast_channel *chan, void *data)
00069 {
00070 int res = -1;
00071 int x;
00072 struct dahdi_params dahdip;
00073
00074 if (strcasecmp(chan->tech->type, "DAHDI")) {
00075 ast_log(LOG_WARNING, "%s is not a DAHDI channel\n", chan->name);
00076 return -1;
00077 }
00078
00079 memset(&dahdip, 0, sizeof(dahdip));
00080 res = ioctl(chan->fds[0], DAHDI_GET_PARAMS, &dahdip);
00081 if (!res) {
00082 if (dahdip.sigtype & __DAHDI_SIG_FXS) {
00083 x = DAHDI_FLASH;
00084 res = ioctl(chan->fds[0], DAHDI_HOOK, &x);
00085 if (!res || (errno == EINPROGRESS)) {
00086 if (res) {
00087
00088 dahdi_wait_event(chan->fds[0]);
00089 }
00090 res = ast_safe_sleep(chan, 1000);
00091 ast_verb(3, "Flashed channel %s\n", chan->name);
00092 } else
00093 ast_log(LOG_WARNING, "Unable to flash channel %s: %s\n", chan->name, strerror(errno));
00094 } else
00095 ast_log(LOG_WARNING, "%s is not an FXO Channel\n", chan->name);
00096 } else
00097 ast_log(LOG_WARNING, "Unable to get parameters of %s: %s\n", chan->name, strerror(errno));
00098
00099 return res;
00100 }
00101
00102 static int unload_module(void)
00103 {
00104 return ast_unregister_application(app);
00105 }
00106
00107 static int load_module(void)
00108 {
00109 return ast_register_application(app, flash_exec, synopsis, descrip);
00110 }
00111
00112 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Flash channel application");
00113