| 
									
										
										
										
											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
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-14 20:13:06 +00:00
										 |  |  | /*** MODULEINFO
 | 
					
						
							|  |  |  | 	<support_level>extended</support_level> | 
					
						
							|  |  |  |  ***/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-07 18:54:56 +00:00
										 |  |  | #include "asterisk.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ASTERISK_FILE_VERSION(__FILE__, "$Revision$") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-21 06:02:45 +00:00
										 |  |  | #include "asterisk/lock.h"
 | 
					
						
							|  |  |  | #include "asterisk/file.h"
 | 
					
						
							|  |  |  | #include "asterisk/channel.h"
 | 
					
						
							|  |  |  | #include "asterisk/pbx.h"
 | 
					
						
							|  |  |  | #include "asterisk/module.h"
 | 
					
						
							|  |  |  | #include "asterisk/adsi.h"
 | 
					
						
							| 
									
										
										
										
											2002-05-13 22:29:39 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-01 21:10:07 +00:00
										 |  |  | /*** DOCUMENTATION
 | 
					
						
							|  |  |  | 	<application name="GetCPEID" language="en_US"> | 
					
						
							|  |  |  | 		<synopsis> | 
					
						
							|  |  |  | 			Get ADSI CPE ID. | 
					
						
							|  |  |  | 		</synopsis> | 
					
						
							|  |  |  | 		<syntax /> | 
					
						
							|  |  |  | 		<description> | 
					
						
							|  |  |  | 			<para>Obtains and displays ADSI CPE ID and other information in order | 
					
						
							|  |  |  | 			to properly setup <filename>dahdi.conf</filename> for on-hook operations.</para> | 
					
						
							|  |  |  | 		</description> | 
					
						
							|  |  |  | 	</application> | 
					
						
							|  |  |  |  ***/ | 
					
						
							| 
									
										
										
										
											2002-05-13 22:29:39 +00:00
										 |  |  | static char *app = "GetCPEID"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 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
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-21 21:13:09 +00:00
										 |  |  | static int cpeid_exec(struct ast_channel *chan, const char *idata) | 
					
						
							| 
									
										
										
										
											2002-05-13 22:29:39 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	int res=0; | 
					
						
							|  |  |  | 	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-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; | 
					
						
							| 
									
										
										
										
											2007-07-26 15:49:18 +00:00
										 |  |  | 			ast_verb(3, "Got CPEID of '%02x:%02x:%02x:%02x' on '%s'\n", cpeid[0], cpeid[1], cpeid[2], cpeid[3], chan->name); | 
					
						
							| 
									
										
										
										
											2002-05-13 22:29:39 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		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) { | 
					
						
							| 
									
										
										
										
											2007-07-26 15:49:18 +00:00
										 |  |  | 				ast_verb(3, "CPE has %d lines, %d columns, and %d buttons on '%s'\n", height, width, buttons, chan->name); | 
					
						
							| 
									
										
										
										
											2002-05-13 22:29:39 +00:00
										 |  |  | 				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
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-07-16 14:39:29 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2007-07-16 13:35:20 +00:00
										 |  |  | 	return ast_unregister_application(app); | 
					
						
							| 
									
										
										
										
											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
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2008-11-01 21:10:07 +00:00
										 |  |  | 	return ast_register_application_xml(app, cpeid_exec); | 
					
						
							| 
									
										
										
										
											2002-05-13 22:29:39 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-02 05:20:59 +00:00
										 |  |  | AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Get ADSI CPE ID", | 
					
						
							|  |  |  | 		.load = load_module, | 
					
						
							|  |  |  | 		.unload = unload_module, | 
					
						
							|  |  |  | 		.nonoptreq = "res_adsi", | 
					
						
							|  |  |  | 		); |