FRDM K64F Metronome

Committer:
ram54288
Date:
Sun May 14 18:37:05 2017 +0000
Revision:
0:dbad57390bd1
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ram54288 0:dbad57390bd1 1 /*
ram54288 0:dbad57390bd1 2 * Copyright (c) 2015 ARM Limited. All rights reserved.
ram54288 0:dbad57390bd1 3 * SPDX-License-Identifier: Apache-2.0
ram54288 0:dbad57390bd1 4 * Licensed under the Apache License, Version 2.0 (the License); you may
ram54288 0:dbad57390bd1 5 * not use this file except in compliance with the License.
ram54288 0:dbad57390bd1 6 * You may obtain a copy of the License at
ram54288 0:dbad57390bd1 7 *
ram54288 0:dbad57390bd1 8 * http://www.apache.org/licenses/LICENSE-2.0
ram54288 0:dbad57390bd1 9 *
ram54288 0:dbad57390bd1 10 * Unless required by applicable law or agreed to in writing, software
ram54288 0:dbad57390bd1 11 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
ram54288 0:dbad57390bd1 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ram54288 0:dbad57390bd1 13 * See the License for the specific language governing permissions and
ram54288 0:dbad57390bd1 14 * limitations under the License.
ram54288 0:dbad57390bd1 15 */
ram54288 0:dbad57390bd1 16 #include "include/m2mtlvdeserializer.h"
ram54288 0:dbad57390bd1 17 #include "mbed-client/m2mconstants.h"
ram54288 0:dbad57390bd1 18 #include "include/nsdllinker.h"
ram54288 0:dbad57390bd1 19 #include "mbed-trace/mbed_trace.h"
ram54288 0:dbad57390bd1 20
ram54288 0:dbad57390bd1 21 #define TRACE_GROUP "mClt"
ram54288 0:dbad57390bd1 22 #define BUFFER_SIZE 10
ram54288 0:dbad57390bd1 23
ram54288 0:dbad57390bd1 24 M2MTLVDeserializer::M2MTLVDeserializer()
ram54288 0:dbad57390bd1 25 {
ram54288 0:dbad57390bd1 26 }
ram54288 0:dbad57390bd1 27
ram54288 0:dbad57390bd1 28 M2MTLVDeserializer::~M2MTLVDeserializer()
ram54288 0:dbad57390bd1 29 {
ram54288 0:dbad57390bd1 30 }
ram54288 0:dbad57390bd1 31
ram54288 0:dbad57390bd1 32 bool M2MTLVDeserializer::is_object_instance(uint8_t *tlv)
ram54288 0:dbad57390bd1 33 {
ram54288 0:dbad57390bd1 34 return is_object_instance(tlv, 0);
ram54288 0:dbad57390bd1 35 }
ram54288 0:dbad57390bd1 36
ram54288 0:dbad57390bd1 37 bool M2MTLVDeserializer::is_resource(uint8_t *tlv)
ram54288 0:dbad57390bd1 38 {
ram54288 0:dbad57390bd1 39 return is_resource(tlv, 0);
ram54288 0:dbad57390bd1 40 }
ram54288 0:dbad57390bd1 41
ram54288 0:dbad57390bd1 42 bool M2MTLVDeserializer::is_multiple_resource(uint8_t *tlv)
ram54288 0:dbad57390bd1 43 {
ram54288 0:dbad57390bd1 44 return is_multiple_resource(tlv, 0);
ram54288 0:dbad57390bd1 45 }
ram54288 0:dbad57390bd1 46
ram54288 0:dbad57390bd1 47 bool M2MTLVDeserializer::is_resource_instance(uint8_t *tlv)
ram54288 0:dbad57390bd1 48 {
ram54288 0:dbad57390bd1 49 return is_resource_instance(tlv, 0);
ram54288 0:dbad57390bd1 50 }
ram54288 0:dbad57390bd1 51
ram54288 0:dbad57390bd1 52 M2MTLVDeserializer::Error M2MTLVDeserializer::deserialise_object_instances(uint8_t* tlv,
ram54288 0:dbad57390bd1 53 uint32_t tlv_size,
ram54288 0:dbad57390bd1 54 M2MObject &object,
ram54288 0:dbad57390bd1 55 M2MTLVDeserializer::Operation operation)
ram54288 0:dbad57390bd1 56 {
ram54288 0:dbad57390bd1 57 M2MTLVDeserializer::Error error = M2MTLVDeserializer::None;
ram54288 0:dbad57390bd1 58 if (is_object_instance(tlv) ) {
ram54288 0:dbad57390bd1 59 tr_debug("M2MTLVDeserializer::deserialise_object_instances");
ram54288 0:dbad57390bd1 60 error = deserialize_object_instances(tlv, tlv_size, 0, object,operation,false);
ram54288 0:dbad57390bd1 61 if(M2MTLVDeserializer::None == error) {
ram54288 0:dbad57390bd1 62 error = deserialize_object_instances(tlv, tlv_size, 0, object,operation,true);
ram54288 0:dbad57390bd1 63 }
ram54288 0:dbad57390bd1 64 } else {
ram54288 0:dbad57390bd1 65 tr_debug("M2MTLVDeserializer::deserialise_object_instances ::NotValid");
ram54288 0:dbad57390bd1 66 error = M2MTLVDeserializer::NotValid;
ram54288 0:dbad57390bd1 67 }
ram54288 0:dbad57390bd1 68 return error;
ram54288 0:dbad57390bd1 69 }
ram54288 0:dbad57390bd1 70
ram54288 0:dbad57390bd1 71 M2MTLVDeserializer::Error M2MTLVDeserializer::deserialize_resources(uint8_t *tlv,
ram54288 0:dbad57390bd1 72 uint32_t tlv_size,
ram54288 0:dbad57390bd1 73 M2MObjectInstance &object_instance,
ram54288 0:dbad57390bd1 74 M2MTLVDeserializer::Operation operation)
ram54288 0:dbad57390bd1 75 {
ram54288 0:dbad57390bd1 76 M2MTLVDeserializer::Error error = M2MTLVDeserializer::None;
ram54288 0:dbad57390bd1 77 if (!is_resource(tlv) && !is_multiple_resource(tlv)) {
ram54288 0:dbad57390bd1 78 error = M2MTLVDeserializer::NotValid;
ram54288 0:dbad57390bd1 79 } else {
ram54288 0:dbad57390bd1 80 error = deserialize_resources(tlv, tlv_size, 0, object_instance, operation,false);
ram54288 0:dbad57390bd1 81 if(M2MTLVDeserializer::None == error) {
ram54288 0:dbad57390bd1 82 error = deserialize_resources(tlv, tlv_size, 0, object_instance, operation,true);
ram54288 0:dbad57390bd1 83 }
ram54288 0:dbad57390bd1 84 }
ram54288 0:dbad57390bd1 85 return error;
ram54288 0:dbad57390bd1 86 }
ram54288 0:dbad57390bd1 87
ram54288 0:dbad57390bd1 88 M2MTLVDeserializer::Error M2MTLVDeserializer::deserialize_resource_instances(uint8_t *tlv,
ram54288 0:dbad57390bd1 89 uint32_t tlv_size,
ram54288 0:dbad57390bd1 90 M2MResource &resource,
ram54288 0:dbad57390bd1 91 M2MTLVDeserializer::Operation operation)
ram54288 0:dbad57390bd1 92 {
ram54288 0:dbad57390bd1 93 M2MTLVDeserializer::Error error = M2MTLVDeserializer::None;
ram54288 0:dbad57390bd1 94 if (!is_multiple_resource(tlv)) {
ram54288 0:dbad57390bd1 95 error = M2MTLVDeserializer::NotValid;
ram54288 0:dbad57390bd1 96 } else {
ram54288 0:dbad57390bd1 97 tr_debug("M2MTLVDeserializer::deserialize_resource_instances()");
ram54288 0:dbad57390bd1 98 uint8_t offset = 2;
ram54288 0:dbad57390bd1 99
ram54288 0:dbad57390bd1 100 ((tlv[0] & 0x20) == 0) ? offset : offset++;
ram54288 0:dbad57390bd1 101
ram54288 0:dbad57390bd1 102 uint8_t length = tlv[0] & 0x18;
ram54288 0:dbad57390bd1 103 if(length == 0x08) {
ram54288 0:dbad57390bd1 104 offset+= 1;
ram54288 0:dbad57390bd1 105 } else if(length == 0x10) {
ram54288 0:dbad57390bd1 106 offset+= 2;
ram54288 0:dbad57390bd1 107 } else if(length == 0x18) {
ram54288 0:dbad57390bd1 108 offset+= 3;
ram54288 0:dbad57390bd1 109 }
ram54288 0:dbad57390bd1 110
ram54288 0:dbad57390bd1 111 tr_debug("M2MTLVDeserializer::deserialize_resource_instances() Offset %d", offset);
ram54288 0:dbad57390bd1 112 error = deserialize_resource_instances(tlv, tlv_size, offset, resource, operation,false);
ram54288 0:dbad57390bd1 113 if(M2MTLVDeserializer::None == error) {
ram54288 0:dbad57390bd1 114 error = deserialize_resource_instances(tlv, tlv_size, offset, resource, operation,true);
ram54288 0:dbad57390bd1 115 }
ram54288 0:dbad57390bd1 116 }
ram54288 0:dbad57390bd1 117 return error;
ram54288 0:dbad57390bd1 118 }
ram54288 0:dbad57390bd1 119
ram54288 0:dbad57390bd1 120 M2MTLVDeserializer::Error M2MTLVDeserializer::deserialize_object_instances(uint8_t *tlv,
ram54288 0:dbad57390bd1 121 uint32_t tlv_size,
ram54288 0:dbad57390bd1 122 uint32_t offset,
ram54288 0:dbad57390bd1 123 M2MObject &object,
ram54288 0:dbad57390bd1 124 M2MTLVDeserializer::Operation operation,
ram54288 0:dbad57390bd1 125 bool update_value)
ram54288 0:dbad57390bd1 126 {
ram54288 0:dbad57390bd1 127 tr_debug("M2MTLVDeserializer::deserialize_object_instances()");
ram54288 0:dbad57390bd1 128 M2MTLVDeserializer::Error error = M2MTLVDeserializer::None;
ram54288 0:dbad57390bd1 129 TypeIdLength *til = TypeIdLength::createTypeIdLength(tlv, offset)->deserialize();
ram54288 0:dbad57390bd1 130 offset = til->_offset;
ram54288 0:dbad57390bd1 131
ram54288 0:dbad57390bd1 132 M2MObjectInstanceList list = object.instances();
ram54288 0:dbad57390bd1 133 M2MObjectInstanceList::const_iterator it;
ram54288 0:dbad57390bd1 134 it = list.begin();
ram54288 0:dbad57390bd1 135
ram54288 0:dbad57390bd1 136 if (TYPE_OBJECT_INSTANCE == til->_type) {
ram54288 0:dbad57390bd1 137 for (; it!=list.end(); it++) {
ram54288 0:dbad57390bd1 138 if((*it)->instance_id() == til->_id) {
ram54288 0:dbad57390bd1 139 error = deserialize_resources(tlv, tlv_size, offset, (**it),operation, update_value);
ram54288 0:dbad57390bd1 140 }
ram54288 0:dbad57390bd1 141 }
ram54288 0:dbad57390bd1 142 offset += til->_length;
ram54288 0:dbad57390bd1 143
ram54288 0:dbad57390bd1 144 if(offset < tlv_size) {
ram54288 0:dbad57390bd1 145 error = deserialize_object_instances(tlv, tlv_size, offset, object, operation, update_value);
ram54288 0:dbad57390bd1 146 }
ram54288 0:dbad57390bd1 147 }
ram54288 0:dbad57390bd1 148 delete til;
ram54288 0:dbad57390bd1 149 return error;
ram54288 0:dbad57390bd1 150 }
ram54288 0:dbad57390bd1 151
ram54288 0:dbad57390bd1 152 M2MTLVDeserializer::Error M2MTLVDeserializer::deserialize_resources(uint8_t *tlv,
ram54288 0:dbad57390bd1 153 uint32_t tlv_size,
ram54288 0:dbad57390bd1 154 uint32_t offset,
ram54288 0:dbad57390bd1 155 M2MObjectInstance &object_instance,
ram54288 0:dbad57390bd1 156 M2MTLVDeserializer::Operation operation,
ram54288 0:dbad57390bd1 157 bool update_value)
ram54288 0:dbad57390bd1 158 {
ram54288 0:dbad57390bd1 159 tr_debug("M2MTLVDeserializer::deserialize_resources()");
ram54288 0:dbad57390bd1 160 M2MTLVDeserializer::Error error = M2MTLVDeserializer::None;
ram54288 0:dbad57390bd1 161 TypeIdLength *til = TypeIdLength::createTypeIdLength(tlv, offset)->deserialize();
ram54288 0:dbad57390bd1 162 offset = til->_offset;
ram54288 0:dbad57390bd1 163
ram54288 0:dbad57390bd1 164 M2MResourceList list = object_instance.resources();
ram54288 0:dbad57390bd1 165 M2MResourceList::const_iterator it;
ram54288 0:dbad57390bd1 166 it = list.begin();
ram54288 0:dbad57390bd1 167
ram54288 0:dbad57390bd1 168 if (TYPE_RESOURCE == til->_type || TYPE_RESOURCE_INSTANCE == til->_type) {
ram54288 0:dbad57390bd1 169 bool found = false;
ram54288 0:dbad57390bd1 170 for (; it!=list.end(); it++) {
ram54288 0:dbad57390bd1 171 if((*it)->name_id() == til->_id){
ram54288 0:dbad57390bd1 172 tr_debug("M2MTLVDeserializer::deserialize_resources() - Resource ID %d ", til->_id);
ram54288 0:dbad57390bd1 173 found = true;
ram54288 0:dbad57390bd1 174 if(update_value) {
ram54288 0:dbad57390bd1 175 if(til->_length > 0) {
ram54288 0:dbad57390bd1 176 tr_debug("M2MTLVDeserializer::deserialize_resources() - Update value");
ram54288 0:dbad57390bd1 177 (*it)->set_value(tlv+offset, til->_length);
ram54288 0:dbad57390bd1 178 } else {
ram54288 0:dbad57390bd1 179 tr_debug("M2MTLVDeserializer::deserialize_resources() - Clear Value");
ram54288 0:dbad57390bd1 180 (*it)->clear_value();
ram54288 0:dbad57390bd1 181 }
ram54288 0:dbad57390bd1 182 break;
ram54288 0:dbad57390bd1 183 } else if(0 == ((*it)->operation() & SN_GRS_PUT_ALLOWED)) {
ram54288 0:dbad57390bd1 184 tr_debug("M2MTLVDeserializer::deserialize_resources() - NOT_ALLOWED");
ram54288 0:dbad57390bd1 185 error = M2MTLVDeserializer::NotAllowed;
ram54288 0:dbad57390bd1 186 break;
ram54288 0:dbad57390bd1 187 }
ram54288 0:dbad57390bd1 188 }
ram54288 0:dbad57390bd1 189 }
ram54288 0:dbad57390bd1 190 if(!found) {
ram54288 0:dbad57390bd1 191 if(M2MTLVDeserializer::Post == operation) {
ram54288 0:dbad57390bd1 192 //Create a new Resource
ram54288 0:dbad57390bd1 193 String id;
ram54288 0:dbad57390bd1 194 id.append_int(til->_id);
ram54288 0:dbad57390bd1 195 M2MResource *resource = object_instance.create_dynamic_resource(id,"",M2MResourceInstance::INTEGER,true,false);
ram54288 0:dbad57390bd1 196 if(resource) {
ram54288 0:dbad57390bd1 197 resource->set_operation(M2MBase::GET_PUT_POST_DELETE_ALLOWED);
ram54288 0:dbad57390bd1 198 }
ram54288 0:dbad57390bd1 199 } else if(M2MTLVDeserializer::Put == operation) {
ram54288 0:dbad57390bd1 200 error = M2MTLVDeserializer::NotFound;
ram54288 0:dbad57390bd1 201 }
ram54288 0:dbad57390bd1 202 }
ram54288 0:dbad57390bd1 203 } else if (TYPE_MULTIPLE_RESOURCE == til->_type) {
ram54288 0:dbad57390bd1 204 for (; it!=list.end(); it++) {
ram54288 0:dbad57390bd1 205 if((*it)->supports_multiple_instances()) {
ram54288 0:dbad57390bd1 206 error = deserialize_resource_instances(tlv, tlv_size-offset, offset, (**it), object_instance, operation, update_value);
ram54288 0:dbad57390bd1 207 }
ram54288 0:dbad57390bd1 208 }
ram54288 0:dbad57390bd1 209
ram54288 0:dbad57390bd1 210 } else {
ram54288 0:dbad57390bd1 211 delete til;
ram54288 0:dbad57390bd1 212 error = M2MTLVDeserializer::NotValid;
ram54288 0:dbad57390bd1 213 return error;
ram54288 0:dbad57390bd1 214 }
ram54288 0:dbad57390bd1 215 offset += til->_length;
ram54288 0:dbad57390bd1 216
ram54288 0:dbad57390bd1 217 delete til;
ram54288 0:dbad57390bd1 218 if(offset < tlv_size) {
ram54288 0:dbad57390bd1 219 error = deserialize_resources(tlv, tlv_size, offset, object_instance, operation, update_value);
ram54288 0:dbad57390bd1 220 }
ram54288 0:dbad57390bd1 221 return error;
ram54288 0:dbad57390bd1 222 }
ram54288 0:dbad57390bd1 223
ram54288 0:dbad57390bd1 224 M2MTLVDeserializer::Error M2MTLVDeserializer::deserialize_resource_instances(uint8_t *tlv,
ram54288 0:dbad57390bd1 225 uint32_t tlv_size,
ram54288 0:dbad57390bd1 226 uint32_t offset,
ram54288 0:dbad57390bd1 227 M2MResource &resource,
ram54288 0:dbad57390bd1 228 M2MObjectInstance &object_instance,
ram54288 0:dbad57390bd1 229 M2MTLVDeserializer::Operation operation,
ram54288 0:dbad57390bd1 230 bool update_value)
ram54288 0:dbad57390bd1 231 {
ram54288 0:dbad57390bd1 232 M2MTLVDeserializer::Error error = M2MTLVDeserializer::None;
ram54288 0:dbad57390bd1 233 TypeIdLength *til = TypeIdLength::createTypeIdLength(tlv, offset)->deserialize();
ram54288 0:dbad57390bd1 234 offset = til->_offset;
ram54288 0:dbad57390bd1 235
ram54288 0:dbad57390bd1 236 if (TYPE_MULTIPLE_RESOURCE == til->_type || TYPE_RESOURCE_INSTANCE == til->_type) {
ram54288 0:dbad57390bd1 237 M2MResourceInstanceList list = resource.resource_instances();
ram54288 0:dbad57390bd1 238 M2MResourceInstanceList::const_iterator it;
ram54288 0:dbad57390bd1 239 it = list.begin();
ram54288 0:dbad57390bd1 240 bool found = false;
ram54288 0:dbad57390bd1 241 for (; it!=list.end(); it++) {
ram54288 0:dbad57390bd1 242 if((*it)->instance_id() == til->_id) {
ram54288 0:dbad57390bd1 243 found = true;
ram54288 0:dbad57390bd1 244 if(update_value) {
ram54288 0:dbad57390bd1 245 if(til->_length > 0) {
ram54288 0:dbad57390bd1 246 (*it)->set_value(tlv+offset, til->_length);
ram54288 0:dbad57390bd1 247 } else {
ram54288 0:dbad57390bd1 248 (*it)->clear_value();
ram54288 0:dbad57390bd1 249 }
ram54288 0:dbad57390bd1 250 break;
ram54288 0:dbad57390bd1 251 } else if(0 == ((*it)->operation() & SN_GRS_PUT_ALLOWED)) {
ram54288 0:dbad57390bd1 252 error = M2MTLVDeserializer::NotAllowed;
ram54288 0:dbad57390bd1 253 break;
ram54288 0:dbad57390bd1 254 }
ram54288 0:dbad57390bd1 255 }
ram54288 0:dbad57390bd1 256 }
ram54288 0:dbad57390bd1 257 if(!found) {
ram54288 0:dbad57390bd1 258 if(M2MTLVDeserializer::Post == operation) {
ram54288 0:dbad57390bd1 259 // Create a new Resource Instance
ram54288 0:dbad57390bd1 260 M2MResourceInstance *res_instance = object_instance.create_dynamic_resource_instance(resource.name(),"",
ram54288 0:dbad57390bd1 261 M2MResourceInstance::INTEGER,
ram54288 0:dbad57390bd1 262 true,
ram54288 0:dbad57390bd1 263 til->_id);
ram54288 0:dbad57390bd1 264 if(res_instance) {
ram54288 0:dbad57390bd1 265 res_instance->set_operation(M2MBase::GET_PUT_POST_DELETE_ALLOWED);
ram54288 0:dbad57390bd1 266 }
ram54288 0:dbad57390bd1 267 } else if(M2MTLVDeserializer::Put == operation) {
ram54288 0:dbad57390bd1 268 error = M2MTLVDeserializer::NotFound;
ram54288 0:dbad57390bd1 269 }
ram54288 0:dbad57390bd1 270 }
ram54288 0:dbad57390bd1 271 } else {
ram54288 0:dbad57390bd1 272 delete til;
ram54288 0:dbad57390bd1 273 error = M2MTLVDeserializer::NotValid;
ram54288 0:dbad57390bd1 274 return error;
ram54288 0:dbad57390bd1 275 }
ram54288 0:dbad57390bd1 276
ram54288 0:dbad57390bd1 277 offset += til->_length;
ram54288 0:dbad57390bd1 278
ram54288 0:dbad57390bd1 279 delete til;
ram54288 0:dbad57390bd1 280 if(offset < tlv_size) {
ram54288 0:dbad57390bd1 281 error = deserialize_resource_instances(tlv, tlv_size-offset, offset, resource, object_instance, operation, update_value);
ram54288 0:dbad57390bd1 282 }
ram54288 0:dbad57390bd1 283 return error;
ram54288 0:dbad57390bd1 284 }
ram54288 0:dbad57390bd1 285
ram54288 0:dbad57390bd1 286 M2MTLVDeserializer::Error M2MTLVDeserializer::deserialize_resource_instances(uint8_t *tlv,
ram54288 0:dbad57390bd1 287 uint32_t tlv_size,
ram54288 0:dbad57390bd1 288 uint32_t offset,
ram54288 0:dbad57390bd1 289 M2MResource &resource,
ram54288 0:dbad57390bd1 290 M2MTLVDeserializer::Operation operation,
ram54288 0:dbad57390bd1 291 bool update_value)
ram54288 0:dbad57390bd1 292 {
ram54288 0:dbad57390bd1 293 M2MTLVDeserializer::Error error = M2MTLVDeserializer::None;
ram54288 0:dbad57390bd1 294 TypeIdLength *til = TypeIdLength::createTypeIdLength(tlv, offset)->deserialize();
ram54288 0:dbad57390bd1 295 offset = til->_offset;
ram54288 0:dbad57390bd1 296
ram54288 0:dbad57390bd1 297 if (TYPE_RESOURCE_INSTANCE == til->_type) {
ram54288 0:dbad57390bd1 298 M2MResourceInstanceList list = resource.resource_instances();
ram54288 0:dbad57390bd1 299 M2MResourceInstanceList::const_iterator it;
ram54288 0:dbad57390bd1 300 it = list.begin();
ram54288 0:dbad57390bd1 301 bool found = false;
ram54288 0:dbad57390bd1 302 for (; it!=list.end(); it++) {
ram54288 0:dbad57390bd1 303 if((*it)->instance_id() == til->_id) {
ram54288 0:dbad57390bd1 304 found = true;
ram54288 0:dbad57390bd1 305 if(update_value) {
ram54288 0:dbad57390bd1 306 if(til->_length > 0) {
ram54288 0:dbad57390bd1 307 (*it)->set_value(tlv+offset, til->_length);
ram54288 0:dbad57390bd1 308 } else {
ram54288 0:dbad57390bd1 309 (*it)->clear_value();
ram54288 0:dbad57390bd1 310 }
ram54288 0:dbad57390bd1 311 break;
ram54288 0:dbad57390bd1 312 } else if(0 == ((*it)->operation() & SN_GRS_PUT_ALLOWED)) {
ram54288 0:dbad57390bd1 313 error = M2MTLVDeserializer::NotAllowed;
ram54288 0:dbad57390bd1 314 break;
ram54288 0:dbad57390bd1 315 }
ram54288 0:dbad57390bd1 316 }
ram54288 0:dbad57390bd1 317 }
ram54288 0:dbad57390bd1 318 if(!found) {
ram54288 0:dbad57390bd1 319 if(M2MTLVDeserializer::Post == operation) {
ram54288 0:dbad57390bd1 320 error = M2MTLVDeserializer::NotAllowed;
ram54288 0:dbad57390bd1 321 } else if(M2MTLVDeserializer::Put == operation) {
ram54288 0:dbad57390bd1 322 error = M2MTLVDeserializer::NotFound;
ram54288 0:dbad57390bd1 323 }
ram54288 0:dbad57390bd1 324 }
ram54288 0:dbad57390bd1 325 } else {
ram54288 0:dbad57390bd1 326 delete til;
ram54288 0:dbad57390bd1 327 error = M2MTLVDeserializer::NotValid;
ram54288 0:dbad57390bd1 328 return error;
ram54288 0:dbad57390bd1 329 }
ram54288 0:dbad57390bd1 330
ram54288 0:dbad57390bd1 331 offset += til->_length;
ram54288 0:dbad57390bd1 332
ram54288 0:dbad57390bd1 333 delete til;
ram54288 0:dbad57390bd1 334 if(offset < tlv_size) {
ram54288 0:dbad57390bd1 335 error = deserialize_resource_instances(tlv, tlv_size-offset, offset, resource, operation, update_value);
ram54288 0:dbad57390bd1 336 }
ram54288 0:dbad57390bd1 337 return error;
ram54288 0:dbad57390bd1 338 }
ram54288 0:dbad57390bd1 339
ram54288 0:dbad57390bd1 340 bool M2MTLVDeserializer::is_object_instance(uint8_t *tlv, uint32_t offset)
ram54288 0:dbad57390bd1 341 {
ram54288 0:dbad57390bd1 342 bool ret = false;
ram54288 0:dbad57390bd1 343 if (tlv) {
ram54288 0:dbad57390bd1 344 uint8_t value = tlv[offset];
ram54288 0:dbad57390bd1 345 ret = (TYPE_OBJECT_INSTANCE == (value & TYPE_RESOURCE));
ram54288 0:dbad57390bd1 346 }
ram54288 0:dbad57390bd1 347 return ret;
ram54288 0:dbad57390bd1 348 }
ram54288 0:dbad57390bd1 349
ram54288 0:dbad57390bd1 350 uint16_t M2MTLVDeserializer::instance_id(uint8_t *tlv)
ram54288 0:dbad57390bd1 351 {
ram54288 0:dbad57390bd1 352 TypeIdLength *til = TypeIdLength::createTypeIdLength(tlv, 0)->deserialize();
ram54288 0:dbad57390bd1 353 uint16_t id = til->_id;
ram54288 0:dbad57390bd1 354 delete til;
ram54288 0:dbad57390bd1 355 return id;
ram54288 0:dbad57390bd1 356 }
ram54288 0:dbad57390bd1 357
ram54288 0:dbad57390bd1 358 bool M2MTLVDeserializer::is_resource(uint8_t *tlv, uint32_t offset)
ram54288 0:dbad57390bd1 359 {
ram54288 0:dbad57390bd1 360 bool ret = false;
ram54288 0:dbad57390bd1 361 if (tlv) {
ram54288 0:dbad57390bd1 362 ret = (TYPE_RESOURCE == (tlv[offset] & TYPE_RESOURCE));
ram54288 0:dbad57390bd1 363 }
ram54288 0:dbad57390bd1 364 return ret;
ram54288 0:dbad57390bd1 365 }
ram54288 0:dbad57390bd1 366
ram54288 0:dbad57390bd1 367 bool M2MTLVDeserializer::is_multiple_resource(uint8_t *tlv, uint32_t offset)
ram54288 0:dbad57390bd1 368 {
ram54288 0:dbad57390bd1 369 bool ret = false;
ram54288 0:dbad57390bd1 370 if (tlv) {
ram54288 0:dbad57390bd1 371 ret = (TYPE_MULTIPLE_RESOURCE == (tlv[offset] & TYPE_RESOURCE));
ram54288 0:dbad57390bd1 372 }
ram54288 0:dbad57390bd1 373 return ret;
ram54288 0:dbad57390bd1 374 }
ram54288 0:dbad57390bd1 375
ram54288 0:dbad57390bd1 376 bool M2MTLVDeserializer::is_resource_instance(uint8_t *tlv, uint32_t offset)
ram54288 0:dbad57390bd1 377 {
ram54288 0:dbad57390bd1 378 bool ret = false;
ram54288 0:dbad57390bd1 379 if (tlv) {
ram54288 0:dbad57390bd1 380 ret = (TYPE_RESOURCE_INSTANCE == (tlv[offset] & TYPE_RESOURCE));
ram54288 0:dbad57390bd1 381 }
ram54288 0:dbad57390bd1 382 return ret;
ram54288 0:dbad57390bd1 383 }
ram54288 0:dbad57390bd1 384
ram54288 0:dbad57390bd1 385 TypeIdLength* TypeIdLength::createTypeIdLength(uint8_t *tlv, uint32_t offset)
ram54288 0:dbad57390bd1 386 {
ram54288 0:dbad57390bd1 387 TypeIdLength *til = new TypeIdLength();
ram54288 0:dbad57390bd1 388 til->_tlv = tlv;
ram54288 0:dbad57390bd1 389 til->_offset = offset;
ram54288 0:dbad57390bd1 390 til->_type = tlv[offset] & 0xC0;
ram54288 0:dbad57390bd1 391 til->_id = 0;
ram54288 0:dbad57390bd1 392 til->_length = 0;
ram54288 0:dbad57390bd1 393 return til;
ram54288 0:dbad57390bd1 394 }
ram54288 0:dbad57390bd1 395
ram54288 0:dbad57390bd1 396 TypeIdLength* TypeIdLength::deserialize()
ram54288 0:dbad57390bd1 397 {
ram54288 0:dbad57390bd1 398 uint32_t idLength = _tlv[_offset] & ID16;
ram54288 0:dbad57390bd1 399 uint32_t lengthType = _tlv[_offset] & LENGTH24;
ram54288 0:dbad57390bd1 400 if (0 == lengthType) {
ram54288 0:dbad57390bd1 401 _length = _tlv[_offset] & 0x07;
ram54288 0:dbad57390bd1 402 }
ram54288 0:dbad57390bd1 403 _offset++;
ram54288 0:dbad57390bd1 404
ram54288 0:dbad57390bd1 405 deserialiseID(idLength);
ram54288 0:dbad57390bd1 406 deserialiseLength(lengthType);
ram54288 0:dbad57390bd1 407
ram54288 0:dbad57390bd1 408 return this;
ram54288 0:dbad57390bd1 409 }
ram54288 0:dbad57390bd1 410
ram54288 0:dbad57390bd1 411 void TypeIdLength::deserialiseID(uint32_t idLength)
ram54288 0:dbad57390bd1 412 {
ram54288 0:dbad57390bd1 413 _id = _tlv[_offset++] & 0xFF;
ram54288 0:dbad57390bd1 414 if (ID16 == idLength) {
ram54288 0:dbad57390bd1 415 _id = (_id << 8) + (_tlv[_offset++] & 0xFF);
ram54288 0:dbad57390bd1 416 }
ram54288 0:dbad57390bd1 417 }
ram54288 0:dbad57390bd1 418
ram54288 0:dbad57390bd1 419 void TypeIdLength::deserialiseLength(uint32_t lengthType)
ram54288 0:dbad57390bd1 420 {
ram54288 0:dbad57390bd1 421 if (lengthType > 0) {
ram54288 0:dbad57390bd1 422 _length = _tlv[_offset++] & 0xFF;
ram54288 0:dbad57390bd1 423 }
ram54288 0:dbad57390bd1 424 if (lengthType > LENGTH8) {
ram54288 0:dbad57390bd1 425 _length = (_length << 8) + (_tlv[_offset++] & 0xFF);
ram54288 0:dbad57390bd1 426 }
ram54288 0:dbad57390bd1 427 if (lengthType > LENGTH16) {
ram54288 0:dbad57390bd1 428 _length = (_length << 8) + (_tlv[_offset++] & 0xFF);
ram54288 0:dbad57390bd1 429 }
ram54288 0:dbad57390bd1 430 }