Skip to content

Commit a9b66ef

Browse files
committed
Bruteforcing Arduino 3.0 support
1 parent 9e4cf09 commit a9b66ef

11 files changed

Lines changed: 55 additions & 38 deletions

include/Hashing.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ namespace OpenShock {
1919
MD5() { mbedtls_md5_init(&ctx); }
2020
~MD5() { mbedtls_md5_free(&ctx); }
2121

22-
inline bool begin() { return mbedtls_md5_starts_ret(&ctx) == 0; }
23-
inline bool update(const uint8_t* data, std::size_t dataLen) { return mbedtls_md5_update_ret(&ctx, data, dataLen) == 0; }
22+
inline bool begin() { return mbedtls_md5_starts(&ctx) == 0; }
23+
inline bool update(const uint8_t* data, std::size_t dataLen) { return mbedtls_md5_update(&ctx, data, dataLen) == 0; }
2424
inline bool update(std::string_view data) { return update(reinterpret_cast<const uint8_t*>(data.data()), data.length()); }
25-
inline bool finish(std::array<uint8_t, 16>& hash) { return mbedtls_md5_finish_ret(&ctx, hash.data()) == 0; }
25+
inline bool finish(std::array<uint8_t, 16>& hash) { return mbedtls_md5_finish(&ctx, hash.data()) == 0; }
2626

2727
private:
2828
mbedtls_md5_context ctx;
@@ -35,10 +35,10 @@ namespace OpenShock {
3535
SHA1() { mbedtls_sha1_init(&ctx); }
3636
~SHA1() { mbedtls_sha1_free(&ctx); }
3737

38-
inline bool begin() { return mbedtls_sha1_starts_ret(&ctx) == 0; }
39-
inline bool update(const uint8_t* data, std::size_t dataLen) { return mbedtls_sha1_update_ret(&ctx, data, dataLen) == 0; }
38+
inline bool begin() { return mbedtls_sha1_starts(&ctx) == 0; }
39+
inline bool update(const uint8_t* data, std::size_t dataLen) { return mbedtls_sha1_update(&ctx, data, dataLen) == 0; }
4040
inline bool update(std::string_view data) { return update(reinterpret_cast<const uint8_t*>(data.data()), data.length()); }
41-
inline bool finish(std::array<uint8_t, 20>& hash) { return mbedtls_sha1_finish_ret(&ctx, hash.data()) == 0; }
41+
inline bool finish(std::array<uint8_t, 20>& hash) { return mbedtls_sha1_finish(&ctx, hash.data()) == 0; }
4242

4343
private:
4444
mbedtls_sha1_context ctx;
@@ -51,10 +51,10 @@ namespace OpenShock {
5151
SHA256() { mbedtls_sha256_init(&ctx); }
5252
~SHA256() { mbedtls_sha256_free(&ctx); }
5353

54-
inline bool begin() { return mbedtls_sha256_starts_ret(&ctx, 0) == 0; }
55-
inline bool update(const uint8_t* data, std::size_t dataLen) { return mbedtls_sha256_update_ret(&ctx, data, dataLen) == 0; }
54+
inline bool begin() { return mbedtls_sha256_starts(&ctx, 0) == 0; }
55+
inline bool update(const uint8_t* data, std::size_t dataLen) { return mbedtls_sha256_update(&ctx, data, dataLen) == 0; }
5656
inline bool update(std::string_view data) { return update(reinterpret_cast<const uint8_t*>(data.data()), data.length()); }
57-
inline bool finish(std::array<uint8_t, 32>& hash) { return mbedtls_sha256_finish_ret(&ctx, hash.data()) == 0; }
57+
inline bool finish(std::array<uint8_t, 32>& hash) { return mbedtls_sha256_finish(&ctx, hash.data()) == 0; }
5858

5959
private:
6060
mbedtls_sha256_context ctx;

include/RGBPatternManager.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ namespace OpenShock {
4747
gpio_num_t m_gpioPin;
4848
uint8_t m_brightness; // 0-255
4949
std::vector<RGBState> m_pattern;
50-
rmt_obj_t* m_rmtHandle;
5150
TaskHandle_t m_taskHandle;
5251
SimpleMutex m_taskMutex;
5352
};

include/radio/RFTransmitter.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace OpenShock {
2323

2424
inline gpio_num_t GetTxPin() const { return m_txPin; }
2525

26-
inline bool ok() const { return m_rmtHandle != nullptr && m_queueHandle != nullptr && m_taskHandle != nullptr; }
26+
inline bool ok() const { return m_txPin != GPIO_NUM_NC && m_queueHandle != nullptr && m_taskHandle != nullptr; }
2727

2828
bool SendCommand(ShockerModelType model, uint16_t shockerId, ShockerCommandType type, uint8_t intensity, uint16_t durationMs, bool overwriteExisting = true);
2929
void ClearPendingCommands();
@@ -35,7 +35,6 @@ namespace OpenShock {
3535
struct Command;
3636

3737
gpio_num_t m_txPin;
38-
rmt_obj_t* m_rmtHandle;
3938
QueueHandle_t m_queueHandle;
4039
TaskHandle_t m_taskHandle;
4140
};

include/span.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ This is an implementation of C++20's std::span
1414
#include <cstddef>
1515
#include <cstdint>
1616
#include <type_traits>
17+
#include <exception>
1718

1819
#ifndef TCB_SPAN_NO_EXCEPTIONS
1920
// Attempt to discover whether we're being compiled with exception support

platformio.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
; https://docs.platformio.org/page/projectconf.html
1010

1111
[env]
12-
platform = espressif32 @ 6.12.0
12+
platform = https://github.com/pioarduino/platform-espressif32/releases/download/55.03.36/platform-espressif32.zip
1313
board = az-delivery-devkit-v4 ; Overridden per board
1414
framework = arduino
1515

@@ -54,7 +54,7 @@ build_src_flags =
5454
lib_deps =
5555
https://github.com/google/flatbuffers#8b02fe6178427b96aea25396b53ea4ae8cadd7d8
5656
https://github.com/OpenShock/ESPAsyncWebServer#469816c6bd287e3ecdda9e519c2532db019aa3c1
57-
https://github.com/OpenShock/BadWebSockets#ec5eae735d94b3774498f8fd7564dce1cd5a5339
57+
https://github.com/OpenShock/BadWebSockets#93de92a3a64f87f9a7cd24e6abf8f67f076f2f16
5858
custom_openshock.flash_size = 4MB; Can be overridden per board
5959
board_build.filesystem = littlefs
6060
board_build.embed_files = certificates/x509_crt_bundle

src/CaptivePortal.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
const char* const TAG = "CaptivePortal";
66

7+
#include "CaptivePortalConfig.h"
78
#include "CaptivePortalInstance.h"
89
#include "CommandHandler.h"
910
#include "config/Config.h"
@@ -155,9 +156,10 @@ bool CaptivePortal::Init()
155156
void CaptivePortal::SetAlwaysEnabled(bool alwaysEnabled)
156157
{
157158
s_alwaysEnabled = alwaysEnabled;
158-
Config::SetCaptivePortalConfig({
159+
CaptivePortalConfig config = {
159160
.alwaysEnabled = alwaysEnabled,
160-
});
161+
};
162+
Config::SetCaptivePortalConfig(config);
161163
}
162164
bool CaptivePortal::IsAlwaysEnabled()
163165
{

src/OtaUpdateManager.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,12 @@ static void otaum_updatetask(void* arg)
393393

394394
// Increase task watchdog timeout.
395395
// Prevents panics on some ESP32s when clearing large partitions.
396-
esp_task_wdt_init(15, true);
396+
esp_task_wdt_config_t twdt_config = {
397+
.timeout_ms = 15,
398+
.idle_core_mask = (1 << CONFIG_FREERTOS_NUMBER_OF_CORES) - 1, // Bitmask of all cores
399+
.trigger_panic = true,
400+
};
401+
ESP_ERROR_CHECK(esp_task_wdt_init(&twdt_config));
397402

398403
// Flash app and filesystem partitions.
399404
if (!_flashFilesystemPartition(filesystemPartition, release.filesystemBinaryUrl, release.filesystemBinaryHash)) continue;
@@ -407,7 +412,8 @@ static void otaum_updatetask(void* arg)
407412
}
408413

409414
// Set task watchdog timeout back to default.
410-
esp_task_wdt_init(5, true);
415+
twdt_config.timeout_ms = 5;
416+
ESP_ERROR_CHECK(esp_task_wdt_init(&twdt_config));
411417

412418
// Send reboot message.
413419
_sendProgressMessage(Serialization::Types::OtaUpdateProgressTask::Rebooting, 0.0f);

src/RGBPatternManager.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ using namespace OpenShock;
1616
// TODO: Support multiple LEDs ?
1717
// TODO: Support other LED types ?
1818

19+
const int32_t kRmtTimeoutMs = 100;
20+
1921
RGBPatternManager::RGBPatternManager(gpio_num_t gpioPin)
2022
: m_gpioPin(GPIO_NUM_NC)
2123
, m_brightness(255)
2224
, m_pattern()
23-
, m_rmtHandle(nullptr)
2425
, m_taskHandle(nullptr)
2526
, m_taskMutex()
2627
{
@@ -34,14 +35,17 @@ RGBPatternManager::RGBPatternManager(gpio_num_t gpioPin)
3435
return;
3536
}
3637

37-
m_rmtHandle = rmtInit(gpioPin, RMT_TX_MODE, RMT_MEM_64);
38-
if (m_rmtHandle == NULL) {
38+
bool success = rmtInit(gpioPin, RMT_TX_MODE, RMT_MEM_NUM_BLOCKS_1, 10'000'000); // RMT_MEM_64, 10MHz
39+
if (!success) {
3940
OS_LOGE(TAG, "Failed to initialize RMT for pin %hhi", gpioPin);
4041
return;
4142
}
4243

43-
float realTick = rmtSetTick(m_rmtHandle, 100.F);
44-
OS_LOGD(TAG, "RMT tick is %f ns for pin %hhi", realTick, gpioPin);
44+
success = rmtSetEOT(gpioPin, 0);
45+
if (!success) {
46+
OS_LOGE(TAG, "Failed to set EOT level for pin %hhi", gpioPin);
47+
return;
48+
}
4549

4650
SetBrightness(20);
4751

@@ -52,7 +56,7 @@ RGBPatternManager::~RGBPatternManager()
5256
{
5357
ClearPattern();
5458

55-
rmtDeinit(m_rmtHandle);
59+
rmtDeinit(m_gpioPin);
5660
}
5761

5862
void RGBPatternManager::SetPattern(const RGBState* pattern, std::size_t patternLength)
@@ -106,8 +110,8 @@ void RGBPatternManager::RunPattern(void* arg)
106110
{
107111
RGBPatternManager* thisPtr = reinterpret_cast<RGBPatternManager*>(arg);
108112

109-
rmt_obj_t* rmtHandle = thisPtr->m_rmtHandle;
110113
uint8_t brightness = thisPtr->m_brightness;
114+
gpio_num_t gpioPin = thisPtr->m_gpioPin;
111115
std::vector<RGBState>& pattern = thisPtr->m_pattern;
112116

113117
std::array<rmt_data_t, 24> led_data; // 24 bits per LED (8 bits per color * 3 colors)
@@ -143,7 +147,7 @@ void RGBPatternManager::RunPattern(void* arg)
143147
}
144148

145149
// Send the data
146-
rmtWriteBlocking(rmtHandle, led_data.data(), led_data.size());
150+
rmtWrite(gpioPin, led_data.data(), led_data.size(), kRmtTimeoutMs);
147151
vTaskDelay(pdMS_TO_TICKS(state.duration));
148152
}
149153
}

src/VisualStateManager.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ const char* const TAG = "VisualStateManager";
1313

1414
#include <memory>
1515

16+
#include "esp_wifi.h"
17+
1618
#ifndef OPENSHOCK_LED_GPIO
1719
#define OPENSHOCK_LED_GPIO GPIO_NUM_NC
1820
#endif // OPENSHOCK_LED_GPIO

src/http/HTTPRequestManager.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const char* const TAG = "HTTPRequestManager";
1111
#include "util/StringUtils.h"
1212

1313
#include <HTTPClient.h>
14+
#include <WiFi.h>
1415

1516
#include <algorithm>
1617
#include <memory>

0 commit comments

Comments
 (0)