-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Add LwM2M firmware push/pull function #1049
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please put space before and after the '+'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please put empty line before the comment, looks a bit better that way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spaces missing before and after +
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same issue here with '+', can you do a search and fix all of these in one go
subsys/net/lib/lwm2m/lwm2m_engine.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
empty line after }
subsys/net/lib/lwm2m/lwm2m_engine.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
empty line after }
subsys/net/lib/lwm2m/lwm2m_engine.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add spaces before and after '*'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
empty line after }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
which is fine here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
empty line after }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looks like you have extra empty line between variable declarations above.
subsys/net/lib/lwm2m/Kconfig
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In reality this is just using the url parser, so wonder if we should split that out of the http later.
Size is also increased quite a bit by just building http_parser, which could probably be optimised if we could just split the url parse part of it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will add a patch to separate the URL parsing from header parsing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Easier to read if using "if (!IS_ENABLED(CONFIG_NET_IPV6)" instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't you also call NOTIFY_OBSERVER(5, 0, 3)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same, also missing NOTIFY_OBSERVER.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spec: "Writing an empty string to Package Resource or to Package URI Resource, resets the Firmware Update State Machine: the State Resource value is set to Idle and the Update Result Resource value is set to 0."
So we should reset state machine even if state is != DOWNLOADED, by checking for data_len outside the if/else block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From LwM2M specification figure 29, it looks like it only reset to state idle when it's currently at state downloaded and an empty package URI/resource is written.
That's why I put the state == STATE_DOWNLOADED check here.
If we reset the state machine at any state, then we have to do (1) cancel the firmware download and (2) cancel the firmware update.
I'm not sure which is the correct behavior. But from my point of view, it's simpler if we only accept the state machine reset at DOWNLOADED state.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Figure 29 seems to be a possible implementation indeed, but that doesn't cover the cancel update case, which is why my interpretation was more to reset at any point in time, at any state.
Looks like something to ask oma for clarification.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would also be nice to add similar checks to package_uri_write_cb.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm afraid that I did not catch your point.
What kind of checks do I have to add to package_uri_write_cb?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least to reset the state machine if there is an empty write.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More natural to read if "state == STATE_DOWNLOADED".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably define a set of possible return codes here, as an error is not necessarily integrity failed (another possible value is just simply firmware update failed, but it could also return unsupported package type).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good suggestion.
I will map -EINVAL to RESULT_INTEGRITY_FAILED and others to RESULT_UPDATE_FAILED.
From LwM2M specification figure 29, it seems there are only three acceptable results which are RESULT_SUCCESS, RESULT_INTEGRITY_FAILED and RESULT_UPDATE_FAILED.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be RESULT_CONNECTION_LOST instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add an empty line before the for ()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
break a line after a } always (unless it's another } etc..)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove that empty line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indent seems wrong here, & should be below f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
which is fine here
subsys/net/lib/lwm2m/lwm2m_engine.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
break a line before for () (see my previous comment about if/for/while etc..)
subsys/net/lib/lwm2m/lwm2m_engine.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you removed the useless else {}, you could do:
if (r) {
goto error;
}
and thus all the code block below could be indented back. Nicer to read, less imbrication of if/else etc...
subsys/net/lib/lwm2m/lwm2m_engine.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here would be you error label
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
usually, in net stack, we try to have declaration with assignment as first lines, then the rest. So I would reverse the order here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete the debug message directly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
declare inbuf and insize before len
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like we should be grouping all of the variables of the same types on a line. Same with the u16_t below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's actually ok to do both. No need to enforce grouping
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same with grouping up variables of the same type here.
include/net/lwm2m.h
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These 2 functions are only available if CONFIG_LWM2M_FIRMWARE_UPDATE_OBJ_SUPPORT is enabled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we sure that we want to assert here (even if CONFIG_ASSERT is enabled)? That seems a bit harsh for passing in an invalid state. Maybe ignore and print an error message? Especially since this is exposed in application code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once again, I'm not sure an assert is the right behavior here. Consider a strongly worded error message?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will replace assert w/ error messages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like lwm2m_firmware_set_update_state() and lwm2m_firmware_set_update_result() are performing data_validation and then a followup call to set related data. In discussions with @rsalveti we had plans to add a new data_validation_callback for data elements which would be called prior to assigning a value to the data element.
This would clean up several issues that I'm seeing here:
- You're creating specific data element based functions to control how a data element is set. This doesn't scale well over time.
- These functions in turn trigger related data element values to be set.
Instead, if we had a data_validation callback which could be assigned to a data element. The validation could be performed there (returning non-zero value when an invalid value is found). And if a valid value was found the follow up assignments of update_state could be handled in a post_write callback of update_result, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, it looks like a good idea if we could have a data validation callback when application want to update the value of the object resources. (I'm assuming that you are talking about adding callback to lwm2m_engine_set_xxx() functions.)
Do I create a ticker on JIRA for tracking it or ?
818d04c to
4e35cf1
Compare
|
@rbtchc while we get all the firmware update review done, would you mind breaking up the fixes you have in a separated pull request? At least "net: lwm2m: fix registration content format and use plain/text", "net: lwm2m: save accept format in observe_node_data" and "net: lwm2m: fix erroneous TLV write", as they are good fixes that could be merged soon. |
4e35cf1 to
2bcbd71
Compare
|
Here are the summary of the changes I made.
TODO
|
|
JIRA for data validation callback is here: https://jira.zephyrproject.org/browse/ZEP-2500 |
|
Raised firmware update cancellation question on OpenMobileAlliance/OMA_LwM2M_for_Developers#219 Do we need to wait for the clarification before we merge the patches? |
|
@jukkar @tbursztyka @mike-scott @rsalveti |
2bcbd71 to
4c3c810
Compare
|
Rebase and resolve code conflicts according to the change dcb80f7 |
Yep, sorry guys, I meant to ping you about it, seeing that lwm2m code uses, but that slipped. @mike-scott , @rsalveti, @mbolivar FYI |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am ok with the HTTP URL parser only option, I was actually needing something like this myself.
include/net/http_parser.h
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could add the config option in comment here as there are almost 200 lines inside this define block.
So something like this:
#endif /* !CONFIG_HTTP_PARSER_URL_ONLY */
subsys/net/lib/http/Kconfig
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps just say here "This option only enables URL parser of the http_parser library."
subsys/net/lib/http/http_parser.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add the /* !CONFIG_HTTP_PARSER_URL_ONLY */ here
subsys/net/lib/http/http_parser.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
subsys/net/lib/http/http_parser.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And here
subsys/net/lib/http/http_parser.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And here
subsys/net/lib/http/http_parser.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And here.
subsys/net/lib/lwm2m/Kconfig
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to add "select HTTP_PARSER" here too as when doing "select" in Kconfig, it will not recursively select other options.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about my comment here, is the HTTP_PARSER option selected by some other way? What I mean by this is if you select HTTP_PARSER_URL_ONLY here, it will not select HTTP_PARSER automatically (at least that is how Kconfig worked before) i.e., recursive "select" is not implemented. But it might be that the HTTP_PARSER is selected automatically by some other mean in which case my concern is moot.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did add "select HTTP_PARSER" at subsys/net/lib/http/Kconfig#L68 when config HTTP_PARSER_URL_ONLY is selected.
In this way, when LWM2M_FIRMWARE_UPDATE_PULL_SUPPORT is selected, both HTTP_PARSER & HTTP_PARSER_URL_ONLY will be selected as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I missed that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't there now a compile error if you disable IPv6 as the any_addr6 is only found if IPv6 is enabled?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And same thing for IPv4
4c3c810 to
70fc343
Compare
|
Update according to @jukkar 's comment. Here's the diff: https://hastebin.com/vovevumeca.cs |
70fc343 to
c0d0481
Compare
|
Update to take care of error handling when failing to add block1 option to the out packet |
c0d0481 to
ee49c3d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, I just submitted #1198 which provides net_ipaddr_parse() function that converts a IPv{4|6} address string to struct sockaddr. That function could probably be used here in order to save some memory, this is just something that could be considered here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to know. I will apply those changes to the PR when they are merged.
ee49c3d to
a60783b
Compare
|
@mike-scott sure |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should always check for data_len == 0 even when state is not downloading. That is just to protect the code flow as the state can be updated via other parts of the code (even when it shouldn't).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to confirm. Are you suggesting that we always check if "data_len == 0" and reset the state back to default?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, my concern is what would happen when data_len == 0 but state is not what we expect to be (simply because state can be changed independently).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here (data_len == 0).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mind also adding a error message here in case this gets called when state == DOWNLOADING.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will print out an error message here.
1. Parse firmware pull URI 2. Add lwm2m_firmware_get/set_update_cb() for applicaiton to register callback. This is because we want to check the update_state before we pass to the application 3. Add lwm2m_firmware_get/set_update_result() and lwm2m_firmware_get/set_update_stat() to manage the state trasnition as well as the sanity check Signed-off-by: Robert Chou <[email protected]>
OPAQUE resource type might/might not have data_ptr/data_len setup depending on the implementation. This introduces an issue that when an OPAQUE resource is written from the server side, the one w/ none setup will not be able to pass data to post_write_cb() Modify to setup data_ptr/data_len as incoming buffer and buffer size Signed-off-by: Robert Chou <[email protected]>
1. Add handling block1 option in handle_request(). The basic idea is to declare structure block_context at compiled time and use "token" as a key to pick up the on-going block cotext. It should be able to support multiple blockwise transfer concurrently 2. Use write callback implemented in lwm2m_obj_firmware to deal w/ the update state transition and than call the callback registered by the application 3. move default_block_size to lwm2m_engine.c to share btw lwm2m_engine and lwm2m_obj_firmware_pull Signed-off-by: Robert Chou <[email protected]>
7e456cd to
db98d60
Compare
|
Update to address @rsalveti 's concerns. Diff: https://hastebin.com/exixuzaxex.cs
|
|
Probably safe to close this PR. I have rebased versions of these patches included in this PR: #4208 |
|
Close as @mike-scott mentioned |
…rproject-rtos#1049) It was checking the length of the filename against the maximum JS file length. Native modules can be longer and were failing because of this. Signed-off-by: Brian J Jones <[email protected]>
This fixes Bluetooth logs that were not sent over RTT. Minor cleanup has been made to limit the number of ifdefs. > ACL Data RX: Handle 0 flags 0x02 dlen 11 zephyrproject-rtos#1049 83.117000 ATT: Handle Value Indication (0x1d) len 6 Handle: 0x0003 Data: 0100ffff = bt: bt_att: Unhandled ATT code 0x1d 83.117100 > HCI Event: Disconnect Complete (0x05) plen 4 zephyrproject-rtos#1050 84.247700 Status: Success (0x00) Handle: 0 Reason: Remote User Terminated Connection (0x13) Signed-off-by: Mariusz Skamra <[email protected]>
This fixes Bluetooth logs that were not sent over RTT. Minor cleanup has been made to limit the number of ifdefs. > ACL Data RX: Handle 0 flags 0x02 dlen 11 zephyrproject-rtos#1049 83.117000 ATT: Handle Value Indication (0x1d) len 6 Handle: 0x0003 Data: 0100ffff = bt: bt_att: Unhandled ATT code 0x1d 83.117100 > HCI Event: Disconnect Complete (0x05) plen 4 zephyrproject-rtos#1050 84.247700 Status: Success (0x00) Handle: 0 Reason: Remote User Terminated Connection (0x13) Signed-off-by: Mariusz Skamra <[email protected]>
This fixes Bluetooth logs that were not sent over RTT. Minor cleanup has been made to limit the number of ifdefs. > ACL Data RX: Handle 0 flags 0x02 dlen 11 #1049 83.117000 ATT: Handle Value Indication (0x1d) len 6 Handle: 0x0003 Data: 0100ffff = bt: bt_att: Unhandled ATT code 0x1d 83.117100 > HCI Event: Disconnect Complete (0x05) plen 4 #1050 84.247700 Status: Success (0x00) Handle: 0 Reason: Remote User Terminated Connection (0x13) Signed-off-by: Mariusz Skamra <[email protected]>
Implement firmware push and pull functions