Have distinct UUID for the 3 devices (IGD, WAN Device, WAN Connection Device)

This commit is contained in:
Thomas Bernard 2013-06-13 16:03:36 +02:00
parent 01bffe494d
commit 50ec2fce4a
9 changed files with 117 additions and 53 deletions

View File

@ -1,4 +1,7 @@
$Id: Changelog.txt,v 1.344 2013/06/06 21:39:58 nanard Exp $ $Id: Changelog.txt,v 1.345 2013/06/13 13:21:28 nanard Exp $
2013/06/13:
Have 3 UUID for the 3 devices (IGD, WAN Device, WAN Connection Device)
2013/06/06: 2013/06/06:
update upnpreplyparse to allow larger values (128 chars instead of 64) update upnpreplyparse to allow larger values (128 chars instead of 64)

View File

@ -1,4 +1,4 @@
/* $Id: minissdp.c,v 1.51 2013/06/11 18:02:18 nanard Exp $ */ /* $Id: minissdp.c,v 1.52 2013/06/13 13:21:29 nanard Exp $ */
/* MiniUPnP project /* MiniUPnP project
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
* (c) 2006-2013 Thomas Bernard * (c) 2006-2013 Thomas Bernard
@ -323,7 +323,7 @@ EXT:
static void static void
SendSSDPResponse(int s, const struct sockaddr * addr, SendSSDPResponse(int s, const struct sockaddr * addr,
const char * st, int st_len, const char * suffix, const char * st, int st_len, const char * suffix,
const char * host, unsigned short port) const char * host, unsigned short port, const char * uuidvalue)
{ {
int l, n; int l, n;
char buf[512]; char buf[512];
@ -412,27 +412,28 @@ SendSSDPResponse(int s, const struct sockaddr * addr,
static struct { static struct {
const char * s; const char * s;
const int version; const int version;
const char * uuid;
} const known_service_types[] = } const known_service_types[] =
{ {
{"upnp:rootdevice", 0}, {"upnp:rootdevice", 0, uuidvalue_igd},
{"urn:schemas-upnp-org:device:InternetGatewayDevice:", IGD_VER}, {"urn:schemas-upnp-org:device:InternetGatewayDevice:", IGD_VER, uuidvalue_igd},
{"urn:schemas-upnp-org:device:WANConnectionDevice:", 1}, {"urn:schemas-upnp-org:device:WANConnectionDevice:", 1, uuidvalue_wcd},
{"urn:schemas-upnp-org:device:WANDevice:", 1}, {"urn:schemas-upnp-org:device:WANDevice:", 1, uuidvalue_wan},
{"urn:schemas-upnp-org:service:WANCommonInterfaceConfig:", 1}, {"urn:schemas-upnp-org:service:WANCommonInterfaceConfig:", 1, uuidvalue_wan},
{"urn:schemas-upnp-org:service:WANIPConnection:", WANIPC_VER}, {"urn:schemas-upnp-org:service:WANIPConnection:", WANIPC_VER, uuidvalue_wcd},
#ifndef UPNP_STRICT #ifndef UPNP_STRICT
/* We use WAN IP Connection, not PPP connection, /* We use WAN IP Connection, not PPP connection,
* but buggy control points may try to use WanPPPConnection * but buggy control points may try to use WanPPPConnection
* anyway */ * anyway */
{"urn:schemas-upnp-org:service:WANPPPConnection:", 1}, {"urn:schemas-upnp-org:service:WANPPPConnection:", 1, uuidvalue_wcd},
#endif #endif
#ifdef ENABLE_L3F_SERVICE #ifdef ENABLE_L3F_SERVICE
{"urn:schemas-upnp-org:service:Layer3Forwarding:", 1}, {"urn:schemas-upnp-org:service:Layer3Forwarding:", 1, uuidvalue_igd},
#endif #endif
#ifdef ENABLE_6FC_SERVICE #ifdef ENABLE_6FC_SERVICE
{"url:schemas-upnp-org:service:WANIPv6FirewallControl:", 1}, {"url:schemas-upnp-org:service:WANIPv6FirewallControl:", 1, uuidvalue_wcd},
#endif #endif
{0, 0} {0, 0, 0}
}; };
static void static void
@ -533,12 +534,13 @@ SendSSDPNotifies(int s, const char * host, unsigned short port,
snprintf(ver_str, sizeof(ver_str), "%d", known_service_types[i].version); snprintf(ver_str, sizeof(ver_str), "%d", known_service_types[i].version);
SendSSDPNotify(s, (struct sockaddr *)&sockname, host, port, SendSSDPNotify(s, (struct sockaddr *)&sockname, host, port,
known_service_types[i].s, ver_str, /* NT: */ known_service_types[i].s, ver_str, /* NT: */
uuidvalue, "::", known_service_types[i].s, /* ver_str, USN: */ known_service_types[i].uuid, "::",
known_service_types[i].s, /* ver_str, USN: */
lifetime, ipv6); lifetime, ipv6);
if(i==0) /* rootdevice */ if(i==0) /* rootdevice */
SendSSDPNotify(s, (struct sockaddr *)&sockname, host, port, SendSSDPNotify(s, (struct sockaddr *)&sockname, host, port,
uuidvalue, "", /* NT: */ uuidvalue_igd, "", /* NT: */
uuidvalue, "", "", /* ver_str, USN: */ uuidvalue_igd, "", "", /* ver_str, USN: */
lifetime, ipv6); lifetime, ipv6);
i++; i++;
} }
@ -751,7 +753,8 @@ ProcessSSDPData(int s, const char *bufr, int n,
syslog(LOG_INFO, "Single search found"); syslog(LOG_INFO, "Single search found");
SendSSDPResponse(s, sender, SendSSDPResponse(s, sender,
st, st_len, "", st, st_len, "",
announced_host, port); announced_host, port,
known_service_types[i].uuid);
break; break;
} }
} }
@ -769,19 +772,39 @@ ProcessSSDPData(int s, const char *bufr, int n,
l = (int)strlen(known_service_types[i].s); l = (int)strlen(known_service_types[i].s);
SendSSDPResponse(s, sender, SendSSDPResponse(s, sender,
known_service_types[i].s, l, ver_str, known_service_types[i].s, l, ver_str,
announced_host, port); announced_host, port,
known_service_types[i].uuid);
} }
/* also answer for uuid */ /* also answer for uuid */
SendSSDPResponse(s, sender, uuidvalue, strlen(uuidvalue), "", SendSSDPResponse(s, sender, uuidvalue_igd, strlen(uuidvalue_igd), "",
announced_host, port); announced_host, port, uuidvalue_igd);
SendSSDPResponse(s, sender, uuidvalue_wan, strlen(uuidvalue_wan), "",
announced_host, port, uuidvalue_wan);
SendSSDPResponse(s, sender, uuidvalue_wcd, strlen(uuidvalue_wcd), "",
announced_host, port, uuidvalue_wcd);
} }
/* responds to request by UUID value */ /* responds to request by UUID value */
l = (int)strlen(uuidvalue); l = (int)strlen(uuidvalue_igd);
if(l==st_len && (0 == memcmp(st, uuidvalue, l))) if(l==st_len)
{ {
syslog(LOG_INFO, "ssdp:uuid found"); if(0 == memcmp(st, uuidvalue_igd, l))
{
syslog(LOG_INFO, "ssdp:uuid (IGD) found");
SendSSDPResponse(s, sender, st, st_len, "", SendSSDPResponse(s, sender, st, st_len, "",
announced_host, port); announced_host, port, uuidvalue_igd);
}
else if(0 == memcmp(st, uuidvalue_wan, l))
{
syslog(LOG_INFO, "ssdp:uuid (WAN) found");
SendSSDPResponse(s, sender, st, st_len, "",
announced_host, port, uuidvalue_wan);
}
else if(0 == memcmp(st, uuidvalue_wcd, l))
{
syslog(LOG_INFO, "ssdp:uuid (WCD) found");
SendSSDPResponse(s, sender, st, st_len, "",
announced_host, port, uuidvalue_wcd);
}
} }
} }
else else
@ -893,7 +916,8 @@ SendSSDPGoodbye(int * sockets, int n_sockets)
(struct sockaddr *)&sockname, (struct sockaddr *)&sockname,
#endif #endif
known_service_types[i].s, ver_str, /* NT: */ known_service_types[i].s, ver_str, /* NT: */
uuidvalue, "::", known_service_types[i].s, /* ver_str, USN: */ known_service_types[i].uuid, "::",
known_service_types[i].s, /* ver_str, USN: */
ipv6); ipv6);
if(i==0) /* root device */ if(i==0) /* root device */
{ {
@ -903,8 +927,8 @@ SendSSDPGoodbye(int * sockets, int n_sockets)
#else #else
(struct sockaddr *)&sockname, (struct sockaddr *)&sockname,
#endif #endif
uuidvalue, "", /* NT: */ uuidvalue_igd, "", /* NT: */
uuidvalue, "", "", /* ver_str, USN: */ uuidvalue_igd, "", "", /* ver_str, USN: */
ipv6); ipv6);
} }
} }
@ -954,7 +978,7 @@ SubmitServicesToMiniSSDPD(const char * host, unsigned short port) {
else else
snprintf(ver_str, sizeof(ver_str), "%d", known_service_types[i].version); snprintf(ver_str, sizeof(ver_str), "%d", known_service_types[i].version);
l = snprintf(strbuf, sizeof(strbuf), "%s::%s%s", l = snprintf(strbuf, sizeof(strbuf), "%s::%s%s",
uuidvalue, known_service_types[i].s, ver_str); known_service_types[i].uuid, known_service_types[i].s, ver_str);
if(l<0) { if(l<0) {
syslog(LOG_WARNING, "SubmitServicesToMiniSSDPD: snprintf %m"); syslog(LOG_WARNING, "SubmitServicesToMiniSSDPD: snprintf %m");
continue; continue;

View File

@ -1,4 +1,4 @@
/* $Id: miniupnpd.c,v 1.175 2013/04/29 09:34:14 nanard Exp $ */ /* $Id: miniupnpd.c,v 1.176 2013/06/13 13:21:29 nanard Exp $ */
/* MiniUPnP project /* MiniUPnP project
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
* (c) 2006-2013 Thomas Bernard * (c) 2006-2013 Thomas Bernard
@ -643,6 +643,35 @@ parselan_error:
return -1; return -1;
} }
/* fill uuidvalue_wan and uuidvalue_wcd based on uuidvalue_igd */
void complete_uuidvalues(void)
{
size_t len;
len = strlen(uuidvalue_igd);
memcpy(uuidvalue_wan, uuidvalue_igd, len+1);
switch(uuidvalue_wan[len-1]) {
case '9':
uuidvalue_wan[len-1] = 'a';
break;
case 'f':
uuidvalue_wan[len-1] = '0';
break;
default:
uuidvalue_wan[len-1]++;
}
memcpy(uuidvalue_wcd, uuidvalue_wan, len+1);
switch(uuidvalue_wcd[len-1]) {
case '9':
uuidvalue_wcd[len-1] = 'a';
break;
case 'f':
uuidvalue_wcd[len-1] = '0';
break;
default:
uuidvalue_wcd[len-1]++;
}
}
/* init phase : /* init phase :
* 1) read configuration file * 1) read configuration file
* 2) read command line arguments * 2) read command line arguments
@ -770,8 +799,9 @@ init(int argc, char * * argv, struct runtime_vars * v)
break; break;
#endif #endif
case UPNPUUID: case UPNPUUID:
strncpy(uuidvalue+5, ary_options[i].value, strncpy(uuidvalue_igd+5, ary_options[i].value,
strlen(uuidvalue+5) + 1); strlen(uuidvalue_igd+5) + 1);
complete_uuidvalues();
break; break;
case UPNPSERIAL: case UPNPSERIAL:
strncpy(serialnumber, ary_options[i].value, SERIALNUMBER_MAX_LEN); strncpy(serialnumber, ary_options[i].value, SERIALNUMBER_MAX_LEN);
@ -866,9 +896,10 @@ init(int argc, char * * argv, struct runtime_vars * v)
fprintf(stderr, "Option -%c takes one argument.\n", argv[i][1]); fprintf(stderr, "Option -%c takes one argument.\n", argv[i][1]);
break; break;
case 'u': case 'u':
if(i+1 < argc) if(i+1 < argc) {
strncpy(uuidvalue+5, argv[++i], strlen(uuidvalue+5) + 1); strncpy(uuidvalue_igd+5, argv[++i], strlen(uuidvalue_igd+5) + 1);
else complete_uuidvalues();
} else
fprintf(stderr, "Option -%c takes one argument.\n", argv[i][1]); fprintf(stderr, "Option -%c takes one argument.\n", argv[i][1]);
break; break;
case 'z': case 'z':

View File

@ -1,7 +1,7 @@
/* $Id: testupnpdescgen.c,v 1.29 2012/04/30 21:08:00 nanard Exp $ */ /* $Id: testupnpdescgen.c,v 1.30 2013/06/13 13:21:30 nanard Exp $ */
/* MiniUPnP project /* MiniUPnP project
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
* (c) 2006-2012 Thomas Bernard * (c) 2006-2013 Thomas Bernard
* This software is subject to the conditions detailed * This software is subject to the conditions detailed
* in the LICENCE file provided within the distribution */ * in the LICENCE file provided within the distribution */
@ -17,7 +17,9 @@
#include "config.h" #include "config.h"
#include "upnpdescgen.h" #include "upnpdescgen.h"
char uuidvalue[] = "uuid:12345678-0000-0000-0000-00000000abcd"; char uuidvalue_igd[] = "uuid:12345678-0000-0000-0000-000000abcd01";
char uuidvalue_wan[] = "uuid:12345678-0000-0000-0000-000000abcd02";
char uuidvalue_wcd[] = "uuid:12345678-0000-0000-0000-000000abcd03";
char serialnumber[] = "12345678"; char serialnumber[] = "12345678";
char modelnumber[] = "1"; char modelnumber[] = "1";
char presentationurl[] = "http://192.168.0.1:8080/"; char presentationurl[] = "http://192.168.0.1:8080/";

View File

@ -1,4 +1,4 @@
/* $Id: upnpdescgen.c,v 1.73 2013/05/29 21:27:22 nanard Exp $ */ /* $Id: upnpdescgen.c,v 1.74 2013/06/13 13:21:30 nanard Exp $ */
/* MiniUPnP project /* MiniUPnP project
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
* (c) 2006-2013 Thomas Bernard * (c) 2006-2013 Thomas Bernard
@ -154,7 +154,7 @@ static const struct XMLElt rootDesc[] =
{"/modelNumber", modelnumber}, {"/modelNumber", modelnumber},
{"/modelURL", ROOTDEV_MODELURL}, {"/modelURL", ROOTDEV_MODELURL},
{"/serialNumber", serialnumber}, {"/serialNumber", serialnumber},
{"/UDN", uuidvalue}, /* required */ {"/UDN", uuidvalue_igd}, /* required */
/* see if /UPC is needed. */ /* see if /UPC is needed. */
#ifdef ENABLE_6FC_SERVICE #ifdef ENABLE_6FC_SERVICE
#define SERVICES_OFFSET 63 #define SERVICES_OFFSET 63
@ -201,7 +201,7 @@ static const struct XMLElt rootDesc[] =
{"/modelNumber", WANDEV_MODELNUMBER}, {"/modelNumber", WANDEV_MODELNUMBER},
{"/modelURL", WANDEV_MODELURL}, {"/modelURL", WANDEV_MODELURL},
{"/serialNumber", serialnumber}, {"/serialNumber", serialnumber},
{"/UDN", uuidvalue}, {"/UDN", uuidvalue_wan},
{"/UPC", WANDEV_UPC}, /* UPC (=12 digit barcode) is optional */ {"/UPC", WANDEV_UPC}, /* UPC (=12 digit barcode) is optional */
/* 30 */ /* 30 */
{"serviceList", INITHELPER(32,1)}, {"serviceList", INITHELPER(32,1)},
@ -229,7 +229,7 @@ static const struct XMLElt rootDesc[] =
{"/modelNumber", WANCDEV_MODELNUMBER}, {"/modelNumber", WANCDEV_MODELNUMBER},
{"/modelURL", WANCDEV_MODELURL}, {"/modelURL", WANCDEV_MODELURL},
{"/serialNumber", serialnumber}, {"/serialNumber", serialnumber},
{"/UDN", uuidvalue}, {"/UDN", uuidvalue_wcd},
{"/UPC", WANCDEV_UPC}, /* UPC (=12 digit Barcode) is optional */ {"/UPC", WANCDEV_UPC}, /* UPC (=12 digit Barcode) is optional */
#ifdef ENABLE_6FC_SERVICE #ifdef ENABLE_6FC_SERVICE
{"serviceList", INITHELPER(51,2)}, {"serviceList", INITHELPER(51,2)},
@ -1205,7 +1205,7 @@ genEventVars(int * len, const struct serviceDesc * s)
break; break;
case DEFAULTCONNECTIONSERVICE_MAGICALVALUE: case DEFAULTCONNECTIONSERVICE_MAGICALVALUE:
/* DefaultConnectionService magical value */ /* DefaultConnectionService magical value */
str = strcat_str(str, len, &tmplen, uuidvalue); str = strcat_str(str, len, &tmplen, uuidvalue_wcd);
#ifdef IGD_V2 #ifdef IGD_V2
str = strcat_str(str, len, &tmplen, ":WANConnectionDevice:2,urn:upnp-org:serviceId:WANIPConn1"); str = strcat_str(str, len, &tmplen, ":WANConnectionDevice:2,urn:upnp-org:serviceId:WANIPConn1");
#else #else

View File

@ -1,7 +1,7 @@
/* $Id: upnpevents.c,v 1.26 2012/10/04 22:11:56 nanard Exp $ */ /* $Id: upnpevents.c,v 1.27 2013/06/13 13:21:30 nanard Exp $ */
/* MiniUPnP project /* MiniUPnP project
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
* (c) 2008-2012 Thomas Bernard * (c) 2008-2013 Thomas Bernard
* This software is subject to the conditions detailed * This software is subject to the conditions detailed
* in the LICENCE file provided within the distribution */ * in the LICENCE file provided within the distribution */
@ -110,7 +110,7 @@ newSubscriber(const char * eventurl, const char * callback, int callbacklen)
tmp->callback[callbacklen] = '\0'; tmp->callback[callbacklen] = '\0';
/* make a dummy uuid */ /* make a dummy uuid */
/* TODO: improve that */ /* TODO: improve that */
strncpy(tmp->uuid, uuidvalue, sizeof(tmp->uuid)); strncpy(tmp->uuid, uuidvalue_igd, sizeof(tmp->uuid));
tmp->uuid[sizeof(tmp->uuid)-1] = '\0'; tmp->uuid[sizeof(tmp->uuid)-1] = '\0';
snprintf(tmp->uuid+37, 5, "%04lx", random() & 0xffff); snprintf(tmp->uuid+37, 5, "%04lx", random() & 0xffff);
return tmp; return tmp;

View File

@ -1,4 +1,4 @@
/* $Id: upnpglobalvars.c,v 1.29 2012/04/26 14:01:16 nanard Exp $ */ /* $Id: upnpglobalvars.c,v 1.30 2013/06/13 13:21:30 nanard Exp $ */
/* MiniUPnP project /* MiniUPnP project
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
* (c) 2006-2012 Thomas Bernard * (c) 2006-2012 Thomas Bernard
@ -36,7 +36,9 @@ int runtime_flags = 0;
const char * pidfilename = "/var/run/miniupnpd.pid"; const char * pidfilename = "/var/run/miniupnpd.pid";
char uuidvalue[] = "uuid:00000000-0000-0000-0000-000000000000"; char uuidvalue_igd[] = "uuid:00000000-0000-0000-0000-000000000000";
char uuidvalue_wan[] = "uuid:00000000-0000-0000-0000-000000000000";
char uuidvalue_wcd[] = "uuid:00000000-0000-0000-0000-000000000000";
char serialnumber[SERIALNUMBER_MAX_LEN] = "00000000"; char serialnumber[SERIALNUMBER_MAX_LEN] = "00000000";
char modelnumber[MODELNUMBER_MAX_LEN] = "1"; char modelnumber[MODELNUMBER_MAX_LEN] = "1";

View File

@ -1,4 +1,4 @@
/* $Id: upnpglobalvars.h,v 1.33 2012/04/26 14:01:16 nanard Exp $ */ /* $Id: upnpglobalvars.h,v 1.35 2013/06/13 13:21:30 nanard Exp $ */
/* MiniUPnP project /* MiniUPnP project
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
* (c) 2006-2012 Thomas Bernard * (c) 2006-2012 Thomas Bernard
@ -54,7 +54,9 @@ extern int runtime_flags;
extern const char * pidfilename; extern const char * pidfilename;
extern char uuidvalue[]; extern char uuidvalue_igd[]; /* uuid of root device (IGD) */
extern char uuidvalue_wan[]; /* uuid of WAN Device */
extern char uuidvalue_wcd[]; /* uuid of WAN Connection Device */
#define SERIALNUMBER_MAX_LEN (10) #define SERIALNUMBER_MAX_LEN (10)
extern char serialnumber[]; extern char serialnumber[];

View File

@ -1,4 +1,4 @@
/* $Id: upnpsoap.c,v 1.117 2013/06/05 09:10:47 nanard Exp $ */ /* $Id: upnpsoap.c,v 1.118 2013/06/13 13:21:30 nanard Exp $ */
/* MiniUPnP project /* MiniUPnP project
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
* (c) 2006-2013 Thomas Bernard * (c) 2006-2013 Thomas Bernard
@ -1040,7 +1040,7 @@ SetDefaultConnectionService(struct upnphttp * h, const char * action)
#ifdef UPNP_STRICT #ifdef UPNP_STRICT
char * service; char * service;
service = strchr(p, ','); service = strchr(p, ',');
if(0 != memcmp(uuidvalue, p, sizeof("uuid:00000000-0000-0000-0000-000000000000") - 1)) { if(0 != memcmp(uuidvalue_wcd, p, sizeof("uuid:00000000-0000-0000-0000-000000000000") - 1)) {
SoapError(h, 720, "InvalidDeviceUUID"); SoapError(h, 720, "InvalidDeviceUUID");
} else if(service == NULL || 0 != strcmp(service+1, SERVICE_ID_WANIPC)) { } else if(service == NULL || 0 != strcmp(service+1, SERVICE_ID_WANIPC)) {
SoapError(h, 721, "InvalidServiceID"); SoapError(h, 721, "InvalidServiceID");
@ -1073,7 +1073,7 @@ GetDefaultConnectionService(struct upnphttp * h, const char * action)
int bodylen; int bodylen;
bodylen = snprintf(body, sizeof(body), resp, bodylen = snprintf(body, sizeof(body), resp,
action, uuidvalue, action); action, uuidvalue_wcd, action);
BuildSendAndCloseSoapResp(h, body, bodylen); BuildSendAndCloseSoapResp(h, body, bodylen);
} }
#endif #endif