app_flash.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 1999 - 2005, Digium, Inc.
  5. *
  6. * Mark Spencer <markster@digium.com>
  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. /*! \file
  19. *
  20. * \brief App to flash a zap trunk
  21. *
  22. * \ingroup applications
  23. */
  24. #include <stdlib.h>
  25. #include <stdio.h>
  26. #include <string.h>
  27. #include <errno.h>
  28. #include <sys/ioctl.h>
  29. #ifdef __linux__
  30. #include <linux/zaptel.h>
  31. #else
  32. #include <zaptel.h>
  33. #endif /* __linux__ */
  34. #include "asterisk.h"
  35. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  36. #include "asterisk/lock.h"
  37. #include "asterisk/file.h"
  38. #include "asterisk/logger.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. #include "asterisk/options.h"
  45. static char *tdesc = "Flash zap trunk application";
  46. static char *app = "Flash";
  47. static char *synopsis = "Flashes a Zap Trunk";
  48. static char *descrip =
  49. " Flash(): Sends a flash on a zap trunk. This is only a hack for\n"
  50. "people who want to perform transfers and such via AGI and is generally\n"
  51. "quite useless oths application will only work on Zap trunks.\n";
  52. STANDARD_LOCAL_USER;
  53. LOCAL_USER_DECL;
  54. static inline int zt_wait_event(int fd)
  55. {
  56. /* Avoid the silly zt_waitevent which ignores a bunch of events */
  57. int i,j=0;
  58. i = ZT_IOMUX_SIGEVENT;
  59. if (ioctl(fd, ZT_IOMUX, &i) == -1) return -1;
  60. if (ioctl(fd, ZT_GETEVENT, &j) == -1) return -1;
  61. return j;
  62. }
  63. static int flash_exec(struct ast_channel *chan, void *data)
  64. {
  65. int res = -1;
  66. int x;
  67. struct localuser *u;
  68. struct zt_params ztp;
  69. LOCAL_USER_ADD(u);
  70. if (!strcasecmp(chan->type, "Zap")) {
  71. memset(&ztp, 0, sizeof(ztp));
  72. res = ioctl(chan->fds[0], ZT_GET_PARAMS, &ztp);
  73. if (!res) {
  74. if (ztp.sigtype & __ZT_SIG_FXS) {
  75. x = ZT_FLASH;
  76. res = ioctl(chan->fds[0], ZT_HOOK, &x);
  77. if (!res || (errno == EINPROGRESS)) {
  78. if (res) {
  79. /* Wait for the event to finish */
  80. zt_wait_event(chan->fds[0]);
  81. }
  82. res = ast_safe_sleep(chan, 1000);
  83. if (option_verbose > 2)
  84. ast_verbose(VERBOSE_PREFIX_3 "Flashed channel %s\n", chan->name);
  85. } else
  86. ast_log(LOG_WARNING, "Unable to flash channel %s: %s\n", chan->name, strerror(errno));
  87. } else
  88. ast_log(LOG_WARNING, "%s is not an FXO Channel\n", chan->name);
  89. } else
  90. ast_log(LOG_WARNING, "Unable to get parameters of %s: %s\n", chan->name, strerror(errno));
  91. } else
  92. ast_log(LOG_WARNING, "%s is not a Zap channel\n", chan->name);
  93. LOCAL_USER_REMOVE(u);
  94. return res;
  95. }
  96. int unload_module(void)
  97. {
  98. int res;
  99. res = ast_unregister_application(app);
  100. STANDARD_HANGUP_LOCALUSERS;
  101. return res;
  102. }
  103. int load_module(void)
  104. {
  105. return ast_register_application(app, flash_exec, synopsis, descrip);
  106. }
  107. char *description(void)
  108. {
  109. return tdesc;
  110. }
  111. int usecount(void)
  112. {
  113. int res;
  114. STANDARD_USECOUNT(res);
  115. return res;
  116. }
  117. char *key()
  118. {
  119. return ASTERISK_GPL_KEY;
  120. }