Skip to content

Commit

Permalink
Change DoIP version to 0x03. It's not yet possible to change it at ru…
Browse files Browse the repository at this point in the history
…ntime, but it made configurable in one of the next versions. In addition we change some logging messages.
  • Loading branch information
marco-wehnert authored and doip committed May 18, 2023
1 parent 06f2316 commit 0e180d2
Show file tree
Hide file tree
Showing 35 changed files with 396 additions and 161 deletions.
18 changes: 18 additions & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,24 @@ https://github.com/doip/doip-library.git
A documentation of the whole project is available at
http://automotive-doip.com/downloads/DoIP-Software-Documentation.pdf

==============================================================================

Release Notes for Version: 1.3.0

CHANGES
=======

- Issue #24: Changed DoIP version to 0x03

==============================================================================

Release Notes for Version: 1.2.2

CHANGES
=======

- Issue #22: Updated README

==============================================================================

Release Notes for Version: 1.2.1
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {


group = "com.github.doip"
version = '1.2.2'
version = '1.3.0'

repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public interface DoipTcpConnectionListener {

public void onDoipTcpDiagnosticMessagePosAck(DoipTcpConnection doipTcpConnection, DoipTcpDiagnosticMessagePosAck doipMessage);

public void onDoipTcpDiagnosticMessageNegAck(DoipTcpConnection doipTcpConnection, DoipTcpDiagnosticMessageNegAck doipTcpDiagnosticMessageNegAck);
public void onDoipTcpDiagnosticMessageNegAck(DoipTcpConnection doipTcpConnection, DoipTcpDiagnosticMessageNegAck doipTcpDiagnosticMessageNegAck);

public void onDoipTcpRoutingActivationRequest(DoipTcpConnection doipTcpConnection, DoipTcpRoutingActivationRequest doipMessage);

Expand Down
31 changes: 18 additions & 13 deletions src/main/java/doip/library/comm/DoipTcpStreamBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.MarkerManager;

import doip.library.message.DoipMessage;
import doip.library.util.StreamBuffer;
Expand All @@ -21,10 +23,10 @@
*/
public class DoipTcpStreamBuffer extends StreamBuffer {

/**
* log4j2 logger
*/
/** Log4j2 logger */
private static Logger logger = LogManager.getLogger(DoipTcpStreamBuffer.class);
private static Marker enter = MarkerManager.getMarker("ENTER");
private static Marker exit = MarkerManager.getMarker("EXIT");

public static final int STATE_HEADER_NOT_COMPLETED = 1;

Expand Down Expand Up @@ -60,17 +62,17 @@ public class DoipTcpStreamBuffer extends StreamBuffer {
private int state = STATE_HEADER_NOT_COMPLETED;

public void addListener(DoipTcpStreamBufferListener listener) {
logger.trace(">>> public void addListener(DoipStreamBufferListener listener)");
logger.trace(enter, ">>> public void addListener(DoipStreamBufferListener listener)");
this.listeners.add(listener);
logger.trace("<<< public void addListener(DoipStreamBufferListener listener)");
logger.trace(exit, "<<< public void addListener(DoipStreamBufferListener listener)");
}

/**
* Appends the new data to the internal buffer and starts to process the data in
* the buffer.
*/
public void append(byte[] newData) {
logger.trace(">>> void append(byte[] newData)");
logger.trace(enter, ">>> void append(byte[] newData)");

logger.debug("Append " + newData.length + " bytes to the buffer");
super.append(newData);
Expand All @@ -80,7 +82,7 @@ public void append(byte[] newData) {
+ " bytes in the buffer which needs to get processed. Calling processBuffer() again.");
ret = this.processBuffer();
}
logger.trace("<<< void append(byte[] newData)");
logger.trace(exit, "<<< void append(byte[] newData)");
}

/**
Expand All @@ -91,18 +93,21 @@ public void append(byte[] newData) {
* payload types for UDP messages will also be declared as invalid
* payload type.
*/
public boolean checkPayloadType(int payloadType) {
public static boolean isValidTcpPayloadType(int payloadType) {
logger.trace(enter, ">>> public boolean checkPayloadType(int payloadType)");
boolean ret = false;
if (payloadType == 0x0000 || payloadType == 0x0005 || payloadType == 0x0006 || payloadType == 0x0007
|| payloadType == 0x0008 || payloadType == 0x8001 || payloadType == 0x8002 || payloadType == 0x8003) {
return true;
ret = true;
}
return false;
logger.trace(enter, ">>> public boolean checkPayloadType(int payloadType)");
return ret;
}

/**
* This function will check if the payload length is correct.
*
* @return Returns true if the payload is correct for the specific payload type.
* @return Returns true if the payload length is correct for the specific payload type.
*/
public boolean checkPayloadTypeSpecificLength() {
logger.trace(">>> boolean checkPayloadTypeSpecificLength()");
Expand Down Expand Up @@ -155,7 +160,7 @@ public boolean checkPayloadTypeSpecificLength() {
* @param data The data which will be checked.
* @return Returns true if the first two bytes contain a valid sync pattern
*/
public boolean checkSyncPattern(byte[] data) {
public static boolean checkSyncPattern(byte[] data) {
logger.trace(">>> boolean checkSyncPattern(byte[] data)");
int protocolVersion = data[0] & 0xFF;
int inverseProtocolVersion = data[1] & 0xFF;
Expand Down Expand Up @@ -223,7 +228,7 @@ public void handleTcpHeader() {
this.payloadLength = (highhigh << 24) | (highlow << 16) | (lowhigh << 8) | lowlow;
logger.debug("\tPayload Length in Header = " + payloadLength);

if (checkPayloadType(payloadType) == false) {
if (isValidTcpPayloadType(payloadType) == false) {
logger.warn("Invalid payload type");
this.onHeaderUnknownPayloadType();
this.state = STATE_SHREDDER_NOT_COMPLETED;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/doip/library/comm/DoipUdpMessageHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,11 @@ public void onDoipUdpEntityStatusRequest(DoipUdpEntityStatusRequest doipMessage,
">>> public void onDoipUdpEntityStatusRequest(DoipUdpEntityStatusRequest doipMessage, DatagramPacket packet)");
}

logger.debug("Number of listeners = " + this.listeners.size());
Iterator<DoipUdpMessageHandlerListener> iter = this.listeners.iterator();
while (iter.hasNext()) {
DoipUdpMessageHandlerListener listener = iter.next();
logger.debug("Calling listener on address " + listener.toString());
listener.onDoipUdpEntityStatusRequest(doipMessage, packet);
}

Expand Down Expand Up @@ -496,7 +498,6 @@ public void onHeaderTooShort(DatagramPacket packet) {
if (logger.isTraceEnabled()) {
logger.trace("<<< public void onHdeaderTooShort(DatagramPacket packet)");
}

}

public void onInvalidPayloadLength(DatagramPacket packet) {
Expand Down
43 changes: 24 additions & 19 deletions src/main/java/doip/library/message/DoipMessage.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package doip.library.message;

import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/**
* Base class for all DoIP Messages
Expand Down Expand Up @@ -28,6 +30,8 @@ public abstract class DoipMessage {
public final static int TYPE_TCP_DIAG_MESSAGE = 0x8001;
public final static int TYPE_TCP_DIAG_MESSAGE_POS_ACK = 0x8002;
public final static int TYPE_TCP_DIAG_MESSAGE_NEG_ACK = 0x8003;

private static Logger logger = LogManager.getLogger(DoipMessage.class);

protected DoipMessage() {
}
Expand All @@ -36,43 +40,44 @@ protected DoipMessage() {

public abstract void log(Level level);

public static String getPayloadTypeAsString(int type) {
public abstract String getMessageName();

public static String getPayloadTypeAsString(int type) {
switch (type) {
case 0x0000:
return "Generic DoIP Header Negative Acknowledge";
return "generic DoIP header negative acknowledge";
case 0x0001:
return "Vehicle Identification Request Message";
return "vehicle identification request message";
case 0x0002:
return "Vehicle Identification Request Message with EID";
return "vehicle identification request message with EID";
case 0x0003:
return "Vehicle Identification Request Message with VIN";
return "vehicle identification request message with VIN";
case 0x0004:
return "Vehicle Announcement Message";
return "vehicle announcement message";
case 0x0005:
return "Routing Activation Request";
return "routing activation request";
case 0x0006:
return "Routing Activation Response";
return "routing activation response";
case 0x0007:
return "Alive Check Request";
return "alive check request";
case 0x0008:
return "Alive Check Response";
return "alive check response";
case 0x4001:
return "DoIP Entity Status Request";
return "DoIP entity status request";
case 0x4002:
return "DoIP Entity Status Response";
return "DoIP entity status response";
case 0x4003:
return "Diagnostic Power Mode Information Request";
return "diagnostic power mode information request";
case 0x4004:
return "Diagnostic Power Mode Information Response";
return "diagnostic power mode information response";
case 0x8001:
return "Diagnostic Message";
return "diagnostic message";
case 0x8002:
return "Diagnostic Message Positive Acknowledgement";
return "diagnostic message positive acknowledgement";
case 0x8003:
return "Diagnostic Message Negative Acknowledgement";
return "diagnostic message negative acknowledgement";
default:
break;
throw logger.throwing(Level.FATAL, new IllegalArgumentException("An invaid value has been passed to function DoipMessage.getPayoadTypeAsString(int type)"));
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,23 @@ public void log(Level level) {
logger.log(level, "DoIP alive check request");
logger.log(level, "----------------------------------------");
}

public String getMessageName() {
return getPayloadTypeAsString(DoipMessage.TYPE_TCP_ALIVE_REQ);
}

public static String getMessageNameOfClass() {
return getPayloadTypeAsString(DoipMessage.TYPE_TCP_ALIVE_REQ);
}

@Override
public void parsePayload(byte[] payload) {
// Nothing to parse because there is no payload
}

@Override
public byte[] getMessage() {
byte[] message = new byte[] { 0x02, (byte) 0xFD, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00 };
byte[] message = new byte[] { 0x03, (byte) 0xFC, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00 };
return message;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ public DoipTcpAliveCheckResponse(int sourceAddress) {
log(Level.INFO);
}
}

public String getMessageName() {
return getPayloadTypeAsString(DoipMessage.TYPE_TCP_ALIVE_RES);
}

public static String getMessageNameOfClass() {
return getPayloadTypeAsString(DoipMessage.TYPE_TCP_ALIVE_RES);
}

public void log(Level level) {
logger.log(level, "----------------------------------------");
Expand All @@ -42,7 +50,7 @@ public void parsePayload(byte[] payload) {

@Override
public byte[] getMessage() {
byte[] message = new byte[] { 0x02, (byte) 0xFD, 0x00, 0x08, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00 };
byte[] message = new byte[] { 0x03, (byte) 0xFC, 0x00, 0x08, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00 };
message[8] = (byte) (sourceAddress >> 8);
message[9] = (byte) sourceAddress;
return message;
Expand Down
17 changes: 12 additions & 5 deletions src/main/java/doip/library/message/DoipTcpDiagnosticMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,23 @@ public DoipTcpDiagnosticMessage(int sourceAddress, int targetAddress, byte[] mes
this.log(Level.INFO);
}
}

public String getMessageName() {
return getPayloadTypeAsString(DoipMessage.TYPE_TCP_DIAG_MESSAGE);
}

public static String getMessageNameOfClass() {
return getPayloadTypeAsString(DoipMessage.TYPE_TCP_DIAG_MESSAGE);
}

public void log(Level level) {
logger.log(level, "----------------------------------------");
logger.log(level, "DoIP diagnostic message:");
logger.log(level, " Source address = " + this.sourceAddress);
logger.log(level, " Target address = " + this.targetAddress);
logger.log(level, " Source address = " + String.format("0x%04X", this.sourceAddress));
logger.log(level, " Target address = " + String.format("0x%04X", this.targetAddress));
logger.log(level,
" Message = " + Conversion.byteArrayToHexStringShortDotted(this.diagnosticMessage, 64));
logger.log(level, "----------------------------------------");

}

@Override
Expand All @@ -61,8 +68,8 @@ public static DoipTcpDiagnosticMessage createInstance(byte[] payload) {
public byte[] getMessage() {

byte[] data = new byte[8 + 4 + diagnosticMessage.length];
data[0] = 0x02;
data[1] = (byte) 0xFD;
data[0] = 0x03;
data[1] = (byte) 0xFC;
data[2] = (byte) 0x80;
data[3] = 0x01;
data[4] = (byte) ((diagnosticMessage.length + 4) >> 24);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ public abstract class DoipTcpDiagnosticMessageAck extends DoipTcpMessage {
protected DoipTcpDiagnosticMessageAck() {
}

public DoipTcpDiagnosticMessageAck(int sourceAddress, int targetAddress, int ackCode, byte[] message) {
public DoipTcpDiagnosticMessageAck(int sourceAddress, int targetAddress, int ackCode, byte[] diagnosticMessage) {
this.sourceAddress = sourceAddress;
this.targetAddress = targetAddress;
this.ackCode = ackCode;
if (message != null) {
this.diagnosticMessage = message;
if (diagnosticMessage != null) {
this.diagnosticMessage = diagnosticMessage;
}
}

Expand All @@ -32,7 +32,7 @@ public void parsePayload(byte[] payload) {
this.targetAddress = (high << 8) | low;
this.ackCode = payload[4] & 0xFF;
if (payload.length > 5) {
this.diagnosticMessage = Arrays.copyOfRange(payload, 5, payload.length - 5);
this.diagnosticMessage = Arrays.copyOfRange(payload, 5, payload.length);
} else {
this.diagnosticMessage = new byte[] {};
}
Expand All @@ -41,8 +41,8 @@ public void parsePayload(byte[] payload) {
@Override
public byte[] getMessage() {
byte[] data = new byte[8 + 4 + 1 + diagnosticMessage.length];
data[0] = 0x02;
data[1] = (byte) 0xFD;
data[0] = 0x03;
data[1] = (byte) 0xFC;
data[2] = (byte) 0x80;
if (this.ackCode == 0) {
data[3] = 0x02;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ public DoipTcpDiagnosticMessageNegAck(int sourceAddress, int targetAddress, int
log(Level.INFO);
}

public String getMessageName () {
return getPayloadTypeAsString(DoipMessage.TYPE_TCP_DIAG_MESSAGE_NEG_ACK);
}

public static String getMessageNameOfClass() {
return getPayloadTypeAsString(DoipMessage.TYPE_TCP_DIAG_MESSAGE_NEG_ACK);
}

public String getNackCodeAsString(int code) {
switch (code) {
case 0x02:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ public DoipTcpDiagnosticMessagePosAck(int sourceAddress, int targetAddress, int
log(Level.INFO);
}

public String getMessageName() {
return getPayloadTypeAsString(DoipMessage.TYPE_TCP_DIAG_MESSAGE_POS_ACK);
}

public static String getMessageNameOfClass() {
return getPayloadTypeAsString(DoipMessage.TYPE_TCP_DIAG_MESSAGE_POS_ACK);
}

public void log(Level level) {
logger.log(level, "----------------------------------------");
logger.log(level, "DoIP diagnostic message positive acknowledgement:");
Expand Down
Loading

0 comments on commit 0e180d2

Please sign in to comment.