app_flash.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 DAHDI trunk
  21. *
  22. * \author Mark Spencer <markster@digium.com>
  23. *
  24. * \ingroup applications
  25. */
  26. /*** MODULEINFO
  27. <depend>dahdi</depend>
  28. <support_level>core</support_level>
  29. ***/
  30. #include "asterisk.h"
  31. #include <dahdi/user.h>
  32. #include "asterisk/lock.h"
  33. #include "asterisk/file.h"
  34. #include "asterisk/channel.h"
  35. #include "asterisk/pbx.h"
  36. #include "asterisk/module.h"
  37. #include "asterisk/translate.h"
  38. #include "asterisk/image.h"
  39. /*** DOCUMENTATION
  40. <application name="Flash" language="en_US">
  41. <synopsis>
  42. Flashes a DAHDI Trunk.
  43. </synopsis>
  44. <syntax />
  45. <description>
  46. <para>Performs a flash on a DAHDI trunk. This can be used to access features
  47. provided on an incoming analogue circuit such as conference and call waiting.
  48. Use with SendDTMF() to perform external transfers.</para>
  49. </description>
  50. <see-also>
  51. <ref type="application">SendDTMF</ref>
  52. </see-also>
  53. </application>
  54. ***/
  55. static char *app = "Flash";
  56. static inline int dahdi_wait_event(int fd)
  57. {
  58. /* Avoid the silly dahdi_waitevent which ignores a bunch of events */
  59. int i,j=0;
  60. i = DAHDI_IOMUX_SIGEVENT;
  61. if (ioctl(fd, DAHDI_IOMUX, &i) == -1) return -1;
  62. if (ioctl(fd, DAHDI_GETEVENT, &j) == -1) return -1;
  63. return j;
  64. }
  65. static int flash_exec(struct ast_channel *chan, const char *data)
  66. {
  67. int res = -1;
  68. int x;
  69. struct dahdi_params dahdip;
  70. if (strcasecmp(ast_channel_tech(chan)->type, "DAHDI")) {
  71. ast_log(LOG_WARNING, "%s is not a DAHDI channel\n", ast_channel_name(chan));
  72. return -1;
  73. }
  74. memset(&dahdip, 0, sizeof(dahdip));
  75. res = ioctl(ast_channel_fd(chan, 0), DAHDI_GET_PARAMS, &dahdip);
  76. if (!res) {
  77. if (dahdip.sigtype & __DAHDI_SIG_FXS) {
  78. x = DAHDI_FLASH;
  79. res = ioctl(ast_channel_fd(chan, 0), DAHDI_HOOK, &x);
  80. if (!res || (errno == EINPROGRESS)) {
  81. if (res) {
  82. /* Wait for the event to finish */
  83. dahdi_wait_event(ast_channel_fd(chan, 0));
  84. }
  85. res = ast_safe_sleep(chan, 1000);
  86. ast_verb(3, "Flashed channel %s\n", ast_channel_name(chan));
  87. } else
  88. ast_log(LOG_WARNING, "Unable to flash channel %s: %s\n", ast_channel_name(chan), strerror(errno));
  89. } else
  90. ast_log(LOG_WARNING, "%s is not an FXO Channel\n", ast_channel_name(chan));
  91. } else
  92. ast_log(LOG_WARNING, "Unable to get parameters of %s: %s\n", ast_channel_name(chan), strerror(errno));
  93. return res;
  94. }
  95. static int unload_module(void)
  96. {
  97. return ast_unregister_application(app);
  98. }
  99. static int load_module(void)
  100. {
  101. return ast_register_application_xml(app, flash_exec);
  102. }
  103. AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Flash channel application");