/src/wireshark/epan/dissectors/packet-log3gpp.c
Line | Count | Source |
1 | | /* packet-log3gpp.c |
2 | | * Routines for dissecting phone logs containing 3GPP protocol messages. |
3 | | * Copyright 2008, Vincent Helfre |
4 | | * |
5 | | * Wireshark - Network traffic analyzer |
6 | | * By Gerald Combs <gerald@wireshark.org> |
7 | | * Copyright 1998 Gerald Combs |
8 | | * |
9 | | * SPDX-License-Identifier: GPL-2.0-or-later |
10 | | */ |
11 | | |
12 | | #include "config.h" |
13 | | |
14 | | #include <epan/packet.h> |
15 | | #include <epan/prefs.h> |
16 | | #include <epan/proto_data.h> |
17 | | #include <wiretap/wtap.h> |
18 | | #include <wsutil/strtoi.h> |
19 | | #include <wsutil/array.h> |
20 | | |
21 | | #include "packet-mac-lte.h" |
22 | | #include "packet-pdcp-lte.h" |
23 | | #include "packet-rlc-lte.h" |
24 | | |
25 | 0 | #define FD1 0 |
26 | 32 | #define REL8 1 |
27 | | |
28 | | void proto_register_log3gpp(void); |
29 | | void proto_reg_handoff_log3gpp(void); |
30 | | |
31 | | /* Protocol and registered fields. */ |
32 | | static int proto_log3gpp; |
33 | | |
34 | | |
35 | | static int hf_log3gpp_timestamp; |
36 | | static int hf_log3gpp_protocol; |
37 | | static int hf_log3gpp_direction; |
38 | | static int hf_log3gpp_dissector_option; |
39 | | static int hf_log3gpp_unparsed_data; |
40 | | static int hf_log3gpp_dissected_length; |
41 | | |
42 | | /* Protocol subtree. */ |
43 | | static int ett_log3gpp; |
44 | | |
45 | | /* Cached protocol identifiers */ |
46 | | static int proto_mac_lte; |
47 | | static int proto_rlc_lte; |
48 | | static int proto_pdcp_lte; |
49 | | |
50 | | |
51 | | /* Variables used to select a version for RRC and NAS */ |
52 | | static int lte_rrc_prot_version = REL8; |
53 | | static int nas_eps_prot_version = REL8; |
54 | | |
55 | | static const enum_val_t lte_rrc_dissector_version[] = { |
56 | | {"FD1", "FD1", FD1}, |
57 | | {"Rel8", "Rel8 dec 2008", REL8}, /* Add new dissector version after */ |
58 | | {NULL, NULL, -1} |
59 | | }; |
60 | | |
61 | | static const enum_val_t nas_eps_dissector_version[] = { |
62 | | {"FD1", "FD1", FD1}, |
63 | | {"Rel8", "Rel8 dec 2008", REL8}, /* Add new dissector version after */ |
64 | | {NULL, NULL, -1} |
65 | | }; |
66 | | |
67 | | typedef enum packet_direction_t |
68 | | { |
69 | | UPLINK, |
70 | | DOWNLINK |
71 | | } packet_direction_t; |
72 | | |
73 | | static const value_string direction_vals[] = { |
74 | | { 0, "Uplink" }, |
75 | | { 1, "Downlink" }, |
76 | | { 0, NULL }, |
77 | | }; |
78 | | /* Pseudo header functions*/ |
79 | | typedef bool (*pseudo_hdr_func_ptr_t) (char *, packet_info *pinfo, uint16_t, packet_direction_t); |
80 | | |
81 | | static bool lte_mac_pseudo_hdr(char *, packet_info *pinfo, uint16_t, packet_direction_t); |
82 | | static bool lte_rlc_pseudo_hdr(char *, packet_info *pinfo, uint16_t, packet_direction_t); |
83 | | static bool lte_pdcp_pseudo_hdr(char *, packet_info *pinfo, uint16_t, packet_direction_t); |
84 | | |
85 | | typedef struct |
86 | | { |
87 | | const char * protocol_name; |
88 | | const char * ul_dissector_name; |
89 | | const char * dl_dissector_name; |
90 | | dissector_handle_t ul_dissector_handle; |
91 | | dissector_handle_t dl_dissector_handle; |
92 | | pseudo_hdr_func_ptr_t hdr_process; |
93 | | } lookup_dissector_element_t; |
94 | | |
95 | | /* Look up table for protocol name /dissector: should be in alphabetic order!!! |
96 | | the purpose is to match a protocol name with a dissector, |
97 | | and to store the dissector handle the first time to avoid looking it up every time. |
98 | | This table should contain all 3GPP specified protocols */ |
99 | | static lookup_dissector_element_t dissector_lookup_table[] = { |
100 | | {"DATA","data","data",0,0,NULL}, |
101 | | {"GAN.TCP","umatcp","umatcp",0,0,NULL}, |
102 | | {"GAN.UDP","umaudp","umaudp",0,0,NULL}, |
103 | | {"GSM.CCCH","gsm_a_ccch","gsm_a_ccch",0,0,NULL}, |
104 | | {"GSM.SACCH","gsm_a_sacch","gsm_a_sacch",0,0,NULL}, |
105 | | {"GTP","gtp","gtp",0,0,NULL}, |
106 | | {"LLC","llcgprs","llcgprs",0,0,NULL}, |
107 | | {"LTE-MAC","mac-lte","mac-lte",0,0, lte_mac_pseudo_hdr}, |
108 | | {"LTE-PDCP","pdcp-lte","pdcp-lte",0,0, lte_pdcp_pseudo_hdr}, |
109 | | {"LTE-RLC","rlc-lte","rlc-lte",0,0, lte_rlc_pseudo_hdr}, |
110 | | {"LTE-RRC.BCCH.BCH",0,0,0,0,NULL}, /* Dissector set according to preferences (depending on the release) */ |
111 | | {"LTE-RRC.BCCH.DL.SCH",0,0,0,0,NULL}, /* Dissector set according to preferences (depending on the release) */ |
112 | | {"LTE-RRC.CCCH",0,0,0,0,NULL}, /* Dissector set according to preferences (depending on the release) */ |
113 | | {"LTE-RRC.DCCH",0,0,0,0,NULL}, /* Dissector set according to preferences (depending on the release) */ |
114 | | {"LTE-RRC.PCCH",0,0,0,0,NULL}, /* Dissector set according to preferences (depending on the release) */ |
115 | | {"NAS","gsm_a_dtap","gsm_a_dtap",0,0,NULL}, |
116 | | {"NAS-EPS",0,0,0,0,NULL}, /* Dissector set according to preferences (depending on the release) */ |
117 | | {"RR","gsm_a_dtap","gsm_a_dtap",0,0,NULL}, |
118 | | {"RRC.BCCH.BCH","rrc.bcch.bch","rrc.bcch.bch",0,0,NULL}, |
119 | | {"RRC.BCCH.FACH","rrc.bcch.fach","rrc.bcch.fach",0,0,NULL}, |
120 | | {"RRC.CCCH","rrc.ul.ccch","rrc.dl.ccch",0,0,NULL}, |
121 | | {"RRC.DCCH","rrc.ul.dcch","rrc.dl.dcch",0,0,NULL}, |
122 | | {"RRC.MCCH","rrc.mcch","rrc.mcch",0,0,NULL}, |
123 | | {"RRC.MSCH","rrc.msch","rrc.msch",0,0,NULL}, |
124 | | {"RRC.PCCH","rrc.pcch","rrc.pcch",0,0,NULL}, |
125 | | {"RRC.SHCCH","rrc.ul.shcch","rrc.dl.shcch",0,0,NULL}, |
126 | | {"RRC.SI.MIB","rrc.si.mib","rrc.si.mib",0,0,NULL}, |
127 | | {"RRC.SI.SB1","rrc.sb1","rrc.sb1",0,0,NULL}, |
128 | | {"RRC.SI.SB2","rrc.sb2","rrc.sb2",0,0,NULL}, |
129 | | {"RRC.SI.SIB1","rrc.si.sib1","rrc.si.sib1",0,0,NULL}, |
130 | | {"RRC.SI.SIB10","rrc.si.sib10","rrc.si.sib10",0,0,NULL}, |
131 | | {"RRC.SI.SIB11","rrc.si.sib11","rrc.si.sib11",0,0,NULL}, |
132 | | {"RRC.SI.SIB11bis","rrc.si.sib11bis","rrc.si.sib11bis",0,0,NULL}, |
133 | | {"RRC.SI.SIB12","rrc.si.sib12","rrc.si.sib12",0,0,NULL}, |
134 | | {"RRC.SI.SIB13","rrc.si.sib13","rrc.si.sib13",0,0,NULL }, |
135 | | {"RRC.SI.SIB13-1","rrc.si.sib13-1","rrc.si.sib13-1",0,0,NULL}, |
136 | | {"RRC.SI.SIB13-2","rrc.si.sib13-2","rrc.si.sib13-2",0,0,NULL}, |
137 | | {"RRC.SI.SIB13-3","rrc.si.sib13-3","rrc.si.sib13-3",0,0,NULL }, |
138 | | {"RRC.SI.SIB13-4","rrc.si.sib13-4","rrc.si.sib13-4",0,0,NULL}, |
139 | | {"RRC.SI.SIB14","rrc.si.sib14","rrc.si.sib14",0,0,NULL}, |
140 | | {"RRC.SI.SIB15","rrc.si.sib15","rrc.si.sib15",0,0,NULL}, |
141 | | {"RRC.SI.SIB15-1","rrc.si.sib15-1","rrc.si.sib15-1",0,0,NULL}, |
142 | | {"RRC.SI.SIB15-1bis","rrc.si.sib15-1bis","rrc.si.sib15-1bis",0,0,NULL }, |
143 | | {"RRC.SI.SIB15-2","rrc.si.sib15-2","rrc.si.sib15-2",0,0,NULL}, |
144 | | {"RRC.SI.SIB15-2bis","rrc.si.sib15-2bis","rrc.si.sib15-2bis",0,0,NULL}, |
145 | | {"RRC.SI.SIB15-3","rrc.si.sib15-3","rrc.si.sib15-3",0,0,NULL}, |
146 | | {"RRC.SI.SIB15-3bis","rrc.si.sib15-3bis","rrc.si.sib15-3bis",0,0,NULL}, |
147 | | {"RRC.SI.SIB15-4","rrc.si.sib15-4","rrc.si.sib15-4",0,0,NULL}, |
148 | | {"RRC.SI.SIB15-5","rrc.si.sib15-5","rrc.si.sib15-5",0,0,NULL}, |
149 | | {"RRC.SI.SIB15-6","rrc.si.sib15-6","rrc.si.sib15-6",0,0,NULL}, |
150 | | {"RRC.SI.SIB15-7","rrc.si.sib15-7","rrc.si.sib15-7",0,0,NULL}, |
151 | | {"RRC.SI.SIB15-8","rrc.si.sib15-8","rrc.si.sib15-8",0,0,NULL}, |
152 | | {"RRC.SI.SIB15bis","rrc.si.sib15bis","rrc.si.sib15bis",0,0,NULL}, |
153 | | {"RRC.SI.SIB17","rrc.si.sib17","rrc.si.sib17",0,0,NULL}, |
154 | | {"RRC.SI.SIB18","rrc.si.sib18","rrc.si.sib18",0,0,NULL}, |
155 | | {"RRC.SI.SIB2","rrc.si.sib2","rrc.si.sib2",0,0,NULL}, |
156 | | {"RRC.SI.SIB3","rrc.si.sib3","rrc.si.sib3",0,0,NULL}, |
157 | | {"RRC.SI.SIB4","rrc.si.sib4","rrc.si.sib4",0,0,NULL}, |
158 | | {"RRC.SI.SIB5","rrc.si.sib5","rrc.si.sib5",0,0,NULL}, |
159 | | {"RRC.SI.SIB5bis","rrc.si.sib5bis","rrc.si.sib5bis",0,0,NULL}, |
160 | | {"RRC.SI.SIB6","rrc.si.sib6","rrc.si.sib6",0,0,NULL}, |
161 | | {"RRC.SI.SIB7","rrc.si.sib7","rrc.si.sib7",0,0,NULL}, |
162 | | {"RRC.SI.SIB8","rrc.si.sib8","rrc.si.sib8",0,0,NULL}, |
163 | | {"RRC.SI.SIB9","rrc.si.sib9","rrc.si.sib9",0,0,NULL}, |
164 | | {"SNDCP","sndcp","sndcp",0,0,NULL}, |
165 | | {"SNDCPXID","sndcpxid","sndcpxid",0,0,NULL} |
166 | | }; |
167 | | |
168 | | |
169 | | static int |
170 | | dissector_element_compare(const void *protocol_name, const void *element) |
171 | 896 | { |
172 | 896 | return strcmp((const char *)protocol_name, ((const lookup_dissector_element_t *) element)->protocol_name); |
173 | 896 | } |
174 | | |
175 | | static dissector_handle_t |
176 | | look_for_dissector(char* protocol_name, packet_direction_t direction, pseudo_hdr_func_ptr_t* func_ptr _U_) |
177 | 0 | { |
178 | 0 | lookup_dissector_element_t* element_ptr; |
179 | 0 | dissector_handle_t dissector_handle = NULL; |
180 | |
|
181 | 0 | element_ptr = (lookup_dissector_element_t*)bsearch((void*)protocol_name, |
182 | 0 | (void*)dissector_lookup_table, |
183 | 0 | array_length(dissector_lookup_table), |
184 | 0 | sizeof dissector_lookup_table[0], |
185 | 0 | dissector_element_compare); |
186 | 0 | if (element_ptr != NULL) { |
187 | 0 | if (direction == UPLINK) |
188 | 0 | { |
189 | 0 | if (element_ptr->ul_dissector_handle == 0) |
190 | 0 | { |
191 | 0 | element_ptr->ul_dissector_handle = find_dissector(element_ptr->ul_dissector_name); |
192 | 0 | } |
193 | 0 | dissector_handle = element_ptr->ul_dissector_handle; |
194 | 0 | } |
195 | 0 | else |
196 | 0 | { |
197 | 0 | if (element_ptr->dl_dissector_handle == 0) |
198 | 0 | { |
199 | 0 | element_ptr->dl_dissector_handle = find_dissector(element_ptr->dl_dissector_name); |
200 | 0 | } |
201 | 0 | dissector_handle = element_ptr->dl_dissector_handle; |
202 | 0 | } |
203 | |
|
204 | 0 | } |
205 | |
|
206 | 0 | return dissector_handle; |
207 | 0 | } |
208 | | |
209 | | static void |
210 | | update_dissector_name(const char* protocol_name, packet_direction_t direction, const char* dissector_name) |
211 | 192 | { |
212 | 192 | lookup_dissector_element_t* element_ptr; |
213 | | |
214 | 192 | element_ptr = (lookup_dissector_element_t*)bsearch((void*)protocol_name, |
215 | 192 | (void*)dissector_lookup_table, |
216 | 192 | array_length(dissector_lookup_table), |
217 | 192 | sizeof dissector_lookup_table[0], |
218 | 192 | dissector_element_compare); |
219 | 192 | if (element_ptr != NULL) { |
220 | 192 | if (direction == UPLINK) |
221 | 96 | { |
222 | 96 | element_ptr->ul_dissector_handle = 0; |
223 | 96 | element_ptr->ul_dissector_name = dissector_name; |
224 | 96 | } |
225 | 96 | else |
226 | 96 | { |
227 | 96 | element_ptr->dl_dissector_handle = 0; |
228 | 96 | element_ptr->dl_dissector_name = dissector_name; |
229 | 96 | } |
230 | | |
231 | 192 | } |
232 | 192 | } |
233 | | |
234 | | /******************************************************************************/ |
235 | | /* pseudo header functions: used for the dissectors that needs pseudo headers */ |
236 | | /******************************************************************************/ |
237 | | |
238 | | |
239 | | /* In the optional string, MAC info should be set as follow (M = mandatory, O = optional): |
240 | | * Radio type (M): "FDD" or "TDD" |
241 | | * RNTI type (M): "NO_RNTI" or "P_RNTI" or "RA_RNTI" or "C_RNTI" or "SI_RNT" followed by rnti value in decimal format |
242 | | * subframe number (M): "SFN" followed by the subframe number in decimal format |
243 | | */ |
244 | | static bool |
245 | | lte_mac_pseudo_hdr(char* option_str, packet_info* pinfo, uint16_t length, packet_direction_t direction) |
246 | 0 | { |
247 | 0 | struct mac_lte_info* p_mac_lte_info; |
248 | 0 | char* par_opt_field; |
249 | 0 | char option[30]; |
250 | | |
251 | | /* Need to copy the string in a local buffer since strtok will modify it */ |
252 | 0 | (void) g_strlcpy(option, option_str, 30); |
253 | | |
254 | | /* Only need to set info once per session. */ |
255 | 0 | p_mac_lte_info = (struct mac_lte_info*)p_get_proto_data(wmem_file_scope(), pinfo, proto_mac_lte, 0); |
256 | 0 | if (p_mac_lte_info != NULL) |
257 | 0 | { |
258 | 0 | return 1; |
259 | 0 | } |
260 | | |
261 | | /* Allocate & zero struct */ |
262 | 0 | p_mac_lte_info = (struct mac_lte_info*) wmem_new0(pinfo->pool, mac_lte_info); |
263 | | |
264 | | /* First mandatory parameter */ |
265 | 0 | par_opt_field = strtok(option, " "); |
266 | 0 | if (par_opt_field == NULL) |
267 | 0 | { |
268 | 0 | return 0; |
269 | 0 | } |
270 | 0 | if (strcmp(par_opt_field, "FDD") == 0) |
271 | 0 | { |
272 | 0 | p_mac_lte_info->radioType = FDD_RADIO; |
273 | 0 | } |
274 | 0 | else if (strcmp(par_opt_field, "TDD") == 0) |
275 | 0 | { |
276 | 0 | p_mac_lte_info->radioType = TDD_RADIO; |
277 | 0 | } |
278 | 0 | else |
279 | 0 | { |
280 | 0 | return 0; |
281 | 0 | } |
282 | | |
283 | | /* Second mandatory parameter */ |
284 | 0 | par_opt_field = strtok(NULL, " "); |
285 | 0 | if (par_opt_field == NULL) |
286 | 0 | { |
287 | 0 | return 0; |
288 | 0 | } |
289 | 0 | if (strcmp(par_opt_field, "NO_RNTI") == 0) |
290 | 0 | { |
291 | 0 | p_mac_lte_info->rntiType = NO_RNTI; |
292 | 0 | } |
293 | 0 | else if (strcmp(par_opt_field, "P_RNTI") == 0) |
294 | 0 | { |
295 | 0 | p_mac_lte_info->rntiType = P_RNTI; |
296 | 0 | } |
297 | 0 | else if (strcmp(par_opt_field, "RA_RNTI") == 0) |
298 | 0 | { |
299 | 0 | p_mac_lte_info->rntiType = RA_RNTI; |
300 | 0 | } |
301 | 0 | else if (strcmp(par_opt_field, "C_RNTI") == 0) |
302 | 0 | { |
303 | 0 | p_mac_lte_info->rntiType = C_RNTI; |
304 | 0 | } |
305 | 0 | else if (strcmp(par_opt_field, "SI_RNTI") == 0) |
306 | 0 | { |
307 | 0 | p_mac_lte_info->rntiType = SI_RNTI; |
308 | 0 | } |
309 | 0 | else |
310 | 0 | { |
311 | 0 | return 0; |
312 | 0 | } |
313 | | /* Get the associated rnti value */ |
314 | 0 | par_opt_field = strtok(NULL, " "); |
315 | 0 | if (par_opt_field) |
316 | 0 | { |
317 | 0 | ws_strtou16(par_opt_field, NULL, &p_mac_lte_info->rnti); |
318 | 0 | } |
319 | 0 | else |
320 | 0 | { |
321 | 0 | return 0; |
322 | 0 | } |
323 | | |
324 | | /* First optional parameter */ |
325 | 0 | p_mac_lte_info->subframeNumber = 0; |
326 | 0 | par_opt_field = strtok(NULL, " "); |
327 | 0 | if (par_opt_field == NULL) |
328 | 0 | { |
329 | 0 | return 0; |
330 | 0 | } |
331 | 0 | if (strcmp(par_opt_field, "SFN") == 0) |
332 | 0 | { |
333 | 0 | par_opt_field = strtok(NULL, " "); |
334 | 0 | if (par_opt_field != NULL) |
335 | 0 | { |
336 | 0 | ws_strtou16(par_opt_field, NULL, &p_mac_lte_info->subframeNumber); |
337 | 0 | } |
338 | 0 | } |
339 | 0 | p_mac_lte_info->direction = (direction == UPLINK) ? DIRECTION_UPLINK : DIRECTION_DOWNLINK; |
340 | 0 | p_mac_lte_info->length = length; |
341 | | |
342 | | /* Store info in packet */ |
343 | 0 | p_add_proto_data(wmem_file_scope(), pinfo, proto_mac_lte, 0, p_mac_lte_info); |
344 | |
|
345 | 0 | return 1; |
346 | 0 | } |
347 | | |
348 | | /* In the optional string, RLC info should be set as follow (M = mandatory, O = optional): |
349 | | * Channel type (M): "SRB" or "DRB" followed by the RB ID |
350 | | * RLC mode (M): "TM" or "UM" or "AM" or "NA" |
351 | | * UM Sequence nb length (O): "SN_5b" or "SN_10b" |
352 | | */ |
353 | | |
354 | | static bool |
355 | | lte_rlc_pseudo_hdr(char* option_str, packet_info* pinfo, uint16_t length, packet_direction_t direction) |
356 | 0 | { |
357 | 0 | struct rlc_lte_info* p_rlc_lte_info; |
358 | 0 | char* par_opt_field; |
359 | 0 | char option[30]; |
360 | |
|
361 | 0 | (void) g_strlcpy(option, option_str, 30); |
362 | | |
363 | | /* Only need to set info once per session. */ |
364 | 0 | p_rlc_lte_info = (struct rlc_lte_info*)p_get_proto_data(wmem_file_scope(), pinfo, proto_rlc_lte, 0); |
365 | 0 | if (p_rlc_lte_info != NULL) |
366 | 0 | { |
367 | 0 | return 1; |
368 | 0 | } |
369 | | |
370 | | /* Allocate & zero struct */ |
371 | 0 | p_rlc_lte_info = (struct rlc_lte_info*) wmem_new0(pinfo->pool, rlc_lte_info); |
372 | | /* First mandatory parameter */ |
373 | 0 | par_opt_field = strtok(option, " "); |
374 | 0 | if (par_opt_field == NULL) |
375 | 0 | { |
376 | 0 | return 0; |
377 | 0 | } |
378 | 0 | if (strcmp(par_opt_field, "SRB") == 0) |
379 | 0 | { |
380 | 0 | p_rlc_lte_info->channelType = CHANNEL_TYPE_SRB; |
381 | 0 | } |
382 | 0 | else if (strcmp(par_opt_field, "DRB") == 0) |
383 | 0 | { |
384 | 0 | p_rlc_lte_info->channelType = CHANNEL_TYPE_DRB; |
385 | 0 | } |
386 | 0 | else |
387 | 0 | { |
388 | 0 | return 0; |
389 | 0 | } |
390 | | /* Fill in the RB ID */ |
391 | 0 | par_opt_field = strtok(NULL, " "); |
392 | 0 | if (par_opt_field == NULL) |
393 | 0 | { |
394 | 0 | return 0; |
395 | 0 | } |
396 | 0 | ws_strtou16(par_opt_field, NULL, &p_rlc_lte_info->channelId); |
397 | | |
398 | | /* Second mandatory parameter */ |
399 | 0 | par_opt_field = strtok(NULL, " "); |
400 | 0 | if (par_opt_field == NULL) |
401 | 0 | { |
402 | 0 | return 0; |
403 | 0 | } |
404 | 0 | if (strcmp(par_opt_field, "TM") == 0) |
405 | 0 | { |
406 | 0 | p_rlc_lte_info->rlcMode = RLC_TM_MODE; |
407 | 0 | } |
408 | 0 | else if (strcmp(par_opt_field, "UM") == 0) |
409 | 0 | { |
410 | 0 | p_rlc_lte_info->rlcMode = RLC_UM_MODE; |
411 | 0 | } |
412 | 0 | else if (strcmp(par_opt_field, "AM") == 0) |
413 | 0 | { |
414 | 0 | p_rlc_lte_info->rlcMode = RLC_AM_MODE; |
415 | 0 | } |
416 | 0 | else if (strcmp(par_opt_field, "NA") == 0) |
417 | 0 | { |
418 | 0 | p_rlc_lte_info->rlcMode = RLC_PREDEF; |
419 | 0 | } |
420 | 0 | else |
421 | 0 | { |
422 | 0 | return 0; |
423 | 0 | } |
424 | | |
425 | | /* First optional parameter */ |
426 | 0 | par_opt_field = strtok(NULL, " "); |
427 | 0 | if (par_opt_field != NULL) |
428 | 0 | { |
429 | 0 | if (strcmp(par_opt_field, "SN_5b") == 0) |
430 | 0 | { |
431 | 0 | p_rlc_lte_info->sequenceNumberLength = UM_SN_LENGTH_5_BITS; |
432 | 0 | } |
433 | 0 | else if (strcmp(par_opt_field, "SN_10b") == 0) |
434 | 0 | { |
435 | 0 | p_rlc_lte_info->sequenceNumberLength = UM_SN_LENGTH_10_BITS; |
436 | 0 | } |
437 | 0 | } |
438 | 0 | p_rlc_lte_info->direction = (direction == UPLINK) ? DIRECTION_UPLINK : DIRECTION_DOWNLINK; |
439 | 0 | p_rlc_lte_info->priority = 0; |
440 | 0 | p_rlc_lte_info->ueid = 0; |
441 | 0 | p_rlc_lte_info->pduLength = length; |
442 | | |
443 | | /* Store info in packet */ |
444 | 0 | p_add_proto_data(wmem_file_scope(), pinfo, proto_rlc_lte, 0, p_rlc_lte_info); |
445 | |
|
446 | 0 | return 1; |
447 | 0 | } |
448 | | |
449 | | /* In the optional string, PDCP info should be set as follow (M = mandatory, O = optional): |
450 | | * Plane: "SRB" or "DRB" |
451 | | * Sequence number length: "SN_7b" or "SN_12b" |
452 | | */ |
453 | | static bool |
454 | | lte_pdcp_pseudo_hdr(char* option_str, packet_info* pinfo, uint16_t length _U_, packet_direction_t direction) |
455 | 0 | { |
456 | 0 | struct pdcp_lte_info* p_pdcp_lte_info; |
457 | 0 | char* par_opt_field; |
458 | 0 | char option[30]; |
459 | | |
460 | | /* look up for protocol handle */ |
461 | 0 | (void) g_strlcpy(option, option_str, 30); |
462 | | |
463 | | /* Only need to set info once per session. */ |
464 | 0 | p_pdcp_lte_info = (struct pdcp_lte_info*)p_get_proto_data(wmem_file_scope(), pinfo, proto_pdcp_lte, 0); |
465 | 0 | if (p_pdcp_lte_info != NULL) |
466 | 0 | { |
467 | 0 | return 1; |
468 | 0 | } |
469 | | |
470 | | /* Allocate & zero struct */ |
471 | 0 | p_pdcp_lte_info = (struct pdcp_lte_info*) wmem_new0(pinfo->pool, pdcp_lte_info); |
472 | | /* First mandatory parameter */ |
473 | 0 | par_opt_field = strtok(option, " "); |
474 | 0 | if (par_opt_field == NULL) |
475 | 0 | { |
476 | 0 | return 0; |
477 | 0 | } |
478 | 0 | if (strcmp(par_opt_field, "SRB") == 0) |
479 | 0 | { |
480 | 0 | p_pdcp_lte_info->plane = SIGNALING_PLANE; |
481 | 0 | } |
482 | 0 | else if (strcmp(par_opt_field, "DRB") == 0) |
483 | 0 | { |
484 | 0 | p_pdcp_lte_info->plane = USER_PLANE; |
485 | 0 | } |
486 | 0 | else |
487 | 0 | { |
488 | 0 | return 0; |
489 | 0 | } |
490 | | /* Second mandatory parameter */ |
491 | 0 | par_opt_field = strtok(NULL, " "); |
492 | 0 | if (par_opt_field == NULL) |
493 | 0 | { |
494 | 0 | return 0; |
495 | 0 | } |
496 | 0 | if (strcmp(par_opt_field, "SN_7b") == 0) |
497 | 0 | { |
498 | 0 | p_pdcp_lte_info->seqnum_length = PDCP_SN_LENGTH_7_BITS; |
499 | 0 | } |
500 | 0 | else if (strcmp(par_opt_field, "SN_12b") == 0) |
501 | 0 | { |
502 | 0 | p_pdcp_lte_info->seqnum_length = PDCP_SN_LENGTH_12_BITS; |
503 | 0 | } |
504 | 0 | else |
505 | 0 | { |
506 | 0 | return 0; |
507 | 0 | } |
508 | 0 | p_pdcp_lte_info->no_header_pdu = 0; |
509 | 0 | p_pdcp_lte_info->rohc.rohc_compression = 0; |
510 | 0 | p_pdcp_lte_info->direction = (direction == UPLINK) ? DIRECTION_UPLINK : DIRECTION_DOWNLINK; |
511 | | |
512 | | /* Store info in packet */ |
513 | 0 | p_add_proto_data(wmem_file_scope(), pinfo, proto_pdcp_lte, 0, p_pdcp_lte_info); |
514 | |
|
515 | 0 | return 1; |
516 | 0 | } |
517 | | |
518 | | |
519 | | /*****************************************/ |
520 | | /* Main dissection function. */ |
521 | | /*****************************************/ |
522 | | static int |
523 | | dissect_log3gpp(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree, void* data _U_) |
524 | 0 | { |
525 | 0 | proto_tree* prot3gpp_tree = NULL; |
526 | 0 | proto_item* ti = NULL; |
527 | 0 | int offset = 0; |
528 | 0 | int protocol_name_start; |
529 | 0 | int protocol_name_length; |
530 | 0 | int protocol_option_start; |
531 | 0 | int protocol_option_length; |
532 | 0 | int timestamp_start; |
533 | 0 | int timestamp_length; |
534 | 0 | packet_direction_t direction; |
535 | 0 | tvbuff_t* next_tvb; |
536 | 0 | dissector_handle_t protocol_handle = 0; |
537 | 0 | int sub_dissector_result = 0; |
538 | 0 | char* protocol_name; |
539 | 0 | char* protocol_option; |
540 | 0 | bool is_hex_data; |
541 | | |
542 | | /* Clear Info */ |
543 | 0 | col_clear(pinfo->cinfo, COL_INFO); |
544 | | |
545 | | /* Create root (protocol) tree. */ |
546 | 0 | ti = proto_tree_add_item(tree, proto_log3gpp, tvb, offset, -1, ENC_NA); |
547 | 0 | prot3gpp_tree = proto_item_add_subtree(ti, ett_log3gpp); |
548 | | |
549 | | /*********************************************************************/ |
550 | | /* Note that these are the fields of the stub header as written out */ |
551 | | /* by the wiretap module */ |
552 | | |
553 | | /* Timestamp in file */ |
554 | 0 | timestamp_start = offset; |
555 | 0 | timestamp_length = tvb_strsize(tvb, offset); |
556 | 0 | if (prot3gpp_tree) { |
557 | 0 | proto_tree_add_double_format_value(prot3gpp_tree, hf_log3gpp_timestamp, tvb, |
558 | 0 | offset, timestamp_length, |
559 | 0 | g_ascii_strtod(tvb_format_text(pinfo->pool, tvb, offset, timestamp_length), NULL), |
560 | 0 | "%s", tvb_format_text(pinfo->pool, tvb, offset, timestamp_length - 1)); |
561 | 0 | } |
562 | 0 | offset += timestamp_length; |
563 | | |
564 | | |
565 | | /* protocol name */ |
566 | 0 | protocol_name_start = offset; |
567 | 0 | protocol_name_length = tvb_strsize(tvb, offset); |
568 | 0 | if (prot3gpp_tree) { |
569 | 0 | proto_tree_add_item(prot3gpp_tree, hf_log3gpp_protocol, tvb, offset, protocol_name_length, ENC_ASCII); |
570 | 0 | } |
571 | 0 | offset += protocol_name_length; |
572 | | |
573 | | /* Direction */ |
574 | 0 | direction = (packet_direction_t)tvb_get_uint8(tvb, offset); |
575 | 0 | if (prot3gpp_tree) { |
576 | 0 | proto_tree_add_item(prot3gpp_tree, hf_log3gpp_direction, tvb, offset, 1, ENC_BIG_ENDIAN); |
577 | 0 | } |
578 | 0 | offset++; |
579 | | |
580 | | /* protocol option */ |
581 | 0 | protocol_option_start = offset; |
582 | 0 | protocol_option_length = tvb_strsize(tvb, offset); |
583 | 0 | if (prot3gpp_tree) { |
584 | 0 | proto_tree_add_item(prot3gpp_tree, hf_log3gpp_dissector_option, tvb, offset, protocol_option_length, ENC_ASCII); |
585 | 0 | } |
586 | 0 | offset += protocol_option_length; |
587 | |
|
588 | 0 | if (prot3gpp_tree) |
589 | 0 | { |
590 | | /* Set selection length of prot3gpp tree */ |
591 | 0 | proto_item_set_len(ti, offset); |
592 | 0 | } |
593 | | |
594 | | /* Add useful details to protocol tree label */ |
595 | 0 | protocol_name = (char*)tvb_get_string_enc(pinfo->pool, tvb, protocol_name_start, protocol_name_length, ENC_UTF_8 | ENC_NA); |
596 | | /* Set Protocol */ |
597 | 0 | col_add_str(pinfo->cinfo, COL_PROTOCOL, protocol_name); |
598 | | /* To know whether the data following is row byte stream or text data */ |
599 | 0 | is_hex_data = strcmp(protocol_name, "TXT"); |
600 | |
|
601 | 0 | proto_item_append_text(ti, " t=%s %c prot=%s", |
602 | 0 | tvb_get_string_enc(pinfo->pool, tvb, timestamp_start, timestamp_length, ENC_UTF_8 | ENC_NA), |
603 | 0 | (direction == 0) ? 'U' : 'D', |
604 | 0 | protocol_name); |
605 | |
|
606 | 0 | if (is_hex_data) |
607 | 0 | { |
608 | | /* We might need to prepend pseudo header for the dissector */ |
609 | 0 | pseudo_hdr_func_ptr_t func_ptr = NULL; |
610 | | |
611 | | /* Look up for the optional information */ |
612 | 0 | protocol_option = (char*)tvb_get_string_enc(pinfo->pool, tvb, protocol_option_start, protocol_option_length, ENC_UTF_8 | ENC_NA); |
613 | | |
614 | | /* look up for the right dissector handle */ |
615 | 0 | protocol_handle = look_for_dissector(protocol_name, direction, &func_ptr); |
616 | | |
617 | | /***********************************************************************/ |
618 | | /* Now hand off to the dissector of intended packet encapsulation type */ |
619 | | |
620 | | /* Try appropriate dissector, if one has been selected */ |
621 | 0 | if (protocol_handle != 0) |
622 | 0 | { |
623 | | /* Dissect the remainder of the frame using chosen protocol handle */ |
624 | 0 | next_tvb = tvb_new_subset_remaining(tvb, offset); |
625 | | |
626 | | /* This part is optional, only for dissector that need pseudo header information */ |
627 | 0 | if (func_ptr != NULL && strlen(protocol_option) != 0) |
628 | 0 | { |
629 | 0 | if (func_ptr(protocol_option, pinfo, offset, direction) == 0) |
630 | 0 | { |
631 | | /* There was an error, return */ |
632 | 0 | return tvb_reported_length(tvb); |
633 | 0 | } |
634 | 0 | } |
635 | 0 | sub_dissector_result = call_dissector(protocol_handle, next_tvb, pinfo, tree); |
636 | 0 | } |
637 | 0 | } |
638 | | |
639 | 0 | if (protocol_handle == 0 || sub_dissector_result == 0) |
640 | 0 | { |
641 | | /* Could get here because: |
642 | | - desired protocol is unavailable (probably disabled), OR |
643 | | - protocol rejected our data |
644 | | Show remaining bytes as unparsed data */ |
645 | 0 | proto_tree_add_item(prot3gpp_tree, hf_log3gpp_unparsed_data, tvb, offset, -1, ENC_NA); |
646 | |
|
647 | 0 | if (!is_hex_data) |
648 | 0 | { |
649 | 0 | col_add_str(pinfo->cinfo, COL_INFO, |
650 | 0 | (char*)tvb_get_string_enc(pinfo->pool, tvb, offset, tvb_reported_length_remaining(tvb, offset), ENC_UTF_8 | ENC_NA)); |
651 | 0 | } |
652 | 0 | else |
653 | 0 | { |
654 | 0 | col_add_fstr(pinfo->cinfo, COL_INFO, |
655 | 0 | "Not dissected ( t=%s %c prot=%s)", |
656 | 0 | tvb_get_string_enc(pinfo->pool, tvb, timestamp_start, timestamp_length, ENC_UTF_8 | ENC_NA), |
657 | 0 | (direction == 0) ? 'U' : 'D', |
658 | 0 | tvb_get_string_enc(pinfo->pool, tvb, protocol_name_start, protocol_name_length, ENC_UTF_8 | ENC_NA)); |
659 | 0 | } |
660 | 0 | } |
661 | 0 | else |
662 | 0 | { |
663 | | /* Show number of dissected bytes */ |
664 | 0 | proto_item* ti_local = proto_tree_add_uint(prot3gpp_tree, |
665 | 0 | hf_log3gpp_dissected_length, |
666 | 0 | tvb, 0, 0, tvb_reported_length(tvb) - offset); |
667 | 0 | proto_item_set_generated(ti_local); |
668 | 0 | } |
669 | 0 | return tvb_reported_length(tvb); |
670 | 0 | } |
671 | | |
672 | | /******************************************************************************/ |
673 | | /* Associate this protocol with the log3gpp file encapsulation type. */ |
674 | | /******************************************************************************/ |
675 | | void proto_reg_handoff_log3gpp(void) |
676 | 16 | { |
677 | 16 | static bool init = false; |
678 | | |
679 | 16 | if (init == false) |
680 | 16 | { |
681 | 16 | dissector_handle_t log3gpp_handle; |
682 | | |
683 | 16 | log3gpp_handle = find_dissector("prot3gpp"); |
684 | 16 | dissector_add_uint("wtap_encap", WTAP_ENCAP_LOG_3GPP, log3gpp_handle); |
685 | | |
686 | 16 | proto_mac_lte = proto_get_id_by_filter_name("mac-lte"); |
687 | 16 | proto_rlc_lte = proto_get_id_by_filter_name("rlc-lte"); |
688 | 16 | proto_pdcp_lte = proto_get_id_by_filter_name("pdcp-lte"); |
689 | | |
690 | 16 | init = true; |
691 | 16 | } |
692 | 16 | if (lte_rrc_prot_version == REL8) |
693 | 16 | { |
694 | 16 | update_dissector_name("LTE-RRC.BCCH.BCH", UPLINK, "lte-rrc.bcch.bch"); |
695 | 16 | update_dissector_name("LTE-RRC.BCCH.BCH", DOWNLINK, "lte-rrc.bcch.bch"); |
696 | 16 | update_dissector_name("LTE-RRC.BCCH.DL.SCH", UPLINK, "lte-rrc.bcch.dl.sch"); |
697 | 16 | update_dissector_name("LTE-RRC.BCCH.DL.SCH", DOWNLINK, "lte-rrc.bcch.dl.sch"); |
698 | 16 | update_dissector_name("LTE-RRC.CCCH", UPLINK, "lte-rrc.ul.ccch"); |
699 | 16 | update_dissector_name("LTE-RRC.CCCH", DOWNLINK, "lte-rrc.dl.ccch"); |
700 | 16 | update_dissector_name("LTE-RRC.DCCH", UPLINK, "lte-rrc.ul.dcch"); |
701 | 16 | update_dissector_name("LTE-RRC.DCCH", DOWNLINK, "lte-rrc.dl.dcch"); |
702 | 16 | update_dissector_name("LTE-RRC.PCCH", UPLINK, "lte-rrc.pcch"); |
703 | 16 | update_dissector_name("LTE-RRC.PCCH", DOWNLINK, "lte-rrc.pcch"); |
704 | 16 | } |
705 | 0 | else if (lte_rrc_prot_version == FD1) |
706 | 0 | { |
707 | 0 | update_dissector_name("LTE-RRC.BCCH.BCH", UPLINK, "lte-rrc-fd1.bcch.bch"); |
708 | 0 | update_dissector_name("LTE-RRC.BCCH.BCH", DOWNLINK, "lte-rrc-fd1.bcch.bch"); |
709 | 0 | update_dissector_name("LTE-RRC.BCCH.DL.SCH", UPLINK, "lte-rrc-fd1.bcch.dl.sch"); |
710 | 0 | update_dissector_name("LTE-RRC.BCCH.DL.SCH", DOWNLINK, "lte-rrc-fd1.bcch.dl.sch"); |
711 | 0 | update_dissector_name("LTE-RRC.CCCH", UPLINK, "lte-rrc-fd1.ul.ccch"); |
712 | 0 | update_dissector_name("LTE-RRC.CCCH", DOWNLINK, "lte-rrc-fd1.dl.ccch"); |
713 | 0 | update_dissector_name("LTE-RRC.DCCH", UPLINK, "lte-rrc-fd1.ul.dcch"); |
714 | 0 | update_dissector_name("LTE-RRC.DCCH", DOWNLINK, "lte-rrc-fd1.dl.dcch"); |
715 | 0 | update_dissector_name("LTE-RRC.PCCH", UPLINK, "lte-rrc-fd1.pcch"); |
716 | 0 | update_dissector_name("LTE-RRC.PCCH", DOWNLINK, "lte-rrc-fd1.pcch"); |
717 | 0 | } |
718 | 16 | if (nas_eps_prot_version == REL8) |
719 | 16 | { |
720 | 16 | update_dissector_name("NAS-EPS", UPLINK, "nas-eps"); |
721 | 16 | update_dissector_name("NAS-EPS", DOWNLINK, "nas-eps"); |
722 | 16 | } |
723 | 0 | else if (nas_eps_prot_version == FD1) |
724 | 0 | { |
725 | 0 | update_dissector_name("NAS-EPS", UPLINK, "nas-eps-fd1"); |
726 | 0 | update_dissector_name("NAS-EPS", DOWNLINK, "nas-eps-fd1"); |
727 | 0 | } |
728 | 16 | } |
729 | | |
730 | | /****************************************/ |
731 | | /* Register the protocol */ |
732 | | /****************************************/ |
733 | | void proto_register_log3gpp(void) |
734 | 16 | { |
735 | 16 | module_t *log3gpp_module; |
736 | 16 | static hf_register_info hf[] = |
737 | 16 | { |
738 | 16 | { &hf_log3gpp_timestamp, |
739 | 16 | { "Timestamp", |
740 | 16 | "log3gpp.timestamp", FT_DOUBLE, BASE_NONE, NULL, 0x0, |
741 | 16 | "File timestamp", HFILL |
742 | 16 | } |
743 | 16 | }, |
744 | 16 | { &hf_log3gpp_protocol, |
745 | 16 | { "3GPP protocol", |
746 | 16 | "log3gpp.protocol", FT_STRING, BASE_NONE, NULL, 0x0, |
747 | 16 | "Original 3GPP protocol name", HFILL |
748 | 16 | } |
749 | 16 | }, |
750 | 16 | { &hf_log3gpp_dissector_option, |
751 | 16 | { "option", |
752 | 16 | "log3gpp.option", FT_STRING, BASE_NONE, NULL, 0x0, |
753 | 16 | "Protocol option", HFILL |
754 | 16 | } |
755 | 16 | }, |
756 | 16 | { &hf_log3gpp_direction, |
757 | 16 | { "Direction", |
758 | 16 | "log3gpp.direction", FT_UINT8, BASE_DEC, VALS(direction_vals), 0x0, |
759 | 16 | "Frame direction (Uplink or Downlink)", HFILL |
760 | 16 | } |
761 | 16 | }, |
762 | 16 | { &hf_log3gpp_unparsed_data, |
763 | 16 | { "Unparsed protocol data", |
764 | 16 | "log3gpp.unparsed_data", FT_BYTES, BASE_NONE, NULL, 0x0, |
765 | 16 | "Unparsed 3GPP protocol data", HFILL |
766 | 16 | } |
767 | 16 | }, |
768 | 16 | { &hf_log3gpp_dissected_length, |
769 | 16 | { "Dissected length", |
770 | 16 | "log3gpp.dissected-length", FT_UINT16, BASE_DEC, NULL, 0x0, |
771 | 16 | "Number of bytes dissected by subdissector(s)", HFILL |
772 | 16 | } |
773 | 16 | }, |
774 | 16 | }; |
775 | | |
776 | 16 | static int *ett[] = |
777 | 16 | { |
778 | 16 | &ett_log3gpp |
779 | 16 | }; |
780 | | |
781 | | /* Register protocol. */ |
782 | 16 | proto_log3gpp = proto_register_protocol("3GPP log packet", |
783 | 16 | "LOG3GPP", |
784 | 16 | "log3gpp"); |
785 | 16 | proto_register_field_array(proto_log3gpp, hf, array_length(hf)); |
786 | 16 | proto_register_subtree_array(ett, array_length(ett)); |
787 | | |
788 | 16 | log3gpp_module = prefs_register_protocol(proto_log3gpp, proto_reg_handoff_log3gpp); |
789 | 16 | prefs_register_enum_preference(log3gpp_module, |
790 | 16 | "rrc_release_version", |
791 | 16 | "Select the release version of LTE RRC protocol", |
792 | 16 | "There might be plugins corresponding to different version of the specification " |
793 | 16 | "If they are present they should be listed here.", |
794 | 16 | <e_rrc_prot_version, |
795 | 16 | lte_rrc_dissector_version, |
796 | 16 | false); |
797 | | |
798 | 16 | prefs_register_enum_preference(log3gpp_module, |
799 | 16 | "nas_eps_release_version", |
800 | 16 | "Select the release version of NAS EPS protocol", |
801 | 16 | "There might be plugins corresponding to different version of the specification " |
802 | 16 | "If they are present they should be listed here.", |
803 | 16 | &nas_eps_prot_version, |
804 | 16 | nas_eps_dissector_version, |
805 | 16 | false); |
806 | | |
807 | | /* Allow dissector to find be found by name. */ |
808 | 16 | register_dissector("prot3gpp", dissect_log3gpp, proto_log3gpp); |
809 | 16 | } |
810 | | |
811 | | /* |
812 | | * Editor modelines - https://www.wireshark.org/tools/modelines.html |
813 | | * |
814 | | * Local variables: |
815 | | * c-basic-offset: 4 |
816 | | * tab-width: 8 |
817 | | * indent-tabs-mode: nil |
818 | | * End: |
819 | | * |
820 | | * vi: set shiftwidth=4 tabstop=8 expandtab: |
821 | | * :indentSize=4:tabSize=8:noTabs=true: |
822 | | */ |