- remove duplicate/unneeded #includes
- remove some boilerplate comments
- fix up whitespace: indentation, trailing & etc
- remove 'if (tree)'
  (Note: 'if (tree)' needs to be around all the code (as in the previous
          version of packet-wsmp) or none so that the same value of offset is used
          in various function calls whether or not 'tree == NULL'.
         For the moment I've chosen to remove the 'if (tree)' since (in theory)
         the (external) data dissector shouldn't be called under 'if (tree)'.
- revert SVN #52757 since no it's longer needed with the removal of 'if (tree)';
- remove another unneeded line of code.

svn path=/trunk/; revision=52761
This commit is contained in:
Bill Meier 2013-10-22 14:27:48 +00:00
parent 29b709298e
commit a7fbfd70cf
1 changed files with 152 additions and 180 deletions

View File

@ -10,8 +10,6 @@
* By Gerald Combs <gerald@wireshark.org> * By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs * Copyright 1998 Gerald Combs
* *
* Copied from README.developer
*
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2 * as published by the Free Software Foundation; either version 2
@ -33,14 +31,12 @@
#include <epan/packet.h> #include <epan/packet.h>
#include <epan/etypes.h> #include <epan/etypes.h>
#include <epan/prefs.h>
#include <glib.h>
#define WSMP 0x80 #define WSMP 0x80
#define WSMP_S 0x81 #define WSMP_S 0x81
#define WSMP_I 0x82 #define WSMP_I 0x82
#define CHANNUM 0x0F #define CHANNUM 0x0F
#define DATARATE 0x10 #define DATARATE 0x10
#define TRANSMITPW 0x04 #define TRANSMITPW 0x04
static const value_string wsmp_elemenid_names[] = { static const value_string wsmp_elemenid_names[] = {
@ -63,11 +59,11 @@ static int hf_wsmp_txpower = -1;
static int hf_wsmp_WAVEid = -1; static int hf_wsmp_WAVEid = -1;
static int hf_wsmp_wsmlength = -1; static int hf_wsmp_wsmlength = -1;
static int hf_wsmp_WSMP_S_data = -1; static int hf_wsmp_WSMP_S_data = -1;
/* Savari function to get the length of a psid based on the number of /* Savari function to get the length of a psid based on the number of
successive 1s in the most sig bits of the most sig octet. Taken successive 1s in the most sig bits of the most sig octet. Taken
from libwme from libwme
*/ */
int wme_getpsidlen (guint8 *psid) int wme_getpsidlen (guint8 *psid)
{ {
int length = 0; int length = 0;
@ -81,218 +77,194 @@ int wme_getpsidlen (guint8 *psid)
length = 2; length = 2;
} else if ((psid[0] & 0x80) == 0x00) { } else if ((psid[0] & 0x80) == 0x00) {
length = 1; length = 1;
} }
return length; return length;
} }
/* Initialize the subtree pointers */ /* Initialize the subtree pointers */
static gint ett_wsmp = -1; static gint ett_wsmp = -1;
static gint ett_wsmdata = -1; static gint ett_wsmdata = -1;
/* Code to actually dissect the packets */
static void static void
dissect_wsmp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) dissect_wsmp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{ {
/* Set up structures needed to add the protocol subtree and manage it */
proto_item *ti, *wsmdata_item;
proto_tree *wsmp_tree, *wsmdata_tree;
tvbuff_t *wsmdata_tvb;
guint16 wsmlength, offset;
guint32 psidLen, psid;
guint8 elemenId, elemenLen, msb, supLen;
/* Set up structures needed to add the protocol subtree and manage it */ /* Make entries in Protocol column and Info column on summary display */
proto_item *ti, *wsmdata_item; col_set_str(pinfo->cinfo, COL_PROTOCOL, "WSMP");
proto_tree *wsmp_tree, *wsmdata_tree;
tvbuff_t *wsmdata_tvb;
guint16 wsmlength, offset;
guint32 psidLen, psid;
guint8 elemenId, elemenLen, msb, supLen;
/* Make entries in Protocol column and Info column on summary display */ col_set_str(pinfo->cinfo, COL_INFO, "WAVE Short Message Protocol IEEE P1609.3");
col_set_str(pinfo->cinfo, COL_PROTOCOL, "WSMP");
col_set_str(pinfo->cinfo, COL_INFO, "WAVE Short Message Protocol IEEE P1609.3"); /* create display subtree for the protocol */
ti = proto_tree_add_item(tree, proto_wsmp, tvb, 0, -1, ENC_NA);
/* create display subtree for the protocol */ wsmp_tree = proto_item_add_subtree(ti, ett_wsmp);
ti = proto_tree_add_item(tree, proto_wsmp, tvb, 0, -1, ENC_NA);
wsmp_tree = proto_item_add_subtree(ti, ett_wsmp); offset = 0;
proto_tree_add_item(wsmp_tree,
offset = 0;
proto_tree_add_item(wsmp_tree,
hf_wsmp_version, tvb, offset, 1, ENC_BIG_ENDIAN); hf_wsmp_version, tvb, offset, 1, ENC_BIG_ENDIAN);
offset ++; offset++;
psid = tvb_get_guint8(tvb, offset); psid = tvb_get_guint8(tvb, offset);
psidLen =(guint32)wme_getpsidlen((guint8*)&psid); psidLen = (guint32)wme_getpsidlen((guint8*)&psid);
if(psidLen == 2) if (psidLen == 2)
psid = tvb_get_ntohs(tvb, offset); psid = tvb_get_ntohs(tvb, offset);
else if(psidLen == 3) else if (psidLen == 3)
{
psid = tvb_get_ntohl(tvb, offset);
psid = psid & 0x00FFFF; /* three bytes */
}
else if (psidLen == 4)
psid = tvb_get_ntohl(tvb, offset);
proto_tree_add_item(wsmp_tree,
hf_wsmp_psid, tvb, offset, psidLen, ENC_BIG_ENDIAN);
offset += psidLen;
elemenId = tvb_get_guint8(tvb, offset);
while ((elemenId != WSMP) && (elemenId != WSMP_S) && (elemenId != WSMP_I))
{
offset++;
if (elemenId == CHANNUM)
{ {
psid = tvb_get_ntohl(tvb, offset); /* channel number */
psid = psid & 0x00FFFF; /* three bytes */ elemenLen = tvb_get_guint8(tvb, offset);
offset++;
} proto_tree_add_item(wsmp_tree,
else if(psidLen ==4)
psid = tvb_get_ntohl(tvb, offset);
wsmlength = 0;
if (tree) {
proto_tree_add_item(wsmp_tree,
hf_wsmp_psid, tvb, offset, psidLen, ENC_BIG_ENDIAN);
offset += psidLen;
elemenId = tvb_get_guint8(tvb, offset);
while(elemenId != WSMP && elemenId != WSMP_S
&& elemenId != WSMP_I)
{
offset++;
if(elemenId == CHANNUM)
{
/* channel number */
elemenLen = tvb_get_guint8(tvb, offset);
offset++;
proto_tree_add_item(wsmp_tree,
hf_wsmp_channel, tvb, offset, elemenLen, ENC_BIG_ENDIAN); hf_wsmp_channel, tvb, offset, elemenLen, ENC_BIG_ENDIAN);
offset += elemenLen; offset += elemenLen;
}
else if(elemenId == DATARATE)
{
/* Data rate */
elemenLen = tvb_get_guint8(tvb, offset);
offset++;
proto_tree_add_item(wsmp_tree,
hf_wsmp_rate, tvb, offset, elemenLen, ENC_BIG_ENDIAN);
offset += elemenLen;
}
else if(elemenId == TRANSMITPW)
{
/* Transmit power */
elemenLen = tvb_get_guint8(tvb, offset);
offset++;
proto_tree_add_item(wsmp_tree,
hf_wsmp_txpower, tvb, offset, elemenLen, ENC_BIG_ENDIAN);
offset += elemenLen;
}
elemenId = tvb_get_guint8(tvb, offset);
elemenLen = 0;
}
proto_tree_add_item(wsmp_tree,
hf_wsmp_WAVEid, tvb, offset, 1, ENC_BIG_ENDIAN);
offset ++;
wsmlength = tvb_get_letohs( tvb, offset);
proto_tree_add_item(wsmp_tree,
hf_wsmp_wsmlength, tvb, offset, 2, ENC_BIG_ENDIAN);
offset += 2;
if(elemenId == WSMP_S)
{
msb = 1;
supLen = 0;
while(msb)
{
msb = tvb_get_guint8(tvb, offset + supLen);
msb = msb & 0x80;
supLen++;
}
proto_tree_add_item(wsmp_tree,
hf_wsmp_WSMP_S_data, tvb, offset, supLen, ENC_BIG_ENDIAN);
wsmlength -= supLen;
offset += supLen;
}
} }
else if (elemenId == DATARATE)
wsmdata_item = proto_tree_add_text (wsmp_tree, tvb, offset, wsmlength,
"Wave Short Message");
wsmdata_tree = proto_item_add_subtree(wsmdata_item, ett_wsmdata);
wsmdata_tvb = tvb_new_subset(tvb, offset,-1, wsmlength);
/* TODO: Branch on the application context and display accordingly
* Default call the data dissector
*/
if(psid == 0xbff0)
{ {
call_dissector(data_handle, wsmdata_tvb, pinfo, wsmdata_tree); /* Data rate */
elemenLen = tvb_get_guint8(tvb, offset);
offset++;
proto_tree_add_item(wsmp_tree,
hf_wsmp_rate, tvb, offset, elemenLen, ENC_BIG_ENDIAN);
offset += elemenLen;
} }
else if (elemenId == TRANSMITPW)
{
/* Transmit power */
elemenLen = tvb_get_guint8(tvb, offset);
offset++;
proto_tree_add_item(wsmp_tree,
hf_wsmp_txpower, tvb, offset, elemenLen, ENC_BIG_ENDIAN);
offset += elemenLen;
}
elemenId = tvb_get_guint8(tvb, offset);
}
proto_tree_add_item(wsmp_tree,
hf_wsmp_WAVEid, tvb, offset, 1, ENC_BIG_ENDIAN);
offset++;
wsmlength = tvb_get_letohs( tvb, offset);
proto_tree_add_item(wsmp_tree,
hf_wsmp_wsmlength, tvb, offset, 2, ENC_BIG_ENDIAN);
offset += 2;
if (elemenId == WSMP_S)
{
msb = 1;
supLen = 0;
while (msb)
{
msb = tvb_get_guint8(tvb, offset + supLen);
msb = msb & 0x80;
supLen++;
}
proto_tree_add_item(wsmp_tree,
hf_wsmp_WSMP_S_data, tvb, offset, supLen, ENC_BIG_ENDIAN);
wsmlength -= supLen;
offset += supLen;
}
wsmdata_item = proto_tree_add_text (wsmp_tree, tvb, offset, wsmlength,
"Wave Short Message");
wsmdata_tree = proto_item_add_subtree(wsmdata_item, ett_wsmdata);
wsmdata_tvb = tvb_new_subset(tvb, offset, -1, wsmlength);
/* TODO: Branch on the application context and display accordingly
* Default: call the data dissector
*/
if (psid == 0xbff0)
{
call_dissector(data_handle, wsmdata_tvb, pinfo, wsmdata_tree);
}
} }
/* Register the protocol with Wireshark */
/* this format is require because a script is used to build the C function
that calls all the protocol registration.
*/
void void
proto_register_wsmp(void) proto_register_wsmp(void)
{ {
/* Setup list of header fields See Section 1.6.1 for details*/ /* Setup list of header fields See Section 1.6.1 for details*/
static hf_register_info hf[] = { static hf_register_info hf[] = {
{ &hf_wsmp_version, { &hf_wsmp_version,
{ "Version", "wsmp.version", FT_UINT8, BASE_DEC, NULL, 0x0, { "Version", "wsmp.version", FT_UINT8, BASE_DEC, NULL, 0x0,
NULL, HFILL }}, NULL, HFILL }},
{ &hf_wsmp_psid, { &hf_wsmp_psid,
{ "PSID", "wsmp.psid", FT_UINT32, BASE_HEX, NULL, 0x0, { "PSID", "wsmp.psid", FT_UINT32, BASE_HEX, NULL, 0x0,
NULL, HFILL }}, NULL, HFILL }},
{ &hf_wsmp_channel, { &hf_wsmp_channel,
{ "Channel", "wsmp.channel", FT_UINT8, BASE_DEC, NULL, 0x0, { "Channel", "wsmp.channel", FT_UINT8, BASE_DEC, NULL, 0x0,
NULL, HFILL }}, NULL, HFILL }},
{ &hf_wsmp_rate, { &hf_wsmp_rate,
{ "Data Rate", "wsmp.rate", FT_UINT8, BASE_DEC, NULL, 0x0, { "Data Rate", "wsmp.rate", FT_UINT8, BASE_DEC, NULL, 0x0,
NULL, HFILL }}, NULL, HFILL }},
{ &hf_wsmp_txpower, { &hf_wsmp_txpower,
{ "Transmit Power", "wsmp.txpower", FT_UINT8, BASE_DEC, NULL, 0x0, { "Transmit Power", "wsmp.txpower", FT_UINT8, BASE_DEC, NULL, 0x0,
NULL, HFILL }}, NULL, HFILL }},
{ &hf_wsmp_WAVEid, { &hf_wsmp_WAVEid,
{ "WAVE element id", "wsmp.WAVEid", FT_UINT8, BASE_DEC, VALS(wsmp_elemenid_names), 0x0, { "WAVE element id", "wsmp.WAVEid", FT_UINT8, BASE_DEC, VALS(wsmp_elemenid_names), 0x0,
NULL, HFILL }}, NULL, HFILL }},
{ &hf_wsmp_wsmlength, { &hf_wsmp_wsmlength,
{ "WSM Length", "wsmp.wsmlength", FT_UINT16, BASE_DEC, NULL, 0x0, { "WSM Length", "wsmp.wsmlength", FT_UINT16, BASE_DEC, NULL, 0x0,
NULL, HFILL }}, NULL, HFILL }},
{ &hf_wsmp_WSMP_S_data, { &hf_wsmp_WSMP_S_data,
{ "WAVE Supplement Data", "wsmp.supplement", FT_UINT8, BASE_HEX, NULL, 0x0, { "WAVE Supplement Data", "wsmp.supplement", FT_UINT8, BASE_HEX, NULL, 0x0,
NULL, HFILL }}, NULL, HFILL }},
}; };
/* Setup protocol subtree array */ /* Setup protocol subtree array */
static gint *ett[] = { static gint *ett[] = {
&ett_wsmp, &ett_wsmp,
&ett_wsmdata, &ett_wsmdata,
}; };
/* Register the protocol name and description */ /* Register the protocol name and description */
proto_wsmp = proto_register_protocol("Wave Short Message Protocol(IEEE P1609.3)", proto_wsmp = proto_register_protocol("Wave Short Message Protocol(IEEE P1609.3)",
"WSMP", "wsmp"); "WSMP", "wsmp");
/* Required function calls to register the header fields and subtrees used */
proto_register_field_array(proto_wsmp, hf, array_length(hf));
proto_register_subtree_array(ett, array_length(ett));
/* Required function calls to register the header fields and subtrees used */
proto_register_field_array(proto_wsmp, hf, array_length(hf));
proto_register_subtree_array(ett, array_length(ett));
} }
/* If this dissector uses sub-dissector registration add a registration routine.
This exact format is required because a script is used to find these routines
and create the code that calls these routines.
*/
void void
proto_reg_handoff_wsmp(void) proto_reg_handoff_wsmp(void)
{ {
dissector_handle_t wsmp_handle; dissector_handle_t wsmp_handle;
wsmp_handle = create_dissector_handle(dissect_wsmp, proto_wsmp); wsmp_handle = create_dissector_handle(dissect_wsmp, proto_wsmp);
dissector_add_uint("ethertype", ETHERTYPE_WSMP, wsmp_handle); dissector_add_uint("ethertype", ETHERTYPE_WSMP, wsmp_handle);
data_handle = find_dissector("data"); data_handle = find_dissector("data");
return; return;
} }