Wireshark-commits: [Wireshark-commits] master 2046666: csn1: fix M_UINT_OFFSET: show value after ap
From: Wireshark code review <code-review-do-not-reply@xxxxxxxxxxxxx>
Date: Fri, 24 Jul 2020 06:00:59 +0000
URL: https://code.wireshark.org/review/gitweb?p=wireshark.git;a=commit;h=2046666b970ff37353a6776d2d903bff5ee36d1a
Submitter: "Anders Broman <a.broman58@xxxxxxxxx>"
Changed: branch: master
Repository: wireshark

Commits:

2046666 by Vadim Yanitskiy (vyanitskiy@xxxxxxxxxxx):

    csn1: fix M_UINT_OFFSET: show value after applying the offset
    
    Some integer fields in CSN.1 structures can be encoded with an offset.
    A good example is GPRS Mobile Allocation IE defined in 3GPP TS 44.060,
    section 12.10a, table 12.10a.1:
    
      < GPRS Mobile Allocation IE > ::=
        < HSN : bit (6) >
        { 0 | 1  < RFL number list : < RFL number list struct > > }
        {     0  < MA_LENGTH : bit (6) >
                 < MA_BITMAP : bit (val(MA_LENGTH) + 1) >
            | 1  { 0 | 1  < ARFCN index list : < ARFCN index list struct > > }
        } ;
    
    so in this case the variable-length MA_BITMAP is defined as follows:
    
      < MA_BITMAP : bit (val(MA_LENGTH) + 1) >
    
    what basically means that its bit length shall be encoded with
    a negative offset 1, therefore the following statements apply:
    
      MA_LENGTH=0 defines MA_BITMAP of bit length 1
      MA_LENGTH=1 defines MA_BITMAP of bit length 2
      ...
      MA_LENGTH=63 defines MA_BITMAP of bit length 64
    
    == What's wrong? ==
    
    For some reason, Wireshark shows the raw values without applying
    the offset.  Here is an example of GPRS Mobile Allocation IE:
    
      GPRS_Mobile_Allocation
          .... .101  010. .... = HSN: 42
          ...0 .... = RFL_NUMBER Exist: 0
          .... 0... = Mobile Allocation:  (Union)
          u.MA
              .... .001  111. .... = Bit length: 15
              ...0 .... = Bitmap: 0 // 1st
              .... 1... = Bitmap: 1
              .... .0.. = Bitmap: 0
              .... ..1. = Bitmap: 1
              .... ...0 = Bitmap: 0
              1... .... = Bitmap: 1
              .0.. .... = Bitmap: 0
              ..1. .... = Bitmap: 1  // 8th
              ...0 .... = Bitmap: 0
              .... 1... = Bitmap: 1
              .... .0.. = Bitmap: 0
              .... ..1. = Bitmap: 1
              .... ...0 = Bitmap: 0
              1... .... = Bitmap: 1
              .0.. .... = Bitmap: 0
              ..1. .... = Bitmap: 1 // 16th
    
    == Solution ==
    
    Let's use proto_tree_add_uint_bits_format_value(), so we can print
    the final value with the offset applied, as well as the original
    one and the offset itself:
    
      GPRS_Mobile_Allocation
          .... .101  010. .... = HSN: 42
          ...0 .... = RFL_NUMBER Exist: 0
          .... 0... = Mobile Allocation:  (Union)
          u.MA
              .... .001  111. .... = Bit length: 16 (Raw 15 + Offset 1)
    
    Change-Id: Ic4eaf2d8a3c2fedca855726e4175ddf47d16c5af
    Reviewed-on: https://code.wireshark.org/review/37931
    Petri-Dish: Anders Broman <a.broman58@xxxxxxxxx>
    Tested-by: Petri Dish Buildbot
    Reviewed-by: Anders Broman <a.broman58@xxxxxxxxx>
    

Actions performed:

    from  26c4120   GTP: extend TPDU Heuristic for ethernet frames
     add  2046666   csn1: fix M_UINT_OFFSET: show value after applying the offset


Summary of changes:
 epan/dissectors/packet-csn1.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)