3 * Routines for Amateur Packet Radio protocol dissection
4 * NET/ROM inter-node frames.
5 * Copyright 2005,2006,2007,2008,2009,2010,2012 R.W. Stearn <richard@rns-stearn.demon.co.uk>
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
15 * Information on the protocol drawn from:
17 * Protocol specification is at:
19 * ftp://ftp.ucsd.edu/hamradio/packet/tcpip/docs/netrom.ps.gz
21 * (yes, it's PostScript, and, yes, it's an FTP URL).
23 * Inspiration on how to build the dissector drawn from
29 * with the base file built from README.developers.
34 #include <epan/packet.h>
35 #include <epan/to_str.h>
36 #include <epan/capture_dissectors.h>
37 #include <epan/ax25_pids.h>
39 #include <wsutil/array.h>
41 void proto_register_netrom(void);
42 void proto_reg_handoff_netrom(void);
46 #define NETROM_MIN_SIZE 7 /* minimum payload for a routing packet */
47 #define NETROM_HEADER_SIZE 20 /* minimum payload for a normal packet */
49 #define NETROM_PROTOEXT 0x00
50 #define NETROM_CONNREQ 0x01
51 #define NETROM_CONNACK 0x02
52 #define NETROM_DISCREQ 0x03
53 #define NETROM_DISCACK 0x04
54 #define NETROM_INFO 0x05
55 #define NETROM_INFOACK 0x06
57 #define NETROM_MORE_FLAG 0x20
58 #define NETROM_NAK_FLAG 0x40
59 #define NETROM_CHOKE_FLAG 0x80
61 #define NETROM_PROTO_IP 0x0C
63 /* Dissector handles */
64 static dissector_handle_t ip_handle
;
66 /* Initialize the protocol and registered fields */
67 static int proto_netrom
;
68 static int hf_netrom_src
;
69 static int hf_netrom_dst
;
70 static int hf_netrom_ttl
;
71 static int hf_netrom_my_cct_index
;
72 static int hf_netrom_my_cct_id
;
73 static int hf_netrom_your_cct_index
;
74 static int hf_netrom_your_cct_id
;
75 static int hf_netrom_n_r
;
76 static int hf_netrom_n_s
;
77 static int hf_netrom_type
;
78 static int hf_netrom_op
;
79 static int hf_netrom_more
;
80 static int hf_netrom_nak
;
81 static int hf_netrom_choke
;
83 static int hf_netrom_user
;
84 static int hf_netrom_node
;
85 static int hf_netrom_pwindow
;
86 static int hf_netrom_awindow
;
88 static int hf_netrom_mnemonic
;
91 * Structure containing pointers to hf_ values for various subfields of
101 static const netrom_tf_items netrom_type_items
= {
109 static const value_string op_code_vals_abbrev
[] = {
110 { NETROM_PROTOEXT
, "PROTOEXT"},
111 { NETROM_CONNREQ
, "CONNREQ"},
112 { NETROM_CONNACK
, "CONNACK"},
113 { NETROM_DISCREQ
, "DISCREQ"},
114 { NETROM_DISCACK
, "DISCACK"},
115 { NETROM_INFO
, "INFO"},
116 { NETROM_INFOACK
, "INFOACK"},
120 static const value_string op_code_vals_text
[] = {
121 { NETROM_PROTOEXT
, "Protocol extension"},
122 { NETROM_CONNREQ
, "Connect request"},
123 { NETROM_CONNACK
, "Connect acknowledge"},
124 { NETROM_DISCREQ
, "Disconnect request"},
125 { NETROM_DISCACK
, "Disconnect acknowledge"},
126 { NETROM_INFO
, "Information"},
127 { NETROM_INFOACK
, "Information acknowledge"},
131 /* Initialize the subtree pointers */
132 static int ett_netrom
;
133 static int ett_netrom_type
;
136 dissect_netrom_type(tvbuff_t
*tvb
, int offset
, packet_info
*pinfo
, proto_tree
*tree
,
137 int hf_netrom_type_param
, int ett_netrom_type_param
, const netrom_tf_items
*type_items
)
140 proto_tree
*type_tree
;
145 type
= tvb_get_uint8( tvb
, offset
);
146 op_code
= type
&0x0f;
148 info_buffer
= wmem_strdup_printf( pinfo
->pool
, "%s%s%s%s (0x%02x)",
149 val_to_str_const( op_code
, op_code_vals_text
, "Unknown" ),
150 ( type
& NETROM_MORE_FLAG
) ? ", More" : "",
151 ( type
& NETROM_NAK_FLAG
) ? ", NAK" : "",
152 ( type
& NETROM_CHOKE_FLAG
) ? ", Choke" : "",
154 col_add_str( pinfo
->cinfo
, COL_INFO
, info_buffer
);
158 tc
= proto_tree_add_uint_format( tree
,
159 hf_netrom_type_param
,
167 type_tree
= proto_item_add_subtree( tc
, ett_netrom_type_param
);
169 proto_tree_add_item( type_tree
, *type_items
->hf_tf_op
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
170 proto_tree_add_item( type_tree
, *type_items
->hf_tf_choke
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
171 proto_tree_add_item( type_tree
, *type_items
->hf_tf_nak
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
172 proto_tree_add_item( type_tree
, *type_items
->hf_tf_more
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
177 dissect_netrom_proto(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
)
180 proto_tree
*netrom_tree
;
191 col_set_str( pinfo
->cinfo
, COL_PROTOCOL
, "NET/ROM" );
192 col_clear( pinfo
->cinfo
, COL_INFO
);
197 set_address_tvb(&pinfo
->dl_src
, AT_AX25
, AX25_ADDR_LEN
, tvb
, offset
);
198 set_address_tvb(&pinfo
->src
, AT_AX25
, AX25_ADDR_LEN
, tvb
, offset
);
199 /* src_ssid = tvb_get_uint8(tvb, offset+6); */
200 offset
+= AX25_ADDR_LEN
; /* step over src addr */
203 set_address_tvb(&pinfo
->dl_dst
, AT_AX25
, AX25_ADDR_LEN
, tvb
, offset
);
204 set_address_tvb(&pinfo
->dst
, AT_AX25
, AX25_ADDR_LEN
, tvb
, offset
);
205 /* dst_ssid = tvb_get_uint8(tvb, offset+6); */
206 offset
+= AX25_ADDR_LEN
; /* step over dst addr */
208 offset
+= 1; /* step over ttl */
209 cct_index
= tvb_get_uint8( tvb
, offset
);
210 offset
+= 1; /* step over cct index*/
211 cct_id
= tvb_get_uint8( tvb
, offset
);
212 offset
+= 1; /* step over cct id */
213 offset
+= 1; /* step over n_s */
214 offset
+= 1; /* step over n_r */
217 op_code
= tvb_get_uint8( tvb
, offset
) & 0x0f;
218 /*offset += 1;*/ /* step over op_code */
220 col_set_str( pinfo
->cinfo
, COL_INFO
, val_to_str_const( op_code
, op_code_vals_text
, "Unknown" ));
224 /* create display subtree for the protocol */
226 ti
= proto_tree_add_protocol_format( tree
, proto_netrom
, tvb
, 0, NETROM_HEADER_SIZE
,
227 "NET/ROM, Src: %s, Dst: %s",
228 address_to_str(pinfo
->pool
, &pinfo
->src
),
229 address_to_str(pinfo
->pool
, &pinfo
->dst
));
231 netrom_tree
= proto_item_add_subtree( ti
, ett_netrom
);
236 proto_tree_add_item( netrom_tree
, hf_netrom_src
, tvb
, offset
, AX25_ADDR_LEN
, ENC_NA
);
237 offset
+= AX25_ADDR_LEN
;
240 proto_tree_add_item( netrom_tree
, hf_netrom_dst
, tvb
, offset
, AX25_ADDR_LEN
, ENC_NA
);
241 offset
+= AX25_ADDR_LEN
;
244 proto_tree_add_item( netrom_tree
, hf_netrom_ttl
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
249 case NETROM_PROTOEXT
:
251 proto_tree_add_item( netrom_tree
, hf_netrom_my_cct_index
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
255 proto_tree_add_item( netrom_tree
, hf_netrom_my_cct_id
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
264 case NETROM_CONNREQ
:
266 proto_tree_add_item( netrom_tree
, hf_netrom_my_cct_index
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
270 proto_tree_add_item( netrom_tree
, hf_netrom_my_cct_id
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
280 case NETROM_CONNACK
:
282 proto_tree_add_item( netrom_tree
, hf_netrom_your_cct_index
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
286 proto_tree_add_item( netrom_tree
, hf_netrom_your_cct_id
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
290 proto_tree_add_item( netrom_tree
, hf_netrom_my_cct_index
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
294 proto_tree_add_item( netrom_tree
, hf_netrom_my_cct_id
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
298 case NETROM_DISCREQ
:
300 proto_tree_add_item( netrom_tree
, hf_netrom_your_cct_index
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
304 proto_tree_add_item( netrom_tree
, hf_netrom_your_cct_id
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
314 case NETROM_DISCACK
:
316 proto_tree_add_item( netrom_tree
, hf_netrom_your_cct_index
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
320 proto_tree_add_item( netrom_tree
, hf_netrom_your_cct_id
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
332 proto_tree_add_item( netrom_tree
, hf_netrom_your_cct_index
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
336 proto_tree_add_item( netrom_tree
, hf_netrom_your_cct_id
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
340 proto_tree_add_item( netrom_tree
, hf_netrom_n_s
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
344 proto_tree_add_item( netrom_tree
, hf_netrom_n_r
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
348 case NETROM_INFOACK
:
350 proto_tree_add_item( netrom_tree
, hf_netrom_your_cct_index
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
354 proto_tree_add_item( netrom_tree
, hf_netrom_your_cct_id
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
361 proto_tree_add_item( netrom_tree
, hf_netrom_n_r
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
375 dissect_netrom_type( tvb
,
387 case NETROM_PROTOEXT
:
389 case NETROM_CONNREQ
:
390 /* proposed window size */
391 proto_tree_add_item( netrom_tree
, hf_netrom_pwindow
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
394 proto_tree_add_item( netrom_tree
, hf_netrom_user
, tvb
, offset
, AX25_ADDR_LEN
, ENC_NA
);
395 offset
+= AX25_ADDR_LEN
;
397 proto_tree_add_item( netrom_tree
, hf_netrom_node
, tvb
, offset
, AX25_ADDR_LEN
, ENC_NA
);
398 offset
+= AX25_ADDR_LEN
;
401 case NETROM_CONNACK
:
402 /* accepted window size */
403 proto_tree_add_item( netrom_tree
, hf_netrom_awindow
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
407 case NETROM_DISCREQ
:
409 case NETROM_DISCACK
:
413 case NETROM_INFOACK
:
420 /* Call sub-dissectors here */
422 next_tvb
= tvb_new_subset_remaining(tvb
, offset
);
426 case NETROM_PROTOEXT
:
427 if ( cct_index
== NETROM_PROTO_IP
&& cct_id
== NETROM_PROTO_IP
)
428 call_dissector( ip_handle
, next_tvb
, pinfo
, tree
);
430 call_data_dissector(next_tvb
, pinfo
, tree
);
435 call_data_dissector(next_tvb
, pinfo
, tree
);
441 dissect_netrom_routing(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
)
444 const uint8_t* mnemonic
;
447 col_set_str( pinfo
->cinfo
, COL_PROTOCOL
, "NET/ROM");
448 col_set_str( pinfo
->cinfo
, COL_INFO
, "routing table frame");
453 proto_tree
*netrom_tree
;
454 ti
= proto_tree_add_item( tree
, proto_netrom
, tvb
, 0, -1, ENC_NA
);
455 netrom_tree
= proto_item_add_subtree( ti
, ett_netrom
);
457 proto_tree_add_item_ret_string_and_length(netrom_tree
, hf_netrom_mnemonic
, tvb
, 1, 6, ENC_ASCII
|ENC_NA
,
458 pinfo
->pool
, &mnemonic
, &mnemonic_len
);
459 proto_item_append_text(ti
, ", routing table frame, Node: %s", mnemonic
);
462 next_tvb
= tvb_new_subset_remaining(tvb
, 7);
464 call_data_dissector(next_tvb
, pinfo
, tree
);
467 /* Code to actually dissect the packets */
469 dissect_netrom(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void* data _U_
)
471 if ( tvb_get_uint8( tvb
, 0 ) == 0xff )
472 dissect_netrom_routing( tvb
, pinfo
, tree
);
474 dissect_netrom_proto( tvb
, pinfo
, tree
);
476 return tvb_captured_length(tvb
);
480 capture_netrom( const unsigned char *pd _U_
, int offset
, int len
, capture_packet_info_t
*cpinfo _U_
, const union wtap_pseudo_header
*pseudo_header _U_
)
482 if ( ! BYTES_ARE_IN_FRAME( offset
, len
, NETROM_MIN_SIZE
) )
485 /* XXX - check for IP-over-NetROM here! */
490 proto_register_netrom(void)
492 /* Setup list of header fields */
493 static hf_register_info hf
[] = {
495 { "Source", "netrom.src",
496 FT_AX25
, BASE_NONE
, NULL
, 0x0,
497 "Source callsign", HFILL
}
500 { "Destination", "netrom.dst",
501 FT_AX25
, BASE_NONE
, NULL
, 0x0,
502 "Destination callsign", HFILL
}
505 { "TTL", "netrom.ttl",
506 FT_UINT8
, BASE_HEX
, NULL
, 0x0,
509 { &hf_netrom_my_cct_index
,
510 { "My circuit index", "netrom.my.cct.index",
511 FT_UINT8
, BASE_HEX
, NULL
, 0x0,
514 { &hf_netrom_my_cct_id
,
515 { "My circuit ID", "netrom.my.cct.id",
516 FT_UINT8
, BASE_HEX
, NULL
, 0x0,
519 { &hf_netrom_your_cct_index
,
520 { "Your circuit index", "netrom.your.cct.index",
521 FT_UINT8
, BASE_HEX
, NULL
, 0x0,
524 { &hf_netrom_your_cct_id
,
525 { "Your circuit ID", "netrom.your.cct.id",
526 FT_UINT8
, BASE_HEX
, NULL
, 0x0,
530 { "N(r)", "netrom.n_r",
531 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
535 { "N(s)", "netrom.n_s",
536 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
540 { "Type", "netrom.type",
541 FT_UINT8
, BASE_HEX
, NULL
, 0x0,
542 "Packet type field", HFILL
}
545 { "OP code", "netrom.op",
546 FT_UINT8
, BASE_HEX
, VALS( op_code_vals_abbrev
), 0x0f,
547 "Protocol operation code", HFILL
}
550 { "More", "netrom.flag.more",
551 FT_BOOLEAN
, 8, TFS(&tfs_set_notset
), NETROM_MORE_FLAG
,
555 { "NAK", "netrom.flag.nak",
556 FT_BOOLEAN
, 8, TFS(&tfs_set_notset
), NETROM_NAK_FLAG
,
560 { "Choke", "netrom.flag.choke",
561 FT_BOOLEAN
, 8, TFS(&tfs_set_notset
), NETROM_CHOKE_FLAG
,
562 "Choke flag", HFILL
}
565 { "User", "netrom.user",
566 FT_AX25
, BASE_NONE
, NULL
, 0x0,
567 "User callsign", HFILL
}
570 { "Node", "netrom.node",
571 FT_AX25
, BASE_NONE
, NULL
, 0x0,
572 "Node callsign", HFILL
}
574 { &hf_netrom_pwindow
,
575 { "Window", "netrom.pwindow",
576 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
577 "Proposed window", HFILL
}
579 { &hf_netrom_awindow
,
580 { "Window", "netrom.awindow",
581 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
582 "Accepted window", HFILL
}
584 { &hf_netrom_mnemonic
,
585 { "Node name", "netrom.name",
586 FT_STRING
, BASE_NONE
, NULL
, 0x0,
591 /* Setup protocol subtree array */
592 static int *ett
[] = {
597 /* Register the protocol name and description */
598 proto_netrom
= proto_register_protocol( "Amateur Radio NET/ROM", "NET/ROM", "netrom" );
600 /* Required function calls to register the header fields and subtrees used */
601 proto_register_field_array( proto_netrom
, hf
, array_length(hf
) );
602 proto_register_subtree_array( ett
, array_length( ett
) );
606 proto_reg_handoff_netrom(void)
608 capture_dissector_handle_t netrom_cap_handle
;
610 dissector_add_uint( "ax25.pid", AX25_P_NETROM
, create_dissector_handle( dissect_netrom
, proto_netrom
) );
611 netrom_cap_handle
= create_capture_dissector_handle(capture_netrom
, proto_netrom
);
612 capture_dissector_add_uint("ax25.pid", AX25_P_NETROM
, netrom_cap_handle
);
614 ip_handle
= find_dissector_add_dependency( "ip", proto_netrom
);
618 * Editor modelines - https://www.wireshark.org/tools/modelines.html
623 * indent-tabs-mode: t
626 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
627 * :indentSize=8:tabSize=8:noTabs=false: