From 21dbc40e58a79f487d1ee34129f16e26cb6ba120 Mon Sep 17 00:00:00 2001 From: Uros Majstorovic Date: Sun, 9 Aug 2020 02:46:08 +0200 Subject: message handling iface updated --- fw/fe310/eos/cell.c | 12 +++++++----- fw/fe310/eos/power.c | 11 ++++++----- fw/fe310/eos/sock.c | 14 ++++++++------ fw/fe310/eos/sock.h | 2 +- fw/fe310/eos/wifi.c | 11 ++++++----- 5 files changed, 28 insertions(+), 22 deletions(-) (limited to 'fw') diff --git a/fw/fe310/eos/cell.c b/fw/fe310/eos/cell.c index 4b4fcc0..452fb47 100644 --- a/fw/fe310/eos/cell.c +++ b/fw/fe310/eos/cell.c @@ -11,14 +11,17 @@ static eos_evt_handler_t evt_handler[EOS_CELL_MAX_MTYPE]; static void cell_handle_evt(unsigned char type, unsigned char *buffer, uint16_t len) { + unsigned char mtype; + unsigned char idx; + if ((buffer == NULL) || (len < 1)) { eos_net_bad_handler(type, buffer, len); return; } - unsigned char mtype = buffer[0]; - unsigned char idx = (mtype & EOS_CELL_MTYPE_MASK) >> 4; - if (idx < EOS_CELL_MAX_MTYPE) { + mtype = buffer[0]; + idx = (mtype & EOS_CELL_MTYPE_MASK) >> 4; + if ((idx < EOS_CELL_MAX_MTYPE) && evt_handler[idx]) { evt_handler[idx](mtype & ~EOS_CELL_MTYPE_MASK, buffer, len); } else { eos_net_bad_handler(type, buffer, len); @@ -34,7 +37,7 @@ void eos_cell_init(void) { int i; for (i=0; i> 4; - if (handler == NULL) handler = eos_net_bad_handler; if (idx < EOS_CELL_MAX_MTYPE) evt_handler[idx] = handler; } diff --git a/fw/fe310/eos/power.c b/fw/fe310/eos/power.c index 5c874e0..2b13c9f 100644 --- a/fw/fe310/eos/power.c +++ b/fw/fe310/eos/power.c @@ -19,14 +19,16 @@ static eos_evt_handler_t evt_handler[EOS_PWR_MAX_MTYPE]; static unsigned char power_btn_down; static void power_handle_evt(unsigned char type, unsigned char *buffer, uint16_t len) { + unsigned char mtype; + if ((buffer == NULL) || (len < 1)) { eos_net_bad_handler(type, buffer, len); return; } - unsigned char mtype = buffer[0]; - if (mtype < EOS_PWR_MAX_MTYPE) { - evt_handler[mtype](type, buffer, len); + mtype = buffer[0]; + if ((mtype < EOS_PWR_MAX_MTYPE) && evt_handler[mtype]) { + evt_handler[mtype](mtype, buffer, len); } else { eos_net_bad_handler(type, buffer, len); } @@ -49,7 +51,7 @@ void eos_power_init(void) { int i; for (i=0; i EOS_SOCK_MAX_SOCK)) { + if ((sock == 0) || (sock > EOS_SOCK_MAX_SOCK) || (evt_handler[sock - 1] == NULL)) { eos_net_bad_handler(type, buffer, len); return; } - sock--; switch(buffer[0]) { case EOS_SOCK_MTYPE_PKT: - evt_handler[sock](type, buffer, len); + evt_handler[sock - 1](type, buffer, len); break; default: eos_net_bad_handler(type, buffer, len); @@ -38,17 +38,16 @@ void eos_sock_init(void) { int i; for (i=0; i