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