@@ -48,7 +48,7 @@ namespace chip {
48
48
namespace DeviceLayer {
49
49
50
50
namespace Internal {
51
- extern CHIP_ERROR InitLwIPCoreLock (void );
51
+ extern CHIP_ERROR InitLwIPCoreLock ();
52
52
}
53
53
54
54
PlatformManagerImpl PlatformManagerImpl::sInstance ;
@@ -60,20 +60,25 @@ static int app_entropy_source(void * data, unsigned char * output, size_t len, s
60
60
return 0 ;
61
61
}
62
62
63
- CHIP_ERROR PlatformManagerImpl::_InitChipStack (void )
63
+ CHIP_ERROR PlatformManagerImpl::_InitChipStack ()
64
64
{
65
65
// Arrange for CHIP-encapsulated ESP32 errors to be translated to text
66
66
Internal::ESP32Utils::RegisterESP32ErrorFormatter ();
67
67
// Make sure the LwIP core lock has been initialized
68
68
ReturnErrorOnFailure (Internal::InitLwIPCoreLock ());
69
+
70
+ // Initialize TCP/IP network interface, which internally initializes LwIP stack. We have to
71
+ // call this before the usage of PacketBufferHandle::New() because in case of LwIP-based pool
72
+ // allocator, the LwIP pool allocator uses the LwIP stack.
73
+ esp_err_t err = esp_netif_init ();
74
+ VerifyOrReturnError (err == ESP_OK, Internal::ESP32Utils::MapError (err));
75
+
69
76
// Arrange for the ESP event loop to deliver events into the CHIP Device layer.
70
- esp_err_t err = esp_event_handler_register (IP_EVENT, ESP_EVENT_ANY_ID, PlatformManagerImpl::HandleESPSystemEvent, NULL );
71
- if (err != ESP_OK)
72
- {
73
- return Internal::ESP32Utils::MapError (err);
74
- }
77
+ err = esp_event_handler_register (IP_EVENT, ESP_EVENT_ANY_ID, PlatformManagerImpl::HandleESPSystemEvent, nullptr );
78
+ VerifyOrReturnError (err == ESP_OK, Internal::ESP32Utils::MapError (err));
79
+
75
80
mStartTime = System::SystemClock ().GetMonotonicTimestamp ();
76
- ReturnErrorOnFailure (chip::Crypto::add_entropy_source (app_entropy_source, NULL , 16 ));
81
+ ReturnErrorOnFailure (chip::Crypto::add_entropy_source (app_entropy_source, nullptr , 16 ));
77
82
78
83
// Call _InitChipStack() on the generic implementation base class
79
84
// to finish the initialization process.
@@ -108,6 +113,7 @@ void PlatformManagerImpl::_Shutdown()
108
113
Internal::GenericPlatformManagerImpl_FreeRTOS<PlatformManagerImpl>::_Shutdown ();
109
114
110
115
esp_event_handler_unregister (IP_EVENT, ESP_EVENT_ANY_ID, PlatformManagerImpl::HandleESPSystemEvent);
116
+ esp_netif_deinit ();
111
117
}
112
118
113
119
void PlatformManagerImpl::HandleESPSystemEvent (void * arg, esp_event_base_t eventBase, int32_t eventId, void * eventData)
0 commit comments