app_flash.c 3.1 KB

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