blob: 82995a796373e9309fa33a4c5341408345689d34 [file] [log] [blame]
Takahiro Suzukid7bf8202020-12-17 20:21:59 +09001/*
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 l2oam
18
19import (
20 "encoding/hex"
21 "fmt"
22
23 "github.com/google/gopacket"
24)
25
26// GenerateGetFirmwareVersion generates "Running Firmware Version" message
27func GenerateGetFirmwareVersion() gopacket.SerializableLayer {
28 tibitData := &TOAMGetRequest{
29 // IEEE 1904.2
30 Opcode: 0x03,
31 // OMI Protocol
32 Flags: 0x0050,
33 OAMPDUCode: 0xfe,
34 OUId: []byte{0x2a, 0xea, 0x15},
35 // TiBiT OLT Management Interface
36 TOMIOpcode: 0x01,
37 // Correlation Tag
38 CTBranch: 0x0c,
39 CTType: 0x0c7a,
40 CTLength: 4,
41 CTInstance: getOltInstance(),
42 // Object Context
43 OCBranch: 0x0c,
44 OCType: 0x0dce,
45 OCLength: 4,
46 OCInstance: 0x00000000,
47 // Vd
48 VdBranch: 0xde,
49 VdLeaf: 0x001b,
50 // End
51 EndBranch: 0,
52 }
53 return tibitData
54}
55
56// GetFirmwareVersionRes is a structure for a response of "Running Firmware Version"
57type GetFirmwareVersionRes struct {
58 ComResp TOAMGetResponse
59 AKLength uint8
60 AKValue []byte
61 RVLength uint8
62 RVValue []byte
63 BSLength uint8
64 BSValue []byte
65 RNLength uint8
66 RNValue []byte
67 BDLength uint8
68 BDValue []byte
69 EndBranch uint8
70}
71
72// String returns the string expression of GetFirmwareVersionRes
73func (d *GetFirmwareVersionRes) String() string {
74 message := d.ComResp.String()
75 message = fmt.Sprintf("%s, AKLength:%02x, AKValue:%s, RVLength:%02x, RVValue:%s", message, d.AKLength, hex.EncodeToString(d.AKValue), d.RVLength, hex.EncodeToString(d.RVValue))
76 message = fmt.Sprintf("%s, BSLength:%02x, BSValue:%s, RNLength:%02x, RNValue:%s", message, d.BSLength, hex.EncodeToString(d.BSValue), d.RNLength, hex.EncodeToString(d.RNValue))
77 message = fmt.Sprintf("%s, BDLength:%02x, BDValue:%s, EndBranch:%02x", message, d.BDLength, hex.EncodeToString(d.BDValue), d.EndBranch)
78 return message
79}
80
81// Len returns the length of GetFirmwareVersionRes
82func (d *GetFirmwareVersionRes) Len() int {
83 return d.ComResp.Len() + int(d.ComResp.VcLength) + 1
84}
85
86// Decode decodes byte arrays to a data structure
87func (d *GetFirmwareVersionRes) Decode(data []byte) error {
88 d.ComResp.Decode(data)
89 i := d.ComResp.Len()
90 d.AKLength = data[i]
91 i++
92 d.AKValue = data[i : i+int(d.AKLength)]
93 i += int(d.AKLength)
94 d.RVLength = data[i]
95 i++
96 d.RVValue = data[i : i+int(d.RVLength)]
97 i += int(d.RVLength)
98 d.BSLength = data[i]
99 i++
100 d.BSValue = data[i : i+int(d.BSLength)]
101 i += int(d.BSLength)
102 d.RNLength = data[i]
103 i++
104 d.RNValue = data[i : i+int(d.RNLength)]
105 i += int(d.RNLength)
106 d.BDLength = data[i]
107 i++
108 d.BDValue = data[i : i+int(d.BDLength)]
109 i += int(d.BDLength)
110 d.EndBranch = data[i]
111
112 return nil
113}
114
115// GetFirmwareVersionNumber returns a firmware version number
116func (d *GetFirmwareVersionRes) GetFirmwareVersionNumber() string {
117 return string(d.RVValue)
118}