diff options
author | Gerald Combs <gerald@wireshark.org> | 2007-05-25 23:40:42 +0000 |
---|---|---|
committer | Gerald Combs <gerald@wireshark.org> | 2007-05-25 23:40:42 +0000 |
commit | a491fec183044f6065b8d92a3775f5130049b636 (patch) | |
tree | 3f899da6a2bb6dead6dbfa2392764a88ac26faa6 /plugins/wimax/wimax_tlv.c | |
parent | 1e7c1bc0369f0c962ed73e8e34fa5ba7fa1a6c3d (diff) |
From Mike Harvey: Support for WiMAX and the WiMAX M2M encapsulation protocol.
Add support for WiMAX and M2M to various makefiles and installer files. Add
basic support for M2M to randpkt.
svn path=/trunk/; revision=21945
Diffstat (limited to 'plugins/wimax/wimax_tlv.c')
-rw-r--r-- | plugins/wimax/wimax_tlv.c | 188 |
1 files changed, 188 insertions, 0 deletions
diff --git a/plugins/wimax/wimax_tlv.c b/plugins/wimax/wimax_tlv.c new file mode 100644 index 0000000000..a37a653637 --- /dev/null +++ b/plugins/wimax/wimax_tlv.c @@ -0,0 +1,188 @@ +/* wimax_tlv.c + * WiMax TLV handling functions + * + * Copyright (c) 2007 by Intel Corporation. + * + * Author: Lu Pan <lu.pan@intel.com> + * + * $Id$ + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 1999 Gerald Combs + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +/*************************************************************/ +/* ----------------------- NOTE ------------------------- */ +/* There is an identical copy of this file, wimax_tlv.c, in */ +/* both .../plugins/m2m and .../plugins/wimax. If either */ +/* one needs to be modified, please be sure to copy the file */ +/* to the sister directory and check it in there also. */ +/* This prevents having to generate a complicated */ +/* Makefile.nmake in .../plugins/m2m. */ +/*************************************************************/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "wimax_tlv.h" + +/*************************************************************/ +/* init_tlv_info() */ +/* retrive the tlv information from specified tvb and offset */ +/* parameter: */ +/* this - pointer of a tlv information data structure */ +/* return: */ +/* 0-success */ +/* !=0-the invalid size of the TLV length (failed) */ +/*************************************************************/ +gint init_tlv_info(tlv_info_t *this, tvbuff_t *tvb, gint offset) +{ + guint tlv_len; + + /* get TLV type */ + this->type = (guint8)tvb_get_guint8( tvb, offset ); + /* get TLV length */ + tlv_len = (guint)tvb_get_guint8( tvb, (offset + 1) ); + /* set the TLV value offset */ + this->value_offset = 2; + /* adjust for multiple-byte TLV length */ + if((tlv_len & WIMAX_TLV_EXTENDED_LENGTH_MASK) != 0) + { /* multiple bytes TLV length */ + this->length_type = 1; + /* get the size of the TLV length */ + tlv_len = (tlv_len & WIMAX_TLV_LENGTH_MASK); + this->size_of_length = tlv_len; + /* update the TLV value offset */ + this->value_offset += tlv_len; + switch (tlv_len) + { + case 0: + this->length = 0; /* no length */ + break; + case 1: + this->length = (gint32)tvb_get_guint8( tvb, (offset + 2) ); /* 8 bit */ + break; + case 2: + this->length = (gint32)tvb_get_ntohs( tvb, (offset + 2) ); /* 16 bit */ + break; + case 3: + this->length = (gint32)tvb_get_ntoh24( tvb, (offset + 2) ); /* 24 bit */ + break; + case 4: + this->length = (gint32)tvb_get_ntohl( tvb, (offset + 2) ); /* 32 bit */ + break; + default: + /* mark invalid tlv */ + this->valid = 0; + /* failed, return the invalid size of the tlv length */ + return (gint)tlv_len; + break; + } + } + else /* single byte length */ + { + this->length_type = 0; + this->size_of_length = 0; + this->length = (gint32)tlv_len; + } + /* mark valid tlv */ + this->valid = 1; + /* success */ + return 0; +} + +/*************************************************************/ +/* get_tlv_type() */ +/* get the tlv type of the specified tlv information */ +/* parameter: */ +/* this - pointer of a tlv information data structure */ +/* return: */ +/* >=0 - TLV type */ +/* =-1 - invalid tlv info */ +/*************************************************************/ +gint get_tlv_type(tlv_info_t *this) +{ + if(this->valid) + return (gint)this->type; + return -1; +} + +/**************************************************************/ +/* get_tlv_size_of_length() */ +/* get the size of tlv length of the specified tlv information*/ +/* parameter: */ +/* this - pointer of a tlv information data structure */ +/* return: */ +/* >=0 - the size of TLV length */ +/* =-1 - invalid tlv info */ +/**************************************************************/ +gint get_tlv_size_of_length(tlv_info_t *this) +{ + if(this->valid) + return (gint)this->size_of_length; + return -1; +} + +/*************************************************************/ +/* get_tlv_length() */ +/* get the tlv length of the specified tlv information */ +/* parameter: */ +/* this - pointer of a tlv information data structure */ +/* return: */ +/* >=0 - TLV length */ +/* =-1 - invalid tlv info */ +/*************************************************************/ +gint32 get_tlv_length(tlv_info_t *this) +{ + if(this->valid) + return (gint32)this->length; + return -1; +} + +/*************************************************************/ +/* get_tlv_value_offset() */ +/* get the tlv value offset of the specified tlv information */ +/* parameter: */ +/* this - pointer of a tlv information data structure */ +/* return: */ +/* >0 - TLV value offset in byte */ +/* =-1 - invalid tlv info */ +/*************************************************************/ +gint get_tlv_value_offset(tlv_info_t *this) +{ + if(this->valid) + return (gint)this->value_offset; + return -1; +} + +/*************************************************************/ +/* get_tlv_length_type() */ +/* get the tlv length type of the specified tlv information */ +/* parameter: */ +/* this - pointer of a tlv information data structure */ +/* return: */ +/* 0 - single byte TLV length */ +/* 1 - multiple bytes TLV length */ +/*************************************************************/ +gint get_tlv_length_type(tlv_info_t *this) +{ + if(this->valid) + return (gint)this->length_type; + return -1; +} |