Coverage Report

Created: 2026-07-12 07:10

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/wireshark/epan/dissectors/packet-gsm_osmux.c
Line
Count
Source
1
/* packet-gsm_osmux.c
2
 * Routines for packet dissection of Osmux voice/signalling multiplex protocol
3
 * Copyright 2016-2024 sysmocom s.f.m.c. GmbH <info@sysmocom.de>
4
 * Written by Daniel Willmann <dwillmann@sysmocom.de>,
5
 *            Pau Espin Pedrol <pespin@sysmocom.de>
6
 *
7
 * Wireshark - Network traffic analyzer
8
 * By Gerald Combs <gerald@wireshark.org>
9
 * Copyright 1998 Gerald Combs
10
 *
11
 * SPDX-License-Identifier: GPL-2.0-or-later
12
 */
13
14
 /* FIXME: I didn't find a way yet to reliably differentiate between streams
15
  * using same IPs+PORTs+CID over time. That means: if a recording session is
16
  * long enough, a call may have allocated a CID which was already used by
17
  * someone else in the past, and wireshark will handle those two calls as the
18
  * same stream. This is bad specially for statistics such as jitter.
19
  */
20
21
#include "config.h"
22
23
#include <string.h>
24
25
#include <epan/conversation.h>
26
#include <epan/packet.h>
27
#include <epan/stats_tree.h>
28
#include <epan/tap.h>
29
#include <epan/to_str.h>
30
#include <epan/strutil.h>
31
32
/* un-comment the following as well as this line in conversation.c, to enable debug printing */
33
/* #define DEBUG_CONVERSATION */
34
#include "conversation_debug.h"
35
36
void proto_register_osmux(void);
37
void proto_reg_handoff_osmux(void);
38
39
#define OSMUX_FT_SIGNAL 0x00
40
0
#define OSMUX_FT_AMR 0x01
41
#define OSMUX_FT_DUMMY 0x02
42
43
static const value_string osmux_ft_vals[] =
44
{
45
    {OSMUX_FT_SIGNAL, "Signalling"},
46
    {OSMUX_FT_AMR, "AMR"},
47
    {OSMUX_FT_DUMMY, "Dummy"},
48
    {0, NULL}
49
};
50
51
#define AMR_FT_0    0
52
#define AMR_FT_1    1
53
#define AMR_FT_2    2
54
#define AMR_FT_3    3
55
#define AMR_FT_4    4
56
#define AMR_FT_5    5
57
#define AMR_FT_6    6
58
#define AMR_FT_7    7
59
#define AMR_FT_SID  8
60
0
#define AMR_FT_MAX  9
61
62
static const value_string amr_ft_names[] =
63
{
64
    {AMR_FT_0, "AMR 4.75"},
65
    {AMR_FT_1, "AMR 5.15"},
66
    {AMR_FT_2, "AMR 5.90"},
67
    {AMR_FT_3, "AMR 6.70"},
68
    {AMR_FT_4, "AMR 7.40"},
69
    {AMR_FT_5, "AMR 7.95"},
70
    {AMR_FT_6, "AMR 10.2"},
71
    {AMR_FT_7, "AMR 12.2"},
72
    {AMR_FT_SID, "AMR SID"},
73
    {0, NULL}
74
};
75
76
static uint8_t amr_ft_bytes[AMR_FT_MAX] = {12, 13, 15, 17, 19, 20, 26, 31, 5};
77
78
#define OSMUX_AMR_HEADER_LEN 4
79
80
/* Initialize the protocol and registered fields */
81
static dissector_handle_t osmux_handle;
82
static int proto_osmux;
83
static int osmux_tap;
84
85
static int hf_osmux_stream_id;
86
static int hf_osmux_ft_ctr;
87
static int hf_osmux_rtp_m;
88
static int hf_osmux_ft;
89
static int hf_osmux_ctr;
90
static int hf_osmux_amr_f;
91
static int hf_osmux_amr_q;
92
static int hf_osmux_seq;
93
static int hf_osmux_circuit_id;
94
static int hf_osmux_amr_ft_cmr;
95
static int hf_osmux_amr_ft;
96
static int hf_osmux_amr_cmr;
97
static int hf_osmux_amr_data;
98
99
/* Initialize the subtree pointers */
100
static int ett_osmux;
101
static int ett_osmux_ft_ctr;
102
static int ett_osmux_amr_ft_cmr;
103
104
/* Stream handling */
105
static wmem_map_t *osmux_stream_hash;
106
static uint32_t osmux_next_stream_id;
107
108
struct osmux_stream_key {
109
    address src;
110
    address dst;
111
    port_type ptype;
112
    uint32_t srcport;
113
    uint32_t destport;
114
    uint32_t cid;
115
};
116
117
struct osmux_stats_tree {
118
    int node_id;
119
    bool amr_received;
120
    uint32_t last_seq;
121
    uint32_t prev_seq;
122
    nstime_t prev_ts;
123
    double jitter;
124
};
125
126
struct osmux_stream {
127
    struct osmux_stream_key *key;
128
    struct osmux_stats_tree stats;
129
    uint32_t id;
130
};
131
132
/* Tap structure of Osmux header */
133
struct osmux_hdr {
134
    bool rtp_m;
135
    uint8_t ft;
136
    uint8_t ctr;
137
    bool amr_f;
138
    bool amr_q;
139
    uint8_t seq;
140
    uint8_t circuit_id;
141
    uint8_t amr_cmr;
142
    uint8_t amr_ft;
143
    bool is_old_dummy;
144
    struct osmux_stream *stream;
145
};
146
147
/* Code to calculate AMR payload size */
148
static uint8_t
149
amr_ft_to_bytes(uint8_t amr_ft)
150
0
{
151
0
    if (amr_ft >= AMR_FT_MAX) /* malformed packet ? */
152
0
        return 0;
153
0
    return amr_ft_bytes[amr_ft];
154
0
}
155
156
/*
157
 * Hash Functions
158
 */
