Skip to content

Commit da687d2

Browse files
soc: silabs: siwx91x: removed sscanf for nwp firmware version check
This patch removes the use of sscanf to maintain compatibility with tests that use the minimal cpp library. The expected version is now defined using multiple individual values rather than a single formatted string. Signed-off-by: Martin Hoff <[email protected]>
1 parent 8ae3880 commit da687d2

File tree

2 files changed

+32
-24
lines changed

2 files changed

+32
-24
lines changed

modules/hal_silabs/wiseconnect/nwp_fw_version.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@
55
*/
66

77
/* This value needs to be updated when the Wiseconnect SDK (hal_silabs/wiseconnect) is updated
8-
* Actually mapped to Wiseconnect SDK 3.5.0
8+
* Actually mapped to Wiseconnect SDK 3.5.2
99
*/
10-
#define SIWX91X_NWP_FW_EXPECTED_VERSION "B.2.14.5.2.0.7"
10+
11+
#include <sl_wifi_types.h>
12+
13+
static const sl_wifi_firmware_version_t siwx91x_nwp_fw_expected_version = {
14+
.rom_id = 0x0B,
15+
.major = 2,
16+
.minor = 14,
17+
.security_version = 5,
18+
.patch_num = 2,
19+
.customer_id = 0,
20+
.build_num = 7,
21+
};

soc/silabs/silabs_siwx91x/siwg917/siwx91x_nwp.c

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,6 @@ static void siwx91x_configure_network_stack(sl_si91x_boot_configuration_t *boot_
261261

262262
static int siwx91x_check_nwp_version(void)
263263
{
264-
sl_wifi_firmware_version_t expected_version;
265264
sl_wifi_firmware_version_t version;
266265
int ret;
267266

@@ -270,38 +269,29 @@ static int siwx91x_check_nwp_version(void)
270269
return -EINVAL;
271270
}
272271

273-
sscanf(SIWX91X_NWP_FW_EXPECTED_VERSION, "%hhX.%hhd.%hhd.%hhd.%hhd.%hhd.%hd",
274-
&expected_version.rom_id,
275-
&expected_version.major,
276-
&expected_version.minor,
277-
&expected_version.security_version,
278-
&expected_version.patch_num,
279-
&expected_version.customer_id,
280-
&expected_version.build_num);
281-
282272
/* Ignore rom_id:
283273
* B is parsed as an hex value and we get 11 in expected_version.rom_id
284274
* We received rom_id=17 in version.rom_id, we suspect a double hex->decimal conversion
285275
*/
286-
if (expected_version.major != version.major) {
276+
if (siwx91x_nwp_fw_expected_version.major != version.major) {
287277
return -EINVAL;
288278
}
289-
if (expected_version.minor != version.minor) {
279+
if (siwx91x_nwp_fw_expected_version.minor != version.minor) {
290280
return -EINVAL;
291281
}
292-
if (expected_version.security_version != version.security_version) {
282+
if (siwx91x_nwp_fw_expected_version.security_version != version.security_version) {
293283
return -EINVAL;
294284
}
295-
if (expected_version.patch_num != version.patch_num) {
285+
if (siwx91x_nwp_fw_expected_version.patch_num != version.patch_num) {
296286
return -EINVAL;
297287
}
298-
if (expected_version.customer_id != version.customer_id) {
299-
LOG_DBG("customer_id diverge: expected %d, actual %d", expected_version.customer_id,
300-
version.customer_id);
288+
if (siwx91x_nwp_fw_expected_version.customer_id != version.customer_id) {
289+
LOG_DBG("customer_id diverge: expected %d, actual %d",
290+
siwx91x_nwp_fw_expected_version.customer_id, version.customer_id);
301291
}
302-
if (expected_version.build_num != version.build_num) {
303-
LOG_DBG("build_num diverge: expected %d, actual %d", expected_version.build_num,
304-
version.build_num);
292+
if (siwx91x_nwp_fw_expected_version.build_num != version.build_num) {
293+
LOG_DBG("build_num diverge: expected %d, actual %d",
294+
siwx91x_nwp_fw_expected_version.build_num, version.build_num);
305295
}
306296

307297
return 0;
@@ -414,8 +404,15 @@ static int siwx91x_nwp_init(const struct device *dev)
414404
/* Check if the NWP firmware version is correct */
415405
ret = siwx91x_check_nwp_version();
416406
if (ret < 0) {
417-
LOG_ERR("Unexpected NWP firmware version (expected: %s)",
418-
SIWX91X_NWP_FW_EXPECTED_VERSION);
407+
LOG_ERR("Unexpected NWP firmware version (expected: %X.%d.%d.%d.%d.%d.%d)",
408+
siwx91x_nwp_fw_expected_version.rom_id,
409+
siwx91x_nwp_fw_expected_version.major,
410+
siwx91x_nwp_fw_expected_version.minor,
411+
siwx91x_nwp_fw_expected_version.security_version,
412+
siwx91x_nwp_fw_expected_version.patch_num,
413+
siwx91x_nwp_fw_expected_version.customer_id,
414+
siwx91x_nwp_fw_expected_version.build_num);
415+
return -EINVAL;
419416
}
420417

421418
if (IS_ENABLED(CONFIG_SOC_SIWX91X_PM_BACKEND_PMGR)) {

0 commit comments

Comments
 (0)