Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cloud_server: allow to factory reset from the cloud #372

Merged
merged 4 commits into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
cloud_server: allow to factory reset from the cloud
  • Loading branch information
jkralik committed Feb 7, 2023
commit f1fb3af2143806475b7d407d43ba75e747d01082
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