Esempio n. 1
0
 private void OnTestCompleted(ActionCompletedUnit ou)
 {
     _testIteration++;
     if (_sendTest.SpecificResult.TransmitStatus != TransmitStatuses.CompleteOk)
     {
         _failIterations++;
     }
     if (_testIteration >= _testFrameCount)
     {
         _sendPowerLevelTestNodeReport.NewToken();
         _sendPowerLevelTestNodeReport.NodeId = _testFromNodeId;
         _sendPowerLevelTestNodeReport.Data   = new COMMAND_CLASS_POWERLEVEL.POWERLEVEL_TEST_NODE_REPORT()
         {
             statusOfOperation = _failIterations == 0 ? (byte)0x01 : (byte)0x00,
             testFrameCount    = new byte[] { (byte)(_testIteration << 8), (byte)_testIteration },
             testNodeid        = _sendTest.NodeId
         };
         ou.SetNextActionItems(_sendPowerLevelTestNodeReport);
     }
     else
     {
         _sendTest.NewToken();
         ou.SetNextActionItems(_sendTest);
     }
 }
Esempio n. 2
0
        private byte[] OnWaitSegment(byte options, byte destNodeId, byte srcNodeId, byte[] data)
        {
            _segmentCompleteExpect.Token.SetCancelled();
            var waitCmd            = (COMMAND_CLASS_TRANSPORT_SERVICE_V2.COMMAND_SEGMENT_WAIT)data;
            var waitMs             = waitCmd.pendingFragments * WAIT_TIMEOUT;
            var timeIntervalAction = new TimeInterval(Id, waitMs);

            _sendNextSegmentCompletedUnit.SetNextActionItems(timeIntervalAction);
            return(null);
        }
Esempio n. 3
0
 private void OnExpectKexGetCompleted(ActionCompletedUnit unit)
 {
     if (_learnMode.Result && _memoryGetId.Result && _serialApiGetInitData.Result)
     {
         if (_expectKexGet.Result)
         {
             _expectSchemeGet.Token.SetCancelled();
             _learnModeS2.NodeId = _expectKexGet.SpecificResult.SrcNodeId;
             if (_learnMode is SetSlaveLearnModeOperation)
             {
                 _learnModeS2.VirtualNodeId = _expectKexGet.SpecificResult.DestNodeId;
             }
             else
             {
                 _securityManagerInfo.Network.ResetAndEnableAndSelfRestore();
             }
             unit.SetNextActionItems(_learnModeS2);
         }
         else if (_expectKexGet.Result.State == ActionStates.Expired)
         {
             SpecificResult.SubstituteStatus = SubstituteStatuses.Failed;
             _securityManagerInfo.Network.ResetSecuritySchemes();
             _securityManagerInfo.Network.ResetSecuritySchemes(_expectKexGet.SpecificResult.SrcNodeId);
             SetStateCompleted(unit);
         }
     }
 }
Esempio n. 4
0
 private void OnExpectSchemeGetCompleted(ActionCompletedUnit unit)
 {
     if (_learnMode.Result && _memoryGetId.Result && _serialApiGetInitData.Result)
     {
         if (_expectSchemeGet.Result)
         {
             _expectKexGet.Token.SetCancelled();
             _learnModeS0.NodeId = _expectSchemeGet.SpecificResult.SrcNodeId;
             if (_learnMode is SetSlaveLearnModeOperation)
             {
                 _learnModeS0.VirtualNodeId = _expectSchemeGet.SpecificResult.DestNodeId;
             }
             else
             {
                 _learnModeS0.IsController = _learnMode is SetLearnModeControllerOperation;
                 _securityManagerInfo.Network.ResetAndEnableAndSelfRestore();
             }
             COMMAND_CLASS_SECURITY.SECURITY_SCHEME_GET cmd = _expectSchemeGet.SpecificResult.Command;
             _learnModeS0.SupportedSecuritySchemes = cmd.supportedSecuritySchemes;
             unit.SetNextActionItems(_learnModeS0);
         }
         else if (_expectSchemeGet.Result.State == ActionStates.Expired)
         {
             SpecificResult.SubstituteStatus = SubstituteStatuses.Failed;
             _securityManagerInfo.Network.ResetSecuritySchemes();
             _securityManagerInfo.Network.ResetSecuritySchemes(_expectSchemeGet.SpecificResult.SrcNodeId);
             SetStateCompleted(unit);
         }
     }
 }
