~ubuntu-branches/ubuntu/gutsy/wireshark/gutsy-security

« back to all changes in this revision

Viewing changes to epan/dissectors/packet-amr.c

  • Committer: Bazaar Package Importer
  • Author(s): Frederic Peters
  • Date: 2007-04-01 08:58:40 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20070401085840-or3qhrpv8alt1bwg
Tags: 0.99.5-1
* New upstream release.
* debian/patches/09_idl2wrs.dpatch: updated to patch idl2wrs.sh.in.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 * Routines for AMR dissection
3
3
 * Copyright 2005, Anders Broman <anders.broman[at]ericsson.com>
4
4
 *
5
 
 * $Id: packet-amr.c 18587 2006-06-27 19:16:38Z etxrab $
 
5
 * $Id: packet-amr.c 19769 2006-11-01 22:58:41Z etxrab $
6
6
 *
7
7
 * Wireshark - Network traffic analyzer
8
8
 * By Gerald Combs <gerald@wireshark.org>
23
23
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
24
 *
25
25
 * References:
26
 
 * RFC 3267 
27
 
 * http://www.ietf.org/rfc/rfc3267.txt?number=3267
 
26
 * RFC 3267  http://www.ietf.org/rfc/rfc3267.txt?number=3267
 
27
 * 3GPP TS 26.101
28
28
 */
29
29
 
30
30
#ifdef HAVE_CONFIG_H
52
52
static int hf_amr_toc_f         = -1;
53
53
static int hf_amr_toc_ft        = -1;
54
54
static int hf_amr_toc_q         = -1;
55
 
static int hf_amr_toc_f_unaligned1 = -1;
56
 
static int hf_amr_toc_ft_unaligned1 = -1;
57
 
static int hf_amr_toc_q_unaligned1 = -1;
58
 
static int hf_amr_toc_f_unaligned2 = -1;
59
 
static int hf_amr_toc_ft_unaligned2 = -1;
60
 
static int hf_amr_toc_q_unaligned2 = -1;
61
55
 
62
56
static int hf_amr_if1_ft = -1;
63
57
static int hf_amr_if1_fqi = -1;
69
63
 
70
64
static int hf_amr_if2_ft = -1;
71
65
 
 
66
static int hf_amr_be_reserved = -1;
 
67
static int hf_amr_be_ft = -1;
 
68
static int hf_amr_be_reserved2 = -1;
 
69
 
72
70
 
73
71
/* Initialize the subtree pointers */
74
72
static int ett_amr = -1;
85
83
 
86
84
static const value_string amr_encoding_type_value[] = {
87
85
        {0,                     "RFC 3267"}, 
88
 
        {1,                     "RFC 3267 bandwidth-efficient mode"}, /* Not coded */
 
86
        {1,                     "RFC 3267 bandwidth-efficient mode"}, 
89
87
        {2,                     "AMR IF 1"},
90
88
        {3,                     "AMR IF 2"},
91
89
        { 0,    NULL }
103
101
        { 0,    NULL }
104
102
};
105
103
 
 
104
/* Ref 3GPP TS 26.101 table 1a */
106
105
static const value_string amr_codec_mode_request_vals[] = {
107
106
        {0,                     "AMR 4,75 kbit/s"}, 
108
107
        {1,                     "AMR 5,15 kbit/s"},
182
181
                col_append_fstr(pinfo->cinfo, COL_INFO, "%s ",
183
182
                        val_to_str(octet, amr_codec_mode_request_vals, "Unknown (%d)" ));
184
183
}
 
184
/*
 
185
 * 4.3.5.1. Single Channel Payload Carrying a Single Frame
 
186
 * 
 
187
 *    The following diagram shows a bandwidth-efficient AMR payload from a
 
188
 *    single channel session carrying a single speech frame-block.
 
189
 * 
 
190
 *    In the payload, no specific mode is requested (CMR=15), the speech
 
191
 *    frame is not damaged at the IP origin (Q=1), and the coding mode is
 
192
 *    AMR 7.4 kbps (FT=4).  The encoded speech bits, d(0) to d(147), are
 
193
 *    arranged in descending sensitivity order according to [2].  Finally,
 
194
 *    two zero bits are added to the end as padding to make the payload
 
195
 *    octet aligned.
 
196
 * 
 
197
 *     0                   1                   2                   3
 
198
 *     0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
 
199
 *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 
200
 *    | CMR=15|0| FT=4  |1|d(0)                                       |
 
201
 *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 
202
 */
 
203
static void
 
