Debian Codegraph @

apps/app_getcpeid.c

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