00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "asterisk.h"
00029
00030 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 122314 $")
00031
00032 #include <stdlib.h>
00033 #include <stdio.h>
00034 #include <unistd.h>
00035 #include <string.h>
00036
00037 #include "asterisk/lock.h"
00038 #include "asterisk/file.h"
00039 #include "asterisk/logger.h"
00040 #include "asterisk/channel.h"
00041 #include "asterisk/pbx.h"
00042 #include "asterisk/module.h"
00043 #include "asterisk/adsi.h"
00044 #include "asterisk/options.h"
00045
00046 static char *app = "GetCPEID";
00047
00048 static char *synopsis = "Get ADSI CPE ID";
00049
00050 static char *descrip =
00051 " GetCPEID: Obtains and displays ADSI CPE ID and other information in order\n"
00052 "to properly setup chan_dahdi.conf for on-hook operations.\n";
00053
00054
00055 static int cpeid_setstatus(struct ast_channel *chan, char *stuff[], int voice)
00056 {
00057 int justify[5] = { ADSI_JUST_CENT, ADSI_JUST_LEFT, ADSI_JUST_LEFT, ADSI_JUST_LEFT };
00058 char *tmp[5];
00059 int x;
00060 for (x=0;x<4;x++)
00061 tmp[x] = stuff[x];
00062 tmp[4] = NULL;
00063 return ast_adsi_print(chan, tmp, justify, voice);
00064 }
00065
00066 static int cpeid_exec(struct ast_channel *chan, void *idata)
00067 {
00068 int res=0;
00069 struct ast_module_user *u;
00070 unsigned char cpeid[4];
00071 int gotgeometry = 0;
00072 int gotcpeid = 0;
00073 int width, height, buttons;
00074 char *data[4];
00075 unsigned int x;
00076
00077 u = ast_module_user_add(chan);
00078
00079 for (x = 0; x < 4; x++)
00080 data[x] = alloca(80);
00081
00082 strcpy(data[0], "** CPE Info **");
00083 strcpy(data[1], "Identifying CPE...");
00084 strcpy(data[2], "Please wait...");
00085 res = ast_adsi_load_session(chan, NULL, 0, 1);
00086 if (res > 0) {
00087 cpeid_setstatus(chan, data, 0);
00088 res = ast_adsi_get_cpeid(chan, cpeid, 0);
00089 if (res > 0) {
00090 gotcpeid = 1;
00091 if (option_verbose > 2)
00092 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);
00093 }
00094 if (res > -1) {
00095 strcpy(data[1], "Measuring CPE...");
00096 strcpy(data[2], "Please wait...");
00097 cpeid_setstatus(chan, data, 0);
00098 res = ast_adsi_get_cpeinfo(chan, &width, &height, &buttons, 0);
00099 if (res > -1) {
00100 if (option_verbose > 2)
00101 ast_verbose(VERBOSE_PREFIX_3 "CPE has %d lines, %d columns, and %d buttons on '%s'\n", height, width, buttons, chan->name);
00102 gotgeometry = 1;
00103 }
00104 }
00105 if (res > -1) {
00106 if (gotcpeid)
00107 snprintf(data[1], 80, "CPEID: %02x:%02x:%02x:%02x", cpeid[0], cpeid[1], cpeid[2], cpeid[3]);
00108 else
00109 strcpy(data[1], "CPEID Unknown");
00110 if (gotgeometry)
00111 snprintf(data[2], 80, "Geom: %dx%d, %d buttons", width, height, buttons);
00112 else
00113 strcpy(data[2], "Geometry unknown");
00114 strcpy(data[3], "Press # to exit");
00115 cpeid_setstatus(chan, data, 1);
00116 for(;;) {
00117 res = ast_waitfordigit(chan, 1000);
00118 if (res < 0)
00119 break;
00120 if (res == '#') {
00121 res = 0;
00122 break;
00123 }
00124 }
00125 ast_adsi_unload_session(chan);
00126 }
00127 }
00128 ast_module_user_remove(u);
00129 return res;
00130 }
00131
00132 static int unload_module(void)
00133 {
00134 int res;
00135
00136 res = ast_unregister_application(app);
00137
00138 ast_module_user_hangup_all();
00139
00140 return res;
00141 }
00142
00143 static int load_module(void)
00144 {
00145 return ast_register_application(app, cpeid_exec, synopsis, descrip);
00146 }
00147
00148 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Get ADSI CPE ID");