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