rajalakshmisv | 21b61dd | 2021-12-07 04:53:03 +0000 | [diff] [blame^] | 1 | #include <errno.h> |
| 2 | #include "wrapper.h" |
| 3 | #include "OCTET_STRING.h" |
| 4 | |
| 5 | |
| 6 | ssize_t e2sm_encode_ric_control_header(void *buffer, size_t buf_size, void *ueIDbuf, size_t ueIDbuf_size, |
| 7 | long ricControlStyleType, long ricControlActionID) |
| 8 | { |
| 9 | E2SM_RC_ControlHeader_t *controlHeaderIE = (E2SM_RC_ControlHeader_t *)calloc(1, sizeof(E2SM_RC_ControlHeader_t)); |
| 10 | if(!controlHeaderIE) |
| 11 | { |
| 12 | fprintf(stderr, "alloc E2SM_RC_ControlHeader failed\n"); |
| 13 | return -1; |
| 14 | } |
| 15 | |
| 16 | controlHeaderIE->present = E2SM_RC_ControlHeader_PR_controlHeader_Format1; |
| 17 | //E2SM_RC_ControlHeader_Format1_t *controlHeader_Fmt1 = controlHeaderIE->choice.controlHeader_Format1; |
| 18 | E2SM_RC_ControlHeader_Format1_t *controlHeader_Fmt1 = (E2SM_RC_ControlHeader_Format1_t *)calloc(1, sizeof(E2SM_RC_ControlHeader_Format1_t)); |
| 19 | if(!controlHeader_Fmt1) |
| 20 | { |
| 21 | fprintf(stderr, "alloc E2SM_RC_ControlHeader failed\n"); |
| 22 | return -1; |
| 23 | } |
| 24 | |
| 25 | controlHeader_Fmt1->ueId.buf = (uint8_t*)calloc(1, ueIDbuf_size); |
| 26 | memcpy(controlHeader_Fmt1->ueId.buf, ueIDbuf, ueIDbuf_size); //Check how to get ueIDbuf from string |
| 27 | controlHeader_Fmt1->ueId.size = ueIDbuf_size; |
| 28 | |
| 29 | controlHeader_Fmt1->ric_ControlStyle_Type = ricControlStyleType; |
| 30 | controlHeader_Fmt1->ric_ControlAction_ID = ricControlActionID; |
| 31 | |
| 32 | controlHeaderIE->choice.controlHeader_Format1 = controlHeader_Fmt1; |
| 33 | |
| 34 | fprintf(stderr, "showing xer of asn_DEF_E2SM_RC_ControlHeader data\n"); |
| 35 | xer_fprint(stderr, &asn_DEF_E2SM_RC_ControlHeader, controlHeaderIE); |
| 36 | fprintf(stderr, "\n"); |
| 37 | fprintf(stderr, "After xer of asn_DEF_E2SM_RC_ControlHeader data\n"); |
| 38 | |
| 39 | asn_enc_rval_t encode_result; |
| 40 | encode_result = aper_encode_to_buffer(&asn_DEF_E2SM_RC_ControlHeader, NULL, controlHeaderIE, buffer, buf_size); |
| 41 | ASN_STRUCT_FREE(asn_DEF_E2SM_RC_ControlHeader, controlHeaderIE); |
| 42 | if(encode_result.encoded == -1) |
| 43 | { |
| 44 | fprintf(stderr, "Cannot encode %s: %s\n", encode_result.failed_type->name, strerror(errno)); |
| 45 | return -1; |
| 46 | } |
| 47 | else |
| 48 | { |
| 49 | return encode_result.encoded; |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | |
| 54 | |
| 55 | ssize_t e2sm_encode_ric_control_message(void *buffer, size_t buf_size, long targetPrimaryCell, |
| 56 | long targetCell, long nrOrEUtraCell, long nrCGIOrECGI, void* ranParameterValue, size_t ranParameterValue_size) |
| 57 | { |
| 58 | E2SM_RC_ControlMessage_t *e2smRcControlMsg = (E2SM_RC_ControlMessage_t*)calloc(1, sizeof(E2SM_RC_ControlMessage_t)); |
| 59 | if(!e2smRcControlMsg) { |
| 60 | fprintf(stderr, "alloc E2SM_RC_ControlMessage_t failed\n"); |
| 61 | return -1; |
| 62 | } |
| 63 | |
| 64 | e2smRcControlMsg->present = E2SM_RC_ControlMessage_PR_controlMessage_Format1; |
| 65 | |
| 66 | // E2SM_RC_ControlMessage_Format1_t *e2smRcControlFormat1 = e2smRcControlMsg->choice.controlMessage_Format1; |
| 67 | |
| 68 | E2SM_RC_ControlMessage_Format1_t *e2smRcControlFormat1 = (E2SM_RC_ControlMessage_Format1_t*)calloc(1, sizeof(E2SM_RC_ControlMessage_Format1_t)); |
| 69 | if(!e2smRcControlMsg) { |
| 70 | fprintf(stderr, "alloc E2SM_RC_ControlMessage_Format1_t failed\n"); |
| 71 | return -1; |
| 72 | } |
| 73 | |
| 74 | |
| 75 | e2smRcControlFormat1->ranParameters_List = |
| 76 | (struct E2SM_RC_ControlMessage_Format1__ranParameters_List*)calloc(1, sizeof(struct E2SM_RC_ControlMessage_Format1__ranParameters_List)); |
| 77 | if(!e2smRcControlFormat1->ranParameters_List) |
| 78 | { |
| 79 | fprintf(stderr, "alloc e2smRcControlFormat1->ranParameters_List failed\n"); |
| 80 | ASN_STRUCT_FREE(asn_DEF_E2SM_RC_ControlMessage, e2smRcControlMsg); |
| 81 | return -1; |
| 82 | } |
| 83 | |
| 84 | // Start Target Primary Cell |
| 85 | RANParameter_Item_t *ranParameterItem1 = (RANParameter_Item_t*)calloc(1,sizeof(RANParameter_Item_t)); |
| 86 | if(!ranParameterItem1) { |
| 87 | fprintf(stderr, "alloc RANParameter_Item_t1 failed\n"); |
| 88 | ASN_STRUCT_FREE(asn_DEF_E2SM_RC_ControlMessage, e2smRcControlMsg); |
| 89 | return -1; |
| 90 | } |
| 91 | |
| 92 | |
| 93 | ranParameterItem1->ranParameterItem_ID = targetPrimaryCell; // Target Primary Cell ID value = 1 |
| 94 | RANParameter_ValueType_t *ranParameterValueType1 = (RANParameter_ValueType_t*)calloc(1, sizeof(RANParameter_ValueType_t)); |
| 95 | if(!ranParameterValueType1) |
| 96 | { |
| 97 | fprintf(stderr, "alloc RANParameter_ValueType_t1 failed\n"); |
| 98 | ASN_STRUCT_FREE(asn_DEF_E2SM_RC_ControlMessage, e2smRcControlMsg); |
| 99 | return -1; |
| 100 | } |
| 101 | |
| 102 | ranParameterValueType1->present = RANParameter_ValueType_PR_ranParameter_Structure; |
| 103 | RANParameter_STRUCTURE_t *ranParameterStructure1 = (RANParameter_STRUCTURE_t*)calloc(1, sizeof(RANParameter_STRUCTURE_t)); |
| 104 | if(!ranParameterStructure1) |
| 105 | { |
| 106 | fprintf(stderr, "alloc RANParameter_STRUCTURE_t1 failed\n"); |
| 107 | ASN_STRUCT_FREE(asn_DEF_E2SM_RC_ControlMessage, e2smRcControlMsg); |
| 108 | return -1; |
| 109 | } |
| 110 | |
| 111 | |
| 112 | // Start Target Cell |
| 113 | RANParameter_Item_t *ranParameterItem2 = (RANParameter_Item_t*)calloc(1,sizeof(RANParameter_Item_t)); |
| 114 | if(!ranParameterItem2) |
| 115 | { |
| 116 | |
| 117 | ASN_STRUCT_FREE(asn_DEF_E2SM_RC_ControlMessage, e2smRcControlMsg); |
| 118 | fprintf(stderr, "alloc RANParameter_Item_t2 failed\n"); |
| 119 | return -1; |
| 120 | } |
| 121 | |
| 122 | ranParameterItem2->ranParameterItem_ID = targetCell; // Target Cell ID value = 2 |
| 123 | RANParameter_ValueType_t *ranParameterValueType2 = (RANParameter_ValueType_t*)calloc(1, sizeof(RANParameter_ValueType_t)); |
| 124 | if(!ranParameterValueType2) |
| 125 | { |
| 126 | ASN_STRUCT_FREE(asn_DEF_E2SM_RC_ControlMessage, e2smRcControlMsg); |
| 127 | fprintf(stderr, "alloc RANParameter_STRUCTURE_t2 failed\n"); |
| 128 | return -1; |
| 129 | } |
| 130 | |
| 131 | |
| 132 | ranParameterValueType2->present = RANParameter_ValueType_PR_ranParameter_Structure; |
| 133 | RANParameter_STRUCTURE_t *ranParameterStructure2 = (RANParameter_STRUCTURE_t*)calloc(1, sizeof(struct RANParameter_STRUCTURE)); |
| 134 | if(!ranParameterStructure2) |
| 135 | { |
| 136 | ASN_STRUCT_FREE(asn_DEF_E2SM_RC_ControlMessage, e2smRcControlMsg); |
| 137 | fprintf(stderr, "alloc RANParameter_STRUCTURE_t2 failed\n"); |
| 138 | return -1; |
| 139 | } |
| 140 | |
| 141 | |
| 142 | // Start NR Cell (or E-UTRA Cell) |
| 143 | RANParameter_Item_t *ranParameterItem3 = (RANParameter_Item_t*)calloc(1,sizeof(RANParameter_Item_t)); |
| 144 | if(!ranParameterItem3) |
| 145 | { |
| 146 | ASN_STRUCT_FREE(asn_DEF_E2SM_RC_ControlMessage, e2smRcControlMsg); |
| 147 | fprintf(stderr, "alloc RANParameter_Item_t3 failed\n"); |
| 148 | return -1; |
| 149 | } |
| 150 | |
| 151 | ranParameterItem3->ranParameterItem_ID = nrOrEUtraCell; // NR Cell ID (or E-UTRA Cell ID) value = |
| 152 | RANParameter_ValueType_t *ranParameterValueType3 = (RANParameter_ValueType_t*)calloc(1, sizeof(RANParameter_ValueType_t)); |
| 153 | if(!ranParameterValueType3) |
| 154 | { |
| 155 | ASN_STRUCT_FREE(asn_DEF_E2SM_RC_ControlMessage, e2smRcControlMsg); |
| 156 | fprintf(stderr, "alloc RANParameter_Item_t3 failed\n"); |
| 157 | return -1; |
| 158 | } |
| 159 | |
| 160 | ranParameterValueType3->present = RANParameter_ValueType_PR_ranParameter_Structure; |
| 161 | RANParameter_STRUCTURE_t *ranParameterStructure3 = (struct RANParameter_STRUCTURE*)calloc(1, sizeof(struct RANParameter_STRUCTURE)); |
| 162 | if(!ranParameterStructure3) |
| 163 | { |
| 164 | ASN_STRUCT_FREE(asn_DEF_E2SM_RC_ControlMessage, e2smRcControlMsg); |
| 165 | fprintf(stderr, "alloc RANParameter_Item_t3 failed\n"); |
| 166 | return -1; |
| 167 | } |
| 168 | |
| 169 | // Start NR CGI (or ECGI) |
| 170 | RANParameter_Item_t *ranParameterItem4 = (RANParameter_Item_t*)calloc(1, sizeof(RANParameter_Item_t)); |
| 171 | if(!ranParameterItem4) |
| 172 | { |
| 173 | ASN_STRUCT_FREE(asn_DEF_E2SM_RC_ControlMessage, e2smRcControlMsg); |
| 174 | fprintf(stderr, "alloc RANParameter_Item_t4 failed\n"); |
| 175 | return -1; |
| 176 | } |
| 177 | ranParameterItem4->ranParameterItem_ID = nrCGIOrECGI; // NR CGI ID (or ECGI ID) value = |
| 178 | RANParameter_ValueType_t *ranParameterValueType4 = (RANParameter_ValueType_t*)calloc(1, sizeof(RANParameter_ValueType_t)); |
| 179 | if(!ranParameterValueType4) |
| 180 | { |
| 181 | ASN_STRUCT_FREE(asn_DEF_E2SM_RC_ControlMessage, e2smRcControlMsg); |
| 182 | fprintf(stderr, "alloc RANParameter_Item_t4 failed\n"); |
| 183 | return -1; |
| 184 | } |
| 185 | ranParameterValueType4->present = RANParameter_ValueType_PR_ranParameter_Element; |
| 186 | ranParameterValueType4->choice.ranParameter_Element = (RANParameter_ELEMENT_t*)calloc(1, sizeof(RANParameter_ELEMENT_t)); |
| 187 | if(!ranParameterValueType4->choice.ranParameter_Element) |
| 188 | { |
| 189 | ASN_STRUCT_FREE(asn_DEF_E2SM_RC_ControlMessage, e2smRcControlMsg); |
| 190 | fprintf(stderr, "alloc RANParameter_Item_t4 failed\n"); |
| 191 | return -1; |
| 192 | } |
| 193 | ranParameterValueType4->choice.ranParameter_Element->keyFlag = 0; |
| 194 | ranParameterValueType4->choice.ranParameter_Element->ranParameter_Value.present = RANParameter_Value_PR_valueOctS; |
| 195 | |
| 196 | ranParameterValueType4->choice.ranParameter_Element->ranParameter_Value.choice.valueOctS.buf = |
| 197 | (uint8_t*)calloc(1, ranParameterValue_size); |
| 198 | if(!ranParameterValueType4->choice.ranParameter_Element->ranParameter_Value.choice.valueOctS.buf) |
| 199 | { |
| 200 | ASN_STRUCT_FREE(asn_DEF_E2SM_RC_ControlMessage, e2smRcControlMsg); |
| 201 | fprintf(stderr, "alloc RANParameter Value failed\n"); |
| 202 | return -1; |
| 203 | } |
| 204 | memcpy(ranParameterValueType4->choice.ranParameter_Element->ranParameter_Value.choice.valueOctS.buf, ranParameterValue, ranParameterValue_size); |
| 205 | ranParameterValueType4->choice.ranParameter_Element->ranParameter_Value.choice.valueOctS.size = ranParameterValue_size; |
| 206 | ranParameterItem4->ranParameterItem_valueType = ranParameterValueType4; // NR CGI (or ECGI) |
| 207 | |
| 208 | ASN_SEQUENCE_ADD(&ranParameterStructure3->sequence_of_ranParameters.list, ranParameterItem4); // NR CGI (or ECGI) |
| 209 | ranParameterValueType3->choice.ranParameter_Structure = ranParameterStructure3; // NR Cell (or E-UTRA Cell) |
| 210 | ranParameterItem3->ranParameterItem_valueType = ranParameterValueType3; |
| 211 | |
| 212 | ASN_SEQUENCE_ADD(&ranParameterStructure2->sequence_of_ranParameters.list, ranParameterItem3); // NR Cell (or E-UTRA Cell) |
| 213 | ranParameterValueType2->choice.ranParameter_Structure = ranParameterStructure2; // Target Cell |
| 214 | ranParameterItem2->ranParameterItem_valueType = ranParameterValueType2; |
| 215 | |
| 216 | ASN_SEQUENCE_ADD(&ranParameterStructure1->sequence_of_ranParameters.list, ranParameterItem2); // Target Cell |
| 217 | ranParameterValueType1->choice.ranParameter_Structure = ranParameterStructure1; // Target Primary Cell |
| 218 | ranParameterItem1->ranParameterItem_valueType = ranParameterValueType1; |
| 219 | |
| 220 | ASN_SEQUENCE_ADD(&e2smRcControlFormat1->ranParameters_List->list, ranParameterItem1); // Target Primary Cell |
| 221 | e2smRcControlMsg->choice.controlMessage_Format1 = e2smRcControlFormat1; |
| 222 | |
| 223 | |
| 224 | fprintf(stderr, "showing xer of asn_DEF_E2SM_RC_ControlMessage data\n"); |
| 225 | xer_fprint(stderr, &asn_DEF_E2SM_RC_ControlMessage, e2smRcControlMsg); |
| 226 | fprintf(stderr, "\n"); |
| 227 | fprintf(stderr, "After xer of asn_DEF_E2SM_RC_ControlMessage data\n"); |
| 228 | |
| 229 | asn_enc_rval_t encode_result; |
| 230 | encode_result = aper_encode_to_buffer(&asn_DEF_E2SM_RC_ControlMessage, NULL, e2smRcControlMsg, buffer, buf_size); |
| 231 | ASN_STRUCT_FREE(asn_DEF_E2SM_RC_ControlMessage, e2smRcControlMsg); |
| 232 | if(encode_result.encoded == -1) |
| 233 | { |
| 234 | fprintf(stderr, "Cannot encode %s: %s\n", encode_result.failed_type->name, strerror(errno)); |
| 235 | return -1; |
| 236 | } |
| 237 | else |
| 238 | { |
| 239 | return encode_result.encoded; |
| 240 | } |
| 241 | } |
| 242 | |