]> The Tcpdump Group git mirrors - tcpdump/blob - print-geonet.c
Adding support for ISO CALM FAST and ETSI GeoNetworking
[tcpdump] / print-geonet.c
1 /*
2 * Copyright (c) 2013
3 * lykkja@hotmail.com All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by Paolo Abeni.''
13 * The name of author may not be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
16 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
17 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18 */
19
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23
24 #include <tcpdump-stdinc.h>
25
26 #include <pcap.h>
27 #include <stdio.h>
28 #include <string.h>
29
30 #include "interface.h"
31 #include "extract.h"
32 #include "addrtoname.h"
33
34
35 /*
36 ETSI TS 102 636-5-1 V1.1.1 (2011-02)
37 Intelligent Transport Systems (ITS); Vehicular Communications; GeoNetworking;
38 Part 5: Transport Protocols; Sub-part 1: Basic Transport Protocol
39
40 ETSI TS 102 636-4-1 V1.1.1 (2011-06)
41 Intelligent Transport Systems (ITS); Vehicular communications; GeoNetworking;
42 Part 4: Geographical addressing and forwarding for point-to-point and point-to-multipoint communications;
43 Sub-part 1: Media-Independent Functionality
44 */
45
46 static const char *
47 hex48_to_string(const u_char *bp)
48 {
49 int i;
50 static char sz[6*3+2];
51 memset(sz, 0, sizeof(sz));
52 for (i=0; i<6; i++) {
53 if (i) strcat(sz,":");
54 sprintf(sz+strlen(sz), "%02x", bp[i]);
55 }
56 return sz;
57 }
58
59 static void
60 print_btp_body(const u_char *bp, u_int length)
61 {
62 // Assuming ItsDpuHeader
63 int version = bp[0];
64 int msg_type = bp[1];
65 const char *msg_type_str = "Unknown";
66
67 switch (msg_type) {
68 case 0: msg_type_str = "CAM"; break;
69 case 1: msg_type_str = "DENM"; break;
70 case 101: msg_type_str = "TPEGM"; break;
71 case 102: msg_type_str = "TSPDM"; break;
72 case 103: msg_type_str = "VPM"; break;
73 case 104: msg_type_str = "SRM"; break;
74 case 105: msg_type_str = "SLAM"; break;
75 case 106: msg_type_str = "ecoCAM"; break;
76 case 107: msg_type_str = "ITM"; break;
77 case 150: msg_type_str = "SA"; break;
78 }
79 printf("; ItsPduHeader v:%d t:%d-%s", version, msg_type, msg_type_str);
80 }
81
82 static void
83 print_btp(const u_char *bp, u_int length)
84 {
85 u_int16_t dest = EXTRACT_16BITS(bp+0);
86 u_int16_t src = EXTRACT_16BITS(bp+2);
87 printf("; BTP Dst:%u Src:%u", dest, src);
88 }
89
90 static void
91 print_long_pos_vector(const char *type, const u_char *bp, u_int length)
92 {
93 int i;
94 u_int32_t lat, lon;
95
96 printf("GN_ADDR:");
97 for (i=0; i<8; i++) {
98 if (i) printf(":");
99 printf("%02x", bp[i]);
100 }
101 printf(" ");
102
103 lat = EXTRACT_32BITS(bp+12);
104 printf("lat:%d ", lat);
105 lon = EXTRACT_32BITS(bp+16);
106 printf("lon:%d", lon);
107 }
108
109
110 /*
111 * This is the top level routine of the printer. 'p' points
112 * to the geonet header of the packet.
113 */
114 void
115 geonet_print(netdissect_options *ndo, const u_char *eth, const u_char *bp, u_int length)
116 {
117 printf("GeoNet src:%s; ", hex48_to_string(eth+6));
118
119 if (length >= 36) {
120 // Process Common Header
121 int version = bp[0] >> 4;
122 int next_hdr = bp[0] & 0x0f;
123 int hdr_type = bp[1] >> 4;
124 int hdr_subtype = bp[1] & 0x0f;
125 u_int16_t payload_length = EXTRACT_16BITS(bp+4);
126 int hop_limit = bp[7];
127 const char *next_hdr_txt = "Unknown";
128 const char *hdr_type_txt = "Unknown";
129 int hdr_size = -1;
130
131 switch (next_hdr) {
132 case 0: next_hdr_txt = "Any"; break;
133 case 1: next_hdr_txt = "BTP-A"; break;
134 case 2: next_hdr_txt = "BTP-B"; break;
135 case 3: next_hdr_txt = "IPv6"; break;
136 }
137
138 switch (hdr_type) {
139 case 0: hdr_type_txt = "Any"; break;
140 case 1: hdr_type_txt = "Beacon"; break;
141 case 2: hdr_type_txt = "GeoUnicast"; break;
142 case 3: switch (hdr_subtype) {
143 case 0: hdr_type_txt = "GeoAnycastCircle"; break;
144 case 1: hdr_type_txt = "GeoAnycastRect"; break;
145 case 2: hdr_type_txt = "GeoAnycastElipse"; break;
146 }
147 break;
148 case 4: switch (hdr_subtype) {
149 case 0: hdr_type_txt = "GeoBroadcastCircle"; break;
150 case 1: hdr_type_txt = "GeoBroadcastRect"; break;
151 case 2: hdr_type_txt = "GeoBroadcastElipse"; break;
152 }
153 break;
154 case 5: switch (hdr_subtype) {
155 case 0: hdr_type_txt = "TopoScopeBcast-SH"; break;
156 case 1: hdr_type_txt = "TopoScopeBcast-MH"; break;
157 }
158 break;
159 case 6: switch (hdr_subtype) {
160 case 0: hdr_type_txt = "LocService-Request"; break;
161 case 1: hdr_type_txt = "LocService-Reply"; break;
162 }
163 break;
164 }
165
166 printf("v:%d ", version);
167 printf("NH:%d-%s ", next_hdr, next_hdr_txt);
168 printf("HT:%d-%d-%s ", hdr_type, hdr_subtype, hdr_type_txt);
169 printf("HopLim:%d ", hop_limit);
170 printf("Payload:%d ", payload_length);
171 print_long_pos_vector("Sender", bp + 8, 36-8);
172
173 // Skip Common Header
174 length -= 36;
175 bp += 36;
176
177 // Process Extended Headers
178 switch (hdr_type) {
179 case 0: /* Any */
180 hdr_size = 0;
181 break;
182 case 1: /* Beacon */
183 hdr_size = 0;
184 break;
185 case 2: /* GeoUnicast */
186 break;
187 case 3: switch (hdr_subtype) {
188 case 0: /* GeoAnycastCircle */
189 break;
190 case 1: /* GeoAnycastRect */
191 break;
192 case 2: /* GeoAnycastElipse */
193 break;
194 }
195 break;
196 case 4: switch (hdr_subtype) {
197 case 0: /* GeoBroadcastCircle */
198 break;
199 case 1: /* GeoBroadcastRect */
200 break;
201 case 2: /* GeoBroadcastElipse */
202 break;
203 }
204 break;
205 case 5: switch (hdr_subtype) {
206 case 0: /* TopoScopeBcast-SH */
207 hdr_size = 0;
208 break;
209 case 1: /* TopoScopeBcast-MH */
210 hdr_size = 68 - 36;
211 break;
212 }
213 break;
214 case 6: switch (hdr_subtype) {
215 case 0: /* LocService-Request */
216 break;
217 case 1: /* LocService-Reply */
218 break;
219 }
220 break;
221 }
222
223 // Skip Extended headers
224 if (hdr_size >= 0) {
225 length -= hdr_size;
226 bp += hdr_size;
227 switch (next_hdr) {
228 case 0: /* Any */
229 break;
230 case 1:
231 case 2: /* BTP A/B */
232 print_btp(bp, length);
233 length -= 4;
234 bp += 4;
235 print_btp_body(bp, length);
236 break;
237 case 3: /* IPv6 */
238 break;
239 }
240 }
241 } else {
242 printf("Malformed (small) ");
243 }
244
245 // Print user data part
246 if (ndo->ndo_vflag)
247 default_print(bp, length);
248 }
249
250
251 /*
252 * Local Variables:
253 * c-style: whitesmith
254 * c-basic-offset: 8
255 * End:
256 */