public NtStatus SmbdNegotiate(
            SmbdVersion minVersion,
            SmbdVersion maxVersion,
            ushort reserved,
            ushort creditsRequested,
            ushort receiveCreditMax,
            uint preferredSendSize,
            uint maxReceiveSize,
            uint maxFragmentedSize,
            out SmbdNegotiateResponse smbdNegotiateResponse
            )
        {
            NtStatus status = smbdClient.Negotiate(
                minVersion,
                maxVersion,
                creditsRequested,
                receiveCreditMax,
                preferredSendSize,
                maxReceiveSize,
                maxFragmentedSize,
                out smbdNegotiateResponse,
                reserved
                );

            // record Server's ADM
            ServerConnection.MaxSendSize       = smbdNegotiateResponse.PreferredSendSize;
            ServerConnection.MaxReceiveSize    = smbdNegotiateResponse.MaxReceiveSize;
            ServerConnection.MaxFragmentedSize = smbdNegotiateResponse.MaxFragmentedSize;
            ServerConnection.MaxReadWriteSize  = smbdNegotiateResponse.MaxReadWriteSize;

            return(status);
        }
Ejemplo n.º 2
0
        public void Negotiate_Version(
            SmbdVersion minVer,
            SmbdVersion maxVer)
        {
            const ushort CREDIT_REQUESTED   = 10;
            const ushort RECEIVE_CREDIT_MAX = 10;
            const uint   MAX_SEND_SIZE      = 1024;
            const uint   MAX_RECEIVE_SIZE   = 1024;
            const uint   MAX_FRAGMENT_SIZE  = 131072;

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Connect to server over RDMA");
            NtStatus status = smbdAdapter.ConnectToServerOverRDMA();

            BaseTestSite.Assert.AreEqual <NtStatus>(NtStatus.STATUS_SUCCESS, status, "Status of SMBD connection is {0}", status);

            BaseTestSite.Log.Add(LogEntryKind.TestStep, string.Format("SMBD Negotiate, MinVersion: {0}; MaxVersion: {1}", minVer.ToString(), maxVer.ToString()));
            SmbdNegotiateResponse response;

            status = smbdAdapter.SmbdNegotiate(
                CREDIT_REQUESTED,
                RECEIVE_CREDIT_MAX,
                MAX_SEND_SIZE,
                MAX_RECEIVE_SIZE,
                MAX_FRAGMENT_SIZE,
                out response,
                minVer,
                maxVer
                );

            // try to negotiate on SMB2
            string fileName = CreateRandomFileName();

            // Windows Server 2012 fails the Negotiate Request Message with STATUS_NOT_SUPPORTED if MinVersion or MaxVersion is not 0x0100.
            if (smbdAdapter.TestConfig.Platform == Platform.WindowsServer2012)
            {
                if (minVer == SmbdVersion.V1 &&
                    maxVer == SmbdVersion.V1)
                {
                    BaseTestSite.Assert.AreEqual <NtStatus>(
                        NtStatus.STATUS_SUCCESS,
                        status,
                        "SMBD Negotiate should succeed");

                    BaseTestSite.Log.Add(LogEntryKind.TestStep, "Establish SMB2 connection and open file " + fileName);
                    status = smbdAdapter.Smb2EstablishSessionAndOpenFile(fileName);
                    BaseTestSite.Assert.AreEqual <NtStatus>(
                        NtStatus.STATUS_SUCCESS,
                        status,
                        "Smb2EstablishSessionAndOpenFile should success");
                }
                else
                {
                    BaseTestSite.Assert.AreEqual <NtStatus>(
                        NtStatus.STATUS_NOT_SUPPORTED,
                        status,
                        "Status of SMBD negotiate {0}", status);

                    try
                    {
                        BaseTestSite.Log.Add(LogEntryKind.TestStep, "Try to establish SMB2 connection and open file " + fileName);
                        status = smbdAdapter.Smb2EstablishSessionAndOpenFile(fileName);
                        BaseTestSite.Assert.AreNotEqual <NtStatus>(
                            NtStatus.STATUS_SUCCESS,
                            status,
                            "Status of Smb2EstablishSessionAndOpenFile is {0}", status);
                    }
                    catch (TimeoutException e)
                    {
                        BaseTestSite.Assert.Pass("Cannot send or receive packets from peer. \nException: {0}\n{1}", e.Message, e.StackTrace);
                    }
                }
            }
            else
            {
                if (minVer <= SmbdVersion.V1 &&
                    maxVer >= SmbdVersion.V1)
                {
                    BaseTestSite.Assert.AreEqual <NtStatus>(
                        NtStatus.STATUS_SUCCESS,
                        status,
                        "SMBD Negotiate should succeed");

                    BaseTestSite.Log.Add(LogEntryKind.TestStep, "Establish SMB2 connection and open file " + fileName);
                    status = smbdAdapter.Smb2EstablishSessionAndOpenFile(fileName);
                    BaseTestSite.Assert.AreEqual <NtStatus>(
                        NtStatus.STATUS_SUCCESS,
                        status,
                        "Smb2EstablishSessionAndOpenFile should success");
                }
                else
                {
                    BaseTestSite.Assert.AreEqual <NtStatus>(
                        NtStatus.STATUS_NOT_SUPPORTED,
                        status,
                        "Status of SMBD negotiate {0}", status);

                    try
                    {
                        BaseTestSite.Log.Add(LogEntryKind.TestStep, "Try to establish SMB2 connection and open file " + fileName);
                        status = smbdAdapter.Smb2EstablishSessionAndOpenFile(fileName);
                        BaseTestSite.Assert.AreNotEqual <NtStatus>(
                            NtStatus.STATUS_SUCCESS,
                            status,
                            "Status of Smb2EstablishSessionAndOpenFile is {0}", status);
                    }
                    catch (TimeoutException e)
                    {
                        BaseTestSite.Assert.Pass("Cannot send or receive packets from peer. \nException: {0}\n{1}", e.Message, e.StackTrace);
                    }
                }
            }
        }
        public void Negotiate_Version(
            SmbdVersion minVer,
            SmbdVersion maxVer)
        {
            const ushort CREDIT_REQUESTED = 10;
            const ushort RECEIVE_CREDIT_MAX = 10;
            const uint MAX_SEND_SIZE = 1024;
            const uint MAX_RECEIVE_SIZE = 1024;
            const uint MAX_FRAGMENT_SIZE = 131072;

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Connect to server over RDMA");
            NtStatus status = smbdAdapter.ConnectToServerOverRDMA();
            BaseTestSite.Assert.AreEqual<NtStatus>(NtStatus.STATUS_SUCCESS, status, "Status of SMBD connection is {0}", status);

            BaseTestSite.Log.Add(LogEntryKind.TestStep, string.Format("SMBD Negotiate, MinVersion: {0}; MaxVersion: {1}", minVer.ToString(), maxVer.ToString()));
            SmbdNegotiateResponse response;
            status = smbdAdapter.SmbdNegotiate(
                CREDIT_REQUESTED,
                RECEIVE_CREDIT_MAX,
                MAX_SEND_SIZE,
                MAX_RECEIVE_SIZE,
                MAX_FRAGMENT_SIZE,
                out response,
                minVer,
                maxVer
                );

            // try to negotiate on SMB2
            string fileName = SmbdUtilities.CreateRandomFileName();

            // "<3> Section 3.1.5.6:  Windows Server 2012 fails the Negotiate Request Message with STATUS_NOT_SUPPORTED if MinVersion or MaxVersion is not 0x0100"
            if (smbdAdapter.TestConfig.Platform == Platform.WindowsServer2012)
            {
                if (minVer == SmbdVersion.V1
                    && maxVer == SmbdVersion.V1)
                {
                    BaseTestSite.Assert.AreEqual<NtStatus>(
                        NtStatus.STATUS_SUCCESS,
                        status,
                        "SMBD Negotiate should succeed");

                    BaseTestSite.Log.Add(LogEntryKind.TestStep, "Establish SMB2 connection and open file " + fileName);
                    status = smbdAdapter.Smb2EstablishSessionAndOpenFile(fileName);
                    BaseTestSite.Assert.AreEqual<NtStatus>(
                            NtStatus.STATUS_SUCCESS,
                            status,
                            "Smb2EstablishSessionAndOpenFile should success");
                }
                else
                {
                    BaseTestSite.Assert.AreEqual<NtStatus>(
                        NtStatus.STATUS_NOT_SUPPORTED,
                        status,
                        "Status of SMBD negotiate {0}", status);

                    try
                    {
                        BaseTestSite.Log.Add(LogEntryKind.TestStep, "Try to establish SMB2 connection and open file " + fileName);
                        status = smbdAdapter.Smb2EstablishSessionAndOpenFile(fileName);
                        BaseTestSite.Assert.AreNotEqual<NtStatus>(
                            NtStatus.STATUS_SUCCESS,
                            status,
                            "Status of Smb2EstablishSessionAndOpenFile is {0}", status);
                    }
                    catch (TimeoutException e)
                    {
                        BaseTestSite.Assert.Pass("Cannot send or receive packets from peer. \nException: {0}\n{1}", e.Message, e.StackTrace);
                    }
                }
            }
            else
            {
                if (minVer <= SmbdVersion.V1
                    && maxVer >= SmbdVersion.V1)
                {
                    BaseTestSite.Assert.AreEqual<NtStatus>(
                        NtStatus.STATUS_SUCCESS,
                        status,
                        "SMBD Negotiate should succeed");

                    BaseTestSite.Log.Add(LogEntryKind.TestStep, "Establish SMB2 connection and open file " + fileName);
                    status = smbdAdapter.Smb2EstablishSessionAndOpenFile(fileName);
                    BaseTestSite.Assert.AreEqual<NtStatus>(
                            NtStatus.STATUS_SUCCESS,
                            status,
                            "Smb2EstablishSessionAndOpenFile should success");
                }
                else
                {
                    BaseTestSite.Assert.AreEqual<NtStatus>(
                        NtStatus.STATUS_NOT_SUPPORTED,
                        status,
                        "Status of SMBD negotiate {0}", status);

                    try
                    {
                        BaseTestSite.Log.Add(LogEntryKind.TestStep, "Try to establish SMB2 connection and open file " + fileName);
                        status = smbdAdapter.Smb2EstablishSessionAndOpenFile(fileName);
                        BaseTestSite.Assert.AreNotEqual<NtStatus>(
                            NtStatus.STATUS_SUCCESS,
                            status,
                            "Status of Smb2EstablishSessionAndOpenFile is {0}", status);
                    }
                    catch (TimeoutException e)
                    {
                        BaseTestSite.Assert.Pass("Cannot send or receive packets from peer. \nException: {0}\n{1}", e.Message, e.StackTrace);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// SMBDirect Negotiate
        /// </summary>
        /// <param name="minVersion">The minimum SMBDirect Protocol version supported by the sender</param>
        /// <param name="maxVersion">The maximum SMBDirect Protocol version supported by the sender</param>
        /// <param name="creditsRequested">The number of Send Credits requested of the receiver</param>
        /// <param name="receiveCreditMax">Maximum of receive credits</param>
        /// <param name="preferredSendSize">The maximum number of bytes that the sender requests to transmit in a single message</param>
        /// <param name="maxReceiveSize">The maximum number of bytes that the sender can receive in a single message</param>
        /// <param name="maxFragmentedSize">The maximum number of upper-layer bytes that the sender can receive as the result of a sequence of fragmented Send operations</param>
        /// <param name="smbdNegotiateResponse">SMBDirect Negotiate response</param>
        /// <param name="reserved">The sender SHOULD set this field to 0 and the receiver MUST ignore it on receipt</param>
        /// <returns></returns>
        public NtStatus Negotiate(
            SmbdVersion minVersion,
            SmbdVersion maxVersion,
            ushort creditsRequested,
            ushort receiveCreditMax,
            uint preferredSendSize,
            uint maxReceiveSize,
            uint maxFragmentedSize,
            out SmbdNegotiateResponse smbdNegotiateResponse,
            ushort reserved = 0
            )
        {
            #region set SMBD connection

            Connection.ReceiveCreditMax  = receiveCreditMax;
            Connection.SendCreditTarget  = creditsRequested;
            Connection.MaxSendSize       = preferredSendSize;
            Connection.MaxFragmentedSize = maxFragmentedSize;
            Connection.MaxReceiveSize    = maxReceiveSize;
            #endregion

            smbdNegotiateResponse = new SmbdNegotiateResponse();

            // send negotiate message
            SmbdNegotiateRequest smbdRequest = new SmbdNegotiateRequest();
            smbdRequest.MinVersion        = minVersion;
            smbdRequest.MaxVersion        = maxVersion;
            smbdRequest.Reserved          = reserved;
            smbdRequest.CreditsRequested  = creditsRequested;
            smbdRequest.PreferredSendSize = preferredSendSize;
            smbdRequest.MaxReceiveSize    = maxReceiveSize;
            smbdRequest.MaxFragmentedSize = maxFragmentedSize;


            byte[] requestBytes = TypeMarshal.ToBytes <SmbdNegotiateRequest>(smbdRequest);

            // post receive
            NtStatus ret = Connection.Endpoint.PostReceive((uint)SmbdNegotiateResponse.SIZE);
            if (ret != NtStatus.STATUS_SUCCESS)
            {
                LogEvent(string.Format("Connection.Endpoint.PostReceive with error {0}", ret));
                return(ret);
            }

            // send message
            ret = (NtStatus)Connection.Endpoint.SendData(requestBytes);
            if (ret != NtStatus.STATUS_SUCCESS)
            {
                LogEvent(string.Format("Connection.Endpoint.SendData with error {0}", ret));
                return(ret);
            }

            byte[] responseBytes;
            try
            {
                ret = Connection.Endpoint.ReceiveData(
                    TimeSpan.FromSeconds(SmbdConnection.ACTIVE_NEGOTIATION_TIMEOUT),
                    out responseBytes);
                if (ret != NtStatus.STATUS_SUCCESS)
                {
                    LogEvent(string.Format("Connection.Endpoint.ReceiveData with error {0}", ret));
                    return(ret);
                }
            }
            catch (TimeoutException e)
            {
                LogEvent(string.Format("Do not get the SMBD negotiate response within {0} seconds", SmbdConnection.ACTIVE_NEGOTIATION_TIMEOUT));
                throw new TimeoutException(e.Message);
            }

            smbdNegotiateResponse = TypeMarshal.ToStruct <SmbdNegotiateResponse>(responseBytes);
            if ((NtStatus)smbdNegotiateResponse.Status != NtStatus.STATUS_SUCCESS)
            {
                LogEvent(string.Format("SMBDirect Negotiate response with status {0}", (NtStatus)smbdNegotiateResponse.Status));
                return((NtStatus)smbdNegotiateResponse.Status);
            }

            #region set connection parameters
            Connection.Protocol            = SmbdVersion.V1;
            Connection.ReceiveCreditTarget = smbdNegotiateResponse.CreditsRequested;
            Connection.MaxReceiveSize      = Smaller(Connection.MaxReceiveSize, smbdNegotiateResponse.PreferredSendSize);
            Connection.MaxSendSize         = Smaller(Connection.MaxSendSize, smbdNegotiateResponse.MaxReceiveSize);
            Connection.MaxReadWriteSize    = Smaller(smbdNegotiateResponse.MaxReadWriteSize, SmbdConnection.FLOOR_MAX_READ_WRITE_SIZE);
            Connection.SendCredits         = smbdNegotiateResponse.CreditsGranted;
            #endregion

            Connection.Role = SmbdRole.ESTABLISHED;
            try
            {
                Connection.FragmentReassemblyBuffer = new byte[Connection.MaxFragmentedSize];
            }
            catch (OverflowException)
            {
                Connection.MaxFragmentedSize        = smbdNegotiateResponse.MaxFragmentedSize;
                Connection.FragmentReassemblyBuffer = new byte[Connection.MaxFragmentedSize];
            }
            return((NtStatus)smbdNegotiateResponse.Status);
        }
        /// <summary>
        /// SMBDirect Negotiate
        /// </summary>
        /// <param name="minVersion">The minimum SMBDirect Protocol version supported by the sender</param>
        /// <param name="maxVersion">The maximum SMBDirect Protocol version supported by the sender</param>
        /// <param name="creditsRequested">The number of Send Credits requested of the receiver</param>
        /// <param name="receiveCreditMax">Maximum of receive credits</param>
        /// <param name="preferredSendSize">The maximum number of bytes that the sender requests to transmit in a single message</param>
        /// <param name="maxReceiveSize">The maximum number of bytes that the sender can receive in a single message</param>
        /// <param name="maxFragmentedSize">The maximum number of upper-layer bytes that the sender can receive as the result of a sequence of fragmented Send operations</param>
        /// <param name="smbdNegotiateResponse">SMBDirect Negotiate response</param>
        /// <param name="reserved">The sender SHOULD set this field to 0 and the receiver MUST ignore it on receipt</param>
        /// <returns></returns>
        public NtStatus Negotiate(
            SmbdVersion minVersion,
            SmbdVersion maxVersion,
            ushort creditsRequested,
            ushort receiveCreditMax,
            uint preferredSendSize,
            uint maxReceiveSize,
            uint maxFragmentedSize,
            out SmbdNegotiateResponse smbdNegotiateResponse,
            ushort reserved = 0
            )
        {
            #region set SMBD connection

            Connection.ReceiveCreditMax = receiveCreditMax;
            Connection.SendCreditTarget = creditsRequested;
            Connection.MaxSendSize = preferredSendSize;
            Connection.MaxFragmentedSize = maxFragmentedSize;
            Connection.MaxReceiveSize = maxReceiveSize;
            #endregion

            smbdNegotiateResponse = new SmbdNegotiateResponse();

            // send negotiate message
            SmbdNegotiateRequest smbdRequest = new SmbdNegotiateRequest();
            smbdRequest.MinVersion = minVersion;
            smbdRequest.MaxVersion = maxVersion;
            smbdRequest.Reserved = reserved;
            smbdRequest.CreditsRequested = creditsRequested;
            smbdRequest.PreferredSendSize = preferredSendSize;
            smbdRequest.MaxReceiveSize = maxReceiveSize;
            smbdRequest.MaxFragmentedSize = maxFragmentedSize;

            byte[] requestBytes = TypeMarshal.ToBytes<SmbdNegotiateRequest>(smbdRequest);

            // post receive
            NtStatus ret = Connection.Endpoint.PostReceive((uint)SmbdNegotiateResponse.SIZE);
            if (ret != NtStatus.STATUS_SUCCESS)
            {
                LogEvent(string.Format("Connection.Endpoint.PostReceive with error {0}", ret));
                return ret;
            }

            // send message
            ret = (NtStatus)Connection.Endpoint.SendData(requestBytes);
            if (ret != NtStatus.STATUS_SUCCESS)
            {
                LogEvent(string.Format("Connection.Endpoint.SendData with error {0}", ret));
                return ret;
            }

            byte[] responseBytes;
            try
            {
                ret = Connection.Endpoint.ReceiveData(
                    TimeSpan.FromSeconds(SmbdConnection.ACTIVE_NEGOTIATION_TIMEOUT),
                    out responseBytes);
                if (ret != NtStatus.STATUS_SUCCESS)
                {
                    LogEvent(string.Format("Connection.Endpoint.ReceiveData with error {0}", ret));
                    return ret;
                }
            }
            catch (TimeoutException e)
            {
                LogEvent(string.Format("Do not get the SMBD negotiate response within {0} seconds", SmbdConnection.ACTIVE_NEGOTIATION_TIMEOUT));
                throw new TimeoutException(e.Message);
            }

            smbdNegotiateResponse = TypeMarshal.ToStruct<SmbdNegotiateResponse>(responseBytes);
            if ((NtStatus)smbdNegotiateResponse.Status != NtStatus.STATUS_SUCCESS)
            {
                LogEvent(string.Format("SMBDirect Negotiate response with status {0}", (NtStatus)smbdNegotiateResponse.Status));
                return (NtStatus)smbdNegotiateResponse.Status;
            }

            #region set connection parameters
            Connection.Protocol = SmbdVersion.V1;
            Connection.ReceiveCreditTarget = smbdNegotiateResponse.CreditsRequested;
            Connection.MaxReceiveSize = Smaller(Connection.MaxReceiveSize, smbdNegotiateResponse.PreferredSendSize);
            Connection.MaxSendSize = Smaller(Connection.MaxSendSize, smbdNegotiateResponse.MaxReceiveSize);
            Connection.MaxReadWriteSize = Smaller(smbdNegotiateResponse.MaxReadWriteSize, SmbdConnection.FLOOR_MAX_READ_WRITE_SIZE);
            Connection.SendCredits = smbdNegotiateResponse.CreditsGranted;
            #endregion

            Connection.Role = SmbdRole.ESTABLISHED;
            try
            {
                Connection.FragmentReassemblyBuffer = new byte[Connection.MaxFragmentedSize];
            }
            catch (OverflowException)
            {
                Connection.MaxFragmentedSize = smbdNegotiateResponse.MaxFragmentedSize;
                Connection.FragmentReassemblyBuffer = new byte[Connection.MaxFragmentedSize];
            }
            return (NtStatus)smbdNegotiateResponse.Status;
        }
 public NtStatus SmbdNegotiate(
     ushort creditsRequested,
     ushort receiveCreditsMax,
     uint preferredSendSize,
     uint maxReceiveSize,
     uint maxFragmentSize,
     out SmbdNegotiateResponse response,
     SmbdVersion minVersion = SmbdVersion.V1,
     SmbdVersion maxVersion = SmbdVersion.V1
     )
 {
     return client.SmbdNegotiate(
         minVersion,
         maxVersion,
         0,
         creditsRequested,
         receiveCreditsMax,
         preferredSendSize,
         maxReceiveSize,
         maxFragmentSize,
         out response
         );
 }