Wireshark-dev: Re: [Wireshark-dev] Adding live 802.15.4 Capture
Date Prev · Date Next · Thread Prev · Thread Next
From: Bill Meier <wmeier@xxxxxxxxxxx>
Date: Wed, 01 Oct 2008 00:32:57 -0400
Colin O'Flynn wrote:

The problem is I don't see "wpan" as an option in the prefrences dialog! Any hints to what I am doing wrong? It seems fairly simple, however I'm not very familiar with the Wireshark sources.


The code compiles and works works fine once an "#include epan/prefs.h> is added :)

or:

Maybe the patch supplied doesn't completely reflect your actual code and the problem is actually that:

The preference appears (perhaps confusingly) under "IEEE 802.15.4" (the protocol "short name") since that's the way the protocol is registered.

    proto_ieee802154 = proto_register_protocol(
         "IEEE 802.15.4 Low-Rate Wireless PAN",
         "IEEE 802.15.4",
         "wpan");

    ("wpan" is used as the "filter_name")

Notes:

1. If the patch supplied reflects your actual code, you should have gotten a compilation error due to the missing include file. If you didn't, you'll need to revisit your compilation process.

2. The patch file is 'backwards' (new --> old) so could not be applied to packet-ieee802154.c as is. (I hand-edited the patch file so as to be usable).

3. I've taken the liberty to re-arrange the proto_reg_handoff code slightly. See the attached revised patch. (I've recently been doing work on the proto_reg_handoff functions in various of the dissectors and will be updating the doc/README.developer shortly).


The attachment is a revised version of your patch and is against the current development version of packet-ieee802154.c.

Index: packet-ieee802154.c
===================================================================
--- packet-ieee802154.c	(revision 26322)
+++ packet-ieee802154.c	(working copy)
@@ -77,6 +77,7 @@
 #include <epan/crc16.h>
 #include <epan/expert.h>
 #include <epan/addr_resolv.h>
+#include <epan/prefs.h>
 
 #include "packet-ieee802154.h"
 #include "packet-frame.h"   /* For Exception Handling */
@@ -85,6 +86,9 @@
 #define DISSECT_IEEE802154_OPTION_CC24xx    0x00000001  /* FCS field contains a TI CC24xx style FCS. */
 #define DISSECT_IEEE802154_OPTION_LINUX     0x00000002  /* Addressing fields are padded DLT_IEEE802_15_4_LINUX, not implemented. */
 
+/* ethertype for 802.15.4 tag - encapsulating an Ethernet packet */
+static unsigned int ieee802154_ethertype = 0x809A;
+
 /*  Function declarations */
 /* Register Functions. Loads the dissector into Wireshark. */
 void proto_reg_handoff_ieee802154   (void);
@@ -1662,6 +1666,8 @@
         &ett_ieee802154_bcn_pending
     };
 
+    module_t *ieee802154_module;
+
     /*  Register Protocol name and description. */
     proto_ieee802154 = proto_register_protocol("IEEE 802.15.4 Low-Rate Wireless PAN", "IEEE 802.15.4", "wpan");
 
@@ -1669,6 +1675,14 @@
     proto_register_field_array(proto_ieee802154, hf, array_length(hf));
     proto_register_subtree_array(ett, array_length(ett));
 
+    /* add a user preference to set the 802.15.4 ethertype */
+    ieee802154_module = prefs_register_protocol(proto_ieee802154, 
+						proto_reg_handoff_ieee802154);
+    prefs_register_uint_preference(ieee802154_module, "802154_ethertype",
+				   "802.15.4 (Hex) Ethertype",
+				   "(Hexadecimal) Ethertype used to indicate IEEE 802.15.4 frame.",
+				   16, &ieee802154_ethertype);
+
     /* Register the subdissector list */
     register_heur_dissector_list("wpan", &ieee802154_heur_subdissector_list);
 
@@ -1684,6 +1698,7 @@
  *  DESCRIPTION
  *      Registers the zigbee dissector with Wireshark.
  *      Will be called every time 'apply' is pressed in the preferences menu.
+ *       as well as during Wireshark initialization
  *  PARAMETERS
  *      none
  *  RETURNS
@@ -1692,13 +1707,26 @@
  */
 void proto_reg_handoff_ieee802154(void)
 {
-    dissector_handle_t  ieee802154_handle;
+    static gboolean prefs_initialized = FALSE;
+    static dissector_handle_t  ieee802154_handle;
+    static unsigned int old_ieee802154_ethertype;
 
-    /* Get the dissector handles. */
-    ieee802154_handle   = find_dissector("wpan");
-    data_handle         = find_dissector("data");
+    if (!prefs_initialized){
+        /* Get the dissector handles. */
+        ieee802154_handle   = find_dissector("wpan");
+        data_handle         = find_dissector("data");
 
+        dissector_add("wtap_encap", WTAP_ENCAP_IEEE802_15_4, ieee802154_handle);
+
+        prefs_initialized = TRUE;
+    } else {
+        dissector_delete("ethertype", old_ieee802154_ethertype, ieee802154_handle);	
+    }
+
+    old_ieee802154_ethertype = ieee802154_ethertype;
+	
     /* Register dissector handles. */
-    dissector_add("wtap_encap", WTAP_ENCAP_IEEE802_15_4, ieee802154_handle);
+    dissector_add("ethertype", ieee802154_ethertype, ieee802154_handle);
+
 } /* proto_reg_handoff_ieee802154 */