]> The Tcpdump Group git mirrors - tcpdump/blob - print-someip.c
Replace some command name 'Tcpdump' with 'tcpdump'
[tcpdump] / print-someip.c
1 /*
2 * Redistribution and use in source and binary forms, with or without
3 * modification, are permitted provided that: (1) source code
4 * distributions retain the above copyright notice and this paragraph
5 * in its entirety, and (2) distributions including binary code include
6 * the above copyright notice and this paragraph in its entirety in
7 * the documentation or other materials provided with the distribution.
8 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND
9 * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
10 * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
11 * FOR A PARTICULAR PURPOSE.
12 *
13 * Original code by Francesco Fondelli (francesco dot fondelli, gmail dot com)
14 */
15
16 /* \summary: Autosar SOME/IP Protocol printer */
17
18 #ifdef HAVE_CONFIG_H
19 #include <config.h>
20 #endif
21
22 #include "netdissect-stdinc.h"
23 #include "netdissect.h"
24 #include "extract.h"
25
26 /*
27 * SOMEIP Header (R19-11)
28 *
29 * 0 1 2 3
30 * 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
31 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
32 * | Message ID (Service ID/Method ID) |
33 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
34 * | Length |
35 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
36 * | Request ID (Client ID/Session ID) |
37 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
38 * | Protocol Ver | Interface Ver | Message Type | Return Code |
39 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
40 * | Payload |
41 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
42 */
43
44 static const struct tok message_type_values[] = {
45 { 0x00, "REQUEST" },
46 { 0x01, "REQUEST_NO_RETURN" },
47 { 0x02, "NOTIFICATION" },
48 { 0x80, "RESPONSE" },
49 { 0x81, "ERROR" },
50 { 0x20, "TP_REQUEST" },
51 { 0x21, "TP_REQUEST_NO_RETURN" },
52 { 0x22, "TP_NOTIFICATION" },
53 { 0xa0, "TP_RESPONSE" },
54 { 0xa1, "TP_ERROR" },
55 { 0, NULL }
56 };
57
58 static const struct tok return_code_values[] = {
59 { 0x00, "E_OK" },
60 { 0x01, "E_NOT_OK" },
61 { 0x02, "E_UNKNOWN_SERVICE" },
62 { 0x03, "E_UNKNOWN_METHOD" },
63 { 0x04, "E_NOT_READY" },
64 { 0x05, "E_NOT_REACHABLE" },
65 { 0x06, "E_TIMEOUT" },
66 { 0x07, "E_WRONG_PROTOCOL_VERSION" },
67 { 0x08, "E_WRONG_INTERFACE_VERSION" },
68 { 0x09, "E_MALFORMED_MESSAGE" },
69 { 0x0a, "E_WRONG_MESSAGE_TYPE" },
70 { 0x0b, "E_E2E_REPEATED" },
71 { 0x0c, "E_E2E_WRONG_SEQUENCE" },
72 { 0x0d, "E_E2E" },
73 { 0x0e, "E_E2E_NOT_AVAILABLE" },
74 { 0x0f, "E_E2E_NO_NEW_DATA" },
75 { 0, NULL }
76 };
77
78 void
79 someip_print(netdissect_options *ndo, const u_char *bp, const u_int len)
80 {
81 uint32_t message_id;
82 uint16_t service_id;
83 uint16_t method_or_event_id;
84 uint8_t event_flag;
85 uint32_t message_len;
86 uint32_t request_id;
87 uint16_t client_id;
88 uint16_t session_id;
89 uint8_t protocol_version;
90 uint8_t interface_version;
91 uint8_t message_type;
92 uint8_t return_code;
93
94 ndo->ndo_protocol = "someip";
95 nd_print_protocol_caps(ndo);
96
97 if (len < 16) {
98 goto invalid;
99 }
100
101 message_id = GET_BE_U_4(bp);
102 service_id = message_id >> 16;
103 event_flag = (message_id & 0x00008000) >> 15;
104 method_or_event_id = message_id & 0x00007FFF;
105 bp += 4;
106 ND_PRINT(", service %u, %s %u",
107 service_id, event_flag ? "event" : "method", method_or_event_id);
108
109 message_len = GET_BE_U_4(bp);
110 bp += 4;
111 ND_PRINT(", len %u", message_len);
112
113 request_id = GET_BE_U_4(bp);
114 client_id = request_id >> 16;
115 session_id = request_id & 0x0000FFFF;
116 bp += 4;
117 ND_PRINT(", client %u, session %u", client_id, session_id);
118
119 protocol_version = GET_U_1(bp);
120 bp += 1;
121 ND_PRINT(", pver %u", protocol_version);
122
123 interface_version = GET_U_1(bp);
124 bp += 1;
125 ND_PRINT(", iver %u", interface_version);
126
127 message_type = GET_U_1(bp);
128 bp += 1;
129 ND_PRINT(", msgtype %s",
130 tok2str(message_type_values, "Unknown", message_type));
131
132 return_code = GET_U_1(bp);
133 bp += 1;
134 ND_PRINT(", retcode %s\n",
135 tok2str(return_code_values, "Unknown", return_code));
136
137 return;
138
139 invalid:
140 nd_print_invalid(ndo);
141 }