Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018 - present. Boling Consulting Solutions (bcsw.net) |
Andrea Campanella | 7167ebb | 2020-02-24 09:56:38 +0100 | [diff] [blame] | 3 | * Copyright 2020-present Open Networking Foundation |
| 4 | |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 5 | * 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 Campanella | 7167ebb | 2020-02-24 09:56:38 +0100 | [diff] [blame] | 8 | |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
Andrea Campanella | 7167ebb | 2020-02-24 09:56:38 +0100 | [diff] [blame] | 10 | |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 11 | * 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 Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 16 | */ |
| 17 | |
| 18 | package omci |
| 19 | |
| 20 | import ( |
| 21 | "errors" |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 22 | "github.com/google/gopacket" |
David K. Bainbridge | adf422d | 2021-04-09 16:06:41 +0000 | [diff] [blame] | 23 | me "github.com/opencord/omci-lib-go/generated" |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 24 | ) |
| 25 | |
| 26 | var nextLayerMapping map[MessageType]gopacket.LayerType |
| 27 | |
| 28 | var ( |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 29 | // Baseline Message Types |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 30 | LayerTypeCreateRequest gopacket.LayerType |
| 31 | LayerTypeDeleteRequest gopacket.LayerType |
| 32 | LayerTypeSetRequest gopacket.LayerType |
| 33 | LayerTypeGetRequest gopacket.LayerType |
| 34 | LayerTypeGetAllAlarmsRequest gopacket.LayerType |
| 35 | LayerTypeGetAllAlarmsNextRequest gopacket.LayerType |
| 36 | LayerTypeMibUploadRequest gopacket.LayerType |
| 37 | LayerTypeMibUploadNextRequest gopacket.LayerType |
| 38 | LayerTypeMibResetRequest gopacket.LayerType |
| 39 | LayerTypeTestRequest gopacket.LayerType |
| 40 | LayerTypeStartSoftwareDownloadRequest gopacket.LayerType |
| 41 | LayerTypeDownloadSectionRequest gopacket.LayerType |
| 42 | LayerTypeDownloadSectionLastRequest gopacket.LayerType |
| 43 | LayerTypeEndSoftwareDownloadRequest gopacket.LayerType |
| 44 | LayerTypeActivateSoftwareRequest gopacket.LayerType |
| 45 | LayerTypeCommitSoftwareRequest gopacket.LayerType |
| 46 | LayerTypeSynchronizeTimeRequest gopacket.LayerType |
| 47 | LayerTypeRebootRequest gopacket.LayerType |
| 48 | LayerTypeGetNextRequest gopacket.LayerType |
| 49 | LayerTypeGetCurrentDataRequest gopacket.LayerType |
| 50 | LayerTypeSetTableRequest gopacket.LayerType |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 51 | |
Chip Boling | c15f61d | 2021-05-13 09:07:17 -0500 | [diff] [blame^] | 52 | // Extended Request Message Types |
Chip Boling | 00a30d2 | 2021-05-04 13:31:52 -0500 | [diff] [blame] | 53 | LayerTypeGetRequestExtended gopacket.LayerType |
| 54 | LayerTypeDownloadSectionRequestExtended gopacket.LayerType |
| 55 | LayerTypeDownloadSectionLastRequestExtended gopacket.LayerType |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 56 | ) |
| 57 | var ( |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 58 | // Baseline Message Types |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 59 | LayerTypeCreateResponse gopacket.LayerType |
| 60 | LayerTypeDeleteResponse gopacket.LayerType |
| 61 | LayerTypeSetResponse gopacket.LayerType |
| 62 | LayerTypeGetResponse gopacket.LayerType |
| 63 | LayerTypeGetAllAlarmsResponse gopacket.LayerType |
| 64 | LayerTypeGetAllAlarmsNextResponse gopacket.LayerType |
| 65 | LayerTypeMibUploadResponse gopacket.LayerType |
| 66 | LayerTypeMibUploadNextResponse gopacket.LayerType |
| 67 | LayerTypeMibResetResponse gopacket.LayerType |
| 68 | LayerTypeAlarmNotification gopacket.LayerType |
| 69 | LayerTypeAttributeValueChange gopacket.LayerType |
| 70 | LayerTypeTestResponse gopacket.LayerType |
| 71 | LayerTypeStartSoftwareDownloadResponse gopacket.LayerType |
| 72 | LayerTypeDownloadSectionResponse gopacket.LayerType |
| 73 | LayerTypeEndSoftwareDownloadResponse gopacket.LayerType |
| 74 | LayerTypeActivateSoftwareResponse gopacket.LayerType |
| 75 | LayerTypeCommitSoftwareResponse gopacket.LayerType |
| 76 | LayerTypeSynchronizeTimeResponse gopacket.LayerType |
| 77 | LayerTypeRebootResponse gopacket.LayerType |
| 78 | LayerTypeGetNextResponse gopacket.LayerType |
| 79 | LayerTypeTestResult gopacket.LayerType |
| 80 | LayerTypeGetCurrentDataResponse gopacket.LayerType |
| 81 | LayerTypeSetTableResponse gopacket.LayerType |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 82 | |
Chip Boling | c15f61d | 2021-05-13 09:07:17 -0500 | [diff] [blame^] | 83 | // Extended Response/Notification Message Types |
Chip Boling | 00a30d2 | 2021-05-04 13:31:52 -0500 | [diff] [blame] | 84 | LayerTypeGetResponseExtended gopacket.LayerType |
| 85 | LayerTypeDownloadSectionResponseExtended gopacket.LayerType |
Chip Boling | c15f61d | 2021-05-13 09:07:17 -0500 | [diff] [blame^] | 86 | LayerTypeAlarmNotificationExtended gopacket.LayerType |
| 87 | LayerTypeAttributeValueChangeExtended gopacket.LayerType |
| 88 | LayerTypeTestResultExtended gopacket.LayerType |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 89 | ) |
| 90 | |
| 91 | func mkReqLayer(mt me.MsgType, mts string, decode gopacket.DecodeFunc) gopacket.LayerType { |
| 92 | return gopacket.RegisterLayerType(1000+(int(mt)|int(me.AR)), |
| 93 | gopacket.LayerTypeMetadata{Name: mts, Decoder: decode}) |
| 94 | } |
| 95 | |
| 96 | func mkRespLayer(mt me.MsgType, mts string, decode gopacket.DecodeFunc) gopacket.LayerType { |
| 97 | return gopacket.RegisterLayerType(1000+(int(mt)|int(me.AK)), |
| 98 | gopacket.LayerTypeMetadata{Name: mts, Decoder: decode}) |
| 99 | } |
| 100 | |
| 101 | func mkLayer(mt me.MsgType, mts string, decode gopacket.DecodeFunc) gopacket.LayerType { |
| 102 | return gopacket.RegisterLayerType(1000+(int(mt)), |
| 103 | gopacket.LayerTypeMetadata{Name: mts, Decoder: decode}) |
| 104 | } |
| 105 | |
| 106 | func init() { |
| 107 | // Create layers for message_type & action |
| 108 | LayerTypeCreateRequest = mkReqLayer(me.Create, "CreateRequest", gopacket.DecodeFunc(decodeCreateRequest)) |
| 109 | LayerTypeDeleteRequest = mkReqLayer(me.Delete, "DeleteRequest", gopacket.DecodeFunc(decodeDeleteRequest)) |
| 110 | LayerTypeSetRequest = mkReqLayer(me.Set, "SetRequest", gopacket.DecodeFunc(decodeSetRequest)) |
| 111 | LayerTypeGetRequest = mkReqLayer(me.Get, "GetRequest", gopacket.DecodeFunc(decodeGetRequest)) |
| 112 | LayerTypeGetAllAlarmsRequest = mkReqLayer(me.GetAllAlarms, "GetAllAlarmsRequest", gopacket.DecodeFunc(decodeGetAllAlarmsRequest)) |
| 113 | LayerTypeGetAllAlarmsNextRequest = mkReqLayer(me.GetAllAlarmsNext, "GetAllAlarmsNextRequest", gopacket.DecodeFunc(decodeGetAllAlarmsNextRequest)) |
| 114 | LayerTypeMibUploadRequest = mkReqLayer(me.MibUpload, "MibUploadRequest", gopacket.DecodeFunc(decodeMibUploadRequest)) |
| 115 | LayerTypeMibUploadNextRequest = mkReqLayer(me.MibUploadNext, "MibUploadNextRequest", gopacket.DecodeFunc(decodeMibUploadNextRequest)) |
| 116 | LayerTypeMibResetRequest = mkReqLayer(me.MibReset, "MibResetRequest", gopacket.DecodeFunc(decodeMibResetRequest)) |
| 117 | LayerTypeTestRequest = mkReqLayer(me.Test, "TestRequest", gopacket.DecodeFunc(decodeTestRequest)) |
| 118 | LayerTypeStartSoftwareDownloadRequest = mkReqLayer(me.StartSoftwareDownload, "StartSoftwareDownloadRequest", gopacket.DecodeFunc(decodeStartSoftwareDownloadRequest)) |
| 119 | |
| 120 | // For Download section, AR=0 if not response expected, AR=1 if response expected (last section of a window) |
| 121 | LayerTypeDownloadSectionRequest = mkLayer(me.DownloadSection, "DownloadSectionRequest", gopacket.DecodeFunc(decodeDownloadSectionRequest)) |
| 122 | LayerTypeDownloadSectionLastRequest = mkReqLayer(me.DownloadSection, "DownloadLastSectionRequest", gopacket.DecodeFunc(decodeDownloadSectionRequest)) |
| 123 | LayerTypeEndSoftwareDownloadRequest = mkReqLayer(me.EndSoftwareDownload, "EndSoftwareDownloadRequest", gopacket.DecodeFunc(decodeEndSoftwareDownloadRequest)) |
| 124 | LayerTypeActivateSoftwareRequest = mkReqLayer(me.ActivateSoftware, "ActivateSoftwareRequest", gopacket.DecodeFunc(decodeActivateSoftwareRequest)) |
| 125 | LayerTypeCommitSoftwareRequest = mkReqLayer(me.CommitSoftware, "CommitSoftwareRequest", gopacket.DecodeFunc(decodeCommitSoftwareRequest)) |
| 126 | LayerTypeSynchronizeTimeRequest = mkReqLayer(me.SynchronizeTime, "SynchronizeTimeRequest", gopacket.DecodeFunc(decodeSynchronizeTimeRequest)) |
| 127 | LayerTypeRebootRequest = mkReqLayer(me.Reboot, "RebootRequest", gopacket.DecodeFunc(decodeRebootRequest)) |
| 128 | LayerTypeGetNextRequest = mkReqLayer(me.GetNext, "GetNextRequest", gopacket.DecodeFunc(decodeGetNextRequest)) |
| 129 | LayerTypeGetCurrentDataRequest = mkReqLayer(me.GetCurrentData, "GetCurrentDataRequest", gopacket.DecodeFunc(decodeGetCurrentDataRequest)) |
| 130 | LayerTypeSetTableRequest = mkReqLayer(me.SetTable, "SetTableRequest", gopacket.DecodeFunc(decodeSetTableRequest)) |
| 131 | |
| 132 | LayerTypeCreateResponse = mkRespLayer(me.Create, "CreateResponse", gopacket.DecodeFunc(decodeCreateResponse)) |
| 133 | LayerTypeDeleteResponse = mkRespLayer(me.Delete, "DeleteResponse", gopacket.DecodeFunc(decodeDeleteResponse)) |
| 134 | LayerTypeSetResponse = mkRespLayer(me.Set, "SetResponse", gopacket.DecodeFunc(decodeSetResponse)) |
| 135 | LayerTypeGetResponse = mkRespLayer(me.Get, "GetResponse", gopacket.DecodeFunc(decodeGetResponse)) |
| 136 | LayerTypeGetAllAlarmsResponse = mkRespLayer(me.GetAllAlarms, "GetAllAlarmsResponse", gopacket.DecodeFunc(decodeGetAllAlarmsResponse)) |
| 137 | LayerTypeGetAllAlarmsNextResponse = mkRespLayer(me.GetAllAlarmsNext, "GetAllAlarmsNextResponse", gopacket.DecodeFunc(decodeGetAllAlarmsNextResponse)) |
| 138 | LayerTypeMibUploadResponse = mkRespLayer(me.MibUpload, "MibUploadResponse", gopacket.DecodeFunc(decodeMibUploadResponse)) |
| 139 | LayerTypeMibUploadNextResponse = mkRespLayer(me.MibUploadNext, "MibUploadNextResponse", gopacket.DecodeFunc(decodeMibUploadNextResponse)) |
| 140 | LayerTypeMibResetResponse = mkRespLayer(me.MibReset, "MibResetResponse", gopacket.DecodeFunc(decodeMibResetResponse)) |
| 141 | LayerTypeAlarmNotification = mkLayer(me.AlarmNotification, "AlarmNotification", gopacket.DecodeFunc(decodeAlarmNotification)) |
| 142 | LayerTypeAttributeValueChange = mkLayer(me.AttributeValueChange, "AttributeValueChange", gopacket.DecodeFunc(decodeAttributeValueChange)) |
| 143 | LayerTypeTestResponse = mkRespLayer(me.Test, "TestResponse", gopacket.DecodeFunc(decodeTestResponse)) |
| 144 | LayerTypeStartSoftwareDownloadResponse = mkRespLayer(me.StartSoftwareDownload, "StartSoftwareDownloadResponse", gopacket.DecodeFunc(decodeStartSoftwareDownloadResponse)) |
| 145 | LayerTypeDownloadSectionResponse = mkRespLayer(me.DownloadSection, "DownloadSectionResponse", gopacket.DecodeFunc(decodeDownloadSectionResponse)) |
| 146 | LayerTypeEndSoftwareDownloadResponse = mkRespLayer(me.EndSoftwareDownload, "EndSoftwareDownloadResponse", gopacket.DecodeFunc(decodeEndSoftwareDownloadResponse)) |
| 147 | LayerTypeActivateSoftwareResponse = mkRespLayer(me.ActivateSoftware, "ActivateSoftwareResponse", gopacket.DecodeFunc(decodeActivateSoftwareResponse)) |
| 148 | LayerTypeCommitSoftwareResponse = mkRespLayer(me.CommitSoftware, "CommitSoftwareResponse", gopacket.DecodeFunc(decodeCommitSoftwareResponse)) |
| 149 | LayerTypeSynchronizeTimeResponse = mkRespLayer(me.SynchronizeTime, "SynchronizeTimeResponse", gopacket.DecodeFunc(decodeSynchronizeTimeResponse)) |
| 150 | LayerTypeRebootResponse = mkRespLayer(me.Reboot, "RebootResponse", gopacket.DecodeFunc(decodeRebootResponse)) |
| 151 | LayerTypeGetNextResponse = mkRespLayer(me.GetNext, "GetNextResponse", gopacket.DecodeFunc(decodeGetNextResponse)) |
| 152 | LayerTypeTestResult = mkRespLayer(me.TestResult, "TestResult", gopacket.DecodeFunc(decodeTestResult)) |
| 153 | LayerTypeGetCurrentDataResponse = mkRespLayer(me.GetCurrentData, "GetCurrentDataResponse", gopacket.DecodeFunc(decodeGetCurrentDataResponse)) |
| 154 | LayerTypeSetTableResponse = mkRespLayer(me.SetTable, "SetTableResponse", gopacket.DecodeFunc(decodeSetTableResponse)) |
| 155 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 156 | // Extended message set support |
| 157 | |
| 158 | LayerTypeGetRequestExtended = mkReqLayer(me.Get|me.ExtendedOffset, "GetRequest-Ext", gopacket.DecodeFunc(decodeGetRequestExtended)) |
| 159 | LayerTypeGetResponseExtended = mkRespLayer(me.Get|me.ExtendedOffset, "GetResponse-Ext", gopacket.DecodeFunc(decodeGetResponseExtended)) |
Chip Boling | 00a30d2 | 2021-05-04 13:31:52 -0500 | [diff] [blame] | 160 | LayerTypeDownloadSectionRequestExtended = mkLayer(me.DownloadSection|me.ExtendedOffset, "DownloadSectionRequest-Ext", gopacket.DecodeFunc(decodeDownloadSectionRequestExtended)) |
| 161 | LayerTypeDownloadSectionLastRequestExtended = mkReqLayer(me.DownloadSection|me.ExtendedOffset, "DownloadLastSectionRequest-Ext", gopacket.DecodeFunc(decodeDownloadSectionRequestExtended)) |
| 162 | LayerTypeDownloadSectionResponseExtended = mkRespLayer(me.DownloadSection|me.ExtendedOffset, "DownloadSectionResponse-Ext", gopacket.DecodeFunc(decodeDownloadSectionResponseExtended)) |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 163 | |
Chip Boling | c15f61d | 2021-05-13 09:07:17 -0500 | [diff] [blame^] | 164 | LayerTypeAlarmNotificationExtended = mkLayer(me.AlarmNotification|me.ExtendedOffset, "AlarmNotification-Ext", gopacket.DecodeFunc(decodeAlarmNotificationExtended)) |
| 165 | LayerTypeAttributeValueChangeExtended = mkLayer(me.AttributeValueChange|me.ExtendedOffset, "AttributeValueChange-Ext", gopacket.DecodeFunc(decodeAttributeValueChangeExtended)) |
| 166 | LayerTypeTestResultExtended = mkLayer(me.TestResult|me.ExtendedOffset, "TestResult-Ext", gopacket.DecodeFunc(decodeTestResultExtended)) |
| 167 | |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 168 | // Map message_type and action to layer |
| 169 | nextLayerMapping = make(map[MessageType]gopacket.LayerType) |
| 170 | |
| 171 | nextLayerMapping[CreateRequestType] = LayerTypeCreateRequest |
| 172 | nextLayerMapping[DeleteRequestType] = LayerTypeDeleteRequest |
| 173 | nextLayerMapping[SetRequestType] = LayerTypeSetRequest |
| 174 | nextLayerMapping[GetRequestType] = LayerTypeGetRequest |
| 175 | nextLayerMapping[GetAllAlarmsRequestType] = LayerTypeGetAllAlarmsRequest |
| 176 | nextLayerMapping[GetAllAlarmsNextRequestType] = LayerTypeGetAllAlarmsNextRequest |
| 177 | nextLayerMapping[MibUploadRequestType] = LayerTypeMibUploadRequest |
| 178 | nextLayerMapping[MibUploadNextRequestType] = LayerTypeMibUploadNextRequest |
| 179 | nextLayerMapping[MibResetRequestType] = LayerTypeMibResetRequest |
| 180 | nextLayerMapping[TestRequestType] = LayerTypeTestRequest |
| 181 | nextLayerMapping[StartSoftwareDownloadRequestType] = LayerTypeStartSoftwareDownloadRequest |
| 182 | nextLayerMapping[DownloadSectionRequestType] = LayerTypeDownloadSectionRequest |
Chip Boling | 8c8018e | 2021-02-22 15:56:00 -0600 | [diff] [blame] | 183 | nextLayerMapping[DownloadSectionRequestWithResponseType] = LayerTypeDownloadSectionRequest |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 184 | nextLayerMapping[EndSoftwareDownloadRequestType] = LayerTypeEndSoftwareDownloadRequest |
| 185 | nextLayerMapping[ActivateSoftwareRequestType] = LayerTypeActivateSoftwareRequest |
| 186 | nextLayerMapping[CommitSoftwareRequestType] = LayerTypeCommitSoftwareRequest |
| 187 | nextLayerMapping[SynchronizeTimeRequestType] = LayerTypeSynchronizeTimeRequest |
| 188 | nextLayerMapping[RebootRequestType] = LayerTypeRebootRequest |
| 189 | nextLayerMapping[GetNextRequestType] = LayerTypeGetNextRequest |
| 190 | nextLayerMapping[GetCurrentDataRequestType] = LayerTypeGetCurrentDataRequest |
| 191 | nextLayerMapping[SetTableRequestType] = LayerTypeSetTableRequest |
| 192 | |
| 193 | nextLayerMapping[CreateResponseType] = LayerTypeCreateResponse |
| 194 | nextLayerMapping[DeleteResponseType] = LayerTypeDeleteResponse |
| 195 | nextLayerMapping[SetResponseType] = LayerTypeSetResponse |
| 196 | nextLayerMapping[GetResponseType] = LayerTypeGetResponse |
| 197 | nextLayerMapping[GetAllAlarmsResponseType] = LayerTypeGetAllAlarmsResponse |
| 198 | nextLayerMapping[GetAllAlarmsNextResponseType] = LayerTypeGetAllAlarmsNextResponse |
| 199 | nextLayerMapping[MibUploadResponseType] = LayerTypeMibUploadResponse |
| 200 | nextLayerMapping[MibUploadNextResponseType] = LayerTypeMibUploadNextResponse |
| 201 | nextLayerMapping[MibResetResponseType] = LayerTypeMibResetResponse |
| 202 | nextLayerMapping[TestResponseType] = LayerTypeTestResponse |
| 203 | nextLayerMapping[StartSoftwareDownloadResponseType] = LayerTypeStartSoftwareDownloadResponse |
| 204 | nextLayerMapping[DownloadSectionResponseType] = LayerTypeDownloadSectionResponse |
| 205 | nextLayerMapping[EndSoftwareDownloadResponseType] = LayerTypeEndSoftwareDownloadResponse |
| 206 | nextLayerMapping[ActivateSoftwareResponseType] = LayerTypeActivateSoftwareResponse |
| 207 | nextLayerMapping[CommitSoftwareResponseType] = LayerTypeCommitSoftwareResponse |
| 208 | nextLayerMapping[SynchronizeTimeResponseType] = LayerTypeSynchronizeTimeResponse |
| 209 | nextLayerMapping[RebootResponseType] = LayerTypeRebootResponse |
| 210 | nextLayerMapping[GetNextResponseType] = LayerTypeGetNextResponse |
| 211 | nextLayerMapping[GetCurrentDataResponseType] = LayerTypeGetCurrentDataResponse |
| 212 | nextLayerMapping[SetTableResponseType] = LayerTypeSetTableResponse |
| 213 | |
| 214 | nextLayerMapping[AttributeValueChangeType] = LayerTypeAttributeValueChange |
| 215 | nextLayerMapping[AlarmNotificationType] = LayerTypeAlarmNotification |
| 216 | nextLayerMapping[TestResultType] = LayerTypeTestResult |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 217 | |
| 218 | // Extended message support |
| 219 | nextLayerMapping[GetRequestType+ExtendedTypeDecodeOffset] = LayerTypeGetRequestExtended |
| 220 | nextLayerMapping[GetResponseType+ExtendedTypeDecodeOffset] = LayerTypeGetResponseExtended |
Chip Boling | 00a30d2 | 2021-05-04 13:31:52 -0500 | [diff] [blame] | 221 | |
| 222 | // For Download section, AR=0 if not response expected, AR=1 if response expected (last section of a window) |
| 223 | nextLayerMapping[DownloadSectionRequestType+ExtendedTypeDecodeOffset] = LayerTypeDownloadSectionRequestExtended |
| 224 | nextLayerMapping[DownloadSectionRequestWithResponseType+ExtendedTypeDecodeOffset] = LayerTypeDownloadSectionLastRequestExtended |
| 225 | nextLayerMapping[DownloadSectionResponseType+ExtendedTypeDecodeOffset] = LayerTypeDownloadSectionResponseExtended |
Chip Boling | c15f61d | 2021-05-13 09:07:17 -0500 | [diff] [blame^] | 226 | |
| 227 | nextLayerMapping[AlarmNotificationType+ExtendedTypeDecodeOffset] = LayerTypeAlarmNotificationExtended |
| 228 | nextLayerMapping[AttributeValueChangeType+ExtendedTypeDecodeOffset] = LayerTypeAttributeValueChangeExtended |
| 229 | nextLayerMapping[TestResultType+ExtendedTypeDecodeOffset] = LayerTypeTestResultExtended |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 230 | } |
| 231 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 232 | func MsgTypeToNextLayer(mt MessageType, isExtended bool) (gopacket.LayerType, error) { |
| 233 | if isExtended { |
| 234 | mt |= ExtendedTypeDecodeOffset |
| 235 | } |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 236 | nextLayer, ok := nextLayerMapping[mt] |
| 237 | if ok { |
| 238 | return nextLayer, nil |
| 239 | } |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 240 | return gopacket.LayerTypeZero, errors.New("unknown/unsupported message type") |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 241 | } |