1 /* 2 * Copyright (c) 2017 Linaro Limited 3 * Copyright (c) 2017-2019 Foundries.io 4 * 5 * SPDX-License-Identifier: Apache-2.0 6 */ 7 8 /** @file lwm2m.h 9 * 10 * @defgroup lwm2m_api LwM2M high-level API 11 * @ingroup networking 12 * @{ 13 * @brief LwM2M high-level API 14 * 15 * @details 16 * LwM2M high-level interface is defined in this header. 17 * 18 * @note The implementation assumes UDP module is enabled. 19 * 20 * @note For more information refer to Technical Specification 21 * OMA-TS-LightweightM2M_Core-V1_1_1-20190617-A 22 */ 23 24 #ifndef ZEPHYR_INCLUDE_NET_LWM2M_H_ 25 #define ZEPHYR_INCLUDE_NET_LWM2M_H_ 26 27 #include <time.h> 28 #include <zephyr/kernel.h> 29 #include <zephyr/sys/mutex.h> 30 #include <zephyr/net/coap.h> 31 #include <zephyr/net/lwm2m_path.h> 32 33 /** 34 * @name LwM2M Objects managed by OMA for LwM2M tech specification. 35 * Objects in this range have IDs from 0 to 1023. 36 * @{ 37 */ 38 39 /* clang-format off */ 40 #define LWM2M_OBJECT_SECURITY_ID 0 /**< Security object */ 41 #define LWM2M_OBJECT_SERVER_ID 1 /**< Server object */ 42 #define LWM2M_OBJECT_ACCESS_CONTROL_ID 2 /**< Access Control object */ 43 #define LWM2M_OBJECT_DEVICE_ID 3 /**< Device object */ 44 #define LWM2M_OBJECT_CONNECTIVITY_MONITORING_ID 4 /**< Connectivity Monitoring object */ 45 #define LWM2M_OBJECT_FIRMWARE_ID 5 /**< Firmware object */ 46 #define LWM2M_OBJECT_LOCATION_ID 6 /**< Location object */ 47 #define LWM2M_OBJECT_CONNECTIVITY_STATISTICS_ID 7 /**< Connectivity Statistics object */ 48 #define LWM2M_OBJECT_SOFTWARE_MANAGEMENT_ID 9 /**< Software Management object */ 49 #define LWM2M_OBJECT_PORTFOLIO_ID 16 /**< Portfolio object */ 50 #define LWM2M_OBJECT_BINARYAPPDATACONTAINER_ID 19 /**< Binary App Data Container object */ 51 #define LWM2M_OBJECT_EVENT_LOG_ID 20 /**< Event Log object */ 52 #define LWM2M_OBJECT_OSCORE_ID 21 /**< OSCORE object */ 53 #define LWM2M_OBJECT_GATEWAY_ID 25 /**< Gateway object */ 54 /* clang-format on */ 55 56 /** @} */ 57 58 /** 59 * @name LwM2M Objects produced by 3rd party Standards Development 60 * Organizations. 61 * Refer to the OMA LightweightM2M (LwM2M) Object and Resource Registry: 62 * http://www.openmobilealliance.org/wp/OMNA/LwM2M/LwM2MRegistry.html 63 * @{ 64 */ 65 66 /* clang-format off */ 67 #define IPSO_OBJECT_GENERIC_SENSOR_ID 3300 /**< IPSO Generic Sensor object */ 68 #define IPSO_OBJECT_TEMP_SENSOR_ID 3303 /**< IPSO Temperature Sensor object */ 69 #define IPSO_OBJECT_HUMIDITY_SENSOR_ID 3304 /**< IPSO Humidity Sensor object */ 70 #define IPSO_OBJECT_LIGHT_CONTROL_ID 3311 /**< IPSO Light Control object */ 71 #define IPSO_OBJECT_ACCELEROMETER_ID 3313 /**< IPSO Accelerometer object */ 72 #define IPSO_OBJECT_VOLTAGE_SENSOR_ID 3316 /**< IPSO Voltage Sensor object */ 73 #define IPSO_OBJECT_CURRENT_SENSOR_ID 3317 /**< IPSO Current Sensor object */ 74 #define IPSO_OBJECT_PRESSURE_ID 3323 /**< IPSO Pressure Sensor object */ 75 #define IPSO_OBJECT_BUZZER_ID 3338 /**< IPSO Buzzer object */ 76 #define IPSO_OBJECT_TIMER_ID 3340 /**< IPSO Timer object */ 77 #define IPSO_OBJECT_ONOFF_SWITCH_ID 3342 /**< IPSO On/Off Switch object */ 78 #define IPSO_OBJECT_PUSH_BUTTON_ID 3347 /**< IPSO Push Button object */ 79 #define UCIFI_OBJECT_BATTERY_ID 3411 /**< uCIFI Battery object */ 80 #define IPSO_OBJECT_FILLING_LEVEL_SENSOR_ID 3435 /**< IPSO Filling Level Sensor object */ 81 /* clang-format on */ 82 83 /** @} */ 84 85 /** 86 * @brief Callback function called when a socket error is encountered 87 * 88 * @param error Error code 89 */ 90 typedef void (*lwm2m_socket_fault_cb_t)(int error); 91 92 /** @brief LwM2M object path structure */ 93 struct lwm2m_obj_path { 94 uint16_t obj_id; /**< Object ID */ 95 uint16_t obj_inst_id; /**< Object instance ID */ 96 uint16_t res_id; /**< Resource ID */ 97 uint16_t res_inst_id; /**< Resource instance ID */ 98 uint8_t level; /**< Path level (0-4). Ex. 4 = resource instance. */ 99 }; 100 101 /** 102 * @brief Observe callback events 103 */ 104 enum lwm2m_observe_event { 105 LWM2M_OBSERVE_EVENT_OBSERVER_ADDED, /**< Observer added */ 106 LWM2M_OBSERVE_EVENT_OBSERVER_REMOVED, /**< Observer removed */ 107 LWM2M_OBSERVE_EVENT_NOTIFY_ACK, /**< Notification ACKed */ 108 LWM2M_OBSERVE_EVENT_NOTIFY_TIMEOUT, /**< Notification timed out */ 109 }; 110 111 /** 112 * @brief Observe callback indicating observer adds and deletes, and 113 * notification ACKs and timeouts 114 * 115 * @param[in] event Observer add/delete or notification ack/timeout 116 * @param[in] path LwM2M path 117 * @param[in] user_data Pointer to user_data buffer, as provided in 118 * send_traceable_notification(). Used to determine for which 119 * data the ACKed/timed out notification was. 120 */ 121 typedef void (*lwm2m_observe_cb_t)(enum lwm2m_observe_event event, struct lwm2m_obj_path *path, 122 void *user_data); 123 124 125 struct lwm2m_ctx; 126 enum lwm2m_rd_client_event; 127 /** 128 * @brief Asynchronous RD client event callback 129 * 130 * @param[in] ctx LwM2M context generating the event 131 * @param[in] event LwM2M RD client event code 132 */ 133 typedef void (*lwm2m_ctx_event_cb_t)(struct lwm2m_ctx *ctx, 134 enum lwm2m_rd_client_event event); 135 136 137 /** 138 * @brief Different traffic states of the LwM2M socket. 139 * 140 * This information can be used to give hints for the network interface 141 * that can decide what kind of power management should be used. 142 * 143 * These hints are given from CoAP layer messages, so usage of DTLS might affect the 144 * actual number of expected datagrams. 145 */ 146 enum lwm2m_socket_states { 147 LWM2M_SOCKET_STATE_ONGOING, /**< Ongoing traffic is expected. */ 148 LWM2M_SOCKET_STATE_ONE_RESPONSE, /**< One response is expected for the next message. */ 149 LWM2M_SOCKET_STATE_LAST, /**< Next message is the last one. */ 150 LWM2M_SOCKET_STATE_NO_DATA, /**< No more data is expected. */ 151 }; 152 153 /** 154 * @brief LwM2M context structure to maintain information for a single 155 * LwM2M connection. 156 */ 157 struct lwm2m_ctx { 158 /** Destination address storage */ 159 struct sockaddr remote_addr; 160 161 /** @cond INTERNAL_HIDDEN 162 * Private CoAP and networking structures + 1 is for RD Client own message 163 */ 164 struct coap_pending pendings[CONFIG_LWM2M_ENGINE_MAX_PENDING + 1]; 165 struct coap_reply replies[CONFIG_LWM2M_ENGINE_MAX_REPLIES + 1]; 166 sys_slist_t pending_sends; 167 #if defined(CONFIG_LWM2M_QUEUE_MODE_ENABLED) 168 sys_slist_t queued_messages; 169 #endif 170 sys_slist_t observer; 171 /** @endcond */ 172 173 /** A pointer to currently processed request, for internal LwM2M engine 174 * use. The underlying type is ``struct lwm2m_message``, but since it's 175 * declared in a private header and not exposed to the application, 176 * it's stored as a void pointer. 177 */ 178 void *processed_req; 179 180 #if defined(CONFIG_LWM2M_DTLS_SUPPORT) || defined(__DOXYGEN__) 181 /** 182 * @name DTLS related information 183 * Available only when @kconfig{CONFIG_LWM2M_DTLS_SUPPORT} is enabled and 184 * @ref lwm2m_ctx.use_dtls is set to true. 185 * @{ 186 */ 187 /** TLS tag is set by client as a reference used when the 188 * LwM2M engine calls tls_credential_(add|delete) 189 */ 190 int tls_tag; 191 192 /** Destination hostname. 193 * When MBEDTLS SNI is enabled socket must be set with destination 194 * server hostname. 195 */ 196 char *desthostname; 197 /** Destination hostname length */ 198 uint16_t desthostnamelen; 199 /** Flag to indicate if hostname verification is enabled */ 200 bool hostname_verify; 201 202 /** Custom load_credentials function. 203 * Client can set load_credentials function as a way of overriding 204 * the default behavior of load_tls_credential() in lwm2m_engine.c 205 */ 206 int (*load_credentials)(struct lwm2m_ctx *client_ctx); 207 /** @} */ 208 #endif 209 /** Custom socket options. 210 * Client can override default socket options by providing 211 * a callback that is called afer a socket is created and before 212 * connect. 213 */ 214 int (*set_socketoptions)(struct lwm2m_ctx *client_ctx); 215 216 /** Flag to indicate if context should use DTLS. 217 * Enabled via the use of coaps:// protocol prefix in connection 218 * information. 219 * NOTE: requires @kconfig{CONFIG_LWM2M_DTLS_SUPPORT} 220 */ 221 bool use_dtls; 222 223 /** 224 * Flag to indicate that the socket connection is suspended. 225 * With queue mode, this will tell if there is a need to reconnect. 226 */ 227 bool connection_suspended; 228 229 #if defined(CONFIG_LWM2M_QUEUE_MODE_ENABLED) || defined(__DOXYGEN__) 230 /** 231 * Flag to indicate that the client is buffering Notifications and Send messages. 232 * True value buffer Notifications and Send messages. 233 */ 234 bool buffer_client_messages; 235 #endif 236 /** Current index of Security Object used for server credentials */ 237 int sec_obj_inst; 238 239 /** Current index of Server Object used in this context. */ 240 int srv_obj_inst; 241 242 /** Flag to enable BOOTSTRAP interface. See Section "Bootstrap Interface" 243 * of LwM2M Technical Specification for more information. 244 */ 245 bool bootstrap_mode; 246 247 /** Socket File Descriptor */ 248 int sock_fd; 249 250 /** Socket fault callback. LwM2M processing thread will call this 251 * callback in case of socket errors on receive. 252 */ 253 lwm2m_socket_fault_cb_t fault_cb; 254 255 /** Callback for new or cancelled observations, and acknowledged or timed 256 * out notifications. 257 */ 258 lwm2m_observe_cb_t observe_cb; 259 260 /** Callback for client events */ 261 lwm2m_ctx_event_cb_t event_cb; 262 263 /** Validation buffer. Used as a temporary buffer to decode the resource 264 * value before validation. On successful validation, its content is 265 * copied into the actual resource buffer. 266 */ 267 uint8_t validate_buf[CONFIG_LWM2M_ENGINE_VALIDATION_BUFFER_SIZE]; 268 269 /** 270 * Callback to indicate transmission states. 271 * Client application may request LwM2M engine to indicate hints about 272 * transmission states and use that information to control various power 273 * saving modes. 274 */ 275 void (*set_socket_state)(int fd, enum lwm2m_socket_states state); 276 }; 277 278 /** 279 * LwM2M Time series data structure 280 */ 281 struct lwm2m_time_series_elem { 282 /** Cached data Unix timestamp */ 283 time_t t; 284 union { 285 uint8_t u8; 286 uint16_t u16; 287 uint32_t u32; 288 uint64_t u64; 289 int8_t i8; 290 int16_t i16; 291 int32_t i32; 292 int64_t i64; 293 time_t time; 294 double f; 295 bool b; 296 }; 297 }; 298 299 /** 300 * @brief Asynchronous callback to get a resource buffer and length. 301 * 302 * Prior to accessing the data buffer of a resource, the engine can 303 * use this callback to get the buffer pointer and length instead 304 * of using the resource's data buffer. 305 * 306 * The client or LwM2M objects can register a function of this type via: 307 * lwm2m_engine_register_read_callback() 308 * lwm2m_engine_register_pre_write_callback() 309 * 310 * @param[in] obj_inst_id Object instance ID generating the callback. 311 * @param[in] res_id Resource ID generating the callback. 312 * @param[in] res_inst_id Resource instance ID generating the callback 313 * (typically 0 for non-multi instance resources). 314 * @param[out] data_len Length of the data buffer. 315 * 316 * @return Callback returns a pointer to the data buffer or NULL for failure. 317 */ 318 typedef void *(*lwm2m_engine_get_data_cb_t)(uint16_t obj_inst_id, 319 uint16_t res_id, 320 uint16_t res_inst_id, 321 size_t *data_len); 322 323 /** 324 * @brief Asynchronous callback when data has been set to a resource buffer. 325 * 326 * After changing the data of a resource buffer, the LwM2M engine can 327 * make use of this callback to pass the data back to the client or LwM2M 328 * objects. 329 * 330 * A function of this type can be registered via: 331 * lwm2m_engine_register_validate_callback() 332 * lwm2m_engine_register_post_write_callback() 333 * 334 * @param[in] obj_inst_id Object instance ID generating the callback. 335 * @param[in] res_id Resource ID generating the callback. 336 * @param[in] res_inst_id Resource instance ID generating the callback 337 * (typically 0 for non-multi instance resources). 338 * @param[in] data Pointer to data. 339 * @param[in] data_len Length of the data. 340 * @param[in] last_block Flag used during block transfer to indicate the last 341 * block of data. For non-block transfers this is always 342 * false. 343 * @param[in] total_size Expected total size of data for a block transfer. 344 * For non-block transfers this is 0. 345 * 346 * @return Callback returns a negative error code (errno.h) indicating 347 * reason of failure or 0 for success. 348 */ 349 typedef int (*lwm2m_engine_set_data_cb_t)(uint16_t obj_inst_id, 350 uint16_t res_id, uint16_t res_inst_id, 351 uint8_t *data, uint16_t data_len, 352 bool last_block, size_t total_size); 353 354 /** 355 * @brief Asynchronous event notification callback. 356 * 357 * Various object instance and resource-based events in the LwM2M engine 358 * can trigger a callback of this function type: object instance create, 359 * and object instance delete. 360 * 361 * Register a function of this type via: 362 * lwm2m_engine_register_create_callback() 363 * lwm2m_engine_register_delete_callback() 364 * 365 * @param[in] obj_inst_id Object instance ID generating the callback. 366 * 367 * @return Callback returns a negative error code (errno.h) indicating 368 * reason of failure or 0 for success. 369 */ 370 typedef int (*lwm2m_engine_user_cb_t)(uint16_t obj_inst_id); 371 372 /** 373 * @brief Asynchronous execute notification callback. 374 * 375 * Resource executes trigger a callback of this type. 376 * 377 * Register a function of this type via: 378 * lwm2m_engine_register_exec_callback() 379 * 380 * @param[in] obj_inst_id Object instance ID generating the callback. 381 * @param[in] args Pointer to execute arguments payload. (This can be 382 * NULL if no arguments are provided) 383 * @param[in] args_len Length of argument payload in bytes. 384 * 385 * @return Callback returns a negative error code (errno.h) indicating 386 * reason of failure or 0 for success. 387 */ 388 typedef int (*lwm2m_engine_execute_cb_t)(uint16_t obj_inst_id, 389 uint8_t *args, uint16_t args_len); 390 391 /** 392 * @name Power source types used for the "Available Power Sources" resource of 393 * the LwM2M Device object (3/0/6). 394 * @{ 395 */ 396 #define LWM2M_DEVICE_PWR_SRC_TYPE_DC_POWER 0 /**< DC power */ 397 #define LWM2M_DEVICE_PWR_SRC_TYPE_BAT_INT 1 /**< Internal battery */ 398 #define LWM2M_DEVICE_PWR_SRC_TYPE_BAT_EXT 2 /**< External battery */ 399 #define LWM2M_DEVICE_PWR_SRC_TYPE_FUEL_CELL 3 /**< Fuel cell */ 400 #define LWM2M_DEVICE_PWR_SRC_TYPE_PWR_OVER_ETH 4 /**< Power over Ethernet */ 401 #define LWM2M_DEVICE_PWR_SRC_TYPE_USB 5 /**< USB */ 402 #define LWM2M_DEVICE_PWR_SRC_TYPE_AC_POWER 6 /**< AC (mains) power */ 403 #define LWM2M_DEVICE_PWR_SRC_TYPE_SOLAR 7 /**< Solar */ 404 #define LWM2M_DEVICE_PWR_SRC_TYPE_MAX 8 /**< Max value for Available Power Source type */ 405 /** @} */ 406 407 /** 408 * @name Error codes used for the "Error Code" resource of the LwM2M Device 409 * object. 410 * An LwM2M client can register one of the following error codes via 411 * the lwm2m_device_add_err() function. 412 * @{ 413 */ 414 #define LWM2M_DEVICE_ERROR_NONE 0 /**< No error */ 415 #define LWM2M_DEVICE_ERROR_LOW_POWER 1 /**< Low battery power */ 416 #define LWM2M_DEVICE_ERROR_EXT_POWER_SUPPLY_OFF 2 /**< External power supply off */ 417 #define LWM2M_DEVICE_ERROR_GPS_FAILURE 3 /**< GPS module failure */ 418 #define LWM2M_DEVICE_ERROR_LOW_SIGNAL_STRENGTH 4 /**< Low received signal strength */ 419 #define LWM2M_DEVICE_ERROR_OUT_OF_MEMORY 5 /**< Out of memory */ 420 #define LWM2M_DEVICE_ERROR_SMS_FAILURE 6 /**< SMS failure */ 421 #define LWM2M_DEVICE_ERROR_NETWORK_FAILURE 7 /**< IP Connectivity failure */ 422 #define LWM2M_DEVICE_ERROR_PERIPHERAL_FAILURE 8 /**< Peripheral malfunction */ 423 424 /** @} */ 425 426 /** 427 * @name Battery status codes used for the "Battery Status" resource (3/0/20) 428 * of the LwM2M Device object. As the battery status changes, an LwM2M 429 * client can set one of the following codes via: 430 * lwm2m_engine_set_u8("3/0/20", [battery status]) 431 * @{ 432 */ 433 #define LWM2M_DEVICE_BATTERY_STATUS_NORMAL 0 /**< The battery is operating normally and not on 434 * power 435 */ 436 #define LWM2M_DEVICE_BATTERY_STATUS_CHARGING 1 /**< The battery is currently charging */ 437 #define LWM2M_DEVICE_BATTERY_STATUS_CHARGE_COMP 2 /**< The battery is fully charged and the charger 438 * is still connected 439 */ 440 #define LWM2M_DEVICE_BATTERY_STATUS_DAMAGED 3 /**< The battery has some problem */ 441 #define LWM2M_DEVICE_BATTERY_STATUS_LOW 4 /**< The battery is low on charge */ 442 #define LWM2M_DEVICE_BATTERY_STATUS_NOT_INST 5 /**< The battery is not installed */ 443 #define LWM2M_DEVICE_BATTERY_STATUS_UNKNOWN 6 /**< The battery information is not available */ 444 445 /** @} */ 446 447 /** 448 * @brief Register a new error code with LwM2M Device object. 449 * 450 * @param[in] error_code New error code. 451 * 452 * @return 0 for success or negative in case of error. 453 */ 454 int lwm2m_device_add_err(uint8_t error_code); 455 456 457 /** 458 * @name LWM2M Firmware Update object states 459 * 460 * An LwM2M client or the LwM2M Firmware Update object use the following codes 461 * to represent the LwM2M Firmware Update state (5/0/3). 462 * @{ 463 */ 464 465 /** 466 * Idle. Before downloading or after successful updating. 467 */ 468 #define STATE_IDLE 0 469 /** 470 * Downloading. The data sequence is being downloaded. 471 */ 472 #define STATE_DOWNLOADING 1 473 /** 474 * Downloaded. The whole data sequence has been downloaded. 475 */ 476 #define STATE_DOWNLOADED 2 477 /** 478 * Updating. The device is being updated. 479 */ 480 #define STATE_UPDATING 3 481 482 /** @} */ 483 484 /** 485 * @name LWM2M Firmware Update object result codes 486 * 487 * After processing a firmware update, the client sets the result via one of 488 * the following codes via lwm2m_engine_set_u8("5/0/5", [result code]) 489 * @{ 490 */ 491 492 #define RESULT_DEFAULT 0 /**< Initial value */ 493 #define RESULT_SUCCESS 1 /**< Firmware updated successfully */ 494 #define RESULT_NO_STORAGE 2 /**< Not enough flash memory for the new firmware package */ 495 #define RESULT_OUT_OF_MEM 3 /**< Out of RAM during downloading process */ 496 #define RESULT_CONNECTION_LOST 4 /**< Connection lost during downloading process */ 497 #define RESULT_INTEGRITY_FAILED 5 /**< Integrity check failure for new downloaded package */ 498 #define RESULT_UNSUP_FW 6 /**< Unsupported package type */ 499 #define RESULT_INVALID_URI 7 /**< Invalid URI */ 500 #define RESULT_UPDATE_FAILED 8 /**< Firmware update failed */ 501 #define RESULT_UNSUP_PROTO 9 /**< Unsupported protocol */ 502 503 /** @} */ 504 505 #if defined(CONFIG_LWM2M_FIRMWARE_UPDATE_OBJ_SUPPORT) || defined(__DOXYGEN__) 506 /** 507 * @brief Set data callback for firmware block transfer. 508 * 509 * LwM2M clients use this function to register a callback for receiving the 510 * block transfer data when performing a firmware update. 511 * 512 * @param[in] cb A callback function to receive the block transfer data 513 */ 514 void lwm2m_firmware_set_write_cb(lwm2m_engine_set_data_cb_t cb); 515 516 /** 517 * @brief Get the data callback for firmware block transfer writes. 518 * 519 * @return A registered callback function to receive the block transfer data 520 */ 521 lwm2m_engine_set_data_cb_t lwm2m_firmware_get_write_cb(void); 522 523 /** 524 * @brief Set data callback for firmware block transfer. 525 * 526 * LwM2M clients use this function to register a callback for receiving the 527 * block transfer data when performing a firmware update. 528 * 529 * @param[in] obj_inst_id Object instance ID 530 * @param[in] cb A callback function to receive the block transfer data 531 */ 532 void lwm2m_firmware_set_write_cb_inst(uint16_t obj_inst_id, lwm2m_engine_set_data_cb_t cb); 533 534 /** 535 * @brief Get the data callback for firmware block transfer writes. 536 * 537 * @param[in] obj_inst_id Object instance ID 538 * @return A registered callback function to receive the block transfer data 539 */ 540 lwm2m_engine_set_data_cb_t lwm2m_firmware_get_write_cb_inst(uint16_t obj_inst_id); 541 542 /** 543 * @brief Set callback for firmware update cancel. 544 * 545 * LwM2M clients use this function to register a callback to perform actions 546 * on firmware update cancel. 547 * 548 * @param[in] cb A callback function perform actions on firmware update cancel. 549 */ 550 void lwm2m_firmware_set_cancel_cb(lwm2m_engine_user_cb_t cb); 551 552 /** 553 * @brief Get a callback for firmware update cancel. 554 * 555 * @return A registered callback function perform actions on firmware update cancel. 556 */ 557 lwm2m_engine_user_cb_t lwm2m_firmware_get_cancel_cb(void); 558 559 /** 560 * @brief Set data callback for firmware update cancel. 561 * 562 * LwM2M clients use this function to register a callback to perform actions 563 * on firmware update cancel. 564 * 565 * @param[in] obj_inst_id Object instance ID 566 * @param[in] cb A callback function perform actions on firmware update cancel. 567 */ 568 void lwm2m_firmware_set_cancel_cb_inst(uint16_t obj_inst_id, lwm2m_engine_user_cb_t cb); 569 570 /** 571 * @brief Get the callback for firmware update cancel. 572 * 573 * @param[in] obj_inst_id Object instance ID 574 * @return A registered callback function perform actions on firmware update cancel. 575 */ 576 lwm2m_engine_user_cb_t lwm2m_firmware_get_cancel_cb_inst(uint16_t obj_inst_id); 577 578 /** 579 * @brief Set data callback to handle firmware update execute events. 580 * 581 * LwM2M clients use this function to register a callback for receiving the 582 * update resource "execute" operation on the LwM2M Firmware Update object. 583 * 584 * @param[in] cb A callback function to receive the execute event. 585 */ 586 void lwm2m_firmware_set_update_cb(lwm2m_engine_execute_cb_t cb); 587 588 /** 589 * @brief Get the event callback for firmware update execute events. 590 * 591 * @return A registered callback function to receive the execute event. 592 */ 593 lwm2m_engine_execute_cb_t lwm2m_firmware_get_update_cb(void); 594 595 /** 596 * @brief Set data callback to handle firmware update execute events. 597 * 598 * LwM2M clients use this function to register a callback for receiving the 599 * update resource "execute" operation on the LwM2M Firmware Update object. 600 * 601 * @param[in] obj_inst_id Object instance ID 602 * @param[in] cb A callback function to receive the execute event. 603 */ 604 void lwm2m_firmware_set_update_cb_inst(uint16_t obj_inst_id, lwm2m_engine_execute_cb_t cb); 605 606 /** 607 * @brief Get the event callback for firmware update execute events. 608 * 609 * @param[in] obj_inst_id Object instance ID 610 * @return A registered callback function to receive the execute event. 611 */ 612 lwm2m_engine_execute_cb_t lwm2m_firmware_get_update_cb_inst(uint16_t obj_inst_id); 613 #endif 614 615 #if defined(CONFIG_LWM2M_SWMGMT_OBJ_SUPPORT) || defined(__DOXYGEN__) 616 617 /** 618 * @brief Set callback to handle software activation requests 619 * 620 * The callback will be executed when the LWM2M execute operation gets called 621 * on the corresponding object's Activate resource instance. 622 * 623 * @param[in] obj_inst_id The instance number to set the callback for. 624 * @param[in] cb A callback function to receive the execute event. 625 * 626 * @return 0 on success, otherwise a negative integer. 627 */ 628 int lwm2m_swmgmt_set_activate_cb(uint16_t obj_inst_id, lwm2m_engine_execute_cb_t cb); 629 630 /** 631 * @brief Set callback to handle software deactivation requests 632 * 633 * The callback will be executed when the LWM2M execute operation gets called 634 * on the corresponding object's Deactivate resource instance. 635 * 636 * @param[in] obj_inst_id The instance number to set the callback for. 637 * @param[in] cb A callback function to receive the execute event. 638 * 639 * @return 0 on success, otherwise a negative integer. 640 */ 641 int lwm2m_swmgmt_set_deactivate_cb(uint16_t obj_inst_id, lwm2m_engine_execute_cb_t cb); 642 643 /** 644 * @brief Set callback to handle software install requests 645 * 646 * The callback will be executed when the LWM2M execute operation gets called 647 * on the corresponding object's Install resource instance. 648 * 649 * @param[in] obj_inst_id The instance number to set the callback for. 650 * @param[in] cb A callback function to receive the execute event. 651 * 652 * @return 0 on success, otherwise a negative integer. 653 */ 654 int lwm2m_swmgmt_set_install_package_cb(uint16_t obj_inst_id, lwm2m_engine_execute_cb_t cb); 655 656 /** 657 * @brief Set callback to handle software uninstall requests 658 * 659 * The callback will be executed when the LWM2M execute operation gets called 660 * on the corresponding object's Uninstall resource instance. 661 * 662 * @param[in] obj_inst_id The instance number to set the callback for. 663 * @param[in] cb A callback function for handling the execute event. 664 * 665 * @return 0 on success, otherwise a negative integer. 666 */ 667 int lwm2m_swmgmt_set_delete_package_cb(uint16_t obj_inst_id, lwm2m_engine_execute_cb_t cb); 668 669 /** 670 * @brief Set callback to read software package 671 * 672 * The callback will be executed when the LWM2M read operation gets called 673 * on the corresponding object. 674 * 675 * @param[in] obj_inst_id The instance number to set the callback for. 676 * @param[in] cb A callback function for handling the read event. 677 * 678 * @return 0 on success, otherwise a negative integer. 679 */ 680 int lwm2m_swmgmt_set_read_package_version_cb(uint16_t obj_inst_id, lwm2m_engine_get_data_cb_t cb); 681 682 /** 683 * @brief Set data callback for software management block transfer. 684 * 685 * The callback will be executed when the LWM2M block write operation gets called 686 * on the corresponding object's resource instance. 687 * 688 * @param[in] obj_inst_id The instance number to set the callback for. 689 * @param[in] cb A callback function for handling the block write event. 690 * 691 * @return 0 on success, otherwise a negative integer. 692 */ 693 int lwm2m_swmgmt_set_write_package_cb(uint16_t obj_inst_id, lwm2m_engine_set_data_cb_t cb); 694 695 /** 696 * Function to be called when a Software Management object instance 697 * completed the Install operation. 698 * 699 * @param[in] obj_inst_id The Software Management object instance 700 * @param[in] error_code The result code of the operation. Zero on success 701 * otherwise it should be a negative integer. 702 * 703 * return 0 on success, otherwise a negative integer. 704 */ 705 int lwm2m_swmgmt_install_completed(uint16_t obj_inst_id, int error_code); 706 707 #endif 708 709 #if defined(CONFIG_LWM2M_EVENT_LOG_OBJ_SUPPORT) || defined(__DOXYGEN__) 710 711 /** 712 * @brief Set callback to read log data 713 * 714 * The callback will be executed when the LWM2M read operation gets called 715 * on the corresponding object. 716 * 717 * @param[in] cb A callback function for handling the read event. 718 */ 719 void lwm2m_event_log_set_read_log_data_cb(lwm2m_engine_get_data_cb_t cb); 720 721 #endif 722 723 /** 724 * @brief Maximum value for Objlnk resource fields 725 */ 726 #define LWM2M_OBJLNK_MAX_ID USHRT_MAX 727 728 /** 729 * @brief LWM2M Objlnk resource type structure 730 */ 731 struct lwm2m_objlnk { 732 uint16_t obj_id; /**< Object ID */ 733 uint16_t obj_inst; /**< Object instance ID */ 734 }; 735 736 /** 737 * @brief Change an observer's pmin value. 738 * 739 * @deprecated Use lwm2m_update_observer_min_period() instead. 740 * 741 * LwM2M clients use this function to modify the pmin attribute 742 * for an observation being made. 743 * Example to update the pmin of a temperature sensor value being observed: 744 * lwm2m_engine_update_observer_min_period("client_ctx, 3303/0/5700", 5); 745 * 746 * @param[in] client_ctx LwM2M context 747 * @param[in] pathstr LwM2M path string "obj/obj-inst/res" 748 * @param[in] period_s Value of pmin to be given (in seconds). 749 * 750 * @return 0 for success or negative in case of error. 751 */ 752 __deprecated 753 int lwm2m_engine_update_observer_min_period(struct lwm2m_ctx *client_ctx, const char *pathstr, 754 uint32_t period_s); 755 756 /** 757 * @brief Change an observer's pmin value. 758 * 759 * LwM2M clients use this function to modify the pmin attribute 760 * for an observation being made. 761 * Example to update the pmin of a temperature sensor value being observed: 762 * lwm2m_update_observer_min_period(client_ctx, &LWM2M_OBJ(3303, 0, 5700), 5); 763 * 764 * @param[in] client_ctx LwM2M context 765 * @param[in] path LwM2M path as a struct 766 * @param[in] period_s Value of pmin to be given (in seconds). 767 * 768 * @return 0 for success or negative in case of error. 769 */ 770 int lwm2m_update_observer_min_period(struct lwm2m_ctx *client_ctx, 771 const struct lwm2m_obj_path *path, uint32_t period_s); 772 773 /** 774 * @brief Change an observer's pmax value. 775 * 776 * @deprecated Use lwm2m_update_observer_max_period() instead. 777 * 778 * LwM2M clients use this function to modify the pmax attribute 779 * for an observation being made. 780 * Example to update the pmax of a temperature sensor value being observed: 781 * lwm2m_engine_update_observer_max_period("client_ctx, 3303/0/5700", 5); 782 * 783 * @param[in] client_ctx LwM2M context 784 * @param[in] pathstr LwM2M path string "obj/obj-inst/res" 785 * @param[in] period_s Value of pmax to be given (in seconds). 786 * 787 * @return 0 for success or negative in case of error. 788 */ 789 __deprecated 790 int lwm2m_engine_update_observer_max_period(struct lwm2m_ctx *client_ctx, const char *pathstr, 791 uint32_t period_s); 792 793 /** 794 * @brief Change an observer's pmax value. 795 * 796 * LwM2M clients use this function to modify the pmax attribute 797 * for an observation being made. 798 * Example to update the pmax of a temperature sensor value being observed: 799 * lwm2m__update_observer_max_period(client_ctx, &LWM2M_OBJ(3303, 0, 5700), 5); 800 * 801 * @param[in] client_ctx LwM2M context 802 * @param[in] path LwM2M path as a struct 803 * @param[in] period_s Value of pmax to be given (in seconds). 804 * 805 * @return 0 for success or negative in case of error. 806 */ 807 int lwm2m_update_observer_max_period(struct lwm2m_ctx *client_ctx, 808 const struct lwm2m_obj_path *path, uint32_t period_s); 809 810 /** 811 * @brief Create an LwM2M object instance. 812 * 813 * @deprecated Use lwm2m_create_obj_inst() instead. 814 * 815 * LwM2M clients use this function to create non-default LwM2M objects: 816 * Example to create first temperature sensor object: 817 * lwm2m_engine_create_obj_inst("3303/0"); 818 * 819 * @param[in] pathstr LwM2M path string "obj/obj-inst" 820 * 821 * @return 0 for success or negative in case of error. 822 */ 823 __deprecated 824 int lwm2m_engine_create_obj_inst(const char *pathstr); 825 826 /** 827 * @brief Create an LwM2M object instance. 828 * 829 * LwM2M clients use this function to create non-default LwM2M objects: 830 * Example to create first temperature sensor object: 831 * lwm2m_create_obj_inst(&LWM2M_OBJ(3303, 0)); 832 * 833 * @param[in] path LwM2M path as a struct 834 * 835 * @return 0 for success or negative in case of error. 836 */ 837 int lwm2m_create_object_inst(const struct lwm2m_obj_path *path); 838 839 /** 840 * @brief Delete an LwM2M object instance. 841 * 842 * @deprecated Use lwm2m_delete_obj_inst() instead. 843 * 844 * LwM2M clients use this function to delete LwM2M objects. 845 * 846 * @param[in] pathstr LwM2M path string "obj/obj-inst" 847 * 848 * @return 0 for success or negative in case of error. 849 */ 850 __deprecated 851 int lwm2m_engine_delete_obj_inst(const char *pathstr); 852 853 /** 854 * @brief Delete an LwM2M object instance. 855 * 856 * LwM2M clients use this function to delete LwM2M objects. 857 * 858 * @param[in] path LwM2M path as a struct 859 * 860 * @return 0 for success or negative in case of error. 861 */ 862 int lwm2m_delete_object_inst(const struct lwm2m_obj_path *path); 863 864 /** 865 * @brief Locks the registry for this thread. 866 * 867 * Use this function before writing to multiple resources. This halts the 868 * lwm2m main thread until all the write-operations are finished. 869 * 870 */ 871 void lwm2m_registry_lock(void); 872 873 /** 874 * @brief Unlocks the registry previously locked by lwm2m_registry_lock(). 875 * 876 */ 877 void lwm2m_registry_unlock(void); 878 879 /** 880 * @brief Set resource (instance) value (opaque buffer) 881 * 882 * @deprecated Use lwm2m_set_opaque() instead. 883 * 884 * @param[in] pathstr LwM2M path string "obj/obj-inst/res(/res-inst)" 885 * @param[in] data_ptr Data buffer 886 * @param[in] data_len Length of buffer 887 * 888 * @return 0 for success or negative in case of error. 889 */ 890 __deprecated 891 int lwm2m_engine_set_opaque(const char *pathstr, const char *data_ptr, uint16_t data_len); 892 893 /** 894 * @brief Set resource (instance) value (opaque buffer) 895 * 896 * @param[in] path LwM2M path as a struct 897 * @param[in] data_ptr Data buffer 898 * @param[in] data_len Length of buffer 899 * 900 * @return 0 for success or negative in case of error. 901 */ 902 int lwm2m_set_opaque(const struct lwm2m_obj_path *path, const char *data_ptr, uint16_t data_len); 903 904 /** 905 * @brief Set resource (instance) value (string) 906 * 907 * @deprecated Use lwm2m_set_string() instead. 908 * 909 * @param[in] pathstr LwM2M path string "obj/obj-inst/res(/res-inst)" 910 * @param[in] data_ptr NULL terminated char buffer 911 * 912 * @return 0 for success or negative in case of error. 913 */ 914 __deprecated 915 int lwm2m_engine_set_string(const char *pathstr, const char *data_ptr); 916 917 /** 918 * @brief Set resource (instance) value (string) 919 * 920 * @param[in] path LwM2M path as a struct 921 * @param[in] data_ptr NULL terminated char buffer 922 * 923 * @return 0 for success or negative in case of error. 924 */ 925 int lwm2m_set_string(const struct lwm2m_obj_path *path, const char *data_ptr); 926 927 /** 928 * @brief Set resource (instance) value (u8) 929 * 930 * @deprecated Use lwm2m_set_u8() instead. 931 * 932 * @param[in] pathstr LwM2M path string "obj/obj-inst/res(/res-inst)" 933 * @param[in] value u8 value 934 * 935 * @return 0 for success or negative in case of error. 936 */ 937 __deprecated 938 int lwm2m_engine_set_u8(const char *pathstr, uint8_t value); 939 940 /** 941 * @brief Set resource (instance) value (u8) 942 * 943 * @param[in] path LwM2M path as a struct 944 * @param[in] value u8 value 945 * 946 * @return 0 for success or negative in case of error. 947 */ 948 int lwm2m_set_u8(const struct lwm2m_obj_path *path, uint8_t value); 949 950 /** 951 * @brief Set resource (instance) value (u16) 952 * 953 * @deprecated Use lwm2m_set_u16() instead. 954 * 955 * @param[in] pathstr LwM2M path string "obj/obj-inst/res(/res-inst)" 956 * @param[in] value u16 value 957 * 958 * @return 0 for success or negative in case of error. 959 */ 960 __deprecated 961 int lwm2m_engine_set_u16(const char *pathstr, uint16_t value); 962 963 /** 964 * @brief Set resource (instance) value (u16) 965 * 966 * @param[in] path LwM2M path as a struct 967 * @param[in] value u16 value 968 * 969 * @return 0 for success or negative in case of error. 970 */ 971 int lwm2m_set_u16(const struct lwm2m_obj_path *path, uint16_t value); 972 973 /** 974 * @brief Set resource (instance) value (u32) 975 * 976 * @deprecated Use lwm2m_set_u32() instead. 977 * 978 * @param[in] pathstr LwM2M path string "obj/obj-inst/res(/res-inst)" 979 * @param[in] value u32 value 980 * 981 * @return 0 for success or negative in case of error. 982 */ 983 __deprecated 984 int lwm2m_engine_set_u32(const char *pathstr, uint32_t value); 985 986 /** 987 * @brief Set resource (instance) value (u32) 988 * 989 * @param[in] path LwM2M path as a struct 990 * @param[in] value u32 value 991 * 992 * @return 0 for success or negative in case of error. 993 */ 994 int lwm2m_set_u32(const struct lwm2m_obj_path *path, uint32_t value); 995 996 /** 997 * @brief Set resource (instance) value (u64) 998 * 999 * @deprecated Use lwm2m_set_u64() instead. 1000 * 1001 * @param[in] pathstr LwM2M path string "obj/obj-inst/res(/res-inst)" 1002 * @param[in] value u64 value 1003 * 1004 * @return 0 for success or negative in case of error. 1005 */ 1006 __deprecated 1007 int lwm2m_engine_set_u64(const char *pathstr, uint64_t value); 1008 1009 /** 1010 * @brief Set resource (instance) value (u64) 1011 * 1012 * @deprecated Unsigned 64bit value type does not exits. 1013 * This is internally handled as a int64_t. 1014 * Use lwm2m_set_s64() instead. 1015 * 1016 * @param[in] path LwM2M path as a struct 1017 * @param[in] value u64 value 1018 * 1019 * @return 0 for success or negative in case of error. 1020 */ 1021 __deprecated 1022 int lwm2m_set_u64(const struct lwm2m_obj_path *path, uint64_t value); 1023 1024 /** 1025 * @brief Set resource (instance) value (s8) 1026 * 1027 * @deprecated Use lwm2m_set_s8() instead. 1028 * 1029 * @param[in] pathstr LwM2M path string "obj/obj-inst/res(/res-inst)" 1030 * @param[in] value s8 value 1031 * 1032 * @return 0 for success or negative in case of error. 1033 */ 1034 __deprecated 1035 int lwm2m_engine_set_s8(const char *pathstr, int8_t value); 1036 1037 /** 1038 * @brief Set resource (instance) value (s8) 1039 * 1040 * @param[in] path LwM2M path as a struct 1041 * @param[in] value s8 value 1042 * 1043 * @return 0 for success or negative in case of error. 1044 */ 1045 int lwm2m_set_s8(const struct lwm2m_obj_path *path, int8_t value); 1046 1047 /** 1048 * @brief Set resource (instance) value (s16) 1049 * 1050 * @deprecated Use lwm2m_set_s16() instead. 1051 * 1052 * @param[in] pathstr LwM2M path string "obj/obj-inst/res(/res-inst)" 1053 * @param[in] value s16 value 1054 * 1055 * @return 0 for success or negative in case of error. 1056 */ 1057 __deprecated 1058 int lwm2m_engine_set_s16(const char *pathstr, int16_t value); 1059 1060 /** 1061 * @brief Set resource (instance) value (s16) 1062 * 1063 * @param[in] path LwM2M path as a struct 1064 * @param[in] value s16 value 1065 * 1066 * @return 0 for success or negative in case of error. 1067 */ 1068 int lwm2m_set_s16(const struct lwm2m_obj_path *path, int16_t value); 1069 1070 /** 1071 * @brief Set resource (instance) value (s32) 1072 * 1073 * @deprecated Use lwm2m_set_s32() instead. 1074 * 1075 * @param[in] pathstr LwM2M path string "obj/obj-inst/res(/res-inst)" 1076 * @param[in] value s32 value 1077 * 1078 * @return 0 for success or negative in case of error. 1079 */ 1080 __deprecated 1081 int lwm2m_engine_set_s32(const char *pathstr, int32_t value); 1082 1083 /** 1084 * @brief Set resource (instance) value (s32) 1085 * 1086 * @param[in] path LwM2M path as a struct 1087 * @param[in] value s32 value 1088 * 1089 * @return 0 for success or negative in case of error. 1090 */ 1091 int lwm2m_set_s32(const struct lwm2m_obj_path *path, int32_t value); 1092 1093 /** 1094 * @brief Set resource (instance) value (s64) 1095 * 1096 * @deprecated Use lwm2m_set_s64() instead. 1097 * 1098 * @param[in] pathstr LwM2M path string "obj/obj-inst/res(/res-inst)" 1099 * @param[in] value s64 value 1100 * 1101 * @return 0 for success or negative in case of error. 1102 */ 1103 __deprecated 1104 int lwm2m_engine_set_s64(const char *pathstr, int64_t value); 1105 1106 /** 1107 * @brief Set resource (instance) value (s64) 1108 * 1109 * @param[in] path LwM2M path as a struct 1110 * @param[in] value s64 value 1111 * 1112 * @return 0 for success or negative in case of error. 1113 */ 1114 int lwm2m_set_s64(const struct lwm2m_obj_path *path, int64_t value); 1115 1116 /** 1117 * @brief Set resource (instance) value (bool) 1118 * 1119 * @deprecated Use lwm2m_set_bool() instead. 1120 * 1121 * @param[in] pathstr LwM2M path string "obj/obj-inst/res(/res-inst)" 1122 * @param[in] value bool value 1123 * 1124 * @return 0 for success or negative in case of error. 1125 */ 1126 __deprecated 1127 int lwm2m_engine_set_bool(const char *pathstr, bool value); 1128 1129 /** 1130 * @brief Set resource (instance) value (bool) 1131 * 1132 * @param[in] path LwM2M path as a struct 1133 * @param[in] value bool value 1134 * 1135 * @return 0 for success or negative in case of error. 1136 */ 1137 int lwm2m_set_bool(const struct lwm2m_obj_path *path, bool value); 1138 1139 /** 1140 * @brief Set resource (instance) value (double) 1141 * 1142 * @deprecated Use lwm2m_set_f64() instead. 1143 * 1144 * @param[in] pathstr LwM2M path string "obj/obj-inst/res(/res-inst)" 1145 * @param[in] value double value 1146 * 1147 * @return 0 for success or negative in case of error. 1148 */ 1149 __deprecated 1150 int lwm2m_engine_set_float(const char *pathstr, const double *value); 1151 1152 /** 1153 * @brief Set resource (instance) value (double) 1154 * 1155 * @param[in] path LwM2M path as a struct 1156 * @param[in] value double value 1157 * 1158 * @return 0 for success or negative in case of error. 1159 */ 1160 int lwm2m_set_f64(const struct lwm2m_obj_path *path, const double value); 1161 1162 /** 1163 * @brief Set resource (instance) value (Objlnk) 1164 * 1165 * @deprecated Use lwm2m_set_objlnk() instead. 1166 * 1167 * @param[in] pathstr LwM2M path string "obj/obj-inst/res(/res-inst)" 1168 * @param[in] value pointer to the lwm2m_objlnk structure 1169 * 1170 * @return 0 for success or negative in case of error. 1171 */ 1172 __deprecated 1173 int lwm2m_engine_set_objlnk(const char *pathstr, const struct lwm2m_objlnk *value); 1174 1175 /** 1176 * @brief Set resource (instance) value (Objlnk) 1177 * 1178 * @param[in] path LwM2M path as a struct 1179 * @param[in] value pointer to the lwm2m_objlnk structure 1180 * 1181 * @return 0 for success or negative in case of error. 1182 */ 1183 int lwm2m_set_objlnk(const struct lwm2m_obj_path *path, const struct lwm2m_objlnk *value); 1184 1185 /** 1186 * @brief Set resource (instance) value (Time) 1187 * 1188 * @deprecated Use lwm2m_set_time() instead. 1189 * 1190 * @param[in] pathstr LwM2M path string "obj/obj-inst/res(/res-inst)" 1191 * @param[in] value Epoch timestamp 1192 * 1193 * @return 0 for success or negative in case of error. 1194 */ 1195 __deprecated 1196 int lwm2m_engine_set_time(const char *pathstr, time_t value); 1197 1198 /** 1199 * @brief Set resource (instance) value (Time) 1200 * 1201 * @param[in] path LwM2M path as a struct 1202 * @param[in] value Epoch timestamp 1203 * 1204 * @return 0 for success or negative in case of error. 1205 */ 1206 int lwm2m_set_time(const struct lwm2m_obj_path *path, time_t value); 1207 1208 /** 1209 * @brief Get resource (instance) value (opaque buffer) 1210 * 1211 * @deprecated Use lwm2m_get_opaque() instead. 1212 * 1213 * @param[in] pathstr LwM2M path string "obj/obj-inst/res(/res-inst)" 1214 * @param[out] buf Data buffer to copy data into 1215 * @param[in] buflen Length of buffer 1216 * 1217 * @return 0 for success or negative in case of error. 1218 */ 1219 __deprecated 1220 int lwm2m_engine_get_opaque(const char *pathstr, void *buf, uint16_t buflen); 1221 1222 /** 1223 * @brief Get resource (instance) value (opaque buffer) 1224 * 1225 * @param[in] path LwM2M path as a struct 1226 * @param[out] buf Data buffer to copy data into 1227 * @param[in] buflen Length of buffer 1228 * 1229 * @return 0 for success or negative in case of error. 1230 */ 1231 int lwm2m_get_opaque(const struct lwm2m_obj_path *path, void *buf, uint16_t buflen); 1232 1233 /** 1234 * @brief Get resource (instance) value (string) 1235 * 1236 * @deprecated Use lwm2m_get_string() instead. 1237 * 1238 * @param[in] pathstr LwM2M path string "obj/obj-inst/res(/res-inst)" 1239 * @param[out] str String buffer to copy data into 1240 * @param[in] buflen Length of buffer 1241 * 1242 * @return 0 for success or negative in case of error. 1243 */ 1244 __deprecated 1245 int lwm2m_engine_get_string(const char *pathstr, void *str, uint16_t buflen); 1246 1247 /** 1248 * @brief Get resource (instance) value (string) 1249 * 1250 * @param[in] path LwM2M path as a struct 1251 * @param[out] str String buffer to copy data into 1252 * @param[in] buflen Length of buffer 1253 * 1254 * @return 0 for success or negative in case of error. 1255 */ 1256 int lwm2m_get_string(const struct lwm2m_obj_path *path, void *str, uint16_t buflen); 1257 1258 /** 1259 * @brief Get resource (instance) value (u8) 1260 * 1261 * @deprecated Use lwm2m_get_u8() instead. 1262 * 1263 * @param[in] pathstr LwM2M path string "obj/obj-inst/res(/res-inst)" 1264 * @param[out] value u8 buffer to copy data into 1265 * 1266 * @return 0 for success or negative in case of error. 1267 */ 1268 __deprecated 1269 int lwm2m_engine_get_u8(const char *pathstr, uint8_t *value); 1270 1271 /** 1272 * @brief Get resource (instance) value (u8) 1273 * 1274 * @param[in] path LwM2M path as a struct 1275 * @param[out] value u8 buffer to copy data into 1276 * 1277 * @return 0 for success or negative in case of error. 1278 */ 1279 int lwm2m_get_u8(const struct lwm2m_obj_path *path, uint8_t *value); 1280 1281 /** 1282 * @brief Get resource (instance) value (u16) 1283 * 1284 * @deprecated Use lwm2m_get_u16() instead. 1285 * 1286 * @param[in] pathstr LwM2M path string "obj/obj-inst/res(/res-inst)" 1287 * @param[out] value u16 buffer to copy data into 1288 * 1289 * @return 0 for success or negative in case of error. 1290 */ 1291 __deprecated 1292 int lwm2m_engine_get_u16(const char *pathstr, uint16_t *value); 1293 1294 /** 1295 * @brief Get resource (instance) value (u16) 1296 * 1297 * @param[in] path LwM2M path as a struct 1298 * @param[out] value u16 buffer to copy data into 1299 * 1300 * @return 0 for success or negative in case of error. 1301 */ 1302 int lwm2m_get_u16(const struct lwm2m_obj_path *path, uint16_t *value); 1303 1304 /** 1305 * @brief Get resource (instance) value (u32) 1306 * 1307 * @deprecated Use lwm2m_get_u32() instead. 1308 * 1309 * @param[in] pathstr LwM2M path string "obj/obj-inst/res(/res-inst)" 1310 * @param[out] value u32 buffer to copy data into 1311 * 1312 * @return 0 for success or negative in case of error. 1313 */ 1314 __deprecated 1315 int lwm2m_engine_get_u32(const char *pathstr, uint32_t *value); 1316 1317 /** 1318 * @brief Get resource (instance) value (u32) 1319 * 1320 * @param[in] path LwM2M path as a struct 1321 * @param[out] value u32 buffer to copy data into 1322 * 1323 * @return 0 for success or negative in case of error. 1324 */ 1325 int lwm2m_get_u32(const struct lwm2m_obj_path *path, uint32_t *value); 1326 1327 /** 1328 * @brief Get resource (instance) value (u64) 1329 * 1330 * @deprecated Use lwm2m_get_u64() instead. 1331 * 1332 * @param[in] pathstr LwM2M path string "obj/obj-inst/res(/res-inst)" 1333 * @param[out] value u64 buffer to copy data into 1334 * 1335 * @return 0 for success or negative in case of error. 1336 */ 1337 __deprecated 1338 int lwm2m_engine_get_u64(const char *pathstr, uint64_t *value); 1339 1340 /** 1341 * @brief Get resource (instance) value (u64) 1342 * 1343 * @deprecated Unsigned 64bit value type does not exits. 1344 * This is internally handled as a int64_t. 1345 * Use lwm2m_get_s64() instead. 1346 1347 * @param[in] path LwM2M path as a struct 1348 * @param[out] value u64 buffer to copy data into 1349 * 1350 * @return 0 for success or negative in case of error. 1351 */ 1352 __deprecated 1353 int lwm2m_get_u64(const struct lwm2m_obj_path *path, uint64_t *value); 1354 1355 /** 1356 * @brief Get resource (instance) value (s8) 1357 * 1358 * @deprecated Use lwm2m_get_s8() instead. 1359 * 1360 * @param[in] pathstr LwM2M path string "obj/obj-inst/res(/res-inst)" 1361 * @param[out] value s8 buffer to copy data into 1362 * 1363 * @return 0 for success or negative in case of error. 1364 */ 1365 __deprecated 1366 int lwm2m_engine_get_s8(const char *pathstr, int8_t *value); 1367 1368 /** 1369 * @brief Get resource (instance) value (s8) 1370 * 1371 * @param[in] path LwM2M path as a struct 1372 * @param[out] value s8 buffer to copy data into 1373 * 1374 * @return 0 for success or negative in case of error. 1375 */ 1376 int lwm2m_get_s8(const struct lwm2m_obj_path *path, int8_t *value); 1377 1378 /** 1379 * @brief Get resource (instance) value (s16) 1380 * 1381 * @deprecated Use lwm2m_get_s16() instead. 1382 * 1383 * @param[in] pathstr LwM2M path string "obj/obj-inst/res(/res-inst)" 1384 * @param[out] value s16 buffer to copy data into 1385 * 1386 * @return 0 for success or negative in case of error. 1387 */ 1388 __deprecated 1389 int lwm2m_engine_get_s16(const char *pathstr, int16_t *value); 1390 1391 /** 1392 * @brief Get resource (instance) value (s16) 1393 * 1394 * @param[in] path LwM2M path as a struct 1395 * @param[out] value s16 buffer to copy data into 1396 * 1397 * @return 0 for success or negative in case of error. 1398 */ 1399 int lwm2m_get_s16(const struct lwm2m_obj_path *path, int16_t *value); 1400 1401 /** 1402 * @brief Get resource (instance) value (s32) 1403 * 1404 * @deprecated Use lwm2m_get_s32() instead. 1405 * 1406 * @param[in] pathstr LwM2M path string "obj/obj-inst/res(/res-inst)" 1407 * @param[out] value s32 buffer to copy data into 1408 * 1409 * @return 0 for success or negative in case of error. 1410 */ 1411 __deprecated 1412 int lwm2m_engine_get_s32(const char *pathstr, int32_t *value); 1413 1414 /** 1415 * @brief Get resource (instance) value (s32) 1416 * 1417 * @param[in] path LwM2M path as a struct 1418 * @param[out] value s32 buffer to copy data into 1419 * 1420 * @return 0 for success or negative in case of error. 1421 */ 1422 int lwm2m_get_s32(const struct lwm2m_obj_path *path, int32_t *value); 1423 1424 /** 1425 * @brief Get resource (instance) value (s64) 1426 * 1427 * @deprecated Use lwm2m_get_s64() instead. 1428 * 1429 * @param[in] pathstr LwM2M path string "obj/obj-inst/res(/res-inst)" 1430 * @param[out] value s64 buffer to copy data into 1431 * 1432 * @return 0 for success or negative in case of error. 1433 */ 1434 __deprecated 1435 int lwm2m_engine_get_s64(const char *pathstr, int64_t *value); 1436 1437 /** 1438 * @brief Get resource (instance) value (s64) 1439 * 1440 * @param[in] path LwM2M path as a struct 1441 * @param[out] value s64 buffer to copy data into 1442 * 1443 * @return 0 for success or negative in case of error. 1444 */ 1445 int lwm2m_get_s64(const struct lwm2m_obj_path *path, int64_t *value); 1446 1447 /** 1448 * @brief Get resource (instance) value (bool) 1449 * 1450 * @deprecated Use lwm2m_get_bool() instead. 1451 * 1452 * @param[in] pathstr LwM2M path string "obj/obj-inst/res(/res-inst)" 1453 * @param[out] value bool buffer to copy data into 1454 * 1455 * @return 0 for success or negative in case of error. 1456 */ 1457 __deprecated 1458 int lwm2m_engine_get_bool(const char *pathstr, bool *value); 1459 1460 /** 1461 * @brief Get resource (instance) value (bool) 1462 * 1463 * @param[in] path LwM2M path as a struct 1464 * @param[out] value bool buffer to copy data into 1465 * 1466 * @return 0 for success or negative in case of error. 1467 */ 1468 int lwm2m_get_bool(const struct lwm2m_obj_path *path, bool *value); 1469 1470 /** 1471 * @brief Get resource (instance) value (double) 1472 * 1473 * @deprecated Use lwm2m_get_f64() instead. 1474 * 1475 * @param[in] pathstr LwM2M path string "obj/obj-inst/res(/res-inst)" 1476 * @param[out] buf double buffer to copy data into 1477 * 1478 * @return 0 for success or negative in case of error. 1479 */ 1480 __deprecated 1481 int lwm2m_engine_get_float(const char *pathstr, double *buf); 1482 1483 /** 1484 * @brief Get resource (instance) value (double) 1485 * 1486 * @param[in] path LwM2M path as a struct 1487 * @param[out] value double buffer to copy data into 1488 * 1489 * @return 0 for success or negative in case of error. 1490 */ 1491 int lwm2m_get_f64(const struct lwm2m_obj_path *path, double *value); 1492 1493 /** 1494 * @brief Get resource (instance) value (Objlnk) 1495 * 1496 * @deprecated Use lwm2m_get_objlnk() instead. 1497 * 1498 * @param[in] pathstr LwM2M path string "obj/obj-inst/res(/res-inst)" 1499 * @param[out] buf lwm2m_objlnk buffer to copy data into 1500 * 1501 * @return 0 for success or negative in case of error. 1502 */ 1503 __deprecated 1504 int lwm2m_engine_get_objlnk(const char *pathstr, struct lwm2m_objlnk *buf); 1505 1506 /** 1507 * @brief Get resource (instance) value (Objlnk) 1508 * 1509 * @param[in] path LwM2M path as a struct 1510 * @param[out] buf lwm2m_objlnk buffer to copy data into 1511 * 1512 * @return 0 for success or negative in case of error. 1513 */ 1514 int lwm2m_get_objlnk(const struct lwm2m_obj_path *path, struct lwm2m_objlnk *buf); 1515 1516 /** 1517 * @brief Get resource (instance) value (Time) 1518 * 1519 * @deprecated Use lwm2m_get_time() instead. 1520 * 1521 * @param[in] pathstr LwM2M path string "obj/obj-inst/res(/res-inst)" 1522 * @param[out] buf time_t pointer to copy data 1523 * 1524 * @return 0 for success or negative in case of error. 1525 */ 1526 __deprecated 1527 int lwm2m_engine_get_time(const char *pathstr, time_t *buf); 1528 1529 /** 1530 * @brief Get resource (instance) value (Time) 1531 * 1532 * @param[in] path LwM2M path as a struct 1533 * @param[out] buf time_t pointer to copy data 1534 * 1535 * @return 0 for success or negative in case of error. 1536 */ 1537 int lwm2m_get_time(const struct lwm2m_obj_path *path, time_t *buf); 1538 1539 /** 1540 * @brief Set resource (instance) read callback 1541 * 1542 * @deprecated Use lwm2m_register_read_callback() instead. 1543 * 1544 * LwM2M clients can use this to set the callback function for resource reads when data 1545 * handling in the LwM2M engine needs to be bypassed. 1546 * For example reading back opaque binary data from external storage. 1547 * 1548 * This callback should not generally be used for any data that might be observed as 1549 * engine does not have any knowledge of data changes. 1550 * 1551 * When separate buffer for data should be used, use lwm2m_engine_set_res_buf() instead 1552 * to set the storage. 1553 * 1554 * @param[in] pathstr LwM2M path string "obj/obj-inst/res(/res-inst)" 1555 * @param[in] cb Read resource callback 1556 * 1557 * @return 0 for success or negative in case of error. 1558 */ 1559 __deprecated 1560 int lwm2m_engine_register_read_callback(const char *pathstr, 1561 lwm2m_engine_get_data_cb_t cb); 1562 1563 /** 1564 * @brief Set resource (instance) read callback 1565 * 1566 * LwM2M clients can use this to set the callback function for resource reads when data 1567 * handling in the LwM2M engine needs to be bypassed. 1568 * For example reading back opaque binary data from external storage. 1569 * 1570 * This callback should not generally be used for any data that might be observed as 1571 * engine does not have any knowledge of data changes. 1572 * 1573 * When separate buffer for data should be used, use lwm2m_engine_set_res_buf() instead 1574 * to set the storage. 1575 * 1576 * @param[in] path LwM2M path as a struct 1577 * @param[in] cb Read resource callback 1578 * 1579 * @return 0 for success or negative in case of error. 1580 */ 1581 int lwm2m_register_read_callback(const struct lwm2m_obj_path *path, lwm2m_engine_get_data_cb_t cb); 1582 1583 /** 1584 * @brief Set resource (instance) pre-write callback 1585 * 1586 * @deprecated Use lwm2m_register_pre_write_callback() instead. 1587 * 1588 * This callback is triggered before setting the value of a resource. It 1589 * can pass a special data buffer to the engine so that the actual resource 1590 * value can be calculated later, etc. 1591 * 1592 * @param[in] pathstr LwM2M path string "obj/obj-inst/res(/res-inst)" 1593 * @param[in] cb Pre-write resource callback 1594 * 1595 * @return 0 for success or negative in case of error. 1596 */ 1597 __deprecated 1598 int lwm2m_engine_register_pre_write_callback(const char *pathstr, 1599 lwm2m_engine_get_data_cb_t cb); 1600 1601 /** 1602 * @brief Set resource (instance) pre-write callback 1603 * 1604 * This callback is triggered before setting the value of a resource. It 1605 * can pass a special data buffer to the engine so that the actual resource 1606 * value can be calculated later, etc. 1607 * 1608 * @param[in] path LwM2M path as a struct 1609 * @param[in] cb Pre-write resource callback 1610 * 1611 * @return 0 for success or negative in case of error. 1612 */ 1613 int lwm2m_register_pre_write_callback(const struct lwm2m_obj_path *path, 1614 lwm2m_engine_get_data_cb_t cb); 1615 1616 /** 1617 * @brief Set resource (instance) validation callback 1618 * 1619 * @deprecated Use lwm2m_register_validate_callback() instead. 1620 * 1621 * This callback is triggered before setting the value of a resource to the 1622 * resource data buffer. 1623 * 1624 * The callback allows an LwM2M client or object to validate the data before 1625 * writing and notify an error if the data should be discarded for any reason 1626 * (by returning a negative error code). 1627 * 1628 * @note All resources that have a validation callback registered are initially 1629 * decoded into a temporary validation buffer. Make sure that 1630 * ``CONFIG_LWM2M_ENGINE_VALIDATION_BUFFER_SIZE`` is large enough to 1631 * store each of the validated resources (individually). 1632 * 1633 * @param[in] pathstr LwM2M path string "obj/obj-inst/res(/res-inst)" 1634 * @param[in] cb Validate resource data callback 1635 * 1636 * @return 0 for success or negative in case of error. 1637 */ 1638 __deprecated 1639 int lwm2m_engine_register_validate_callback(const char *pathstr, 1640 lwm2m_engine_set_data_cb_t cb); 1641 1642 /** 1643 * @brief Set resource (instance) validation callback 1644 * 1645 * This callback is triggered before setting the value of a resource to the 1646 * resource data buffer. 1647 * 1648 * The callback allows an LwM2M client or object to validate the data before 1649 * writing and notify an error if the data should be discarded for any reason 1650 * (by returning a negative error code). 1651 * 1652 * @note All resources that have a validation callback registered are initially 1653 * decoded into a temporary validation buffer. Make sure that 1654 * ``CONFIG_LWM2M_ENGINE_VALIDATION_BUFFER_SIZE`` is large enough to 1655 * store each of the validated resources (individually). 1656 * 1657 * @param[in] path LwM2M path as a struct 1658 * @param[in] cb Validate resource data callback 1659 * 1660 * @return 0 for success or negative in case of error. 1661 */ 1662 int lwm2m_register_validate_callback(const struct lwm2m_obj_path *path, 1663 lwm2m_engine_set_data_cb_t cb); 1664 1665 /** 1666 * @brief Set resource (instance) post-write callback 1667 * 1668 * @deprecated Use lwm2m_register_post_write_callback() instead. 1669 * 1670 * This callback is triggered after setting the value of a resource to the 1671 * resource data buffer. 1672 * 1673 * It allows an LwM2M client or object to post-process the value of a resource 1674 * or trigger other related resource calculations. 1675 * 1676 * @param[in] pathstr LwM2M path string "obj/obj-inst/res(/res-inst)" 1677 * @param[in] cb Post-write resource callback 1678 * 1679 * @return 0 for success or negative in case of error. 1680 */ 1681 __deprecated 1682 int lwm2m_engine_register_post_write_callback(const char *pathstr, 1683 lwm2m_engine_set_data_cb_t cb); 1684 1685 /** 1686 * @brief Set resource (instance) post-write callback 1687 * 1688 * This callback is triggered after setting the value of a resource to the 1689 * resource data buffer. 1690 * 1691 * It allows an LwM2M client or object to post-process the value of a resource 1692 * or trigger other related resource calculations. 1693 * 1694 * @param[in] path LwM2M path as a struct 1695 * @param[in] cb Post-write resource callback 1696 * 1697 * @return 0 for success or negative in case of error. 1698 */ 1699 int lwm2m_register_post_write_callback(const struct lwm2m_obj_path *path, 1700 lwm2m_engine_set_data_cb_t cb); 1701 1702 /** 1703 * @brief Set resource execute event callback 1704 * 1705 * @deprecated Use lwm2m_register_exec_callback() instead. 1706 * 1707 * This event is triggered when the execute method of a resource is enabled. 1708 * 1709 * @param[in] pathstr LwM2M path string "obj/obj-inst/res" 1710 * @param[in] cb Execute resource callback 1711 * 1712 * @return 0 for success or negative in case of error. 1713 */ 1714 __deprecated 1715 int lwm2m_engine_register_exec_callback(const char *pathstr, 1716 lwm2m_engine_execute_cb_t cb); 1717 1718 /** 1719 * @brief Set resource execute event callback 1720 * 1721 * This event is triggered when the execute method of a resource is enabled. 1722 * 1723 * @param[in] path LwM2M path as a struct 1724 * @param[in] cb Execute resource callback 1725 * 1726 * @return 0 for success or negative in case of error. 1727 */ 1728 int lwm2m_register_exec_callback(const struct lwm2m_obj_path *path, lwm2m_engine_execute_cb_t cb); 1729 1730 /** 1731 * @brief Set object instance create event callback 1732 * 1733 * @deprecated Use lwm2m_register_create_callback instead. 1734 * 1735 * This event is triggered when an object instance is created. 1736 * 1737 * @param[in] obj_id LwM2M object id 1738 * @param[in] cb Create object instance callback 1739 * 1740 * @return 0 for success or negative in case of error. 1741 */ 1742 __deprecated 1743 int lwm2m_engine_register_create_callback(uint16_t obj_id, 1744 lwm2m_engine_user_cb_t cb); 1745 1746 /** 1747 * @brief Set object instance create event callback 1748 * 1749 * This event is triggered when an object instance is created. 1750 * 1751 * @param[in] obj_id LwM2M object id 1752 * @param[in] cb Create object instance callback 1753 * 1754 * @return 0 for success or negative in case of error. 1755 */ 1756 int lwm2m_register_create_callback(uint16_t obj_id, 1757 lwm2m_engine_user_cb_t cb); 1758 1759 /** 1760 * @brief Set object instance delete event callback 1761 * 1762 * @deprecated Use lwm2m_register_delete_callback instead 1763 * 1764 * This event is triggered when an object instance is deleted. 1765 * 1766 * @param[in] obj_id LwM2M object id 1767 * @param[in] cb Delete object instance callback 1768 * 1769 * @return 0 for success or negative in case of error. 1770 */ 1771 __deprecated 1772 int lwm2m_engine_register_delete_callback(uint16_t obj_id, 1773 lwm2m_engine_user_cb_t cb); 1774 1775 /** 1776 * @brief Set object instance delete event callback 1777 * 1778 * This event is triggered when an object instance is deleted. 1779 * 1780 * @param[in] obj_id LwM2M object id 1781 * @param[in] cb Delete object instance callback 1782 * 1783 * @return 0 for success or negative in case of error. 1784 */ 1785 int lwm2m_register_delete_callback(uint16_t obj_id, 1786 lwm2m_engine_user_cb_t cb); 1787 1788 /** 1789 * @brief Resource read-only value bit 1790 */ 1791 #define LWM2M_RES_DATA_READ_ONLY 0 1792 1793 /** 1794 * @brief Resource read-only flag 1795 */ 1796 #define LWM2M_RES_DATA_FLAG_RO BIT(LWM2M_RES_DATA_READ_ONLY) 1797 1798 /** 1799 * @brief Read resource flags helper macro 1800 */ 1801 #define LWM2M_HAS_RES_FLAG(res, f) ((res->data_flags & f) == f) 1802 1803 /** 1804 * @brief Set data buffer for a resource 1805 * 1806 * @deprecated Use lwm2m_set_res_buf() instead. 1807 * 1808 * Use this function to set the data buffer and flags for the specified LwM2M 1809 * resource. 1810 * 1811 * @param[in] pathstr LwM2M path string "obj/obj-inst/res(/res-inst)" 1812 * @param[in] buffer_ptr Data buffer pointer 1813 * @param[in] buffer_len Length of buffer 1814 * @param[in] data_len Length of existing data in the buffer 1815 * @param[in] data_flags Data buffer flags (such as read-only, etc) 1816 * 1817 * @return 0 for success or negative in case of error. 1818 */ 1819 __deprecated 1820 int lwm2m_engine_set_res_buf(const char *pathstr, void *buffer_ptr, uint16_t buffer_len, 1821 uint16_t data_len, uint8_t data_flags); 1822 1823 /** 1824 * @brief Set data buffer for a resource 1825 * 1826 * Use this function to set the data buffer and flags for the specified LwM2M 1827 * resource. 1828 * 1829 * @param[in] path LwM2M path as a struct 1830 * @param[in] buffer_ptr Data buffer pointer 1831 * @param[in] buffer_len Length of buffer 1832 * @param[in] data_len Length of existing data in the buffer 1833 * @param[in] data_flags Data buffer flags (such as read-only, etc) 1834 * 1835 * @return 0 for success or negative in case of error. 1836 */ 1837 int lwm2m_set_res_buf(const struct lwm2m_obj_path *path, void *buffer_ptr, uint16_t buffer_len, 1838 uint16_t data_len, uint8_t data_flags); 1839 1840 /** 1841 * @brief Set data buffer for a resource 1842 * 1843 * Use this function to set the data buffer and flags for the specified LwM2M 1844 * resource. 1845 * 1846 * @deprecated Use lwm2m_set_res_buf() instead, so you can define buffer size and data size 1847 * separately. 1848 * 1849 * @param[in] pathstr LwM2M path string "obj/obj-inst/res(/res-inst)" 1850 * @param[in] data_ptr Data buffer pointer 1851 * @param[in] data_len Length of buffer 1852 * @param[in] data_flags Data buffer flags (such as read-only, etc) 1853 * 1854 * @return 0 for success or negative in case of error. 1855 */ 1856 __deprecated 1857 int lwm2m_engine_set_res_data(const char *pathstr, void *data_ptr, uint16_t data_len, 1858 uint8_t data_flags); 1859 1860 /** 1861 * @brief Update data size for a resource 1862 * 1863 * @deprecated Use lwm2m_set_res_data_len() instead. 1864 * 1865 * Use this function to set the new size of data in the buffer if you write 1866 * to a buffer received by lwm2m_engine_get_res_buf(). 1867 * 1868 * @param[in] pathstr LwM2M path string "obj/obj-inst/res(/res-inst)" 1869 * @param[in] data_len Length of data 1870 * @return 0 for success or negative in case of error. 1871 */ 1872 __deprecated 1873 int lwm2m_engine_set_res_data_len(const char *pathstr, uint16_t data_len); 1874 1875 /** 1876 * @brief Update data size for a resource 1877 * 1878 * Use this function to set the new size of data in the buffer if you write 1879 * to a buffer received by lwm2m_engine_get_res_buf(). 1880 * 1881 * @param[in] path LwM2M path as a struct 1882 * @param[in] data_len Length of data 1883 * @return 0 for success or negative in case of error. 1884 */ 1885 int lwm2m_set_res_data_len(const struct lwm2m_obj_path *path, uint16_t data_len); 1886 1887 /** 1888 * @brief Get data buffer for a resource 1889 * 1890 * @deprecated Use lwm2m_get_res_buf() instead. 1891 * 1892 * Use this function to get the data buffer information for the specified LwM2M 1893 * resource. 1894 * 1895 * If you directly write into the buffer, you must use lwm2m_engine_set_res_data_len() 1896 * function to update the new size of the written data. 1897 * 1898 * All parameters except pathstr can NULL if you don't want to read those values. 1899 * 1900 * @param[in] pathstr LwM2M path string "obj/obj-inst/res(/res-inst)" 1901 * @param[out] buffer_ptr Data buffer pointer 1902 * @param[out] buffer_len Length of buffer 1903 * @param[out] data_len Length of existing data in the buffer 1904 * @param[out] data_flags Data buffer flags (such as read-only, etc) 1905 * 1906 * @return 0 for success or negative in case of error. 1907 */ 1908 __deprecated 1909 int lwm2m_engine_get_res_buf(const char *pathstr, void **buffer_ptr, uint16_t *buffer_len, 1910 uint16_t *data_len, uint8_t *data_flags); 1911 1912 /** 1913 * @brief Get data buffer for a resource 1914 * 1915 * Use this function to get the data buffer information for the specified LwM2M 1916 * resource. 1917 * 1918 * If you directly write into the buffer, you must use lwm2m_set_res_data_len() 1919 * function to update the new size of the written data. 1920 * 1921 * All parameters, except for the pathstr, can be NULL if you don't want to read those values. 1922 * 1923 * @param[in] path LwM2M path as a struct 1924 * @param[out] buffer_ptr Data buffer pointer 1925 * @param[out] buffer_len Length of buffer 1926 * @param[out] data_len Length of existing data in the buffer 1927 * @param[out] data_flags Data buffer flags (such as read-only, etc) 1928 * 1929 * @return 0 for success or negative in case of error. 1930 */ 1931 int lwm2m_get_res_buf(const struct lwm2m_obj_path *path, void **buffer_ptr, uint16_t *buffer_len, 1932 uint16_t *data_len, uint8_t *data_flags); 1933 1934 /** 1935 * @brief Get data buffer for a resource 1936 * 1937 * Use this function to get the data buffer information for the specified LwM2M 1938 * resource. 1939 * 1940 * @deprecated Use lwm2m_get_res_buf() as it can tell you the size of the buffer as well. 1941 * 1942 * @param[in] pathstr LwM2M path string "obj/obj-inst/res(/res-inst)" 1943 * @param[out] data_ptr Data buffer pointer 1944 * @param[out] data_len Length of existing data in the buffer 1945 * @param[out] data_flags Data buffer flags (such as read-only, etc) 1946 * 1947 * @return 0 for success or negative in case of error. 1948 */ 1949 __deprecated 1950 int lwm2m_engine_get_res_data(const char *pathstr, void **data_ptr, uint16_t *data_len, 1951 uint8_t *data_flags); 1952 1953 /** 1954 * @brief Create a resource instance 1955 * 1956 * @deprecated Use lwm2m_create_res_inst() instead. 1957 * 1958 * LwM2M clients use this function to create multi-resource instances: 1959 * Example to create 0 instance of device available power sources: 1960 * lwm2m_engine_create_res_inst("3/0/6/0"); 1961 * 1962 * @param[in] pathstr LwM2M path string "obj/obj-inst/res/res-inst" 1963 * 1964 * @return 0 for success or negative in case of error. 1965 */ 1966 __deprecated 1967 int lwm2m_engine_create_res_inst(const char *pathstr); 1968 1969 /** 1970 * @brief Create a resource instance 1971 * 1972 * LwM2M clients use this function to create multi-resource instances: 1973 * Example to create 0 instance of device available power sources: 1974 * lwm2m_create_res_inst(&LWM2M_OBJ(3, 0, 6, 0)); 1975 * 1976 * @param[in] path LwM2M path as a struct 1977 * 1978 * @return 0 for success or negative in case of error. 1979 */ 1980 int lwm2m_create_res_inst(const struct lwm2m_obj_path *path); 1981 1982 /** 1983 * @brief Delete a resource instance 1984 * 1985 * @deprecated Use lwm2m_delete_res_inst() instead. 1986 * 1987 * Use this function to remove an existing resource instance 1988 * 1989 * @param[in] pathstr LwM2M path string "obj/obj-inst/res/res-inst" 1990 * 1991 * @return 0 for success or negative in case of error. 1992 */ 1993 __deprecated 1994 int lwm2m_engine_delete_res_inst(const char *pathstr); 1995 1996 /** 1997 * @brief Delete a resource instance 1998 * 1999 * Use this function to remove an existing resource instance 2000 * 2001 * @param[in] path LwM2M path as a struct 2002 * 2003 * @return 0 for success or negative in case of error. 2004 */ 2005 int lwm2m_delete_res_inst(const struct lwm2m_obj_path *path); 2006 2007 /** 2008 * @brief Update the period of the device service. 2009 * 2010 * Change the duration of the periodic device service that notifies the 2011 * current time. 2012 * 2013 * @param[in] period_ms New period for the device service (in milliseconds) 2014 * 2015 * @return 0 for success or negative in case of error. 2016 */ 2017 int lwm2m_update_device_service_period(uint32_t period_ms); 2018 2019 /** 2020 * @brief Check whether a path is observed 2021 * 2022 * @deprecated Use lwm2m_path_is_observed() instead. 2023 * 2024 * @param[in] pathstr LwM2M path string to check, e.g. "3/0/1" 2025 * 2026 * @return true when there exists an observation of the same level 2027 * or lower as the given path, false if it doesn't or path is not a 2028 * valid LwM2M-path. 2029 * E.g. true if path refers to a resource and the parent object has an 2030 * observation, false for the inverse. 2031 */ 2032 __deprecated 2033 bool lwm2m_engine_path_is_observed(const char *pathstr); 2034 2035 /** 2036 * @brief Check whether a path is observed 2037 * 2038 * @param[in] path LwM2M path as a struct to check 2039 * 2040 * @return true when there exists an observation of the same level 2041 * or lower as the given path, false if it doesn't or path is not a 2042 * valid LwM2M-path. 2043 * E.g. true if path refers to a resource and the parent object has an 2044 * observation, false for the inverse. 2045 */ 2046 bool lwm2m_path_is_observed(const struct lwm2m_obj_path *path); 2047 2048 /** 2049 * @brief Stop the LwM2M engine 2050 * 2051 * LwM2M clients normally do not need to call this function as it is called 2052 * within lwm2m_rd_client. However, if the client does not use the RD 2053 * client implementation, it will need to be called manually. 2054 * 2055 * @param[in] client_ctx LwM2M context 2056 * 2057 * @return 0 for success or negative in case of error. 2058 */ 2059 int lwm2m_engine_stop(struct lwm2m_ctx *client_ctx); 2060 2061 /** 2062 * @brief Start the LwM2M engine 2063 * 2064 * LwM2M clients normally do not need to call this function as it is called 2065 * by lwm2m_rd_client_start(). However, if the client does not use the RD 2066 * client implementation, it will need to be called manually. 2067 * 2068 * @param[in] client_ctx LwM2M context 2069 * 2070 * @return 0 for success or negative in case of error. 2071 */ 2072 int lwm2m_engine_start(struct lwm2m_ctx *client_ctx); 2073 2074 /** 2075 * @brief Acknowledge the currently processed request with an empty ACK. 2076 * 2077 * LwM2M engine by default sends piggybacked responses for requests. 2078 * This function allows to send an empty ACK for a request earlier (from the 2079 * application callback). The LwM2M engine will then send the actual response 2080 * as a separate CON message after all callbacks are executed. 2081 * 2082 * @param[in] client_ctx LwM2M context 2083 * 2084 */ 2085 void lwm2m_acknowledge(struct lwm2m_ctx *client_ctx); 2086 2087 /** 2088 * @brief LwM2M RD client events 2089 * 2090 * LwM2M client events are passed back to the event_cb function in 2091 * lwm2m_rd_client_start() 2092 */ 2093 enum lwm2m_rd_client_event { 2094 LWM2M_RD_CLIENT_EVENT_NONE, 2095 LWM2M_RD_CLIENT_EVENT_BOOTSTRAP_REG_FAILURE, 2096 LWM2M_RD_CLIENT_EVENT_BOOTSTRAP_REG_COMPLETE, 2097 LWM2M_RD_CLIENT_EVENT_BOOTSTRAP_TRANSFER_COMPLETE, 2098 LWM2M_RD_CLIENT_EVENT_REGISTRATION_FAILURE, 2099 LWM2M_RD_CLIENT_EVENT_REGISTRATION_COMPLETE, 2100 LWM2M_RD_CLIENT_EVENT_REG_TIMEOUT, 2101 LWM2M_RD_CLIENT_EVENT_REG_UPDATE_COMPLETE, 2102 LWM2M_RD_CLIENT_EVENT_DEREGISTER_FAILURE, 2103 LWM2M_RD_CLIENT_EVENT_DISCONNECT, 2104 LWM2M_RD_CLIENT_EVENT_QUEUE_MODE_RX_OFF, 2105 LWM2M_RD_CLIENT_EVENT_ENGINE_SUSPENDED, 2106 LWM2M_RD_CLIENT_EVENT_NETWORK_ERROR, 2107 LWM2M_RD_CLIENT_EVENT_REG_UPDATE, 2108 LWM2M_RD_CLIENT_EVENT_DEREGISTER, 2109 LWM2M_RD_CLIENT_EVENT_SERVER_DISABLED, 2110 }; 2111 2112 /** 2113 * Define for old event name keeping backward compatibility. 2114 */ 2115 #define LWM2M_RD_CLIENT_EVENT_REG_UPDATE_FAILURE \ 2116 LWM2M_RD_CLIENT_EVENT_REG_TIMEOUT __DEPRECATED_MACRO 2117 2118 /* 2119 * LwM2M RD client flags, used to configure LwM2M session. 2120 */ 2121 2122 /** 2123 * @brief Run bootstrap procedure in current session. 2124 */ 2125 #define LWM2M_RD_CLIENT_FLAG_BOOTSTRAP BIT(0) 2126 2127 /** 2128 * @brief Start the LwM2M RD (Registration / Discovery) Client 2129 * 2130 * The RD client sits just above the LwM2M engine and performs the necessary 2131 * actions to implement the "Registration interface". 2132 * For more information see Section "Client Registration Interface" of 2133 * LwM2M Technical Specification. 2134 * 2135 * NOTE: lwm2m_engine_start() is called automatically by this function. 2136 * 2137 * @param[in] client_ctx LwM2M context 2138 * @param[in] ep_name Registered endpoint name 2139 * @param[in] flags Flags used to configure current LwM2M session. 2140 * @param[in] event_cb Client event callback function 2141 * @param[in] observe_cb Observe callback function called when an observer was 2142 * added or deleted, and when a notification was acked or 2143 * has timed out 2144 * 2145 * @return 0 for success, -EINPROGRESS when client is already running 2146 * or negative error codes in case of failure. 2147 */ 2148 int lwm2m_rd_client_start(struct lwm2m_ctx *client_ctx, const char *ep_name, 2149 uint32_t flags, lwm2m_ctx_event_cb_t event_cb, 2150 lwm2m_observe_cb_t observe_cb); 2151 2152 /** 2153 * @brief Stop the LwM2M RD (De-register) Client 2154 * 2155 * The RD client sits just above the LwM2M engine and performs the necessary 2156 * actions to implement the "Registration interface". 2157 * For more information see Section "Client Registration Interface" of the 2158 * LwM2M Technical Specification. 2159 * 2160 * @param[in] client_ctx LwM2M context 2161 * @param[in] event_cb Client event callback function 2162 * @param[in] deregister True to deregister the client if registered. 2163 * False to force close the connection. 2164 * 2165 * @return 0 for success or negative in case of error. 2166 */ 2167 int lwm2m_rd_client_stop(struct lwm2m_ctx *client_ctx, 2168 lwm2m_ctx_event_cb_t event_cb, bool deregister); 2169 2170 /** 2171 * @brief Suspend the LwM2M engine Thread 2172 * 2173 * Suspend LwM2M engine. Use case could be when network connection is down. 2174 * LwM2M Engine indicate before it suspend by 2175 * LWM2M_RD_CLIENT_EVENT_ENGINE_SUSPENDED event. 2176 * 2177 * @return 0 for success or negative in case of error. 2178 */ 2179 int lwm2m_engine_pause(void); 2180 2181 /** 2182 * @brief Resume the LwM2M engine thread 2183 * 2184 * Resume suspended LwM2M engine. After successful resume call engine will do 2185 * full registration or registration update based on suspended time. 2186 * Event's LWM2M_RD_CLIENT_EVENT_REGISTRATION_COMPLETE or LWM2M_RD_CLIENT_EVENT_REG_UPDATE_COMPLETE 2187 * indicate that client is connected to server. 2188 * 2189 * @return 0 for success or negative in case of error. 2190 */ 2191 int lwm2m_engine_resume(void); 2192 2193 /** 2194 * @brief Trigger a Registration Update of the LwM2M RD Client 2195 */ 2196 void lwm2m_rd_client_update(void); 2197 2198 /** 2199 * @brief LwM2M path maximum length 2200 */ 2201 #define LWM2M_MAX_PATH_STR_SIZE sizeof("/65535/65535/65535/65535") 2202 2203 /** 2204 * @brief Helper function to print path objects' contents to log 2205 * 2206 * @param[in] buf The buffer to use for formatting the string 2207 * @param[in] path The path to stringify 2208 * 2209 * @return Resulting formatted path string 2210 */ 2211 char *lwm2m_path_log_buf(char *buf, struct lwm2m_obj_path *path); 2212 2213 /** 2214 * @brief LwM2M send status 2215 * 2216 * LwM2M send status are generated back to the lwm2m_send_cb_t function in 2217 * lwm2m_send_cb() 2218 */ 2219 enum lwm2m_send_status { 2220 LWM2M_SEND_STATUS_SUCCESS, 2221 LWM2M_SEND_STATUS_FAILURE, 2222 LWM2M_SEND_STATUS_TIMEOUT, 2223 }; 2224 2225 /** 2226 * @typedef lwm2m_send_cb_t 2227 * @brief Callback returning send status 2228 */ 2229 typedef void (*lwm2m_send_cb_t)(enum lwm2m_send_status status); 2230 2231 /** 2232 * @brief LwM2M SEND operation to given path list 2233 * 2234 * @deprecated Use lwm2m_send_cb() instead. 2235 * 2236 * @param ctx LwM2M context 2237 * @param path_list LwM2M Path string list 2238 * @param path_list_size Length of path list. Max size is CONFIG_LWM2M_COMPOSITE_PATH_LIST_SIZE 2239 * @param confirmation_request True request confirmation for operation. 2240 * 2241 * @return 0 for success or negative in case of error. 2242 * 2243 */ 2244 __deprecated 2245 int lwm2m_engine_send(struct lwm2m_ctx *ctx, char const *path_list[], uint8_t path_list_size, 2246 bool confirmation_request); 2247 2248 /** 2249 * @brief LwM2M SEND operation to given path list 2250 * 2251 * @deprecated Use lwm2m_send_cb() instead. 2252 * 2253 * @param ctx LwM2M context 2254 * @param path_list LwM2M path struct list 2255 * @param path_list_size Length of path list. Max size is CONFIG_LWM2M_COMPOSITE_PATH_LIST_SIZE 2256 * @param confirmation_request True request confirmation for operation. 2257 * 2258 * @return 0 for success or negative in case of error. 2259 * 2260 */ 2261 __deprecated 2262 int lwm2m_send(struct lwm2m_ctx *ctx, const struct lwm2m_obj_path path_list[], 2263 uint8_t path_list_size, bool confirmation_request); 2264 2265 /** 2266 * @brief LwM2M SEND operation to given path list asynchronously with confirmation callback 2267 * 2268 * @param ctx LwM2M context 2269 * @param path_list LwM2M path struct list 2270 * @param path_list_size Length of path list. Max size is CONFIG_LWM2M_COMPOSITE_PATH_LIST_SIZE 2271 * @param reply_cb Callback triggered with confirmation state or NULL if not used 2272 * 2273 * @return 0 for success or negative in case of error. 2274 * 2275 */ 2276 int lwm2m_send_cb(struct lwm2m_ctx *ctx, const struct lwm2m_obj_path path_list[], 2277 uint8_t path_list_size, lwm2m_send_cb_t reply_cb); 2278 2279 /** 2280 * @brief Returns LwM2M client context 2281 * 2282 * @return ctx LwM2M context 2283 * 2284 */ 2285 struct lwm2m_ctx *lwm2m_rd_client_ctx(void); 2286 2287 /** 2288 * @brief Enable data cache for a resource. 2289 * 2290 * @deprecated Use lwm2m_enable_cache instead 2291 * 2292 * Application may enable caching of resource data by allocating buffer for LwM2M engine to use. 2293 * Buffer must be size of struct @ref lwm2m_time_series_elem times cache_len 2294 * 2295 * @param resource_path LwM2M resourcepath string "obj/obj-inst/res(/res-inst)" 2296 * @param data_cache Pointer to Data cache array 2297 * @param cache_len number of cached entries 2298 * 2299 * @return 0 for success or negative in case of error. 2300 * 2301 */ 2302 __deprecated 2303 int lwm2m_engine_enable_cache(char const *resource_path, struct lwm2m_time_series_elem *data_cache, 2304 size_t cache_len); 2305 2306 /** 2307 * @brief Enable data cache for a resource. 2308 * 2309 * Application may enable caching of resource data by allocating buffer for LwM2M engine to use. 2310 * Buffer must be size of struct @ref lwm2m_time_series_elem times cache_len 2311 * 2312 * @param path LwM2M path to resource as a struct 2313 * @param data_cache Pointer to Data cache array 2314 * @param cache_len number of cached entries 2315 * 2316 * @return 0 for success or negative in case of error. 2317 * 2318 */ 2319 int lwm2m_enable_cache(const struct lwm2m_obj_path *path, struct lwm2m_time_series_elem *data_cache, 2320 size_t cache_len); 2321 2322 /** 2323 * @brief Security modes as defined in LwM2M Security object. 2324 */ 2325 enum lwm2m_security_mode_e { 2326 LWM2M_SECURITY_PSK = 0, /**< Pre-Shared Key mode */ 2327 LWM2M_SECURITY_RAW_PK = 1, /**< Raw Public Key mode */ 2328 LWM2M_SECURITY_CERT = 2, /**< Certificate mode */ 2329 LWM2M_SECURITY_NOSEC = 3, /**< NoSec mode */ 2330 LWM2M_SECURITY_CERT_EST = 4, /**< Certificate mode with EST */ 2331 }; 2332 2333 /** 2334 * @brief Read security mode from selected security object instance. 2335 * 2336 * This data is valid only if RD client is running. 2337 * 2338 * @param ctx Pointer to client context. 2339 * @return int Positive values are @ref lwm2m_security_mode_e, negative error codes otherwise. 2340 */ 2341 int lwm2m_security_mode(struct lwm2m_ctx *ctx); 2342 2343 /** 2344 * @brief Set default socket options for DTLS connections. 2345 * 2346 * The engine calls this when @ref lwm2m_ctx::set_socketoptions is not overwritten. 2347 * You can call this from the overwritten callback to set extra options after or 2348 * before defaults. 2349 * 2350 * @param ctx Client context 2351 * @return 0 for success or negative in case of error. 2352 */ 2353 int lwm2m_set_default_sockopt(struct lwm2m_ctx *ctx); 2354 2355 #endif /* ZEPHYR_INCLUDE_NET_LWM2M_H_ */ 2356 /**@} */ 2357