Asterisk - The Open Source Telephony Project  18.5.0
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 <[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  <synopsis>
45  Get ADSI CPE ID.
46  </synopsis>
47  <syntax />
48  <description>
49  <para>Obtains and displays ADSI CPE ID and other information in order
50  to properly setup <filename>dahdi.conf</filename> for on-hook operations.</para>
51  </description>
52  </application>
53  ***/
54 static char *app = "GetCPEID";
55 
56 static int cpeid_setstatus(struct ast_channel *chan, char *stuff[], int voice)
57 {
58  int justify[5] = { ADSI_JUST_CENT, ADSI_JUST_LEFT, ADSI_JUST_LEFT, ADSI_JUST_LEFT };
59  char *tmp[5];
60  int x;
61  for (x=0;x<4;x++)
62  tmp[x] = stuff[x];
63  tmp[4] = NULL;
64  return ast_adsi_print(chan, tmp, justify, voice);
65 }
66 
67 static int cpeid_exec(struct ast_channel *chan, const char *idata)
68 {
69  int res=0;
70  unsigned char cpeid[4];
71  int gotgeometry = 0;
72  int gotcpeid = 0;
73  int width, height, buttons;
74  char *data[4];
75  unsigned int x;
76 
77  for (x = 0; x < 4; x++)
78  data[x] = ast_alloca(80);
79 
80  strcpy(data[0], "** CPE Info **");
81  strcpy(data[1], "Identifying CPE...");
82  strcpy(data[2], "Please wait...");
83  res = ast_adsi_load_session(chan, NULL, 0, 1);
84  if (res > 0) {
85  cpeid_setstatus(chan, data, 0);
86  res = ast_adsi_get_cpeid(chan, cpeid, 0);
87  if (res > 0) {
88  gotcpeid = 1;
89  ast_verb(3, "Got CPEID of '%02hhx:%02hhx:%02hhx:%02hhx' on '%s'\n",
90  cpeid[0], cpeid[1], cpeid[2], cpeid[3], ast_channel_name(chan));
91  }
92  if (res > -1) {
93  strcpy(data[1], "Measuring CPE...");
94  strcpy(data[2], "Please wait...");
95  cpeid_setstatus(chan, data, 0);
96  res = ast_adsi_get_cpeinfo(chan, &width, &height, &buttons, 0);
97  if (res > -1) {
98  ast_verb(3, "CPE has %d lines, %d columns, and %d buttons on '%s'\n", height, width, buttons, ast_channel_name(chan));
99  gotgeometry = 1;
100  }
101  }
102  if (res > -1) {
103  if (gotcpeid)
104  snprintf(data[1], 80, "CPEID: %02hhx:%02hhx:%02hhx:%02hhx",
105  cpeid[0], cpeid[1], cpeid[2], cpeid[3]);
106  else
107  strcpy(data[1], "CPEID Unknown");
108  if (gotgeometry)
109  snprintf(data[2], 80, "Geom: %dx%d, %d buttons", width, height, buttons);
110  else
111  strcpy(data[2], "Geometry unknown");
112  strcpy(data[3], "Press # to exit");
113  cpeid_setstatus(chan, data, 1);
114  for(;;) {
115  res = ast_waitfordigit(chan, 1000);
116  if (res < 0)
117  break;
118  if (res == '#') {
119  res = 0;
120  break;
121  }
122  }
124  }
125  }
126 
127  return res;
128 }
129 
130 static int unload_module(void)
131 {
133 }
134 
135 static int load_module(void)
136 {
138 }
139 
141  .support_level = AST_MODULE_SUPPORT_DEPRECATED,
142  .load = load_module,
143  .unload = unload_module,
144  .requires = "res_adsi",
145 );
Main Channel structure associated with a channel.
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
static int tmp()
Definition: bt_open.c:389
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
static int cpeid_exec(struct ast_channel *chan, const char *idata)
Definition: app_getcpeid.c:67
static int load_module(void)
Definition: app_getcpeid.c:135
#define ADSI_JUST_LEFT
Definition: adsi.h:112
Generic File Format Support. Should be included by clients of the file handling routines. File service providers should instead include mod_format.h.
#define NULL
Definition: resample.c:96
ADSI Support (built upon Caller*ID)
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx_app.c:392
int ast_adsi_get_cpeid(struct ast_channel *chan, unsigned char *cpeid, int voice)
Definition: adsi.c:164
#define ast_verb(level,...)
Definition: logger.h:463
static const struct adsi_event justify[]
Definition: app_adsiprog.c:112
General Asterisk PBX channel definitions.
Core PBX routines and definitions.
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
Definition: astmm.h:290
static int cpeid_setstatus(struct ast_channel *chan, char *stuff[], int voice)
Definition: app_getcpeid.c:56
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS|AST_MODFLAG_LOAD_ORDER, "HTTP Phone Provisioning",.support_level=AST_MODULE_SUPPORT_EXTENDED,.load=load_module,.unload=unload_module,.reload=reload,.load_pri=AST_MODPRI_CHANNEL_DEPEND,.requires="http",)
int ast_waitfordigit(struct ast_channel *c, int ms)
Waits for a digit.
Definition: channel.c:3184
static int unload_module(void)
Definition: app_getcpeid.c:130
const char * ast_channel_name(const struct ast_channel *chan)
int ast_adsi_unload_session(struct ast_channel *chan)
Definition: adsi.c:87
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:46
Asterisk module definitions.
static char * app
Definition: app_getcpeid.c:54
#define ADSI_JUST_CENT
Definition: adsi.h:114
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:626
int ast_adsi_get_cpeinfo(struct ast_channel *chan, int *width, int *height, int *buttons, int voice)
Definition: adsi.c:175
int ast_adsi_print(struct ast_channel *chan, char **lines, int *align, int voice)
Display some stuff on the screen.
Definition: adsi.c:65