LoRaTap/LoRaWAN: Add decode as and fix field types

Allow LoRaTap syncword field to be used for "decode as".
Fix field types for LoRaWAN EUI fields to display as EUI-64 little endian.

Change-Id: I584f338031a4bc87e127d35a7bf8751a60e93d55
Reviewed-on: https://code.wireshark.org/review/25199
Reviewed-by: Michael Mann <mmann78@netscape.net>
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
This commit is contained in:
Erik de Jong 2018-01-08 21:09:51 +01:00 committed by Anders Broman
parent 958374f352
commit 0a8d6cf97e
2 changed files with 25 additions and 5 deletions

View File

@ -26,6 +26,8 @@
#include <wiretap/wtap.h>
#include <epan/packet.h>
#include <epan/capture_dissectors.h>
#include <epan/decode_as.h>
#include <epan/proto_data.h>
void proto_reg_handoff_loratap(void);
void proto_register_loratap(void);
@ -78,6 +80,18 @@ snr_base_custom(gchar *buffer, guint32 value) {
g_snprintf(buffer, ITEM_LABEL_LENGTH, "%d dB", value);
}
static void
loratap_prompt(packet_info *pinfo, gchar* result)
{
g_snprintf(result, MAX_DECODE_AS_PROMPT_LEN, "LoRaTap syncword 0x%02x as", GPOINTER_TO_UINT(p_get_proto_data(pinfo->pool, pinfo, proto_loratap, 0)));
}
static gpointer
loratap_value(packet_info *pinfo)
{
return p_get_proto_data(pinfo->pool, pinfo, proto_loratap, 0);
}
static int
dissect_loratap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree _U_, void *data _U_)
{
@ -119,7 +133,7 @@ dissect_loratap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree _U_, void *d
current_offset++;
proto_tree_add_item_ret_uint(loratap_tree, hf_loratap_header_syncword_type, tvb, current_offset, 1, ENC_NA, &syncword);
current_offset++;
p_add_proto_data(pinfo->pool, pinfo, proto_loratap, 0, GUINT_TO_POINTER((guint)syncword));
next_tvb = tvb_new_subset_length_caplen(tvb, current_offset, tvb_captured_length_remaining(tvb, current_offset), tvb_reported_length_remaining(tvb, current_offset));
if (!dissector_try_uint_new(loratap_dissector_table, syncword, next_tvb, pinfo, tree, TRUE, NULL)) {
@ -219,6 +233,11 @@ proto_register_loratap(void)
},
};
/* Register for decode as */
static build_valid_func loratap_da_build_value[1] = {loratap_value};
static decode_as_value_t loratap_da_values = {loratap_prompt, 1, loratap_da_build_value};
static decode_as_t loratap_da = {"loratap", "LoRa Syncword", "loratap.syncword", 1, 0, &loratap_da_values, NULL, NULL, decode_as_default_populate_list, decode_as_default_reset, decode_as_default_change, NULL};
/* Setup protocol subtree array */
static gint *ett[] = {
&ett_loratap
@ -234,6 +253,7 @@ proto_register_loratap(void)
proto_register_field_array(proto_loratap, hf, array_length(hf));
proto_register_subtree_array(ett, array_length(ett));
loratap_dissector_table = register_dissector_table("loratap.syncword", "LoRa Syncword", proto_loratap, FT_UINT8, BASE_HEX);
register_decode_as(&loratap_da);
}
/*

View File

@ -694,9 +694,9 @@ dissect_lorawan(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree _U_, void *d
if (mac_mtype == LORAWAN_MAC_MTYPE_JOINREQUEST) {
tf = proto_tree_add_item(lorawan_tree, hf_lorawan_join_request_type, tvb, current_offset, 18, ENC_NA);
field_tree = proto_item_add_subtree(tf, ett_lorawan_join_request);
proto_tree_add_item(field_tree, hf_lorawan_join_request_appeui_type, tvb, current_offset, 8, ENC_NA);
proto_tree_add_item(field_tree, hf_lorawan_join_request_appeui_type, tvb, current_offset, 8, ENC_LITTLE_ENDIAN);
current_offset += 8;
proto_tree_add_item(field_tree, hf_lorawan_join_request_deveui_type, tvb, current_offset, 8, ENC_NA);
proto_tree_add_item(field_tree, hf_lorawan_join_request_deveui_type, tvb, current_offset, 8, ENC_LITTLE_ENDIAN);
current_offset += 8;
proto_tree_add_item(field_tree, hf_lorawan_join_request_devnonce_type, tvb, current_offset, 2, ENC_NA);
current_offset += 2;
@ -1184,13 +1184,13 @@ proto_register_lorawan(void)
},
{ &hf_lorawan_join_request_appeui_type,
{ "AppEUI", "lorawan.join_request.appeui",
FT_BYTES, BASE_NONE,
FT_EUI64, BASE_NONE,
NULL, 0x0,
NULL, HFILL }
},
{ &hf_lorawan_join_request_deveui_type,
{ "DevEUI", "lorawan.join_request.deveui",
FT_BYTES, BASE_NONE,
FT_EUI64, BASE_NONE,
NULL, 0x0,
NULL, HFILL }
},