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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 /*************************************************************/
43 #include <plugins/wimax/wimax_tlv.h>
45 /*************************************************************/
47 /* retrive the tlv information from specified tvb and offset */
49 /* this - pointer of a tlv information data structure */
52 /* !=0-the invalid size of the TLV length (failed) */
53 /*************************************************************/
54 gint init_tlv_info(tlv_info_t *this, tvbuff_t *tvb, gint offset)
59 this->type = (guint8)tvb_get_guint8( tvb, offset );
61 tlv_len = (guint)tvb_get_guint8( tvb, (offset + 1) );
62 /* set the TLV value offset */
63 this->value_offset = 2;
64 /* adjust for multiple-byte TLV length */
65 if((tlv_len & WIMAX_TLV_EXTENDED_LENGTH_MASK) != 0)
66 { /* multiple bytes TLV length */
67 this->length_type = 1;
68 /* get the size of the TLV length */
69 tlv_len = (tlv_len & WIMAX_TLV_LENGTH_MASK);
70 this->size_of_length = tlv_len;
71 /* update the TLV value offset */
72 this->value_offset += tlv_len;
76 this->length = 0; /* no length */
79 this->length = (gint32)tvb_get_guint8( tvb, (offset + 2) ); /* 8 bit */
82 this->length = (gint32)tvb_get_ntohs( tvb, (offset + 2) ); /* 16 bit */
85 this->length = (gint32)tvb_get_ntoh24( tvb, (offset + 2) ); /* 24 bit */
88 this->length = (gint32)tvb_get_ntohl( tvb, (offset + 2) ); /* 32 bit */
91 /* mark invalid tlv */
93 /* failed, return the invalid size of the tlv length */
98 else /* single byte length */
100 this->length_type = 0;
101 this->size_of_length = 0;
102 this->length = (gint32)tlv_len;
110 /*************************************************************/
112 /* get the tlv type of the specified tlv information */
114 /* this - pointer of a tlv information data structure */
117 /* =-1 - invalid tlv info */
118 /*************************************************************/
119 gint get_tlv_type(tlv_info_t *this)
122 return (gint)this->type;
126 /**************************************************************/
127 /* get_tlv_size_of_length() */
128 /* get the size of tlv length of the specified tlv information*/
130 /* this - pointer of a tlv information data structure */
132 /* >=0 - the size of TLV length */
133 /* =-1 - invalid tlv info */
134 /**************************************************************/
135 gint get_tlv_size_of_length(tlv_info_t *this)
138 return (gint)this->size_of_length;
142 /*************************************************************/
143 /* get_tlv_length() */
144 /* get the tlv length of the specified tlv information */
146 /* this - pointer of a tlv information data structure */
148 /* >=0 - TLV length */
149 /* =-1 - invalid tlv info */
150 /*************************************************************/
151 gint32 get_tlv_length(tlv_info_t *this)
154 return (gint32)this->length;
158 /*************************************************************/
159 /* get_tlv_value_offset() */
160 /* get the tlv value offset of the specified tlv information */
162 /* this - pointer of a tlv information data structure */
164 /* >0 - TLV value offset in byte */
165 /* =-1 - invalid tlv info */
166 /*************************************************************/
167 gint get_tlv_value_offset(tlv_info_t *this)
170 return (gint)this->value_offset;
174 /*************************************************************/
175 /* get_tlv_length_type() */
176 /* get the tlv length type of the specified tlv information */
178 /* this - pointer of a tlv information data structure */
180 /* 0 - single byte TLV length */
181 /* 1 - multiple bytes TLV length */
182 /*************************************************************/
183 gint get_tlv_length_type(tlv_info_t *this)
186 return (gint)this->length_type;