Wed Jan 8 2020 09:49:39

Asterisk developer's documentation


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  <support_level>extended</support_level>
30  ***/
31 
32 #include "asterisk.h"
33 
34 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 413586 $")
35 
36 #include "asterisk/lock.h"
37 #include "asterisk/file.h"
38 #include "asterisk/channel.h"
39 #include "asterisk/pbx.h"
40 #include "asterisk/module.h"
41 #include "asterisk/adsi.h"
42 
43 /*** DOCUMENTATION
44  <application name="GetCPEID" language="en_US">
45  <synopsis>
46  Get ADSI CPE ID.
47  </synopsis>
48  <syntax />
49  <description>
50  <para>Obtains and displays ADSI CPE ID and other information in order
51  to properly setup <filename>dahdi.conf</filename> for on-hook operations.</para>
52  </description>
53  </application>
54  ***/
55 static char *app = "GetCPEID";
56 
57 static int cpeid_setstatus(struct ast_channel *chan, char *stuff[], int voice)
58 {
59  int justify[5] = { ADSI_JUST_CENT, ADSI_JUST_LEFT, ADSI_JUST_LEFT, ADSI_JUST_LEFT };
60  char *tmp[5];
61  int x;
62  for (x=0;x<4;x++)
63  tmp[x] = stuff[x];
64  tmp[4] = NULL;
65  return ast_adsi_print(chan, tmp, justify, voice);
66 }
67 
68 static int cpeid_exec(struct ast_channel *chan, const char *idata)
69 {
70  int res=0;
71  unsigned char cpeid[4];
72  int gotgeometry = 0;
73  int gotcpeid = 0;
74  int width, height, buttons;
75  char *data[4];
76  unsigned int x;
77 
78  for (x = 0; x < 4; x++)
79  data[x] = ast_alloca(80);
80 
81  strcpy(data[0], "** CPE Info **");
82  strcpy(data[1], "Identifying CPE...");
83  strcpy(data[2], "Please wait...");
84  res = ast_adsi_load_session(chan, NULL, 0, 1);
85  if (res > 0) {
86  cpeid_setstatus(chan, data, 0);
87  res = ast_adsi_get_cpeid(chan, cpeid, 0);
88  if (res > 0) {
89  gotcpeid = 1;
90  ast_verb(3, "Got CPEID of '%02x:%02x:%02x:%02x' on '%s'\n",
91  (unsigned)cpeid[0], (unsigned)cpeid[1], (unsigned)cpeid[2],
92  (unsigned)cpeid[3], chan->name);
93  }
94  if (res > -1) {
95  strcpy(data[1], "Measuring CPE...");
96  strcpy(data[2], "Please wait...");
97  cpeid_setstatus(chan, data, 0);
98  res = ast_adsi_get_cpeinfo(chan, &width, &height, &buttons, 0);
99  if (res > -1) {
100  ast_verb(3, "CPE has %d lines, %d columns, and %d buttons on '%s'\n", height, width, buttons, chan->name);
101  gotgeometry = 1;
102  }
103  }
104  if (res > -1) {
105  if (gotcpeid)
106  snprintf(data[1], 80, "CPEID: %02x:%02x:%02x:%02x",
107  (unsigned)cpeid[0], (unsigned)cpeid[1],
108  (unsigned)cpeid[2], (unsigned)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 
133 static int unload_module(void)
134 {
135  return ast_unregister_application(app);
136 }
137 
138 static int load_module(void)
139 {
141 }
142 
144  .load = load_module,
145  .unload = unload_module,
146  .nonoptreq = "res_adsi",
147  );
Main Channel structure associated with a channel.
Definition: channel.h:742
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: utils.h:653
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:68
static int load_module(void)
Definition: app_getcpeid.c:138
#define ADSI_JUST_LEFT
Definition: adsi.h:112
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...)
Definition: module.h:374
Generic File Format Support. Should be included by clients of the file handling routines. File service providers should instead include mod_format.h.
static struct adsi_event justify[]
Definition: app_adsiprog.c:105
ADSI Support (built upon Caller*ID)
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx.c:7705
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:243
General Asterisk PBX channel definitions.
Core PBX routines and definitions.
static int cpeid_setstatus(struct ast_channel *chan, char *stuff[], int voice)
Definition: app_getcpeid.c:57
const ast_string_field name
Definition: channel.h:787
int ast_waitfordigit(struct ast_channel *c, int ms)
Waits for a digit.
Definition: channel.c:3552
static int unload_module(void)
Definition: app_getcpeid.c:133
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:38
Asterisk module definitions.
static char * app
Definition: app_getcpeid.c:55
#define ADSI_JUST_CENT
Definition: adsi.h:114
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:437
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.
Definition: asterisk.h:180
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