aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-maccontrol.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2009-10-31 19:44:17 +0000
committerGuy Harris <guy@alum.mit.edu>2009-10-31 19:44:17 +0000
commita212873733aab871c72a60cdc248b6c0222995c9 (patch)
treeec436dca97c7ed15955e5eb6ef1a080052b3d504 /epan/dissectors/packet-maccontrol.c
parent6b3f4e5a153aa25fcc1ab2063e4435e94517bae3 (diff)
The first field of a MAC Control frame isn't the "pause" field, it's the
opcode; an opcode of 0x0001 means PAUSE. Dissect the opcode field even if it's not a PAUSE frame. The second field of a PAUSE frame isn't the "quanta" field, it's the pause_time field; it's in *units* of quanta. Don't fetch fields until we need them (so we don't throw an exception if they're missing until we actually look at them). Clean up indentation. svn path=/trunk/; revision=30785
Diffstat (limited to 'epan/dissectors/packet-maccontrol.c')
-rw-r--r--epan/dissectors/packet-maccontrol.c71
1 files changed, 38 insertions, 33 deletions
diff --git a/epan/dissectors/packet-maccontrol.c b/epan/dissectors/packet-maccontrol.c
index bef490f9dc..2b52efadc3 100644
--- a/epan/dissectors/packet-maccontrol.c
+++ b/epan/dissectors/packet-maccontrol.c
@@ -35,61 +35,66 @@
static int proto_macctrl = -1;
static gint ett_macctrl = -1;
-static int hf_macctrl_pause = -1;
-static int hf_macctrl_quanta = -1;
+static int hf_macctrl_opcode = -1;
+static int hf_macctrl_pause_time = -1;
+#define MACCTRL_PAUSE 0x0001
+
+static const value_string opcode_vals[] = {
+ { MACCTRL_PAUSE, "Pause" },
+ { 0, NULL }
+};
static void
dissect_macctrl(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
proto_tree *ti;
- proto_tree *volatile macctrl_tree;
- guint16 pause;
- guint16 pause_quanta;
-
- pause = tvb_get_ntohs(tvb, 0);
- pause_quanta = tvb_get_ntohs(tvb, 2);
+ proto_tree *macctrl_tree = NULL;
+ guint16 opcode;
+ guint16 pause_time;
col_set_str(pinfo->cinfo, COL_PROTOCOL, "CTRL");
col_clear(pinfo->cinfo, COL_INFO);
- if (pause==1){
- if (check_col(pinfo->cinfo, COL_INFO)) {
- col_add_fstr(pinfo->cinfo, COL_INFO, "MAC PAUSE: Quanta %d", pause_quanta);
- }
- }
-
- macctrl_tree = NULL;
-
+ opcode = tvb_get_ntohs(tvb, 0);
if (tree) {
- ti = proto_tree_add_item(tree, proto_macctrl, tvb, 0, 4, FALSE);
- macctrl_tree = proto_item_add_subtree(ti, ett_macctrl);
+ ti = proto_tree_add_item(tree, proto_macctrl, tvb, 0, 4, FALSE);
+ macctrl_tree = proto_item_add_subtree(ti, ett_macctrl);
- proto_tree_add_uint(macctrl_tree, hf_macctrl_pause, tvb, 0, 2, pause);
- proto_tree_add_uint(macctrl_tree, hf_macctrl_quanta, tvb, 2, 2, pause_quanta);
- }
-
+ proto_tree_add_uint(macctrl_tree, hf_macctrl_opcode, tvb, 0, 2, opcode);
+ }
+
+ switch (opcode) {
+
+ case MACCTRL_PAUSE:
+ pause_time = tvb_get_ntohs(tvb, 2);
+ col_add_fstr(pinfo->cinfo, COL_INFO, "MAC PAUSE: pause_time %u quanta",
+ pause_time);
+ if (tree)
+ proto_tree_add_uint(macctrl_tree, hf_macctrl_pause_time, tvb, 2, 2,
+ pause_time);
+ break;
+ }
}
-
void
proto_register_macctrl(void)
{
- static hf_register_info hf[] = {
- { &hf_macctrl_pause,
- { "Pause", "macctrl.pause", FT_UINT16, BASE_HEX,
- NULL, 0x0, "MAC control Pause", HFILL}},
-
- { &hf_macctrl_quanta,
- { "Quanta", "macctrl.quanta", FT_UINT16, BASE_DEC,
- NULL, 0x0, "MAC control quanta", HFILL }}
- };
+ static hf_register_info hf[] = {
+ { &hf_macctrl_opcode,
+ { "Opcode", "macctrl.opcode", FT_UINT16, BASE_HEX,
+ VALS(opcode_vals), 0x0, "MAC Control opcode", HFILL}},
+
+ { &hf_macctrl_pause_time,
+ { "pause_time", "macctrl.pause_time", FT_UINT16, BASE_DEC,
+ NULL, 0x0, "MAC control PAUSE frame pause_time", HFILL }}
+ };
static gint *ett[] = {
&ett_macctrl,
};
proto_macctrl = proto_register_protocol("MAC Control", "MACC", "macc");
- proto_register_field_array(proto_macctrl, hf, array_length(hf));
+ proto_register_field_array(proto_macctrl, hf, array_length(hf));
proto_register_subtree_array(ett, array_length(ett));
}