blob: 06f22ddb2b06c8afb47fcbc8f0f6dafbd47bd7ad [file] [log] [blame]
Shad Ansari1106b022019-01-16 22:22:35 -08001/*
2 * Copyright 2018-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 */
16package core
17
18import (
19 "bytes"
20 "encoding/binary"
21 "errors"
Shad Ansari53935c02019-01-17 16:41:45 -080022 "log"
Shad Ansari1106b022019-01-16 22:22:35 -080023)
24
25//
26// OMCI definitions
27//
28
29// OmciMsgType represents a OMCI message-type
30type OmciMsgType byte
31
32const (
33 // Message Types
34 _ = iota
35 Create OmciMsgType = 4
36 Delete OmciMsgType = 6
37 Set OmciMsgType = 8
38 Get OmciMsgType = 9
39 GetAllAlarms OmciMsgType = 11
40 GetAllAlarmsNext OmciMsgType = 12
41 MibUpload OmciMsgType = 13
42 MibUploadNext OmciMsgType = 14
43 MibReset OmciMsgType = 15
44 AlarmNotification OmciMsgType = 16
45 AttributeValueChange OmciMsgType = 17
46 Test OmciMsgType = 18
47 StartSoftwareDownload OmciMsgType = 19
48 DownloadSection OmciMsgType = 20
49 EndSoftwareDownload OmciMsgType = 21
50 ActivateSoftware OmciMsgType = 22
51 CommitSoftware OmciMsgType = 23
52 SynchronizeTime OmciMsgType = 24
53 Reboot OmciMsgType = 25
54 GetNext OmciMsgType = 26
55 TestResult OmciMsgType = 27
56 GetCurrentData OmciMsgType = 28
57 SetTable OmciMsgType = 29 // Defined in Extended Message Set Only
58)
59
60const (
61 // Managed Entity Class values
62 GEMPortNetworkCTP OmciClass = 268
63)
64
65// OMCI Managed Entity Class
66type OmciClass uint16
67
68// OMCI Message Identifier
69type OmciMessageIdentifier struct {
70 Class OmciClass
71 Instance uint16
72}
73
74type OmciContent [32]byte
75
76type OmciMessage struct {
77 TransactionId uint16
78 MessageType OmciMsgType
79 DeviceId uint8
80 MessageId OmciMessageIdentifier
81 Content OmciContent
82}
83
84func ParsePkt(pkt []byte) (uint16, uint8, OmciMsgType, OmciClass, uint16, OmciContent, error) {
85 var m OmciMessage
86
87 r := bytes.NewReader(pkt)
88
89 if err := binary.Read(r, binary.BigEndian, &m); err != nil {
Shad Ansari53935c02019-01-17 16:41:45 -080090 log.Printf("binary.Read failed: %s", err)
Shad Ansari1106b022019-01-16 22:22:35 -080091 return 0, 0, 0, 0, 0, OmciContent{}, errors.New("binary.Read failed")
92 }
Mahir Gunyel133913f2019-02-14 19:57:07 -080093 /* Message Type = Set
94 0... .... = Destination Bit: 0x0
95 .1.. .... = Acknowledge Request: 0x1
96 ..0. .... = Acknowledgement: 0x0
97 ...0 1000 = Message Type: Set (8)
98 */
Shad Ansari53935c02019-01-17 16:41:45 -080099 log.Printf("OmciRun - TransactionId: %d MessageType: %d, ME Class: %d, ME Instance: %d, Content: %x",
Mahir Gunyel133913f2019-02-14 19:57:07 -0800100 m.TransactionId, m.MessageType&0x1F, m.MessageId.Class, m.MessageId.Instance, m.Content)
101 return m.TransactionId, m.DeviceId, m.MessageType & 0x1F, m.MessageId.Class, m.MessageId.Instance, m.Content, nil
Shad Ansari1106b022019-01-16 22:22:35 -0800102}