leo hendrickson / Mbed OS example-Ethernet-mbed-Cloud-connect
Committer:
leothedragon
Date:
Tue May 04 08:55:12 2021 +0000
Revision:
0:8f0bb79ddd48
nmn

Who changed what in which revision?

UserRevisionLine numberNew contents of line
leothedragon 0:8f0bb79ddd48 1 /*
leothedragon 0:8f0bb79ddd48 2 * Copyright (c) 2015 ARM Limited. All rights reserved.
leothedragon 0:8f0bb79ddd48 3 * SPDX-License-Identifier: Apache-2.0
leothedragon 0:8f0bb79ddd48 4 * Licensed under the Apache License, Version 2.0 (the License); you may
leothedragon 0:8f0bb79ddd48 5 * not use this file except in compliance with the License.
leothedragon 0:8f0bb79ddd48 6 * You may obtain a copy of the License at
leothedragon 0:8f0bb79ddd48 7 *
leothedragon 0:8f0bb79ddd48 8 * http://www.apache.org/licenses/LICENSE-2.0
leothedragon 0:8f0bb79ddd48 9 *
leothedragon 0:8f0bb79ddd48 10 * Unless required by applicable law or agreed to in writing, software
leothedragon 0:8f0bb79ddd48 11 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
leothedragon 0:8f0bb79ddd48 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
leothedragon 0:8f0bb79ddd48 13 * See the License for the specific language governing permissions and
leothedragon 0:8f0bb79ddd48 14 * limitations under the License.
leothedragon 0:8f0bb79ddd48 15 */
leothedragon 0:8f0bb79ddd48 16 #ifndef M2MNSDLINTERFACE_H
leothedragon 0:8f0bb79ddd48 17 #define M2MNSDLINTERFACE_H
leothedragon 0:8f0bb79ddd48 18
leothedragon 0:8f0bb79ddd48 19 #include "ns_list.h"
leothedragon 0:8f0bb79ddd48 20 #include "mbed-client/m2mvector.h"
leothedragon 0:8f0bb79ddd48 21 #include "mbed-client/m2mconfig.h"
leothedragon 0:8f0bb79ddd48 22 #include "mbed-client/m2minterface.h"
leothedragon 0:8f0bb79ddd48 23 #include "mbed-client/m2mtimerobserver.h"
leothedragon 0:8f0bb79ddd48 24 #include "mbed-client/m2mobservationhandler.h"
leothedragon 0:8f0bb79ddd48 25 #include "mbed-client/m2mtimer.h"
leothedragon 0:8f0bb79ddd48 26 #include "mbed-client/m2mbase.h"
leothedragon 0:8f0bb79ddd48 27 #include "mbed-client/m2mserver.h"
leothedragon 0:8f0bb79ddd48 28 #include "include/nsdllinker.h"
leothedragon 0:8f0bb79ddd48 29 #include "eventOS_event.h"
leothedragon 0:8f0bb79ddd48 30
leothedragon 0:8f0bb79ddd48 31 //FORWARD DECLARARTION
leothedragon 0:8f0bb79ddd48 32 class M2MSecurity;
leothedragon 0:8f0bb79ddd48 33 class M2MObject;
leothedragon 0:8f0bb79ddd48 34 class M2MObjectInstance;
leothedragon 0:8f0bb79ddd48 35 class M2MResource;
leothedragon 0:8f0bb79ddd48 36 class M2MResourceInstance;
leothedragon 0:8f0bb79ddd48 37 class M2MNsdlObserver;
leothedragon 0:8f0bb79ddd48 38 class M2MServer;
leothedragon 0:8f0bb79ddd48 39 class M2MConnectionHandler;
leothedragon 0:8f0bb79ddd48 40 class M2MNotificationHandler;
leothedragon 0:8f0bb79ddd48 41
leothedragon 0:8f0bb79ddd48 42 const int UNDEFINED_MSG_ID = -1;
leothedragon 0:8f0bb79ddd48 43
leothedragon 0:8f0bb79ddd48 44 /**
leothedragon 0:8f0bb79ddd48 45 * @brief M2MNsdlInterface
leothedragon 0:8f0bb79ddd48 46 * Class which interacts between mbed Client C++ Library and mbed-client-c library.
leothedragon 0:8f0bb79ddd48 47 */
leothedragon 0:8f0bb79ddd48 48 class M2MNsdlInterface : public M2MTimerObserver,
leothedragon 0:8f0bb79ddd48 49 public M2MObservationHandler
leothedragon 0:8f0bb79ddd48 50 {
leothedragon 0:8f0bb79ddd48 51 private:
leothedragon 0:8f0bb79ddd48 52 // Prevents the use of assignment operator by accident.
leothedragon 0:8f0bb79ddd48 53 M2MNsdlInterface& operator=( const M2MNsdlInterface& /*other*/ );
leothedragon 0:8f0bb79ddd48 54
leothedragon 0:8f0bb79ddd48 55 // Prevents the use of copy constructor by accident
leothedragon 0:8f0bb79ddd48 56 M2MNsdlInterface( const M2MNsdlInterface& /*other*/ );
leothedragon 0:8f0bb79ddd48 57
leothedragon 0:8f0bb79ddd48 58 public:
leothedragon 0:8f0bb79ddd48 59
leothedragon 0:8f0bb79ddd48 60 struct request_context_s {
leothedragon 0:8f0bb79ddd48 61 request_data_cb on_request_data_cb;
leothedragon 0:8f0bb79ddd48 62 request_error_cb on_request_error_cb;
leothedragon 0:8f0bb79ddd48 63 size_t received_size;
leothedragon 0:8f0bb79ddd48 64 uint32_t msg_token;
leothedragon 0:8f0bb79ddd48 65 char *uri_path;
leothedragon 0:8f0bb79ddd48 66 void *context;
leothedragon 0:8f0bb79ddd48 67 bool async_req;
leothedragon 0:8f0bb79ddd48 68 sn_coap_msg_code_e msg_code;
leothedragon 0:8f0bb79ddd48 69 bool resend;
leothedragon 0:8f0bb79ddd48 70 DownloadType download_type;
leothedragon 0:8f0bb79ddd48 71 ns_list_link_t link;
leothedragon 0:8f0bb79ddd48 72 };
leothedragon 0:8f0bb79ddd48 73
leothedragon 0:8f0bb79ddd48 74 struct nsdl_coap_data_s {
leothedragon 0:8f0bb79ddd48 75 nsdl_s *nsdl_handle;
leothedragon 0:8f0bb79ddd48 76 sn_coap_hdr_s *received_coap_header;
leothedragon 0:8f0bb79ddd48 77 sn_nsdl_addr_s address;
leothedragon 0:8f0bb79ddd48 78 };
leothedragon 0:8f0bb79ddd48 79
leothedragon 0:8f0bb79ddd48 80 struct coap_response_s {
leothedragon 0:8f0bb79ddd48 81 char *uri_path;
leothedragon 0:8f0bb79ddd48 82 int32_t msg_id;
leothedragon 0:8f0bb79ddd48 83 M2MBase::MessageType type;
leothedragon 0:8f0bb79ddd48 84 bool blockwise_used;
leothedragon 0:8f0bb79ddd48 85 ns_list_link_t link;
leothedragon 0:8f0bb79ddd48 86 };
leothedragon 0:8f0bb79ddd48 87
leothedragon 0:8f0bb79ddd48 88 typedef NS_LIST_HEAD(request_context_s, link) request_context_list_t;
leothedragon 0:8f0bb79ddd48 89
leothedragon 0:8f0bb79ddd48 90 typedef NS_LIST_HEAD(coap_response_s, link) response_list_t;
leothedragon 0:8f0bb79ddd48 91
leothedragon 0:8f0bb79ddd48 92 /**
leothedragon 0:8f0bb79ddd48 93 * @brief Constructor
leothedragon 0:8f0bb79ddd48 94 * @param observer, Observer to pass the event callbacks from nsdl library.
leothedragon 0:8f0bb79ddd48 95 */
leothedragon 0:8f0bb79ddd48 96 M2MNsdlInterface(M2MNsdlObserver &observer, M2MConnectionHandler &connection_handler);
leothedragon 0:8f0bb79ddd48 97
leothedragon 0:8f0bb79ddd48 98 /**
leothedragon 0:8f0bb79ddd48 99 * @brief Destructor
leothedragon 0:8f0bb79ddd48 100 */
leothedragon 0:8f0bb79ddd48 101 virtual ~M2MNsdlInterface();
leothedragon 0:8f0bb79ddd48 102
leothedragon 0:8f0bb79ddd48 103 /**
leothedragon 0:8f0bb79ddd48 104 * @brief Creates endpoint object for the nsdl stack.
leothedragon 0:8f0bb79ddd48 105 * @param endpoint_name, Endpoint name of the client.
leothedragon 0:8f0bb79ddd48 106 * @param endpoint_type, Endpoint type of the client.
leothedragon 0:8f0bb79ddd48 107 * @param life_time, Life time of the client in seconds
leothedragon 0:8f0bb79ddd48 108 * @param domain, Domain of the client.
leothedragon 0:8f0bb79ddd48 109 * @param mode, Binding mode of the client, default is UDP
leothedragon 0:8f0bb79ddd48 110 * @param context_address, Context address default is empty.
leothedragon 0:8f0bb79ddd48 111 */
leothedragon 0:8f0bb79ddd48 112 void create_endpoint(const String &endpoint_name,
leothedragon 0:8f0bb79ddd48 113 const String &endpoint_type,
leothedragon 0:8f0bb79ddd48 114 const int32_t life_time,
leothedragon 0:8f0bb79ddd48 115 const String &domain,
leothedragon 0:8f0bb79ddd48 116 const uint8_t mode,
leothedragon 0:8f0bb79ddd48 117 const String &context_address);
leothedragon 0:8f0bb79ddd48 118
leothedragon 0:8f0bb79ddd48 119 /**
leothedragon 0:8f0bb79ddd48 120 * @brief Deletes the endpoint.
leothedragon 0:8f0bb79ddd48 121 */
leothedragon 0:8f0bb79ddd48 122 void delete_endpoint();
leothedragon 0:8f0bb79ddd48 123
leothedragon 0:8f0bb79ddd48 124 /**
leothedragon 0:8f0bb79ddd48 125 * @brief Updates endpoint name.
leothedragon 0:8f0bb79ddd48 126 */
leothedragon 0:8f0bb79ddd48 127 void update_endpoint(const String &name);
leothedragon 0:8f0bb79ddd48 128
leothedragon 0:8f0bb79ddd48 129 /**
leothedragon 0:8f0bb79ddd48 130 * @brief Updates domain.
leothedragon 0:8f0bb79ddd48 131 */
leothedragon 0:8f0bb79ddd48 132 void update_domain(const String &domain);
leothedragon 0:8f0bb79ddd48 133
leothedragon 0:8f0bb79ddd48 134 /**
leothedragon 0:8f0bb79ddd48 135 * @brief Creates the NSDL structure for the registered objectlist.
leothedragon 0:8f0bb79ddd48 136 * @param list, List of objects implementing the M2MBase interface to be registered.
leothedragon 0:8f0bb79ddd48 137 * @return true if structure created successfully else false.
leothedragon 0:8f0bb79ddd48 138 */
leothedragon 0:8f0bb79ddd48 139 bool create_nsdl_list_structure(const M2MBaseList &list);
leothedragon 0:8f0bb79ddd48 140
leothedragon 0:8f0bb79ddd48 141 /**
leothedragon 0:8f0bb79ddd48 142 * @brief Removed the NSDL resource for the given resource.
leothedragon 0:8f0bb79ddd48 143 * @param base, Resource to be removed.
leothedragon 0:8f0bb79ddd48 144 * @return true if removed successfully else false.
leothedragon 0:8f0bb79ddd48 145 */
leothedragon 0:8f0bb79ddd48 146 bool remove_nsdl_resource(M2MBase *base);
leothedragon 0:8f0bb79ddd48 147
leothedragon 0:8f0bb79ddd48 148 /**
leothedragon 0:8f0bb79ddd48 149 * @brief Creates the bootstrap object.
leothedragon 0:8f0bb79ddd48 150 * @param address Bootstrap address.
leothedragon 0:8f0bb79ddd48 151 * @return true if created and sent successfully else false.
leothedragon 0:8f0bb79ddd48 152 */
leothedragon 0:8f0bb79ddd48 153 bool create_bootstrap_resource(sn_nsdl_addr_s *address);
leothedragon 0:8f0bb79ddd48 154
leothedragon 0:8f0bb79ddd48 155 /**
leothedragon 0:8f0bb79ddd48 156 * @brief Sets the register message to the server.
leothedragon 0:8f0bb79ddd48 157 * @param address M2MServer address.
leothedragon 0:8f0bb79ddd48 158 * @param address_length M2MServer address length.
leothedragon 0:8f0bb79ddd48 159 * @param port M2MServer port.
leothedragon 0:8f0bb79ddd48 160 * @param address_type IP Address type.
leothedragon 0:8f0bb79ddd48 161 */
leothedragon 0:8f0bb79ddd48 162 void set_server_address(uint8_t* address,
leothedragon 0:8f0bb79ddd48 163 uint8_t address_length,
leothedragon 0:8f0bb79ddd48 164 const uint16_t port,
leothedragon 0:8f0bb79ddd48 165 sn_nsdl_addr_type_e address_type);
leothedragon 0:8f0bb79ddd48 166 /**
leothedragon 0:8f0bb79ddd48 167 * @brief Sends the register message to the server.
leothedragon 0:8f0bb79ddd48 168 * @return true if register sent successfully else false.
leothedragon 0:8f0bb79ddd48 169 */
leothedragon 0:8f0bb79ddd48 170 bool send_register_message();
leothedragon 0:8f0bb79ddd48 171
leothedragon 0:8f0bb79ddd48 172 /**
leothedragon 0:8f0bb79ddd48 173 * @brief Sends the CoAP request to the server.
leothedragon 0:8f0bb79ddd48 174 * @type Download type.
leothedragon 0:8f0bb79ddd48 175 * @uri Uri path to the data.
leothedragon 0:8f0bb79ddd48 176 * @msg_code CoAP message code of request to send.
leothedragon 0:8f0bb79ddd48 177 * @offset Data offset.
leothedragon 0:8f0bb79ddd48 178 * @async In async mode application must call this API again with the updated offset.
leothedragon 0:8f0bb79ddd48 179 * If set to false then client will automatically download the whole package.
leothedragon 0:8f0bb79ddd48 180 * @token The token to use for the request, 0 value will generate new token.
leothedragon 0:8f0bb79ddd48 181 * @payload_len Length of payload buffer.
leothedragon 0:8f0bb79ddd48 182 * @payload_ptr Pointer to payload buffer.
leothedragon 0:8f0bb79ddd48 183 * @request_data_cb Callback which is triggered once there is data available.
leothedragon 0:8f0bb79ddd48 184 * @request_error_cb Callback which is trigged in case of any error.
leothedragon 0:8f0bb79ddd48 185 * @context Application context.
leothedragon 0:8f0bb79ddd48 186 */
leothedragon 0:8f0bb79ddd48 187 void send_request(DownloadType type,
leothedragon 0:8f0bb79ddd48 188 const char *uri,
leothedragon 0:8f0bb79ddd48 189 const sn_coap_msg_code_e msg_code,
leothedragon 0:8f0bb79ddd48 190 const size_t offset,
leothedragon 0:8f0bb79ddd48 191 const bool async,
leothedragon 0:8f0bb79ddd48 192 uint32_t token,
leothedragon 0:8f0bb79ddd48 193 const uint16_t payload_len,
leothedragon 0:8f0bb79ddd48 194 uint8_t *payload_ptr,
leothedragon 0:8f0bb79ddd48 195 request_data_cb data_cb,
leothedragon 0:8f0bb79ddd48 196 request_error_cb error_cb,
leothedragon 0:8f0bb79ddd48 197 void *context);
leothedragon 0:8f0bb79ddd48 198
leothedragon 0:8f0bb79ddd48 199 /**
leothedragon 0:8f0bb79ddd48 200 * @brief Sends the update registration message to the server.
leothedragon 0:8f0bb79ddd48 201 * @param lifetime, Updated lifetime value in seconds.
leothedragon 0:8f0bb79ddd48 202 * @return true if sent successfully else false.
leothedragon 0:8f0bb79ddd48 203 *
leothedragon 0:8f0bb79ddd48 204 */
leothedragon 0:8f0bb79ddd48 205 bool send_update_registration(const uint32_t lifetime = 0);
leothedragon 0:8f0bb79ddd48 206
leothedragon 0:8f0bb79ddd48 207 /**
leothedragon 0:8f0bb79ddd48 208 * @brief Sends unregister message to the server.
leothedragon 0:8f0bb79ddd48 209 * @return true if unregister sent successfully else false.
leothedragon 0:8f0bb79ddd48 210 */
leothedragon 0:8f0bb79ddd48 211 bool send_unregister_message();
leothedragon 0:8f0bb79ddd48 212
leothedragon 0:8f0bb79ddd48 213 /**
leothedragon 0:8f0bb79ddd48 214 * @brief Memory Allocation required for libCoap.
leothedragon 0:8f0bb79ddd48 215 * @param size, Size of memory to be reserved.
leothedragon 0:8f0bb79ddd48 216 */
leothedragon 0:8f0bb79ddd48 217 static void* memory_alloc(uint32_t size);
leothedragon 0:8f0bb79ddd48 218
leothedragon 0:8f0bb79ddd48 219 /**
leothedragon 0:8f0bb79ddd48 220 * @brief Memory free functions required for libCoap
leothedragon 0:8f0bb79ddd48 221 * @param ptr, Object whose memory needs to be freed.
leothedragon 0:8f0bb79ddd48 222 */
leothedragon 0:8f0bb79ddd48 223 static void memory_free(void *ptr);
leothedragon 0:8f0bb79ddd48 224
leothedragon 0:8f0bb79ddd48 225 /**
leothedragon 0:8f0bb79ddd48 226 * @brief Callback from nsdl library to inform the data is ready
leothedragon 0:8f0bb79ddd48 227 * to be sent to server.
leothedragon 0:8f0bb79ddd48 228 * @param nsdl_handle, Handler for the nsdl structure for this endpoint
leothedragon 0:8f0bb79ddd48 229 * @param protocol, Protocol format of the data
leothedragon 0:8f0bb79ddd48 230 * @param data, Data to be sent.
leothedragon 0:8f0bb79ddd48 231 * @param data_len, Size of the data to be sent
leothedragon 0:8f0bb79ddd48 232 * @param address, server address where data has to be sent.
leothedragon 0:8f0bb79ddd48 233 * @return 1 if successful else 0.
leothedragon 0:8f0bb79ddd48 234 */
leothedragon 0:8f0bb79ddd48 235 uint8_t send_to_server_callback(struct nsdl_s * nsdl_handle,
leothedragon 0:8f0bb79ddd48 236 sn_nsdl_capab_e protocol,
leothedragon 0:8f0bb79ddd48 237 uint8_t *data,
leothedragon 0:8f0bb79ddd48 238 uint16_t data_len,
leothedragon 0:8f0bb79ddd48 239 sn_nsdl_addr_s *address);
leothedragon 0:8f0bb79ddd48 240
leothedragon 0:8f0bb79ddd48 241 /**
leothedragon 0:8f0bb79ddd48 242 * @brief Callback from nsdl library to inform the data which is
leothedragon 0:8f0bb79ddd48 243 * received from server for the client has been converted to coap message.
leothedragon 0:8f0bb79ddd48 244 * @param nsdl_handle, Handler for the nsdl structure for this endpoint
leothedragon 0:8f0bb79ddd48 245 * @param coap_header, Coap message formed from data.
leothedragon 0:8f0bb79ddd48 246 * @param address, Server address from where the data is received.
leothedragon 0:8f0bb79ddd48 247 * @return 1 if successful else 0.
leothedragon 0:8f0bb79ddd48 248 */
leothedragon 0:8f0bb79ddd48 249 uint8_t received_from_server_callback(struct nsdl_s * nsdl_handle,
leothedragon 0:8f0bb79ddd48 250 sn_coap_hdr_s *coap_header,
leothedragon 0:8f0bb79ddd48 251 sn_nsdl_addr_s *address);
leothedragon 0:8f0bb79ddd48 252
leothedragon 0:8f0bb79ddd48 253 /**
leothedragon 0:8f0bb79ddd48 254 * @brief Callback from nsdl library to inform the data which is
leothedragon 0:8f0bb79ddd48 255 * received from server for the resources has been converted to coap message.
leothedragon 0:8f0bb79ddd48 256 * @param nsdl_handle, Handler for the nsdl resource structure for this endpoint..
leothedragon 0:8f0bb79ddd48 257 * @param coap_header, Coap message formed from data.
leothedragon 0:8f0bb79ddd48 258 * @param address, Server address from where the data is received.
leothedragon 0:8f0bb79ddd48 259 * @param nsdl_capab, Protocol for the message, currently only coap is supported.
leothedragon 0:8f0bb79ddd48 260 * @return 1 if successful else 0.
leothedragon 0:8f0bb79ddd48 261 */
leothedragon 0:8f0bb79ddd48 262 uint8_t resource_callback(struct nsdl_s *nsdl_handle, sn_coap_hdr_s *coap,
leothedragon 0:8f0bb79ddd48 263 sn_nsdl_addr_s *address,
leothedragon 0:8f0bb79ddd48 264 sn_nsdl_capab_e nsdl_capab);
leothedragon 0:8f0bb79ddd48 265
leothedragon 0:8f0bb79ddd48 266 /**
leothedragon 0:8f0bb79ddd48 267 * @brief Callback from event loop for handling CoAP messages received from server for the resources
leothedragon 0:8f0bb79ddd48 268 * that has been converted to coap message.
leothedragon 0:8f0bb79ddd48 269 * @param coap_header, Coap message formed from data.
leothedragon 0:8f0bb79ddd48 270 * @param address, Server address from where the data is received.
leothedragon 0:8f0bb79ddd48 271 * @return 0 if successful else 1.
leothedragon 0:8f0bb79ddd48 272 */
leothedragon 0:8f0bb79ddd48 273 uint8_t resource_callback_handle_event(sn_coap_hdr_s *coap,
leothedragon 0:8f0bb79ddd48 274 sn_nsdl_addr_s *address);
leothedragon 0:8f0bb79ddd48 275
leothedragon 0:8f0bb79ddd48 276
leothedragon 0:8f0bb79ddd48 277 /**
leothedragon 0:8f0bb79ddd48 278 * @brief Callback when there is data received from server and needs to be processed.
leothedragon 0:8f0bb79ddd48 279 * @param data, data received from server.
leothedragon 0:8f0bb79ddd48 280 * @param data_size, data size received from server.
leothedragon 0:8f0bb79ddd48 281 * @param addres, address structure of the server.
leothedragon 0:8f0bb79ddd48 282 * @return true if successfully processed else false.
leothedragon 0:8f0bb79ddd48 283 */
leothedragon 0:8f0bb79ddd48 284 bool process_received_data(uint8_t *data,
leothedragon 0:8f0bb79ddd48 285 uint16_t data_size,
leothedragon 0:8f0bb79ddd48 286 sn_nsdl_addr_s *address);
leothedragon 0:8f0bb79ddd48 287
leothedragon 0:8f0bb79ddd48 288 /**
leothedragon 0:8f0bb79ddd48 289 * @brief Stops all the timers in case there is any errors.
leothedragon 0:8f0bb79ddd48 290 */
leothedragon 0:8f0bb79ddd48 291 void stop_timers();
leothedragon 0:8f0bb79ddd48 292
leothedragon 0:8f0bb79ddd48 293 /**
leothedragon 0:8f0bb79ddd48 294 * @brief Returns nsdl handle.
leothedragon 0:8f0bb79ddd48 295 * @return ndsl handle
leothedragon 0:8f0bb79ddd48 296 */
leothedragon 0:8f0bb79ddd48 297 nsdl_s* get_nsdl_handle() const;
leothedragon 0:8f0bb79ddd48 298
leothedragon 0:8f0bb79ddd48 299 /**
leothedragon 0:8f0bb79ddd48 300 * @brief Get endpoint name
leothedragon 0:8f0bb79ddd48 301 * @return endpoint name
leothedragon 0:8f0bb79ddd48 302 */
leothedragon 0:8f0bb79ddd48 303 const String& endpoint_name() const;
leothedragon 0:8f0bb79ddd48 304
leothedragon 0:8f0bb79ddd48 305 /**
leothedragon 0:8f0bb79ddd48 306 * @brief Get internal endpoint name
leothedragon 0:8f0bb79ddd48 307 * @return internal endpoint name
leothedragon 0:8f0bb79ddd48 308 */
leothedragon 0:8f0bb79ddd48 309 const String internal_endpoint_name() const;
leothedragon 0:8f0bb79ddd48 310
leothedragon 0:8f0bb79ddd48 311 /**
leothedragon 0:8f0bb79ddd48 312 * @brief Set server address
leothedragon 0:8f0bb79ddd48 313 * @param server_address, Bootstrap or M2M server address.
leothedragon 0:8f0bb79ddd48 314 */
leothedragon 0:8f0bb79ddd48 315 void set_server_address(const char *server_address);
leothedragon 0:8f0bb79ddd48 316
leothedragon 0:8f0bb79ddd48 317 /**
leothedragon 0:8f0bb79ddd48 318 * @brief Remove an object from the list kept by the NSDLInteface.
leothedragon 0:8f0bb79ddd48 319 * Does not call delete on the object.
leothedragon 0:8f0bb79ddd48 320 */
leothedragon 0:8f0bb79ddd48 321 bool remove_object_from_list(M2MBase *base);
leothedragon 0:8f0bb79ddd48 322
leothedragon 0:8f0bb79ddd48 323 /*
leothedragon 0:8f0bb79ddd48 324 * @brief Get NSDL timer.
leothedragon 0:8f0bb79ddd48 325 * @return NSDL execution timer.
leothedragon 0:8f0bb79ddd48 326 */
leothedragon 0:8f0bb79ddd48 327 M2MTimer &get_nsdl_execution_timer();
leothedragon 0:8f0bb79ddd48 328
leothedragon 0:8f0bb79ddd48 329 /**
leothedragon 0:8f0bb79ddd48 330 * @brief Get unregister state.
leothedragon 0:8f0bb79ddd48 331 * @return Is unregistration ongoing.
leothedragon 0:8f0bb79ddd48 332 */
leothedragon 0:8f0bb79ddd48 333 bool is_unregister_ongoing() const;
leothedragon 0:8f0bb79ddd48 334
leothedragon 0:8f0bb79ddd48 335 /**
leothedragon 0:8f0bb79ddd48 336 * @brief Get update register state.
leothedragon 0:8f0bb79ddd48 337 * @return Is updare registration ongoing.
leothedragon 0:8f0bb79ddd48 338 */
leothedragon 0:8f0bb79ddd48 339 bool is_update_register_ongoing() const;
leothedragon 0:8f0bb79ddd48 340
leothedragon 0:8f0bb79ddd48 341 /**
leothedragon 0:8f0bb79ddd48 342 * @brief Starts the NSDL execution timer.
leothedragon 0:8f0bb79ddd48 343 */
leothedragon 0:8f0bb79ddd48 344 void start_nsdl_execution_timer();
leothedragon 0:8f0bb79ddd48 345
leothedragon 0:8f0bb79ddd48 346 /**
leothedragon 0:8f0bb79ddd48 347 * @brief Returns security object.
leothedragon 0:8f0bb79ddd48 348 * @return M2MSecurity object, contains lwm2m server information.
leothedragon 0:8f0bb79ddd48 349 */
leothedragon 0:8f0bb79ddd48 350 M2MSecurity* get_security_object();
leothedragon 0:8f0bb79ddd48 351
leothedragon 0:8f0bb79ddd48 352 /**
leothedragon 0:8f0bb79ddd48 353 * @brief Returns auto-observation token.
leothedragon 0:8f0bb79ddd48 354 * @param path, Resource path, used for searching the right object.
leothedragon 0:8f0bb79ddd48 355 * @param token[OUT], Token data.
leothedragon 0:8f0bb79ddd48 356 * @return Length of the token if found otherwise 0.
leothedragon 0:8f0bb79ddd48 357 */
leothedragon 0:8f0bb79ddd48 358 uint8_t find_auto_obs_token(const char *path, uint8_t *token) const;
leothedragon 0:8f0bb79ddd48 359
leothedragon 0:8f0bb79ddd48 360 /**
leothedragon 0:8f0bb79ddd48 361 * @brief Set custom uri query paramaters used in LWM2M registration.
leothedragon 0:8f0bb79ddd48 362 * @uri_query_params Uri query params. Parameters must be in key-value pair format:
leothedragon 0:8f0bb79ddd48 363 * "a=100&b=200". Maximum length can be up to 64 bytes.
leothedragon 0:8f0bb79ddd48 364 * @return False if maximum length exceeded otherwise True.
leothedragon 0:8f0bb79ddd48 365 */
leothedragon 0:8f0bb79ddd48 366 bool set_uri_query_parameters(const char *uri_query_params);
leothedragon 0:8f0bb79ddd48 367
leothedragon 0:8f0bb79ddd48 368 /**
leothedragon 0:8f0bb79ddd48 369 * @brief Clears the sent blockwise message list in CoAP library.
leothedragon 0:8f0bb79ddd48 370 */
leothedragon 0:8f0bb79ddd48 371 void clear_sent_blockwise_messages();
leothedragon 0:8f0bb79ddd48 372
leothedragon 0:8f0bb79ddd48 373 /**
leothedragon 0:8f0bb79ddd48 374 * @brief Clears the received blockwise message list in CoAP library.
leothedragon 0:8f0bb79ddd48 375 */
leothedragon 0:8f0bb79ddd48 376 void clear_received_blockwise_messages();
leothedragon 0:8f0bb79ddd48 377
leothedragon 0:8f0bb79ddd48 378 /**
leothedragon 0:8f0bb79ddd48 379 * @brief Send next notification message.
leothedragon 0:8f0bb79ddd48 380 */
leothedragon 0:8f0bb79ddd48 381 void send_next_notification(bool clear_token);
leothedragon 0:8f0bb79ddd48 382
leothedragon 0:8f0bb79ddd48 383 /**
leothedragon 0:8f0bb79ddd48 384 * @brief Store the "BS finished" response id.
leothedragon 0:8f0bb79ddd48 385 * @param msg_id Response id.
leothedragon 0:8f0bb79ddd48 386 */
leothedragon 0:8f0bb79ddd48 387 void store_bs_finished_response_id(uint16_t msg_id);
leothedragon 0:8f0bb79ddd48 388
leothedragon 0:8f0bb79ddd48 389 /**
leothedragon 0:8f0bb79ddd48 390 * @brief Store the registration state.
leothedragon 0:8f0bb79ddd48 391 * @param registered Registered to lwm2m server or not.
leothedragon 0:8f0bb79ddd48 392 */
leothedragon 0:8f0bb79ddd48 393 void set_registration_status(bool registered);
leothedragon 0:8f0bb79ddd48 394
leothedragon 0:8f0bb79ddd48 395 /**
leothedragon 0:8f0bb79ddd48 396 * @brief Handle incoming bootstrap PUT message.
leothedragon 0:8f0bb79ddd48 397 * @param coap_header, Received CoAP message
leothedragon 0:8f0bb79ddd48 398 * @param address, Server address
leothedragon 0:8f0bb79ddd48 399 */
leothedragon 0:8f0bb79ddd48 400 void handle_bootstrap_put_message(sn_coap_hdr_s *coap_header, sn_nsdl_addr_s *address);
leothedragon 0:8f0bb79ddd48 401
leothedragon 0:8f0bb79ddd48 402 /**
leothedragon 0:8f0bb79ddd48 403 * @brief Handle bootstrap finish acknowledgement.
leothedragon 0:8f0bb79ddd48 404 */
leothedragon 0:8f0bb79ddd48 405 void handle_bootstrap_finish_ack(uint16_t msg_id);
leothedragon 0:8f0bb79ddd48 406
leothedragon 0:8f0bb79ddd48 407 /**
leothedragon 0:8f0bb79ddd48 408 * @brief Returns total retransmission time
leothedragon 0:8f0bb79ddd48 409 * @resend_count Resend count
leothedragon 0:8f0bb79ddd48 410 * @return Total retransmission time
leothedragon 0:8f0bb79ddd48 411 */
leothedragon 0:8f0bb79ddd48 412 uint32_t total_retransmission_time(uint32_t resend_count);
leothedragon 0:8f0bb79ddd48 413
leothedragon 0:8f0bb79ddd48 414 /**
leothedragon 0:8f0bb79ddd48 415 * @brief Returns CoAP retransmission count
leothedragon 0:8f0bb79ddd48 416 * @return CoAP retransmission count
leothedragon 0:8f0bb79ddd48 417 */
leothedragon 0:8f0bb79ddd48 418 uint8_t get_resend_count();
leothedragon 0:8f0bb79ddd48 419
leothedragon 0:8f0bb79ddd48 420 /**
leothedragon 0:8f0bb79ddd48 421 * @brief Mark request to be resend again after network break
leothedragon 0:8f0bb79ddd48 422 * @param token, Message token
leothedragon 0:8f0bb79ddd48 423 * @param token_len, Message token length
leothedragon 0:8f0bb79ddd48 424 */
leothedragon 0:8f0bb79ddd48 425 void set_request_context_to_be_resend(uint8_t *token, uint8_t token_len);
leothedragon 0:8f0bb79ddd48 426
leothedragon 0:8f0bb79ddd48 427 /**
leothedragon 0:8f0bb79ddd48 428 * @brief Create a new time when to send CoAP ping.
leothedragon 0:8f0bb79ddd48 429 */
leothedragon 0:8f0bb79ddd48 430 void calculate_new_coap_ping_send_time();
leothedragon 0:8f0bb79ddd48 431
leothedragon 0:8f0bb79ddd48 432 protected: // from M2MTimerObserver
leothedragon 0:8f0bb79ddd48 433
leothedragon 0:8f0bb79ddd48 434 virtual void timer_expired(M2MTimerObserver::Type type);
leothedragon 0:8f0bb79ddd48 435
leothedragon 0:8f0bb79ddd48 436 protected: // from M2MObservationHandler
leothedragon 0:8f0bb79ddd48 437
leothedragon 0:8f0bb79ddd48 438 virtual bool observation_to_be_sent(M2MBase *object,
leothedragon 0:8f0bb79ddd48 439 uint16_t obs_number,
leothedragon 0:8f0bb79ddd48 440 const m2m::Vector<uint16_t> &changed_instance_ids,
leothedragon 0:8f0bb79ddd48 441 bool send_object = false);
leothedragon 0:8f0bb79ddd48 442
leothedragon 0:8f0bb79ddd48 443 virtual void resource_to_be_deleted(M2MBase* base);
leothedragon 0:8f0bb79ddd48 444
leothedragon 0:8f0bb79ddd48 445 virtual void value_updated(M2MBase *base);
leothedragon 0:8f0bb79ddd48 446
leothedragon 0:8f0bb79ddd48 447 virtual void remove_object(M2MBase *object);
leothedragon 0:8f0bb79ddd48 448 #ifndef DISABLE_DELAYED_RESPONSE
leothedragon 0:8f0bb79ddd48 449 virtual void send_delayed_response(M2MBase *base);
leothedragon 0:8f0bb79ddd48 450 #endif //DISABLE_DELAYED_RESPONSE
leothedragon 0:8f0bb79ddd48 451
leothedragon 0:8f0bb79ddd48 452 #ifdef ENABLE_ASYNC_REST_RESPONSE
leothedragon 0:8f0bb79ddd48 453 virtual void send_asynchronous_response(M2MBase *base,
leothedragon 0:8f0bb79ddd48 454 const uint8_t *payload,
leothedragon 0:8f0bb79ddd48 455 size_t payload_len,
leothedragon 0:8f0bb79ddd48 456 const uint8_t* token,
leothedragon 0:8f0bb79ddd48 457 const uint8_t token_len,
leothedragon 0:8f0bb79ddd48 458 coap_response_code_e code);
leothedragon 0:8f0bb79ddd48 459 #endif //ENABLE_ASYNC_REST_RESPONSE
leothedragon 0:8f0bb79ddd48 460
leothedragon 0:8f0bb79ddd48 461 private:
leothedragon 0:8f0bb79ddd48 462
leothedragon 0:8f0bb79ddd48 463 /**
leothedragon 0:8f0bb79ddd48 464 * Enum defining an LWM2M object type.
leothedragon 0:8f0bb79ddd48 465 */
leothedragon 0:8f0bb79ddd48 466 typedef enum {
leothedragon 0:8f0bb79ddd48 467 SECURITY = 0x00,
leothedragon 0:8f0bb79ddd48 468 SERVER = 0x01,
leothedragon 0:8f0bb79ddd48 469 DEVICE = 0x02
leothedragon 0:8f0bb79ddd48 470 }ObjectType;
leothedragon 0:8f0bb79ddd48 471
leothedragon 0:8f0bb79ddd48 472 /**
leothedragon 0:8f0bb79ddd48 473 * @brief Initializes all the nsdl library component to be usable.
leothedragon 0:8f0bb79ddd48 474 * @return true if initialization is successful else false.
leothedragon 0:8f0bb79ddd48 475 */
leothedragon 0:8f0bb79ddd48 476 bool initialize();
leothedragon 0:8f0bb79ddd48 477
leothedragon 0:8f0bb79ddd48 478 bool add_object_to_list(M2MBase *base);
leothedragon 0:8f0bb79ddd48 479
leothedragon 0:8f0bb79ddd48 480 bool create_nsdl_structure(M2MBase *base);
leothedragon 0:8f0bb79ddd48 481
leothedragon 0:8f0bb79ddd48 482 #ifdef MBED_CLOUD_CLIENT_EDGE_EXTENSION
leothedragon 0:8f0bb79ddd48 483 bool create_nsdl_endpoint_structure(M2MEndpoint *endpoint);
leothedragon 0:8f0bb79ddd48 484 #endif
leothedragon 0:8f0bb79ddd48 485
leothedragon 0:8f0bb79ddd48 486 bool create_nsdl_object_structure(M2MObject *object);
leothedragon 0:8f0bb79ddd48 487
leothedragon 0:8f0bb79ddd48 488 bool create_nsdl_object_instance_structure(M2MObjectInstance *object_instance);
leothedragon 0:8f0bb79ddd48 489
leothedragon 0:8f0bb79ddd48 490 bool create_nsdl_resource_structure(M2MResource *resource,
leothedragon 0:8f0bb79ddd48 491 bool multiple_instances = false);
leothedragon 0:8f0bb79ddd48 492
leothedragon 0:8f0bb79ddd48 493 bool create_nsdl_resource(M2MBase *base);
leothedragon 0:8f0bb79ddd48 494
leothedragon 0:8f0bb79ddd48 495 static String coap_to_string(const uint8_t *coap_data_ptr,
leothedragon 0:8f0bb79ddd48 496 int coap_data_ptr_length);
leothedragon 0:8f0bb79ddd48 497
leothedragon 0:8f0bb79ddd48 498 void execute_nsdl_process_loop();
leothedragon 0:8f0bb79ddd48 499
leothedragon 0:8f0bb79ddd48 500 uint64_t registration_time() const;
leothedragon 0:8f0bb79ddd48 501
leothedragon 0:8f0bb79ddd48 502 M2MBase* find_resource(const String &object) const;
leothedragon 0:8f0bb79ddd48 503
leothedragon 0:8f0bb79ddd48 504 #ifdef MBED_CLOUD_CLIENT_EDGE_EXTENSION
leothedragon 0:8f0bb79ddd48 505 M2MBase* find_resource(const M2MEndpoint *endpoint,
leothedragon 0:8f0bb79ddd48 506 const String &object_name) const;
leothedragon 0:8f0bb79ddd48 507 #endif
leothedragon 0:8f0bb79ddd48 508
leothedragon 0:8f0bb79ddd48 509 M2MBase* find_resource(const M2MObject *object,
leothedragon 0:8f0bb79ddd48 510 const String &object_instance) const;
leothedragon 0:8f0bb79ddd48 511
leothedragon 0:8f0bb79ddd48 512 M2MBase* find_resource(const M2MObjectInstance *object_instance,
leothedragon 0:8f0bb79ddd48 513 const String &resource_instance) const;
leothedragon 0:8f0bb79ddd48 514
leothedragon 0:8f0bb79ddd48 515 M2MBase* find_resource(const M2MResource *resource,
leothedragon 0:8f0bb79ddd48 516 const String &object_name,
leothedragon 0:8f0bb79ddd48 517 const String &resource_instance) const;
leothedragon 0:8f0bb79ddd48 518
leothedragon 0:8f0bb79ddd48 519 bool object_present(M2MBase *base) const;
leothedragon 0:8f0bb79ddd48 520
leothedragon 0:8f0bb79ddd48 521 int object_index(M2MBase *base) const;
leothedragon 0:8f0bb79ddd48 522
leothedragon 0:8f0bb79ddd48 523 static M2MInterface::Error interface_error(const sn_coap_hdr_s &coap_header);
leothedragon 0:8f0bb79ddd48 524
leothedragon 0:8f0bb79ddd48 525 void send_object_observation(M2MObject *object,
leothedragon 0:8f0bb79ddd48 526 uint16_t obs_number,
leothedragon 0:8f0bb79ddd48 527 const m2m::Vector<uint16_t> &changed_instance_ids,
leothedragon 0:8f0bb79ddd48 528 bool send_object);
leothedragon 0:8f0bb79ddd48 529
leothedragon 0:8f0bb79ddd48 530 void send_object_instance_observation(M2MObjectInstance *object_instance,
leothedragon 0:8f0bb79ddd48 531 uint16_t obs_number);
leothedragon 0:8f0bb79ddd48 532
leothedragon 0:8f0bb79ddd48 533 void send_resource_observation(M2MResource *resource, uint16_t obs_number);
leothedragon 0:8f0bb79ddd48 534
leothedragon 0:8f0bb79ddd48 535
leothedragon 0:8f0bb79ddd48 536
leothedragon 0:8f0bb79ddd48 537 /**
leothedragon 0:8f0bb79ddd48 538 * @brief Allocate (size + 1) amount of memory, copy size bytes into
leothedragon 0:8f0bb79ddd48 539 * it and add zero termination.
leothedragon 0:8f0bb79ddd48 540 * @param source Source string to copy, may not be NULL.
leothedragon 0:8f0bb79ddd48 541 * @param size The size of memory to be reserved.
leothedragon 0:8f0bb79ddd48 542 */
leothedragon 0:8f0bb79ddd48 543 static uint8_t* alloc_string_copy(const uint8_t* source, uint16_t size);
leothedragon 0:8f0bb79ddd48 544
leothedragon 0:8f0bb79ddd48 545 /**
leothedragon 0:8f0bb79ddd48 546 * @brief Utility method to convert given lifetime int to ascii
leothedragon 0:8f0bb79ddd48 547 * and allocate a buffer for it and set it to _endpoint->lifetime_ptr.
leothedragon 0:8f0bb79ddd48 548 * @param lifetime A new value for lifetime.
leothedragon 0:8f0bb79ddd48 549 */
leothedragon 0:8f0bb79ddd48 550 void set_endpoint_lifetime_buffer(int lifetime);
leothedragon 0:8f0bb79ddd48 551
leothedragon 0:8f0bb79ddd48 552 /**
leothedragon 0:8f0bb79ddd48 553 * @brief Handle bootstrap finished message.
leothedragon 0:8f0bb79ddd48 554 * @param coap_header, Received CoAP message
leothedragon 0:8f0bb79ddd48 555 * @param address, Server address
leothedragon 0:8f0bb79ddd48 556 */
leothedragon 0:8f0bb79ddd48 557 void handle_bootstrap_finished(sn_coap_hdr_s *coap_header,sn_nsdl_addr_s *address);
leothedragon 0:8f0bb79ddd48 558
leothedragon 0:8f0bb79ddd48 559 /**
leothedragon 0:8f0bb79ddd48 560 * @brief Handle bootstrap delete message.
leothedragon 0:8f0bb79ddd48 561 * @param coap_header, Received CoAP message
leothedragon 0:8f0bb79ddd48 562 * @param address, Server address
leothedragon 0:8f0bb79ddd48 563 */
leothedragon 0:8f0bb79ddd48 564 void handle_bootstrap_delete(sn_coap_hdr_s *coap_header,sn_nsdl_addr_s *address);
leothedragon 0:8f0bb79ddd48 565
leothedragon 0:8f0bb79ddd48 566 /**
leothedragon 0:8f0bb79ddd48 567 * @brief Parse bootstrap TLV message.
leothedragon 0:8f0bb79ddd48 568 * @param coap_header, Received CoAP message
leothedragon 0:8f0bb79ddd48 569 * @return True if parsing was succesful else false
leothedragon 0:8f0bb79ddd48 570 */
leothedragon 0:8f0bb79ddd48 571 bool parse_bootstrap_message(sn_coap_hdr_s *coap_header, M2MNsdlInterface::ObjectType lwm2m_object_type);
leothedragon 0:8f0bb79ddd48 572
leothedragon 0:8f0bb79ddd48 573 /**
leothedragon 0:8f0bb79ddd48 574 * @brief Parse bootstrap TLV message.
leothedragon 0:8f0bb79ddd48 575 * @param coap_header, Received CoAP message
leothedragon 0:8f0bb79ddd48 576 * @return True if parsing was succesful else false
leothedragon 0:8f0bb79ddd48 577 */
leothedragon 0:8f0bb79ddd48 578 bool validate_security_object();
leothedragon 0:8f0bb79ddd48 579
leothedragon 0:8f0bb79ddd48 580 /**
leothedragon 0:8f0bb79ddd48 581 * @brief Handle bootstrap errors.
leothedragon 0:8f0bb79ddd48 582 * @param reason, Reason for Bootstrap failure.
leothedragon 0:8f0bb79ddd48 583 * @param wait, True if need to wait that ACK has been sent.
leothedragon 0:8f0bb79ddd48 584 * False if reconnection can start immediately.
leothedragon 0:8f0bb79ddd48 585 */
leothedragon 0:8f0bb79ddd48 586 void handle_bootstrap_error(const char *reason, bool wait);
leothedragon 0:8f0bb79ddd48 587
leothedragon 0:8f0bb79ddd48 588 /**
leothedragon 0:8f0bb79ddd48 589 * @brief Handle different coap errors.
leothedragon 0:8f0bb79ddd48 590 * @param coap_header, CoAP structure.
leothedragon 0:8f0bb79ddd48 591 * @return Error reason.
leothedragon 0:8f0bb79ddd48 592 */
leothedragon 0:8f0bb79ddd48 593 static const char *coap_error(const sn_coap_hdr_s &coap_header);
leothedragon 0:8f0bb79ddd48 594
leothedragon 0:8f0bb79ddd48 595 /**
leothedragon 0:8f0bb79ddd48 596 * @brief Claim
leothedragon 0:8f0bb79ddd48 597 */
leothedragon 0:8f0bb79ddd48 598 void claim_mutex();
leothedragon 0:8f0bb79ddd48 599
leothedragon 0:8f0bb79ddd48 600 /**
leothedragon 0:8f0bb79ddd48 601 * @brief Release
leothedragon 0:8f0bb79ddd48 602 */
leothedragon 0:8f0bb79ddd48 603 void release_mutex();
leothedragon 0:8f0bb79ddd48 604
leothedragon 0:8f0bb79ddd48 605 /**
leothedragon 0:8f0bb79ddd48 606 * @brief Change operation mode of every resource.
leothedragon 0:8f0bb79ddd48 607 * @param object, Object to be updated.
leothedragon 0:8f0bb79ddd48 608 * @return operation, New operation mode.
leothedragon 0:8f0bb79ddd48 609 */
leothedragon 0:8f0bb79ddd48 610 void change_operation_mode(M2MObject *object, M2MBase::Operation operation);
leothedragon 0:8f0bb79ddd48 611
leothedragon 0:8f0bb79ddd48 612 /**
leothedragon 0:8f0bb79ddd48 613 * @brief Parse URI query parameters and pass those to nsdl-c.
leothedragon 0:8f0bb79ddd48 614 * @return True if parsing success otherwise False
leothedragon 0:8f0bb79ddd48 615 */
leothedragon 0:8f0bb79ddd48 616 bool parse_and_send_uri_query_parameters();
leothedragon 0:8f0bb79ddd48 617
leothedragon 0:8f0bb79ddd48 618 /**
leothedragon 0:8f0bb79ddd48 619 * @brief Callback function that triggers the registration update call.
leothedragon 0:8f0bb79ddd48 620 * @param argument, Arguments part of the POST request.
leothedragon 0:8f0bb79ddd48 621 */
leothedragon 0:8f0bb79ddd48 622 void update_trigger_callback(void *argument);
leothedragon 0:8f0bb79ddd48 623
leothedragon 0:8f0bb79ddd48 624 bool lifetime_value_changed() const;
leothedragon 0:8f0bb79ddd48 625
leothedragon 0:8f0bb79ddd48 626 void execute_notification_delivery_status_cb(M2MBase* object, int32_t msgid);
leothedragon 0:8f0bb79ddd48 627
leothedragon 0:8f0bb79ddd48 628 bool is_response_to_request(const sn_coap_hdr_s *coap_header,
leothedragon 0:8f0bb79ddd48 629 struct request_context_s &get_data);
leothedragon 0:8f0bb79ddd48 630
leothedragon 0:8f0bb79ddd48 631 void free_request_context_list(const sn_coap_hdr_s *coap_header, bool call_error_cb, request_error_t error_code = FAILED_TO_SEND_MSG);
leothedragon 0:8f0bb79ddd48 632
leothedragon 0:8f0bb79ddd48 633 void free_response_list();
leothedragon 0:8f0bb79ddd48 634
leothedragon 0:8f0bb79ddd48 635 void remove_item_from_response_list(const char* uri_path, const int32_t msg_id);
leothedragon 0:8f0bb79ddd48 636
leothedragon 0:8f0bb79ddd48 637 #if !defined(DISABLE_DELAYED_RESPONSE) || defined(ENABLE_ASYNC_REST_RESPONSE)
leothedragon 0:8f0bb79ddd48 638 void remove_items_from_response_list_for_uri(const char* uri_path);
leothedragon 0:8f0bb79ddd48 639 #endif
leothedragon 0:8f0bb79ddd48 640 /**
leothedragon 0:8f0bb79ddd48 641 * @brief Send next notification for object, return true if notification sent, false
leothedragon 0:8f0bb79ddd48 642 * if no notification to send or send already in progress.
leothedragon 0:8f0bb79ddd48 643 * @param object, M2MObject whose next notification should be sent
leothedragon 0:8f0bb79ddd48 644 * @param clear_token, Flag to indicate whether observation token should be cleared.
leothedragon 0:8f0bb79ddd48 645 * @return True if notification sent, false otherwise or if send already in progress
leothedragon 0:8f0bb79ddd48 646 */
leothedragon 0:8f0bb79ddd48 647 bool send_next_notification_for_object(M2MObject& object, bool clear_token);
leothedragon 0:8f0bb79ddd48 648
leothedragon 0:8f0bb79ddd48 649 static char* parse_uri_query_parameters(char* uri);
leothedragon 0:8f0bb79ddd48 650
leothedragon 0:8f0bb79ddd48 651 void send_coap_ping();
leothedragon 0:8f0bb79ddd48 652
leothedragon 0:8f0bb79ddd48 653 void send_empty_ack(const sn_coap_hdr_s *header, sn_nsdl_addr_s *address);
leothedragon 0:8f0bb79ddd48 654
leothedragon 0:8f0bb79ddd48 655 struct M2MNsdlInterface::nsdl_coap_data_s* create_coap_event_data(sn_coap_hdr_s *received_coap_header,
leothedragon 0:8f0bb79ddd48 656 sn_nsdl_addr_s *address,
leothedragon 0:8f0bb79ddd48 657 struct nsdl_s *nsdl_handle,
leothedragon 0:8f0bb79ddd48 658 uint8_t coap_msg_code = COAP_MSG_CODE_EMPTY);
leothedragon 0:8f0bb79ddd48 659
leothedragon 0:8f0bb79ddd48 660 void handle_register_response(const sn_coap_hdr_s *coap_header);
leothedragon 0:8f0bb79ddd48 661
leothedragon 0:8f0bb79ddd48 662 void handle_unregister_response(const sn_coap_hdr_s *coap_header);
leothedragon 0:8f0bb79ddd48 663
leothedragon 0:8f0bb79ddd48 664 void handle_register_update_response(const sn_coap_hdr_s *coap_header);
leothedragon 0:8f0bb79ddd48 665
leothedragon 0:8f0bb79ddd48 666 void handle_request_response(const sn_coap_hdr_s *coap_header, struct request_context_s *request_context);
leothedragon 0:8f0bb79ddd48 667
leothedragon 0:8f0bb79ddd48 668 void handle_bootstrap_response(const sn_coap_hdr_s *coap_header);
leothedragon 0:8f0bb79ddd48 669
leothedragon 0:8f0bb79ddd48 670 void handle_message_delivered(M2MBase *base, const M2MBase::MessageType type);
leothedragon 0:8f0bb79ddd48 671
leothedragon 0:8f0bb79ddd48 672 void handle_empty_ack(const sn_coap_hdr_s *coap_header, bool is_bootstrap_msg);
leothedragon 0:8f0bb79ddd48 673
leothedragon 0:8f0bb79ddd48 674 bool handle_post_response(sn_coap_hdr_s *coap_header,
leothedragon 0:8f0bb79ddd48 675 sn_nsdl_addr_s *address,
leothedragon 0:8f0bb79ddd48 676 sn_coap_hdr_s *&coap_response,
leothedragon 0:8f0bb79ddd48 677 M2MObjectInstance *&obj_instance,
leothedragon 0:8f0bb79ddd48 678 bool is_bootstrap_msg);
leothedragon 0:8f0bb79ddd48 679
leothedragon 0:8f0bb79ddd48 680 void set_retransmission_parameters();
leothedragon 0:8f0bb79ddd48 681
leothedragon 0:8f0bb79ddd48 682 void send_pending_request();
leothedragon 0:8f0bb79ddd48 683
leothedragon 0:8f0bb79ddd48 684 void store_to_response_list(const char *uri, int32_t msg_id, M2MBase::MessageType type);
leothedragon 0:8f0bb79ddd48 685
leothedragon 0:8f0bb79ddd48 686 struct coap_response_s* find_response(int32_t msg_id);
leothedragon 0:8f0bb79ddd48 687
leothedragon 0:8f0bb79ddd48 688 #if !defined(DISABLE_DELAYED_RESPONSE) || defined(ENABLE_ASYNC_REST_RESPONSE)
leothedragon 0:8f0bb79ddd48 689 struct coap_response_s* find_delayed_response(const char* uri_path,
leothedragon 0:8f0bb79ddd48 690 const M2MBase::MessageType type,
leothedragon 0:8f0bb79ddd48 691 int32_t message_id = UNDEFINED_MSG_ID);
leothedragon 0:8f0bb79ddd48 692
leothedragon 0:8f0bb79ddd48 693 bool handle_delayed_response_store(const char* uri_path,
leothedragon 0:8f0bb79ddd48 694 sn_coap_hdr_s* received_coap,
leothedragon 0:8f0bb79ddd48 695 sn_nsdl_addr_s *address,
leothedragon 0:8f0bb79ddd48 696 const M2MBase::MessageType message_type);
leothedragon 0:8f0bb79ddd48 697 #endif
leothedragon 0:8f0bb79ddd48 698
leothedragon 0:8f0bb79ddd48 699 void failed_to_send_request(request_context_s *request, const sn_coap_hdr_s *coap_header);
leothedragon 0:8f0bb79ddd48 700
leothedragon 0:8f0bb79ddd48 701 bool coap_ping_in_process() const;
leothedragon 0:8f0bb79ddd48 702
leothedragon 0:8f0bb79ddd48 703 void remove_ping_from_response_list();
leothedragon 0:8f0bb79ddd48 704
leothedragon 0:8f0bb79ddd48 705 #ifdef ENABLE_ASYNC_REST_RESPONSE
leothedragon 0:8f0bb79ddd48 706 static M2MBase::Operation operation_for_message_code(sn_coap_msg_code_e code);
leothedragon 0:8f0bb79ddd48 707 #endif // ENABLE_ASYNC_REST_RESPONSE
leothedragon 0:8f0bb79ddd48 708
leothedragon 0:8f0bb79ddd48 709 private:
leothedragon 0:8f0bb79ddd48 710 M2MNsdlObserver &_observer;
leothedragon 0:8f0bb79ddd48 711 M2MBaseList _base_list;
leothedragon 0:8f0bb79ddd48 712 sn_nsdl_ep_parameters_s *_endpoint;
leothedragon 0:8f0bb79ddd48 713 nsdl_s *_nsdl_handle;
leothedragon 0:8f0bb79ddd48 714 M2MSecurity *_security; // Not owned
leothedragon 0:8f0bb79ddd48 715 M2MServer *_server;
leothedragon 0:8f0bb79ddd48 716 M2MTimer _nsdl_execution_timer;
leothedragon 0:8f0bb79ddd48 717 M2MTimer _registration_timer;
leothedragon 0:8f0bb79ddd48 718 M2MConnectionHandler &_connection_handler;
leothedragon 0:8f0bb79ddd48 719 String _endpoint_name;
leothedragon 0:8f0bb79ddd48 720 String _internal_endpoint_name;
leothedragon 0:8f0bb79ddd48 721 uint32_t _counter_for_nsdl;
leothedragon 0:8f0bb79ddd48 722 uint32_t _next_coap_ping_send_time;
leothedragon 0:8f0bb79ddd48 723 char *_server_address; // BS or M2M address
leothedragon 0:8f0bb79ddd48 724 request_context_list_t _request_context_list;
leothedragon 0:8f0bb79ddd48 725 response_list_t _response_list;
leothedragon 0:8f0bb79ddd48 726 char *_custom_uri_query_params;
leothedragon 0:8f0bb79ddd48 727 M2MNotificationHandler *_notification_handler;
leothedragon 0:8f0bb79ddd48 728 arm_event_storage_t _event;
leothedragon 0:8f0bb79ddd48 729 uint16_t _auto_obs_token;
leothedragon 0:8f0bb79ddd48 730 uint16_t _bootstrap_id;
leothedragon 0:8f0bb79ddd48 731 static int8_t _tasklet_id;
leothedragon 0:8f0bb79ddd48 732 uint8_t _binding_mode;
leothedragon 0:8f0bb79ddd48 733 bool _identity_accepted;
leothedragon 0:8f0bb79ddd48 734 bool _nsdl_execution_timer_running;
leothedragon 0:8f0bb79ddd48 735 bool _notification_send_ongoing;
leothedragon 0:8f0bb79ddd48 736 bool _registered;
leothedragon 0:8f0bb79ddd48 737 bool _bootstrap_finish_ack_received;
leothedragon 0:8f0bb79ddd48 738 M2MTimer _download_retry_timer;
leothedragon 0:8f0bb79ddd48 739 uint64_t _download_retry_time;
leothedragon 0:8f0bb79ddd48 740
leothedragon 0:8f0bb79ddd48 741 friend class Test_M2MNsdlInterface;
leothedragon 0:8f0bb79ddd48 742
leothedragon 0:8f0bb79ddd48 743 };
leothedragon 0:8f0bb79ddd48 744
leothedragon 0:8f0bb79ddd48 745 #endif // M2MNSDLINTERFACE_H
leothedragon 0:8f0bb79ddd48 746