/src/wireshark/epan/dissectors/packet-packetlogger.c
Line | Count | Source |
1 | | /* packet-packetlogger.c |
2 | | * Routines for Apple's PacketLogger Types |
3 | | * |
4 | | * Copyright 2009, Stig Bjorlykke <stig@bjorlykke.org> |
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 | | #include "config.h" |
14 | | |
15 | | #include <epan/packet.h> |
16 | | #include <wiretap/wtap.h> |
17 | | |
18 | | #include "packet-bluetooth.h" |
19 | | |
20 | | void proto_register_packetlogger(void); |
21 | | void proto_reg_handoff_packetlogger(void); |
22 | | |
23 | 14 | #define PNAME "PacketLogger" |
24 | 14 | #define PSNAME "PKTLOG" |
25 | 28 | #define PFNAME "packetlogger" |
26 | | |
27 | | static int proto_packetlogger; |
28 | | |
29 | | static int hf_type; |
30 | | static int hf_info; |
31 | | static int hf_syslog; |
32 | | static int hf_syslog_process_id; |
33 | | static int hf_syslog_message_type; |
34 | | static int hf_syslog_process; |
35 | | static int hf_syslog_sender; |
36 | | static int hf_syslog_subsystem; |
37 | | static int hf_syslog_category; |
38 | | static int hf_syslog_message; |
39 | | |
40 | | static int ett_packetlogger; |
41 | | static int ett_syslog; |
42 | | |
43 | | static dissector_handle_t packetlogger_handle; |
44 | | static dissector_table_t hci_h1_table; |
45 | | |
46 | | /* |
47 | | * Packet types. |
48 | | * |
49 | | * NOTE: if you add a new type here, you MUST also add it to |
50 | | * wiretap/packetlogger.c's list of packet types *AND* to the |
51 | | * packet types it checks for in its "does this look like a |
52 | | * Packetlogger file?" heuristics; otherwise, some valid |
53 | | * Packetlogger files will not be recognize as Packetlogger |
54 | | * files. |
55 | | */ |
56 | 0 | #define PKT_HCI_COMMAND 0x00 |
57 | 0 | #define PKT_HCI_EVENT 0x01 |
58 | 0 | #define PKT_SENT_ACL_DATA 0x02 |
59 | 0 | #define PKT_RECV_ACL_DATA 0x03 |
60 | 0 | #define PKT_SENT_SCO_DATA 0x08 |
61 | 0 | #define PKT_RECV_SCO_DATA 0x09 |
62 | | #define PKT_LMP_SEND 0x0A |
63 | | #define PKT_LMP_RECV 0x0B |
64 | 0 | #define PKT_SYSLOG 0xF7 |
65 | 0 | #define PKT_KERNEL 0xF8 |
66 | 0 | #define PKT_KERNEL_DEBUG 0xF9 |
67 | 0 | #define PKT_ERROR 0xFA |
68 | 0 | #define PKT_POWER 0xFB |
69 | 0 | #define PKT_NOTE 0xFC |
70 | 0 | #define PKT_CONFIG 0xFD |
71 | 0 | #define PKT_NEW_CONTROLLER 0xFE |
72 | | |
73 | | static const value_string type_vals[] = { |
74 | | { PKT_HCI_COMMAND, "HCI Command" }, |
75 | | { PKT_HCI_EVENT, "HCI Event" }, |
76 | | { PKT_SENT_ACL_DATA, "Sent ACL Data" }, |
77 | | { PKT_RECV_ACL_DATA, "Recv ACL Data" }, |
78 | | { PKT_SENT_SCO_DATA, "Sent SCO Data" }, |
79 | | { PKT_RECV_SCO_DATA, "Recv SCO Data" }, |
80 | | { PKT_LMP_SEND, "Sent LMP Data" }, |
81 | | { PKT_LMP_RECV, "Recv LMP Data" }, |
82 | | { PKT_SYSLOG, "Syslog" }, |
83 | | { PKT_KERNEL, "Kernel" }, |
84 | | { PKT_KERNEL_DEBUG, "Kernel Debug" }, |
85 | | { PKT_ERROR, "Error" }, |
86 | | { PKT_POWER, "Power" }, |
87 | | { PKT_NOTE, "Note" }, |
88 | | { PKT_CONFIG, "Config" }, |
89 | | { PKT_NEW_CONTROLLER, "New Controller" }, |
90 | | { 0, NULL } |
91 | | }; |
92 | | |
93 | | static void dissect_bthci_h1(tvbuff_t *tvb, packet_info *pinfo, |
94 | | proto_tree *tree, proto_item *ti, uint8_t pl_type, uint32_t channel, |
95 | | bool sent, bluetooth_data_t *bluetooth_data) |
96 | 0 | { |
97 | 0 | struct bthci_phdr bthci; |
98 | |
|
99 | 0 | bthci.channel = channel; |
100 | 0 | bthci.sent = sent; |
101 | 0 | pinfo->p2p_dir = sent ? P2P_DIR_SENT : P2P_DIR_RECV; |
102 | |
|
103 | 0 | bluetooth_data->previous_protocol_data.bthci = &bthci; |
104 | 0 | proto_item_set_len (ti, 1); |
105 | |
|
106 | 0 | col_add_str (pinfo->cinfo, COL_INFO, val_to_str(pinfo->pool, pl_type, type_vals, "Unknown 0x%02x")); |
107 | 0 | if (!dissector_try_uint_with_data (hci_h1_table, bthci.channel, |
108 | 0 | tvb, pinfo, tree, true, bluetooth_data)) { |
109 | 0 | call_data_dissector (tvb, pinfo, tree); |
110 | 0 | } |
111 | 0 | } |
112 | | |
113 | | static void dissect_syslog(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) |
114 | 0 | { |
115 | 0 | proto_item *ti = NULL; |
116 | 0 | proto_tree *sub_tree = NULL; |
117 | 0 | int offset = 0; |
118 | 0 | int len; |
119 | |
|
120 | 0 | ti = proto_tree_add_item (tree, hf_syslog, tvb, 0, -1, ENC_NA); |
121 | 0 | sub_tree = proto_item_add_subtree (ti, ett_syslog); |
122 | |
|
123 | 0 | proto_tree_add_item (sub_tree, hf_syslog_process_id, tvb, offset, 4, ENC_LITTLE_ENDIAN); |
124 | 0 | offset += 4; |
125 | |
|
126 | 0 | proto_tree_add_item (sub_tree, hf_syslog_message_type, tvb, offset, 1, ENC_NA); |
127 | 0 | offset += 1; |
128 | |
|
129 | 0 | len = tvb_strsize (tvb, offset); |
130 | 0 | proto_tree_add_item (sub_tree, hf_syslog_process, tvb, offset, len, ENC_ASCII); |
131 | 0 | offset += len; |
132 | |
|
133 | 0 | len = tvb_strsize (tvb, offset); |
134 | 0 | proto_tree_add_item (sub_tree, hf_syslog_sender, tvb, offset, len, ENC_ASCII); |
135 | 0 | offset += len; |
136 | |
|
137 | 0 | len = tvb_strsize (tvb, offset); |
138 | 0 | proto_tree_add_item (sub_tree, hf_syslog_subsystem, tvb, offset, len, ENC_ASCII); |
139 | 0 | offset += len; |
140 | |
|
141 | 0 | len = tvb_strsize (tvb, offset); |
142 | 0 | proto_tree_add_item (sub_tree, hf_syslog_category, tvb, offset, len, ENC_ASCII); |
143 | 0 | offset += len; |
144 | |
|
145 | 0 | len = tvb_strsize (tvb, offset); |
146 | 0 | proto_tree_add_item (sub_tree, hf_syslog_message, tvb, offset, len, ENC_ASCII); |
147 | 0 | col_add_str (pinfo->cinfo, COL_INFO, tvb_format_stringzpad_wsp (pinfo->pool, tvb, offset, len)); |
148 | 0 | } |
149 | | |
150 | | static int dissect_packetlogger(tvbuff_t *tvb, packet_info *pinfo, |
151 | | proto_tree *tree, void *data) |
152 | 0 | { |
153 | 0 | proto_tree *packetlogger_tree = NULL; |
154 | 0 | tvbuff_t *next_tvb; |
155 | 0 | proto_item *ti = NULL; |
156 | 0 | uint8_t pl_type; |
157 | 0 | int len; |
158 | 0 | bluetooth_data_t *bluetooth_data; |
159 | |
|
160 | 0 | bluetooth_data = (bluetooth_data_t *) data; |
161 | |
|
162 | 0 | col_set_str (pinfo->cinfo, COL_PROTOCOL, PSNAME); |
163 | 0 | col_clear (pinfo->cinfo, COL_INFO); |
164 | |
|
165 | 0 | ti = proto_tree_add_item (tree, proto_packetlogger, tvb, 0, -1, ENC_NA); |
166 | 0 | packetlogger_tree = proto_item_add_subtree (ti, ett_packetlogger); |
167 | |
|
168 | 0 | pl_type = tvb_get_uint8 (tvb, 0); |
169 | 0 | proto_tree_add_item (packetlogger_tree, hf_type, tvb, 0, 1, ENC_BIG_ENDIAN); |
170 | 0 | proto_item_append_text (ti, " %s", val_to_str(pinfo->pool, pl_type, type_vals, "Unknown 0x%02x")); |
171 | |
|
172 | 0 | len = tvb_reported_length_remaining (tvb, 1); |
173 | 0 | next_tvb = tvb_new_subset_remaining (tvb, 1); |
174 | |
|
175 | 0 | switch (pl_type) { |
176 | 0 | case PKT_HCI_COMMAND: |
177 | 0 | dissect_bthci_h1 (next_tvb, pinfo, tree, ti, pl_type, BTHCI_CHANNEL_COMMAND, |
178 | 0 | true, bluetooth_data); |
179 | 0 | break; |
180 | 0 | case PKT_HCI_EVENT: |
181 | 0 | dissect_bthci_h1 (next_tvb, pinfo, tree, ti, pl_type, BTHCI_CHANNEL_EVENT, |
182 | 0 | false, bluetooth_data); |
183 | 0 | break; |
184 | 0 | case PKT_SENT_ACL_DATA: |
185 | 0 | dissect_bthci_h1 (next_tvb, pinfo, tree, ti, pl_type, BTHCI_CHANNEL_ACL, |
186 | 0 | true, bluetooth_data); |
187 | 0 | break; |
188 | 0 | case PKT_RECV_ACL_DATA: |
189 | 0 | dissect_bthci_h1 (next_tvb, pinfo, tree, ti, pl_type, BTHCI_CHANNEL_ACL, |
190 | 0 | false, bluetooth_data); |
191 | 0 | break; |
192 | 0 | case PKT_SENT_SCO_DATA: |
193 | 0 | dissect_bthci_h1 (next_tvb, pinfo, tree, ti, pl_type, BTHCI_CHANNEL_SCO, |
194 | 0 | true, bluetooth_data); |
195 | 0 | break; |
196 | 0 | case PKT_RECV_SCO_DATA: |
197 | 0 | dissect_bthci_h1 (next_tvb, pinfo, tree, ti, pl_type, BTHCI_CHANNEL_SCO, |
198 | 0 | false, bluetooth_data); |
199 | 0 | break; |
200 | 0 | case PKT_SYSLOG: |
201 | 0 | dissect_syslog (next_tvb, pinfo, packetlogger_tree); |
202 | 0 | break; |
203 | 0 | case PKT_KERNEL: |
204 | 0 | case PKT_KERNEL_DEBUG: |
205 | 0 | case PKT_ERROR: |
206 | 0 | case PKT_POWER: |
207 | 0 | case PKT_NOTE: |
208 | 0 | case PKT_CONFIG: |
209 | 0 | case PKT_NEW_CONTROLLER: |
210 | 0 | proto_tree_add_item (packetlogger_tree, hf_info, next_tvb, 0, len, ENC_ASCII); |
211 | 0 | col_add_str (pinfo->cinfo, COL_INFO, tvb_format_stringzpad_wsp (pinfo->pool, next_tvb, 0, len)); |
212 | 0 | break; |
213 | 0 | default: |
214 | 0 | call_data_dissector(next_tvb, pinfo, tree); |
215 | 0 | col_add_str (pinfo->cinfo, COL_INFO, val_to_str(pinfo->pool, pl_type, type_vals, "Unknown 0x%02x")); |
216 | 0 | break; |
217 | 0 | } |
218 | | |
219 | 0 | return tvb_captured_length(tvb); |
220 | 0 | } |
221 | | |
222 | | void proto_register_packetlogger (void) |
223 | 14 | { |
224 | 14 | static hf_register_info hf[] = { |
225 | 14 | { &hf_type, |
226 | 14 | { "Type", "packetlogger.type", FT_UINT8, BASE_HEX, VALS(type_vals), 0x0, NULL, HFILL } }, |
227 | 14 | { &hf_info, |
228 | 14 | { "Info", "packetlogger.info", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL } }, |
229 | 14 | { &hf_syslog, |
230 | 14 | { "Syslog", "packetlogger.syslog", FT_NONE, BASE_NONE, NULL, 0, NULL, HFILL } }, |
231 | 14 | { &hf_syslog_process_id, |
232 | 14 | { "ProcessID", "packetlogger.syslog.process_id", FT_UINT32, BASE_DEC, NULL, 0, NULL, HFILL } }, |
233 | 14 | { &hf_syslog_message_type, |
234 | 14 | { "Message Type", "packetlogger.syslog.message_type", FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL } }, |
235 | 14 | { &hf_syslog_process, |
236 | 14 | { "Process", "packetlogger.syslog.process", FT_STRINGZ, BASE_NONE, NULL, 0, NULL, HFILL } }, |
237 | 14 | { &hf_syslog_sender, |
238 | 14 | { "Sender", "packetlogger.syslog.sender", FT_STRINGZ, BASE_NONE, NULL, 0, NULL, HFILL } }, |
239 | 14 | { &hf_syslog_subsystem, |
240 | 14 | { "Subsystem", "packetlogger.syslog.subsystem", FT_STRINGZ, BASE_NONE, NULL, 0, NULL, HFILL } }, |
241 | 14 | { &hf_syslog_category, |
242 | 14 | { "Category", "packetlogger.syslog.category", FT_STRINGZ, BASE_NONE, NULL, 0, NULL, HFILL } }, |
243 | 14 | { &hf_syslog_message, |
244 | 14 | { "Message", "packetlogger.syslog.message", FT_STRINGZ, BASE_NONE, NULL, 0, NULL, HFILL } } |
245 | 14 | }; |
246 | | |
247 | 14 | static int *ett[] = { |
248 | 14 | &ett_packetlogger, |
249 | 14 | &ett_syslog |
250 | 14 | }; |
251 | | |
252 | 14 | proto_packetlogger = proto_register_protocol (PNAME, PSNAME, PFNAME); |
253 | | |
254 | 14 | packetlogger_handle = register_dissector (PFNAME, dissect_packetlogger, proto_packetlogger); |
255 | | |
256 | 14 | proto_register_field_array (proto_packetlogger, hf, array_length (hf)); |
257 | 14 | proto_register_subtree_array (ett, array_length (ett)); |
258 | 14 | } |
259 | | |
260 | | void proto_reg_handoff_packetlogger (void) |
261 | 14 | { |
262 | 14 | hci_h1_table = find_dissector_table("hci_h1.type"); |
263 | 14 | dissector_add_uint ("bluetooth.encap", WTAP_ENCAP_PACKETLOGGER, packetlogger_handle); |
264 | 14 | } |
265 | | |
266 | | /* |
267 | | * Editor modelines |
268 | | * |
269 | | * Local Variables: |
270 | | * c-basic-offset: 2 |
271 | | * tab-width: 8 |
272 | | * indent-tabs-mode: nil |
273 | | * End: |
274 | | * |
275 | | * ex: set shiftwidth=2 tabstop=8 expandtab: |
276 | | * :indentSize=2:tabSize=8:noTabs=true: |
277 | | */ |