epan/dissectors/pidl/ C99 drsuapi
[wireshark-sm.git] / epan / dissectors / asn1 / ieee1609dot2 / packet-ieee1609dot2-template.c
blob85ae09cfba8665d179489e484baad6758fff9691
1 /* packet-IEEE1609dot2.c
2 * Routines for IEEE 1609.2
3 * Copyright 2018, Anders Broman <anders.broman@ericsson.com>
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * SPDX-License-Identifier: GPL-2.0-or-later
12 /* Also contains IEEE std 1609.12
13 * section 4.1.3 PSID allocations
16 #include "config.h"
18 #include <stdlib.h>
19 #include <time.h>
21 #include <epan/packet.h>
22 #include <epan/conversation.h>
23 #include <epan/oids.h>
24 #include <epan/asn1.h>
25 #include <epan/proto_data.h>
26 #include <wsutil/array.h>
28 #include "packet-oer.h"
29 #include "packet-ieee1609dot2.h"
31 #define PNAME "IEEE1609dot2"
32 #define PSNAME "IEEE1609dot2"
33 #define PFNAME "ieee1609dot2"
35 void proto_register_ieee1609dot2(void);
36 void proto_reg_handoff_ieee1609dot2(void);
38 /* Initialize the protocol and registered fields */
39 int proto_ieee1609dot2;
40 dissector_handle_t proto_ieee1609dot2_handle;
41 #include "packet-ieee1609dot2-hf.c"
43 /* Initialize the subtree pointers */
44 static int ett_ieee1609dot2_ssp;
45 #include "packet-ieee1609dot2-ett.c"
47 static dissector_table_t unsecured_data_subdissector_table;
48 static dissector_table_t ssp_subdissector_table;
50 typedef struct ieee1609_private_data {
51 tvbuff_t *unsecured_data;
52 uint64_t psidssp; // psid for Service Specific Permissions
53 } ieee1609_private_data_t;
55 void
56 ieee1609dot2_set_next_default_psid(packet_info *pinfo, uint32_t psid)
58 p_add_proto_data(wmem_file_scope(), pinfo, proto_ieee1609dot2, 0, GUINT_TO_POINTER(psid));
61 #include "packet-ieee1609dot2-fn.c"
64 static void
65 ieee1609dot2_NinetyDegreeInt_fmt(char *s, uint32_t v)
67 int32_t lat = (int32_t)v;
68 if (lat == 900000001) {
69 snprintf(s, ITEM_LABEL_LENGTH, "unavailable(%d)", lat);
70 } else {
71 snprintf(s, ITEM_LABEL_LENGTH, "%u°%u'%.3f\"%c (%d)",
72 abs(lat) / 10000000,
73 abs(lat) % 10000000 * 6 / 1000000,
74 abs(lat) % 10000000 * 6 % 1000000 * 6.0 / 100000.0,
75 (lat >= 0) ? 'N' : 'S',
76 lat);
80 static void
81 ieee1609dot2_OneEightyDegreeInt_fmt(char *s, uint32_t v)
83 int32_t lng = (int32_t)v;
84 if (lng == 1800000001) {
85 snprintf(s, ITEM_LABEL_LENGTH, "unavailable(%d)", lng);
86 } else {
87 snprintf(s, ITEM_LABEL_LENGTH, "%u°%u'%.3f\"%c (%d)",
88 abs(lng) / 10000000,
89 abs(lng) % 10000000 * 6 / 1000000,
90 abs(lng) % 10000000 * 6 % 1000000 * 6.0 / 100000.0,
91 (lng >= 0) ? 'E' : 'W',
92 lng);
97 static void
98 ieee1609dot2_Time32_fmt(char *s, uint32_t v)
100 time_t secs = v + 1072915200 - 5;
101 struct tm *tm = gmtime(&secs);
102 snprintf(s, ITEM_LABEL_LENGTH, "%u-%02u-%02u %02u:%02u:%02u (%u)",
103 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, v
107 static void
108 ieee1609dot2_Time64_fmt(char *s, uint64_t v)
110 time_t secs = v / 1000000 + 1072915200 - 5;
111 uint32_t usecs = v % 1000000;
112 struct tm *tm = gmtime(&secs);
113 snprintf(s, ITEM_LABEL_LENGTH, "%u-%02u-%02u %02u:%02u:%02u.%06u (%" PRIu64 ")",
114 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, usecs, v
118 /*--- proto_register_ieee1609dot2 ----------------------------------------------*/
119 void proto_register_ieee1609dot2(void) {
121 /* List of fields */
122 static hf_register_info hf[] = {
123 #include "packet-ieee1609dot2-hfarr.c"
126 /* List of subtrees */
127 static int *ett[] = {
128 #include "packet-ieee1609dot2-ettarr.c"
129 &ett_ieee1609dot2_ssp,
132 /* Register protocol */
133 proto_ieee1609dot2 = proto_register_protocol(PNAME, PSNAME, PFNAME);
135 /* Register fields and subtrees */
136 proto_register_field_array(proto_ieee1609dot2, hf, array_length(hf));
137 proto_register_subtree_array(ett, array_length(ett));
139 proto_ieee1609dot2_handle = register_dissector("ieee1609dot2.data", dissect_Ieee1609Dot2Data_PDU, proto_ieee1609dot2);
141 // See TS17419_ITS-AID_AssignedNumbers
142 unsecured_data_subdissector_table = register_dissector_table("ieee1609dot2.psid",
143 "ATS-AID/PSID based dissector for unsecured/signed data", proto_ieee1609dot2, FT_UINT32, BASE_HEX);
144 ssp_subdissector_table = register_dissector_table("ieee1609dot2.ssp",
145 "ATS-AID/PSID based dissector for Service Specific Permissions (SSP)", proto_ieee1609dot2, FT_UINT32, BASE_HEX);
149 void proto_reg_handoff_ieee1609dot2(void) {
150 dissector_add_string("media_type", "application/x-its", proto_ieee1609dot2_handle);
151 dissector_add_string("media_type", "application/x-its-request", proto_ieee1609dot2_handle);
152 dissector_add_string("media_type", "application/x-its-response", proto_ieee1609dot2_handle);
154 dissector_add_uint("ieee1609dot2.psid", psid_certificate_revocation_list_application, create_dissector_handle(dissect_SecuredCrl_PDU, proto_ieee1609dot2));
155 //dissector_add_uint_range_with_preference("udp.port", "56000,56001", proto_ieee1609dot2_handle);