blob: d7904adf9edc380324d1c8aeff5d6de482ecd495 [file] [log] [blame]
Chip Boling6e27b352020-02-14 09:10:01 -06001/*
2 * Copyright (c) 2018 - present. Boling Consulting Solutions (bcsw.net)
Andrea Campanella7167ebb2020-02-24 09:56:38 +01003 * Copyright 2020-present Open Networking Foundation
4
Chip Boling6e27b352020-02-14 09:10:01 -06005 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
Andrea Campanella7167ebb2020-02-24 09:56:38 +01008
Chip Boling6e27b352020-02-14 09:10:01 -06009 * http://www.apache.org/licenses/LICENSE-2.0
Andrea Campanella7167ebb2020-02-24 09:56:38 +010010
Chip Boling6e27b352020-02-14 09:10:01 -060011 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
Chip Boling6e27b352020-02-14 09:10:01 -060016 */
17
18package omci
19
20import (
21 "errors"
Chip Boling6e27b352020-02-14 09:10:01 -060022 "github.com/google/gopacket"
David K. Bainbridgeadf422d2021-04-09 16:06:41 +000023 me "github.com/opencord/omci-lib-go/generated"
Chip Boling6e27b352020-02-14 09:10:01 -060024)
25
26var nextLayerMapping map[MessageType]gopacket.LayerType
27
28var (
29 LayerTypeCreateRequest gopacket.LayerType
30 LayerTypeDeleteRequest gopacket.LayerType
31 LayerTypeSetRequest gopacket.LayerType
32 LayerTypeGetRequest gopacket.LayerType
33 LayerTypeGetAllAlarmsRequest gopacket.LayerType
34 LayerTypeGetAllAlarmsNextRequest gopacket.LayerType
35 LayerTypeMibUploadRequest gopacket.LayerType
36 LayerTypeMibUploadNextRequest gopacket.LayerType
37 LayerTypeMibResetRequest gopacket.LayerType
38 LayerTypeTestRequest gopacket.LayerType
39 LayerTypeStartSoftwareDownloadRequest gopacket.LayerType
40 LayerTypeDownloadSectionRequest gopacket.LayerType
41 LayerTypeDownloadSectionLastRequest gopacket.LayerType
42 LayerTypeEndSoftwareDownloadRequest gopacket.LayerType
43 LayerTypeActivateSoftwareRequest gopacket.LayerType
44 LayerTypeCommitSoftwareRequest gopacket.LayerType
45 LayerTypeSynchronizeTimeRequest gopacket.LayerType
46 LayerTypeRebootRequest gopacket.LayerType
47 LayerTypeGetNextRequest gopacket.LayerType
48 LayerTypeGetCurrentDataRequest gopacket.LayerType
49 LayerTypeSetTableRequest gopacket.LayerType
Chip Boling157c9b92021-04-21 09:58:36 -050050
Chip Boling610117d2021-09-09 11:24:34 -050051 LayerTypeCreateRequestExtended gopacket.LayerType
52 LayerTypeDeleteRequestExtended gopacket.LayerType
53 LayerTypeSetRequestExtended gopacket.LayerType
54 LayerTypeMibUploadRequestExtended gopacket.LayerType
55 LayerTypeMibUploadNextRequestExtended gopacket.LayerType
56 LayerTypeMibResetRequestExtended gopacket.LayerType
57 LayerTypeGetRequestExtended gopacket.LayerType
58 LayerTypeGetNextRequestExtended gopacket.LayerType
59 LayerTypeStartSoftwareDownloadRequestExtended gopacket.LayerType
60 LayerTypeDownloadSectionRequestExtended gopacket.LayerType
61 LayerTypeDownloadSectionLastRequestExtended gopacket.LayerType
62 LayerTypeEndSoftwareDownloadRequestExtended gopacket.LayerType
63 LayerTypeActivateSoftwareRequestExtended gopacket.LayerType
64 LayerTypeCommitSoftwareRequestExtended gopacket.LayerType
65 LayerTypeSynchronizeTimeRequestExtended gopacket.LayerType
66 LayerTypeRebootRequestExtended gopacket.LayerType
67 LayerTypeGetCurrentDataRequestExtended gopacket.LayerType
68 LayerTypeSetTableRequestExtended gopacket.LayerType
69 LayerTypeGetAllAlarmsRequestExtended gopacket.LayerType
70 LayerTypeGetAllAlarmsNextRequestExtended gopacket.LayerType
Chip Boling6e27b352020-02-14 09:10:01 -060071)
72var (
73 LayerTypeCreateResponse gopacket.LayerType
74 LayerTypeDeleteResponse gopacket.LayerType
75 LayerTypeSetResponse gopacket.LayerType
76 LayerTypeGetResponse gopacket.LayerType
77 LayerTypeGetAllAlarmsResponse gopacket.LayerType
78 LayerTypeGetAllAlarmsNextResponse gopacket.LayerType
79 LayerTypeMibUploadResponse gopacket.LayerType
80 LayerTypeMibUploadNextResponse gopacket.LayerType
81 LayerTypeMibResetResponse gopacket.LayerType
82 LayerTypeAlarmNotification gopacket.LayerType
83 LayerTypeAttributeValueChange gopacket.LayerType
84 LayerTypeTestResponse gopacket.LayerType
85 LayerTypeStartSoftwareDownloadResponse gopacket.LayerType
86 LayerTypeDownloadSectionResponse gopacket.LayerType
87 LayerTypeEndSoftwareDownloadResponse gopacket.LayerType
88 LayerTypeActivateSoftwareResponse gopacket.LayerType
89 LayerTypeCommitSoftwareResponse gopacket.LayerType
90 LayerTypeSynchronizeTimeResponse gopacket.LayerType
91 LayerTypeRebootResponse gopacket.LayerType
92 LayerTypeGetNextResponse gopacket.LayerType
93 LayerTypeTestResult gopacket.LayerType
94 LayerTypeGetCurrentDataResponse gopacket.LayerType
95 LayerTypeSetTableResponse gopacket.LayerType
Chip Boling157c9b92021-04-21 09:58:36 -050096
Chip Boling610117d2021-09-09 11:24:34 -050097 LayerTypeCreateResponseExtended gopacket.LayerType
98 LayerTypeDeleteResponseExtended gopacket.LayerType
99 LayerTypeSetResponseExtended gopacket.LayerType
100 LayerTypeMibUploadResponseExtended gopacket.LayerType
101 LayerTypeMibUploadNextResponseExtended gopacket.LayerType
102 LayerTypeMibResetResponseExtended gopacket.LayerType
103 LayerTypeGetResponseExtended gopacket.LayerType
104 LayerTypeGetNextResponseExtended gopacket.LayerType
105 LayerTypeStartSoftwareDownloadResponseExtended gopacket.LayerType
106 LayerTypeDownloadSectionResponseExtended gopacket.LayerType
107 LayerTypeEndSoftwareDownloadResponseExtended gopacket.LayerType
108 LayerTypeActivateSoftwareResponseExtended gopacket.LayerType
109 LayerTypeCommitSoftwareResponseExtended gopacket.LayerType
110 LayerTypeAlarmNotificationExtended gopacket.LayerType
111 LayerTypeAttributeValueChangeExtended gopacket.LayerType
112 LayerTypeTestResultExtended gopacket.LayerType
113 LayerTypeSynchronizeTimeResponseExtended gopacket.LayerType
114 LayerTypeRebootResponseExtended gopacket.LayerType
115 LayerTypeGetCurrentDataResponseExtended gopacket.LayerType
116 LayerTypeSetTableResponseExtended gopacket.LayerType
117 LayerTypeGetAllAlarmsResponseExtended gopacket.LayerType
118 LayerTypeGetAllAlarmsNextResponseExtended gopacket.LayerType
Chip Boling6e27b352020-02-14 09:10:01 -0600119)
Chip Boling934e1052021-09-27 15:12:06 -0500120var (
121 LayerTypeUnknownAttributes gopacket.LayerType
122)
Chip Boling6e27b352020-02-14 09:10:01 -0600123
124func mkReqLayer(mt me.MsgType, mts string, decode gopacket.DecodeFunc) gopacket.LayerType {
125 return gopacket.RegisterLayerType(1000+(int(mt)|int(me.AR)),
126 gopacket.LayerTypeMetadata{Name: mts, Decoder: decode})
127}
128
129func mkRespLayer(mt me.MsgType, mts string, decode gopacket.DecodeFunc) gopacket.LayerType {
130 return gopacket.RegisterLayerType(1000+(int(mt)|int(me.AK)),
131 gopacket.LayerTypeMetadata{Name: mts, Decoder: decode})
132}
133
134func mkLayer(mt me.MsgType, mts string, decode gopacket.DecodeFunc) gopacket.LayerType {
135 return gopacket.RegisterLayerType(1000+(int(mt)),
136 gopacket.LayerTypeMetadata{Name: mts, Decoder: decode})
137}
138
139func init() {
140 // Create layers for message_type & action
Chip Boling610117d2021-09-09 11:24:34 -0500141 LayerTypeCreateRequest = mkReqLayer(me.Create, "CreateRequest", decodeCreateRequest)
142 LayerTypeDeleteRequest = mkReqLayer(me.Delete, "DeleteRequest", decodeDeleteRequest)
143 LayerTypeSetRequest = mkReqLayer(me.Set, "SetRequest", decodeSetRequest)
144 LayerTypeGetRequest = mkReqLayer(me.Get, "GetRequest", decodeGetRequest)
145 LayerTypeGetAllAlarmsRequest = mkReqLayer(me.GetAllAlarms, "GetAllAlarmsRequest", decodeGetAllAlarmsRequest)
146 LayerTypeGetAllAlarmsNextRequest = mkReqLayer(me.GetAllAlarmsNext, "GetAllAlarmsNextRequest", decodeGetAllAlarmsNextRequest)
147 LayerTypeMibUploadRequest = mkReqLayer(me.MibUpload, "MibUploadRequest", decodeMibUploadRequest)
148 LayerTypeMibUploadNextRequest = mkReqLayer(me.MibUploadNext, "MibUploadNextRequest", decodeMibUploadNextRequest)
149 LayerTypeMibResetRequest = mkReqLayer(me.MibReset, "MibResetRequest", decodeMibResetRequest)
150 LayerTypeTestRequest = mkReqLayer(me.Test, "TestRequest", decodeTestRequest)
151 LayerTypeStartSoftwareDownloadRequest = mkReqLayer(me.StartSoftwareDownload, "StartSoftwareDownloadRequest", decodeStartSoftwareDownloadRequest)
Chip Boling6e27b352020-02-14 09:10:01 -0600152
153 // For Download section, AR=0 if not response expected, AR=1 if response expected (last section of a window)
Chip Boling610117d2021-09-09 11:24:34 -0500154 LayerTypeDownloadSectionRequest = mkLayer(me.DownloadSection, "DownloadSectionRequest", decodeDownloadSectionRequest)
155 LayerTypeDownloadSectionLastRequest = mkReqLayer(me.DownloadSection, "DownloadLastSectionRequest", decodeDownloadSectionRequest)
156 LayerTypeEndSoftwareDownloadRequest = mkReqLayer(me.EndSoftwareDownload, "EndSoftwareDownloadRequest", decodeEndSoftwareDownloadRequest)
157 LayerTypeActivateSoftwareRequest = mkReqLayer(me.ActivateSoftware, "ActivateSoftwareRequest", decodeActivateSoftwareRequest)
158 LayerTypeCommitSoftwareRequest = mkReqLayer(me.CommitSoftware, "CommitSoftwareRequest", decodeCommitSoftwareRequest)
159 LayerTypeSynchronizeTimeRequest = mkReqLayer(me.SynchronizeTime, "SynchronizeTimeRequest", decodeSynchronizeTimeRequest)
160 LayerTypeRebootRequest = mkReqLayer(me.Reboot, "RebootRequest", decodeRebootRequest)
161 LayerTypeGetNextRequest = mkReqLayer(me.GetNext, "GetNextRequest", decodeGetNextRequest)
162 LayerTypeGetCurrentDataRequest = mkReqLayer(me.GetCurrentData, "GetCurrentDataRequest", decodeGetCurrentDataRequest)
163 LayerTypeSetTableRequest = mkReqLayer(me.SetTable, "SetTableRequest", decodeSetTableRequest)
Chip Boling6e27b352020-02-14 09:10:01 -0600164
Chip Boling610117d2021-09-09 11:24:34 -0500165 LayerTypeCreateResponse = mkRespLayer(me.Create, "CreateResponse", decodeCreateResponse)
166 LayerTypeDeleteResponse = mkRespLayer(me.Delete, "DeleteResponse", decodeDeleteResponse)
167 LayerTypeSetResponse = mkRespLayer(me.Set, "SetResponse", decodeSetResponse)
168 LayerTypeGetResponse = mkRespLayer(me.Get, "GetResponse", decodeGetResponse)
169 LayerTypeGetAllAlarmsResponse = mkRespLayer(me.GetAllAlarms, "GetAllAlarmsResponse", decodeGetAllAlarmsResponse)
170 LayerTypeGetAllAlarmsNextResponse = mkRespLayer(me.GetAllAlarmsNext, "GetAllAlarmsNextResponse", decodeGetAllAlarmsNextResponse)
171 LayerTypeMibUploadResponse = mkRespLayer(me.MibUpload, "MibUploadResponse", decodeMibUploadResponse)
172 LayerTypeMibUploadNextResponse = mkRespLayer(me.MibUploadNext, "MibUploadNextResponse", decodeMibUploadNextResponse)
173 LayerTypeMibResetResponse = mkRespLayer(me.MibReset, "MibResetResponse", decodeMibResetResponse)
174 LayerTypeAlarmNotification = mkLayer(me.AlarmNotification, "AlarmNotification", decodeAlarmNotification)
175 LayerTypeAttributeValueChange = mkLayer(me.AttributeValueChange, "AttributeValueChange", decodeAttributeValueChange)
176 LayerTypeTestResponse = mkRespLayer(me.Test, "TestResponse", decodeTestResponse)
177 LayerTypeStartSoftwareDownloadResponse = mkRespLayer(me.StartSoftwareDownload, "StartSoftwareDownloadResponse", decodeStartSoftwareDownloadResponse)
178 LayerTypeDownloadSectionResponse = mkRespLayer(me.DownloadSection, "DownloadSectionResponse", decodeDownloadSectionResponse)
179 LayerTypeEndSoftwareDownloadResponse = mkRespLayer(me.EndSoftwareDownload, "EndSoftwareDownloadResponse", decodeEndSoftwareDownloadResponse)
180 LayerTypeActivateSoftwareResponse = mkRespLayer(me.ActivateSoftware, "ActivateSoftwareResponse", decodeActivateSoftwareResponse)
181 LayerTypeCommitSoftwareResponse = mkRespLayer(me.CommitSoftware, "CommitSoftwareResponse", decodeCommitSoftwareResponse)
182 LayerTypeSynchronizeTimeResponse = mkRespLayer(me.SynchronizeTime, "SynchronizeTimeResponse", decodeSynchronizeTimeResponse)
183 LayerTypeRebootResponse = mkRespLayer(me.Reboot, "RebootResponse", decodeRebootResponse)
184 LayerTypeGetNextResponse = mkRespLayer(me.GetNext, "GetNextResponse", decodeGetNextResponse)
185 LayerTypeTestResult = mkRespLayer(me.TestResult, "TestResult", decodeTestResult)
186 LayerTypeGetCurrentDataResponse = mkRespLayer(me.GetCurrentData, "GetCurrentDataResponse", decodeGetCurrentDataResponse)
187 LayerTypeSetTableResponse = mkRespLayer(me.SetTable, "SetTableResponse", decodeSetTableResponse)
Chip Boling6e27b352020-02-14 09:10:01 -0600188
Chip Boling157c9b92021-04-21 09:58:36 -0500189 // Extended message set support
190
Chip Boling610117d2021-09-09 11:24:34 -0500191 LayerTypeCreateRequestExtended = mkReqLayer(me.Create|me.ExtendedOffset, "CreateRequest-Ext", decodeCreateRequestExtended)
192 LayerTypeDeleteRequestExtended = mkReqLayer(me.Delete|me.ExtendedOffset, "DeleteRequest-Ext", decodeDeleteRequestExtended)
193 LayerTypeSetRequestExtended = mkReqLayer(me.Set|me.ExtendedOffset, "SetRequest-Ext", decodeSetRequestExtended)
194 LayerTypeGetRequestExtended = mkReqLayer(me.Get|me.ExtendedOffset, "GetRequest-Ext", decodeGetRequestExtended)
195 LayerTypeGetNextRequestExtended = mkReqLayer(me.GetNext|me.ExtendedOffset, "GetNextRequest-Ext", decodeGetNextRequestExtended)
196 LayerTypeMibUploadRequestExtended = mkReqLayer(me.MibUpload|me.ExtendedOffset, "MibUploadRequest-Ext", decodeMibUploadRequestExtended)
197 LayerTypeMibUploadNextRequestExtended = mkReqLayer(me.MibUploadNext|me.ExtendedOffset, "MibUploadNextRequest-Ext", decodeMibUploadNextRequestExtended)
198 LayerTypeMibResetRequestExtended = mkReqLayer(me.MibReset|me.ExtendedOffset, "MibResetRequest-Ext", decodeMibResetRequestExtended)
199 LayerTypeStartSoftwareDownloadRequestExtended = mkReqLayer(me.StartSoftwareDownload|me.ExtendedOffset, "StartSoftwareDownloadRequest-Ext", decodeStartSoftwareDownloadRequestExtended)
200 LayerTypeDownloadSectionRequestExtended = mkLayer(me.DownloadSection|me.ExtendedOffset, "DownloadSectionRequest-Ext", decodeDownloadSectionRequestExtended)
201 LayerTypeDownloadSectionLastRequestExtended = mkReqLayer(me.DownloadSection|me.ExtendedOffset, "DownloadLastSectionRequest-Ext", decodeDownloadSectionRequestExtended)
202 LayerTypeEndSoftwareDownloadRequestExtended = mkReqLayer(me.EndSoftwareDownload|me.ExtendedOffset, "EndSoftwareDownloadRequest-Ext", decodeEndSoftwareDownloadRequestExtended)
203 LayerTypeActivateSoftwareRequestExtended = mkReqLayer(me.ActivateSoftware|me.ExtendedOffset, "ActivateSoftwareRequest-Ext", decodeActivateSoftwareRequestExtended)
204 LayerTypeCommitSoftwareRequestExtended = mkReqLayer(me.CommitSoftware|me.ExtendedOffset, "CommitSoftwareRequest-Ext", decodeCommitSoftwareRequestExtended)
205 LayerTypeSynchronizeTimeRequestExtended = mkReqLayer(me.SynchronizeTime|me.ExtendedOffset, "SynchronizeTimeRequest-Ext", decodeSynchronizeTimeRequestExtended)
206 LayerTypeRebootRequestExtended = mkReqLayer(me.Reboot|me.ExtendedOffset, "RebootRequest-Ext", decodeRebootRequestExtended)
207 LayerTypeGetCurrentDataRequestExtended = mkReqLayer(me.GetCurrentData|me.ExtendedOffset, "GetCurrentDataRequest-Ext", decodeGetCurrentDataRequestExtended)
208 LayerTypeSetTableRequestExtended = mkReqLayer(me.SetTable|me.ExtendedOffset, "SetTableRequest-Ext", decodeSetTableRequestExtended)
209 LayerTypeGetAllAlarmsRequestExtended = mkReqLayer(me.GetAllAlarms|me.ExtendedOffset, "GetAllAlarmsRequest-Ext", decodeGetAllAlarmsRequestExtended)
210 LayerTypeGetAllAlarmsNextRequestExtended = mkReqLayer(me.GetAllAlarmsNext|me.ExtendedOffset, "GetAllAlarmsNextRequest-Ext", decodeGetAllAlarmsNextRequestExtended)
Chip Boling157c9b92021-04-21 09:58:36 -0500211
Chip Boling610117d2021-09-09 11:24:34 -0500212 LayerTypeCreateResponseExtended = mkRespLayer(me.Create|me.ExtendedOffset, "CreateResponse-Ext", decodeCreateResponseExtended)
213 LayerTypeDeleteResponseExtended = mkRespLayer(me.Delete|me.ExtendedOffset, "DeleteResponse-Ext", decodeDeleteResponseExtended)
214 LayerTypeSetResponseExtended = mkRespLayer(me.Set|me.ExtendedOffset, "SetResponse-Ext", decodeSetResponseExtended)
215 LayerTypeGetResponseExtended = mkRespLayer(me.Get|me.ExtendedOffset, "GetResponse-Ext", decodeGetResponseExtended)
216 LayerTypeGetNextResponseExtended = mkRespLayer(me.GetNext|me.ExtendedOffset, "GetNextResponse-Ext", decodeGetNextResponseExtended)
217 LayerTypeMibUploadResponseExtended = mkRespLayer(me.MibUpload|me.ExtendedOffset, "MibUploadResponse-Ext", decodeMibUploadResponseExtended)
218 LayerTypeMibUploadNextResponseExtended = mkRespLayer(me.MibUploadNext|me.ExtendedOffset, "MibUploadNextResponse-Ext", decodeMibUploadNextResponseExtended)
219 LayerTypeMibResetResponseExtended = mkRespLayer(me.MibReset|me.ExtendedOffset, "MibResetResponse-Ext", decodeMibResetResponseExtended)
220 LayerTypeStartSoftwareDownloadResponseExtended = mkRespLayer(me.StartSoftwareDownload|me.ExtendedOffset, "StartSoftwareDownloadResponse-Ext", decodeStartSoftwareDownloadResponseExtended)
221 LayerTypeDownloadSectionResponseExtended = mkRespLayer(me.DownloadSection|me.ExtendedOffset, "DownloadSectionResponse-Ext", decodeDownloadSectionResponseExtended)
222 LayerTypeEndSoftwareDownloadResponseExtended = mkRespLayer(me.EndSoftwareDownload|me.ExtendedOffset, "EndSoftwareDownloadResponse-Ext", decodeEndSoftwareDownloadResponseExtended)
223 LayerTypeActivateSoftwareResponseExtended = mkRespLayer(me.ActivateSoftware|me.ExtendedOffset, "ActivateSoftwareResponse-Ext", decodeActivateSoftwareResponseExtended)
224 LayerTypeCommitSoftwareResponseExtended = mkRespLayer(me.CommitSoftware|me.ExtendedOffset, "CommitSoftwareResponse-Ext", decodeCommitSoftwareResponseExtended)
225 LayerTypeSynchronizeTimeResponseExtended = mkRespLayer(me.SynchronizeTime|me.ExtendedOffset, "SynchronizeTimeResponse-Ext", decodeSynchronizeTimeResponseExtended)
226 LayerTypeRebootResponseExtended = mkRespLayer(me.Reboot|me.ExtendedOffset, "RebootResponse-Ext", decodeRebootResponseExtended)
227 LayerTypeGetCurrentDataResponseExtended = mkRespLayer(me.GetCurrentData|me.ExtendedOffset, "GetCurrentDataResponse-Ext", decodeGetCurrentDataResponseExtended)
228 LayerTypeSetTableResponseExtended = mkRespLayer(me.SetTable|me.ExtendedOffset, "SetTableResponse-Ext", decodeSetTableResponseExtended)
229 LayerTypeGetAllAlarmsResponseExtended = mkRespLayer(me.GetAllAlarms|me.ExtendedOffset, "GetAllAlarmsResponse-Ext", decodeGetAllAlarmsResponseExtended)
230 LayerTypeGetAllAlarmsNextResponseExtended = mkRespLayer(me.GetAllAlarmsNext|me.ExtendedOffset, "GetAllAlarmsNextResponse-Ext", decodeGetAllAlarmsNextResponseExtended)
231
232 LayerTypeAlarmNotificationExtended = mkLayer(me.AlarmNotification|me.ExtendedOffset, "AlarmNotification-Ext", decodeAlarmNotificationExtended)
233 LayerTypeAttributeValueChangeExtended = mkLayer(me.AttributeValueChange|me.ExtendedOffset, "AttributeValueChange-Ext", decodeAttributeValueChangeExtended)
234 LayerTypeTestResultExtended = mkLayer(me.TestResult|me.ExtendedOffset, "TestResult-Ext", decodeTestResultExtended)
Chip Bolingc15f61d2021-05-13 09:07:17 -0500235
Chip Boling6e27b352020-02-14 09:10:01 -0600236 // Map message_type and action to layer
237 nextLayerMapping = make(map[MessageType]gopacket.LayerType)
238
239 nextLayerMapping[CreateRequestType] = LayerTypeCreateRequest
240 nextLayerMapping[DeleteRequestType] = LayerTypeDeleteRequest
241 nextLayerMapping[SetRequestType] = LayerTypeSetRequest
242 nextLayerMapping[GetRequestType] = LayerTypeGetRequest
243 nextLayerMapping[GetAllAlarmsRequestType] = LayerTypeGetAllAlarmsRequest
244 nextLayerMapping[GetAllAlarmsNextRequestType] = LayerTypeGetAllAlarmsNextRequest
245 nextLayerMapping[MibUploadRequestType] = LayerTypeMibUploadRequest
246 nextLayerMapping[MibUploadNextRequestType] = LayerTypeMibUploadNextRequest
247 nextLayerMapping[MibResetRequestType] = LayerTypeMibResetRequest
248 nextLayerMapping[TestRequestType] = LayerTypeTestRequest
249 nextLayerMapping[StartSoftwareDownloadRequestType] = LayerTypeStartSoftwareDownloadRequest
250 nextLayerMapping[DownloadSectionRequestType] = LayerTypeDownloadSectionRequest
Chip Boling610117d2021-09-09 11:24:34 -0500251 nextLayerMapping[DownloadSectionRequestWithResponseType] = LayerTypeDownloadSectionLastRequest
Chip Boling6e27b352020-02-14 09:10:01 -0600252 nextLayerMapping[EndSoftwareDownloadRequestType] = LayerTypeEndSoftwareDownloadRequest
253 nextLayerMapping[ActivateSoftwareRequestType] = LayerTypeActivateSoftwareRequest
254 nextLayerMapping[CommitSoftwareRequestType] = LayerTypeCommitSoftwareRequest
255 nextLayerMapping[SynchronizeTimeRequestType] = LayerTypeSynchronizeTimeRequest
256 nextLayerMapping[RebootRequestType] = LayerTypeRebootRequest
257 nextLayerMapping[GetNextRequestType] = LayerTypeGetNextRequest
258 nextLayerMapping[GetCurrentDataRequestType] = LayerTypeGetCurrentDataRequest
Chip Boling6e27b352020-02-14 09:10:01 -0600259
260 nextLayerMapping[CreateResponseType] = LayerTypeCreateResponse
261 nextLayerMapping[DeleteResponseType] = LayerTypeDeleteResponse
262 nextLayerMapping[SetResponseType] = LayerTypeSetResponse
263 nextLayerMapping[GetResponseType] = LayerTypeGetResponse
264 nextLayerMapping[GetAllAlarmsResponseType] = LayerTypeGetAllAlarmsResponse
265 nextLayerMapping[GetAllAlarmsNextResponseType] = LayerTypeGetAllAlarmsNextResponse
266 nextLayerMapping[MibUploadResponseType] = LayerTypeMibUploadResponse
267 nextLayerMapping[MibUploadNextResponseType] = LayerTypeMibUploadNextResponse
268 nextLayerMapping[MibResetResponseType] = LayerTypeMibResetResponse
269 nextLayerMapping[TestResponseType] = LayerTypeTestResponse
270 nextLayerMapping[StartSoftwareDownloadResponseType] = LayerTypeStartSoftwareDownloadResponse
271 nextLayerMapping[DownloadSectionResponseType] = LayerTypeDownloadSectionResponse
272 nextLayerMapping[EndSoftwareDownloadResponseType] = LayerTypeEndSoftwareDownloadResponse
273 nextLayerMapping[ActivateSoftwareResponseType] = LayerTypeActivateSoftwareResponse
274 nextLayerMapping[CommitSoftwareResponseType] = LayerTypeCommitSoftwareResponse
275 nextLayerMapping[SynchronizeTimeResponseType] = LayerTypeSynchronizeTimeResponse
276 nextLayerMapping[RebootResponseType] = LayerTypeRebootResponse
277 nextLayerMapping[GetNextResponseType] = LayerTypeGetNextResponse
278 nextLayerMapping[GetCurrentDataResponseType] = LayerTypeGetCurrentDataResponse
Chip Boling6e27b352020-02-14 09:10:01 -0600279
280 nextLayerMapping[AttributeValueChangeType] = LayerTypeAttributeValueChange
281 nextLayerMapping[AlarmNotificationType] = LayerTypeAlarmNotification
282 nextLayerMapping[TestResultType] = LayerTypeTestResult
Chip Boling157c9b92021-04-21 09:58:36 -0500283
Chip Boling610117d2021-09-09 11:24:34 -0500284 nextLayerMapping[SetTableRequestType] = LayerTypeSetTableRequest
285 nextLayerMapping[SetTableResponseType] = LayerTypeSetTableResponse
286
Chip Boling157c9b92021-04-21 09:58:36 -0500287 // Extended message support
Chip Boling610117d2021-09-09 11:24:34 -0500288 nextLayerMapping[CreateRequestType+ExtendedTypeDecodeOffset] = LayerTypeCreateRequestExtended
289 nextLayerMapping[CreateResponseType+ExtendedTypeDecodeOffset] = LayerTypeCreateResponseExtended
290 nextLayerMapping[DeleteResponseType+ExtendedTypeDecodeOffset] = LayerTypeDeleteResponseExtended
291 nextLayerMapping[DeleteRequestType+ExtendedTypeDecodeOffset] = LayerTypeDeleteRequestExtended
292 nextLayerMapping[SetRequestType+ExtendedTypeDecodeOffset] = LayerTypeSetRequestExtended
293 nextLayerMapping[SetResponseType+ExtendedTypeDecodeOffset] = LayerTypeSetResponseExtended
Chip Boling157c9b92021-04-21 09:58:36 -0500294 nextLayerMapping[GetRequestType+ExtendedTypeDecodeOffset] = LayerTypeGetRequestExtended
295 nextLayerMapping[GetResponseType+ExtendedTypeDecodeOffset] = LayerTypeGetResponseExtended
Chip Boling610117d2021-09-09 11:24:34 -0500296 nextLayerMapping[GetNextRequestType+ExtendedTypeDecodeOffset] = LayerTypeGetNextRequestExtended
297 nextLayerMapping[GetNextResponseType+ExtendedTypeDecodeOffset] = LayerTypeGetNextResponseExtended
Chip Boling00a30d22021-05-04 13:31:52 -0500298
Chip Boling610117d2021-09-09 11:24:34 -0500299 nextLayerMapping[MibUploadRequestType+ExtendedTypeDecodeOffset] = LayerTypeMibUploadRequestExtended
300 nextLayerMapping[MibUploadResponseType+ExtendedTypeDecodeOffset] = LayerTypeMibUploadResponseExtended
301 nextLayerMapping[MibUploadNextRequestType+ExtendedTypeDecodeOffset] = LayerTypeMibUploadNextRequestExtended
302 nextLayerMapping[MibUploadNextResponseType+ExtendedTypeDecodeOffset] = LayerTypeMibUploadNextResponseExtended
303
304 nextLayerMapping[MibResetRequestType+ExtendedTypeDecodeOffset] = LayerTypeMibResetRequestExtended
305 nextLayerMapping[MibResetResponseType+ExtendedTypeDecodeOffset] = LayerTypeMibResetResponseExtended
306 nextLayerMapping[SynchronizeTimeRequestType+ExtendedTypeDecodeOffset] = LayerTypeSynchronizeTimeRequestExtended
307 nextLayerMapping[SynchronizeTimeResponseType+ExtendedTypeDecodeOffset] = LayerTypeSynchronizeTimeResponseExtended
308 nextLayerMapping[RebootRequestType+ExtendedTypeDecodeOffset] = LayerTypeRebootRequestExtended
309 nextLayerMapping[RebootResponseType+ExtendedTypeDecodeOffset] = LayerTypeRebootResponseExtended
310 nextLayerMapping[GetCurrentDataRequestType+ExtendedTypeDecodeOffset] = LayerTypeGetCurrentDataRequestExtended
311 nextLayerMapping[GetCurrentDataResponseType+ExtendedTypeDecodeOffset] = LayerTypeGetCurrentDataResponseExtended
312
313 nextLayerMapping[SetTableRequestType+ExtendedTypeDecodeOffset] = LayerTypeSetTableRequestExtended
314 nextLayerMapping[SetTableResponseType+ExtendedTypeDecodeOffset] = LayerTypeSetTableResponseExtended
315
316 nextLayerMapping[GetAllAlarmsRequestType+ExtendedTypeDecodeOffset] = LayerTypeGetAllAlarmsRequestExtended
317 nextLayerMapping[GetAllAlarmsNextRequestType+ExtendedTypeDecodeOffset] = LayerTypeGetAllAlarmsNextRequestExtended
318 nextLayerMapping[GetAllAlarmsResponseType+ExtendedTypeDecodeOffset] = LayerTypeGetAllAlarmsResponseExtended
319 nextLayerMapping[GetAllAlarmsNextResponseType+ExtendedTypeDecodeOffset] = LayerTypeGetAllAlarmsNextResponseExtended
320
321 nextLayerMapping[StartSoftwareDownloadRequestType+ExtendedTypeDecodeOffset] = LayerTypeStartSoftwareDownloadRequestExtended
322 nextLayerMapping[StartSoftwareDownloadResponseType+ExtendedTypeDecodeOffset] = LayerTypeStartSoftwareDownloadResponseExtended
Chip Boling00a30d22021-05-04 13:31:52 -0500323 // For Download section, AR=0 if not response expected, AR=1 if response expected (last section of a window)
324 nextLayerMapping[DownloadSectionRequestType+ExtendedTypeDecodeOffset] = LayerTypeDownloadSectionRequestExtended
325 nextLayerMapping[DownloadSectionRequestWithResponseType+ExtendedTypeDecodeOffset] = LayerTypeDownloadSectionLastRequestExtended
326 nextLayerMapping[DownloadSectionResponseType+ExtendedTypeDecodeOffset] = LayerTypeDownloadSectionResponseExtended
Chip Bolingc15f61d2021-05-13 09:07:17 -0500327
Chip Boling610117d2021-09-09 11:24:34 -0500328 nextLayerMapping[EndSoftwareDownloadRequestType+ExtendedTypeDecodeOffset] = LayerTypeEndSoftwareDownloadRequestExtended
329 nextLayerMapping[EndSoftwareDownloadResponseType+ExtendedTypeDecodeOffset] = LayerTypeEndSoftwareDownloadResponseExtended
330
331 nextLayerMapping[ActivateSoftwareRequestType+ExtendedTypeDecodeOffset] = LayerTypeActivateSoftwareRequestExtended
332 nextLayerMapping[ActivateSoftwareResponseType+ExtendedTypeDecodeOffset] = LayerTypeActivateSoftwareResponseExtended
333
334 nextLayerMapping[CommitSoftwareRequestType+ExtendedTypeDecodeOffset] = LayerTypeCommitSoftwareRequestExtended
335 nextLayerMapping[CommitSoftwareResponseType+ExtendedTypeDecodeOffset] = LayerTypeCommitSoftwareResponseExtended
336
Chip Bolingc15f61d2021-05-13 09:07:17 -0500337 nextLayerMapping[AlarmNotificationType+ExtendedTypeDecodeOffset] = LayerTypeAlarmNotificationExtended
338 nextLayerMapping[AttributeValueChangeType+ExtendedTypeDecodeOffset] = LayerTypeAttributeValueChangeExtended
339 nextLayerMapping[TestResultType+ExtendedTypeDecodeOffset] = LayerTypeTestResultExtended
Chip Boling934e1052021-09-27 15:12:06 -0500340
341 ////////////////////////////////////////////////////////////////////////
342 // The following are custom layers used during relaxed decode. They are defined
343 // as layers but will be appended to decoded packets as an error layer. The DecodeFunc
344 // is actually never called and does not have to be added to the nextLayerMapping
345 var decode gopacket.DecodeFunc
346
347 decode = decodeUnknownAttributes
348 LayerTypeUnknownAttributes = gopacket.RegisterLayerType(2000,
349 gopacket.LayerTypeMetadata{Name: "Unknown Attributes", Decoder: decode})
Chip Boling6e27b352020-02-14 09:10:01 -0600350}
351
Chip Boling157c9b92021-04-21 09:58:36 -0500352func MsgTypeToNextLayer(mt MessageType, isExtended bool) (gopacket.LayerType, error) {
353 if isExtended {
354 mt |= ExtendedTypeDecodeOffset
355 }
Chip Boling6e27b352020-02-14 09:10:01 -0600356 nextLayer, ok := nextLayerMapping[mt]
357 if ok {
358 return nextLayer, nil
359 }
Chip Boling157c9b92021-04-21 09:58:36 -0500360 return gopacket.LayerTypeZero, errors.New("unknown/unsupported message type")
Chip Boling6e27b352020-02-14 09:10:01 -0600361}