SCSICommandDescriptorBlock16.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /* Copyright (C) 2012-2016 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
  2. *
  3. * You can redistribute this program and/or modify it under the terms of
  4. * the GNU Lesser Public License as published by the Free Software Foundation,
  5. * either version 3 of the License, or (at your option) any later version.
  6. */
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Text;
  10. using Utilities;
  11. namespace SCSI
  12. {
  13. /// <summary>
  14. /// 16-byte SCSI CDB
  15. /// </summary>
  16. public class SCSICommandDescriptorBlock16 : SCSICommandDescriptorBlock
  17. {
  18. public SCSICommandDescriptorBlock16(SCSIOpCodeName opCode) : base()
  19. {
  20. this.OpCode = opCode;
  21. }
  22. public SCSICommandDescriptorBlock16(byte[] buffer, int offset) : base()
  23. {
  24. OpCode = (SCSIOpCodeName)buffer[offset + 0];
  25. MiscellaneousCDBInformationHeader = (byte)((buffer[offset + 1] & 0xE0) >> 5);
  26. ServiceAction = (ServiceAction)((buffer[offset + 1] & 0x1F));
  27. LogicalBlockAddress = BigEndianConverter.ToUInt32(buffer, offset + 2);
  28. AdditionalCDBdata = BigEndianConverter.ToUInt32(buffer, offset + 6);
  29. TransferLength = BigEndianConverter.ToUInt32(buffer, offset + 10);
  30. MiscellaneousCDBinformation = buffer[offset + 14];
  31. Control = buffer[offset + 15];
  32. }
  33. public override byte[] GetBytes()
  34. {
  35. byte[] buffer = new byte[16];
  36. buffer[0] = (byte)OpCode;
  37. buffer[1] |= (byte)(MiscellaneousCDBInformationHeader << 5);
  38. buffer[1] |= (byte)((byte)ServiceAction & 0x1F);
  39. BigEndianWriter.WriteUInt32(buffer, 2, LogicalBlockAddress);
  40. BigEndianWriter.WriteUInt32(buffer, 6, AdditionalCDBdata);
  41. BigEndianWriter.WriteUInt32(buffer, 10, TransferLength);
  42. buffer[14] = MiscellaneousCDBinformation;
  43. buffer[15] = Control;
  44. return buffer;
  45. }
  46. }
  47. }