From 664cc129f1a5ad13fab966d3c293e7aa6ce12ab6 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Wed, 5 Oct 2016 14:20:59 +0500 Subject: - Remove hardcoded password from commands - Authenticate device on heardbeat stage --- src/org/traccar/protocol/Gl200Protocol.java | 1 + src/org/traccar/protocol/Gl200ProtocolDecoder.java | 9 +++++++-- src/org/traccar/protocol/Gl200ProtocolEncoder.java | 14 ++++++++++---- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/org/traccar/protocol/Gl200Protocol.java b/src/org/traccar/protocol/Gl200Protocol.java index d38bdf8a9..3bf558d71 100644 --- a/src/org/traccar/protocol/Gl200Protocol.java +++ b/src/org/traccar/protocol/Gl200Protocol.java @@ -35,6 +35,7 @@ public class Gl200Protocol extends BaseProtocol { Command.TYPE_POSITION_SINGLE, Command.TYPE_ENGINE_STOP, Command.TYPE_ENGINE_RESUME, + Command.TYPE_IDENTIFICATION, Command.TYPE_REBOOT_DEVICE); } diff --git a/src/org/traccar/protocol/Gl200ProtocolDecoder.java b/src/org/traccar/protocol/Gl200ProtocolDecoder.java index 385039399..362e3fb38 100644 --- a/src/org/traccar/protocol/Gl200ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gl200ProtocolDecoder.java @@ -39,7 +39,8 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN_HBD = new PatternBuilder() .text("+ACK:GTHBD,") - .number("([0-9A-Z]{2}xxxx),") + .number("([0-9A-Z]{2}xxxx),") // protocol version + .number("(d{15}),") // imei .any().text(",") .number("(xxxx)") .text("$").optional() @@ -245,7 +246,11 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { private Object decodeHbd(Channel channel, SocketAddress remoteAddress, String sentence) { Parser parser = new Parser(PATTERN_HBD, sentence); if (parser.matches() && channel != null) { - channel.write("+SACK:GTHBD," + parser.next() + "," + parser.next() + "$", remoteAddress); + String protocolVersion = parser.next(); + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next()); + if (deviceSession != null) { + channel.write("+SACK:GTHBD," + protocolVersion + "," + parser.next() + "$", remoteAddress); + } } return null; } diff --git a/src/org/traccar/protocol/Gl200ProtocolEncoder.java b/src/org/traccar/protocol/Gl200ProtocolEncoder.java index 0537420a0..25ca1bf75 100644 --- a/src/org/traccar/protocol/Gl200ProtocolEncoder.java +++ b/src/org/traccar/protocol/Gl200ProtocolEncoder.java @@ -24,15 +24,21 @@ public class Gl200ProtocolEncoder extends StringProtocolEncoder { @Override protected Object encodeCommand(Command command) { + initDevicePassword(command, ""); + switch (command.getType()) { case Command.TYPE_POSITION_SINGLE: - return "AT+GTRTO=gv300,1,,,,,,FFFF$"; + return formatCommand(command, "AT+GTRTO={%s},1,,,,,,FFFF$", Command.KEY_DEVICE_PASSWORD); case Command.TYPE_ENGINE_STOP: - return "AT+GTOUT=gv300,1,,,0,0,0,0,0,0,0,,,,,,,FFFF$"; + return formatCommand(command, "AT+GTOUT={%s},1,,,0,0,0,0,0,0,0,,,,,,,FFFF$", + Command.KEY_DEVICE_PASSWORD); case Command.TYPE_ENGINE_RESUME: - return "AT+GTOUT=gv300,0,,,0,0,0,0,0,0,0,,,,,,,FFFF$"; + return formatCommand(command, "AT+GTOUT={%s},0,,,0,0,0,0,0,0,0,,,,,,,FFFF$", + Command.KEY_DEVICE_PASSWORD); + case Command.TYPE_IDENTIFICATION: + return formatCommand(command, "AT+GTRTO={%s},8,,,,,,FFFF$", Command.KEY_DEVICE_PASSWORD); case Command.TYPE_REBOOT_DEVICE: - return "AT+GTRTO=gv300,3,,,,,,FFFF$"; + return formatCommand(command, "AT+GTRTO={%s},3,,,,,,FFFF$", Command.KEY_DEVICE_PASSWORD); default: Log.warning(new UnsupportedOperationException(command.getType())); break; -- cgit v1.2.3 From 1160c79fa59518f70183aea4b58b12755bdf6475 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Wed, 5 Oct 2016 14:24:11 +0500 Subject: Fix comment indentation --- src/org/traccar/protocol/Gl200ProtocolDecoder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/org/traccar/protocol/Gl200ProtocolDecoder.java b/src/org/traccar/protocol/Gl200ProtocolDecoder.java index 362e3fb38..b55f4e606 100644 --- a/src/org/traccar/protocol/Gl200ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gl200ProtocolDecoder.java @@ -39,7 +39,7 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN_HBD = new PatternBuilder() .text("+ACK:GTHBD,") - .number("([0-9A-Z]{2}xxxx),") // protocol version + .number("([0-9A-Z]{2}xxxx),") // protocol version .number("(d{15}),") // imei .any().text(",") .number("(xxxx)") -- cgit v1.2.3