Ethereal-dev: [ethereal-dev] Hints for WAP WTP processing in packet-wtp.c

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: Biot Olivier <Olivier.Biot@xxxxxxxxxxxxxxx>
Date: Tue, 15 Jan 2002 16:47:55 +0100
Hi all,

I've been looking at the current WTP dissecting code, and have some initital
suggestions for making TPI parsing possible. There's a "if ( fCon ) { }"
loop hopping over the TPI part (lines 345-358). Currently it's not doing
anything but hopping. Unfortunately I don't have the time to write any
additions (and my compiler environment is broken), so I'm just sending in
untested code snippets and suggestions:

/1/ In the declarations section, add:

<<<<< start >>>>>
static int hf_wtp_header_tpi_type = HF_EMPTY;
static const value_string vals_tpi_type[] = {
	{ 0x00, "Error TPI" },
	{ 0x01, "Info TPI" },
	{ 0x02, "Option TPI" },
	{ 0x03, "Packet Sequence Number TPI" },
	{ OxO4, "SDU Boundary TPI" },
	{ 0x05, "Frame Boundary TPI" },
	{ 0x00, NULL }
};
<<<<<  end  >>>>>

/2/ Move the TPI scanning part from lines 345-358 to after the next "switch(
pdut )" statement starting at line 415 and ending at line 530, into the
existing "if ( fCon ) {}"
construct from lines 532-546, and "replace" it by something like :
<<<<< start >>>>>
    if( fCon ) {            /* Scan variable part (TPI's)   */
        unsigned char   tCon;
        unsigned char   tByte;
        unsigned char   tpiType;
        unsigned char   tpiLen;

        do {
            tByte = tvb_get_guint8(tvb, offCur + cbHeader + vHeader);
            tCon = tByte & 0x80;
            tpiType = (tByte & 0x38) >> 3;
            if (tByte & 0x04) /* Long TPI format */
                tpiLen = 2 + tvb_get_guint8(tvb,
                    offCur + cbHeader + vHeader + 1);
            else              /* Short TPI format */
                tpiLen = 1 + (tByte & 0x03);
            /* Process TPI */
            proto_tree_add_uint(wtp_tpi_tree, hf_wtp_header_tpi_type,
                    tvb, offCur + cbHeader + vHeader, tpiLen, tpiType);

            vHeader += tpiLen;
        } while (tCon);
    }
<<<<<  end  >>>>>
This has some implications since the code in the lines 360-- sometimes makes
use of the vHeader parameter; perhaps we should move those statements behind
the "switch(pdut)" statement and "if (fCon)" too, otherwise we'll have to
parse the variable header part twice (once for getting its length, and once
for really parsing the TPIs).

Finally, create the header field, e.g., 
<<<<< start >>>>>
	{ &hf_wtp_header_tpi_type,
		{ "TPI Type",
		  "wtp.header.tpi.type",
		  FT_UINT8, BASE_HEX, VALS (vals_tpi_type), 0x00,
		  "TPI Type", HFILL
		}
	},
<<<<<  end  >>>>>

Any suggestions?

Regards,

  Olivier Biot                     Siemens ATEA IC D MS C
O-------------------------------o-------------------------------O
| Phone   : +32  (14) 25 39 84  |  Address: Atealaan 34         |
| Fax     : +32  (14) 22 29 94  |           2200 Herentals      |
| Cellular: +32 (474) 96 32 09  |           Belgium             |
O-------------------------------o-------------------------------O
~  "While you're waiting, read the free novel we sent you.      ~
~   It's a Spanish story about a guy named `Manual'" - Dilbert  ~