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>
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * SPDX-License-Identifier: GPL-2.0-or-later
16 #include <epan/packet.h>
17 #include <epan/prefs.h>
19 #include <wsutil/array.h>
21 void proto_register_itdm(void);
22 void proto_reg_handoff_itdm(void);
24 /* Initialize the protocol and registered fields */
25 static int proto_itdm
;
26 static int hf_itdm_timestamp
;
27 static int hf_itdm_seqnum
;
28 static int hf_itdm_sop_eop
;
29 static int hf_itdm_last_pack
;
30 static int hf_itdm_pktlen
;
31 static int hf_itdm_chksum
;
32 static int hf_itdm_uid
;
33 static int hf_itdm_ack
;
34 static int hf_itdm_act
;
35 static int hf_itdm_chcmd
;
36 static int hf_itdm_chid
;
37 static int hf_itdm_chloc1
;
38 static int hf_itdm_chloc2
;
39 static int hf_itdm_pktrate
;
40 static int hf_itdm_cxnsize
;
42 /* I-TDM control protocol fields */
43 static int hf_itdm_ctl_transid
;
44 static int hf_itdm_ctl_command
;
45 static int hf_itdm_ctl_flowid
;
46 static int hf_itdm_ctl_dm
;
47 static int hf_itdm_ctl_emts
;
48 static int hf_itdm_ctl_pktrate
;
49 static int hf_itdm_ctl_ptid
;
50 static int hf_itdm_ctl_cksum
;
53 /* Initialize the subtree pointers */
55 static int ett_itdm_ctl
;
57 static dissector_handle_t itdm_handle
;
59 /* ZZZZ some magic number.. */
60 static unsigned gbl_ItdmMPLSLabel
= 0x99887;
61 static unsigned gbl_ItdmCTLFlowNo
;
63 /* I-TDM 125usec mode commands for data flows */
64 #define ITDM_CMD_NEW_CHAN 1
65 #define ITDM_CMD_CLOSE_CHAN 2
66 #define ITDM_CMD_RELOC_CHAN 3
67 #define ITDM_CMD_CYCLIC_REAF 4
68 #define ITDM_CMD_PACKET_RATE 5
70 #define ITDM_FLOWID_OFFSET 7
71 #define ITDM_CHCMD_OFFSET 10
72 #define ITDM_CHANID_OFFSET 11
73 #define ITDM_CHLOC1_OFFSET 14
74 #define ITDM_CHLOC2_OFFSET 16
76 /* I-TDM commands for I-TDM control flows */
77 #define ITDM_CTL_TRANSID_OFFSET 10
78 #define ITDM_CTL_CMD_OFFSET 14
79 #define ITDM_CTL_FLOWID_OFFSET 15
80 #define ITDM_CTL_ITDM_MODE_OFFSET 18
81 #define ITDM_CTL_EMTS_OFFSET 20
82 #define ITDM_CTL_PKTRATE_OFFSET 22
83 #define ITDM_CTL_PAIRED_TRANSID_OFFSET 26
84 #define ITDM_CTL_CRC_OFFSET 30
86 #define ITDM_CTL_CMD_AFI_REQ 1
88 static const value_string sop_eop_vals
[] = {
89 { 0x0, "Middle of Packet" },
90 { 0x1, "End of Packet" },
91 { 0x2, "Start of Packet" },
92 { 0x3, "Complete Packet" },
96 static const true_false_string ack_tfs
= {
97 "Acknowledging a command from remote node",
101 static const value_string chcmd_vals
[] = {
103 { 0x1, "New Channel ID" },
104 { 0x2, "Close Channel ID" },
105 { 0x3, "Relocate Channel ID" },
106 { 0x4, "Cyclic Reaffirmation" },
107 { 0x5, "Packet Rate Integrity Check" },
121 static const value_string itdm_ctl_command_vals
[] = {
123 { 0x1, "AFI_REQ: Alloc Flow ID Req" },
124 { 0x2, "AFI_RSP: Alloc Flow ID Rsp - Req Accepted." },
125 { 0x3, "DFI_REQ: Dealloc Flow ID Req" },
126 { 0x4, "DFI_RSP: Dealloc Flow ID Rsp - Req Accepted." },
128 { 0x10, "AFI_RSP: Reject: Data Mode Field value Not Supported." },
129 { 0x11, "AFI_RSP: Reject: Explicit Multi-timeslot value Not Supported." },
130 { 0x12, "AFI_RSP: Reject: Packet Rate value Not Supported." },
131 { 0x13, "AFI_RSP: Reject: Checksum Invalid." },
132 { 0x14, "AFI_RSP: Reject: No more flows available." },
134 { 0x20, "DFI_RSP: Reject: Data Mode Field value does not match Flow ID." },
135 { 0x21, "DFI_RSP: Reject: Explicit Multi-timeslots value does not match." },
136 { 0x22, "DFI_RSP: Reject: Packet Rate value does not match." },
137 { 0x23, "DFI_RSP: Reject: Checksum Invalid." },
138 { 0x24, "DFI_RSP: Reject: Flow ID invalid (out of range)." },
139 { 0x25, "DFI_RSP: Reject: Flow ID not currently allocated." },
140 { 0x26, "DFI_RSP: Reject: Other Flow ID in pair has active connections." },
144 static const value_string itdm_ctl_data_mode_vals
[] = {
146 { 1, "I-TDM 1ms Data Mode." },
147 { 2, "I-TDM 125usec Data Mode." },
148 { 3, "I-TDM Explicit Multi-timeslot Data Mode." },
149 { 4, "I-TDM CAS Signaling Data Mode." },
153 static const value_string itdm_ctl_pktrate_vals
[] = {
154 { 0x447A0000, "I-TDM 1ms Data Mode." },
155 { 0x45FA0000, "I-TDM 125usec/EMTS Data Mode." },
156 { 0x43A6AAAB, "I-TDM T1 CAS Mode." },
157 { 0x43FA0000, "I-TDM E1 CAS Mode." },
162 dissect_itdm_125usec(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
)
165 proto_item
*itdm_item
= NULL
;
166 proto_tree
*itdm_tree
= NULL
;
177 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "ITDM");
179 flowid
= tvb_get_ntoh24(tvb
, ITDM_FLOWID_OFFSET
);
180 chanid
= tvb_get_ntoh24(tvb
, ITDM_CHANID_OFFSET
);
181 chcmd
= tvb_get_uint8(tvb
, ITDM_CHCMD_OFFSET
);
182 chloc1
= tvb_get_ntohs(tvb
, ITDM_CHLOC1_OFFSET
);
183 actbit
= (chcmd
& 0x10) ? 1 : 0;
184 ackbit
= (chcmd
& 0x20) ? 1 : 0;
185 chcmd
= chcmd
& 0x0f;
187 col_add_fstr(pinfo
->cinfo
, COL_INFO
,
188 "Flow %d Chan %d ACT %d ACK %d %s",
189 flowid
, chanid
, actbit
, ackbit
,
190 val_to_str_const(chcmd
, chcmd_vals
, "Reserved"));
191 if (chcmd
== ITDM_CMD_NEW_CHAN
||
192 chcmd
== ITDM_CMD_CLOSE_CHAN
||
193 chcmd
== ITDM_CMD_CYCLIC_REAF
)
195 col_append_fstr(pinfo
->cinfo
, COL_INFO
,
198 else if (chcmd
== ITDM_CMD_RELOC_CHAN
)
200 chloc2
= tvb_get_ntohs(tvb
, ITDM_CHLOC2_OFFSET
);
201 col_append_fstr(pinfo
->cinfo
, COL_INFO
,
202 " Loc1 %d Loc2 %d", chloc1
, chloc2
);
209 itdm_item
= proto_tree_add_item(tree
, proto_itdm
, tvb
, 0, -1, ENC_NA
);
210 itdm_tree
= proto_item_add_subtree(itdm_item
, ett_itdm
);
212 proto_tree_add_item(itdm_tree
, hf_itdm_timestamp
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
214 proto_tree_add_item(itdm_tree
, hf_itdm_seqnum
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
216 proto_tree_add_item(itdm_tree
, hf_itdm_sop_eop
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
217 proto_tree_add_item(itdm_tree
, hf_itdm_last_pack
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
218 proto_tree_add_item(itdm_tree
, hf_itdm_pktlen
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
220 proto_tree_add_checksum(itdm_tree
, tvb
, offset
, hf_itdm_chksum
, -1, NULL
, pinfo
, 0, ENC_BIG_ENDIAN
, PROTO_CHECKSUM_NO_FLAGS
);
222 proto_tree_add_item(itdm_tree
, hf_itdm_uid
, tvb
, offset
, 3, ENC_BIG_ENDIAN
);
224 proto_tree_add_item(itdm_tree
, hf_itdm_ack
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
225 proto_tree_add_item(itdm_tree
, hf_itdm_act
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
226 proto_tree_add_item(itdm_tree
, hf_itdm_chcmd
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
228 proto_tree_add_item(itdm_tree
, hf_itdm_chid
, tvb
, offset
, 3, ENC_BIG_ENDIAN
);
230 if (chcmd
== ITDM_CMD_PACKET_RATE
)
232 proto_tree_add_item(itdm_tree
, hf_itdm_pktrate
, tvb
, offset
, 4, ENC_BIG_ENDIAN
);
237 proto_tree_add_item(itdm_tree
, hf_itdm_chloc1
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
239 if (chcmd
== ITDM_CMD_CYCLIC_REAF
||
240 chcmd
== ITDM_CMD_NEW_CHAN
||
241 chcmd
== ITDM_CMD_CLOSE_CHAN
)
243 proto_tree_add_item(itdm_tree
, hf_itdm_cxnsize
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
248 proto_tree_add_item(itdm_tree
, hf_itdm_chloc2
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
254 next_tvb
= tvb_new_subset_remaining(tvb
, offset
);
255 call_data_dissector(next_tvb
, pinfo
, tree
);
259 dissect_itdm_control(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
)
262 proto_item
*itdm_ctl_item
= NULL
;
263 proto_tree
*itdm_ctl_tree
= NULL
;
268 uint32_t paired_trans_id
;
269 uint32_t allocd_flowid
;
271 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "ITDM-Control");
273 flowid
= tvb_get_ntoh24(tvb
, ITDM_FLOWID_OFFSET
);
274 command
= tvb_get_uint8(tvb
, ITDM_CTL_CMD_OFFSET
);
275 allocd_flowid
= tvb_get_ntoh24(tvb
, ITDM_CTL_FLOWID_OFFSET
);
276 trans_id
= tvb_get_ntohl(tvb
, ITDM_CTL_TRANSID_OFFSET
);
277 paired_trans_id
= tvb_get_ntohl(tvb
, ITDM_CTL_PAIRED_TRANSID_OFFSET
);
279 col_add_fstr(pinfo
->cinfo
, COL_INFO
,
280 "Flow %d Command %s ",
281 flowid
, val_to_str_const(command
, itdm_ctl_command_vals
, "Reserved"));
283 if (command
!= ITDM_CTL_CMD_AFI_REQ
)
285 col_append_fstr(pinfo
->cinfo
, COL_INFO
,
286 " Alloc'd FlowID %d", allocd_flowid
);
289 col_append_fstr(pinfo
->cinfo
, COL_INFO
, " TransID 0x%x ", trans_id
);
291 if (command
!= ITDM_CTL_CMD_AFI_REQ
)
293 col_append_fstr(pinfo
->cinfo
, COL_INFO
,
294 " Paired TransID 0x%x", paired_trans_id
);
301 itdm_ctl_item
= proto_tree_add_item(tree
, proto_itdm
, tvb
, 0, -1, ENC_NA
);
302 itdm_ctl_tree
= proto_item_add_subtree(itdm_ctl_item
, ett_itdm_ctl
);
304 /* These eventually should go into a SFP.0 dissector... */
305 proto_tree_add_item(itdm_ctl_tree
, hf_itdm_timestamp
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
307 proto_tree_add_item(itdm_ctl_tree
, hf_itdm_seqnum
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
309 proto_tree_add_item(itdm_ctl_tree
, hf_itdm_sop_eop
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
310 proto_tree_add_item(itdm_ctl_tree
, hf_itdm_last_pack
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
311 proto_tree_add_item(itdm_ctl_tree
, hf_itdm_pktlen
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
313 proto_tree_add_checksum(itdm_ctl_tree
, tvb
, offset
, hf_itdm_chksum
, -1, NULL
, pinfo
, 0, ENC_BIG_ENDIAN
, PROTO_CHECKSUM_NO_FLAGS
);
315 proto_tree_add_item(itdm_ctl_tree
, hf_itdm_uid
, tvb
, offset
, 3, ENC_BIG_ENDIAN
);
318 proto_tree_add_item(itdm_ctl_tree
, hf_itdm_ctl_transid
, tvb
, offset
, 4, ENC_BIG_ENDIAN
);
321 proto_tree_add_item(itdm_ctl_tree
, hf_itdm_ctl_command
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
323 if (command
!= ITDM_CTL_CMD_AFI_REQ
) {
324 proto_tree_add_item(itdm_ctl_tree
, hf_itdm_ctl_flowid
, tvb
, offset
, 3, ENC_BIG_ENDIAN
);
327 proto_tree_add_item(itdm_ctl_tree
, hf_itdm_ctl_dm
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
331 proto_tree_add_item(itdm_ctl_tree
, hf_itdm_ctl_emts
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
333 proto_tree_add_item(itdm_ctl_tree
, hf_itdm_ctl_pktrate
, tvb
, offset
, 4, ENC_BIG_ENDIAN
);
335 if (command
!= ITDM_CTL_CMD_AFI_REQ
) {
336 proto_tree_add_item(itdm_ctl_tree
, hf_itdm_ctl_ptid
, tvb
, offset
, 4, ENC_BIG_ENDIAN
);
341 proto_tree_add_item(itdm_ctl_tree
, hf_itdm_ctl_cksum
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
345 next_tvb
= tvb_new_subset_remaining(tvb
, offset
);
346 call_data_dissector(next_tvb
, pinfo
, tree
);
350 dissect_itdm(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void* data _U_
)
354 /* ZZZ for now, 125 usec mode and I-TDM control protocol
355 * need to add 1ms mode */
356 if (tvb_captured_length(tvb
) < 18)
359 /* See if this packet is a data flow or the I-TDM control flow. */
360 flowid
= tvb_get_ntoh24(tvb
, ITDM_FLOWID_OFFSET
);
362 /* gbl_ItdmCTLFlowNo is the configurable flow number where
363 * the control protocol resides... Usually 0.
365 if (flowid
== gbl_ItdmCTLFlowNo
)
366 dissect_itdm_control(tvb
, pinfo
, tree
);
368 dissect_itdm_125usec(tvb
, pinfo
, tree
);
369 return tvb_captured_length(tvb
);
373 proto_register_itdm(void)
376 static hf_register_info hf
[] = {
377 { &hf_itdm_timestamp
,{ "Timestamp", "itdm.timestamp",
378 FT_UINT16
, BASE_DEC
, NULL
, 0x0, NULL
, HFILL
} },
379 { &hf_itdm_seqnum
,{ "Sequence Number", "itdm.seqnum",
380 FT_UINT8
, BASE_DEC
, NULL
, 0x0, NULL
, HFILL
} },
381 { &hf_itdm_sop_eop
,{ "Start/End of Packet", "itdm.sop_eop",
382 FT_UINT8
, BASE_DEC
, VALS(sop_eop_vals
), 0xc0, NULL
, HFILL
} },
383 { &hf_itdm_last_pack
,{ "Last Packet", "itdm.last_pack",
384 FT_BOOLEAN
, 8, NULL
, 0x20, NULL
, HFILL
} },
385 { &hf_itdm_pktlen
,{ "Packet Length", "itdm.pktlen",
386 FT_UINT16
, BASE_DEC
, NULL
, 0x07ff, NULL
, HFILL
} },
387 { &hf_itdm_chksum
,{ "Checksum", "itdm.chksum",
388 FT_UINT16
, BASE_HEX
, NULL
, 0x0, NULL
, HFILL
} },
389 { &hf_itdm_uid
,{ "Flow ID", "itdm.uid",
390 FT_UINT24
, BASE_DEC
, NULL
, 0x0, NULL
, HFILL
} },
391 { &hf_itdm_ack
,{ "ACK", "itdm.ack",
392 FT_BOOLEAN
, 8, TFS(&ack_tfs
), 0x20, NULL
, HFILL
} },
393 { &hf_itdm_act
,{ "Activate", "itdm.act",
394 FT_BOOLEAN
, 8, NULL
, 0x10, NULL
, HFILL
} },
395 { &hf_itdm_chcmd
,{ "Channel Command", "itdm.chcmd",
396 FT_UINT8
, BASE_DEC
, VALS(chcmd_vals
), 0x0f, NULL
, HFILL
} },
397 { &hf_itdm_chid
,{ "Channel ID", "itdm.chid",
398 FT_UINT24
, BASE_DEC
, NULL
, 0x0, NULL
, HFILL
} },
399 { &hf_itdm_chloc1
,{ "Channel Location 1", "itdm.chloc1",
400 FT_UINT16
, BASE_DEC
, NULL
, 0x01ff, NULL
, HFILL
} },
401 { &hf_itdm_chloc2
,{ "Channel Location 2", "itdm.chloc2",
402 FT_UINT16
, BASE_DEC
, NULL
, 0x01ff, NULL
, HFILL
} },
403 { &hf_itdm_pktrate
,{ "IEEE 754 Packet Rate", "itdm.pktrate",
404 FT_UINT32
, BASE_HEX
, NULL
, 0x0, NULL
, HFILL
} },
405 { &hf_itdm_cxnsize
, { "Connection Size", "itdm.cxnsize",
406 FT_UINT16
, BASE_DEC
, NULL
, 0x0, NULL
, HFILL
} },
408 { &hf_itdm_ctl_transid
, { "Transaction ID", "itdm.ctl_transid",
409 FT_UINT32
, BASE_HEX
, NULL
, 0x0, NULL
, HFILL
} },
410 { &hf_itdm_ctl_command
, { "Control Command", "itdm.ctl_cmd",
411 FT_UINT8
, BASE_DEC
, VALS(itdm_ctl_command_vals
), 0x0, NULL
, HFILL
} },
412 { &hf_itdm_ctl_flowid
, { "Allocated Flow ID", "itdm.ctl_flowid",
413 FT_UINT24
, BASE_DEC
, NULL
, 0x0, NULL
, HFILL
} },
414 { &hf_itdm_ctl_dm
, { "I-TDM Data Mode", "itdm.ctl_dm",
415 FT_UINT8
, BASE_DEC
, VALS(itdm_ctl_data_mode_vals
), 0x0, NULL
, HFILL
} },
416 { &hf_itdm_ctl_emts
, { "I-TDM Explicit Multi-timeslot Size", "itdm.ctlemts",
417 FT_UINT16
, BASE_DEC
, NULL
, 0x0, NULL
, HFILL
} },
418 { &hf_itdm_ctl_pktrate
, { "I-TDM Packet Rate", "itdm.ctl_pktrate",
419 FT_UINT32
, BASE_HEX
, VALS(itdm_ctl_pktrate_vals
), 0x0, NULL
, HFILL
} },
420 { &hf_itdm_ctl_ptid
, { "Paired Transaction ID", "itdm.ctl_ptid",
421 FT_UINT32
, BASE_HEX
, NULL
, 0x0, NULL
, HFILL
} },
422 { &hf_itdm_ctl_cksum
, { "ITDM Control Message Checksum", "itdm.ctl_cksum",
423 FT_UINT16
, BASE_HEX
, NULL
, 0x0, NULL
, HFILL
} }
426 static int *ett
[] = {
431 module_t
*itdm_module
;
433 proto_itdm
= proto_register_protocol("Internal TDM", "ITDM", "itdm");
434 itdm_handle
= register_dissector("itdm", dissect_itdm
, proto_itdm
);
436 proto_register_field_array(proto_itdm
, hf
, array_length(hf
));
437 proto_register_subtree_array(ett
, array_length(ett
));
439 itdm_module
= prefs_register_protocol(proto_itdm
, proto_reg_handoff_itdm
);
441 prefs_register_uint_preference(itdm_module
, "mpls_label",
442 "ITDM MPLS label (Flow Bundle ID in hex)",
443 "The MPLS label (aka Flow Bundle ID) used by ITDM traffic.",
444 16, &gbl_ItdmMPLSLabel
);
446 prefs_register_uint_preference(itdm_module
, "ctl_flowno",
447 "I-TDM Control Protocol Flow Number",
448 "Flow Number used by I-TDM Control Protocol traffic.",
449 10, &gbl_ItdmCTLFlowNo
);
453 proto_reg_handoff_itdm(void)
455 static bool Initialized
=false;
456 static unsigned ItdmMPLSLabel
;
461 dissector_delete_uint("mpls.label", ItdmMPLSLabel
, itdm_handle
);
464 ItdmMPLSLabel
= gbl_ItdmMPLSLabel
;
465 dissector_add_uint("mpls.label", gbl_ItdmMPLSLabel
, itdm_handle
);
469 * Editor modelines - https://www.wireshark.org/tools/modelines.html
474 * indent-tabs-mode: nil
477 * ex: set shiftwidth=2 tabstop=8 expandtab:
478 * :indentSize=2:tabSize=8:noTabs=true: