2 ==================================================================================
3 Copyright (c) 2019 AT&T Intellectual Property.
4 Copyright (c) 2019 Nokia
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17 ==================================================================================
26 //-----------------------------------------------------------------------------
28 //-----------------------------------------------------------------------------
29 type PlmnIdentityIf interface {
33 EncodeTo(writer io.Writer) (int, error)
34 DecodeFrom(reader io.Reader) (int, error)
37 //-----------------------------------------------------------------------------
39 //-----------------------------------------------------------------------------
41 type PlmnIdentity struct {
46 func (plmnid *PlmnIdentity) String() string {
47 return plmnid.MccString() + plmnid.MncString()
50 func (plmnid *PlmnIdentity) MccString() string {
54 func (plmnid *PlmnIdentity) MncString() string {
58 func (plmnid *PlmnIdentity) Set(str string) {
63 //-----------------------------------------------------------------------------
65 // MCC 3 digits MNC 2 digits
66 // String format : C1C2C3N1N2
67 // Pre encode format : C1C2C3FN1N2
68 // TBCD Coded format : 0xC2C1 0xfC3 0xN2N1
69 // Post decode format : C1C2C3FN1N2
70 // String format : C1C2C3N1N2
72 // MCC 3 digits MNC 3 digits
73 // String format : C1C2C3N1N2N3
74 // Pre encode format : C1C2C3N3N1N2
75 // TBCD Coded format : 0xC2C1 0xN3C3 0xN2N1
76 // Post decode format : C1C2C3N3N1N2
77 // String format : C1C2C3N1N2N3
79 //-----------------------------------------------------------------------------
81 type PlmnIdentityTbcd struct {
85 func (plmnid *PlmnIdentityTbcd) EncodeTo(writer io.Writer) (int, error) {
89 case len(plmnid.Mnc) == 2:
90 tmpStr = plmnid.Mcc + string("f") + plmnid.Mnc
91 case len(plmnid.Mnc) == 3:
92 tmpStr = plmnid.Mcc + string(plmnid.Mnc[2]) + string(plmnid.Mnc[0:2])
97 buf := TBCD.Encode(tmpStr)
98 return writer.Write(buf)
101 func (plmnid *PlmnIdentityTbcd) DecodeFrom(reader io.Reader) (int, error) {
102 tmpBytes := make([]byte, 3)
103 n, err := reader.Read(tmpBytes)
107 str := TBCD.Decode(tmpBytes)
110 plmnid.Mcc = string(str[0:3])
111 plmnid.Mnc = string(str[4:])
113 plmnid.Mcc = string(str[0:3])
114 plmnid.Mnc = string(str[4:]) + string(str[3])
119 //-----------------------------------------------------------------------------
121 // MCC 3 digits MNC 2 digits
122 // String format : C1C2C3N1N2
123 // Pre encode format : C1C2C3FN1N2
124 // BCD Coded format : 0xC2C1 0xC3f 0xN1N2
125 // Post decode format : C1C2C3FN1N2
126 // String format : C1C2C3N1N2
128 // MCC 3 digits MNC 3 digits
129 // String format : C1C2C3N1N2N3
130 // Pre encode format : C1C2C3N1N2N3
131 // BCD Coded format : 0xC2C1 0xC3N1 0xN2N3
132 // Post decode format : C1C2C3N1N2N3
133 // String format : C1C2C3N1N2N3
135 //-----------------------------------------------------------------------------
137 type PlmnIdentityBcd struct {
141 func (plmnid *PlmnIdentityBcd) EncodeTo(writer io.Writer) (int, error) {
145 case len(plmnid.Mnc) == 2:
146 tmpStr = plmnid.Mcc + string("f") + plmnid.Mnc
147 case len(plmnid.Mnc) == 3:
148 tmpStr = plmnid.Mcc + plmnid.Mnc
153 buf := BCD.Encode(tmpStr)
154 return writer.Write(buf)
157 func (plmnid *PlmnIdentityBcd) DecodeFrom(reader io.Reader) (int, error) {
158 tmpBytes := make([]byte, 3)
159 n, err := reader.Read(tmpBytes)
163 str := BCD.Decode(tmpBytes)
166 plmnid.Mcc = string(str[0:3])
167 plmnid.Mnc = string(str[4:])
169 plmnid.Mcc = string(str[0:3])
170 plmnid.Mnc = string(str[3:])