Skip to content

Fix incorrect bit check for MaxLRTxPowerLevel in SupportsSerialAPISetup_func#45

Open
ptphan28 wants to merge 1 commit into
SiliconLabs:mainfrom
ptphan28:fix/MaxLRTxPowerLevel_subcmd_bit_check
Open

Fix incorrect bit check for MaxLRTxPowerLevel in SupportsSerialAPISetup_func#45
ptphan28 wants to merge 1 commit into
SiliconLabs:mainfrom
ptphan28:fix/MaxLRTxPowerLevel_subcmd_bit_check

Conversation

@ptphan28

Copy link
Copy Markdown

This PR fixes an issue in SupportsSerialAPISetup_func() where the subcommand ID was incorrectly used as a bit index in is_bit_num_set_in_byte(). This prevented MaxLRTxPowerLevel from being configured via zipgateway.cfg.

@ptphan28 ptphan28 marked this pull request as draft October 28, 2025 10:18
@ptphan28 ptphan28 marked this pull request as ready for review October 28, 2025 10:21
@rzr

rzr commented Oct 28, 2025

Copy link
Copy Markdown
Contributor

Thank you, this looks legit, let me run tests

Please update commit message, to explain what was the observed issue and the motivation of the fix (reference to specs will be also appreciated)

Reviewers welcome (I cant add names)

cc: @lmolina @ochavezmiranda @Thomasdjb @XavierPerraud-Silabs

@rzr

rzr commented Oct 28, 2025

Copy link
Copy Markdown
Contributor

I noticed an issue (not related to this change) in build log:

1046.6 Generating codsh: 1: mscgen: not found
1047.6 sh: 1: mscgen: not found

https://en.wikipedia.org/wiki/MscGen

May this be fixed

Comment thread src/serialapi/Serialapi.c
@@ -243,9 +243,9 @@
"beyond 1st byte of Extended Z-Wave API Setup Supported Sub"
"Commands bitmask, which is not supported.\n", subcmd);
} else if (subcmd > 8) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend something closer to the source code of the Z-Wave stack:

    uint8_t index = (subcmd - 1) / 8 + 1; // +1 because the sub command bitmask start at index 1 instead of 0.
    uint8_t mask = (1 << ((x - 1) % 8));
    return capabilities.supported_serialapi_bitmask[index] & mask;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@XavierPerraud-Silabs is it a blocker?

Comment thread src/serialapi/Serialapi.c
// check if the subcmd being checked has two bits set for e.g. 3(0011), 5(0101)
// Where we need to check the Extended Z-Wave API Setup Supported Sub Commands bitmask
if (subcmd & (subcmd - 1)) {
if (subcmd > 16) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why subcmd is limited to 16?
Highest subcmd defined in the controller is 22: SERIAL_API_SETUP_CMD_GET_REGION_INFO.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the reason is the limitation of the Z/IP Gateway, which only supports a few specific Serial API subcommands.
The Z/IP Gateway supports only the following Serial API subcommands:
SERIAL_API_SETUP_CMD_UNSUPPORTED,
SERIAL_API_SETUP_CMD_SUPPORTED = 1<<0,
SERIAL_API_SETUP_CMD_TX_STATUS_REPORT = 1<<1,
SERIAL_API_SETUP_CMD_MAX_LR_TX_PWR_SET = 3,
SERIAL_API_SETUP_CMD_TX_POWERLEVEL_SET = 1<<2,
SERIAL_API_SETUP_CMD_MAX_LR_TX_PWR_GET = 5,
SERIAL_API_SETUP_CMD_TX_POWERLEVEL_GET = 1<<3,
// SERIAL_API_SETUP_CMD_TX_GET_MAX_PAYLOAD_SIZE = 1<<4,
SERIAL_API_SETUP_CMD_RF_REGION_GET = 1<<5,
SERIAL_API_SETUP_CMD_RF_REGION_SET = 1<<6,
SERIAL_API_SETUP_CMD_NODEID_BASETYPE_SET = 1<<7,

@michael-correia

Copy link
Copy Markdown

Can this change be merged in? We needed this change when using the latest zipgateway.

FYI @lmolina

@lmolina

lmolina commented May 21, 2026

Copy link
Copy Markdown
Collaborator

@ptphan28 would you add unit test to cover the change? Also, could you develop the commit message? I suggest some like:

fix: correct Extended Sub Commands bitmask bit index

SupportsSerialAPISetup_func decoded Serial API Setup sub-command
IDs against the wrong bit positions in the Sub Commands bitmask.
See Host API 2025A section 4.3.16.1.

Adjust the byte-1 and byte-2 lookups to subcmd - 1 and subcmd - 9.

If the refactor in #45 (comment) is a blocker, I suggest to do it in a separate commit and tag it as refactor.

Balance that the project is in maintenance.

@lmolina lmolina left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

Comment thread src/serialapi/Serialapi.c
return (is_bit_num_set_in_byte(subcmd - 9, capabilities.supported_serialapi_bitmask[2]));
} else if (subcmd > 0) {
return (is_bit_num_set_in_byte(subcmd ,capabilities.supported_serialapi_bitmask[1]));
return (is_bit_num_set_in_byte(subcmd - 1,capabilities.supported_serialapi_bitmask[1]));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return (is_bit_num_set_in_byte(subcmd - 1,capabilities.supported_serialapi_bitmask[1]));
return (is_bit_num_set_in_byte(subcmd - 1, capabilities.supported_serialapi_bitmask[1]));

Comment thread src/serialapi/Serialapi.c
@@ -243,9 +243,9 @@ BYTE SupportsSerialAPISetup_func(BYTE subcmd)
"beyond 1st byte of Extended Z-Wave API Setup Supported Sub"
"Commands bitmask, which is not supported.\n", subcmd);
} else if (subcmd > 8) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@XavierPerraud-Silabs is it a blocker?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants