send CSR response separately from ACK
#include "oc_certs.h"
#include "oc_core_res.h"
-void
-get_csr(oc_request_t *request, oc_interface_mask_t iface_mask, void *data)
-{
- (void)data;
+static oc_separate_response_t csr_response;
- size_t device = request->resource->device;
+struct csr_callback_params
+{
+ size_t device;
+ oc_interface_mask_t iface_mask;
+};
+oc_event_callback_retval_t generate_csr(void *data)
+{
+ if (csr_response.active)
+ {
+ struct csr_callback_params *params = data;
+ size_t device = params->device;
unsigned char csr[4096];
+ oc_set_separate_response_buffer(&csr_response);
+
int ret = oc_certs_generate_csr(device, csr, OC_PDU_SIZE);
+
if (ret != 0) {
- oc_send_response(request, OC_STATUS_INTERNAL_SERVER_ERROR);
- return;
+ oc_send_separate_response(&csr_response, OC_STATUS_INTERNAL_SERVER_ERROR);
+ free(params);
+ return OC_EVENT_DONE;
}
oc_rep_start_root_object();
- if (iface_mask & OC_IF_BASELINE) {
+ if (params->iface_mask & OC_IF_BASELINE) {
oc_process_baseline_interface(
oc_core_get_resource_by_index(OCF_SEC_CSR, device));
}
@@ -46,7 +57,20 @@ get_csr(oc_request_t *request, oc_interface_mask_t iface_mask, void *data)
oc_rep_set_text_string(root, encoding, "oic.sec.encoding.pem");
oc_rep_end_root_object();
- oc_send_response(request, OC_STATUS_OK);
+ oc_send_separate_response(&csr_response, OC_STATUS_OK);
+ }
+ return OC_EVENT_DONE;
+}
+
+void
+get_csr(oc_request_t *request, oc_interface_mask_t iface_mask, void *data)
+{
+ (void)data;
+ oc_indicate_separate_response(request, &csr_response);
+ struct csr_callback_params *params = malloc(sizeof(struct csr_callback_params));
+ params->device = request->resource->device;
+ params->iface_mask = iface_mask;
+ oc_set_delayed_callback(params, generate_csr, 1);
}
#else /* OC_PKI */
