app_flash.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * Asterisk -- A telephony toolkit for Linux.
  3. *
  4. * App to flash a zap trunk
  5. *
  6. * Copyright (C) 1999, Mark Spencer
  7. *
  8. * Mark Spencer <markster@linux-support.net>
  9. *
  10. * This program is free software, distributed under the terms of
  11. * the GNU General Public License
  12. */
  13. #include <asterisk/lock.h>
  14. #include <asterisk/file.h>
  15. #include <asterisk/logger.h>
  16. #include <asterisk/channel.h>
  17. #include <asterisk/pbx.h>
  18. #include <asterisk/module.h>
  19. #include <asterisk/translate.h>
  20. #include <asterisk/image.h>
  21. #include <asterisk/options.h>
  22. #include <sys/ioctl.h>
  23. #ifdef __linux__
  24. #include <linux/zaptel.h>
  25. #else
  26. #include <zaptel.h>
  27. #endif /* __linux__ */
  28. #include <string.h>
  29. #include <errno.h>
  30. #include <stdlib.h>
  31. static char *tdesc = "Flash zap trunk application";
  32. static char *app = "Flash";
  33. static char *synopsis = "Flashes a Zap Trunk";
  34. static char *descrip =
  35. " Flash(): Sends a flash on a zap trunk. This is only a hack for\n"
  36. "people who want to perform transfers and such via AGI and is generally\n"
  37. "quite useless otherwise. Returns 0 on success or -1 if this is not\n"
  38. "a zap trunk\n";
  39. STANDARD_LOCAL_USER;
  40. LOCAL_USER_DECL;
  41. static inline int zt_wait_event(int fd)
  42. {
  43. /* Avoid the silly zt_waitevent which ignores a bunch of events */
  44. int i,j=0;
  45. i = ZT_IOMUX_SIGEVENT;
  46. if (ioctl(fd, ZT_IOMUX, &i) == -1) return -1;
  47. if (ioctl(fd, ZT_GETEVENT, &j) == -1) return -1;
  48. return j;
  49. }
  50. static int flash_exec(struct ast_channel *chan, void *data)
  51. {
  52. int res = -1;
  53. int x;
  54. struct localuser *u;
  55. struct zt_params ztp;
  56. LOCAL_USER_ADD(u);
  57. if (!strcasecmp(chan->type, "Zap")) {
  58. memset(&ztp, 0, sizeof(ztp));
  59. res = ioctl(chan->fds[0], ZT_GET_PARAMS, &ztp);
  60. if (!res) {
  61. if (ztp.sigtype & __ZT_SIG_FXS) {
  62. x = ZT_FLASH;
  63. res = ioctl(chan->fds[0], ZT_HOOK, &x);
  64. if (!res || (errno == EINPROGRESS)) {
  65. if (res) {
  66. /* Wait for the event to finish */
  67. zt_wait_event(chan->fds[0]);
  68. }
  69. res = ast_safe_sleep(chan, 1000);
  70. if (option_verbose > 2)
  71. ast_verbose(VERBOSE_PREFIX_3 "Flashed channel %s\n", chan->name);
  72. } else
  73. ast_log(LOG_WARNING, "Unable to flash channel %s: %s\n", chan->name, strerror(errno));
  74. } else
  75. ast_log(LOG_WARNING, "%s is not an FXO Channel\n", chan->name);
  76. } else
  77. ast_log(LOG_WARNING, "Unable to get parameters of %s: %s\n", chan->name, strerror(errno));
  78. } else
  79. ast_log(LOG_WARNING, "%s is not a Zap channel\n", chan->name);
  80. LOCAL_USER_REMOVE(u);
  81. return res;
  82. }
  83. int unload_module(void)
  84. {
  85. STANDARD_HANGUP_LOCALUSERS;
  86. return ast_unregister_application(app);
  87. }
  88. int load_module(void)
  89. {
  90. return ast_register_application(app, flash_exec, synopsis, descrip);
  91. }
  92. char *description(void)
  93. {
  94. return tdesc;
  95. }
  96. int usecount(void)
  97. {
  98. int res;
  99. STANDARD_USECOUNT(res);
  100. return res;
  101. }
  102. char *key()
  103. {
  104. return ASTERISK_GPL_KEY;
  105. }