2 * Routines for BXXP packet disassembly
4 * $Id: packet-bxxp.c,v 1.15 2001/01/09 06:31:34 guy Exp $
6 * Copyright (c) 2000 by Richard Sharpe <rsharpe@ns.aus.com>
8 * Developed with funding from InvisibleWorlds (www.invisibleworlds.com) via
11 * Ethereal - Network traffic analyzer
13 * Copyright 1999 Gerald Combs
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
33 #ifdef HAVE_SYS_TYPES_H
34 # include <sys/types.h>
37 #ifdef HAVE_NETINET_IN_H
38 #include <netinet/in.h>
50 #include "conversation.h"
52 #define TCP_PORT_BXXP 10288
53 void proto_reg_handoff_bxxp(void);
56 static int global_bxxp_tcp_port = TCP_PORT_BXXP;
57 static int global_bxxp_strict_term = TRUE;
59 static int proto_bxxp = -1;
61 static int hf_bxxp_req = -1;
62 static int hf_bxxp_req_chan = -1;
63 static int hf_bxxp_rsp_chan = -1;
64 static int hf_bxxp_seq_chan = -1;
65 static int hf_bxxp_rsp = -1;
66 static int hf_bxxp_seq = -1;
67 static int hf_bxxp_end = -1;
68 static int hf_bxxp_proto_viol = -1;
69 static int hf_bxxp_complete = -1; /* No More data follows */
70 static int hf_bxxp_intermediate = -1; /* More data follows */
71 static int hf_bxxp_serial = -1;
72 static int hf_bxxp_seqno = -1;
73 static int hf_bxxp_size = -1;
74 static int hf_bxxp_channel = -1;
75 static int hf_bxxp_positive = -1;
76 static int hf_bxxp_negative = -1;
77 static int hf_bxxp_ackno = -1;
78 static int hf_bxxp_window = -1;
80 /* Arrays of hf entry pointers for some routines to use. If you want more
81 * hidden items added for a field, add them to the list before the NULL,
82 * and the various routines that these are passed to will add them.
85 static int *req_serial_hfa[] = { &hf_bxxp_serial, NULL };
86 static int *req_seqno_hfa[] = { &hf_bxxp_seqno, NULL };
87 static int *req_size_hfa[] = { &hf_bxxp_size, NULL };
88 static int *req_chan_hfa[] = { &hf_bxxp_channel, &hf_bxxp_req_chan, NULL };
89 static int *rsp_serial_hfa[] = { &hf_bxxp_serial, NULL };
90 static int *rsp_seqno_hfa[] = { &hf_bxxp_seqno, NULL };
91 static int *rsp_size_hfa[] = { &hf_bxxp_size, NULL };
92 static int *seq_chan_hfa[] = { &hf_bxxp_channel, &hf_bxxp_seq_chan, NULL };
93 static int *seq_ackno_hfa[] = { &hf_bxxp_ackno, NULL };
94 static int *seq_window_hfa[] = { &hf_bxxp_window, NULL };
96 static int ett_bxxp = -1;
97 static int ett_mime_header = -1;
98 static int ett_header = -1;
99 static int ett_trailer = -1;
101 static int tcp_port = 0;
103 /* Get the state of the more flag ... */
106 #define BXXP_INTERMEDIATE 1
107 #define BXXP_COMPLETE 2
112 * pl_left is the amount of data in this packet that belongs to another
115 * It relies on TCP segments not being re-ordered too much ...
117 struct bxxp_proto_data {
118 int pl_left; /* Payload at beginning of frame */
119 int pl_size; /* Payload in current message ...*/
120 int mime_hdr; /* Whether we expect a mime header. 1 on first, 0 on rest
128 static int bxxp_packet_init_count = 100;
130 struct bxxp_request_key {
131 guint32 conversation;
134 struct bxxp_request_val {
135 guint16 processed; /* Have we processed this conversation? */
136 int size; /* Size of the message */
137 /* We need an indication in each dirn of
138 * whether on not a mime header is expected
140 int c_mime_hdr, s_mime_hdr;
143 GHashTable *bxxp_request_hash = NULL;
144 GMemChunk *bxxp_request_keys = NULL;
145 GMemChunk *bxxp_request_vals = NULL;
146 GMemChunk *bxxp_packet_infos = NULL;
150 bxxp_equal(gconstpointer v, gconstpointer w)
152 struct bxxp_request_key *v1 = (struct bxxp_request_key *)v;
153 struct bxxp_request_key *v2 = (struct bxxp_request_key *)w;
155 #if defined(DEBUG_BXXP_HASH)
156 printf("Comparing %08X\n and %08X\n",
157 v1->conversation, v2->conversation);
160 if (v1->conversation == v2->conversation)
168 bxxp_hash(gconstpointer v)
170 struct bxxp_request_key *key = (struct bxxp_request_key *)v;
173 val = key->conversation;
175 #if defined(DEBUG_BXXP_HASH)
176 printf("BXXP Hash calculated as %u\n", val);
184 bxxp_init_protocol(void)
186 #if defined(DEBUG_BXXP_HASH)
187 fprintf(stderr, "Initializing BXXP hashtable area\n");
190 if (bxxp_request_hash)
191 g_hash_table_destroy(bxxp_request_hash);
192 if (bxxp_request_keys)
193 g_mem_chunk_destroy(bxxp_request_keys);
194 if (bxxp_request_vals)
195 g_mem_chunk_destroy(bxxp_request_vals);
196 if (bxxp_packet_infos)
197 g_mem_chunk_destroy(bxxp_packet_infos);
199 bxxp_request_hash = g_hash_table_new(bxxp_hash, bxxp_equal);
200 bxxp_request_keys = g_mem_chunk_new("bxxp_request_keys",
201 sizeof(struct bxxp_request_key),
202 bxxp_packet_init_count * sizeof(struct bxxp_request_key), G_ALLOC_AND_FREE);
203 bxxp_request_vals = g_mem_chunk_new("bxxp_request_vals",
204 sizeof(struct bxxp_request_val),
205 bxxp_packet_init_count * sizeof(struct bxxp_request_val), G_ALLOC_AND_FREE);
206 bxxp_packet_infos = g_mem_chunk_new("bxxp_packet_infos",
207 sizeof(struct bxxp_proto_data),
208 bxxp_packet_init_count * sizeof(struct bxxp_proto_data), G_ALLOC_AND_FREE);
215 int bxxp_get_more(char more)
219 return BXXP_COMPLETE;
220 else if (more == '*')
221 return BXXP_INTERMEDIATE;
226 /* dissect the more flag, and return a value of:
229 * -1 -> Proto violation
233 dissect_bxxp_more(tvbuff_t *tvb, int offset, frame_data *fd,
238 switch (bxxp_get_more(tvb_get_guint8(tvb, offset))) {
243 proto_tree_add_boolean_hidden(tree, hf_bxxp_complete, tvb, offset, 1, TRUE);
244 proto_tree_add_text(tree, tvb, offset, 1, "More: Complete");
251 case BXXP_INTERMEDIATE:
254 proto_tree_add_boolean_hidden(tree, hf_bxxp_intermediate, tvb, offset, 1, TRUE);
255 proto_tree_add_text(tree, tvb, offset, 1, "More: Intermediate");
265 proto_tree_add_boolean_hidden(tree, hf_bxxp_proto_viol, tvb, offset, 1, TRUE);
266 proto_tree_add_text(tree, tvb, offset, 1, "PROTOCOL VIOLATION: Expected More Flag (* or .)");
276 void dissect_bxxp_status(tvbuff_t *tvb, int offset, frame_data *fd,
280 /* FIXME: We should return a value to indicate all OK. */
282 switch(tvb_get_guint8(tvb, offset)) {
287 proto_tree_add_boolean_hidden(tree, hf_bxxp_positive, tvb, offset, 1, TRUE);
288 proto_tree_add_text(tree, tvb, offset, 1, "Status: Positive");
296 proto_tree_add_boolean_hidden(tree, hf_bxxp_negative, tvb, offset, 1, TRUE);
297 proto_tree_add_text(tree, tvb, offset, 1, "Status: Negative");
302 default: /* Proto violation: FIXME */
310 int num_len(tvbuff_t *tvb, int offset)
314 while (isdigit(tvb_get_guint8(tvb, offset + i))) i++;
321 * We check for a terminator. This can be CRLF, which will be recorded
322 * as a terminator, or CR or LF by itself, which will be redorded as
323 * an incorrect terminator ... We build the tree at this point
324 * However, we depend on the variable bxxp_strict_term
328 check_term(tvbuff_t *tvb, int offset, proto_tree *tree)
331 /* First, check for CRLF, or, if global_bxxp_strict_term is false,
332 * one of CR or LF ... If neither of these hold, we add an element
333 * that complains of a protocol violation, and return -1, else
334 * we add a terminator to the tree (possibly non-standard) and return
335 * the count of characters we saw ... This may throw off the rest of the
336 * dissection ... so-be-it!
339 if ((tvb_get_guint8(tvb, offset) == 0x0d &&
340 tvb_get_guint8(tvb, offset + 1) == 0x0a)){ /* Correct terminator */
343 proto_tree_add_text(tree, tvb, offset, 2, "Terminator: CRLF");
348 else if ((tvb_get_guint8(tvb, offset) == 0x0d) && !global_bxxp_strict_term) {
351 proto_tree_add_text(tree, tvb, offset, 1, "Nonstandard Terminator: CR");
352 proto_tree_add_boolean_hidden(tree, hf_bxxp_proto_viol, tvb, offset, 1, TRUE);
357 else if ((tvb_get_guint8(tvb, offset) == 0x0a) && !global_bxxp_strict_term) {
360 proto_tree_add_text(tree, tvb, offset, 1, "Nonstandard Terminator: LF");
361 proto_tree_add_boolean_hidden(tree, hf_bxxp_proto_viol, tvb, offset, 1, TRUE);
369 proto_tree_add_text(tree, tvb, offset, 2, "PROTOCOL VIOLATION, Invalid Terminator: %s", tvb_format_text(tvb, offset, 2));
370 proto_tree_add_boolean_hidden(tree, hf_bxxp_proto_viol, tvb, offset, 2, TRUE);
378 /* Get the header length, up to CRLF or CR or LF */
379 int header_len(tvbuff_t *tvb, int offset)
384 /* FIXME: Have to make sure we stop looking at the end of the tvb ... */
386 /* We look for CRLF, or CR or LF if global_bxxp_strict_term is
392 if (tvb_length_remaining(tvb, offset + i) < 1)
393 return i; /* Not enough characters left ... */
395 if ((sc = tvb_get_guint8(tvb, offset + i)) == 0x0d
396 && tvb_get_guint8(tvb, offset + i + 1) == 0x0a)
397 return i; /* Done here ... */
399 if (!global_bxxp_strict_term && (sc == 0x0d || sc == 0x0a))
400 return i; /* Done here also ... */
408 dissect_bxxp_mime_header(tvbuff_t *tvb, int offset,
409 struct bxxp_proto_data *frame_data,
412 proto_tree *ti = NULL, *mime_tree = NULL;
413 int mime_length = header_len(tvb, offset), cc = 0;
415 if (frame_data && !frame_data->mime_hdr) return 0;
419 /* FIXME: Should calculate the whole length of the mime headers */
421 ti = proto_tree_add_text(tree, tvb, offset, mime_length, "Mime header: %s", tvb_format_text(tvb, offset, mime_length));
422 mime_tree = proto_item_add_subtree(ti, ett_mime_header);
425 if (mime_length == 0) { /* Default header */
428 proto_tree_add_text(mime_tree, tvb, offset, 0, "Default values");
431 if ((cc = check_term(tvb, offset, mime_tree)) <= 0) {
433 /* Ignore it, it will cause funnies in the rest of the dissect */
438 else { /* FIXME: Process the headers */
441 proto_tree_add_text(mime_tree, tvb, offset, mime_length, "Header: %s",
442 tvb_format_text(tvb, offset, mime_length));
445 if ((cc = check_term(tvb, offset + mime_length, mime_tree)) <= 0) {
447 /* Ignore it, it will cause funnies in the rest of the dissect */
453 return mime_length + cc; /* FIXME: Check that the CRLF is there */
458 dissect_bxxp_int(tvbuff_t *tvb, int offset, frame_data *fd,
459 proto_tree *tree, int hf, int *val, int *hfa[])
461 int ival, ind = 0, i = num_len(tvb, offset);
462 guint8 int_buff[100];
464 memset(int_buff, '\0', sizeof(int_buff));
466 tvb_memcpy(tvb, int_buff, offset, MIN(sizeof(int_buff), i));
468 sscanf(int_buff, "%d", &ival); /* FIXME: Dangerous */
471 proto_tree_add_uint(tree, hf, tvb, offset, i, ival);
476 proto_tree_add_uint_hidden(tree, *hfa[ind], tvb, offset, i, ival);
481 *val = ival; /* Return the value */
488 set_mime_hdr_flags(int more, struct bxxp_request_val *request_val,
489 struct bxxp_proto_data *frame_data)
492 if (!request_val) return; /* Nothing to do ??? */
494 if (pi.destport == tcp_port) { /* Going to the server ... client */
496 if (request_val->c_mime_hdr) {
498 frame_data->mime_hdr = 0;
500 if (!more) request_val->c_mime_hdr = 0;
505 frame_data->mime_hdr = 1;
507 if (more) request_val->c_mime_hdr = 1;
514 if (request_val->s_mime_hdr) {
516 frame_data->mime_hdr = 0;
518 if (!more) request_val->s_mime_hdr = 0;
523 frame_data->mime_hdr = 1;
525 if (more) request_val->s_mime_hdr = 1;
535 * A return value of <= 0 says we bailed out, skip the rest of this message,
538 * A return value > 0 is the count of bytes we consumed ...
542 dissect_bxxp_tree(tvbuff_t *tvb, int offset, packet_info *pinfo,
543 proto_tree *tree, struct bxxp_request_val *request_val,
544 struct bxxp_proto_data *frame_data)
546 proto_tree *ti = NULL, *hdr = NULL;
547 int st_offset, serial, seqno, size, channel, ackno, window, cc,
552 if (tvb_strneql(tvb, offset, "REQ ", 4) == 0) {
555 ti = proto_tree_add_text(tree, tvb, offset, header_len(tvb, offset) + 2, "Header");
557 hdr = proto_item_add_subtree(ti, ett_header);
559 proto_tree_add_boolean_hidden(hdr, hf_bxxp_req, tvb, offset, 3, TRUE);
560 proto_tree_add_text(hdr, NullTVB, offset, 3, "Command: REQ");
566 if (tvb_get_guint8(tvb, offset) != ' ') { /* Protocol violation */
568 /* Hmm, FIXME ... Add some code here ... */
573 offset += 1; /* Skip the space */
575 /* Insert the more elements ... */
577 if ((more = dissect_bxxp_more(tvb, offset, pinfo->fd, hdr)) >= 0) {
579 /* Figure out which direction this is in and what mime_hdr flag to
580 * add to the frame_data. If there are missing segments, this code
584 set_mime_hdr_flags(more, request_val, frame_data);
587 else { /* Protocol violation, so dissect rest as undisectable */
591 proto_tree_add_text(hdr, tvb, offset,
592 tvb_length_remaining(tvb, offset),
593 "Undissected Payload: %s",
594 tvb_format_text(tvb, offset,
595 tvb_length_remaining(tvb, offset)
607 /* Check the space ... */
611 /* Dissect the serial */
613 offset += dissect_bxxp_int(tvb, offset, pinfo->fd, hdr, hf_bxxp_serial, &serial, req_serial_hfa);
618 /* now for the seqno */
620 offset += dissect_bxxp_int(tvb, offset, pinfo->fd, hdr, hf_bxxp_seqno, &seqno, req_seqno_hfa);
626 offset += dissect_bxxp_int(tvb, offset, pinfo->fd, hdr, hf_bxxp_size, &size, req_size_hfa);
627 if (request_val) /* FIXME, is this the right order ... */
628 request_val -> size = size; /* Stash this away */
630 frame_data->pl_size = size;
631 if (frame_data->pl_size < 0) frame_data->pl_size = 0; /* FIXME: OK? */
634 /* Check the space */
638 /* Get the channel */
640 offset += dissect_bxxp_int(tvb, offset, pinfo->fd, hdr, hf_bxxp_channel, &channel, req_chan_hfa);
642 if ((cc = check_term(tvb, offset, hdr)) <= 0) {
644 /* We dissect the rest as data and bail ... */
647 proto_tree_add_text(hdr, tvb, offset,
648 tvb_length_remaining(tvb, offset),
649 "Undissected Payload: %s",
650 tvb_format_text(tvb, offset,
651 tvb_length_remaining(tvb, offset)
662 /* Insert MIME header ... */
664 if (frame_data && frame_data->mime_hdr)
665 offset += dissect_bxxp_mime_header(tvb, offset, frame_data, hdr);
667 /* Now for the payload, if any */
669 if (tvb_length_remaining(tvb, offset) > 0) { /* Dissect what is left as payload */
671 int pl_size = MIN(size, tvb_length_remaining(tvb, offset));
673 /* Except, check the payload length, and only dissect that much */
675 /* We need to keep track, in the conversation, of how much is left
676 * so in the next packet, we can figure out what is part of the payload
677 * and what is the next message
681 proto_tree_add_text(tree, tvb, offset, pl_size, "Payload: %s", tvb_format_text(tvb, offset, pl_size));
688 request_val->size -= pl_size;
689 if (request_val->size < 0) request_val->size = 0;
692 frame_data->pl_size -= pl_size;
693 if (frame_data->pl_size < 0) frame_data->pl_size = 0;
697 /* If anything else left, dissect it ... */
699 if (tvb_length_remaining(tvb, offset) > 0)
700 offset += dissect_bxxp_tree(tvb, offset, pinfo, tree, request_val, frame_data);
702 } else if (tvb_strneql(tvb, offset, "RSP ", 4) == 0) {
706 ti = proto_tree_add_text(tree, tvb, offset, header_len(tvb, offset) + 2, "Header");
708 hdr = proto_item_add_subtree(ti, ett_header);
710 proto_tree_add_boolean_hidden(hdr, hf_bxxp_rsp, NullTVB, offset, 3, TRUE);
711 proto_tree_add_text(hdr, tvb, offset, 3, "Command: RSP");
717 /* Now check the space: FIXME */
721 /* Next, the 'more' flag ... */
723 if ((more = dissect_bxxp_more(tvb, offset, pinfo->fd, hdr)) >= 0) {
725 set_mime_hdr_flags(more, request_val, frame_data);
732 proto_tree_add_text(hdr, tvb, offset,
733 tvb_length_remaining(tvb, offset),
734 "Undissected Payload: %s",
735 tvb_format_text(tvb, offset,
736 tvb_length_remaining(tvb, offset)
748 /* Check the space */
752 offset += dissect_bxxp_int(tvb, offset, pinfo->fd, hdr, hf_bxxp_serial, &serial, rsp_serial_hfa);
757 /* now for the seqno */
759 offset += dissect_bxxp_int(tvb, offset, pinfo->fd, hdr, hf_bxxp_seqno, &seqno, rsp_seqno_hfa);
765 offset += dissect_bxxp_int(tvb, offset, pinfo->fd, hdr, hf_bxxp_size, &size, rsp_size_hfa);
767 request_val->size = size;
769 frame_data->pl_size = size;
771 /* Check the space ... */
775 dissect_bxxp_status(tvb, offset, pinfo->fd, hdr);
779 if ((cc = check_term(tvb, offset, hdr)) <= 0) {
781 /* We dissect the rest as data and bail ... */
784 proto_tree_add_text(hdr, tvb, offset,
785 tvb_length_remaining(tvb, offset),
786 "Undissected Payload: %s",
787 tvb_format_text(tvb, offset,
788 tvb_length_remaining(tvb, offset)
799 /* Insert MIME header ... */
801 if (frame_data && frame_data->mime_hdr)
802 offset += dissect_bxxp_mime_header(tvb, offset, frame_data, hdr);
804 /* Now for the payload, if any */
806 if (tvb_length_remaining(tvb, offset) > 0) { /* Dissect what is left as payload */
808 int pl_size = MIN(size, tvb_length_remaining(tvb, offset));
810 /* Except, check the payload length, and only dissect that much */
813 proto_tree_add_text(tree, tvb, offset, pl_size, "Payload: %s", tvb_format_text(tvb, offset, pl_size));
819 request_val->size -= pl_size;
820 if (request_val->size < 0) request_val->size = 0;
823 frame_data->pl_size -= pl_size;
824 if (frame_data->pl_size < 0) frame_data->pl_size = 0;
828 /* If anything else left, dissect it ... As what? */
830 if (tvb_length_remaining(tvb, offset) > 0)
831 offset += dissect_bxxp_tree(tvb, offset, pinfo, tree, request_val, frame_data);
833 } else if (tvb_strneql(tvb, offset, "SEQ ", 4) == 0) {
836 proto_tree_add_boolean_hidden(tree, hf_bxxp_seq, NullTVB, offset, 3, TRUE);
837 proto_tree_add_text(tree, tvb, offset, 3, "Command: SEQ");
842 /* Now check the space: FIXME */
846 offset += dissect_bxxp_int(tvb, offset, pinfo->fd, tree, hf_bxxp_channel, &channel, seq_chan_hfa);
848 /* Check the space: FIXME */
852 offset += dissect_bxxp_int(tvb, offset, pinfo->fd, tree, hf_bxxp_ackno, &ackno, seq_ackno_hfa);
854 /* Check the space: FIXME */
858 offset += dissect_bxxp_int(tvb, offset, pinfo->fd, tree, hf_bxxp_window, &window, seq_window_hfa);
860 if ((cc = check_term(tvb, offset, tree)) <= 0) {
862 /* We dissect the rest as data and bail ... */
865 proto_tree_add_text(tree, tvb, offset,
866 tvb_length_remaining(tvb, offset),
867 "Undissected Payload: %s",
868 tvb_format_text(tvb, offset,
869 tvb_length_remaining(tvb, offset)
880 } else if (tvb_strneql(tvb, offset, "END", 3) == 0) {
882 proto_tree *tr = NULL;
885 ti = proto_tree_add_text(tree, tvb, offset, MIN(5, tvb_length_remaining(tvb, offset)), "Trailer");
887 tr = proto_item_add_subtree(ti, ett_trailer);
889 proto_tree_add_boolean_hidden(tr, hf_bxxp_end, NullTVB, offset, 3, TRUE);
890 proto_tree_add_text(tr, tvb, offset, 3, "Command: END");
896 if ((cc = check_term(tvb, offset, tr)) <= 0) {
898 /* We dissect the rest as data and bail ... */
901 proto_tree_add_text(tr, tvb, offset, tvb_length_remaining(tvb, offset),
902 "Undissected Payload: %s",
903 tvb_format_text(tvb, offset,
904 tvb_length_remaining(tvb, offset)
917 if (tvb_length_remaining(tvb, offset) > 0) { /* Dissect anything left over */
923 pl_size = MIN(request_val->size, tvb_length_remaining(tvb, offset));
925 /* FIXME: May be redundent ... */
927 if (pl_size == 0 && offset == st_offset) { /* The whole of the rest must be payload */
929 pl_size = tvb_length_remaining(tvb, offset); /* Right place ? */
933 } else if (frame_data) {
934 pl_size = MIN(frame_data->pl_size, tvb_length_remaining(tvb, offset));
935 } else { /* Just in case */
936 pl_size = tvb_length_remaining(tvb, offset);
939 /* Take care here to handle the payload correctly, and if there is
940 * another message here, then handle it correctly as well.
943 /* If the pl_size == 0 and the offset == st_offset, then we have not
944 * processed anything in this frame above, so we better treat all this
945 * data as payload to avoid recursion loops
948 if (pl_size == 0 && offset == st_offset)
949 pl_size = tvb_length_remaining(tvb, offset);
954 proto_tree_add_text(tree, tvb, offset, pl_size, "Payload: %s",
955 tvb_format_text(tvb, offset, pl_size));
958 offset += pl_size; /* Advance past the payload */
961 request_val->size -= pl_size; /* Reduce payload by what we added */
962 if (request_val->size < 0) request_val->size = 0;
965 frame_data->pl_size -= pl_size;
966 if (frame_data->pl_size < 0) frame_data->pl_size = 0;
970 if (tvb_length_remaining(tvb, offset) > 0) {
971 offset += dissect_bxxp_tree(tvb, offset, pinfo, tree, request_val, frame_data);
975 return offset - st_offset;
980 dissect_bxxp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
983 struct bxxp_proto_data *frame_data = NULL;
984 proto_tree *bxxp_tree = NULL, *ti = NULL;
985 conversation_t *conversation = NULL;
986 struct bxxp_request_key request_key, *new_request_key;
987 struct bxxp_request_val *request_val = NULL;
989 CHECK_DISPLAY_AS_DATA(proto_bxxp, tvb, pinfo, tree);
991 pinfo->current_proto = "BXXP";
995 /* If we have per frame data, use that, else, we must have lost the per-
996 * frame data, and we have to do a full dissect pass again.
998 * The per-frame data tells us how much of this frame is left over from a
999 * previous frame, so we dissect it as payload and then try to dissect the
1002 * We use the conversation to build up info on the first pass over the
1003 * packets of type BXXP, and record anything that is needed if the user
1004 * does random dissects of packets in per packet data.
1006 * Once we have per-packet data, we don't need the conversation stuff
1007 * anymore, but if per-packet data and conversation stuff gets deleted, as
1008 * it does under some circumstances when a rescan is done, it all gets
1012 /* Find out what conversation this packet is part of ... but only
1013 * if we have no information on this packet, so find the per-frame
1017 frame_data = p_get_proto_data(pinfo->fd, proto_bxxp);
1021 conversation = find_conversation(&pinfo->src, &pinfo->dst, pi.ptype,
1022 pinfo->srcport, pinfo->destport, 0);
1023 if (conversation == NULL) { /* No conversation, create one */
1024 conversation = conversation_new(&pinfo->src, &pinfo->dst, pinfo->ptype,
1025 pinfo->srcport, pinfo->destport, NULL,
1031 * Check for and insert an entry in the request table if does not exist
1033 request_key.conversation = conversation->index;
1035 request_val = (struct bxxp_request_val *)g_hash_table_lookup(bxxp_request_hash, &request_key);
1037 if (!request_val) { /* Create one */
1039 new_request_key = g_mem_chunk_alloc(bxxp_request_keys);
1040 new_request_key->conversation = conversation->index;
1042 request_val = g_mem_chunk_alloc(bxxp_request_vals);
1043 request_val->processed = 0;
1044 request_val->size = 0;
1046 g_hash_table_insert(bxxp_request_hash, new_request_key, request_val);
1051 if (check_col(pinfo->fd, COL_PROTOCOL))
1052 col_set_str(pinfo->fd, COL_PROTOCOL, "BXXP");
1054 if (check_col(pinfo->fd, COL_INFO)) { /* Check the type ... */
1056 col_add_fstr(pinfo->fd, COL_INFO, "%s", tvb_format_text(tvb, offset, tvb_length_remaining(tvb, offset)));
1060 /* Here, we parse the message so we can retrieve the info we need, which
1061 * is that there is some payload left from a previous segment on the
1062 * front of this segment ... This all depends on TCP segments not getting
1065 * As a huge kludge, we push the checking for the tree down into the code
1066 * and process as if we were given a tree but not call the routines that
1067 * adorn the protocol tree if they were NULL.
1070 if (tree) { /* Build the tree info ... */
1072 ti = proto_tree_add_item(tree, proto_bxxp, tvb, offset, tvb_length(tvb), FALSE);
1074 bxxp_tree = proto_item_add_subtree(ti, ett_bxxp);
1078 /* Check the per-frame data and the conversation for any left-over
1079 * payload from the previous frame
1081 * We check that per-frame data exists first, and if so, use it,
1082 * else we use the conversation data.
1084 * We create per-frame data here as well, but we must ensure we create it
1085 * after we have done the check for per-frame or conversation data.
1087 * We also depend on the first frame in a group having a pl_size of 0.
1090 if (frame_data && frame_data->pl_left > 0) {
1092 int pl_left = frame_data->pl_left;
1094 pl_left = MIN(pl_left, tvb_length_remaining(tvb, offset));
1096 /* Add the payload bit, only if we have a tree */
1098 proto_tree_add_text(bxxp_tree, tvb, offset, pl_left, "Payload: %s",
1099 tvb_format_text(tvb, offset, pl_left));
1103 else if (request_val && request_val->size > 0) {
1105 int pl_left = request_val->size;
1107 request_val->size = 0;
1109 /* We create the frame data here for this case, and
1110 * elsewhere for other frames
1113 frame_data = g_mem_chunk_alloc(bxxp_packet_infos);
1115 frame_data->pl_left = pl_left;
1116 frame_data->pl_size = 0;
1117 frame_data->mime_hdr = 0;
1119 p_add_proto_data(pinfo->fd, proto_bxxp, frame_data);
1123 /* Set up the per-frame data here if not already done so
1124 * This _must_ come after the checks above ...
1127 if (frame_data == NULL) {
1129 frame_data = g_mem_chunk_alloc(bxxp_packet_infos);
1131 frame_data->pl_left = 0;
1132 frame_data->pl_size = 0;
1133 frame_data->mime_hdr = 0;
1135 p_add_proto_data(pinfo->fd, proto_bxxp, frame_data);
1139 if (tvb_length_remaining(tvb, offset) > 0) {
1141 offset += dissect_bxxp_tree(tvb, offset, pinfo, bxxp_tree, request_val, frame_data);
1147 /* Register all the bits needed with the filtering engine */
1150 proto_register_bxxp(void)
1152 static hf_register_info hf[] = {
1153 { &hf_bxxp_proto_viol,
1154 { "Protocol Violation", "bxxp.violation", FT_BOOLEAN, BASE_NONE, NULL, 0x0, "" }},
1157 { "Request", "bxxp.req", FT_BOOLEAN, BASE_NONE, NULL, 0x0, "" }},
1159 { &hf_bxxp_req_chan,
1160 { "Request Channel Number", "bxxp.req.channel", FT_UINT32, BASE_DEC, NULL, 0x0, ""}},
1163 { "Response", "bxxp.rsp", FT_BOOLEAN, BASE_NONE, NULL, 0x0, "" }},
1165 { &hf_bxxp_rsp_chan,
1166 { "Response Channel Number", "bxxp.rsp.channel", FT_UINT32, BASE_DEC, NULL, 0x0, ""}},
1169 { "Sequence", "bxxp.seq", FT_BOOLEAN, BASE_NONE, NULL, 0x0, "" }},
1171 { &hf_bxxp_seq_chan,
1172 { "Sequence Channel Number", "bxxp.seq.channel", FT_UINT32, BASE_DEC, NULL, 0x0, ""}},
1175 { "End", "bxxp.end", FT_BOOLEAN, BASE_NONE, NULL, 0x0, "" }},
1177 { &hf_bxxp_complete,
1178 { "Complete", "bxxp.more.complete", FT_BOOLEAN, BASE_NONE, NULL, 0x0, "" }},
1180 { &hf_bxxp_intermediate,
1181 { "Intermediate", "bxxp.more.intermediate", FT_BOOLEAN, BASE_NONE, NULL, 0x0, "" }},
1184 { "Serial", "bxxp.serial", FT_UINT32, BASE_DEC, NULL, 0x0, "" }},
1187 { "Seqno", "bxxp.seqno", FT_UINT32, BASE_DEC, NULL, 0x0, "" }},
1190 { "Size", "bxxp.size", FT_UINT32, BASE_DEC, NULL, 0x0, "" }},
1193 { "Channel", "bxxp.channel", FT_UINT32, BASE_DEC, NULL, 0x0, "" }},
1195 { &hf_bxxp_negative,
1196 { "Negative", "bxxp.status.negative", FT_BOOLEAN, BASE_NONE, NULL, 0x0, ""}},
1198 { &hf_bxxp_positive,
1199 { "Positive", "bxxp.status.positive", FT_BOOLEAN, BASE_NONE, NULL, 0x0, ""}},
1202 { "Ackno", "bxxp.seq.ackno", FT_UINT32, BASE_DEC, NULL, 0x0, ""}},
1205 { "Window", "bxxp.seq.window", FT_UINT32, BASE_DEC, NULL, 0x0, ""}},
1208 static gint *ett[] = {
1214 module_t *bxxp_module;
1216 proto_bxxp = proto_register_protocol("Blocks eXtensible eXchange Protocol",
1219 proto_register_field_array(proto_bxxp, hf, array_length(hf));
1220 proto_register_subtree_array(ett, array_length(ett));
1221 register_init_routine(&bxxp_init_protocol);
1223 /* Register our configuration options for BXXP, particularly our port */
1225 bxxp_module = prefs_register_protocol(proto_bxxp, proto_reg_handoff_bxxp);
1227 prefs_register_uint_preference(bxxp_module, "tcp.port", "BXXP TCP Port",
1228 "Set the port for BXXP messages (if other"
1229 " than the default of 10288)",
1230 10, &global_bxxp_tcp_port);
1232 prefs_register_bool_preference(bxxp_module, "strict_header_terminator",
1233 "BXXP Header Requires CRLF",
1234 "Specifies that BXXP requires CRLF as a "
1235 "terminator, and not just CR or LF",
1236 &global_bxxp_strict_term);
1239 /* The registration hand-off routine */
1241 proto_reg_handoff_bxxp(void)
1243 static int bxxp_prefs_initialized = FALSE;
1245 if (bxxp_prefs_initialized) {
1247 dissector_delete("tcp.port", tcp_port, dissect_bxxp);
1252 bxxp_prefs_initialized = TRUE;
1256 /* Set our port number for future use */
1258 tcp_port = global_bxxp_tcp_port;
1260 dissector_add("tcp.port", global_bxxp_tcp_port, dissect_bxxp, proto_bxxp);