204
dissect_amr_be(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree){
 
205
        proto_item *item;
 
206
        guint8 octet;
 
207
        int offset =0;
185
208
 
 
209
        proto_tree_add_item(tree, hf_amr_cmr, tvb, offset, 1, FALSE);
 
210
        proto_tree_add_item(tree, hf_amr_be_reserved, tvb, offset, 1, FALSE);
 
211
        octet = tvb_get_guint8(tvb,offset) & 0x08;
 
212
        if ( octet != 0  ){
 
213
                item = proto_tree_add_text(tree, tvb, offset, -1, "Reserved != 0, wrongly encoded or not bandwidth-efficient.");
 
214
                PROTO_ITEM_SET_GENERATED(item);
 
215
                return;
 
216
        }
 
217
        proto_tree_add_item(tree, hf_amr_be_ft, tvb, offset, 2, FALSE);
 
218
        proto_tree_add_item(tree, hf_amr_be_reserved2, tvb, offset, 2, FALSE);
 
219
        offset++;
 
220
        octet = tvb_get_guint8(tvb,offset) & 0x40;
 
221
        if ( octet != 0x40  ){
 
222
                item = proto_tree_add_text(tree, tvb, offset, -1, "Reserved != 1, wrongly encoded or not bandwidth-efficient.");
 
223
                PROTO_ITEM_SET_GENERATED(item);
 
224
                return;
 
225
        }
 
226
        
 
227
}
186
228
/* Code to actually dissect the packets */
187
229
static void
188
230
dissect_amr(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
208
250
                proto_tree_add_text(amr_tree, tvb, offset, -1, "Payload decoded as %s",val_to_str(amr_encoding_type, amr_encoding_type_value, "Unknown value - Error"));
209
251
 
210
252
                switch (amr_encoding_type){
211
 
                case 0:
212
 
                case 1:
 
253
                case 0: /* RFC 3267 Byte aligned */
213
254
                        break;
 
255
                case 1: /* RFC 3267 Bandwidth-efficient */
 
256
                        dissect_amr_be(tvb, pinfo, amr_tree);
 
257
                        return;
214
258
                case 2: /* AMR IF1 */
215
259
                        dissect_amr_if1(tvb, pinfo, amr_tree);
216
260
                        return;
228
272
                if ( octet != 0  ){
229
273
                        item = proto_tree_add_text(amr_tree, tvb, offset, -1, "Reserved != 0, wrongly encoded or not octet aligned. Decoding as bandwidth-efficient mode");
230
274
                        PROTO_ITEM_SET_GENERATED(item);
231
 
                        if (!tvb_length_remaining(tvb,offset))
232
 
                                return;
233
 
                        /*     0 1 2 3 4 5
234
 
                         *   +-+-+-+-+-+-+
235
 
                         *   |F|  FT   |Q|
236
 
                         *   +-+-+-+-+-+-+
237
 
                         */
238
 
 
239
 
                        toc_item = proto_tree_add_text(amr_tree, tvb, offset, -1, "Payload Table of Contents");
240
 
                        toc_tree = proto_item_add_subtree(toc_item, ett_amr_toc);
241
 
 
242
 
                        proto_tree_add_item(amr_tree, hf_amr_toc_f_unaligned1, tvb, offset, 2, FALSE);
243
 
                        proto_tree_add_item(amr_tree, hf_amr_toc_ft_unaligned1, tvb, offset, 2, FALSE);
244
 
                        proto_tree_add_item(amr_tree, hf_amr_toc_q_unaligned1, tvb, offset, 2, FALSE);
245
 
                        if (octet & 0x04)
246
 
                                return;
247
 
                        octet = tvb_get_guint8(tvb,offset+1);
248
 
                        proto_tree_add_item(amr_tree, hf_amr_toc_f_unaligned2, tvb, offset, 2, FALSE);
249
 
                        proto_tree_add_item(amr_tree, hf_amr_toc_ft_unaligned2, tvb, offset, 2, FALSE);
250
 
                        proto_tree_add_item(amr_tree, hf_amr_toc_q_unaligned2, tvb, offset, 2, FALSE);
251
 
                        if (octet & 0x20)
252
 
                                return;
253
275
                        return;
 
276
 
254
277
                }
255
278
 
256
279
                proto_tree_add_item(amr_tree, hf_amr_reserved, tvb, offset, 1, FALSE);
257
280
                offset++;
258
281
                toc_offset = offset;
259
 
                /* If interleaced ILL and ILP follows here */
260
 
 
261
 
                /* Payload Table of Contents 
262
 
                 * A ToC entry takes the following format in octet-aligned mode:
263
 
                 *
264
 
                 *  0 1 2 3 4 5 6 7
265
 
                 * +-+-+-+-+-+-+-+-+
266
 
                 * |F|  FT   |Q|P|P|
267
 
                 * +-+-+-+-+-+-+-+-+
 
282
                /*
 
283
                 *  A ToC entry takes the following format in octet-aligned mode:
 
284
                 *
 
285
                 *    0 1 2 3 4 5 6 7
 
286
                 *   +-+-+-+-+-+-+-+-+
 
287
                 *   |F|  FT   |Q|P|P|
 
288
                 *   +-+-+-+-+-+-+-+-+
 
289
                 *
 
290
                 *   F (1 bit): see definition in Section 4.3.2.
 
291
                 *
 
292
                 *   FT (4 bits unsigned integer): see definition in Section 4.3.2.
 
293
                 *
 
294
                 *   Q (1 bit): see definition in Section 4.3.2.
 
295
                 *
 
296
                 *   P bits: padding bits, MUST be set to zero.
268
297
                 */
269
298
                octet = tvb_get_guint8(tvb,offset);
270
299
                toc_item = proto_tree_add_text(amr_tree, tvb, offset, -1, "Payload Table of Contents");
344
373
                { &hf_amr_toc_ft,
345
374
                        { "FT bits",           "amr.toc.ft",
346
375
                        FT_UINT8, BASE_DEC, VALS(amr_codec_mode_request_vals), 0x78,          
347
 
                        "FT bits", HFILL }
 
376
                        "Frame type index", HFILL }
348
377
                },
349
378
                { &hf_amr_toc_q,
350
379
                        { "Q bit",           "amr.toc.q",
351
380
                        FT_BOOLEAN, 8, TFS(&toc_q_bit_vals), 0x04,          
352
381
                        "Frame quality indicator bit", HFILL }
353
382
                },
354
 
                { &hf_amr_toc_f_unaligned1,
355
 
                        { "F bit",           "amr.toc.f.ual1",
356
 
                        FT_BOOLEAN, 16, TFS(&toc_f_bit_vals), 0x0800,          
357
 
                        "F bit", HFILL }
358
 
                },
359
 
                { &hf_amr_toc_ft_unaligned1,
360
 
                        { "FT bits",           "amr.toc.ft.ual1",
361
 
                        FT_UINT16, BASE_DEC, VALS(amr_codec_mode_request_vals), 0x0780,          
362
 
                        "FT bits", HFILL }
363
 
                },
364
 
                { &hf_amr_toc_q_unaligned1,
365
 
                        { "Q bit",           "amr.toc.ua1.q.ual1",
366
 
                        FT_BOOLEAN, 16, TFS(&toc_q_bit_vals), 0x0040,          
367
 
                        "Frame quality indicator bit", HFILL }
368
 
                },
369
 
                { &hf_amr_toc_f_unaligned2,
370
 
                        { "F bit",           "amr.toc.f.ual2",
371
 
                        FT_BOOLEAN, 16, TFS(&toc_f_bit_vals), 0x0020,          
372
 
                        "F bit", HFILL }
373
 
                },
374
 
                { &hf_amr_toc_ft_unaligned2,
375
 
                        { "FT bits",           "amr.toc.ft.ual2",
376
 
                        FT_UINT16, BASE_DEC, VALS(amr_codec_mode_request_vals), 0x001e,          
377
 
                        "FT bits", HFILL }
378
 
                },
379
 
                { &hf_amr_toc_q_unaligned2,
380
 
                        { "Q bit",           "amr.toc.ua1.q.ual2",
381
 
                        FT_BOOLEAN, 16, TFS(&toc_q_bit_vals), 0x00001,          
382
 
                        "Frame quality indicator bit", HFILL }
383
 
                },
384
383
                { &hf_amr_if1_ft,
385
384
                        { "Frame Type",           "amr.if1.ft",
386
385
                        FT_UINT8, BASE_DEC, VALS(amr_codec_mode_request_vals), 0xf0,          
421
420
                        FT_BOOLEAN, 8, TFS(&toc_q_bit_vals), 0x08,          
422
421
                        "Frame quality indicator bit", HFILL }
423
422
                },
 
423
                { &hf_amr_be_reserved,
 
424
                        { "Reserved",           "amr.be.reserved",
 
425
                        FT_UINT8, BASE_DEC, NULL, 0x08,          
 
426
                        "Reserved", HFILL }
 
427
                },
 
428
                { &hf_amr_be_ft,
 
429
                        { "Frame Type",           "amr.be.ft",
 
430
                        FT_UINT16, BASE_DEC, VALS(amr_codec_mode_request_vals), 0x0780,          
 
431
                        "Frame Type", HFILL }
 
432
                },
 
433
                { &hf_amr_be_reserved2,
 
434
                        { "Reserved",           "amr.be.reserved2",
 
435
                        FT_UINT16, BASE_DEC, NULL, 0x0040,          
 
436
                        "Reserved", HFILL }
 
437
                },
424
438
        };
425
439
 
426
440
/* Setup protocol subtree array */
429
443
                &ett_amr_toc,
430
444
        };
431
445
    static enum_val_t encoding_types[] = {
432
 
        {"RFC 3267 Byte aligned", "RFC 3267", 0},
 
446
        {"RFC 3267 Byte aligned", "RFC 3267 octet aligned", 0},
 
447
        {"RFC 3267 Bandwidth-efficient", "RFC 3267 BW-efficient", 1}, 
433
448
        {"AMR IF1", "AMR IF1", 2},
434
449
        {"AMR IF2", "AMR IF2", 3},
435
450
        {NULL, NULL, -1}