Exemplo n.º 1
0
// for each server update the registration if needed
int lwm2m_update_registrations(lwm2m_context_t * contextP, uint32_t currentTime, struct timeval * timeoutP)
{
    lwm2m_server_t * targetP;
    targetP = contextP->serverList;
    while (targetP != NULL)
    {
        switch (targetP->status) {
            case STATE_REGISTERED:
                if (targetP->registration + targetP->lifetime - timeoutP->tv_sec <= currentTime)
                {
                    prv_update_registration(contextP, targetP);
                }
                break;
            case STATE_UNKNOWN:
                // TODO: is it disabled?
                prv_register(contextP, targetP);
                break;
            case STATE_REG_PENDING:
                break;
            case STATE_REG_UPDATE_PENDING:
                // TODO: check for timeout and retry?
                break;
            case STATE_DEREG_PENDING:
                break;
        }
        targetP = targetP->next;
    }
    return 0;
}
Exemplo n.º 2
0
// update the registration of a given server
int lwm2m_update_registration(lwm2m_context_t * contextP,
                              uint16_t shortServerID)
{
    lwm2m_server_t * targetP;

    targetP = contextP->serverList;
    if (targetP == NULL)
    {
        if (object_getServers(contextP) == -1)
        {
            return NOT_FOUND_4_04;
        }
    }
    while (targetP != NULL)
    {
        if (targetP->shortID == shortServerID)
        {
            // found the server, trigger the update transaction
            return prv_update_registration(contextP, targetP);
        }
        else
        {
            // try next server
            targetP = targetP->next;
        }
    }

    // no server found
    return NOT_FOUND_4_04;
}
Exemplo n.º 3
0
// for each server update the registration if needed
void registration_update(lwm2m_context_t * contextP,
                         time_t currentTime,
                         time_t * timeoutP)
{
    time_t nextUpdate;
    time_t interval;
    lwm2m_server_t * targetP = contextP->serverList;
#ifdef LWM2M_BOOTSTRAP
    bool allServerFailed = true;
    bool serverRegistered = false;

    while (targetP != NULL)
    {
        if (STATE_REGISTERED == targetP->status)
        {
            serverRegistered = true;
            allServerFailed = false;
            break;
        }
        else if (STATE_REG_FAILED != targetP->status) allServerFailed = false;
        targetP = targetP->next;
    }
#endif

    targetP = contextP->serverList;
    while (targetP != NULL)
    {
        switch (targetP->status)
        {
            case STATE_REGISTERED:
                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_update_registration(contextP, targetP);
                }
                else if (interval < *timeoutP)
                {
                    *timeoutP = interval;
                }
                break;

            case STATE_DEREGISTERED:
                // TODO: is it disabled?
                prv_register(contextP, targetP);
                break;

            case STATE_REG_UPDATE_PENDING:
                // TODO: check for timeout and retry?
                break;

            case STATE_DEREG_PENDING:
                break;

            case STATE_REG_FAILED:
#ifdef LWM2M_BOOTSTRAP
                if (serverRegistered || NULL == contextP->bootstrapServerList)
                {
#endif
                    interval = targetP->registration + targetP->lifetime - currentTime;
                    if (0 >= interval)
                    {
                        LOG("Retry registration...\r\n");
                        prv_register(contextP, targetP);
                    }
                    else if (interval < *timeoutP)
                    {
                        *timeoutP = interval;
                    }
#ifdef LWM2M_BOOTSTRAP
                }
#endif
                break;

            default:
                break;
        }
        targetP = targetP->next;
    }
#ifdef LWM2M_BOOTSTRAP
    if (allServerFailed && NULL != contextP->bootstrapServerList)
    {
        if (BOOTSTRAPPED == contextP->bsState || NOT_BOOTSTRAPPED == contextP->bsState)
        {
            contextP->bsState = BOOTSTRAP_REQUESTED;
        }
    }
#endif
}
Exemplo n.º 4
0
// 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)
    {
        if (targetP->status == 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_update_registration(contextP, targetP);
            }
            else if (interval < *timeoutP)
            {
                *timeoutP = interval;
            }
        }
        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, DELETED_2_02, LWM2M_CONTENT_TEXT, NULL, 0, contextP->monitorUserData);
            }
            prv_freeClient(clientP);
        }
        else
        {
            time_t interval;

            interval = clientP->endOfLife - currentTime;

            if (*timeoutP > interval)
            {
                *timeoutP = interval;
            }
        }
        clientP = nextP;
    }
#endif

}