blob: 4a6d6f1d7e30de9da21abe3bab8dc6f8c2fa2d48 [file] [log] [blame]
Matteo Scandolo732c0752020-01-28 07:24:13 -08001/*
2 * Copyright 2020-present Open Networking Foundation
3
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7
8 * http://www.apache.org/licenses/LICENSE-2.0
9
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package core
18
19type OnuGAttributes int
20
21const (
22 _ = iota
23 VendorID OnuGAttributes = 0x8000
24 Version OnuGAttributes = 0x4000
25 SerialNumber OnuGAttributes = 0x2000
26 TrafficManagementOptions OnuGAttributes = 0x1000
27 VpVcCrossConnectOptions OnuGAttributes = 0x0800
28 BatteryBackup OnuGAttributes = 0x0400
29 AdministrativeState OnuGAttributes = 0x0200
30 OperationalState OnuGAttributes = 0x0100
31 OntSurvivalTime OnuGAttributes = 0x0080
32 LogicalOnuID OnuGAttributes = 0x0040
33 LogicalPassword OnuGAttributes = 0x0020
34 CredentialsStatus OnuGAttributes = 0x0010
35 ExtendedTcLayerOptions OnuGAttributes = 0x0008
36)
37
Matteo Scandolo7b512202020-11-09 16:38:10 -080038type OnuGAttributeHandler func(*uint, []byte, OnuKey) ([]byte, error)
Matteo Scandolo732c0752020-01-28 07:24:13 -080039
40var OnuGAttributeHandlers = map[OnuGAttributes]OnuGAttributeHandler{
41 VendorID: GetVendorID,
42 Version: GetVersion,
43 SerialNumber: GetSerialNumber,
44 TrafficManagementOptions: GetTrafficManagementOptions,
45 VpVcCrossConnectOptions: GetVpVcCrossConnectOptions,
46 BatteryBackup: GetBatteryBackup,
47 AdministrativeState: GetAdministrativeState,
48 OperationalState: GetOperationalState,
49 OntSurvivalTime: GetOntSurvivalTime,
50 LogicalOnuID: GetLogicalOnuID,
51 LogicalPassword: GetLogicalPassword,
52 CredentialsStatus: GetCredentialsStatus,
53 ExtendedTcLayerOptions: GetExtendedTcLayerOptions,
54}
55
Matteo Scandolo7b512202020-11-09 16:38:10 -080056func GetOnuGAttributes(pos *uint, pkt []byte, content OmciContent, key OnuKey) ([]byte, error) {
Matteo Scandolo732c0752020-01-28 07:24:13 -080057 AttributesMask := getAttributeMask(content)
58
59 for index := uint(16); index >= 1; index-- {
60 Attribute := 1 << (index - 1)
61 reqAttribute := Attribute & AttributesMask
62
63 if reqAttribute != 0 {
Matteo Scandolo7b512202020-11-09 16:38:10 -080064 pkt, _ = OnuGAttributeHandlers[OnuGAttributes(reqAttribute)](pos, pkt, key)
Matteo Scandolo732c0752020-01-28 07:24:13 -080065 }
66 }
67
68 pkt[8] = 0x00 // Command Processed Successfully
69 pkt[9] = uint8(AttributesMask >> 8)
70 pkt[10] = uint8(AttributesMask & 0x00FF)
71
72 return pkt, nil
73
74}
75
Matteo Scandolo7b512202020-11-09 16:38:10 -080076func GetVendorID(pos *uint, pkt []byte, _ OnuKey) ([]byte, error) {
Matteo Scandolo732c0752020-01-28 07:24:13 -080077 // 4 bytes
78 vendorid := []byte("BBSM")
79 for _, ch := range vendorid {
80 pkt[*pos] = ch
81 *pos++
82 }
83 return pkt, nil
84}
85
Matteo Scandolo7b512202020-11-09 16:38:10 -080086func GetVersion(pos *uint, pkt []byte, _ OnuKey) ([]byte, error) {
Matteo Scandolo732c0752020-01-28 07:24:13 -080087 // 14 bytes
88 for i := 1; i <= 14; i++ {
89 b := byte(' ')
90 pkt[*pos] = b
91 *pos++
92 }
93 return pkt, nil
94}
95
Matteo Scandolo7b512202020-11-09 16:38:10 -080096func GetSerialNumber(pos *uint, pkt []byte, key OnuKey) ([]byte, error) {
Matteo Scandolo732c0752020-01-28 07:24:13 -080097 // 8 bytes
98 vendorid := []byte("BBSM")
Matteo Scandolo7b512202020-11-09 16:38:10 -080099 serialhex := []byte{0x00, byte(key.OltId % 256), byte(key.IntfId), byte(key.OnuId)}
Matteo Scandolo732c0752020-01-28 07:24:13 -0800100 serialnumber := append(vendorid, serialhex...)
101 for _, ch := range serialnumber {
102 pkt[*pos] = ch
103 *pos++
104 }
105 return pkt, nil
106}
107
Matteo Scandolo7b512202020-11-09 16:38:10 -0800108func GetTrafficManagementOptions(pos *uint, pkt []byte, _ OnuKey) ([]byte, error) {
Matteo Scandolo732c0752020-01-28 07:24:13 -0800109 // 1 byte
110 pkt[*pos] = 0x00
111 *pos++
112 return pkt, nil
113}
114
Matteo Scandolo7b512202020-11-09 16:38:10 -0800115func GetVpVcCrossConnectOptions(pos *uint, pkt []byte, _ OnuKey) ([]byte, error) {
Matteo Scandolo732c0752020-01-28 07:24:13 -0800116 // 1 byte
117 pkt[*pos] = 0x00
118 *pos++
119 return pkt, nil
120}
121
Matteo Scandolo7b512202020-11-09 16:38:10 -0800122func GetBatteryBackup(pos *uint, pkt []byte, _ OnuKey) ([]byte, error) {
Matteo Scandolo732c0752020-01-28 07:24:13 -0800123 // 1 byte
124 pkt[*pos] = 0x00
125 *pos++
126 return pkt, nil
127}
128
Matteo Scandolo7b512202020-11-09 16:38:10 -0800129func GetAdministrativeState(pos *uint, pkt []byte, _ OnuKey) ([]byte, error) {
Matteo Scandolo732c0752020-01-28 07:24:13 -0800130 // 1 byte
131 pkt[*pos] = 0x00
132 *pos++
133 return pkt, nil
134}
135
Matteo Scandolo7b512202020-11-09 16:38:10 -0800136func GetOperationalState(pos *uint, pkt []byte, _ OnuKey) ([]byte, error) {
Matteo Scandolo732c0752020-01-28 07:24:13 -0800137 // 1 byte
138 pkt[*pos] = 0x00
139 *pos++
140 return pkt, nil
141}
142
Matteo Scandolo7b512202020-11-09 16:38:10 -0800143func GetOntSurvivalTime(pos *uint, pkt []byte, _ OnuKey) ([]byte, error) {
Matteo Scandolo732c0752020-01-28 07:24:13 -0800144 // 1 byte
145 pkt[*pos] = 0x00
146 *pos++
147 return pkt, nil
148}
149
Matteo Scandolo7b512202020-11-09 16:38:10 -0800150func GetLogicalOnuID(pos *uint, pkt []byte, _ OnuKey) ([]byte, error) {
Matteo Scandolo732c0752020-01-28 07:24:13 -0800151 // 24 bytes
152 for i := 1; i <= 24; i++ {
153 b := byte(' ')
154 pkt[*pos] = b
155 *pos++
156 }
157 return pkt, nil
158}
159
Matteo Scandolo7b512202020-11-09 16:38:10 -0800160func GetLogicalPassword(pos *uint, pkt []byte, _ OnuKey) ([]byte, error) {
Matteo Scandolo732c0752020-01-28 07:24:13 -0800161 // 24 bytes
162 for i := 1; i <= 24; i++ {
163 b := byte(' ')
164 pkt[*pos] = b
165 *pos++
166 }
167 return pkt, nil
168}
169
Matteo Scandolo7b512202020-11-09 16:38:10 -0800170func GetCredentialsStatus(pos *uint, pkt []byte, _ OnuKey) ([]byte, error) {
Matteo Scandolo732c0752020-01-28 07:24:13 -0800171 // 1 byte
172 pkt[*pos] = 0x00
173 *pos++
174 return pkt, nil
175}
176
Matteo Scandolo7b512202020-11-09 16:38:10 -0800177func GetExtendedTcLayerOptions(pos *uint, pkt []byte, _ OnuKey) ([]byte, error) {
Matteo Scandolo732c0752020-01-28 07:24:13 -0800178 // 2 bytes
179 tcbits := []byte{0x00, 0x00}
180 for _, ch := range tcbits {
181 pkt[*pos] = ch
182 *pos++
183 }
184 return pkt, nil
185}