/src/wireshark/epan/dissectors/packet-bpq.c
Line | Count | Source |
1 | | /* packet-bpq.c |
2 | | * |
3 | | * Routines for Amateur Packet Radio protocol dissection |
4 | | * Copyright 2005,2006,2007,2008,2009,2010,2012 R.W. Stearn <richard@rns-stearn.demon.co.uk> |
5 | | * |
6 | | * Wireshark - Network traffic analyzer |
7 | | * By Gerald Combs <gerald@wireshark.org> |
8 | | * Copyright 1998 Gerald Combs |
9 | | * |
10 | | * SPDX-License-Identifier: GPL-2.0-or-later |
11 | | */ |
12 | | |
13 | | /* |
14 | | * This dissector is for: |
15 | | * Ethernet encapsulated Amateur AX.25 (AX.25 over Ethernet) |
16 | | * |
17 | | * Information was drawn from: |
18 | | * ? |
19 | | * |
20 | | * It uses Ether ID 0x08ff which is not officially registered. |
21 | | * |
22 | | */ |
23 | | |
24 | | #include "config.h" |
25 | | |
26 | | #include <epan/packet.h> |
27 | | #include <epan/etypes.h> |
28 | | #include <epan/capture_dissectors.h> |
29 | | |
30 | | #define STRLEN 80 |
31 | | |
32 | 415 | #define BPQ_HEADER_SIZE 2 /* length of bpq_len */ |
33 | | |
34 | | void proto_register_bpq(void); |
35 | | void proto_reg_handoff_bpq(void); |
36 | | |
37 | | static dissector_handle_t bpq_handle; |
38 | | static dissector_handle_t ax25_handle; |
39 | | |
40 | | static capture_dissector_handle_t ax25_cap_handle; |
41 | | |
42 | | static int proto_bpq; |
43 | | static int hf_bpq_len; |
44 | | |
45 | | static int ett_bpq; |
46 | | |
47 | | static int |
48 | | dissect_bpq( tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, void* data _U_ ) |
49 | 139 | { |
50 | 139 | proto_item *ti; |
51 | 139 | proto_tree *bpq_tree; |
52 | 139 | int offset; |
53 | 139 | uint16_t bpq_len; |
54 | 139 | tvbuff_t *next_tvb; |
55 | | |
56 | | |
57 | 139 | col_set_str( pinfo->cinfo, COL_PROTOCOL, "BPQ" ); |
58 | | |
59 | 139 | col_clear( pinfo->cinfo, COL_INFO ); |
60 | | |
61 | | /* protocol offset for the BPQ header */ |
62 | 139 | offset = 0; |
63 | | |
64 | 139 | bpq_len = tvb_get_letohs( tvb, offset ); |
65 | | |
66 | 139 | col_add_fstr( pinfo->cinfo, COL_INFO, "%u", bpq_len ); |
67 | | |
68 | 139 | if ( parent_tree ) |
69 | 138 | { |
70 | | /* protocol offset for the BPQ header */ |
71 | 138 | offset = 0; |
72 | | |
73 | | /* create display subtree for the protocol */ |
74 | 138 | ti = proto_tree_add_protocol_format( parent_tree, proto_bpq, tvb, offset, BPQ_HEADER_SIZE, |
75 | 138 | "BPQ, Len: %u", |
76 | 138 | bpq_len & 0xfff /* XXX - lower 12 bits? */ |
77 | 138 | ); |
78 | | |
79 | 138 | bpq_tree = proto_item_add_subtree( ti, ett_bpq ); |
80 | | |
81 | 138 | proto_tree_add_item( bpq_tree, hf_bpq_len, tvb, offset, BPQ_HEADER_SIZE, ENC_LITTLE_ENDIAN ); |
82 | | |
83 | 138 | } |
84 | | |
85 | 139 | offset += BPQ_HEADER_SIZE; |
86 | | |
87 | | /* XXX - use the length */ |
88 | 139 | next_tvb = tvb_new_subset_remaining( tvb, offset ); |
89 | 139 | call_dissector( ax25_handle, next_tvb, pinfo, parent_tree ); |
90 | 139 | return tvb_captured_length(tvb); |
91 | 139 | } |
92 | | |
93 | | static bool |
94 | | capture_bpq( const unsigned char *pd, int offset, int len, capture_packet_info_t *cpinfo, const union wtap_pseudo_header *pseudo_header) |
95 | 0 | { |
96 | 0 | int l_offset; |
97 | |
|
98 | 0 | if ( ! BYTES_ARE_IN_FRAME( offset, len, BPQ_HEADER_SIZE ) ) |
99 | 0 | return false; |
100 | | |
101 | 0 | l_offset = offset; |
102 | 0 | l_offset += BPQ_HEADER_SIZE; /* step over bpq header to point at the AX.25 packet*/ |
103 | 0 | return call_capture_dissector( ax25_cap_handle, pd, l_offset, len, cpinfo, pseudo_header ); |
104 | 0 | } |
105 | | |
106 | | void |
107 | | proto_register_bpq(void) |
108 | 14 | { |
109 | | /* Setup list of header fields */ |
110 | 14 | static hf_register_info hf[] = { |
111 | 14 | { &hf_bpq_len, |
112 | 14 | { "BPQ len", "bpq.len", |
113 | 14 | FT_UINT16, BASE_DEC, NULL, 0x0, |
114 | 14 | NULL, HFILL } |
115 | 14 | }, |
116 | 14 | }; |
117 | | |
118 | | /* Setup protocol subtree array */ |
119 | 14 | static int *ett[] = { |
120 | 14 | &ett_bpq, |
121 | 14 | }; |
122 | | |
123 | | /* Register the protocol name and description */ |
124 | 14 | proto_bpq = proto_register_protocol( "Amateur Radio BPQ", "BPQ", "bpq" ); |
125 | | |
126 | | /* Register the dissector */ |
127 | 14 | bpq_handle = register_dissector("bpq", dissect_bpq, proto_bpq); |
128 | | |
129 | | /* Required function calls to register the header fields and subtrees used */ |
130 | 14 | proto_register_field_array( proto_bpq, hf, array_length( hf ) ); |
131 | 14 | proto_register_subtree_array( ett, array_length( ett ) ); |
132 | 14 | } |
133 | | |
134 | | void |
135 | | proto_reg_handoff_bpq(void) |
136 | 14 | { |
137 | 14 | capture_dissector_handle_t bpq_cap_handle; |
138 | | |
139 | 14 | dissector_add_uint("ethertype", ETHERTYPE_BPQ, bpq_handle); |
140 | 14 | bpq_cap_handle = create_capture_dissector_handle(capture_bpq, proto_bpq); |
141 | 14 | capture_dissector_add_uint("ethertype", ETHERTYPE_BPQ, bpq_cap_handle); |
142 | | |
143 | | /* BPQ is only implemented for AX.25 */ |
144 | 14 | ax25_handle = find_dissector_add_dependency( "ax25", proto_bpq ); |
145 | | |
146 | 14 | ax25_cap_handle = find_capture_dissector( "ax25" ); |
147 | 14 | } |
148 | | |
149 | | /* |
150 | | * Editor modelines - https://www.wireshark.org/tools/modelines.html |
151 | | * |
152 | | * Local variables: |
153 | | * c-basic-offset: 8 |
154 | | * tab-width: 8 |
155 | | * indent-tabs-mode: t |
156 | | * End: |
157 | | * |
158 | | * vi: set shiftwidth=8 tabstop=8 noexpandtab: |
159 | | * :indentSize=8:tabSize=8:noTabs=false: |
160 | | */ |