Skip to content

Commit e829221

Browse files
Lan-Hekaryd-a-v
authored andcommitted
Fix ssdp (#5750)
* Update ESP8266SSDP.h Fix SSDP bug: The response to M-Search Packet with ST field set to UUID should be with the UUID not the Device Type Integrated 'uuid:' prefix into the char array of the _uuid * Update ESP8266SSDP.cpp Fix SSDP bug: The response to M-Search Packet with ST field set to UUID should be with the UUID not the Device Type Integrated 'uuid:' prefix into the char array of the _uuid * include 'uuid:' in format String and in flash * Update ESP8266SSDP.cpp
1 parent 8961bba commit e829221

File tree

2 files changed

+30
-14
lines changed

2 files changed

+30
-14
lines changed

libraries/ESP8266SSDP/ESP8266SSDP.cpp

+23-8
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ static const char _ssdp_packet_template[] PROGMEM =
7171
"%s" // _ssdp_response_template / _ssdp_notify_template
7272
"CACHE-CONTROL: max-age=%u\r\n" // SSDP_INTERVAL
7373
"SERVER: Arduino/1.0 UPNP/1.1 %s/%s\r\n" // _modelName, _modelNumber
74-
"USN: uuid:%s\r\n" // _uuid
74+
"USN: %s\r\n" // _uuid
7575
"%s: %s\r\n" // "NT" or "ST", _deviceType
7676
"LOCATION: http://%u.%u.%u.%u:%u/%s\r\n" // WiFi.localIP(), _port, _schemaURL
7777
"\r\n";
@@ -99,7 +99,7 @@ static const char _ssdp_schema_template[] PROGMEM =
9999
"<modelURL>%s</modelURL>"
100100
"<manufacturer>%s</manufacturer>"
101101
"<manufacturerURL>%s</manufacturerURL>"
102-
"<UDN>uuid:%s</UDN>"
102+
"<UDN>%s</UDN>"
103103
"</device>"
104104
//"<iconList>"
105105
//"<icon>"
@@ -130,8 +130,10 @@ SSDPClass::SSDPClass() :
130130
_timer(0),
131131
_port(80),
132132
_ttl(SSDP_MULTICAST_TTL),
133+
_respondToAddr(0,0,0,0),
133134
_respondToPort(0),
134135
_pending(false),
136+
_st_is_uuid(false),
135137
_delay(0),
136138
_process_time(0),
137139
_notify_time(0)
@@ -155,12 +157,13 @@ SSDPClass::~SSDPClass() {
155157

156158
bool SSDPClass::begin() {
157159
end();
158-
160+
159161
_pending = false;
162+
_st_is_uuid = false;
160163
if (strcmp(_uuid,"") == 0) {
161164
uint32_t chipId = ESP.getChipId();
162-
sprintf(_uuid, "38323636-4558-4dda-9188-cda0e6%02x%02x%02x",
163-
(uint16_t) ((chipId >> 16) & 0xff),
165+
sprintf_P(_uuid, PSTR("uuid:38323636-4558-4dda-9188-cda0e6%02x%02x%02x"),
166+
(uint16_t) ((chipId >> 16) & 0xff),
164167
(uint16_t) ((chipId >> 8) & 0xff),
165168
(uint16_t) chipId & 0xff);
166169
}
@@ -178,7 +181,9 @@ bool SSDPClass::begin() {
178181
IPAddress mcast(SSDP_MULTICAST_ADDR);
179182

180183
if (igmp_joingroup(local, mcast) != ERR_OK ) {
181-
DEBUGV("SSDP failed to join igmp group");
184+
#ifdef DEBUG_SSDP
185+
DEBUG_SSDP.printf_P(PSTR("SSDP failed to join igmp group\n"));
186+
#endif
182187
return false;
183188
}
184189

@@ -241,7 +246,7 @@ void SSDPClass::_send(ssdp_method_t method) {
241246
_modelNumber,
242247
_uuid,
243248
(method == NONE) ? "ST" : "NT",
244-
_deviceType,
249+
(_st_is_uuid) ? _uuid : _deviceType,
245250
ip[0], ip[1], ip[2], ip[3], _port, _schemaURL
246251
);
247252

@@ -373,10 +378,19 @@ void SSDPClass::_update() {
373378
#ifdef DEBUG_SSDP
374379
DEBUG_SSDP.printf("REJECT: %s\n", (char *)buffer);
375380
#endif
381+
}else{
382+
_st_is_uuid = false;
376383
}
377384
// if the search type matches our type, we should respond instead of ABORT
378385
if (strcasecmp(buffer, _deviceType) == 0) {
379386
_pending = true;
387+
_st_is_uuid = false;
388+
_process_time = millis();
389+
state = KEY;
390+
}
391+
if (strcasecmp(buffer, _uuid) == 0) {
392+
_pending = true;
393+
_st_is_uuid = true;
380394
_process_time = millis();
381395
state = KEY;
382396
}
@@ -416,6 +430,7 @@ void SSDPClass::_update() {
416430
_send(NONE);
417431
} else if(_notify_time == 0 || (millis() - _notify_time) > (SSDP_INTERVAL * 1000L)){
418432
_notify_time = millis();
433+
_st_is_uuid = false;
419434
_send(NOTIFY);
420435
}
421436

@@ -439,7 +454,7 @@ void SSDPClass::setDeviceType(const char *deviceType) {
439454
}
440455

441456
void SSDPClass::setUUID(const char *uuid) {
442-
strlcpy(_uuid, uuid, sizeof(_uuid));
457+
snprintf_P(_uuid, sizeof(_uuid), PSTR("uuid:%s"), uuid);
443458
}
444459

445460
void SSDPClass::setName(const char *name) {

libraries/ESP8266SSDP/ESP8266SSDP.h

+7-6
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ License (MIT license):
3535

3636
class UdpContext;
3737

38-
#define SSDP_UUID_SIZE 37
38+
#define SSDP_UUID_SIZE 42
3939
#define SSDP_SCHEMA_URL_SIZE 64
4040
#define SSDP_DEVICE_TYPE_SIZE 64
4141
#define SSDP_FRIENDLY_NAME_SIZE 64
@@ -66,17 +66,17 @@ class SSDPClass{
6666
void setDeviceType(const String& deviceType) { setDeviceType(deviceType.c_str()); }
6767
void setDeviceType(const char *deviceType);
6868

69-
/*To define a custom UUID, you must call the method before begin(). Otherwise an automatic UUID based on CHIPID will be generated.*/
70-
void setUUID(const String& uuid) { setUUID(uuid.c_str()); }
71-
void setUUID(const char *uuid);
69+
/*To define a custom UUID, you must call the method before begin(). Otherwise an automatic UUID based on CHIPID will be generated.*/
70+
void setUUID(const String& uuid) { setUUID(uuid.c_str()); }
71+
void setUUID(const char *uuid);
7272

73-
void setName(const String& name) { setName(name.c_str()); }
73+
void setName(const String& name) { setName(name.c_str()); }
7474
void setName(const char *name);
7575
void setURL(const String& url) { setURL(url.c_str()); }
7676
void setURL(const char *url);
7777
void setSchemaURL(const String& url) { setSchemaURL(url.c_str()); }
7878
void setSchemaURL(const char *url);
79-
void setSerialNumber(const String& serialNumber) { setSerialNumber(serialNumber.c_str()); }
79+
void setSerialNumber(const String& serialNumber) { setSerialNumber(serialNumber.c_str()); }
8080
void setSerialNumber(const char *serialNumber);
8181
void setSerialNumber(const uint32_t serialNumber);
8282
void setModelName(const String& name) { setModelName(name.c_str()); }
@@ -108,6 +108,7 @@ class SSDPClass{
108108
uint16_t _respondToPort;
109109

110110
bool _pending;
111+
bool _st_is_uuid;
111112
unsigned short _delay;
112113
unsigned long _process_time;
113114
unsigned long _notify_time;

0 commit comments

Comments
 (0)