Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-gsm_r_uus1.c
blob03a6dc41ba196e93fbccd91d93bd2d3a6b445701
1 /* packet-gsm_r_uus1.c
2 * Routines for GSM-R UUS1 dissection
4 * Copyright 2018, Michail Koreshkov <michail.koreshkov [at] bk.ru
6 * Reference [1]
7 * Railways Telecommunications (RT);
8 * Global System for Mobile communications (GSM);
9 * Usage of the User-to-User Information Element
10 * for GSM Operation on Railways
11 * (ETSI TS 102 610 V1.2.0 (2012-08))
13 * Reference [2]
14 * EIRENE SRS: "UIC Project EIRENE System Requirements Specification".
16 * Reference [3]
17 * MORANE F 10 T 6003 4: "FFFS for Presentation of Functional Numbers
18 * to Called and Calling Parties".
20 * Reference [4]
21 * eLDA IRS (V5.0): "Interface Requirements Specification
22 * enhanced Location Dependent Addressing".
24 * SPDX-License-Identifier: GPL-2.0-or-later
27 #include "config.h"
29 #include <epan/packet.h>
30 #include <epan/expert.h>
31 #include <epan/tfs.h>
32 #include <epan/prefs.h>
34 /* forward reference */
35 void proto_register_gsm_r_uus1(void);
36 void proto_reg_handoff_gsm_r_uus1(void);
39 /* Initialize the protocol and registered fields */
40 static int proto_gsm_r_uus1;
42 static int hf_gsm_r_uus1_elem_tag;
43 static int hf_gsm_r_uus1_elem_len;
44 static int hf_gsm_r_uus1_pfn;
45 static int hf_gsm_r_uus1_pfn_digits;
47 /* 5.2 and 5.3 */
48 static int hf_gsm_r_uus1_chpc;
49 static int hf_gsm_r_uus1_chpc_t_dur;
50 static int hf_gsm_r_uus1_chpc_t_rel;
51 static int hf_gsm_r_uus1_chpc_pl_call;
52 static int hf_gsm_r_uus1_chpc_cause;
53 static int hf_gsm_r_uus1_chpc_cause_power;
54 static int hf_gsm_r_uus1_chpc_cause_radio;
55 static int hf_gsm_r_uus1_chpc_cause_reserved3;
56 static int hf_gsm_r_uus1_chpc_cause_reserved4;
57 static int hf_gsm_r_uus1_chpc_cause_user_command;
58 static int hf_gsm_r_uus1_chpc_cause_reserved6;
59 static int hf_gsm_r_uus1_chpc_cause_reserved7;
60 static int hf_gsm_r_uus1_chpc_cause_reserved8;
61 static int hf_gsm_r_uus1_chpc_gref;
62 static int hf_gsm_r_uus1_chpc_ack_cause;
64 /* 5.4 */
65 static int hf_gsm_r_uus1_epfn;
67 /* 5.5 */
68 static int hf_gsm_r_uus1_present_text_str;
70 /* 5.6 */
71 static int hf_gsm_r_uus1_elda;
72 static int hf_gsm_r_uus1_elda_lat;
73 static int hf_gsm_r_uus1_elda_lat_deg;
74 static int hf_gsm_r_uus1_elda_lat_min;
75 static int hf_gsm_r_uus1_elda_lat_sec;
76 static int hf_gsm_r_uus1_elda_lat_hem;
77 static int hf_gsm_r_uus1_elda_long;
78 static int hf_gsm_r_uus1_elda_long_deg;
79 static int hf_gsm_r_uus1_elda_long_min;
80 static int hf_gsm_r_uus1_elda_long_sec;
81 static int hf_gsm_r_uus1_elda_long_hem;
82 static int hf_gsm_r_uus1_elda_height;
83 static int hf_gsm_r_uus1_elda_speed;
84 static int hf_gsm_r_uus1_elda_heading;
85 static int hf_gsm_r_uus1_elda_e_time;
86 static int hf_gsm_r_uus1_elda_distance;
87 static int hf_gsm_r_uus1_elda_scale;
88 static int hf_gsm_r_uus1_elda_spare;
90 /* 5.7 */
91 static int hf_gsm_r_uus1_present_dsd_alarm;
92 static int hf_gsm_r_uus1_present_dsd_alarm_loco_number;
94 /* 5.8 */
95 static int hf_gsm_r_uus1_alert_controller;
96 static int hf_gsm_r_uus1_alert_controller_gref;
98 /* Initialize the subtree pointers */
99 static int ett_gsm_r_uus1;
100 static int ett_gsm_r_uus1_pfn;
101 static int ett_gsm_r_uus1_chpc;
102 static int ett_gsm_r_uus1_chpc_cause;
103 static int ett_gsm_r_uus1_epfn;
104 static int ett_gsm_r_uus1_present_text_str;
105 static int ett_gsm_r_uus1_elda;
106 static int ett_gsm_r_uus1_elda_lat;
107 static int ett_gsm_r_uus1_elda_long;
108 static int ett_gsm_r_uus1_present_dsd_alarm;
109 static int ett_gsm_r_uus1_alert_controller;
112 /* Preferences */
113 static bool q931_u2u;
114 static bool gsm_a_u2u = true;
117 static expert_field ei_gsm_r_uus1_not_implemented_yet;
119 static const value_string gsm_r_uus1_tags[] = {
120 { 2, "Acknowledgement by Receiver of a HPC and response from device accepting the acknowledgement" },
121 { 3, "Acknowledgement by Initiator of a HPC" },
122 { 5, "Presentation of Functional Number" },
123 { 6, "enhanced Location Dependent Addressing" },
124 { 7, "enhanced Location Dependent Addressing (Reserved for future use)" },
125 { 8, "enhanced Location Dependent Addressing (Reserved for future use)" },
126 { 9, "ePFN Information" },
127 { 10, "User specific plain text according to alphabet indicator" },
128 { 11, "DSD Alarm Notification" },
129 { 12, "Alerting of a Controller Notification and Response" },
130 { 0, NULL }
135 * 5.1 Presentation of functional number
138 static uint16_t
139 de_gsm_r_uus1_pfn(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, uint32_t offset)
141 uint32_t curr_offset;
142 uint32_t len;
143 const char *fn_str;
144 proto_item *item;
145 proto_tree *sub_tree;
147 curr_offset = offset;
149 len = tvb_get_uint8(tvb, offset+1);
151 item = proto_tree_add_item(tree, hf_gsm_r_uus1_pfn, tvb, curr_offset, len+2, ENC_NA);
152 sub_tree = proto_item_add_subtree(item, ett_gsm_r_uus1_pfn);
154 proto_tree_add_item(sub_tree, hf_gsm_r_uus1_elem_tag, tvb, curr_offset, 1, ENC_NA);
155 proto_tree_add_item(sub_tree, hf_gsm_r_uus1_elem_len, tvb, curr_offset+1, 1, ENC_NA);
156 curr_offset += 2;
158 if(len == 0) {
159 proto_item_append_text(item, ": No FN Available");
160 }else {
161 fn_str = tvb_bcd_dig_to_str(pinfo->pool, tvb, offset+2, len, NULL, false);
162 proto_tree_add_string(sub_tree, hf_gsm_r_uus1_pfn_digits, tvb, curr_offset, len, fn_str);
163 proto_item_append_text(item, ": %s", fn_str);
165 curr_offset += len;
168 return (curr_offset - offset);
173 * 5.2 Confirmation of High Priority Calls
176 static const range_string gsm_r_uus1_chpc_priority_vals[] = {
177 { 0x00, 0x00, "no priority specified in call"},
178 { 0x01, 0x01, "eMLPP priority of 4 (Railway Information)"},
179 { 0x02, 0x02, "eMLPP priority of 3 (Railway Operation)"},
180 { 0x03, 0x03, "eMLPP priority of 2 (Public Emergency/Group Calls)"},
181 { 0x04, 0x04, "eMLPP priority of 1 (Command and Control)"},
182 { 0x05, 0x05, "eMLPP priority of 0 (Railway Emergency)"},
183 { 0x06, 0x07, "unknown" },
184 { 0, 0, NULL }
187 static uint16_t
188 de_gsm_r_uus1_chpc_forward(tvbuff_t *tvb, proto_tree *tree, uint32_t offset)
190 uint32_t curr_offset;
191 uint32_t len;
192 uint32_t t_dur;
193 uint32_t t_rel;
194 proto_item *item;
195 proto_tree *sub_tree;
197 curr_offset = offset;
199 len = tvb_get_uint8(tvb, offset+1);
201 item = proto_tree_add_item(tree, hf_gsm_r_uus1_chpc, tvb, curr_offset, len+2, ENC_NA);
202 sub_tree = proto_item_add_subtree(item, ett_gsm_r_uus1_chpc);
204 proto_tree_add_item(sub_tree, hf_gsm_r_uus1_elem_tag, tvb, curr_offset, 1, ENC_NA);
205 proto_tree_add_item(sub_tree, hf_gsm_r_uus1_elem_len, tvb, curr_offset+1, 1, ENC_NA);
206 curr_offset += 2;
208 t_dur = tvb_get_uint24(tvb, curr_offset, ENC_LITTLE_ENDIAN);
209 proto_tree_add_uint_format_value(sub_tree, hf_gsm_r_uus1_chpc_t_dur, tvb, curr_offset, 3, t_dur, "%d ms", t_dur*100);
210 curr_offset += 3;
212 t_rel = tvb_get_uint32(tvb, curr_offset, ENC_LITTLE_ENDIAN);
213 proto_tree_add_uint_format_value(sub_tree, hf_gsm_r_uus1_chpc_t_rel, tvb, curr_offset, 4, t_rel, "%d ms", t_rel*100);
214 curr_offset += 4;
216 proto_tree_add_item(sub_tree, hf_gsm_r_uus1_chpc_pl_call, tvb, curr_offset, 1, ENC_NA);
217 curr_offset += 1;
219 static int * const cause_flags[] = {
220 &hf_gsm_r_uus1_chpc_cause_power,
221 &hf_gsm_r_uus1_chpc_cause_radio,
222 &hf_gsm_r_uus1_chpc_cause_reserved3,
223 &hf_gsm_r_uus1_chpc_cause_reserved4,
224 &hf_gsm_r_uus1_chpc_cause_user_command,
225 &hf_gsm_r_uus1_chpc_cause_reserved6,
226 &hf_gsm_r_uus1_chpc_cause_reserved7,
227 &hf_gsm_r_uus1_chpc_cause_reserved8,
228 NULL
231 proto_tree_add_bitmask(sub_tree, tvb, curr_offset, hf_gsm_r_uus1_chpc_cause, ett_gsm_r_uus1_chpc_cause, cause_flags, ENC_NA);
232 curr_offset += 1;
234 proto_tree_add_item(sub_tree, hf_gsm_r_uus1_chpc_gref, tvb, curr_offset, 4, ENC_BCD_DIGITS_0_9|ENC_LITTLE_ENDIAN);
235 curr_offset += 4;
237 return (curr_offset - offset);
241 * 5.3 CHPC tag definition for collecting network device
243 * The tag is included in a RELEASE_COMPLETE message
244 * which shall have the release cause value of "Normal Call Clearing".
246 * gsm_a.dtap.msg_cc_type == 0x2a
248 static const range_string gsm_r_uus1_chpc_ack_cause_vals[] = {
249 { 0x00, 0x00, "ACK (no error)" },
250 { 0x01, 0x01, "NACK-1 (error, repetition should take place)" },
251 { 0x02, 0x7f, "Reserved for internal use" },
252 { 0x80, 0x80, "NACK-2 (fatal error, NO repetition to take place)" },
253 { 0x81, 0xff, "Reserved" },
254 { 0, 0, NULL }
257 static uint16_t
258 de_gsm_r_uus1_chpc_collect(tvbuff_t *tvb, proto_tree *tree, uint32_t offset)
260 proto_item *item;
261 proto_tree *sub_tree;
263 item = proto_tree_add_item(tree, hf_gsm_r_uus1_chpc, tvb, offset, 2, ENC_NA);
264 proto_item_set_text(item, "CHPC for collecting network device");
265 sub_tree = proto_item_add_subtree(item, ett_gsm_r_uus1_chpc);
267 proto_tree_add_item(sub_tree, hf_gsm_r_uus1_elem_tag, tvb, offset, 1, ENC_NA);
268 proto_tree_add_item(sub_tree, hf_gsm_r_uus1_chpc_ack_cause, tvb, offset+1, 1, ENC_NA);
270 return 2;
274 * Type of field depends on BSSAP message type. SETUP or RELEASE_COMPLETE
275 * But I don't know how to verify message type.
276 * That is why use length variable to find type of field
278 static uint16_t
279 de_gsm_r_uus1_chpc(tvbuff_t *tvb, proto_tree *tree, uint32_t offset)
281 uint8_t field_length;
282 field_length = tvb_get_uint8(tvb, offset+1);
283 if(field_length == 13)
284 return de_gsm_r_uus1_chpc_forward(tvb, tree, offset);
285 else
286 return de_gsm_r_uus1_chpc_collect(tvb, tree, offset);
290 * 5.4 Enhanced presentation of functional number
291 * (not implemented now)
293 static uint16_t
294 de_gsm_r_uus1_epfn(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo, uint32_t offset)
296 uint32_t curr_offset;
297 uint32_t len;
298 proto_item *item;
299 proto_tree *sub_tree;
301 curr_offset = offset;
303 len = tvb_get_uint8(tvb, offset+1);
305 item = proto_tree_add_item(tree, hf_gsm_r_uus1_epfn, tvb, curr_offset, len+2, ENC_NA);
306 sub_tree = proto_item_add_subtree(item, ett_gsm_r_uus1_epfn);
308 proto_tree_add_item(sub_tree, hf_gsm_r_uus1_elem_tag, tvb, curr_offset, 1, ENC_NA);
309 proto_tree_add_item(sub_tree, hf_gsm_r_uus1_elem_len, tvb, curr_offset+1, 1, ENC_NA);
310 curr_offset += 2;
312 proto_tree_add_expert(sub_tree, pinfo, &ei_gsm_r_uus1_not_implemented_yet, tvb, curr_offset, len);
313 curr_offset += len;
315 return (curr_offset - offset);
319 * 5.5 Presentation of text strings
320 * (not implemented now)
322 static uint16_t
323 de_gsm_r_uus1_text_str(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo, uint32_t offset)
325 uint32_t curr_offset;
326 uint32_t len;
327 proto_item *item;
328 proto_tree *sub_tree;
330 curr_offset = offset;
332 len = tvb_get_uint8(tvb, offset+1);
334 item = proto_tree_add_item(tree, hf_gsm_r_uus1_present_text_str, tvb, curr_offset, len+2, ENC_NA);
335 sub_tree = proto_item_add_subtree(item, ett_gsm_r_uus1_present_text_str);
337 proto_tree_add_item(sub_tree, hf_gsm_r_uus1_elem_tag, tvb, curr_offset, 1, ENC_NA);
338 proto_tree_add_item(sub_tree, hf_gsm_r_uus1_elem_len, tvb, curr_offset+1, 1, ENC_NA);
339 curr_offset += 2;
341 proto_tree_add_expert(sub_tree, pinfo, &ei_gsm_r_uus1_not_implemented_yet, tvb, curr_offset, len);
342 curr_offset += len;
344 return (curr_offset - offset);
348 * 5.6 Transfer of train position (eLDA)
351 static const true_false_string gsm_r_uus1_elda_lat_hem = {
352 "North",
353 "South"
356 static const true_false_string gsm_r_uus1_elda_long_hem = {
357 "West",
358 "East"
361 static const value_string gsm_r_uus1_elda_scale_vals[] = {
362 { 0, "10 cm resolution" },
363 { 1, "1 metre resolution" },
364 { 2, "10 metre resolution" },
365 { 3, "Odometry information not valid" },
366 { 0, NULL }
370 static uint16_t
371 de_gsm_r_uus1_elda(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_, uint32_t offset)
373 uint32_t curr_offset;
374 unsigned bit_offset;
376 uint32_t val;
377 uint32_t lat_deg_val;
378 uint32_t lat_min_val;
379 uint32_t lat_sec_val;
380 uint32_t lat_hem_val;
382 uint32_t long_deg_val;
383 uint32_t long_min_val;
384 uint32_t long_sec_val;
385 uint32_t long_hem_val;
387 uint32_t t_val;
389 proto_item *item;
390 proto_tree *sub_tree;
392 proto_item *lat_item;
393 proto_item *long_item;
394 proto_tree *lat_tree;
395 proto_tree *long_tree;
397 curr_offset = offset;
399 item = proto_tree_add_item(tree, hf_gsm_r_uus1_elda, tvb, curr_offset, 16, ENC_NA);
400 sub_tree = proto_item_add_subtree(item, ett_gsm_r_uus1_elda);
401 proto_tree_add_item(sub_tree, hf_gsm_r_uus1_elem_tag, tvb, curr_offset, 1, ENC_NA);
402 proto_tree_add_item(sub_tree, hf_gsm_r_uus1_elem_len, tvb, curr_offset+1, 1, ENC_NA);
403 curr_offset += 2;
405 bit_offset = curr_offset * 8;
407 /* Latitude */
408 lat_item = proto_tree_add_item(sub_tree, hf_gsm_r_uus1_elda_lat, tvb, curr_offset, 4, ENC_NA);
409 lat_tree = proto_item_add_subtree(lat_item, ett_gsm_r_uus1_elda_lat);
411 val = tvb_get_uint32(tvb, curr_offset, ENC_NA);
412 lat_deg_val = tvb_get_bits(tvb, bit_offset, 7, ENC_NA);
413 bit_offset += 7;
414 lat_min_val = tvb_get_bits(tvb, bit_offset, 6, ENC_NA);
415 bit_offset += 6;
416 lat_sec_val = tvb_get_bits(tvb, bit_offset, 13, ENC_NA);
417 bit_offset += 13;
418 lat_hem_val = tvb_get_bits(tvb, bit_offset, 1, ENC_NA);
419 bit_offset += 1;
421 proto_tree_add_uint(lat_tree, hf_gsm_r_uus1_elda_lat_deg, tvb, curr_offset, 4, val);
422 proto_tree_add_uint(lat_tree, hf_gsm_r_uus1_elda_lat_min, tvb, curr_offset, 4, val);
423 proto_tree_add_uint_format_value(lat_tree, hf_gsm_r_uus1_elda_lat_sec, tvb, curr_offset, 4, val, "%.2f", (float)(lat_sec_val)/100);
424 proto_tree_add_boolean(lat_tree, hf_gsm_r_uus1_elda_lat_hem, tvb, curr_offset, 4, val);
426 proto_item_set_text(lat_item, "Latitude: %d %d\'%.2f\"%s", lat_deg_val, lat_min_val, (float)(lat_sec_val)/100,
427 lat_hem_val ? "N" : "S");
429 curr_offset += 3;
431 /* Longitude */
432 long_item = proto_tree_add_item(sub_tree, hf_gsm_r_uus1_elda_long, tvb, curr_offset, 4, ENC_NA);
433 long_tree = proto_item_add_subtree(long_item, ett_gsm_r_uus1_elda_long);
435 val = tvb_get_uint32(tvb, curr_offset, ENC_NA);
436 long_deg_val = tvb_get_bits(tvb, bit_offset, 8, ENC_NA);
437 bit_offset += 8;
438 long_min_val = tvb_get_bits(tvb, bit_offset, 6, ENC_NA);
439 bit_offset += 6;
440 long_sec_val = tvb_get_bits(tvb, bit_offset, 13, ENC_NA);
441 bit_offset += 13;
442 long_hem_val = tvb_get_bits(tvb, bit_offset, 1, ENC_NA);
443 bit_offset += 1;
445 proto_tree_add_uint(long_tree, hf_gsm_r_uus1_elda_long_deg, tvb, curr_offset, 4, val);
446 proto_tree_add_uint(long_tree, hf_gsm_r_uus1_elda_long_min, tvb, curr_offset, 4, val);
447 proto_tree_add_uint_format_value(long_tree, hf_gsm_r_uus1_elda_long_sec, tvb, curr_offset, 4, val, "%.2f", (float)(long_sec_val)/100);
448 proto_tree_add_boolean(long_tree, hf_gsm_r_uus1_elda_long_hem, tvb, curr_offset, 4, val);
450 proto_item_set_text(long_item, "Longitude: %d %d\'%.2f\"%s", long_deg_val, long_min_val, (float)(long_sec_val)/100,
451 long_hem_val ? "W" : "E");
453 curr_offset += 3;
455 /* Height, Speed, Heading */
457 // height step 1m. Range: -100m...+4500m
458 t_val = tvb_get_bits(tvb, bit_offset, 13, ENC_NA) - 100;
459 proto_tree_add_int(sub_tree, hf_gsm_r_uus1_elda_height, tvb, curr_offset, 4, t_val);
460 bit_offset += 13;
462 // speed step 10 km/h
463 t_val = tvb_get_bits(tvb, bit_offset, 6, ENC_NA) * 10;
464 proto_tree_add_uint(sub_tree, hf_gsm_r_uus1_elda_speed, tvb, curr_offset, 4, t_val);
465 bit_offset += 6;
467 // heading step 10 deg
468 t_val = tvb_get_bits(tvb, bit_offset, 6, ENC_NA) * 10;
469 proto_tree_add_uint(sub_tree, hf_gsm_r_uus1_elda_heading, tvb, curr_offset, 4, t_val);
470 bit_offset += 6;
472 curr_offset += 4;
474 /* Elapsed Time, Distance, Scale, Spare */
476 // time step 1 second. Range: 0...2047
477 t_val = tvb_get_bits(tvb, bit_offset, 11, ENC_NA);
478 proto_tree_add_uint(sub_tree, hf_gsm_r_uus1_elda_e_time, tvb, curr_offset, 4, t_val);
479 bit_offset += 11;
481 // distance step = 10 cm, 1 m or 10 m depending on the parameter Scale
482 t_val = tvb_get_bits(tvb, bit_offset, 14, ENC_NA);
483 proto_tree_add_uint(sub_tree, hf_gsm_r_uus1_elda_distance, tvb, curr_offset, 4, t_val);
484 bit_offset += 14;
486 // scale
487 t_val = tvb_get_bits(tvb, bit_offset, 2, ENC_NA);
488 proto_tree_add_uint(sub_tree, hf_gsm_r_uus1_elda_scale, tvb, curr_offset, 4, t_val);
489 bit_offset += 2;
491 // spare
492 t_val = tvb_get_bits(tvb, bit_offset, 5, ENC_NA);
493 proto_tree_add_uint(sub_tree, hf_gsm_r_uus1_elda_spare, tvb, curr_offset, 4, t_val);
495 return 16;
499 * 5.7 Notification DSD alarm condition
502 static uint16_t
503 de_gsm_r_uus1_dsd_alarm(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_, uint32_t offset)
505 uint32_t curr_offset;
506 uint32_t len;
507 const char *loco_engine_number;
508 proto_item *item;
509 proto_tree *sub_tree;
511 curr_offset = offset;
513 len = tvb_get_uint8(tvb, offset+1);
515 item = proto_tree_add_item(tree, hf_gsm_r_uus1_present_dsd_alarm, tvb, curr_offset, len+2, ENC_NA);
516 sub_tree = proto_item_add_subtree(item, ett_gsm_r_uus1_present_dsd_alarm);
518 proto_tree_add_item(sub_tree, hf_gsm_r_uus1_elem_tag, tvb, curr_offset, 1, ENC_NA);
519 proto_tree_add_item(sub_tree, hf_gsm_r_uus1_elem_len, tvb, curr_offset+1, 1, ENC_NA);
520 curr_offset += 2;
522 loco_engine_number = tvb_bcd_dig_to_str(pinfo->pool, tvb, offset+2, len, NULL, false);
523 proto_tree_add_string(sub_tree, hf_gsm_r_uus1_present_dsd_alarm_loco_number, tvb, curr_offset, len, loco_engine_number);
524 proto_item_append_text(item, ": %s", loco_engine_number);
525 curr_offset += len;
527 return (curr_offset - offset);
532 * 5.8 Notification of a request to alert a controller
535 static uint16_t
536 de_gsm_r_uus1_alert_controller(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_, uint32_t offset)
538 uint32_t curr_offset;
539 uint32_t len;
540 proto_item *item;
541 proto_tree *sub_tree;
542 char *gref_str;
544 curr_offset = offset;
546 len = tvb_get_uint8(tvb, offset+1);
548 item = proto_tree_add_item(tree, hf_gsm_r_uus1_alert_controller, tvb, curr_offset+2, len, ENC_NA);
549 sub_tree = proto_item_add_subtree(item, ett_gsm_r_uus1_alert_controller);
551 proto_tree_add_item(sub_tree, hf_gsm_r_uus1_elem_tag, tvb, curr_offset, 1, ENC_NA);
552 proto_tree_add_item(sub_tree, hf_gsm_r_uus1_elem_len, tvb, curr_offset+1, 1, ENC_NA);
553 curr_offset += 2;
555 proto_tree_add_item_ret_display_string(sub_tree, hf_gsm_r_uus1_alert_controller_gref, tvb, curr_offset, 4, ENC_BCD_DIGITS_0_9|ENC_LITTLE_ENDIAN, pinfo->pool, &gref_str);
556 proto_item_append_text(item, ": %s", gref_str);
557 curr_offset += 4;
559 return (curr_offset - offset);
563 static int
564 dissect_gsm_r_uus1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
566 uint8_t elem_tag;
567 uint32_t offset;
568 uint32_t len;
569 proto_item *gsm_r_uus1_item = NULL;
570 proto_tree *gsm_r_uus1_tree = NULL;
572 offset = 0;
573 len = tvb_captured_length(tvb);
575 gsm_r_uus1_item =
576 proto_tree_add_protocol_format(tree, proto_gsm_r_uus1, tvb, 0, len, "GSM-R User-to-User Signaling");
578 gsm_r_uus1_tree = proto_item_add_subtree(gsm_r_uus1_item, ett_gsm_r_uus1);
580 while (offset < len){
581 elem_tag = tvb_get_uint8(tvb, offset);
582 switch (elem_tag) {
583 case 2:
584 case 3:
585 offset += de_gsm_r_uus1_chpc(tvb, gsm_r_uus1_tree, offset);
586 break;
587 case 5:
588 offset += de_gsm_r_uus1_pfn(tvb, pinfo, gsm_r_uus1_tree, offset);
589 break;
590 case 6:
591 case 7:
592 case 8:
593 offset += de_gsm_r_uus1_elda(tvb, gsm_r_uus1_tree, pinfo, offset);
594 break;
595 case 9:
596 offset += de_gsm_r_uus1_epfn(tvb, gsm_r_uus1_tree, pinfo, offset);
597 break;
598 case 10:
599 offset += de_gsm_r_uus1_text_str(tvb, gsm_r_uus1_tree, pinfo, offset);
600 break;
601 case 11:
602 offset += de_gsm_r_uus1_dsd_alarm(tvb, gsm_r_uus1_tree, pinfo, offset);
603 break;
604 case 12:
605 offset += de_gsm_r_uus1_alert_controller(tvb, gsm_r_uus1_tree, pinfo, offset);
606 break;
607 default:
608 return offset;
612 return offset;
615 /* heuristic dissector */
616 static bool
617 dissect_gsm_r_uus1_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
619 if (dissect_gsm_r_uus1(tvb, pinfo, tree, data) > 0)
620 return false;
622 return true;
626 /* Register the protocol with Wireshark */
627 void
628 proto_register_gsm_r_uus1(void)
630 /* Setup list of header fields */
632 static hf_register_info hf[] = {
633 { &hf_gsm_r_uus1_elem_tag,
634 { "Element tag", "gsm-r-uus1.elem_tag",
635 FT_UINT8, BASE_DEC, VALS(gsm_r_uus1_tags), 0x0,
636 NULL, HFILL }
638 { &hf_gsm_r_uus1_elem_len,
639 { "Length", "gsm-r-uus1.elem_len",
640 FT_UINT8, BASE_DEC, NULL, 0x0,
641 NULL, HFILL }
643 { &hf_gsm_r_uus1_pfn,
644 { "Presentation of Functional Number (PFN)", "gsm-r-uus1.pfn",
645 FT_NONE, BASE_NONE, NULL, 0x0,
646 NULL, HFILL }
648 { &hf_gsm_r_uus1_pfn_digits,
649 { "Digits", "gsm-r-uus1.pfn.digits",
650 FT_STRING, BASE_NONE, NULL, 0x0,
651 NULL, HFILL }
653 { &hf_gsm_r_uus1_chpc,
654 { "Confirmation of High Priority Calls (CHPC)", "gsm-r-uus1.chpc",
655 FT_NONE, BASE_NONE, NULL, 0x0,
656 NULL, HFILL }
658 { &hf_gsm_r_uus1_chpc_t_dur,
659 { "Duration of the call", "gsm-r-uus1.chpc.t_dur",
660 FT_UINT24, BASE_DEC, NULL, 0x0,
661 NULL, HFILL }
663 { &hf_gsm_r_uus1_chpc_t_rel,
664 { "Interval between the end of the call and the transmission of the confirmation message", "gsm-r-uus1.chpc.t_rel",
665 FT_UINT32, BASE_DEC, NULL, 0x0,
666 NULL, HFILL }
668 { &hf_gsm_r_uus1_chpc_pl_call,
669 { "Priority level of the call", "gsm-r-uus1.chpc.pl_call",
670 FT_UINT8, BASE_DEC|BASE_RANGE_STRING, RVALS(gsm_r_uus1_chpc_priority_vals), 0x0,
671 NULL, HFILL }
673 { &hf_gsm_r_uus1_chpc_cause,
674 { "Reason for termination of the call", "gsm-r-uus1.chpc.cause",
675 FT_UINT8, BASE_HEX, NULL, 0x0,
676 NULL, HFILL }
678 { &hf_gsm_r_uus1_chpc_cause_power,
679 { "Mobile was powered off when receiving (power fail)", "gsm-r-uus1.chpc.cause.power",
680 FT_BOOLEAN, 8, NULL, 0x01,
681 NULL, HFILL }
683 { &hf_gsm_r_uus1_chpc_cause_radio,
684 { "Call was interrupted due to radio link error", "gsm-r-uus1.chpc.cause.radio",
685 FT_BOOLEAN, 8, NULL, 0x02,
686 NULL, HFILL }
688 { &hf_gsm_r_uus1_chpc_cause_reserved3,
689 { "Reserved", "gsm-r-uus1.chpc.cause.reserved3",
690 FT_BOOLEAN, 8, NULL, 0x04,
691 NULL, HFILL }
693 { &hf_gsm_r_uus1_chpc_cause_reserved4,
694 { "Reserved", "gsm-r-uus1.chpc.cause.reserved4",
695 FT_BOOLEAN, 8, NULL, 0x08,
696 NULL, HFILL }
698 { &hf_gsm_r_uus1_chpc_cause_user_command,
699 { "Call was left on user command", "gsm-r-uus1.chpc.cause.user_command",
700 FT_BOOLEAN, 8, NULL, 0x10,
701 NULL, HFILL }
703 { &hf_gsm_r_uus1_chpc_cause_reserved6,
704 { "Reserved", "gsm-r-uus1.chpc.cause.reserved6",
705 FT_BOOLEAN, 8, NULL, 0x20,
706 NULL, HFILL }
708 { &hf_gsm_r_uus1_chpc_cause_reserved7,
709 { "Reserved", "gsm-r-uus1.chpc.cause.reserved7",
710 FT_BOOLEAN, 8, NULL, 0x40,
711 NULL, HFILL }
713 { &hf_gsm_r_uus1_chpc_cause_reserved8,
714 { "Reserved", "gsm-r-uus1.chpc.cause.reserved8",
715 FT_BOOLEAN, 8, NULL, 0x80,
716 NULL, HFILL }
718 { &hf_gsm_r_uus1_chpc_gref,
719 { "Group call reference", "gsm-r-uus1.chpc.gref",
720 FT_STRING, BASE_NONE, NULL, 0x0,
721 NULL, HFILL }
723 { &hf_gsm_r_uus1_chpc_ack_cause,
724 { "ACK/CAUSE", "gsm-r-uus1.chpc.ack_cause",
725 FT_UINT8, BASE_DEC|BASE_RANGE_STRING, RVALS(gsm_r_uus1_chpc_ack_cause_vals), 0x0,
726 NULL, HFILL }
728 { &hf_gsm_r_uus1_epfn,
729 { "Enhanced presentation of functional number (ePFN)", "gsm-r-uus1.epfn",
730 FT_BYTES, BASE_NONE, NULL, 0x0,
731 NULL, HFILL }
733 { &hf_gsm_r_uus1_present_text_str,
734 { "Presentation of text strings", "gsm-r-uus1.present_text_str",
735 FT_BYTES, BASE_NONE, NULL, 0x0,
736 NULL, HFILL }
738 { &hf_gsm_r_uus1_elda,
739 { "Train position (eLDA)", "gsm-r-uus1.elda",
740 FT_NONE, BASE_NONE, NULL, 0x0,
741 NULL, HFILL }
743 { &hf_gsm_r_uus1_elda_lat,
744 { "Latitude", "gsm-r-uus1.elda.lat",
745 FT_NONE, BASE_NONE, NULL, 0x0,
746 NULL, HFILL }
748 { &hf_gsm_r_uus1_elda_lat_deg,
749 { "Degrees", "gsm-r-uus1.elda.lat.deg",
750 FT_UINT32, BASE_DEC, NULL, 0xFE000000,
751 NULL, HFILL }
753 { &hf_gsm_r_uus1_elda_lat_min,
754 { "Minutes", "gsm-r-uus1.elda.lat.min",
755 FT_UINT32, BASE_DEC, NULL, 0x01F80000,
756 NULL, HFILL }
758 { &hf_gsm_r_uus1_elda_lat_sec,
759 { "Seconds", "gsm-r-uus1.elda.lat.sec",
760 FT_UINT32, BASE_DEC, NULL, 0x0007FFC0,
761 NULL, HFILL }
763 { &hf_gsm_r_uus1_elda_lat_hem,
764 { "Hemisphere", "gsm-r-uus1.elda.lat.hem",
765 FT_BOOLEAN, 32, TFS(&gsm_r_uus1_elda_lat_hem), 0x00000020,
766 NULL, HFILL }
768 { &hf_gsm_r_uus1_elda_long,
769 { "Latitude", "gsm-r-uus1.elda.long",
770 FT_NONE, BASE_NONE, NULL, 0x0,
771 NULL, HFILL }
773 { &hf_gsm_r_uus1_elda_long_deg,
774 { "Degrees", "gsm-r-uus1.elda.long.deg",
775 FT_UINT32, BASE_DEC, NULL, 0x1FE00000,
776 NULL, HFILL }
778 { &hf_gsm_r_uus1_elda_long_min,
779 { "Minutes", "gsm-r-uus1.elda.long.min",
780 FT_UINT32, BASE_DEC, NULL, 0x001F8000,
781 NULL, HFILL }
783 { &hf_gsm_r_uus1_elda_long_sec,
784 { "Seconds", "gsm-r-uus1.elda_long.sec",
785 FT_UINT32, BASE_DEC, NULL, 0x00007FFC,
786 NULL, HFILL }
788 { &hf_gsm_r_uus1_elda_long_hem,
789 { "Hemisphere", "gsm-r-uus1.elda_long.hem",
790 FT_BOOLEAN, 32, TFS(&gsm_r_uus1_elda_long_hem), 0x00000002,
791 NULL, HFILL }
793 { &hf_gsm_r_uus1_elda_height,
794 { "Height (m)", "gsm-r-uus1.elda.height",
795 FT_INT32, BASE_DEC, NULL, 0x0,
796 NULL, HFILL }
798 { &hf_gsm_r_uus1_elda_speed,
799 { "Speed (km/h)", "gsm-r-uus1.elda.speed",
800 FT_UINT32, BASE_DEC, NULL, 0x0,
801 NULL, HFILL }
803 { &hf_gsm_r_uus1_elda_heading,
804 { "Heading (deg)", "gsm-r-uus1.elda.heading",
805 FT_UINT8, BASE_DEC, NULL, 0x0,
806 NULL, HFILL }
808 { &hf_gsm_r_uus1_elda_e_time,
809 { "Elapsed Time (sec)", "gsm-r-uus1.elda.e_time",
810 FT_UINT32, BASE_DEC, NULL, 0x0,
811 NULL, HFILL }
813 { &hf_gsm_r_uus1_elda_distance,
814 { "Distance", "gsm-r-uus1.elda.distance",
815 FT_UINT32, BASE_DEC, NULL, 0x0,
816 NULL, HFILL }
818 { &hf_gsm_r_uus1_elda_scale,
819 { "Scale", "gsm-r-uus1.elda.scale",
820 FT_UINT32, BASE_DEC, VALS(gsm_r_uus1_elda_scale_vals), 0x00,
821 NULL, HFILL }
823 { &hf_gsm_r_uus1_elda_spare,
824 { "Spare", "gsm-r-uus1.elda.spare",
825 FT_UINT32, BASE_DEC, NULL, 0x0,
826 NULL, HFILL }
828 { &hf_gsm_r_uus1_present_dsd_alarm,
829 { "Notification DSD alarm condition", "gsm-r-uus1.present_dsd_alarm",
830 FT_NONE, BASE_NONE, NULL, 0x0,
831 NULL, HFILL }
833 { &hf_gsm_r_uus1_present_dsd_alarm_loco_number,
834 { "Locomotive engine number", "gsm-r-uus1.present_dsd_alarm.loco_number",
835 FT_STRING, BASE_NONE, NULL, 0x0,
836 NULL, HFILL }
838 { &hf_gsm_r_uus1_alert_controller,
839 { "Notification of a request to alert a controller", "gsm-r-uus1.alert_controller",
840 FT_NONE, BASE_NONE, NULL, 0x0,
841 NULL, HFILL }
843 { &hf_gsm_r_uus1_alert_controller_gref,
844 { "Group call reference", "gsm-r-uus1.alert_controller.gref",
845 FT_STRING, BASE_NONE, NULL, 0x0,
846 NULL, HFILL }
850 static ei_register_info ei[] = {
851 { &ei_gsm_r_uus1_not_implemented_yet, { "gsm-r-uus1.not_implemented_yet", PI_UNDECODED, PI_NOTE, "Not implemented yet", EXPFILL }},
854 expert_module_t* expert_gsm_r_uus1;
856 static int *ett[] = {
857 &ett_gsm_r_uus1,
858 &ett_gsm_r_uus1_pfn,
859 &ett_gsm_r_uus1_chpc,
860 &ett_gsm_r_uus1_chpc_cause,
861 &ett_gsm_r_uus1_epfn,
862 &ett_gsm_r_uus1_present_text_str,
863 &ett_gsm_r_uus1_elda,
864 &ett_gsm_r_uus1_elda_lat,
865 &ett_gsm_r_uus1_elda_long,
866 &ett_gsm_r_uus1_present_dsd_alarm,
867 &ett_gsm_r_uus1_alert_controller
870 module_t *gsm_r_uus1_module;
872 /* Register the protocol name and description */
873 proto_gsm_r_uus1 =
874 proto_register_protocol("GSM-R User-to-User Signaling", "GSM-R", "gsm-r-uus1");
876 proto_register_field_array(proto_gsm_r_uus1, hf, array_length(hf));
878 proto_register_subtree_array(ett, array_length(ett));
880 expert_gsm_r_uus1 = expert_register_protocol(proto_gsm_r_uus1);
881 expert_register_field_array(expert_gsm_r_uus1, ei, array_length(ei));
883 /* subdissector code */
884 register_dissector("gsm-r-uus1", dissect_gsm_r_uus1, proto_gsm_r_uus1);
886 gsm_r_uus1_module = prefs_register_protocol(proto_gsm_r_uus1, proto_reg_handoff_gsm_r_uus1);
887 prefs_register_bool_preference(gsm_r_uus1_module, "dissect_q931_u2u",
888 "Dissect Q.931 User-To-User information",
889 "Dissect Q.931 User-To-User information",
890 &q931_u2u);
891 prefs_register_bool_preference(gsm_r_uus1_module, "dissect_gsm_a_u2u",
892 "Dissect GSM-A User-To-User information",
893 "Dissect GSM-A User-To-User information",
894 &gsm_a_u2u);
897 void
898 proto_reg_handoff_gsm_r_uus1(void)
900 dissector_handle_t gsm_r_uus1_handle;
902 gsm_r_uus1_handle = find_dissector("gsm-r-uus1");
904 if(q931_u2u){
905 heur_dissector_add("q931_user", dissect_gsm_r_uus1_heur, "GSM-R over UUS1", "gsm_r_uus1", proto_gsm_r_uus1, HEURISTIC_ENABLE);
906 } else {
907 heur_dissector_delete("q931_user", dissect_gsm_r_uus1_heur, proto_gsm_r_uus1);
911 if(gsm_a_u2u){
912 dissector_add_uint("gsm_a.dtap.u2u_prot_discr", 0, gsm_r_uus1_handle);
913 } else {
914 dissector_delete_uint("gsm_a.dtap.u2u_prot_discr", 0, gsm_r_uus1_handle);
919 * Editor modelines - https://www.wireshark.org/tools/modelines.html
921 * Local variables:
922 * c-basic-offset: 4
923 * tab-width: 8
924 * indent-tabs-mode: nil
925 * End:
927 * vi: set shiftwidth=4 tabstop=8 expandtab:
928 * :indentSize=4:tabSize=8:noTabs=true: