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