void bootstrap_step(lwm2m_context_t * contextP, time_t currentTime, time_t * timeoutP) { lwm2m_server_t * targetP; LOG("entering"); targetP = contextP->bootstrapServerList; while (targetP != NULL) { LOG_ARG("Initial status: %s", STR_STATUS(targetP->status)); switch (targetP->status) { case STATE_DEREGISTERED: targetP->registration = currentTime + targetP->lifetime; targetP->status = STATE_BS_HOLD_OFF; if (*timeoutP > targetP->lifetime) { *timeoutP = targetP->lifetime; } break; case STATE_BS_HOLD_OFF: if (targetP->registration <= currentTime) { prv_requestBootstrap(contextP, targetP); } else if (*timeoutP > targetP->registration - currentTime) { *timeoutP = targetP->registration - currentTime; } break; case STATE_BS_INITIATED: // waiting break; case STATE_BS_PENDING: 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: if (targetP->sessionH != NULL) { lwm2m_close_connection(targetP->sessionH, contextP->userData); targetP->sessionH = NULL; } targetP->status = STATE_BS_FINISHED; *timeoutP = 0; break; case STATE_BS_FAILING: if (targetP->sessionH != NULL) { lwm2m_close_connection(targetP->sessionH, contextP->userData); targetP->sessionH = NULL; } targetP->status = STATE_BS_FAILED; *timeoutP = 0; break; default: break; } LOG_ARG("Finalal status: %s", STR_STATUS(targetP->status)); targetP = targetP->next; } }
// for each server update the registration if needed // for each client check if the registration expired void registration_step(lwm2m_context_t * contextP, time_t currentTime, time_t * timeoutP) { #ifdef LWM2M_CLIENT_MODE lwm2m_server_t * targetP = contextP->serverList; targetP = contextP->serverList; while (targetP != NULL) { switch (targetP->status) { case STATE_REGISTERED: { time_t nextUpdate; time_t interval; nextUpdate = targetP->lifetime; if (30 < nextUpdate) { nextUpdate -= 15; // update 15s earlier to have a chance to resend } interval = targetP->registration + nextUpdate - currentTime; if (0 >= interval) { LOG("Updating registration...\r\n"); prv_updateRegistration(contextP, targetP, false); } else if (interval < *timeoutP) { *timeoutP = interval; } } break; case STATE_REG_FAILED: if (targetP->sessionH != NULL) { lwm2m_close_connection(targetP->sessionH, contextP->userData); targetP->sessionH = NULL; } break; default: break; } targetP = targetP->next; } #endif #ifdef LWM2M_SERVER_MODE lwm2m_client_t * clientP; // monitor clients lifetime clientP = contextP->clientList; while (clientP != NULL) { lwm2m_client_t * nextP = clientP->next; if (clientP->endOfLife <= currentTime) { contextP->clientList = (lwm2m_client_t *)LWM2M_LIST_RM(contextP->clientList, clientP->internalID, NULL); if (contextP->monitorCallback != NULL) { contextP->monitorCallback(clientP->internalID, NULL, COAP_202_DELETED, LWM2M_CONTENT_TEXT, NULL, 0, contextP->monitorUserData); } registration_freeClient(clientP); } else { time_t interval; interval = clientP->endOfLife - currentTime; if (*timeoutP > interval) { *timeoutP = interval; } } clientP = nextP; } #endif }