]>
The Tcpdump Group git mirrors - tcpdump/blob - print-geonet.c
2 * Copyright (c) 2013 The TCPDUMP project
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.
15 * Original code by Ola Martin Lykkja (ola.lykkja@q-free.com)
18 /* \summary: ISO CALM FAST and ETSI GeoNetworking printer */
24 #include "netdissect-stdinc.h"
26 #include "netdissect.h"
28 #include "addrtoname.h"
32 ETSI TS 102 636-5-1 V1.1.1 (2011-02)
33 Intelligent Transport Systems (ITS); Vehicular Communications; GeoNetworking;
34 Part 5: Transport Protocols; Sub-part 1: Basic Transport Protocol
36 ETSI TS 102 636-4-1 V1.1.1 (2011-06)
37 Intelligent Transport Systems (ITS); Vehicular communications; GeoNetworking;
38 Part 4: Geographical addressing and forwarding for point-to-point and point-to-multipoint communications;
39 Sub-part 1: Media-Independent Functionality
42 #define GEONET_ADDR_LEN 8
44 static const struct tok msg_type_values
[] = {
59 print_btp_body(netdissect_options
*ndo
,
64 const char *msg_type_str
;
66 /* Assuming ItsDpuHeader */
67 /* 2 bytes ND_TCHECKed in geonet_print() */
68 version
= EXTRACT_U_1(bp
);
69 msg_type
= EXTRACT_U_1(bp
+ 1);
70 msg_type_str
= tok2str(msg_type_values
, "unknown (%u)", msg_type
);
72 ND_PRINT("; ItsPduHeader v:%u t:%u-%s", version
, msg_type
, msg_type_str
);
76 print_btp(netdissect_options
*ndo
,
79 /* 4 bytes ND_TCHECKed in geonet_print() */
80 uint16_t dest
= EXTRACT_BE_U_2(bp
+ 0);
81 uint16_t src
= EXTRACT_BE_U_2(bp
+ 2);
82 ND_PRINT("; BTP Dst:%u Src:%u", dest
, src
);
86 print_long_pos_vector(netdissect_options
*ndo
,
91 ND_TCHECK_LEN(bp
, GEONET_ADDR_LEN
);
92 ND_PRINT("GN_ADDR:%s ", linkaddr_string (ndo
, bp
, 0, GEONET_ADDR_LEN
));
95 lat
= EXTRACT_BE_U_4(bp
+ 12);
96 ND_PRINT("lat:%u ", lat
);
97 lon
= EXTRACT_BE_U_4(bp
+ 16);
98 ND_PRINT("lon:%u", lon
);
106 * This is the top level routine of the printer. 'p' points
107 * to the geonet header of the packet.
110 geonet_print(netdissect_options
*ndo
, const u_char
*bp
, u_int length
,
111 const struct lladdr_info
*src
)
117 uint16_t payload_length
;
119 const char *next_hdr_txt
= "Unknown";
120 const char *hdr_type_txt
= "Unknown";
123 ndo
->ndo_protocol
= "geonet";
126 ND_PRINT("src:%s", (src
->addr_string
)(ndo
, src
->addr
));
129 /* Process Common Header */
134 version
= EXTRACT_U_1(bp
) >> 4;
135 next_hdr
= EXTRACT_U_1(bp
) & 0x0f;
136 hdr_type
= EXTRACT_U_1(bp
+ 1) >> 4;
137 hdr_subtype
= EXTRACT_U_1(bp
+ 1) & 0x0f;
138 payload_length
= EXTRACT_BE_U_2(bp
+ 4);
139 hop_limit
= EXTRACT_U_1(bp
+ 7);
142 case 0: next_hdr_txt
= "Any"; break;
143 case 1: next_hdr_txt
= "BTP-A"; break;
144 case 2: next_hdr_txt
= "BTP-B"; break;
145 case 3: next_hdr_txt
= "IPv6"; break;
149 case 0: hdr_type_txt
= "Any"; break;
150 case 1: hdr_type_txt
= "Beacon"; break;
151 case 2: hdr_type_txt
= "GeoUnicast"; break;
152 case 3: switch (hdr_subtype
) {
153 case 0: hdr_type_txt
= "GeoAnycastCircle"; break;
154 case 1: hdr_type_txt
= "GeoAnycastRect"; break;
155 case 2: hdr_type_txt
= "GeoAnycastElipse"; break;
158 case 4: switch (hdr_subtype
) {
159 case 0: hdr_type_txt
= "GeoBroadcastCircle"; break;
160 case 1: hdr_type_txt
= "GeoBroadcastRect"; break;
161 case 2: hdr_type_txt
= "GeoBroadcastElipse"; break;
164 case 5: switch (hdr_subtype
) {
165 case 0: hdr_type_txt
= "TopoScopeBcast-SH"; break;
166 case 1: hdr_type_txt
= "TopoScopeBcast-MH"; break;
169 case 6: switch (hdr_subtype
) {
170 case 0: hdr_type_txt
= "LocService-Request"; break;
171 case 1: hdr_type_txt
= "LocService-Reply"; break;
176 ND_PRINT("v:%u ", version
);
177 ND_PRINT("NH:%u-%s ", next_hdr
, next_hdr_txt
);
178 ND_PRINT("HT:%u-%u-%s ", hdr_type
, hdr_subtype
, hdr_type_txt
);
179 ND_PRINT("HopLim:%u ", hop_limit
);
180 ND_PRINT("Payload:%u ", payload_length
);
181 if (print_long_pos_vector(ndo
, bp
+ 8) == -1)
184 /* Skip Common Header */
188 /* Process Extended Headers */
196 case 2: /* GeoUnicast */
198 case 3: switch (hdr_subtype
) {
199 case 0: /* GeoAnycastCircle */
201 case 1: /* GeoAnycastRect */
203 case 2: /* GeoAnycastElipse */
207 case 4: switch (hdr_subtype
) {
208 case 0: /* GeoBroadcastCircle */
210 case 1: /* GeoBroadcastRect */
212 case 2: /* GeoBroadcastElipse */
216 case 5: switch (hdr_subtype
) {
217 case 0: /* TopoScopeBcast-SH */
220 case 1: /* TopoScopeBcast-MH */
225 case 6: switch (hdr_subtype
) {
226 case 0: /* LocService-Request */
228 case 1: /* LocService-Reply */
234 /* Skip Extended headers */
236 if (length
< (u_int
)hdr_size
)
238 ND_TCHECK_LEN(bp
, hdr_size
);
245 case 2: /* BTP A/B */
254 * XXX - did print_btp_body()
255 * return if length < 2
256 * because this is optional,
257 * or was that just not
258 * reporting genuine errors?
261 print_btp_body(ndo
, bp
);
269 /* Print user data part */
271 ND_DEFAULTPRINT(bp
, length
);
275 ND_PRINT(" Malformed (small) ");
276 /* XXX - print the remaining data as hex? */