Skip to content

Commit

Permalink
Heap addendum to handle changes in NON-OS SDK 3.0.x
Browse files Browse the repository at this point in the history
The NON-OS SDK 3.0.x has breaking changes to pvPortMalloc. They added one more
argument for selecting a heap. To avoid breaking the build, I renamed their
broken version pvEsprMalloc. To be used, the LIBS need to be edited.

They also added pvPortZallocIram and pvPortCallocIram, which are not a
problem.

WPA2 Enterprise connect crashing is fixed at v3.0.2 and up.
  • Loading branch information
mhightower83 committed Dec 7, 2022
1 parent da48a52 commit f967e98
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 6 deletions.
47 changes: 42 additions & 5 deletions cores/esp8266/heap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,25 +356,25 @@ void system_show_malloc(void)
void* IRAM_ATTR pvPortMalloc(size_t size, const char* file, int line)
{
HeapSelectDram ephemeral;
return heap_pvPortMalloc(size, file, line);;
return heap_pvPortMalloc(size, file, line);;
}

void* IRAM_ATTR pvPortCalloc(size_t count, size_t size, const char* file, int line)
{
HeapSelectDram ephemeral;
return heap_pvPortCalloc(count, size, file, line);
return heap_pvPortCalloc(count, size, file, line);
}

void* IRAM_ATTR pvPortRealloc(void *ptr, size_t size, const char* file, int line)
{
HeapSelectDram ephemeral;
return heap_pvPortRealloc(ptr, size, file, line);
return heap_pvPortRealloc(ptr, size, file, line);
}

void* IRAM_ATTR pvPortZalloc(size_t size, const char* file, int line)
{
HeapSelectDram ephemeral;
return heap_pvPortZalloc(size, file, line);
return heap_pvPortZalloc(size, file, line);
}

void IRAM_ATTR vPortFree(void *ptr, const char* file, int line)
Expand All @@ -384,7 +384,44 @@ void IRAM_ATTR vPortFree(void *ptr, const char* file, int line)
// correct context. umm_malloc free internally determines the correct heap.
HeapSelectDram ephemeral;
#endif
return heap_vPortFree(ptr, file, line);
return heap_vPortFree(ptr, file, line);
}

////////////////////////////////////////////////////////////////////////////////
/*
New for NON-OS SDK 3.0.0 and up
Needed for WPA2 Enterprise support. This was not present in SDK pre 3.0
The NON-OS SDK 3.0.x has breaking changes to pvPortMalloc. They added one more
argument for selecting a heap. To avoid breaking the build, I renamed their
broken version pvEsprMalloc. To be used, the LIBS need to be edited.
They also added pvPortZallocIram and pvPortCallocIram, which are not a
problem.
WPA2 Enterprise connect crashing is fixed at v3.0.2 and up.
*/
void* IRAM_ATTR pvEsprMalloc(size_t size, const char* file, int line, bool iram)
{
if (iram) {
HeapSelectIram ephemeral;
return heap_pvPortMalloc(size, file, line);;
} else {
HeapSelectDram ephemeral;
return heap_pvPortMalloc(size, file, line);;
}
}

void* IRAM_ATTR pvPortCallocIram(size_t count, size_t size, const char* file, int line)
{
HeapSelectIram ephemeral;
return heap_pvPortCalloc(count, size, file, line);
}

void* IRAM_ATTR pvPortZallocIram(size_t size, const char* file, int line)
{
HeapSelectIram ephemeral;
return heap_pvPortZalloc(size, file, line);
}

};
26 changes: 25 additions & 1 deletion cores/esp8266/wpa2_eap_patch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,25 @@
* modules.
*
*/

#include <string.h>
#include <ets_sys.h>
#include <pgmspace.h>
#include "coredecls.h"

#if defined(NONOSDK22x_190703) || \
defined(NONOSDK22x_191122) || \
defined(NONOSDK22x_191105) || \
defined(NONOSDK22x_191124) || \
defined(NONOSDK22x_190313) || \
defined(NONOSDK221) || \
defined(NONOSDK3V0)

// These are broken for WPA Enterprise - no patch leave as is for now:
// NONOSDK300
// NONOSDK301
//
// These appear to work without a patch NONOSDK302 - NONOSDK305

#ifdef DEBUG_WPA2_EAP_PATCH
#include "esp8266_undocumented.h"
#define DEBUG_PRINTF ets_uart_printf
Expand Down Expand Up @@ -141,6 +154,17 @@ void patch_wpa2_eap_vPortFree_a12(void *ptr, const char* file, int line, void* a

};

#elif defined(NONOSDK300) || defined(NONOSDK301)
#error "NONOSDK300 and NONOSDK301 will crash with WPA2 Enterpise connection. Use NONOSDK302 or later"

#elif defined(NONOSDK302) || defined(NONOSDK303) || defined(NONOSDK304) || defined(NONOSDK305)
// WPA2 Enterpise connections appear to work without crashing

#else
#error "Internal error: A new SDK has been added. This module must be updated."
#error " Need to test WPA2 Enterpise connectivity."
#endif

/*
* This will minimize code space for non-wifi enterprise sketches which do not
* need the patch and disable_extra4k_at_link_time().
Expand Down

0 comments on commit f967e98

Please sign in to comment.