alanmcgovern / Mono.Nat

UPNP and NAT-PMP port forwarding for .NET
https://github.com/mono/Mono.Nat
MIT License
160 stars 156 forks source link

Unknown message returned when deleting a mapping. #27

Open BaronGreenback opened 3 years ago

BaronGreenback commented 3 years ago

[2020-08-15 19:47:37.213 +01:00] [INF] [5] Mono.Nat.Upnp.UpnpNatDevice: uPnP Response: , <?xml version="1.0"?> </u:DeletePortMappingResponse></s:Body></s:Envelope>

[2020-08-15 19:47:37.220 +01:00] [ERR] [5] Mono.Nat.Upnp.ResponseMessage: Unknown message returned. Please send me back the following XML: <?xml version="1.0"?> </u:DeletePortMappingResponse></s:Body></s:Envelope>

BaronGreenback commented 3 years ago

Sorry!

alanmcgovern commented 3 years ago

Huh, bonkers!

Could you capture the whole set of requests/responses? The shape of the response is somewhat dependent on the shape of the request. I'll double check this anyway in case there's an obvious issue!

alanmcgovern commented 3 years ago

Ah it's actually an easy one - the response is invalid. This is a proper response. Please ignore the escaping in the string, i just pulled it straight from the debugger:

"<?xml version=\"1.0\"?>\r\n<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><s:Body><u:DeletePortMappingResponse xmlns:u=\"urn:schemas-upnp-org:service:WANIPConnection:1\"></u:DeletePortMappingResponse></s:Body></s:Envelope>\r\n"

The xml namespace for the 'DeletePortMappingResponse' element is supposed to be the service type. In my case it's WANIPConnection:1. Your device has a broken response and sets the namespace to DeletePortMapping. I'm not really sure how this should be handled. I'll have to review the spec and see if this is actually a feature of a newer version of the spec.

What is the service type for your device?

BaronGreenback commented 3 years ago

It's a real funny device - fibre dsl router with build in wifi.

Would be surprised as far as the response not being standard. It's ISP provided so will be as cheap as they come!

<?xml version="1.0" encoding="UTF-8"?>
<root xmlns="urn:schemas-upnp-org:device-1-0" configId="1337">
   <specVersion>
      <major>1</major>
      <minor>0</minor>
   </specVersion>
   <device>
      <deviceType>urn:schemas-upnp-org:device:InternetGatewayDevice:1</deviceType>
      <friendlyName>EE Smart Hub</friendlyName>
      <manufacturer>EE</manufacturer>
      <manufacturerURL>http://www.ee.co.uk/</manufacturerURL>
      <modelDescription>EE Smart Hub 6.0B</modelDescription>
      <modelName>EE Smart Hub 6.0B</modelName>
      <modelNumber>1</modelNumber>
      <modelURL>http://eehub.home</modelURL>
      <serialNumber>+EEH001+1903011269</serialNumber>
      <UDN>uuid:32c7b261-fdb8-43f2-99a1-9ec907178949</UDN>
      <deviceList>
         <device>
            <deviceType>urn:schemas-upnp-org:device:WANDevice:1</deviceType>
            <friendlyName>WANDevice</friendlyName>
            <manufacturer>EE</manufacturer>
            <manufacturerURL>http://www.ee.co.uk/</manufacturerURL>
            <modelDescription>EE Smart Hub 6.0B</modelDescription>
            <modelName>EE Smart Hub 6.0B</modelName>
            <modelNumber>1</modelNumber>
            <modelURL>http://eehub.home</modelURL>
            <serialNumber>+EEH001+1903011269</serialNumber>
            <UDN>uuid:32c7b261-fdb8-43f2-99a1-9ec90717894a</UDN>
            <UPC>000000000000</UPC>
            <serviceList>
               <service>
                  <serviceType>urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1</serviceType>
                  <serviceId>urn:upnp-org:serviceId:WANCommonIFC1</serviceId>
                  <controlURL>/32c7b261/ctl/CmnIfCfg</controlURL>
                  <eventSubURL>/32c7b261/evt/CmnIfCfg</eventSubURL>
                  <SCPDURL>/32c7b261/WANCfg.xml</SCPDURL>
               </service>
            </serviceList>
            <deviceList>
               <device>
                  <deviceType>urn:schemas-upnp-org:device:WANConnectionDevice:1</deviceType>
                  <friendlyName>WANConnectionDevice</friendlyName>
                  <manufacturer>EE</manufacturer>
                  <manufacturerURL>http://www.ee.co.uk/</manufacturerURL>
                  <modelDescription>EE Smart Hub 6.0B</modelDescription>
                  <modelName>EE Smart Hub 6.0B</modelName>
                  <modelNumber>1</modelNumber>
                  <modelURL>http://eehub.home</modelURL>
                  <serialNumber>+EEH001+1903011269</serialNumber>
                  <UDN>uuid:32c7b261-fdb8-43f2-99a1-9ec90717894b</UDN>
                  <UPC>000000000000</UPC>
                  <serviceList>
                     <service>
                        <serviceType>urn:schemas-upnp-org:service:WANPPPConnection:1</serviceType>
                        <serviceId>urn:upnp-org:serviceId:WANPPPConn1</serviceId>
                        <controlURL>/32c7b261/ctl/PPPConn</controlURL>
                        <eventSubURL>/32c7b261/evt/PPPConn</eventSubURL>
                        <SCPDURL>/32c7b261/WANPPPCn.xml</SCPDURL>
                     </service>
                  </serviceList>
               </device>
            </deviceList>
         </device>
      </deviceList>
      <serviceList>
         <service>
            <serviceType>urn:schemas-upnp-org:service:Layer3Forwarding:1</serviceType>
            <serviceId>urn:upnp-org:serviceId:L3Forwarding1</serviceId>
            <SCPDURL>/32c7b261/L3F.xml</SCPDURL>
            <controlURL>/32c7b261/ctl/L3F</controlURL>
            <eventSubURL>/32c7b261/evt/L3F</eventSubURL>
         </service>
      </serviceList>
      <presentationURL>http://eehub.home</presentationURL>
   </device>
</root>
BaronGreenback commented 3 years ago

Alan, sorry to bother - any change you could update nuget with the latest version please?

alanmcgovern commented 3 years ago

@BaronGreenback I released what's in master as of now as v3.0.0. There was an API break which necessitated a major version change.

However, i don't know how to fully resolve the issue you're facing with your router yet. To figure this one out I'd need the full sequence of request/response messages in a single log file.

It looks like whoever created that xml response literally hardcoded the strings, including the xmlns prefixes, rather than construct a proper response. The response has u: prefixes but there's no namespace declaration which tells the xml parse what u: actually means. there should be something like: xmlns:u="urn:schemas-upnp-org:service:WANIPConnection:1" but it's not there!

BaronGreenback commented 3 years ago

Thanks!

I totally understand what you mean about the xml - i've been doing some dlna to my sharp tv - and i've had to write a "loose" parser as they return questionable xml to say the least.

Wouldn't worry about the xml at the moment. As soon as i've finished my current PR - i'll do a network trace and post you the results.