Initial commit of KPIMON xAPP for Bronze Release Enhancement.
[scp/ric-app/kpimon.git] / e2sm / wrapper.c
1 #include <errno.h>
2 #include "wrapper.h"
3
4 ssize_t e2sm_encode_ric_event_trigger_definition(void *buffer, size_t buf_size, size_t event_trigger_count, long *RT_periods) {
5         E2SM_KPM_EventTriggerDefinition_t *eventTriggerDef = (E2SM_KPM_EventTriggerDefinition_t *)calloc(1, sizeof(E2SM_KPM_EventTriggerDefinition_t));
6         if(!eventTriggerDef) {
7                 fprintf(stderr, "alloc EventTriggerDefinition failed\n");
8                 return -1;
9         }
10
11         E2SM_KPM_EventTriggerDefinition_Format1_t *innerDef = (E2SM_KPM_EventTriggerDefinition_Format1_t *)calloc(1, sizeof(E2SM_KPM_EventTriggerDefinition_Format1_t));
12         if(!innerDef) {
13                 fprintf(stderr, "alloc EventTriggerDefinition Format1 failed\n");
14                 ASN_STRUCT_FREE(asn_DEF_E2SM_KPM_EventTriggerDefinition, eventTriggerDef);
15                 return -1;
16         }
17
18         eventTriggerDef->present = E2SM_KPM_EventTriggerDefinition_PR_eventDefinition_Format1;
19         eventTriggerDef->choice.eventDefinition_Format1 = innerDef;
20
21         struct E2SM_KPM_EventTriggerDefinition_Format1__policyTest_List *policyTestList = (struct E2SM_KPM_EventTriggerDefinition_Format1__policyTest_List *)calloc(1, sizeof(struct E2SM_KPM_EventTriggerDefinition_Format1__policyTest_List));
22         innerDef->policyTest_List = policyTestList;
23         
24         int index = 0;
25         while(index < event_trigger_count) {
26                 Trigger_ConditionIE_Item_t *triggerCondition = (Trigger_ConditionIE_Item_t *)calloc(1, sizeof(Trigger_ConditionIE_Item_t));
27                 assert(triggerCondition != 0);
28                 triggerCondition->report_Period_IE = RT_periods[index];
29
30                 ASN_SEQUENCE_ADD(&policyTestList->list, triggerCondition);
31                 index++;
32         }
33
34         asn_enc_rval_t encode_result;
35     encode_result = aper_encode_to_buffer(&asn_DEF_E2SM_KPM_EventTriggerDefinition, NULL, eventTriggerDef, buffer, buf_size);
36     ASN_STRUCT_FREE(asn_DEF_E2SM_KPM_EventTriggerDefinition, eventTriggerDef);
37     if(encode_result.encoded == -1) {
38         fprintf(stderr, "Cannot encode %s: %s\n", encode_result.failed_type->name, strerror(errno));
39         return -1;
40     } else {
41             return encode_result.encoded;
42         }
43 }
44
45 ssize_t e2sm_encode_ric_action_definition(void *buffer, size_t buf_size, long ric_style_type) {
46         E2SM_KPM_ActionDefinition_t *actionDef = (E2SM_KPM_ActionDefinition_t *)calloc(1, sizeof(E2SM_KPM_ActionDefinition_t));
47         if(!actionDef) {
48                 fprintf(stderr, "alloc RIC ActionDefinition failed\n");
49                 return -1;
50         }
51
52         actionDef->ric_Style_Type = ric_style_type;
53
54         asn_enc_rval_t encode_result;
55     encode_result = aper_encode_to_buffer(&asn_DEF_E2SM_KPM_ActionDefinition, NULL, actionDef, buffer, buf_size);
56     ASN_STRUCT_FREE(asn_DEF_E2SM_KPM_ActionDefinition, actionDef);
57         if(encode_result.encoded == -1) {
58             fprintf(stderr, "Cannot encode %s: %s\n", encode_result.failed_type->name, strerror(errno));
59             return -1;
60         } else {
61         return encode_result.encoded;
62     }
63 }
64
65 E2SM_KPM_IndicationHeader_t* e2sm_decode_ric_indication_header(void *buffer, size_t buf_size) {
66         asn_dec_rval_t decode_result;
67     E2SM_KPM_IndicationHeader_t *indHdr = 0;
68     decode_result = aper_decode_complete(NULL, &asn_DEF_E2SM_KPM_IndicationHeader, (void **)&indHdr, buffer, buf_size);
69     if(decode_result.code == RC_OK) {
70         return indHdr;
71     }
72     else {
73         ASN_STRUCT_FREE(asn_DEF_E2SM_KPM_IndicationHeader, indHdr);
74         return NULL;
75     }
76 }
77
78 void e2sm_free_ric_indication_header(E2SM_KPM_IndicationHeader_t* indHdr) {
79         ASN_STRUCT_FREE(asn_DEF_E2SM_KPM_IndicationHeader, indHdr);
80 }
81
82 E2SM_KPM_IndicationMessage_t* e2sm_decode_ric_indication_message(void *buffer, size_t buf_size) {
83         asn_dec_rval_t decode_result;
84     E2SM_KPM_IndicationMessage_t *indMsg = 0;
85     decode_result = aper_decode_complete(NULL, &asn_DEF_E2SM_KPM_IndicationMessage, (void **)&indMsg, buffer, buf_size);
86     if(decode_result.code == RC_OK) {
87         return indMsg;
88     }
89     else {
90         ASN_STRUCT_FREE(asn_DEF_E2SM_KPM_IndicationMessage, indMsg);
91         return NULL;
92     }
93 }
94
95 void e2sm_free_ric_indication_message(E2SM_KPM_IndicationMessage_t* indMsg) {
96         ASN_STRUCT_FREE(asn_DEF_E2SM_KPM_IndicationMessage, indMsg);
97 }