Skip to content
This repository was archived by the owner on Jan 20, 2025. It is now read-only.

Fix compiler error for ESP32-C3 and mbed TLS v2.7.0+ #970

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/AsyncWebSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ void AsyncWebSocketClient::binary(AsyncWebSocketMessageBuffer * buffer)

IPAddress AsyncWebSocketClient::remoteIP() {
if(!_client) {
return IPAddress(0U);
return IPAddress((uint32_t) 0);
Copy link

@agners agners Jul 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using a type cast I'd just use a more specific type suffix:

Suggested change
return IPAddress((uint32_t) 0);
return IPAddress(0UL);

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, using 0UL breaks ESP32. I think the only proper way to fix this is using a static type cast.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we return IPADDR_ANY or IPADDR_NONE here? IPADDR_ANY looks good for this, no?

}
return _client->remoteIP();
}
Expand Down
5 changes: 5 additions & 0 deletions src/AsyncWebSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@
#ifndef ASYNCWEBSOCKET_H_
#define ASYNCWEBSOCKET_H_

#if (MBEDTLS_VERSION_NUMBER >= 0x02070000)
//#error Must use ESP32 core v1.0.6-, with MBEDTLS_VERSION_NUMBER < v2.7.0
#endif

#include <Arduino.h>
#ifdef ESP32
#include "mbedtls/version.h"
#include <AsyncTCP.h>
#define WS_MAX_QUEUED_MESSAGES 32
#else
Expand Down
14 changes: 11 additions & 3 deletions src/WebAuthentication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <libb64/cencode.h>
#ifdef ESP32
#include "mbedtls/md5.h"
#include "mbedtls/version.h"
#else
#include "md5.h"
#endif
Expand Down Expand Up @@ -71,9 +72,16 @@ static bool getMD5(uint8_t * data, uint16_t len, char * output){//33 bytes or mo
memset(_buf, 0x00, 16);
#ifdef ESP32
mbedtls_md5_init(&_ctx);
mbedtls_md5_starts_ret(&_ctx);
mbedtls_md5_update_ret(&_ctx, data, len);
mbedtls_md5_finish_ret(&_ctx, _buf);
#if (MBEDTLS_VERSION_NUMBER < 0x02070000)
// Superseded from v2.7.0
mbedtls_md5_starts(&_ctx);
mbedtls_md5_update(&_ctx, data, len);
mbedtls_md5_finish(&_ctx, _buf);
#else
mbedtls_md5_starts_ret(&_ctx);
mbedtls_md5_update_ret(&_ctx, data, len);
mbedtls_md5_finish_ret(&_ctx, _buf);
#endif
#else
MD5Init(&_ctx);
MD5Update(&_ctx, data, len);
Expand Down