Esempio n. 5
0
        private void OnPKReport(ActionCompletedUnit ou)
        {
            _PkReportReceivedTimeStamp = DateTime.Now;
            if (_PKReportPKReport.Result.State == ActionStates.Completed &&
                _PKReportPKReport.SpecificResult.Command != null &&
                _PKReportPKReport.SpecificResult.Command.Length > 2)
            {
                COMMAND_CLASS_SECURITY_2.PUBLIC_KEY_REPORT rpt = _PKReportPKReport.SpecificResult.Command;
                if (rpt.properties1.includingNode == 1)
                {
                    var receiverPublicKey = ((List <byte>)rpt.ecdhPublicKey).ToArray();
                    if (receiverPublicKey != null && receiverPublicKey.Length == 32 && ValidatePublicKeyReport(receiverPublicKey))
                    {
                        var senderPublicKey = _securityManagerInfo.GetJoinPublicKeyS2();
                        if (_isClientSideAuthRequested && _KEX_SET.properties1.requestCsa > 0 && _securityManagerInfo.DSKVerificationOnReceiverCallback != null)
                        {
                            byte[] senderDSK = _securityManagerInfo.DSKVerificationOnReceiverCallback();
                            if (senderDSK != null && senderDSK.Length == 4)
                            {
                                Array.Copy(senderDSK, 0, receiverPublicKey, 0, 4);
                            }
                        }
                        _securityManagerInfo.SetNetworkKeyS2Temp(_securityManagerInfo.CalculateTempNetworkKeyS2(receiverPublicKey, false));
                        _securityManagerInfo.ActivateNetworkKeyS2TempForNode(_peerNodeId);

                        var kexSetEcho = _KEX_SET;
                        kexSetEcho.properties1.echo         = 1;
                        _KEXSetEchoKEXReportEcho.DestNodeId = NodeId;
                        _KEXSetEchoKEXReportEcho.SrcNodeId  = VirtualNodeId;
                        _KEXSetEchoKEXReportEcho.Data       = kexSetEcho;

                        _isWaitingForKexReportEcho = true;
                        #region KEXSetEcho
                        _securityTestSettingsService.ActivateTestPropertiesForFrame(SecurityS2TestFrames.KEXSetEcho, _KEXSetEchoKEXReportEcho);
                        #endregion
                    }
                    else
                    {
                        _KexFail.Data = new COMMAND_CLASS_SECURITY_2.KEX_FAIL {
                            kexFailType = 0x00
                        };
                        _KexFail.NodeId       = NodeId;
                        _KexFail.BridgeNodeId = VirtualNodeId;
                        ou.SetNextActionItems(_KexFail);
                    }
                }
                else
                {
                    SetStateCompletedSecurityFailed(ou);
                }
            }
            else
            {
                SetStateCompletedSecurityFailed(ou);
            }
        }
Esempio n. 6
0
        private void OnNetworkKeySet(ActionCompletedUnit ou)
        {
            const byte keyLength = 16;

            if (requestNetworkKey.Result.State == ActionStates.Completed)
            {
                COMMAND_CLASS_SECURITY.NETWORK_KEY_SET cmd = requestNetworkKey.SpecificResult.Command;
                byte[] key = new byte[keyLength];
                if (cmd.networkKeyByte != null && cmd.networkKeyByte.Count() == keyLength)
                {
                    Array.Copy(cmd.networkKeyByte.ToArray(), 0, key, 0, Math.Min(cmd.networkKeyByte.Count, keyLength));
                    _securityManagerInfo.SetNetworkKey(key, SecuritySchemes.S0);
                    _securityManagerInfo.ActivateNetworkKeyS0();
                    if (VirtualNodeId > 0 || !IsController)
                    {
                        sendNetworkKeyVerify.NodeId       = NodeId;
                        sendNetworkKeyVerify.BridgeNodeId = VirtualNodeId;
                        ou.SetNextActionItems(sendNetworkKeyVerify);
                    }
                    else
                    {
                        requestSchemeInherit.DestNodeId = NodeId;
                        requestSchemeInherit.SrcNodeId  = VirtualNodeId;
                        ou.SetNextActionItems(requestSchemeInherit);
                        if (_securityManagerInfo.DelaysS0.ContainsKey(SecurityS0Delays.NetworkKeyVerify))
                        {
                            requestSchemeInherit.DataDelay = _securityManagerInfo.DelaysS0[SecurityS0Delays.NetworkKeyVerify];
                        }
                    }
                }
                else
                {
                    SpecificResult.SubstituteStatus = SubstituteStatuses.Failed;
                    SetStateCompletedSecurityFailed(ou);
                }
            }
            else
            {
                SpecificResult.SubstituteStatus = SubstituteStatuses.Failed;
                SetStateCompletedSecurityFailed(ou);
            }
        }
