Mistake on this page? Email us
m2minterface.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 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 <stdint.h>
20 #include "mbed-client/m2mvector.h"
21 #include "mbed-client/m2mconfig.h"
23 
24 #include "sn_coap_protocol.h"
25 #include "nsdl-c/sn_nsdl_lib.h"
26 
27 
28 //FORWARD DECLARATION
29 class M2MSecurity;
30 class M2MObject;
31 class M2MBase;
33 
36 typedef FP callback_handler;
37 
38 typedef enum request_error_e {
39  FAILED_TO_SEND_MSG = 0, // Message sending has failed
40  FAILED_TO_ALLOCATE_MEMORY = 1, // Can't allocate memory for the request
41  ERROR_NOT_REGISTERED = 2 // Not registered, request will NOT to be stored for resending purposes
42 } request_error_t;
43 
44 typedef request_error_e get_data_req_error_e;
45 typedef request_error_t get_data_req_error_t;
46 
58 typedef void (*request_data_cb)(const uint8_t *buffer,
59  size_t buffer_size,
60  size_t total_size,
61  bool last_block,
62  void *context);
63 typedef request_data_cb get_data_cb; // For backward compatibility
64 
70 typedef void (*request_error_cb)(request_error_t error_code, void *context);
71 typedef request_error_cb get_data_error_cb; // For backward compatibility
72 
73 
82 class M2MInterface {
83 
84 public:
85 
90  typedef enum {
91  ErrorNone = 0,
92  AlreadyExists,
93  BootstrapFailed,
94  InvalidParameters,
95  NotRegistered,
96  Timeout,
97  NetworkError,
98  ResponseParseFailed,
99  UnknownError,
100  MemoryFail,
101  NotAllowed,
102  SecureConnectionFailed,
103  DnsResolvingFailed,
104  UnregistrationFailed,
105  ESTEnrollmentFailed,
106  FailedToStoreCredentials,
107  FailedToReadCredentials
108  }Error;
109 
114  typedef enum {
115  NOT_SET = 0,
116  UDP = 0x01,
117  UDP_QUEUE = 0x03,
118  SMS = 0x04,
119  SMS_QUEUE =0x06,
120  UDP_SMS_QUEUE = 0x07,
121  TCP = 0x09, //not real value, spec does not have one!
122  //this has nsdl binding mode bit UDP set
123  TCP_QUEUE = 0x0b //not real value, spec does not have one!
124  //this has nsdl binding mode bits, UDP and UDP_QUEUE set
125  }BindingMode;
126 
131  typedef enum {
132  Uninitialized = 0,
133  LwIP_IPv4,
134  LwIP_IPv6,
135  Reserved,
136  Nanostack_IPv6,
137  ATWINC_IPv4,
138  Unknown
139  }NetworkStack;
140 
141 public:
142 
143  virtual ~M2MInterface(){}
144 
145 #ifndef MBED_CLIENT_DISABLE_BOOTSTRAP_FEATURE
146 
153  virtual void bootstrap(M2MSecurity *security_object) = 0;
154 
161  virtual void cancel_bootstrap() = 0;
162 
166  virtual void finish_bootstrap() = 0;
167 #endif //MBED_CLIENT_DISABLE_BOOTSTRAP_FEATURE
168 
179  virtual void register_object(M2MSecurity *security_object, const M2MBaseList &list) = 0;
180 
191  virtual void register_object(M2MSecurity *security_object, const M2MObjectList &object_list) = 0;
192 
193 
199  virtual bool remove_object(M2MBase *base) = 0;
200 
210  virtual void update_registration(M2MSecurity *security_object, const uint32_t lifetime = 0) = 0;
211 
223  virtual void update_registration(M2MSecurity *security_object, const M2MBaseList &list,
224  const uint32_t lifetime = 0) = 0;
225 
237  virtual void update_registration(M2MSecurity *security_object, const M2MObjectList &object_list,
238  const uint32_t lifetime = 0) = 0;
239 
246  virtual void unregister_object(M2MSecurity* security_object = NULL) = 0;
247 
254  virtual void set_queue_sleep_handler(callback_handler handler) = 0;
255 
263  virtual void set_random_number_callback(random_number_cb callback) = 0;
264 
274  virtual void set_entropy_callback(entropy_cb callback) = 0;
275 
283  virtual void set_platform_network_handler(void *handler = NULL) = 0;
284 
289  virtual void update_endpoint(const String &name) = 0;
290 
295  virtual void update_domain(const String &domain) = 0;
296 
297 
302  virtual const String internal_endpoint_name() const = 0;
303 
308  virtual const char *error_description() const = 0;
309 
320  virtual void get_data_request(DownloadType type,
321  const char *uri,
322  const size_t offset,
323  const bool async,
324  get_data_cb,
325  get_data_error_cb,
326  void *context) = 0;
327 
338  virtual void post_data_request(const char *uri,
339  const bool async,
340  const uint16_t payload_len,
341  uint8_t *payload_ptr,
342  get_data_cb data_cb,
343  get_data_error_cb error_cb,
344  void *context) = 0;
345 
352  virtual bool set_uri_query_parameters(const char *uri_query_params) = 0;
353 
362  virtual void pause() = 0;
363 
373  virtual void resume(void *iface, const M2MBaseList &object_list) = 0;
374 };
375 
376 #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...
The base class for Client Objects.
Definition: m2mobject.h:39
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.
The base class based on which all LwM2M object models can be created.
Definition: m2mbase.h:63
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 void resume(void *iface, const M2MBaseList &object_list)=0
Resumes client&#39;s timed functionality and network connection to the Cloud. Updates registration...
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:114
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...
Definition: m2mstring.h:33
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:131
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...
A class for storing and calling a pointer to a static or member void function.
virtual void register_object(M2MSecurity *security_object, const M2MBaseList &list)=0
Initiates the registration of a provided security object to the corresponding LWM2M server...
A simple C++ Vector class, used as replacement for std::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:82
virtual void unregister_object(M2MSecurity *security_object=NULL)=0
Unregisters the registered object from the LWM2M server.
Definition: m2mconfig.h:116
File defining all system build time configuration used by mbed-client.
Definition: m2mvector.h:30
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:58
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:70
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:90
virtual bool remove_object(M2MBase *base)=0
Removes an object from M2MInterface. Does not call delete on the object though.