The SMB2 Lease Break Notification packet is sent by the server when the underlying object store indicates that a lease is being broken, representing a change in the lease state. This is only valid on the SMB 2.1 dialect. This response is composed of an SMB2 header, as specified in section 2.2.1, followed by this notification structure:
 /// <summary>
 /// Acknowledge LeaseBreakNotification received from server
 /// </summary>
 /// <param name="client">Client to send the acknowledgement</param>
 /// <param name="treeId">TreeId associated to send the acknowledgement</param>
 /// <param name="leaseBreakNotify">LeaseBreakNotification received from server</param>
 protected virtual void AcknowledgeLeaseBreak(Smb2FunctionalClient client, uint treeId, LEASE_BREAK_Notification_Packet leaseBreakNotify)
 {
     if (receivedLeaseBreakNotify.Flags == LEASE_BREAK_Notification_Packet_Flags_Values.SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED)
     {
         BaseTestSite.Log.Add(
             LogEntryKind.Debug,
             "Server requires an LEASE_BREAK_ACK on this LEASE_BREAK_NOTIFY");
         // Will add verification for response after SDK change
         uint status = client.LeaseBreakAcknowledgment(treeId, leaseBreakNotify.LeaseKey, leaseBreakNotify.NewLeaseState);
         BaseTestSite.Assert.AreEqual(
             Smb2Status.STATUS_SUCCESS,
             status,
             "LeaseBreakAcknowledgement should succeed, actual status is {0}", Smb2Status.GetStatusCode(status));
     }
     else
     {
         BaseTestSite.Log.Add(
             LogEntryKind.Debug,
             "Server does not require an LEASE_BREAK_ACK on this LEASE_BREAK_NOTIFY");
     }
 }
 private void OnLeaseBreakNotificationReceived(Packet_Header header, LEASE_BREAK_Notification_Packet notification)
 {
     // Set Lease break state
     breakType = ModelBreakType.LeaseBreak;
     leaseClient.LeaseBreakAcknowledgment(treeIdLease, notification.LeaseKey, notification.NewLeaseState);
 }
 private void OnLeaseBreakNotificationReceived(Packet_Header header, LEASE_BREAK_Notification_Packet notification)
 {
     // Set Lease breake state
     leaseBreakState = LeaseBreakState.LeaseBreakExisted;
 }
        /// <summary>
        /// Handler when receive a LeaseBreakNotification
        /// </summary>
        /// <param name="respHeader">Packet header of LeaseBreakNotification</param>
        /// <param name="leaseBreakNotify">Received LeaseBreakNotification</param>
        protected override void OnLeaseBreakNotificationReceived(Packet_Header respHeader, LEASE_BREAK_Notification_Packet leaseBreakNotify)
        {
            BaseTestSite.Log.Add(
                LogEntryKind.Comment,
                "LeaseBreakNotification with LeaseKey \"{0}\" was received from server", leaseBreakNotify.LeaseKey.ToString());
            lock (breakNotifications)
            {
                breakNotifications.Add(leaseBreakNotify.LeaseKey, leaseBreakNotify);
            }

            receivedLeaseBreakNotify = leaseBreakNotify;

            BaseTestSite.Assert.AreEqual<ulong>(
                0xFFFFFFFFFFFFFFFF,
                respHeader.MessageId,
                "Expect that the field MessageId is set to 0xFFFFFFFFFFFFFFFF.");
            BaseTestSite.Assert.AreEqual<ulong>(
                0,
                respHeader.SessionId,
                "Expect that the field SessionId is set to 0.");
            BaseTestSite.Assert.AreEqual<uint>(
                0,
                respHeader.TreeId,
                "Expect that the field TreeId is set to 0.");

            BaseTestSite.Assert.AreEqual(
                expectedNewLeaseStates[leaseBreakNotify.LeaseKey],
                leaseBreakNotify.NewLeaseState,
                "NewLeaseState in LeaseBreakNotification from server should be {0}", expectedNewLeaseStates[leaseBreakNotify.LeaseKey]);
            // NewEpoch should be 2 based on assumption that no lease state change before this break since server initially granted
            BaseTestSite.Assert.AreEqual(
                2,
                leaseBreakNotify.NewEpoch,
                "NewEpoch in LeaseBreakNotification from server should be 2");
            BaseTestSite.Assert.AreEqual<uint>(
                0,
                leaseBreakNotify.BreakReason,
                "Expect that the field BreakReason is set to 0.");
            BaseTestSite.Assert.AreEqual<uint>(
                0,
                leaseBreakNotify.AccessMaskHint,
                "Expect that the field AccessMaskHint is set to 0.");
            BaseTestSite.Assert.AreEqual<uint>(
                0,
                leaseBreakNotify.ShareMaskHint,
                "Expect that the field ShareMaskHint is set to 0.");

            notificationsReceived[leaseBreakNotify.LeaseKey].Set();
        }
        /// <summary>
        /// Handle the lease break notification.
        /// </summary>
        /// <param name="respHeader">The SMB2 header included in the notification.</param>
        /// <param name="leaseBreakNotify">Lease break notification payload in the notification.</param>
        public void OnLeaseBreakNotificationReceived(Packet_Header respHeader, LEASE_BREAK_Notification_Packet leaseBreakNotify)
        {
            uint status = 0;
            Packet_Header header;
            LEASE_BREAK_Response leaseBreakResp;

            status = Client.LeaseBreakAcknowledgment(1, 1, Flags, MessageId++, SessionId,
                TreeId, leaseBreakNotify.LeaseKey, leaseBreakNotify.NewLeaseState, out header, out leaseBreakResp);
        }
        private void OnLeaseBreakNotificationReceived(Packet_Header respHeader, LEASE_BREAK_Notification_Packet leaseBreakNotify)
        {
            Site.Log.Add(LogEntryKind.Debug, "LeaseBreakNotification was received from server");

            Site.Assert.AreEqual<Smb2Command>(Smb2Command.OPLOCK_BREAK, respHeader.Command, "Expect that the Command MUST be OPLOCK_BREAK.");
            Site.Assert.AreEqual<ulong>(0xFFFFFFFFFFFFFFFF, respHeader.MessageId, "Expect that the field MessageId MUST be set to 0xFFFFFFFFFFFFFFFF.");
            Site.Assert.AreEqual<ulong>(0, respHeader.SessionId, "Expect that the field SessionId MUST be set to 0.");
            Site.Assert.AreEqual<uint>(0, respHeader.TreeId, "Expect that the field TreeId MUST be set to 0.");

            Site.CaptureRequirementIfAreEqual<ushort>((ushort)44, leaseBreakNotify.StructureSize,
                        RequirementCategory.MUST_BE_SPECIFIED_VALUE.Id,
                        RequirementCategory.MUST_BE_SPECIFIED_VALUE.Description);
            Site.Assert.AreEqual<Guid>(LeaseKey, leaseBreakNotify.LeaseKey, "Expect that the field LeaseKey equals {0}.", LeaseKey.ToString());
            Site.CaptureRequirementIfAreEqual<uint>(0, leaseBreakNotify.BreakReason,
                        RequirementCategory.MUST_BE_ZERO.Id,
                        RequirementCategory.MUST_BE_ZERO.Description);
            Site.CaptureRequirementIfAreEqual<uint>(0, leaseBreakNotify.AccessMaskHint,
                        RequirementCategory.MUST_BE_ZERO.Id,
                        RequirementCategory.MUST_BE_ZERO.Description);
            Site.CaptureRequirementIfAreEqual<uint>(0, leaseBreakNotify.ShareMaskHint,
                        RequirementCategory.MUST_BE_ZERO.Id,
                        RequirementCategory.MUST_BE_ZERO.Description);

            Site.Log.Add(LogEntryKind.Debug, "Current lease state: \t{0}", leaseBreakNotify.CurrentLeaseState);
            Site.Log.Add(LogEntryKind.Debug, "New lease state: \t{0}", leaseBreakNotify.NewLeaseState);
            Site.Log.Add(LogEntryKind.Debug, "New epoch: \t{0}", leaseBreakNotify.NewEpoch);

            this.OnLeaseBreakNotification(leaseBreakNotify.NewEpoch, leaseBreakNotify.Flags, (uint)leaseBreakNotify.CurrentLeaseState,
                (uint)leaseBreakNotify.NewLeaseState);
        }
        /// <summary>
        /// Handler when receive LeaseBreakNotification
        /// </summary>
        /// <param name="respHeader">Packet header in LeaseBreakNotification</param>
        /// <param name="leaseBreakNotify">Received LeaseBreakNotification</param>
        protected virtual void OnLeaseBreakNotificationReceived(Packet_Header respHeader, LEASE_BREAK_Notification_Packet leaseBreakNotify)
        {
            BaseTestSite.Log.Add(
                LogEntryKind.Debug,
                "LeaseBreakNotification was received from server");
            receivedLeaseBreakNotify = leaseBreakNotify;

            BaseTestSite.Assert.AreEqual<ulong>(
                0xFFFFFFFFFFFFFFFF,
                respHeader.MessageId,
                "Expect that the field MessageId is set to 0xFFFFFFFFFFFFFFFF.");
            BaseTestSite.Assert.AreEqual<ulong>(
                0,
                respHeader.SessionId,
                "Expect that the field SessionId is set to 0.");
            BaseTestSite.Assert.AreEqual<uint>(
                0,
                respHeader.TreeId,
                "Expect that the field TreeId is set to 0.");
            BaseTestSite.Assert.AreEqual(
                expectedNewLeaseState,
                leaseBreakNotify.NewLeaseState,
                "NewLeaseState in LeaseBreakNotification from server should be {0}", expectedNewLeaseState);
            BaseTestSite.Assert.AreEqual<uint>(
                0,
                leaseBreakNotify.BreakReason,
                "Expect that the field BreakReason is set to 0.");
            BaseTestSite.Assert.AreEqual<uint>(
                0,
                leaseBreakNotify.AccessMaskHint,
                "Expect that the field AccessMaskHint is set to 0.");
            BaseTestSite.Assert.AreEqual<uint>(
                0,
                leaseBreakNotify.ShareMaskHint,
                "Expect that the field ShareMaskHint is set to 0.");

            notificationReceived.Set();
        }
 protected override void OnLeaseBreakNotificationReceived(Packet_Header respHeader, LEASE_BREAK_Notification_Packet leaseBreakNotify)
 {
     BaseTestSite.Log.Add(LogEntryKind.Debug, "LeaseBreakNotification was received from server");
     isLeaseBreakReceived = true;
 }
        /// <summary>
        /// Handle the lease break notification.
        /// </summary>
        /// <param name="respHeader">The SMB2 header included in the notification.</param>
        /// <param name="leaseBreakNotify">Lease break notification payload in the notification.</param>
        private void OnLeaseBreakNotificationReceived(Packet_Header respHeader, LEASE_BREAK_Notification_Packet leaseBreakNotify)
        {
            Smb2FunctionalClient client = null;
            if (smb2ClientMainChannel != null)
            {
                client = smb2ClientMainChannel;
            }
            else if (smb2ClientAlternativeChannel != null)
            {
                client = smb2ClientAlternativeChannel;
            }

            if (client != null)
            {
                Site.Log.Add(LogEntryKind.Debug, "Receive a lease break notification and will send lease break acknowledgment.");
                client.LeaseBreakAcknowledgment(
                    treeIdMainChannel,
                    leaseKeyMainChannel,
                    leaseBreakNotify.NewLeaseState);
            }
        }