Diagnostics over IP
Last modified:
ISO 13400 (DoIP — Diagnostics over IP) is a standard for vehicle diagnostics over Ethernet. It is used in modern vehicles for high-speed diagnostics and software updates. ScanDoc supports DoIP via its built-in Ethernet adapter.
Before using the DoIP commands, the parameters must be configured via SET_CONFIG.
| Parameter | Value | Description | Default |
|---|---|---|---|
| ISO13400_SOURCE_ADDR | 0x8100 | Tester logical address (SA). Typically 0x0E00-0x0EFF. | 0x0E00 |
| ISO13400_TARGET_ADDR | 0x8101 | ECU logical address (TA). Vehicle-specific. | — |
| ISO13400_ECU_IP_ADDR | 0x8102 | IP address of the gateway/ECU (4 bytes, big-endian) | — |
| ISO13400_ECU_TCP_PORT | 0x8103 | TCP port to connect to | 13400 |
| ISO13400_T_TCP_INITIAL | 0x8104 | Inactivity timeout before routing activation (ms) | 2000 |
| ISO13400_T_TCP_GENERAL | 0x8105 | General TCP inactivity timeout (ms) | 300000 |
| ISO13400_T_DIAG_MSG | 0x8106 | Timeout for waiting on a diagnostic response (ms) | 2000 |
| ISO13400_ACTIVATION_TYPE | 0x8107 | Routing activation type (0x00 — default, 0x01 — WWH-OBD, 0xE0 — Central Security) | 0 |
Sends a UDP broadcast request to discover DoIP-enabled vehicles on the local network. The results are stored in an internal buffer and are available via ISO13400_GET_VEHICLE_INFO.
| IoctlID | 0x8110 |
| pInput | NULL |
| pOutput | NULL |
#include "j2534_dll.hpp"
unsigned long ChannelID; // Obtained from PassThruConnect for ISO13400_PS
long ret;
ret = PassThruIoctl(ChannelID, ISO13400_DISCOVER_VEHICLES, NULL, NULL);
if (ret == STATUS_NOERROR)
{
printf("Discovery complete\n");
}
val result = j2534.ptIoctl(channelID, ISO13400_DISCOVER_VEHICLES, 0, null)
if (result.status == STATUS_NOERROR) {
Log.i("DoIP", "Discovery complete")
}
ret = j2534.PassThruIoctl(channel_id, ISO13400_DISCOVER_VEHICLES, None, None)
if ret == 0:
print("Discovery complete")
int ret = J2534.PassThruIoctl(channelId, ISO13400_DISCOVER_VEHICLES, IntPtr.Zero, IntPtr.Zero);
if (ret == 0)
Console.WriteLine("Discovery complete");
Returns information about a discovered vehicle: VIN, logical address, gateway IP address. Called after ISO13400_DISCOVER_VEHICLES.
| IoctlID | 0x8111 |
| pInput | NULL |
| pOutput | DOIP_VEHICLE_INFO* — structure with information about the first discovered vehicle |
typedef struct {
char VIN[18]; // VIN (17 characters + '\0')
unsigned short LogicalAddr; // Logical address of the DoIP gateway
unsigned char EID[6]; // Entity Identification (MAC address)
unsigned char GID[6]; // Group Identification
unsigned char FurtherAction;// Further action code (0x00 — none, 0x10 — routing activation required)
unsigned char SyncStatus; // VIN/GID sync status (0x00 — synced, 0x10 — not completed)
unsigned long IPAddr; // IPv4 address (big-endian)
} DOIP_VEHICLE_INFO;
#include "j2534_dll.hpp"
unsigned long ChannelID; // Obtained from PassThruConnect for ISO13400_PS
DOIP_VEHICLE_INFO vehicleInfo;
long ret;
ret = PassThruIoctl(ChannelID, ISO13400_GET_VEHICLE_INFO, NULL, &vehicleInfo);
if (ret == STATUS_NOERROR)
{
printf("VIN: %s\n", vehicleInfo.VIN);
printf("Logical address: 0x%04X\n", vehicleInfo.LogicalAddr);
printf("IP: %d.%d.%d.%d\n",
(vehicleInfo.IPAddr >> 24) & 0xFF,
(vehicleInfo.IPAddr >> 16) & 0xFF,
(vehicleInfo.IPAddr >> 8) & 0xFF,
vehicleInfo.IPAddr & 0xFF);
}
val result = j2534.ptGetVehicleInfo(channelID)
if (result.status == STATUS_NOERROR) {
Log.i("DoIP", "VIN: ${result.vin}")
Log.i("DoIP", "Logical address: 0x${result.logicalAddr.toString(16).uppercase()}")
Log.i("DoIP", "IP: ${result.ipAddrString}")
}
from ctypes import *
class DOIP_VEHICLE_INFO(Structure):
_fields_ = [
("VIN", c_char * 18),
("LogicalAddr", c_ushort),
("EID", c_ubyte * 6),
("GID", c_ubyte * 6),
("FurtherAction", c_ubyte),
("SyncStatus", c_ubyte),
("IPAddr", c_ulong)
]
vehicle_info = DOIP_VEHICLE_INFO()
ret = j2534.PassThruIoctl(channel_id, ISO13400_GET_VEHICLE_INFO, None, byref(vehicle_info))
if ret == 0:
ip = vehicle_info.IPAddr
print(f"VIN: {vehicle_info.VIN.decode()}")
print(f"Logical address: 0x{vehicle_info.LogicalAddr:04X}")
print(f"IP: {(ip >> 24) & 0xFF}.{(ip >> 16) & 0xFF}.{(ip >> 8) & 0xFF}.{ip & 0xFF}")
[StructLayout(LayoutKind.Sequential)]
public struct DOIP_VEHICLE_INFO {
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 18)]
public byte[] VIN;
public ushort LogicalAddr;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)]
public byte[] EID;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)]
public byte[] GID;
public byte FurtherAction;
public byte SyncStatus;
public uint IPAddr;
}
DOIP_VEHICLE_INFO vehicleInfo;
int ret = J2534.PassThruIoctl(channelId, ISO13400_GET_VEHICLE_INFO, IntPtr.Zero, out vehicleInfo);
if (ret == 0)
{
Console.WriteLine($"VIN: {Encoding.ASCII.GetString(vehicleInfo.VIN).TrimEnd('\0')}");
Console.WriteLine($"Logical address: 0x{vehicleInfo.LogicalAddr:X4}");
var ip = vehicleInfo.IPAddr;
Console.WriteLine($"IP: {(ip >> 24) & 0xFF}.{(ip >> 16) & 0xFF}.{(ip >> 8) & 0xFF}.{ip & 0xFF}");
}
Establishes a TCP connection to the vehicle gateway. The IP address and port must be configured beforehand via SET_CONFIG or obtained from ISO13400_GET_VEHICLE_INFO.
| IoctlID | 0x8112 |
| pInput | NULL (uses parameters from SET_CONFIG) or DOIP_CONNECT_PARAMS* |
| pOutput | NULL |
#include "j2534_dll.hpp"
unsigned long ChannelID; // Obtained from PassThruConnect for ISO13400
long ret;
// Parameters have already been configured via SET_CONFIG
ret = PassThruIoctl(ChannelID, ISO13400_CONNECT_TCP, NULL, NULL);
if (ret == STATUS_NOERROR)
{
printf("TCP connection established\n");
}
else
{
char error[256];
PassThruGetLastError(error);
printf("Connection error: %s\n", error);
}
val result = j2534.ptIoctl(channelID, ISO13400_CONNECT_TCP, 0, null)
if (result.status == STATUS_NOERROR) {
Log.i("DoIP", "TCP connection established")
} else {
Log.e("DoIP", "TCP connection error: ${result.status}")
}
ret = j2534.PassThruIoctl(channel_id, ISO13400_CONNECT_TCP, None, None)
if ret == 0:
print("TCP connection established")
else:
print(f"TCP connection error: {ret}")
int ret = J2534.PassThruIoctl(channelId, ISO13400_CONNECT_TCP, IntPtr.Zero, IntPtr.Zero);
if (ret == 0)
Console.WriteLine("TCP connection established");
else
Console.WriteLine($"TCP connection error: {ret}");
Sends a Routing Activation request to obtain diagnostic access. The activation type is set by the ISO13400_ACTIVATION_TYPE parameter.
| IoctlID | 0x8113 |
| pInput | NULL or unsigned long* — activation type (0 — default, 1 — WWH-OBD) |
| pOutput | unsigned long* — response code from the gateway |
| 0x00 | Routing activation denied — Unknown source address |
| 0x01 | Routing activation denied — All TCP_DATA sockets registered and active |
| 0x02 | Routing activation denied — Different SA on already activated socket |
| 0x03 | Routing activation denied — SA already registered on different socket |
| 0x04 | Routing activation denied — Missing authentication |
| 0x05 | Routing activation denied — Rejected confirmation |
| 0x06 | Routing activation denied — Unsupported routing activation type |
| 0x07 | Routing activation denied — Requires TLS socket |
| 0x10 | Routing successfully activated |
| 0x11 | Routing will be activated — confirmation required |
#include "j2534_dll.hpp"
unsigned long ChannelID;
unsigned long activationType = 0; // Default
unsigned long responseCode = 0;
long ret;
ret = PassThruIoctl(ChannelID, ISO13400_ACTIVATE_ROUTING, &activationType, &responseCode);
if (ret == STATUS_NOERROR)
{
if (responseCode == 0x10)
printf("Routing activated successfully\n");
else
printf("Response code: 0x%02X\n", responseCode);
}
val result = j2534.ptIoctl(channelID, ISO13400_ACTIVATE_ROUTING, 0, null)
if (result.status == STATUS_NOERROR) {
if (result.outputValue == 0x10) {
Log.i("DoIP", "Routing activated successfully")
} else {
Log.w("DoIP", "Response code: 0x${result.outputValue.toString(16)}")
}
}
from ctypes import *
activation_type = c_ulong(0) # Default
response_code = c_ulong(0)
ret = j2534.PassThruIoctl(channel_id, ISO13400_ACTIVATE_ROUTING, byref(activation_type), byref(response_code))
if ret == 0:
if response_code.value == 0x10:
print("Routing activated successfully")
else:
print(f"Response code: 0x{response_code.value:02X}")
uint activationType = 0; // Default
uint responseCode;
int ret = J2534.PassThruIoctl(channelId, ISO13400_ACTIVATE_ROUTING, ref activationType, out responseCode);
if (ret == 0)
{
if (responseCode == 0x10)
Console.WriteLine("Routing activated successfully");
else
Console.WriteLine($"Response code: 0x{responseCode:X2}");
}
| Code | Description | Possible causes and solutions |
|---|---|---|
| STATUS_NOERROR | Function completed successfully | — |
| ERR_DEVICE_NOT_CONNECTED | No connection to the adapter |
|
| ERR_NOT_SUPPORTED | DoIP not supported |
|
| ERR_TIMEOUT | Operation timeout |
|
| ERR_INVALID_CHANNEL_ID | Invalid channel identifier |
|
| ERR_FAILED | Unspecified error |
|
#include "j2534_dll.hpp"
#include <stdio.h>
int DoIPDiagnosticSession(void)
{
unsigned long DeviceID, ChannelID;
long ret;
// 1. Open the device
ret = PassThruOpen(NULL, &DeviceID);
if (ret != STATUS_NOERROR) return ret;
// 2. Check Ethernet support
SCONFIG cfg[1];
SCONFIG_LIST cfgList = {1, cfg};
cfg[0].Parameter = ETHERNET_NDIS_SUPPORTED;
ret = PassThruIoctl(DeviceID, GET_DEVICE_INFO, &cfgList, NULL);
if (ret != STATUS_NOERROR || cfg[0].Value == 0)
{
printf("DoIP not supported\n");
PassThruClose(DeviceID);
return -1;
}
// 3. Open an ISO 13400 channel
ret = PassThruConnect(DeviceID, ISO13400_PS, 0, 0, &ChannelID);
if (ret != STATUS_NOERROR)
{
PassThruClose(DeviceID);
return ret;
}
// 4. Discover vehicles on the network
ret = PassThruIoctl(ChannelID, ISO13400_DISCOVER_VEHICLES, NULL, NULL);
if (ret != STATUS_NOERROR)
{
printf("Vehicle discovery error\n");
PassThruDisconnect(ChannelID);
PassThruClose(DeviceID);
return ret;
}
// 5. Retrieve information about the discovered vehicle
DOIP_VEHICLE_INFO vehicleInfo;
ret = PassThruIoctl(ChannelID, ISO13400_GET_VEHICLE_INFO, NULL, &vehicleInfo);
if (ret != STATUS_NOERROR)
{
printf("No vehicles found\n");
PassThruDisconnect(ChannelID);
PassThruClose(DeviceID);
return ret;
}
printf("VIN: %s\n", vehicleInfo.VIN);
// 6. Configure DoIP parameters
SCONFIG doipCfg[3];
SCONFIG_LIST doipCfgList = {3, doipCfg};
doipCfg[0].Parameter = ISO13400_SOURCE_ADDR;
doipCfg[0].Value = 0x0E00;
doipCfg[1].Parameter = ISO13400_TARGET_ADDR;
doipCfg[1].Value = vehicleInfo.LogicalAddr;
doipCfg[2].Parameter = ISO13400_ECU_IP_ADDR;
doipCfg[2].Value = vehicleInfo.IPAddr;
ret = PassThruIoctl(ChannelID, SET_CONFIG, &doipCfgList, NULL);
if (ret != STATUS_NOERROR)
{
PassThruDisconnect(ChannelID);
PassThruClose(DeviceID);
return ret;
}
// 7. Establish the TCP connection
ret = PassThruIoctl(ChannelID, ISO13400_CONNECT_TCP, NULL, NULL);
if (ret != STATUS_NOERROR)
{
printf("TCP connection error\n");
PassThruDisconnect(ChannelID);
PassThruClose(DeviceID);
return ret;
}
// 8. Activate routing
unsigned long activationType = 0;
unsigned long responseCode = 0;
ret = PassThruIoctl(ChannelID, ISO13400_ACTIVATE_ROUTING, &activationType, &responseCode);
if (ret != STATUS_NOERROR || responseCode != 0x10)
{
printf("Routing activation error: 0x%02X\n", responseCode);
PassThruDisconnect(ChannelID);
PassThruClose(DeviceID);
return ret;
}
printf("DoIP connection established!\n");
// 9. You can now send diagnostic requests
// via PassThruWriteMsgs / PassThruReadMsgs
// Close the connection
PassThruDisconnect(ChannelID);
PassThruClose(DeviceID);
return 0;
}
suspend fun connectDoIP(): Boolean {
// 1. Open the device
val openResult = j2534.ptOpen(null)
if (openResult.status != STATUS_NOERROR) return false
val deviceID = openResult.deviceId
// 2. Open an ISO 13400 channel
val connectResult = j2534.ptConnect(deviceID, ISO13400_PS, 0u, 0u)
if (connectResult.status != STATUS_NOERROR) {
j2534.ptClose(deviceID)
return false
}
val channelID = connectResult.channelId
// 3. Discover vehicles
val discoverResult = j2534.ptIoctl(channelID, ISO13400_DISCOVER_VEHICLES, 0, null)
if (discoverResult.status != STATUS_NOERROR) {
Log.e("DoIP", "Vehicle discovery error")
j2534.ptDisconnect(channelID)
j2534.ptClose(deviceID)
return false
}
// 4. Retrieve information about the discovered vehicle
val infoResult = j2534.ptGetVehicleInfo(channelID)
if (infoResult.status != STATUS_NOERROR) {
Log.e("DoIP", "No vehicles found")
j2534.ptDisconnect(channelID)
j2534.ptClose(deviceID)
return false
}
Log.i("DoIP", "VIN: ${infoResult.vin}")
// 5. Configure parameters and connect
val params = listOf(
PtConfig(ISO13400_SOURCE_ADDR, 0x0E00u),
PtConfig(ISO13400_TARGET_ADDR, infoResult.logicalAddr.toUInt()),
PtConfig(ISO13400_ECU_IP_ADDR, infoResult.ipAddr)
)
j2534.ptIoctl(channelID, SET_CONFIG, params.size, params.toByteArray())
// 6. TCP connection
val tcpResult = j2534.ptIoctl(channelID, ISO13400_CONNECT_TCP, 0, null)
if (tcpResult.status != STATUS_NOERROR) {
Log.e("DoIP", "TCP connection error")
j2534.ptDisconnect(channelID)
j2534.ptClose(deviceID)
return false
}
// 7. Routing activation
val routingResult = j2534.ptIoctl(channelID, ISO13400_ACTIVATE_ROUTING, 0, null)
if (routingResult.status != STATUS_NOERROR || routingResult.outputValue != 0x10) {
Log.e("DoIP", "Activation error: 0x${routingResult.outputValue.toString(16)}")
j2534.ptDisconnect(channelID)
j2534.ptClose(deviceID)
return false
}
Log.i("DoIP", "DoIP connection established!")
return true
}
from ctypes import *
def connect_doip():
# 1. Open the device
device_id = c_ulong()
ret = j2534.PassThruOpen(None, byref(device_id))
if ret != 0:
return False
# 2. Open an ISO 13400 channel
channel_id = c_ulong()
ret = j2534.PassThruConnect(device_id, ISO13400_PS, 0, 0, byref(channel_id))
if ret != 0:
j2534.PassThruClose(device_id)
return False
# 3. Discover vehicles
ret = j2534.PassThruIoctl(channel_id, ISO13400_DISCOVER_VEHICLES, None, None)
if ret != 0:
print("Vehicle discovery error")
j2534.PassThruDisconnect(channel_id)
j2534.PassThruClose(device_id)
return False
# 4. Retrieve information about the discovered vehicle
vehicle_info = DOIP_VEHICLE_INFO()
ret = j2534.PassThruIoctl(channel_id, ISO13400_GET_VEHICLE_INFO, None, byref(vehicle_info))
if ret != 0:
print("No vehicles found")
j2534.PassThruDisconnect(channel_id)
j2534.PassThruClose(device_id)
return False
print(f"VIN: {vehicle_info.VIN.decode()}")
# 5. Configure DoIP parameters
config = (SCONFIG * 3)()
config[0].Parameter = ISO13400_SOURCE_ADDR
config[0].Value = 0x0E00
config[1].Parameter = ISO13400_TARGET_ADDR
config[1].Value = vehicle_info.LogicalAddr
config[2].Parameter = ISO13400_ECU_IP_ADDR
config[2].Value = vehicle_info.IPAddr
config_list = SCONFIG_LIST()
config_list.NumOfParams = 3
config_list.ConfigPtr = config
ret = j2534.PassThruIoctl(channel_id, SET_CONFIG, byref(config_list), None)
if ret != 0:
j2534.PassThruDisconnect(channel_id)
j2534.PassThruClose(device_id)
return False
# 6. TCP connection
ret = j2534.PassThruIoctl(channel_id, ISO13400_CONNECT_TCP, None, None)
if ret != 0:
print("TCP connection error")
j2534.PassThruDisconnect(channel_id)
j2534.PassThruClose(device_id)
return False
# 7. Routing activation
activation_type = c_ulong(0)
response_code = c_ulong(0)
ret = j2534.PassThruIoctl(channel_id, ISO13400_ACTIVATE_ROUTING, byref(activation_type), byref(response_code))
if ret != 0 or response_code.value != 0x10:
print(f"Activation error: 0x{response_code.value:02X}")
j2534.PassThruDisconnect(channel_id)
j2534.PassThruClose(device_id)
return False
print("DoIP connection established!")
return True
public bool ConnectDoIP()
{
// 1. Open the device
uint deviceId;
int ret = J2534.PassThruOpen(null, out deviceId);
if (ret != 0) return false;
// 2. Open an ISO 13400 channel
uint channelId;
ret = J2534.PassThruConnect(deviceId, ISO13400_PS, 0, 0, out channelId);
if (ret != 0)
{
J2534.PassThruClose(deviceId);
return false;
}
// 3. Discover vehicles
ret = J2534.PassThruIoctl(channelId, ISO13400_DISCOVER_VEHICLES, IntPtr.Zero, IntPtr.Zero);
if (ret != 0)
{
Console.WriteLine("Vehicle discovery error");
J2534.PassThruDisconnect(channelId);
J2534.PassThruClose(deviceId);
return false;
}
// 4. Retrieve information about the discovered vehicle
DOIP_VEHICLE_INFO vehicleInfo;
ret = J2534.PassThruIoctl(channelId, ISO13400_GET_VEHICLE_INFO, IntPtr.Zero, out vehicleInfo);
if (ret != 0)
{
Console.WriteLine("No vehicles found");
J2534.PassThruDisconnect(channelId);
J2534.PassThruClose(deviceId);
return false;
}
Console.WriteLine($"VIN: {Encoding.ASCII.GetString(vehicleInfo.VIN).TrimEnd('\0')}");
// 5. Configure DoIP parameters
var configs = new SCONFIG[3];
configs[0] = new SCONFIG { Parameter = ISO13400_SOURCE_ADDR, Value = 0x0E00 };
configs[1] = new SCONFIG { Parameter = ISO13400_TARGET_ADDR, Value = vehicleInfo.LogicalAddr };
configs[2] = new SCONFIG { Parameter = ISO13400_ECU_IP_ADDR, Value = vehicleInfo.IPAddr };
var configList = new SCONFIG_LIST { NumOfParams = 3, ConfigPtr = configs };
ret = J2534.PassThruIoctl(channelId, SET_CONFIG, ref configList, IntPtr.Zero);
if (ret != 0)
{
J2534.PassThruDisconnect(channelId);
J2534.PassThruClose(deviceId);
return false;
}
// 6. TCP connection
ret = J2534.PassThruIoctl(channelId, ISO13400_CONNECT_TCP, IntPtr.Zero, IntPtr.Zero);
if (ret != 0)
{
Console.WriteLine("TCP connection error");
J2534.PassThruDisconnect(channelId);
J2534.PassThruClose(deviceId);
return false;
}
// 7. Routing activation
uint activationType = 0;
uint responseCode;
ret = J2534.PassThruIoctl(channelId, ISO13400_ACTIVATE_ROUTING, ref activationType, out responseCode);
if (ret != 0 || responseCode != 0x10)
{
Console.WriteLine($"Activation error: 0x{responseCode:X2}");
J2534.PassThruDisconnect(channelId);
J2534.PassThruClose(deviceId);
return false;
}
Console.WriteLine("DoIP connection established!");
return true;
}