// SPDX-License-Identifier: BSD-3-Clause OR Apache-2.0 #include "ud3tn/bundle.h" #include "ud3tn/eid.h" #include "ud3tn/report_manager.h" #include "bundle6/reports.h" #include "bundle7/reports.h" #include #include struct bundle_administrative_record *init_administrative_record(void) { struct bundle_administrative_record *const record = malloc( sizeof(struct bundle_administrative_record) ); if (!record) return NULL; record->type = BUNDLE_AR_UNKNOWN; record->flags = BUNDLE_AR_FLAG_NONE; record->start_of_record_ptr = NULL; record->status_report = NULL; record->bpdu = NULL; record->fragment_offset = 0; record->fragment_length = 0; record->bundle_creation_timestamp_ms = 0; record->bundle_sequence_number = 0; record->bundle_source_eid = eid_get_null(); return record; } struct bundle_status_report *init_status_report(void) { struct bundle_status_report *const report = malloc(sizeof(struct bundle_status_report)); if (!report) return NULL; report->status = BUNDLE_SR_FLAG_NONE; report->reason = BUNDLE_SR_REASON_NO_INFO; report->bundle_received_time = 0; report->bundle_forwarded_time = 0; report->bundle_delivered_time = 0; report->bundle_deleted_time = 0; report->bundle_custody_accepted_time = 0; return report; } struct bundle *generate_status_report( const struct bundle *const bundle, const enum bundle_status_report_status_flags status, const enum bundle_status_report_reason reason, const struct eid source, const uint64_t status_timestamp_ms) { if (bundle->protocol_version == 6) return bundle6_generate_status_report( bundle, status, reason, source, status_timestamp_ms ); else if (bundle->protocol_version != 7) return NULL; struct bundle_status_report prototype = { .status = status, .reason = reason, }; switch (status) { case BUNDLE_SR_FLAG_BUNDLE_RECEIVED: prototype.bundle_received_time = status_timestamp_ms; break; case BUNDLE_SR_FLAG_BUNDLE_FORWARDED: prototype.bundle_forwarded_time = status_timestamp_ms; break; case BUNDLE_SR_FLAG_BUNDLE_DELIVERED: prototype.bundle_delivered_time = status_timestamp_ms; break; case BUNDLE_SR_FLAG_BUNDLE_DELETED: prototype.bundle_deleted_time = status_timestamp_ms; break; default: return NULL; } return bundle7_generate_status_report( bundle, &prototype, source, status_timestamp_ms ); } struct bundle_administrative_record *parse_administrative_record( uint8_t protocol_version, const uint8_t *const data, const size_t length) { switch (protocol_version) { // RFC 5050 case 6: return bundle6_parse_administrative_record(data, length); // BPv7-bis case 7: return bundle7_parse_administrative_record(data, length); default: return NULL; } } void free_administrative_record(struct bundle_administrative_record *record) { if (record != NULL) { free(record->status_report); if (record->bpdu != NULL) free(record->bpdu->encapsulated_bundle); free(record->bpdu); eid_free(record->bundle_source_eid); free(record); } }