Fix observer removal logic on RFNOP transitions
@@ -150,7 +150,7 @@ oc_pstat_handle_state(oc_sec_pstat_t *ps, size_t device, bool from_storage,
oc_sec_doxm_default(device);
oc_sec_cred_default(device);
oc_sec_acl_default(device);
- if (!from_storage) {
+ if (!from_storage && oc_get_con_res_announced()) {
oc_device_info_t *di = oc_core_get_device_info(device);
oc_free_string(&di->name);
}
@@ -258,9 +258,6 @@ oc_pstat_handle_state(oc_sec_pstat_t *ps, size_t device, bool from_storage,
ps->p = false;
} break;
case OC_DOS_RFNOP: {
-#ifdef OC_SERVER
- coap_remove_observers_on_dos_change(device, false);
-#endif /* OC_SERVER */
ps->p = true;
ps->cm = 0;
ps->tm = 0;
@@ -373,6 +370,11 @@ oc_pstat_handle_state(oc_sec_pstat_t *ps, size_t device, bool from_storage,
break;
}
memmove(&pstat[device], ps, sizeof(oc_sec_pstat_t));
+#ifdef OC_SERVER
+ if (ps->s == OC_DOS_RFNOP) {
+ coap_remove_observers_on_dos_change(device, false);
+ }
+#endif /* OC_SERVER */
OC_DBG("oc_pstat: leaving pstat_handle_state");
return true;
pstat_state_error:
