/// <summary>
        /// Create TRANS2_QUERY_FS_INFORMATION Response 
        /// </summary>
        /// <param name="connection">the connection identified the client</param>
        /// <param name = "data">data specified by [CIFS] </param>
        /// <returns>The SmbTrans2QueryFileInformationResponsePacket </returns>
        /// <exception cref="ArgumentNullException">connection must not be null</exception>
        public virtual SmbTrans2QueryFsInformationResponsePacket CreateTrans2QueryFsInformationResponse(
            SmbServerConnection connection,
            object data)
        {
            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }

            SmbTrans2QueryFsInformationResponsePacket packet = new SmbTrans2QueryFsInformationResponsePacket();

            // get the request packet
            SmbPacket request = connection.GetRequestPacket(connection.MessageId);

            // create smb packet header
            packet.SmbHeader = CifsMessageUtils.CreateSmbHeader(
                SmbCommand.SMB_COM_TRANSACTION2,
                connection.ProcessId, connection.MessageId, request.SmbHeader.Uid, request.SmbHeader.Tid,
                (SmbFlags)connection.Capability.Flag, (SmbFlags2)connection.Capability.Flags2);

            // update smb parameters
            SMB_COM_TRANSACTION2_FinalResponse_SMB_Parameters smbParameters = packet.SmbParameters;

            smbParameters.Setup = new ushort[0];

            smbParameters.WordCount = (byte)(CifsMessageUtils.GetSize<SMB_COM_TRANSACTION2_FinalResponse_SMB_Parameters>(
                smbParameters) / SmbCapability.NUM_BYTES_OF_WORD);

            // update smb data
            SMB_COM_TRANSACTION2_FinalResponse_SMB_Data smbData = packet.SmbData;

            // update trans2 data
            TRANS2_QUERY_FS_INFORMATION_Response_Trans2_Data trans2Data = packet.Trans2Data;

            trans2Data.Data = data;

            // store the parameters and data to packet.
            packet.Trans2Data = trans2Data;
            packet.SmbParameters = smbParameters;
            packet.SmbData = smbData;

            packet.UpdateCountAndOffset();

            return packet;
        }
        private SmbPacket CreateTransaction2ResponsePacket(SmbPacket request, SmbHeader smbHeader, Channel channel)
        {
            SmbPacket smbPacket = null;

            if (smbHeader.Status == 0 && channel.Peek<byte>(0) == 0 && channel.Peek<ushort>(1) == 0)
            {
                return smbPacket;
            }

            SmbTransaction2RequestPacket transaction2Request = request as SmbTransaction2RequestPacket;
            if (transaction2Request == null)
            {
                return smbPacket;
            }

            // if no setup command. break
            if (transaction2Request.SmbParameters.SetupCount == 0)
            {
                return smbPacket;
            }

            // decode packet using the setup command
            switch ((Trans2SubCommand)transaction2Request.SmbParameters.Setup[0])
            {
                case Trans2SubCommand.TRANS2_QUERY_FILE_INFORMATION:
                    SmbTrans2QueryFileInformationRequestPacket queryFileRequest =
                        transaction2Request as SmbTrans2QueryFileInformationRequestPacket;
                    if (queryFileRequest != null)
                    {
                        smbPacket = new SmbTrans2QueryFileInformationResponsePacket(
                            queryFileRequest.Trans2Parameters.InformationLevel);
                    }
                    break;

                case Trans2SubCommand.TRANS2_QUERY_PATH_INFORMATION:
                    SmbTrans2QueryPathInformationRequestPacket queryPathRequest =
                       transaction2Request as SmbTrans2QueryPathInformationRequestPacket;
                    if (queryPathRequest != null)
                    {
                        smbPacket = new SmbTrans2QueryPathInformationResponsePacket(
                            queryPathRequest.Trans2Parameters.InformationLevel);
                    }
                    break;

                case Trans2SubCommand.TRANS2_SET_FILE_INFORMATION:
                    smbPacket = new SmbTrans2SetFileInformationResponsePacket();
                    break;

                case Trans2SubCommand.TRANS2_SET_PATH_INFORMATION:
                    smbPacket = new SmbTrans2SetPathInformationResponsePacket();
                    break;

                case Trans2SubCommand.TRANS2_QUERY_FS_INFORMATION:
                    SmbTrans2QueryFsInformationRequestPacket queryFsRequest =
                        transaction2Request as SmbTrans2QueryFsInformationRequestPacket;
                    if (queryFsRequest != null)
                    {
                        smbPacket = new SmbTrans2QueryFsInformationResponsePacket(
                            queryFsRequest.Trans2Parameters.InformationLevel);
                    }
                    break;

                case Trans2SubCommand.TRANS2_SET_FS_INFORMATION:
                    smbPacket = new SmbTrans2SetFsInformationResponsePacket();
                    break;

                case Trans2SubCommand.TRANS2_FIND_FIRST2:
                    SmbTrans2FindFirst2RequestPacket first2Request =
                       transaction2Request as SmbTrans2FindFirst2RequestPacket;
                    if (first2Request != null)
                    {
                        smbPacket = new SmbTrans2FindFirst2ResponsePacket(first2Request.Trans2Parameters.InformationLevel,
                            (first2Request.Trans2Parameters.Flags & Trans2FindFlags.SMB_FIND_RETURN_RESUME_KEYS)
                            == Trans2FindFlags.SMB_FIND_RETURN_RESUME_KEYS);
                    }
                    break;

                case Trans2SubCommand.TRANS2_FIND_NEXT2:
                    SmbTrans2FindNext2RequestPacket next2Request =
                       transaction2Request as SmbTrans2FindNext2RequestPacket;
                    if (next2Request != null)
                    {
                        smbPacket = new SmbTrans2FindNext2ResponsePacket(next2Request.Trans2Parameters.InformationLevel,
                            (next2Request.Trans2Parameters.Flags & Trans2FindFlags.SMB_FIND_RETURN_RESUME_KEYS)
                            == Trans2FindFlags.SMB_FIND_RETURN_RESUME_KEYS);
                    }
                    break;

                case Trans2SubCommand.TRANS2_GET_DFS_REFERRAL:
                    smbPacket = new SmbTrans2GetDfsReferralResponsePacket();
                    break;

                default:
                    break;
            }

            return smbPacket;
        }
        /// <summary>
        /// get fscc query fs response, verify data
        /// </summary>
        /// <param name="qureryFsInformationFsccPacket">The trans2 query fs information response packet to be verified</param>
        private void FSCCTrans2QueryFSInformationResponse(SmbTrans2QueryFsInformationResponsePacket
            qureryFsInformationFsccPacket)
        {
            bool isPerUserQuotasUsed = Boolean.Parse(Site.Properties["IsPerUserQuotasUsedForFscc"]);
            uint expectedTotalFreeAllocationUnits = uint.Parse(Site.Properties["ExpectedTotalFreeAllocationUnitsForFscc"]);
            string typeOfFileSystem = Site.Properties["TypeOfFileSystemForFscc"];
            switch (fsccQueryFSLevel)
            {
                case 0://FileFsVolumeInformation,
                    NamespaceFscc.FsccFileFsVolumeInformationResponsePacket fileFsVolumeInformationResponse
                        = new NamespaceFscc.FsccFileFsVolumeInformationResponsePacket();
                    fileFsVolumeInformationResponse.FromBytes(qureryFsInformationFsccPacket.SmbData.Trans2_Data);
                    NamespaceFscc.FileFsVolumeInformation fileFsVolumeInformation = fileFsVolumeInformationResponse.Payload;

                    uint volumeSerialNumber = uint.Parse(Site.Properties["VolumeSerialNumberForFSCC"]);
                    bool isSupportsOOFileSysObj = Boolean.Parse(Site.Properties["IsSupportsOOFileSysObj"]);
                    VerifyDataTypeFileFsVolumeInformationForOld(
                        fileFsVolumeInformation,
                        volumeSerialNumber,
                        isSupportsOOFileSysObj);
                    VerifyDataTypeFileFsVolumeInformation(fileFsVolumeInformation, typeOfFileSystem);
                    break;

                case 1://FileFsSizeInformation,
                    NamespaceFscc.FsccFileFsSizeInformationResponsePacket fileFsSizeInformationResponse
                        = new NamespaceFscc.FsccFileFsSizeInformationResponsePacket();
                    fileFsSizeInformationResponse.FromBytes(qureryFsInformationFsccPacket.SmbData.Trans2_Data);
                    NamespaceFscc.FileFsSizeInformation fileFsSizeInformation = fileFsSizeInformationResponse.Payload;

                    uint sectorsPerAllocationUnit = uint.Parse(Site.Properties["SectorsPerAllocationUnitFprFSCC"]);
                    uint bytesPerSector = uint.Parse(Site.Properties["BytesPerSectorForFSCC"]);
                    VerifyDataTypeFileFsSizeInformation(
                        fileFsSizeInformation,
                        sectorsPerAllocationUnit,
                        bytesPerSector);

                    VerifyDataTypeFileFsSizeInformationField(
                        fileFsSizeInformation,
                        isPerUserQuotasUsed,
                        expectedTotalFreeAllocationUnits);
                    break;

                case 2://FileFsDeviceInformation,
                    NamespaceFscc.FsccFileFsDeviceInformationResponsePacket fileFsDeviceInformationResponse
                        = new NamespaceFscc.FsccFileFsDeviceInformationResponsePacket();
                    fileFsDeviceInformationResponse.FromBytes(qureryFsInformationFsccPacket.SmbData.Trans2_Data);
                    NamespaceFscc.FileFsDeviceInformation fileFsDeviceInformation = fileFsDeviceInformationResponse.Payload;

                    VerifyDataTypeFileFsDeviceInformation(fileFsDeviceInformation);
                    break;

                case 3://FileFsAttributeInformation,
                    NamespaceFscc.FsccFileFsAttributeInformationResponsePacket fileFsAttributeInformationResponse
                        = new NamespaceFscc.FsccFileFsAttributeInformationResponsePacket();
                    fileFsAttributeInformationResponse.FromBytes(qureryFsInformationFsccPacket.SmbData.Trans2_Data);
                    NamespaceFscc.FileFsAttributeInformation fileFsAttributeInformation
                        = fileFsAttributeInformationResponse.Payload;

                    int maximumFileNameComponentLength = int.Parse(Site.Properties["MaximumFileNameComponentLengthForFscc"]);
                    VerifyMessageSyntaxFileFsAttributeInformation(fileFsAttributeInformation, maximumFileNameComponentLength);

                    VerifyDataTypeFileFsAttributeInformation(fileFsAttributeInformation);

                    VerifyDataTypeFileFsAttributeInformationForOld(fileFsAttributeInformation);
                    break;

                case 4://FileFsControlInformation,
                    NamespaceFscc.FsccFileFsControlInformationResponsePacket fileFsControlInformationResponse
                        = new NamespaceFscc.FsccFileFsControlInformationResponsePacket();
                    fileFsControlInformationResponse.FromBytes(qureryFsInformationFsccPacket.SmbData.Trans2_Data);
                    NamespaceFscc.FileFsControlInformation fileFsControlInformation = fileFsControlInformationResponse.Payload;

                    long defaultQuotaLimit = long.Parse(Site.Properties["DefaultQuotaLimitForFSCC"]);

                    VerifyDataTypeFileFsControlInformationForOld(
                        fileFsControlInformation,
                        defaultQuotaLimit);

                    long deaultPerUserDiskQuotaWarningThreshold
                        = long.Parse(Site.Properties["DeaultPerUserDiskQuotaWarningThresholdForFscc"]);
                    long minAmountOfFreeDiskSpaceForStartFiltering
                        = long.Parse(Site.Properties["MinAmountOfFreeDiskSpaceForStartFilteringForFscc"]);
                    long minAmountOfFreeDiskSpaceForStopFiltering
                        = long.Parse(Site.Properties["MinAmountOfFreeDiskSpaceForStopFilteringForFscc"]);
                    long minAmountOfFreeDiskSpaceForThreshold
                        = long.Parse(Site.Properties["MinAmountOfFreeDiskSpaceForThresholdForFscc"]);

                    VerifyMessageSyntaxFileFsControlInformation(
                        fileFsControlInformation,
                        deaultPerUserDiskQuotaWarningThreshold,
                        minAmountOfFreeDiskSpaceForStartFiltering,
                        minAmountOfFreeDiskSpaceForStopFiltering,
                        minAmountOfFreeDiskSpaceForThreshold);

                    VerifyDataTypeFileFsControlInformation(fileFsControlInformation);
                    break;

                case 5: //FileFsFullSizeInformation,
                    NamespaceFscc.FsccFileFsFullSizeInformationResponsePacket fileFsFullSizeInformationResponse
                        = new NamespaceFscc.FsccFileFsFullSizeInformationResponsePacket();
                    fileFsFullSizeInformationResponse.FromBytes(qureryFsInformationFsccPacket.SmbData.Trans2_Data);
                    NamespaceFscc.FileFsFullSizeInformation fileFsFullSizeInformation
                        = fileFsFullSizeInformationResponse.Payload;

                    uint bytesPerSectorForFullSize = uint.Parse(Site.Properties["BytesPerSectorForFSCC"]);
                    VerifyDataTypeFileFsFullSizeInformation(
                        fileFsFullSizeInformation,
                        bytesPerSectorForFullSize);

                    VerifyDataTypeFileFsFullSizeInformationField(
                        fileFsFullSizeInformation,
                        isPerUserQuotasUsed,
                        expectedTotalFreeAllocationUnits);
                    break;

                case 6://FileFsObjectIdInformation
                    NamespaceFscc.FsccFileFsObjectIdInformationResponsePacket fileFsObjectIdInformationResponse
                        = new NamespaceFscc.FsccFileFsObjectIdInformationResponsePacket();
                    fileFsObjectIdInformationResponse.FromBytes(qureryFsInformationFsccPacket.SmbData.Trans2_Data);
                    NamespaceFscc.FileFsObjectIdInformation fileFsObjectIdInformation
                        = fileFsObjectIdInformationResponse.Payload;

                    uint returnedStatusCode = uint.Parse(Site.Properties["ReturnedStatusCodeForFscc"]);
                    VerifyResponseForFileFsObjectIdInformationQuery(
                        fileFsObjectIdInformation,
                        returnedStatusCode,
                        typeOfFileSystem);
                    bool isNoExInfoWritten = Boolean.Parse(Site.Properties["IsNoExInfoWrittenForFSCC"]);
                    VerifyDataTypeFileFsObjectIdInformation(
                        fileFsObjectIdInformation,
                        isNoExInfoWritten);
                    break;

                default:
                    break;
            }
        }
        private SmbPacket CreateTransaction2ResponsePacket(SmbPacket request, SmbHeader smbHeader, Channel channel)
        {
            SmbPacket smbPacket = null;

            if (smbHeader.Status == 0 && channel.Peek <byte>(0) == 0 && channel.Peek <ushort>(1) == 0)
            {
                return(smbPacket);
            }

            SmbTransaction2RequestPacket transaction2Request = request as SmbTransaction2RequestPacket;

            if (transaction2Request == null)
            {
                return(smbPacket);
            }

            // if no setup command. break
            if (transaction2Request.SmbParameters.SetupCount == 0)
            {
                return(smbPacket);
            }

            // decode packet using the setup command
            switch ((Trans2SubCommand)transaction2Request.SmbParameters.Setup[0])
            {
            case Trans2SubCommand.TRANS2_QUERY_FILE_INFORMATION:
                SmbTrans2QueryFileInformationRequestPacket queryFileRequest =
                    transaction2Request as SmbTrans2QueryFileInformationRequestPacket;
                if (queryFileRequest != null)
                {
                    smbPacket = new SmbTrans2QueryFileInformationResponsePacket(
                        queryFileRequest.Trans2Parameters.InformationLevel);
                }
                break;

            case Trans2SubCommand.TRANS2_QUERY_PATH_INFORMATION:
                SmbTrans2QueryPathInformationRequestPacket queryPathRequest =
                    transaction2Request as SmbTrans2QueryPathInformationRequestPacket;
                if (queryPathRequest != null)
                {
                    smbPacket = new SmbTrans2QueryPathInformationResponsePacket(
                        queryPathRequest.Trans2Parameters.InformationLevel);
                }
                break;

            case Trans2SubCommand.TRANS2_SET_FILE_INFORMATION:
                smbPacket = new SmbTrans2SetFileInformationResponsePacket();
                break;

            case Trans2SubCommand.TRANS2_SET_PATH_INFORMATION:
                smbPacket = new SmbTrans2SetPathInformationResponsePacket();
                break;

            case Trans2SubCommand.TRANS2_QUERY_FS_INFORMATION:
                SmbTrans2QueryFsInformationRequestPacket queryFsRequest =
                    transaction2Request as SmbTrans2QueryFsInformationRequestPacket;
                if (queryFsRequest != null)
                {
                    smbPacket = new SmbTrans2QueryFsInformationResponsePacket(
                        queryFsRequest.Trans2Parameters.InformationLevel);
                }
                break;

            case Trans2SubCommand.TRANS2_SET_FS_INFORMATION:
                smbPacket = new SmbTrans2SetFsInformationResponsePacket();
                break;

            case Trans2SubCommand.TRANS2_FIND_FIRST2:
                SmbTrans2FindFirst2RequestPacket first2Request =
                    transaction2Request as SmbTrans2FindFirst2RequestPacket;
                if (first2Request != null)
                {
                    smbPacket = new SmbTrans2FindFirst2ResponsePacket(first2Request.Trans2Parameters.InformationLevel,
                                                                      (first2Request.Trans2Parameters.Flags & Trans2FindFlags.SMB_FIND_RETURN_RESUME_KEYS)
                                                                      == Trans2FindFlags.SMB_FIND_RETURN_RESUME_KEYS);
                }
                break;

            case Trans2SubCommand.TRANS2_FIND_NEXT2:
                SmbTrans2FindNext2RequestPacket next2Request =
                    transaction2Request as SmbTrans2FindNext2RequestPacket;
                if (next2Request != null)
                {
                    smbPacket = new SmbTrans2FindNext2ResponsePacket(next2Request.Trans2Parameters.InformationLevel,
                                                                     (next2Request.Trans2Parameters.Flags & Trans2FindFlags.SMB_FIND_RETURN_RESUME_KEYS)
                                                                     == Trans2FindFlags.SMB_FIND_RETURN_RESUME_KEYS);
                }
                break;

            case Trans2SubCommand.TRANS2_GET_DFS_REFERRAL:
                smbPacket = new SmbTrans2GetDfsReferralResponsePacket();
                break;

            default:
                break;
            }

            return(smbPacket);
        }