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 void proto_register_netrom(void);
40 void proto_reg_handoff_netrom(void);
44 #define NETROM_MIN_SIZE 7 /* minimum payload for a routing packet */
45 #define NETROM_HEADER_SIZE 20 /* minimum payload for a normal packet */
47 #define NETROM_PROTOEXT 0x00
48 #define NETROM_CONNREQ 0x01
49 #define NETROM_CONNACK 0x02
50 #define NETROM_DISCREQ 0x03
51 #define NETROM_DISCACK 0x04
52 #define NETROM_INFO 0x05
53 #define NETROM_INFOACK 0x06
55 #define NETROM_MORE_FLAG 0x20
56 #define NETROM_NAK_FLAG 0x40
57 #define NETROM_CHOKE_FLAG 0x80
59 #define NETROM_PROTO_IP 0x0C
61 /* Dissector handles */
62 static dissector_handle_t ip_handle;
64 /* Initialize the protocol and registered fields */
65 static int proto_netrom = -1;
66 static int hf_netrom_src = -1;
67 static int hf_netrom_dst = -1;
68 static int hf_netrom_ttl = -1;
69 static int hf_netrom_my_cct_index = -1;
70 static int hf_netrom_my_cct_id = -1;
71 static int hf_netrom_your_cct_index = -1;
72 static int hf_netrom_your_cct_id = -1;
73 static int hf_netrom_n_r = -1;
74 static int hf_netrom_n_s = -1;
75 static int hf_netrom_type = -1;
76 static int hf_netrom_op = -1;
77 static int hf_netrom_more = -1;
78 static int hf_netrom_nak = -1;
79 static int hf_netrom_choke = -1;
81 static int hf_netrom_user = -1;
82 static int hf_netrom_node = -1;
83 static int hf_netrom_pwindow = -1;
84 static int hf_netrom_awindow = -1;
86 static int hf_netrom_mnemonic = -1;
89 * Structure containing pointers to hf_ values for various subfields of
99 static const netrom_tf_items netrom_type_items = {
107 const value_string op_code_vals_abbrev[] = {
108 { NETROM_PROTOEXT , "PROTOEXT"},
109 { NETROM_CONNREQ , "CONNREQ"},
110 { NETROM_CONNACK , "CONNACK"},
111 { NETROM_DISCREQ , "DISCREQ"},
112 { NETROM_DISCACK , "DISCACK"},
113 { NETROM_INFO , "INFO"},
114 { NETROM_INFOACK , "INFOACK"},
118 const value_string op_code_vals_text[] = {
119 { NETROM_PROTOEXT , "Protocol extension"},
120 { NETROM_CONNREQ , "Connect request"},
121 { NETROM_CONNACK , "Connect acknowledge"},
122 { NETROM_DISCREQ , "Disconnect request"},
123 { NETROM_DISCACK , "Disconnect acknowledge"},
124 { NETROM_INFO , "Information"},
125 { NETROM_INFOACK , "Information acknowledge"},
129 /* Initialize the subtree pointers */
130 static gint ett_netrom = -1;
131 static gint ett_netrom_type = -1;
134 dissect_netrom_type(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree,
135 int hf_netrom_type_param, gint ett_netrom_type_param, const netrom_tf_items *type_items )
138 proto_tree *type_tree;
143 type = tvb_get_guint8( tvb, offset );
144 op_code = type &0x0f;
146 info_buffer = wmem_strdup_printf( wmem_packet_scope(), "%s%s%s%s (0x%02x)",
147 val_to_str_const( op_code, op_code_vals_text, "Unknown" ),
148 ( type & NETROM_MORE_FLAG ) ? ", More" : "",
149 ( type & NETROM_NAK_FLAG ) ? ", NAK" : "",
150 ( type & NETROM_CHOKE_FLAG ) ? ", Choke" : "",
152 col_add_str( pinfo->cinfo, COL_INFO, info_buffer );
156 tc = proto_tree_add_uint_format( tree,
157 hf_netrom_type_param,
165 type_tree = proto_item_add_subtree( tc, ett_netrom_type_param );
167 proto_tree_add_item( type_tree, *type_items->hf_tf_op, tvb, offset, 1, ENC_BIG_ENDIAN );
168 proto_tree_add_item( type_tree, *type_items->hf_tf_choke, tvb, offset, 1, ENC_BIG_ENDIAN );
169 proto_tree_add_item( type_tree, *type_items->hf_tf_nak, tvb, offset, 1, ENC_BIG_ENDIAN );
170 proto_tree_add_item( type_tree, *type_items->hf_tf_more, tvb, offset, 1, ENC_BIG_ENDIAN );
175 dissect_netrom_proto(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
178 proto_tree *netrom_tree;
189 col_set_str( pinfo->cinfo, COL_PROTOCOL, "NET/ROM" );
190 col_clear( pinfo->cinfo, COL_INFO );
195 set_address_tvb(&pinfo->dl_src, AT_AX25, AX25_ADDR_LEN, tvb, offset);
196 set_address_tvb(&pinfo->src, AT_AX25, AX25_ADDR_LEN, tvb, offset);
197 /* src_ssid = tvb_get_guint8(tvb, offset+6); */
198 offset += AX25_ADDR_LEN; /* step over src addr */
201 set_address_tvb(&pinfo->dl_dst, AT_AX25, AX25_ADDR_LEN, tvb, offset);
202 set_address_tvb(&pinfo->dst, AT_AX25, AX25_ADDR_LEN, tvb, offset);
203 /* dst_ssid = tvb_get_guint8(tvb, offset+6); */
204 offset += AX25_ADDR_LEN; /* step over dst addr */
206 offset += 1; /* step over ttl */
207 cct_index = tvb_get_guint8( tvb, offset );
208 offset += 1; /* step over cct index*/
209 cct_id = tvb_get_guint8( tvb, offset );
210 offset += 1; /* step over cct id */
211 offset += 1; /* step over n_s */
212 offset += 1; /* step over n_r */
215 op_code = tvb_get_guint8( tvb, offset ) & 0x0f;
216 /*offset += 1;*/ /* step over op_code */
218 col_add_fstr( pinfo->cinfo, COL_INFO, "%s", val_to_str_const( op_code, op_code_vals_text, "Unknown" ));
222 /* create display subtree for the protocol */
224 ti = proto_tree_add_protocol_format( tree, proto_netrom, tvb, 0, NETROM_HEADER_SIZE,
225 "NET/ROM, Src: %s, Dst: %s",
226 address_to_str(wmem_packet_scope(), &pinfo->src),
227 address_to_str(wmem_packet_scope(), &pinfo->dst));
229 netrom_tree = proto_item_add_subtree( ti, ett_netrom );
234 proto_tree_add_item( netrom_tree, hf_netrom_src, tvb, offset, AX25_ADDR_LEN, ENC_NA );
235 offset += AX25_ADDR_LEN;
238 proto_tree_add_item( netrom_tree, hf_netrom_dst, tvb, offset, AX25_ADDR_LEN, ENC_NA );
239 offset += AX25_ADDR_LEN;
242 proto_tree_add_item( netrom_tree, hf_netrom_ttl, tvb, offset, 1, ENC_BIG_ENDIAN );
247 case NETROM_PROTOEXT :
249 proto_tree_add_item( netrom_tree, hf_netrom_my_cct_index, tvb, offset, 1, ENC_BIG_ENDIAN );
253 proto_tree_add_item( netrom_tree, hf_netrom_my_cct_id, tvb, offset, 1, ENC_BIG_ENDIAN );
262 case NETROM_CONNREQ :
264 proto_tree_add_item( netrom_tree, hf_netrom_my_cct_index, tvb, offset, 1, ENC_BIG_ENDIAN );
268 proto_tree_add_item( netrom_tree, hf_netrom_my_cct_id, tvb, offset, 1, ENC_BIG_ENDIAN );
278 case NETROM_CONNACK :
280 proto_tree_add_item( netrom_tree, hf_netrom_your_cct_index, tvb, offset, 1, ENC_BIG_ENDIAN );
284 proto_tree_add_item( netrom_tree, hf_netrom_your_cct_id, tvb, offset, 1, ENC_BIG_ENDIAN );
288 proto_tree_add_item( netrom_tree, hf_netrom_my_cct_index, tvb, offset, 1, ENC_BIG_ENDIAN );
292 proto_tree_add_item( netrom_tree, hf_netrom_my_cct_id, tvb, offset, 1, ENC_BIG_ENDIAN );
296 case NETROM_DISCREQ :
298 proto_tree_add_item( netrom_tree, hf_netrom_your_cct_index, tvb, offset, 1, ENC_BIG_ENDIAN );
302 proto_tree_add_item( netrom_tree, hf_netrom_your_cct_id, tvb, offset, 1, ENC_BIG_ENDIAN );
312 case NETROM_DISCACK :
314 proto_tree_add_item( netrom_tree, hf_netrom_your_cct_index, tvb, offset, 1, ENC_BIG_ENDIAN );
318 proto_tree_add_item( netrom_tree, hf_netrom_your_cct_id, tvb, offset, 1, ENC_BIG_ENDIAN );
330 proto_tree_add_item( netrom_tree, hf_netrom_your_cct_index, tvb, offset, 1, ENC_BIG_ENDIAN );
334 proto_tree_add_item( netrom_tree, hf_netrom_your_cct_id, tvb, offset, 1, ENC_BIG_ENDIAN );
338 proto_tree_add_item( netrom_tree, hf_netrom_n_s, tvb, offset, 1, ENC_BIG_ENDIAN );
342 proto_tree_add_item( netrom_tree, hf_netrom_n_r, tvb, offset, 1, ENC_BIG_ENDIAN );
346 case NETROM_INFOACK :
348 proto_tree_add_item( netrom_tree, hf_netrom_your_cct_index, tvb, offset, 1, ENC_BIG_ENDIAN );
352 proto_tree_add_item( netrom_tree, hf_netrom_your_cct_id, tvb, offset, 1, ENC_BIG_ENDIAN );
359 proto_tree_add_item( netrom_tree, hf_netrom_n_r, tvb, offset, 1, ENC_BIG_ENDIAN );
373 dissect_netrom_type( tvb,
385 case NETROM_PROTOEXT :
387 case NETROM_CONNREQ :
388 /* proposed window size */
389 proto_tree_add_item( netrom_tree, hf_netrom_pwindow, tvb, offset, 1, ENC_BIG_ENDIAN );
392 proto_tree_add_item( netrom_tree, hf_netrom_user, tvb, offset, AX25_ADDR_LEN, ENC_NA );
393 offset += AX25_ADDR_LEN;
395 proto_tree_add_item( netrom_tree, hf_netrom_node, tvb, offset, AX25_ADDR_LEN, ENC_NA );
396 offset += AX25_ADDR_LEN;
399 case NETROM_CONNACK :
400 /* accepted window size */
401 proto_tree_add_item( netrom_tree, hf_netrom_awindow, tvb, offset, 1, ENC_BIG_ENDIAN );
405 case NETROM_DISCREQ :
407 case NETROM_DISCACK :
411 case NETROM_INFOACK :
418 /* Call sub-dissectors here */
420 next_tvb = tvb_new_subset_remaining(tvb, offset);
424 case NETROM_PROTOEXT :
425 if ( cct_index == NETROM_PROTO_IP && cct_id == NETROM_PROTO_IP )
426 call_dissector( ip_handle , next_tvb, pinfo, tree );
428 call_data_dissector(next_tvb, pinfo, tree );
433 call_data_dissector(next_tvb, pinfo, tree );
439 dissect_netrom_routing(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
442 const guint8* mnemonic;
445 col_set_str( pinfo->cinfo, COL_PROTOCOL, "NET/ROM");
446 col_set_str( pinfo->cinfo, COL_INFO, "routing table frame");
451 proto_tree *netrom_tree;
452 ti = proto_tree_add_item( tree, proto_netrom, tvb, 0, -1, ENC_NA);
453 netrom_tree = proto_item_add_subtree( ti, ett_netrom );
455 proto_tree_add_item_ret_string_and_length(netrom_tree, hf_netrom_mnemonic, tvb, 1, 6, ENC_ASCII|ENC_NA,
456 wmem_packet_scope(), &mnemonic, &mnemonic_len);
457 proto_item_append_text(ti, ", routing table frame, Node: %.6s", mnemonic);
460 next_tvb = tvb_new_subset_remaining(tvb, 7);
462 call_data_dissector(next_tvb, pinfo, tree );
465 /* Code to actually dissect the packets */
467 dissect_netrom(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
469 if ( tvb_get_guint8( tvb, 0 ) == 0xff )
470 dissect_netrom_routing( tvb, pinfo, tree );
472 dissect_netrom_proto( tvb, pinfo, tree );
474 return tvb_captured_length(tvb);
478 capture_netrom( const guchar *pd _U_, int offset, int len, capture_packet_info_t *cpinfo _U_, const union wtap_pseudo_header *pseudo_header _U_)
480 if ( ! BYTES_ARE_IN_FRAME( offset, len, NETROM_MIN_SIZE ) )
483 /* XXX - check for IP-over-NetROM here! */
488 proto_register_netrom(void)
490 /* Setup list of header fields */
491 static hf_register_info hf[] = {
493 { "Source", "netrom.src",
494 FT_AX25, BASE_NONE, NULL, 0x0,
495 "Source callsign", HFILL }
498 { "Destination", "netrom.dst",
499 FT_AX25, BASE_NONE, NULL, 0x0,
500 "Destination callsign", HFILL }
503 { "TTL", "netrom.ttl",
504 FT_UINT8, BASE_HEX, NULL, 0x0,
507 { &hf_netrom_my_cct_index,
508 { "My circuit index", "netrom.my.cct.index",
509 FT_UINT8, BASE_HEX, NULL, 0x0,
512 { &hf_netrom_my_cct_id,
513 { "My circuit ID", "netrom.my.cct.id",
514 FT_UINT8, BASE_HEX, NULL, 0x0,
517 { &hf_netrom_your_cct_index,
518 { "Your circuit index", "netrom.your.cct.index",
519 FT_UINT8, BASE_HEX, NULL, 0x0,
522 { &hf_netrom_your_cct_id,
523 { "Your circuit ID", "netrom.your.cct.id",
524 FT_UINT8, BASE_HEX, NULL, 0x0,
528 { "N(r)", "netrom.n_r",
529 FT_UINT8, BASE_DEC, NULL, 0x0,
533 { "N(s)", "netrom.n_s",
534 FT_UINT8, BASE_DEC, NULL, 0x0,
538 { "Type", "netrom.type",
539 FT_UINT8, BASE_HEX, NULL, 0x0,
540 "Packet type field", HFILL }
543 { "OP code", "netrom.op",
544 FT_UINT8, BASE_HEX, VALS( op_code_vals_abbrev ), 0x0f,
545 "Protocol operation code", HFILL }
548 { "More", "netrom.flag.more",
549 FT_BOOLEAN, 8, TFS(&tfs_set_notset), NETROM_MORE_FLAG,
553 { "NAK", "netrom.flag.nak",
554 FT_BOOLEAN, 8, TFS(&tfs_set_notset), NETROM_NAK_FLAG,
558 { "Choke", "netrom.flag.choke",
559 FT_BOOLEAN, 8, TFS(&tfs_set_notset), NETROM_CHOKE_FLAG,
560 "Choke flag", HFILL }
563 { "User", "netrom.user",
564 FT_AX25, BASE_NONE, NULL, 0x0,
565 "User callsign", HFILL }
568 { "Node", "netrom.node",
569 FT_AX25, BASE_NONE, NULL, 0x0,
570 "Node callsign", HFILL }
572 { &hf_netrom_pwindow,
573 { "Window", "netrom.pwindow",
574 FT_UINT8, BASE_DEC, NULL, 0x0,
575 "Proposed window", HFILL }
577 { &hf_netrom_awindow,
578 { "Window", "netrom.awindow",
579 FT_UINT8, BASE_DEC, NULL, 0x0,
580 "Accepted window", HFILL }
582 { &hf_netrom_mnemonic,
583 { "Node name", "netrom.name",
584 FT_STRING, BASE_NONE, NULL, 0x0,
589 /* Setup protocol subtree array */
590 static gint *ett[] = {
595 /* Register the protocol name and description */
596 proto_netrom = proto_register_protocol( "Amateur Radio NET/ROM", "NET/ROM", "netrom" );
598 /* Required function calls to register the header fields and subtrees used */
599 proto_register_field_array( proto_netrom, hf, array_length(hf ) );
600 proto_register_subtree_array( ett, array_length( ett ) );
604 proto_reg_handoff_netrom(void)
606 capture_dissector_handle_t netrom_cap_handle;
608 dissector_add_uint( "ax25.pid", AX25_P_NETROM, create_dissector_handle( dissect_netrom, proto_netrom ) );
609 netrom_cap_handle = create_capture_dissector_handle(capture_netrom, proto_netrom);
610 capture_dissector_add_uint("ax25.pid", AX25_P_NETROM, netrom_cap_handle);
612 ip_handle = find_dissector_add_dependency( "ip", proto_netrom );
616 * Editor modelines - https://www.wireshark.org/tools/modelines.html
621 * indent-tabs-mode: t
624 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
625 * :indentSize=8:tabSize=8:noTabs=false: