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" |
Andrea Campanella | e0cd823 | 2021-10-15 15:10:23 +0200 | [diff] [blame] | 23 | me "github.com/opencord/omci-lib-go/v2/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 ( |
| 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 Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 50 | |
Chip Boling | 610117d | 2021-09-09 11:24:34 -0500 | [diff] [blame] | 51 | 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 Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 71 | ) |
| 72 | var ( |
| 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 Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 96 | |
Chip Boling | 610117d | 2021-09-09 11:24:34 -0500 | [diff] [blame] | 97 | 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 Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 119 | ) |
Chip Boling | 934e105 | 2021-09-27 15:12:06 -0500 | [diff] [blame] | 120 | var ( |
| 121 | LayerTypeUnknownAttributes gopacket.LayerType |
| 122 | ) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 123 | |
| 124 | func 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 | |
| 129 | func 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 | |
| 134 | func 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 | |
| 139 | func init() { |
| 140 | // Create layers for message_type & action |
Chip Boling | 610117d | 2021-09-09 11:24:34 -0500 | [diff] [blame] | 141 | 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 Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 152 | |
| 153 | // For Download section, AR=0 if not response expected, AR=1 if response expected (last section of a window) |
Chip Boling | 610117d | 2021-09-09 11:24:34 -0500 | [diff] [blame] | 154 | 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 Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 164 | |
Chip Boling | 610117d | 2021-09-09 11:24:34 -0500 | [diff] [blame] | 165 | 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 Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 188 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 189 | // Extended message set support |
| 190 | |
Chip Boling | 610117d | 2021-09-09 11:24:34 -0500 | [diff] [blame] | 191 | 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 Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 211 | |
Chip Boling | 610117d | 2021-09-09 11:24:34 -0500 | [diff] [blame] | 212 | 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 Boling | c15f61d | 2021-05-13 09:07:17 -0500 | [diff] [blame] | 235 | |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 236 | // 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 Boling | 610117d | 2021-09-09 11:24:34 -0500 | [diff] [blame] | 251 | nextLayerMapping[DownloadSectionRequestWithResponseType] = LayerTypeDownloadSectionLastRequest |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 252 | 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 Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 259 | |
| 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 Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 279 | |
| 280 | nextLayerMapping[AttributeValueChangeType] = LayerTypeAttributeValueChange |
| 281 | nextLayerMapping[AlarmNotificationType] = LayerTypeAlarmNotification |
| 282 | nextLayerMapping[TestResultType] = LayerTypeTestResult |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 283 | |
Chip Boling | 610117d | 2021-09-09 11:24:34 -0500 | [diff] [blame] | 284 | nextLayerMapping[SetTableRequestType] = LayerTypeSetTableRequest |
| 285 | nextLayerMapping[SetTableResponseType] = LayerTypeSetTableResponse |
| 286 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 287 | // Extended message support |
Chip Boling | 610117d | 2021-09-09 11:24:34 -0500 | [diff] [blame] | 288 | 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 Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 294 | nextLayerMapping[GetRequestType+ExtendedTypeDecodeOffset] = LayerTypeGetRequestExtended |
| 295 | nextLayerMapping[GetResponseType+ExtendedTypeDecodeOffset] = LayerTypeGetResponseExtended |
Chip Boling | 610117d | 2021-09-09 11:24:34 -0500 | [diff] [blame] | 296 | nextLayerMapping[GetNextRequestType+ExtendedTypeDecodeOffset] = LayerTypeGetNextRequestExtended |
| 297 | nextLayerMapping[GetNextResponseType+ExtendedTypeDecodeOffset] = LayerTypeGetNextResponseExtended |
Chip Boling | 00a30d2 | 2021-05-04 13:31:52 -0500 | [diff] [blame] | 298 | |
Chip Boling | 610117d | 2021-09-09 11:24:34 -0500 | [diff] [blame] | 299 | 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 Boling | 00a30d2 | 2021-05-04 13:31:52 -0500 | [diff] [blame] | 323 | // 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 Boling | c15f61d | 2021-05-13 09:07:17 -0500 | [diff] [blame] | 327 | |
Chip Boling | 610117d | 2021-09-09 11:24:34 -0500 | [diff] [blame] | 328 | 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 Boling | c15f61d | 2021-05-13 09:07:17 -0500 | [diff] [blame] | 337 | nextLayerMapping[AlarmNotificationType+ExtendedTypeDecodeOffset] = LayerTypeAlarmNotificationExtended |
| 338 | nextLayerMapping[AttributeValueChangeType+ExtendedTypeDecodeOffset] = LayerTypeAttributeValueChangeExtended |
| 339 | nextLayerMapping[TestResultType+ExtendedTypeDecodeOffset] = LayerTypeTestResultExtended |
Chip Boling | 934e105 | 2021-09-27 15:12:06 -0500 | [diff] [blame] | 340 | |
| 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 Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 350 | } |
| 351 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 352 | func MsgTypeToNextLayer(mt MessageType, isExtended bool) (gopacket.LayerType, error) { |
| 353 | if isExtended { |
| 354 | mt |= ExtendedTypeDecodeOffset |
| 355 | } |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 356 | nextLayer, ok := nextLayerMapping[mt] |
| 357 | if ok { |
| 358 | return nextLayer, nil |
| 359 | } |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 360 | return gopacket.LayerTypeZero, errors.New("unknown/unsupported message type") |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 361 | } |