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

📄 plugins-wimax-packet-wmx.c

📁 Intel的WIMAX代码,主要是mac层code
💻 C
📖 第 1 页 / 共 2 页
字号:
	&ett_tlv_87,
	&ett_tlv_88,
	&ett_tlv_89,
	&ett_tlv_90,
	&ett_tlv_91,
	&ett_tlv_92,
	&ett_tlv_93,
	&ett_tlv_94,
	&ett_tlv_95,
	&ett_tlv_96,
	&ett_tlv_97,
	&ett_tlv_98,
	&ett_tlv_99,
	&ett_tlv_100,
	&ett_tlv_101,
	&ett_tlv_102,
	&ett_tlv_103,
	&ett_tlv_104,
	&ett_tlv_105,
	&ett_tlv_106,
	&ett_tlv_107,
	&ett_tlv_108,
	&ett_tlv_109,
	&ett_tlv_110,
	&ett_tlv_111,
	&ett_tlv_112,
	&ett_tlv_113,
	&ett_tlv_114,
	&ett_tlv_115,
	&ett_tlv_116,
	&ett_tlv_117,
	&ett_tlv_118,
	&ett_tlv_119,
	&ett_tlv_120,
	&ett_tlv_121,
	&ett_tlv_122,
	&ett_tlv_123,
	&ett_tlv_124,
	&ett_tlv_125,
	&ett_tlv_126,
	&ett_tlv_127,
	&ett_tlv_128,
	&ett_tlv_129,
	&ett_tlv_130,
	&ett_tlv_131,
	&ett_tlv_132,
	&ett_tlv_133,
	&ett_tlv_134,
	&ett_tlv_135,
	&ett_tlv_136,
	&ett_tlv_137,
	&ett_tlv_138,
	&ett_tlv_139,
	&ett_tlv_140,
	&ett_tlv_141,
	&ett_tlv_142,
	&ett_tlv_143,
	&ett_tlv_144,
	&ett_tlv_145,
	&ett_tlv_146,
	&ett_tlv_147,
	&ett_tlv_148,
	&ett_tlv_149,
	&ett_tlv_150,
	&ett_tlv_151,
	&ett_tlv_152,
	&ett_tlv_153,
	&ett_tlv_154,
	&ett_tlv_155,
	&ett_tlv_156,
	&ett_tlv_157,
	&ett_tlv_158,
	&ett_tlv_159,
	&ett_tlv_160,
	&ett_tlv_161,
	&ett_tlv_162,
	&ett_tlv_163,
	&ett_tlv_164,
	&ett_tlv_165,
	&ett_tlv_166,
	&ett_tlv_167,
	&ett_tlv_168,
	&ett_tlv_169,
	&ett_tlv_170,
	&ett_tlv_171,
	&ett_tlv_172,
	&ett_tlv_173,
	&ett_tlv_174,
	&ett_tlv_175,
	&ett_tlv_176,
	&ett_tlv_177,
	&ett_tlv_178,
	&ett_tlv_179,
	&ett_tlv_180,
	&ett_tlv_181,
	&ett_tlv_182,
	&ett_tlv_183,
	&ett_tlv_184,
	&ett_tlv_185,
	&ett_tlv_186,
	&ett_tlv_187,
	&ett_tlv_188,
	&ett_tlv_189,
	&ett_tlv_190,
	&ett_tlv_191,
	&ett_tlv_192,
	&ett_tlv_193,
	&ett_tlv_194,
	&ett_tlv_195,
	&ett_tlv_196,
	&ett_tlv_197,
	&ett_tlv_198,
	&ett_tlv_199,
	&ett_tlv_200,
	&ett_tlv_201,
	&ett_tlv_202,
	&ett_tlv_203,
	&ett_tlv_204,
	&ett_tlv_205,
	&ett_tlv_206,
	&ett_tlv_207,
	&ett_tlv_208,
	&ett_tlv_209,
	&ett_tlv_210,
	&ett_tlv_211,
	&ett_tlv_212,
	&ett_tlv_213,
	&ett_tlv_214,
	&ett_tlv_215,
	&ett_tlv_216,
	&ett_tlv_217,
	&ett_tlv_218,
	&ett_tlv_219,
	&ett_tlv_220,
	&ett_tlv_221,
	&ett_tlv_222,
	&ett_tlv_223,
	&ett_tlv_224,
	&ett_tlv_225,
	&ett_tlv_226,
	&ett_tlv_227,
	&ett_tlv_228,
	&ett_tlv_229,
	&ett_tlv_230,
	&ett_tlv_231,
	&ett_tlv_232,
	&ett_tlv_233,
	&ett_tlv_234,
	&ett_tlv_235,
	&ett_tlv_236,
	&ett_tlv_237,
	&ett_tlv_238,
	&ett_tlv_239,
	&ett_tlv_240,
	&ett_tlv_241,
	&ett_tlv_242,
	&ett_tlv_243,
	&ett_tlv_244,
	&ett_tlv_245,
	&ett_tlv_246,
	&ett_tlv_247,
	&ett_tlv_248,
	&ett_tlv_249,
	&ett_tlv_250,
	&ett_tlv_251,
	&ett_tlv_252,
	&ett_tlv_253,
	&ett_tlv_254,
	&ett_tlv_255
};

