Skip to content

Fix WiFiStation buffer management #134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions libraries/ESPhost/src/CEspCommunication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,15 @@ bool CEspCom::getMsgForStation(CMsg &msg) {
return false;
}

/* -------------------------------------------------------------------------- */
int CEspCom::peekMsgSizeForStation() {
/* -------------------------------------------------------------------------- */
if(CEspCom::rxStationQueue.size() > 0) {
return CEspCom::rxStationQueue.front().get_size();
}
return 0;
}

/* -------------------------------------------------------------------------- */
bool CEspCom::getMsgForSoftAp(CMsg &msg) {
/* -------------------------------------------------------------------------- */
Expand Down
1 change: 1 addition & 0 deletions libraries/ESPhost/src/CEspCommunication.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class CEspCom {
static bool storeStationMsg(CMsg &msg);
static bool storeSoftApMsg(CMsg &msg);
static bool getMsgForStation(CMsg &msg);
static int peekMsgSizeForStation();
static bool getMsgForSoftAp(CMsg &msg);

static void clearStationRx();
Expand Down
13 changes: 11 additions & 2 deletions libraries/ESPhost/src/CEspControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,11 @@ int CEspControl::process_test_messages(CCtrlMsgWrapper* response) {
return 0;
}


/* -------------------------------------------------------------------------- */
uint8_t *CEspControl::getStationRx(uint8_t &if_num, uint16_t &dim) {
/* -------------------------------------------------------------------------- */
uint8_t *rv = nullptr;
CMsg msg;
CMsg msg;
__disable_irq();
bool res = CEspCom::getMsgForStation(msg);
if(!res) {
Expand All @@ -91,6 +90,16 @@ uint8_t *CEspControl::getStationRx(uint8_t &if_num, uint16_t &dim) {
return rv;
}

/* -------------------------------------------------------------------------- */
uint16_t CEspControl::peekStationRxMsgSize() {
/* -------------------------------------------------------------------------- */
uint16_t res;
__disable_irq();
res = CEspCom::peekMsgSizeForStation();
__enable_irq();
return res;
}

/* -------------------------------------------------------------------------- */
uint8_t *CEspControl::getSoftApRx(uint8_t &if_num, uint16_t &dim) {
/* -------------------------------------------------------------------------- */
Expand Down
1 change: 1 addition & 0 deletions libraries/ESPhost/src/CEspControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ class CEspControl {
int sendBuffer(ESP_INTERFACE_TYPE type, uint8_t num, uint8_t *buf, uint16_t dim);

uint8_t *getStationRx(uint8_t &if_num, uint16_t &dim);
uint16_t peekStationRxMsgSize();
uint8_t *getSoftApRx(uint8_t &if_num, uint16_t &dim);


Expand Down
23 changes: 12 additions & 11 deletions libraries/lwIpWrapper/src/CNetIf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1374,27 +1374,28 @@ void CWifiStation::task()
/* -------------------------------------------------------------------------- */
/* get messages and process it */
uint8_t if_num;
uint16_t dim;
uint16_t dim = 0;
uint8_t* buf = nullptr;
struct pbuf* p = nullptr;

/* shall we verify something about if_num??? */
do {
buf = CEspControl::getInstance().getStationRx(if_num, dim);

if (buf != nullptr) {
// Serial.println("Wifi Station - msg rx");

struct pbuf* p = pbuf_alloc(PBUF_RAW, dim, PBUF_RAM);
if (p != NULL) {
dim = CEspControl::getInstance().peekStationRxMsgSize();
if (dim > 0)
{
p = pbuf_alloc(PBUF_RAW, dim, PBUF_RAM);
if (p != nullptr)
{
buf = CEspControl::getInstance().getStationRx(if_num, dim);
/* Copy ethernet frame into pbuf */
pbuf_take((struct pbuf*)p, (uint8_t*)buf, (uint32_t)dim);
delete[] buf;

if (ni.input(p, &ni) != ERR_OK) {
pbuf_free(p);
}
delete[] buf;
}
}
} while(buf != nullptr);
} while(dim > 0 && p != nullptr);


#if LWIP_DHCP
Expand Down