diff --git a/src/main/java/net/rptools/maptool/util/upnp/PortMappingListener.java b/src/main/java/net/rptools/maptool/util/upnp/PortMappingListener.java index 5dc4a5111b..f6d413d016 100644 --- a/src/main/java/net/rptools/maptool/util/upnp/PortMappingListener.java +++ b/src/main/java/net/rptools/maptool/util/upnp/PortMappingListener.java @@ -78,10 +78,13 @@ public class PortMappingListener extends DefaultRegistryListener { private final Logger logger = LoggerFactory.getLogger(PortMappingListener.class); - public static final DeviceType IGD_DEVICE_TYPE = new UDADeviceType("InternetGatewayDevice", 1); - public static final DeviceType CONNECTION_DEVICE_TYPE = new UDADeviceType("WANConnectionDevice", 1); + public static final DeviceType IGD_DEVICE_TYPE_V1 = new UDADeviceType("InternetGatewayDevice", 1); + public static final DeviceType IGD_DEVICE_TYPE_V2 = new UDADeviceType("InternetGatewayDevice", 2); + public static final DeviceType CONNECTION_DEVICE_TYPE_V1 = new UDADeviceType("WANConnectionDevice", 1); + public static final DeviceType CONNECTION_DEVICE_TYPE_V2 = new UDADeviceType("WANConnectionDevice", 2); - public static final ServiceType IP_SERVICE_TYPE = new UDAServiceType("WANIPConnection", 1); + public static final ServiceType IP_SERVICE_TYPE_V1 = new UDAServiceType("WANIPConnection", 1); + public static final ServiceType IP_SERVICE_TYPE_V2 = new UDAServiceType("WANIPConnection", 2); public static final ServiceType PPP_SERVICE_TYPE = new UDAServiceType("WANPPPConnection", 1); protected PortMapping[] portMappings; @@ -199,27 +202,37 @@ public void failure(ActionInvocation invocation, UpnpResponse operation, String } protected Service discoverConnectionService(Device device) { - if (!device.getType().equals(IGD_DEVICE_TYPE)) { + DeviceType deviceType = device.getType(); + if (!deviceType.equals(IGD_DEVICE_TYPE_V1) && !deviceType.equals(IGD_DEVICE_TYPE_V2)) { return null; } - Device[] connectionDevices = device.findDevices(CONNECTION_DEVICE_TYPE); + Device[] connectionDevices = device.findDevices(CONNECTION_DEVICE_TYPE_V2); if (connectionDevices.length == 0) { - logger.debug("IGD doesn't support '{}': {}", CONNECTION_DEVICE_TYPE, device); + logger.debug("IGD doesn't support '{}': {}", CONNECTION_DEVICE_TYPE_V2, device); + connectionDevices = device.findDevices(CONNECTION_DEVICE_TYPE_V1); + } + if (connectionDevices.length == 0) { + logger.debug("IGD doesn't support '{}': {}", CONNECTION_DEVICE_TYPE_V1, device); return null; } Device connectionDevice = connectionDevices[0]; logger.debug("Using first discovered WAN connection device: {}", connectionDevice); - Service ipConnectionService = connectionDevice.findService(IP_SERVICE_TYPE); - Service pppConnectionService = connectionDevice.findService(PPP_SERVICE_TYPE); + Service connectionService = connectionDevice.findService(IP_SERVICE_TYPE_V2); + if (connectionService == null) { + connectionService = connectionDevice.findService(IP_SERVICE_TYPE_V1); + } + if (connectionService == null) { + connectionService = connectionDevice.findService(PPP_SERVICE_TYPE); + } - if (ipConnectionService == null && pppConnectionService == null) { + if (connectionService == null) { logger.debug("IGD doesn't support IP or PPP WAN connection service: {}", device); } - return ipConnectionService != null ? ipConnectionService : pppConnectionService; + return connectionService; } protected void handleFailureMessage(String s) {