/* packet-diameter.c
* Routines for Diameter packet disassembly
*
- * $Id: packet-diameter.c,v 1.49 2002/08/02 23:35:48 jmayer Exp $
+ * $Id: packet-diameter.c,v 1.50 2002/08/28 21:00:12 jmayer Exp $
*
* Copyright (c) 2001 by David Frascone <dave@frascone.com>
*
DIAMETER_MIP_REG_REQ, /* OctetString */
DIAMETER_VENDOR_ID, /* Integer32 */
DIAMETER_APPLICATION_ID
-
+
} diameterDataType;
int res, size = 1024;
char chars[1024];
xmlParserCtxtPtr ctxt;
-
+
/* I wonder what kind of a performance hit this is? */
*XmlStub.xmlDoValidityCheckingDefaultValue = checkValid;
-
+
f = fopen(filename, "r");
if (f == NULL) {
g_warning("Diameter: Unable to open %s", filename);
valid=ctxt->valid;
XmlStub.xmlFreeParserCtxt(ctxt);
}
- fclose(f);
+ fclose(f);
/* Check valid */
if (!valid) {
if (values) {
for (i=0; values[i].strptr != NULL; i++) {
ValueName *ve = NULL;
-
+
ve = g_malloc(sizeof(ValueName));
ve->name = strdup(values[i].strptr);
ve->value = values[i].value;
avpListHead = entry;
return (0);
-
+
} /* addStaticAVP */
/*
ValueName *ve = NULL;
valueName = XmlStub.xmlGetProp(cur, "name");
valueCode = XmlStub.xmlGetProp(cur, "code");
-
+
if (!valueName || !valueCode) {
g_warning( "Error, bad value on avp %s", name);
return (-1);
}
-
+
ve = g_malloc(sizeof(ValueName));
ve->name = strdup(valueName);
ve->value = atol(valueCode);
}
/* WORK - Handle flags -- for validation later */
-
+
/* And, create the entry */
entry = (avpInfo *)g_malloc(sizeof(avpInfo));
entry->name = g_strdup(name);
entry->code = atol(code);
- if (vendorName)
+ if (vendorName)
entry->vendorName = g_strdup(vendorName);
else
entry->vendorName = NULL;
g_warning( "Unable to allocate memory");
return (-1);
}
-
+
entry->name = g_strdup(name);
entry->id = id;
-
+
/* Add it to the list */
entry->next = ApplicationIdHead;
ApplicationIdHead = entry;
if (!base) {
char *name;
char *id;
-
+
/* Add our application */
id = XmlStub.xmlGetProp(cur, "id");
name = XmlStub.xmlGetProp(cur, "name");
-
+
if (!name || !id) {
/* ERROR!!! */
g_warning("Diameter: Invalid application!: name=\"%s\", id=\"%s\"",
name?name:"NULL", id?id:"NULL");
return -1;
}
-
+
/* Add the application */
if (dictionaryAddApplication(name, atol(id)) != 0) {
/* ERROR! */
}
}
-
+
/*
* Get segment values
*/
} /* xmlDictionaryParseSegment */
/*
- * The main xml parse routine. This will walk through an XML
+ * The main xml parse routine. This will walk through an XML
* dictionary that has been parsed by libxml.
*/
static int
gbl_diameterDictionary);
return -1;
}
-
+
/*
* Check the document is of the right kind
*/
XmlStub.xmlFreeDoc(doc);
return -1;
}
-
+
/*
* Ok, the dictionary has been parsed by libxml, and is valid.
* All we have to do now is read in our information.
} /* initializeDictionaryDefaults */
-/*
- * This routine will attempt to load the XML dictionary, and on
+/*
+ * This routine will attempt to load the XML dictionary, and on
* failure, will call initializeDictionaryDefaults to load in
* our static dictionary.
*/
initializeDictionary()
{
/*
- * Using ugly ordering here. If loadLibXML succeeds, then
+ * Using ugly ordering here. If loadLibXML succeeds, then
* loadXMLDictionary will be called. This is one of the few times when
* I think this is prettier than the nested if alternative.
*/
}
}
}
-
- g_warning("Diameter: Unable to find name for command code 0x%08x, Vendor \"%u\"!",
+
+ g_warning("Diameter: Unable to find name for command code 0x%08x, Vendor \"%u\"!",
commandCode, vendorId);
snprintf(buffer, sizeof(buffer),
"Cmd-0x%08x", commandCode);
diameter_avp_get_type(guint32 avpCode, guint32 vendorId){
avpInfo *probe;
gchar *vendorName=NULL;
-
+
if (vendorId)
vendorName = diameter_vendor_to_str(vendorId, FALSE);
-
+
for (probe=avpListHead; probe; probe=probe->next) {
if (avpCode == probe->code) {
-
+
if (vendorId) {
/* g_warning("AvpType: Comparing \"%s\" to \"%s\"", */
/* vendorName?vendorName:"(null)", */
}
}
}
-
+
/* If we don't find it, assume it's data */
g_warning("Diameter: Unable to find type for avpCode %u, Vendor %u!", avpCode,
vendorId);
}
}
- g_warning("Diameter: Unable to find name for AVP 0x%08x, Vendor %u!",
+ g_warning("Diameter: Unable to find name for AVP 0x%08x, Vendor %u!",
avpCode, vendorId);
/* If we don't find it, build a name string */
initializeDictionary();
initialized=TRUE;
}
-
+
/* Make entries in Protocol column and Info column on summary display */
- if (check_col(pinfo->cinfo, COL_PROTOCOL))
+ if (check_col(pinfo->cinfo, COL_PROTOCOL))
col_set_str(pinfo->cinfo, COL_PROTOCOL, "Diameter");
- if (check_col(pinfo->cinfo, COL_INFO))
+ if (check_col(pinfo->cinfo, COL_INFO))
col_clear(pinfo->cinfo, COL_INFO);
-
+
/* Copy our header */
tvb_memcpy(tvb, (guint8*) &dh, offset, sizeof(dh));
-
+
/* Fix byte ordering in our static structure */
dh.versionLength = g_ntohl(dh.versionLength);
dh.flagsCmdCode = g_ntohl(dh.flagsCmdCode);
dh.endToEndId = g_ntohl(dh.endToEndId);
if (dh.vendorId) {
- strcpy(vendorName,
+ strcpy(vendorName,
diameter_vendor_to_str(dh.vendorId, TRUE));
} else {
strcpy(vendorName, "None");
commandCode = DIAM_GET_COMMAND(dh);
/* Set up our flags */
- if (check_col(pinfo->cinfo, COL_INFO) || tree) {
+ if (check_col(pinfo->cinfo, COL_INFO) || tree) {
flagstr[0]=0;
for (i = 0; i < 8; i++) {
bpos = 1 << i;
strcpy(flagstr,"<None>");
}
}
-
+
/* Set up our commandString */
strcpy(commandString, diameter_command_to_str(commandCode, dh.vendorId));
- if (flags & DIAM_FLAGS_R)
+ if (flags & DIAM_FLAGS_R)
strcat(commandString, "-Request");
else
strcat(commandString, "-Answer");
(flags & DIAM_FLAGS_P)?1:0,
(flags & DIAM_FLAGS_E)?1:0);
}
-
+
/* In the interest of speed, if "tree" is NULL, don't do any work not
necessary to generate protocol tree items. */
/* Update the lengths */
avplength= pktLength - sizeof(e_diameterhdr);
-
+
avp_tvb = tvb_new_subset(tvb, offset, avplength, avplength);
avptf = proto_tree_add_text(diameter_tree,
tvb, offset, avplength,
"Attribute Value Pairs");
-
+
avp_tree = proto_item_add_subtree(avptf,
ett_diameter_avp);
if (avp_tree != NULL) {
guint32 plen;
guint32 available_bytes;
/* guint32 noffset; */
-
+
/* Loop through the packet, dissecting multiple diameter messages */
do {
available_bytes = tvb_length_remaining(tvb, offset);
return;
}
}
-
+
/* Otherwise, dissect our packet */
offset = dissect_diameter_common(tvb, offset, pinfo, tree);
mip_tvb = tvb_new_subset(tvb, offset,
MIN(length, tvb_length(tvb)-offset),
length);
-
+
/* The contained packet is a MIP registration request;
dissect it with the MIP dissector. */
col_set_writable(pinfo->cinfo, FALSE);
guint8 flags;
proto_item *tf;
proto_tree *flags_tree;
-
+
gint32 packetLength;
size_t avpDataLength;
int avpType;
/* Don't even bother trying to parse a short packet. */
return;
}
-
+
/* Copy our header */
tvb_memcpy(tvb, (guint8*) &avph, offset, MIN((long)sizeof(avph),packetLength));
-
+
/* Fix the byte ordering */
avph.avp_code = g_ntohl(avph.avp_code);
avph.avp_flagsLength = g_ntohl(avph.avp_flagsLength);
-
+
flags = (avph.avp_flagsLength & 0xff000000) >> 24;
avpLength = avph.avp_flagsLength & 0x00ffffff;
-
+
/* Set up our flags string */
- if (check_col(pinfo->cinfo, COL_INFO) || avp_tree) {
+ if (check_col(pinfo->cinfo, COL_INFO) || avp_tree) {
flagstr[0]=0;
for (i = 0; i < 8; i++) {
bpos = 1 << i;
hdrLength = sizeof(e_avphdr);
} else {
/* No vendor */
- hdrLength = sizeof(e_avphdr) -
+ hdrLength = sizeof(e_avphdr) -
sizeof(guint32);
vendorId = 0;
}
if (vendorId) {
- strcpy(vendorName,
+ strcpy(vendorName,
diameter_vendor_to_str(vendorId, TRUE));
} else {
vendorName[0]='\0';
}
/* Check for bad length */
- if (avpLength < MIN_AVP_SIZE ||
+ if (avpLength < MIN_AVP_SIZE ||
((long)avpLength > packetLength)) {
g_warning("Diameter: AVP payload size invalid: avp_length: %ld bytes, "
"min: %ld bytes, packetLen: %d",
/* For now, don't set bad packet, since I'm accidentally setting a wrong bit */
/* BadPacket = TRUE; */
}
-
+
/*
* Compute amount of byte-alignment fix (Diameter AVPs are sent on 4 byte
* boundries)
*/
fixAmt = 4 - (avpLength % 4);
if (fixAmt == 4) fixAmt = 0;
-
+
/* shrink our packetLength */
packetLength = packetLength - (avpLength + fixAmt);
-
+
/* Check for out of bounds */
if (packetLength < 0) {
g_warning("Diameter: Bad AVP: Bad new length (%d bytes) ",
/* Make avp Name & type */
strcpy(avpTypeString, val_to_str(diameter_avp_get_type(avph.avp_code,vendorId),
- TypeValues,
+ TypeValues,
"Unknown-Type: 0x%08x"));
strcpy(avpNameString, diameter_avp_get_name(avph.avp_code, vendorId));
proto_tree_add_uint_format(avpi_tree, hf_diameter_avp_code,
tvb, offset, 4, avph.avp_code, "AVP Code: %s", avpNameString);
offset += 4;
-
+
tf = proto_tree_add_uint_format(avpi_tree, hf_diameter_avp_flags, tvb,
offset , 1, flags, "Flags: 0x%02x (%s)", flags,
flagstr);
grouptf = proto_tree_add_text(avpi_tree,
tvb, offset, tvb_length(tvb),
buffer);
-
+
group_tree = proto_item_add_subtree(grouptf,
ett_diameter_avp);
data.nsecs = 0;
ltp = localtime(&data.secs);
- strftime(buffer, 64,
+ strftime(buffer, 64,
"%a, %d %b %Y %H:%M:%S %z", ltp);
proto_tree_add_time_format(avpi_tree, hf_diameter_avp_data_time,
case DIAMETER_ENUMERATED:
if (avpDataLength == 4) {
guint32 data;
-
+
data = tvb_get_ntohl(tvb, offset);
valstr = diameter_avp_get_value(avph.avp_code, vendorId, data);
proto_tree_add_uint_format(avpi_tree, hf_diameter_avp_data_uint32,
case DIAMETER_VENDOR_ID:
if (avpDataLength == 4) {
guint32 data;
-
+
data = tvb_get_ntohl(tvb, offset);
valstr = diameter_vendor_to_str(data, TRUE);
proto_tree_add_uint_format(avpi_tree, hf_diameter_avp_data_uint32,
case DIAMETER_APPLICATION_ID:
if (avpDataLength == 4) {
guint32 data;
-
+
data = tvb_get_ntohl(tvb, offset);
valstr = diameter_app_to_str(data);
proto_tree_add_uint_format(avpi_tree, hf_diameter_avp_data_uint32,
tvb_get_ptr(tvb, offset, avpDataLength),
"Hex Data Highlighted Below");
break;
-
+
} /* switch type */
} /* avpi_tree != null */
offset += (avpLength - hdrLength);
{ &hf_diameter_length,
{ "Length","diameter.length", FT_UINT24, BASE_DEC, NULL, 0x0,
"", HFILL }},
-
+
{ &hf_diameter_flags,
{ "Flags", "diameter.flags", FT_UINT8, BASE_HEX, NULL, 0x0,
"", HFILL }},
{ "Hop-by-Hop Identifier", "diameter.hopbyhopid", FT_UINT32,
BASE_HEX, NULL, 0x0, "", HFILL }},
{ &hf_diameter_endtoendid,
- { "End-to-End Identifier", "diameter.endtoendid", FT_UINT32,
+ { "End-to-End Identifier", "diameter.endtoendid", FT_UINT32,
BASE_HEX, NULL, 0x0, "", HFILL }},
-
+
{ &hf_diameter_avp_code,
{ "AVP Code","diameter.avp.code", FT_UINT32, BASE_DEC,
NULL, 0x0, "", HFILL }},