Skip to content

Commit

Permalink
Fix issue eclipse-wakaama#281: Check consistency at bootstrap finish.
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 Jun 1, 2017
1 parent 3b6cc09 commit 63285b9
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 9 deletions.
13 changes: 10 additions & 3 deletions core/bootstrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,16 @@ coap_status_t bootstrap_handleFinish(lwm2m_context_t * context,
if (bootstrapServer != NULL
&& bootstrapServer->status == STATE_BS_PENDING)
{
LOG("Bootstrap server status changed to STATE_BS_FINISHING");
bootstrapServer->status = STATE_BS_FINISHING;
return COAP_204_CHANGED;
if (object_getServers(context, true) == 0)
{
LOG("Bootstrap server status changed to STATE_BS_FINISHING");
bootstrapServer->status = STATE_BS_FINISHING;
return COAP_204_CHANGED;
}
else
{
return COAP_406_NOT_ACCEPTABLE;
}
}

return COAP_IGNORE;
Expand Down
2 changes: 1 addition & 1 deletion core/internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ uint8_t object_checkReadable(lwm2m_context_t * contextP, lwm2m_uri_t * uriP);
uint8_t object_checkNumeric(lwm2m_context_t * contextP, lwm2m_uri_t * uriP);
bool object_isInstanceNew(lwm2m_context_t * contextP, uint16_t objectId, uint16_t instanceId);
int object_getRegisterPayload(lwm2m_context_t * contextP, uint8_t * buffer, size_t length);
int object_getServers(lwm2m_context_t * contextP);
int object_getServers(lwm2m_context_t * contextP, bool checkOnly);
coap_status_t object_createInstance(lwm2m_context_t * contextP, lwm2m_uri_t * uriP, lwm2m_data_t * dataP);
coap_status_t object_writeInstance(lwm2m_context_t * contextP, lwm2m_uri_t * uriP, lwm2m_data_t * dataP);

Expand Down
2 changes: 1 addition & 1 deletion core/liblwm2m.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ static int prv_refreshServerList(lwm2m_context_t * contextP)
targetP = nextP;
}

return object_getServers(contextP);
return object_getServers(contextP, false);
}

int lwm2m_configure(lwm2m_context_t * contextP,
Expand Down
20 changes: 17 additions & 3 deletions core/objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ static int prv_getMandatoryInfo(lwm2m_object_t * objectP,
return 0;
}

int object_getServers(lwm2m_context_t * contextP)
int object_getServers(lwm2m_context_t * contextP, bool checkOnly)
{
lwm2m_object_t * objectP;
lwm2m_object_t * securityObjP = NULL;
Expand Down Expand Up @@ -772,7 +772,14 @@ int object_getServers(lwm2m_context_t * contextP)
// lifetime of a bootstrap server is set to ClientHoldOffTime
targetP->lifetime = value;

contextP->bootstrapServerList = (lwm2m_server_t*)LWM2M_LIST_ADD(contextP->bootstrapServerList, targetP);
if (checkOnly)
{
lwm2m_free(targetP);
}
else
{
contextP->bootstrapServerList = (lwm2m_server_t*)LWM2M_LIST_ADD(contextP->bootstrapServerList, targetP);
}
}
else
{
Expand All @@ -792,7 +799,14 @@ int object_getServers(lwm2m_context_t * contextP)
return -1;
}
targetP->status = STATE_DEREGISTERED;
contextP->serverList = (lwm2m_server_t*)LWM2M_LIST_ADD(contextP->serverList, targetP);
if (checkOnly)
{
lwm2m_free(targetP);
}
else
{
contextP->serverList = (lwm2m_server_t*)LWM2M_LIST_ADD(contextP->serverList, targetP);
}
}
}
lwm2m_data_free(size, dataP);
Expand Down
2 changes: 1 addition & 1 deletion core/registration.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ int lwm2m_update_registration(lwm2m_context_t * contextP,
targetP = contextP->serverList;
if (targetP == NULL)
{
if (object_getServers(contextP) == -1)
if (object_getServers(contextP, false) == -1)
{
LOG("No server found");
return COAP_404_NOT_FOUND;
Expand Down

0 comments on commit 63285b9

Please sign in to comment.