Disable manifest building for our DLLs. This attempts to fix bug 3272.
[obnox/wireshark/wip.git] / plugins / m2m / packet-m2m.c
1 /* packet-m2m.c
2  * Routines for WiMax MAC to MAC TLV packet disassembly
3  *
4  * Copyright (c) 2007 by Intel Corporation.
5  *
6  * Author: Lu Pan <lu.pan@intel.com>
7  *
8  * $Id$
9  *
10  * Wireshark - Network traffic analyzer
11  * By Gerald Combs <gerald@wireshark.org>
12  * Copyright 1999 Gerald Combs
13  *
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.
18  *
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.
23  *
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.
27  */
28
29 /* Include files */
30
31 #ifdef HAVE_CONFIG_H
32 #include "config.h"
33 #endif
34
35 #include <string.h>
36
37 #include <string.h>
38 #include <glib.h>
39 #include <epan/packet.h>
40 #include <epan/reassemble.h>
41 #include <epan/etypes.h>
42 #include <plugins/wimax/wimax_tlv.h>
43
44 /* forward reference */
45 static void dissect_m2m(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
46 static void fch_burst_decoder(proto_tree *tree, tvbuff_t *tvb, gint offset, gint length, packet_info *pinfo);
47 static void cdma_code_decoder(proto_tree *tree, tvbuff_t *tvb, gint offset, gint length, packet_info *pinfo);
48 static void pdu_burst_decoder(proto_tree *tree, tvbuff_t *tvb, gint offset, gint length, packet_info *pinfo, gint burst_number, gint frag_type, gint frag_number);
49 static void fast_feedback_burst_decoder(proto_tree *tree, tvbuff_t *tvb, gint offset, gint length, packet_info *pinfo);
50 static void harq_ack_bursts_decoder(proto_tree *tree, tvbuff_t *tvb, gint offset, gint length, packet_info *pinfo);
51 static void physical_attributes_decoder(proto_tree *tree, tvbuff_t *tvb, gint offset, gint length, packet_info *pinfo);
52 static void extended_tlv_decoder(packet_info *pinfo);
53 void proto_tree_add_tlv(tlv_info_t *this, tvbuff_t *tvb, guint offset, packet_info *pinfo, proto_tree *tree, gint hf);
54
55 /* Global variables */
56 gint    sequence_number = 0;
57 GHashTable *pdu_frag_table = NULL;
58 guint g_frame_number = 0;
59
60 /* Local Variables */
61 static gint proto_m2m = -1;
62 static dissector_handle_t wimax_fch_burst_handle = NULL;
63 static dissector_handle_t wimax_cdma_code_burst_handle = NULL;
64 static dissector_handle_t wimax_pdu_burst_handle = NULL;
65 static dissector_handle_t wimax_ffb_burst_handle = NULL;
66 static dissector_handle_t wimax_hack_burst_handle = NULL;
67 static dissector_handle_t wimax_phy_attributes_burst_handle = NULL;
68
69 static gint ett_m2m = -1;
70 static gint ett_m2m_tlv = -1;
71 static gint ett_m2m_fch = -1;
72 static gint ett_m2m_cdma = -1;
73 static gint ett_m2m_ffb = -1;
74
75 /* Setup protocol subtree array */
76 static gint *ett[] =
77 {
78         &ett_m2m,
79         &ett_m2m_tlv,
80         &ett_m2m_fch,
81         &ett_m2m_cdma,
82         &ett_m2m_ffb,
83 };
84
85 /* TLV types (rev:0.2) */
86 #define TLV_PROTO_VER           1
87 #define TLV_FRAME_NUM           2
88 #define TLV_BURST_NUM           3
89 #define TLV_FRAG_TYPE           4
90 #define TLV_FRAG_NUM            5
91 #define TLV_CDMA_CODE           7
92 #define TLV_FCH_BURST           8
93 #define TLV_PDU_BURST           9
94 #define TLV_FAST_FB             10
95 #define TLV_CRC16_STATUS        11
96 #define TLV_BURST_POWER         12
97 #define TLV_BURST_CINR          13
98 #define TLV_PREAMBLE            14
99 #define TLV_HARQ_ACK_BURST      15
100 #define TLV_PHY_ATTRIBUTES      16
101 #define TLV_EXTENDED_TLV        255
102
103 /* TLV names */
104 static const value_string tlv_name[] =
105 {
106         { TLV_PROTO_VER, "Protocol Version" },
107         { TLV_FRAME_NUM, "Frame Number" },
108         { TLV_BURST_NUM, "Burst Number" },
109         { TLV_FRAG_TYPE, "Fragment Type" },
110         { TLV_FRAG_NUM, "Fragment Number" },
111         { TLV_CDMA_CODE, "CDMA Attribute" },
112         { TLV_FCH_BURST, "FCH Burst" },
113         { TLV_PDU_BURST, "PDU Burst" },
114         { TLV_FAST_FB, "Fast Feedback Burst" },
115         { TLV_CRC16_STATUS, "CRC16 Status" },
116         { TLV_BURST_POWER, " Burst Power" },
117         { TLV_BURST_CINR, "Burst CINR" },
118         { TLV_PREAMBLE, "Preamble" },
119         { TLV_HARQ_ACK_BURST, "HARQ ACK Bursts" },
120         { TLV_PHY_ATTRIBUTES, "PDU Burst Physical Attributes" },
121         { TLV_EXTENDED_TLV, "Extended TLV" },
122         { 0, NULL }
123 };
124
125 /* TLV Fragment types */
126 #define TLV_NO_FRAG     0
127 #define TLV_FIRST_FRAG  1
128 #define TLV_MIDDLE_FRAG 2
129 #define TLV_LAST_FRAG   3
130
131 /* TLV Fragment Type names */
132 static const value_string tlv_frag_type_name[] =
133 {
134         { TLV_NO_FRAG, "No TLV Fragment" },
135         { TLV_FIRST_FRAG, "First TLV Fragment" },
136         { TLV_MIDDLE_FRAG, "Middle TLV Fragment" },
137         { TLV_LAST_FRAG, "Last TLV Fragment" },
138         { 0, NULL }
139 };
140
141 /* TLV CRC16 Status */
142 static const value_string tlv_crc16_status[] =
143 {
144         { 0, "No CRC-16 in burst" },
145         { 1, "Good CRC-16 in burst" },
146         { 2, "Bad CRC-16 in burst" },
147         { 0, NULL }
148 };
149
150 static gint hf_m2m_sequence_number = -1;
151 static gint hf_m2m_frame_number = -1;
152 static gint hf_m2m_tlv_count = -1;
153
154 /* M2M TLV display */
155 static hf_register_info hf[] =
156 {
157         {
158                 &hf_m2m_sequence_number,
159                 {
160                         "Packet Sequence Number", "m2m.seq_number",
161                         FT_UINT16, BASE_DEC, NULL, 0x0,
162                         NULL, HFILL
163                 }
164         },
165         {
166                 &hf_m2m_frame_number,
167                 {
168                         "Value", "m2m.frame_number",
169                         FT_UINT24, BASE_DEC, NULL, 0x0,
170                         NULL, HFILL
171                 }
172         },
173         {
174                 &hf_m2m_tlv_count,
175                 {
176                         "Number of TLVs in the packet", "m2m.tlv_count",
177                         FT_UINT16, BASE_DEC, NULL, 0x0,
178                         NULL, HFILL
179                 }
180         }
181 };
182
183 static gint hf_m2m_type = -1;
184 static gint hf_m2m_len = -1;
185 static gint hf_m2m_len_size = -1;
186 static gint hf_m2m_value_bytes = -1;
187 static gint hf_wimax_invalid_tlv = -1;
188 static gint hf_m2m_value_protocol_vers_uint8 = -1;
189 static gint hf_m2m_value_burst_num_uint8 = -1;
190 static gint hf_m2m_value_frag_type_uint8 = -1;
191 static gint hf_m2m_value_frag_num_uint8 = -1;
192 static gint hf_m2m_value_pdu_burst = -1;
193 static gint hf_m2m_value_fast_fb = -1;
194 static gint hf_m2m_value_fch_burst_uint24 = -1;
195 static gint hf_m2m_value_cdma_code_uint24 = -1;
196 static gint hf_m2m_value_crc16_status_uint8 = -1;
197 static gint hf_m2m_value_burst_power_uint16 = -1;
198 static gint hf_m2m_value_burst_cinr_uint16 = -1;
199 static gint hf_m2m_value_preamble_uint16 = -1;
200 static gint hf_m2m_value_harq_ack_burst_bytes = -1;
201 static gint hf_m2m_phy_attributes = -1;
202
203 /* WiMax TLV display */
204 static hf_register_info hf_tlv[] =
205 {
206         {
207                 &hf_m2m_type,
208                 {
209                         "Type", "m2m.tlv_type",
210                         FT_UINT8, BASE_DEC, NULL, 0x0,
211                         NULL, HFILL
212                 }
213         },
214         {
215                 &hf_m2m_len,
216                 {
217                         "Length", "m2m.tlv_len",
218                         FT_UINT8, BASE_DEC, NULL, 0x0,
219                         NULL, HFILL
220                 }
221         },
222         {
223                 &hf_m2m_len_size,
224                 {
225                         "Length Size", "m2m.tlv_len_size",
226                         FT_UINT8, BASE_HEX, NULL, 0x0,
227                         NULL, HFILL
228                 }
229         },
230         {
231                 &hf_m2m_value_bytes,
232                 {
233                         "Value (hex)", "m2m.multibyte_tlv_value",
234                         FT_BYTES, BASE_HEX, NULL, 0x0,
235                         NULL, HFILL
236                 }
237         },
238         {
239                 &hf_m2m_value_protocol_vers_uint8,
240                 {
241                         "Value", "m2m.protocol_vers_tlv_value",
242                         FT_UINT8, BASE_DEC, NULL, 0x0,
243                         NULL, HFILL
244                 }
245         },
246         {
247                 &hf_m2m_value_burst_num_uint8,
248                 {
249                         "Value", "m2m.burst_num_tlv_value",
250                         FT_UINT8, BASE_DEC, NULL, 0x0,
251                         NULL, HFILL
252                 }
253         },
254         {
255                 &hf_m2m_value_frag_type_uint8,
256                 {
257                         "Value", "m2m.frag_type_tlv_value",
258                         FT_UINT8, BASE_DEC, NULL, 0x0,
259                         NULL, HFILL
260                 }
261         },
262         {
263                 &hf_m2m_value_frag_num_uint8,
264                 {
265                         "Value", "m2m.frag_num_tlv_value",
266                         FT_UINT8, BASE_DEC, NULL, 0x0,
267                         NULL, HFILL
268                 }
269         },
270         {
271                 &hf_m2m_value_pdu_burst,
272                 {
273                         "Value (hex)", "m2m.pdu_burst_tlv_value",
274                         FT_BYTES, BASE_HEX, NULL, 0x0,
275                         NULL, HFILL
276                 }
277         },
278         {
279                 &hf_m2m_value_fast_fb,
280                 {
281                         "Value (hex)", "m2m.fast_fb_tlv_value",
282                         FT_BYTES, BASE_HEX, NULL, 0x0,
283                         NULL, HFILL
284                 }
285         },
286         {
287                 &hf_m2m_value_fch_burst_uint24,
288                 {
289                         "Value", "m2m.fch_burst_tlv_value",
290                         FT_BYTES, BASE_HEX, NULL, 0x0,
291                         NULL, HFILL
292                 }
293         },
294         {
295                 &hf_m2m_value_cdma_code_uint24,
296                 {
297                         "Value", "m2m.cdma_code_tlv_value",
298                         FT_UINT24, BASE_DEC, NULL, 0x0,
299                         NULL, HFILL
300                 }
301         },
302         {
303                 &hf_m2m_value_crc16_status_uint8,
304                 {
305                         "Value", "m2m.crc16_status_tlv_value",
306                         FT_UINT8, BASE_DEC, NULL, 0x0,
307                         NULL, HFILL
308                 }
309         },
310         {
311                 &hf_m2m_value_burst_power_uint16,
312                 {
313                         "Value", "m2m.burst_power_tlv_value",
314                         FT_UINT16, BASE_DEC, NULL, 0x0,
315                         NULL, HFILL
316                 }
317         },
318         {
319                 &hf_m2m_value_burst_cinr_uint16,
320                 {
321                         "Value", "m2m.burst_cinr_tlv_value",
322                         FT_UINT16, BASE_DEC, NULL, 0x0,
323                         NULL, HFILL
324                 }
325         },
326         {
327                 &hf_m2m_value_preamble_uint16,
328                 {
329                         "Value", "m2m.preamble_tlv_value",
330                         FT_UINT16, BASE_DEC, NULL, 0x0,
331                         NULL, HFILL
332                 }
333         },
334         {
335                 &hf_m2m_value_harq_ack_burst_bytes,
336                 {
337                         "Value (hex)", "m2m.harq_ack_burst_tlv_value",
338                         FT_BYTES, BASE_HEX, NULL, 0x0,
339                         NULL, HFILL
340                 }
341         },
342         {
343                 &hf_m2m_phy_attributes,
344                 {
345                         "Value (hex)", "m2m.phy_attributes",
346                         FT_BYTES, BASE_HEX, NULL, 0x0,
347                         NULL, HFILL
348                 }
349         },
350         {
351                 &hf_wimax_invalid_tlv,
352                 {
353                         "Invalid TLV (hex)", "m2m.invalid_tlv",
354                         FT_BYTES, BASE_HEX, NULL, 0x0,
355                         NULL, HFILL
356                 }
357         }
358 };
359
360 /* Register M2M defrag table init routine. */
361 static void
362 m2m_defragment_init(void)
363 {
364         fragment_table_init(&pdu_frag_table);
365 }
366
367 /* Register Wimax Mac to Mac Protocol handler */
368 void proto_reg_handoff_m2m(void)
369 {
370         dissector_handle_t m2m_handle;
371
372         m2m_handle = create_dissector_handle(dissect_m2m, proto_m2m);
373         dissector_add("ethertype", ETHERTYPE_WMX_M2M, m2m_handle);
374 }
375
376 /* Register Wimax Mac to Mac Protocol */
377 void proto_register_m2m(void)
378 {
379         proto_m2m = proto_register_protocol (
380                 "WiMax Mac to Mac Packet", /* name */
381                 "M2M  (m2m)", /* short name */
382                 "m2m" /* abbrev */
383                 );
384
385         proto_register_field_array(proto_m2m, hf, array_length(hf));
386         proto_register_field_array(proto_m2m, hf_tlv, array_length(hf_tlv));
387         proto_register_subtree_array(ett, array_length(ett));
388
389         /* init the PDU fragment table */
390         fragment_table_init(&pdu_frag_table);
391         /* Register the PDU fragment table init routine */
392         register_init_routine(m2m_defragment_init);
393
394         /* Add new protocols here */
395 }
396
397 /* WiMax MAC to MAC protocol dissector */
398 static void dissect_m2m(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
399 {
400         proto_item *ti = NULL;
401         proto_item *m2m_item = NULL;
402         proto_tree *m2m_tree = NULL;
403         proto_tree *tlv_tree = NULL;
404         gint burst_number = 0;
405         gint length, offset = 0;
406         gint tlv_count;
407         gint tlv_type, tlv_len, tlv_offset, tlv_value;
408         gint tlv_frag_type = 0;
409         gint tlv_frag_number = 0;
410         tlv_info_t m2m_tlv_info;
411         gint hf = 0;
412
413         /* display the M2M protocol name */
414         if (check_col(pinfo->cinfo, COL_PROTOCOL))
415         {
416                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "WiMax");
417         }
418
419         /* Clear out stuff in the info column */
420         if (check_col(pinfo->cinfo, COL_INFO))
421         {
422                 col_clear(pinfo->cinfo, COL_INFO);
423         }
424
425
426         {       /* we are being asked for details */
427                 m2m_item = proto_tree_add_item(tree, proto_m2m, tvb, 0, -1, FALSE);
428                 m2m_tree = proto_item_add_subtree(m2m_item, ett_m2m);
429                 /* get the tvb reported length */
430                 length =  tvb_reported_length(tvb);
431                 /* add the size info */
432         /*
433                 proto_item_append_text(m2m_item, " (%u bytes) - Packet Sequence Number,Number of TLVs", length);
434         */
435                 proto_item_append_text(m2m_item, " (%u bytes)", length);
436                 /* get the sequence number */
437                 sequence_number =  tvb_get_ntohs(tvb, offset);
438                 /* display the sequence number */
439                 proto_tree_add_item(m2m_tree, hf_m2m_sequence_number, tvb, offset, 2, FALSE);
440                 offset += 2;
441                 /* display the TLV count */
442                 proto_tree_add_item(m2m_tree, hf_m2m_tlv_count, tvb, offset, 2, FALSE);
443                 tlv_count = tvb_get_ntohs(tvb, offset);
444                 offset += 2;
445                 /* parses the TLVs within current packet */
446                 while ( tlv_count > 0)
447                 {       /* init MAC to MAC TLV information */
448                         init_tlv_info(&m2m_tlv_info, tvb, offset);
449                         /* get the TLV type */
450                         tlv_type = get_tlv_type(&m2m_tlv_info);
451                         /* get the TLV length */
452                         tlv_len = get_tlv_length(&m2m_tlv_info);
453                         if(tlv_type == -1 || tlv_len > 64000 || tlv_len < 1)
454                         {       /* invalid tlv info */
455                                 if (check_col(pinfo->cinfo, COL_INFO))
456                                 {
457                                         col_append_sep_str(pinfo->cinfo, COL_INFO, ", ", "M2M TLV error");
458                                 }
459                                 /* display the invalid TLV in HEX */
460                                 proto_tree_add_item(m2m_tree, hf_wimax_invalid_tlv, tvb, offset, (length - offset), FALSE);
461                                 break;
462                         }
463                         /* get the TLV value offset */
464                         tlv_offset = get_tlv_value_offset(&m2m_tlv_info);
465                         /* display TLV type */
466                         ti = proto_tree_add_protocol_format(m2m_tree, proto_m2m, tvb, offset, (tlv_len + tlv_offset), "%s", val_to_str(tlv_type, tlv_name, "Unknown TLV"));
467                         /* add TLV subtree */
468                         tlv_tree = proto_item_add_subtree(ti, ett_m2m_tlv);
469                         /* update the offset */
470                         offset += tlv_offset;
471                         /* add the size info */
472                         /* decode TLV content (TLV value) */
473                         switch (tlv_type)
474                         {
475                                 case TLV_PROTO_VER:
476                                         /* get the protocol version */
477                                         tlv_value = tvb_get_guint8( tvb, offset );
478                                         /* add the description */
479                                         proto_item_append_text(ti, ": %d", tlv_value);
480                                         hf = hf_m2m_value_protocol_vers_uint8;
481                                 break;
482
483                                 case TLV_BURST_NUM:
484                                         /* get the burst number */
485                                         burst_number = tvb_get_guint8( tvb, offset );
486                                         /* add the description */
487                                         proto_item_append_text(ti, ": %d", burst_number);
488                                         hf = hf_m2m_value_burst_num_uint8;
489                                 break;
490
491                                 case TLV_FRAG_TYPE:
492                                         /* add the description */
493                                         tlv_frag_type = tvb_get_guint8( tvb, offset );
494                                         proto_item_append_text(ti, ": %s", val_to_str(tlv_frag_type, tlv_frag_type_name, "Unknown"));
495                                         hf = hf_m2m_value_frag_type_uint8;
496                                 break;
497
498                                 case TLV_FRAG_NUM:
499                                         /* get the fragment number */
500                                         tlv_frag_number = tvb_get_guint8( tvb, offset );
501                                         /* add the description */
502                                         proto_item_append_text(ti, ": %d", tlv_frag_number);
503                                         hf = hf_m2m_value_frag_num_uint8;
504                                 break;
505
506                                 case TLV_PDU_BURST:
507                                         /* display PDU Burst length info */
508                                         proto_item_append_text(ti, " (%u bytes)", tlv_len);
509                                         /* decode and display the PDU Burst */
510                                         pdu_burst_decoder(tree, tvb, offset, tlv_len, pinfo, burst_number, tlv_frag_type, tlv_frag_number);
511                                         hf = hf_m2m_value_pdu_burst;
512                                 break;
513
514                                 case TLV_FAST_FB:
515                                         /* display the Fast Feedback Burst length info */
516                                         proto_item_append_text(ti, " (%u bytes)", tlv_len);
517                                         /* decode and display the Fast Feedback Burst */
518                                         fast_feedback_burst_decoder(tree, tvb, offset, tlv_len, pinfo);
519                                         hf = hf_m2m_value_fast_fb;
520                                 break;
521
522                                 case TLV_FRAME_NUM:
523                                         /* get the frame number */
524                                         g_frame_number = tvb_get_ntoh24( tvb, offset );
525                                         /* add the description */
526                                         proto_tree_add_item(tlv_tree, hf_m2m_frame_number, tvb, offset, 3, FALSE);
527                                         proto_item_append_text(ti, ": %d", g_frame_number);
528                                 break;
529
530                                 case TLV_FCH_BURST:
531                                         /* add the description */
532                                         tlv_value = tvb_get_ntoh24( tvb, offset );
533                                         proto_item_append_text(ti, ": 0x%X", tlv_value);
534                                         /* decode and display the TLV FCH bust */
535                                         fch_burst_decoder(tree, tvb, offset, tlv_len, pinfo);
536                                         hf = hf_m2m_value_fch_burst_uint24;
537                                 break;
538
539                                 case TLV_CDMA_CODE:
540                                         /* add the description */
541                                         tlv_value = tvb_get_ntoh24( tvb, offset );
542                                         proto_item_append_text(ti, ": 0x%X", tlv_value);
543                                         /* decode and display the CDMA Code */
544                                         cdma_code_decoder(tree, tvb, offset, tlv_len, pinfo);
545                                         hf = hf_m2m_value_cdma_code_uint24;
546                                 break;
547
548                                 case TLV_CRC16_STATUS:
549                                         /* add the description */
550                                         tlv_value = tvb_get_guint8( tvb, offset );
551                                         proto_item_append_text(ti, ": %s", val_to_str(tlv_value, tlv_crc16_status, "Unknown"));
552                                         hf = hf_m2m_value_crc16_status_uint8;
553                                 break;
554
555                                 case TLV_BURST_POWER:
556                                         /* add the description */
557                                         tlv_value = tvb_get_ntohs( tvb, offset );
558                                         proto_item_append_text(ti, ": %d", tlv_value);
559                                         hf = hf_m2m_value_burst_power_uint16;
560                                 break;
561
562                                 case TLV_BURST_CINR:
563                                         /* add the description */
564                                         tlv_value = tvb_get_ntohs( tvb, offset );
565                                         proto_item_append_text(ti, ": 0x%X", tlv_value);
566                                         hf = hf_m2m_value_burst_cinr_uint16;
567                                 break;
568
569                                 case TLV_PREAMBLE:
570                                         /* add the description */
571                                         tlv_value = tvb_get_ntohs( tvb, offset );
572                                         proto_item_append_text(ti, ": 0x%X", tlv_value);
573                                         hf = hf_m2m_value_preamble_uint16;
574                                 break;
575
576                                 case TLV_HARQ_ACK_BURST:
577                                         /* display the Burst length info */
578                                         proto_item_append_text(ti, " (%u bytes)", tlv_len);
579                                         /* decode and display the HARQ ACK Bursts */
580                                         harq_ack_bursts_decoder(tree, tvb, offset, tlv_len, pinfo);
581                                         hf = hf_m2m_value_harq_ack_burst_bytes;
582                                 break;
583
584                                 case TLV_PHY_ATTRIBUTES:
585                                         /* display the Burst length info */
586                                         proto_item_append_text(ti, " (%u bytes)", tlv_len);
587                                         /* decode and display the PDU Burst Physical Attributes */
588                                         physical_attributes_decoder(tree, tvb, offset, tlv_len, pinfo);
589                                         hf = hf_m2m_phy_attributes;
590                                 break;
591
592                                 case TLV_EXTENDED_TLV:
593                                         /* display the Burst length info */
594                                         proto_item_append_text(ti, " (%u bytes)", tlv_len);
595                                         /* decode and display the Extended TLV */
596                                         extended_tlv_decoder(pinfo);
597                                 break;
598
599                                 default:
600                                         /* update the info column */
601                                         if (check_col(pinfo->cinfo, COL_INFO))
602                                         {
603                                                 col_append_sep_str(pinfo->cinfo, COL_INFO, ", ", "Unknown TLV Type");
604                                         }
605                                 break;
606                         }
607                         /* expand the TLV detail */
608                         proto_tree_add_tlv(&m2m_tlv_info, tvb, offset - tlv_offset, pinfo, tlv_tree, hf);
609                         offset += tlv_len;
610                         /* update tlv_count */
611                         tlv_count--;
612                 }
613         }
614 }
615
616 /* Decode and display the FCH burst */
617 static void fch_burst_decoder(proto_tree *tree, tvbuff_t *tvb, gint offset, gint length, packet_info *pinfo)
618 {
619         /* find the TLV FCH Burst handler */
620         wimax_fch_burst_handle = find_dissector("wimax_fch_burst_handler");
621         if(wimax_fch_burst_handle)
622         {       /* call FCH dissector */
623                 call_dissector(wimax_fch_burst_handle, tvb_new_subset(tvb, offset, length, length), pinfo, tree);
624         }
625         else    /* display FCH info */
626         {       /* update the info column */
627                 if (check_col(pinfo->cinfo, COL_INFO))
628                 {
629                         col_append_str(pinfo->cinfo, COL_INFO, "FCH Burst: DL Frame Prefix");
630                 }
631         }
632 }
633
634 /* Decode and display the CDMA Code Attribute */
635 static void cdma_code_decoder(proto_tree *tree, tvbuff_t *tvb, gint offset, gint length, packet_info *pinfo)
636 {
637         /* find the TLV CDMA CODE Burst handler */
638         wimax_cdma_code_burst_handle = find_dissector("wimax_cdma_code_burst_handler");
639         if(wimax_cdma_code_burst_handle)
640         {       /* call CDMA dissector */
641                 call_dissector(wimax_cdma_code_burst_handle, tvb_new_subset(tvb, offset, length, length), pinfo, tree);
642         }
643         else    /* display CDMA Code Attribute info */
644         {       /* update the info column */
645                 if (check_col(pinfo->cinfo, COL_INFO))
646                 {
647                         col_append_str(pinfo->cinfo, COL_INFO, "CDMA Code Attribute");
648                 }
649         }
650 }
651
652 /* Decode and display the PDU Burst */
653 static void pdu_burst_decoder(proto_tree *tree, tvbuff_t *tvb, gint offset, gint length, packet_info *pinfo, gint burst_number, gint frag_type, gint frag_number)
654 {
655         fragment_data *pdu_frag;
656         tvbuff_t *pdu_tvb = NULL;
657         gint pdu_length = 0;
658
659         /* update the info column */
660         if (check_col(pinfo->cinfo, COL_INFO))
661         {
662                 switch (frag_type)
663                 {
664                         case TLV_FIRST_FRAG:
665                                 col_append_sep_fstr(pinfo->cinfo, COL_INFO, NULL, "First TLV Fragment (%d)", frag_number);
666                         break;
667                         case TLV_LAST_FRAG:
668                                 col_append_sep_fstr(pinfo->cinfo, COL_INFO, NULL, "Last TLV Fragment (%d)", frag_number);
669                         break;
670                         case TLV_MIDDLE_FRAG:
671                                 col_append_sep_fstr(pinfo->cinfo, COL_INFO, NULL, "Middle TLV Fragment %d", frag_number);
672                         break;
673                 }
674         }
675         if(frag_type == TLV_NO_FRAG)
676         {       /* not fragmented PDU */
677                 pdu_tvb =  tvb_new_subset(tvb, offset, length, length);
678                 pdu_length = length;
679         }
680         else    /* fragmented PDU */
681         {       /* add the frag */
682                 pdu_frag = fragment_add_seq(tvb, offset, pinfo, burst_number, pdu_frag_table, frag_number - 1, length, ((frag_type==TLV_LAST_FRAG)?0:1));
683                 if(pdu_frag && frag_type == TLV_LAST_FRAG)
684                 {
685                         pdu_length = pdu_frag->len;
686                         /* create the new tvb for defraged frame */
687                         pdu_tvb = tvb_new_real_data(pdu_frag->data, pdu_length, pdu_length);
688                         /* attach the pdu_tvb to tvb so that it will be cleaned up when tvb is cleaned up */
689                         tvb_set_child_real_data_tvbuff(tvb, pdu_tvb);
690                         /* add the defragmented data to the data source list */
691                         add_new_data_source(pinfo, pdu_tvb, "Reassembled WiMax PDU Frame");
692                 }
693                 else
694                 {
695                         pdu_tvb = NULL;
696                         if(frag_type == TLV_LAST_FRAG)
697                         {       /* update the info column */
698                                 if (check_col(pinfo->cinfo, COL_INFO))
699                                         col_append_sep_str(pinfo->cinfo, COL_INFO, ", ", "Incomplete PDU frame");
700                         }
701                 }
702         }
703         /* process the defragmented PDU burst */
704         if(pdu_tvb)
705         {       /* find the TLV PDU Burst handler */
706                 wimax_pdu_burst_handle = find_dissector("wimax_pdu_burst_handler");
707                 if(wimax_pdu_burst_handle)
708                         /* decode and display PDU Burst */
709                         call_dissector(wimax_pdu_burst_handle, pdu_tvb, pinfo, tree);
710                 else    /* display PDU Burst info */
711                 {       /* update the info column */
712                         if (check_col(pinfo->cinfo, COL_INFO))
713                         {
714                                 col_append_str(pinfo->cinfo, COL_INFO, "PDU Burst");
715                         }
716                 }
717         }
718 }
719
720 /* Decode and display the Fast Feedback Burst */
721 static void fast_feedback_burst_decoder(proto_tree *tree, tvbuff_t *tvb, gint offset, gint length, packet_info *pinfo)
722 {
723         /* find the TLV Fast Feedback Burst handler */
724         wimax_ffb_burst_handle = find_dissector("wimax_ffb_burst_handler");
725         if(wimax_ffb_burst_handle)
726         {       /* display the TLV Fast Feedback Burst dissector info */
727                 call_dissector(wimax_ffb_burst_handle, tvb_new_subset(tvb, offset, length, length), pinfo, tree);
728         }
729         else    /* display the Fast Feedback Burst info */
730         {       /* update the info column */
731                 if (check_col(pinfo->cinfo, COL_INFO))
732                 {
733                         col_append_str(pinfo->cinfo, COL_INFO, "Fast Feedback Burst");
734                 }
735         }
736 }
737
738 static void harq_ack_bursts_decoder(proto_tree *tree, tvbuff_t *tvb, gint offset, gint length, packet_info *pinfo)
739 {
740         /* find the TLV HARQ ACK Bursts handler */
741         wimax_hack_burst_handle = find_dissector("wimax_hack_burst_handler");
742         if(wimax_hack_burst_handle)
743         {       /* call the TLV HARQ ACK Bursts dissector */
744                 call_dissector(wimax_hack_burst_handle, tvb_new_subset(tvb, offset, length, length), pinfo, tree);
745         }
746         else    /* display the TLV HARQ ACK Bursts info */
747         {       /* update the info column */
748                 if (check_col(pinfo->cinfo, COL_INFO))
749                 {
750                         col_append_str(pinfo->cinfo, COL_INFO, "HARQ ACK Bursts");
751                 }
752         }
753 }
754
755 static void physical_attributes_decoder(proto_tree *tree, tvbuff_t *tvb, gint offset, gint length, packet_info *pinfo)
756 {
757         /* find the TLV PDU Burst Physical Attributes handler */
758         wimax_phy_attributes_burst_handle = find_dissector("wimax_phy_attributes_burst_handler");
759         if(wimax_phy_attributes_burst_handle)
760         {       /* call the TLV PDU Burst Physical Attributes dissector */
761                 call_dissector(wimax_phy_attributes_burst_handle, tvb_new_subset(tvb, offset, length, length), pinfo, tree);
762         }
763         else    /* display the TLV PDU Burst Physical Attributes info */
764         {       /* update the info column */
765                 if (check_col(pinfo->cinfo, COL_INFO))
766                 {
767                         col_append_str(pinfo->cinfo, COL_INFO, "PHY-attr");
768                 }
769         }
770 }
771
772 static void extended_tlv_decoder(packet_info *pinfo)
773 {
774         /* display the Extended TLV info */
775         /* update the info column */
776         if (check_col(pinfo->cinfo, COL_INFO))
777         {
778                 col_append_str(pinfo->cinfo, COL_INFO, "Extended TLV");
779         }
780 }
781
782 /* Display the raw WiMax TLV */
783 void proto_tree_add_tlv(tlv_info_t *this, tvbuff_t *tvb, guint offset, packet_info *pinfo, proto_tree *tree, gint hf)
784 {
785         guint tlv_offset;
786         gint tlv_type, tlv_len;
787
788         /* make sure the TLV information is valid */
789         if(!this->valid)
790         {       /* invalid TLV info */
791                 if (check_col(pinfo->cinfo, COL_INFO))
792                 {
793                         col_append_sep_fstr(pinfo->cinfo, COL_INFO, NULL, "Invalid TLV");
794                 }
795                 return;
796         }
797         tlv_offset = offset;
798         /* display TLV type */
799         proto_tree_add_item(tree, hf_m2m_type, tvb, tlv_offset, 1, FALSE);
800         tlv_offset++;
801         /* check the TLV length type */
802         if( this->length_type )
803         {       /* multiple bytes TLV length */
804                 /* display the length of the TLV length with MSB */
805                 proto_tree_add_item(tree, hf_m2m_len_size, tvb, tlv_offset, 1, FALSE);
806                 tlv_offset++;
807                 if(this->size_of_length)
808                         /* display the multiple byte TLV length */
809                         proto_tree_add_item(tree, hf_m2m_len, tvb, tlv_offset, this->size_of_length, FALSE);
810                 else
811                         return;
812         }
813         else    /* display the single byte TLV length */
814                 proto_tree_add_item(tree, hf_m2m_len, tvb, tlv_offset, 1, FALSE);
815
816         tlv_type = get_tlv_type(this);
817         /* Display Frame Number as special case for filter */
818         if ( tlv_type == TLV_FRAME_NUM )
819         {
820                 return;
821         }
822
823         /* get the TLV length */
824         tlv_len = get_tlv_length(this);
825         proto_tree_add_item(tree, hf, tvb, (offset + this->value_offset), tlv_len, FALSE);
826 }