mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Get USB Data remote packet.
This commit is contained in:
@@ -451,106 +451,125 @@ namespace DiscImageChef.Devices
|
|||||||
|
|
||||||
#region USB
|
#region USB
|
||||||
|
|
||||||
switch (PlatformId)
|
if (remote is null)
|
||||||
{
|
{
|
||||||
case PlatformID.Linux:
|
switch (PlatformId)
|
||||||
if (devicePath.StartsWith("/dev/sd", StringComparison.Ordinal) ||
|
{
|
||||||
devicePath.StartsWith("/dev/sr", StringComparison.Ordinal) ||
|
case PlatformID.Linux:
|
||||||
devicePath.StartsWith("/dev/st", StringComparison.Ordinal))
|
if (devicePath.StartsWith("/dev/sd", StringComparison.Ordinal) ||
|
||||||
{
|
devicePath.StartsWith("/dev/sr", StringComparison.Ordinal) ||
|
||||||
var devPath = devicePath.Substring(5);
|
devicePath.StartsWith("/dev/st", StringComparison.Ordinal))
|
||||||
if (Directory.Exists("/sys/block/" + devPath))
|
|
||||||
{
|
{
|
||||||
var resolvedLink = Linux.Command.ReadLink("/sys/block/" + devPath);
|
var devPath = devicePath.Substring(5);
|
||||||
if (!string.IsNullOrEmpty(resolvedLink))
|
if (Directory.Exists("/sys/block/" + devPath))
|
||||||
{
|
{
|
||||||
resolvedLink = "/sys" + resolvedLink.Substring(2);
|
var resolvedLink = Linux.Command.ReadLink("/sys/block/" + devPath);
|
||||||
|
if (!string.IsNullOrEmpty(resolvedLink))
|
||||||
while (resolvedLink.Contains("usb"))
|
|
||||||
{
|
{
|
||||||
resolvedLink = Path.GetDirectoryName(resolvedLink);
|
resolvedLink = "/sys" + resolvedLink.Substring(2);
|
||||||
if (!File.Exists(resolvedLink + "/descriptors") ||
|
|
||||||
!File.Exists(resolvedLink + "/idProduct") ||
|
|
||||||
!File.Exists(resolvedLink + "/idVendor")) continue;
|
|
||||||
|
|
||||||
var usbFs = new FileStream(resolvedLink + "/descriptors",
|
while (resolvedLink.Contains("usb"))
|
||||||
System.IO.FileMode.Open,
|
|
||||||
System.IO.FileAccess.Read);
|
|
||||||
var usbBuf = new byte[65536];
|
|
||||||
var usbCount = usbFs.Read(usbBuf, 0, 65536);
|
|
||||||
UsbDescriptors = new byte[usbCount];
|
|
||||||
Array.Copy(usbBuf, 0, UsbDescriptors, 0, usbCount);
|
|
||||||
usbFs.Close();
|
|
||||||
|
|
||||||
var usbSr = new StreamReader(resolvedLink + "/idProduct");
|
|
||||||
var usbTemp = usbSr.ReadToEnd();
|
|
||||||
ushort.TryParse(usbTemp, NumberStyles.HexNumber, CultureInfo.InvariantCulture,
|
|
||||||
out usbProduct);
|
|
||||||
usbSr.Close();
|
|
||||||
|
|
||||||
usbSr = new StreamReader(resolvedLink + "/idVendor");
|
|
||||||
usbTemp = usbSr.ReadToEnd();
|
|
||||||
ushort.TryParse(usbTemp, NumberStyles.HexNumber, CultureInfo.InvariantCulture,
|
|
||||||
out usbVendor);
|
|
||||||
usbSr.Close();
|
|
||||||
|
|
||||||
if (File.Exists(resolvedLink + "/manufacturer"))
|
|
||||||
{
|
{
|
||||||
usbSr = new StreamReader(resolvedLink + "/manufacturer");
|
resolvedLink = Path.GetDirectoryName(resolvedLink);
|
||||||
UsbManufacturerString = usbSr.ReadToEnd().Trim();
|
if (!File.Exists(resolvedLink + "/descriptors") ||
|
||||||
usbSr.Close();
|
!File.Exists(resolvedLink + "/idProduct") ||
|
||||||
}
|
!File.Exists(resolvedLink + "/idVendor")) continue;
|
||||||
|
|
||||||
if (File.Exists(resolvedLink + "/product"))
|
var usbFs = new FileStream(resolvedLink + "/descriptors",
|
||||||
{
|
System.IO.FileMode.Open,
|
||||||
usbSr = new StreamReader(resolvedLink + "/product");
|
System.IO.FileAccess.Read);
|
||||||
UsbProductString = usbSr.ReadToEnd().Trim();
|
var usbBuf = new byte[65536];
|
||||||
usbSr.Close();
|
var usbCount = usbFs.Read(usbBuf, 0, 65536);
|
||||||
}
|
UsbDescriptors = new byte[usbCount];
|
||||||
|
Array.Copy(usbBuf, 0, UsbDescriptors, 0, usbCount);
|
||||||
|
usbFs.Close();
|
||||||
|
|
||||||
if (File.Exists(resolvedLink + "/serial"))
|
var usbSr = new StreamReader(resolvedLink + "/idProduct");
|
||||||
{
|
var usbTemp = usbSr.ReadToEnd();
|
||||||
usbSr = new StreamReader(resolvedLink + "/serial");
|
ushort.TryParse(usbTemp, NumberStyles.HexNumber, CultureInfo.InvariantCulture,
|
||||||
UsbSerialString = usbSr.ReadToEnd().Trim();
|
out usbProduct);
|
||||||
usbSr.Close();
|
usbSr.Close();
|
||||||
}
|
|
||||||
|
|
||||||
IsUsb = true;
|
usbSr = new StreamReader(resolvedLink + "/idVendor");
|
||||||
break;
|
usbTemp = usbSr.ReadToEnd();
|
||||||
|
ushort.TryParse(usbTemp, NumberStyles.HexNumber, CultureInfo.InvariantCulture,
|
||||||
|
out usbVendor);
|
||||||
|
usbSr.Close();
|
||||||
|
|
||||||
|
if (File.Exists(resolvedLink + "/manufacturer"))
|
||||||
|
{
|
||||||
|
usbSr = new StreamReader(resolvedLink + "/manufacturer");
|
||||||
|
UsbManufacturerString = usbSr.ReadToEnd().Trim();
|
||||||
|
usbSr.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (File.Exists(resolvedLink + "/product"))
|
||||||
|
{
|
||||||
|
usbSr = new StreamReader(resolvedLink + "/product");
|
||||||
|
UsbProductString = usbSr.ReadToEnd().Trim();
|
||||||
|
usbSr.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (File.Exists(resolvedLink + "/serial"))
|
||||||
|
{
|
||||||
|
usbSr = new StreamReader(resolvedLink + "/serial");
|
||||||
|
UsbSerialString = usbSr.ReadToEnd().Trim();
|
||||||
|
usbSr.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
IsUsb = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case PlatformID.Win32NT:
|
case PlatformID.Win32NT:
|
||||||
Usb.UsbDevice usbDevice = null;
|
Usb.UsbDevice usbDevice = null;
|
||||||
|
|
||||||
// I have to search for USB disks, floppies and CD-ROMs as separate device types
|
// I have to search for USB disks, floppies and CD-ROMs as separate device types
|
||||||
foreach (var devGuid in new[]
|
foreach (var devGuid in new[]
|
||||||
{
|
{
|
||||||
Usb.GuidDevinterfaceFloppy, Usb.GuidDevinterfaceCdrom, Usb.GuidDevinterfaceDisk
|
Usb.GuidDevinterfaceFloppy, Usb.GuidDevinterfaceCdrom, Usb.GuidDevinterfaceDisk
|
||||||
})
|
})
|
||||||
{
|
{
|
||||||
usbDevice = Usb.FindDrivePath(devicePath, devGuid);
|
usbDevice = Usb.FindDrivePath(devicePath, devGuid);
|
||||||
if (usbDevice != null) break;
|
if (usbDevice != null) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (usbDevice != null)
|
if (usbDevice != null)
|
||||||
{
|
{
|
||||||
UsbDescriptors = usbDevice.BinaryDescriptors;
|
UsbDescriptors = usbDevice.BinaryDescriptors;
|
||||||
usbVendor = (ushort) usbDevice.DeviceDescriptor.idVendor;
|
usbVendor = (ushort) usbDevice.DeviceDescriptor.idVendor;
|
||||||
usbProduct = (ushort) usbDevice.DeviceDescriptor.idProduct;
|
usbProduct = (ushort) usbDevice.DeviceDescriptor.idProduct;
|
||||||
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;
|
||||||
default:
|
default:
|
||||||
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
|
||||||
|
|||||||
@@ -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,
|
||||||
|
|||||||
Reference in New Issue
Block a user