2 * WiMax TLV handling functions
4 * Copyright (c) 2007 by Intel Corporation.
6 * Author: Lu Pan <lu.pan@intel.com>
10 * Wireshark - Network traffic analyzer
11 * By Gerald Combs <gerald@wireshark.org>
12 * Copyright 1999 Gerald Combs
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 /*************************************************************/
30 /* ----------------------- NOTE ------------------------- */
31 /* There is an identical copy of this file, wimax_tlv.c, in */
32 /* both .../plugins/m2m and .../plugins/wimax. If either */
33 /* one needs to be modified, please be sure to copy the file */
34 /* to the sister directory and check it in there also. */
35 /* This prevents having to generate a complicated */
36 /* Makefile.nmake in .../plugins/m2m. */
37 /*************************************************************/
41 #include "wimax_tlv.h"
43 /*************************************************************/
45 /* retrive the tlv information from specified tvb and offset */
47 /* info - pointer of a tlv information data structure */
50 /* !=0-the invalid size of the TLV length (failed) */
51 /*************************************************************/
52 gint
init_tlv_info(tlv_info_t
*info
, tvbuff_t
*tvb
, gint offset
)
57 info
->type
= (guint8
)tvb_get_guint8( tvb
, offset
);
59 tlv_len
= (guint
)tvb_get_guint8( tvb
, (offset
+ 1) );
60 /* set the TLV value offset */
61 info
->value_offset
= 2;
62 /* adjust for multiple-byte TLV length */
63 if((tlv_len
& WIMAX_TLV_EXTENDED_LENGTH_MASK
) != 0)
64 { /* multiple bytes TLV length */
65 info
->length_type
= 1;
66 /* get the size of the TLV length */
67 tlv_len
= (tlv_len
& WIMAX_TLV_LENGTH_MASK
);
68 info
->size_of_length
= tlv_len
;
69 /* update the TLV value offset */
70 info
->value_offset
+= tlv_len
;
74 info
->length
= 0; /* no length */
77 info
->length
= (gint32
)tvb_get_guint8( tvb
, (offset
+ 2) ); /* 8 bit */
80 info
->length
= (gint32
)tvb_get_ntohs( tvb
, (offset
+ 2) ); /* 16 bit */
83 info
->length
= (gint32
)tvb_get_ntoh24( tvb
, (offset
+ 2) ); /* 24 bit */
86 info
->length
= (gint32
)tvb_get_ntohl( tvb
, (offset
+ 2) ); /* 32 bit */
89 /* mark invalid tlv */
91 /* failed, return the invalid size of the tlv length */
96 else /* single byte length */
98 info
->length_type
= 0;
99 info
->size_of_length
= 0;
100 info
->length
= (gint32
)tlv_len
;
108 /*************************************************************/
110 /* get the tlv type of the specified tlv information */
112 /* info - pointer of a tlv information data structure */
115 /* =-1 - invalid tlv info */
116 /*************************************************************/
117 gint
get_tlv_type(tlv_info_t
*info
)
120 return (gint
)info
->type
;
124 /**************************************************************/
125 /* get_tlv_size_of_length() */
126 /* get the size of tlv length of the specified tlv information*/
128 /* info - pointer of a tlv information data structure */
130 /* >=0 - the size of TLV length */
131 /* =-1 - invalid tlv info */
132 /**************************************************************/
133 gint
get_tlv_size_of_length(tlv_info_t
*info
)
136 return (gint
)info
->size_of_length
;
140 /*************************************************************/
141 /* get_tlv_length() */
142 /* get the tlv length of the specified tlv information */
144 /* info - pointer of a tlv information data structure */
146 /* >=0 - TLV length */
147 /* =-1 - invalid tlv info */
148 /*************************************************************/
149 gint32
get_tlv_length(tlv_info_t
*info
)
152 return (gint32
)info
->length
;
156 /*************************************************************/
157 /* get_tlv_value_offset() */
158 /* get the tlv value offset of the specified tlv information */
160 /* info - pointer of a tlv information data structure */
162 /* >0 - TLV value offset in byte */
163 /* =-1 - invalid tlv info */
164 /*************************************************************/
165 gint
get_tlv_value_offset(tlv_info_t
*info
)
168 return (gint
)info
->value_offset
;
172 /*************************************************************/
173 /* get_tlv_length_type() */
174 /* get the tlv length type of the specified tlv information */
176 /* info - pointer of a tlv information data structure */
178 /* 0 - single byte TLV length */
179 /* 1 - multiple bytes TLV length */
180 /*************************************************************/
181 gint
get_tlv_length_type(tlv_info_t
*info
)
184 return (gint
)info
->length_type
;