Skip to content

Commit

Permalink
Merge pull request eclipse-wakaama#303 from sbertin-telular/fix_282
Browse files Browse the repository at this point in the history
Add a bootstrap timeout to fix issue eclipse-wakaama#282
  • Loading branch information
dnav committed Jun 7, 2017
2 parents 3b6cc09 + 158a9a2 commit bc7547c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
15 changes: 12 additions & 3 deletions core/bootstrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ static void prv_handleResponse(lwm2m_server_t * bootstrapServer,
{
LOG("Received ACK/2.04, Bootstrap pending, waiting for DEL/PUT from BS server...");
bootstrapServer->status = STATE_BS_PENDING;
bootstrapServer->registration = lwm2m_gettime() + COAP_EXCHANGE_LIFETIME;
}
else
{
Expand Down Expand Up @@ -162,7 +163,15 @@ void bootstrap_step(lwm2m_context_t * contextP,
break;

case STATE_BS_PENDING:
// waiting
if (targetP->registration <= currentTime)
{
targetP->status = STATE_BS_FAILING;
*timeoutP = 0;
}
else if (*timeoutP > targetP->registration - currentTime)
{
*timeoutP = targetP->registration - currentTime;
}
break;

case STATE_BS_FINISHING:
Expand Down Expand Up @@ -298,7 +307,7 @@ static coap_status_t prv_checkServerStatus(lwm2m_server_t * serverP)
case STATE_DEREGISTERED:
// server initiated bootstrap
case STATE_BS_PENDING:
// do nothing
serverP->registration = lwm2m_gettime() + COAP_EXCHANGE_LIFETIME;
break;

case STATE_BS_FINISHED:
Expand Down Expand Up @@ -431,7 +440,7 @@ coap_status_t bootstrap_handleCommand(lwm2m_context_t * contextP,
prv_tagServer(contextP, dataP[i].id);
}
}

if(result != COAP_204_CHANGED) // Stop object create or write when result is error
{
break;
Expand Down
4 changes: 4 additions & 0 deletions core/er-coap-13/er-coap-13.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,12 @@
#define COAP_RESPONSE_TIMEOUT 2
#define COAP_MAX_RETRANSMIT 4
#define COAP_ACK_RANDOM_FACTOR 1.5
#define COAP_MAX_LATENCY 100
#define COAP_PROCESSING_DELAY COAP_RESPONSE_TIMEOUT

#define COAP_MAX_TRANSMIT_WAIT ((COAP_RESPONSE_TIMEOUT * ( (1 << (COAP_MAX_RETRANSMIT + 1) ) - 1) * COAP_ACK_RANDOM_FACTOR))
#define COAP_MAX_TRANSMIT_SPAN ((COAP_RESPONSE_TIMEOUT * ( (1 << COAP_MAX_RETRANSMIT) - 1) * COAP_ACK_RANDOM_FACTOR))
#define COAP_EXCHANGE_LIFETIME (COAP_MAX_TRANSMIT_SPAN + (2 * COAP_MAX_LATENCY) + COAP_PROCESSING_DELAY)

#define COAP_HEADER_LEN 4 /* | version:0x03 type:0x0C tkl:0xF0 | code | mid:0x00FF | mid:0xFF00 | */
#define COAP_ETAG_LEN 8 /* The maximum number of bytes for the ETag */
Expand Down

0 comments on commit bc7547c

Please sign in to comment.