epan/dissectors/pidl/ C99 drsuapi
[wireshark-sm.git] / plugins / epan / wimax / wimax_tlv.c
blobb447208fbe573ad4f4925466816d4e623ebebb9a
1 /* wimax_tlv.c
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
15 #include "config.h"
17 #include "wimax_tlv.h"
19 /**************************************************************/
20 /* init_tlv_info() */
21 /* retrieve the tlv information from specified tvb and offset */
22 /* parameter: */
23 /* info - pointer of a tlv information data structure */
24 /* return: */
25 /* 0-success */
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)
30 unsigned tlv_len;
32 /* get TLV type */
33 info->type = (uint8_t)tvb_get_uint8( tvb, offset );
34 /* get TLV length */
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;
47 switch (tlv_len)
49 case 0:
50 info->length = 0; /* no length */
51 break;
52 case 1:
53 info->length = (int32_t)tvb_get_uint8( tvb, (offset + 2) ); /* 8 bit */
54 break;
55 case 2:
56 info->length = (int32_t)tvb_get_ntohs( tvb, (offset + 2) ); /* 16 bit */
57 break;
58 case 3:
59 info->length = (int32_t)tvb_get_ntoh24( tvb, (offset + 2) ); /* 24 bit */
60 break;
61 case 4:
62 info->length = (int32_t)tvb_get_ntohl( tvb, (offset + 2) ); /* 32 bit */
63 break;
64 default:
65 /* mark invalid tlv */
66 info->valid = 0;
67 /* failed, return the invalid size of the tlv length */
68 return (int)tlv_len;
69 break;
72 else /* single byte length */
74 info->length_type = 0;
75 info->size_of_length = 0;
76 info->length = (int32_t)tlv_len;
78 /* mark valid tlv */
79 info->valid = 1;
80 /* success */
81 return 0;
84 /*************************************************************/
85 /* get_tlv_type() */
86 /* get the tlv type of the specified tlv information */
87 /* parameter: */
88 /* info - pointer of a tlv information data structure */
89 /* return: */
90 /* >=0 - TLV type */
91 /* =-1 - invalid tlv info */
92 /*************************************************************/
93 int get_tlv_type(tlv_info_t *info)
95 if(info->valid)
96 return (int)info->type;
97 return -1;
100 /**************************************************************/
101 /* get_tlv_size_of_length() */
102 /* get the size of tlv length of the specified tlv information*/
103 /* parameter: */
104 /* info - pointer of a tlv information data structure */
105 /* return: */
106 /* >=0 - the size of TLV length */
107 /* =-1 - invalid tlv info */
108 /**************************************************************/
109 int get_tlv_size_of_length(tlv_info_t *info)
111 if(info->valid)
112 return (int)info->size_of_length;
113 return -1;
116 /*************************************************************/
117 /* get_tlv_length() */
118 /* get the tlv length of the specified tlv information */
119 /* parameter: */
120 /* info - pointer of a tlv information data structure */
121 /* return: */
122 /* >=0 - TLV length */
123 /* =-1 - invalid tlv info */
124 /*************************************************************/
125 int32_t get_tlv_length(tlv_info_t *info)
127 if(info->valid)
128 return (int32_t)info->length;
129 return -1;
132 /*************************************************************/
133 /* get_tlv_value_offset() */
134 /* get the tlv value offset of the specified tlv information */
135 /* parameter: */
136 /* info - pointer of a tlv information data structure */
137 /* return: */
138 /* >0 - TLV value offset in byte */
139 /* =-1 - invalid tlv info */
140 /*************************************************************/
141 int get_tlv_value_offset(tlv_info_t *info)
143 if(info->valid)
144 return (int)info->value_offset;
145 return -1;
148 /*************************************************************/
149 /* get_tlv_length_type() */
150 /* get the tlv length type of the specified tlv information */
151 /* parameter: */
152 /* info - pointer of a tlv information data structure */
153 /* return: */
154 /* 0 - single byte TLV length */
155 /* 1 - multiple bytes TLV length */
156 /*************************************************************/
157 int get_tlv_length_type(tlv_info_t *info)
159 if(info->valid)
160 return (int)info->length_type;
161 return -1;
165 * Editor modelines - https://www.wireshark.org/tools/modelines.html
167 * Local variables:
168 * c-basic-offset: 8
169 * tab-width: 8
170 * indent-tabs-mode: t
171 * End:
173 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
174 * :indentSize=8:tabSize=8:noTabs=false: