Merge pull request #590 from carlosgp143/contrib/lwm2m-multiple-server
Add support for multiple server session in LwM2M
This commit is contained in:
commit
12f3686232
@ -34,6 +34,7 @@
|
||||
* \author
|
||||
* Joakim Eriksson, joakime@sics.se
|
||||
* Niclas Finne, nfi@sics.se
|
||||
* Carlos Gonzalo Peces, carlosgp143@gmail.com
|
||||
*/
|
||||
|
||||
#include "contiki.h"
|
||||
@ -51,18 +52,28 @@
|
||||
#define DEBUG DEBUG_NONE
|
||||
#include "net/ipv6/uip-debug.h"
|
||||
|
||||
/* Define this macro to non-zero to register via a bootstrap server */
|
||||
#ifndef REGISTER_WITH_LWM2M_BOOTSTRAP_SERVER
|
||||
#define REGISTER_WITH_LWM2M_BOOTSTRAP_SERVER 0
|
||||
#endif
|
||||
|
||||
#ifndef REGISTER_WITH_LWM2M_SERVER
|
||||
#define REGISTER_WITH_LWM2M_SERVER 1
|
||||
#if REGISTER_WITH_LWM2M_BOOTSTRAP_SERVER
|
||||
#define SERVER_TYPE LWM2M_RD_CLIENT_BOOTSTRAP_SERVER
|
||||
#else
|
||||
#define SERVER_TYPE LWM2M_RD_CLIENT_LWM2M_SERVER
|
||||
#endif
|
||||
|
||||
#ifndef LWM2M_SERVER_ADDRESS
|
||||
#define LWM2M_SERVER_ADDRESS "coap://[fd00::1]"
|
||||
#endif
|
||||
|
||||
static lwm2m_session_info_t session_info;
|
||||
|
||||
/* Define this macro to register with a second LWM2M server */
|
||||
#ifdef LWM2M_SERVER_ADDRESS_SECOND
|
||||
static lwm2m_session_info_t session_info_second;
|
||||
#endif
|
||||
|
||||
#if BOARD_SENSORTAG
|
||||
#include "board-peripherals.h"
|
||||
|
||||
@ -148,13 +159,17 @@ 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);
|
||||
lwm2m_rd_client_register_with_server(&session_info, &server_ep, SERVER_TYPE);
|
||||
}
|
||||
#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);
|
||||
#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) {
|
||||
lwm2m_rd_client_register_with_server(&session_info_second, &server_ep_second, SERVER_TYPE);
|
||||
}
|
||||
#endif /* LWM2M_SERVER_ADDRESS_SECOND */
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(example_ipso_objects, ev, data)
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -46,6 +46,13 @@
|
||||
#ifndef LWM2M_RD_CLIENT_H_
|
||||
#define LWM2M_RD_CLIENT_H_
|
||||
|
||||
/* The type of server to use for registration: bootstrap or LWM2M */
|
||||
typedef enum {
|
||||
LWM2M_RD_CLIENT_BOOTSTRAP_SERVER,
|
||||
LWM2M_RD_CLIENT_LWM2M_SERVER
|
||||
} lwm2m_rd_client_server_type_t;
|
||||
|
||||
/* Session callback states */
|
||||
#define LWM2M_RD_CLIENT_BOOTSTRAPPED 1
|
||||
#define LWM2M_RD_CLIENT_REGISTERED 2
|
||||
#define LWM2M_RD_CLIENT_DEREGISTERED 3
|
||||
@ -54,28 +61,70 @@
|
||||
|
||||
#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;
|
||||
lwm2m_rd_client_server_type_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, lwm2m_rd_client_server_type_t server_type);
|
||||
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 +133,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_ */
|
||||
/** @} */
|
||||
|
@ -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 {
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 67b858437f7cf1e4e027d821c4c2ac15fdf2ab44
|
||||
Subproject commit 3b23ca8d6a19d281b6330d3f24afc2e1bb14ddb7
|
Loading…
Reference in New Issue
Block a user