app_getcpeid.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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 Get ADSI CPE ID
  21. *
  22. * \author Mark Spencer <markster@digium.com>
  23. *
  24. * \ingroup applications
  25. */
  26. /*** MODULEINFO
  27. <support_level>extended</support_level>
  28. ***/
  29. #include "asterisk.h"
  30. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  31. #include "asterisk/lock.h"
  32. #include "asterisk/file.h"
  33. #include "asterisk/channel.h"
  34. #include "asterisk/pbx.h"
  35. #include "asterisk/module.h"
  36. #include "asterisk/adsi.h"
  37. /*** DOCUMENTATION
  38. <application name="GetCPEID" language="en_US">
  39. <synopsis>
  40. Get ADSI CPE ID.
  41. </synopsis>
  42. <syntax />
  43. <description>
  44. <para>Obtains and displays ADSI CPE ID and other information in order
  45. to properly setup <filename>dahdi.conf</filename> for on-hook operations.</para>
  46. </description>
  47. </application>
  48. ***/
  49. static char *app = "GetCPEID";
  50. static int cpeid_setstatus(struct ast_channel *chan, char *stuff[], int voice)
  51. {
  52. int justify[5] = { ADSI_JUST_CENT, ADSI_JUST_LEFT, ADSI_JUST_LEFT, ADSI_JUST_LEFT };
  53. char *tmp[5];
  54. int x;
  55. for (x=0;x<4;x++)
  56. tmp[x] = stuff[x];
  57. tmp[4] = NULL;
  58. return ast_adsi_print(chan, tmp, justify, voice);
  59. }
  60. static int cpeid_exec(struct ast_channel *chan, const char *idata)
  61. {
  62. int res=0;
  63. unsigned char cpeid[4];
  64. int gotgeometry = 0;
  65. int gotcpeid = 0;
  66. int width, height, buttons;
  67. char *data[4];
  68. unsigned int x;
  69. for (x = 0; x < 4; x++)
  70. data[x] = ast_alloca(80);
  71. strcpy(data[0], "** CPE Info **");
  72. strcpy(data[1], "Identifying CPE...");
  73. strcpy(data[2], "Please wait...");
  74. res = ast_adsi_load_session(chan, NULL, 0, 1);
  75. if (res > 0) {
  76. cpeid_setstatus(chan, data, 0);
  77. res = ast_adsi_get_cpeid(chan, cpeid, 0);
  78. if (res > 0) {
  79. gotcpeid = 1;
  80. ast_verb(3, "Got CPEID of '%02hhx:%02hhx:%02hhx:%02hhx' on '%s'\n",
  81. cpeid[0], cpeid[1], cpeid[2], cpeid[3], ast_channel_name(chan));
  82. }
  83. if (res > -1) {
  84. strcpy(data[1], "Measuring CPE...");
  85. strcpy(data[2], "Please wait...");
  86. cpeid_setstatus(chan, data, 0);
  87. res = ast_adsi_get_cpeinfo(chan, &width, &height, &buttons, 0);
  88. if (res > -1) {
  89. ast_verb(3, "CPE has %d lines, %d columns, and %d buttons on '%s'\n", height, width, buttons, ast_channel_name(chan));
  90. gotgeometry = 1;
  91. }
  92. }
  93. if (res > -1) {
  94. if (gotcpeid)
  95. snprintf(data[1], 80, "CPEID: %02hhx:%02hhx:%02hhx:%02hhx",
  96. cpeid[0], cpeid[1], cpeid[2], cpeid[3]);
  97. else
  98. strcpy(data[1], "CPEID Unknown");
  99. if (gotgeometry)
  100. snprintf(data[2], 80, "Geom: %dx%d, %d buttons", width, height, buttons);
  101. else
  102. strcpy(data[2], "Geometry unknown");
  103. strcpy(data[3], "Press # to exit");
  104. cpeid_setstatus(chan, data, 1);
  105. for(;;) {
  106. res = ast_waitfordigit(chan, 1000);
  107. if (res < 0)
  108. break;
  109. if (res == '#') {
  110. res = 0;
  111. break;
  112. }
  113. }
  114. ast_adsi_unload_session(chan);
  115. }
  116. }
  117. return res;
  118. }
  119. static int unload_module(void)
  120. {
  121. return ast_unregister_application(app);
  122. }
  123. static int load_module(void)
  124. {
  125. return ast_register_application_xml(app, cpeid_exec);
  126. }
  127. AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Get ADSI CPE ID",
  128. .support_level = AST_MODULE_SUPPORT_EXTENDED,
  129. .load = load_module,
  130. .unload = unload_module,
  131. .nonoptreq = "res_adsi",
  132. );