app_flash.c

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 1999 - 2005, Digium, Inc.
00005  *
00006  * Mark Spencer <markster@digium.com>
00007  *
00008  * See http://www.asterisk.org for more information about
00009  * the Asterisk project. Please do not directly contact
00010  * any of the maintainers of this project for assistance;
00011  * the project provides a web site, mailing lists and IRC
00012  * channels for your use.
00013  *
00014  * This program is free software, distributed under the terms of
00015  * the GNU General Public License Version 2. See the LICENSE file
00016  * at the top of the source tree.
00017  */
00018 
00019 /*! \file
00020  *
00021  * \brief App to flash a DAHDI trunk
00022  *
00023  * \author Mark Spencer <markster@digium.com>
00024  * 
00025  * \ingroup applications
00026  */
00027  
00028 /*** MODULEINFO
00029    <depend>dahdi</depend>
00030    <support_level>core</support_level>
00031  ***/
00032 
00033 #include "asterisk.h"
00034 
00035 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 357721 $")
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 /*** DOCUMENTATION
00048    <application name="Flash" language="en_US">
00049       <synopsis>
00050          Flashes a DAHDI Trunk.
00051       </synopsis>
00052       <syntax />
00053       <description>
00054          <para>Performs a flash on a DAHDI trunk. This can be used to access features
00055          provided on an incoming analogue circuit such as conference and call waiting.
00056          Use with SendDTMF() to perform external transfers.</para>
00057       </description>
00058       <see-also>
00059          <ref type="application">SendDTMF</ref>
00060       </see-also>
00061    </application>
00062  ***/
00063 
00064 static char *app = "Flash";
00065 
00066 static inline int dahdi_wait_event(int fd)
00067 {
00068    /* Avoid the silly dahdi_waitevent which ignores a bunch of events */
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(ast_channel_tech(chan)->type, "DAHDI")) {
00083       ast_log(LOG_WARNING, "%s is not a DAHDI channel\n", ast_channel_name(chan));
00084       return -1;
00085    }
00086    
00087    memset(&dahdip, 0, sizeof(dahdip));
00088    res = ioctl(ast_channel_fd(chan, 0), DAHDI_GET_PARAMS, &dahdip);
00089    if (!res) {
00090       if (dahdip.sigtype & __DAHDI_SIG_FXS) {
00091          x = DAHDI_FLASH;
00092          res = ioctl(ast_channel_fd(chan, 0), DAHDI_HOOK, &x);
00093          if (!res || (errno == EINPROGRESS)) {
00094             if (res) {
00095                /* Wait for the event to finish */
00096                dahdi_wait_event(ast_channel_fd(chan, 0));
00097             }
00098             res = ast_safe_sleep(chan, 1000);
00099             ast_verb(3, "Flashed channel %s\n", ast_channel_name(chan));
00100          } else
00101             ast_log(LOG_WARNING, "Unable to flash channel %s: %s\n", ast_channel_name(chan), strerror(errno));
00102       } else
00103          ast_log(LOG_WARNING, "%s is not an FXO Channel\n", ast_channel_name(chan));
00104    } else
00105       ast_log(LOG_WARNING, "Unable to get parameters of %s: %s\n", ast_channel_name(chan), 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 

Generated on Thu Apr 16 06:27:09 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6