app_flash.c
Go to the documentation of this file.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
00033 #include "asterisk.h"
00034
00035 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 328209 $")
00036
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
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064 static char *app = "Flash";
00065
00066 static inline int dahdi_wait_event(int fd)
00067 {
00068
00069 int i,j=0;
00070 i = DAHDI_IOMUX_SIGEVENT;
00071 if (ioctl(fd, DAHDI_IOMUX, &i) == -1) return -1;
00072 if (ioctl(fd, DAHDI_GETEVENT, &j) == -1) return -1;
00073 return j;
00074 }
00075
00076 static int flash_exec(struct ast_channel *chan, const char *data)
00077 {
00078 int res = -1;
00079 int x;
00080 struct dahdi_params dahdip;
00081
00082 if (strcasecmp(chan->tech->type, "DAHDI")) {
00083 ast_log(LOG_WARNING, "%s is not a DAHDI channel\n", chan->name);
00084 return -1;
00085 }
00086
00087 memset(&dahdip, 0, sizeof(dahdip));
00088 res = ioctl(chan->fds[0], DAHDI_GET_PARAMS, &dahdip);
00089 if (!res) {
00090 if (dahdip.sigtype & __DAHDI_SIG_FXS) {
00091 x = DAHDI_FLASH;
00092 res = ioctl(chan->fds[0], DAHDI_HOOK, &x);
00093 if (!res || (errno == EINPROGRESS)) {
00094 if (res) {
00095
00096 dahdi_wait_event(chan->fds[0]);
00097 }
00098 res = ast_safe_sleep(chan, 1000);
00099 ast_verb(3, "Flashed channel %s\n", chan->name);
00100 } else
00101 ast_log(LOG_WARNING, "Unable to flash channel %s: %s\n", chan->name, strerror(errno));
00102 } else
00103 ast_log(LOG_WARNING, "%s is not an FXO Channel\n", chan->name);
00104 } else
00105 ast_log(LOG_WARNING, "Unable to get parameters of %s: %s\n", chan->name, strerror(errno));
00106
00107 return res;
00108 }
00109
00110 static int unload_module(void)
00111 {
00112 return ast_unregister_application(app);
00113 }
00114
00115 static int load_module(void)
00116 {
00117 return ast_register_application_xml(app, flash_exec);
00118 }
00119
00120 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Flash channel application");
00121