Skip to content
This repository was archived by the owner on Apr 24, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions source/include/m2mtlvdeserializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

/**
* @brief M2MTLVDeserializer
* TLV Deserialiser get the object instances and resources as binary data and
* builds the <code>lwm2m</code> representation from it. See OMA-LWM2M
* TLV Deserialiser get the object instances and resources as binary data and
* builds the <code>lwm2m</code> representation from it. See OMA-LWM2M
* specification, chapter 6.1 for the resource model and chapter 6.3.3 for
* the OMA-TLV specification.
*/
Expand Down Expand Up @@ -51,9 +51,9 @@ public :
*/
static bool is_object_instance(uint8_t *tlv);


/**
* This method checks whether the given binary encodes a resource or
* This method checks whether the given binary encodes a resource or
* something else. It returns <code>true</code> if bits 7-6 of the first
* byte is "11".
* @param tlv Binary to be checked as LWM2M resource.
Expand All @@ -69,7 +69,7 @@ public :
* @return <code>true</code> or <code>false</code>.
*/
static bool is_multiple_resource(uint8_t *tlv);

/**
* This method checks whether the given binary encodes a resource instance
* or something else. It returns <code>true</code> if bits 7-6 of the first
Expand All @@ -81,15 +81,15 @@ public :

/**
* Deserialises the given binary that must encode object instances. Binary
* array can be checked before invoking this method with
* array can be checked before invoking this method with
*/
static M2MTLVDeserializer::Error deserialise_object_instances(uint8_t* tlv,
uint32_t tlv_size,
M2MObject &object,
M2MTLVDeserializer::Operation operation);

/**
* Deserialises the given binary that must encode resources. Binary array
* Deserialises the given binary that must encode resources. Binary array
* can be checked before invoking this method.
*/
static M2MTLVDeserializer::Error deserialize_resources(uint8_t *tlv,
Expand All @@ -111,7 +111,7 @@ public :
* @return Object instance id or resource id.
*/
static uint16_t instance_id(uint8_t *tlv);

private:

static M2MTLVDeserializer::Error deserialize_object_instances(uint8_t *tlv,
Expand All @@ -120,7 +120,7 @@ public :
M2MObject &object,
M2MTLVDeserializer::Operation operation,
bool update_value);

static M2MTLVDeserializer::Error deserialize_resources(uint8_t *tlv,
uint32_t tlv_size,
uint32_t offset,
Expand All @@ -144,12 +144,14 @@ public :
bool update_value);

static bool is_object_instance(uint8_t *tlv, uint32_t offset);

static bool is_resource(uint8_t *tlv, uint32_t offset);

static bool is_multiple_resource(uint8_t *tlv, uint32_t offset);

static bool is_resource_instance(uint8_t *tlv, uint32_t offset);

static void set_resource_instance_value(M2MResourceInstance *res, uint8_t *tlv, uint32_t size);
};