/* Local Variables */
static gint ett_wimax = -1;
static gint ett_wimax_tlv = -1;
static gint ett_wimax_fch = -1;
static gint ett_wimax_cdma = -1;
static gint ett_wimax_ffb = -1;

static gchar *tlv_val_1byte = "TLV value: %s (0x%02x)";
static gchar *tlv_val_2byte = "TLV value: %s (0x%04x)";
static gchar *tlv_val_3byte = "TLV value: %s (0x%06x)";
static gchar *tlv_val_4byte = "TLV value: %s (0x%08x)";
static gchar *tlv_val_5byte = "TLV value: %s (0x%08x...)";

/* Setup protocol subtree array */
static gint *ett[] =
{
	&ett_wimax,
	&ett_wimax_tlv,
	&ett_wimax_fch,
	&ett_wimax_cdma,
	&ett_wimax_ffb,
};

/*************************************************************/
/* add_tlv_subtree()                                         */
/* Return a pointer to a proto_tree that already contains    */
/* the type and length of a given TLV.                       */
/*   tree          - the parent to which the new tree will   */
/*                   be attached                             */
/*   hfindex       - the index of the item to be attached    */
/*   tvb           - a pointer to the packet data            */
/*   start         - offset within the packet                */
/*   length        - length of this item                     */
/*   little_endian - endian indicator                        */
/* return:                                                   */
/*   pointer to a proto_tree                                 */
/*************************************************************/
proto_tree *add_tlv_subtree(tlv_info_t *this, gint idx, proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start, gint length, gboolean little_endian)
{
	/* Declare local variables */
	proto_tree *tlv_tree;
	proto_item *tlv_item;
	guint start_of_tlv;
	gint tlv_value_length, tlv_val_offset;
	guint8 size_of_tlv_length_field;
	guint8 tlv_type;
	guint32 tlv_value;
	gchar *hex_fmt;

	UNREFERENCED_PARAMETER(length);

	/* Retrieve the necessary TLV information */
	tlv_val_offset = get_tlv_value_offset(this);
	start_of_tlv = start - tlv_val_offset;
	tlv_value_length = get_tlv_length(this);
	size_of_tlv_length_field = get_tlv_size_of_length(this);
	tlv_type = get_tlv_type(this);

	/* display the TLV name and display the value in hex. Highlight type, length, and value. */
	tlv_item = proto_tree_add_item(tree, hfindex, tvb, start, tlv_value_length, little_endian);
	/* Correct the highlighting. */
	tlv_item->finfo->start -= tlv_val_offset;
	tlv_item->finfo->length += tlv_val_offset;
	/* add TLV subtree to contain the type, length, and value */
	tlv_tree = proto_item_add_subtree(tlv_item, *ett_tlv[tlv_type]);
	/* display the TLV type */
	proto_tree_add_text(tlv_tree, tvb, start_of_tlv, 1, "TLV type: %u", tlv_type);
	/* check if this is an extended TLV */
	if (size_of_tlv_length_field > 0) /* It is */
	{
		/* display the length of the length field TLV */
		proto_tree_add_text(tlv_tree, tvb, start_of_tlv+1, 1, "Size of TLV length field: %u", size_of_tlv_length_field);
		/* display the TLV length */
		proto_tree_add_text(tlv_tree, tvb, start_of_tlv+2, size_of_tlv_length_field, "TLV length: %u", tlv_value_length);
	} else { /* It is not */
		/* display the TLV length */
		proto_tree_add_text(tlv_tree, tvb, start_of_tlv+1, 1, "TLV length: %u", tlv_value_length);
	}
	/* display the TLV value and make it a subtree */
	switch (tlv_value_length)
	{
		case 1:
			tlv_value = tvb_get_guint8(tvb, start);
			hex_fmt = tlv_val_1byte;
			break;
		case 2:
			tlv_value = tvb_get_ntohs(tvb, start);
			hex_fmt = tlv_val_2byte;
			break;
		case 3:
			tlv_value = tvb_get_ntoh24(tvb, start);
			hex_fmt = tlv_val_3byte;
			break;
		case 4:
			tlv_value = tvb_get_ntohl(tvb, start);
			hex_fmt = tlv_val_4byte;
			break;
		default:
			tlv_value = tvb_get_ntohl(tvb, start);
			hex_fmt = tlv_val_5byte;
			break;
	}
	/* Show "TLV value: " */
	tlv_item = proto_tree_add_text(tlv_tree, tvb, start, tlv_value_length, hex_fmt, tlv_item->finfo->hfinfo->name, tlv_value);
	tlv_tree = proto_item_add_subtree(tlv_item, idx);

	/* Return a pointer to the value level */
	return tlv_tree;
}

