Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 1 | /* |
Joey Armstrong | 2c03936 | 2024-02-04 18:51:52 -0500 | [diff] [blame] | 2 | * Copyright 2018-2024 Open Networking Foundation (ONF) and the ONF Contributors |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 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 omci |
| 18 | |
| 19 | import ( |
| 20 | "encoding/hex" |
| 21 | "errors" |
Holger Hildebrandt | 9638257 | 2022-05-31 09:41:38 +0000 | [diff] [blame] | 22 | "strconv" |
| 23 | |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 24 | "github.com/google/gopacket" |
Andrea Campanella | 10426e2 | 2021-10-15 17:58:04 +0200 | [diff] [blame] | 25 | "github.com/opencord/omci-lib-go/v2" |
| 26 | me "github.com/opencord/omci-lib-go/v2/generated" |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 27 | log "github.com/sirupsen/logrus" |
Holger Hildebrandt | 9638257 | 2022-05-31 09:41:38 +0000 | [diff] [blame] | 28 | ) |
| 29 | |
| 30 | const ( |
| 31 | cOmciDownloadSectionSizeBaseLine = 31 //in bytes |
| 32 | cOmciDownloadSectionSizeExtLine = 1965 //in bytes |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 33 | ) |
| 34 | |
| 35 | func ParseStartSoftwareDownloadRequest(omciPkt gopacket.Packet) (*omci.StartSoftwareDownloadRequest, error) { |
| 36 | msgLayer := omciPkt.Layer(omci.LayerTypeStartSoftwareDownloadRequest) |
| 37 | if msgLayer == nil { |
| 38 | err := "omci Msg layer could not be detected for LayerTypeStartSoftwareDownloadRequest" |
| 39 | omciLogger.Error(err) |
| 40 | return nil, errors.New(err) |
| 41 | } |
| 42 | msgObj, msgOk := msgLayer.(*omci.StartSoftwareDownloadRequest) |
| 43 | if !msgOk { |
| 44 | err := "omci Msg layer could not be assigned for LayerTypeStartSoftwareDownloadRequest" |
| 45 | omciLogger.Error(err) |
| 46 | return nil, errors.New(err) |
| 47 | } |
| 48 | return msgObj, nil |
| 49 | } |
| 50 | |
| 51 | func ParseDownloadSectionRequest(omciPkt gopacket.Packet) (*omci.DownloadSectionRequest, error) { |
| 52 | msgLayer := omciPkt.Layer(omci.LayerTypeDownloadSectionRequest) |
| 53 | if msgLayer == nil { |
| 54 | err := "omci Msg layer could not be detected for LayerTypeDownloadSectionRequest" |
| 55 | omciLogger.Error(err) |
| 56 | return nil, errors.New(err) |
| 57 | } |
| 58 | msgObj, msgOk := msgLayer.(*omci.DownloadSectionRequest) |
| 59 | if !msgOk { |
| 60 | err := "omci Msg layer could not be assigned for LayerTypeDownloadSectionRequest" |
| 61 | omciLogger.Error(err) |
| 62 | return nil, errors.New(err) |
| 63 | } |
| 64 | return msgObj, nil |
| 65 | } |
| 66 | |
| 67 | func ParseEndSoftwareDownloadRequest(omciPkt gopacket.Packet) (*omci.EndSoftwareDownloadRequest, error) { |
| 68 | msgLayer := omciPkt.Layer(omci.LayerTypeEndSoftwareDownloadRequest) |
| 69 | if msgLayer == nil { |
| 70 | err := "omci Msg layer could not be detected for LayerTypeEndSoftwareDownloadRequest" |
| 71 | omciLogger.Error(err) |
| 72 | return nil, errors.New(err) |
| 73 | } |
| 74 | msgObj, msgOk := msgLayer.(*omci.EndSoftwareDownloadRequest) |
| 75 | if !msgOk { |
| 76 | err := "omci Msg layer could not be assigned for LayerTypeEndSoftwareDownloadRequest" |
| 77 | omciLogger.Error(err) |
| 78 | return nil, errors.New(err) |
| 79 | } |
| 80 | return msgObj, nil |
| 81 | } |
| 82 | |
| 83 | func ParseActivateSoftwareRequest(omciPkt gopacket.Packet) (*omci.ActivateSoftwareRequest, error) { |
| 84 | msgLayer := omciPkt.Layer(omci.LayerTypeActivateSoftwareRequest) |
| 85 | if msgLayer == nil { |
| 86 | err := "omci Msg layer could not be detected for LayerTypeActivateSoftwareRequest" |
| 87 | omciLogger.Error(err) |
| 88 | return nil, errors.New(err) |
| 89 | } |
| 90 | msgObj, msgOk := msgLayer.(*omci.ActivateSoftwareRequest) |
| 91 | if !msgOk { |
| 92 | err := "omci Msg layer could not be assigned for LayerTypeActivateSoftwareRequest" |
| 93 | omciLogger.Error(err) |
| 94 | return nil, errors.New(err) |
| 95 | } |
| 96 | return msgObj, nil |
| 97 | } |
| 98 | |
| 99 | func ParseCommitSoftwareRequest(omciPkt gopacket.Packet) (*omci.CommitSoftwareRequest, error) { |
| 100 | msgLayer := omciPkt.Layer(omci.LayerTypeCommitSoftwareRequest) |
| 101 | if msgLayer == nil { |
| 102 | err := "omci Msg layer could not be detected for LayerTypeCommitSoftwareRequest" |
| 103 | omciLogger.Error(err) |
| 104 | return nil, errors.New(err) |
| 105 | } |
| 106 | msgObj, msgOk := msgLayer.(*omci.CommitSoftwareRequest) |
| 107 | if !msgOk { |
| 108 | err := "omci Msg layer could not be assigned for LayerTypeCommitSoftwareRequest" |
| 109 | omciLogger.Error(err) |
| 110 | return nil, errors.New(err) |
| 111 | } |
| 112 | return msgObj, nil |
| 113 | } |
| 114 | |
| 115 | func CreateStartSoftwareDownloadResponse(omciPkt gopacket.Packet, omciMsg *omci.OMCI) ([]byte, error) { |
Holger Hildebrandt | 9638257 | 2022-05-31 09:41:38 +0000 | [diff] [blame] | 116 | |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 117 | responeCode := me.Success |
| 118 | msgObj, err := ParseStartSoftwareDownloadRequest(omciPkt) |
| 119 | if err != nil { |
| 120 | responeCode = me.ProcessingError |
| 121 | } |
Holger Hildebrandt | 9638257 | 2022-05-31 09:41:38 +0000 | [diff] [blame] | 122 | isExtended := false |
| 123 | if omciMsg.DeviceIdentifier == omci.ExtendedIdent { |
| 124 | isExtended = true |
| 125 | } |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 126 | omciLogger.WithFields(log.Fields{ |
| 127 | "OmciMsgType": omciMsg.MessageType, |
| 128 | "TransCorrId": omciMsg.TransactionID, |
Holger Hildebrandt | 9638257 | 2022-05-31 09:41:38 +0000 | [diff] [blame] | 129 | "DeviceIdentifier": omciMsg.DeviceIdentifier, |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 130 | "EntityInstance": msgObj.EntityInstance, |
| 131 | "WindowSize": msgObj.WindowSize, |
| 132 | "ImageSize": msgObj.ImageSize, |
| 133 | "NumberOfCircuitPacks": msgObj.NumberOfCircuitPacks, |
| 134 | "CircuitPacks": msgObj.CircuitPacks, |
| 135 | }).Debug("received-start-software-download-request") |
| 136 | |
| 137 | response := &omci.StartSoftwareDownloadResponse{ |
| 138 | MeBasePacket: omci.MeBasePacket{ |
| 139 | EntityClass: msgObj.EntityClass, |
| 140 | EntityInstance: msgObj.EntityInstance, |
Holger Hildebrandt | 9638257 | 2022-05-31 09:41:38 +0000 | [diff] [blame] | 141 | Extended: isExtended, |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 142 | }, |
| 143 | WindowSize: msgObj.WindowSize, |
| 144 | Result: responeCode, |
| 145 | NumberOfInstances: 0, // NOTE this can't be bigger than 0 this we can populate downloadResults |
| 146 | MeResults: []omci.DownloadResults{}, // FIXME downloadResults is not exported |
| 147 | } |
Holger Hildebrandt | 9638257 | 2022-05-31 09:41:38 +0000 | [diff] [blame] | 148 | omciLayer := &omci.OMCI{ |
| 149 | TransactionID: omciMsg.TransactionID, |
| 150 | MessageType: omci.StartSoftwareDownloadResponseType, |
| 151 | DeviceIdentifier: omciMsg.DeviceIdentifier, |
| 152 | } |
| 153 | var options gopacket.SerializeOptions |
| 154 | options.FixLengths = true |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 155 | |
Holger Hildebrandt | 9638257 | 2022-05-31 09:41:38 +0000 | [diff] [blame] | 156 | buffer := gopacket.NewSerializeBuffer() |
| 157 | err = gopacket.SerializeLayers(buffer, options, omciLayer, response) |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 158 | if err != nil { |
| 159 | omciLogger.WithFields(log.Fields{ |
Holger Hildebrandt | 9638257 | 2022-05-31 09:41:38 +0000 | [diff] [blame] | 160 | "Err": err, |
| 161 | "TxID": strconv.FormatInt(int64(omciMsg.TransactionID), 16), |
| 162 | }).Error("cannot-Serialize-StartSoftwareDownloadResponse") |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 163 | return nil, err |
| 164 | } |
Holger Hildebrandt | 9638257 | 2022-05-31 09:41:38 +0000 | [diff] [blame] | 165 | pkt := buffer.Bytes() |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 166 | |
| 167 | log.WithFields(log.Fields{ |
| 168 | "TxID": strconv.FormatInt(int64(omciMsg.TransactionID), 16), |
| 169 | "pkt": hex.EncodeToString(pkt), |
| 170 | }).Trace("omci-start-software-download-response") |
| 171 | |
| 172 | return pkt, nil |
| 173 | } |
| 174 | |
| 175 | func CreateDownloadSectionResponse(omciPkt gopacket.Packet, omciMsg *omci.OMCI) ([]byte, error) { |
| 176 | |
| 177 | msgObj, err := ParseDownloadSectionRequest(omciPkt) |
| 178 | |
| 179 | if err != nil { |
| 180 | return nil, err |
| 181 | } |
Holger Hildebrandt | 9638257 | 2022-05-31 09:41:38 +0000 | [diff] [blame] | 182 | isExtended := false |
| 183 | if omciMsg.DeviceIdentifier == omci.ExtendedIdent { |
| 184 | isExtended = true |
| 185 | } |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 186 | omciLogger.WithFields(log.Fields{ |
Holger Hildebrandt | 9638257 | 2022-05-31 09:41:38 +0000 | [diff] [blame] | 187 | "OmciMsgType": omciMsg.MessageType, |
| 188 | "TransCorrId": omciMsg.TransactionID, |
| 189 | "DeviceIdentifier": omciMsg.DeviceIdentifier, |
| 190 | "EntityInstance": msgObj.EntityInstance, |
| 191 | "SectionNumber": msgObj.SectionNumber, |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 192 | }).Debug("received-download-section-request") |
| 193 | |
| 194 | response := &omci.DownloadSectionResponse{ |
| 195 | MeBasePacket: omci.MeBasePacket{ |
| 196 | EntityClass: msgObj.EntityClass, |
| 197 | EntityInstance: msgObj.EntityInstance, |
Holger Hildebrandt | 9638257 | 2022-05-31 09:41:38 +0000 | [diff] [blame] | 198 | Extended: isExtended, |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 199 | }, |
| 200 | Result: me.Success, |
| 201 | SectionNumber: msgObj.SectionNumber, |
| 202 | } |
Holger Hildebrandt | 9638257 | 2022-05-31 09:41:38 +0000 | [diff] [blame] | 203 | omciLayer := &omci.OMCI{ |
| 204 | TransactionID: omciMsg.TransactionID, |
| 205 | MessageType: omci.DownloadSectionResponseType, |
| 206 | DeviceIdentifier: omciMsg.DeviceIdentifier, |
| 207 | } |
| 208 | var options gopacket.SerializeOptions |
| 209 | options.FixLengths = true |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 210 | |
Holger Hildebrandt | 9638257 | 2022-05-31 09:41:38 +0000 | [diff] [blame] | 211 | buffer := gopacket.NewSerializeBuffer() |
| 212 | err = gopacket.SerializeLayers(buffer, options, omciLayer, response) |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 213 | if err != nil { |
Holger Hildebrandt | 9638257 | 2022-05-31 09:41:38 +0000 | [diff] [blame] | 214 | omciLogger.WithFields(log.Fields{ |
| 215 | "Err": err, |
| 216 | "TxID": strconv.FormatInt(int64(omciMsg.TransactionID), 16), |
| 217 | }).Error("cannot-Serialize-DownloadSectionResponse") |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 218 | return nil, err |
| 219 | } |
Holger Hildebrandt | 9638257 | 2022-05-31 09:41:38 +0000 | [diff] [blame] | 220 | pkt := buffer.Bytes() |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 221 | |
| 222 | log.WithFields(log.Fields{ |
| 223 | "TxID": strconv.FormatInt(int64(omciMsg.TransactionID), 16), |
| 224 | "pkt": hex.EncodeToString(pkt), |
| 225 | }).Trace("omci-download-section-with-response-response") |
| 226 | |
| 227 | return pkt, nil |
| 228 | } |
| 229 | |
| 230 | func CreateEndSoftwareDownloadResponse(omciPkt gopacket.Packet, omciMsg *omci.OMCI, status me.Results) ([]byte, error) { |
| 231 | |
| 232 | msgObj, err := ParseEndSoftwareDownloadRequest(omciPkt) |
| 233 | |
| 234 | if err != nil { |
| 235 | return nil, err |
| 236 | } |
Holger Hildebrandt | 9638257 | 2022-05-31 09:41:38 +0000 | [diff] [blame] | 237 | isExtended := false |
| 238 | if omciMsg.DeviceIdentifier == omci.ExtendedIdent { |
| 239 | isExtended = true |
| 240 | } |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 241 | omciLogger.WithFields(log.Fields{ |
| 242 | "OmciMsgType": omciMsg.MessageType, |
| 243 | "TransCorrId": omciMsg.TransactionID, |
Holger Hildebrandt | 9638257 | 2022-05-31 09:41:38 +0000 | [diff] [blame] | 244 | "DeviceIdentifier": omciMsg.DeviceIdentifier, |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 245 | "EntityInstance": msgObj.EntityInstance, |
| 246 | "Crc32": msgObj.CRC32, |
| 247 | "ImageSize": msgObj.ImageSize, |
| 248 | "NumberOfInstances": msgObj.NumberOfInstances, |
| 249 | "ImageInstances": msgObj.ImageInstances, |
| 250 | }).Debug("received-end-software-download-request") |
| 251 | |
| 252 | response := &omci.EndSoftwareDownloadResponse{ |
| 253 | MeBasePacket: omci.MeBasePacket{ |
| 254 | EntityClass: msgObj.EntityClass, |
| 255 | EntityInstance: msgObj.EntityInstance, |
Holger Hildebrandt | 9638257 | 2022-05-31 09:41:38 +0000 | [diff] [blame] | 256 | Extended: isExtended, |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 257 | }, |
| 258 | Result: status, |
| 259 | NumberOfInstances: 0, // NOTE this can't be bigger than 0 this we can populate downloadResults |
| 260 | //MeResults: []omci.downloadResults{}, // FIXME downloadResults is not exported |
| 261 | } |
Holger Hildebrandt | 9638257 | 2022-05-31 09:41:38 +0000 | [diff] [blame] | 262 | omciLayer := &omci.OMCI{ |
| 263 | TransactionID: omciMsg.TransactionID, |
| 264 | MessageType: omci.EndSoftwareDownloadResponseType, |
| 265 | DeviceIdentifier: omciMsg.DeviceIdentifier, |
| 266 | } |
| 267 | var options gopacket.SerializeOptions |
| 268 | options.FixLengths = true |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 269 | |
Holger Hildebrandt | 9638257 | 2022-05-31 09:41:38 +0000 | [diff] [blame] | 270 | buffer := gopacket.NewSerializeBuffer() |
| 271 | err = gopacket.SerializeLayers(buffer, options, omciLayer, response) |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 272 | if err != nil { |
Holger Hildebrandt | 9638257 | 2022-05-31 09:41:38 +0000 | [diff] [blame] | 273 | omciLogger.WithFields(log.Fields{ |
| 274 | "Err": err, |
| 275 | "TxID": strconv.FormatInt(int64(omciMsg.TransactionID), 16), |
| 276 | }).Error("cannot-Serialize-EndSoftwareDownloadResponse") |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 277 | return nil, err |
| 278 | } |
Holger Hildebrandt | 9638257 | 2022-05-31 09:41:38 +0000 | [diff] [blame] | 279 | pkt := buffer.Bytes() |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 280 | |
| 281 | log.WithFields(log.Fields{ |
| 282 | "TxID": strconv.FormatInt(int64(omciMsg.TransactionID), 16), |
| 283 | "pkt": hex.EncodeToString(pkt), |
| 284 | }).Trace("omci-end-software-download-response") |
| 285 | |
| 286 | return pkt, nil |
| 287 | } |
| 288 | |
| 289 | func CreateActivateSoftwareResponse(omciPkt gopacket.Packet, omciMsg *omci.OMCI) ([]byte, error) { |
| 290 | |
| 291 | msgObj, err := ParseActivateSoftwareRequest(omciPkt) |
| 292 | |
| 293 | if err != nil { |
| 294 | return nil, err |
| 295 | } |
Holger Hildebrandt | 9638257 | 2022-05-31 09:41:38 +0000 | [diff] [blame] | 296 | isExtended := false |
| 297 | if omciMsg.DeviceIdentifier == omci.ExtendedIdent { |
| 298 | isExtended = true |
| 299 | } |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 300 | omciLogger.WithFields(log.Fields{ |
Holger Hildebrandt | 9638257 | 2022-05-31 09:41:38 +0000 | [diff] [blame] | 301 | "OmciMsgType": omciMsg.MessageType, |
| 302 | "TransCorrId": omciMsg.TransactionID, |
| 303 | "DeviceIdentifier": omciMsg.DeviceIdentifier, |
| 304 | "EntityInstance": msgObj.EntityInstance, |
| 305 | "ActivateFlags": msgObj.ActivateFlags, |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 306 | }).Debug("received-activate-software-request") |
| 307 | |
| 308 | response := &omci.ActivateSoftwareResponse{ |
| 309 | MeBasePacket: omci.MeBasePacket{ |
| 310 | EntityClass: msgObj.EntityClass, |
| 311 | EntityInstance: msgObj.EntityInstance, |
Holger Hildebrandt | 9638257 | 2022-05-31 09:41:38 +0000 | [diff] [blame] | 312 | Extended: isExtended, |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 313 | }, |
| 314 | Result: me.Success, |
| 315 | } |
Holger Hildebrandt | 9638257 | 2022-05-31 09:41:38 +0000 | [diff] [blame] | 316 | omciLayer := &omci.OMCI{ |
| 317 | TransactionID: omciMsg.TransactionID, |
| 318 | MessageType: omci.ActivateSoftwareResponseType, |
| 319 | DeviceIdentifier: omciMsg.DeviceIdentifier, |
| 320 | } |
| 321 | var options gopacket.SerializeOptions |
| 322 | options.FixLengths = true |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 323 | |
Holger Hildebrandt | 9638257 | 2022-05-31 09:41:38 +0000 | [diff] [blame] | 324 | buffer := gopacket.NewSerializeBuffer() |
| 325 | err = gopacket.SerializeLayers(buffer, options, omciLayer, response) |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 326 | if err != nil { |
Holger Hildebrandt | 9638257 | 2022-05-31 09:41:38 +0000 | [diff] [blame] | 327 | omciLogger.WithFields(log.Fields{ |
| 328 | "Err": err, |
| 329 | "TxID": strconv.FormatInt(int64(omciMsg.TransactionID), 16), |
| 330 | }).Error("cannot-Serialize-ActivateSoftwareResponse") |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 331 | return nil, err |
| 332 | } |
Holger Hildebrandt | 9638257 | 2022-05-31 09:41:38 +0000 | [diff] [blame] | 333 | pkt := buffer.Bytes() |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 334 | |
| 335 | log.WithFields(log.Fields{ |
| 336 | "TxID": strconv.FormatInt(int64(omciMsg.TransactionID), 16), |
| 337 | "pkt": hex.EncodeToString(pkt), |
| 338 | }).Trace("omci-activate-software-response") |
| 339 | |
| 340 | return pkt, nil |
| 341 | } |
| 342 | |
| 343 | func CreateCommitSoftwareResponse(omciPkt gopacket.Packet, omciMsg *omci.OMCI) ([]byte, error) { |
| 344 | |
| 345 | msgObj, err := ParseCommitSoftwareRequest(omciPkt) |
| 346 | |
| 347 | if err != nil { |
| 348 | return nil, err |
| 349 | } |
Holger Hildebrandt | 9638257 | 2022-05-31 09:41:38 +0000 | [diff] [blame] | 350 | isExtended := false |
| 351 | if omciMsg.DeviceIdentifier == omci.ExtendedIdent { |
| 352 | isExtended = true |
| 353 | } |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 354 | omciLogger.WithFields(log.Fields{ |
Holger Hildebrandt | 9638257 | 2022-05-31 09:41:38 +0000 | [diff] [blame] | 355 | "OmciMsgType": omciMsg.MessageType, |
| 356 | "TransCorrId": omciMsg.TransactionID, |
| 357 | "DeviceIdentifier": omciMsg.DeviceIdentifier, |
| 358 | "EntityInstance": msgObj.EntityInstance, |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 359 | }).Debug("received-commit-software-request") |
| 360 | |
| 361 | response := &omci.CommitSoftwareResponse{ |
| 362 | MeBasePacket: omci.MeBasePacket{ |
| 363 | EntityClass: msgObj.EntityClass, |
| 364 | EntityInstance: msgObj.EntityInstance, |
Holger Hildebrandt | 9638257 | 2022-05-31 09:41:38 +0000 | [diff] [blame] | 365 | Extended: isExtended, |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 366 | }, |
| 367 | } |
Holger Hildebrandt | 9638257 | 2022-05-31 09:41:38 +0000 | [diff] [blame] | 368 | omciLayer := &omci.OMCI{ |
| 369 | TransactionID: omciMsg.TransactionID, |
| 370 | MessageType: omci.CommitSoftwareResponseType, |
| 371 | DeviceIdentifier: omciMsg.DeviceIdentifier, |
| 372 | } |
| 373 | var options gopacket.SerializeOptions |
| 374 | options.FixLengths = true |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 375 | |
Holger Hildebrandt | 9638257 | 2022-05-31 09:41:38 +0000 | [diff] [blame] | 376 | buffer := gopacket.NewSerializeBuffer() |
| 377 | err = gopacket.SerializeLayers(buffer, options, omciLayer, response) |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 378 | if err != nil { |
Holger Hildebrandt | 9638257 | 2022-05-31 09:41:38 +0000 | [diff] [blame] | 379 | omciLogger.WithFields(log.Fields{ |
| 380 | "Err": err, |
| 381 | "TxID": strconv.FormatInt(int64(omciMsg.TransactionID), 16), |
| 382 | }).Error("cannot-Serialize-CommitSoftwareResponse") |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 383 | return nil, err |
| 384 | } |
Holger Hildebrandt | 9638257 | 2022-05-31 09:41:38 +0000 | [diff] [blame] | 385 | pkt := buffer.Bytes() |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 386 | |
| 387 | log.WithFields(log.Fields{ |
| 388 | "TxID": strconv.FormatInt(int64(omciMsg.TransactionID), 16), |
| 389 | "pkt": hex.EncodeToString(pkt), |
| 390 | }).Trace("omci-commit-software-response") |
| 391 | |
| 392 | return pkt, nil |
| 393 | } |
| 394 | |
Holger Hildebrandt | 9638257 | 2022-05-31 09:41:38 +0000 | [diff] [blame] | 395 | func ComputeDownloadSectionsCount(pkt gopacket.Packet) uint32 { |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 396 | msgObj, err := ParseStartSoftwareDownloadRequest(pkt) |
| 397 | if err != nil { |
| 398 | omciLogger.Error("cannot-parse-start-software-download-request") |
| 399 | } |
Holger Hildebrandt | 9638257 | 2022-05-31 09:41:38 +0000 | [diff] [blame] | 400 | var omciDownloadSectionSize uint32 |
| 401 | if msgObj.Extended { |
| 402 | omciDownloadSectionSize = cOmciDownloadSectionSizeExtLine |
| 403 | } else { |
| 404 | omciDownloadSectionSize = cOmciDownloadSectionSizeBaseLine |
| 405 | } |
| 406 | noOfSections := msgObj.ImageSize / omciDownloadSectionSize |
| 407 | if msgObj.ImageSize%omciDownloadSectionSize > 0 { |
| 408 | noOfSections++ |
| 409 | } |
| 410 | return noOfSections |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 411 | } |