Ethereal-dev: [Ethereal-dev] Patch for WSP/WTP

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: Georg von Zezschwitz <gvz@xxxxxxxxxx>
Date: Sat, 6 Oct 2001 21:52:20 +0200
Hi!

The attached patches include three modifications for the WAP
stack (WSP/WTP):

  - A bug related to "WSP header pages" is fixed, that
    resulted into "malformed WSP frame" alerts
  - "Concatenated PDUs" (Multiple PDUs within one UDP
    packet) are now supported (used e.g. by Nokia 8310)
  - The URL of WSP GET/POST requests is display in the
    info column, same like HTTP GET requests

If anybody needs test data for quality ensuring - please
contact me!

Cheers,


Georg
Index: packet-wsp.c
===================================================================
RCS file: /cvsroot/ethereal/packet-wsp.c,v
retrieving revision 1.38
diff -u -r1.38 packet-wsp.c
--- packet-wsp.c	2001/09/28 18:59:30	1.38
+++ packet-wsp.c	2001/10/06 17:42:25
@@ -225,6 +225,7 @@
 	{ 0x33, "See Other" },
 	{ 0x34, "Not Modified" },
 	{ 0x35, "Use Proxy" },
+	{ 0x37, "Temporary Redirect" },
 
 	{ 0x40, "Bad Request" },
 	{ 0x41, "Unauthorised" },
@@ -242,6 +243,8 @@
 	{ 0x4D, "Request Entity Too Large" },
 	{ 0x4E, "Request-URI Too Large" },
 	{ 0x4F, "Unsupported Media Type" },
+	{ 0x50, "Requested Range Not Satisfiable" },
+	{ 0x51, "Expectation Failed" },
 
 	{ 0x60, "Internal Server Error" },
 	{ 0x61, "Not Implemented" },
@@ -323,6 +326,10 @@
 #define FN_SET_COOKIE		0x41
 #define FN_COOKIE		0x42
 #define FN_ENCODING_VERSION	0x43
+#define FN_PROFILE_WARNING	0x44
+#define FN_CONTENT_DISPOSITION14	0x45
+#define FN_X_WAP_SECURITY	0x46
+#define FN_CACHE_CONTROL14	0x47
 
 static const value_string vals_field_names[] = {
 	{ FN_ACCEPT,               "Accept" },
@@ -393,6 +400,10 @@
 	{ FN_SET_COOKIE,           "Set-Cookie" },
 	{ FN_COOKIE,               "Cookie" },
 	{ FN_ENCODING_VERSION,     "Encoding-Version" },
+	{ FN_PROFILE_WARNING,      "Profile-Warning" },
+	{ FN_CONTENT_DISPOSITION14,"Content-Disposition (encoding 1.4)" },
+	{ FN_X_WAP_SECURITY,       "X-WAP-Security" },
+	{ FN_CACHE_CONTROL14,      "Cache-Control (encoding 1.4)" },
 	{ 0,                       NULL }
 };	
 
@@ -721,7 +732,7 @@
 
 static heur_dissector_list_t heur_subdissector_list;
 
-static void add_uri (proto_tree *, tvbuff_t *, guint, guint);
+static void add_uri (proto_tree *, frame_data *, tvbuff_t *, guint, guint);
 static void add_headers (proto_tree *, tvbuff_t *);
 static int add_well_known_header (proto_tree *, tvbuff_t *, int, guint8);
 static int add_unknown_header (proto_tree *, tvbuff_t *, int, guint8);
@@ -987,12 +998,6 @@
    it, if possible, summarize what's in the packet, so that a user looking
    at the list of packets can tell what type of packet it is. */
     
