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