From b655b617c86512920daaa1106c18d8c8d39f07ef Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sat, 12 Oct 2019 22:34:27 +0100 Subject: [PATCH] Add packets for list devices. --- DiscImageChef.Devices/Device/List.cs | 18 +++++++++++++++--- DiscImageChef.Devices/Remote/Enums.cs | 4 +++- DiscImageChef.Devices/Remote/Structs.cs | 21 +++++++++++++++++---- 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/DiscImageChef.Devices/Device/List.cs b/DiscImageChef.Devices/Device/List.cs index 1867a5713..cc3bfaad4 100644 --- a/DiscImageChef.Devices/Device/List.cs +++ b/DiscImageChef.Devices/Device/List.cs @@ -31,29 +31,41 @@ // ****************************************************************************/ using System; +using System.Runtime.InteropServices; using DiscImageChef.CommonTypes.Interop; using PlatformID = DiscImageChef.CommonTypes.Interop.PlatformID; namespace DiscImageChef.Devices { + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)] public struct DeviceInfo { + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1024)] public string Path; + + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] public string Vendor; + + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] public string Model; + + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] public string Serial; + + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] public string Bus; - public bool Supported; + + [MarshalAs(UnmanagedType.U1)] public bool Supported; } public partial class Device { public static DeviceInfo[] ListDevices() { - switch(DetectOS.GetRealPlatformID()) + switch (DetectOS.GetRealPlatformID()) { case PlatformID.Win32NT: return Windows.ListDevices.GetList(); - case PlatformID.Linux: return Linux.ListDevices.GetList(); + case PlatformID.Linux: return Linux.ListDevices.GetList(); case PlatformID.FreeBSD: return FreeBSD.ListDevices.GetList(); default: throw new InvalidOperationException($"Platform {DetectOS.GetRealPlatformID()} not yet supported."); diff --git a/DiscImageChef.Devices/Remote/Enums.cs b/DiscImageChef.Devices/Remote/Enums.cs index a28662450..4423e6884 100644 --- a/DiscImageChef.Devices/Remote/Enums.cs +++ b/DiscImageChef.Devices/Remote/Enums.cs @@ -2,6 +2,8 @@ namespace DiscImageChef.Devices.Remote { public enum DicPacketType : byte { - Hello = 1 + Hello = 1, + CommandListDevices = 2, + ResponseListDevices = 3 } } \ No newline at end of file diff --git a/DiscImageChef.Devices/Remote/Structs.cs b/DiscImageChef.Devices/Remote/Structs.cs index 33c09458a..4a5fcccb7 100644 --- a/DiscImageChef.Devices/Remote/Structs.cs +++ b/DiscImageChef.Devices/Remote/Structs.cs @@ -2,7 +2,7 @@ using System.Runtime.InteropServices; namespace DiscImageChef.Devices.Remote { - [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)] public struct DicPacketHeader { public ulong id; @@ -12,10 +12,10 @@ namespace DiscImageChef.Devices.Remote public DicPacketType packetType; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)] - public byte[] spare; + public readonly byte[] spare; } - [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)] public struct DicPacketHello { public DicPacketHeader hdr; @@ -29,7 +29,7 @@ namespace DiscImageChef.Devices.Remote public byte maxProtocol; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)] - public byte[] spare; + public readonly byte[] spare; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] public string sysname; @@ -40,4 +40,17 @@ namespace DiscImageChef.Devices.Remote [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] public string machine; } + + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)] + public struct DicPacketCommandListDevices + { + public DicPacketHeader hdr; + } + + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)] + public struct DicPacketResponseListDevices + { + public readonly DicPacketHeader hdr; + public readonly ushort devices; + } } \ No newline at end of file