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 void proto_register_itdm(void);
20 void proto_reg_handoff_itdm(void);
22 /* Initialize the protocol and registered fields */
23 static int proto_itdm = -1;
24 static int hf_itdm_timestamp = -1;
25 static int hf_itdm_seqnum = -1;
26 static int hf_itdm_sop_eop = -1;
27 static int hf_itdm_last_pack = -1;
28 static int hf_itdm_pktlen = -1;
29 static int hf_itdm_chksum = -1;
30 static int hf_itdm_uid = -1;
31 static int hf_itdm_ack = -1;
32 static int hf_itdm_act = -1;
33 static int hf_itdm_chcmd = -1;
34 static int hf_itdm_chid = -1;
35 static int hf_itdm_chloc1 = -1;
36 static int hf_itdm_chloc2 = -1;
37 static int hf_itdm_pktrate = -1;
38 static int hf_itdm_cxnsize = -1;
40 /* I-TDM control protocol fields */
41 static int hf_itdm_ctl_transid = -1;
42 static int hf_itdm_ctl_command = -1;
43 static int hf_itdm_ctl_flowid = -1;
44 static int hf_itdm_ctl_dm = -1;
45 static int hf_itdm_ctl_emts = -1;
46 static int hf_itdm_ctl_pktrate = -1;
47 static int hf_itdm_ctl_ptid = -1;
48 static int hf_itdm_ctl_cksum = -1;
51 /* Initialize the subtree pointers */
52 static gint ett_itdm = -1;
53 static gint ett_itdm_ctl = -1;
55 static dissector_handle_t itdm_handle;
57 /* ZZZZ some magic number.. */
58 static guint gbl_ItdmMPLSLabel = 0x99887;
59 static guint gbl_ItdmCTLFlowNo = 0;
61 /* I-TDM 125usec mode commands for data flows */
62 #define ITDM_CMD_NEW_CHAN 1
63 #define ITDM_CMD_CLOSE_CHAN 2
64 #define ITDM_CMD_RELOC_CHAN 3
65 #define ITDM_CMD_CYCLIC_REAF 4
66 #define ITDM_CMD_PACKET_RATE 5
68 #define ITDM_FLOWID_OFFSET 7
69 #define ITDM_CHCMD_OFFSET 10
70 #define ITDM_CHANID_OFFSET 11
71 #define ITDM_CHLOC1_OFFSET 14
72 #define ITDM_CHLOC2_OFFSET 16
74 /* I-TDM commands for I-TDM control flows */
75 #define ITDM_CTL_TRANSID_OFFSET 10
76 #define ITDM_CTL_CMD_OFFSET 14
77 #define ITDM_CTL_FLOWID_OFFSET 15
78 #define ITDM_CTL_ITDM_MODE_OFFSET 18
79 #define ITDM_CTL_EMTS_OFFSET 20
80 #define ITDM_CTL_PKTRATE_OFFSET 22
81 #define ITDM_CTL_PAIRED_TRANSID_OFFSET 26
82 #define ITDM_CTL_CRC_OFFSET 30
84 #define ITDM_CTL_CMD_AFI_REQ 1
86 static const value_string sop_eop_vals[] = {
87 { 0x0, "Middle of Packet" },
88 { 0x1, "End of Packet" },
89 { 0x2, "Start of Packet" },
90 { 0x3, "Complete Packet" },
94 static const true_false_string ack_tfs = {
95 "Acknowledging a command from remote node",
99 static const value_string chcmd_vals[] = {
101 { 0x1, "New Channel ID" },
102 { 0x2, "Close Channel ID" },
103 { 0x3, "Relocate Channel ID" },
104 { 0x4, "Cyclic Reaffirmation" },
105 { 0x5, "Packet Rate Integrity Check" },
119 static const value_string itdm_ctl_command_vals[] = {
121 { 0x1, "AFI_REQ: Alloc Flow ID Req" },
122 { 0x2, "AFI_RSP: Alloc Flow ID Rsp - Req Accepted." },
123 { 0x3, "DFI_REQ: Dealloc Flow ID Req" },
124 { 0x4, "DFI_RSP: Dealloc Flow ID Rsp - Req Accepted." },
126 { 0x10, "AFI_RSP: Reject: Data Mode Field value Not Supported." },
127 { 0x11, "AFI_RSP: Reject: Explicit Multi-timeslot value Not Supported." },
128 { 0x12, "AFI_RSP: Reject: Packet Rate value Not Supported." },
129 { 0x13, "AFI_RSP: Reject: Checksum Invalid." },
130 { 0x14, "AFI_RSP: Reject: No more flows available." },
132 { 0x20, "DFI_RSP: Reject: Data Mode Field value does not match Flow ID." },
133 { 0x21, "DFI_RSP: Reject: Explicit Multi-timeslots value does not match." },
134 { 0x22, "DFI_RSP: Reject: Packet Rate value does not match." },
135 { 0x23, "DFI_RSP: Reject: Checksum Invalid." },
136 { 0x24, "DFI_RSP: Reject: Flow ID invalid (out of range)." },
137 { 0x25, "DFI_RSP: Reject: Flow ID not currently allocated." },
138 { 0x26, "DFI_RSP: Reject: Other Flow ID in pair has active connections." },
142 static const value_string itdm_ctl_data_mode_vals[] = {
144 { 1, "I-TDM 1ms Data Mode." },
145 { 2, "I-TDM 125usec Data Mode." },
146 { 3, "I-TDM Explicit Multi-timeslot Data Mode." },
147 { 4, "I-TDM CAS Signaling Data Mode." },
151 static const value_string itdm_ctl_pktrate_vals[] = {
152 { 0x447A0000, "I-TDM 1ms Data Mode." },
153 { 0x45FA0000, "I-TDM 125usec/EMTS Data Mode." },
154 { 0x43A6AAAB, "I-TDM T1 CAS Mode." },
155 { 0x43FA0000, "I-TDM E1 CAS Mode." },
160 dissect_itdm_125usec(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
163 proto_item *itdm_item = NULL;
164 proto_tree *itdm_tree = NULL;
175 col_set_str(pinfo->cinfo, COL_PROTOCOL, "ITDM");
177 flowid = tvb_get_ntoh24(tvb, ITDM_FLOWID_OFFSET);
178 chanid = tvb_get_ntoh24(tvb, ITDM_CHANID_OFFSET);
179 chcmd = tvb_get_guint8(tvb, ITDM_CHCMD_OFFSET);
180 chloc1 = tvb_get_ntohs(tvb, ITDM_CHLOC1_OFFSET);
181 actbit = (chcmd & 0x10) ? 1 : 0;
182 ackbit = (chcmd & 0x20) ? 1 : 0;
183 chcmd = chcmd & 0x0f;
185 col_add_fstr(pinfo->cinfo, COL_INFO,
186 "Flow %d Chan %d ACT %d ACK %d %s",
187 flowid, chanid, actbit, ackbit,
188 val_to_str_const(chcmd, chcmd_vals, "Reserved"));
189 if (chcmd == ITDM_CMD_NEW_CHAN ||
190 chcmd == ITDM_CMD_CLOSE_CHAN ||
191 chcmd == ITDM_CMD_CYCLIC_REAF)
193 col_append_fstr(pinfo->cinfo, COL_INFO,
196 else if (chcmd == ITDM_CMD_RELOC_CHAN)
198 chloc2 = tvb_get_ntohs(tvb, ITDM_CHLOC2_OFFSET);
199 col_append_fstr(pinfo->cinfo, COL_INFO,
200 " Loc1 %d Loc2 %d", chloc1, chloc2);
207 itdm_item = proto_tree_add_item(tree, proto_itdm, tvb, 0, -1, ENC_NA);
208 itdm_tree = proto_item_add_subtree(itdm_item, ett_itdm);
210 proto_tree_add_item(itdm_tree, hf_itdm_timestamp, tvb, offset, 2, ENC_BIG_ENDIAN);
212 proto_tree_add_item(itdm_tree, hf_itdm_seqnum, tvb, offset, 1, ENC_BIG_ENDIAN);
214 proto_tree_add_item(itdm_tree, hf_itdm_sop_eop, tvb, offset, 1, ENC_BIG_ENDIAN);
215 proto_tree_add_item(itdm_tree, hf_itdm_last_pack, tvb, offset, 1, ENC_BIG_ENDIAN);
216 proto_tree_add_item(itdm_tree, hf_itdm_pktlen, tvb, offset, 2, ENC_BIG_ENDIAN);
218 proto_tree_add_checksum(itdm_tree, tvb, offset, hf_itdm_chksum, -1, NULL, pinfo, 0, ENC_BIG_ENDIAN, PROTO_CHECKSUM_NO_FLAGS);
220 proto_tree_add_item(itdm_tree, hf_itdm_uid, tvb, offset, 3, ENC_BIG_ENDIAN);
222 proto_tree_add_item(itdm_tree, hf_itdm_ack, tvb, offset, 1, ENC_BIG_ENDIAN);
223 proto_tree_add_item(itdm_tree, hf_itdm_act, tvb, offset, 1, ENC_BIG_ENDIAN);
224 proto_tree_add_item(itdm_tree, hf_itdm_chcmd, tvb, offset, 1, ENC_BIG_ENDIAN);
226 proto_tree_add_item(itdm_tree, hf_itdm_chid, tvb, offset, 3, ENC_BIG_ENDIAN);
228 if (chcmd == ITDM_CMD_PACKET_RATE)
230 proto_tree_add_item(itdm_tree, hf_itdm_pktrate, tvb, offset, 4, ENC_BIG_ENDIAN);
235 proto_tree_add_item(itdm_tree, hf_itdm_chloc1, tvb, offset, 2, ENC_BIG_ENDIAN);
237 if (chcmd == ITDM_CMD_CYCLIC_REAF ||
238 chcmd == ITDM_CMD_NEW_CHAN ||
239 chcmd == ITDM_CMD_CLOSE_CHAN)
241 proto_tree_add_item(itdm_tree, hf_itdm_cxnsize, tvb, offset, 2, ENC_BIG_ENDIAN);
246 proto_tree_add_item(itdm_tree, hf_itdm_chloc2, tvb, offset, 2, ENC_BIG_ENDIAN);
252 next_tvb = tvb_new_subset_remaining(tvb, offset);
253 call_data_dissector(next_tvb, pinfo, tree);
257 dissect_itdm_control(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
260 proto_item *itdm_ctl_item = NULL;
261 proto_tree *itdm_ctl_tree = NULL;
266 guint32 paired_trans_id;
267 guint32 allocd_flowid;
269 col_set_str(pinfo->cinfo, COL_PROTOCOL, "ITDM-Control");
271 flowid = tvb_get_ntoh24(tvb, ITDM_FLOWID_OFFSET);
272 command = tvb_get_guint8(tvb, ITDM_CTL_CMD_OFFSET);
273 allocd_flowid = tvb_get_ntoh24(tvb, ITDM_CTL_FLOWID_OFFSET);
274 trans_id = tvb_get_ntohl(tvb, ITDM_CTL_TRANSID_OFFSET);
275 paired_trans_id = tvb_get_ntohl(tvb, ITDM_CTL_PAIRED_TRANSID_OFFSET);
277 col_add_fstr(pinfo->cinfo, COL_INFO,
278 "Flow %d Command %s ",
279 flowid, val_to_str_const(command, itdm_ctl_command_vals, "Reserved"));
281 if (command != ITDM_CTL_CMD_AFI_REQ )
283 col_append_fstr(pinfo->cinfo, COL_INFO,
284 " Alloc'd FlowID %d", allocd_flowid);
287 col_append_fstr(pinfo->cinfo, COL_INFO, " TransID 0x%x ", trans_id);
289 if (command != ITDM_CTL_CMD_AFI_REQ )
291 col_append_fstr(pinfo->cinfo, COL_INFO,
292 " Paired TransID 0x%x", paired_trans_id);
299 itdm_ctl_item = proto_tree_add_item(tree, proto_itdm, tvb, 0, -1, ENC_NA);
300 itdm_ctl_tree = proto_item_add_subtree(itdm_ctl_item, ett_itdm_ctl);
302 /* These eventually should go into a SFP.0 dissector... */
303 proto_tree_add_item(itdm_ctl_tree, hf_itdm_timestamp, tvb, offset, 2, ENC_BIG_ENDIAN);
305 proto_tree_add_item(itdm_ctl_tree, hf_itdm_seqnum, tvb, offset, 1, ENC_BIG_ENDIAN);
307 proto_tree_add_item(itdm_ctl_tree, hf_itdm_sop_eop, tvb, offset, 1, ENC_BIG_ENDIAN);
308 proto_tree_add_item(itdm_ctl_tree, hf_itdm_last_pack, tvb, offset, 1, ENC_BIG_ENDIAN);
309 proto_tree_add_item(itdm_ctl_tree, hf_itdm_pktlen, tvb, offset, 2, ENC_BIG_ENDIAN);
311 proto_tree_add_checksum(itdm_ctl_tree, tvb, offset, hf_itdm_chksum, -1, NULL, pinfo, 0, ENC_BIG_ENDIAN, PROTO_CHECKSUM_NO_FLAGS);
313 proto_tree_add_item(itdm_ctl_tree, hf_itdm_uid, tvb, offset, 3, ENC_BIG_ENDIAN);
316 proto_tree_add_item(itdm_ctl_tree, hf_itdm_ctl_transid, tvb, offset, 4, ENC_BIG_ENDIAN);
319 proto_tree_add_item(itdm_ctl_tree, hf_itdm_ctl_command, tvb, offset, 1, ENC_BIG_ENDIAN);
321 if (command != ITDM_CTL_CMD_AFI_REQ) {
322 proto_tree_add_item(itdm_ctl_tree, hf_itdm_ctl_flowid, tvb, offset, 3, ENC_BIG_ENDIAN);
325 proto_tree_add_item(itdm_ctl_tree, hf_itdm_ctl_dm, tvb, offset, 1, ENC_BIG_ENDIAN);
329 proto_tree_add_item(itdm_ctl_tree, hf_itdm_ctl_emts, tvb, offset, 2, ENC_BIG_ENDIAN);
331 proto_tree_add_item(itdm_ctl_tree, hf_itdm_ctl_pktrate, tvb, offset, 4, ENC_BIG_ENDIAN);
333 if (command != ITDM_CTL_CMD_AFI_REQ) {
334 proto_tree_add_item(itdm_ctl_tree, hf_itdm_ctl_ptid, tvb, offset, 4, ENC_BIG_ENDIAN);
339 proto_tree_add_item(itdm_ctl_tree, hf_itdm_ctl_cksum, tvb, offset, 2, ENC_BIG_ENDIAN);
343 next_tvb = tvb_new_subset_remaining(tvb, offset);
344 call_data_dissector(next_tvb, pinfo, tree);
348 dissect_itdm(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
352 /* ZZZ for now, 125 usec mode and I-TDM control protocol
353 * need to add 1ms mode */
354 if (tvb_captured_length(tvb) < 18)
357 /* See if this packet is a data flow or the I-TDM control flow. */
358 flowid = tvb_get_ntoh24(tvb, ITDM_FLOWID_OFFSET);
360 /* gbl_ItdmCTLFlowNo is the configurable flow number where
361 * the control protocol resides... Usually 0.
363 if (flowid == gbl_ItdmCTLFlowNo)
364 dissect_itdm_control(tvb, pinfo, tree);
366 dissect_itdm_125usec(tvb, pinfo, tree);
367 return tvb_captured_length(tvb);
371 proto_register_itdm(void)
374 static hf_register_info hf[] = {
375 { &hf_itdm_timestamp,{ "Timestamp", "itdm.timestamp",
376 FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } },
377 { &hf_itdm_seqnum,{ "Sequence Number", "itdm.seqnum",
378 FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL } },
379 { &hf_itdm_sop_eop,{ "Start/End of Packet", "itdm.sop_eop",
380 FT_UINT8, BASE_DEC, VALS(sop_eop_vals), 0xc0, NULL, HFILL } },
381 { &hf_itdm_last_pack,{ "Last Packet", "itdm.last_pack",
382 FT_BOOLEAN, 8, TFS(&tfs_true_false), 0x20, NULL, HFILL } },
383 { &hf_itdm_pktlen,{ "Packet Length", "itdm.pktlen",
384 FT_UINT16, BASE_DEC, NULL, 0x07ff, NULL, HFILL } },
385 { &hf_itdm_chksum,{ "Checksum", "itdm.chksum",
386 FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL } },
387 { &hf_itdm_uid,{ "Flow ID", "itdm.uid",
388 FT_UINT24, BASE_DEC, NULL, 0x0, NULL, HFILL } },
389 { &hf_itdm_ack,{ "ACK", "itdm.ack",
390 FT_BOOLEAN, 8, TFS(&ack_tfs), 0x20, NULL, HFILL } },
391 { &hf_itdm_act,{ "Activate", "itdm.act",
392 FT_BOOLEAN, 8, TFS(&tfs_true_false), 0x10, NULL, HFILL } },
393 { &hf_itdm_chcmd,{ "Channel Command", "itdm.chcmd",
394 FT_UINT8, BASE_DEC, VALS(chcmd_vals), 0x0f, NULL, HFILL } },
395 { &hf_itdm_chid,{ "Channel ID", "itdm.chid",
396 FT_UINT24, BASE_DEC, NULL, 0x0, NULL, HFILL } },
397 { &hf_itdm_chloc1,{ "Channel Location 1", "itdm.chloc1",
398 FT_UINT16, BASE_DEC, NULL, 0x1ff, NULL, HFILL } },
399 { &hf_itdm_chloc2,{ "Channel Location 2", "itdm.chloc2",
400 FT_UINT16, BASE_DEC, NULL, 0x1ff, NULL, HFILL } },
401 { &hf_itdm_pktrate,{ "IEEE 754 Packet Rate", "itdm.pktrate",
402 FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL } },
403 { &hf_itdm_cxnsize, { "Connection Size", "itdm.cxnsize",
404 FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } },
406 { &hf_itdm_ctl_transid, { "Transaction ID", "itdm.ctl_transid",
407 FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL } },
408 { &hf_itdm_ctl_command, { "Control Command", "itdm.ctl_cmd",
409 FT_UINT8, BASE_DEC, VALS(itdm_ctl_command_vals), 0x0, NULL, HFILL } },
410 { &hf_itdm_ctl_flowid, { "Allocated Flow ID", "itdm.ctl_flowid",
411 FT_UINT24, BASE_DEC, NULL, 0x0, NULL, HFILL } },
412 { &hf_itdm_ctl_dm, { "I-TDM Data Mode", "itdm.ctl_dm",
413 FT_UINT8, BASE_DEC, VALS(itdm_ctl_data_mode_vals), 0x0, NULL, HFILL } },
414 { &hf_itdm_ctl_emts, { "I-TDM Explicit Multi-timeslot Size", "itdm.ctlemts",
415 FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } },
416 { &hf_itdm_ctl_pktrate, { "I-TDM Packet Rate", "itdm.ctl_pktrate",
417 FT_UINT32, BASE_HEX, VALS(itdm_ctl_pktrate_vals), 0x0, NULL, HFILL } },
418 { &hf_itdm_ctl_ptid, { "Paired Transaction ID", "itdm.ctl_ptid",
419 FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL } },
420 { &hf_itdm_ctl_cksum, { "ITDM Control Message Checksum", "itdm.ctl_cksum",
421 FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL } }
424 static gint *ett[] = {
429 module_t *itdm_module;
431 proto_itdm = proto_register_protocol("Internal TDM", "ITDM", "itdm");
432 itdm_handle = register_dissector("itdm", dissect_itdm, proto_itdm);
434 proto_register_field_array(proto_itdm, hf, array_length(hf));
435 proto_register_subtree_array(ett, array_length(ett));
437 itdm_module = prefs_register_protocol(proto_itdm, proto_reg_handoff_itdm);
439 prefs_register_uint_preference(itdm_module, "mpls_label",
440 "ITDM MPLS label (Flow Bundle ID in hex)",
441 "The MPLS label (aka Flow Bundle ID) used by ITDM traffic.",
442 16, &gbl_ItdmMPLSLabel);
444 prefs_register_uint_preference(itdm_module, "ctl_flowno",
445 "I-TDM Control Protocol Flow Number",
446 "Flow Number used by I-TDM Control Protocol traffic.",
447 10, &gbl_ItdmCTLFlowNo);
451 proto_reg_handoff_itdm(void)
453 static gboolean Initialized=FALSE;
454 static guint ItdmMPLSLabel;
459 dissector_delete_uint("mpls.label", ItdmMPLSLabel, itdm_handle);
462 ItdmMPLSLabel = gbl_ItdmMPLSLabel;
463 dissector_add_uint("mpls.label", gbl_ItdmMPLSLabel, itdm_handle);
467 * Editor modelines - http://www.wireshark.org/tools/modelines.html
472 * indent-tabs-mode: nil
475 * ex: set shiftwidth=2 tabstop=8 expandtab:
476 * :indentSize=2:tabSize=8:noTabs=true: