Ejemplo n.º 1
0
        protected override void OnHandledInternal(DataReceivedUnit ou)
        {
            byte nodeId = ReceivedAchData.SrcNodeId;

            byte[] command = ReceivedAchData.Command;
            if (command != null && command.Length > 1)
            {
                if (command[1] == COMMAND_CLASS_INCLUSION_CONTROLLER.INITIATE.ID && nodeIdToInclude == 0)
                {
                    var initiateCommand = (COMMAND_CLASS_INCLUSION_CONTROLLER.INITIATE)command;

                    if (initiateCommand.stepId == PROXY_INCLUSION || initiateCommand.stepId == PROXY_INCLUSION_REPLACE)
                    {
                        /*TO# 07220 - Delay before request Node Info*/
                        Thread.Sleep(2000);

                        //if we're not SIS then ignore
                        if (_securityManagerInfo.Network.SucNodeId == _securityManagerInfo.Network.NodeId)
                        {
                            //Start add node for example
                            nodeIdToInclude = initiateCommand.nodeId;

                            var isVirtualNodeOperation = new IsVirtualNodeOperation(nodeIdToInclude);
                            if (ReceivedAchData.CommandType != CommandTypes.CmdApplicationCommandHandler_Bridge)
                            {
                                isVirtualNodeOperation.Token.SetCancelled();
                            }
                            var stepId           = initiateCommand.stepId;
                            var sendDataComplete = new InclusionController.Complete(nodeId, TxOptions);
                            sendDataComplete.SetCommandParameters(STEP_OK, stepId);
                            var requestDataStep2 = new InclusionController.Initiate(0, nodeId, TxOptions, 20000);
                            requestDataStep2.SetCommandParameters(nodeIdToInclude, S0_INCLUSION);
                            var sendDataRejectComplete = new InclusionController.Complete(nodeId, TxOptions);
                            sendDataRejectComplete.SetCommandParameters(STEP_USER_REJECTED, stepId);

                            var addNodeOperation = new AddNodeS2Operation(_securityManagerInfo);
                            addNodeOperation.SetInclusionControllerInitiateParameters(nodeIdToInclude);

                            var setupNodeLifelineTask = new SetupNodeLifelineTask(_securityManagerInfo.Network);
                            setupNodeLifelineTask.NodeId            = _securityManagerInfo.Network.NodeId;
                            setupNodeLifelineTask.SucNodeId         = _securityManagerInfo.Network.NodeId;
                            setupNodeLifelineTask.TargetNodeId      = nodeIdToInclude;
                            setupNodeLifelineTask.CompletedCallback = OnNodeInfoCompleted;

                            var serialGroup = new ActionSerialGroup(OnInitiateFlowActionCompleted, isVirtualNodeOperation,
                                                                    new RequestNodeInfoOperation(nodeIdToInclude)
                            {
                                SubstituteSettings = new SubstituteSettings(SubstituteFlags.DenySecurity, 0)
                            },
                                                                    addNodeOperation, requestDataStep2, setupNodeLifelineTask, sendDataComplete);
                            serialGroup.ActionUnitStop = new ActionUnit(sendDataRejectComplete);
                            //hack
                            serialGroup.Token.Result      = new AddRemoveNodeResult();
                            serialGroup.CompletedCallback = OnS2SerialGroupCompleted;

                            if (_inclusionControllerStatusUpdateCallback != null)
                            {
                                _inclusionControllerStatusUpdateCallback(serialGroup.Token, false);
                            }
                            ou.SetNextActionItems(serialGroup);
                        }
                    }
                    else if (initiateCommand.stepId == S0_INCLUSION)
                    {
                        //only if asked from SIS
                        if (_securityManagerInfo.Network.SucNodeId == nodeId)
                        {
                            InclusionController.Complete sendDataComplete = null;
                            //Start S0
                            nodeIdToInclude = initiateCommand.nodeId;

                            if (_securityManagerInfo.Network.HasSecurityScheme(SecuritySchemes.S0))
                            {
                                sendDataComplete = new InclusionController.Complete(nodeId, TxOptions);
                                sendDataComplete.SetCommandParameters(STEP_OK, S0_INCLUSION);

                                var addNodeOperation = new AddNodeS0Operation(_securityManagerInfo);
                                addNodeOperation.SetInclusionControllerInitiateParameters(nodeIdToInclude);

                                var nodeInfoOperation = new RequestNodeInfoOperation(nodeIdToInclude);
                                nodeInfoOperation.CompletedCallback = OnNodeInfoCompleted;

                                var serialGroup = new ActionSerialGroup(new RequestNodeInfoOperation(nodeIdToInclude)
                                {
                                    SubstituteSettings = new SubstituteSettings(SubstituteFlags.DenySecurity, 0)
                                },
                                                                        addNodeOperation, nodeInfoOperation, sendDataComplete);

                                //hack
                                serialGroup.Token.Result = new AddRemoveNodeResult();

                                ou.SetNextActionItems(serialGroup);
                            }
                            else
                            {
                                sendDataComplete = new InclusionController.Complete(nodeId, TxOptions);
                                sendDataComplete.SetCommandParameters(STEP_NOT_SUPPORTED, S0_INCLUSION);
                                ou.SetNextActionItems(sendDataComplete);
                            }
                        }
                    }
                }
                else if (command[1] == COMMAND_CLASS_INCLUSION_CONTROLLER.COMPLETE.ID)
                {
                }
            }
        }
Ejemplo n.º 2
0
        public RequestNodeInfoSecureTask(SecurityManagerInfo securityManagerInfo, RequestNodeInfoOperation action, bool isInclusionTask)
        {
            _allowFailed         = true;
            _securityManagerInfo = securityManagerInfo;
            _nodeInfo            = action;
            _isInclusionTask     = isInclusionTask;

            var tm = CMD_SUPPORTED;

            if (securityManagerInfo.Network.IsFlirs(_nodeInfo.NodeId)) //skip only for ENTRY
            {
                tm = CMD_SUPPORTED_FLIRS;
            }

            _delayBeforeStart = new DelayOperation(START_DELAY);

            _supportedS0 = new RequestDataExOperation(0, 0,
                                                      new COMMAND_CLASS_SECURITY.SECURITY_COMMANDS_SUPPORTED_GET(), _txOptions,
                                                      TransmitSecurityOptions.S2_TXOPTION_VERIFY_DELIVERY, SecuritySchemes.S0, TransmitOptions2.NONE,
                                                      COMMAND_CLASS_SECURITY.ID, COMMAND_CLASS_SECURITY.SECURITY_COMMANDS_SUPPORTED_REPORT.ID, tm);

            _supportedS2_ACCESS = new RequestDataExOperation(0, 0,
                                                             new COMMAND_CLASS_SECURITY_2.SECURITY_2_COMMANDS_SUPPORTED_GET(), _txOptions,
                                                             TransmitSecurityOptions.S2_TXOPTION_VERIFY_DELIVERY, SecuritySchemes.S2_ACCESS, TransmitOptions2.NONE,
                                                             COMMAND_CLASS_SECURITY_2.ID, COMMAND_CLASS_SECURITY_2.SECURITY_2_COMMANDS_SUPPORTED_REPORT.ID, tm);

            _supportedS2_AUTHENTICATED = new RequestDataExOperation(0, 0,
                                                                    new COMMAND_CLASS_SECURITY_2.SECURITY_2_COMMANDS_SUPPORTED_GET(), _txOptions,
                                                                    TransmitSecurityOptions.S2_TXOPTION_VERIFY_DELIVERY, SecuritySchemes.S2_AUTHENTICATED, TransmitOptions2.NONE,
                                                                    COMMAND_CLASS_SECURITY_2.ID, COMMAND_CLASS_SECURITY_2.SECURITY_2_COMMANDS_SUPPORTED_REPORT.ID, tm);

            _supportedS2_UNAUTHENTICATED = new RequestDataExOperation(0, 0,
                                                                      new COMMAND_CLASS_SECURITY_2.SECURITY_2_COMMANDS_SUPPORTED_GET(), _txOptions,
                                                                      TransmitSecurityOptions.S2_TXOPTION_VERIFY_DELIVERY, SecuritySchemes.S2_UNAUTHENTICATED, TransmitOptions2.NONE,
                                                                      COMMAND_CLASS_SECURITY_2.ID, COMMAND_CLASS_SECURITY_2.SECURITY_2_COMMANDS_SUPPORTED_REPORT.ID, tm);

            List <ActionBase> list = new List <ActionBase>();

            list.Add(_delayBeforeStart);
            list.Add(_nodeInfo);
            if (_securityManagerInfo.Network.HasSecurityScheme(SecuritySchemeSet.ALLS2))
            {
                if (_securityManagerInfo.Network.IsSecuritySchemesSpecified(_nodeInfo.NodeId))
                {
                    if (_securityManagerInfo.Network.HasSecurityScheme(SecuritySchemes.S2_ACCESS))
                    {
                        if (!_isInclusionTask || _securityManagerInfo.Network.HasSecurityScheme(_nodeInfo.NodeId, SecuritySchemes.S2_ACCESS))
                        {
                            list.Add(_supportedS2_ACCESS);
                        }
                    }
                    if (_securityManagerInfo.Network.HasSecurityScheme(SecuritySchemes.S2_AUTHENTICATED))
                    {
                        if (!_isInclusionTask || _securityManagerInfo.Network.HasSecurityScheme(_nodeInfo.NodeId, SecuritySchemes.S2_AUTHENTICATED))
                        {
                            list.Add(_supportedS2_AUTHENTICATED);
                        }
                    }
                    if (_securityManagerInfo.Network.HasSecurityScheme(SecuritySchemes.S2_UNAUTHENTICATED))
                    {
                        if (!_isInclusionTask || _securityManagerInfo.Network.HasSecurityScheme(_nodeInfo.NodeId, SecuritySchemes.S2_UNAUTHENTICATED))
                        {
                            list.Add(_supportedS2_UNAUTHENTICATED);
                        }
                    }
                    if (_securityManagerInfo.Network.HasSecurityScheme(SecuritySchemes.S0))
                    {
                        if (!_isInclusionTask || _securityManagerInfo.Network.HasSecurityScheme(_nodeInfo.NodeId, SecuritySchemes.S0))
                        {
                            if (!list.Contains(_supportedS0))
                            {
                                list.Add(_supportedS0);
                            }
                        }
                    }
                }
                else
                {
                    if (_securityManagerInfo.Network.HasSecurityScheme(SecuritySchemes.S2_ACCESS))
                    {
                        list.Add(_supportedS2_ACCESS);
                    }
                    if (_securityManagerInfo.Network.HasSecurityScheme(SecuritySchemes.S2_AUTHENTICATED))
                    {
                        list.Add(_supportedS2_AUTHENTICATED);
                    }
                    if (_securityManagerInfo.Network.HasSecurityScheme(SecuritySchemes.S2_UNAUTHENTICATED))
                    {
                        list.Add(_supportedS2_UNAUTHENTICATED);
                    }
                }
            }
            if (_securityManagerInfo.Network.HasSecurityScheme(SecuritySchemes.S0))
            {
                if (_securityManagerInfo.Network.IsSecuritySchemesSpecified(_nodeInfo.NodeId))
                {
                    if (_securityManagerInfo.Network.HasSecurityScheme(_nodeInfo.NodeId, SecuritySchemes.S0) &&
                        !_securityManagerInfo.Network.HasSecurityScheme(_nodeInfo.NodeId, SecuritySchemeSet.ALLS2))
                    {
                        if (!list.Contains(_supportedS0))
                        {
                            list.Add(_supportedS0);
                        }
                    }
                }
                else
                {
                    if (!list.Contains(_supportedS0))
                    {
                        list.Add(_supportedS0);
                    }
                }
            }

            Actions = list.ToArray();
        }