private void VerifyMessageSyntaxSmbComNegotiateNonExtendedSecurityServerResponse(
            SmbNegotiateImplicitNtlmResponsePacket response,
            bool isAuthenticationSupported)
        {
            //
            // The following statement code will be run only when debugging.
            //
            Site.Log.Add(LogEntryKind.Debug,
                @"Verify MS-SMB_R9212");

            //
            // Verify MS-SMB requirement: MS-SMB_R9212.
            //
            // "The server MUST set the unused bits to zero in a response." will be verified in R109215 and R209215.
            // Here only verify the capabilities's byte-length.
            Site.CaptureRequirementIfAreEqual<int>(
                4,
                Marshal.SizeOf((uint)response.SmbParameters.Capabilities),
                9212,
                @"[In Non-Extended Security Response]Capabilities (4 bytes):  The server MUST set the unused bits to
                zero in a response.");

            //
            // Verify requirement MS-SMB_R109215 and MS-SMB_R209215
            //
            // The 4bytes have been verified in R9212, here only verify whether the unused bits were set to zero or not.
            string isR109215Implementated = Site.Properties.Get("SHOULDMAYR109215Implementation");

            // All the flags of Capabilities of SMB are listed in the following equation.
            Microsoft.Protocols.TestTools.StackSdk.FileAccessService.Smb.Capabilities capabilitiesAllSet
                = (Microsoft.Protocols.TestTools.StackSdk.FileAccessService.Smb.Capabilities.CAP_RAW_MODE
                | Microsoft.Protocols.TestTools.StackSdk.FileAccessService.Smb.Capabilities.CAP_MPX_MODE
                | Microsoft.Protocols.TestTools.StackSdk.FileAccessService.Smb.Capabilities.CAP_UNICODE
                | Microsoft.Protocols.TestTools.StackSdk.FileAccessService.Smb.Capabilities.CAP_LARGE_FILES
                | Microsoft.Protocols.TestTools.StackSdk.FileAccessService.Smb.Capabilities.CAP_NT_SMBS
                | Microsoft.Protocols.TestTools.StackSdk.FileAccessService.Smb.Capabilities.CAP_RPC_REMOTE_APIS
                | Microsoft.Protocols.TestTools.StackSdk.FileAccessService.Smb.Capabilities.CAP_STATUS32
                | Microsoft.Protocols.TestTools.StackSdk.FileAccessService.Smb.Capabilities.CAP_LEVEL_II_OPLOCKS
                | Microsoft.Protocols.TestTools.StackSdk.FileAccessService.Smb.Capabilities.CAP_LOCK_AND_READ
                | Microsoft.Protocols.TestTools.StackSdk.FileAccessService.Smb.Capabilities.CAP_NT_FIND
                | Microsoft.Protocols.TestTools.StackSdk.FileAccessService.Smb.Capabilities.CAP_DFS
                | Microsoft.Protocols.TestTools.StackSdk.FileAccessService.Smb.Capabilities.CAP_INFOLEVEL_PASSTHRU
                | Microsoft.Protocols.TestTools.StackSdk.FileAccessService.Smb.Capabilities.CAP_LARGE_READX
                | Microsoft.Protocols.TestTools.StackSdk.FileAccessService.Smb.Capabilities.CAP_LARGE_WRITE
                | Microsoft.Protocols.TestTools.StackSdk.FileAccessService.Smb.Capabilities.CAP_LWIO
                | Microsoft.Protocols.TestTools.StackSdk.FileAccessService.Smb.Capabilities.CAP_UNIX
                | Microsoft.Protocols.TestTools.StackSdk.FileAccessService.Smb.Capabilities.CAP_COMPRESSED_DATA
                | Microsoft.Protocols.TestTools.StackSdk.FileAccessService.Smb.Capabilities.CAP_DYNAMIC_REAUTH
                | Microsoft.Protocols.TestTools.StackSdk.FileAccessService.Smb.Capabilities.CAP_PERSISTENT_HANDLES
                | Microsoft.Protocols.TestTools.StackSdk.FileAccessService.Smb.Capabilities.CAP_EXTENDED_SECURITY);
            bool isR209215Satisfied = (0 == ((uint)~capabilitiesAllSet & (uint)response.SmbParameters.Capabilities));
            if (isWindows)
            {
                //
                // The following statement code will be run only when debugging.
                //
                Site.Log.Add(LogEntryKind.Debug,
                     @"Verify MS-SMB_R209215,Capabilities:{0}",
                     (uint)response.SmbParameters.Capabilities);

                //
                // Verify MS-SMB requirement: MS-SMB_R209215.
                //
                Site.CaptureRequirementIfIsTrue(
                    isR209215Satisfied,
                    209215,
                    @"[In Non-Extended Security Response]Capabilities (4 bytes): value not listed in the following
                    table is unused in Windows.");

                if (null == isR109215Implementated)
                {
                    Site.Properties.Add("SHOULDMAYR109215Implementation", Boolean.TrueString);
                    isR109215Implementated = Boolean.TrueString;
                }
            }

            if (null != isR109215Implementated)
            {
                bool implemented = Boolean.Parse(isR109215Implementated);
                bool isSatisfied = isR209215Satisfied;

                //
                // The following statement code will be run only when debugging.
                //
                Site.Log.Add(LogEntryKind.Debug,
                    @"Verify MS-SMB_R109215,Capabilities:{0}",
                    (uint)response.SmbParameters.Capabilities);

                //
                // Verify MS-SMB requirement: MS-SMB_R109215.
                //
                Site.CaptureRequirementIfAreEqual<Boolean>(
                    implemented,
                    isSatisfied,
                    109215,
                    String.Format("[In Non-Extended Security Response]Capabilities (4 bytes): value not listed in the " +
                    "following table SHOULD be unused. This requirement is {0}implemented", implemented ? "" : "not "));
            }

            //
            // Verify requirement MS-SMB_R105227 and MS-SMB_R205227
            //
            // Here verify R105227 and R205227 partially, only verify whether the unused bits are set to zero or not.
            string isR105227Implementated = Site.Properties.Get("SHOULDMAYR105227Implementation");
            bool isR205227Satisfied = (0 == ((uint)~capabilitiesAllSet & (uint)response.SmbParameters.Capabilities));

            if (isWindows)
            {
                //
                // The following statement code will be run only when debugging.
                //
                Site.Log.Add(LogEntryKind.Debug,
                    @"Verify MS-SMB_R205227,Capabilities:{0}",
                    (uint)response.SmbParameters.Capabilities);

                //
                // Verify MS-SMB requirement: MS-SMB_R205227.
                //
                Site.CaptureRequirementIfIsTrue(
                    isR205227Satisfied,
                    205227,
                    @"[In Message Syntax]Unless otherwise noted, unused or reserved bits in bit fields is set to zero
                    when being sent in Windows.");

                if (null == isR105227Implementated)
                {
                    Site.Properties.Add("SHOULDMAYR105227Implementation", Boolean.TrueString);
                    isR105227Implementated = Boolean.TrueString;
                }
            }

            if (null != isR105227Implementated)
            {
                bool implemented = Boolean.Parse(isR105227Implementated);
                bool isSatisfied = isR205227Satisfied;

                //
                // The following statement code will be run only when debugging.
                //
                Site.Log.Add(LogEntryKind.Debug,
                    @"Verify MS-SMB_R105227,Capabilities:{0}",
                    (uint)response.SmbParameters.Capabilities);

                //
                // Verify MS-SMB requirement: MS-SMB_R105227.
                //
                Site.CaptureRequirementIfAreEqual<Boolean>(
                    implemented,
                    isSatisfied,
                    105227,
                    String.Format("[In Message Syntax]Unless otherwise noted, unused or reserved bits in bit fields " +
                    "SHOULD be set to zero when being sent. This requirement is {0}implemented", implemented ? "" : "not "));
            }

            //
            // Verify requirement MS-SMB_R109216 and MS-SMB_R9216
            //
            // The Capabilities's byte length has been verified in R9212.
            string isR9216Implementated = Site.Properties.Get("SHOULDMAYR9216Implementation");
            bool isR109216Satisfied = (0 == ((uint)~capabilitiesAllSet & (uint)response.SmbParameters.Capabilities));
            if (isWindows)
            {
                //
                // The following statement code will be run only when debugging.
                //
                Site.Log.Add(LogEntryKind.Debug,
                    @"Verify MS-SMB_R109216,Capabilities:{0}",
                    (uint)response.SmbParameters.Capabilities);

                //
                // Verify MS-SMB requirement: MS-SMB_R109216.
                //
                Site.CaptureRequirementIfIsTrue(
                    isR109216Satisfied,
                    109216,
                    @"[In Non-Extended Security Response]Capabilities (4 bytes):  A server is set the unused bits to
                    zero in a response in Windows.");

                if (null == isR9216Implementated)
                {
                    Site.Properties.Add("SHOULDMAYR9216Implementation", Boolean.TrueString);
                    isR9216Implementated = Boolean.TrueString;
                }
            }

            if (null != isR9216Implementated)
            {
                bool implemented = Boolean.Parse(isR9216Implementated);
                bool isSatisfied = isR109216Satisfied;

                //
                // The following statement code will be run only when debugging.
                //
                Site.Log.Add(LogEntryKind.Debug,
                    @"Verify MS-SMB_R9216,Capabilities:{0}",
                    (uint)response.SmbParameters.Capabilities);

                //
                // Verify MS-SMB requirement: MS-SMB_R9216.
                //
                Site.CaptureRequirementIfAreEqual<Boolean>(
                    implemented,
                    isSatisfied,
                    9216,
                    String.Format("[In Non-Extended Security Response]Capabilities (4 bytes):  A server SHOULD set the " +
                    "unused bits to zero in a response. This requirement is {0}implemented", implemented ? "" : "not "));
            }

            //
            // The following statement code will be run only when debugging.
            //
            Site.Log.Add(LogEntryKind.Debug,
                @"Verify MS-SMB_R9219,ChallengeLength:{0}",
                response.SmbParameters.ChallengeLength);

            //
            // Verify MS-SMB requirement: MS-SMB_R9219.
            //
            // Based on the latest TD v20101101 to the fixed TDI #53077, the description for RS MS-SMB_R9219 has been changed to as below:
            // "ChallengeLength (1 byte): The value of this field MUST be 0x08 and is the length of the random challenge used in challenge/response authentication."
            // Currently only change the capture logic according to MIP's rule.
            bool isVerifyR9219 = ((1 == Marshal.SizeOf(response.SmbParameters.ChallengeLength))
                && (0x08 == response.SmbParameters.ChallengeLength));

            Site.CaptureRequirementIfIsTrue(
                isVerifyR9219,
                9219,
                @"[In Non-Extended Security Response] ChallengeLength (1 byte):  This field MUST be either 0x00 or 0x08
                and is the length of the random challenge used in challenge/response authentication.");

            //
            // The following statement code will be run only when debugging.
            //
            Site.Log.Add(LogEntryKind.Debug,
                @"Verify MS-SMB_R9222, ByteCound:{0}",
                response.SmbData.ByteCount);

            //
            // Verify MS-SMB requirement: MS-SMB_R9222.
            //
            bool isVerifyR9222 = ((2 == Marshal.SizeOf(response.SmbData.ByteCount))
                && (response.SmbData.ByteCount >= 0x0003));

            Site.CaptureRequirementIfIsTrue(
                isVerifyR9222,
                9222,
                @"[In Non-Extended Security Response] ByteCount (2 bytes):  This field MUST be greater than or equal to
                0x0003.");

            //
            // The following statement code will be run only when debugging.
            //
            Site.Log.Add(LogEntryKind.Debug,
                @"Verify MS-SMB_R9223");

            //
            // Verify MS-SMB requirement: MS-SMB_R9223.
            //
            Site.CaptureRequirementIfAreEqual<int>(
                response.SmbParameters.ChallengeLength,
                response.SmbData.Challenge.Length,
                9223,
                @"[In Non-Extended Security Response] Challenge (variable):  An array of unsigned bytes that MUST be
                the length of the number of bytes specified in the ChallengeLength field.");

            //
            // The following statement code will be run only when debugging.
            //
            Site.Log.Add(LogEntryKind.Debug,
                @"Verify MS-SMB_R9224");

            //
            // Verify MS-SMB requirement: MS-SMB_R9224.
            //
            // Whether the byte is unsigned or not is decided by the protocol SDK's decoding method.
            // The protocol SDK has ensured that they are unsigned bytes.
            Site.CaptureRequirementIfAreEqual<Type>(
                typeof(byte[]),
                response.SmbData.Challenge.GetType(),
                9224,
                @"[In Non-Extended Security Response] Challenge (variable):  An array of unsigned bytes MUST represent
                the server challenge.");

            if (isWindows &&
                ((sutOsVersion == Platform.Win2K) ||
                (sutOsVersion == Platform.Win2K3) ||
                (sutOsVersion == Platform.Win2K3R2) ||
                (sutOsVersion == Platform.Win2K8) ||
                (sutOsVersion == Platform.Win2K8R2)))
            {
                //
                // The following statement code will be run only when debugging.
                //
                Site.Log.Add(LogEntryKind.Debug,
                    @"Verify MS-SMB_R9538");

                //
                // Verify MS-SMB requirement: MS-SMB_R9538.
                //
                Site.CaptureRequirementIfAreEqual<uint>(
                    16644,
                    response.SmbParameters.MaxBufferSize,
                    9538,
                    @"<41> Section 2.2.4.5.2.2: Windows-based servers default to a MaxBufferSize value of
                    16,644 bytes.");

                //
                // The following statement code will be run only when debugging.
                //
                Site.Log.Add(LogEntryKind.Debug,
                    @"Verify MS-SMB_R9541");

                //
                // Verify MS-SMB requirement: MS-SMB_R9541.
                //
                Site.CaptureRequirementIfAreEqual<int>(
                    8,
                    response.SmbData.Challenge.Length,
                    9541,
                    @"<42> Section 2.2.4.5.2.2: Windows-based servers provide 8-bit cryptographic challenges.");
            }

            //
            // The following statement code will be run only when debugging.
            //
            Site.Log.Add(LogEntryKind.Debug,
                @"Verify MS-SMB_R9200");

            // The response's form is verified in the R9212, R9219, R9222, R9223, R9224. Here capture this requirement
            // directly.
            Site.CaptureRequirement(
                9200,
                @"[In Non-Extended Security Response]If extended security is not being used and the NT LAN Manager
                dialect has been selected, then a successful response MUST take the following form
                [SMB_Parameters
                  {
                  UCHAR  WordCount;
                  Words
                    {
                    USHORT   DialectIndex;
                    UCHAR    SecurityMode;
                    USHORT   MaxMpxCount;
                    USHORT   MaxNumberVcs;
                    ULONG    MaxBufferSize;
                    ULONG    MaxRawSize;
                    ULONG    SessionKey;
                    ULONG    Capabilities;
                    FILETIME SystemTime;
                    SHORT    ServerTimeZone;
                    UCHAR    ChallengeLength;
                    }
                  }
                SMB_Data
                  {
                  USHORT ByteCount;
                  Bytes
                    {
                    UCHAR      Challenge[];
                    SMB_STRING DomainName[];
                    SMB_STRING ServerName[];
                    }
                  }
                ].");
        }
        protected override SmbPacket CreateSmbResponsePacket(
            SmbPacket request,
            SmbHeader smbHeader,
            Channel channel)
        {
            SmbPacket smbPacket = null;

            // error packet
            SmbStatus packetStatus = (SmbStatus)smbHeader.Status;

            // error packet
            if (packetStatus != SmbStatus.STATUS_SUCCESS &&
                    packetStatus != SmbStatus.STATUS_MORE_PROCESSING_REQUIRED &&
                    packetStatus != SmbStatus.STATUS_BUFFER_OVERFLOW)
            {
                smbPacket = new SmbErrorResponsePacket();
                smbPacket.SmbHeader = smbHeader;

                return smbPacket;
            }

            // success packet
            switch (smbHeader.Command)
            {
                case SmbCommand.SMB_COM_NEGOTIATE:
                    if (smbClient.Capability.IsSupportsExtendedSecurity)
                    {
                        smbPacket = new SmbNegotiateResponsePacket();
                    }
                    else
                    {
                        smbPacket = new SmbNegotiateImplicitNtlmResponsePacket();
                    }
                    break;

                case SmbCommand.SMB_COM_SESSION_SETUP_ANDX:
                    if (smbClient.Capability.IsSupportsExtendedSecurity)
                    {
                        smbPacket = new SmbSessionSetupAndxResponsePacket();
                    }
                    else
                    {
                        smbPacket = new SmbSessionSetupImplicitNtlmAndxResponsePacket();
                    }
                    break;

                case SmbCommand.SMB_COM_TREE_CONNECT_ANDX:
                    smbPacket = new SmbTreeConnectAndxResponsePacket();
                    break;

                case SmbCommand.SMB_COM_TREE_DISCONNECT:
                    smbPacket = new SmbTreeDisconnectResponsePacket();
                    break;

                case SmbCommand.SMB_COM_LOGOFF_ANDX:
                    smbPacket = new SmbLogoffAndxResponsePacket();
                    break;

                case SmbCommand.SMB_COM_NT_CREATE_ANDX:
                    smbPacket = new SmbNtCreateAndxResponsePacket();
                    break;

                case SmbCommand.SMB_COM_CLOSE:
                    smbPacket = new SmbCloseResponsePacket();
                    break;

                case SmbCommand.SMB_COM_OPEN_ANDX:
                    smbPacket = new SmbOpenAndxResponsePacket();
                    break;

                case SmbCommand.SMB_COM_WRITE_ANDX:
                    smbPacket = new SmbWriteAndxResponsePacket();
                    break;

                case SmbCommand.SMB_COM_READ_ANDX:
                    smbPacket = new SmbReadAndxResponsePacket();
                    break;

                case SmbCommand.SMB_COM_TRANSACTION:
                    smbPacket = this.CreateTransactionResponsePacket(request, smbHeader, channel);

                    break;

                case SmbCommand.SMB_COM_TRANSACTION2:
                    smbPacket = this.CreateTransaction2ResponsePacket(request, smbHeader, channel);

                    break;

                case SmbCommand.SMB_COM_NT_TRANSACT:
                    smbPacket = this.CreateNtTransactionResponsePacket(request, smbHeader, channel);

                    break;

                default:
                    break;

            }
            if (smbPacket != null)
            {
                smbPacket.SmbHeader = smbHeader;
                return smbPacket;
            }

            return base.CreateSmbResponsePacket(request, smbHeader, channel);
        }
 /// <summary>
 /// Deep copy constructor. 
 /// </summary>
 public SmbNegotiateImplicitNtlmResponsePacket(SmbNegotiateImplicitNtlmResponsePacket packet)
     : base(packet)
 {
 }
        protected override SmbPacket CreateSmbResponsePacket(
            SmbPacket request,
            SmbHeader smbHeader,
            Channel channel)
        {
            SmbPacket smbPacket = null;

            // error packet
            SmbStatus packetStatus = (SmbStatus)smbHeader.Status;

            // error packet
            if (packetStatus != SmbStatus.STATUS_SUCCESS &&
                packetStatus != SmbStatus.STATUS_MORE_PROCESSING_REQUIRED &&
                packetStatus != SmbStatus.STATUS_BUFFER_OVERFLOW)
            {
                smbPacket           = new SmbErrorResponsePacket();
                smbPacket.SmbHeader = smbHeader;

                return(smbPacket);
            }

            // success packet
            switch (smbHeader.Command)
            {
            case SmbCommand.SMB_COM_NEGOTIATE:
                if (smbClient.Capability.IsSupportsExtendedSecurity)
                {
                    smbPacket = new SmbNegotiateResponsePacket();
                }
                else
                {
                    smbPacket = new SmbNegotiateImplicitNtlmResponsePacket();
                }
                break;

            case SmbCommand.SMB_COM_SESSION_SETUP_ANDX:
                if (smbClient.Capability.IsSupportsExtendedSecurity)
                {
                    smbPacket = new SmbSessionSetupAndxResponsePacket();
                }
                else
                {
                    smbPacket = new SmbSessionSetupImplicitNtlmAndxResponsePacket();
                }
                break;

            case SmbCommand.SMB_COM_TREE_CONNECT_ANDX:
                smbPacket = new SmbTreeConnectAndxResponsePacket();
                break;

            case SmbCommand.SMB_COM_TREE_DISCONNECT:
                smbPacket = new SmbTreeDisconnectResponsePacket();
                break;

            case SmbCommand.SMB_COM_LOGOFF_ANDX:
                smbPacket = new SmbLogoffAndxResponsePacket();
                break;

            case SmbCommand.SMB_COM_NT_CREATE_ANDX:
                smbPacket = new SmbNtCreateAndxResponsePacket();
                break;

            case SmbCommand.SMB_COM_CLOSE:
                smbPacket = new SmbCloseResponsePacket();
                break;

            case SmbCommand.SMB_COM_OPEN_ANDX:
                smbPacket = new SmbOpenAndxResponsePacket();
                break;

            case SmbCommand.SMB_COM_WRITE_ANDX:
                smbPacket = new SmbWriteAndxResponsePacket();
                break;

            case SmbCommand.SMB_COM_READ_ANDX:
                smbPacket = new SmbReadAndxResponsePacket();
                break;

            case SmbCommand.SMB_COM_TRANSACTION:
                smbPacket = this.CreateTransactionResponsePacket(request, smbHeader, channel);

                break;

            case SmbCommand.SMB_COM_TRANSACTION2:
                smbPacket = this.CreateTransaction2ResponsePacket(request, smbHeader, channel);

                break;

            case SmbCommand.SMB_COM_NT_TRANSACT:
                smbPacket = this.CreateNtTransactionResponsePacket(request, smbHeader, channel);

                break;

            default:
                break;
            }
            if (smbPacket != null)
            {
                smbPacket.SmbHeader = smbHeader;
                return(smbPacket);
            }

            return(base.CreateSmbResponsePacket(request, smbHeader, channel));
        }
 /// <summary>
 /// Deep copy constructor.
 /// </summary>
 public SmbNegotiateImplicitNtlmResponsePacket(SmbNegotiateImplicitNtlmResponsePacket packet)
     : base(packet)
 {
 }