aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar
diff options
context:
space:
mode:
authorStefan Clark <stefanclark@gmail.com>2022-07-28 22:37:15 +0100
committerStefan Clark <stefanclark@gmail.com>2022-07-28 22:37:15 +0100
commit42e88c2bf95962f1274a8bbb6e8fc09af95f627f (patch)
tree40fc4b9ef9de16e634e706895c27a46f934d7cac /src/main/java/org/traccar
parentde2219565e4a61aa0d64b03650ec36ef6d17de93 (diff)
downloadtrackermap-server-42e88c2bf95962f1274a8bbb6e8fc09af95f627f.tar.gz
trackermap-server-42e88c2bf95962f1274a8bbb6e8fc09af95f627f.tar.bz2
trackermap-server-42e88c2bf95962f1274a8bbb6e8fc09af95f627f.zip
Added udp() to Checksum helper and Updated Xexun2 procotol
Diffstat (limited to 'src/main/java/org/traccar')
-rw-r--r--src/main/java/org/traccar/helper/Checksum.java19
-rw-r--r--src/main/java/org/traccar/protocol/Xexun2ProtocolDecoder.java11
-rw-r--r--src/main/java/org/traccar/protocol/Xexun2ProtocolEncoder.java24
3 files changed, 29 insertions, 25 deletions
diff --git a/src/main/java/org/traccar/helper/Checksum.java b/src/main/java/org/traccar/helper/Checksum.java
index 8c3d0063a..e660790ef 100644
--- a/src/main/java/org/traccar/helper/Checksum.java
+++ b/src/main/java/org/traccar/helper/Checksum.java
@@ -200,4 +200,23 @@ public final class Checksum {
return (10 - (checksum % 10)) % 10;
}
+ public static int udp(ByteBuffer data) {
+ int sum = 0;
+ int len = data.capacity();
+ for (int j = 0; len > 1; len--) {
+ sum += data.get() & 0xff;
+ if ((sum & 0x80000000) > 0) {
+ sum = (sum & 0xffff) + (sum >> 16);
+ }
+ }
+ if (len == 1) {
+ sum += data.get() & 0xff;
+ }
+ while ((sum >> 16) > 0) {
+ sum = (sum & 0xffff) + sum >> 16;
+ }
+ sum = (sum == 0xffff) ? sum & 0xffff : (~sum) & 0xffff;
+ return sum;
+ }
+
}
diff --git a/src/main/java/org/traccar/protocol/Xexun2ProtocolDecoder.java b/src/main/java/org/traccar/protocol/Xexun2ProtocolDecoder.java
index 8deb2328b..f0158e6ce 100644
--- a/src/main/java/org/traccar/protocol/Xexun2ProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/Xexun2ProtocolDecoder.java
@@ -24,6 +24,7 @@ import org.traccar.session.DeviceSession;
import org.traccar.NetworkMessage;
import org.traccar.Protocol;
import org.traccar.helper.BitUtil;
+import org.traccar.helper.Checksum;
import org.traccar.helper.UnitsConverter;
import org.traccar.model.CellTower;
import org.traccar.model.Network;
@@ -97,13 +98,17 @@ public class Xexun2ProtocolDecoder extends BaseProtocolDecoder {
return null;
}
+ int payloadSize = buf.readUnsignedShort() & 0x03ff;
+ int checksum = buf.readUnsignedShort(); // checksum
+
+ if (checksum != Checksum.udp(buf.nioBuffer(buf.readerIndex(), payloadSize))) {
+ return null;
+ }
+
if (type != Xexun2ProtocolEncoder.MSG_COMMAND) {
sendResponse(channel, type, index, imei);
}
- buf.readUnsignedShort(); // attributes
- buf.readUnsignedShort(); // checksum
-
if (type == MSG_POSITION) {
List<Integer> lengths = new ArrayList<>();
List<Position> positions = new ArrayList<>();
diff --git a/src/main/java/org/traccar/protocol/Xexun2ProtocolEncoder.java b/src/main/java/org/traccar/protocol/Xexun2ProtocolEncoder.java
index f876853bf..6e1e1d68d 100644
--- a/src/main/java/org/traccar/protocol/Xexun2ProtocolEncoder.java
+++ b/src/main/java/org/traccar/protocol/Xexun2ProtocolEncoder.java
@@ -18,6 +18,7 @@ package org.traccar.protocol;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.traccar.BaseProtocolEncoder;
+import org.traccar.helper.Checksum;
import org.traccar.helper.DataConverter;
import org.traccar.model.Command;
import org.traccar.Protocol;
@@ -62,26 +63,6 @@ public class Xexun2ProtocolEncoder extends BaseProtocolEncoder {
return result;
}
- private static int udpchecksum(ByteBuf data) {
- int sum = 0;
- int len = data.capacity();
- for (int j = 0; len > 1; len--) {
- sum += data.readByte() & 0xff;
- if ((sum & 0x80000000) > 0) {
- sum = (sum & 0xffff) + (sum >> 16);
- }
- }
- if (len == 1) {
- sum += data.readByte() & 0xff;
- }
- while ((sum >> 16) > 0) {
- sum = (sum & 0xffff) + sum >> 16;
- }
- sum = (sum == 0xffff) ? sum & 0xffff : (~sum) & 0xffff;
- return sum;
- }
-
-
private static ByteBuf encodeContent(String uniqueId, String content) {
ByteBuf buf = Unpooled.buffer();
@@ -92,8 +73,7 @@ public class Xexun2ProtocolEncoder extends BaseProtocolEncoder {
buf.writeShort(1); // index
buf.writeBytes(DataConverter.parseHex(uniqueId + "0"));
buf.writeShort(message.capacity());
- buf.writeShort(udpchecksum(message));
- message.resetReaderIndex();
+ buf.writeShort(Checksum.udp(message.nioBuffer()));
buf.writeBytes(message);
buf.writeShort(FLAG);