]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Autosar SOME/IP protocol support 828/head
authorFrancesco Fondelli <[email protected]>
Tue, 18 Feb 2020 15:38:16 +0000 (16:38 +0100)
committerFrancesco Fondelli <[email protected]>
Wed, 19 Feb 2020 09:05:32 +0000 (10:05 +0100)
14 files changed:
CMakeLists.txt
Makefile.in
netdissect.h
print-someip.c [new file with mode: 0644]
print-udp.c
tcpdump.c
tests/TESTLIST
tests/someip1.out [new file with mode: 0644]
tests/someip1.pcap [new file with mode: 0644]
tests/someip2.out [new file with mode: 0644]
tests/someip2.pcap [new file with mode: 0644]
udp.h
win32/prj/WinDump.dsp
win32/prj/WinDump.vcproj

index 626f090a676003582f434ba9872d3306070e3294..7a65ead1b3f41f9aa9bdf8ad9ff15d5a44af57d0 100644 (file)
@@ -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
index 2b3b7e3da9a1a7a549ed0ad4d712f641029a9ce3..3fa5ea93a93727f9b50797de927b7d6848e4aebb 100644 (file)
@@ -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
index 76a18425c44e5dd706e9e0e1c4e31a1da3713d0d..fddcdc46aa0d0800783baca1f7c78a7cc436b886 100644 (file)
@@ -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 (file)
index 0000000..5da3851
--- /dev/null
@@ -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;
+}
index d130eee7752a5d1b665d8c99bf4f4513f7d36c4a..9cde3d8910f588f974bb583879905b4aa0d37598 100644 (file)
@@ -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);
index 107cdbb6b175e43fd2db2156efd8897c892bbe61..cd277042e3483e91d65b495b7633b2bdf09cb214 100644 (file)
--- 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;
index fd08195ce1c63bc33b0b862991a612d8d364f861..fde636bb70cb71dd2acc9e1f1379f302b8cc26db 100644 (file)
@@ -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 (file)
index 0000000..3f42863
--- /dev/null
@@ -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 (file)
index 0000000..0c3a6de
Binary files /dev/null and b/tests/someip1.pcap differ
diff --git a/tests/someip2.out b/tests/someip2.out
new file mode 100644 (file)
index 0000000..9640a83
--- /dev/null
@@ -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 (file)
index 0000000..cd83310
Binary files /dev/null and b/tests/someip2.pcap differ
diff --git a/udp.h b/udp.h
index f88641c809fb0bc8841404f66547df4f8c5171cf..a68c23161fc2f378e4658f3befe1f20634775fc3 100644 (file)
--- 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
index 42ab44afe87852edb9ac609d8b9601d91966c2a9..f920cb2c602a0723578bec3100c4703a703bed70 100644 (file)
@@ -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
index 3c746f99a12c463dc8dfac25215e59aa6da70fbe..3a56204f385f81b9d381e28999acea9b65c5acc2 100644 (file)
                                />
                        </FileConfiguration>
                </File>
+               <File
+                       RelativePath="..\..\print-someip.c"
+                       >
+                       <FileConfiguration
+                               Name="Debug|Win32"
+                               >
+                               <Tool
+                                       Name="VCCLCompilerTool"
+                                       AdditionalIncludeDirectories=""
+                                       PreprocessorDefinitions=""
+                               />
+                       </FileConfiguration>
+                       <FileConfiguration
+                               Name="Release|Win32"
+                               >
+                               <Tool
+                                       Name="VCCLCompilerTool"
+                                       AdditionalIncludeDirectories=""
+                                       PreprocessorDefinitions=""
+                               />
+                       </FileConfiguration>
+               </File>
                <File
                        RelativePath="..\..\setsignal.c"
                        >