net: lwm2m: Add option to register in UDP queue mode
Add Kconfig option to enable Queue Mode binding. With this option enabled, the LWM2M client will register with `UQ` binding, instead of `U`. Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
This commit is contained in:
parent
9e45c67679
commit
842d4b220f
6 changed files with 42 additions and 4 deletions
|
@ -83,6 +83,21 @@ config LWM2M_ENGINE_DEFAULT_LIFETIME
|
|||
help
|
||||
Set the default lifetime (in seconds) for the LWM2M library engine
|
||||
|
||||
config LWM2M_QUEUE_MODE_ENABLED
|
||||
bool "Enable Queue Mode UDP binding"
|
||||
help
|
||||
Set the transport binding to UDP with Queue Mode (UQ).
|
||||
|
||||
config LWM2M_QUEUE_MODE_UPTIME
|
||||
int "Specify time the LWM2M client should stay online in queue mode."
|
||||
default 93
|
||||
help
|
||||
This config specifies time (in seconds) the device should stay online
|
||||
after sending a message to the server. Note, that LWM2M specification
|
||||
recommends this to be CoAP MAX_TRANSMIT_WAIT parameter (which
|
||||
defaults to 93 seconds, see RFC 7252), it does not forbid other
|
||||
values though.
|
||||
|
||||
config LWM2M_RD_CLIENT_SUPPORT
|
||||
bool "support for LWM2M client bootstrap/registration state machine"
|
||||
default y
|
||||
|
|
|
@ -1851,6 +1851,16 @@ int lwm2m_engine_get_resource(char *pathstr, struct lwm2m_engine_res **res)
|
|||
return path_to_objs(&path, NULL, NULL, res, NULL);
|
||||
}
|
||||
|
||||
void lwm2m_engine_get_binding(char *binding)
|
||||
{
|
||||
if (IS_ENABLED(CONFIG_LWM2M_QUEUE_MODE_ENABLED)) {
|
||||
strcpy(binding, "UQ");
|
||||
} else {
|
||||
/* Defaults to UDP. */
|
||||
strcpy(binding, "U");
|
||||
}
|
||||
}
|
||||
|
||||
int lwm2m_engine_create_res_inst(char *pathstr)
|
||||
{
|
||||
int ret, i;
|
||||
|
|
|
@ -96,6 +96,8 @@ int lwm2m_engine_add_service(k_work_handler_t service, u32_t period_ms);
|
|||
int lwm2m_engine_get_resource(char *pathstr,
|
||||
struct lwm2m_engine_res **res);
|
||||
|
||||
void lwm2m_engine_get_binding(char *binding);
|
||||
|
||||
size_t lwm2m_engine_get_opaque_more(struct lwm2m_input_context *in,
|
||||
u8_t *buf, size_t buflen, bool *last_block);
|
||||
|
||||
|
|
|
@ -353,8 +353,7 @@ static int lwm2m_device_init(struct device *dev)
|
|||
|
||||
/* Set default values */
|
||||
time_offset = 0U;
|
||||
/* currently only support UDP binding mode (no SMS or Queue mode) */
|
||||
strcpy(binding_mode, "U");
|
||||
lwm2m_engine_get_binding(binding_mode);
|
||||
|
||||
/* initialize the device field data */
|
||||
device.obj_id = LWM2M_OBJECT_DEVICE_ID;
|
||||
|
|
|
@ -166,7 +166,7 @@ static struct lwm2m_engine_obj_inst *server_create(u16_t obj_inst_id)
|
|||
default_min_period[index] = CONFIG_LWM2M_SERVER_DEFAULT_PMIN;
|
||||
default_max_period[index] = CONFIG_LWM2M_SERVER_DEFAULT_PMAX;
|
||||
disabled_timeout[index] = 86400U;
|
||||
strcpy(transport_binding[index], "U");
|
||||
lwm2m_engine_get_binding(transport_binding[index]);
|
||||
|
||||
(void)memset(res[index], 0,
|
||||
sizeof(res[index][0]) * ARRAY_SIZE(res[index]));
|
||||
|
|
|
@ -67,6 +67,9 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);
|
|||
/* Leave room for 32 hexadeciaml digits (UUID) + NULL */
|
||||
#define CLIENT_EP_LEN 33
|
||||
|
||||
/* Up to 3 characters + NULL */
|
||||
#define CLIENT_BINDING_LEN sizeof("UQS")
|
||||
|
||||
/* The states for the RD client state machine */
|
||||
/*
|
||||
* When node is unregistered it ends up in UNREGISTERED
|
||||
|
@ -579,6 +582,7 @@ static int sm_send_registration(bool send_obj_support_data,
|
|||
struct lwm2m_message *msg;
|
||||
u16_t client_data_len;
|
||||
int ret;
|
||||
char binding[CLIENT_BINDING_LEN];
|
||||
|
||||
msg = lwm2m_get_message(client.ctx);
|
||||
if (!msg) {
|
||||
|
@ -633,7 +637,15 @@ static int sm_send_registration(bool send_obj_support_data,
|
|||
coap_packet_append_option(&msg->cpkt, COAP_OPTION_URI_QUERY,
|
||||
query_buffer, strlen(query_buffer));
|
||||
|
||||
/* TODO: add supported binding query string */
|
||||
lwm2m_engine_get_binding(binding);
|
||||
/* UDP is a default binding, no need to add option if UDP is used. */
|
||||
if (strcmp(binding, "U") != 0) {
|
||||
snprintk(query_buffer, sizeof(query_buffer) - 1,
|
||||
"b=%s", binding);
|
||||
/* TODO: handle return error */
|
||||
coap_packet_append_option(&msg->cpkt, COAP_OPTION_URI_QUERY,
|
||||
query_buffer, strlen(query_buffer));
|
||||
}
|
||||
|
||||
if (send_obj_support_data) {
|
||||
ret = coap_packet_append_payload_marker(&msg->cpkt);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue