| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 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 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
static char *app = "GetCPEID"; |
| 58 |
|
| 59 |
static int cpeid_setstatus(struct ast_channel *chan, char *stuff[], int voice) |
| 60 |
{ |
| 61 |
int justify[5] = { ADSI_JUST_CENT, ADSI_JUST_LEFT, ADSI_JUST_LEFT, ADSI_JUST_LEFT }; |
| 62 |
char *tmp[5]; |
| 63 |
int x; |
| 64 |
for (x=0;x<4;x++) |
| 65 |
tmp[x] = stuff[x]; |
| 66 |
tmp[4] = NULL; |
| 67 |
return ast_adsi_print(chan, tmp, justify, voice); |
| 68 |
} |
| 69 |
|
| 70 |
static int cpeid_exec(struct ast_channel *chan, const char *idata) |
| 71 |
{ |
| 72 |
int res=0; |
| 73 |
unsigned char cpeid[4]; |
| 74 |
int gotgeometry = 0; |
| 75 |
int gotcpeid = 0; |
| 76 |
int width, height, buttons; |
| 77 |
char *data[4]; |
| 78 |
unsigned int x; |
| 79 |
|
| 80 |
for (x = 0; x < 4; x++) |
| 81 |
data[x] = ast_alloca(80); |
| 82 |
|
| 83 |
strcpy(data[0], "** CPE Info **"); |
| 84 |
strcpy(data[1], "Identifying CPE..."); |
| 85 |
strcpy(data[2], "Please wait..."); |
| 86 |
res = ast_adsi_load_session(chan, NULL, 0, 1); |
| 87 |
if (res > 0) { |
| 88 |
cpeid_setstatus(chan, data, 0); |
| 89 |
res = ast_adsi_get_cpeid(chan, cpeid, 0); |
| 90 |
if (res > 0) { |
| 91 |
gotcpeid = 1; |
| 92 |
ast_verb(3, "Got CPEID of '%02hhx:%02hhx:%02hhx:%02hhx' on '%s'\n", |
| 93 |
cpeid[0], cpeid[1], cpeid[2], cpeid[3], ast_channel_name(chan)); |
| 94 |
} |
| 95 |
if (res > -1) { |
| 96 |
strcpy(data[1], "Measuring CPE..."); |
| 97 |
strcpy(data[2], "Please wait..."); |
| 98 |
cpeid_setstatus(chan, data, 0); |
| 99 |
res = ast_adsi_get_cpeinfo(chan, &width, &height, &buttons, 0); |
| 100 |
if (res > -1) { |
| 101 |
ast_verb(3, "CPE has %d lines, %d columns, and %d buttons on '%s'\n", height, width, buttons, ast_channel_name(chan)); |
| 102 |
gotgeometry = 1; |
| 103 |
} |
| 104 |
} |
| 105 |
if (res > -1) { |
| 106 |
if (gotcpeid) |
| 107 |
snprintf(data[1], 80, "CPEID: %02hhx:%02hhx:%02hhx:%02hhx", |
| 108 |
cpeid[0], cpeid[1], cpeid[2], 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 |
} |
| 126 |
ast_adsi_unload_session(chan); |
| 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 |
{ |
| 140 |
return ast_register_application_xml(app, cpeid_exec); |
| 141 |
} |
| 142 |
|
| 143 |
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Get ADSI CPE ID", |
| 144 |
.support_level = AST_MODULE_SUPPORT_DEPRECATED, |
| 145 |
.load = load_module, |
| 146 |
.unload = unload_module, |
| 147 |
.requires = "res_adsi", |
| 148 |
); |