Esempio n. 7
0
 protected void OnSecurityMessageReceived(ActionCompletedUnit ou)
 {
     if (_SecurityMessageReceived.Result)
     {
         if (_isWaitingForKexReportEcho)
         {
             Thread.Sleep(3000);
             _KexFail.SubstituteSettings.ClearFlag(SubstituteFlags.DenySecurity);
         }
         _KexFail.Data = new COMMAND_CLASS_SECURITY_2.KEX_FAIL {
             kexFailType = 0x05
         };
         _KexFail.NodeId       = NodeId;
         _KexFail.BridgeNodeId = VirtualNodeId;
         ou.SetNextActionItems(_KexFail);
     }
 }
Esempio n. 8
0
 private void OnNetworkKeyVerify(ActionCompletedUnit ou)
 {
     if (expectNetworkKeyVerify.Result.State == ActionStates.Completed)
     {
         if (SpecificResult.IsSlave)
         {
             SetStateCompletedSecurityDone(ou);
         }
         else
         {
             requestSchemeInherit.DestNodeId = SpecificResult.Id;
             ou.SetNextActionItems(requestSchemeInherit);
             if (SecurityManagerInfo.DelaysS0.ContainsKey(SecurityS0Delays.SchemeInherit))
             {
                 requestSchemeInherit.DataDelay = SecurityManagerInfo.DelaysS0[SecurityS0Delays.SchemeInherit];
             }
         }
     }
     else
     {
         SetStateCompletedSecurityFailed(ou);
     }
 }
Esempio n. 9
0
 private void OnOperationCompletedAfter(ActionCompletedUnit taskUnit, ActionCompletedUnit completedTaskUnit, ApiOperation op)
 {
     op.SubstituteSettings = SubstituteSettings;
     op.NewToken();
     taskUnit.SetNextActionItems(op);
 }
Esempio n. 10
0
        private void OnTransferEnd(ActionCompletedUnit ou)
        {
            if (_NKVerifyTransferEnd.Result)
            {
                if (_NKVerifyTransferEnd.SpecificResult.RxSecurityScheme == SecuritySchemes.S2_TEMP)
                {
                    COMMAND_CLASS_SECURITY_2.SECURITY_2_TRANSFER_END rpt = _NKVerifyTransferEnd.SpecificResult.Command;
                    if (rpt.properties1.keyVerified > 0)
                    {
                        if (_grantedKeys.Count > 0)
                        {
                            _NKGetNKReport.NewToken();
                            var cmd = new COMMAND_CLASS_SECURITY_2.SECURITY_2_NETWORK_KEY_GET();
                            var key = _grantedKeys.Dequeue();
                            cmd.requestedKey    = (byte)key;
                            _NKGetNKReport.Data = cmd;

                            #region TestFrame Section
                            var scheme = SecurityManagerInfo.ConvertToSecurityScheme(key);
                            switch (scheme)
                            {
                            case SecuritySchemes.S0:
                                #region NetworkKeyGet
                                _securityTestSettingsService.ActivateTestPropertiesForFrame(SecurityS2TestFrames.NetworkKeyGet_S0, _NKGetNKReport);
                                #endregion
                                break;

                            case SecuritySchemes.S2_UNAUTHENTICATED:
                                #region NetworkKeyGet
                                _securityTestSettingsService.ActivateTestPropertiesForFrame(SecurityS2TestFrames.NetworkKeyGet_S2Unauthenticated, _NKGetNKReport);
                                #endregion
                                break;

                            case SecuritySchemes.S2_AUTHENTICATED:
                                #region NetworkKeyGet
                                _securityTestSettingsService.ActivateTestPropertiesForFrame(SecurityS2TestFrames.NetworkKeyGet_S2Authenticated, _NKGetNKReport);
                                #endregion
                                break;

                            case SecuritySchemes.S2_ACCESS:
                                #region NetworkKeyGet
                                _securityTestSettingsService.ActivateTestPropertiesForFrame(SecurityS2TestFrames.NetworkKeyGet_S2Access, _NKGetNKReport);
                                #endregion
                                break;
                            }
                            #endregion

                            ou.SetNextActionItems(_NKGetNKReport);
                        }
                        else
                        {
                            _TransferEnd.NodeId       = NodeId;
                            _TransferEnd.BridgeNodeId = VirtualNodeId;
                            var cmd = new COMMAND_CLASS_SECURITY_2.SECURITY_2_TRANSFER_END();
                            cmd.properties1.keyRequestComplete = 1;
                            cmd.properties1.keyVerified        = 0;
                            _TransferEnd.Data = cmd;
                            #region TransferEndB
                            _securityTestSettingsService.ActivateTestPropertiesForFrame(SecurityS2TestFrames.TransferEndB, _TransferEnd);
                            #endregion
                            ou.SetNextActionItems(_TransferEnd);
                        }
                    }
                    else
                    {
                        SetStateCompletedSecurityFailed(ou);
                    }
                }
                else
                {
                    _securityManagerInfo.ActivateNetworkKeyS2TempForNode(_peerNodeId);
                    _KexFail.SubstituteSettings.ClearFlag(SubstituteFlags.DenySecurity);
                    _KexFail.Data = new COMMAND_CLASS_SECURITY_2.KEX_FAIL {
                        kexFailType = 0x07
                    };                                                                            // KEX_FAIL_AUTH
                    _KexFail.NodeId       = NodeId;
                    _KexFail.BridgeNodeId = VirtualNodeId;
                    ou.SetNextActionItems(_KexFail);
                }
            }
            else
            {
                SetStateCompletedSecurityFailed(ou);
            }
        }
Esempio n. 11
0
        private void OnNKReport(ActionCompletedUnit ou)
        {
            if (_NKGetNKReport.Result)
            {
                if (_NKGetNKReport.SpecificResult.RxSecurityScheme == SecuritySchemes.S2_TEMP)
                {
                    COMMAND_CLASS_SECURITY_2.SECURITY_2_NETWORK_KEY_GET    get = _NKGetNKReport.Data;
                    COMMAND_CLASS_SECURITY_2.SECURITY_2_NETWORK_KEY_REPORT rpt = _NKGetNKReport.SpecificResult.Command;
                    if (rpt.grantedKey == get.requestedKey && rpt.networkKey != null && rpt.networkKey.Length == 16)
                    {
                        NetworkKeyS2Flags verifyKey = (NetworkKeyS2Flags)rpt.grantedKey;
                        var scheme = SecurityManagerInfo.ConvertToSecurityScheme(verifyKey);
                        if (scheme != SecuritySchemes.NONE)
                        {
                            _grantedSchemes.Add(scheme);
                            SpecificResult.SecuritySchemes = _grantedSchemes.ToArray();
                            _securityManagerInfo.SetNetworkKey(rpt.networkKey, scheme);
                            if (scheme == SecuritySchemes.S0)
                            {
                                _securityManagerInfo.ActivateNetworkKeyS0();
                            }
                            _securityManagerInfo.ActivateNetworkKeyS2ForNode(_peerNodeId, scheme);

                            _NKVerifyTransferEnd.NewToken();
                            _NKVerifyTransferEnd.DestNodeId = NodeId;
                            _NKVerifyTransferEnd.SrcNodeId  = VirtualNodeId;
                            var cmd = new COMMAND_CLASS_SECURITY_2.SECURITY_2_NETWORK_KEY_VERIFY();
                            _NKVerifyTransferEnd.Data = cmd;

                            #region TestFrame Section
                            switch (scheme)
                            {
                            case SecuritySchemes.S0:
                                #region NetworkKeyVerify_S0
                                _securityTestSettingsService.ActivateTestPropertiesForFrame(SecurityS2TestFrames.NetworkKeyVerify_S0, _NKVerifyTransferEnd);
                                #endregion
                                break;

                            case SecuritySchemes.S2_UNAUTHENTICATED:
                                #region NetworkKeyVerify_S2Unauthenticated
                                _securityTestSettingsService.ActivateTestPropertiesForFrame(SecurityS2TestFrames.NetworkKeyVerify_S2Unauthenticated, _NKVerifyTransferEnd);
                                #endregion
                                break;

                            case SecuritySchemes.S2_AUTHENTICATED:
                                #region NetworkKeyVerify_S2Authenticated
                                _securityTestSettingsService.ActivateTestPropertiesForFrame(SecurityS2TestFrames.NetworkKeyVerify_S2Authenticated, _NKVerifyTransferEnd);
                                #endregion
                                break;

                            case SecuritySchemes.S2_ACCESS:
                                #region NetworkKeyVerify_S2Access
                                _securityTestSettingsService.ActivateTestPropertiesForFrame(SecurityS2TestFrames.NetworkKeyVerify_S2Access, _NKVerifyTransferEnd);
                                #endregion
                                break;
                            }
                            #endregion
                            _NKVerifyTransferEnd.SendDataSubstituteCallback = () =>
                            {
                                _securityManagerInfo.ActivateNetworkKeyS2TempForNode(_peerNodeId);
                            };
                        }
                        else
                        {
                            _securityManagerInfo.ActivateNetworkKeyS2TempForNode(_peerNodeId);
                            _KexFail.SubstituteSettings.ClearFlag(SubstituteFlags.DenySecurity);
                            _KexFail.Data = new COMMAND_CLASS_SECURITY_2.KEX_FAIL {
                                kexFailType = 0x0A
                            };                                                                            // KEX_FAIL_KEY_REPORT
                            _KexFail.NodeId       = NodeId;
                            _KexFail.BridgeNodeId = VirtualNodeId;
                            ou.SetNextActionItems(_KexFail);
                        }
                    }
                    else
                    {
                        _securityManagerInfo.ActivateNetworkKeyS2TempForNode(_peerNodeId);
                        _KexFail.SubstituteSettings.ClearFlag(SubstituteFlags.DenySecurity);
                        _KexFail.Data = new COMMAND_CLASS_SECURITY_2.KEX_FAIL {
                            kexFailType = 0x0A
                        };                                                                            // KEX_FAIL_KEY_REPORT
                        _KexFail.NodeId       = NodeId;
                        _KexFail.BridgeNodeId = VirtualNodeId;
                        ou.SetNextActionItems(_KexFail);
                    }
                }
                else
                {
                    _securityManagerInfo.ActivateNetworkKeyS2TempForNode(_peerNodeId);
                    _KexFail.SubstituteSettings.ClearFlag(SubstituteFlags.DenySecurity);
                    _KexFail.Data = new COMMAND_CLASS_SECURITY_2.KEX_FAIL {
                        kexFailType = 0x07
                    };                                                                            // KEX_FAIL_AUTH
                    _KexFail.NodeId       = NodeId;
                    _KexFail.BridgeNodeId = VirtualNodeId;
                    ou.SetNextActionItems(_KexFail);
                }
            }
            else
            {
                SetStateCompletedSecurityFailed(ou);
            }
        }
