2 * Routines for BXXP packet disassembly
4 * $Id: packet-bxxp.c,v 1.5 2000/10/03 10:59:10 sharpe Exp $
6 * Copyright (c) 2000 by Richard Sharpe <rsharpe@ns.aus.com>
8 * Ethereal - Network traffic analyzer
10 * Copyright 1999 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30 #ifdef HAVE_SYS_TYPES_H
31 # include <sys/types.h>
34 #ifdef HAVE_NETINET_IN_H
35 #include <netinet/in.h>
47 #include "conversation.h"
49 #define TCP_PORT_BXXP 10288
50 void proto_reg_handoff_bxxp(void);
53 static int global_bxxp_tcp_port = TCP_PORT_BXXP;
54 static int global_bxxp_strict_term = TRUE;
56 static int proto_bxxp = -1;
58 static int hf_bxxp_req = -1;
59 static int hf_bxxp_req_chan = -1;
60 static int hf_bxxp_rsp_chan = -1;
61 static int hf_bxxp_seq_chan = -1;
62 static int hf_bxxp_rsp = -1;
63 static int hf_bxxp_seq = -1;
64 static int hf_bxxp_end = -1;
65 static int hf_bxxp_proto_viol = -1;
66 static int hf_bxxp_complete = -1; /* No More data follows */
67 static int hf_bxxp_intermediate = -1; /* More data follows */
68 static int hf_bxxp_serial = -1;
69 static int hf_bxxp_seqno = -1;
70 static int hf_bxxp_size = -1;
71 static int hf_bxxp_channel = -1;
72 static int hf_bxxp_positive = -1;
73 static int hf_bxxp_negative = -1;
74 static int hf_bxxp_ackno = -1;
75 static int hf_bxxp_window = -1;
77 /* Arrays of hf entry pointers for some routines to use. If you want more
78 * hidden items added for a field, add them to the list before the NULL,
79 * and the various routines that these are passed to will add them.
82 static int *req_serial_hfa[] = { &hf_bxxp_serial, NULL };
83 static int *req_seqno_hfa[] = { &hf_bxxp_seqno, NULL };
84 static int *req_size_hfa[] = { &hf_bxxp_size, NULL };
85 static int *req_chan_hfa[] = { &hf_bxxp_channel, &hf_bxxp_req_chan, NULL };
86 static int *rsp_serial_hfa[] = { &hf_bxxp_serial, NULL };
87 static int *rsp_seqno_hfa[] = { &hf_bxxp_seqno, NULL };
88 static int *rsp_size_hfa[] = { &hf_bxxp_size, NULL };
89 static int *seq_chan_hfa[] = { &hf_bxxp_channel, &hf_bxxp_seq_chan, NULL };
90 static int *seq_ackno_hfa[] = { &hf_bxxp_ackno, NULL };
91 static int *seq_window_hfa[] = { &hf_bxxp_window, NULL };
93 static int ett_bxxp = -1;
94 static int ett_mime_header = -1;
95 static int ett_header = -1;
96 static int ett_trailer = -1;
98 static int tcp_port = 0;
100 /* Get the state of the more flag ... */
103 #define BXXP_INTERMEDIATE 1
104 #define BXXP_COMPLETE 2
109 * pl_left is the amount of data in this packet that belongs to another
112 * It relies on TCP segments not being re-ordered too much ...
114 struct bxxp_proto_data {
115 int pl_left; /* Payload at beginning of frame */
116 int pl_size; /* Payload in current message ...*/
122 static int bxxp_packet_init_count = 100;
124 struct bxxp_request_key {
125 guint32 conversation;
128 struct bxxp_request_val {
129 guint16 processed; /* Have we processed this conversation? */
130 int size; /* Size of the message */
133 GHashTable *bxxp_request_hash = NULL;
134 GMemChunk *bxxp_request_keys = NULL;
135 GMemChunk *bxxp_request_vals = NULL;
136 GMemChunk *bxxp_packet_infos = NULL;
140 bxxp_equal(gconstpointer v, gconstpointer w)
142 struct bxxp_request_key *v1 = (struct bxxp_request_key *)v;
143 struct bxxp_request_key *v2 = (struct bxxp_request_key *)w;
145 #if defined(DEBUG_BXXP_HASH)
146 printf("Comparing %08X\n and %08X\n",
147 v1->conversation, v2->conversation);
150 if (v1->conversation == v2->conversation)
158 bxxp_hash(gconstpointer v)
160 struct bxxp_request_key *key = (struct bxxp_request_key *)v;
163 val = key->conversation;
165 #if defined(DEBUG_BXXP_HASH)
166 printf("BXXP Hash calculated as %u\n", val);
174 bxxp_init_protocol(void)
176 #if defined(DEBUG_BXXP_HASH)
177 fprintf(stderr, "Initializing BXXP hashtable area\n");
180 if (bxxp_request_hash)
181 g_hash_table_destroy(bxxp_request_hash);
182 if (bxxp_request_keys)
183 g_mem_chunk_destroy(bxxp_request_keys);
184 if (bxxp_request_vals)
185 g_mem_chunk_destroy(bxxp_request_vals);
186 if (bxxp_packet_infos)
187 g_mem_chunk_destroy(bxxp_packet_infos);
189 bxxp_request_hash = g_hash_table_new(bxxp_hash, bxxp_equal);
190 bxxp_request_keys = g_mem_chunk_new("bxxp_request_keys",
191 sizeof(struct bxxp_request_key),
192 bxxp_packet_init_count * sizeof(struct bxxp_request_key), G_ALLOC_AND_FREE);
193 bxxp_request_vals = g_mem_chunk_new("bxxp_request_vals",
194 sizeof(struct bxxp_request_val),
195 bxxp_packet_init_count * sizeof(struct bxxp_request_val), G_ALLOC_AND_FREE);
196 bxxp_packet_infos = g_mem_chunk_new("bxxp_packet_infos",
197 sizeof(struct bxxp_proto_data),
198 bxxp_packet_init_count * sizeof(struct bxxp_proto_data), G_ALLOC_AND_FREE);
205 int bxxp_get_more(char more)
209 return BXXP_COMPLETE;
210 else if (more == '*')
211 return BXXP_INTERMEDIATE;
217 dissect_bxxp_more(tvbuff_t *tvb, int offset, frame_data *fd,
221 /* FIXME: We should return a value to indicate all OK */
222 switch (bxxp_get_more(tvb_get_guint8(tvb, offset))) {
227 proto_tree_add_boolean_hidden(tree, hf_bxxp_complete, tvb, offset, 1, TRUE);
228 proto_tree_add_text(tree, tvb, offset, 1, "More: Complete");
233 case BXXP_INTERMEDIATE:
236 proto_tree_add_boolean_hidden(tree, hf_bxxp_intermediate, tvb, offset, 1, TRUE);
237 proto_tree_add_text(tree, tvb, offset, 1, "More: Intermediate");
242 default: /* FIXME: Add code for this case ... */
244 fprintf(stderr, "Error from bxxp_get_more ...\n");
250 void dissect_bxxp_status(tvbuff_t *tvb, int offset, frame_data *fd,
254 /* FIXME: We should return a value to indicate all OK. */
256 switch(tvb_get_guint8(tvb, offset)) {
261 proto_tree_add_boolean_hidden(tree, hf_bxxp_positive, tvb, offset, 1, TRUE);
262 proto_tree_add_text(tree, tvb, offset, 1, "Status: Positive");
270 proto_tree_add_boolean_hidden(tree, hf_bxxp_negative, tvb, offset, 1, TRUE);
271 proto_tree_add_text(tree, tvb, offset, 1, "Status: Negative");
276 default: /* Proto violation: FIXME */
284 int num_len(tvbuff_t *tvb, int offset)
288 while (isdigit(tvb_get_guint8(tvb, offset + i))) i++;
295 * We check for a terminator. This can be CRLF, which will be recorded
296 * as a terminator, or CR or LF by itself, which will be redorded as
297 * an incorrect terminator ... We build the tree at this point
298 * However, we depend on the variable bxxp_strict_term
302 check_term(tvbuff_t *tvb, int offset, proto_tree *tree)
305 /* First, check for CRLF, or, if global_bxxp_strict_term is false,
306 * one of CR or LF ... If neither of these hold, we add an element
307 * that complains of a protocol violation, and return -1, else
308 * we add a terminator to the tree (possibly non-standard) and return
309 * the count of characters we saw ... This may throw off the rest of the
310 * dissection ... so-be-it!
313 if ((tvb_get_guint8(tvb, offset) == 0x0d &&
314 tvb_get_guint8(tvb, offset + 1) == 0x0a)){ /* Correct terminator */
317 proto_tree_add_text(tree, tvb, offset, 2, "Terminator: CRLF");
322 else if ((tvb_get_guint8(tvb, offset) == 0x0d) && !global_bxxp_strict_term) {
325 proto_tree_add_text(tree, tvb, offset, 1, "Nonstandard Terminator: CR");
330 else if ((tvb_get_guint8(tvb, offset) == 0x0a) && !global_bxxp_strict_term) {
333 proto_tree_add_text(tree, tvb, offset, 1, "Nonstandard Terminator: LF");
341 proto_tree_add_text(tree, tvb, offset, 2, "PROTOCOL VIOLATION, Invalid Terminator: %s", tvb_format_text(tvb, offset, 2));
349 /* Get the MIME header length */
350 int header_len(tvbuff_t *tvb, int offset)
355 /* FIXME: Have to make sure we stop looking at the end of the tvb ... */
357 /* We look for CRLF, or CR or LF if global_bxxp_strict_term is
363 if (tvb_length_remaining(tvb, offset + i) < 1)
364 return i; /* Not enough characters left ... */
366 if ((sc = tvb_get_guint8(tvb, offset + i)) == 0x0d
367 && tvb_get_guint8(tvb, offset + i + 1) == 0x0a)
368 return i; /* Done here ... */
370 if (!global_bxxp_strict_term && (sc == 0x0d || sc == 0x0a))
371 return i; /* Done here also ... */
379 dissect_bxxp_mime_header(tvbuff_t *tvb, int offset, frame_data *fd,
382 proto_tree *ti = NULL, *mime_tree = NULL;
383 int mime_length = header_len(tvb, offset), cc = 0;
387 /* FIXME: Should calculate the whole length of the mime headers */
389 ti = proto_tree_add_text(tree, tvb, offset, mime_length, "Mime header: %s", tvb_format_text(tvb, offset, mime_length));
390 mime_tree = proto_item_add_subtree(ti, ett_mime_header);
393 if (mime_length == 0) { /* Default header */
396 proto_tree_add_text(mime_tree, tvb, offset, 0, "Default values");
399 if ((cc = check_term(tvb, offset, mime_tree)) <= 0) {
401 /* Ignore it, it will cause funnies in the rest of the dissect */
406 else { /* FIXME: Process the headers */
409 proto_tree_add_text(mime_tree, tvb, offset, mime_length, "Header: %s",
410 tvb_format_text(tvb, offset, mime_length));
413 if ((cc = check_term(tvb, offset + mime_length, mime_tree)) <= 0) {
415 /* Ignore it, it will cause funnies in the rest of the dissect */
421 return mime_length + cc; /* FIXME: Check that the CRLF is there */
426 dissect_bxxp_int(tvbuff_t *tvb, int offset, frame_data *fd,
427 proto_tree *tree, int hf, int *val, int *hfa[])
429 int ival, ind = 0, i = num_len(tvb, offset);
430 guint8 int_buff[100];
432 memset(int_buff, '\0', sizeof(int_buff));
434 tvb_memcpy(tvb, int_buff, offset, MIN(sizeof(int_buff), i));
436 sscanf(int_buff, "%d", &ival); /* FIXME: Dangerous */
439 proto_tree_add_uint(tree, hf, tvb, offset, i, ival);
444 proto_tree_add_uint_hidden(tree, *hfa[ind], tvb, offset, i, ival);
449 *val = ival; /* Return the value */
457 * A return value of <= 0 says we bailed out, skip the rest of this message,
460 * A return value > 0 is the count of bytes we consumed ...
464 dissect_bxxp_tree(tvbuff_t *tvb, int offset, packet_info *pinfo,
465 proto_tree *tree, struct bxxp_request_val *request_val,
466 struct bxxp_proto_data *frame_data)
468 proto_tree *ti = NULL, *hdr = NULL;
469 int st_offset, serial, seqno, size, channel, ackno, window, cc;
473 if (tvb_strneql(tvb, offset, "REQ ", 4) == 0) {
476 ti = proto_tree_add_text(tree, tvb, offset, header_len(tvb, offset) + 2, "Header");
478 hdr = proto_item_add_subtree(ti, ett_header);
480 proto_tree_add_boolean_hidden(hdr, hf_bxxp_req, tvb, offset, 3, TRUE);
481 proto_tree_add_text(hdr, NullTVB, offset, 3, "Command: REQ");
487 if (tvb_get_guint8(tvb, offset) != ' ') { /* Protocol violation */
489 /* Hmm, FIXME ... Add some code here ... */
494 offset += 1; /* Skip the space */
496 /* Insert the more elements ... */
498 dissect_bxxp_more(tvb, offset, pinfo->fd, hdr);
501 /* Check the space ... */
505 /* Dissect the serial */
507 offset += dissect_bxxp_int(tvb, offset, pinfo->fd, hdr, hf_bxxp_serial, &serial, req_serial_hfa);
512 /* now for the seqno */
514 offset += dissect_bxxp_int(tvb, offset, pinfo->fd, hdr, hf_bxxp_seqno, &seqno, req_seqno_hfa);
520 offset += dissect_bxxp_int(tvb, offset, pinfo->fd, hdr, hf_bxxp_size, &size, req_size_hfa);
522 request_val -> size = size; /* Stash this away */
524 frame_data->pl_size = size;
525 if (frame_data->pl_size < 0) frame_data->pl_size = 0;
528 /* Check the space */
532 /* Get the channel */
534 offset += dissect_bxxp_int(tvb, offset, pinfo->fd, hdr, hf_bxxp_channel, &channel, req_chan_hfa);
536 if ((cc = check_term(tvb, offset, hdr)) <= 0) {
538 /* We dissect the rest as data and bail ... */
541 proto_tree_add_text(hdr, tvb, offset,
542 tvb_length_remaining(tvb, offset),
543 "Undissected Payload: %s",
544 tvb_format_text(tvb, offset,
545 tvb_length_remaining(tvb, offset)
556 /* Insert MIME header ... */
558 offset += dissect_bxxp_mime_header(tvb, offset, pinfo->fd, hdr);
560 /* Now for the payload, if any */
562 if (tvb_length_remaining(tvb, offset) > 0) { /* Dissect what is left as payload */
564 int pl_size = MIN(size, tvb_length_remaining(tvb, offset));
566 /* Except, check the payload length, and only dissect that much */
568 /* We need to keep track, in the conversation, of how much is left
569 * so in the next packet, we can figure out what is part of the payload
570 * and what is the next message
574 proto_tree_add_text(tree, tvb, offset, pl_size, "Payload: %s", tvb_format_text(tvb, offset, pl_size));
581 request_val->size -= pl_size;
582 if (request_val->size < 0) request_val->size = 0;
585 frame_data->pl_size -= pl_size;
586 if (frame_data->pl_size < 0) frame_data->pl_size = 0;
590 /* If anything else left, dissect it ... */
592 if (tvb_length_remaining(tvb, offset) > 0)
593 offset += dissect_bxxp_tree(tvb, offset, pinfo, tree, request_val, frame_data);
595 } else if (tvb_strneql(tvb, offset, "RSP ", 4) == 0) {
599 ti = proto_tree_add_text(tree, tvb, offset, header_len(tvb, offset) + 2, "Header");
601 hdr = proto_item_add_subtree(ti, ett_header);
603 proto_tree_add_boolean_hidden(hdr, hf_bxxp_rsp, NullTVB, offset, 3, TRUE);
604 proto_tree_add_text(hdr, tvb, offset, 3, "Command: RSP");
610 /* Now check the space: FIXME */
614 /* Next, the 'more' flag ... */
616 dissect_bxxp_more(tvb, offset, pinfo->fd, hdr);
619 /* Check the space */
623 offset += dissect_bxxp_int(tvb, offset, pinfo->fd, hdr, hf_bxxp_serial, &serial, rsp_serial_hfa);
628 /* now for the seqno */
630 offset += dissect_bxxp_int(tvb, offset, pinfo->fd, hdr, hf_bxxp_seqno, &seqno, rsp_seqno_hfa);
636 offset += dissect_bxxp_int(tvb, offset, pinfo->fd, hdr, hf_bxxp_size, &size, rsp_size_hfa);
638 request_val->size = size;
640 frame_data->pl_size = size;
642 /* Check the space ... */
646 dissect_bxxp_status(tvb, offset, pinfo->fd, hdr);
650 if ((cc = check_term(tvb, offset, hdr)) <= 0) {
652 /* We dissect the rest as data and bail ... */
655 proto_tree_add_text(hdr, tvb, offset,
656 tvb_length_remaining(tvb, offset),
657 "Undissected Payload: %s",
658 tvb_format_text(tvb, offset,
659 tvb_length_remaining(tvb, offset)
670 /* Insert MIME header ... */
672 offset += dissect_bxxp_mime_header(tvb, offset, pinfo->fd, hdr);
674 /* Now for the payload, if any */
676 if (tvb_length_remaining(tvb, offset) > 0) { /* Dissect what is left as payload */
678 int pl_size = MIN(size, tvb_length_remaining(tvb, offset));
680 /* Except, check the payload length, and only dissect that much */
683 proto_tree_add_text(tree, tvb, offset, pl_size, "Payload: %s", tvb_format_text(tvb, offset, pl_size));
689 request_val->size -= pl_size;
690 if (request_val->size < 0) request_val->size = 0;
693 frame_data->pl_size -= pl_size;
694 if (frame_data->pl_size < 0) frame_data->pl_size = 0;
698 /* If anything else left, dissect it ... As what? */
700 if (tvb_length_remaining(tvb, offset) > 0)
701 offset += dissect_bxxp_tree(tvb, offset, pinfo, tree, request_val, frame_data);
703 } else if (tvb_strneql(tvb, offset, "SEQ ", 4) == 0) {
706 proto_tree_add_boolean_hidden(tree, hf_bxxp_seq, NullTVB, offset, 3, TRUE);
707 proto_tree_add_text(tree, tvb, offset, 3, "Command: SEQ");
712 /* Now check the space: FIXME */
716 offset += dissect_bxxp_int(tvb, offset, pinfo->fd, tree, hf_bxxp_channel, &channel, seq_chan_hfa);
718 /* Check the space: FIXME */
722 offset += dissect_bxxp_int(tvb, offset, pinfo->fd, tree, hf_bxxp_ackno, &ackno, seq_ackno_hfa);
724 /* Check the space: FIXME */
728 offset += dissect_bxxp_int(tvb, offset, pinfo->fd, tree, hf_bxxp_window, &window, seq_window_hfa);
730 if ((cc = check_term(tvb, offset, tree)) <= 0) {
732 /* We dissect the rest as data and bail ... */
735 proto_tree_add_text(tree, tvb, offset,
736 tvb_length_remaining(tvb, offset),
737 "Undissected Payload: %s",
738 tvb_format_text(tvb, offset,
739 tvb_length_remaining(tvb, offset)
750 } else if (tvb_strneql(tvb, offset, "END", 3) == 0) {
752 proto_tree *tr = NULL;
755 ti = proto_tree_add_text(tree, tvb, offset, MIN(5, tvb_length_remaining(tvb, offset)), "Trailer");
757 tr = proto_item_add_subtree(ti, ett_trailer);
759 proto_tree_add_boolean_hidden(tr, hf_bxxp_end, NullTVB, offset, 3, TRUE);
760 proto_tree_add_text(tr, tvb, offset, 3, "Command: END");
766 if ((cc = check_term(tvb, offset, tr)) <= 0) {
768 /* We dissect the rest as data and bail ... */
771 proto_tree_add_text(tr, tvb, offset, tvb_length_remaining(tvb, offset),
772 "Undissected Payload: %s",
773 tvb_format_text(tvb, offset,
774 tvb_length_remaining(tvb, offset)
787 if (tvb_length_remaining(tvb, offset) > 0) { /* Dissect anything left over */
793 pl_size = MIN(request_val->size, tvb_length_remaining(tvb, offset));
795 if (pl_size == 0) { /* The whole of the rest must be payload */
797 pl_size = tvb_length_remaining(tvb, offset); /* Right place ? */
801 } else if (frame_data) {
802 pl_size = MIN(frame_data->pl_size, tvb_length_remaining(tvb, offset));
803 } else { /* Just in case */
804 pl_size = tvb_length_remaining(tvb, offset);
807 /* Take care here to handle the payload correctly, and if there is
808 * another message here, then handle it correctly as well.
811 /* If the pl_size == 0 and the offset == 0?, then we have not processed
812 * anything in this frame above, so we better treat all this data as
813 * payload to avoid recursion loops
816 if (pl_size == 0 && offset == st_offset)
817 pl_size = tvb_length_remaining(tvb, offset);
822 proto_tree_add_text(tree, tvb, offset, pl_size, "Payload: %s",
823 tvb_format_text(tvb, offset, pl_size));
826 offset += pl_size; /* Advance past the payload */
829 request_val->size -= pl_size; /* Reduce payload by what we added */
830 if (request_val->size < 0) request_val->size = 0;
833 frame_data->pl_size -= pl_size;
834 if (frame_data->pl_size < 0) frame_data->pl_size = 0;
838 if (tvb_length_remaining(tvb, offset) > 0) {
839 offset += dissect_bxxp_tree(tvb, offset, pinfo, tree, request_val, frame_data);
843 return offset - st_offset;
848 dissect_bxxp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
851 struct bxxp_proto_data *frame_data = NULL;
852 proto_tree *bxxp_tree = NULL, *ti = NULL;
853 conversation_t *conversation = NULL;
854 struct bxxp_request_key request_key, *new_request_key;
855 struct bxxp_request_val *request_val = NULL;
857 CHECK_DISPLAY_AS_DATA(proto_bxxp, tvb, pinfo, tree);
861 /* If we have per frame data, use that, else, we must have lost the per-
862 * frame data, and we have to do a full dissect pass again.
864 * The per-frame data tells us how much of this frame is left over from a
865 * previous frame, so we dissect it as payload and then try to dissect the
868 * We use the conversation to build up info on the first pass over the
869 * packets of type BXXP, and record anything that is needed if the user
870 * does random dissects of packets in per packet data.
872 * Once we have per-packet data, we don't need the conversation stuff
873 * anymore, but if per-packet data and conversation stuff gets deleted, as
874 * it does under some circumstances when a rescan is done, it all gets
878 /* Find out what conversation this packet is part of ... but only
879 * if we have no information on this packet, so find the per-frame
883 frame_data = p_get_proto_data(pinfo->fd, proto_bxxp);
887 conversation = find_conversation(&pinfo->src, &pinfo->dst, pi.ptype,
888 pinfo->srcport, pinfo->destport);
889 if (conversation == NULL) { /* No conversation, create one */
890 conversation = conversation_new(&pinfo->src, &pinfo->dst, pinfo->ptype,
891 pinfo->srcport, pinfo->destport, NULL);
896 * Check for and insert an entry in the request table if does not exist
898 request_key.conversation = conversation->index;
900 request_val = (struct bxxp_request_val *)g_hash_table_lookup(bxxp_request_hash, &request_key);
902 if (!request_val) { /* Create one */
904 new_request_key = g_mem_chunk_alloc(bxxp_request_keys);
905 new_request_key->conversation = conversation->index;
907 request_val = g_mem_chunk_alloc(bxxp_request_vals);
908 request_val->processed = 0;
909 request_val->size = 0;
911 g_hash_table_insert(bxxp_request_hash, new_request_key, request_val);
916 if (check_col(pinfo->fd, COL_PROTOCOL))
917 col_add_str(pinfo->fd, COL_PROTOCOL, "BXXP");
919 if (check_col(pinfo->fd, COL_INFO)) { /* Check the type ... */
921 col_add_fstr(pinfo->fd, COL_INFO, "%s", tvb_format_text(tvb, offset, tvb_length_remaining(tvb, offset)));
925 /* Here, we parse the message so we can retrieve the info we need, which
926 * is that there is some payload left from a previous segment on the
927 * front of this segment ... This all depends on TCP segments not getting
930 * As a huge kludge, we push the checking for the tree down into the code
931 * and process as if we were given a tree but not call the routines that
932 * adorn the protocol tree if they were NULL.
935 if (tree) { /* Build the tree info ... */
937 ti = proto_tree_add_item(tree, proto_bxxp, tvb, offset, tvb_length(tvb), FALSE);
939 bxxp_tree = proto_item_add_subtree(ti, ett_bxxp);
943 /* Check the per-frame data and the conversation for any left-over
944 * payload from the previous frame
947 /* FIXME: This conditional is not quite correct */
948 if ((frame_data && frame_data->pl_left > 0) ||
949 (request_val && request_val->size > 0)) {
953 pl_left = frame_data->pl_left;
956 pl_left = request_val->size;
957 request_val->size = 0;
959 /* We create the frame data here for this case, and
960 * elsewhere for other frames
963 frame_data = g_mem_chunk_alloc(bxxp_packet_infos);
965 frame_data->pl_left = pl_left;
966 frame_data->pl_size = 0;
968 p_add_proto_data(pinfo->fd, proto_bxxp, frame_data);
972 pl_left = MIN(pl_left, tvb_length_remaining(tvb, offset));
974 /* Add the payload bit, only if we have a tree */
976 proto_tree_add_text(bxxp_tree, tvb, offset, pl_left, "Payload: %s",
977 tvb_format_text(tvb, offset, pl_left));
982 if (tvb_length_remaining(tvb, offset) > 0) {
984 offset += dissect_bxxp_tree(tvb, offset, pinfo, bxxp_tree, request_val, frame_data);
988 /* Set up the per-frame data here if not already done so */
990 if (frame_data == NULL) {
992 frame_data = g_mem_chunk_alloc(bxxp_packet_infos);
994 frame_data->pl_left = 0;
995 frame_data->pl_size = 0;
997 p_add_proto_data(pinfo->fd, proto_bxxp, frame_data);
1003 /* Register all the bits needed with the filtering engine */
1006 proto_register_bxxp(void)
1008 static hf_register_info hf[] = {
1009 { &hf_bxxp_proto_viol,
1010 { "Protocol Violation", "bxxp.violation", FT_BOOLEAN, BASE_NONE, NULL, 0x0, "" }},
1013 { "Request", "bxxp.req", FT_BOOLEAN, BASE_NONE, NULL, 0x0, "" }},
1015 { &hf_bxxp_req_chan,
1016 { "Request Channel Number", "bxxp.req.channel", FT_UINT32, BASE_DEC, NULL, 0x0, ""}},
1019 { "Response", "bxxp.rsp", FT_BOOLEAN, BASE_NONE, NULL, 0x0, "" }},
1021 { &hf_bxxp_rsp_chan,
1022 { "Response Channel Number", "bxxp.rsp.channel", FT_UINT32, BASE_DEC, NULL, 0x0, ""}},
1025 { "Sequence", "bxxp.seq", FT_BOOLEAN, BASE_NONE, NULL, 0x0, "" }},
1027 { &hf_bxxp_seq_chan,
1028 { "Sequence Channel Number", "bxxp.seq.channel", FT_UINT32, BASE_DEC, NULL, 0x0, ""}},
1031 { "End", "bxxp.end", FT_BOOLEAN, BASE_NONE, NULL, 0x0, "" }},
1033 { &hf_bxxp_complete,
1034 { "Complete", "bxxp.more.complete", FT_BOOLEAN, BASE_NONE, NULL, 0x0, "" }},
1036 { &hf_bxxp_intermediate,
1037 { "Intermediate", "bxxp.more.intermediate", FT_BOOLEAN, BASE_NONE, NULL, 0x0, "" }},
1040 { "Serial", "bxxp.serial", FT_UINT32, BASE_DEC, NULL, 0x0, "" }},
1043 { "Seqno", "bxxp.seqno", FT_UINT32, BASE_DEC, NULL, 0x0, "" }},
1046 { "Size", "bxxp.size", FT_UINT32, BASE_DEC, NULL, 0x0, "" }},
1049 { "Channel", "bxxp.channel", FT_UINT32, BASE_DEC, NULL, 0x0, "" }},
1051 { &hf_bxxp_negative,
1052 { "Negative", "bxxp.status.negative", FT_BOOLEAN, BASE_NONE, NULL, 0x0, ""}},
1054 { &hf_bxxp_positive,
1055 { "Positive", "bxxp.status.positive", FT_BOOLEAN, BASE_NONE, NULL, 0x0, ""}},
1058 { "Ackno", "bxxp.seq.ackno", FT_UINT32, BASE_DEC, NULL, 0x0, ""}},
1061 { "Window", "bxxp.seq.window", FT_UINT32, BASE_DEC, NULL, 0x0, ""}},
1064 static gint *ett[] = {
1070 module_t *bxxp_module;
1072 /* Register our configuration options for BXXP, particularly our port */
1074 bxxp_module = prefs_register_module("bxxp", "BXXP", proto_reg_handoff_bxxp);
1076 prefs_register_uint_preference(bxxp_module, "tcp.port", "BXXP TCP Port",
1077 "Set the port for BXXP messages (if other"
1078 " than the default of 10288)",
1079 10, &global_bxxp_tcp_port);
1081 prefs_register_bool_preference(bxxp_module, "strict_header_terminator",
1082 "BXXP Header Requires CRLF",
1083 "Specifies that BXXP requires CRLF as a "
1084 "terminator, and not just CR or LF",
1085 &global_bxxp_strict_term);
1087 proto_bxxp = proto_register_protocol("Blocks eXtensible eXchange Protocol",
1090 proto_register_field_array(proto_bxxp, hf, array_length(hf));
1091 proto_register_subtree_array(ett, array_length(ett));
1092 register_init_routine(&bxxp_init_protocol);
1096 /* The registration hand-off routine */
1098 proto_reg_handoff_bxxp(void)
1100 static int bxxp_prefs_initialized = FALSE;
1102 if (bxxp_prefs_initialized) {
1104 dissector_delete("tcp.port", tcp_port, dissect_bxxp);
1109 bxxp_prefs_initialized = TRUE;
1113 /* Set our port number for future use */
1115 tcp_port = global_bxxp_tcp_port;
1117 dissector_add("tcp.port", global_bxxp_tcp_port, dissect_bxxp);