2 * Routines for I-TDM (Internal TDM) dissection
3 * Compliant to PICMG SFP.0 and SFP.1 March 24, 2005
5 * Copyright 2008, Dan Gora <dg [AT] adax.com>
9 * Wireshark - Network traffic analyzer
10 * By Gerald Combs <gerald@wireshark.org>
11 * Copyright 1998 Gerald Combs
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
31 #include <epan/packet.h>
32 #include <epan/prefs.h>
34 /* Initialize the protocol and registered fields */
35 static int proto_itdm
= -1;
36 static int hf_itdm_timestamp
= -1;
37 static int hf_itdm_seqnum
= -1;
38 static int hf_itdm_sop_eop
= -1;
39 static int hf_itdm_last_pack
= -1;
40 static int hf_itdm_pktlen
= -1;
41 static int hf_itdm_chksum
= -1;
42 static int hf_itdm_uid
= -1;
43 static int hf_itdm_ack
= -1;
44 static int hf_itdm_act
= -1;
45 static int hf_itdm_chcmd
= -1;
46 static int hf_itdm_chid
= -1;
47 static int hf_itdm_chloc1
= -1;
48 static int hf_itdm_chloc2
= -1;
49 static int hf_itdm_pktrate
= -1;
50 static int hf_itdm_cxnsize
= -1;
52 /* I-TDM control protocol fields */
53 static int hf_itdm_ctl_transid
= -1;
54 static int hf_itdm_ctl_command
= -1;
55 static int hf_itdm_ctl_flowid
= -1;
56 static int hf_itdm_ctl_dm
= -1;
57 static int hf_itdm_ctl_emts
= -1;
58 static int hf_itdm_ctl_pktrate
= -1;
59 static int hf_itdm_ctl_ptid
= -1;
60 static int hf_itdm_ctl_cksum
= -1;
63 /* Initialize the subtree pointers */
64 static gint ett_itdm
= -1;
65 static gint ett_itdm_ctl
= -1;
67 /* ZZZZ some magic number.. */
68 static guint gbl_ItdmMPLSLabel
= 0x99887;
69 static guint gbl_ItdmCTLFlowNo
= 0;
71 static dissector_handle_t data_handle
;
73 /* I-TDM 125usec mode commands for data flows */
74 #define ITDM_CMD_NEW_CHAN 1
75 #define ITDM_CMD_CLOSE_CHAN 2
76 #define ITDM_CMD_RELOC_CHAN 3
77 #define ITDM_CMD_CYCLIC_REAF 4
78 #define ITDM_CMD_PACKET_RATE 5
80 #define ITDM_FLOWID_OFFSET 7
81 #define ITDM_CHCMD_OFFSET 10
82 #define ITDM_CHANID_OFFSET 11
83 #define ITDM_CHLOC1_OFFSET 14
84 #define ITDM_CHLOC2_OFFSET 16
86 /* I-TDM commands for I-TDM control flows */
87 #define ITDM_CTL_TRANSID_OFFSET 10
88 #define ITDM_CTL_CMD_OFFSET 14
89 #define ITDM_CTL_FLOWID_OFFSET 15
90 #define ITDM_CTL_ITDM_MODE_OFFSET 18
91 #define ITDM_CTL_EMTS_OFFSET 20
92 #define ITDM_CTL_PKTRATE_OFFSET 22
93 #define ITDM_CTL_PAIRED_TRANSID_OFFSET 26
94 #define ITDM_CTL_CRC_OFFSET 30
96 #define ITDM_CTL_CMD_AFI_REQ 1
98 static const value_string sop_eop_vals
[] = {
99 { 0x0, "Middle of Packet" },
100 { 0x1, "End of Packet" },
101 { 0x2, "Start of Packet" },
102 { 0x3, "Complete Packet" },
106 static const true_false_string ack_tfs
= {
107 "Acknowledging a command from remote node",
111 static const value_string chcmd_vals
[] = {
113 { 0x1, "New Channel ID" },
114 { 0x2, "Close Channel ID" },
115 { 0x3, "Relocate Channel ID" },
116 { 0x4, "Cyclic Reaffirmation" },
117 { 0x5, "Packet Rate Integrity Check" },
131 static const value_string itdm_ctl_command_vals
[] = {
133 { 0x1, "AFI_REQ: Alloc Flow ID Req" },
134 { 0x2, "AFI_RSP: Alloc Flow ID Rsp - Req Accepted." },
135 { 0x3, "DFI_REQ: Dealloc Flow ID Req" },
136 { 0x4, "DFI_RSP: Dealloc Flow ID Rsp - Req Accepted." },
138 { 0x10, "AFI_RSP: Reject: Data Mode Field value Not Supported." },
139 { 0x11, "AFI_RSP: Reject: Explicit Multi-timeslot value Not Supported." },
140 { 0x12, "AFI_RSP: Reject: Packet Rate value Not Supported." },
141 { 0x13, "AFI_RSP: Reject: Checksum Invalid." },
142 { 0x14, "AFI_RSP: Reject: No more flows available." },
144 { 0x20, "DFI_RSP: Reject: Data Mode Field value does not match Flow ID." },
145 { 0x21, "DFI_RSP: Reject: Explicit Multi-timeslots value does not match." },
146 { 0x22, "DFI_RSP: Reject: Packet Rate value does not match." },
147 { 0x23, "DFI_RSP: Reject: Checksum Invalid." },
148 { 0x24, "DFI_RSP: Reject: Flow ID invalid (out of range)." },
149 { 0x25, "DFI_RSP: Reject: Flow ID not currently allocated." },
150 { 0x26, "DFI_RSP: Reject: Other Flow ID in pair has active connections." },
154 static const value_string itdm_ctl_data_mode_vals
[] = {
156 { 1, "I-TDM 1ms Data Mode." },
157 { 2, "I-TDM 125usec Data Mode." },
158 { 3, "I-TDM Explicit Multi-timeslot Data Mode." },
159 { 4, "I-TDM CAS Signaling Data Mode." },
163 static const value_string itdm_ctl_pktrate_vals
[] = {
164 { 0x447A0000, "I-TDM 1ms Data Mode." },
165 { 0x45FA0000, "I-TDM 125usec/EMTS Data Mode." },
166 { 0x43A6AAAB, "I-TDM T1 CAS Mode." },
167 { 0x43FA0000, "I-TDM E1 CAS Mode." },
172 dissect_itdm_125usec(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
)
175 proto_item
*itdm_item
= NULL
;
176 proto_tree
*itdm_tree
= NULL
;
187 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "ITDM");
189 flowid
= tvb_get_ntoh24(tvb
, ITDM_FLOWID_OFFSET
);
190 chanid
= tvb_get_ntoh24(tvb
, ITDM_CHANID_OFFSET
);
191 chcmd
= tvb_get_guint8(tvb
, ITDM_CHCMD_OFFSET
);
192 chloc1
= tvb_get_ntohs(tvb
, ITDM_CHLOC1_OFFSET
);
193 actbit
= (chcmd
& 0x10) ? 1 : 0;
194 ackbit
= (chcmd
& 0x20) ? 1 : 0;
195 chcmd
= chcmd
& 0x0f;
197 col_add_fstr(pinfo
->cinfo
, COL_INFO
,
198 "Flow %d Chan %d ACT %d ACK %d %s",
199 flowid
, chanid
, actbit
, ackbit
,
200 val_to_str_const(chcmd
, chcmd_vals
, "Reserved"));
201 if (chcmd
== ITDM_CMD_NEW_CHAN
||
202 chcmd
== ITDM_CMD_CLOSE_CHAN
||
203 chcmd
== ITDM_CMD_CYCLIC_REAF
)
205 col_append_fstr(pinfo
->cinfo
, COL_INFO
,
208 else if (chcmd
== ITDM_CMD_RELOC_CHAN
)
210 chloc2
= tvb_get_ntohs(tvb
, ITDM_CHLOC2_OFFSET
);
211 col_append_fstr(pinfo
->cinfo
, COL_INFO
,
212 " Loc1 %d Loc2 %d", chloc1
, chloc2
);
219 itdm_item
= proto_tree_add_item(tree
, proto_itdm
, tvb
, 0, -1, ENC_NA
);
220 itdm_tree
= proto_item_add_subtree(itdm_item
, ett_itdm
);
222 proto_tree_add_item(itdm_tree
, hf_itdm_timestamp
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
224 proto_tree_add_item(itdm_tree
, hf_itdm_seqnum
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
226 proto_tree_add_item(itdm_tree
, hf_itdm_sop_eop
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
227 proto_tree_add_item(itdm_tree
, hf_itdm_last_pack
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
228 proto_tree_add_item(itdm_tree
, hf_itdm_pktlen
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
230 proto_tree_add_item(itdm_tree
, hf_itdm_chksum
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
232 proto_tree_add_item(itdm_tree
, hf_itdm_uid
, tvb
, offset
, 3, ENC_BIG_ENDIAN
);
234 proto_tree_add_item(itdm_tree
, hf_itdm_ack
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
235 proto_tree_add_item(itdm_tree
, hf_itdm_act
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
236 proto_tree_add_item(itdm_tree
, hf_itdm_chcmd
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
238 proto_tree_add_item(itdm_tree
, hf_itdm_chid
, tvb
, offset
, 3, ENC_BIG_ENDIAN
);
240 if (chcmd
== ITDM_CMD_PACKET_RATE
)
242 proto_tree_add_item(itdm_tree
, hf_itdm_pktrate
, tvb
, offset
, 4, ENC_BIG_ENDIAN
);
247 proto_tree_add_item(itdm_tree
, hf_itdm_chloc1
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
249 if (chcmd
== ITDM_CMD_CYCLIC_REAF
||
250 chcmd
== ITDM_CMD_NEW_CHAN
||
251 chcmd
== ITDM_CMD_CLOSE_CHAN
)
253 proto_tree_add_item(itdm_tree
, hf_itdm_cxnsize
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
258 proto_tree_add_item(itdm_tree
, hf_itdm_chloc2
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
264 next_tvb
= tvb_new_subset_remaining(tvb
, offset
);
265 call_dissector(data_handle
, next_tvb
, pinfo
, tree
);
269 dissect_itdm_control(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
)
272 proto_item
*itdm_ctl_item
= NULL
;
273 proto_tree
*itdm_ctl_tree
= NULL
;
278 guint32 paired_trans_id
;
279 guint32 allocd_flowid
;
281 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "ITDM-Control");
283 flowid
= tvb_get_ntoh24(tvb
, ITDM_FLOWID_OFFSET
);
284 command
= tvb_get_guint8(tvb
, ITDM_CTL_CMD_OFFSET
);
285 allocd_flowid
= tvb_get_ntoh24(tvb
, ITDM_CTL_FLOWID_OFFSET
);
286 trans_id
= tvb_get_ntohl(tvb
, ITDM_CTL_TRANSID_OFFSET
);
287 paired_trans_id
= tvb_get_ntohl(tvb
, ITDM_CTL_PAIRED_TRANSID_OFFSET
);
289 col_add_fstr(pinfo
->cinfo
, COL_INFO
,
290 "Flow %d Command %s ",
291 flowid
, val_to_str_const(command
, itdm_ctl_command_vals
, "Reserved"));
293 if (command
!= ITDM_CTL_CMD_AFI_REQ
)
295 col_append_fstr(pinfo
->cinfo
, COL_INFO
,
296 " Alloc'd FlowID %d", allocd_flowid
);
299 col_append_fstr(pinfo
->cinfo
, COL_INFO
, " TransID 0x%x ", trans_id
);
301 if (command
!= ITDM_CTL_CMD_AFI_REQ
)
303 col_append_fstr(pinfo
->cinfo
, COL_INFO
,
304 " Paired TransID 0x%x", paired_trans_id
);
311 itdm_ctl_item
= proto_tree_add_item(tree
, proto_itdm
, tvb
, 0, -1, ENC_NA
);
312 itdm_ctl_tree
= proto_item_add_subtree(itdm_ctl_item
, ett_itdm_ctl
);
314 /* These eventually should go into a SFP.0 dissector... */
315 proto_tree_add_item(itdm_ctl_tree
, hf_itdm_timestamp
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
317 proto_tree_add_item(itdm_ctl_tree
, hf_itdm_seqnum
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
319 proto_tree_add_item(itdm_ctl_tree
, hf_itdm_sop_eop
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
320 proto_tree_add_item(itdm_ctl_tree
, hf_itdm_last_pack
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
321 proto_tree_add_item(itdm_ctl_tree
, hf_itdm_pktlen
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
323 proto_tree_add_item(itdm_ctl_tree
, hf_itdm_chksum
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
325 proto_tree_add_item(itdm_ctl_tree
, hf_itdm_uid
, tvb
, offset
, 3, ENC_BIG_ENDIAN
);
328 proto_tree_add_item(itdm_ctl_tree
, hf_itdm_ctl_transid
, tvb
, offset
, 4, ENC_BIG_ENDIAN
);
331 proto_tree_add_item(itdm_ctl_tree
, hf_itdm_ctl_command
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
333 if (command
!= ITDM_CTL_CMD_AFI_REQ
) {
334 proto_tree_add_item(itdm_ctl_tree
, hf_itdm_ctl_flowid
, tvb
, offset
, 3, ENC_BIG_ENDIAN
);
337 proto_tree_add_item(itdm_ctl_tree
, hf_itdm_ctl_dm
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
341 proto_tree_add_item(itdm_ctl_tree
, hf_itdm_ctl_emts
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
343 proto_tree_add_item(itdm_ctl_tree
, hf_itdm_ctl_pktrate
, tvb
, offset
, 4, ENC_BIG_ENDIAN
);
345 if (command
!= ITDM_CTL_CMD_AFI_REQ
) {
346 proto_tree_add_item(itdm_ctl_tree
, hf_itdm_ctl_ptid
, tvb
, offset
, 4, ENC_BIG_ENDIAN
);
351 proto_tree_add_item(itdm_ctl_tree
, hf_itdm_ctl_cksum
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
355 next_tvb
= tvb_new_subset_remaining(tvb
, offset
);
356 call_dissector(data_handle
, next_tvb
, pinfo
, tree
);
360 dissect_itdm(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
)
364 /* ZZZ for now, 125 usec mode and I-TDM control protocol
365 * need to add 1ms mode */
366 if (tvb_length(tvb
) < 18)
369 /* See if this packet is a data flow or the I-TDM control flow. */
370 flowid
= tvb_get_ntoh24(tvb
, ITDM_FLOWID_OFFSET
);
372 /* gbl_ItdmCTLFlowNo is the configurable flow number where
373 * the control protocol resides... Usually 0.
375 if (flowid
== gbl_ItdmCTLFlowNo
)
376 dissect_itdm_control(tvb
, pinfo
, tree
);
378 dissect_itdm_125usec(tvb
, pinfo
, tree
);
381 void proto_reg_handoff_itdm(void);
384 proto_register_itdm(void)
387 static hf_register_info hf
[] = {
388 { &hf_itdm_timestamp
,{ "Timestamp", "itdm.timestamp",
389 FT_UINT16
, BASE_DEC
, NULL
, 0x0, NULL
, HFILL
} },
390 { &hf_itdm_seqnum
,{ "Sequence Number", "itdm.seqnum",
391 FT_UINT8
, BASE_DEC
, NULL
, 0x0, NULL
, HFILL
} },
392 { &hf_itdm_sop_eop
,{ "Start/End of Packet", "itdm.sop_eop",
393 FT_UINT8
, BASE_DEC
, VALS(sop_eop_vals
), 0xc0, NULL
, HFILL
} },
394 { &hf_itdm_last_pack
,{ "Last Packet", "itdm.last_pack",
395 FT_BOOLEAN
, 8, TFS(&tfs_true_false
), 0x20, NULL
, HFILL
} },
396 { &hf_itdm_pktlen
,{ "Packet Length", "itdm.pktlen",
397 FT_UINT16
, BASE_DEC
, NULL
, 0x07ff, NULL
, HFILL
} },
398 { &hf_itdm_chksum
,{ "Checksum", "itdm.chksum",
399 FT_UINT16
, BASE_HEX
, NULL
, 0x0, NULL
, HFILL
} },
400 { &hf_itdm_uid
,{ "Flow ID", "itdm.uid",
401 FT_UINT24
, BASE_DEC
, NULL
, 0x0, NULL
, HFILL
} },
402 { &hf_itdm_ack
,{ "ACK", "itdm.ack",
403 FT_BOOLEAN
, 8, TFS(&ack_tfs
), 0x20, NULL
, HFILL
} },
404 { &hf_itdm_act
,{ "Activate", "itdm.act",
405 FT_BOOLEAN
, 8, TFS(&tfs_true_false
), 0x10, NULL
, HFILL
} },
406 { &hf_itdm_chcmd
,{ "Channel Command", "itdm.chcmd",
407 FT_UINT8
, BASE_DEC
, VALS(chcmd_vals
), 0x0f, NULL
, HFILL
} },
408 { &hf_itdm_chid
,{ "Channel ID", "itdm.chid",
409 FT_UINT24
, BASE_DEC
, NULL
, 0x0, NULL
, HFILL
} },
410 { &hf_itdm_chloc1
,{ "Channel Location 1", "itdm.chloc1",
411 FT_UINT16
, BASE_DEC
, NULL
, 0x1ff, NULL
, HFILL
} },
412 { &hf_itdm_chloc2
,{ "Channel Location 2", "itdm.chloc2",
413 FT_UINT16
, BASE_DEC
, NULL
, 0x1ff, NULL
, HFILL
} },
414 { &hf_itdm_pktrate
,{ "IEEE 754 Packet Rate", "itdm.pktrate",
415 FT_UINT32
, BASE_HEX
, NULL
, 0x0, NULL
, HFILL
} },
416 { &hf_itdm_cxnsize
, { "Connection Size", "itdm.cxnsize",
417 FT_UINT16
, BASE_DEC
, NULL
, 0x0, NULL
, HFILL
} },
419 { &hf_itdm_ctl_transid
, { "Transaction ID", "itdm.ctl_transid",
420 FT_UINT32
, BASE_HEX
, NULL
, 0x0, NULL
, HFILL
} },
421 { &hf_itdm_ctl_command
, { "Control Command", "itdm.ctl_cmd",
422 FT_UINT8
, BASE_DEC
, VALS(itdm_ctl_command_vals
), 0x0, NULL
, HFILL
} },
423 { &hf_itdm_ctl_flowid
, { "Allocated Flow ID", "itdm.ctl_flowid",
424 FT_UINT24
, BASE_DEC
, NULL
, 0x0, NULL
, HFILL
} },
425 { &hf_itdm_ctl_dm
, { "I-TDM Data Mode", "itdm.ctl_dm",
426 FT_UINT8
, BASE_DEC
, VALS(itdm_ctl_data_mode_vals
), 0x0, NULL
, HFILL
} },
427 { &hf_itdm_ctl_emts
, { "I-TDM Explicit Multi-timeslot Size", "itdm.ctlemts",
428 FT_UINT16
, BASE_DEC
, NULL
, 0x0, NULL
, HFILL
} },
429 { &hf_itdm_ctl_pktrate
, { "I-TDM Packet Rate", "itdm.ctl_pktrate",
430 FT_UINT32
, BASE_HEX
, VALS(itdm_ctl_pktrate_vals
), 0x0, NULL
, HFILL
} },
431 { &hf_itdm_ctl_ptid
, { "Paired Transaction ID", "itdm.ctl_ptid",
432 FT_UINT32
, BASE_HEX
, NULL
, 0x0, NULL
, HFILL
} },
433 { &hf_itdm_ctl_cksum
, { "ITDM Control Message Checksum", "itdm.ctl_cksum",
434 FT_UINT16
, BASE_HEX
, NULL
, 0x0, NULL
, HFILL
} }
437 static gint
*ett
[] = {
442 module_t
*itdm_module
;
444 proto_itdm
= proto_register_protocol("Internal TDM", "ITDM", "itdm");
445 register_dissector("itdm", dissect_itdm
, proto_itdm
);
447 proto_register_field_array(proto_itdm
, hf
, array_length(hf
));
448 proto_register_subtree_array(ett
, array_length(ett
));
450 itdm_module
= prefs_register_protocol(proto_itdm
, proto_reg_handoff_itdm
);
452 prefs_register_uint_preference(itdm_module
, "mpls_label",
453 "ITDM MPLS label (Flow Bundle ID in hex)",
454 "The MPLS label (aka Flow Bundle ID) used by ITDM traffic.",
455 16, &gbl_ItdmMPLSLabel
);
457 prefs_register_uint_preference(itdm_module
, "ctl_flowno",
458 "I-TDM Control Protocol Flow Number",
459 "Flow Number used by I-TDM Control Protocol traffic.",
460 10, &gbl_ItdmCTLFlowNo
);
464 proto_reg_handoff_itdm(void)
466 static gboolean Initialized
=FALSE
;
467 static dissector_handle_t itdm_handle
;
468 static guint ItdmMPLSLabel
;
471 itdm_handle
= find_dissector("itdm");
472 data_handle
= find_dissector("data");
475 dissector_delete_uint("mpls.label", ItdmMPLSLabel
, itdm_handle
);
478 ItdmMPLSLabel
= gbl_ItdmMPLSLabel
;
479 dissector_add_uint("mpls.label", gbl_ItdmMPLSLabel
, itdm_handle
);