Skip to content

Commit

Permalink
cloud_server: allow to factory reset from the cloud
Browse files Browse the repository at this point in the history
  • Loading branch information
jkralik committed Feb 6, 2023
1 parent 86cde01 commit 7961f6c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
17 changes: 12 additions & 5 deletions api/oc_mnt.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ get_mnt(oc_request_t *request, oc_interface_mask_t iface_mask, void *data)
oc_send_response(request, OC_STATUS_OK);
}

static oc_event_callback_retval_t
factory_reset(void *data)
{
size_t device = (size_t)(data);
oc_pstat_reset_device(device, false);
return OC_EVENT_DONE;
}

void
post_mnt(oc_request_t *request, oc_interface_mask_t iface_mask, void *data)
{
Expand All @@ -54,12 +62,11 @@ post_mnt(oc_request_t *request, oc_interface_mask_t iface_mask, void *data)
if (oc_rep_get_bool(request->request_payload, "fr", &fr)) {
if (fr) {
#ifdef OC_SECURITY
if (oc_pstat_reset_device(request->resource->device, false)) {
success = true;
}
#else /* OC_SECURITY */
// 250ms delay to allow the response to be sent before the device resets
oc_set_delayed_callback_ms((void *)request->resource->device,
factory_reset, 250);
#endif /* OC_SECURITY */
success = true;
#endif /* !OC_SECURITY */
}
}

Expand Down
12 changes: 12 additions & 0 deletions apps/cloud_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,15 @@ register_con()
oc_cloud_add_resource(con_res);
}

#ifdef OC_MNT
static void
register_mnt()
{
oc_resource_t *mnt_res = oc_core_get_resource_by_index(OCF_MNT, 0);
oc_cloud_add_resource(mnt_res);
}
#endif /* OC_MNT */

static void
register_resources(void)
{
Expand All @@ -564,6 +573,9 @@ register_resources(void)
register_collection();
#endif /* OC_COLLECTIONS */
register_con();
#ifdef OC_MNT
register_mnt();
#endif /* OC_MNT */
}

#if defined(OC_SECURITY) && defined(OC_PKI)
Expand Down

0 comments on commit 7961f6c

Please sign in to comment.