2 * WiMax TLV handling functions
4 * Copyright (c) 2007 by Intel Corporation.
6 * Author: Lu Pan <lu.pan@intel.com>
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 1999 Gerald Combs
12 * SPDX-License-Identifier: GPL-2.0-or-later
17 #include "wimax_tlv.h"
19 /**************************************************************/
21 /* retrieve the tlv information from specified tvb and offset */
23 /* info - pointer of a tlv information data structure */
26 /* !=0-the invalid size of the TLV length (failed) */
27 /**************************************************************/
28 int init_tlv_info(tlv_info_t
*info
, tvbuff_t
*tvb
, int offset
)
33 info
->type
= (uint8_t)tvb_get_uint8( tvb
, offset
);
35 tlv_len
= (unsigned)tvb_get_uint8( tvb
, (offset
+ 1) );
36 /* set the TLV value offset */
37 info
->value_offset
= 2;
38 /* adjust for multiple-byte TLV length */
39 if((tlv_len
& WIMAX_TLV_EXTENDED_LENGTH_MASK
) != 0)
40 { /* multiple bytes TLV length */
41 info
->length_type
= 1;
42 /* get the size of the TLV length */
43 tlv_len
= (tlv_len
& WIMAX_TLV_LENGTH_MASK
);
44 info
->size_of_length
= tlv_len
;
45 /* update the TLV value offset */
46 info
->value_offset
+= tlv_len
;
50 info
->length
= 0; /* no length */
53 info
->length
= (int32_t)tvb_get_uint8( tvb
, (offset
+ 2) ); /* 8 bit */
56 info
->length
= (int32_t)tvb_get_ntohs( tvb
, (offset
+ 2) ); /* 16 bit */
59 info
->length
= (int32_t)tvb_get_ntoh24( tvb
, (offset
+ 2) ); /* 24 bit */
62 info
->length
= (int32_t)tvb_get_ntohl( tvb
, (offset
+ 2) ); /* 32 bit */
65 /* mark invalid tlv */
67 /* failed, return the invalid size of the tlv length */
72 else /* single byte length */
74 info
->length_type
= 0;
75 info
->size_of_length
= 0;
76 info
->length
= (int32_t)tlv_len
;
84 /*************************************************************/
86 /* get the tlv type of the specified tlv information */
88 /* info - pointer of a tlv information data structure */
91 /* =-1 - invalid tlv info */
92 /*************************************************************/
93 int get_tlv_type(tlv_info_t
*info
)
96 return (int)info
->type
;
100 /**************************************************************/
101 /* get_tlv_size_of_length() */
102 /* get the size of tlv length of the specified tlv information*/
104 /* info - pointer of a tlv information data structure */
106 /* >=0 - the size of TLV length */
107 /* =-1 - invalid tlv info */
108 /**************************************************************/
109 int get_tlv_size_of_length(tlv_info_t
*info
)
112 return (int)info
->size_of_length
;
116 /*************************************************************/
117 /* get_tlv_length() */
118 /* get the tlv length of the specified tlv information */
120 /* info - pointer of a tlv information data structure */
122 /* >=0 - TLV length */
123 /* =-1 - invalid tlv info */
124 /*************************************************************/
125 int32_t get_tlv_length(tlv_info_t
*info
)
128 return (int32_t)info
->length
;
132 /*************************************************************/
133 /* get_tlv_value_offset() */
134 /* get the tlv value offset of the specified tlv information */
136 /* info - pointer of a tlv information data structure */
138 /* >0 - TLV value offset in byte */
139 /* =-1 - invalid tlv info */
140 /*************************************************************/
141 int get_tlv_value_offset(tlv_info_t
*info
)
144 return (int)info
->value_offset
;
148 /*************************************************************/
149 /* get_tlv_length_type() */
150 /* get the tlv length type of the specified tlv information */
152 /* info - pointer of a tlv information data structure */
154 /* 0 - single byte TLV length */
155 /* 1 - multiple bytes TLV length */
156 /*************************************************************/
157 int get_tlv_length_type(tlv_info_t
*info
)
160 return (int)info
->length_type
;
165 * Editor modelines - https://www.wireshark.org/tools/modelines.html
170 * indent-tabs-mode: t
173 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
174 * :indentSize=8:tabSize=8:noTabs=false: