⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 plugins-wimax-wimax_utils.c

📁 Intel的WIMAX代码,主要是mac层code
💻 C
📖 第 1 页 / 共 4 页
字号:
				tlv_tree = add_tlv_subtree(&tlv_info, ett_sa_descriptor_decoder, tree, hf_pkm_attr_sa_service_type, tvb, offset, tlv_len, FALSE);
				proto_tree_add_item(tlv_tree, hf_pkm_attr_sa_service_type, tvb, offset, tlv_len, FALSE);
			break;
			case PKM_ATTR_CRYPTO_SUITE:
				/* add subtree */
				tlv_tree = add_tlv_subtree(&tlv_info, ett_sa_descriptor_decoder, tree, hf_pkm_msg_crypto_suite, tvb, offset, tlv_len, FALSE);
				proto_tree_add_item(tlv_tree, hf_pkm_msg_crypto_suite_msb, tvb, offset, 1, FALSE);
				proto_tree_add_item(tlv_tree, hf_pkm_msg_crypto_suite_middle, tvb, offset, 1, FALSE);
				proto_tree_add_item(tlv_tree, hf_pkm_msg_crypto_suite_lsb, tvb, offset, 1, FALSE);
			break;
			default:
				tlv_tree = add_tlv_subtree(&tlv_info, ett_sa_descriptor_decoder, tree, hf_pkm_msg_unknown_type, tvb, offset, tlv_len, FALSE);
				proto_tree_add_item(tlv_tree, hf_pkm_msg_unknown_type, tvb, offset, tlv_len, FALSE);
			break;
		}
		offset += tlv_len;
	}	/* end of TLV process while loop */
}

/******************************************************************/
/* wimax_security_capabilities_decoder()                          */
/* decode and display the WiMax Security Capabilities             */
/* parameter:                                                     */
/*   tvb - pointer of the tvb of service flow encodings           */
/*   tree - pointer of Wireshark display tree                     */
/*   pinfo - pointer of Wireshark packet information structure    */
/******************************************************************/
void wimax_security_capabilities_decoder(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
	guint offset;
	guint tvb_len, tlv_len, tlv_value_offset;
	gint  tlv_type;
	proto_tree *tlv_tree = NULL;
	tlv_info_t tlv_info;

	/* get the tvb reported length */
	tvb_len = tvb_reported_length(tvb);
	/* do nothing if the TLV fields is not exist */
	if(!tvb_len)
		return;
	/* report error if the packet size is less than 2 bytes (type+length) */
	if(tvb_len < 2)
	{	/* invalid tlv info */
		if(pinfo->cinfo)
		{
			col_append_sep_str(pinfo->cinfo, COL_INFO, NULL, "Invalid Security Capabilities");
		}
		return;
	}
	/* process Security Capabilities (11.9.13) */
	for(offset = 0; offset < tvb_len; )
	{
		/* get the TLV information */
		init_tlv_info(&tlv_info, tvb, offset);
		/* get the TLV type */
		tlv_type = get_tlv_type(&tlv_info);
		/* get the TLV length */
		tlv_len = get_tlv_length(&tlv_info);
		if(tlv_type == -1 || tlv_len > MAX_TLV_LEN || tlv_len < 1)
		{	/* invalid tlv info */
			if(pinfo->cinfo)
			{
				col_append_sep_str(pinfo->cinfo, COL_INFO, NULL, "Security Capabilities TLV error");
			}
			proto_tree_add_item(tree, hf_cst_invalid_tlv, tvb, offset, (tvb_len - offset), FALSE);
			break;
		}
		/* get the TLV value offset */
		tlv_value_offset = get_tlv_value_offset(&tlv_info);
#ifdef DEBUG /* for debug only */
		proto_tree_add_protocol_format(tree, proto_wimax_utility_decoders, tvb, offset, (tlv_len + tlv_value_offset), "Security Capabilities TLV Type: %u (%u bytes, offset=%u, tvb_len=%u)", tlv_type, (tlv_len + tlv_value_offset), offset, tvb_len);
#endif
		/* update the offset for the TLV value */
		offset += tlv_value_offset;
		/* parse Security Capabilities (table 374) */
		switch (tlv_type)
		{
			case PKM_ATTR_CRYPTO_LIST:
				tlv_tree = add_protocol_subtree(&tlv_info, ett_security_capabilities_decoder, tree, proto_wimax_utility_decoders, tvb, offset, tlv_len, "Cryptographic-Suite List (%u bytes)", tlv_len);
				/* add subtree */
				wimax_cryptographic_suite_list_decoder(tvb_new_subset(tvb, offset, tlv_len, tlv_len), pinfo, tlv_tree);
			break;
			default:
				tlv_tree = add_tlv_subtree(&tlv_info, ett_security_capabilities_decoder, tree, proto_wimax_utility_decoders, tvb, offset, tlv_len, FALSE);
				proto_tree_add_item(tlv_tree, hf_pkm_msg_unknown_type, tvb, offset, tlv_len, FALSE);
			break;
		}
		offset += tlv_len;
	}	/* end of TLV process while loop */
}

/******************************************************************/
/* wimax_vendor_specific_information_decoder()                    */
/* decode and display the WiMax Vendor-Specific Information       */
/* parameter:                                                     */
/*   tvb - pointer of the tvb of service flow encodings           */
/*   tree - pointer of Wireshark display tree                     */
/*   pinfo - pointer of Wireshark packet information structure    */
/******************************************************************/
void wimax_vendor_specific_information_decoder(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
	proto_tree *tlv_tree = NULL;
	guint offset;
	guint tvb_len, tlv_len, tlv_value_offset;
	gint  tlv_type;
	tlv_info_t tlv_info;

	/* get the tvb reported length */
	tvb_len = tvb_reported_length(tvb);
	/* do nothing if the TLV fields is not exist */
	if(!tvb_len)
		return;
	/* report error if the packet size is less than 2 bytes (type+length) */
	if(tvb_len < 2)
	{	/* invalid tlv info */
		if(pinfo->cinfo)
		{
			col_append_sep_str(pinfo->cinfo, COL_INFO, NULL, "Invalid Vendor Specific Info");
		}
		proto_tree_add_text(tree, tvb, 0, tvb_len, "Invalid TLV info");
		return;
	}
	/* process Vendor Specific Information (11.1.6) */
	for(offset = 0; offset < tvb_len; )
	{
		/* get the TLV information */
		init_tlv_info(&tlv_info, tvb, offset);
		/* get the TLV type */
		tlv_type = get_tlv_type(&tlv_info);
		/* get the TLV length */
		tlv_len = get_tlv_length(&tlv_info);
		if(tlv_type == -1 || tlv_len > MAX_TLV_LEN || tlv_len < 1)
		{	/* invalid tlv info */
			if(pinfo->cinfo)
			{
				col_append_sep_str(pinfo->cinfo, COL_INFO, NULL, "Vendor Specific Info TLV error");
			}
			proto_tree_add_item(tree, hf_cst_invalid_tlv, tvb, offset, (tvb_len - offset), FALSE);
			break;
		}
		/* get the TLV value offset */
		tlv_value_offset = get_tlv_value_offset(&tlv_info);
#ifdef DEBUG /* for debug only */
		proto_tree_add_protocol_format(tree, proto_wimax_utility_decoders, tvb, offset, (tlv_len + tlv_value_offset), "Vendor Specific Info TLV Type: %u (%u bytes, offset=%u, tvb_len=%u)", tlv_type, (tlv_len + tlv_value_offset), offset, tvb_len);
#endif
		/* parse Vendor Specific Information (11.1.6) */
		if(tlv_type == VENDOR_ID_ENCODING)
		{
			/* decode and display the Vendor ID Encoding */
			tlv_tree = add_tlv_subtree(&tlv_info, ett_vendor_id_encoding_decoder, tree, hf_common_tlv_vendor_id, tvb, (offset + tlv_value_offset), tlv_len, FALSE);
			proto_tree_add_item(tlv_tree, hf_common_tlv_vendor_id, tvb, (offset + tlv_value_offset), tlv_len, FALSE);
		}
		else
		{
			/* decode and display the Vendor Specific Info */
			proto_tree_add_item(tree, hf_common_tlv_vendor_specific_type, tvb, offset, 1, FALSE);
			if(get_tlv_length_type(&tlv_info) == 0)
			{	/* single byte TLV length */
				proto_tree_add_item(tree, hf_common_tlv_vendor_specific_length, tvb, (offset + 1), 1, FALSE);
			}
			else
			{	/* multiple bytes TLV length */
				/* display the length of the TLV length with MSB */
				proto_tree_add_item(tree, hf_common_tlv_vendor_specific_length_size, tvb, (offset + 1), 1, FALSE);
				if(get_tlv_size_of_length(&tlv_info))
				{	/* display the multiple byte TLV length */
					proto_tree_add_text(tree, tvb, (offset + 2), get_tlv_size_of_length(&tlv_info), "Vendor Specific Length: %u", get_tlv_size_of_length(&tlv_info));
				}
				else
				{	/* length = 0 */
					continue;
				}
			}
			proto_tree_add_item(tree, hf_common_tlv_vendor_specific_value, tvb, (offset + tlv_value_offset), tlv_len, FALSE);
		}
		/* update the offset */
		offset += tlv_value_offset + tlv_len;
	}
}

/******************************************************************/
/* wimax_common_tlv_encoding_decoder()                            */
/* decode and display the WiMax Common TLV Encoding (Table 346)   */
/* parameter:                                                     */
/*   tvb - pointer of the tvb of service flow encodings           */
/*   tree - pointer of Wireshark display tree                     */
/*   pinfo - pointer of Wireshark packet information structure    */
/******************************************************************/
guint wimax_common_tlv_encoding_decoder(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
	guint offset, value;
	guint tvb_len, tlv_len, tlv_value_offset;
	gint  tlv_type;
	proto_tree *tlv_tree = NULL;
	tlv_info_t tlv_info;
	gfloat current_power;

	/* get the tvb reported length */
	tvb_len = tvb_reported_length(tvb);
	/* do nothing if the TLV fields is not exist */
	if(!tvb_len)
		return 0;
	/* report error if the packet size is less than 2 bytes (type+length) */
	if(tvb_len < 2)
	{	/* invalid tlv info */
		if(pinfo->cinfo)
		{
			col_append_sep_str(pinfo->cinfo, COL_INFO, NULL, "Invalid Common TLV encoding");
		}
		proto_tree_add_item(tree, hf_cst_invalid_tlv, tvb, 0, tvb_len, FALSE);
		return 0;
	}
	/* process Common TLV Encoding (11.1) */
	for(offset = 0; offset < tvb_len; )
	{
		/* get the TLV information */
		init_tlv_info(&tlv_info, tvb, offset);
		/* get the TLV type */
		tlv_type = get_tlv_type(&tlv_info);
		/* get the TLV length */
		tlv_len = get_tlv_length(&tlv_info);
		if(tlv_type == -1 || tlv_len > MAX_TLV_LEN || tlv_len < 1)
		{	/* invalid tlv info */
			if(pinfo->cinfo)
			{
				col_append_sep_str(pinfo->cinfo, COL_INFO, NULL, "Common TLV encoding TLV error");
			}
			proto_tree_add_item(tree, hf_cst_invalid_tlv, tvb, offset, (tvb_len - offset), FALSE);
			break;
		}
		/* get the TLV value offset */
		tlv_value_offset = get_tlv_value_offset(&tlv_info);
#ifdef DEBUG /* for debug only */
		proto_tree_add_protocol_format(tree, proto_wimax_utility_decoders, tvb, offset, (tlv_len + tlv_value_offset), "Common TLV Encoding TLV Type: %u (%u bytes, offset=%u, tvb_len=%u)", tlv_type, (tlv_len + tlv_value_offset), offset, tvb_len);
#endif
		/* update the offset for the TLV value */
		offset += tlv_value_offset;
		/* parse Common TLV Encoding (table 346) */
		switch (tlv_type)
		{
			case VENDOR_SPECIFIC_INFO:
				/* display Vendor-Specific Information */
				/* add subtree */
				tlv_tree = add_protocol_subtree(&tlv_info, ett_vendor_specific_info_decoder, tree, proto_wimax_utility_decoders, tvb, offset, tlv_len, "Vendor-Specific Information (%u bytes)", tlv_len);
				/* decode and display the Vendor-Specific Information */
				wimax_vendor_specific_information_decoder(tvb_new_subset(tvb, offset, tlv_len, tlv_len), pinfo, tlv_tree);
			break;
			case VENDOR_ID_ENCODING:
				/* display Vendor ID Encoding */
				/* add subtree */
				tlv_tree = add_protocol_subtree(&tlv_info, ett_vendor_specific_info_decoder, tree, proto_wimax_utility_decoders, tvb, offset, tlv_len, "Vendor ID Encoding (%u bytes)", tlv_len);
				/* decode and display the Vendor ID Encoding */
				proto_tree_add_item(tlv_tree, hf_common_tlv_vendor_id, tvb, offset, tlv_len, FALSE);
			break;
			case DSx_UPLINK_FLOW:
				/* display Uplink Service Flow Encodings info */
				/* add subtree */
				tlv_tree = add_protocol_subtree(&tlv_info, ett_ul_service_flow_decoder, tree, proto_wimax_utility_decoders, tvb, offset, tlv_len, "Uplink Service Flow Encodings (%u bytes)", tlv_len);
				/* decode and display the UL Service Flow Encodings */
				wimax_service_flow_encodings_decoder(tvb_new_subset(tvb, offset, tlv_len, tlv_len), pinfo, tlv_tree);
			break;
			case DSx_DOWNLINK_FLOW:
				/* display Downlink Service Flow Encodings info */
				/* add subtree */
				tlv_tree = add_protocol_subtree(&tlv_info, ett_dl_service_flow_decoder, tree, proto_wimax_utility_decoders, tvb, offset, tlv_len, "Downlink Service Flow Encodings (%u bytes)", tlv_len);
				/* decode and display the DL Service Flow Encodings */
				wimax_service_flow_encodings_decoder(tvb_new_subset(tvb,offset, tlv_len, tlv_len), pinfo, tlv_tree);
			break;
			case CURRENT_TX_POWER:
				tlv_tree = add_protocol_subtree(&tlv_info, ett_dl_service_flow_decoder, tree, proto_wimax_utility_decoders, tvb, offset, tlv_len, "Current Transmitted Power (%u byte(s))", tlv_len);
				value = tvb_get_guint8(tvb, offset);
				current_power = (gfloat)(value - 128) / 2;
				proto_tree_add_text(tlv_tree, tvb, offset, 1, "Current Transmitted Power: %.2f dBm (Value: 0x%x)", (gdouble)current_power, value);
			break;
			case MAC_VERSION_ENCODING:
				/* display MAC Version Encoding */
				/* add subtree */
				tlv_tree = add_protocol_subtree(&tlv_info, ett_vendor_specific_info_decoder, tree, proto_wimax_utility_decoders, tvb, offset, tlv_len, "MAC Version Encoding (%u byte)", tlv_len);
				/* decode and display the MAC Version Encoding */
				proto_tree_add_item(tlv_tree, hf_common_tlv_mac_version, tvb, offset, tlv_len, FALSE);
			break;
			case HMAC_TUPLE:	/* Table 348d */
				tlv_tree = add_protocol_subtree(&tlv_info, ett_vendor_specific_info_decoder, tree, proto_wimax_utility_decoders, tvb, offset, tlv_len, "HMAC Tuple (%u byte(s))", tlv_len);
				/* decode and display the HMAC Tuple */
				wimax_hmac_tuple_decoder(tlv_tree, tvb, offset, tlv_len);
			break;
			case CMAC_TUPLE:	/* Table 348b */
				tlv_tree = add_protocol_subtree(&tlv_info, ett_vendor_specific_info_decoder, tree, proto_wimax_utility_decoders, tvb, offset, tlv_len, "HMAC Tuple (%u byte(s))", tlv_len);
				/* decode and display the CMAC Tuple */
				wimax_cmac_tuple_decoder(tlv_tree, tvb, offset, tlv_len);
			break;
			default:
				/* Back to calling routine to finish decoding. */
				return offset - tlv_value_offset;  /* Ret amount decoded. */
			break;
		}
		offset += tlv_len;
	}	/* end of while loop */
	return offset;
}



      取自 
      http://anonsvn.wireshark.org/wireshark/trunk 的 plugins/wimax/wimax_utils.c 
      - GPL - C


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -