예제 #1
0
        private void HandleAddressReply(
            MacAddress srcAddr,
            MacAddress dstAddr,
            ref Frame sdu)
        {
            Message.AddressReply arep = new Message.AddressReply();
            if (arep.ReadFromFrame(sdu))
            {
                if (dstAddr.Mode == MacAddressingMode.ExtendedAddress && dstAddr.ExtendedAddress == _addrExt)
                {
                    // address is for us
                    if (_addrShort == cUnallocatedShortAddr)
                    {
                        _addrShort = arep.ShortAddr;

                        PibValue value = new PibValue();
                        value.Int = _addrShort;
                        _mac.SetRequest(PibAttribute.macShortAddress, 0, value, null);

                        _getAddressEvent.Set();

                        SetDiscoveryTimer(arep.DiscoveryInterval);
                    }
                }
                else
                {
                    if (arep.HopsLeft > 0)
                    {
                        arep.HopsLeft--;
                        Frame frame = Frame.GetFrame(_macHeader, Message.AddressRequest.cLength + _macTailer);
                        if (arep.WriteToFrame(frame))
                        {
                            if (arep.BrokerAddr == _addrShort)
                            {
                                // we are the broker
                                MacDataRequest(arep.DeviceAddr, ref frame);
                            }
                            else
                            {
                                // forward to broker
                                _routingTable.DataRequest(arep.BrokerAddr, ref frame, 0, null, true);
                            }
                        }

                        Frame.Release(ref frame);
                    }
                }
            }
        }
예제 #2
0
        private void HandleAddressRequest(
            MacAddress srcAddr,
            MacAddress dstAddr,
            ref Frame sdu)
        {
            Message.AddressRequest areq = new Message.AddressRequest();
            if (areq.ReadFromFrame(sdu))
            {
                if (_isAddrServer)
                {
                    // process message as address server
                    Message.AddressReply arep = new Message.AddressReply();
                    if (_addrServer.AllocateAddress(areq.DeviceAddr, out arep.ShortAddr))
                    {
                        // send address
                        arep.HopsLeft = cDefaultHopLimit;
                        arep.BrokerAddr = areq.BrokerAddr;
                        arep.DeviceAddr = areq.DeviceAddr;
                        arep.DiscoveryInterval = _addrServer.TimeInterval;

                        Frame frame = Frame.GetFrame(_macHeader, Message.AddressReply.cLength + _macTailer);
                        if (arep.WriteToFrame(frame))
                        {
                            if (areq.BrokerAddr == cCoordinatorShortAddr)
                            {
                                // direct response
                                if (srcAddr.Mode == MacAddressingMode.ExtendedAddress)
                                {
                                    MacDataRequest(srcAddr.ExtendedAddress, ref frame);
                                }
                            }
                            else
                            {
                                // send to broker
                                _routingTable.DataRequest(areq.BrokerAddr, ref frame, 0, null, true);
                            }
                        }

                        Frame.Release(ref frame);
                    }
                }
                else
                {
                    // forward towards address server
                    if (areq.HopsLeft > 0)
                    {
                        areq.HopsLeft--;
                        if (areq.BrokerAddr == cCoordinatorShortAddr)
                        {
                            areq.BrokerAddr = _addrShort;
                        }

                        Frame frame = Frame.GetFrame(_macHeader, Message.AddressRequest.cLength + _macTailer);
                        if (areq.WriteToFrame(frame))
                        {
                            // send to address server
                            _routingTable.DataRequest(cCoordinatorShortAddr, ref frame, 0, null, true);
                        }

                        Frame.Release(ref frame);
                    }
                }
            }
        }