summaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-evrc.c
blob: 982d7c9f146458f41a52506e5f293c5cf98c94a9 (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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
/* packet-evrc.c
 * Routines for:
 *      EVRC EVRC-B EVRC-WB EVRC-NW EVRC-NW2K
 * RTP payload header dissection
 *
 * Copyright 2008, Michael Lum <michael.lum [AT] shaw.ca>
 * In association with Star Solutions
 *
 * Title                3GPP2                   Other
 *
 *   Enhanced Variable Rate Codec, Speech Service Options 3, 68, 70, 73 and 77
 *   for Wideband Spread Spectrum Digital Systems
 *                      3GPP2 C.S0014-E v1.0      TIA-127-?
 *
 * RFC 3558  https://tools.ietf.org/html/rfc3558
 * RFC 4788  https://tools.ietf.org/html/rfc4788
 * RFC 5188  https://tools.ietf.org/html/rfc5188
 * draft-agupta-payload-rtp-evrc-nw2k-00
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#include "config.h"

#include <epan/packet.h>
#include <epan/prefs.h>
#include <epan/expert.h>

#include <wsutil/str_util.h>

/* PROTOTYPES/FORWARDS */

void proto_register_evrc(void);
void proto_reg_handoff_evrc(void);

static dissector_handle_t evrc_handle;
static dissector_handle_t evrcb_handle;
static dissector_handle_t evrcwb_handle;
static dissector_handle_t evrcnw_handle;
static dissector_handle_t evrcnw2k_handle;
static dissector_handle_t evrc_legacy_handle;

static const value_string evrc_frame_type_vals[] = {
    { 0,        "Blank (0 bits)" },
    { 1,        "1/8 Rate (16 bits)" },
    { 2,        "Not valid (1/4 Rate : 40 bits)" },
    { 3,        "1/2 Rate (80 bits)" },
    { 4,        "Full Rate (171 bits; + 5 bits padding)" },
    { 5,        "Erasure (0 bits)" },
    { 0,        NULL }
};

static const value_string evrc_b_frame_type_vals[] = {
    { 0,        "Blank (0 bits)" },
    { 1,        "1/8 Rate (16 bits)" },
    { 2,        "1/4 Rate (40 bits)" },
    { 3,        "1/2 Rate (80 bits)" },
    { 4,        "Full Rate (171 bits; + 5 bits padding)" },
    { 5,        "Erasure (0 bits)" },
    { 0,        NULL }
};

static const value_string evrc_legacy_frame_type_vals[] = {
    { 0,        "Blank (0 bits)" },
    { 1,        "1/8 Rate (16 bits)" },
    { 3,        "1/2 Rate (80 bits)" },
    { 4,        "Full Rate (171 bits; + 5 bits padding)" },
    { 14,       "Erasure (0 bits)" },
    { 0,        NULL }
};

static const value_string evrc_mode_request_vals[] = {
    { 0,        "Rate Reduction 0 (Full Rate)" },
    { 1,        "Rate Reduction 1" },
    { 2,        "Rate Reduction 2" },
    { 3,        "Rate Reduction 3" },
    { 4,        "Rate Reduction 4" },
    { 0,        NULL }
};

static const value_string evrc_b_mode_request_vals[] = {
    { 0,        "Encoder Operating Point 0 (Full Rate)" },
    { 1,        "Encoder Operating Point 1" },
    { 2,        "Encoder Operating Point 2" },
    { 3,        "Encoder Operating Point 3" },
    { 4,        "Encoder Operating Point 4" },
    { 5,        "Encoder Operating Point 5" },
    { 6,        "Encoder Operating Point 6" },
    { 7,        "Encoder Operating Point 7 (1/2 rate max)" },
    { 0,        NULL }
};

static const value_string evrc_wb_mode_request_vals[] = {
    { 0,        "Encoder Operating Point 0 (Full Rate)" },
    { 1,        "Reserved" },
    { 2,        "Reserved" },
    { 3,        "Reserved" },
    { 4,        "Encoder Operating Point 4" },
    { 5,        "Reserved" },
    { 6,        "Reserved" },
    { 7,        "Encoder Operating Point 7 (1/2 rate max)" },
    { 0,        NULL }
};

static const value_string evrc_nw_mode_request_vals[] = {
    { 0,        "Encoder Operating Point 0 (EVRC-WB COP0)" },
    { 1,        "Encoder Operating Point 1 (EVRC-B COP0/EVRC-WB COP4)" },
    { 2,        "Encoder Operating Point 2 (EVRC-B COP2)" },
    { 3,        "Encoder Operating Point 3 (EVRC-B COP3)" },
    { 4,        "Encoder Operating Point 4 (EVRC-B COP4)" },
    { 5,        "Encoder Operating Point 5 (EVRC-B COP5)" },
    { 6,        "Encoder Operating Point 6 (EVRC-B COP6)" },
    { 7,        "Encoder Operating Point 7 (EVRC-B COP7/EVRC-WB COP7)" },
    { 0,        NULL }
};

static const value_string evrc_nw2k_mode_request_vals[] = {
    { 0,        "Encoder Operating Point 0 (EVRC-WB COP0)" },
    { 1,        "Encoder Operating Point 1 (EVRC-B COP0/EVRC-WB COP4)" },
    { 2,        "Encoder Operating Point 2 (EVRC-B COP2)" },
    { 3,        "Encoder Operating Point 3 (EVRC-B COP3/EVRC-NW2k)" },
    { 4,        "Encoder Operating Point 4 (EVRC-B COP4)" },
    { 5,        "Encoder Operating Point 5 (EVRC-B COP5)" },
    { 6,        "Encoder Operating Point 6 (EVRC-B COP6)" },
    { 7,        "Encoder Operating Point 7 (EVRC-B COP7/EVRC-WB COP7)" },
    { 0,        NULL }
};

static const true_false_string toc_further_entries_bit_vals = {
  "More ToC entries follow",
  "End of ToC entries"
};

static const true_false_string evrc_nw2k_enc_capability_bit_vals = {
  "Mode-0 wideband encoding capable",
  "Mode-0 wideband encoding incapable (i.e. narrowband encoding only)"
};

typedef enum
{
    EVRC_VARIANT_EVRC,
    EVRC_VARIANT_EVRC_B,
    EVRC_VARIANT_EVRC_WB,
    EVRC_VARIANT_EVRC_NW,
    EVRC_VARIANT_EVRC_NW2k,
    EVRC_VARIANT_EVRC_LEGACY
}
evrc_variant_t;


/* Initialize the protocol and registered fields */
static int proto_evrc = -1;
static int proto_evrcb = -1;
static int proto_evrcwb = -1;
static int proto_evrcnw = -1;
static int proto_evrcnw2k = -1;
static int proto_evrc_legacy = -1;

static int hf_evrc_reserved = -1;
static int hf_evrc_reserved_2k = -1;
static int hf_evrc_enc_capability_2k = -1;
static int hf_evrc_interleave_length = -1;
static int hf_evrc_interleave_index = -1;
static int hf_evrc_mode_request = -1;
static int hf_evrc_b_mode_request = -1;
static int hf_evrc_wb_mode_request = -1;
static int hf_evrc_nw_mode_request = -1;
static int hf_evrc_nw2k_mode_request = -1;
static int hf_evrc_frame_count = -1;
static int hf_evrc_toc_frame_type_high = -1;
static int hf_evrc_toc_frame_type_low = -1;
static int hf_evrc_b_toc_frame_type_high = -1;
static int hf_evrc_b_toc_frame_type_low = -1;
static int hf_evrc_padding = -1;
static int hf_evrc_speech_data = -1;
static int hf_evrc_legacy_toc_fe_ind = -1;
static int hf_evrc_legacy_toc_reduc_rate = -1;
static int hf_evrc_legacy_toc_frame_type = -1;

/* Initialize the subtree pointers */
static gint ett_evrc = -1;
static gint ett_toc = -1;

static expert_field ei_evrc_unknown_variant = EI_INIT;

/*
 * Variables to allow for proper deletion of dissector registration when
 * the user changes values
 */
static gboolean legacy_pt_60 = FALSE;


static guint8
evrc_frame_type_to_octs(guint8 frame_type)
{
    switch (frame_type)
    {
    default:
        break;

    case 1:     /* 1/8 rate */
        return(2);

    case 2:     /* 1/4 rate */
        return(5);

    case 3:     /* 1/2 rate */
        return(10);

    case 4:     /* full rate */
        return(22);
    }

    return(0);
}

/* GENERIC EVRC DISSECTOR FUNCTIONS */

static void
dissect_evrc_aux(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, evrc_variant_t evrc_variant)
{
    guint8                      oct;
    guint8                      frame_count;
    guint8                      i;
    guint32                     offset, saved_offset;
    gboolean                    further_entries;
    guint32                     len;
    proto_item                  *item = NULL;
    proto_tree                  *evrc_tree = NULL;
    proto_tree                  *toc_tree = NULL;
    int                         hf_mode_request;
    int                         hf_toc_frame_type_high;
    int                         hf_toc_frame_type_low;

    /*
     * assumed max number of speech frames based on
     * frame count being 5 bits + 1
     */
    guint8                      speech_data_len[0x20];


    col_set_str(pinfo->cinfo, COL_PROTOCOL, "EVRC");

    if (!tree) return;

    offset = 0;
    memset(speech_data_len, 0, sizeof(speech_data_len));

    len = tvb_reported_length(tvb);

    item = proto_tree_add_item(tree, proto_evrc, tvb, 0, len, ENC_NA);

    evrc_tree = proto_item_add_subtree(item, ett_evrc);

    if (evrc_variant == EVRC_VARIANT_EVRC_LEGACY)
    {
        /* legacy 'payload type 60' draft-ietf-avt-evrc-07.txt header format */

        proto_tree_add_item(evrc_tree, hf_evrc_reserved, tvb, offset, 1, ENC_BIG_ENDIAN);
        proto_tree_add_item(evrc_tree, hf_evrc_interleave_length, tvb, offset, 1, ENC_BIG_ENDIAN);
        proto_tree_add_item(evrc_tree, hf_evrc_interleave_index, tvb, offset, 1, ENC_BIG_ENDIAN);

        offset++;

        frame_count = 0;
        further_entries = TRUE;
        while (further_entries && (frame_count < sizeof(speech_data_len)) &&
            ((len - offset) > 0))
        {
            toc_tree =
                proto_tree_add_subtree_format(evrc_tree, tvb, offset, 1, ett_toc, NULL, "ToC [%u]", frame_count+1);

            proto_tree_add_item(toc_tree, hf_evrc_legacy_toc_fe_ind, tvb, offset, 1, ENC_BIG_ENDIAN);
            proto_tree_add_item(toc_tree, hf_evrc_legacy_toc_reduc_rate, tvb, offset, 1, ENC_BIG_ENDIAN);
            proto_tree_add_item(toc_tree, hf_evrc_legacy_toc_frame_type, tvb, offset, 1, ENC_BIG_ENDIAN);

            oct = tvb_get_guint8(tvb, offset);
            further_entries = (oct & 0x80) ? TRUE : FALSE;

            speech_data_len[frame_count] = evrc_frame_type_to_octs((guint8)(oct & 0x7f));

            frame_count++;
            offset++;
        }
    }
    else
    {
        /* RFC 3558 header format */

        switch (evrc_variant)
        {
        default:
            proto_tree_add_expert(evrc_tree, pinfo, &ei_evrc_unknown_variant, tvb, offset, len);
            return;

        case EVRC_VARIANT_EVRC:
            hf_mode_request = hf_evrc_mode_request;
            hf_toc_frame_type_high = hf_evrc_toc_frame_type_high;
            hf_toc_frame_type_low = hf_evrc_toc_frame_type_low;

            proto_tree_add_item(evrc_tree, hf_evrc_reserved, tvb, offset, 1, ENC_BIG_ENDIAN);
            break;

        case EVRC_VARIANT_EVRC_B:
            hf_mode_request = hf_evrc_b_mode_request;
            hf_toc_frame_type_high = hf_evrc_b_toc_frame_type_high;
            hf_toc_frame_type_low = hf_evrc_b_toc_frame_type_low;

            proto_tree_add_item(evrc_tree, hf_evrc_reserved, tvb, offset, 1, ENC_BIG_ENDIAN);
            break;

        case EVRC_VARIANT_EVRC_WB:
            hf_mode_request = hf_evrc_wb_mode_request;
            hf_toc_frame_type_high = hf_evrc_b_toc_frame_type_high;
            hf_toc_frame_type_low = hf_evrc_b_toc_frame_type_low;

            proto_tree_add_item(evrc_tree, hf_evrc_reserved, tvb, offset, 1, ENC_BIG_ENDIAN);
            break;

        case EVRC_VARIANT_EVRC_NW:
            hf_mode_request = hf_evrc_nw_mode_request;
            hf_toc_frame_type_high = hf_evrc_b_toc_frame_type_high;
            hf_toc_frame_type_low = hf_evrc_b_toc_frame_type_low;

            proto_tree_add_item(evrc_tree, hf_evrc_reserved, tvb, offset, 1, ENC_BIG_ENDIAN);
            break;

        case EVRC_VARIANT_EVRC_NW2k:
            hf_mode_request = hf_evrc_nw2k_mode_request;
            hf_toc_frame_type_high = hf_evrc_b_toc_frame_type_high;
            hf_toc_frame_type_low = hf_evrc_b_toc_frame_type_low;

            proto_tree_add_item(evrc_tree, hf_evrc_reserved_2k, tvb, offset, 1, ENC_BIG_ENDIAN);
            proto_tree_add_item(evrc_tree, hf_evrc_enc_capability_2k, tvb, offset, 1, ENC_BIG_ENDIAN);
            break;
        }

        proto_tree_add_item(evrc_tree, hf_evrc_interleave_length, tvb, offset, 1, ENC_BIG_ENDIAN);
        proto_tree_add_item(evrc_tree, hf_evrc_interleave_index, tvb, offset, 1, ENC_BIG_ENDIAN);

        offset++;

        proto_tree_add_item(evrc_tree, hf_mode_request, tvb, offset, 1, ENC_BIG_ENDIAN);
        proto_tree_add_item(evrc_tree, hf_evrc_frame_count, tvb, offset, 1, ENC_BIG_ENDIAN);

        /*
         * number of frames in PACKET is frame_count + 1
         */
        frame_count = (tvb_get_guint8(tvb, offset) & 0x1f) + 1;

        offset++;
        saved_offset = offset;

        toc_tree =
            proto_tree_add_subtree_format(evrc_tree, tvb, offset, -1, ett_toc, &item, "ToC - %u frame%s",
                frame_count, plurality(frame_count, "", "s"));

        i = 0;
        while ((i < frame_count) &&
            ((len - offset) > 0))
        {
            oct = tvb_get_guint8(tvb, offset);

            proto_tree_add_item(toc_tree, hf_toc_frame_type_high, tvb, offset, 1, ENC_BIG_ENDIAN);

            speech_data_len[i] = evrc_frame_type_to_octs((guint8)((oct & 0xf0) >> 4));

            i++;

            if (i < frame_count)
            {
                /* even number of frames */
                proto_tree_add_item(toc_tree, hf_toc_frame_type_low, tvb, offset, 1, ENC_BIG_ENDIAN);

                speech_data_len[i] = evrc_frame_type_to_octs((guint8)(oct & 0x0f));

                i++;
            }

            offset++;
        }

        if (frame_count & 0x01)
        {
            /* odd number of frames */
            proto_tree_add_item(toc_tree, hf_evrc_padding, tvb, offset-1, 1, ENC_BIG_ENDIAN);
        }

        proto_item_set_len(item, offset - saved_offset);
    }

    i = 0;
    while ((i < frame_count) &&
        ((len - offset) >= speech_data_len[i]))
    {
        proto_tree_add_bytes_format(evrc_tree, hf_evrc_speech_data, tvb, offset, speech_data_len[i], NULL, "Speech Data [%u]", i+1);

        offset += speech_data_len[i];
        i++;
    }
}

static int
dissect_evrc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
{
    dissect_evrc_aux(tvb, pinfo, tree, EVRC_VARIANT_EVRC);
    return tvb_captured_length(tvb);
}

static int
dissect_evrcb(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
{
    dissect_evrc_aux(tvb, pinfo, tree, EVRC_VARIANT_EVRC_B);
    return tvb_captured_length(tvb);
}

static int
dissect_evrcwb(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
{
    dissect_evrc_aux(tvb, pinfo, tree, EVRC_VARIANT_EVRC_WB);
    return tvb_captured_length(tvb);
}

static int
dissect_evrcnw(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
{
    dissect_evrc_aux(tvb, pinfo, tree, EVRC_VARIANT_EVRC_NW);
    return tvb_captured_length(tvb);
}

static int
dissect_evrcnw2k(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
{
    dissect_evrc_aux(tvb, pinfo, tree, EVRC_VARIANT_EVRC_NW2k);
    return tvb_captured_length(tvb);
}

static int
dissect_evrc_legacy(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
{
    dissect_evrc_aux(tvb, pinfo, tree, EVRC_VARIANT_EVRC_LEGACY);
    return tvb_captured_length(tvb);
}


/* Register the protocol with Wireshark */
void
proto_register_evrc(void)
{
    module_t            *evrc_module;

    /* Setup list of header fields */

    static hf_register_info hf[] =
    {
        { &hf_evrc_reserved,
            { "Reserved",               "evrc.reserved",
            FT_UINT8, BASE_HEX, NULL, 0xc0,
            "Reserved bits", HFILL }
        },
        { &hf_evrc_reserved_2k,
            { "Reserved",               "evrc.reserved",
            FT_UINT8, BASE_HEX, NULL, 0x80,
            "Reserved bits", HFILL }
        },
        { &hf_evrc_enc_capability_2k,
            { "Encoding Capability",               "evrc.enc_capability",
            FT_BOOLEAN, 8, TFS(&evrc_nw2k_enc_capability_bit_vals), 0x40,
            "Encoding Capability Identification", HFILL }
        },
        { &hf_evrc_interleave_length,
            { "Interleave Length",      "evrc.interleave_len",
            FT_UINT8, BASE_DEC, NULL, 0x38,
            "Interleave length bits", HFILL }
        },
        { &hf_evrc_interleave_index,
            { "Interleave Index",       "evrc.interleave_idx",
            FT_UINT8, BASE_DEC, NULL, 0x07,
            "Interleave index bits", HFILL }
        },
        { &hf_evrc_mode_request,
            { "Mode Request",           "evrc.mode_request",
            FT_UINT8, BASE_DEC, VALS(evrc_mode_request_vals), 0xe0,
            "Mode Request bits", HFILL }
        },
        { &hf_evrc_b_mode_request,
            { "Mode Request",           "evrc.b.mode_request",
            FT_UINT8, BASE_DEC, VALS(evrc_b_mode_request_vals), 0xe0,
            "Mode Request bits", HFILL }
        },
        { &hf_evrc_wb_mode_request,
            { "Mode Request",           "evrc.wb.mode_request",
            FT_UINT8, BASE_DEC, VALS(evrc_wb_mode_request_vals), 0xe0,
            "Mode Request bits", HFILL }
        },
        { &hf_evrc_nw_mode_request,
            { "Mode Request",           "evrc.nw.mode_request",
            FT_UINT8, BASE_DEC, VALS(evrc_nw_mode_request_vals), 0xe0,
            "Mode Request bits", HFILL }
        },
        { &hf_evrc_nw2k_mode_request,
            { "Mode Request",           "evrc.nw2k.mode_request",
            FT_UINT8, BASE_DEC, VALS(evrc_nw2k_mode_request_vals), 0xe0,
            "Mode Request bits", HFILL }
        },
        { &hf_evrc_frame_count,
            { "Frame Count (0 means 1 frame)",  "evrc.frame_count",
            FT_UINT8, BASE_DEC, NULL, 0x1f,
            "Frame Count bits, a value of 0 means 1 frame", HFILL }
        },
        { &hf_evrc_toc_frame_type_high,
            { "ToC Frame Type",         "evrc.toc.frame_type_hi",
            FT_UINT8, BASE_DEC, VALS(evrc_frame_type_vals), 0xf0,
            "ToC Frame Type bits", HFILL }
        },
        { &hf_evrc_toc_frame_type_low,
            { "ToC Frame Type",         "evrc.toc.frame_type_lo",
            FT_UINT8, BASE_DEC, VALS(evrc_frame_type_vals), 0x0f,
            "ToC Frame Type bits", HFILL }
        },
        { &hf_evrc_b_toc_frame_type_high,
            { "ToC Frame Type",         "evrc.b.toc.frame_type_hi",
            FT_UINT8, BASE_DEC, VALS(evrc_b_frame_type_vals), 0xf0,
            "ToC Frame Type bits", HFILL }
        },
        { &hf_evrc_b_toc_frame_type_low,
            { "ToC Frame Type",         "evrc.b.toc.frame_type_lo",
            FT_UINT8, BASE_DEC, VALS(evrc_b_frame_type_vals), 0x0f,
            "ToC Frame Type bits", HFILL }
        },
        { &hf_evrc_padding,
            { "Padding",                "evrc.padding",
            FT_UINT8, BASE_DEC, NULL, 0x0f,
            "Padding bits", HFILL }
        },
        { &hf_evrc_speech_data,
            { "Speech data",                "evrc.speech_data",
            FT_BYTES, BASE_NONE, NULL, 0x0,
            NULL, HFILL }
        },
        { &hf_evrc_legacy_toc_fe_ind,
            { "ToC Further Entries Indicator",  "evrc.legacy.toc.further_entries_ind",
            FT_BOOLEAN, 8, TFS(&toc_further_entries_bit_vals), 0x80,
            "ToC Further Entries Indicator bit", HFILL }
        },
        { &hf_evrc_legacy_toc_reduc_rate,
            { "ToC Reduced Rate",       "evrc.legacy.toc.reduced_rate",
            FT_UINT8, BASE_DEC, NULL, 0x40,
            "ToC Reduced Rate bits", HFILL }
        },
        { &hf_evrc_legacy_toc_frame_type,
            { "ToC Frame Type",         "evrc.legacy.toc.frame_type",
            FT_UINT8, BASE_DEC, VALS(evrc_legacy_frame_type_vals), 0x3f,
            "ToC Frame Type bits", HFILL }
        }
    };

    static ei_register_info ei[] = {
        { &ei_evrc_unknown_variant,
            { "evrc.unknown_variant", PI_UNDECODED, PI_WARN,
            "Variant Unknown/Unsupported - dissector bug/later version spec (report to wireshark.org)",
            EXPFILL }
        }
    };

    expert_module_t     *expert_evrc;

    /* Setup protocol subtree array */

    static gint *ett[] =
    {
        &ett_evrc,
        &ett_toc
    };

    /* Register the protocol name and description */

    proto_evrc =
        proto_register_protocol("Enhanced Variable Rate Codec", "EVRC", "evrc");

    proto_evrcb =
        proto_register_protocol_in_name_only("Enhanced Variable Rate Codec B",
        "EVRC-B", "evrcb", proto_evrc, FT_PROTOCOL);
    proto_evrcwb =
        proto_register_protocol_in_name_only("Enhanced Variable Rate Codec - Wideband",
        "EVRC-WB", "evrcwb", proto_evrc, FT_PROTOCOL);
    proto_evrcnw =
        proto_register_protocol_in_name_only("Enhanced Variable Rate Codec - Narrowband-Wideband",
        "EVRC-NW", "evrcnw", proto_evrc, FT_PROTOCOL);
    proto_evrcnw2k =
        proto_register_protocol_in_name_only("Enhanced Variable Rate Codec - Narrowband-Wideband plus 2kpbs",
        "EVRC-NW2K", "evrcnw2k", proto_evrc, FT_PROTOCOL);
    proto_evrc_legacy =
        proto_register_protocol_in_name_only("Enhanced Variable Rate Codec (Legacy Encapsulation)",
        "EVRC (Legacy)", "evrc_legacy", proto_evrc, FT_PROTOCOL);
    proto_register_field_array(proto_evrc, hf, array_length(hf));

    proto_register_subtree_array(ett, array_length(ett));

    evrc_handle        = register_dissector("evrc", dissect_evrc, proto_evrc);
    evrcb_handle       = register_dissector("evrcb", dissect_evrcb, proto_evrcb);
    evrcwb_handle      = register_dissector("evrcwb", dissect_evrcwb, proto_evrcwb);
    evrcnw_handle      = register_dissector("evrcnw", dissect_evrcnw, proto_evrcnw);
    evrcnw2k_handle    = register_dissector("evrcnw2k", dissect_evrcnw2k, proto_evrcnw2k);
    evrc_legacy_handle = register_dissector("evrc_legacy", dissect_evrc_legacy, proto_evrc_legacy);

    expert_evrc =
        expert_register_protocol(proto_evrc);
    expert_register_field_array(expert_evrc, ei, array_length(ei));

    /*
     * setup for preferences
     */
    evrc_module = prefs_register_protocol(proto_evrc, proto_reg_handoff_evrc);

    prefs_register_bool_preference(evrc_module,
        "legacy_pt_60",
        "Add dissector for static payload type 60 as legacy EVRC (non-RFC3558)",
        "Whether the EVRC dissector should process payload type 60 as legacy EVRC packets",
        &legacy_pt_60);
}


void
proto_reg_handoff_evrc(void)
{
    static gboolean             evrc_prefs_initialized = FALSE;

    if (!evrc_prefs_initialized)
    {
        /* header-full mime types */
        dissector_add_string("rtp_dyn_payload_type",  "EVRC", evrc_handle);
        dissector_add_string("rtp_dyn_payload_type",  "EVRCB", evrcb_handle);
        dissector_add_string("rtp_dyn_payload_type",  "EVRCWB", evrcwb_handle);
        dissector_add_string("rtp_dyn_payload_type",  "EVRCNW", evrcnw_handle);
        dissector_add_string("rtp_dyn_payload_type",  "EVRCNW2K", evrcnw2k_handle);

        dissector_add_for_decode_as("rtp.pt", evrc_handle);
        dissector_add_for_decode_as("rtp.pt", evrcb_handle);
        dissector_add_for_decode_as("rtp.pt", evrcwb_handle);
        dissector_add_for_decode_as("rtp.pt", evrcnw_handle);
        dissector_add_for_decode_as("rtp.pt", evrcnw2k_handle);
        /* Since the draft legacy encapsulation only appears on PT 60, not
         * adding it to decode as */
        /* dissector_add_for_decode_as("rtp.pt", evrc_legacy_handle); */
        evrc_prefs_initialized = TRUE;
    }
    else
    {
        dissector_delete_uint("rtp.pt", 60, evrc_legacy_handle);
    }

    if (legacy_pt_60)
    {
        dissector_add_uint("rtp.pt", 60, evrc_legacy_handle);
    }
}

/*
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
 *
 * Local variables:
 * c-basic-offset: 4
 * tab-width: 8
 * indent-tabs-mode: nil
 * End:
 *
 * vi: set shiftwidth=4 tabstop=8 expandtab:
 * :indentSize=4:tabSize=8:noTabs=true:
 */