2002-05-13 22:29:39 +00:00
|
|
|
/*
|
2005-09-14 20:46:50 +00:00
|
|
|
* Asterisk -- An open source telephony toolkit.
|
2002-05-13 22:29:39 +00:00
|
|
|
*
|
2005-09-14 20:46:50 +00:00
|
|
|
* Copyright (C) 1999 - 2005, Digium, Inc.
|
2002-05-13 22:29:39 +00:00
|
|
|
*
|
2005-01-08 19:30:40 +00:00
|
|
|
* Mark Spencer <markster@digium.com>
|
2002-05-13 22:29:39 +00:00
|
|
|
*
|
2005-09-14 20:46:50 +00:00
|
|
|
* See http://www.asterisk.org for more information about
|
|
|
|
* the Asterisk project. Please do not directly contact
|
|
|
|
* any of the maintainers of this project for assistance;
|
|
|
|
* the project provides a web site, mailing lists and IRC
|
|
|
|
* channels for your use.
|
|
|
|
*
|
2002-05-13 22:29:39 +00:00
|
|
|
* This program is free software, distributed under the terms of
|
2005-09-14 20:46:50 +00:00
|
|
|
* the GNU General Public License Version 2. See the LICENSE file
|
|
|
|
* at the top of the source tree.
|
|
|
|
*/
|
|
|
|
|
2005-10-24 20:12:06 +00:00
|
|
|
/*! \file
|
2005-09-14 20:46:50 +00:00
|
|
|
*
|
2005-11-06 15:09:47 +00:00
|
|
|
* \brief Get ADSI CPE ID
|
2005-12-30 21:18:06 +00:00
|
|
|
*
|
|
|
|
* \author Mark Spencer <markster@digium.com>
|
2005-09-14 20:46:50 +00:00
|
|
|
*
|
2005-11-06 15:09:47 +00:00
|
|
|
* \ingroup applications
|
2002-05-13 22:29:39 +00:00
|
|
|
*/
|
|
|
|
|
2006-06-07 18:54:56 +00:00
|
|
|
#include "asterisk.h"
|
|
|
|
|
|
|
|
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
|
|
|
|
2005-06-06 22:39:32 +00:00
|
|
|
#include <stdlib.h>
|
2005-11-08 04:48:00 +00:00
|
|
|
#include <stdio.h>
|
2005-06-06 22:39:32 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2005-04-21 06:02:45 +00:00
|
|
|
#include "asterisk/lock.h"
|
|
|
|
#include "asterisk/file.h"
|
|
|
|
#include "asterisk/logger.h"
|
|
|
|
#include "asterisk/channel.h"
|
|
|
|
#include "asterisk/pbx.h"
|
|
|
|
#include "asterisk/module.h"
|
|
|
|
#include "asterisk/adsi.h"
|
|
|
|
#include "asterisk/options.h"
|
2002-05-13 22:29:39 +00:00
|
|
|
|
|
|
|
static char *app = "GetCPEID";
|
|
|
|
|
|
|
|
static char *synopsis = "Get ADSI CPE ID";
|
|
|
|
|
|
|
|
static char *descrip =
|
2005-01-08 19:30:40 +00:00
|
|
|
" GetCPEID: Obtains and displays ADSI CPE ID and other information in order\n"
|
2005-11-07 22:01:22 +00:00
|
|
|
"to properly setup zapata.conf for on-hook operations.\n";
|
2002-05-13 22:29:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
static int cpeid_setstatus(struct ast_channel *chan, char *stuff[], int voice)
|
|
|
|
{
|
|
|
|
int justify[5] = { ADSI_JUST_CENT, ADSI_JUST_LEFT, ADSI_JUST_LEFT, ADSI_JUST_LEFT };
|
2005-09-07 18:55:03 +00:00
|
|
|
char *tmp[5];
|
2002-05-13 22:29:39 +00:00
|
|
|
int x;
|
|
|
|
for (x=0;x<4;x++)
|
|
|
|
tmp[x] = stuff[x];
|
|
|
|
tmp[4] = NULL;
|
2006-09-20 04:34:51 +00:00
|
|
|
return ast_adsi_print(chan, tmp, justify, voice);
|
2002-05-13 22:29:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int cpeid_exec(struct ast_channel *chan, void *idata)
|
|
|
|
{
|
|
|
|
int res=0;
|
2006-08-21 02:11:39 +00:00
|
|
|
struct ast_module_user *u;
|
2002-05-13 22:29:39 +00:00
|
|
|
unsigned char cpeid[4];
|
|
|
|
int gotgeometry = 0;
|
|
|
|
int gotcpeid = 0;
|
|
|
|
int width, height, buttons;
|
2006-10-25 14:44:50 +00:00
|
|
|
char *data[4];
|
|
|
|
unsigned int x;
|
2002-05-13 22:29:39 +00:00
|
|
|
|
2006-08-21 02:11:39 +00:00
|
|
|
u = ast_module_user_add(chan);
|
2006-10-25 14:44:50 +00:00
|
|
|
|
|
|
|
for (x = 0; x < 4; x++)
|
|
|
|
data[x] = alloca(80);
|
|
|
|
|
|
|
|
strcpy(data[0], "** CPE Info **");
|
|
|
|
strcpy(data[1], "Identifying CPE...");
|
|
|
|
strcpy(data[2], "Please wait...");
|
2006-09-20 04:34:51 +00:00
|
|
|
res = ast_adsi_load_session(chan, NULL, 0, 1);
|
2002-05-13 22:29:39 +00:00
|
|
|
if (res > 0) {
|
2006-10-25 14:44:50 +00:00
|
|
|
cpeid_setstatus(chan, data, 0);
|
2006-09-20 04:34:51 +00:00
|
|
|
res = ast_adsi_get_cpeid(chan, cpeid, 0);
|
2002-05-13 22:29:39 +00:00
|
|
|
if (res > 0) {
|
|
|
|
gotcpeid = 1;
|
|
|
|
if (option_verbose > 2)
|
|
|
|
ast_verbose(VERBOSE_PREFIX_3 "Got CPEID of '%02x:%02x:%02x:%02x' on '%s'\n", cpeid[0], cpeid[1], cpeid[2], cpeid[3], chan->name);
|
|
|
|
}
|
|
|
|
if (res > -1) {
|
2006-10-25 14:44:50 +00:00
|
|
|
strcpy(data[1], "Measuring CPE...");
|
|
|
|
strcpy(data[2], "Please wait...");
|
|
|
|
cpeid_setstatus(chan, data, 0);
|
2006-09-20 04:34:51 +00:00
|
|
|
res = ast_adsi_get_cpeinfo(chan, &width, &height, &buttons, 0);
|
2002-05-13 22:29:39 +00:00
|
|
|
if (res > -1) {
|
|
|
|
if (option_verbose > 2)
|
|
|
|
ast_verbose(VERBOSE_PREFIX_3 "CPE has %d lines, %d columns, and %d buttons on '%s'\n", height, width, buttons, chan->name);
|
|
|
|
gotgeometry = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (res > -1) {
|
|
|
|
if (gotcpeid)
|
2006-10-25 14:44:50 +00:00
|
|
|
snprintf(data[1], 80, "CPEID: %02x:%02x:%02x:%02x", cpeid[0], cpeid[1], cpeid[2], cpeid[3]);
|
2002-05-13 22:29:39 +00:00
|
|
|
else
|
2006-10-25 14:44:50 +00:00
|
|
|
strcpy(data[1], "CPEID Unknown");
|
2002-05-13 22:29:39 +00:00
|
|
|
if (gotgeometry)
|
2006-10-25 14:44:50 +00:00
|
|
|
snprintf(data[2], 80, "Geom: %dx%d, %d buttons", width, height, buttons);
|
2002-05-13 22:29:39 +00:00
|
|
|
else
|
2006-10-25 14:44:50 +00:00
|
|
|
strcpy(data[2], "Geometry unknown");
|
|
|
|
strcpy(data[3], "Press # to exit");
|
|
|
|
cpeid_setstatus(chan, data, 1);
|
2002-05-13 22:29:39 +00:00
|
|
|
for(;;) {
|
|
|
|
res = ast_waitfordigit(chan, 1000);
|
|
|
|
if (res < 0)
|
|
|
|
break;
|
|
|
|
if (res == '#') {
|
|
|
|
res = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-09-20 04:34:51 +00:00
|
|
|
ast_adsi_unload_session(chan);
|
2002-05-13 22:29:39 +00:00
|
|
|
}
|
|
|
|
}
|
2006-08-21 02:11:39 +00:00
|
|
|
ast_module_user_remove(u);
|
2002-05-13 22:29:39 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2006-08-21 02:11:39 +00:00
|
|
|
static int unload_module(void)
|
2002-05-13 22:29:39 +00:00
|
|
|
{
|
2005-10-18 22:52:21 +00:00
|
|
|
int res;
|
|
|
|
|
|
|
|
res = ast_unregister_application(app);
|
|
|
|
|
2006-08-21 02:11:39 +00:00
|
|
|
ast_module_user_hangup_all();
|
2005-10-18 22:52:21 +00:00
|
|
|
|
|
|
|
return res;
|
2002-05-13 22:29:39 +00:00
|
|
|
}
|
|
|
|
|
2006-08-21 02:11:39 +00:00
|
|
|
static int load_module(void)
|
2002-05-13 22:29:39 +00:00
|
|
|
{
|
|
|
|
return ast_register_application(app, cpeid_exec, synopsis, descrip);
|
|
|
|
}
|
|
|
|
|
2006-08-21 02:11:39 +00:00
|
|
|
AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Get ADSI CPE ID");
|