Get USB Data remote packet.

This commit is contained in:
2019-10-18 23:42:18 +01:00
parent bcf8f3951b
commit 2cfcdf8842
2 changed files with 178 additions and 84 deletions

View File

@@ -451,6 +451,8 @@ namespace DiscImageChef.Devices
#region USB #region USB
if (remote is null)
{
switch (PlatformId) switch (PlatformId)
{ {
case PlatformID.Linux: case PlatformID.Linux:
@@ -544,7 +546,8 @@ namespace DiscImageChef.Devices
UsbManufacturerString = usbDevice.Manufacturer; UsbManufacturerString = usbDevice.Manufacturer;
UsbProductString = usbDevice.Product; UsbProductString = usbDevice.Product;
UsbSerialString = UsbSerialString =
usbDevice.SerialNumber; // This is incorrect filled by Windows with SCSI/ATA serial number usbDevice
.SerialNumber; // This is incorrect filled by Windows with SCSI/ATA serial number
} }
break; break;
@@ -552,6 +555,22 @@ namespace DiscImageChef.Devices
IsUsb = false; IsUsb = false;
break; break;
} }
}
else
{
if (remote.GetUsbData(out var remoteUsbDescriptors, out var remoteUsbVendor,
out var remoteUsbProduct, out var remoteUsbManufacturer, out var remoteUsbProductString,
out var remoteUsbSerial))
{
IsUsb = true;
UsbDescriptors = remoteUsbDescriptors;
usbVendor = remoteUsbVendor;
usbProduct = remoteUsbProduct;
UsbManufacturerString = remoteUsbManufacturer;
UsbProductString = remoteUsbProductString;
UsbSerialString = remoteUsbSerial;
}
}
#endregion USB #endregion USB

View File

@@ -625,7 +625,82 @@ namespace DiscImageChef.Devices.Remote
public bool GetUsbData(out byte[] descriptors, out ushort idVendor, out ushort idProduct, public bool GetUsbData(out byte[] descriptors, out ushort idVendor, out ushort idProduct,
out string manufacturer, out string product, out string serial) out string manufacturer, out string product, out string serial)
{ {
throw new NotImplementedException("Getting USB data not yet implemented..."); descriptors = null;
idVendor = 0;
idProduct = 0;
manufacturer = null;
product = null;
serial = null;
var cmdPkt = new DicPacketCmdGetSdhciRegisters
{
hdr = new DicPacketHeader
{
id = Consts.PacketId,
len = (uint) Marshal.SizeOf<DicPacketCmdGetUsbData>(),
version = Consts.PacketVersion,
packetType = DicPacketType.CommandGetUsbData
}
};
var buf = Marshal.StructureToByteArrayLittleEndian(cmdPkt);
var len = _socket.Send(buf, SocketFlags.None);
if (len != buf.Length)
{
DicConsole.ErrorWriteLine("Could not write to the network...");
return false;
}
var hdrBuf = new byte[Marshal.SizeOf<DicPacketHeader>()];
len = _socket.Receive(hdrBuf, hdrBuf.Length, SocketFlags.Peek);
if (len < hdrBuf.Length)
{
DicConsole.ErrorWriteLine("Could not read from the network...");
return false;
}
var hdr = Marshal.ByteArrayToStructureLittleEndian<DicPacketHeader>(hdrBuf);
if (hdr.id != Consts.PacketId)
{
DicConsole.ErrorWriteLine("Received data is not a DIC Remote Packet...");
return false;
}
if (hdr.packetType != DicPacketType.ResponseGetUsbData)
{
DicConsole.ErrorWriteLine("Expected USB Data Response Packet, got packet type {0}...",
hdr.packetType);
return false;
}
buf = new byte[hdr.len];
len = _socket.Receive(buf, buf.Length, SocketFlags.None);
if (len < buf.Length)
{
DicConsole.ErrorWriteLine("Could not read from the network...");
return false;
}
var res = Marshal.ByteArrayToStructureLittleEndian<DicPacketResGetUsbData>(buf);
if (!res.isUsb)
return false;
descriptors = new byte[res.descLen];
Array.Copy(res.descriptors, 0, descriptors, 0, res.descLen);
idVendor = res.idVendor;
idProduct = res.idProduct;
manufacturer = res.manufacturer;
product = res.product;
serial = res.serial;
return true;
} }
public bool GetFirewireData(out uint idVendor, out uint idProduct, public bool GetFirewireData(out uint idVendor, out uint idProduct,