class TypeIdLength {
Expand Down
5 changes: 5 additions & 0 deletions source/m2mnsdlinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1668,6 +1668,11 @@ bool M2MNsdlInterface::validate_security_object()
uint32_t public_key_size = _security->get_resource(M2MSecurity::PublicKey)->value_length();
uint32_t server_key_size = _security->get_resource(M2MSecurity::ServerPublicKey)->value_length();
uint32_t pkey_size = _security->get_resource(M2MSecurity::Secretkey)->value_length();
M2MDevice* dev = M2MInterfaceFactory::create_device();
if (dev) {
tr_debug("M2MNsdlInterface::validate_security_object - Current time: %" PRIu32,
dev->resource_value_int(M2MDevice::CurrentTime));
}
tr_debug("M2MNsdlInterface::validate_security_object - Server URI /0/0: %s", address.c_str());
tr_debug("M2MNsdlInterface::validate_security_object - is bs server /0/1: %d", is_bs_server);
tr_debug("M2MNsdlInterface::validate_security_object - Security Mode /0/2: %" PRIu32, sec_mode);
Expand Down
19 changes: 4 additions & 15 deletions source/m2msecurity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,8 @@ bool M2MSecurity::set_resource_value(SecurityResource resource,
M2MSecurity::M2MServerSMSNumber == resource ||
M2MSecurity::ShortServerID == resource ||
M2MSecurity::ClientHoldOffTime == resource) {
// If it is any of the above resource
// set the value of the resource.
uint8_t size = 0;
uint8_t *buffer = String::convert_integer_to_array(value, size);
success = res->set_value(buffer,size);
free(buffer);
success = res->set_value(value);

}
}
return success;
Expand Down Expand Up @@ -272,15 +268,8 @@ uint32_t M2MSecurity::resource_value_int(SecurityResource resource) const
M2MSecurity::M2MServerSMSNumber == resource ||
M2MSecurity::ShortServerID == resource ||
M2MSecurity::ClientHoldOffTime == resource) {
// Get the value and convert it into integer. This is not the most
// efficient way, as it takes pointless heap copy to get the zero termination.
uint8_t* buffer = NULL;
uint32_t length = 0;
res->get_value(buffer,length);
if(buffer) {
value = String::convert_array_to_integer(buffer,length);
free(buffer);
}
// note: the value may be 32bit int on 32b archs.
value = res->get_value_int();
}
}
return value;
Expand Down
45 changes: 42 additions & 3 deletions source/m2mtlvdeserializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,24 @@ M2MTLVDeserializer::Error M2MTLVDeserializer::deserialize_resources(uint8_t *tlv
if(update_value) {
if(til._length > 0) {
tr_debug("M2MTLVDeserializer::deserialize_resources() - Update value");
(*it)->set_value(tlv+offset, til._length);
int64_t value = 0;
switch ((*it)->resource_instance_type()) {
case M2MResourceInstance::INTEGER:
case M2MResourceInstance::BOOLEAN:
value = String::convert_array_to_integer(tlv+offset, til._length);
(*it)->set_value(value);
break;
// Todo! implement support for other types as well
case M2MResourceInstance::STRING:
case M2MResourceInstance::FLOAT:
case M2MResourceInstance::OPAQUE:
case M2MResourceInstance::TIME:
case M2MResourceInstance::OBJLINK:
(*it)->set_value(tlv+offset, til._length);
break;
default:
break;
}
} else {
tr_debug("M2MTLVDeserializer::deserialize_resources() - Clear Value");
(*it)->clear_value();
Expand Down Expand Up @@ -235,7 +252,7 @@ M2MTLVDeserializer::Error M2MTLVDeserializer::deserialize_resource_instances(uin
found = true;
if(update_value) {
if(til._length > 0) {
(*it)->set_value(tlv+offset, til._length);
set_resource_instance_value((*it), tlv+offset, til._length);
} else {
(*it)->clear_value();
}
Expand Down Expand Up @@ -295,7 +312,7 @@ M2MTLVDeserializer::Error M2MTLVDeserializer::deserialize_resource_instances(uin
found = true;
if(update_value) {
if(til._length > 0) {
(*it)->set_value(tlv+offset, til._length);
set_resource_instance_value((*it),tlv+offset, til._length);
} else {
(*it)->clear_value();
}
Expand Down Expand Up @@ -371,6 +388,28 @@ bool M2MTLVDeserializer::is_resource_instance(uint8_t *tlv, uint32_t offset)
return ret;
}

void M2MTLVDeserializer::set_resource_instance_value(M2MResourceInstance *res, uint8_t *tlv, uint32_t size)
{
int64_t value = 0;
switch (res->resource_instance_type()) {
case M2MResourceInstance::INTEGER:
case M2MResourceInstance::BOOLEAN:
value = String::convert_array_to_integer(tlv, size);
res->set_value(value);
break;
// Todo! implement conversion for other types as well
case M2MResourceInstance::STRING:
case M2MResourceInstance::FLOAT:
case M2MResourceInstance::OPAQUE:
case M2MResourceInstance::TIME:
case M2MResourceInstance::OBJLINK:
res->set_value(tlv, size);
break;
default:
break;
}
}

TypeIdLength::TypeIdLength(uint8_t *tlv, uint32_t offset)
{
_tlv = tlv;
Expand Down