Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 | /* * Copyright (c) 2017 Linaro Limited * Copyright (c) 2018-2019 Foundries.io * * SPDX-License-Identifier: Apache-2.0 */ /* * Copyright (c) 2016, Eistec AB. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * Original Authors: * Joakim Nohlgård <joakim.nohlgard@eistec.se> * Joakim Eriksson <joakime@sics.se> added JSON reader parts */ /* * Zephyr Contribution by Michael Scott <michael.scott@linaro.org> * - Zephyr code style changes / code cleanup * - Move to Zephyr APIs where possible * - Convert to Zephyr int/uint types * - Remove engine dependency (replace with writer/reader context) * - Add write / read int64 functions */ /* * TODO: * - Debug formatting errors in Leshan * - Replace magic #'s with defines * - Research using Zephyr JSON lib for json_next_token() */ #define LOG_MODULE_NAME net_lwm2m_json #define LOG_LEVEL CONFIG_LWM2M_LOG_LEVEL #include <logging/log.h> LOG_MODULE_REGISTER(LOG_MODULE_NAME); #include <stdio.h> #include <stddef.h> #include <stdint.h> #include <inttypes.h> #include <ctype.h> #include "lwm2m_object.h" #include "lwm2m_rw_json.h" #include "lwm2m_rw_plain_text.h" #include "lwm2m_engine.h" #define T_OBJECT_BEGIN BIT(0) #define T_OBJECT_END BIT(1) #define T_STRING_BEGIN BIT(2) #define T_STRING_END BIT(3) #define T_VALUE BIT(4) #define SEPARATOR(f) ((f & WRITER_OUTPUT_VALUE) ? "," : "") /* writer modes */ #define MODE_NONE 0 #define MODE_INSTANCE 1 #define MODE_VALUE 2 #define MODE_READY 3 #define TOKEN_BUF_LEN 64 struct json_out_formatter_data { /* offset position storage */ u16_t mark_pos_ri; /* flags */ u8_t writer_flags; /* path storage */ u8_t path_level; }; struct json_in_formatter_data { /* name info */ u16_t name_offset; u16_t name_len; /* value info */ u16_t value_offset; u16_t value_len; /* state */ u16_t offset; /* flags */ u8_t json_flags; }; /* some temporary buffer space for format conversions */ static char json_buffer[TOKEN_BUF_LEN]; static void json_add_char(struct lwm2m_input_context *in, struct json_in_formatter_data *fd) { if ((fd->json_flags & T_VALUE) || ((fd->json_flags & T_STRING_BEGIN) && !(fd->json_flags & T_STRING_END))) { if (fd->json_flags & T_VALUE) { fd->value_len++; if (fd->value_len == 1U) { fd->value_offset = fd->offset; } } else { fd->name_len++; if (fd->name_len == 1U) { fd->name_offset = fd->offset; } } } } /* Simlified JSON style reader for reading in values from a LWM2M JSON string */ static int json_next_token(struct lwm2m_input_context *in, struct json_in_formatter_data *fd) { u8_t cont, c; bool escape = false; (void)memset(fd, 0, sizeof(*fd)); cont = 1U; /* We will be either at start, or at a specific position */ while (in->offset < in->in_cpkt->offset && cont) { fd->offset = in->offset; if (buf_read_u8(&c, CPKT_BUF_READ(in->in_cpkt), &in->offset) < 0) { break; } if (c == '\\') { escape = true; /* Keep track of the escape codes */ json_add_char(in, fd); continue; } switch (c) { case '[': if (!escape) { fd->json_flags |= T_OBJECT_BEGIN; cont = 0U; } else { json_add_char(in, fd); } break; case ']': if (!escape) { fd->json_flags |= T_OBJECT_END; cont = 0U; } else { json_add_char(in, fd); } break; case '{': if (!escape) { fd->json_flags |= T_OBJECT_BEGIN; } else { json_add_char(in, fd); } break; case '}': case ',': if (!escape) { cont = 0U; } else { json_add_char(in, fd); } break; case '"': if (!escape) { if (fd->json_flags & T_STRING_BEGIN) { fd->json_flags &= ~T_STRING_BEGIN; fd->json_flags |= T_STRING_END; } else { fd->json_flags &= ~T_STRING_END; fd->json_flags |= T_STRING_BEGIN; } } else { json_add_char(in, fd); } break; case ':': if (!escape) { fd->json_flags &= ~T_STRING_END; fd->json_flags |= T_VALUE; } else { json_add_char(in, fd); } break; /* ignore whitespace */ case ' ': case '\n': case '\t': if (!(fd->json_flags & T_STRING_BEGIN)) { break; } /* fallthrough */ default: json_add_char(in, fd); } if (escape) { escape = false; } } /* OK if cont == 0 othewise we failed */ return (cont == 0U); } static size_t put_begin(struct lwm2m_output_context *out, struct lwm2m_obj_path *path) { int len = -1; if (path->level >= 2U) { len = snprintk(json_buffer, sizeof(json_buffer), "{\"bn\":\"/%u/%u/\",\"e\":[", path->obj_id, path->obj_inst_id); } else { len = snprintk(json_buffer, sizeof(json_buffer), "{\"bn\":\"/%u/\",\"e\":[", path->obj_id); } if (len < 0) { /* TODO: Generate error? */ return 0; } if (buf_append(CPKT_BUF_WRITE(out->out_cpkt), json_buffer, len) < 0) { /* TODO: Generate error? */ return 0; } return (size_t)len; } static size_t put_end(struct lwm2m_output_context *out, struct lwm2m_obj_path *path) { if (buf_append(CPKT_BUF_WRITE(out->out_cpkt), "]}", 2) < 0) { /* TODO: Generate error? */ return 0; } return 2; } static size_t put_begin_ri(struct lwm2m_output_context *out, struct lwm2m_obj_path *path) { struct json_out_formatter_data *fd; fd = engine_get_out_user_data(out); if (!fd) { return 0; } fd->writer_flags |= WRITER_RESOURCE_INSTANCE; return 0; } static size_t put_end_ri(struct lwm2m_output_context *out, struct lwm2m_obj_path *path) { struct json_out_formatter_data *fd; fd = engine_get_out_user_data(out); if (!fd) { return 0; } fd->writer_flags &= ~WRITER_RESOURCE_INSTANCE; return 0; } static size_t put_char(struct lwm2m_output_context *out, char c) { if (buf_append(CPKT_BUF_WRITE(out->out_cpkt), &c, sizeof(c)) < 0) { /* TODO: Generate error? */ return 0; } return 1; } static size_t put_json_prefix(struct lwm2m_output_context *out, struct lwm2m_obj_path *path, const char *format) { struct json_out_formatter_data *fd; char *sep; int len = 0; fd = engine_get_out_user_data(out); if (!fd) { return 0; } sep = SEPARATOR(fd->writer_flags); if (fd->path_level >= 2U) { if (fd->writer_flags & WRITER_RESOURCE_INSTANCE) { len = snprintk(json_buffer, sizeof(json_buffer), "%s{\"n\":\"%u/%u\",%s:", sep, path->res_id, path->res_inst_id, format); } else { len = snprintk(json_buffer, sizeof(json_buffer), "%s{\"n\":\"%u\",%s:", sep, path->res_id, format); } } else { if (fd->writer_flags & WRITER_RESOURCE_INSTANCE) { len = snprintk(json_buffer, sizeof(json_buffer), "%s{\"n\":\"%u/%u/%u\",%s:", sep, path->obj_inst_id, path->res_id, path->res_inst_id, format); } else { len = snprintk(json_buffer, sizeof(json_buffer), "%s{\"n\":\"%u/%u\",%s:", sep, path->obj_inst_id, path->res_id, format); } } if (len < 0) { /* TODO: Generate error? */ return 0; } if (buf_append(CPKT_BUF_WRITE(out->out_cpkt), json_buffer, len) < 0) { /* TODO: Generate error? */ return 0; } return len; } static size_t put_json_postfix(struct lwm2m_output_context *out) { struct json_out_formatter_data *fd; fd = engine_get_out_user_data(out); if (!fd) { return 0; } if (put_char(out, '}') < 1) { /* TODO: Generate error? */ return 0; } fd->writer_flags |= WRITER_OUTPUT_VALUE; return 1; } static size_t put_s32(struct lwm2m_output_context *out, struct lwm2m_obj_path *path, s32_t value) { int len; len = put_json_prefix(out, path, "\"v\""); len += plain_text_put_format(out, "%d", value); len += put_json_postfix(out); return (size_t)len; } static size_t put_s16(struct lwm2m_output_context *out, struct lwm2m_obj_path *path, s16_t value) { return put_s32(out, path, (s32_t)value); } static size_t put_s8(struct lwm2m_output_context *out, struct lwm2m_obj_path *path, s8_t value) { return put_s32(out, path, (s32_t)value); } static size_t put_s64(struct lwm2m_output_context *out, struct lwm2m_obj_path *path, s64_t value) { int len; len = put_json_prefix(out, path, "\"v\""); len += plain_text_put_format(out, "%lld", value); len += put_json_postfix(out); return (size_t)len; } static size_t put_string(struct lwm2m_output_context *out, struct lwm2m_obj_path *path, char *buf, size_t buflen) { size_t i; size_t len = 0; int res; res = put_json_prefix(out, path, "\"sv\""); res += put_char(out, '"'); if (res < 0) { /* TODO: Generate error? */ return 0; } len += res; for (i = 0; i < buflen; ++i) { /* Escape special characters */ /* TODO: Handle UTF-8 strings */ if (buf[i] < '\x20') { res = snprintk(json_buffer, sizeof(json_buffer), "\\x%x", buf[i]); if (res < 0) { /* TODO: Generate error? */ return 0; } if (buf_append(CPKT_BUF_WRITE(out->out_cpkt), json_buffer, res) < 0) { /* TODO: Generate error? */ return 0; } len += res; continue; } else if (buf[i] == '"' || buf[i] == '\\') { len += put_char(out, '\\'); } len += put_char(out, buf[i]); } res = put_char(out, '"'); if (res < 0) { /* TODO: Generate error? */ return 0; } len += res; len += put_json_postfix(out); return len; } static size_t put_float32fix(struct lwm2m_output_context *out, struct lwm2m_obj_path *path, float32_value_t *value) { size_t len; len = put_json_prefix(out, path, "\"v\""); len += plain_text_put_float32fix(out, path, value); len += put_json_postfix(out); return len; } static size_t put_float64fix(struct lwm2m_output_context *out, struct lwm2m_obj_path *path, float64_value_t *value) { size_t len; len = put_json_prefix(out, path, "\"v\""); len += plain_text_put_float64fix(out, path, value); len += put_json_postfix(out); return len; } static size_t put_bool(struct lwm2m_output_context *out, struct lwm2m_obj_path *path, bool value) { size_t len; len = put_json_prefix(out, path, "\"bv\""); len += plain_text_put_format(out, "%s", value ? "true" : "false"); len += put_json_postfix(out); return (size_t)len; } static size_t read_number(struct lwm2m_input_context *in, s64_t *value1, s64_t *value2, bool accept_sign, bool accept_dot) { struct json_in_formatter_data *fd; s64_t *counter = value1; u8_t *buf; size_t i = 0; bool neg = false; bool dot_found = false; char c; /* initialize values to 0 */ *value1 = 0; if (value2) { *value2 = 0; } fd = engine_get_in_user_data(in); if (!fd) { return 0; } buf = in->in_cpkt->data + fd->value_offset; while (*(buf + i) && i < fd->value_len) { c = *(buf + i); if (c == '-' && accept_sign && i == 0) { neg = true; } else if (c == '.' && i > 0 && accept_dot && !dot_found && value2) { dot_found = true; counter = value2; } else if (isdigit(c)) { *counter = *counter * 10 + (c - '0'); } else { /* anything else stop reading */ break; } i++; } if (neg) { *value1 = -*value1; } return i; } static size_t get_s64(struct lwm2m_input_context *in, s64_t *value) { return read_number(in, value, NULL, true, true); } static size_t get_s32(struct lwm2m_input_context *in, s32_t *value) { s64_t tmp = 0; size_t len = 0; len = read_number(in, &tmp, NULL, true, true); if (len > 0) { *value = (s32_t)tmp; } return len; } static size_t get_string(struct lwm2m_input_context *in, u8_t *buf, size_t buflen) { struct json_in_formatter_data *fd; int ret; fd = engine_get_in_user_data(in); if (!fd) { return 0; } if (fd->value_len > buflen) { /* TODO: generate warning? */ fd->value_len = buflen - 1; } /* TODO: Handle escape codes */ ret = buf_read(buf, fd->value_len, CPKT_BUF_READ(in->in_cpkt), &fd->value_offset); if (ret < 0) { return 0; } return fd->value_len; } static size_t get_float32fix(struct lwm2m_input_context *in, float32_value_t *value) { s64_t tmp1, tmp2; size_t len; len = read_number(in, &tmp1, &tmp2, true, true); if (len > 0) { value->val1 = (s32_t)tmp1; value->val2 = (s32_t)tmp2; } return len; } static size_t get_float64fix(struct lwm2m_input_context *in, float64_value_t *value) { s64_t tmp1, tmp2; size_t len; len = read_number(in, &tmp1, &tmp2, true, true); if (len > 0) { value->val1 = tmp1; value->val2 = tmp2; } return len; } static size_t get_bool(struct lwm2m_input_context *in, bool *value) { struct json_in_formatter_data *fd; fd = engine_get_in_user_data(in); if (!fd) { return 0; } if (strncmp(in->in_cpkt->data + fd->value_offset, "true", 4) == 0) { *value = true; } else if (strncmp(in->in_cpkt->data + fd->value_offset, "false", 5) == 0) { *value = false; } return fd->value_len; } static size_t get_opaque(struct lwm2m_input_context *in, u8_t *value, size_t buflen, bool *last_block) { /* TODO */ return 0; } const struct lwm2m_writer json_writer = { .put_begin = put_begin, .put_end = put_end, .put_begin_ri = put_begin_ri, .put_end_ri = put_end_ri, .put_s8 = put_s8, .put_s16 = put_s16, .put_s32 = put_s32, .put_s64 = put_s64, .put_string = put_string, .put_float32fix = put_float32fix, .put_float64fix = put_float64fix, .put_bool = put_bool, }; const struct lwm2m_reader json_reader = { .get_s32 = get_s32, .get_s64 = get_s64, .get_string = get_string, .get_float32fix = get_float32fix, .get_float64fix = get_float64fix, .get_bool = get_bool, .get_opaque = get_opaque, }; int do_read_op_json(struct lwm2m_message *msg, int content_format) { struct json_out_formatter_data fd; int ret; (void)memset(&fd, 0, sizeof(fd)); engine_set_out_user_data(&msg->out, &fd); /* save the level for output processing */ fd.path_level = msg->path.level; ret = lwm2m_perform_read_op(msg, content_format); engine_clear_out_user_data(&msg->out); return ret; } static int parse_path(const u8_t *buf, u16_t buflen, struct lwm2m_obj_path *path) { int ret = 0; int pos = 0; u16_t val; u8_t c = 0U; (void)memset(path, 0, sizeof(*path)); do { val = 0U; c = buf[pos]; /* we should get a value first - consume all numbers */ while (pos < buflen && isdigit(c)) { val = val * 10U + (c - '0'); c = buf[++pos]; } /* slash will mote thing forward */ if (pos == 0 && c == '/') { /* skip leading slashes */ pos++; } else if (c == '/' || pos == buflen) { LOG_DBG("Setting %u = %u", ret, val); if (ret == 0) { path->obj_id = val; } else if (ret == 1) { path->obj_inst_id = val; } else if (ret == 2) { path->res_id = val; } else if (ret == 3) { path->res_inst_id = val; } ret++; pos++; } else { LOG_ERR("Error: illegal char '%c' at pos:%d", c, pos); return -1; } } while (pos < buflen); return ret; } int do_write_op_json(struct lwm2m_message *msg) { struct lwm2m_engine_obj_field *obj_field = NULL; struct lwm2m_engine_obj_inst *obj_inst = NULL; struct lwm2m_engine_res *res = NULL; struct lwm2m_engine_res_inst *res_inst = NULL; struct lwm2m_obj_path orig_path; struct json_in_formatter_data fd; int ret = 0, index; u8_t value[TOKEN_BUF_LEN]; u8_t base_name[MAX_RESOURCE_LEN]; u8_t full_name[MAX_RESOURCE_LEN]; u8_t created; (void)memset(&fd, 0, sizeof(fd)); engine_set_in_user_data(&msg->in, &fd); /* store a copy of the original path */ memcpy(&orig_path, &msg->path, sizeof(msg->path)); /* PARSE base name "bn" */ json_next_token(&msg->in, &fd); /* TODO: validate name == "bn" */ if (buf_read(base_name, fd.value_len, CPKT_BUF_READ(msg->in.in_cpkt), &fd.value_offset) < 0) { LOG_ERR("Error parsing base name!"); return -EINVAL; } /* skip to elements */ json_next_token(&msg->in, &fd); /* TODO: validate name == "bv" */ while (json_next_token(&msg->in, &fd)) { if (!(fd.json_flags & T_VALUE)) { continue; } if (buf_read(value, fd.name_len, CPKT_BUF_READ(msg->in.in_cpkt), &fd.name_offset) < 0) { LOG_ERR("Error parsing name!"); continue; } /* handle resource name */ if (value[0] == 'n') { /* reset values */ created = 0U; /* get value for relative path */ if (buf_read(value, fd.value_len, CPKT_BUF_READ(msg->in.in_cpkt), &fd.value_offset) < 0) { LOG_ERR("Error parsing relative path!"); continue; } /* combine base_name + name */ snprintf(full_name, TOKEN_BUF_LEN, "%s%s", base_name, value); /* parse full_name into path */ ret = parse_path(full_name, strlen(full_name), &msg->path); if (ret < 0) { break; } /* if valid, use the return value as level */ msg->path.level = ret; ret = lwm2m_get_or_create_engine_obj(msg, &obj_inst, &created); if (ret < 0) { break; } obj_field = lwm2m_get_engine_obj_field( obj_inst->obj, msg->path.res_id); /* * if obj_field is not found, * treat as an optional resource */ if (!obj_field) { ret = -ENOENT; break; } /* * TODO: support BOOTSTRAP WRITE where optional * resources are ignored */ if (!LWM2M_HAS_PERM(obj_field, LWM2M_PERM_W)) { ret = -EPERM; break; } if (!obj_inst->resources || obj_inst->resource_count == 0U) { ret = -EINVAL; break; } for (index = 0; index < obj_inst->resource_count; index++) { if (obj_inst->resources[index].res_id == msg->path.res_id) { res = &obj_inst->resources[index]; break; } } if (!res) { ret = -ENOENT; break; } for (index = 0; index < res->res_inst_count; index++) { if (res->res_instances[index].res_inst_id == msg->path.res_inst_id) { res_inst = &res->res_instances[index]; break; } } if (!res_inst) { ret = -ENOENT; break; } } else if (res && res_inst) { /* handle value assignment */ ret = lwm2m_write_handler(obj_inst, res, res_inst, obj_field, msg); if (orig_path.level >= 3U && ret < 0) { /* return errors on a single write */ break; } } else { /* complain about error? */ } } engine_clear_in_user_data(&msg->in); return ret; } |