//struct EchoRequest
        //{
        //    public UInt32 DestinationIPAddress;
        //    public UInt16 Identifier;
        //    public UInt16 SequenceNumber;
        //    public byte[] Data;

        //    AutoResetEvent _responseReceivedEvent;

        //    public EchoRequest(UInt32 destinationIPAddress, UInt16 identifier, UInt16 sequenceNumber, byte[] data)
        //    {
        //        this.DestinationIPAddress = destinationIPAddress;
        //        this.Identifier = identifier;
        //        this.SequenceNumber = sequenceNumber;
        //        this.Data = data;

        //        _responseReceivedEvent = new AutoResetEvent(false);
        //    }

        //    public bool WaitForResponse(Int32 millisecondsTimeout)
        //    {
        //        return _responseReceivedEvent.WaitOne(millisecondsTimeout, false);
        //    }

        //    internal void SetResponseReceived()
        //    {
        //        _responseReceivedEvent.Set();
        //    }
        //}
        //System.Collections.ArrayList _outstandingEchoRequests = new System.Collections.ArrayList();
        //object _outstandingEchoRequestsLock = new object();
        //UInt16 _nextEchoRequestSequenceNumber = 0;

        internal ICMPv4Handler(IPv4Layer ipv4Layer)
        {
            _ipv4Layer = ipv4Layer;

            // start our "send ICMP messages transmission" thread
            _sendIcmpMessagesInBackgroundQueue  = new System.Collections.Queue();
            _sendIcmpMessagesInBackgroundThread = new Thread(SendIcmpMessagesThread);
            _sendIcmpMessagesInBackgroundThread.Start();
        }
        public DnsResolver(IPv4Layer ipv4Layer)
        {
            _ipv4Layer = ipv4Layer;

            // create our DNS cache
            _dnsCache = new System.Collections.Hashtable();

            // enable our "cleanup DNS cache" timer (fired every 600 seconds)
            _cleanupDnsCacheTimer = new Timer(CleanupDnsCache, null, 600000, 600000);
        }
예제 #3
0
        const Int32 RECEIVE_BUFFER_MIN_SIZE = 536; /* 536 bytes is the minimum receive buffer size allowed by UDP spec */

        public UdpSocket(IPv4Layer ipv4Layer, int handle)
            : base(handle)
        {
            // save a reference to our IPv4Layer; we'll use this to send IPv4 frames
            _ipv4Layer = ipv4Layer;

            base._protocolType = IPv4Layer.ProtocolType.Udp;

            InitializeReceivedPacketBuffer(_receivedPacketBuffer);
        }
예제 #4
0
        const Int32 RECEIVE_BUFFER_MIN_SIZE             = 536; /* 536 bytes is the minimum receive buffer size allowed by UDP spec */

        public UdpSocket(IPv4Layer ipv4Layer, int handle)
            : base(handle)
        {
            // save a reference to our IPv4Layer; we'll use this to send IPv4 frames
            _ipv4Layer = ipv4Layer;

            base._protocolType = IPv4Layer.ProtocolType.Udp;

            InitializeReceivedPacketBuffer(_receivedPacketBuffer);
        }
        public void Dispose()
        {
            if (_isDisposed)
            {
                return;
            }

            _isDisposed = true;

            if (_dnsCache != null)
            {
                _dnsCache.Clear();
            }
            _cleanupDnsCacheTimer.Dispose();

            _ipv4Layer = null;
        }
예제 #6
0
        public void Dispose()
        {
            _ipv4Layer = null;

            _tcpHeaderBuffer = null;
            _tcpHeaderBufferLockObject = null;

            _tcpPseudoHeaderBuffer = null;
            _tcpPseudoHeaderBufferLockObject = null;

            _checksumBufferArray = null;
            _checksumOffsetArray = null;
            _checksumCountArray = null;

            _bufferArray = null;
            _indexArray = null;
            _countArray = null;
        }
