-
Notifications
You must be signed in to change notification settings - Fork 376
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
Make CoAP block size configurable at build- and run-time #596
Make CoAP block size configurable at build- and run-time #596
Conversation
- -s Set the device management or bootstrap server Pre-Shared-Key. If not set use none secure mode | ||
``` | ||
-i Set the device management or bootstrap server PSK identity. If not set use none secure mode | ||
-s Set the device management or bootstrap server Pre-Shared-Key. If not set use none secure mode |
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.
CoAP block size and Pre-Shared-Key are both -s.
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 missed that. I would go with -S
then. Another option would be -a
since other obvious options are already used.
examples/lightclient/lightclient.c
Outdated
@@ -57,6 +57,7 @@ | |||
|
|||
#include "liblwm2m.h" | |||
#include "connection.h" | |||
#include "commandline.h" |
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.
Why the additional include? I don't think the lightclient supports commands.
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 put validate_coap_block_size
in commandline.c
because it is shared code for the examples. Therefore this include is needed in the lightclient. Another place would be core/utils.c
and liblwm2m.h
.
examples/shared/commandline.c
Outdated
{ | ||
return coap_block_size_arg >= 16 && \ | ||
coap_block_size_arg <= 1024 && \ | ||
coap_block_size_arg % 2 == 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.
This would allow any even block size from 16 to 1024, not just 16, 32, 64, 128, 256, 512, 1024.
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 update this part and move into core/utils.c
coap/er-coap-13/er-coap-13.c
Outdated
@@ -65,6 +65,7 @@ | |||
/*- Variables -----------------------------------------------------------------------*/ | |||
/*-----------------------------------------------------------------------------------*/ | |||
static uint16_t current_mid = 0; | |||
uint16_t coap_block_size = COAP_DEFAULT_BLOCK_SIZE; |
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.
This is declared in liblwm2m.h. I think the storage and default value should be set in one of the core files, not here. I would suggest core/packet.c since that is where most of the usage occurs.
include/liblwm2m.h
Outdated
@@ -97,6 +97,8 @@ extern "C" { | |||
#error "LWM2M_BOOTSTRAP and LWM2M_BOOTSTRAP_SERVER_MODE cannot be defined at the same time!" | |||
#endif | |||
|
|||
extern uint16_t coap_block_size; |
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 don't think there are any other variables publicly exported by Wakaama. I would suggest moving this to core/internals.h and creating a function to set it. That would also give a point to notify a CoAP stack (if we support a different one in the future) of a change in the block size.
On another note, anything meant to be accessed by the user's code should start with lwm2m.
examples/client/lwm2mclient.c
Outdated
@@ -1014,6 +1015,22 @@ int main(int argc, char *argv[]) | |||
case '4': | |||
data.addressFamily = AF_INET; | |||
break; | |||
case 's': |
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.
Duplicate case if WITH_TINYDTLS is defined.
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.
@rettichschnidi, the CI didn't catch this. Possibly another area for improvement. I'm not sure if it is doing a DTLS build or not.
1024 bytes for the block size agrees with RFC7252 section 4.6 |
824e7be
to
a08f7d7
Compare
@mlasch Please rebase on the current master 😸 |
a08f7d7
to
b65fb0f
Compare
core/packet.c
Outdated
|
||
bool lwm2m_validate_block_size(uint16_t coap_block_size_arg) | ||
{ | ||
uint16_t valid_block_sizes[7] = {16, 32, 64, 128, 256, 512, 1024}; |
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 add const here. That will allow it to remain in flash on some devices rather than being copied to RAM and using more resources.
core/packet.c
Outdated
|
||
void lwm2m_set_block_size(uint16_t coap_block_size_arg) | ||
{ | ||
coap_block_size = coap_block_size_arg; |
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'd like to see the set do the validation and return a true/false indication to prevent misuse and simplify the API for the user.
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.
Sounds sensible. I will remove lwm2m_validate_block_size
from the public interface then.
b65fb0f
to
dffbfb7
Compare
Pushed again, let clang-format do the formatting. |
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.
LGTM
examples/lightclient/lightclient.c
Outdated
uint16_t coap_block_size_arg; | ||
if (1 == sscanf(argv[opt], "%hu", &coap_block_size_arg) && lwm2m_set_block_size(coap_block_size_arg)) { | ||
break; | ||
} else { | ||
print_usage(); | ||
return 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.
Same as above.
examples/server/lwm2mserver.c
Outdated
@@ -1217,7 +1232,7 @@ int main(int argc, char *argv[]) | |||
in_port_t port; | |||
connection_t * connP; | |||
|
|||
s[0] = 0; | |||
s[0] = 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.
Unwanted cosmetic change?
examples/server/lwm2mserver.c
Outdated
uint16_t coap_block_size_arg; | ||
if (1 == sscanf(argv[opt], "%hu", &coap_block_size_arg) && lwm2m_set_block_size(coap_block_size_arg)) { | ||
break; | ||
} else { | ||
print_usage(); | ||
return 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.
Same as above.
include/liblwm2m.h
Outdated
@@ -277,6 +277,11 @@ void lwm2m_list_free(lwm2m_list_t * head); | |||
#define LWM2M_LIST_FIND(H,I) lwm2m_list_find((lwm2m_list_t *)H, I) | |||
#define LWM2M_LIST_FREE(H) lwm2m_list_free((lwm2m_list_t *)H) | |||
|
|||
/* | |||
* Helper functions for coap block size settings. |
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.
* Helper functions for coap block size settings. | |
* Helper functions for CoAP block size settings. |
dffbfb7
to
d92c2c4
Compare
core/packet.c
Outdated
@@ -93,6 +93,28 @@ Contains code snippets which are: | |||
|
|||
#include <stdio.h> | |||
|
|||
uint16_t coap_block_size = LWM2M_COAP_DEFAULT_BLOCK_SIZE; | |||
|
|||
static bool validate_block_size(uint16_t coap_block_size_arg) { |
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.
static bool validate_block_size(uint16_t coap_block_size_arg) { | |
static bool validate_block_size(const uint16_t coap_block_size_arg) { |
core/packet.c
Outdated
return false; | ||
} | ||
|
||
bool lwm2m_set_coap_block_size(uint16_t coap_block_size_arg) { |
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.
bool lwm2m_set_coap_block_size(uint16_t coap_block_size_arg) { | |
bool lwm2m_set_coap_block_size(const uint16_t coap_block_size_arg) { |
d92c2c4
to
1ca6295
Compare
return 0; | ||
} | ||
uint16_t coap_block_size_arg; | ||
if (1 == sscanf(argv[opt], "%hu", &coap_block_size_arg) && lwm2m_set_coap_block_size(coap_block_size_arg)) { |
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 rather use C99 format specifiers:
if (1 == sscanf(argv[opt], "%hu", &coap_block_size_arg) && lwm2m_set_coap_block_size(coap_block_size_arg)) { | |
if (1 == sscanf(argv[opt], "%" PRIu16, &coap_block_size_arg) && lwm2m_set_coap_block_size(coap_block_size_arg)) { |
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 guess you meant SCNu16
in this case. I can change those lines.
examples/client/lwm2mclient.c
Outdated
return 0; | ||
} | ||
uint16_t coap_block_size_arg; | ||
if (1 == sscanf(argv[opt], "%hu", &coap_block_size_arg) && lwm2m_set_coap_block_size(coap_block_size_arg)) { |
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 rather use C99 format specifiers.
examples/lightclient/lightclient.c
Outdated
return 0; | ||
} | ||
uint16_t coap_block_size_arg; | ||
if (1 == sscanf(argv[opt], "%hu", &coap_block_size_arg) && lwm2m_set_coap_block_size(coap_block_size_arg)) { |
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 rather use C99 format specifiers.
examples/server/lwm2mserver.c
Outdated
return 0; | ||
} | ||
uint16_t coap_block_size_arg; | ||
if (1 == sscanf(argv[opt], "%hu", &coap_block_size_arg) && lwm2m_set_coap_block_size(coap_block_size_arg)) { |
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 rather use C99 format specifiers.
include/liblwm2m.h
Outdated
* Helper functions for CoAP block size settings. | ||
*/ | ||
bool lwm2m_set_coap_block_size(uint16_t coap_block_size_arg); | ||
uint16_t lwm2m_get_coap_block_size(); |
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 use prototypes in C:
uint16_t lwm2m_get_coap_block_size(); | |
uint16_t lwm2m_get_coap_block_size(void); |
1ca6295
to
f93b8c1
Compare
f93b8c1
to
e8d92c7
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.
One small fix/improvement I feel is worth to take into account. See comment. Everything else LGTM.
core/wakaama.cmake
Outdated
if (LWM2M_COAP_DEFAULT_BLOCK_SIZE) | ||
add_compile_definitions(LWM2M_COAP_DEFAULT_BLOCK_SIZE=${LWM2M_COAP_DEFAULT_BLOCK_SIZE}) | ||
endif() |
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.
The Wakaama code will neither compile nor work when LWM2M_COAP_DEFAULT_BLOCK_SIZE is zero. Therefore, this if should not exist.
if (LWM2M_COAP_DEFAULT_BLOCK_SIZE) | |
add_compile_definitions(LWM2M_COAP_DEFAULT_BLOCK_SIZE=${LWM2M_COAP_DEFAULT_BLOCK_SIZE}) | |
endif() | |
add_compile_definitions(LWM2M_COAP_DEFAULT_BLOCK_SIZE=${LWM2M_COAP_DEFAULT_BLOCK_SIZE}) |
Once this PR is merged (with the modified default blocksize) other PRs related to integration tests can me merged |
This patch makes the CoAP block size, used in block transfers, configurable in two ways. 1. Build-time configurable default value via a cmake variable. LWM2M_COAP_DEFAULT_BLOCK_SIZE 2. Run-time configurable via new -S command line argument. Add this new function to the interface: - lwm2m_set_coap_block_size() - lwm2m_get_coap_block_size() The new default value for the block size will now be 1024 with no further configuration. This avoids block transfers in common use-cases. Signed-off-by: Marc Lasch <marc.lasch@husqvarnagroup.com>
clang-format enforced changes for unkown reasons. Signed-off-by: Marc Lasch <marc.lasch@husqvarnagroup.com>
Adjust git blame ignores Signed-off-by: Marc Lasch <marc.lasch@husqvarnagroup.com>
e8d92c7
to
17b6ac6
Compare
This patch makes the block size used in CoAP block transfers configurable in two ways.
-S
command line argument for all examples. This will simplify (automated) testing with different block sizes.