Contiki-NG
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 */
50 typedef 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 #include "lwm2m-object.h"
63 #include "lwm2m-queue-mode-conf.h"
64 #include "coap-endpoint.h"
65 #include "coap-callback-api.h"
66 
67 struct lwm2m_session_info;
68 typedef void (*session_callback_t)(struct lwm2m_session_info *session, int status);
69 
70 #ifndef LWM2M_RD_CLIENT_ASSIGNED_ENDPOINT_MAX_LEN
71 #define LWM2M_RD_CLIENT_ASSIGNED_ENDPOINT_MAX_LEN 15
72 #endif /* LWM2M_RD_CLIENT_ASSIGNED_ENDPOINT_MAX_LEN */
73 /*---------------------------------------------------------------------------*/
74 /*- Server session----------------------------*/
75 /*---------------------------------------------------------------------------*/
76 typedef struct lwm2m_session_info {
77 
78  struct lwm2m_session_info *next;
79  /* Information */
80  const char *ep;
81  const char *binding;
82  char assigned_ep[LWM2M_RD_CLIENT_ASSIGNED_ENDPOINT_MAX_LEN];
83  uint16_t lifetime;
84  coap_endpoint_t bs_server_ep;
85  coap_endpoint_t server_ep;
86  lwm2m_rd_client_server_type_t use_server_type;
87  uint8_t has_bs_server_info;
88  uint8_t has_registration_server_info;
89  uint8_t bootstrapped; /* bootstrap done */
90  session_callback_t callback;
91 
92  /* CoAP Request */
93  coap_callback_request_state_t rd_request_state;
94  coap_message_t request[1]; /* This way the message can be treated as pointer as usual. */
95 
96  /* RD parameters */
97  uint8_t rd_state;
98  uint8_t rd_flags;
99  uint64_t wait_until_network_check;
100  uint64_t last_update;
101  uint64_t last_rd_progress;
102 
103  /* Blosk Transfer */
104  uint32_t rd_block1;
105  uint8_t rd_more;
106  void (*rd_callback)(coap_callback_request_state_t *state);
107  coap_timer_t block1_timer;
108 } lwm2m_session_info_t;
109 
110 int lwm2m_rd_client_is_registered(lwm2m_session_info_t *session_info);
111 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);
112 uint16_t lwm2m_rd_client_get_lifetime(lwm2m_session_info_t *session_info);
113 void lwm2m_rd_client_set_lifetime(lwm2m_session_info_t *session_info, uint16_t lifetime);
114 void lwm2m_rd_client_set_endpoint_name(lwm2m_session_info_t *session_info, const char *endpoint);
115 void lwm2m_rd_client_set_default_endpoint_name(const char *endpoint);
116 
117 /* Indicate that something in the object list have changed */
118 void lwm2m_rd_client_set_update_rd(void);
119 /* Control if the object list should be automatically updated at updates of lifetime */
120 void lwm2m_rd_client_set_automatic_update(lwm2m_session_info_t *session_info, int update);
121 /* trigger an immediate update */
122 void lwm2m_rd_client_update_triggered(const coap_endpoint_t *server_ep);
123 
124 int lwm2m_rd_client_deregister(lwm2m_session_info_t *session_info);
125 void lwm2m_rd_client_init(const char *ep);
126 
127 void lwm2m_rd_client_set_session_callback(lwm2m_session_info_t *session_info, session_callback_t cb);
128 
129 #if LWM2M_QUEUE_MODE_ENABLED
130 uint8_t lwm2m_rd_client_is_client_awake(void);
131 void lwm2m_rd_client_restart_client_awake_timer(void);
132 void lwm2m_rd_client_fsm_execute_queue_mode_awake();
133 void lwm2m_rd_client_fsm_execute_queue_mode_update();
134 #endif
135 
136 #endif /* LWM2M_RD_CLIENT_H_ */
137 /** @} */
Header file for the LWM2M object API
API to address CoAP endpoints
Callback API for doing CoAP requests Adapted from the blocking API
Queue Mode Configuration Parameters