X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=e2ap%2Fpkg%2Fconv%2Fplmn.go;fp=e2ap%2Fpkg%2Fconv%2Fplmn.go;h=61f2c3e09619e176389301343b21fa0b2adaa356;hb=ff8dccd02d76eebfccc0b509ce0b42a2c1760e12;hp=0000000000000000000000000000000000000000;hpb=f1d0eb6a82e11f14f60e3636d526299ced0173ea;p=ric-plt%2Fsubmgr.git diff --git a/e2ap/pkg/conv/plmn.go b/e2ap/pkg/conv/plmn.go new file mode 100644 index 0000000..61f2c3e --- /dev/null +++ b/e2ap/pkg/conv/plmn.go @@ -0,0 +1,95 @@ +/* +================================================================================== + Copyright (c) 2019 AT&T Intellectual Property. + Copyright (c) 2019 Nokia + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +================================================================================== +*/ + +package conv + +//----------------------------------------------------------------------------- +// +// MCC 3 digits MNC 2 digits +// BCD Coded format: 0xC2C1 0xfC3 0xN2N1 +// String format : C1C2C3N1N2 +// +// MCC 3 digits MNC 3 digits +// BCD Coded format: 0xC2C1 0xN3C3 0xN2N1 +// String format : C1C2C3N1N2N3 +// +//----------------------------------------------------------------------------- + +type PlmnIdentity struct { + Val [3]uint8 +} + +func (plmnid *PlmnIdentity) String() string { + bcd := NewBcd("0123456789?????f") + + str := bcd.Decode(plmnid.Val[:]) + + if str[3] == 'f' { + return string(str[0:3]) + string(str[4:]) + } + return string(str[0:3]) + string(str[4:]) + string(str[3]) +} + +func (plmnid *PlmnIdentity) MccString() string { + fullstr := plmnid.String() + return string(fullstr[0:3]) +} + +func (plmnid *PlmnIdentity) MncString() string { + fullstr := plmnid.String() + return string(fullstr[3:]) +} + +func (plmnid *PlmnIdentity) StringPut(str string) bool { + + var tmpStr string + switch { + + case len(str) == 5: + //C1 C2 C3 N1 N2 --> + //C2C1 0fC3 N2N1 + tmpStr = string(str[0:3]) + string("f") + string(str[3:]) + case len(str) == 6: + //C1 C2 C3 N1 N2 N3 --> + //C2C1 N3C3 N2N1 + tmpStr = string(str[0:3]) + string(str[5]) + string(str[3:5]) + default: + return false + } + + bcd := NewBcd("0123456789?????f") + buf := bcd.Encode(tmpStr) + + if buf == nil { + return false + } + + return plmnid.BcdPut(buf) +} + +func (plmnid *PlmnIdentity) BcdPut(val []uint8) bool { + + if len(val) != 3 { + return false + } + for i := 0; i < 3; i++ { + plmnid.Val[i] = val[i] + } + return true +}