change a whole bunch of ethereal into wireshark
[obnox/wireshark/wip.git] / epan / dissectors / packet-wcp.c
1 /* packet-wcp.c
2  * Routines for Wellfleet Compression frame disassembly
3  * Copyright 2001, Jeffrey C. Foster <jfoste@woodward.com>
4  *
5  * $Id$
6  *
7  * Wireshark - Network traffic analyzer
8  * By Gerald Combs <gerald@wireshark.org>
9  * Copyright 1998
10  *
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.
15  *
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.
20  *
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.
24  *
25  * ToDo:
26  *      Add preference to allow/disallow decompression
27  *      Calculate and verify check byte (last byte), if only we knew how!
28  *      Handle Wellfleet compression over PPP links.
29  *              - This will require changing the sub-dissector call
30  *                routine to determine if layer 2 is frame relay or
31  *                or PPP and different sub-dissector routines for each.
32  *
33  * Based upon information in the Nortel TCL based Pcaptap code.
34  *http://www.mynetworkforum.com/tools/PCAPTAP/pcaptap-Win32-3.00.exe
35  *
36  * And lzss algorithm
37  *http://www.rasip.fer.hr/research/compress/algorithms/fund/lz/lzss.html
38  */
39
40 /*
41  * Wellfleet compression is a variation on LZSS encoding.
42  *
43  * Compression is done by keeping a sliding window of previous
44  * data transmited. The sender will use a pattern match to
45  * encode repeated data as a data pointer field. Then a stream
46  * of pointers and actual data bytes. The pointer values include
47  * an offset to previous data in the stream and the length of the
48  *  matching data.
49  *
50  * The data pattern matching is done on the octects.
51  *
52  * The data is encoded as 8 field blocks with a compression flag
53  * byte at the beginning.  If the bit is set in the compression
54  * flag, then that field has a compression field. If it isn't set
55  * then the byte is raw data.
56  *
57  * The compression field is either 2 or 3 bytes long. The length
58  * is determined by the length of the matching data, for short
59  * matches the match length is encoded in the high nibble of the
60  * first byte. Otherwise the third byte of the field contains
61  * the match length.
62  *
63  * First byte -
64  * lower 4 bits:
65  *              High order nibble of the offset
66  *
67  * upper 4 bits:
68  *              1   = length is in 3rd byte
69  *              2-F = length of matching data - 1
70  *
71  * Second byte -
72  *  Lower byte of the source offset.
73  *
74  * Third byte -
75  *  Length of match - 1 if First byte upper nibble = 1, otherwise
76  *  this byte isn't added to data stream.
77  *
78  * Example:
79  *      Uncompressed data (hex):  11 22 22 22 22 33 44 55 66 77
80  *
81  *
82  *      Compression data :
83  *                      Flag bits:      0x20 (third field is compressed)
84  *                      Data:   11 22 20 00 33 44 55
85  *                              /  /  /  /
86  *              raw data ------+--+  /  /
87  *              (Comp length - 1)<<4+  /
88  *              Data offset ----------+
89  *
90  *      Output data (hex):  20 11 22 20 00 33 44 55 66 77
91  *
92  * In this example the copy src is one byte behind the copy destination
93  * so if appears as if output is being loaded with the source byte.
94  *
95  */
96
97
98
99 #ifdef HAVE_CONFIG_H
100 # include "config.h"
101 #endif
102
103 #include <stdio.h>
104 #include <glib.h>
105 #include <string.h>
106 #include <epan/packet.h>
107 #include "packet-frame.h"
108 #include <epan/circuit.h>
109 #include <epan/emem.h>
110 #include <epan/etypes.h>
111 #include <epan/nlpid.h>
112
113 #define MAX_WIN_BUF_LEN 0x7fff          /* storage size for decompressed data */
114 #define MAX_WCP_BUF_LEN 2048            /* storage size for decompressed data */
115 #define FROM_DCE        0x80            /* for direction setting */
116
117 typedef struct {
118
119         guint8  *buf_cur;
120         guint8  buffer[MAX_WIN_BUF_LEN];
121
122 }wcp_window_t;
123
124 typedef struct {
125         wcp_window_t recv;
126         wcp_window_t send;
127 } wcp_circuit_data_t;
128
129 /*XXX do I really want the length in here  */
130 typedef struct {
131
132         guint16  len;
133         guint8  buffer[MAX_WCP_BUF_LEN];
134
135 }wcp_pdata_t;
136
137
138 static int proto_wcp = -1;
139 static int hf_wcp_cmd = -1;
140 static int hf_wcp_ext_cmd = -1;
141 static int hf_wcp_seq = -1;
142 static int hf_wcp_chksum = -1;
143 static int hf_wcp_tid = -1;
144 static int hf_wcp_rev = -1;
145 static int hf_wcp_init = -1;
146 static int hf_wcp_seq_size = -1;
147 static int hf_wcp_alg = -1;
148 static int hf_wcp_alg_cnt = -1;
149 static int hf_wcp_alg_a = -1;
150 static int hf_wcp_alg_b = -1;
151 static int hf_wcp_alg_c = -1;
152 static int hf_wcp_alg_d = -1;
153 static int hf_wcp_rexmit = -1;
154
155 static int hf_wcp_hist_size = -1;
156 static int hf_wcp_ppc = -1;
157 static int hf_wcp_pib = -1;
158
159 static int hf_wcp_comp_bits = -1;
160 static int hf_wcp_comp_marker = -1;
161 static int hf_wcp_short_len = -1;
162 static int hf_wcp_long_len = -1;
163 static int hf_wcp_short_run = -1;
164 static int hf_wcp_long_run = -1;
165 static int hf_wcp_offset = -1;
166
167 static gint ett_wcp = -1;
168 static gint ett_wcp_field = -1;
169
170 static dissector_handle_t fr_uncompressed_handle;
171
172 /*
173  * Bits in the address field.
174  */
175 #define WCP_CMD                 0xf0    /* WCP Command */
176 #define WCP_EXT_CMD             0x0f    /* WCP Extended Command */
177 #define WCP_SEQ                 0x0fff  /* WCP Sequence number */
178 #define WCP_OFFSET_MASK         0x0fff  /* WCP Pattern source offset */
179
180 #define PPC_COMPRESSED_IND              0x0
181 #define PPC_UNCOMPRESSED_IND            0x1
182 #define PPC_TPPC_COMPRESSED_IND         0x2
183 #define PPC_TPPC_UNCOMPRESSED_IND       0x3
184 #define CONNECT_REQ                     0x4
185 #define CONNECT_ACK                     0x5
186 #define CONNECT_NAK                     0x6
187 #define DISCONNECT_REQ                  0x7
188 #define DISCONNECT_ACK                  0x8
189 #define INIT_REQ                        0x9
190 #define INIT_ACK                        0xa
191 #define RESET_REQ                       0xb
192 #define RESET_ACK                       0xc
193 #define REXMIT_NAK                      0xd
194
195
196 static const value_string cmd_string[] = {
197         {0, "Compressed Data"},
198         {1, "Uncompressed Data"},
199         {15, "Extended"},
200         { 0,       NULL }
201         };
202
203 static const value_string ext_cmd_string[] = {
204         {0, "Per Packet Compression"},
205         {4, "Connect Req"},
206         {5, "Connect Ack"},
207         {9, "Init Req"},
208         {0x0a, "Init Ack"},
209
210         { 0,       NULL }
211         };
212
213
214
215 static tvbuff_t *wcp_uncompress( tvbuff_t *src_tvb, int offset, packet_info *pinfo, proto_tree *tree);
216 static wcp_window_t *get_wcp_window_ptr( packet_info *pinfo);
217
218 static void
219 dissect_wcp_con_req(tvbuff_t *tvb, int offset, proto_tree *tree) {
220
221 /* WCP connector request message */
222
223         guint alg_cnt = tvb_get_guint8(tvb, 5);
224
225         proto_tree_add_uint(tree, hf_wcp_tid, tvb, offset, 2, tvb_get_ntohs(tvb, offset));
226         proto_tree_add_uint(tree, hf_wcp_rev, tvb, offset + 2, 1, tvb_get_guint8(tvb, offset + 2));
227         proto_tree_add_uint(tree, hf_wcp_init, tvb, offset + 3, 1, tvb_get_guint8(tvb, offset + 3));
228         proto_tree_add_uint(tree, hf_wcp_seq_size, tvb, offset + 4, 1, tvb_get_guint8(tvb, offset + 4));
229         proto_tree_add_uint(tree, hf_wcp_alg_cnt, tvb, offset + 5, 1, alg_cnt);
230         proto_tree_add_uint(tree, hf_wcp_alg_a, tvb, offset + 6, 1, tvb_get_guint8(tvb, offset + 6));
231         if ( alg_cnt > 1)
232                 proto_tree_add_uint(tree, hf_wcp_alg_b, tvb, offset + 7, 1, tvb_get_guint8(tvb, offset + 7));
233         if ( alg_cnt > 2)
234                 proto_tree_add_uint(tree, hf_wcp_alg_c, tvb, offset + 8, 1, tvb_get_guint8(tvb, offset + 8));
235         if ( alg_cnt > 3)
236                 proto_tree_add_uint(tree, hf_wcp_alg_d, tvb, offset + 9, 1, tvb_get_guint8(tvb, offset + 9));
237 }
238
239 static void
240 dissect_wcp_con_ack( tvbuff_t *tvb, int offset, proto_tree *tree){
241
242 /* WCP connector ack message */
243
244         proto_tree_add_uint(tree, hf_wcp_tid, tvb, offset, 2, tvb_get_ntohs(tvb, offset));
245         proto_tree_add_uint(tree, hf_wcp_rev, tvb, offset + 2, 1, tvb_get_guint8(tvb, offset + 2));
246         proto_tree_add_uint(tree, hf_wcp_seq_size, tvb, offset + 3, 1, tvb_get_guint8(tvb, offset + 3));
247         proto_tree_add_uint(tree, hf_wcp_alg, tvb, offset + 4, 1, tvb_get_guint8(tvb, offset + 4));
248 }
249
250 static void
251 dissect_wcp_init( tvbuff_t *tvb, int offset, proto_tree *tree){
252
253 /* WCP Initiate Request/Ack message */
254
255         proto_tree_add_uint(tree, hf_wcp_tid, tvb, offset, 2, tvb_get_ntohs(tvb, offset));
256         proto_tree_add_uint(tree, hf_wcp_rev, tvb, offset + 2, 1, tvb_get_guint8(tvb, offset + 2));
257         proto_tree_add_uint(tree, hf_wcp_hist_size, tvb, offset + 3, 1, tvb_get_guint8(tvb, offset + 3));
258         proto_tree_add_uint(tree, hf_wcp_ppc, tvb, offset + 4, 1, tvb_get_guint8(tvb, offset + 4));
259         proto_tree_add_uint(tree, hf_wcp_pib, tvb, offset + 5, 1, tvb_get_guint8(tvb, offset + 5));
260 }
261
262
263 static void
264 dissect_wcp_reset( tvbuff_t *tvb, int offset, proto_tree *tree){
265
266 /* Process WCP Reset Request/Ack message */
267
268         proto_tree_add_uint(tree, hf_wcp_tid, tvb, offset, 2, tvb_get_ntohs(tvb, offset));
269 }
270
271
272 static void wcp_save_data( tvbuff_t *tvb, packet_info *pinfo){
273
274         wcp_window_t *buf_ptr = 0;
275         int len;
276
277         /* discard first 2 bytes, header and last byte (check byte) */
278         len = tvb_reported_length( tvb)-3;
279         buf_ptr = get_wcp_window_ptr( pinfo);
280
281         if (( buf_ptr->buf_cur + len) <= (buf_ptr->buffer + MAX_WIN_BUF_LEN)){
282                 tvb_memcpy( tvb, buf_ptr->buf_cur, 2, len);
283                 buf_ptr->buf_cur = buf_ptr->buf_cur + len;
284
285         } else {
286                 guint8 *buf_end = buf_ptr->buffer + MAX_WIN_BUF_LEN;
287                 tvb_memcpy( tvb, buf_ptr->buf_cur, 2, buf_end - buf_ptr->buf_cur);
288                 tvb_memcpy( tvb, buf_ptr->buffer, buf_end - buf_ptr->buf_cur-2,
289                         len - (int)(buf_end - buf_ptr->buf_cur));
290                 buf_ptr->buf_cur = buf_ptr->buf_cur + len - MAX_WIN_BUF_LEN;
291         }
292
293 }
294
295
296 static void dissect_wcp( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
297
298         proto_tree      *wcp_tree;
299         proto_item      *ti;
300         int             wcp_header_len;
301         guint16         temp, cmd, ext_cmd, seq;
302         tvbuff_t        *next_tvb;
303
304         if (check_col(pinfo->cinfo, COL_PROTOCOL))
305                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "WCP");
306         if (check_col(pinfo->cinfo, COL_INFO))
307                 col_clear(pinfo->cinfo, COL_INFO);
308
309         temp =tvb_get_ntohs(tvb, 0);
310
311         cmd = (temp & 0xf000) >> 12;
312         ext_cmd = (temp & 0x0f00) >> 8;
313
314         if ( cmd == 0xf)
315                 wcp_header_len= 1;
316         else
317                 wcp_header_len= 2;
318
319         seq = temp & 0x0fff;
320
321 /*XXX should test seq to be sure it the last + 1 !! */
322
323         if (check_col(pinfo->cinfo, COL_INFO)){
324                 col_add_str(pinfo->cinfo, COL_INFO, val_to_str(cmd, cmd_string, "Unknown"));
325                 if ( cmd == 0xf)
326                         col_append_fstr(pinfo->cinfo, COL_INFO, ", %s",
327                                 val_to_str(ext_cmd, ext_cmd_string, "Unknown"));
328         }
329
330         if (tree) {
331                 ti = proto_tree_add_item(tree, proto_wcp, tvb, 0, wcp_header_len, FALSE);
332
333                 wcp_tree = proto_item_add_subtree(ti, ett_wcp);
334
335                 proto_tree_add_uint(wcp_tree, hf_wcp_cmd, tvb, 0, 1, tvb_get_guint8( tvb, 0));
336                 if ( cmd == 0xf){
337                         proto_tree_add_uint(wcp_tree, hf_wcp_ext_cmd, tvb, 1, 1,
338                                         tvb_get_guint8( tvb, 0));
339                         switch (ext_cmd){
340                         case CONNECT_REQ:
341                                 dissect_wcp_con_req( tvb, 1, wcp_tree);
342                                 break;
343
344                         case CONNECT_ACK:
345                                 dissect_wcp_con_ack( tvb, 1, wcp_tree);
346                                 break;
347                         case INIT_REQ:
348                         case INIT_ACK:
349                                 dissect_wcp_init( tvb, 1, wcp_tree);
350                                 break;
351                         case RESET_REQ:
352                         case RESET_ACK:
353                                 dissect_wcp_reset( tvb, 1, wcp_tree);
354                                 break;
355                         default:
356                                 break;
357                         }
358                 }else {
359                         proto_tree_add_uint(wcp_tree, hf_wcp_seq,  tvb, 0, 2, seq);
360                 }
361         }
362         else {
363                 wcp_tree = NULL;
364         }
365
366
367                                         /* exit if done */
368         if ( cmd != 1 && cmd != 0 && !(cmd == 0xf && ext_cmd == 0))
369                 return;
370
371         if ( cmd == 1) {                /* uncompressed data */
372                 if ( !pinfo->fd->flags.visited){        /* if first pass */
373                         wcp_save_data( tvb, pinfo);
374                 }
375                 next_tvb = tvb_new_subset(tvb, wcp_header_len, -1, -1);
376         }
377         else {          /* cmd == 0 || (cmd == 0xf && ext_cmd == 0) */
378
379                 next_tvb = wcp_uncompress( tvb, wcp_header_len, pinfo, wcp_tree);
380
381                 if ( !next_tvb){
382                         proto_tree_add_protocol_format(tree, proto_malformed, tvb, 0, 0,
383                                         "[Malformed Frame: Bad WCP compressed data]" );
384                         return;
385                 }
386         }
387
388         if ( tree)                      /* add the check byte */
389                 proto_tree_add_uint(wcp_tree, hf_wcp_chksum, tvb,
390                         tvb_reported_length( tvb)-1, 1,
391                         tvb_get_guint8( tvb, tvb_reported_length(tvb)-1));
392
393         call_dissector(fr_uncompressed_handle, next_tvb, pinfo, tree);
394
395         return;
396 }
397
398
399 static guint8 *decompressed_entry( guint8 *src, guint8 *dst, int *len, guint8 * buf_start, guint8 *buf_end){
400
401 /* do the decompression for one field */
402
403         guint16 data_offset, data_cnt;
404         guint8 tmp = *src;
405
406         data_offset = (*(src++) & 0xf) << 8;    /* get high byte */
407         data_offset += *(src++);                /* add next byte */
408
409         if (( tmp & 0xf0) == 0x10){             /* 2 byte count */
410                 data_cnt = *src;
411                 data_cnt++;
412
413         }else {                                 /* one byte count */
414                 data_cnt = tmp >> 4;
415                 data_cnt++;
416         }
417
418
419         src = (dst - 1 - data_offset);
420         if ( src < buf_start)
421                 src += MAX_WIN_BUF_LEN;
422
423
424 /*XXX could do some fancy memory moves, later if speed is problem */
425
426         while( data_cnt--){
427                 *dst = *src;
428                 if ( ++(*len) >MAX_WCP_BUF_LEN){
429                         printf("decomp failed, len = %d\n",  *len);
430
431                         return NULL;    /* end of buffer error */
432                 }
433                 if ( dst++ == buf_end)
434                         dst = buf_start;
435                 if ( src++ == buf_end)
436                         src = buf_start;
437
438         }
439         return dst;
440 }
441
442
443 static
444 wcp_window_t *get_wcp_window_ptr( packet_info *pinfo){
445
446 /* find the circuit for this DLCI, create one if needed */
447 /* and return the wcp_window data structure pointer */
448 /* for the direction of this packet */
449
450         circuit_t *circuit;
451         wcp_circuit_data_t *wcp_circuit_data;
452
453         circuit = find_circuit( pinfo->ctype, pinfo->circuit_id,
454             pinfo->fd->num);
455         if ( !circuit){
456                 circuit = circuit_new( pinfo->ctype, pinfo->circuit_id,
457                     pinfo->fd->num);
458         }
459         wcp_circuit_data = circuit_get_proto_data(circuit, proto_wcp);
460         if ( !wcp_circuit_data){
461                 wcp_circuit_data = se_alloc(sizeof(wcp_circuit_data_t));
462                 wcp_circuit_data->recv.buf_cur = wcp_circuit_data->recv.buffer;
463                 wcp_circuit_data->send.buf_cur = wcp_circuit_data->send.buffer;
464                 circuit_add_proto_data(circuit, proto_wcp, wcp_circuit_data);
465         }
466         if (pinfo->pseudo_header->x25.flags & FROM_DCE)
467                 return &wcp_circuit_data->recv;
468         else
469                 return &wcp_circuit_data->send;
470 }
471
472
473 static tvbuff_t *wcp_uncompress( tvbuff_t *src_tvb, int offset, packet_info *pinfo, proto_tree *tree) {
474
475 /* do the packet data uncompression and load it into the dst buffer */
476
477         proto_tree      *sub_tree;
478         proto_item      *ti;
479
480         int len=0, i = -1;
481         int cnt = tvb_reported_length( src_tvb)-1;      /* don't include check byte */
482
483         guint8 *dst, *src, *buf_start, *buf_end,  *tmp, comp_flag_bits = 0;
484         guint8 src_buf[ MAX_WCP_BUF_LEN];
485         tvbuff_t *volatile tvb = 0;
486         wcp_window_t *buf_ptr = 0;
487         wcp_pdata_t *volatile pdata_ptr;
488
489         buf_ptr = get_wcp_window_ptr( pinfo);
490
491         buf_start = buf_ptr->buffer;
492         buf_end = buf_start + MAX_WIN_BUF_LEN;
493         tmp = buf_ptr->buf_cur;
494
495         if (cnt - offset > MAX_WCP_BUF_LEN) {
496                 if (tree)
497                         proto_tree_add_text( tree, src_tvb, offset, -1,
498                                 "Compressed data exceeds maximum buffer length (%d > %d)",
499                                 cnt - offset, MAX_WCP_BUF_LEN);
500                 return NULL;
501         }
502
503         src = tvb_memcpy(src_tvb, src_buf, offset, cnt - offset);
504         dst = buf_ptr->buf_cur;
505
506         while( offset++ < cnt){
507
508                 if ( --i >= 0){
509                         if ( comp_flag_bits & 0x80){    /* if this is a compressed entry */
510
511                                 if ( !pinfo->fd->flags.visited){        /* if first pass */
512                                         dst = decompressed_entry( src, dst, &len, buf_start, buf_end);
513                                 }
514                                 if ((*src & 0xf0) == 0x10){
515                                         if ( tree) {
516                                                 ti = proto_tree_add_item( tree, hf_wcp_long_run, src_tvb,
517                                                          offset-1, 3, 0);
518                                                 sub_tree = proto_item_add_subtree(ti, ett_wcp_field);
519                                                 proto_tree_add_uint(sub_tree, hf_wcp_offset, src_tvb,
520                                                          offset-1, 2, pntohs(src));
521
522                                                 proto_tree_add_item( sub_tree, hf_wcp_long_len, src_tvb,
523                                                          offset+1, 1, pntohs(src));
524                                         }
525                                         src += 3;
526                                         offset += 2;
527                                 }else{
528                                         if ( tree) {
529                                                 ti = proto_tree_add_item( tree, hf_wcp_short_run, src_tvb,
530                                                          offset - 1, 2, *src);
531                                                 sub_tree = proto_item_add_subtree(ti, ett_wcp_field);
532                                                 proto_tree_add_item( sub_tree, hf_wcp_short_len, src_tvb,
533                                                          offset-1, 1, *src);
534                                                 proto_tree_add_uint(sub_tree, hf_wcp_offset, src_tvb,
535                                                          offset-1, 2, pntohs(src));
536                                         }
537                                         src += 2;
538                                         offset += 1;
539                                 }
540                         }else {
541                                 if ( !pinfo->fd->flags.visited){        /* if first pass */
542                                         *dst = *src;
543                                         if ( dst++ == buf_end)
544                                                 dst = buf_start;
545                                 }
546                                 ++src;
547                                 ++len;
548
549                         }
550
551                         if ( len >MAX_WCP_BUF_LEN){
552                                 return NULL;
553                         }
554
555                         comp_flag_bits <<= 1;
556
557                 }else { /* compressed data flag */
558
559                         comp_flag_bits = *src++;
560                         if (tree)
561                                 proto_tree_add_uint( tree, hf_wcp_comp_bits,  src_tvb, offset-1, 1,
562                                         comp_flag_bits);
563
564                         i = 8;
565                 }
566         }
567
568         if ( pinfo->fd->flags.visited){ /* if not first pass */
569                                         /* get uncompressed data */
570                 pdata_ptr = p_get_proto_data( pinfo->fd, proto_wcp);
571
572                 if ( !pdata_ptr)        /* exit if no data */
573                         return NULL;
574                 len = pdata_ptr->len;
575         } else {
576
577         /* save the new data as per packet data */
578                 pdata_ptr = se_alloc(sizeof(wcp_pdata_t));
579                 memcpy( &pdata_ptr->buffer, buf_ptr->buf_cur,  len);
580                 pdata_ptr->len = len;
581
582                 p_add_proto_data( pinfo->fd, proto_wcp, (void*)pdata_ptr);
583
584                 buf_ptr->buf_cur = dst;
585         }
586
587
588         TRY {
589                 tvb = tvb_new_real_data( pdata_ptr->buffer, pdata_ptr->len, pdata_ptr->len);
590
591         }
592         CATCH(BoundsError) {
593                 DISSECTOR_ASSERT_NOT_REACHED();
594                 return NULL;
595         }
596         CATCH(ReportedBoundsError) {
597                 return NULL;
598         }
599         ENDTRY;
600
601         /* link new tvbuff into tvbuff chain so cleanup is done later */
602         tvb_set_child_real_data_tvbuff( src_tvb, tvb);
603
604         /* Add new data to the data source list */
605         add_new_data_source( pinfo, tvb, "Uncompressed WCP");
606         return tvb;
607
608 }
609
610
611 void
612 proto_register_wcp(void)
613 {
614     static hf_register_info hf[] = {
615         { &hf_wcp_cmd,
616           { "Command", "wcp.cmd", FT_UINT8, BASE_HEX, VALS(cmd_string), WCP_CMD,
617                 "Compression Command", HFILL }},
618         { &hf_wcp_ext_cmd,
619           { "Extended Command", "wcp.ext_cmd", FT_UINT8, BASE_HEX, VALS(ext_cmd_string), WCP_EXT_CMD,
620                 "Extended Compression Command", HFILL }},
621         { &hf_wcp_seq,
622           { "SEQ", "wcp.seq", FT_UINT16, BASE_HEX, NULL, WCP_SEQ,
623                 "Sequence Number", HFILL }},
624         { &hf_wcp_chksum,
625           { "Checksum", "wcp.checksum", FT_UINT8, BASE_DEC, NULL, 0,
626                 "Packet Checksum", HFILL }},
627         { &hf_wcp_tid,
628           { "TID", "wcp.tid", FT_UINT16, BASE_DEC, NULL, 0,
629                 "TID", HFILL }},
630         { &hf_wcp_rev,
631           { "Revision", "wcp.rev", FT_UINT8, BASE_DEC, NULL, 0,
632                 "Revision", HFILL }},
633         { &hf_wcp_init,
634           { "Initiator", "wcp.init", FT_UINT8, BASE_DEC, NULL, 0,
635                 "Initiator", HFILL }},
636         { &hf_wcp_seq_size,
637           { "Seq Size", "wcp.seq_size", FT_UINT8, BASE_DEC, NULL, 0,
638                 "Sequence Size", HFILL }},
639         { &hf_wcp_alg_cnt,
640           { "Alg Count", "wcp.alg_cnt", FT_UINT8, BASE_DEC, NULL, 0,
641                 "Algorithm Count", HFILL }},
642         { &hf_wcp_alg_a,
643           { "Alg 1", "wcp.alg1", FT_UINT8, BASE_DEC, NULL, 0,
644                 "Algorithm #1", HFILL }},
645         { &hf_wcp_alg_b,
646           { "Alg 2", "wcp.alg2", FT_UINT8, BASE_DEC, NULL, 0,
647                 "Algorithm #2", HFILL }},
648         { &hf_wcp_alg_c,
649           { "Alg 3", "wcp.alg3", FT_UINT8, BASE_DEC, NULL, 0,
650                 "Algorithm #3", HFILL }},
651         { &hf_wcp_alg_d,
652           { "Alg 4", "wcp.alg4", FT_UINT8, BASE_DEC, NULL, 0,
653                 "Algorithm #4", HFILL }},
654         { &hf_wcp_alg,
655           { "Alg", "wcp.alg", FT_UINT8, BASE_DEC, NULL, 0,
656                 "Algorithm", HFILL }},
657         { &hf_wcp_rexmit,
658           { "Rexmit", "wcp.rexmit", FT_UINT8, BASE_DEC, NULL, 0,
659                 "Retransmit", HFILL }},
660         { &hf_wcp_hist_size,
661           { "History", "wcp.hist", FT_UINT8, BASE_DEC, NULL, 0,
662                 "History Size", HFILL }},
663         { &hf_wcp_ppc,
664           { "PerPackComp", "wcp.ppc", FT_UINT8, BASE_DEC, NULL, 0,
665                 "Per Packet Compression", HFILL }},
666         { &hf_wcp_pib,
667           { "PIB", "wcp.pib", FT_UINT8, BASE_DEC, NULL, 0,
668                 "PIB", HFILL }},
669         { &hf_wcp_comp_bits,
670           { "Compress Flag", "wcp.flag", FT_UINT8, BASE_HEX, NULL, 0,
671                 "Compressed byte flag", HFILL }},
672         { &hf_wcp_comp_marker,
673           { "Compress Marker", "wcp.mark", FT_UINT8, BASE_DEC, NULL, 0,
674                 "Compressed marker", HFILL }},
675         { &hf_wcp_offset,
676           { "Source offset", "wcp.off", FT_UINT16, BASE_HEX, NULL, WCP_OFFSET_MASK,
677                 "Data source offset", HFILL }},
678         { &hf_wcp_short_len,
679           { "Compress Length", "wcp.short_len", FT_UINT8, BASE_HEX, NULL, 0xf0,
680                 "Compressed length", HFILL }},
681         { &hf_wcp_long_len,
682           { "Compress Length", "wcp.long_len", FT_UINT8, BASE_HEX, NULL, 0,
683                 "Compressed length", HFILL }},
684         { &hf_wcp_long_run,
685           { "Long Compression", "wcp.long_comp", FT_UINT16, BASE_HEX, NULL, 0,
686                 "Long Compression type", HFILL }},
687         { &hf_wcp_short_run,
688           { "Short Compression", "wcp.short_comp", FT_UINT8, BASE_HEX, NULL, 0,
689                 "Short Compression type", HFILL }},
690
691    };
692
693
694     static gint *ett[] = {
695         &ett_wcp,
696         &ett_wcp_field,
697     };
698
699     proto_wcp = proto_register_protocol ("Wellfleet Compression", "WCP", "wcp");
700     proto_register_field_array (proto_wcp, hf, array_length(hf));
701     proto_register_subtree_array(ett, array_length(ett));
702 }
703
704
705 void
706 proto_reg_handoff_wcp(void) {
707     dissector_handle_t wcp_handle;
708
709     /*
710      * Get handle for the Frame Relay (uncompressed) dissector.
711      */
712     fr_uncompressed_handle = find_dissector("fr_uncompressed");
713
714     wcp_handle = create_dissector_handle(dissect_wcp, proto_wcp);
715     dissector_add("fr.ietf", NLPID_COMPRESSED, wcp_handle);
716     dissector_add("ethertype",  ETHERTYPE_WCP, wcp_handle);
717 }