/*************************************************************/
/* add_protocol_subtree()                                    */
/* Return a pointer to a proto_tree that already contains    */
/* the type and length of a given TLV.                       */
/*   tree          - the parent to which the new tree will   */
/*                   be attached                             */
/*   hfindex       - the index of the item to be attached    */
/*   tvb           - a pointer to the packet data            */
/*   start         - offset within the packet                */
/*   length        - length of this item                     */
/*   format        - printf style formatting string          */
/*   ...	   - arguments to format                     */
/* return:                                                   */
/*   pointer to a proto_tree                                 */
/*************************************************************/
proto_tree *add_protocol_subtree(tlv_info_t *this, gint idx, proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start, gint length, const char *format, ...)
{
	/* Declare local variables */
	proto_tree *tlv_tree;
	proto_item *tlv_item;
	guint start_of_tlv;
	gint tlv_value_length, tlv_val_offset;
	guint8 size_of_tlv_length_field;
	guint8 tlv_type;
	guint32 tlv_value;
	va_list ap; /* points to each unnamed arg in turn */
	gchar *message = NULL;
	gchar *hex_fmt;

	/* Retrieve the necessary TLV information */
	tlv_val_offset = get_tlv_value_offset(this);
	start_of_tlv = start - tlv_val_offset;
	tlv_value_length = get_tlv_length(this);
	size_of_tlv_length_field = get_tlv_size_of_length(this);
	tlv_type = get_tlv_type(this);

	/* display the TLV name and display the value in hex. Highlight type, length, and value. */
	if( (message = se_alloc_array(gchar, 255)) ){
		va_start(ap, format);
		vsprintf(message, format, ap);
		va_end(ap);
	} else {
		message = "Memory error";
	}
	tlv_item = proto_tree_add_protocol_format(tree, hfindex, tvb, start, length, "%s", message);
	/* Correct the highlighting. */
	tlv_item->finfo->start -= tlv_val_offset;
	tlv_item->finfo->length += tlv_val_offset;
	/* add TLV subtree to contain the type, length, and value */
	tlv_tree = proto_item_add_subtree(tlv_item, *ett_tlv[tlv_type]);
	/* display the TLV type */
	proto_tree_add_text(tlv_tree, tvb, start_of_tlv, 1, "TLV type: %u", tlv_type);
	/* check if this is an extended TLV */
	if (size_of_tlv_length_field > 0) /* It is */
	{
		/* display the length of the length field TLV */
		proto_tree_add_text(tlv_tree, tvb, start_of_tlv+1, 1, "Size of TLV length field: %u", size_of_tlv_length_field);
		/* display the TLV length */
		proto_tree_add_text(tlv_tree, tvb, start_of_tlv+2, size_of_tlv_length_field, "TLV length: %u", tlv_value_length);
	} else { /* It is not */
		/* display the TLV length */
		proto_tree_add_text(tlv_tree, tvb, start_of_tlv+1, 1, "TLV length: %u", tlv_value_length);
	}
	/* display the TLV value and make it a subtree */
	switch (tlv_value_length)
	{
		case 1:
			tlv_value = tvb_get_guint8(tvb, start);
			hex_fmt = tlv_val_1byte;
			break;
		case 2:
			tlv_value = tvb_get_ntohs(tvb, start);
			hex_fmt = tlv_val_2byte;
			break;
		case 3:
			tlv_value = tvb_get_ntoh24(tvb, start);
			hex_fmt = tlv_val_3byte;
			break;
		case 4:
			tlv_value = tvb_get_ntohl(tvb, start);
			hex_fmt = tlv_val_4byte;
			break;
		default:
			tlv_value = tvb_get_ntohl(tvb, start);
			hex_fmt = tlv_val_5byte;
			break;
	}
	/* Show "TLV value: " */
	tlv_item = proto_tree_add_text(tlv_tree, tvb, start, length, hex_fmt, message, tlv_value);
	tlv_tree = proto_item_add_subtree(tlv_item, idx);

	/* Return a pointer to the value level */
	return tlv_tree;
}