예제 #7
0
        public void Dispose()
        {
            _ipv4Layer = null;

            _tcpHeaderBuffer           = null;
            _tcpHeaderBufferLockObject = null;

            _tcpPseudoHeaderBuffer           = null;
            _tcpPseudoHeaderBufferLockObject = null;

            _checksumBufferArray = null;
            _checksumOffsetArray = null;
            _checksumCountArray  = null;

            _bufferArray = null;
            _indexArray  = null;
            _countArray  = null;
        }
        public void Dispose()
        {
            if (_isDisposed)
            {
                return;
            }

            _isDisposed = true;

            // shut down our icmp messages transmission thread
            if (_sendIcmpMessagesInBackgroundEvent != null)
            {
                _sendIcmpMessagesInBackgroundEvent.Set();
                _sendIcmpMessagesInBackgroundEvent = null;
            }

            _ipv4Layer = null;

            _icmpFrameBuffer     = null;
            _icmpFrameBufferLock = null;

            //if (_outstandingEchoRequests != null)
            //{
            //    for (int i = 0; i < _outstandingEchoRequests.Count; i++)
            //    {
            //        if (_outstandingEchoRequests[i] != null)
            //        {
            //            ((IDisposable)_outstandingEchoRequests[i]).Dispose();
            //        }
            //    }
            //}
            //_outstandingEchoRequests = null;
            //_outstandingEchoRequestsLock = null;

            _bufferArray = null;
            _indexArray  = null;
            _countArray  = null;

            _checksumBufferArray = null;
            _checksumOffsetArray = null;
            _checksumCountArray  = null;
            _checksumLock        = null;
        }
예제 #9
0
        public override void Dispose()
        {
            base.Dispose();

            _ipv4Layer = null;

            _udpHeaderBuffer = null;
            _udpHeaderBufferLockObject = null;

            _udpPseudoHeaderBuffer = null;
            _udpPseudoHeaderBufferLockObject = null;

            _checksumBufferArray = null;
            _checksumOffsetArray = null;
            _checksumCountArray = null;

            _bufferArray = null;
            _indexArray = null;
            _countArray = null;
        }
예제 #10
0
        public override void Dispose()
        {
            base.Dispose();

            _ipv4Layer = null;

            _udpHeaderBuffer           = null;
            _udpHeaderBufferLockObject = null;

            _udpPseudoHeaderBuffer           = null;
            _udpPseudoHeaderBufferLockObject = null;

            _checksumBufferArray = null;
            _checksumOffsetArray = null;
            _checksumCountArray  = null;

            _bufferArray = null;
            _indexArray  = null;
            _countArray  = null;
        }
예제 #11
0
        static internal void Initialize()
        {
            lock (_initializeMethodSyncObject)
            {
                if (_isInitialized)
                {
                    return;
                }

#if CC3100
                Type socketNativeType = Type.GetType("Netduino.IP.LinkLayers.CC3100SocketNative, Netduino.IP.LinkLayers.CC3100");
                System.Reflection.MethodInfo initializeMethod = socketNativeType.GetMethod("Initialize", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static);
                initializeMethod.Invoke(null, new object[] { });
#else
                // create the appropriate link layer object
                Type linkLayerType = Type.GetType(LINK_LAYER_BASE_TYPENAME);
                System.Reflection.ConstructorInfo linkLayerConstructor = linkLayerType.GetConstructor(new Type[] { typeof(SPI.SPI_module), typeof(Cpu.Pin), typeof(Cpu.Pin), typeof(Cpu.Pin), typeof(Cpu.Pin) });
#if NETDUINOIP_AX88796C
                ILinkLayer linkLayer = (ILinkLayer)linkLayerConstructor.Invoke(new object[] { SPI.SPI_module.SPI2 /* spiBusID */, (Cpu.Pin) 0x28 /* csPinID */, (Cpu.Pin) 0x04 /* intPinID */, (Cpu.Pin) 0x12 /* resetPinID */, (Cpu.Pin) 0x44 /* wakeupPinID */ });
#elif NETDUINOIP_ENC28J60
                ILinkLayer linkLayer = (ILinkLayer)linkLayerConstructor.Invoke(new object[] { SPI.SPI_module.SPI2 /* spiBusID */, (Cpu.Pin) 0x28 /* csPinID */, (Cpu.Pin) 0x04 /* intPinID */, (Cpu.Pin) 0x32 /* resetPinID */, Cpu.Pin.GPIO_NONE /* wakeupPinID */ });
#elif NETDUINOIP_CC3100
#endif
                // retrieve MAC address from the config sector
                object networkInterface = Netduino.IP.Interop.NetworkInterface.GetNetworkInterface(0);
                byte[] physicalAddress  = (byte[])networkInterface.GetType().GetMethod("get_PhysicalAddress").Invoke(networkInterface, new object[] { });
                linkLayer.SetMacAddress(physicalAddress);

                // create EthernetInterface instance
                _ethernetInterface = new Netduino.IP.EthernetInterface(linkLayer);
                // create our IPv4Layer instance
                _ipv4Layer = new IPv4Layer(_ethernetInterface);

                // start up our link layer
                linkLayer.Start();
#endif

                _isInitialized = true;
            }
        }
        static internal void Initialize()
        {
            lock (_initializeMethodSyncObject)
            {
                if (_isInitialized) return;

#if CC3100
                Type socketNativeType = Type.GetType("Netduino.IP.LinkLayers.CC3100SocketNative, Netduino.IP.LinkLayers.CC3100");
                System.Reflection.MethodInfo initializeMethod = socketNativeType.GetMethod("Initialize", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static);
                initializeMethod.Invoke(null, new object[] { });
#else
                // create the appropriate link layer object
                Type linkLayerType = Type.GetType(LINK_LAYER_BASE_TYPENAME);
                System.Reflection.ConstructorInfo linkLayerConstructor = linkLayerType.GetConstructor(new Type[] { typeof(SPI.SPI_module), typeof(Cpu.Pin), typeof(Cpu.Pin), typeof(Cpu.Pin), typeof(Cpu.Pin) });
#if NETDUINOIP_AX88796C
                ILinkLayer linkLayer = (ILinkLayer)linkLayerConstructor.Invoke(new object[] { SPI.SPI_module.SPI2  /* spiBusID */, (Cpu.Pin)0x28 /* csPinID */, (Cpu.Pin)0x04 /* intPinID */, (Cpu.Pin)0x12 /* resetPinID */, (Cpu.Pin)0x44 /* wakeupPinID */ });
#elif NETDUINOIP_ENC28J60
                ILinkLayer linkLayer = (ILinkLayer)linkLayerConstructor.Invoke(new object[] { SPI.SPI_module.SPI2  /* spiBusID */, (Cpu.Pin)0x28 /* csPinID */, (Cpu.Pin)0x04 /* intPinID */, (Cpu.Pin)0x32 /* resetPinID */, Cpu.Pin.GPIO_NONE /* wakeupPinID */ });
#elif NETDUINOIP_CC3100
#endif
                // retrieve MAC address from the config sector
                object networkInterface = Netduino.IP.Interop.NetworkInterface.GetNetworkInterface(0);
                byte[] physicalAddress = (byte[])networkInterface.GetType().GetMethod("get_PhysicalAddress").Invoke(networkInterface, new object[] { });
                linkLayer.SetMacAddress(physicalAddress);

                // create EthernetInterface instance
                _ethernetInterface = new Netduino.IP.EthernetInterface(linkLayer);
                // create our IPv4Layer instance
                _ipv4Layer = new IPv4Layer(_ethernetInterface);

                // start up our link layer
                linkLayer.Start();
#endif

                _isInitialized = true;
            }
        }
예제 #13
0
        public DHCPv4Client(IPv4Layer ipv4Layer)
        {
            _ipv4Layer = ipv4Layer;
            _physicalAddress = ipv4Layer.GetPhysicalAddressAsUInt64();

            // create DHCP state machine thread
            _dhcpStateMachineThread = new Thread(DhcpStateMachine);
            _dhcpStateMachineThread.Start();

            _leaseUpdateTimer = new Timer(LeaseUpdateTimerCallback, null, System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite);

            // wire up LinkStateChanged event
            _ipv4Layer.LinkStateChanged += _ipv4Layer_LinkStateChanged;
        }
예제 #14
0
 public TcpHandler(IPv4Layer ipv4Layer)
 {
     // save a reference to our IPv4Layer; we'll use this to send IPv4 frames
     _ipv4Layer = ipv4Layer;
 }
예제 #15
0
        public void Dispose()
        {
            if (_isDisposed) return;

            _isDisposed = true;

            if (_dnsCache != null)
                _dnsCache.Clear();
            _cleanupDnsCacheTimer.Dispose();

            _ipv4Layer = null;
        }