-	/* Clear the Info column before we fetch anything from the packet */
-	if (check_col(fdata, COL_INFO))
-	{
-		col_clear(fdata, COL_INFO);
-	}
-
 	/* Connection-less mode has a TID first */
 	if (is_connectionless)
 	{
@@ -1005,7 +1010,7 @@
 	/* Develop the string to put in the Info column */
 	if (check_col(fdata, COL_INFO))
 	{
-		col_add_fstr(fdata, COL_INFO, "WSP %s",
+		col_append_fstr(fdata, COL_INFO, "WSP %s",
 			val_to_str (pdut, vals_pdu_type, "Unknown PDU type (0x%02x)"));
 	};
 
@@ -1128,12 +1133,12 @@
 			break;
 
 		case GET:
-			if (tree) {
-				count = 0;	/* Initialise count */
+			count = 0;	/* Initialise count */
 				/* Length of URI and size of URILen field */
-				value = tvb_get_guintvar (tvb, offset, &count);
-				nextOffset = offset + count;
-				add_uri (wsp_tree, tvb, offset, nextOffset);
+			value = tvb_get_guintvar (tvb, offset, &count);
+			nextOffset = offset + count;
+			add_uri (wsp_tree, fdata, tvb, offset, nextOffset);
+			if (tree) {
 				offset += (value+count); /* VERIFY */
 				tmp_tvb = tvb_new_subset (tvb, offset, -1, -1);
 				add_headers (wsp_tree, tmp_tvb);
@@ -1149,8 +1154,8 @@
 			headersLength = tvb_get_guintvar (tvb, headerStart, &count);
 			offset = headerStart + count;
 
+			add_uri (wsp_tree, fdata, tvb, uriStart, offset);
 			if (tree) {
-				add_uri (wsp_tree, tvb, uriStart, offset);
 				offset += uriLength;
 
 				ti = proto_tree_add_uint (wsp_tree, hf_wsp_header_length,tvb,headerStart,count,headersLength);
@@ -1280,6 +1285,8 @@
 {
 	if (check_col(pinfo->fd, COL_PROTOCOL))
 		col_set_str(pinfo->fd, COL_PROTOCOL, "WSP" );
+	if (check_col(pinfo->fd, COL_INFO))
+		col_clear(pinfo->fd, COL_INFO);
 
 	dissect_wsp_common(tvb, pinfo, tree, dissect_wsp_fromudp, TRUE);
 }
@@ -1309,35 +1316,35 @@
 	/*
 	 * XXX - what about WTLS->WSP?
 	 */
+	if (check_col(pinfo->fd, COL_INFO))
+	{
+		col_clear(pinfo->fd, COL_INFO);
+	}
 	dissect_wsp_common(tvb, pinfo, tree, dissect_wtp_fromudp, TRUE);
 }
 
 static void
-add_uri (proto_tree *tree, tvbuff_t *tvb, guint URILenOffset, guint URIOffset)
+add_uri (proto_tree *tree, frame_data *fdata, tvbuff_t *tvb, guint URILenOffset, guint URIOffset)
 {
 	proto_item *ti;
-	guint8 terminator = 0;
 	char *newBuffer;
 
 	guint count = 0;
 	guint uriLen = tvb_get_guintvar (tvb, URILenOffset, &count);
 
-	ti = proto_tree_add_uint (tree, hf_wsp_header_uri_len,tvb,URILenOffset,count,uriLen);
+	if (tree)
+		ti = proto_tree_add_uint (tree, hf_wsp_header_uri_len,tvb,URILenOffset,count,uriLen);
 
-	/* If string doesn't end with a 0x00, we need to add one to be on the safe side */
-	terminator = tvb_get_guint8 (tvb, URIOffset+uriLen-1);
-	if (terminator != 0)
-	{
-		newBuffer = g_malloc (uriLen+1);
-		strncpy (newBuffer, tvb_get_ptr (tvb, URIOffset, uriLen), uriLen);
-		newBuffer[uriLen] = 0;
-		ti = proto_tree_add_string (tree, hf_wsp_header_uri,tvb,URIOffset,uriLen,newBuffer);
-		g_free (newBuffer);
-	}
-	else
-	{
-		ti = proto_tree_add_item (tree, hf_wsp_header_uri,tvb,URIOffset,uriLen,bo_little_endian);
-	}
+	newBuffer = g_malloc (uriLen+2);
+	newBuffer[0] = ' ';  /* This is for COL_INFO */
+	strncpy (newBuffer+1, tvb_get_ptr (tvb, URIOffset, uriLen), uriLen);
+	newBuffer[uriLen+1] = 0;
+	if (tree)
+		ti = proto_tree_add_string (tree, hf_wsp_header_uri,tvb,URIOffset,uriLen,newBuffer+1);
+	if (check_col(fdata, COL_INFO)) {
+		col_append_str(fdata, COL_INFO, newBuffer);
+	};
+	g_free (newBuffer);
 }
 
 static void
@@ -2584,7 +2591,7 @@
 			case 0x06 : /* Header Code Pages */ 
 				offsetStr = offset;
 				offset++;
-				add_capability_vals(tvb, TRUE,
+				add_capability_vals(tvb, (type == CONNECT),
 				    offsetStr, length, capabilitiesStart,
 				    valString, sizeof valString);
 				proto_tree_add_string(wsp_capabilities, hf_wsp_capabilities_header_code_pages, tvb, capabilitiesStart, length+1, valString);
Index: packet-wtp.c
===================================================================
RCS file: /cvsroot/ethereal/packet-wtp.c,v
retrieving revision 1.19
diff -u -r1.19 packet-wtp.c
--- packet-wtp.c	2001/09/11 14:36:31	1.19
+++ packet-wtp.c	2001/10/06 17:42:11
@@ -148,6 +148,7 @@
 
 /* These fields used by fixed part of header */
 static int hf_wtp_header_fixed_part 			= HF_EMPTY;
+static int hf_wtp_header_sub_pdu_size 			= HF_EMPTY;
 static int hf_wtp_header_flag_continue 			= HF_EMPTY;
 static int hf_wtp_header_pdu_type 				= HF_EMPTY;
 static int hf_wtp_header_flag_Trailer 			= HF_EMPTY;
@@ -210,7 +211,7 @@
 
 /* Set up structures we will need to add the protocol subtree and manage it */
 	proto_item *ti;
-	proto_tree *wtp_tree;
+	proto_tree *wtp_tree = NULL;
 	proto_tree *wtp_header_fixed;
 	
 	char pdut;
@@ -224,11 +225,38 @@
 	fprintf( stderr, "dissect_wtp: (Entering) Frame data at %p\n", fdata ); 
 	fprintf( stderr, "dissect_wtp: tvb length is %d\n", tvb_reported_length( tvb ) ); 
 #endif
-	if (check_col(fdata, COL_INFO)) {
-		col_clear(fdata, COL_INFO);
-	};
-    
 	b0 = tvb_get_guint8 (tvb, offCur + 0);
+	/* Discover Concatenated PDUs */
+	if (b0 == 0) {
+		if (tree) {
+			wtp_tree = proto_tree_add_item(tree, proto_wtp, tvb, offCur, 1, bo_little_endian);
+		}
+		offCur = 1;
+		i = 1;
+		while (offCur < (int) tvb_reported_length (tvb)) {
+			b0 = tvb_get_guint8 (tvb, offCur + 0);
+			if (b0 & 0x80) {
+				vHeader = 2;
+				cbHeader = ((b0 & 0x7f) << 8) |
+							tvb_get_guint8 (tvb, offCur + 1);
+			} else {
+				vHeader = 1;
+				cbHeader = b0;
+			}
+		    if (tree) {
+				proto_tree_add_item(wtp_tree, hf_wtp_header_sub_pdu_size, tvb, offCur, vHeader, bo_big_endian);
+			}
+			if (i > 1 && check_col(fdata, COL_INFO)) {
+				col_append_str (fdata, COL_INFO, ", ");
+			}
+			wsp_tvb = tvb_new_subset(tvb,
+				offCur + vHeader, -1, cbHeader);
+			dissect_wtp_common (wsp_tvb, pinfo, wtp_tree);
+			offCur += vHeader + cbHeader;
+			i++;
+		}
+		return;
+	}
 	fCon = b0 & 0x80;
 	fRID = retransmission_indicator( b0 );
 	pdut = pdu_type( b0 );
@@ -288,11 +316,12 @@
 /* This field shows up as the "Info" column in the display; you should make
    it, if possible, summarize what's in the packet, so that a user looking
    at the list of packets can tell what type of packet it is. */
-	if (check_col(fdata, COL_INFO)) {
+	if (check_col(fdata, COL_INFO) &&
+		tvb_reported_length (tvb) <= cbHeader + vHeader) {
 #ifdef DEBUG
 		fprintf( stderr, "dissect_wtp: (6) About to set info_col header to %s\n", szInfo );
 #endif
-		col_add_str(fdata, COL_INFO, szInfo );
+		col_append_str(fdata, COL_INFO, szInfo );
 	};
 /* In the interest of speed, if "tree" is NULL, don't do any work not
    necessary to generate protocol tree items. */
@@ -457,6 +486,9 @@
 {
 	if (check_col(pinfo->fd, COL_PROTOCOL))
 		col_set_str(pinfo->fd, COL_PROTOCOL, "WTP+WSP" );
+	if (check_col(pinfo->fd, COL_INFO)) {
+		col_clear(pinfo->fd, COL_INFO);
+	}
 
 	dissect_wtp_common(tvb, pinfo, tree);
 }
@@ -475,6 +507,9 @@
 {
 	if (check_col(pinfo->fd, COL_PROTOCOL))
 		col_set_str(pinfo->fd, COL_PROTOCOL, "WTLS+WTP+WSP" );
+	if (check_col(pinfo->fd, COL_INFO)) {
+		col_clear(pinfo->fd, COL_INFO);
+	}
 
 	dissect_wtp_common(tvb, pinfo, tree);
 }
@@ -519,6 +554,13 @@
 				"wtp.header_fixed_part",
 				FT_BYTES, BASE_HEX, NULL, 0x0,          
 				"Fixed part of the header", HFILL
+			}
+		},
+		{ &hf_wtp_header_sub_pdu_size,
+			{ 	"Sub PDU size",           
+				"wtp.sub_pdu_size",
+				FT_BYTES, BASE_HEX, NULL, 0x0,
+				"Size of Sub-PDU", HFILL
 			}
 		},
 		{ &hf_wtp_header_flag_continue,