MSWSP: fix dissect_mswsp_smb()
[wireshark-wip.git] / epan / dissectors / packet-mmse.c
blob45550855b95d3d5c32153c6efb028e737fe3eda0
1 /* packet-mmse.c
2 * Routines for MMS Message Encapsulation dissection
3 * Copyright 2001, Tom Uijldert <tom.uijldert@cmg.nl>
4 * Copyright 2004, Olivier Biot
6 * $Id$
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 1998 Gerald Combs
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 * ----------
27 * Dissector of an encoded Multimedia message PDU, as defined by the WAPForum
28 * (http://www.wapforum.org) in "WAP-209-MMSEncapsulation-20020105-a".
29 * Subsequent releases of MMS are in control of the Open Mobile Alliance (OMA):
30 * Dissection of MMS 1.1 as in OMA-MMS-ENC-v1.1.
31 * Dissection of MMS 1.2 as in OMA-MMS-ENC-v1.2 (not finished yet).
34 /* This file has been edited with 8-space tabs and 4-space indentation */
36 #include "config.h"
38 #include <string.h>
40 #include <glib.h>
42 #include <epan/packet.h>
43 #include <epan/to_str.h>
44 #include <epan/strutil.h>
45 #include <epan/wmem/wmem.h>
46 #include "packet-wap.h"
47 #include "packet-wsp.h"
48 /* #include "packet-mmse.h" */ /* We autoregister */
50 #define MM_QUOTE 0x7F /* Quoted string */
52 #define MMS_CONTENT_TYPE 0x3E /* WINA-value for mms-message */
54 /* General-purpose debug logger.
55 * Requires double parentheses because of variable arguments of printf().
57 * Enable debug logging for MMSE by defining AM_CFLAGS
58 * so that it contains "-DDEBUG_mmse"
60 #ifdef DEBUG_mmse
61 #define DebugLog(x) \
62 g_print("%s:%u: ", __FILE__, __LINE__); \
63 g_print x
64 #else
65 #define DebugLog(x) ;
66 #endif
69 * Forward declarations
71 static void dissect_mmse_standalone(tvbuff_t *, packet_info *, proto_tree *);
72 static void dissect_mmse(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
73 guint8 pdut, const char *message_type);
76 * Header field values
78 /* MMS 1.0 */
79 #define MM_BCC_HDR 0x81 /* Bcc */
80 #define MM_CC_HDR 0x82 /* Cc */
81 #define MM_CLOCATION_HDR 0x83 /* X-Mms-Content-Location */
82 #define MM_CTYPE_HDR 0x84 /* Content-Type */
83 #define MM_DATE_HDR 0x85 /* Date */
84 #define MM_DREPORT_HDR 0x86 /* X-Mms-Delivery-Report */
85 #define MM_DTIME_HDR 0x87 /* X-Mms-Delivery-Time */
86 #define MM_EXPIRY_HDR 0x88 /* X-Mms-Expiry */
87 #define MM_FROM_HDR 0x89 /* From */
88 #define MM_MCLASS_HDR 0x8A /* X-Mms-Message-Class */
89 #define MM_MID_HDR 0x8B /* Message-ID */
90 #define MM_MTYPE_HDR 0x8C /* X-Mms-Message-Type */
91 #define MM_VERSION_HDR 0x8D /* X-Mms-MMS-Version */
92 #define MM_MSIZE_HDR 0x8E /* X-Mms-Message-Size */
93 #define MM_PRIORITY_HDR 0x8F /* X-Mms-Priority */
94 #define MM_RREPLY_HDR 0x90 /* X-Mms-Read-Reply */
95 #define MM_RALLOWED_HDR 0x91 /* X-Mms-Report-Allowed */
96 #define MM_RSTATUS_HDR 0x92 /* X-Mms-Response-Status */
97 #define MM_RTEXT_HDR 0x93 /* X-Mms-Response-Text */
98 #define MM_SVISIBILITY_HDR 0x94 /* X-Mms-Sender-Visibility */
99 #define MM_STATUS_HDR 0x95 /* X-Mms-Status */
100 #define MM_SUBJECT_HDR 0x96 /* Subject */
101 #define MM_TO_HDR 0x97 /* To */
102 #define MM_TID_HDR 0x98 /* X-Mms-Transaction-Id */
103 /* MMS 1.1 */
104 #define MM_RETRIEVE_STATUS_HDR 0x99 /* X-Mms-Retrieve-Status */
105 #define MM_RETRIEVE_TEXT_HDR 0x9A /* X-Mms-Retrieve-Text */
106 #define MM_READ_STATUS_HDR 0x9B /* X-Mms-Read-Status */
107 #define MM_REPLY_CHARGING_HDR 0x9C /* X-Mms-Reply-Charging */
108 #define MM_REPLY_CHARGING_DEADLINE_HDR \
109 0x9D /* X-Mms-Reply-Charging-Deadline*/
110 #define MM_REPLY_CHARGING_ID_HDR \
111 0x9E /* X-Mms-Reply-Charging-ID */
112 #define MM_REPLY_CHARGING_SIZE_HDR \
113 0x9F /* X-Mms-Reply-Charging-Size */
114 #define MM_PREV_SENT_BY_HDR 0xA0 /* X-Mms-Previously-Sent-By */
115 #define MM_PREV_SENT_DATE_HDR 0xA1 /* X-Mms-Previously-Sent-Date */
116 /* MMS 1.2 */
117 #define MM_STORE_HDR 0xA2 /* X-Mms-Store */
118 #define MM_MM_STATE_HDR 0xA3 /* X-Mms-MM-State */
119 #define MM_MM_FLAGS_HDR 0xA4 /* X-Mms-MM-Flags */
120 #define MM_STORE_STATUS_HDR 0xA5 /* X-Mms-Store-Status */
121 #define MM_STORE_STATUS_TEXT_HDR \
122 0xA6 /* X-Mms-Store-Status-Text */
123 #define MM_STORED_HDR 0xA7 /* X-Mms-Stored */
124 #define MM_ATTRIBUTES_HDR 0xA8 /* X-Mms-Attributes */
125 #define MM_TOTALS_HDR 0xA9 /* X-Mms-Totals */
126 #define MM_MBOX_TOTALS_HDR 0xAA /* X-Mms-Mbox-Totals */
127 #define MM_QUOTAS_HDR 0xAB /* X-Mms-Quotas */
128 #define MM_MBOX_QUOTAS_HDR 0xAC /* X-Mms-Mbox-Quotas */
129 #define MM_MBOX_MSG_COUNT_HDR 0xAD /* X-Mms-Message-Count */
130 #define MM_CONTENT_HDR 0xAE /* Content */
131 #define MM_START_HDR 0xAF /* X-Mms-Start */
132 #define MM_ADDITIONAL_HDR 0xB0 /* Additional-headers */
133 #define MM_DISTRIBUION_IND_HDR 0xB1 /* X-Mms-Distribution-Indcator */
134 #define MM_ELEMENT_DESCR_HDR 0xB2 /* X-Mms-Element-Descriptor */
135 #define MM_LIMIT_HDR 0xB3 /* X-Mms-Limit */
137 static const value_string vals_mm_header_names[] = {
138 /* MMS 1.0 */
139 { MM_BCC_HDR, "Bcc" },
140 { MM_CC_HDR, "Cc" },
141 { MM_CLOCATION_HDR, "X-Mms-Content-Location" },
142 { MM_CTYPE_HDR, "X-Mms-Content-Type" },
143 { MM_DATE_HDR, "Date" },
144 { MM_DREPORT_HDR, "X-Mms-Delivery-Report" },
145 { MM_DTIME_HDR, "X-Mms-Delivery-Time" },
146 { MM_EXPIRY_HDR, "X-Mms-Expiry" },
147 { MM_FROM_HDR, "From" },
148 { MM_MCLASS_HDR, "X-Mms-Message-Class" },
149 { MM_MID_HDR, "Message-ID" },
150 { MM_MTYPE_HDR, "X-Mms-Message-Type" },
151 { MM_VERSION_HDR, "X-Mms-MMS-Version" },
152 { MM_MSIZE_HDR, "X-Mms-Message-Size" },
153 { MM_PRIORITY_HDR, "X-Mms-Priority" },
154 { MM_RREPLY_HDR, "X-Mms-Read-Reply" },
155 { MM_RALLOWED_HDR, "X-Mms-Report-Allowed" },
156 { MM_RSTATUS_HDR, "X-Mms-Response-Status" },
157 { MM_RTEXT_HDR, "X-Mms-Response-Text" },
158 { MM_SVISIBILITY_HDR, "X-Mms-Sender-Visibility" },
159 { MM_STATUS_HDR, "X-Mms-Status" },
160 { MM_SUBJECT_HDR, "Subject" },
161 { MM_TO_HDR, "To" },
162 { MM_TID_HDR, "X-Mms-Transaction-Id" },
163 /* MMS 1.1 */
164 { MM_RETRIEVE_STATUS_HDR, "X-Mms-Retrieve-Status" },
165 { MM_RETRIEVE_TEXT_HDR, "X-Mms-Retrieve-Text" },
166 { MM_READ_STATUS_HDR, "X-Mms-Read-Status" },
167 { MM_REPLY_CHARGING_HDR, "X-Mms-Reply-Charging" },
168 { MM_REPLY_CHARGING_DEADLINE_HDR,
169 "X-Mms-Reply-Charging-Deadline" },
170 { MM_REPLY_CHARGING_ID_HDR, "X-Mms-Reply-Charging-ID" },
171 { MM_REPLY_CHARGING_SIZE_HDR, "X-Mms-Reply-Charging-Size" },
172 { MM_PREV_SENT_BY_HDR, "X-Mms-Previously-Sent-By" },
173 { MM_PREV_SENT_DATE_HDR, "X-Mms-Previously-Sent-Date" },
174 /* MMS 1.2 */
175 { MM_STORE_HDR, "X-Mms-Store" },
176 { MM_MM_STATE_HDR, "X-Mms-MM-State" },
177 { MM_MM_FLAGS_HDR, "X-Mms-MM-Flags" },
178 { MM_STORE_STATUS_HDR, "X-Mms-Store-Status" },
179 { MM_STORE_STATUS_TEXT_HDR, "X-Mms-Store-Status-Text" },
180 { MM_STORED_HDR, "X-Mms-Stored" },
181 { MM_ATTRIBUTES_HDR, "X-Mms-Attributes" },
182 { MM_TOTALS_HDR, "X-Mms-Totals" },
183 { MM_MBOX_TOTALS_HDR, "X-Mms-Mbox-Totals" },
184 { MM_QUOTAS_HDR, "X-Mms-Quotas" },
185 { MM_MBOX_QUOTAS_HDR, "X-Mms-Mbox-Quotas" },
186 { MM_MBOX_MSG_COUNT_HDR, "X-Mms-Message-Count" },
187 { MM_CONTENT_HDR, "Content" },
188 { MM_START_HDR, "X-Mms-Start" },
189 { MM_ADDITIONAL_HDR, "Additional-headers" },
190 { MM_DISTRIBUION_IND_HDR, "X-Mms-Distribution-Indcator" },
191 { MM_ELEMENT_DESCR_HDR, "X-Mms-Element-Descriptor" },
192 { MM_LIMIT_HDR, "X-Mms-Limit" },
194 { 0x00, NULL },
197 * Initialize the protocol and registered fields
199 static int proto_mmse = -1;
201 static int hf_mmse_message_type = -1;
202 static int hf_mmse_transaction_id = -1;
203 static int hf_mmse_mms_version = -1;
204 static int hf_mmse_bcc = -1;
205 static int hf_mmse_cc = -1;
206 static int hf_mmse_content_location = -1;
207 static int hf_mmse_date = -1;
208 static int hf_mmse_delivery_report = -1;
209 static int hf_mmse_delivery_time_abs = -1;
210 static int hf_mmse_delivery_time_rel = -1;
211 static int hf_mmse_expiry_abs = -1;
212 static int hf_mmse_expiry_rel = -1;
213 static int hf_mmse_from = -1;
214 static int hf_mmse_message_class_id = -1;
215 static int hf_mmse_message_class_str = -1;
216 static int hf_mmse_message_id = -1;
217 static int hf_mmse_message_size = -1;
218 static int hf_mmse_priority = -1;
219 static int hf_mmse_read_reply = -1;
220 static int hf_mmse_report_allowed = -1;
221 static int hf_mmse_response_status = -1;
222 static int hf_mmse_response_text = -1;
223 static int hf_mmse_sender_visibility = -1;
224 static int hf_mmse_status = -1;
225 static int hf_mmse_subject = -1;
226 static int hf_mmse_to = -1;
227 /* static int hf_mmse_content_type = -1; */
228 static int hf_mmse_ffheader = -1;
229 /* MMSE 1.1 */
230 static int hf_mmse_read_report = -1;
231 static int hf_mmse_retrieve_status = -1;
232 static int hf_mmse_retrieve_text = -1;
233 static int hf_mmse_read_status = -1;
234 static int hf_mmse_reply_charging = -1;
235 static int hf_mmse_reply_charging_deadline_abs = -1;
236 static int hf_mmse_reply_charging_deadline_rel = -1;
237 static int hf_mmse_reply_charging_id = -1;
238 static int hf_mmse_reply_charging_size = -1;
239 static int hf_mmse_prev_sent_by = -1;
240 static int hf_mmse_prev_sent_by_fwd_count = -1;
241 static int hf_mmse_prev_sent_by_address = -1;
242 static int hf_mmse_prev_sent_date = -1;
243 static int hf_mmse_prev_sent_date_fwd_count = -1;
244 static int hf_mmse_prev_sent_date_date = -1;
247 * Initialize the subtree pointers
249 static gint ett_mmse = -1;
250 static gint ett_mmse_hdr_details = -1;
253 * Valuestrings for PDU types
255 /* MMS 1.0 */
256 #define PDU_M_SEND_REQ 0x80
257 #define PDU_M_SEND_CONF 0x81
258 #define PDU_M_NOTIFICATION_IND 0x82
259 #define PDU_M_NOTIFYRESP_IND 0x83
260 #define PDU_M_RETRIEVE_CONF 0x84
261 #define PDU_M_ACKNOWLEDGE_IND 0x85
262 #define PDU_M_DELIVERY_IND 0x86
263 /* MMS 1.1 */
264 #define PDU_M_READ_REC_IND 0x87
265 #define PDU_M_READ_ORIG_IND 0x88
266 #define PDU_M_FORWARD_REQ 0x89
267 #define PDU_M_FORWARD_CONF 0x8A
268 /* MMS 1.2 */
269 #define PDU_M_MBOX_STORE_REQ 0x8B
270 #define PDU_M_MBOX_STORE_CONF 0x8C
271 #define PDU_M_MBOX_VIEW_REQ 0x8D
272 #define PDU_M_MBOX_VIEW_CONF 0x8E
273 #define PDU_M_MBOX_UPLOAD_REQ 0x8F
274 #define PDU_M_MBOX_UPLOAD_CONF 0x90
275 #define PDU_M_MBOX_DELETE_REQ 0x91
276 #define PDU_M_MBOX_DELETE_CONF 0x92
277 #define PDU_M_MBOX_DESCR 0x93
279 #define pdu_has_content(pdut) \
280 ( ((pdut) == PDU_M_SEND_REQ) \
281 || ((pdut) == PDU_M_DELIVERY_IND) \
282 || ((pdut) == PDU_M_RETRIEVE_CONF) \
283 || ((pdut) == PDU_M_MBOX_VIEW_CONF) \
284 || ((pdut) == PDU_M_MBOX_DESCR) \
285 || ((pdut) == PDU_M_MBOX_UPLOAD_REQ) \
288 static const value_string vals_message_type[] = {
289 /* MMS 1.0 */
290 { PDU_M_SEND_REQ, "m-send-req" },
291 { PDU_M_SEND_CONF, "m-send-conf" },
292 { PDU_M_NOTIFICATION_IND, "m-notification-ind" },
293 { PDU_M_NOTIFYRESP_IND, "m-notifyresp-ind" },
294 { PDU_M_RETRIEVE_CONF, "m-retrieve-conf" },
295 { PDU_M_ACKNOWLEDGE_IND, "m-acknowledge-ind" },
296 { PDU_M_DELIVERY_IND, "m-delivery-ind" },
297 /* MMS 1.1 */
298 { PDU_M_READ_REC_IND, "m-read-rec-ind" },
299 { PDU_M_READ_ORIG_IND, "m-read-orig-ind" },
300 { PDU_M_FORWARD_REQ, "m-forward-req" },
301 { PDU_M_FORWARD_CONF, "m-forward-conf" },
302 /* MMS 1.2 */
303 { PDU_M_MBOX_STORE_REQ, "m-mbox-store-req" },
304 { PDU_M_MBOX_STORE_CONF, "m-mbox-store-conf" },
305 { PDU_M_MBOX_VIEW_REQ, "m-mbox-view-req" },
306 { PDU_M_MBOX_VIEW_CONF, "m-mbox-view-conf" },
307 { PDU_M_MBOX_UPLOAD_REQ, "m-mbox-upload-req" },
308 { PDU_M_MBOX_UPLOAD_CONF, "m-mbox-upload-conf" },
309 { PDU_M_MBOX_DELETE_REQ, "m-mbox-delete-req" },
310 { PDU_M_MBOX_DELETE_CONF, "m-mbox-delete-conf" },
311 { PDU_M_MBOX_DESCR, "m-mbox-descr" },
312 { 0x00, NULL },
315 static const value_string vals_yes_no[] = {
316 { 0x80, "Yes" },
317 { 0x81, "No" },
318 { 0x00, NULL },
321 static const value_string vals_message_class[] = {
322 { 0x80, "Personal" },
323 { 0x81, "Advertisement" },
324 { 0x82, "Informational" },
325 { 0x83, "Auto" },
326 { 0x00, NULL },
329 static const value_string vals_priority[] = {
330 { 0x80, "Low" },
331 { 0x81, "Normal" },
332 { 0x82, "High" },
333 { 0x00, NULL },
336 static const value_string vals_response_status[] = {
337 /* MMS 1.0 - obsolete as from MMS 1.1 */
338 { 0x80, "Ok" },
339 { 0x81, "Unspecified" },
340 { 0x82, "Service denied" },
341 { 0x83, "Message format corrupt" },
342 { 0x84, "Sending address unresolved" },
343 { 0x85, "Message not found" },
344 { 0x86, "Network problem" },
345 { 0x87, "Content not accepted" },
346 { 0x88, "Unsupported message" },
349 * Transient errors
351 /* MMS 1.1 */
352 { 0xC0, "Transient failure" },
353 { 0xC1, "Transient: Sending address unresolved" },
354 { 0xC2, "Transient: Message not found" },
355 { 0xC3, "Transient: Network problem" },
356 /* MMS 1.2 */
357 { 0xC4, "Transient: Partial success" },
360 * Permanent errors
362 /* MMS 1.1 */
363 { 0xE0, "Permanent failure" },
364 { 0xE1, "Permanent: Service denied" },
365 { 0xE2, "Permanent: Message format corrupt" },
366 { 0xE3, "Permanent: Sending address unresolved" },
367 { 0xE4, "Permanent: Message not found" },
368 { 0xE5, "Permanent: Content not accepted" },
369 { 0xE6, "Permanent: Reply charging limitations not met" },
370 { 0xE7, "Permanent: Reply charging request not accepted" },
371 { 0xE8, "Permanent: Reply charging forwarding denied" },
372 { 0xE9, "Permanent: Reply charging not supported" },
373 /* MMS 1.2 */
374 { 0xEA, "Permanent: Address hiding not supported" },
376 { 0x00, NULL },
379 static const value_string vals_sender_visibility[] = {
380 { 0x80, "Hide" },
381 { 0x81, "Show" },
382 { 0x00, NULL },
385 static const value_string vals_message_status[] = {
386 /* MMS 1.0 */
387 { 0x80, "Expired" },
388 { 0x81, "Retrieved" },
389 { 0x82, "Rejected" },
390 { 0x83, "Deferred" },
391 { 0x84, "Unrecognized" },
392 /* MMS 1.1 */
393 { 0x85, "Indeterminate" },
394 { 0x86, "Forwarded" },
395 /* MMS 1.2 */
396 { 0x87, "Unreachable" },
398 { 0x00, NULL },
401 static const value_string vals_retrieve_status[] = {
403 * Transient errors
405 /* MMS 1.1 */
406 { 0xC0, "Transient failure" },
407 { 0xC1, "Transient: Message not found" },
408 { 0xC2, "Transient: Network problem" },
411 * Permanent errors
413 /* MMS 1.1 */
414 { 0xE0, "Permanent failure" },
415 { 0xE1, "Permanent: Service denied" },
416 { 0xE2, "Permanent: Message not found" },
417 { 0xE3, "Permanent: Content unsupported" },
419 { 0x00, NULL },
422 static const value_string vals_read_status[] = {
423 { 0x80, "Read" },
424 { 0x81, "Deleted without being read" },
426 { 0x00, NULL },
429 static const value_string vals_reply_charging[] = {
430 { 0x80, "Requested" },
431 { 0x81, "Requested text only" },
432 { 0x82, "Accepted" },
433 { 0x83, "Accepted text only" },
435 { 0x00, NULL },
439 * Decodes a Text-string from the protocol data
440 * Text-string = [Quote] *TEXT End-of-string
441 * Quote = <Octet 127>
442 * End-of-string = <Octet 0>
444 * \todo Shouldn't we be sharing this with WSP (packet-wap.c)?
446 * \param tvb The buffer with PDU-data
447 * \param offset Offset within that buffer
448 * \param strval Pointer to variable into which to put pointer to
449 * buffer allocated to hold the text; must be freed
450 * when no longer used
452 * \return The length in bytes of the entire field
454 static guint
455 get_text_string(tvbuff_t *tvb, guint offset, const char **strval)
457 guint len;
459 DebugLog(("get_text_string(tvb = %p, offset = %u, **strval) - start\n",
460 tvb, offset));
461 len = tvb_strsize(tvb, offset);
462 DebugLog((" [1] tvb_strsize(tvb, offset) == %u\n", len));
463 if (tvb_get_guint8(tvb, offset) == MM_QUOTE)
464 *strval = (const char *)tvb_memdup(wmem_packet_scope(), tvb, offset+1, len-1);
465 else
466 *strval = (const char *)tvb_memdup(wmem_packet_scope(), tvb, offset, len);
467 DebugLog((" [3] Return(len) == %u\n", len));
468 return len;
472 * Decodes a Value-length from the protocol data.
473 * Value-length = Short-length | (Length-quote Length)
474 * Short-length = <Any octet 0-30>
475 * Length-quote = <Octet 31>
476 * Length = Uintvar-integer
478 * \todo Shouldn't we be sharing this with WSP (packet-wap.c)?
480 * \param tvb The buffer with PDU-data
481 * \param offset Offset within that buffer
482 * \param byte_count Returns the length in bytes of
483 * the "Value-length" field.
485 * \return The actual value of "Value-length"
487 static guint
488 get_value_length(tvbuff_t *tvb, guint offset, guint *byte_count)
490 guint field;
492 field = tvb_get_guint8(tvb, offset++);
493 if (field < 31)
494 *byte_count = 1;
495 else { /* Must be 31 so, Uintvar follows */
496 field = tvb_get_guintvar(tvb, offset, byte_count);
497 (*byte_count)++;
499 return field;
503 * Decodes an Encoded-string-value from the protocol data
504 * Encoded-string-value = Text-string | Value-length Char-set Text-string
506 * \param tvb The buffer with PDU-data
507 * \param offset Offset within that buffer
508 * \param strval Pointer to variable into which to put pointer to
509 * buffer allocated to hold the text; must be freed
510 * when no longer used
512 * \return The length in bytes of the entire field
514 static guint
515 get_encoded_strval(tvbuff_t *tvb, guint offset, const char **strval)
517 guint field;
518 guint length;
519 guint count;
521 field = tvb_get_guint8(tvb, offset);
523 if (field < 32) {
524 length = get_value_length(tvb, offset, &count);
525 if (length < 2) {
526 *strval = "";
527 } else {
528 /* \todo Something with "Char-set", skip for now */
529 *strval = (char *)tvb_get_string(wmem_packet_scope(), tvb, offset + count + 1, length - 1);
531 return count + length;
532 } else
533 return get_text_string(tvb, offset, strval);
537 * Decodes a Long-integer from the protocol data
538 * Long-integer = Short-length Multi-octet-integer
539 * Short-length = <Any octet 0-30>
540 * Multi-octet-integer = 1*30OCTET
542 * \todo Shouldn't we be sharing this with WSP (packet-wap.c)?
544 * \param tvb The buffer with PDU-data
545 * \param offset Offset within that buffer
546 * \param byte_count Returns the length in bytes of the field
548 * \return The value of the Long-integer
550 * \note A maximum of 4-byte integers will be handled.
552 static guint
553 get_long_integer(tvbuff_t *tvb, guint offset, guint *byte_count)
555 guint val;
557 *byte_count = tvb_get_guint8(tvb, offset++);
558 switch (*byte_count) {
559 case 1:
560 val = tvb_get_guint8(tvb, offset);
561 break;
562 case 2:
563 val = tvb_get_ntohs(tvb, offset);
564 break;
565 case 3:
566 val = tvb_get_ntoh24(tvb, offset);
567 break;
568 case 4:
569 val = tvb_get_ntohl(tvb, offset);
570 break;
571 default:
572 val = 0;
573 break;
575 (*byte_count)++;
576 return val;
580 * Decodes an Integer-value from the protocol data
581 * Integer-value = Short-integer | Long-integer
582 * Short-integer = OCTET
583 * Long-integer = Short-length Multi-octet-integer
584 * Short-length = <Any octet 0-30>
585 * Multi-octet-integer = 1*30OCTET
587 * \todo Shouldn't we be sharing this with WSP (packet-wap.c)?
589 * \param tvb The buffer with PDU-data
590 * \param offset Offset within that buffer
591 * \param byte_count Returns the length in bytes of the field
593 * \return The value of the Long-integer
595 * \note A maximum of 4-byte integers will be handled.
597 static guint
598 get_integer_value(tvbuff_t *tvb, guint offset, guint *byte_count)
600 guint val;
601 guint8 peek;
603 peek = tvb_get_guint8(tvb, offset++);
604 if (peek & 0x80) {
605 val = peek & 0x7F;
606 *byte_count = 1;
607 return val;
608 } else {
609 *byte_count = peek;
610 switch (peek) {
611 case 1:
612 val = tvb_get_guint8(tvb, offset);
613 break;
614 case 2:
615 val = tvb_get_ntohs(tvb, offset);
616 break;
617 case 3:
618 val = tvb_get_ntoh24(tvb, offset);
619 break;
620 case 4:
621 val = tvb_get_ntohl(tvb, offset);
622 break;
623 default:
624 val = 0;
625 break;
628 (*byte_count)++;
629 return val;
632 /* Code to actually dissect the packets */
633 static gboolean
634 dissect_mmse_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
636 guint8 pdut;
638 DebugLog(("dissect_mmse_heur()\n"));
640 * Check if data makes sense for it to be dissected as MMSE: Message-type
641 * field must make sense and followed by either Transaction-Id
642 * or MMS-Version header
644 if (tvb_get_guint8(tvb, 0) != MM_MTYPE_HDR)
645 return FALSE;
646 pdut = tvb_get_guint8(tvb, 1);
647 if (try_val_to_str(pdut, vals_message_type) == NULL)
648 return FALSE;
649 if ((tvb_get_guint8(tvb, 2) != MM_TID_HDR) &&
650 (tvb_get_guint8(tvb, 2) != MM_VERSION_HDR))
651 return FALSE;
652 dissect_mmse_standalone(tvb, pinfo, tree);
653 return TRUE;
656 static void
657 dissect_mmse_standalone(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
659 guint8 pdut;
660 const char *message_type;
662 DebugLog(("dissect_mmse_standalone() - START (Packet %u)\n",
663 pinfo->fd->num));
665 pdut = tvb_get_guint8(tvb, 1);
666 message_type = val_to_str(pdut, vals_message_type, "Unknown type %u");
668 /* Make entries in Protocol column and Info column on summary display */
669 col_set_str(pinfo->cinfo, COL_PROTOCOL, "MMSE");
671 col_add_fstr(pinfo->cinfo, COL_INFO, "MMS %s", message_type);
673 dissect_mmse(tvb, pinfo, tree, pdut, message_type);
676 static void
677 dissect_mmse_encapsulated(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
679 guint8 pdut;
680 const char *message_type;
682 DebugLog(("dissect_mmse_encapsulated() - START (Packet %u)\n",
683 pinfo->fd->num));
685 pdut = tvb_get_guint8(tvb, 1);
686 message_type = val_to_str(pdut, vals_message_type, "Unknown type %u");
688 /* Make entries in Info column on summary display */
689 col_append_sep_fstr(pinfo->cinfo, COL_INFO, " ", "(MMS %s)",
690 message_type);
692 dissect_mmse(tvb, pinfo, tree, pdut, message_type);
695 static void
696 dissect_mmse(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint8 pdut,
697 const char *message_type)
699 guint offset;
700 guint8 field = 0;
701 const char *strval;
702 guint length;
703 guint count;
704 guint8 version = 0x80; /* Default to MMSE 1.0 */
706 /* Set up structures needed to add the protocol subtree and manage it */
707 proto_item *ti = NULL;
708 proto_tree *mmse_tree = NULL;
710 DebugLog(("dissect_mmse() - START (Packet %u)\n", pinfo->fd->num));
712 /* If tree == NULL then we are only interested in protocol dissection
713 * up to reassembly and handoff to subdissectors if applicable; the
714 * columns must be set appropriately too.
715 * If tree != NULL then we also want to display the protocol tree
716 * with its fields.
718 * In the interest of speed, skip protocol tree item generation
719 * if tree is NULL.
721 if (tree) {
722 DebugLog(("tree != NULL\n"));
724 ti = proto_tree_add_item(tree, proto_mmse, tvb, 0, -1, ENC_NA);
725 proto_item_append_text(ti, ", Type: %s", message_type);
726 /* create display subtree for the protocol */
727 mmse_tree = proto_item_add_subtree(ti, ett_mmse);
729 /* Report PDU-type */
730 proto_tree_add_uint(mmse_tree, hf_mmse_message_type, tvb, 0, 2, pdut);
733 offset = 2; /* Skip Message-Type */
736 * Cycle through MMS-headers
738 * NOTE - some PDUs may convey content which can be handed off
739 * to subdissectors.
741 if (tree || pdu_has_content(pdut)) {
742 while ((offset < tvb_reported_length(tvb)) &&
743 (field = tvb_get_guint8(tvb, offset++)) != MM_CTYPE_HDR)
745 DebugLog(("\tField = 0x%02X (offset = %u): %s\n",
746 field, offset,
747 val_to_str(field, vals_mm_header_names,
748 "Unknown MMS header 0x%02X")));
749 switch (field)
751 case MM_TID_HDR: /* Text-string */
752 length = get_text_string(tvb, offset, &strval);
753 if (tree) {
754 proto_tree_add_string(mmse_tree, hf_mmse_transaction_id,
755 tvb, offset - 1, length + 1,strval);
757 offset += length;
758 break;
759 case MM_VERSION_HDR: /* nibble-Major/nibble-minor*/
760 version = tvb_get_guint8(tvb, offset++);
761 if (tree) {
762 guint8 major, minor;
763 char *vers_string;
765 major = (version & 0x70) >> 4;
766 minor = version & 0x0F;
767 if (minor == 0x0F)
768 vers_string = wmem_strdup_printf(wmem_packet_scope(), "%u", major);
769 else
770 vers_string = wmem_strdup_printf(wmem_packet_scope(), "%u.%u", major, minor);
771 proto_tree_add_string(mmse_tree, hf_mmse_mms_version,
772 tvb, offset - 2, 2, vers_string);
774 break;
775 case MM_BCC_HDR: /* Encoded-string-value */
776 length = get_encoded_strval(tvb, offset, &strval);
777 if (tree) {
778 proto_tree_add_string(mmse_tree, hf_mmse_bcc, tvb,
779 offset - 1, length + 1, strval);
781 offset += length;
782 break;
783 case MM_CC_HDR: /* Encoded-string-value */
784 length = get_encoded_strval(tvb, offset, &strval);
785 if (tree) {
786 proto_tree_add_string(mmse_tree, hf_mmse_cc, tvb,
787 offset - 1, length + 1, strval);
789 offset += length;
790 break;
791 case MM_CLOCATION_HDR: /* Uri-value */
792 if (pdut == PDU_M_MBOX_DELETE_CONF) {
793 /* General form with length */
794 length = tvb_get_guint8(tvb, offset);
795 if (length == 0x1F) {
796 guint length_len = 0;
797 length = tvb_get_guintvar(tvb, offset + 1,
798 &length_len);
799 length += 1 + length_len;
800 } else {
801 length += 1;
803 if (tree) {
804 tvb_ensure_bytes_exist(tvb, offset - 1, length + 1);
805 proto_tree_add_string(mmse_tree,
806 hf_mmse_content_location,
807 tvb, offset - 1, length + 1,
808 "<Undecoded value for m-mbox-delete-conf>");
810 } else {
811 length = get_text_string(tvb, offset, &strval);
812 if (tree) {
813 proto_tree_add_string(mmse_tree,
814 hf_mmse_content_location,
815 tvb, offset - 1, length + 1, strval);
818 offset += length;
819 break;
820 case MM_DATE_HDR: /* Long-integer */
822 guint tval;
823 nstime_t tmptime;
825 tval = get_long_integer(tvb, offset, &count);
826 tmptime.secs = tval;
827 tmptime.nsecs = 0;
828 if (tree) {
829 tvb_ensure_bytes_exist(tvb, offset - 1, count + 1);
830 proto_tree_add_time(mmse_tree, hf_mmse_date, tvb,
831 offset - 1, count + 1, &tmptime);
834 offset += count;
835 break;
836 case MM_DREPORT_HDR: /* Yes|No */
837 field = tvb_get_guint8(tvb, offset++);
838 if (tree) {
839 proto_tree_add_uint(mmse_tree,
840 hf_mmse_delivery_report,
841 tvb, offset - 2, 2, field);
843 break;
844 case MM_DTIME_HDR:
846 * Value-length(Absolute-token Date-value|
847 * Relative-token Delta-seconds-value)
849 length = get_value_length(tvb, offset, &count);
850 field = tvb_get_guint8(tvb, offset + count);
851 if (tree) {
852 guint tval;
853 nstime_t tmptime;
854 guint cnt;
856 tval = get_long_integer(tvb, offset + count + 1, &cnt);
857 tmptime.secs = tval;
858 tmptime.nsecs = 0;
860 tvb_ensure_bytes_exist(tvb, offset - 1, length + count + 1);
861 if (field == 0x80)
862 proto_tree_add_time(mmse_tree,
863 hf_mmse_delivery_time_abs,
864 tvb, offset - 1,
865 length + count + 1, &tmptime);
866 else
867 proto_tree_add_time(mmse_tree,
868 hf_mmse_delivery_time_rel,
869 tvb, offset - 1,
870 length + count + 1, &tmptime);
872 offset += length + count;
873 break;
874 case MM_EXPIRY_HDR:
876 * Value-length(Absolute-token Date-value|
877 * Relative-token Delta-seconds-value)
879 length = get_value_length(tvb, offset, &count);
880 field = tvb_get_guint8(tvb, offset + count);
881 if (tree) {
882 guint tval;
883 nstime_t tmptime;
884 guint cnt;
886 tval = get_long_integer(tvb, offset + count + 1, &cnt);
887 tmptime.secs = tval;
888 tmptime.nsecs = 0;
890 tvb_ensure_bytes_exist(tvb, offset - 1, length + count + 1);
891 if (field == 0x80)
892 proto_tree_add_time(mmse_tree, hf_mmse_expiry_abs,
893 tvb, offset - 1,
894 length + count + 1, &tmptime);
895 else
896 proto_tree_add_time(mmse_tree, hf_mmse_expiry_rel,
897 tvb, offset - 1,
898 length + count + 1, &tmptime);
900 offset += length + count;
901 break;
902 case MM_FROM_HDR:
904 * Value-length(Address-present-token Encoded-string-value
905 * |Insert-address-token)
907 length = get_value_length(tvb, offset, &count);
908 if (tree) {
909 field = tvb_get_guint8(tvb, offset + count);
910 tvb_ensure_bytes_exist(tvb, offset - 1, length + count + 1);
911 if (field == 0x81) {
912 proto_tree_add_string(mmse_tree, hf_mmse_from, tvb,
913 offset-1, length + count + 1,
914 "<insert address>");
915 } else {
916 (void) get_encoded_strval(tvb, offset + count + 1,
917 &strval);
918 proto_tree_add_string(mmse_tree, hf_mmse_from, tvb,
919 offset-1, length + count + 1, strval);
922 offset += length + count;
923 break;
924 case MM_MCLASS_HDR:
926 * Class-identifier|Text-string
928 field = tvb_get_guint8(tvb, offset);
929 if (field & 0x80) {
930 offset++;
931 if (tree) {
932 proto_tree_add_uint(mmse_tree,
933 hf_mmse_message_class_id,
934 tvb, offset - 2, 2, field);
936 } else {
937 length = get_text_string(tvb, offset, &strval);
938 if (tree) {
939 proto_tree_add_string(mmse_tree,
940 hf_mmse_message_class_str,
941 tvb, offset - 1, length + 1,
942 strval);
944 offset += length;
946 break;
947 case MM_MID_HDR: /* Text-string */
948 length = get_text_string(tvb, offset, &strval);
949 if (tree) {
950 proto_tree_add_string(mmse_tree, hf_mmse_message_id,
951 tvb, offset - 1, length + 1, strval);
953 offset += length;
954 break;
955 case MM_MSIZE_HDR: /* Long-integer */
956 length = get_long_integer(tvb, offset, &count);
957 if (tree) {
958 proto_tree_add_uint(mmse_tree, hf_mmse_message_size,
959 tvb, offset - 1, count + 1, length);
961 offset += count;
962 break;
963 case MM_PRIORITY_HDR: /* Low|Normal|High */
964 field = tvb_get_guint8(tvb, offset++);
965 if (tree) {
966 proto_tree_add_uint(mmse_tree, hf_mmse_priority, tvb,
967 offset - 2, 2, field);
969 break;
970 case MM_RREPLY_HDR: /* Yes|No */
971 field = tvb_get_guint8(tvb, offset++);
972 if (tree) {
973 if (version == 0x80) { /* MMSE 1.0 */
974 proto_tree_add_uint(mmse_tree, hf_mmse_read_reply,
975 tvb, offset - 2, 2, field);
976 } else {
977 proto_tree_add_uint(mmse_tree, hf_mmse_read_report,
978 tvb, offset - 2, 2, field);
981 break;
982 case MM_RALLOWED_HDR: /* Yes|No */
983 field = tvb_get_guint8(tvb, offset++);
984 if (tree) {
985 proto_tree_add_uint(mmse_tree, hf_mmse_report_allowed,
986 tvb, offset - 2, 2, field);
988 break;
989 case MM_RSTATUS_HDR:
990 field = tvb_get_guint8(tvb, offset++);
991 if (tree) {
992 proto_tree_add_uint(mmse_tree, hf_mmse_response_status,
993 tvb, offset - 2, 2, field);
995 break;
996 case MM_RTEXT_HDR: /* Encoded-string-value */
997 if (pdut == PDU_M_MBOX_DELETE_CONF) {
998 /* General form with length */
999 length = tvb_get_guint8(tvb, offset);
1000 if (length == 0x1F) {
1001 guint length_len = 0;
1002 length = tvb_get_guintvar(tvb, offset + 1,
1003 &length_len);
1004 length += 1 + length_len;
1005 } else {
1006 length += 1;
1008 if (tree) {
1009 proto_tree_add_string(mmse_tree,
1010 hf_mmse_content_location,
1011 tvb, offset - 1, length + 1,
1012 "<Undecoded value for m-mbox-delete-conf>");
1014 } else {
1015 length = get_encoded_strval(tvb, offset, &strval);
1016 if (tree) {
1017 proto_tree_add_string(mmse_tree,
1018 hf_mmse_response_text, tvb, offset - 1,
1019 length + 1, strval);
1022 offset += length;
1023 break;
1024 case MM_SVISIBILITY_HDR: /* Hide|Show */
1025 field = tvb_get_guint8(tvb, offset++);
1026 if (tree) {
1027 proto_tree_add_uint(mmse_tree,hf_mmse_sender_visibility,
1028 tvb, offset - 2, 2, field);
1030 break;
1031 case MM_STATUS_HDR:
1032 field = tvb_get_guint8(tvb, offset++);
1033 if (tree) {
1034 proto_tree_add_uint(mmse_tree, hf_mmse_status, tvb,
1035 offset - 2, 2, field);
1037 break;
1038 case MM_SUBJECT_HDR: /* Encoded-string-value */
1039 length = get_encoded_strval(tvb, offset, &strval);
1040 if (tree) {
1041 proto_tree_add_string(mmse_tree, hf_mmse_subject, tvb,
1042 offset - 1, length + 1, strval);
1044 offset += length;
1045 break;
1046 case MM_TO_HDR: /* Encoded-string-value */
1047 length = get_encoded_strval(tvb, offset, &strval);
1048 if (tree) {
1049 proto_tree_add_string(mmse_tree, hf_mmse_to, tvb,
1050 offset - 1, length + 1, strval);
1052 offset += length;
1053 break;
1056 * MMS Encapsulation 1.1
1058 case MM_RETRIEVE_STATUS_HDR: /* Well-known-value */
1059 field = tvb_get_guint8(tvb, offset++);
1060 if (tree) {
1061 proto_tree_add_uint(mmse_tree, hf_mmse_retrieve_status,
1062 tvb, offset - 2, 2, field);
1064 break;
1065 case MM_RETRIEVE_TEXT_HDR:
1066 if (pdut == PDU_M_MBOX_DELETE_CONF) {
1067 /* General form with length */
1068 length = tvb_get_guint8(tvb, offset);
1069 if (length == 0x1F) {
1070 guint length_len = 0;
1071 length = tvb_get_guintvar(tvb, offset + 1,
1072 &length_len);
1073 length += 1 + length_len;
1074 } else {
1075 length += 1;
1077 if (tree) {
1078 proto_tree_add_string(mmse_tree,
1079 hf_mmse_content_location,
1080 tvb, offset - 1, length + 1,
1081 "<Undecoded value for m-mbox-delete-conf>");
1083 } else {
1084 /* Encoded-string-value */
1085 length = get_encoded_strval(tvb, offset, &strval);
1086 if (tree) {
1087 proto_tree_add_string(mmse_tree,
1088 hf_mmse_retrieve_text, tvb, offset - 1,
1089 length + 1, strval);
1092 offset += length;
1093 break;
1094 case MM_READ_STATUS_HDR: /* Well-known-value */
1095 field = tvb_get_guint8(tvb, offset++);
1096 if (tree) {
1097 proto_tree_add_uint(mmse_tree, hf_mmse_read_status,
1098 tvb, offset - 2, 2, field);
1100 break;
1101 case MM_REPLY_CHARGING_HDR: /* Well-known-value */
1102 field = tvb_get_guint8(tvb, offset++);
1103 if (tree) {
1104 proto_tree_add_uint(mmse_tree, hf_mmse_reply_charging,
1105 tvb, offset - 2, 2, field);
1107 break;
1108 case MM_REPLY_CHARGING_DEADLINE_HDR: /* Well-known-value */
1110 * Value-length(Absolute-token Date-value|
1111 * Relative-token Delta-seconds-value)
1113 length = get_value_length(tvb, offset, &count);
1114 field = tvb_get_guint8(tvb, offset + count);
1115 if (tree) {
1116 guint tval;
1117 nstime_t tmptime;
1118 guint cnt;
1120 tval = get_long_integer(tvb, offset + count + 1, &cnt);
1121 tmptime.secs = tval;
1122 tmptime.nsecs = 0;
1124 tvb_ensure_bytes_exist(tvb, offset - 1, length + count + 1);
1125 if (field == 0x80)
1126 proto_tree_add_time(mmse_tree, hf_mmse_reply_charging_deadline_abs,
1127 tvb, offset - 1,
1128 length + count + 1, &tmptime);
1129 else
1130 proto_tree_add_time(mmse_tree, hf_mmse_reply_charging_deadline_rel,
1131 tvb, offset - 1,
1132 length + count + 1, &tmptime);
1134 offset += length + count;
1135 break;
1136 case MM_REPLY_CHARGING_ID_HDR: /* Text-string */
1137 length = get_text_string(tvb, offset, &strval);
1138 if (tree) {
1139 proto_tree_add_string(mmse_tree,
1140 hf_mmse_reply_charging_id,
1141 tvb, offset - 1, length + 1, strval);
1143 offset += length;
1144 break;
1145 case MM_REPLY_CHARGING_SIZE_HDR: /* Long-integer */
1146 length = get_long_integer(tvb, offset, &count);
1147 if (tree) {
1148 proto_tree_add_uint(mmse_tree,
1149 hf_mmse_reply_charging_size,
1150 tvb, offset - 1, count + 1, length);
1152 offset += count;
1153 break;
1154 case MM_PREV_SENT_BY_HDR:
1155 /* Value-length Integer-value Encoded-string-value */
1156 length = get_value_length(tvb, offset, &count);
1157 if (tree) {
1158 guint32 fwd_count, count1, count2;
1159 proto_tree *subtree = NULL;
1160 proto_item *tii = NULL;
1161 /* 1. Forwarded-count-value := Integer-value */
1162 fwd_count = get_integer_value(tvb, offset + count,
1163 &count1);
1164 /* 2. Encoded-string-value */
1165 count2 = get_encoded_strval(tvb,
1166 offset + count + count1, &strval);
1167 /* Now render the fields */
1168 tii = proto_tree_add_string_format(mmse_tree,
1169 hf_mmse_prev_sent_by,
1170 tvb, offset - 1, 1 + count + length,
1171 strval, "%s (Forwarded-count=%u)",
1172 format_text(strval, strlen(strval)),
1173 fwd_count);
1174 subtree = proto_item_add_subtree(tii,
1175 ett_mmse_hdr_details);
1176 proto_tree_add_uint(subtree,
1177 hf_mmse_prev_sent_by_fwd_count,
1178 tvb, offset + count, count1, fwd_count);
1179 proto_tree_add_string(subtree,
1180 hf_mmse_prev_sent_by_address,
1181 tvb, offset + count + count1, count2, strval);
1183 offset += length + count;
1184 break;
1185 case MM_PREV_SENT_DATE_HDR:
1186 /* Value-Length Forwarded-count-value Date-value */
1187 length = get_value_length(tvb, offset, &count);
1188 if (tree) {
1189 guint32 fwd_count, count1, count2;
1190 guint tval;
1191 nstime_t tmptime;
1192 proto_tree *subtree = NULL;
1193 proto_item *tii = NULL;
1194 /* 1. Forwarded-count-value := Integer-value */
1195 fwd_count = get_integer_value(tvb, offset + count,
1196 &count1);
1197 /* 2. Date-value := Long-integer */
1198 tval = get_long_integer(tvb, offset + count + count1,
1199 &count2);
1200 tmptime.secs = tval;
1201 tmptime.nsecs = 0;
1202 strval = abs_time_to_str(&tmptime, ABSOLUTE_TIME_LOCAL,
1203 TRUE);
1204 /* Now render the fields */
1205 tvb_ensure_bytes_exist(tvb, offset - 1, length + count + 1);
1206 tii = proto_tree_add_string_format(mmse_tree,
1207 hf_mmse_prev_sent_date,
1208 tvb, offset - 1, 1 + count + length,
1209 strval, "%s (Forwarded-count=%u)",
1210 format_text(strval, strlen(strval)),
1211 fwd_count);
1212 subtree = proto_item_add_subtree(tii,
1213 ett_mmse_hdr_details);
1214 proto_tree_add_uint(subtree,
1215 hf_mmse_prev_sent_date_fwd_count,
1216 tvb, offset + count, count1, fwd_count);
1217 proto_tree_add_string(subtree,
1218 hf_mmse_prev_sent_date_date,
1219 tvb, offset + count + count1, count2, strval);
1221 offset += length + count;
1222 break;
1224 /* MMS Encapsulation 1.2 */
1226 default:
1227 if (field & 0x80) { /* Well-known WSP header encoding */
1228 guint8 peek = tvb_get_guint8(tvb, offset);
1229 const char *hdr_name = val_to_str(field, vals_mm_header_names,
1230 "Unknown field (0x%02x)");
1231 DebugLog(("\t\tUndecoded well-known header: %s\n",
1232 hdr_name));
1234 if (peek & 0x80) { /* Well-known value */
1235 length = 1;
1236 if (tree) {
1237 proto_tree_add_text(mmse_tree, tvb, offset - 1,
1238 length + 1,
1239 "%s: <Well-known value 0x%02x>"
1240 " (not decoded)",
1241 hdr_name, peek);
1243 } else if ((peek == 0) || (peek >= 0x20)) { /* Text */
1244 length = get_text_string(tvb, offset, &strval);
1245 if (tree) {
1246 proto_tree_add_text(mmse_tree, tvb, offset - 1,
1247 length + 1, "%s: %s (Not decoded)",
1248 hdr_name,
1249 format_text(strval, strlen(strval)));
1251 } else { /* General form with length */
1252 if (peek == 0x1F) { /* Value length in guintvar */
1253 guint length_len = 0;
1254 length = 1 + tvb_get_guintvar(tvb, offset + 1,
1255 &length_len);
1256 length += length_len;
1257 } else { /* Value length in octet */
1258 length = 1 + tvb_get_guint8(tvb, offset);
1260 if (tree) {
1261 proto_tree_add_text(mmse_tree, tvb, offset - 1,
1262 length + 1, "%s: "
1263 "<Value in general form> (not decoded)",
1264 hdr_name);
1267 offset += length;
1268 } else { /* Literal WSP header encoding */
1269 guint length2;
1270 const char *strval2;
1272 --offset;
1273 length = get_text_string(tvb, offset, &strval);
1274 DebugLog(("\t\tUndecoded literal header: %s\n",
1275 strval));
1276 length2= get_text_string(tvb, offset+length, &strval2);
1278 if (tree) {
1279 proto_tree_add_string_format(mmse_tree,
1280 hf_mmse_ffheader, tvb, offset,
1281 length + length2,
1282 tvb_get_string(wmem_packet_scope(), tvb, offset,
1283 length + length2),
1284 "%s: %s",
1285 format_text(strval, strlen(strval)),
1286 format_text(strval2, strlen(strval2)));
1288 offset += length + length2;
1290 break;
1292 DebugLog(("\tEnd(case)\n"));
1294 DebugLog(("\tEnd(switch)\n"));
1295 if (field == MM_CTYPE_HDR) {
1297 * Eeehh, we're now actually back to good old WSP content-type
1298 * encoding. Let's steal that from the WSP-dissector.
1300 tvbuff_t *tmp_tvb;
1301 guint type;
1302 const char *type_str;
1304 DebugLog(("Content-Type: [from WSP dissector]\n"));
1305 DebugLog(("Calling add_content_type() in WSP dissector\n"));
1306 offset = add_content_type(mmse_tree, tvb, offset, &type, &type_str);
1307 DebugLog(("Generating new TVB subset (offset = %u)\n", offset));
1308 tmp_tvb = tvb_new_subset_remaining(tvb, offset);
1309 DebugLog(("Add POST data\n"));
1310 add_post_data(mmse_tree, tmp_tvb, type, type_str, pinfo);
1311 DebugLog(("Done!\n"));
1313 } else {
1314 DebugLog(("tree == NULL and PDU has no potential content\n"));
1317 /* If this protocol has a sub-dissector call it here, see section 1.8 */
1318 DebugLog(("dissect_mmse() - END\n"));
1322 /* Register the protocol with Wireshark */
1324 /* this format is required because a script is used to build the C function
1325 * that calls all the protocol registration.
1327 void
1328 proto_register_mmse(void)
1330 /* Setup list of header fields See Section 1.6.1 for details */
1331 static hf_register_info hf[] = {
1332 { &hf_mmse_message_type,
1333 { "X-Mms-Message-Type", "mmse.message_type",
1334 FT_UINT8, BASE_HEX, VALS(vals_message_type), 0x00,
1335 "Specifies the transaction type. Effectively defines PDU.",
1336 HFILL
1339 { &hf_mmse_transaction_id,
1340 { "X-Mms-Transaction-ID", "mmse.transaction_id",
1341 FT_STRING, BASE_NONE, NULL, 0x00,
1342 "A unique identifier for this transaction. Identifies request and corresponding response only.",
1343 HFILL
1346 { &hf_mmse_mms_version,
1347 { "X-Mms-MMS-Version", "mmse.mms_version",
1348 FT_STRING, BASE_NONE, NULL, 0x00,
1349 "Version of the protocol used.",
1350 HFILL
1353 { &hf_mmse_bcc,
1354 { "Bcc", "mmse.bcc",
1355 FT_STRING, BASE_NONE, NULL, 0x00,
1356 "Blind carbon copy.",
1357 HFILL
1360 { &hf_mmse_cc,
1361 { "Cc", "mmse.cc",
1362 FT_STRING, BASE_NONE, NULL, 0x00,
1363 "Carbon copy.",
1364 HFILL
1367 { &hf_mmse_content_location,
1368 { "X-Mms-Content-Location", "mmse.content_location",
1369 FT_STRING, BASE_NONE, NULL, 0x00,
1370 "Defines the location of the message.",
1371 HFILL
1374 { &hf_mmse_date,
1375 { "Date", "mmse.date",
1376 FT_ABSOLUTE_TIME, ABSOLUTE_TIME_LOCAL, NULL, 0x00,
1377 "Arrival timestamp of the message or sending timestamp.",
1378 HFILL
1381 { &hf_mmse_delivery_report,
1382 { "X-Mms-Delivery-Report", "mmse.delivery_report",
1383 FT_UINT8, BASE_HEX, VALS(vals_yes_no), 0x00,
1384 "Whether a report of message delivery is wanted or not.",
1385 HFILL
1388 { &hf_mmse_delivery_time_abs,
1389 { "X-Mms-Delivery-Time", "mmse.delivery_time.abs",
1390 FT_ABSOLUTE_TIME, ABSOLUTE_TIME_LOCAL, NULL, 0x00,
1391 "The time at which message delivery is desired.",
1392 HFILL
1395 { &hf_mmse_delivery_time_rel,
1396 { "X-Mms-Delivery-Time", "mmse.delivery_time.rel",
1397 FT_RELATIVE_TIME, BASE_NONE, NULL, 0x00,
1398 "The desired message delivery delay.",
1399 HFILL
1402 { &hf_mmse_expiry_abs,
1403 { "X-Mms-Expiry", "mmse.expiry.abs",
1404 FT_ABSOLUTE_TIME, ABSOLUTE_TIME_LOCAL, NULL, 0x00,
1405 "Time when message expires and need not be delivered anymore.",
1406 HFILL
1409 { &hf_mmse_expiry_rel,
1410 { "X-Mms-Expiry", "mmse.expiry.rel",
1411 FT_RELATIVE_TIME, BASE_NONE, NULL, 0x00,
1412 "Delay before message expires and need not be delivered anymore.",
1413 HFILL
1416 { &hf_mmse_from,
1417 { "From", "mmse.from",
1418 FT_STRING, BASE_NONE, NULL, 0x00,
1419 "Address of the message sender.",
1420 HFILL
1423 { &hf_mmse_message_class_id,
1424 { "X-Mms-Message-Class", "mmse.message_class.id",
1425 FT_UINT8, BASE_HEX, VALS(vals_message_class), 0x00,
1426 "Of what category is the message.",
1427 HFILL
1430 { &hf_mmse_message_class_str,
1431 { "X-Mms-Message-Class", "mmse.message_class.str",
1432 FT_STRING, BASE_NONE, NULL, 0x00,
1433 "Of what category is the message.",
1434 HFILL
1437 { &hf_mmse_message_id,
1438 { "Message-Id", "mmse.message_id",
1439 FT_STRING, BASE_NONE, NULL, 0x00,
1440 "Unique identification of the message.",
1441 HFILL
1444 { &hf_mmse_message_size,
1445 { "X-Mms-Message-Size", "mmse.message_size",
1446 FT_UINT32, BASE_DEC, NULL, 0x00,
1447 "The size of the message in octets.",
1448 HFILL
1451 { &hf_mmse_priority,
1452 { "X-Mms-Priority", "mmse.priority",
1453 FT_UINT8, BASE_HEX, VALS(vals_priority), 0x00,
1454 "Priority of the message.",
1455 HFILL
1458 { &hf_mmse_read_reply,
1459 { "X-Mms-Read-Reply", "mmse.read_reply",
1460 FT_UINT8, BASE_HEX, VALS(vals_yes_no), 0x00,
1461 "Whether a read report from every recipient is wanted.",
1462 HFILL
1465 { &hf_mmse_read_report,
1466 { "X-Mms-Read-Report", "mmse.read_report",
1467 FT_UINT8, BASE_HEX, VALS(vals_yes_no), 0x00,
1468 "Whether a read report from every recipient is wanted.",
1469 HFILL
1472 { &hf_mmse_report_allowed,
1473 { "X-Mms-Report-Allowed", "mmse.report_allowed",
1474 FT_UINT8, BASE_HEX, VALS(vals_yes_no), 0x00,
1475 "Sending of delivery report allowed or not.",
1476 HFILL
1479 { &hf_mmse_response_status,
1480 { "Response-Status", "mmse.response_status",
1481 FT_UINT8, BASE_HEX, VALS(vals_response_status), 0x00,
1482 "MMS-specific result of a message submission or retrieval.",
1483 HFILL
1486 { &hf_mmse_response_text,
1487 { "Response-Text", "mmse.response_text",
1488 FT_STRING, BASE_NONE, NULL, 0x00,
1489 "Additional information on MMS-specific result.",
1490 HFILL
1493 { &hf_mmse_sender_visibility,
1494 { "Sender-Visibility", "mmse.sender_visibility",
1495 FT_UINT8, BASE_HEX, VALS(vals_sender_visibility), 0x00,
1496 "Disclose sender identity to receiver or not.",
1497 HFILL
1500 { &hf_mmse_status,
1501 { "Status", "mmse.status",
1502 FT_UINT8, BASE_HEX, VALS(vals_message_status), 0x00,
1503 "Current status of the message.",
1504 HFILL
1507 { &hf_mmse_subject,
1508 { "Subject", "mmse.subject",
1509 FT_STRING, BASE_NONE, NULL, 0x00,
1510 "Subject of the message.",
1511 HFILL
1514 { &hf_mmse_to,
1515 { "To", "mmse.to",
1516 FT_STRING, BASE_NONE, NULL, 0x00,
1517 "Recipient(s) of the message.",
1518 HFILL
1521 #if 0
1522 { &hf_mmse_content_type,
1523 { "Data", "mmse.content_type",
1524 FT_NONE, BASE_NONE, NULL, 0x00,
1525 "Media content of the message.",
1526 HFILL
1529 #endif
1530 { &hf_mmse_ffheader,
1531 { "Free format (not encoded) header", "mmse.ffheader",
1532 FT_STRING, BASE_NONE, NULL, 0x00,
1533 "Application header without corresponding encoding.",
1534 HFILL
1537 /* MMSE 1.1 */
1538 { &hf_mmse_retrieve_status,
1539 { "X-Mms-Retrieve-Status", "mmse.retrieve_status",
1540 FT_UINT8, BASE_HEX, VALS(vals_retrieve_status), 0x00,
1541 "MMS-specific result of a message retrieval.",
1542 HFILL
1545 { &hf_mmse_retrieve_text,
1546 { "X-Mms-Retrieve-Text", "mmse.retrieve_text",
1547 FT_STRING, BASE_NONE, NULL, 0x00,
1548 "Status text of a MMS message retrieval.",
1549 HFILL
1552 { &hf_mmse_read_status,
1553 { "X-Mms-Read-Status", "mmse.read_status",
1554 FT_UINT8, BASE_HEX, VALS(vals_read_status), 0x00,
1555 "MMS-specific message read status.",
1556 HFILL
1559 { &hf_mmse_reply_charging,
1560 { "X-Mms-Reply-Charging", "mmse.reply_charging",
1561 FT_UINT8, BASE_HEX, VALS(vals_reply_charging), 0x00,
1562 "MMS-specific message reply charging method.",
1563 HFILL
1566 { &hf_mmse_reply_charging_deadline_abs,
1567 { "X-Mms-Reply-Charging-Deadline", "mmse.reply_charging_deadline.abs",
1568 FT_ABSOLUTE_TIME, ABSOLUTE_TIME_LOCAL, NULL, 0x00,
1569 "The latest time of the recipient(s) to submit the Reply MM.",
1570 HFILL
1573 { &hf_mmse_reply_charging_deadline_rel,
1574 { "X-Mms-Reply-Charging-Deadline", "mmse.reply_charging_deadline.rel",
1575 FT_RELATIVE_TIME, BASE_NONE, NULL, 0x00,
1576 "The latest time of the recipient(s) to submit the Reply MM.",
1577 HFILL
1580 { &hf_mmse_reply_charging_id,
1581 { "X-Mms-Reply-Charging-Id", "mmse.reply_charging_id",
1582 FT_STRING, BASE_NONE, NULL, 0x00,
1583 "Unique reply charging identification of the message.",
1584 HFILL
1587 { &hf_mmse_reply_charging_size,
1588 { "X-Mms-Reply-Charging-Size", "mmse.reply_charging_size",
1589 FT_UINT32, BASE_DEC, NULL, 0x00,
1590 "The size of the reply charging in octets.",
1591 HFILL
1594 { &hf_mmse_prev_sent_by,
1595 { "X-Mms-Previously-Sent-By", "mmse.previously_sent_by",
1596 FT_STRING, BASE_NONE, NULL, 0x00,
1597 "Indicates that the MM has been previously sent by this user.",
1598 HFILL
1601 { &hf_mmse_prev_sent_by_fwd_count,
1602 { "Forward Count", "mmse.previously_sent_by.forward_count",
1603 FT_UINT32, BASE_DEC, NULL, 0x00,
1604 "Forward count of the previously sent MM.",
1605 HFILL
1608 { &hf_mmse_prev_sent_by_address,
1609 { "Address", "mmse.previously_sent_by.address",
1610 FT_STRING, BASE_NONE, NULL, 0x00,
1611 "Indicates from whom the MM has been previously sent.",
1612 HFILL
1615 { &hf_mmse_prev_sent_date,
1616 { "X-Mms-Previously-Sent-Date", "mmse.previously_sent_date",
1617 FT_STRING, BASE_NONE, NULL, 0x00,
1618 "Indicates the date that the MM has been previously sent.",
1619 HFILL
1622 { &hf_mmse_prev_sent_date_fwd_count,
1623 { "Forward Count", "mmse.previously_sent_date.forward_count",
1624 FT_UINT32, BASE_DEC, NULL, 0x00,
1625 "Forward count of the previously sent MM.",
1626 HFILL
1629 { &hf_mmse_prev_sent_date_date,
1630 { "Date", "mmse.previously_sent_date.date",
1631 FT_STRING, BASE_NONE, NULL, 0x00,
1632 "Time when the MM has been previously sent.",
1633 HFILL
1640 /* Setup protocol subtree array */
1641 static gint *ett[] = {
1642 &ett_mmse,
1643 &ett_mmse_hdr_details,
1646 /* Register the protocol name and description */
1647 proto_mmse = proto_register_protocol("MMS Message Encapsulation",
1648 "MMSE", "mmse");
1650 /* Required function calls to register header fields and subtrees used */
1651 proto_register_field_array(proto_mmse, hf, array_length(hf));
1652 proto_register_subtree_array(ett, array_length(ett));
1655 /* If this dissector uses sub-dissector registration add registration routine.
1656 * This format is required because a script is used to find these routines and
1657 * create the code that calls these routines.
1659 void
1660 proto_reg_handoff_mmse(void)
1662 dissector_handle_t mmse_standalone_handle;
1663 dissector_handle_t mmse_encapsulated_handle;
1665 heur_dissector_add("wsp", dissect_mmse_heur, proto_mmse);
1666 mmse_standalone_handle = create_dissector_handle(
1667 dissect_mmse_standalone, proto_mmse);
1668 mmse_encapsulated_handle = create_dissector_handle(
1669 dissect_mmse_encapsulated, proto_mmse);
1670 /* As the media types for WSP and HTTP are the same, the WSP dissector
1671 * uses the same string dissector table as the HTTP protocol. */
1672 dissector_add_string("media_type",
1673 "application/vnd.wap.mms-message", mmse_standalone_handle);
1674 dissector_add_string("multipart_media_type",
1675 "application/vnd.wap.mms-message", mmse_encapsulated_handle);