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 #include <stdlib.h>
00027 #include <stdio.h>
00028 #include <string.h>
00029 #include <errno.h>
00030 #include <sys/ioctl.h>
00031 #ifdef __linux__
00032 #include <linux/zaptel.h>
00033 #else
00034 #include <zaptel.h>
00035 #endif
00036
00037 #include "asterisk.h"
00038
00039 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 7221 $")
00040
00041 #include "asterisk/lock.h"
00042 #include "asterisk/file.h"
00043 #include "asterisk/logger.h"
00044 #include "asterisk/channel.h"
00045 #include "asterisk/pbx.h"
00046 #include "asterisk/module.h"
00047 #include "asterisk/translate.h"
00048 #include "asterisk/image.h"
00049 #include "asterisk/options.h"
00050
00051 static char *tdesc = "Flash zap trunk application";
00052
00053 static char *app = "Flash";
00054
00055 static char *synopsis = "Flashes a Zap Trunk";
00056
00057 static char *descrip =
00058 " Flash(): Sends a flash on a zap trunk. This is only a hack for\n"
00059 "people who want to perform transfers and such via AGI and is generally\n"
00060 "quite useless oths application will only work on Zap trunks.\n";
00061
00062 STANDARD_LOCAL_USER;
00063
00064 LOCAL_USER_DECL;
00065
00066 static inline int zt_wait_event(int fd)
00067 {
00068
00069 int i,j=0;
00070 i = ZT_IOMUX_SIGEVENT;
00071 if (ioctl(fd, ZT_IOMUX, &i) == -1) return -1;
00072 if (ioctl(fd, ZT_GETEVENT, &j) == -1) return -1;
00073 return j;
00074 }
00075
00076 static int flash_exec(struct ast_channel *chan, void *data)
00077 {
00078 int res = -1;
00079 int x;
00080 struct localuser *u;
00081 struct zt_params ztp;
00082 LOCAL_USER_ADD(u);
00083 if (!strcasecmp(chan->type, "Zap")) {
00084 memset(&ztp, 0, sizeof(ztp));
00085 res = ioctl(chan->fds[0], ZT_GET_PARAMS, &ztp);
00086 if (!res) {
00087 if (ztp.sigtype & __ZT_SIG_FXS) {
00088 x = ZT_FLASH;
00089 res = ioctl(chan->fds[0], ZT_HOOK, &x);
00090 if (!res || (errno == EINPROGRESS)) {
00091 if (res) {
00092
00093 zt_wait_event(chan->fds[0]);
00094 }
00095 res = ast_safe_sleep(chan, 1000);
00096 if (option_verbose > 2)
00097 ast_verbose(VERBOSE_PREFIX_3 "Flashed channel %s\n", chan->name);
00098 } else
00099 ast_log(LOG_WARNING, "Unable to flash channel %s: %s\n", chan->name, strerror(errno));
00100 } else
00101 ast_log(LOG_WARNING, "%s is not an FXO Channel\n", chan->name);
00102 } else
00103 ast_log(LOG_WARNING, "Unable to get parameters of %s: %s\n", chan->name, strerror(errno));
00104 } else
00105 ast_log(LOG_WARNING, "%s is not a Zap channel\n", chan->name);
00106 LOCAL_USER_REMOVE(u);
00107 return res;
00108 }
00109
00110 int unload_module(void)
00111 {
00112 int res;
00113
00114 res = ast_unregister_application(app);
00115
00116 STANDARD_HANGUP_LOCALUSERS;
00117
00118 return res;
00119 }
00120
00121 int load_module(void)
00122 {
00123 return ast_register_application(app, flash_exec, synopsis, descrip);
00124 }
00125
00126 char *description(void)
00127 {
00128 return tdesc;
00129 }
00130
00131 int usecount(void)
00132 {
00133 int res;
00134 STANDARD_USECOUNT(res);
00135 return res;
00136 }
00137
00138 char *key()
00139 {
00140 return ASTERISK_GPL_KEY;
00141 }