1 /*******************************************************************************
3 * Copyright (c) 2019 AT&T Intellectual Property.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 *******************************************************************************/
20 // #cgo CFLAGS: -I../3rdparty/asn1codec/inc/ -I../3rdparty/asn1codec/e2ap_engine/
21 // #cgo LDFLAGS: -L ../3rdparty/asn1codec/lib/ -L../3rdparty/asn1codec/e2ap_engine/ -le2ap_codec -lasncodec
22 // #include <asn1codec_utils.h>
23 // #include <resource_status_request_wrapper.h>
27 "github.com/pkg/errors"
33 MaxAsn1PackedBufferSize = 4096
34 MaxAsn1CodecMessageBufferSize = 4096
37 type Measurement_ID int64
39 type ResourceStatusRequestData struct {
40 CellID string // PLMNIdentifier:eUTRANCellIdentifier
41 MeasurementID Measurement_ID
42 MeasurementID2 Measurement_ID
43 PartialSuccessAllowed bool
45 TnlLoadIndPeriodic bool
46 HwLoadIndPeriodic bool
47 AbsStatusPeriodic bool
48 RsrpMeasurementPeriodic bool
50 PeriodicityMS enums.ReportingPeriodicity
51 PeriodicityRsrpMeasurementMS enums.ReportingPeriodicityRSRPMR
52 PeriodicityCsiMS enums.ReportingPeriodicityCSIR
55 func BuildPackedResourceStatusRequest(registrationRequest enums.Registration_Request, request *ResourceStatusRequestData, maxAsn1PackedBufferSize int, maxAsn1CodecMessageBufferSize int, withDebug bool) ([]byte, string, error) {
57 packedBuf := make([]byte, maxAsn1PackedBufferSize)
58 errBuf := make([]C.char, maxAsn1CodecMessageBufferSize)
59 packedBufSize := C.ulong(len(packedBuf))
62 var pLMNIdentifier, eUTRANCellIdentifier string
64 if _, err := fmt.Sscanf(request.CellID, "%x:%x", &pLMNIdentifier, &eUTRANCellIdentifier); err != nil {
65 return nil, "", fmt.Errorf("BuildPackedResourceStatusRequest() - unexpected CellID value [%s] (want: \"<PLMNIdentifier>:<eUTRANCellIdentifier>\"), err: %s", request.CellID, err)
70 When specifying information elements which are to be represented by bit strings, if not otherwise specifically stated in the semantics description of the concerned IE or elsewhere, the following principle applies with regards to the ordering of bits:
71 - The first bit (leftmost bit) contains the most significant bit (MSB);
72 - The last bit (rightmost bit) contains the least significant bit (LSB);
73 - When importing bit strings from other specifications, the first bit of the bit string contains the first bit of the concerned information.
76 /*reportCharacteristics:
77 1) First Bit = PRB Periodic.
78 2) Second Bit = TNL load Ind Periodic.
79 3) Third Bit = HW Load Ind Periodic.
80 4) Fourth Bit = Composite Available Capacity Periodic, this bit should be set to 1 if at least one of the First, Second or Third bits is set to 1.
81 5) Fifth Bit = ABPartialSuccessIndicator_tS Status Periodic.
82 6) Sixth Bit = RSRP Measurement Report Periodic.
83 7) Seventh Bit = CSI Report Periodic.
85 var prbPeriodic, tnlLoadIndPeriodic, hwLoadIndPeriodic, compositeAvailablCapacityPeriodic, absStatusPeriodic, rsrpMeasurementPeriodic, csiPeriodic int
86 var partialSuccessAllowed C.PartialSuccessIndicator_t
88 if request.PartialSuccessAllowed {
89 partialSuccessAllowed = C.PartialSuccessIndicator_partial_success_allowed
91 partialSuccessAllowed = C.PartialSuccessIndicator_t(-1)
93 if request.PrbPeriodic {
96 if request.TnlLoadIndPeriodic {
97 tnlLoadIndPeriodic = 1
99 if request.HwLoadIndPeriodic {
100 hwLoadIndPeriodic = 1
102 if request.PrbPeriodic || request.TnlLoadIndPeriodic || request.HwLoadIndPeriodic {
103 compositeAvailablCapacityPeriodic = 1
105 if request.AbsStatusPeriodic {
106 absStatusPeriodic = 1
108 if request.RsrpMeasurementPeriodic {
109 rsrpMeasurementPeriodic = 1
111 if request.CsiPeriodic {
114 reportCharacteristics := uint32(prbPeriodic<<7 | tnlLoadIndPeriodic<<6 | hwLoadIndPeriodic<<5 | compositeAvailablCapacityPeriodic<<4 | absStatusPeriodic<<3 | rsrpMeasurementPeriodic<<2 | csiPeriodic<<1)
116 if !C.build_pack_resource_status_request(
117 (*C.uchar)(unsafe.Pointer(&[]byte(pLMNIdentifier)[0])),
118 (*C.uchar)(unsafe.Pointer(&[]byte(eUTRANCellIdentifier)[0])),
119 C.Measurement_ID_t(request.MeasurementID),
120 C.Measurement_ID_t(request.MeasurementID2),
121 C.Registration_Request_t(registrationRequest),
122 C.uint(reportCharacteristics),
123 C.ReportingPeriodicity_t(request.PeriodicityMS-1),
124 partialSuccessAllowed,
125 C.ReportingPeriodicityRSRPMR_t(request.PeriodicityRsrpMeasurementMS-1),
126 C.ReportingPeriodicityCSIR_t(request.PeriodicityCsiMS-1),
128 (*C.uchar)(unsafe.Pointer(&packedBuf[0])),
129 C.ulong(len(errBuf)),
131 return nil, "", errors.New(fmt.Sprintf("BuildPackedResourceStatusRequest - packing error: %s", C.GoString(&errBuf[0])))
136 defer C.delete_pdu(pdu)
137 if C.per_unpack_pdu(pdu, packedBufSize, (*C.uchar)(unsafe.Pointer(&packedBuf[0])), C.size_t(len(errBuf)), &errBuf[0]) {
138 C.asn1_pdu_printer(pdu, C.size_t(len(errBuf)), &errBuf[0])
139 pduAsString = C.GoString(&errBuf[0])
143 return packedBuf[:packedBufSize], pduAsString, nil