pick up wakaama files from https://github.com/eclipse/wakaama

Committer:
terencez
Date:
Wed Apr 19 11:27:34 2017 +0000
Revision:
0:c2dff8cbb91a
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
terencez 0:c2dff8cbb91a 1 /*******************************************************************************
terencez 0:c2dff8cbb91a 2 *
terencez 0:c2dff8cbb91a 3 * Copyright (c) 2013, 2014 Intel Corporation and others.
terencez 0:c2dff8cbb91a 4 * All rights reserved. This program and the accompanying materials
terencez 0:c2dff8cbb91a 5 * are made available under the terms of the Eclipse Public License v1.0
terencez 0:c2dff8cbb91a 6 * and Eclipse Distribution License v1.0 which accompany this distribution.
terencez 0:c2dff8cbb91a 7 *
terencez 0:c2dff8cbb91a 8 * The Eclipse Public License is available at
terencez 0:c2dff8cbb91a 9 * http://www.eclipse.org/legal/epl-v10.html
terencez 0:c2dff8cbb91a 10 * The Eclipse Distribution License is available at
terencez 0:c2dff8cbb91a 11 * http://www.eclipse.org/org/documents/edl-v10.php.
terencez 0:c2dff8cbb91a 12 *
terencez 0:c2dff8cbb91a 13 * Contributors:
terencez 0:c2dff8cbb91a 14 * David Navarro, Intel Corporation - initial API and implementation
terencez 0:c2dff8cbb91a 15 * Fabien Fleutot - Please refer to git log
terencez 0:c2dff8cbb91a 16 * Simon Bernard - Please refer to git log
terencez 0:c2dff8cbb91a 17 * Toby Jaffey - Please refer to git log
terencez 0:c2dff8cbb91a 18 * Julien Vermillard - Please refer to git log
terencez 0:c2dff8cbb91a 19 * Bosch Software Innovations GmbH - Please refer to git log
terencez 0:c2dff8cbb91a 20 * Pascal Rieux - Please refer to git log
terencez 0:c2dff8cbb91a 21 *******************************************************************************/
terencez 0:c2dff8cbb91a 22
terencez 0:c2dff8cbb91a 23 /*
terencez 0:c2dff8cbb91a 24 Copyright (c) 2013, 2014 Intel Corporation
terencez 0:c2dff8cbb91a 25
terencez 0:c2dff8cbb91a 26 Redistribution and use in source and binary forms, with or without modification,
terencez 0:c2dff8cbb91a 27 are permitted provided that the following conditions are met:
terencez 0:c2dff8cbb91a 28
terencez 0:c2dff8cbb91a 29 * Redistributions of source code must retain the above copyright notice,
terencez 0:c2dff8cbb91a 30 this list of conditions and the following disclaimer.
terencez 0:c2dff8cbb91a 31 * Redistributions in binary form must reproduce the above copyright notice,
terencez 0:c2dff8cbb91a 32 this list of conditions and the following disclaimer in the documentation
terencez 0:c2dff8cbb91a 33 and/or other materials provided with the distribution.
terencez 0:c2dff8cbb91a 34 * Neither the name of Intel Corporation nor the names of its contributors
terencez 0:c2dff8cbb91a 35 may be used to endorse or promote products derived from this software
terencez 0:c2dff8cbb91a 36 without specific prior written permission.
terencez 0:c2dff8cbb91a 37
terencez 0:c2dff8cbb91a 38 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
terencez 0:c2dff8cbb91a 39 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
terencez 0:c2dff8cbb91a 40 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
terencez 0:c2dff8cbb91a 41 IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
terencez 0:c2dff8cbb91a 42 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
terencez 0:c2dff8cbb91a 43 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
terencez 0:c2dff8cbb91a 44 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
terencez 0:c2dff8cbb91a 45 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
terencez 0:c2dff8cbb91a 46 OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
terencez 0:c2dff8cbb91a 47 THE POSSIBILITY OF SUCH DAMAGE.
terencez 0:c2dff8cbb91a 48
terencez 0:c2dff8cbb91a 49 David Navarro <david.navarro@intel.com>
terencez 0:c2dff8cbb91a 50
terencez 0:c2dff8cbb91a 51 */
terencez 0:c2dff8cbb91a 52
terencez 0:c2dff8cbb91a 53 #ifndef _LWM2M_CLIENT_H_
terencez 0:c2dff8cbb91a 54 #define _LWM2M_CLIENT_H_
terencez 0:c2dff8cbb91a 55
terencez 0:c2dff8cbb91a 56 #ifdef __cplusplus
terencez 0:c2dff8cbb91a 57 extern "C" {
terencez 0:c2dff8cbb91a 58 #endif
terencez 0:c2dff8cbb91a 59
terencez 0:c2dff8cbb91a 60 #include <stdint.h>
terencez 0:c2dff8cbb91a 61 #include <stddef.h>
terencez 0:c2dff8cbb91a 62 #include <stdbool.h>
terencez 0:c2dff8cbb91a 63 #include <time.h>
terencez 0:c2dff8cbb91a 64
terencez 0:c2dff8cbb91a 65 #ifdef LWM2M_SERVER_MODE
terencez 0:c2dff8cbb91a 66 #ifndef LWM2M_SUPPORT_JSON
terencez 0:c2dff8cbb91a 67 #define LWM2M_SUPPORT_JSON
terencez 0:c2dff8cbb91a 68 #endif
terencez 0:c2dff8cbb91a 69 #endif
terencez 0:c2dff8cbb91a 70
terencez 0:c2dff8cbb91a 71 #if defined(LWM2M_BOOTSTRAP) && defined(LWM2M_BOOTSTRAP_SERVER_MODE)
terencez 0:c2dff8cbb91a 72 #error "LWM2M_BOOTSTRAP and LWM2M_BOOTSTRAP_SERVER_MODE cannot be defined at the same time!"
terencez 0:c2dff8cbb91a 73 #endif
terencez 0:c2dff8cbb91a 74
terencez 0:c2dff8cbb91a 75 /*
terencez 0:c2dff8cbb91a 76 * Platform abstraction functions to be implemented by the user
terencez 0:c2dff8cbb91a 77 */
terencez 0:c2dff8cbb91a 78
terencez 0:c2dff8cbb91a 79 #ifndef LWM2M_MEMORY_TRACE
terencez 0:c2dff8cbb91a 80 // Allocate a block of size bytes of memory, returning a pointer to the beginning of the block.
terencez 0:c2dff8cbb91a 81 void * lwm2m_malloc(size_t s);
terencez 0:c2dff8cbb91a 82 // Deallocate a block of memory previously allocated by lwm2m_malloc() or lwm2m_strdup()
terencez 0:c2dff8cbb91a 83 void lwm2m_free(void * p);
terencez 0:c2dff8cbb91a 84 // Allocate a memory block, duplicate the string str in it and return a pointer to this new block.
terencez 0:c2dff8cbb91a 85 char * lwm2m_strdup(const char * str);
terencez 0:c2dff8cbb91a 86 #else
terencez 0:c2dff8cbb91a 87 // same functions as above with caller location for debugging purposes
terencez 0:c2dff8cbb91a 88 char * lwm2m_trace_strdup(const char * str, const char * file, const char * function, int lineno);
terencez 0:c2dff8cbb91a 89 void * lwm2m_trace_malloc(size_t size, const char * file, const char * function, int lineno);
terencez 0:c2dff8cbb91a 90 void lwm2m_trace_free(void * mem, const char * file, const char * function, int lineno);
terencez 0:c2dff8cbb91a 91
terencez 0:c2dff8cbb91a 92 #define lwm2m_strdup(S) lwm2m_trace_strdup(S, __FILE__, __FUNCTION__, __LINE__)
terencez 0:c2dff8cbb91a 93 #define lwm2m_malloc(S) lwm2m_trace_malloc(S, __FILE__, __FUNCTION__, __LINE__)
terencez 0:c2dff8cbb91a 94 #define lwm2m_free(M) lwm2m_trace_free(M, __FILE__, __FUNCTION__, __LINE__)
terencez 0:c2dff8cbb91a 95 #endif
terencez 0:c2dff8cbb91a 96 // Compare at most the n first bytes of s1 and s2, return 0 if they match
terencez 0:c2dff8cbb91a 97 int lwm2m_strncmp(const char * s1, const char * s2, size_t n);
terencez 0:c2dff8cbb91a 98 // This function must return the number of seconds elapsed since origin.
terencez 0:c2dff8cbb91a 99 // The origin (Epoch, system boot, etc...) does not matter as this
terencez 0:c2dff8cbb91a 100 // function is used only to determine the elapsed time since the last
terencez 0:c2dff8cbb91a 101 // call to it.
terencez 0:c2dff8cbb91a 102 // In case of error, this must return a negative value.
terencez 0:c2dff8cbb91a 103 // Per POSIX specifications, time_t is a signed integer.
terencez 0:c2dff8cbb91a 104 time_t lwm2m_gettime(void);
terencez 0:c2dff8cbb91a 105
terencez 0:c2dff8cbb91a 106 #ifdef LWM2M_WITH_LOGS
terencez 0:c2dff8cbb91a 107 // Same usage as C89 printf()
terencez 0:c2dff8cbb91a 108 void lwm2m_printf(const char * format, ...);
terencez 0:c2dff8cbb91a 109 #endif
terencez 0:c2dff8cbb91a 110
terencez 0:c2dff8cbb91a 111 // communication layer
terencez 0:c2dff8cbb91a 112 #ifdef LWM2M_CLIENT_MODE
terencez 0:c2dff8cbb91a 113 // Returns a session handle that MUST uniquely identify a peer.
terencez 0:c2dff8cbb91a 114 // secObjInstID: ID of the Securty Object instance to open a connection to
terencez 0:c2dff8cbb91a 115 // userData: parameter to lwm2m_init()
terencez 0:c2dff8cbb91a 116 void * lwm2m_connect_server(uint16_t secObjInstID, void * userData);
terencez 0:c2dff8cbb91a 117 // Close a session created by lwm2m_connect_server()
terencez 0:c2dff8cbb91a 118 // sessionH: session handle identifying the peer (opaque to the core)
terencez 0:c2dff8cbb91a 119 // userData: parameter to lwm2m_init()
terencez 0:c2dff8cbb91a 120 void lwm2m_close_connection(void * sessionH, void * userData);
terencez 0:c2dff8cbb91a 121 #endif
terencez 0:c2dff8cbb91a 122 // Send data to a peer
terencez 0:c2dff8cbb91a 123 // Returns COAP_NO_ERROR or a COAP_NNN error code
terencez 0:c2dff8cbb91a 124 // sessionH: session handle identifying the peer (opaque to the core)
terencez 0:c2dff8cbb91a 125 // buffer, length: data to send
terencez 0:c2dff8cbb91a 126 // userData: parameter to lwm2m_init()
terencez 0:c2dff8cbb91a 127 uint8_t lwm2m_buffer_send(void * sessionH, uint8_t * buffer, size_t length, void * userData);
terencez 0:c2dff8cbb91a 128 // Compare two session handles
terencez 0:c2dff8cbb91a 129 // Returns true if the two sessions identify the same peer. false otherwise.
terencez 0:c2dff8cbb91a 130 // userData: parameter to lwm2m_init()
terencez 0:c2dff8cbb91a 131 bool lwm2m_session_is_equal(void * session1, void * session2, void * userData);
terencez 0:c2dff8cbb91a 132
terencez 0:c2dff8cbb91a 133 /*
terencez 0:c2dff8cbb91a 134 * Error code
terencez 0:c2dff8cbb91a 135 */
terencez 0:c2dff8cbb91a 136
terencez 0:c2dff8cbb91a 137 #define COAP_NO_ERROR (uint8_t)0x00
terencez 0:c2dff8cbb91a 138 #define COAP_IGNORE (uint8_t)0x01
terencez 0:c2dff8cbb91a 139
terencez 0:c2dff8cbb91a 140 #define COAP_201_CREATED (uint8_t)0x41
terencez 0:c2dff8cbb91a 141 #define COAP_202_DELETED (uint8_t)0x42
terencez 0:c2dff8cbb91a 142 #define COAP_204_CHANGED (uint8_t)0x44
terencez 0:c2dff8cbb91a 143 #define COAP_205_CONTENT (uint8_t)0x45
terencez 0:c2dff8cbb91a 144 #define COAP_231_CONTINUE (uint8_t)0x5F
terencez 0:c2dff8cbb91a 145 #define COAP_400_BAD_REQUEST (uint8_t)0x80
terencez 0:c2dff8cbb91a 146 #define COAP_401_UNAUTHORIZED (uint8_t)0x81
terencez 0:c2dff8cbb91a 147 #define COAP_402_BAD_OPTION (uint8_t)0x82
terencez 0:c2dff8cbb91a 148 #define COAP_404_NOT_FOUND (uint8_t)0x84
terencez 0:c2dff8cbb91a 149 #define COAP_405_METHOD_NOT_ALLOWED (uint8_t)0x85
terencez 0:c2dff8cbb91a 150 #define COAP_406_NOT_ACCEPTABLE (uint8_t)0x86
terencez 0:c2dff8cbb91a 151 #define COAP_408_REQ_ENTITY_INCOMPLETE (uint8_t)0x88
terencez 0:c2dff8cbb91a 152 #define COAP_412_PRECONDITION_FAILED (uint8_t)0x8C
terencez 0:c2dff8cbb91a 153 #define COAP_413_ENTITY_TOO_LARGE (uint8_t)0x8D
terencez 0:c2dff8cbb91a 154 #define COAP_500_INTERNAL_SERVER_ERROR (uint8_t)0xA0
terencez 0:c2dff8cbb91a 155 #define COAP_501_NOT_IMPLEMENTED (uint8_t)0xA1
terencez 0:c2dff8cbb91a 156 #define COAP_503_SERVICE_UNAVAILABLE (uint8_t)0xA3
terencez 0:c2dff8cbb91a 157
terencez 0:c2dff8cbb91a 158 /*
terencez 0:c2dff8cbb91a 159 * Standard Object IDs
terencez 0:c2dff8cbb91a 160 */
terencez 0:c2dff8cbb91a 161 #define LWM2M_SECURITY_OBJECT_ID 0
terencez 0:c2dff8cbb91a 162 #define LWM2M_SERVER_OBJECT_ID 1
terencez 0:c2dff8cbb91a 163 #define LWM2M_ACL_OBJECT_ID 2
terencez 0:c2dff8cbb91a 164 #define LWM2M_DEVICE_OBJECT_ID 3
terencez 0:c2dff8cbb91a 165 #define LWM2M_CONN_MONITOR_OBJECT_ID 4
terencez 0:c2dff8cbb91a 166 #define LWM2M_FIRMWARE_UPDATE_OBJECT_ID 5
terencez 0:c2dff8cbb91a 167 #define LWM2M_LOCATION_OBJECT_ID 6
terencez 0:c2dff8cbb91a 168 #define LWM2M_CONN_STATS_OBJECT_ID 7
terencez 0:c2dff8cbb91a 169
terencez 0:c2dff8cbb91a 170 /*
terencez 0:c2dff8cbb91a 171 * Ressource IDs for the LWM2M Security Object
terencez 0:c2dff8cbb91a 172 */
terencez 0:c2dff8cbb91a 173 #define LWM2M_SECURITY_URI_ID 0
terencez 0:c2dff8cbb91a 174 #define LWM2M_SECURITY_BOOTSTRAP_ID 1
terencez 0:c2dff8cbb91a 175 #define LWM2M_SECURITY_SECURITY_ID 2
terencez 0:c2dff8cbb91a 176 #define LWM2M_SECURITY_PUBLIC_KEY_ID 3
terencez 0:c2dff8cbb91a 177 #define LWM2M_SECURITY_SERVER_PUBLIC_KEY_ID 4
terencez 0:c2dff8cbb91a 178 #define LWM2M_SECURITY_SECRET_KEY_ID 5
terencez 0:c2dff8cbb91a 179 #define LWM2M_SECURITY_SMS_SECURITY_ID 6
terencez 0:c2dff8cbb91a 180 #define LWM2M_SECURITY_SMS_KEY_PARAM_ID 7
terencez 0:c2dff8cbb91a 181 #define LWM2M_SECURITY_SMS_SECRET_KEY_ID 8
terencez 0:c2dff8cbb91a 182 #define LWM2M_SECURITY_SMS_SERVER_NUMBER_ID 9
terencez 0:c2dff8cbb91a 183 #define LWM2M_SECURITY_SHORT_SERVER_ID 10
terencez 0:c2dff8cbb91a 184 #define LWM2M_SECURITY_HOLD_OFF_ID 11
terencez 0:c2dff8cbb91a 185 #define LWM2M_SECURITY_BOOTSTRAP_TIMEOUT_ID 12
terencez 0:c2dff8cbb91a 186
terencez 0:c2dff8cbb91a 187 /*
terencez 0:c2dff8cbb91a 188 * Ressource IDs for the LWM2M Server Object
terencez 0:c2dff8cbb91a 189 */
terencez 0:c2dff8cbb91a 190 #define LWM2M_SERVER_SHORT_ID_ID 0
terencez 0:c2dff8cbb91a 191 #define LWM2M_SERVER_LIFETIME_ID 1
terencez 0:c2dff8cbb91a 192 #define LWM2M_SERVER_MIN_PERIOD_ID 2
terencez 0:c2dff8cbb91a 193 #define LWM2M_SERVER_MAX_PERIOD_ID 3
terencez 0:c2dff8cbb91a 194 #define LWM2M_SERVER_DISABLE_ID 4
terencez 0:c2dff8cbb91a 195 #define LWM2M_SERVER_TIMEOUT_ID 5
terencez 0:c2dff8cbb91a 196 #define LWM2M_SERVER_STORING_ID 6
terencez 0:c2dff8cbb91a 197 #define LWM2M_SERVER_BINDING_ID 7
terencez 0:c2dff8cbb91a 198 #define LWM2M_SERVER_UPDATE_ID 8
terencez 0:c2dff8cbb91a 199
terencez 0:c2dff8cbb91a 200 #define LWM2M_SECURITY_MODE_PRE_SHARED_KEY 0
terencez 0:c2dff8cbb91a 201 #define LWM2M_SECURITY_MODE_RAW_PUBLIC_KEY 1
terencez 0:c2dff8cbb91a 202 #define LWM2M_SECURITY_MODE_CERTIFICATE 2
terencez 0:c2dff8cbb91a 203 #define LWM2M_SECURITY_MODE_NONE 3
terencez 0:c2dff8cbb91a 204
terencez 0:c2dff8cbb91a 205
terencez 0:c2dff8cbb91a 206 /*
terencez 0:c2dff8cbb91a 207 * Utility functions for sorted linked list
terencez 0:c2dff8cbb91a 208 */
terencez 0:c2dff8cbb91a 209
terencez 0:c2dff8cbb91a 210 typedef struct _lwm2m_list_t
terencez 0:c2dff8cbb91a 211 {
terencez 0:c2dff8cbb91a 212 struct _lwm2m_list_t * next;
terencez 0:c2dff8cbb91a 213 uint16_t id;
terencez 0:c2dff8cbb91a 214 } lwm2m_list_t;
terencez 0:c2dff8cbb91a 215
terencez 0:c2dff8cbb91a 216 // defined in list.c
terencez 0:c2dff8cbb91a 217 // Add 'node' to the list 'head' and return the new list
terencez 0:c2dff8cbb91a 218 lwm2m_list_t * lwm2m_list_add(lwm2m_list_t * head, lwm2m_list_t * node);
terencez 0:c2dff8cbb91a 219 // Return the node with ID 'id' from the list 'head' or NULL if not found
terencez 0:c2dff8cbb91a 220 lwm2m_list_t * lwm2m_list_find(lwm2m_list_t * head, uint16_t id);
terencez 0:c2dff8cbb91a 221 // Remove the node with ID 'id' from the list 'head' and return the new list
terencez 0:c2dff8cbb91a 222 lwm2m_list_t * lwm2m_list_remove(lwm2m_list_t * head, uint16_t id, lwm2m_list_t ** nodeP);
terencez 0:c2dff8cbb91a 223 // Return the lowest unused ID in the list 'head'
terencez 0:c2dff8cbb91a 224 uint16_t lwm2m_list_newId(lwm2m_list_t * head);
terencez 0:c2dff8cbb91a 225 // Free a list. Do not use if nodes contain allocated pointers as it calls lwm2m_free on nodes only.
terencez 0:c2dff8cbb91a 226 // If the nodes of the list need to do more than just "free()" their instances, don't use lwm2m_list_free().
terencez 0:c2dff8cbb91a 227 void lwm2m_list_free(lwm2m_list_t * head);
terencez 0:c2dff8cbb91a 228
terencez 0:c2dff8cbb91a 229 #define LWM2M_LIST_ADD(H,N) lwm2m_list_add((lwm2m_list_t *)H, (lwm2m_list_t *)N);
terencez 0:c2dff8cbb91a 230 #define LWM2M_LIST_RM(H,I,N) lwm2m_list_remove((lwm2m_list_t *)H, I, (lwm2m_list_t **)N);
terencez 0:c2dff8cbb91a 231 #define LWM2M_LIST_FIND(H,I) lwm2m_list_find((lwm2m_list_t *)H, I)
terencez 0:c2dff8cbb91a 232 #define LWM2M_LIST_FREE(H) lwm2m_list_free((lwm2m_list_t *)H)
terencez 0:c2dff8cbb91a 233
terencez 0:c2dff8cbb91a 234 /*
terencez 0:c2dff8cbb91a 235 * URI
terencez 0:c2dff8cbb91a 236 *
terencez 0:c2dff8cbb91a 237 * objectId is always set
terencez 0:c2dff8cbb91a 238 * instanceId or resourceId are set according to the flag bit-field
terencez 0:c2dff8cbb91a 239 *
terencez 0:c2dff8cbb91a 240 */
terencez 0:c2dff8cbb91a 241
terencez 0:c2dff8cbb91a 242 #define LWM2M_MAX_ID ((uint16_t)0xFFFF)
terencez 0:c2dff8cbb91a 243
terencez 0:c2dff8cbb91a 244 #define LWM2M_URI_FLAG_OBJECT_ID (uint8_t)0x04
terencez 0:c2dff8cbb91a 245 #define LWM2M_URI_FLAG_INSTANCE_ID (uint8_t)0x02
terencez 0:c2dff8cbb91a 246 #define LWM2M_URI_FLAG_RESOURCE_ID (uint8_t)0x01
terencez 0:c2dff8cbb91a 247
terencez 0:c2dff8cbb91a 248 #define LWM2M_URI_IS_SET_INSTANCE(uri) (((uri)->flag & LWM2M_URI_FLAG_INSTANCE_ID) != 0)
terencez 0:c2dff8cbb91a 249 #define LWM2M_URI_IS_SET_RESOURCE(uri) (((uri)->flag & LWM2M_URI_FLAG_RESOURCE_ID) != 0)
terencez 0:c2dff8cbb91a 250
terencez 0:c2dff8cbb91a 251 typedef struct
terencez 0:c2dff8cbb91a 252 {
terencez 0:c2dff8cbb91a 253 uint8_t flag; // indicates which segments are set
terencez 0:c2dff8cbb91a 254 uint16_t objectId;
terencez 0:c2dff8cbb91a 255 uint16_t instanceId;
terencez 0:c2dff8cbb91a 256 uint16_t resourceId;
terencez 0:c2dff8cbb91a 257 } lwm2m_uri_t;
terencez 0:c2dff8cbb91a 258
terencez 0:c2dff8cbb91a 259
terencez 0:c2dff8cbb91a 260 #define LWM2M_STRING_ID_MAX_LEN 6
terencez 0:c2dff8cbb91a 261
terencez 0:c2dff8cbb91a 262 // Parse an URI in LWM2M format and fill the lwm2m_uri_t.
terencez 0:c2dff8cbb91a 263 // Return the number of characters read from buffer or 0 in case of error.
terencez 0:c2dff8cbb91a 264 // Valid URIs: /1, /1/, /1/2, /1/2/, /1/2/3
terencez 0:c2dff8cbb91a 265 // Invalid URIs: /, //, //2, /1//, /1//3, /1/2/3/, /1/2/3/4
terencez 0:c2dff8cbb91a 266 int lwm2m_stringToUri(const char * buffer, size_t buffer_len, lwm2m_uri_t * uriP);
terencez 0:c2dff8cbb91a 267
terencez 0:c2dff8cbb91a 268 /*
terencez 0:c2dff8cbb91a 269 * The lwm2m_data_t is used to store LWM2M resource values in a hierarchical way.
terencez 0:c2dff8cbb91a 270 * Depending on the type the value is different:
terencez 0:c2dff8cbb91a 271 * - LWM2M_TYPE_OBJECT, LWM2M_TYPE_OBJECT_INSTANCE, LWM2M_TYPE_MULTIPLE_RESOURCE: value.asChildren
terencez 0:c2dff8cbb91a 272 * - LWM2M_TYPE_STRING, LWM2M_TYPE_OPAQUE: value.asBuffer
terencez 0:c2dff8cbb91a 273 * - LWM2M_TYPE_INTEGER, LWM2M_TYPE_TIME: value.asInteger
terencez 0:c2dff8cbb91a 274 * - LWM2M_TYPE_FLOAT: value.asFloat
terencez 0:c2dff8cbb91a 275 * - LWM2M_TYPE_BOOLEAN: value.asBoolean
terencez 0:c2dff8cbb91a 276 *
terencez 0:c2dff8cbb91a 277 * LWM2M_TYPE_STRING is also used when the data is in text format.
terencez 0:c2dff8cbb91a 278 */
terencez 0:c2dff8cbb91a 279
terencez 0:c2dff8cbb91a 280 typedef enum
terencez 0:c2dff8cbb91a 281 {
terencez 0:c2dff8cbb91a 282 LWM2M_TYPE_UNDEFINED = 0,
terencez 0:c2dff8cbb91a 283 LWM2M_TYPE_OBJECT,
terencez 0:c2dff8cbb91a 284 LWM2M_TYPE_OBJECT_INSTANCE,
terencez 0:c2dff8cbb91a 285 LWM2M_TYPE_MULTIPLE_RESOURCE,
terencez 0:c2dff8cbb91a 286
terencez 0:c2dff8cbb91a 287 LWM2M_TYPE_STRING,
terencez 0:c2dff8cbb91a 288 LWM2M_TYPE_OPAQUE,
terencez 0:c2dff8cbb91a 289 LWM2M_TYPE_INTEGER,
terencez 0:c2dff8cbb91a 290 LWM2M_TYPE_FLOAT,
terencez 0:c2dff8cbb91a 291 LWM2M_TYPE_BOOLEAN,
terencez 0:c2dff8cbb91a 292
terencez 0:c2dff8cbb91a 293 LWM2M_TYPE_OBJECT_LINK
terencez 0:c2dff8cbb91a 294 } lwm2m_data_type_t;
terencez 0:c2dff8cbb91a 295
terencez 0:c2dff8cbb91a 296 typedef struct _lwm2m_data_t lwm2m_data_t;
terencez 0:c2dff8cbb91a 297
terencez 0:c2dff8cbb91a 298 struct _lwm2m_data_t
terencez 0:c2dff8cbb91a 299 {
terencez 0:c2dff8cbb91a 300 lwm2m_data_type_t type;
terencez 0:c2dff8cbb91a 301 uint16_t id;
terencez 0:c2dff8cbb91a 302 union
terencez 0:c2dff8cbb91a 303 {
terencez 0:c2dff8cbb91a 304 bool asBoolean;
terencez 0:c2dff8cbb91a 305 int64_t asInteger;
terencez 0:c2dff8cbb91a 306 double asFloat;
terencez 0:c2dff8cbb91a 307 struct
terencez 0:c2dff8cbb91a 308 {
terencez 0:c2dff8cbb91a 309 size_t length;
terencez 0:c2dff8cbb91a 310 uint8_t * buffer;
terencez 0:c2dff8cbb91a 311 } asBuffer;
terencez 0:c2dff8cbb91a 312 struct
terencez 0:c2dff8cbb91a 313 {
terencez 0:c2dff8cbb91a 314 size_t count;
terencez 0:c2dff8cbb91a 315 lwm2m_data_t * array;
terencez 0:c2dff8cbb91a 316 } asChildren;
terencez 0:c2dff8cbb91a 317 struct
terencez 0:c2dff8cbb91a 318 {
terencez 0:c2dff8cbb91a 319 uint16_t objectId;
terencez 0:c2dff8cbb91a 320 uint16_t objectInstanceId;
terencez 0:c2dff8cbb91a 321 } asObjLink;
terencez 0:c2dff8cbb91a 322 } value;
terencez 0:c2dff8cbb91a 323 };
terencez 0:c2dff8cbb91a 324
terencez 0:c2dff8cbb91a 325 typedef enum
terencez 0:c2dff8cbb91a 326 {
terencez 0:c2dff8cbb91a 327 LWM2M_CONTENT_TEXT = 0, // Also used as undefined
terencez 0:c2dff8cbb91a 328 LWM2M_CONTENT_LINK = 40,
terencez 0:c2dff8cbb91a 329 LWM2M_CONTENT_OPAQUE = 42,
terencez 0:c2dff8cbb91a 330 LWM2M_CONTENT_TLV_OLD = 1542, // Keep old value for backward-compatibility
terencez 0:c2dff8cbb91a 331 LWM2M_CONTENT_TLV = 11542,
terencez 0:c2dff8cbb91a 332 LWM2M_CONTENT_JSON_OLD = 1543, // Keep old value for backward-compatibility
terencez 0:c2dff8cbb91a 333 LWM2M_CONTENT_JSON = 11543
terencez 0:c2dff8cbb91a 334 } lwm2m_media_type_t;
terencez 0:c2dff8cbb91a 335
terencez 0:c2dff8cbb91a 336 lwm2m_data_t * lwm2m_data_new(int size);
terencez 0:c2dff8cbb91a 337 int lwm2m_data_parse(lwm2m_uri_t * uriP, uint8_t * buffer, size_t bufferLen, lwm2m_media_type_t format, lwm2m_data_t ** dataP);
terencez 0:c2dff8cbb91a 338 int lwm2m_data_serialize(lwm2m_uri_t * uriP, int size, lwm2m_data_t * dataP, lwm2m_media_type_t * formatP, uint8_t ** bufferP);
terencez 0:c2dff8cbb91a 339 void lwm2m_data_free(int size, lwm2m_data_t * dataP);
terencez 0:c2dff8cbb91a 340
terencez 0:c2dff8cbb91a 341 void lwm2m_data_encode_string(const char * string, lwm2m_data_t * dataP);
terencez 0:c2dff8cbb91a 342 void lwm2m_data_encode_nstring(const char * string, size_t length, lwm2m_data_t * dataP);
terencez 0:c2dff8cbb91a 343 void lwm2m_data_encode_opaque(uint8_t * buffer, size_t length, lwm2m_data_t * dataP);
terencez 0:c2dff8cbb91a 344 void lwm2m_data_encode_int(int64_t value, lwm2m_data_t * dataP);
terencez 0:c2dff8cbb91a 345 int lwm2m_data_decode_int(const lwm2m_data_t * dataP, int64_t * valueP);
terencez 0:c2dff8cbb91a 346 void lwm2m_data_encode_float(double value, lwm2m_data_t * dataP);
terencez 0:c2dff8cbb91a 347 int lwm2m_data_decode_float(const lwm2m_data_t * dataP, double * valueP);
terencez 0:c2dff8cbb91a 348 void lwm2m_data_encode_bool(bool value, lwm2m_data_t * dataP);
terencez 0:c2dff8cbb91a 349 int lwm2m_data_decode_bool(const lwm2m_data_t * dataP, bool * valueP);
terencez 0:c2dff8cbb91a 350 void lwm2m_data_encode_objlink(uint16_t objectId, uint16_t objectInstanceId, lwm2m_data_t * dataP);
terencez 0:c2dff8cbb91a 351 void lwm2m_data_encode_instances(lwm2m_data_t * subDataP, size_t count, lwm2m_data_t * dataP);
terencez 0:c2dff8cbb91a 352 void lwm2m_data_include(lwm2m_data_t * subDataP, size_t count, lwm2m_data_t * dataP);
terencez 0:c2dff8cbb91a 353
terencez 0:c2dff8cbb91a 354
terencez 0:c2dff8cbb91a 355 /*
terencez 0:c2dff8cbb91a 356 * Utility function to parse TLV buffers directly
terencez 0:c2dff8cbb91a 357 *
terencez 0:c2dff8cbb91a 358 * Returned value: number of bytes parsed
terencez 0:c2dff8cbb91a 359 * buffer: buffer to parse
terencez 0:c2dff8cbb91a 360 * buffer_len: length in bytes of buffer
terencez 0:c2dff8cbb91a 361 * oType: (OUT) type of the parsed TLV record. can be:
terencez 0:c2dff8cbb91a 362 * - LWM2M_TYPE_OBJECT
terencez 0:c2dff8cbb91a 363 * - LWM2M_TYPE_OBJECT_INSTANCE
terencez 0:c2dff8cbb91a 364 * - LWM2M_TYPE_MULTIPLE_RESOURCE
terencez 0:c2dff8cbb91a 365 * - LWM2M_TYPE_OPAQUE
terencez 0:c2dff8cbb91a 366 * oID: (OUT) ID of the parsed TLV record
terencez 0:c2dff8cbb91a 367 * oDataIndex: (OUT) index of the data of the parsed TLV record in the buffer
terencez 0:c2dff8cbb91a 368 * oDataLen: (OUT) length of the data of the parsed TLV record
terencez 0:c2dff8cbb91a 369 */
terencez 0:c2dff8cbb91a 370
terencez 0:c2dff8cbb91a 371 #define LWM2M_TLV_HEADER_MAX_LENGTH 6
terencez 0:c2dff8cbb91a 372
terencez 0:c2dff8cbb91a 373 int lwm2m_decode_TLV(const uint8_t * buffer, size_t buffer_len, lwm2m_data_type_t * oType, uint16_t * oID, size_t * oDataIndex, size_t * oDataLen);
terencez 0:c2dff8cbb91a 374
terencez 0:c2dff8cbb91a 375
terencez 0:c2dff8cbb91a 376 /*
terencez 0:c2dff8cbb91a 377 * LWM2M Objects
terencez 0:c2dff8cbb91a 378 *
terencez 0:c2dff8cbb91a 379 * For the read callback, if *numDataP is not zero, *dataArrayP is pre-allocated
terencez 0:c2dff8cbb91a 380 * and contains the list of resources to read.
terencez 0:c2dff8cbb91a 381 *
terencez 0:c2dff8cbb91a 382 */
terencez 0:c2dff8cbb91a 383
terencez 0:c2dff8cbb91a 384 typedef struct _lwm2m_object_t lwm2m_object_t;
terencez 0:c2dff8cbb91a 385
terencez 0:c2dff8cbb91a 386 typedef uint8_t (*lwm2m_read_callback_t) (uint16_t instanceId, int * numDataP, lwm2m_data_t ** dataArrayP, lwm2m_object_t * objectP);
terencez 0:c2dff8cbb91a 387 typedef uint8_t (*lwm2m_discover_callback_t) (uint16_t instanceId, int * numDataP, lwm2m_data_t ** dataArrayP, lwm2m_object_t * objectP);
terencez 0:c2dff8cbb91a 388 typedef uint8_t (*lwm2m_write_callback_t) (uint16_t instanceId, int numData, lwm2m_data_t * dataArray, lwm2m_object_t * objectP);
terencez 0:c2dff8cbb91a 389 typedef uint8_t (*lwm2m_execute_callback_t) (uint16_t instanceId, uint16_t resourceId, uint8_t * buffer, int length, lwm2m_object_t * objectP);
terencez 0:c2dff8cbb91a 390 typedef uint8_t (*lwm2m_create_callback_t) (uint16_t instanceId, int numData, lwm2m_data_t * dataArray, lwm2m_object_t * objectP);
terencez 0:c2dff8cbb91a 391 typedef uint8_t (*lwm2m_delete_callback_t) (uint16_t instanceId, lwm2m_object_t * objectP);
terencez 0:c2dff8cbb91a 392
terencez 0:c2dff8cbb91a 393 struct _lwm2m_object_t
terencez 0:c2dff8cbb91a 394 {
terencez 0:c2dff8cbb91a 395 struct _lwm2m_object_t * next; // for internal use only.
terencez 0:c2dff8cbb91a 396 uint16_t objID;
terencez 0:c2dff8cbb91a 397 lwm2m_list_t * instanceList;
terencez 0:c2dff8cbb91a 398 lwm2m_read_callback_t readFunc;
terencez 0:c2dff8cbb91a 399 lwm2m_write_callback_t writeFunc;
terencez 0:c2dff8cbb91a 400 lwm2m_execute_callback_t executeFunc;
terencez 0:c2dff8cbb91a 401 lwm2m_create_callback_t createFunc;
terencez 0:c2dff8cbb91a 402 lwm2m_delete_callback_t deleteFunc;
terencez 0:c2dff8cbb91a 403 lwm2m_discover_callback_t discoverFunc;
terencez 0:c2dff8cbb91a 404 void * userData;
terencez 0:c2dff8cbb91a 405 };
terencez 0:c2dff8cbb91a 406
terencez 0:c2dff8cbb91a 407 /*
terencez 0:c2dff8cbb91a 408 * LWM2M Servers
terencez 0:c2dff8cbb91a 409 *
terencez 0:c2dff8cbb91a 410 * Since LWM2M Server Object instances are not accessible to LWM2M servers,
terencez 0:c2dff8cbb91a 411 * there is no need to store them as lwm2m_objects_t
terencez 0:c2dff8cbb91a 412 */
terencez 0:c2dff8cbb91a 413
terencez 0:c2dff8cbb91a 414 typedef enum
terencez 0:c2dff8cbb91a 415 {
terencez 0:c2dff8cbb91a 416 STATE_DEREGISTERED = 0, // not registered or boostrap not started
terencez 0:c2dff8cbb91a 417 STATE_REG_PENDING, // registration pending
terencez 0:c2dff8cbb91a 418 STATE_REGISTERED, // successfully registered
terencez 0:c2dff8cbb91a 419 STATE_REG_FAILED, // last registration failed
terencez 0:c2dff8cbb91a 420 STATE_REG_UPDATE_PENDING, // registration update pending
terencez 0:c2dff8cbb91a 421 STATE_REG_UPDATE_NEEDED, // registration update required
terencez 0:c2dff8cbb91a 422 STATE_REG_FULL_UPDATE_NEEDED, // registration update with objects required
terencez 0:c2dff8cbb91a 423 STATE_DEREG_PENDING, // deregistration pending
terencez 0:c2dff8cbb91a 424 STATE_BS_HOLD_OFF, // bootstrap hold off time
terencez 0:c2dff8cbb91a 425 STATE_BS_INITIATED, // bootstrap request sent
terencez 0:c2dff8cbb91a 426 STATE_BS_PENDING, // boostrap ongoing
terencez 0:c2dff8cbb91a 427 STATE_BS_FINISHING, // boostrap finish received
terencez 0:c2dff8cbb91a 428 STATE_BS_FINISHED, // bootstrap done
terencez 0:c2dff8cbb91a 429 STATE_BS_FAILING, // bootstrap error occurred
terencez 0:c2dff8cbb91a 430 STATE_BS_FAILED, // bootstrap failed
terencez 0:c2dff8cbb91a 431 } lwm2m_status_t;
terencez 0:c2dff8cbb91a 432
terencez 0:c2dff8cbb91a 433 typedef enum
terencez 0:c2dff8cbb91a 434 {
terencez 0:c2dff8cbb91a 435 BINDING_UNKNOWN = 0,
terencez 0:c2dff8cbb91a 436 BINDING_U, // UDP
terencez 0:c2dff8cbb91a 437 BINDING_UQ, // UDP queue mode
terencez 0:c2dff8cbb91a 438 BINDING_S, // SMS
terencez 0:c2dff8cbb91a 439 BINDING_SQ, // SMS queue mode
terencez 0:c2dff8cbb91a 440 BINDING_US, // UDP plus SMS
terencez 0:c2dff8cbb91a 441 BINDING_UQS // UDP queue mode plus SMS
terencez 0:c2dff8cbb91a 442 } lwm2m_binding_t;
terencez 0:c2dff8cbb91a 443
terencez 0:c2dff8cbb91a 444 /*
terencez 0:c2dff8cbb91a 445 * LWM2M block1 data
terencez 0:c2dff8cbb91a 446 *
terencez 0:c2dff8cbb91a 447 * Temporary data needed to handle block1 request.
terencez 0:c2dff8cbb91a 448 * Currently support only one block1 request by server.
terencez 0:c2dff8cbb91a 449 */
terencez 0:c2dff8cbb91a 450 typedef struct _lwm2m_block1_data_ lwm2m_block1_data_t;
terencez 0:c2dff8cbb91a 451
terencez 0:c2dff8cbb91a 452 struct _lwm2m_block1_data_
terencez 0:c2dff8cbb91a 453 {
terencez 0:c2dff8cbb91a 454 uint8_t * block1buffer; // data buffer
terencez 0:c2dff8cbb91a 455 size_t block1bufferSize; // buffer size
terencez 0:c2dff8cbb91a 456 uint16_t lastmid; // mid of the last message received
terencez 0:c2dff8cbb91a 457 };
terencez 0:c2dff8cbb91a 458
terencez 0:c2dff8cbb91a 459 typedef struct _lwm2m_server_
terencez 0:c2dff8cbb91a 460 {
terencez 0:c2dff8cbb91a 461 struct _lwm2m_server_ * next; // matches lwm2m_list_t::next
terencez 0:c2dff8cbb91a 462 uint16_t secObjInstID; // matches lwm2m_list_t::id
terencez 0:c2dff8cbb91a 463 uint16_t shortID; // servers short ID, may be 0 for bootstrap server
terencez 0:c2dff8cbb91a 464 time_t lifetime; // lifetime of the registration in sec or 0 if default value (86400 sec), also used as hold off time for bootstrap servers
terencez 0:c2dff8cbb91a 465 time_t registration; // date of the last registration in sec or end of client hold off time for bootstrap servers
terencez 0:c2dff8cbb91a 466 lwm2m_binding_t binding; // client connection mode with this server
terencez 0:c2dff8cbb91a 467 void * sessionH;
terencez 0:c2dff8cbb91a 468 lwm2m_status_t status;
terencez 0:c2dff8cbb91a 469 char * location;
terencez 0:c2dff8cbb91a 470 bool dirty;
terencez 0:c2dff8cbb91a 471 lwm2m_block1_data_t * block1Data; // buffer to handle block1 data, should be replace by a list to support several block1 transfer by server.
terencez 0:c2dff8cbb91a 472 } lwm2m_server_t;
terencez 0:c2dff8cbb91a 473
terencez 0:c2dff8cbb91a 474
terencez 0:c2dff8cbb91a 475 /*
terencez 0:c2dff8cbb91a 476 * LWM2M result callback
terencez 0:c2dff8cbb91a 477 *
terencez 0:c2dff8cbb91a 478 * When used with an observe, if 'data' is not nil, 'status' holds the observe counter.
terencez 0:c2dff8cbb91a 479 */
terencez 0:c2dff8cbb91a 480 typedef void (*lwm2m_result_callback_t) (uint16_t clientID, lwm2m_uri_t * uriP, int status, lwm2m_media_type_t format, uint8_t * data, int dataLength, void * userData);
terencez 0:c2dff8cbb91a 481
terencez 0:c2dff8cbb91a 482 /*
terencez 0:c2dff8cbb91a 483 * LWM2M Observations
terencez 0:c2dff8cbb91a 484 *
terencez 0:c2dff8cbb91a 485 * Used to store observation of remote clients resources.
terencez 0:c2dff8cbb91a 486 * status STATE_REG_PENDING means the observe request was sent to the client but not yet answered.
terencez 0:c2dff8cbb91a 487 * status STATE_REGISTERED means the client acknowledged the observe request.
terencez 0:c2dff8cbb91a 488 * status STATE_DEREG_PENDING means the user canceled the request before the client answered it.
terencez 0:c2dff8cbb91a 489 */
terencez 0:c2dff8cbb91a 490
terencez 0:c2dff8cbb91a 491 typedef struct _lwm2m_observation_
terencez 0:c2dff8cbb91a 492 {
terencez 0:c2dff8cbb91a 493 struct _lwm2m_observation_ * next; // matches lwm2m_list_t::next
terencez 0:c2dff8cbb91a 494 uint16_t id; // matches lwm2m_list_t::id
terencez 0:c2dff8cbb91a 495 struct _lwm2m_client_ * clientP;
terencez 0:c2dff8cbb91a 496 lwm2m_uri_t uri;
terencez 0:c2dff8cbb91a 497 lwm2m_status_t status;
terencez 0:c2dff8cbb91a 498 lwm2m_result_callback_t callback;
terencez 0:c2dff8cbb91a 499 void * userData;
terencez 0:c2dff8cbb91a 500 } lwm2m_observation_t;
terencez 0:c2dff8cbb91a 501
terencez 0:c2dff8cbb91a 502 /*
terencez 0:c2dff8cbb91a 503 * LWM2M Link Attributes
terencez 0:c2dff8cbb91a 504 *
terencez 0:c2dff8cbb91a 505 * Used for observation parameters.
terencez 0:c2dff8cbb91a 506 *
terencez 0:c2dff8cbb91a 507 */
terencez 0:c2dff8cbb91a 508
terencez 0:c2dff8cbb91a 509 #define LWM2M_ATTR_FLAG_MIN_PERIOD (uint8_t)0x01
terencez 0:c2dff8cbb91a 510 #define LWM2M_ATTR_FLAG_MAX_PERIOD (uint8_t)0x02
terencez 0:c2dff8cbb91a 511 #define LWM2M_ATTR_FLAG_GREATER_THAN (uint8_t)0x04
terencez 0:c2dff8cbb91a 512 #define LWM2M_ATTR_FLAG_LESS_THAN (uint8_t)0x08
terencez 0:c2dff8cbb91a 513 #define LWM2M_ATTR_FLAG_STEP (uint8_t)0x10
terencez 0:c2dff8cbb91a 514
terencez 0:c2dff8cbb91a 515 typedef struct
terencez 0:c2dff8cbb91a 516 {
terencez 0:c2dff8cbb91a 517 uint8_t toSet;
terencez 0:c2dff8cbb91a 518 uint8_t toClear;
terencez 0:c2dff8cbb91a 519 uint32_t minPeriod;
terencez 0:c2dff8cbb91a 520 uint32_t maxPeriod;
terencez 0:c2dff8cbb91a 521 double greaterThan;
terencez 0:c2dff8cbb91a 522 double lessThan;
terencez 0:c2dff8cbb91a 523 double step;
terencez 0:c2dff8cbb91a 524 } lwm2m_attributes_t;
terencez 0:c2dff8cbb91a 525
terencez 0:c2dff8cbb91a 526 /*
terencez 0:c2dff8cbb91a 527 * LWM2M Clients
terencez 0:c2dff8cbb91a 528 *
terencez 0:c2dff8cbb91a 529 * Be careful not to mix lwm2m_client_object_t used to store list of objects of remote clients
terencez 0:c2dff8cbb91a 530 * and lwm2m_object_t describing objects exposed to remote servers.
terencez 0:c2dff8cbb91a 531 *
terencez 0:c2dff8cbb91a 532 */
terencez 0:c2dff8cbb91a 533
terencez 0:c2dff8cbb91a 534 typedef struct _lwm2m_client_object_
terencez 0:c2dff8cbb91a 535 {
terencez 0:c2dff8cbb91a 536 struct _lwm2m_client_object_ * next; // matches lwm2m_list_t::next
terencez 0:c2dff8cbb91a 537 uint16_t id; // matches lwm2m_list_t::id
terencez 0:c2dff8cbb91a 538 lwm2m_list_t * instanceList;
terencez 0:c2dff8cbb91a 539 } lwm2m_client_object_t;
terencez 0:c2dff8cbb91a 540
terencez 0:c2dff8cbb91a 541 typedef struct _lwm2m_client_
terencez 0:c2dff8cbb91a 542 {
terencez 0:c2dff8cbb91a 543 struct _lwm2m_client_ * next; // matches lwm2m_list_t::next
terencez 0:c2dff8cbb91a 544 uint16_t internalID; // matches lwm2m_list_t::id
terencez 0:c2dff8cbb91a 545 char * name;
terencez 0:c2dff8cbb91a 546 lwm2m_binding_t binding;
terencez 0:c2dff8cbb91a 547 char * msisdn;
terencez 0:c2dff8cbb91a 548 char * altPath;
terencez 0:c2dff8cbb91a 549 bool supportJSON;
terencez 0:c2dff8cbb91a 550 uint32_t lifetime;
terencez 0:c2dff8cbb91a 551 time_t endOfLife;
terencez 0:c2dff8cbb91a 552 void * sessionH;
terencez 0:c2dff8cbb91a 553 lwm2m_client_object_t * objectList;
terencez 0:c2dff8cbb91a 554 lwm2m_observation_t * observationList;
terencez 0:c2dff8cbb91a 555 } lwm2m_client_t;
terencez 0:c2dff8cbb91a 556
terencez 0:c2dff8cbb91a 557
terencez 0:c2dff8cbb91a 558 /*
terencez 0:c2dff8cbb91a 559 * LWM2M transaction
terencez 0:c2dff8cbb91a 560 *
terencez 0:c2dff8cbb91a 561 * Adaptation of Erbium's coap_transaction_t
terencez 0:c2dff8cbb91a 562 */
terencez 0:c2dff8cbb91a 563
terencez 0:c2dff8cbb91a 564 typedef struct _lwm2m_transaction_ lwm2m_transaction_t;
terencez 0:c2dff8cbb91a 565
terencez 0:c2dff8cbb91a 566 typedef void (*lwm2m_transaction_callback_t) (lwm2m_transaction_t * transacP, void * message);
terencez 0:c2dff8cbb91a 567
terencez 0:c2dff8cbb91a 568 struct _lwm2m_transaction_
terencez 0:c2dff8cbb91a 569 {
terencez 0:c2dff8cbb91a 570 lwm2m_transaction_t * next; // matches lwm2m_list_t::next
terencez 0:c2dff8cbb91a 571 uint16_t mID; // matches lwm2m_list_t::id
terencez 0:c2dff8cbb91a 572 void * peerH;
terencez 0:c2dff8cbb91a 573 uint8_t ack_received; // indicates, that the ACK was received
terencez 0:c2dff8cbb91a 574 time_t response_timeout; // timeout to wait for response, if token is used. When 0, use calculated acknowledge timeout.
terencez 0:c2dff8cbb91a 575 uint8_t retrans_counter;
terencez 0:c2dff8cbb91a 576 time_t retrans_time;
terencez 0:c2dff8cbb91a 577 char objStringID[LWM2M_STRING_ID_MAX_LEN];
terencez 0:c2dff8cbb91a 578 char instanceStringID[LWM2M_STRING_ID_MAX_LEN];
terencez 0:c2dff8cbb91a 579 char resourceStringID[LWM2M_STRING_ID_MAX_LEN];
terencez 0:c2dff8cbb91a 580 void * message;
terencez 0:c2dff8cbb91a 581 uint16_t buffer_len;
terencez 0:c2dff8cbb91a 582 uint8_t * buffer;
terencez 0:c2dff8cbb91a 583 lwm2m_transaction_callback_t callback;
terencez 0:c2dff8cbb91a 584 void * userData;
terencez 0:c2dff8cbb91a 585 };
terencez 0:c2dff8cbb91a 586
terencez 0:c2dff8cbb91a 587 /*
terencez 0:c2dff8cbb91a 588 * LWM2M observed resources
terencez 0:c2dff8cbb91a 589 */
terencez 0:c2dff8cbb91a 590 typedef struct _lwm2m_watcher_
terencez 0:c2dff8cbb91a 591 {
terencez 0:c2dff8cbb91a 592 struct _lwm2m_watcher_ * next;
terencez 0:c2dff8cbb91a 593
terencez 0:c2dff8cbb91a 594 bool active;
terencez 0:c2dff8cbb91a 595 bool update;
terencez 0:c2dff8cbb91a 596 lwm2m_server_t * server;
terencez 0:c2dff8cbb91a 597 lwm2m_attributes_t * parameters;
terencez 0:c2dff8cbb91a 598 uint8_t token[8];
terencez 0:c2dff8cbb91a 599 size_t tokenLen;
terencez 0:c2dff8cbb91a 600 time_t lastTime;
terencez 0:c2dff8cbb91a 601 uint32_t counter;
terencez 0:c2dff8cbb91a 602 uint16_t lastMid;
terencez 0:c2dff8cbb91a 603 union
terencez 0:c2dff8cbb91a 604 {
terencez 0:c2dff8cbb91a 605 int64_t asInteger;
terencez 0:c2dff8cbb91a 606 double asFloat;
terencez 0:c2dff8cbb91a 607 } lastValue;
terencez 0:c2dff8cbb91a 608 } lwm2m_watcher_t;
terencez 0:c2dff8cbb91a 609
terencez 0:c2dff8cbb91a 610 typedef struct _lwm2m_observed_
terencez 0:c2dff8cbb91a 611 {
terencez 0:c2dff8cbb91a 612 struct _lwm2m_observed_ * next;
terencez 0:c2dff8cbb91a 613
terencez 0:c2dff8cbb91a 614 lwm2m_uri_t uri;
terencez 0:c2dff8cbb91a 615 lwm2m_watcher_t * watcherList;
terencez 0:c2dff8cbb91a 616 } lwm2m_observed_t;
terencez 0:c2dff8cbb91a 617
terencez 0:c2dff8cbb91a 618 #ifdef LWM2M_CLIENT_MODE
terencez 0:c2dff8cbb91a 619
terencez 0:c2dff8cbb91a 620 typedef enum
terencez 0:c2dff8cbb91a 621 {
terencez 0:c2dff8cbb91a 622 STATE_INITIAL = 0,
terencez 0:c2dff8cbb91a 623 STATE_BOOTSTRAP_REQUIRED,
terencez 0:c2dff8cbb91a 624 STATE_BOOTSTRAPPING,
terencez 0:c2dff8cbb91a 625 STATE_REGISTER_REQUIRED,
terencez 0:c2dff8cbb91a 626 STATE_REGISTERING,
terencez 0:c2dff8cbb91a 627 STATE_READY
terencez 0:c2dff8cbb91a 628 } lwm2m_client_state_t;
terencez 0:c2dff8cbb91a 629
terencez 0:c2dff8cbb91a 630 #endif
terencez 0:c2dff8cbb91a 631 /*
terencez 0:c2dff8cbb91a 632 * LWM2M Context
terencez 0:c2dff8cbb91a 633 */
terencez 0:c2dff8cbb91a 634
terencez 0:c2dff8cbb91a 635 #ifdef LWM2M_BOOTSTRAP_SERVER_MODE
terencez 0:c2dff8cbb91a 636 // In all the following APIs, the session handle MUST uniquely identify a peer.
terencez 0:c2dff8cbb91a 637
terencez 0:c2dff8cbb91a 638 // LWM2M bootstrap callback
terencez 0:c2dff8cbb91a 639 // When a LWM2M client requests bootstrap information, the callback is called with status COAP_NO_ERROR, uriP is nil and
terencez 0:c2dff8cbb91a 640 // name is set. The callback must return a COAP_* error code. COAP_204_CHANGED for success.
terencez 0:c2dff8cbb91a 641 // After a lwm2m_bootstrap_delete() or a lwm2m_bootstrap_write(), the callback is called with the status returned by the
terencez 0:c2dff8cbb91a 642 // client, the URI of the operation (may be nil) and name is nil. The callback return value is ignored.
terencez 0:c2dff8cbb91a 643 typedef int (*lwm2m_bootstrap_callback_t) (void * sessionH, uint8_t status, lwm2m_uri_t * uriP, char * name, void * userData);
terencez 0:c2dff8cbb91a 644 #endif
terencez 0:c2dff8cbb91a 645
terencez 0:c2dff8cbb91a 646 typedef struct
terencez 0:c2dff8cbb91a 647 {
terencez 0:c2dff8cbb91a 648 #ifdef LWM2M_CLIENT_MODE
terencez 0:c2dff8cbb91a 649 lwm2m_client_state_t state;
terencez 0:c2dff8cbb91a 650 char * endpointName;
terencez 0:c2dff8cbb91a 651 char * msisdn;
terencez 0:c2dff8cbb91a 652 char * altPath;
terencez 0:c2dff8cbb91a 653 lwm2m_server_t * bootstrapServerList;
terencez 0:c2dff8cbb91a 654 lwm2m_server_t * serverList;
terencez 0:c2dff8cbb91a 655 lwm2m_object_t * objectList;
terencez 0:c2dff8cbb91a 656 lwm2m_observed_t * observedList;
terencez 0:c2dff8cbb91a 657 #endif
terencez 0:c2dff8cbb91a 658 #ifdef LWM2M_SERVER_MODE
terencez 0:c2dff8cbb91a 659 lwm2m_client_t * clientList;
terencez 0:c2dff8cbb91a 660 lwm2m_result_callback_t monitorCallback;
terencez 0:c2dff8cbb91a 661 void * monitorUserData;
terencez 0:c2dff8cbb91a 662 #endif
terencez 0:c2dff8cbb91a 663 #ifdef LWM2M_BOOTSTRAP_SERVER_MODE
terencez 0:c2dff8cbb91a 664 lwm2m_bootstrap_callback_t bootstrapCallback;
terencez 0:c2dff8cbb91a 665 void * bootstrapUserData;
terencez 0:c2dff8cbb91a 666 #endif
terencez 0:c2dff8cbb91a 667 uint16_t nextMID;
terencez 0:c2dff8cbb91a 668 lwm2m_transaction_t * transactionList;
terencez 0:c2dff8cbb91a 669 void * userData;
terencez 0:c2dff8cbb91a 670 } lwm2m_context_t;
terencez 0:c2dff8cbb91a 671
terencez 0:c2dff8cbb91a 672
terencez 0:c2dff8cbb91a 673 // initialize a liblwm2m context.
terencez 0:c2dff8cbb91a 674 lwm2m_context_t * lwm2m_init(void * userData);
terencez 0:c2dff8cbb91a 675 // close a liblwm2m context.
terencez 0:c2dff8cbb91a 676 void lwm2m_close(lwm2m_context_t * contextP);
terencez 0:c2dff8cbb91a 677
terencez 0:c2dff8cbb91a 678 // perform any required pending operation and adjust timeoutP to the maximal time interval to wait in seconds.
terencez 0:c2dff8cbb91a 679 int lwm2m_step(lwm2m_context_t * contextP, time_t * timeoutP);
terencez 0:c2dff8cbb91a 680 // dispatch received data to liblwm2m
terencez 0:c2dff8cbb91a 681 void lwm2m_handle_packet(lwm2m_context_t * contextP, uint8_t * buffer, int length, void * fromSessionH);
terencez 0:c2dff8cbb91a 682
terencez 0:c2dff8cbb91a 683 #ifdef LWM2M_CLIENT_MODE
terencez 0:c2dff8cbb91a 684 // configure the client side with the Endpoint Name, binding, MSISDN (can be nil), alternative path
terencez 0:c2dff8cbb91a 685 // for objects (can be nil) and a list of objects.
terencez 0:c2dff8cbb91a 686 // LWM2M Security Object (ID 0) must be present with either a bootstrap server or a LWM2M server and
terencez 0:c2dff8cbb91a 687 // its matching LWM2M Server Object (ID 1) instance
terencez 0:c2dff8cbb91a 688 int lwm2m_configure(lwm2m_context_t * contextP, const char * endpointName, const char * msisdn, const char * altPath, uint16_t numObject, lwm2m_object_t * objectList[]);
terencez 0:c2dff8cbb91a 689 int lwm2m_add_object(lwm2m_context_t * contextP, lwm2m_object_t * objectP);
terencez 0:c2dff8cbb91a 690 int lwm2m_remove_object(lwm2m_context_t * contextP, uint16_t id);
terencez 0:c2dff8cbb91a 691
terencez 0:c2dff8cbb91a 692 // send a registration update to the server specified by the server short identifier
terencez 0:c2dff8cbb91a 693 // or all if the ID is 0.
terencez 0:c2dff8cbb91a 694 // If withObjects is true, the registration update contains the object list.
terencez 0:c2dff8cbb91a 695 int lwm2m_update_registration(lwm2m_context_t * contextP, uint16_t shortServerID, bool withObjects);
terencez 0:c2dff8cbb91a 696
terencez 0:c2dff8cbb91a 697 void lwm2m_resource_value_changed(lwm2m_context_t * contextP, lwm2m_uri_t * uriP);
terencez 0:c2dff8cbb91a 698 #endif
terencez 0:c2dff8cbb91a 699
terencez 0:c2dff8cbb91a 700 #ifdef LWM2M_SERVER_MODE
terencez 0:c2dff8cbb91a 701 // Clients registration/deregistration monitoring API.
terencez 0:c2dff8cbb91a 702 // When a LWM2M client registers, the callback is called with status COAP_201_CREATED.
terencez 0:c2dff8cbb91a 703 // When a LWM2M client deregisters, the callback is called with status COAP_202_DELETED.
terencez 0:c2dff8cbb91a 704 // clientID is the internal ID of the LWM2M Client.
terencez 0:c2dff8cbb91a 705 // The callback's parameters uri, data, dataLength are always NULL.
terencez 0:c2dff8cbb91a 706 // The lwm2m_client_t is present in the lwm2m_context_t's clientList when the callback is called. On a deregistration, it deleted when the callback returns.
terencez 0:c2dff8cbb91a 707 void lwm2m_set_monitoring_callback(lwm2m_context_t * contextP, lwm2m_result_callback_t callback, void * userData);
terencez 0:c2dff8cbb91a 708
terencez 0:c2dff8cbb91a 709 // Device Management APIs
terencez 0:c2dff8cbb91a 710 int lwm2m_dm_read(lwm2m_context_t * contextP, uint16_t clientID, lwm2m_uri_t * uriP, lwm2m_result_callback_t callback, void * userData);
terencez 0:c2dff8cbb91a 711 int lwm2m_dm_discover(lwm2m_context_t * contextP, uint16_t clientID, lwm2m_uri_t * uriP, lwm2m_result_callback_t callback, void * userData);
terencez 0:c2dff8cbb91a 712 int lwm2m_dm_write(lwm2m_context_t * contextP, uint16_t clientID, lwm2m_uri_t * uriP, lwm2m_media_type_t format, uint8_t * buffer, int length, lwm2m_result_callback_t callback, void * userData);
terencez 0:c2dff8cbb91a 713 int lwm2m_dm_write_attributes(lwm2m_context_t * contextP, uint16_t clientID, lwm2m_uri_t * uriP, lwm2m_attributes_t * attrP, lwm2m_result_callback_t callback, void * userData);
terencez 0:c2dff8cbb91a 714 int lwm2m_dm_execute(lwm2m_context_t * contextP, uint16_t clientID, lwm2m_uri_t * uriP, lwm2m_media_type_t format, uint8_t * buffer, int length, lwm2m_result_callback_t callback, void * userData);
terencez 0:c2dff8cbb91a 715 int lwm2m_dm_create(lwm2m_context_t * contextP, uint16_t clientID, lwm2m_uri_t * uriP, lwm2m_media_type_t format, uint8_t * buffer, int length, lwm2m_result_callback_t callback, void * userData);
terencez 0:c2dff8cbb91a 716 int lwm2m_dm_delete(lwm2m_context_t * contextP, uint16_t clientID, lwm2m_uri_t * uriP, lwm2m_result_callback_t callback, void * userData);
terencez 0:c2dff8cbb91a 717
terencez 0:c2dff8cbb91a 718 // Information Reporting APIs
terencez 0:c2dff8cbb91a 719 int lwm2m_observe(lwm2m_context_t * contextP, uint16_t clientID, lwm2m_uri_t * uriP, lwm2m_result_callback_t callback, void * userData);
terencez 0:c2dff8cbb91a 720 int lwm2m_observe_cancel(lwm2m_context_t * contextP, uint16_t clientID, lwm2m_uri_t * uriP, lwm2m_result_callback_t callback, void * userData);
terencez 0:c2dff8cbb91a 721 #endif
terencez 0:c2dff8cbb91a 722
terencez 0:c2dff8cbb91a 723 #ifdef LWM2M_BOOTSTRAP_SERVER_MODE
terencez 0:c2dff8cbb91a 724 // Clients bootstrap request monitoring API.
terencez 0:c2dff8cbb91a 725 // When a LWM2M client sends a bootstrap request, the callback is called with the client's endpoint name.
terencez 0:c2dff8cbb91a 726 void lwm2m_set_bootstrap_callback(lwm2m_context_t * contextP, lwm2m_bootstrap_callback_t callback, void * userData);
terencez 0:c2dff8cbb91a 727
terencez 0:c2dff8cbb91a 728 // Boostrap Interface APIs
terencez 0:c2dff8cbb91a 729 // if uriP is nil, a "Delete /" is sent to the client
terencez 0:c2dff8cbb91a 730 int lwm2m_bootstrap_delete(lwm2m_context_t * contextP, void * sessionH, lwm2m_uri_t * uriP);
terencez 0:c2dff8cbb91a 731 int lwm2m_bootstrap_write(lwm2m_context_t * contextP, void * sessionH, lwm2m_uri_t * uriP, lwm2m_media_type_t format, uint8_t * buffer, size_t length);
terencez 0:c2dff8cbb91a 732 int lwm2m_bootstrap_finish(lwm2m_context_t * contextP, void * sessionH);
terencez 0:c2dff8cbb91a 733
terencez 0:c2dff8cbb91a 734 #endif
terencez 0:c2dff8cbb91a 735
terencez 0:c2dff8cbb91a 736 #ifdef __cplusplus
terencez 0:c2dff8cbb91a 737 }
terencez 0:c2dff8cbb91a 738 #endif
terencez 0:c2dff8cbb91a 739
terencez 0:c2dff8cbb91a 740 #endif