Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fbaae21011 | ||
|
|
fa2064b957 | ||
|
|
21a194f43d | ||
|
|
b255402659 | ||
|
|
dfabfbb921 | ||
|
|
3b36a70c9a | ||
|
|
d1386a8e9d |
@@ -20,8 +20,6 @@ env.ParseCustomOptions(platform)
|
||||
env.ParseCustomFlashLayout(platform, board)
|
||||
# Add flash layout C defines
|
||||
env.AddFlashLayout(board)
|
||||
# Write custom header options
|
||||
env.ApplyCustomOptions(platform)
|
||||
# Export board manifest for ltchiptool
|
||||
env.ExportBoardData(board)
|
||||
# Print information about versions and custom options
|
||||
|
||||
@@ -184,6 +184,9 @@ class LibraryQueue:
|
||||
else:
|
||||
self.env.Append(CPPPATH=self.includes)
|
||||
|
||||
# prepend headers with custom options
|
||||
self.env.ApplyCustomOptions(self.env.PioPlatform())
|
||||
|
||||
# clone the environment for the whole library queue
|
||||
queue_env = self.env.Clone()
|
||||
# add private options to the cloned environment
|
||||
|
||||
@@ -27,6 +27,40 @@ static void wifiEventTask(void *arg) {
|
||||
}
|
||||
}
|
||||
|
||||
// There is a race condition, when we have an event about a successful
|
||||
// connection but no SSID yet returned by BDK. Even a single millisecond
|
||||
// delay should prevent this from happening. It's better to waste a bit
|
||||
// of time here than to lose a valid connection down the line.
|
||||
static String waitForValidSSID(WiFiClass *pWiFi) {
|
||||
String result;
|
||||
|
||||
// Read the initial value that might just be available already.
|
||||
result = pWiFi->SSID();
|
||||
|
||||
if (!result.length()) {
|
||||
std::size_t i = 0;
|
||||
for (; i < 10; i++) {
|
||||
// Delay and query again.
|
||||
delay(1);
|
||||
result = pWiFi->SSID();
|
||||
|
||||
if (result.length()) {
|
||||
LT_DM(WIFI, "Got valid SSID after %u delays", i + 1);
|
||||
break;
|
||||
}
|
||||
|
||||
// It's a good idea to yield.
|
||||
yield();
|
||||
}
|
||||
|
||||
if (!result.length()) {
|
||||
LT_WM(WIFI, "Could not obtain a valid SSID after %u delays", i);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void wifiEventSendArduino(EventId event) {
|
||||
event = (EventId)(RW_EVT_ARDUINO | event);
|
||||
wifiStatusCallback((rw_evt_type *)&event);
|
||||
@@ -52,11 +86,6 @@ void wifiEventHandler(rw_evt_type event) {
|
||||
|
||||
LT_DM(WIFI, "BK event %u", event);
|
||||
|
||||
if (event <= RW_EVT_STA_GOT_IP)
|
||||
pDATA->lastStaEvent = event;
|
||||
else
|
||||
pDATA->lastApEvent = event;
|
||||
|
||||
EventId eventId;
|
||||
EventInfo eventInfo;
|
||||
String ssid;
|
||||
@@ -103,7 +132,7 @@ void wifiEventHandler(rw_evt_type event) {
|
||||
|
||||
case RW_EVT_STA_CONNECTED:
|
||||
eventId = ARDUINO_EVENT_WIFI_STA_CONNECTED;
|
||||
ssid = pWiFi->SSID();
|
||||
ssid = waitForValidSSID(pWiFi);
|
||||
eventInfo.wifi_sta_connected.ssid_len = ssid.length();
|
||||
eventInfo.wifi_sta_connected.channel = pWiFi->channel();
|
||||
eventInfo.wifi_sta_connected.authmode = pWiFi->getEncryption();
|
||||
@@ -145,5 +174,13 @@ void wifiEventHandler(rw_evt_type event) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Publish state update only after the event data is retrieved.
|
||||
// This relates to the race condition with RW_EVT_STA_CONNECTED.
|
||||
if (event <= RW_EVT_STA_GOT_IP) {
|
||||
pDATA->lastStaEvent = event;
|
||||
} else {
|
||||
pDATA->lastApEvent = event;
|
||||
}
|
||||
|
||||
pWiFi->postEvent(eventId, eventInfo);
|
||||
}
|
||||
|
||||
9
cores/beken-72xx/base/config/tls_config.h
Normal file
9
cores/beken-72xx/base/config/tls_config.h
Normal file
@@ -0,0 +1,9 @@
|
||||
/* Copyright (c) Kuba Szczodrzyński 2024-05-18. */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include_next "tls_config.h"
|
||||
|
||||
// allow more entropy sources
|
||||
#undef MBEDTLS_ENTROPY_MAX_SOURCES
|
||||
#define MBEDTLS_ENTROPY_MAX_SOURCES 10
|
||||
@@ -31,9 +31,34 @@ static const char *hostName;
|
||||
NETIF_DECLARE_EXT_CALLBACK(netif_callback)
|
||||
#endif
|
||||
|
||||
static inline void freeAllocatedStrings(const std::vector<char *> &strings) {
|
||||
for (auto &str : strings) {
|
||||
free(str);
|
||||
}
|
||||
}
|
||||
|
||||
mDNS::mDNS() {}
|
||||
|
||||
mDNS::~mDNS() {}
|
||||
mDNS::~mDNS() {
|
||||
cleanup();
|
||||
}
|
||||
|
||||
void mDNS::cleanup() {
|
||||
freeAllocatedStrings(services_name);
|
||||
services_name.clear();
|
||||
freeAllocatedStrings(services);
|
||||
services.clear();
|
||||
for (auto &record : records) {
|
||||
freeAllocatedStrings(record);
|
||||
}
|
||||
records.clear();
|
||||
|
||||
free((void *)hostName);
|
||||
hostName = NULL;
|
||||
|
||||
free((void *)instanceName);
|
||||
instanceName = NULL;
|
||||
}
|
||||
|
||||
static void mdnsTxtCallback(struct mdns_service *service, void *userdata) {
|
||||
size_t index = (size_t)userdata;
|
||||
@@ -42,8 +67,9 @@ static void mdnsTxtCallback(struct mdns_service *service, void *userdata) {
|
||||
|
||||
for (const auto record : records[index]) {
|
||||
err_t err = mdns_resp_add_service_txtitem(service, record, strlen(record));
|
||||
if (err != ERR_OK)
|
||||
return;
|
||||
if (err != ERR_OK) {
|
||||
LT_DM(MDNS, "Error %d while adding txt record: %s", err, record);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,12 +162,18 @@ bool mDNS::begin(const char *hostname) {
|
||||
}
|
||||
|
||||
void mDNS::end() {
|
||||
#ifdef LWIP_NETIF_EXT_STATUS_CALLBACK
|
||||
netif_remove_ext_callback(&netif_callback);
|
||||
#endif
|
||||
|
||||
struct netif *netif = netif_list;
|
||||
while (netif != NULL) {
|
||||
if (netif_is_up(netif))
|
||||
mdns_resp_remove_netif(netif);
|
||||
netif = netif->next;
|
||||
}
|
||||
|
||||
cleanup();
|
||||
}
|
||||
|
||||
bool mDNS::addServiceImpl(const char *name, const char *service, uint8_t proto, uint16_t port) {
|
||||
@@ -181,18 +213,17 @@ bool mDNS::addServiceImpl(const char *name, const char *service, uint8_t proto,
|
||||
}
|
||||
|
||||
bool mDNS::addServiceTxtImpl(const char *service, uint8_t proto, const char *item) {
|
||||
int8_t index = -1;
|
||||
for (uint8_t i = 0; i < services.size(); i++) {
|
||||
uint8_t i;
|
||||
for (i = 0; i < services.size(); i++) {
|
||||
// find a matching service
|
||||
if (strcmp(services[i], service) == 0 && protos[i] == proto) {
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (index == -1)
|
||||
if (i == services.size())
|
||||
return false;
|
||||
|
||||
records[index].push_back(strdup(item));
|
||||
records[i].push_back(strdup(item));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,14 +2,23 @@
|
||||
|
||||
#include "mDNS.h"
|
||||
|
||||
static char *ensureUnderscore(const char *value) {
|
||||
uint8_t len = strlen(value) + 1;
|
||||
static char *ensureUnderscore(char *value) {
|
||||
if (value[0] == '_') {
|
||||
return value;
|
||||
}
|
||||
size_t len = strlen(value) + 1 + 1; // 1 for underscore, 1 for null-terminator
|
||||
char *result = (char *)malloc(len);
|
||||
result[0] = '_';
|
||||
strcpy(result + 1, value + (value[0] == '_'));
|
||||
strcpy(result + 1, value);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline void freeIfCopied(const char *original, char *duplicate) {
|
||||
if ((duplicate) && (original != duplicate)) {
|
||||
free(duplicate);
|
||||
}
|
||||
}
|
||||
|
||||
void mDNS::setInstanceName(const char *name) {
|
||||
if (instanceName)
|
||||
free(instanceName);
|
||||
@@ -21,7 +30,7 @@ bool mDNS::addService(char *service, char *proto, uint16_t port) {
|
||||
uint8_t _proto = strncmp(proto + (proto[0] == '_'), "tcp", 3) == 0 ? MDNS_TCP : MDNS_UDP;
|
||||
|
||||
bool result = addServiceImpl(instanceName ? instanceName : "LT mDNS", _service, _proto, port);
|
||||
free(_service);
|
||||
freeIfCopied(service, _service);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -34,7 +43,7 @@ bool mDNS::addServiceTxt(char *service, char *proto, char *key, char *value) {
|
||||
sprintf(txt, "%s=%s", key, value);
|
||||
|
||||
bool result = addServiceTxtImpl(_service, _proto, txt);
|
||||
free(_service);
|
||||
freeIfCopied(service, _service);
|
||||
free(txt);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -51,6 +51,7 @@ class mDNS {
|
||||
private:
|
||||
bool addServiceImpl(const char *name, const char *service, uint8_t proto, uint16_t port);
|
||||
bool addServiceTxtImpl(const char *service, uint8_t proto, const char *item);
|
||||
void cleanup();
|
||||
|
||||
char *instanceName = NULL;
|
||||
|
||||
|
||||
@@ -15,8 +15,15 @@
|
||||
|
||||
// set lwIP debugging options according to LT config
|
||||
#if LT_DEBUG_LWIP
|
||||
// enable main debugging switch
|
||||
#undef LWIP_DEBUG
|
||||
#define LWIP_DEBUG 1
|
||||
// enable all messages
|
||||
#undef LWIP_DBG_MIN_LEVEL
|
||||
#define LWIP_DBG_MIN_LEVEL 0
|
||||
// enable all debugging types
|
||||
#undef LWIP_DBG_TYPES_ON
|
||||
#define LWIP_DBG_TYPES_ON 0xF8
|
||||
// make lwIP use printf() library
|
||||
#include <stdio.h>
|
||||
#undef LWIP_PLATFORM_DIAG
|
||||
|
||||
@@ -100,31 +100,31 @@ void lt_log_disable();
|
||||
#endif
|
||||
|
||||
// ESP32 compat
|
||||
#define log_printf(...) LT_I(__VA_ARGS__)
|
||||
#define log_v(...) LT_V(__VA_ARGS__)
|
||||
#define log_d(...) LT_D(__VA_ARGS__)
|
||||
#define log_i(...) LT_I(__VA_ARGS__)
|
||||
#define log_w(...) LT_W(__VA_ARGS__)
|
||||
#define log_e(...) LT_E(__VA_ARGS__)
|
||||
#define log_n(...) LT_E(__VA_ARGS__)
|
||||
#define isr_log_v(...) LT_V(__VA_ARGS__)
|
||||
#define isr_log_d(...) LT_D(__VA_ARGS__)
|
||||
#define isr_log_i(...) LT_I(__VA_ARGS__)
|
||||
#define isr_log_w(...) LT_W(__VA_ARGS__)
|
||||
#define isr_log_e(...) LT_E(__VA_ARGS__)
|
||||
#define isr_log_n(...) LT_E(__VA_ARGS__)
|
||||
#define ESP_LOGV(...) LT_V(__VA_ARGS__)
|
||||
#define ESP_LOGD(...) LT_D(__VA_ARGS__)
|
||||
#define ESP_LOGI(...) LT_I(__VA_ARGS__)
|
||||
#define ESP_LOGW(...) LT_W(__VA_ARGS__)
|
||||
#define ESP_LOGE(...) LT_E(__VA_ARGS__)
|
||||
#define ESP_EARLY_LOGV(...) LT_V(__VA_ARGS__)
|
||||
#define ESP_EARLY_LOGD(...) LT_D(__VA_ARGS__)
|
||||
#define ESP_EARLY_LOGI(...) LT_I(__VA_ARGS__)
|
||||
#define ESP_EARLY_LOGW(...) LT_W(__VA_ARGS__)
|
||||
#define ESP_EARLY_LOGE(...) LT_E(__VA_ARGS__)
|
||||
#define ets_printf(...) LT_I(__VA_ARGS__)
|
||||
#define ETS_PRINTF(...) LT_I(__VA_ARGS__)
|
||||
#define log_printf(...) LT_I(__VA_ARGS__)
|
||||
#define log_v(...) LT_V(__VA_ARGS__)
|
||||
#define log_d(...) LT_D(__VA_ARGS__)
|
||||
#define log_i(...) LT_I(__VA_ARGS__)
|
||||
#define log_w(...) LT_W(__VA_ARGS__)
|
||||
#define log_e(...) LT_E(__VA_ARGS__)
|
||||
#define log_n(...) LT_E(__VA_ARGS__)
|
||||
#define isr_log_v(...) LT_V(__VA_ARGS__)
|
||||
#define isr_log_d(...) LT_D(__VA_ARGS__)
|
||||
#define isr_log_i(...) LT_I(__VA_ARGS__)
|
||||
#define isr_log_w(...) LT_W(__VA_ARGS__)
|
||||
#define isr_log_e(...) LT_E(__VA_ARGS__)
|
||||
#define isr_log_n(...) LT_E(__VA_ARGS__)
|
||||
#define ESP_LOGV(tag, ...) LT_V(__VA_ARGS__)
|
||||
#define ESP_LOGD(tag, ...) LT_D(__VA_ARGS__)
|
||||
#define ESP_LOGI(tag, ...) LT_I(__VA_ARGS__)
|
||||
#define ESP_LOGW(tag, ...) LT_W(__VA_ARGS__)
|
||||
#define ESP_LOGE(tag, ...) LT_E(__VA_ARGS__)
|
||||
#define ESP_EARLY_LOGV(tag, ...) LT_V(__VA_ARGS__)
|
||||
#define ESP_EARLY_LOGD(tag, ...) LT_D(__VA_ARGS__)
|
||||
#define ESP_EARLY_LOGI(tag, ...) LT_I(__VA_ARGS__)
|
||||
#define ESP_EARLY_LOGW(tag, ...) LT_W(__VA_ARGS__)
|
||||
#define ESP_EARLY_LOGE(tag, ...) LT_E(__VA_ARGS__)
|
||||
#define ets_printf(...) LT_I(__VA_ARGS__)
|
||||
#define ETS_PRINTF(...) LT_I(__VA_ARGS__)
|
||||
|
||||
#define LT_RET(ret) \
|
||||
LT_E("ret=%d", ret); \
|
||||
|
||||
@@ -61,6 +61,9 @@ void attachInterruptParam(pin_size_t interruptNumber, voidFuncPtrParam callback,
|
||||
case CHANGE:
|
||||
#if LT_RTL8720C
|
||||
event = IRQ_FALL_RISE;
|
||||
// Prevents Change interrupt errors on RTL8710B chips.
|
||||
#elif LT_RTL8710B
|
||||
event = IRQ_RISE;
|
||||
#else
|
||||
LT_W("CHANGE interrupts not supported");
|
||||
#endif
|
||||
|
||||
@@ -13,7 +13,10 @@ custom_fw_version = 1.2.0
|
||||
|
||||
# custom build options (#defines, NOT compiler flags)
|
||||
custom_options.lwip =
|
||||
LWIP_IPV4 = 1
|
||||
# make sure to enable LT_DEBUG_LWIP as well
|
||||
NETIF_DEBUG = 0x80
|
||||
IP_DEBUG = 0x80
|
||||
TCP_DEBUG = 0x80
|
||||
custom_options.freertos =
|
||||
configUSE_TICK_HOOK = 1
|
||||
|
||||
@@ -82,7 +85,7 @@ To see debug messages from i.e. OTA, loglevel must also be changed.
|
||||
- `LT_DEBUG_OTA` (1) - OTA updates (`Update` library)
|
||||
- `LT_DEBUG_FDB` (0) - FlashDB debugging (macros within the library)
|
||||
- `LT_DEBUG_MDNS` (0) - mDNS client library
|
||||
- `LT_DEBUG_LWIP` (0) - enables `LWIP_DEBUG`, provides `LWIP_PLATFORM_DIAG`; per-module options (i.e. `TCP_DEBUG`) are off by default and need to be enabled separately
|
||||
- `LT_DEBUG_LWIP` (0) - enables `LWIP_DEBUG`, provides `LWIP_PLATFORM_DIAG`; per-module options (i.e. `TCP_DEBUG`) are off by default and need to be enabled separately - see example in `Project options` above
|
||||
- `LT_DEBUG_LWIP_ASSERT` (0) - enables assertions within lwIP (doesn't need `LT_DEBUG_LWIP`)
|
||||
|
||||
!!! tip
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/libretiny-eu/libretiny.git"
|
||||
},
|
||||
"version": "1.5.1",
|
||||
"version": "1.6.0",
|
||||
"frameworks": {
|
||||
"base": {
|
||||
"title": "Base Framework (SDK only)",
|
||||
|
||||
Reference in New Issue
Block a user