/* Register Wimax Protocol */
void proto_register_wimax(void)
{
	module_t *wimax_module;

	if (proto_wimax == -1)
	{
		/* Register the WiMax protocols here */
		proto_wimax = proto_register_protocol (
							"WiMax Protocol", /* name */
							"WiMax (wmx)", /* short name */
							"wmx" /* abbrev */
							);
		/* Register the WiMax protocol subtree array */
		proto_register_subtree_array(ett, array_length(ett));
		/* Register the WiMax dissector */
		register_dissector("wmx", dissect_wimax, proto_wimax);

		/* Register other WiMax dissectors */
		proto_register_wimax_cdma();
		proto_register_wimax_fch();
		proto_register_wimax_pdu();
		proto_register_wimax_ffb();
		proto_register_wimax_hack();
		proto_register_wimax_harq_map();
		proto_register_wimax_phy_attributes();
		proto_register_wimax_compact_dlmap_ie();
		proto_register_wimax_compact_ulmap_ie();

		wimax_module = prefs_register_protocol(proto_wimax, proto_reg_handoff_wimax);

		prefs_register_uint_preference(wimax_module, "wimax.basic_cid_max",
				 "Maximum Basic CID",
				 "Set the maximum Basic CID"
				 " used in the Wimax decoder"
				 " (if other than the default of 320)."
				 "  Note: The maximum Primary CID is"
				 " double the maximum Basic CID.",
				10, &global_cid_max_basic);

		prefs_register_bool_preference(wimax_module, "wimax.corrigendum_2_version",
				 "Corrigendum 2 Version",
				 "Set to TRUE to use the Corrigendum"
				 " 2 version of Wimax message decoding."
				 " Set to FALSE to use the 802.16e-2005"
				 "  version.",
				&include_cor2_changes);

		register_dissector_table("wimax.max_basic_cid", "Max Basic CID", FT_UINT16, BASE_DEC);
		register_dissector_table("wimax.corrigendum_2_version", "Corrigendum 2 Version", FT_UINT16, BASE_DEC);
		proto_register_subtree_array(ett_tlv, array_length(ett_tlv));
	}
}

/* Register Wimax Protocol handler */
void proto_reg_wimax(void)
{
	if (find_dissector("wmx") == NULL)
	{
		/* Register the WiMax dissector */
		register_dissector("wimax_dissector", dissect_wimax, proto_wimax);
	}
}

/* WiMax protocol dissector */
static void dissect_wimax(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
	UNREFERENCED_PARAMETER(tvb);
	UNREFERENCED_PARAMETER(tree);

	/* display the WiMax protocol name */
	if (check_col(pinfo->cinfo, COL_PROTOCOL))
	{
		col_set_str(pinfo->cinfo, COL_PROTOCOL, "WiMax");
	}
	/* Clear out stuff in the info column */
	if (check_col(pinfo->cinfo, COL_INFO))
	{
		col_clear(pinfo->cinfo, COL_INFO);
	}
}

gboolean is_down_link(address *src_address)
{
	if(bs_address.len && !CMP_ADDRESS(&bs_address, src_address))
		return TRUE;

	return FALSE;
}

/* The registration hand-off routine for the max_basic_cid pref */
void
proto_reg_handoff_wimax(void)
{
	static int wimax_prefs_initialized = FALSE;
	static dissector_handle_t wimax_handle;

	if(!wimax_prefs_initialized)
	{
                wimax_handle = create_dissector_handle(dissect_wimax, proto_wimax);
                wimax_prefs_initialized = TRUE;
        } else {
                dissector_delete("wimax.max_basic_cid", global_cid_max_basic, wimax_handle);
                dissector_delete("wimax.corrigendum_2_version", include_cor2_changes, wimax_handle);

        }

	dissector_add("wimax.max_basic_cid", global_cid_max_basic, wimax_handle);
	dissector_add("wimax.corrigendum_2_version", include_cor2_changes, wimax_handle);
}




      取自 
      http://anonsvn.wireshark.org/wireshark/trunk 的 plugins/wimax/packet-wmx.c 
      - LGPL - C


⌨️ 快捷键说明

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