Asterisk - The Open Source Telephony Project  18.5.0
app_flash.c
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 1999 - 2005, Digium, Inc.
5  *
6  * Mark Spencer <[email protected]>
7  *
8  * See http://www.asterisk.org for more information about
9  * the Asterisk project. Please do not directly contact
10  * any of the maintainers of this project for assistance;
11  * the project provides a web site, mailing lists and IRC
12  * channels for your use.
13  *
14  * This program is free software, distributed under the terms of
15  * the GNU General Public License Version 2. See the LICENSE file
16  * at the top of the source tree.
17  */
18 
19 /*! \file
20  *
21  * \brief App to flash a DAHDI trunk
22  *
23  * \author Mark Spencer <[email protected]>
24  *
25  * \ingroup applications
26  */
27 
28 /*** MODULEINFO
29  <depend>dahdi</depend>
30  <support_level>core</support_level>
31  ***/
32 
33 #include "asterisk.h"
34 
35 #include <dahdi/user.h>
36 
37 #include "asterisk/lock.h"
38 #include "asterisk/file.h"
39 #include "asterisk/channel.h"
40 #include "asterisk/pbx.h"
41 #include "asterisk/module.h"
42 #include "asterisk/translate.h"
43 #include "asterisk/image.h"
44 
45 /*** DOCUMENTATION
46  <application name="Flash" language="en_US">
47  <synopsis>
48  Flashes a DAHDI Trunk.
49  </synopsis>
50  <syntax />
51  <description>
52  <para>Performs a flash on a DAHDI trunk. This can be used to access features
53  provided on an incoming analogue circuit such as conference and call waiting.
54  Use with SendDTMF() to perform external transfers.</para>
55  </description>
56  <see-also>
57  <ref type="application">SendDTMF</ref>
58  </see-also>
59  </application>
60  ***/
61 
62 static char *app = "Flash";
63 
64 static inline int dahdi_wait_event(int fd)
65 {
66  /* Avoid the silly dahdi_waitevent which ignores a bunch of events */
67  int i,j=0;
68  i = DAHDI_IOMUX_SIGEVENT;
69  if (ioctl(fd, DAHDI_IOMUX, &i) == -1) return -1;
70  if (ioctl(fd, DAHDI_GETEVENT, &j) == -1) return -1;
71  return j;
72 }
73 
74 static int flash_exec(struct ast_channel *chan, const char *data)
75 {
76  int res = -1;
77  int x;
78  struct dahdi_params dahdip;
79 
80  if (strcasecmp(ast_channel_tech(chan)->type, "DAHDI")) {
81  ast_log(LOG_WARNING, "%s is not a DAHDI channel\n", ast_channel_name(chan));
82  return -1;
83  }
84 
85  memset(&dahdip, 0, sizeof(dahdip));
86  res = ioctl(ast_channel_fd(chan, 0), DAHDI_GET_PARAMS, &dahdip);
87  if (!res) {
88  if (dahdip.sigtype & __DAHDI_SIG_FXS) {
89  x = DAHDI_FLASH;
90  res = ioctl(ast_channel_fd(chan, 0), DAHDI_HOOK, &x);
91  if (!res || (errno == EINPROGRESS)) {
92  if (res) {
93  /* Wait for the event to finish */
95  }
96  res = ast_safe_sleep(chan, 1000);
97  ast_verb(3, "Flashed channel %s\n", ast_channel_name(chan));
98  } else
99  ast_log(LOG_WARNING, "Unable to flash channel %s: %s\n", ast_channel_name(chan), strerror(errno));
100  } else
101  ast_log(LOG_WARNING, "%s is not an FXO Channel\n", ast_channel_name(chan));
102  } else
103  ast_log(LOG_WARNING, "Unable to get parameters of %s: %s\n", ast_channel_name(chan), strerror(errno));
104 
105  return res;
106 }
107 
108 static int unload_module(void)
109 {
111 }
112 
113 static int load_module(void)
114 {
116 }
117 
118 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Flash channel application");
int ast_safe_sleep(struct ast_channel *chan, int ms)
Wait for a specified amount of time, looking for hangups.
Definition: channel.c:1574
static char * app
Definition: app_flash.c:62
static const char type[]
Definition: chan_ooh323.c:109
Main Channel structure associated with a channel.
#define AST_MODULE_INFO_STANDARD(keystr, desc)
Definition: module.h:567
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
Support for translation of data formats. translate.c.
#define LOG_WARNING
Definition: logger.h:274
static int flash_exec(struct ast_channel *chan, const char *data)
Definition: app_flash.c:74
Generic File Format Support. Should be included by clients of the file handling routines. File service providers should instead include mod_format.h.
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx_app.c:392
#define ast_verb(level,...)
Definition: logger.h:463
#define ast_log
Definition: astobj2.c:42
General Asterisk channel definitions for image handling.
static int load_module(void)
Definition: app_flash.c:113
General Asterisk PBX channel definitions.
static int unload_module(void)
Definition: app_flash.c:108
Core PBX routines and definitions.
static int dahdi_wait_event(int fd)
Definition: app_flash.c:64
int errno
int ast_channel_fd(const struct ast_channel *chan, int which)
const char * ast_channel_name(const struct ast_channel *chan)
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:46
Asterisk module definitions.
const struct ast_channel_tech * ast_channel_tech(const struct ast_channel *chan)
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:626