/// <summary> /// This method reads the ATIP information from a CD media /// </summary> /// <returns></returns> public CommandStatus ReadAtip(out AtipInfo info) { ushort len; info = null; if (m_logger != null) { string args = "info"; m_logger.LogMessage(new UserMessage(UserMessage.Category.Debug, 8, "Bwg.Scsi.Device.ReadAtip(" + args + ")")); } using (Command cmd = new Command(ScsiCommandCode.ReadTocPmaAtip, 10, 32, Command.CmdDirection.In, 5 * 60)) { cmd.SetCDB8(2, 4); cmd.SetCDB16(7, 32); CommandStatus st = SendCommand(cmd); if (st != CommandStatus.Success) return st; len = cmd.GetBuffer16(0); len += 2; } if (len <= 4) return CommandStatus.Success; using (Command cmd = new Command(ScsiCommandCode.ReadTocPmaAtip, 10, len, Command.CmdDirection.In, 5 * 60)) { cmd.SetCDB8(2, 4); cmd.SetCDB16(7, len); CommandStatus st = SendCommand(cmd); if (st != CommandStatus.Success) return st; info = new AtipInfo(cmd.GetBuffer(), len); } return CommandStatus.Success; }
/// <summary> /// This method reads the ATIP information from a CD media /// </summary> /// <returns></returns> public CommandStatus ReadPMA(out byte[] data) { ushort len; data = null; if (m_logger != null) { string args = "info"; m_logger.LogMessage(new UserMessage(UserMessage.Category.Debug, 8, "Bwg.Scsi.Device.ReadFullToc(" + args + ")")); } using (Command cmd = new Command(ScsiCommandCode.ReadTocPmaAtip, 10, 320, Command.CmdDirection.In, 5 * 60)) { cmd.SetCDB8(1, 2); cmd.SetCDB8(2, 3); cmd.SetCDB16(7, 320); CommandStatus st = SendCommand(cmd); if (st != CommandStatus.Success) return st; len = cmd.GetBuffer16(0); len += 2; if (len <= 320) { data = new byte[len]; Marshal.Copy(cmd.GetBuffer(), data, 0, len); return CommandStatus.Success; } } using (Command cmd = new Command(ScsiCommandCode.ReadTocPmaAtip, 10, len, Command.CmdDirection.In, 5 * 60)) { cmd.SetCDB8(2, 3); cmd.SetCDB16(7, len); CommandStatus st = SendCommand(cmd); if (st != CommandStatus.Success) return st; //info = new AtipInfo(cmd.GetBuffer(), len); data = new byte[len]; Marshal.Copy(cmd.GetBuffer(), data, 0, len); } return CommandStatus.Success; }
/// <summary> /// Return the data from a ReadDvdStructure request as a series of bytes. /// </summary> /// <param name="format">the format of the read dvd structure request</param> /// <param name="data">the AACS volume identifier</param> /// <returns>status of command execution</returns> private CommandStatus ReadDiskStructureReturnBytes(byte format, out byte[] data) { data = null; if (m_logger != null) { string args = "out byte[] data"; m_logger.LogMessage(new UserMessage(UserMessage.Category.Debug, 8, "Bwg.Scsi.Device.ReadDvdStructureAACSVolumeIdentifier(" + args + ")")); } ushort len = 4; using (Command cmd = new Command(ScsiCommandCode.ReadDvdStructure, 12, len, Command.CmdDirection.In, 60)) { cmd.SetCDB8(7, format); // Read manufacturing information cmd.SetCDB16(8, len); // Up to 2k of data CommandStatus st = SendCommand(cmd); if (st != CommandStatus.Success) return st; len = cmd.GetBuffer16(0); if (len == 0) { data = new byte[0]; return CommandStatus.Success; } Debug.Assert(len < 8192); } using (Command cmd = new Command(ScsiCommandCode.ReadDvdStructure, 12, len, Command.CmdDirection.In, 60)) { cmd.SetCDB8(7, format); // Read manufacturing information cmd.SetCDB16(8, len); // Up to 2k of data CommandStatus st = SendCommand(cmd); if (st != CommandStatus.Success) return st; len = cmd.GetBuffer16(0); data = new byte[len]; Marshal.Copy(cmd.GetBuffer(), data, 0, len); } return CommandStatus.Success; }
/// <summary> /// Read the table of contents from the disk /// </summary> /// <param name="track">the track or session to find the TOC for</param> /// <param name="toc">a list return value containins a list of table of content entryies</param> /// <param name="mode">time versus lba mode</param> /// <returns></returns> public CommandStatus ReadToc(byte track, bool mode, out IList<TocEntry> toc) { ushort len; toc = null; if (m_logger != null) { string args = "info"; m_logger.LogMessage(new UserMessage(UserMessage.Category.Debug, 8, "Bwg.Scsi.Device.ReadToc(" + args + ")")); } using (Command cmd = new Command(ScsiCommandCode.ReadTocPmaAtip, 10, 16, Command.CmdDirection.In, 5 * 60)) { if (mode) cmd.SetCDB8(1, 2); cmd.SetCDB8(6, track); cmd.SetCDB16(7, 16); CommandStatus st = SendCommand(cmd); if (st != CommandStatus.Success) return st; len = cmd.GetBuffer16(0); len += 2; } using (Command cmd = new Command(ScsiCommandCode.ReadTocPmaAtip, 10, len, Command.CmdDirection.In, 5 * 60)) { if (mode) cmd.SetCDB8(1, 2); cmd.SetCDB8(6, track); cmd.SetCDB16(7, len); CommandStatus st = SendCommand(cmd); if (st != CommandStatus.Success) return st; int offset = 4; toc = new List<TocEntry>(); while (offset + 8 <= len) { TocEntry entry = new TocEntry(cmd.GetBuffer(), offset, cmd.BufferSize, mode); toc.Add(entry); offset += 8; } } return CommandStatus.Success; }
/// <summary> /// This method reads the PAC data for a blu-ray disk /// </summary> /// <param name="pacid">the pac id of the pac to read</param> /// <param name="pacfmt">the format of the pac to read</param> /// <param name="data">return storage for the pac data</param> /// <returns></returns> public CommandStatus ReadDiskStructurePac(uint pacid, byte pacfmt, out byte [] data) { data = null; if (m_logger != null) { string args = "out byte[] data"; m_logger.LogMessage(new UserMessage(UserMessage.Category.Debug, 8, "Bwg.Scsi.Device.ReadDvdStructurePac(" + args + ")")); } ushort len = 4; using (Command cmd = new Command(ScsiCommandCode.ReadDvdStructure, 12, len, Command.CmdDirection.In, 60)) { cmd.SetCDB24(2, pacid); cmd.SetCDB8(6, pacfmt); cmd.SetCDB8(7, 0x30); // Read PAC data cmd.SetCDB16(8, len); CommandStatus st = SendCommand(cmd); if (st != CommandStatus.Success) return st; len = (ushort)(cmd.GetBuffer16(0) + 2); if (len == 2) { data = new byte[0]; return CommandStatus.Success; } Debug.Assert(len < 8192); } using (Command cmd = new Command(ScsiCommandCode.ReadDvdStructure, 12, len, Command.CmdDirection.In, 60)) { cmd.SetCDB24(2, pacid); cmd.SetCDB8(6, pacfmt); cmd.SetCDB8(7, 0x30); // Read manufacturing information cmd.SetCDB16(8, len); // Up to 2k of data CommandStatus st = SendCommand(cmd); if (st != CommandStatus.Success) return st; len = (ushort)(cmd.GetBuffer16(0) + 2); data = new byte[len]; Marshal.Copy(cmd.GetBuffer(), data, 0, len); } return CommandStatus.Success; }
/// <summary> /// /// </summary> /// <returns></returns> public CommandStatus ReadDiskInformation(out DiskInformation result) { if (m_logger != null) { string args = "out result"; m_logger.LogMessage(new UserMessage(UserMessage.Category.Debug, 8, "Bwg.Scsi.Device.ReadDiskInformation(" + args + ")")); } ushort len = 0; result = null; using (Command cmd = new Command(ScsiCommandCode.ReadDiskInformation, 10, 34, Command.CmdDirection.In, 60)) { cmd.SetCDB16(7, 34); CommandStatus st = SendCommand(cmd); if (st != CommandStatus.Success) return st; len = cmd.GetBuffer16(0); if (len <= 34) { result = new DiskInformation(cmd.GetBuffer(), cmd.BufferSize); return CommandStatus.Success; } len += 2; } using (Command cmd = new Command(ScsiCommandCode.ReadDiskInformation, 10, len, Command.CmdDirection.In, 60)) { cmd.SetCDB16(7, len); CommandStatus st = SendCommand(cmd); if (st != CommandStatus.Success) return st; result = new DiskInformation(cmd.GetBuffer(), cmd.BufferSize); } return CommandStatus.Success; }
/// <summary> /// Read the CD text information from the leadin using the ReadTocPmaAtip command form /// </summary> /// <param name="data"></param> /// <param name="_timeout"></param> /// <returns></returns> public CommandStatus ReadCDText(out byte [] data, int _timeout) { ushort len; if (m_logger != null) { string args = "info"; m_logger.LogMessage(new UserMessage(UserMessage.Category.Debug, 8, "Bwg.Scsi.Device.ReadCDText(" + args + ")")); } data = null; using (Command cmd = new Command(ScsiCommandCode.ReadTocPmaAtip, 10, 4, Command.CmdDirection.In, _timeout)) { cmd.SetCDB8(2, 5); // CDText info in leadin cmd.SetCDB16(7, 4); CommandStatus st = SendCommand(cmd); if (st != CommandStatus.Success) return st; len = cmd.GetBuffer16(0); len += 2; if (len <= 4) { data = new byte[len]; Marshal.Copy(cmd.GetBuffer(), data, 0, len); return CommandStatus.Success; } } using (Command cmd = new Command(ScsiCommandCode.ReadTocPmaAtip, 10, len, Command.CmdDirection.In, _timeout)) { cmd.SetCDB8(2, 5); // CDText info in leadin cmd.SetCDB16(7, len); CommandStatus st = SendCommand(cmd); if (st != CommandStatus.Success) return st; data = new byte[len]; Marshal.Copy(cmd.GetBuffer(), data, 0, len); } return CommandStatus.Success; }
/// <summary> /// /// </summary> /// <param name="pc"></param> /// <param name="page"></param> /// <param name="table"></param> /// <returns></returns> public CommandStatus ModeSense(PageControl pc, byte page, out ModeTable table) { if (m_logger != null) { string args = pc.ToString() + ", " + page.ToString() + ", out result"; m_logger.LogMessage(new UserMessage(UserMessage.Category.Debug, 8, "Bwg.Scsi.Device.ModeSense(" + args + ")")); } ushort len = 0; table = null; byte b = 0; b |= (byte)((byte)(pc) << 7); b |= (byte)(page & 0x3f); using (Command cmd = new Command(ScsiCommandCode.ModeSense, 10, 8, Command.CmdDirection.In, 60 * 5)) { cmd.SetCDB8(1, 8); // Disable block descriptors cmd.SetCDB8(2, b); cmd.SetCDB16(7, 8); CommandStatus st = SendCommand(cmd); if (st != CommandStatus.Success) return st; len = cmd.GetBuffer16(0); len += 2; } using (Command cmd = new Command(ScsiCommandCode.ModeSense, 10, len, Command.CmdDirection.In, 60 * 5)) { cmd.SetCDB8(1, 8); // Disable block descriptors cmd.SetCDB8(2, b); cmd.SetCDB16(7, len); CommandStatus st = SendCommand(cmd); if (st != CommandStatus.Success) return st; table = new ModeTable(cmd.GetBuffer(), cmd.BufferSize); } return CommandStatus.Success; }
/// <summary> /// /// </summary> /// <param name="polled"></param> /// <param name="request"></param> /// <param name="result"></param> /// <returns></returns> public CommandStatus GetEventStatusNotification(bool polled, NotificationClass request, out EventStatusNotification result) { if (m_logger != null) { string args = polled.ToString() + ", " + request.ToString() + ", out result"; m_logger.LogMessage(new UserMessage(UserMessage.Category.Debug, 8, "Bwg.Scsi.Device.GetEventStatusNotification(" + args + ")")); } ushort len = 0; result = null; using (Command cmd = new Command(ScsiCommandCode.GetEventStatusNotification, 10, 4, Command.CmdDirection.In, 10)) { if (polled) cmd.SetCDB8(1, 1); cmd.SetCDB8(4, (byte)request); cmd.SetCDB16(7, 4); CommandStatus st = SendCommand(cmd); if (st != CommandStatus.Success) return st; byte n = cmd.GetBuffer8(2); if ((n & 0x80) != 0) { // There are no events, just capture the header result = new EventStatusNotification(cmd.GetBuffer(), cmd.BufferSize); return CommandStatus.Success; } // // There are event notifications to be grabbed, allocate space for these // len = cmd.GetBuffer16(0); len += 4; // For the length field } using (Command cmd = new Command(ScsiCommandCode.GetEventStatusNotification, 10, len, Command.CmdDirection.In, 10)) { if (polled) cmd.SetCDB8(1, 1); cmd.SetCDB8(4, (byte)request); cmd.SetCDB16(7, len); CommandStatus st = SendCommand(cmd); if (st != CommandStatus.Success) return st; result = new EventStatusNotification(cmd.GetBuffer(), cmd.BufferSize); } return CommandStatus.Success; }