* Copyright 2001, Michal Melerowicz <michal.melerowicz@nokia.com>
* Nicolas Balkota <balkota@mac.com>
*
- * $Id: packet-gtp.c,v 1.55 2003/07/09 07:12:23 guy Exp $
+ * $Id: packet-gtp.c,v 1.63 2003/09/21 20:06:00 gerald Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
#include <glib.h>
#include <epan/packet.h>
+#include "prefs.h"
#include "packet-gtp.h"
#include "packet-ipv6.h"
#include "packet-ppp.h"
-#include "prefs.h"
static dissector_table_t ppp_subdissector_table;
static gchar *
id_to_str(const guint8 *ad) {
- static gchar *str[17];
- gchar *p;
- guint8 bits8to5, bits4to1, i;
+ static gchar str[17] = " ";
+ guint8 bits8to5, bits4to1;
+ int i;
static const gchar hex_digits[10] = "0123456789";
- p = (gchar *)&str[17];
- *--p = '\0';
- i = 7;
- for (;;) {
+ str[16] = '\0';
+ for (i = 15; i >= 0; i--) {
bits8to5 = (ad[i] >> 4) & 0x0F;
bits4to1 = ad[i] & 0x0F;
- if (bits8to5 < 0xA) *--p = hex_digits[bits8to5];
- if (bits4to1 < 0xA) *--p = hex_digits[bits4to1];
- if (i == 0) break;
+ if (bits8to5 < 0xA) str[i] = hex_digits[bits8to5];
i--;
+ if (bits4to1 < 0xA) str[i] = hex_digits[bits4to1];
}
- return p;
+ return str;
}
static gchar *
imsi_to_str(const guint8 *ad) {
- static gchar *str[16];
- gchar *p;
- guint8 i, j = 0;
-
- p = (gchar *)&str[0];
- for (i=0;i<8;i++) {
- if ((ad[i] & 0x0F) <= 9) p[j++] = (ad[i] & 0x0F) + 0x30;
- if (((ad[i] >> 4) & 0x0F) <= 9) p[j++] = ((ad[i] >> 4) & 0x0F) + 0x30;
+ static gchar str[17] = " ";
+ int i, j = 0;
+
+ for (i = 0; i < 8; i++) {
+ if ((ad[i] & 0x0F) <= 9) str[j++] = (ad[i] & 0x0F) + 0x30;
+ if (((ad[i] >> 4) & 0x0F) <= 9) str[j++] = ((ad[i] >> 4) & 0x0F) + 0x30;
}
- p[j] = 0;
-
- return p;
+ str[j] = '\0';
+
+ return str;
}
static gchar *
msisdn_to_str(const guint8 *ad, int len) {
- static gchar *str[17];
+ static gchar str[18] = "+ ";
gchar *p;
- guint8 bits8to5, bits4to1, i;
+ guint8 bits8to5, bits4to1;
+ int i;
static const gchar hex_digits[16] = "0123456789 ";
- p = (gchar *)&str[0];
- *p = '+';
- i = 1;
- for (;;) {
+ p = &str[0];
+ for (i = 1; i < len && i < 9; i++) {
bits8to5 = (ad[i] >> 4) & 0x0F;
bits4to1 = ad[i] & 0x0F;
if (bits4to1 < 0xA) *++p = hex_digits[bits4to1];
if (bits8to5 < 0xA) *++p = hex_digits[bits8to5];
- if (i == len-1) break;
- i++;
}
- *++p = '\0';
- return (gchar *)&str[0];
+ *p = '\0';
+ return str;
}
static gchar *
if(ranap > 112 && ranap <=128)
proto_tree_add_uint_format(tree, hf_gtpv1_ranap_cause, tvb, offset, 2, ranap, "%s (Miscellaneous Cause) : %s (%u)", val_to_str(GTP_EXT_RANAP_CAUSE, gtp_val, "Unknown"), val_to_str(ranap, ranap_cause_type, "Unknown RANAP Cause"), ranap);
- if(ranap > 128 && ranap <=255)
+ if(ranap > 128 /* && ranap <=255 */)
proto_tree_add_uint_format(tree, hf_gtpv1_ranap_cause, tvb, offset, 2, ranap, "%s (Non-standard Cause) : %s (%u)", val_to_str(GTP_EXT_RANAP_CAUSE, gtp_val, "Unknown"), val_to_str(ranap, ranap_cause_type, "Unknown RANAP Cause"), ranap);
return 2;
/* Will keep the value that will be returned
* */
int retval = 0;
-
+
switch (type) {
case 1:
length = tvb_get_guint8 (tvb, offset);
proto_tree_add_text (ext_tree_qos, tvb, offset + 3, 1, "Hyphen separator: -");
offset++; /* "Get rid" of hyphen */
}
-
+
/* Now, we modify offset here and in order to use type later
* effectively.*/
offset += 2;
break;
/* flow label type = 3 bytes */
case 0x80:
- label = tvb_get_ntoh24(tvb, offset + pf_offset + 1) & 0x0FFFFF;;
+ label = tvb_get_ntoh24(tvb, offset + pf_offset + 1) & 0x0FFFFF;
proto_tree_add_text (ext_tree_tft_pf, tvb, offset + pf_offset, 4, "ID 0x80: Flow Label: %u (%x)", label, label);
pf_offset = pf_offset + 4;
break;
if ((gtpv0_hdr.message == GTP_MSG_TPDU) && gtp_tpdu) {
guint8 sub_proto;
-
+
sub_proto = tvb_get_guint8(tvb,GTPv0_HDR_LENGTH);
if ((sub_proto >= 0x45) && (sub_proto <= 0x4e)) {
/* this is most likely an IPv4 packet */
/* we can exclude 0x40 - 0x44 because the minimum header size is 20 octets */
- /* 0x4f is excluded because PPP protocol type "IPv6 header compression"
- with protocol field compression is more likely than a plain IPv4 packet with 60 octet header size */
-
+ /* 0x4f is excluded because PPP protocol type "IPv6 header compression"
+ with protocol field compression is more likely than a plain IPv4 packet with 60 octet header size */
+
next_tvb = tvb_new_subset(tvb, GTPv0_HDR_LENGTH, -1, -1);
call_dissector(ip_handle, next_tvb, pinfo, tree);
} else
if ((sub_proto >= 0x45) && (sub_proto <= 0x4e)) {
/* this is most likely an IPv4 packet */
/* we can exclude 0x40 - 0x44 because the minimum header size is 20 octets */
- /* 0x4f is excluded because PPP protocol type "IPv6 header compression"
- with protocol field compression is more likely than a plain IPv4 packet with 60 octet header size */
-
+ /* 0x4f is excluded because PPP protocol type "IPv6 header compression"
+ with protocol field compression is more likely than a plain IPv4 packet with 60 octet header size */
+
next_tvb = tvb_new_subset(tvb, GTPv1_HDR_LENGTH - hdr_offset, -1, -1);
call_dissector(ip_handle, next_tvb, pinfo, tree);
} else
if (sub_proto == 0xff) {
/* this might be an address field, even it shouldn't be here */
- guint8 control_field;
+ guint8 control_field;
control_field = tvb_get_guint8(tvb,GTPv1_HDR_LENGTH - hdr_offset + 1);
if (control_field == 0x03)
{