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 ( |
| 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 | ) |
| 120 | |
| 121 | func mkReqLayer(mt me.MsgType, mts string, decode gopacket.DecodeFunc) gopacket.LayerType { |
| 122 | return gopacket.RegisterLayerType(1000+(int(mt)|int(me.AR)), |
| 123 | gopacket.LayerTypeMetadata{Name: mts, Decoder: decode}) |
| 124 | } |
| 125 | |
| 126 | func mkRespLayer(mt me.MsgType, mts string, decode gopacket.DecodeFunc) gopacket.LayerType { |
| 127 | return gopacket.RegisterLayerType(1000+(int(mt)|int(me.AK)), |
| 128 | gopacket.LayerTypeMetadata{Name: mts, Decoder: decode}) |
| 129 | } |
| 130 | |
| 131 | func mkLayer(mt me.MsgType, mts string, decode gopacket.DecodeFunc) gopacket.LayerType { |
| 132 | return gopacket.RegisterLayerType(1000+(int(mt)), |
| 133 | gopacket.LayerTypeMetadata{Name: mts, Decoder: decode}) |
| 134 | } |
| 135 | |
| 136 | func init() { |
| 137 | // Create layers for message_type & action |
Chip Boling | 610117d | 2021-09-09 11:24:34 -0500 | [diff] [blame^] | 138 | LayerTypeCreateRequest = mkReqLayer(me.Create, "CreateRequest", decodeCreateRequest) |
| 139 | LayerTypeDeleteRequest = mkReqLayer(me.Delete, "DeleteRequest", decodeDeleteRequest) |
| 140 | LayerTypeSetRequest = mkReqLayer(me.Set, "SetRequest", decodeSetRequest) |
| 141 | LayerTypeGetRequest = mkReqLayer(me.Get, "GetRequest", decodeGetRequest) |
| 142 | LayerTypeGetAllAlarmsRequest = mkReqLayer(me.GetAllAlarms, "GetAllAlarmsRequest", decodeGetAllAlarmsRequest) |
| 143 | LayerTypeGetAllAlarmsNextRequest = mkReqLayer(me.GetAllAlarmsNext, "GetAllAlarmsNextRequest", decodeGetAllAlarmsNextRequest) |
| 144 | LayerTypeMibUploadRequest = mkReqLayer(me.MibUpload, "MibUploadRequest", decodeMibUploadRequest) |
| 145 | LayerTypeMibUploadNextRequest = mkReqLayer(me.MibUploadNext, "MibUploadNextRequest", decodeMibUploadNextRequest) |
| 146 | LayerTypeMibResetRequest = mkReqLayer(me.MibReset, "MibResetRequest", decodeMibResetRequest) |
| 147 | LayerTypeTestRequest = mkReqLayer(me.Test, "TestRequest", decodeTestRequest) |
| 148 | LayerTypeStartSoftwareDownloadRequest = mkReqLayer(me.StartSoftwareDownload, "StartSoftwareDownloadRequest", decodeStartSoftwareDownloadRequest) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 149 | |
| 150 | // 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^] | 151 | LayerTypeDownloadSectionRequest = mkLayer(me.DownloadSection, "DownloadSectionRequest", decodeDownloadSectionRequest) |
| 152 | LayerTypeDownloadSectionLastRequest = mkReqLayer(me.DownloadSection, "DownloadLastSectionRequest", decodeDownloadSectionRequest) |
| 153 | LayerTypeEndSoftwareDownloadRequest = mkReqLayer(me.EndSoftwareDownload, "EndSoftwareDownloadRequest", decodeEndSoftwareDownloadRequest) |
| 154 | LayerTypeActivateSoftwareRequest = mkReqLayer(me.ActivateSoftware, "ActivateSoftwareRequest", decodeActivateSoftwareRequest) |
| 155 | LayerTypeCommitSoftwareRequest = mkReqLayer(me.CommitSoftware, "CommitSoftwareRequest", decodeCommitSoftwareRequest) |
| 156 | LayerTypeSynchronizeTimeRequest = mkReqLayer(me.SynchronizeTime, "SynchronizeTimeRequest", decodeSynchronizeTimeRequest) |
| 157 | LayerTypeRebootRequest = mkReqLayer(me.Reboot, "RebootRequest", decodeRebootRequest) |
| 158 | LayerTypeGetNextRequest = mkReqLayer(me.GetNext, "GetNextRequest", decodeGetNextRequest) |
| 159 | LayerTypeGetCurrentDataRequest = mkReqLayer(me.GetCurrentData, "GetCurrentDataRequest", decodeGetCurrentDataRequest) |
| 160 | LayerTypeSetTableRequest = mkReqLayer(me.SetTable, "SetTableRequest", decodeSetTableRequest) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 161 | |
Chip Boling | 610117d | 2021-09-09 11:24:34 -0500 | [diff] [blame^] | 162 | LayerTypeCreateResponse = mkRespLayer(me.Create, "CreateResponse", decodeCreateResponse) |
| 163 | LayerTypeDeleteResponse = mkRespLayer(me.Delete, "DeleteResponse", decodeDeleteResponse) |
| 164 | LayerTypeSetResponse = mkRespLayer(me.Set, "SetResponse", decodeSetResponse) |
| 165 | LayerTypeGetResponse = mkRespLayer(me.Get, "GetResponse", decodeGetResponse) |
| 166 | LayerTypeGetAllAlarmsResponse = mkRespLayer(me.GetAllAlarms, "GetAllAlarmsResponse", decodeGetAllAlarmsResponse) |
| 167 | LayerTypeGetAllAlarmsNextResponse = mkRespLayer(me.GetAllAlarmsNext, "GetAllAlarmsNextResponse", decodeGetAllAlarmsNextResponse) |
| 168 | LayerTypeMibUploadResponse = mkRespLayer(me.MibUpload, "MibUploadResponse", decodeMibUploadResponse) |
| 169 | LayerTypeMibUploadNextResponse = mkRespLayer(me.MibUploadNext, "MibUploadNextResponse", decodeMibUploadNextResponse) |
| 170 | LayerTypeMibResetResponse = mkRespLayer(me.MibReset, "MibResetResponse", decodeMibResetResponse) |
| 171 | LayerTypeAlarmNotification = mkLayer(me.AlarmNotification, "AlarmNotification", decodeAlarmNotification) |
| 172 | LayerTypeAttributeValueChange = mkLayer(me.AttributeValueChange, "AttributeValueChange", decodeAttributeValueChange) |
| 173 | LayerTypeTestResponse = mkRespLayer(me.Test, "TestResponse", decodeTestResponse) |
| 174 | LayerTypeStartSoftwareDownloadResponse = mkRespLayer(me.StartSoftwareDownload, "StartSoftwareDownloadResponse", decodeStartSoftwareDownloadResponse) |
| 175 | LayerTypeDownloadSectionResponse = mkRespLayer(me.DownloadSection, "DownloadSectionResponse", decodeDownloadSectionResponse) |
| 176 | LayerTypeEndSoftwareDownloadResponse = mkRespLayer(me.EndSoftwareDownload, "EndSoftwareDownloadResponse", decodeEndSoftwareDownloadResponse) |
| 177 | LayerTypeActivateSoftwareResponse = mkRespLayer(me.ActivateSoftware, "ActivateSoftwareResponse", decodeActivateSoftwareResponse) |
| 178 | LayerTypeCommitSoftwareResponse = mkRespLayer(me.CommitSoftware, "CommitSoftwareResponse", decodeCommitSoftwareResponse) |
| 179 | LayerTypeSynchronizeTimeResponse = mkRespLayer(me.SynchronizeTime, "SynchronizeTimeResponse", decodeSynchronizeTimeResponse) |
| 180 | LayerTypeRebootResponse = mkRespLayer(me.Reboot, "RebootResponse", decodeRebootResponse) |
| 181 | LayerTypeGetNextResponse = mkRespLayer(me.GetNext, "GetNextResponse", decodeGetNextResponse) |
| 182 | LayerTypeTestResult = mkRespLayer(me.TestResult, "TestResult", decodeTestResult) |
| 183 | LayerTypeGetCurrentDataResponse = mkRespLayer(me.GetCurrentData, "GetCurrentDataResponse", decodeGetCurrentDataResponse) |
| 184 | LayerTypeSetTableResponse = mkRespLayer(me.SetTable, "SetTableResponse", decodeSetTableResponse) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 185 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 186 | // Extended message set support |
| 187 | |
Chip Boling | 610117d | 2021-09-09 11:24:34 -0500 | [diff] [blame^] | 188 | LayerTypeCreateRequestExtended = mkReqLayer(me.Create|me.ExtendedOffset, "CreateRequest-Ext", decodeCreateRequestExtended) |
| 189 | LayerTypeDeleteRequestExtended = mkReqLayer(me.Delete|me.ExtendedOffset, "DeleteRequest-Ext", decodeDeleteRequestExtended) |
| 190 | LayerTypeSetRequestExtended = mkReqLayer(me.Set|me.ExtendedOffset, "SetRequest-Ext", decodeSetRequestExtended) |
| 191 | LayerTypeGetRequestExtended = mkReqLayer(me.Get|me.ExtendedOffset, "GetRequest-Ext", decodeGetRequestExtended) |
| 192 | LayerTypeGetNextRequestExtended = mkReqLayer(me.GetNext|me.ExtendedOffset, "GetNextRequest-Ext", decodeGetNextRequestExtended) |
| 193 | LayerTypeMibUploadRequestExtended = mkReqLayer(me.MibUpload|me.ExtendedOffset, "MibUploadRequest-Ext", decodeMibUploadRequestExtended) |
| 194 | LayerTypeMibUploadNextRequestExtended = mkReqLayer(me.MibUploadNext|me.ExtendedOffset, "MibUploadNextRequest-Ext", decodeMibUploadNextRequestExtended) |
| 195 | LayerTypeMibResetRequestExtended = mkReqLayer(me.MibReset|me.ExtendedOffset, "MibResetRequest-Ext", decodeMibResetRequestExtended) |
| 196 | LayerTypeStartSoftwareDownloadRequestExtended = mkReqLayer(me.StartSoftwareDownload|me.ExtendedOffset, "StartSoftwareDownloadRequest-Ext", decodeStartSoftwareDownloadRequestExtended) |
| 197 | LayerTypeDownloadSectionRequestExtended = mkLayer(me.DownloadSection|me.ExtendedOffset, "DownloadSectionRequest-Ext", decodeDownloadSectionRequestExtended) |
| 198 | LayerTypeDownloadSectionLastRequestExtended = mkReqLayer(me.DownloadSection|me.ExtendedOffset, "DownloadLastSectionRequest-Ext", decodeDownloadSectionRequestExtended) |
| 199 | LayerTypeEndSoftwareDownloadRequestExtended = mkReqLayer(me.EndSoftwareDownload|me.ExtendedOffset, "EndSoftwareDownloadRequest-Ext", decodeEndSoftwareDownloadRequestExtended) |
| 200 | LayerTypeActivateSoftwareRequestExtended = mkReqLayer(me.ActivateSoftware|me.ExtendedOffset, "ActivateSoftwareRequest-Ext", decodeActivateSoftwareRequestExtended) |
| 201 | LayerTypeCommitSoftwareRequestExtended = mkReqLayer(me.CommitSoftware|me.ExtendedOffset, "CommitSoftwareRequest-Ext", decodeCommitSoftwareRequestExtended) |
| 202 | LayerTypeSynchronizeTimeRequestExtended = mkReqLayer(me.SynchronizeTime|me.ExtendedOffset, "SynchronizeTimeRequest-Ext", decodeSynchronizeTimeRequestExtended) |
| 203 | LayerTypeRebootRequestExtended = mkReqLayer(me.Reboot|me.ExtendedOffset, "RebootRequest-Ext", decodeRebootRequestExtended) |
| 204 | LayerTypeGetCurrentDataRequestExtended = mkReqLayer(me.GetCurrentData|me.ExtendedOffset, "GetCurrentDataRequest-Ext", decodeGetCurrentDataRequestExtended) |
| 205 | LayerTypeSetTableRequestExtended = mkReqLayer(me.SetTable|me.ExtendedOffset, "SetTableRequest-Ext", decodeSetTableRequestExtended) |
| 206 | LayerTypeGetAllAlarmsRequestExtended = mkReqLayer(me.GetAllAlarms|me.ExtendedOffset, "GetAllAlarmsRequest-Ext", decodeGetAllAlarmsRequestExtended) |
| 207 | LayerTypeGetAllAlarmsNextRequestExtended = mkReqLayer(me.GetAllAlarmsNext|me.ExtendedOffset, "GetAllAlarmsNextRequest-Ext", decodeGetAllAlarmsNextRequestExtended) |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 208 | |
Chip Boling | 610117d | 2021-09-09 11:24:34 -0500 | [diff] [blame^] | 209 | LayerTypeCreateResponseExtended = mkRespLayer(me.Create|me.ExtendedOffset, "CreateResponse-Ext", decodeCreateResponseExtended) |
| 210 | LayerTypeDeleteResponseExtended = mkRespLayer(me.Delete|me.ExtendedOffset, "DeleteResponse-Ext", decodeDeleteResponseExtended) |
| 211 | LayerTypeSetResponseExtended = mkRespLayer(me.Set|me.ExtendedOffset, "SetResponse-Ext", decodeSetResponseExtended) |
| 212 | LayerTypeGetResponseExtended = mkRespLayer(me.Get|me.ExtendedOffset, "GetResponse-Ext", decodeGetResponseExtended) |
| 213 | LayerTypeGetNextResponseExtended = mkRespLayer(me.GetNext|me.ExtendedOffset, "GetNextResponse-Ext", decodeGetNextResponseExtended) |
| 214 | LayerTypeMibUploadResponseExtended = mkRespLayer(me.MibUpload|me.ExtendedOffset, "MibUploadResponse-Ext", decodeMibUploadResponseExtended) |
| 215 | LayerTypeMibUploadNextResponseExtended = mkRespLayer(me.MibUploadNext|me.ExtendedOffset, "MibUploadNextResponse-Ext", decodeMibUploadNextResponseExtended) |
| 216 | LayerTypeMibResetResponseExtended = mkRespLayer(me.MibReset|me.ExtendedOffset, "MibResetResponse-Ext", decodeMibResetResponseExtended) |
| 217 | LayerTypeStartSoftwareDownloadResponseExtended = mkRespLayer(me.StartSoftwareDownload|me.ExtendedOffset, "StartSoftwareDownloadResponse-Ext", decodeStartSoftwareDownloadResponseExtended) |
| 218 | LayerTypeDownloadSectionResponseExtended = mkRespLayer(me.DownloadSection|me.ExtendedOffset, "DownloadSectionResponse-Ext", decodeDownloadSectionResponseExtended) |
| 219 | LayerTypeEndSoftwareDownloadResponseExtended = mkRespLayer(me.EndSoftwareDownload|me.ExtendedOffset, "EndSoftwareDownloadResponse-Ext", decodeEndSoftwareDownloadResponseExtended) |
| 220 | LayerTypeActivateSoftwareResponseExtended = mkRespLayer(me.ActivateSoftware|me.ExtendedOffset, "ActivateSoftwareResponse-Ext", decodeActivateSoftwareResponseExtended) |
| 221 | LayerTypeCommitSoftwareResponseExtended = mkRespLayer(me.CommitSoftware|me.ExtendedOffset, "CommitSoftwareResponse-Ext", decodeCommitSoftwareResponseExtended) |
| 222 | LayerTypeSynchronizeTimeResponseExtended = mkRespLayer(me.SynchronizeTime|me.ExtendedOffset, "SynchronizeTimeResponse-Ext", decodeSynchronizeTimeResponseExtended) |
| 223 | LayerTypeRebootResponseExtended = mkRespLayer(me.Reboot|me.ExtendedOffset, "RebootResponse-Ext", decodeRebootResponseExtended) |
| 224 | LayerTypeGetCurrentDataResponseExtended = mkRespLayer(me.GetCurrentData|me.ExtendedOffset, "GetCurrentDataResponse-Ext", decodeGetCurrentDataResponseExtended) |
| 225 | LayerTypeSetTableResponseExtended = mkRespLayer(me.SetTable|me.ExtendedOffset, "SetTableResponse-Ext", decodeSetTableResponseExtended) |
| 226 | LayerTypeGetAllAlarmsResponseExtended = mkRespLayer(me.GetAllAlarms|me.ExtendedOffset, "GetAllAlarmsResponse-Ext", decodeGetAllAlarmsResponseExtended) |
| 227 | LayerTypeGetAllAlarmsNextResponseExtended = mkRespLayer(me.GetAllAlarmsNext|me.ExtendedOffset, "GetAllAlarmsNextResponse-Ext", decodeGetAllAlarmsNextResponseExtended) |
| 228 | |
| 229 | LayerTypeAlarmNotificationExtended = mkLayer(me.AlarmNotification|me.ExtendedOffset, "AlarmNotification-Ext", decodeAlarmNotificationExtended) |
| 230 | LayerTypeAttributeValueChangeExtended = mkLayer(me.AttributeValueChange|me.ExtendedOffset, "AttributeValueChange-Ext", decodeAttributeValueChangeExtended) |
| 231 | LayerTypeTestResultExtended = mkLayer(me.TestResult|me.ExtendedOffset, "TestResult-Ext", decodeTestResultExtended) |
Chip Boling | c15f61d | 2021-05-13 09:07:17 -0500 | [diff] [blame] | 232 | |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 233 | // Map message_type and action to layer |
| 234 | nextLayerMapping = make(map[MessageType]gopacket.LayerType) |
| 235 | |
| 236 | nextLayerMapping[CreateRequestType] = LayerTypeCreateRequest |
| 237 | nextLayerMapping[DeleteRequestType] = LayerTypeDeleteRequest |
| 238 | nextLayerMapping[SetRequestType] = LayerTypeSetRequest |
| 239 | nextLayerMapping[GetRequestType] = LayerTypeGetRequest |
| 240 | nextLayerMapping[GetAllAlarmsRequestType] = LayerTypeGetAllAlarmsRequest |
| 241 | nextLayerMapping[GetAllAlarmsNextRequestType] = LayerTypeGetAllAlarmsNextRequest |
| 242 | nextLayerMapping[MibUploadRequestType] = LayerTypeMibUploadRequest |
| 243 | nextLayerMapping[MibUploadNextRequestType] = LayerTypeMibUploadNextRequest |
| 244 | nextLayerMapping[MibResetRequestType] = LayerTypeMibResetRequest |
| 245 | nextLayerMapping[TestRequestType] = LayerTypeTestRequest |
| 246 | nextLayerMapping[StartSoftwareDownloadRequestType] = LayerTypeStartSoftwareDownloadRequest |
| 247 | nextLayerMapping[DownloadSectionRequestType] = LayerTypeDownloadSectionRequest |
Chip Boling | 610117d | 2021-09-09 11:24:34 -0500 | [diff] [blame^] | 248 | nextLayerMapping[DownloadSectionRequestWithResponseType] = LayerTypeDownloadSectionLastRequest |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 249 | nextLayerMapping[EndSoftwareDownloadRequestType] = LayerTypeEndSoftwareDownloadRequest |
| 250 | nextLayerMapping[ActivateSoftwareRequestType] = LayerTypeActivateSoftwareRequest |
| 251 | nextLayerMapping[CommitSoftwareRequestType] = LayerTypeCommitSoftwareRequest |
| 252 | nextLayerMapping[SynchronizeTimeRequestType] = LayerTypeSynchronizeTimeRequest |
| 253 | nextLayerMapping[RebootRequestType] = LayerTypeRebootRequest |
| 254 | nextLayerMapping[GetNextRequestType] = LayerTypeGetNextRequest |
| 255 | nextLayerMapping[GetCurrentDataRequestType] = LayerTypeGetCurrentDataRequest |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 256 | |
| 257 | nextLayerMapping[CreateResponseType] = LayerTypeCreateResponse |
| 258 | nextLayerMapping[DeleteResponseType] = LayerTypeDeleteResponse |
| 259 | nextLayerMapping[SetResponseType] = LayerTypeSetResponse |
| 260 | nextLayerMapping[GetResponseType] = LayerTypeGetResponse |
| 261 | nextLayerMapping[GetAllAlarmsResponseType] = LayerTypeGetAllAlarmsResponse |
| 262 | nextLayerMapping[GetAllAlarmsNextResponseType] = LayerTypeGetAllAlarmsNextResponse |
| 263 | nextLayerMapping[MibUploadResponseType] = LayerTypeMibUploadResponse |
| 264 | nextLayerMapping[MibUploadNextResponseType] = LayerTypeMibUploadNextResponse |
| 265 | nextLayerMapping[MibResetResponseType] = LayerTypeMibResetResponse |
| 266 | nextLayerMapping[TestResponseType] = LayerTypeTestResponse |
| 267 | nextLayerMapping[StartSoftwareDownloadResponseType] = LayerTypeStartSoftwareDownloadResponse |
| 268 | nextLayerMapping[DownloadSectionResponseType] = LayerTypeDownloadSectionResponse |
| 269 | nextLayerMapping[EndSoftwareDownloadResponseType] = LayerTypeEndSoftwareDownloadResponse |
| 270 | nextLayerMapping[ActivateSoftwareResponseType] = LayerTypeActivateSoftwareResponse |
| 271 | nextLayerMapping[CommitSoftwareResponseType] = LayerTypeCommitSoftwareResponse |
| 272 | nextLayerMapping[SynchronizeTimeResponseType] = LayerTypeSynchronizeTimeResponse |
| 273 | nextLayerMapping[RebootResponseType] = LayerTypeRebootResponse |
| 274 | nextLayerMapping[GetNextResponseType] = LayerTypeGetNextResponse |
| 275 | nextLayerMapping[GetCurrentDataResponseType] = LayerTypeGetCurrentDataResponse |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 276 | |
| 277 | nextLayerMapping[AttributeValueChangeType] = LayerTypeAttributeValueChange |
| 278 | nextLayerMapping[AlarmNotificationType] = LayerTypeAlarmNotification |
| 279 | nextLayerMapping[TestResultType] = LayerTypeTestResult |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 280 | |
Chip Boling | 610117d | 2021-09-09 11:24:34 -0500 | [diff] [blame^] | 281 | nextLayerMapping[SetTableRequestType] = LayerTypeSetTableRequest |
| 282 | nextLayerMapping[SetTableResponseType] = LayerTypeSetTableResponse |
| 283 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 284 | // Extended message support |
Chip Boling | 610117d | 2021-09-09 11:24:34 -0500 | [diff] [blame^] | 285 | nextLayerMapping[CreateRequestType+ExtendedTypeDecodeOffset] = LayerTypeCreateRequestExtended |
| 286 | nextLayerMapping[CreateResponseType+ExtendedTypeDecodeOffset] = LayerTypeCreateResponseExtended |
| 287 | nextLayerMapping[DeleteResponseType+ExtendedTypeDecodeOffset] = LayerTypeDeleteResponseExtended |
| 288 | nextLayerMapping[DeleteRequestType+ExtendedTypeDecodeOffset] = LayerTypeDeleteRequestExtended |
| 289 | nextLayerMapping[SetRequestType+ExtendedTypeDecodeOffset] = LayerTypeSetRequestExtended |
| 290 | nextLayerMapping[SetResponseType+ExtendedTypeDecodeOffset] = LayerTypeSetResponseExtended |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 291 | nextLayerMapping[GetRequestType+ExtendedTypeDecodeOffset] = LayerTypeGetRequestExtended |
| 292 | nextLayerMapping[GetResponseType+ExtendedTypeDecodeOffset] = LayerTypeGetResponseExtended |
Chip Boling | 610117d | 2021-09-09 11:24:34 -0500 | [diff] [blame^] | 293 | nextLayerMapping[GetNextRequestType+ExtendedTypeDecodeOffset] = LayerTypeGetNextRequestExtended |
| 294 | nextLayerMapping[GetNextResponseType+ExtendedTypeDecodeOffset] = LayerTypeGetNextResponseExtended |
Chip Boling | 00a30d2 | 2021-05-04 13:31:52 -0500 | [diff] [blame] | 295 | |
Chip Boling | 610117d | 2021-09-09 11:24:34 -0500 | [diff] [blame^] | 296 | nextLayerMapping[MibUploadRequestType+ExtendedTypeDecodeOffset] = LayerTypeMibUploadRequestExtended |
| 297 | nextLayerMapping[MibUploadResponseType+ExtendedTypeDecodeOffset] = LayerTypeMibUploadResponseExtended |
| 298 | nextLayerMapping[MibUploadNextRequestType+ExtendedTypeDecodeOffset] = LayerTypeMibUploadNextRequestExtended |
| 299 | nextLayerMapping[MibUploadNextResponseType+ExtendedTypeDecodeOffset] = LayerTypeMibUploadNextResponseExtended |
| 300 | |
| 301 | nextLayerMapping[MibResetRequestType+ExtendedTypeDecodeOffset] = LayerTypeMibResetRequestExtended |
| 302 | nextLayerMapping[MibResetResponseType+ExtendedTypeDecodeOffset] = LayerTypeMibResetResponseExtended |
| 303 | nextLayerMapping[SynchronizeTimeRequestType+ExtendedTypeDecodeOffset] = LayerTypeSynchronizeTimeRequestExtended |
| 304 | nextLayerMapping[SynchronizeTimeResponseType+ExtendedTypeDecodeOffset] = LayerTypeSynchronizeTimeResponseExtended |
| 305 | nextLayerMapping[RebootRequestType+ExtendedTypeDecodeOffset] = LayerTypeRebootRequestExtended |
| 306 | nextLayerMapping[RebootResponseType+ExtendedTypeDecodeOffset] = LayerTypeRebootResponseExtended |
| 307 | nextLayerMapping[GetCurrentDataRequestType+ExtendedTypeDecodeOffset] = LayerTypeGetCurrentDataRequestExtended |
| 308 | nextLayerMapping[GetCurrentDataResponseType+ExtendedTypeDecodeOffset] = LayerTypeGetCurrentDataResponseExtended |
| 309 | |
| 310 | nextLayerMapping[SetTableRequestType+ExtendedTypeDecodeOffset] = LayerTypeSetTableRequestExtended |
| 311 | nextLayerMapping[SetTableResponseType+ExtendedTypeDecodeOffset] = LayerTypeSetTableResponseExtended |
| 312 | |
| 313 | nextLayerMapping[GetAllAlarmsRequestType+ExtendedTypeDecodeOffset] = LayerTypeGetAllAlarmsRequestExtended |
| 314 | nextLayerMapping[GetAllAlarmsNextRequestType+ExtendedTypeDecodeOffset] = LayerTypeGetAllAlarmsNextRequestExtended |
| 315 | nextLayerMapping[GetAllAlarmsResponseType+ExtendedTypeDecodeOffset] = LayerTypeGetAllAlarmsResponseExtended |
| 316 | nextLayerMapping[GetAllAlarmsNextResponseType+ExtendedTypeDecodeOffset] = LayerTypeGetAllAlarmsNextResponseExtended |
| 317 | |
| 318 | nextLayerMapping[StartSoftwareDownloadRequestType+ExtendedTypeDecodeOffset] = LayerTypeStartSoftwareDownloadRequestExtended |
| 319 | nextLayerMapping[StartSoftwareDownloadResponseType+ExtendedTypeDecodeOffset] = LayerTypeStartSoftwareDownloadResponseExtended |
Chip Boling | 00a30d2 | 2021-05-04 13:31:52 -0500 | [diff] [blame] | 320 | // For Download section, AR=0 if not response expected, AR=1 if response expected (last section of a window) |
| 321 | nextLayerMapping[DownloadSectionRequestType+ExtendedTypeDecodeOffset] = LayerTypeDownloadSectionRequestExtended |
| 322 | nextLayerMapping[DownloadSectionRequestWithResponseType+ExtendedTypeDecodeOffset] = LayerTypeDownloadSectionLastRequestExtended |
| 323 | nextLayerMapping[DownloadSectionResponseType+ExtendedTypeDecodeOffset] = LayerTypeDownloadSectionResponseExtended |
Chip Boling | c15f61d | 2021-05-13 09:07:17 -0500 | [diff] [blame] | 324 | |
Chip Boling | 610117d | 2021-09-09 11:24:34 -0500 | [diff] [blame^] | 325 | nextLayerMapping[EndSoftwareDownloadRequestType+ExtendedTypeDecodeOffset] = LayerTypeEndSoftwareDownloadRequestExtended |
| 326 | nextLayerMapping[EndSoftwareDownloadResponseType+ExtendedTypeDecodeOffset] = LayerTypeEndSoftwareDownloadResponseExtended |
| 327 | |
| 328 | nextLayerMapping[ActivateSoftwareRequestType+ExtendedTypeDecodeOffset] = LayerTypeActivateSoftwareRequestExtended |
| 329 | nextLayerMapping[ActivateSoftwareResponseType+ExtendedTypeDecodeOffset] = LayerTypeActivateSoftwareResponseExtended |
| 330 | |
| 331 | nextLayerMapping[CommitSoftwareRequestType+ExtendedTypeDecodeOffset] = LayerTypeCommitSoftwareRequestExtended |
| 332 | nextLayerMapping[CommitSoftwareResponseType+ExtendedTypeDecodeOffset] = LayerTypeCommitSoftwareResponseExtended |
| 333 | |
Chip Boling | c15f61d | 2021-05-13 09:07:17 -0500 | [diff] [blame] | 334 | nextLayerMapping[AlarmNotificationType+ExtendedTypeDecodeOffset] = LayerTypeAlarmNotificationExtended |
| 335 | nextLayerMapping[AttributeValueChangeType+ExtendedTypeDecodeOffset] = LayerTypeAttributeValueChangeExtended |
| 336 | nextLayerMapping[TestResultType+ExtendedTypeDecodeOffset] = LayerTypeTestResultExtended |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 337 | } |
| 338 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 339 | func MsgTypeToNextLayer(mt MessageType, isExtended bool) (gopacket.LayerType, error) { |
| 340 | if isExtended { |
| 341 | mt |= ExtendedTypeDecodeOffset |
| 342 | } |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 343 | nextLayer, ok := nextLayerMapping[mt] |
| 344 | if ok { |
| 345 | return nextLayer, nil |
| 346 | } |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 347 | return gopacket.LayerTypeZero, errors.New("unknown/unsupported message type") |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 348 | } |