UPnP Failing with CETON TV Tuner cards

Oct 12, 2012 at 3:32 AM

Some of the folks who are using CETON TV Tuner cards are seeing a systems failure on teh card when the UPnP code is used.

 

I suspect this has something to do with the fact that CETON TV Tuner cards are installed a network device on the computer. Somehow the UPnP enable code is messing with teh card and rendering it useless.

Is there some way to figure out which are the real network cards and limit the enabling to only those cards?

Here is code i'm using to enable UPnP.

        /// <summary>
        /// Enabled NAT Forwarding on all UPnP devices on the network (and opens Firewall) for the specified port on the local machine
        /// </summary>
        /// <param name="onPort">Port number to map</param>
        /// <param name="verbose">Write detailed logs</param>
        public static void EnableUPnP(int onPort, bool verbose)
        {
            try
            {
                bool searchCompleted;

                if (verbose)
                    Log.AppLog.WriteEntry("UPnP", "Enabling Firewall for UPnP", Log.LogEntryType.Debug, true);

                // Enable windows firewall for allowing UPnP (if it's not already enabled)
                if (WindowsFirewall.UPnPPortsOpen != WindowsFirewall.Status.Open)
                {
                    WindowsFirewall.UPnPPortsOpen = WindowsFirewall.Status.Open;
                    if (WindowsFirewall.UPnPPortsOpen != WindowsFirewall.Status.Open)
                    {
                        Log.AppLog.WriteEntry("UPnP", "Unable to open Windows Firewall UPnP ports, please MANUALLY ALLOW/ENABLE the UPnP ports (TCP:2869 and UDP:1900)", Log.LogEntryType.Warning, true);
                        Log.AppLog.WriteEntry("UPnP", "Windows Firewall Status -> " + WindowsFirewall.UPnPPortsOpen.ToString(), Log.LogEntryType.Warning, true);
                    }
                }

                if (verbose)
                    Log.AppLog.WriteEntry("UPnP", "Searching for UPnP devices", Log.LogEntryType.Debug, true);

                // Search for UPnP devices
                Services lsServices = Discovery.FindServices(null, int.MaxValue, int.MaxValue, out searchCompleted, AddressFamilyFlags.IPvBoth, true);

                // Check for an incomplete search
                if (!searchCompleted)
                {
                    Log.AppLog.WriteEntry("UPnP", "UPnP search incomplete, retrying again", Log.LogEntryType.Warning, true);
                    lsServices = Discovery.FindServices(null, int.MaxValue, int.MaxValue, out searchCompleted, AddressFamilyFlags.IPvBoth, false);

                    if (!searchCompleted)
                        Log.AppLog.WriteEntry("UPnP", "UPnP search incomplete, UPnP enablement may not succeed", Log.LogEntryType.Warning, true);
                }

                foreach (ManagedUPnP.Service lsService in lsServices)
                {
                    ServiceDescription lsdDesc = lsService.Description();
                    if (lsdDesc.Actions.ContainsKey("AddPortMapping")) // Check to see if is a WAN UPnP device that supports Port Mappings, if we so need to enable Port Forwarding for each such device
                    {
                        object[] inParams;

                        try
                        {
                            inParams = new object[] { "", onPort, "tcp" };
                            lsService.InvokeAction("DeletePortMapping", inParams); // Delete the port mapping (we will create a fresh one later)
                        }
                        catch (Exception)
                        {
                        }

                        // For the UPnP device, add a port mapping for each network interface adapter/IPaddress that can connect to the device
                        foreach (IPAddress ifAddress in lsService.Device.AdapterIPAddresses)
                        {
                            try
                            {
                                // For IPv6 addresses we need to remove the Interface Identifier from the string (%x at the end of the ip6 address)
                                if (verbose)
                                    Log.AppLog.WriteEntry("UPnP", "Adding Port Mapping to " + (ifAddress.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6 ? ifAddress.ToString().Substring(0, ifAddress.ToString().IndexOf("%")) : ifAddress.ToString()) + " Port " + onPort.ToString(), Log.LogEntryType.Debug, true);

                                // Now we add the port mapping for the current MCEBuddy server
                                inParams = new object[] { "", onPort, "tcp", onPort, (ifAddress.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6 ? ifAddress.ToString().Substring(0, ifAddress.ToString().IndexOf("%")) : ifAddress.ToString()), true, "mcebuddy2x", 0 };
                                lsService.InvokeAction("AddPortMapping", inParams);
                            }
                            catch (Exception e)
                            {
                                if (verbose)
                                {
                                    Log.AppLog.WriteEntry("UPnP", "Unable to Add Port Mapping to " + lsService.Device.RootHostName, Log.LogEntryType.Warning, true);
                                    Log.AppLog.WriteEntry("UPnP", "Add Error " + e.ToString(), Log.LogEntryType.Warning, true);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Log.AppLog.WriteEntry("UPnP", "Error trying to enable UPnP -> " + e.ToString(), Log.LogEntryType.Warning, true);
            }
        }

Coordinator
Oct 13, 2012 at 1:36 AM
Edited Oct 13, 2012 at 1:37 AM

rboy1,

 

"I suspect this has something to do with the fact that CETON TV Tuner cards are installed a network device on the computer. Somehow the UPnP enable code is messing with teh card and rendering it useless."

What do you mean by this, I have never used a CETON TV Tuner Card so im not sure what you mean, are they installed as a NIC device for some reason?

 

"Is there some way to figure out which are the real network cards and limit the enabling to only those cards?"

Quite possibly, but because I dont have  Ceton TV Tuner Card I have no idea how they are installed, you will need to give me more information on how the cards are installed into the windows subsystem?

 

If you could send me some screenshots of the driver information it might help.

 

Cheers,

Aaron

Oct 13, 2012 at 5:03 AM
Yes it looks like the device is installed a NIC, unfortunately I don't have access to one either. I have a couple of users who are using it and reporting issues when UPnP is enabled.
Any thoughts on how we can go about debugging this?
Coordinator
Oct 13, 2012 at 7:08 AM
Edited Oct 13, 2012 at 7:09 AM

You will need to investigate what is actually causing the problem first, ie, is it the device discovery that causes the problem or is it the call to the Action to map the ports which causes the problem.

It may be that the drivers for the NIC on the CETON TV are really badly designed and dont like the broadcast message that gets sent over the network during discovery, if this is the case then there isnt anything you can do about it and any UPnP discovery would cause this problem.

However, it could be something that is software driven, so treat it like any other bug, perform isolation tests to determine the problem, ie, does it only do it if the card is on the same machine which is running the UPnP enabled software or does it do it on the network. Does it occur only after mapping the ports, if it does, does un-mapping the ports help the problem

So try to determine what part of the UPnP is causing the issues, however, the UPnP implementation adheres to all UPnP standards, so chances are it will be either be due to badly designed drivers for the NICs on the CETON TV cards or some other esoteric problem which would seem unrelated.

Once you find out the problem you MAY be able to circumvent it by checking the MAC address of the NIC and using the first two bytes (manufacturer ID) to identify any NICs made by CETON then excluding them somehow.

Whatever you do, you are probably going to need direct access to a PC with one of these devices installed.

Oct 23, 2012 at 1:30 PM

Some of the Folks over at Ceton are in touch with me. They are claiming that the tv tuner card is getting flooded with UPnP discovery packets which is causing the card to fail.

Did you check by any chance how many packets are send by he code (MCEBuddy calls this function every 10 minutes).

Coordinator
Oct 24, 2012 at 11:30 AM

This is purely controlled by the Microsoft UPnP EndPoint API, and according to the doco it will send exactly 3 requests per full device scan, about 4 seconds apart, this is the standard for UPnP device discovery according to www.upnp.org.