Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Update:UDP Broadcast Send/Receive fixed for next release


  • Please log in to reply
11 replies to this topic

#1 Valkyrie-MT

Valkyrie-MT

    Advanced Member

  • Members
  • PipPipPip
  • 315 posts
  • LocationIndiana, USA

Posted 07 August 2011 - 08:25 PM

Update2: Codeplex issue is now closed and I am very optimistic that we've fixed it this time as I have a working build right now.
Update: Vote here - http://netmf.codeple...m/workitem/1166

We are very close with the recent changes in the Framework, but UDP Broadcast is still not working. Please vote so we can get this resolved before .NET Microframework 4.2 gets released!



I just Tested RC1 and receiving UDP Broadcasts (needed by NetBios) still doesn't work. I wrote my own simplified test to just listen for UDP Broadcasts. Below is a link to a video that shows the Netbios messages in Wireshark and the test code that shows how the Emulator works and the NetduinoPlus does not. A few things to notice in the video, the Netduino network lights flash showing that it is getting the Netbios messages. Also, you can see in Wireshark that the browser is emitting the Netbios name broadcasts. Netduino just seems to ignore them. But, if you send a directed message to the N+, it works (not shown). So Listening for UDP messages from a specific IP works, but Listening for UDP Broadcast messages is received and ignored by the firmware.

Here is the video (I recommend full-screen 720P viewing):
http://www.youtube.com/watch?v=0z28CSwE6rU

Here is the Test code:
public class Program
    {
        public static void Main()
        {
            // While this is running on the NetduinoPlus, navigate to http://netduino (on a machine on the same subnet)

            using (var serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp))
            {
                EndPoint remoteEndPoint = new IPEndPoint(IPAddress.Any, 137);
                serverSocket.Bind(remoteEndPoint);

                while (true)
                {
                    if (serverSocket.Poll(-1, SelectMode.SelectRead))
                    {
                        var inBuffer = new byte[serverSocket.Available];
                        int count = serverSocket.ReceiveFrom(inBuffer, ref remoteEndPoint);

                        if (count > 0) Debug.Print("SUCCESS!  We see a Netbios name request! ");
                    }
                }
            }
        }
    }

Also, if you look in Wireshark, there are LLMNR (Link-Local Multicast Name Resolution) messages sent along-side the Netbios messages which might also allow for name resolution, but I don't believe UDP Multicast is supported in .NET MF. There are bits and pieces of multicast support in the API, but no obvious way to make it work.

-Valkyrie-MT

#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 07 August 2011 - 08:56 PM

Hi Valkyrie, We'll have to re-open the codeplex issue on this it seems. Can you send brodcast packets from the Netduino now? To other devices in your local network? Multicast: NETMF does technically support multicast at some level through IGMP...not sure how it works, but if I remember right it's too big so IGMP is not enabled on Netduino Plus. Chris

#3 Valkyrie-MT

Valkyrie-MT

    Advanced Member

  • Members
  • PipPipPip
  • 315 posts
  • LocationIndiana, USA

Posted 07 August 2011 - 09:54 PM

Can you send brodcast packets from the Netduino now?


No, Broadcast is not working either, as compared to the Emulator and verified with Wireshark.

Here is the code that works on the Emulator, but not on N+ v4.2RC1.

public class Program
    {
        public static void Main()
        {
            // Open Wireshark, then run this to see if the message "TEST" is broadcast

            using (var clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp))
            {
                IPHostEntry entry = Dns.GetHostEntry("192.168.1.255"); // This the address to local broadcast for me, may be different for others.  
                IPAddress ipAddress = entry.AddressList[0];
                IPEndPoint brodcastEndPoint = new IPEndPoint(ipAddress, 137);  
                
                clientSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, true); // Enable broadcast      

                clientSocket.SendTo(Encoding.UTF8.GetBytes("TEST"), brodcastEndPoint);
                // This actually generates a Malformed Netbios response from the router, but it does demonstrate UDP Broadcast.
            }
        }
    }

Wireshark output with Emulator running this broadcast test:
Posted Image

P.S. I didn't open the original codeplex issue, so I can't reopen it. I'll open a new one soon.

-Valkyrie-MT

#4 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 07 August 2011 - 10:04 PM

