| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 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 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
static char *app = "Flash"; |
| 66 |
|
| 67 |
static inline int dahdi_wait_event(int fd) |
| 68 |
{ |
| 69 |
|
| 70 |
int i,j=0; |
| 71 |
i = DAHDI_IOMUX_SIGEVENT; |
| 72 |
if (ioctl(fd, DAHDI_IOMUX, &i) == -1) return -1; |
| 73 |
if (ioctl(fd, DAHDI_GETEVENT, &j) == -1) return -1; |
| 74 |
return j; |
| 75 |
} |
| 76 |
|
| 77 |
static int flash_exec(struct ast_channel *chan, const char *data) |
| 78 |
{ |
| 79 |
int res = -1; |
| 80 |
int x; |
| 81 |
struct dahdi_params dahdip; |
| 82 |
|
| 83 |
if (strcasecmp(ast_channel_tech(chan)->type, "DAHDI")) { |
| 84 |
ast_log(LOG_WARNING, "%s is not a DAHDI channel\n", ast_channel_name(chan)); |
| 85 |
return -1; |
| 86 |
} |
| 87 |
|
| 88 |
memset(&dahdip, 0, sizeof(dahdip)); |
| 89 |
res = ioctl(ast_channel_fd(chan, 0), DAHDI_GET_PARAMS, &dahdip); |
| 90 |
if (!res) { |
| 91 |
if (dahdip.sigtype & __DAHDI_SIG_FXS) { |
| 92 |
x = DAHDI_FLASH; |
| 93 |
res = ioctl(ast_channel_fd(chan, 0), DAHDI_HOOK, &x); |
| 94 |
if (!res || (errno == EINPROGRESS)) { |
| 95 |
if (res) { |
| 96 |
|
| 97 |
dahdi_wait_event(ast_channel_fd(chan, 0)); |
| 98 |
} |
| 99 |
res = ast_safe_sleep(chan, 1000); |
| 100 |
ast_verb(3, "Flashed channel %s\n", ast_channel_name(chan)); |
| 101 |
} else |
| 102 |
ast_log(LOG_WARNING, "Unable to flash channel %s: %s\n", ast_channel_name(chan), strerror(errno)); |
| 103 |
} else |
| 104 |
ast_log(LOG_WARNING, "%s is not an FXO Channel\n", ast_channel_name(chan)); |
| 105 |
} else |
| 106 |
ast_log(LOG_WARNING, "Unable to get parameters of %s: %s\n", ast_channel_name(chan), strerror(errno)); |
| 107 |
|
| 108 |
return res; |
| 109 |
} |
| 110 |
|
| 111 |
static int unload_module(void) |
| 112 |
{ |
| 113 |
return ast_unregister_application(app); |
| 114 |
} |
| 115 |
|
| 116 |
static int load_module(void) |
| 117 |
{ |
| 118 |
return ast_register_application_xml(app, flash_exec); |
| 119 |
} |
| 120 |
|
| 121 |
AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Flash channel application"); |