Asterisk - The Open Source Telephony Project GIT-master-754dea3
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Modules Pages
app_getcpeid.c
Go to the documentation of this file.
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
19/*! \file
20 *
21 * \brief Get ADSI CPE ID
22 *
23 * \author Mark Spencer <markster@digium.com>
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 ***/
57static char *app = "GetCPEID";
58
59static int cpeid_setstatus(struct ast_channel *chan, char *stuff[], int voice)
60{
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
70static 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 }
127 }
128 }
129
130 return res;
131}
132
133static int unload_module(void)
134{
136}
137
138static int load_module(void)
139{
141}
142
144 .support_level = AST_MODULE_SUPPORT_DEPRECATED,
145 .load = load_module,
146 .unload = unload_module,
147 .requires = "res_adsi",
ADSI Support (built upon Caller*ID)
int ast_adsi_unload_session(struct ast_channel *chan)
Definition: adsi.c:87
#define ADSI_JUST_CENT
Definition: adsi.h:114
int ast_adsi_print(struct ast_channel *chan, char **lines, int *align, int voice)
Display some stuff on the screen.
Definition: adsi.c:65
#define ADSI_JUST_LEFT
Definition: adsi.h:112
int ast_adsi_get_cpeid(struct ast_channel *chan, unsigned char *cpeid, int voice)
Definition: adsi.c:164
int ast_adsi_load_session(struct ast_channel *chan, unsigned char *app, int ver, int data)
Check if scripts for a given app are already loaded. Version may be -1, if any version is okay,...
Definition: adsi.c:76
int ast_adsi_get_cpeinfo(struct ast_channel *chan, int *width, int *height, int *buttons, int voice)
Definition: adsi.c:175
static const struct adsi_event justify[]
Definition: app_adsiprog.c:115
static int cpeid_setstatus(struct ast_channel *chan, char *stuff[], int voice)
Definition: app_getcpeid.c:59
static char * app
Definition: app_getcpeid.c:57
static int cpeid_exec(struct ast_channel *chan, const char *idata)
Definition: app_getcpeid.c:70
static int load_module(void)
Definition: app_getcpeid.c:138
static int unload_module(void)
Definition: app_getcpeid.c:133
Asterisk main include file. File version handling, generic pbx functions.
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
Definition: astmm.h:288
General Asterisk PBX channel definitions.
int ast_waitfordigit(struct ast_channel *c, int ms)
Waits for a digit.
Definition: channel.c:3203
const char * ast_channel_name(const struct ast_channel *chan)
Generic File Format Support. Should be included by clients of the file handling routines....
#define ast_verb(level,...)
Asterisk locking-related definitions:
Asterisk module definitions.
@ AST_MODFLAG_DEFAULT
Definition: module.h:329
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...)
Definition: module.h:557
@ AST_MODULE_SUPPORT_DEPRECATED
Definition: module.h:123
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:46
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx_app.c:392
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:640
Core PBX routines and definitions.
#define NULL
Definition: resample.c:96
Main Channel structure associated with a channel.