Soletta™ Framework
Framework for making IoT devices

Full online documentation | C API Index
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
sol-lwm2m.h
Go to the documentation of this file.
1 /*
2  * This file is part of the Soletta (TM) Project
3  *
4  * Copyright (C) 2015 Intel Corporation. All rights reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 #pragma once
19 
20 #include <stdbool.h>
21 #include <stdint.h>
22 #include <stdarg.h>
23 #include <string.h>
24 
25 #include "sol-coap.h"
26 #include "sol-network.h"
27 #include "sol-str-slice.h"
28 #include "sol-vector.h"
29 #include "sol-buffer.h"
30 #include "sol-types.h"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
69 #define SOL_LWM2M_DEFAULT_SERVER_PORT_COAP (5683)
70 
74 #define SOL_LWM2M_DEFAULT_SERVER_PORT_DTLS (5684)
75 
83 
141 };
142 
176 };
177 
200 };
201 
223 };
224 
262 };
263 
280 };
281 
291 typedef struct sol_lwm2m_security_psk {
293  struct sol_blob *id;
295  struct sol_blob *key;
297 
307 typedef struct sol_lwm2m_security_rpk {
319 
336 typedef struct sol_lwm2m_tlv {
337 #ifndef SOL_NO_API_VERSION
338 #define SOL_LWM2M_TLV_API_VERSION (1)
339 
340  uint16_t api_version;
341 #endif
342 
346  uint16_t id;
349 } sol_lwm2m_tlv;
350 
355 typedef struct sol_lwm2m_resource {
356 #ifndef SOL_NO_API_VERSION
357 #define SOL_LWM2M_RESOURCE_API_VERSION (1)
358 
359  uint16_t api_version;
360 #endif
361 
366  uint16_t id;
368  uint16_t data_len;
371  uint16_t id;
372  union {
374  struct sol_blob *blob;
376  int64_t integer;
378  double fp;
380  bool b;
381  } content;
382  } *data;
384 
419 };
420 
436 #define SOL_LWM2M_RESOURCE_INIT(ret_value_, resource_, id_, type_, resource_len_, data_type_, ...) \
437  do { \
438  SOL_SET_API_VERSION((resource_)->api_version = SOL_LWM2M_RESOURCE_API_VERSION; ) \
439  (ret_value_) = sol_lwm2m_resource_init((resource_), (id_), (type_), (resource_len_), (data_type_), __VA_ARGS__); \
440  } while (0)
441 
453 #define SOL_LWM2M_RESOURCE_SINGLE_INIT(ret_value_, resource_, id_, data_type_, value_) \
454  do { \
455  SOL_SET_API_VERSION((resource_)->api_version = SOL_LWM2M_RESOURCE_API_VERSION; ) \
456  (ret_value_) = sol_lwm2m_resource_init((resource_), (id_), SOL_LWM2M_RESOURCE_TYPE_SINGLE, 1, (data_type_), value_); \
457  } while (0)
458 
483 #define SOL_LWM2M_RESOURCE_SINGLE_INT_INIT(ret_value_, resource_, id_, value_) \
484  do { \
485  SOL_SET_API_VERSION((resource_)->api_version = SOL_LWM2M_RESOURCE_API_VERSION; ) \
486  (ret_value_) = sol_lwm2m_resource_init((resource_), (id_), SOL_LWM2M_RESOURCE_TYPE_SINGLE, 1, SOL_LWM2M_RESOURCE_DATA_TYPE_INT, SOL_TYPE_CHECK(int64_t, (value_))); \
487  } while (0)
488 
495 typedef struct sol_lwm2m_payload {
507  } payload ;
509 
516 void sol_lwm2m_resource_clear(struct sol_lwm2m_resource *resource);
517 
550 int sol_lwm2m_resource_init(struct sol_lwm2m_resource *resource,
551  uint16_t id, enum sol_lwm2m_resource_type type, uint16_t resource_len,
552  enum sol_lwm2m_resource_data_type data_type, ...);
553 
575  uint16_t id, enum sol_lwm2m_resource_data_type data_type,
576  struct sol_vector *res_instances);
577 
586 int sol_lwm2m_parse_tlv(const struct sol_str_slice content, struct sol_vector *tlv_values);
587 
593 void sol_lwm2m_tlv_list_clear(struct sol_vector *tlvs);
594 
600 void sol_lwm2m_tlv_clear(struct sol_lwm2m_tlv *tlv);
601 
609 int sol_lwm2m_tlv_get_float(struct sol_lwm2m_tlv *tlv, double *value);
610 
618 int sol_lwm2m_tlv_get_bool(struct sol_lwm2m_tlv *tlv, bool *value);
619 
627 int sol_lwm2m_tlv_get_int(struct sol_lwm2m_tlv *tlv, int64_t *value);
628 
636 int sol_lwm2m_tlv_get_bytes(struct sol_lwm2m_tlv *tlv, struct sol_buffer *buf);
637 
646 int sol_lwm2m_tlv_get_obj_link(struct sol_lwm2m_tlv *tlv, uint16_t *object_id, uint16_t *instance_id);
647 
655 int sol_lwm2m_client_object_get_id(const struct sol_lwm2m_client_object *object, uint16_t *id);
656 
667 
671 #ifdef __cplusplus
672 }
673 #endif
Indicates that the client is using UDP and SMS binding.
Definition: sol-lwm2m.h:128
const struct sol_ptr_vector * sol_lwm2m_client_object_get_instances(const struct sol_lwm2m_client_object *object)
Gets the instances of a given object.
struct sol_lwm2m_tlv sol_lwm2m_tlv
Struct that represents TLV data.
struct sol_blob * key
The PSK Key, composed of an Opaque 16-bytes (128-bit) AES Key.
Definition: sol-lwm2m.h:295
sol_lwm2m_resource_type
Enum data represents if an sol_lwm2m_resource is an array or not.
Definition: sol-lwm2m.h:267
The resource data array.
Definition: sol-lwm2m.h:370
Indicates that the client is reacheable all the time and all the communication must be done using SMS...
Definition: sol-lwm2m.h:115
The resource type is unknown.
Definition: sol-lwm2m.h:279
No bit is set (No access rights for any operation)
Definition: sol-lwm2m.h:394
sol_lwm2m_resource_data_type
Enum that represents a LWM2M resource data type.
Definition: sol-lwm2m.h:229
Indicates that the client is using Queued SMS binding and all the communication must be done using SM...
Definition: sol-lwm2m.h:120
void sol_lwm2m_resource_clear(struct sol_lwm2m_resource *resource)
Clears a sol_lwm2m_resource.
struct sol_lwm2m_security_psk sol_lwm2m_security_psk
Struct that represents a Pre-Shared Key (PSK).
struct sol_str_slice slice_content
The payload content in bytes.
Definition: sol-lwm2m.h:506
struct sol_blob * id
The PSK Identity, composed of a 16-bytes UTF-8 String.
Definition: sol-lwm2m.h:293
These routines are used for Soletta types' manipulation.
sol_lwm2m_tlv_type
Enum that represents the TLV type.
Definition: sol-lwm2m.h:206
struct sol_lwm2m_payload sol_lwm2m_payload
A payload received from the network used to create a LWM2M object instance.
bool b
The resource is a bool value.
Definition: sol-lwm2m.h:380
int sol_lwm2m_tlv_get_bool(struct sol_lwm2m_tlv *tlv, bool *value)
Converts an TLV value to boolean value.
Struct that represents a Raw Public Key (RPK) pair.
Definition: sol-lwm2m.h:307
1st lsb: R (Read, Observe, Discover, Write Attributes)
Definition: sol-lwm2m.h:398
int sol_lwm2m_resource_init(struct sol_lwm2m_resource *resource, uint16_t id, enum sol_lwm2m_resource_type type, uint16_t resource_len, enum sol_lwm2m_resource_data_type data_type,...)
Initializes a LWM2M resource.
No security ("NoSec") mode (CoAP without DTLS)
Definition: sol-lwm2m.h:175
sol_lwm2m_binding_mode
LWM2M Client binding mode.
Definition: sol-lwm2m.h:100
uint16_t api_version
API version.
Definition: sol-lwm2m.h:359
struct sol_blob * blob
The resource is opaque or an string.
Definition: sol-lwm2m.h:374
The resource value is a boolean.
Definition: sol-lwm2m.h:245
Struct that represents TLV data.
Definition: sol-lwm2m.h:336
static struct sol_buffer value
Definition: server.c:42
All 5 lsbs: Full Access Rights.
Definition: sol-lwm2m.h:418
The TLV represents a resource instance.
Definition: sol-lwm2m.h:214
The content type of the message is in JSON.
Definition: sol-lwm2m.h:199
int sol_lwm2m_tlv_get_int(struct sol_lwm2m_tlv *tlv, int64_t *value)
Converts an TLV value to int value.
String slice type.
Definition: sol-str-slice.h:84
These are routines that Soletta provides for its buffer implementation.
struct sol_lwm2m_security_rpk sol_lwm2m_security_rpk
Struct that represents a Raw Public Key (RPK) pair.
sol_lwm2m_security_mode
Enum that represents the UDP Security Mode.
Definition: sol-lwm2m.h:148
sol_lwm2m_acl_rights
Enum that represents the Access Control Rights.
Definition: sol-lwm2m.h:390
struct sol_lwm2m_resource::sol_lwm2m_resource_data * data
uint16_t id
The resource id.
Definition: sol-lwm2m.h:366
struct sol_buffer content
The TLV content.
Definition: sol-lwm2m.h:348
Raw Public Key security mode with Cipher Suite TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 In this case...
Definition: sol-lwm2m.h:163
The resource type is an array.
Definition: sol-lwm2m.h:275
enum sol_lwm2m_resource_type type
The resource type.
Definition: sol-lwm2m.h:362
union sol_lwm2m_resource::sol_lwm2m_resource_data::@9 content
enum sol_lwm2m_content_type type
The payload type.
Definition: sol-lwm2m.h:499
It was not possible to determine the client binding.
Definition: sol-lwm2m.h:140
The content type message is pure text.
Definition: sol-lwm2m.h:185
Indicate that the client is using Queued UDP binding and all the communication must be done using UDP...
Definition: sol-lwm2m.h:110
int sol_lwm2m_tlv_get_bytes(struct sol_lwm2m_tlv *tlv, struct sol_buffer *buf)
Get TLV content is plain bytes.
struct sol_blob * public_key
The Public Key, composed of an Opaque 64-bytes (2x256-bit) ECC key.
Definition: sol-lwm2m.h:317
The resource value is a string.
Definition: sol-lwm2m.h:233
double fp
The resource is a float value.
Definition: sol-lwm2m.h:378
int sol_lwm2m_resource_init_vector(struct sol_lwm2m_resource *resource, uint16_t id, enum sol_lwm2m_resource_data_type data_type, struct sol_vector *res_instances)
Initializes a LWM2M resource of type multiple using a sol_vector.
Data type describing the default blob implementation.
Definition: sol-types.h:468
struct sol_blob * private_key
The Private Key, composed of an Opaque 32-bytes (128-bit) ECC key.
Definition: sol-lwm2m.h:309
The resource type has single value.
Definition: sol-lwm2m.h:271
The resource value is an integer.
Definition: sol-lwm2m.h:237
A payload received from the network used to create a LWM2M object instance.
Definition: sol-lwm2m.h:495
Certificate security mode with Cipher Suite TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 In this case...
Definition: sol-lwm2m.h:171
The content type of the message is in TLV format.
Definition: sol-lwm2m.h:194
4th lsb: D (Delete)
Definition: sol-lwm2m.h:410
The TLV is a resource.
Definition: sol-lwm2m.h:222
3rd lsb: E (Execute)
Definition: sol-lwm2m.h:406
uint16_t id
Definition: sol-lwm2m.h:371
int sol_lwm2m_client_object_get_id(const struct sol_lwm2m_client_object *object, uint16_t *id)
Gets the object id.
sol_lwm2m_content_type
Enum that represents a LWM2M response/request content type.
Definition: sol-lwm2m.h:181
The content type of the message is undeterminated, in other words, it is an array of bytes...
Definition: sol-lwm2m.h:190
int sol_lwm2m_parse_tlv(const struct sol_str_slice content, struct sol_vector *tlv_values)
Parses a binary content into TLV.
The resource value is undeterminated.
Definition: sol-lwm2m.h:261
int sol_lwm2m_tlv_get_obj_link(struct sol_lwm2m_tlv *tlv, uint16_t *object_id, uint16_t *instance_id)
Converts an TLV value to object link.
struct sol_lwm2m_client_object sol_lwm2m_client_object
A handle of a client's object.
Definition: sol-lwm2m.h:82
These are routines that Soletta provides for its string slice implementation.
Pre-Shared Key security mode with Cipher Suite TLS_PSK_WITH_AES_128_CCM_8 In this case...
Definition: sol-lwm2m.h:155
struct sol_vector tlv_content
The payload content as TLV format - use only when sol_lwm2m_payload::type is SOL_LWM2M_CONTENT_TYPE_T...
Definition: sol-lwm2m.h:504
The resource value is opaque.
Definition: sol-lwm2m.h:249
uint16_t id
The id of the object/instance/resource.
Definition: sol-lwm2m.h:346
Soletta pointer vector is a wrapper around vector with an API more convenient to handle pointers...
Definition: sol-vector.h:310
The TLV is composed of multiple resources.
Definition: sol-lwm2m.h:218
int sol_lwm2m_tlv_get_float(struct sol_lwm2m_tlv *tlv, double *value)
Converts an TLV value to float value.
enum sol_lwm2m_resource_data_type data_type
The resource data type.
Definition: sol-lwm2m.h:364
Struct that represents a Pre-Shared Key (PSK).
Definition: sol-lwm2m.h:291
Soletta vector is an array that grows dynamically.
Definition: sol-vector.h:58
The TLV represents an object instance.
Definition: sol-lwm2m.h:210
uint16_t api_version
API version.
Definition: sol-lwm2m.h:340
5th lsb: C (Create)
Definition: sol-lwm2m.h:414
Indicates that the client is reacheable all the time and all the communication must be done using UDP...
Definition: sol-lwm2m.h:105
Routines to handle CoAP protocol.
enum sol_lwm2m_tlv_type type
The TLV type.
Definition: sol-lwm2m.h:344
These are routines that Soletta provides for its vector implementation.
A sol_buffer is a dynamic array, that can be resized if needed.
Definition: sol-buffer.h:130
int64_t integer
The resource is a integer value.
Definition: sol-lwm2m.h:376
union sol_lwm2m_payload::sol_lwm2m_payload_data payload
The payload data.
uint16_t data_len
The resource data array len.
Definition: sol-lwm2m.h:368
The resource value is a timestamp (Unix time).
Definition: sol-lwm2m.h:253
void sol_lwm2m_tlv_list_clear(struct sol_vector *tlvs)
Clears an TLV array.
Indicates that the client using Queued SMS and UDP binding.
Definition: sol-lwm2m.h:136
void sol_lwm2m_tlv_clear(struct sol_lwm2m_tlv *tlv)
Clear a TLV.
The resource value is a float.
Definition: sol-lwm2m.h:241
2nd lsb: W (Write)
Definition: sol-lwm2m.h:402
These are routines that Soletta provides for handling network link interfaces, making it possible to ...
The resource value is an object link.
Definition: sol-lwm2m.h:257
Struct that represents a LWM2M resource.
Definition: sol-lwm2m.h:355
struct sol_lwm2m_resource sol_lwm2m_resource
Struct that represents a LWM2M resource.