mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Send device open command packet.
This commit is contained in:
@@ -76,9 +76,11 @@ namespace DiscImageChef.Devices
|
|||||||
|
|
||||||
remote = new Remote.Remote(host);
|
remote = new Remote.Remote(host);
|
||||||
|
|
||||||
throw new NotImplementedException("Remote devices not yet implemented...");
|
Error = remote.Open(devicePath, out var errno);
|
||||||
|
LastError = errno;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
switch (PlatformId)
|
switch (PlatformId)
|
||||||
{
|
{
|
||||||
case PlatformID.Win32NT:
|
case PlatformID.Win32NT:
|
||||||
@@ -146,6 +148,7 @@ namespace DiscImageChef.Devices
|
|||||||
}
|
}
|
||||||
default: throw new InvalidOperationException($"Platform {PlatformId} not yet supported.");
|
default: throw new InvalidOperationException($"Platform {PlatformId} not yet supported.");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (Error) throw new SystemException($"Error {LastError} opening device.");
|
if (Error) throw new SystemException($"Error {LastError} opening device.");
|
||||||
|
|
||||||
|
|||||||
@@ -8,4 +8,14 @@ namespace DiscImageChef.Devices.Remote
|
|||||||
ResponseListDevices = 3,
|
ResponseListDevices = 3,
|
||||||
CommandOpen = 4
|
CommandOpen = 4
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum DicNopReason : byte
|
||||||
|
{
|
||||||
|
OutOfOrder = 0,
|
||||||
|
NotImplemented = 1,
|
||||||
|
NotRecognized = 2,
|
||||||
|
ErrorListDevices = 3,
|
||||||
|
OpenOk = 4,
|
||||||
|
OpenError = 5
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -245,5 +245,85 @@ namespace DiscImageChef.Devices.Remote
|
|||||||
|
|
||||||
return devices.ToArray();
|
return devices.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool Open(string devicePath, out int LastError)
|
||||||
|
{
|
||||||
|
LastError = 0;
|
||||||
|
|
||||||
|
var cmdPkt = new DicPacketCommandOpenDevice
|
||||||
|
{
|
||||||
|
hdr = new DicPacketHeader
|
||||||
|
{
|
||||||
|
id = Consts.PacketId,
|
||||||
|
len = (uint) Marshal.SizeOf<DicPacketCommandOpenDevice>(),
|
||||||
|
version = Consts.PacketVersion,
|
||||||
|
packetType = DicPacketType.CommandOpen
|
||||||
|
},
|
||||||
|
device_path = devicePath
|
||||||
|
};
|
||||||
|
|
||||||
|
var buf = Marshal.StructureToByteArrayLittleEndian(cmdPkt);
|
||||||
|
|
||||||
|
var len = _socket.Send(buf, SocketFlags.None);
|
||||||
|
|
||||||
|
if (len != buf.Length)
|
||||||
|
{
|
||||||
|
DicConsole.ErrorWriteLine("Could not write to the network...");
|
||||||
|
LastError = -1;
|
||||||
|
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...");
|
||||||
|
LastError = -1;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var hdr = Marshal.ByteArrayToStructureLittleEndian<DicPacketHeader>(hdrBuf);
|
||||||
|
|
||||||
|
if (hdr.id != Consts.PacketId)
|
||||||
|
{
|
||||||
|
DicConsole.ErrorWriteLine("Received data is not a DIC Remote Packet...");
|
||||||
|
LastError = -1;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hdr.packetType != DicPacketType.Nop)
|
||||||
|
{
|
||||||
|
DicConsole.ErrorWriteLine("Expected List Devices Response Packet, got packet type {0}...",
|
||||||
|
hdr.packetType);
|
||||||
|
LastError = -1;
|
||||||
|
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...");
|
||||||
|
LastError = -1;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var nop = Marshal.ByteArrayToStructureLittleEndian<DicPacketNop>(buf);
|
||||||
|
|
||||||
|
switch (nop.reasonCode)
|
||||||
|
{
|
||||||
|
case DicNopReason.OpenOk:
|
||||||
|
return true;
|
||||||
|
case DicNopReason.NotImplemented:
|
||||||
|
throw new NotImplementedException($"{nop.reason}");
|
||||||
|
}
|
||||||
|
|
||||||
|
DicConsole.ErrorWriteLine($"{nop.reason}");
|
||||||
|
LastError = nop.errno;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -58,7 +58,7 @@ namespace DiscImageChef.Devices.Remote
|
|||||||
public struct DicPacketNop
|
public struct DicPacketNop
|
||||||
{
|
{
|
||||||
public DicPacketHeader hdr;
|
public DicPacketHeader hdr;
|
||||||
public byte reasonCode;
|
public DicNopReason reasonCode;
|
||||||
|
|
||||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
|
||||||
public readonly byte[] spare;
|
public readonly byte[] spare;
|
||||||
|
|||||||
Reference in New Issue
Block a user