Matteo Scandolo | 732c075 | 2020-01-28 07:24:13 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package core |
| 18 | |
| 19 | type OnuGAttributes int |
| 20 | |
| 21 | const ( |
| 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 Scandolo | 7b51220 | 2020-11-09 16:38:10 -0800 | [diff] [blame] | 38 | type OnuGAttributeHandler func(*uint, []byte, OnuKey) ([]byte, error) |
Matteo Scandolo | 732c075 | 2020-01-28 07:24:13 -0800 | [diff] [blame] | 39 | |
| 40 | var 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 Scandolo | 7b51220 | 2020-11-09 16:38:10 -0800 | [diff] [blame] | 56 | func GetOnuGAttributes(pos *uint, pkt []byte, content OmciContent, key OnuKey) ([]byte, error) { |
Matteo Scandolo | 732c075 | 2020-01-28 07:24:13 -0800 | [diff] [blame] | 57 | 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 Scandolo | 7b51220 | 2020-11-09 16:38:10 -0800 | [diff] [blame] | 64 | pkt, _ = OnuGAttributeHandlers[OnuGAttributes(reqAttribute)](pos, pkt, key) |
Matteo Scandolo | 732c075 | 2020-01-28 07:24:13 -0800 | [diff] [blame] | 65 | } |
| 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 Scandolo | 7b51220 | 2020-11-09 16:38:10 -0800 | [diff] [blame] | 76 | func GetVendorID(pos *uint, pkt []byte, _ OnuKey) ([]byte, error) { |
Matteo Scandolo | 732c075 | 2020-01-28 07:24:13 -0800 | [diff] [blame] | 77 | // 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 Scandolo | 7b51220 | 2020-11-09 16:38:10 -0800 | [diff] [blame] | 86 | func GetVersion(pos *uint, pkt []byte, _ OnuKey) ([]byte, error) { |
Matteo Scandolo | 732c075 | 2020-01-28 07:24:13 -0800 | [diff] [blame] | 87 | // 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 Scandolo | 7b51220 | 2020-11-09 16:38:10 -0800 | [diff] [blame] | 96 | func GetSerialNumber(pos *uint, pkt []byte, key OnuKey) ([]byte, error) { |
Matteo Scandolo | 732c075 | 2020-01-28 07:24:13 -0800 | [diff] [blame] | 97 | // 8 bytes |
| 98 | vendorid := []byte("BBSM") |
Matteo Scandolo | 7b51220 | 2020-11-09 16:38:10 -0800 | [diff] [blame] | 99 | serialhex := []byte{0x00, byte(key.OltId % 256), byte(key.IntfId), byte(key.OnuId)} |
Matteo Scandolo | 732c075 | 2020-01-28 07:24:13 -0800 | [diff] [blame] | 100 | serialnumber := append(vendorid, serialhex...) |
| 101 | for _, ch := range serialnumber { |
| 102 | pkt[*pos] = ch |
| 103 | *pos++ |
| 104 | } |
| 105 | return pkt, nil |
| 106 | } |
| 107 | |
Matteo Scandolo | 7b51220 | 2020-11-09 16:38:10 -0800 | [diff] [blame] | 108 | func GetTrafficManagementOptions(pos *uint, pkt []byte, _ OnuKey) ([]byte, error) { |
Matteo Scandolo | 732c075 | 2020-01-28 07:24:13 -0800 | [diff] [blame] | 109 | // 1 byte |
| 110 | pkt[*pos] = 0x00 |
| 111 | *pos++ |
| 112 | return pkt, nil |
| 113 | } |
| 114 | |
Matteo Scandolo | 7b51220 | 2020-11-09 16:38:10 -0800 | [diff] [blame] | 115 | func GetVpVcCrossConnectOptions(pos *uint, pkt []byte, _ OnuKey) ([]byte, error) { |
Matteo Scandolo | 732c075 | 2020-01-28 07:24:13 -0800 | [diff] [blame] | 116 | // 1 byte |
| 117 | pkt[*pos] = 0x00 |
| 118 | *pos++ |
| 119 | return pkt, nil |
| 120 | } |
| 121 | |
Matteo Scandolo | 7b51220 | 2020-11-09 16:38:10 -0800 | [diff] [blame] | 122 | func GetBatteryBackup(pos *uint, pkt []byte, _ OnuKey) ([]byte, error) { |
Matteo Scandolo | 732c075 | 2020-01-28 07:24:13 -0800 | [diff] [blame] | 123 | // 1 byte |
| 124 | pkt[*pos] = 0x00 |
| 125 | *pos++ |
| 126 | return pkt, nil |
| 127 | } |
| 128 | |
Matteo Scandolo | 7b51220 | 2020-11-09 16:38:10 -0800 | [diff] [blame] | 129 | func GetAdministrativeState(pos *uint, pkt []byte, _ OnuKey) ([]byte, error) { |
Matteo Scandolo | 732c075 | 2020-01-28 07:24:13 -0800 | [diff] [blame] | 130 | // 1 byte |
| 131 | pkt[*pos] = 0x00 |
| 132 | *pos++ |
| 133 | return pkt, nil |
| 134 | } |
| 135 | |
Matteo Scandolo | 7b51220 | 2020-11-09 16:38:10 -0800 | [diff] [blame] | 136 | func GetOperationalState(pos *uint, pkt []byte, _ OnuKey) ([]byte, error) { |
Matteo Scandolo | 732c075 | 2020-01-28 07:24:13 -0800 | [diff] [blame] | 137 | // 1 byte |
| 138 | pkt[*pos] = 0x00 |
| 139 | *pos++ |
| 140 | return pkt, nil |
| 141 | } |
| 142 | |
Matteo Scandolo | 7b51220 | 2020-11-09 16:38:10 -0800 | [diff] [blame] | 143 | func GetOntSurvivalTime(pos *uint, pkt []byte, _ OnuKey) ([]byte, error) { |
Matteo Scandolo | 732c075 | 2020-01-28 07:24:13 -0800 | [diff] [blame] | 144 | // 1 byte |
| 145 | pkt[*pos] = 0x00 |
| 146 | *pos++ |
| 147 | return pkt, nil |
| 148 | } |
| 149 | |
Matteo Scandolo | 7b51220 | 2020-11-09 16:38:10 -0800 | [diff] [blame] | 150 | func GetLogicalOnuID(pos *uint, pkt []byte, _ OnuKey) ([]byte, error) { |
Matteo Scandolo | 732c075 | 2020-01-28 07:24:13 -0800 | [diff] [blame] | 151 | // 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 Scandolo | 7b51220 | 2020-11-09 16:38:10 -0800 | [diff] [blame] | 160 | func GetLogicalPassword(pos *uint, pkt []byte, _ OnuKey) ([]byte, error) { |
Matteo Scandolo | 732c075 | 2020-01-28 07:24:13 -0800 | [diff] [blame] | 161 | // 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 Scandolo | 7b51220 | 2020-11-09 16:38:10 -0800 | [diff] [blame] | 170 | func GetCredentialsStatus(pos *uint, pkt []byte, _ OnuKey) ([]byte, error) { |
Matteo Scandolo | 732c075 | 2020-01-28 07:24:13 -0800 | [diff] [blame] | 171 | // 1 byte |
| 172 | pkt[*pos] = 0x00 |
| 173 | *pos++ |
| 174 | return pkt, nil |
| 175 | } |
| 176 | |
Matteo Scandolo | 7b51220 | 2020-11-09 16:38:10 -0800 | [diff] [blame] | 177 | func GetExtendedTcLayerOptions(pos *uint, pkt []byte, _ OnuKey) ([]byte, error) { |
Matteo Scandolo | 732c075 | 2020-01-28 07:24:13 -0800 | [diff] [blame] | 178 | // 2 bytes |
| 179 | tcbits := []byte{0x00, 0x00} |
| 180 | for _, ch := range tcbits { |
| 181 | pkt[*pos] = ch |
| 182 | *pos++ |
| 183 | } |
| 184 | return pkt, nil |
| 185 | } |