1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-15 00:02:49 +03:00
* 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
This commit is contained in:
Ahmed El Sharnoby
2019-03-21 19:21:48 +02:00
committed by david gauchard
parent 8961bba94e
commit e829221833
2 changed files with 30 additions and 14 deletions

View File

@ -71,7 +71,7 @@ static const char _ssdp_packet_template[] PROGMEM =
"%s" // _ssdp_response_template / _ssdp_notify_template "%s" // _ssdp_response_template / _ssdp_notify_template
"CACHE-CONTROL: max-age=%u\r\n" // SSDP_INTERVAL "CACHE-CONTROL: max-age=%u\r\n" // SSDP_INTERVAL
"SERVER: Arduino/1.0 UPNP/1.1 %s/%s\r\n" // _modelName, _modelNumber "SERVER: Arduino/1.0 UPNP/1.1 %s/%s\r\n" // _modelName, _modelNumber
"USN: uuid:%s\r\n" // _uuid "USN: %s\r\n" // _uuid
"%s: %s\r\n" // "NT" or "ST", _deviceType "%s: %s\r\n" // "NT" or "ST", _deviceType
"LOCATION: http://%u.%u.%u.%u:%u/%s\r\n" // WiFi.localIP(), _port, _schemaURL "LOCATION: http://%u.%u.%u.%u:%u/%s\r\n" // WiFi.localIP(), _port, _schemaURL
"\r\n"; "\r\n";
@ -99,7 +99,7 @@ static const char _ssdp_schema_template[] PROGMEM =
"<modelURL>%s</modelURL>" "<modelURL>%s</modelURL>"
"<manufacturer>%s</manufacturer>" "<manufacturer>%s</manufacturer>"
"<manufacturerURL>%s</manufacturerURL>" "<manufacturerURL>%s</manufacturerURL>"
"<UDN>uuid:%s</UDN>" "<UDN>%s</UDN>"
"</device>" "</device>"
//"<iconList>" //"<iconList>"
//"<icon>" //"<icon>"
@ -130,8 +130,10 @@ SSDPClass::SSDPClass() :
_timer(0), _timer(0),
_port(80), _port(80),
_ttl(SSDP_MULTICAST_TTL), _ttl(SSDP_MULTICAST_TTL),
_respondToAddr(0,0,0,0),
_respondToPort(0), _respondToPort(0),
_pending(false), _pending(false),
_st_is_uuid(false),
_delay(0), _delay(0),
_process_time(0), _process_time(0),
_notify_time(0) _notify_time(0)
@ -157,10 +159,11 @@ bool SSDPClass::begin() {
end(); end();
_pending = false; _pending = false;
_st_is_uuid = false;
if (strcmp(_uuid,"") == 0) { if (strcmp(_uuid,"") == 0) {
uint32_t chipId = ESP.getChipId(); uint32_t chipId = ESP.getChipId();
sprintf(_uuid, "38323636-4558-4dda-9188-cda0e6%02x%02x%02x", sprintf_P(_uuid, PSTR("uuid:38323636-4558-4dda-9188-cda0e6%02x%02x%02x"),
(uint16_t) ((chipId >> 16) & 0xff), (uint16_t) ((chipId >> 16) & 0xff),
(uint16_t) ((chipId >> 8) & 0xff), (uint16_t) ((chipId >> 8) & 0xff),
(uint16_t) chipId & 0xff); (uint16_t) chipId & 0xff);
} }
@ -178,7 +181,9 @@ bool SSDPClass::begin() {
IPAddress mcast(SSDP_MULTICAST_ADDR); IPAddress mcast(SSDP_MULTICAST_ADDR);
if (igmp_joingroup(local, mcast) != ERR_OK ) { if (igmp_joingroup(local, mcast) != ERR_OK ) {
DEBUGV("SSDP failed to join igmp group"); #ifdef DEBUG_SSDP
DEBUG_SSDP.printf_P(PSTR("SSDP failed to join igmp group\n"));
#endif
return false; return false;
} }
@ -241,7 +246,7 @@ void SSDPClass::_send(ssdp_method_t method) {
_modelNumber, _modelNumber,
_uuid, _uuid,
(method == NONE) ? "ST" : "NT", (method == NONE) ? "ST" : "NT",
_deviceType, (_st_is_uuid) ? _uuid : _deviceType,
ip[0], ip[1], ip[2], ip[3], _port, _schemaURL ip[0], ip[1], ip[2], ip[3], _port, _schemaURL
); );
@ -373,10 +378,19 @@ void SSDPClass::_update() {
#ifdef DEBUG_SSDP #ifdef DEBUG_SSDP
DEBUG_SSDP.printf("REJECT: %s\n", (char *)buffer); DEBUG_SSDP.printf("REJECT: %s\n", (char *)buffer);
#endif #endif
}else{
_st_is_uuid = false;
} }
// if the search type matches our type, we should respond instead of ABORT // if the search type matches our type, we should respond instead of ABORT
if (strcasecmp(buffer, _deviceType) == 0) { if (strcasecmp(buffer, _deviceType) == 0) {
_pending = true; _pending = true;
_st_is_uuid = false;
_process_time = millis();
state = KEY;
}
if (strcasecmp(buffer, _uuid) == 0) {
_pending = true;
_st_is_uuid = true;
_process_time = millis(); _process_time = millis();
state = KEY; state = KEY;
} }
@ -416,6 +430,7 @@ void SSDPClass::_update() {
_send(NONE); _send(NONE);
} else if(_notify_time == 0 || (millis() - _notify_time) > (SSDP_INTERVAL * 1000L)){ } else if(_notify_time == 0 || (millis() - _notify_time) > (SSDP_INTERVAL * 1000L)){
_notify_time = millis(); _notify_time = millis();
_st_is_uuid = false;
_send(NOTIFY); _send(NOTIFY);
} }
@ -439,7 +454,7 @@ void SSDPClass::setDeviceType(const char *deviceType) {
} }
void SSDPClass::setUUID(const char *uuid) { void SSDPClass::setUUID(const char *uuid) {
strlcpy(_uuid, uuid, sizeof(_uuid)); snprintf_P(_uuid, sizeof(_uuid), PSTR("uuid:%s"), uuid);
} }
void SSDPClass::setName(const char *name) { void SSDPClass::setName(const char *name) {

View File

@ -35,7 +35,7 @@ License (MIT license):
class UdpContext; class UdpContext;
#define SSDP_UUID_SIZE 37 #define SSDP_UUID_SIZE 42
#define SSDP_SCHEMA_URL_SIZE 64 #define SSDP_SCHEMA_URL_SIZE 64
#define SSDP_DEVICE_TYPE_SIZE 64 #define SSDP_DEVICE_TYPE_SIZE 64
#define SSDP_FRIENDLY_NAME_SIZE 64 #define SSDP_FRIENDLY_NAME_SIZE 64
@ -66,17 +66,17 @@ class SSDPClass{
void setDeviceType(const String& deviceType) { setDeviceType(deviceType.c_str()); } void setDeviceType(const String& deviceType) { setDeviceType(deviceType.c_str()); }
void setDeviceType(const char *deviceType); void setDeviceType(const char *deviceType);
/*To define a custom UUID, you must call the method before begin(). Otherwise an automatic UUID based on CHIPID will be generated.*/ /*To define a custom UUID, you must call the method before begin(). Otherwise an automatic UUID based on CHIPID will be generated.*/
void setUUID(const String& uuid) { setUUID(uuid.c_str()); } void setUUID(const String& uuid) { setUUID(uuid.c_str()); }
void setUUID(const char *uuid); void setUUID(const char *uuid);
void setName(const String& name) { setName(name.c_str()); } void setName(const String& name) { setName(name.c_str()); }
void setName(const char *name); void setName(const char *name);
void setURL(const String& url) { setURL(url.c_str()); } void setURL(const String& url) { setURL(url.c_str()); }
void setURL(const char *url); void setURL(const char *url);
void setSchemaURL(const String& url) { setSchemaURL(url.c_str()); } void setSchemaURL(const String& url) { setSchemaURL(url.c_str()); }
void setSchemaURL(const char *url); void setSchemaURL(const char *url);
void setSerialNumber(const String& serialNumber) { setSerialNumber(serialNumber.c_str()); } void setSerialNumber(const String& serialNumber) { setSerialNumber(serialNumber.c_str()); }
void setSerialNumber(const char *serialNumber); void setSerialNumber(const char *serialNumber);
void setSerialNumber(const uint32_t serialNumber); void setSerialNumber(const uint32_t serialNumber);
void setModelName(const String& name) { setModelName(name.c_str()); } void setModelName(const String& name) { setModelName(name.c_str()); }
@ -108,6 +108,7 @@ class SSDPClass{
uint16_t _respondToPort; uint16_t _respondToPort;
bool _pending; bool _pending;
bool _st_is_uuid;
unsigned short _delay; unsigned short _delay;
unsigned long _process_time; unsigned long _process_time;
unsigned long _notify_time; unsigned long _notify_time;