Wei-Yu Chen | ad55cb8 | 2022-02-15 20:07:01 +0800 | [diff] [blame] | 1 | # SPDX-FileCopyrightText: 2020 The Magma Authors. |
| 2 | # SPDX-FileCopyrightText: 2022 Open Networking Foundation <support@opennetworking.org> |
| 3 | # |
| 4 | # SPDX-License-Identifier: BSD-3-Clause |
Wei-Yu Chen | 49950b9 | 2021-11-08 19:19:18 +0800 | [diff] [blame] | 5 | |
| 6 | from spyne.model import ComplexModel |
| 7 | from spyne.model.complex import XmlAttribute, XmlData |
| 8 | from spyne.model.primitive import ( |
| 9 | Boolean, |
| 10 | DateTime, |
| 11 | Integer, |
| 12 | String, |
| 13 | UnsignedInteger, |
| 14 | ) |
| 15 | from spyne.util.odict import odict |
| 16 | |
| 17 | # Namespaces |
| 18 | XSI_NS = 'http://www.w3.org/2001/XMLSchema-instance' |
| 19 | SOAP_ENV = 'http://schemas.xmlsoap.org/soap/envelope/' |
| 20 | SOAP_ENC = 'http://schemas.xmlsoap.org/soap/encoding/' |
| 21 | CWMP_NS = 'urn:dslforum-org:cwmp-1-0' |
| 22 | |
| 23 | |
| 24 | class Tr069ComplexModel(ComplexModel): |
| 25 | """ Base class for TR-069 models, to set common attributes. Does not appear |
| 26 | in CWMP XSD file. """ |
| 27 | __namespace__ = CWMP_NS |
| 28 | |
| 29 | |
| 30 | class anySimpleType(Tr069ComplexModel): |
| 31 | """ Type used to transfer simple data of various types. Data type is |
| 32 | defined in 'type' XML attribute. Data is handled as a string. """ |
| 33 | _type_info = odict() |
| 34 | _type_info["type"] = XmlAttribute(String, ns=XSI_NS) |
| 35 | _type_info["Data"] = XmlData(String) |
| 36 | |
| 37 | def __repr__(self): |
| 38 | """For types we can't resolve only print the datum""" |
| 39 | return self.Data |
| 40 | |
| 41 | |
| 42 | # SOAP Header Elements |
| 43 | |
| 44 | |
| 45 | class ID(Tr069ComplexModel): |
| 46 | # Note: for some reason, XmlAttribute/XmlData pairs MUST be ordered, with |
| 47 | # XmlAttribute coming first. This appears to be a spyne bug (something to do |
| 48 | # with spyne.interface._base.add_class()) |
| 49 | _type_info = odict() |
| 50 | _type_info["mustUnderstand"] = XmlAttribute(String, ns=SOAP_ENV) |
| 51 | _type_info["Data"] = XmlData(String) |
| 52 | |
| 53 | |
| 54 | class HoldRequests(Tr069ComplexModel): |
| 55 | _type_info = odict() |
| 56 | _type_info["mustUnderstand"] = XmlAttribute(String, ns=SOAP_ENV) |
| 57 | _type_info["Data"] = XmlData(Boolean) |
| 58 | |
| 59 | |
| 60 | # SOAP Fault Extensions |
| 61 | |
| 62 | |
| 63 | class SetParameterValuesFault(Tr069ComplexModel): |
| 64 | _type_info = odict() |
| 65 | _type_info["ParameterName"] = String |
| 66 | _type_info["FaultCode"] = UnsignedInteger |
| 67 | _type_info["FaultString"] = String |
| 68 | |
| 69 | |
| 70 | class Fault(Tr069ComplexModel): |
| 71 | _type_info = odict() |
| 72 | _type_info["FaultCode"] = UnsignedInteger |
| 73 | _type_info["FaultString"] = String |
| 74 | _type_info["SetParameterValuesFault"] = SetParameterValuesFault.customize( |
| 75 | max_occurs='unbounded', |
| 76 | ) |
| 77 | |
| 78 | |
| 79 | # Type definitions used in messages |
| 80 | |
| 81 | |
| 82 | class MethodList(Tr069ComplexModel): |
| 83 | _type_info = odict() |
| 84 | _type_info["string"] = String(max_length=64, max_occurs='unbounded') |
| 85 | _type_info["arrayType"] = XmlAttribute(String, ns=SOAP_ENC) |
| 86 | |
| 87 | |
| 88 | class FaultStruct(Tr069ComplexModel): |
| 89 | _type_info = odict() |
| 90 | _type_info["FaultCode"] = Integer |
| 91 | _type_info["FaultString"] = String(max_length=256) |
| 92 | |
| 93 | |
| 94 | class DeviceIdStruct(Tr069ComplexModel): |
| 95 | _type_info = odict() |
| 96 | _type_info["Manufacturer"] = String(max_length=64) |
| 97 | _type_info["OUI"] = String(length=6) |
| 98 | _type_info["ProductClass"] = String(max_length=64) |
| 99 | _type_info["SerialNumber"] = String(max_length=64) |
| 100 | |
| 101 | |
| 102 | class EventStruct(Tr069ComplexModel): |
| 103 | _type_info = odict() |
| 104 | _type_info["EventCode"] = String(max_length=64) |
| 105 | _type_info["CommandKey"] = String(max_length=32) |
| 106 | |
| 107 | |
| 108 | class EventList(Tr069ComplexModel): |
| 109 | _type_info = odict() |
| 110 | _type_info["EventStruct"] = EventStruct.customize(max_occurs='unbounded') |
| 111 | _type_info["arrayType"] = XmlAttribute(String, ns=SOAP_ENC) |
| 112 | |
| 113 | |
| 114 | class ParameterValueStruct(Tr069ComplexModel): |
| 115 | _type_info = odict() |
| 116 | _type_info["Name"] = String |
| 117 | _type_info["Value"] = anySimpleType |
| 118 | |
| 119 | |
| 120 | class ParameterValueList(Tr069ComplexModel): |
| 121 | _type_info = odict() |
| 122 | _type_info["ParameterValueStruct"] = ParameterValueStruct.customize( |
| 123 | max_occurs='unbounded', |
| 124 | ) |
| 125 | _type_info["arrayType"] = XmlAttribute(String, ns=SOAP_ENC) |
| 126 | |
| 127 | |
| 128 | class ParameterInfoStruct(Tr069ComplexModel): |
| 129 | _type_info = odict() |
| 130 | _type_info["Name"] = String(max_length=256) |
| 131 | _type_info["Writable"] = Boolean |
| 132 | |
| 133 | |
| 134 | class ParameterInfoList(Tr069ComplexModel): |
| 135 | _type_info = odict() |
| 136 | _type_info["ParameterInfoStruct"] = ParameterInfoStruct.customize(max_occurs='unbounded') |
| 137 | _type_info["arrayType"] = XmlAttribute(String, ns=SOAP_ENC) |
| 138 | |
| 139 | |
| 140 | class ParameterNames(Tr069ComplexModel): |
| 141 | _type_info = odict() |
| 142 | _type_info["string"] = String.customize(max_occurs='unbounded', max_length=256) |
| 143 | _type_info["arrayType"] = XmlAttribute(String, ns=SOAP_ENC) |
| 144 | |
| 145 | |
| 146 | class ParameterKeyType(anySimpleType): |
| 147 | pass |
| 148 | |
| 149 | |
| 150 | class AccessList(Tr069ComplexModel): |
| 151 | _type_info = odict() |
| 152 | _type_info["string"] = String.customize(max_occurs='unbounded', max_length=64) |
| 153 | _type_info["arrayType"] = XmlAttribute(String, ns=SOAP_ENC) |
| 154 | |
| 155 | |
| 156 | class SetParameterAttributesStruct(Tr069ComplexModel): |
| 157 | _type_info = odict() |
| 158 | _type_info["Name"] = String(max_length=256) |
| 159 | _type_info["NotificationChange"] = Boolean |
| 160 | _type_info["Notification"] = Integer |
| 161 | _type_info["AccessListChange"] = Boolean |
| 162 | _type_info["AccessList"] = AccessList |
| 163 | |
| 164 | |
| 165 | class SetParameterAttributesList(Tr069ComplexModel): |
| 166 | _type_info = odict() |
| 167 | _type_info["SetParameterAttributesStruct"] = SetParameterAttributesStruct.customize( |
| 168 | max_occurs='unbounded', |
| 169 | ) |
| 170 | _type_info["arrayType"] = XmlAttribute(String, ns=SOAP_ENC) |
| 171 | |
| 172 | |
| 173 | class ParameterAttributeStruct(Tr069ComplexModel): |
| 174 | _type_info = odict() |
| 175 | _type_info["Name"] = String(max_length=256) |
| 176 | _type_info["Notification"] = Integer |
| 177 | _type_info["AccessList"] = AccessList |
| 178 | |
| 179 | |
| 180 | class ParameterAttributeList(Tr069ComplexModel): |
| 181 | _type_info = odict() |
| 182 | _type_info["ParameterValueStruct"] = ParameterAttributeStruct.customize( |
| 183 | max_occurs='unbounded', |
| 184 | ) |
| 185 | _type_info["arrayType"] = XmlAttribute(String, ns=SOAP_ENC) |
| 186 | |
| 187 | |
| 188 | class CommandKeyType(String.customize(max_length=32)): |
| 189 | pass |
| 190 | |
| 191 | |
| 192 | class ObjectNameType(String.customize(max_length=256)): |
| 193 | pass |
| 194 | |
| 195 | |
| 196 | # CPE messages |
| 197 | |
| 198 | |
| 199 | class SetParameterValues(Tr069ComplexModel): |
| 200 | _type_info = odict() |
| 201 | _type_info["ParameterList"] = ParameterValueList |
| 202 | _type_info["ParameterKey"] = ParameterKeyType |
| 203 | |
| 204 | |
| 205 | class SetParameterValuesResponse(Tr069ComplexModel): |
| 206 | _type_info = odict() |
| 207 | _type_info["Status"] = Integer |
| 208 | |
| 209 | |
| 210 | class GetParameterValues(Tr069ComplexModel): |
| 211 | _type_info = odict() |
| 212 | _type_info["ParameterNames"] = ParameterNames |
| 213 | |
| 214 | |
| 215 | class GetParameterValuesResponse(Tr069ComplexModel): |
| 216 | _type_info = odict() |
| 217 | _type_info["ParameterList"] = ParameterValueList |
| 218 | |
| 219 | |
| 220 | class GetParameterNames(Tr069ComplexModel): |
| 221 | _type_info = odict() |
| 222 | _type_info["ParameterPath"] = String.customize(max_length=256) |
| 223 | _type_info["NextLevel"] = Boolean |
| 224 | |
| 225 | |
| 226 | class GetParameterNamesResponse(Tr069ComplexModel): |
| 227 | _type_info = odict() |
| 228 | _type_info["ParameterList"] = ParameterInfoList |
| 229 | |
| 230 | |
| 231 | class SetParameterAttributes(Tr069ComplexModel): |
| 232 | _type_info = odict() |
| 233 | _type_info["ParameterList"] = SetParameterAttributesList |
| 234 | |
| 235 | |
| 236 | class SetParameterAttributesResponse(Tr069ComplexModel): |
| 237 | # Dummy field required because spyne does not allow 'bare' RPC function with |
| 238 | # no input parameters. This field is never sent by CPE. |
| 239 | _type_info = odict() |
| 240 | _type_info["DummyField"] = UnsignedInteger |
| 241 | |
| 242 | |
| 243 | class GetParameterAttributes(Tr069ComplexModel): |
| 244 | _type_info = odict() |
| 245 | _type_info["ParameterNames"] = ParameterNames |
| 246 | |
| 247 | |
| 248 | class GetParameterAttributesResponse(Tr069ComplexModel): |
| 249 | _type_info = odict() |
| 250 | _type_info["ParameterList"] = ParameterAttributeList |
| 251 | |
| 252 | |
| 253 | class AddObject(Tr069ComplexModel): |
| 254 | _type_info = odict() |
| 255 | _type_info["ObjectName"] = ObjectNameType |
| 256 | _type_info["ParameterKey"] = ParameterKeyType |
| 257 | |
| 258 | |
| 259 | class AddObjectResponse(Tr069ComplexModel): |
| 260 | _type_info = odict() |
| 261 | _type_info["InstanceNumber"] = UnsignedInteger |
| 262 | _type_info["Status"] = Integer |
| 263 | |
| 264 | |
| 265 | class DeleteObject(Tr069ComplexModel): |
| 266 | _type_info = odict() |
| 267 | _type_info["ObjectName"] = ObjectNameType |
| 268 | _type_info["ParameterKey"] = ParameterKeyType |
| 269 | |
| 270 | |
| 271 | class DeleteObjectResponse(Tr069ComplexModel): |
| 272 | _type_info = odict() |
| 273 | _type_info["Status"] = Integer |
| 274 | |
| 275 | |
| 276 | class Download(Tr069ComplexModel): |
| 277 | _type_info = odict() |
| 278 | _type_info["CommandKey"] = CommandKeyType |
| 279 | _type_info["FileType"] = String(max_length=64) |
| 280 | _type_info["URL"] = String(max_length=256) |
| 281 | _type_info["Username"] = String(max_length=256) |
| 282 | _type_info["Password"] = String(max_length=256) |
| 283 | _type_info["FileSize"] = UnsignedInteger |
| 284 | _type_info["TargetFileName"] = String(max_length=256) |
| 285 | _type_info["DelaySeconds"] = UnsignedInteger |
| 286 | _type_info["SuccessURL"] = String(max_length=256) |
| 287 | _type_info["FailureURL"] = String(max_length=256) |
| 288 | |
| 289 | |
| 290 | class DownloadResponse(Tr069ComplexModel): |
| 291 | _type_info = odict() |
| 292 | _type_info["Status"] = Integer |
| 293 | _type_info["StartTime"] = DateTime |
| 294 | _type_info["CompleteTime"] = DateTime |
| 295 | |
| 296 | |
| 297 | class Reboot(Tr069ComplexModel): |
| 298 | _type_info = odict() |
| 299 | _type_info["CommandKey"] = CommandKeyType |
| 300 | |
| 301 | |
| 302 | class RebootResponse(Tr069ComplexModel): |
| 303 | # Dummy field required because spyne does not allow 'bare' RPC function with |
| 304 | # no input parameters. This field is never sent by CPE. |
| 305 | _type_info = odict() |
| 306 | _type_info["DummyField"] = UnsignedInteger |
| 307 | |
| 308 | |
| 309 | # ACS messages |
| 310 | |
| 311 | |
| 312 | class Inform(Tr069ComplexModel): |
| 313 | _type_info = odict() |
| 314 | _type_info["DeviceId"] = DeviceIdStruct |
| 315 | _type_info["Event"] = EventList |
| 316 | _type_info["MaxEnvelopes"] = UnsignedInteger |
| 317 | _type_info["CurrentTime"] = DateTime |
| 318 | _type_info["RetryCount"] = UnsignedInteger |
| 319 | _type_info["ParameterList"] = ParameterValueList |
| 320 | |
| 321 | |
| 322 | class InformResponse(Tr069ComplexModel): |
| 323 | _type_info = odict() |
| 324 | _type_info["MaxEnvelopes"] = UnsignedInteger |
| 325 | |
| 326 | |
| 327 | class TransferComplete(Tr069ComplexModel): |
| 328 | _type_info = odict() |
| 329 | _type_info["CommandKey"] = CommandKeyType |
| 330 | _type_info["FaultStruct"] = FaultStruct |
| 331 | _type_info["StartTime"] = DateTime |
| 332 | _type_info["CompleteTime"] = DateTime |
| 333 | |
| 334 | |
| 335 | class TransferCompleteResponse(Tr069ComplexModel): |
| 336 | # Dummy field required because spyne does not allow 'bare' RPC function with |
| 337 | # no input parameters. This field is never sent by ACS. |
| 338 | _type_info = odict() |
| 339 | _type_info["DummyField"] = UnsignedInteger |
| 340 | |
| 341 | |
| 342 | class GetRPCMethods(Tr069ComplexModel): |
| 343 | _type_info = odict() |
| 344 | _type_info["DummyField"] = UnsignedInteger |
| 345 | |
| 346 | |
| 347 | class GetRPCMethodsResponse(Tr069ComplexModel): |
| 348 | _type_info = odict() |
| 349 | _type_info["MethodList"] = MethodList |
| 350 | |
| 351 | |
| 352 | # |
| 353 | # Miscellaneous |
| 354 | # |
| 355 | |
| 356 | class ParameterListUnion(Tr069ComplexModel): |
| 357 | """ Union of structures that get instantiated as 'ParameterList' in ACS->CPE |
| 358 | messages. This is required because AcsToCpeRequests can only have one |
| 359 | parameter named 'ParameterList', so that must also be a union """ |
| 360 | _type_info = odict() |
| 361 | |
| 362 | # Fields from ParameterValueList |
| 363 | _type_info["ParameterValueStruct"] = ParameterValueStruct.customize( |
| 364 | max_occurs='unbounded', |
| 365 | ) |
| 366 | _type_info["arrayType"] = XmlAttribute(String, ns=SOAP_ENC) |
| 367 | |
| 368 | # Fields from SetParameterAttributesList |
| 369 | _type_info["SetParameterAttributesStruct"] = \ |
| 370 | SetParameterAttributesStruct.customize(max_occurs='unbounded') |
| 371 | # arrayType = XmlAttribute(String, ns=SOAP_ENC) - Already covered above |
| 372 | |
| 373 | |
| 374 | class AcsToCpeRequests(Tr069ComplexModel): |
| 375 | """ Union of all ACS->CPE requests. Only fields for one request is populated |
| 376 | per message instance """ |
| 377 | _type_info = odict() |
| 378 | |
| 379 | # Fields for SetParameterValues |
| 380 | _type_info["ParameterList"] = ParameterListUnion # See ParameterListUnion for explanation |
| 381 | _type_info["ParameterKey"] = ParameterKeyType |
| 382 | |
| 383 | # Fields for GetParameterValues |
| 384 | # _type_info["ParameterList"] = ParameterValueList - Already covered above |
| 385 | |
| 386 | # Fields for GetParameterNames |
| 387 | _type_info["ParameterPath"] = String.customize(max_length=256) |
| 388 | _type_info["NextLevel"] = Boolean |
| 389 | |
| 390 | # Fields for SetParameterAttributes |
| 391 | # _type_info["ParameterList"] = SetParameterAttributesList - Already covered above |
| 392 | |
| 393 | # Fields for GetParameterAttributes |
| 394 | _type_info["ParameterNames"] = ParameterNames |
| 395 | |
| 396 | # Fields for AddObject |
| 397 | _type_info["ObjectName"] = ObjectNameType |
| 398 | _type_info["ParameterKey"] = ParameterKeyType |
| 399 | |
| 400 | # Fields for DeleteObject |
| 401 | # _type_info["ObjectName"] = ObjectNameType - Already covered above |
| 402 | # _type_info["ParameterKey"] = ParameterKeyType - Already covered above |
| 403 | |
| 404 | # Fields for Download |
| 405 | _type_info["CommandKey"] = CommandKeyType |
| 406 | _type_info["FileType"] = String(max_length=64) |
| 407 | _type_info["URL"] = String(max_length=256) |
| 408 | _type_info["Username"] = String(max_length=256) |
| 409 | _type_info["Password"] = String(max_length=256) |
| 410 | _type_info["FileSize"] = UnsignedInteger |
| 411 | _type_info["TargetFileName"] = String(max_length=256) |
| 412 | _type_info["DelaySeconds"] = UnsignedInteger |
| 413 | _type_info["SuccessURL"] = String(max_length=256) |
| 414 | _type_info["FailureURL"] = String(max_length=256) |
| 415 | |
| 416 | # Fields for Reboot |
| 417 | # _type_info["CommandKey"] = CommandKeyType - Already covered above |
| 418 | |
| 419 | |
| 420 | class DummyInput(Tr069ComplexModel): |
| 421 | """ Dummy complex model. Used for 'EmptyHttp' function, because spyne Does |
| 422 | not handle 'bare' function with no inputs """ |
| 423 | _type_info = odict() |
| 424 | _type_info["DummyField"] = UnsignedInteger |