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