Mistake on this page? Email us
m2minterface.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2020 ARM Limited. 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 
36 typedef Vector<M2MObject*> M2MObjectList;
37 typedef Vector<M2MBase*> M2MBaseList;
38 typedef FP callback_handler;
39 
40 typedef enum request_error_e {
41  FAILED_TO_SEND_MSG = 0, // Message sending has failed
42  FAILED_TO_ALLOCATE_MEMORY = 1, // Can't allocate memory for the request
43  ERROR_NOT_REGISTERED = 2 // Not registered, request will NOT to be stored for resending purposes
44 } request_error_t;
45 
46 typedef request_error_e get_data_req_error_e;
47 typedef request_error_t get_data_req_error_t;
48 
60 typedef void (*request_data_cb)(const uint8_t *buffer,
61  size_t buffer_size,
62  size_t total_size,
63  bool last_block,
64  void *context);
65 typedef request_data_cb get_data_cb; // For backward compatibility
66 
72 typedef void (*request_error_cb)(request_error_t error_code, void *context);
73 typedef request_error_cb get_data_error_cb; // For backward compatibility
74 
75 
87 class M2MInterface {
88 
89 public:
90 
95  typedef enum {
96  ErrorNone = 0,
97  AlreadyExists,
98  BootstrapFailed,
99  InvalidParameters,
100  NotRegistered,
101  Timeout,
102  NetworkError,
103  ResponseParseFailed,
104  UnknownError,
105  MemoryFail,
106  NotAllowed,
107  SecureConnectionFailed,
108  DnsResolvingFailed,
109  UnregistrationFailed,
110  ESTEnrollmentFailed,
111  FailedToStoreCredentials,
112  FailedToReadCredentials
113  }Error;
114 
119  typedef enum {
120  NOT_SET = 0,
121  UDP = 0x01,
122  UDP_QUEUE = 0x03,
123  SMS = 0x04,
124  SMS_QUEUE =0x06,
125  UDP_SMS_QUEUE = 0x07,
126  TCP = 0x09, //not real value, spec does not have one!
127  //this has nsdl binding mode bit UDP set
128  TCP_QUEUE = 0x0b //not real value, spec does not have one!
129  //this has nsdl binding mode bits, UDP and UDP_QUEUE set
130  }BindingMode;
131 
136  typedef enum {
137  Uninitialized = 0,
138  LwIP_IPv4,
139  LwIP_IPv6,
140  Reserved,
141  Nanostack_IPv6,
142  ATWINC_IPv4,
143  Unknown
144  }NetworkStack;
145 
146 public:
147 
148  virtual ~M2MInterface(){}
149 
150 #ifndef MBED_CLIENT_DISABLE_BOOTSTRAP_FEATURE
151 
158  virtual void bootstrap(M2MSecurity *security_object) = 0;
159 
166  virtual void cancel_bootstrap() = 0;
167 
171  virtual void finish_bootstrap() = 0;
172 #endif //MBED_CLIENT_DISABLE_BOOTSTRAP_FEATURE
173 
185  virtual void register_object(M2MSecurity *security_object, const M2MBaseList &list, bool full_registration = false) = 0;
186 
197  virtual void register_object(M2MSecurity *security_object, const M2MObjectList &object_list) = 0;
198 
204  virtual bool remove_object(M2MBase *base) = 0;
205 
215  virtual void update_registration(M2MSecurity *security_object, const uint32_t lifetime = 0) = 0;
216 
228  virtual void update_registration(M2MSecurity *security_object, const M2MBaseList &list,
229  const uint32_t lifetime = 0) = 0;
230 
242  virtual void update_registration(M2MSecurity *security_object, const M2MObjectList &object_list,
243  const uint32_t lifetime = 0) = 0;
244 
251  virtual void unregister_object(M2MSecurity* security_object = NULL) = 0;
252 
259  virtual void set_queue_sleep_handler(callback_handler handler) = 0;
260 
268  virtual void set_random_number_callback(random_number_cb callback) = 0;
269 
279  virtual void set_entropy_callback(entropy_cb callback) = 0;
280 
288  virtual void set_platform_network_handler(void *handler = NULL) = 0;
289 
300  virtual void set_platform_network_handler(void *handler = NULL, bool credentials_available = 0) = 0;
301 
306  virtual void update_endpoint(const String &name) = 0;
307 
312  virtual void update_domain(const String &domain) = 0;
313 
314 
319  virtual const String internal_endpoint_name() const = 0;
320 
325  virtual const char *error_description() const = 0;
326 
337  virtual void get_data_request(DownloadType type,
338  const char *uri,
339  const size_t offset,
340  const bool async,
341  get_data_cb,
342  get_data_error_cb,
343  void *context) = 0;
344 
355  virtual void post_data_request(const char *uri,
356  const bool async,
357  const uint16_t payload_len,
358  uint8_t *payload_ptr,
359  get_data_cb data_cb,
360  get_data_error_cb error_cb,
361  void *context) = 0;
362 
369  virtual bool set_uri_query_parameters(const char *uri_query_params) = 0;
370 
379  virtual void pause() = 0;
380 
381  virtual nsdl_s* get_nsdl_handle() const = 0;
382 
383  virtual uint16_t stagger_wait_time(bool boostrap) const = 0;
384 };
385 
386 #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
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 const char * error_description() const =0
Return error description for the latest error code.
Definition: functionpointer.h:27
BindingMode
An enum defining different kinds of binding modes handled for client operations.
Definition: m2minterface.h:119
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:136
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...
Header for function pointer classes.
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:87
virtual void unregister_object(M2MSecurity *security_object=NULL)=0
Unregisters the registered object from the LWM2M server.
Definition: m2mconfig.h:112
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:60
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:72
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:95
virtual bool remove_object(M2MBase *base)=0
Removes an object from M2MInterface. Does not call delete on the object though.