aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-mms-data.c
blob: f2558ca4eddba4e2289ccf3d86b45ad2c2b9a504 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
/* packet-msmms-data.c
 *
 * Routines for MSMMS data message dissection
 * MMS = Microsoft Media Server
 *
 * Copyright 2005
 * Written by Martin Mathieson
 *
 * $Id: packet-rdt.c 14456 2005-05-27 18:35:19Z etxrab $
 *
 * Ethereal - Network traffic analyzer
 * By Gerald Combs <gerald@ethereal.com>
 * Copyright 1998 Gerald Combs
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

/* Information sources:
 * sdp.ppona.com
 */

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <glib.h>
#include <stdio.h>
#include <string.h>

#include <epan/packet.h>
#include <epan/conversation.h>

static dissector_handle_t msmms_data_handle;

static gint   proto_msmms_data                             = -1;

/* Fields */

/* Pre-header fields */
static gint   hf_msmms_data_sequence_number                = -1;
static gint   hf_msmms_data_packet_id_type                 = -1;
static gint   hf_msmms_data_packet_length                  = -1;

/* UDP command fields */
static gint   hf_msmms_data_header_id                      = -1;
static gint   hf_msmms_data_client_id                      = -1;
static gint   hf_msmms_data_command_id                     = -1;
static gint   hf_msmms_data_packet_to_resend               = -1;

static gint   ett_msmms_data                               = -1;

#define MSMMS_UDP_COMMAND_PORT 1755

/* Parse the only known UDP command (0x01) */
static void dissect_msmms_data_udp_command(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
    gint offset = 0;

    /* Header ID */
    proto_tree_add_item(tree, hf_msmms_data_header_id, tvb, offset, 4, TRUE);
    offset += 4;

    /* Client ID */
    proto_tree_add_item(tree, hf_msmms_data_client_id, tvb, offset, 4, TRUE);
    offset += 4;

    /* Command ID */
    proto_tree_add_item(tree, hf_msmms_data_command_id, tvb, offset, 2, TRUE);
    offset += 4;

    if (check_col(pinfo->cinfo, COL_INFO))
    {
        col_add_str(pinfo->cinfo, COL_INFO, "Request to resend packet(s):");
    }

    /* Show list of packets to resend */
    while (tvb_length_remaining(tvb, offset) >= 4)
    {
        guint32 packet_number = tvb_get_letohl(tvb, offset);
        proto_tree_add_item(tree, hf_msmms_data_packet_to_resend, tvb, offset, 4, TRUE);
        offset += 4;

        if (check_col(pinfo->cinfo, COL_INFO))
        {
            col_append_fstr(pinfo->cinfo, COL_INFO, " %u", packet_number);
        }
    }
}


/****************************************************************************/
/* Main dissection function                                                 */
/****************************************************************************/
static void dissect_msmms_data(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
    gint offset = 0;
    proto_item  *ti = NULL;
    proto_tree  *msmms_tree = NULL;
    guint32 sequence_number;
    guint16 packet_length;

    if (check_col(pinfo->cinfo, COL_PROTOCOL))
    {
        col_set_str(pinfo->cinfo, COL_PROTOCOL, "MSMMS-d");
    }

    /* Create MSMMS data protocol tree */
    if (tree)
    {
        ti = proto_tree_add_item(tree, proto_msmms_data, tvb, offset, -1, FALSE);
        msmms_tree = proto_item_add_subtree(ti, ett_msmms_data);
    }

    /* May be the command asking for packets to be resent */
    if ((pinfo->ptype == PT_UDP) && (pinfo->destport == MSMMS_UDP_COMMAND_PORT))
    {
        dissect_msmms_data_udp_command(tvb, pinfo, msmms_tree);
        return;
    }

    /* Sequence number */
    sequence_number = tvb_get_letohl(tvb, offset);
    proto_tree_add_item(msmms_tree, hf_msmms_data_sequence_number, tvb, offset, 4, TRUE);
    offset += 4;

    /* Packet ID type */
    proto_tree_add_item(msmms_tree, hf_msmms_data_packet_id_type, tvb, offset, 1, TRUE);
    offset++;

    /* TODO: flags depending upon whether UDP or TCP */
    offset++;

    /* Packet Length */
    packet_length = tvb_get_letohs(tvb, offset);
    proto_tree_add_item(msmms_tree, hf_msmms_data_packet_length, tvb, offset, 2, TRUE);
    offset += 2;

    /* Show summary in info column */
    if (check_col(pinfo->cinfo, COL_INFO))
    {
        col_add_fstr(pinfo->cinfo, COL_INFO, "Data: s=%05u, l=%05u",
                     sequence_number, packet_length);
    }
}


