1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-28 12:56:49 +01:00

Hauwei: Extend debug request to allow setting the sliced flag

This commit is contained in:
Martin.JM 2024-06-10 14:06:52 +02:00 committed by José Rebelo
parent 81ceb46eab
commit 72dcb3250e
3 changed files with 58 additions and 19 deletions

View File

@ -788,6 +788,10 @@ public class HuaweiPacket {
this.isEncrypted = b;
}
public void setSliced(boolean b) {
this.isSliced = b;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;

View File

@ -48,16 +48,18 @@ public class DebugRequest extends Request {
}
/*
DebugString := [service_id] "," [command id] "," [encryptflag] ("," [tlv])*
DebugString := [service_id] "," [command id] "," [encryptflag] "," [sliceflag] ("," [tlv])*
service_id := int
| "0x" hex
command_id := int
| "0x" hex
encryptflag := "true"
encryptflag := [boolean]
sliceflag := [boolean]
boolean := "true"
| "t"
| "false"
| "f"
tlv := "(" [tag] "," [typevalue] ")"
tlv := "(" [tag] "," [typevalue] ")" ("," [tlv])*
tag := int
| "0x" hex
typevalue := [type] [value]
@ -100,10 +102,8 @@ public class DebugRequest extends Request {
current = nextComma + 1;
nextComma = debugString.indexOf(',', current);
if (debugString.length() - current < 2)
if (nextComma < 1 || debugString.length() - current < 2)
throw new RequestCreationException("Invalid debug command");
if (nextComma < 0)
nextComma = debugString.length(); // For no TLVs
switch (debugString.substring(current, nextComma)) {
case "true":
@ -118,6 +118,26 @@ public class DebugRequest extends Request {
throw new RequestCreationException("Boolean is not a boolean");
}
current = nextComma + 1;
nextComma = debugString.indexOf(',', current);
if (debugString.length() - current < 1)
throw new RequestCreationException("Invalid debug command");
if (nextComma < 0)
nextComma = debugString.length(); // For no TLVs
switch (debugString.substring(current, nextComma)) {
case "true":
case "t":
packet.setSliced(true);
break;
case "false":
case "f":
packet.setSliced(false);
break;
default:
throw new RequestCreationException("Boolean is not a boolean");
}
current = nextComma + 1;
if (current < debugString.length()) {

View File

@ -181,7 +181,22 @@ public class TestDebugRequestParser {
expected.setEncryption(false);
expected.complete = true;
HuaweiPacket packet = debugRequest.parseDebugString("1,1,false");
HuaweiPacket packet = debugRequest.parseDebugString("1,1,false,false");
Assert.assertEquals(expected, packet);
}
@Test
public void emptyPacketShortBooleans() throws Request.RequestCreationException {
DebugRequest debugRequest = new DebugRequest(supportProvider);
HuaweiPacket expected = new HuaweiPacket(supportProvider.getParamsProvider());
expected.serviceId = 1;
expected.commandId = 1;
expected.setEncryption(false);
expected.complete = true;
HuaweiPacket packet = debugRequest.parseDebugString("1,1,f,f");
Assert.assertEquals(expected, packet);
}
@ -197,7 +212,7 @@ public class TestDebugRequestParser {
expected.setTlv(new HuaweiTLV().put(1));
expected.complete = true;
HuaweiPacket packet = debugRequest.parseDebugString("1,1,false,(1,/)");
HuaweiPacket packet = debugRequest.parseDebugString("1,1,false,false,(1,/)");
Assert.assertEquals(expected, packet);
}
@ -213,7 +228,7 @@ public class TestDebugRequestParser {
expected.setTlv(new HuaweiTLV().put(1, (byte) 1));
expected.complete = true;
HuaweiPacket packet = debugRequest.parseDebugString("1,1,false,(1,B1)");
HuaweiPacket packet = debugRequest.parseDebugString("1,1,false,false,(1,B1)");
Assert.assertEquals(expected, packet);
}
@ -229,7 +244,7 @@ public class TestDebugRequestParser {
expected.setTlv(new HuaweiTLV().put(1, (short) 1));
expected.complete = true;
HuaweiPacket packet = debugRequest.parseDebugString("1,1,false,(1,S1)");
HuaweiPacket packet = debugRequest.parseDebugString("1,1,false,false,(1,S1)");
Assert.assertEquals(expected, packet);
}
@ -245,7 +260,7 @@ public class TestDebugRequestParser {
expected.setTlv(new HuaweiTLV().put(1, (int) 1));
expected.complete = true;
HuaweiPacket packet = debugRequest.parseDebugString("1,1,false,(1,I1)");
HuaweiPacket packet = debugRequest.parseDebugString("1,1,false,false,(1,I1)");
Assert.assertEquals(expected, packet);
}
@ -261,7 +276,7 @@ public class TestDebugRequestParser {
expected.setTlv(new HuaweiTLV().put(1, true));
expected.complete = true;
HuaweiPacket packet = debugRequest.parseDebugString("1,1,false,(1,b1)");
HuaweiPacket packet = debugRequest.parseDebugString("1,1,false,false,(1,b1)");
Assert.assertEquals(expected, packet);
}
@ -277,7 +292,7 @@ public class TestDebugRequestParser {
expected.setTlv(new HuaweiTLV().put(1, new byte[] {(byte) 0xCA, (byte) 0xFE}));
expected.complete = true;
HuaweiPacket packet = debugRequest.parseDebugString("1,1,false,(1,aCAFE)");
HuaweiPacket packet = debugRequest.parseDebugString("1,1,false,false,(1,aCAFE)");
Assert.assertEquals(expected, packet);
}
@ -293,7 +308,7 @@ public class TestDebugRequestParser {
expected.setTlv(new HuaweiTLV().put(1, new byte[] {0x79, 0x65, 0x73}));
expected.complete = true;
HuaweiPacket packet = debugRequest.parseDebugString("1,1,false,(1,-yes)");
HuaweiPacket packet = debugRequest.parseDebugString("1,1,false,false,(1,-yes)");
Assert.assertEquals(expected, packet);
}
@ -309,7 +324,7 @@ public class TestDebugRequestParser {
expected.setTlv(new HuaweiTLV().put(1, new byte[] {0x79, 0x65, 0x73}));
expected.complete = true;
HuaweiPacket packet = debugRequest.parseDebugString("0x01,0x1,false,(0x01,-yes)");
HuaweiPacket packet = debugRequest.parseDebugString("0x01,0x1,false,false,(0x01,-yes)");
Assert.assertEquals(expected, packet);
}
@ -324,7 +339,7 @@ public class TestDebugRequestParser {
expected.setEncryption(false);
expected.complete = true;
HuaweiPacket packet = debugRequest.parseDebugString("0xff,255,false");
HuaweiPacket packet = debugRequest.parseDebugString("0xff,255,false,false");
Assert.assertEquals(expected, packet);
}
@ -344,7 +359,7 @@ public class TestDebugRequestParser {
));
expected.complete = true;
HuaweiPacket packet = debugRequest.parseDebugString("1,1,false,(129,(1,/),(2,/))");
HuaweiPacket packet = debugRequest.parseDebugString("1,1,false,false,(129,(1,/),(2,/))");
Assert.assertEquals(expected, packet);
}
@ -367,7 +382,7 @@ public class TestDebugRequestParser {
));
expected.complete = true;
HuaweiPacket packet = debugRequest.parseDebugString("1,1,false,(129,(129,(129,(1,/))))");
HuaweiPacket packet = debugRequest.parseDebugString("1,1,false,false,(129,(129,(129,(1,/))))");
Assert.assertEquals(expected, packet);
}
@ -389,7 +404,7 @@ public class TestDebugRequestParser {
);
expected.complete = true;
HuaweiPacket packet = debugRequest.parseDebugString("1,1,false,(129,(1,/),(2,b1)),(1,b1)");
HuaweiPacket packet = debugRequest.parseDebugString("1,1,false,false,(129,(1,/),(2,b1)),(1,b1)");
Assert.assertEquals(expected, packet);
}