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 #include "udp.h" 26 27 /* 28 * SOMEIP Header (R19-11) 29 * 30 * 0 1 2 3 31 * 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 32 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 33 * | Message ID (Service ID/Method ID) | 34 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 35 * | Length | 36 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 37 * | Request ID (Client ID/Session ID) | 38 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 39 * | Protocol Ver | Interface Ver | Message Type | Return Code | 40 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 41 * | Payload | 42 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 43 */ 44 45 static const struct tok message_type_values[] = { 46 { 0x00, "REQUEST" }, 47 { 0x01, "REQUEST_NO_RETURN" }, 48 { 0x02, "NOTIFICATION" }, 49 { 0x80, "RESPONSE" }, 50 { 0x81, "ERROR" }, 51 { 0x20, "TP_REQUEST" }, 52 { 0x21, "TP_REQUEST_NO_RETURN" }, 53 { 0x22, "TP_NOTIFICATION" }, 54 { 0xa0, "TP_RESPONSE" }, 55 { 0xa1, "TP_ERROR" }, 56 { 0, NULL } 57 }; 58 59 static const struct tok return_code_values[] = { 60 { 0x00, "E_OK" }, 61 { 0x01, "E_NOT_OK" }, 62 { 0x02, "E_UNKNOWN_SERVICE" }, 63 { 0x03, "E_UNKNOWN_METHOD" }, 64 { 0x04, "E_NOT_READY" }, 65 { 0x05, "E_NOT_REACHABLE" }, 66 { 0x06, "E_TIMEOUT" }, 67 { 0x07, "E_WRONG_PROTOCOL_VERSION" }, 68 { 0x08, "E_WRONG_INTERFACE_VERSION" }, 69 { 0x09, "E_MALFORMED_MESSAGE" }, 70 { 0x0a, "E_WRONG_MESSAGE_TYPE" }, 71 { 0x0b, "E_E2E_REPEATED" }, 72 { 0x0c, "E_E2E_WRONG_SEQUENCE" }, 73 { 0x0d, "E_E2E" }, 74 { 0x0e, "E_E2E_NOT_AVAILABLE" }, 75 { 0x0f, "E_E2E_NO_NEW_DATA" }, 76 { 0, NULL } 77 }; 78 79 void 80 someip_print(netdissect_options *ndo, const u_char *bp, const u_int len) 81 { 82 uint32_t message_id; 83 uint16_t service_id; 84 uint16_t method_or_event_id; 85 uint8_t event_flag; 86 uint32_t message_len; 87 uint32_t request_id; 88 uint16_t client_id; 89 uint16_t session_id; 90 uint8_t protocol_version; 91 uint8_t interface_version; 92 uint8_t message_type; 93 uint8_t return_code; 94 95 ndo->ndo_protocol = "someip"; 96 nd_print_protocol_caps(ndo); 97 98 if (len < 16) { 99 goto invalid; 100 } 101 102 message_id = GET_BE_U_4(bp); 103 service_id = message_id >> 16; 104 event_flag = (message_id & 0x00008000) >> 15; 105 method_or_event_id = message_id & 0x00007FFF; 106 bp += 4; 107 ND_PRINT(", service %u, %s %u", 108 service_id, event_flag ? "event" : "method", method_or_event_id); 109 110 message_len = GET_BE_U_4(bp); 111 bp += 4; 112 ND_PRINT(", len %u", message_len); 113 114 request_id = GET_BE_U_4(bp); 115 client_id = request_id >> 16; 116 session_id = request_id & 0x0000FFFF; 117 bp += 4; 118 ND_PRINT(", client %u, session %u", client_id, session_id); 119 120 protocol_version = GET_U_1(bp); 121 bp += 1; 122 ND_PRINT(", pver %u", protocol_version); 123 124 interface_version = GET_U_1(bp); 125 bp += 1; 126 ND_PRINT(", iver %u", interface_version); 127 128 message_type = GET_U_1(bp); 129 bp += 1; 130 ND_PRINT(", msgtype %s", 131 tok2str(message_type_values, "Unknown", message_type)); 132 133 return_code = GET_U_1(bp); 134 bp += 1; 135 ND_PRINT(", retcode %s\n", 136 tok2str(return_code_values, "Unknown", return_code)); 137 138 return; 139 140 invalid: 141 nd_print_invalid(ndo); 142 } 143