2 * Routines for BXXP packet disassembly
4 * $Id: packet-bxxp.c,v 1.4 2000/10/02 01:44:58 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++;
294 /* Get the MIME header length */
295 int header_len(tvbuff_t *tvb, int offset)
299 while (tvb_get_guint8(tvb, offset + i) != 0x0d
300 && tvb_get_guint8(tvb, offset + i + 1) != 0x0a) i++;
307 dissect_bxxp_mime_header(tvbuff_t *tvb, int offset, frame_data *fd,
310 proto_tree *ti = NULL, *mime_tree = NULL;
311 int mime_length = header_len(tvb, offset);
314 ti = proto_tree_add_text(tree, tvb, offset, mime_length + 2, "Mime header: %s", tvb_format_text(tvb, offset, mime_length + 2));
315 mime_tree = proto_item_add_subtree(ti, ett_mime_header);
318 if (mime_length == 0) { /* Default header */
321 proto_tree_add_text(mime_tree, tvb, offset, 2, "Default values");
325 else { /* FIXME: Process the headers */
330 return mime_length + 2; /* FIXME: Check that the CRLF is there */
335 dissect_bxxp_int(tvbuff_t *tvb, int offset, frame_data *fd,
336 proto_tree *tree, int hf, int *val, int *hfa[])
338 int ival, ind = 0, i = num_len(tvb, offset);
339 guint8 int_buff[100];
341 memset(int_buff, '\0', sizeof(int_buff));
343 tvb_memcpy(tvb, int_buff, offset, MIN(sizeof(int_buff), i));
345 sscanf(int_buff, "%d", &ival); /* FIXME: Dangerous */
348 proto_tree_add_uint(tree, hf, tvb, offset, i, ival);
353 proto_tree_add_uint_hidden(tree, *hfa[ind], tvb, offset, i, ival);
358 *val = ival; /* Return the value */
365 * We check for a terminator. This can be CRLF, which will be recorded
366 * as a terminator, or CR or LF by itself, which will be redorded as
367 * an incorrect terminator ... We build the tree at this point
368 * However, we depend on the variable bxxp_strict_term
372 check_term(tvbuff_t *tvb, int offset, frame_data *fd, proto_tree *tree)
375 /* First, check for CRLF, or, if global_bxxp_strict_term is false,
376 * one of CR or LF ... If neither of these hold, we add an element
377 * that complains of a protocol violation, and return -1, else
378 * we add a terminator to the tree (possibly non-standard) and return
379 * the count of characters we saw ... This may throw off the rest of the
380 * dissection ... so-be-it!
383 if ((tvb_get_guint8(tvb, offset) == 0x0d &&
384 tvb_get_guint8(tvb, offset + 1) == 0x0a)){ /* Correct terminator */
387 proto_tree_add_text(tree, tvb, offset, 2, "Terminator: CRLF");
392 else if ((tvb_get_guint8(tvb, offset) == 0x0d) && !global_bxxp_strict_term) {
395 proto_tree_add_text(tree, tvb, offset, 1, "Nonstandard Terminator: CR");
400 else if ((tvb_get_guint8(tvb, offset) == 0x0a) && !global_bxxp_strict_term) {
403 proto_tree_add_text(tree, tvb, offset, 1, "Nonstandard Terminator: LF");
411 proto_tree_add_text(tree, tvb, offset, 2, "PROTOCOL VIOLATION, Invalid Terminator: %s", tvb_format_text(tvb, offset, 2));
421 * A return value of <= 0 says we bailed out, skip the rest of this message,
424 * A return value > 0 is the count of bytes we consumed ...
428 dissect_bxxp_tree(tvbuff_t *tvb, int offset, packet_info *pinfo,
429 proto_tree *tree, struct bxxp_request_val *request_val,
430 struct bxxp_proto_data *frame_data)
432 proto_tree *ti = NULL, *hdr = NULL;
433 int st_offset, serial, seqno, size, channel, ackno, window, cc;
437 if (tvb_strneql(tvb, offset, "REQ ", 4) == 0) {
440 ti = proto_tree_add_text(tree, tvb, offset, header_len(tvb, offset) + 2, "Header");
442 hdr = proto_item_add_subtree(ti, ett_header);
444 proto_tree_add_boolean_hidden(hdr, hf_bxxp_req, tvb, offset, 3, TRUE);
445 proto_tree_add_text(hdr, NullTVB, offset, 3, "Command: REQ");
451 if (tvb_get_guint8(tvb, offset) != ' ') { /* Protocol violation */
453 /* Hmm, FIXME ... Add some code here ... */
458 offset += 1; /* Skip the space */
460 /* Insert the more elements ... */
462 dissect_bxxp_more(tvb, offset, pinfo->fd, hdr);
465 /* Check the space ... */
469 /* Dissect the serial */
471 offset += dissect_bxxp_int(tvb, offset, pinfo->fd, hdr, hf_bxxp_serial, &serial, req_serial_hfa);
476 /* now for the seqno */
478 offset += dissect_bxxp_int(tvb, offset, pinfo->fd, hdr, hf_bxxp_seqno, &seqno, req_seqno_hfa);
484 offset += dissect_bxxp_int(tvb, offset, pinfo->fd, hdr, hf_bxxp_size, &size, req_size_hfa);
486 request_val -> size = size; /* Stash this away */
488 frame_data->pl_size = size;
489 if (frame_data->pl_size < 0) frame_data->pl_size = 0;
492 /* Check the space */
496 /* Get the channel */
498 offset += dissect_bxxp_int(tvb, offset, pinfo->fd, hdr, hf_bxxp_channel, &channel, req_chan_hfa);
500 if ((cc = check_term(tvb, offset, pinfo->fd, hdr)) <= 0) {
502 /* We dissect the rest as data and bail ... */
505 proto_tree_add_text(hdr, tvb, offset,
506 tvb_length_remaining(tvb, offset),
507 "Undissected Payload: %s",
508 tvb_format_text(tvb, offset,
509 tvb_length_remaining(tvb, offset)
520 /* Insert MIME header ... */
522 offset += dissect_bxxp_mime_header(tvb, offset, pinfo->fd, hdr);
524 /* Now for the payload, if any */
526 if (tvb_length_remaining(tvb, offset) > 0) { /* Dissect what is left as payload */
528 int pl_size = MIN(size, tvb_length_remaining(tvb, offset));
530 /* Except, check the payload length, and only dissect that much */
532 /* We need to keep track, in the conversation, of how much is left
533 * so in the next packet, we can figure out what is part of the payload
534 * and what is the next message
538 proto_tree_add_text(tree, tvb, offset, pl_size, "Payload: %s", tvb_format_text(tvb, offset, pl_size));
545 request_val->size -= pl_size;
546 if (request_val->size < 0) request_val->size = 0;
549 frame_data->pl_size -= pl_size;
550 if (frame_data->pl_size < 0) frame_data->pl_size = 0;
554 /* If anything else left, dissect it ... */
556 if (tvb_length_remaining(tvb, offset) > 0)
557 offset += dissect_bxxp_tree(tvb, offset, pinfo, tree, request_val, frame_data);
559 } else if (tvb_strneql(tvb, offset, "RSP ", 4) == 0) {
563 ti = proto_tree_add_text(tree, tvb, offset, header_len(tvb, offset) + 2, "Header");
565 hdr = proto_item_add_subtree(ti, ett_header);
567 proto_tree_add_boolean_hidden(hdr, hf_bxxp_rsp, NullTVB, offset, 3, TRUE);
568 proto_tree_add_text(hdr, tvb, offset, 3, "Command: RSP");
574 /* Now check the space: FIXME */
578 /* Next, the 'more' flag ... */
580 dissect_bxxp_more(tvb, offset, pinfo->fd, hdr);
583 /* Check the space */
587 offset += dissect_bxxp_int(tvb, offset, pinfo->fd, hdr, hf_bxxp_serial, &serial, rsp_serial_hfa);
592 /* now for the seqno */
594 offset += dissect_bxxp_int(tvb, offset, pinfo->fd, hdr, hf_bxxp_seqno, &seqno, rsp_seqno_hfa);
600 offset += dissect_bxxp_int(tvb, offset, pinfo->fd, hdr, hf_bxxp_size, &size, rsp_size_hfa);
602 request_val->size = size;
604 frame_data->pl_size = size;
606 /* Check the space ... */
610 dissect_bxxp_status(tvb, offset, pinfo->fd, hdr);
614 if ((cc = check_term(tvb, offset, pinfo->fd, hdr)) <= 0) {
616 /* We dissect the rest as data and bail ... */
619 proto_tree_add_text(hdr, tvb, offset,
620 tvb_length_remaining(tvb, offset),
621 "Undissected Payload: %s",
622 tvb_format_text(tvb, offset,
623 tvb_length_remaining(tvb, offset)
634 /* Insert MIME header ... */
636 offset += dissect_bxxp_mime_header(tvb, offset, pinfo->fd, hdr);
638 /* Now for the payload, if any */
640 if (tvb_length_remaining(tvb, offset) > 0) { /* Dissect what is left as payload */
642 int pl_size = MIN(size, tvb_length_remaining(tvb, offset));
644 /* Except, check the payload length, and only dissect that much */
647 proto_tree_add_text(tree, tvb, offset, pl_size, "Payload: %s", tvb_format_text(tvb, offset, pl_size));
653 request_val->size -= pl_size;
654 if (request_val->size < 0) request_val->size = 0;
657 frame_data->pl_size -= pl_size;
658 if (frame_data->pl_size < 0) frame_data->pl_size = 0;
662 /* If anything else left, dissect it ... As what? */
664 if (tvb_length_remaining(tvb, offset) > 0)
665 offset += dissect_bxxp_tree(tvb, offset, pinfo, tree, request_val, frame_data);
667 } else if (tvb_strneql(tvb, offset, "SEQ ", 4) == 0) {
670 proto_tree_add_boolean_hidden(tree, hf_bxxp_seq, NullTVB, offset, 3, TRUE);
671 proto_tree_add_text(tree, tvb, offset, 3, "Command: SEQ");
676 /* Now check the space: FIXME */
680 offset += dissect_bxxp_int(tvb, offset, pinfo->fd, tree, hf_bxxp_channel, &channel, seq_chan_hfa);
682 /* Check the space: FIXME */
686 offset += dissect_bxxp_int(tvb, offset, pinfo->fd, tree, hf_bxxp_ackno, &ackno, seq_ackno_hfa);
688 /* Check the space: FIXME */
692 offset += dissect_bxxp_int(tvb, offset, pinfo->fd, tree, hf_bxxp_window, &window, seq_window_hfa);
694 if ((cc = check_term(tvb, offset, pinfo->fd, tree)) <= 0) {
696 /* We dissect the rest as data and bail ... */
699 proto_tree_add_text(tree, tvb, offset,
700 tvb_length_remaining(tvb, offset),
701 "Undissected Payload: %s",
702 tvb_format_text(tvb, offset,
703 tvb_length_remaining(tvb, offset)
714 } else if (tvb_strneql(tvb, offset, "END", 3) == 0) {
716 proto_tree *tr = NULL;
719 ti = proto_tree_add_text(tree, tvb, offset, MIN(5, tvb_length_remaining(tvb, offset)), "Trailer");
721 tr = proto_item_add_subtree(ti, ett_trailer);
723 proto_tree_add_boolean_hidden(tr, hf_bxxp_end, NullTVB, offset, 3, TRUE);
724 proto_tree_add_text(tr, tvb, offset, 3, "Command: END");
730 if ((cc = check_term(tvb, offset, pinfo->fd, tr)) <= 0) {
732 /* We dissect the rest as data and bail ... */
735 proto_tree_add_text(tr, tvb, offset, tvb_length_remaining(tvb, offset),
736 "Undissected Payload: %s",
737 tvb_format_text(tvb, offset,
738 tvb_length_remaining(tvb, offset)
751 if (tvb_length_remaining(tvb, offset) > 0) { /* Dissect anything left over */
757 pl_size = MIN(request_val->size, tvb_length_remaining(tvb, offset));
759 if (pl_size == 0) { /* The whole of the rest must be payload */
761 pl_size = tvb_length_remaining(tvb, offset); /* Right place ? */
765 } else if (frame_data) {
766 pl_size = MIN(frame_data->pl_size, tvb_length_remaining(tvb, offset));
767 } else { /* Just in case */
768 pl_size = tvb_length_remaining(tvb, offset);
771 /* Take care here to handle the payload correctly, and if there is
772 * another message here, then handle it correctly as well.
775 /* If the pl_size == 0 and the offset == 0?, then we have not processed
776 * anything in this frame above, so we better treat all this data as
777 * payload to avoid recursion loops
780 if (pl_size == 0 && offset == st_offset)
781 pl_size = tvb_length_remaining(tvb, offset);
786 proto_tree_add_text(tree, tvb, offset, pl_size, "Payload: %s",
787 tvb_format_text(tvb, offset, pl_size));
790 offset += pl_size; /* Advance past the payload */
793 request_val->size -= pl_size; /* Reduce payload by what we added */
794 if (request_val->size < 0) request_val->size = 0;
797 frame_data->pl_size -= pl_size;
798 if (frame_data->pl_size < 0) frame_data->pl_size = 0;
802 if (tvb_length_remaining(tvb, offset) > 0) {
803 offset += dissect_bxxp_tree(tvb, offset, pinfo, tree, request_val, frame_data);
807 return offset - st_offset;
812 dissect_bxxp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
815 struct bxxp_proto_data *frame_data = NULL;
816 proto_tree *bxxp_tree = NULL, *ti = NULL;
817 conversation_t *conversation = NULL;
818 struct bxxp_request_key request_key, *new_request_key;
819 struct bxxp_request_val *request_val = NULL;
821 CHECK_DISPLAY_AS_DATA(proto_bxxp, tvb, pinfo, tree);
825 /* If we have per frame data, use that, else, we must have lost the per-
826 * frame data, and we have to do a full dissect pass again.
828 * The per-frame data tells us how much of this frame is left over from a
829 * previous frame, so we dissect it as payload and then try to dissect the
832 * We use the conversation to build up info on the first pass over the
833 * packets of type BXXP, and record anything that is needed if the user
834 * does random dissects of packets in per packet data.
836 * Once we have per-packet data, we don't need the conversation stuff
837 * anymore, but if per-packet data and conversation stuff gets deleted, as
838 * it does under some circumstances when a rescan is done, it all gets
842 /* Find out what conversation this packet is part of ... but only
843 * if we have no information on this packet, so find the per-frame
847 frame_data = p_get_proto_data(pinfo->fd, proto_bxxp);
851 conversation = find_conversation(&pinfo->src, &pinfo->dst, pi.ptype,
852 pinfo->srcport, pinfo->destport);
853 if (conversation == NULL) { /* No conversation, create one */
854 conversation = conversation_new(&pinfo->src, &pinfo->dst, pinfo->ptype,
855 pinfo->srcport, pinfo->destport, NULL);
860 * Check for and insert an entry in the request table if does not exist
862 request_key.conversation = conversation->index;
864 request_val = (struct bxxp_request_val *)g_hash_table_lookup(bxxp_request_hash, &request_key);
866 if (!request_val) { /* Create one */
868 new_request_key = g_mem_chunk_alloc(bxxp_request_keys);
869 new_request_key->conversation = conversation->index;
871 request_val = g_mem_chunk_alloc(bxxp_request_vals);
872 request_val->processed = 0;
873 request_val->size = 0;
875 g_hash_table_insert(bxxp_request_hash, new_request_key, request_val);
880 if (check_col(pinfo->fd, COL_PROTOCOL))
881 col_add_str(pinfo->fd, COL_PROTOCOL, "BXXP");
883 if (check_col(pinfo->fd, COL_INFO)) { /* Check the type ... */
885 col_add_fstr(pinfo->fd, COL_INFO, "%s", tvb_format_text(tvb, offset, tvb_length_remaining(tvb, offset)));
889 /* Here, we parse the message so we can retrieve the info we need, which
890 * is that there is some payload left from a previous segment on the
891 * front of this segment ... This all depends on TCP segments not getting
894 * As a huge kludge, we push the checking for the tree down into the code
895 * and process as if we were given a tree but not call the routines that
896 * adorn the protocol tree if they were NULL.
899 if (tree) { /* Build the tree info ... */
901 ti = proto_tree_add_item(tree, proto_bxxp, tvb, offset, tvb_length(tvb), FALSE);
903 bxxp_tree = proto_item_add_subtree(ti, ett_bxxp);
907 /* Check the per-frame data and the conversation for any left-over
908 * payload from the previous frame
911 /* FIXME: This conditional is not quite correct */
912 if ((frame_data && frame_data->pl_left > 0) ||
913 (request_val && request_val->size > 0)) {
917 pl_left = frame_data->pl_left;
920 pl_left = request_val->size;
921 request_val->size = 0;
923 /* We create the frame data here for this case, and
924 * elsewhere for other frames
927 frame_data = g_mem_chunk_alloc(bxxp_packet_infos);
929 frame_data->pl_left = pl_left;
930 frame_data->pl_size = 0;
932 p_add_proto_data(pinfo->fd, proto_bxxp, frame_data);
936 pl_left = MIN(pl_left, tvb_length_remaining(tvb, offset));
938 /* Add the payload bit, only if we have a tree */
940 proto_tree_add_text(bxxp_tree, tvb, offset, pl_left, "Payload: %s",
941 tvb_format_text(tvb, offset, pl_left));
946 if (tvb_length_remaining(tvb, offset) > 0) {
948 offset += dissect_bxxp_tree(tvb, offset, pinfo, bxxp_tree, request_val, frame_data);
952 /* Set up the per-frame data here if not already done so */
954 if (frame_data == NULL) {
956 frame_data = g_mem_chunk_alloc(bxxp_packet_infos);
958 frame_data->pl_left = 0;
959 frame_data->pl_size = 0;
961 p_add_proto_data(pinfo->fd, proto_bxxp, frame_data);
967 /* Register all the bits needed with the filtering engine */
970 proto_register_bxxp(void)
972 static hf_register_info hf[] = {
973 { &hf_bxxp_proto_viol,
974 { "Protocol Violation", "bxxp.violation", FT_BOOLEAN, BASE_NONE, NULL, 0x0, "" }},
977 { "Request", "bxxp.req", FT_BOOLEAN, BASE_NONE, NULL, 0x0, "" }},
980 { "Request Channel Number", "bxxp.req.channel", FT_UINT32, BASE_DEC, NULL, 0x0, ""}},
983 { "Response", "bxxp.rsp", FT_BOOLEAN, BASE_NONE, NULL, 0x0, "" }},
986 { "Response Channel Number", "bxxp.rsp.channel", FT_UINT32, BASE_DEC, NULL, 0x0, ""}},
989 { "Sequence", "bxxp.seq", FT_BOOLEAN, BASE_NONE, NULL, 0x0, "" }},
992 { "Sequence Channel Number", "bxxp.seq.channel", FT_UINT32, BASE_DEC, NULL, 0x0, ""}},
995 { "End", "bxxp.end", FT_BOOLEAN, BASE_NONE, NULL, 0x0, "" }},
998 { "Complete", "bxxp.more.complete", FT_BOOLEAN, BASE_NONE, NULL, 0x0, "" }},
1000 { &hf_bxxp_intermediate,
1001 { "Intermediate", "bxxp.more.intermediate", FT_BOOLEAN, BASE_NONE, NULL, 0x0, "" }},
1004 { "Serial", "bxxp.serial", FT_UINT32, BASE_DEC, NULL, 0x0, "" }},
1007 { "Seqno", "bxxp.seqno", FT_UINT32, BASE_DEC, NULL, 0x0, "" }},
1010 { "Size", "bxxp.size", FT_UINT32, BASE_DEC, NULL, 0x0, "" }},
1013 { "Channel", "bxxp.channel", FT_UINT32, BASE_DEC, NULL, 0x0, "" }},
1015 { &hf_bxxp_negative,
1016 { "Negative", "bxxp.status.negative", FT_BOOLEAN, BASE_NONE, NULL, 0x0, ""}},
1018 { &hf_bxxp_positive,
1019 { "Positive", "bxxp.status.positive", FT_BOOLEAN, BASE_NONE, NULL, 0x0, ""}},
1022 { "Ackno", "bxxp.seq.ackno", FT_UINT32, BASE_DEC, NULL, 0x0, ""}},
1025 { "Window", "bxxp.seq.window", FT_UINT32, BASE_DEC, NULL, 0x0, ""}},
1028 static gint *ett[] = {
1034 module_t *bxxp_module;
1036 /* Register our configuration options for BXXP, particularly our port */
1038 bxxp_module = prefs_register_module("bxxp", "BXXP", proto_reg_handoff_bxxp);
1040 prefs_register_uint_preference(bxxp_module, "tcp.port", "BXXP TCP Port",
1041 "Set the port for BXXP messages (if other"
1042 " than the default of 10288)",
1043 10, &global_bxxp_tcp_port);
1045 prefs_register_bool_preference(bxxp_module, "strict_header_terminator",
1046 "BXXP Header Requires CRLF",
1047 "Specifies that BXXP requires CRLF as a "
1048 "terminator, and not just CR or LF",
1049 &global_bxxp_strict_term);
1051 proto_bxxp = proto_register_protocol("Blocks eXtensible eXchange Protocol",
1054 proto_register_field_array(proto_bxxp, hf, array_length(hf));
1055 proto_register_subtree_array(ett, array_length(ett));
1056 register_init_routine(&bxxp_init_protocol);
1060 /* The registration hand-off routine */
1062 proto_reg_handoff_bxxp(void)
1064 static int bxxp_prefs_initialized = FALSE;
1066 if (bxxp_prefs_initialized) {
1068 dissector_delete("tcp.port", tcp_port, dissect_bxxp);
1073 bxxp_prefs_initialized = TRUE;
1077 /* Set our port number for future use */
1079 tcp_port = global_bxxp_tcp_port;
1081 dissector_add("tcp.port", global_bxxp_tcp_port, dissect_bxxp);