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