Added support for multiple server session in LwM2M

This commit is contained in:
carlosgp143@gmail.com 2018-04-30 13:04:23 +02:00 committed by Carlos Gonzalo
parent 21f9d1710c
commit be71b5fc1d
4 changed files with 537 additions and 399 deletions

View File

@ -34,6 +34,7 @@
* \author
* Joakim Eriksson, joakime@sics.se
* Niclas Finne, nfi@sics.se
* Carlos Gonzalo Peces, carlosgp143@gmail.com
*/
#include "contiki.h"
@ -63,6 +64,20 @@
#define LWM2M_SERVER_ADDRESS "coap://[fd00::1]"
#endif
#ifndef LWM2M_SERVER_ADDRESS_SECOND
#define LWM2M_SERVER_ADDRESS_SECOND "coap://[fd00::1]:5686"
#endif
#ifndef LWM2M_SESSIONS
#define LWM2M_SESSIONS 2
#endif
static lwm2m_session_info_t session_info;
#if LWM2M_SESSIONS == 2
static lwm2m_session_info_t session_info_second;
#endif
#if BOARD_SENSORTAG
#include "board-peripherals.h"
@ -148,13 +163,27 @@ setup_lwm2m_servers(void)
coap_endpoint_t server_ep;
if(coap_endpoint_parse(LWM2M_SERVER_ADDRESS, strlen(LWM2M_SERVER_ADDRESS),
&server_ep) != 0) {
lwm2m_rd_client_register_with_bootstrap_server(&server_ep);
lwm2m_rd_client_register_with_server(&server_ep);
#if REGISTER_WITH_LWM2M_BOOTSTRAP_SERVER
lwm2m_rd_client_register_with_bootstrap_server(&session_info, &server_ep);
#else
lwm2m_rd_client_register_with_server(&session_info, &server_ep);
#endif
}
#endif /* LWM2M_SERVER_ADDRESS */
lwm2m_rd_client_use_bootstrap_server(REGISTER_WITH_LWM2M_BOOTSTRAP_SERVER);
lwm2m_rd_client_use_registration_server(REGISTER_WITH_LWM2M_SERVER);
#if LWM2M_SESSIONS == 2
#ifdef LWM2M_SERVER_ADDRESS_SECOND
coap_endpoint_t server_ep_second;
if(coap_endpoint_parse(LWM2M_SERVER_ADDRESS_SECOND, strlen(LWM2M_SERVER_ADDRESS_SECOND),
&server_ep_second) != 0) {
#if REGISTER_WITH_LWM2M_BOOTSTRAP_SERVER
lwm2m_rd_client_register_with_bootstrap_server(&session_info_second, &server_ep_second);
#else
lwm2m_rd_client_register_with_server(&session_info_second, &server_ep_second);
#endif
}
#endif /* LWM2M_SERVER_ADDRESS_SECOND */
#endif /* LWM2M_SESSIONS == 2 */
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(example_ipso_objects, ev, data)

File diff suppressed because it is too large Load Diff

View File

@ -54,28 +54,71 @@
#include "lwm2m-object.h"
#include "lwm2m-queue-mode-conf.h"
#include "coap-endpoint.h"
#include "coap-callback-api.h"
struct lwm2m_session_info;
typedef void (*session_callback_t)(struct lwm2m_session_info *session, int status);
int lwm2m_rd_client_is_registered(void);
void lwm2m_rd_client_use_bootstrap_server(int use);
void lwm2m_rd_client_use_registration_server(int use);
void lwm2m_rd_client_register_with_server(const coap_endpoint_t *server);
void lwm2m_rd_client_register_with_bootstrap_server(const coap_endpoint_t *server);
uint16_t lwm2m_rd_client_get_lifetime(void);
void lwm2m_rd_client_set_lifetime(uint16_t lifetime);
#ifndef LWM2M_RD_CLIENT_ASSIGNED_ENDPOINT_MAX_LEN
#define LWM2M_RD_CLIENT_ASSIGNED_ENDPOINT_MAX_LEN 15
#endif /* LWM2M_RD_CLIENT_ASSIGNED_ENDPOINT_MAX_LEN */
/*---------------------------------------------------------------------------*/
/*- Server session----------------------------*/
/*---------------------------------------------------------------------------*/
typedef struct lwm2m_session_info {
struct lwm2m_session_info *next;
/* Information */
const char *ep;
const char *binding;
char assigned_ep[LWM2M_RD_CLIENT_ASSIGNED_ENDPOINT_MAX_LEN];
uint16_t lifetime;
coap_endpoint_t bs_server_ep;
coap_endpoint_t server_ep;
uint8_t use_server_type;
uint8_t has_bs_server_info;
uint8_t has_registration_server_info;
uint8_t bootstrapped; /* bootstrap done */
session_callback_t callback;
/* CoAP Request */
coap_callback_request_state_t rd_request_state;
coap_message_t request[1]; /* This way the message can be treated as pointer as usual. */
/* RD parameters */
uint8_t rd_state;
uint8_t rd_flags;
uint64_t wait_until_network_check;
uint64_t last_update;
uint64_t last_rd_progress;
/* Blosk Transfer */
uint32_t rd_block1;
uint8_t rd_more;
void (*rd_callback)(coap_callback_request_state_t *state);
coap_timer_t block1_timer;
} lwm2m_session_info_t;
int lwm2m_rd_client_is_registered(lwm2m_session_info_t *session_info);
void lwm2m_rd_client_register_with_server(lwm2m_session_info_t *session_info, const coap_endpoint_t *server);
void lwm2m_rd_client_register_with_bootstrap_server(lwm2m_session_info_t *session_info, const coap_endpoint_t *server);
uint16_t lwm2m_rd_client_get_lifetime(lwm2m_session_info_t *session_info);
void lwm2m_rd_client_set_lifetime(lwm2m_session_info_t *session_info, uint16_t lifetime);
void lwm2m_rd_client_set_endpoint_name(lwm2m_session_info_t *session_info, const char *endpoint);
void lwm2m_rd_client_set_default_endpoint_name(const char *endpoint);
/* Indicate that something in the object list have changed */
void lwm2m_rd_client_set_update_rd(void);
/* Control if the object list should be automatically updated at updates of lifetime */
void lwm2m_rd_client_set_automatic_update(int update);
void lwm2m_rd_client_set_automatic_update(lwm2m_session_info_t *session_info, int update);
/* trigger an immediate update */
void lwm2m_rd_client_update_triggered(void);
void lwm2m_rd_client_update_triggered(const coap_endpoint_t *server_ep);
int lwm2m_rd_client_deregister(void);
int lwm2m_rd_client_deregister(lwm2m_session_info_t *session_info);
void lwm2m_rd_client_init(const char *ep);
void lwm2m_rd_client_set_session_callback(session_callback_t cb);
void lwm2m_rd_client_set_session_callback(lwm2m_session_info_t *session_info, session_callback_t cb);
#if LWM2M_QUEUE_MODE_ENABLED
uint8_t lwm2m_rd_client_is_client_awake(void);
@ -84,28 +127,5 @@ void lwm2m_rd_client_fsm_execute_queue_mode_awake();
void lwm2m_rd_client_fsm_execute_queue_mode_update();
#endif
#ifndef LWM2M_RD_CLIENT_ASSIGNED_ENDPOINT_MAX_LEN
#define LWM2M_RD_CLIENT_ASSIGNED_ENDPOINT_MAX_LEN 15
#endif /* LWM2M_RD_CLIENT_ASSIGNED_ENDPOINT_MAX_LEN */
/*---------------------------------------------------------------------------*/
/*- Server session-*Currently single session only*---------------------------*/
/*---------------------------------------------------------------------------*/
struct lwm2m_session_info {
const char *ep;
const char *binding;
char assigned_ep[LWM2M_RD_CLIENT_ASSIGNED_ENDPOINT_MAX_LEN];
uint16_t lifetime;
coap_endpoint_t bs_server_ep;
coap_endpoint_t server_ep;
uint8_t use_bootstrap;
uint8_t has_bs_server_info;
uint8_t use_registration;
uint8_t has_registration_server_info;
uint8_t registered;
uint8_t bootstrapped; /* bootstrap done */
session_callback_t callback;
};
#endif /* LWM2M_RD_CLIENT_H_ */
/** @} */

View File

@ -221,7 +221,7 @@ lwm2m_callback(lwm2m_object_instance_t *object,
} else if(ctx->operation == LWM2M_OP_EXECUTE) {
switch(ctx->resource_id) {
case LWM2M_SERVER_REG_UPDATE_TRIGGER_ID:
lwm2m_rd_client_update_triggered();
lwm2m_rd_client_update_triggered(ctx->request->src_ep);
break;
}
} else {