epan/dissectors/pidl/ C99 drsuapi
[wireshark-sm.git] / epan / dissectors / asn1 / atn-cm / packet-atn-cm-template.c
blob3d0755dda63aaa74a64d4292b087ffc20950d23e
1 /* packet-atn-cm.c
2 * By Mathias Guettler <guettler@web.de>
3 * Copyright 2013
5 * Routines for ATN context management protocol packet disassembly.
6 * ATN context management allows an aircraft
7 * to log on to a ground facility.
9 * details see:
10 * https://en.wikipedia.org/wiki/CPDLC
11 * https://members.optusnet.com.au/~cjr/introduction.htm
13 * standards:
14 * We are dealing with ATN/CPDLC aka ICAO Doc 9705 Second Edition here
15 * (CPDLC may also be transmitted via ACARS/AOA aka "FANS-1/A ").
16 * https://www.icao.int/safety/acp/repository/_%20Doc9705_ed2_1999.pdf
18 * Wireshark - Network traffic analyzer
19 * By Gerald Combs <gerald@wireshark.org>
20 * Copyright 1998 Gerald Combs
22 * SPDX-License-Identifier: GPL-2.0-or-later
25 #include "config.h"
27 #include <epan/packet.h>
28 #include <epan/exceptions.h>
29 #include <epan/conversation.h>
30 #include <wsutil/array.h>
31 #include "packet-ber.h"
32 #include "packet-per.h"
33 #include "packet-atn-ulcs.h"
35 #define ATN_CM_PROTO "ICAO Doc9705 CM"
37 void proto_register_atn_cm(void);
38 void proto_reg_handoff_atn_cm(void);
40 #include "packet-atn-cm-hf.c"
42 #include "packet-atn-cm-ett.c"
43 static int ett_atn_cm;
45 #include "packet-atn-cm-fn.c"
46 static int proto_atn_cm;
48 static int
49 dissect_atn_cm(
50 tvbuff_t *tvb,
51 packet_info *pinfo,
52 proto_tree *tree,
53 void *data _U_)
55 int type;
56 proto_tree *sub_tree;
58 sub_tree = proto_tree_add_subtree(
59 tree, tvb, 0, -1, ett_atn_cm, NULL, ATN_CM_PROTO);
61 /* ti = proto_tree_add_item(tree, proto_atn_cm, tvb, 0, 0 , ENC_NA); */
62 /* sub_tree = proto_item_add_subtree(ti, ett_atn_cm_pdu); */
64 /* determine whether it is uplink or downlink */
65 type = check_heur_msg_type(pinfo);
67 switch(type){
68 case um:
69 dissect_CMGroundMessage_PDU(
70 tvb,
71 pinfo,
72 sub_tree, NULL);
73 break;
74 case dm:
75 dissect_CMAircraftMessage_PDU(
76 tvb,
77 pinfo,
78 sub_tree, NULL);
79 break;
80 default:
81 break;
83 return tvb_reported_length_remaining(tvb, 0);
86 static bool
87 dissect_atn_cm_heur(
88 tvbuff_t *tvb,
89 packet_info *pinfo,
90 proto_tree *tree,
91 void *data _U_)
93 atn_conversation_t *volatile atn_cv = NULL;
94 volatile bool is_atn_cm = false;
95 int type;
97 /* determine whether it is uplink or downlink */
98 type = check_heur_msg_type(pinfo);
100 /* heuristically decode message */
101 switch(type){
102 case um:
103 TRY {
104 dissect_CMGroundMessage_PDU(
105 tvb,
106 pinfo,
107 NULL, NULL);
108 /* no exception thrown: looks like it is a CM PDU */
109 is_atn_cm = true; }
110 CATCH_ALL {
111 is_atn_cm = false; }
112 ENDTRY;
113 break;
114 case dm:
115 TRY {
116 dissect_CMAircraftMessage_PDU(
117 tvb,
118 pinfo,
119 NULL, NULL);
120 /* no exception thrown: looks like it is a CM PDU */
121 is_atn_cm = true;}
122 CATCH_ALL {
123 is_atn_cm = false; }
124 ENDTRY;
125 break;
126 default:
127 break;
130 if (is_atn_cm == true) {
131 /* note: */
132 /* all subsequent PDU's belonging to this conversation are considered CM */
133 /* if the first CM PDU has been decoded successfully */
134 /* (This is done in "atn-ulcs" by using "call_dissector_with_data()") */
136 /* DT: dstref present, srcref is always zero */
137 if((pinfo->clnp_dstref) &&
138 (!pinfo->clnp_srcref)){
140 atn_cv = find_atn_conversation(
141 &pinfo->dst,
142 pinfo->clnp_dstref,
143 &pinfo->src );
145 /* CR: srcref present, dstref is always zero */
146 if((!pinfo->clnp_dstref) &&
147 (pinfo->clnp_srcref)){
149 atn_cv = find_atn_conversation(
150 &pinfo->src,
151 pinfo->clnp_srcref,
152 &pinfo->dst );
155 /* CC: srcref and dstref present */
156 if((pinfo->clnp_dstref) &&
157 (pinfo->clnp_srcref)){
158 atn_cv = find_atn_conversation(
159 &pinfo->src,
160 pinfo->clnp_srcref,
161 &pinfo->dst );
163 if(atn_cv){
164 atn_cv->ae_qualifier = cma;
166 dissect_atn_cm(
167 tvb,
168 pinfo,
169 tree,
170 NULL);
173 return is_atn_cm;
177 void proto_register_atn_cm (void)
179 static hf_register_info hf_atn_cm[] = {
180 #include "packet-atn-cm-hfarr.c"
182 static int *ett[] = {
183 #include "packet-atn-cm-ettarr.c"
184 &ett_atn_cm
187 /* register CM application */
188 proto_atn_cm = proto_register_protocol(ATN_CM_PROTO, "ATN-CM", "atn-cm");
190 proto_register_field_array(
191 proto_atn_cm,
192 hf_atn_cm,
193 array_length(hf_atn_cm));
195 proto_register_subtree_array(
196 ett,
197 array_length(ett));
199 register_dissector(
200 "atn-cm",
201 dissect_atn_cm,
202 proto_atn_cm);
205 void proto_reg_handoff_atn_cm(void)
207 /* add session dissector to subdissector list*/
208 heur_dissector_add(
209 "atn-ulcs",
210 dissect_atn_cm_heur,
211 "ATN-CM over ATN-ULCS",
212 "atn-cm-ulcs",
213 proto_atn_cm, HEURISTIC_ENABLE);
217 * Editor modelines - https://www.wireshark.org/tools/modelines.html
219 * Local variables:
220 * c-basic-offset: 4
221 * tab-width: 8
222 * indent-tabs-mode: nil
223 * End:
225 * vi: set shiftwidth=4 tabstop=8 expandtab:
226 * :indentSize=4:tabSize=8:noTabs=true: