app_getcpeid.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 '%02x:%02x:%02x:%02x' on '%s'\n", cpeid[0], cpeid[1], cpeid[2], cpeid[3], chan->name);
  81. }
  82. if (res > -1) {
  83. strcpy(data[1], "Measuring CPE...");
  84. strcpy(data[2], "Please wait...");
  85. cpeid_setstatus(chan, data, 0);
  86. res = ast_adsi_get_cpeinfo(chan, &width, &height, &buttons, 0);
  87. if (res > -1) {
  88. ast_verb(3, "CPE has %d lines, %d columns, and %d buttons on '%s'\n", height, width, buttons, chan->name);
  89. gotgeometry = 1;
  90. }
  91. }
  92. if (res > -1) {
  93. if (gotcpeid)
  94. snprintf(data[1], 80, "CPEID: %02x:%02x:%02x:%02x", cpeid[0], cpeid[1], cpeid[2], cpeid[3]);
  95. else
  96. strcpy(data[1], "CPEID Unknown");
  97. if (gotgeometry)
  98. snprintf(data[2], 80, "Geom: %dx%d, %d buttons", width, height, buttons);
  99. else
  100. strcpy(data[2], "Geometry unknown");
  101. strcpy(data[3], "Press # to exit");
  102. cpeid_setstatus(chan, data, 1);
  103. for(;;) {
  104. res = ast_waitfordigit(chan, 1000);
  105. if (res < 0)
  106. break;
  107. if (res == '#') {
  108. res = 0;
  109. break;
  110. }
  111. }
  112. ast_adsi_unload_session(chan);
  113. }
  114. }
  115. return res;
  116. }
  117. static int unload_module(void)
  118. {
  119. return ast_unregister_application(app);
  120. }
  121. static int load_module(void)
  122. {
  123. return ast_register_application_xml(app, cpeid_exec);
  124. }
  125. AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Get ADSI CPE ID",
  126. .load = load_module,
  127. .unload = unload_module,
  128. .nonoptreq = "res_adsi",
  129. );