Esempio n. 12
0
        private void OnKEXReportEcho(ActionCompletedUnit ou)
        {
            if (_KEXSetEchoKEXReportEcho.Result)
            {
                _isWaitingForKexReportEcho = false;
                if (_KEXSetEchoKEXReportEcho.SpecificResult.RxSecurityScheme == SecuritySchemes.S2_TEMP)
                {
                    if (ValidateKexReportEcho(_KEXSetEchoKEXReportEcho.SpecificResult.Command))
                    {
                        _NKGetNKReport.DestNodeId = NodeId;
                        _NKGetNKReport.SrcNodeId  = VirtualNodeId;
                        if (_grantedKeys.Count > 0)
                        {
                            var cmd = new COMMAND_CLASS_SECURITY_2.SECURITY_2_NETWORK_KEY_GET();
                            var key = _grantedKeys.Dequeue();
                            cmd.requestedKey    = (byte)key;
                            _NKGetNKReport.Data = cmd;

                            ou.SetNextActionItems(_NKGetNKReport);

                            #region TestFrame Section
                            var scheme = SecurityManagerInfo.ConvertToSecurityScheme(key);
                            switch (scheme)
                            {
                            case SecuritySchemes.S0:
                                #region NetworkKeyGet
                                _securityTestSettingsService.ActivateTestPropertiesForFrame(SecurityS2TestFrames.NetworkKeyGet_S0, _NKGetNKReport);
                                #endregion
                                break;

                            case SecuritySchemes.S2_UNAUTHENTICATED:
                                #region NetworkKeyGet
                                _securityTestSettingsService.ActivateTestPropertiesForFrame(SecurityS2TestFrames.NetworkKeyGet_S2Unauthenticated, _NKGetNKReport);
                                #endregion
                                break;

                            case SecuritySchemes.S2_AUTHENTICATED:
                                #region NetworkKeyGet
                                _securityTestSettingsService.ActivateTestPropertiesForFrame(SecurityS2TestFrames.NetworkKeyGet_S2Authenticated, _NKGetNKReport);
                                #endregion
                                break;

                            case SecuritySchemes.S2_ACCESS:
                                #region NetworkKeyGet
                                _securityTestSettingsService.ActivateTestPropertiesForFrame(SecurityS2TestFrames.NetworkKeyGet_S2Access, _NKGetNKReport);
                                #endregion
                                break;
                            }
                            #endregion
                        }
                        else
                        {
                            _TransferEnd.NodeId       = NodeId;
                            _TransferEnd.BridgeNodeId = VirtualNodeId;
                            var cmd = new COMMAND_CLASS_SECURITY_2.SECURITY_2_TRANSFER_END();
                            cmd.properties1.keyRequestComplete = 1;
                            cmd.properties1.keyVerified        = 0;
                            _TransferEnd.Data = cmd;

                            #region TransferEndB
                            _securityTestSettingsService.ActivateTestPropertiesForFrame(SecurityS2TestFrames.TransferEndB, _TransferEnd);
                            #endregion
                            ou.SetNextActionItems(_TransferEnd);
                        }
                    }
                    else
                    {
                        _KexFail.SubstituteSettings.ClearFlag(SubstituteFlags.DenySecurity);
                        _KexFail.Data = new COMMAND_CLASS_SECURITY_2.KEX_FAIL {
                            kexFailType = 0x07
                        };                                                                            // KEX_FAIL_AUTH
                        _KexFail.NodeId       = NodeId;
                        _KexFail.BridgeNodeId = VirtualNodeId;
                        ou.SetNextActionItems(_KexFail);
                    }
                }
                else
                {
                    _KexFail.SubstituteSettings.ClearFlag(SubstituteFlags.DenySecurity);
                    _KexFail.Data = new COMMAND_CLASS_SECURITY_2.KEX_FAIL {
                        kexFailType = 0x07
                    };                                                                            // KEX_FAIL_AUTH
                    _KexFail.NodeId       = NodeId;
                    _KexFail.BridgeNodeId = VirtualNodeId;
                    ou.SetNextActionItems(_KexFail);
                }
            }
            else if (_isClientSideAuthGranted)
            {
                _KexFail.Data = new COMMAND_CLASS_SECURITY_2.KEX_FAIL {
                    kexFailType = 0x06
                };                                                                            // KEX_FAIL_CANCEL
                _KexFail.NodeId       = NodeId;
                _KexFail.BridgeNodeId = VirtualNodeId;
                ou.SetNextActionItems(_KexFail);
            }
            else if ((DateTime.Now - _PkReportReceivedTimeStamp).TotalMilliseconds < InclusionS2TimeoutConstants.Including.UserInputDsk)
            {
                _KEXSetEchoKEXReportEcho.NewToken();
                ou.SetNextActionItems(_KEXSetEchoKEXReportEcho);
            }
            else
            {
                SetStateCompletedSecurityFailed(ou);
            }
        }
Esempio n. 13
0
        private void OnKEXSet(ActionCompletedUnit ou)
        {
            if (_KEXReportKEXSet.Result &&
                _KEXReportKEXSet.Result.State == ActionStates.Completed &&
                _KEXReportKEXSet.SpecificResult.Command != null &&
                _KEXReportKEXSet.SpecificResult.Command.Length > 2)
            {
                _grantedKeys.Clear();
                _KEX_SET = _KEXReportKEXSet.SpecificResult.Command;
                if (_KEX_SET.properties1.echo == 0 && _KEX_SET.selectedKexScheme == 0x02 && _KEX_SET.selectedEcdhProfile == 0x01)
                {
                    if (CheckIsCsaCorrectlyGranted() && ValidateKexSetKeys())
                    {
                        bool hasHighKeys = false;
                        NetworkKeyS2Flags grantedKeysMask = (NetworkKeyS2Flags)_KEX_SET.grantedKeys;
                        if (grantedKeysMask.HasFlag(NetworkKeyS2Flags.S2Class2))
                        {
                            _grantedKeys.Enqueue(NetworkKeyS2Flags.S2Class2);
                            hasHighKeys = true;
                        }
                        if (grantedKeysMask.HasFlag(NetworkKeyS2Flags.S2Class1))
                        {
                            _grantedKeys.Enqueue(NetworkKeyS2Flags.S2Class1);
                            hasHighKeys = true;
                        }
                        if (grantedKeysMask.HasFlag(NetworkKeyS2Flags.S2Class0))
                        {
                            _grantedKeys.Enqueue(NetworkKeyS2Flags.S2Class0);
                        }
                        if (grantedKeysMask.HasFlag(NetworkKeyS2Flags.S0))
                        {
                            _grantedKeys.Enqueue(NetworkKeyS2Flags.S0);
                        }

                        _PKReportPKReport.DestNodeId = NodeId;
                        _PKReportPKReport.SrcNodeId  = VirtualNodeId;
                        var cmd = new COMMAND_CLASS_SECURITY_2.PUBLIC_KEY_REPORT();
                        cmd.properties1          = 0;
                        cmd.ecdhPublicKey        = new List <byte>(_securityManagerInfo.GetJoinPublicKeyS2());
                        _isClientSideAuthGranted = _KEX_SET.properties1.requestCsa > 0 ? true : false;
                        if (hasHighKeys && !_isClientSideAuthGranted && cmd.ecdhPublicKey.Count > 1)
                        {
                            cmd.ecdhPublicKey[0] = 0;
                            cmd.ecdhPublicKey[1] = 0;
                            if (_securityManagerInfo.DskPinCallback != null)
                            {
                                _securityManagerInfo.DskPinCallback();
                            }
                        }
                        _PKReportPKReport.Data = cmd;
                        #region PublicKeyReportB
                        _securityTestSettingsService.ActivateTestPropertiesForFrame(SecurityS2TestFrames.PublicKeyReportB, _PKReportPKReport);
                        #endregion
                    }
                    else
                    {
                        _KexFail.Data = new COMMAND_CLASS_SECURITY_2.KEX_FAIL {
                            kexFailType = 0x01
                        };
                        _KexFail.NodeId       = NodeId;
                        _KexFail.BridgeNodeId = VirtualNodeId;
                        ou.SetNextActionItems(_KexFail);
                    }
                }
                else
                {
                    byte currentKexFailType = _KEX_SET.selectedKexScheme != 0x02 ? (byte)0x02 : (byte)0x00;
                    if (currentKexFailType == 0x00)
                    {
                        currentKexFailType = _KEX_SET.selectedEcdhProfile != 0x01 ? (byte)0x03 : (byte)0x00;
                    }

                    _KexFail.Data = new COMMAND_CLASS_SECURITY_2.KEX_FAIL {
                        kexFailType = currentKexFailType
                    };
                    _KexFail.NodeId       = NodeId;
                    _KexFail.BridgeNodeId = VirtualNodeId;
                    ou.SetNextActionItems(_KexFail);
                }
            }
            else
            {
                SetStateCompletedSecurityFailed(ou);
            }
        }