From 06062ec4940aebf636a67cd8357d88d66896f892 Mon Sep 17 00:00:00 2001 From: Scott Kilau Date: Wed, 23 Aug 2023 22:29:17 -0500 Subject: [PATCH] RP2040: Add support for the RP2040. --- src/AsyncEventSource.h | 2 ++ src/AsyncWebSocket.cpp | 11 +++++++++++ src/AsyncWebSocket.h | 6 ++++++ src/ESPAsyncWebServer.h | 3 +++ src/WebAuthentication.cpp | 8 ++++++++ 5 files changed, 30 insertions(+) diff --git a/src/AsyncEventSource.h b/src/AsyncEventSource.h index b0ea6ff5d..5c31e3a07 100644 --- a/src/AsyncEventSource.h +++ b/src/AsyncEventSource.h @@ -24,6 +24,8 @@ #include #if defined(ESP32) || defined(LIBRETUYA) #include +#elif defined(USE_RP2040) +#include #else #include #endif diff --git a/src/AsyncWebSocket.cpp b/src/AsyncWebSocket.cpp index 6e88da94f..d4e046817 100644 --- a/src/AsyncWebSocket.cpp +++ b/src/AsyncWebSocket.cpp @@ -24,8 +24,13 @@ #include #ifndef ESP8266 +#if defined(USE_RP2040) +#include "bearssl/bearssl.h" +#include "bearssl/bearssl_hash.h" +#else #include "mbedtls/sha1.h" #include "mbedtls/version.h" +#endif #else #include #endif @@ -1253,6 +1258,12 @@ AsyncWebSocketResponse::AsyncWebSocketResponse(const String& key, AsyncWebSocket } #ifdef ESP8266 sha1(key + WS_STR_UUID, hash); +#elif defined(USE_RP2040) + (String&)key += WS_STR_UUID; + br_sha1_context ctx; + br_sha1_init(&ctx); + br_sha1_update(&ctx, (const unsigned char*)key.c_str(), key.length()); + br_sha1_out(&ctx, hash); #else (String&)key += WS_STR_UUID; mbedtls_sha1_context ctx; diff --git a/src/AsyncWebSocket.h b/src/AsyncWebSocket.h index 9d137288a..cf8499270 100644 --- a/src/AsyncWebSocket.h +++ b/src/AsyncWebSocket.h @@ -27,6 +27,12 @@ #ifndef WS_MAX_QUEUED_MESSAGES #define WS_MAX_QUEUED_MESSAGES 32 #endif +#elif defined(USE_RP2040) +#include +#ifndef WS_MAX_QUEUED_MESSAGES +#define WS_MAX_QUEUED_MESSAGES 8 +#endif +#define ets_printf(msg) void() #else #include #ifndef WS_MAX_QUEUED_MESSAGES diff --git a/src/ESPAsyncWebServer.h b/src/ESPAsyncWebServer.h index 1e37d9037..056df2a8f 100644 --- a/src/ESPAsyncWebServer.h +++ b/src/ESPAsyncWebServer.h @@ -34,6 +34,9 @@ #elif defined(ESP8266) #include #include +#elif defined(USE_RP2040) +#include +#include #else #error Platform not supported #endif diff --git a/src/WebAuthentication.cpp b/src/WebAuthentication.cpp index 45246a196..6dbddb007 100644 --- a/src/WebAuthentication.cpp +++ b/src/WebAuthentication.cpp @@ -22,6 +22,8 @@ #include #ifdef ESP32 #include "mbedtls/md5.h" +#elif defined(USE_RP2040) +#include #else #include "md5.h" #endif @@ -61,6 +63,8 @@ bool checkBasicAuthentication(const char * hash, const char * username, const ch static bool getMD5(uint8_t * data, uint16_t len, char * output){//33 bytes or more #ifdef ESP32 mbedtls_md5_context _ctx; +#elif defined(USE_RP2040) + br_md5_context _ctx; #else md5_context_t _ctx; #endif @@ -74,6 +78,10 @@ static bool getMD5(uint8_t * data, uint16_t len, char * output){//33 bytes or mo mbedtls_md5_starts_ret(&_ctx); mbedtls_md5_update_ret(&_ctx, data, len); mbedtls_md5_finish_ret(&_ctx, _buf); +#elif defined(USE_RP2040) + br_md5_init(&_ctx); + br_md5_update(&_ctx, data, len); + br_md5_state(&_ctx, _buf); #else MD5Init(&_ctx); MD5Update(&_ctx, data, len);