80
83
static void dump_byte(char *output, int maxlen, void *value, int len)
82
if (len == sizeof(unsigned char))
83
snprintf(output, maxlen, "%d", ntohs(*((unsigned char *)value)));
85
if (len == (int)sizeof(unsigned char))
86
snprintf(output, maxlen, "%d", *((unsigned char *)value));
85
88
snprintf(output, maxlen, "Invalid BYTE");
91
static void dump_ipaddr(char *output, int maxlen, void *value, int len)
93
struct sockaddr_in sin;
94
char iabuf[INET_ADDRSTRLEN];
95
if (len == (int)sizeof(unsigned int)) {
96
memcpy(&sin.sin_addr, value, len);
97
ast_inet_ntoa(iabuf, sizeof(iabuf), sin.sin_addr);
98
snprintf(output, maxlen, "%s", iabuf);
100
snprintf(output, maxlen, "Invalid IPADDR");
104
static void dump_prov_flags(char *output, int maxlen, void *value, int len)
107
if (len == (int)sizeof(unsigned int))
108
snprintf(output, maxlen, "%lu (%s)", (unsigned long)ntohl(*((unsigned int *)value)),
109
iax_provflags2str(buf, sizeof(buf), ntohl(*((unsigned int *)value))));
111
snprintf(output, maxlen, "Invalid INT");
114
static void dump_prov_ies(char *output, int maxlen, unsigned char *iedata, int len);
115
static void dump_prov(char *output, int maxlen, void *value, int len)
117
dump_prov_ies(output, maxlen, value, len);
88
120
static struct iax2_ie {
117
149
{ IAX_IE_AUTOANSWER, "AUTO ANSWER REQ" },
118
150
{ IAX_IE_TRANSFERID, "TRANSFER ID", dump_int },
119
151
{ IAX_IE_RDNIS, "REFERRING DNIS", dump_string },
120
{ IAX_IE_PROVISIONING, "PROVISIONING" },
121
{ IAX_IE_AESPROVISIONING, "AES PROVISIONING" },
152
{ IAX_IE_PROVISIONING, "PROVISIONING", dump_prov },
153
{ IAX_IE_AESPROVISIONING, "AES PROVISIONG" },
122
154
{ IAX_IE_DATETIME, "DATE TIME", dump_int },
155
{ IAX_IE_DEVICETYPE, "DEVICE TYPE", dump_string },
156
{ IAX_IE_SERVICEIDENT, "SERVICE IDENT", dump_string },
157
{ IAX_IE_FIRMWAREVER, "FIRMWARE VER", dump_short },
158
{ IAX_IE_FWBLOCKDESC, "FW BLOCK DESC", dump_int },
159
{ IAX_IE_FWBLOCKDATA, "FW BLOCK DATA" },
160
{ IAX_IE_PROVVER, "PROVISIONG VER", dump_int },
163
static struct iax2_ie prov_ies[] = {
164
{ PROV_IE_USEDHCP, "USEDHCP" },
165
{ PROV_IE_IPADDR, "IPADDR", dump_ipaddr },
166
{ PROV_IE_SUBNET, "SUBNET", dump_ipaddr },
167
{ PROV_IE_GATEWAY, "GATEWAY", dump_ipaddr },
168
{ PROV_IE_PORTNO, "BINDPORT", dump_short },
169
{ PROV_IE_USER, "USERNAME", dump_string },
170
{ PROV_IE_PASS, "PASSWORD", dump_string },
171
{ PROV_IE_LANG, "LANGUAGE", dump_string },
172
{ PROV_IE_TOS, "TYPEOFSERVICE", dump_byte },
173
{ PROV_IE_FLAGS, "FLAGS", dump_prov_flags },
174
{ PROV_IE_FORMAT, "FORMAT", dump_int },
175
{ PROV_IE_AESKEY, "AESKEY" },
176
{ PROV_IE_SERVERIP, "SERVERIP", dump_ipaddr },
177
{ PROV_IE_SERVERPORT, "SERVERPORT", dump_short },
178
{ PROV_IE_NEWAESKEY, "NEWAESKEY" },
179
{ PROV_IE_PROVVER, "PROV VERSION", dump_int },
180
{ PROV_IE_ALTSERVER, "ALTSERVERIP", dump_ipaddr },
125
183
const char *iax_ie2str(int ie)
128
for (x=0;x<sizeof(ies) / sizeof(ies[0]); x++) {
186
for (x=0;x<(int)sizeof(ies) / (int)sizeof(ies[0]); x++) {
129
187
if (ies[x].ie == ie)
130
188
return ies[x].name;
132
190
return "Unknown IE";
194
static void dump_prov_ies(char *output, int maxlen, unsigned char *iedata, int len)
204
strcpy(output, "\n");
205
maxlen -= strlen(output); output += strlen(output);
209
if (ielen + 2> len) {
210
snprintf(tmp, (int)sizeof(tmp), "Total Prov IE length of %d bytes exceeds remaining prov frame length of %d bytes\n", ielen + 2, len);
211
strncpy(output, tmp, maxlen - 1);
212
maxlen -= strlen(output); output += strlen(output);
216
for (x=0;x<(int)sizeof(prov_ies) / (int)sizeof(prov_ies[0]); x++) {
217
if (prov_ies[x].ie == ie) {
218
if (prov_ies[x].dump) {
219
prov_ies[x].dump(interp, (int)sizeof(interp), iedata + 2, ielen);
220
snprintf(tmp, (int)sizeof(tmp), " %-15.15s : %s\n", prov_ies[x].name, interp);
221
strncpy(output, tmp, maxlen - 1);
222
maxlen -= strlen(output); output += strlen(output);
225
snprintf(interp, (int)sizeof(interp), "%d bytes", ielen);
227
strcpy(interp, "Present");
228
snprintf(tmp, (int)sizeof(tmp), " %-15.15s : %s\n", prov_ies[x].name, interp);
229
strncpy(output, tmp, maxlen - 1);
230
maxlen -= strlen(output); output += strlen(output);
236
snprintf(tmp, (int)sizeof(tmp), " Unknown Prov IE %03d : Present\n", ie);
237
strncpy(output, tmp, maxlen - 1);
238
maxlen -= strlen(output); output += strlen(output);
240
iedata += (2 + ielen);
135
245
static void dump_ies(unsigned char *iedata, int len)
147
257
ielen = iedata[1];
148
258
if (ielen + 2> len) {
149
snprintf(tmp, sizeof(tmp), "Total IE length of %d bytes exceeds remaining frame length of %d bytes\n", ielen + 2, len);
259
snprintf(tmp, (int)sizeof(tmp), "Total IE length of %d bytes exceeds remaining frame length of %d bytes\n", ielen + 2, len);
154
for (x=0;x<sizeof(ies) / sizeof(ies[0]); x++) {
264
for (x=0;x<(int)sizeof(ies) / (int)sizeof(ies[0]); x++) {
155
265
if (ies[x].ie == ie) {
156
266
if (ies[x].dump) {
157
ies[x].dump(interp, sizeof(interp), iedata + 2, ielen);
158
snprintf(tmp, sizeof(tmp), " %-15.15s : %s\n", ies[x].name, interp);
267
ies[x].dump(interp, (int)sizeof(interp), iedata + 2, ielen);
268
snprintf(tmp, (int)sizeof(tmp), " %-15.15s : %s\n", ies[x].name, interp);
161
snprintf(tmp, sizeof(tmp), " %-15.15s : Present\n", ies[x].name);
272
snprintf(interp, (int)sizeof(interp), "%d bytes", ielen);
274
strcpy(interp, "Present");
275
snprintf(tmp, (int)sizeof(tmp), " %-15.15s : %s\n", ies[x].name, interp);
168
snprintf(tmp, sizeof(tmp), " Unknown IE %03d : Present\n", ie);
282
snprintf(tmp, (int)sizeof(tmp), " Unknown IE %03d : Present\n", ie);
171
285
iedata += (2 + ielen);
264
381
sprintf(subclass2, "%c", fh->csub);
265
382
subclass = subclass2;
266
383
} else if (fh->type == AST_FRAME_IAX) {
267
if (fh->csub >= sizeof(iaxs)/sizeof(iaxs[0])) {
268
snprintf(subclass2, sizeof(subclass2), "(%d?)", fh->csub);
384
if (fh->csub >= (int)sizeof(iaxs)/(int)sizeof(iaxs[0])) {
385
snprintf(subclass2, (int)sizeof(subclass2), "(%d?)", fh->csub);
269
386
subclass = subclass2;
271
388
subclass = iaxs[(int)fh->csub];
273
390
} else if (fh->type == AST_FRAME_CONTROL) {
274
if (fh->csub > sizeof(cmds)/sizeof(char *)) {
275
snprintf(subclass2, sizeof(subclass2), "(%d?)", fh->csub);
391
if (fh->csub > (int)sizeof(cmds)/(int)sizeof(char *)) {
392
snprintf(subclass2, (int)sizeof(subclass2), "(%d?)", fh->csub);
276
393
subclass = subclass2;
278
395
subclass = cmds[(int)fh->csub];
281
snprintf(subclass2, sizeof(subclass2), "%d", fh->csub);
398
snprintf(subclass2, (int)sizeof(subclass2), "%d", fh->csub);
282
399
subclass = subclass2;
284
snprintf(tmp, sizeof(tmp),
401
snprintf(tmp, (int)sizeof(tmp),
285
402
"%s-Frame Retry[%s] -- OSeqno: %3.3d ISeqno: %3.3d Type: %s Subclass: %s\n",
286
403
(rx ? "Rx" : "Tx"),
287
404
retries, fh->oseqno, fh->iseqno, class, subclass);
289
snprintf(tmp, sizeof(tmp),
406
snprintf(tmp, (int)sizeof(tmp),
290
407
" Timestamp: %05lums SCall: %5.5d DCall: %5.5d [%s:%d]\n",
291
408
(unsigned long)ntohl(fh->ts),
292
409
ntohs(fh->scallno) & ~IAX_FLAG_FULL, ntohs(fh->dcallno) & ~IAX_FLAG_RETRANS,
293
inet_ntoa(sin->sin_addr), ntohs(sin->sin_port));
410
ast_inet_ntoa(iabuf, sizeof(iabuf), sin->sin_addr), ntohs(sin->sin_port));
295
412
if (fh->type == AST_FRAME_IAX)
296
413
dump_ies(fh->iedata, datalen);
449
567
ies->apparent_addr = ((struct sockaddr_in *)(data + 2));
451
569
case IAX_IE_REFRESH:
452
if (len != sizeof(unsigned short)) {
453
snprintf(tmp, sizeof(tmp), "Expecting refresh to be %d bytes long but was %d\n", sizeof(unsigned short), len);
570
if (len != (int)sizeof(unsigned short)) {
571
snprintf(tmp, (int)sizeof(tmp), "Expecting refresh to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
456
574
ies->refresh = ntohs(*((unsigned short *)(data + 2)));
458
576
case IAX_IE_DPSTATUS:
459
if (len != sizeof(unsigned short)) {
460
snprintf(tmp, sizeof(tmp), "Expecting dpstatus to be %d bytes long but was %d\n", sizeof(unsigned short), len);
577
if (len != (int)sizeof(unsigned short)) {
578
snprintf(tmp, (int)sizeof(tmp), "Expecting dpstatus to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
463
581
ies->dpstatus = ntohs(*((unsigned short *)(data + 2)));
465
583
case IAX_IE_CALLNO:
466
if (len != sizeof(unsigned short)) {
467
snprintf(tmp, sizeof(tmp), "Expecting callno to be %d bytes long but was %d\n", sizeof(unsigned short), len);
584
if (len != (int)sizeof(unsigned short)) {
585
snprintf(tmp, (int)sizeof(tmp), "Expecting callno to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
470
588
ies->callno = ntohs(*((unsigned short *)(data + 2)));
494
612
ies->musiconhold = 1;
496
614
case IAX_IE_TRANSFERID:
497
if (len != sizeof(unsigned int)) {
498
snprintf(tmp, sizeof(tmp), "Expecting transferid to be %d bytes long but was %d\n", sizeof(unsigned int), len);
615
if (len != (int)sizeof(unsigned int)) {
616
snprintf(tmp, (int)sizeof(tmp), "Expecting transferid to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
501
619
ies->transferid = ntohl(*((unsigned int *)(data + 2)));
503
621
case IAX_IE_DATETIME:
504
if (len != sizeof(unsigned int)) {
505
snprintf(tmp, sizeof(tmp), "Expecting date/time to be %d bytes long but was %d\n", sizeof(unsigned int), len);
622
if (len != (int)sizeof(unsigned int)) {
623
snprintf(tmp, (int)sizeof(tmp), "Expecting date/time to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
508
626
ies->datetime = ntohl(*((unsigned int *)(data + 2)));
628
case IAX_IE_FIRMWAREVER:
629
if (len != (int)sizeof(unsigned short)) {
630
snprintf(tmp, (int)sizeof(tmp), "Expecting firmwarever to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
633
ies->firmwarever = ntohs(*((unsigned short *)(data + 2)));
635
case IAX_IE_DEVICETYPE:
636
ies->devicetype = data + 2;
638
case IAX_IE_SERVICEIDENT:
639
ies->serviceident = data + 2;
641
case IAX_IE_FWBLOCKDESC:
642
if (len != (int)sizeof(unsigned int)) {
643
snprintf(tmp, (int)sizeof(tmp), "Expected block desc to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
646
ies->fwdesc = ntohl(*((unsigned int *)(data + 2)));
648
case IAX_IE_FWBLOCKDATA:
649
ies->fwdata = data + 2;
650
ies->fwdatalen = len;
653
if (len != (int)sizeof(unsigned int)) {
654
snprintf(tmp, (int)sizeof(tmp), "Expected provisioning version to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
657
ies->provverpres = 1;
658
ies->provver = ntohl(*((unsigned int *)(data + 2)));
511
snprintf(tmp, sizeof(tmp), "Ignoring unknown information element '%s' (%d) of length %d\n", iax_ie2str(ie), ie, len);
662
snprintf(tmp, (int)sizeof(tmp), "Ignoring unknown information element '%s' (%d) of length %d\n", iax_ie2str(ie), ie, len);
514
665
/* Overwrite information element with 0, to null terminate previous portion */