Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mgmt: mcumgr: stat_mgmt: stat_mgmt_list always send legacy behavior #80476

Closed
nandojve opened this issue Oct 27, 2024 · 7 comments · Fixed by #80477
Closed

mgmt: mcumgr: stat_mgmt: stat_mgmt_list always send legacy behavior #80476

nandojve opened this issue Oct 27, 2024 · 7 comments · Fixed by #80477
Assignees
Labels
area: mcumgr bug The issue is a bug, or the PR is fixing a bug priority: medium Medium impact/importance bug
Milestone

Comments

@nandojve
Copy link
Member

Describe the bug

The MCUmgr statistics only work correctly when selecting MCUMGR_SMP_LEGACY_RC_BEHAVIOUR. This flag is correctly handled for stat_mgmt_show command but it is missing for stat_mgmt_list command.

It is easy to compare both functions on this points:

if (IS_ENABLED(CONFIG_MCUMGR_SMP_LEGACY_RC_BEHAVIOUR)) {
ok = zcbor_tstr_put_lit(zse, "rc") &&
zcbor_int32_put(zse, MGMT_ERR_EOK);
}
if (ok) {
ok = zcbor_tstr_put_lit(zse, "name") &&
zcbor_tstr_encode(zse, &name) &&
zcbor_tstr_put_lit(zse, "fields") &&
zcbor_map_start_encode(zse, counter);
}

ok = zcbor_tstr_put_lit(zse, "rc") &&
zcbor_int32_put(zse, MGMT_ERR_EOK) &&
zcbor_tstr_put_lit(zse, "stat_list") &&
zcbor_list_start_encode(zse, counter);

Expected behavior

The MCUmgr statistics should work correctly for all protocol versions.

Impact

Field devices can not report their groups correctly when using a tool that not allow to use the MCUMGR_SMP_LEGACY_RC_BEHAVIOUR.

Environment (please complete the following information):

  • OS: Linux
  • Toolchain Zephyr SDK: 0.16.4
  • mainline

Additional context

Tested with https://github.com/intercreate/smpmgr

@nandojve nandojve added the bug The issue is a bug, or the PR is fixing a bug label Oct 27, 2024
@nandojve nandojve added this to the v4.0.0 milestone Oct 27, 2024
@nandojve nandojve self-assigned this Oct 27, 2024
@nandojve nandojve changed the title mgmt: mcumgr: stat_mgmt: stat_mgmt_list always send legacy behaviour mgmt: mcumgr: stat_mgmt: stat_mgmt_list always send legacy behavior Oct 27, 2024
@thedjnK
Copy link
Collaborator

thedjnK commented Oct 27, 2024

The MCUmgr statistics only work correctly when selecting MCUMGR_SMP_LEGACY_RC_BEHAVIOUR

Then your tool is broken, this Kconfig exists specifically for the go tool, which had a deprecated warning added to the documention a long time ago, and whose documentation was fully removed from zephyr earlier this year. If you use another tool and it requires this then the fault is with the tool

Just saw the PR and even more confused, the tool does not work without the patch because it receives an rc? Then the tool is even more broken that originally thought, response with rc = 0 and response without rc are equivalent, if the tool can't handle that then the tool is flawed

@nandojve
Copy link
Member Author

nandojve commented Oct 27, 2024

@thedjnK ,

Can you explain why one command send the RC and the another not?

@nandojve nandojve linked a pull request Oct 27, 2024 that will close this issue
@thedjnK
Copy link
Collaborator

thedjnK commented Oct 27, 2024

@thedjnK ,

Can you explain why one command send the RC and the another not?

Probably an oversight when it was added, but the extra rc field being there should not breaks tools when rc is 0 (PR is fine)

@nandojve
Copy link
Member Author

Ok,

response with rc = 0 and response without rc are equivalent,

This means that if I drop rc field it still comply with a V2 protocol. Is this assumption correct? I mean, a tool that only works with V2 will be able to handle the response. In this case, can I assume that rc field on V2 protocol means always an error ?

@thedjnK
Copy link
Collaborator

thedjnK commented Oct 27, 2024

Ok,

response with rc = 0 and response without rc are equivalent,

This means that if I drop rc field it still comply with a V2 protocol. Is this assumption correct? I mean, a tool that only works with V2 will be able to handle the response. In this case, can I assume that rc field on V2 protocol means always an error ?

No rc has nothing to do with v2, it was added before such a protocol existed, it is because you don't need an error variable if there is no error, it is superfluous. See #42590 for details

@nandojve
Copy link
Member Author

@thedjnK ,

Thank you for point out those info it help me to clarify some concepts since I still green in this area.
In the case of the PR #80477, I think it is fair to move in. At least we ensure behavior for both commands.

@JPHutchins
Copy link
Contributor

JPHutchins commented Nov 12, 2024

@nandojve Is any action needed at smp/smpclient/smpmgr to fix this?

Looking at the spec I see no rc field in the success response: https://docs.zephyrproject.org/latest/services/device_mgmt/smp_groups/smp_group_2.html

I see no indication that the behavior should be different for V1 or V2. Presence of rc = 0 should cause validation to fail because that is not a valid success response of the form:

{
    (str)"stat_list" :  [
        (str)<stat_group_name>, ...
    ]
}

and rather indicates that the SMP server has sent a malformed response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: mcumgr bug The issue is a bug, or the PR is fixing a bug priority: medium Medium impact/importance bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants