Skip to content

Commit

Permalink
Fix cloud registration during initialization (#192)
Browse files Browse the repository at this point in the history
* Initialize the cloud cis property with NULL.

* Initialize the cloud sid property with NULL.

* Remove oc_cloud_deinit, because it duplicates cloud_store_initialize now

* Call cloud_register only if cps is set to OC_CPS_READYTOREGISTER

Without this additional check, cloud_register is called during a
fresh startup even when no cloud has been configured. This eventually
led to the cps property to change to the failed state.

* Start cloud manager process only in RFPRO or RFNOP proviosining states

* Add missing OC_SECURITY preprocessor directive
  • Loading branch information
Oxymoron79 authored Feb 17, 2022
1 parent 88c84f5 commit a3a75a5
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 19 deletions.
2 changes: 1 addition & 1 deletion api/cloud/oc_cloud.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion api/cloud/oc_cloud_apis.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion api/cloud/oc_cloud_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 10 additions & 1 deletion api/cloud/oc_cloud_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <stdint.h>
Expand Down Expand Up @@ -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)) {
Expand Down
17 changes: 2 additions & 15 deletions api/cloud/oc_cloud_store.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit a3a75a5

Please sign in to comment.