2008-08-14 20:41:55 +00:00
|
|
|
/* packet-wsmp.c
|
|
|
|
* Routines for WAVE Short Message dissection (WSMP)
|
2013-10-22 02:37:49 +00:00
|
|
|
* Copyright 2013, Savari Networks (http://www.savarinetworks.com) (email: smooney@savarinetworks.com)
|
|
|
|
* Based on packet-wsmp.c implemented by
|
|
|
|
* Arada Systems (http://www.aradasystems.com) (email: siva@aradasystems.com)
|
2008-08-14 20:41:55 +00:00
|
|
|
*
|
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
|
|
|
* Copyright 1998 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
2012-09-20 02:03:38 +00:00
|
|
|
#include "config.h"
|
2008-08-14 20:41:55 +00:00
|
|
|
|
|
|
|
#include <epan/packet.h>
|
|
|
|
#include <epan/etypes.h>
|
2013-10-22 02:37:49 +00:00
|
|
|
|
2014-11-17 20:05:11 +00:00
|
|
|
/* elemenID Types */
|
|
|
|
#define TRANSMITPW 0x04
|
|
|
|
#define CHANNUM 0x0F
|
|
|
|
#define DATARATE 0x10
|
2013-10-22 14:27:48 +00:00
|
|
|
#define WSMP 0x80
|
|
|
|
#define WSMP_S 0x81
|
|
|
|
#define WSMP_I 0x82
|
2013-10-22 02:37:49 +00:00
|
|
|
|
2013-12-10 17:41:57 +00:00
|
|
|
void proto_register_wsmp(void);
|
|
|
|
void proto_reg_handoff_wsmp(void);
|
|
|
|
|
2013-10-22 02:37:49 +00:00
|
|
|
static const value_string wsmp_elemenid_names[] = {
|
|
|
|
{ 0x80, "WSMP" },
|
|
|
|
{ 0x81, "WSMP-S" },
|
|
|
|
{ 0x82, "WSMP-I" },
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
|
2008-08-14 20:41:55 +00:00
|
|
|
|
|
|
|
static dissector_handle_t data_handle;
|
|
|
|
|
|
|
|
/* Initialize the protocol and registered fields */
|
|
|
|
static int proto_wsmp = -1;
|
|
|
|
static int hf_wsmp_version = -1;
|
2013-10-22 02:37:49 +00:00
|
|
|
static int hf_wsmp_psid = -1;
|
2008-08-14 20:41:55 +00:00
|
|
|
static int hf_wsmp_rate = -1;
|
|
|
|
static int hf_wsmp_channel = -1;
|
|
|
|
static int hf_wsmp_txpower = -1;
|
2013-10-22 02:37:49 +00:00
|
|
|
static int hf_wsmp_WAVEid = -1;
|
2008-08-14 20:41:55 +00:00
|
|
|
static int hf_wsmp_wsmlength = -1;
|
2013-10-22 02:37:49 +00:00
|
|
|
static int hf_wsmp_WSMP_S_data = -1;
|
2013-10-22 14:27:48 +00:00
|
|
|
|
2013-10-22 02:37:49 +00:00
|
|
|
/* 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
|
|
|
|
from libwme
|
|
|
|
*/
|
2013-12-10 17:41:57 +00:00
|
|
|
static int wme_getpsidlen (guint8 *psid)
|
2013-10-22 02:37:49 +00:00
|
|
|
{
|
|
|
|
int length = 0;
|
|
|
|
if ((psid[0] & 0xF0) == 0xF0) {
|
|
|
|
length = 255;
|
2014-11-17 20:05:11 +00:00
|
|
|
} else if ( (psid[0] & 0xF0) == 0xE0) {
|
2013-10-22 02:37:49 +00:00
|
|
|
length = 4;
|
|
|
|
} else if ( (psid[0] & 0xE0) == 0xC0) {
|
|
|
|
length = 3;
|
|
|
|
} else if ( (psid[0] & 0xC0) == 0x80) {
|
|
|
|
length = 2;
|
|
|
|
} else if ((psid[0] & 0x80) == 0x00) {
|
|
|
|
length = 1;
|
2013-10-22 14:27:48 +00:00
|
|
|
}
|
2013-10-22 02:37:49 +00:00
|
|
|
return length;
|
|
|
|
}
|
|
|
|
|
2008-08-14 20:41:55 +00:00
|
|
|
/* Initialize the subtree pointers */
|
|
|
|
static gint ett_wsmp = -1;
|
|
|
|
static gint ett_wsmdata = -1;
|
|
|
|
|
|
|
|
static void
|
|
|
|
dissect_wsmp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
|
|
|
{
|
2013-10-22 14:27:48 +00:00
|
|
|
/* Set up structures needed to add the protocol subtree and manage it */
|
2014-07-06 18:21:40 +00:00
|
|
|
proto_item *ti;
|
2013-10-22 14:27:48 +00:00
|
|
|
proto_tree *wsmp_tree, *wsmdata_tree;
|
|
|
|
tvbuff_t *wsmdata_tvb;
|
|
|
|
guint16 wsmlength, offset;
|
2013-11-07 15:54:11 +00:00
|
|
|
guint32 psidLen, psid, supLen;
|
|
|
|
guint8 elemenId, elemenLen, msb;
|
2008-08-14 20:41:55 +00:00
|
|
|
|
2013-10-22 14:27:48 +00:00
|
|
|
/* Make entries in Protocol column and Info column on summary display */
|
|
|
|
col_set_str(pinfo->cinfo, COL_PROTOCOL, "WSMP");
|
2008-08-14 20:41:55 +00:00
|
|
|
|
2013-10-22 14:27:48 +00:00
|
|
|
col_set_str(pinfo->cinfo, COL_INFO, "WAVE Short Message Protocol IEEE P1609.3");
|
2008-08-14 20:41:55 +00:00
|
|
|
|
2013-10-22 14:27:48 +00:00
|
|
|
/* create display subtree for the protocol */
|
|
|
|
ti = proto_tree_add_item(tree, proto_wsmp, tvb, 0, -1, ENC_NA);
|
2008-08-14 20:41:55 +00:00
|
|
|
|
2013-10-22 14:27:48 +00:00
|
|
|
wsmp_tree = proto_item_add_subtree(ti, ett_wsmp);
|
2008-08-14 20:41:55 +00:00
|
|
|
|
2013-10-22 14:27:48 +00:00
|
|
|
offset = 0;
|
|
|
|
proto_tree_add_item(wsmp_tree,
|
2013-10-22 02:37:49 +00:00
|
|
|
hf_wsmp_version, tvb, offset, 1, ENC_BIG_ENDIAN);
|
2013-10-22 14:27:48 +00:00
|
|
|
offset++;
|
2008-08-14 20:41:55 +00:00
|
|
|
|
2013-10-22 14:27:48 +00:00
|
|
|
psid = tvb_get_guint8(tvb, offset);
|
|
|
|
psidLen = (guint32)wme_getpsidlen((guint8*)&psid);
|
2008-08-14 20:41:55 +00:00
|
|
|
|
|
|
|
|
2013-10-22 14:27:48 +00:00
|
|
|
if (psidLen == 2)
|
|
|
|
psid = tvb_get_ntohs(tvb, offset);
|
|
|
|
else if (psidLen == 3)
|
2014-11-17 20:05:11 +00:00
|
|
|
psid = tvb_get_ntoh24(tvb, offset);
|
2013-10-22 14:27:48 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
|
2014-11-17 20:05:11 +00:00
|
|
|
/* TLV decoder that does not display the T and L elements */
|
2013-10-22 14:27:48 +00:00
|
|
|
elemenId = tvb_get_guint8(tvb, offset);
|
|
|
|
while ((elemenId != WSMP) && (elemenId != WSMP_S) && (elemenId != WSMP_I))
|
|
|
|
{
|
|
|
|
offset++;
|
|
|
|
if (elemenId == CHANNUM)
|
|
|
|
{
|
|
|
|
elemenLen = tvb_get_guint8(tvb, offset);
|
|
|
|
offset++;
|
|
|
|
proto_tree_add_item(wsmp_tree,
|
2013-10-22 02:37:49 +00:00
|
|
|
hf_wsmp_channel, tvb, offset, elemenLen, ENC_BIG_ENDIAN);
|
2013-10-22 14:27:48 +00:00
|
|
|
offset += elemenLen;
|
|
|
|
}
|
|
|
|
else if (elemenId == DATARATE)
|
|
|
|
{
|
|
|
|
elemenLen = tvb_get_guint8(tvb, offset);
|
|
|
|
offset++;
|
|
|
|
proto_tree_add_item(wsmp_tree,
|
2013-10-22 02:37:49 +00:00
|
|
|
hf_wsmp_rate, tvb, offset, elemenLen, ENC_BIG_ENDIAN);
|
2013-10-22 14:27:48 +00:00
|
|
|
offset += elemenLen;
|
|
|
|
}
|
|
|
|
else if (elemenId == TRANSMITPW)
|
|
|
|
{
|
|
|
|
elemenLen = tvb_get_guint8(tvb, offset);
|
|
|
|
offset++;
|
|
|
|
proto_tree_add_item(wsmp_tree,
|
2013-10-22 02:37:49 +00:00
|
|
|
hf_wsmp_txpower, tvb, offset, elemenLen, ENC_BIG_ENDIAN);
|
2013-10-22 14:27:48 +00:00
|
|
|
offset += elemenLen;
|
2008-08-14 20:41:55 +00:00
|
|
|
}
|
2013-10-22 14:27:48 +00:00
|
|
|
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)
|
2013-10-22 02:37:49 +00:00
|
|
|
{
|
2013-10-22 14:27:48 +00:00
|
|
|
msb = tvb_get_guint8(tvb, offset + supLen);
|
|
|
|
msb = msb & 0x80;
|
|
|
|
supLen++;
|
2013-10-22 02:37:49 +00:00
|
|
|
}
|
2013-10-22 14:27:48 +00:00
|
|
|
proto_tree_add_item(wsmp_tree,
|
|
|
|
hf_wsmp_WSMP_S_data, tvb, offset, supLen, ENC_BIG_ENDIAN);
|
|
|
|
wsmlength -= supLen;
|
|
|
|
offset += supLen;
|
|
|
|
}
|
|
|
|
|
2014-07-06 18:21:40 +00:00
|
|
|
wsmdata_tree = proto_tree_add_subtree(wsmp_tree, tvb, offset, wsmlength,
|
|
|
|
ett_wsmdata, NULL, "Wave Short Message");
|
2013-10-22 14:27:48 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2008-08-14 20:41:55 +00:00
|
|
|
}
|
|
|
|
|
2008-08-25 19:25:40 +00:00
|
|
|
void
|
2008-08-14 20:41:55 +00:00
|
|
|
proto_register_wsmp(void)
|
2011-10-21 02:10:19 +00:00
|
|
|
{
|
2013-10-22 14:27:48 +00:00
|
|
|
static hf_register_info hf[] = {
|
|
|
|
{ &hf_wsmp_version,
|
|
|
|
{ "Version", "wsmp.version", FT_UINT8, BASE_DEC, NULL, 0x0,
|
|
|
|
NULL, HFILL }},
|
|
|
|
|
|
|
|
{ &hf_wsmp_psid,
|
|
|
|
{ "PSID", "wsmp.psid", FT_UINT32, BASE_HEX, NULL, 0x0,
|
|
|
|
NULL, HFILL }},
|
|
|
|
|
|
|
|
{ &hf_wsmp_channel,
|
|
|
|
{ "Channel", "wsmp.channel", FT_UINT8, BASE_DEC, NULL, 0x0,
|
|
|
|
NULL, HFILL }},
|
|
|
|
|
|
|
|
{ &hf_wsmp_rate,
|
|
|
|
{ "Data Rate", "wsmp.rate", FT_UINT8, BASE_DEC, NULL, 0x0,
|
|
|
|
NULL, HFILL }},
|
|
|
|
|
|
|
|
{ &hf_wsmp_txpower,
|
|
|
|
{ "Transmit Power", "wsmp.txpower", FT_UINT8, BASE_DEC, NULL, 0x0,
|
|
|
|
NULL, HFILL }},
|
|
|
|
|
|
|
|
{ &hf_wsmp_WAVEid,
|
|
|
|
{ "WAVE element id", "wsmp.WAVEid", FT_UINT8, BASE_DEC, VALS(wsmp_elemenid_names), 0x0,
|
|
|
|
NULL, HFILL }},
|
|
|
|
|
|
|
|
{ &hf_wsmp_wsmlength,
|
|
|
|
{ "WSM Length", "wsmp.wsmlength", FT_UINT16, BASE_DEC, NULL, 0x0,
|
|
|
|
NULL, HFILL }},
|
|
|
|
|
|
|
|
{ &hf_wsmp_WSMP_S_data,
|
|
|
|
{ "WAVE Supplement Data", "wsmp.supplement", FT_UINT8, BASE_HEX, NULL, 0x0,
|
|
|
|
NULL, HFILL }},
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Setup protocol subtree array */
|
|
|
|
static gint *ett[] = {
|
|
|
|
&ett_wsmp,
|
|
|
|
&ett_wsmdata,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Register the protocol name and description */
|
|
|
|
proto_wsmp = proto_register_protocol("Wave Short Message Protocol(IEEE P1609.3)",
|
|
|
|
"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));
|
2008-08-14 20:41:55 +00:00
|
|
|
}
|
|
|
|
|
2008-08-25 19:25:40 +00:00
|
|
|
void
|
2008-08-14 20:41:55 +00:00
|
|
|
proto_reg_handoff_wsmp(void)
|
|
|
|
{
|
2013-10-22 14:27:48 +00:00
|
|
|
dissector_handle_t wsmp_handle;
|
2008-08-14 20:41:55 +00:00
|
|
|
|
2013-10-22 14:27:48 +00:00
|
|
|
wsmp_handle = create_dissector_handle(dissect_wsmp, proto_wsmp);
|
|
|
|
dissector_add_uint("ethertype", ETHERTYPE_WSMP, wsmp_handle);
|
|
|
|
data_handle = find_dissector("data");
|
|
|
|
return;
|
2008-08-14 20:41:55 +00:00
|
|
|
}
|
2014-09-29 18:42:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Editor modelines - http://www.wireshark.org/tools/modelines.html
|
|
|
|
*
|
|
|
|
* Local variables:
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* tab-width: 8
|
|
|
|
* indent-tabs-mode: nil
|
|
|
|
* End:
|
|
|
|
*
|
|
|
|
* vi: set shiftwidth=4 tabstop=8 expandtab:
|
|
|
|
* :indentSize=4:tabSize=8:noTabs=true:
|
|
|
|
*/
|