Skip to content

Commit

Permalink
Add support for Corelnk type
Browse files Browse the repository at this point in the history
Signed-off-by: Scott Bertin <sbertin@telular.com>
  • Loading branch information
sbertin-telular committed Feb 5, 2019
1 parent a0d85a4 commit cc55289
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 2 deletions.
14 changes: 14 additions & 0 deletions core/data.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ static int prv_textSerialize(lwm2m_data_t * dataP,
switch (dataP->type)
{
case LWM2M_TYPE_STRING:
case LWM2M_TYPE_CORE_LINK:
*bufferP = (uint8_t *)lwm2m_malloc(dataP->value.asBuffer.length);
if (*bufferP == NULL) return 0;
memcpy(*bufferP, dataP->value.asBuffer.buffer, dataP->value.asBuffer.length);
Expand Down Expand Up @@ -189,10 +190,12 @@ void lwm2m_data_free(int size,

case LWM2M_TYPE_STRING:
case LWM2M_TYPE_OPAQUE:
case LWM2M_TYPE_CORE_LINK:
if (dataP[i].value.asBuffer.buffer != NULL)
{
lwm2m_free(dataP[i].value.asBuffer.buffer);
}
break;

default:
// do nothing
Expand Down Expand Up @@ -579,6 +582,16 @@ int lwm2m_data_decode_bool(const lwm2m_data_t * dataP,
return result;
}

void lwm2m_data_encode_corelink(const char * corelink, lwm2m_data_t * dataP)
{
LOG_ARG("\"%s\"", corelink);
lwm2m_data_encode_string(corelink, dataP);
if (dataP->type == LWM2M_TYPE_STRING)
{
dataP->type = LWM2M_TYPE_CORE_LINK;
}
}

void lwm2m_data_encode_objlink(uint16_t objectId,
uint16_t objectInstanceId,
lwm2m_data_t * dataP)
Expand All @@ -605,6 +618,7 @@ void lwm2m_data_include(lwm2m_data_t * subDataP,
case LWM2M_TYPE_FLOAT:
case LWM2M_TYPE_BOOLEAN:
case LWM2M_TYPE_OBJECT_LINK:
case LWM2M_TYPE_CORE_LINK:
case LWM2M_TYPE_MULTIPLE_RESOURCE:
dataP->type = LWM2M_TYPE_OBJECT_INSTANCE;
break;
Expand Down
1 change: 1 addition & 0 deletions core/discover.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ static int prv_serializeLinkData(lwm2m_context_t * contextP,
case LWM2M_TYPE_FLOAT:
case LWM2M_TYPE_BOOLEAN:
case LWM2M_TYPE_OBJECT_LINK:
case LWM2M_TYPE_CORE_LINK:
case LWM2M_TYPE_MULTIPLE_RESOURCE:
if (bufferLen < LINK_ITEM_START_SIZE) return -1;
memcpy(buffer + head, LINK_ITEM_START, LINK_ITEM_START_SIZE);
Expand Down
1 change: 1 addition & 0 deletions core/json.c
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,7 @@ static int prv_serializeValue(lwm2m_data_t * tlvP,
switch (tlvP->type)
{
case LWM2M_TYPE_STRING:
case LWM2M_TYPE_CORE_LINK:
if (bufferLen < JSON_ITEM_STRING_BEGIN_SIZE) return -1;
memcpy(buffer, JSON_ITEM_STRING_BEGIN, JSON_ITEM_STRING_BEGIN_SIZE);
head = JSON_ITEM_STRING_BEGIN_SIZE;
Expand Down
6 changes: 4 additions & 2 deletions core/liblwm2m.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ int lwm2m_stringToUri(const char * buffer, size_t buffer_len, lwm2m_uri_t * uriP
* The lwm2m_data_t is used to store LWM2M resource values in a hierarchical way.
* Depending on the type the value is different:
* - LWM2M_TYPE_OBJECT, LWM2M_TYPE_OBJECT_INSTANCE, LWM2M_TYPE_MULTIPLE_RESOURCE: value.asChildren
* - LWM2M_TYPE_STRING, LWM2M_TYPE_OPAQUE: value.asBuffer
* - LWM2M_TYPE_STRING, LWM2M_TYPE_OPAQUE, LWM2M_TYPE_CORE_LINK: value.asBuffer
* - LWM2M_TYPE_INTEGER, LWM2M_TYPE_TIME: value.asInteger
* - LWM2M_TYPE_UNSIGNED_INTEGER: value.asUnsigned
* - LWM2M_TYPE_FLOAT: value.asFloat
Expand All @@ -296,7 +296,8 @@ typedef enum
LWM2M_TYPE_FLOAT,
LWM2M_TYPE_BOOLEAN,

LWM2M_TYPE_OBJECT_LINK
LWM2M_TYPE_OBJECT_LINK,
LWM2M_TYPE_CORE_LINK
} lwm2m_data_type_t;

typedef struct _lwm2m_data_t lwm2m_data_t;
Expand Down Expand Up @@ -357,6 +358,7 @@ int lwm2m_data_decode_float(const lwm2m_data_t * dataP, double * valueP);
void lwm2m_data_encode_bool(bool value, lwm2m_data_t * dataP);
int lwm2m_data_decode_bool(const lwm2m_data_t * dataP, bool * valueP);
void lwm2m_data_encode_objlink(uint16_t objectId, uint16_t objectInstanceId, lwm2m_data_t * dataP);
void lwm2m_data_encode_corelink(const char * corelink, lwm2m_data_t * dataP);
void lwm2m_data_encode_instances(lwm2m_data_t * subDataP, size_t count, lwm2m_data_t * dataP);
void lwm2m_data_include(lwm2m_data_t * subDataP, size_t count, lwm2m_data_t * dataP);

Expand Down
3 changes: 3 additions & 0 deletions core/tlv.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ static uint8_t prv_getHeaderType(lwm2m_data_type_t type)
case LWM2M_TYPE_BOOLEAN:
case LWM2M_TYPE_OPAQUE:
case LWM2M_TYPE_OBJECT_LINK:
case LWM2M_TYPE_CORE_LINK:
return _PRV_TLV_TYPE_RESOURCE;

case LWM2M_TYPE_UNDEFINED:
Expand Down Expand Up @@ -431,6 +432,7 @@ static int prv_getLength(int size,

case LWM2M_TYPE_STRING:
case LWM2M_TYPE_OPAQUE:
case LWM2M_TYPE_CORE_LINK:
length += prv_getHeaderLength(dataP[i].id, dataP[i].value.asBuffer.length) + dataP[i].value.asBuffer.length;
break;

Expand Down Expand Up @@ -570,6 +572,7 @@ int tlv_serialize(bool isResourceInstance,

case LWM2M_TYPE_STRING:
case LWM2M_TYPE_OPAQUE:
case LWM2M_TYPE_CORE_LINK:
headerLen = prv_createHeader(*bufferP + index, isInstance, dataP[i].type, dataP[i].id, dataP[i].value.asBuffer.length);
index += headerLen;
memcpy(*bufferP + index, dataP[i].value.asBuffer.buffer, dataP[i].value.asBuffer.length);
Expand Down
5 changes: 5 additions & 0 deletions examples/shared/commandline.c
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,11 @@ void dump_tlv(FILE * stream,
print_indent(stream, indent + 1);
fprintf(stream, "\"%.*s\"\r\n", (int)dataP[i].value.asBuffer.length, dataP[i].value.asBuffer.buffer);
break;
case LWM2M_TYPE_CORE_LINK:
fprintf(stream, "LWM2M_TYPE_CORE_LINK\r\n");
print_indent(stream, indent + 1);
fprintf(stream, "\"%.*s\"\r\n", (int)dataP[i].value.asBuffer.length, dataP[i].value.asBuffer.buffer);
break;
case LWM2M_TYPE_OPAQUE:
fprintf(stream, "LWM2M_TYPE_OPAQUE\r\n");
output_buffer(stream, dataP[i].value.asBuffer.buffer, dataP[i].value.asBuffer.length, indent + 1);
Expand Down

0 comments on commit cc55289

Please sign in to comment.