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

Commit 262dcab

Browse files
authored
Merge pull request #567 from erjiaqing/esp-3.3
[ESP32] Add ESP-IDF 3.3 support
2 parents 79320bf + 6d89d76 commit 262dcab

File tree

4 files changed

+59
-17
lines changed

4 files changed

+59
-17
lines changed

build/esp32/components/openweave/component.mk

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -122,17 +122,6 @@ endif
122122
COMPONENT_ADD_INCLUDEDIRS = project-config \
123123
$(REL_OUTPUT_DIR)/include
124124

125-
# Linker flags to be included when building other components that use Weave.
126-
COMPONENT_ADD_LDFLAGS = -L$(OUTPUT_DIR)/lib \
127-
-lWeave \
128-
-lInetLayer \
129-
-lmincrypt \
130-
-lnlfaultinjection \
131-
-lSystemLayer \
132-
-luECC \
133-
-lWarm \
134-
-lDeviceLayer
135-
136125
# Tell the ESP-IDF build system that the OpenWeave component defines its own build
137126
# and clean targets.
138127
COMPONENT_OWNBUILDTARGET = 1
@@ -143,7 +132,7 @@ COMPONENT_OWNCLEANTARGET = 1
143132
# Build Rules
144133
# ==================================================
145134

146-
.PHONY : check-config-args-updated
135+
.PHONY : check-config-args-updated install-weave build-weave configure-weave
147136
check-config-args-updated : | $(OUTPUT_DIR)
148137
echo $(OPENWEAVE_ROOT)/configure -C $(CONFIGURE_OPTIONS) > $(OUTPUT_DIR)/config.args.tmp; \
149138
(test -r $(OUTPUT_DIR)/config.args && cmp -s $(OUTPUT_DIR)/config.args.tmp $(OUTPUT_DIR)/config.args) || \
@@ -171,11 +160,34 @@ build-weave : configure-weave
171160
echo "BUILD OPENWEAVE..."
172161
MAKEFLAGS= make -C $(OUTPUT_DIR) --no-print-directory all
173162

174-
install-weave : | build-weave
163+
install-weave : build-weave
175164
echo "INSTALL OPENWEAVE..."
176165
MAKEFLAGS= make -C $(OUTPUT_DIR) --no-print-directory install
177166

178-
build : build-weave install-weave
167+
# Openweave build routine builds several .a libraries (lib{Weave|InetLayer|...}.a)
168+
# instead of a single library (libopenweave.a) which is expected by esp-idf 3.3
169+
# Here, we extract the libraries and repack them into a one big library
170+
OPENWEAVE_STATIC_LIBRARIES = \
171+
$(OUTPUT_DIR)/lib/libWeave.a \
172+
$(OUTPUT_DIR)/lib/libInetLayer.a \
173+
$(OUTPUT_DIR)/lib/libmincrypt.a \
174+
$(OUTPUT_DIR)/lib/libnlfaultinjection.a \
175+
$(OUTPUT_DIR)/lib/libSystemLayer.a \
176+
$(OUTPUT_DIR)/lib/libuECC.a \
177+
$(OUTPUT_DIR)/lib/libWarm.a \
178+
$(OUTPUT_DIR)/lib/libDeviceLayer.a \
179+
180+
# Extract and repack the %.a files into a single libopenweave.a
181+
$(OUTPUT_DIR)/libopenweave.a : install-weave
182+
mkdir -p $(OUTPUT_DIR)/libopenweave.a.tmp
183+
cd $(OUTPUT_DIR)/libopenweave.a.tmp; \
184+
for files in $(OPENWEAVE_STATIC_LIBRARIES) ; do \
185+
$(AR) -x $$files ; \
186+
done
187+
$(AR) cru $@ $(OUTPUT_DIR)/libopenweave.a.tmp/*.o
188+
rm -rf $(OUTPUT_DIR)/libopenweave.a.tmp
189+
190+
build : build-weave install-weave $(OUTPUT_DIR)/libopenweave.a
179191

180192
clean:
181193
echo "RM $(OUTPUT_DIR)"

src/adaptations/device-layer/ESP32/AESBlockCipher.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <Weave/Support/crypto/AESBlockCipher.h>
3131

3232
#include <hwcrypto/aes.h>
33+
#include <esp_system.h>
3334

3435
namespace nl {
3536
namespace Weave {
@@ -64,7 +65,11 @@ void AES128BlockCipherEnc::EncryptBlock(const uint8_t *inBlock, uint8_t *outBloc
6465

6566
esp_aes_init(&ctx);
6667
esp_aes_setkey(&ctx, mKey, kKeyLengthBits);
68+
#if ESP_IDF_VERSION_MAJOR > 3 || (ESP_IDF_VERSION_MAJOR == 3 && ESP_IDF_VERSION_MINOR >= 2)
69+
esp_aes_crypt_ecb(&ctx, ESP_AES_ENCRYPT, inBlock, outBlock);
70+
#else
6771
esp_aes_encrypt(&ctx, inBlock, outBlock);
72+
#endif
6873
esp_aes_free(&ctx);
6974
}
7075

@@ -79,7 +84,11 @@ void AES128BlockCipherDec::DecryptBlock(const uint8_t *inBlock, uint8_t *outBloc
7984

8085
esp_aes_init(&ctx);
8186
esp_aes_setkey(&ctx, mKey, kKeyLengthBits);
87+
#if ESP_IDF_VERSION_MAJOR > 3 || (ESP_IDF_VERSION_MAJOR == 3 && ESP_IDF_VERSION_MINOR >= 2)
88+
esp_aes_crypt_ecb(&ctx, ESP_AES_DECRYPT, inBlock, outBlock);
89+
#else
8290
esp_aes_decrypt(&ctx, inBlock, outBlock);
91+
#endif
8392
esp_aes_free(&ctx);
8493
}
8594

@@ -109,7 +118,11 @@ void AES256BlockCipherEnc::EncryptBlock(const uint8_t *inBlock, uint8_t *outBloc
109118

110119
esp_aes_init(&ctx);
111120
esp_aes_setkey(&ctx, mKey, kKeyLengthBits);
121+
#if ESP_IDF_VERSION_MAJOR > 3 || (ESP_IDF_VERSION_MAJOR == 3 && ESP_IDF_VERSION_MINOR >= 2)
122+
esp_aes_crypt_ecb(&ctx, ESP_AES_ENCRYPT, inBlock, outBlock);
123+
#else
112124
esp_aes_encrypt(&ctx, inBlock, outBlock);
125+
#endif
113126
esp_aes_free(&ctx);
114127
}
115128

@@ -124,7 +137,11 @@ void AES256BlockCipherDec::DecryptBlock(const uint8_t *inBlock, uint8_t *outBloc
124137

125138
esp_aes_init(&ctx);
126139
esp_aes_setkey(&ctx, mKey, kKeyLengthBits);
140+
#if ESP_IDF_VERSION_MAJOR > 3 || (ESP_IDF_VERSION_MAJOR == 3 && ESP_IDF_VERSION_MINOR >= 2)
141+
esp_aes_crypt_ecb(&ctx, ESP_AES_DECRYPT, inBlock, outBlock);
142+
#else
127143
esp_aes_decrypt(&ctx, inBlock, outBlock);
144+
#endif
128145
esp_aes_free(&ctx);
129146
}
130147

src/adaptations/device-layer/ESP32/ConnectivityManagerImpl.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
#include "esp_event.h"
3232
#include "esp_wifi.h"
33+
#include "esp_system.h"
3334

3435
#include <lwip/ip_addr.h>
3536
#include <lwip/netif.h>
@@ -78,7 +79,11 @@ ConnectivityManager::WiFiStationMode ConnectivityManagerImpl::_GetWiFiStationMod
7879
if (mWiFiStationMode != kWiFiStationMode_ApplicationControlled)
7980
{
8081
bool autoConnect;
81-
mWiFiStationMode = (esp_wifi_get_auto_connect(&autoConnect) == ESP_OK && autoConnect)
82+
#pragma GCC diagnostic push
83+
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
84+
WEAVE_ERROR err = esp_wifi_get_auto_connect(&autoConnect);
85+
#pragma GCC diagnostic pop
86+
mWiFiStationMode = (err == ESP_OK && autoConnect)
8287
? kWiFiStationMode_Enabled
8388
: kWiFiStationMode_Disabled;
8489
}
@@ -99,7 +104,10 @@ WEAVE_ERROR ConnectivityManagerImpl::_SetWiFiStationMode(WiFiStationMode val)
99104
if (val != kWiFiStationMode_ApplicationControlled)
100105
{
101106
bool autoConnect = (val == kWiFiStationMode_Enabled);
107+
#pragma GCC diagnostic push
108+
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
102109
err = esp_wifi_set_auto_connect(autoConnect);
110+
#pragma GCC diagnostic pop
103111
SuccessOrExit(err);
104112

105113
SystemLayer.ScheduleWork(DriveStationState, NULL);
@@ -934,8 +942,13 @@ void ConnectivityManagerImpl::UpdateInternetConnectivityState(void)
934942
if (netif != NULL && netif_is_up(netif) && netif_is_link_up(netif))
935943
{
936944
// Check if a DNS server is currently configured. If so...
945+
#if ESP_IDF_VERSION_MAJOR > 3 || (ESP_IDF_VERSION_MAJOR == 3 && ESP_IDF_VERSION_MINOR >= 3)
946+
const ip_addr_t* dnsServerAddr = dns_getserver(0);
947+
if (!ip_addr_isany_val(*dnsServerAddr))
948+
#else
937949
ip_addr_t dnsServerAddr = dns_getserver(0);
938950
if (!ip_addr_isany_val(dnsServerAddr))
951+
#endif
939952
{
940953
// If the station interface has been assigned an IPv4 address, and has
941954
// an IPv4 gateway, then presume that the device has IPv4 Internet

src/inet/DNSResolver.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@
3636
#include <lwip/dns.h>
3737
#include <lwip/tcpip.h>
3838

39-
#if LWIP_VERSION_MAJOR < 2
39+
#ifndef LWIP_DNS_FOUND_CALLBACK_TYPE
4040
#define LWIP_DNS_FOUND_CALLBACK_TYPE dns_found_callback
41-
#endif // LWIP_VERSION_MAJOR < 2
41+
#endif
4242
#endif // WEAVE_SYSTEM_CONFIG_USE_LWIP
4343

4444
#if WEAVE_SYSTEM_CONFIG_USE_SOCKETS

0 commit comments

Comments
 (0)