diff options
Diffstat (limited to 'app.cpp')
-rw-r--r-- | app.cpp | 22 |
1 files changed, 12 insertions, 10 deletions
@@ -10,10 +10,6 @@ #error "SM_BOARD_VERSION must be set. See config.h" #endif -// http://bleaklow.com/2010/09/05/progmem_and_gcc_bug_34734.html -#undef PROGMEM -#define PROGMEM __attribute__((section(".progmem.data"))) - #define LED_PIN 13 #define EEPROM_MAGIC 0xa5 @@ -249,6 +245,10 @@ void write_res(struct sm_res const& res) { } #endif // SM_DEBUG +static inline bool len_ok(uint8_t sizeof_packet, uint8_t sizeof_struct) { + return sizeof_packet >= sizeof_struct; +} + void on_soil_moisture_ctrl(uint8_t *data, uint8_t len) { struct sm_req *req = (struct sm_req *) data; struct sm_res res; @@ -258,9 +258,16 @@ void on_soil_moisture_ctrl(uint8_t *data, uint8_t len) { write_req(*req); #endif + if (len <= 1) { + return; + } + res.code = req->code; - uint8_t body_len; + uint8_t body_len = 0; + res.code = SM_CMD_FAIL; + + // TODO: use len_op(len, sizeof(sm_XX_req)) to check that each request's size is ok. switch(req->code) { case SM_CMD_GET_SENSOR_COUNT: body_len = sizeof(sm_get_sensor_count_res); @@ -335,11 +342,6 @@ void on_soil_moisture_ctrl(uint8_t *data, uint8_t len) { res.code = SM_CMD_FAIL; } break; - - default: - body_len = 0; - res.code = SM_CMD_FAIL; - break; } if (res.code == SM_CMD_FAIL) { |