From: Francesco Fondelli Date: Tue, 18 Feb 2020 15:38:16 +0000 (+0100) Subject: Autosar SOME/IP protocol support X-Git-Tag: tcpdump-4.99-bp~518^2 X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/246ca110d152b6483fd8c1c176a570858307f76b Autosar SOME/IP protocol support --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 626f090a..7a65ead1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1086,6 +1086,7 @@ set(NETDISSECT_SOURCE_LIST_C print-zep.c print-zephyr.c print-zeromq.c + print-someip.c ${LOCALSRC} signature.c strtoaddr.c diff --git a/Makefile.in b/Makefile.in index 2b3b7e3d..3fa5ea93 100644 --- a/Makefile.in +++ b/Makefile.in @@ -241,6 +241,7 @@ LIBNETDISSECT_SRC=\ print-zep.c \ print-zephyr.c \ print-zeromq.c \ + print-someip.c \ signature.c \ strtoaddr.c \ util-print.c diff --git a/netdissect.h b/netdissect.h index 76a18425..fddcdc46 100644 --- a/netdissect.h +++ b/netdissect.h @@ -292,6 +292,7 @@ extern void nd_pop_all_packet_info(netdissect_options *); #define PT_LMP 16 /* Link Management Protocol */ #define PT_RESP 17 /* RESP */ #define PT_PTP 18 /* PTP */ +#define PT_SOMEIP 19 /* Autosar SOME/IP Protocol */ #ifndef min #define min(a,b) ((a)>(b)?(b):(a)) @@ -702,6 +703,7 @@ extern void zep_print(netdissect_options *, const u_char *, u_int); extern void zephyr_print(netdissect_options *, const u_char *, int); extern void zmtp1_print(netdissect_options *, const u_char *, u_int); extern void zmtp1_datagram_print(netdissect_options *, const u_char *, const u_int); +extern void someip_print(netdissect_options *, const u_char *, const u_int); /* checksum routines */ extern void init_checksum(void); diff --git a/print-someip.c b/print-someip.c new file mode 100644 index 00000000..5da3851b --- /dev/null +++ b/print-someip.c @@ -0,0 +1,133 @@ +/* + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that: (1) source code + * distributions retain the above copyright notice and this paragraph + * in its entirety, and (2) distributions including binary code include + * the above copyright notice and this paragraph in its entirety in + * the documentation or other materials provided with the distribution. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND + * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT + * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE. + * + * Original code by Francesco Fondelli (francesco dot fondelli, gmail dot com) + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "netdissect-stdinc.h" +#include "netdissect.h" +#include "extract.h" +#include "udp.h" + +/* + * SOMEIP Header (R19-11) + * + * 0 1 2 3 + * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Message ID (Service ID/Method ID) | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Length | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Request ID (Client ID/Session ID) | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Protocol Ver | Interface Ver | Message Type | Return Code | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Payload | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + */ + +struct tok message_type_values[] = { + { 0x00, "REQUEST" }, + { 0x01, "REQUEST_NO_RETURN" }, + { 0x02, "NOTIFICATION" }, + { 0x80, "RESPONSE" }, + { 0x81, "ERROR" }, + { 0x20, "TP_REQUEST" }, + { 0x21, "TP_REQUEST_NO_RETURN" }, + { 0x22, "TP_NOTIFICATION" }, + { 0xa0, "TP_RESPONSE" }, + { 0xa1, "TP_ERROR" }, + { 0, NULL } +}; + +struct tok return_code_values[] = { + { 0x00, "E_OK" }, + { 0x01, "E_NOT_OK" }, + { 0x02, "E_UNKNOWN_SERVICE" }, + { 0x03, "E_UNKNOWN_METHOD" }, + { 0x04, "E_NOT_READY" }, + { 0x05, "E_NOT_REACHABLE" }, + { 0x06, "E_TIMEOUT" }, + { 0x07, "E_WRONG_PROTOCOL_VERSION" }, + { 0x08, "E_WRONG_INTERFACE_VERSION" }, + { 0x09, "E_MALFORMED_MESSAGE" }, + { 0x0a, "E_WRONG_MESSAGE_TYPE" }, + { 0x0b, "E_E2E_REPEATED" }, + { 0x0c, "E_E2E_WRONG_SEQUENCE" }, + { 0x0d, "E_E2E" }, + { 0x0e, "E_E2E_NOT_AVAILABLE" }, + { 0x0f, "E_E2E_NO_NEW_DATA" }, +}; + +void +someip_print(netdissect_options *ndo, const u_char *bp, u_int len) +{ + uint32_t message_id; + uint16_t service_id; + uint16_t method_or_event_id; + uint8_t event_flag; + uint32_t message_len; + uint32_t request_id; + uint16_t client_id; + uint16_t session_id; + uint8_t protocol_version; + uint8_t interface_version; + uint8_t message_type; + uint8_t return_code; + + ndo->ndo_protocol = "someip"; + + if (len < 16) { + nd_print_trunc(ndo); + return; + } + + message_id = GET_BE_U_4(bp); + service_id = message_id >> 16; + event_flag = (message_id & 0x00008000) >> 15; + method_or_event_id = message_id & 0x00007FFF; + bp += 4; + + message_len = GET_BE_U_4(bp); + bp += 4; + + request_id = GET_BE_U_4(bp); + client_id = request_id >> 16; + session_id = request_id & 0x0000FFFF; + bp += 4; + + protocol_version = GET_U_1(bp); + bp += 1; + + interface_version = GET_U_1(bp); + bp += 1; + + message_type = GET_U_1(bp); + bp += 1; + + return_code = GET_U_1(bp); + bp += 1; + + ND_PRINT("SOMEIP, service %u, %s %u, len %u, client %u, session %u, " + "pver %u, iver %u, msgtype %s, retcode %s\n", + service_id, event_flag ? "event" : "method", method_or_event_id, + message_len, client_id, session_id, protocol_version, + interface_version, + tok2str(message_type_values, "Unknown", message_type), + tok2str(return_code_values, "Unknown", return_code)); + return; +} diff --git a/print-udp.c b/print-udp.c index d130eee7..9cde3d89 100644 --- a/print-udp.c +++ b/print-udp.c @@ -524,6 +524,10 @@ udp_print(netdissect_options *ndo, const u_char *bp, u_int length, udpipaddr_print(ndo, ip, sport, dport); ptp_print(ndo, cp, length); break; + case PT_SOMEIP: + udpipaddr_print(ndo, ip, sport, dport); + someip_print(ndo, cp, length); + break; } return; } @@ -727,7 +731,9 @@ udp_print(netdissect_options *ndo, const u_char *bp, u_int length, } else if (IS_SRC_OR_DST_PORT(PTP_EVENT_PORT) || IS_SRC_OR_DST_PORT(PTP_GENERAL_PORT)) { ptp_print(ndo, cp, length); - } else { + } else if (IS_SRC_OR_DST_PORT(SOMEIP_PORT)) + someip_print(ndo, (const u_char *)(up + 1), length); + else { if (ulen > length) ND_PRINT("UDP, bad length %u > %u", ulen, length); diff --git a/tcpdump.c b/tcpdump.c index 107cdbb6..cd277042 100644 --- a/tcpdump.c +++ b/tcpdump.c @@ -1791,6 +1791,8 @@ main(int argc, char **argv) ndo->ndo_packettype = PT_RESP; else if (ascii_strcasecmp(optarg, "ptp") == 0) ndo->ndo_packettype = PT_PTP; + else if (ascii_strcasecmp(optarg, "someip") == 0) + ndo->ndo_packettype = PT_SOMEIP; else error("unknown packet type `%s'", optarg); break; diff --git a/tests/TESTLIST b/tests/TESTLIST index fd08195c..fde636bb 100644 --- a/tests/TESTLIST +++ b/tests/TESTLIST @@ -758,3 +758,7 @@ ptp ptp.pcap ptp.out # bad packets from Jason Xiaole ldp_tlv_print-oobr ldp_tlv_print-oobr.pcap ldp_tlv_print-oobr.out -v + +#someip tests +someip1 someip1.pcap someip1.out +someip2 someip2.pcap someip2.out \ No newline at end of file diff --git a/tests/someip1.out b/tests/someip1.out new file mode 100644 index 00000000..3f42863c --- /dev/null +++ b/tests/someip1.out @@ -0,0 +1,6 @@ + 1 17:47:06.889447 IP 192.168.88.8.30490 > 192.168.88.8.31490: SOMEIP, service 65535, event 256, len 64, client 0, session 0, pver 1, iver 1, msgtype NOTIFICATION, retcode E_OK + + 2 17:47:08.944638 IP 192.168.88.8.31490 > 192.168.88.8.30490: SOMEIP, service 65535, event 256, len 48, client 0, session 0, pver 1, iver 1, msgtype NOTIFICATION, retcode E_OK + + 3 17:47:10.935734 IP 192.168.88.8.30490 > 192.168.88.8.31490: SOMEIP, service 65535, event 256, len 48, client 0, session 0, pver 1, iver 1, msgtype NOTIFICATION, retcode E_OK + diff --git a/tests/someip1.pcap b/tests/someip1.pcap new file mode 100644 index 00000000..0c3a6de6 Binary files /dev/null and b/tests/someip1.pcap differ diff --git a/tests/someip2.out b/tests/someip2.out new file mode 100644 index 00000000..9640a834 --- /dev/null +++ b/tests/someip2.out @@ -0,0 +1,2 @@ + 1 18:44:34.812094 IP 192.168.88.8.56001 > 192.168.88.8.30490: SOMEIP, service 1, method 2, len 8, client 8, session 5, pver 1, iver 1, msgtype REQUEST_NO_RETURN, retcode E_OK + diff --git a/tests/someip2.pcap b/tests/someip2.pcap new file mode 100644 index 00000000..cd833105 Binary files /dev/null and b/tests/someip2.pcap differ diff --git a/udp.h b/udp.h index f88641c8..a68c2316 100644 --- a/udp.h +++ b/udp.h @@ -242,3 +242,6 @@ struct udphdr { #ifndef ZEP_PORT #define ZEP_PORT 17754 /* XXX */ #endif +#ifndef SOMEIP_PORT +#define SOMEIP_PORT 30490 /* https://www.autosar.org/standards/foundation */ +#endif diff --git a/win32/prj/WinDump.dsp b/win32/prj/WinDump.dsp index 42ab44af..f920cb2c 100644 --- a/win32/prj/WinDump.dsp +++ b/win32/prj/WinDump.dsp @@ -721,6 +721,10 @@ SOURCE="..\..\print-zephyr.c" # End Source File # Begin Source File +SOURCE="..\..\print-someip.c" +# End Source File +# Begin Source File + SOURCE=..\..\setsignal.c # End Source File # Begin Source File diff --git a/win32/prj/WinDump.vcproj b/win32/prj/WinDump.vcproj index 3c746f99..3a56204f 100644 --- a/win32/prj/WinDump.vcproj +++ b/win32/prj/WinDump.vcproj @@ -3680,6 +3680,28 @@ /> + + + + + + + +