Skip to content

Commit f9b1f00

Browse files
committed
DDP invalid packet filter
1 parent 9969cc1 commit f9b1f00

5 files changed

Lines changed: 18 additions & 7 deletions

File tree

wled00/e131.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,8 @@ void handleE131Packet(e131_packet_t* p, IPAddress clientIP, byte protocol) {
266266
}
267267
}
268268
}
269-
unsigned ddpChannelsPerLed = ((p->dataType & 0b00111000)>>3 == 0b011) ? 4 : 3; // data type 0x1B (formerly 0x1A) is RGBW (type 3, 8 bit/channel)
269+
if (!(p->dataType == DDP_TYPE_RGBW32 || p->dataType == DDP_TYPE_RGB24) && p->destination != 1) return; // only RGB or RGBW supported and default device ID
270+
unsigned ddpChannelsPerLed = 3 + (p->dataType == DDP_TYPE_RGBW32); // data type 0x1B (formerly 0x1A) is RGBW (type 3, 8 bit/channel)
270271
uint32_t start = htonl(p->channelOffset) / ddpChannelsPerLed;
271272
start += DMXAddress / ddpChannelsPerLed;
272273
unsigned stop = start + htons(p->dataLen) / ddpChannelsPerLed;

wled00/src/dependencies/e131/ESPAsyncE131.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,13 @@ void ESPAsyncE131::parsePacket(AsyncUDPPacket _packet) {
124124
}
125125

126126
if (error && _packet.localPort() == DDP_DEFAULT_PORT) { //DDP packet
127-
error = false;
128-
protocol = P_DDP;
127+
// check if it is indeed DDP packet (version bits >0; data len == actual packet length - header)
128+
if (_packet.length() > DDP_HEADER_SIZE && (sbuff->flags & DDP_VERSION_MASK) != 0) {
129+
if (sbuff->dataLen == _packet.length() - DDP_HEADER_SIZE - (sbuff->flags & DDP_TIMECODE_FLAG ? sizeof(uint32_t) : 0)) {
130+
error = false;
131+
protocol = P_DDP;
132+
}
133+
}
129134
}
130135

131136
if (!error) {

wled00/src/dependencies/e131/ESPAsyncE131.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ typedef struct ip_addr ip4_addr_t;
5050
#define ARTNET_DEFAULT_PORT 6454
5151
#define DDP_DEFAULT_PORT 4048
5252

53+
#define DDP_HEADER_SIZE 10 // increases to 14 if timecode flag is set
54+
#define DDP_VERSION_MASK 0xC0
5355
#define DDP_PUSH_FLAG 0x01
5456
#define DDP_TIMECODE_FLAG 0x10
5557

wled00/udp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ uint8_t realtimeBroadcast(uint8_t type, IPAddress client, uint16_t length, const
835835
// write the header
836836
/*0*/ddpUdp.write(flags);
837837
/*1*/ddpUdp.write(sequenceNumber++ & 0x0F); // sequence may be unnecessary unless we are sending twice (as requested in Sync settings)
838-
/*2*/ddpUdp.write(isRGBW ? DDP_TYPE_RGBW32 : DDP_TYPE_RGB24);
838+
/*2*/ddpUdp.write(isRGBW ? DDP_TYPE_RGBW32 : DDP_TYPE_RGB24);
839839
/*3*/ddpUdp.write(DDP_ID_DISPLAY);
840840
// data offset in bytes, 32-bit number, MSB first
841841
/*4*/ddpUdp.write(0xFF & (channel >> 24));

wled00/wled.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -460,9 +460,12 @@ void WLED::setup()
460460
WiFi.persistent(false);
461461
//WiFi.enableLongRange(true);
462462
WiFi.onEvent(WiFiEvent);
463-
//#if defined(ARDUINO_ARCH_ESP32) && ESP_IDF_VERSION_MAJOR==4 && !defined(CONFIG_IDF_TARGET_ESP32S2)
464-
// WiFi.useStaticBuffers(true); // use preallocated buffers (for speed); WARNING: uses 60kB of RAM!!!
465-
//#endif
463+
#if defined(ARDUINO_ARCH_ESP32) && ESP_IDF_VERSION_MAJOR==4
464+
WiFi.setScanMethod(WIFI_ALL_CHANNEL_SCAN);
465+
#if defined(CONFIG_IDF_TARGET_ESP32S3) && !defined(WLED_ENABLE_HUB75MATRIX)
466+
WiFi.useStaticBuffers(true); // use preallocated buffers (for speed); WARNING: uses 60kB of RAM!!!
467+
#endif
468+
#endif
466469
delay(15); // wait for hardware to be ready
467470

468471
if (isWiFiConfigured()) {

0 commit comments

Comments
 (0)