diff --git a/api/cloud/oc_cloud.c b/api/cloud/oc_cloud.c index 443788be76..5ea3bda448 100644 --- a/api/cloud/oc_cloud.c +++ b/api/cloud/oc_cloud.c @@ -409,7 +409,7 @@ oc_cloud_shutdown(void) if (ctx) { cloud_rd_deinit(ctx); cloud_manager_stop(ctx); - cloud_store_deinit(&ctx->store); + cloud_store_initialize(&ctx->store); cloud_close_endpoint(ctx->cloud_ep); oc_free_endpoint(ctx->cloud_ep); oc_list_remove(cloud_context_list, ctx); diff --git a/api/cloud/oc_cloud_apis.c b/api/cloud/oc_cloud_apis.c index e2fc46960a..c7c41d5d3b 100644 --- a/api/cloud/oc_cloud_apis.c +++ b/api/cloud/oc_cloud_apis.c @@ -246,7 +246,7 @@ cloud_deregistered_internal(oc_client_response_t *data) ctx->store.status |= OC_CLOUD_FAILURE; } - ctx->store.cps = OC_CPS_READYTOREGISTER; + ctx->store.cps = OC_CPS_UNINITIALIZED; if (p->cb) { p->cb(ctx, ctx->store.status, p->data); diff --git a/api/cloud/oc_cloud_internal.h b/api/cloud/oc_cloud_internal.h index 703c13d4ab..2e650f55ea 100644 --- a/api/cloud/oc_cloud_internal.h +++ b/api/cloud/oc_cloud_internal.h @@ -76,7 +76,6 @@ void cloud_close_endpoint(oc_endpoint_t *cloud_ep); void cloud_store_dump_async(const oc_cloud_store_t *store); void cloud_store_load(oc_cloud_store_t *store); void cloud_store_dump(const oc_cloud_store_t *store); -void cloud_store_deinit(oc_cloud_store_t *store); void cloud_store_initialize(oc_cloud_store_t *store); void cloud_manager_cb(oc_cloud_context_t *ctx); void cloud_set_string(oc_string_t *dst, const char *data, size_t len); diff --git a/api/cloud/oc_cloud_manager.c b/api/cloud/oc_cloud_manager.c index 462a97d646..7889cf3d62 100644 --- a/api/cloud/oc_cloud_manager.c +++ b/api/cloud/oc_cloud_manager.c @@ -28,6 +28,7 @@ #include "util/oc_list.h" #include "util/oc_memb.h" #ifdef OC_SECURITY +#include "security/oc_pstat.h" #include "security/oc_tls.h" #endif /* OC_SECURITY */ #include @@ -123,7 +124,15 @@ cloud_start_process(oc_cloud_context_t *ctx) ctx->retry_count = 0; ctx->retry_refresh_token_count = 0; - if (ctx->store.status == OC_CLOUD_INITIALIZED) { +#ifdef OC_SECURITY + oc_sec_pstat_t *pstat = oc_sec_get_pstat(ctx->device); + if (pstat->s != OC_DOS_RFNOP && pstat->s != OC_DOS_RFPRO) { + return; + } +#endif + + if (ctx->store.status == OC_CLOUD_INITIALIZED && + ctx->store.cps == OC_CPS_READYTOREGISTER) { reset_delayed_callback(ctx, cloud_register, message_timeout[0]); } else if (ctx->store.status & OC_CLOUD_REGISTERED) { if (cloud_is_permanent_access_token(ctx->store.expires_in)) { diff --git a/api/cloud/oc_cloud_store.c b/api/cloud/oc_cloud_store.c index 829bcbfa88..624dfa2382 100644 --- a/api/cloud/oc_cloud_store.c +++ b/api/cloud/oc_cloud_store.c @@ -244,19 +244,6 @@ cloud_store_decode(oc_rep_t *rep, oc_cloud_store_t *store) return 0; } -void -cloud_store_deinit(oc_cloud_store_t *store) -{ - cloud_set_string(&store->ci_server, NULL, 0); - cloud_set_string(&store->auth_provider, NULL, 0); - cloud_set_string(&store->uid, NULL, 0); - cloud_set_string(&store->access_token, NULL, 0); - cloud_set_string(&store->refresh_token, NULL, 0); - cloud_set_string(&store->sid, NULL, 0); - store->status = 0; - store->expires_in = 0; -} - static int cloud_store_load_internal(const char *store_name, oc_cloud_store_t *store) { @@ -308,12 +295,12 @@ cloud_store_load_internal(const char *store_name, oc_cloud_store_t *store) void cloud_store_initialize(oc_cloud_store_t *store) { - cloud_set_string(&store->ci_server, "coaps+tcp://127.0.0.1", 21); + cloud_set_string(&store->ci_server, NULL, 0); cloud_set_string(&store->auth_provider, NULL, 0); cloud_set_string(&store->uid, NULL, 0); cloud_set_string(&store->access_token, NULL, 0); cloud_set_string(&store->refresh_token, NULL, 0); - cloud_set_string(&store->sid, "00000000-0000-0000-0000-000000000000", 36); + cloud_set_string(&store->sid, NULL, 0); store->status = 0; store->expires_in = 0; }