blob: f0d2f9e9ce086bc07d2c7d645c010ea2ba758071 [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 SoftwareImageAttributes int
20
21const (
22 _ = iota
23 SoftwareVersion SoftwareImageAttributes = 0x8000
24 IsCommited SoftwareImageAttributes = 0x4000
25 IsActive SoftwareImageAttributes = 0x2000
26 IsValid SoftwareImageAttributes = 0x1000
27 ProductCode SoftwareImageAttributes = 0x0800
28 ImageHash SoftwareImageAttributes = 0x0400
29)
30
31type SoftwareImageAttributeHandler func(*uint, []byte) ([]byte, error)
32
33var SoftwareImageAttributeHandlers = map[SoftwareImageAttributes]SoftwareImageAttributeHandler{
34 SoftwareVersion: GetSoftwareVersion,
35 IsCommited: GetIsCommited,
36 IsActive: GetIsActive,
37 IsValid: GetIsValid,
38 ProductCode: GetProductCode,
39 ImageHash: GetImageHash,
40}
41
42func GetSoftwareImageAttributes(pos *uint, pkt []byte, content OmciContent) ([]byte, error) {
43 AttributesMask := getAttributeMask(content)
44
45 for index := uint(16); index >= 1; index-- {
46 Attribute := 1 << (index - 1)
47 reqAttribute := Attribute & AttributesMask
48
49 if reqAttribute != 0 {
50 pkt, _ = SoftwareImageAttributeHandlers[SoftwareImageAttributes(reqAttribute)](pos, pkt)
51 }
52 }
53
54 pkt[8] = 0x00 // Command Processed Successfully
55 pkt[9] = uint8(AttributesMask >> 8)
56 pkt[10] = uint8(AttributesMask & 0x00FF)
57
58 return pkt, nil
59
60}
61
62func GetSoftwareVersion(pos *uint, pkt []byte) ([]byte, error) {
63 // 14 bytes
64 version := []byte("00000000000001")
65 for _, ch := range version {
66 pkt[*pos] = ch
67 *pos++
68 }
69 return pkt, nil
70}
71
72func GetIsCommited(pos *uint, pkt []byte) ([]byte, error) {
73 // 1 bytes
74 pkt[*pos] = 0x01
75 *pos++
76 return pkt, nil
77}
78
79func GetIsActive(pos *uint, pkt []byte) ([]byte, error) {
80 // 1 bytes
81 pkt[*pos] = 0x01
82 *pos++
83 return pkt, nil
84}
85
86func GetIsValid(pos *uint, pkt []byte) ([]byte, error) {
87 // 1 byte
88 pkt[*pos] = 0x01
89 *pos++
90 return pkt, nil
91}
92
93func GetProductCode(pos *uint, pkt []byte) ([]byte, error) {
94 // 25 bytes
95 // BRCM has 25 nulls
96 for i := 1; i <= 25; i++ {
97 pkt[*pos] = 0x00
98 *pos++
99 }
100 return pkt, nil
101}
102
103func GetImageHash(pos *uint, pkt []byte) ([]byte, error) {
104 // 16 bytes
105 // BRCM has 16 nulls
106 for i := 1; i <= 16; i++ {
107 pkt[*pos] = 0x00
108 *pos++
109 }
110 return pkt, nil
111}