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