mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Add NOP packet.
This commit is contained in:
@@ -1,7 +1,8 @@
|
|||||||
namespace DiscImageChef.Devices.Remote
|
namespace DiscImageChef.Devices.Remote
|
||||||
{
|
{
|
||||||
public enum DicPacketType : byte
|
public enum DicPacketType : sbyte
|
||||||
{
|
{
|
||||||
|
Nop = -1,
|
||||||
Hello = 1,
|
Hello = 1,
|
||||||
CommandListDevices = 2,
|
CommandListDevices = 2,
|
||||||
ResponseListDevices = 3
|
ResponseListDevices = 3
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ namespace DiscImageChef.Devices.Remote
|
|||||||
{
|
{
|
||||||
public class Remote : IDisposable
|
public class Remote : IDisposable
|
||||||
{
|
{
|
||||||
private readonly Socket _socket;
|
|
||||||
private readonly string _host;
|
private readonly string _host;
|
||||||
|
private readonly Socket _socket;
|
||||||
|
|
||||||
public Remote(string host)
|
public Remote(string host)
|
||||||
{
|
{
|
||||||
@@ -54,9 +54,28 @@ namespace DiscImageChef.Devices.Remote
|
|||||||
throw new ArgumentException();
|
throw new ArgumentException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
byte[] buf;
|
||||||
|
|
||||||
if (hdr.packetType != DicPacketType.Hello)
|
if (hdr.packetType != DicPacketType.Hello)
|
||||||
{
|
{
|
||||||
DicConsole.ErrorWriteLine("Expected Hello Packet, got packet type {0}...", hdr.packetType);
|
if (hdr.packetType != DicPacketType.Nop)
|
||||||
|
{
|
||||||
|
DicConsole.ErrorWriteLine("Expected Hello Packet, got packet type {0}...", hdr.packetType);
|
||||||
|
throw new ArgumentException();
|
||||||
|
}
|
||||||
|
|
||||||
|
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...");
|
||||||
|
throw new IOException();
|
||||||
|
}
|
||||||
|
|
||||||
|
var nop = Marshal.ByteArrayToStructureLittleEndian<DicPacketNop>(buf);
|
||||||
|
|
||||||
|
DicConsole.ErrorWriteLine($"{nop.reason}");
|
||||||
throw new ArgumentException();
|
throw new ArgumentException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,7 +85,7 @@ namespace DiscImageChef.Devices.Remote
|
|||||||
throw new ArgumentException();
|
throw new ArgumentException();
|
||||||
}
|
}
|
||||||
|
|
||||||
var buf = new byte[hdr.len];
|
buf = new byte[hdr.len];
|
||||||
len = _socket.Receive(buf, buf.Length, SocketFlags.None);
|
len = _socket.Receive(buf, buf.Length, SocketFlags.None);
|
||||||
|
|
||||||
if (len < buf.Length)
|
if (len < buf.Length)
|
||||||
@@ -174,8 +193,25 @@ namespace DiscImageChef.Devices.Remote
|
|||||||
|
|
||||||
if (hdr.packetType != DicPacketType.ResponseListDevices)
|
if (hdr.packetType != DicPacketType.ResponseListDevices)
|
||||||
{
|
{
|
||||||
DicConsole.ErrorWriteLine("Expected List Devices Response Packet, got packet type {0}...",
|
if (hdr.packetType != DicPacketType.Nop)
|
||||||
hdr.packetType);
|
{
|
||||||
|
DicConsole.ErrorWriteLine("Expected List Devices Response Packet, got packet type {0}...",
|
||||||
|
hdr.packetType);
|
||||||
|
return new DeviceInfo[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
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 new DeviceInfo[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
var nop = Marshal.ByteArrayToStructureLittleEndian<DicPacketNop>(buf);
|
||||||
|
|
||||||
|
DicConsole.ErrorWriteLine($"{nop.reason}");
|
||||||
return new DeviceInfo[0];
|
return new DeviceInfo[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,4 +53,17 @@ namespace DiscImageChef.Devices.Remote
|
|||||||
public readonly DicPacketHeader hdr;
|
public readonly DicPacketHeader hdr;
|
||||||
public readonly ushort devices;
|
public readonly ushort devices;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]
|
||||||
|
public struct DicPacketNop
|
||||||
|
{
|
||||||
|
public DicPacketHeader hdr;
|
||||||
|
public byte reasonCode;
|
||||||
|
|
||||||
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
|
||||||
|
public readonly byte[] spare;
|
||||||
|
|
||||||
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
|
||||||
|
public string reason;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user