more
authorStefan Metzmacher <metze@samba.org>
Fri, 24 Nov 2017 14:26:00 +0000 (15:26 +0100)
committerStefan Metzmacher <metze@samba.org>
Sun, 20 Jan 2019 22:14:58 +0000 (23:14 +0100)
Change-Id: I8929f209b3b4eb9a3e851233527950846b34f292

epan/dissectors/packet-nmf.c

index ae5ab77..53f4cde 100644 (file)
@@ -45,6 +45,9 @@ static int hf_nmf_version_minor = -1;
 static int hf_nmf_mode_value = -1;
 static int hf_nmf_via_length = -1;
 static int hf_nmf_via_value = -1;
+static int hf_nmf_known_mode_value = -1;
+static int hf_nmf_upgrade_length = -1;
+static int hf_nmf_upgrade_protocol = -1;
 
 enum nmf_record_type {
        NMF_VERSION_RECORD              = 0x00,
@@ -86,6 +89,23 @@ static const value_string mode_values[] = {
        { 0, NULL }
 };
 
+static const value_string known_mode_values[] = {
+       { 0x00,         "SOAP 1.1 UTF-8"},
+       { 0x01,         "SOAP 1.1 UTF-16"},
+       { 0x02,         "SOAP 1.1 Unicode Little-Endian"},
+       { 0x03,         "SOAP 1.2 UTF-8"},
+       { 0x04,         "SOAP 1.2 UTF-16"},
+       { 0x05,         "SOAP 1.2 Unicode Little-Endian"},
+       { 0x06,         "SOAP 1.2 MOTM"},
+       { 0x07,         "SOAP 1.2 Binary"},
+       { 0x08,         "SOAP 1.2 Binary with in-band dictionary"},
+       { 0, NULL }
+};
+
+typedef struct nmf_conv_info_t {
+       guint32 fnum_upgraded;
+} nmf_conv_info_t;
+
 static int
 dissect_nmf_record_size(tvbuff_t *tvb, proto_tree *tree,
                        int hf_index, int offset, guint32 *_size)
@@ -118,7 +138,9 @@ dissect_nmf_record_size(tvbuff_t *tvb, proto_tree *tree,
 }
 
 static int
-dissect_nmf_record(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset)
+dissect_nmf_record(tvbuff_t *tvb, packet_info *pinfo,
+                  nmf_conv_info_t *nmf_info,
+                  proto_tree *tree, int offset)
 {
        proto_item *record_item = NULL;
        proto_tree *record_tree = NULL;
@@ -171,17 +193,48 @@ dissect_nmf_record(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offs
                proto_item_append_text(record_item, ": %s", (const gchar *)str);
                break;
        case NMF_KNOWN_ENCODING_RECORD:
+               proto_tree_add_item(record_tree, hf_nmf_known_mode_value,
+                                   tvb, offset, 1, ENC_NA);
                offset += 1;
                break;
        case NMF_EXTENSIBLE_ENCODING_RECORD:
+               /* TODO */
+               break;
        case NMF_UNSIZED_ENVELOPE_RECORD:
+               /* TODO */
+               break;
        case NMF_SIZED_ENVELOPE_RECORD:
+               /* TODO */
+               break;
        case NMF_END_RECORD:
+               /* TODO */
+               break;
        case NMF_FAULT_RECORD:
+               /* TODO */
+               break;
        case NMF_UPGRADE_REQUEST_RECORD:
+               offset = dissect_nmf_record_size(tvb, record_tree,
+                                                hf_nmf_upgrade_length,
+                                                offset, &size);
+               if (offset <= 0) {
+                       return -1;
+               }
+
+               proto_tree_add_item_ret_string(record_tree, hf_nmf_upgrade_protocol,
+                                              tvb, offset, size, ENC_UTF_8,
+                                              wmem_packet_scope(), &str);
+               offset += size;
+               proto_item_append_text(record_item, ": %s", (const gchar *)str);
+               break;
+
        case NMF_UPGRADE_RESPONSE_RECORD:
+               nmf_info->fnum_upgraded = pinfo->fd->num;
+               break;
        case NMF_PREAMBLE_ACK_RECORD:
+               /* TODO */
+               break;
        case NMF_PREAMBLE_END_RECORD:
+               /* TODO */
                break;
        }
 
@@ -194,11 +247,22 @@ dissect_nmf_record(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offs
 static int
 dissect_nmf(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, _U_ void *_unused)
 {
+       conversation_t *conv = NULL;
+       nmf_conv_info_t *nmf_info = NULL;
        proto_tree *tree = NULL;
        proto_item *item = NULL;
        guint len = tvb_reported_length(tvb);
        int offset = 0;
 
+       conv = find_or_create_conversation(pinfo);
+       nmf_info = (nmf_conv_info_t *)conversation_get_proto_data(conv,
+                                                                 proto_nmf);
+       if (nmf_info == NULL) {
+               nmf_info = wmem_new0(wmem_file_scope(), nmf_conv_info_t);
+               nmf_info->fnum_upgraded = 0xffffffff;
+               conversation_add_proto_data(conv, proto_nmf, nmf_info);
+       }
+
        col_set_str(pinfo->cinfo, COL_PROTOCOL, "NMF");
        col_clear(pinfo->cinfo, COL_INFO);
 
@@ -211,9 +275,16 @@ dissect_nmf(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, _U_ void
                return -1;
        }
 
+       if (pinfo->fd->num > nmf_info->fnum_upgraded) {
+               proto_item_append_text(item, ", Upgraded Packet len: %u (0x%x)",
+                               (unsigned)len, (unsigned)len);
+               offset += len;
+               return offset;
+       }
+
        while (len > 0) {
                int start_offset = offset;
-               offset = dissect_nmf_record(tvb, pinfo, tree, offset);
+               offset = dissect_nmf_record(tvb, pinfo, nmf_info, tree, offset);
                if (offset <= 0) {
                        return -1;
                }
@@ -248,8 +319,17 @@ void proto_register_nmf(void)
                { "Length", "nmf.via.length",
                FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }},
        { &hf_nmf_via_value,
-               { "Value", "nmf.via.value",
+               { "URI", "nmf.via.uri",
                FT_STRING, BASE_NONE, NULL, 0x0, "Via URI", HFILL }},
+       { &hf_nmf_known_mode_value,
+               { "Mode", "nmf.known_mode.value",
+               FT_UINT8, BASE_DEC, VALS(known_mode_values), 0, NULL, HFILL }},
+       { &hf_nmf_upgrade_length,
+               { "Length", "nmf.upgrade.length",
+               FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }},
+       { &hf_nmf_upgrade_protocol,
+               { "Upgrade Protocol", "nmf.upgrade.protocol",
+               FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }},
        };
 
        proto_nmf = proto_register_protocol("NMF (.NET Message Framing Protocol)",