From 47a65e5e51635e2eeb9fd238decf56c2222231c2 Mon Sep 17 00:00:00 2001 From: Dniel97 Date: Sun, 17 Mar 2024 14:19:56 +0100 Subject: [PATCH] fixed aime LED firmware --- board/sg-cmd.h | 7 +++++++ board/sg-led.c | 14 +++++++------- board/sg-nfc.c | 28 ++++++++++++++-------------- 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/board/sg-cmd.h b/board/sg-cmd.h index 685377f..73029ec 100644 --- a/board/sg-cmd.h +++ b/board/sg-cmd.h @@ -25,6 +25,13 @@ struct sg_res_header { uint8_t payload_len; }; +/* struct to save the version string with its length + to fix NUL terminator issues */ +struct version_info { + const char *version; + uint8_t length; +}; + typedef HRESULT (*sg_dispatch_fn_t)( void *ctx, const void *req, diff --git a/board/sg-led.c b/board/sg-led.c index cd09c14..47f97c2 100644 --- a/board/sg-led.c +++ b/board/sg-led.c @@ -27,11 +27,11 @@ static HRESULT sg_led_cmd_set_color( const struct sg_led *led, const struct sg_led_req_set_color *req); -const char *sg_led_info[] = { - "15084\xFF\x10\x00\x12", - "000-00000\xFF\x11\x40", +static const struct version_info led_version[] = { + {"15084\xFF\x10\x00\x12", 9}, + {"000-00000\xFF\x11\x40", 12}, // maybe the same? - "000-00000\xFF\x11\x40" + {"000-00000\xFF\x11\x40", 12} }; void sg_led_init( @@ -156,10 +156,10 @@ static HRESULT sg_led_cmd_get_info( { sg_led_dprintf(led, "Get info\n"); - unsigned int len = strlen(sg_led_info[led->gen - 1]); + const struct version_info *fw = &led_version[led->gen - 1]; - sg_res_init(&res->res, req, len); - memcpy(res->payload, sg_led_info[led->gen - 1], len); + sg_res_init(&res->res, req, fw->length); + memcpy(res->payload, fw->version, fw->length); return S_OK; } diff --git a/board/sg-nfc.c b/board/sg-nfc.c index c519358..8f7c9bd 100644 --- a/board/sg-nfc.c +++ b/board/sg-nfc.c @@ -65,16 +65,16 @@ static HRESULT sg_nfc_cmd_dummy( const struct sg_req_header *req, struct sg_res_header *res); -static const char *hw_version[] = { - "TN32MSEC003S H/W Ver3.0", - "837-15286", - "837-15396" +static const struct version_info hw_version[] = { + {"TN32MSEC003S H/W Ver3.0", 23}, + {"837-15286", 9}, + {"837-15396", 9} }; -static const char *fw_version[] = { - "TN32MSEC003S F/W Ver1.2", - "\x94", - "\x94" +static const struct version_info fw_version[] = { + {"TN32MSEC003S F/W Ver1.2", 23}, + {"\x94", 1}, + {"\x94", 1} }; void sg_nfc_init( @@ -217,11 +217,11 @@ static HRESULT sg_nfc_cmd_get_fw_version( const struct sg_req_header *req, struct sg_nfc_res_get_fw_version *res) { - unsigned int len = strlen(fw_version[nfc->gen - 1]); + const struct version_info *fw = &fw_version[nfc->gen - 1]; /* Dest version is not NUL terminated, this is intentional */ - sg_res_init(&res->res, req, len); - memcpy(res->version, fw_version[nfc->gen - 1], len); + sg_res_init(&res->res, req, fw->length); + memcpy(res->version, fw->version, fw->length); return S_OK; } @@ -231,11 +231,11 @@ static HRESULT sg_nfc_cmd_get_hw_version( const struct sg_req_header *req, struct sg_nfc_res_get_hw_version *res) { - unsigned int len = strlen(hw_version[nfc->gen - 1]); + const struct version_info *hw = &hw_version[nfc->gen - 1]; /* Dest version is not NUL terminated, this is intentional */ - sg_res_init(&res->res, req, len); - memcpy(res->version, hw_version[nfc->gen - 1], len); + sg_res_init(&res->res, req, hw->length); + memcpy(res->version, hw->version, hw->length); return S_OK; }