2 * Routines for BEEP packet disassembly
4 * $Id: packet-beep.c,v 1.7 2002/04/29 08:20:05 guy Exp $
6 * Copyright (c) 2000 by Richard Sharpe <rsharpe@ns.aus.com>
7 * Modified 2001 Darren New <dnew@invisible.net> for BEEP.
9 * Original BXXP dissector developed with funding from InvisibleWorlds
10 * (www.invisibleworlds.com) via Collab.Net.
12 * Ethereal - Network traffic analyzer
14 * Copyright 1999 Gerald Combs
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License
18 * as published by the Free Software Foundation; either version 2
19 * of the License, or (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
35 #ifdef HAVE_SYS_TYPES_H
36 # include <sys/types.h>
39 #ifdef HAVE_NETINET_IN_H
40 #include <netinet/in.h>
49 #include <epan/packet.h>
50 #include <epan/resolv.h>
52 #include <epan/conversation.h>
54 #define TCP_PORT_BEEP 10288
55 void proto_reg_handoff_beep(void);
58 static int global_beep_tcp_port = TCP_PORT_BEEP;
59 static int global_beep_strict_term = TRUE;
61 static int proto_beep = -1;
63 static int hf_beep_req = -1;
64 static int hf_beep_req_chan = -1;
65 static int hf_beep_rsp_chan = -1;
66 static int hf_beep_seq_chan = -1;
67 static int hf_beep_rsp = -1;
68 static int hf_beep_seq = -1;
69 static int hf_beep_end = -1;
70 static int hf_beep_proto_viol = -1;
71 static int hf_beep_complete = -1; /* No More data follows */
72 static int hf_beep_intermediate = -1; /* More data follows */
73 static int hf_beep_msgno = -1;
74 static int hf_beep_ansno = -1;
75 static int hf_beep_seqno = -1;
76 static int hf_beep_size = -1;
77 static int hf_beep_channel = -1;
78 static int hf_beep_positive = -1;
79 static int hf_beep_negative = -1;
80 static int hf_beep_ackno = -1;
81 static int hf_beep_window = -1;
83 /* Arrays of hf entry pointers for some routines to use. If you want more
84 * hidden items added for a field, add them to the list before the NULL,
85 * and the various routines that these are passed to will add them.
88 static int *req_msgno_hfa[] = { &hf_beep_msgno, NULL };
89 static int *req_ansno_hfa[] = { &hf_beep_ansno, NULL };
90 static int *req_seqno_hfa[] = { &hf_beep_seqno, NULL };
91 static int *req_size_hfa[] = { &hf_beep_size, NULL };
92 static int *req_chan_hfa[] = { &hf_beep_channel, &hf_beep_req_chan, NULL };
94 static int *rsp_msgno_hfa[] = { &hf_beep_msgno, NULL };
95 static int *rsp_seqno_hfa[] = { &hf_beep_seqno, NULL };
96 static int *rsp_size_hfa[] = { &hf_beep_size, NULL };
98 static int *seq_chan_hfa[] = { &hf_beep_channel, &hf_beep_seq_chan, NULL };
99 static int *seq_ackno_hfa[] = { &hf_beep_ackno, NULL };
100 static int *seq_window_hfa[] = { &hf_beep_window, NULL };
102 static int ett_beep = -1;
103 static int ett_mime_header = -1;
104 static int ett_header = -1;
105 static int ett_trailer = -1;
107 static unsigned int tcp_port = 0;
109 /* Get the state of the more flag ... */
112 #define BEEP_INTERMEDIATE 1
113 #define BEEP_COMPLETE 2
118 * pl_left is the amount of data in this packet that belongs to another
121 * It relies on TCP segments not being re-ordered too much ...
123 struct beep_proto_data {
124 int pl_left; /* Payload at beginning of frame */
125 int pl_size; /* Payload in current message ...*/
126 int mime_hdr; /* Whether we expect a mime header. 1 on first, 0 on rest
134 static int beep_packet_init_count = 100;
136 struct beep_request_key {
137 guint32 conversation;
140 struct beep_request_val {
141 guint16 processed; /* Have we processed this conversation? */
142 int size; /* Size of the message */
143 /* We need an indication in each dirn of
144 * whether on not a mime header is expected
146 int c_mime_hdr, s_mime_hdr;
149 static GHashTable *beep_request_hash = NULL;
150 static GMemChunk *beep_request_keys = NULL;
151 static GMemChunk *beep_request_vals = NULL;
152 static GMemChunk *beep_packet_infos = NULL;
156 beep_equal(gconstpointer v, gconstpointer w)
158 struct beep_request_key *v1 = (struct beep_request_key *)v;
159 struct beep_request_key *v2 = (struct beep_request_key *)w;
161 #if defined(DEBUG_BEEP_HASH)
162 printf("Comparing %08X\n and %08X\n",
163 v1->conversation, v2->conversation);
166 if (v1->conversation == v2->conversation)
174 beep_hash(gconstpointer v)
176 struct beep_request_key *key = (struct beep_request_key *)v;
179 val = key->conversation;
181 #if defined(DEBUG_BEEP_HASH)
182 printf("BEEP Hash calculated as %u\n", val);
190 beep_init_protocol(void)
192 #if defined(DEBUG_BEEP_HASH)
193 fprintf(stderr, "Initializing BEEP hashtable area\n");
196 if (beep_request_hash)
197 g_hash_table_destroy(beep_request_hash);
198 if (beep_request_keys)
199 g_mem_chunk_destroy(beep_request_keys);
200 if (beep_request_vals)
201 g_mem_chunk_destroy(beep_request_vals);
202 if (beep_packet_infos)
203 g_mem_chunk_destroy(beep_packet_infos);
205 beep_request_hash = g_hash_table_new(beep_hash, beep_equal);
206 beep_request_keys = g_mem_chunk_new("beep_request_keys",
207 sizeof(struct beep_request_key),
208 beep_packet_init_count * sizeof(struct beep_request_key), G_ALLOC_AND_FREE);
209 beep_request_vals = g_mem_chunk_new("beep_request_vals",
210 sizeof(struct beep_request_val),
211 beep_packet_init_count * sizeof(struct beep_request_val), G_ALLOC_AND_FREE);
212 beep_packet_infos = g_mem_chunk_new("beep_packet_infos",
213 sizeof(struct beep_proto_data),
214 beep_packet_init_count * sizeof(struct beep_proto_data), G_ALLOC_AND_FREE);
221 static int beep_get_more(char more)
225 return BEEP_COMPLETE;
226 else if (more == '*')
227 return BEEP_INTERMEDIATE;
232 /* dissect the more flag, and return a value of:
235 * -1 -> Proto violation
239 dissect_beep_more(tvbuff_t *tvb, int offset,
244 switch (beep_get_more(tvb_get_guint8(tvb, offset))) {
249 proto_tree_add_boolean_hidden(tree, hf_beep_complete, tvb, offset, 1, TRUE);
250 proto_tree_add_text(tree, tvb, offset, 1, "More: Complete");
257 case BEEP_INTERMEDIATE:
260 proto_tree_add_boolean_hidden(tree, hf_beep_intermediate, tvb, offset, 1, TRUE);
261 proto_tree_add_text(tree, tvb, offset, 1, "More: Intermediate");
271 proto_tree_add_boolean_hidden(tree, hf_beep_proto_viol, tvb, offset, 1, TRUE);
272 proto_tree_add_text(tree, tvb, offset, 1, "PROTOCOL VIOLATION: Expected More Flag (* or .)");
283 static void dissect_beep_status(tvbuff_t *tvb, int offset,
287 /* FIXME: We should return a value to indicate all OK. */
289 switch(tvb_get_guint8(tvb, offset)) {
294 proto_tree_add_boolean_hidden(tree, hf_beep_positive, tvb, offset, 1, TRUE);
295 proto_tree_add_text(tree, tvb, offset, 1, "Status: Positive");
303 proto_tree_add_boolean_hidden(tree, hf_beep_negative, tvb, offset, 1, TRUE);
304 proto_tree_add_text(tree, tvb, offset, 1, "Status: Negative");
309 default: /* Proto violation: FIXME */
318 static int num_len(tvbuff_t *tvb, int offset)
322 while (isdigit(tvb_get_guint8(tvb, offset + i))) i++;
329 * We check for a terminator. This can be CRLF, which will be recorded
330 * as a terminator, or CR or LF by itself, which will be redorded as
331 * an incorrect terminator ... We build the tree at this point
332 * However, we depend on the variable beep_strict_term
336 check_term(tvbuff_t *tvb, int offset, proto_tree *tree)
339 /* First, check for CRLF, or, if global_beep_strict_term is false,
340 * one of CR or LF ... If neither of these hold, we add an element
341 * that complains of a protocol violation, and return -1, else
342 * we add a terminator to the tree (possibly non-standard) and return
343 * the count of characters we saw ... This may throw off the rest of the
344 * dissection ... so-be-it!
347 if ((tvb_get_guint8(tvb, offset) == 0x0d &&
348 tvb_get_guint8(tvb, offset + 1) == 0x0a)){ /* Correct terminator */
351 proto_tree_add_text(tree, tvb, offset, 2, "Terminator: CRLF");
356 else if ((tvb_get_guint8(tvb, offset) == 0x0d) && !global_beep_strict_term) {
359 proto_tree_add_text(tree, tvb, offset, 1, "Nonstandard Terminator: CR");
360 proto_tree_add_boolean_hidden(tree, hf_beep_proto_viol, tvb, offset, 1, TRUE);
365 else if ((tvb_get_guint8(tvb, offset) == 0x0a) && !global_beep_strict_term) {
368 proto_tree_add_text(tree, tvb, offset, 1, "Nonstandard Terminator: LF");
369 proto_tree_add_boolean_hidden(tree, hf_beep_proto_viol, tvb, offset, 1, TRUE);
377 proto_tree_add_text(tree, tvb, offset, 2, "PROTOCOL VIOLATION, Invalid Terminator: %s", tvb_format_text(tvb, offset, 2));
378 proto_tree_add_boolean_hidden(tree, hf_beep_proto_viol, tvb, offset, 2, TRUE);
386 /* Get the header length, up to CRLF or CR or LF */
387 static int header_len(tvbuff_t *tvb, int offset)
392 /* FIXME: Have to make sure we stop looking at the end of the tvb ... */
394 /* We look for CRLF, or CR or LF if global_beep_strict_term is
400 if (tvb_ensure_length_remaining(tvb, offset + i) < 1)
401 return i; /* Not enough characters left ... */
403 if ((sc = tvb_get_guint8(tvb, offset + i)) == 0x0d
404 && tvb_get_guint8(tvb, offset + i + 1) == 0x0a)
405 return i; /* Done here ... */
407 if (!global_beep_strict_term && (sc == 0x0d || sc == 0x0a))
408 return i; /* Done here also ... */
416 dissect_beep_mime_header(tvbuff_t *tvb, int offset,
417 struct beep_proto_data *frame_data,
420 proto_tree *ti = NULL, *mime_tree = NULL;
421 int mime_length = header_len(tvb, offset), cc = 0;
423 if (frame_data && !frame_data->mime_hdr) return 0;
427 /* FIXME: Should calculate the whole length of the mime headers */
429 ti = proto_tree_add_text(tree, tvb, offset, mime_length, "Mime header: %s", tvb_format_text(tvb, offset, mime_length));
430 mime_tree = proto_item_add_subtree(ti, ett_mime_header);
433 if (mime_length == 0) { /* Default header */
436 proto_tree_add_text(mime_tree, tvb, offset, 0, "Default values");
439 if ((cc = check_term(tvb, offset, mime_tree)) <= 0) {
441 /* Ignore it, it will cause funnies in the rest of the dissect */
446 else { /* FIXME: Process the headers */
449 proto_tree_add_text(mime_tree, tvb, offset, mime_length, "Header: %s",
450 tvb_format_text(tvb, offset, mime_length));
453 if ((cc = check_term(tvb, offset + mime_length, mime_tree)) <= 0) {
455 /* Ignore it, it will cause funnies in the rest of the dissect */
461 return mime_length + cc; /* FIXME: Check that the CRLF is there */
466 dissect_beep_int(tvbuff_t *tvb, int offset,
467 proto_tree *tree, int hf, int *val, int *hfa[])
470 unsigned int i = num_len(tvb, offset);
471 guint8 int_buff[100];
473 memset(int_buff, '\0', sizeof(int_buff));
475 tvb_memcpy(tvb, int_buff, offset, MIN(sizeof(int_buff), i));
477 sscanf(int_buff, "%d", &ival); /* FIXME: Dangerous */
480 proto_tree_add_uint(tree, hf, tvb, offset, i, ival);
485 proto_tree_add_uint_hidden(tree, *hfa[ind], tvb, offset, i, ival);
490 *val = ival; /* Return the value */
497 set_mime_hdr_flags(int more, struct beep_request_val *request_val,
498 struct beep_proto_data *frame_data, packet_info *pinfo)
501 if (!request_val) return; /* Nothing to do ??? */
503 if (pinfo->destport == tcp_port) { /* Going to the server ... client */
505 if (request_val->c_mime_hdr) {
507 frame_data->mime_hdr = 0;
509 if (!more) request_val->c_mime_hdr = 0;
514 frame_data->mime_hdr = 1;
516 if (more) request_val->c_mime_hdr = 1;
523 if (request_val->s_mime_hdr) {
525 frame_data->mime_hdr = 0;
527 if (!more) request_val->s_mime_hdr = 0;
532 frame_data->mime_hdr = 1;
534 if (more) request_val->s_mime_hdr = 1;
544 * A return value of <= 0 says we bailed out, skip the rest of this message,
547 * A return value > 0 is the count of bytes we consumed ...
551 dissect_beep_tree(tvbuff_t *tvb, int offset, packet_info *pinfo,
552 proto_tree *tree, struct beep_request_val *request_val,
553 struct beep_proto_data *frame_data)
555 proto_tree *ti = NULL, *hdr = NULL;
556 int st_offset, msgno, ansno, seqno, size, channel, ackno, window, cc,
559 char * cmd_temp = NULL;
563 if (tvb_strneql(tvb, offset, "MSG ", 4) == 0)
564 cmd_temp = "Command: MSG";
565 if (tvb_strneql(tvb, offset, "RPY ", 4) == 0)
566 cmd_temp = "Command: RPY";
567 if (tvb_strneql(tvb, offset, "ERR ", 4) == 0)
568 cmd_temp = "Command: ERR";
569 if (tvb_strneql(tvb, offset, "NUL ", 4) == 0)
570 cmd_temp = "Command: NUL";
571 if (tvb_strneql(tvb, offset, "ANS ", 4) == 0) {
572 cmd_temp = "Command: ANS";
576 if (cmd_temp != NULL) {
579 ti = proto_tree_add_text(tree, tvb, offset, header_len(tvb, offset) + 2, "Header");
581 hdr = proto_item_add_subtree(ti, ett_header);
583 proto_tree_add_boolean_hidden(hdr, hf_beep_req, tvb, offset, 3, TRUE);
584 proto_tree_add_text(hdr, tvb, offset, 3, cmd_temp);
589 /* Get the channel */
590 offset += dissect_beep_int(tvb, offset, hdr, hf_beep_channel, &channel, req_chan_hfa);
591 offset += 1; /* Skip the space */
593 /* Dissect the message number */
594 offset += dissect_beep_int(tvb, offset, hdr, hf_beep_msgno, &msgno, req_msgno_hfa);
595 offset += 1; /* skip the space */
597 /* Insert the more elements ... */
598 if ((more = dissect_beep_more(tvb, offset, hdr)) >= 0) {
599 /* Figure out which direction this is in and what mime_hdr flag to
600 * add to the frame_data. If there are missing segments, this code
603 set_mime_hdr_flags(more, request_val, frame_data, pinfo);
605 else { /* Protocol violation, so dissect rest as undisectable */
607 proto_tree_add_text(hdr, tvb, offset,
608 tvb_length_remaining(tvb, offset),
609 "Undissected Payload: %s",
610 tvb_format_text(tvb, offset,
611 tvb_length_remaining(tvb, offset)
619 offset += 2; /* Skip the flag and the space ... */
621 /* now for the seqno */
622 offset += dissect_beep_int(tvb, offset, hdr, hf_beep_seqno, &seqno, req_seqno_hfa);
623 offset += 1; /* skip the space */
625 offset += dissect_beep_int(tvb, offset, hdr, hf_beep_size, &size, req_size_hfa);
626 if (request_val) /* FIXME, is this the right order ... */
627 request_val -> size = size; /* Stash this away */
629 frame_data->pl_size = size;
630 if (frame_data->pl_size < 0) frame_data->pl_size = 0; /* FIXME: OK? */
632 /* offset += 1; skip the space */
634 if (is_ANS) { /* We need to put in the ansno */
635 offset += 1; /* skip the space */
636 /* Dissect the message number */
637 offset += dissect_beep_int(tvb, offset, hdr, hf_beep_ansno, &ansno, req_ansno_hfa);
640 if ((cc = check_term(tvb, offset, hdr)) <= 0) {
642 /* We dissect the rest as data and bail ... */
645 proto_tree_add_text(hdr, tvb, offset,
646 tvb_length_remaining(tvb, offset),
647 "Undissected Payload: %s",
648 tvb_format_text(tvb, offset,
649 tvb_length_remaining(tvb, offset)
660 /* Insert MIME header ... */
662 if (frame_data && frame_data->mime_hdr)
663 offset += dissect_beep_mime_header(tvb, offset, frame_data, hdr);
665 /* Now for the payload, if any */
667 if (tvb_length_remaining(tvb, offset) > 0) { /* Dissect what is left as payload */
669 int pl_size = MIN(size, tvb_length_remaining(tvb, offset));
671 /* Except, check the payload length, and only dissect that much */
673 /* We need to keep track, in the conversation, of how much is left
674 * so in the next packet, we can figure out what is part of the payload
675 * and what is the next message
679 proto_tree_add_text(tree, tvb, offset, pl_size, "Payload: %s", tvb_format_text(tvb, offset, pl_size));
686 request_val->size -= pl_size;
687 if (request_val->size < 0) request_val->size = 0;
690 frame_data->pl_size -= pl_size;
691 if (frame_data->pl_size < 0) frame_data->pl_size = 0;
695 /* If anything else left, dissect it ... */
697 if (tvb_length_remaining(tvb, offset) > 0)
698 offset += dissect_beep_tree(tvb, offset, pinfo, tree, request_val, frame_data);
700 } else if (tvb_strneql(tvb, offset, "SEQ ", 4) == 0) {
703 proto_tree_add_boolean_hidden(tree, hf_beep_seq, tvb, offset, 3, TRUE);
704 proto_tree_add_text(tree, tvb, offset, 3, "Command: SEQ");
709 /* Now check the space: FIXME */
713 offset += dissect_beep_int(tvb, offset, tree, hf_beep_channel, &channel, seq_chan_hfa);
715 /* Check the space: FIXME */
719 offset += dissect_beep_int(tvb, offset, tree, hf_beep_ackno, &ackno, seq_ackno_hfa);
721 /* Check the space: FIXME */
725 offset += dissect_beep_int(tvb, offset, tree, hf_beep_window, &window, seq_window_hfa);
727 if ((cc = check_term(tvb, offset, tree)) <= 0) {
729 /* We dissect the rest as data and bail ... */
732 proto_tree_add_text(tree, tvb, offset,
733 tvb_length_remaining(tvb, offset),
734 "Undissected Payload: %s",
735 tvb_format_text(tvb, offset,
736 tvb_length_remaining(tvb, offset)
747 } else if (tvb_strneql(tvb, offset, "END", 3) == 0) {
749 proto_tree *tr = NULL;
752 ti = proto_tree_add_text(tree, tvb, offset, MIN(5, tvb_length_remaining(tvb, offset)), "Trailer");
754 tr = proto_item_add_subtree(ti, ett_trailer);
756 proto_tree_add_boolean_hidden(tr, hf_beep_end, tvb, offset, 3, TRUE);
757 proto_tree_add_text(tr, tvb, offset, 3, "Command: END");
763 if ((cc = check_term(tvb, offset, tr)) <= 0) {
765 /* We dissect the rest as data and bail ... */
768 proto_tree_add_text(tr, tvb, offset, tvb_length_remaining(tvb, offset),
769 "Undissected Payload: %s",
770 tvb_format_text(tvb, offset,
771 tvb_length_remaining(tvb, offset)
784 if (tvb_length_remaining(tvb, offset) > 0) { /* Dissect anything left over */
790 pl_size = MIN(request_val->size, tvb_length_remaining(tvb, offset));
792 if (pl_size == 0) { /* The whole of the rest must be payload */
794 pl_size = tvb_length_remaining(tvb, offset); /* Right place ? */
798 } else if (frame_data) {
799 pl_size = MIN(frame_data->pl_size, tvb_length_remaining(tvb, offset));
800 } else { /* Just in case */
801 pl_size = tvb_length_remaining(tvb, offset);
804 /* Take care here to handle the payload correctly, and if there is
805 * another message here, then handle it correctly as well.
808 /* If the pl_size == 0 and the offset == 0?, then we have not processed
809 * anything in this frame above, so we better treat all this data as
810 * payload to avoid recursion loops
813 if (pl_size == 0 && offset == st_offset)
814 pl_size = tvb_length_remaining(tvb, offset);
819 proto_tree_add_text(tree, tvb, offset, pl_size, "Payload: %s",
820 tvb_format_text(tvb, offset, pl_size));
823 offset += pl_size; /* Advance past the payload */
826 request_val->size -= pl_size; /* Reduce payload by what we added */
827 if (request_val->size < 0) request_val->size = 0;
830 frame_data->pl_size -= pl_size;
831 if (frame_data->pl_size < 0) frame_data->pl_size = 0;
835 if (tvb_length_remaining(tvb, offset) > 0) {
836 offset += dissect_beep_tree(tvb, offset, pinfo, tree, request_val, frame_data);
840 return offset - st_offset;
845 dissect_beep(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
848 struct beep_proto_data *frame_data = NULL;
849 proto_tree *beep_tree = NULL, *ti = NULL;
850 conversation_t *conversation = NULL;
851 struct beep_request_key request_key, *new_request_key;
852 struct beep_request_val *request_val = NULL;
856 /* If we have per frame data, use that, else, we must have lost the per-
857 * frame data, and we have to do a full dissect pass again.
859 * The per-frame data tells us how much of this frame is left over from a
860 * previous frame, so we dissect it as payload and then try to dissect the
863 * We use the conversation to build up info on the first pass over the
864 * packets of type BEEP, and record anything that is needed if the user
865 * does random dissects of packets in per packet data.
867 * Once we have per-packet data, we don't need the conversation stuff
868 * anymore, but if per-packet data and conversation stuff gets deleted, as
869 * it does under some circumstances when a rescan is done, it all gets
873 /* Find out what conversation this packet is part of ... but only
874 * if we have no information on this packet, so find the per-frame
878 frame_data = p_get_proto_data(pinfo->fd, proto_beep);
882 conversation = find_conversation(&pinfo->src, &pinfo->dst, pinfo->ptype,
883 pinfo->srcport, pinfo->destport, 0);
884 if (conversation == NULL) { /* No conversation, create one */
885 conversation = conversation_new(&pinfo->src, &pinfo->dst, pinfo->ptype,
886 pinfo->srcport, pinfo->destport, 0);
891 * Check for and insert an entry in the request table if does not exist
893 request_key.conversation = conversation->index;
895 request_val = (struct beep_request_val *)g_hash_table_lookup(beep_request_hash, &request_key);
897 if (!request_val) { /* Create one */
899 new_request_key = g_mem_chunk_alloc(beep_request_keys);
900 new_request_key->conversation = conversation->index;
902 request_val = g_mem_chunk_alloc(beep_request_vals);
903 request_val->processed = 0;
904 request_val->size = 0;
906 g_hash_table_insert(beep_request_hash, new_request_key, request_val);
911 if (check_col(pinfo->cinfo, COL_PROTOCOL))
912 col_set_str(pinfo->cinfo, COL_PROTOCOL, "BEEP");
914 if (check_col(pinfo->cinfo, COL_INFO)) { /* Check the type ... */
916 /* "tvb_format_text()" is passed a value that won't go past the end
917 * of the packet, so it won't throw an exception. */
918 col_add_str(pinfo->cinfo, COL_INFO, tvb_format_text(tvb, offset, tvb_length_remaining(tvb, offset)));
922 /* Here, we parse the message so we can retrieve the info we need, which
923 * is that there is some payload left from a previous segment on the
924 * front of this segment ... This all depends on TCP segments not getting
927 * As a huge kludge, we push the checking for the tree down into the code
928 * and process as if we were given a tree but not call the routines that
929 * adorn the protocol tree if they were NULL.
932 if (tree) { /* Build the tree info ... */
934 ti = proto_tree_add_item(tree, proto_beep, tvb, offset, -1, FALSE);
936 beep_tree = proto_item_add_subtree(ti, ett_beep);
940 /* Check the per-frame data and the conversation for any left-over
941 * payload from the previous frame
943 * We check that per-frame data exists first, and if so, use it,
944 * else we use the conversation data.
946 * We create per-frame data here as well, but we must ensure we create it
947 * after we have done the check for per-frame or conversation data.
949 * We also depend on the first frame in a group having a pl_size of 0.
952 if (frame_data && frame_data->pl_left > 0) {
954 int pl_left = frame_data->pl_left;
956 pl_left = MIN(pl_left, tvb_length_remaining(tvb, offset));
958 /* Add the payload bit, only if we have a tree */
960 proto_tree_add_text(beep_tree, tvb, offset, pl_left, "Payload: %s",
961 tvb_format_text(tvb, offset, pl_left));
965 else if (request_val && request_val->size > 0) {
967 int pl_left = request_val->size;
969 request_val->size = 0;
971 /* We create the frame data here for this case, and
972 * elsewhere for other frames
975 frame_data = g_mem_chunk_alloc(beep_packet_infos);
977 frame_data->pl_left = pl_left;
978 frame_data->pl_size = 0;
979 frame_data->mime_hdr = 0;
981 p_add_proto_data(pinfo->fd, proto_beep, frame_data);
985 /* Set up the per-frame data here if not already done so
986 * This _must_ come after the checks above ...
989 if (frame_data == NULL) {
991 frame_data = g_mem_chunk_alloc(beep_packet_infos);
993 frame_data->pl_left = 0;
994 frame_data->pl_size = 0;
995 frame_data->mime_hdr = 0;
997 p_add_proto_data(pinfo->fd, proto_beep, frame_data);
1001 if (tvb_length_remaining(tvb, offset) > 0) {
1003 offset += dissect_beep_tree(tvb, offset, pinfo, beep_tree, request_val, frame_data);
1009 /* Register all the bits needed with the filtering engine */
1012 proto_register_beep(void)
1014 static hf_register_info hf[] = {
1015 { &hf_beep_proto_viol,
1016 { "Protocol Violation", "beep.violation", FT_BOOLEAN, BASE_NONE, NULL, 0x0, "", HFILL }},
1019 { "Request", "beep.req", FT_BOOLEAN, BASE_NONE, NULL, 0x0, "", HFILL }},
1021 { &hf_beep_req_chan,
1022 { "Request Channel Number", "beep.req.channel", FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},
1025 { "Response", "beep.rsp", FT_BOOLEAN, BASE_NONE, NULL, 0x0, "", HFILL }},
1027 { &hf_beep_rsp_chan,
1028 { "Response Channel Number", "beep.rsp.channel", FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},
1031 { "Sequence", "beep.seq", FT_BOOLEAN, BASE_NONE, NULL, 0x0, "", HFILL }},
1033 { &hf_beep_seq_chan,
1034 { "Sequence Channel Number", "beep.seq.channel", FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},
1037 { "End", "beep.end", FT_BOOLEAN, BASE_NONE, NULL, 0x0, "", HFILL }},
1039 { &hf_beep_complete,
1040 { "Complete", "beep.more.complete", FT_BOOLEAN, BASE_NONE, NULL, 0x0, "", HFILL }},
1042 { &hf_beep_intermediate,
1043 { "Intermediate", "beep.more.intermediate", FT_BOOLEAN, BASE_NONE, NULL, 0x0, "", HFILL }},
1046 { "Msgno", "beep.msgno", FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},
1049 { "Ansno", "beep.ansno", FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},
1052 { "Seqno", "beep.seqno", FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},
1055 { "Size", "beep.size", FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},
1058 { "Channel", "beep.channel", FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},
1060 { &hf_beep_negative,
1061 { "Negative", "beep.status.negative", FT_BOOLEAN, BASE_NONE, NULL, 0x0, "", HFILL }},
1063 { &hf_beep_positive,
1064 { "Positive", "beep.status.positive", FT_BOOLEAN, BASE_NONE, NULL, 0x0, "", HFILL }},
1067 { "Ackno", "beep.seq.ackno", FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},
1070 { "Window", "beep.seq.window", FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},
1073 static gint *ett[] = {
1079 module_t *beep_module;
1081 proto_beep = proto_register_protocol("Blocks Extensible Exchange Protocol",
1084 proto_register_field_array(proto_beep, hf, array_length(hf));
1085 proto_register_subtree_array(ett, array_length(ett));
1086 register_init_routine(&beep_init_protocol);
1088 /* Register our configuration options for BEEP, particularly our port */
1090 beep_module = prefs_register_protocol(proto_beep, proto_reg_handoff_beep);
1092 prefs_register_uint_preference(beep_module, "tcp.port", "BEEP TCP Port",
1093 "Set the port for BEEP messages (if other"
1094 " than the default of 10288)",
1095 10, &global_beep_tcp_port);
1097 prefs_register_bool_preference(beep_module, "strict_header_terminator",
1098 "BEEP Header Requires CRLF",
1099 "Specifies that BEEP requires CRLF as a "
1100 "terminator, and not just CR or LF",
1101 &global_beep_strict_term);
1104 /* The registration hand-off routine */
1106 proto_reg_handoff_beep(void)
1108 static int beep_prefs_initialized = FALSE;
1109 static dissector_handle_t beep_handle;
1111 if (!beep_prefs_initialized) {
1113 beep_handle = create_dissector_handle(dissect_beep, proto_beep);
1115 beep_prefs_initialized = TRUE;
1120 dissector_delete("tcp.port", tcp_port, beep_handle);
1124 /* Set our port number for future use */
1126 tcp_port = global_beep_tcp_port;
1128 dissector_add("tcp.port", global_beep_tcp_port, beep_handle);