1 /* packet-wsp.c (c) 2000 Neil Hunter
2 * Based on original work by Ben Fowler
4 * Routines to dissect WSP component of WAP traffic.
6 * $Id: packet-wsp.c,v 1.8 2001/01/03 16:41:07 gram Exp $
8 * Ethereal - Network traffic analyzer
9 * By Gerald Combs <gerald@zing.org>
10 * Copyright 1998 Didier Jorand
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34 #ifdef HAVE_SYS_TYPES_H
35 # include <sys/types.h>
38 #ifdef HAVE_NETINET_IN_H
39 # include <netinet/in.h>
42 #ifdef NEED_SNPRINTF_H
48 # include "snprintf.h"
54 #include "packet-wap.h"
55 #include "packet-wsp.h"
57 /* File scoped variables for the protocol and registered fields */
58 static int proto_wsp = HF_EMPTY;
60 /* These fields used by fixed part of header */
61 static int hf_wsp_header_tid = HF_EMPTY;
62 static int hf_wsp_header_pdu_type = HF_EMPTY;
63 static int hf_wsp_version_major = HF_EMPTY;
64 static int hf_wsp_version_minor = HF_EMPTY;
65 static int hf_wsp_capability_length = HF_EMPTY;
66 static int hf_wsp_capabilities_section = HF_EMPTY;
67 static int hf_wsp_header_uri_len = HF_EMPTY;
68 static int hf_wsp_header_uri = HF_EMPTY;
69 static int hf_wsp_server_session_id = HF_EMPTY;
70 static int hf_wsp_header_status = HF_EMPTY;
71 static int hf_wsp_header_length = HF_EMPTY;
72 static int hf_wsp_headers_section = HF_EMPTY;
73 static int hf_wsp_header = HF_EMPTY;
74 static int hf_wsp_content_type = HF_EMPTY;
75 static int hf_wsp_parameter_well_known_charset = HF_EMPTY;
76 static int hf_wsp_reply_data = HF_EMPTY;
77 static int hf_wsp_post_data = HF_EMPTY;
79 static int hf_wsp_header_accept = HF_EMPTY;
80 static int hf_wsp_header_accept_str = HF_EMPTY;
81 static int hf_wsp_header_accept_charset = HF_EMPTY;
82 static int hf_wsp_header_accept_language = HF_EMPTY;
83 static int hf_wsp_header_accept_ranges = HF_EMPTY;
84 static int hf_wsp_header_cache_control = HF_EMPTY;
85 static int hf_wsp_header_content_length = HF_EMPTY;
86 static int hf_wsp_header_age = HF_EMPTY;
87 static int hf_wsp_header_date = HF_EMPTY;
88 static int hf_wsp_header_etag = HF_EMPTY;
89 static int hf_wsp_header_expires = HF_EMPTY;
90 static int hf_wsp_header_last_modified = HF_EMPTY;
91 static int hf_wsp_header_location = HF_EMPTY;
92 static int hf_wsp_header_if_modified_since = HF_EMPTY;
93 static int hf_wsp_header_server = HF_EMPTY;
94 static int hf_wsp_header_user_agent = HF_EMPTY;
95 static int hf_wsp_header_application_header = HF_EMPTY;
96 static int hf_wsp_header_application_value = HF_EMPTY;
97 static int hf_wsp_header_x_wap_tod = HF_EMPTY;
99 /* Initialize the subtree pointers */
100 static gint ett_wsp = ETT_EMPTY;
101 static gint ett_header = ETT_EMPTY;
102 static gint ett_headers = ETT_EMPTY;
103 static gint ett_capabilities = ETT_EMPTY;
104 static gint ett_content_type = ETT_EMPTY;
106 static const value_string vals_pdu_type[] = {
107 { 0x00, "Reserved" },
109 { 0x02, "ConnectReply" },
110 { 0x03, "Redirect" },
112 { 0x05, "Disconnect" },
114 { 0x07, "ConfirmedPush" },
118 /* 0x10 - 0x3F Unassigned */
126 /* 0x45 - 0x4F Unassigned (Get PDU) */
127 /* 0x50 - 0x5F Extended method (Get PDU) */
132 /* 0x62 - 0x6F Unassigned (Post PDU) */
133 /* 0x70 - 0x7F Extended method (Post PDU) */
134 /* 0x80 - 0xFF Reserved */
140 static const value_string vals_status[] = {
141 /* 0x00 - 0x0F Reserved */
143 { 0x10, "Continue" },
144 { 0x11, "Switching Protocols" },
148 { 0x22, "Accepted" },
149 { 0x23, "Non-Authoritative Information" },
150 { 0x24, "No Content" },
151 { 0x25, "Reset Content" },
152 { 0x26, "Partial Content" },
154 { 0x30, "Multiple Choices" },
155 { 0x31, "Moved Permanently" },
156 { 0x32, "Moved Temporarily" },
157 { 0x33, "See Other" },
158 { 0x34, "Not Modified" },
159 { 0x35, "Use Proxy" },
161 { 0x40, "Bad Request" },
162 { 0x41, "Unauthorised" },
163 { 0x42, "Payment Required" },
164 { 0x43, "Forbidden" },
165 { 0x44, "Not Found" },
166 { 0x45, "Method Not Allowed" },
167 { 0x46, "Not Acceptable" },
168 { 0x47, "Proxy Authentication Required" },
169 { 0x48, "Request Timeout" },
170 { 0x49, "Conflict" },
172 { 0x4B, "Length Required" },
173 { 0x4C, "Precondition Failed" },
174 { 0x4D, "Request Entity Too Large" },
175 { 0x4E, "Request-URI Too Large" },
176 { 0x4F, "Unsupported Media Type" },
178 { 0x60, "Internal Server Error" },
179 { 0x61, "Not Implemented" },
180 { 0x62, "Bad Gateway" },
181 { 0x63, "Service Unavailable" },
182 { 0x64, "Gateway Timeout" },
183 { 0x65, "HTTP Version Not Supported" },
187 static const value_string vals_content_types[] = {
190 { 0x02, "text/html" },
191 { 0x03, "text/plain" },
192 { 0x04, "text/x-hdml" },
193 { 0x05, "text/x-ttml" },
194 { 0x06, "text/x-vCalendar" },
195 { 0x07, "text/x-vCard" },
196 { 0x08, "text/vnd.wap.wml" },
197 { 0x09, "text/vnd.wap.wmlscript" },
198 { 0x0A, "text/vnd.wap.channel" },
199 { 0x0B, "Multipart/*" },
200 { 0x0C, "Multipart/mixed" },
201 { 0x0D, "Multipart/form-data" },
202 { 0x0E, "Multipart/byteranges" },
203 { 0x0F, "Multipart/alternative" },
204 { 0x10, "application/*" },
205 { 0x11, "application/java-vm" },
206 { 0x12, "application/x-www-form-urlencoded" },
207 { 0x13, "application/x-hdmlc" },
208 { 0x14, "application/vnd.wap.wmlc" },
209 { 0x15, "application/vnd.wap.wmlscriptc" },
210 { 0x16, "application/vnd.wap.channelc" },
211 { 0x17, "application/vnd.wap.uaprof" },
212 { 0x18, "application/vnd.wap.wtls-ca-certificate" },
213 { 0x19, "application/vnd.wap.wtls-user-certificate" },
214 { 0x1A, "application/x-x509-ca-cert" },
215 { 0x1B, "application/x-x509-user-cert" },
217 { 0x1D, "image/gif" },
218 { 0x1E, "image/jpeg" },
219 { 0x1F, "image/tiff" },
220 { 0x20, "image/png" },
221 { 0x21, "image/vnd.wap.wbmp" },
222 { 0x22, "application/vnd.wap.multipart.*" },
223 { 0x23, "application/vnd.wap.multipart.mixed" },
224 { 0x24, "application/vnd.wap.multipart.form-data" },
225 { 0x25, "application/vnd.wap.multipart.byteranges" },
226 { 0x26, "application/vnd.wap.multipart.alternative" },
227 { 0x27, "application/xml" },
228 { 0x28, "text/xml" },
229 { 0x29, "application/vnd.wap.wbxml" },
230 { 0x2A, "application/x-x968-cross-cert" },
231 { 0x2B, "application/x-x968-ca-cert" },
232 { 0x2C, "application/x-x968-user-cert" },
233 { 0x2D, "text/vnd.wap.si" },
234 { 0x2E, "application/vnd.wap.sic" },
235 { 0x2F, "text/vnd.wap.sl" },
236 { 0x30, "application/vnd.wap.slc" },
237 { 0x31, "text/vnd.wap.co" },
238 { 0x32, "application/vnd.wap.coc" },
239 { 0x33, "application/vnd.wap.multipart.related" },
240 { 0x34, "application/vnd.wap.sia" },
244 static const value_string vals_character_sets[] = {
245 { 0x0003, "us-ascii" },
246 { 0x0004, "iso-8859-1" },
247 { 0x0005, "iso-8859-2" },
248 { 0x0006, "iso-8859-3" },
249 { 0x0007, "iso-8859-4" },
250 { 0x0008, "iso-8859-5" },
251 { 0x0009, "iso-8859-6" },
252 { 0x000A, "iso-8859-7" },
253 { 0x000B, "iso-8859-8" },
254 { 0x000C, "iso-8859-9" },
255 { 0x0011, "shift_JIS" },
257 { 0x03E8, "iso-10646-ucs-2" },
262 static const value_string vals_languages[] = {
263 { 0x19, "English (en)" },
267 static const value_string vals_accept_ranges[] = {
273 static const value_string vals_cache_control[] = {
274 { 0x80, "No-cache" },
275 { 0x81, "No-store" },
277 { 0x83, "Max-stale" },
278 { 0x84, "Min-fresh" },
279 { 0x85, "Only-if-cached" },
282 { 0x88, "No-transform" },
283 { 0x89, "Must-revalidate" },
284 { 0x8A, "Proxy-revalidate" },
289 * Windows appears to define DELETE.
299 REDIRECT = 0x03, /* No sample data */
302 PUSH = 0x06, /* No sample data */
303 CONFIRMEDPUSH = 0x07, /* No sample data */
304 SUSPEND = 0x08, /* No sample data */
305 RESUME = 0x09, /* No sample data */
308 OPTIONS = 0x41, /* No sample data */
309 HEAD = 0x42, /* No sample data */
310 DELETE = 0x43, /* No sample data */
311 TRACE = 0x44, /* No sample data */
314 PUT = 0x61, /* No sample data */
317 void add_uri (proto_tree *, tvbuff_t *, guint, guint);
318 void add_headers (proto_tree *, tvbuff_t *);
319 void add_header (proto_tree *, tvbuff_t *, tvbuff_t *);
320 guint get_value_length (tvbuff_t *, guint, guint *);
321 guint add_content_type (proto_tree *, tvbuff_t *, guint, guint *);
322 guint add_parameter (proto_tree *, tvbuff_t *, guint);
323 guint add_parameter_charset (proto_tree *, tvbuff_t *, guint, guint);
324 void add_post_data (proto_tree *, tvbuff_t *, guint);
325 void add_post_variable (proto_tree *, tvbuff_t *, guint, guint, guint, guint);
328 * Accessor to retrieve variable length int as used in WAP protocol.
329 * The value is encoded in the lower 7 bits. If the top bit is set, then the
330 * value continues into the next byte.
331 * The octetCount parameter holds the number of bytes read in order to return
332 * the final value. Can be pre-initialised to start at offset+count.
335 tvb_get_guintvar (tvbuff_t *tvb, guint offset, guint *octetCount)
342 if (octetCount != NULL)
345 fprintf (stderr, "dissect_wsp: Starting tvb_get_guintvar at offset %d, count=NULL\n", offset);
351 fprintf (stderr, "dissect_wsp: Starting tvb_get_guintvar at offset %d, count=%d\n", offset, *octetCount);
353 counter = *octetCount;
358 value<<=7; /* Value only exists in 7 of the 8 bits */
359 octet = tvb_get_guint8 (tvb, offset+counter);
361 value += (octet & 0x7F);
362 cont = (octet & 0x80);
364 fprintf (stderr, "dissect_wsp: octet is %d (0x%02x), count=%d, value=%d, cont=%d\n", octet, octet, counter, value, cont);
368 if (octetCount != NULL)
370 *octetCount = counter;
372 fprintf (stderr, "dissect_wsp: Leaving tvb_get_guintvar count=%d\n", *octetCount);
379 /* Code to actually dissect the packets */
381 dissect_wsp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
383 frame_data *fdata = pinfo->fd;
393 guint capabilityLength = 0;
394 guint capabilityStart = 0;
395 guint headersLength = 0;
396 guint headerLength = 0;
397 guint headerStart = 0;
398 guint nextOffset = 0;
399 guint contentTypeStart = 0;
400 guint contentType = 0;
403 /* Set up structures we will need to add the protocol subtree and manage it */
405 proto_tree *wsp_tree;
406 /* proto_tree *wsp_header_fixed; */
407 proto_tree *wsp_capabilities;
409 CHECK_DISPLAY_AS_DATA(proto_wsp, tvb, pinfo, tree);
411 pinfo->current_proto = "WSP";
413 /* This field shows up as the "Info" column in the display; you should make
414 it, if possible, summarize what's in the packet, so that a user looking
415 at the list of packets can tell what type of packet it is. */
417 /* Display protocol type depending on the port */
418 if (check_col(fdata, COL_PROTOCOL))
420 switch ( pinfo->match_port )
423 col_set_str(fdata, COL_PROTOCOL, "WSP" );
425 case UDP_PORT_WTLS_WSP:
426 col_set_str(fdata, COL_PROTOCOL, "WTLS+WSP" );
431 /* Connection-less mode has a TID first */
432 if ((pinfo->match_port == UDP_PORT_WSP) || (pinfo->match_port == UDP_PORT_WTLS_WSP))
437 /* Find the PDU type */
438 pdut = tvb_get_guint8 (tvb, offset);
440 /* Develop the string to put in the Info column */
441 cchInfo = snprintf( szInfo, sizeof( szInfo ), "WSP %s",
442 match_strval (( int )pdut, vals_pdu_type));
443 if (check_col(fdata, COL_INFO)) {
444 col_add_str(fdata, COL_INFO, szInfo );
447 /* In the interest of speed, if "tree" is NULL, don't do any work not
448 necessary to generate protocol tree items. */
450 ti = proto_tree_add_item(tree, proto_wsp, tvb, 0,
451 tvb_length(tvb), bo_little_endian);
452 wsp_tree = proto_item_add_subtree(ti, ett_wsp);
454 /* Code to process the packet goes here */
456 wsp_header_fixed = proto_item_add_subtree(
462 /* Add common items: only TID and PDU Type */
464 /* TID Field is always first (if it exists) */
465 if ((pinfo->match_port == UDP_PORT_WSP) || (pinfo->match_port == UDP_PORT_WTLS_WSP))
467 ti = proto_tree_add_item (wsp_tree, hf_wsp_header_tid,tvb,0,1,bo_little_endian);
470 ti = proto_tree_add_item(
472 hf_wsp_header_pdu_type, /* id */
474 offset++, /* start of high light */
475 1, /* length of high light */
476 bo_little_endian /* value */
482 ti = proto_tree_add_item (wsp_tree, hf_wsp_version_major,tvb,offset,1,bo_little_endian);
483 ti = proto_tree_add_item (wsp_tree, hf_wsp_version_minor,tvb,offset,1,bo_little_endian);
485 capabilityStart = offset;
486 capabilityLength = tvb_get_guintvar (tvb, offset, &count);
488 ti = proto_tree_add_uint (wsp_tree, hf_wsp_capability_length,tvb,capabilityStart,count,capabilityLength);
490 headerStart = offset;
491 headerLength = tvb_get_guintvar (tvb, offset, &count);
493 ti = proto_tree_add_uint (wsp_tree, hf_wsp_header_length,tvb,headerStart,count,headerLength);
494 if (capabilityLength > 0)
496 ti = proto_tree_add_item (wsp_tree, hf_wsp_capabilities_section,tvb,offset,capabilityLength,bo_little_endian);
497 wsp_capabilities = proto_item_add_subtree( ti, ett_capabilities );
498 offset += capabilityLength;
501 if (headerLength > 0)
503 tmp_tvb = tvb_new_subset (tvb, offset, headerLength, headerLength);
504 add_headers (wsp_tree, tmp_tvb);
510 value = tvb_get_guintvar (tvb, offset, &count);
511 ti = proto_tree_add_uint (wsp_tree, hf_wsp_server_session_id,tvb,offset,count,value);
514 capabilityStart = offset;
515 capabilityLength = tvb_get_guintvar (tvb, offset, &count);
517 ti = proto_tree_add_uint (wsp_tree, hf_wsp_capability_length,tvb,capabilityStart,count,capabilityLength);
519 headerStart = offset;
520 headerLength = tvb_get_guintvar (tvb, offset, &count);
522 ti = proto_tree_add_item (wsp_tree, hf_wsp_header_length,tvb,headerStart,count,bo_little_endian);
523 if (capabilityLength > 0)
525 ti = proto_tree_add_item (wsp_tree, hf_wsp_capabilities_section,tvb,offset,capabilityLength,bo_little_endian);
526 wsp_capabilities = proto_item_add_subtree( ti, ett_capabilities );
527 offset += capabilityLength;
530 if (headerLength > 0)
534 ti = proto_tree_add_item (wsp_tree, hf_wsp_headers_section,tvb,offset,headerLength,bo_little_endian);
535 wsp_headers = proto_item_add_subtree( ti, ett_headers );
537 tmp_tvb = tvb_new_subset (tvb, offset, headerLength, headerLength);
538 add_headers (wsp_tree, tmp_tvb);
544 value = tvb_get_guintvar (tvb, offset, &count);
545 ti = proto_tree_add_uint (wsp_tree, hf_wsp_server_session_id,tvb,offset,count,value);
549 /* Length of URI and size of URILen field */
550 value = tvb_get_guintvar (tvb, offset, &count);
551 nextOffset = offset + count;
552 add_uri (wsp_tree, tvb, offset, nextOffset);
554 tmp_tvb = tvb_new_subset (tvb, offset, -1, -1);
555 add_headers (wsp_tree, tmp_tvb);
560 uriLength = tvb_get_guintvar (tvb, offset, &count);
561 headerStart = uriStart+count;
562 headersLength = tvb_get_guintvar (tvb, headerStart, &count);
563 offset = headerStart + count;
565 add_uri (wsp_tree, tvb, uriStart, offset);
568 ti = proto_tree_add_item (wsp_tree, hf_wsp_header_length,tvb,headerStart,count,bo_little_endian);
570 contentTypeStart = offset;
571 nextOffset = add_content_type (wsp_tree, tvb, offset, &contentType);
573 /* Add headers subtree that will hold the headers fields */
574 /* Runs from nextOffset for value-(length of content-type field)*/
575 headerLength = headersLength-(nextOffset-contentTypeStart);
576 tmp_tvb = tvb_new_subset (tvb, nextOffset, headerLength, headerLength);
577 add_headers (wsp_tree, tmp_tvb);
579 /* TODO: Post DATA */
580 /* Runs from start of headers+headerLength to END_OF_FRAME */
581 offset = nextOffset+headerLength;
582 tmp_tvb = tvb_new_subset (tvb, offset, tvb_reported_length (tvb)-offset, tvb_reported_length (tvb)-offset);
583 add_post_data (wsp_tree, tmp_tvb, contentType);
587 ti = proto_tree_add_item (wsp_tree, hf_wsp_header_status,tvb,offset,1,bo_little_endian);
588 value = tvb_get_guintvar (tvb, offset+1, &count);
589 nextOffset = offset + 1 + count;
590 ti = proto_tree_add_item (wsp_tree, hf_wsp_header_length,tvb,offset+1,count,bo_little_endian);
592 contentTypeStart = nextOffset;
593 nextOffset = add_content_type (wsp_tree, tvb, nextOffset, &contentType);
595 /* Add headers subtree that will hold the headers fields */
596 /* Runs from nextOffset for value-(length of content-type field)*/
597 headerLength = value-(nextOffset-contentTypeStart);
598 tmp_tvb = tvb_new_subset (tvb, nextOffset, headerLength, headerLength);
599 add_headers (wsp_tree, tmp_tvb);
600 offset += count+value+1;
602 /* TODO: Data - decode WMLC */
603 /* Runs from offset+1+count+value+1 to END_OF_FRAME */
604 if (offset < tvb_reported_length (tvb))
606 ti = proto_tree_add_item (wsp_tree, hf_wsp_reply_data,tvb,offset,END_OF_FRAME,bo_little_endian);
614 add_uri (proto_tree *tree, tvbuff_t *tvb, guint URILenOffset, guint URIOffset)
617 guint8 terminator = 0;
621 guint uriLen = tvb_get_guintvar (tvb, URILenOffset, &count);
623 ti = proto_tree_add_uint (tree, hf_wsp_header_uri_len,tvb,URILenOffset,count,uriLen);
625 /* If string doesn't end with a 0x00, we need to add one to be on the safe side */
626 terminator = tvb_get_guint8 (tvb, URIOffset+uriLen-1);
629 newBuffer = g_malloc (uriLen+1);
630 strncpy (newBuffer, tvb_get_ptr (tvb, URIOffset, uriLen), uriLen);
631 newBuffer[uriLen] = 0;
632 ti = proto_tree_add_string (tree, hf_wsp_header_uri,tvb,URIOffset,uriLen,newBuffer);
637 ti = proto_tree_add_item (tree, hf_wsp_header_uri,tvb,URIOffset,uriLen,bo_little_endian);
642 add_headers (proto_tree *tree, tvbuff_t *tvb)
645 proto_tree *wsp_headers;
647 guint headersLen = tvb_reported_length (tvb);
648 guint8 headerStart = 0;
650 tvbuff_t *header_buff;
651 tvbuff_t *value_buff;
653 guint valueStart = 0;
657 fprintf (stderr, "dissect_wsp: Offset is %d, size is %d\n", offset, headersLen);
667 fprintf (stderr, "dissect_wsp: Headers to process\n");
670 ti = proto_tree_add_item (tree, hf_wsp_headers_section,tvb,offset,headersLen,bo_little_endian);
671 wsp_headers = proto_item_add_subtree( ti, ett_headers );
675 while (offset < headersLen)
677 /* Loop round each header */
678 headerStart = offset;
679 peek = tvb_get_guint8 (tvb, headerStart);
681 if (peek < 32) /* Short-cut shift delimeter */
683 fprintf (stderr, "dissect_wsp: header: short-cut shift %d (0x%02X)\n", peek, peek);
686 else if (peek == 0x7F) /* Shift delimeter */
688 fprintf (stderr, "dissect_wsp: header: shift delimeter %d (0x%02X)\n", peek, peek);
694 fprintf (stderr, "dissect_wsp: header: application-header start %d (0x%02X)\n", peek, peek);
696 while (tvb_get_guint8 (tvb, offset++)) { /* Do nothing, just look for NULL */ }
698 else if (peek & 0x80) /* Well-known header */
701 fprintf (stderr, "dissect_wsp: header: well-known %d (0x%02X)\n", peek, peek);
706 /* Get value part of header */
708 peek = tvb_get_guint8 (tvb, valueStart);
712 fprintf (stderr, "dissect_wsp: Looking for %d octets\n", peek);
715 valueEnd = offset+1+peek;
721 fprintf (stderr, "dissect_wsp: Looking for uintvar octets\n");
723 tvb_get_guintvar (tvb, valueStart, &count);
724 valueEnd = offset+1+count;
727 else if (peek <= 127)
730 fprintf (stderr, "dissect_wsp: Looking for NULL-terminated string\n");
732 valueEnd = valueStart+1;
733 while (tvb_get_guint8 (tvb, valueEnd++)) { /* Do nothing, just look for NULL */ }
739 fprintf (stderr, "dissect_wsp: Value is %d\n", (peek & 0x7F));
745 fprintf (stderr, "dissect_wsp: Creating value buffer from offset %d, size=%d\n", headerStart, (offset-headerStart));
748 header_buff = tvb_new_subset (tvb, headerStart, (offset-headerStart), (offset-headerStart));
749 value_buff = tvb_new_subset (tvb, valueStart, (valueEnd-valueStart), (valueEnd-valueStart));
751 add_header (wsp_headers, header_buff, value_buff);
756 add_header (proto_tree *tree, tvbuff_t *header_buff, tvbuff_t *value_buff)
759 guint8 headerType = 0;
761 guint headerLen = tvb_reported_length (header_buff);
762 guint valueLen = tvb_reported_length (value_buff);
764 struct timeval timeValue;
767 headerType = tvb_get_guint8 (header_buff, 0);
768 peek = tvb_get_guint8 (value_buff, 0);
770 fprintf (stderr, "dissect_wsp: Got header 0x%02x\n", headerType);
771 fprintf (stderr, "dissect_wsp: First value octet is 0x%02x\n", peek);
774 if (headerType == 0x7F)
777 else if (headerType < 0x1F)
780 else if (headerType & 0x80)
782 headerType = headerType & 0x7F;
785 case 0x00: /* Accept */
788 proto_tree_add_uint (tree, hf_wsp_header_accept, header_buff, offset, headerLen, (peek & 0x7F));
792 proto_tree_add_string (tree, hf_wsp_header_accept_str,header_buff,offset,headerLen,tvb_get_ptr (value_buff, 0, valueLen));
796 case 0x01: /* Accept-Charset */
799 /* Peek contains the number of octets to follow */
803 proto_tree_add_uint (tree, hf_wsp_header_accept_charset, header_buff, offset, headerLen, tvb_get_guint8 (value_buff, 1) );
806 proto_tree_add_uint (tree, hf_wsp_header_accept_charset, header_buff, offset, headerLen, tvb_get_ntohs (value_buff, 1) );
809 proto_tree_add_uint (tree, hf_wsp_header_accept_charset, header_buff, offset, headerLen, tvb_get_ntohl (value_buff, 1) );
812 fprintf (stderr, "dissect_wsp: accept-charset size %d NYI\n", peek);
815 else if (peek & 0x80)
817 proto_tree_add_uint (tree, hf_wsp_header_accept_charset, header_buff, offset, headerLen, (peek & 0x7F) );
821 fprintf (stderr, "dissect_wsp: Accept-Charset value %d (0x%02X) NYI\n", peek, peek);
825 case 0x03: /* Accept-Language */
826 proto_tree_add_uint (tree, hf_wsp_header_accept_language, header_buff, offset, headerLen, (peek & 0x7F));
829 case 0x04: /* Accept-Ranges */
830 if ((peek == 128) || (peek == 129))
832 proto_tree_add_uint (tree, hf_wsp_header_accept_ranges, header_buff, offset, headerLen, peek);
836 fprintf (stderr, "dissect_wsp: accept-ranges NYI\n");
845 proto_tree_add_uint (tree, hf_wsp_header_age, header_buff, offset, headerLen, tvb_get_guint8 (value_buff, 0));
848 proto_tree_add_uint (tree, hf_wsp_header_age, header_buff, offset, headerLen, tvb_get_ntohs (value_buff, 0));
851 proto_tree_add_uint (tree, hf_wsp_header_age, header_buff, offset, headerLen, tvb_get_ntoh24 (value_buff, 0));
854 proto_tree_add_uint (tree, hf_wsp_header_age, header_buff, offset, headerLen, tvb_get_ntohl (value_buff, 0));
859 case 0x08: /* Cache-Control */
862 if (valueLen == 1) /* Well-known value */
864 proto_tree_add_uint (tree, hf_wsp_header_cache_control, header_buff, offset, headerLen, peek);
868 if ((peek == 0x82) || (peek == 0x83) || (peek == 0x84)) /* Delta seconds value to follow */
870 value = tvb_get_guint8 (value_buff, 1);
873 proto_tree_add_text (tree, header_buff, 0, headerLen, "Cache-Control: %s %d (0x%02X)",
874 match_strval ((int) peek, vals_cache_control), (value & 0x7F), peek);
878 fprintf (stderr, "dissect_wsp: Cache-Control integer value Delta seconds NYI\n");
881 else if ((peek == 0x80) || (peek == 0x87)) /* Fields to follow */
883 fprintf (stderr, "dissect_wsp: Cache-Control field values NYI\n");
887 fprintf (stderr, "dissect_wsp: Cache-Control cache extension NYI\n");
893 fprintf (stderr, "dissect_wsp: Cache-Control cache extension NYI\n");
897 case 0x0D: /* Content-Length */
900 proto_tree_add_uint (tree, hf_wsp_header_content_length, header_buff, offset, headerLen, (peek & 0x7F));
904 fprintf (stderr, "dissect_wsp: Content-Length long-integer size NYI\n");
908 case 0x12: /* Date */
909 timeValue.tv_sec = tvb_get_ntohl (value_buff, 0);
910 ti = proto_tree_add_time (tree, hf_wsp_header_date, header_buff, offset, headerLen, &timeValue);
913 case 0x13: /* Etag */
914 ti = proto_tree_add_string (tree, hf_wsp_header_etag,header_buff,offset,headerLen,tvb_get_ptr (value_buff, 0, valueLen));
917 case 0x14: /* Expires */
922 fprintf (stderr, "dissect_wsp: Expires value length %d NYI\n", valueLen);
925 timeValue.tv_sec = tvb_get_ntoh24 (value_buff, 0);
928 timeValue.tv_sec = tvb_get_ntohl (value_buff, 0);
931 ti = proto_tree_add_time (tree, hf_wsp_header_expires, header_buff, offset, headerLen, &timeValue);
934 case 0x17: /* If-Modified-Since */
937 timeValue.tv_sec = tvb_get_ntohl (value_buff, 0);
941 timeValue.tv_sec = 0;
943 ti = proto_tree_add_time (tree, hf_wsp_header_if_modified_since, header_buff, offset, headerLen, &timeValue);
946 case 0x1C: /* Location */
947 ti = proto_tree_add_string (tree, hf_wsp_header_location,header_buff,offset,headerLen,tvb_get_ptr (value_buff, 0, valueLen));
950 case 0x1D: /* Last-Modified */
951 timeValue.tv_sec = tvb_get_ntohl (value_buff, 0);
952 ti = proto_tree_add_time (tree, hf_wsp_header_last_modified, header_buff, offset, headerLen, &timeValue);
955 case 0x1F: /* Pragma */
958 proto_tree_add_text (tree, header_buff, 0, headerLen, "Pragma: No-cache");
962 proto_tree_add_text (tree, header_buff, 0, headerLen, "Unsupported Header (0x%02X)", (tvb_get_guint8 (header_buff, 0) & 0x7F));
966 case 0x26: /* Server */
967 ti = proto_tree_add_string (tree, hf_wsp_header_server,header_buff,offset,headerLen,tvb_get_ptr (value_buff, 0, valueLen));
970 case 0x29: /* User-Agent */
971 ti = proto_tree_add_string (tree, hf_wsp_header_user_agent,header_buff,offset,headerLen,tvb_get_ptr (value_buff, 0, valueLen));
975 ti = proto_tree_add_text (tree, header_buff, 0, headerLen, "Unsupported Header (0x%02X)", (tvb_get_guint8 (header_buff, 0) & 0x7F));
981 /* Special case header X-WAP.TOD that is sometimes followed
982 * by a 4-byte date value */
983 if (strncasecmp ("x-wap.tod", tvb_get_ptr (header_buff, 0, headerLen), 9) == 0)
985 if (tvb_reported_length (value_buff) == 4) /* Probably a date value */
987 timeValue.tv_sec = tvb_get_ntohl (value_buff, 0);
988 ti = proto_tree_add_time (tree, hf_wsp_header_x_wap_tod, header_buff, offset, headerLen, &timeValue);
992 ti = proto_tree_add_text (tree, header_buff, 0, headerLen, "%s: %s", tvb_get_ptr (header_buff, 0, headerLen), tvb_get_ptr (value_buff, 0, valueLen));
997 ti = proto_tree_add_text (tree, header_buff, 0, headerLen, "%s: %s", tvb_get_ptr (header_buff, 0, headerLen), tvb_get_ptr (value_buff, 0, valueLen));
1004 get_value_length (tvbuff_t *tvb, guint offset, guint *nextOffset)
1008 guint octet = tvb_get_guint8 (tvb, offset);
1010 if (octet <= 30) /* Short length */
1013 *nextOffset = offset+1;
1015 else if (octet == 31)
1017 value = tvb_get_guintvar (tvb, offset+1, &count);
1018 *nextOffset = offset+1+count;
1022 fprintf (stderr, "dissect_wsp: get_value_length: case NYI\n");
1029 add_content_type (proto_tree *tree, tvbuff_t *tvb, guint offset, guint *contentType)
1031 proto_tree *contentTypeTree;
1032 guint nextOffset = offset;
1033 guint fieldLength = 0;
1034 guint octet = tvb_get_guint8 (tvb, offset);
1035 guint totalSizeOfField = 0;
1039 fieldLength = get_value_length (tvb, offset, &nextOffset);
1040 totalSizeOfField = (nextOffset-offset)+fieldLength;
1042 else if (octet & 0x80)
1045 totalSizeOfField = 1;
1049 fprintf (stderr, "dissect-wsp: Content-type is un-supported\n");
1052 *contentType = (tvb_get_guint8 (tvb, nextOffset) & 0x7F);
1053 contentTypeTree = proto_tree_add_uint (tree, hf_wsp_content_type, tvb, offset, totalSizeOfField, (tvb_get_guint8(tvb,nextOffset++) & 0x7F));
1055 while (nextOffset < (offset+totalSizeOfField))
1058 nextOffset = add_parameter (contentTypeTree, tvb, nextOffset);
1061 return (offset+totalSizeOfField);
1065 add_parameter (proto_tree *tree, tvbuff_t *tvb, guint offset)
1067 guint octet = tvb_get_guint8 (tvb, offset);
1068 if (octet & 0x80) /* Short integer */
1071 octet = octet & 0x7F;
1075 offset = add_parameter_charset (tree, tvb, offset, offset-1);
1079 fprintf (stderr, "dissect-wsp: add_parameter octet=0x%02x\n", octet);
1084 fprintf (stderr, "dissect-wsp: add_parameter octet=0x%02x\n", octet);
1091 add_parameter_charset (proto_tree *tree, tvbuff_t *tvb, guint offset, guint startOffset)
1093 guint octet = tvb_get_guint8 (tvb, offset);
1097 proto_tree_add_item (tree, hf_wsp_parameter_well_known_charset, tvb, startOffset+1, octet, bo_big_endian);
1099 else if (octet & 0x80)
1102 proto_tree_add_uint (tree, hf_wsp_parameter_well_known_charset, tvb, startOffset, offset-startOffset, (octet & 0x7F));
1109 add_post_data (proto_tree *tree, tvbuff_t *tvb, guint contentType)
1112 guint variableStart = 0;
1113 guint variableEnd = 0;
1114 guint valueStart = 0;
1119 ti = proto_tree_add_item (tree, hf_wsp_post_data,tvb,offset,END_OF_FRAME,bo_little_endian);
1121 if (contentType == 0x12) /* URL Encoded data */
1123 /* Iterate through post data */
1124 for (offset = 0; offset < tvb_reported_length (tvb); offset++)
1126 peek = tvb_get_guint8 (tvb, offset);
1129 variableEnd = offset-1;
1130 valueStart = offset+1;
1132 else if (peek == '&')
1134 if (variableEnd > 0)
1136 add_post_variable (ti, tvb, variableStart, variableEnd, valueStart, offset);
1138 variableStart = offset+1;
1145 /* See if there's outstanding data */
1146 if (variableEnd > 0)
1148 add_post_variable (ti, tvb, variableStart, variableEnd, valueStart, offset);
1154 add_post_variable (proto_tree *tree, tvbuff_t *tvb, guint variableStart, guint variableEnd, guint valueStart, guint valueEnd)
1156 int variableLength = variableEnd-variableStart;
1157 int valueLength = 0;
1158 char *variableBuffer;
1161 variableBuffer = g_malloc (variableLength+1);
1162 strncpy (variableBuffer, tvb_get_ptr (tvb, variableStart, variableLength), variableLength+1);
1163 variableBuffer[variableLength+1] = 0;
1167 valueBuffer = g_malloc (1);
1169 valueEnd = valueStart;
1173 valueLength = valueEnd-valueStart;
1174 valueBuffer = g_malloc (valueLength+1);
1175 strncpy (valueBuffer, tvb_get_ptr (tvb, valueStart, valueLength), valueLength);
1176 valueBuffer[valueLength] = 0;
1179 /* Check for variables with no value */
1180 if (valueStart >= tvb_reported_length (tvb))
1182 valueStart = tvb_reported_length (tvb);
1183 valueEnd = valueStart;
1185 valueLength = valueEnd-valueStart;
1187 proto_tree_add_text (tree, tvb, variableStart, valueEnd-variableStart, "%s: %s", variableBuffer, valueBuffer);
1189 g_free (variableBuffer);
1190 g_free (valueBuffer);
1193 /* Register the protocol with Ethereal */
1195 proto_register_wsp(void)
1198 /* Setup list of header fields */
1199 static hf_register_info hf[] = {
1200 { &hf_wsp_header_tid,
1201 { "Transmission ID",
1203 FT_UINT8, BASE_HEX, NULL, 0x00,
1207 { &hf_wsp_header_pdu_type,
1210 FT_UINT8, BASE_HEX, VALS( vals_pdu_type ), 0x00,
1214 { &hf_wsp_version_major,
1215 { "Version (Major)",
1216 "wsp.version.major",
1217 FT_UINT8, BASE_DEC, NULL, 0xF0,
1221 { &hf_wsp_version_minor,
1222 { "Version (Minor)",
1223 "wsp.version.minor",
1224 FT_UINT8, BASE_DEC, NULL, 0x0F,
1228 { &hf_wsp_capability_length,
1229 { "Capability Length",
1230 "wsp.capability.length",
1231 FT_UINT32, BASE_DEC, NULL, 0x00,
1235 { &hf_wsp_header_length,
1237 "wsp.headers-length",
1238 FT_UINT32, BASE_DEC, NULL, 0x00,
1242 { &hf_wsp_capabilities_section,
1245 FT_NONE, BASE_DEC, NULL, 0x00,
1249 { &hf_wsp_headers_section,
1252 FT_NONE, BASE_DEC, NULL, 0x00,
1258 "wsp.headers.header",
1259 FT_NONE, BASE_DEC, NULL, 0x00,
1263 { &hf_wsp_header_uri_len,
1266 FT_UINT32, BASE_DEC, NULL, 0x00,
1270 { &hf_wsp_header_uri,
1273 FT_STRING, BASE_NONE, NULL, 0x00,
1277 { &hf_wsp_server_session_id,
1278 { "Server Session ID",
1279 "wsp.server.session-id",
1280 FT_UINT32, BASE_DEC, NULL, 0x00,
1284 { &hf_wsp_header_status,
1287 FT_UINT8, BASE_HEX, VALS( vals_status ), 0x00,
1291 { &hf_wsp_content_type,
1293 "wsp.content-type.type",
1294 FT_UINT8, BASE_HEX, VALS ( vals_content_types ), 0x00,
1298 { &hf_wsp_parameter_well_known_charset,
1300 "wsp.content-type.parameter.charset",
1301 FT_UINT16, BASE_HEX, VALS ( vals_character_sets ), 0x00,
1305 { &hf_wsp_reply_data,
1308 FT_NONE, BASE_NONE, NULL, 0x00,
1312 { &hf_wsp_header_accept,
1314 "wsp.header.accept",
1315 /*FT_NONE, BASE_DEC, NULL, 0x00,*/
1316 FT_UINT8, BASE_HEX, VALS ( vals_content_types ), 0x00,
1320 { &hf_wsp_header_accept_str,
1322 "wsp.header.accept.string",
1323 FT_STRING, BASE_NONE, NULL, 0x00,
1327 { &hf_wsp_header_accept_charset,
1329 "wsp.header.accept-charset",
1330 FT_UINT16, BASE_HEX, VALS ( vals_character_sets ), 0x00,
1334 { &hf_wsp_header_accept_language,
1335 { "Accept-Language",
1336 "wsp.header.accept-language",
1337 FT_UINT8, BASE_HEX, VALS ( vals_languages ), 0x00,
1341 { &hf_wsp_header_accept_ranges,
1343 "wsp.header.accept-ranges",
1344 FT_UINT8, BASE_HEX, VALS ( vals_accept_ranges ), 0x00,
1348 { &hf_wsp_header_age,
1351 FT_UINT32, BASE_DEC, NULL, 0x00,
1355 { &hf_wsp_header_cache_control,
1357 "wsp.header.cache-control",
1358 FT_UINT8, BASE_HEX, VALS ( vals_cache_control ), 0x00,
1362 { &hf_wsp_header_content_length,
1364 "wsp.header.content-length",
1365 FT_UINT32, BASE_DEC, NULL, 0x00,
1369 { &hf_wsp_header_date,
1372 FT_ABSOLUTE_TIME, BASE_NONE, NULL, 0x0,
1376 { &hf_wsp_header_etag,
1379 /*FT_NONE, BASE_DEC, NULL, 0x00,*/
1380 FT_STRING, BASE_NONE, NULL, 0x00,
1384 { &hf_wsp_header_expires,
1386 "wsp.header.expires",
1387 FT_ABSOLUTE_TIME, BASE_NONE, NULL, 0x0,
1391 { &hf_wsp_header_last_modified,
1393 "wsp.header.last-modified",
1394 FT_ABSOLUTE_TIME, BASE_NONE, NULL, 0x0,
1398 { &hf_wsp_header_location,
1400 "wsp.header.location",
1401 FT_STRING, BASE_NONE, NULL, 0x00,
1405 { &hf_wsp_header_if_modified_since,
1406 { "If-Modified-Since",
1407 "wsp.header.if-modified-since",
1408 FT_ABSOLUTE_TIME, BASE_NONE, NULL, 0x0,
1412 { &hf_wsp_header_server,
1414 "wsp.header.server",
1415 /*FT_NONE, BASE_DEC, NULL, 0x00,*/
1416 FT_STRING, BASE_NONE, NULL, 0x00,
1420 { &hf_wsp_header_user_agent,
1422 "wsp.header.user-agent",
1423 /*FT_NONE, BASE_DEC, NULL, 0x00,*/
1424 FT_STRING, BASE_NONE, NULL, 0x00,
1428 { &hf_wsp_header_application_header,
1429 { "Application Header",
1430 "wsp.header.application-header",
1431 FT_STRING, BASE_NONE, NULL, 0x00,
1432 "Application Header"
1435 { &hf_wsp_header_application_value,
1436 { "Application Header Value",
1437 "wsp.header.application-header.value",
1438 FT_STRING, BASE_NONE, NULL, 0x00,
1439 "Application Header Value"
1442 { &hf_wsp_header_x_wap_tod,
1444 "wsp.header.x_wap_tod",
1445 FT_ABSOLUTE_TIME, BASE_NONE, NULL, 0x0,
1449 { &hf_wsp_post_data,
1452 FT_NONE, BASE_NONE, NULL, 0x00,
1458 /* Setup protocol subtree array */
1459 static gint *ett[] = {
1467 /* Register the protocol name and description */
1468 proto_wsp = proto_register_protocol(
1469 "Wireless Session Protocol", /* protocol name for use by ethereal */
1470 "WSP", /* short version of name */
1471 "wap-wsp" /* Abbreviated protocol name, should Match IANA
1472 < URL:http://www.isi.edu/in-notes/iana/assignments/port-numbers/ >
1476 /* Required function calls to register the header fields and subtrees used */
1477 proto_register_field_array(proto_wsp, hf, array_length(hf));
1478 proto_register_subtree_array(ett, array_length(ett));
1480 register_dissector("wsp", dissect_wsp);
1484 proto_reg_handoff_wsp(void)
1486 /* Only connection-less WSP has no previous handler */
1487 dissector_add("udp.port", UDP_PORT_WSP, dissect_wsp);
1488 /* dissector_add("udp.port", UDP_PORT_WTP_WSP, dissect_wsp); */
1489 /* dissector_add("udp.port", UDP_PORT_WTLS_WSP, dissect_wsp); */
1490 /* dissector_add("udp.port", UDP_PORT_WTLS_WTP_WSP, dissect_wsp); */