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