예제 #16
0
        public DnsResolver(IPv4Layer ipv4Layer)
        {
            _ipv4Layer = ipv4Layer;

            // create our DNS cache
            _dnsCache = new System.Collections.Hashtable();

            // enable our "cleanup DNS cache" timer (fired every 600 seconds)
            _cleanupDnsCacheTimer = new Timer(CleanupDnsCache, null, 600000, 600000); 
        }
예제 #17
0
        public void Dispose()
        {
            if (_isDisposed) return;

            _isDisposed = true;

            // shut down our icmp messages transmission thread
            if (_sendIcmpMessagesInBackgroundEvent != null)
            {
                _sendIcmpMessagesInBackgroundEvent.Set();
                _sendIcmpMessagesInBackgroundEvent = null;
            }

            _ipv4Layer = null;

            _icmpFrameBuffer = null;
            _icmpFrameBufferLock = null;

            //if (_outstandingEchoRequests != null)
            //{
            //    for (int i = 0; i < _outstandingEchoRequests.Count; i++)
            //    {
            //        if (_outstandingEchoRequests[i] != null)
            //        {
            //            ((IDisposable)_outstandingEchoRequests[i]).Dispose();
            //        }
            //    }
            //}
            //_outstandingEchoRequests = null;
            //_outstandingEchoRequestsLock = null;

            _bufferArray = null;
            _indexArray = null;
            _countArray = null;

            _checksumBufferArray = null;
            _checksumOffsetArray = null;
            _checksumCountArray = null;
            _checksumLock = null;
        }
예제 #18
0
        //struct EchoRequest
        //{
        //    public UInt32 DestinationIPAddress;
        //    public UInt16 Identifier;
        //    public UInt16 SequenceNumber;
        //    public byte[] Data;

        //    AutoResetEvent _responseReceivedEvent;

        //    public EchoRequest(UInt32 destinationIPAddress, UInt16 identifier, UInt16 sequenceNumber, byte[] data)
        //    {
        //        this.DestinationIPAddress = destinationIPAddress;
        //        this.Identifier = identifier;
        //        this.SequenceNumber = sequenceNumber;
        //        this.Data = data;

        //        _responseReceivedEvent = new AutoResetEvent(false);
        //    }

        //    public bool WaitForResponse(Int32 millisecondsTimeout)
        //    {
        //        return _responseReceivedEvent.WaitOne(millisecondsTimeout, false);
        //    }

        //    internal void SetResponseReceived()
        //    {
        //        _responseReceivedEvent.Set();
        //    }
        //}
        //System.Collections.ArrayList _outstandingEchoRequests = new System.Collections.ArrayList();
        //object _outstandingEchoRequestsLock = new object();
        //UInt16 _nextEchoRequestSequenceNumber = 0;

        internal ICMPv4Handler(IPv4Layer ipv4Layer)
        {
            _ipv4Layer = ipv4Layer;

            // start our "send ICMP messages transmission" thread
            _sendIcmpMessagesInBackgroundQueue = new System.Collections.Queue();
            _sendIcmpMessagesInBackgroundThread = new Thread(SendIcmpMessagesThread);
            _sendIcmpMessagesInBackgroundThread.Start();
        }
예제 #19
0
        public void Dispose()
        {
            if (_isDisposed) return;

            _isDisposed = true;

            if (_leaseUpdateTimer != null)
                _leaseUpdateTimer.Dispose();

            // shut down our state machine thread
            if (_dhcpStateMachineEvent != null)
            {
                _dhcpStateMachineEvent.Set();
                _dhcpStateMachineEvent = null;
            }

            //_cleanupArpCacheTimer.Dispose();

            try
            {
                _ipv4Layer.LinkStateChanged -= _ipv4Layer_LinkStateChanged;
            }
            catch { }
            _ipv4Layer = null;

            //_bufferArray = null;
            //_indexArray = null;
            //_countArray = null;

            _randomGenerator = null;

            // unwire all event handlers
            IpConfigChanged = null;
            DnsConfigChanged = null;
        }
예제 #20
0
 public TcpHandler(IPv4Layer ipv4Layer)
 {
     // save a reference to our IPv4Layer; we'll use this to send IPv4 frames
     _ipv4Layer = ipv4Layer;
 }