/* Set up an MSMMS-d conversation */
void msmms_data_add_address(packet_info *pinfo, address *addr, port_type pt, int port)
{
    address null_addr;
    conversation_t* p_conv;

    /* If this isn't the first time this packet has been processed,
     * we've already done this work, so we don't need to do it
     * again. */
    if (pinfo->fd->flags.visited)
    {
        return;
    }

    SET_ADDRESS(&null_addr, AT_NONE, 0, NULL);

    /* Check if the ip address and port combination is not
     * already registered as a conversation. */
    p_conv = find_conversation(pinfo->fd->num, addr, &null_addr, pt, port, 0,
                               NO_ADDR_B | NO_PORT_B);

    /* If not, create a new conversation. */
    if (!p_conv)
    {
        p_conv = conversation_new(pinfo->fd->num, addr, &null_addr, pt,
                                  (guint32)port, 0, NO_ADDR2 | NO_PORT2);
    }

    /* Set dissector */
    conversation_set_dissector(p_conv, msmms_data_handle);
}


/**************************/
/* Register protocol      */
void proto_register_msmms_data(void)
{
    static hf_register_info hf[] =
    {
        {
            &hf_msmms_data_sequence_number,
            {
                "Sequence number",
                "msmms.data.sequence",
                FT_UINT32,
                BASE_DEC,
                NULL,
                0x0,
                "", HFILL
            }
        },
        {
            &hf_msmms_data_packet_id_type,
            {
                "Packet ID type",
                "msmms.data.packet-id-type",
                FT_UINT8,
                BASE_HEX,
                NULL,
                0x0,
                "", HFILL
            }
        },
        {
            &hf_msmms_data_packet_length,
            {
                "Packet length",
                "msmms.data.packet-length",
                FT_UINT16,
                BASE_DEC,
                NULL,
                0x0,
                "", HFILL
            }
        },

        {
            &hf_msmms_data_header_id,
            {
                "Header ID",
                "msmms.data.header-id",
                FT_UINT32,
                BASE_HEX,
                NULL,
                0x0,
                "", HFILL
            }
        },
        {
            &hf_msmms_data_client_id,
            {
                "Client ID",
                "msmms.data.client-id",
                FT_UINT32,
                BASE_HEX,
                NULL,
                0x0,
                "", HFILL
            }
        },
        {
            &hf_msmms_data_command_id,
            {
                "Command ID",
                "msmms.data.command-id",
                FT_UINT16,
                BASE_DEC,
                NULL,
                0x0,
                "", HFILL
            }
        },
        {
            &hf_msmms_data_packet_to_resend,
            {
                "Packet to resend",
                "msmms.data.packet-to-resend",
                FT_UINT32,
                BASE_DEC,
                NULL,
                0x0,
                "", HFILL
            }
        },
    };

    static gint *ett[] =
    {
        &ett_msmms_data
    };

    /* Register protocol and fields */
    proto_msmms_data = proto_register_protocol("Microsoft Media Server Data",
                                             "MSMMS-d", "msmms-d");
    proto_register_field_array(proto_msmms_data, hf, array_length(hf));
    proto_register_subtree_array(ett, array_length(ett));
    register_dissector("msmms-d", dissect_msmms_data, proto_msmms_data);
}

void proto_reg_handoff_msmms_data(void)
{
    msmms_data_handle = find_dissector("msmms-d");
    dissector_add_handle("udp.port", msmms_data_handle);
    dissector_add_handle("tcp.port", msmms_data_handle);
    dissector_add("udp.port", MSMMS_UDP_COMMAND_PORT, msmms_data_handle);
}