huawei; fileupload: Parse FileUploadConsultAck.Response

This commit is contained in:
Vitaliy Tomin 2024-04-01 22:57:54 +08:00
parent 68e81a4887
commit b543e4717e
4 changed files with 49 additions and 6 deletions

View File

@ -544,6 +544,8 @@ public class HuaweiPacket {
switch(this.commandId) {
case FileUpload.FileNextChunkParams.id:
return new FileUpload.FileNextChunkParams(paramsProvider).fromPacket(this);
case FileUpload.FileUploadConsultAck.id:
return new FileUpload.FileUploadConsultAck.Response(paramsProvider).fromPacket(this);
default:
this.isEncrypted = this.attemptDecrypt(); // Helps with debugging
return this;

View File

@ -71,22 +71,58 @@ public class FileUpload {
public static class FileUploadConsultAck {
public static final byte id = 0x04;
public static class Request extends HuaweiPacket {
public Request(ParamsProvider paramsProvider) {
public Request(ParamsProvider paramsProvider, byte noEncryption) {
super(paramsProvider);
this.serviceId = FileUpload.id;
this.commandId = id;
this.tlv = new HuaweiTLV()
.put(0x7f, 0x000186A0) //ok
.put(0x01, (byte) 0x01) // filetype 1 - watchface, 2 -music
.put(0x09, (byte) 0x01); //??? present in watchface only
.put(0x01, (byte) 0x01); // filetype 1 - watchface, 2 -music
if (noEncryption == 1)
this.tlv.put(0x09, (byte)0x01); // need on devices which generally encrypted, but files
this.complete = true;
}
}
public static class Response extends HuaweiPacket {
public byte file_id = 0;
public String protocolVersion = "";
public short app_wait_time = 0;
public byte bitmap_enable = 0;
public short unit_size = 0;
public int max_apply_data_size = 0;
public short interval =0;
public int received_file_size =0;
public byte no_encrypt = 0;
public Response (ParamsProvider paramsProvider) {
super(paramsProvider);
}
@Override
public void parseTlv() throws HuaweiPacket.ParseException {
if (this.tlv.contains(0x01) && this.tlv.getBytes(0x01).length == 1)
this.file_id = this.tlv.getByte(0x01);
if (this.tlv.contains(0x02))
this.protocolVersion = this.tlv.getString(0x02);
if (this.tlv.contains(0x03) && this.tlv.getBytes(0x03).length == 2)
this.app_wait_time = this.tlv.getShort(0x03);
if (this.tlv.contains(0x04))
this.bitmap_enable = this.tlv.getByte(0x04);
if (this.tlv.contains(0x05) && this.tlv.getBytes(0x05).length == 2)
this.unit_size = this.tlv.getShort(0x05);
if (this.tlv.contains(0x06) && this.tlv.getBytes(0x06).length == 4)
this.max_apply_data_size = this.tlv.getInteger(0x06);
if (this.tlv.contains(0x07) && this.tlv.getBytes(0x07).length == 2)
this.interval = this.tlv.getShort(0x07);
if (this.tlv.contains(0x08) && this.tlv.getBytes(0x08).length == 4)
this.received_file_size = this.tlv.getInteger(0x08);
if (this.tlv.contains(0x09))
this.no_encrypt = this.tlv.getByte(0x09);
}
}
}

View File

@ -400,8 +400,11 @@ public class AsynchronousResponse {
LOG.error("Could not send fileupload hash request", e);
}
} else if (response.commandId == FileUpload.FileUploadConsultAck.id) {
if (!(response instanceof FileUpload.FileUploadConsultAck.Response))
throw new Request.ResponseTypeMismatchException(response, FileUpload.FileUploadConsultAck.Response.class);
FileUpload.FileUploadConsultAck.Response resp = (FileUpload.FileUploadConsultAck.Response) response;
try {
SendFileUploadAck sendFileUploadAck = new SendFileUploadAck(this.support);
SendFileUploadAck sendFileUploadAck = new SendFileUploadAck(this.support, resp.no_encrypt);
sendFileUploadAck.doPerform();
} catch (IOException e) {
LOG.error("Could not send fileupload ack request", e);

View File

@ -7,16 +7,18 @@ import nodomain.freeyourgadget.gadgetbridge.devices.huawei.packets.FileUpload;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.HuaweiSupportProvider;
public class SendFileUploadAck extends Request {
public SendFileUploadAck(HuaweiSupportProvider support) {
byte noEncryption = 0;
public SendFileUploadAck(HuaweiSupportProvider support, byte noEncryption) {
super(support);
this.serviceId = FileUpload.id;
this.commandId = FileUpload.FileUploadConsultAck.id;
this.noEncryption = noEncryption;
}
@Override
protected List<byte[]> createRequest() throws RequestCreationException {
try {
return new FileUpload.FileUploadConsultAck.Request(this.paramsProvider ).serialize();
return new FileUpload.FileUploadConsultAck.Request(this.paramsProvider, this.noEncryption ).serialize();
} catch (HuaweiPacket.CryptoException e) {
throw new RequestCreationException(e);
}