summaryrefslogtreecommitdiff
path: root/epan
diff options
context:
space:
mode:
authorMichael Mann <mmann78@netscape.net>2016-06-21 20:06:01 -0400
committerAnders Broman <a.broman58@gmail.com>2016-06-22 04:57:43 +0000
commite7b78eb0a60a52e844a64452817649126213f771 (patch)
tree4cf3b86582a0cbd2632b79b6ce6932fd47a32ef5 /epan
parent3ed06ec32b64821b311f47c95862f3486f78aa53 (diff)
downloadwireshark-e7b78eb0a60a52e844a64452817649126213f771.tar.gz
Move AT_USB to inside USB dissector.
This required some hacking in the conversation table handling, but still seemed worth it as USB address is not widely used. Maybe a "is_stringlike" property for address types... Change-Id: I628a15c17cb1f595bb292130867adbc5bea0f41a Reviewed-on: https://code.wireshark.org/review/16068 Petri-Dish: Michael Mann <mmann78@netscape.net> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'epan')
-rw-r--r--epan/address.h2
-rw-r--r--epan/address_types.c39
-rw-r--r--epan/conversation_table.c17
-rw-r--r--epan/dissectors/packet-usb.c45
4 files changed, 50 insertions, 53 deletions
diff --git a/epan/address.h b/epan/address.h
index f0954aee7b..a0d098a423 100644
--- a/epan/address.h
+++ b/epan/address.h
@@ -52,8 +52,6 @@ typedef enum {
AT_STRINGZ, /* null-terminated string */
AT_EUI64, /* IEEE EUI-64 */
AT_IB, /* Infiniband GID/LID */
- AT_USB, /* USB Device address
- * (0xffffffff represents the host) */
AT_AX25, /* AX.25 */
AT_END_OF_LIST /* Must be last in list */
diff --git a/epan/address_types.c b/epan/address_types.c
index b1f94d8c47..a04af3f923 100644
--- a/epan/address_types.c
+++ b/epan/address_types.c
@@ -31,8 +31,6 @@
#include "wsutil/str_util.h"
#include "wsutil/inet_addr.h"
-#include <epan/dissectors/packet-mtp3.h>
-
struct _address_type_t {
int addr_type; /* From address_type enumeration or registered value */
const char *name;
@@ -489,30 +487,6 @@ static int ib_str_len(const address* addr _U_)
}
/******************************************************************************
- * AT_USB
- * XXX - This functionality should really be in packet-usb.c as a dissector
- * address type, but currently need support of AT_USB in conversation_table.c
- ******************************************************************************/
-static int usb_addr_to_str(const address* addr, gchar *buf, int buf_len _U_)
-{
- const guint8 *addrp = (const guint8 *)addr->data;
-
- if(pletoh32(&addrp[0])==0xffffffff){
- g_strlcpy(buf, "host", buf_len);
- } else {
- g_snprintf(buf, buf_len, "%d.%d.%d", pletoh16(&addrp[8]),
- pletoh32(&addrp[0]), pletoh32(&addrp[4]));
- }
-
- return (int)(strlen(buf)+1);
-}
-
-static int usb_addr_str_len(const address* addr _U_)
-{
- return 50;
-}
-
-/******************************************************************************
* AT_AX25
******************************************************************************/
static int ax25_addr_to_str(const address* addr, gchar *buf, int buf_len _U_)
@@ -692,18 +666,6 @@ void address_types_initialize(void)
NULL, /* addr_name_res_len */
};
- static address_type_t usb_address = {
- AT_USB, /* addr_type */
- "AT_USB", /* name */
- "USB Address", /* pretty_name */
- usb_addr_to_str, /* addr_to_str */
- usb_addr_str_len, /* addr_str_len */
- NULL, /* addr_col_filter */
- NULL, /* addr_fixed_len */
- NULL, /* addr_name_res_str */
- NULL, /* addr_name_res_len */
- };
-
static address_type_t ax25_address = {
AT_AX25, /* addr_type */
"AT_AX25", /* name */
@@ -733,7 +695,6 @@ void address_types_initialize(void)
address_type_register(AT_STRINGZ, &stringz_address );
address_type_register(AT_EUI64, &eui64_address );
address_type_register(AT_IB, &ib_address );
- address_type_register(AT_USB, &usb_address );
address_type_register(AT_AX25, &ax25_address );
}
diff --git a/epan/conversation_table.c b/epan/conversation_table.c
index e92f986d10..db6e972aab 100644
--- a/epan/conversation_table.c
+++ b/epan/conversation_table.c
@@ -29,6 +29,7 @@
#include "packet_info.h"
#include "conversation_table.h"
#include "addr_resolv.h"
+#include "address_types.h"
#include "stat_tap_ui.h"
@@ -396,24 +397,30 @@ ct_port_to_str(port_type ptype, guint32 port)
return NULL;
}
+static int usb_address_type = -1;
+
char *get_conversation_filter(conv_item_t *conv_item, conv_direction_e direction)
{
char *sport, *dport, *src_addr, *dst_addr;
char *str;
+ /* XXX - Hack until we find something better */
+ if (usb_address_type == -1)
+ usb_address_type = address_type_get_by_name("AT_USB");
+
sport = ct_port_to_str(conv_item->ptype, conv_item->src_port);
dport = ct_port_to_str(conv_item->ptype, conv_item->dst_port);
src_addr = address_to_str(NULL, &conv_item->src_address);
dst_addr = address_to_str(NULL, &conv_item->dst_address);
- if (conv_item->src_address.type == AT_STRINGZ || conv_item->src_address.type == AT_USB) {
+ if (conv_item->src_address.type == AT_STRINGZ || conv_item->src_address.type == usb_address_type) {
char *new_addr;
new_addr = wmem_strdup_printf(NULL, "\"%s\"", src_addr);
wmem_free(NULL, src_addr);
src_addr = new_addr;
}
- if (conv_item->dst_address.type == AT_STRINGZ || conv_item->dst_address.type == AT_USB) {
+ if (conv_item->dst_address.type == AT_STRINGZ || conv_item->dst_address.type == usb_address_type) {
char *new_addr;
new_addr = wmem_strdup_printf(NULL, "\"%s\"", dst_addr);
@@ -555,9 +562,13 @@ char *get_hostlist_filter(hostlist_talker_t *host)
char *sport, *src_addr;
char *str;
+ /* XXX - Hack until we find something better */
+ if (usb_address_type == -1)
+ usb_address_type = address_type_get_by_name("AT_USB");
+
sport = ct_port_to_str(host->ptype, host->port);
src_addr = address_to_str(NULL, &host->myaddress);
- if (host->myaddress.type == AT_STRINGZ || host->myaddress.type == AT_USB) {
+ if (host->myaddress.type == AT_STRINGZ || host->myaddress.type == usb_address_type) {
char *new_addr;
new_addr = wmem_strdup_printf(NULL, "\"%s\"", src_addr);
diff --git a/epan/dissectors/packet-usb.c b/epan/dissectors/packet-usb.c
index 85fdb1a8ef..9c1cc16470 100644
--- a/epan/dissectors/packet-usb.c
+++ b/epan/dissectors/packet-usb.c
@@ -31,11 +31,13 @@
#include <epan/packet.h>
#include <epan/exceptions.h>
#include <epan/addr_resolv.h>
+#include <epan/address_types.h>
#include <epan/conversation_table.h>
#include <epan/expert.h>
#include <epan/prefs.h>
#include <epan/decode_as.h>
#include <epan/proto_data.h>
+#include <wsutil/pint.h>
#include "packet-usb.h"
#include "packet-mausb.h"
@@ -255,6 +257,8 @@ static expert_field ei_usb_bLength_too_short = EI_INIT;
static expert_field ei_usb_desc_length_invalid = EI_INIT;
static expert_field ei_usb_invalid_setup = EI_INIT;
+static int usb_address_type = -1;
+
static const int *usb_endpoint_fields[] = {
&hf_usb_endpoint_direction,
&hf_usb_endpoint_number_value,
@@ -1255,6 +1259,27 @@ static value_string_ext usb_app_usb_test_and_measurement_protocol_vals_ext = VAL
void proto_register_usb(void);
void proto_reg_handoff_usb(void);
+/* USB address handling */
+static int usb_addr_to_str(const address* addr, gchar *buf, int buf_len _U_)
+{
+ const guint8 *addrp = (const guint8 *)addr->data;
+
+ if(pletoh32(&addrp[0])==0xffffffff){
+ g_strlcpy(buf, "host", buf_len);
+ } else {
+ g_snprintf(buf, buf_len, "%d.%d.%d", pletoh16(&addrp[8]),
+ pletoh32(&addrp[0]), pletoh32(&addrp[4]));
+ }
+
+ return (int)(strlen(buf)+1);
+}
+
+static int usb_addr_str_len(const address* addr _U_)
+{
+ return 50;
+}
+
+
/* This keys provide information for DecodeBy and other dissector via
per packet data: p_get_proto_data()/p_add_proto_data() */
#define USB_BUS_ID 0
@@ -1441,13 +1466,13 @@ get_usb_iface_conv_info(packet_info *pinfo, guint8 interface_num)
static const char* usb_conv_get_filter_type(conv_item_t* conv, conv_filter_type_e filter)
{
- if ((filter == CONV_FT_SRC_ADDRESS) && (conv->src_address.type == AT_USB))
+ if ((filter == CONV_FT_SRC_ADDRESS) && (conv->src_address.type == usb_address_type))
return "usb.src";
- if ((filter == CONV_FT_DST_ADDRESS) && (conv->dst_address.type == AT_USB))
+ if ((filter == CONV_FT_DST_ADDRESS) && (conv->dst_address.type == usb_address_type))
return "usb.dst";
- if ((filter == CONV_FT_ANY_ADDRESS) && (conv->src_address.type == AT_USB))
+ if ((filter == CONV_FT_ANY_ADDRESS) && (conv->src_address.type == usb_address_type))
return "usb.addr";
return CONV_FILTER_INVALID;
@@ -1466,7 +1491,7 @@ usb_conversation_packet(void *pct, packet_info *pinfo, epan_dissect_t *edt _U_,
static const char* usb_host_get_filter_type(hostlist_talker_t* host, conv_filter_type_e filter)
{
- if ((filter == CONV_FT_ANY_ADDRESS) && (host->myaddress.type == AT_USB))
+ if ((filter == CONV_FT_ANY_ADDRESS) && (host->myaddress.type == usb_address_type))
return "usb.addr";
return CONV_FILTER_INVALID;
@@ -2102,7 +2127,7 @@ dissect_usb_endpoint_descriptor(packet_info *pinfo, proto_tree *parent_tree,
usb_addr->bus_id = ((const usb_address_t *)(pinfo->src.data))->bus_id;
usb_addr->device = ((const usb_address_t *)(pinfo->src.data))->device;
usb_addr->endpoint = GUINT32_TO_LE(endpoint);
- set_address(&tmp_addr, AT_USB, USB_ADDR_LEN, (char *)usb_addr);
+ set_address(&tmp_addr, usb_address_type, USB_ADDR_LEN, (char *)usb_addr);
conversation = get_usb_conversation(pinfo, &tmp_addr, &pinfo->dst, usb_addr->endpoint, pinfo->destport);
}
@@ -3107,7 +3132,7 @@ try_dissect_next_protocol(proto_tree *tree, tvbuff_t *next_tvb, packet_info *pin
dst_addr->bus_id = usb_conv_info->bus_id;
dst_addr->device = usb_conv_info->device_address;
dst_addr->endpoint = dst_endpoint = GUINT32_TO_LE(endpoint);
- set_address(&endpoint_addr, AT_USB, USB_ADDR_LEN, (char *)dst_addr);
+ set_address(&endpoint_addr, usb_address_type, USB_ADDR_LEN, (char *)dst_addr);
conversation = get_usb_conversation(pinfo, &pinfo->src, &endpoint_addr, pinfo->srcport, dst_endpoint);
}
@@ -3116,7 +3141,7 @@ try_dissect_next_protocol(proto_tree *tree, tvbuff_t *next_tvb, packet_info *pin
src_addr->bus_id = usb_conv_info->bus_id;
src_addr->device = usb_conv_info->device_address;
src_addr->endpoint = src_endpoint = GUINT32_TO_LE(endpoint);
- set_address(&endpoint_addr, AT_USB, USB_ADDR_LEN, (char *)src_addr);
+ set_address(&endpoint_addr, usb_address_type, USB_ADDR_LEN, (char *)src_addr);
conversation = get_usb_conversation(pinfo, &endpoint_addr, &pinfo->dst, src_endpoint, pinfo->destport);
}
@@ -3517,9 +3542,9 @@ usb_set_addr(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, guint16 bus_id
src_addr->bus_id = GUINT16_TO_LE(bus_id);
dst_addr->bus_id = GUINT16_TO_LE(bus_id);
- set_address(&pinfo->net_src, AT_USB, USB_ADDR_LEN, (char *)src_addr);
+ set_address(&pinfo->net_src, usb_address_type, USB_ADDR_LEN, (char *)src_addr);
copy_address_shallow(&pinfo->src, &pinfo->net_src);
- set_address(&pinfo->net_dst, AT_USB, USB_ADDR_LEN, (char *)dst_addr);
+ set_address(&pinfo->net_dst, usb_address_type, USB_ADDR_LEN, (char *)dst_addr);
copy_address_shallow(&pinfo->dst, &pinfo->net_dst);
pinfo->ptype = PT_USB;
@@ -5290,6 +5315,8 @@ proto_register_usb(void)
register_decode_as(&usb_product_da);
register_decode_as(&usb_device_da);
+ usb_address_type = address_type_dissector_register("AT_USB", "USB Address", usb_addr_to_str, usb_addr_str_len, NULL, NULL, NULL, NULL);
+
register_conversation_table(proto_usb, TRUE, usb_conversation_packet, usb_hostlist_packet);
}