@@ -935,23 +935,53 @@ static int do_write_op_tlv_item(struct lwm2m_message *msg)
935935 return ret ;
936936}
937937
938+ static int write_tlv_resource (struct lwm2m_message * msg , struct oma_tlv * tlv )
939+ {
940+ int ret ;
941+
942+ if (msg -> in .block_ctx ) {
943+ msg -> in .block_ctx -> res_id = tlv -> id ;
944+ }
945+
946+ msg -> path .res_id = tlv -> id ;
947+ msg -> path .level = 3U ;
948+ ret = do_write_op_tlv_item (msg );
949+
950+ /*
951+ * ignore errors for CREATE op
952+ * for OP_CREATE and BOOTSTRAP WRITE: errors on
953+ * optional resources are ignored (ENOTSUP)
954+ */
955+ if (ret < 0 &&
956+ !((ret == - ENOTSUP ) &&
957+ (msg -> ctx -> bootstrap_mode ||
958+ msg -> operation == LWM2M_OP_CREATE ))) {
959+ return ret ;
960+ }
961+
962+ return 0 ;
963+ }
964+
938965int do_write_op_tlv (struct lwm2m_message * msg )
939966{
940967 struct lwm2m_engine_obj_inst * obj_inst = NULL ;
941968 size_t len ;
942969 struct oma_tlv tlv ;
943970 int ret ;
944971
945- /* In case of Firmware object Package resource go directly to the
972+ /* In case of block transfer go directly to the
946973 * message processing - consecutive blocks will not carry the TLV
947974 * header.
948975 */
949- if (msg -> in .block_ctx != NULL && msg -> in .block_ctx -> ctx .current > 0 &&
950- msg -> path .obj_id == 5 && msg -> path .res_id == 0 ) {
976+ if (msg -> in .block_ctx != NULL && msg -> in .block_ctx -> ctx .current > 0 ) {
977+ msg -> path .res_id = msg -> in .block_ctx -> res_id ;
978+ msg -> path .level = 3U ;
951979 ret = do_write_op_tlv_item (msg );
952980 if (ret < 0 ) {
953981 return ret ;
954982 }
983+
984+ return 0 ;
955985 }
956986
957987 while (true) {
@@ -995,36 +1025,16 @@ int do_write_op_tlv(struct lwm2m_message *msg)
9951025 continue ;
9961026 }
9971027
998- msg -> path .res_id = tlv2 .id ;
999- msg -> path .level = 3U ;
1000- ret = do_write_op_tlv_item (msg );
1001- /*
1002- * ignore errors for CREATE op
1003- * for OP_CREATE and BOOTSTRAP WRITE: errors on
1004- * optional resources are ignored (ENOTSUP)
1005- */
1006- if (ret < 0 &&
1007- !((ret == - ENOTSUP ) &&
1008- (msg -> ctx -> bootstrap_mode ||
1009- msg -> operation == LWM2M_OP_CREATE ))) {
1028+ ret = write_tlv_resource (msg , & tlv2 );
1029+ if (ret ) {
10101030 return ret ;
10111031 }
10121032
10131033 pos += len2 ;
10141034 }
10151035 } else if (tlv .type == OMA_TLV_TYPE_RESOURCE ) {
1016- msg -> path .res_id = tlv .id ;
1017- msg -> path .level = 3U ;
1018- ret = do_write_op_tlv_item (msg );
1019- /*
1020- * ignore errors for CREATE op
1021- * for OP_CREATE and BOOTSTRAP WRITE: errors on optional
1022- * resources are ignored (ENOTSUP)
1023- */
1024- if (ret < 0 &&
1025- !((ret == - ENOTSUP ) &&
1026- (msg -> ctx -> bootstrap_mode ||
1027- msg -> operation == LWM2M_OP_CREATE ))) {
1036+ ret = write_tlv_resource (msg , & tlv );
1037+ if (ret ) {
10281038 return ret ;
10291039 }
10301040 } else {
0 commit comments