Hmm. We made sure that the BROADCAST option was set. Unless it's glitchy without ICMP, it should be working. We'll be posting the source code patch files online shortly too... Chris

#5 Valkyrie-MT

Valkyrie-MT

    Advanced Member

  • Members
  • PipPipPip
  • 315 posts
  • LocationIndiana, USA

Posted 09 August 2011 - 01:46 PM

New Codeplex issue: http://netmf.codeple...m/workitem/1166

#6 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 09 August 2011 - 03:59 PM

New Codeplex issue: http://netmf.codeple...m/workitem/1166

Thanks, Valkyrie.

If anyone else is having this issue, please vote for the bug.

#7 Valkyrie-MT

Valkyrie-MT

    Advanced Member

  • Members
  • PipPipPip
  • 315 posts
  • LocationIndiana, USA

Posted 15 August 2011 - 12:55 AM

Thanks, Valkyrie.

If anyone else is having this issue, please vote for the bug.


I think I figured out the problem. I'm still looking into it, but I think the settings in the opt.h file are blocking UDP Broadcast. I recommend that the opt.h be changed to look like this:

/**
 * IP_SOF_BROADCAST=1: Use the SOF_BROADCAST field to enable broadcast
 * filter per pcb on udp and raw send operations. To enable broadcast filter
 * on recv operations, you also have to set IP_SOF_BROADCAST_RECV=1.
 */
//#ifndef IP_SOF_BROADCAST
#define IP_SOF_BROADCAST                0  // Default is 1
//#endif

/**
 * IP_SOF_BROADCAST_RECV (requires IP_SOF_BROADCAST=1) enable the broadcast
 * filter on recv operations.
 */
//#ifndef IP_SOF_BROADCAST_RECV
#define IP_SOF_BROADCAST_RECV           0  // Default is 1
//#endif

It appears that the default values are 1 and have the effect of blocking broadcasts (aka. filtering broadcasts). I have tested this and one other change (already made by ZachLibby in 4.2) and it works. Both UDP Send and Receive. Once I can test this change in a 4.2 based firmware, I'll propose it back to as a change in codeplex.

Valkyrie-MT

#8 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 15 August 2011 - 05:06 AM

It appears that the default values are 1 and have the effect of blocking broadcasts (aka. filtering broadcasts). I have tested this and one other change (already made by ZachLibby in 4.2) and it works. Both UDP Send and Receive. Once I can test this change in a 4.2 based firmware, I'll propose it back to as a change in codeplex.

Very interesting. I thought these values were supposed to work the _other_ way (i.e. enable broadcast rather than disabling it). Hmm.

Thanks for the great detective work, Valkyrie-MT.

Chris

#9 Edward

Edward

    Advanced Member

  • Members
  • PipPipPip
  • 38 posts
  • LocationLondon, UK

Posted 15 August 2011 - 02:59 PM

I've reproduced this too while porting the framework for xAP home automation to the N+. So lookes like the define set to 1 enables a filter that stops broadcasts. FYI broadcast tx and rx do work on the address 255.255.255.255 but not the local subnet broadcast eg 192.168.1.255. No xAP without broadcast. Vote added. What I'm not clear on is if this is an issue for the MF team or Secret Labs. Not quite worked out where that division of responsibility falls.

#10 Valkyrie-MT

Valkyrie-MT

    Advanced Member

  • Members
  • PipPipPip
  • 315 posts
  • LocationIndiana, USA

Posted 15 August 2011 - 07:01 PM

After further review I now see the problem. I am using DHCP which automatically sets the broadcast filter option (SOF_BROADCAST) on the pcb. I will change the define for the broadcast filter from opt.h to 0 since there is no way to set this value from managed code for the pcb.


Woo hoo! Looks like ZachLibby agrees and the settings were the problem. This means we'll likely have UDP Broadcast working in the Release!

-Valkyrie-MT

#11 Edward

Edward

    Advanced Member

  • Members
  • PipPipPip
  • 38 posts
  • LocationLondon, UK

Posted 15 August 2011 - 07:34 PM

High five!

#12 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 15 August 2011 - 08:53 PM

Woo hoo! Looks like ZachLibby agrees and the settings were the problem. This means we'll likely have UDP Broadcast working in the Release!

We're going to build an RC2 firmware build for Netduino Plus. We just made these updates. Should be posted later this week :)

Chris




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.