libe3 0.6.1
C++ library for E3AP RAN vendor integration
Loading...
Searching...
No Matches
e2sm_dapp_c.cpp
Go to the documentation of this file.
1/**
2 * @file e2sm_dapp_c.cpp
3 * @brief C API of the E2SM-DAPP codec, implemented on top of the C++ one.
4 *
5 * Every function converts the C struct to its C++ counterpart (or back), calls
6 * pack() / unpack(), and maps the result to an e3_error_t. All memory handed to
7 * the caller is malloc'ed, so the free_* functions and plain `free` both work.
8 * Nothing here lets a C++ exception cross the C boundary.
9 *
10 * SPDX-FileCopyrightText: Copyright (c) 2026 Northeastern University
11 * SPDX-License-Identifier: Apache-2.0
12 */
13
14#include "libe3/e2sm_dapp_c.h"
15
16#include <cstdlib>
17#include <cstring>
18#include <new>
19#include <string>
20#include <vector>
21
22#include "libe3/e2sm_dapp.hpp"
23
24namespace {
25
26namespace dapp = libe3::e2sm_dapp;
27
28// Grammar limits that bound the size of what is copied from caller memory, so
29// that an absurd length is rejected before it is read, not after.
30constexpr size_t k_max_payload = 32768;
31constexpr size_t k_max_name = 150;
32constexpr size_t k_max_oid = 1000;
33constexpr size_t k_max_subs = 256;
34constexpr size_t k_max_rf_per_sub = 64;
35constexpr size_t k_max_report_sty = 2;
36constexpr size_t k_max_ctrl_sty = 1;
37
38/// An error to report from inside a conversion; caught at the API boundary.
39struct CError {
40 e3_error_t code;
41};
42
43[[noreturn]] void fail(e3_error_t code)
44{
45 throw CError{code};
46}
47
48// ---------------------------------------------------------------------------
49// Small allocation helpers (malloc, so that `free` releases them).
50// ---------------------------------------------------------------------------
51
52template <class T>
53T* alloc_array(size_t n)
54{
55 if (n == 0) {
56 return nullptr;
57 }
58 void* p = std::calloc(n, sizeof(T));
59 if (p == nullptr) {
61 }
62 return static_cast<T*>(p);
63}
64
65void set_bytes(libe3_e2sm_dapp_bytes_t& dst, const uint8_t* src, size_t n)
66{
67 dst.data = alloc_array<uint8_t>(n);
68 dst.len = n;
69 if (n != 0) {
70 std::memcpy(dst.data, src, n);
71 }
72}
73
74void set_bytes(libe3_e2sm_dapp_bytes_t& dst, const std::string& s)
75{
76 set_bytes(dst, reinterpret_cast<const uint8_t*>(s.data()), s.size());
77}
78
79// ---------------------------------------------------------------------------
80// C -> C++
81// ---------------------------------------------------------------------------
82
83std::vector<uint8_t> payload_from(const libe3_e2sm_dapp_bytes_t& b)
84{
85 // An empty payload is a value the encoder rejects (SIZE(1..32768)): let it.
86 if (b.len > k_max_payload) {
87 fail(E3_ENCODE_FAILED);
88 }
89 if (b.len != 0 && b.data == nullptr) {
90 fail(E3_INVALID_PARAM);
91 }
92 return b.len == 0 ? std::vector<uint8_t>() : std::vector<uint8_t>(b.data, b.data + b.len);
93}
94
95std::string string_from(const libe3_e2sm_dapp_bytes_t& b, size_t max)
96{
97 if (b.len > max) {
98 fail(E3_ENCODE_FAILED);
99 }
100 if (b.len != 0 && b.data == nullptr) {
101 fail(E3_INVALID_PARAM);
102 }
103 return b.len == 0 ? std::string() : std::string(reinterpret_cast<const char*>(b.data), b.len);
104}
105
106dapp::dapp_e3_subscription_list_l subs_from(const libe3_e2sm_dapp_sub_list_t& s)
107{
108 if (s.n_items > k_max_subs) {
109 fail(E3_ENCODE_FAILED);
110 }
111 if (s.n_items != 0 && s.items == nullptr) {
112 fail(E3_INVALID_PARAM);
113 }
114 dapp::dapp_e3_subscription_list_l out;
115 out.resize(s.n_items);
116 for (size_t i = 0; i < s.n_items; ++i) {
117 const auto& in = s.items[i];
118 if (in.n_ran_functions > k_max_rf_per_sub) {
119 fail(E3_ENCODE_FAILED);
120 }
121 if (in.n_ran_functions != 0 && in.ran_functions == nullptr) {
122 fail(E3_INVALID_PARAM);
123 }
124 out[i].dapp_id = in.dapp_id;
125 out[i].subscribed_e3_ran_functions.assign(in.ran_functions, in.ran_functions + in.n_ran_functions);
126 }
127 return out;
128}
129
130void to_cpp(const libe3_e2sm_dapp_ind_hdr_format1_t& in, dapp::e2sm_dapp_ind_hdr_format1_s& out)
131{
132 out.ran_function_id = in.ran_function_id;
133 out.dapp_id = in.dapp_id;
134 out.node_type = in.node_type;
135 std::memcpy(out.node_plmn_id.data(), in.node_plmn_id, 3);
136 out.node_nb_id = in.node_nb_id;
137 out.node_cu_du_id_present = in.has_node_cu_du_id;
138 out.node_cu_du_id = in.node_cu_du_id;
139 out.timestamp_present = in.has_timestamp;
140 out.timestamp = in.timestamp;
141 out.sequence_id_present = in.has_sequence_id;
142 out.sequence_id = in.sequence_id;
143}
144
145void to_cpp(const libe3_e2sm_dapp_ind_hdr_format2_t& in, dapp::e2sm_dapp_ind_hdr_format2_s& out)
146{
147 out.node_type = in.node_type;
148 std::memcpy(out.node_plmn_id.data(), in.node_plmn_id, 3);
149 out.node_nb_id = in.node_nb_id;
150 out.node_cu_du_id_present = in.has_node_cu_du_id;
151 out.node_cu_du_id = in.node_cu_du_id;
152 out.timestamp_present = in.has_timestamp;
153 out.timestamp = in.timestamp;
154 out.sequence_id_present = in.has_sequence_id;
155 out.sequence_id = in.sequence_id;
156}
157
158dapp::ran_function_name_s name_from(const libe3_e2sm_dapp_ran_function_name_t& in)
159{
160 dapp::ran_function_name_s out;
161 out.ran_function_short_name.from_string(string_from(in.short_name, k_max_name));
162 out.ran_function_e2sm_o_id.from_string(string_from(in.e2sm_oid, k_max_oid));
163 out.ran_function_description.from_string(string_from(in.description, k_max_name));
164 out.ran_function_instance_present = in.has_instance;
165 out.ran_function_instance = in.instance;
166 return out;
167}
168
169// ---------------------------------------------------------------------------
170// C++ -> C (decode results). Allocations go into `out` as they are made, so the
171// caller's free_* can release a half-filled struct.
172// ---------------------------------------------------------------------------
173
174void subs_to_c(const dapp::dapp_e3_subscription_list_l& in, libe3_e2sm_dapp_sub_list_t& out)
175{
176 out.items = alloc_array<libe3_e2sm_dapp_sub_item_t>(in.size());
177 out.n_items = 0;
178 for (size_t i = 0; i < in.size(); ++i) {
179 auto& o = out.items[i];
180 o.dapp_id = static_cast<uint32_t>(in[i].dapp_id);
181 o.ran_functions = alloc_array<uint32_t>(in[i].subscribed_e3_ran_functions.size());
182 o.n_ran_functions = in[i].subscribed_e3_ran_functions.size();
183 for (size_t j = 0; j < o.n_ran_functions; ++j) {
184 o.ran_functions[j] = static_cast<uint32_t>(in[i].subscribed_e3_ran_functions[j]);
185 }
186 out.n_items = i + 1;
187 }
188}
189
190void to_c(const dapp::e2sm_dapp_ind_hdr_format1_s& in, libe3_e2sm_dapp_ind_hdr_format1_t& out)
191{
192 out.ran_function_id = static_cast<uint32_t>(in.ran_function_id);
193 out.dapp_id = static_cast<uint32_t>(in.dapp_id);
194 out.node_type = in.node_type;
195 std::memcpy(out.node_plmn_id, in.node_plmn_id.data(), 3);
196 out.node_nb_id = static_cast<uint32_t>(in.node_nb_id);
197 out.has_node_cu_du_id = in.node_cu_du_id_present;
198 out.node_cu_du_id = in.node_cu_du_id_present ? static_cast<uint32_t>(in.node_cu_du_id) : 0;
199 out.has_timestamp = in.timestamp_present;
200 out.timestamp = in.timestamp_present ? in.timestamp : 0;
201 out.has_sequence_id = in.sequence_id_present;
202 out.sequence_id = in.sequence_id_present ? in.sequence_id : 0;
203}
204
205void to_c(const dapp::e2sm_dapp_ind_hdr_format2_s& in, libe3_e2sm_dapp_ind_hdr_format2_t& out)
206{
207 out.node_type = in.node_type;
208 std::memcpy(out.node_plmn_id, in.node_plmn_id.data(), 3);
209 out.node_nb_id = static_cast<uint32_t>(in.node_nb_id);
210 out.has_node_cu_du_id = in.node_cu_du_id_present;
211 out.node_cu_du_id = in.node_cu_du_id_present ? static_cast<uint32_t>(in.node_cu_du_id) : 0;
212 out.has_timestamp = in.timestamp_present;
213 out.timestamp = in.timestamp_present ? in.timestamp : 0;
214 out.has_sequence_id = in.sequence_id_present;
215 out.sequence_id = in.sequence_id_present ? in.sequence_id : 0;
216}
217
218// ---------------------------------------------------------------------------
219// Free helpers.
220// ---------------------------------------------------------------------------
221
222void release(libe3_e2sm_dapp_bytes_t& b)
223{
224 std::free(b.data);
225 b.data = nullptr;
226 b.len = 0;
227}
228
229void release(libe3_e2sm_dapp_sub_list_t& l)
230{
231 if (l.items != nullptr) {
232 for (size_t i = 0; i < l.n_items; ++i) {
233 std::free(l.items[i].ran_functions);
234 }
235 std::free(l.items);
236 }
237 l.items = nullptr;
238 l.n_items = 0;
239}
240
242{
243 release(v.name.short_name);
244 release(v.name.e2sm_oid);
245 release(v.name.description);
246 if (v.report_styles != nullptr) {
247 for (size_t i = 0; i < v.n_report_styles; ++i) {
248 release(v.report_styles[i].name);
250 }
251 std::free(v.report_styles);
252 }
253 if (v.ctrl_styles != nullptr) {
254 for (size_t i = 0; i < v.n_ctrl_styles; ++i) {
255 release(v.ctrl_styles[i].name);
257 }
258 std::free(v.ctrl_styles);
259 }
260 std::memset(&v, 0, sizeof(v));
261}
262
263// ---------------------------------------------------------------------------
264// The shared bodies of the encode_* and decode_* functions.
265// ---------------------------------------------------------------------------
266
267/// Pack `v` into a malloc'ed buffer in `*out`.
268e3_error_t pack_to_c(const std::vector<uint8_t>& buf, libe3_e2sm_dapp_bytes_t* out)
269{
270 set_bytes(*out, buf.data(), buf.size());
271 return E3_SUCCESS;
272}
273
274template <class Cpp, class CIn, class Convert>
275e3_error_t encode_impl(const CIn* in, libe3_e2sm_dapp_bytes_t* out, Convert convert)
276{
277 if (in == nullptr || out == nullptr) {
278 return E3_INVALID_PARAM;
279 }
280 out->data = nullptr;
281 out->len = 0;
282 try {
283 Cpp v;
284 convert(*in, v);
285 std::vector<uint8_t> buf;
286 if (v.pack(buf) != dapp::ASN_SUCCESS) {
287 return E3_ENCODE_FAILED;
288 }
289 return pack_to_c(buf, out);
290 } catch (const CError& e) {
291 release(*out);
292 return e.code;
293 } catch (const std::bad_alloc&) {
294 release(*out);
295 return E3_SM_ERROR_MEMORY;
296 } catch (...) {
297 release(*out);
298 return E3_INTERNAL_ERROR;
299 }
300}
301
302template <class Cpp, class COut, class Convert, class Release>
303e3_error_t decode_impl(const uint8_t* buf, size_t len, COut* out, Convert convert, Release release_out)
304{
305 if (out == nullptr) {
306 return E3_INVALID_PARAM;
307 }
308 std::memset(out, 0, sizeof(*out));
309 if (buf == nullptr) {
310 return E3_INVALID_PARAM;
311 }
312 try {
313 Cpp v;
314 if (v.unpack(buf, len) != dapp::ASN_SUCCESS) {
315 return E3_DECODE_FAILED;
316 }
317 convert(v, *out);
318 return E3_SUCCESS;
319 } catch (const CError& e) {
320 release_out(*out);
321 std::memset(out, 0, sizeof(*out));
322 return e.code;
323 } catch (const std::bad_alloc&) {
324 release_out(*out);
325 std::memset(out, 0, sizeof(*out));
326 return E3_SM_ERROR_MEMORY;
327 } catch (...) {
328 release_out(*out);
329 std::memset(out, 0, sizeof(*out));
330 return E3_INTERNAL_ERROR;
331 }
332}
333
334} // namespace
335
336extern "C" {
337
339{
340 if (b != nullptr) {
341 release(*b);
342 }
343}
344
345// ---- event trigger ----
346
348{
349 return encode_impl<dapp::e2sm_dapp_event_trigger_s>(
350 in, out, [](const libe3_e2sm_dapp_event_trigger_t& s, dapp::e2sm_dapp_event_trigger_s&) {
352 fail(E3_INVALID_PARAM);
353 }
354 });
355}
356
358{
359 return decode_impl<dapp::e2sm_dapp_event_trigger_s>(
360 buf,
361 len,
362 out,
363 [](const dapp::e2sm_dapp_event_trigger_s&, libe3_e2sm_dapp_event_trigger_t& d) {
365 },
367}
368
370{
371 if (v != nullptr) {
372 std::memset(v, 0, sizeof(*v));
373 }
374}
375
376// ---- action definition ----
377
380{
381 return encode_impl<dapp::e2sm_dapp_action_definition_s>(
382 in, out, [](const libe3_e2sm_dapp_action_definition_t& s, dapp::e2sm_dapp_action_definition_s& d) {
384 fail(E3_INVALID_PARAM);
385 }
386 d.ric_style_type = s.ric_style_type;
387 });
388}
389
391{
392 return decode_impl<dapp::e2sm_dapp_action_definition_s>(
393 buf,
394 len,
395 out,
396 [](const dapp::e2sm_dapp_action_definition_s& s, libe3_e2sm_dapp_action_definition_t& d) {
398 d.ric_style_type = s.ric_style_type;
399 },
401}
402
404{
405 if (v != nullptr) {
406 std::memset(v, 0, sizeof(*v));
407 }
408}
409
410// ---- indication header ----
411
413{
414 return encode_impl<dapp::e2sm_dapp_ind_hdr_s>(
415 in, out, [](const libe3_e2sm_dapp_ind_hdr_t& s, dapp::e2sm_dapp_ind_hdr_s& d) {
416 switch (s.format) {
418 to_cpp(s.frmt_1, d.ric_ind_hdr_formats.set_ind_hdr_format1());
419 break;
421 to_cpp(s.frmt_2, d.ric_ind_hdr_formats.set_ind_hdr_format2());
422 break;
423 default:
424 fail(E3_INVALID_PARAM);
425 }
426 });
427}
428
430{
431 return decode_impl<dapp::e2sm_dapp_ind_hdr_s>(
432 buf,
433 len,
434 out,
435 [](const dapp::e2sm_dapp_ind_hdr_s& s, libe3_e2sm_dapp_ind_hdr_t& d) {
436 using types = dapp::e2sm_dapp_ind_hdr_s::ric_ind_hdr_formats_c_::types;
437 if (s.ric_ind_hdr_formats.type().value == types::ind_hdr_format1) {
439 to_c(s.ric_ind_hdr_formats.ind_hdr_format1(), d.frmt_1);
440 } else {
442 to_c(s.ric_ind_hdr_formats.ind_hdr_format2(), d.frmt_2);
443 }
444 },
446}
447
449{
450 if (v != nullptr) {
451 std::memset(v, 0, sizeof(*v));
452 }
453}
454
455// ---- indication message ----
456
458{
459 return encode_impl<dapp::e2sm_dapp_ind_msg_s>(
460 in, out, [](const libe3_e2sm_dapp_ind_msg_t& s, dapp::e2sm_dapp_ind_msg_s& d) {
461 switch (s.format) {
463 auto& f = d.ric_ind_msg_formats.set_ind_msg_format1();
464 static_cast<std::vector<uint8_t>&>(f.data) = payload_from(s.frmt_1.data);
465 // data-size is the payload length, as in the C API's contract.
466 f.data_size = static_cast<uint16_t>(f.data.size());
467 break;
468 }
470 d.ric_ind_msg_formats.set_ind_msg_format2().dapp_e3_subscriptions =
471 subs_from(s.frmt_2.dapp_e3_subscriptions);
472 break;
473 default:
474 fail(E3_INVALID_PARAM);
475 }
476 });
477}
478
480{
481 return decode_impl<dapp::e2sm_dapp_ind_msg_s>(
482 buf,
483 len,
484 out,
485 [](const dapp::e2sm_dapp_ind_msg_s& s, libe3_e2sm_dapp_ind_msg_t& d) {
486 using types = dapp::e2sm_dapp_ind_msg_s::ric_ind_msg_formats_c_::types;
487 if (s.ric_ind_msg_formats.type().value == types::ind_msg_format1) {
489 const auto& dat = s.ric_ind_msg_formats.ind_msg_format1().data;
490 set_bytes(d.frmt_1.data, dat.data(), dat.size());
491 } else {
493 subs_to_c(s.ric_ind_msg_formats.ind_msg_format2().dapp_e3_subscriptions,
495 }
496 },
498 release(d.frmt_1.data);
499 release(d.frmt_2.dapp_e3_subscriptions);
500 });
501}
502
504{
505 if (v != nullptr) {
506 release(v->frmt_1.data);
507 release(v->frmt_2.dapp_e3_subscriptions);
508 std::memset(v, 0, sizeof(*v));
509 }
510}
511
512// ---- control header ----
513
515{
516 return encode_impl<dapp::e2sm_dapp_ctrl_hdr_s>(
517 in, out, [](const libe3_e2sm_dapp_ctrl_hdr_t& s, dapp::e2sm_dapp_ctrl_hdr_s& d) {
519 fail(E3_INVALID_PARAM);
520 }
521 auto& f = d.ric_ctrl_hdr_formats.ctrl_hdr_format1();
522 f.ran_function_id = s.ran_function_id;
523 f.dapp_id = s.dapp_id;
524 f.timestamp_present = s.has_timestamp;
525 f.timestamp = s.timestamp;
526 f.sequence_id_present = s.has_sequence_id;
527 f.sequence_id = s.sequence_id;
528 });
529}
530
532{
533 return decode_impl<dapp::e2sm_dapp_ctrl_hdr_s>(
534 buf,
535 len,
536 out,
537 [](const dapp::e2sm_dapp_ctrl_hdr_s& s, libe3_e2sm_dapp_ctrl_hdr_t& d) {
538 const auto& f = s.ric_ctrl_hdr_formats.ctrl_hdr_format1();
540 d.ran_function_id = static_cast<uint32_t>(f.ran_function_id);
541 d.dapp_id = static_cast<uint32_t>(f.dapp_id);
542 d.has_timestamp = f.timestamp_present;
543 d.timestamp = f.timestamp_present ? f.timestamp : 0;
544 d.has_sequence_id = f.sequence_id_present;
545 d.sequence_id = f.sequence_id_present ? f.sequence_id : 0;
546 },
548}
549
551{
552 if (v != nullptr) {
553 std::memset(v, 0, sizeof(*v));
554 }
555}
556
557// ---- control message ----
558
560{
561 return encode_impl<dapp::e2sm_dapp_ctrl_msg_s>(
562 in, out, [](const libe3_e2sm_dapp_ctrl_msg_t& s, dapp::e2sm_dapp_ctrl_msg_s& d) {
564 fail(E3_INVALID_PARAM);
565 }
566 auto& f = d.ric_ctrl_msg_formats.ctrl_msg_format1();
567 static_cast<std::vector<uint8_t>&>(f.data) = payload_from(s.data);
568 f.data_size = static_cast<uint16_t>(f.data.size());
569 });
570}
571
573{
574 return decode_impl<dapp::e2sm_dapp_ctrl_msg_s>(
575 buf,
576 len,
577 out,
578 [](const dapp::e2sm_dapp_ctrl_msg_s& s, libe3_e2sm_dapp_ctrl_msg_t& d) {
579 const auto& dat = s.ric_ctrl_msg_formats.ctrl_msg_format1().data;
581 set_bytes(d.data, dat.data(), dat.size());
582 },
583 [](libe3_e2sm_dapp_ctrl_msg_t& d) { release(d.data); });
584}
585
587{
588 if (v != nullptr) {
589 release(v->data);
590 std::memset(v, 0, sizeof(*v));
591 }
592}
593
594// ---- control outcome ----
595
597{
598 return encode_impl<dapp::e2sm_dapp_ctrl_outcome_s>(
599 in, out, [](const libe3_e2sm_dapp_ctrl_outcome_t& s, dapp::e2sm_dapp_ctrl_outcome_s& d) {
601 fail(E3_INVALID_PARAM);
602 }
603 auto& f = d.ric_ctrl_outcome_formats.ctrl_outcome_format1();
604 f.timestamp_present = s.has_timestamp;
605 f.timestamp = s.timestamp;
606 f.sequence_id_present = s.has_sequence_id;
607 f.sequence_id = s.sequence_id;
609 if (s.e3_control_outcome.len != 0 && s.e3_control_outcome.data == nullptr) {
610 fail(E3_INVALID_PARAM);
611 }
612 f.e3_ctrl_outcome_present = true;
613 f.e3_ctrl_outcome.from_bytes(s.e3_control_outcome.data, s.e3_control_outcome.len);
614 }
615 });
616}
617
619{
620 return decode_impl<dapp::e2sm_dapp_ctrl_outcome_s>(
621 buf,
622 len,
623 out,
624 [](const dapp::e2sm_dapp_ctrl_outcome_s& s, libe3_e2sm_dapp_ctrl_outcome_t& d) {
625 const auto& f = s.ric_ctrl_outcome_formats.ctrl_outcome_format1();
627 d.has_timestamp = f.timestamp_present;
628 d.timestamp = f.timestamp_present ? f.timestamp : 0;
629 d.has_sequence_id = f.sequence_id_present;
630 d.sequence_id = f.sequence_id_present ? f.sequence_id : 0;
631 d.has_e3_control_outcome = f.e3_ctrl_outcome_present;
632 if (f.e3_ctrl_outcome_present) {
633 set_bytes(d.e3_control_outcome, f.e3_ctrl_outcome.data(), f.e3_ctrl_outcome.size());
634 }
635 },
637}
638
640{
641 if (v != nullptr) {
642 release(v->e3_control_outcome);
643 std::memset(v, 0, sizeof(*v));
644 }
645}
646
647// ---- RAN function definition ----
648
651{
652 return encode_impl<dapp::e2sm_dapp_ran_function_definition_s>(
653 in,
654 out,
655 [](const libe3_e2sm_dapp_ran_function_definition_t& s, dapp::e2sm_dapp_ran_function_definition_s& d) {
656 d.ran_function_name = name_from(s.name);
657 d.ran_function_definition_event_trigger_present = s.has_event_trigger;
658
659 d.ran_function_definition_report_present = s.has_report;
660 if (s.has_report) {
661 if (s.n_report_styles > k_max_report_sty) {
662 fail(E3_ENCODE_FAILED);
663 }
664 if (s.n_report_styles != 0 && s.report_styles == nullptr) {
665 fail(E3_INVALID_PARAM);
666 }
667 auto& list = d.ran_function_definition_report.ric_report_style_list;
668 list.resize(s.n_report_styles);
669 for (size_t i = 0; i < s.n_report_styles; ++i) {
670 const auto& in_i = s.report_styles[i];
671 auto& o = list[i];
672 o.ric_report_style_type = in_i.report_style_type;
673 o.ric_report_style_name.from_string(string_from(in_i.name, k_max_name));
674 o.ric_ind_hdr_format_type = in_i.ind_hdr_format_type;
675 o.ric_ind_msg_format_type = in_i.ind_msg_format_type;
676 o.dapp_e3_subscriptions_present = in_i.has_dapp_e3_subscriptions;
677 if (in_i.has_dapp_e3_subscriptions) {
678 o.dapp_e3_subscriptions = subs_from(in_i.dapp_e3_subscriptions);
679 }
680 }
681 }
682
683 d.ran_function_definition_ctrl_present = s.has_ctrl;
684 if (s.has_ctrl) {
685 if (s.n_ctrl_styles > k_max_ctrl_sty) {
686 fail(E3_ENCODE_FAILED);
687 }
688 if (s.n_ctrl_styles != 0 && s.ctrl_styles == nullptr) {
689 fail(E3_INVALID_PARAM);
690 }
691 auto& list = d.ran_function_definition_ctrl.ric_ctrl_style_list;
692 list.resize(s.n_ctrl_styles);
693 for (size_t i = 0; i < s.n_ctrl_styles; ++i) {
694 const auto& in_i = s.ctrl_styles[i];
695 auto& o = list[i];
696 o.ric_ctrl_style_type = in_i.ctrl_style_type;
697 o.ric_ctrl_style_name.from_string(string_from(in_i.name, k_max_name));
698 o.ric_ctrl_hdr_format_type = in_i.ctrl_hdr_format_type;
699 o.ric_ctrl_msg_format_type = in_i.ctrl_msg_format_type;
700 o.ric_ctrl_outcome_format_type = in_i.ctrl_outcome_format_type;
701 o.dapp_e3_subscriptions_present = in_i.has_dapp_e3_subscriptions;
702 if (in_i.has_dapp_e3_subscriptions) {
703 o.dapp_e3_subscriptions = subs_from(in_i.dapp_e3_subscriptions);
704 }
705 }
706 }
707 });
708}
709
711 size_t len,
713{
714 return decode_impl<dapp::e2sm_dapp_ran_function_definition_s>(
715 buf,
716 len,
717 out,
718 [](const dapp::e2sm_dapp_ran_function_definition_s& s, libe3_e2sm_dapp_ran_function_definition_t& d) {
719 const auto& n = s.ran_function_name;
720 set_bytes(d.name.short_name, n.ran_function_short_name.to_string());
721 set_bytes(d.name.e2sm_oid, n.ran_function_e2sm_o_id.to_string());
722 set_bytes(d.name.description, n.ran_function_description.to_string());
723 d.name.has_instance = n.ran_function_instance_present;
724 d.name.instance = n.ran_function_instance_present ? n.ran_function_instance : 0;
725
726 d.has_event_trigger = s.ran_function_definition_event_trigger_present;
727
728 d.has_report = s.ran_function_definition_report_present;
729 if (d.has_report) {
730 const auto& list = s.ran_function_definition_report.ric_report_style_list;
731 d.report_styles = alloc_array<libe3_e2sm_dapp_report_style_t>(list.size());
732 d.n_report_styles = list.size();
733 for (size_t i = 0; i < list.size(); ++i) {
734 auto& o = d.report_styles[i];
735 o.report_style_type = list[i].ric_report_style_type;
736 o.ind_hdr_format_type = list[i].ric_ind_hdr_format_type;
737 o.ind_msg_format_type = list[i].ric_ind_msg_format_type;
738 set_bytes(o.name, list[i].ric_report_style_name.to_string());
739 o.has_dapp_e3_subscriptions = list[i].dapp_e3_subscriptions_present;
740 if (o.has_dapp_e3_subscriptions) {
741 subs_to_c(list[i].dapp_e3_subscriptions, o.dapp_e3_subscriptions);
742 }
743 }
744 }
745
746 d.has_ctrl = s.ran_function_definition_ctrl_present;
747 if (d.has_ctrl) {
748 const auto& list = s.ran_function_definition_ctrl.ric_ctrl_style_list;
749 d.ctrl_styles = alloc_array<libe3_e2sm_dapp_ctrl_style_t>(list.size());
750 d.n_ctrl_styles = list.size();
751 for (size_t i = 0; i < list.size(); ++i) {
752 auto& o = d.ctrl_styles[i];
753 o.ctrl_style_type = list[i].ric_ctrl_style_type;
754 o.ctrl_hdr_format_type = list[i].ric_ctrl_hdr_format_type;
755 o.ctrl_msg_format_type = list[i].ric_ctrl_msg_format_type;
756 o.ctrl_outcome_format_type = list[i].ric_ctrl_outcome_format_type;
757 set_bytes(o.name, list[i].ric_ctrl_style_name.to_string());
758 o.has_dapp_e3_subscriptions = list[i].dapp_e3_subscriptions_present;
759 if (o.has_dapp_e3_subscriptions) {
760 subs_to_c(list[i].dapp_e3_subscriptions, o.dapp_e3_subscriptions);
761 }
762 }
763 }
764 },
765 release_def);
766}
767
769{
770 if (v != nullptr) {
771 release_def(*v);
772 }
773}
774
775} // extern "C"
E2SM-DAPP information elements and their APER codec (C++ API).
e3_error_t libe3_e2sm_dapp_decode_ctrl_outcome(const uint8_t *buf, size_t len, libe3_e2sm_dapp_ctrl_outcome_t *out)
e3_error_t libe3_e2sm_dapp_encode_ctrl_hdr(const libe3_e2sm_dapp_ctrl_hdr_t *in, libe3_e2sm_dapp_bytes_t *out)
e3_error_t libe3_e2sm_dapp_decode_ctrl_hdr(const uint8_t *buf, size_t len, libe3_e2sm_dapp_ctrl_hdr_t *out)
e3_error_t libe3_e2sm_dapp_encode_ind_msg(const libe3_e2sm_dapp_ind_msg_t *in, libe3_e2sm_dapp_bytes_t *out)
e3_error_t libe3_e2sm_dapp_encode_ctrl_outcome(const libe3_e2sm_dapp_ctrl_outcome_t *in, libe3_e2sm_dapp_bytes_t *out)
e3_error_t libe3_e2sm_dapp_encode_action_definition(const libe3_e2sm_dapp_action_definition_t *in, libe3_e2sm_dapp_bytes_t *out)
void libe3_e2sm_dapp_free_event_trigger(libe3_e2sm_dapp_event_trigger_t *v)
e3_error_t libe3_e2sm_dapp_encode_event_trigger(const libe3_e2sm_dapp_event_trigger_t *in, libe3_e2sm_dapp_bytes_t *out)
e3_error_t libe3_e2sm_dapp_decode_action_definition(const uint8_t *buf, size_t len, libe3_e2sm_dapp_action_definition_t *out)
void libe3_e2sm_dapp_free_ctrl_outcome(libe3_e2sm_dapp_ctrl_outcome_t *v)
e3_error_t libe3_e2sm_dapp_decode_ctrl_msg(const uint8_t *buf, size_t len, libe3_e2sm_dapp_ctrl_msg_t *out)
void libe3_e2sm_dapp_free_ran_function_definition(libe3_e2sm_dapp_ran_function_definition_t *v)
void libe3_e2sm_dapp_free_ind_msg(libe3_e2sm_dapp_ind_msg_t *v)
e3_error_t libe3_e2sm_dapp_encode_ctrl_msg(const libe3_e2sm_dapp_ctrl_msg_t *in, libe3_e2sm_dapp_bytes_t *out)
e3_error_t libe3_e2sm_dapp_decode_ind_hdr(const uint8_t *buf, size_t len, libe3_e2sm_dapp_ind_hdr_t *out)
e3_error_t libe3_e2sm_dapp_encode_ind_hdr(const libe3_e2sm_dapp_ind_hdr_t *in, libe3_e2sm_dapp_bytes_t *out)
e3_error_t libe3_e2sm_dapp_decode_event_trigger(const uint8_t *buf, size_t len, libe3_e2sm_dapp_event_trigger_t *out)
void libe3_e2sm_dapp_free_ctrl_msg(libe3_e2sm_dapp_ctrl_msg_t *v)
e3_error_t libe3_e2sm_dapp_decode_ind_msg(const uint8_t *buf, size_t len, libe3_e2sm_dapp_ind_msg_t *out)
void libe3_e2sm_dapp_bytes_free(libe3_e2sm_dapp_bytes_t *b)
void libe3_e2sm_dapp_free_ctrl_hdr(libe3_e2sm_dapp_ctrl_hdr_t *v)
e3_error_t libe3_e2sm_dapp_decode_ran_function_definition(const uint8_t *buf, size_t len, libe3_e2sm_dapp_ran_function_definition_t *out)
void libe3_e2sm_dapp_free_action_definition(libe3_e2sm_dapp_action_definition_t *v)
void libe3_e2sm_dapp_free_ind_hdr(libe3_e2sm_dapp_ind_hdr_t *v)
e3_error_t libe3_e2sm_dapp_encode_ran_function_definition(const libe3_e2sm_dapp_ran_function_definition_t *in, libe3_e2sm_dapp_bytes_t *out)
E2SM-DAPP information elements and their APER codec (C API).
@ LIBE3_E2SM_DAPP_EVENT_TRIGGER_FORMAT_1
Format 1.
Definition e2sm_dapp_c.h:69
@ LIBE3_E2SM_DAPP_CTRL_OUTCOME_FORMAT_1
Format 1.
@ LIBE3_E2SM_DAPP_CTRL_HDR_FORMAT_1
Format 1.
@ LIBE3_E2SM_DAPP_IND_HDR_FORMAT_2
Format 2.
Definition e2sm_dapp_c.h:95
@ LIBE3_E2SM_DAPP_IND_HDR_FORMAT_1
Format 1.
Definition e2sm_dapp_c.h:94
@ LIBE3_E2SM_DAPP_CTRL_MSG_FORMAT_1
Format 1.
@ LIBE3_E2SM_DAPP_IND_MSG_FORMAT_1
Format 1.
@ LIBE3_E2SM_DAPP_IND_MSG_FORMAT_2
Format 2.
@ LIBE3_E2SM_DAPP_ACTION_DEFINITION_FORMAT_1
Format 1.
Definition e2sm_dapp_c.h:81
int e3_error_t
C error type alias.
@ E3_ENCODE_FAILED
@ E3_SM_ERROR_MEMORY
@ E3_DECODE_FAILED
@ E3_INTERNAL_ERROR
@ E3_INVALID_PARAM
@ E3_SUCCESS
int64_t ric_style_type
Report style the subscription selects (1 or 2); it selects the indication formats.
Definition e2sm_dapp_c.h:87
libe3_e2sm_dapp_action_definition_format_e format
Definition e2sm_dapp_c.h:86
uint8_t * data
The bytes, heap allocated.
Definition e2sm_dapp_c.h:42
size_t len
Number of bytes in data.
Definition e2sm_dapp_c.h:43
uint32_t ran_function_id
E3 RAN function id the control is for.
uint32_t dapp_id
The dApp that is the target of the control.
int64_t timestamp
When the xApp built the control, in nanoseconds on the realtime clock of its host.
bool has_sequence_id
true when sequence_id is present
bool has_timestamp
true when timestamp is present
int64_t sequence_id
Id of the procedure, echoed from the indication header; absent or 0 means the RAN cannot defer the ac...
libe3_e2sm_dapp_ctrl_hdr_format_e format
Selected format.
libe3_e2sm_dapp_ctrl_msg_format_e format
Selected format.
libe3_e2sm_dapp_bytes_t data
bool has_e3_control_outcome
true when e3_control_outcome is present
int64_t sequence_id
Procedure this outcome answers, copied from the control header.
libe3_e2sm_dapp_ctrl_outcome_format_e format
Selected format.
libe3_e2sm_dapp_bytes_t e3_control_outcome
bool has_timestamp
true when timestamp is present
bool has_sequence_id
true when sequence_id is present
int64_t timestamp
When the RAN built the outcome, in nanoseconds on its realtime clock.
libe3_e2sm_dapp_sub_list_t dapp_e3_subscriptions
dApp E3 subscription map
int64_t ctrl_style_type
Control style number (1).
libe3_e2sm_dapp_bytes_t name
libe3_e2sm_dapp_event_trigger_format_e format
Definition e2sm_dapp_c.h:74
uint32_t ran_function_id
E3 RAN function id of the report, not the E2 RAN function id.
uint32_t dapp_id
The dApp that sent the report.
int64_t sequence_id
Correlation id of the dApp for this report, copied from the E3 report.
uint8_t node_plmn_id[3]
PLMN id of the node, 3 octets.
bool has_timestamp
true when timestamp is present
uint32_t node_cu_du_id
CU or DU id inside the node.
uint8_t node_type
Type of the reporting node (0 to 255).
bool has_node_cu_du_id
true when node_cu_du_id is present
uint32_t node_nb_id
gNB id of the node
bool has_sequence_id
true when sequence_id is present
int64_t timestamp
When the RAN built the indication, in nanoseconds on its realtime clock.
uint32_t node_cu_du_id
CU or DU id inside the node.
uint8_t node_plmn_id[3]
PLMN id of the node, 3 octets.
bool has_node_cu_du_id
true when node_cu_du_id is present
uint8_t node_type
Type of the reporting node (0 to 255).
int64_t sequence_id
Correlation id; a subscription map has no procedure, so a RAN leaves it absent.
uint32_t node_nb_id
gNB id of the node
bool has_sequence_id
true when sequence_id is present
bool has_timestamp
true when timestamp is present
libe3_e2sm_dapp_ind_hdr_format1_t frmt_1
libe3_e2sm_dapp_ind_hdr_format2_t frmt_2
libe3_e2sm_dapp_ind_hdr_format_e format
Selected format.
libe3_e2sm_dapp_bytes_t data
libe3_e2sm_dapp_sub_list_t dapp_e3_subscriptions
Current dApp E3 subscription map; can be empty.
libe3_e2sm_dapp_ind_msg_format_e format
Selected format.
libe3_e2sm_dapp_ind_msg_format1_t frmt_1
Content when format is FORMAT_1.
libe3_e2sm_dapp_ind_msg_format2_t frmt_2
Content when format is FORMAT_2.
libe3_e2sm_dapp_report_style_t * report_styles
Array of n_report_styles report styles.
bool has_ctrl
true when the control section is present
libe3_e2sm_dapp_ctrl_style_t * ctrl_styles
Array of n_ctrl_styles control styles.
libe3_e2sm_dapp_ran_function_name_t name
Name of the RAN function.
bool has_report
true when the report section is present
int64_t instance
Instance number; not used, a sender shall not set it.
libe3_e2sm_dapp_bytes_t e2sm_oid
bool has_instance
true when instance is present
libe3_e2sm_dapp_bytes_t short_name
libe3_e2sm_dapp_bytes_t description
int64_t report_style_type
Report style number (1 or 2).
libe3_e2sm_dapp_sub_list_t dapp_e3_subscriptions
dApp E3 subscription map
libe3_e2sm_dapp_bytes_t name
uint32_t dapp_id
The dApp.
Definition e2sm_dapp_c.h:54
libe3_e2sm_dapp_sub_item_t * items
Array of n_items subscription items.
Definition e2sm_dapp_c.h:62