2022-02-17 16:14:33 +01:00
|
|
|
// SPDX-License-Identifier: BSD-3-Clause OR Apache-2.0
|
2020-11-13 10:42:31 +01:00
|
|
|
#include "bundle7/bundle7.h"
|
|
|
|
|
#include "bundle7/create.h"
|
|
|
|
|
|
2020-11-17 12:49:29 +01:00
|
|
|
#include "ud3tn/bundle.h"
|
|
|
|
|
#include "ud3tn/common.h"
|
2020-11-13 10:42:31 +01:00
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
#include <stddef.h>
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct bundle *bundle7_create_local(
|
|
|
|
|
void *payload, size_t payload_length,
|
2025-04-15 13:18:52 +02:00
|
|
|
const char *source, const char *destination, const char *report_to,
|
2022-12-21 14:02:40 +01:00
|
|
|
uint64_t creation_time_ms, uint64_t sequence_number,
|
|
|
|
|
uint64_t lifetime_ms, enum bundle_proc_flags proc_flags)
|
2020-11-13 10:42:31 +01:00
|
|
|
{
|
2025-04-14 08:59:36 +02:00
|
|
|
if (!payload || !source || !destination)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
2020-11-13 10:42:31 +01:00
|
|
|
struct bundle *bundle = bundle_init();
|
|
|
|
|
|
|
|
|
|
if (bundle == NULL) {
|
|
|
|
|
free(payload);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bundle->protocol_version = 0x7;
|
|
|
|
|
bundle->proc_flags = proc_flags;
|
|
|
|
|
|
|
|
|
|
// Creation time
|
2022-12-21 14:02:40 +01:00
|
|
|
bundle->creation_timestamp_ms = creation_time_ms;
|
2021-06-23 20:21:43 +02:00
|
|
|
bundle->sequence_number = sequence_number;
|
2022-12-21 14:02:40 +01:00
|
|
|
bundle->lifetime_ms = lifetime_ms;
|
2020-11-13 10:42:31 +01:00
|
|
|
|
2023-09-29 14:35:03 +02:00
|
|
|
bundle->crc_type = DEFAULT_BPV7_CRC_TYPE;
|
2020-11-13 10:42:31 +01:00
|
|
|
|
|
|
|
|
// Create payload block and block list
|
|
|
|
|
bundle->payload_block = bundle_block_create(BUNDLE_BLOCK_TYPE_PAYLOAD);
|
|
|
|
|
bundle->blocks = bundle_block_entry_create(bundle->payload_block);
|
|
|
|
|
|
|
|
|
|
if (bundle->payload_block == NULL || bundle->blocks == NULL)
|
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
|
|
bundle->source = strdup(source);
|
|
|
|
|
if (bundle->source == NULL)
|
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
|
|
bundle->destination = strdup(destination);
|
|
|
|
|
if (bundle->destination == NULL)
|
|
|
|
|
goto fail; // bundle_free takes care of source
|
|
|
|
|
|
2025-04-15 13:18:52 +02:00
|
|
|
if (report_to)
|
|
|
|
|
bundle->report_to = strdup(report_to);
|
|
|
|
|
else
|
|
|
|
|
bundle->report_to = strdup("dtn:none");
|
2020-11-13 10:42:31 +01:00
|
|
|
if (bundle->report_to == NULL)
|
|
|
|
|
goto fail; // bundle_free takes care of source and destination
|
|
|
|
|
|
|
|
|
|
bundle->payload_block->data = payload;
|
|
|
|
|
bundle->payload_block->length = payload_length;
|
|
|
|
|
|
|
|
|
|
bundle7_recalculate_primary_block_length(bundle);
|
|
|
|
|
|
|
|
|
|
return bundle;
|
|
|
|
|
|
|
|
|
|
fail:
|
|
|
|
|
free(payload);
|
|
|
|
|
bundle_free(bundle);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|