Mistake on this page? Email us
m2minterface.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2021 Pelion. All rights reserved.
3  * SPDX-License-Identifier: Apache-2.0
4  * Licensed under the Apache License, Version 2.0 (the License); you may
5  * not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #ifndef M2M_INTERFACE_H
17 #define M2M_INTERFACE_H
18 
19 #include "mbed-client/m2mvector.h"
20 #include "mbed-client/m2mconfig.h"
22 
23 #include "sn_coap_protocol.h"
24 #include "nsdl-c/sn_nsdl_lib.h"
25 
26 #include <stdint.h>
27 
30 //FORWARD DECLARATION
31 class M2MSecurity;
32 class M2MObject;
33 class M2MBase;
35 class M2MServer;
36 
37 typedef Vector<M2MObject *> M2MObjectList;
38 typedef Vector<M2MBase *> M2MBaseList;
39 typedef FP callback_handler;
40 
41 typedef enum request_error_e {
42  FAILED_TO_SEND_MSG = 0, // Message sending has failed
43  FAILED_TO_ALLOCATE_MEMORY = 1, // Can't allocate memory for the request
44  ERROR_NOT_REGISTERED = 2 // Not registered, request will NOT to be stored for resending purposes
45 } request_error_t;
46 
47 typedef request_error_e get_data_req_error_e;
48 typedef request_error_t get_data_req_error_t;
49 
61 typedef void (*request_data_cb)(const uint8_t *buffer,
62  size_t buffer_size,
63  size_t total_size,
64  bool last_block,
65  void *context);
66 typedef request_data_cb get_data_cb; // For backward compatibility
67 
73 typedef void (*request_error_cb)(request_error_t error_code, void *context);
74 typedef request_error_cb get_data_error_cb; // For backward compatibility
75 
76 
88 class M2MInterface {
89 
90 public:
91 
96  typedef enum {
97  ErrorNone = 0,
98  AlreadyExists,
99  BootstrapFailed,
100  InvalidParameters,
101  InvalidCertificates,
102  NotRegistered,
103  Timeout,
104  NetworkError,
105  ResponseParseFailed,
106  UnknownError,
107  MemoryFail,
108  NotAllowed,
109  SecureConnectionFailed,
110  DnsResolvingFailed,
111  UnregistrationFailed,
112  ESTEnrollmentFailed,
113  FailedToStoreCredentials,
114  FailedToReadCredentials
115  } Error;
116 
121  typedef enum {
122  NOT_SET = 0,
123  UDP = 0x01,
124  UDP_QUEUE = 0x03,
125  SMS = 0x04,
126  SMS_QUEUE = 0x06,
127  UDP_SMS_QUEUE = 0x07,
128  TCP = 0x09, //not real value, spec does not have one!
129  //this has nsdl binding mode bit UDP set
130  TCP_QUEUE = 0x0b //not real value, spec does not have one!
131  //this has nsdl binding mode bits, UDP and UDP_QUEUE set
132  } BindingMode;
133 
138  typedef enum {
139  Uninitialized = 0,
140  LwIP_IPv4,
141  LwIP_IPv6,
142  Reserved,
143  Nanostack_IPv6,
144  ATWINC_IPv4,
145  Unknown
146  } NetworkStack;
147 
148 public:
149 
150  virtual ~M2MInterface() {}
151 
152 #ifndef MBED_CLIENT_DISABLE_BOOTSTRAP_FEATURE
153 
160  virtual void bootstrap(M2MSecurity *security_object) = 0;
161 
168  virtual void cancel_bootstrap() = 0;
169 
173  virtual void finish_bootstrap() = 0;
174 #endif //MBED_CLIENT_DISABLE_BOOTSTRAP_FEATURE
175 
187  virtual void register_object(M2MSecurity *security_object, const M2MBaseList &list, bool full_registration = false) = 0;
188 
199  virtual void register_object(M2MSecurity *security_object, const M2MObjectList &object_list) = 0;
200 
206  virtual bool remove_object(M2MBase *base) = 0;
207 
217  virtual void update_registration(M2MSecurity *security_object, const uint32_t lifetime = 0) = 0;
218 
230  virtual void update_registration(M2MSecurity *security_object, const M2MBaseList &list,
231  const uint32_t lifetime = 0) = 0;
232 
244  virtual void update_registration(M2MSecurity *security_object, const M2MObjectList &object_list,
245  const uint32_t lifetime = 0) = 0;
246 
253  virtual void unregister_object(M2MSecurity *security_object = NULL) = 0;
254 
261  virtual void set_queue_sleep_handler(callback_handler handler) = 0;
262 
270  virtual void set_random_number_callback(random_number_cb callback) = 0;
271 
281  virtual void set_entropy_callback(entropy_cb callback) = 0;
282 
290  virtual void set_platform_network_handler(void *handler = NULL) = 0;
291 
302  virtual void set_platform_network_handler(void *handler = NULL, bool credentials_available = 0) = 0;
303 
308  virtual void update_endpoint(const String &name) = 0;
309 
314  virtual void update_domain(const String &domain) = 0;
315 
316 
321  virtual const String internal_endpoint_name() const = 0;
322 
327  virtual const char *error_description() const = 0;
328 
339  virtual void get_data_request(DownloadType type,
340  const char *uri,
341  const size_t offset,
342  const bool async,
343  get_data_cb,
344  get_data_error_cb,
345  void *context) = 0;
346 
357  virtual void post_data_request(const char *uri,
358  const bool async,
359  const uint16_t payload_len,
360  uint8_t *payload_ptr,
361  get_data_cb data_cb,
362  get_data_error_cb error_cb,
363  void *context) = 0;
364 
371  virtual bool set_uri_query_parameters(const char *uri_query_params) = 0;
372 
381  virtual void pause() = 0;
382 
389  virtual void alert() = 0;
390 
395  virtual nsdl_s *get_nsdl_handle() const = 0;
396 
401  virtual M2MServer *get_m2mserver() const = 0;
402 
403  virtual uint16_t stagger_wait_time(bool boostrap) const = 0;
404 
410  virtual void set_cid_value(const uint8_t *data_ptr, const size_t data_len) = 0;
411 };
412 
413 #endif // M2M_INTERFACE_H
virtual void post_data_request(const char *uri, const bool async, const uint16_t payload_len, uint8_t *payload_ptr, get_data_cb data_cb, get_data_error_cb error_cb, void *context)=0
Sends the CoAP POST request to the server. Uri path to the data. In async mode application must cal...
Definition: m2mobject.h:35
Definition: m2mserver.h:31
virtual void set_entropy_callback(entropy_cb callback)=0
Sets the function callback that is called by mbed Client to provide an entropy source from an applica...
virtual void update_registration(M2MSecurity *security_object, const uint32_t lifetime=0)=0
Updates or refreshes the client&#39;s registration on the LWM2M server.
virtual bool set_uri_query_parameters(const char *uri_query_params)=0
Set custom uri query paramaters used in LWM2M registration. Uri query params. Parameters must be in ...
virtual void finish_bootstrap()=0
Finishes bootstrap in cases where client will be the one to finish it.
Definition: m2mbase.h:54
virtual void register_object(M2MSecurity *security_object, const M2MBaseList &list, bool full_registration=false)=0
Initiates the registration of a provided security object to the corresponding LWM2M server...
Definition: m2minterfaceobserver.h:32
virtual void set_queue_sleep_handler(callback_handler handler)=0
Sets the function that is called for indicating that the client is going to sleep when the binding mo...
virtual M2MServer * get_m2mserver() const =0
Returns M2MServer handle.
virtual const char * error_description() const =0
Return error description for the latest error code.
Definition: functionpointer.h:27
virtual nsdl_s * get_nsdl_handle() const =0
Get ndsl handle.
BindingMode
An enum defining different kinds of binding modes handled for client operations.
Definition: m2minterface.h:121
Definition: m2msecurity.h:31
virtual void get_data_request(DownloadType type, const char *uri, const size_t offset, const bool async, get_data_cb, get_data_error_cb, void *context)=0
Sends the CoAP GET request to the server. Download type. Uri path to the data. Data offset...
virtual void update_domain(const String &domain)=0
Updates the domain name.
NetworkStack
An enum defining different kinds of network stacks that can be used by mbed Client.
Definition: m2minterface.h:138
virtual void pause()=0
Pauses client&#39;s timed functionality and closes network connection to the Cloud. After successful call...
virtual void update_endpoint(const String &name)=0
Updates the endpoint name.
virtual void set_random_number_callback(random_number_cb callback)=0
Sets the function callback that is called by mbed Client to fetch a random number from an application...
virtual void set_cid_value(const uint8_t *data_ptr, const size_t data_len)=0
Internal test function. Set CID for current tls session.
Header for function pointer classes.
virtual void alert()=0
Sets client into an alert mode.
header for m2m::Vector
virtual const String internal_endpoint_name() const =0
Return internal endpoint name.
virtual void set_platform_network_handler(void *handler=NULL)=0
Sets the network interface handler that is used by mbed Client to connect to a network over IP...
Definition: m2minterface.h:88
virtual void unregister_object(M2MSecurity *security_object=NULL)=0
Unregisters the registered object from the LWM2M server.
Definition: m2mconfig.h:113
File defining all system build time configuration used by mbed-client.
void(* request_data_cb)(const uint8_t *buffer, size_t buffer_size, size_t total_size, bool last_block, void *context)
A callback function to receive data from GET request. Transfer is completed once total size equals to...
Definition: m2minterface.h:61
virtual void bootstrap(M2MSecurity *security_object)=0
Initiates bootstrapping of the client with the provided Bootstrap Server information. NOTE: This API is not supported for developers!!
void(* request_error_cb)(request_error_t error_code, void *context)
A callback function to receive errors from GET transfer.
Definition: m2minterface.h:73
virtual void cancel_bootstrap()=0
Cancels an ongoing bootstrapping operation of the client. If the client has already successfully boot...
Error
An enum defining different kinds of errors that can occur during various client operations.
Definition: m2minterface.h:96
virtual bool remove_object(M2MBase *base)=0
Removes an object from M2MInterface. Does not call delete on the object though.