epan/dissectors/pidl/samr/samr.cnf cnf_dissect_lsa_BinaryString => lsarpc_dissect_str...
[wireshark-sm.git] / epan / dissectors / packet-netrom.c
blobce422de0f63d9365d408a408cfc60b4fc9dc8f0e
1 /* packet-netrom.c
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
24 * packet-sdlc.c
25 * packet-x25.c
26 * packet-lapb.c
27 * paket-gprs-llc.c
28 * xdlc.c
29 * with the base file built from README.developers.
32 #include "config.h"
34 #include <epan/packet.h>
35 #include <epan/to_str.h>
36 #include <epan/capture_dissectors.h>
37 #include <epan/ax25_pids.h>
38 #include <epan/tfs.h>
39 #include <wsutil/array.h>
41 void proto_register_netrom(void);
42 void proto_reg_handoff_netrom(void);
44 #define STRLEN 80
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
92 * the type field.
94 typedef struct {
95 int *hf_tf_op;
96 int *hf_tf_more;
97 int *hf_tf_nak;
98 int *hf_tf_choke;
99 } netrom_tf_items;
101 static const netrom_tf_items netrom_type_items = {
102 &hf_netrom_op,
103 &hf_netrom_more,
104 &hf_netrom_nak,
105 &hf_netrom_choke
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"},
117 { 0 , NULL}
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"},
128 { 0 , NULL}
131 /* Initialize the subtree pointers */
132 static int ett_netrom;
133 static int ett_netrom_type;
135 static void
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 )
139 proto_tree *tc;
140 proto_tree *type_tree;
141 char *info_buffer;
142 uint8_t type;
143 uint8_t op_code;
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" : "",
153 type );
154 col_add_str( pinfo->cinfo, COL_INFO, info_buffer );
156 if ( tree )
158 tc = proto_tree_add_uint_format( tree,
159 hf_netrom_type_param,
160 tvb,
161 offset,
163 type,
164 "Type field: %s",
165 info_buffer
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 );
176 static void
177 dissect_netrom_proto(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
179 proto_item *ti;
180 proto_tree *netrom_tree;
181 int offset;
182 #if 0
183 uint8_t src_ssid;
184 uint8_t dst_ssid;
185 #endif
186 uint8_t op_code;
187 uint8_t cct_index;
188 uint8_t cct_id;
189 tvbuff_t *next_tvb;
191 col_set_str( pinfo->cinfo, COL_PROTOCOL, "NET/ROM" );
192 col_clear( pinfo->cinfo, COL_INFO );
194 offset = 0;
196 /* source */
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 */
202 /* destination */
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 */
216 /* frame type */
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" ));
222 /* if ( tree ) */
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 );
233 offset = 0;
235 /* source */
236 proto_tree_add_item( netrom_tree, hf_netrom_src, tvb, offset, AX25_ADDR_LEN, ENC_NA );
237 offset += AX25_ADDR_LEN;
239 /* destination */
240 proto_tree_add_item( netrom_tree, hf_netrom_dst, tvb, offset, AX25_ADDR_LEN, ENC_NA );
241 offset += AX25_ADDR_LEN;
243 /* ttl */
244 proto_tree_add_item( netrom_tree, hf_netrom_ttl, tvb, offset, 1, ENC_BIG_ENDIAN );
245 offset += 1;
247 switch ( op_code )
249 case NETROM_PROTOEXT :
250 /* cct index */
251 proto_tree_add_item( netrom_tree, hf_netrom_my_cct_index, tvb, offset, 1, ENC_BIG_ENDIAN );
252 offset += 1;
254 /* cct id */
255 proto_tree_add_item( netrom_tree, hf_netrom_my_cct_id, tvb, offset, 1, ENC_BIG_ENDIAN );
256 offset += 1;
258 /* unused */
259 offset += 1;
261 /* unused */
262 offset += 1;
263 break;
264 case NETROM_CONNREQ :
265 /* cct index */
266 proto_tree_add_item( netrom_tree, hf_netrom_my_cct_index, tvb, offset, 1, ENC_BIG_ENDIAN );
267 offset += 1;
269 /* cct id */
270 proto_tree_add_item( netrom_tree, hf_netrom_my_cct_id, tvb, offset, 1, ENC_BIG_ENDIAN );
271 offset += 1;
273 /* unused */
274 offset += 1;
276 /* unused */
277 offset += 1;
279 break;
280 case NETROM_CONNACK :
281 /* your cct index */
282 proto_tree_add_item( netrom_tree, hf_netrom_your_cct_index, tvb, offset, 1, ENC_BIG_ENDIAN );
283 offset += 1;
285 /* your cct id */
286 proto_tree_add_item( netrom_tree, hf_netrom_your_cct_id, tvb, offset, 1, ENC_BIG_ENDIAN );
287 offset += 1;
289 /* my cct index */
290 proto_tree_add_item( netrom_tree, hf_netrom_my_cct_index, tvb, offset, 1, ENC_BIG_ENDIAN );
291 offset += 1;
293 /* my cct id */
294 proto_tree_add_item( netrom_tree, hf_netrom_my_cct_id, tvb, offset, 1, ENC_BIG_ENDIAN );
295 offset += 1;
297 break;
298 case NETROM_DISCREQ :
299 /* your cct index */
300 proto_tree_add_item( netrom_tree, hf_netrom_your_cct_index, tvb, offset, 1, ENC_BIG_ENDIAN );
301 offset += 1;
303 /* your cct id */
304 proto_tree_add_item( netrom_tree, hf_netrom_your_cct_id, tvb, offset, 1, ENC_BIG_ENDIAN );
305 offset += 1;
307 /* unused */
308 offset += 1;
310 /* unused */
311 offset += 1;
313 break;
314 case NETROM_DISCACK :
315 /* your cct index */
316 proto_tree_add_item( netrom_tree, hf_netrom_your_cct_index, tvb, offset, 1, ENC_BIG_ENDIAN );
317 offset += 1;
319 /* your cct id */
320 proto_tree_add_item( netrom_tree, hf_netrom_your_cct_id, tvb, offset, 1, ENC_BIG_ENDIAN );
321 offset += 1;
323 /* unused */
324 offset += 1;
326 /* unused */
327 offset += 1;
329 break;
330 case NETROM_INFO :
331 /* your cct index */
332 proto_tree_add_item( netrom_tree, hf_netrom_your_cct_index, tvb, offset, 1, ENC_BIG_ENDIAN );
333 offset += 1;
335 /* your cct id */
336 proto_tree_add_item( netrom_tree, hf_netrom_your_cct_id, tvb, offset, 1, ENC_BIG_ENDIAN );
337 offset += 1;
339 /* n_s */
340 proto_tree_add_item( netrom_tree, hf_netrom_n_s, tvb, offset, 1, ENC_BIG_ENDIAN );
341 offset += 1;
343 /* n_r */
344 proto_tree_add_item( netrom_tree, hf_netrom_n_r, tvb, offset, 1, ENC_BIG_ENDIAN );
345 offset += 1;
347 break;
348 case NETROM_INFOACK :
349 /* your cct index */
350 proto_tree_add_item( netrom_tree, hf_netrom_your_cct_index, tvb, offset, 1, ENC_BIG_ENDIAN );
351 offset += 1;
353 /* your cct id */
354 proto_tree_add_item( netrom_tree, hf_netrom_your_cct_id, tvb, offset, 1, ENC_BIG_ENDIAN );
355 offset += 1;
357 /* unused */
358 offset += 1;
360 /* n_r */
361 proto_tree_add_item( netrom_tree, hf_netrom_n_r, tvb, offset, 1, ENC_BIG_ENDIAN );
362 offset += 1;
364 break;
365 default :
366 offset += 1;
367 offset += 1;
368 offset += 1;
369 offset += 1;
371 break;
374 /* type */
375 dissect_netrom_type( tvb,
376 offset,
377 pinfo,
378 netrom_tree,
379 hf_netrom_type,
380 ett_netrom_type,
381 &netrom_type_items
383 offset += 1;
385 switch ( op_code )
387 case NETROM_PROTOEXT :
388 break;
389 case NETROM_CONNREQ :
390 /* proposed window size */
391 proto_tree_add_item( netrom_tree, hf_netrom_pwindow, tvb, offset, 1, ENC_BIG_ENDIAN );
392 offset += 1;
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;
400 break;
401 case NETROM_CONNACK :
402 /* accepted window size */
403 proto_tree_add_item( netrom_tree, hf_netrom_awindow, tvb, offset, 1, ENC_BIG_ENDIAN );
404 offset += 1;
406 break;
407 case NETROM_DISCREQ :
408 break;
409 case NETROM_DISCACK :
410 break;
411 case NETROM_INFO :
412 break;
413 case NETROM_INFOACK :
414 break;
415 default :
416 break;
420 /* Call sub-dissectors here */
422 next_tvb = tvb_new_subset_remaining(tvb, offset);
424 switch ( op_code )
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 );
429 else
430 call_data_dissector(next_tvb, pinfo, tree );
432 break;
433 case NETROM_INFO :
434 default :
435 call_data_dissector(next_tvb, pinfo, tree );
436 break;
440 static void
441 dissect_netrom_routing(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
443 tvbuff_t *next_tvb;
444 const uint8_t* mnemonic;
445 int mnemonic_len;
447 col_set_str( pinfo->cinfo, COL_PROTOCOL, "NET/ROM");
448 col_set_str( pinfo->cinfo, COL_INFO, "routing table frame");
450 if (tree)
452 proto_item *ti;
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 */
468 static int
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 );
473 else
474 dissect_netrom_proto( tvb, pinfo, tree );
476 return tvb_captured_length(tvb);
479 static bool
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 ) )
483 return false;
485 /* XXX - check for IP-over-NetROM here! */
486 return false;
489 void
490 proto_register_netrom(void)
492 /* Setup list of header fields */
493 static hf_register_info hf[] = {
494 { &hf_netrom_src,
495 { "Source", "netrom.src",
496 FT_AX25, BASE_NONE, NULL, 0x0,
497 "Source callsign", HFILL }
499 { &hf_netrom_dst,
500 { "Destination", "netrom.dst",
501 FT_AX25, BASE_NONE, NULL, 0x0,
502 "Destination callsign", HFILL }
504 { &hf_netrom_ttl,
505 { "TTL", "netrom.ttl",
506 FT_UINT8, BASE_HEX, NULL, 0x0,
507 NULL, HFILL }
509 { &hf_netrom_my_cct_index,
510 { "My circuit index", "netrom.my.cct.index",
511 FT_UINT8, BASE_HEX, NULL, 0x0,
512 NULL, HFILL }
514 { &hf_netrom_my_cct_id,
515 { "My circuit ID", "netrom.my.cct.id",
516 FT_UINT8, BASE_HEX, NULL, 0x0,
517 NULL, HFILL }
519 { &hf_netrom_your_cct_index,
520 { "Your circuit index", "netrom.your.cct.index",
521 FT_UINT8, BASE_HEX, NULL, 0x0,
522 NULL, HFILL }
524 { &hf_netrom_your_cct_id,
525 { "Your circuit ID", "netrom.your.cct.id",
526 FT_UINT8, BASE_HEX, NULL, 0x0,
527 NULL, HFILL }
529 { &hf_netrom_n_r,
530 { "N(r)", "netrom.n_r",
531 FT_UINT8, BASE_DEC, NULL, 0x0,
532 NULL, HFILL }
534 { &hf_netrom_n_s,
535 { "N(s)", "netrom.n_s",
536 FT_UINT8, BASE_DEC, NULL, 0x0,
537 NULL, HFILL }
539 { &hf_netrom_type,
540 { "Type", "netrom.type",
541 FT_UINT8, BASE_HEX, NULL, 0x0,
542 "Packet type field", HFILL }
544 { &hf_netrom_op,
545 { "OP code", "netrom.op",
546 FT_UINT8, BASE_HEX, VALS( op_code_vals_abbrev ), 0x0f,
547 "Protocol operation code", HFILL }
549 { &hf_netrom_more,
550 { "More", "netrom.flag.more",
551 FT_BOOLEAN, 8, TFS(&tfs_set_notset), NETROM_MORE_FLAG,
552 "More flag", HFILL }
554 { &hf_netrom_nak,
555 { "NAK", "netrom.flag.nak",
556 FT_BOOLEAN, 8, TFS(&tfs_set_notset), NETROM_NAK_FLAG,
557 "NAK flag", HFILL }
559 { &hf_netrom_choke,
560 { "Choke", "netrom.flag.choke",
561 FT_BOOLEAN, 8, TFS(&tfs_set_notset), NETROM_CHOKE_FLAG,
562 "Choke flag", HFILL }
564 { &hf_netrom_user,
565 { "User", "netrom.user",
566 FT_AX25, BASE_NONE, NULL, 0x0,
567 "User callsign", HFILL }
569 { &hf_netrom_node,
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,
587 NULL, HFILL }
591 /* Setup protocol subtree array */
592 static int *ett[] = {
593 &ett_netrom,
594 &ett_netrom_type,
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 ) );
605 void
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
620 * Local variables:
621 * c-basic-offset: 8
622 * tab-width: 8
623 * indent-tabs-mode: t
624 * End:
626 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
627 * :indentSize=8:tabSize=8:noTabs=false: