Contiki-NG
Loading...
Searching...
No Matches
lwm2m-rd-client.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2016-2018, SICS Swedish ICT AB.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the copyright holder nor the names of its
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28 * OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31/**
32 * \addtogroup lwm2m
33 * @{
34 */
35
36/**
37 * \file
38 * Header file for the Contiki OMA LWM2M Registration and Bootstrap
39 * Client.
40 * \author
41 * Joakim Eriksson <joakime@sics.se>
42 * Niclas Finne <nfi@sics.se>
43 * Carlos Gonzalo Peces <carlosgp143@gmail.com>
44 */
45
46#ifndef LWM2M_RD_CLIENT_H_
47#define LWM2M_RD_CLIENT_H_
48
49/* The type of server to use for registration: bootstrap or LWM2M */
50typedef enum {
51 LWM2M_RD_CLIENT_BOOTSTRAP_SERVER,
52 LWM2M_RD_CLIENT_LWM2M_SERVER
53} lwm2m_rd_client_server_type_t;
54
55/* Session callback states */
56#define LWM2M_RD_CLIENT_BOOTSTRAPPED 1
57#define LWM2M_RD_CLIENT_REGISTERED 2
58#define LWM2M_RD_CLIENT_DEREGISTERED 3
59#define LWM2M_RD_CLIENT_DEREGISTER_FAILED 4
60#define LWM2M_RD_CLIENT_DISCONNECTED 5
61
62#define LWM2M_PROTOCOL_VERSION "1.0"
63
64#include "lwm2m-object.h"
66#include "coap-endpoint.h"
67#include "coap-callback-api.h"
68
69struct lwm2m_session_info;
70typedef void (*session_callback_t)(struct lwm2m_session_info *session, int status);
71
72#ifndef LWM2M_RD_CLIENT_ASSIGNED_ENDPOINT_MAX_LEN
73#define LWM2M_RD_CLIENT_ASSIGNED_ENDPOINT_MAX_LEN 15
74#endif /* LWM2M_RD_CLIENT_ASSIGNED_ENDPOINT_MAX_LEN */
75/*---------------------------------------------------------------------------*/
76/*- Server session----------------------------*/
77/*---------------------------------------------------------------------------*/
78typedef struct lwm2m_session_info {
79
80 struct lwm2m_session_info *next;
81 /* Information */
82 const char *ep;
83 const char *binding;
84 char assigned_ep[LWM2M_RD_CLIENT_ASSIGNED_ENDPOINT_MAX_LEN];
85 uint16_t lifetime;
86 coap_endpoint_t bs_server_ep;
87 coap_endpoint_t server_ep;
88 lwm2m_rd_client_server_type_t use_server_type;
89 uint8_t has_bs_server_info;
90 uint8_t has_registration_server_info;
91 uint8_t bootstrapped; /* bootstrap done */
92 session_callback_t callback;
93
94 /* CoAP Request */
95 coap_callback_request_state_t rd_request_state;
96 coap_message_t request[1]; /* This way the message can be treated as pointer as usual. */
97
98 /* RD parameters */
99 uint8_t rd_state;
100 uint8_t rd_flags;
101 uint64_t wait_until_network_check;
102 uint64_t last_update;
103 uint64_t last_rd_progress;
104
105 /* Blosk Transfer */
106 uint32_t rd_block1;
107 uint8_t rd_more;
108 void (*rd_callback)(coap_callback_request_state_t *state);
109 coap_timer_t block1_timer;
110} lwm2m_session_info_t;
111
112int lwm2m_rd_client_is_registered(lwm2m_session_info_t *session_info);
113void 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);
114uint16_t lwm2m_rd_client_get_lifetime(lwm2m_session_info_t *session_info);
115void lwm2m_rd_client_set_lifetime(lwm2m_session_info_t *session_info, uint16_t lifetime);
116void lwm2m_rd_client_set_endpoint_name(lwm2m_session_info_t *session_info, const char *endpoint);
117void lwm2m_rd_client_set_default_endpoint_name(const char *endpoint);
118
119/* Indicate that something in the object list have changed */
120void lwm2m_rd_client_set_update_rd(void);
121/* Control if the object list should be automatically updated at updates of lifetime */
122void lwm2m_rd_client_set_automatic_update(lwm2m_session_info_t *session_info, int update);
123/* trigger an immediate update */
124void lwm2m_rd_client_update_triggered(const coap_endpoint_t *server_ep);
125
126int lwm2m_rd_client_deregister(lwm2m_session_info_t *session_info);
127void lwm2m_rd_client_init(const char *ep);
128
129void lwm2m_rd_client_set_session_callback(lwm2m_session_info_t *session_info, session_callback_t cb);
130
131#if LWM2M_QUEUE_MODE_ENABLED
132uint8_t lwm2m_rd_client_is_client_awake(void);
133void lwm2m_rd_client_restart_client_awake_timer(void);
134void lwm2m_rd_client_fsm_execute_queue_mode_awake();
135void lwm2m_rd_client_fsm_execute_queue_mode_update();
136#endif
137
138#endif /* LWM2M_RD_CLIENT_H_ */
139/** @} */
Callback API for doing CoAP requests Adapted from the blocking API.
API to address CoAP endpoints.
Header file for the LWM2M object API.
Queue Mode Configuration Parameters.