159
static int
160
osmux_equal(const void *v, const void *w)
161
0
{
162
0
    const struct osmux_stream_key *v1 = (const struct osmux_stream_key *)v;
163
0
    const struct osmux_stream_key *v2 = (const struct osmux_stream_key *)w;
164
165
0
    if (v1->ptype != v2->ptype)
166
0
        return 0; /* different types of port */
167
168
0
    if (v1->srcport == v2->srcport &&
169
0
        v1->destport == v2->destport &&
170
0
        addresses_equal(&v1->src, &v2->src) &&
171
0
        addresses_equal(&v1->dst, &v2->dst) &&
172
0
        v1->cid == v2->cid) {
173
0
        return 1;
174
0
    }
175
176
0
    return 0;
177
0
}
178
179
static unsigned
180
osmux_hash (const void *v)
181
0
{
182
0
    const struct osmux_stream_key *key = (const struct osmux_stream_key *)v;
183
0
    unsigned hash_val;
184
0
    address tmp_addr;
185
186
0
    hash_val = 0;
187
0
    tmp_addr.len  = 4;
188
189
0
    hash_val = add_address_to_hash(hash_val, &key->src);
190
0
    tmp_addr.data = &key->srcport;
191
0
    hash_val = add_address_to_hash(hash_val, &tmp_addr);
192
193
0
    hash_val = add_address_to_hash(hash_val, &key->dst);
194
0
    tmp_addr.data = &key->destport;
195
0
    hash_val = add_address_to_hash(hash_val, &tmp_addr);
196
197
0
    tmp_addr.data = &key->cid;
198
0
    hash_val = add_address_to_hash(hash_val, &tmp_addr);
199
200
0
    hash_val += ( hash_val << 3 );
201
0
    hash_val ^= ( hash_val >> 11 );
202
0
    hash_val += ( hash_val << 15 );
203
204
0
    return hash_val;
205
0
}
206
207
208
static char* stream_str(struct osmux_stream *stream, packet_info* pinfo)
209
0
{
210
0
    char *ip_str, *ip2_str, *str;
211
212
0
    ip_str = address_to_str(NULL, &stream->key->src);
213
0
    ip2_str = address_to_str(NULL, &stream->key->dst);
214
0
    str = wmem_strdup_printf(pinfo->pool, "%u ([%s:%u->%s:%u]:%u)", stream->id,
215
0
                ip_str, stream->key->srcport, ip2_str, stream->key->destport,
216
0
                stream->key->cid);
217
0
    wmem_free(NULL, ip_str);
218
0
    wmem_free(NULL, ip2_str);
219
220
0
    return str;
221
0
}
222
223
static struct osmux_stream *
224
get_stream(packet_info *pinfo, uint32_t cid)
225
0
{
226
0
    struct osmux_stream_key key, *new_key;
227
0
    struct osmux_stream *stream;
228
229
0
    copy_address_shallow(&key.src, &pinfo->src);
230
0
    copy_address_shallow(&key.dst, &pinfo->dst);
231
0
    key.ptype = pinfo->ptype;
232
0
    key.srcport = pinfo->srcport;
233
0
    key.destport = pinfo->destport;
234
0
    key.cid = cid;
235
236
0
    stream = (struct osmux_stream *) wmem_map_lookup(osmux_stream_hash, &key);
237
0
    if (!stream) {
238
0
        new_key = wmem_new(wmem_file_scope(), struct osmux_stream_key);
239
0
        *new_key = key;
240
0
        copy_address_wmem(wmem_file_scope(), &new_key->src, &key.src);
241
0
        copy_address_wmem(wmem_file_scope(), &new_key->dst, &key.dst);
242
243
0
        stream = wmem_new0(wmem_file_scope(), struct osmux_stream);
244
0
        stream->key = new_key;
245
0
        stream->id = osmux_next_stream_id;
246
0
        osmux_next_stream_id++;
247
248
0
        wmem_map_insert(osmux_stream_hash, new_key, stream);
249
0
    }
250
251
0
    return stream;
252
0
}
253
254
255
static void finish_process_pkt(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, struct osmux_hdr *osmuxh)
256
0
{
257
0
    proto_item* ti;
258
0
    osmuxh->stream = get_stream(pinfo, osmuxh->circuit_id);
259
260
0
    ti = proto_tree_add_uint(tree, hf_osmux_stream_id, tvb, 0, 0, osmuxh->stream->id);
261
0
    proto_item_set_generated(ti);
262
0
    tap_queue_packet(osmux_tap, pinfo, osmuxh);
263
0
}
264
265
/* Code to actually dissect the packets */
266
static int
267
dissect_osmux(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
268
0
{
269
0
    static int * const ft_ctr_fields[] = {
270
0
        &hf_osmux_rtp_m,
271
0
        &hf_osmux_ft,
272
0
        &hf_osmux_ctr,
273
0
        &hf_osmux_amr_f,
274
0
        &hf_osmux_amr_q,
275
0
        NULL
276
0
    };
277
0
    static int * const amr_ft_cmr_fields[] = {
278
0
        &hf_osmux_amr_ft,
279
0
        &hf_osmux_amr_cmr,
280
0
        NULL
281
0
    };
282
283
0
    unsigned offset = 0;
284
285
0
    col_set_str(pinfo->cinfo, COL_PROTOCOL, "Osmux");
286
0
    col_clear(pinfo->cinfo, COL_INFO);
287
288
0
    while (tvb_reported_length_remaining(tvb, offset) >= 2) {
289
290
0
        struct osmux_hdr *osmuxh;
291
0
        proto_item *ti;
292
0
        proto_tree *osmux_tree = NULL;
293
0
        uint8_t ft_ctr;
294
0
        uint64_t amr_ft_cmr;
295
0
        uint8_t i;
296
0
        uint32_t size, temp;
297
298
0
        osmuxh = wmem_new0(pinfo->pool, struct osmux_hdr);
299
300
0
        ft_ctr = tvb_get_uint8(tvb, offset);
301
302
0
        osmuxh->rtp_m = ft_ctr >> 7;
303
0
        osmuxh->ft = (ft_ctr >> 5) & 0x3;
304
0
        osmuxh->ctr = (ft_ctr >> 2) & 0x7;
305
0
        osmuxh->amr_q = !!(ft_ctr & 0x02);
306
0
        osmuxh->amr_f = !!(ft_ctr & 0x01);
307
308
0
        col_append_sep_str(pinfo->cinfo, COL_INFO, ", ", "Osmux ");
309
310
0
        col_append_fstr(pinfo->cinfo, COL_INFO, "%s ",
311
0
                        val_to_str(pinfo->pool, osmuxh->ft, osmux_ft_vals,
312
0
                                   "unknown 0x%02x"));
313
314
0
        if (osmuxh->rtp_m)
315
0
            col_append_str(pinfo->cinfo, COL_INFO, "(M) ");
316
317
0
        ti = proto_tree_add_protocol_format(tree, proto_osmux, tvb, offset, -1,
318
0
                "Osmux type %s frame",
319
0
                val_to_str(pinfo->pool, osmuxh->ft, osmux_ft_vals, "unknown 0x%02x"));
320
321
0
        osmux_tree = proto_item_add_subtree(ti, ett_osmux);
322
323
0
        proto_tree_add_bitmask(osmux_tree, tvb, offset, hf_osmux_ft_ctr,
324
0
               ett_osmux_ft_ctr, ft_ctr_fields, ENC_BIG_ENDIAN);
325
0
         offset++;
326
327
        /* Old versions of the protocol used to send dummy packets of only 2 bytes (control + cid):_*/
328
0
        if (ft_ctr == 0x23 && tvb_reported_length_remaining(tvb, offset - 1) == 2) {
329
0
            osmuxh->is_old_dummy = true;
330
0
            proto_tree_add_item_ret_uint(osmux_tree, hf_osmux_circuit_id, tvb, offset, 1, ENC_BIG_ENDIAN, &temp);
331
0
            osmuxh->circuit_id = (uint8_t)temp;
332
0
            col_append_fstr(pinfo->cinfo, COL_INFO, "Old Dummy (CID %u)", osmuxh->circuit_id);
333
0
            finish_process_pkt(tvb,  pinfo, tree, osmuxh);
334
0
            return tvb_reported_length(tvb);
335
0
        }
336
337
0
        proto_tree_add_item_ret_uint(osmux_tree, hf_osmux_seq, tvb, offset, 1, ENC_BIG_ENDIAN, &temp);
338
0
        osmuxh->seq = (uint8_t)temp;
339
0
        offset++;
340
341
0
        proto_tree_add_item_ret_uint(osmux_tree, hf_osmux_circuit_id, tvb, offset, 1, ENC_BIG_ENDIAN, &temp);
342
0
        osmuxh->circuit_id = (uint8_t)temp;
343
0
        offset++;
344
0
        col_append_fstr(pinfo->cinfo, COL_INFO, "(CID %u) ", osmuxh->circuit_id);
345
346
0
        proto_tree_add_bitmask_ret_uint64(osmux_tree, tvb, offset, hf_osmux_amr_ft_cmr,
347
0
                ett_osmux_amr_ft_cmr, amr_ft_cmr_fields, ENC_BIG_ENDIAN, &amr_ft_cmr);
348
0
        offset++;
349
0
        osmuxh->amr_ft = (uint32_t)(amr_ft_cmr & 0xf0) >> 4;
350
0
        osmuxh->amr_cmr = (uint32_t)amr_ft_cmr & 0x0f;
351
0
        size = amr_ft_to_bytes(osmuxh->amr_ft);
352
0
        for (i = 0; i < osmuxh->ctr + 1; i++) {
353
0
            proto_tree_add_item(osmux_tree, hf_osmux_amr_data, tvb, offset, size, ENC_NA);
354
0
            offset += size;
355
0
        }
356
0
        finish_process_pkt(tvb,  pinfo, tree, osmuxh);
357
0
    }
358
359
0
    return tvb_reported_length(tvb);
360
0
}
361
362
/* Statistics */
363
static const char *st_str_total_pkts = "Osmux Total Packets";
364
static const char *st_str_conn = "Osmux Streams";
365
static const char *st_str_pkts = "Count: Osmux Packets";
366
static const char *st_str_amr = "Count: AMR frames";
367
static const char *st_str_rtp_m = "Field: RTP Marker (M)";
368
static const char *st_str_seq_rep = "SeqNum Analysis: Consecutive Repeated";
369
static const char *st_str_seq_lost = "SeqNum Analysis: Lost";
370
static const char *st_str_seq_ord = "SeqNum Analysis: In Order";
371
static const char *st_str_seq_ooo = "SeqNum Analysis: Out Of Order";
372
static const char *st_str_jit_rtt = "Jitter Analysis: Relative Transmit Time [ms]";
373
static const char *st_str_jit_rtt_abs = "Jitter Analysis: Relative Transmit Time (abs) [ms]";
374
static const char *st_str_jit_jit = "Jitter Analysis: Jitter [ms]";
375
376
static int st_osmux_stats = -1;
377
static int st_osmux_stats_conn = -1;
378
379
380
0
static void stream_hash_clean_stats(void *key _U_, void *value, void *user_data _U_) {
381
0
    struct osmux_stream *stream = (struct osmux_stream *)value;
382
0
    memset(&stream->stats, 0, sizeof(struct osmux_stats_tree));
383
0
}
384
385
static void osmux_stats_tree_init(stats_tree *st)
386
0
{
387
0
    wmem_map_foreach(osmux_stream_hash, stream_hash_clean_stats, NULL);
388
0
    st_osmux_stats = stats_tree_create_node(st, st_str_total_pkts, 0, STAT_DT_INT, true);
389
0
    st_osmux_stats_conn = stats_tree_create_node(st, st_str_conn, st_osmux_stats, STAT_DT_INT, true);
390
0
}
391
392
static tap_packet_status osmux_stats_tree_packet(stats_tree *st,
393
        packet_info *pinfo, epan_dissect_t *edt _U_, const void *p _U_, tap_flags_t flags _U_)
394
0
{
395
0
    char* stream_name;
396
0
    char* ft_name;
397
0
    const struct osmux_hdr *osmuxh = (const struct osmux_hdr*) p;
398
0
    struct osmux_stream *stream = osmuxh->stream;
399
400
0
    stream_name = stream_str(stream, pinfo);
401
402
0
    tick_stat_node(st, st_str_total_pkts, 0, true);
403
404
0
    if (!stream->stats.node_id) {
405
0
        tick_stat_node(st, st_str_conn, st_osmux_stats, true);
406
0
        stream->stats.node_id = stats_tree_create_node(st, stream_name, st_osmux_stats_conn, STAT_DT_INT, true);
407
0
    }
408
409
0
    tick_stat_node(st, stream_name, st_osmux_stats_conn, true);
410
0
    tick_stat_node(st, st_str_pkts, stream->stats.node_id, true);
411
412
0
    ft_name = wmem_strdup_printf(pinfo->pool, "Field: FT: %s", osmuxh->is_old_dummy ? "Old Dummy" : osmux_ft_vals[osmuxh->ft].strptr);
413
0
    tick_stat_node(st, ft_name, stream->stats.node_id, true);
414
415
0
    if (osmuxh->ft == OSMUX_FT_AMR && !osmuxh->is_old_dummy) {
416
417
0
        increase_stat_node(st, st_str_amr, stream->stats.node_id, true, osmuxh->ctr+1);
418
0
        avg_stat_node_add_value_notick(st, st_str_amr, stream->stats.node_id, true, osmuxh->ctr+1);
419
420
0
        increase_stat_node(st, st_str_rtp_m, stream->stats.node_id, true, osmuxh->rtp_m);
421
0
        avg_stat_node_add_value_notick(st, st_str_rtp_m, stream->stats.node_id, true, osmuxh->rtp_m);
422
423
424
        /* Calculate relative transmit time */
425
0
        if ((stream->stats.prev_ts.secs == 0 && stream->stats.prev_ts.nsecs == 0) || osmuxh->rtp_m) {
426
0
            avg_stat_node_add_value_int(st, st_str_jit_rtt, stream->stats.node_id, true, 0);
427
0
            avg_stat_node_add_value_int(st, st_str_jit_rtt_abs, stream->stats.node_id, true, 0);
428
0
            avg_stat_node_add_value_int(st, st_str_jit_jit, stream->stats.node_id, true, 0);
429
0
            stream->stats.jitter = 0;
430
0
        } else {
431
0
            nstime_t diff_rx;
432
0
            int32_t diff_rx_ms, diff_tx_ms, Dij;
433
0
            uint32_t abs_Dij;
434
0
            nstime_delta(&diff_rx, &pinfo->abs_ts, &stream->stats.prev_ts);
435
0
            diff_rx_ms = (uint32_t) nstime_to_msec(&diff_rx);
436
0
            diff_tx_ms = (osmuxh->seq - stream->stats.prev_seq)*(osmuxh->ctr+1)*20; /* SAMPLE RATE is 20msec/AMRframe */
437
0
            Dij = diff_rx_ms - diff_tx_ms;
438
0
            abs_Dij = Dij * ( Dij >= 0 ? 1 : -1 );
439
0
            stream->stats.jitter = stream->stats.jitter + ((double) abs_Dij - stream->stats.jitter)/16.0;
440
0
            avg_stat_node_add_value_int(st, st_str_jit_rtt, stream->stats.node_id, true, Dij);
441
0
            avg_stat_node_add_value_int(st, st_str_jit_rtt_abs, stream->stats.node_id, true, abs_Dij);
442
0
            avg_stat_node_add_value_int(st, st_str_jit_jit, stream->stats.node_id, true, (int) stream->stats.jitter);
443
0
        }
444
0
        stream->stats.prev_ts = pinfo->abs_ts;
445
0
        stream->stats.prev_seq = osmuxh->seq;
446
447
        /* Check sequence numbers */
448
0
        if (!stream->stats.amr_received || (stream->stats.last_seq + 1) % 256 == osmuxh->seq ) {
449
            /* normal case */
450
0
            tick_stat_node(st, st_str_seq_ord, stream->stats.node_id, true);
451
0
            stream->stats.last_seq = osmuxh->seq;
452
0
            stream->stats.amr_received = true;
453
0
        } else if (stream->stats.last_seq == osmuxh->seq) {
454
            /* Last packet is repeated */
455
0
            tick_stat_node(st, st_str_seq_rep, stream->stats.node_id, true);
456
0
        } else if ((stream->stats.last_seq + 1) % 256 < osmuxh->seq) {
457
            /* Normal packet loss */
458
0
            increase_stat_node(st, st_str_seq_lost, stream->stats.node_id, true, osmuxh->seq - stream->stats.last_seq - 1);
459
0
            stream->stats.last_seq = osmuxh->seq;
460
0
        } else if (stream->stats.last_seq - osmuxh->seq > 0x008F) {
461
            /* If last_Seq is a lot higher, a wraparound occurred with packet loss */
462
0
            increase_stat_node(st, st_str_seq_lost, stream->stats.node_id, true, 255 - stream->stats.last_seq + osmuxh->seq);
463
0
            stream->stats.last_seq = osmuxh->seq;
464
0
        } else if (stream->stats.last_seq > osmuxh->seq || osmuxh->seq - stream->stats.last_seq > 0x008F) {
465
            /* Out of order packet */
466
0
            tick_stat_node(st, st_str_seq_ooo, stream->stats.node_id, true);
467
0
            increase_stat_node(st, st_str_seq_lost, stream->stats.node_id, true, -1);
468
0
        }
469
470
0
    }
471
472
0
    return TAP_PACKET_REDRAW;
473
0
}
474
475
/* Set up an Osmux conversation. Called from MGCP/SDP dissector to set
476
 * appropriate dissector for the set up MGW endpoint. */
477
void
478
osmux_add_address(packet_info *pinfo, address *addr, int port, int other_port, uint32_t setup_frame_number)
479
0
{
480
0
    address null_addr;
481
0
    conversation_t* p_conv;
482
483
    /*
484
     * If this isn't the first time this packet has been processed,
485
     * we've already done this work, so we don't need to do it
486
     * again.
487
     */
488
0
    if (pinfo->fd->visited)
489
0
        return;
490
491
0
    clear_address(&null_addr);
492
493
    /*
494
     * Check if the ip address and port combination is not
495
     * already registered as a conversation.
496
     */
497
0
    p_conv = find_conversation(setup_frame_number, addr, &null_addr, CONVERSATION_UDP, port, other_port,
498
0
                               NO_ADDR_B | (!other_port ? NO_PORT_B : 0));
499
500
    /*
501
     * If not, create a new conversation.
502
     */
503
0
    if (!p_conv || p_conv->setup_frame != setup_frame_number) {
504
        /* XXX - If setup_frame_number < pinfo->num, creating this conversation
505
         * can mean that the dissection is different on later passes.
506
         */
507
0
        p_conv = conversation_new(setup_frame_number, addr, &null_addr, CONVERSATION_UDP,
508
0
                                  (uint32_t)port, (uint32_t)other_port,
509
0
                                  NO_ADDR2 | (!other_port ? NO_PORT2 : 0));
510
0
    }
511
0
    conversation_set_dissector(p_conv, osmux_handle);
512
0
}
513
514
void proto_register_osmux(void)
515
15
{
516
15
    static hf_register_info hf[] = {
517
15
        {&hf_osmux_stream_id,
518
15
         {"OSmux Stream ID", "osmux.stream_id",
519
15
          FT_UINT32, BASE_DEC, NULL, 0x00,
520
15
          "ID for a specific OSMUX flow", HFILL}
521
15
        },
522
15
        {&hf_osmux_ft_ctr,
523
15
         {"FTCTRByte", "osmux.ft_ctr",
524
15
          FT_UINT8, BASE_DEC, NULL, 0x00,
525
15
          "Byte with Fieldtype, Counter", HFILL}
526
15
        },
527
15
        {&hf_osmux_rtp_m,
528
15
         {"RTP Marker", "osmux.rtp_m",
529
15
          FT_BOOLEAN, 8, NULL, 0x80,
530
15
          "Type of data in packet", HFILL}
531
15
         },
532
15
        {&hf_osmux_ft,
533
15
         {"FieldType", "osmux.ft",
534
15
          FT_UINT8, BASE_DEC, VALS(osmux_ft_vals), 0x60,
535
15
          "Type of data in packet", HFILL}
536
15
         },
537
15
        {&hf_osmux_ctr,
538
15
         {"CTR", "osmux.ctr",
539
15
          FT_UINT8, BASE_HEX, NULL, 0x1c,
540
15
          "Number of AMR packets inside", HFILL}
541
15
         },
542
15
        {&hf_osmux_amr_q,
543
15
         {"AMR f", "osmux.amr_f",
544
15
          FT_BOOLEAN, 8, NULL, 0x02,
545
15
          "AMR f parameter", HFILL}
546
15
         },
547
15
        {&hf_osmux_amr_f,
548
15
         {"AMR q", "osmux.amr_q",
549
15
          FT_BOOLEAN, 8, NULL, 0x01,
550
15
          "AMR q parameter", HFILL}
551
15
         },
552
15
        {&hf_osmux_seq,
553
15
         {"Seq", "osmux.seq",
554
15
          FT_UINT8, BASE_HEX, NULL, 0x0,
555
15
          "Sequence number", HFILL}
556
15
         },
557
15
        {&hf_osmux_circuit_id,
558
15
         {"Circuit ID", "osmux.circuit_id",
559
15
          FT_UINT8, BASE_HEX, NULL, 0x0,
560
15
          NULL, HFILL}
561
15
         },
562
15
        {&hf_osmux_amr_ft_cmr,
563
15
         {"AMR info", "osmux.amr_ft_cmr",
564
15
          FT_UINT8, BASE_DEC, NULL, 0x00,
565
15
          "Byte with AMR params ft and cmr", HFILL}
566
15
        },
567
15
        {&hf_osmux_amr_ft,
568
15
         {"AMR ft", "osmux.amr_ft",
569
15
          FT_UINT8, BASE_HEX,VALS(amr_ft_names), 0xf0,
570
15
          "AMR parameter ft", HFILL}
571
15
         },
572
15
        {&hf_osmux_amr_cmr,
573
15
         {"AMR cmr", "osmux.amr_cmr",
574
15
          FT_UINT8, BASE_HEX, NULL, 0x0f,
575
15
          "AMR parameter cmr", HFILL}
576
15
         },
577
15
        {&hf_osmux_amr_data,
578
15
         {"AMR data", "osmux.amr_data",
579
15
          FT_BYTES, BASE_NONE, NULL, 0x00,
580
15
          "AMR voice data", HFILL}
581
15
         },
582
15
    };
583
584
15
    static int *ett[] = {
585
15
        &ett_osmux,
586
15
        &ett_osmux_ft_ctr,
587
15
        &ett_osmux_amr_ft_cmr,
588
15
    };
589
590
15
    proto_osmux = proto_register_protocol("GSM multiplexing for AMR", "GSM Osmux", "osmux");
591
592
15
    proto_register_field_array(proto_osmux, hf, array_length(hf));
593
15
    proto_register_subtree_array(ett, array_length(ett));
594
595
15
    osmux_stream_hash = wmem_map_new_autoreset(wmem_epan_scope(), wmem_file_scope(),
596
15
                                             osmux_hash, osmux_equal);
597
598
15
    osmux_handle = register_dissector("osmux", dissect_osmux, proto_osmux);
599
600
15
    osmux_tap = register_tap("osmux");
601
15
}
602
603
604
void proto_reg_handoff_osmux(void)
605
15
{
606
15
    dissector_add_for_decode_as_with_preference("udp.port", osmux_handle);
607
608
15
    stats_tree_register("osmux", "osmux", "Osmux" STATS_TREE_MENU_SEPARATOR "osmux", 0,
609
            osmux_stats_tree_packet, osmux_stats_tree_init, NULL);
610
15
}
611
612
/*
613
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
614
 *
615
 * Local variables:
616
 * c-basic-offset: 4
617
 * tab-width: 8
618
 * indent-tabs-mode: nil
619
 * End:
620
 *
621
 * vi: set shiftwidth=4 tabstop=8 expandtab:
622
 * :indentSize=4:tabSize=8:noTabs=true:
623
 */